1
0
mirror of https://github.com/RevCurtisP/C02.git synced 2024-11-18 21:07:28 +00:00
C02/include/stddef.a02

160 lines
4.2 KiB
Plaintext
Raw Normal View History

;c02 library stddef.h02 assembly language subroutines
;Requires External Zero Page Variables DSTPTR, SRCPTR
;and External Variables TEMP0, TEMP1, TEMP2 (system header)
SUBROUTINE STDDEF
2018-07-27 18:11:39 +00:00
;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
2019-03-24 20:29:19 +00:00
;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
2019-03-23 00:30:49 +00:00
;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
2019-03-23 00:30:49 +00:00
2020-09-08 15:51:30 +00:00
;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
2020-09-08 15:51:30 +00:00
DEY
.SKIP DEX
2020-09-08 15:51:30 +00:00
RTS
;Increment X,Y Register Pair
INCRXY: INX
BNE .RETURN
2020-09-08 15:51:30 +00:00
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
2020-09-08 15:51:30 +00:00
;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