OS7800.S 9.1 KB

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