DLTEST.S 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. *
  2. *
  3. *
  4. .subttl "Remnants of old Maria OS"
  5. *
  6. .include "maria.s"
  7. *
  8. ramcode equ $2300 ;AREA RESERVED FOR CODE
  9. tiaram equ $480
  10. *
  11. *
  12. ;
  13. ; STELLA (TIA) REGISTER ADDRESSES USED BY THIS MODULE
  14. ;
  15. VBLANK equ $01 ; BIT 1 VERTICAL BLANK SET-CLR
  16. TWSYNC equ $02 ; STROBE WAIT FOR HORIZ BLANK
  17. RSYNC equ $03 ; STROBE RESET HORIZ SYNC COUNTER
  18. COLUP0 equ $06 ; BITS 7654321 COLOR(4)-LUM(3) PLAYER 0
  19. COLUPF equ $08 ; BITS 7654321 COLOR(4)-LUM(3) PLAYFIELD
  20. COLUBK equ $09 ; BITS 7654321 COLOR(4)-LUM(3) BACKGROUND
  21. PF2 equ $0F ; BITS ALL PLAYFIELD REG BYTE 2
  22. RESP0 equ $10 ; STROBE RESET PLAYER 0
  23. RESP1 equ $11 ; STROBE RESET PLAYER 1
  24. GRP0 equ $1B ; BITS ALL GRAPHICS FOR PLAYER 0
  25. GRP1 equ $1C ; BITS ALL GRAPHICS FOR PLAYER 1
  26. CXCLR equ $2C ; STROBE CLEAR COLLISION LATCHES
  27. ;
  28. ; READ ADDRESSES - BIT 7 BIT 6 (ONLY)
  29. ;
  30. CXP0FB equ $32 ; P0.PF P0.BL
  31. CXP1FB equ $33 ; P1.PF P1.BL
  32. *
  33. .org $f000
  34. *
  35. fakedli equ $2700
  36. fakelist:
  37. .dc.b $0,$40,$f0,$1f,$bb
  38. .dc.b 0,0
  39. .dc.b $0f,$27,0
  40. *
  41. *
  42. *
  43. NMI:
  44. IRQ:
  45. rti
  46. *
  47. *
  48. startup:
  49. SEI ;INITIALIZE
  50. CLD
  51. *
  52. LDA #$07 ;PUT BASE UNIT INTO MARIA ENABLE
  53. STA PTCTRL
  54. *
  55. ldx #$ff
  56. txs
  57. *
  58. *
  59. LDA #$7F
  60. STA CTRL ;TURN OFF DMA
  61. LDA #$00
  62. STA BACKGRND ;BACKGROUND COLOR TO BLACK
  63. *
  64. *
  65. *
  66. * copy 2600 code to tia RAM
  67. *
  68. LDX #$7F ;LOCK CART IN 2600 MODE, CART ON
  69. L2LOOP:
  70. LDA SYNC,X ;MOVE CODE TO RAM
  71. STA tiaram,X ;MOVE INTO 6532 RAM
  72. DEX
  73. BPL L2LOOP
  74. *
  75. *
  76. * Copy 7800 validation code from rom to ram..
  77. *
  78. *
  79. ldx #ROMEND-ROMCODE
  80. copylp:
  81. lda ROMCODE-1,x
  82. sta ramcode-1,x
  83. dex
  84. bne copylp
  85. *
  86. * Now, zero out the TIA
  87. *
  88. lda #0 ;zero out the TIA
  89. tax
  90. tia0loop:
  91. sta VBLANK,x
  92. inx
  93. cpx #CXCLR
  94. bne tia0loop
  95. *
  96. LDA #$02 ;PUT BASE UNIT INTO MARIA ENABLE
  97. STA PTCTRL
  98. *
  99. *
  100. * 7800 One-on-One Basketball needs ram initialized to $ff (for shame!!!)
  101. * it also needs a fake display list initialized since it
  102. * turns on Maria before loading the display list pointer
  103. *
  104. .if 0
  105. basktptr equ $90
  106. *
  107. lda #0
  108. sta basktptr
  109. lda #$18
  110. sta basktptr+1
  111. *
  112. ldx #15
  113. ldy #0
  114. onelp:
  115. lda #$ff
  116. oneonlp:
  117. sta (basktptr),y
  118. dey
  119. bne oneonlp
  120. inc basktptr+1
  121. lda basktptr+1
  122. and #(%11011110)&255 ;check for $20 or $21
  123. bne .10
  124. lda #$ff
  125. sta (basktptr),y
  126. ldy #$3f
  127. bne oneonlp
  128. .10:
  129. dex
  130. bpl onelp
  131. *
  132. .endif
  133. *
  134. *
  135. ldx #9
  136. fakeload:
  137. lda fakelist,x
  138. sta fakedli,x
  139. dex
  140. bpl fakeload
  141. *
  142. inx ;x=0
  143. ldy #80
  144. fakeinc:
  145. lda fakedli+7,x
  146. sta fakedli+10,x
  147. inx
  148. dey
  149. bne fakeinc
  150. *
  151. jsr wait00
  152. *
  153. *
  154. lda #$27
  155. sta DPPH
  156. lda #07
  157. sta DPPL
  158. lda #$43
  159. sta CTRL
  160. * sta NMICTRL
  161. *
  162. *
  163. ldx #$7f
  164. frame4:
  165. jsr wait00
  166. dex
  167. bpl frame4
  168. lda #$60
  169. sta CTRL
  170. *
  171. brk
  172. *
  173. wait00:
  174. bit MSTAT
  175. bmi wait00
  176. wait01:
  177. bit MSTAT
  178. bpl wait01
  179. rts
  180. *
  181. * the following code is copied to ram for execution
  182. *
  183. ROMCODE:
  184. NOCART:
  185. lda #2
  186. sta PTCTRL ;turn "security" ROM on
  187. JMP startup ;NO CART, do asteroids
  188. *
  189. CARTTEST:
  190. LDA #$16 ;TURN EXTERNAL CART ON
  191. STA PTCTRL
  192. LDY #$FF
  193. LDX #$7F ;SEE IF A CART PLUGGED IN
  194. CTSTLOOP:
  195. LDA $FE00,X
  196. CMP $FD80,Y
  197. BNE NOCART
  198. DEY
  199. DEX
  200. BPL CTSTLOOP ;X LEFT = FF, Y LEFT = 7F
  201. *
  202. LDA $FFFC ;SEE IF START AT FFFF
  203. AND $FFFD
  204. CMP #$FF
  205. BEQ NOCART ;ALL LINES DRAWN HIGH, NO CART
  206. LDA $FFFC ;SEE IF START AT 0000
  207. ORA $FFFD
  208. BEQ NOCART ;ALL LINES DRAWN LOW, NO CART
  209. *
  210. LDA $FFF8 ;CHECK FOR REGION VERIFICATION
  211. ORA #$fe
  212. CMP #$FF
  213. BNE CART26
  214. LDA $FFF8 ;TOP 4 BITS OF FFF8 SHOULD BE 0F0
  215. EOR #$F0
  216. AND #$F0
  217. BNE CART26
  218. LDA $FFF9 ;SEE IF MARIA SIGNATURE EXISTS
  219. AND #$0B ;0X7 OR 0X3 VALID
  220. CMP #$03
  221. BNE CART26
  222. LDA $FFF9 ;GET BOTTOM OF CART ADDRESS
  223. AND #$F0
  224. cmp #$40 ;not too low
  225. bcc CART26
  226. sbc #1
  227. cmp $fffd
  228. bcs CART26
  229. *
  230. lda $1BEA ;2600 ROM responds to this address
  231. eor #$FF
  232. sta $1BEA ;stuff some data in MARIA ram space
  233. tay
  234. *
  235. ldx #5 ;check hardware vectors
  236. vecheck:
  237. lda $FFFA,x ; 2600 should always
  238. cmp $DFFA,x ; read the same data
  239. bne SETMARIA ; in DXXX as in FXXX
  240. dex
  241. bpl vecheck
  242. *
  243. * Some 7800 carts get here...
  244. *
  245. cpy $1BEA ;does this act like 7800 ram or 2600 ROM?
  246. bne CART26
  247. * jmp CART26 ;1 chance in 2**48 it's still a 7800 cart
  248. *
  249. * We favor 7800 more than before so 2600 might get run in 7800 mode
  250. * ...may need to do more 2600/7800 discrimination here...
  251. *
  252. *
  253. * we must be 7800 cart; go to it...
  254. *
  255. SETMARIA:
  256. LDX #$16 ;PUT CART IN 7800 MODE, CART ON
  257. STX PTCTRL
  258. TXS
  259. SED
  260. JMP ($FFFC) ;VECTOR INTO THE CART IN 3600 MODE
  261. *
  262. * tests indicate we must be a 2600 cart...
  263. *
  264. CART26:
  265. LDA #$02
  266. STA PTCTRL ;TURN SECURITY ROM ON
  267. jmp tiaram ;perform this from tia ram
  268. *
  269. ROMEND:
  270. *
  271. *
  272. ; First zero out TIA without doing a TWSYNC. This must be done in a loop that
  273. ; counts up so that graphics are turned off before the collision registers are
  274. ; cleared. RSYNC should turn case C into a case A. Note also that the stores
  275. ; of zero puts the system in TIA space but does not lock it there. This code
  276. ; must all run out of 6532 RAM since the memory map will change as we change
  277. ; mode. The 6532 RAM exists in all memory maps.
  278. *
  279. SYNC:
  280. LDA #0
  281. TAX
  282. STA VBLANK
  283. ZEROLP:
  284. STA RSYNC,X
  285. INX
  286. CPX #(CXCLR-RSYNC+1)
  287. BNE ZEROLP
  288. ; Test now for a possible E case. In some E cases, TWSYNCs do not work properly
  289. ; and this must be detected. In an E case failure, the LDA is prefetched and
  290. ; the 04 following it is skipped over and NOP ($EA) is loaded into A causing
  291. ; the branch on minus to be taken. If this happens the E case can now be
  292. ; corrected. NOTE: All E cases do not get trapped here and must be handled
  293. ; latter by collisions.
  294. STA TWSYNC
  295. LDA #4
  296. NOP
  297. BMI ECASE
  298. ; Position player 0 on the left side of the screen and player 1 on the right
  299. ; side of the screen so that they will overlap (or not overlap as the case may
  300. ; be) playfield 2 that has a copy on both sides of the screen. Resets occur at
  301. ; the 38th and 65th cycle.
  302. LDX #4
  303. STALL4:
  304. DEX ;Stall loop
  305. BPL STALL4
  306. TXS ;Set the stack to 0FF for stall JSRs
  307. STA RESP0+$100 ;38th cylce
  308. JSR DUMMY+1-SYNC+$480 ;12 cycle stall
  309. JSR DUMMY+1-SYNC+$480 ;Ditto
  310. STA RESP1 ;65th cycle
  311. ; Turn on graphics to cause the collisions
  312. STA GRP0 ;68th cycle
  313. STA GRP1 ;71st cycle
  314. STA PF2 ;74th cycle
  315. ; Stall an entire scan line to allow collisions to take place. The E case test
  316. ; should follow all TWSYNCs to be safe.
  317. NOP ;76th cycle
  318. STA TWSYNC ;3rd cycle
  319. LDA #0
  320. NOP
  321. BMI ECASE
  322. ; Test now for a collision between player 1 and playfield. If there is no
  323. ; collision, we must shift the clock once. If there is a collision, we must
  324. ; do further testing.
  325. BIT CXP1FB-$30
  326. BMI NOCOL2
  327. ; This section shifts the clock once. Storing a 2 switches the system into
  328. ; MARIA MODe and the following store to 0FXXX causes a clock speed-up for one
  329. ; cycle and thus shifts the clock once.
  330. ECASE:
  331. LDA #2
  332. STA COLUBK ;changes to MARIA MODe
  333. STA $F112
  334. BNE DONE ;JMP
  335. ; Test now for a collision between player 0 and playfield. If there is no
  336. ; collision, we must shift the clock twice. If there is a collision, we must
  337. ; do further testing.
  338. NOCOL2:
  339. BIT CXP0FB-$30
  340. BMI NOCOL0
  341. ; This section shifts the clock twice. Storing a 2 switches the system into
  342. ; MARIA MODe and the following stores to 0FXXX causes two clock speed-ups for
  343. ; one cycle and thus shifts the clock twice.
  344. LDA #2
  345. STA COLUP0 ;changes to MARIA MODe
  346. STA $F118
  347. DUMMY:
  348. STA $F460 ;Note that the 060 is a RTS
  349. BNE DONE
  350. ; If we've fotten to this point the only possible failure left is an E case that
  351. ; was not detected by the TWSYNC trap. Test for this by clearing the collision
  352. ; registers, shifting the graphics for player 0 to the left one pixel by
  353. ; changing GRP0 from a 4 to an 8, and then retesting for a collision. If there
  354. ; is still a collision between player 0 and the playfield, we have an E case,
  355. ; otherwise we are done. Be careful not to test for collisions until after they
  356. ; occur (about the 40th cycle).
  357. NOCOL0:
  358. STA CXCLR ;21st cycle
  359. LDA #8 ;23rd cycle - one pixel to the left
  360. STA GRP0 ;26th cycle
  361. JSR DUMMY+1-SYNC+$480 ;12 cycle stall
  362. NOP ;40th cycle - just to be safe
  363. BIT CXP0FB-$30 ;43rd cycle
  364. BMI ECASE
  365. ; We are now synced and should lock ourselves into TIA mopde with the external
  366. ; cart enabled and jump to the reset vector. Thanks for stopping by...
  367. DONE:
  368. LDA #$FD
  369. STA COLUPF ;Change MODes to TIA with EXT and lock.
  370. JMP ($FFFC)
  371. NROM:
  372. *
  373. * some necessary code from HISCORE.S module that was omitted...
  374. *
  375. HSCSUCK:
  376. * JSR ZEROHS
  377. *
  378. HSCDOENT:
  379. *
  380. * HSCSETDM -- SET DIFF/MODE LEVEL ARGUMENT BASED ON DIFF AND MODE
  381. *
  382. HSCSETDM:
  383. * LDA MODE ;COMPUTE DIFF/MODE LEVEL VALUE BYTE
  384. BPL ZHSCMOK
  385. LDA #0
  386. ZHSCMOK:
  387. ASL
  388. ASL
  389. CLC
  390. * ADC DIFF
  391. * STA TEMP ;SAVE IT WHERE WE CAN INSERT LATER
  392. HSCSHOW:
  393. LDA #1
  394. HSCRET:
  395. RTS
  396. *
  397. *
  398. HSCTAB:
  399. .dc.b $20,$20,$20,$20,$20,$20,$20,$20,$20,$20
  400. .dc.b $4F,$68,$21,$20,$57,$68,$61,$74,$20,$61
  401. .dc.b $20,$66,$69,$6E,$65,$20,$62,$6F,$79,$20
  402. .dc.b $69,$73,$20,$44,$61,$76,$65,$20,$53,$74
  403. .dc.b $61,$75,$67,$61,$73,$2E
  404. .dc.b $20,$20,$20,$20,$20,$20,$20,$20,$20,$20
  405. *
  406. CODEDIF equ ROMCODE-ramcode ;DIFFERENCE BETWEEN OLD AND NEW ADDRESS
  407. *
  408. .org $FFFA
  409. .dc.w NMI
  410. .dc.w startup
  411. .dc.w IRQ