monroeoc8800diag.asm 15 KB

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