2018-07-27 17:38:47 +00:00
|
|
|
;c02 library stddef.h02 assembly language subroutines
|
2020-10-11 18:45:01 +00:00
|
|
|
;Requires External Zero Page Variables DSTPTR, SRCPTR
|
|
|
|
;and External Variables TEMP0, TEMP1, TEMP2 (system header)
|
|
|
|
|
|
|
|
SUBROUTINE STDDEF
|
2018-07-27 17:38:47 +00:00
|
|
|
|
2018-07-27 18:11:39 +00:00
|
|
|
;Constant Definitions
|
2020-10-11 18:45:01 +00:00
|
|
|
STRSIZ EQU 128 ;Maximum String Size
|
2018-07-27 17:38:47 +00:00
|
|
|
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
|
2020-10-11 18:45:01 +00:00
|
|
|
BVC SAVRXY ;Save X & Y Registers
|
2018-07-27 17:38:47 +00:00
|
|
|
|
2019-03-24 20:29:19 +00:00
|
|
|
;savsrc() - Save Source Pointer
|
2018-07-27 17:38:47 +00:00
|
|
|
SAVSRC: JSR GETSRC ;Load Destination Pointer
|
2020-10-11 18:45:01 +00:00
|
|
|
BVC SAVRXY ;Save X & Y Registers
|
2018-07-27 17:38:47 +00:00
|
|
|
|
|
|
|
;Save Registers
|
|
|
|
SAVREG: STA TEMP0 ;Save Accumulater
|
|
|
|
SAVRXY: STX TEMP1 ;Save X Index
|
|
|
|
STY TEMP2 ;Save Y Index
|
|
|
|
RTS
|
|
|
|
|
|
|
|
;Restore Registers
|
2020-10-11 18:45:01 +00:00
|
|
|
RESREG: LDA TEMP0 ;Load Accumulator
|
|
|
|
RESRXY: LDX TEMP1 ;Load X Index
|
|
|
|
LDY TEMP2 ;Load Y Index
|
2018-07-27 17:38:47 +00:00
|
|
|
RTS
|
|
|
|
|
2020-10-11 18:45:01 +00:00
|
|
|
;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
|
2020-10-11 18:45:01 +00:00
|
|
|
SETDSS: JSR GETSRC ;Get Destination Pointer
|
|
|
|
BVC SETDST ;Store in Source Pointer
|
2018-07-30 22:35:35 +00:00
|
|
|
|
2018-07-27 17:38:47 +00:00
|
|
|
;Restore Destination Pointer
|
2020-10-11 18:45:01 +00:00
|
|
|
RESDST: JSR RESRXY ;Load Address and Drop into SETDST
|
2018-07-27 17:38:47 +00:00
|
|
|
|
|
|
|
;Initialize Destination Pointer
|
2020-10-11 18:45:01 +00:00
|
|
|
SETDST: STX DSTPTR ;Store Destination Pointer
|
|
|
|
STY DSTPTR+1
|
2018-07-27 17:38:47 +00:00
|
|
|
RTS
|
|
|
|
|
|
|
|
;Restore Source Pointer
|
2020-10-11 18:45:01 +00:00
|
|
|
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
|
2018-07-27 17:38:47 +00:00
|
|
|
|
|
|
|
;Set Source Pointer to Destination Pointer
|
2020-10-11 18:45:01 +00:00
|
|
|
SETSRD: JSR GETDST ;Get Destination Point and fall into SETSRC
|
2018-07-27 17:38:47 +00:00
|
|
|
|
|
|
|
;Initialize Source Pointer and Index
|
2020-10-11 18:45:01 +00:00
|
|
|
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
|
2018-07-27 17:38:47 +00:00
|
|
|
RTS
|
|
|
|
|
|
|
|
;Retrieve Source String Pointer
|
2020-10-11 18:45:01 +00:00
|
|
|
GETDST: LDX DSTPTR
|
|
|
|
LDY DSTPTR+1
|
|
|
|
CLV ;Clear Overflow Flag for BVC
|
2018-07-27 17:38:47 +00:00
|
|
|
RTS
|
|
|
|
|
|
|
|
;Retrieve Source String Pointer
|
2020-10-11 18:45:01 +00:00
|
|
|
GETSRC: LDX SRCPTR
|
|
|
|
LDY SRCPTR+1
|
|
|
|
CLV ;Clear Overflow Flag for BVC
|
2018-07-27 17:38:47 +00:00
|
|
|
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
|
2020-10-11 18:45:01 +00:00
|
|
|
BNE .SKIP
|
2020-09-08 15:51:30 +00:00
|
|
|
DEY
|
2020-10-11 18:45:01 +00:00
|
|
|
.SKIP DEX
|
2020-09-08 15:51:30 +00:00
|
|
|
RTS
|
|
|
|
|
|
|
|
;Increment X,Y Register Pair
|
|
|
|
INCRXY: INX
|
2020-10-11 18:45:01 +00:00
|
|
|
BNE .RETURN
|
2020-09-08 15:51:30 +00:00
|
|
|
INY
|
2020-10-11 18:45:01 +00:00
|
|
|
.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
|
|
|
|
2019-05-27 21:12:10 +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
|
2020-10-11 18:45:01 +00:00
|
|
|
ADDDST: LDA #DSTPTR ;Set Index to Destination Pointer
|
2019-05-27 21:12:10 +00:00
|
|
|
BNE ADDZPW ;and Execute ADDZPW
|
|
|
|
|
2020-10-11 18:45:01 +00:00
|
|
|
;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
|
|
|
|
|
2019-05-27 21:12:10 +00:00
|
|
|
;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
|
2020-10-11 18:45:01 +00:00
|
|
|
ADDSRC: LDA #SRCPTR ;Set Index and Drop into ADDZPW
|
2019-05-27 21:12:10 +00:00
|
|
|
|
|
|
|
;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
|
|
|
|
|
2020-10-11 18:45:01 +00:00
|
|
|
ENDSUBROUTINE
|