monroeoc8800diag.asm 14 KB

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