I/O0 and illegal opcodes

Modding and Technical Issues

Moderator: Moderators

Post Reply
User avatar
mythic66
Vic 20 Drifter
Posts: 32
Joined: Sat Dec 31, 2022 1:21 pm
Location: Canada
Occupation: Technician

I/O0 and illegal opcodes

Post 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
User avatar
Mike
Herr VC
Posts: 4841
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: I/O0 and illegal opcodes

Post 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.
groepaz
Vic 20 Scientist
Posts: 1188
Joined: Wed Aug 25, 2010 5:30 pm

Re: I/O0 and illegal opcodes

Post 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)
I'm just a Software Guy who has no Idea how the Hardware works. Don't listen to me.
User avatar
tokra
Vic 20 Scientist
Posts: 1123
Joined: Tue Apr 27, 2010 5:32 pm
Location: Scheessel, Germany

Re: I/O0 and illegal opcodes

Post 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.
User avatar
chysn
Vic 20 Scientist
Posts: 1205
Joined: Tue Oct 22, 2019 12:36 pm
Website: http://www.beigemaze.com
Location: Michigan, USA
Occupation: Software Dev Manager

Re: I/O0 and illegal opcodes

Post 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.
Last edited by chysn on Wed Sep 13, 2023 12:50 pm, edited 2 times in total.
VIC-20 Projects: wAx Assembler, TRBo: Turtle RescueBot, Helix Colony, Sub Med, Trolley Problem, Dungeon of Dance, ZEPTOPOLIS, MIDI KERNAL, The Archivist, Ed for Prophet-5

WIP: MIDIcast BASIC extension

he/him/his
groepaz
Vic 20 Scientist
Posts: 1188
Joined: Wed Aug 25, 2010 5:30 pm

Re: I/O0 and illegal opcodes

Post 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 :)
I'm just a Software Guy who has no Idea how the Hardware works. Don't listen to me.
User avatar
Wilson
Vic 20 Enthusiast
Posts: 190
Joined: Mon Sep 28, 2009 7:19 am
Location: Brooklyn, NY

Re: I/O0 and illegal opcodes

Post 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.
User avatar
chysn
Vic 20 Scientist
Posts: 1205
Joined: Tue Oct 22, 2019 12:36 pm
Website: http://www.beigemaze.com
Location: Michigan, USA
Occupation: Software Dev Manager

Re: I/O0 and illegal opcodes

Post 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
User avatar
Wilson
Vic 20 Enthusiast
Posts: 190
Joined: Mon Sep 28, 2009 7:19 am
Location: Brooklyn, NY

Re: I/O0 and illegal opcodes

Post 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!
User avatar
JonBrawn
Vic 20 Devotee
Posts: 225
Joined: Sat Sep 11, 2021 10:47 pm
Website: http://youtube.com/@vicenary
Location: Austin TX USA
Occupation: CPU design engineer

Re: I/O0 and illegal opcodes

Post 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.
Working on FPGA replacement for 6560/6561
https://youtube.com/@vicenary
Post Reply