Skip to content

Commit 6f929e9

Browse files
committed
Add tests
1 parent 39712e0 commit 6f929e9

8 files changed

Lines changed: 777 additions & 0 deletions

File tree

tests/functional/lbound8.asm

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
org 32768
2+
__START_PROGRAM:
3+
di
4+
push ix
5+
push iy
6+
exx
7+
push hl
8+
exx
9+
ld hl, 0
10+
add hl, sp
11+
ld (__CALL_BACK__), hl
12+
ei
13+
ld hl, _a
14+
push hl
15+
call _test
16+
ld hl, 0
17+
ld b, h
18+
ld c, l
19+
__END_PROGRAM:
20+
di
21+
ld hl, (__CALL_BACK__)
22+
ld sp, hl
23+
exx
24+
pop hl
25+
exx
26+
pop iy
27+
pop ix
28+
ei
29+
ret
30+
__CALL_BACK__:
31+
DEFW 0
32+
_test:
33+
push ix
34+
ld ix, 0
35+
add ix, sp
36+
ld hl, 0
37+
ld (_b), hl
38+
jp __LABEL0
39+
__LABEL3:
40+
ld hl, (_b)
41+
push hl
42+
ld l, (ix+4)
43+
ld h, (ix+5)
44+
call __LBOUND
45+
ld (_c), hl
46+
__LABEL4:
47+
ld hl, (_b)
48+
inc hl
49+
ld (_b), hl
50+
__LABEL0:
51+
ld hl, 3
52+
ld de, (_b)
53+
or a
54+
sbc hl, de
55+
jp nc, __LABEL3
56+
__LABEL2:
57+
_test__leave:
58+
ld sp, ix
59+
pop ix
60+
exx
61+
pop hl
62+
ex (sp), hl
63+
exx
64+
ret
65+
#line 1 "bound.asm"
66+
; ---------------------------------------------------------
67+
; Copyleft (k)2011 by Jose Rodriguez (a.k.a. Boriel)
68+
; http://www.boriel.com
69+
;
70+
; ZX BASIC Compiler http://www.zxbasic.net
71+
; This code is released under the BSD License
72+
; ---------------------------------------------------------
73+
; Implements both LBOUND(array, N) and UBOUND(array, N) function
74+
; Parameters:
75+
; HL = PTR to array
76+
; [stack - 2] -> N (dimension)
77+
PROC
78+
LOCAL __BOUND
79+
LOCAL __DIM_NOT_EXIST
80+
LOCAL __CONT
81+
__LBOUND:
82+
ld a, 4
83+
jr __BOUND
84+
__UBOUND:
85+
ld a, 6
86+
__BOUND:
87+
ex de, hl ; DE <-- Array ptr
88+
pop hl ; HL <-- Ret address
89+
ex (sp), hl ; CALLEE: HL <-- N, (SP) <-- Ret address
90+
ex de, hl ; DE <-- N, HL <-- ARRAY_PTR
91+
push hl
92+
ld c, (hl)
93+
inc hl
94+
ld h, (hl)
95+
ld l, c ; HL = start of dimension table (first position contains number of dimensions - 1)
96+
ld c, (hl)
97+
inc hl
98+
ld b, (hl)
99+
inc bc ; Number of total dimensions of the array
100+
pop hl ; Recovers ARRAY PTR
101+
ex af, af' ; Saves A for later
102+
ld a, d
103+
or e
104+
jr nz, __CONT ; N = 0 => Return number of dimensions
105+
;; Return the number of dimensions of the array
106+
ld h, b
107+
ld l, c
108+
ret
109+
__CONT:
110+
dec de
111+
ex af, af' ; Recovers A (contains PTR offset)
112+
ex de, hl ; HL = N (dimension asked) - 1, DE = Array PTR
113+
or a
114+
sbc hl, bc ; if no Carry => the user asked for a dimension that does not exist. Return 0
115+
jr nc, __DIM_NOT_EXIST
116+
add hl, bc ; restores HL = (N - 1)
117+
add hl, hl ; hl *= 2
118+
ex de, hl ; hl = ARRAY_PTR + 3, DE jsz = (N - 1) * 2
119+
ld b, 0
120+
ld c, a
121+
add hl, bc ; HL = &BOUND_PTR
122+
ld a, (hl)
123+
inc hl
124+
ld h, (hl)
125+
ld l, a ; LD HL, (HL) => Origin of L/U Bound table
126+
add hl, de ; hl += OFFSET __LBOUND._xxxx
127+
ld e, (hl) ; de = (hl)
128+
inc hl
129+
ld d, (hl)
130+
ex de, hl ; hl = de => returns result in HL
131+
ret
132+
__DIM_NOT_EXIST:
133+
; The dimension requested by the user does not exists. Return 0
134+
ld hl, 0
135+
ret
136+
ENDP
137+
#line 54 "lbound8.bas"
138+
ZXBASIC_USER_DATA:
139+
_b:
140+
DEFB 00, 00
141+
_c:
142+
DEFB 00, 00
143+
_a:
144+
DEFW __LABEL5
145+
_a.__DATA__.__PTR__:
146+
DEFW _a.__DATA__
147+
DEFW _a.__LBOUND__
148+
DEFW 0
149+
_a.__DATA__:
150+
DEFB 00h
151+
DEFB 00h
152+
DEFB 00h
153+
DEFB 00h
154+
DEFB 00h
155+
DEFB 00h
156+
DEFB 00h
157+
DEFB 00h
158+
DEFB 00h
159+
__LABEL5:
160+
DEFW 0001h
161+
DEFW 0003h
162+
DEFB 01h
163+
_a.__LBOUND__:
164+
DEFW 0003h
165+
DEFW 0007h
166+
; Defines DATA END --> HEAP size is 0
167+
ZXBASIC_USER_DATA_END:
168+
; Defines USER DATA Length in bytes
169+
ZXBASIC_USER_DATA_LEN EQU ZXBASIC_USER_DATA_END - ZXBASIC_USER_DATA
170+
END

tests/functional/lbound8.bas

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
DIM b, c as UInteger
3+
DIM a(3 TO 5, 7 TO 9) As UByte
4+
5+
SUB test(a() as UByte)
6+
FOR b = 0 TO 3
7+
c = LBound(a, b)
8+
NEXT
9+
END SUB
10+
11+
test(a)
12+
13+

tests/functional/lbound9.asm

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
org 32768
2+
__START_PROGRAM:
3+
di
4+
push ix
5+
push iy
6+
exx
7+
push hl
8+
exx
9+
ld hl, 0
10+
add hl, sp
11+
ld (__CALL_BACK__), hl
12+
ei
13+
ld hl, _a
14+
push hl
15+
call _test2
16+
ld hl, 0
17+
ld b, h
18+
ld c, l
19+
__END_PROGRAM:
20+
di
21+
ld hl, (__CALL_BACK__)
22+
ld sp, hl
23+
exx
24+
pop hl
25+
exx
26+
pop iy
27+
pop ix
28+
ei
29+
ret
30+
__CALL_BACK__:
31+
DEFW 0
32+
_test2:
33+
push ix
34+
ld ix, 0
35+
add ix, sp
36+
ld l, (ix+4)
37+
ld h, (ix+5)
38+
push hl
39+
call _test1
40+
_test2__leave:
41+
ld sp, ix
42+
pop ix
43+
exx
44+
pop hl
45+
ex (sp), hl
46+
exx
47+
ret
48+
_test1:
49+
push ix
50+
ld ix, 0
51+
add ix, sp
52+
ld hl, 0
53+
ld (_b), hl
54+
jp __LABEL0
55+
__LABEL3:
56+
ld hl, (_b)
57+
push hl
58+
ld l, (ix+4)
59+
ld h, (ix+5)
60+
call __LBOUND
61+
ld (_c), hl
62+
__LABEL4:
63+
ld hl, (_b)
64+
inc hl
65+
ld (_b), hl
66+
__LABEL0:
67+
ld hl, 3
68+
ld de, (_b)
69+
or a
70+
sbc hl, de
71+
jp nc, __LABEL3
72+
__LABEL2:
73+
_test1__leave:
74+
ld sp, ix
75+
pop ix
76+
exx
77+
pop hl
78+
ex (sp), hl
79+
exx
80+
ret
81+
#line 1 "bound.asm"
82+
; ---------------------------------------------------------
83+
; Copyleft (k)2011 by Jose Rodriguez (a.k.a. Boriel)
84+
; http://www.boriel.com
85+
;
86+
; ZX BASIC Compiler http://www.zxbasic.net
87+
; This code is released under the BSD License
88+
; ---------------------------------------------------------
89+
; Implements both LBOUND(array, N) and UBOUND(array, N) function
90+
; Parameters:
91+
; HL = PTR to array
92+
; [stack - 2] -> N (dimension)
93+
PROC
94+
LOCAL __BOUND
95+
LOCAL __DIM_NOT_EXIST
96+
LOCAL __CONT
97+
__LBOUND:
98+
ld a, 4
99+
jr __BOUND
100+
__UBOUND:
101+
ld a, 6
102+
__BOUND:
103+
ex de, hl ; DE <-- Array ptr
104+
pop hl ; HL <-- Ret address
105+
ex (sp), hl ; CALLEE: HL <-- N, (SP) <-- Ret address
106+
ex de, hl ; DE <-- N, HL <-- ARRAY_PTR
107+
push hl
108+
ld c, (hl)
109+
inc hl
110+
ld h, (hl)
111+
ld l, c ; HL = start of dimension table (first position contains number of dimensions - 1)
112+
ld c, (hl)
113+
inc hl
114+
ld b, (hl)
115+
inc bc ; Number of total dimensions of the array
116+
pop hl ; Recovers ARRAY PTR
117+
ex af, af' ; Saves A for later
118+
ld a, d
119+
or e
120+
jr nz, __CONT ; N = 0 => Return number of dimensions
121+
;; Return the number of dimensions of the array
122+
ld h, b
123+
ld l, c
124+
ret
125+
__CONT:
126+
dec de
127+
ex af, af' ; Recovers A (contains PTR offset)
128+
ex de, hl ; HL = N (dimension asked) - 1, DE = Array PTR
129+
or a
130+
sbc hl, bc ; if no Carry => the user asked for a dimension that does not exist. Return 0
131+
jr nc, __DIM_NOT_EXIST
132+
add hl, bc ; restores HL = (N - 1)
133+
add hl, hl ; hl *= 2
134+
ex de, hl ; hl = ARRAY_PTR + 3, DE jsz = (N - 1) * 2
135+
ld b, 0
136+
ld c, a
137+
add hl, bc ; HL = &BOUND_PTR
138+
ld a, (hl)
139+
inc hl
140+
ld h, (hl)
141+
ld l, a ; LD HL, (HL) => Origin of L/U Bound table
142+
add hl, de ; hl += OFFSET __LBOUND._xxxx
143+
ld e, (hl) ; de = (hl)
144+
inc hl
145+
ld d, (hl)
146+
ex de, hl ; hl = de => returns result in HL
147+
ret
148+
__DIM_NOT_EXIST:
149+
; The dimension requested by the user does not exists. Return 0
150+
ld hl, 0
151+
ret
152+
ENDP
153+
#line 70 "lbound9.bas"
154+
ZXBASIC_USER_DATA:
155+
_b:
156+
DEFB 00, 00
157+
_c:
158+
DEFB 00, 00
159+
_a:
160+
DEFW __LABEL5
161+
_a.__DATA__.__PTR__:
162+
DEFW _a.__DATA__
163+
DEFW _a.__LBOUND__
164+
DEFW 0
165+
_a.__DATA__:
166+
DEFB 00h
167+
DEFB 00h
168+
DEFB 00h
169+
DEFB 00h
170+
DEFB 00h
171+
DEFB 00h
172+
DEFB 00h
173+
DEFB 00h
174+
DEFB 00h
175+
__LABEL5:
176+
DEFW 0001h
177+
DEFW 0003h
178+
DEFB 01h
179+
_a.__LBOUND__:
180+
DEFW 0003h
181+
DEFW 0007h
182+
; Defines DATA END --> HEAP size is 0
183+
ZXBASIC_USER_DATA_END:
184+
; Defines USER DATA Length in bytes
185+
ZXBASIC_USER_DATA_LEN EQU ZXBASIC_USER_DATA_END - ZXBASIC_USER_DATA
186+
END

tests/functional/lbound9.bas

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
DIM b, c as UInteger
3+
DIM a(3 TO 5, 7 TO 9) As UByte
4+
5+
DECLARE SUB test1(a() as UByte)
6+
7+
SUB test2(b() as UByte)
8+
test1(b)
9+
END SUB
10+
11+
SUB test1(a() as UByte)
12+
FOR b = 0 TO 3
13+
c = LBound(a, b)
14+
NEXT
15+
END SUB
16+
17+
18+
19+
test2(a)
20+

0 commit comments

Comments
 (0)