Page 1 of 1
Illegal opcodes emulation in simple emulator written in C
Posted: Thu Dec 08, 2022 3:56 pm
by LTVA
Hello. I have forked this nice tool:
https://github.com/LTVA1/siddump. In cpu.c I tried to add some illegal opcodes support (search by word "Lunatico"), but when I try to use the program on Lunatico sid files I don't get any SID registers writes but they should happen. This means that the 4 opcodes I tried to implement are done wrong. So I need help since I know almost nothing about 6502 internals and how illegal opcodes work.
Re: Illegal opcodes emulation in simple emulator written in
Posted: Thu Dec 08, 2022 4:19 pm
by BigEd
Welcome!
A quick look suggests that you'd need
WRITE(ABSOLUTE());
in some appropriate place(s).
Re: Illegal opcodes emulation in simple emulator written in
Posted: Thu Dec 08, 2022 5:13 pm
by LTVA
Welcome!
A quick look suggests that you'd need
WRITE(ABSOLUTE());
in some appropriate place(s).
Hmm, I was worried that this might be the case since WRITE(foo) just does nothing (it has something commented out). I will try to add the actual WRITE() functionality first and see if it doesn't break.
Re: Illegal opcodes emulation in simple emulator written in
Posted: Thu Dec 08, 2022 5:37 pm
by LTVA
Well, it does break. Maybe it won't be an easy fix, although I haven't found any C emulator with all illegal opcodes.
Re: Illegal opcodes emulation in simple emulator written in
Posted: Thu Dec 08, 2022 6:53 pm
by LTVA
Ok so I corrected program counter increments and now Lunatico sids actually write some data to SID registers, but it seems like the program is being stuck in short loop since after some time it starts to output repeating portions of nonsensical data (e.g. C-0 notes over and over again which isn't what the sid should play, obviously).
I updated code on github, and it's late now, so for today I won't do any further work on this.
P.S. Funny thing with this emulator is that
is what actually writes to some memory location, while
just does nothing.
The whole issue is basically because LFT made his custom sid player to fit in like ~15 rasterlines which is apparently implying some self-modifying code (?) and clever illegal opcodes hacks.
Re: Illegal opcodes emulation in simple emulator written in
Posted: Sun Dec 11, 2022 8:17 pm
by MicroCoreLabs
Well, it does break. Maybe it won't be an easy fix, although I haven't found any C emulator with all illegal opcodes.
You could take a look at my MCL64 which is a 6510 emulator written in C and supports the undocumented/unstable opcodes fairly well when used as a drop-in replacement into a Commodore 64.
https://github.com/MicroCoreLabs/Projec ... /MCL64.ino
Re: Illegal opcodes emulation in simple emulator written in
Posted: Mon Dec 12, 2022 11:18 am
by dp11
I would probably check to see how good the emulation is of the instructions with
https://github.com/Klaus2m5/6502_65C02_functional_tests and my cycle timing checker which includes undocumented instructions :
https://github.com/dp111/6502Timing
Re: Illegal opcodes emulation in simple emulator written in
Posted: Mon Dec 12, 2022 7:08 pm
by LTVA
Well, it does break. Maybe it won't be an easy fix, although I haven't found any C emulator with all illegal opcodes.
You could take a look at my MCL64 which is a 6510 emulator written in C and supports the undocumented/unstable opcodes fairly well when used as a drop-in replacement into a Commodore 64.
https://github.com/MicroCoreLabs/Projec ... /MCL64.ino
Quite nice emulator, although it can't be easily made as a replacement in my case since in my fork there is an array which acts like C64 memory and a function that reads virtual SID registers values regularly. I like your code for illegal opcodes though, may adapt it to my program.
Re: Illegal opcodes emulation in simple emulator written in
Posted: Mon Dec 12, 2022 7:09 pm
by LTVA
Actually no need now, I have the source code so I see what opcodes are implemented and what aren't.
Re: Illegal opcodes emulation in simple emulator written in
Posted: Mon Dec 12, 2022 8:49 pm
by MicroCoreLabs
Well, it does break. Maybe it won't be an easy fix, although I haven't found any C emulator with all illegal opcodes.
You could take a look at my MCL64 which is a 6510 emulator written in C and supports the undocumented/unstable opcodes fairly well when used as a drop-in replacement into a Commodore 64.
https://github.com/MicroCoreLabs/Projec ... /MCL64.ino
Quite nice emulator, although it can't be easily made as a replacement in my case since in my fork there is an array which acts like C64 memory and a function that reads virtual SID registers values regularly. I like your code for illegal opcodes though, may adapt it to my program.
Sounds like you are all set, however note that the MCL64 has a separate Bus Interface Unit (BIU) which takes as inputs the memory read and write commands and inplements them on a physical bus signals. If you wanted to instead use an array for your memory or implement peripherals then this is the place to do this. This is how I debugged the code using command-line gcc - instead of physical interface I just used an array in the BIU...
Re: Illegal opcodes emulation in simple emulator written in
Posted: Tue Dec 13, 2022 2:18 pm
by LTVA
Well, it does break. Maybe it won't be an easy fix, although I haven't found any C emulator with all illegal opcodes.
You could take a look at my MCL64 which is a 6510 emulator written in C and supports the undocumented/unstable opcodes fairly well when used as a drop-in replacement into a Commodore 64.
https://github.com/MicroCoreLabs/Projec ... /MCL64.ino
Quite nice emulator, although it can't be easily made as a replacement in my case since in my fork there is an array which acts like C64 memory and a function that reads virtual SID registers values regularly. I like your code for illegal opcodes though, may adapt it to my program.
Sounds like you are all set, however note that the MCL64 has a separate Bus Interface Unit (BIU) which takes as inputs the memory read and write commands and inplements them on a physical bus signals. If you wanted to instead use an array for your memory or implement peripherals then this is the place to do this. This is how I debugged the code using command-line gcc - instead of physical interface I just used an array in the BIU...
Okay I think I will try to use it since the in-place opcode implementation didn't work.
Re: Illegal opcodes emulation in simple emulator written in
Posted: Thu Dec 22, 2022 10:08 am
by LTVA
okay so... I could not adapt it, it just hangs on some instruction forever!
https://github.com/LTVA1/siddump/tree/broken
Re: Illegal opcodes emulation in simple emulator written in
Posted: Thu Dec 22, 2022 10:12 am
by LTVA
Well, it does break. Maybe it won't be an easy fix, although I haven't found any C emulator with all illegal opcodes.
You could take a look at my MCL64 which is a 6510 emulator written in C and supports the undocumented/unstable opcodes fairly well when used as a drop-in replacement into a Commodore 64.
https://github.com/MicroCoreLabs/Projec ... /MCL64.ino
Quite nice emulator, although it can't be easily made as a replacement in my case since in my fork there is an array which acts like C64 memory and a function that reads virtual SID registers values regularly. I like your code for illegal opcodes though, may adapt it to my program.
Sounds like you are all set, however note that the MCL64 has a separate Bus Interface Unit (BIU) which takes as inputs the memory read and write commands and inplements them on a physical bus signals. If you wanted to instead use an array for your memory or implement peripherals then this is the place to do this. This is how I debugged the code using command-line gcc - instead of physical interface I just used an array in the BIU...
So I tried to remove internal RAM requests and all the stuff related to MCU and external signals. From what I debugged it seems like it successfully passes SID model check but then it just hangs executing 0x00, 0x40 or 0x60 forever (I made it stop on these as in original emulator but it just stops and does not advance any further; I made sure PC increments when I jump out of the loop)