6

I am building a computer based on the 65C02S, and when stepping through the code, I see strange things happening.

This is my code:

SEI
CLD
LDX #$ff
TXS

JSR someRoutine
...

This translates to this behaviour (when stepping though and monitoring with an Arduino):

READ  address:   80 0d   1000.0000 0000.1101   data:   78   0111.1000 SEI
READ  address:   80 0e   1000.0000 0000.1110   data:   d8   1101.1000 CLD
READ  address:   80 0e   1000.0000 0000.1110   data:   d8   1101.1000 d8 
READ  address:   80 0f   1000.0000 0000.1111   data:   a2   1010.0010 LDX
READ  address:   80 0f   1000.0000 0000.1111   data:   a2   1010.0010 a2 
READ  address:   80 10   1000.0000 0001.0000   data:   ff   1111.1111 ff 
READ  address:   80 11   1000.0000 0001.0001   data:   9a   1001.1010 TXS
READ  address:   80 12   1000.0000 0001.0010   data:   20   0010.0000 JSR
READ  address:   80 12   1000.0000 0001.0010   data:   20   0010.0000 JSR
READ  address:   80 13   1000.0000 0001.0011   data:   28   0010.1000 28 
READ  address:   01 ff   0000.0001 1111.1111   data:   80   1000.0000 ---
WRITE address:   01 ff   0000.0001 1111.1111   data:   80   1000.0000 ---
WRITE address:   01 fe   0000.0001 1111.1110   data:   ff   1111.1111 ---    ; Why write FF?
READ  address:   80 14   1000.0000 0001.0100   data:   80   1000.0000 80 
READ  address:   ff ff   1111.1111 1111.1111   data:   ff   1111.1111 ---
READ  address:   80 14   1000.0000 0001.0100   data:   80   1000.0000 80     ; Why not jump?
READ  address:   80 15   1000.0000 0001.0101   data:   a9   1010.1001 LDA

As you can see, the WRITEs are already weird (why write 80 ff, when the PC is at 80 12 at that point?), but also, the JSR doesn't seem to jump at all, it just continues at 80 14.

I first thought it might be some noise somewhere, but the behaviour is always the same. I also tried adding the reset code (SEI, etc), but that just gives slightly different, incorrect, results. I am trying to figure out if my code is wrong, or that I should look at other parts somewhere (noise, design ...)

For clarity, this is the binary code that I am running:

00000000  48 65 6c 6c 6f 20 57 6f  72 6c 64 21 00 78 d8 a2  |Hello World!.x..|
00000010  ff 9a 20 28 80 a9 00 85  10 a9 80 85 11 20 5d 80  |.. (......... ].|
00000020  ea 4c 20 80 a2 ff 9a 60  a9 00 8d f8 7f 8d f9 7f  |.L ....`........|
00000030  a9 30 20 45 80 a9 01 20  45 80 a9 0f 20 45 80 60  |.0 E... E... E.`|
00000040  3a 8d f9 7f 60 8d f8 7f  a9 01 8d f9 7f 20 40 80  |:...`........ @.|
00000050  60 8d f8 7f a9 05 8d f9  7f 20 40 80 60 a0 00 b1  |`........ @.`...|
00000060  10 f0 07 20 51 80 c8 4c  5f 80 60                 |... Q..L_.`|

Update I created a very simple program that loops forever, with a simple JMP and that runs fine. Which make me think noise is not a problem here.

Update This is how I attach the Arduino (pin 2 is connected to PHI2 (pin 37) of the CPU):

#define CLOCK 2

pinMode(CLOCK, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(CLOCK), onClock, FALLING);

Update I attached an oscilloscope to the databus and see that at some point the level is 1.5V instead of 0 or 5, so I think the design is failing somewhere...

Update this is my design:

enter image description here

27
  • 1
    I'm not entirely sure what I see. Mind to tell at what points your 'trace' is taken? Using an Arduino sounds suspect at first. How is it connected? what does it exactly do, does it drive some liens? Maybe even just for a short period? Likewise, how does it continue?
    – Raffzahn
    Apr 17, 2021 at 20:01
  • 3
    Are you monitoring the SYNC signal with the Arduino? That may give clues as to whether the 6502 is actually executing the instructions you think it is. Also, be sure that you're sampling the address and data lines at the correct points in the clock cycle: addresses are valid at the rising edge of Phi2, but data is valid at the falling edge. Finally, beware of counterfeit CPUs; while most genuine 65C02s can be run very slowly, many on eBay are actually older NMOS CPUs that have a minimum clock speed for correct operation.
    – Chromatix
    Apr 17, 2021 at 20:08
  • 1
    Thanks for all your remarks, made me look into the Arduino a little more critical. I set the pins to INPUT_PULLUP. Changing this to INPUT seems to have effect. Apr 18, 2021 at 12:13
  • 1
    I suspect the data is taken form the setups databuss. To be able to answer , I think it is needed to know what is connected to the data bus, and probably the whole schematics of the computer you built, including the Arduino connections. The actual schematics, checked against reality, not how it was planned to be connected.
    – UncleBod
    Apr 18, 2021 at 14:38
  • 3
    If this is still an issue, please post the schematics. If it is not an issue, please edit the question or post an answer about what was wrong.
    – UncleBod
    Apr 19, 2021 at 10:43

1 Answer 1

1

The 6502 cannot be single stepped, and neither can the 65C02, as they use DRAM cells for their internal registers.

If you want single-stepping, you have to buy a 65C02S.

2

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .