Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/arch/z80/backend/runtime/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,16 @@ class CoreLabels:
CoreLabels.ABS32: "abs32.asm",
CoreLabels.ADDF: "arith/addf.asm",
CoreLabels.ADDSTR: "strcat.asm",
CoreLabels.ALLOC_INITIALIZED_LOCAL_ARRAY: "arrayalloc.asm",
CoreLabels.ALLOC_INITIALIZED_LOCAL_ARRAY_WITH_BOUNDS: "arrayalloc.asm",
CoreLabels.ALLOC_LOCAL_ARRAY: "arrayalloc.asm",
CoreLabels.ALLOC_LOCAL_ARRAY_WITH_BOUNDS: "arrayalloc.asm",
CoreLabels.ALLOC_INITIALIZED_LOCAL_ARRAY: "array/arrayalloc.asm",
CoreLabels.ALLOC_INITIALIZED_LOCAL_ARRAY_WITH_BOUNDS: "array/arrayalloc.asm",
CoreLabels.ALLOC_LOCAL_ARRAY: "array/arrayalloc.asm",
CoreLabels.ALLOC_LOCAL_ARRAY_WITH_BOUNDS: "array/arrayalloc.asm",
CoreLabels.AND16: "bool/and16.asm",
CoreLabels.AND32: "bool/and32.asm",
CoreLabels.ANDF: "bool/andf.asm",
CoreLabels.ARRAY: "array.asm",
CoreLabels.ARRAY_PTR: "array.asm",
CoreLabels.ARRAYSTR_FREE_MEM: "arraystrfree.asm",
CoreLabels.ARRAY: "array/array.asm",
CoreLabels.ARRAY_PTR: "array/array.asm",
CoreLabels.ARRAYSTR_FREE_MEM: "array/arraystrfree.asm",
CoreLabels.BAND16: "bitwise/band16.asm",
CoreLabels.BAND32: "bitwise/band32.asm",
CoreLabels.BNOT16: "bitwise/bnot16.asm",
Expand Down Expand Up @@ -239,7 +239,7 @@ class CoreLabels:
CoreLabels.STORE32: "store32.asm",
CoreLabels.STORE_STR: "storestr.asm",
CoreLabels.STORE_STR2: "storestr2.asm",
CoreLabels.STR_ARRAYCOPY: "strarraycpy.asm",
CoreLabels.STR_ARRAYCOPY: "array/strarraycpy.asm",
CoreLabels.STR_FAST: "str.asm",
CoreLabels.STREQ: "string.asm",
CoreLabels.STRGE: "string.asm",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,3 @@ __ARRAYSTR_FREE_MEM: ; like the above, buf also frees the array itself
jp __MEM_FREE ; Frees it and returns from __MEM_FREE

pop namespace

Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,3 @@ __ARRAYSTR_FREE_MEM: ; like the above, buf also frees the array itself
jp __MEM_FREE ; Frees it and returns from __MEM_FREE

pop namespace

126 changes: 63 additions & 63 deletions tests/functional/arch/zx48k/arraycopy5.asm
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,30 @@ _c.__DATA__:
DEFB 6Ch
DEFB 64h
;; --- end of user code ---
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/storestr.asm"
; vim:ts=4:et:sw=4
; Stores value of current string pointed by DE register into address pointed by HL
; Returns DE = Address pointer (&a$)
; Returns HL = HL (b$ => might be needed later to free it from the heap)
;
; e.g. => HL = _variableName (DIM _variableName$)
; DE = Address into the HEAP
;
; This function will resize (REALLOC) the space pointed by HL
; before copying the content of b$ into a$
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/array/strarraycpy.asm"
; (K)opyleft - by Jose M. Rodriguez de la Rosa (a.k.a. Boriel)
; 2009 - This is Free OpenSource BSD code
; vim: et:ts=4:sw=4
; Copies a vector of strings from one place to another
; reallocating strings of the destiny vector to hold source strings.
; This is used in the following code:
; DIM a$(20) : DIM b$(20): a$ = b$
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/lddede.asm"
; Loads DE into DE
; Modifies C register
; There is a routine similar to this one
; at ROM address L2AEE
push namespace core
__LOAD_DE_DE:
ex de, hl
ld c, (hl)
inc hl
ld h, (hl)
ld l, c
ex de, hl
ret
pop namespace
#line 11 "/zxbasic/src/lib/arch/zx48k/runtime/array/strarraycpy.asm"
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/strcpy.asm"
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/realloc.asm"
; vim: ts=4:et:sw=4:
Expand Down Expand Up @@ -780,58 +793,7 @@ __NOTHING_TO_COPY:
ret
ENDP
pop namespace
#line 14 "/zxbasic/src/lib/arch/zx48k/runtime/storestr.asm"
push namespace core
__PISTORE_STR: ; Indirect assignment at (IX + BC)
push ix
pop hl
add hl, bc
__ISTORE_STR: ; Indirect assignment, hl point to a pointer to a pointer to the heap!
ld c, (hl)
inc hl
ld h, (hl)
ld l, c ; HL = (HL)
__STORE_STR:
push de ; Pointer to b$
push hl ; Pointer to a$
ld c, (hl)
inc hl
ld h, (hl)
ld l, c ; HL = (HL)
call __STRASSIGN ; HL (a$) = DE (b$); HL changed to a new dynamic memory allocation
ex de, hl ; DE = new address of a$
pop hl ; Recover variable memory address pointer
ld (hl), e
inc hl
ld (hl), d ; Stores a$ ptr into element ptr
pop hl ; Returns ptr to b$ in HL (Caller might needed to free it from memory)
ret
pop namespace
#line 40 "arch/zx48k/arraycopy5.bas"
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/strarraycpy.asm"
; (K)opyleft - by Jose M. Rodriguez de la Rosa (a.k.a. Boriel)
; 2009 - This is Free OpenSource BSD code
; vim: et:ts=4:sw=4
; Copies a vector of strings from one place to another
; reallocating strings of the destiny vector to hold source strings.
; This is used in the following code:
; DIM a$(20) : DIM b$(20): a$ = b$
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/lddede.asm"
; Loads DE into DE
; Modifies C register
; There is a routine similar to this one
; at ROM address L2AEE
push namespace core
__LOAD_DE_DE:
ex de, hl
ld c, (hl)
inc hl
ld h, (hl)
ld l, c
ex de, hl
ret
pop namespace
#line 11 "/zxbasic/src/lib/arch/zx48k/runtime/strarraycpy.asm"
#line 12 "/zxbasic/src/lib/arch/zx48k/runtime/array/strarraycpy.asm"
push namespace core
STR_ARRAYCOPY:
; Copies an array of string a$ = b$
Expand Down Expand Up @@ -877,5 +839,43 @@ LOOP:
jp LOOP
ENDP
pop namespace
#line 40 "arch/zx48k/arraycopy5.bas"
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/storestr.asm"
; vim:ts=4:et:sw=4
; Stores value of current string pointed by DE register into address pointed by HL
; Returns DE = Address pointer (&a$)
; Returns HL = HL (b$ => might be needed later to free it from the heap)
;
; e.g. => HL = _variableName (DIM _variableName$)
; DE = Address into the HEAP
;
; This function will resize (REALLOC) the space pointed by HL
; before copying the content of b$ into a$
push namespace core
__PISTORE_STR: ; Indirect assignment at (IX + BC)
push ix
pop hl
add hl, bc
__ISTORE_STR: ; Indirect assignment, hl point to a pointer to a pointer to the heap!
ld c, (hl)
inc hl
ld h, (hl)
ld l, c ; HL = (HL)
__STORE_STR:
push de ; Pointer to b$
push hl ; Pointer to a$
ld c, (hl)
inc hl
ld h, (hl)
ld l, c ; HL = (HL)
call __STRASSIGN ; HL (a$) = DE (b$); HL changed to a new dynamic memory allocation
ex de, hl ; DE = new address of a$
pop hl ; Recover variable memory address pointer
ld (hl), e
inc hl
ld (hl), d ; Stores a$ ptr into element ptr
pop hl ; Returns ptr to b$ in HL (Caller might needed to free it from memory)
ret
pop namespace
#line 41 "arch/zx48k/arraycopy5.bas"
END
77 changes: 77 additions & 0 deletions tests/functional/arch/zxnext/arraycopy0.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
org 32768
.core.__START_PROGRAM:
di
push iy
ld iy, 0x5C3A ; ZX Spectrum ROM variables address
ld hl, 0
add hl, sp
ld (.core.__CALL_BACK__), hl
ei
jp .core.__MAIN_PROGRAM__
.core.__CALL_BACK__:
DEFW 0
.core.ZXBASIC_USER_DATA:
; Defines USER DATA Length in bytes
.core.ZXBASIC_USER_DATA_LEN EQU .core.ZXBASIC_USER_DATA_END - .core.ZXBASIC_USER_DATA
.core.__LABEL__.ZXBASIC_USER_DATA_LEN EQU .core.ZXBASIC_USER_DATA_LEN
.core.__LABEL__.ZXBASIC_USER_DATA EQU .core.ZXBASIC_USER_DATA
_a:
DEFB 00
_grid:
DEFW .LABEL.__LABEL0
_grid.__DATA__.__PTR__:
DEFW _grid.__DATA__
DEFW 0
DEFW 0
_grid.__DATA__:
DEFB 00h
DEFB 01h
DEFB 02h
DEFB 03h
DEFB 04h
.LABEL.__LABEL0:
DEFW 0000h
DEFB 01h
_gridcopy:
DEFW .LABEL.__LABEL1
_gridcopy.__DATA__.__PTR__:
DEFW _gridcopy.__DATA__
DEFW 0
DEFW 0
_gridcopy.__DATA__:
DEFB 00h
DEFB 00h
DEFB 00h
DEFB 00h
DEFB 00h
.LABEL.__LABEL1:
DEFW 0000h
DEFB 01h
.core.ZXBASIC_USER_DATA_END:
.core.__MAIN_PROGRAM__:
ld hl, 5
ld b, h
ld c, l
ld hl, _grid.__DATA__
ld de, _gridcopy.__DATA__
ldir
ld a, (_grid.__DATA__ + 0)
ld (_a), a
ld hl, 5
ld b, h
ld c, l
ld hl, _grid.__DATA__
ld de, _gridcopy.__DATA__
ldir
ld hl, 0
ld b, h
ld c, l
.core.__END_PROGRAM:
di
ld hl, (.core.__CALL_BACK__)
ld sp, hl
pop iy
ei
ret
;; --- end of user code ---
END
8 changes: 8 additions & 0 deletions tests/functional/arch/zxnext/arraycopy0.bas
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
DIM grid (4) as uByte => {0,1,2,3,4}
DIM gridcopy(4) as uByte

gridcopy=grid

a = grid(0)

gridcopy=grid
Loading