home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Transactor
/
Transactor_01_1983_Transactor_Publishing.d64
/
bmbstringthing
< prev
next >
Wrap
Text File
|
2023-02-26
|
3KB
|
163 lines
;general purpose routines for the pet/cbm system
;requires a 257 character buffer
;starting at a page boundary
;
;for 32k basic 4.0 only
;
chkcom = $bef5 ;check for comma
varpar = $bd98 ;evaluate expression
fltint = $c92d ;floating pt to int
synerr = $bf00 ;?syntax error
len1 = $00 ;work space
len2 = $88 ; ''
temp1 = $01 ; ''
temp2 = $89 ; ''
varptr = $44 ;current varaible pointer
integ = $11 ;int value for sys
curfil = $d2 ;current file number
buffer = $7e00 ;block get buffer, must be sealed
; ;off with poke53,126:clr
status = $96 ;st storage
aryend = $2e ;end of arrays
* = $7f02 ;starts 2 byts in due to buffer
;
; vector table
jmp blkget ;block get - sys 32514
jmp instrg ;instring - sys 32517
jmp postrg ;pos search - sys 32520
;
chkpar jsr chkcom ;check for comma and
jsr varpar ;set up pointer to string
ldy #00
rts
findab jsr chkpar ;find first string
lda (varptr),y
sta len1 ;store string 1 length
iny
lda (varptr),y
sta temp1 ;string 1 address low
iny
lda (varptr),y
sta temp1+1 ;string 1 address hi
findb jsr chkpar ;find another string
lda (varptr),y
sta len2 ;store string 2 length
iny
lda (varptr),y
sta temp2 ;string 2 address low
iny
lda (varptr),y
sta temp2+1 ;string 2 address hi
rts
kilstr sec ;get rid of old string
lda temp2+1
cmp aryend+1 ;string in text?
bcc nokill ;yes, exit
lda temp2
cmp aryend
bcc nokill
lda len2
clc
adc temp2
sta temp2
bcc nohiin
inc temp2+1
nohiin ldy #01
lda len2
sta (temp2),y
iny
lda #$ff
sta (temp2),y ;old string dead
nokill rts
;
findi jsr chkpar ;evaluate numeric
jsr fltint
lda integ+1
beq r1
jmp synerr
r1 lda integ
rts
;
;** block get routine **
blkget jsr findi ;get file number
sta curfil
lda #<buffer ;get buffer address
sta temp1
lda #>buffer
sta temp1+1
jsr findb ;find string variable
jsr kilstr ;kill old string
ldx curfil
jsr $ffc6 ;set input device
inloop jsr $ffe4 ;get a character
tax ;save char in .x
cmp #$0d ;carriage return?
beq varset ;yes, stop input
ldy #$00
sta (temp1),y ;store char in buffer
inc temp1 ;increment length
ldy temp1 ;get length
cpy #255 ;max ?
beq preset
ldy status ;more chars?
beq inloop ;yes, continue
preset txa ;get char from .x
bne varset ;last char chr$(0)?
dec temp1 ;yes, dec length
varset jsr $ffcc ;close channel
ldy #$00
lda temp1
sta (varptr),y ;stor len in pointer
iny
lda #<buffer
sta (varptr),y ;store pointer low
iny
lda #>buffer
sta (varptr),y ;store pointer hi
rts
;
;** instring routine **
instrg jsr findab ;find both variables
jsr findi ;get insert position
dec integ
lda temp2
clc
adc integ
sta temp2
bcc i1
inc temp2+1
i1 ldy #$00
i2 lda (temp1),y
sta (temp2),y ;transfer bytes
iny
cpy len1 ;end of insert
bne i2 ;no, do more
rts
;
;** position search routine **
postrg jsr findab ;find both variables
lda #$00
tax ;x reg = 0
sta $b6 ;reset position
loopp ldy #$00 ;zeroize offset
p1 lda (temp1),y ;get char at a$,y
cmp (temp2),y ;same as char at b$,y ?
bne bump ;no, move to next a$ char
iny ;yes, increment y
cpy len1 ;same as len of a$?
bne p1 ;no, more chars to compare
inc $b6 ;yes, bump position
lda $b6 ;and store it
sta $00 ;in location 0
rts
bump inc temp2 ;move to next char in b$
bne p2
inc temp2+1
p2 inc $b6 ;bump position
lda $b6
cmp len2 ;end of b$ ?
bne loopp ;no, do more compares
stx $00 ;not found
rts
.end