Thursday, April 5, 2018

Patching the CoCo ROM Part 4

*REVISED*


While this will require patching everywhere CHRGET and CHRGOT are called with the new addresses, it will allow the CoCo parser patch to be as fast as the MC-10 version except when it passes a byte boundary.  255 out of 256 cases is good enough for me.

I looked at calling a function to automatically patch calls from the ROM, but there isn't enough room for the jumps to the rest of the code even if there are no JMPs to CHRGET the code.

org $9F
OLDCHRGET
bra CHRGET         ;catch any unpatched calls to CHRGET
INCHIGHBYTE       ;code to increment the high byte of the current address being parsed
inc CHRGOT+1
bra CHRGOT
OLDCHRGOT
bra CHRGOT        ;catch any unpatched calls to CHRGOT



org $F3
CHRGET                 ; increment BASIC code pointer, then fall through to CHRGOT
inc CHRGOT+2
beq INCHIGHBYTE
CHRGOT                 ; read the current byte of BASIC code we are pointing at
lda >0000              ; self modifying code, the actual read takes place here

*LINE OF CODE IS MISSING HERE*

bcs PARSER2       ;
rts
PARSER2
jmp >BROMHK+4


*edit*
Always double check your code after cutting and pasting!  This is one of the most common causes of bugs in a program.  Doing so saved me a lot of headaches with this code.

Please note that after adding the missing line of code, this patch is too large for the available space at $F3 without changes.  That prompted this revision.  It no longer catches calls to the old CHRGET and CHRGOT addresses, but there is room to catch one of them if I decide to do so.


org $9F
INCHIGHBYTE       ;code to increment the high byte of the current address being parsed
inc CHRGOT+1
bra CHRGOT
PARSER2
  jmp >BROMHK+4  ; test for other characters

org $F3
CHRGET                 ; increment BASIC code pointer, then fall through to CHRGOT
inc CHRGOT+2

beq INCHIGHBYTE
CHRGOT                 ; read the current byte of BASIC code we are pointing at
lda >0000              ; self modifying code, the actual read takes place here

cmpa      #':' ; set Z flag if statement separator or larger
bcs PARSER2       ; 
rts

No comments:

Post a Comment