📄 strings.mod
字号:
?CompareStr pshy
ldx X_,y
ldy Y_,y
?CompareStr.Loop lda ,x ;get character at X
cmpa ,y ;is the same as the one at Y?
bne ?Compare.No ;No, get out then
tsta ;are we done with all characters?
beq ?Compare.OK ;Yes, and they all compare OK
inx ;No, let's go check next ones
iny
bra ?CompareStr.Loop
; Purpose: Convert ASCIZ string pointed to by X to uppercase
; Input : X_,y->string
; Output : X_,y->STRING
?UpString ldx X_,y ;point X to string
?UpString.Loop lda ,x
beq ?UpString.Exit
jsr Upcase ;convert to uppercase
sta ,x
cpx #RAM_END ;do not run wild outside of RAM
bhs ?UpString.Exit
inx
bne ?UpString.Loop ;avoids infinite loops
ldb #errOutOfRange
sec
rts
?UpString.Exit clc
rts
; Purpose: Convert Pascal-type string pointed to by X to uppercase
; Input : X_,y->string
; Output : X_,y->STRING
?UpPascalStr ldx X_,y ;point X to string
ldb ,x ;get length in B
beq ?UpPascalStr.Exit ;get out now, if length is 0
?UpPascalStr.Loop inx ;point to data byte
lda ,x
jsr Upcase ;convert to uppercase
sta ,x
decb
bne ?UpPascalStr.Loop
?UpPascalStr.Exit clc
rts
; Routine: Length
; Purpose: Get the length of an ASCIZ string
; Input : X points to string
; Output : B holds length if Carry Clear, error "errOutOfRange" if Carry Set
; Note(s): Maximum string length is 255 characters
?Length clrb
ldx X_,y
?Length.Loop tst ,x
beq ?Length.Exit
incb
beq ?Length.Error ;more than 255 is an error
inx
bne ?Length.Loop ;avoids infinite loops
?Length.Error ldb #errOutOfRange
sec
rts
?Length.Exit stb B_,y
clc
rts
; Routine: Insert
; Purpose: Insert a character within an ASCIZ string
; Input : X points to string
; : A holds character
; : B holds position before which to insert
; Output : None
?Insert lda A_,y
ldb B_,y
beq ?Insert.Exit ;Nothing to do, get out
ldx X_,y
decb ;Make zero-based
abx
lda ,x ;get first character
beq ?Insert.End ;are we done moving string up?
?Insert.Loop ldb 1,x ;get next character
sta 1,x
inx ;go upstring
tba ;move next char to A
bne ?Insert.Loop ;repeat until A is zero
?Insert.End sta 1,x ;save trailing zero
ldx X_,y ;now, add the character
lda A_,y
ldb B_,y
decb
abx
sta ,x
?Insert.Exit clc
rts
; Routine: Delete
; Purpose: Delete a character within an ASCIZ string
; Input : X points to ASCIZ string
; : B holds position to delete (first=1)
; Output : None
?Delete ldb B_,y
?Delete.Local beq ?Delete.Exit ;Nothing to do, get out
ldx X_,y
decb ;Make zero-based
abx
?Delete.Loop tst ,x ;check if at end-of-string
beq ?Delete.Exit ;are we done?
lda 1,x ;get next character
sta ,x ;move down one place
inx ;go upstring
bne ?Delete.Loop ;repeat (avoids infinite loops)
?Delete.Exit clc
rts
; Routine: DeleteWord
; Purpose: Delete chars until (and including) a certain char
; Input : X points to ASCIZ string
; : A holds target character (zero if for remaining string)
; Output : None
?DeleteWord lda A_,y ;get target character
ldx X_,y ;point X to buffer
ldb #1
cmpa ,x ;is first character the target?
beq ?DeleteWord.Exit ;yes, go delete it and exit
bsr ?Delete.Local ;Delete first character
bra ?DeleteWord ;repeat (need to reload regs)
?DeleteWord.Exit tsta ;to reset the zero flag
bsr ?Delete.Local ;Delete target character
clc
rts
; Routine: NoLeadChar
; Purpose: Convert leading RegB chars to RegA char
; Input : A Character to use for filling
; : B Character to be replaced
; : X->Buffer area to change leading zeros to char in RegA
; Output : X->Buffer with leading RegB characters changed to RegA character
; Note(s): Terminates at first non-matching (RegB) character
?NoLeadChar ldx X_,y
lda A_,y
ldb B_,y
?NoLeadChar.Loop cmpb ,x
bne ?NoLeadChar.Exit
sta ,x ;replace with RegA character
inx
bne ?NoLeadChar.Loop ;avoids infinite loops
?NoLeadChar.Exit clc
rts
; Routine: Garble
; Purpose: Garble buffer at X with seed in RegA
; Input : X->buffer
; : A=8-bit seed to use for garbling
; : B=Length of buffer
; Output : Buffer at X is garbled with seed in RegA
?Garble ldx X_,y
ldb B_,y
beq ?Garble.Exit ;no more bytes to process
?Garble.Loop lda ,x ;get character
eora A_,y ;XOR with user seed
sta ,x ;put character back in buffer
inx ;point to next character
decb ;are we done with all chars?
bne ?Garble.Loop
?Garble.Exit clc
rts
#ifmain
#include DISPATCH.MOD
#endif
#ROM
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -