1
0
mirror of https://github.com/RevCurtisP/C02.git synced 2024-11-29 16:51:10 +00:00
C02/include/pointer.a02

141 lines
5.0 KiB
Plaintext
Raw Normal View History

2018-01-28 18:30:49 +00:00
;C02 library pointer.h02 assembly language subroutines
;Requires External Zero Page Variables PTRLO, PTRHI
2018-01-28 18:30:49 +00:00
;External Routines MSETSRC
;ptrini - Pointer Initialization code
;Sets: TEMP0 = Memory Pointer Address
PTRINI: STX TEMP0 ;Save Address LSB
TAX ;Copy Memory Pointer to X register
LDA TEMP0 ;Retrieve Address LSB
2018-01-28 18:30:49 +00:00
RTS
;ptradr(ptr, &addr) - Return Address Stored in Pointer
;Args: A = Zero Page Pointer Address
;Sets: TEMP0 = Pointer Address
;Affects: N,Z
;Returns: A = Zero Page Pointer Address
; Y,X = New Pointer Contents
PTRADR: JSR PTRINI ;Swap A and X Registers
PTRRTN: LDY (1,X) ;Load Pointer MSB into Y
LDA (1,X) ;Load Pointer LSB into A
TAX ;and transfer to X
LDA TEMP0 ;Load Pointer Addres into A
RTS
;ptrset(ptr, &addr) - Store Address in Pointer
;Args: A = Zero Page Pointer Address
; X,Y = Address to Store
;Sets: TEMP0 = Pointer Address
;Affects: N,Z
;Returns: A = Zero Page Pointer Address
; Y,X = New Pointer Contents
PTRSET: JSR PTRINI ;Swap A and X Registers
STA 0,X ;Store in Memory Pointer LSB
STY 1,X ;Store Address MSB in Memory Pointer MSB
TXA
LDX TEMP0
RTS ;Return Pointer Address as Result
;ptrcmp(ptr, &addr) - Compare Pointer to Address
;Args: A = Zero Page Pointer Address
; X,Y = Address to Compare Against
2018-01-28 18:30:49 +00:00
;Affects N,Z
;Returns A=$01 and C=? if Pointer > Address
; A=$00 and Z=1, C=? if Pointer = Address
; A=$FF and C=? if Pointer < Address
PTRCMP: JSR PRTINI ;Swap A and X Registers
CPY 1,X ;Compare High Bytes
BCC PTRCMN ;If Pointer > Address, Return 1
BNE PTRCMF ;If Pointer < Address Return 1
CPA 0,X ;Compare Low Byte
BCC PTRCMN ;If Pointer > Address, Return 1
BNE PTRCMF ;If Pointer < Address Return 1
PTRCMZ: LDA #$00 ;Return 0
2018-01-28 18:30:49 +00:00
RTS
PTRCMN: LDA #$01 ;Return 1
2018-01-28 18:30:49 +00:00
RTS
PTRCMF: LDA #$FF ;Return 255
2018-01-28 18:30:49 +00:00
RTS
;ptrget(ptr) - Read Byte from Pointed to Address
; and Increment Pointer
;Args: A = Zero Page Pointer Address
;Affects: N, Z
2018-01-28 18:30:49 +00:00
;Returns: A = Byte at pointer address
; X = Zero Page Pointer Address
PTRGET: TAX ;Transfer Pointer Address to X
LDA (0,X) ;Load Value at Pointer
JMP PTRINN ;Increment Pointer Value
2018-01-28 18:30:49 +00:00
;ptrinc(ptr) - Increment Pointer Address
;Args: A = Zero Page Pointer Address
2018-01-28 18:30:49 +00:00
;Affects: N, Z
;Returns: A,X = Zero Page Pointer Address
PTRINC: TAX ;Transfer Pointer Address to X
PTRINN: INC (0,X) ;Increment Pointer Low Byte
BNE PTRRET ;If Zero
INC (1,X) ; Increment Pointer High Byte
PTRRET: RTS ;Return from function
2018-01-28 18:30:49 +00:00
;ptrput(ptr,byte) - Write Byte from Pointer Address
2018-01-28 18:30:49 +00:00
; and Increment Pointer
;Args: A = Zero Page Pointer Address
; Y = Byte to write
;Affects: N, Z
;Returns: A,X = Zero Page Pointer Address
PTRPUT: TAX ;Transfer Pointer Address to X
STY (0,X) ;Store Value at Pointed to Address
JMP PTRINN ;Increment Pointer
2018-01-28 18:30:49 +00:00
;ptrdec() - Decrement Pointer Address
;Args: A = Zero Page Pointer Address
2018-01-28 18:30:49 +00:00
;Affects: Y, N, Z
;Returns: A = Zero Page Pointer Address
; Y,X = New Pointer Contents
PTRDEC: TAX ;Transfer Pointer Address to X
LDY (0,X) ;Get Pointer Low Byter
BNE PTRDEL ;If Zero
DEC (1,X) ; Decrement Pointer High Byte
PTRDEL: DEC (0,X) ;Decrement Pointer Low Byte
JMP PTRRTN ;Set Registers and Return
2018-01-28 18:30:49 +00:00
;ptradd(ptr, &offset) - Add Offset to Pointer
;Args: A = Zero Page Pointer Address
; Y,X = Number of bytes to add
;Sets: TEMP0 = Pointer Address
;Affects: N, Z
;Returns: A = Zero Page Pointer Address
; Y,X = New Pointer Contents
PTRADD: JSR PRTINI ;Swap A and X Registers
CLC ;Add Offset Low Byte
ADC (0,X) ;to Pointer Low Byte
STA (0,X) ;and Save It
TYA ;Add Offset High Byte
ADC (1,X) ;to Pointer High Byte
STA (1,X) ;and Save It
JMP PTRRTN ;Set Registers and Return
;ptrsub(offset) - Subtract Offset from Pointer
;Args: A = Zero Page Pointer Address
; Y,X = Number of bytes to add
;Sets: TEMP0 = Pointer Address
; TEMP1 = Offset LSB
; TEMP2 = Offset MSB
;Affects: N, Z
;Returns: A = Zero Page Pointer Address
; Y,X = New Pointer Contents
PTRSUB: STY TEMP2 ;Save Offset MSB
STX TEMP1 ;Save Offset LSB
STA TEMP0 ;Save Pointer Address
TAX ;Transfer Pointer Address to X
LDA (0,X) ;Get Pointer Low Byte
SEC ;Subtract Offset LSB
SBC TEMP1 ;from Pointer LSB
STA PTRLO ;and Save It
LDA (1,X) ;Subtract Offset MSB
SBC TEMP1 ;from Pointer MSB
STA (1,X) ;and Save It
JMP PTRRTN ;Set Registers and Return
2018-01-28 18:30:49 +00:00