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:
INPUT_PULLUP
. Changing this toINPUT
seems to have effect.