6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sat Apr 27, 2024 3:57 pm

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: lib6502/run6502 updates
PostPosted: Sat Mar 16, 2024 6:28 pm 
Offline

Joined: Sat Dec 12, 2015 7:48 pm
Posts: 122
Location: Lake Tahoe
Here is a very minor update to Ian Piumarta's excellent 6502 simulator. I was in need of a simple command line environment to test my Apple 1 PLASMA VM - running a full blown emulator was just too inconvenient to test my code. However, lib6502 didn't easily allow for tracing executing code which is what I was looking for. So, I made some very minor changes to the spectacular C macros he created to allow for single stepping. And I do mean his macros are spectacular; really, you should check them out.

Now, by setting a flag in the mpu structure such as:

Code:
mpu->flags |= M6502_SingleStep;


One can run the simulator and trace/single step the 6502 code for easy debugging:

Code:
while (M6502_run(mpu))
  {
    char state[64];
    char insn[64];
    M6502_dump(mpu, state);
    M6502_disassemble(mpu, mpu->registers->pc, insn);
    printf("%s : %s\n", state, insn);
  }


This will display to the console:
Code:
PC=0677 SP=01FC A=6A X=10 Y=00 P=05 -----I-C : iny
PC=0678 SP=01FC A=6A X=10 Y=01 P=05 -----I-C : lda (F2),Y
PC=067A SP=01FC A=82 X=10 Y=01 P=85 N----I-C : sta E7
PC=067C SP=01FC A=82 X=10 Y=01 P=85 N----I-C : iny
PC=067D SP=01FC A=82 X=10 Y=02 P=05 -----I-C : lda (F2),Y
PC=067F SP=01FC A=0B X=10 Y=02 P=05 -----I-C : sta E8
PC=0681 SP=01FC A=0B X=10 Y=02 P=05 -----I-C : sty E4
PC=0683 SP=01FC A=0B X=10 Y=02 P=05 -----I-C : ldy #00
PC=0685 SP=01FC A=0B X=10 Y=00 P=07 -----IZC : lda (E7),Y
PC=0687 SP=01FC A=40 X=10 Y=00 P=05 -----I-C : dex
PC=0688 SP=01FC A=40 X=0F Y=00 P=05 -----I-C : sta D0,X
PC=068A SP=01FC A=40 X=0F Y=00 P=05 -----I-C : iny
PC=068B SP=01FC A=40 X=0F Y=01 P=05 -----I-C : lda (E7),Y
PC=068D SP=01FC A=0B X=0F Y=01 P=05 -----I-C : sta C0,X
PC=068F SP=01FC A=0B X=0F Y=01 P=05 -----I-C : ldy E4
PC=0691 SP=01FC A=0B X=0F Y=02 P=05 -----I-C : rts
PC=069B SP=01FE A=0B X=0F Y=02 P=05 -----I-C : jmp 00F0
PC=00F0 SP=01FE A=0B X=0F Y=02 P=05 -----I-C : iny
PC=00F1 SP=01FE A=0B X=0F Y=03 P=05 -----I-C : lda 15BF,Y
PC=00F4 SP=01FE A=62 X=0F Y=03 P=05 -----I-C : sta F7
PC=00F6 SP=01FE A=62 X=0F Y=03 P=05 -----I-C : jmp (0362)
PC=05DE SP=01FE A=62 X=0F Y=03 P=05 -----I-C : lda D0,X
PC=05E0 SP=01FE A=40 X=0F Y=03 P=05 -----I-C : sta BF,X
PC=05E2 SP=01FE A=40 X=0F Y=03 P=05 -----I-C : lda (BF,X)
PC=05E4 SP=01FE A=A6 X=0F Y=03 P=85 N----I-C : sta D0,X
PC=05E6 SP=01FE A=A6 X=0F Y=03 P=85 N----I-C : inc BF,X


It's simply based on the return value from M6502_run: 1 (or non-zero) means it is single stepping, 0 means error/exit. I sent email to Ian but he may not check that email address very often or is busy with real life. So I thought I would post it here if anyone is interested. It's part of the PLASMA project located here: https://github.com/dschmenk/PLASMA/tree ... rc/lib6502

The Apple1+CFFA1 code is in a1cffa.c which is a very simplistic version of an Apple 1 with CFFA1 card but sufficient for my needs.


Top
 Profile  
Reply with quote  
PostPosted: Sun Mar 17, 2024 7:28 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10793
Location: England
Thanks for this! Ian's code really is a splendid example of what can be done.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 10 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: