theGSman wrote:
... I'm sure that much greater optimizations can be achieved but that would take a lot of further research and I already have something that works a treat ...
Mike B.
Code: Select all
; initialize length
; - Z-flag set if no length, clear if at least one byte
INI_LEN:
ldx lenl
ldy lenh
bne +
txa
+ rts
; update length, source and target pointers
; - Z-flag set if done, clear if not done
UPD_STL:
txa ; update length
bne +
tya
beq done ; no more to do
dey
+ dex
inc srcl ; update source pointer
bne +
inc srch
+ inc tgtl ; update target pointer
bne done
inc tgth ; warning: sets Z-flag if rollover from $FFFF to $0000
done:
rtsCode: Select all
UPD_STL INC SRCL ;Increment source low byte
BNE UPD_TL ;Check for rollover
INC SRCH ;Increment source high byte
UPD_TL INC TGTL ;Increment target low byte
BNE DECLEN ;Check for rollover
INC TGTH ;Increment target high byte
;
;DECLEN subroutine: decrement 16-bit variable LENL/LENH
DECLEN LDA LENL ;Get length low byte
BNE SKP_LENH ;Test for LENL = zero
DEC LENH ;Else decrement length high byte
SKP_LENH DEC LENL ;Decrement length low byte
RTS ;Return to callerCode: Select all
COMPLP LDA LENL ;Get low byte of length
ORA LENH ;OR in High byte of length
BEQ QUITMV ;If zero, nothing to write
BIT TEMP2 ;Check for EEPROM programming
BPL SKP_BURN ;If bit 7 not set, skip it
JSR BURN_BYTE ;Else Burn a byte to EEPROM
SKP_BURN LDA (SRCL) ;Else load source
CMP (TGTL) ;Compare to source
BEQ CMP_OK ;If compare is good, continue
;
LDA TEMP2 ;Get EEPROM flag
ORA #$40 ;Get bit 6 mask for error
STA TEMP2 ;Store to flag to show error in EEPROM write
JSR SPC2 ;Send 2 spaces
JSR DOLLAR ;Print $ sign
LDA TGTH ;Get high byte of address
LDY TGTL ;Get Low byte of address
JSR PRWORD ;Print word
JSR SPC ;Add 1 space for formatting
;
CMP_OK JSR UPD_STL ;Update pointers
BRA COMPLP ;Loop back until doneCode: Select all
PROG LDA #$80 ;Get EEPROM write active mask
STA TEMP2 ;Set flag for COMPLP routine
JSR COMPLP ;Call routine to write/compare
;
BIT TEMP2 ;Check for error bit in flag
BVC PRG_GOOD ;Branch if no errors
;
LDA #$26 ;Get Prog failed message
BRA BRA_PRMPT ;Branch to Prompt routine
;
PRG_GOOD LDA #$25 ;Get completed message
JSR PROMPT ;Send to console and exit
LDA #$27 ;Get warning message for RTC and Reset
BRA_PRMPT JMP PROMPT ;Send to console and exit