added string.append()

cleanup redundant diskio prefixes
This commit is contained in:
Irmen de Jong 2023-11-10 22:27:07 +01:00
parent e0668b55b9
commit 7ebc9c79cf
6 changed files with 66 additions and 38 deletions

View File

@ -91,7 +91,7 @@ io_error:
sub diskname() -> uword {
; returns disk label name or 0 if error
cbm.SETNAM(3, "$")
cbm.SETLFS(READ_IO_CHANNEL, diskio.drivenumber, 0)
cbm.SETLFS(READ_IO_CHANNEL, drivenumber, 0)
ubyte status = 1
void cbm.OPEN() ; open 12,8,0,"$=c"
if_cs
@ -104,12 +104,12 @@ io_error:
; skip up to entry name
}
cx16.r0 = &diskio.list_filename
cx16.r0 = &list_filename
repeat {
@(cx16.r0) = cbm.CHRIN()
if @(cx16.r0)=='"' {
@(cx16.r0) = ' '
while @(cx16.r0)==' ' and cx16.r0>=&diskio.list_filename {
while @(cx16.r0)==' ' and cx16.r0>=&list_filename {
@(cx16.r0) = 0
cx16.r0--
}
@ -124,7 +124,7 @@ io_error:
cbm.CLOSE(READ_IO_CHANNEL)
if status and status & $40 == 0
return 0
return diskio.list_filename
return list_filename
}
; internal variables for the iterative file lister / loader
@ -716,7 +716,7 @@ internal_vload:
cx16.r12 = reversebuffer + MAX_PATH_LEN-1
@(cx16.r12)=0
cbm.SETNAM(3, "$=c")
cbm.SETLFS(READ_IO_CHANNEL, diskio.drivenumber, 0)
cbm.SETLFS(READ_IO_CHANNEL, drivenumber, 0)
void cbm.OPEN() ; open 12,8,0,"$=c"
if_cs
goto io_error
@ -805,14 +805,14 @@ io_error:
; NOTE: f_seek_w() doesn't work reliably right now. I only manage to corrupt the fat32 filesystem on the sdcard with it...
; sub f_seek_w(uword pos_hiword, uword pos_loword) {
; ; -- seek in the output file opened with f_open_w, to the given 32-bits position
; diskio.f_seek.command[1] = WRITE_IO_CHANNEL ; f_open_w uses the write io channel
; diskio.f_seek.command[2] = lsb(pos_loword)
; diskio.f_seek.command[3] = msb(pos_loword)
; diskio.f_seek.command[4] = lsb(pos_hiword)
; diskio.f_seek.command[5] = msb(pos_hiword)
; goto diskio.f_seek.send_command
; }
sub f_seek_w(uword pos_hiword, uword pos_loword) {
; -- seek in the output file opened with f_open_w, to the given 32-bits position
diskio.f_seek.command[1] = WRITE_IO_CHANNEL ; f_open_w uses the write io channel
diskio.f_seek.command[2] = lsb(pos_loword)
diskio.f_seek.command[3] = msb(pos_loword)
diskio.f_seek.command[4] = lsb(pos_hiword)
diskio.f_seek.command[5] = msb(pos_hiword)
goto diskio.f_seek.send_command
}
}

View File

@ -107,7 +107,7 @@ io_error:
@(cx16.r0) = cbm.CHRIN()
if @(cx16.r0)=='"' {
@(cx16.r0) = ' '
while @(cx16.r0)==' ' and cx16.r0>=&diskio.list_filename {
while @(cx16.r0)==' ' and cx16.r0>=&list_filename {
@(cx16.r0) = 0
cx16.r0--
}

View File

@ -146,11 +146,11 @@ _startloop dey
iny
bne -
_notfound lda #0
clc
clc
rts
_found tya
sec
rts
_found tya
sec
rts
}}
}
@ -168,6 +168,31 @@ _found tya
}}
}
asmsub append(uword target @R0, uword suffix @R1) clobbers(Y) -> ubyte @A {
; Append the suffix string to the target. (make sure the buffer is large enough!)
; Returns the length of the resulting string.
%asm {{
lda cx16.r0
ldy cx16.r0+1
jsr length
sty P8ZP_SCRATCH_B1
tya
clc
adc cx16.r0
sta P8ZP_SCRATCH_W1
lda cx16.r0+1
adc #0
sta P8ZP_SCRATCH_W1+1
lda cx16.r1
ldy cx16.r1+1
jsr prog8_lib.strcpy
tya
clc
adc P8ZP_SCRATCH_B1
rts
}}
}
asmsub compare(uword string1 @R0, uword string2 @AY) clobbers(Y) -> byte @A {
; Compares two strings for sorting.
; Returns -1 (255), 0 or 1 depending on wether string1 sorts before, equal or after string2.

View File

@ -78,6 +78,13 @@ string {
}
}
sub append(str target, str suffix) -> ubyte {
; Append the suffix string to the target. (make sure the buffer is large enough!)
; Returns the length of the resulting string.
cx16.r0L = length(target)
return copy(suffix, target+cx16.r0L) + cx16.r0L
}
sub compare(str st1, str st2) -> byte {
; Compares two strings for sorting.
; Returns -1 (255), 0 or 1 depending on wether string1 sorts before, equal or after string2.

View File

@ -236,6 +236,10 @@ Provides string manipulation routines.
Often you don't have to call this explicitly and can just write ``string1 = string2``
but this function is useful if you're dealing with addresses for instance.
``append (string, suffix) -> ubyte length``
Appends the suffix string to the other string (make sure the memory buffer is large enough!)
Returns the length of the combined string.
``lower (string)``
Lowercases the PETSCII-string in place.

View File

@ -1,29 +1,21 @@
%import textio
%import string
%zeropage basicsafe
main {
sub start() {
uword address = 1000
str name = "irmen????????????"
name[5] = 0
poke(1000, 99)
ubyte prev = pokemon(1000,123)
txt.print_ub(prev)
txt.nl()
prev = pokemon(1000,0)
txt.print_ub(prev)
txt.nl()
txt.print_ub(@(1000))
txt.nl()
txt.print(name)
txt.nl()
ubyte length = string.append(name, ".prg")
poke(address+3, 99)
prev = pokemon(address+3,123)
txt.print_ub(prev)
txt.nl()
prev = pokemon(address+3,0)
txt.print_ub(prev)
txt.nl()
txt.print_ub(@(address+3))
txt.nl()
txt.print_ub(length)
txt.chrout('[')
for cx16.r0L in 0 to length-1 {
txt.chrout(name[cx16.r0L])
}
txt.chrout(']')
}
}