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
4 changes: 2 additions & 2 deletions src/arch/z80/backend/runtime/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class CoreLabels:
CoreLabels.FP_PUSH_REV: "pushf.asm",
CoreLabels.FTOF16REG: "ftof16reg.asm",
CoreLabels.FTOU32REG: "ftou32reg.asm",
CoreLabels.LBOUND: "bound.asm",
CoreLabels.LBOUND: "array/arraybound.asm",
CoreLabels.LEF: "cmp/lef.asm",
CoreLabels.LEI16: "cmp/lei16.asm",
CoreLabels.LEI32: "cmp/lei32.asm",
Expand Down Expand Up @@ -254,7 +254,7 @@ class CoreLabels:
CoreLabels.SWAP32: "swap32.asm",
CoreLabels.U32TOFREG: "u32tofreg.asm",
CoreLabels.U8TOFREG: "u32tofreg.asm",
CoreLabels.UBOUND: "bound.asm",
CoreLabels.UBOUND: "array/arraybound.asm",
CoreLabels.XOR16: "bool/xor16.asm",
CoreLabels.XOR8: "bool/xor8.asm",
CoreLabels.XOR32: "bool/xor32.asm",
Expand Down
156 changes: 78 additions & 78 deletions tests/functional/arch/zx48k/lbound12.asm
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,84 @@ __ALLOC_INITIALIZED_LOCAL_ARRAY:
#line 142 "/zxbasic/src/lib/arch/zx48k/runtime/array/arrayalloc.asm"
pop namespace
#line 98 "arch/zx48k/lbound12.bas"
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/array/arraybound.asm"
; ---------------------------------------------------------
; Copyleft (k)2011 by Jose Rodriguez (a.k.a. Boriel)
; http://www.boriel.com
;
; ZX BASIC Compiler http://www.zxbasic.net
; This code is released under the BSD License
; ---------------------------------------------------------
; Implements both LBOUND(array, N) and UBOUND(array, N) function
; Parameters:
; HL = PTR to array
; [stack - 2] -> N (dimension)
push namespace core
PROC
LOCAL __BOUND
LOCAL __DIM_NOT_EXIST
LOCAL __CONT
__LBOUND:
ld a, 4
jr __BOUND
__UBOUND:
ld a, 6
__BOUND:
ex de, hl ; DE <-- Array ptr
pop hl ; HL <-- Ret address
ex (sp), hl ; CALLEE: HL <-- N, (SP) <-- Ret address
ex de, hl ; DE <-- N, HL <-- ARRAY_PTR
push hl
ld c, (hl)
inc hl
ld h, (hl)
ld l, c ; HL = start of dimension table (first position contains number of dimensions - 1)
ld c, (hl)
inc hl
ld b, (hl)
inc bc ; Number of total dimensions of the array
pop hl ; Recovers ARRAY PTR
ex af, af' ; Saves A for later
ld a, d
or e
jr nz, __CONT ; N = 0 => Return number of dimensions
;; Return the number of dimensions of the array
ld h, b
ld l, c
ret
__CONT:
dec de
ex af, af' ; Recovers A (contains PTR offset)
ex de, hl ; HL = N (dimension asked) - 1, DE = Array PTR
or a
sbc hl, bc ; if no Carry => the user asked for a dimension that does not exist. Return 0
jr nc, __DIM_NOT_EXIST
add hl, bc ; restores HL = (N - 1)
add hl, hl ; hl *= 2
ex de, hl ; hl = ARRAY_PTR + 3, DE jsz = (N - 1) * 2
ld b, 0
ld c, a
add hl, bc ; HL = &BOUND_PTR
ld a, (hl)
inc hl
ld h, (hl)
ld l, a ; LD HL, (HL) => Origin of L/U Bound table
; for LBound only, HL = 0x0000 (NULL) if the array is all 0-based
or h
ret z ; Should never happen for UBound
add hl, de ; hl += OFFSET __LBOUND._xxxx
ld e, (hl) ; de = (hl)
inc hl
ld d, (hl)
ex de, hl ; hl = de => returns result in HL
ret
__DIM_NOT_EXIST:
; The dimension requested by the user does not exists. Return 0
ld hl, 0
ret
ENDP
pop namespace
#line 99 "arch/zx48k/lbound12.bas"
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/array/arraystrfree.asm"
; This routine is in charge of freeing an array of strings from memory
; HL = Pointer to start of array in memory
Expand Down Expand Up @@ -742,84 +820,6 @@ __ARRAYSTR_FREE_MEM: ; like the above, buf also frees the array itself
pop hl ; recovers array block pointer
jp __MEM_FREE ; Frees it and returns from __MEM_FREE
pop namespace
#line 99 "arch/zx48k/lbound12.bas"
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/bound.asm"
; ---------------------------------------------------------
; Copyleft (k)2011 by Jose Rodriguez (a.k.a. Boriel)
; http://www.boriel.com
;
; ZX BASIC Compiler http://www.zxbasic.net
; This code is released under the BSD License
; ---------------------------------------------------------
; Implements both LBOUND(array, N) and UBOUND(array, N) function
; Parameters:
; HL = PTR to array
; [stack - 2] -> N (dimension)
push namespace core
PROC
LOCAL __BOUND
LOCAL __DIM_NOT_EXIST
LOCAL __CONT
__LBOUND:
ld a, 4
jr __BOUND
__UBOUND:
ld a, 6
__BOUND:
ex de, hl ; DE <-- Array ptr
pop hl ; HL <-- Ret address
ex (sp), hl ; CALLEE: HL <-- N, (SP) <-- Ret address
ex de, hl ; DE <-- N, HL <-- ARRAY_PTR
push hl
ld c, (hl)
inc hl
ld h, (hl)
ld l, c ; HL = start of dimension table (first position contains number of dimensions - 1)
ld c, (hl)
inc hl
ld b, (hl)
inc bc ; Number of total dimensions of the array
pop hl ; Recovers ARRAY PTR
ex af, af' ; Saves A for later
ld a, d
or e
jr nz, __CONT ; N = 0 => Return number of dimensions
;; Return the number of dimensions of the array
ld h, b
ld l, c
ret
__CONT:
dec de
ex af, af' ; Recovers A (contains PTR offset)
ex de, hl ; HL = N (dimension asked) - 1, DE = Array PTR
or a
sbc hl, bc ; if no Carry => the user asked for a dimension that does not exist. Return 0
jr nc, __DIM_NOT_EXIST
add hl, bc ; restores HL = (N - 1)
add hl, hl ; hl *= 2
ex de, hl ; hl = ARRAY_PTR + 3, DE jsz = (N - 1) * 2
ld b, 0
ld c, a
add hl, bc ; HL = &BOUND_PTR
ld a, (hl)
inc hl
ld h, (hl)
ld l, a ; LD HL, (HL) => Origin of L/U Bound table
; for LBound only, HL = 0x0000 (NULL) if the array is all 0-based
or h
ret z ; Should never happen for UBound
add hl, de ; hl += OFFSET __LBOUND._xxxx
ld e, (hl) ; de = (hl)
inc hl
ld d, (hl)
ex de, hl ; hl = de => returns result in HL
ret
__DIM_NOT_EXIST:
; The dimension requested by the user does not exists. Return 0
ld hl, 0
ret
ENDP
pop namespace
#line 100 "arch/zx48k/lbound12.bas"
.LABEL.__LABEL5:
DEFB 01h
Expand Down
156 changes: 78 additions & 78 deletions tests/functional/arch/zx48k/ubound12.asm
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,84 @@ __ALLOC_INITIALIZED_LOCAL_ARRAY_WITH_BOUNDS:
#line 142 "/zxbasic/src/lib/arch/zx48k/runtime/array/arrayalloc.asm"
pop namespace
#line 110 "arch/zx48k/ubound12.bas"
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/array/arraybound.asm"
; ---------------------------------------------------------
; Copyleft (k)2011 by Jose Rodriguez (a.k.a. Boriel)
; http://www.boriel.com
;
; ZX BASIC Compiler http://www.zxbasic.net
; This code is released under the BSD License
; ---------------------------------------------------------
; Implements both LBOUND(array, N) and UBOUND(array, N) function
; Parameters:
; HL = PTR to array
; [stack - 2] -> N (dimension)
push namespace core
PROC
LOCAL __BOUND
LOCAL __DIM_NOT_EXIST
LOCAL __CONT
__LBOUND:
ld a, 4
jr __BOUND
__UBOUND:
ld a, 6
__BOUND:
ex de, hl ; DE <-- Array ptr
pop hl ; HL <-- Ret address
ex (sp), hl ; CALLEE: HL <-- N, (SP) <-- Ret address
ex de, hl ; DE <-- N, HL <-- ARRAY_PTR
push hl
ld c, (hl)
inc hl
ld h, (hl)
ld l, c ; HL = start of dimension table (first position contains number of dimensions - 1)
ld c, (hl)
inc hl
ld b, (hl)
inc bc ; Number of total dimensions of the array
pop hl ; Recovers ARRAY PTR
ex af, af' ; Saves A for later
ld a, d
or e
jr nz, __CONT ; N = 0 => Return number of dimensions
;; Return the number of dimensions of the array
ld h, b
ld l, c
ret
__CONT:
dec de
ex af, af' ; Recovers A (contains PTR offset)
ex de, hl ; HL = N (dimension asked) - 1, DE = Array PTR
or a
sbc hl, bc ; if no Carry => the user asked for a dimension that does not exist. Return 0
jr nc, __DIM_NOT_EXIST
add hl, bc ; restores HL = (N - 1)
add hl, hl ; hl *= 2
ex de, hl ; hl = ARRAY_PTR + 3, DE jsz = (N - 1) * 2
ld b, 0
ld c, a
add hl, bc ; HL = &BOUND_PTR
ld a, (hl)
inc hl
ld h, (hl)
ld l, a ; LD HL, (HL) => Origin of L/U Bound table
; for LBound only, HL = 0x0000 (NULL) if the array is all 0-based
or h
ret z ; Should never happen for UBound
add hl, de ; hl += OFFSET __LBOUND._xxxx
ld e, (hl) ; de = (hl)
inc hl
ld d, (hl)
ex de, hl ; hl = de => returns result in HL
ret
__DIM_NOT_EXIST:
; The dimension requested by the user does not exists. Return 0
ld hl, 0
ret
ENDP
pop namespace
#line 111 "arch/zx48k/ubound12.bas"
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/array/arraystrfree.asm"
; This routine is in charge of freeing an array of strings from memory
; HL = Pointer to start of array in memory
Expand Down Expand Up @@ -814,84 +892,6 @@ __ARRAYSTR_FREE_MEM: ; like the above, buf also frees the array itself
pop hl ; recovers array block pointer
jp __MEM_FREE ; Frees it and returns from __MEM_FREE
pop namespace
#line 111 "arch/zx48k/ubound12.bas"
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/bound.asm"
; ---------------------------------------------------------
; Copyleft (k)2011 by Jose Rodriguez (a.k.a. Boriel)
; http://www.boriel.com
;
; ZX BASIC Compiler http://www.zxbasic.net
; This code is released under the BSD License
; ---------------------------------------------------------
; Implements both LBOUND(array, N) and UBOUND(array, N) function
; Parameters:
; HL = PTR to array
; [stack - 2] -> N (dimension)
push namespace core
PROC
LOCAL __BOUND
LOCAL __DIM_NOT_EXIST
LOCAL __CONT
__LBOUND:
ld a, 4
jr __BOUND
__UBOUND:
ld a, 6
__BOUND:
ex de, hl ; DE <-- Array ptr
pop hl ; HL <-- Ret address
ex (sp), hl ; CALLEE: HL <-- N, (SP) <-- Ret address
ex de, hl ; DE <-- N, HL <-- ARRAY_PTR
push hl
ld c, (hl)
inc hl
ld h, (hl)
ld l, c ; HL = start of dimension table (first position contains number of dimensions - 1)
ld c, (hl)
inc hl
ld b, (hl)
inc bc ; Number of total dimensions of the array
pop hl ; Recovers ARRAY PTR
ex af, af' ; Saves A for later
ld a, d
or e
jr nz, __CONT ; N = 0 => Return number of dimensions
;; Return the number of dimensions of the array
ld h, b
ld l, c
ret
__CONT:
dec de
ex af, af' ; Recovers A (contains PTR offset)
ex de, hl ; HL = N (dimension asked) - 1, DE = Array PTR
or a
sbc hl, bc ; if no Carry => the user asked for a dimension that does not exist. Return 0
jr nc, __DIM_NOT_EXIST
add hl, bc ; restores HL = (N - 1)
add hl, hl ; hl *= 2
ex de, hl ; hl = ARRAY_PTR + 3, DE jsz = (N - 1) * 2
ld b, 0
ld c, a
add hl, bc ; HL = &BOUND_PTR
ld a, (hl)
inc hl
ld h, (hl)
ld l, a ; LD HL, (HL) => Origin of L/U Bound table
; for LBound only, HL = 0x0000 (NULL) if the array is all 0-based
or h
ret z ; Should never happen for UBound
add hl, de ; hl += OFFSET __LBOUND._xxxx
ld e, (hl) ; de = (hl)
inc hl
ld d, (hl)
ex de, hl ; hl = de => returns result in HL
ret
__DIM_NOT_EXIST:
; The dimension requested by the user does not exists. Return 0
ld hl, 0
ret
ENDP
pop namespace
#line 112 "arch/zx48k/ubound12.bas"
.LABEL.__LABEL5:
DEFB 01h
Expand Down
Loading