forked from brendanalford/zx-diagnostics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
128tests.asm
513 lines (372 loc) · 7.66 KB
/
128tests.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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
;
; ZX Diagnostics - fixing ZX Spectrums in the 21st Century
; https://github.com/brendanalford/zx-diagnostics
;
; Original code by Dylan Smith
; Modifications and 128K support by Brendan Alford
;
; This code is free software; you can redistribute it and/or
; modify it under the terms of the GNU Lesser General Public
; License as published by the Free Software Foundation;
; version 2.1 of the License.
;
; This code is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
; Lesser General Public License for more details.
;
; 128tests.asm
;
;
; 128K Specific Tests
;
; Page 5 has already been tested lower RAM), so just do pages 0,1,2,3,4,6 and 7.
; Page each one into the top 16K of RAM and perform the standard fill, inversion
; and random tests.
; Finally, do a paging test (only if the RAM checks pass, otherwise it
; can't be reliable).
;
test_128k
xor a
ld (v_128type), a
jr begin_128_tests
test_plus2
ld a, 1
ld (v_128type), a
jr begin_128_tests
test_plus3
ld a, 2
ld (v_128type), a
jr begin_128_tests
begin_128_tests
ld hl, str_testingbank
call print
; Copy paging string to RAM where we can write to it
ld hl, str_bankm
ld de, v_paging
ld bc, 3
ldir
ld b, 0
; Test an individual RAM page.
test_ram_page
ld a, b
; Don't touch page 5. That's where the screen and sysvars live.
; Plus we've already tested it via the 48K lower RAM tests.
cp 5
jp z, test_ram_page_skip
; Page the target page in and write its index to the screen
call pagein
ld a, b
or 0x30
ld (v_paging), a
ld hl, v_paging
call print
ld hl, str_dblbackspace
call print
xor a
ld (v_fail_ic), a
ld ixh, a
; Run the walk, inversion and random fill tests on the
; target page. Save BC beforehand as we're using that
; to keep track of the current page being tested.
push bc
ld hl, 49152
ld de, 16384
call walkloop
call testresult128
ld hl, 49152
ld bc, 16382
ld d, 0
call altpata
ld hl, 49152
ld bc, 16382
ld d, 255
call altpata
ld hl, 49152
ld bc, 16382
ld d, 0
call altpatb
ld hl, 49152
ld bc, 16382
ld d, 255
call altpatb
call testresult128
ld hl, 49152
ld bc, 16384
call marchtest
call testresult128
ld hl, 49152
ld de, 8192
ld bc, 11
call randfillup
ld hl, 65534
ld de, 8191
ld bc, 17
call randfilldown
call testresult128
pop bc
; Check if we got a failure for this bank
push ix
pop af
cp 0
; Skip to test next page if not
ld a, 60
jr z, test_ram_page_next
ld c, ixh
; Are we on a machine with contention as per the 128 documentation
; (+2A/+3)?
ld a, (v_128type)
cp 2
jr z, even_contend
jr odd_contend
even_contend
; +2a/+3 - Was this in a contented bank (4,5,6,7)?
ld a, b
cp 4
jr nc, test_ram_fail_contend
jr test_ram_fail_uncontend
; 128/+2 - Was this in a contended bank (1,3,5,7)?
odd_contend
bit 0, b
jr nz, test_ram_fail_contend
; Store result in appropriate sysvar
test_ram_fail_uncontend
ld a, (v_fail_ic_uncontend)
or ixh
ld a, ixh
ld (v_fail_ic_uncontend), a
out (LED_PORT), a
ld a, 58
jr test_ram_page_next
; Contended bank fail (1,3,5,7)
test_ram_fail_contend
ld a, (v_fail_ic_contend)
or ixh
ld a, ixh
ld (v_fail_ic_contend), a
out (LED_PORT), a
ld a, 58
; Check if we've any more pages to test
test_ram_page_next
; First write the pass/fail attribute back
ld (v_attr), a
ld hl, v_paging
call print
ld a, 56
ld (v_attr), a
test_ram_page_skip
inc b
ld a, b
cp 8
jp nz, test_ram_page
; Now check if any errors were detected
ld a, (v_fail_ic_contend)
ld b, a
ld a, (v_fail_ic_uncontend)
or b
jp z, test_ram_bank_pass
; Test failed - say so and abort 128K tests.
; No point in testing paging if we don't have
; reliable RAM to do so.
ld hl, str_testfail
call print
call newline
ld hl, str_128ktestsfail
call print
; XXX Todo - check for PCF/ASIC failures by checking low nybble of ixl
ld a, ixl
cp 0x0c
jr z, print_pcf_asic_fail
; If possible, output the failing IC's to the screen
ld hl, str_check_ic
call print
; Are we a +2 or +3?
ld a, (v_128type)
cp 1
jr z, ic_fail_plus2
cp 2
jr z, ic_fail_plus3
; Output failing IC's with Toastrack IC references
ld a, (v_fail_ic_contend)
ld d, a
ld ix, str_128k_ic_contend
call print_fail_ic
ld a, (v_fail_ic_uncontend)
ld d, a
ld ix, str_128k_ic_uncontend
call print_fail_ic
jr test_ram_fail_end
; Output failing IC's with Grey +2 IC references
ic_fail_plus2
ld a, (v_fail_ic_uncontend)
ld d, a
ld ix, str_plus2_ic_uncontend
call print_fail_ic
ld a, (v_fail_ic_contend)
ld d, a
ld ix, str_plus2_ic_contend
call print_fail_ic
jr test_ram_fail_end
ic_fail_plus3
ld a, (v_fail_ic_contend)
ld d, a
ld ix, str_plus3_ic_contend
call print_fail_ic_4bit
ld a, (v_fail_ic_uncontend)
ld d, a
ld ix, str_plus3_ic_uncontend
call print_fail_ic_4bit
jr test_ram_fail_end
print_pcf_asic_fail
ld hl, str_pcf_asic_fail
call print
; Abandon test at this point
test_ram_fail_end
ret
; RAM tests passed, now test the paging
test_ram_bank_pass
ld hl, str_testpass
call print
call newline
ld hl, str_testingpaging
call print
; Fill all RAM pages (except page 5) with a pattern
; that uniquely identifies the page
ld b, 0
test_write_paging
ld a, b
cp 5
jr z, skip_write_page5
; Page target page in and write the pattern
call pagein
push bc
ld hl, 0xc000
ld de, 0xc001
ld bc, 0x3fff
; Ok, it's a really simple pattern (RAM page number) :)
ld (hl), a
ldir
pop bc
skip_write_page5
inc b
ld a, b
cp 8
jr nz, test_write_paging
; Pages all written, now page each one back in turn
; and verify that the expected pattern is in each one.
xor a
ld b, a
test_read_paging
; Skip page 5 as per usual
ld a, b
cp 5
jr z, skip_read_page5
; Page in test page and write which one is being tested to the screen
call pagein
ld a, b
or 0x30
ld (v_paging), a
ld hl, v_paging
call print
ld hl, str_dblbackspace
call print
; Test the full page to see if it matches what was written
ld hl, 0xc000
test_read_loop
ld a, (hl)
cp b
; Non zero comparison means we've not got what we expected.
; RAM all checks out (as far as we know), so this must be
; a paging issue.
jr nz, test_paging_fail
; Otherwise continue testing
inc hl
ld a, h
or l
jr nz, test_read_loop
; Attrs - red text
ld a, 60
ld (v_attr), a
ld hl, v_paging
call print
; Attrs back to normal black
ld a, 56
ld (v_attr), a
skip_read_page5
; Any more pages to test paging with?
inc b
ld a, b
cp 8
jr nz, test_read_paging
; All tests pass, we're all good. Nothing else to test so return.
call newline
ld hl, str_128ktestspass
call print
ret
test_paging_fail
ld a, 58
ld (v_attr), a
ld hl, v_paging
call print
ld a, 56
ld (v_attr), a
; Give the user the bad news
ld a, 2
out (ULA_PORT), a
ld hl, str_testfail
call print
call newline
ld hl, str_128kpagingfail
call print
; A paging fault is most likely the PAL/HAL/ULA chip so identify
; what type of machine we are running on, then use this info to
; inform the user which IC to check
ld a, (v_128type)
cp 1
jr z, plus2_pal_msg
cp 2
jr z, plus3_ula_msg
ld hl, str_check_128_hal
call print
ret
plus2_pal_msg
ld hl, str_check_plus2_hal
call print
ret
plus3_ula_msg
ld hl, str_check_plus3_ula
call print
ret
;
; Overpaints attribute of page number to indicate previous pass/fail
; Inputs: A=attribute to paint
;
set_page_success_status
push hl
push af
ld a, (v_row)
srl a
srl a
srl a
and 3
or 0x58
ld h, a
ld a, (v_row)
sla a
sla a
sla a
sla a
sla a
ld l, a
ld a, (v_column)
dec a
dec a
add a, l
ld l, a
pop af
ld (hl), a
pop hl
ret
test_page_contention
str_pcf_asic_fail
defb "PCF/ASIC Failure\n", 0