mirror of
https://github.com/RevCurtisP/C02.git
synced 2024-11-29 01:49:19 +00:00
90 lines
2.9 KiB
Plaintext
90 lines
2.9 KiB
Plaintext
;C02 library pointer.h02 assembly language subroutines
|
|
;Requires External Zero Page Variables PTRLO, PTRHI
|
|
;External Routines MSETSRC
|
|
|
|
;ptrset(&a) - Store Address in Pointer
|
|
;Args: A = Zero Page Pointer Locatione
|
|
; X,Y = Address
|
|
;Sets: PTRLO, PTRHI = Pointer
|
|
PTRSET: STX PTRLO ;Pointer Low Byte
|
|
STY PTRHI ;Pointer Start High Byte
|
|
RTS
|
|
|
|
;ptrcmp(&a) - Compare Pointer to Address
|
|
;Requires: PTRLO, PTRHI - Pointer
|
|
;Args: X,Y = Address to Compare Against
|
|
;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: CPY PTRHI ;Compare High Bytes
|
|
BCC PTRCMN ;If Pointer > Address, Return 1
|
|
BNE PTRCMF ;If Pointer < Address Return 1
|
|
CPX PTRLO ;Compare Low Byte
|
|
BCC PTRCMN ;If Pointer > Address, Return 1
|
|
BNE PTRCMF ;If Pointer < Address Return 1
|
|
PTRCMZ: LDA #$00 ;Return 0
|
|
RTS
|
|
PTRCMN: LDA #$01 ;Return 1
|
|
RTS
|
|
PTRCMF: LDA #$FF ;Return 255
|
|
RTS
|
|
|
|
;ptrget() - Read Byte from Pointer Address
|
|
; and Increment Pointer
|
|
;Sets: PTRLO, PTRSHI = New pointer address
|
|
;Returns: A = Byte at pointer address
|
|
;Affects: Y, N, Z
|
|
PTRGET: LDY #0 ;Set Offset to 0
|
|
LDA (PTRLO),Y ;Load Value at Pointer
|
|
|
|
;ptrinc() - Increment Pointer Address
|
|
;Sets: PTRLO, PTRSHI = New pointer address
|
|
;Affects: N, Z
|
|
PTRINC: INC PTRLO ;Increment Pointer Low Byte
|
|
BNE PTRRET ;If Zero
|
|
INC PTRHI ; Increment Pointer High Byte
|
|
PTRRET: RTS ;Return from function
|
|
|
|
;ptrput() - Write Byte from Pointer Address
|
|
; and Increment Pointer
|
|
;Args: A = Byte to write
|
|
;Sets: PTRLO, PTRSHI = New pointer address
|
|
;Affects: Y, N, Z
|
|
PTRPUT: LDY #0 ;Set Offset to 0
|
|
STA (PTRLO),Y ;Load Value at Pointer
|
|
JMP PTRINC ;Increment Pointer
|
|
|
|
;ptrdec() - Decrement Pointer Address
|
|
;Sets: PTRLO, PTRSHI = New pointer address
|
|
;Affects: Y, N, Z
|
|
PTRDEC: LDY PTRLO ;Get Pointer Low Byter
|
|
BNE PTRDEL ;If Zero
|
|
DEC PTRHI ; Deccrement Pointer High Byte
|
|
PTRDEL: DEC PTRLO ;Decrement Pointer Low Byte
|
|
RTS ;Return from function
|
|
|
|
;ptradd() - Add Offset to Pointer
|
|
;Args: A = Number of bytes to add
|
|
;Sets: PTRLO, PTRSHI = New pointer address
|
|
;Affects: A, N, Z
|
|
PTRADD: CLC ;Add Offset to Low Byte
|
|
ADC PTRLO
|
|
STA PTRLO ;And Save It
|
|
BCC PTRRET ;If Carry
|
|
INC PTRHI ; Increment High Byte
|
|
RTS
|
|
|
|
;ptrsub() - Subtract Offset from Pointer
|
|
;Args: A = Number of bytes to subtract
|
|
;Sets: PTRLO, PTRSHI = New pointer address
|
|
;Affects: A, N, Z
|
|
PTRSUB: STA TEMP0 ;Save Offset
|
|
LDA PTRLO ;Get Pointer Low Byte
|
|
SEC ;Subtract Offset
|
|
SBC TEMP0 ;
|
|
STA PTRLO ;And Save New Low Byte
|
|
BCS PTRRET ;If Borrow
|
|
DEC PTRHI ; Decrement High Byte
|
|
RTS
|