diff --git a/src/api/python_version_check.py b/src/api/python_version_check.py index 812538842..d8af98634 100644 --- a/src/api/python_version_check.py +++ b/src/api/python_version_check.py @@ -6,7 +6,7 @@ def init(): if sys.version_info < MINIMUM_REQUIRED_PYTHON_VERSION: - sys.exit("Python 3.12 or later is required.") + sys.exit("Python %i.%i or later is required." % MINIMUM_REQUIRED_PYTHON_VERSION) init() diff --git a/src/arch/z80/visitor/translator.py b/src/arch/z80/visitor/translator.py index c2e0ff508..f215a9327 100644 --- a/src/arch/z80/visitor/translator.py +++ b/src/arch/z80/visitor/translator.py @@ -6,7 +6,6 @@ import src.api.global_ as gl import src.api.tmp_labels from src.api import check -from src.api.config import OPTIONS from src.api.constants import CLASS, CONVENTION, SCOPE, TYPE from src.api.debug import __DEBUG__ from src.api.errmsg import error @@ -175,15 +174,6 @@ def visit_ARGLIST(self, node): for i in range(len(node) - 1, -1, -1): # visit in reverse order yield node[i] - if ( - isinstance(node.parent, symbols.ARRAYACCESS) - and OPTIONS.array_check - and node.parent.entry.scope != SCOPE.parameter - ): - upper = node.parent.entry.bounds[i].upper - lower = node.parent.entry.bounds[i].lower - self.ic_param(gl.PTR_TYPE, upper - lower) - def visit_ARGUMENT(self, node): if not node.byref: if node.value.token == "VAR" and node.type_.is_dynamic and node.value.t[0] == "$": diff --git a/src/arch/z80/visitor/var_translator.py b/src/arch/z80/visitor/var_translator.py index e9c28a0a4..ddc308fb7 100644 --- a/src/arch/z80/visitor/var_translator.py +++ b/src/arch/z80/visitor/var_translator.py @@ -1,5 +1,6 @@ import src.api from src.api import global_ as gl +from src.api.config import OPTIONS from src.arch.z80 import Translator from src.arch.z80.visitor.translator_visitor import TranslatorVisitor from src.symbols import sym as symbols @@ -43,16 +44,15 @@ def visit_ARRAYDECL(self, node): if self.O_LEVEL > 1: return - bound_ptrs = [] # Bound tables pointers (empty if not used) lbound_label = entry.mangled + ".__LBOUND__" ubound_label = entry.mangled + ".__UBOUND__" - if entry.lbound_used or entry.ubound_used: - bound_ptrs = ["0", "0"] # NULL by default - if entry.lbound_used: - bound_ptrs[0] = lbound_label - if entry.ubound_used: - bound_ptrs[1] = ubound_label + is_zero_based_array = all(bound.lower == 0 for bound in node.bounds) + bound_ptrs = ["0", "0"] # NULL by default + if entry.lbound_used or not is_zero_based_array: + bound_ptrs[0] = lbound_label + if entry.ubound_used or OPTIONS.array_check: + bound_ptrs[1] = ubound_label data_label = entry.data_label idx_table_label = src.api.tmp_labels.tmp_label() @@ -87,10 +87,10 @@ def visit_ARRAYDECL(self, node): self.ic_vard(idx_table_label, l) - if entry.lbound_used: + if bound_ptrs[0] != "0": l = ["%04X" % bound.lower for bound in node.bounds] self.ic_vard(lbound_label, l) - if entry.ubound_used: + if bound_ptrs[1] != "0": l = ["%04X" % bound.upper for bound in node.bounds] self.ic_vard(ubound_label, l) diff --git a/src/lib/arch/zx48k/runtime/array.asm b/src/lib/arch/zx48k/runtime/array.asm index b9ca58313..b801186cf 100644 --- a/src/lib/arch/zx48k/runtime/array.asm +++ b/src/lib/arch/zx48k/runtime/array.asm @@ -28,67 +28,110 @@ __ARRAY_PTR: ;; computes an array offset from a pointer ld c, (hl) inc hl ld h, (hl) - ld l, c + ld l, c ;; HL <-- [HL] __ARRAY: PROC LOCAL LOOP LOCAL ARRAY_END - LOCAL RET_ADDRESS ; Stores return address - LOCAL TMP_ARR_PTR ; Stores pointer temporarily + LOCAL TMP_ARR_PTR ; Ptr to Array DATA region. Stored temporarily + LOCAL LBOUND_PTR, UBOUND_PTR ; LBound and UBound PTR indexes + LOCAL RET_ADDR ; Contains the return address popped from the stack + +LBOUND_PTR EQU 23698 ; Uses MEMBOT as a temporary variable +UBOUND_PTR EQU LBOUND_PTR + 2 ; Next 2 bytes for UBOUND PTR +RET_ADDR EQU UBOUND_PTR + 2 ; Next 2 bytes for RET_ADDR +TMP_ARR_PTR EQU RET_ADDR + 2 ; Next 2 bytes for TMP_ARR_PTR ld e, (hl) inc hl ld d, (hl) + inc hl ; DE <-- PTR to Dim sizes table + ld (TMP_ARR_PTR), hl ; HL = Array __DATA__.__PTR__ inc hl - ld (TMP_ARR_PTR), hl - ex de, hl - ex (sp), hl ; Return address in HL, array address in the stack - ld (RET_ADDRESS + 1), hl ; Stores it for later + inc hl + ld c, (hl) + inc hl + ld b, (hl) ; BC <-- Array __LBOUND__ PTR + ld (LBOUND_PTR), bc ; Store it for later + +#ifdef __CHECK_ARRAY_BOUNDARY__ + inc hl + ld c, (hl) + inc hl + ld b, (hl) ; BC <-- Array __UBOUND__ PTR + ld (UBOUND_PTR), bc +#endif + + ex de, hl ; HL <-- PTR to Dim sizes table, DE <-- dummy + ex (sp), hl ; Return address in HL, PTR Dim sizes table onto Stack + ld (RET_ADDR), hl ; Stores it for later exx - pop hl ; Will use H'L' as the pointer + pop hl ; Will use H'L' as the pointer to Dim sizes table ld c, (hl) ; Loads Number of dimensions from (hl) inc hl ld b, (hl) inc hl ; Ready exx - ld hl, 0 ; HL = Offset "accumulator" + ld hl, 0 ; HL = Element Offset "accumulator" LOOP: -#ifdef __CHECK_ARRAY_BOUNDARY__ - pop de -#endif - pop bc ; Get next index (Ai) from the stack + ex de, hl ; DE = Element Offset + ld hl, (LBOUND_PTR) + ld a, h + or l + ld b, h + ld c, l + jr z, 1f + ld c, (hl) + inc hl + ld b, (hl) + inc hl + ld (LBOUND_PTR), hl +1: + pop hl ; Get next index (Ai) from the stack + sbc hl, bc ; Subtract LBOUND #ifdef __CHECK_ARRAY_BOUNDARY__ - ex de, hl - or a - sbc hl, bc ld a, ERROR_SubscriptWrong jp c, __ERROR - ex de, hl + push hl ; Saves (Ai) - Lbound(i) + add hl, bc ; Recover original (Ai) value + push hl + ld hl, (UBOUND_PTR) + ld c, (hl) + inc hl + ld b, (hl) + inc hl + ld (UBOUND_PTR), hl + pop hl ; original (Ai) value + scf + sbc hl, bc ; HL <- HL - BC - 1 = Ai - UBound(i) - 1 => No Carry if Ai > UBound(i) + jp nc, __ERROR + pop hl ; Recovers (Ai) - Lbound(Ai) #endif - add hl, bc ; Adds current index + add hl, de ; Adds current index exx ; Checks if B'C' = 0 ld a, b ; Which means we must exit (last element is not multiplied by anything) or c jr z, ARRAY_END ; if B'Ci == 0 we are done + dec bc ; Decrements loop counter - ld e, (hl) ; Loads next dimension into D'E' + ld e, (hl) ; Loads next dimension size into D'E' inc hl ld d, (hl) inc hl push de - dec bc ; Decrements loop counter exx + pop de ; DE = Max bound Number (i-th dimension) - call __FNMUL + call __FNMUL ; HL <= HL * DE mod 65536 jp LOOP ARRAY_END: @@ -118,9 +161,9 @@ ARRAY_SIZE_LOOP: ld h, (hl) ld l, a add hl, de ; Adds element start - -RET_ADDRESS: - jp 0 + ld de, (RET_ADDR) + push de + ret ;; Performs a faster multiply for little 16bit numbs LOCAL __FNMUL, __FNMUL2 @@ -143,10 +186,6 @@ __FNMUL2: djnz __FNMUL2 ret -TMP_ARR_PTR: - DW 0 ; temporary storage for pointer to tables - ENDP pop namespace - diff --git a/src/lib/arch/zxnext/runtime/array.asm b/src/lib/arch/zxnext/runtime/array.asm index 87af3ce8c..b801186cf 100644 --- a/src/lib/arch/zxnext/runtime/array.asm +++ b/src/lib/arch/zxnext/runtime/array.asm @@ -28,67 +28,110 @@ __ARRAY_PTR: ;; computes an array offset from a pointer ld c, (hl) inc hl ld h, (hl) - ld l, c + ld l, c ;; HL <-- [HL] __ARRAY: PROC LOCAL LOOP LOCAL ARRAY_END - LOCAL RET_ADDRESS ; Stores return address - LOCAL TMP_ARR_PTR ; Stores pointer temporarily + LOCAL TMP_ARR_PTR ; Ptr to Array DATA region. Stored temporarily + LOCAL LBOUND_PTR, UBOUND_PTR ; LBound and UBound PTR indexes + LOCAL RET_ADDR ; Contains the return address popped from the stack + +LBOUND_PTR EQU 23698 ; Uses MEMBOT as a temporary variable +UBOUND_PTR EQU LBOUND_PTR + 2 ; Next 2 bytes for UBOUND PTR +RET_ADDR EQU UBOUND_PTR + 2 ; Next 2 bytes for RET_ADDR +TMP_ARR_PTR EQU RET_ADDR + 2 ; Next 2 bytes for TMP_ARR_PTR ld e, (hl) inc hl ld d, (hl) + inc hl ; DE <-- PTR to Dim sizes table + ld (TMP_ARR_PTR), hl ; HL = Array __DATA__.__PTR__ inc hl - ld (TMP_ARR_PTR), hl - ex de, hl - ex (sp), hl ; Return address in HL, array address in the stack - ld (RET_ADDRESS + 1), hl ; Stores it for later + inc hl + ld c, (hl) + inc hl + ld b, (hl) ; BC <-- Array __LBOUND__ PTR + ld (LBOUND_PTR), bc ; Store it for later + +#ifdef __CHECK_ARRAY_BOUNDARY__ + inc hl + ld c, (hl) + inc hl + ld b, (hl) ; BC <-- Array __UBOUND__ PTR + ld (UBOUND_PTR), bc +#endif + + ex de, hl ; HL <-- PTR to Dim sizes table, DE <-- dummy + ex (sp), hl ; Return address in HL, PTR Dim sizes table onto Stack + ld (RET_ADDR), hl ; Stores it for later exx - pop hl ; Will use H'L' as the pointer + pop hl ; Will use H'L' as the pointer to Dim sizes table ld c, (hl) ; Loads Number of dimensions from (hl) inc hl ld b, (hl) inc hl ; Ready exx - ld hl, 0 ; HL = Offset "accumulator" + ld hl, 0 ; HL = Element Offset "accumulator" LOOP: -#ifdef __CHECK_ARRAY_BOUNDARY__ - pop de -#endif - pop bc ; Get next index (Ai) from the stack + ex de, hl ; DE = Element Offset + ld hl, (LBOUND_PTR) + ld a, h + or l + ld b, h + ld c, l + jr z, 1f + ld c, (hl) + inc hl + ld b, (hl) + inc hl + ld (LBOUND_PTR), hl +1: + pop hl ; Get next index (Ai) from the stack + sbc hl, bc ; Subtract LBOUND #ifdef __CHECK_ARRAY_BOUNDARY__ - ex de, hl - or a - sbc hl, bc ld a, ERROR_SubscriptWrong jp c, __ERROR - ex de, hl + push hl ; Saves (Ai) - Lbound(i) + add hl, bc ; Recover original (Ai) value + push hl + ld hl, (UBOUND_PTR) + ld c, (hl) + inc hl + ld b, (hl) + inc hl + ld (UBOUND_PTR), hl + pop hl ; original (Ai) value + scf + sbc hl, bc ; HL <- HL - BC - 1 = Ai - UBound(i) - 1 => No Carry if Ai > UBound(i) + jp nc, __ERROR + pop hl ; Recovers (Ai) - Lbound(Ai) #endif - add hl, bc ; Adds current index + add hl, de ; Adds current index exx ; Checks if B'C' = 0 ld a, b ; Which means we must exit (last element is not multiplied by anything) or c jr z, ARRAY_END ; if B'Ci == 0 we are done + dec bc ; Decrements loop counter - ld e, (hl) ; Loads next dimension into D'E' + ld e, (hl) ; Loads next dimension size into D'E' inc hl ld d, (hl) inc hl push de - dec bc ; Decrements loop counter exx + pop de ; DE = Max bound Number (i-th dimension) - call __MUL16_FAST + call __FNMUL ; HL <= HL * DE mod 65536 jp LOOP ARRAY_END: @@ -98,7 +141,7 @@ ARRAY_END: #ifdef __BIG_ARRAY__ ld d, 0 ld e, a - call __MUL16_FAST + call __FNMUL #else LOCAL ARRAY_SIZE_LOOP @@ -118,16 +161,31 @@ ARRAY_SIZE_LOOP: ld h, (hl) ld l, a add hl, de ; Adds element start - -RET_ADDRESS: - jp 0 + ld de, (RET_ADDR) + push de + ret ;; Performs a faster multiply for little 16bit numbs + LOCAL __FNMUL, __FNMUL2 + +__FNMUL: + xor a + or h + jp nz, __MUL16_FAST + or l + ret z -TMP_ARR_PTR: - DW 0 ; temporary storage for pointer to tables + cp 33 + jp nc, __MUL16_FAST + + ld b, l + ld l, h ; HL = 0 + +__FNMUL2: + add hl, de + djnz __FNMUL2 + ret ENDP pop namespace - diff --git a/src/symbols/arrayaccess.py b/src/symbols/arrayaccess.py index af83d2ce1..378b0ef8f 100644 --- a/src/symbols/arrayaccess.py +++ b/src/symbols/arrayaccess.py @@ -1,25 +1,23 @@ #!/usr/bin/env python # vim: ts=4:et:sw=4: - -# ---------------------------------------------------------------------- -# Copyleft (K), Jose M. Rodriguez-Rosa (a.k.a. Boriel) -# -# This program is Free Software and is released under the terms of -# the GNU General License -# ---------------------------------------------------------------------- - +from functools import cached_property from typing import Optional import src.api.global_ as gl from src.api import check, errmsg from src.api.constants import SCOPE from src.symbols.arglist import SymbolARGLIST -from src.symbols.binary import SymbolBINARY as BINARY from src.symbols.call import SymbolCALL from src.symbols.id_ import SymbolID -from src.symbols.number import SymbolNUMBER as NUMBER from src.symbols.typecast import SymbolTYPECAST as TYPECAST +# ---------------------------------------------------------------------- +# Copyleft (K), Jose M. Rodriguez-Rosa (a.k.a. Boriel) +# +# This program is Free Software and is released under the terms of +# the GNU General License +# ---------------------------------------------------------------------- + class SymbolARRAYACCESS(SymbolCALL): """Defines an array access. It's pretty much like a function call @@ -68,8 +66,8 @@ def arglist(self, value: SymbolARGLIST): def scope(self): return self.entry.scope - @property - def offset(self): + @cached_property + def offset(self) -> int | None: """If this is a constant access (e.g. A(1)) return the offset in bytes from the beginning of the variable in memory. @@ -86,15 +84,11 @@ def offset(self): for i, b in zip(self.arglist, self.entry.bounds): tmp = i.children[0] if check.is_number(tmp) or check.is_const(tmp): - if offset is not None: - offset = offset * b.count + tmp.value + offset = offset * b.count + (tmp.value - b.lower) else: - offset = None - break - - if offset is not None: - offset *= self.type_.size + return None + offset *= self.type_.size return offset @classmethod @@ -116,21 +110,12 @@ def make_node(cls, id_: str, arglist: SymbolARGLIST, lineno: int, filename: str) # e.g. A(1) is a constant subscript access btype = gl.SYMBOL_TABLE.basic_types[gl.BOUND_TYPE] for i, b in zip(arglist, variable.bounds): - lower_bound = NUMBER(b.lower, type_=btype, lineno=lineno) - if check.is_number(i.value) or check.is_const(i.value): val = i.value.value if val < b.lower or val > b.upper: errmsg.warning(lineno, "Array '%s' subscript out of range" % id_) - i.value = BINARY.make_node( - "MINUS", - TYPECAST.make_node(btype, i.value, lineno), - lower_bound, - lineno, - func=lambda x, y: x - y, - type_=btype, - ) + i.value = TYPECAST.make_node(btype, i.value, lineno) else: btype = gl.SYMBOL_TABLE.basic_types[gl.BOUND_TYPE] for arg in arglist: diff --git a/tests/functional/arch/zx48k/05.asm b/tests/functional/arch/zx48k/05.asm index a1b9d40c2..6dde0e7fe 100644 --- a/tests/functional/arch/zx48k/05.asm +++ b/tests/functional/arch/zx48k/05.asm @@ -22,6 +22,8 @@ _a: DEFW .LABEL.__LABEL0 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW 0 + DEFW 0 _a.__DATA__: DEFB 00h DEFB 00h diff --git a/tests/functional/arch/zx48k/06.asm b/tests/functional/arch/zx48k/06.asm index a73a9711d..33e4ce8fa 100644 --- a/tests/functional/arch/zx48k/06.asm +++ b/tests/functional/arch/zx48k/06.asm @@ -22,6 +22,8 @@ _a: DEFW .LABEL.__LABEL0 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW 0 + DEFW 0 _a.__DATA__: DEFB 00h DEFB 00h diff --git a/tests/functional/arch/zx48k/07.asm b/tests/functional/arch/zx48k/07.asm index 44f34d4fe..6efa2e35a 100644 --- a/tests/functional/arch/zx48k/07.asm +++ b/tests/functional/arch/zx48k/07.asm @@ -22,6 +22,8 @@ _a: DEFW .LABEL.__LABEL0 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW 0 + DEFW 0 _a.__DATA__: DEFB 00h DEFB 00h diff --git a/tests/functional/arch/zx48k/09.asm b/tests/functional/arch/zx48k/09.asm index f264caf36..d911d164a 100644 --- a/tests/functional/arch/zx48k/09.asm +++ b/tests/functional/arch/zx48k/09.asm @@ -22,6 +22,8 @@ _a: DEFW .LABEL.__LABEL0 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW 0 + DEFW 0 _a.__DATA__: DEFB 82h DEFB 00h diff --git a/tests/functional/arch/zx48k/10.asm b/tests/functional/arch/zx48k/10.asm index b426f39a9..f87750422 100644 --- a/tests/functional/arch/zx48k/10.asm +++ b/tests/functional/arch/zx48k/10.asm @@ -22,6 +22,8 @@ _a: DEFW .LABEL.__LABEL0 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW 0 + DEFW 0 _a.__DATA__: DEFB 02h DEFB 03h diff --git a/tests/functional/arch/zx48k/11.asm b/tests/functional/arch/zx48k/11.asm index 2dc2a9478..f12555c7b 100644 --- a/tests/functional/arch/zx48k/11.asm +++ b/tests/functional/arch/zx48k/11.asm @@ -22,6 +22,8 @@ _a: DEFW .LABEL.__LABEL0 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW 0 + DEFW 0 _a.__DATA__: DEFB 82h DEFB 40h diff --git a/tests/functional/arch/zx48k/41.asm b/tests/functional/arch/zx48k/41.asm index 0ebc6153b..c9290e081 100644 --- a/tests/functional/arch/zx48k/41.asm +++ b/tests/functional/arch/zx48k/41.asm @@ -24,6 +24,8 @@ _b: DEFW .LABEL.__LABEL0 _b.__DATA__.__PTR__: DEFW _b.__DATA__ + DEFW 0 + DEFW 0 _b.__DATA__: DEFB 0AAh DEFB 0BBh diff --git a/tests/functional/arch/zx48k/44.asm b/tests/functional/arch/zx48k/44.asm index dbec33367..436356f0e 100644 --- a/tests/functional/arch/zx48k/44.asm +++ b/tests/functional/arch/zx48k/44.asm @@ -24,6 +24,8 @@ _b: DEFW .LABEL.__LABEL0 _b.__DATA__.__PTR__: DEFW _b.__DATA__ + DEFW 0 + DEFW 0 _b.__DATA__: DEFB 0A0h DEFB 0A1h diff --git a/tests/functional/arch/zx48k/46.asm b/tests/functional/arch/zx48k/46.asm index 1c9c6d4d9..e1233aaf6 100644 --- a/tests/functional/arch/zx48k/46.asm +++ b/tests/functional/arch/zx48k/46.asm @@ -26,6 +26,8 @@ _b: DEFW .LABEL.__LABEL0 _b.__DATA__.__PTR__: DEFW _b.__DATA__ + DEFW 0 + DEFW 0 _b.__DATA__: DEFB 0A0h DEFB 0A1h @@ -75,7 +77,7 @@ _b.__DATA__: ei ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -91,7 +93,7 @@ _b.__DATA__: ; O = [a0 + b0 * (a1 + b1 * (a2 + ... bN-2(aN-1)))] ; What I will do here is to calculate the following sequence: ; ((aN-1 * bN-2) + aN-2) * bN-3 + ... -#line 1 "/zxbasic/src/arch/zx48k/library-asm/mul16.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/mul16.asm" push namespace core __MUL16: ; Mutiplies HL with the last value stored into de stack ; Works for both signed and unsigned @@ -117,59 +119,84 @@ __MUL16NOADD: ret ; Result in hl (16 lower bits) ENDP pop namespace -#line 20 "/zxbasic/src/arch/zx48k/library-asm/array.asm" -#line 24 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 20 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 24 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" push namespace core __ARRAY_PTR: ;; computes an array offset from a pointer ld c, (hl) inc hl ld h, (hl) - ld l, c + ld l, c ;; HL <-- [HL] __ARRAY: PROC LOCAL LOOP LOCAL ARRAY_END - LOCAL RET_ADDRESS ; Stores return address - LOCAL TMP_ARR_PTR ; Stores pointer temporarily + LOCAL TMP_ARR_PTR ; Ptr to Array DATA region. Stored temporarily + LOCAL LBOUND_PTR, UBOUND_PTR ; LBound and UBound PTR indexes + LOCAL RET_ADDR ; Contains the return address popped from the stack + LBOUND_PTR EQU 23698 ; Uses MEMBOT as a temporary variable + UBOUND_PTR EQU LBOUND_PTR + 2 ; Next 2 bytes for UBOUND PTR + RET_ADDR EQU UBOUND_PTR + 2 ; Next 2 bytes for RET_ADDR + TMP_ARR_PTR EQU RET_ADDR + 2 ; Next 2 bytes for TMP_ARR_PTR ld e, (hl) inc hl ld d, (hl) + inc hl ; DE <-- PTR to Dim sizes table + ld (TMP_ARR_PTR), hl ; HL = Array __DATA__.__PTR__ inc hl - ld (TMP_ARR_PTR), hl - ex de, hl - ex (sp), hl ; Return address in HL, array address in the stack - ld (RET_ADDRESS + 1), hl ; Stores it for later + inc hl + ld c, (hl) + inc hl + ld b, (hl) ; BC <-- Array __LBOUND__ PTR + ld (LBOUND_PTR), bc ; Store it for later +#line 66 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + ex de, hl ; HL <-- PTR to Dim sizes table, DE <-- dummy + ex (sp), hl ; Return address in HL, PTR Dim sizes table onto Stack + ld (RET_ADDR), hl ; Stores it for later exx - pop hl ; Will use H'L' as the pointer + pop hl ; Will use H'L' as the pointer to Dim sizes table ld c, (hl) ; Loads Number of dimensions from (hl) inc hl ld b, (hl) inc hl ; Ready exx - ld hl, 0 ; HL = Offset "accumulator" + ld hl, 0 ; HL = Element Offset "accumulator" LOOP: -#line 64 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - pop bc ; Get next index (Ai) from the stack -#line 74 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - add hl, bc ; Adds current index + ex de, hl ; DE = Element Offset + ld hl, (LBOUND_PTR) + ld a, h + or l + ld b, h + ld c, l + jr z, 1f + ld c, (hl) + inc hl + ld b, (hl) + inc hl + ld (LBOUND_PTR), hl +1: + pop hl ; Get next index (Ai) from the stack + sbc hl, bc ; Subtract LBOUND +#line 116 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + add hl, de ; Adds current index exx ; Checks if B'C' = 0 ld a, b ; Which means we must exit (last element is not multiplied by anything) or c jr z, ARRAY_END ; if B'Ci == 0 we are done - ld e, (hl) ; Loads next dimension into D'E' + dec bc ; Decrements loop counter + ld e, (hl) ; Loads next dimension size into D'E' inc hl ld d, (hl) inc hl push de - dec bc ; Decrements loop counter exx pop de ; DE = Max bound Number (i-th dimension) - call __FNMUL + call __FNMUL ; HL <= HL * DE mod 65536 jp LOOP ARRAY_END: ld a, (hl) exx -#line 103 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 146 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl ld hl, 0 @@ -177,7 +204,7 @@ ARRAY_END: ARRAY_SIZE_LOOP: add hl, de djnz ARRAY_SIZE_LOOP -#line 113 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 156 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ex de, hl ld hl, (TMP_ARR_PTR) ld a, (hl) @@ -185,8 +212,9 @@ ARRAY_SIZE_LOOP: ld h, (hl) ld l, a add hl, de ; Adds element start -RET_ADDRESS: - jp 0 + ld de, (RET_ADDR) + push de + ret ;; Performs a faster multiply for little 16bit numbs LOCAL __FNMUL, __FNMUL2 __FNMUL: @@ -203,9 +231,7 @@ __FNMUL2: add hl, de djnz __FNMUL2 ret -TMP_ARR_PTR: - DW 0 ; temporary storage for pointer to tables ENDP pop namespace -#line 32 "46.bas" +#line 32 "arch/zx48k/46.bas" END diff --git a/tests/functional/arch/zx48k/47.asm b/tests/functional/arch/zx48k/47.asm index 5a8889b0e..2e7a1bad0 100644 --- a/tests/functional/arch/zx48k/47.asm +++ b/tests/functional/arch/zx48k/47.asm @@ -82,7 +82,7 @@ _test__leave: pop ix ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -98,7 +98,7 @@ _test__leave: ; O = [a0 + b0 * (a1 + b1 * (a2 + ... bN-2(aN-1)))] ; What I will do here is to calculate the following sequence: ; ((aN-1 * bN-2) + aN-2) * bN-3 + ... -#line 1 "/zxbasic/src/arch/zx48k/library-asm/mul16.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/mul16.asm" push namespace core __MUL16: ; Mutiplies HL with the last value stored into de stack ; Works for both signed and unsigned @@ -124,59 +124,84 @@ __MUL16NOADD: ret ; Result in hl (16 lower bits) ENDP pop namespace -#line 20 "/zxbasic/src/arch/zx48k/library-asm/array.asm" -#line 24 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 20 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 24 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" push namespace core __ARRAY_PTR: ;; computes an array offset from a pointer ld c, (hl) inc hl ld h, (hl) - ld l, c + ld l, c ;; HL <-- [HL] __ARRAY: PROC LOCAL LOOP LOCAL ARRAY_END - LOCAL RET_ADDRESS ; Stores return address - LOCAL TMP_ARR_PTR ; Stores pointer temporarily + LOCAL TMP_ARR_PTR ; Ptr to Array DATA region. Stored temporarily + LOCAL LBOUND_PTR, UBOUND_PTR ; LBound and UBound PTR indexes + LOCAL RET_ADDR ; Contains the return address popped from the stack + LBOUND_PTR EQU 23698 ; Uses MEMBOT as a temporary variable + UBOUND_PTR EQU LBOUND_PTR + 2 ; Next 2 bytes for UBOUND PTR + RET_ADDR EQU UBOUND_PTR + 2 ; Next 2 bytes for RET_ADDR + TMP_ARR_PTR EQU RET_ADDR + 2 ; Next 2 bytes for TMP_ARR_PTR ld e, (hl) inc hl ld d, (hl) + inc hl ; DE <-- PTR to Dim sizes table + ld (TMP_ARR_PTR), hl ; HL = Array __DATA__.__PTR__ inc hl - ld (TMP_ARR_PTR), hl - ex de, hl - ex (sp), hl ; Return address in HL, array address in the stack - ld (RET_ADDRESS + 1), hl ; Stores it for later + inc hl + ld c, (hl) + inc hl + ld b, (hl) ; BC <-- Array __LBOUND__ PTR + ld (LBOUND_PTR), bc ; Store it for later +#line 66 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + ex de, hl ; HL <-- PTR to Dim sizes table, DE <-- dummy + ex (sp), hl ; Return address in HL, PTR Dim sizes table onto Stack + ld (RET_ADDR), hl ; Stores it for later exx - pop hl ; Will use H'L' as the pointer + pop hl ; Will use H'L' as the pointer to Dim sizes table ld c, (hl) ; Loads Number of dimensions from (hl) inc hl ld b, (hl) inc hl ; Ready exx - ld hl, 0 ; HL = Offset "accumulator" + ld hl, 0 ; HL = Element Offset "accumulator" LOOP: -#line 64 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - pop bc ; Get next index (Ai) from the stack -#line 74 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - add hl, bc ; Adds current index + ex de, hl ; DE = Element Offset + ld hl, (LBOUND_PTR) + ld a, h + or l + ld b, h + ld c, l + jr z, 1f + ld c, (hl) + inc hl + ld b, (hl) + inc hl + ld (LBOUND_PTR), hl +1: + pop hl ; Get next index (Ai) from the stack + sbc hl, bc ; Subtract LBOUND +#line 116 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + add hl, de ; Adds current index exx ; Checks if B'C' = 0 ld a, b ; Which means we must exit (last element is not multiplied by anything) or c jr z, ARRAY_END ; if B'Ci == 0 we are done - ld e, (hl) ; Loads next dimension into D'E' + dec bc ; Decrements loop counter + ld e, (hl) ; Loads next dimension size into D'E' inc hl ld d, (hl) inc hl push de - dec bc ; Decrements loop counter exx pop de ; DE = Max bound Number (i-th dimension) - call __FNMUL + call __FNMUL ; HL <= HL * DE mod 65536 jp LOOP ARRAY_END: ld a, (hl) exx -#line 103 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 146 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl ld hl, 0 @@ -184,7 +209,7 @@ ARRAY_END: ARRAY_SIZE_LOOP: add hl, de djnz ARRAY_SIZE_LOOP -#line 113 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 156 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ex de, hl ld hl, (TMP_ARR_PTR) ld a, (hl) @@ -192,8 +217,9 @@ ARRAY_SIZE_LOOP: ld h, (hl) ld l, a add hl, de ; Adds element start -RET_ADDRESS: - jp 0 + ld de, (RET_ADDR) + push de + ret ;; Performs a faster multiply for little 16bit numbs LOCAL __FNMUL, __FNMUL2 __FNMUL: @@ -210,13 +236,11 @@ __FNMUL2: add hl, de djnz __FNMUL2 ret -TMP_ARR_PTR: - DW 0 ; temporary storage for pointer to tables ENDP pop namespace -#line 59 "47.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/arrayalloc.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/calloc.asm" +#line 59 "arch/zx48k/47.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/arrayalloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/calloc.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -227,7 +251,7 @@ TMP_ARR_PTR: ; closed source programs). ; ; Please read the MIT license on the internet -#line 1 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -287,7 +311,7 @@ TMP_ARR_PTR: ; HL = BLOCK Start & DE = Length. ; An init directive is useful for initialization routines. ; They will be added automatically if needed. -#line 1 "/zxbasic/src/arch/zx48k/library-asm/error.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/error.asm" ; Simple error control routines ; vim:ts=4:et: push namespace core @@ -321,8 +345,8 @@ __STOP: ld (ERR_NR), a ret pop namespace -#line 69 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/heapinit.asm" +#line 69 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/heapinit.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -429,7 +453,7 @@ __MEM_INIT2: ret ENDP pop namespace -#line 70 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 70 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; --------------------------------------------------------------------- ; MEM_ALLOC ; Allocates a block of memory in the heap. @@ -460,9 +484,9 @@ __MEM_START: __MEM_LOOP: ; Loads lengh at (HL, HL+). If Lenght >= BC, jump to __MEM_DONE ld a, h ; HL = NULL (No memory available?) or l -#line 113 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 113 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ret z ; NULL -#line 115 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 115 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; HL = Pointer to Free block ld e, (hl) inc hl @@ -527,7 +551,7 @@ __MEM_SUBTRACT: ret ENDP pop namespace -#line 13 "/zxbasic/src/arch/zx48k/library-asm/calloc.asm" +#line 13 "/zxbasic/src/lib/arch/zx48k/runtime/calloc.asm" ; --------------------------------------------------------------------- ; MEM_CALLOC ; Allocates a block of memory in the heap, and clears it filling it @@ -561,7 +585,7 @@ __MEM_CALLOC: pop hl ret pop namespace -#line 3 "/zxbasic/src/arch/zx48k/library-asm/arrayalloc.asm" +#line 3 "/zxbasic/src/lib/arch/zx48k/runtime/arrayalloc.asm" ; --------------------------------------------------------------------- ; __ALLOC_LOCAL_ARRAY ; Allocates an array element area in the heap, and clears it filling it @@ -625,10 +649,10 @@ __ALLOC_INITIALIZED_LOCAL_ARRAY: ldir pop hl ; HL = addr of LBound area if used ret -#line 139 "/zxbasic/src/arch/zx48k/library-asm/arrayalloc.asm" +#line 139 "/zxbasic/src/lib/arch/zx48k/runtime/arrayalloc.asm" pop namespace -#line 60 "47.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/free.asm" +#line 60 "arch/zx48k/47.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/free.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -786,7 +810,7 @@ __MEM_BLOCK_JOIN: ; Joins current block (pointed by HL) with next one (pointed ret ENDP pop namespace -#line 61 "47.bas" +#line 61 "arch/zx48k/47.bas" .LABEL.__LABEL0: DEFB 01h DEFB 00h diff --git a/tests/functional/arch/zx48k/52.asm b/tests/functional/arch/zx48k/52.asm index 5ae659220..5f25cb65b 100644 --- a/tests/functional/arch/zx48k/52.asm +++ b/tests/functional/arch/zx48k/52.asm @@ -22,6 +22,8 @@ _a: DEFW .LABEL.__LABEL0 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW 0 + DEFW 0 _a.__DATA__: DEFB 00h DEFB 00h @@ -43,6 +45,8 @@ _b: DEFW .LABEL.__LABEL1 _b.__DATA__.__PTR__: DEFW _b.__DATA__ + DEFW 0 + DEFW 0 _b.__DATA__: DEFB 0A0h DEFB 0A1h diff --git a/tests/functional/arch/zx48k/54.asm b/tests/functional/arch/zx48k/54.asm index 6cccf0dc2..d2a055dac 100644 --- a/tests/functional/arch/zx48k/54.asm +++ b/tests/functional/arch/zx48k/54.asm @@ -24,6 +24,8 @@ _b: DEFW .LABEL.__LABEL0 _b.__DATA__.__PTR__: DEFW _b.__DATA__ + DEFW 0 + DEFW 0 _b.__DATA__: DEFB 0A0h DEFB 0A1h diff --git a/tests/functional/arch/zx48k/55.asm b/tests/functional/arch/zx48k/55.asm index f64f8d8a6..caa398ad5 100644 --- a/tests/functional/arch/zx48k/55.asm +++ b/tests/functional/arch/zx48k/55.asm @@ -24,6 +24,8 @@ _b: DEFW .LABEL.__LABEL0 _b.__DATA__.__PTR__: DEFW _b.__DATA__ + DEFW 0 + DEFW 0 _b.__DATA__: DEFB 0A0h DEFB 0A1h @@ -68,7 +70,7 @@ _b.__DATA__: ei ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -84,7 +86,7 @@ _b.__DATA__: ; O = [a0 + b0 * (a1 + b1 * (a2 + ... bN-2(aN-1)))] ; What I will do here is to calculate the following sequence: ; ((aN-1 * bN-2) + aN-2) * bN-3 + ... -#line 1 "/zxbasic/src/arch/zx48k/library-asm/mul16.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/mul16.asm" push namespace core __MUL16: ; Mutiplies HL with the last value stored into de stack ; Works for both signed and unsigned @@ -110,59 +112,84 @@ __MUL16NOADD: ret ; Result in hl (16 lower bits) ENDP pop namespace -#line 20 "/zxbasic/src/arch/zx48k/library-asm/array.asm" -#line 24 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 20 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 24 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" push namespace core __ARRAY_PTR: ;; computes an array offset from a pointer ld c, (hl) inc hl ld h, (hl) - ld l, c + ld l, c ;; HL <-- [HL] __ARRAY: PROC LOCAL LOOP LOCAL ARRAY_END - LOCAL RET_ADDRESS ; Stores return address - LOCAL TMP_ARR_PTR ; Stores pointer temporarily + LOCAL TMP_ARR_PTR ; Ptr to Array DATA region. Stored temporarily + LOCAL LBOUND_PTR, UBOUND_PTR ; LBound and UBound PTR indexes + LOCAL RET_ADDR ; Contains the return address popped from the stack + LBOUND_PTR EQU 23698 ; Uses MEMBOT as a temporary variable + UBOUND_PTR EQU LBOUND_PTR + 2 ; Next 2 bytes for UBOUND PTR + RET_ADDR EQU UBOUND_PTR + 2 ; Next 2 bytes for RET_ADDR + TMP_ARR_PTR EQU RET_ADDR + 2 ; Next 2 bytes for TMP_ARR_PTR ld e, (hl) inc hl ld d, (hl) + inc hl ; DE <-- PTR to Dim sizes table + ld (TMP_ARR_PTR), hl ; HL = Array __DATA__.__PTR__ inc hl - ld (TMP_ARR_PTR), hl - ex de, hl - ex (sp), hl ; Return address in HL, array address in the stack - ld (RET_ADDRESS + 1), hl ; Stores it for later + inc hl + ld c, (hl) + inc hl + ld b, (hl) ; BC <-- Array __LBOUND__ PTR + ld (LBOUND_PTR), bc ; Store it for later +#line 66 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + ex de, hl ; HL <-- PTR to Dim sizes table, DE <-- dummy + ex (sp), hl ; Return address in HL, PTR Dim sizes table onto Stack + ld (RET_ADDR), hl ; Stores it for later exx - pop hl ; Will use H'L' as the pointer + pop hl ; Will use H'L' as the pointer to Dim sizes table ld c, (hl) ; Loads Number of dimensions from (hl) inc hl ld b, (hl) inc hl ; Ready exx - ld hl, 0 ; HL = Offset "accumulator" + ld hl, 0 ; HL = Element Offset "accumulator" LOOP: -#line 64 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - pop bc ; Get next index (Ai) from the stack -#line 74 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - add hl, bc ; Adds current index + ex de, hl ; DE = Element Offset + ld hl, (LBOUND_PTR) + ld a, h + or l + ld b, h + ld c, l + jr z, 1f + ld c, (hl) + inc hl + ld b, (hl) + inc hl + ld (LBOUND_PTR), hl +1: + pop hl ; Get next index (Ai) from the stack + sbc hl, bc ; Subtract LBOUND +#line 116 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + add hl, de ; Adds current index exx ; Checks if B'C' = 0 ld a, b ; Which means we must exit (last element is not multiplied by anything) or c jr z, ARRAY_END ; if B'Ci == 0 we are done - ld e, (hl) ; Loads next dimension into D'E' + dec bc ; Decrements loop counter + ld e, (hl) ; Loads next dimension size into D'E' inc hl ld d, (hl) inc hl push de - dec bc ; Decrements loop counter exx pop de ; DE = Max bound Number (i-th dimension) - call __FNMUL + call __FNMUL ; HL <= HL * DE mod 65536 jp LOOP ARRAY_END: ld a, (hl) exx -#line 103 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 146 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl ld hl, 0 @@ -170,7 +197,7 @@ ARRAY_END: ARRAY_SIZE_LOOP: add hl, de djnz ARRAY_SIZE_LOOP -#line 113 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 156 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ex de, hl ld hl, (TMP_ARR_PTR) ld a, (hl) @@ -178,8 +205,9 @@ ARRAY_SIZE_LOOP: ld h, (hl) ld l, a add hl, de ; Adds element start -RET_ADDRESS: - jp 0 + ld de, (RET_ADDR) + push de + ret ;; Performs a faster multiply for little 16bit numbs LOCAL __FNMUL, __FNMUL2 __FNMUL: @@ -196,9 +224,7 @@ __FNMUL2: add hl, de djnz __FNMUL2 ret -TMP_ARR_PTR: - DW 0 ; temporary storage for pointer to tables ENDP pop namespace -#line 27 "55.bas" +#line 27 "arch/zx48k/55.bas" END diff --git a/tests/functional/arch/zx48k/aloadstr0.asm b/tests/functional/arch/zx48k/aloadstr0.asm index 0f3b4c9b0..a192f8894 100644 --- a/tests/functional/arch/zx48k/aloadstr0.asm +++ b/tests/functional/arch/zx48k/aloadstr0.asm @@ -29,6 +29,8 @@ _a: DEFW .LABEL.__LABEL0 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW 0 + DEFW 0 _a.__DATA__: DEFB 00h DEFB 00h @@ -257,8 +259,8 @@ _a.__DATA__: ei ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/loadstr.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/loadstr.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -318,7 +320,7 @@ _a.__DATA__: ; HL = BLOCK Start & DE = Length. ; An init directive is useful for initialization routines. ; They will be added automatically if needed. -#line 1 "/zxbasic/src/arch/zx48k/library-asm/error.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/error.asm" ; Simple error control routines ; vim:ts=4:et: push namespace core @@ -352,8 +354,8 @@ __STOP: ld (ERR_NR), a ret pop namespace -#line 69 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/heapinit.asm" +#line 69 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/heapinit.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -460,7 +462,7 @@ __MEM_INIT2: ret ENDP pop namespace -#line 70 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 70 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; --------------------------------------------------------------------- ; MEM_ALLOC ; Allocates a block of memory in the heap. @@ -491,9 +493,9 @@ __MEM_START: __MEM_LOOP: ; Loads lengh at (HL, HL+). If Lenght >= BC, jump to __MEM_DONE ld a, h ; HL = NULL (No memory available?) or l -#line 113 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 113 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ret z ; NULL -#line 115 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 115 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; HL = Pointer to Free block ld e, (hl) inc hl @@ -558,7 +560,7 @@ __MEM_SUBTRACT: ret ENDP pop namespace -#line 2 "/zxbasic/src/arch/zx48k/library-asm/loadstr.asm" +#line 2 "/zxbasic/src/lib/arch/zx48k/runtime/loadstr.asm" ; Loads a string (ptr) from HL ; and duplicates it on dynamic memory again ; Finally, it returns result pointer in HL @@ -595,15 +597,15 @@ __LOADSTR: ; __FASTCALL__ entry pop hl ; Recovers destiny in hl as result ret pop namespace -#line 22 "aloadstr0.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/storestr2.asm" +#line 22 "arch/zx48k/aloadstr0.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/storestr2.asm" ; Similar to __STORE_STR, but this one is called when ; the value of B$ if already duplicated onto the stack. ; So we needn't call STRASSING to create a duplication ; HL = address of string memory variable ; DE = address of 2n string. It just copies DE into (HL) ; freeing (HL) previously. -#line 1 "/zxbasic/src/arch/zx48k/library-asm/free.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/free.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -761,7 +763,7 @@ __MEM_BLOCK_JOIN: ; Joins current block (pointed by HL) with next one (pointed ret ENDP pop namespace -#line 9 "/zxbasic/src/arch/zx48k/library-asm/storestr2.asm" +#line 9 "/zxbasic/src/lib/arch/zx48k/runtime/storestr2.asm" push namespace core __PISTORE_STR2: ; Indirect store temporary string at (IX + BC) push ix @@ -788,5 +790,5 @@ __STORE_STR2: dec hl ; HL points to mem address variable. This might be useful in the future. ret pop namespace -#line 23 "aloadstr0.bas" +#line 23 "arch/zx48k/aloadstr0.bas" END diff --git a/tests/functional/arch/zx48k/aloadstr1.asm b/tests/functional/arch/zx48k/aloadstr1.asm index e2b9ab708..3447f7116 100644 --- a/tests/functional/arch/zx48k/aloadstr1.asm +++ b/tests/functional/arch/zx48k/aloadstr1.asm @@ -31,6 +31,8 @@ _a: DEFW .LABEL.__LABEL0 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW 0 + DEFW 0 _a.__DATA__: DEFB 00h DEFB 00h @@ -264,7 +266,7 @@ _a.__DATA__: ei ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -280,7 +282,7 @@ _a.__DATA__: ; O = [a0 + b0 * (a1 + b1 * (a2 + ... bN-2(aN-1)))] ; What I will do here is to calculate the following sequence: ; ((aN-1 * bN-2) + aN-2) * bN-3 + ... -#line 1 "/zxbasic/src/arch/zx48k/library-asm/mul16.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/mul16.asm" push namespace core __MUL16: ; Mutiplies HL with the last value stored into de stack ; Works for both signed and unsigned @@ -306,59 +308,84 @@ __MUL16NOADD: ret ; Result in hl (16 lower bits) ENDP pop namespace -#line 20 "/zxbasic/src/arch/zx48k/library-asm/array.asm" -#line 24 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 20 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 24 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" push namespace core __ARRAY_PTR: ;; computes an array offset from a pointer ld c, (hl) inc hl ld h, (hl) - ld l, c + ld l, c ;; HL <-- [HL] __ARRAY: PROC LOCAL LOOP LOCAL ARRAY_END - LOCAL RET_ADDRESS ; Stores return address - LOCAL TMP_ARR_PTR ; Stores pointer temporarily + LOCAL TMP_ARR_PTR ; Ptr to Array DATA region. Stored temporarily + LOCAL LBOUND_PTR, UBOUND_PTR ; LBound and UBound PTR indexes + LOCAL RET_ADDR ; Contains the return address popped from the stack + LBOUND_PTR EQU 23698 ; Uses MEMBOT as a temporary variable + UBOUND_PTR EQU LBOUND_PTR + 2 ; Next 2 bytes for UBOUND PTR + RET_ADDR EQU UBOUND_PTR + 2 ; Next 2 bytes for RET_ADDR + TMP_ARR_PTR EQU RET_ADDR + 2 ; Next 2 bytes for TMP_ARR_PTR ld e, (hl) inc hl ld d, (hl) + inc hl ; DE <-- PTR to Dim sizes table + ld (TMP_ARR_PTR), hl ; HL = Array __DATA__.__PTR__ inc hl - ld (TMP_ARR_PTR), hl - ex de, hl - ex (sp), hl ; Return address in HL, array address in the stack - ld (RET_ADDRESS + 1), hl ; Stores it for later + inc hl + ld c, (hl) + inc hl + ld b, (hl) ; BC <-- Array __LBOUND__ PTR + ld (LBOUND_PTR), bc ; Store it for later +#line 66 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + ex de, hl ; HL <-- PTR to Dim sizes table, DE <-- dummy + ex (sp), hl ; Return address in HL, PTR Dim sizes table onto Stack + ld (RET_ADDR), hl ; Stores it for later exx - pop hl ; Will use H'L' as the pointer + pop hl ; Will use H'L' as the pointer to Dim sizes table ld c, (hl) ; Loads Number of dimensions from (hl) inc hl ld b, (hl) inc hl ; Ready exx - ld hl, 0 ; HL = Offset "accumulator" + ld hl, 0 ; HL = Element Offset "accumulator" LOOP: -#line 64 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - pop bc ; Get next index (Ai) from the stack -#line 74 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - add hl, bc ; Adds current index + ex de, hl ; DE = Element Offset + ld hl, (LBOUND_PTR) + ld a, h + or l + ld b, h + ld c, l + jr z, 1f + ld c, (hl) + inc hl + ld b, (hl) + inc hl + ld (LBOUND_PTR), hl +1: + pop hl ; Get next index (Ai) from the stack + sbc hl, bc ; Subtract LBOUND +#line 116 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + add hl, de ; Adds current index exx ; Checks if B'C' = 0 ld a, b ; Which means we must exit (last element is not multiplied by anything) or c jr z, ARRAY_END ; if B'Ci == 0 we are done - ld e, (hl) ; Loads next dimension into D'E' + dec bc ; Decrements loop counter + ld e, (hl) ; Loads next dimension size into D'E' inc hl ld d, (hl) inc hl push de - dec bc ; Decrements loop counter exx pop de ; DE = Max bound Number (i-th dimension) - call __FNMUL + call __FNMUL ; HL <= HL * DE mod 65536 jp LOOP ARRAY_END: ld a, (hl) exx -#line 103 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 146 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl ld hl, 0 @@ -366,7 +393,7 @@ ARRAY_END: ARRAY_SIZE_LOOP: add hl, de djnz ARRAY_SIZE_LOOP -#line 113 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 156 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ex de, hl ld hl, (TMP_ARR_PTR) ld a, (hl) @@ -374,8 +401,9 @@ ARRAY_SIZE_LOOP: ld h, (hl) ld l, a add hl, de ; Adds element start -RET_ADDRESS: - jp 0 + ld de, (RET_ADDR) + push de + ret ;; Performs a faster multiply for little 16bit numbs LOCAL __FNMUL, __FNMUL2 __FNMUL: @@ -392,13 +420,11 @@ __FNMUL2: add hl, de djnz __FNMUL2 ret -TMP_ARR_PTR: - DW 0 ; temporary storage for pointer to tables ENDP pop namespace -#line 27 "aloadstr1.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/loadstr.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 27 "arch/zx48k/aloadstr1.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/loadstr.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -458,7 +484,7 @@ TMP_ARR_PTR: ; HL = BLOCK Start & DE = Length. ; An init directive is useful for initialization routines. ; They will be added automatically if needed. -#line 1 "/zxbasic/src/arch/zx48k/library-asm/error.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/error.asm" ; Simple error control routines ; vim:ts=4:et: push namespace core @@ -492,8 +518,8 @@ __STOP: ld (ERR_NR), a ret pop namespace -#line 69 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/heapinit.asm" +#line 69 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/heapinit.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -600,7 +626,7 @@ __MEM_INIT2: ret ENDP pop namespace -#line 70 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 70 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; --------------------------------------------------------------------- ; MEM_ALLOC ; Allocates a block of memory in the heap. @@ -631,9 +657,9 @@ __MEM_START: __MEM_LOOP: ; Loads lengh at (HL, HL+). If Lenght >= BC, jump to __MEM_DONE ld a, h ; HL = NULL (No memory available?) or l -#line 113 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 113 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ret z ; NULL -#line 115 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 115 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; HL = Pointer to Free block ld e, (hl) inc hl @@ -698,7 +724,7 @@ __MEM_SUBTRACT: ret ENDP pop namespace -#line 2 "/zxbasic/src/arch/zx48k/library-asm/loadstr.asm" +#line 2 "/zxbasic/src/lib/arch/zx48k/runtime/loadstr.asm" ; Loads a string (ptr) from HL ; and duplicates it on dynamic memory again ; Finally, it returns result pointer in HL @@ -735,15 +761,15 @@ __LOADSTR: ; __FASTCALL__ entry pop hl ; Recovers destiny in hl as result ret pop namespace -#line 28 "aloadstr1.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/storestr2.asm" +#line 28 "arch/zx48k/aloadstr1.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/storestr2.asm" ; Similar to __STORE_STR, but this one is called when ; the value of B$ if already duplicated onto the stack. ; So we needn't call STRASSING to create a duplication ; HL = address of string memory variable ; DE = address of 2n string. It just copies DE into (HL) ; freeing (HL) previously. -#line 1 "/zxbasic/src/arch/zx48k/library-asm/free.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/free.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -901,7 +927,7 @@ __MEM_BLOCK_JOIN: ; Joins current block (pointed by HL) with next one (pointed ret ENDP pop namespace -#line 9 "/zxbasic/src/arch/zx48k/library-asm/storestr2.asm" +#line 9 "/zxbasic/src/lib/arch/zx48k/runtime/storestr2.asm" push namespace core __PISTORE_STR2: ; Indirect store temporary string at (IX + BC) push ix @@ -928,5 +954,5 @@ __STORE_STR2: dec hl ; HL points to mem address variable. This might be useful in the future. ret pop namespace -#line 29 "aloadstr1.bas" +#line 29 "arch/zx48k/aloadstr1.bas" END diff --git a/tests/functional/arch/zx48k/arr_addr_global.asm b/tests/functional/arch/zx48k/arr_addr_global.asm index 712b06036..ade2067d9 100644 --- a/tests/functional/arch/zx48k/arr_addr_global.asm +++ b/tests/functional/arch/zx48k/arr_addr_global.asm @@ -22,6 +22,8 @@ _aglobal: DEFW .LABEL.__LABEL0 _aglobal.__DATA__.__PTR__: DEFW _aglobal.__DATA__ + DEFW 0 + DEFW 0 _aglobal.__DATA__: DEFB 00h DEFB 01h diff --git a/tests/functional/arch/zx48k/arr_addr_local.asm b/tests/functional/arch/zx48k/arr_addr_local.asm index 2fa41c890..da4157af5 100644 --- a/tests/functional/arch/zx48k/arr_addr_local.asm +++ b/tests/functional/arch/zx48k/arr_addr_local.asm @@ -78,7 +78,7 @@ _test__leave: pop ix ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -94,7 +94,7 @@ _test__leave: ; O = [a0 + b0 * (a1 + b1 * (a2 + ... bN-2(aN-1)))] ; What I will do here is to calculate the following sequence: ; ((aN-1 * bN-2) + aN-2) * bN-3 + ... -#line 1 "/zxbasic/src/arch/zx48k/library-asm/mul16.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/mul16.asm" push namespace core __MUL16: ; Mutiplies HL with the last value stored into de stack ; Works for both signed and unsigned @@ -120,59 +120,84 @@ __MUL16NOADD: ret ; Result in hl (16 lower bits) ENDP pop namespace -#line 20 "/zxbasic/src/arch/zx48k/library-asm/array.asm" -#line 24 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 20 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 24 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" push namespace core __ARRAY_PTR: ;; computes an array offset from a pointer ld c, (hl) inc hl ld h, (hl) - ld l, c + ld l, c ;; HL <-- [HL] __ARRAY: PROC LOCAL LOOP LOCAL ARRAY_END - LOCAL RET_ADDRESS ; Stores return address - LOCAL TMP_ARR_PTR ; Stores pointer temporarily + LOCAL TMP_ARR_PTR ; Ptr to Array DATA region. Stored temporarily + LOCAL LBOUND_PTR, UBOUND_PTR ; LBound and UBound PTR indexes + LOCAL RET_ADDR ; Contains the return address popped from the stack + LBOUND_PTR EQU 23698 ; Uses MEMBOT as a temporary variable + UBOUND_PTR EQU LBOUND_PTR + 2 ; Next 2 bytes for UBOUND PTR + RET_ADDR EQU UBOUND_PTR + 2 ; Next 2 bytes for RET_ADDR + TMP_ARR_PTR EQU RET_ADDR + 2 ; Next 2 bytes for TMP_ARR_PTR ld e, (hl) inc hl ld d, (hl) + inc hl ; DE <-- PTR to Dim sizes table + ld (TMP_ARR_PTR), hl ; HL = Array __DATA__.__PTR__ inc hl - ld (TMP_ARR_PTR), hl - ex de, hl - ex (sp), hl ; Return address in HL, array address in the stack - ld (RET_ADDRESS + 1), hl ; Stores it for later + inc hl + ld c, (hl) + inc hl + ld b, (hl) ; BC <-- Array __LBOUND__ PTR + ld (LBOUND_PTR), bc ; Store it for later +#line 66 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + ex de, hl ; HL <-- PTR to Dim sizes table, DE <-- dummy + ex (sp), hl ; Return address in HL, PTR Dim sizes table onto Stack + ld (RET_ADDR), hl ; Stores it for later exx - pop hl ; Will use H'L' as the pointer + pop hl ; Will use H'L' as the pointer to Dim sizes table ld c, (hl) ; Loads Number of dimensions from (hl) inc hl ld b, (hl) inc hl ; Ready exx - ld hl, 0 ; HL = Offset "accumulator" + ld hl, 0 ; HL = Element Offset "accumulator" LOOP: -#line 64 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - pop bc ; Get next index (Ai) from the stack -#line 74 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - add hl, bc ; Adds current index + ex de, hl ; DE = Element Offset + ld hl, (LBOUND_PTR) + ld a, h + or l + ld b, h + ld c, l + jr z, 1f + ld c, (hl) + inc hl + ld b, (hl) + inc hl + ld (LBOUND_PTR), hl +1: + pop hl ; Get next index (Ai) from the stack + sbc hl, bc ; Subtract LBOUND +#line 116 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + add hl, de ; Adds current index exx ; Checks if B'C' = 0 ld a, b ; Which means we must exit (last element is not multiplied by anything) or c jr z, ARRAY_END ; if B'Ci == 0 we are done - ld e, (hl) ; Loads next dimension into D'E' + dec bc ; Decrements loop counter + ld e, (hl) ; Loads next dimension size into D'E' inc hl ld d, (hl) inc hl push de - dec bc ; Decrements loop counter exx pop de ; DE = Max bound Number (i-th dimension) - call __FNMUL + call __FNMUL ; HL <= HL * DE mod 65536 jp LOOP ARRAY_END: ld a, (hl) exx -#line 103 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 146 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl ld hl, 0 @@ -180,7 +205,7 @@ ARRAY_END: ARRAY_SIZE_LOOP: add hl, de djnz ARRAY_SIZE_LOOP -#line 113 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 156 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ex de, hl ld hl, (TMP_ARR_PTR) ld a, (hl) @@ -188,8 +213,9 @@ ARRAY_SIZE_LOOP: ld h, (hl) ld l, a add hl, de ; Adds element start -RET_ADDRESS: - jp 0 + ld de, (RET_ADDR) + push de + ret ;; Performs a faster multiply for little 16bit numbs LOCAL __FNMUL, __FNMUL2 __FNMUL: @@ -206,13 +232,11 @@ __FNMUL2: add hl, de djnz __FNMUL2 ret -TMP_ARR_PTR: - DW 0 ; temporary storage for pointer to tables ENDP pop namespace -#line 55 "arr_addr_local.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/arrayalloc.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/calloc.asm" +#line 55 "arch/zx48k/arr_addr_local.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/arrayalloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/calloc.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -223,7 +247,7 @@ TMP_ARR_PTR: ; closed source programs). ; ; Please read the MIT license on the internet -#line 1 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -283,7 +307,7 @@ TMP_ARR_PTR: ; HL = BLOCK Start & DE = Length. ; An init directive is useful for initialization routines. ; They will be added automatically if needed. -#line 1 "/zxbasic/src/arch/zx48k/library-asm/error.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/error.asm" ; Simple error control routines ; vim:ts=4:et: push namespace core @@ -317,8 +341,8 @@ __STOP: ld (ERR_NR), a ret pop namespace -#line 69 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/heapinit.asm" +#line 69 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/heapinit.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -425,7 +449,7 @@ __MEM_INIT2: ret ENDP pop namespace -#line 70 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 70 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; --------------------------------------------------------------------- ; MEM_ALLOC ; Allocates a block of memory in the heap. @@ -456,9 +480,9 @@ __MEM_START: __MEM_LOOP: ; Loads lengh at (HL, HL+). If Lenght >= BC, jump to __MEM_DONE ld a, h ; HL = NULL (No memory available?) or l -#line 113 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 113 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ret z ; NULL -#line 115 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 115 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; HL = Pointer to Free block ld e, (hl) inc hl @@ -523,7 +547,7 @@ __MEM_SUBTRACT: ret ENDP pop namespace -#line 13 "/zxbasic/src/arch/zx48k/library-asm/calloc.asm" +#line 13 "/zxbasic/src/lib/arch/zx48k/runtime/calloc.asm" ; --------------------------------------------------------------------- ; MEM_CALLOC ; Allocates a block of memory in the heap, and clears it filling it @@ -557,7 +581,7 @@ __MEM_CALLOC: pop hl ret pop namespace -#line 3 "/zxbasic/src/arch/zx48k/library-asm/arrayalloc.asm" +#line 3 "/zxbasic/src/lib/arch/zx48k/runtime/arrayalloc.asm" ; --------------------------------------------------------------------- ; __ALLOC_LOCAL_ARRAY ; Allocates an array element area in the heap, and clears it filling it @@ -621,10 +645,10 @@ __ALLOC_INITIALIZED_LOCAL_ARRAY: ldir pop hl ; HL = addr of LBound area if used ret -#line 139 "/zxbasic/src/arch/zx48k/library-asm/arrayalloc.asm" +#line 139 "/zxbasic/src/lib/arch/zx48k/runtime/arrayalloc.asm" pop namespace -#line 56 "arr_addr_local.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/free.asm" +#line 56 "arch/zx48k/arr_addr_local.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/free.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -782,7 +806,7 @@ __MEM_BLOCK_JOIN: ; Joins current block (pointed by HL) with next one (pointed ret ENDP pop namespace -#line 57 "arr_addr_local.bas" +#line 57 "arch/zx48k/arr_addr_local.bas" .LABEL.__LABEL0: DEFB 01h DEFB 00h diff --git a/tests/functional/arch/zx48k/arr_addr_param.asm b/tests/functional/arch/zx48k/arr_addr_param.asm index 47c62512d..0cca34d7d 100644 --- a/tests/functional/arch/zx48k/arr_addr_param.asm +++ b/tests/functional/arch/zx48k/arr_addr_param.asm @@ -22,6 +22,8 @@ _aglobal1: DEFW .LABEL.__LABEL0 _aglobal1.__DATA__.__PTR__: DEFW _aglobal1.__DATA__ + DEFW 0 + DEFW 0 _aglobal1.__DATA__: DEFB 00h DEFB 01h @@ -81,7 +83,7 @@ _test__leave: exx ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -97,7 +99,7 @@ _test__leave: ; O = [a0 + b0 * (a1 + b1 * (a2 + ... bN-2(aN-1)))] ; What I will do here is to calculate the following sequence: ; ((aN-1 * bN-2) + aN-2) * bN-3 + ... -#line 1 "/zxbasic/src/arch/zx48k/library-asm/mul16.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/mul16.asm" push namespace core __MUL16: ; Mutiplies HL with the last value stored into de stack ; Works for both signed and unsigned @@ -123,59 +125,84 @@ __MUL16NOADD: ret ; Result in hl (16 lower bits) ENDP pop namespace -#line 20 "/zxbasic/src/arch/zx48k/library-asm/array.asm" -#line 24 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 20 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 24 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" push namespace core __ARRAY_PTR: ;; computes an array offset from a pointer ld c, (hl) inc hl ld h, (hl) - ld l, c + ld l, c ;; HL <-- [HL] __ARRAY: PROC LOCAL LOOP LOCAL ARRAY_END - LOCAL RET_ADDRESS ; Stores return address - LOCAL TMP_ARR_PTR ; Stores pointer temporarily + LOCAL TMP_ARR_PTR ; Ptr to Array DATA region. Stored temporarily + LOCAL LBOUND_PTR, UBOUND_PTR ; LBound and UBound PTR indexes + LOCAL RET_ADDR ; Contains the return address popped from the stack + LBOUND_PTR EQU 23698 ; Uses MEMBOT as a temporary variable + UBOUND_PTR EQU LBOUND_PTR + 2 ; Next 2 bytes for UBOUND PTR + RET_ADDR EQU UBOUND_PTR + 2 ; Next 2 bytes for RET_ADDR + TMP_ARR_PTR EQU RET_ADDR + 2 ; Next 2 bytes for TMP_ARR_PTR ld e, (hl) inc hl ld d, (hl) + inc hl ; DE <-- PTR to Dim sizes table + ld (TMP_ARR_PTR), hl ; HL = Array __DATA__.__PTR__ inc hl - ld (TMP_ARR_PTR), hl - ex de, hl - ex (sp), hl ; Return address in HL, array address in the stack - ld (RET_ADDRESS + 1), hl ; Stores it for later + inc hl + ld c, (hl) + inc hl + ld b, (hl) ; BC <-- Array __LBOUND__ PTR + ld (LBOUND_PTR), bc ; Store it for later +#line 66 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + ex de, hl ; HL <-- PTR to Dim sizes table, DE <-- dummy + ex (sp), hl ; Return address in HL, PTR Dim sizes table onto Stack + ld (RET_ADDR), hl ; Stores it for later exx - pop hl ; Will use H'L' as the pointer + pop hl ; Will use H'L' as the pointer to Dim sizes table ld c, (hl) ; Loads Number of dimensions from (hl) inc hl ld b, (hl) inc hl ; Ready exx - ld hl, 0 ; HL = Offset "accumulator" + ld hl, 0 ; HL = Element Offset "accumulator" LOOP: -#line 64 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - pop bc ; Get next index (Ai) from the stack -#line 74 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - add hl, bc ; Adds current index + ex de, hl ; DE = Element Offset + ld hl, (LBOUND_PTR) + ld a, h + or l + ld b, h + ld c, l + jr z, 1f + ld c, (hl) + inc hl + ld b, (hl) + inc hl + ld (LBOUND_PTR), hl +1: + pop hl ; Get next index (Ai) from the stack + sbc hl, bc ; Subtract LBOUND +#line 116 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + add hl, de ; Adds current index exx ; Checks if B'C' = 0 ld a, b ; Which means we must exit (last element is not multiplied by anything) or c jr z, ARRAY_END ; if B'Ci == 0 we are done - ld e, (hl) ; Loads next dimension into D'E' + dec bc ; Decrements loop counter + ld e, (hl) ; Loads next dimension size into D'E' inc hl ld d, (hl) inc hl push de - dec bc ; Decrements loop counter exx pop de ; DE = Max bound Number (i-th dimension) - call __FNMUL + call __FNMUL ; HL <= HL * DE mod 65536 jp LOOP ARRAY_END: ld a, (hl) exx -#line 103 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 146 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl ld hl, 0 @@ -183,7 +210,7 @@ ARRAY_END: ARRAY_SIZE_LOOP: add hl, de djnz ARRAY_SIZE_LOOP -#line 113 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 156 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ex de, hl ld hl, (TMP_ARR_PTR) ld a, (hl) @@ -191,8 +218,9 @@ ARRAY_SIZE_LOOP: ld h, (hl) ld l, a add hl, de ; Adds element start -RET_ADDRESS: - jp 0 + ld de, (RET_ADDR) + push de + ret ;; Performs a faster multiply for little 16bit numbs LOCAL __FNMUL, __FNMUL2 __FNMUL: @@ -209,9 +237,7 @@ __FNMUL2: add hl, de djnz __FNMUL2 ret -TMP_ARR_PTR: - DW 0 ; temporary storage for pointer to tables ENDP pop namespace -#line 45 "arr_addr_param.bas" +#line 45 "arch/zx48k/arr_addr_param.bas" END diff --git a/tests/functional/arch/zx48k/array00.asm b/tests/functional/arch/zx48k/array00.asm index 7f501a156..5efbb68b0 100644 --- a/tests/functional/arch/zx48k/array00.asm +++ b/tests/functional/arch/zx48k/array00.asm @@ -22,6 +22,8 @@ _bufferx: DEFW .LABEL.__LABEL0 _bufferx.__DATA__.__PTR__: DEFW _bufferx.__DATA__ + DEFW 0 + DEFW 0 _bufferx.__DATA__: DEFB 0Ah DEFB 00h diff --git a/tests/functional/arch/zx48k/array01.asm b/tests/functional/arch/zx48k/array01.asm index 9bb226313..ed0e116ce 100644 --- a/tests/functional/arch/zx48k/array01.asm +++ b/tests/functional/arch/zx48k/array01.asm @@ -22,6 +22,8 @@ _a: DEFW .LABEL.__LABEL0 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW 0 + DEFW 0 _a.__DATA__: DEFB 00h DEFB 00h diff --git a/tests/functional/arch/zx48k/array02.asm b/tests/functional/arch/zx48k/array02.asm index 6c61d3063..9e7bddfef 100644 --- a/tests/functional/arch/zx48k/array02.asm +++ b/tests/functional/arch/zx48k/array02.asm @@ -24,6 +24,8 @@ _a: DEFW .LABEL.__LABEL0 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW 0 + DEFW 0 _a.__DATA__: DEFB 00h DEFB 00h diff --git a/tests/functional/arch/zx48k/array03.asm b/tests/functional/arch/zx48k/array03.asm index 04b79c300..b744c0392 100644 --- a/tests/functional/arch/zx48k/array03.asm +++ b/tests/functional/arch/zx48k/array03.asm @@ -24,6 +24,8 @@ _a: DEFW .LABEL.__LABEL0 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW 0 + DEFW 0 _a.__DATA__: DEFB 00h DEFB 00h @@ -64,7 +66,7 @@ _a.__DATA__: ei ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -80,7 +82,7 @@ _a.__DATA__: ; O = [a0 + b0 * (a1 + b1 * (a2 + ... bN-2(aN-1)))] ; What I will do here is to calculate the following sequence: ; ((aN-1 * bN-2) + aN-2) * bN-3 + ... -#line 1 "/zxbasic/src/arch/zx48k/library-asm/mul16.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/mul16.asm" push namespace core __MUL16: ; Mutiplies HL with the last value stored into de stack ; Works for both signed and unsigned @@ -106,59 +108,84 @@ __MUL16NOADD: ret ; Result in hl (16 lower bits) ENDP pop namespace -#line 20 "/zxbasic/src/arch/zx48k/library-asm/array.asm" -#line 24 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 20 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 24 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" push namespace core __ARRAY_PTR: ;; computes an array offset from a pointer ld c, (hl) inc hl ld h, (hl) - ld l, c + ld l, c ;; HL <-- [HL] __ARRAY: PROC LOCAL LOOP LOCAL ARRAY_END - LOCAL RET_ADDRESS ; Stores return address - LOCAL TMP_ARR_PTR ; Stores pointer temporarily + LOCAL TMP_ARR_PTR ; Ptr to Array DATA region. Stored temporarily + LOCAL LBOUND_PTR, UBOUND_PTR ; LBound and UBound PTR indexes + LOCAL RET_ADDR ; Contains the return address popped from the stack + LBOUND_PTR EQU 23698 ; Uses MEMBOT as a temporary variable + UBOUND_PTR EQU LBOUND_PTR + 2 ; Next 2 bytes for UBOUND PTR + RET_ADDR EQU UBOUND_PTR + 2 ; Next 2 bytes for RET_ADDR + TMP_ARR_PTR EQU RET_ADDR + 2 ; Next 2 bytes for TMP_ARR_PTR ld e, (hl) inc hl ld d, (hl) + inc hl ; DE <-- PTR to Dim sizes table + ld (TMP_ARR_PTR), hl ; HL = Array __DATA__.__PTR__ inc hl - ld (TMP_ARR_PTR), hl - ex de, hl - ex (sp), hl ; Return address in HL, array address in the stack - ld (RET_ADDRESS + 1), hl ; Stores it for later + inc hl + ld c, (hl) + inc hl + ld b, (hl) ; BC <-- Array __LBOUND__ PTR + ld (LBOUND_PTR), bc ; Store it for later +#line 66 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + ex de, hl ; HL <-- PTR to Dim sizes table, DE <-- dummy + ex (sp), hl ; Return address in HL, PTR Dim sizes table onto Stack + ld (RET_ADDR), hl ; Stores it for later exx - pop hl ; Will use H'L' as the pointer + pop hl ; Will use H'L' as the pointer to Dim sizes table ld c, (hl) ; Loads Number of dimensions from (hl) inc hl ld b, (hl) inc hl ; Ready exx - ld hl, 0 ; HL = Offset "accumulator" + ld hl, 0 ; HL = Element Offset "accumulator" LOOP: -#line 64 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - pop bc ; Get next index (Ai) from the stack -#line 74 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - add hl, bc ; Adds current index + ex de, hl ; DE = Element Offset + ld hl, (LBOUND_PTR) + ld a, h + or l + ld b, h + ld c, l + jr z, 1f + ld c, (hl) + inc hl + ld b, (hl) + inc hl + ld (LBOUND_PTR), hl +1: + pop hl ; Get next index (Ai) from the stack + sbc hl, bc ; Subtract LBOUND +#line 116 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + add hl, de ; Adds current index exx ; Checks if B'C' = 0 ld a, b ; Which means we must exit (last element is not multiplied by anything) or c jr z, ARRAY_END ; if B'Ci == 0 we are done - ld e, (hl) ; Loads next dimension into D'E' + dec bc ; Decrements loop counter + ld e, (hl) ; Loads next dimension size into D'E' inc hl ld d, (hl) inc hl push de - dec bc ; Decrements loop counter exx pop de ; DE = Max bound Number (i-th dimension) - call __FNMUL + call __FNMUL ; HL <= HL * DE mod 65536 jp LOOP ARRAY_END: ld a, (hl) exx -#line 103 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 146 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl ld hl, 0 @@ -166,7 +193,7 @@ ARRAY_END: ARRAY_SIZE_LOOP: add hl, de djnz ARRAY_SIZE_LOOP -#line 113 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 156 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ex de, hl ld hl, (TMP_ARR_PTR) ld a, (hl) @@ -174,8 +201,9 @@ ARRAY_SIZE_LOOP: ld h, (hl) ld l, a add hl, de ; Adds element start -RET_ADDRESS: - jp 0 + ld de, (RET_ADDR) + push de + ret ;; Performs a faster multiply for little 16bit numbs LOCAL __FNMUL, __FNMUL2 __FNMUL: @@ -192,9 +220,7 @@ __FNMUL2: add hl, de djnz __FNMUL2 ret -TMP_ARR_PTR: - DW 0 ; temporary storage for pointer to tables ENDP pop namespace -#line 25 "array03.bas" +#line 25 "arch/zx48k/array03.bas" END diff --git a/tests/functional/arch/zx48k/array04.asm b/tests/functional/arch/zx48k/array04.asm index 76e9b10f7..da88ceefe 100644 --- a/tests/functional/arch/zx48k/array04.asm +++ b/tests/functional/arch/zx48k/array04.asm @@ -22,6 +22,8 @@ _a: DEFW .LABEL.__LABEL0 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW 0 + DEFW 0 _a.__DATA__: DEFB 00h DEFB 00h diff --git a/tests/functional/arch/zx48k/array05.asm b/tests/functional/arch/zx48k/array05.asm index 19d118479..346cace04 100644 --- a/tests/functional/arch/zx48k/array05.asm +++ b/tests/functional/arch/zx48k/array05.asm @@ -24,6 +24,8 @@ _a: DEFW .LABEL.__LABEL0 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW 0 + DEFW 0 _a.__DATA__: DEFB 00h DEFB 00h diff --git a/tests/functional/arch/zx48k/array06.asm b/tests/functional/arch/zx48k/array06.asm index 54f3ce304..4357b8db3 100644 --- a/tests/functional/arch/zx48k/array06.asm +++ b/tests/functional/arch/zx48k/array06.asm @@ -24,6 +24,8 @@ _a: DEFW .LABEL.__LABEL0 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW 0 + DEFW 0 _a.__DATA__: DEFB 00h DEFB 00h @@ -75,7 +77,7 @@ _a.__DATA__: ei ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -91,7 +93,7 @@ _a.__DATA__: ; O = [a0 + b0 * (a1 + b1 * (a2 + ... bN-2(aN-1)))] ; What I will do here is to calculate the following sequence: ; ((aN-1 * bN-2) + aN-2) * bN-3 + ... -#line 1 "/zxbasic/src/arch/zx48k/library-asm/mul16.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/mul16.asm" push namespace core __MUL16: ; Mutiplies HL with the last value stored into de stack ; Works for both signed and unsigned @@ -117,59 +119,84 @@ __MUL16NOADD: ret ; Result in hl (16 lower bits) ENDP pop namespace -#line 20 "/zxbasic/src/arch/zx48k/library-asm/array.asm" -#line 24 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 20 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 24 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" push namespace core __ARRAY_PTR: ;; computes an array offset from a pointer ld c, (hl) inc hl ld h, (hl) - ld l, c + ld l, c ;; HL <-- [HL] __ARRAY: PROC LOCAL LOOP LOCAL ARRAY_END - LOCAL RET_ADDRESS ; Stores return address - LOCAL TMP_ARR_PTR ; Stores pointer temporarily + LOCAL TMP_ARR_PTR ; Ptr to Array DATA region. Stored temporarily + LOCAL LBOUND_PTR, UBOUND_PTR ; LBound and UBound PTR indexes + LOCAL RET_ADDR ; Contains the return address popped from the stack + LBOUND_PTR EQU 23698 ; Uses MEMBOT as a temporary variable + UBOUND_PTR EQU LBOUND_PTR + 2 ; Next 2 bytes for UBOUND PTR + RET_ADDR EQU UBOUND_PTR + 2 ; Next 2 bytes for RET_ADDR + TMP_ARR_PTR EQU RET_ADDR + 2 ; Next 2 bytes for TMP_ARR_PTR ld e, (hl) inc hl ld d, (hl) + inc hl ; DE <-- PTR to Dim sizes table + ld (TMP_ARR_PTR), hl ; HL = Array __DATA__.__PTR__ inc hl - ld (TMP_ARR_PTR), hl - ex de, hl - ex (sp), hl ; Return address in HL, array address in the stack - ld (RET_ADDRESS + 1), hl ; Stores it for later + inc hl + ld c, (hl) + inc hl + ld b, (hl) ; BC <-- Array __LBOUND__ PTR + ld (LBOUND_PTR), bc ; Store it for later +#line 66 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + ex de, hl ; HL <-- PTR to Dim sizes table, DE <-- dummy + ex (sp), hl ; Return address in HL, PTR Dim sizes table onto Stack + ld (RET_ADDR), hl ; Stores it for later exx - pop hl ; Will use H'L' as the pointer + pop hl ; Will use H'L' as the pointer to Dim sizes table ld c, (hl) ; Loads Number of dimensions from (hl) inc hl ld b, (hl) inc hl ; Ready exx - ld hl, 0 ; HL = Offset "accumulator" + ld hl, 0 ; HL = Element Offset "accumulator" LOOP: -#line 64 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - pop bc ; Get next index (Ai) from the stack -#line 74 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - add hl, bc ; Adds current index + ex de, hl ; DE = Element Offset + ld hl, (LBOUND_PTR) + ld a, h + or l + ld b, h + ld c, l + jr z, 1f + ld c, (hl) + inc hl + ld b, (hl) + inc hl + ld (LBOUND_PTR), hl +1: + pop hl ; Get next index (Ai) from the stack + sbc hl, bc ; Subtract LBOUND +#line 116 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + add hl, de ; Adds current index exx ; Checks if B'C' = 0 ld a, b ; Which means we must exit (last element is not multiplied by anything) or c jr z, ARRAY_END ; if B'Ci == 0 we are done - ld e, (hl) ; Loads next dimension into D'E' + dec bc ; Decrements loop counter + ld e, (hl) ; Loads next dimension size into D'E' inc hl ld d, (hl) inc hl push de - dec bc ; Decrements loop counter exx pop de ; DE = Max bound Number (i-th dimension) - call __FNMUL + call __FNMUL ; HL <= HL * DE mod 65536 jp LOOP ARRAY_END: ld a, (hl) exx -#line 103 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 146 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl ld hl, 0 @@ -177,7 +204,7 @@ ARRAY_END: ARRAY_SIZE_LOOP: add hl, de djnz ARRAY_SIZE_LOOP -#line 113 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 156 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ex de, hl ld hl, (TMP_ARR_PTR) ld a, (hl) @@ -185,8 +212,9 @@ ARRAY_SIZE_LOOP: ld h, (hl) ld l, a add hl, de ; Adds element start -RET_ADDRESS: - jp 0 + ld de, (RET_ADDR) + push de + ret ;; Performs a faster multiply for little 16bit numbs LOCAL __FNMUL, __FNMUL2 __FNMUL: @@ -203,9 +231,7 @@ __FNMUL2: add hl, de djnz __FNMUL2 ret -TMP_ARR_PTR: - DW 0 ; temporary storage for pointer to tables ENDP pop namespace -#line 25 "array06.bas" +#line 25 "arch/zx48k/array06.bas" END diff --git a/tests/functional/arch/zx48k/array07.asm b/tests/functional/arch/zx48k/array07.asm index f056d4d9d..22d83740b 100644 --- a/tests/functional/arch/zx48k/array07.asm +++ b/tests/functional/arch/zx48k/array07.asm @@ -29,6 +29,8 @@ _a: DEFW .LABEL.__LABEL0 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW 0 + DEFW 0 _a.__DATA__: DEFB 00h DEFB 00h @@ -149,52 +151,77 @@ __ARRAY_PTR: ;; computes an array offset from a pointer ld c, (hl) inc hl ld h, (hl) - ld l, c + ld l, c ;; HL <-- [HL] __ARRAY: PROC LOCAL LOOP LOCAL ARRAY_END - LOCAL RET_ADDRESS ; Stores return address - LOCAL TMP_ARR_PTR ; Stores pointer temporarily + LOCAL TMP_ARR_PTR ; Ptr to Array DATA region. Stored temporarily + LOCAL LBOUND_PTR, UBOUND_PTR ; LBound and UBound PTR indexes + LOCAL RET_ADDR ; Contains the return address popped from the stack + LBOUND_PTR EQU 23698 ; Uses MEMBOT as a temporary variable + UBOUND_PTR EQU LBOUND_PTR + 2 ; Next 2 bytes for UBOUND PTR + RET_ADDR EQU UBOUND_PTR + 2 ; Next 2 bytes for RET_ADDR + TMP_ARR_PTR EQU RET_ADDR + 2 ; Next 2 bytes for TMP_ARR_PTR ld e, (hl) inc hl ld d, (hl) + inc hl ; DE <-- PTR to Dim sizes table + ld (TMP_ARR_PTR), hl ; HL = Array __DATA__.__PTR__ inc hl - ld (TMP_ARR_PTR), hl - ex de, hl - ex (sp), hl ; Return address in HL, array address in the stack - ld (RET_ADDRESS + 1), hl ; Stores it for later + inc hl + ld c, (hl) + inc hl + ld b, (hl) ; BC <-- Array __LBOUND__ PTR + ld (LBOUND_PTR), bc ; Store it for later +#line 66 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + ex de, hl ; HL <-- PTR to Dim sizes table, DE <-- dummy + ex (sp), hl ; Return address in HL, PTR Dim sizes table onto Stack + ld (RET_ADDR), hl ; Stores it for later exx - pop hl ; Will use H'L' as the pointer + pop hl ; Will use H'L' as the pointer to Dim sizes table ld c, (hl) ; Loads Number of dimensions from (hl) inc hl ld b, (hl) inc hl ; Ready exx - ld hl, 0 ; HL = Offset "accumulator" + ld hl, 0 ; HL = Element Offset "accumulator" LOOP: -#line 64 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" - pop bc ; Get next index (Ai) from the stack -#line 74 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" - add hl, bc ; Adds current index + ex de, hl ; DE = Element Offset + ld hl, (LBOUND_PTR) + ld a, h + or l + ld b, h + ld c, l + jr z, 1f + ld c, (hl) + inc hl + ld b, (hl) + inc hl + ld (LBOUND_PTR), hl +1: + pop hl ; Get next index (Ai) from the stack + sbc hl, bc ; Subtract LBOUND +#line 116 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + add hl, de ; Adds current index exx ; Checks if B'C' = 0 ld a, b ; Which means we must exit (last element is not multiplied by anything) or c jr z, ARRAY_END ; if B'Ci == 0 we are done - ld e, (hl) ; Loads next dimension into D'E' + dec bc ; Decrements loop counter + ld e, (hl) ; Loads next dimension size into D'E' inc hl ld d, (hl) inc hl push de - dec bc ; Decrements loop counter exx pop de ; DE = Max bound Number (i-th dimension) - call __FNMUL + call __FNMUL ; HL <= HL * DE mod 65536 jp LOOP ARRAY_END: ld a, (hl) exx -#line 103 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 146 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl ld hl, 0 @@ -202,7 +229,7 @@ ARRAY_END: ARRAY_SIZE_LOOP: add hl, de djnz ARRAY_SIZE_LOOP -#line 113 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 156 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ex de, hl ld hl, (TMP_ARR_PTR) ld a, (hl) @@ -210,8 +237,9 @@ ARRAY_SIZE_LOOP: ld h, (hl) ld l, a add hl, de ; Adds element start -RET_ADDRESS: - jp 0 + ld de, (RET_ADDR) + push de + ret ;; Performs a faster multiply for little 16bit numbs LOCAL __FNMUL, __FNMUL2 __FNMUL: @@ -228,8 +256,6 @@ __FNMUL2: add hl, de djnz __FNMUL2 ret -TMP_ARR_PTR: - DW 0 ; temporary storage for pointer to tables ENDP pop namespace #line 45 "arch/zx48k/array07.bas" diff --git a/tests/functional/arch/zx48k/array08.asm b/tests/functional/arch/zx48k/array08.asm index 6a0a07bec..6c64b0a5c 100644 --- a/tests/functional/arch/zx48k/array08.asm +++ b/tests/functional/arch/zx48k/array08.asm @@ -31,6 +31,8 @@ _a: DEFW .LABEL.__LABEL0 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW 0 + DEFW 0 _a.__DATA__: DEFB 00h DEFB 00h @@ -129,52 +131,77 @@ __ARRAY_PTR: ;; computes an array offset from a pointer ld c, (hl) inc hl ld h, (hl) - ld l, c + ld l, c ;; HL <-- [HL] __ARRAY: PROC LOCAL LOOP LOCAL ARRAY_END - LOCAL RET_ADDRESS ; Stores return address - LOCAL TMP_ARR_PTR ; Stores pointer temporarily + LOCAL TMP_ARR_PTR ; Ptr to Array DATA region. Stored temporarily + LOCAL LBOUND_PTR, UBOUND_PTR ; LBound and UBound PTR indexes + LOCAL RET_ADDR ; Contains the return address popped from the stack + LBOUND_PTR EQU 23698 ; Uses MEMBOT as a temporary variable + UBOUND_PTR EQU LBOUND_PTR + 2 ; Next 2 bytes for UBOUND PTR + RET_ADDR EQU UBOUND_PTR + 2 ; Next 2 bytes for RET_ADDR + TMP_ARR_PTR EQU RET_ADDR + 2 ; Next 2 bytes for TMP_ARR_PTR ld e, (hl) inc hl ld d, (hl) + inc hl ; DE <-- PTR to Dim sizes table + ld (TMP_ARR_PTR), hl ; HL = Array __DATA__.__PTR__ inc hl - ld (TMP_ARR_PTR), hl - ex de, hl - ex (sp), hl ; Return address in HL, array address in the stack - ld (RET_ADDRESS + 1), hl ; Stores it for later + inc hl + ld c, (hl) + inc hl + ld b, (hl) ; BC <-- Array __LBOUND__ PTR + ld (LBOUND_PTR), bc ; Store it for later +#line 66 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + ex de, hl ; HL <-- PTR to Dim sizes table, DE <-- dummy + ex (sp), hl ; Return address in HL, PTR Dim sizes table onto Stack + ld (RET_ADDR), hl ; Stores it for later exx - pop hl ; Will use H'L' as the pointer + pop hl ; Will use H'L' as the pointer to Dim sizes table ld c, (hl) ; Loads Number of dimensions from (hl) inc hl ld b, (hl) inc hl ; Ready exx - ld hl, 0 ; HL = Offset "accumulator" + ld hl, 0 ; HL = Element Offset "accumulator" LOOP: -#line 64 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" - pop bc ; Get next index (Ai) from the stack -#line 74 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" - add hl, bc ; Adds current index + ex de, hl ; DE = Element Offset + ld hl, (LBOUND_PTR) + ld a, h + or l + ld b, h + ld c, l + jr z, 1f + ld c, (hl) + inc hl + ld b, (hl) + inc hl + ld (LBOUND_PTR), hl +1: + pop hl ; Get next index (Ai) from the stack + sbc hl, bc ; Subtract LBOUND +#line 116 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + add hl, de ; Adds current index exx ; Checks if B'C' = 0 ld a, b ; Which means we must exit (last element is not multiplied by anything) or c jr z, ARRAY_END ; if B'Ci == 0 we are done - ld e, (hl) ; Loads next dimension into D'E' + dec bc ; Decrements loop counter + ld e, (hl) ; Loads next dimension size into D'E' inc hl ld d, (hl) inc hl push de - dec bc ; Decrements loop counter exx pop de ; DE = Max bound Number (i-th dimension) - call __FNMUL + call __FNMUL ; HL <= HL * DE mod 65536 jp LOOP ARRAY_END: ld a, (hl) exx -#line 103 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 146 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl ld hl, 0 @@ -182,7 +209,7 @@ ARRAY_END: ARRAY_SIZE_LOOP: add hl, de djnz ARRAY_SIZE_LOOP -#line 113 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 156 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ex de, hl ld hl, (TMP_ARR_PTR) ld a, (hl) @@ -190,8 +217,9 @@ ARRAY_SIZE_LOOP: ld h, (hl) ld l, a add hl, de ; Adds element start -RET_ADDRESS: - jp 0 + ld de, (RET_ADDR) + push de + ret ;; Performs a faster multiply for little 16bit numbs LOCAL __FNMUL, __FNMUL2 __FNMUL: @@ -208,8 +236,6 @@ __FNMUL2: add hl, de djnz __FNMUL2 ret -TMP_ARR_PTR: - DW 0 ; temporary storage for pointer to tables ENDP pop namespace #line 23 "arch/zx48k/array08.bas" diff --git a/tests/functional/arch/zx48k/array09.asm b/tests/functional/arch/zx48k/array09.asm index 71bef2eff..266b2efea 100644 --- a/tests/functional/arch/zx48k/array09.asm +++ b/tests/functional/arch/zx48k/array09.asm @@ -31,6 +31,8 @@ _a: DEFW .LABEL.__LABEL0 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW 0 + DEFW 0 _a.__DATA__: DEFB 00h DEFB 00h @@ -129,52 +131,77 @@ __ARRAY_PTR: ;; computes an array offset from a pointer ld c, (hl) inc hl ld h, (hl) - ld l, c + ld l, c ;; HL <-- [HL] __ARRAY: PROC LOCAL LOOP LOCAL ARRAY_END - LOCAL RET_ADDRESS ; Stores return address - LOCAL TMP_ARR_PTR ; Stores pointer temporarily + LOCAL TMP_ARR_PTR ; Ptr to Array DATA region. Stored temporarily + LOCAL LBOUND_PTR, UBOUND_PTR ; LBound and UBound PTR indexes + LOCAL RET_ADDR ; Contains the return address popped from the stack + LBOUND_PTR EQU 23698 ; Uses MEMBOT as a temporary variable + UBOUND_PTR EQU LBOUND_PTR + 2 ; Next 2 bytes for UBOUND PTR + RET_ADDR EQU UBOUND_PTR + 2 ; Next 2 bytes for RET_ADDR + TMP_ARR_PTR EQU RET_ADDR + 2 ; Next 2 bytes for TMP_ARR_PTR ld e, (hl) inc hl ld d, (hl) + inc hl ; DE <-- PTR to Dim sizes table + ld (TMP_ARR_PTR), hl ; HL = Array __DATA__.__PTR__ inc hl - ld (TMP_ARR_PTR), hl - ex de, hl - ex (sp), hl ; Return address in HL, array address in the stack - ld (RET_ADDRESS + 1), hl ; Stores it for later + inc hl + ld c, (hl) + inc hl + ld b, (hl) ; BC <-- Array __LBOUND__ PTR + ld (LBOUND_PTR), bc ; Store it for later +#line 66 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + ex de, hl ; HL <-- PTR to Dim sizes table, DE <-- dummy + ex (sp), hl ; Return address in HL, PTR Dim sizes table onto Stack + ld (RET_ADDR), hl ; Stores it for later exx - pop hl ; Will use H'L' as the pointer + pop hl ; Will use H'L' as the pointer to Dim sizes table ld c, (hl) ; Loads Number of dimensions from (hl) inc hl ld b, (hl) inc hl ; Ready exx - ld hl, 0 ; HL = Offset "accumulator" + ld hl, 0 ; HL = Element Offset "accumulator" LOOP: -#line 64 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" - pop bc ; Get next index (Ai) from the stack -#line 74 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" - add hl, bc ; Adds current index + ex de, hl ; DE = Element Offset + ld hl, (LBOUND_PTR) + ld a, h + or l + ld b, h + ld c, l + jr z, 1f + ld c, (hl) + inc hl + ld b, (hl) + inc hl + ld (LBOUND_PTR), hl +1: + pop hl ; Get next index (Ai) from the stack + sbc hl, bc ; Subtract LBOUND +#line 116 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + add hl, de ; Adds current index exx ; Checks if B'C' = 0 ld a, b ; Which means we must exit (last element is not multiplied by anything) or c jr z, ARRAY_END ; if B'Ci == 0 we are done - ld e, (hl) ; Loads next dimension into D'E' + dec bc ; Decrements loop counter + ld e, (hl) ; Loads next dimension size into D'E' inc hl ld d, (hl) inc hl push de - dec bc ; Decrements loop counter exx pop de ; DE = Max bound Number (i-th dimension) - call __FNMUL + call __FNMUL ; HL <= HL * DE mod 65536 jp LOOP ARRAY_END: ld a, (hl) exx -#line 103 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 146 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl ld hl, 0 @@ -182,7 +209,7 @@ ARRAY_END: ARRAY_SIZE_LOOP: add hl, de djnz ARRAY_SIZE_LOOP -#line 113 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 156 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ex de, hl ld hl, (TMP_ARR_PTR) ld a, (hl) @@ -190,8 +217,9 @@ ARRAY_SIZE_LOOP: ld h, (hl) ld l, a add hl, de ; Adds element start -RET_ADDRESS: - jp 0 + ld de, (RET_ADDR) + push de + ret ;; Performs a faster multiply for little 16bit numbs LOCAL __FNMUL, __FNMUL2 __FNMUL: @@ -208,8 +236,6 @@ __FNMUL2: add hl, de djnz __FNMUL2 ret -TMP_ARR_PTR: - DW 0 ; temporary storage for pointer to tables ENDP pop namespace #line 23 "arch/zx48k/array09.bas" diff --git a/tests/functional/arch/zx48k/array10.asm b/tests/functional/arch/zx48k/array10.asm index 8eace1e8a..25d904185 100644 --- a/tests/functional/arch/zx48k/array10.asm +++ b/tests/functional/arch/zx48k/array10.asm @@ -26,6 +26,8 @@ _x: DEFW .LABEL.__LABEL0 _x.__DATA__.__PTR__: DEFW _x.__DATA__ + DEFW 0 + DEFW 0 _x.__DATA__: DEFB 00h DEFB 00h @@ -85,6 +87,8 @@ _y: DEFW .LABEL.__LABEL1 _y.__DATA__.__PTR__: DEFW _y.__DATA__ + DEFW 0 + DEFW 0 _y.__DATA__: DEFB 00h DEFB 00h @@ -198,7 +202,7 @@ _y.__DATA__: ei ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -214,7 +218,7 @@ _y.__DATA__: ; O = [a0 + b0 * (a1 + b1 * (a2 + ... bN-2(aN-1)))] ; What I will do here is to calculate the following sequence: ; ((aN-1 * bN-2) + aN-2) * bN-3 + ... -#line 1 "/zxbasic/src/arch/zx48k/library-asm/mul16.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/mul16.asm" push namespace core __MUL16: ; Mutiplies HL with the last value stored into de stack ; Works for both signed and unsigned @@ -240,59 +244,84 @@ __MUL16NOADD: ret ; Result in hl (16 lower bits) ENDP pop namespace -#line 20 "/zxbasic/src/arch/zx48k/library-asm/array.asm" -#line 24 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 20 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 24 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" push namespace core __ARRAY_PTR: ;; computes an array offset from a pointer ld c, (hl) inc hl ld h, (hl) - ld l, c + ld l, c ;; HL <-- [HL] __ARRAY: PROC LOCAL LOOP LOCAL ARRAY_END - LOCAL RET_ADDRESS ; Stores return address - LOCAL TMP_ARR_PTR ; Stores pointer temporarily + LOCAL TMP_ARR_PTR ; Ptr to Array DATA region. Stored temporarily + LOCAL LBOUND_PTR, UBOUND_PTR ; LBound and UBound PTR indexes + LOCAL RET_ADDR ; Contains the return address popped from the stack + LBOUND_PTR EQU 23698 ; Uses MEMBOT as a temporary variable + UBOUND_PTR EQU LBOUND_PTR + 2 ; Next 2 bytes for UBOUND PTR + RET_ADDR EQU UBOUND_PTR + 2 ; Next 2 bytes for RET_ADDR + TMP_ARR_PTR EQU RET_ADDR + 2 ; Next 2 bytes for TMP_ARR_PTR ld e, (hl) inc hl ld d, (hl) + inc hl ; DE <-- PTR to Dim sizes table + ld (TMP_ARR_PTR), hl ; HL = Array __DATA__.__PTR__ inc hl - ld (TMP_ARR_PTR), hl - ex de, hl - ex (sp), hl ; Return address in HL, array address in the stack - ld (RET_ADDRESS + 1), hl ; Stores it for later + inc hl + ld c, (hl) + inc hl + ld b, (hl) ; BC <-- Array __LBOUND__ PTR + ld (LBOUND_PTR), bc ; Store it for later +#line 66 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + ex de, hl ; HL <-- PTR to Dim sizes table, DE <-- dummy + ex (sp), hl ; Return address in HL, PTR Dim sizes table onto Stack + ld (RET_ADDR), hl ; Stores it for later exx - pop hl ; Will use H'L' as the pointer + pop hl ; Will use H'L' as the pointer to Dim sizes table ld c, (hl) ; Loads Number of dimensions from (hl) inc hl ld b, (hl) inc hl ; Ready exx - ld hl, 0 ; HL = Offset "accumulator" + ld hl, 0 ; HL = Element Offset "accumulator" LOOP: -#line 64 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - pop bc ; Get next index (Ai) from the stack -#line 74 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - add hl, bc ; Adds current index + ex de, hl ; DE = Element Offset + ld hl, (LBOUND_PTR) + ld a, h + or l + ld b, h + ld c, l + jr z, 1f + ld c, (hl) + inc hl + ld b, (hl) + inc hl + ld (LBOUND_PTR), hl +1: + pop hl ; Get next index (Ai) from the stack + sbc hl, bc ; Subtract LBOUND +#line 116 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + add hl, de ; Adds current index exx ; Checks if B'C' = 0 ld a, b ; Which means we must exit (last element is not multiplied by anything) or c jr z, ARRAY_END ; if B'Ci == 0 we are done - ld e, (hl) ; Loads next dimension into D'E' + dec bc ; Decrements loop counter + ld e, (hl) ; Loads next dimension size into D'E' inc hl ld d, (hl) inc hl push de - dec bc ; Decrements loop counter exx pop de ; DE = Max bound Number (i-th dimension) - call __FNMUL + call __FNMUL ; HL <= HL * DE mod 65536 jp LOOP ARRAY_END: ld a, (hl) exx -#line 103 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 146 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl ld hl, 0 @@ -300,7 +329,7 @@ ARRAY_END: ARRAY_SIZE_LOOP: add hl, de djnz ARRAY_SIZE_LOOP -#line 113 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 156 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ex de, hl ld hl, (TMP_ARR_PTR) ld a, (hl) @@ -308,8 +337,9 @@ ARRAY_SIZE_LOOP: ld h, (hl) ld l, a add hl, de ; Adds element start -RET_ADDRESS: - jp 0 + ld de, (RET_ADDR) + push de + ret ;; Performs a faster multiply for little 16bit numbs LOCAL __FNMUL, __FNMUL2 __FNMUL: @@ -326,9 +356,7 @@ __FNMUL2: add hl, de djnz __FNMUL2 ret -TMP_ARR_PTR: - DW 0 ; temporary storage for pointer to tables ENDP pop namespace -#line 58 "array10.bas" +#line 58 "arch/zx48k/array10.bas" END diff --git a/tests/functional/arch/zx48k/array12.asm b/tests/functional/arch/zx48k/array12.asm index ec0c14400..3b2de09b4 100644 --- a/tests/functional/arch/zx48k/array12.asm +++ b/tests/functional/arch/zx48k/array12.asm @@ -31,6 +31,8 @@ _a: DEFW .LABEL.__LABEL0 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW 0 + DEFW 0 _a.__DATA__: DEFB 00h DEFB 00h @@ -352,52 +354,77 @@ __ARRAY_PTR: ;; computes an array offset from a pointer ld c, (hl) inc hl ld h, (hl) - ld l, c + ld l, c ;; HL <-- [HL] __ARRAY: PROC LOCAL LOOP LOCAL ARRAY_END - LOCAL RET_ADDRESS ; Stores return address - LOCAL TMP_ARR_PTR ; Stores pointer temporarily + LOCAL TMP_ARR_PTR ; Ptr to Array DATA region. Stored temporarily + LOCAL LBOUND_PTR, UBOUND_PTR ; LBound and UBound PTR indexes + LOCAL RET_ADDR ; Contains the return address popped from the stack + LBOUND_PTR EQU 23698 ; Uses MEMBOT as a temporary variable + UBOUND_PTR EQU LBOUND_PTR + 2 ; Next 2 bytes for UBOUND PTR + RET_ADDR EQU UBOUND_PTR + 2 ; Next 2 bytes for RET_ADDR + TMP_ARR_PTR EQU RET_ADDR + 2 ; Next 2 bytes for TMP_ARR_PTR ld e, (hl) inc hl ld d, (hl) + inc hl ; DE <-- PTR to Dim sizes table + ld (TMP_ARR_PTR), hl ; HL = Array __DATA__.__PTR__ inc hl - ld (TMP_ARR_PTR), hl - ex de, hl - ex (sp), hl ; Return address in HL, array address in the stack - ld (RET_ADDRESS + 1), hl ; Stores it for later + inc hl + ld c, (hl) + inc hl + ld b, (hl) ; BC <-- Array __LBOUND__ PTR + ld (LBOUND_PTR), bc ; Store it for later +#line 66 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + ex de, hl ; HL <-- PTR to Dim sizes table, DE <-- dummy + ex (sp), hl ; Return address in HL, PTR Dim sizes table onto Stack + ld (RET_ADDR), hl ; Stores it for later exx - pop hl ; Will use H'L' as the pointer + pop hl ; Will use H'L' as the pointer to Dim sizes table ld c, (hl) ; Loads Number of dimensions from (hl) inc hl ld b, (hl) inc hl ; Ready exx - ld hl, 0 ; HL = Offset "accumulator" + ld hl, 0 ; HL = Element Offset "accumulator" LOOP: -#line 64 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" - pop bc ; Get next index (Ai) from the stack -#line 74 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" - add hl, bc ; Adds current index + ex de, hl ; DE = Element Offset + ld hl, (LBOUND_PTR) + ld a, h + or l + ld b, h + ld c, l + jr z, 1f + ld c, (hl) + inc hl + ld b, (hl) + inc hl + ld (LBOUND_PTR), hl +1: + pop hl ; Get next index (Ai) from the stack + sbc hl, bc ; Subtract LBOUND +#line 116 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + add hl, de ; Adds current index exx ; Checks if B'C' = 0 ld a, b ; Which means we must exit (last element is not multiplied by anything) or c jr z, ARRAY_END ; if B'Ci == 0 we are done - ld e, (hl) ; Loads next dimension into D'E' + dec bc ; Decrements loop counter + ld e, (hl) ; Loads next dimension size into D'E' inc hl ld d, (hl) inc hl push de - dec bc ; Decrements loop counter exx pop de ; DE = Max bound Number (i-th dimension) - call __FNMUL + call __FNMUL ; HL <= HL * DE mod 65536 jp LOOP ARRAY_END: ld a, (hl) exx -#line 103 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 146 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl ld hl, 0 @@ -405,7 +432,7 @@ ARRAY_END: ARRAY_SIZE_LOOP: add hl, de djnz ARRAY_SIZE_LOOP -#line 113 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 156 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ex de, hl ld hl, (TMP_ARR_PTR) ld a, (hl) @@ -413,8 +440,9 @@ ARRAY_SIZE_LOOP: ld h, (hl) ld l, a add hl, de ; Adds element start -RET_ADDRESS: - jp 0 + ld de, (RET_ADDR) + push de + ret ;; Performs a faster multiply for little 16bit numbs LOCAL __FNMUL, __FNMUL2 __FNMUL: @@ -431,8 +459,6 @@ __FNMUL2: add hl, de djnz __FNMUL2 ret -TMP_ARR_PTR: - DW 0 ; temporary storage for pointer to tables ENDP pop namespace #line 25 "arch/zx48k/array12.bas" diff --git a/tests/functional/arch/zx48k/array_check_param.asm b/tests/functional/arch/zx48k/array_check_param.asm index 3be48a999..815c6cde3 100644 --- a/tests/functional/arch/zx48k/array_check_param.asm +++ b/tests/functional/arch/zx48k/array_check_param.asm @@ -70,7 +70,7 @@ _pickString__leave: exx ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -86,7 +86,7 @@ _pickString__leave: ; O = [a0 + b0 * (a1 + b1 * (a2 + ... bN-2(aN-1)))] ; What I will do here is to calculate the following sequence: ; ((aN-1 * bN-2) + aN-2) * bN-3 + ... -#line 1 "/zxbasic/src/arch/zx48k/library-asm/mul16.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/mul16.asm" push namespace core __MUL16: ; Mutiplies HL with the last value stored into de stack ; Works for both signed and unsigned @@ -112,59 +112,84 @@ __MUL16NOADD: ret ; Result in hl (16 lower bits) ENDP pop namespace -#line 20 "/zxbasic/src/arch/zx48k/library-asm/array.asm" -#line 24 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 20 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 24 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" push namespace core __ARRAY_PTR: ;; computes an array offset from a pointer ld c, (hl) inc hl ld h, (hl) - ld l, c + ld l, c ;; HL <-- [HL] __ARRAY: PROC LOCAL LOOP LOCAL ARRAY_END - LOCAL RET_ADDRESS ; Stores return address - LOCAL TMP_ARR_PTR ; Stores pointer temporarily + LOCAL TMP_ARR_PTR ; Ptr to Array DATA region. Stored temporarily + LOCAL LBOUND_PTR, UBOUND_PTR ; LBound and UBound PTR indexes + LOCAL RET_ADDR ; Contains the return address popped from the stack + LBOUND_PTR EQU 23698 ; Uses MEMBOT as a temporary variable + UBOUND_PTR EQU LBOUND_PTR + 2 ; Next 2 bytes for UBOUND PTR + RET_ADDR EQU UBOUND_PTR + 2 ; Next 2 bytes for RET_ADDR + TMP_ARR_PTR EQU RET_ADDR + 2 ; Next 2 bytes for TMP_ARR_PTR ld e, (hl) inc hl ld d, (hl) + inc hl ; DE <-- PTR to Dim sizes table + ld (TMP_ARR_PTR), hl ; HL = Array __DATA__.__PTR__ inc hl - ld (TMP_ARR_PTR), hl - ex de, hl - ex (sp), hl ; Return address in HL, array address in the stack - ld (RET_ADDRESS + 1), hl ; Stores it for later + inc hl + ld c, (hl) + inc hl + ld b, (hl) ; BC <-- Array __LBOUND__ PTR + ld (LBOUND_PTR), bc ; Store it for later +#line 66 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + ex de, hl ; HL <-- PTR to Dim sizes table, DE <-- dummy + ex (sp), hl ; Return address in HL, PTR Dim sizes table onto Stack + ld (RET_ADDR), hl ; Stores it for later exx - pop hl ; Will use H'L' as the pointer + pop hl ; Will use H'L' as the pointer to Dim sizes table ld c, (hl) ; Loads Number of dimensions from (hl) inc hl ld b, (hl) inc hl ; Ready exx - ld hl, 0 ; HL = Offset "accumulator" + ld hl, 0 ; HL = Element Offset "accumulator" LOOP: -#line 64 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - pop bc ; Get next index (Ai) from the stack -#line 74 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - add hl, bc ; Adds current index + ex de, hl ; DE = Element Offset + ld hl, (LBOUND_PTR) + ld a, h + or l + ld b, h + ld c, l + jr z, 1f + ld c, (hl) + inc hl + ld b, (hl) + inc hl + ld (LBOUND_PTR), hl +1: + pop hl ; Get next index (Ai) from the stack + sbc hl, bc ; Subtract LBOUND +#line 116 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + add hl, de ; Adds current index exx ; Checks if B'C' = 0 ld a, b ; Which means we must exit (last element is not multiplied by anything) or c jr z, ARRAY_END ; if B'Ci == 0 we are done - ld e, (hl) ; Loads next dimension into D'E' + dec bc ; Decrements loop counter + ld e, (hl) ; Loads next dimension size into D'E' inc hl ld d, (hl) inc hl push de - dec bc ; Decrements loop counter exx pop de ; DE = Max bound Number (i-th dimension) - call __FNMUL + call __FNMUL ; HL <= HL * DE mod 65536 jp LOOP ARRAY_END: ld a, (hl) exx -#line 103 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 146 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl ld hl, 0 @@ -172,7 +197,7 @@ ARRAY_END: ARRAY_SIZE_LOOP: add hl, de djnz ARRAY_SIZE_LOOP -#line 113 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 156 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ex de, hl ld hl, (TMP_ARR_PTR) ld a, (hl) @@ -180,8 +205,9 @@ ARRAY_SIZE_LOOP: ld h, (hl) ld l, a add hl, de ; Adds element start -RET_ADDRESS: - jp 0 + ld de, (RET_ADDR) + push de + ret ;; Performs a faster multiply for little 16bit numbs LOCAL __FNMUL, __FNMUL2 __FNMUL: @@ -198,13 +224,11 @@ __FNMUL2: add hl, de djnz __FNMUL2 ret -TMP_ARR_PTR: - DW 0 ; temporary storage for pointer to tables ENDP pop namespace -#line 47 "array_check_param.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/ftou32reg.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/neg32.asm" +#line 47 "arch/zx48k/array_check_param.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/ftou32reg.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/neg32.asm" push namespace core __ABS32: bit 7, d @@ -229,7 +253,7 @@ __NEG32: ; Negates DEHL (Two's complement) inc de ret pop namespace -#line 2 "/zxbasic/src/arch/zx48k/library-asm/ftou32reg.asm" +#line 2 "/zxbasic/src/lib/arch/zx48k/runtime/ftou32reg.asm" push namespace core __FTOU32REG: ; Converts a Float to (un)signed 32 bit integer (NOTE: It's ALWAYS 32 bit signed) ; Input FP number in A EDCB (A exponent, EDCB mantissa) @@ -301,9 +325,9 @@ __FTOU8: ; Converts float in C ED LH to Unsigned byte in A ld a, l ret pop namespace -#line 48 "array_check_param.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/loadstr.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 48 "arch/zx48k/array_check_param.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/loadstr.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -363,7 +387,7 @@ __FTOU8: ; Converts float in C ED LH to Unsigned byte in A ; HL = BLOCK Start & DE = Length. ; An init directive is useful for initialization routines. ; They will be added automatically if needed. -#line 1 "/zxbasic/src/arch/zx48k/library-asm/error.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/error.asm" ; Simple error control routines ; vim:ts=4:et: push namespace core @@ -397,8 +421,8 @@ __STOP: ld (ERR_NR), a ret pop namespace -#line 69 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/heapinit.asm" +#line 69 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/heapinit.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -505,7 +529,7 @@ __MEM_INIT2: ret ENDP pop namespace -#line 70 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 70 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; --------------------------------------------------------------------- ; MEM_ALLOC ; Allocates a block of memory in the heap. @@ -536,9 +560,9 @@ __MEM_START: __MEM_LOOP: ; Loads lengh at (HL, HL+). If Lenght >= BC, jump to __MEM_DONE ld a, h ; HL = NULL (No memory available?) or l -#line 113 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 113 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ret z ; NULL -#line 115 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 115 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; HL = Pointer to Free block ld e, (hl) inc hl @@ -603,7 +627,7 @@ __MEM_SUBTRACT: ret ENDP pop namespace -#line 2 "/zxbasic/src/arch/zx48k/library-asm/loadstr.asm" +#line 2 "/zxbasic/src/lib/arch/zx48k/runtime/loadstr.asm" ; Loads a string (ptr) from HL ; and duplicates it on dynamic memory again ; Finally, it returns result pointer in HL @@ -640,13 +664,13 @@ __LOADSTR: ; __FASTCALL__ entry pop hl ; Recovers destiny in hl as result ret pop namespace -#line 49 "array_check_param.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/ploadf.asm" +#line 49 "arch/zx48k/array_check_param.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/ploadf.asm" ; Parameter / Local var load ; A => Offset ; IX = Stack Frame ; RESULT: HL => IX + DE -#line 1 "/zxbasic/src/arch/zx48k/library-asm/iloadf.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/iloadf.asm" ; __FASTCALL__ routine which ; loads a 40 bits floating point into A ED CB ; stored at position pointed by POINTER HL @@ -673,7 +697,7 @@ __LOADF: ; Loads a 40 bits FP number from address pointed by HL ld b, (hl) ret pop namespace -#line 7 "/zxbasic/src/arch/zx48k/library-asm/ploadf.asm" +#line 7 "/zxbasic/src/lib/arch/zx48k/runtime/ploadf.asm" push namespace core __PLOADF: push ix @@ -681,5 +705,5 @@ __PLOADF: add hl, de jp __LOADF pop namespace -#line 50 "array_check_param.bas" +#line 50 "arch/zx48k/array_check_param.bas" END diff --git a/tests/functional/arch/zx48k/array_check_warn.asm b/tests/functional/arch/zx48k/array_check_warn.asm index f1f923b1e..3b89bb1fb 100644 --- a/tests/functional/arch/zx48k/array_check_warn.asm +++ b/tests/functional/arch/zx48k/array_check_warn.asm @@ -24,6 +24,8 @@ _aux: DEFW .LABEL.__LABEL0 _aux.__DATA__.__PTR__: DEFW _aux.__DATA__ + DEFW 0 + DEFW 0 _aux.__DATA__: DEFB 00h DEFB 00h @@ -36,6 +38,8 @@ _aux1: DEFW .LABEL.__LABEL1 _aux1.__DATA__.__PTR__: DEFW _aux1.__DATA__ + DEFW _aux1.__LBOUND__ + DEFW 0 _aux1.__DATA__: DEFB 00h DEFB 00h @@ -43,6 +47,8 @@ _aux1.__DATA__: .LABEL.__LABEL1: DEFW 0000h DEFB 01h +_aux1.__LBOUND__: + DEFW 0001h .core.ZXBASIC_USER_DATA_END: .core.__MAIN_PROGRAM__: ld a, (_aux.__DATA__ + 4) diff --git a/tests/functional/arch/zx48k/arraycopy0.asm b/tests/functional/arch/zx48k/arraycopy0.asm index 4f0a7f22a..fab7c663d 100644 --- a/tests/functional/arch/zx48k/arraycopy0.asm +++ b/tests/functional/arch/zx48k/arraycopy0.asm @@ -24,6 +24,8 @@ _grid: DEFW .LABEL.__LABEL0 _grid.__DATA__.__PTR__: DEFW _grid.__DATA__ + DEFW 0 + DEFW 0 _grid.__DATA__: DEFB 00h DEFB 01h @@ -37,6 +39,8 @@ _gridcopy: DEFW .LABEL.__LABEL1 _gridcopy.__DATA__.__PTR__: DEFW _gridcopy.__DATA__ + DEFW 0 + DEFW 0 _gridcopy.__DATA__: DEFB 00h DEFB 00h diff --git a/tests/functional/arch/zx48k/arraycopy1.asm b/tests/functional/arch/zx48k/arraycopy1.asm index c6cf9f718..f1aa26eac 100644 --- a/tests/functional/arch/zx48k/arraycopy1.asm +++ b/tests/functional/arch/zx48k/arraycopy1.asm @@ -27,6 +27,8 @@ _grid: DEFW .LABEL.__LABEL1 _grid.__DATA__.__PTR__: DEFW _grid.__DATA__ + DEFW 0 + DEFW 0 _grid.__DATA__: DEFB 00h DEFB 01h @@ -84,8 +86,8 @@ _Test__leave: pop ix ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/arrayalloc.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/calloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/arrayalloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/calloc.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -96,7 +98,7 @@ _Test__leave: ; closed source programs). ; ; Please read the MIT license on the internet -#line 1 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -156,7 +158,7 @@ _Test__leave: ; HL = BLOCK Start & DE = Length. ; An init directive is useful for initialization routines. ; They will be added automatically if needed. -#line 1 "/zxbasic/src/arch/zx48k/library-asm/error.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/error.asm" ; Simple error control routines ; vim:ts=4:et: push namespace core @@ -190,8 +192,8 @@ __STOP: ld (ERR_NR), a ret pop namespace -#line 69 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/heapinit.asm" +#line 69 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/heapinit.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -298,7 +300,7 @@ __MEM_INIT2: ret ENDP pop namespace -#line 70 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 70 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; --------------------------------------------------------------------- ; MEM_ALLOC ; Allocates a block of memory in the heap. @@ -329,9 +331,9 @@ __MEM_START: __MEM_LOOP: ; Loads lengh at (HL, HL+). If Lenght >= BC, jump to __MEM_DONE ld a, h ; HL = NULL (No memory available?) or l -#line 113 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 113 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ret z ; NULL -#line 115 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 115 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; HL = Pointer to Free block ld e, (hl) inc hl @@ -396,7 +398,7 @@ __MEM_SUBTRACT: ret ENDP pop namespace -#line 13 "/zxbasic/src/arch/zx48k/library-asm/calloc.asm" +#line 13 "/zxbasic/src/lib/arch/zx48k/runtime/calloc.asm" ; --------------------------------------------------------------------- ; MEM_CALLOC ; Allocates a block of memory in the heap, and clears it filling it @@ -430,7 +432,7 @@ __MEM_CALLOC: pop hl ret pop namespace -#line 3 "/zxbasic/src/arch/zx48k/library-asm/arrayalloc.asm" +#line 3 "/zxbasic/src/lib/arch/zx48k/runtime/arrayalloc.asm" ; --------------------------------------------------------------------- ; __ALLOC_LOCAL_ARRAY ; Allocates an array element area in the heap, and clears it filling it @@ -494,10 +496,10 @@ __ALLOC_INITIALIZED_LOCAL_ARRAY: ldir pop hl ; HL = addr of LBound area if used ret -#line 139 "/zxbasic/src/arch/zx48k/library-asm/arrayalloc.asm" +#line 139 "/zxbasic/src/lib/arch/zx48k/runtime/arrayalloc.asm" pop namespace -#line 48 "arraycopy1.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/free.asm" +#line 48 "arch/zx48k/arraycopy1.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/free.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -655,7 +657,7 @@ __MEM_BLOCK_JOIN: ; Joins current block (pointed by HL) with next one (pointed ret ENDP pop namespace -#line 49 "arraycopy1.bas" +#line 49 "arch/zx48k/arraycopy1.bas" .LABEL.__LABEL0: DEFB 00h DEFB 00h diff --git a/tests/functional/arch/zx48k/arraycopy2.asm b/tests/functional/arch/zx48k/arraycopy2.asm index 33922ed91..ddf16ae88 100644 --- a/tests/functional/arch/zx48k/arraycopy2.asm +++ b/tests/functional/arch/zx48k/arraycopy2.asm @@ -27,6 +27,8 @@ _gridcopy: DEFW .LABEL.__LABEL2 _gridcopy.__DATA__.__PTR__: DEFW _gridcopy.__DATA__ + DEFW 0 + DEFW 0 _gridcopy.__DATA__: DEFB 00h DEFB 00h @@ -86,8 +88,8 @@ _Test__leave: pop ix ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/arrayalloc.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/calloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/arrayalloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/calloc.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -98,7 +100,7 @@ _Test__leave: ; closed source programs). ; ; Please read the MIT license on the internet -#line 1 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -158,7 +160,7 @@ _Test__leave: ; HL = BLOCK Start & DE = Length. ; An init directive is useful for initialization routines. ; They will be added automatically if needed. -#line 1 "/zxbasic/src/arch/zx48k/library-asm/error.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/error.asm" ; Simple error control routines ; vim:ts=4:et: push namespace core @@ -192,8 +194,8 @@ __STOP: ld (ERR_NR), a ret pop namespace -#line 69 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/heapinit.asm" +#line 69 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/heapinit.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -300,7 +302,7 @@ __MEM_INIT2: ret ENDP pop namespace -#line 70 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 70 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; --------------------------------------------------------------------- ; MEM_ALLOC ; Allocates a block of memory in the heap. @@ -331,9 +333,9 @@ __MEM_START: __MEM_LOOP: ; Loads lengh at (HL, HL+). If Lenght >= BC, jump to __MEM_DONE ld a, h ; HL = NULL (No memory available?) or l -#line 113 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 113 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ret z ; NULL -#line 115 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 115 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; HL = Pointer to Free block ld e, (hl) inc hl @@ -398,7 +400,7 @@ __MEM_SUBTRACT: ret ENDP pop namespace -#line 13 "/zxbasic/src/arch/zx48k/library-asm/calloc.asm" +#line 13 "/zxbasic/src/lib/arch/zx48k/runtime/calloc.asm" ; --------------------------------------------------------------------- ; MEM_CALLOC ; Allocates a block of memory in the heap, and clears it filling it @@ -432,7 +434,7 @@ __MEM_CALLOC: pop hl ret pop namespace -#line 3 "/zxbasic/src/arch/zx48k/library-asm/arrayalloc.asm" +#line 3 "/zxbasic/src/lib/arch/zx48k/runtime/arrayalloc.asm" ; --------------------------------------------------------------------- ; __ALLOC_LOCAL_ARRAY ; Allocates an array element area in the heap, and clears it filling it @@ -496,10 +498,10 @@ __ALLOC_INITIALIZED_LOCAL_ARRAY: ldir pop hl ; HL = addr of LBound area if used ret -#line 139 "/zxbasic/src/arch/zx48k/library-asm/arrayalloc.asm" +#line 139 "/zxbasic/src/lib/arch/zx48k/runtime/arrayalloc.asm" pop namespace -#line 50 "arraycopy2.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/free.asm" +#line 50 "arch/zx48k/arraycopy2.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/free.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -657,7 +659,7 @@ __MEM_BLOCK_JOIN: ; Joins current block (pointed by HL) with next one (pointed ret ENDP pop namespace -#line 51 "arraycopy2.bas" +#line 51 "arch/zx48k/arraycopy2.bas" .LABEL.__LABEL0: DEFB 00h DEFB 00h diff --git a/tests/functional/arch/zx48k/arraycopy5.asm b/tests/functional/arch/zx48k/arraycopy5.asm index c3313a4ab..2271c4ea3 100644 --- a/tests/functional/arch/zx48k/arraycopy5.asm +++ b/tests/functional/arch/zx48k/arraycopy5.asm @@ -27,6 +27,8 @@ _a: DEFW .LABEL.__LABEL1 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW 0 + DEFW 0 _a.__DATA__: DEFB 00h DEFB 00h @@ -43,6 +45,8 @@ _c: DEFW .LABEL.__LABEL2 _c.__DATA__.__PTR__: DEFW _c.__DATA__ + DEFW 0 + DEFW 0 _c.__DATA__: DEFB 00h DEFB 00h diff --git a/tests/functional/arch/zx48k/arrbase1.asm b/tests/functional/arch/zx48k/arrbase1.asm index 204127113..c460df294 100644 --- a/tests/functional/arch/zx48k/arrbase1.asm +++ b/tests/functional/arch/zx48k/arrbase1.asm @@ -29,6 +29,8 @@ _c: DEFW .LABEL.__LABEL5 _c.__DATA__.__PTR__: DEFW _c.__DATA__ + DEFW _c.__LBOUND__ + DEFW 0 _c.__DATA__: DEFB 00h DEFB 00h @@ -40,6 +42,9 @@ _c.__DATA__: DEFW 0001h DEFW 0003h DEFB 01h +_c.__LBOUND__: + DEFW 0001h + DEFW 0001h .core.ZXBASIC_USER_DATA_END: .core.__MAIN_PROGRAM__: ld hl, 1 @@ -49,10 +54,9 @@ _c.__DATA__: ld a, 2 call .core.__READ push af - ld hl, 0 + ld hl, 1 push hl ld hl, (_k) - dec hl push hl ld hl, _c call .core.__ARRAY @@ -87,7 +91,7 @@ __DATA__0: __DATA__END: DEFB 00h ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -103,7 +107,7 @@ __DATA__END: ; O = [a0 + b0 * (a1 + b1 * (a2 + ... bN-2(aN-1)))] ; What I will do here is to calculate the following sequence: ; ((aN-1 * bN-2) + aN-2) * bN-3 + ... -#line 1 "/zxbasic/src/arch/zx48k/library-asm/mul16.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/mul16.asm" push namespace core __MUL16: ; Mutiplies HL with the last value stored into de stack ; Works for both signed and unsigned @@ -129,59 +133,84 @@ __MUL16NOADD: ret ; Result in hl (16 lower bits) ENDP pop namespace -#line 20 "/zxbasic/src/arch/zx48k/library-asm/array.asm" -#line 24 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 20 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 24 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" push namespace core __ARRAY_PTR: ;; computes an array offset from a pointer ld c, (hl) inc hl ld h, (hl) - ld l, c + ld l, c ;; HL <-- [HL] __ARRAY: PROC LOCAL LOOP LOCAL ARRAY_END - LOCAL RET_ADDRESS ; Stores return address - LOCAL TMP_ARR_PTR ; Stores pointer temporarily + LOCAL TMP_ARR_PTR ; Ptr to Array DATA region. Stored temporarily + LOCAL LBOUND_PTR, UBOUND_PTR ; LBound and UBound PTR indexes + LOCAL RET_ADDR ; Contains the return address popped from the stack + LBOUND_PTR EQU 23698 ; Uses MEMBOT as a temporary variable + UBOUND_PTR EQU LBOUND_PTR + 2 ; Next 2 bytes for UBOUND PTR + RET_ADDR EQU UBOUND_PTR + 2 ; Next 2 bytes for RET_ADDR + TMP_ARR_PTR EQU RET_ADDR + 2 ; Next 2 bytes for TMP_ARR_PTR ld e, (hl) inc hl ld d, (hl) + inc hl ; DE <-- PTR to Dim sizes table + ld (TMP_ARR_PTR), hl ; HL = Array __DATA__.__PTR__ inc hl - ld (TMP_ARR_PTR), hl - ex de, hl - ex (sp), hl ; Return address in HL, array address in the stack - ld (RET_ADDRESS + 1), hl ; Stores it for later + inc hl + ld c, (hl) + inc hl + ld b, (hl) ; BC <-- Array __LBOUND__ PTR + ld (LBOUND_PTR), bc ; Store it for later +#line 66 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + ex de, hl ; HL <-- PTR to Dim sizes table, DE <-- dummy + ex (sp), hl ; Return address in HL, PTR Dim sizes table onto Stack + ld (RET_ADDR), hl ; Stores it for later exx - pop hl ; Will use H'L' as the pointer + pop hl ; Will use H'L' as the pointer to Dim sizes table ld c, (hl) ; Loads Number of dimensions from (hl) inc hl ld b, (hl) inc hl ; Ready exx - ld hl, 0 ; HL = Offset "accumulator" + ld hl, 0 ; HL = Element Offset "accumulator" LOOP: -#line 64 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - pop bc ; Get next index (Ai) from the stack -#line 74 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - add hl, bc ; Adds current index + ex de, hl ; DE = Element Offset + ld hl, (LBOUND_PTR) + ld a, h + or l + ld b, h + ld c, l + jr z, 1f + ld c, (hl) + inc hl + ld b, (hl) + inc hl + ld (LBOUND_PTR), hl +1: + pop hl ; Get next index (Ai) from the stack + sbc hl, bc ; Subtract LBOUND +#line 116 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + add hl, de ; Adds current index exx ; Checks if B'C' = 0 ld a, b ; Which means we must exit (last element is not multiplied by anything) or c jr z, ARRAY_END ; if B'Ci == 0 we are done - ld e, (hl) ; Loads next dimension into D'E' + dec bc ; Decrements loop counter + ld e, (hl) ; Loads next dimension size into D'E' inc hl ld d, (hl) inc hl push de - dec bc ; Decrements loop counter exx pop de ; DE = Max bound Number (i-th dimension) - call __FNMUL + call __FNMUL ; HL <= HL * DE mod 65536 jp LOOP ARRAY_END: ld a, (hl) exx -#line 103 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 146 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl ld hl, 0 @@ -189,7 +218,7 @@ ARRAY_END: ARRAY_SIZE_LOOP: add hl, de djnz ARRAY_SIZE_LOOP -#line 113 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 156 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ex de, hl ld hl, (TMP_ARR_PTR) ld a, (hl) @@ -197,8 +226,9 @@ ARRAY_SIZE_LOOP: ld h, (hl) ld l, a add hl, de ; Adds element start -RET_ADDRESS: - jp 0 + ld de, (RET_ADDR) + push de + ret ;; Performs a faster multiply for little 16bit numbs LOCAL __FNMUL, __FNMUL2 __FNMUL: @@ -215,12 +245,10 @@ __FNMUL2: add hl, de djnz __FNMUL2 ret -TMP_ARR_PTR: - DW 0 ; temporary storage for pointer to tables ENDP pop namespace -#line 47 "arrbase1.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/read_restore.asm" +#line 46 "arch/zx48k/arrbase1.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/read_restore.asm" ;; This implements READ & RESTORE functions ;; Reads a new element from the DATA Address code ;; Updates the DATA_ADDR read ptr for the next read @@ -238,7 +266,7 @@ TMP_ARR_PTR: ;; 09: Float ;; bit7 is set for a parameter-less function ;; In that case, the next two bytes are the ptr of the function to jump -#line 1 "/zxbasic/src/arch/zx48k/library-asm/error.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/error.asm" ; Simple error control routines ; vim:ts=4:et: push namespace core @@ -272,9 +300,9 @@ __STOP: ld (ERR_NR), a ret pop namespace -#line 23 "/zxbasic/src/arch/zx48k/library-asm/read_restore.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/loadstr.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 23 "/zxbasic/src/lib/arch/zx48k/runtime/read_restore.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/loadstr.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -334,7 +362,7 @@ __STOP: ; HL = BLOCK Start & DE = Length. ; An init directive is useful for initialization routines. ; They will be added automatically if needed. -#line 1 "/zxbasic/src/arch/zx48k/library-asm/heapinit.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/heapinit.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -441,7 +469,7 @@ __MEM_INIT2: ret ENDP pop namespace -#line 70 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 70 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; --------------------------------------------------------------------- ; MEM_ALLOC ; Allocates a block of memory in the heap. @@ -472,9 +500,9 @@ __MEM_START: __MEM_LOOP: ; Loads lengh at (HL, HL+). If Lenght >= BC, jump to __MEM_DONE ld a, h ; HL = NULL (No memory available?) or l -#line 113 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 113 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ret z ; NULL -#line 115 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 115 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; HL = Pointer to Free block ld e, (hl) inc hl @@ -539,7 +567,7 @@ __MEM_SUBTRACT: ret ENDP pop namespace -#line 2 "/zxbasic/src/arch/zx48k/library-asm/loadstr.asm" +#line 2 "/zxbasic/src/lib/arch/zx48k/runtime/loadstr.asm" ; Loads a string (ptr) from HL ; and duplicates it on dynamic memory again ; Finally, it returns result pointer in HL @@ -576,8 +604,8 @@ __LOADSTR: ; __FASTCALL__ entry pop hl ; Recovers destiny in hl as result ret pop namespace -#line 24 "/zxbasic/src/arch/zx48k/library-asm/read_restore.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/iload32.asm" +#line 24 "/zxbasic/src/lib/arch/zx48k/runtime/read_restore.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/iload32.asm" ; __FASTCALL__ routine which ; loads a 32 bits integer into DE,HL ; stored at position pointed by POINTER HL @@ -595,8 +623,8 @@ __ILOAD32: ex de, hl ret pop namespace -#line 25 "/zxbasic/src/arch/zx48k/library-asm/read_restore.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/iloadf.asm" +#line 25 "/zxbasic/src/lib/arch/zx48k/runtime/read_restore.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/iloadf.asm" ; __FASTCALL__ routine which ; loads a 40 bits floating point into A ED CB ; stored at position pointed by POINTER HL @@ -623,10 +651,10 @@ __LOADF: ; Loads a 40 bits FP number from address pointed by HL ld b, (hl) ret pop namespace -#line 26 "/zxbasic/src/arch/zx48k/library-asm/read_restore.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/ftof16reg.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/ftou32reg.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/neg32.asm" +#line 26 "/zxbasic/src/lib/arch/zx48k/runtime/read_restore.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/ftof16reg.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/ftou32reg.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/neg32.asm" push namespace core __ABS32: bit 7, d @@ -651,7 +679,7 @@ __NEG32: ; Negates DEHL (Two's complement) inc de ret pop namespace -#line 2 "/zxbasic/src/arch/zx48k/library-asm/ftou32reg.asm" +#line 2 "/zxbasic/src/lib/arch/zx48k/runtime/ftou32reg.asm" push namespace core __FTOU32REG: ; Converts a Float to (un)signed 32 bit integer (NOTE: It's ALWAYS 32 bit signed) ; Input FP number in A EDCB (A exponent, EDCB mantissa) @@ -723,7 +751,7 @@ __FTOU8: ; Converts float in C ED LH to Unsigned byte in A ld a, l ret pop namespace -#line 2 "/zxbasic/src/arch/zx48k/library-asm/ftof16reg.asm" +#line 2 "/zxbasic/src/lib/arch/zx48k/runtime/ftof16reg.asm" push namespace core __FTOF16REG: ; Converts a Float to 16.16 (32 bit) fixed point decimal ; Input FP number in A EDCB (A exponent, EDCB mantissa) @@ -754,9 +782,9 @@ __FTOF16REG: ; Converts a Float to 16.16 (32 bit) fixed point decimal ld b, a ; Loop counter = exponent - 128 + 16 (we need to shift 16 bit more) jp __FTOU32REG_LOOP ; proceed as an u32 integer pop namespace -#line 27 "/zxbasic/src/arch/zx48k/library-asm/read_restore.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/f16tofreg.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/u32tofreg.asm" +#line 27 "/zxbasic/src/lib/arch/zx48k/runtime/read_restore.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/f16tofreg.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/u32tofreg.asm" push namespace core __I8TOFREG: ld l, a @@ -826,7 +854,7 @@ __U32TOFREG_END: ret ENDP pop namespace -#line 3 "/zxbasic/src/arch/zx48k/library-asm/f16tofreg.asm" +#line 3 "/zxbasic/src/lib/arch/zx48k/runtime/f16tofreg.asm" push namespace core __F16TOFREG: ; Converts a 16.16 signed fixed point (stored in DEHL) ; to a Floating Point Number returned in (C ED CB) @@ -861,8 +889,8 @@ __F16TOFREG2: ; Converts an unsigned 32 bit integer (DEHL) jp __U32TOFREG_LOOP ; Proceed as an integer ENDP pop namespace -#line 28 "/zxbasic/src/arch/zx48k/library-asm/read_restore.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/free.asm" +#line 28 "/zxbasic/src/lib/arch/zx48k/runtime/read_restore.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/free.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -1020,16 +1048,16 @@ __MEM_BLOCK_JOIN: ; Joins current block (pointed by HL) with next one (pointed ret ENDP pop namespace -#line 29 "/zxbasic/src/arch/zx48k/library-asm/read_restore.asm" -#line 31 "/zxbasic/src/arch/zx48k/library-asm/read_restore.asm" -#line 32 "/zxbasic/src/arch/zx48k/library-asm/read_restore.asm" -#line 33 "/zxbasic/src/arch/zx48k/library-asm/read_restore.asm" -#line 34 "/zxbasic/src/arch/zx48k/library-asm/read_restore.asm" -#line 35 "/zxbasic/src/arch/zx48k/library-asm/read_restore.asm" -#line 36 "/zxbasic/src/arch/zx48k/library-asm/read_restore.asm" -#line 37 "/zxbasic/src/arch/zx48k/library-asm/read_restore.asm" -#line 38 "/zxbasic/src/arch/zx48k/library-asm/read_restore.asm" -#line 39 "/zxbasic/src/arch/zx48k/library-asm/read_restore.asm" +#line 29 "/zxbasic/src/lib/arch/zx48k/runtime/read_restore.asm" +#line 31 "/zxbasic/src/lib/arch/zx48k/runtime/read_restore.asm" +#line 32 "/zxbasic/src/lib/arch/zx48k/runtime/read_restore.asm" +#line 33 "/zxbasic/src/lib/arch/zx48k/runtime/read_restore.asm" +#line 34 "/zxbasic/src/lib/arch/zx48k/runtime/read_restore.asm" +#line 35 "/zxbasic/src/lib/arch/zx48k/runtime/read_restore.asm" +#line 36 "/zxbasic/src/lib/arch/zx48k/runtime/read_restore.asm" +#line 37 "/zxbasic/src/lib/arch/zx48k/runtime/read_restore.asm" +#line 38 "/zxbasic/src/lib/arch/zx48k/runtime/read_restore.asm" +#line 39 "/zxbasic/src/lib/arch/zx48k/runtime/read_restore.asm" ;; Updates restore point to the given HL mem. address push namespace core __RESTORE: @@ -1309,5 +1337,5 @@ __DATA_ADDR: ;; Stores current DATA ptr dw .DATA.__DATA__0 ENDP pop namespace -#line 48 "arrbase1.bas" +#line 47 "arch/zx48k/arrbase1.bas" END diff --git a/tests/functional/arch/zx48k/arrcheck.asm b/tests/functional/arch/zx48k/arrcheck.asm index b90022350..0a9c3c280 100644 --- a/tests/functional/arch/zx48k/arrcheck.asm +++ b/tests/functional/arch/zx48k/arrcheck.asm @@ -27,6 +27,8 @@ _a: DEFW .LABEL.__LABEL0 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW 0 + DEFW _a.__UBOUND__ _a.__DATA__: DEFB 00h DEFB 00h @@ -98,29 +100,24 @@ _a.__DATA__: DEFW 0001h DEFW 0006h DEFB 01h +_a.__UBOUND__: + DEFW 000Ah + DEFW 0005h .core.ZXBASIC_USER_DATA_END: .core.__MAIN_PROGRAM__: ld hl, (_b) push hl - ld hl, 5 - push hl ld hl, (_b) push hl - ld hl, 10 - push hl ld hl, _a call .core.__ARRAY ld (hl), 7 ld hl, (_b) push hl - ld hl, 5 - push hl ld hl, (_b) ld de, 6 add hl, de push hl - ld hl, 10 - push hl ld hl, _a call .core.__ARRAY ld a, (hl) @@ -141,7 +138,7 @@ _a.__DATA__: ei ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -157,7 +154,7 @@ _a.__DATA__: ; O = [a0 + b0 * (a1 + b1 * (a2 + ... bN-2(aN-1)))] ; What I will do here is to calculate the following sequence: ; ((aN-1 * bN-2) + aN-2) * bN-3 + ... -#line 1 "/zxbasic/src/arch/zx48k/library-asm/mul16.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/mul16.asm" push namespace core __MUL16: ; Mutiplies HL with the last value stored into de stack ; Works for both signed and unsigned @@ -183,8 +180,8 @@ __MUL16NOADD: ret ; Result in hl (16 lower bits) ENDP pop namespace -#line 20 "/zxbasic/src/arch/zx48k/library-asm/array.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/error.asm" +#line 20 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/error.asm" ; Simple error control routines ; vim:ts=4:et: push namespace core @@ -218,66 +215,104 @@ __STOP: ld (ERR_NR), a ret pop namespace -#line 23 "/zxbasic/src/arch/zx48k/library-asm/array.asm" -#line 24 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 23 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 24 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" push namespace core __ARRAY_PTR: ;; computes an array offset from a pointer ld c, (hl) inc hl ld h, (hl) - ld l, c + ld l, c ;; HL <-- [HL] __ARRAY: PROC LOCAL LOOP LOCAL ARRAY_END - LOCAL RET_ADDRESS ; Stores return address - LOCAL TMP_ARR_PTR ; Stores pointer temporarily + LOCAL TMP_ARR_PTR ; Ptr to Array DATA region. Stored temporarily + LOCAL LBOUND_PTR, UBOUND_PTR ; LBound and UBound PTR indexes + LOCAL RET_ADDR ; Contains the return address popped from the stack + LBOUND_PTR EQU 23698 ; Uses MEMBOT as a temporary variable + UBOUND_PTR EQU LBOUND_PTR + 2 ; Next 2 bytes for UBOUND PTR + RET_ADDR EQU UBOUND_PTR + 2 ; Next 2 bytes for RET_ADDR + TMP_ARR_PTR EQU RET_ADDR + 2 ; Next 2 bytes for TMP_ARR_PTR ld e, (hl) inc hl ld d, (hl) + inc hl ; DE <-- PTR to Dim sizes table + ld (TMP_ARR_PTR), hl ; HL = Array __DATA__.__PTR__ inc hl - ld (TMP_ARR_PTR), hl - ex de, hl - ex (sp), hl ; Return address in HL, array address in the stack - ld (RET_ADDRESS + 1), hl ; Stores it for later + inc hl + ld c, (hl) + inc hl + ld b, (hl) ; BC <-- Array __LBOUND__ PTR + ld (LBOUND_PTR), bc ; Store it for later + inc hl + ld c, (hl) + inc hl + ld b, (hl) ; BC <-- Array __UBOUND__ PTR + ld (UBOUND_PTR), bc + ex de, hl ; HL <-- PTR to Dim sizes table, DE <-- dummy + ex (sp), hl ; Return address in HL, PTR Dim sizes table onto Stack + ld (RET_ADDR), hl ; Stores it for later exx - pop hl ; Will use H'L' as the pointer + pop hl ; Will use H'L' as the pointer to Dim sizes table ld c, (hl) ; Loads Number of dimensions from (hl) inc hl ld b, (hl) inc hl ; Ready exx - ld hl, 0 ; HL = Offset "accumulator" + ld hl, 0 ; HL = Element Offset "accumulator" LOOP: - pop de -#line 64 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - pop bc ; Get next index (Ai) from the stack - ex de, hl - or a - sbc hl, bc + ex de, hl ; DE = Element Offset + ld hl, (LBOUND_PTR) + ld a, h + or l + ld b, h + ld c, l + jr z, 1f + ld c, (hl) + inc hl + ld b, (hl) + inc hl + ld (LBOUND_PTR), hl +1: + pop hl ; Get next index (Ai) from the stack + sbc hl, bc ; Subtract LBOUND ld a, ERROR_SubscriptWrong jp c, __ERROR - ex de, hl -#line 74 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - add hl, bc ; Adds current index + push hl ; Saves (Ai) - Lbound(i) + add hl, bc ; Recover original (Ai) value + push hl + ld hl, (UBOUND_PTR) + ld c, (hl) + inc hl + ld b, (hl) + inc hl + ld (UBOUND_PTR), hl + pop hl ; original (Ai) value + scf + sbc hl, bc ; HL <- HL - BC - 1 = Ai - UBound(i) - 1 => No Carry if Ai > UBound(i) + jp nc, __ERROR + pop hl ; Recovers (Ai) - Lbound(Ai) +#line 113 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + add hl, de ; Adds current index exx ; Checks if B'C' = 0 ld a, b ; Which means we must exit (last element is not multiplied by anything) or c jr z, ARRAY_END ; if B'Ci == 0 we are done - ld e, (hl) ; Loads next dimension into D'E' + dec bc ; Decrements loop counter + ld e, (hl) ; Loads next dimension size into D'E' inc hl ld d, (hl) inc hl push de - dec bc ; Decrements loop counter exx pop de ; DE = Max bound Number (i-th dimension) - call __FNMUL + call __FNMUL ; HL <= HL * DE mod 65536 jp LOOP ARRAY_END: ld a, (hl) exx -#line 103 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 143 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl ld hl, 0 @@ -285,7 +320,7 @@ ARRAY_END: ARRAY_SIZE_LOOP: add hl, de djnz ARRAY_SIZE_LOOP -#line 113 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 153 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ex de, hl ld hl, (TMP_ARR_PTR) ld a, (hl) @@ -293,8 +328,9 @@ ARRAY_SIZE_LOOP: ld h, (hl) ld l, a add hl, de ; Adds element start -RET_ADDRESS: - jp 0 + ld de, (RET_ADDR) + push de + ret ;; Performs a faster multiply for little 16bit numbs LOCAL __FNMUL, __FNMUL2 __FNMUL: @@ -311,9 +347,7 @@ __FNMUL2: add hl, de djnz __FNMUL2 ret -TMP_ARR_PTR: - DW 0 ; temporary storage for pointer to tables ENDP pop namespace -#line 43 "arrcheck.bas" +#line 35 "arch/zx48k/arrcheck.bas" END diff --git a/tests/functional/arch/zx48k/arrconst.asm b/tests/functional/arch/zx48k/arrconst.asm index 4e9274c14..264b92f1f 100644 --- a/tests/functional/arch/zx48k/arrconst.asm +++ b/tests/functional/arch/zx48k/arrconst.asm @@ -24,6 +24,8 @@ _a: DEFW .LABEL.__LABEL0 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW 0 + DEFW 0 _a.__DATA__: DEFB 00h DEFB 00h diff --git a/tests/functional/arch/zx48k/arrlabels.asm b/tests/functional/arch/zx48k/arrlabels.asm index 0fc3dfea5..d0de6c70c 100644 --- a/tests/functional/arch/zx48k/arrlabels.asm +++ b/tests/functional/arch/zx48k/arrlabels.asm @@ -22,6 +22,8 @@ _a: DEFW .LABEL.__LABEL0 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW _a.__LBOUND__ + DEFW 0 _a.__DATA__: DEFW .LABEL._label1 DEFW .LABEL._label2 @@ -29,6 +31,8 @@ _a.__DATA__: .LABEL.__LABEL0: DEFW 0000h DEFB 02h +_a.__LBOUND__: + DEFW 0001h .core.ZXBASIC_USER_DATA_END: .core.__MAIN_PROGRAM__: .LABEL._label1: diff --git a/tests/functional/arch/zx48k/arrlabels1.asm b/tests/functional/arch/zx48k/arrlabels1.asm index c7346fa15..0f9daa154 100644 --- a/tests/functional/arch/zx48k/arrlabels1.asm +++ b/tests/functional/arch/zx48k/arrlabels1.asm @@ -22,6 +22,8 @@ _a: DEFW .LABEL.__LABEL0 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW _a.__LBOUND__ + DEFW 0 _a.__DATA__: DEFW _a.__DATA__ DEFW _a.__DATA__ @@ -29,6 +31,8 @@ _a.__DATA__: .LABEL.__LABEL0: DEFW 0000h DEFB 02h +_a.__LBOUND__: + DEFW 0001h .core.ZXBASIC_USER_DATA_END: .core.__MAIN_PROGRAM__: ld hl, 0 diff --git a/tests/functional/arch/zx48k/arrlabels10a.asm b/tests/functional/arch/zx48k/arrlabels10a.asm index 13adef172..104571c3a 100644 --- a/tests/functional/arch/zx48k/arrlabels10a.asm +++ b/tests/functional/arch/zx48k/arrlabels10a.asm @@ -22,6 +22,8 @@ _a: DEFW .LABEL.__LABEL0 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW _a.__LBOUND__ + DEFW 0 _a.__DATA__: DEFB (_a.__DATA__) & 0xFF DEFB ((_a.__DATA__) + (1)) & 0xFF @@ -29,6 +31,8 @@ _a.__DATA__: .LABEL.__LABEL0: DEFW 0000h DEFB 01h +_a.__LBOUND__: + DEFW 0001h .core.ZXBASIC_USER_DATA_END: .core.__MAIN_PROGRAM__: ld hl, 0 diff --git a/tests/functional/arch/zx48k/arrlabels10b.asm b/tests/functional/arch/zx48k/arrlabels10b.asm index 1bfb5a4ff..d7d3610dc 100644 --- a/tests/functional/arch/zx48k/arrlabels10b.asm +++ b/tests/functional/arch/zx48k/arrlabels10b.asm @@ -22,6 +22,8 @@ _a: DEFW .LABEL.__LABEL0 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW _a.__LBOUND__ + DEFW 0 _a.__DATA__: DEFW 0000h DEFW (_a.__DATA__) & 0xFFFF @@ -34,6 +36,8 @@ _a.__DATA__: .LABEL.__LABEL0: DEFW 0000h DEFB 04h +_a.__LBOUND__: + DEFW 0001h .core.ZXBASIC_USER_DATA_END: .core.__MAIN_PROGRAM__: ld hl, 0 diff --git a/tests/functional/arch/zx48k/arrlabels2.asm b/tests/functional/arch/zx48k/arrlabels2.asm index faed38f85..bf19d2863 100644 --- a/tests/functional/arch/zx48k/arrlabels2.asm +++ b/tests/functional/arch/zx48k/arrlabels2.asm @@ -22,6 +22,8 @@ _a: DEFW .LABEL.__LABEL0 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW _a.__LBOUND__ + DEFW 0 _a.__DATA__: DEFW _a.__DATA__ DEFW _a.__DATA__ @@ -29,6 +31,8 @@ _a.__DATA__: .LABEL.__LABEL0: DEFW 0000h DEFB 02h +_a.__LBOUND__: + DEFW 0001h .core.ZXBASIC_USER_DATA_END: .core.__MAIN_PROGRAM__: ld hl, (_a.__DATA__ + 0) diff --git a/tests/functional/arch/zx48k/arrlabels3.asm b/tests/functional/arch/zx48k/arrlabels3.asm index f9ec19922..935ff2e04 100644 --- a/tests/functional/arch/zx48k/arrlabels3.asm +++ b/tests/functional/arch/zx48k/arrlabels3.asm @@ -22,6 +22,8 @@ _a: DEFW .LABEL.__LABEL0 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW _a.__LBOUND__ + DEFW 0 _a.__DATA__: DEFW _a.__DATA__ DEFW _a.__DATA__ @@ -29,6 +31,8 @@ _a.__DATA__: .LABEL.__LABEL0: DEFW 0000h DEFB 02h +_a.__LBOUND__: + DEFW 0001h .core.ZXBASIC_USER_DATA_END: .core.__MAIN_PROGRAM__: ld hl, (_a.__DATA__ + 0) diff --git a/tests/functional/arch/zx48k/arrlabels6.asm b/tests/functional/arch/zx48k/arrlabels6.asm index f8431a5f0..49d898b0e 100644 --- a/tests/functional/arch/zx48k/arrlabels6.asm +++ b/tests/functional/arch/zx48k/arrlabels6.asm @@ -22,6 +22,8 @@ _a: DEFW .LABEL.__LABEL0 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW _a.__LBOUND__ + DEFW 0 _a.__DATA__: DEFW .LABEL._label1 DEFW .LABEL._label2 @@ -29,6 +31,8 @@ _a.__DATA__: .LABEL.__LABEL0: DEFW 0000h DEFB 02h +_a.__LBOUND__: + DEFW 0001h .core.ZXBASIC_USER_DATA_END: .core.__MAIN_PROGRAM__: ld hl, (_a.__DATA__ + 0) diff --git a/tests/functional/arch/zx48k/astore16.asm b/tests/functional/arch/zx48k/astore16.asm index 6202c1467..8a6646be9 100644 --- a/tests/functional/arch/zx48k/astore16.asm +++ b/tests/functional/arch/zx48k/astore16.asm @@ -25,6 +25,8 @@ _obj: DEFW .LABEL.__LABEL5 _obj.__DATA__.__PTR__: DEFW _obj.__DATA__ + DEFW 0 + DEFW 0 _obj.__DATA__: DEFB 00h DEFB 00h @@ -162,52 +164,77 @@ __ARRAY_PTR: ;; computes an array offset from a pointer ld c, (hl) inc hl ld h, (hl) - ld l, c + ld l, c ;; HL <-- [HL] __ARRAY: PROC LOCAL LOOP LOCAL ARRAY_END - LOCAL RET_ADDRESS ; Stores return address - LOCAL TMP_ARR_PTR ; Stores pointer temporarily + LOCAL TMP_ARR_PTR ; Ptr to Array DATA region. Stored temporarily + LOCAL LBOUND_PTR, UBOUND_PTR ; LBound and UBound PTR indexes + LOCAL RET_ADDR ; Contains the return address popped from the stack + LBOUND_PTR EQU 23698 ; Uses MEMBOT as a temporary variable + UBOUND_PTR EQU LBOUND_PTR + 2 ; Next 2 bytes for UBOUND PTR + RET_ADDR EQU UBOUND_PTR + 2 ; Next 2 bytes for RET_ADDR + TMP_ARR_PTR EQU RET_ADDR + 2 ; Next 2 bytes for TMP_ARR_PTR ld e, (hl) inc hl ld d, (hl) + inc hl ; DE <-- PTR to Dim sizes table + ld (TMP_ARR_PTR), hl ; HL = Array __DATA__.__PTR__ inc hl - ld (TMP_ARR_PTR), hl - ex de, hl - ex (sp), hl ; Return address in HL, array address in the stack - ld (RET_ADDRESS + 1), hl ; Stores it for later + inc hl + ld c, (hl) + inc hl + ld b, (hl) ; BC <-- Array __LBOUND__ PTR + ld (LBOUND_PTR), bc ; Store it for later +#line 66 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + ex de, hl ; HL <-- PTR to Dim sizes table, DE <-- dummy + ex (sp), hl ; Return address in HL, PTR Dim sizes table onto Stack + ld (RET_ADDR), hl ; Stores it for later exx - pop hl ; Will use H'L' as the pointer + pop hl ; Will use H'L' as the pointer to Dim sizes table ld c, (hl) ; Loads Number of dimensions from (hl) inc hl ld b, (hl) inc hl ; Ready exx - ld hl, 0 ; HL = Offset "accumulator" + ld hl, 0 ; HL = Element Offset "accumulator" LOOP: -#line 64 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" - pop bc ; Get next index (Ai) from the stack -#line 74 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" - add hl, bc ; Adds current index + ex de, hl ; DE = Element Offset + ld hl, (LBOUND_PTR) + ld a, h + or l + ld b, h + ld c, l + jr z, 1f + ld c, (hl) + inc hl + ld b, (hl) + inc hl + ld (LBOUND_PTR), hl +1: + pop hl ; Get next index (Ai) from the stack + sbc hl, bc ; Subtract LBOUND +#line 116 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + add hl, de ; Adds current index exx ; Checks if B'C' = 0 ld a, b ; Which means we must exit (last element is not multiplied by anything) or c jr z, ARRAY_END ; if B'Ci == 0 we are done - ld e, (hl) ; Loads next dimension into D'E' + dec bc ; Decrements loop counter + ld e, (hl) ; Loads next dimension size into D'E' inc hl ld d, (hl) inc hl push de - dec bc ; Decrements loop counter exx pop de ; DE = Max bound Number (i-th dimension) - call __FNMUL + call __FNMUL ; HL <= HL * DE mod 65536 jp LOOP ARRAY_END: ld a, (hl) exx -#line 103 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 146 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl ld hl, 0 @@ -215,7 +242,7 @@ ARRAY_END: ARRAY_SIZE_LOOP: add hl, de djnz ARRAY_SIZE_LOOP -#line 113 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 156 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ex de, hl ld hl, (TMP_ARR_PTR) ld a, (hl) @@ -223,8 +250,9 @@ ARRAY_SIZE_LOOP: ld h, (hl) ld l, a add hl, de ; Adds element start -RET_ADDRESS: - jp 0 + ld de, (RET_ADDR) + push de + ret ;; Performs a faster multiply for little 16bit numbs LOCAL __FNMUL, __FNMUL2 __FNMUL: @@ -241,8 +269,6 @@ __FNMUL2: add hl, de djnz __FNMUL2 ret -TMP_ARR_PTR: - DW 0 ; temporary storage for pointer to tables ENDP pop namespace #line 52 "arch/zx48k/astore16.bas" diff --git a/tests/functional/arch/zx48k/astore32.asm b/tests/functional/arch/zx48k/astore32.asm index 79bdd021f..801c10587 100644 --- a/tests/functional/arch/zx48k/astore32.asm +++ b/tests/functional/arch/zx48k/astore32.asm @@ -27,6 +27,8 @@ _r: DEFW .LABEL.__LABEL0 _r.__DATA__.__PTR__: DEFW _r.__DATA__ + DEFW 0 + DEFW 0 _r.__DATA__: DEFB 40h DEFB 9Ch @@ -131,7 +133,7 @@ _main__leave: exx ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -147,7 +149,7 @@ _main__leave: ; O = [a0 + b0 * (a1 + b1 * (a2 + ... bN-2(aN-1)))] ; What I will do here is to calculate the following sequence: ; ((aN-1 * bN-2) + aN-2) * bN-3 + ... -#line 1 "/zxbasic/src/arch/zx48k/library-asm/mul16.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/mul16.asm" push namespace core __MUL16: ; Mutiplies HL with the last value stored into de stack ; Works for both signed and unsigned @@ -173,59 +175,84 @@ __MUL16NOADD: ret ; Result in hl (16 lower bits) ENDP pop namespace -#line 20 "/zxbasic/src/arch/zx48k/library-asm/array.asm" -#line 24 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 20 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 24 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" push namespace core __ARRAY_PTR: ;; computes an array offset from a pointer ld c, (hl) inc hl ld h, (hl) - ld l, c + ld l, c ;; HL <-- [HL] __ARRAY: PROC LOCAL LOOP LOCAL ARRAY_END - LOCAL RET_ADDRESS ; Stores return address - LOCAL TMP_ARR_PTR ; Stores pointer temporarily + LOCAL TMP_ARR_PTR ; Ptr to Array DATA region. Stored temporarily + LOCAL LBOUND_PTR, UBOUND_PTR ; LBound and UBound PTR indexes + LOCAL RET_ADDR ; Contains the return address popped from the stack + LBOUND_PTR EQU 23698 ; Uses MEMBOT as a temporary variable + UBOUND_PTR EQU LBOUND_PTR + 2 ; Next 2 bytes for UBOUND PTR + RET_ADDR EQU UBOUND_PTR + 2 ; Next 2 bytes for RET_ADDR + TMP_ARR_PTR EQU RET_ADDR + 2 ; Next 2 bytes for TMP_ARR_PTR ld e, (hl) inc hl ld d, (hl) + inc hl ; DE <-- PTR to Dim sizes table + ld (TMP_ARR_PTR), hl ; HL = Array __DATA__.__PTR__ inc hl - ld (TMP_ARR_PTR), hl - ex de, hl - ex (sp), hl ; Return address in HL, array address in the stack - ld (RET_ADDRESS + 1), hl ; Stores it for later + inc hl + ld c, (hl) + inc hl + ld b, (hl) ; BC <-- Array __LBOUND__ PTR + ld (LBOUND_PTR), bc ; Store it for later +#line 66 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + ex de, hl ; HL <-- PTR to Dim sizes table, DE <-- dummy + ex (sp), hl ; Return address in HL, PTR Dim sizes table onto Stack + ld (RET_ADDR), hl ; Stores it for later exx - pop hl ; Will use H'L' as the pointer + pop hl ; Will use H'L' as the pointer to Dim sizes table ld c, (hl) ; Loads Number of dimensions from (hl) inc hl ld b, (hl) inc hl ; Ready exx - ld hl, 0 ; HL = Offset "accumulator" + ld hl, 0 ; HL = Element Offset "accumulator" LOOP: -#line 64 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - pop bc ; Get next index (Ai) from the stack -#line 74 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - add hl, bc ; Adds current index + ex de, hl ; DE = Element Offset + ld hl, (LBOUND_PTR) + ld a, h + or l + ld b, h + ld c, l + jr z, 1f + ld c, (hl) + inc hl + ld b, (hl) + inc hl + ld (LBOUND_PTR), hl +1: + pop hl ; Get next index (Ai) from the stack + sbc hl, bc ; Subtract LBOUND +#line 116 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + add hl, de ; Adds current index exx ; Checks if B'C' = 0 ld a, b ; Which means we must exit (last element is not multiplied by anything) or c jr z, ARRAY_END ; if B'Ci == 0 we are done - ld e, (hl) ; Loads next dimension into D'E' + dec bc ; Decrements loop counter + ld e, (hl) ; Loads next dimension size into D'E' inc hl ld d, (hl) inc hl push de - dec bc ; Decrements loop counter exx pop de ; DE = Max bound Number (i-th dimension) - call __FNMUL + call __FNMUL ; HL <= HL * DE mod 65536 jp LOOP ARRAY_END: ld a, (hl) exx -#line 103 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 146 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl ld hl, 0 @@ -233,7 +260,7 @@ ARRAY_END: ARRAY_SIZE_LOOP: add hl, de djnz ARRAY_SIZE_LOOP -#line 113 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 156 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ex de, hl ld hl, (TMP_ARR_PTR) ld a, (hl) @@ -241,8 +268,9 @@ ARRAY_SIZE_LOOP: ld h, (hl) ld l, a add hl, de ; Adds element start -RET_ADDRESS: - jp 0 + ld de, (RET_ADDR) + push de + ret ;; Performs a faster multiply for little 16bit numbs LOCAL __FNMUL, __FNMUL2 __FNMUL: @@ -259,12 +287,10 @@ __FNMUL2: add hl, de djnz __FNMUL2 ret -TMP_ARR_PTR: - DW 0 ; temporary storage for pointer to tables ENDP pop namespace -#line 72 "zx48k/astore32.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/store32.asm" +#line 72 "arch/zx48k/astore32.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/store32.asm" push namespace core __PISTORE32: push hl @@ -287,5 +313,5 @@ __STORE32: ; Stores the given integer in DEBC at address HL ld (hl), d ret pop namespace -#line 73 "zx48k/astore32.bas" +#line 73 "arch/zx48k/astore32.bas" END diff --git a/tests/functional/arch/zx48k/ataddr.asm b/tests/functional/arch/zx48k/ataddr.asm index b7e2edbfd..70ca8f415 100644 --- a/tests/functional/arch/zx48k/ataddr.asm +++ b/tests/functional/arch/zx48k/ataddr.asm @@ -24,6 +24,8 @@ _a: DEFW .LABEL.__LABEL0 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW 0 + DEFW 0 _a.__DATA__: DEFB 00h DEFB 00h diff --git a/tests/functional/arch/zx48k/bad_fname_err3.asm b/tests/functional/arch/zx48k/bad_fname_err3.asm index 124dd5958..bfda71b38 100644 --- a/tests/functional/arch/zx48k/bad_fname_err3.asm +++ b/tests/functional/arch/zx48k/bad_fname_err3.asm @@ -22,6 +22,8 @@ _dirData: DEFW .LABEL.__LABEL0 _dirData.__DATA__.__PTR__: DEFW _dirData.__DATA__ + DEFW 0 + DEFW 0 _dirData.__DATA__: DEFB 00h DEFB 00h diff --git a/tests/functional/arch/zx48k/bound00.asm b/tests/functional/arch/zx48k/bound00.asm index 557290f20..b8b4e9155 100644 --- a/tests/functional/arch/zx48k/bound00.asm +++ b/tests/functional/arch/zx48k/bound00.asm @@ -26,6 +26,8 @@ _a: DEFW .LABEL.__LABEL0 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW _a.__LBOUND__ + DEFW 0 _a.__DATA__: DEFB 00h DEFB 00h @@ -44,6 +46,8 @@ _a.__DATA__: .LABEL.__LABEL0: DEFW 0000h DEFB 02h +_a.__LBOUND__: + DEFW 0002h .core.ZXBASIC_USER_DATA_END: .core.__MAIN_PROGRAM__: ld hl, 1 diff --git a/tests/functional/arch/zx48k/bound01.asm b/tests/functional/arch/zx48k/bound01.asm index 1603f89b7..14ccbeabc 100644 --- a/tests/functional/arch/zx48k/bound01.asm +++ b/tests/functional/arch/zx48k/bound01.asm @@ -26,6 +26,8 @@ _a: DEFW .LABEL.__LABEL0 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW _a.__LBOUND__ + DEFW 0 _a.__DATA__: DEFB 00h DEFB 00h @@ -87,6 +89,9 @@ _a.__DATA__: DEFW 0001h DEFW 0004h DEFB 02h +_a.__LBOUND__: + DEFW 0002h + DEFW 0003h .core.ZXBASIC_USER_DATA_END: .core.__MAIN_PROGRAM__: ld hl, 8 diff --git a/tests/functional/arch/zx48k/bound03.asm b/tests/functional/arch/zx48k/bound03.asm index f1a1c6149..1ba498eec 100644 --- a/tests/functional/arch/zx48k/bound03.asm +++ b/tests/functional/arch/zx48k/bound03.asm @@ -26,7 +26,7 @@ _a: DEFW .LABEL.__LABEL0 _a.__DATA__.__PTR__: DEFW _a.__DATA__ - DEFW 0 + DEFW _a.__LBOUND__ DEFW _a.__UBOUND__ _a.__DATA__: DEFB 00h @@ -89,6 +89,9 @@ _a.__DATA__: DEFW 0001h DEFW 0004h DEFB 02h +_a.__LBOUND__: + DEFW 0002h + DEFW 0003h _a.__UBOUND__: DEFW 0008h DEFW 0006h @@ -133,7 +136,7 @@ _a.__UBOUND__: ei ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/bound.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/bound.asm" ; --------------------------------------------------------- ; Copyleft (k)2011 by Jose Rodriguez (a.k.a. Boriel) ; http://www.boriel.com @@ -207,5 +210,5 @@ __DIM_NOT_EXIST: ret ENDP pop namespace -#line 41 "bound03.bas" +#line 41 "arch/zx48k/bound03.bas" END diff --git a/tests/functional/arch/zx48k/bound04.asm b/tests/functional/arch/zx48k/bound04.asm index e17fcd747..104e8a71d 100644 --- a/tests/functional/arch/zx48k/bound04.asm +++ b/tests/functional/arch/zx48k/bound04.asm @@ -24,6 +24,8 @@ _a: DEFW .LABEL.__LABEL0 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW 0 + DEFW 0 _a.__DATA__: DEFB 00h DEFB 00h diff --git a/tests/functional/arch/zx48k/const3.asm b/tests/functional/arch/zx48k/const3.asm index d0a18780a..fb0b17d57 100644 --- a/tests/functional/arch/zx48k/const3.asm +++ b/tests/functional/arch/zx48k/const3.asm @@ -22,6 +22,8 @@ _dgConnected: DEFW .LABEL.__LABEL0 _dgConnected.__DATA__.__PTR__: DEFW _dgConnected.__DATA__ + DEFW 0 + DEFW 0 _dgConnected.__DATA__: DEFB 00h DEFB 00h diff --git a/tests/functional/arch/zx48k/dim_arr_at_label0.asm b/tests/functional/arch/zx48k/dim_arr_at_label0.asm index 18447f3aa..418c8e1bd 100644 --- a/tests/functional/arch/zx48k/dim_arr_at_label0.asm +++ b/tests/functional/arch/zx48k/dim_arr_at_label0.asm @@ -23,6 +23,8 @@ _a: DEFW .LABEL.__LABEL0 _a.__DATA__.__PTR__: DEFW .LABEL._c + DEFW 0 + DEFW 0 .LABEL.__LABEL0: DEFW 0000h DEFB 01h diff --git a/tests/functional/arch/zx48k/dim_arr_at_label1.asm b/tests/functional/arch/zx48k/dim_arr_at_label1.asm index 988638c83..12fdae5e3 100644 --- a/tests/functional/arch/zx48k/dim_arr_at_label1.asm +++ b/tests/functional/arch/zx48k/dim_arr_at_label1.asm @@ -23,6 +23,8 @@ _a: DEFW .LABEL.__LABEL0 _a.__DATA__.__PTR__: DEFW (.LABEL._c) + (1) + DEFW 0 + DEFW 0 .LABEL.__LABEL0: DEFW 0000h DEFB 01h diff --git a/tests/functional/arch/zx48k/dim_arr_at_label2.asm b/tests/functional/arch/zx48k/dim_arr_at_label2.asm index 6b866d66c..963ddc5ea 100644 --- a/tests/functional/arch/zx48k/dim_arr_at_label2.asm +++ b/tests/functional/arch/zx48k/dim_arr_at_label2.asm @@ -23,6 +23,8 @@ _tile: DEFW .LABEL.__LABEL0 _tile.__DATA__.__PTR__: DEFW 16768 + DEFW 0 + DEFW 0 .LABEL.__LABEL0: DEFW 0000h DEFB 02h diff --git a/tests/functional/arch/zx48k/dim_const0.asm b/tests/functional/arch/zx48k/dim_const0.asm index 99f216b3a..c906806bc 100644 --- a/tests/functional/arch/zx48k/dim_const0.asm +++ b/tests/functional/arch/zx48k/dim_const0.asm @@ -22,6 +22,8 @@ _c: DEFW .LABEL.__LABEL0 _c.__DATA__.__PTR__: DEFW _c.__DATA__ + DEFW 0 + DEFW 0 _c.__DATA__: DEFB 7 DEFB 7 diff --git a/tests/functional/arch/zx48k/dim_const_const.asm b/tests/functional/arch/zx48k/dim_const_const.asm index 3f5f76628..e45427126 100644 --- a/tests/functional/arch/zx48k/dim_const_const.asm +++ b/tests/functional/arch/zx48k/dim_const_const.asm @@ -22,6 +22,8 @@ _mobCoords: DEFW .LABEL.__LABEL0 _mobCoords.__DATA__.__PTR__: DEFW _mobCoords.__DATA__ + DEFW 0 + DEFW 0 _mobCoords.__DATA__: DEFB 00h DEFB 00h diff --git a/tests/functional/arch/zx48k/dimconst7.asm b/tests/functional/arch/zx48k/dimconst7.asm index ea8bb683b..ec52bafe0 100644 --- a/tests/functional/arch/zx48k/dimconst7.asm +++ b/tests/functional/arch/zx48k/dimconst7.asm @@ -24,6 +24,8 @@ _c: DEFW .LABEL.__LABEL0 _c.__DATA__.__PTR__: DEFW _c.__DATA__ + DEFW 0 + DEFW 0 _c.__DATA__: DEFB 00h DEFB 00h diff --git a/tests/functional/arch/zx48k/einar01.asm b/tests/functional/arch/zx48k/einar01.asm index 32ce8cd9b..08412a27b 100644 --- a/tests/functional/arch/zx48k/einar01.asm +++ b/tests/functional/arch/zx48k/einar01.asm @@ -22,12 +22,16 @@ _score: DEFW .LABEL.__LABEL0 _score.__DATA__.__PTR__: DEFW _score.__DATA__ + DEFW _score.__LBOUND__ + DEFW 0 _score.__DATA__: DEFB 01h DEFB 02h .LABEL.__LABEL0: DEFW 0000h DEFB 01h +_score.__LBOUND__: + DEFW 0001h .core.ZXBASIC_USER_DATA_END: .core.__MAIN_PROGRAM__: ld a, (_score.__DATA__ + 1) diff --git a/tests/functional/arch/zx48k/lbound0.asm b/tests/functional/arch/zx48k/lbound0.asm index 22c4aa61b..854423613 100644 --- a/tests/functional/arch/zx48k/lbound0.asm +++ b/tests/functional/arch/zx48k/lbound0.asm @@ -24,6 +24,8 @@ _a: DEFW .LABEL.__LABEL0 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW _a.__LBOUND__ + DEFW 0 _a.__DATA__: DEFB 00h DEFB 00h @@ -38,6 +40,9 @@ _a.__DATA__: DEFW 0001h DEFW 0003h DEFB 01h +_a.__LBOUND__: + DEFW 0003h + DEFW 0007h .core.ZXBASIC_USER_DATA_END: .core.__MAIN_PROGRAM__: ld hl, 2 diff --git a/tests/functional/arch/zx48k/lbound1.asm b/tests/functional/arch/zx48k/lbound1.asm index 22c4aa61b..854423613 100644 --- a/tests/functional/arch/zx48k/lbound1.asm +++ b/tests/functional/arch/zx48k/lbound1.asm @@ -24,6 +24,8 @@ _a: DEFW .LABEL.__LABEL0 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW _a.__LBOUND__ + DEFW 0 _a.__DATA__: DEFB 00h DEFB 00h @@ -38,6 +40,9 @@ _a.__DATA__: DEFW 0001h DEFW 0003h DEFB 01h +_a.__LBOUND__: + DEFW 0003h + DEFW 0007h .core.ZXBASIC_USER_DATA_END: .core.__MAIN_PROGRAM__: ld hl, 2 diff --git a/tests/functional/arch/zx48k/lbound13.asm b/tests/functional/arch/zx48k/lbound13.asm index af1458d03..c4dea149e 100644 --- a/tests/functional/arch/zx48k/lbound13.asm +++ b/tests/functional/arch/zx48k/lbound13.asm @@ -130,7 +130,7 @@ _maxValue__leave: exx ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -146,7 +146,7 @@ _maxValue__leave: ; O = [a0 + b0 * (a1 + b1 * (a2 + ... bN-2(aN-1)))] ; What I will do here is to calculate the following sequence: ; ((aN-1 * bN-2) + aN-2) * bN-3 + ... -#line 1 "/zxbasic/src/arch/zx48k/library-asm/mul16.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/mul16.asm" push namespace core __MUL16: ; Mutiplies HL with the last value stored into de stack ; Works for both signed and unsigned @@ -172,59 +172,84 @@ __MUL16NOADD: ret ; Result in hl (16 lower bits) ENDP pop namespace -#line 20 "/zxbasic/src/arch/zx48k/library-asm/array.asm" -#line 24 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 20 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 24 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" push namespace core __ARRAY_PTR: ;; computes an array offset from a pointer ld c, (hl) inc hl ld h, (hl) - ld l, c + ld l, c ;; HL <-- [HL] __ARRAY: PROC LOCAL LOOP LOCAL ARRAY_END - LOCAL RET_ADDRESS ; Stores return address - LOCAL TMP_ARR_PTR ; Stores pointer temporarily + LOCAL TMP_ARR_PTR ; Ptr to Array DATA region. Stored temporarily + LOCAL LBOUND_PTR, UBOUND_PTR ; LBound and UBound PTR indexes + LOCAL RET_ADDR ; Contains the return address popped from the stack + LBOUND_PTR EQU 23698 ; Uses MEMBOT as a temporary variable + UBOUND_PTR EQU LBOUND_PTR + 2 ; Next 2 bytes for UBOUND PTR + RET_ADDR EQU UBOUND_PTR + 2 ; Next 2 bytes for RET_ADDR + TMP_ARR_PTR EQU RET_ADDR + 2 ; Next 2 bytes for TMP_ARR_PTR ld e, (hl) inc hl ld d, (hl) + inc hl ; DE <-- PTR to Dim sizes table + ld (TMP_ARR_PTR), hl ; HL = Array __DATA__.__PTR__ inc hl - ld (TMP_ARR_PTR), hl - ex de, hl - ex (sp), hl ; Return address in HL, array address in the stack - ld (RET_ADDRESS + 1), hl ; Stores it for later + inc hl + ld c, (hl) + inc hl + ld b, (hl) ; BC <-- Array __LBOUND__ PTR + ld (LBOUND_PTR), bc ; Store it for later +#line 66 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + ex de, hl ; HL <-- PTR to Dim sizes table, DE <-- dummy + ex (sp), hl ; Return address in HL, PTR Dim sizes table onto Stack + ld (RET_ADDR), hl ; Stores it for later exx - pop hl ; Will use H'L' as the pointer + pop hl ; Will use H'L' as the pointer to Dim sizes table ld c, (hl) ; Loads Number of dimensions from (hl) inc hl ld b, (hl) inc hl ; Ready exx - ld hl, 0 ; HL = Offset "accumulator" + ld hl, 0 ; HL = Element Offset "accumulator" LOOP: -#line 64 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - pop bc ; Get next index (Ai) from the stack -#line 74 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - add hl, bc ; Adds current index + ex de, hl ; DE = Element Offset + ld hl, (LBOUND_PTR) + ld a, h + or l + ld b, h + ld c, l + jr z, 1f + ld c, (hl) + inc hl + ld b, (hl) + inc hl + ld (LBOUND_PTR), hl +1: + pop hl ; Get next index (Ai) from the stack + sbc hl, bc ; Subtract LBOUND +#line 116 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + add hl, de ; Adds current index exx ; Checks if B'C' = 0 ld a, b ; Which means we must exit (last element is not multiplied by anything) or c jr z, ARRAY_END ; if B'Ci == 0 we are done - ld e, (hl) ; Loads next dimension into D'E' + dec bc ; Decrements loop counter + ld e, (hl) ; Loads next dimension size into D'E' inc hl ld d, (hl) inc hl push de - dec bc ; Decrements loop counter exx pop de ; DE = Max bound Number (i-th dimension) - call __FNMUL + call __FNMUL ; HL <= HL * DE mod 65536 jp LOOP ARRAY_END: ld a, (hl) exx -#line 103 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 146 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl ld hl, 0 @@ -232,7 +257,7 @@ ARRAY_END: ARRAY_SIZE_LOOP: add hl, de djnz ARRAY_SIZE_LOOP -#line 113 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 156 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ex de, hl ld hl, (TMP_ARR_PTR) ld a, (hl) @@ -240,8 +265,9 @@ ARRAY_SIZE_LOOP: ld h, (hl) ld l, a add hl, de ; Adds element start -RET_ADDRESS: - jp 0 + ld de, (RET_ADDR) + push de + ret ;; Performs a faster multiply for little 16bit numbs LOCAL __FNMUL, __FNMUL2 __FNMUL: @@ -258,12 +284,10 @@ __FNMUL2: add hl, de djnz __FNMUL2 ret -TMP_ARR_PTR: - DW 0 ; temporary storage for pointer to tables ENDP pop namespace -#line 91 "lbound13.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/bound.asm" +#line 91 "arch/zx48k/lbound13.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 @@ -337,5 +361,5 @@ __DIM_NOT_EXIST: ret ENDP pop namespace -#line 92 "lbound13.bas" +#line 92 "arch/zx48k/lbound13.bas" END diff --git a/tests/functional/arch/zx48k/lbound3.asm b/tests/functional/arch/zx48k/lbound3.asm index c93b83b0f..54641ca53 100644 --- a/tests/functional/arch/zx48k/lbound3.asm +++ b/tests/functional/arch/zx48k/lbound3.asm @@ -24,6 +24,8 @@ _a: DEFW .LABEL.__LABEL0 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW _a.__LBOUND__ + DEFW 0 _a.__DATA__: DEFB 00h DEFB 00h @@ -38,6 +40,9 @@ _a.__DATA__: DEFW 0001h DEFW 0003h DEFB 01h +_a.__LBOUND__: + DEFW 0003h + DEFW 0007h .core.ZXBASIC_USER_DATA_END: .core.__MAIN_PROGRAM__: ld hl, 3 diff --git a/tests/functional/arch/zx48k/lcd5.asm b/tests/functional/arch/zx48k/lcd5.asm index 333be9967..13daa2019 100644 --- a/tests/functional/arch/zx48k/lcd5.asm +++ b/tests/functional/arch/zx48k/lcd5.asm @@ -22,6 +22,8 @@ _tile: DEFW .LABEL.__LABEL0 _tile.__DATA__.__PTR__: DEFW _tile.__DATA__ + DEFW 0 + DEFW 0 _tile.__DATA__: DEFB 00h DEFB 00h diff --git a/tests/functional/arch/zx48k/lcd6.asm b/tests/functional/arch/zx48k/lcd6.asm index 7b8ab8a59..21281ff2f 100644 --- a/tests/functional/arch/zx48k/lcd6.asm +++ b/tests/functional/arch/zx48k/lcd6.asm @@ -27,6 +27,8 @@ _tile: DEFW .LABEL.__LABEL1 _tile.__DATA__.__PTR__: DEFW _tile.__DATA__ + DEFW 0 + DEFW 0 _tile.__DATA__: DEFB 00h DEFB 00h @@ -112,8 +114,8 @@ _SubLifetime__leave: exx ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/arrayalloc.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/calloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/arrayalloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/calloc.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -124,7 +126,7 @@ _SubLifetime__leave: ; closed source programs). ; ; Please read the MIT license on the internet -#line 1 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -184,7 +186,7 @@ _SubLifetime__leave: ; HL = BLOCK Start & DE = Length. ; An init directive is useful for initialization routines. ; They will be added automatically if needed. -#line 1 "/zxbasic/src/arch/zx48k/library-asm/error.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/error.asm" ; Simple error control routines ; vim:ts=4:et: push namespace core @@ -218,8 +220,8 @@ __STOP: ld (ERR_NR), a ret pop namespace -#line 69 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/heapinit.asm" +#line 69 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/heapinit.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -326,7 +328,7 @@ __MEM_INIT2: ret ENDP pop namespace -#line 70 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 70 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; --------------------------------------------------------------------- ; MEM_ALLOC ; Allocates a block of memory in the heap. @@ -357,9 +359,9 @@ __MEM_START: __MEM_LOOP: ; Loads lengh at (HL, HL+). If Lenght >= BC, jump to __MEM_DONE ld a, h ; HL = NULL (No memory available?) or l -#line 113 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 113 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ret z ; NULL -#line 115 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 115 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; HL = Pointer to Free block ld e, (hl) inc hl @@ -424,7 +426,7 @@ __MEM_SUBTRACT: ret ENDP pop namespace -#line 13 "/zxbasic/src/arch/zx48k/library-asm/calloc.asm" +#line 13 "/zxbasic/src/lib/arch/zx48k/runtime/calloc.asm" ; --------------------------------------------------------------------- ; MEM_CALLOC ; Allocates a block of memory in the heap, and clears it filling it @@ -458,7 +460,7 @@ __MEM_CALLOC: pop hl ret pop namespace -#line 3 "/zxbasic/src/arch/zx48k/library-asm/arrayalloc.asm" +#line 3 "/zxbasic/src/lib/arch/zx48k/runtime/arrayalloc.asm" ; --------------------------------------------------------------------- ; __ALLOC_LOCAL_ARRAY ; Allocates an array element area in the heap, and clears it filling it @@ -522,10 +524,10 @@ __ALLOC_INITIALIZED_LOCAL_ARRAY: ldir pop hl ; HL = addr of LBound area if used ret -#line 139 "/zxbasic/src/arch/zx48k/library-asm/arrayalloc.asm" +#line 139 "/zxbasic/src/lib/arch/zx48k/runtime/arrayalloc.asm" pop namespace -#line 45 "lcd6.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/free.asm" +#line 45 "arch/zx48k/lcd6.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/free.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -683,7 +685,7 @@ __MEM_BLOCK_JOIN: ; Joins current block (pointed by HL) with next one (pointed ret ENDP pop namespace -#line 46 "lcd6.bas" +#line 46 "arch/zx48k/lcd6.bas" .LABEL.__LABEL0: DEFB 00h DEFB 00h diff --git a/tests/functional/arch/zx48k/lcd_crash.asm b/tests/functional/arch/zx48k/lcd_crash.asm index eb5efd744..8cf193b54 100644 --- a/tests/functional/arch/zx48k/lcd_crash.asm +++ b/tests/functional/arch/zx48k/lcd_crash.asm @@ -24,6 +24,8 @@ _tiles: DEFW .LABEL.__LABEL0 _tiles.__DATA__.__PTR__: DEFW _tiles.__DATA__ + DEFW 0 + DEFW 0 _tiles.__DATA__: DEFB 00h DEFB 00h @@ -143,7 +145,7 @@ _settile__leave: exx ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/mul8.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/mul8.asm" push namespace core __MUL8: ; Performs 8bit x 8bit multiplication PROC @@ -189,5 +191,5 @@ __MUL8B: ret ; result = HL ENDP pop namespace -#line 81 "lcd_crash.bas" +#line 81 "arch/zx48k/lcd_crash.bas" END diff --git a/tests/functional/arch/zx48k/let_array_local_const0.asm b/tests/functional/arch/zx48k/let_array_local_const0.asm index ff43b8c0b..a91e3f52b 100644 --- a/tests/functional/arch/zx48k/let_array_local_const0.asm +++ b/tests/functional/arch/zx48k/let_array_local_const0.asm @@ -184,52 +184,77 @@ __ARRAY_PTR: ;; computes an array offset from a pointer ld c, (hl) inc hl ld h, (hl) - ld l, c + ld l, c ;; HL <-- [HL] __ARRAY: PROC LOCAL LOOP LOCAL ARRAY_END - LOCAL RET_ADDRESS ; Stores return address - LOCAL TMP_ARR_PTR ; Stores pointer temporarily + LOCAL TMP_ARR_PTR ; Ptr to Array DATA region. Stored temporarily + LOCAL LBOUND_PTR, UBOUND_PTR ; LBound and UBound PTR indexes + LOCAL RET_ADDR ; Contains the return address popped from the stack + LBOUND_PTR EQU 23698 ; Uses MEMBOT as a temporary variable + UBOUND_PTR EQU LBOUND_PTR + 2 ; Next 2 bytes for UBOUND PTR + RET_ADDR EQU UBOUND_PTR + 2 ; Next 2 bytes for RET_ADDR + TMP_ARR_PTR EQU RET_ADDR + 2 ; Next 2 bytes for TMP_ARR_PTR ld e, (hl) inc hl ld d, (hl) + inc hl ; DE <-- PTR to Dim sizes table + ld (TMP_ARR_PTR), hl ; HL = Array __DATA__.__PTR__ inc hl - ld (TMP_ARR_PTR), hl - ex de, hl - ex (sp), hl ; Return address in HL, array address in the stack - ld (RET_ADDRESS + 1), hl ; Stores it for later + inc hl + ld c, (hl) + inc hl + ld b, (hl) ; BC <-- Array __LBOUND__ PTR + ld (LBOUND_PTR), bc ; Store it for later +#line 66 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + ex de, hl ; HL <-- PTR to Dim sizes table, DE <-- dummy + ex (sp), hl ; Return address in HL, PTR Dim sizes table onto Stack + ld (RET_ADDR), hl ; Stores it for later exx - pop hl ; Will use H'L' as the pointer + pop hl ; Will use H'L' as the pointer to Dim sizes table ld c, (hl) ; Loads Number of dimensions from (hl) inc hl ld b, (hl) inc hl ; Ready exx - ld hl, 0 ; HL = Offset "accumulator" + ld hl, 0 ; HL = Element Offset "accumulator" LOOP: -#line 64 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" - pop bc ; Get next index (Ai) from the stack -#line 74 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" - add hl, bc ; Adds current index + ex de, hl ; DE = Element Offset + ld hl, (LBOUND_PTR) + ld a, h + or l + ld b, h + ld c, l + jr z, 1f + ld c, (hl) + inc hl + ld b, (hl) + inc hl + ld (LBOUND_PTR), hl +1: + pop hl ; Get next index (Ai) from the stack + sbc hl, bc ; Subtract LBOUND +#line 116 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + add hl, de ; Adds current index exx ; Checks if B'C' = 0 ld a, b ; Which means we must exit (last element is not multiplied by anything) or c jr z, ARRAY_END ; if B'Ci == 0 we are done - ld e, (hl) ; Loads next dimension into D'E' + dec bc ; Decrements loop counter + ld e, (hl) ; Loads next dimension size into D'E' inc hl ld d, (hl) inc hl push de - dec bc ; Decrements loop counter exx pop de ; DE = Max bound Number (i-th dimension) - call __FNMUL + call __FNMUL ; HL <= HL * DE mod 65536 jp LOOP ARRAY_END: ld a, (hl) exx -#line 103 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 146 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl ld hl, 0 @@ -237,7 +262,7 @@ ARRAY_END: ARRAY_SIZE_LOOP: add hl, de djnz ARRAY_SIZE_LOOP -#line 113 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 156 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ex de, hl ld hl, (TMP_ARR_PTR) ld a, (hl) @@ -245,8 +270,9 @@ ARRAY_SIZE_LOOP: ld h, (hl) ld l, a add hl, de ; Adds element start -RET_ADDRESS: - jp 0 + ld de, (RET_ADDR) + push de + ret ;; Performs a faster multiply for little 16bit numbs LOCAL __FNMUL, __FNMUL2 __FNMUL: @@ -263,8 +289,6 @@ __FNMUL2: add hl, de djnz __FNMUL2 ret -TMP_ARR_PTR: - DW 0 ; temporary storage for pointer to tables ENDP pop namespace #line 100 "arch/zx48k/let_array_local_const0.bas" diff --git a/tests/functional/arch/zx48k/let_array_substr.asm b/tests/functional/arch/zx48k/let_array_substr.asm index 364225551..59fcdf3b0 100644 --- a/tests/functional/arch/zx48k/let_array_substr.asm +++ b/tests/functional/arch/zx48k/let_array_substr.asm @@ -30,6 +30,8 @@ _a: DEFW .LABEL.__LABEL2 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW 0 + DEFW 0 _a.__DATA__: DEFB 00h DEFB 00h @@ -164,52 +166,77 @@ __ARRAY_PTR: ;; computes an array offset from a pointer ld c, (hl) inc hl ld h, (hl) - ld l, c + ld l, c ;; HL <-- [HL] __ARRAY: PROC LOCAL LOOP LOCAL ARRAY_END - LOCAL RET_ADDRESS ; Stores return address - LOCAL TMP_ARR_PTR ; Stores pointer temporarily + LOCAL TMP_ARR_PTR ; Ptr to Array DATA region. Stored temporarily + LOCAL LBOUND_PTR, UBOUND_PTR ; LBound and UBound PTR indexes + LOCAL RET_ADDR ; Contains the return address popped from the stack + LBOUND_PTR EQU 23698 ; Uses MEMBOT as a temporary variable + UBOUND_PTR EQU LBOUND_PTR + 2 ; Next 2 bytes for UBOUND PTR + RET_ADDR EQU UBOUND_PTR + 2 ; Next 2 bytes for RET_ADDR + TMP_ARR_PTR EQU RET_ADDR + 2 ; Next 2 bytes for TMP_ARR_PTR ld e, (hl) inc hl ld d, (hl) + inc hl ; DE <-- PTR to Dim sizes table + ld (TMP_ARR_PTR), hl ; HL = Array __DATA__.__PTR__ inc hl - ld (TMP_ARR_PTR), hl - ex de, hl - ex (sp), hl ; Return address in HL, array address in the stack - ld (RET_ADDRESS + 1), hl ; Stores it for later + inc hl + ld c, (hl) + inc hl + ld b, (hl) ; BC <-- Array __LBOUND__ PTR + ld (LBOUND_PTR), bc ; Store it for later +#line 66 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + ex de, hl ; HL <-- PTR to Dim sizes table, DE <-- dummy + ex (sp), hl ; Return address in HL, PTR Dim sizes table onto Stack + ld (RET_ADDR), hl ; Stores it for later exx - pop hl ; Will use H'L' as the pointer + pop hl ; Will use H'L' as the pointer to Dim sizes table ld c, (hl) ; Loads Number of dimensions from (hl) inc hl ld b, (hl) inc hl ; Ready exx - ld hl, 0 ; HL = Offset "accumulator" + ld hl, 0 ; HL = Element Offset "accumulator" LOOP: -#line 64 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" - pop bc ; Get next index (Ai) from the stack -#line 74 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" - add hl, bc ; Adds current index + ex de, hl ; DE = Element Offset + ld hl, (LBOUND_PTR) + ld a, h + or l + ld b, h + ld c, l + jr z, 1f + ld c, (hl) + inc hl + ld b, (hl) + inc hl + ld (LBOUND_PTR), hl +1: + pop hl ; Get next index (Ai) from the stack + sbc hl, bc ; Subtract LBOUND +#line 116 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + add hl, de ; Adds current index exx ; Checks if B'C' = 0 ld a, b ; Which means we must exit (last element is not multiplied by anything) or c jr z, ARRAY_END ; if B'Ci == 0 we are done - ld e, (hl) ; Loads next dimension into D'E' + dec bc ; Decrements loop counter + ld e, (hl) ; Loads next dimension size into D'E' inc hl ld d, (hl) inc hl push de - dec bc ; Decrements loop counter exx pop de ; DE = Max bound Number (i-th dimension) - call __FNMUL + call __FNMUL ; HL <= HL * DE mod 65536 jp LOOP ARRAY_END: ld a, (hl) exx -#line 103 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 146 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl ld hl, 0 @@ -217,7 +244,7 @@ ARRAY_END: ARRAY_SIZE_LOOP: add hl, de djnz ARRAY_SIZE_LOOP -#line 113 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 156 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ex de, hl ld hl, (TMP_ARR_PTR) ld a, (hl) @@ -225,8 +252,9 @@ ARRAY_SIZE_LOOP: ld h, (hl) ld l, a add hl, de ; Adds element start -RET_ADDRESS: - jp 0 + ld de, (RET_ADDR) + push de + ret ;; Performs a faster multiply for little 16bit numbs LOCAL __FNMUL, __FNMUL2 __FNMUL: @@ -243,8 +271,6 @@ __FNMUL2: add hl, de djnz __FNMUL2 ret -TMP_ARR_PTR: - DW 0 ; temporary storage for pointer to tables ENDP pop namespace #line 59 "arch/zx48k/let_array_substr.bas" diff --git a/tests/functional/arch/zx48k/let_array_substr1.asm b/tests/functional/arch/zx48k/let_array_substr1.asm index b4b493cfe..ebd2fe087 100644 --- a/tests/functional/arch/zx48k/let_array_substr1.asm +++ b/tests/functional/arch/zx48k/let_array_substr1.asm @@ -30,6 +30,8 @@ _a: DEFW .LABEL.__LABEL2 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW 0 + DEFW 0 _a.__DATA__: DEFB 00h DEFB 00h @@ -164,52 +166,77 @@ __ARRAY_PTR: ;; computes an array offset from a pointer ld c, (hl) inc hl ld h, (hl) - ld l, c + ld l, c ;; HL <-- [HL] __ARRAY: PROC LOCAL LOOP LOCAL ARRAY_END - LOCAL RET_ADDRESS ; Stores return address - LOCAL TMP_ARR_PTR ; Stores pointer temporarily + LOCAL TMP_ARR_PTR ; Ptr to Array DATA region. Stored temporarily + LOCAL LBOUND_PTR, UBOUND_PTR ; LBound and UBound PTR indexes + LOCAL RET_ADDR ; Contains the return address popped from the stack + LBOUND_PTR EQU 23698 ; Uses MEMBOT as a temporary variable + UBOUND_PTR EQU LBOUND_PTR + 2 ; Next 2 bytes for UBOUND PTR + RET_ADDR EQU UBOUND_PTR + 2 ; Next 2 bytes for RET_ADDR + TMP_ARR_PTR EQU RET_ADDR + 2 ; Next 2 bytes for TMP_ARR_PTR ld e, (hl) inc hl ld d, (hl) + inc hl ; DE <-- PTR to Dim sizes table + ld (TMP_ARR_PTR), hl ; HL = Array __DATA__.__PTR__ inc hl - ld (TMP_ARR_PTR), hl - ex de, hl - ex (sp), hl ; Return address in HL, array address in the stack - ld (RET_ADDRESS + 1), hl ; Stores it for later + inc hl + ld c, (hl) + inc hl + ld b, (hl) ; BC <-- Array __LBOUND__ PTR + ld (LBOUND_PTR), bc ; Store it for later +#line 66 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + ex de, hl ; HL <-- PTR to Dim sizes table, DE <-- dummy + ex (sp), hl ; Return address in HL, PTR Dim sizes table onto Stack + ld (RET_ADDR), hl ; Stores it for later exx - pop hl ; Will use H'L' as the pointer + pop hl ; Will use H'L' as the pointer to Dim sizes table ld c, (hl) ; Loads Number of dimensions from (hl) inc hl ld b, (hl) inc hl ; Ready exx - ld hl, 0 ; HL = Offset "accumulator" + ld hl, 0 ; HL = Element Offset "accumulator" LOOP: -#line 64 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" - pop bc ; Get next index (Ai) from the stack -#line 74 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" - add hl, bc ; Adds current index + ex de, hl ; DE = Element Offset + ld hl, (LBOUND_PTR) + ld a, h + or l + ld b, h + ld c, l + jr z, 1f + ld c, (hl) + inc hl + ld b, (hl) + inc hl + ld (LBOUND_PTR), hl +1: + pop hl ; Get next index (Ai) from the stack + sbc hl, bc ; Subtract LBOUND +#line 116 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + add hl, de ; Adds current index exx ; Checks if B'C' = 0 ld a, b ; Which means we must exit (last element is not multiplied by anything) or c jr z, ARRAY_END ; if B'Ci == 0 we are done - ld e, (hl) ; Loads next dimension into D'E' + dec bc ; Decrements loop counter + ld e, (hl) ; Loads next dimension size into D'E' inc hl ld d, (hl) inc hl push de - dec bc ; Decrements loop counter exx pop de ; DE = Max bound Number (i-th dimension) - call __FNMUL + call __FNMUL ; HL <= HL * DE mod 65536 jp LOOP ARRAY_END: ld a, (hl) exx -#line 103 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 146 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl ld hl, 0 @@ -217,7 +244,7 @@ ARRAY_END: ARRAY_SIZE_LOOP: add hl, de djnz ARRAY_SIZE_LOOP -#line 113 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 156 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ex de, hl ld hl, (TMP_ARR_PTR) ld a, (hl) @@ -225,8 +252,9 @@ ARRAY_SIZE_LOOP: ld h, (hl) ld l, a add hl, de ; Adds element start -RET_ADDRESS: - jp 0 + ld de, (RET_ADDR) + push de + ret ;; Performs a faster multiply for little 16bit numbs LOCAL __FNMUL, __FNMUL2 __FNMUL: @@ -243,8 +271,6 @@ __FNMUL2: add hl, de djnz __FNMUL2 ret -TMP_ARR_PTR: - DW 0 ; temporary storage for pointer to tables ENDP pop namespace #line 59 "arch/zx48k/let_array_substr1.bas" diff --git a/tests/functional/arch/zx48k/let_array_substr10.asm b/tests/functional/arch/zx48k/let_array_substr10.asm index 3c781b09d..fe5e593af 100644 --- a/tests/functional/arch/zx48k/let_array_substr10.asm +++ b/tests/functional/arch/zx48k/let_array_substr10.asm @@ -27,6 +27,8 @@ _a: DEFW .LABEL.__LABEL2 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW 0 + DEFW 0 _a.__DATA__: DEFB 00h DEFB 00h diff --git a/tests/functional/arch/zx48k/let_array_substr11.asm b/tests/functional/arch/zx48k/let_array_substr11.asm index f6c9a1ed0..c05c8916f 100644 --- a/tests/functional/arch/zx48k/let_array_substr11.asm +++ b/tests/functional/arch/zx48k/let_array_substr11.asm @@ -27,6 +27,8 @@ _a: DEFW .LABEL.__LABEL2 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW 0 + DEFW 0 _a.__DATA__: DEFB 00h DEFB 00h diff --git a/tests/functional/arch/zx48k/let_array_substr12.asm b/tests/functional/arch/zx48k/let_array_substr12.asm index 1dfb22784..8f8e463cb 100644 --- a/tests/functional/arch/zx48k/let_array_substr12.asm +++ b/tests/functional/arch/zx48k/let_array_substr12.asm @@ -27,6 +27,8 @@ _a: DEFW .LABEL.__LABEL2 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW 0 + DEFW 0 _a.__DATA__: DEFB 00h DEFB 00h diff --git a/tests/functional/arch/zx48k/let_array_substr13.asm b/tests/functional/arch/zx48k/let_array_substr13.asm index 65cdfd589..a548c71a4 100644 --- a/tests/functional/arch/zx48k/let_array_substr13.asm +++ b/tests/functional/arch/zx48k/let_array_substr13.asm @@ -27,6 +27,8 @@ _a: DEFW .LABEL.__LABEL2 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW 0 + DEFW 0 _a.__DATA__: DEFB 00h DEFB 00h diff --git a/tests/functional/arch/zx48k/let_array_substr2.asm b/tests/functional/arch/zx48k/let_array_substr2.asm index 3e09b4987..fc8981926 100644 --- a/tests/functional/arch/zx48k/let_array_substr2.asm +++ b/tests/functional/arch/zx48k/let_array_substr2.asm @@ -27,6 +27,8 @@ _a: DEFW .LABEL.__LABEL2 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW 0 + DEFW 0 _a.__DATA__: DEFB 00h DEFB 00h diff --git a/tests/functional/arch/zx48k/let_array_substr3.asm b/tests/functional/arch/zx48k/let_array_substr3.asm index 2116e32af..f84fe2142 100644 --- a/tests/functional/arch/zx48k/let_array_substr3.asm +++ b/tests/functional/arch/zx48k/let_array_substr3.asm @@ -27,6 +27,8 @@ _a: DEFW .LABEL.__LABEL2 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW 0 + DEFW 0 _a.__DATA__: DEFB 00h DEFB 00h diff --git a/tests/functional/arch/zx48k/let_array_substr5.asm b/tests/functional/arch/zx48k/let_array_substr5.asm index e9b2008c6..2d81f188c 100644 --- a/tests/functional/arch/zx48k/let_array_substr5.asm +++ b/tests/functional/arch/zx48k/let_array_substr5.asm @@ -30,6 +30,8 @@ _a: DEFW .LABEL.__LABEL2 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW 0 + DEFW 0 _a.__DATA__: DEFB 00h DEFB 00h @@ -164,52 +166,77 @@ __ARRAY_PTR: ;; computes an array offset from a pointer ld c, (hl) inc hl ld h, (hl) - ld l, c + ld l, c ;; HL <-- [HL] __ARRAY: PROC LOCAL LOOP LOCAL ARRAY_END - LOCAL RET_ADDRESS ; Stores return address - LOCAL TMP_ARR_PTR ; Stores pointer temporarily + LOCAL TMP_ARR_PTR ; Ptr to Array DATA region. Stored temporarily + LOCAL LBOUND_PTR, UBOUND_PTR ; LBound and UBound PTR indexes + LOCAL RET_ADDR ; Contains the return address popped from the stack + LBOUND_PTR EQU 23698 ; Uses MEMBOT as a temporary variable + UBOUND_PTR EQU LBOUND_PTR + 2 ; Next 2 bytes for UBOUND PTR + RET_ADDR EQU UBOUND_PTR + 2 ; Next 2 bytes for RET_ADDR + TMP_ARR_PTR EQU RET_ADDR + 2 ; Next 2 bytes for TMP_ARR_PTR ld e, (hl) inc hl ld d, (hl) + inc hl ; DE <-- PTR to Dim sizes table + ld (TMP_ARR_PTR), hl ; HL = Array __DATA__.__PTR__ inc hl - ld (TMP_ARR_PTR), hl - ex de, hl - ex (sp), hl ; Return address in HL, array address in the stack - ld (RET_ADDRESS + 1), hl ; Stores it for later + inc hl + ld c, (hl) + inc hl + ld b, (hl) ; BC <-- Array __LBOUND__ PTR + ld (LBOUND_PTR), bc ; Store it for later +#line 66 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + ex de, hl ; HL <-- PTR to Dim sizes table, DE <-- dummy + ex (sp), hl ; Return address in HL, PTR Dim sizes table onto Stack + ld (RET_ADDR), hl ; Stores it for later exx - pop hl ; Will use H'L' as the pointer + pop hl ; Will use H'L' as the pointer to Dim sizes table ld c, (hl) ; Loads Number of dimensions from (hl) inc hl ld b, (hl) inc hl ; Ready exx - ld hl, 0 ; HL = Offset "accumulator" + ld hl, 0 ; HL = Element Offset "accumulator" LOOP: -#line 64 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" - pop bc ; Get next index (Ai) from the stack -#line 74 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" - add hl, bc ; Adds current index + ex de, hl ; DE = Element Offset + ld hl, (LBOUND_PTR) + ld a, h + or l + ld b, h + ld c, l + jr z, 1f + ld c, (hl) + inc hl + ld b, (hl) + inc hl + ld (LBOUND_PTR), hl +1: + pop hl ; Get next index (Ai) from the stack + sbc hl, bc ; Subtract LBOUND +#line 116 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + add hl, de ; Adds current index exx ; Checks if B'C' = 0 ld a, b ; Which means we must exit (last element is not multiplied by anything) or c jr z, ARRAY_END ; if B'Ci == 0 we are done - ld e, (hl) ; Loads next dimension into D'E' + dec bc ; Decrements loop counter + ld e, (hl) ; Loads next dimension size into D'E' inc hl ld d, (hl) inc hl push de - dec bc ; Decrements loop counter exx pop de ; DE = Max bound Number (i-th dimension) - call __FNMUL + call __FNMUL ; HL <= HL * DE mod 65536 jp LOOP ARRAY_END: ld a, (hl) exx -#line 103 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 146 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl ld hl, 0 @@ -217,7 +244,7 @@ ARRAY_END: ARRAY_SIZE_LOOP: add hl, de djnz ARRAY_SIZE_LOOP -#line 113 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 156 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ex de, hl ld hl, (TMP_ARR_PTR) ld a, (hl) @@ -225,8 +252,9 @@ ARRAY_SIZE_LOOP: ld h, (hl) ld l, a add hl, de ; Adds element start -RET_ADDRESS: - jp 0 + ld de, (RET_ADDR) + push de + ret ;; Performs a faster multiply for little 16bit numbs LOCAL __FNMUL, __FNMUL2 __FNMUL: @@ -243,8 +271,6 @@ __FNMUL2: add hl, de djnz __FNMUL2 ret -TMP_ARR_PTR: - DW 0 ; temporary storage for pointer to tables ENDP pop namespace #line 59 "arch/zx48k/let_array_substr5.bas" diff --git a/tests/functional/arch/zx48k/let_array_substr7.asm b/tests/functional/arch/zx48k/let_array_substr7.asm index 3c6432a94..1651c0018 100644 --- a/tests/functional/arch/zx48k/let_array_substr7.asm +++ b/tests/functional/arch/zx48k/let_array_substr7.asm @@ -27,6 +27,8 @@ _a: DEFW .LABEL.__LABEL2 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW 0 + DEFW 0 _a.__DATA__: DEFB 00h DEFB 00h diff --git a/tests/functional/arch/zx48k/let_array_substr9.asm b/tests/functional/arch/zx48k/let_array_substr9.asm index ecea6e4e3..00ff22af3 100644 --- a/tests/functional/arch/zx48k/let_array_substr9.asm +++ b/tests/functional/arch/zx48k/let_array_substr9.asm @@ -27,6 +27,8 @@ _a: DEFW .LABEL.__LABEL2 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW 0 + DEFW 0 _a.__DATA__: DEFB 00h DEFB 00h diff --git a/tests/functional/arch/zx48k/letarrstr_substr0.asm b/tests/functional/arch/zx48k/letarrstr_substr0.asm index bed533abf..63e89665c 100644 --- a/tests/functional/arch/zx48k/letarrstr_substr0.asm +++ b/tests/functional/arch/zx48k/letarrstr_substr0.asm @@ -29,6 +29,8 @@ _a: DEFW .LABEL.__LABEL0 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW 0 + DEFW 0 _a.__DATA__: DEFB 00h DEFB 00h @@ -74,8 +76,8 @@ _a.__DATA__: ei ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/loadstr.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/loadstr.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -135,7 +137,7 @@ _a.__DATA__: ; HL = BLOCK Start & DE = Length. ; An init directive is useful for initialization routines. ; They will be added automatically if needed. -#line 1 "/zxbasic/src/arch/zx48k/library-asm/error.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/error.asm" ; Simple error control routines ; vim:ts=4:et: push namespace core @@ -169,8 +171,8 @@ __STOP: ld (ERR_NR), a ret pop namespace -#line 69 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/heapinit.asm" +#line 69 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/heapinit.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -277,7 +279,7 @@ __MEM_INIT2: ret ENDP pop namespace -#line 70 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 70 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; --------------------------------------------------------------------- ; MEM_ALLOC ; Allocates a block of memory in the heap. @@ -308,9 +310,9 @@ __MEM_START: __MEM_LOOP: ; Loads lengh at (HL, HL+). If Lenght >= BC, jump to __MEM_DONE ld a, h ; HL = NULL (No memory available?) or l -#line 113 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 113 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ret z ; NULL -#line 115 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 115 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; HL = Pointer to Free block ld e, (hl) inc hl @@ -375,7 +377,7 @@ __MEM_SUBTRACT: ret ENDP pop namespace -#line 2 "/zxbasic/src/arch/zx48k/library-asm/loadstr.asm" +#line 2 "/zxbasic/src/lib/arch/zx48k/runtime/loadstr.asm" ; Loads a string (ptr) from HL ; and duplicates it on dynamic memory again ; Finally, it returns result pointer in HL @@ -412,15 +414,15 @@ __LOADSTR: ; __FASTCALL__ entry pop hl ; Recovers destiny in hl as result ret pop namespace -#line 29 "letarrstr_substr0.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/storestr2.asm" +#line 29 "arch/zx48k/letarrstr_substr0.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/storestr2.asm" ; Similar to __STORE_STR, but this one is called when ; the value of B$ if already duplicated onto the stack. ; So we needn't call STRASSING to create a duplication ; HL = address of string memory variable ; DE = address of 2n string. It just copies DE into (HL) ; freeing (HL) previously. -#line 1 "/zxbasic/src/arch/zx48k/library-asm/free.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/free.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -578,7 +580,7 @@ __MEM_BLOCK_JOIN: ; Joins current block (pointed by HL) with next one (pointed ret ENDP pop namespace -#line 9 "/zxbasic/src/arch/zx48k/library-asm/storestr2.asm" +#line 9 "/zxbasic/src/lib/arch/zx48k/runtime/storestr2.asm" push namespace core __PISTORE_STR2: ; Indirect store temporary string at (IX + BC) push ix @@ -605,8 +607,8 @@ __STORE_STR2: dec hl ; HL points to mem address variable. This might be useful in the future. ret pop namespace -#line 30 "letarrstr_substr0.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/strslice.asm" +#line 30 "arch/zx48k/letarrstr_substr0.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/strslice.asm" ; String slicing library ; HL = Str pointer ; DE = String start @@ -620,7 +622,7 @@ __STORE_STR2: ; it in dynamic memory if needed). Returns pointer (HL) to resulting ; string. NULL (0) if no memory for padding. ; -#line 1 "/zxbasic/src/arch/zx48k/library-asm/strlen.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/strlen.asm" ; Returns len if a string ; If a string is NULL, its len is also 0 ; Result returned in HL @@ -635,7 +637,7 @@ __STRLEN: ; Direct FASTCALL entry ld l, a ret pop namespace -#line 18 "/zxbasic/src/arch/zx48k/library-asm/strslice.asm" +#line 18 "/zxbasic/src/lib/arch/zx48k/runtime/strslice.asm" push namespace core __STRSLICE: ; Callee entry pop hl ; Return ADDRESS @@ -707,5 +709,5 @@ __FREE_ON_EXIT: ret ENDP pop namespace -#line 31 "letarrstr_substr0.bas" +#line 31 "arch/zx48k/letarrstr_substr0.bas" END diff --git a/tests/functional/arch/zx48k/letarrstr_substr1.asm b/tests/functional/arch/zx48k/letarrstr_substr1.asm index 3278f67cf..89743d2d7 100644 --- a/tests/functional/arch/zx48k/letarrstr_substr1.asm +++ b/tests/functional/arch/zx48k/letarrstr_substr1.asm @@ -29,6 +29,8 @@ _a: DEFW .LABEL.__LABEL0 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW 0 + DEFW 0 _a.__DATA__: DEFB 00h DEFB 00h @@ -74,8 +76,8 @@ _a.__DATA__: ei ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/loadstr.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/loadstr.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -135,7 +137,7 @@ _a.__DATA__: ; HL = BLOCK Start & DE = Length. ; An init directive is useful for initialization routines. ; They will be added automatically if needed. -#line 1 "/zxbasic/src/arch/zx48k/library-asm/error.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/error.asm" ; Simple error control routines ; vim:ts=4:et: push namespace core @@ -169,8 +171,8 @@ __STOP: ld (ERR_NR), a ret pop namespace -#line 69 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/heapinit.asm" +#line 69 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/heapinit.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -277,7 +279,7 @@ __MEM_INIT2: ret ENDP pop namespace -#line 70 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 70 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; --------------------------------------------------------------------- ; MEM_ALLOC ; Allocates a block of memory in the heap. @@ -308,9 +310,9 @@ __MEM_START: __MEM_LOOP: ; Loads lengh at (HL, HL+). If Lenght >= BC, jump to __MEM_DONE ld a, h ; HL = NULL (No memory available?) or l -#line 113 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 113 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ret z ; NULL -#line 115 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 115 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; HL = Pointer to Free block ld e, (hl) inc hl @@ -375,7 +377,7 @@ __MEM_SUBTRACT: ret ENDP pop namespace -#line 2 "/zxbasic/src/arch/zx48k/library-asm/loadstr.asm" +#line 2 "/zxbasic/src/lib/arch/zx48k/runtime/loadstr.asm" ; Loads a string (ptr) from HL ; and duplicates it on dynamic memory again ; Finally, it returns result pointer in HL @@ -412,15 +414,15 @@ __LOADSTR: ; __FASTCALL__ entry pop hl ; Recovers destiny in hl as result ret pop namespace -#line 29 "letarrstr_substr1.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/storestr2.asm" +#line 29 "arch/zx48k/letarrstr_substr1.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/storestr2.asm" ; Similar to __STORE_STR, but this one is called when ; the value of B$ if already duplicated onto the stack. ; So we needn't call STRASSING to create a duplication ; HL = address of string memory variable ; DE = address of 2n string. It just copies DE into (HL) ; freeing (HL) previously. -#line 1 "/zxbasic/src/arch/zx48k/library-asm/free.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/free.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -578,7 +580,7 @@ __MEM_BLOCK_JOIN: ; Joins current block (pointed by HL) with next one (pointed ret ENDP pop namespace -#line 9 "/zxbasic/src/arch/zx48k/library-asm/storestr2.asm" +#line 9 "/zxbasic/src/lib/arch/zx48k/runtime/storestr2.asm" push namespace core __PISTORE_STR2: ; Indirect store temporary string at (IX + BC) push ix @@ -605,8 +607,8 @@ __STORE_STR2: dec hl ; HL points to mem address variable. This might be useful in the future. ret pop namespace -#line 30 "letarrstr_substr1.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/strslice.asm" +#line 30 "arch/zx48k/letarrstr_substr1.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/strslice.asm" ; String slicing library ; HL = Str pointer ; DE = String start @@ -620,7 +622,7 @@ __STORE_STR2: ; it in dynamic memory if needed). Returns pointer (HL) to resulting ; string. NULL (0) if no memory for padding. ; -#line 1 "/zxbasic/src/arch/zx48k/library-asm/strlen.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/strlen.asm" ; Returns len if a string ; If a string is NULL, its len is also 0 ; Result returned in HL @@ -635,7 +637,7 @@ __STRLEN: ; Direct FASTCALL entry ld l, a ret pop namespace -#line 18 "/zxbasic/src/arch/zx48k/library-asm/strslice.asm" +#line 18 "/zxbasic/src/lib/arch/zx48k/runtime/strslice.asm" push namespace core __STRSLICE: ; Callee entry pop hl ; Return ADDRESS @@ -707,5 +709,5 @@ __FREE_ON_EXIT: ret ENDP pop namespace -#line 31 "letarrstr_substr1.bas" +#line 31 "arch/zx48k/letarrstr_substr1.bas" END diff --git a/tests/functional/arch/zx48k/local_float_array0.asm b/tests/functional/arch/zx48k/local_float_array0.asm index 87debf48c..ac41c2497 100644 --- a/tests/functional/arch/zx48k/local_float_array0.asm +++ b/tests/functional/arch/zx48k/local_float_array0.asm @@ -87,7 +87,7 @@ _test__leave: pop ix ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -103,7 +103,7 @@ _test__leave: ; O = [a0 + b0 * (a1 + b1 * (a2 + ... bN-2(aN-1)))] ; What I will do here is to calculate the following sequence: ; ((aN-1 * bN-2) + aN-2) * bN-3 + ... -#line 1 "/zxbasic/src/arch/zx48k/library-asm/mul16.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/mul16.asm" push namespace core __MUL16: ; Mutiplies HL with the last value stored into de stack ; Works for both signed and unsigned @@ -129,59 +129,84 @@ __MUL16NOADD: ret ; Result in hl (16 lower bits) ENDP pop namespace -#line 20 "/zxbasic/src/arch/zx48k/library-asm/array.asm" -#line 24 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 20 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 24 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" push namespace core __ARRAY_PTR: ;; computes an array offset from a pointer ld c, (hl) inc hl ld h, (hl) - ld l, c + ld l, c ;; HL <-- [HL] __ARRAY: PROC LOCAL LOOP LOCAL ARRAY_END - LOCAL RET_ADDRESS ; Stores return address - LOCAL TMP_ARR_PTR ; Stores pointer temporarily + LOCAL TMP_ARR_PTR ; Ptr to Array DATA region. Stored temporarily + LOCAL LBOUND_PTR, UBOUND_PTR ; LBound and UBound PTR indexes + LOCAL RET_ADDR ; Contains the return address popped from the stack + LBOUND_PTR EQU 23698 ; Uses MEMBOT as a temporary variable + UBOUND_PTR EQU LBOUND_PTR + 2 ; Next 2 bytes for UBOUND PTR + RET_ADDR EQU UBOUND_PTR + 2 ; Next 2 bytes for RET_ADDR + TMP_ARR_PTR EQU RET_ADDR + 2 ; Next 2 bytes for TMP_ARR_PTR ld e, (hl) inc hl ld d, (hl) + inc hl ; DE <-- PTR to Dim sizes table + ld (TMP_ARR_PTR), hl ; HL = Array __DATA__.__PTR__ inc hl - ld (TMP_ARR_PTR), hl - ex de, hl - ex (sp), hl ; Return address in HL, array address in the stack - ld (RET_ADDRESS + 1), hl ; Stores it for later + inc hl + ld c, (hl) + inc hl + ld b, (hl) ; BC <-- Array __LBOUND__ PTR + ld (LBOUND_PTR), bc ; Store it for later +#line 66 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + ex de, hl ; HL <-- PTR to Dim sizes table, DE <-- dummy + ex (sp), hl ; Return address in HL, PTR Dim sizes table onto Stack + ld (RET_ADDR), hl ; Stores it for later exx - pop hl ; Will use H'L' as the pointer + pop hl ; Will use H'L' as the pointer to Dim sizes table ld c, (hl) ; Loads Number of dimensions from (hl) inc hl ld b, (hl) inc hl ; Ready exx - ld hl, 0 ; HL = Offset "accumulator" + ld hl, 0 ; HL = Element Offset "accumulator" LOOP: -#line 64 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - pop bc ; Get next index (Ai) from the stack -#line 74 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - add hl, bc ; Adds current index + ex de, hl ; DE = Element Offset + ld hl, (LBOUND_PTR) + ld a, h + or l + ld b, h + ld c, l + jr z, 1f + ld c, (hl) + inc hl + ld b, (hl) + inc hl + ld (LBOUND_PTR), hl +1: + pop hl ; Get next index (Ai) from the stack + sbc hl, bc ; Subtract LBOUND +#line 116 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + add hl, de ; Adds current index exx ; Checks if B'C' = 0 ld a, b ; Which means we must exit (last element is not multiplied by anything) or c jr z, ARRAY_END ; if B'Ci == 0 we are done - ld e, (hl) ; Loads next dimension into D'E' + dec bc ; Decrements loop counter + ld e, (hl) ; Loads next dimension size into D'E' inc hl ld d, (hl) inc hl push de - dec bc ; Decrements loop counter exx pop de ; DE = Max bound Number (i-th dimension) - call __FNMUL + call __FNMUL ; HL <= HL * DE mod 65536 jp LOOP ARRAY_END: ld a, (hl) exx -#line 103 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 146 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl ld hl, 0 @@ -189,7 +214,7 @@ ARRAY_END: ARRAY_SIZE_LOOP: add hl, de djnz ARRAY_SIZE_LOOP -#line 113 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 156 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ex de, hl ld hl, (TMP_ARR_PTR) ld a, (hl) @@ -197,8 +222,9 @@ ARRAY_SIZE_LOOP: ld h, (hl) ld l, a add hl, de ; Adds element start -RET_ADDRESS: - jp 0 + ld de, (RET_ADDR) + push de + ret ;; Performs a faster multiply for little 16bit numbs LOCAL __FNMUL, __FNMUL2 __FNMUL: @@ -215,13 +241,11 @@ __FNMUL2: add hl, de djnz __FNMUL2 ret -TMP_ARR_PTR: - DW 0 ; temporary storage for pointer to tables ENDP pop namespace -#line 62 "zx48k/local_float_array0.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/arrayalloc.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/calloc.asm" +#line 62 "arch/zx48k/local_float_array0.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/arrayalloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/calloc.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -232,7 +256,7 @@ TMP_ARR_PTR: ; closed source programs). ; ; Please read the MIT license on the internet -#line 1 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -292,7 +316,7 @@ TMP_ARR_PTR: ; HL = BLOCK Start & DE = Length. ; An init directive is useful for initialization routines. ; They will be added automatically if needed. -#line 1 "/zxbasic/src/arch/zx48k/library-asm/error.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/error.asm" ; Simple error control routines ; vim:ts=4:et: push namespace core @@ -326,8 +350,8 @@ __STOP: ld (ERR_NR), a ret pop namespace -#line 69 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/heapinit.asm" +#line 69 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/heapinit.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -434,7 +458,7 @@ __MEM_INIT2: ret ENDP pop namespace -#line 70 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 70 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; --------------------------------------------------------------------- ; MEM_ALLOC ; Allocates a block of memory in the heap. @@ -465,9 +489,9 @@ __MEM_START: __MEM_LOOP: ; Loads lengh at (HL, HL+). If Lenght >= BC, jump to __MEM_DONE ld a, h ; HL = NULL (No memory available?) or l -#line 113 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 113 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ret z ; NULL -#line 115 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 115 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; HL = Pointer to Free block ld e, (hl) inc hl @@ -532,7 +556,7 @@ __MEM_SUBTRACT: ret ENDP pop namespace -#line 13 "/zxbasic/src/arch/zx48k/library-asm/calloc.asm" +#line 13 "/zxbasic/src/lib/arch/zx48k/runtime/calloc.asm" ; --------------------------------------------------------------------- ; MEM_CALLOC ; Allocates a block of memory in the heap, and clears it filling it @@ -566,7 +590,7 @@ __MEM_CALLOC: pop hl ret pop namespace -#line 3 "/zxbasic/src/arch/zx48k/library-asm/arrayalloc.asm" +#line 3 "/zxbasic/src/lib/arch/zx48k/runtime/arrayalloc.asm" ; --------------------------------------------------------------------- ; __ALLOC_LOCAL_ARRAY ; Allocates an array element area in the heap, and clears it filling it @@ -630,10 +654,10 @@ __ALLOC_INITIALIZED_LOCAL_ARRAY: ldir pop hl ; HL = addr of LBound area if used ret -#line 139 "/zxbasic/src/arch/zx48k/library-asm/arrayalloc.asm" +#line 139 "/zxbasic/src/lib/arch/zx48k/runtime/arrayalloc.asm" pop namespace -#line 63 "zx48k/local_float_array0.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/free.asm" +#line 63 "arch/zx48k/local_float_array0.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/free.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -791,8 +815,8 @@ __MEM_BLOCK_JOIN: ; Joins current block (pointed by HL) with next one (pointed ret ENDP pop namespace -#line 64 "zx48k/local_float_array0.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/iloadf.asm" +#line 64 "arch/zx48k/local_float_array0.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/iloadf.asm" ; __FASTCALL__ routine which ; loads a 40 bits floating point into A ED CB ; stored at position pointed by POINTER HL @@ -819,8 +843,8 @@ __LOADF: ; Loads a 40 bits FP number from address pointed by HL ld b, (hl) ret pop namespace -#line 65 "zx48k/local_float_array0.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/storef.asm" +#line 65 "arch/zx48k/local_float_array0.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/storef.asm" push namespace core __PISTOREF: ; Indect Stores a float (A, E, D, C, B) at location stored in memory, pointed by (IX + HL) push de @@ -848,7 +872,7 @@ __STOREF: ; Stores the given FP number in A EDCB at address HL ld (hl), b ret pop namespace -#line 66 "zx48k/local_float_array0.bas" +#line 66 "arch/zx48k/local_float_array0.bas" .LABEL.__LABEL0: DEFB 00h DEFB 00h diff --git a/tests/functional/arch/zx48k/local_str_array1.asm b/tests/functional/arch/zx48k/local_str_array1.asm index b4ec12834..15f487a65 100644 --- a/tests/functional/arch/zx48k/local_str_array1.asm +++ b/tests/functional/arch/zx48k/local_str_array1.asm @@ -99,7 +99,7 @@ _test__leave: DEFB 4Ch DEFB 44h ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -115,7 +115,7 @@ _test__leave: ; O = [a0 + b0 * (a1 + b1 * (a2 + ... bN-2(aN-1)))] ; What I will do here is to calculate the following sequence: ; ((aN-1 * bN-2) + aN-2) * bN-3 + ... -#line 1 "/zxbasic/src/arch/zx48k/library-asm/mul16.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/mul16.asm" push namespace core __MUL16: ; Mutiplies HL with the last value stored into de stack ; Works for both signed and unsigned @@ -141,59 +141,84 @@ __MUL16NOADD: ret ; Result in hl (16 lower bits) ENDP pop namespace -#line 20 "/zxbasic/src/arch/zx48k/library-asm/array.asm" -#line 24 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 20 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 24 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" push namespace core __ARRAY_PTR: ;; computes an array offset from a pointer ld c, (hl) inc hl ld h, (hl) - ld l, c + ld l, c ;; HL <-- [HL] __ARRAY: PROC LOCAL LOOP LOCAL ARRAY_END - LOCAL RET_ADDRESS ; Stores return address - LOCAL TMP_ARR_PTR ; Stores pointer temporarily + LOCAL TMP_ARR_PTR ; Ptr to Array DATA region. Stored temporarily + LOCAL LBOUND_PTR, UBOUND_PTR ; LBound and UBound PTR indexes + LOCAL RET_ADDR ; Contains the return address popped from the stack + LBOUND_PTR EQU 23698 ; Uses MEMBOT as a temporary variable + UBOUND_PTR EQU LBOUND_PTR + 2 ; Next 2 bytes for UBOUND PTR + RET_ADDR EQU UBOUND_PTR + 2 ; Next 2 bytes for RET_ADDR + TMP_ARR_PTR EQU RET_ADDR + 2 ; Next 2 bytes for TMP_ARR_PTR ld e, (hl) inc hl ld d, (hl) + inc hl ; DE <-- PTR to Dim sizes table + ld (TMP_ARR_PTR), hl ; HL = Array __DATA__.__PTR__ inc hl - ld (TMP_ARR_PTR), hl - ex de, hl - ex (sp), hl ; Return address in HL, array address in the stack - ld (RET_ADDRESS + 1), hl ; Stores it for later + inc hl + ld c, (hl) + inc hl + ld b, (hl) ; BC <-- Array __LBOUND__ PTR + ld (LBOUND_PTR), bc ; Store it for later +#line 66 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + ex de, hl ; HL <-- PTR to Dim sizes table, DE <-- dummy + ex (sp), hl ; Return address in HL, PTR Dim sizes table onto Stack + ld (RET_ADDR), hl ; Stores it for later exx - pop hl ; Will use H'L' as the pointer + pop hl ; Will use H'L' as the pointer to Dim sizes table ld c, (hl) ; Loads Number of dimensions from (hl) inc hl ld b, (hl) inc hl ; Ready exx - ld hl, 0 ; HL = Offset "accumulator" + ld hl, 0 ; HL = Element Offset "accumulator" LOOP: -#line 64 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - pop bc ; Get next index (Ai) from the stack -#line 74 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - add hl, bc ; Adds current index + ex de, hl ; DE = Element Offset + ld hl, (LBOUND_PTR) + ld a, h + or l + ld b, h + ld c, l + jr z, 1f + ld c, (hl) + inc hl + ld b, (hl) + inc hl + ld (LBOUND_PTR), hl +1: + pop hl ; Get next index (Ai) from the stack + sbc hl, bc ; Subtract LBOUND +#line 116 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + add hl, de ; Adds current index exx ; Checks if B'C' = 0 ld a, b ; Which means we must exit (last element is not multiplied by anything) or c jr z, ARRAY_END ; if B'Ci == 0 we are done - ld e, (hl) ; Loads next dimension into D'E' + dec bc ; Decrements loop counter + ld e, (hl) ; Loads next dimension size into D'E' inc hl ld d, (hl) inc hl push de - dec bc ; Decrements loop counter exx pop de ; DE = Max bound Number (i-th dimension) - call __FNMUL + call __FNMUL ; HL <= HL * DE mod 65536 jp LOOP ARRAY_END: ld a, (hl) exx -#line 103 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 146 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl ld hl, 0 @@ -201,7 +226,7 @@ ARRAY_END: ARRAY_SIZE_LOOP: add hl, de djnz ARRAY_SIZE_LOOP -#line 113 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 156 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ex de, hl ld hl, (TMP_ARR_PTR) ld a, (hl) @@ -209,8 +234,9 @@ ARRAY_SIZE_LOOP: ld h, (hl) ld l, a add hl, de ; Adds element start -RET_ADDRESS: - jp 0 + ld de, (RET_ADDR) + push de + ret ;; Performs a faster multiply for little 16bit numbs LOCAL __FNMUL, __FNMUL2 __FNMUL: @@ -227,13 +253,11 @@ __FNMUL2: add hl, de djnz __FNMUL2 ret -TMP_ARR_PTR: - DW 0 ; temporary storage for pointer to tables ENDP pop namespace -#line 73 "local_str_array1.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/arrayalloc.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/calloc.asm" +#line 73 "arch/zx48k/local_str_array1.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/arrayalloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/calloc.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -244,7 +268,7 @@ TMP_ARR_PTR: ; closed source programs). ; ; Please read the MIT license on the internet -#line 1 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -304,7 +328,7 @@ TMP_ARR_PTR: ; HL = BLOCK Start & DE = Length. ; An init directive is useful for initialization routines. ; They will be added automatically if needed. -#line 1 "/zxbasic/src/arch/zx48k/library-asm/error.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/error.asm" ; Simple error control routines ; vim:ts=4:et: push namespace core @@ -338,8 +362,8 @@ __STOP: ld (ERR_NR), a ret pop namespace -#line 69 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/heapinit.asm" +#line 69 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/heapinit.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -446,7 +470,7 @@ __MEM_INIT2: ret ENDP pop namespace -#line 70 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 70 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; --------------------------------------------------------------------- ; MEM_ALLOC ; Allocates a block of memory in the heap. @@ -477,9 +501,9 @@ __MEM_START: __MEM_LOOP: ; Loads lengh at (HL, HL+). If Lenght >= BC, jump to __MEM_DONE ld a, h ; HL = NULL (No memory available?) or l -#line 113 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 113 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ret z ; NULL -#line 115 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 115 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; HL = Pointer to Free block ld e, (hl) inc hl @@ -544,7 +568,7 @@ __MEM_SUBTRACT: ret ENDP pop namespace -#line 13 "/zxbasic/src/arch/zx48k/library-asm/calloc.asm" +#line 13 "/zxbasic/src/lib/arch/zx48k/runtime/calloc.asm" ; --------------------------------------------------------------------- ; MEM_CALLOC ; Allocates a block of memory in the heap, and clears it filling it @@ -578,7 +602,7 @@ __MEM_CALLOC: pop hl ret pop namespace -#line 3 "/zxbasic/src/arch/zx48k/library-asm/arrayalloc.asm" +#line 3 "/zxbasic/src/lib/arch/zx48k/runtime/arrayalloc.asm" ; --------------------------------------------------------------------- ; __ALLOC_LOCAL_ARRAY ; Allocates an array element area in the heap, and clears it filling it @@ -642,14 +666,14 @@ __ALLOC_INITIALIZED_LOCAL_ARRAY: ldir pop hl ; HL = addr of LBound area if used ret -#line 139 "/zxbasic/src/arch/zx48k/library-asm/arrayalloc.asm" +#line 139 "/zxbasic/src/lib/arch/zx48k/runtime/arrayalloc.asm" pop namespace -#line 74 "local_str_array1.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/arraystrfree.asm" +#line 74 "arch/zx48k/local_str_array1.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/arraystrfree.asm" ; This routine is in charge of freeing an array of strings from memory ; HL = Pointer to start of array in memory ; Top of the stack = Number of elements of the array -#line 1 "/zxbasic/src/arch/zx48k/library-asm/free.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/free.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -807,7 +831,7 @@ __MEM_BLOCK_JOIN: ; Joins current block (pointed by HL) with next one (pointed ret ENDP pop namespace -#line 6 "/zxbasic/src/arch/zx48k/library-asm/arraystrfree.asm" +#line 6 "/zxbasic/src/lib/arch/zx48k/runtime/arraystrfree.asm" push namespace core __ARRAYSTR_FREE: PROC @@ -849,8 +873,8 @@ __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 75 "local_str_array1.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/loadstr.asm" +#line 75 "arch/zx48k/local_str_array1.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/loadstr.asm" ; Loads a string (ptr) from HL ; and duplicates it on dynamic memory again ; Finally, it returns result pointer in HL @@ -887,8 +911,8 @@ __LOADSTR: ; __FASTCALL__ entry pop hl ; Recovers destiny in hl as result ret pop namespace -#line 77 "local_str_array1.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/storestr2.asm" +#line 77 "arch/zx48k/local_str_array1.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/storestr2.asm" ; Similar to __STORE_STR, but this one is called when ; the value of B$ if already duplicated onto the stack. ; So we needn't call STRASSING to create a duplication @@ -921,7 +945,7 @@ __STORE_STR2: dec hl ; HL points to mem address variable. This might be useful in the future. ret pop namespace -#line 78 "local_str_array1.bas" +#line 78 "arch/zx48k/local_str_array1.bas" .LABEL.__LABEL1: DEFB 00h DEFB 00h diff --git a/tests/functional/arch/zx48k/local_str_array2.asm b/tests/functional/arch/zx48k/local_str_array2.asm index 8cc2e82e6..72e115356 100644 --- a/tests/functional/arch/zx48k/local_str_array2.asm +++ b/tests/functional/arch/zx48k/local_str_array2.asm @@ -107,7 +107,7 @@ _test__leave: DEFB 4Ch DEFB 44h ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -123,7 +123,7 @@ _test__leave: ; O = [a0 + b0 * (a1 + b1 * (a2 + ... bN-2(aN-1)))] ; What I will do here is to calculate the following sequence: ; ((aN-1 * bN-2) + aN-2) * bN-3 + ... -#line 1 "/zxbasic/src/arch/zx48k/library-asm/mul16.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/mul16.asm" push namespace core __MUL16: ; Mutiplies HL with the last value stored into de stack ; Works for both signed and unsigned @@ -149,59 +149,84 @@ __MUL16NOADD: ret ; Result in hl (16 lower bits) ENDP pop namespace -#line 20 "/zxbasic/src/arch/zx48k/library-asm/array.asm" -#line 24 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 20 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 24 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" push namespace core __ARRAY_PTR: ;; computes an array offset from a pointer ld c, (hl) inc hl ld h, (hl) - ld l, c + ld l, c ;; HL <-- [HL] __ARRAY: PROC LOCAL LOOP LOCAL ARRAY_END - LOCAL RET_ADDRESS ; Stores return address - LOCAL TMP_ARR_PTR ; Stores pointer temporarily + LOCAL TMP_ARR_PTR ; Ptr to Array DATA region. Stored temporarily + LOCAL LBOUND_PTR, UBOUND_PTR ; LBound and UBound PTR indexes + LOCAL RET_ADDR ; Contains the return address popped from the stack + LBOUND_PTR EQU 23698 ; Uses MEMBOT as a temporary variable + UBOUND_PTR EQU LBOUND_PTR + 2 ; Next 2 bytes for UBOUND PTR + RET_ADDR EQU UBOUND_PTR + 2 ; Next 2 bytes for RET_ADDR + TMP_ARR_PTR EQU RET_ADDR + 2 ; Next 2 bytes for TMP_ARR_PTR ld e, (hl) inc hl ld d, (hl) + inc hl ; DE <-- PTR to Dim sizes table + ld (TMP_ARR_PTR), hl ; HL = Array __DATA__.__PTR__ inc hl - ld (TMP_ARR_PTR), hl - ex de, hl - ex (sp), hl ; Return address in HL, array address in the stack - ld (RET_ADDRESS + 1), hl ; Stores it for later + inc hl + ld c, (hl) + inc hl + ld b, (hl) ; BC <-- Array __LBOUND__ PTR + ld (LBOUND_PTR), bc ; Store it for later +#line 66 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + ex de, hl ; HL <-- PTR to Dim sizes table, DE <-- dummy + ex (sp), hl ; Return address in HL, PTR Dim sizes table onto Stack + ld (RET_ADDR), hl ; Stores it for later exx - pop hl ; Will use H'L' as the pointer + pop hl ; Will use H'L' as the pointer to Dim sizes table ld c, (hl) ; Loads Number of dimensions from (hl) inc hl ld b, (hl) inc hl ; Ready exx - ld hl, 0 ; HL = Offset "accumulator" + ld hl, 0 ; HL = Element Offset "accumulator" LOOP: -#line 64 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - pop bc ; Get next index (Ai) from the stack -#line 74 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - add hl, bc ; Adds current index + ex de, hl ; DE = Element Offset + ld hl, (LBOUND_PTR) + ld a, h + or l + ld b, h + ld c, l + jr z, 1f + ld c, (hl) + inc hl + ld b, (hl) + inc hl + ld (LBOUND_PTR), hl +1: + pop hl ; Get next index (Ai) from the stack + sbc hl, bc ; Subtract LBOUND +#line 116 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + add hl, de ; Adds current index exx ; Checks if B'C' = 0 ld a, b ; Which means we must exit (last element is not multiplied by anything) or c jr z, ARRAY_END ; if B'Ci == 0 we are done - ld e, (hl) ; Loads next dimension into D'E' + dec bc ; Decrements loop counter + ld e, (hl) ; Loads next dimension size into D'E' inc hl ld d, (hl) inc hl push de - dec bc ; Decrements loop counter exx pop de ; DE = Max bound Number (i-th dimension) - call __FNMUL + call __FNMUL ; HL <= HL * DE mod 65536 jp LOOP ARRAY_END: ld a, (hl) exx -#line 103 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 146 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl ld hl, 0 @@ -209,7 +234,7 @@ ARRAY_END: ARRAY_SIZE_LOOP: add hl, de djnz ARRAY_SIZE_LOOP -#line 113 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 156 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ex de, hl ld hl, (TMP_ARR_PTR) ld a, (hl) @@ -217,8 +242,9 @@ ARRAY_SIZE_LOOP: ld h, (hl) ld l, a add hl, de ; Adds element start -RET_ADDRESS: - jp 0 + ld de, (RET_ADDR) + push de + ret ;; Performs a faster multiply for little 16bit numbs LOCAL __FNMUL, __FNMUL2 __FNMUL: @@ -235,13 +261,11 @@ __FNMUL2: add hl, de djnz __FNMUL2 ret -TMP_ARR_PTR: - DW 0 ; temporary storage for pointer to tables ENDP pop namespace -#line 84 "local_str_array2.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/arrayalloc.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/calloc.asm" +#line 84 "arch/zx48k/local_str_array2.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/arrayalloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/calloc.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -252,7 +276,7 @@ TMP_ARR_PTR: ; closed source programs). ; ; Please read the MIT license on the internet -#line 1 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -312,7 +336,7 @@ TMP_ARR_PTR: ; HL = BLOCK Start & DE = Length. ; An init directive is useful for initialization routines. ; They will be added automatically if needed. -#line 1 "/zxbasic/src/arch/zx48k/library-asm/error.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/error.asm" ; Simple error control routines ; vim:ts=4:et: push namespace core @@ -346,8 +370,8 @@ __STOP: ld (ERR_NR), a ret pop namespace -#line 69 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/heapinit.asm" +#line 69 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/heapinit.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -454,7 +478,7 @@ __MEM_INIT2: ret ENDP pop namespace -#line 70 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 70 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; --------------------------------------------------------------------- ; MEM_ALLOC ; Allocates a block of memory in the heap. @@ -485,9 +509,9 @@ __MEM_START: __MEM_LOOP: ; Loads lengh at (HL, HL+). If Lenght >= BC, jump to __MEM_DONE ld a, h ; HL = NULL (No memory available?) or l -#line 113 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 113 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ret z ; NULL -#line 115 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 115 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; HL = Pointer to Free block ld e, (hl) inc hl @@ -552,7 +576,7 @@ __MEM_SUBTRACT: ret ENDP pop namespace -#line 13 "/zxbasic/src/arch/zx48k/library-asm/calloc.asm" +#line 13 "/zxbasic/src/lib/arch/zx48k/runtime/calloc.asm" ; --------------------------------------------------------------------- ; MEM_CALLOC ; Allocates a block of memory in the heap, and clears it filling it @@ -586,7 +610,7 @@ __MEM_CALLOC: pop hl ret pop namespace -#line 3 "/zxbasic/src/arch/zx48k/library-asm/arrayalloc.asm" +#line 3 "/zxbasic/src/lib/arch/zx48k/runtime/arrayalloc.asm" ; --------------------------------------------------------------------- ; __ALLOC_LOCAL_ARRAY ; Allocates an array element area in the heap, and clears it filling it @@ -650,14 +674,14 @@ __ALLOC_INITIALIZED_LOCAL_ARRAY: ldir pop hl ; HL = addr of LBound area if used ret -#line 139 "/zxbasic/src/arch/zx48k/library-asm/arrayalloc.asm" +#line 139 "/zxbasic/src/lib/arch/zx48k/runtime/arrayalloc.asm" pop namespace -#line 85 "local_str_array2.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/arraystrfree.asm" +#line 85 "arch/zx48k/local_str_array2.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/arraystrfree.asm" ; This routine is in charge of freeing an array of strings from memory ; HL = Pointer to start of array in memory ; Top of the stack = Number of elements of the array -#line 1 "/zxbasic/src/arch/zx48k/library-asm/free.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/free.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -815,7 +839,7 @@ __MEM_BLOCK_JOIN: ; Joins current block (pointed by HL) with next one (pointed ret ENDP pop namespace -#line 6 "/zxbasic/src/arch/zx48k/library-asm/arraystrfree.asm" +#line 6 "/zxbasic/src/lib/arch/zx48k/runtime/arraystrfree.asm" push namespace core __ARRAYSTR_FREE: PROC @@ -857,8 +881,8 @@ __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 86 "local_str_array2.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/loadstr.asm" +#line 86 "arch/zx48k/local_str_array2.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/loadstr.asm" ; Loads a string (ptr) from HL ; and duplicates it on dynamic memory again ; Finally, it returns result pointer in HL @@ -895,8 +919,8 @@ __LOADSTR: ; __FASTCALL__ entry pop hl ; Recovers destiny in hl as result ret pop namespace -#line 88 "local_str_array2.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/storestr2.asm" +#line 88 "arch/zx48k/local_str_array2.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/storestr2.asm" ; Similar to __STORE_STR, but this one is called when ; the value of B$ if already duplicated onto the stack. ; So we needn't call STRASSING to create a duplication @@ -929,7 +953,7 @@ __STORE_STR2: dec hl ; HL points to mem address variable. This might be useful in the future. ret pop namespace -#line 89 "local_str_array2.bas" +#line 89 "arch/zx48k/local_str_array2.bas" .LABEL.__LABEL1: DEFB 01h DEFB 00h diff --git a/tests/functional/arch/zx48k/local_str_array3.asm b/tests/functional/arch/zx48k/local_str_array3.asm index 68851d1be..ef82556fd 100644 --- a/tests/functional/arch/zx48k/local_str_array3.asm +++ b/tests/functional/arch/zx48k/local_str_array3.asm @@ -126,7 +126,7 @@ _test__leave: DEFB 44h DEFB 20h ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -142,7 +142,7 @@ _test__leave: ; O = [a0 + b0 * (a1 + b1 * (a2 + ... bN-2(aN-1)))] ; What I will do here is to calculate the following sequence: ; ((aN-1 * bN-2) + aN-2) * bN-3 + ... -#line 1 "/zxbasic/src/arch/zx48k/library-asm/mul16.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/mul16.asm" push namespace core __MUL16: ; Mutiplies HL with the last value stored into de stack ; Works for both signed and unsigned @@ -168,59 +168,84 @@ __MUL16NOADD: ret ; Result in hl (16 lower bits) ENDP pop namespace -#line 20 "/zxbasic/src/arch/zx48k/library-asm/array.asm" -#line 24 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 20 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 24 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" push namespace core __ARRAY_PTR: ;; computes an array offset from a pointer ld c, (hl) inc hl ld h, (hl) - ld l, c + ld l, c ;; HL <-- [HL] __ARRAY: PROC LOCAL LOOP LOCAL ARRAY_END - LOCAL RET_ADDRESS ; Stores return address - LOCAL TMP_ARR_PTR ; Stores pointer temporarily + LOCAL TMP_ARR_PTR ; Ptr to Array DATA region. Stored temporarily + LOCAL LBOUND_PTR, UBOUND_PTR ; LBound and UBound PTR indexes + LOCAL RET_ADDR ; Contains the return address popped from the stack + LBOUND_PTR EQU 23698 ; Uses MEMBOT as a temporary variable + UBOUND_PTR EQU LBOUND_PTR + 2 ; Next 2 bytes for UBOUND PTR + RET_ADDR EQU UBOUND_PTR + 2 ; Next 2 bytes for RET_ADDR + TMP_ARR_PTR EQU RET_ADDR + 2 ; Next 2 bytes for TMP_ARR_PTR ld e, (hl) inc hl ld d, (hl) + inc hl ; DE <-- PTR to Dim sizes table + ld (TMP_ARR_PTR), hl ; HL = Array __DATA__.__PTR__ inc hl - ld (TMP_ARR_PTR), hl - ex de, hl - ex (sp), hl ; Return address in HL, array address in the stack - ld (RET_ADDRESS + 1), hl ; Stores it for later + inc hl + ld c, (hl) + inc hl + ld b, (hl) ; BC <-- Array __LBOUND__ PTR + ld (LBOUND_PTR), bc ; Store it for later +#line 66 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + ex de, hl ; HL <-- PTR to Dim sizes table, DE <-- dummy + ex (sp), hl ; Return address in HL, PTR Dim sizes table onto Stack + ld (RET_ADDR), hl ; Stores it for later exx - pop hl ; Will use H'L' as the pointer + pop hl ; Will use H'L' as the pointer to Dim sizes table ld c, (hl) ; Loads Number of dimensions from (hl) inc hl ld b, (hl) inc hl ; Ready exx - ld hl, 0 ; HL = Offset "accumulator" + ld hl, 0 ; HL = Element Offset "accumulator" LOOP: -#line 64 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - pop bc ; Get next index (Ai) from the stack -#line 74 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - add hl, bc ; Adds current index + ex de, hl ; DE = Element Offset + ld hl, (LBOUND_PTR) + ld a, h + or l + ld b, h + ld c, l + jr z, 1f + ld c, (hl) + inc hl + ld b, (hl) + inc hl + ld (LBOUND_PTR), hl +1: + pop hl ; Get next index (Ai) from the stack + sbc hl, bc ; Subtract LBOUND +#line 116 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + add hl, de ; Adds current index exx ; Checks if B'C' = 0 ld a, b ; Which means we must exit (last element is not multiplied by anything) or c jr z, ARRAY_END ; if B'Ci == 0 we are done - ld e, (hl) ; Loads next dimension into D'E' + dec bc ; Decrements loop counter + ld e, (hl) ; Loads next dimension size into D'E' inc hl ld d, (hl) inc hl push de - dec bc ; Decrements loop counter exx pop de ; DE = Max bound Number (i-th dimension) - call __FNMUL + call __FNMUL ; HL <= HL * DE mod 65536 jp LOOP ARRAY_END: ld a, (hl) exx -#line 103 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 146 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl ld hl, 0 @@ -228,7 +253,7 @@ ARRAY_END: ARRAY_SIZE_LOOP: add hl, de djnz ARRAY_SIZE_LOOP -#line 113 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 156 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ex de, hl ld hl, (TMP_ARR_PTR) ld a, (hl) @@ -236,8 +261,9 @@ ARRAY_SIZE_LOOP: ld h, (hl) ld l, a add hl, de ; Adds element start -RET_ADDRESS: - jp 0 + ld de, (RET_ADDR) + push de + ret ;; Performs a faster multiply for little 16bit numbs LOCAL __FNMUL, __FNMUL2 __FNMUL: @@ -254,13 +280,11 @@ __FNMUL2: add hl, de djnz __FNMUL2 ret -TMP_ARR_PTR: - DW 0 ; temporary storage for pointer to tables ENDP pop namespace -#line 103 "local_str_array3.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/arrayalloc.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/calloc.asm" +#line 103 "arch/zx48k/local_str_array3.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/arrayalloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/calloc.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -271,7 +295,7 @@ TMP_ARR_PTR: ; closed source programs). ; ; Please read the MIT license on the internet -#line 1 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -331,7 +355,7 @@ TMP_ARR_PTR: ; HL = BLOCK Start & DE = Length. ; An init directive is useful for initialization routines. ; They will be added automatically if needed. -#line 1 "/zxbasic/src/arch/zx48k/library-asm/error.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/error.asm" ; Simple error control routines ; vim:ts=4:et: push namespace core @@ -365,8 +389,8 @@ __STOP: ld (ERR_NR), a ret pop namespace -#line 69 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/heapinit.asm" +#line 69 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/heapinit.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -473,7 +497,7 @@ __MEM_INIT2: ret ENDP pop namespace -#line 70 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 70 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; --------------------------------------------------------------------- ; MEM_ALLOC ; Allocates a block of memory in the heap. @@ -504,9 +528,9 @@ __MEM_START: __MEM_LOOP: ; Loads lengh at (HL, HL+). If Lenght >= BC, jump to __MEM_DONE ld a, h ; HL = NULL (No memory available?) or l -#line 113 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 113 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ret z ; NULL -#line 115 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 115 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; HL = Pointer to Free block ld e, (hl) inc hl @@ -571,7 +595,7 @@ __MEM_SUBTRACT: ret ENDP pop namespace -#line 13 "/zxbasic/src/arch/zx48k/library-asm/calloc.asm" +#line 13 "/zxbasic/src/lib/arch/zx48k/runtime/calloc.asm" ; --------------------------------------------------------------------- ; MEM_CALLOC ; Allocates a block of memory in the heap, and clears it filling it @@ -605,7 +629,7 @@ __MEM_CALLOC: pop hl ret pop namespace -#line 3 "/zxbasic/src/arch/zx48k/library-asm/arrayalloc.asm" +#line 3 "/zxbasic/src/lib/arch/zx48k/runtime/arrayalloc.asm" ; --------------------------------------------------------------------- ; __ALLOC_LOCAL_ARRAY ; Allocates an array element area in the heap, and clears it filling it @@ -669,14 +693,14 @@ __ALLOC_INITIALIZED_LOCAL_ARRAY: ldir pop hl ; HL = addr of LBound area if used ret -#line 139 "/zxbasic/src/arch/zx48k/library-asm/arrayalloc.asm" +#line 139 "/zxbasic/src/lib/arch/zx48k/runtime/arrayalloc.asm" pop namespace -#line 104 "local_str_array3.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/arraystrfree.asm" +#line 104 "arch/zx48k/local_str_array3.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/arraystrfree.asm" ; This routine is in charge of freeing an array of strings from memory ; HL = Pointer to start of array in memory ; Top of the stack = Number of elements of the array -#line 1 "/zxbasic/src/arch/zx48k/library-asm/free.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/free.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -834,7 +858,7 @@ __MEM_BLOCK_JOIN: ; Joins current block (pointed by HL) with next one (pointed ret ENDP pop namespace -#line 6 "/zxbasic/src/arch/zx48k/library-asm/arraystrfree.asm" +#line 6 "/zxbasic/src/lib/arch/zx48k/runtime/arraystrfree.asm" push namespace core __ARRAYSTR_FREE: PROC @@ -876,8 +900,8 @@ __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 105 "local_str_array3.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/loadstr.asm" +#line 105 "arch/zx48k/local_str_array3.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/loadstr.asm" ; Loads a string (ptr) from HL ; and duplicates it on dynamic memory again ; Finally, it returns result pointer in HL @@ -914,8 +938,8 @@ __LOADSTR: ; __FASTCALL__ entry pop hl ; Recovers destiny in hl as result ret pop namespace -#line 107 "local_str_array3.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/storestr2.asm" +#line 107 "arch/zx48k/local_str_array3.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/storestr2.asm" ; Similar to __STORE_STR, but this one is called when ; the value of B$ if already duplicated onto the stack. ; So we needn't call STRASSING to create a duplication @@ -948,7 +972,7 @@ __STORE_STR2: dec hl ; HL points to mem address variable. This might be useful in the future. ret pop namespace -#line 108 "local_str_array3.bas" +#line 108 "arch/zx48k/local_str_array3.bas" .LABEL.__LABEL6: DEFB 00h DEFB 00h diff --git a/tests/functional/arch/zx48k/local_u16_array1.asm b/tests/functional/arch/zx48k/local_u16_array1.asm index e18250dff..ff6575e63 100644 --- a/tests/functional/arch/zx48k/local_u16_array1.asm +++ b/tests/functional/arch/zx48k/local_u16_array1.asm @@ -88,7 +88,7 @@ _test__leave: pop ix ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -104,7 +104,7 @@ _test__leave: ; O = [a0 + b0 * (a1 + b1 * (a2 + ... bN-2(aN-1)))] ; What I will do here is to calculate the following sequence: ; ((aN-1 * bN-2) + aN-2) * bN-3 + ... -#line 1 "/zxbasic/src/arch/zx48k/library-asm/mul16.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/mul16.asm" push namespace core __MUL16: ; Mutiplies HL with the last value stored into de stack ; Works for both signed and unsigned @@ -130,59 +130,84 @@ __MUL16NOADD: ret ; Result in hl (16 lower bits) ENDP pop namespace -#line 20 "/zxbasic/src/arch/zx48k/library-asm/array.asm" -#line 24 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 20 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 24 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" push namespace core __ARRAY_PTR: ;; computes an array offset from a pointer ld c, (hl) inc hl ld h, (hl) - ld l, c + ld l, c ;; HL <-- [HL] __ARRAY: PROC LOCAL LOOP LOCAL ARRAY_END - LOCAL RET_ADDRESS ; Stores return address - LOCAL TMP_ARR_PTR ; Stores pointer temporarily + LOCAL TMP_ARR_PTR ; Ptr to Array DATA region. Stored temporarily + LOCAL LBOUND_PTR, UBOUND_PTR ; LBound and UBound PTR indexes + LOCAL RET_ADDR ; Contains the return address popped from the stack + LBOUND_PTR EQU 23698 ; Uses MEMBOT as a temporary variable + UBOUND_PTR EQU LBOUND_PTR + 2 ; Next 2 bytes for UBOUND PTR + RET_ADDR EQU UBOUND_PTR + 2 ; Next 2 bytes for RET_ADDR + TMP_ARR_PTR EQU RET_ADDR + 2 ; Next 2 bytes for TMP_ARR_PTR ld e, (hl) inc hl ld d, (hl) + inc hl ; DE <-- PTR to Dim sizes table + ld (TMP_ARR_PTR), hl ; HL = Array __DATA__.__PTR__ inc hl - ld (TMP_ARR_PTR), hl - ex de, hl - ex (sp), hl ; Return address in HL, array address in the stack - ld (RET_ADDRESS + 1), hl ; Stores it for later + inc hl + ld c, (hl) + inc hl + ld b, (hl) ; BC <-- Array __LBOUND__ PTR + ld (LBOUND_PTR), bc ; Store it for later +#line 66 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + ex de, hl ; HL <-- PTR to Dim sizes table, DE <-- dummy + ex (sp), hl ; Return address in HL, PTR Dim sizes table onto Stack + ld (RET_ADDR), hl ; Stores it for later exx - pop hl ; Will use H'L' as the pointer + pop hl ; Will use H'L' as the pointer to Dim sizes table ld c, (hl) ; Loads Number of dimensions from (hl) inc hl ld b, (hl) inc hl ; Ready exx - ld hl, 0 ; HL = Offset "accumulator" + ld hl, 0 ; HL = Element Offset "accumulator" LOOP: -#line 64 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - pop bc ; Get next index (Ai) from the stack -#line 74 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - add hl, bc ; Adds current index + ex de, hl ; DE = Element Offset + ld hl, (LBOUND_PTR) + ld a, h + or l + ld b, h + ld c, l + jr z, 1f + ld c, (hl) + inc hl + ld b, (hl) + inc hl + ld (LBOUND_PTR), hl +1: + pop hl ; Get next index (Ai) from the stack + sbc hl, bc ; Subtract LBOUND +#line 116 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + add hl, de ; Adds current index exx ; Checks if B'C' = 0 ld a, b ; Which means we must exit (last element is not multiplied by anything) or c jr z, ARRAY_END ; if B'Ci == 0 we are done - ld e, (hl) ; Loads next dimension into D'E' + dec bc ; Decrements loop counter + ld e, (hl) ; Loads next dimension size into D'E' inc hl ld d, (hl) inc hl push de - dec bc ; Decrements loop counter exx pop de ; DE = Max bound Number (i-th dimension) - call __FNMUL + call __FNMUL ; HL <= HL * DE mod 65536 jp LOOP ARRAY_END: ld a, (hl) exx -#line 103 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 146 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl ld hl, 0 @@ -190,7 +215,7 @@ ARRAY_END: ARRAY_SIZE_LOOP: add hl, de djnz ARRAY_SIZE_LOOP -#line 113 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 156 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ex de, hl ld hl, (TMP_ARR_PTR) ld a, (hl) @@ -198,8 +223,9 @@ ARRAY_SIZE_LOOP: ld h, (hl) ld l, a add hl, de ; Adds element start -RET_ADDRESS: - jp 0 + ld de, (RET_ADDR) + push de + ret ;; Performs a faster multiply for little 16bit numbs LOCAL __FNMUL, __FNMUL2 __FNMUL: @@ -216,13 +242,11 @@ __FNMUL2: add hl, de djnz __FNMUL2 ret -TMP_ARR_PTR: - DW 0 ; temporary storage for pointer to tables ENDP pop namespace -#line 62 "local_u16_array1.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/arrayalloc.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/calloc.asm" +#line 62 "arch/zx48k/local_u16_array1.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/arrayalloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/calloc.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -233,7 +257,7 @@ TMP_ARR_PTR: ; closed source programs). ; ; Please read the MIT license on the internet -#line 1 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -293,7 +317,7 @@ TMP_ARR_PTR: ; HL = BLOCK Start & DE = Length. ; An init directive is useful for initialization routines. ; They will be added automatically if needed. -#line 1 "/zxbasic/src/arch/zx48k/library-asm/error.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/error.asm" ; Simple error control routines ; vim:ts=4:et: push namespace core @@ -327,8 +351,8 @@ __STOP: ld (ERR_NR), a ret pop namespace -#line 69 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/heapinit.asm" +#line 69 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/heapinit.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -435,7 +459,7 @@ __MEM_INIT2: ret ENDP pop namespace -#line 70 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 70 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; --------------------------------------------------------------------- ; MEM_ALLOC ; Allocates a block of memory in the heap. @@ -466,9 +490,9 @@ __MEM_START: __MEM_LOOP: ; Loads lengh at (HL, HL+). If Lenght >= BC, jump to __MEM_DONE ld a, h ; HL = NULL (No memory available?) or l -#line 113 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 113 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ret z ; NULL -#line 115 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 115 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; HL = Pointer to Free block ld e, (hl) inc hl @@ -533,7 +557,7 @@ __MEM_SUBTRACT: ret ENDP pop namespace -#line 13 "/zxbasic/src/arch/zx48k/library-asm/calloc.asm" +#line 13 "/zxbasic/src/lib/arch/zx48k/runtime/calloc.asm" ; --------------------------------------------------------------------- ; MEM_CALLOC ; Allocates a block of memory in the heap, and clears it filling it @@ -567,7 +591,7 @@ __MEM_CALLOC: pop hl ret pop namespace -#line 3 "/zxbasic/src/arch/zx48k/library-asm/arrayalloc.asm" +#line 3 "/zxbasic/src/lib/arch/zx48k/runtime/arrayalloc.asm" ; --------------------------------------------------------------------- ; __ALLOC_LOCAL_ARRAY ; Allocates an array element area in the heap, and clears it filling it @@ -631,10 +655,10 @@ __ALLOC_INITIALIZED_LOCAL_ARRAY: ldir pop hl ; HL = addr of LBound area if used ret -#line 139 "/zxbasic/src/arch/zx48k/library-asm/arrayalloc.asm" +#line 139 "/zxbasic/src/lib/arch/zx48k/runtime/arrayalloc.asm" pop namespace -#line 63 "local_u16_array1.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/free.asm" +#line 63 "arch/zx48k/local_u16_array1.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/free.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -792,7 +816,7 @@ __MEM_BLOCK_JOIN: ; Joins current block (pointed by HL) with next one (pointed ret ENDP pop namespace -#line 64 "local_u16_array1.bas" +#line 64 "arch/zx48k/local_u16_array1.bas" .LABEL.__LABEL0: DEFB 00h DEFB 00h diff --git a/tests/functional/arch/zx48k/local_u16_array2.asm b/tests/functional/arch/zx48k/local_u16_array2.asm index d463a05f6..937b05ef6 100644 --- a/tests/functional/arch/zx48k/local_u16_array2.asm +++ b/tests/functional/arch/zx48k/local_u16_array2.asm @@ -96,7 +96,7 @@ _test__leave: pop ix ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -112,7 +112,7 @@ _test__leave: ; O = [a0 + b0 * (a1 + b1 * (a2 + ... bN-2(aN-1)))] ; What I will do here is to calculate the following sequence: ; ((aN-1 * bN-2) + aN-2) * bN-3 + ... -#line 1 "/zxbasic/src/arch/zx48k/library-asm/mul16.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/mul16.asm" push namespace core __MUL16: ; Mutiplies HL with the last value stored into de stack ; Works for both signed and unsigned @@ -138,59 +138,84 @@ __MUL16NOADD: ret ; Result in hl (16 lower bits) ENDP pop namespace -#line 20 "/zxbasic/src/arch/zx48k/library-asm/array.asm" -#line 24 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 20 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 24 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" push namespace core __ARRAY_PTR: ;; computes an array offset from a pointer ld c, (hl) inc hl ld h, (hl) - ld l, c + ld l, c ;; HL <-- [HL] __ARRAY: PROC LOCAL LOOP LOCAL ARRAY_END - LOCAL RET_ADDRESS ; Stores return address - LOCAL TMP_ARR_PTR ; Stores pointer temporarily + LOCAL TMP_ARR_PTR ; Ptr to Array DATA region. Stored temporarily + LOCAL LBOUND_PTR, UBOUND_PTR ; LBound and UBound PTR indexes + LOCAL RET_ADDR ; Contains the return address popped from the stack + LBOUND_PTR EQU 23698 ; Uses MEMBOT as a temporary variable + UBOUND_PTR EQU LBOUND_PTR + 2 ; Next 2 bytes for UBOUND PTR + RET_ADDR EQU UBOUND_PTR + 2 ; Next 2 bytes for RET_ADDR + TMP_ARR_PTR EQU RET_ADDR + 2 ; Next 2 bytes for TMP_ARR_PTR ld e, (hl) inc hl ld d, (hl) + inc hl ; DE <-- PTR to Dim sizes table + ld (TMP_ARR_PTR), hl ; HL = Array __DATA__.__PTR__ inc hl - ld (TMP_ARR_PTR), hl - ex de, hl - ex (sp), hl ; Return address in HL, array address in the stack - ld (RET_ADDRESS + 1), hl ; Stores it for later + inc hl + ld c, (hl) + inc hl + ld b, (hl) ; BC <-- Array __LBOUND__ PTR + ld (LBOUND_PTR), bc ; Store it for later +#line 66 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + ex de, hl ; HL <-- PTR to Dim sizes table, DE <-- dummy + ex (sp), hl ; Return address in HL, PTR Dim sizes table onto Stack + ld (RET_ADDR), hl ; Stores it for later exx - pop hl ; Will use H'L' as the pointer + pop hl ; Will use H'L' as the pointer to Dim sizes table ld c, (hl) ; Loads Number of dimensions from (hl) inc hl ld b, (hl) inc hl ; Ready exx - ld hl, 0 ; HL = Offset "accumulator" + ld hl, 0 ; HL = Element Offset "accumulator" LOOP: -#line 64 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - pop bc ; Get next index (Ai) from the stack -#line 74 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - add hl, bc ; Adds current index + ex de, hl ; DE = Element Offset + ld hl, (LBOUND_PTR) + ld a, h + or l + ld b, h + ld c, l + jr z, 1f + ld c, (hl) + inc hl + ld b, (hl) + inc hl + ld (LBOUND_PTR), hl +1: + pop hl ; Get next index (Ai) from the stack + sbc hl, bc ; Subtract LBOUND +#line 116 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + add hl, de ; Adds current index exx ; Checks if B'C' = 0 ld a, b ; Which means we must exit (last element is not multiplied by anything) or c jr z, ARRAY_END ; if B'Ci == 0 we are done - ld e, (hl) ; Loads next dimension into D'E' + dec bc ; Decrements loop counter + ld e, (hl) ; Loads next dimension size into D'E' inc hl ld d, (hl) inc hl push de - dec bc ; Decrements loop counter exx pop de ; DE = Max bound Number (i-th dimension) - call __FNMUL + call __FNMUL ; HL <= HL * DE mod 65536 jp LOOP ARRAY_END: ld a, (hl) exx -#line 103 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 146 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl ld hl, 0 @@ -198,7 +223,7 @@ ARRAY_END: ARRAY_SIZE_LOOP: add hl, de djnz ARRAY_SIZE_LOOP -#line 113 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 156 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ex de, hl ld hl, (TMP_ARR_PTR) ld a, (hl) @@ -206,8 +231,9 @@ ARRAY_SIZE_LOOP: ld h, (hl) ld l, a add hl, de ; Adds element start -RET_ADDRESS: - jp 0 + ld de, (RET_ADDR) + push de + ret ;; Performs a faster multiply for little 16bit numbs LOCAL __FNMUL, __FNMUL2 __FNMUL: @@ -224,13 +250,11 @@ __FNMUL2: add hl, de djnz __FNMUL2 ret -TMP_ARR_PTR: - DW 0 ; temporary storage for pointer to tables ENDP pop namespace -#line 73 "local_u16_array2.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/arrayalloc.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/calloc.asm" +#line 73 "arch/zx48k/local_u16_array2.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/arrayalloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/calloc.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -241,7 +265,7 @@ TMP_ARR_PTR: ; closed source programs). ; ; Please read the MIT license on the internet -#line 1 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -301,7 +325,7 @@ TMP_ARR_PTR: ; HL = BLOCK Start & DE = Length. ; An init directive is useful for initialization routines. ; They will be added automatically if needed. -#line 1 "/zxbasic/src/arch/zx48k/library-asm/error.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/error.asm" ; Simple error control routines ; vim:ts=4:et: push namespace core @@ -335,8 +359,8 @@ __STOP: ld (ERR_NR), a ret pop namespace -#line 69 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/heapinit.asm" +#line 69 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/heapinit.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -443,7 +467,7 @@ __MEM_INIT2: ret ENDP pop namespace -#line 70 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 70 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; --------------------------------------------------------------------- ; MEM_ALLOC ; Allocates a block of memory in the heap. @@ -474,9 +498,9 @@ __MEM_START: __MEM_LOOP: ; Loads lengh at (HL, HL+). If Lenght >= BC, jump to __MEM_DONE ld a, h ; HL = NULL (No memory available?) or l -#line 113 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 113 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ret z ; NULL -#line 115 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 115 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; HL = Pointer to Free block ld e, (hl) inc hl @@ -541,7 +565,7 @@ __MEM_SUBTRACT: ret ENDP pop namespace -#line 13 "/zxbasic/src/arch/zx48k/library-asm/calloc.asm" +#line 13 "/zxbasic/src/lib/arch/zx48k/runtime/calloc.asm" ; --------------------------------------------------------------------- ; MEM_CALLOC ; Allocates a block of memory in the heap, and clears it filling it @@ -575,7 +599,7 @@ __MEM_CALLOC: pop hl ret pop namespace -#line 3 "/zxbasic/src/arch/zx48k/library-asm/arrayalloc.asm" +#line 3 "/zxbasic/src/lib/arch/zx48k/runtime/arrayalloc.asm" ; --------------------------------------------------------------------- ; __ALLOC_LOCAL_ARRAY ; Allocates an array element area in the heap, and clears it filling it @@ -639,10 +663,10 @@ __ALLOC_INITIALIZED_LOCAL_ARRAY: ldir pop hl ; HL = addr of LBound area if used ret -#line 139 "/zxbasic/src/arch/zx48k/library-asm/arrayalloc.asm" +#line 139 "/zxbasic/src/lib/arch/zx48k/runtime/arrayalloc.asm" pop namespace -#line 74 "local_u16_array2.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/free.asm" +#line 74 "arch/zx48k/local_u16_array2.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/free.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -800,7 +824,7 @@ __MEM_BLOCK_JOIN: ; Joins current block (pointed by HL) with next one (pointed ret ENDP pop namespace -#line 75 "local_u16_array2.bas" +#line 75 "arch/zx48k/local_u16_array2.bas" .LABEL.__LABEL0: DEFB 01h DEFB 00h diff --git a/tests/functional/arch/zx48k/local_u16_array3.asm b/tests/functional/arch/zx48k/local_u16_array3.asm index 00e4acb7a..57bc7a5ef 100644 --- a/tests/functional/arch/zx48k/local_u16_array3.asm +++ b/tests/functional/arch/zx48k/local_u16_array3.asm @@ -118,7 +118,7 @@ _test__leave: exx ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -134,7 +134,7 @@ _test__leave: ; O = [a0 + b0 * (a1 + b1 * (a2 + ... bN-2(aN-1)))] ; What I will do here is to calculate the following sequence: ; ((aN-1 * bN-2) + aN-2) * bN-3 + ... -#line 1 "/zxbasic/src/arch/zx48k/library-asm/mul16.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/mul16.asm" push namespace core __MUL16: ; Mutiplies HL with the last value stored into de stack ; Works for both signed and unsigned @@ -160,59 +160,84 @@ __MUL16NOADD: ret ; Result in hl (16 lower bits) ENDP pop namespace -#line 20 "/zxbasic/src/arch/zx48k/library-asm/array.asm" -#line 24 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 20 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 24 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" push namespace core __ARRAY_PTR: ;; computes an array offset from a pointer ld c, (hl) inc hl ld h, (hl) - ld l, c + ld l, c ;; HL <-- [HL] __ARRAY: PROC LOCAL LOOP LOCAL ARRAY_END - LOCAL RET_ADDRESS ; Stores return address - LOCAL TMP_ARR_PTR ; Stores pointer temporarily + LOCAL TMP_ARR_PTR ; Ptr to Array DATA region. Stored temporarily + LOCAL LBOUND_PTR, UBOUND_PTR ; LBound and UBound PTR indexes + LOCAL RET_ADDR ; Contains the return address popped from the stack + LBOUND_PTR EQU 23698 ; Uses MEMBOT as a temporary variable + UBOUND_PTR EQU LBOUND_PTR + 2 ; Next 2 bytes for UBOUND PTR + RET_ADDR EQU UBOUND_PTR + 2 ; Next 2 bytes for RET_ADDR + TMP_ARR_PTR EQU RET_ADDR + 2 ; Next 2 bytes for TMP_ARR_PTR ld e, (hl) inc hl ld d, (hl) + inc hl ; DE <-- PTR to Dim sizes table + ld (TMP_ARR_PTR), hl ; HL = Array __DATA__.__PTR__ inc hl - ld (TMP_ARR_PTR), hl - ex de, hl - ex (sp), hl ; Return address in HL, array address in the stack - ld (RET_ADDRESS + 1), hl ; Stores it for later + inc hl + ld c, (hl) + inc hl + ld b, (hl) ; BC <-- Array __LBOUND__ PTR + ld (LBOUND_PTR), bc ; Store it for later +#line 66 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + ex de, hl ; HL <-- PTR to Dim sizes table, DE <-- dummy + ex (sp), hl ; Return address in HL, PTR Dim sizes table onto Stack + ld (RET_ADDR), hl ; Stores it for later exx - pop hl ; Will use H'L' as the pointer + pop hl ; Will use H'L' as the pointer to Dim sizes table ld c, (hl) ; Loads Number of dimensions from (hl) inc hl ld b, (hl) inc hl ; Ready exx - ld hl, 0 ; HL = Offset "accumulator" + ld hl, 0 ; HL = Element Offset "accumulator" LOOP: -#line 64 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - pop bc ; Get next index (Ai) from the stack -#line 74 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - add hl, bc ; Adds current index + ex de, hl ; DE = Element Offset + ld hl, (LBOUND_PTR) + ld a, h + or l + ld b, h + ld c, l + jr z, 1f + ld c, (hl) + inc hl + ld b, (hl) + inc hl + ld (LBOUND_PTR), hl +1: + pop hl ; Get next index (Ai) from the stack + sbc hl, bc ; Subtract LBOUND +#line 116 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + add hl, de ; Adds current index exx ; Checks if B'C' = 0 ld a, b ; Which means we must exit (last element is not multiplied by anything) or c jr z, ARRAY_END ; if B'Ci == 0 we are done - ld e, (hl) ; Loads next dimension into D'E' + dec bc ; Decrements loop counter + ld e, (hl) ; Loads next dimension size into D'E' inc hl ld d, (hl) inc hl push de - dec bc ; Decrements loop counter exx pop de ; DE = Max bound Number (i-th dimension) - call __FNMUL + call __FNMUL ; HL <= HL * DE mod 65536 jp LOOP ARRAY_END: ld a, (hl) exx -#line 103 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 146 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl ld hl, 0 @@ -220,7 +245,7 @@ ARRAY_END: ARRAY_SIZE_LOOP: add hl, de djnz ARRAY_SIZE_LOOP -#line 113 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 156 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ex de, hl ld hl, (TMP_ARR_PTR) ld a, (hl) @@ -228,8 +253,9 @@ ARRAY_SIZE_LOOP: ld h, (hl) ld l, a add hl, de ; Adds element start -RET_ADDRESS: - jp 0 + ld de, (RET_ADDR) + push de + ret ;; Performs a faster multiply for little 16bit numbs LOCAL __FNMUL, __FNMUL2 __FNMUL: @@ -246,13 +272,11 @@ __FNMUL2: add hl, de djnz __FNMUL2 ret -TMP_ARR_PTR: - DW 0 ; temporary storage for pointer to tables ENDP pop namespace -#line 95 "local_u16_array3.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/arrayalloc.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/calloc.asm" +#line 95 "arch/zx48k/local_u16_array3.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/arrayalloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/calloc.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -263,7 +287,7 @@ TMP_ARR_PTR: ; closed source programs). ; ; Please read the MIT license on the internet -#line 1 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -323,7 +347,7 @@ TMP_ARR_PTR: ; HL = BLOCK Start & DE = Length. ; An init directive is useful for initialization routines. ; They will be added automatically if needed. -#line 1 "/zxbasic/src/arch/zx48k/library-asm/error.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/error.asm" ; Simple error control routines ; vim:ts=4:et: push namespace core @@ -357,8 +381,8 @@ __STOP: ld (ERR_NR), a ret pop namespace -#line 69 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/heapinit.asm" +#line 69 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/heapinit.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -465,7 +489,7 @@ __MEM_INIT2: ret ENDP pop namespace -#line 70 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 70 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; --------------------------------------------------------------------- ; MEM_ALLOC ; Allocates a block of memory in the heap. @@ -496,9 +520,9 @@ __MEM_START: __MEM_LOOP: ; Loads lengh at (HL, HL+). If Lenght >= BC, jump to __MEM_DONE ld a, h ; HL = NULL (No memory available?) or l -#line 113 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 113 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ret z ; NULL -#line 115 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 115 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; HL = Pointer to Free block ld e, (hl) inc hl @@ -563,7 +587,7 @@ __MEM_SUBTRACT: ret ENDP pop namespace -#line 13 "/zxbasic/src/arch/zx48k/library-asm/calloc.asm" +#line 13 "/zxbasic/src/lib/arch/zx48k/runtime/calloc.asm" ; --------------------------------------------------------------------- ; MEM_CALLOC ; Allocates a block of memory in the heap, and clears it filling it @@ -597,7 +621,7 @@ __MEM_CALLOC: pop hl ret pop namespace -#line 3 "/zxbasic/src/arch/zx48k/library-asm/arrayalloc.asm" +#line 3 "/zxbasic/src/lib/arch/zx48k/runtime/arrayalloc.asm" ; --------------------------------------------------------------------- ; __ALLOC_LOCAL_ARRAY ; Allocates an array element area in the heap, and clears it filling it @@ -661,10 +685,10 @@ __ALLOC_INITIALIZED_LOCAL_ARRAY: ldir pop hl ; HL = addr of LBound area if used ret -#line 139 "/zxbasic/src/arch/zx48k/library-asm/arrayalloc.asm" +#line 139 "/zxbasic/src/lib/arch/zx48k/runtime/arrayalloc.asm" pop namespace -#line 96 "local_u16_array3.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/free.asm" +#line 96 "arch/zx48k/local_u16_array3.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/free.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -822,7 +846,7 @@ __MEM_BLOCK_JOIN: ; Joins current block (pointed by HL) with next one (pointed ret ENDP pop namespace -#line 97 "local_u16_array3.bas" +#line 97 "arch/zx48k/local_u16_array3.bas" .LABEL.__LABEL5: DEFB 00h DEFB 00h diff --git a/tests/functional/arch/zx48k/ltee10.asm b/tests/functional/arch/zx48k/ltee10.asm index 7f160fc03..0dcf855ca 100644 --- a/tests/functional/arch/zx48k/ltee10.asm +++ b/tests/functional/arch/zx48k/ltee10.asm @@ -76,7 +76,7 @@ _setlocal__leave: pop ix ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -92,7 +92,7 @@ _setlocal__leave: ; O = [a0 + b0 * (a1 + b1 * (a2 + ... bN-2(aN-1)))] ; What I will do here is to calculate the following sequence: ; ((aN-1 * bN-2) + aN-2) * bN-3 + ... -#line 1 "/zxbasic/src/arch/zx48k/library-asm/mul16.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/mul16.asm" push namespace core __MUL16: ; Mutiplies HL with the last value stored into de stack ; Works for both signed and unsigned @@ -118,59 +118,84 @@ __MUL16NOADD: ret ; Result in hl (16 lower bits) ENDP pop namespace -#line 20 "/zxbasic/src/arch/zx48k/library-asm/array.asm" -#line 24 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 20 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 24 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" push namespace core __ARRAY_PTR: ;; computes an array offset from a pointer ld c, (hl) inc hl ld h, (hl) - ld l, c + ld l, c ;; HL <-- [HL] __ARRAY: PROC LOCAL LOOP LOCAL ARRAY_END - LOCAL RET_ADDRESS ; Stores return address - LOCAL TMP_ARR_PTR ; Stores pointer temporarily + LOCAL TMP_ARR_PTR ; Ptr to Array DATA region. Stored temporarily + LOCAL LBOUND_PTR, UBOUND_PTR ; LBound and UBound PTR indexes + LOCAL RET_ADDR ; Contains the return address popped from the stack + LBOUND_PTR EQU 23698 ; Uses MEMBOT as a temporary variable + UBOUND_PTR EQU LBOUND_PTR + 2 ; Next 2 bytes for UBOUND PTR + RET_ADDR EQU UBOUND_PTR + 2 ; Next 2 bytes for RET_ADDR + TMP_ARR_PTR EQU RET_ADDR + 2 ; Next 2 bytes for TMP_ARR_PTR ld e, (hl) inc hl ld d, (hl) + inc hl ; DE <-- PTR to Dim sizes table + ld (TMP_ARR_PTR), hl ; HL = Array __DATA__.__PTR__ inc hl - ld (TMP_ARR_PTR), hl - ex de, hl - ex (sp), hl ; Return address in HL, array address in the stack - ld (RET_ADDRESS + 1), hl ; Stores it for later + inc hl + ld c, (hl) + inc hl + ld b, (hl) ; BC <-- Array __LBOUND__ PTR + ld (LBOUND_PTR), bc ; Store it for later +#line 66 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + ex de, hl ; HL <-- PTR to Dim sizes table, DE <-- dummy + ex (sp), hl ; Return address in HL, PTR Dim sizes table onto Stack + ld (RET_ADDR), hl ; Stores it for later exx - pop hl ; Will use H'L' as the pointer + pop hl ; Will use H'L' as the pointer to Dim sizes table ld c, (hl) ; Loads Number of dimensions from (hl) inc hl ld b, (hl) inc hl ; Ready exx - ld hl, 0 ; HL = Offset "accumulator" + ld hl, 0 ; HL = Element Offset "accumulator" LOOP: -#line 64 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - pop bc ; Get next index (Ai) from the stack -#line 74 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - add hl, bc ; Adds current index + ex de, hl ; DE = Element Offset + ld hl, (LBOUND_PTR) + ld a, h + or l + ld b, h + ld c, l + jr z, 1f + ld c, (hl) + inc hl + ld b, (hl) + inc hl + ld (LBOUND_PTR), hl +1: + pop hl ; Get next index (Ai) from the stack + sbc hl, bc ; Subtract LBOUND +#line 116 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + add hl, de ; Adds current index exx ; Checks if B'C' = 0 ld a, b ; Which means we must exit (last element is not multiplied by anything) or c jr z, ARRAY_END ; if B'Ci == 0 we are done - ld e, (hl) ; Loads next dimension into D'E' + dec bc ; Decrements loop counter + ld e, (hl) ; Loads next dimension size into D'E' inc hl ld d, (hl) inc hl push de - dec bc ; Decrements loop counter exx pop de ; DE = Max bound Number (i-th dimension) - call __FNMUL + call __FNMUL ; HL <= HL * DE mod 65536 jp LOOP ARRAY_END: ld a, (hl) exx -#line 103 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 146 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl ld hl, 0 @@ -178,7 +203,7 @@ ARRAY_END: ARRAY_SIZE_LOOP: add hl, de djnz ARRAY_SIZE_LOOP -#line 113 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 156 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ex de, hl ld hl, (TMP_ARR_PTR) ld a, (hl) @@ -186,8 +211,9 @@ ARRAY_SIZE_LOOP: ld h, (hl) ld l, a add hl, de ; Adds element start -RET_ADDRESS: - jp 0 + ld de, (RET_ADDR) + push de + ret ;; Performs a faster multiply for little 16bit numbs LOCAL __FNMUL, __FNMUL2 __FNMUL: @@ -204,13 +230,11 @@ __FNMUL2: add hl, de djnz __FNMUL2 ret -TMP_ARR_PTR: - DW 0 ; temporary storage for pointer to tables ENDP pop namespace -#line 51 "ltee10.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/arrayalloc.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/calloc.asm" +#line 51 "arch/zx48k/ltee10.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/arrayalloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/calloc.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -221,7 +245,7 @@ TMP_ARR_PTR: ; closed source programs). ; ; Please read the MIT license on the internet -#line 1 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -281,7 +305,7 @@ TMP_ARR_PTR: ; HL = BLOCK Start & DE = Length. ; An init directive is useful for initialization routines. ; They will be added automatically if needed. -#line 1 "/zxbasic/src/arch/zx48k/library-asm/error.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/error.asm" ; Simple error control routines ; vim:ts=4:et: push namespace core @@ -315,8 +339,8 @@ __STOP: ld (ERR_NR), a ret pop namespace -#line 69 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/heapinit.asm" +#line 69 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/heapinit.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -423,7 +447,7 @@ __MEM_INIT2: ret ENDP pop namespace -#line 70 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 70 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; --------------------------------------------------------------------- ; MEM_ALLOC ; Allocates a block of memory in the heap. @@ -454,9 +478,9 @@ __MEM_START: __MEM_LOOP: ; Loads lengh at (HL, HL+). If Lenght >= BC, jump to __MEM_DONE ld a, h ; HL = NULL (No memory available?) or l -#line 113 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 113 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ret z ; NULL -#line 115 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 115 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; HL = Pointer to Free block ld e, (hl) inc hl @@ -521,7 +545,7 @@ __MEM_SUBTRACT: ret ENDP pop namespace -#line 13 "/zxbasic/src/arch/zx48k/library-asm/calloc.asm" +#line 13 "/zxbasic/src/lib/arch/zx48k/runtime/calloc.asm" ; --------------------------------------------------------------------- ; MEM_CALLOC ; Allocates a block of memory in the heap, and clears it filling it @@ -555,7 +579,7 @@ __MEM_CALLOC: pop hl ret pop namespace -#line 3 "/zxbasic/src/arch/zx48k/library-asm/arrayalloc.asm" +#line 3 "/zxbasic/src/lib/arch/zx48k/runtime/arrayalloc.asm" ; --------------------------------------------------------------------- ; __ALLOC_LOCAL_ARRAY ; Allocates an array element area in the heap, and clears it filling it @@ -619,10 +643,10 @@ __ALLOC_INITIALIZED_LOCAL_ARRAY: ldir pop hl ; HL = addr of LBound area if used ret -#line 139 "/zxbasic/src/arch/zx48k/library-asm/arrayalloc.asm" +#line 139 "/zxbasic/src/lib/arch/zx48k/runtime/arrayalloc.asm" pop namespace -#line 52 "ltee10.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/free.asm" +#line 52 "arch/zx48k/ltee10.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/free.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -780,7 +804,7 @@ __MEM_BLOCK_JOIN: ; Joins current block (pointed by HL) with next one (pointed ret ENDP pop namespace -#line 53 "ltee10.bas" +#line 53 "arch/zx48k/ltee10.bas" .LABEL.__LABEL0: DEFB 00h DEFB 00h diff --git a/tests/functional/arch/zx48k/ltee4.asm b/tests/functional/arch/zx48k/ltee4.asm index a49b59cac..3ec8724db 100644 --- a/tests/functional/arch/zx48k/ltee4.asm +++ b/tests/functional/arch/zx48k/ltee4.asm @@ -22,6 +22,8 @@ _hsName: DEFW .LABEL.__LABEL0 _hsName.__DATA__.__PTR__: DEFW _hsName.__DATA__ + DEFW 0 + DEFW 0 _hsName.__DATA__: DEFB 00h DEFB 00h @@ -59,9 +61,9 @@ _hsGetName: push ix ld ix, 0 add ix, sp -#line 5 "ltee4.bas" +#line 4 "arch/zx48k/ltee4.bas" ld hl, 0 -#line 7 "ltee4.bas" +#line 7 "arch/zx48k/ltee4.bas" _hsGetName__leave: ld sp, ix pop ix diff --git a/tests/functional/arch/zx48k/ltee6.asm b/tests/functional/arch/zx48k/ltee6.asm index 1700dea7f..42b5a7a65 100644 --- a/tests/functional/arch/zx48k/ltee6.asm +++ b/tests/functional/arch/zx48k/ltee6.asm @@ -29,6 +29,8 @@ _testglobal: DEFW .LABEL.__LABEL1 _testglobal.__DATA__.__PTR__: DEFW _testglobal.__DATA__ + DEFW 0 + DEFW 0 _testglobal.__DATA__: DEFB 00h DEFB 00h @@ -127,52 +129,77 @@ __ARRAY_PTR: ;; computes an array offset from a pointer ld c, (hl) inc hl ld h, (hl) - ld l, c + ld l, c ;; HL <-- [HL] __ARRAY: PROC LOCAL LOOP LOCAL ARRAY_END - LOCAL RET_ADDRESS ; Stores return address - LOCAL TMP_ARR_PTR ; Stores pointer temporarily + LOCAL TMP_ARR_PTR ; Ptr to Array DATA region. Stored temporarily + LOCAL LBOUND_PTR, UBOUND_PTR ; LBound and UBound PTR indexes + LOCAL RET_ADDR ; Contains the return address popped from the stack + LBOUND_PTR EQU 23698 ; Uses MEMBOT as a temporary variable + UBOUND_PTR EQU LBOUND_PTR + 2 ; Next 2 bytes for UBOUND PTR + RET_ADDR EQU UBOUND_PTR + 2 ; Next 2 bytes for RET_ADDR + TMP_ARR_PTR EQU RET_ADDR + 2 ; Next 2 bytes for TMP_ARR_PTR ld e, (hl) inc hl ld d, (hl) + inc hl ; DE <-- PTR to Dim sizes table + ld (TMP_ARR_PTR), hl ; HL = Array __DATA__.__PTR__ inc hl - ld (TMP_ARR_PTR), hl - ex de, hl - ex (sp), hl ; Return address in HL, array address in the stack - ld (RET_ADDRESS + 1), hl ; Stores it for later + inc hl + ld c, (hl) + inc hl + ld b, (hl) ; BC <-- Array __LBOUND__ PTR + ld (LBOUND_PTR), bc ; Store it for later +#line 66 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + ex de, hl ; HL <-- PTR to Dim sizes table, DE <-- dummy + ex (sp), hl ; Return address in HL, PTR Dim sizes table onto Stack + ld (RET_ADDR), hl ; Stores it for later exx - pop hl ; Will use H'L' as the pointer + pop hl ; Will use H'L' as the pointer to Dim sizes table ld c, (hl) ; Loads Number of dimensions from (hl) inc hl ld b, (hl) inc hl ; Ready exx - ld hl, 0 ; HL = Offset "accumulator" + ld hl, 0 ; HL = Element Offset "accumulator" LOOP: -#line 64 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" - pop bc ; Get next index (Ai) from the stack -#line 74 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" - add hl, bc ; Adds current index + ex de, hl ; DE = Element Offset + ld hl, (LBOUND_PTR) + ld a, h + or l + ld b, h + ld c, l + jr z, 1f + ld c, (hl) + inc hl + ld b, (hl) + inc hl + ld (LBOUND_PTR), hl +1: + pop hl ; Get next index (Ai) from the stack + sbc hl, bc ; Subtract LBOUND +#line 116 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + add hl, de ; Adds current index exx ; Checks if B'C' = 0 ld a, b ; Which means we must exit (last element is not multiplied by anything) or c jr z, ARRAY_END ; if B'Ci == 0 we are done - ld e, (hl) ; Loads next dimension into D'E' + dec bc ; Decrements loop counter + ld e, (hl) ; Loads next dimension size into D'E' inc hl ld d, (hl) inc hl push de - dec bc ; Decrements loop counter exx pop de ; DE = Max bound Number (i-th dimension) - call __FNMUL + call __FNMUL ; HL <= HL * DE mod 65536 jp LOOP ARRAY_END: ld a, (hl) exx -#line 103 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 146 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl ld hl, 0 @@ -180,7 +207,7 @@ ARRAY_END: ARRAY_SIZE_LOOP: add hl, de djnz ARRAY_SIZE_LOOP -#line 113 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 156 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ex de, hl ld hl, (TMP_ARR_PTR) ld a, (hl) @@ -188,8 +215,9 @@ ARRAY_SIZE_LOOP: ld h, (hl) ld l, a add hl, de ; Adds element start -RET_ADDRESS: - jp 0 + ld de, (RET_ADDR) + push de + ret ;; Performs a faster multiply for little 16bit numbs LOCAL __FNMUL, __FNMUL2 __FNMUL: @@ -206,8 +234,6 @@ __FNMUL2: add hl, de djnz __FNMUL2 ret -TMP_ARR_PTR: - DW 0 ; temporary storage for pointer to tables ENDP pop namespace #line 33 "arch/zx48k/ltee6.bas" diff --git a/tests/functional/arch/zx48k/ltee7.asm b/tests/functional/arch/zx48k/ltee7.asm index 6e141888c..670222154 100644 --- a/tests/functional/arch/zx48k/ltee7.asm +++ b/tests/functional/arch/zx48k/ltee7.asm @@ -84,7 +84,7 @@ _setlocal__leave: DEFB 6Ch DEFB 6Fh ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -100,7 +100,7 @@ _setlocal__leave: ; O = [a0 + b0 * (a1 + b1 * (a2 + ... bN-2(aN-1)))] ; What I will do here is to calculate the following sequence: ; ((aN-1 * bN-2) + aN-2) * bN-3 + ... -#line 1 "/zxbasic/src/arch/zx48k/library-asm/mul16.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/mul16.asm" push namespace core __MUL16: ; Mutiplies HL with the last value stored into de stack ; Works for both signed and unsigned @@ -126,59 +126,84 @@ __MUL16NOADD: ret ; Result in hl (16 lower bits) ENDP pop namespace -#line 20 "/zxbasic/src/arch/zx48k/library-asm/array.asm" -#line 24 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 20 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 24 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" push namespace core __ARRAY_PTR: ;; computes an array offset from a pointer ld c, (hl) inc hl ld h, (hl) - ld l, c + ld l, c ;; HL <-- [HL] __ARRAY: PROC LOCAL LOOP LOCAL ARRAY_END - LOCAL RET_ADDRESS ; Stores return address - LOCAL TMP_ARR_PTR ; Stores pointer temporarily + LOCAL TMP_ARR_PTR ; Ptr to Array DATA region. Stored temporarily + LOCAL LBOUND_PTR, UBOUND_PTR ; LBound and UBound PTR indexes + LOCAL RET_ADDR ; Contains the return address popped from the stack + LBOUND_PTR EQU 23698 ; Uses MEMBOT as a temporary variable + UBOUND_PTR EQU LBOUND_PTR + 2 ; Next 2 bytes for UBOUND PTR + RET_ADDR EQU UBOUND_PTR + 2 ; Next 2 bytes for RET_ADDR + TMP_ARR_PTR EQU RET_ADDR + 2 ; Next 2 bytes for TMP_ARR_PTR ld e, (hl) inc hl ld d, (hl) + inc hl ; DE <-- PTR to Dim sizes table + ld (TMP_ARR_PTR), hl ; HL = Array __DATA__.__PTR__ inc hl - ld (TMP_ARR_PTR), hl - ex de, hl - ex (sp), hl ; Return address in HL, array address in the stack - ld (RET_ADDRESS + 1), hl ; Stores it for later + inc hl + ld c, (hl) + inc hl + ld b, (hl) ; BC <-- Array __LBOUND__ PTR + ld (LBOUND_PTR), bc ; Store it for later +#line 66 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + ex de, hl ; HL <-- PTR to Dim sizes table, DE <-- dummy + ex (sp), hl ; Return address in HL, PTR Dim sizes table onto Stack + ld (RET_ADDR), hl ; Stores it for later exx - pop hl ; Will use H'L' as the pointer + pop hl ; Will use H'L' as the pointer to Dim sizes table ld c, (hl) ; Loads Number of dimensions from (hl) inc hl ld b, (hl) inc hl ; Ready exx - ld hl, 0 ; HL = Offset "accumulator" + ld hl, 0 ; HL = Element Offset "accumulator" LOOP: -#line 64 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - pop bc ; Get next index (Ai) from the stack -#line 74 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - add hl, bc ; Adds current index + ex de, hl ; DE = Element Offset + ld hl, (LBOUND_PTR) + ld a, h + or l + ld b, h + ld c, l + jr z, 1f + ld c, (hl) + inc hl + ld b, (hl) + inc hl + ld (LBOUND_PTR), hl +1: + pop hl ; Get next index (Ai) from the stack + sbc hl, bc ; Subtract LBOUND +#line 116 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + add hl, de ; Adds current index exx ; Checks if B'C' = 0 ld a, b ; Which means we must exit (last element is not multiplied by anything) or c jr z, ARRAY_END ; if B'Ci == 0 we are done - ld e, (hl) ; Loads next dimension into D'E' + dec bc ; Decrements loop counter + ld e, (hl) ; Loads next dimension size into D'E' inc hl ld d, (hl) inc hl push de - dec bc ; Decrements loop counter exx pop de ; DE = Max bound Number (i-th dimension) - call __FNMUL + call __FNMUL ; HL <= HL * DE mod 65536 jp LOOP ARRAY_END: ld a, (hl) exx -#line 103 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 146 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl ld hl, 0 @@ -186,7 +211,7 @@ ARRAY_END: ARRAY_SIZE_LOOP: add hl, de djnz ARRAY_SIZE_LOOP -#line 113 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 156 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ex de, hl ld hl, (TMP_ARR_PTR) ld a, (hl) @@ -194,8 +219,9 @@ ARRAY_SIZE_LOOP: ld h, (hl) ld l, a add hl, de ; Adds element start -RET_ADDRESS: - jp 0 + ld de, (RET_ADDR) + push de + ret ;; Performs a faster multiply for little 16bit numbs LOCAL __FNMUL, __FNMUL2 __FNMUL: @@ -212,13 +238,11 @@ __FNMUL2: add hl, de djnz __FNMUL2 ret -TMP_ARR_PTR: - DW 0 ; temporary storage for pointer to tables ENDP pop namespace -#line 59 "ltee7.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/arrayalloc.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/calloc.asm" +#line 59 "arch/zx48k/ltee7.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/arrayalloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/calloc.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -229,7 +253,7 @@ TMP_ARR_PTR: ; closed source programs). ; ; Please read the MIT license on the internet -#line 1 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -289,7 +313,7 @@ TMP_ARR_PTR: ; HL = BLOCK Start & DE = Length. ; An init directive is useful for initialization routines. ; They will be added automatically if needed. -#line 1 "/zxbasic/src/arch/zx48k/library-asm/error.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/error.asm" ; Simple error control routines ; vim:ts=4:et: push namespace core @@ -323,8 +347,8 @@ __STOP: ld (ERR_NR), a ret pop namespace -#line 69 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/heapinit.asm" +#line 69 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/heapinit.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -431,7 +455,7 @@ __MEM_INIT2: ret ENDP pop namespace -#line 70 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 70 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; --------------------------------------------------------------------- ; MEM_ALLOC ; Allocates a block of memory in the heap. @@ -462,9 +486,9 @@ __MEM_START: __MEM_LOOP: ; Loads lengh at (HL, HL+). If Lenght >= BC, jump to __MEM_DONE ld a, h ; HL = NULL (No memory available?) or l -#line 113 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 113 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ret z ; NULL -#line 115 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 115 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; HL = Pointer to Free block ld e, (hl) inc hl @@ -529,7 +553,7 @@ __MEM_SUBTRACT: ret ENDP pop namespace -#line 13 "/zxbasic/src/arch/zx48k/library-asm/calloc.asm" +#line 13 "/zxbasic/src/lib/arch/zx48k/runtime/calloc.asm" ; --------------------------------------------------------------------- ; MEM_CALLOC ; Allocates a block of memory in the heap, and clears it filling it @@ -563,7 +587,7 @@ __MEM_CALLOC: pop hl ret pop namespace -#line 3 "/zxbasic/src/arch/zx48k/library-asm/arrayalloc.asm" +#line 3 "/zxbasic/src/lib/arch/zx48k/runtime/arrayalloc.asm" ; --------------------------------------------------------------------- ; __ALLOC_LOCAL_ARRAY ; Allocates an array element area in the heap, and clears it filling it @@ -627,14 +651,14 @@ __ALLOC_INITIALIZED_LOCAL_ARRAY: ldir pop hl ; HL = addr of LBound area if used ret -#line 139 "/zxbasic/src/arch/zx48k/library-asm/arrayalloc.asm" +#line 139 "/zxbasic/src/lib/arch/zx48k/runtime/arrayalloc.asm" pop namespace -#line 60 "ltee7.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/arraystrfree.asm" +#line 60 "arch/zx48k/ltee7.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/arraystrfree.asm" ; This routine is in charge of freeing an array of strings from memory ; HL = Pointer to start of array in memory ; Top of the stack = Number of elements of the array -#line 1 "/zxbasic/src/arch/zx48k/library-asm/free.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/free.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -792,7 +816,7 @@ __MEM_BLOCK_JOIN: ; Joins current block (pointed by HL) with next one (pointed ret ENDP pop namespace -#line 6 "/zxbasic/src/arch/zx48k/library-asm/arraystrfree.asm" +#line 6 "/zxbasic/src/lib/arch/zx48k/runtime/arraystrfree.asm" push namespace core __ARRAYSTR_FREE: PROC @@ -834,8 +858,8 @@ __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 61 "ltee7.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/storestr2.asm" +#line 61 "arch/zx48k/ltee7.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/storestr2.asm" ; Similar to __STORE_STR, but this one is called when ; the value of B$ if already duplicated onto the stack. ; So we needn't call STRASSING to create a duplication @@ -868,7 +892,7 @@ __STORE_STR2: dec hl ; HL points to mem address variable. This might be useful in the future. ret pop namespace -#line 62 "ltee7.bas" +#line 62 "arch/zx48k/ltee7.bas" .LABEL.__LABEL1: DEFB 00h DEFB 00h diff --git a/tests/functional/arch/zx48k/opt1_arr_at_init.asm b/tests/functional/arch/zx48k/opt1_arr_at_init.asm index c7d3a3e79..949946c60 100644 --- a/tests/functional/arch/zx48k/opt1_arr_at_init.asm +++ b/tests/functional/arch/zx48k/opt1_arr_at_init.asm @@ -24,6 +24,8 @@ _a: DEFW .LABEL.__LABEL0 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW 0 + DEFW 0 _a.__DATA__: DEFB 00h DEFB 00h diff --git a/tests/functional/arch/zx48k/opt1_dim_arr_at1.asm b/tests/functional/arch/zx48k/opt1_dim_arr_at1.asm index 78999f3b6..b8e1e5ea7 100644 --- a/tests/functional/arch/zx48k/opt1_dim_arr_at1.asm +++ b/tests/functional/arch/zx48k/opt1_dim_arr_at1.asm @@ -25,6 +25,8 @@ _a: DEFW .LABEL.__LABEL0 _a.__DATA__.__PTR__: DEFW 30000 + DEFW 0 + DEFW 0 .LABEL.__LABEL0: DEFW 0001h DEFW 0006h @@ -33,6 +35,8 @@ _b: DEFW .LABEL.__LABEL1 _b.__DATA__.__PTR__: DEFW _b.__DATA__ + DEFW 0 + DEFW 0 _b.__DATA__: DEFB 00h DEFB 00h diff --git a/tests/functional/arch/zx48k/opt1_dim_arr_at2.asm b/tests/functional/arch/zx48k/opt1_dim_arr_at2.asm index 985bb2a39..11506493a 100644 --- a/tests/functional/arch/zx48k/opt1_dim_arr_at2.asm +++ b/tests/functional/arch/zx48k/opt1_dim_arr_at2.asm @@ -25,6 +25,8 @@ _a: DEFW .LABEL.__LABEL0 _a.__DATA__.__PTR__: DEFW 20000 + DEFW 0 + DEFW 0 .LABEL.__LABEL0: DEFW 0001h DEFW 0005h @@ -34,6 +36,8 @@ _test.a: DEFW .LABEL.__LABEL1 _test.a.__DATA__.__PTR__: DEFW 30000 + DEFW 0 + DEFW 0 .LABEL.__LABEL1: DEFW 0001h DEFW 0005h diff --git a/tests/functional/arch/zx48k/opt1_dim_arr_at3.asm b/tests/functional/arch/zx48k/opt1_dim_arr_at3.asm index 9c997cf87..2d8a4d3dd 100644 --- a/tests/functional/arch/zx48k/opt1_dim_arr_at3.asm +++ b/tests/functional/arch/zx48k/opt1_dim_arr_at3.asm @@ -29,6 +29,8 @@ _a: DEFW .LABEL.__LABEL0 _a.__DATA__.__PTR__: DEFW 30000 + DEFW 0 + DEFW 0 .LABEL.__LABEL0: DEFW 0001h DEFW 0006h @@ -37,6 +39,8 @@ _b: DEFW .LABEL.__LABEL1 _b.__DATA__.__PTR__: DEFW _b.__DATA__ + DEFW 0 + DEFW 0 _b.__DATA__: DEFB 00h DEFB 00h @@ -103,7 +107,7 @@ _b.__DATA__: ei ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -119,7 +123,7 @@ _b.__DATA__: ; O = [a0 + b0 * (a1 + b1 * (a2 + ... bN-2(aN-1)))] ; What I will do here is to calculate the following sequence: ; ((aN-1 * bN-2) + aN-2) * bN-3 + ... -#line 1 "/zxbasic/src/arch/zx48k/library-asm/mul16.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/mul16.asm" push namespace core __MUL16: ; Mutiplies HL with the last value stored into de stack ; Works for both signed and unsigned @@ -145,59 +149,84 @@ __MUL16NOADD: ret ; Result in hl (16 lower bits) ENDP pop namespace -#line 20 "/zxbasic/src/arch/zx48k/library-asm/array.asm" -#line 24 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 20 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 24 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" push namespace core __ARRAY_PTR: ;; computes an array offset from a pointer ld c, (hl) inc hl ld h, (hl) - ld l, c + ld l, c ;; HL <-- [HL] __ARRAY: PROC LOCAL LOOP LOCAL ARRAY_END - LOCAL RET_ADDRESS ; Stores return address - LOCAL TMP_ARR_PTR ; Stores pointer temporarily + LOCAL TMP_ARR_PTR ; Ptr to Array DATA region. Stored temporarily + LOCAL LBOUND_PTR, UBOUND_PTR ; LBound and UBound PTR indexes + LOCAL RET_ADDR ; Contains the return address popped from the stack + LBOUND_PTR EQU 23698 ; Uses MEMBOT as a temporary variable + UBOUND_PTR EQU LBOUND_PTR + 2 ; Next 2 bytes for UBOUND PTR + RET_ADDR EQU UBOUND_PTR + 2 ; Next 2 bytes for RET_ADDR + TMP_ARR_PTR EQU RET_ADDR + 2 ; Next 2 bytes for TMP_ARR_PTR ld e, (hl) inc hl ld d, (hl) + inc hl ; DE <-- PTR to Dim sizes table + ld (TMP_ARR_PTR), hl ; HL = Array __DATA__.__PTR__ inc hl - ld (TMP_ARR_PTR), hl - ex de, hl - ex (sp), hl ; Return address in HL, array address in the stack - ld (RET_ADDRESS + 1), hl ; Stores it for later + inc hl + ld c, (hl) + inc hl + ld b, (hl) ; BC <-- Array __LBOUND__ PTR + ld (LBOUND_PTR), bc ; Store it for later +#line 66 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + ex de, hl ; HL <-- PTR to Dim sizes table, DE <-- dummy + ex (sp), hl ; Return address in HL, PTR Dim sizes table onto Stack + ld (RET_ADDR), hl ; Stores it for later exx - pop hl ; Will use H'L' as the pointer + pop hl ; Will use H'L' as the pointer to Dim sizes table ld c, (hl) ; Loads Number of dimensions from (hl) inc hl ld b, (hl) inc hl ; Ready exx - ld hl, 0 ; HL = Offset "accumulator" + ld hl, 0 ; HL = Element Offset "accumulator" LOOP: -#line 64 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - pop bc ; Get next index (Ai) from the stack -#line 74 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - add hl, bc ; Adds current index + ex de, hl ; DE = Element Offset + ld hl, (LBOUND_PTR) + ld a, h + or l + ld b, h + ld c, l + jr z, 1f + ld c, (hl) + inc hl + ld b, (hl) + inc hl + ld (LBOUND_PTR), hl +1: + pop hl ; Get next index (Ai) from the stack + sbc hl, bc ; Subtract LBOUND +#line 116 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + add hl, de ; Adds current index exx ; Checks if B'C' = 0 ld a, b ; Which means we must exit (last element is not multiplied by anything) or c jr z, ARRAY_END ; if B'Ci == 0 we are done - ld e, (hl) ; Loads next dimension into D'E' + dec bc ; Decrements loop counter + ld e, (hl) ; Loads next dimension size into D'E' inc hl ld d, (hl) inc hl push de - dec bc ; Decrements loop counter exx pop de ; DE = Max bound Number (i-th dimension) - call __FNMUL + call __FNMUL ; HL <= HL * DE mod 65536 jp LOOP ARRAY_END: ld a, (hl) exx -#line 103 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 146 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl ld hl, 0 @@ -205,7 +234,7 @@ ARRAY_END: ARRAY_SIZE_LOOP: add hl, de djnz ARRAY_SIZE_LOOP -#line 113 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 156 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ex de, hl ld hl, (TMP_ARR_PTR) ld a, (hl) @@ -213,8 +242,9 @@ ARRAY_SIZE_LOOP: ld h, (hl) ld l, a add hl, de ; Adds element start -RET_ADDRESS: - jp 0 + ld de, (RET_ADDR) + push de + ret ;; Performs a faster multiply for little 16bit numbs LOCAL __FNMUL, __FNMUL2 __FNMUL: @@ -231,9 +261,7 @@ __FNMUL2: add hl, de djnz __FNMUL2 ret -TMP_ARR_PTR: - DW 0 ; temporary storage for pointer to tables ENDP pop namespace -#line 31 "opt1_dim_arr_at3.bas" +#line 31 "arch/zx48k/opt1_dim_arr_at3.bas" END diff --git a/tests/functional/arch/zx48k/opt1_dim_arr_at4.asm b/tests/functional/arch/zx48k/opt1_dim_arr_at4.asm index 6ec2b1eb9..3d3a2c5b5 100644 --- a/tests/functional/arch/zx48k/opt1_dim_arr_at4.asm +++ b/tests/functional/arch/zx48k/opt1_dim_arr_at4.asm @@ -25,6 +25,8 @@ _a: DEFW .LABEL.__LABEL0 _a.__DATA__.__PTR__: DEFW 30000 + DEFW 0 + DEFW 0 .LABEL.__LABEL0: DEFW 0001h DEFW 0006h @@ -33,6 +35,8 @@ _b: DEFW .LABEL.__LABEL1 _b.__DATA__.__PTR__: DEFW _b.__DATA__ + DEFW 0 + DEFW 0 _b.__DATA__: DEFB 00h DEFB 00h diff --git a/tests/functional/arch/zx48k/opt1_dim_arr_at5.asm b/tests/functional/arch/zx48k/opt1_dim_arr_at5.asm index 4a736fde1..3dce2219c 100644 --- a/tests/functional/arch/zx48k/opt1_dim_arr_at5.asm +++ b/tests/functional/arch/zx48k/opt1_dim_arr_at5.asm @@ -23,6 +23,8 @@ _a: DEFW .LABEL.__LABEL0 _a.__DATA__.__PTR__: DEFW 16384 + DEFW 0 + DEFW 0 .LABEL.__LABEL0: DEFW 0001h DEFW 0020h diff --git a/tests/functional/arch/zx48k/opt1_dim_arr_at_copy.asm b/tests/functional/arch/zx48k/opt1_dim_arr_at_copy.asm index 6a358c54a..2a08c4731 100644 --- a/tests/functional/arch/zx48k/opt1_dim_arr_at_copy.asm +++ b/tests/functional/arch/zx48k/opt1_dim_arr_at_copy.asm @@ -23,6 +23,8 @@ _a: DEFW .LABEL.__LABEL0 _a.__DATA__.__PTR__: DEFW 16384 + DEFW 0 + DEFW 0 .LABEL.__LABEL0: DEFW 0000h DEFB 02h @@ -30,6 +32,8 @@ _b: DEFW .LABEL.__LABEL1 _b.__DATA__.__PTR__: DEFW _b.__DATA__ + DEFW 0 + DEFW 0 _b.__DATA__: DEFB 00h DEFB 0FFh diff --git a/tests/functional/arch/zx48k/opt1_dim_arr_at_copy2.asm b/tests/functional/arch/zx48k/opt1_dim_arr_at_copy2.asm index d0a0fa9ef..0782edc6a 100644 --- a/tests/functional/arch/zx48k/opt1_dim_arr_at_copy2.asm +++ b/tests/functional/arch/zx48k/opt1_dim_arr_at_copy2.asm @@ -28,6 +28,8 @@ _test.a: DEFW .LABEL.__LABEL2 _test.a.__DATA__.__PTR__: DEFW 16384 + DEFW 0 + DEFW 0 .LABEL.__LABEL2: DEFW 0000h DEFB 02h @@ -82,8 +84,8 @@ _test__leave: pop ix ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/arrayalloc.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/calloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/arrayalloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/calloc.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -94,7 +96,7 @@ _test__leave: ; closed source programs). ; ; Please read the MIT license on the internet -#line 1 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -154,7 +156,7 @@ _test__leave: ; HL = BLOCK Start & DE = Length. ; An init directive is useful for initialization routines. ; They will be added automatically if needed. -#line 1 "/zxbasic/src/arch/zx48k/library-asm/error.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/error.asm" ; Simple error control routines ; vim:ts=4:et: push namespace core @@ -188,8 +190,8 @@ __STOP: ld (ERR_NR), a ret pop namespace -#line 69 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/heapinit.asm" +#line 69 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/heapinit.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -296,7 +298,7 @@ __MEM_INIT2: ret ENDP pop namespace -#line 70 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 70 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; --------------------------------------------------------------------- ; MEM_ALLOC ; Allocates a block of memory in the heap. @@ -327,9 +329,9 @@ __MEM_START: __MEM_LOOP: ; Loads lengh at (HL, HL+). If Lenght >= BC, jump to __MEM_DONE ld a, h ; HL = NULL (No memory available?) or l -#line 113 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 113 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ret z ; NULL -#line 115 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 115 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; HL = Pointer to Free block ld e, (hl) inc hl @@ -394,7 +396,7 @@ __MEM_SUBTRACT: ret ENDP pop namespace -#line 13 "/zxbasic/src/arch/zx48k/library-asm/calloc.asm" +#line 13 "/zxbasic/src/lib/arch/zx48k/runtime/calloc.asm" ; --------------------------------------------------------------------- ; MEM_CALLOC ; Allocates a block of memory in the heap, and clears it filling it @@ -428,7 +430,7 @@ __MEM_CALLOC: pop hl ret pop namespace -#line 3 "/zxbasic/src/arch/zx48k/library-asm/arrayalloc.asm" +#line 3 "/zxbasic/src/lib/arch/zx48k/runtime/arrayalloc.asm" ; --------------------------------------------------------------------- ; __ALLOC_LOCAL_ARRAY ; Allocates an array element area in the heap, and clears it filling it @@ -492,10 +494,10 @@ __ALLOC_INITIALIZED_LOCAL_ARRAY: ldir pop hl ; HL = addr of LBound area if used ret -#line 139 "/zxbasic/src/arch/zx48k/library-asm/arrayalloc.asm" +#line 139 "/zxbasic/src/lib/arch/zx48k/runtime/arrayalloc.asm" pop namespace -#line 51 "opt1_dim_arr_at_copy2.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/free.asm" +#line 51 "arch/zx48k/opt1_dim_arr_at_copy2.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/free.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -653,7 +655,7 @@ __MEM_BLOCK_JOIN: ; Joins current block (pointed by HL) with next one (pointed ret ENDP pop namespace -#line 52 "opt1_dim_arr_at_copy2.bas" +#line 52 "arch/zx48k/opt1_dim_arr_at_copy2.bas" .LABEL.__LABEL0: DEFB 00h DEFB 00h diff --git a/tests/functional/arch/zx48k/opt1_dim_arr_at_copy3.asm b/tests/functional/arch/zx48k/opt1_dim_arr_at_copy3.asm index 6535533e0..41d089b30 100644 --- a/tests/functional/arch/zx48k/opt1_dim_arr_at_copy3.asm +++ b/tests/functional/arch/zx48k/opt1_dim_arr_at_copy3.asm @@ -28,6 +28,8 @@ _test.a: DEFW .LABEL.__LABEL1 _test.a.__DATA__.__PTR__: DEFW 16384 + DEFW 0 + DEFW 0 .LABEL.__LABEL1: DEFW 0000h DEFB 02h @@ -80,8 +82,8 @@ _test__leave: pop ix ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/arrayalloc.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/calloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/arrayalloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/calloc.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -92,7 +94,7 @@ _test__leave: ; closed source programs). ; ; Please read the MIT license on the internet -#line 1 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -152,7 +154,7 @@ _test__leave: ; HL = BLOCK Start & DE = Length. ; An init directive is useful for initialization routines. ; They will be added automatically if needed. -#line 1 "/zxbasic/src/arch/zx48k/library-asm/error.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/error.asm" ; Simple error control routines ; vim:ts=4:et: push namespace core @@ -186,8 +188,8 @@ __STOP: ld (ERR_NR), a ret pop namespace -#line 69 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/heapinit.asm" +#line 69 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/heapinit.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -294,7 +296,7 @@ __MEM_INIT2: ret ENDP pop namespace -#line 70 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 70 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; --------------------------------------------------------------------- ; MEM_ALLOC ; Allocates a block of memory in the heap. @@ -325,9 +327,9 @@ __MEM_START: __MEM_LOOP: ; Loads lengh at (HL, HL+). If Lenght >= BC, jump to __MEM_DONE ld a, h ; HL = NULL (No memory available?) or l -#line 113 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 113 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ret z ; NULL -#line 115 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 115 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; HL = Pointer to Free block ld e, (hl) inc hl @@ -392,7 +394,7 @@ __MEM_SUBTRACT: ret ENDP pop namespace -#line 13 "/zxbasic/src/arch/zx48k/library-asm/calloc.asm" +#line 13 "/zxbasic/src/lib/arch/zx48k/runtime/calloc.asm" ; --------------------------------------------------------------------- ; MEM_CALLOC ; Allocates a block of memory in the heap, and clears it filling it @@ -426,7 +428,7 @@ __MEM_CALLOC: pop hl ret pop namespace -#line 3 "/zxbasic/src/arch/zx48k/library-asm/arrayalloc.asm" +#line 3 "/zxbasic/src/lib/arch/zx48k/runtime/arrayalloc.asm" ; --------------------------------------------------------------------- ; __ALLOC_LOCAL_ARRAY ; Allocates an array element area in the heap, and clears it filling it @@ -490,10 +492,10 @@ __ALLOC_INITIALIZED_LOCAL_ARRAY: ldir pop hl ; HL = addr of LBound area if used ret -#line 139 "/zxbasic/src/arch/zx48k/library-asm/arrayalloc.asm" +#line 139 "/zxbasic/src/lib/arch/zx48k/runtime/arrayalloc.asm" pop namespace -#line 49 "opt1_dim_arr_at_copy3.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/free.asm" +#line 49 "arch/zx48k/opt1_dim_arr_at_copy3.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/free.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -651,7 +653,7 @@ __MEM_BLOCK_JOIN: ; Joins current block (pointed by HL) with next one (pointed ret ENDP pop namespace -#line 50 "opt1_dim_arr_at_copy3.bas" +#line 50 "arch/zx48k/opt1_dim_arr_at_copy3.bas" .LABEL.__LABEL0: DEFB 00h DEFB 00h diff --git a/tests/functional/arch/zx48k/opt1_dim_arr_global.asm b/tests/functional/arch/zx48k/opt1_dim_arr_global.asm index 8b153f102..e378623c5 100644 --- a/tests/functional/arch/zx48k/opt1_dim_arr_global.asm +++ b/tests/functional/arch/zx48k/opt1_dim_arr_global.asm @@ -25,6 +25,8 @@ _a: DEFW .LABEL.__LABEL0 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW 0 + DEFW 0 _a.__DATA__: DEFB 00h DEFB 01h @@ -111,52 +113,77 @@ __ARRAY_PTR: ;; computes an array offset from a pointer ld c, (hl) inc hl ld h, (hl) - ld l, c + ld l, c ;; HL <-- [HL] __ARRAY: PROC LOCAL LOOP LOCAL ARRAY_END - LOCAL RET_ADDRESS ; Stores return address - LOCAL TMP_ARR_PTR ; Stores pointer temporarily + LOCAL TMP_ARR_PTR ; Ptr to Array DATA region. Stored temporarily + LOCAL LBOUND_PTR, UBOUND_PTR ; LBound and UBound PTR indexes + LOCAL RET_ADDR ; Contains the return address popped from the stack + LBOUND_PTR EQU 23698 ; Uses MEMBOT as a temporary variable + UBOUND_PTR EQU LBOUND_PTR + 2 ; Next 2 bytes for UBOUND PTR + RET_ADDR EQU UBOUND_PTR + 2 ; Next 2 bytes for RET_ADDR + TMP_ARR_PTR EQU RET_ADDR + 2 ; Next 2 bytes for TMP_ARR_PTR ld e, (hl) inc hl ld d, (hl) + inc hl ; DE <-- PTR to Dim sizes table + ld (TMP_ARR_PTR), hl ; HL = Array __DATA__.__PTR__ inc hl - ld (TMP_ARR_PTR), hl - ex de, hl - ex (sp), hl ; Return address in HL, array address in the stack - ld (RET_ADDRESS + 1), hl ; Stores it for later + inc hl + ld c, (hl) + inc hl + ld b, (hl) ; BC <-- Array __LBOUND__ PTR + ld (LBOUND_PTR), bc ; Store it for later +#line 66 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + ex de, hl ; HL <-- PTR to Dim sizes table, DE <-- dummy + ex (sp), hl ; Return address in HL, PTR Dim sizes table onto Stack + ld (RET_ADDR), hl ; Stores it for later exx - pop hl ; Will use H'L' as the pointer + pop hl ; Will use H'L' as the pointer to Dim sizes table ld c, (hl) ; Loads Number of dimensions from (hl) inc hl ld b, (hl) inc hl ; Ready exx - ld hl, 0 ; HL = Offset "accumulator" + ld hl, 0 ; HL = Element Offset "accumulator" LOOP: -#line 64 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" - pop bc ; Get next index (Ai) from the stack -#line 74 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" - add hl, bc ; Adds current index + ex de, hl ; DE = Element Offset + ld hl, (LBOUND_PTR) + ld a, h + or l + ld b, h + ld c, l + jr z, 1f + ld c, (hl) + inc hl + ld b, (hl) + inc hl + ld (LBOUND_PTR), hl +1: + pop hl ; Get next index (Ai) from the stack + sbc hl, bc ; Subtract LBOUND +#line 116 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + add hl, de ; Adds current index exx ; Checks if B'C' = 0 ld a, b ; Which means we must exit (last element is not multiplied by anything) or c jr z, ARRAY_END ; if B'Ci == 0 we are done - ld e, (hl) ; Loads next dimension into D'E' + dec bc ; Decrements loop counter + ld e, (hl) ; Loads next dimension size into D'E' inc hl ld d, (hl) inc hl push de - dec bc ; Decrements loop counter exx pop de ; DE = Max bound Number (i-th dimension) - call __FNMUL + call __FNMUL ; HL <= HL * DE mod 65536 jp LOOP ARRAY_END: ld a, (hl) exx -#line 103 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 146 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl ld hl, 0 @@ -164,7 +191,7 @@ ARRAY_END: ARRAY_SIZE_LOOP: add hl, de djnz ARRAY_SIZE_LOOP -#line 113 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 156 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ex de, hl ld hl, (TMP_ARR_PTR) ld a, (hl) @@ -172,8 +199,9 @@ ARRAY_SIZE_LOOP: ld h, (hl) ld l, a add hl, de ; Adds element start -RET_ADDRESS: - jp 0 + ld de, (RET_ADDR) + push de + ret ;; Performs a faster multiply for little 16bit numbs LOCAL __FNMUL, __FNMUL2 __FNMUL: @@ -190,8 +218,6 @@ __FNMUL2: add hl, de djnz __FNMUL2 ret -TMP_ARR_PTR: - DW 0 ; temporary storage for pointer to tables ENDP pop namespace #line 27 "arch/zx48k/opt1_dim_arr_global.bas" diff --git a/tests/functional/arch/zx48k/opt1_dim_arr_global2.asm b/tests/functional/arch/zx48k/opt1_dim_arr_global2.asm index 76227284a..578d2bcfd 100644 --- a/tests/functional/arch/zx48k/opt1_dim_arr_global2.asm +++ b/tests/functional/arch/zx48k/opt1_dim_arr_global2.asm @@ -23,6 +23,8 @@ _a: DEFW .LABEL.__LABEL0 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW 0 + DEFW 0 _a.__DATA__: DEFB 00h DEFB 01h diff --git a/tests/functional/arch/zx48k/opt1_dim_arr_global3.asm b/tests/functional/arch/zx48k/opt1_dim_arr_global3.asm index 4c16a2b45..89ee6179e 100644 --- a/tests/functional/arch/zx48k/opt1_dim_arr_global3.asm +++ b/tests/functional/arch/zx48k/opt1_dim_arr_global3.asm @@ -23,6 +23,8 @@ _a: DEFW .LABEL.__LABEL0 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW 0 + DEFW 0 _a.__DATA__: DEFB 00h DEFB 01h diff --git a/tests/functional/arch/zx48k/opt1_dim_arr_global4.asm b/tests/functional/arch/zx48k/opt1_dim_arr_global4.asm index 8feca87fe..b1dd06e69 100644 --- a/tests/functional/arch/zx48k/opt1_dim_arr_global4.asm +++ b/tests/functional/arch/zx48k/opt1_dim_arr_global4.asm @@ -25,6 +25,8 @@ _a: DEFW .LABEL.__LABEL0 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW 0 + DEFW 0 _a.__DATA__: DEFB 00h DEFB 01h @@ -115,52 +117,77 @@ __ARRAY_PTR: ;; computes an array offset from a pointer ld c, (hl) inc hl ld h, (hl) - ld l, c + ld l, c ;; HL <-- [HL] __ARRAY: PROC LOCAL LOOP LOCAL ARRAY_END - LOCAL RET_ADDRESS ; Stores return address - LOCAL TMP_ARR_PTR ; Stores pointer temporarily + LOCAL TMP_ARR_PTR ; Ptr to Array DATA region. Stored temporarily + LOCAL LBOUND_PTR, UBOUND_PTR ; LBound and UBound PTR indexes + LOCAL RET_ADDR ; Contains the return address popped from the stack + LBOUND_PTR EQU 23698 ; Uses MEMBOT as a temporary variable + UBOUND_PTR EQU LBOUND_PTR + 2 ; Next 2 bytes for UBOUND PTR + RET_ADDR EQU UBOUND_PTR + 2 ; Next 2 bytes for RET_ADDR + TMP_ARR_PTR EQU RET_ADDR + 2 ; Next 2 bytes for TMP_ARR_PTR ld e, (hl) inc hl ld d, (hl) + inc hl ; DE <-- PTR to Dim sizes table + ld (TMP_ARR_PTR), hl ; HL = Array __DATA__.__PTR__ inc hl - ld (TMP_ARR_PTR), hl - ex de, hl - ex (sp), hl ; Return address in HL, array address in the stack - ld (RET_ADDRESS + 1), hl ; Stores it for later + inc hl + ld c, (hl) + inc hl + ld b, (hl) ; BC <-- Array __LBOUND__ PTR + ld (LBOUND_PTR), bc ; Store it for later +#line 66 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + ex de, hl ; HL <-- PTR to Dim sizes table, DE <-- dummy + ex (sp), hl ; Return address in HL, PTR Dim sizes table onto Stack + ld (RET_ADDR), hl ; Stores it for later exx - pop hl ; Will use H'L' as the pointer + pop hl ; Will use H'L' as the pointer to Dim sizes table ld c, (hl) ; Loads Number of dimensions from (hl) inc hl ld b, (hl) inc hl ; Ready exx - ld hl, 0 ; HL = Offset "accumulator" + ld hl, 0 ; HL = Element Offset "accumulator" LOOP: -#line 64 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" - pop bc ; Get next index (Ai) from the stack -#line 74 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" - add hl, bc ; Adds current index + ex de, hl ; DE = Element Offset + ld hl, (LBOUND_PTR) + ld a, h + or l + ld b, h + ld c, l + jr z, 1f + ld c, (hl) + inc hl + ld b, (hl) + inc hl + ld (LBOUND_PTR), hl +1: + pop hl ; Get next index (Ai) from the stack + sbc hl, bc ; Subtract LBOUND +#line 116 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + add hl, de ; Adds current index exx ; Checks if B'C' = 0 ld a, b ; Which means we must exit (last element is not multiplied by anything) or c jr z, ARRAY_END ; if B'Ci == 0 we are done - ld e, (hl) ; Loads next dimension into D'E' + dec bc ; Decrements loop counter + ld e, (hl) ; Loads next dimension size into D'E' inc hl ld d, (hl) inc hl push de - dec bc ; Decrements loop counter exx pop de ; DE = Max bound Number (i-th dimension) - call __FNMUL + call __FNMUL ; HL <= HL * DE mod 65536 jp LOOP ARRAY_END: ld a, (hl) exx -#line 103 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 146 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl ld hl, 0 @@ -168,7 +195,7 @@ ARRAY_END: ARRAY_SIZE_LOOP: add hl, de djnz ARRAY_SIZE_LOOP -#line 113 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 156 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ex de, hl ld hl, (TMP_ARR_PTR) ld a, (hl) @@ -176,8 +203,9 @@ ARRAY_SIZE_LOOP: ld h, (hl) ld l, a add hl, de ; Adds element start -RET_ADDRESS: - jp 0 + ld de, (RET_ADDR) + push de + ret ;; Performs a faster multiply for little 16bit numbs LOCAL __FNMUL, __FNMUL2 __FNMUL: @@ -194,8 +222,6 @@ __FNMUL2: add hl, de djnz __FNMUL2 ret -TMP_ARR_PTR: - DW 0 ; temporary storage for pointer to tables ENDP pop namespace #line 31 "arch/zx48k/opt1_dim_arr_global4.bas" diff --git a/tests/functional/arch/zx48k/opt1_dim_arr_local.asm b/tests/functional/arch/zx48k/opt1_dim_arr_local.asm index a8d8c296f..51b28ae8b 100644 --- a/tests/functional/arch/zx48k/opt1_dim_arr_local.asm +++ b/tests/functional/arch/zx48k/opt1_dim_arr_local.asm @@ -76,7 +76,7 @@ _test__leave: pop ix ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -92,7 +92,7 @@ _test__leave: ; O = [a0 + b0 * (a1 + b1 * (a2 + ... bN-2(aN-1)))] ; What I will do here is to calculate the following sequence: ; ((aN-1 * bN-2) + aN-2) * bN-3 + ... -#line 1 "/zxbasic/src/arch/zx48k/library-asm/mul16.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/mul16.asm" push namespace core __MUL16: ; Mutiplies HL with the last value stored into de stack ; Works for both signed and unsigned @@ -118,59 +118,84 @@ __MUL16NOADD: ret ; Result in hl (16 lower bits) ENDP pop namespace -#line 20 "/zxbasic/src/arch/zx48k/library-asm/array.asm" -#line 24 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 20 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 24 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" push namespace core __ARRAY_PTR: ;; computes an array offset from a pointer ld c, (hl) inc hl ld h, (hl) - ld l, c + ld l, c ;; HL <-- [HL] __ARRAY: PROC LOCAL LOOP LOCAL ARRAY_END - LOCAL RET_ADDRESS ; Stores return address - LOCAL TMP_ARR_PTR ; Stores pointer temporarily + LOCAL TMP_ARR_PTR ; Ptr to Array DATA region. Stored temporarily + LOCAL LBOUND_PTR, UBOUND_PTR ; LBound and UBound PTR indexes + LOCAL RET_ADDR ; Contains the return address popped from the stack + LBOUND_PTR EQU 23698 ; Uses MEMBOT as a temporary variable + UBOUND_PTR EQU LBOUND_PTR + 2 ; Next 2 bytes for UBOUND PTR + RET_ADDR EQU UBOUND_PTR + 2 ; Next 2 bytes for RET_ADDR + TMP_ARR_PTR EQU RET_ADDR + 2 ; Next 2 bytes for TMP_ARR_PTR ld e, (hl) inc hl ld d, (hl) + inc hl ; DE <-- PTR to Dim sizes table + ld (TMP_ARR_PTR), hl ; HL = Array __DATA__.__PTR__ inc hl - ld (TMP_ARR_PTR), hl - ex de, hl - ex (sp), hl ; Return address in HL, array address in the stack - ld (RET_ADDRESS + 1), hl ; Stores it for later + inc hl + ld c, (hl) + inc hl + ld b, (hl) ; BC <-- Array __LBOUND__ PTR + ld (LBOUND_PTR), bc ; Store it for later +#line 66 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + ex de, hl ; HL <-- PTR to Dim sizes table, DE <-- dummy + ex (sp), hl ; Return address in HL, PTR Dim sizes table onto Stack + ld (RET_ADDR), hl ; Stores it for later exx - pop hl ; Will use H'L' as the pointer + pop hl ; Will use H'L' as the pointer to Dim sizes table ld c, (hl) ; Loads Number of dimensions from (hl) inc hl ld b, (hl) inc hl ; Ready exx - ld hl, 0 ; HL = Offset "accumulator" + ld hl, 0 ; HL = Element Offset "accumulator" LOOP: -#line 64 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - pop bc ; Get next index (Ai) from the stack -#line 74 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - add hl, bc ; Adds current index + ex de, hl ; DE = Element Offset + ld hl, (LBOUND_PTR) + ld a, h + or l + ld b, h + ld c, l + jr z, 1f + ld c, (hl) + inc hl + ld b, (hl) + inc hl + ld (LBOUND_PTR), hl +1: + pop hl ; Get next index (Ai) from the stack + sbc hl, bc ; Subtract LBOUND +#line 116 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + add hl, de ; Adds current index exx ; Checks if B'C' = 0 ld a, b ; Which means we must exit (last element is not multiplied by anything) or c jr z, ARRAY_END ; if B'Ci == 0 we are done - ld e, (hl) ; Loads next dimension into D'E' + dec bc ; Decrements loop counter + ld e, (hl) ; Loads next dimension size into D'E' inc hl ld d, (hl) inc hl push de - dec bc ; Decrements loop counter exx pop de ; DE = Max bound Number (i-th dimension) - call __FNMUL + call __FNMUL ; HL <= HL * DE mod 65536 jp LOOP ARRAY_END: ld a, (hl) exx -#line 103 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 146 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl ld hl, 0 @@ -178,7 +203,7 @@ ARRAY_END: ARRAY_SIZE_LOOP: add hl, de djnz ARRAY_SIZE_LOOP -#line 113 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 156 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ex de, hl ld hl, (TMP_ARR_PTR) ld a, (hl) @@ -186,8 +211,9 @@ ARRAY_SIZE_LOOP: ld h, (hl) ld l, a add hl, de ; Adds element start -RET_ADDRESS: - jp 0 + ld de, (RET_ADDR) + push de + ret ;; Performs a faster multiply for little 16bit numbs LOCAL __FNMUL, __FNMUL2 __FNMUL: @@ -204,13 +230,11 @@ __FNMUL2: add hl, de djnz __FNMUL2 ret -TMP_ARR_PTR: - DW 0 ; temporary storage for pointer to tables ENDP pop namespace -#line 51 "opt1_dim_arr_local.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/arrayalloc.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/calloc.asm" +#line 51 "arch/zx48k/opt1_dim_arr_local.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/arrayalloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/calloc.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -221,7 +245,7 @@ TMP_ARR_PTR: ; closed source programs). ; ; Please read the MIT license on the internet -#line 1 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -281,7 +305,7 @@ TMP_ARR_PTR: ; HL = BLOCK Start & DE = Length. ; An init directive is useful for initialization routines. ; They will be added automatically if needed. -#line 1 "/zxbasic/src/arch/zx48k/library-asm/error.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/error.asm" ; Simple error control routines ; vim:ts=4:et: push namespace core @@ -315,8 +339,8 @@ __STOP: ld (ERR_NR), a ret pop namespace -#line 69 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/heapinit.asm" +#line 69 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/heapinit.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -423,7 +447,7 @@ __MEM_INIT2: ret ENDP pop namespace -#line 70 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 70 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; --------------------------------------------------------------------- ; MEM_ALLOC ; Allocates a block of memory in the heap. @@ -454,9 +478,9 @@ __MEM_START: __MEM_LOOP: ; Loads lengh at (HL, HL+). If Lenght >= BC, jump to __MEM_DONE ld a, h ; HL = NULL (No memory available?) or l -#line 113 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 113 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ret z ; NULL -#line 115 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 115 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; HL = Pointer to Free block ld e, (hl) inc hl @@ -521,7 +545,7 @@ __MEM_SUBTRACT: ret ENDP pop namespace -#line 13 "/zxbasic/src/arch/zx48k/library-asm/calloc.asm" +#line 13 "/zxbasic/src/lib/arch/zx48k/runtime/calloc.asm" ; --------------------------------------------------------------------- ; MEM_CALLOC ; Allocates a block of memory in the heap, and clears it filling it @@ -555,7 +579,7 @@ __MEM_CALLOC: pop hl ret pop namespace -#line 3 "/zxbasic/src/arch/zx48k/library-asm/arrayalloc.asm" +#line 3 "/zxbasic/src/lib/arch/zx48k/runtime/arrayalloc.asm" ; --------------------------------------------------------------------- ; __ALLOC_LOCAL_ARRAY ; Allocates an array element area in the heap, and clears it filling it @@ -619,10 +643,10 @@ __ALLOC_INITIALIZED_LOCAL_ARRAY: ldir pop hl ; HL = addr of LBound area if used ret -#line 139 "/zxbasic/src/arch/zx48k/library-asm/arrayalloc.asm" +#line 139 "/zxbasic/src/lib/arch/zx48k/runtime/arrayalloc.asm" pop namespace -#line 52 "opt1_dim_arr_local.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/free.asm" +#line 52 "arch/zx48k/opt1_dim_arr_local.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/free.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -780,7 +804,7 @@ __MEM_BLOCK_JOIN: ; Joins current block (pointed by HL) with next one (pointed ret ENDP pop namespace -#line 53 "opt1_dim_arr_local.bas" +#line 53 "arch/zx48k/opt1_dim_arr_local.bas" .LABEL.__LABEL0: DEFB 00h DEFB 00h diff --git a/tests/functional/arch/zx48k/opt1_dim_arr_local3.asm b/tests/functional/arch/zx48k/opt1_dim_arr_local3.asm index 175661d04..d021c01d9 100644 --- a/tests/functional/arch/zx48k/opt1_dim_arr_local3.asm +++ b/tests/functional/arch/zx48k/opt1_dim_arr_local3.asm @@ -90,7 +90,7 @@ _test__leave: pop ix ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -106,7 +106,7 @@ _test__leave: ; O = [a0 + b0 * (a1 + b1 * (a2 + ... bN-2(aN-1)))] ; What I will do here is to calculate the following sequence: ; ((aN-1 * bN-2) + aN-2) * bN-3 + ... -#line 1 "/zxbasic/src/arch/zx48k/library-asm/mul16.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/mul16.asm" push namespace core __MUL16: ; Mutiplies HL with the last value stored into de stack ; Works for both signed and unsigned @@ -132,59 +132,84 @@ __MUL16NOADD: ret ; Result in hl (16 lower bits) ENDP pop namespace -#line 20 "/zxbasic/src/arch/zx48k/library-asm/array.asm" -#line 24 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 20 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 24 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" push namespace core __ARRAY_PTR: ;; computes an array offset from a pointer ld c, (hl) inc hl ld h, (hl) - ld l, c + ld l, c ;; HL <-- [HL] __ARRAY: PROC LOCAL LOOP LOCAL ARRAY_END - LOCAL RET_ADDRESS ; Stores return address - LOCAL TMP_ARR_PTR ; Stores pointer temporarily + LOCAL TMP_ARR_PTR ; Ptr to Array DATA region. Stored temporarily + LOCAL LBOUND_PTR, UBOUND_PTR ; LBound and UBound PTR indexes + LOCAL RET_ADDR ; Contains the return address popped from the stack + LBOUND_PTR EQU 23698 ; Uses MEMBOT as a temporary variable + UBOUND_PTR EQU LBOUND_PTR + 2 ; Next 2 bytes for UBOUND PTR + RET_ADDR EQU UBOUND_PTR + 2 ; Next 2 bytes for RET_ADDR + TMP_ARR_PTR EQU RET_ADDR + 2 ; Next 2 bytes for TMP_ARR_PTR ld e, (hl) inc hl ld d, (hl) + inc hl ; DE <-- PTR to Dim sizes table + ld (TMP_ARR_PTR), hl ; HL = Array __DATA__.__PTR__ inc hl - ld (TMP_ARR_PTR), hl - ex de, hl - ex (sp), hl ; Return address in HL, array address in the stack - ld (RET_ADDRESS + 1), hl ; Stores it for later + inc hl + ld c, (hl) + inc hl + ld b, (hl) ; BC <-- Array __LBOUND__ PTR + ld (LBOUND_PTR), bc ; Store it for later +#line 66 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + ex de, hl ; HL <-- PTR to Dim sizes table, DE <-- dummy + ex (sp), hl ; Return address in HL, PTR Dim sizes table onto Stack + ld (RET_ADDR), hl ; Stores it for later exx - pop hl ; Will use H'L' as the pointer + pop hl ; Will use H'L' as the pointer to Dim sizes table ld c, (hl) ; Loads Number of dimensions from (hl) inc hl ld b, (hl) inc hl ; Ready exx - ld hl, 0 ; HL = Offset "accumulator" + ld hl, 0 ; HL = Element Offset "accumulator" LOOP: -#line 64 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - pop bc ; Get next index (Ai) from the stack -#line 74 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - add hl, bc ; Adds current index + ex de, hl ; DE = Element Offset + ld hl, (LBOUND_PTR) + ld a, h + or l + ld b, h + ld c, l + jr z, 1f + ld c, (hl) + inc hl + ld b, (hl) + inc hl + ld (LBOUND_PTR), hl +1: + pop hl ; Get next index (Ai) from the stack + sbc hl, bc ; Subtract LBOUND +#line 116 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + add hl, de ; Adds current index exx ; Checks if B'C' = 0 ld a, b ; Which means we must exit (last element is not multiplied by anything) or c jr z, ARRAY_END ; if B'Ci == 0 we are done - ld e, (hl) ; Loads next dimension into D'E' + dec bc ; Decrements loop counter + ld e, (hl) ; Loads next dimension size into D'E' inc hl ld d, (hl) inc hl push de - dec bc ; Decrements loop counter exx pop de ; DE = Max bound Number (i-th dimension) - call __FNMUL + call __FNMUL ; HL <= HL * DE mod 65536 jp LOOP ARRAY_END: ld a, (hl) exx -#line 103 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 146 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl ld hl, 0 @@ -192,7 +217,7 @@ ARRAY_END: ARRAY_SIZE_LOOP: add hl, de djnz ARRAY_SIZE_LOOP -#line 113 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 156 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ex de, hl ld hl, (TMP_ARR_PTR) ld a, (hl) @@ -200,8 +225,9 @@ ARRAY_SIZE_LOOP: ld h, (hl) ld l, a add hl, de ; Adds element start -RET_ADDRESS: - jp 0 + ld de, (RET_ADDR) + push de + ret ;; Performs a faster multiply for little 16bit numbs LOCAL __FNMUL, __FNMUL2 __FNMUL: @@ -218,13 +244,11 @@ __FNMUL2: add hl, de djnz __FNMUL2 ret -TMP_ARR_PTR: - DW 0 ; temporary storage for pointer to tables ENDP pop namespace -#line 67 "opt1_dim_arr_local3.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/arrayalloc.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/calloc.asm" +#line 67 "arch/zx48k/opt1_dim_arr_local3.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/arrayalloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/calloc.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -235,7 +259,7 @@ TMP_ARR_PTR: ; closed source programs). ; ; Please read the MIT license on the internet -#line 1 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -295,7 +319,7 @@ TMP_ARR_PTR: ; HL = BLOCK Start & DE = Length. ; An init directive is useful for initialization routines. ; They will be added automatically if needed. -#line 1 "/zxbasic/src/arch/zx48k/library-asm/error.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/error.asm" ; Simple error control routines ; vim:ts=4:et: push namespace core @@ -329,8 +353,8 @@ __STOP: ld (ERR_NR), a ret pop namespace -#line 69 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/heapinit.asm" +#line 69 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/heapinit.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -437,7 +461,7 @@ __MEM_INIT2: ret ENDP pop namespace -#line 70 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 70 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; --------------------------------------------------------------------- ; MEM_ALLOC ; Allocates a block of memory in the heap. @@ -468,9 +492,9 @@ __MEM_START: __MEM_LOOP: ; Loads lengh at (HL, HL+). If Lenght >= BC, jump to __MEM_DONE ld a, h ; HL = NULL (No memory available?) or l -#line 113 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 113 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ret z ; NULL -#line 115 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 115 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; HL = Pointer to Free block ld e, (hl) inc hl @@ -535,7 +559,7 @@ __MEM_SUBTRACT: ret ENDP pop namespace -#line 13 "/zxbasic/src/arch/zx48k/library-asm/calloc.asm" +#line 13 "/zxbasic/src/lib/arch/zx48k/runtime/calloc.asm" ; --------------------------------------------------------------------- ; MEM_CALLOC ; Allocates a block of memory in the heap, and clears it filling it @@ -569,7 +593,7 @@ __MEM_CALLOC: pop hl ret pop namespace -#line 3 "/zxbasic/src/arch/zx48k/library-asm/arrayalloc.asm" +#line 3 "/zxbasic/src/lib/arch/zx48k/runtime/arrayalloc.asm" ; --------------------------------------------------------------------- ; __ALLOC_LOCAL_ARRAY ; Allocates an array element area in the heap, and clears it filling it @@ -633,10 +657,10 @@ __ALLOC_INITIALIZED_LOCAL_ARRAY: ldir pop hl ; HL = addr of LBound area if used ret -#line 139 "/zxbasic/src/arch/zx48k/library-asm/arrayalloc.asm" +#line 139 "/zxbasic/src/lib/arch/zx48k/runtime/arrayalloc.asm" pop namespace -#line 68 "opt1_dim_arr_local3.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/free.asm" +#line 68 "arch/zx48k/opt1_dim_arr_local3.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/free.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -794,7 +818,7 @@ __MEM_BLOCK_JOIN: ; Joins current block (pointed by HL) with next one (pointed ret ENDP pop namespace -#line 69 "opt1_dim_arr_local3.bas" +#line 69 "arch/zx48k/opt1_dim_arr_local3.bas" .LABEL.__LABEL0: DEFB 00h DEFB 00h diff --git a/tests/functional/arch/zx48k/opt1_dim_arr_local4.asm b/tests/functional/arch/zx48k/opt1_dim_arr_local4.asm index 8f409dd2e..b13d12ad3 100644 --- a/tests/functional/arch/zx48k/opt1_dim_arr_local4.asm +++ b/tests/functional/arch/zx48k/opt1_dim_arr_local4.asm @@ -93,7 +93,7 @@ _test__leave: pop ix ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -109,7 +109,7 @@ _test__leave: ; O = [a0 + b0 * (a1 + b1 * (a2 + ... bN-2(aN-1)))] ; What I will do here is to calculate the following sequence: ; ((aN-1 * bN-2) + aN-2) * bN-3 + ... -#line 1 "/zxbasic/src/arch/zx48k/library-asm/mul16.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/mul16.asm" push namespace core __MUL16: ; Mutiplies HL with the last value stored into de stack ; Works for both signed and unsigned @@ -135,59 +135,84 @@ __MUL16NOADD: ret ; Result in hl (16 lower bits) ENDP pop namespace -#line 20 "/zxbasic/src/arch/zx48k/library-asm/array.asm" -#line 24 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 20 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 24 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" push namespace core __ARRAY_PTR: ;; computes an array offset from a pointer ld c, (hl) inc hl ld h, (hl) - ld l, c + ld l, c ;; HL <-- [HL] __ARRAY: PROC LOCAL LOOP LOCAL ARRAY_END - LOCAL RET_ADDRESS ; Stores return address - LOCAL TMP_ARR_PTR ; Stores pointer temporarily + LOCAL TMP_ARR_PTR ; Ptr to Array DATA region. Stored temporarily + LOCAL LBOUND_PTR, UBOUND_PTR ; LBound and UBound PTR indexes + LOCAL RET_ADDR ; Contains the return address popped from the stack + LBOUND_PTR EQU 23698 ; Uses MEMBOT as a temporary variable + UBOUND_PTR EQU LBOUND_PTR + 2 ; Next 2 bytes for UBOUND PTR + RET_ADDR EQU UBOUND_PTR + 2 ; Next 2 bytes for RET_ADDR + TMP_ARR_PTR EQU RET_ADDR + 2 ; Next 2 bytes for TMP_ARR_PTR ld e, (hl) inc hl ld d, (hl) + inc hl ; DE <-- PTR to Dim sizes table + ld (TMP_ARR_PTR), hl ; HL = Array __DATA__.__PTR__ inc hl - ld (TMP_ARR_PTR), hl - ex de, hl - ex (sp), hl ; Return address in HL, array address in the stack - ld (RET_ADDRESS + 1), hl ; Stores it for later + inc hl + ld c, (hl) + inc hl + ld b, (hl) ; BC <-- Array __LBOUND__ PTR + ld (LBOUND_PTR), bc ; Store it for later +#line 66 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + ex de, hl ; HL <-- PTR to Dim sizes table, DE <-- dummy + ex (sp), hl ; Return address in HL, PTR Dim sizes table onto Stack + ld (RET_ADDR), hl ; Stores it for later exx - pop hl ; Will use H'L' as the pointer + pop hl ; Will use H'L' as the pointer to Dim sizes table ld c, (hl) ; Loads Number of dimensions from (hl) inc hl ld b, (hl) inc hl ; Ready exx - ld hl, 0 ; HL = Offset "accumulator" + ld hl, 0 ; HL = Element Offset "accumulator" LOOP: -#line 64 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - pop bc ; Get next index (Ai) from the stack -#line 74 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - add hl, bc ; Adds current index + ex de, hl ; DE = Element Offset + ld hl, (LBOUND_PTR) + ld a, h + or l + ld b, h + ld c, l + jr z, 1f + ld c, (hl) + inc hl + ld b, (hl) + inc hl + ld (LBOUND_PTR), hl +1: + pop hl ; Get next index (Ai) from the stack + sbc hl, bc ; Subtract LBOUND +#line 116 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + add hl, de ; Adds current index exx ; Checks if B'C' = 0 ld a, b ; Which means we must exit (last element is not multiplied by anything) or c jr z, ARRAY_END ; if B'Ci == 0 we are done - ld e, (hl) ; Loads next dimension into D'E' + dec bc ; Decrements loop counter + ld e, (hl) ; Loads next dimension size into D'E' inc hl ld d, (hl) inc hl push de - dec bc ; Decrements loop counter exx pop de ; DE = Max bound Number (i-th dimension) - call __FNMUL + call __FNMUL ; HL <= HL * DE mod 65536 jp LOOP ARRAY_END: ld a, (hl) exx -#line 103 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 146 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl ld hl, 0 @@ -195,7 +220,7 @@ ARRAY_END: ARRAY_SIZE_LOOP: add hl, de djnz ARRAY_SIZE_LOOP -#line 113 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 156 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ex de, hl ld hl, (TMP_ARR_PTR) ld a, (hl) @@ -203,8 +228,9 @@ ARRAY_SIZE_LOOP: ld h, (hl) ld l, a add hl, de ; Adds element start -RET_ADDRESS: - jp 0 + ld de, (RET_ADDR) + push de + ret ;; Performs a faster multiply for little 16bit numbs LOCAL __FNMUL, __FNMUL2 __FNMUL: @@ -221,13 +247,11 @@ __FNMUL2: add hl, de djnz __FNMUL2 ret -TMP_ARR_PTR: - DW 0 ; temporary storage for pointer to tables ENDP pop namespace -#line 70 "opt1_dim_arr_local4.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/arrayalloc.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/calloc.asm" +#line 70 "arch/zx48k/opt1_dim_arr_local4.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/arrayalloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/calloc.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -238,7 +262,7 @@ TMP_ARR_PTR: ; closed source programs). ; ; Please read the MIT license on the internet -#line 1 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -298,7 +322,7 @@ TMP_ARR_PTR: ; HL = BLOCK Start & DE = Length. ; An init directive is useful for initialization routines. ; They will be added automatically if needed. -#line 1 "/zxbasic/src/arch/zx48k/library-asm/error.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/error.asm" ; Simple error control routines ; vim:ts=4:et: push namespace core @@ -332,8 +356,8 @@ __STOP: ld (ERR_NR), a ret pop namespace -#line 69 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/heapinit.asm" +#line 69 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/heapinit.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -440,7 +464,7 @@ __MEM_INIT2: ret ENDP pop namespace -#line 70 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 70 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; --------------------------------------------------------------------- ; MEM_ALLOC ; Allocates a block of memory in the heap. @@ -471,9 +495,9 @@ __MEM_START: __MEM_LOOP: ; Loads lengh at (HL, HL+). If Lenght >= BC, jump to __MEM_DONE ld a, h ; HL = NULL (No memory available?) or l -#line 113 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 113 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ret z ; NULL -#line 115 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 115 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; HL = Pointer to Free block ld e, (hl) inc hl @@ -538,7 +562,7 @@ __MEM_SUBTRACT: ret ENDP pop namespace -#line 13 "/zxbasic/src/arch/zx48k/library-asm/calloc.asm" +#line 13 "/zxbasic/src/lib/arch/zx48k/runtime/calloc.asm" ; --------------------------------------------------------------------- ; MEM_CALLOC ; Allocates a block of memory in the heap, and clears it filling it @@ -572,7 +596,7 @@ __MEM_CALLOC: pop hl ret pop namespace -#line 3 "/zxbasic/src/arch/zx48k/library-asm/arrayalloc.asm" +#line 3 "/zxbasic/src/lib/arch/zx48k/runtime/arrayalloc.asm" ; --------------------------------------------------------------------- ; __ALLOC_LOCAL_ARRAY ; Allocates an array element area in the heap, and clears it filling it @@ -636,10 +660,10 @@ __ALLOC_INITIALIZED_LOCAL_ARRAY: ldir pop hl ; HL = addr of LBound area if used ret -#line 139 "/zxbasic/src/arch/zx48k/library-asm/arrayalloc.asm" +#line 139 "/zxbasic/src/lib/arch/zx48k/runtime/arrayalloc.asm" pop namespace -#line 71 "opt1_dim_arr_local4.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/free.asm" +#line 71 "arch/zx48k/opt1_dim_arr_local4.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/free.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -797,7 +821,7 @@ __MEM_BLOCK_JOIN: ; Joins current block (pointed by HL) with next one (pointed ret ENDP pop namespace -#line 72 "opt1_dim_arr_local4.bas" +#line 72 "arch/zx48k/opt1_dim_arr_local4.bas" .LABEL.__LABEL0: DEFB 00h DEFB 00h diff --git a/tests/functional/arch/zx48k/opt2_dim_arr_at1.asm b/tests/functional/arch/zx48k/opt2_dim_arr_at1.asm index ea622ab22..db83cee51 100644 --- a/tests/functional/arch/zx48k/opt2_dim_arr_at1.asm +++ b/tests/functional/arch/zx48k/opt2_dim_arr_at1.asm @@ -25,6 +25,8 @@ _a: DEFW .LABEL.__LABEL0 _a.__DATA__.__PTR__: DEFW 30000 + DEFW 0 + DEFW 0 .LABEL.__LABEL0: DEFW 0001h DEFW 0006h diff --git a/tests/functional/arch/zx48k/opt2_global_array2.asm b/tests/functional/arch/zx48k/opt2_global_array2.asm index 0f93eaeda..28555518a 100644 --- a/tests/functional/arch/zx48k/opt2_global_array2.asm +++ b/tests/functional/arch/zx48k/opt2_global_array2.asm @@ -22,6 +22,8 @@ _myArray2: DEFW .LABEL.__LABEL0 _myArray2.__DATA__.__PTR__: DEFW _myArray2.__DATA__ + DEFW _myArray2.__LBOUND__ + DEFW 0 _myArray2.__DATA__: DEFB 00h DEFB 00h @@ -32,6 +34,8 @@ _myArray2.__DATA__: .LABEL.__LABEL0: DEFW 0000h DEFB 01h +_myArray2.__LBOUND__: + DEFW 0001h .core.ZXBASIC_USER_DATA_END: .core.__MAIN_PROGRAM__: call _Init diff --git a/tests/functional/arch/zx48k/opt2_snake_es.asm b/tests/functional/arch/zx48k/opt2_snake_es.asm index 047cb7227..35772aa9e 100644 --- a/tests/functional/arch/zx48k/opt2_snake_es.asm +++ b/tests/functional/arch/zx48k/opt2_snake_es.asm @@ -28,6 +28,8 @@ _y: DEFW .LABEL.__LABEL0 _y.__DATA__.__PTR__: DEFW _y.__DATA__ + DEFW 0 + DEFW 0 _y.__DATA__: DEFB 00h DEFB 00h @@ -187,7 +189,7 @@ _y.__DATA__: ei ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -203,7 +205,7 @@ _y.__DATA__: ; O = [a0 + b0 * (a1 + b1 * (a2 + ... bN-2(aN-1)))] ; What I will do here is to calculate the following sequence: ; ((aN-1 * bN-2) + aN-2) * bN-3 + ... -#line 1 "/zxbasic/src/arch/zx48k/library-asm/mul16.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/mul16.asm" push namespace core __MUL16: ; Mutiplies HL with the last value stored into de stack ; Works for both signed and unsigned @@ -229,59 +231,84 @@ __MUL16NOADD: ret ; Result in hl (16 lower bits) ENDP pop namespace -#line 20 "/zxbasic/src/arch/zx48k/library-asm/array.asm" -#line 24 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 20 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 24 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" push namespace core __ARRAY_PTR: ;; computes an array offset from a pointer ld c, (hl) inc hl ld h, (hl) - ld l, c + ld l, c ;; HL <-- [HL] __ARRAY: PROC LOCAL LOOP LOCAL ARRAY_END - LOCAL RET_ADDRESS ; Stores return address - LOCAL TMP_ARR_PTR ; Stores pointer temporarily + LOCAL TMP_ARR_PTR ; Ptr to Array DATA region. Stored temporarily + LOCAL LBOUND_PTR, UBOUND_PTR ; LBound and UBound PTR indexes + LOCAL RET_ADDR ; Contains the return address popped from the stack + LBOUND_PTR EQU 23698 ; Uses MEMBOT as a temporary variable + UBOUND_PTR EQU LBOUND_PTR + 2 ; Next 2 bytes for UBOUND PTR + RET_ADDR EQU UBOUND_PTR + 2 ; Next 2 bytes for RET_ADDR + TMP_ARR_PTR EQU RET_ADDR + 2 ; Next 2 bytes for TMP_ARR_PTR ld e, (hl) inc hl ld d, (hl) + inc hl ; DE <-- PTR to Dim sizes table + ld (TMP_ARR_PTR), hl ; HL = Array __DATA__.__PTR__ inc hl - ld (TMP_ARR_PTR), hl - ex de, hl - ex (sp), hl ; Return address in HL, array address in the stack - ld (RET_ADDRESS + 1), hl ; Stores it for later + inc hl + ld c, (hl) + inc hl + ld b, (hl) ; BC <-- Array __LBOUND__ PTR + ld (LBOUND_PTR), bc ; Store it for later +#line 66 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + ex de, hl ; HL <-- PTR to Dim sizes table, DE <-- dummy + ex (sp), hl ; Return address in HL, PTR Dim sizes table onto Stack + ld (RET_ADDR), hl ; Stores it for later exx - pop hl ; Will use H'L' as the pointer + pop hl ; Will use H'L' as the pointer to Dim sizes table ld c, (hl) ; Loads Number of dimensions from (hl) inc hl ld b, (hl) inc hl ; Ready exx - ld hl, 0 ; HL = Offset "accumulator" + ld hl, 0 ; HL = Element Offset "accumulator" LOOP: -#line 64 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - pop bc ; Get next index (Ai) from the stack -#line 74 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - add hl, bc ; Adds current index + ex de, hl ; DE = Element Offset + ld hl, (LBOUND_PTR) + ld a, h + or l + ld b, h + ld c, l + jr z, 1f + ld c, (hl) + inc hl + ld b, (hl) + inc hl + ld (LBOUND_PTR), hl +1: + pop hl ; Get next index (Ai) from the stack + sbc hl, bc ; Subtract LBOUND +#line 116 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + add hl, de ; Adds current index exx ; Checks if B'C' = 0 ld a, b ; Which means we must exit (last element is not multiplied by anything) or c jr z, ARRAY_END ; if B'Ci == 0 we are done - ld e, (hl) ; Loads next dimension into D'E' + dec bc ; Decrements loop counter + ld e, (hl) ; Loads next dimension size into D'E' inc hl ld d, (hl) inc hl push de - dec bc ; Decrements loop counter exx pop de ; DE = Max bound Number (i-th dimension) - call __FNMUL + call __FNMUL ; HL <= HL * DE mod 65536 jp LOOP ARRAY_END: ld a, (hl) exx -#line 103 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 146 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl ld hl, 0 @@ -289,7 +316,7 @@ ARRAY_END: ARRAY_SIZE_LOOP: add hl, de djnz ARRAY_SIZE_LOOP -#line 113 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 156 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ex de, hl ld hl, (TMP_ARR_PTR) ld a, (hl) @@ -297,8 +324,9 @@ ARRAY_SIZE_LOOP: ld h, (hl) ld l, a add hl, de ; Adds element start -RET_ADDRESS: - jp 0 + ld de, (RET_ADDR) + push de + ret ;; Performs a faster multiply for little 16bit numbs LOCAL __FNMUL, __FNMUL2 __FNMUL: @@ -315,9 +343,7 @@ __FNMUL2: add hl, de djnz __FNMUL2 ret -TMP_ARR_PTR: - DW 0 ; temporary storage for pointer to tables ENDP pop namespace -#line 33 "opt2_snake_es.bas" +#line 33 "arch/zx48k/opt2_snake_es.bas" END diff --git a/tests/functional/arch/zx48k/opt3_OPT27wws2.asm b/tests/functional/arch/zx48k/opt3_OPT27wws2.asm index e07a21d05..c8b55437d 100644 --- a/tests/functional/arch/zx48k/opt3_OPT27wws2.asm +++ b/tests/functional/arch/zx48k/opt3_OPT27wws2.asm @@ -24,6 +24,8 @@ _yenem: DEFW .LABEL.__LABEL0 _yenem.__DATA__.__PTR__: DEFW _yenem.__DATA__ + DEFW 0 + DEFW 0 _yenem.__DATA__: DEFB 00h DEFB 00h @@ -43,6 +45,8 @@ _incyenem: DEFW .LABEL.__LABEL1 _incyenem.__DATA__.__PTR__: DEFW _incyenem.__DATA__ + DEFW 0 + DEFW 0 _incyenem.__DATA__: DEFB 00h DEFB 00h @@ -92,7 +96,7 @@ _incyenem.__DATA__: ei ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -108,7 +112,7 @@ _incyenem.__DATA__: ; O = [a0 + b0 * (a1 + b1 * (a2 + ... bN-2(aN-1)))] ; What I will do here is to calculate the following sequence: ; ((aN-1 * bN-2) + aN-2) * bN-3 + ... -#line 1 "/zxbasic/src/arch/zx48k/library-asm/mul16.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/mul16.asm" push namespace core __MUL16: ; Mutiplies HL with the last value stored into de stack ; Works for both signed and unsigned @@ -134,59 +138,84 @@ __MUL16NOADD: ret ; Result in hl (16 lower bits) ENDP pop namespace -#line 20 "/zxbasic/src/arch/zx48k/library-asm/array.asm" -#line 24 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 20 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 24 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" push namespace core __ARRAY_PTR: ;; computes an array offset from a pointer ld c, (hl) inc hl ld h, (hl) - ld l, c + ld l, c ;; HL <-- [HL] __ARRAY: PROC LOCAL LOOP LOCAL ARRAY_END - LOCAL RET_ADDRESS ; Stores return address - LOCAL TMP_ARR_PTR ; Stores pointer temporarily + LOCAL TMP_ARR_PTR ; Ptr to Array DATA region. Stored temporarily + LOCAL LBOUND_PTR, UBOUND_PTR ; LBound and UBound PTR indexes + LOCAL RET_ADDR ; Contains the return address popped from the stack + LBOUND_PTR EQU 23698 ; Uses MEMBOT as a temporary variable + UBOUND_PTR EQU LBOUND_PTR + 2 ; Next 2 bytes for UBOUND PTR + RET_ADDR EQU UBOUND_PTR + 2 ; Next 2 bytes for RET_ADDR + TMP_ARR_PTR EQU RET_ADDR + 2 ; Next 2 bytes for TMP_ARR_PTR ld e, (hl) inc hl ld d, (hl) + inc hl ; DE <-- PTR to Dim sizes table + ld (TMP_ARR_PTR), hl ; HL = Array __DATA__.__PTR__ inc hl - ld (TMP_ARR_PTR), hl - ex de, hl - ex (sp), hl ; Return address in HL, array address in the stack - ld (RET_ADDRESS + 1), hl ; Stores it for later + inc hl + ld c, (hl) + inc hl + ld b, (hl) ; BC <-- Array __LBOUND__ PTR + ld (LBOUND_PTR), bc ; Store it for later +#line 66 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + ex de, hl ; HL <-- PTR to Dim sizes table, DE <-- dummy + ex (sp), hl ; Return address in HL, PTR Dim sizes table onto Stack + ld (RET_ADDR), hl ; Stores it for later exx - pop hl ; Will use H'L' as the pointer + pop hl ; Will use H'L' as the pointer to Dim sizes table ld c, (hl) ; Loads Number of dimensions from (hl) inc hl ld b, (hl) inc hl ; Ready exx - ld hl, 0 ; HL = Offset "accumulator" + ld hl, 0 ; HL = Element Offset "accumulator" LOOP: -#line 64 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - pop bc ; Get next index (Ai) from the stack -#line 74 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - add hl, bc ; Adds current index + ex de, hl ; DE = Element Offset + ld hl, (LBOUND_PTR) + ld a, h + or l + ld b, h + ld c, l + jr z, 1f + ld c, (hl) + inc hl + ld b, (hl) + inc hl + ld (LBOUND_PTR), hl +1: + pop hl ; Get next index (Ai) from the stack + sbc hl, bc ; Subtract LBOUND +#line 116 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + add hl, de ; Adds current index exx ; Checks if B'C' = 0 ld a, b ; Which means we must exit (last element is not multiplied by anything) or c jr z, ARRAY_END ; if B'Ci == 0 we are done - ld e, (hl) ; Loads next dimension into D'E' + dec bc ; Decrements loop counter + ld e, (hl) ; Loads next dimension size into D'E' inc hl ld d, (hl) inc hl push de - dec bc ; Decrements loop counter exx pop de ; DE = Max bound Number (i-th dimension) - call __FNMUL + call __FNMUL ; HL <= HL * DE mod 65536 jp LOOP ARRAY_END: ld a, (hl) exx -#line 103 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 146 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl ld hl, 0 @@ -194,7 +223,7 @@ ARRAY_END: ARRAY_SIZE_LOOP: add hl, de djnz ARRAY_SIZE_LOOP -#line 113 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 156 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ex de, hl ld hl, (TMP_ARR_PTR) ld a, (hl) @@ -202,8 +231,9 @@ ARRAY_SIZE_LOOP: ld h, (hl) ld l, a add hl, de ; Adds element start -RET_ADDRESS: - jp 0 + ld de, (RET_ADDR) + push de + ret ;; Performs a faster multiply for little 16bit numbs LOCAL __FNMUL, __FNMUL2 __FNMUL: @@ -220,9 +250,7 @@ __FNMUL2: add hl, de djnz __FNMUL2 ret -TMP_ARR_PTR: - DW 0 ; temporary storage for pointer to tables ENDP pop namespace -#line 34 "opt3_OPT27wws2.bas" +#line 34 "arch/zx48k/opt3_OPT27wws2.bas" END diff --git a/tests/functional/arch/zx48k/opt3_data2.asm b/tests/functional/arch/zx48k/opt3_data2.asm index 5e2fa3371..f97877abc 100644 --- a/tests/functional/arch/zx48k/opt3_data2.asm +++ b/tests/functional/arch/zx48k/opt3_data2.asm @@ -30,6 +30,8 @@ _a: DEFW .LABEL.__LABEL5 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW 0 + DEFW 0 _a.__DATA__: DEFB 00h DEFB 00h @@ -190,52 +192,77 @@ __ARRAY_PTR: ;; computes an array offset from a pointer ld c, (hl) inc hl ld h, (hl) - ld l, c + ld l, c ;; HL <-- [HL] __ARRAY: PROC LOCAL LOOP LOCAL ARRAY_END - LOCAL RET_ADDRESS ; Stores return address - LOCAL TMP_ARR_PTR ; Stores pointer temporarily + LOCAL TMP_ARR_PTR ; Ptr to Array DATA region. Stored temporarily + LOCAL LBOUND_PTR, UBOUND_PTR ; LBound and UBound PTR indexes + LOCAL RET_ADDR ; Contains the return address popped from the stack + LBOUND_PTR EQU 23698 ; Uses MEMBOT as a temporary variable + UBOUND_PTR EQU LBOUND_PTR + 2 ; Next 2 bytes for UBOUND PTR + RET_ADDR EQU UBOUND_PTR + 2 ; Next 2 bytes for RET_ADDR + TMP_ARR_PTR EQU RET_ADDR + 2 ; Next 2 bytes for TMP_ARR_PTR ld e, (hl) inc hl ld d, (hl) + inc hl ; DE <-- PTR to Dim sizes table + ld (TMP_ARR_PTR), hl ; HL = Array __DATA__.__PTR__ inc hl - ld (TMP_ARR_PTR), hl - ex de, hl - ex (sp), hl ; Return address in HL, array address in the stack - ld (RET_ADDRESS + 1), hl ; Stores it for later + inc hl + ld c, (hl) + inc hl + ld b, (hl) ; BC <-- Array __LBOUND__ PTR + ld (LBOUND_PTR), bc ; Store it for later +#line 66 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + ex de, hl ; HL <-- PTR to Dim sizes table, DE <-- dummy + ex (sp), hl ; Return address in HL, PTR Dim sizes table onto Stack + ld (RET_ADDR), hl ; Stores it for later exx - pop hl ; Will use H'L' as the pointer + pop hl ; Will use H'L' as the pointer to Dim sizes table ld c, (hl) ; Loads Number of dimensions from (hl) inc hl ld b, (hl) inc hl ; Ready exx - ld hl, 0 ; HL = Offset "accumulator" + ld hl, 0 ; HL = Element Offset "accumulator" LOOP: -#line 64 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" - pop bc ; Get next index (Ai) from the stack -#line 74 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" - add hl, bc ; Adds current index + ex de, hl ; DE = Element Offset + ld hl, (LBOUND_PTR) + ld a, h + or l + ld b, h + ld c, l + jr z, 1f + ld c, (hl) + inc hl + ld b, (hl) + inc hl + ld (LBOUND_PTR), hl +1: + pop hl ; Get next index (Ai) from the stack + sbc hl, bc ; Subtract LBOUND +#line 116 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + add hl, de ; Adds current index exx ; Checks if B'C' = 0 ld a, b ; Which means we must exit (last element is not multiplied by anything) or c jr z, ARRAY_END ; if B'Ci == 0 we are done - ld e, (hl) ; Loads next dimension into D'E' + dec bc ; Decrements loop counter + ld e, (hl) ; Loads next dimension size into D'E' inc hl ld d, (hl) inc hl push de - dec bc ; Decrements loop counter exx pop de ; DE = Max bound Number (i-th dimension) - call __FNMUL + call __FNMUL ; HL <= HL * DE mod 65536 jp LOOP ARRAY_END: ld a, (hl) exx -#line 103 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 146 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl ld hl, 0 @@ -243,7 +270,7 @@ ARRAY_END: ARRAY_SIZE_LOOP: add hl, de djnz ARRAY_SIZE_LOOP -#line 113 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 156 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ex de, hl ld hl, (TMP_ARR_PTR) ld a, (hl) @@ -251,8 +278,9 @@ ARRAY_SIZE_LOOP: ld h, (hl) ld l, a add hl, de ; Adds element start -RET_ADDRESS: - jp 0 + ld de, (RET_ADDR) + push de + ret ;; Performs a faster multiply for little 16bit numbs LOCAL __FNMUL, __FNMUL2 __FNMUL: @@ -269,8 +297,6 @@ __FNMUL2: add hl, de djnz __FNMUL2 ret -TMP_ARR_PTR: - DW 0 ; temporary storage for pointer to tables ENDP pop namespace #line 97 "arch/zx48k/opt3_data2.bas" diff --git a/tests/functional/arch/zx48k/paramnameclash0.asm b/tests/functional/arch/zx48k/paramnameclash0.asm index b89b8e4e5..9b8392f78 100644 --- a/tests/functional/arch/zx48k/paramnameclash0.asm +++ b/tests/functional/arch/zx48k/paramnameclash0.asm @@ -22,6 +22,8 @@ _a: DEFW .LABEL.__LABEL0 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW 0 + DEFW 0 _a.__DATA__: DEFB 00h DEFB 00h diff --git a/tests/functional/arch/zx48k/pararray0.asm b/tests/functional/arch/zx48k/pararray0.asm index 9158f02ae..ce8f6c2ff 100644 --- a/tests/functional/arch/zx48k/pararray0.asm +++ b/tests/functional/arch/zx48k/pararray0.asm @@ -22,6 +22,8 @@ _q: DEFW .LABEL.__LABEL0 _q.__DATA__.__PTR__: DEFW _q.__DATA__ + DEFW 0 + DEFW 0 _q.__DATA__: DEFB 00h DEFB 00h @@ -91,7 +93,7 @@ _test__leave: exx ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -107,7 +109,7 @@ _test__leave: ; O = [a0 + b0 * (a1 + b1 * (a2 + ... bN-2(aN-1)))] ; What I will do here is to calculate the following sequence: ; ((aN-1 * bN-2) + aN-2) * bN-3 + ... -#line 1 "/zxbasic/src/arch/zx48k/library-asm/mul16.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/mul16.asm" push namespace core __MUL16: ; Mutiplies HL with the last value stored into de stack ; Works for both signed and unsigned @@ -133,59 +135,84 @@ __MUL16NOADD: ret ; Result in hl (16 lower bits) ENDP pop namespace -#line 20 "/zxbasic/src/arch/zx48k/library-asm/array.asm" -#line 24 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 20 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 24 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" push namespace core __ARRAY_PTR: ;; computes an array offset from a pointer ld c, (hl) inc hl ld h, (hl) - ld l, c + ld l, c ;; HL <-- [HL] __ARRAY: PROC LOCAL LOOP LOCAL ARRAY_END - LOCAL RET_ADDRESS ; Stores return address - LOCAL TMP_ARR_PTR ; Stores pointer temporarily + LOCAL TMP_ARR_PTR ; Ptr to Array DATA region. Stored temporarily + LOCAL LBOUND_PTR, UBOUND_PTR ; LBound and UBound PTR indexes + LOCAL RET_ADDR ; Contains the return address popped from the stack + LBOUND_PTR EQU 23698 ; Uses MEMBOT as a temporary variable + UBOUND_PTR EQU LBOUND_PTR + 2 ; Next 2 bytes for UBOUND PTR + RET_ADDR EQU UBOUND_PTR + 2 ; Next 2 bytes for RET_ADDR + TMP_ARR_PTR EQU RET_ADDR + 2 ; Next 2 bytes for TMP_ARR_PTR ld e, (hl) inc hl ld d, (hl) + inc hl ; DE <-- PTR to Dim sizes table + ld (TMP_ARR_PTR), hl ; HL = Array __DATA__.__PTR__ inc hl - ld (TMP_ARR_PTR), hl - ex de, hl - ex (sp), hl ; Return address in HL, array address in the stack - ld (RET_ADDRESS + 1), hl ; Stores it for later + inc hl + ld c, (hl) + inc hl + ld b, (hl) ; BC <-- Array __LBOUND__ PTR + ld (LBOUND_PTR), bc ; Store it for later +#line 66 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + ex de, hl ; HL <-- PTR to Dim sizes table, DE <-- dummy + ex (sp), hl ; Return address in HL, PTR Dim sizes table onto Stack + ld (RET_ADDR), hl ; Stores it for later exx - pop hl ; Will use H'L' as the pointer + pop hl ; Will use H'L' as the pointer to Dim sizes table ld c, (hl) ; Loads Number of dimensions from (hl) inc hl ld b, (hl) inc hl ; Ready exx - ld hl, 0 ; HL = Offset "accumulator" + ld hl, 0 ; HL = Element Offset "accumulator" LOOP: -#line 64 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - pop bc ; Get next index (Ai) from the stack -#line 74 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - add hl, bc ; Adds current index + ex de, hl ; DE = Element Offset + ld hl, (LBOUND_PTR) + ld a, h + or l + ld b, h + ld c, l + jr z, 1f + ld c, (hl) + inc hl + ld b, (hl) + inc hl + ld (LBOUND_PTR), hl +1: + pop hl ; Get next index (Ai) from the stack + sbc hl, bc ; Subtract LBOUND +#line 116 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + add hl, de ; Adds current index exx ; Checks if B'C' = 0 ld a, b ; Which means we must exit (last element is not multiplied by anything) or c jr z, ARRAY_END ; if B'Ci == 0 we are done - ld e, (hl) ; Loads next dimension into D'E' + dec bc ; Decrements loop counter + ld e, (hl) ; Loads next dimension size into D'E' inc hl ld d, (hl) inc hl push de - dec bc ; Decrements loop counter exx pop de ; DE = Max bound Number (i-th dimension) - call __FNMUL + call __FNMUL ; HL <= HL * DE mod 65536 jp LOOP ARRAY_END: ld a, (hl) exx -#line 103 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 146 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl ld hl, 0 @@ -193,7 +220,7 @@ ARRAY_END: ARRAY_SIZE_LOOP: add hl, de djnz ARRAY_SIZE_LOOP -#line 113 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 156 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ex de, hl ld hl, (TMP_ARR_PTR) ld a, (hl) @@ -201,8 +228,9 @@ ARRAY_SIZE_LOOP: ld h, (hl) ld l, a add hl, de ; Adds element start -RET_ADDRESS: - jp 0 + ld de, (RET_ADDR) + push de + ret ;; Performs a faster multiply for little 16bit numbs LOCAL __FNMUL, __FNMUL2 __FNMUL: @@ -219,9 +247,7 @@ __FNMUL2: add hl, de djnz __FNMUL2 ret -TMP_ARR_PTR: - DW 0 ; temporary storage for pointer to tables ENDP pop namespace -#line 43 "pararray0.bas" +#line 43 "arch/zx48k/pararray0.bas" END diff --git a/tests/functional/arch/zx48k/pararray1.asm b/tests/functional/arch/zx48k/pararray1.asm index 9913d9fda..7efaae7cc 100644 --- a/tests/functional/arch/zx48k/pararray1.asm +++ b/tests/functional/arch/zx48k/pararray1.asm @@ -22,6 +22,8 @@ _q: DEFW .LABEL.__LABEL1 _q.__DATA__.__PTR__: DEFW _q.__DATA__ + DEFW 0 + DEFW 0 _q.__DATA__: DEFB 00h DEFB 00h @@ -104,7 +106,7 @@ _test__leave: exx ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -120,7 +122,7 @@ _test__leave: ; O = [a0 + b0 * (a1 + b1 * (a2 + ... bN-2(aN-1)))] ; What I will do here is to calculate the following sequence: ; ((aN-1 * bN-2) + aN-2) * bN-3 + ... -#line 1 "/zxbasic/src/arch/zx48k/library-asm/mul16.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/mul16.asm" push namespace core __MUL16: ; Mutiplies HL with the last value stored into de stack ; Works for both signed and unsigned @@ -146,59 +148,84 @@ __MUL16NOADD: ret ; Result in hl (16 lower bits) ENDP pop namespace -#line 20 "/zxbasic/src/arch/zx48k/library-asm/array.asm" -#line 24 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 20 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 24 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" push namespace core __ARRAY_PTR: ;; computes an array offset from a pointer ld c, (hl) inc hl ld h, (hl) - ld l, c + ld l, c ;; HL <-- [HL] __ARRAY: PROC LOCAL LOOP LOCAL ARRAY_END - LOCAL RET_ADDRESS ; Stores return address - LOCAL TMP_ARR_PTR ; Stores pointer temporarily + LOCAL TMP_ARR_PTR ; Ptr to Array DATA region. Stored temporarily + LOCAL LBOUND_PTR, UBOUND_PTR ; LBound and UBound PTR indexes + LOCAL RET_ADDR ; Contains the return address popped from the stack + LBOUND_PTR EQU 23698 ; Uses MEMBOT as a temporary variable + UBOUND_PTR EQU LBOUND_PTR + 2 ; Next 2 bytes for UBOUND PTR + RET_ADDR EQU UBOUND_PTR + 2 ; Next 2 bytes for RET_ADDR + TMP_ARR_PTR EQU RET_ADDR + 2 ; Next 2 bytes for TMP_ARR_PTR ld e, (hl) inc hl ld d, (hl) + inc hl ; DE <-- PTR to Dim sizes table + ld (TMP_ARR_PTR), hl ; HL = Array __DATA__.__PTR__ inc hl - ld (TMP_ARR_PTR), hl - ex de, hl - ex (sp), hl ; Return address in HL, array address in the stack - ld (RET_ADDRESS + 1), hl ; Stores it for later + inc hl + ld c, (hl) + inc hl + ld b, (hl) ; BC <-- Array __LBOUND__ PTR + ld (LBOUND_PTR), bc ; Store it for later +#line 66 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + ex de, hl ; HL <-- PTR to Dim sizes table, DE <-- dummy + ex (sp), hl ; Return address in HL, PTR Dim sizes table onto Stack + ld (RET_ADDR), hl ; Stores it for later exx - pop hl ; Will use H'L' as the pointer + pop hl ; Will use H'L' as the pointer to Dim sizes table ld c, (hl) ; Loads Number of dimensions from (hl) inc hl ld b, (hl) inc hl ; Ready exx - ld hl, 0 ; HL = Offset "accumulator" + ld hl, 0 ; HL = Element Offset "accumulator" LOOP: -#line 64 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - pop bc ; Get next index (Ai) from the stack -#line 74 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - add hl, bc ; Adds current index + ex de, hl ; DE = Element Offset + ld hl, (LBOUND_PTR) + ld a, h + or l + ld b, h + ld c, l + jr z, 1f + ld c, (hl) + inc hl + ld b, (hl) + inc hl + ld (LBOUND_PTR), hl +1: + pop hl ; Get next index (Ai) from the stack + sbc hl, bc ; Subtract LBOUND +#line 116 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + add hl, de ; Adds current index exx ; Checks if B'C' = 0 ld a, b ; Which means we must exit (last element is not multiplied by anything) or c jr z, ARRAY_END ; if B'Ci == 0 we are done - ld e, (hl) ; Loads next dimension into D'E' + dec bc ; Decrements loop counter + ld e, (hl) ; Loads next dimension size into D'E' inc hl ld d, (hl) inc hl push de - dec bc ; Decrements loop counter exx pop de ; DE = Max bound Number (i-th dimension) - call __FNMUL + call __FNMUL ; HL <= HL * DE mod 65536 jp LOOP ARRAY_END: ld a, (hl) exx -#line 103 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 146 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl ld hl, 0 @@ -206,7 +233,7 @@ ARRAY_END: ARRAY_SIZE_LOOP: add hl, de djnz ARRAY_SIZE_LOOP -#line 113 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 156 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ex de, hl ld hl, (TMP_ARR_PTR) ld a, (hl) @@ -214,8 +241,9 @@ ARRAY_SIZE_LOOP: ld h, (hl) ld l, a add hl, de ; Adds element start -RET_ADDRESS: - jp 0 + ld de, (RET_ADDR) + push de + ret ;; Performs a faster multiply for little 16bit numbs LOCAL __FNMUL, __FNMUL2 __FNMUL: @@ -232,11 +260,9 @@ __FNMUL2: add hl, de djnz __FNMUL2 ret -TMP_ARR_PTR: - DW 0 ; temporary storage for pointer to tables ENDP pop namespace -#line 56 "pararray1.bas" +#line 56 "arch/zx48k/pararray1.bas" .LABEL.__LABEL0: DEFB 03h END diff --git a/tests/functional/arch/zx48k/pararray10.asm b/tests/functional/arch/zx48k/pararray10.asm index 7e8704da5..97c198588 100644 --- a/tests/functional/arch/zx48k/pararray10.asm +++ b/tests/functional/arch/zx48k/pararray10.asm @@ -26,6 +26,8 @@ _a: DEFW .LABEL.__LABEL5 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW 0 + DEFW 0 _a.__DATA__: DEFB 0Ah DEFB 00h @@ -121,7 +123,7 @@ _func2__leave: exx ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -137,7 +139,7 @@ _func2__leave: ; O = [a0 + b0 * (a1 + b1 * (a2 + ... bN-2(aN-1)))] ; What I will do here is to calculate the following sequence: ; ((aN-1 * bN-2) + aN-2) * bN-3 + ... -#line 1 "/zxbasic/src/arch/zx48k/library-asm/mul16.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/mul16.asm" push namespace core __MUL16: ; Mutiplies HL with the last value stored into de stack ; Works for both signed and unsigned @@ -163,59 +165,84 @@ __MUL16NOADD: ret ; Result in hl (16 lower bits) ENDP pop namespace -#line 20 "/zxbasic/src/arch/zx48k/library-asm/array.asm" -#line 24 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 20 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 24 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" push namespace core __ARRAY_PTR: ;; computes an array offset from a pointer ld c, (hl) inc hl ld h, (hl) - ld l, c + ld l, c ;; HL <-- [HL] __ARRAY: PROC LOCAL LOOP LOCAL ARRAY_END - LOCAL RET_ADDRESS ; Stores return address - LOCAL TMP_ARR_PTR ; Stores pointer temporarily + LOCAL TMP_ARR_PTR ; Ptr to Array DATA region. Stored temporarily + LOCAL LBOUND_PTR, UBOUND_PTR ; LBound and UBound PTR indexes + LOCAL RET_ADDR ; Contains the return address popped from the stack + LBOUND_PTR EQU 23698 ; Uses MEMBOT as a temporary variable + UBOUND_PTR EQU LBOUND_PTR + 2 ; Next 2 bytes for UBOUND PTR + RET_ADDR EQU UBOUND_PTR + 2 ; Next 2 bytes for RET_ADDR + TMP_ARR_PTR EQU RET_ADDR + 2 ; Next 2 bytes for TMP_ARR_PTR ld e, (hl) inc hl ld d, (hl) + inc hl ; DE <-- PTR to Dim sizes table + ld (TMP_ARR_PTR), hl ; HL = Array __DATA__.__PTR__ inc hl - ld (TMP_ARR_PTR), hl - ex de, hl - ex (sp), hl ; Return address in HL, array address in the stack - ld (RET_ADDRESS + 1), hl ; Stores it for later + inc hl + ld c, (hl) + inc hl + ld b, (hl) ; BC <-- Array __LBOUND__ PTR + ld (LBOUND_PTR), bc ; Store it for later +#line 66 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + ex de, hl ; HL <-- PTR to Dim sizes table, DE <-- dummy + ex (sp), hl ; Return address in HL, PTR Dim sizes table onto Stack + ld (RET_ADDR), hl ; Stores it for later exx - pop hl ; Will use H'L' as the pointer + pop hl ; Will use H'L' as the pointer to Dim sizes table ld c, (hl) ; Loads Number of dimensions from (hl) inc hl ld b, (hl) inc hl ; Ready exx - ld hl, 0 ; HL = Offset "accumulator" + ld hl, 0 ; HL = Element Offset "accumulator" LOOP: -#line 64 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - pop bc ; Get next index (Ai) from the stack -#line 74 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - add hl, bc ; Adds current index + ex de, hl ; DE = Element Offset + ld hl, (LBOUND_PTR) + ld a, h + or l + ld b, h + ld c, l + jr z, 1f + ld c, (hl) + inc hl + ld b, (hl) + inc hl + ld (LBOUND_PTR), hl +1: + pop hl ; Get next index (Ai) from the stack + sbc hl, bc ; Subtract LBOUND +#line 116 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + add hl, de ; Adds current index exx ; Checks if B'C' = 0 ld a, b ; Which means we must exit (last element is not multiplied by anything) or c jr z, ARRAY_END ; if B'Ci == 0 we are done - ld e, (hl) ; Loads next dimension into D'E' + dec bc ; Decrements loop counter + ld e, (hl) ; Loads next dimension size into D'E' inc hl ld d, (hl) inc hl push de - dec bc ; Decrements loop counter exx pop de ; DE = Max bound Number (i-th dimension) - call __FNMUL + call __FNMUL ; HL <= HL * DE mod 65536 jp LOOP ARRAY_END: ld a, (hl) exx -#line 103 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 146 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl ld hl, 0 @@ -223,7 +250,7 @@ ARRAY_END: ARRAY_SIZE_LOOP: add hl, de djnz ARRAY_SIZE_LOOP -#line 113 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 156 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ex de, hl ld hl, (TMP_ARR_PTR) ld a, (hl) @@ -231,8 +258,9 @@ ARRAY_SIZE_LOOP: ld h, (hl) ld l, a add hl, de ; Adds element start -RET_ADDRESS: - jp 0 + ld de, (RET_ADDR) + push de + ret ;; Performs a faster multiply for little 16bit numbs LOCAL __FNMUL, __FNMUL2 __FNMUL: @@ -249,9 +277,7 @@ __FNMUL2: add hl, de djnz __FNMUL2 ret -TMP_ARR_PTR: - DW 0 ; temporary storage for pointer to tables ENDP pop namespace -#line 83 "pararray10.bas" +#line 83 "arch/zx48k/pararray10.bas" END diff --git a/tests/functional/arch/zx48k/pararray11.asm b/tests/functional/arch/zx48k/pararray11.asm index 06fee1def..2fefd3c54 100644 --- a/tests/functional/arch/zx48k/pararray11.asm +++ b/tests/functional/arch/zx48k/pararray11.asm @@ -147,7 +147,7 @@ _func3__leave: pop ix ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -163,7 +163,7 @@ _func3__leave: ; O = [a0 + b0 * (a1 + b1 * (a2 + ... bN-2(aN-1)))] ; What I will do here is to calculate the following sequence: ; ((aN-1 * bN-2) + aN-2) * bN-3 + ... -#line 1 "/zxbasic/src/arch/zx48k/library-asm/mul16.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/mul16.asm" push namespace core __MUL16: ; Mutiplies HL with the last value stored into de stack ; Works for both signed and unsigned @@ -189,59 +189,84 @@ __MUL16NOADD: ret ; Result in hl (16 lower bits) ENDP pop namespace -#line 20 "/zxbasic/src/arch/zx48k/library-asm/array.asm" -#line 24 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 20 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 24 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" push namespace core __ARRAY_PTR: ;; computes an array offset from a pointer ld c, (hl) inc hl ld h, (hl) - ld l, c + ld l, c ;; HL <-- [HL] __ARRAY: PROC LOCAL LOOP LOCAL ARRAY_END - LOCAL RET_ADDRESS ; Stores return address - LOCAL TMP_ARR_PTR ; Stores pointer temporarily + LOCAL TMP_ARR_PTR ; Ptr to Array DATA region. Stored temporarily + LOCAL LBOUND_PTR, UBOUND_PTR ; LBound and UBound PTR indexes + LOCAL RET_ADDR ; Contains the return address popped from the stack + LBOUND_PTR EQU 23698 ; Uses MEMBOT as a temporary variable + UBOUND_PTR EQU LBOUND_PTR + 2 ; Next 2 bytes for UBOUND PTR + RET_ADDR EQU UBOUND_PTR + 2 ; Next 2 bytes for RET_ADDR + TMP_ARR_PTR EQU RET_ADDR + 2 ; Next 2 bytes for TMP_ARR_PTR ld e, (hl) inc hl ld d, (hl) + inc hl ; DE <-- PTR to Dim sizes table + ld (TMP_ARR_PTR), hl ; HL = Array __DATA__.__PTR__ inc hl - ld (TMP_ARR_PTR), hl - ex de, hl - ex (sp), hl ; Return address in HL, array address in the stack - ld (RET_ADDRESS + 1), hl ; Stores it for later + inc hl + ld c, (hl) + inc hl + ld b, (hl) ; BC <-- Array __LBOUND__ PTR + ld (LBOUND_PTR), bc ; Store it for later +#line 66 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + ex de, hl ; HL <-- PTR to Dim sizes table, DE <-- dummy + ex (sp), hl ; Return address in HL, PTR Dim sizes table onto Stack + ld (RET_ADDR), hl ; Stores it for later exx - pop hl ; Will use H'L' as the pointer + pop hl ; Will use H'L' as the pointer to Dim sizes table ld c, (hl) ; Loads Number of dimensions from (hl) inc hl ld b, (hl) inc hl ; Ready exx - ld hl, 0 ; HL = Offset "accumulator" + ld hl, 0 ; HL = Element Offset "accumulator" LOOP: -#line 64 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - pop bc ; Get next index (Ai) from the stack -#line 74 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - add hl, bc ; Adds current index + ex de, hl ; DE = Element Offset + ld hl, (LBOUND_PTR) + ld a, h + or l + ld b, h + ld c, l + jr z, 1f + ld c, (hl) + inc hl + ld b, (hl) + inc hl + ld (LBOUND_PTR), hl +1: + pop hl ; Get next index (Ai) from the stack + sbc hl, bc ; Subtract LBOUND +#line 116 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + add hl, de ; Adds current index exx ; Checks if B'C' = 0 ld a, b ; Which means we must exit (last element is not multiplied by anything) or c jr z, ARRAY_END ; if B'Ci == 0 we are done - ld e, (hl) ; Loads next dimension into D'E' + dec bc ; Decrements loop counter + ld e, (hl) ; Loads next dimension size into D'E' inc hl ld d, (hl) inc hl push de - dec bc ; Decrements loop counter exx pop de ; DE = Max bound Number (i-th dimension) - call __FNMUL + call __FNMUL ; HL <= HL * DE mod 65536 jp LOOP ARRAY_END: ld a, (hl) exx -#line 103 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 146 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl ld hl, 0 @@ -249,7 +274,7 @@ ARRAY_END: ARRAY_SIZE_LOOP: add hl, de djnz ARRAY_SIZE_LOOP -#line 113 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 156 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ex de, hl ld hl, (TMP_ARR_PTR) ld a, (hl) @@ -257,8 +282,9 @@ ARRAY_SIZE_LOOP: ld h, (hl) ld l, a add hl, de ; Adds element start -RET_ADDRESS: - jp 0 + ld de, (RET_ADDR) + push de + ret ;; Performs a faster multiply for little 16bit numbs LOCAL __FNMUL, __FNMUL2 __FNMUL: @@ -275,13 +301,11 @@ __FNMUL2: add hl, de djnz __FNMUL2 ret -TMP_ARR_PTR: - DW 0 ; temporary storage for pointer to tables ENDP pop namespace -#line 124 "pararray11.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/arrayalloc.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/calloc.asm" +#line 124 "arch/zx48k/pararray11.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/arrayalloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/calloc.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -292,7 +316,7 @@ TMP_ARR_PTR: ; closed source programs). ; ; Please read the MIT license on the internet -#line 1 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -352,7 +376,7 @@ TMP_ARR_PTR: ; HL = BLOCK Start & DE = Length. ; An init directive is useful for initialization routines. ; They will be added automatically if needed. -#line 1 "/zxbasic/src/arch/zx48k/library-asm/error.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/error.asm" ; Simple error control routines ; vim:ts=4:et: push namespace core @@ -386,8 +410,8 @@ __STOP: ld (ERR_NR), a ret pop namespace -#line 69 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/heapinit.asm" +#line 69 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/heapinit.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -494,7 +518,7 @@ __MEM_INIT2: ret ENDP pop namespace -#line 70 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 70 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; --------------------------------------------------------------------- ; MEM_ALLOC ; Allocates a block of memory in the heap. @@ -525,9 +549,9 @@ __MEM_START: __MEM_LOOP: ; Loads lengh at (HL, HL+). If Lenght >= BC, jump to __MEM_DONE ld a, h ; HL = NULL (No memory available?) or l -#line 113 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 113 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ret z ; NULL -#line 115 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 115 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; HL = Pointer to Free block ld e, (hl) inc hl @@ -592,7 +616,7 @@ __MEM_SUBTRACT: ret ENDP pop namespace -#line 13 "/zxbasic/src/arch/zx48k/library-asm/calloc.asm" +#line 13 "/zxbasic/src/lib/arch/zx48k/runtime/calloc.asm" ; --------------------------------------------------------------------- ; MEM_CALLOC ; Allocates a block of memory in the heap, and clears it filling it @@ -626,7 +650,7 @@ __MEM_CALLOC: pop hl ret pop namespace -#line 3 "/zxbasic/src/arch/zx48k/library-asm/arrayalloc.asm" +#line 3 "/zxbasic/src/lib/arch/zx48k/runtime/arrayalloc.asm" ; --------------------------------------------------------------------- ; __ALLOC_LOCAL_ARRAY ; Allocates an array element area in the heap, and clears it filling it @@ -690,10 +714,10 @@ __ALLOC_INITIALIZED_LOCAL_ARRAY: ldir pop hl ; HL = addr of LBound area if used ret -#line 139 "/zxbasic/src/arch/zx48k/library-asm/arrayalloc.asm" +#line 139 "/zxbasic/src/lib/arch/zx48k/runtime/arrayalloc.asm" pop namespace -#line 125 "pararray11.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/free.asm" +#line 125 "arch/zx48k/pararray11.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/free.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -851,7 +875,7 @@ __MEM_BLOCK_JOIN: ; Joins current block (pointed by HL) with next one (pointed ret ENDP pop namespace -#line 126 "pararray11.bas" +#line 126 "arch/zx48k/pararray11.bas" .LABEL.__LABEL5: DEFB 00h DEFB 00h diff --git a/tests/functional/arch/zx48k/pararray5.asm b/tests/functional/arch/zx48k/pararray5.asm index ab161d393..8d5ab9c42 100644 --- a/tests/functional/arch/zx48k/pararray5.asm +++ b/tests/functional/arch/zx48k/pararray5.asm @@ -22,6 +22,8 @@ _q: DEFW .LABEL.__LABEL1 _q.__DATA__.__PTR__: DEFW _q.__DATA__ + DEFW 0 + DEFW 0 _q.__DATA__: DEFB 00h DEFB 00h @@ -104,7 +106,7 @@ _test__leave: exx ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -120,7 +122,7 @@ _test__leave: ; O = [a0 + b0 * (a1 + b1 * (a2 + ... bN-2(aN-1)))] ; What I will do here is to calculate the following sequence: ; ((aN-1 * bN-2) + aN-2) * bN-3 + ... -#line 1 "/zxbasic/src/arch/zx48k/library-asm/mul16.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/mul16.asm" push namespace core __MUL16: ; Mutiplies HL with the last value stored into de stack ; Works for both signed and unsigned @@ -146,59 +148,84 @@ __MUL16NOADD: ret ; Result in hl (16 lower bits) ENDP pop namespace -#line 20 "/zxbasic/src/arch/zx48k/library-asm/array.asm" -#line 24 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 20 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 24 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" push namespace core __ARRAY_PTR: ;; computes an array offset from a pointer ld c, (hl) inc hl ld h, (hl) - ld l, c + ld l, c ;; HL <-- [HL] __ARRAY: PROC LOCAL LOOP LOCAL ARRAY_END - LOCAL RET_ADDRESS ; Stores return address - LOCAL TMP_ARR_PTR ; Stores pointer temporarily + LOCAL TMP_ARR_PTR ; Ptr to Array DATA region. Stored temporarily + LOCAL LBOUND_PTR, UBOUND_PTR ; LBound and UBound PTR indexes + LOCAL RET_ADDR ; Contains the return address popped from the stack + LBOUND_PTR EQU 23698 ; Uses MEMBOT as a temporary variable + UBOUND_PTR EQU LBOUND_PTR + 2 ; Next 2 bytes for UBOUND PTR + RET_ADDR EQU UBOUND_PTR + 2 ; Next 2 bytes for RET_ADDR + TMP_ARR_PTR EQU RET_ADDR + 2 ; Next 2 bytes for TMP_ARR_PTR ld e, (hl) inc hl ld d, (hl) + inc hl ; DE <-- PTR to Dim sizes table + ld (TMP_ARR_PTR), hl ; HL = Array __DATA__.__PTR__ inc hl - ld (TMP_ARR_PTR), hl - ex de, hl - ex (sp), hl ; Return address in HL, array address in the stack - ld (RET_ADDRESS + 1), hl ; Stores it for later + inc hl + ld c, (hl) + inc hl + ld b, (hl) ; BC <-- Array __LBOUND__ PTR + ld (LBOUND_PTR), bc ; Store it for later +#line 66 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + ex de, hl ; HL <-- PTR to Dim sizes table, DE <-- dummy + ex (sp), hl ; Return address in HL, PTR Dim sizes table onto Stack + ld (RET_ADDR), hl ; Stores it for later exx - pop hl ; Will use H'L' as the pointer + pop hl ; Will use H'L' as the pointer to Dim sizes table ld c, (hl) ; Loads Number of dimensions from (hl) inc hl ld b, (hl) inc hl ; Ready exx - ld hl, 0 ; HL = Offset "accumulator" + ld hl, 0 ; HL = Element Offset "accumulator" LOOP: -#line 64 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - pop bc ; Get next index (Ai) from the stack -#line 74 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - add hl, bc ; Adds current index + ex de, hl ; DE = Element Offset + ld hl, (LBOUND_PTR) + ld a, h + or l + ld b, h + ld c, l + jr z, 1f + ld c, (hl) + inc hl + ld b, (hl) + inc hl + ld (LBOUND_PTR), hl +1: + pop hl ; Get next index (Ai) from the stack + sbc hl, bc ; Subtract LBOUND +#line 116 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + add hl, de ; Adds current index exx ; Checks if B'C' = 0 ld a, b ; Which means we must exit (last element is not multiplied by anything) or c jr z, ARRAY_END ; if B'Ci == 0 we are done - ld e, (hl) ; Loads next dimension into D'E' + dec bc ; Decrements loop counter + ld e, (hl) ; Loads next dimension size into D'E' inc hl ld d, (hl) inc hl push de - dec bc ; Decrements loop counter exx pop de ; DE = Max bound Number (i-th dimension) - call __FNMUL + call __FNMUL ; HL <= HL * DE mod 65536 jp LOOP ARRAY_END: ld a, (hl) exx -#line 103 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 146 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl ld hl, 0 @@ -206,7 +233,7 @@ ARRAY_END: ARRAY_SIZE_LOOP: add hl, de djnz ARRAY_SIZE_LOOP -#line 113 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 156 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ex de, hl ld hl, (TMP_ARR_PTR) ld a, (hl) @@ -214,8 +241,9 @@ ARRAY_SIZE_LOOP: ld h, (hl) ld l, a add hl, de ; Adds element start -RET_ADDRESS: - jp 0 + ld de, (RET_ADDR) + push de + ret ;; Performs a faster multiply for little 16bit numbs LOCAL __FNMUL, __FNMUL2 __FNMUL: @@ -232,11 +260,9 @@ __FNMUL2: add hl, de djnz __FNMUL2 ret -TMP_ARR_PTR: - DW 0 ; temporary storage for pointer to tables ENDP pop namespace -#line 56 "pararray5.bas" +#line 56 "arch/zx48k/pararray5.bas" .LABEL.__LABEL0: DEFB 03h END diff --git a/tests/functional/arch/zx48k/pararray6.asm b/tests/functional/arch/zx48k/pararray6.asm index 2fdd795f1..0851302a0 100644 --- a/tests/functional/arch/zx48k/pararray6.asm +++ b/tests/functional/arch/zx48k/pararray6.asm @@ -22,6 +22,8 @@ _q: DEFW .LABEL.__LABEL1 _q.__DATA__.__PTR__: DEFW _q.__DATA__ + DEFW 0 + DEFW 0 _q.__DATA__: DEFB 00h DEFB 00h @@ -107,7 +109,7 @@ _test__leave: exx ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -123,7 +125,7 @@ _test__leave: ; O = [a0 + b0 * (a1 + b1 * (a2 + ... bN-2(aN-1)))] ; What I will do here is to calculate the following sequence: ; ((aN-1 * bN-2) + aN-2) * bN-3 + ... -#line 1 "/zxbasic/src/arch/zx48k/library-asm/mul16.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/mul16.asm" push namespace core __MUL16: ; Mutiplies HL with the last value stored into de stack ; Works for both signed and unsigned @@ -149,59 +151,84 @@ __MUL16NOADD: ret ; Result in hl (16 lower bits) ENDP pop namespace -#line 20 "/zxbasic/src/arch/zx48k/library-asm/array.asm" -#line 24 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 20 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 24 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" push namespace core __ARRAY_PTR: ;; computes an array offset from a pointer ld c, (hl) inc hl ld h, (hl) - ld l, c + ld l, c ;; HL <-- [HL] __ARRAY: PROC LOCAL LOOP LOCAL ARRAY_END - LOCAL RET_ADDRESS ; Stores return address - LOCAL TMP_ARR_PTR ; Stores pointer temporarily + LOCAL TMP_ARR_PTR ; Ptr to Array DATA region. Stored temporarily + LOCAL LBOUND_PTR, UBOUND_PTR ; LBound and UBound PTR indexes + LOCAL RET_ADDR ; Contains the return address popped from the stack + LBOUND_PTR EQU 23698 ; Uses MEMBOT as a temporary variable + UBOUND_PTR EQU LBOUND_PTR + 2 ; Next 2 bytes for UBOUND PTR + RET_ADDR EQU UBOUND_PTR + 2 ; Next 2 bytes for RET_ADDR + TMP_ARR_PTR EQU RET_ADDR + 2 ; Next 2 bytes for TMP_ARR_PTR ld e, (hl) inc hl ld d, (hl) + inc hl ; DE <-- PTR to Dim sizes table + ld (TMP_ARR_PTR), hl ; HL = Array __DATA__.__PTR__ inc hl - ld (TMP_ARR_PTR), hl - ex de, hl - ex (sp), hl ; Return address in HL, array address in the stack - ld (RET_ADDRESS + 1), hl ; Stores it for later + inc hl + ld c, (hl) + inc hl + ld b, (hl) ; BC <-- Array __LBOUND__ PTR + ld (LBOUND_PTR), bc ; Store it for later +#line 66 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + ex de, hl ; HL <-- PTR to Dim sizes table, DE <-- dummy + ex (sp), hl ; Return address in HL, PTR Dim sizes table onto Stack + ld (RET_ADDR), hl ; Stores it for later exx - pop hl ; Will use H'L' as the pointer + pop hl ; Will use H'L' as the pointer to Dim sizes table ld c, (hl) ; Loads Number of dimensions from (hl) inc hl ld b, (hl) inc hl ; Ready exx - ld hl, 0 ; HL = Offset "accumulator" + ld hl, 0 ; HL = Element Offset "accumulator" LOOP: -#line 64 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - pop bc ; Get next index (Ai) from the stack -#line 74 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - add hl, bc ; Adds current index + ex de, hl ; DE = Element Offset + ld hl, (LBOUND_PTR) + ld a, h + or l + ld b, h + ld c, l + jr z, 1f + ld c, (hl) + inc hl + ld b, (hl) + inc hl + ld (LBOUND_PTR), hl +1: + pop hl ; Get next index (Ai) from the stack + sbc hl, bc ; Subtract LBOUND +#line 116 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + add hl, de ; Adds current index exx ; Checks if B'C' = 0 ld a, b ; Which means we must exit (last element is not multiplied by anything) or c jr z, ARRAY_END ; if B'Ci == 0 we are done - ld e, (hl) ; Loads next dimension into D'E' + dec bc ; Decrements loop counter + ld e, (hl) ; Loads next dimension size into D'E' inc hl ld d, (hl) inc hl push de - dec bc ; Decrements loop counter exx pop de ; DE = Max bound Number (i-th dimension) - call __FNMUL + call __FNMUL ; HL <= HL * DE mod 65536 jp LOOP ARRAY_END: ld a, (hl) exx -#line 103 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 146 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl ld hl, 0 @@ -209,7 +236,7 @@ ARRAY_END: ARRAY_SIZE_LOOP: add hl, de djnz ARRAY_SIZE_LOOP -#line 113 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 156 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ex de, hl ld hl, (TMP_ARR_PTR) ld a, (hl) @@ -217,8 +244,9 @@ ARRAY_SIZE_LOOP: ld h, (hl) ld l, a add hl, de ; Adds element start -RET_ADDRESS: - jp 0 + ld de, (RET_ADDR) + push de + ret ;; Performs a faster multiply for little 16bit numbs LOCAL __FNMUL, __FNMUL2 __FNMUL: @@ -235,11 +263,9 @@ __FNMUL2: add hl, de djnz __FNMUL2 ret -TMP_ARR_PTR: - DW 0 ; temporary storage for pointer to tables ENDP pop namespace -#line 59 "pararray6.bas" +#line 59 "arch/zx48k/pararray6.bas" .LABEL.__LABEL0: DEFB 03h END diff --git a/tests/functional/arch/zx48k/pararray7.asm b/tests/functional/arch/zx48k/pararray7.asm index 3f3ac07cf..e3a85192f 100644 --- a/tests/functional/arch/zx48k/pararray7.asm +++ b/tests/functional/arch/zx48k/pararray7.asm @@ -22,6 +22,8 @@ _z: DEFW .LABEL.__LABEL1 _z.__DATA__.__PTR__: DEFW _z.__DATA__ + DEFW 0 + DEFW 0 _z.__DATA__: DEFB 00h DEFB 00h @@ -61,6 +63,8 @@ _q: DEFW .LABEL.__LABEL2 _q.__DATA__.__PTR__: DEFW _q.__DATA__ + DEFW 0 + DEFW 0 _q.__DATA__: DEFB 00h DEFB 00h @@ -158,7 +162,7 @@ _test__leave: exx ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -174,7 +178,7 @@ _test__leave: ; O = [a0 + b0 * (a1 + b1 * (a2 + ... bN-2(aN-1)))] ; What I will do here is to calculate the following sequence: ; ((aN-1 * bN-2) + aN-2) * bN-3 + ... -#line 1 "/zxbasic/src/arch/zx48k/library-asm/mul16.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/mul16.asm" push namespace core __MUL16: ; Mutiplies HL with the last value stored into de stack ; Works for both signed and unsigned @@ -200,59 +204,84 @@ __MUL16NOADD: ret ; Result in hl (16 lower bits) ENDP pop namespace -#line 20 "/zxbasic/src/arch/zx48k/library-asm/array.asm" -#line 24 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 20 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 24 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" push namespace core __ARRAY_PTR: ;; computes an array offset from a pointer ld c, (hl) inc hl ld h, (hl) - ld l, c + ld l, c ;; HL <-- [HL] __ARRAY: PROC LOCAL LOOP LOCAL ARRAY_END - LOCAL RET_ADDRESS ; Stores return address - LOCAL TMP_ARR_PTR ; Stores pointer temporarily + LOCAL TMP_ARR_PTR ; Ptr to Array DATA region. Stored temporarily + LOCAL LBOUND_PTR, UBOUND_PTR ; LBound and UBound PTR indexes + LOCAL RET_ADDR ; Contains the return address popped from the stack + LBOUND_PTR EQU 23698 ; Uses MEMBOT as a temporary variable + UBOUND_PTR EQU LBOUND_PTR + 2 ; Next 2 bytes for UBOUND PTR + RET_ADDR EQU UBOUND_PTR + 2 ; Next 2 bytes for RET_ADDR + TMP_ARR_PTR EQU RET_ADDR + 2 ; Next 2 bytes for TMP_ARR_PTR ld e, (hl) inc hl ld d, (hl) + inc hl ; DE <-- PTR to Dim sizes table + ld (TMP_ARR_PTR), hl ; HL = Array __DATA__.__PTR__ inc hl - ld (TMP_ARR_PTR), hl - ex de, hl - ex (sp), hl ; Return address in HL, array address in the stack - ld (RET_ADDRESS + 1), hl ; Stores it for later + inc hl + ld c, (hl) + inc hl + ld b, (hl) ; BC <-- Array __LBOUND__ PTR + ld (LBOUND_PTR), bc ; Store it for later +#line 66 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + ex de, hl ; HL <-- PTR to Dim sizes table, DE <-- dummy + ex (sp), hl ; Return address in HL, PTR Dim sizes table onto Stack + ld (RET_ADDR), hl ; Stores it for later exx - pop hl ; Will use H'L' as the pointer + pop hl ; Will use H'L' as the pointer to Dim sizes table ld c, (hl) ; Loads Number of dimensions from (hl) inc hl ld b, (hl) inc hl ; Ready exx - ld hl, 0 ; HL = Offset "accumulator" + ld hl, 0 ; HL = Element Offset "accumulator" LOOP: -#line 64 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - pop bc ; Get next index (Ai) from the stack -#line 74 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - add hl, bc ; Adds current index + ex de, hl ; DE = Element Offset + ld hl, (LBOUND_PTR) + ld a, h + or l + ld b, h + ld c, l + jr z, 1f + ld c, (hl) + inc hl + ld b, (hl) + inc hl + ld (LBOUND_PTR), hl +1: + pop hl ; Get next index (Ai) from the stack + sbc hl, bc ; Subtract LBOUND +#line 116 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + add hl, de ; Adds current index exx ; Checks if B'C' = 0 ld a, b ; Which means we must exit (last element is not multiplied by anything) or c jr z, ARRAY_END ; if B'Ci == 0 we are done - ld e, (hl) ; Loads next dimension into D'E' + dec bc ; Decrements loop counter + ld e, (hl) ; Loads next dimension size into D'E' inc hl ld d, (hl) inc hl push de - dec bc ; Decrements loop counter exx pop de ; DE = Max bound Number (i-th dimension) - call __FNMUL + call __FNMUL ; HL <= HL * DE mod 65536 jp LOOP ARRAY_END: ld a, (hl) exx -#line 103 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 146 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl ld hl, 0 @@ -260,7 +289,7 @@ ARRAY_END: ARRAY_SIZE_LOOP: add hl, de djnz ARRAY_SIZE_LOOP -#line 113 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 156 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ex de, hl ld hl, (TMP_ARR_PTR) ld a, (hl) @@ -268,8 +297,9 @@ ARRAY_SIZE_LOOP: ld h, (hl) ld l, a add hl, de ; Adds element start -RET_ADDRESS: - jp 0 + ld de, (RET_ADDR) + push de + ret ;; Performs a faster multiply for little 16bit numbs LOCAL __FNMUL, __FNMUL2 __FNMUL: @@ -286,11 +316,9 @@ __FNMUL2: add hl, de djnz __FNMUL2 ret -TMP_ARR_PTR: - DW 0 ; temporary storage for pointer to tables ENDP pop namespace -#line 71 "pararray7.bas" +#line 71 "arch/zx48k/pararray7.bas" .LABEL.__LABEL0: DEFB 03h END diff --git a/tests/functional/arch/zx48k/pararray8.asm b/tests/functional/arch/zx48k/pararray8.asm index 818f06ae2..c2e8da9ac 100644 --- a/tests/functional/arch/zx48k/pararray8.asm +++ b/tests/functional/arch/zx48k/pararray8.asm @@ -24,6 +24,8 @@ _a: DEFW .LABEL.__LABEL7 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW 0 + DEFW 0 _a.__DATA__: DEFB 04h DEFB 03h @@ -118,7 +120,7 @@ _max__leave: exx ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -134,7 +136,7 @@ _max__leave: ; O = [a0 + b0 * (a1 + b1 * (a2 + ... bN-2(aN-1)))] ; What I will do here is to calculate the following sequence: ; ((aN-1 * bN-2) + aN-2) * bN-3 + ... -#line 1 "/zxbasic/src/arch/zx48k/library-asm/mul16.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/mul16.asm" push namespace core __MUL16: ; Mutiplies HL with the last value stored into de stack ; Works for both signed and unsigned @@ -160,59 +162,84 @@ __MUL16NOADD: ret ; Result in hl (16 lower bits) ENDP pop namespace -#line 20 "/zxbasic/src/arch/zx48k/library-asm/array.asm" -#line 24 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 20 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 24 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" push namespace core __ARRAY_PTR: ;; computes an array offset from a pointer ld c, (hl) inc hl ld h, (hl) - ld l, c + ld l, c ;; HL <-- [HL] __ARRAY: PROC LOCAL LOOP LOCAL ARRAY_END - LOCAL RET_ADDRESS ; Stores return address - LOCAL TMP_ARR_PTR ; Stores pointer temporarily + LOCAL TMP_ARR_PTR ; Ptr to Array DATA region. Stored temporarily + LOCAL LBOUND_PTR, UBOUND_PTR ; LBound and UBound PTR indexes + LOCAL RET_ADDR ; Contains the return address popped from the stack + LBOUND_PTR EQU 23698 ; Uses MEMBOT as a temporary variable + UBOUND_PTR EQU LBOUND_PTR + 2 ; Next 2 bytes for UBOUND PTR + RET_ADDR EQU UBOUND_PTR + 2 ; Next 2 bytes for RET_ADDR + TMP_ARR_PTR EQU RET_ADDR + 2 ; Next 2 bytes for TMP_ARR_PTR ld e, (hl) inc hl ld d, (hl) + inc hl ; DE <-- PTR to Dim sizes table + ld (TMP_ARR_PTR), hl ; HL = Array __DATA__.__PTR__ inc hl - ld (TMP_ARR_PTR), hl - ex de, hl - ex (sp), hl ; Return address in HL, array address in the stack - ld (RET_ADDRESS + 1), hl ; Stores it for later + inc hl + ld c, (hl) + inc hl + ld b, (hl) ; BC <-- Array __LBOUND__ PTR + ld (LBOUND_PTR), bc ; Store it for later +#line 66 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + ex de, hl ; HL <-- PTR to Dim sizes table, DE <-- dummy + ex (sp), hl ; Return address in HL, PTR Dim sizes table onto Stack + ld (RET_ADDR), hl ; Stores it for later exx - pop hl ; Will use H'L' as the pointer + pop hl ; Will use H'L' as the pointer to Dim sizes table ld c, (hl) ; Loads Number of dimensions from (hl) inc hl ld b, (hl) inc hl ; Ready exx - ld hl, 0 ; HL = Offset "accumulator" + ld hl, 0 ; HL = Element Offset "accumulator" LOOP: -#line 64 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - pop bc ; Get next index (Ai) from the stack -#line 74 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - add hl, bc ; Adds current index + ex de, hl ; DE = Element Offset + ld hl, (LBOUND_PTR) + ld a, h + or l + ld b, h + ld c, l + jr z, 1f + ld c, (hl) + inc hl + ld b, (hl) + inc hl + ld (LBOUND_PTR), hl +1: + pop hl ; Get next index (Ai) from the stack + sbc hl, bc ; Subtract LBOUND +#line 116 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + add hl, de ; Adds current index exx ; Checks if B'C' = 0 ld a, b ; Which means we must exit (last element is not multiplied by anything) or c jr z, ARRAY_END ; if B'Ci == 0 we are done - ld e, (hl) ; Loads next dimension into D'E' + dec bc ; Decrements loop counter + ld e, (hl) ; Loads next dimension size into D'E' inc hl ld d, (hl) inc hl push de - dec bc ; Decrements loop counter exx pop de ; DE = Max bound Number (i-th dimension) - call __FNMUL + call __FNMUL ; HL <= HL * DE mod 65536 jp LOOP ARRAY_END: ld a, (hl) exx -#line 103 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 146 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl ld hl, 0 @@ -220,7 +247,7 @@ ARRAY_END: ARRAY_SIZE_LOOP: add hl, de djnz ARRAY_SIZE_LOOP -#line 113 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 156 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ex de, hl ld hl, (TMP_ARR_PTR) ld a, (hl) @@ -228,8 +255,9 @@ ARRAY_SIZE_LOOP: ld h, (hl) ld l, a add hl, de ; Adds element start -RET_ADDRESS: - jp 0 + ld de, (RET_ADDR) + push de + ret ;; Performs a faster multiply for little 16bit numbs LOCAL __FNMUL, __FNMUL2 __FNMUL: @@ -246,9 +274,7 @@ __FNMUL2: add hl, de djnz __FNMUL2 ret -TMP_ARR_PTR: - DW 0 ; temporary storage for pointer to tables ENDP pop namespace -#line 84 "pararray8.bas" +#line 84 "arch/zx48k/pararray8.bas" END diff --git a/tests/functional/arch/zx48k/pararray9.asm b/tests/functional/arch/zx48k/pararray9.asm index 9ccd65bb0..bc6a07103 100644 --- a/tests/functional/arch/zx48k/pararray9.asm +++ b/tests/functional/arch/zx48k/pararray9.asm @@ -22,6 +22,8 @@ _q: DEFW .LABEL.__LABEL0 _q.__DATA__.__PTR__: DEFW _q.__DATA__ + DEFW 0 + DEFW 0 _q.__DATA__: DEFB 00h DEFB 00h @@ -91,7 +93,7 @@ _test__leave: exx ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -107,7 +109,7 @@ _test__leave: ; O = [a0 + b0 * (a1 + b1 * (a2 + ... bN-2(aN-1)))] ; What I will do here is to calculate the following sequence: ; ((aN-1 * bN-2) + aN-2) * bN-3 + ... -#line 1 "/zxbasic/src/arch/zx48k/library-asm/mul16.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/mul16.asm" push namespace core __MUL16: ; Mutiplies HL with the last value stored into de stack ; Works for both signed and unsigned @@ -133,59 +135,84 @@ __MUL16NOADD: ret ; Result in hl (16 lower bits) ENDP pop namespace -#line 20 "/zxbasic/src/arch/zx48k/library-asm/array.asm" -#line 24 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 20 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 24 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" push namespace core __ARRAY_PTR: ;; computes an array offset from a pointer ld c, (hl) inc hl ld h, (hl) - ld l, c + ld l, c ;; HL <-- [HL] __ARRAY: PROC LOCAL LOOP LOCAL ARRAY_END - LOCAL RET_ADDRESS ; Stores return address - LOCAL TMP_ARR_PTR ; Stores pointer temporarily + LOCAL TMP_ARR_PTR ; Ptr to Array DATA region. Stored temporarily + LOCAL LBOUND_PTR, UBOUND_PTR ; LBound and UBound PTR indexes + LOCAL RET_ADDR ; Contains the return address popped from the stack + LBOUND_PTR EQU 23698 ; Uses MEMBOT as a temporary variable + UBOUND_PTR EQU LBOUND_PTR + 2 ; Next 2 bytes for UBOUND PTR + RET_ADDR EQU UBOUND_PTR + 2 ; Next 2 bytes for RET_ADDR + TMP_ARR_PTR EQU RET_ADDR + 2 ; Next 2 bytes for TMP_ARR_PTR ld e, (hl) inc hl ld d, (hl) + inc hl ; DE <-- PTR to Dim sizes table + ld (TMP_ARR_PTR), hl ; HL = Array __DATA__.__PTR__ inc hl - ld (TMP_ARR_PTR), hl - ex de, hl - ex (sp), hl ; Return address in HL, array address in the stack - ld (RET_ADDRESS + 1), hl ; Stores it for later + inc hl + ld c, (hl) + inc hl + ld b, (hl) ; BC <-- Array __LBOUND__ PTR + ld (LBOUND_PTR), bc ; Store it for later +#line 66 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + ex de, hl ; HL <-- PTR to Dim sizes table, DE <-- dummy + ex (sp), hl ; Return address in HL, PTR Dim sizes table onto Stack + ld (RET_ADDR), hl ; Stores it for later exx - pop hl ; Will use H'L' as the pointer + pop hl ; Will use H'L' as the pointer to Dim sizes table ld c, (hl) ; Loads Number of dimensions from (hl) inc hl ld b, (hl) inc hl ; Ready exx - ld hl, 0 ; HL = Offset "accumulator" + ld hl, 0 ; HL = Element Offset "accumulator" LOOP: -#line 64 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - pop bc ; Get next index (Ai) from the stack -#line 74 "/zxbasic/src/arch/zx48k/library-asm/array.asm" - add hl, bc ; Adds current index + ex de, hl ; DE = Element Offset + ld hl, (LBOUND_PTR) + ld a, h + or l + ld b, h + ld c, l + jr z, 1f + ld c, (hl) + inc hl + ld b, (hl) + inc hl + ld (LBOUND_PTR), hl +1: + pop hl ; Get next index (Ai) from the stack + sbc hl, bc ; Subtract LBOUND +#line 116 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + add hl, de ; Adds current index exx ; Checks if B'C' = 0 ld a, b ; Which means we must exit (last element is not multiplied by anything) or c jr z, ARRAY_END ; if B'Ci == 0 we are done - ld e, (hl) ; Loads next dimension into D'E' + dec bc ; Decrements loop counter + ld e, (hl) ; Loads next dimension size into D'E' inc hl ld d, (hl) inc hl push de - dec bc ; Decrements loop counter exx pop de ; DE = Max bound Number (i-th dimension) - call __FNMUL + call __FNMUL ; HL <= HL * DE mod 65536 jp LOOP ARRAY_END: ld a, (hl) exx -#line 103 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 146 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl ld hl, 0 @@ -193,7 +220,7 @@ ARRAY_END: ARRAY_SIZE_LOOP: add hl, de djnz ARRAY_SIZE_LOOP -#line 113 "/zxbasic/src/arch/zx48k/library-asm/array.asm" +#line 156 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ex de, hl ld hl, (TMP_ARR_PTR) ld a, (hl) @@ -201,8 +228,9 @@ ARRAY_SIZE_LOOP: ld h, (hl) ld l, a add hl, de ; Adds element start -RET_ADDRESS: - jp 0 + ld de, (RET_ADDR) + push de + ret ;; Performs a faster multiply for little 16bit numbs LOCAL __FNMUL, __FNMUL2 __FNMUL: @@ -219,9 +247,7 @@ __FNMUL2: add hl, de djnz __FNMUL2 ret -TMP_ARR_PTR: - DW 0 ; temporary storage for pointer to tables ENDP pop namespace -#line 43 "pararray9.bas" +#line 43 "arch/zx48k/pararray9.bas" END diff --git a/tests/functional/arch/zx48k/print_arrstr.asm b/tests/functional/arch/zx48k/print_arrstr.asm index ddda44e4e..2a3958761 100644 --- a/tests/functional/arch/zx48k/print_arrstr.asm +++ b/tests/functional/arch/zx48k/print_arrstr.asm @@ -28,6 +28,8 @@ _a: DEFW .LABEL.__LABEL1 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW 0 + DEFW 0 _a.__DATA__: DEFB 00h DEFB 00h diff --git a/tests/functional/arch/zx48k/read13.asm b/tests/functional/arch/zx48k/read13.asm index 06ffbe861..1fe75d2e8 100644 --- a/tests/functional/arch/zx48k/read13.asm +++ b/tests/functional/arch/zx48k/read13.asm @@ -35,6 +35,8 @@ _c: DEFW .LABEL.__LABEL5 _c.__DATA__.__PTR__: DEFW _c.__DATA__ + DEFW 0 + DEFW 0 _c.__DATA__: DEFB 00h DEFB 00h @@ -215,52 +217,77 @@ __ARRAY_PTR: ;; computes an array offset from a pointer ld c, (hl) inc hl ld h, (hl) - ld l, c + ld l, c ;; HL <-- [HL] __ARRAY: PROC LOCAL LOOP LOCAL ARRAY_END - LOCAL RET_ADDRESS ; Stores return address - LOCAL TMP_ARR_PTR ; Stores pointer temporarily + LOCAL TMP_ARR_PTR ; Ptr to Array DATA region. Stored temporarily + LOCAL LBOUND_PTR, UBOUND_PTR ; LBound and UBound PTR indexes + LOCAL RET_ADDR ; Contains the return address popped from the stack + LBOUND_PTR EQU 23698 ; Uses MEMBOT as a temporary variable + UBOUND_PTR EQU LBOUND_PTR + 2 ; Next 2 bytes for UBOUND PTR + RET_ADDR EQU UBOUND_PTR + 2 ; Next 2 bytes for RET_ADDR + TMP_ARR_PTR EQU RET_ADDR + 2 ; Next 2 bytes for TMP_ARR_PTR ld e, (hl) inc hl ld d, (hl) + inc hl ; DE <-- PTR to Dim sizes table + ld (TMP_ARR_PTR), hl ; HL = Array __DATA__.__PTR__ inc hl - ld (TMP_ARR_PTR), hl - ex de, hl - ex (sp), hl ; Return address in HL, array address in the stack - ld (RET_ADDRESS + 1), hl ; Stores it for later + inc hl + ld c, (hl) + inc hl + ld b, (hl) ; BC <-- Array __LBOUND__ PTR + ld (LBOUND_PTR), bc ; Store it for later +#line 66 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + ex de, hl ; HL <-- PTR to Dim sizes table, DE <-- dummy + ex (sp), hl ; Return address in HL, PTR Dim sizes table onto Stack + ld (RET_ADDR), hl ; Stores it for later exx - pop hl ; Will use H'L' as the pointer + pop hl ; Will use H'L' as the pointer to Dim sizes table ld c, (hl) ; Loads Number of dimensions from (hl) inc hl ld b, (hl) inc hl ; Ready exx - ld hl, 0 ; HL = Offset "accumulator" + ld hl, 0 ; HL = Element Offset "accumulator" LOOP: -#line 64 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" - pop bc ; Get next index (Ai) from the stack -#line 74 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" - add hl, bc ; Adds current index + ex de, hl ; DE = Element Offset + ld hl, (LBOUND_PTR) + ld a, h + or l + ld b, h + ld c, l + jr z, 1f + ld c, (hl) + inc hl + ld b, (hl) + inc hl + ld (LBOUND_PTR), hl +1: + pop hl ; Get next index (Ai) from the stack + sbc hl, bc ; Subtract LBOUND +#line 116 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + add hl, de ; Adds current index exx ; Checks if B'C' = 0 ld a, b ; Which means we must exit (last element is not multiplied by anything) or c jr z, ARRAY_END ; if B'Ci == 0 we are done - ld e, (hl) ; Loads next dimension into D'E' + dec bc ; Decrements loop counter + ld e, (hl) ; Loads next dimension size into D'E' inc hl ld d, (hl) inc hl push de - dec bc ; Decrements loop counter exx pop de ; DE = Max bound Number (i-th dimension) - call __FNMUL + call __FNMUL ; HL <= HL * DE mod 65536 jp LOOP ARRAY_END: ld a, (hl) exx -#line 103 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 146 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl ld hl, 0 @@ -268,7 +295,7 @@ ARRAY_END: ARRAY_SIZE_LOOP: add hl, de djnz ARRAY_SIZE_LOOP -#line 113 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 156 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ex de, hl ld hl, (TMP_ARR_PTR) ld a, (hl) @@ -276,8 +303,9 @@ ARRAY_SIZE_LOOP: ld h, (hl) ld l, a add hl, de ; Adds element start -RET_ADDRESS: - jp 0 + ld de, (RET_ADDR) + push de + ret ;; Performs a faster multiply for little 16bit numbs LOCAL __FNMUL, __FNMUL2 __FNMUL: @@ -294,8 +322,6 @@ __FNMUL2: add hl, de djnz __FNMUL2 ret -TMP_ARR_PTR: - DW 0 ; temporary storage for pointer to tables ENDP pop namespace #line 111 "arch/zx48k/read13.bas" diff --git a/tests/functional/arch/zx48k/read4.asm b/tests/functional/arch/zx48k/read4.asm index 3059248e4..edd582dac 100644 --- a/tests/functional/arch/zx48k/read4.asm +++ b/tests/functional/arch/zx48k/read4.asm @@ -33,6 +33,8 @@ _x: DEFW .LABEL.__LABEL1 _x.__DATA__.__PTR__: DEFW _x.__DATA__ + DEFW 0 + DEFW 0 _x.__DATA__: DEFB 00h DEFB 00h @@ -151,8 +153,8 @@ __DATA__END: DEFB 6Ch DEFB 6Fh ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/loadstr.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/loadstr.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -212,7 +214,7 @@ __DATA__END: ; HL = BLOCK Start & DE = Length. ; An init directive is useful for initialization routines. ; They will be added automatically if needed. -#line 1 "/zxbasic/src/arch/zx48k/library-asm/error.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/error.asm" ; Simple error control routines ; vim:ts=4:et: push namespace core @@ -246,8 +248,8 @@ __STOP: ld (ERR_NR), a ret pop namespace -#line 69 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/heapinit.asm" +#line 69 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/heapinit.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -354,7 +356,7 @@ __MEM_INIT2: ret ENDP pop namespace -#line 70 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 70 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; --------------------------------------------------------------------- ; MEM_ALLOC ; Allocates a block of memory in the heap. @@ -385,9 +387,9 @@ __MEM_START: __MEM_LOOP: ; Loads lengh at (HL, HL+). If Lenght >= BC, jump to __MEM_DONE ld a, h ; HL = NULL (No memory available?) or l -#line 113 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 113 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ret z ; NULL -#line 115 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm" +#line 115 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm" ; HL = Pointer to Free block ld e, (hl) inc hl @@ -452,7 +454,7 @@ __MEM_SUBTRACT: ret ENDP pop namespace -#line 2 "/zxbasic/src/arch/zx48k/library-asm/loadstr.asm" +#line 2 "/zxbasic/src/lib/arch/zx48k/runtime/loadstr.asm" ; Loads a string (ptr) from HL ; and duplicates it on dynamic memory again ; Finally, it returns result pointer in HL @@ -489,9 +491,9 @@ __LOADSTR: ; __FASTCALL__ entry pop hl ; Recovers destiny in hl as result ret pop namespace -#line 89 "read4.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/mulf.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/stackf.asm" +#line 89 "arch/zx48k/read4.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/mulf.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/stackf.asm" ; ------------------------------------------------------------- ; Functions to manage FP-Stack of the ZX Spectrum ROM CALC ; ------------------------------------------------------------- @@ -530,7 +532,7 @@ __FPSTACK_I16: ; Pushes 16 bits integer in HL into the FP ROM STACK ld b, a jp __FPSTACK_PUSH pop namespace -#line 2 "/zxbasic/src/arch/zx48k/library-asm/mulf.asm" +#line 2 "/zxbasic/src/lib/arch/zx48k/runtime/mulf.asm" ; ------------------------------------------------------------- ; Floating point library using the FP ROM Calculator (ZX 48K) ; All of them uses A EDCB registers as 1st paramter. @@ -548,8 +550,8 @@ __MULF: ; Multiplication defb 38h; ; END CALC jp __FPSTACK_POP pop namespace -#line 90 "read4.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/pow.asm" +#line 90 "arch/zx48k/read4.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/pow.asm" ; ------------------------------------------------------------- ; Floating point library using the FP ROM Calculator (ZX 48K) ; All of them uses A EDCB registers as 1st paramter. @@ -574,8 +576,8 @@ __POW: ; Exponentiation jp __FPSTACK_POP ENDP pop namespace -#line 91 "read4.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/pushf.asm" +#line 91 "arch/zx48k/read4.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/pushf.asm" ; Routine to push Float pointed by HL ; Into the stack. Notice that the hl points to the last ; byte of the FP number. @@ -602,8 +604,8 @@ __FP_PUSH_REV: exx ret pop namespace -#line 92 "read4.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/read_restore.asm" +#line 92 "arch/zx48k/read4.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/read_restore.asm" ;; This implements READ & RESTORE functions ;; Reads a new element from the DATA Address code ;; Updates the DATA_ADDR read ptr for the next read @@ -621,7 +623,7 @@ __FP_PUSH_REV: ;; 09: Float ;; bit7 is set for a parameter-less function ;; In that case, the next two bytes are the ptr of the function to jump -#line 1 "/zxbasic/src/arch/zx48k/library-asm/iload32.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/iload32.asm" ; __FASTCALL__ routine which ; loads a 32 bits integer into DE,HL ; stored at position pointed by POINTER HL @@ -639,8 +641,8 @@ __ILOAD32: ex de, hl ret pop namespace -#line 25 "/zxbasic/src/arch/zx48k/library-asm/read_restore.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/iloadf.asm" +#line 25 "/zxbasic/src/lib/arch/zx48k/runtime/read_restore.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/iloadf.asm" ; __FASTCALL__ routine which ; loads a 40 bits floating point into A ED CB ; stored at position pointed by POINTER HL @@ -667,10 +669,10 @@ __LOADF: ; Loads a 40 bits FP number from address pointed by HL ld b, (hl) ret pop namespace -#line 26 "/zxbasic/src/arch/zx48k/library-asm/read_restore.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/ftof16reg.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/ftou32reg.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/neg32.asm" +#line 26 "/zxbasic/src/lib/arch/zx48k/runtime/read_restore.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/ftof16reg.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/ftou32reg.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/neg32.asm" push namespace core __ABS32: bit 7, d @@ -695,7 +697,7 @@ __NEG32: ; Negates DEHL (Two's complement) inc de ret pop namespace -#line 2 "/zxbasic/src/arch/zx48k/library-asm/ftou32reg.asm" +#line 2 "/zxbasic/src/lib/arch/zx48k/runtime/ftou32reg.asm" push namespace core __FTOU32REG: ; Converts a Float to (un)signed 32 bit integer (NOTE: It's ALWAYS 32 bit signed) ; Input FP number in A EDCB (A exponent, EDCB mantissa) @@ -767,7 +769,7 @@ __FTOU8: ; Converts float in C ED LH to Unsigned byte in A ld a, l ret pop namespace -#line 2 "/zxbasic/src/arch/zx48k/library-asm/ftof16reg.asm" +#line 2 "/zxbasic/src/lib/arch/zx48k/runtime/ftof16reg.asm" push namespace core __FTOF16REG: ; Converts a Float to 16.16 (32 bit) fixed point decimal ; Input FP number in A EDCB (A exponent, EDCB mantissa) @@ -798,9 +800,9 @@ __FTOF16REG: ; Converts a Float to 16.16 (32 bit) fixed point decimal ld b, a ; Loop counter = exponent - 128 + 16 (we need to shift 16 bit more) jp __FTOU32REG_LOOP ; proceed as an u32 integer pop namespace -#line 27 "/zxbasic/src/arch/zx48k/library-asm/read_restore.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/f16tofreg.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/u32tofreg.asm" +#line 27 "/zxbasic/src/lib/arch/zx48k/runtime/read_restore.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/f16tofreg.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/u32tofreg.asm" push namespace core __I8TOFREG: ld l, a @@ -870,7 +872,7 @@ __U32TOFREG_END: ret ENDP pop namespace -#line 3 "/zxbasic/src/arch/zx48k/library-asm/f16tofreg.asm" +#line 3 "/zxbasic/src/lib/arch/zx48k/runtime/f16tofreg.asm" push namespace core __F16TOFREG: ; Converts a 16.16 signed fixed point (stored in DEHL) ; to a Floating Point Number returned in (C ED CB) @@ -905,8 +907,8 @@ __F16TOFREG2: ; Converts an unsigned 32 bit integer (DEHL) jp __U32TOFREG_LOOP ; Proceed as an integer ENDP pop namespace -#line 28 "/zxbasic/src/arch/zx48k/library-asm/read_restore.asm" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/free.asm" +#line 28 "/zxbasic/src/lib/arch/zx48k/runtime/read_restore.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/free.asm" ; vim: ts=4:et:sw=4: ; Copyleft (K) by Jose M. Rodriguez de la Rosa ; (a.k.a. Boriel) @@ -1064,16 +1066,16 @@ __MEM_BLOCK_JOIN: ; Joins current block (pointed by HL) with next one (pointed ret ENDP pop namespace -#line 29 "/zxbasic/src/arch/zx48k/library-asm/read_restore.asm" -#line 31 "/zxbasic/src/arch/zx48k/library-asm/read_restore.asm" -#line 32 "/zxbasic/src/arch/zx48k/library-asm/read_restore.asm" -#line 33 "/zxbasic/src/arch/zx48k/library-asm/read_restore.asm" -#line 34 "/zxbasic/src/arch/zx48k/library-asm/read_restore.asm" -#line 35 "/zxbasic/src/arch/zx48k/library-asm/read_restore.asm" -#line 36 "/zxbasic/src/arch/zx48k/library-asm/read_restore.asm" -#line 37 "/zxbasic/src/arch/zx48k/library-asm/read_restore.asm" -#line 38 "/zxbasic/src/arch/zx48k/library-asm/read_restore.asm" -#line 39 "/zxbasic/src/arch/zx48k/library-asm/read_restore.asm" +#line 29 "/zxbasic/src/lib/arch/zx48k/runtime/read_restore.asm" +#line 31 "/zxbasic/src/lib/arch/zx48k/runtime/read_restore.asm" +#line 32 "/zxbasic/src/lib/arch/zx48k/runtime/read_restore.asm" +#line 33 "/zxbasic/src/lib/arch/zx48k/runtime/read_restore.asm" +#line 34 "/zxbasic/src/lib/arch/zx48k/runtime/read_restore.asm" +#line 35 "/zxbasic/src/lib/arch/zx48k/runtime/read_restore.asm" +#line 36 "/zxbasic/src/lib/arch/zx48k/runtime/read_restore.asm" +#line 37 "/zxbasic/src/lib/arch/zx48k/runtime/read_restore.asm" +#line 38 "/zxbasic/src/lib/arch/zx48k/runtime/read_restore.asm" +#line 39 "/zxbasic/src/lib/arch/zx48k/runtime/read_restore.asm" ;; Updates restore point to the given HL mem. address push namespace core __RESTORE: @@ -1353,8 +1355,8 @@ __DATA_ADDR: ;; Stores current DATA ptr dw .DATA.__DATA__0 ENDP pop namespace -#line 93 "read4.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/sin.asm" +#line 93 "arch/zx48k/read4.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/sin.asm" push namespace core SIN: ; Computes SIN using ROM FP-CALC call __FPSTACK_PUSH @@ -1363,8 +1365,8 @@ SIN: ; Computes SIN using ROM FP-CALC defb 38h ; END CALC jp __FPSTACK_POP pop namespace -#line 94 "read4.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/storef.asm" +#line 94 "arch/zx48k/read4.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/storef.asm" push namespace core __PISTOREF: ; Indect Stores a float (A, E, D, C, B) at location stored in memory, pointed by (IX + HL) push de @@ -1392,8 +1394,8 @@ __STOREF: ; Stores the given FP number in A EDCB at address HL ld (hl), b ret pop namespace -#line 95 "read4.bas" -#line 1 "/zxbasic/src/arch/zx48k/library-asm/tan.asm" +#line 95 "arch/zx48k/read4.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/tan.asm" push namespace core TAN: ; Computes TAN using ROM FP-CALC call __FPSTACK_PUSH @@ -1402,5 +1404,5 @@ TAN: ; Computes TAN using ROM FP-CALC defb 38h ; END CALC jp __FPSTACK_POP pop namespace -#line 96 "read4.bas" +#line 96 "arch/zx48k/read4.bas" END diff --git a/tests/functional/arch/zx48k/read8.asm b/tests/functional/arch/zx48k/read8.asm index e51ec2be0..cf308dd02 100644 --- a/tests/functional/arch/zx48k/read8.asm +++ b/tests/functional/arch/zx48k/read8.asm @@ -36,6 +36,8 @@ _c: DEFW .LABEL.__LABEL5 _c.__DATA__.__PTR__: DEFW _c.__DATA__ + DEFW 0 + DEFW 0 _c.__DATA__: DEFB 00h DEFB 00h diff --git a/tests/functional/arch/zx48k/read9.asm b/tests/functional/arch/zx48k/read9.asm index ab13f8938..413ec28e0 100644 --- a/tests/functional/arch/zx48k/read9.asm +++ b/tests/functional/arch/zx48k/read9.asm @@ -36,6 +36,8 @@ _c: DEFW .LABEL.__LABEL5 _c.__DATA__.__PTR__: DEFW _c.__DATA__ + DEFW 0 + DEFW 0 _c.__DATA__: DEFB 00h DEFB 00h @@ -225,52 +227,77 @@ __ARRAY_PTR: ;; computes an array offset from a pointer ld c, (hl) inc hl ld h, (hl) - ld l, c + ld l, c ;; HL <-- [HL] __ARRAY: PROC LOCAL LOOP LOCAL ARRAY_END - LOCAL RET_ADDRESS ; Stores return address - LOCAL TMP_ARR_PTR ; Stores pointer temporarily + LOCAL TMP_ARR_PTR ; Ptr to Array DATA region. Stored temporarily + LOCAL LBOUND_PTR, UBOUND_PTR ; LBound and UBound PTR indexes + LOCAL RET_ADDR ; Contains the return address popped from the stack + LBOUND_PTR EQU 23698 ; Uses MEMBOT as a temporary variable + UBOUND_PTR EQU LBOUND_PTR + 2 ; Next 2 bytes for UBOUND PTR + RET_ADDR EQU UBOUND_PTR + 2 ; Next 2 bytes for RET_ADDR + TMP_ARR_PTR EQU RET_ADDR + 2 ; Next 2 bytes for TMP_ARR_PTR ld e, (hl) inc hl ld d, (hl) + inc hl ; DE <-- PTR to Dim sizes table + ld (TMP_ARR_PTR), hl ; HL = Array __DATA__.__PTR__ inc hl - ld (TMP_ARR_PTR), hl - ex de, hl - ex (sp), hl ; Return address in HL, array address in the stack - ld (RET_ADDRESS + 1), hl ; Stores it for later + inc hl + ld c, (hl) + inc hl + ld b, (hl) ; BC <-- Array __LBOUND__ PTR + ld (LBOUND_PTR), bc ; Store it for later +#line 66 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + ex de, hl ; HL <-- PTR to Dim sizes table, DE <-- dummy + ex (sp), hl ; Return address in HL, PTR Dim sizes table onto Stack + ld (RET_ADDR), hl ; Stores it for later exx - pop hl ; Will use H'L' as the pointer + pop hl ; Will use H'L' as the pointer to Dim sizes table ld c, (hl) ; Loads Number of dimensions from (hl) inc hl ld b, (hl) inc hl ; Ready exx - ld hl, 0 ; HL = Offset "accumulator" + ld hl, 0 ; HL = Element Offset "accumulator" LOOP: -#line 64 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" - pop bc ; Get next index (Ai) from the stack -#line 74 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" - add hl, bc ; Adds current index + ex de, hl ; DE = Element Offset + ld hl, (LBOUND_PTR) + ld a, h + or l + ld b, h + ld c, l + jr z, 1f + ld c, (hl) + inc hl + ld b, (hl) + inc hl + ld (LBOUND_PTR), hl +1: + pop hl ; Get next index (Ai) from the stack + sbc hl, bc ; Subtract LBOUND +#line 116 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" + add hl, de ; Adds current index exx ; Checks if B'C' = 0 ld a, b ; Which means we must exit (last element is not multiplied by anything) or c jr z, ARRAY_END ; if B'Ci == 0 we are done - ld e, (hl) ; Loads next dimension into D'E' + dec bc ; Decrements loop counter + ld e, (hl) ; Loads next dimension size into D'E' inc hl ld d, (hl) inc hl push de - dec bc ; Decrements loop counter exx pop de ; DE = Max bound Number (i-th dimension) - call __FNMUL + call __FNMUL ; HL <= HL * DE mod 65536 jp LOOP ARRAY_END: ld a, (hl) exx -#line 103 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 146 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl ld hl, 0 @@ -278,7 +305,7 @@ ARRAY_END: ARRAY_SIZE_LOOP: add hl, de djnz ARRAY_SIZE_LOOP -#line 113 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" +#line 156 "/zxbasic/src/lib/arch/zx48k/runtime/array.asm" ex de, hl ld hl, (TMP_ARR_PTR) ld a, (hl) @@ -286,8 +313,9 @@ ARRAY_SIZE_LOOP: ld h, (hl) ld l, a add hl, de ; Adds element start -RET_ADDRESS: - jp 0 + ld de, (RET_ADDR) + push de + ret ;; Performs a faster multiply for little 16bit numbs LOCAL __FNMUL, __FNMUL2 __FNMUL: @@ -304,8 +332,6 @@ __FNMUL2: add hl, de djnz __FNMUL2 ret -TMP_ARR_PTR: - DW 0 ; temporary storage for pointer to tables ENDP pop namespace #line 116 "arch/zx48k/read9.bas" diff --git a/tests/functional/arch/zx48k/str_base0.asm b/tests/functional/arch/zx48k/str_base0.asm index 928b43526..b8674d15b 100644 --- a/tests/functional/arch/zx48k/str_base0.asm +++ b/tests/functional/arch/zx48k/str_base0.asm @@ -27,6 +27,8 @@ _a: DEFW .LABEL.__LABEL2 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW 0 + DEFW 0 _a.__DATA__: DEFB 00h DEFB 00h diff --git a/tests/functional/arch/zx48k/str_base1.asm b/tests/functional/arch/zx48k/str_base1.asm index 335259283..9eba471e1 100644 --- a/tests/functional/arch/zx48k/str_base1.asm +++ b/tests/functional/arch/zx48k/str_base1.asm @@ -27,6 +27,8 @@ _a: DEFW .LABEL.__LABEL2 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW 0 + DEFW 0 _a.__DATA__: DEFB 00h DEFB 00h diff --git a/tests/functional/arch/zx48k/str_base2.asm b/tests/functional/arch/zx48k/str_base2.asm index 09726dba8..a4363f829 100644 --- a/tests/functional/arch/zx48k/str_base2.asm +++ b/tests/functional/arch/zx48k/str_base2.asm @@ -27,6 +27,8 @@ _a: DEFW .LABEL.__LABEL2 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW 0 + DEFW 0 _a.__DATA__: DEFB 00h DEFB 00h diff --git a/tests/functional/arch/zx48k/str_base3.asm b/tests/functional/arch/zx48k/str_base3.asm index 8cb57cc05..7b87888a3 100644 --- a/tests/functional/arch/zx48k/str_base3.asm +++ b/tests/functional/arch/zx48k/str_base3.asm @@ -27,6 +27,8 @@ _a: DEFW .LABEL.__LABEL2 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW 0 + DEFW 0 _a.__DATA__: DEFB 00h DEFB 00h diff --git a/tests/functional/arch/zx48k/str_base4.asm b/tests/functional/arch/zx48k/str_base4.asm index 761d3305e..be4466de3 100644 --- a/tests/functional/arch/zx48k/str_base4.asm +++ b/tests/functional/arch/zx48k/str_base4.asm @@ -27,6 +27,8 @@ _a: DEFW .LABEL.__LABEL2 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW 0 + DEFW 0 _a.__DATA__: DEFB 00h DEFB 00h diff --git a/tests/functional/arch/zx48k/str_base5.asm b/tests/functional/arch/zx48k/str_base5.asm index 278e08dc1..48277717d 100644 --- a/tests/functional/arch/zx48k/str_base5.asm +++ b/tests/functional/arch/zx48k/str_base5.asm @@ -27,6 +27,8 @@ _a: DEFW .LABEL.__LABEL2 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW 0 + DEFW 0 _a.__DATA__: DEFB 00h DEFB 00h diff --git a/tests/functional/arch/zx48k/sys_letarrsubstr0.asm b/tests/functional/arch/zx48k/sys_letarrsubstr0.asm index 292045e20..1de18ce43 100644 --- a/tests/functional/arch/zx48k/sys_letarrsubstr0.asm +++ b/tests/functional/arch/zx48k/sys_letarrsubstr0.asm @@ -27,6 +27,8 @@ _a: DEFW .LABEL.__LABEL2 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW 0 + DEFW 0 _a.__DATA__: DEFB 00h DEFB 00h diff --git a/tests/functional/arch/zx48k/sys_letarrsubstr1.asm b/tests/functional/arch/zx48k/sys_letarrsubstr1.asm index f1d8d8045..59a4f6b52 100644 --- a/tests/functional/arch/zx48k/sys_letarrsubstr1.asm +++ b/tests/functional/arch/zx48k/sys_letarrsubstr1.asm @@ -29,6 +29,8 @@ _a: DEFW .LABEL.__LABEL2 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW 0 + DEFW 0 _a.__DATA__: DEFB 00h DEFB 00h diff --git a/tests/functional/arch/zx48k/sys_letarrsubstr2.asm b/tests/functional/arch/zx48k/sys_letarrsubstr2.asm index fde9660a7..85cab0cd0 100644 --- a/tests/functional/arch/zx48k/sys_letarrsubstr2.asm +++ b/tests/functional/arch/zx48k/sys_letarrsubstr2.asm @@ -29,6 +29,8 @@ _a: DEFW .LABEL.__LABEL2 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW 0 + DEFW 0 _a.__DATA__: DEFB 00h DEFB 00h diff --git a/tests/functional/arch/zx48k/ubound0.asm b/tests/functional/arch/zx48k/ubound0.asm index 22c4aa61b..854423613 100644 --- a/tests/functional/arch/zx48k/ubound0.asm +++ b/tests/functional/arch/zx48k/ubound0.asm @@ -24,6 +24,8 @@ _a: DEFW .LABEL.__LABEL0 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW _a.__LBOUND__ + DEFW 0 _a.__DATA__: DEFB 00h DEFB 00h @@ -38,6 +40,9 @@ _a.__DATA__: DEFW 0001h DEFW 0003h DEFB 01h +_a.__LBOUND__: + DEFW 0003h + DEFW 0007h .core.ZXBASIC_USER_DATA_END: .core.__MAIN_PROGRAM__: ld hl, 2 diff --git a/tests/functional/arch/zx48k/ubound1.asm b/tests/functional/arch/zx48k/ubound1.asm index 22c4aa61b..854423613 100644 --- a/tests/functional/arch/zx48k/ubound1.asm +++ b/tests/functional/arch/zx48k/ubound1.asm @@ -24,6 +24,8 @@ _a: DEFW .LABEL.__LABEL0 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW _a.__LBOUND__ + DEFW 0 _a.__DATA__: DEFB 00h DEFB 00h @@ -38,6 +40,9 @@ _a.__DATA__: DEFW 0001h DEFW 0003h DEFB 01h +_a.__LBOUND__: + DEFW 0003h + DEFW 0007h .core.ZXBASIC_USER_DATA_END: .core.__MAIN_PROGRAM__: ld hl, 2 diff --git a/tests/functional/arch/zx48k/ubound2.asm b/tests/functional/arch/zx48k/ubound2.asm index 42e968330..beb6a9185 100644 --- a/tests/functional/arch/zx48k/ubound2.asm +++ b/tests/functional/arch/zx48k/ubound2.asm @@ -27,7 +27,7 @@ _a: DEFW .LABEL.__LABEL0 _a.__DATA__.__PTR__: DEFW _a.__DATA__ - DEFW 0 + DEFW _a.__LBOUND__ DEFW _a.__UBOUND__ _a.__DATA__: DEFB 00h @@ -43,6 +43,9 @@ _a.__DATA__: DEFW 0001h DEFW 0003h DEFB 01h +_a.__LBOUND__: + DEFW 0003h + DEFW 0007h _a.__UBOUND__: DEFW 0005h DEFW 0009h @@ -68,7 +71,7 @@ _a.__UBOUND__: ei ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/bound.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/bound.asm" ; --------------------------------------------------------- ; Copyleft (k)2011 by Jose Rodriguez (a.k.a. Boriel) ; http://www.boriel.com @@ -142,5 +145,5 @@ __DIM_NOT_EXIST: ret ENDP pop namespace -#line 22 "ubound2.bas" +#line 22 "arch/zx48k/ubound2.bas" END diff --git a/tests/functional/arch/zx48k/ubound3.asm b/tests/functional/arch/zx48k/ubound3.asm index e8a52ebfe..58c5db75e 100644 --- a/tests/functional/arch/zx48k/ubound3.asm +++ b/tests/functional/arch/zx48k/ubound3.asm @@ -24,6 +24,8 @@ _a: DEFW .LABEL.__LABEL0 _a.__DATA__.__PTR__: DEFW _a.__DATA__ + DEFW _a.__LBOUND__ + DEFW 0 _a.__DATA__: DEFB 00h DEFB 00h @@ -38,6 +40,9 @@ _a.__DATA__: DEFW 0001h DEFW 0003h DEFB 01h +_a.__LBOUND__: + DEFW 0003h + DEFW 0007h .core.ZXBASIC_USER_DATA_END: .core.__MAIN_PROGRAM__: ld hl, 5 diff --git a/tests/functional/arch/zx48k/ubound4.asm b/tests/functional/arch/zx48k/ubound4.asm index 45c857a24..a88fcc6de 100644 --- a/tests/functional/arch/zx48k/ubound4.asm +++ b/tests/functional/arch/zx48k/ubound4.asm @@ -27,7 +27,7 @@ _a: DEFW .LABEL.__LABEL0 _a.__DATA__.__PTR__: DEFW _a.__DATA__ - DEFW 0 + DEFW _a.__LBOUND__ DEFW _a.__UBOUND__ _a.__DATA__: DEFB 00h @@ -43,6 +43,9 @@ _a.__DATA__: DEFW 0001h DEFW 0003h DEFB 01h +_a.__LBOUND__: + DEFW 0003h + DEFW 0007h _a.__UBOUND__: DEFW 0005h DEFW 0009h @@ -68,7 +71,7 @@ _a.__UBOUND__: ei ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/bound.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/bound.asm" ; --------------------------------------------------------- ; Copyleft (k)2011 by Jose Rodriguez (a.k.a. Boriel) ; http://www.boriel.com @@ -142,5 +145,5 @@ __DIM_NOT_EXIST: ret ENDP pop namespace -#line 22 "ubound4.bas" +#line 22 "arch/zx48k/ubound4.bas" END diff --git a/tests/functional/arch/zx48k/ubound5.asm b/tests/functional/arch/zx48k/ubound5.asm index 0c4b8b9a2..c1b76d19d 100644 --- a/tests/functional/arch/zx48k/ubound5.asm +++ b/tests/functional/arch/zx48k/ubound5.asm @@ -27,7 +27,7 @@ _a: DEFW .LABEL.__LABEL0 _a.__DATA__.__PTR__: DEFW _a.__DATA__ - DEFW 0 + DEFW _a.__LBOUND__ DEFW _a.__UBOUND__ _a.__DATA__: DEFB 00h @@ -43,6 +43,9 @@ _a.__DATA__: DEFW 0001h DEFW 0003h DEFB 01h +_a.__LBOUND__: + DEFW 0003h + DEFW 0007h _a.__UBOUND__: DEFW 0005h DEFW 0009h @@ -68,7 +71,7 @@ _a.__UBOUND__: ei ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/bound.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/bound.asm" ; --------------------------------------------------------- ; Copyleft (k)2011 by Jose Rodriguez (a.k.a. Boriel) ; http://www.boriel.com @@ -142,5 +145,5 @@ __DIM_NOT_EXIST: ret ENDP pop namespace -#line 22 "ubound5.bas" +#line 22 "arch/zx48k/ubound5.bas" END diff --git a/tests/functional/arch/zx48k/ubound7.asm b/tests/functional/arch/zx48k/ubound7.asm index e5dc6606d..a0cb8ac3b 100644 --- a/tests/functional/arch/zx48k/ubound7.asm +++ b/tests/functional/arch/zx48k/ubound7.asm @@ -26,7 +26,7 @@ _a: DEFW .LABEL.__LABEL5 _a.__DATA__.__PTR__: DEFW _a.__DATA__ - DEFW 0 + DEFW _a.__LBOUND__ DEFW _a.__UBOUND__ _a.__DATA__: DEFB 00h @@ -42,6 +42,9 @@ _a.__DATA__: DEFW 0001h DEFW 0003h DEFB 01h +_a.__LBOUND__: + DEFW 0003h + DEFW 0007h _a.__UBOUND__: DEFW 0005h DEFW 0009h @@ -103,7 +106,7 @@ _test__leave: exx ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/bound.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/bound.asm" ; --------------------------------------------------------- ; Copyleft (k)2011 by Jose Rodriguez (a.k.a. Boriel) ; http://www.boriel.com @@ -177,5 +180,5 @@ __DIM_NOT_EXIST: ret ENDP pop namespace -#line 58 "ubound7.bas" +#line 58 "arch/zx48k/ubound7.bas" END diff --git a/tests/functional/arch/zx48k/ubound8.asm b/tests/functional/arch/zx48k/ubound8.asm index b223c8890..356614e4e 100644 --- a/tests/functional/arch/zx48k/ubound8.asm +++ b/tests/functional/arch/zx48k/ubound8.asm @@ -26,7 +26,7 @@ _a: DEFW .LABEL.__LABEL5 _a.__DATA__.__PTR__: DEFW _a.__DATA__ - DEFW 0 + DEFW _a.__LBOUND__ DEFW _a.__UBOUND__ _a.__DATA__: DEFB 00h @@ -42,6 +42,9 @@ _a.__DATA__: DEFW 0001h DEFW 0003h DEFB 01h +_a.__LBOUND__: + DEFW 0003h + DEFW 0007h _a.__UBOUND__: DEFW 0005h DEFW 0009h @@ -98,7 +101,7 @@ _test__leave: exx ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/bound.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/bound.asm" ; --------------------------------------------------------- ; Copyleft (k)2011 by Jose Rodriguez (a.k.a. Boriel) ; http://www.boriel.com @@ -172,5 +175,5 @@ __DIM_NOT_EXIST: ret ENDP pop namespace -#line 53 "ubound8.bas" +#line 53 "arch/zx48k/ubound8.bas" END diff --git a/tests/functional/arch/zx48k/ubound9.asm b/tests/functional/arch/zx48k/ubound9.asm index dc2a9b6fb..d158ff283 100644 --- a/tests/functional/arch/zx48k/ubound9.asm +++ b/tests/functional/arch/zx48k/ubound9.asm @@ -26,7 +26,7 @@ _a: DEFW .LABEL.__LABEL5 _a.__DATA__.__PTR__: DEFW _a.__DATA__ - DEFW 0 + DEFW _a.__LBOUND__ DEFW _a.__UBOUND__ _a.__DATA__: DEFB 00h @@ -42,6 +42,9 @@ _a.__DATA__: DEFW 0001h DEFW 0003h DEFB 01h +_a.__LBOUND__: + DEFW 0003h + DEFW 0007h _a.__UBOUND__: DEFW 0005h DEFW 0009h @@ -114,7 +117,7 @@ _test1__leave: exx ret ;; --- end of user code --- -#line 1 "/zxbasic/src/arch/zx48k/library-asm/bound.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/bound.asm" ; --------------------------------------------------------- ; Copyleft (k)2011 by Jose Rodriguez (a.k.a. Boriel) ; http://www.boriel.com @@ -188,5 +191,5 @@ __DIM_NOT_EXIST: ret ENDP pop namespace -#line 69 "ubound9.bas" +#line 69 "arch/zx48k/ubound9.bas" END diff --git a/tests/runtime/cases/arrbound_check1.bas b/tests/runtime/cases/arrbound_check1.bas new file mode 100644 index 000000000..fbac5f7fe --- /dev/null +++ b/tests/runtime/cases/arrbound_check1.bas @@ -0,0 +1,15 @@ +#pragma array_check = yes +#include "lib/tst_framework.bas" + +INIT("Testing global array\#013boundary check") + +DIM a(23, 31) as Uinteger + +FOR i = 0 TO 23 + FOR j = 0 TO 31 + LET m = i * 32 + j + LET a(i, j) = m + NEXT j +NEXT i + +REPORT_OK diff --git a/tests/runtime/cases/arrbound_check2.bas b/tests/runtime/cases/arrbound_check2.bas new file mode 100644 index 000000000..ba37bb130 --- /dev/null +++ b/tests/runtime/cases/arrbound_check2.bas @@ -0,0 +1,18 @@ +#pragma array_check = yes +#include "lib/tst_framework.bas" + +INIT("Testing global array\#013boundary check #2") + +DIM a(23, 31) as Uinteger + +FOR i = 0 TO 23 + FOR j = 0 TO 32 : REM j = 32 => Out of Boundary + LET m = i * 32 + j + LET a(i, j) = m + IF a(i, j) <> m THEN + REPORT_FAIL + END IF + NEXT j +NEXT i + +REPORT_FAIL: REM Should never reach this line diff --git a/tests/runtime/cases/arrbound_check3.bas b/tests/runtime/cases/arrbound_check3.bas new file mode 100644 index 000000000..24781b70d --- /dev/null +++ b/tests/runtime/cases/arrbound_check3.bas @@ -0,0 +1,19 @@ +#pragma array_check = yes +#include "lib/tst_framework.bas" + +INIT("Testing global array\#013boundary check #3") + +DIM a(2 TO 23, 1 TO 31) as Uinteger + +FOR i = 2 TO 23 + FOR j = 0 TO 31 : REM j = 0 => Out of Boundary + PRINT AT 5, 0; i; " "; j; + LET m = i * 32 + j + LET a(i, j) = m + IF a(i, j) <> m THEN + REPORT_FAIL + END IF + NEXT j +NEXT i + +REPORT_FAIL : REM should never reach this line diff --git a/tests/runtime/expected/arrbound_check1.tzx.scr b/tests/runtime/expected/arrbound_check1.tzx.scr new file mode 100644 index 000000000..69d9b7a8c Binary files /dev/null and b/tests/runtime/expected/arrbound_check1.tzx.scr differ diff --git a/tests/runtime/expected/arrbound_check2.tzx.scr b/tests/runtime/expected/arrbound_check2.tzx.scr new file mode 100644 index 000000000..e1ed76243 Binary files /dev/null and b/tests/runtime/expected/arrbound_check2.tzx.scr differ diff --git a/tests/runtime/expected/arrbound_check3.tzx.scr b/tests/runtime/expected/arrbound_check3.tzx.scr new file mode 100644 index 000000000..e120831be Binary files /dev/null and b/tests/runtime/expected/arrbound_check3.tzx.scr differ diff --git a/tests/runtime/update_test.sh b/tests/runtime/update_test.sh index 8a67c152b..929195ac6 100755 --- a/tests/runtime/update_test.sh +++ b/tests/runtime/update_test.sh @@ -4,4 +4,4 @@ NAME=$(basename -s .bas $1).z80 ../../zxbc.py -f z80 -aB "$@" --debug-memory || exit 1 ./update_test.py $NAME -# mv $NAME.scr expected +mv $NAME.scr expected/$(basename -s .bas $1).tzx.scr