1
0
mirror of https://github.com/RevCurtisP/C02.git synced 2024-11-15 17:08:51 +00:00
C02/include/stddef.a02
2020-10-11 14:45:01 -04:00

160 lines
4.2 KiB
Plaintext

;c02 library stddef.h02 assembly language subroutines
;Requires External Zero Page Variables DSTPTR, SRCPTR
;and External Variables TEMP0, TEMP1, TEMP2 (system header)
SUBROUTINE STDDEF
;Constant Definitions
STRSIZ EQU 128 ;Maximum String Size
TRUE EQU $FF ;Returned for Success or Failure
FALSE EQU $00 ;by some Library Routines
;savdst() - Save Destination Pointer
SAVDST: JSR GETDST ;Load Destination Pointer
BVC SAVRXY ;Save X & Y Registers
;savsrc() - Save Source Pointer
SAVSRC: JSR GETSRC ;Load Destination Pointer
BVC SAVRXY ;Save X & Y Registers
;Save Registers
SAVREG: STA TEMP0 ;Save Accumulater
SAVRXY: STX TEMP1 ;Save X Index
STY TEMP2 ;Save Y Index
RTS
;Restore Registers
RESREG: LDA TEMP0 ;Load Accumulator
RESRXY: LDX TEMP1 ;Load X Index
LDY TEMP2 ;Load Y Index
RTS
;Set Destination Pointer to System Buffer
SETDSB: JSR GETBFR ;Get Buffer Address
BVC SETDST
;Set Destination Pointer to Source Pointer
SETDSS: JSR GETSRC ;Get Destination Pointer
BVC SETDST ;Store in Source Pointer
;Restore Destination Pointer
RESDST: JSR RESRXY ;Load Address and Drop into SETDST
;Initialize Destination Pointer
SETDST: STX DSTPTR ;Store Destination Pointer
STY DSTPTR+1
RTS
;Restore Source Pointer
RESSRC: JSR RESRXY ;Load Saved Address
BVC SETSRC ;Set Source Pointer
;Set Source Pointer to System Buffer
SETSRB: JSR GETBFR ;Get Buffer Address
BVC SETSRC
;Set Source Pointer to Destination Pointer
SETSRD: JSR GETDST ;Get Destination Point and fall into SETSRC
;Initialize Source Pointer and Index
SETSRC: STX SRCPTR ;Store Source Pointer
STY SRCPTR+1
LDY #$00 ;Initialize Index Into String
RTS
;Retrieve System Buffer Address
GETBFR: LDX #<SYSBFR
LDY #>SYSBFR
CLV ;Clear Overflow Flag for BVC
RTS
;Retrieve Source String Pointer
GETDST: LDX DSTPTR
LDY DSTPTR+1
CLV ;Clear Overflow Flag for BVC
RTS
;Retrieve Source String Pointer
GETSRC: LDX SRCPTR
LDY SRCPTR+1
CLV ;Clear Overflow Flag for BVC
RTS
;Add TEMP1,TEMP2 to X,Y
ADDTXY: TXA
CLC
ADC TEMP1
TAX
TYA
ADC TEMP2
TAY
RTS
;Subtract TEMP1,TEMP2 from X,Y
SUBTXY: TXA
SEC
SBC TEMP1
TAX
TYA
SBC TEMP2
TAY
RTS
;Decrement X,Y Register Pair
DECRXY: CPY #0
BNE .SKIP
DEY
.SKIP DEX
RTS
;Increment X,Y Register Pair
INCRXY: INX
BNE .RETURN
INY
.RETURN RTS
;Set Source Pointer to Buffer Location and Add Accumulator
SETDBA: LDA SYSBFP ;Get Buffer Position
JSR SETDSB ;Set Destination to Buffer Address
;Add Accumulator to Destination Address
ADDDSA: TAX ;Move Accumulator to Argument LSB
LDY #0 ;Clear Argument MSB
;Add to Destination Address
;Args: Y,X = MSB,LSB of Integer to Add
;Affects: A,Y,X
ADDDST: LDA #DSTPTR ;Set Index to Destination Pointer
BNE ADDZPW ;and Execute ADDZPW
;Set Source Pointer to System Buffer Position
SETSBP: LDA SYSBFP ;Load Position in Buffer
BMI .RETURN ;If Greater than 127, Return
JSR SETSRB ;Set Source Pointer to Buffer Address
;Add Accumulator to Source Address
ADDSRA: TAX ;Move Accumulator to Argument LSB
LDY #0 ;Clear Argument MSB
;Add to Source Address
;Args: Y,X = MSB,LSB of Integer to Add
;Affects: A,Y,X
ADDSRC: LDA #SRCPTR ;Set Index and Drop into ADDZPW
;Add to Zero Page Word
;Args: A = Address of Zero Page Word
; Y,X = MSB,LSB of Integer to Add
;Affects: A
ADDZPW: STA TEMP3 ;Save Zero Page Address
TXA ;Move Argument LSB to Accumulator
LDX TEMP3 ;Set Index to Zero Page Address
CLC ;Clear Carry
ADC 0,X ;Add Argument LSB to Target LSB
STA 0,X ;and Save Result
TYA ;Move Argument MSB to Accumulator
ADC 1,X ;Add Argument MSB to Target MSB
STA 1,X ;and Save Result
RTS
ENDSUBROUTINE