mirror of
https://github.com/irmen/prog8.git
synced 2025-01-11 13:29:45 +00:00
added string.append()
cleanup redundant diskio prefixes
This commit is contained in:
parent
e0668b55b9
commit
7ebc9c79cf
@ -91,7 +91,7 @@ io_error:
|
|||||||
sub diskname() -> uword {
|
sub diskname() -> uword {
|
||||||
; returns disk label name or 0 if error
|
; returns disk label name or 0 if error
|
||||||
cbm.SETNAM(3, "$")
|
cbm.SETNAM(3, "$")
|
||||||
cbm.SETLFS(READ_IO_CHANNEL, diskio.drivenumber, 0)
|
cbm.SETLFS(READ_IO_CHANNEL, drivenumber, 0)
|
||||||
ubyte status = 1
|
ubyte status = 1
|
||||||
void cbm.OPEN() ; open 12,8,0,"$=c"
|
void cbm.OPEN() ; open 12,8,0,"$=c"
|
||||||
if_cs
|
if_cs
|
||||||
@ -104,12 +104,12 @@ io_error:
|
|||||||
; skip up to entry name
|
; skip up to entry name
|
||||||
}
|
}
|
||||||
|
|
||||||
cx16.r0 = &diskio.list_filename
|
cx16.r0 = &list_filename
|
||||||
repeat {
|
repeat {
|
||||||
@(cx16.r0) = cbm.CHRIN()
|
@(cx16.r0) = cbm.CHRIN()
|
||||||
if @(cx16.r0)=='"' {
|
if @(cx16.r0)=='"' {
|
||||||
@(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) = 0
|
||||||
cx16.r0--
|
cx16.r0--
|
||||||
}
|
}
|
||||||
@ -124,7 +124,7 @@ io_error:
|
|||||||
cbm.CLOSE(READ_IO_CHANNEL)
|
cbm.CLOSE(READ_IO_CHANNEL)
|
||||||
if status and status & $40 == 0
|
if status and status & $40 == 0
|
||||||
return 0
|
return 0
|
||||||
return diskio.list_filename
|
return list_filename
|
||||||
}
|
}
|
||||||
|
|
||||||
; internal variables for the iterative file lister / loader
|
; internal variables for the iterative file lister / loader
|
||||||
@ -716,7 +716,7 @@ internal_vload:
|
|||||||
cx16.r12 = reversebuffer + MAX_PATH_LEN-1
|
cx16.r12 = reversebuffer + MAX_PATH_LEN-1
|
||||||
@(cx16.r12)=0
|
@(cx16.r12)=0
|
||||||
cbm.SETNAM(3, "$=c")
|
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"
|
void cbm.OPEN() ; open 12,8,0,"$=c"
|
||||||
if_cs
|
if_cs
|
||||||
goto io_error
|
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...
|
; 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) {
|
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
|
; -- 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[1] = WRITE_IO_CHANNEL ; f_open_w uses the write io channel
|
||||||
; diskio.f_seek.command[2] = lsb(pos_loword)
|
diskio.f_seek.command[2] = lsb(pos_loword)
|
||||||
; diskio.f_seek.command[3] = msb(pos_loword)
|
diskio.f_seek.command[3] = msb(pos_loword)
|
||||||
; diskio.f_seek.command[4] = lsb(pos_hiword)
|
diskio.f_seek.command[4] = lsb(pos_hiword)
|
||||||
; diskio.f_seek.command[5] = msb(pos_hiword)
|
diskio.f_seek.command[5] = msb(pos_hiword)
|
||||||
; goto diskio.f_seek.send_command
|
goto diskio.f_seek.send_command
|
||||||
; }
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -107,7 +107,7 @@ io_error:
|
|||||||
@(cx16.r0) = cbm.CHRIN()
|
@(cx16.r0) = cbm.CHRIN()
|
||||||
if @(cx16.r0)=='"' {
|
if @(cx16.r0)=='"' {
|
||||||
@(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) = 0
|
||||||
cx16.r0--
|
cx16.r0--
|
||||||
}
|
}
|
||||||
|
@ -146,11 +146,11 @@ _startloop dey
|
|||||||
iny
|
iny
|
||||||
bne -
|
bne -
|
||||||
_notfound lda #0
|
_notfound lda #0
|
||||||
clc
|
clc
|
||||||
rts
|
rts
|
||||||
_found tya
|
_found tya
|
||||||
sec
|
sec
|
||||||
rts
|
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 {
|
asmsub compare(uword string1 @R0, uword string2 @AY) clobbers(Y) -> byte @A {
|
||||||
; Compares two strings for sorting.
|
; Compares two strings for sorting.
|
||||||
; Returns -1 (255), 0 or 1 depending on wether string1 sorts before, equal or after string2.
|
; Returns -1 (255), 0 or 1 depending on wether string1 sorts before, equal or after string2.
|
||||||
|
@ -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 {
|
sub compare(str st1, str st2) -> byte {
|
||||||
; Compares two strings for sorting.
|
; Compares two strings for sorting.
|
||||||
; Returns -1 (255), 0 or 1 depending on wether string1 sorts before, equal or after string2.
|
; Returns -1 (255), 0 or 1 depending on wether string1 sorts before, equal or after string2.
|
||||||
|
@ -236,6 +236,10 @@ Provides string manipulation routines.
|
|||||||
Often you don't have to call this explicitly and can just write ``string1 = string2``
|
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.
|
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)``
|
``lower (string)``
|
||||||
Lowercases the PETSCII-string in place.
|
Lowercases the PETSCII-string in place.
|
||||||
|
|
||||||
|
@ -1,29 +1,21 @@
|
|||||||
%import textio
|
%import textio
|
||||||
|
%import string
|
||||||
%zeropage basicsafe
|
%zeropage basicsafe
|
||||||
|
|
||||||
main {
|
main {
|
||||||
sub start() {
|
sub start() {
|
||||||
uword address = 1000
|
str name = "irmen????????????"
|
||||||
|
name[5] = 0
|
||||||
|
|
||||||
poke(1000, 99)
|
txt.print(name)
|
||||||
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.nl()
|
txt.nl()
|
||||||
|
ubyte length = string.append(name, ".prg")
|
||||||
|
|
||||||
poke(address+3, 99)
|
txt.print_ub(length)
|
||||||
prev = pokemon(address+3,123)
|
txt.chrout('[')
|
||||||
txt.print_ub(prev)
|
for cx16.r0L in 0 to length-1 {
|
||||||
txt.nl()
|
txt.chrout(name[cx16.r0L])
|
||||||
prev = pokemon(address+3,0)
|
}
|
||||||
txt.print_ub(prev)
|
txt.chrout(']')
|
||||||
txt.nl()
|
|
||||||
txt.print_ub(@(address+3))
|
|
||||||
txt.nl()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user