Skip to content

Commit 2304e7f

Browse files
committed
Update array routine to use new scheme
* Also includes ARRAY_PTR routine to use a ref (ptr) to an array. * Also update the ARRAY_FREE_FAST routine (simpler) to free array of strings.
1 parent af00406 commit 2304e7f

2 files changed

Lines changed: 23 additions & 13 deletions

File tree

library-asm/array.asm

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,26 @@
2222
#include once <error.asm>
2323
#endif
2424

25+
__ARRAY_PTR: ;; computes an array offset from a pointer
26+
ld c, (hl)
27+
inc hl
28+
ld h, (hl)
29+
ld l, c
30+
2531
__ARRAY:
2632
PROC
2733

2834
LOCAL LOOP
2935
LOCAL ARRAY_END
3036
LOCAL RET_ADDRESS ; Stores return address
37+
LOCAL TMP_ARR_PTR ; Stores pointer temporarily
3138

39+
ld e, (hl)
40+
inc hl
41+
ld d, (hl)
42+
inc hl
43+
ld (TMP_ARR_PTR), hl
44+
ex de, hl
3245
ex (sp), hl ; Return address in HL, array address in the stack
3346
ld (RET_ADDRESS + 1), hl ; Stores it for later
3447

@@ -78,8 +91,6 @@ LOOP:
7891

7992
ARRAY_END:
8093
ld a, (hl)
81-
inc hl
82-
push hl
8394
exx
8495

8596
#ifdef __BIG_ARRAY__
@@ -98,7 +109,12 @@ ARRAY_SIZE_LOOP:
98109

99110
#endif
100111

101-
pop de
112+
ex de, hl
113+
ld hl, (TMP_ARR_PTR)
114+
ld a, (hl)
115+
inc hl
116+
ld h, (hl)
117+
ld l, a
102118
add hl, de ; Adds element start
103119

104120
RET_ADDRESS:
@@ -125,5 +141,8 @@ __FNMUL2:
125141
djnz __FNMUL2
126142
ret
127143

144+
TMP_ARR_PTR:
145+
DW 0 ; temporary storage for pointer to tables
146+
128147
ENDP
129148

library-asm/arrayfree.asm

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ __ARRAY_FREE:
1313
pop hl ; (ret address)
1414
ex (sp), hl ; Callee -> HL = Number of elements
1515
16-
ex de, hl
16+
ex de, hl
1717

1818
__ARRAY_FREE_FAST: ; Fastcall entry: DE = Number of elements
1919
ld a, h
@@ -23,15 +23,6 @@ __ARRAY_FREE_FAST: ; Fastcall entry: DE = Number of elements
2323
ld b, d
2424
ld c, e
2525

26-
ld e, (hl)
27-
inc hl
28-
ld d, (hl)
29-
inc hl ; DE = Number of dimensions
30-
ex de, hl
31-
add hl, hl ; HL = HL * 2
32-
add hl, de
33-
inc hl ; HL now points to the element start
34-
3526
__ARRAY_LOOP:
3627
ld e, (hl)
3728
inc hl

0 commit comments

Comments
 (0)