2018-01-28 18:30:49 +00:00
|
|
|
; C02 library stringx.h02 assembly language subroutines
|
2021-09-21 00:57:42 +00:00
|
|
|
; Requires subroutines and definitions from string.asm
|
2018-01-28 18:30:49 +00:00
|
|
|
|
2020-10-11 18:45:01 +00:00
|
|
|
SUBROUTINE STRINGX
|
|
|
|
|
2018-01-28 18:30:49 +00:00
|
|
|
;Common Code - Initialize Variables
|
2021-09-21 00:57:42 +00:00
|
|
|
.INIVAR JSR SETSRC ;Initialize Source String
|
2018-01-28 18:30:49 +00:00
|
|
|
STY TEMP1 ;Save Destination Pointer
|
|
|
|
LDX #0 ;Set End of String Flag
|
|
|
|
RTS ; and Return
|
|
|
|
|
|
|
|
;Common Code - Check Next Character in Destination String
|
2021-09-21 00:57:42 +00:00
|
|
|
.CHKNXT LDY TEMP1
|
|
|
|
LDA (DSTPTR),Y ;Get Next Character in Destination String
|
|
|
|
BEQ .POPRET ;If NUL, Return from Calling Routine
|
2018-01-28 18:30:49 +00:00
|
|
|
LDY #0 ;Initialize Source Pointer
|
|
|
|
JMP STRCHA ;Search for Character in Source and Return
|
|
|
|
|
|
|
|
;Common Code - Exit with Result
|
2021-09-21 00:57:42 +00:00
|
|
|
.POPRET PLA ;Pop Return Address Off Stack
|
2018-01-28 18:30:49 +00:00
|
|
|
PLA ; to force exit from Calling Routine
|
2021-09-21 00:57:42 +00:00
|
|
|
.RETNOF TXA ;Load End of String Flag into Accumulator
|
|
|
|
BNE .RETURN ;If 0 Then
|
|
|
|
.RETPOS LDA TEMP1 ; Load Character Position into Accumulator
|
|
|
|
.RETURN RTS ;Return
|
2018-01-28 18:30:49 +00:00
|
|
|
|
|
|
|
;strpbk(&s) - Return position of first character in Destination
|
|
|
|
; also contained in Source
|
2021-09-21 00:57:42 +00:00
|
|
|
;Requires: DSTPTR - Pointer to destination string
|
2018-01-28 18:30:49 +00:00
|
|
|
;Args: X,Y = Pointer to source string
|
2021-09-21 00:57:42 +00:00
|
|
|
;Sets: SRCPTR = Pointer to source string
|
2018-01-28 18:30:49 +00:00
|
|
|
; TEMP1 = Position of last character checked
|
|
|
|
;Uses: TEMP0
|
|
|
|
;Affects: C,X,Y
|
|
|
|
;Returns: A = Position of first character that matches
|
|
|
|
; $FF if no characters matched
|
2021-09-21 00:57:42 +00:00
|
|
|
STRPBK: JSR .INIVAR ;Initialize Variables
|
2018-01-28 18:30:49 +00:00
|
|
|
DEX ;Change End of String Flag to $FF
|
2021-09-21 00:57:42 +00:00
|
|
|
BNE .STRBRK ;Jump into strbrk subroutine
|
2018-01-28 18:30:49 +00:00
|
|
|
|
|
|
|
;strbrk(&s) - Return length of Destination with characters
|
|
|
|
; not contained in Source
|
2021-09-21 00:57:42 +00:00
|
|
|
;Requires: DSTPTR - Pointer to destination string
|
2018-01-28 18:30:49 +00:00
|
|
|
;Args: X,Y = Pointer to source string
|
2021-09-21 00:57:42 +00:00
|
|
|
;Sets: SRCPTR = Pointer to source string
|
2018-01-28 18:30:49 +00:00
|
|
|
; TEMP1 = Return value
|
|
|
|
;Uses: TEMP0
|
|
|
|
;Affects: C,X,Y
|
|
|
|
;Returns: A = Length of matching string segment
|
|
|
|
; Z = 1 if no characters matched
|
|
|
|
; N = 1 if > 127 characters matched
|
|
|
|
STRCSP: ;Alias to strbrk
|
2021-09-21 00:57:42 +00:00
|
|
|
STRBRK: JSR .INIVAR ;Initialize Variables
|
|
|
|
.STRBRK JSR .CHKNXT ;and Search for Character in Source String
|
|
|
|
BCS .RETPOS ;If Not Found
|
2018-01-28 18:30:49 +00:00
|
|
|
INC TEMP1 ; Increment Destination Pointer
|
2021-09-21 00:57:42 +00:00
|
|
|
BPL .STRBRK ; and Loop if < 128
|
|
|
|
BMI .RETNOF ;and Return Not Found
|
2018-01-28 18:30:49 +00:00
|
|
|
|
|
|
|
;strspn(&s) - Return length of Destination with characters
|
|
|
|
; contained in Source
|
2021-09-21 00:57:42 +00:00
|
|
|
;Requires: DSTPTR - Pointer to destination string
|
2018-01-28 18:30:49 +00:00
|
|
|
;Args: X,Y = Pointer to source string
|
2021-09-21 00:57:42 +00:00
|
|
|
;Sets: SRCPTR = Pointer to source string
|
2018-01-28 18:30:49 +00:00
|
|
|
; TEMP1 = Return value
|
|
|
|
;Uses: TEMP0
|
|
|
|
;Affects: C,X,Y
|
|
|
|
;Returns: A = Length of matching string segment
|
|
|
|
; Z = 1 if no characters matched
|
|
|
|
; N = 1 if > 127 characters matched
|
2021-09-21 00:57:42 +00:00
|
|
|
STRSPN: JSR .INIVAR ;Initialize Variables
|
|
|
|
.SPLOOP JSR .CHKNXT ;and Search for Character in Source String
|
|
|
|
BCC .RETPOS ;If Found
|
2018-01-28 18:30:49 +00:00
|
|
|
INC TEMP1 ; Increment Destination Pointer
|
2021-09-21 00:57:42 +00:00
|
|
|
BPL .SPLOOP ; and Loop if < 128
|
|
|
|
BMI .RETPOS ;Else Return Position
|
2018-01-28 18:30:49 +00:00
|
|
|
|
2020-10-11 18:45:01 +00:00
|
|
|
;strtok(c, &s) - Split String by Specified Character
|
|
|
|
;Args: A = Delimiter, 0 = Set String to Tokenize
|
|
|
|
; X,Y = Address of Argument String
|
|
|
|
;Sets: DSTPTR = Address of Argument String
|
|
|
|
; or Address of System Buffer (A=0)
|
|
|
|
; SRCPTR = Address of System Buffer Location
|
|
|
|
; or Address of Argument String (A=0)
|
|
|
|
; TEMP0 = Delimiter Character
|
|
|
|
;Populates: SYSBFR - String to Tokenize
|
|
|
|
;Returns: A = Length of Token
|
|
|
|
; Y = New Buffer Position, $FF = End of String
|
|
|
|
; X = End of String Flag, $00 or $FF
|
|
|
|
STRTOK: ORA #0
|
|
|
|
BNE .STRTOK ;If Delimiter is NUL
|
|
|
|
STA SYSBFP ; Initialize System Buffer Position
|
|
|
|
JMP STRCPB ; Copy String to System Buffer and Return
|
|
|
|
.STRTOK STA TEMP0 ;Save Delimiter Character
|
|
|
|
JSR SETDST ;Set Destination to String Address
|
|
|
|
JSR SETSBP ;Set Source to Current Buffer Position
|
|
|
|
BPL .STCOPY ;If at End of Buffer
|
|
|
|
LDA #0
|
|
|
|
TAY ;Set Destination String to ""
|
|
|
|
STA (DSTPTR),Y ;and Return String Length 0
|
|
|
|
RTS
|
|
|
|
.STCOPY LDY #0 ;Initialize Index
|
|
|
|
LDX #0 ;Clear End of String Flag
|
|
|
|
.STLOOP LDA (SRCPTR),Y ;Get Character from Source String
|
|
|
|
BNE .STSKIP ;If End of String
|
|
|
|
DEX ; Set End of Buffer Flag
|
|
|
|
BMI .STDONE ; and Finish Up
|
|
|
|
.STSKIP CMP TEMP0 ;
|
|
|
|
BEQ .STDONE ;If Not Delimiter Character
|
|
|
|
STA (DSTPTR),Y ; Copy to Destination String
|
|
|
|
INY ; Increment Index
|
|
|
|
CPY #SYSBFL ; If Less Than Buffer Size
|
|
|
|
BCC .STLOOP ; Loop
|
|
|
|
DEX ;Else Set End of Buffer Flag
|
|
|
|
.STDONE LDA #0 ;Terminate String
|
2021-09-21 00:57:42 +00:00
|
|
|
STA (DSTPTR),Y ;
|
2020-10-11 18:45:01 +00:00
|
|
|
.STRTN STY TEMP0 ;Save String Length
|
|
|
|
INY ;Increment Past Delimiter
|
|
|
|
TYA ; and Add to Buffer Position
|
|
|
|
CLC
|
|
|
|
ADC SYSBFP
|
|
|
|
STA SYSBFP ;Save New Buffer Position
|
|
|
|
CPX #0 ;If End of Buffer Flag is Set
|
|
|
|
BPL .STRTRN
|
|
|
|
STX SYSBFP ; Set Buffer Position to 255
|
|
|
|
.STRTRN LDA TEMP0 ;Return String Length
|
|
|
|
RTS
|
|
|
|
|
|
|
|
ENDSUBROUTINE
|