Hello all! I am working on expanding the Ben Eater 6502 project and I started looking at implementing a serial function, with data coming from an Arduino and being loaded into RAM. I managed to get the code to work properly, but only for an 8-bit amount of instructions. If the number of instructions is > 255, my code breaks down. I'm not sure exactly what the issue is, though. I've tried the "standard" 16-bit subtraction code snippit from
https://dwheeler.com/6502/oneelkruns/asm1step.html to completely replace what I have, but it didn't work, even for an 8-bit number. Here is the code I'm using:
Code:
(BYTECOUNT and BYTECOUNT+1 are used to keep track of how many instructions are to be sent from the Arduino)
(These numbers are 1 based, i.e. when the BYTECOUNT (and BYTECOUNT+1) are 0, there are no more instructions left and the code should branch out to the end)
.byteToRam:
; Receive 8 individual bits and construct them into a byte
jsr .receiveBits
; Builds up IECDATA as the byte
; Save byte to RAM
; USRMEM is the location in RAM the code can start writing to = $0400
; X starts at 0
lda IECDATA
sta USRMEM,X
INX
dec BYTECOUNT
beq .highByte
jmp .byteToRam
.highByte:
lda BYTECOUNT+1
bne .decBC1
jmp .end
.decBC1:
dec BYTECOUNT+1
lda #%11111111
sta BYTECOUNT
jmp .byteToRam
.end:
cli ; enable interrupts
jmp USRMEM
I have one thought that the above code is missing the 0th byte when there is more than 255 instructions to pass in, i.e. byte 256 or 512, etc. I tried coding for that, but it still didn't work as I expected. Does anyone have any ideas and/or simplifications? I really appreciate it! Please let me know if more detail is required and I shall add it.
Thanks!