Need help with debugging an emulator

3 posts / 0 new
Last post
Last seen: 1 month 4 days ago
Joined: Apr 3 2024 - 19:22
Posts: 4
Need help with debugging an emulator

Hello! This is my first time on a forum at all, so sorry if I'm rude or something, I really have no idea how this works.


I'm currently trying to create an emulator for the Apple I as a side project, but I've run into an issue: wozmon just doesn't work.

Say, if I do 0.7F, then it prints out the bytes from 0000 to 007f.

But, if I do 0.81, then it prints out only 0000!

What's even weirder is that when I do 0.100 it starts to work again, printing from 0000 to 0100.


I've spent hours looking at a trace of the emulator (attached), but I can't seem to get anything out of it.

I'm suspecting it's a bug in my 6502 emulation that I didn't catch with testing, but I really can't be sure at this point.


If anyone decides to help, thank you!

Last seen: 1 day 32 min ago
Joined: Apr 1 2020 - 16:46
Posts: 940
Apple-1 emulation ...

... without prior 100% testing of the 6502 emulation is futile. The Apple-1 is so simple that the 6502 emulation is most of the code.

I know because I wrote my own Apple-1 emulator which uses the switch level simuation of the NMOS 6502 netlist.

10 x slower than the real Apple-1 (this is called ' technical progress' ;-)  but it is guaranteed to be cycle-for-cycle exact with all the quirks of the 6502.


Here is my advice:


There is a 6502 emulation source on github which comes with a 6502 test suite. This tests all opcodes, all adressing modes, with all possible values.

I don't remember the name of that source but if you look you shall find.

Use it to debug your own 6502 emulation (if you insist to code everything by yourself).

Do not fall for the 65C02 versions. Apple-1 is NMOS 6502.


Another advice:


You need to implement the 6520 PIA function perfectly because there is some code around in the Apple-1 world which  manipulates the configuration of the PIA and it won't work if the PIA is not correctly modelled. You can find a good PIA emulation in the MAME project.


Yet another advice / wish:


Support AIFF and WAV files so your emulator can load audio files of the various Apple-1 software which was ripped from cassette records.

This entails emulation of the ACI. I always wanted to do that for my own Apple-1 emulator but never had the time to do it.


- Uncle Bernie

Last seen: 1 month 4 days ago
Joined: Apr 3 2024 - 19:22
Posts: 4
Fixed it!


I ended up finding and fixing the bug, it was in my 6502 emulation.

Turns out, it was setting carry in CMP based on if the difference between the arguments was greater than 0 with a signed byte, not unsigned. Whoops!

Log in or register to post comments