Advertisement
Guest User

Untitled

a guest
Sep 3rd, 2019
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 26.74 KB | None | 0 0
  1. .enum $0000 ;;start variables at ram location 0
  2. spritenumber .dsb 1
  3. newbuttons .dsb 1
  4. oldbuttons .dsb 1
  5. justpressed .dsb 1
  6. tempval .dsb 1
  7. gamestate .dsb 1
  8. titlespritesloadcheck .dsb 1
  9. cursorx .dsb 1
  10. cursory .dsb 1
  11. piclo .dsb 1
  12. pichi .dsb 1
  13. spriteclearcounter .dsb 1
  14. textstring .dsb 32
  15. stringlocation .dsb 1
  16. lobyte .dsb 1
  17. hibyte .dsb 1
  18. screennumber .dsb 1
  19. oldscreen .dsb 1
  20. loopgap .dsb 1
  21. looplength .dsb 1
  22. spritedir .dsb 1
  23. spritedirpointer .dsb 2
  24.  
  25. ;variables for scrollnes routine
  26. scroll_h .dsb 1
  27. scroll_v .dsb 1
  28. sspeed .dsb 1
  29. offset_counter .dsb 1
  30. char_counter .dsb 1
  31. char_address .dsb 1 ; Points to beginning of desired character memory
  32. write_width .dsb 1
  33. size_toggle .dsb 1 ; 8x8 or 16x8
  34. char_val .dsb 1 ; tile 0,1,2,3
  35. size .dsb 1
  36. char .dsb 1
  37. speed_toggle .dsb 1
  38. currentvirtpos .dsb 1
  39. framenumber .dsb 1
  40. virtcounter .dsb 1
  41. virtnumber .dsb 1
  42. ppumask .dsb 1
  43. textstringcounter .dsb 1
  44. prescrollcleanup .dsb 1
  45. clearflag .dsb 1
  46. scrollspritesloadcheck .dsb 1
  47. spriteanimationcounter .dsb 1
  48. spriteanimationnumber .dsb 1
  49.  
  50. .ende
  51.  
  52. spriteram = $0200
  53. statetitle = $0
  54. stateplay = $1
  55. leftwall = $00
  56. rightwall = $f0
  57. topwall = $7f
  58. bottomwall = $cf
  59.  
  60. ; ----------------------------------------------------
  61.  
  62. .ORG $7ff0
  63. Header: ; 16 byte .NES header (iNES format)
  64. .DB "NES", $1a
  65. .DB $02 ; size of PRG ROM in 16kb units
  66. .DB $01 ; size of CHR ROM in 8kb units
  67. .DB #%00000000 ; mapper 0
  68. .DB #%00000000 ; mapper 0
  69. .DB $00
  70. .DB $00
  71. .DB $00
  72. .DB $00
  73. .DB $00
  74. .DB $00
  75. .DB $00
  76. .DB $00
  77.  
  78. .ORG $8000
  79.  
  80. ;----reset routine----
  81. Reset: ; reset routine
  82. sei ; disable IRQs
  83. cld ; disable decimal mode
  84. ldx #$40
  85. stx $4017 ; disable APU frame IRQ
  86. ldx #$FF
  87. txs ; Set up stack
  88. inx ; now X = 0
  89. stx $2000 ; disable NMI
  90. stx $2001 ; disable rendering
  91. stx $4010 ; disable DMC IRQs
  92.  
  93. clrmem: ; As it says, clears the RAM
  94. lda #$00
  95. sta $0000, x
  96. sta $0100, x
  97. sta $0300, x
  98. sta $0400, x
  99. sta $0500, x
  100. sta $0600, x
  101. sta $0700, x
  102. lda #$FE ; Sprite RAM needs $FE so that all sprites are off screen until set
  103. sta $0200, x
  104. inx
  105. bne clrmem
  106.  
  107. ldx #$00
  108. ldy #$10
  109. ClearPPU sta $2007
  110. dex
  111. bne ClearPPU
  112. dey
  113. bne ClearPPU
  114.  
  115. lda #$00
  116. sta $2003
  117. tay
  118. ClearSpr sta $2004
  119. dey
  120. bne ClearSpr
  121.  
  122. ;----setting up variables----
  123. lda #$00
  124. sta spriteclearcounter
  125. sta titlespritesloadcheck
  126. sta stringlocation
  127. sta textstring
  128. STA scroll_h
  129. STA scroll_v
  130. STA offset_counter
  131. STA char_counter
  132. STA write_width
  133. STA char
  134. STA size_toggle
  135. STA size
  136. STA currentvirtpos
  137. sta framenumber
  138. sta clearflag
  139. sta prescrollcleanup
  140. sta oldscreen
  141. sta tempval
  142. sta screennumber
  143. sta scrollspritesloadcheck
  144. sta spritedir
  145. sta spritenumber
  146. STA textstringcounter
  147.  
  148. lda #01
  149. STA sspeed
  150. STA speed_toggle
  151.  
  152. lda #1
  153. sta virtcounter
  154. sta virtnumber
  155.  
  156. lda #10 ;higher/lower number = longer / shorter gap before text loop
  157. sta loopgap
  158.  
  159. LDA #$30 ;higher/lower number = faster/slower animation
  160. STA spriteanimationcounter
  161. STA spriteanimationnumber
  162.  
  163. lda #$00
  164. sta cursorx
  165. lda #$7f
  166. sta cursory
  167.  
  168. lda #$f0
  169. STA char_val
  170.  
  171. lda #$20
  172. sta lobyte
  173.  
  174. lda #$e0
  175. sta hibyte
  176.  
  177. lda #statetitle
  178. sta gamestate
  179.  
  180. ;----warm up----
  181. ldx #$02
  182. WarmUp:
  183. BIT $2002
  184. BPL WarmUp
  185. DEX
  186. bne WarmUp
  187.  
  188. lda #$3F
  189. sta $2006
  190. lda #$00
  191. sta $2006
  192. TAX
  193. LoadPal: ;
  194. lda palette, x
  195. sta $2007
  196. INX
  197. CPX #$20
  198. bne LoadPal
  199.  
  200. lda #$20
  201. sta $2006
  202. lda #$00
  203. sta $2006
  204.  
  205. ; jsr clearnametable
  206.  
  207. ;----Pre Vblank----
  208.  
  209. ;----load title screen----
  210. lda #<titlescreen ; load low byte of
  211. sta piclo ; store it in the piclo variable
  212. lda #>titlescreen ; load high byte of first picture
  213. sta pichi ; store it in the pichi variable
  214.  
  215. jsr drawscreen ; draw the screen we just loaded
  216.  
  217. ;----move all 64 sprites off screen----
  218. jsr movespritesoffscreen ; move all the sprites off screen
  219. jsr vblank ; turn on screen
  220.  
  221. ;----infinite loop: program now controlled by NMI routine----
  222. infloop:
  223. jmp infloop
  224.  
  225.  
  226. jsr scroll ; jump to scroll sub routine
  227.  
  228. scrolldone:
  229.  
  230. ;----NMI----
  231. NMI:
  232. jsr controllertest ; check for user input
  233.  
  234. gameengine:
  235. lda gamestate ; load the current game state
  236. cmp #statetitle ; check and see if it is the title state
  237. beq enginestatetitle ; if so jump to the title engine state
  238.  
  239. lda gamestate ; if not load the current game state
  240. cmp #stateplay ; check and see if it is the play state
  241. beq enginestateplay ; if so jump to the play engine state
  242. gameenginedone:
  243.  
  244. RTI
  245. IRQ:
  246. RTI
  247.  
  248. ;----------------------------------------------------
  249. controllertest: ;button ( 0 0 0 0 0 0 0 0 )
  250. lda newbuttons ;layout ( R L D U St Sl B A )
  251. sta oldbuttons
  252.  
  253. ldx #$00
  254. lda #$01 ; strobe joypad
  255. sta $4016
  256. lda #$00
  257. sta $4016
  258. ConLoop:
  259. lda $4016 ; check the state of each button
  260. LSR
  261. ROR newbuttons
  262. INX
  263. CPX #$08
  264. bne ConLoop
  265.  
  266. lda oldbuttons ; invert bits
  267. EOR #$FF
  268. and newbuttons
  269. sta justpressed
  270. rts
  271.  
  272. ;----gameengine----
  273. enginestatetitle:
  274. lda titlespritesloadcheck ; check to see if we need to load the title screen sprites
  275. bne skiptitlespriteload ; if we have, skip loading them again
  276. jsr loadtitlesprites ; jump to the load title sprites routine
  277.  
  278. skiptitlespriteload:
  279. jsr titlecontrols ; read the controls for the title states
  280. jsr updatecursorsprite ; update the cursor sprite
  281. jsr updatesprites ; transfer the sprites to ram
  282.  
  283. lda #00 ; load #00 to A
  284. sta $2005 ; write twice to $2005
  285. sta $2005 ; to confirm no scrolling in this state.
  286.  
  287. jmp gameenginedone ; game engine complete for this frame
  288.  
  289. enginestateplay:
  290. lda prescrollcleanup ; load pre scroll cleanup flag
  291. cmp #01 ; check if we have cleaned up the screen the frame before starting the scroll routine
  292. beq skipprescrollcleanup ; skip cleanup if we have done it already
  293.  
  294. jsr movespritesoffscreen ; move all the sprites of screen
  295. jsr loadblankscreen ; load a blank screen or our title screen will scroll which would suck.
  296. jsr drawscreen ; draw the blank screen
  297. jsr vblank ; vblank
  298. lda #01 ; set the pre scroll clean up flag
  299. sta prescrollcleanup ; store it so we skip this next time.
  300. skipprescrollcleanup:
  301.  
  302. jsr playcontrols ; load the play state controls
  303. JSR virtscroll ; update vertical scrolling (sin up / down)
  304. JSR horizscroll
  305. lda #%10001100
  306. sta $2000
  307. lda scrollspritesloadcheck ; check if we have loaded the play state sprites
  308. cmp #01
  309. beq skipscrollspriteload ; if we have, skip loading them
  310.  
  311. jsr loadscrollsprites ; load playstate sprites
  312.  
  313.  
  314. skipscrollspriteload:
  315. jsr animatesprites ; check if we need to animate sprites thie frame
  316. jsr changesprites ; if so, change them
  317. jsr spritemovecheck ; check if we need to move sprites this frame
  318. jsr updatesprites ; write sprites to ram
  319.  
  320. jmp gameenginedone ; game engine complete.
  321.  
  322. ;----sub routines----------------------------------------------------------------------------------
  323. ;--------------------------------------------------------------------------------------------------
  324.  
  325. vblank:
  326. BIT $2002 ; vblank
  327. BPL vblank
  328. lda #%10000100
  329. sta $2000
  330. lda #%00011110
  331. sta $2001
  332. sta ppumask
  333. rts
  334.  
  335.  
  336.  
  337. loadtitlesprites:
  338. lda cursory ; load cursor y position
  339. sta $0200 ; store it in y pos for sprite 1
  340. lda #tempval ; load tempval
  341. sta $0201 ; store in tile pos for sprite 1
  342. lda #$00 ; load attribute $00
  343. sta $0202 ; store in attribute pos for sprite 1
  344. lda cursorx ; load cursor x position
  345. sta $0203 ; store in x pos for sprite 1
  346.  
  347. lda #01 ; load #01 to a
  348. sta titlespritesloadcheck ; store in loadcheck flag so we only do this once
  349. rts
  350.  
  351. updatecursorsprite:
  352. lda tempval ; load current tempval
  353. sta $0201 ; store in tile pos for sprite 1
  354. rts
  355.  
  356. titlecontrols:
  357. checkup:
  358. lda #%00010000 ; check if up was pressed
  359. and justpressed
  360. beq checkdown ; if not skip this button and check down
  361.  
  362. lda cursory ; load cursory position
  363. cmp #topwall ; compare to #topwall (the top row of letters)
  364. beq checkdown ; if = skip this button and check down
  365.  
  366. lda spriteram ; load value in spriteram 0
  367. sec ; set the carry flag
  368. sbc #$10 ; subtract $10
  369. sta spriteram ; store in spriteram 0
  370. sta cursory ; and cursory position
  371.  
  372. lda tempval ; load tempval
  373. sec ; set the carry flag
  374. sbc #$10 ; subtract $10
  375. sta tempval ; store in tempval
  376.  
  377. checkdown:
  378. lda #%00100000 ; check down/left/right follow the same pattern
  379. and justpressed
  380. beq checkleft
  381.  
  382. lda cursory
  383. cmp #bottomwall
  384. beq checkleft
  385.  
  386. lda spriteram
  387. clc
  388. adc #$10
  389. sta spriteram
  390. sta cursory
  391.  
  392. lda tempval
  393. CLC
  394. adc #$10
  395. sta tempval
  396.  
  397. checkleft:
  398. lda #%01000000
  399. and justpressed
  400. beq checkright
  401.  
  402. lda cursorx
  403. cmp #leftwall
  404. beq checkright
  405.  
  406. lda spriteram+3
  407. sec
  408. sbc #$10
  409. sta spriteram+3
  410. sta cursorx
  411.  
  412. lda tempval
  413. sec
  414. sbc #$01
  415. sta tempval
  416.  
  417. checkright:
  418. lda #%10000000
  419. and justpressed
  420. beq checkselect
  421.  
  422. lda cursorx
  423. cmp #rightwall
  424. beq checkselect
  425.  
  426. lda spriteram+3
  427. clc
  428. adc #$10
  429. sta spriteram+3
  430. sta cursorx
  431.  
  432. lda tempval
  433. CLC
  434. adc #$01
  435. sta tempval
  436.  
  437. checkselect: ; this button doesn't do anything
  438. lda #%00000100
  439. and justpressed
  440. beq checkstart
  441.  
  442. checkstart:
  443. lda #%00001000 ; check if start was pressed
  444. and justpressed
  445. beq checkb ; if not skip this button and check b
  446. lda #stateplay ; load #stateplay
  447. sta gamestate ; store in gamestate (tell engine start scrolling)
  448. lda #01 ; load #01
  449. sta screennumber ; store in screen number to start scrolling with blank screen in the background rather than the title screen
  450. lda stringlocation ; load the current stringlocation ("test" is 4 letters for stringlocation is 4
  451. adc loopgap ; add the string location to the loop gap (if stringlocation is 4 and loopgap is 3 we have 7)
  452. sta looplength ; store the total in looplength
  453.  
  454. checkb:
  455. lda #%00000010 ; check is b was pressed
  456. and justpressed
  457. beq checka ; if not skip this button and check a
  458.  
  459. lda stringlocation ; load the current string location
  460. cmp #$20 ; compare it to #$20 (32 letters=full string)
  461. beq checka ; if = skip this button and check a
  462.  
  463. lda stringlocation ; load the current string location
  464. cmp #$10 ; compare to $10 (the first row of letters is 16 letters long, if we are on string location $10 we need to move to the next row of letters)
  465. bne skipline2increment ; if not $10 yet, don't move to 2nd line
  466. lda #$21 ; if $10 load $21
  467. sta lobyte ; store it in the lobyte screen location
  468. lda #$20 ; then load $20
  469. sta hibyte ; store it in the hibyte screen location, this starts entering text back at the beginning of the first line.
  470.  
  471. skipline2increment
  472. lda lobyte ; load the current lobyte
  473. sta $2006 ; write it to $2006
  474. lda hibyte ; load the current hibyte
  475. sta $2006 ; store it to $2006
  476. lda tempval ; load tempval (if tempval = $00 display a space)
  477. sta $2007 ; store it in $2007
  478. ldx stringlocation ; load to x the current stringlocation
  479. sta textstring,x ; store tempval in textstring at location X, for example if we want to write "test" and the cursor is on lower case "t" tempval will be $54. If this is the first character we enter, stringlocation will be $00 so we store it in location $00 of textext string
  480. inc stringlocation ; stringlocation +1, next time we run this routine we will load the next string location
  481. inc hibyte ; increment the hibyte
  482. inc hibyte ; do it again to display the next character 2 spaces to the right.
  483.  
  484. checka: ; delete one character
  485. lda #%00000001
  486. and justpressed ; check if A was pressed
  487. beq titlecontrolsdone ; if not, handling A is done
  488.  
  489. lda stringlocation ; load string location
  490. cmp #$00 ; check is the string is at #$00 (empty string = nothing to delete)
  491. beq titlecontrolsdone ; if string = #$00 handling A is done
  492.  
  493. lda stringlocation ; load string location
  494. cmp #$10 ; check if it is #$10 (16th character) if it is, we need to move to the top line of characters on the title screeen.
  495. bne skipline2decrement ; if not #$11 skip code to move to top line
  496. lda #$20 ; load #$20 (top "slice" of the background)
  497. sta lobyte ; store it in the lobyte
  498. lda #$fe ; load #$fe (far right top line space)
  499. sta hibyte ; store it in the hibyte
  500. jmp skipdecrement ; we hardwrote the location for the far right of the top line so we don't need to decrement the hibyte in this case
  501.  
  502. skipline2decrement
  503. dec hibyte ; subtract 1 from the high byte
  504. dec hibyte ; subtract 1 from the high byte
  505. skipdecrement
  506. lda lobyte
  507. sta $2006
  508. lda hibyte
  509. sta $2006
  510. lda $00 ; load tile $00 (blank tile)
  511. sta $2007
  512. dec stringlocation ; subtract 1 from the string location
  513. ldx stringlocation ; load the string location into x
  514. sta textstring,x
  515.  
  516.  
  517. titlecontrolsdone:
  518. rts
  519.  
  520. ;----play state controls----
  521. playcontrols:
  522.  
  523. heldchecks:
  524. LDA #%00000010 ;check if b is held
  525. AND newbuttons
  526. BEQ aheld
  527.  
  528. LDA #%00000001 ;check if a is held
  529. AND newbuttons
  530. BEQ bheld
  531.  
  532. JSR baheldchecks ;check if a and b are held
  533. JMP checksdone
  534.  
  535. bheld:
  536. JSR bheldchecks
  537. JMP checksdone
  538.  
  539. aheld:
  540. LDA #%00000001 ;check if a is held
  541. AND newbuttons
  542. BEQ nothingheld
  543. JSR aheldchecks
  544. JMP checksdone
  545.  
  546. nothingheld:
  547. JSR nothingheldchecks
  548. JMP checksdone
  549.  
  550. checksdone:
  551. rts
  552.  
  553. baheldchecks
  554. rts
  555.  
  556. bheldchecks
  557. rts
  558.  
  559.  
  560. nothingheldchecks:
  561. playcheckup:
  562. lda #%00010000
  563. and justpressed
  564. beq playcheckdown
  565. LDA #1
  566. STA size_toggle
  567.  
  568. playcheckdown:
  569. lda #%00100000
  570. and justpressed
  571. beq playcheckleft
  572. LDA #0
  573. STA size_toggle
  574.  
  575. playcheckleft:
  576. lda #%01000000
  577. and justpressed
  578. beq playcheckright
  579. lda #01
  580. sta speed_toggle
  581.  
  582. playcheckright:
  583. lda #%10000000
  584. and justpressed
  585. beq playcheckselect
  586. lda #00
  587. sta speed_toggle
  588.  
  589. playcheckselect:
  590. lda #%00000100
  591. and justpressed
  592. beq playcheckstart
  593. INC char_val
  594. INC char_val
  595. LDA char_val
  596. cmp #$Fe
  597. BNE playcheckstart
  598. LDA #$f0
  599. STA char_val
  600.  
  601. playcheckstart:
  602. lda #%00001000
  603. and justpressed
  604. beq playchecksdone
  605.  
  606. LDA #%00001000 ;toggle sprites on/off
  607. eor ppumask
  608. STA $2001
  609. sta ppumask
  610.  
  611.  
  612. playchecksdone:
  613. rts
  614.  
  615. aheldchecks:
  616. aplaycheckup:
  617. lda #%00010000
  618. and justpressed
  619. beq aplaycheckdown
  620. LDA #0
  621. STA spritedir
  622.  
  623. aplaycheckdown:
  624. lda #%00100000
  625. and justpressed
  626. beq aplaycheckleft
  627. LDA #1
  628. STA spritedir
  629.  
  630. aplaycheckleft:
  631. lda #%01000000
  632. and justpressed
  633. beq aplaycheckright
  634. lda #2
  635. sta spritedir
  636.  
  637. aplaycheckright:
  638. lda #%10000000
  639. and justpressed
  640. beq aplaycheckselect
  641. lda #3
  642. sta spritedir
  643.  
  644. aplaycheckselect:
  645. lda #%00000100
  646. and justpressed
  647. beq aplaycheckstart
  648.  
  649. ldx #0 ; this code can be used to move
  650. - ; sprites to fore / back ground
  651. lda #%00100000
  652. eor spriteram+2,x
  653. sta $202,x
  654. sta spriteram+2,x
  655. inx
  656. inx
  657. inx
  658. inx
  659. bne -
  660.  
  661.  
  662.  
  663. aplaycheckstart:
  664. lda #%000001000
  665. and justpressed
  666. beq aplaychecksdone
  667.  
  668. LDA #%00010000 ;toggle sprites on/off
  669. eor ppumask
  670. STA $2001
  671. sta ppumask
  672.  
  673.  
  674. aplaychecksdone
  675. rts
  676.  
  677. scroll:
  678.  
  679. Vblank: ; turn on the screen
  680. BIT $2002
  681. BPL Vblank
  682.  
  683. LDX scroll_h
  684. STX $2005
  685. LDX scroll_v
  686. STX $2005
  687.  
  688. LDA #%1001100
  689. STA $2000
  690.  
  691. LDA #%00011110
  692. STA $2001
  693. STA ppumask
  694.  
  695. RTS
  696.  
  697. ; ----------------------------------------------------
  698. ; a huge section of the drawloop routine is directly from scrollnes.
  699. DrawLoop: ;** CALCULATE CHARACTER ADDRESS
  700.  
  701. LDX size_toggle ; Change size, speed and character set after string loops
  702. STX size
  703. LDX char_val
  704. STX char
  705. LDX speed_toggle
  706. STX sspeed
  707.  
  708.  
  709. LDX textstringcounter
  710. ; Determine high address
  711. LDA textstring,x ; or whatever your text string is
  712. LSR ; Divide by 4 (Shift right 2 times)
  713. LSR
  714. CLC
  715. ADC #$C0 ; Add #$c0 to result to start at bank $c000 where the bin file is
  716. STA char_address+1
  717.  
  718. ;Determine low address
  719. LDA textstring,x ; or whatever your text string is
  720. ASL ; Multiply by 64 (Shift left 6 times)
  721. ASL
  722. ASL
  723. ASL
  724. ASL
  725. ASL
  726. STA char_address+0
  727.  
  728. LDA textstringcounter
  729. CMP looplength
  730. BNE noreset
  731. LDA #$00
  732. STA textstringcounter
  733. noreset:
  734.  
  735.  
  736. ; Final result $C000 -> $C040 -> $C080 -> $C0C0 -> $C100 AND so on
  737.  
  738. ; ----------------------------------------------------
  739.  
  740. LDX offset_counter
  741. LDY offset_table,x
  742.  
  743. LDA #$20
  744. STA $2006
  745. STY $2006
  746.  
  747. LDX #8
  748. ReadChar:
  749. LDY char_counter
  750. LDA (char_address),y ; Use post-address indexing to use full memory address
  751.  
  752. CLC
  753. ADC char
  754. STA $2007
  755. TAY
  756.  
  757. LDA size ; Check status of size variable to decide if there should be an extra write
  758. BEQ small
  759. STY $2007
  760. small:
  761. INC char_counter
  762. DEX
  763. BNE ReadChar
  764.  
  765. LDA char_counter ; Do not exceed 64 (8x8->length of character)
  766. AND #$3f
  767. STA char_counter
  768. BNE SkipInc ; While we're here, Increment the string position if the result is zero
  769.  
  770.  
  771. inc textstringcounter
  772. SkipInc:
  773. RTS
  774.  
  775. ; ----------------------------------------------------
  776.  
  777. EraseInit:
  778. INC offset_counter
  779. LDA offset_counter
  780. CMP #32
  781. BNE EraseColumn
  782. LDA #0
  783. STA offset_counter
  784.  
  785. EraseColumn:
  786. LDX offset_counter
  787. LDY offset_table,x ; Use offset table to calculate screen position
  788.  
  789. LDA #$20
  790. STA $2006
  791. STY $2006
  792.  
  793. LDX #16
  794. EraseLoop:
  795. LDA #$00 ; Write blank tile (erase)
  796. STA $2007
  797. DEX ; 16x to cover height of character
  798. BNE EraseLoop
  799.  
  800. RTS
  801.  
  802.  
  803. virtscroll:
  804. DEC virtcounter
  805. BNE novirt
  806. LDX framenumber
  807. LDA virtpos,x
  808. STA scroll_v
  809. inc framenumber
  810. LDA framenumber
  811. cmp #$80
  812. BNE noresetframe
  813. LDA #$00
  814. STA framenumber
  815. noresetframe
  816. LDA virtnumber
  817. STA virtcounter
  818.  
  819. novirt:
  820. RTS
  821.  
  822. horizscroll:
  823. INC scroll_h ; Update scroll counters
  824. INC scroll_h
  825.  
  826. LDA sspeed
  827. BEQ SlowScroll
  828. INC scroll_h
  829. INC scroll_h
  830.  
  831. SlowScroll:
  832. LDA scroll_h
  833. AND #$07
  834. BNE KeepGoing
  835.  
  836. JSR DrawLoop
  837. JSR EraseInit
  838.  
  839. KeepGoing:
  840. LDX scroll_h ; Update scroll registers
  841. STX $2005
  842. LDX scroll_v
  843. STX $2005
  844. RTS
  845.  
  846. clearnametable:
  847. LDY #$04 ; clear nametables
  848. clearname:
  849. ldx #$00
  850. lda #$00
  851. ppuloop:
  852. sta $2007
  853. DEX
  854. bne ppuloop
  855.  
  856. DEY
  857. bne clearname
  858. rts
  859.  
  860.  
  861. ;----movesprites off screen----
  862. movespritesoffscreen:
  863. lda #$ff
  864. ldx #$00
  865. -
  866. sta spriteram,x ;copy to RAM
  867. inx
  868. bne -
  869. rts
  870.  
  871. drawscreen:
  872. lda #$20 ; set to beginning of first nametable
  873. sta $2006
  874. lda #$00
  875. sta $2006
  876. LDY #$00
  877. ldx #$04
  878.  
  879. nameloop: ;loop to draw entire nametable
  880. lda (piclo),y
  881. sta $2007
  882. INY
  883. bne nameloop
  884. inc pichi
  885. DEX
  886. bne nameloop
  887. rts
  888.  
  889. loadblankscreen:
  890. LDA #%00000000 ; disable NMI's and screen display
  891. STA $2000
  892. LDA #%00000000
  893. STA $2001
  894.  
  895. lda #<blank ; load low byte of
  896. sta piclo
  897. lda #>blank ; load high byte of first picture
  898. sta pichi
  899. rts
  900.  
  901. loadscrollsprites:
  902. LDX #$00 ; start at 0
  903. loadscrollspritesloop
  904. LDA sprites, x ; load data from address (sprites + x)
  905. STA spriteram, x ; store into RAM address ($0200 + x)
  906. INX ; X = X + 1
  907. CPX #$00 ; Compare X to hex $ff, decimal 64
  908. BNE loadscrollspritesloop ; Branch to LoadSpritesLoop if compare was Not Equal to zero
  909.  
  910. lda #01
  911. sta scrollspritesloadcheck
  912. rts
  913.  
  914. ;----sprite update subroutine start----
  915. updatesprites:
  916. lda #$00
  917. sta $2003 ; low byte (00) of RAM address
  918. lda #$02
  919. sta $4014 ; high byte (02) of RAM address, start transfer
  920. rts
  921.  
  922. ;------------------------------
  923. ; Sprite move subroutines start
  924. spritemovecheck:
  925.  
  926. lda spritedir ; load the screen number
  927. asl a ; x2 for word indexing
  928. tax ; use the game screen # as our index
  929. lda loadspritedir,x ; store the screennumber as a pointer.
  930. sta spritedirpointer
  931. lda loadspritedir+1,x
  932. sta spritedirpointer+1
  933. jmp (spritedirpointer)
  934. rts ; back to normal program flow
  935.  
  936. playup:
  937. LDX #0
  938. LDY #0
  939. @loop
  940. CLC
  941. LDA spriteram,x
  942. SBC speed,y
  943. STA spriteram,x
  944. STA $0200,x
  945. INY
  946. cpy #4
  947. BNE @skipreset
  948. LDY #0
  949. @skipreset
  950. INX
  951. INX
  952. INX
  953. INX
  954. CPX #0
  955. BNE @loop
  956. RTS
  957.  
  958. playdown:
  959. LDX #0
  960. LDY #0
  961. @loop
  962. CLC
  963. LDA spriteram,x
  964. ADC speed,y
  965. STA spriteram,x
  966. STA $0200,x
  967. INY
  968. cpy #4
  969. BNE @skipreset
  970. LDY #0
  971. @skipreset
  972. INX
  973. INX
  974. INX
  975. INX
  976. CPX #0
  977. BNE @loop
  978. RTS
  979.  
  980. playright:
  981. LDX #0
  982. LDY #0
  983. @loop
  984. CLC
  985. LDA spriteram+3,x
  986. ADC speed,y
  987. STA spriteram+3,x
  988. STA $0203,x
  989. INY
  990. cpy #4
  991. BNE @skipreset
  992. LDY #0
  993. @skipreset
  994. INX
  995. INX
  996. INX
  997. INX
  998. CPX #0
  999. BNE @loop
  1000. RTS
  1001.  
  1002. playleft:
  1003. LDX #0
  1004. LDY #0
  1005. @loop
  1006. CLC
  1007. LDA spriteram+3,x
  1008. SBC speed,y
  1009. STA spriteram+3,x
  1010. STA $0203,x
  1011. INY
  1012. cpy #4
  1013. BNE @skipreset
  1014. LDY #0
  1015. @skipreset
  1016. INX
  1017. INX
  1018. INX
  1019. INX
  1020. CPX #0
  1021. BNE @loop
  1022. RTS
  1023.  
  1024. ; Sprite direction subroutines end
  1025. ;---------------------------------
  1026.  
  1027.  
  1028. ;----------------------------------
  1029. ; sprite animation subroutine start
  1030. animatesprites:
  1031.  
  1032. DEC spriteanimationcounter
  1033. lda spriteanimationcounter
  1034. CMP #$00
  1035. BNE noanimationthiscycle
  1036.  
  1037. ;increment SPRITE number here
  1038. INC spritenumber
  1039. LDA spritenumber
  1040. CMP #4
  1041. BCC NoResetSpr
  1042. lda #0
  1043. sta spritenumber
  1044.  
  1045. NoResetSpr:
  1046.  
  1047. LDA spriteanimationnumber
  1048. STA spriteanimationcounter
  1049.  
  1050. noanimationthiscycle:
  1051. rts
  1052. ; sprite animation subroutine end
  1053. ;--------------------------------
  1054.  
  1055. ;--------------------------------
  1056. ; change sprite subroutine
  1057. changesprites
  1058. lda spritenumber
  1059.  
  1060. ;------------------
  1061. SprNum0:
  1062. CMP #0
  1063. BNE SprNum1
  1064.  
  1065. ldx #0
  1066. ldy #0
  1067. -
  1068. lda spritetiles0,y
  1069. sta $201,x
  1070. iny
  1071. cpy #$0f
  1072. BNE @skipreset
  1073. LDY #0
  1074. @skipreset
  1075. inx
  1076. inx
  1077. inx
  1078. inx
  1079. bne -
  1080.  
  1081. JMP SprChangeOver
  1082. ;------------------
  1083. SprNum1:
  1084. CMP #1
  1085. BNE SprNum2
  1086.  
  1087. ldx #0
  1088. ldy #0
  1089. -
  1090. lda spritetiles1,y
  1091. sta $201,x
  1092. iny
  1093. cpy #$0f
  1094. BNE @skipreset
  1095. LDY #0
  1096. @skipreset
  1097. inx
  1098. inx
  1099. inx
  1100. inx
  1101. bne -
  1102.  
  1103. JMP SprChangeOver
  1104. ;------------------
  1105. SprNum2:
  1106. CMP #2
  1107. BNE SprNum3
  1108.  
  1109. ldx #0
  1110. ldy #0
  1111. -
  1112. lda spritetiles2,y
  1113. sta $201,x
  1114. iny
  1115. cpy #$0f
  1116. BNE @skipreset
  1117. LDY #0
  1118. @skipreset
  1119. inx
  1120. inx
  1121. inx
  1122. inx
  1123. bne -
  1124. JMP SprChangeOver
  1125. ;------------------
  1126. SprNum3:
  1127. CMP #3
  1128. BNE SprChangeOver
  1129.  
  1130. ldx #0
  1131. ldy #0
  1132. -
  1133. lda spritetiles3,y
  1134. sta $201,x
  1135. iny
  1136. cpy #$0f
  1137. BNE @skipreset
  1138. LDY #0
  1139. @skipreset
  1140. inx
  1141. inx
  1142. inx
  1143. inx
  1144. bne -
  1145. JMP SprChangeOver
  1146. SprChangeOver:
  1147. RTS
  1148.  
  1149.  
  1150.  
  1151.  
  1152. ;----data tables----
  1153.  
  1154. loadspritedir:
  1155. .word playup,playdown,playleft,playright
  1156.  
  1157. loadspritetile:
  1158. .word spritetiles0,spritetiles1,spritetiles2,spritetiles3
  1159.  
  1160. palette:
  1161. .db $0F,$f0,$24,$f0,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F ;
  1162. .db $0F,$04,$14,$24,$0F,$14,$24,$34,$0F,$04,$14,$24,$0F,$14,$24,$34 ; palette 0
  1163.  
  1164. offset_table:
  1165. .db $e0,$e1,$e2,$e3,$e4,$e5,$e6,$e7,$e8,$e9,$ea,$eb,$ec,$ed,$ee,$ef
  1166. .db $f0,$f1,$f2,$f3,$f4,$f5,$f6,$f7,$f8,$f9,$fa,$fb,$fc,$fd,$fe,$ff
  1167.  
  1168. speed:
  1169. .db $01,$02,$03,$04
  1170.  
  1171. virtpos:
  1172. .db $0,$0,$0,$0,$0,$0,$0,$0,$0,$0,$0,$0,$0,$0,$0,$0
  1173. .db $1,$2,$3,$4,$5,$6,$7,$8,$A,$C,$E,$10,$12,$14,$16,$18
  1174. .db $1A,$1C,$1E,$20,$22,$24,$26,$28,$29,$2A,$2B,$2C,$2D,$2E,$2F,$30
  1175. .db $30,$30,$30,$30,$30,$30,$30,$30,$30,$30,$30,$30,$30,$30,$30,$30
  1176.  
  1177. .db $30,$30,$30,$30,$30,$30,$30,$30,$30,$30,$30,$30,$30,$30,$30,$30
  1178. .db $2F,$2E,$2D,$2C,$2B,$2A,$29,$28,$26,$24,$22,$20,$1E,$1C,$1A,$18
  1179. .db $16,$14,$12,$10,$E,$C,$A,$8,$7,$6,$5,$4,$3,$2,$1,$0
  1180. .db $0,$0,$0,$0,$0,$0,$0,$0,$0,$0,$0,$0,$0,$0,$0,$0
  1181.  
  1182. sprites:
  1183. ;vert tile attr horiz
  1184. .db $08, $00, $20, $a4
  1185. .db $08, $01, $20, $c9
  1186. .db $08, $02, $20, $84
  1187. .db $10, $03, $20, $88
  1188. .db $10, $04, $20, $e5
  1189. .db $18, $05, $20, $20
  1190. .db $18, $06, $20, $31
  1191. .db $20, $07, $20, $17
  1192. .db $28, $08, $20, $6e
  1193. .db $28, $09, $20, $89
  1194. .db $30, $0a, $20, $6b
  1195. .db $38, $0b, $20, $e1
  1196. .db $38, $00, $20, $5a
  1197. .db $38, $01, $20, $bd
  1198. .db $40, $02, $20, $90
  1199. .db $40, $03, $20, $bf
  1200. .db $48, $04, $20, $53
  1201. .db $48, $05, $20, $63
  1202. .db $48, $06, $20, $9d
  1203. .db $50, $07, $20, $e9
  1204. .db $50, $08, $20, $f3
  1205. .db $58, $09, $20, $13
  1206. .db $60, $0a, $20, $53
  1207. .db $60, $0b, $20, $88
  1208. .db $68, $00, $20, $76
  1209. .db $68, $01, $20, $bb
  1210. .db $68, $02, $20, $f6
  1211. .db $70, $03, $20, $dd
  1212. .db $70, $04, $20, $df
  1213. .db $78, $05, $20, $86
  1214. .db $78, $06, $20, $1d
  1215. .db $80, $07, $20, $e1
  1216. .db $80, $08, $20, $ca
  1217. .db $80, $09, $20, $99
  1218. .db $88, $0a, $20, $c3
  1219. .db $88, $0b, $20, $5e
  1220. .db $90, $00, $20, $1f
  1221. .db $98, $01, $20, $1e
  1222. .db $98, $02, $20, $99
  1223. .db $98, $03, $20, $e2
  1224. .db $a0, $04, $20, $3d
  1225. .db $a0, $05, $20, $a2
  1226. .db $a8, $06, $20, $24
  1227. .db $b0, $07, $20, $ec
  1228. .db $b0, $08, $20, $09
  1229. .db $b0, $09, $20, $16
  1230. .db $b8, $0a, $20, $aa
  1231. .db $b8, $0b, $20, $5b
  1232. .db $c0, $00, $20, $54
  1233. .db $c0, $01, $20, $fa
  1234. .db $c0, $02, $20, $74
  1235. .db $c8, $03, $20, $c9
  1236. .db $c8, $04, $20, $0b
  1237. .db $d0, $05, $20, $a9
  1238. .db $d0, $06, $20, $37
  1239. .db $d0, $07, $20, $e2
  1240. .db $d8, $08, $20, $74
  1241. .db $d8, $09, $20, $1d
  1242. .db $d8, $0a, $20, $85
  1243. .db $e0, $0b, $20, $d1
  1244. .db $e0, $00, $20, $f4
  1245. .db $e8, $01, $20, $da
  1246. .db $e8, $02, $20, $31
  1247. .db $e8, $03, $20, $12
  1248.  
  1249. spritetiles0:
  1250. .db $00,$01,$02,$03,$04,$05,$06,$07,$08,$09,$0a,$0b,$0c,$0d,$0e,$0f
  1251.  
  1252. spritetiles1:
  1253. .db $10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$1a,$1b,$1c,$1d,$1e,$1f
  1254.  
  1255. spritetiles2:
  1256. .db $20,$21,$22,$23,$24,$25,$26,$27,$28,$29,$2a,$2b,$2c,$2d,$2e,$2f
  1257.  
  1258. spritetiles3:
  1259. .db $30,$31,$32,$33,$34,$35,$36,$37,$38,$39,$3a,$3b,$3c,$3d,$3e,$3f
  1260.  
  1261.  
  1262.  
  1263. ;----include picture data----
  1264. .ORG $C000
  1265. .include "charmap.bin" ; Attach character map to ROM
  1266.  
  1267. titlescreen:
  1268. .incbin "titlescreen.nam"
  1269. blank:
  1270. .incbin "blank.nam"
  1271.  
  1272. ;----vectors----
  1273.  
  1274. .ORG $fffa
  1275. .DW NMI
  1276. .DW Reset
  1277. .DW IRQ
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement