1
0
mirror of https://github.com/RevCurtisP/C02.git synced 2024-11-22 01:31:33 +00:00

Updated module stringx

This commit is contained in:
Curtis F Kaylor 2021-09-20 20:57:42 -04:00
parent d4d3453b59
commit 71fa944e55

View File

@ -1,48 +1,48 @@
; C02 library stringx.h02 assembly language subroutines ; C02 library stringx.h02 assembly language subroutines
; Requires the subroutines and definitions from string.asm ; Requires subroutines and definitions from string.asm
SUBROUTINE STRINGX SUBROUTINE STRINGX
;Common Code - Initialize Variables ;Common Code - Initialize Variables
STRXSI: JSR SETSRC ;Initialize Source String .INIVAR JSR SETSRC ;Initialize Source String
STY TEMP1 ;Save Destination Pointer STY TEMP1 ;Save Destination Pointer
LDX #0 ;Set End of String Flag LDX #0 ;Set End of String Flag
RTS ; and Return RTS ; and Return
;Common Code - Check Next Character in Destination String ;Common Code - Check Next Character in Destination String
STRXSL: LDY TEMP1 .CHKNXT LDY TEMP1
LDA (DSTLO),Y ;Get Next Character in Destination String LDA (DSTPTR),Y ;Get Next Character in Destination String
BEQ STRXST ;If NUL, Return from Calling Routine BEQ .POPRET ;If NUL, Return from Calling Routine
LDY #0 ;Initialize Source Pointer LDY #0 ;Initialize Source Pointer
JMP STRCHA ;Search for Character in Source and Return JMP STRCHA ;Search for Character in Source and Return
;Common Code - Exit with Result ;Common Code - Exit with Result
STRXST: PLA ;Pop Return Address Off Stack .POPRET PLA ;Pop Return Address Off Stack
PLA ; to force exit from Calling Routine PLA ; to force exit from Calling Routine
STRXSX: TXA ;Load End of String Flag into Accumulator .RETNOF TXA ;Load End of String Flag into Accumulator
BNE STRXSR ;If 0 Then BNE .RETURN ;If 0 Then
STRXSP: LDA TEMP1 ; Load Character Position into Accumulator .RETPOS LDA TEMP1 ; Load Character Position into Accumulator
STRXSR: RTS ;Return .RETURN RTS ;Return
;strpbk(&s) - Return position of first character in Destination ;strpbk(&s) - Return position of first character in Destination
; also contained in Source ; also contained in Source
;Requires: DSTLO, dsthi - Pointer to destination string ;Requires: DSTPTR - Pointer to destination string
;Args: X,Y = Pointer to source string ;Args: X,Y = Pointer to source string
;Sets: srclo,srchi = Pointer to source string ;Sets: SRCPTR = Pointer to source string
; TEMP1 = Position of last character checked ; TEMP1 = Position of last character checked
;Uses: TEMP0 ;Uses: TEMP0
;Affects: C,X,Y ;Affects: C,X,Y
;Returns: A = Position of first character that matches ;Returns: A = Position of first character that matches
; $FF if no characters matched ; $FF if no characters matched
STRPBK: JSR STRXSI ;Initialize Variables STRPBK: JSR .INIVAR ;Initialize Variables
DEX ;Change End of String Flag to $FF DEX ;Change End of String Flag to $FF
BNE STRBRL ;Jump into strbrk subroutine BNE .STRBRK ;Jump into strbrk subroutine
;strbrk(&s) - Return length of Destination with characters ;strbrk(&s) - Return length of Destination with characters
; not contained in Source ; not contained in Source
;Requires: DSTLO, dsthi - Pointer to destination string ;Requires: DSTPTR - Pointer to destination string
;Args: X,Y = Pointer to source string ;Args: X,Y = Pointer to source string
;Sets: srclo,srchi = Pointer to source string ;Sets: SRCPTR = Pointer to source string
; TEMP1 = Return value ; TEMP1 = Return value
;Uses: TEMP0 ;Uses: TEMP0
;Affects: C,X,Y ;Affects: C,X,Y
@ -50,30 +50,30 @@ STRPBK: JSR STRXSI ;Initialize Variables
; Z = 1 if no characters matched ; Z = 1 if no characters matched
; N = 1 if > 127 characters matched ; N = 1 if > 127 characters matched
STRCSP: ;Alias to strbrk STRCSP: ;Alias to strbrk
STRBRK: JSR STRXSI ;Initialize Variables STRBRK: JSR .INIVAR ;Initialize Variables
STRBRL: JSR STRXSL ;and Search for Character in Source String .STRBRK JSR .CHKNXT ;and Search for Character in Source String
BCS STRXSP ;If Not Found BCS .RETPOS ;If Not Found
INC TEMP1 ; Increment Destination Pointer INC TEMP1 ; Increment Destination Pointer
BPL STRBRL ; and Loop if < 128 BPL .STRBRK ; and Loop if < 128
BMI STRXSX ;and Return Not Found BMI .RETNOF ;and Return Not Found
;strspn(&s) - Return length of Destination with characters ;strspn(&s) - Return length of Destination with characters
; contained in Source ; contained in Source
;Requires: DSTLO, dsthi - Pointer to destination string ;Requires: DSTPTR - Pointer to destination string
;Args: X,Y = Pointer to source string ;Args: X,Y = Pointer to source string
;Sets: srclo,srchi = Pointer to source string ;Sets: SRCPTR = Pointer to source string
; TEMP1 = Return value ; TEMP1 = Return value
;Uses: TEMP0 ;Uses: TEMP0
;Affects: C,X,Y ;Affects: C,X,Y
;Returns: A = Length of matching string segment ;Returns: A = Length of matching string segment
; Z = 1 if no characters matched ; Z = 1 if no characters matched
; N = 1 if > 127 characters matched ; N = 1 if > 127 characters matched
STRSPN: JSR STRXSI ;Initialize Variables STRSPN: JSR .INIVAR ;Initialize Variables
STRSPL: JSR STRXSL ;and Search for Character in Source String .SPLOOP JSR .CHKNXT ;and Search for Character in Source String
BCC STRXSP ;If Found BCC .RETPOS ;If Found
INC TEMP1 ; Increment Destination Pointer INC TEMP1 ; Increment Destination Pointer
BPL STRSPL ; and Loop if < 128 BPL .SPLOOP ; and Loop if < 128
BMI STRXSP ;Else Return Position BMI .RETPOS ;Else Return Position
;strtok(c, &s) - Split String by Specified Character ;strtok(c, &s) - Split String by Specified Character
;Args: A = Delimiter, 0 = Set String to Tokenize ;Args: A = Delimiter, 0 = Set String to Tokenize
@ -113,7 +113,7 @@ STRTOK: ORA #0
BCC .STLOOP ; Loop BCC .STLOOP ; Loop
DEX ;Else Set End of Buffer Flag DEX ;Else Set End of Buffer Flag
.STDONE LDA #0 ;Terminate String .STDONE LDA #0 ;Terminate String
STA (DSTLO),Y ; STA (DSTPTR),Y ;
.STRTN STY TEMP0 ;Save String Length .STRTN STY TEMP0 ;Save String Length
INY ;Increment Past Delimiter INY ;Increment Past Delimiter
TYA ; and Add to Buffer Position TYA ; and Add to Buffer Position
@ -126,5 +126,4 @@ STRTOK: ORA #0
.STRTRN LDA TEMP0 ;Return String Length .STRTRN LDA TEMP0 ;Return String Length
RTS RTS
ENDSUBROUTINE ENDSUBROUTINE