mirror of
https://github.com/irmen/prog8.git
synced 2025-02-16 22:30:46 +00:00
adding strcopy()
This commit is contained in:
parent
f6920172dd
commit
3b7a92f1b4
@ -83,9 +83,7 @@ io_error:
|
||||
name_ptrs++
|
||||
@(name_ptrs) = msb(buf_ptr)
|
||||
name_ptrs++
|
||||
; ubyte length = strcpy(diskio.list_filename, buf_ptr)
|
||||
memcopy(diskio.list_filename, buf_ptr, strlen(list_filename)+1) ; todo replace with strcpy()
|
||||
buf_ptr += strlen(list_filename)+1
|
||||
buf_ptr += strcopy(diskio.list_filename, buf_ptr) + 1
|
||||
files_found++
|
||||
if buf_ptr - &names_buffer > (len(names_buffer) + len(names_buffer1) - 18)
|
||||
break
|
||||
|
@ -1346,3 +1346,24 @@ func_strcmp_stack .proc
|
||||
dex
|
||||
rts
|
||||
.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
|
||||
; copy a string (must be 0-terminated) from A/Y to (P8ZP_SCRATCH_W1)
|
||||
; it is assumed the target string is large enough.
|
||||
; returns the length of the string that was copied in Y.
|
||||
sta P8ZP_SCRATCH_W2
|
||||
sty P8ZP_SCRATCH_W2+1
|
||||
ldy #$ff
|
||||
|
@ -81,6 +81,13 @@ internal class BuiltinFunctionsAsmGen(private val program: Program, private val
|
||||
"set_irqd" -> asmgen.out(" sei")
|
||||
"strlen" -> funcStrlen(fcall, resultToStack)
|
||||
"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)
|
||||
"substr", "leftstr", "rightstr" -> {
|
||||
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) {
|
||||
"**" -> throw AssemblyError("** operator requires floats")
|
||||
"*" -> 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")
|
||||
asmgen.out(" jsr prog8_lib.remainder_uw")
|
||||
}
|
||||
"+" -> asmgen.out(" jsr prog8_lib.add_w")
|
||||
"-" -> asmgen.out(" jsr prog8_lib.sub_w")
|
||||
"<<" -> throw AssemblyError("<< should not operate via stack")
|
||||
">>" -> throw AssemblyError(">> should not operate via stack")
|
||||
"<" -> asmgen.out(if(types==DataType.UWORD) " jsr prog8_lib.less_uw" else " jsr prog8_lib.less_w")
|
||||
">" -> asmgen.out(if(types==DataType.UWORD) " jsr prog8_lib.greater_uw" else " jsr prog8_lib.greater_w")
|
||||
"<=" -> asmgen.out(if(types==DataType.UWORD) " jsr prog8_lib.lesseq_uw" else " jsr prog8_lib.lesseq_w")
|
||||
">=" -> asmgen.out(if(types==DataType.UWORD) " jsr prog8_lib.greatereq_uw" else " jsr prog8_lib.greatereq_w")
|
||||
"<<" -> asmgen.out(" jsr math.shift_left_w")
|
||||
">>" -> {
|
||||
if(dt==DataType.UWORD)
|
||||
asmgen.out(" jsr math.shift_right_uw")
|
||||
else
|
||||
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.notequal_w") "&" -> asmgen.out(" jsr prog8_lib.bitand_w")
|
||||
"^" -> asmgen.out(" jsr prog8_lib.bitxor_w")
|
||||
|
@ -156,6 +156,7 @@ private val functionSignatures: List<FSignature> = listOf(
|
||||
FParam("numwords", setOf(DataType.UWORD)),
|
||||
FParam("wordvalue", setOf(DataType.UWORD, DataType.WORD))), null),
|
||||
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(
|
||||
FParam("source", 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.
|
||||
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
|
||||
^^^^^^^^^^^^^
|
||||
exit(returncode)
|
||||
|
@ -2,8 +2,6 @@
|
||||
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...
|
||||
- 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.
|
||||
|
@ -324,6 +324,10 @@ main {
|
||||
txt.print(result)
|
||||
txt.chrout('\n')
|
||||
|
||||
void strcopy(s2, s1)
|
||||
txt.print_ub(99+strcopy(s2,s1))
|
||||
txt.chrout('\n')
|
||||
|
||||
test_stack.test()
|
||||
|
||||
}
|
||||
|
@ -9,22 +9,39 @@
|
||||
main {
|
||||
sub start () {
|
||||
|
||||
uword bitmap_load_address = progend()
|
||||
uword max_bitmap_size = $9eff - bitmap_load_address ; TODO why is this not optimized away?
|
||||
str s1 = "1234567890"
|
||||
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
|
||||
; foo($0001<<x) ; TODO fix crash
|
||||
txt.print_ub(strcopy(s2, s1))
|
||||
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()
|
||||
txt.print_uwhex(xx, 1)
|
||||
txt.print_uwhex(progend(), 1)
|
||||
|
||||
uword scanline_data_ptr= $6000
|
||||
uword pixptr = x/8 + scanline_data_ptr ; TODO why is this code so much larger than the following:
|
||||
uword pixptr2 = scanline_data_ptr + x/8
|
||||
; uword xx
|
||||
;
|
||||
; 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
|
||||
; foo($0001<<xx) ; TODO fix crash
|
||||
; foo($0001>>xx) ; TODO fix crash
|
||||
;
|
||||
;
|
||||
; 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()
|
||||
}
|
||||
|
||||
sub foo(uword argje) {
|
||||
txt.print_uwhex(argje, 1)
|
||||
txt.chrout('\n')
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user