Skip to content
This repository was archived by the owner on Sep 10, 2025. It is now read-only.

Commit 81bb2c5

Browse files
authored
Fixed read-test to work correctly (#223)
This program was only testing the first byte of each read-record which meant that it did not accomplish its intended purpose. Also failures of that first byte would show a dump of memory which was bogus. Fixed these, which closes #221. However I think more could be done to improve this program.
1 parent 6372fc0 commit 81bb2c5

File tree

2 files changed

+54
-26
lines changed

2 files changed

+54
-26
lines changed

samples/read.com

40 Bytes
Binary file not shown.

samples/read.z80

Lines changed: 54 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
;; Given a filename open it, and read 256 records to it - testing that the contents
44
;; match what we expect.
55
;;
6-
;; A record of 0x00
7-
;; A record of 0x01
6+
;; A record of 128 bytes each of 0x00
7+
;; A record of 128 bytes each of 0x01
8+
;; A record of 128 bytes each of 0x02
9+
;; A record of 128 bytes each of 0x03
810
;; ..
9-
;; A record of 0xFF
11+
;; A record of 128 bytes each of 0xFE
12+
;; A record of 128 bytes each of 0xFE
1013
;;
1114
;;
1215

@@ -81,22 +84,36 @@ open_ok:
8184
;; Right here we loop from 0x00 - 0xFF starting at 0x00
8285
ld a, 0x00
8386
read_record:
87+
;; show the record we're reading
88+
PUSH_ALL
89+
call show_a_register
90+
ld c, 0x02
91+
ld e, "\n"
92+
call 0x0005
93+
ld c, 0x02
94+
ld e, "\r"
95+
call 0x0005
96+
POP_ALL
97+
98+
;; read the next record into the DMA area
8499
PUSH AF
85-
; read a record
86100
LD C, BDOS_READ_FILE
87101
LD DE, FCB1
88102
CALL BDOS_ENTRY_POINT
89-
90103
POP AF
91104

92105
; Does this record contain the current record number?
93106
LD HL, DMA
94-
LD b,(HL)
95-
CP B
107+
LD b, 128
108+
loopy:
109+
CP (hl)
96110
JR NZ, RECORD_FAILED
111+
inc hl
112+
DEC b
113+
JR NZ, loopy
97114

98115
INC A
99-
cp 0
116+
cp 0x00
100117
jr nz, read_record
101118

102119
;; Close the file
@@ -108,54 +125,65 @@ read_record:
108125
jr exit_fn
109126

110127
RECORD_FAILED:
128+
;; show the failure message
111129
push af
112130
ld de, FAILURE
113131
ld c, BDOS_OUTPUT_STRING
114132
call BDOS_ENTRY_POINT
115133

116134
pop af
135+
136+
;; show the record number
117137
call show_a_register
118138

119-
ld c, 0x02
120-
ld e, 0x0a
121-
call 0x0005
122-
ld c, 0x02
123-
ld e, 0x0d
124-
call 0x0005
139+
;; newline
140+
ld c, 0x02
141+
ld e, "\r"
142+
call 0x0005
143+
ld c, 0x02
144+
ld e, "\n"
145+
call 0x0005
125146

126-
; now dump the memory
147+
;; now dump the DMA-areas memory
127148
ld b, 128
128149
ld hl, DMA
129150
show_mem:
130151
push bc
152+
push hl
131153
ld a,(hl)
132154
call show_a_register
133155
ld c, 0x02
134156
ld e, " "
135157
call 0x0005
158+
pop hl
159+
inc hl
136160
pop bc
137161
djnz show_mem
138-
jr exit_fn
162+
jp exit_fn
139163

140164

165+
;; Display a number from HL
141166
DispHL:
142-
ld c,-10
143-
call Num1
144-
ld c,-1
145-
Num1: ld a,'0'-1
146-
Num2: inc a
147-
add hl,bc
148-
jr c,Num2
149-
sbc hl,bc
167+
ld bc,-100
168+
call Num1
169+
ld c,-10
170+
call Num1
171+
ld c,-1
172+
Num1: ld a,'0'-1
173+
Num2: inc a
174+
add hl,bc
175+
jr c,Num2
176+
sbc hl,bc
150177
PUSH_ALL
151178
ld e, a
152179
ld c, 0x02
153180
call 0x0005
154181
POP_ALL
155-
ret
182+
ret
156183

184+
;; Show the A register contents as a number
157185
show_a_register:
158-
ld h,0
186+
ld h,0x00
159187
ld l,a
160188
call DispHL
161189
ret

0 commit comments

Comments
 (0)