monroeoc8800diag.asm 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  1. ; code: language=z80-asm tabSize=8
  2. ; SIMULATE_ERROR = $80
  3. ; SIMULATE_ERROR = $3C
  4. .include "inc/z80.mac"
  5. .include "inc/spt.mac"
  6. ; Notes on global register allocation:
  7. ;
  8. ; This ROM doesn't work like typical Z80 code, which assumes the presence of a stack.
  9. ; There may in fact be no working memory in the machine for holding the stack.
  10. ;
  11. ; An overall goal for this version of the code is to run in the absence of any working
  12. ; ram at all. There is no stack and no RAM variables. The only storage of variables
  13. ; is in registers, so the registers must be carefully preserved.
  14. ;
  15. ; Without a stack, that means either saving them to other registers and restoring before
  16. ; jumping to other code (remembering there can be no CALLs when there is no stack)
  17. ; or avoiding their use altogether. These are extremely confining restrictions.
  18. ;
  19. ; Assembly purists will shudder at the extensive use of macros, but for sanity it
  20. ; cannot be avoided.
  21. ;
  22. ; Globally, the contents of these registers must be preserved
  23. ; e = bit errors in the region of memory currently being tested
  24. ; ix = current location in VRAM for printing messages
  25. ; iy = current table entry for test parameters
  26. ;
  27. VBASE equ 03000h
  28. VSIZE equ 0ffeh
  29. VLINE equ 80
  30. .org 0000h ; z80 boot code starts at location 0
  31. reset:
  32. di ; mask INT
  33. im 1
  34. diagnostics:
  35. xor a
  36. out (0c0h),a ;0046 clear io, floppy control
  37. out (0c4h),a ;0048 clear io,Program map A base
  38. out (0c5h),a ;004a clear io,Program map B base
  39. out (0c6h),a ;004c clear io,DMA map A base
  40. out (0c7h),a ;004e clear io,DMA map B base
  41. out (0d4h),a ;0050 clear io,Hi-res color
  42. out (0d8h),a ;0052 clear io,Hi-res start
  43. ld hl,set_regs_start
  44. jp set_monroe_regs
  45. init_continue:
  46. jp setupclearscreen
  47. screen_clear_continue:
  48. ld a,080h ;0092
  49. out (0d4h),a
  50. ;
  51. ld a,005h ;00a8
  52. out (0a3h),a ;00aa DART B command
  53. ld a,068h ;00ac
  54. out (0a3h),a ;00ae DART B command
  55. ld a,0f0h ;00b0 ?????
  56. out (0c8h),a ;00b2 Map and system control
  57. ;select screen memory
  58. ld a,004h ;0541 Select display memory
  59. out (0c8h),a ;0543 Output to screen Map and system control
  60. test_vram:
  61. SPTHREAD_BEGIN ; set up to begin running threaded code
  62. SPT_SKIP_NMIVEC
  63. dw spt_playmusic, tones_welcome
  64. dw spt_select_test, tp_vram
  65. dw memtestmarch ; test the VRAM
  66. dw spt_check_7bit_vram
  67. ; dw spt_sim_error, $40
  68. dw spt_jp_nc, .vram_ok
  69. ; we have bad vram
  70. dw spt_prepare_display
  71. dw spt_chartest
  72. .vram_bad_loop:
  73. ;dw spt_play_testresult ; play the tones for bit errorssetupcrt
  74. ;dw spt_pause, $0000
  75. dw spt_jp,.vram_bad_loop
  76. .vram_7bit:
  77. dw spt_con_print, msg_ok7bit
  78. ; dw spt_play_testresult ; play the tones for bit errors
  79. ;dw spt_jp,.vram_goodtones
  80. .vram_ok:
  81. dw spt_prepare_display
  82. MAC_SPT_CON_GOTO 2,0
  83. dw spt_announcetest2 ; print results of VRAM tst
  84. ; dw print_biterrs
  85. dw spt_jp_e_7bit_vram, .vram_7bit
  86. dw spt_con_print, msg_ok8bit
  87. .vram_goodtones:
  88. ;dw spt_playmusic, tones_vramgood ; play the VRAM good tones
  89. .vram_continue:
  90. MAC_SPT_CON_GOTO 1,0
  91. dw spt_check_size
  92. dw spt_jp_256_fail, .skip256
  93. dw spt_con_print, msg_256k
  94. dw spt_select_test, tp_16k_256 ; load the first test
  95. dw spt_jp, .start
  96. .skip256:
  97. dw spt_con_print, msg_128k
  98. dw spt_select_test, tp_16k ; load the first test
  99. dw spt_jp, .start
  100. .start: dw spt_con_goto
  101. MAC_SPT_CON_OFFSET 3,0
  102. .loop: dw spt_announcetest ; announce what test we are about to run
  103. dw memtestmarch2 ; test the current bank
  104. dw spt_jp_nc, .ok
  105. dw spt_con_print, msg_biterrs ; we have errors: print the bit string
  106. dw print_biterrs
  107. ;dw spt_play_testresult ; play the tones for bit errors
  108. dw spt_jp, .cont
  109. .ok: dw spt_con_print, msg_testok ; bank is good: print the OK message
  110. ;dw spt_play_testresult ; play the tones
  111. .cont:
  112. dw spt_tp_next, .start
  113. dw spt_jp, .loop
  114. ;; -------------------------------------------------------------------------------------------------
  115. ;; end of main program.
  116. spt_prepare_display:
  117. SPTHREAD_ENTER
  118. dw con_clear
  119. dw spt_con_print, msg_banner ; print the banner
  120. dw spt_print_charset
  121. dw spt_exit
  122. spt_check_size:
  123. ; Check if 256k memory or 128k
  124. ld hl,0c000h ;
  125. ld a,0a0h ;
  126. ld b,00h ;
  127. out (0c5h),a ; Select memory bank 9
  128. ld (hl),b ;
  129. dec b ;
  130. inc a ;
  131. out (0c5h),a ; Select memory bank 1
  132. ld (hl),b ;
  133. dec a ;
  134. out (0c5h),a ; Select memory bank 9
  135. ld b,(hl) ;
  136. ret
  137. spt_check_vram_contents:
  138. pop bc
  139. ld a,b
  140. ld d,c
  141. ; confirm that all of VRAM contains the value in register A
  142. check_vram_contents:
  143. ld hl,VBASE
  144. ld bc,VSIZE
  145. .fillloop:
  146. ld (HL),a
  147. cpi
  148. jp pe,.fillloop
  149. ld hl,VBASE
  150. ld bc,VSIZE
  151. ld a,d
  152. .readloop:
  153. cpi
  154. jr nz,.bad
  155. jp pe,.readloop
  156. or a ; clear carry flag
  157. ret
  158. .bad: scf
  159. ret
  160. spt_check_7bit_vram:
  161. ret nc ; if carry flag is not set, do nothing
  162. ld a,01000000b
  163. cp e
  164. jr z,.scantests
  165. scf ; something other than bit 6 is bad, so this is not 7bit VRAM
  166. ret
  167. .scantests:
  168. SPTHREAD_ENTER
  169. dw spt_check_vram_contents, $0040
  170. dw spt_jp_c, .exit
  171. dw spt_check_vram_contents, $FFBF
  172. dw spt_jp_c, .exit
  173. dw spt_check_vram_contents, $AAAA
  174. dw spt_jp_c, .exit
  175. dw spt_check_vram_contents, $5555
  176. dw spt_jp_c, .exit
  177. .exit: dw spt_exit ; if carry flag is set, this is not good 7-bit VRAM
  178. spt_sim_error:
  179. pop de
  180. scf
  181. ret
  182. ; test if the error is $FF (all bits bad)
  183. spt_jp_256_fail:
  184. pop hl ; get the address for jumping if match
  185. inc b
  186. ret nz ; return without jump if there is NOT a match
  187. ld sp,hl ; else jump to the requested location
  188. ret
  189. ; test if the e register matches 7-bit vram and jump to spt address if match
  190. spt_jp_e_7bit_vram:
  191. pop hl ; get the address for jumping if match
  192. ld a,01000000b ; ignore bit 6
  193. cp e ; see if there are other errors
  194. ret nz ; return without jump if there is NOT a match
  195. ld sp,hl ; else jump to the requested location
  196. ret
  197. ; test if the e register matches 7-bit vram and jump to spt address if match
  198. spt_jp_e_zero:
  199. pop hl ; get the address for jumping if match
  200. ld a,0 ; test clean
  201. cp e ; see if there are other errors
  202. ret nz ; return without jump if there is NOT a match
  203. ld sp,hl ; else jump to the requested location
  204. ret
  205. ; load the label string address from the current test parameter table entry into hl
  206. spt_ld_hl_tp_label:
  207. ld l,(iy+4)
  208. ld h,(iy+5)
  209. ret
  210. ; load the label string address from the current test parameter table entry into hl
  211. spt_ld_hl_tp_tones:
  212. ld l,(iy+6)
  213. ld h,(iy+7)
  214. ret
  215. spt_ld_new_line:
  216. ld a,(iy+9)
  217. ld ixh,a
  218. ld a,(iy+8)
  219. ld ixl,a
  220. ret
  221. ; move to the next test parameter table entry
  222. spt_tp_next: pop hl ; get the address to jump to if we are starting over
  223. ld bc,tp_size ; find the next entry
  224. add iy,bc
  225. ld a,(iy+0) ; is the length zero?
  226. add a,(iy+1)
  227. ret nz ; no, use it
  228. ld c,(iy+2) ; yes, get the address of the first entry
  229. ld b,(iy+3)
  230. ld iy,0
  231. add iy,bc
  232. ; sub a ; clear zero flag when restarting
  233. ld sp,hl ; jump to the next location
  234. ret
  235. spt_announcetest:
  236. ; pop hl ; get the message to be printed
  237. SPTHREAD_ENTER
  238. dw spt_ld_new_line
  239. ;dw con_NL
  240. dw spt_ld_hl_tp_label
  241. dw con_print ; picks up message from hl
  242. dw spt_con_print, msg_testing
  243. dw spt_con_index, -18
  244. dw spt_exit
  245. spt_announcetest2:
  246. ; pop hl ; get the message to be printed
  247. SPTHREAD_ENTER
  248. dw spt_ld_hl_tp_label
  249. dw con_print ; picks up message from hl
  250. dw spt_con_print, msg_testing
  251. dw spt_con_index, -18
  252. dw spt_exit
  253. spt_play_testresult:
  254. SPTHREAD_SAVE ; save the stack pointer
  255. SPTHREAD_BEGIN
  256. dw spt_ld_hl_tp_tones ; play the ID tune for current bank
  257. ;dw playmusic
  258. dw spt_pause, $2000
  259. SPTHREAD_END
  260. ld a,$FF
  261. cp e
  262. jr z,.allbad ; if all bits bad, play shorter tune
  263. cpl
  264. cp e
  265. jr z,.allgood ; if all bits good, play shorter tune
  266. ld d,8 ; play bit tune for each bit, high to low
  267. .showbit:
  268. rlc e
  269. jr nc,.zero
  270. ld hl,tones_bitbad
  271. jr .msbe_cont
  272. .zero:
  273. ld hl,tones_bitgood
  274. .msbe_cont:
  275. SPTHREAD_BEGIN
  276. ;dw playmusic
  277. dw spt_pause, $2000
  278. SPTHREAD_END
  279. ; pause $4000
  280. dec d
  281. jr nz,.showbit
  282. jr .done
  283. .allbad:
  284. SPTHREAD_BEGIN
  285. ;dw spt_playmusic, tones_bytebad
  286. dw spt_pause, $8000
  287. SPTHREAD_END
  288. jr .done
  289. .allgood:
  290. SPTHREAD_BEGIN
  291. ;dw spt_playmusic, tones_bytegood
  292. dw spt_pause, $8000
  293. SPTHREAD_END
  294. .done:
  295. SPTHREAD_RESTORE ; restore the stack pointer
  296. ret
  297. spt_pause:
  298. pop bc
  299. ; pause by an amount specified in BC
  300. pause_bc:
  301. .loop:
  302. dec bc
  303. ld a,b
  304. or c
  305. jr nz,.loop
  306. ret
  307. print_biterrs:
  308. ld a,004h ; Select display memory
  309. out (0c8h),a ; Output to screen Map and system control
  310. ld a,'7'
  311. ld b,8
  312. .showbit:
  313. rlc e
  314. jr nc,.zero
  315. ld (ix+1),a
  316. jr .cont
  317. .zero:
  318. ld (ix+1),'.'
  319. .cont:
  320. inc ix
  321. inc ix
  322. dec a
  323. djnz .showbit
  324. xor a ;054b Reset map
  325. out (0c8h),a ;054c Reset to memory Map and system control
  326. ret
  327. spt_ld_bc: pop bc
  328. ret
  329. spt_print_charset:
  330. ld a,ixh
  331. ld h,a
  332. ld a,ixl
  333. ld l,a
  334. ld a,0
  335. SPTHREAD_ENTER
  336. MAC_SPT_CON_GOTO 15,24
  337. dw spt_con_print, msg_charset ; show a copy of the character set
  338. MAC_SPT_CON_GOTO 16,0
  339. dw spt_ld_bc, $100
  340. dw do_charset_ix
  341. dw spt_exit
  342. spt_chartest:
  343. ld ix,VBASE
  344. ld bc,VSIZE
  345. do_charset_ix:
  346. ld a,004h ; Select display memory
  347. out (0c8h),a ; Output to screen Map and system control
  348. ld a,32
  349. .charloop:
  350. ld (ix+1),a ; copy A to byte pointed by HL
  351. inc a ; increments A
  352. inc ix
  353. inc ix
  354. cpi ; increments HL, decrements BC (and does a CP)
  355. jp pe, .charloop
  356. xor a ;054b Reset map
  357. out (0c8h),a ;054c Reset to memory Map and system control
  358. ret
  359. screenclearloop:
  360. otir ;0560 out B bytes from (HL) to (C)
  361. set_monroe_regs:
  362. ld c,(hl) ; get register
  363. inc hl ; bump
  364. ld b,(hl) ;get count
  365. inc hl ; bump
  366. ld a,b ;
  367. and a ;
  368. jr nz,screenclearloop ;0568 if count not 0 loop $-8
  369. jp init_continue
  370. setupclearscreen:
  371. ;entry during initiation w
  372. xor a ; start A=0
  373. ld bc,00eb9h ; C=B9 B=14
  374. ld hl,set_up_crt ;
  375. setupclearloop:
  376. out (0b8h),a ;CRT register select
  377. inc a ; A++
  378. outi ; C)=(HL++) and B--
  379. jr nz,setupclearloop ; loop until B==0 (14 bytes to write) $-5
  380. jp screen_clear_continue
  381. label_vram: dbz " 4K VRAM 3000-3FFE "
  382. label_dram16k1: dbz "16K DRAM 0 C000-FFFF "
  383. label_dram16k2: dbz "16K DRAM 1 C000-FFFF "
  384. label_dram16k3: dbz "16K DRAM 2 C000-FFFF "
  385. label_dram16k4: dbz "16K DRAM 3 C000-FFFF "
  386. label_dram16k5: dbz "16K DRAM 4 C000-FFFF "
  387. label_dram16k6: dbz "16K DRAM 5 C000-FFFF "
  388. label_dram16k7: dbz "16K DRAM 6 C000-FFFF "
  389. label_dram16k8: dbz "16K DRAM 7 C000-FFFF "
  390. label_dram16k9: dbz "16K DRAM 8 C000-FFFF "
  391. label_dram16k10: dbz "16K DRAM 9 C000-FFFF "
  392. label_dram16k11: dbz "16K DRAM 10 C000-FFFF "
  393. label_dram16k12: dbz "16K DRAM 11 C000-FFFF "
  394. label_dram16k13: dbz "16K DRAM 12 C000-FFFF "
  395. label_dram16k14: dbz "16K DRAM 13 C000-FFFF "
  396. label_dram16k15: dbz "16K DRAM 14 C000-FFFF "
  397. label_dram16k16: dbz "16K DRAM 15 C000-FFFF "
  398. msg_banner: dbz "Monroe OC8820 TEST ROM -- FRANK IZ8DWF / DAVE KI3V / ADRIAN BLACK"
  399. msg_charset: dbz "-CHARACTER SET-"
  400. ; msg_testing: db " ", " "+$80, "t"+$80, "e"+$80, "s"+$80, "t"+$80, " "+$80, " ", 0
  401. msg_testing: dbz "..TEST.. "
  402. msg_128k: dbz "128K machine"
  403. msg_256k: dbz "256K machine"
  404. msg_testok: dbz "---OK--- "
  405. msg_biterrs: dbz "BIT ERRS "
  406. msg_ok7bit: dbz "OK! (7-BIT MODEL 1)"
  407. msg_ok8bit: dbz "OK! (8-BIT)"
  408. ; test parameter table. 2-byte entries:
  409. ; 1. size of test in bytes
  410. ; 2. starting address
  411. ; 3. address of string for announcing test
  412. ; 4. address of tones for identifying the test audibly
  413. tp_size equ 10
  414. memtest_ld_bc_size .macro
  415. ld c,(iy+0)
  416. ld b,(iy+1)
  417. .endm
  418. memtest_ld_hl_base .macro
  419. ld l,(iy+2)
  420. ld h,(iy+3)
  421. .endm
  422. memtest_loadregs .macro
  423. memtest_ld_bc_size
  424. memtest_ld_hl_base
  425. .endm
  426. spt_ld_iya6 .macro
  427. ld a,(iy+6)
  428. .endm
  429. spt_ld_iya7 .macro
  430. ld a,(iy+7)
  431. .endm
  432. tp_vram: dw VSIZE, VBASE, label_vram, tones_vram
  433. tp_16k: dw $4000, $C000, label_dram16k1, $a100,$31e0
  434. dw $4000, $C000, label_dram16k2, $c100,$3280
  435. dw $4000, $C000, label_dram16k3, $e100,$3320
  436. dw $4000, $C000, label_dram16k4, $0000,$33c0
  437. dw $4000, $C000, label_dram16k5, $2000,$3460
  438. dw $4000, $C000, label_dram16k6, $4020,$3500
  439. dw $4000, $C000, label_dram16k7, $6000,$35a0
  440. dw $4000, $C000, label_dram16k8, $8000,$3640
  441. dw $0000, tp_16k
  442. tp_16k_256: dw $4000, $C000, label_dram16k1, $a100,$31e0
  443. dw $4000, $C000, label_dram16k2, $c100,$3280
  444. dw $4000, $C000, label_dram16k3, $e100,$3320
  445. dw $4000, $C000, label_dram16k4, $0000,$33c0
  446. dw $4000, $C000, label_dram16k5, $2000,$3460
  447. dw $4000, $C000, label_dram16k6, $4000,$3500
  448. dw $4000, $C000, label_dram16k7, $6000,$35a0
  449. dw $4000, $C000, label_dram16k8, $8000,$3640
  450. dw $4000, $C000, label_dram16k9, $a000,$3230
  451. dw $4000, $C000, label_dram16k10, $c000,$32d0
  452. dw $4000, $C000, label_dram16k11, $e000,$3370
  453. dw $4000, $C000, label_dram16k12, $0100,$3410
  454. dw $4000, $C000, label_dram16k13, $2100,$34b0
  455. dw $4000, $C000, label_dram16k14, $4120,$3550
  456. dw $4000, $C000, label_dram16k15, $6100,$35f0
  457. dw $4000, $C000, label_dram16k16, $8100,$3690
  458. dw $0000, tp_16k
  459. set_regs_start:
  460. defb 0b5h ;005a io port CRT register select
  461. defb 004h ;005b count 4
  462. defb 0cfh ;005c
  463. defb 0b8h ;005d
  464. defb 037h ;005e
  465. defb 0efh ;005f
  466. ;
  467. defb 0b4h ;0060 io port PIO A data
  468. defb 001h ;0061 count 1
  469. defb 001h ;0062
  470. ;
  471. defb 0a1h ;0063 io port DART A command
  472. defb 006h ;0064 count 6
  473. defb 048h ;0065
  474. defb 048h ;0066
  475. defb 004h ;0067
  476. defb 044h ;0068
  477. defb 005h ;0069
  478. defb 0eah ;006a
  479. ;
  480. defb 0a3h ;006b io port DART B command
  481. defb 008h ;006c count 8
  482. defb 048h ;006d
  483. defb 048h ;006e
  484. defb 004h ;006f
  485. defb 044h ;0070
  486. defb 001h ;0071
  487. defb 000h ;0072
  488. defb 003h ;0073
  489. defb 0c1h ;0074
  490. ;
  491. defb 0a5h ;0075 io port SIO A command
  492. defb 002h ;0076 count 2
  493. defb 048h ;0077
  494. defb 048h ;0078
  495. ;
  496. defb 0a7h ;0079 io port SIO B command
  497. defb 002h ;007a count 2
  498. defb 048h ;007b
  499. defb 048h ;007c
  500. ;
  501. defb 0a8h ;007d io port CTC CHANNEL 0 - Communications baud rate
  502. defb 002h ;007e count 2
  503. defb 003h ;007f
  504. defb 003h ;0080
  505. ;
  506. defb 0a9h ;0081 io port CTC CHANNEL 1 - AUX RS-232C baud rate
  507. defb 002h ;0082 count 2
  508. defb 003h ;0083
  509. defb 003h ;0084
  510. ;
  511. defb 0aah ;0085 io port CTC CHANNEL 2 - Printer baud rate
  512. defb 002h ;0086 count 2
  513. defb 057h ;0087
  514. defb 04eh ;0088
  515. ;
  516. defb 000h ;0089 io port reset
  517. defb 000h ;008a count 0 terminator
  518. set_up_crt:
  519. ;data to be output to io port B9 14 byte CRT data register
  520. defb 069h ;054f
  521. defb 050h ;0550
  522. defb 056h ;0551
  523. defb 00bh ;0552
  524. defb 019h ;0553
  525. defb 003h ;0554
  526. defb 018h ;0555
  527. defb 018h ;0556
  528. defb 000h ;0557
  529. defb 00bh ;0558
  530. defb 020h ;0559
  531. defb 000h ;055a
  532. defb 000h ;055b
  533. defb 000h ;055c
  534. include "inc/spt.asm"
  535. include "inc/memtestmarch.asm"
  536. include "inc/monroecon.asm"
  537. include "inc/trs80music.asm"