-
Notifications
You must be signed in to change notification settings - Fork 1
/
memtest.asm
317 lines (283 loc) · 5.8 KB
/
memtest.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
; Z80-MBC2 MEMORY TEST PROGRAM
; James Pattinson 2018
;
; TESTS THE FOLLOWING REGIONS OF MEMORY
; $8300 - $FFFF ; Bit ugly but avoids this program and stack
; $0000 - $7FFF BANK 0
; $0000 - $7FFF BANK 1
; $0000 - $7FFF BANK 2
rx_port .equ $01 ; IOS "serial Rx" read port address
opcode_port .equ $01 ; IOS opcode write port address
exec_wport .equ $00 ; IOS "execute opcode" write port address
tx_opcode .equ $01 ; IOS "serial Tx" operation opcode
sb_opcode .equ $0d ; IOS "switch bank" opcode
eos .equ $00 ; End of string
cr .equ $0d ; Carriage return
lf .equ $0a ; Line feed
ORG $0 ; Force the HEX output of zasm to start at $8000
ORG $8000 ;
LD SP, $82FF
LD HL, MSGSTART
CALL puts
LD HL, $8300
LD DE, $7CFF
CALL RAMTST
CALL CHKERROR
LD A, $0
CALL TESTBANK
LD A, $1
CALL TESTBANK
LD A, $2
CALL TESTBANK
LD HL, MSGALLPASS
CALL puts
HALT
CHKERROR:
RET NC
LD B, A
PUSH HL
LD HL, MSGERROR
CALL puts
POP HL
CALL dispadd
LD HL, MSGBITS
CALL puts
LD A, B
CALL hexout
HALT
TESTBANK:
; A contains bank to switch to and test.
; Displays message and switches bank
LD B, A
LD HL, MSGBANK
CALL puts
ADD A, '0'
CALL putc
LD A, cr
CALL putc
ld A, lf
CALL putc
LD A, sb_opcode
OUT (opcode_port), A
LD A, B
OUT (exec_wport), A
LD HL, $0000
LD DE, $7FFF
CALL RAMTST
CALL CHKERROR
RET
MSGSTART .BYTE "Memory test starting", cr, lf, eos
MSGINFO .BYTE " bytes starting from address ", eos
MSGOK .BYTE "PASS", cr, lf, eos
MSGERROR .BYTE "Test failed at address ", eos
MSGBITS .BYTE " with bit pattern ", eos
MSG00 .BYTE "Read and write 00000000 : ", eos
MSGFF .BYTE "Read and write 11111111 : ", eos
MSGAA .BYTE "Read and write 10101010 : ", eos
MSG55 .BYTE "Read and write 01010101 : ", eos
MSGWLK .BYTE "Walking bit test : ", eos
MSGBANK .BYTE cr, lf, "Switching to BANK ", eos
MSGALLPASS .BYTE cr, lf, "All tests PASSED - HALT", cr, lf, eos
RAMTST:
; EXIT WITH NO ERRORS IF AREA SIZE IS 0
LD A, D
OR E
RET Z
PUSH HL
LD HL, DE
CALL dispadd
LD HL, MSGINFO
CALL puts
POP HL
CALL dispadd
LD A, cr
CALL putc
LD A, lf
CALL putc
LD B,D
LD C,E
;FILL MEMORY WITH 0 AND TEST
PUSH HL
LD HL, MSG00
CALL puts
POP HL
SUB A
CALL FILCMP
RET C
;FILL MEMORY WITH FF HEX AND TEST
PUSH HL
LD HL, MSGFF
CALL puts
POP HL
LD A, $FF
CALL FILCMP
RET C
; FILL MEMORY WITH AA HEX AND TEST
PUSH HL
LD HL, MSGAA
CALL puts
POP HL
LD A, $AA
CALL FILCMP
RET C
; FILL MEMORY WITH 55 HEX AND TEST
PUSH HL
LD HL, MSG55
CALL puts
POP HL
LD A, $55
CALL FILCMP
RET C
PUSH HL
LD HL, MSGWLK
CALL puts
POP HL
WLKLP:
LD A, $80 ; BINARY 1000000
WLKLP1:
LD (HL), A ; STORE TEST PATTERN IN MEMORY
CP (HL) ; TRY TO READ IT BACK
SCF ; SET CARRY N CASE OF ERROR
RET NZ ; RETURN IF ERROR
RRCA ; ROTATE PATTERN 1 RIGHT
CP $80
JR NZ,WLKLP1 ; CONT UNTIL BINARY 10000000 AGAIN
LD (HL), 0 ; CLEAR BYTE JUST CHECKED
INC HL
DEC BC ; DEC AND TEST 16-BIT COUNTER
LD A, B
OR C ; CLEAR CARRY
JR NZ,WLKLP ; CONT UNTIL MEMORY TESTED
PUSH HL
LD HL, MSGOK
CALL puts
POP HL
RET ; NO ERRORS
FILCMP:
PUSH HL ; SAVE BASE ADDRESS
PUSH BC ; SAVE SIZE OF AREA
LD E, A ; SAVE TEST VALUE
LD (HL), A ; STORE TEST VALUE IN FIRST BYTE
DEC BC ; REMAINING AREA = SIZE - 1
LD A, B ; CHECK IF ANY AREA REMAINS
OR C
LD A, E ; RESTORE TEST VALUE
JR Z, COMPARE ; BRANCH IF AREA WAS ONLY 1 BYTE
; FILL REST OF AREA USING BLOCK MOVE
; EACH ITERATION MOVES TEST VALUE TO NEXT HIGHER ADDRESS
LD D, H ; DESTINATION IS ALWAYS SOURCE + 1
LD E, L
INC DE
LDIR ; FILL MEMORY
; NOW THAT MEMORY HAS BEEN FILLED, TEST TO SEE IF
; EACH BYTE CAN BE READ BACK CORRECTLY
COMPARE:
POP BC ; RESTORE SIZE OF AREA
POP HL ; RESTORE BASE ADDRESS
PUSH HL ; SAVE BASE ADDRESS
PUSH BC ; SAVE SIZE OF VALUE
; COMPARE MEMORY AND TEST VALUE
CMPLP:
CPI
JR NZ, CMPER ; JUMP IF NOT EQUAL
JP PE, CMPLP ; CONTINUE THROUGH ENTIRE AREA
; NOTE CPI CLEARS P/V FLAG IF IT
; DECREMENTS BC TO 0
; NO ERRORS FOUND, SO CLEAR CARRY
POP BC ; BC = SIZE OF AREA
POP HL ; HL = BASE ADDRESS
OR A ; CLEARS CARRY
PUSH HL
LD HL, MSGOK
CALL puts
POP HL
RET
; ERROR EXIT, SET CARRY
CMPER:
POP BC
POP DE
SCF
RET
;
; Send a string to the serial line, HL contains the pointer to the string
;
puts push af
push hl
puts_loop ld a, (hl)
cp eos ; End of string reached?
jr z, puts_end ; Yes
call putc
inc hl ; Increment character pointer
jr puts_loop ; Transmit next character
puts_end pop hl
pop af
ret
;
; Send a single character to the serial line (A contains the character)
;
putc push af ; Save A
ld a, tx_opcode ; A = IOS Serial Tx operation opcode
out (opcode_port), a; Send to IOS the Tx operation opcode
pop af ; Restore the output char into A
out (exec_wport), a ; Write A to the serial
ret
;; Display '[aaaa]' - address of HL
dispadd:
LD A, '['
CALL putc
LD A, H
CALL hexout
LD A, L
CALL hexout
LD A, ']'
CALL putc
RET
; OUTPUT VALUE OF A IN HEX ONE NYBBLE AT A TIME
hexout PUSH BC
PUSH AF
LD B, A
; Upper nybble
SRL A
SRL A
SRL A
SRL A
CALL TOHEX
CALL putc
; Lower nybble
LD A, B
AND 0FH
CALL TOHEX
CALL putc
POP AF
POP BC
RET
; TRANSLATE VALUE IN A TO 2 HEX CHAR CODES FOR DISPLAY
TOHEX:
PUSH HL
PUSH DE
LD D, 0
LD E, A
LD HL, DATA
ADD HL, DE
LD A, (HL)
POP DE
POP HL
RET
; LOOKUP TABLE FOR TOHEX ROUTINE
DATA:
DEFB 30h ; 0
DEFB 31h ; 1
DEFB 32h ; 2
DEFB 33h ; 3
DEFB 34h ; 4
DEFB 35h ; 5
DEFB 36h ; 6
DEFB 37h ; 7
DEFB 38h ; 8
DEFB 39h ; 9
DEFB 41h ; A
DEFB 42h ; B
DEFB 43h ; C
DEFB 44h ; D
DEFB 45h ; E
DEFB 46h ; F