mirror of
https://github.com/irmen/prog8.git
synced 2024-09-10 09:54:32 +00:00
adding strcopy()
This commit is contained in:
parent
f6920172dd
commit
3b7a92f1b4
@ -83,9 +83,7 @@ io_error:
|
|||||||
name_ptrs++
|
name_ptrs++
|
||||||
@(name_ptrs) = msb(buf_ptr)
|
@(name_ptrs) = msb(buf_ptr)
|
||||||
name_ptrs++
|
name_ptrs++
|
||||||
; ubyte length = strcpy(diskio.list_filename, buf_ptr)
|
buf_ptr += strcopy(diskio.list_filename, buf_ptr) + 1
|
||||||
memcopy(diskio.list_filename, buf_ptr, strlen(list_filename)+1) ; todo replace with strcpy()
|
|
||||||
buf_ptr += strlen(list_filename)+1
|
|
||||||
files_found++
|
files_found++
|
||||||
if buf_ptr - &names_buffer > (len(names_buffer) + len(names_buffer1) - 18)
|
if buf_ptr - &names_buffer > (len(names_buffer) + len(names_buffer1) - 18)
|
||||||
break
|
break
|
||||||
|
@ -1346,3 +1346,24 @@ func_strcmp_stack .proc
|
|||||||
dex
|
dex
|
||||||
rts
|
rts
|
||||||
.pend
|
.pend
|
||||||
|
|
||||||
|
func_strcopy .proc
|
||||||
|
lda _arg_to
|
||||||
|
ldy _arg_to+1
|
||||||
|
sta P8ZP_SCRATCH_W1
|
||||||
|
sty P8ZP_SCRATCH_W1+1
|
||||||
|
lda _arg_from
|
||||||
|
ldy _arg_from+1
|
||||||
|
jsr strcpy
|
||||||
|
tya
|
||||||
|
rts
|
||||||
|
_arg_from .word 0
|
||||||
|
_arg_to .word 0
|
||||||
|
.pend
|
||||||
|
|
||||||
|
func_strcopy_to_stack .proc
|
||||||
|
jsr func_strcopy
|
||||||
|
sta P8ESTACK_LO,x
|
||||||
|
dex
|
||||||
|
rts
|
||||||
|
.pend
|
||||||
|
@ -993,6 +993,7 @@ _arg_index .byte 0
|
|||||||
strcpy .proc
|
strcpy .proc
|
||||||
; copy a string (must be 0-terminated) from A/Y to (P8ZP_SCRATCH_W1)
|
; copy a string (must be 0-terminated) from A/Y to (P8ZP_SCRATCH_W1)
|
||||||
; it is assumed the target string is large enough.
|
; it is assumed the target string is large enough.
|
||||||
|
; returns the length of the string that was copied in Y.
|
||||||
sta P8ZP_SCRATCH_W2
|
sta P8ZP_SCRATCH_W2
|
||||||
sty P8ZP_SCRATCH_W2+1
|
sty P8ZP_SCRATCH_W2+1
|
||||||
ldy #$ff
|
ldy #$ff
|
||||||
|
@ -81,6 +81,13 @@ internal class BuiltinFunctionsAsmGen(private val program: Program, private val
|
|||||||
"set_irqd" -> asmgen.out(" sei")
|
"set_irqd" -> asmgen.out(" sei")
|
||||||
"strlen" -> funcStrlen(fcall, resultToStack)
|
"strlen" -> funcStrlen(fcall, resultToStack)
|
||||||
"strcmp" -> funcStrcmp(fcall, func, resultToStack, scope)
|
"strcmp" -> funcStrcmp(fcall, func, resultToStack, scope)
|
||||||
|
"strcopy" -> {
|
||||||
|
translateArguments(fcall.args, func, scope)
|
||||||
|
if(resultToStack)
|
||||||
|
asmgen.out(" jsr prog8_lib.func_strcopy_to_stack")
|
||||||
|
else
|
||||||
|
asmgen.out(" jsr prog8_lib.func_strcopy")
|
||||||
|
}
|
||||||
"memcopy", "memset", "memsetw" -> funcMemSetCopy(fcall, func, scope)
|
"memcopy", "memset", "memsetw" -> funcMemSetCopy(fcall, func, scope)
|
||||||
"substr", "leftstr", "rightstr" -> {
|
"substr", "leftstr", "rightstr" -> {
|
||||||
translateArguments(fcall.args, func, scope)
|
translateArguments(fcall.args, func, scope)
|
||||||
|
@ -1947,24 +1947,29 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun translateBinaryOperatorWords(operator: String, types: DataType) {
|
private fun translateBinaryOperatorWords(operator: String, dt: DataType) {
|
||||||
when(operator) {
|
when(operator) {
|
||||||
"**" -> throw AssemblyError("** operator requires floats")
|
"**" -> throw AssemblyError("** operator requires floats")
|
||||||
"*" -> asmgen.out(" jsr prog8_lib.mul_word")
|
"*" -> asmgen.out(" jsr prog8_lib.mul_word")
|
||||||
"/" -> asmgen.out(if(types==DataType.UWORD) " jsr prog8_lib.idiv_uw" else " jsr prog8_lib.idiv_w")
|
"/" -> asmgen.out(if(dt==DataType.UWORD) " jsr prog8_lib.idiv_uw" else " jsr prog8_lib.idiv_w")
|
||||||
"%" -> {
|
"%" -> {
|
||||||
if(types==DataType.WORD)
|
if(dt==DataType.WORD)
|
||||||
throw AssemblyError("remainder of signed integers is not properly defined/implemented, use unsigned instead")
|
throw AssemblyError("remainder of signed integers is not properly defined/implemented, use unsigned instead")
|
||||||
asmgen.out(" jsr prog8_lib.remainder_uw")
|
asmgen.out(" jsr prog8_lib.remainder_uw")
|
||||||
}
|
}
|
||||||
"+" -> asmgen.out(" jsr prog8_lib.add_w")
|
"+" -> asmgen.out(" jsr prog8_lib.add_w")
|
||||||
"-" -> asmgen.out(" jsr prog8_lib.sub_w")
|
"-" -> asmgen.out(" jsr prog8_lib.sub_w")
|
||||||
"<<" -> throw AssemblyError("<< should not operate via stack")
|
"<<" -> asmgen.out(" jsr math.shift_left_w")
|
||||||
">>" -> throw AssemblyError(">> should not operate via stack")
|
">>" -> {
|
||||||
"<" -> asmgen.out(if(types==DataType.UWORD) " jsr prog8_lib.less_uw" else " jsr prog8_lib.less_w")
|
if(dt==DataType.UWORD)
|
||||||
">" -> asmgen.out(if(types==DataType.UWORD) " jsr prog8_lib.greater_uw" else " jsr prog8_lib.greater_w")
|
asmgen.out(" jsr math.shift_right_uw")
|
||||||
"<=" -> asmgen.out(if(types==DataType.UWORD) " jsr prog8_lib.lesseq_uw" else " jsr prog8_lib.lesseq_w")
|
else
|
||||||
">=" -> asmgen.out(if(types==DataType.UWORD) " jsr prog8_lib.greatereq_uw" else " jsr prog8_lib.greatereq_w")
|
asmgen.out(" jsr math.shift_right_w")
|
||||||
|
}
|
||||||
|
"<" -> asmgen.out(if(dt==DataType.UWORD) " jsr prog8_lib.less_uw" else " jsr prog8_lib.less_w")
|
||||||
|
">" -> asmgen.out(if(dt==DataType.UWORD) " jsr prog8_lib.greater_uw" else " jsr prog8_lib.greater_w")
|
||||||
|
"<=" -> asmgen.out(if(dt==DataType.UWORD) " jsr prog8_lib.lesseq_uw" else " jsr prog8_lib.lesseq_w")
|
||||||
|
">=" -> asmgen.out(if(dt==DataType.UWORD) " jsr prog8_lib.greatereq_uw" else " jsr prog8_lib.greatereq_w")
|
||||||
"==" -> asmgen.out(" jsr prog8_lib.equal_w")
|
"==" -> asmgen.out(" jsr prog8_lib.equal_w")
|
||||||
"!=" -> asmgen.out(" jsr prog8_lib.notequal_w") "&" -> asmgen.out(" jsr prog8_lib.bitand_w")
|
"!=" -> asmgen.out(" jsr prog8_lib.notequal_w") "&" -> asmgen.out(" jsr prog8_lib.bitand_w")
|
||||||
"^" -> asmgen.out(" jsr prog8_lib.bitxor_w")
|
"^" -> asmgen.out(" jsr prog8_lib.bitxor_w")
|
||||||
|
@ -156,6 +156,7 @@ private val functionSignatures: List<FSignature> = listOf(
|
|||||||
FParam("numwords", setOf(DataType.UWORD)),
|
FParam("numwords", setOf(DataType.UWORD)),
|
||||||
FParam("wordvalue", setOf(DataType.UWORD, DataType.WORD))), null),
|
FParam("wordvalue", setOf(DataType.UWORD, DataType.WORD))), null),
|
||||||
FSignature("strlen" , true, listOf(FParam("string", setOf(DataType.STR))), DataType.UBYTE, ::builtinStrlen),
|
FSignature("strlen" , true, listOf(FParam("string", setOf(DataType.STR))), DataType.UBYTE, ::builtinStrlen),
|
||||||
|
FSignature("strcopy" , false, listOf(FParam("from", IterableDatatypes + DataType.UWORD), FParam("to", IterableDatatypes + DataType.UWORD)), DataType.UBYTE),
|
||||||
FSignature("substr" , false, listOf(
|
FSignature("substr" , false, listOf(
|
||||||
FParam("source", IterableDatatypes + DataType.UWORD),
|
FParam("source", IterableDatatypes + DataType.UWORD),
|
||||||
FParam("target", IterableDatatypes + DataType.UWORD),
|
FParam("target", IterableDatatypes + DataType.UWORD),
|
||||||
|
@ -814,6 +814,12 @@ substr(source, target, start, length)
|
|||||||
Also, you have to make sure yourself that start and length are within bounds of the strings.
|
Also, you have to make sure yourself that start and length are within bounds of the strings.
|
||||||
Modifies in-place, doesn't return a value (so can't be used in an expression).
|
Modifies in-place, doesn't return a value (so can't be used in an expression).
|
||||||
|
|
||||||
|
strcopy(from, to)
|
||||||
|
Copy a string to another, overwriting that one. Returns the length of the string that was copied.
|
||||||
|
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.
|
||||||
|
|
||||||
|
|
||||||
Miscellaneous
|
Miscellaneous
|
||||||
^^^^^^^^^^^^^
|
^^^^^^^^^^^^^
|
||||||
exit(returncode)
|
exit(returncode)
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
TODO
|
TODO
|
||||||
====
|
====
|
||||||
|
|
||||||
- txt.clear_screen() must also position text cursor at 0,0 on both machines
|
|
||||||
- add strcpy()
|
|
||||||
- reverse mkword() again because of consistency with the platform and AY register pairs...
|
- reverse mkword() again because of consistency with the platform and AY register pairs...
|
||||||
- see if we can group some errors together for instance the (now single) errors about unidentified symbols
|
- see if we can group some errors together for instance the (now single) errors about unidentified symbols
|
||||||
- Cx16 target: support full-screen 640x480 and 320x240 graphics? That requires our own custom graphics routines though to draw lines.
|
- Cx16 target: support full-screen 640x480 and 320x240 graphics? That requires our own custom graphics routines though to draw lines.
|
||||||
|
@ -324,6 +324,10 @@ main {
|
|||||||
txt.print(result)
|
txt.print(result)
|
||||||
txt.chrout('\n')
|
txt.chrout('\n')
|
||||||
|
|
||||||
|
void strcopy(s2, s1)
|
||||||
|
txt.print_ub(99+strcopy(s2,s1))
|
||||||
|
txt.chrout('\n')
|
||||||
|
|
||||||
test_stack.test()
|
test_stack.test()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -9,22 +9,39 @@
|
|||||||
main {
|
main {
|
||||||
sub start () {
|
sub start () {
|
||||||
|
|
||||||
uword bitmap_load_address = progend()
|
str s1 = "1234567890"
|
||||||
uword max_bitmap_size = $9eff - bitmap_load_address ; TODO why is this not optimized away?
|
str s2 = "aapje"
|
||||||
|
|
||||||
; foo(2**x) ; TODO arg is zero if x=8, in the function. Param type uword. fix that . also check bit shift
|
txt.print_ub(strcopy(s2, s1))
|
||||||
; foo($0001<<x) ; TODO fix crash
|
txt.chrout('\n')
|
||||||
|
txt.print_ub(strcopy(s2, s1)+1)
|
||||||
|
txt.chrout('\n')
|
||||||
|
txt.print_ub(strlen(s2))
|
||||||
|
txt.chrout('\n')
|
||||||
|
txt.print_ub(strlen(s1))
|
||||||
|
txt.chrout('\n')
|
||||||
|
|
||||||
uword xx = progend()
|
; uword xx
|
||||||
txt.print_uwhex(xx, 1)
|
;
|
||||||
txt.print_uwhex(progend(), 1)
|
; foo(2**xx) ; TODO arg is zero if x=8, in the function. Param type uword. fix that . also check bit shift
|
||||||
|
; foo(1<<xx) ; TODO fix crash
|
||||||
uword scanline_data_ptr= $6000
|
; foo($0001<<xx) ; TODO fix crash
|
||||||
uword pixptr = x/8 + scanline_data_ptr ; TODO why is this code so much larger than the following:
|
; foo($0001>>xx) ; TODO fix crash
|
||||||
uword pixptr2 = scanline_data_ptr + x/8
|
;
|
||||||
|
;
|
||||||
|
; xx = $0001<<xx ; TODO make math.shift_left_w
|
||||||
|
; xx = $0001>>xx ; TODO make math.shift_right_(u)w
|
||||||
|
; uword scanline_data_ptr= $6000
|
||||||
|
; uword pixptr = xx/8 + scanline_data_ptr ; TODO why is this code so much larger than the following line:
|
||||||
|
; uword pixptr2 = scanline_data_ptr + xx/8
|
||||||
|
|
||||||
|
|
||||||
test_stack.test()
|
test_stack.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub foo(uword argje) {
|
||||||
|
txt.print_uwhex(argje, 1)
|
||||||
|
txt.chrout('\n')
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user