Skip to content

Commit 8c9215f

Browse files
authored
Merge pull request #209 from boriel/bugfix/array_access
Bugfix/array access
2 parents 5879814 + 935485e commit 8c9215f

27 files changed

+322
-322
lines changed

library-asm/array.asm

+10-10
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ __ARRAY:
4040
inc hl ; Ready
4141
exx
4242
43-
ld hl, 0 ; BC = Offset "accumulator"
43+
ld hl, 0 ; HL = Offset "accumulator"
4444

4545
LOOP:
4646
#ifdef __CHECK_ARRAY_BOUNDARY__
@@ -75,26 +75,24 @@ LOOP:
7575

7676
call __FNMUL
7777
jp LOOP
78-
78+
7979
ARRAY_END:
80-
ld e, (hl)
80+
ld a, (hl)
8181
inc hl
82-
ld d, c ; C = 0 => DE = E = Element size
8382
push hl
84-
push de
8583
exx
8684

8785
#ifdef __BIG_ARRAY__
88-
pop de
86+
ld d, 0
87+
ld e, a
8988
call __FNMUL
9089
#else
9190
LOCAL ARRAY_SIZE_LOOP
9291

9392
ex de, hl
9493
ld hl, 0
95-
pop bc
96-
ld b, c
97-
ARRAY_SIZE_LOOP:
94+
ld b, a
95+
ARRAY_SIZE_LOOP:
9896
add hl, de
9997
djnz ARRAY_SIZE_LOOP
10098

@@ -111,8 +109,10 @@ RET_ADDRESS:
111109

112110
__FNMUL:
113111
xor a
114-
or d
112+
or h
115113
jp nz, __MUL16_FAST
114+
or l
115+
ret z
116116

117117
cp 33
118118
jp nc, __MUL16_FAST

tests/functional/46.asm

+11-12
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ __MUL16NOADD:
9797

9898
#line 20 "array.asm"
9999

100-
#line 24 "/zxbasic/library-asm/array.asm"
100+
#line 24 "/home/boriel/src/zxbasic/zxbasic/library-asm/array.asm"
101101

102102
__ARRAY:
103103
PROC
@@ -117,13 +117,13 @@ __ARRAY:
117117
inc hl ; Ready
118118
exx
119119

120-
ld hl, 0 ; BC = Offset "accumulator"
120+
ld hl, 0 ; HL = Offset "accumulator"
121121

122122
LOOP:
123-
#line 49 "/zxbasic/library-asm/array.asm"
123+
#line 49 "/home/boriel/src/zxbasic/zxbasic/library-asm/array.asm"
124124
pop bc ; Get next index (Ai) from the stack
125125

126-
#line 59 "/zxbasic/library-asm/array.asm"
126+
#line 59 "/home/boriel/src/zxbasic/zxbasic/library-asm/array.asm"
127127

128128
add hl, bc ; Adds current index
129129

@@ -145,25 +145,22 @@ LOOP:
145145
jp LOOP
146146

147147
ARRAY_END:
148-
ld e, (hl)
148+
ld a, (hl)
149149
inc hl
150-
ld d, c ; C = 0 => DE = E = Element size
151150
push hl
152-
push de
153151
exx
154152

155-
#line 91 "/zxbasic/library-asm/array.asm"
153+
#line 90 "/home/boriel/src/zxbasic/zxbasic/library-asm/array.asm"
156154
LOCAL ARRAY_SIZE_LOOP
157155

158156
ex de, hl
159157
ld hl, 0
160-
pop bc
161-
ld b, c
158+
ld b, a
162159
ARRAY_SIZE_LOOP:
163160
add hl, de
164161
djnz ARRAY_SIZE_LOOP
165162

166-
#line 102 "/zxbasic/library-asm/array.asm"
163+
#line 100 "/home/boriel/src/zxbasic/zxbasic/library-asm/array.asm"
167164

168165
pop de
169166
add hl, de ; Adds element start
@@ -176,8 +173,10 @@ RET_ADDRESS:
176173

177174
__FNMUL:
178175
xor a
179-
or d
176+
or h
180177
jp nz, __MUL16_FAST
178+
or l
179+
ret z
181180

182181
cp 33
183182
jp nc, __MUL16_FAST

tests/functional/47.asm

+8-9
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ __ARRAY:
144144
inc hl ; Ready
145145
exx
146146

147-
ld hl, 0 ; BC = Offset "accumulator"
147+
ld hl, 0 ; HL = Offset "accumulator"
148148

149149
LOOP:
150150
#line 49 "/zxbasic/library-asm/array.asm"
@@ -172,25 +172,22 @@ LOOP:
172172
jp LOOP
173173

174174
ARRAY_END:
175-
ld e, (hl)
175+
ld a, (hl)
176176
inc hl
177-
ld d, c ; C = 0 => DE = E = Element size
178177
push hl
179-
push de
180178
exx
181179

182-
#line 91 "/zxbasic/library-asm/array.asm"
180+
#line 90 "/zxbasic/library-asm/array.asm"
183181
LOCAL ARRAY_SIZE_LOOP
184182

185183
ex de, hl
186184
ld hl, 0
187-
pop bc
188-
ld b, c
185+
ld b, a
189186
ARRAY_SIZE_LOOP:
190187
add hl, de
191188
djnz ARRAY_SIZE_LOOP
192189

193-
#line 102 "/zxbasic/library-asm/array.asm"
190+
#line 100 "/zxbasic/library-asm/array.asm"
194191

195192
pop de
196193
add hl, de ; Adds element start
@@ -203,8 +200,10 @@ RET_ADDRESS:
203200

204201
__FNMUL:
205202
xor a
206-
or d
203+
or h
207204
jp nz, __MUL16_FAST
205+
or l
206+
ret z
208207

209208
cp 33
210209
jp nc, __MUL16_FAST

tests/functional/55.asm

+11-12
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ __MUL16NOADD:
9292

9393
#line 20 "array.asm"
9494

95-
#line 24 "/zxbasic/library-asm/array.asm"
95+
#line 24 "/home/boriel/src/zxbasic/zxbasic/library-asm/array.asm"
9696

9797
__ARRAY:
9898
PROC
@@ -112,13 +112,13 @@ __ARRAY:
112112
inc hl ; Ready
113113
exx
114114

115-
ld hl, 0 ; BC = Offset "accumulator"
115+
ld hl, 0 ; HL = Offset "accumulator"
116116

117117
LOOP:
118-
#line 49 "/zxbasic/library-asm/array.asm"
118+
#line 49 "/home/boriel/src/zxbasic/zxbasic/library-asm/array.asm"
119119
pop bc ; Get next index (Ai) from the stack
120120

121-
#line 59 "/zxbasic/library-asm/array.asm"
121+
#line 59 "/home/boriel/src/zxbasic/zxbasic/library-asm/array.asm"
122122

123123
add hl, bc ; Adds current index
124124

@@ -140,25 +140,22 @@ LOOP:
140140
jp LOOP
141141

142142
ARRAY_END:
143-
ld e, (hl)
143+
ld a, (hl)
144144
inc hl
145-
ld d, c ; C = 0 => DE = E = Element size
146145
push hl
147-
push de
148146
exx
149147

150-
#line 91 "/zxbasic/library-asm/array.asm"
148+
#line 90 "/home/boriel/src/zxbasic/zxbasic/library-asm/array.asm"
151149
LOCAL ARRAY_SIZE_LOOP
152150

153151
ex de, hl
154152
ld hl, 0
155-
pop bc
156-
ld b, c
153+
ld b, a
157154
ARRAY_SIZE_LOOP:
158155
add hl, de
159156
djnz ARRAY_SIZE_LOOP
160157

161-
#line 102 "/zxbasic/library-asm/array.asm"
158+
#line 100 "/home/boriel/src/zxbasic/zxbasic/library-asm/array.asm"
162159

163160
pop de
164161
add hl, de ; Adds element start
@@ -171,8 +168,10 @@ RET_ADDRESS:
171168

172169
__FNMUL:
173170
xor a
174-
or d
171+
or h
175172
jp nz, __MUL16_FAST
173+
or l
174+
ret z
176175

177176
cp 33
178177
jp nc, __MUL16_FAST

tests/functional/aloadstr1.asm

+13-14
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ __MUL16NOADD:
9595

9696
#line 20 "array.asm"
9797

98-
#line 24 "/zxbasic/library-asm/array.asm"
98+
#line 24 "/home/boriel/src/zxbasic/zxbasic/library-asm/array.asm"
9999

100100
__ARRAY:
101101
PROC
@@ -115,13 +115,13 @@ __ARRAY:
115115
inc hl ; Ready
116116
exx
117117

118-
ld hl, 0 ; BC = Offset "accumulator"
118+
ld hl, 0 ; HL = Offset "accumulator"
119119

120120
LOOP:
121-
#line 49 "/zxbasic/library-asm/array.asm"
121+
#line 49 "/home/boriel/src/zxbasic/zxbasic/library-asm/array.asm"
122122
pop bc ; Get next index (Ai) from the stack
123123

124-
#line 59 "/zxbasic/library-asm/array.asm"
124+
#line 59 "/home/boriel/src/zxbasic/zxbasic/library-asm/array.asm"
125125

126126
add hl, bc ; Adds current index
127127

@@ -143,25 +143,22 @@ LOOP:
143143
jp LOOP
144144

145145
ARRAY_END:
146-
ld e, (hl)
146+
ld a, (hl)
147147
inc hl
148-
ld d, c ; C = 0 => DE = E = Element size
149148
push hl
150-
push de
151149
exx
152150

153-
#line 91 "/zxbasic/library-asm/array.asm"
151+
#line 90 "/home/boriel/src/zxbasic/zxbasic/library-asm/array.asm"
154152
LOCAL ARRAY_SIZE_LOOP
155153

156154
ex de, hl
157155
ld hl, 0
158-
pop bc
159-
ld b, c
156+
ld b, a
160157
ARRAY_SIZE_LOOP:
161158
add hl, de
162159
djnz ARRAY_SIZE_LOOP
163160

164-
#line 102 "/zxbasic/library-asm/array.asm"
161+
#line 100 "/home/boriel/src/zxbasic/zxbasic/library-asm/array.asm"
165162

166163
pop de
167164
add hl, de ; Adds element start
@@ -174,8 +171,10 @@ RET_ADDRESS:
174171

175172
__FNMUL:
176173
xor a
177-
or d
174+
or h
178175
jp nz, __MUL16_FAST
176+
or l
177+
ret z
179178

180179
cp 33
181180
jp nc, __MUL16_FAST
@@ -470,9 +469,9 @@ __MEM_START:
470469
__MEM_LOOP: ; Loads lengh at (HL, HL+). If Lenght >= BC, jump to __MEM_DONE
471470
ld a, h ; HL = NULL (No memory available?)
472471
or l
473-
#line 111 "/zxbasic/library-asm/alloc.asm"
472+
#line 111 "/home/boriel/src/zxbasic/zxbasic/library-asm/alloc.asm"
474473
ret z ; NULL
475-
#line 113 "/zxbasic/library-asm/alloc.asm"
474+
#line 113 "/home/boriel/src/zxbasic/zxbasic/library-asm/alloc.asm"
476475
; HL = Pointer to Free block
477476
ld e, (hl)
478477
inc hl

tests/functional/array03.asm

+11-12
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ __MUL16NOADD:
9090

9191
#line 20 "array.asm"
9292

93-
#line 24 "/zxbasic/library-asm/array.asm"
93+
#line 24 "/home/boriel/src/zxbasic/zxbasic/library-asm/array.asm"
9494

9595
__ARRAY:
9696
PROC
@@ -110,13 +110,13 @@ __ARRAY:
110110
inc hl ; Ready
111111
exx
112112

113-
ld hl, 0 ; BC = Offset "accumulator"
113+
ld hl, 0 ; HL = Offset "accumulator"
114114

115115
LOOP:
116-
#line 49 "/zxbasic/library-asm/array.asm"
116+
#line 49 "/home/boriel/src/zxbasic/zxbasic/library-asm/array.asm"
117117
pop bc ; Get next index (Ai) from the stack
118118

119-
#line 59 "/zxbasic/library-asm/array.asm"
119+
#line 59 "/home/boriel/src/zxbasic/zxbasic/library-asm/array.asm"
120120

121121
add hl, bc ; Adds current index
122122

@@ -138,25 +138,22 @@ LOOP:
138138
jp LOOP
139139

140140
ARRAY_END:
141-
ld e, (hl)
141+
ld a, (hl)
142142
inc hl
143-
ld d, c ; C = 0 => DE = E = Element size
144143
push hl
145-
push de
146144
exx
147145

148-
#line 91 "/zxbasic/library-asm/array.asm"
146+
#line 90 "/home/boriel/src/zxbasic/zxbasic/library-asm/array.asm"
149147
LOCAL ARRAY_SIZE_LOOP
150148

151149
ex de, hl
152150
ld hl, 0
153-
pop bc
154-
ld b, c
151+
ld b, a
155152
ARRAY_SIZE_LOOP:
156153
add hl, de
157154
djnz ARRAY_SIZE_LOOP
158155

159-
#line 102 "/zxbasic/library-asm/array.asm"
156+
#line 100 "/home/boriel/src/zxbasic/zxbasic/library-asm/array.asm"
160157

161158
pop de
162159
add hl, de ; Adds element start
@@ -169,8 +166,10 @@ RET_ADDRESS:
169166

170167
__FNMUL:
171168
xor a
172-
or d
169+
or h
173170
jp nz, __MUL16_FAST
171+
or l
172+
ret z
174173

175174
cp 33
176175
jp nc, __MUL16_FAST

0 commit comments

Comments
 (0)