; 8-byte read/add/write routine. ; Goes at ROM offset 0x80. ; Used to copy and/or modify pointers in the host heap. ; Upon entry: ; 0x20 contains the 6502 address to read 8 bytes from. ; 0x22 contains the 6502 address of a 4-byte addition constant. ; 0x24 contains the 6502 address to write 8 bytes to. ; The read and write address may be the same. ; The addition constant may be 0, of course. ; The addition constant may be negative. ; Note that to save space, the addition constant is 4 bytes. ; The last byte of the addition constant should be 0 or 0xff. ; It will be re-used for the most significant 4 bytes. CLC LDY #0 loop: LDA ($20),Y ADC ($22),Y STA ($24),Y INY TYA ; Note: use AND here instead of CPY to avoid carry flag AND #4 BEQ less_than_four DEC $22 less_than_four: TYA AND #8 BEQ loop RTS