Advertisement
Guest User

Untitled

a guest
Nov 28th, 2016
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.67 KB | None | 0 0
  1. .enum $0000 ;;start variables at ram location 0
  2.  
  3. graphicslobyte .dsb 1
  4. graphicshibyte .dsb 1
  5. screennumber .dsb 1
  6. nametable .dsb 1
  7. framenumber .dsb 1
  8. framecounter .dsb 1
  9. picpointer .dsb 2
  10. ppuhibyte .dsb 1
  11. ppulobyte .dsb 1
  12. frameodd .dsb 1
  13.  
  14. .ende
  15. tilestowrite = $78
  16. maxframes = $08
  17.  
  18.  
  19. ; ----------------------------------------------------
  20.  
  21. .ORG $7ff0
  22. Header: ; 16 byte .NES header (iNES format)
  23. .DB "NES", $1a
  24. .DB $02 ; size of PRG ROM in 16kb units
  25. .DB $01 ; size of CHR ROM in 8kb units
  26. .DB #%00000001 ; mapper 0
  27. .DB #%00000000 ; mapper 0
  28. .DB $00
  29. .DB $00
  30. .DB $00
  31. .DB $00
  32. .DB $00
  33. .DB $00
  34. .DB $00
  35. .DB $00
  36.  
  37. .ORG $8000
  38.  
  39. ; ----------------------------------------------------
  40.  
  41. Reset: ; reset routine
  42. SEI
  43. CLD
  44. LDX #$00
  45. STX $2000
  46. STX $2001
  47. DEX
  48. TXS
  49. LDX #0
  50. TXA
  51. ClearMemory:
  52. sta 0, X
  53. sta $100, X
  54. sta $200, X
  55. sta $300, X
  56. sta $400, X
  57. sta $500, X
  58. sta $600, X
  59. sta $700, X
  60. sta $800, X
  61. sta $900, X
  62. INX
  63. BNE ClearMemory
  64.  
  65. ; ----------------------------------------------------
  66.  
  67. lda #$00 ; setting up variables
  68. sta screennumber
  69. sta nametable
  70. sta framecounter
  71. sta framenumber
  72. sta frameodd
  73.  
  74. lda #$01
  75. sta nametable
  76.  
  77. lda #$24
  78. sta ppuhibyte
  79. lda #$00
  80. sta ppulobyte
  81. ; ----------------------------------------------------
  82.  
  83. LDX #$02 ; warm up
  84. WarmUp:
  85. BIT $2002
  86. BPL WarmUp
  87. DEX
  88. BNE WarmUp
  89.  
  90. LDY #$04 ; clear nametables
  91. ClearName:
  92. LDX #$00
  93. lda #$00
  94. ppuloop:
  95. sta $2007
  96. DEX
  97. BNE ppuloop
  98.  
  99. DEY
  100. BNE ClearName
  101.  
  102. LoadnewPalette:
  103. LDX #$00 ; load palette lookup value
  104. LDY #$00
  105. lda #$3F
  106. sta $2006
  107. lda #$00
  108. sta $2006
  109. LoadPalette: ; load palette
  110. lda palette, x
  111. sta $2007
  112. INX
  113. INY
  114. CPY #$10
  115. BNE LoadPalette
  116.  
  117. jsr loadnewscreen
  118.  
  119. ; ----------------------------------------------------
  120.  
  121. jsr Vblank ; turn on screen
  122.  
  123. ; ----------------------------------------------------
  124.  
  125. InfLoop: ; loop forever, program now controlled by NMI routine
  126.  
  127. JMP InfLoop
  128.  
  129. ; ----------------------------------------------------
  130.  
  131. NMI:
  132.  
  133. pha ; ??? back up registers
  134.  
  135. ; jsr loadnewscreen
  136.  
  137. lda ppuhibyte ; load ppu hi - set as current name table for this frame
  138. sta $2006
  139. lda ppulobyte ; load ppu - set as current name table for this frame
  140. sta $2006
  141.  
  142. jsr writetiles
  143.  
  144. jsr incaddress ; set address to write tiles to
  145.  
  146. ; jsr animation
  147.  
  148.  
  149.  
  150.  
  151.  
  152. ; This is the PPU clean up section, so rendering the next frame starts properly.
  153. lda #$00
  154. sta $2006 ; clean up PPU address registers
  155. sta $2006
  156.  
  157. lda frameodd ; load either 4 or 0
  158. lsr ; move 4 down to 1
  159. lsr
  160. ora #$80 ; turn on bit 7 and leave bit 0 as is
  161. sta $2000
  162. LDA #%00011110
  163. STA $2001
  164.  
  165. lda #$00
  166. sta $2005 ; no horizontal scrolling
  167. sta $2005 ; no vertical scrolling
  168.  
  169. pla ; restore registers
  170.  
  171. RTI
  172. IRQ:
  173. RTI
  174.  
  175. ;-------------------------------------------------------------------------------------------
  176.  
  177. loadnewscreen:
  178.  
  179. lda #%00000000 ; disable NMI's and screen display
  180. sta $2000
  181. lda #%00000000
  182. sta $2001
  183.  
  184. lda screennumber ; load the screen number
  185. asl a ; x2 for word indexing
  186. tax ; use the game screen # as our index
  187. lda loadpic,x ; store the screennumber as a pointer.
  188. sta picpointer
  189. lda loadpic+1,x
  190. sta picpointer+1
  191. jmp (picpointer)
  192. rts ; back to normal program flow
  193.  
  194.  
  195. screen00:
  196. lda #<pic0 ; load low byte of picture
  197. sta graphicslobyte
  198. lda #>pic0 ; load high byte of picture
  199. sta graphicshibyte
  200. rts
  201.  
  202. screen01:
  203. lda #<pic1
  204. sta graphicslobyte
  205. lda #>pic1
  206. sta graphicshibyte
  207. rts
  208.  
  209. screen02:
  210. lda #<pic2
  211. sta graphicslobyte
  212. lda #>pic2
  213. sta graphicshibyte
  214. rts
  215.  
  216. screen03:
  217. lda #<pic3
  218. sta graphicslobyte
  219. lda #>pic3
  220. sta graphicshibyte
  221. rts
  222.  
  223. screen04:
  224. lda #<pic4
  225. sta graphicslobyte
  226. lda #>pic4
  227. sta graphicshibyte
  228. rts
  229.  
  230. screen05:
  231. lda #<pic5
  232. sta graphicslobyte
  233. lda #>pic5
  234. sta graphicshibyte
  235. rts
  236.  
  237. screen06:
  238. lda #<pic6
  239. sta graphicslobyte
  240. lda #>pic6
  241. sta graphicshibyte
  242. rts
  243.  
  244. screen07:
  245. lda #<pic7
  246. sta graphicslobyte
  247. lda #>pic7
  248. sta graphicshibyte
  249. rts
  250.  
  251. ;-------------------------------------------------------------------
  252.  
  253. animation:
  254.  
  255. inc screennumber
  256. lda screennumber
  257. cmp #08
  258. bne done
  259. lda #0
  260. sta screennumber
  261.  
  262. done:
  263. rts
  264.  
  265. incaddress:
  266.  
  267. lda #tilestowrite ; load the number of tiles to draw each frame
  268. clc ; clc for good adc
  269. adc ppulobyte ; add it to the current low ppu name table location
  270. sta ppulobyte ; save it
  271. lda #$00 ; empty accumulator - we only want to add the carry
  272. adc ppuhibyte ; if carry, it gets added to the name table address
  273. sta ppuhibyte ; save the result
  274.  
  275. lda ppuhibyte ; check ppuhibyte for the end of a name table block
  276. and #%11111011 ; test for $23 or $27 as upper PPU address (??)
  277. ; $23 - %00100011 , $27 - %00100111 (chops to 23)
  278. cmp #$23 ; if not 23, go to the notppu section
  279. bne notppuoverflow
  280. lda ppulobyte ; load ppulobyte
  281. cmp #$C0 ; equal to $C0? (192 - 2nd write to name table)
  282. bne notppuoverflow
  283.  
  284. lda #$20 ; (32 or %00100000)
  285. clc ; clear carry
  286. adc frameodd ; add the current frameodd to 32
  287. sta ppuhibyte ; save as the ppu hi address
  288. lda #$00 ; set ppu lo back to 00
  289. sta ppulobyte
  290.  
  291. inc framecounter
  292. lda #$04 ; %00000100 ; frameodd starts at zero at run time start
  293. ; the first time this executes, frameodd is set to ; 4 (due to bit flip below) the second time, it ; gets set to 0, 1st name table write is clearly to ; 2000 block in ppu, when 2300 is hit, the next ; write is to 2400 block and back and forth.
  294. eor frameodd ; exclusive or with frameodd (flips bit 2)
  295. sta frameodd ; save it
  296.  
  297.  
  298. notppuoverflow
  299. lda #tilestowrite ; 96 - number of tiles to write
  300. clc ; clc for good adc
  301. adc graphicslobyte ; add to the lo byte of the name table data pointer
  302. sta graphicslobyte
  303. lda #$00 ; 16bit Maths on the pointer.
  304. adc graphicshibyte
  305. sta graphicshibyte
  306.  
  307. ; this block prevents the pointer from running past the cmcmap data and into junk code - it resets the pointers after 32 name table swaps in the ppu
  308. lda framecounter ; what frame are we on?
  309. cmp #maxframes ; if it's been #maxframes, reset name table pointers
  310. bne animationnotfinished ; if not, this subroutine is done
  311. lda #<pic0 ; load low byte of picture
  312. sta graphicslobyte
  313. lda #>pic0 ; load high byte of picture
  314. sta graphicshibyte
  315. lda #$00
  316. sta framecounter ; reset the table counter
  317.  
  318. animationnotfinished
  319. rts
  320.  
  321. Vblank: ; turn on the screen
  322. BIT $2002
  323. BPL Vblank
  324.  
  325. LDX #$00
  326. STX $2005
  327. STX $2005
  328.  
  329.  
  330. lda #%10001000
  331. sta $2000
  332. lda #%00011110
  333. sta $2001
  334. rts
  335.  
  336. writetiles:
  337. ldx #tilestowrite
  338. LDY #$00
  339. tileloop: ; loop to write X tiles to nametable
  340. lda (graphicslobyte),y
  341. sta $2007
  342. INY
  343. dex
  344. BNE tileloop
  345. rts
  346.  
  347. ; ----------------------------------------------------
  348.  
  349. loadpic:
  350. .word screen00,screen01,screen02,screen03,screen04,screen05,screen06,screen07
  351.  
  352. palette: ; palette data
  353. .byte $0F,$f0,$f0,$f0,$0F,$30,$30,$30,$0F,$30,$30,$30,$0F,$30,$30,$30
  354.  
  355. ; ----------------------------------------------------
  356.  
  357.  
  358. ; include picture data
  359.  
  360. pic0:
  361. .INCBIN "pic0.nam"
  362. pic1:
  363. .INCBIN "pic1.nam"
  364. pic2:
  365. .INCBIN "pic2.nam"
  366. pic3:
  367. .INCBIN "pic3.nam"
  368. pic4:
  369. .INCBIN "pic4.nam"
  370. pic5:
  371. .INCBIN "pic5.nam"
  372. pic6:
  373. .INCBIN "pic6.nam"
  374. pic7:
  375. .INCBIN "pic7.nam"
  376.  
  377. ; ----------------------------------------------------
  378.  
  379.  
  380.  
  381. ; ----------------------------------------------------
  382.  
  383. .ORG $fffa ; vectors
  384. .DW NMI
  385. .DW Reset
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement