Page 1 of 1

I/O0 and illegal opcodes

Posted: Tue Sep 12, 2023 6:02 pm
by mythic66
Hi,

The 2 parts of the subject are not related but I wanted to kill 2 birds with one stone :wink:

* Is there any expansion card, or cartridges that use for any purpose the address space $9130-93FF ?. I know that in the
doc its says 'future expansion' but is there " anyone " using it ?

* Is there many games or apps that use the illegal opcodes of the 6502? Any list or numbers? I ask this to see if I can
get mostly 100% compatibility by using the W65C02.

thanks,
M

Re: I/O0 and illegal opcodes

Posted: Wed Sep 13, 2023 1:26 am
by Mike
mythic66 wrote:[Are] there any expansion [...] cartridges that use for any purpose the address space $9130-$93FF? I know that in the doc it says 'future expansion' but is there "anyone" using it?
(Note that address range is actually referred to as part of I/O0 as evident from the schematics, not I/O1 as you originally wrote in the topic title. I changed the topic title to follow suit.)

There is no select signal for the I/O0 address range that appears at the cartridge expansion port. Following that, there does not exist any cartridge that would use the addresses $9130..$93FF, neither would one be able to build one. Any expansion that makes use of this address range would need to be realized on the VIC-20 mainboard itself. That has actually been done indeed. More info here.
[Are] there many games or apps that use the illegal opcodes of the 6502? Any list or numbers? I ask this to see if I can get mostly 100% compatibility by using the W65C02.
BASIC and KERNAL in the VIC-20 only use the documented opcodes, but there does exist software that uses the so-called "illegal opcodes". If you install a W65C02 into your VIC-20, you will have to live with less than 100% compatibility in that regard.

...
The 2 parts of the subject are not related but I wanted to kill 2 birds with one stone :wink:
Yet both parts of the subject would have deserved an own topic, if only to prevent confusion in any follow-up discussion.

Re: I/O0 and illegal opcodes

Posted: Wed Sep 13, 2023 9:53 am
by groepaz
but there does exist software that uses the so-called "illegal opcodes".
To add to this: not seldom in old games there are undocumented opcodes executed not because the coder used them intentionally, but because they are a result of accidental memory corruption during development. (This is also true for use of uninitialized RAM, which happens surprisingly often in VIC20 games)

Re: I/O0 and illegal opcodes

Posted: Wed Sep 13, 2023 10:02 am
by tokra
I'd say if the illegal opcodes are used unintentionally and serve no true purpose (i.e. making code faster or more compact) they warrant a crack/hack to improve them. Otherwise I only know of VIC Doom that uses illegals, and Kweepa already regrets this since the effect seems minor.

One of my graphic-modes uses the illegal opcode SAX as this is the only way to show the graphics without changing the volume register as well.

Also I know the C64-fastloader Spindle uses illegals to do GCR-decoding on the fly which was deemed impossible before.

So, 99.9% of software will work, but there will always be some cool edge cases that require illegal opcodes. Supporting a W65C02 is fine, but if you can also support using the original 6502.

Re: I/O0 and illegal opcodes

Posted: Wed Sep 13, 2023 11:58 am
by chysn
I often use the multi-byte illegal NOPs, TOP ($3c, a.k.a. SKW) and DOP ($34, a.k.a. SKB) as selectors, because they're terribly useful:

Code: Select all

Load:     jsr SETNAM, etc.
          jsr LOAD
          bcc ok
          jmp LoadErr
ok:       rts

LoadErr:  lda #LOAD_ERR
          .byte $3c ; Skip next two bytes
MemErr:   lda #OUT_OF_MEM_ERR
          .byte $3c ; Skip next two bytes
RangeErr: lda #OUT_OF_RANGE_ERR
          jsr DisplayError
          jmp WarmStart
I'm not hesitant to use these because on 65C02 they correspond to BIT abs,X and BIT zp,X, respectively, so they should maintain the same functionality (as long as I don't rely on the flags that BIT sets). For the most part, I don't see the illegal instructions as making a lot of sense, conceptually, so my use isn't going to go beyond the fancy NOPs.

Re: I/O0 and illegal opcodes

Posted: Wed Sep 13, 2023 12:08 pm
by groepaz
Also I know the C64-fastloader Spindle uses illegals to do GCR-decoding on the fly which was deemed impossible before.
All the modern loaders do :)

Re: I/O0 and illegal opcodes

Posted: Thu Sep 14, 2023 9:07 am
by Wilson
chysn wrote: Wed Sep 13, 2023 11:58 am I often use the multi-byte illegal NOPs, TOP ($3c, a.k.a. SKW) and DOP ($34, a.k.a. SKB) as selectors, because they're terribly useful:
It's a very common pattern, but, out of curiosity, why not just use the BIT opcodes ($24 and $2C)? The Vic-20 KERNAL (and many other 6502 programs) do this.
The only reason I can imagine is to preserve the status register, but then this:
chysn wrote: I'm not hesitant to use these because on 65C02 they correspond to BIT abs,X and BIT zp,X, respectively
will be explicitly the wrong behavior

I have nothing against illegals myself. It's an extreme optimization in most cases, but there are applications for that. :)
Seems like they're very popular on the Atari-2600, which often demands an extra cycle here and there.

Re: I/O0 and illegal opcodes

Posted: Thu Sep 14, 2023 10:01 am
by chysn
Wilson wrote: Thu Sep 14, 2023 9:07 am It's a very common pattern, but, out of curiosity, why not just use the BIT opcodes ($24 and $2C)? The Vic-20 KERNAL (and many other 6502 programs) do this.
That's a fair question, and I've thought about it a lot in the course of my assembler design. I think that code is about communication with people as well as machines, so it's totally with that aesthetic in mind. Meaning is better conveyed by this:
Screen Shot 2023-09-14 at 11.49.46 AM.png
or this:
Screen Shot 2023-09-14 at 11.50.39 AM.png
than this:
Screen Shot 2023-09-14 at 1.55.21 PM.png
Since there's pretty much no downside to using those ?OP/SK? "instructions" instead of BIT, I adopt the practice for my own sense of harmony. :D

Re: I/O0 and illegal opcodes

Posted: Thu Sep 14, 2023 1:28 pm
by Wilson
chysn wrote: That's a fair question, and I've thought about it a lot in the course of my assembler design. I think that code is about communication with people as well as machines, so it's totally with that aesthetic in mind. Meaning is better conveyed by this:
Huh, never thought of it in terms of disassembly ergonomics. Neat!

Re: I/O0 and illegal opcodes

Posted: Wed Sep 20, 2023 5:33 pm
by JonBrawn
mythic66 wrote: Tue Sep 12, 2023 6:02 pm * Is there any expansion card, or cartridges that use for any purpose the address space $9130-93FF ?. I know that in the
doc its says 'future expansion' but is there " anyone " using it ?
Victor, my FPGA replacement for the 6560/1, uses many of the addresses in that range (the ones that do not collide with the regular VIC chip or the two VIAs). They are used for re-flashing the firmware and programming the user-definable colour palette. Having said which, Victor will only accept accesses to those locations after the magic unlock values have been written to the read-only VIC registers.

Note that this address range is a veritable minefield - the VIC and the two VIAs do not do complete address decoding, so multiple copies of their registers appear in that space, sometimes two or three of the devices being addressed at the same time, leading to possible bus contentions.