diff --git a/arch/zx48k/backend/__init__.py b/arch/zx48k/backend/__init__.py index 0ed3d67e1..e3330818d 100644 --- a/arch/zx48k/backend/__init__.py +++ b/arch/zx48k/backend/__init__.py @@ -132,7 +132,7 @@ OPT32 = True # Label RegExp -RE_LABEL = re.compile('^[ \t]*[a-zA-Z_][_a-zA-Z\d]*:') +RE_LABEL = re.compile(r'^[ \t]*[a-zA-Z_][_a-zA-Z\d]*:') # (ix +/- ...) regexp RE_IX_IDX = re.compile(r'^\([ \t]*ix[ \t]*[-+][ \t]*.+\)$') diff --git a/arch/zx48k/optimizer.py b/arch/zx48k/optimizer.py index 8beedb11a..cf0b68e7a 100644 --- a/arch/zx48k/optimizer.py +++ b/arch/zx48k/optimizer.py @@ -44,14 +44,14 @@ 'bc', 'de', 'hl', 'sp', 'ix', 'iy', 'ixh', 'ixl', 'iyh', 'iyl', 'af', "af'", 'i', 'r'} -RE_NUMBER = re.compile('^([-+]?[0-9]+|$[A-Fa-f0-9]+|[0-9][A-Fa-f0-9]*[Hh]|%[01]+|[01]+[bB])$') +RE_NUMBER = re.compile(r'^([-+]?[0-9]+|$[A-Fa-f0-9]+|[0-9][A-Fa-f0-9]*[Hh]|%[01]+|[01]+[bB])$') RE_INDIR = re.compile(r'\([ \t]*[Ii][XxYy][ \t]*[-+][ \t]*[0-9]+[ \t]*\)') RE_IXIND = re.compile(r'[iI][xXyY]([-+][0-9]+)?') RE_LABEL = re.compile(r'^[ \t]*[_a-zA-Z][a-zA-Z\d]*:') -RE_INDIR16 = re.compile('r[ \t]*\([ \t]*([dD][eE])|([hH][lL])[ \t]*\)[ \t]*') -RE_OUTC = re.compile('[ \t]*\([ \t]*[cC]\)') -RE_ID = re.compile('[.a-zA-Z_][.a-zA-Z_0-9]*') -RE_PRAGMA = re.compile('^#[ \t]?pragma[ \t]opt[ \t]') +RE_INDIR16 = re.compile(r'[ \t]*\([ \t]*([dD][eE])|([hH][lL])[ \t]*\)[ \t]*') +RE_OUTC = re.compile(r'[ \t]*\([ \t]*[cC]\)') +RE_ID = re.compile(r'[.a-zA-Z_][.a-zA-Z_0-9]*') +RE_PRAGMA = re.compile(r'^#[ \t]?pragma[ \t]opt[ \t]') # Enabled Optimizations (this is useful for debugging) OPT00 = True diff --git a/arch/zx48k/translator.py b/arch/zx48k/translator.py index be043866a..90467f4bc 100644 --- a/arch/zx48k/translator.py +++ b/arch/zx48k/translator.py @@ -285,6 +285,9 @@ def traverse_const(node): if node.token == 'CONST': return Translator.traverse_const(node.expr) + if node.token == 'ARRAYACCESS': + return '({} + {})'.format(node.entry.mangled, node.offset) + raise InvalidCONSTexpr(node) @staticmethod @@ -457,6 +460,11 @@ 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.arrayCheck.value: + upper = node.parent.entry.bounds[i].upper + lower = node.parent.entry.bounds[i].lower + self.emit('paramu16', upper - lower) + def visit_ARGUMENT(self, node): if not node.byref: suffix = self.TSUFFIX(node.type_) @@ -496,11 +504,6 @@ def visit_ARRAYLOAD(self, node): if node.offset is None: yield node.args - if OPTIONS.arrayCheck.value: - upper = node.entry.bounds[0].upper - lower = node.entry.bounds[0].lower - self.emit('paramu16', upper - lower) - if scope == SCOPE.global_: self.emit('aload' + self.TSUFFIX(node.type_), node.entry.t, node.entry.mangled) elif scope == SCOPE.parameter: @@ -644,9 +647,6 @@ def visit_LETARRAYSUBSTR(self, node): def visit_ARRAYACCESS(self, node): yield node.arglist - if OPTIONS.arrayCheck.value: - self.emit('param' + self.TSUFFIX(gl.BOUND_TYPE), len(node.entry.bounds)) - def visit_STRSLICE(self, node): yield node.string if node.string.token == 'STRING' or \ diff --git a/library-asm/array.asm b/library-asm/array.asm index c5c4ff696..b2d185e6f 100644 --- a/library-asm/array.asm +++ b/library-asm/array.asm @@ -42,11 +42,10 @@ __ARRAY: ld hl, 0 ; BC = Offset "accumulator" +LOOP: #ifdef __CHECK_ARRAY_BOUNDARY__ pop de #endif - -LOOP: pop bc ; Get next index (Ai) from the stack #ifdef __CHECK_ARRAY_BOUNDARY__ @@ -74,15 +73,8 @@ LOOP: exx pop de ; DE = Max bound Number (i-th dimension) -#ifdef __CHECK_ARRAY_BOUNDARY__ - push de -#endif ;call __MUL16_FAST ; HL *= DE call __FNMUL -#ifdef __CHECK_ARRAY_BOUNDARY__ - pop de - dec de -#endif jp LOOP ARRAY_END: diff --git a/tests/functional/46.asm b/tests/functional/46.asm index ca025a8d4..e3cbf2ca8 100644 --- a/tests/functional/46.asm +++ b/tests/functional/46.asm @@ -140,12 +140,11 @@ __ARRAY: ld hl, 0 ; BC = Offset "accumulator" -#line 48 "/src/zxb/trunk/library-asm/array.asm" - LOOP: +#line 49 "/src/zxb/trunk/library-asm/array.asm" pop bc ; Get next index (Ai) from the stack -#line 60 "/src/zxb/trunk/library-asm/array.asm" +#line 59 "/src/zxb/trunk/library-asm/array.asm" add hl, bc ; Adds current index @@ -163,10 +162,8 @@ LOOP: exx pop de ; DE = Max bound Number (i-th dimension) -#line 80 "/src/zxb/trunk/library-asm/array.asm" ;call __MUL16_FAST ; HL *= DE call __FNMUL -#line 86 "/src/zxb/trunk/library-asm/array.asm" jp LOOP ARRAY_END: @@ -177,7 +174,7 @@ ARRAY_END: push de exx -#line 100 "/src/zxb/trunk/library-asm/array.asm" +#line 92 "/src/zxb/trunk/library-asm/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl @@ -208,7 +205,7 @@ ARRAY_SIZE_LOOP: ;add hl, de ;__ARRAY_FIN: -#line 131 "/src/zxb/trunk/library-asm/array.asm" +#line 123 "/src/zxb/trunk/library-asm/array.asm" pop de add hl, de ; Adds element start diff --git a/tests/functional/47.asm b/tests/functional/47.asm index 1f517ec29..b4857103f 100644 --- a/tests/functional/47.asm +++ b/tests/functional/47.asm @@ -167,12 +167,11 @@ __ARRAY: ld hl, 0 ; BC = Offset "accumulator" -#line 48 "/src/zxb/trunk/library-asm/array.asm" - LOOP: +#line 49 "/src/zxb/trunk/library-asm/array.asm" pop bc ; Get next index (Ai) from the stack -#line 60 "/src/zxb/trunk/library-asm/array.asm" +#line 59 "/src/zxb/trunk/library-asm/array.asm" add hl, bc ; Adds current index @@ -190,10 +189,8 @@ LOOP: exx pop de ; DE = Max bound Number (i-th dimension) -#line 80 "/src/zxb/trunk/library-asm/array.asm" ;call __MUL16_FAST ; HL *= DE call __FNMUL -#line 86 "/src/zxb/trunk/library-asm/array.asm" jp LOOP ARRAY_END: @@ -204,7 +201,7 @@ ARRAY_END: push de exx -#line 100 "/src/zxb/trunk/library-asm/array.asm" +#line 92 "/src/zxb/trunk/library-asm/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl @@ -235,7 +232,7 @@ ARRAY_SIZE_LOOP: ;add hl, de ;__ARRAY_FIN: -#line 131 "/src/zxb/trunk/library-asm/array.asm" +#line 123 "/src/zxb/trunk/library-asm/array.asm" pop de add hl, de ; Adds element start diff --git a/tests/functional/55.asm b/tests/functional/55.asm index 189e202bb..b75d4ec38 100644 --- a/tests/functional/55.asm +++ b/tests/functional/55.asm @@ -135,12 +135,11 @@ __ARRAY: ld hl, 0 ; BC = Offset "accumulator" -#line 48 "/src/zxb/trunk/library-asm/array.asm" - LOOP: +#line 49 "/src/zxb/trunk/library-asm/array.asm" pop bc ; Get next index (Ai) from the stack -#line 60 "/src/zxb/trunk/library-asm/array.asm" +#line 59 "/src/zxb/trunk/library-asm/array.asm" add hl, bc ; Adds current index @@ -158,10 +157,8 @@ LOOP: exx pop de ; DE = Max bound Number (i-th dimension) -#line 80 "/src/zxb/trunk/library-asm/array.asm" ;call __MUL16_FAST ; HL *= DE call __FNMUL -#line 86 "/src/zxb/trunk/library-asm/array.asm" jp LOOP ARRAY_END: @@ -172,7 +169,7 @@ ARRAY_END: push de exx -#line 100 "/src/zxb/trunk/library-asm/array.asm" +#line 92 "/src/zxb/trunk/library-asm/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl @@ -203,7 +200,7 @@ ARRAY_SIZE_LOOP: ;add hl, de ;__ARRAY_FIN: -#line 131 "/src/zxb/trunk/library-asm/array.asm" +#line 123 "/src/zxb/trunk/library-asm/array.asm" pop de add hl, de ; Adds element start diff --git a/tests/functional/aloadstr1.asm b/tests/functional/aloadstr1.asm index 9507c722b..ebacf0849 100644 --- a/tests/functional/aloadstr1.asm +++ b/tests/functional/aloadstr1.asm @@ -138,12 +138,11 @@ __ARRAY: ld hl, 0 ; BC = Offset "accumulator" -#line 48 "/src/zxb/trunk/library-asm/array.asm" - LOOP: +#line 49 "/src/zxb/trunk/library-asm/array.asm" pop bc ; Get next index (Ai) from the stack -#line 60 "/src/zxb/trunk/library-asm/array.asm" +#line 59 "/src/zxb/trunk/library-asm/array.asm" add hl, bc ; Adds current index @@ -161,10 +160,8 @@ LOOP: exx pop de ; DE = Max bound Number (i-th dimension) -#line 80 "/src/zxb/trunk/library-asm/array.asm" ;call __MUL16_FAST ; HL *= DE call __FNMUL -#line 86 "/src/zxb/trunk/library-asm/array.asm" jp LOOP ARRAY_END: @@ -175,7 +172,7 @@ ARRAY_END: push de exx -#line 100 "/src/zxb/trunk/library-asm/array.asm" +#line 92 "/src/zxb/trunk/library-asm/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl @@ -206,7 +203,7 @@ ARRAY_SIZE_LOOP: ;add hl, de ;__ARRAY_FIN: -#line 131 "/src/zxb/trunk/library-asm/array.asm" +#line 123 "/src/zxb/trunk/library-asm/array.asm" pop de add hl, de ; Adds element start diff --git a/tests/functional/array03.asm b/tests/functional/array03.asm index 630631c9a..ca70f21ce 100644 --- a/tests/functional/array03.asm +++ b/tests/functional/array03.asm @@ -133,12 +133,11 @@ __ARRAY: ld hl, 0 ; BC = Offset "accumulator" -#line 48 "/src/zxb/trunk/library-asm/array.asm" - LOOP: +#line 49 "/src/zxb/trunk/library-asm/array.asm" pop bc ; Get next index (Ai) from the stack -#line 60 "/src/zxb/trunk/library-asm/array.asm" +#line 59 "/src/zxb/trunk/library-asm/array.asm" add hl, bc ; Adds current index @@ -156,10 +155,8 @@ LOOP: exx pop de ; DE = Max bound Number (i-th dimension) -#line 80 "/src/zxb/trunk/library-asm/array.asm" ;call __MUL16_FAST ; HL *= DE call __FNMUL -#line 86 "/src/zxb/trunk/library-asm/array.asm" jp LOOP ARRAY_END: @@ -170,7 +167,7 @@ ARRAY_END: push de exx -#line 100 "/src/zxb/trunk/library-asm/array.asm" +#line 92 "/src/zxb/trunk/library-asm/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl @@ -201,7 +198,7 @@ ARRAY_SIZE_LOOP: ;add hl, de ;__ARRAY_FIN: -#line 131 "/src/zxb/trunk/library-asm/array.asm" +#line 123 "/src/zxb/trunk/library-asm/array.asm" pop de add hl, de ; Adds element start diff --git a/tests/functional/array06.asm b/tests/functional/array06.asm index d4ddedce3..b6fc12f28 100644 --- a/tests/functional/array06.asm +++ b/tests/functional/array06.asm @@ -133,12 +133,11 @@ __ARRAY: ld hl, 0 ; BC = Offset "accumulator" -#line 48 "/src/zxb/trunk/library-asm/array.asm" - LOOP: +#line 49 "/src/zxb/trunk/library-asm/array.asm" pop bc ; Get next index (Ai) from the stack -#line 60 "/src/zxb/trunk/library-asm/array.asm" +#line 59 "/src/zxb/trunk/library-asm/array.asm" add hl, bc ; Adds current index @@ -156,10 +155,8 @@ LOOP: exx pop de ; DE = Max bound Number (i-th dimension) -#line 80 "/src/zxb/trunk/library-asm/array.asm" ;call __MUL16_FAST ; HL *= DE call __FNMUL -#line 86 "/src/zxb/trunk/library-asm/array.asm" jp LOOP ARRAY_END: @@ -170,7 +167,7 @@ ARRAY_END: push de exx -#line 100 "/src/zxb/trunk/library-asm/array.asm" +#line 92 "/src/zxb/trunk/library-asm/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl @@ -201,7 +198,7 @@ ARRAY_SIZE_LOOP: ;add hl, de ;__ARRAY_FIN: -#line 131 "/src/zxb/trunk/library-asm/array.asm" +#line 123 "/src/zxb/trunk/library-asm/array.asm" pop de add hl, de ; Adds element start diff --git a/tests/functional/array07.asm b/tests/functional/array07.asm index d8aeb3612..774a4bc51 100644 --- a/tests/functional/array07.asm +++ b/tests/functional/array07.asm @@ -156,12 +156,11 @@ __ARRAY: ld hl, 0 ; BC = Offset "accumulator" -#line 48 "/src/zxb/trunk/library-asm/array.asm" - LOOP: +#line 49 "/src/zxb/trunk/library-asm/array.asm" pop bc ; Get next index (Ai) from the stack -#line 60 "/src/zxb/trunk/library-asm/array.asm" +#line 59 "/src/zxb/trunk/library-asm/array.asm" add hl, bc ; Adds current index @@ -179,10 +178,8 @@ LOOP: exx pop de ; DE = Max bound Number (i-th dimension) -#line 80 "/src/zxb/trunk/library-asm/array.asm" ;call __MUL16_FAST ; HL *= DE call __FNMUL -#line 86 "/src/zxb/trunk/library-asm/array.asm" jp LOOP ARRAY_END: @@ -193,7 +190,7 @@ ARRAY_END: push de exx -#line 100 "/src/zxb/trunk/library-asm/array.asm" +#line 92 "/src/zxb/trunk/library-asm/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl @@ -224,7 +221,7 @@ ARRAY_SIZE_LOOP: ;add hl, de ;__ARRAY_FIN: -#line 131 "/src/zxb/trunk/library-asm/array.asm" +#line 123 "/src/zxb/trunk/library-asm/array.asm" pop de add hl, de ; Adds element start diff --git a/tests/functional/array08.asm b/tests/functional/array08.asm index 11d22cf91..174c4493e 100644 --- a/tests/functional/array08.asm +++ b/tests/functional/array08.asm @@ -134,12 +134,11 @@ __ARRAY: ld hl, 0 ; BC = Offset "accumulator" -#line 48 "/src/zxb/trunk/library-asm/array.asm" - LOOP: +#line 49 "/src/zxb/trunk/library-asm/array.asm" pop bc ; Get next index (Ai) from the stack -#line 60 "/src/zxb/trunk/library-asm/array.asm" +#line 59 "/src/zxb/trunk/library-asm/array.asm" add hl, bc ; Adds current index @@ -157,10 +156,8 @@ LOOP: exx pop de ; DE = Max bound Number (i-th dimension) -#line 80 "/src/zxb/trunk/library-asm/array.asm" ;call __MUL16_FAST ; HL *= DE call __FNMUL -#line 86 "/src/zxb/trunk/library-asm/array.asm" jp LOOP ARRAY_END: @@ -171,7 +168,7 @@ ARRAY_END: push de exx -#line 100 "/src/zxb/trunk/library-asm/array.asm" +#line 92 "/src/zxb/trunk/library-asm/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl @@ -202,7 +199,7 @@ ARRAY_SIZE_LOOP: ;add hl, de ;__ARRAY_FIN: -#line 131 "/src/zxb/trunk/library-asm/array.asm" +#line 123 "/src/zxb/trunk/library-asm/array.asm" pop de add hl, de ; Adds element start diff --git a/tests/functional/array09.asm b/tests/functional/array09.asm index 778c07563..9dd88c40b 100644 --- a/tests/functional/array09.asm +++ b/tests/functional/array09.asm @@ -134,12 +134,11 @@ __ARRAY: ld hl, 0 ; BC = Offset "accumulator" -#line 48 "/src/zxb/trunk/library-asm/array.asm" - LOOP: +#line 49 "/src/zxb/trunk/library-asm/array.asm" pop bc ; Get next index (Ai) from the stack -#line 60 "/src/zxb/trunk/library-asm/array.asm" +#line 59 "/src/zxb/trunk/library-asm/array.asm" add hl, bc ; Adds current index @@ -157,10 +156,8 @@ LOOP: exx pop de ; DE = Max bound Number (i-th dimension) -#line 80 "/src/zxb/trunk/library-asm/array.asm" ;call __MUL16_FAST ; HL *= DE call __FNMUL -#line 86 "/src/zxb/trunk/library-asm/array.asm" jp LOOP ARRAY_END: @@ -171,7 +168,7 @@ ARRAY_END: push de exx -#line 100 "/src/zxb/trunk/library-asm/array.asm" +#line 92 "/src/zxb/trunk/library-asm/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl @@ -202,7 +199,7 @@ ARRAY_SIZE_LOOP: ;add hl, de ;__ARRAY_FIN: -#line 131 "/src/zxb/trunk/library-asm/array.asm" +#line 123 "/src/zxb/trunk/library-asm/array.asm" pop de add hl, de ; Adds element start diff --git a/tests/functional/array10.asm b/tests/functional/array10.asm index b4575b4de..8d6f2b0e0 100644 --- a/tests/functional/array10.asm +++ b/tests/functional/array10.asm @@ -166,12 +166,11 @@ __ARRAY: ld hl, 0 ; BC = Offset "accumulator" -#line 48 "/src/zxb/trunk/library-asm/array.asm" - LOOP: +#line 49 "/src/zxb/trunk/library-asm/array.asm" pop bc ; Get next index (Ai) from the stack -#line 60 "/src/zxb/trunk/library-asm/array.asm" +#line 59 "/src/zxb/trunk/library-asm/array.asm" add hl, bc ; Adds current index @@ -189,10 +188,8 @@ LOOP: exx pop de ; DE = Max bound Number (i-th dimension) -#line 80 "/src/zxb/trunk/library-asm/array.asm" ;call __MUL16_FAST ; HL *= DE call __FNMUL -#line 86 "/src/zxb/trunk/library-asm/array.asm" jp LOOP ARRAY_END: @@ -203,7 +200,7 @@ ARRAY_END: push de exx -#line 100 "/src/zxb/trunk/library-asm/array.asm" +#line 92 "/src/zxb/trunk/library-asm/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl @@ -234,7 +231,7 @@ ARRAY_SIZE_LOOP: ;add hl, de ;__ARRAY_FIN: -#line 131 "/src/zxb/trunk/library-asm/array.asm" +#line 123 "/src/zxb/trunk/library-asm/array.asm" pop de add hl, de ; Adds element start diff --git a/tests/functional/array12.asm b/tests/functional/array12.asm index 70da58a5f..42a760e67 100644 --- a/tests/functional/array12.asm +++ b/tests/functional/array12.asm @@ -136,12 +136,11 @@ __ARRAY: ld hl, 0 ; BC = Offset "accumulator" -#line 48 "/src/zxb/trunk/library-asm/array.asm" - LOOP: +#line 49 "/src/zxb/trunk/library-asm/array.asm" pop bc ; Get next index (Ai) from the stack -#line 60 "/src/zxb/trunk/library-asm/array.asm" +#line 59 "/src/zxb/trunk/library-asm/array.asm" add hl, bc ; Adds current index @@ -159,10 +158,8 @@ LOOP: exx pop de ; DE = Max bound Number (i-th dimension) -#line 80 "/src/zxb/trunk/library-asm/array.asm" ;call __MUL16_FAST ; HL *= DE call __FNMUL -#line 86 "/src/zxb/trunk/library-asm/array.asm" jp LOOP ARRAY_END: @@ -173,7 +170,7 @@ ARRAY_END: push de exx -#line 100 "/src/zxb/trunk/library-asm/array.asm" +#line 92 "/src/zxb/trunk/library-asm/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl @@ -204,7 +201,7 @@ ARRAY_SIZE_LOOP: ;add hl, de ;__ARRAY_FIN: -#line 131 "/src/zxb/trunk/library-asm/array.asm" +#line 123 "/src/zxb/trunk/library-asm/array.asm" pop de add hl, de ; Adds element start diff --git a/tests/functional/arrcheck.asm b/tests/functional/arrcheck.asm new file mode 100644 index 000000000..d1fae43e2 --- /dev/null +++ b/tests/functional/arrcheck.asm @@ -0,0 +1,389 @@ + org 32768 +__START_PROGRAM: + di + push ix + push iy + exx + push hl + exx + ld hl, 0 + add hl, sp + ld (__CALL_BACK__), hl + ei + ld hl, (_b) + push hl + ld hl, 5 + push hl + ld hl, (_b) + push hl + ld hl, 10 + push hl + ld hl, _a + call __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 __ARRAY + ld a, (hl) + ld (_c), a + ld (_c), a + ld hl, 0 + ld b, h + ld c, l +__END_PROGRAM: + di + ld hl, (__CALL_BACK__) + ld sp, hl + exx + pop hl + exx + pop iy + pop ix + ei + ret +__CALL_BACK__: + DEFW 0 +#line 1 "array.asm" + +; vim: ts=4:et:sw=4: + ; Copyleft (K) by Jose M. Rodriguez de la Rosa + ; (a.k.a. Boriel) +; http://www.boriel.com + ; ------------------------------------------------------------------- + ; Simple array Index routine + ; Number of total indexes dimensions - 1 at beginning of memory + ; HL = Start of array memory (First two bytes contains N-1 dimensions) + ; Dimension values on the stack, (top of the stack, highest dimension) + ; E.g. A(2, 4) -> PUSH <4>; PUSH <2> + + ; For any array of N dimension A(aN-1, ..., a1, a0) + ; and dimensions D[bN-1, ..., b1, b0], the offset is calculated as + ; 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 "mul16.asm" + +__MUL16: ; Mutiplies HL with the last value stored into de stack + ; Works for both signed and unsigned + + PROC + + LOCAL __MUL16LOOP + LOCAL __MUL16NOADD + + ex de, hl + pop hl ; Return address + ex (sp), hl ; CALLEE caller convention + +;;__MUL16_FAST: ; __FASTCALL ENTRY: HL = 1st operand, DE = 2nd Operand + ;; ld c, h + ;; ld a, l ; C,A => 1st Operand + ;; + ;; ld hl, 0 ; Accumulator + ;; ld b, 16 + ;; +;;__MUL16LOOP: + ;; sra c ; C,A >> 1 (Arithmetic) + ;; rra + ;; + ;; jr nc, __MUL16NOADD + ;; add hl, de + ;; +;;__MUL16NOADD: + ;; sla e + ;; rl d + ;; + ;; djnz __MUL16LOOP + +__MUL16_FAST: + ld b, 16 + ld a, d + ld c, e + ex de, hl + ld hl, 0 + +__MUL16LOOP: + add hl, hl ; hl << 1 + sla c + rla ; a,c << 1 + jp nc, __MUL16NOADD + add hl, de + +__MUL16NOADD: + djnz __MUL16LOOP + + ret ; Result in hl (16 lower bits) + + ENDP + +#line 20 "array.asm" + + +#line 1 "error.asm" + + ; Simple error control routines +; vim:ts=4:et: + + ERR_NR EQU 23610 ; Error code system variable + + + ; Error code definitions (as in ZX spectrum manual) + +; Set error code with: + ; ld a, ERROR_CODE + ; ld (ERR_NR), a + + + ERROR_Ok EQU -1 + ERROR_SubscriptWrong EQU 2 + ERROR_OutOfMemory EQU 3 + ERROR_OutOfScreen EQU 4 + ERROR_NumberTooBig EQU 5 + ERROR_InvalidArg EQU 9 + ERROR_IntOutOfRange EQU 10 + ERROR_NonsenseInBasic EQU 11 + ERROR_InvalidFileName EQU 14 + ERROR_InvalidColour EQU 19 + ERROR_BreakIntoProgram EQU 20 + ERROR_TapeLoadingErr EQU 26 + + + ; Raises error using RST #8 +__ERROR: + ld (__ERROR_CODE), a + rst 8 +__ERROR_CODE: + nop + ret + + ; Sets the error system variable, but keeps running. + ; Usually this instruction if followed by the END intermediate instruction. +__STOP: + ld (ERR_NR), a + ret +#line 23 "array.asm" +#line 24 "/Users/boriel/Documents/src/zxbasic/zxbasic/library-asm/array.asm" + +__ARRAY: + PROC + + LOCAL LOOP + LOCAL ARRAY_END + LOCAL RET_ADDRESS ; Stores return address + + ex (sp), hl ; Return address in HL, array address in the stack + ld (RET_ADDRESS + 1), hl ; Stores it for later + + exx + pop hl ; Will use H'L' as the pointer + ld c, (hl) ; Loads Number of dimensions from (hl) + inc hl + ld b, (hl) + inc hl ; Ready + exx + + ld hl, 0 ; BC = Offset "accumulator" + +LOOP: + + pop de +#line 49 "/Users/boriel/Documents/src/zxbasic/zxbasic/library-asm/array.asm" + pop bc ; Get next index (Ai) from the stack + + + ex de, hl + or a + sbc hl, bc + ld a, ERROR_SubscriptWrong + jp c, __ERROR + ex de, hl +#line 59 "/Users/boriel/Documents/src/zxbasic/zxbasic/library-asm/array.asm" + + add hl, bc ; 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' + 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 ; HL *= DE + call __FNMUL + jp LOOP + +ARRAY_END: + ld e, (hl) + inc hl + ld d, c ; C = 0 => DE = E = Element size + push hl + push de + exx + +#line 92 "/Users/boriel/Documents/src/zxbasic/zxbasic/library-asm/array.asm" + LOCAL ARRAY_SIZE_LOOP + + ex de, hl + ld hl, 0 + pop bc + ld b, c +ARRAY_SIZE_LOOP: + add hl, de + djnz ARRAY_SIZE_LOOP + + ;; Even faster + ;pop bc + + ;ld d, h + ;ld e, l + + ;dec c + ;jp z, __ARRAY_FIN + + ;add hl, hl + ;dec c + ;jp z, __ARRAY_FIN + + ;add hl, hl + ;dec c + ;dec c + ;jp z, __ARRAY_FIN + + ;add hl, de + ;__ARRAY_FIN: +#line 123 "/Users/boriel/Documents/src/zxbasic/zxbasic/library-asm/array.asm" + + pop de + add hl, de ; Adds element start + +RET_ADDRESS: + ld de, 0 + push de + ret ; HL = (Start of Elements + Offset) + + ;; Performs a faster multiply for little 16bit numbs + LOCAL __FNMUL, __FNMUL2 + +__FNMUL: + xor a + or d + jp nz, __MUL16_FAST + + or e + ex de, hl + ret z + + cp 33 + jp nc, __MUL16_FAST + + ld b, l + ld l, h ; HL = 0 + +__FNMUL2: + add hl, de + djnz __FNMUL2 + ret + + ENDP + +#line 44 "arrcheck.bas" + +ZXBASIC_USER_DATA: +_c: + DEFB 00 +_b: + DEFB 05h + DEFB 00h +_a: + DEFW 0001h + DEFW 0006h + DEFB 01h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + ; Defines DATA END --> HEAP size is 0 +ZXBASIC_USER_DATA_END EQU ZXBASIC_MEM_HEAP + ; Defines USER DATA Length in bytes +ZXBASIC_USER_DATA_LEN EQU ZXBASIC_USER_DATA_END - ZXBASIC_USER_DATA + END diff --git a/tests/functional/arrcheck.bas b/tests/functional/arrcheck.bas new file mode 100644 index 000000000..51f503a9a --- /dev/null +++ b/tests/functional/arrcheck.bas @@ -0,0 +1,10 @@ +#pragma arrayCheck=true +#define __CHECK_ARRAY_BOUNDARY__ + +DIM a(10, 5) as byte +DIM c as Byte + +DIM b as UInteger = 5 +Let a(b, b) = 7 +Let c = a(b + 6, b) +let c = c diff --git a/tests/functional/arrconst.asm b/tests/functional/arrconst.asm new file mode 100644 index 000000000..3f0ee8e83 --- /dev/null +++ b/tests/functional/arrconst.asm @@ -0,0 +1,61 @@ + org 32768 +__START_PROGRAM: + di + push ix + push iy + exx + push hl + exx + ld hl, 0 + add hl, sp + ld (__CALL_BACK__), hl + ei + ld hl, (_p) + ld (_p), hl + ld hl, 0 + ld b, h + ld c, l +__END_PROGRAM: + di + ld hl, (__CALL_BACK__) + ld sp, hl + exx + pop hl + exx + pop iy + pop ix + ei + ret +__CALL_BACK__: + DEFW 0 + +ZXBASIC_USER_DATA: +_p: + DEFW (_a + 5) +_a: + DEFW 0001h + DEFW 0003h + DEFB 02h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + DEFB 00h + ; Defines DATA END --> HEAP size is 0 +ZXBASIC_USER_DATA_END EQU ZXBASIC_MEM_HEAP + ; Defines USER DATA Length in bytes +ZXBASIC_USER_DATA_LEN EQU ZXBASIC_USER_DATA_END - ZXBASIC_USER_DATA + END diff --git a/tests/functional/arrconst.bas b/tests/functional/arrconst.bas new file mode 100644 index 000000000..daa169f44 --- /dev/null +++ b/tests/functional/arrconst.bas @@ -0,0 +1,5 @@ + +DIM a(2, 2) as UInteger +DIM p = @a(0, 0) +p = p + diff --git a/tests/functional/astore16.asm b/tests/functional/astore16.asm index 3c59a2cbb..eab6b4224 100644 --- a/tests/functional/astore16.asm +++ b/tests/functional/astore16.asm @@ -160,12 +160,11 @@ __ARRAY: ld hl, 0 ; BC = Offset "accumulator" -#line 48 "/src/zxb/trunk/library-asm/array.asm" - LOOP: +#line 49 "/src/zxb/trunk/library-asm/array.asm" pop bc ; Get next index (Ai) from the stack -#line 60 "/src/zxb/trunk/library-asm/array.asm" +#line 59 "/src/zxb/trunk/library-asm/array.asm" add hl, bc ; Adds current index @@ -183,10 +182,8 @@ LOOP: exx pop de ; DE = Max bound Number (i-th dimension) -#line 80 "/src/zxb/trunk/library-asm/array.asm" ;call __MUL16_FAST ; HL *= DE call __FNMUL -#line 86 "/src/zxb/trunk/library-asm/array.asm" jp LOOP ARRAY_END: @@ -197,7 +194,7 @@ ARRAY_END: push de exx -#line 100 "/src/zxb/trunk/library-asm/array.asm" +#line 92 "/src/zxb/trunk/library-asm/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl @@ -228,7 +225,7 @@ ARRAY_SIZE_LOOP: ;add hl, de ;__ARRAY_FIN: -#line 131 "/src/zxb/trunk/library-asm/array.asm" +#line 123 "/src/zxb/trunk/library-asm/array.asm" pop de add hl, de ; Adds element start diff --git a/tests/functional/let_array_substr.asm b/tests/functional/let_array_substr.asm index 9e1d270c3..8e3fdb996 100644 --- a/tests/functional/let_array_substr.asm +++ b/tests/functional/let_array_substr.asm @@ -171,12 +171,11 @@ __ARRAY: ld hl, 0 ; BC = Offset "accumulator" -#line 48 "/src/zxb/trunk/library-asm/array.asm" - LOOP: +#line 49 "/src/zxb/trunk/library-asm/array.asm" pop bc ; Get next index (Ai) from the stack -#line 60 "/src/zxb/trunk/library-asm/array.asm" +#line 59 "/src/zxb/trunk/library-asm/array.asm" add hl, bc ; Adds current index @@ -194,10 +193,8 @@ LOOP: exx pop de ; DE = Max bound Number (i-th dimension) -#line 80 "/src/zxb/trunk/library-asm/array.asm" ;call __MUL16_FAST ; HL *= DE call __FNMUL -#line 86 "/src/zxb/trunk/library-asm/array.asm" jp LOOP ARRAY_END: @@ -208,7 +205,7 @@ ARRAY_END: push de exx -#line 100 "/src/zxb/trunk/library-asm/array.asm" +#line 92 "/src/zxb/trunk/library-asm/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl @@ -239,7 +236,7 @@ ARRAY_SIZE_LOOP: ;add hl, de ;__ARRAY_FIN: -#line 131 "/src/zxb/trunk/library-asm/array.asm" +#line 123 "/src/zxb/trunk/library-asm/array.asm" pop de add hl, de ; Adds element start diff --git a/tests/functional/let_array_substr1.asm b/tests/functional/let_array_substr1.asm index eb062d890..a8df9e06d 100644 --- a/tests/functional/let_array_substr1.asm +++ b/tests/functional/let_array_substr1.asm @@ -171,12 +171,11 @@ __ARRAY: ld hl, 0 ; BC = Offset "accumulator" -#line 48 "/src/zxb/trunk/library-asm/array.asm" - LOOP: +#line 49 "/src/zxb/trunk/library-asm/array.asm" pop bc ; Get next index (Ai) from the stack -#line 60 "/src/zxb/trunk/library-asm/array.asm" +#line 59 "/src/zxb/trunk/library-asm/array.asm" add hl, bc ; Adds current index @@ -194,10 +193,8 @@ LOOP: exx pop de ; DE = Max bound Number (i-th dimension) -#line 80 "/src/zxb/trunk/library-asm/array.asm" ;call __MUL16_FAST ; HL *= DE call __FNMUL -#line 86 "/src/zxb/trunk/library-asm/array.asm" jp LOOP ARRAY_END: @@ -208,7 +205,7 @@ ARRAY_END: push de exx -#line 100 "/src/zxb/trunk/library-asm/array.asm" +#line 92 "/src/zxb/trunk/library-asm/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl @@ -239,7 +236,7 @@ ARRAY_SIZE_LOOP: ;add hl, de ;__ARRAY_FIN: -#line 131 "/src/zxb/trunk/library-asm/array.asm" +#line 123 "/src/zxb/trunk/library-asm/array.asm" pop de add hl, de ; Adds element start diff --git a/tests/functional/let_array_substr5.asm b/tests/functional/let_array_substr5.asm index 224ac4e01..a3a06a424 100644 --- a/tests/functional/let_array_substr5.asm +++ b/tests/functional/let_array_substr5.asm @@ -171,12 +171,11 @@ __ARRAY: ld hl, 0 ; BC = Offset "accumulator" -#line 48 "/src/zxb/trunk/library-asm/array.asm" - LOOP: +#line 49 "/src/zxb/trunk/library-asm/array.asm" pop bc ; Get next index (Ai) from the stack -#line 60 "/src/zxb/trunk/library-asm/array.asm" +#line 59 "/src/zxb/trunk/library-asm/array.asm" add hl, bc ; Adds current index @@ -194,10 +193,8 @@ LOOP: exx pop de ; DE = Max bound Number (i-th dimension) -#line 80 "/src/zxb/trunk/library-asm/array.asm" ;call __MUL16_FAST ; HL *= DE call __FNMUL -#line 86 "/src/zxb/trunk/library-asm/array.asm" jp LOOP ARRAY_END: @@ -208,7 +205,7 @@ ARRAY_END: push de exx -#line 100 "/src/zxb/trunk/library-asm/array.asm" +#line 92 "/src/zxb/trunk/library-asm/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl @@ -239,7 +236,7 @@ ARRAY_SIZE_LOOP: ;add hl, de ;__ARRAY_FIN: -#line 131 "/src/zxb/trunk/library-asm/array.asm" +#line 123 "/src/zxb/trunk/library-asm/array.asm" pop de add hl, de ; Adds element start diff --git a/tests/functional/ltee10.asm b/tests/functional/ltee10.asm index cd6491273..e9315333a 100644 --- a/tests/functional/ltee10.asm +++ b/tests/functional/ltee10.asm @@ -155,12 +155,11 @@ __ARRAY: ld hl, 0 ; BC = Offset "accumulator" -#line 48 "/src/zxb/trunk/library-asm/array.asm" - LOOP: +#line 49 "/src/zxb/trunk/library-asm/array.asm" pop bc ; Get next index (Ai) from the stack -#line 60 "/src/zxb/trunk/library-asm/array.asm" +#line 59 "/src/zxb/trunk/library-asm/array.asm" add hl, bc ; Adds current index @@ -178,10 +177,8 @@ LOOP: exx pop de ; DE = Max bound Number (i-th dimension) -#line 80 "/src/zxb/trunk/library-asm/array.asm" ;call __MUL16_FAST ; HL *= DE call __FNMUL -#line 86 "/src/zxb/trunk/library-asm/array.asm" jp LOOP ARRAY_END: @@ -192,7 +189,7 @@ ARRAY_END: push de exx -#line 100 "/src/zxb/trunk/library-asm/array.asm" +#line 92 "/src/zxb/trunk/library-asm/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl @@ -223,7 +220,7 @@ ARRAY_SIZE_LOOP: ;add hl, de ;__ARRAY_FIN: -#line 131 "/src/zxb/trunk/library-asm/array.asm" +#line 123 "/src/zxb/trunk/library-asm/array.asm" pop de add hl, de ; Adds element start diff --git a/tests/functional/ltee6.asm b/tests/functional/ltee6.asm index ef574d011..74c44c58d 100644 --- a/tests/functional/ltee6.asm +++ b/tests/functional/ltee6.asm @@ -144,12 +144,11 @@ __ARRAY: ld hl, 0 ; BC = Offset "accumulator" -#line 48 "/src/zxb/trunk/library-asm/array.asm" - LOOP: +#line 49 "/src/zxb/trunk/library-asm/array.asm" pop bc ; Get next index (Ai) from the stack -#line 60 "/src/zxb/trunk/library-asm/array.asm" +#line 59 "/src/zxb/trunk/library-asm/array.asm" add hl, bc ; Adds current index @@ -167,10 +166,8 @@ LOOP: exx pop de ; DE = Max bound Number (i-th dimension) -#line 80 "/src/zxb/trunk/library-asm/array.asm" ;call __MUL16_FAST ; HL *= DE call __FNMUL -#line 86 "/src/zxb/trunk/library-asm/array.asm" jp LOOP ARRAY_END: @@ -181,7 +178,7 @@ ARRAY_END: push de exx -#line 100 "/src/zxb/trunk/library-asm/array.asm" +#line 92 "/src/zxb/trunk/library-asm/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl @@ -212,7 +209,7 @@ ARRAY_SIZE_LOOP: ;add hl, de ;__ARRAY_FIN: -#line 131 "/src/zxb/trunk/library-asm/array.asm" +#line 123 "/src/zxb/trunk/library-asm/array.asm" pop de add hl, de ; Adds element start diff --git a/tests/functional/ltee7.asm b/tests/functional/ltee7.asm index 6d0651ee2..a48906068 100644 --- a/tests/functional/ltee7.asm +++ b/tests/functional/ltee7.asm @@ -182,12 +182,11 @@ __ARRAY: ld hl, 0 ; BC = Offset "accumulator" -#line 48 "/src/zxb/trunk/library-asm/array.asm" - LOOP: +#line 49 "/src/zxb/trunk/library-asm/array.asm" pop bc ; Get next index (Ai) from the stack -#line 60 "/src/zxb/trunk/library-asm/array.asm" +#line 59 "/src/zxb/trunk/library-asm/array.asm" add hl, bc ; Adds current index @@ -205,10 +204,8 @@ LOOP: exx pop de ; DE = Max bound Number (i-th dimension) -#line 80 "/src/zxb/trunk/library-asm/array.asm" ;call __MUL16_FAST ; HL *= DE call __FNMUL -#line 86 "/src/zxb/trunk/library-asm/array.asm" jp LOOP ARRAY_END: @@ -219,7 +216,7 @@ ARRAY_END: push de exx -#line 100 "/src/zxb/trunk/library-asm/array.asm" +#line 92 "/src/zxb/trunk/library-asm/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl @@ -250,7 +247,7 @@ ARRAY_SIZE_LOOP: ;add hl, de ;__ARRAY_FIN: -#line 131 "/src/zxb/trunk/library-asm/array.asm" +#line 123 "/src/zxb/trunk/library-asm/array.asm" pop de add hl, de ; Adds element start diff --git a/tests/functional/opt2_snake_es.asm b/tests/functional/opt2_snake_es.asm index 5540c63da..d403db9fc 100644 --- a/tests/functional/opt2_snake_es.asm +++ b/tests/functional/opt2_snake_es.asm @@ -141,12 +141,11 @@ __ARRAY: ld hl, 0 ; BC = Offset "accumulator" -#line 48 "/src/zxb/trunk/library-asm/array.asm" - LOOP: +#line 49 "/src/zxb/trunk/library-asm/array.asm" pop bc ; Get next index (Ai) from the stack -#line 60 "/src/zxb/trunk/library-asm/array.asm" +#line 59 "/src/zxb/trunk/library-asm/array.asm" add hl, bc ; Adds current index @@ -164,10 +163,8 @@ LOOP: exx pop de ; DE = Max bound Number (i-th dimension) -#line 80 "/src/zxb/trunk/library-asm/array.asm" ;call __MUL16_FAST ; HL *= DE call __FNMUL -#line 86 "/src/zxb/trunk/library-asm/array.asm" jp LOOP ARRAY_END: @@ -178,7 +175,7 @@ ARRAY_END: push de exx -#line 100 "/src/zxb/trunk/library-asm/array.asm" +#line 92 "/src/zxb/trunk/library-asm/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl @@ -209,7 +206,7 @@ ARRAY_SIZE_LOOP: ;add hl, de ;__ARRAY_FIN: -#line 131 "/src/zxb/trunk/library-asm/array.asm" +#line 123 "/src/zxb/trunk/library-asm/array.asm" pop de add hl, de ; Adds element start diff --git a/tests/functional/opt3_OPT27wws2.asm b/tests/functional/opt3_OPT27wws2.asm index f1eea3a4a..d80751e05 100644 --- a/tests/functional/opt3_OPT27wws2.asm +++ b/tests/functional/opt3_OPT27wws2.asm @@ -142,12 +142,11 @@ __ARRAY: ld hl, 0 ; BC = Offset "accumulator" -#line 48 "/src/zxb/trunk/library-asm/array.asm" - LOOP: +#line 49 "/src/zxb/trunk/library-asm/array.asm" pop bc ; Get next index (Ai) from the stack -#line 60 "/src/zxb/trunk/library-asm/array.asm" +#line 59 "/src/zxb/trunk/library-asm/array.asm" add hl, bc ; Adds current index @@ -165,10 +164,8 @@ LOOP: exx pop de ; DE = Max bound Number (i-th dimension) -#line 80 "/src/zxb/trunk/library-asm/array.asm" ;call __MUL16_FAST ; HL *= DE call __FNMUL -#line 86 "/src/zxb/trunk/library-asm/array.asm" jp LOOP ARRAY_END: @@ -179,7 +176,7 @@ ARRAY_END: push de exx -#line 100 "/src/zxb/trunk/library-asm/array.asm" +#line 92 "/src/zxb/trunk/library-asm/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl @@ -210,7 +207,7 @@ ARRAY_SIZE_LOOP: ;add hl, de ;__ARRAY_FIN: -#line 131 "/src/zxb/trunk/library-asm/array.asm" +#line 123 "/src/zxb/trunk/library-asm/array.asm" pop de add hl, de ; Adds element start diff --git a/tests/functional/opt3_data2.asm b/tests/functional/opt3_data2.asm index fb20c2605..71b41a3e7 100644 --- a/tests/functional/opt3_data2.asm +++ b/tests/functional/opt3_data2.asm @@ -208,12 +208,11 @@ __ARRAY: ld hl, 0 ; BC = Offset "accumulator" -#line 48 "/src/zxb/trunk/library-asm/array.asm" - LOOP: +#line 49 "/src/zxb/trunk/library-asm/array.asm" pop bc ; Get next index (Ai) from the stack -#line 60 "/src/zxb/trunk/library-asm/array.asm" +#line 59 "/src/zxb/trunk/library-asm/array.asm" add hl, bc ; Adds current index @@ -231,10 +230,8 @@ LOOP: exx pop de ; DE = Max bound Number (i-th dimension) -#line 80 "/src/zxb/trunk/library-asm/array.asm" ;call __MUL16_FAST ; HL *= DE call __FNMUL -#line 86 "/src/zxb/trunk/library-asm/array.asm" jp LOOP ARRAY_END: @@ -245,7 +242,7 @@ ARRAY_END: push de exx -#line 100 "/src/zxb/trunk/library-asm/array.asm" +#line 92 "/src/zxb/trunk/library-asm/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl @@ -276,7 +273,7 @@ ARRAY_SIZE_LOOP: ;add hl, de ;__ARRAY_FIN: -#line 131 "/src/zxb/trunk/library-asm/array.asm" +#line 123 "/src/zxb/trunk/library-asm/array.asm" pop de add hl, de ; Adds element start diff --git a/tests/functional/read9.asm b/tests/functional/read9.asm index 1c154dff7..043aa4b28 100644 --- a/tests/functional/read9.asm +++ b/tests/functional/read9.asm @@ -230,12 +230,11 @@ __ARRAY: ld hl, 0 ; BC = Offset "accumulator" -#line 48 "/src/zxb/trunk/library-asm/array.asm" - LOOP: +#line 49 "/src/zxb/trunk/library-asm/array.asm" pop bc ; Get next index (Ai) from the stack -#line 60 "/src/zxb/trunk/library-asm/array.asm" +#line 59 "/src/zxb/trunk/library-asm/array.asm" add hl, bc ; Adds current index @@ -253,10 +252,8 @@ LOOP: exx pop de ; DE = Max bound Number (i-th dimension) -#line 80 "/src/zxb/trunk/library-asm/array.asm" ;call __MUL16_FAST ; HL *= DE call __FNMUL -#line 86 "/src/zxb/trunk/library-asm/array.asm" jp LOOP ARRAY_END: @@ -267,7 +264,7 @@ ARRAY_END: push de exx -#line 100 "/src/zxb/trunk/library-asm/array.asm" +#line 92 "/src/zxb/trunk/library-asm/array.asm" LOCAL ARRAY_SIZE_LOOP ex de, hl @@ -298,7 +295,7 @@ ARRAY_SIZE_LOOP: ;add hl, de ;__ARRAY_FIN: -#line 131 "/src/zxb/trunk/library-asm/array.asm" +#line 123 "/src/zxb/trunk/library-asm/array.asm" pop de add hl, de ; Adds element start diff --git a/tests/runtime/arrcheck2.bas b/tests/runtime/arrcheck2.bas new file mode 100644 index 000000000..3bb2b033b --- /dev/null +++ b/tests/runtime/arrcheck2.bas @@ -0,0 +1,24 @@ + +DIM a(7, 19, 11) as UInteger +DIM p = @a(0, 0, 0) +DIM i as Uinteger +DIM j as UInteger +DIM k as UInteger +DIM m as UInteger + +FOR i = 0 TO 7 + FOR j = 0 TO 19 + FOR k = 0 TO 11 + LET m = i * j * k + LET a(i, j, k) = m + PRINT AT 0, 0; i; " "; j; " "; k; " " + IF PEEK(UInteger, p) <> m THEN + PRINT INK 2; FLASH 1; " ERROR " + STOP + END IF + LET p = p + 2 + NEXT k + NEXT j +NEXT i + +PRINT INK 4; FLASH 1; " OK " diff --git a/tox.ini b/tox.ini index 4e1fffb00..25707ddd7 100644 --- a/tox.ini +++ b/tox.ini @@ -16,7 +16,7 @@ commands = [flake8] max-line-length = 120 -ignore = E722, E731, E741 +ignore = E722, E731, E741, W504 exclude = .cache/, .tox/,