Advertisement
Guest User

NES Random Letter Generator

a guest
Feb 8th, 2014
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.05 KB | None | 0 0
  1. .inesprg 1 ; 1x 16KB PRG code
  2. .ineschr 1 ; 1x 8KB CHR data
  3. .inesmap 0 ; mapper 0 = NROM, no bank swapping
  4. .inesmir 1 ; background mirroring
  5.  
  6. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7.  
  8. .rsset $0000
  9.  
  10. randomness .rs 1 ;randomness for the letters
  11. apressed .rs 1 ;is A pressed?
  12.  
  13. .bank 0
  14. .org $8000
  15.  
  16. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  17.  
  18. RESET:
  19. SEI ;Fuck IRQs
  20. CLD ;Decimals too! Fuck 'em
  21. LDX #$40
  22. STX $4017 ;APU frame IRQ! I said FUCK IRQs!!!
  23. LDX #$FF
  24. TXS ;Set up stack
  25. INX ;X register overflow, X=0
  26. STX $2000 ;no NMI for now
  27. STX $2001 ;No rendering for now
  28. STX $4010 ;Dang! DMC IRQs! y so many of 'em?
  29.  
  30. vblankwait1: ; First wait for vblank to make sure PPU is ready
  31. BIT $2002
  32. BPL vblankwait1
  33.  
  34. clrmem:
  35. LDA #$00
  36. STA $0000, x
  37. STA $0100, x
  38. STA $0300, x
  39. STA $0400, x
  40. STA $0500, x
  41. STA $0600, x
  42. STA $0700, x
  43. LDA #$FE
  44. STA $0200, x ;move all sprites off screen
  45. INX
  46. BNE clrmem
  47.  
  48. vblankwait2: ; Second wait for vblank, PPU is ready after this
  49. BIT $2002
  50. BPL vblankwait2
  51.  
  52. ;NES is ready now! LET'S DO THIS! (LEEEEEEEEEEEEEROOOOOOOOOOOY JJJJJJJJJJJENKINS!)
  53.  
  54. PalLoad:
  55. LDA $2002 ;PPU? r u there? We need to reset the HiLo latch!
  56. LDA #$3F ;Hi part of $3F00
  57. STA $2006
  58. LDA #$00 ;Lo part of it
  59. STA $2006
  60. LDX #$00
  61. PalLoop:
  62. LDA pal, x
  63. STA $2007 ;Load 'em palettes to PPU
  64. INX
  65. CPX #$20
  66. BNE PalLoop ;Advance only when all 32 palettes are copied!
  67.  
  68. LDA #$30
  69. STA randomness ;Put value 30 in randomness variable
  70.  
  71. LoadBG:
  72. LDA $2002
  73. LDA #$21 ;Write Hipart of $2100 to PPU
  74. STA $2006
  75. LDA #$00 ;Now Lopart
  76. STA $2006
  77. LDX #$00
  78. LoadBGLoop:
  79. LDA graphics, x ; load data from address (background + the value in x) (I hate typing, so I copypasted some NN code ;))
  80. STA $2007 ; write to PPU
  81. INX ; X = X + 1
  82. CPX #$00 ; Compare X to hex $00, decimal 00 - copying 256 bytes
  83. BNE LoadBGLoop ; Branch to LoadBackgroundLoop if compare was Not Equal to zero
  84. ; if compare was equal to 256, keep going down
  85.  
  86. LoadAttribute:
  87. LDA $2002 ; read PPU status to reset the high/low latch
  88. LDA #$23
  89. STA $2006 ; write the high byte of $23C0 address
  90. LDA #$C0
  91. STA $2006 ; write the low byte of $23C0 address
  92. LDX #$00 ; start out at 0
  93. LoadAttributeLoop:
  94. LDA attribute, x ; load data from address (attribute + the value in x)
  95. STA $2007 ; write to PPU
  96. INX ; X = X + 1
  97. CPX #$40 ; Compare X to hex $40, decimal 64 - copying 64 bytes
  98. BNE LoadAttributeLoop ; Branch to LoadAttributeLoop if compare was Not Equal to zero
  99. ; if compare was equal to 64, keep going down
  100.  
  101.  
  102. LDA #%10010000 ; enable NMI, sprites from Pattern Table 0, background from Pattern Table 1
  103. STA $2000
  104.  
  105. LDA #%00011110 ; enable sprites, enable background, no clipping on left side
  106. STA $2001
  107.  
  108. Forever:
  109. JMP Forever ;jump back to Forever, infinite loop
  110.  
  111.  
  112.  
  113. NMI:
  114. LDA #$00
  115. STA $2003 ; set the low byte (00) of the RAM address
  116. LDA #$02
  117. STA $4014 ; set the high byte (02) of the RAM address, start the transfer
  118.  
  119. INC randomness
  120. LDA randomness
  121. CMP #$40 ;Check if 40 (CHR value for the bottom part of the first row of letters)
  122. BEQ makeitfifty
  123. JMP fiftydone
  124. makeitfifty:
  125. LDA #$50 ;Speaks for itself -- goes to next row of letters!
  126. STA randomness
  127. fiftydone:
  128. LDA randomness
  129. CMP #$5A ;Got to Z?
  130. BEQ randreset
  131. JMP randresetted
  132. randreset:
  133. LDA #$30 ;Then reset it!
  134. STA randomness
  135. randresetted:
  136.  
  137. LatchController:
  138. LDA #$01
  139. STA $4016
  140. LDA #$00
  141. STA $4016 ; tell both the controllers to latch buttons
  142.  
  143. LDA $4016
  144. AND #%00000001
  145. BEQ AUnpressed
  146. LDA apressed
  147. CMP #$01 ;Is it pressed?
  148. BEQ ReadADone
  149. LDA $2002
  150. LDA #$21 ;Write Hipart of $21BC to PPU
  151. STA $2006
  152. LDA #$BC ;Now Lopart
  153. STA $2006
  154. LDA randomness
  155. STA $2007
  156. LDA $2002
  157. LDA #$21 ;Write Hipart of $21DC to PPU
  158. STA $2006
  159. LDA #$DC ;Now Lopart
  160. STA $2006
  161. LDA randomness
  162. CLC
  163. ADC #$10
  164. STA $2007
  165. LDA #$01
  166. STA apressed
  167. JMP ReadADone
  168. AUnpressed:
  169. LDA #$00
  170. STA apressed
  171. ReadADone:
  172.  
  173. ;;This is the PPU clean up section, so rendering the next frame starts properly.
  174. LDA #%10010000 ; enable NMI, sprites from Pattern Table 0, background from Pattern Table 1
  175. STA $2000
  176. LDA #%00011110 ; enable sprites, enable background, no clipping on left side
  177. STA $2001
  178. LDA #$00 ;;tell the ppu there is no background scrolling
  179. STA $2005
  180. STA $2005
  181.  
  182. RTI ; return from interrupt
  183.  
  184.  
  185. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  186.  
  187. .bank 1
  188. .org $E000
  189.  
  190. pal:
  191. .db $0F,$18,$28,$38,$0F,$08,$18,$28,$0F,$00,$10,$20,$0F,$15,$3B,$30
  192. .db $0F,$1A,$3B,$30,$0F,$08,$27,$37,$0F,$30,$28,$31,$0F,$00,$10,$20
  193.  
  194. graphics:
  195. .db $1C,$01,$02,$03,$04,$05,$06,$07,$08,$09,$0A,$FF,$FF,$FF,$FF,$FF ;;FG Soft logo top
  196. .db $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ;;
  197.  
  198. .db $10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$1A,$51,$30,$3D,$33,$3E ;;FG Middle,RLP top
  199. .db $3C,$FF,$3B,$34,$53,$53,$34,$51,$FF,$3F,$51,$3E,$36,$51,$30,$3C ;;
  200.  
  201. .db $20,$21,$22,$23,$24,$25,$26,$27,$28,$29,$2A,$61,$40,$4D,$43,$4E ;;FG Bottom, RLP bottom
  202. .db $4C,$FF,$4B,$44,$63,$63,$44,$61,$FF,$4F,$61,$4E,$46,$61,$40,$4C ;;
  203.  
  204. .db $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ;;NUFFIN
  205. .db $FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF ;;NUFFIN
  206.  
  207. .db $3F,$54,$52,$37,$FF,$30,$FF,$30,$3D,$33,$FF,$56,$30,$53,$32,$37 ;;Push A and watch the box
  208. .db $FF,$53,$37,$34,$FF,$31,$3E,$57,$FF,$FF,$FF,$0B,$0C,$0D,$FF,$FF ;;
  209.  
  210. .db $4F,$64,$62,$47,$FF,$40,$FF,$40,$4D,$43,$FF,$66,$40,$63,$42,$47 ;;Push A and watch the box
  211. .db $FF,$63,$47,$44,$FF,$41,$4E,$67,$FF,$FF,$FF,$1B,$FF,$1D,$FF,$FF ;;
  212.  
  213. .db $5A,$55,$34,$32,$53,$51,$34,$57,$5D,$73,$5B,$74,$74,$71,$FF,$30 ;;Copyright
  214. .db $3D,$33,$FF,$35,$36,$FF,$52,$3E,$35,$53,$FF,$1B,$FF,$1D,$FF,$FF ;;
  215.  
  216. .db $6A,$65,$44,$42,$63,$61,$44,$67,$6D,$83,$6B,$84,$84,$81,$FF,$40 ;;Copyright
  217. .db $4D,$43,$FF,$45,$46,$FF,$62,$4E,$45,$63,$FF,$2B,$2C,$2D,$FF,$FF ;;
  218.  
  219. attribute:
  220. .db $00,$00,$00,$00,$00,$00,$00,$00
  221. .db $00,$00,$00,$00,$00,$00,$00,$00
  222. .db $00,$00,$00,$00,$00,$00,$00,$00
  223. .db $00,$00,$00,$00,$00,$00,$00,$00
  224. .db $00,$00,$00,$00,$00,$00,$00,$00
  225. .db $00,$00,$00,$00,$00,$00,$00,$00
  226. .db $00,$00,$00,$00,$00,$00,$00,$00
  227. .db $00,$00,$00,$00,$00,$00,$00,$00
  228.  
  229.  
  230. .org $FFFA ;first of the three vectors starts here
  231. .dw NMI ;when an NMI happens (once per frame if enabled) the
  232. ;processor will jump to the label NMI:
  233. .dw RESET ;when the processor first turns on or is reset, it will jump
  234. ;to the label RESET:
  235. .dw 0 ;external interrupt IRQ is not used in this tutorial
  236.  
  237. ;;;;;;;;;;;;;;
  238.  
  239.  
  240. .bank 2
  241. .org $0000
  242. .incbin "randomletter.chr" ;includes 8KB graphics file for the game
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement