Advertisement
Guest User

Untitled

a guest
Feb 16th, 2012
346
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 34.85 KB | None | 0 0
  1.  
  2. .inesprg 1 ; 1x 16KB PRG code
  3. .ineschr 1 ; 1x 8KB CHR data
  4. .inesmap 0 ; mapper 0 = NROM, no bank swapping
  5. .inesmir 1 ; background mirroring
  6.  
  7.  
  8. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  9. ;;;;;;;VARIABLE DECLARATIONS;;;;;;;
  10. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11.  
  12. .rsset $0000 ;;start variables at ram location 0
  13.  
  14. gamestate .rs 1 ; .rs 1 means reserve one byte of space
  15. ballx .rs 1 ; ball horizontal position
  16. bally .rs 1 ; ball vertical position
  17. ballup .rs 1 ; 1 = ball moving up
  18. balldown .rs 1 ; 1 = ball moving down
  19. ballleft .rs 1 ; 1 = ball moving left
  20. ballright .rs 1 ; 1 = ball moving right
  21. ballspeedx .rs 1 ; ball horizontal speed per frame
  22. ballspeedy .rs 1 ; ball vertical speed per frame
  23. paddle1ytop .rs 1 ; player 1 paddle top vertical position
  24. paddle2ytop .rs 1 ; player 2 paddle top vertical position
  25. paddle1ybot .rs 1 ; player 1 paddle bottom vertical position
  26. paddle2ybot .rs 1 ; player 2 paddle bottom vertical position
  27. paddle1speed .rs 1 ; player 1 paddle speed
  28. paddle2speed .rs 1 ; player 2 paddle speed
  29. buttons1 .rs 1 ; player 1 gamepad buttons, one bit per button
  30. buttons2 .rs 1 ; player 2 gamepad buttons, one bit per button
  31. score1 .rs 1 ; player 1 score, 0-15
  32. score2 .rs 1 ; player 2 score, 0-15
  33. score1Ones .rs 1 ; player 1's score's ones digit
  34. score1Tens .rs 1 ; player 1's score's tens digit
  35. score2Ones .rs 1 ; player 2's score's ones digit
  36. score2Tens .rs 1 ; player 2's score's tens digit
  37. AddrLow .rs 1
  38. AddrHigh .rs 1
  39. frameCounter .rs 1
  40. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  48. ;;;;;;;;CONSTANT DECLARATIONS;;;;
  49. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  50. STATETITLE = $00 ; displaying title screen
  51. STATEPLAYING = $01 ; move paddles/ball, check for collisions
  52. STATEGAMEOVER = $02 ; displaying game over screen
  53.  
  54. RIGHTWALL = $F4 ; when ball reaches one of these, do something
  55. TOPWALL = $20
  56. BOTTOMWALL = $E0
  57. LEFTWALL = $04
  58.  
  59. PADDLE1X = $08 ; horizontal position for paddles, doesn't move
  60. PADDLE2X = $F0
  61. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  62.  
  63.  
  64.  
  65.  
  66. .bank 0
  67. .org $C000
  68. RESET:
  69. SEI ; disable IRQs
  70. CLD ; disable decimal mode
  71. LDX #$40
  72. STX $4017 ; disable APU frame IRQ
  73. LDX #$FF
  74. TXS ; Set up stack
  75. INX ; now X = 0
  76. STX $2000 ; disable NMI
  77. STX $2001 ; disable rendering
  78. STX $4010 ; disable DMC IRQs
  79.  
  80. vblankwait1: ; First wait for vblank to make sure PPU is ready
  81. BIT $2002
  82. BPL vblankwait1
  83.  
  84. clrmem:
  85. LDA #$00
  86. STA $0000, x
  87. STA $0100, x
  88. STA $0300, x
  89. STA $0400, x
  90. STA $0500, x
  91. STA $0600, x
  92. STA $0700, x
  93. LDA #$FE
  94. STA $0200, x
  95. INX
  96. BNE clrmem
  97.  
  98. vblankwait2: ; Second wait for vblank, PPU is ready after this
  99. BIT $2002
  100. BPL vblankwait2
  101.  
  102.  
  103.  
  104.  
  105. ;; LOAD PALETTES, BACKGROUND, ATTRIBUTES
  106. LoadPalettes:
  107. LDA $2002 ; read PPU status to reset the high/low latch
  108. LDA #$3F
  109. STA $2006 ; write the high byte of $3F00 address
  110. LDA #$00
  111. STA $2006 ; write the low byte of $3F00 address
  112. LDX #$00 ; start out at 0
  113. LoadPalettesLoop:
  114. LDA palette, x ; load data from address (palette + the value in x)
  115. ; 1st time through loop it will load palette+0
  116. ; 2nd time through loop it will load palette+1
  117. ; 3rd time through loop it will load palette+2
  118. ; etc
  119. STA $2007 ; write to PPU
  120. INX ; X = X + 1
  121. CPX #$20 ; Compare X to hex $20, decimal 32 - copying 32 bytes = 8 sprites
  122. BNE LoadPalettesLoop ; Branch to LoadPalettesLoop if compare was Not Equal to zero
  123. ; if compare was equal to 32, keep going down
  124.  
  125. LoadTitleScreen:
  126. LDA $2002 ; read PPU status to reset the high/low latch
  127. LDA #$20
  128. STA $2006 ; write the high byte of $2000 address
  129. LDA #$00
  130. STA $2006 ; write the low byte of $2000 address
  131. LDA #low(title)
  132. STA AddrLow
  133. LDA #high(title)
  134. STA AddrHigh
  135.  
  136. LDX #$04 ; Loop X 4 times
  137. LDY #$00 ; Loop Y 256 times
  138. LoadTitleLoop:
  139. LDA [AddrLow],y
  140. STA $2007
  141. INY
  142. BNE LoadTitleLoop
  143. ; Outer loop
  144. INC AddrHigh ; increment high byte of address backg to next 256 byte chunk
  145. DEX ; one chunk done so X = X - 1.
  146. BNE LoadTitleLoop ; if X isn't zero, do again
  147.  
  148.  
  149.  
  150. ;;:Set starting game state
  151. LDA #STATETITLE
  152. STA gamestate
  153.  
  154. ;;This is the PPU clean up section, so rendering the next frame starts properly.
  155. LDA #%10010000 ; enable NMI, sprites from Pattern Table 0, background from Pattern Table 1
  156. STA $2000
  157. LDA #%00011110 ; enable sprites, enable background, no clipping on left side
  158. STA $2001
  159.  
  160.  
  161.  
  162.  
  163. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  164. ;;;;;;;;;MAIN GAME LOGIC;;;;;;;;;;;;;;;;
  165. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  166. MainLoop:
  167. CheckTitle:
  168. JSR WaitForNMI
  169. LDA gamestate
  170. CMP #STATETITLE
  171. BNE CheckPlaying
  172. JSR ReadController1
  173. LDA buttons1
  174. AND #%00010000
  175. BEQ CheckPlaying
  176. JSR InitializeGame
  177. CheckPlaying:
  178. JSR WaitForNMI
  179. LDA gamestate
  180. CMP #STATEPLAYING
  181. BNE CheckOver
  182. JSR ReadController1 ;;get the current button data for player 1
  183. JSR ReadController2 ;;get the current button data for player 2
  184. JSR UpdateSprites
  185. JSR MoveBall
  186. JSR MovePaddles
  187. JSR CheckCollisions
  188. CheckOver:
  189. LDA gamestate
  190. CMP #STATEGAMEOVER
  191. BNE MainLoop
  192. JMP MainLoop ;jump back to MainLoop, infinite loop, waiting for NMI
  193. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204. ;;;;;;;;;;
  205. ;;NMI;;;;;
  206. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  207. NMI:
  208. INC frameCounter
  209.  
  210. LDA #$00
  211. STA $2003 ; set the low byte (00) of the RAM address
  212. LDA #$02
  213. STA $4014 ; set the high byte (02) of the RAM address, start the transfer
  214.  
  215. LDA #$00 ;;tell the ppu there is no background scrolling
  216. STA $2005
  217. STA $2005
  218.  
  219. LDA #%00011110 ; enable sprites, disable background, no clipping on left side
  220. STA $2001
  221.  
  222. RTI ; return from interrupt
  223. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  224.  
  225.  
  226.  
  227.  
  228.  
  229. ;;;;;;;;;;;;;;;;;;;;;
  230. ;;;;;SUBROUTINES;;;;;
  231. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  232.  
  233.  
  234. ;***************
  235. ;INITIALIZE GAME
  236. ;******************************************************************
  237. InitializeGame:
  238.  
  239. LDA #$00
  240. STA $2000
  241. STA $2001
  242.  
  243. ;;;;;;;;LOAD ALL BACKGROUND INFO FOR GAME PLAYING STATE
  244. LoadBackgroundScreen:
  245. LDA $2002 ; read PPU status to reset the high/low latch
  246. LDA #$20
  247. STA $2006 ; write the high byte of $2000 address
  248. LDA #$00
  249. STA $2006 ; write the low byte of $2000 address
  250. LDA #low(background)
  251. STA AddrLow
  252. LDA #high(background)
  253. STA AddrHigh
  254.  
  255. LDX #$04 ; Loop X 4 times
  256. LDY #$00 ; Loop Y 256 times
  257. LoadBackgroundLoop:
  258. LDA [AddrLow],y
  259. STA $2007
  260. INY
  261. BNE LoadBackgroundLoop
  262. ; Outer loop
  263. INC AddrHigh ; increment high byte of address backg to next 256 byte chunk
  264. DEX ; one chunk done so X = X - 1.
  265. BNE LoadBackgroundLoop ; if X isn't zero, do again
  266.  
  267.  
  268.  
  269. ;;;INITIALIZATION
  270. ;;BALL STATS
  271. LDA #$01 ; True
  272. STA balldown ; Here we set direction components of ball vector
  273. STA ballright
  274. LDA #$00 ; False
  275. STA ballup
  276. STA ballleft
  277.  
  278. LDA #$78 ; Vertical center of screen
  279. STA bally
  280.  
  281. LDA #$80 ; Horizontal center of screen
  282. STA ballx
  283.  
  284. LDA #$01 ; Ball will move 1 pixel at a time
  285. STA ballspeedx
  286. STA ballspeedy
  287.  
  288. LDA #$75 ; Ball will look like top of flagpole from SMB
  289. STA $0201
  290.  
  291. LDA #$01 ; Ball will use first set of 4 colors from sprite palette
  292. STA $0202
  293.  
  294.  
  295. ;;;PADDLES Y-COORDINATES
  296. LDA #$70 ; Align top of paddle near center
  297. STA paddle1ytop
  298. STA paddle2ytop
  299. LDA #$90 ; Align bottom of paddle near center
  300. STA paddle1ybot
  301. STA paddle2ybot
  302.  
  303. ;;;LOADING TILES FOR PADDLE GRAPHICS
  304. LDX #$00
  305. Load_Paddle_Tile:
  306. LDA #$5B ; In mario.chr this is one of the platform graphics from SMB
  307. STA $0205, x ; $0205 is paddle 1's top tile y-coordinate
  308. STA $0215, x ; $0215 is paddle 2's top tile y-coordinate
  309. INX
  310. INX
  311. INX ; Increasing X by 4 shifts over 4 bytes in memory to reach next y-coordinate for next paddle tile
  312. INX
  313. CPX #$10 ; Once we hit 16, we've loaded 4 tiles (each paddle is 4 tiles high)
  314. BNE Load_Paddle_Tile
  315.  
  316. ;;;LOADING ATTRIBUTES FOR EACH PADDLE
  317. LDX #$00
  318. Load_Paddle_Attr:
  319. LDA #$01 ; Use the first set of 4 colors from sprites
  320. STA $0206, x ; $0206 is paddle 1's top tile attribute
  321. STA $0216, x ; $0216 is paddle 2's top tile attribute
  322. INX
  323. INX
  324. INX
  325. INX
  326. CPX #$10
  327. BNE Load_Paddle_Attr
  328.  
  329. ;;;LOADING X-COORDINATES FOR EACH PADDLE
  330. LDX #$00
  331. Load_Paddle_X:
  332. LDA #PADDLE1X ; Paddles can't move horizontally
  333. STA $0207, x ; $0207 is paddle 1's top tile x-coordinate
  334. LDA #PADDLE2X
  335. STA $0217, x ; $0217 is paddle 2's top tile x-coordinate
  336. INX
  337. INX
  338. INX
  339. INX
  340. CPX #$10
  341. BNE Load_Paddle_X
  342.  
  343. ;;;PADDLE SPEEDS
  344. Load_Paddle_Speeds:
  345. LDA #$01 ; Paddles can initially move 1 pixel per frame
  346. STA paddle1speed
  347. STA paddle2speed
  348.  
  349. ;;Set scores
  350. LDA #$00
  351. STA score1Ones ; Zero out placeholders (these numbers are drawn to screen)
  352. STA score1Tens
  353. STA score2Ones
  354. STA score2Tens
  355. STA score1 ; Zero out actual scores which get checked for win conditions
  356. STA score2
  357.  
  358. LDA #STATEPLAYING ; Change state to playing
  359. STA gamestate
  360.  
  361. LDA #%10010000 ; enable NMI, sprites from Pattern Table 0, background from Pattern Table 1
  362. STA $2000
  363.  
  364. RTS
  365. ;******************************************************************
  366.  
  367.  
  368.  
  369. ;***************
  370. ;UPDATE SPRITES
  371. ;******************************************************************
  372. UpdateSprites:
  373. LDA bally ; Update ball y-coordinate
  374. STA $0200
  375.  
  376. LDA ballx ; Update ball x-coordinate
  377. STA $0203
  378.  
  379.  
  380. LDX #$00 ; Clear out indices
  381. LDY #$00
  382.  
  383. Load_Paddle_Y:
  384. LDA paddle1ytop ; Load all y-coordinates for paddle 1 relative to the top tile y-coordinate
  385. CLC
  386. ADC vertical_offsets, y
  387. STA $0204, x
  388.  
  389. LDA paddle2ytop ; Load all y-coordinates for paddle 2 relative to the top tile y-coordinate
  390. CLC
  391. ADC vertical_offsets, y
  392. STA $0214, x
  393.  
  394. INX
  395. INX
  396. INX
  397. INX
  398.  
  399. INY
  400. CPY #$04
  401. BNE Load_Paddle_Y
  402. RTS
  403. ;******************************************************************
  404.  
  405.  
  406. ;***************
  407. ;UPDATE SCORE
  408. ;******************************************************************
  409. UpdateScore:
  410. LDA #$00
  411. STA $2000
  412. STA $2001
  413.  
  414. LDA $2002
  415. LDA #$20
  416. STA $2006
  417. LDA #$42
  418. STA $2006 ; start drawing player 1 score at PPU $2042
  419.  
  420. LDA score1Tens ; first digit
  421. STA $2007 ; draw to background
  422. LDA score1Ones ; last digit
  423. STA $2007
  424.  
  425. LDA $2002 ; start drawing player 2 score at PPU $203E
  426. LDA #$20
  427. STA $2006
  428. LDA #$5A
  429. STA $2006
  430.  
  431. LDA score2Tens
  432. STA $2007
  433. LDA score2Ones
  434. STA $2007
  435.  
  436. LDA #%10010000 ; enable NMI, sprites from Pattern Table 0, background from Pattern Table 1
  437. STA $2000
  438.  
  439.  
  440. RTS
  441. ;******************************************************************
  442.  
  443.  
  444. ;***************
  445. ;INCREMENT SCORE 1
  446. ;******************************************************************
  447. IncrementScore1:
  448. Inc1Ones:
  449. LDA score1Ones ; load the lowest digit of the number
  450. CLC
  451. ADC #$01 ; add one
  452. STA score1Ones
  453. CMP #$0A ; check if it overflowed, now equals 10
  454. BNE Check1Score ; if there was no overflow, all done
  455. Inc1Tens:
  456. LDA #$00
  457. STA score1Ones ; wrap digit to 0
  458. LDA score1Tens ; load the next digit
  459. CLC
  460. ADC #$01 ; add one, the carry from previous digit
  461. STA score1Tens
  462.  
  463. Check1Score:
  464. LDA score1 ; This variable will be used to check win conditions
  465. CLC
  466. ADC #$01
  467. STA score1
  468. CMP #$10 ; Compare to 16. If equal to 16, we have a winner
  469. BNE Inc1Done
  470. LDA STATEGAMEOVER
  471. STA gamestate
  472. Inc1Done:
  473. JSR PlayerScored
  474. RTS
  475. ;******************************************************************
  476.  
  477.  
  478. ;***************
  479. ;INCREMENT SCORE 2
  480. ;******************************************************************
  481. IncrementScore2:
  482. Inc2Ones:
  483. LDA score2Ones ; load the lowest digit of the number
  484. CLC
  485. ADC #$01 ; add one
  486. STA score2Ones
  487. CMP #$0A ; check if it overflowed, now equals 10
  488. BNE Check2Score ; if there was no overflow, all done
  489. Inc2Tens:
  490. LDA #$00
  491. STA score2Ones ; wrap digit to 0
  492. LDA score2Tens ; load the next digit
  493. CLC
  494. ADC #$01 ; add one, the carry from previous digit
  495. STA score2Tens
  496.  
  497. Check2Score:
  498. LDA score2 ; This variable will be used to check win conditions
  499. CLC
  500. ADC #$01
  501. STA score2
  502. CMP #$10 ; Compare to 16. If equal to 16, we have a winner
  503. BNE Inc2Done
  504. LDA STATEGAMEOVER
  505. STA gamestate
  506. Inc2Done:
  507. JSR PlayerScored
  508. RTS
  509. ;******************************************************************
  510.  
  511.  
  512. ;***************
  513. ;READ CONTROLLER 1
  514. ;******************************************************************
  515. ;; In the following subroutines, we loop through controller input and store each button state in a bit
  516. ;; The order (from left to right) is: A, B, Select, Start, Up, Down, Left, Right
  517. ReadController1:
  518. LDA #$01
  519. STA $4016
  520. LDA #$00
  521. STA $4016
  522. LDX #$08
  523. ReadController1Loop:
  524. LDA $4016
  525. LSR A ; bit0 -> Carry
  526. ROL buttons1 ; bit0 <- Carry
  527. DEX
  528. BNE ReadController1Loop
  529. RTS
  530. ;******************************************************************
  531.  
  532.  
  533. ;***************
  534. ;READ CONTROLLER 2
  535. ;******************************************************************
  536. ReadController2:
  537. LDA #$01
  538. STA $4016
  539. LDA #$00
  540. STA $4016
  541. LDX #$08
  542. ReadController2Loop:
  543. LDA $4017
  544. LSR A ; bit0 -> Carry
  545. ROL buttons2 ; bit0 <- Carry
  546. DEX
  547. BNE ReadController2Loop
  548. RTS
  549. ;******************************************************************
  550.  
  551.  
  552.  
  553. ;***************
  554. ;INCREASE BALL SPEED X
  555. ;******************************************************************
  556. IncreaseBallSpeedX:
  557. LDA ballspeedx
  558. CLC
  559. ADC #$01
  560. STA ballspeedx
  561. RTS
  562. ;******************************************************************
  563.  
  564. ;***************
  565. ;INCREASE BALL SPEED Y
  566. ;******************************************************************
  567. IncreaseBallSpeedY:
  568. LDA ballspeedy
  569. CLC
  570. ADC #$01
  571. STA ballspeedy
  572. RTS
  573. ;******************************************************************
  574.  
  575. ;***************
  576. ;PLAYER SCORED
  577. ;******************************************************************
  578. PlayerScored:
  579. JSR UpdateScore
  580. LDA #$01
  581. STA ballspeedx
  582. STA ballspeedy
  583. STA paddle1speed
  584. STA paddle2speed
  585. LDA #$78
  586. STA bally
  587. LDA #$80
  588. STA ballx
  589. RTS
  590. ;******************************************************************
  591.  
  592.  
  593.  
  594.  
  595. ;***************
  596. ;MOVE BALL
  597. ;******************************************************************
  598.  
  599. MoveBall:
  600. MoveBallRight:
  601. LDA ballright
  602. BEQ MoveBallRightDone ;;if ballright=0, skip this section
  603.  
  604. LDA ballx
  605. CLC
  606. ADC ballspeedx ;;ballx position = ballx + ballspeedx
  607. STA ballx
  608.  
  609. LDA ballx
  610. CMP #RIGHTWALL
  611. BCC MoveBallRightDone ;;if ball x < right wall, still on screen, skip next section
  612. LDA #$00
  613. STA ballright
  614. LDA #$01
  615. STA ballleft ;;bounce, ball now moving left
  616. JSR IncrementScore1 ;;give point to player 1, reset ball
  617. MoveBallRightDone:
  618.  
  619.  
  620. MoveBallLeft:
  621. LDA ballleft
  622. BEQ MoveBallLeftDone ;;if ballleft=0, skip this section
  623.  
  624. LDA ballx
  625. SEC
  626. SBC ballspeedx ;;ballx position = ballx - ballspeedx
  627. STA ballx
  628.  
  629. LDA ballx
  630. CMP #LEFTWALL
  631. BCS MoveBallLeftDone ;;if ball x > left wall, still on screen, skip next section
  632. LDA #$01
  633. STA ballright
  634. LDA #$00
  635. STA ballleft ;;bounce, ball now moving right
  636. JSR IncrementScore2 ;;give point to player 2, reset ball
  637. MoveBallLeftDone:
  638.  
  639.  
  640. MoveBallUp:
  641. LDA ballup
  642. BEQ MoveBallUpDone ;;if ballup=0, skip this section
  643.  
  644. LDA bally
  645. SEC
  646. SBC ballspeedy ;;bally position = bally - ballspeedy
  647. STA bally
  648.  
  649. LDA bally
  650. CMP #TOPWALL
  651. BCS MoveBallUpDone ;;if ball y > top wall, still on screen, skip next section
  652. LDA #$01
  653. STA balldown
  654. LDA #$00
  655. STA ballup ;;bounce, ball now moving down
  656. MoveBallUpDone:
  657.  
  658.  
  659. MoveBallDown:
  660. LDA balldown
  661. BEQ MoveBallDownDone ;;if ballup=0, skip this section
  662.  
  663. LDA bally
  664. CLC
  665. ADC ballspeedy ;;bally position = bally + ballspeedy
  666. STA bally
  667.  
  668. LDA bally
  669. CMP #BOTTOMWALL
  670. BCC MoveBallDownDone ;;if ball y < bottom wall, still on screen, skip next section
  671. LDA #$00
  672. STA balldown
  673. LDA #$01
  674. STA ballup ;;bounce, ball now moving down
  675. MoveBallDownDone:
  676. RTS
  677. ;******************************************************************
  678.  
  679.  
  680.  
  681.  
  682.  
  683. ;***************
  684. ;MOVE PADDLES
  685. ;******************************************************************
  686. MovePaddles:
  687. MovePaddle1Up:
  688. LDA buttons1
  689. AND #%00001000
  690. BEQ MovePaddle1UpDone ; Use BEQ because zero flag will be set if result of AND operation is false
  691.  
  692. ;;if up button pressed, move paddle up
  693. LDA paddle1ytop
  694. SEC
  695. SBC paddle1speed
  696. STA paddle1ytop
  697. LDA paddle1ybot
  698. SEC
  699. SBC paddle1speed
  700. STA paddle1ybot
  701.  
  702. ;; if paddle top > top wall
  703. LDA paddle1ytop
  704. CMP #TOPWALL
  705. BCS MovePaddle1UpDone
  706. LDA #TOPWALL
  707. STA paddle1ytop ;set top tile y-coordinate to TOPWALL
  708. CLC
  709. ADC #$20 ;bottom of paddle is 32 pixels below TOPWALL, so have to keep it set there
  710. STA paddle1ybot ;otherwise, bottom y-coordinate will decrease when up is pushed
  711. MovePaddle1UpDone:
  712.  
  713. MovePaddle2Up:
  714. LDA buttons2
  715. AND #%00001000
  716. BEQ MovePaddle2UpDone
  717.  
  718. ;; if up button pressed, move paddle up
  719. LDA paddle2ytop
  720. SEC
  721. SBC paddle2speed
  722. STA paddle2ytop
  723. LDA paddle2ybot
  724. SEC
  725. SBC paddle2speed
  726. STA paddle2ybot
  727.  
  728. ;; if paddle top > top wall
  729. LDA paddle2ytop
  730. CMP #TOPWALL
  731. BCS MovePaddle2UpDone
  732. LDA #TOPWALL
  733. STA paddle2ytop ;set top tile y-coordinate to TOPWALL
  734. CLC
  735. ADC #$20 ;bottom of paddle is 32 pixels below TOPWALL, so have to keep it set there
  736. STA paddle2ybot ;otherwise, bottom y-coordinate will decrease when up is pushed
  737. MovePaddle2UpDone:
  738.  
  739. MovePaddle1Down:
  740. LDA buttons1
  741. AND #%00000100
  742. BEQ MovePaddle1DownDone
  743.  
  744. ;;if down button pressed
  745. LDA paddle1ytop
  746. CLC
  747. ADC paddle1speed
  748. STA paddle1ytop
  749. LDA paddle1ybot
  750. CLC
  751. ADC paddle1speed
  752. STA paddle1ybot
  753.  
  754. ;; if paddle bottom < bottom wall
  755. LDA paddle1ybot
  756. CMP #BOTTOMWALL
  757. BCC MovePaddle1DownDone
  758. LDA #BOTTOMWALL ;set bottom tile y-coordinate to BOTTOMWALL
  759. STA paddle1ybot
  760. SEC
  761. SBC #$20 ;top of paddle is 32 pixels above BOTTOMWALL, so have to keep it set there
  762. STA paddle1ytop ;otherwise, top y-coordinate will increase when down is pushed
  763. MovePaddle1DownDone:
  764.  
  765. MovePaddle2Down:
  766. LDA buttons2
  767. AND #%00000100
  768. BEQ MovePaddle2DownDone
  769.  
  770. ;;if down button pressed
  771. LDA paddle2ytop
  772. CLC
  773. ADC paddle2speed
  774. STA paddle2ytop
  775. LDA paddle2ybot
  776. CLC
  777. ADC paddle2speed
  778. STA paddle2ybot
  779.  
  780. ;; if paddle bottom < bottom wall
  781. LDA paddle2ybot
  782. CMP #BOTTOMWALL
  783. BCC MovePaddle2DownDone
  784. LDA #BOTTOMWALL
  785. STA paddle2ybot ;set bottom tile y-coordinate to BOTTOMWALL
  786. SEC
  787. SBC #$20 ;top of paddle is 32 pixels above BOTTOMWALL, so have to keep it set there
  788. STA paddle2ytop ;otherwise, top y-coordinate will increase when down is pushed
  789. MovePaddle2DownDone:
  790. RTS
  791. ;******************************************************************
  792.  
  793.  
  794. ;***************
  795. ;CHECK COLLISIONS
  796. ;******************************************************************
  797. CheckCollisions:
  798. CheckPaddle1Collision:
  799. ;;if ball x < paddle1x
  800. LDA ballx
  801. SEC
  802. SBC #$08
  803. CMP #PADDLE1X
  804. BCS CheckPaddle1CollisionDone
  805.  
  806. ;; if ball y > paddle y top
  807. LDA bally
  808. CLC
  809. ADC #$08
  810. CMP paddle1ytop
  811. BCC CheckPaddle1CollisionDone
  812.  
  813. ;; if ball y < paddle y bottom
  814. LDA bally
  815. SEC
  816. SBC #$08
  817. CMP paddle1ybot
  818. BCS CheckPaddle1CollisionDone
  819.  
  820. ;; bounce, ball now moving right
  821. LDA #$01
  822. STA ballright
  823. LDA #$00
  824. STA ballleft
  825. JSR IncreaseBallSpeedX ; increase horizontal speed of ball
  826. LDA paddle1speed
  827. CLC
  828. ADC #$01
  829. STA paddle1speed ; increase paddle 1 speed
  830. CheckPaddle1CollisionDone:
  831.  
  832. CheckPaddle2Collision:
  833. ;;if ball x < paddle1x
  834. LDA ballx
  835. CLC
  836. ADC #$08
  837. CMP #PADDLE2X
  838. BCC CheckPaddle2CollisionDone
  839.  
  840. ;; if ball y > paddle y top
  841. LDA bally
  842. CLC
  843. ADC #$08
  844. CMP paddle2ytop
  845. BCC CheckPaddle2CollisionDone
  846.  
  847. ;; if ball y < paddle y bottom
  848. LDA bally
  849. SEC
  850. SBC #$08
  851. CMP paddle2ybot
  852. BCS CheckPaddle2CollisionDone
  853.  
  854. ;; bounce, ball now moving right
  855. LDA #$01
  856. STA ballleft
  857. LDA #$00
  858. STA ballright
  859. JSR IncreaseBallSpeedY ; increase vertical speed of ball
  860. LDA paddle2speed
  861. CLC
  862. ADC #$01
  863. STA paddle2speed ; increase paddle 2 speed
  864. CheckPaddle2CollisionDone:
  865. RTS
  866. ;******************************************************************
  867.  
  868.  
  869. ;***************
  870. ;WAIT FOR NMI
  871. ;******************************************************************
  872. WaitForNMI:
  873. LDA frameCounter
  874. WaitLoop:
  875. CMP frameCounter
  876. BEQ WaitLoop
  877. RTS
  878. ;******************************************************************
  879.  
  880.  
  881.  
  882.  
  883.  
  884.  
  885. ;;;;;;;;;;;;;;;;;;;;;;;;
  886. ;;;;;;;; DATA ;;;;;;;;;;
  887. ;;;;;;;;;;;;;;;;;;;;;;;;
  888.  
  889.  
  890.  
  891. .bank 1
  892. .org $E000
  893. palette:
  894. .db $22,$29,$1A,$0F, $22,$36,$17,$0F, $22,$30,$21,$0F, $22,$27,$17,$0F ;;background palette
  895. .db $22,$1C,$15,$14, $22,$02,$38,$3C, $22,$1C,$15,$14, $22,$02,$38,$3C ;;sprite palette
  896.  
  897.  
  898. sprites:
  899. ;vert tile attr horiz
  900. .db $80, $75, $00, $80 ;sprite 0
  901.  
  902. vertical_offsets:
  903. .db $00, $08, $10, $18
  904.  
  905. background:
  906. .db $26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26
  907. .db $19,$15,$0a,$22,$0e,$1b,$26,$01,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$19,$15,$0a,$22,$0e,$1b,$26,$02
  908. .db $26,$26,$00,$00,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$00,$00,$26,$26,$26,$26
  909. .db $26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26
  910. .db $26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26
  911. .db $26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26
  912. .db $26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26
  913. .db $26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26
  914. .db $26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26
  915. .db $26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26
  916. .db $26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26
  917. .db $26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26
  918. .db $26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26
  919. .db $26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26
  920. .db $26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26
  921. .db $26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26
  922. .db $26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26
  923. .db $26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26
  924. .db $26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26
  925. .db $26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26
  926. .db $26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26
  927. .db $26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26
  928. .db $26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26
  929. .db $26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26
  930. .db $26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26
  931. .db $26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26
  932. .db $26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26
  933. .db $26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26
  934. .db $26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26
  935. .db $26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26,$26
  936.  
  937. attributes:
  938. .db $01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01
  939. .db $01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01
  940.  
  941.  
  942. title:
  943. .db $25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25
  944. .db $25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25
  945. .db $25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25
  946. .db $25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25
  947. .db $25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25
  948. .db $25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25
  949. .db $25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25
  950. .db $25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25
  951. .db $26,$26,$26,$26,$26,$26,$26,$25,$25,$26,$26,$26,$26,$26,$26,$25,$26,$26,$26,$25,$25,$25,$26,$26,$25,$25,$26,$26,$26,$26,$26,$25
  952. .db $26,$26,$26,$26,$26,$26,$26,$27,$26,$26,$26,$26,$26,$26,$26,$27,$26,$26,$26,$26,$25,$25,$26,$26,$25,$26,$26,$26,$26,$26,$26,$26
  953. .db $26,$26,$27,$27,$27,$26,$26,$27,$26,$26,$27,$27,$27,$26,$26,$27,$26,$26,$26,$26,$26,$25,$26,$27,$26,$26,$26,$27,$27,$27,$27,$25
  954. .db $26,$26,$27,$25,$25,$26,$26,$27,$26,$26,$27,$25,$25,$26,$26,$27,$26,$26,$26,$26,$26,$26,$26,$27,$26,$26,$26,$27,$25,$25,$25,$25
  955. .db $26,$26,$27,$25,$25,$26,$26,$27,$26,$26,$27,$25,$25,$26,$26,$27,$26,$26,$27,$26,$26,$26,$26,$27,$26,$26,$26,$27,$25,$26,$26,$26
  956. .db $26,$26,$26,$26,$26,$26,$26,$27,$26,$26,$26,$26,$26,$26,$26,$27,$26,$26,$27,$25,$26,$26,$26,$27,$26,$26,$26,$27,$25,$25,$26,$26
  957. .db $26,$26,$26,$26,$26,$26,$27,$27,$25,$26,$26,$26,$26,$26,$27,$27,$26,$26,$27,$25,$25,$26,$26,$27,$25,$26,$26,$26,$26,$26,$26,$27
  958. .db $26,$26,$26,$26,$27,$27,$27,$25,$25,$27,$27,$27,$27,$27,$27,$25,$27,$27,$27,$25,$25,$25,$27,$27,$25,$25,$26,$26,$26,$26,$27,$25
  959. .db $26,$26,$26,$26,$27,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25
  960. .db $26,$26,$26,$26,$27,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25
  961. .db $26,$26,$26,$26,$27,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25
  962. .db $25,$27,$27,$27,$27,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25
  963. .db $25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25
  964. .db $25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25
  965. .db $25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$19,$1b,$0e,$1c,$1c,$25,$1c,$1d,$0a,$1b,$1d,$2b,$25,$25,$25,$25,$25,$25,$25,$25
  966. .db $25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25
  967. .db $25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25
  968. .db $25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25
  969. .db $25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25
  970. .db $25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25
  971. .db $25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25
  972. .db $25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25,$25
  973.  
  974. titleattr:
  975. .db $03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03
  976. .db $03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03
  977.  
  978. .org $FFFA ;first of the three vectors starts here
  979. .dw NMI ;when an NMI happens (once per frame if enabled) the
  980. ;processor will jump to the label NMI:
  981. .dw RESET ;when the processor first turns on or is reset, it will jump
  982. ;to the label RESET:
  983. .dw 0 ;external interrupt IRQ is not used in this tutorial
  984.  
  985.  
  986. ;;;;;;;;;;;;;;
  987.  
  988.  
  989. .bank 2
  990. .org $0000
  991. .incbin "mario.chr" ;includes 8KB graphics file from SMB1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement