daily pastebin goal
13%
SHARE
TWEET

Untitled

a guest Feb 7th, 2016 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;       ----------------------------------------------------
  2.  
  3. ;    galleryNES - version 0.1
  4. ;    Copyright 2009 Don Miller
  5. ;    For more information, visit: http://www.no-carrier.com
  6.  
  7. ;    This program is free software: you can redistribute it and/or modify
  8. ;    it under the terms of the GNU General Public License as published by
  9. ;    the Free Software Foundation, either version 3 of the License, or
  10. ;    (at your option) any later version.
  11.  
  12. ;    This program is distributed in the hope that it will be useful,
  13. ;    but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. ;    GNU General Public License for more details.
  16.  
  17. ;    You should have received a copy of the GNU General Public License
  18. ;    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  19.  
  20. ;       ----------------------------------------------------
  21.  
  22. NewButtons = $41
  23. OldButtons = $42
  24. JustPressed = $43
  25. ScreenNumber = $44
  26. OldScreen = $45
  27. PaletteNumber = $46
  28.  
  29. ;       ----------------------------------------------------
  30.  
  31.         .ORG $7ff0
  32. Header:                         ; 16 byte .NES header (iNES format)
  33.     .DB "NES", $1a
  34.     .DB $02                 ; size of PRG ROM in 16kb units
  35.     .DB $01         ; size of CHR ROM in 8kb units
  36.     .DB #%00000000      ; mapper 0
  37.     .DB #%00000000      ; mapper 0
  38.         .DB $00
  39.         .DB $00
  40.         .DB $00
  41.         .DB $00
  42.         .DB $00
  43.         .DB $00
  44.         .DB $00
  45.         .DB $00
  46.  
  47.         .ORG $8000
  48.  
  49. ;       ----------------------------------------------------
  50.  
  51. Reset:                          ; reset routine
  52.         SEI
  53.         CLD
  54.     LDX #$00
  55.     STX $2000
  56.     STX $2001
  57.     DEX
  58.     TXS
  59.     LDX #0
  60.     TXA
  61. ClearMemory:
  62.     STA 0, X
  63.     STA $100, X
  64.     STA $200, X
  65.     STA $300, X
  66.     STA $400, X
  67.     STA $500, X
  68.     STA $600, X
  69.     STA $700, X
  70.         STA $800, X
  71.         STA $900, X
  72.         INX
  73.     BNE ClearMemory
  74.  
  75. ;       ----------------------------------------------------
  76.  
  77.         LDA #$00                ; setting up variables
  78.         STA ScreenNumber
  79.         STA PaletteNumber
  80.  
  81. ;       ----------------------------------------------------
  82.  
  83.     LDX #$02                ; warm up
  84. WarmUp:
  85.     BIT $2002
  86.     BPL WarmUp
  87.     DEX
  88.     BNE WarmUp
  89.  
  90.         LDA #$3F
  91.     STA $2006
  92.     LDA #$00
  93.     STA $2006
  94.         TAX
  95. LoadPal:                        ; load palette
  96.         LDA palette, x
  97.         STA $2007
  98.         INX
  99.         CPX #$10
  100.         BNE LoadPal
  101.  
  102.     LDA #$20
  103.     STA $2006
  104.     LDA #$00
  105.     STA $2006
  106.  
  107.     LDY #$04                ; clear nametables
  108. ClearName:
  109.     LDX #$00
  110.     LDA #$00
  111. PPULoop:
  112.     STA $2007
  113.     DEX
  114.     BNE PPULoop
  115.  
  116.     DEY
  117.     BNE ClearName
  118.  
  119. ;       ----------------------------------------------------
  120.  
  121.         LDA #<pic0              ; load low byte of first picture
  122.         STA $10
  123.  
  124.         LDA #>pic0              ; load high byte of first picture
  125.         STA $11
  126.  
  127. ;       ----------------------------------------------------
  128.  
  129.         JSR DrawScreen          ; draw initial nametable
  130.         JSR Vblank              ; turn on screen
  131.  
  132. ;       ----------------------------------------------------
  133.  
  134. InfLoop:                        ; loop forever, program now controlled by NMI routine
  135.  
  136.         JMP InfLoop
  137.  
  138. ;       ----------------------------------------------------
  139.  
  140. LoadNewPalette:
  141.         LDX PaletteNumber       ; load palette lookup value
  142.         LDY #$00
  143.         LDA #$3F
  144.     STA $2006
  145.     LDA #$00
  146.     STA $2006
  147. LoadNewPal:                     ; load palette
  148.         LDA palette, x
  149.         STA $2007
  150.         INX
  151.         INY
  152.         CPY #$10
  153.         BNE LoadNewPal
  154.         RTS
  155.  
  156. ;       ----------------------------------------------------
  157.  
  158. DrawScreen:
  159.  
  160.     LDA #$20                ; set to beginning of first nametable
  161.         STA $2006
  162.         LDA #$00
  163.         STA $2006
  164.  
  165.         LDY #$00
  166.         LDX #$04
  167.  
  168. NameLoop:                       ; loop to draw entire nametable
  169.         LDA ($10),y
  170.         STA $2007
  171.         INY
  172.         BNE NameLoop
  173.         INC $11
  174.         DEX
  175.         BNE NameLoop
  176.  
  177.         RTS
  178.  
  179. ;       ----------------------------------------------------
  180.  
  181. Vblank:                         ; turn on the screen and start the party
  182.     BIT $2002
  183.     BPL Vblank
  184.  
  185.         LDX #$00
  186.         STX $2005
  187.         STX $2005
  188.  
  189.     LDA #%10001000
  190.     STA $2000
  191.         LDA #%00001110
  192.     STA $2001
  193.  
  194.         RTS
  195.  
  196. ;       ----------------------------------------------------
  197.  
  198. LoadScreen:
  199.  
  200.         LDA #%00000000          ; disable NMI's and screen display
  201.     STA $2000
  202.     LDA #%00000000
  203.     STA $2001
  204.  
  205.         LDA ScreenNumber
  206.  
  207. Test0:
  208.         CMP #0                  ; compare ScreenNumber to find out which picture / palette to load
  209.         BNE Test1
  210.         LDA #<pic0              ; load low byte of picture
  211.         STA $10
  212.         LDA #>pic0              ; load high byte of picture
  213.         STA $11
  214.         LDA #$00
  215.         STA PaletteNumber       ; set palette lookup location
  216.         RTS
  217.  
  218. Test1:
  219.         CMP #1
  220.         BNE Test2
  221.         LDA #<pic1
  222.         STA $10
  223.         LDA #>pic1
  224.         STA $11
  225.         LDA #$10
  226.         STA PaletteNumber
  227.         RTS
  228.  
  229. Test2:
  230.         CMP #2
  231.         BNE Test3
  232.         LDA #<pic2
  233.         STA $10
  234.         LDA #>pic2
  235.         STA $11
  236.         LDA #$20
  237.         STA PaletteNumber
  238.         RTS
  239.  
  240. Test3:
  241.         CMP #3
  242.         BNE Test4
  243.         LDA #<pic3
  244.         STA $10
  245.         LDA #>pic3
  246.         STA $11
  247.         LDA #$30
  248.         STA PaletteNumber
  249.         RTS
  250.  
  251. Test4:
  252.         CMP #4
  253.         BNE Test5
  254.         LDA #<pic4
  255.         STA $10
  256.         LDA #>pic4
  257.         STA $11
  258.         LDA #$40
  259.         STA PaletteNumber
  260.         RTS
  261.  
  262. Test5:
  263.         CMP #5
  264.         BNE Test6
  265.         LDA #<pic5
  266.         STA $10
  267.         LDA #>pic5
  268.         STA $11
  269.         LDA #$50
  270.         STA PaletteNumber
  271.         RTS
  272.  
  273. Test6:
  274.         CMP #6
  275.         BNE Test7
  276.         LDA #<pic6
  277.         STA $10
  278.         LDA #>pic6
  279.         STA $11
  280.         LDA #$60
  281.         STA PaletteNumber
  282.         RTS
  283.  
  284. Test7:
  285.         CMP #7
  286.         BNE Test8
  287.         LDA #<pic7
  288.         STA $10
  289.         LDA #>pic7
  290.         STA $11
  291.         LDA #$70
  292.         STA PaletteNumber
  293.         RTS
  294.  
  295. Test8:
  296.         CMP #8
  297.         BNE Test9
  298.         LDA #<pic8
  299.         STA $10
  300.         LDA #>pic8
  301.         STA $11
  302.         LDA #$80
  303.         STA PaletteNumber
  304.         RTS
  305.  
  306. Test9:
  307.         LDA #<pic9
  308.         STA $10
  309.         LDA #>pic9
  310.         STA $11
  311.         LDA #$90
  312.         STA PaletteNumber
  313.         RTS
  314.  
  315. ;       ----------------------------------------------------
  316.  
  317. ControllerTest:
  318.  
  319.         LDA NewButtons
  320.     STA OldButtons
  321.  
  322.         LDX #$00
  323.     LDA #$01        ; strobe joypad
  324.     STA $4016
  325.     LDA #$00
  326.     STA $4016
  327. ConLoop:
  328.     LDA $4016       ; check the state of each button
  329.     LSR
  330.     ROR NewButtons
  331.         INX
  332.         CPX #$08
  333.         bne ConLoop
  334.  
  335.     LDA OldButtons          ; invert bits
  336.     EOR #$FF
  337.     AND NewButtons
  338.     STA JustPressed
  339.  
  340.     LDA ScreenNumber        ; save old screen number for later compare
  341.     STA OldScreen
  342.  
  343. CheckLeft:
  344.     LDA #%01000000
  345.     AND JustPressed
  346.     BEQ CheckRight
  347.  
  348.     DEC ScreenNumber        ; decrement screen number here
  349.         BPL CheckRight
  350.     LDA #9                  ; equal to total # of screens, starting from 0
  351.     STA ScreenNumber
  352.  
  353. CheckRight:
  354.     LDA #%10000000
  355.     AND JustPressed
  356.     BEQ EndDrawChk
  357.  
  358.     INC ScreenNumber        ; increment screen number here
  359.         LDA ScreenNumber
  360.     CMP #10                 ; equal to total # of screens +1, starting from 0
  361.     BNE EndDrawChk
  362.     LDA #0
  363.     STA ScreenNumber
  364.  
  365. EndDrawChk:
  366.     LDA ScreenNumber        ; has screen number changed? if not, skip redraw
  367.     CMP OldScreen
  368.     BEQ CheckOver
  369.  
  370.         JSR LoadScreen          ; turn off and load new screen data
  371.         JSR LoadNewPalette      ; load new palette
  372.         JSR DrawScreen          ; draw new screen
  373.         JSR Vblank              ; turn the screen back on
  374.  
  375. CheckOver:
  376.  
  377.         RTS
  378.  
  379. ;       ----------------------------------------------------
  380.  
  381. NMI:
  382.         JSR ControllerTest      ; check for user input
  383.  
  384.         RTI
  385. IRQ:
  386.         RTI
  387.  
  388. ;       ----------------------------------------------------
  389.  
  390. palette:                        ; palette data
  391.         .byte $0F,$00,$10,$30,$0F,$05,$26,$30,$0F,$13,$23,$33,$0F,$1C,$2B,$39 ; palette 0 - aligns with pic0.nam below
  392.         .byte $0F,$05,$15,$33,$0F,$26,$37,$30,$0F,$0B,$2B,$39,$0F,$02,$21,$3C ; palette 1 - alings with pic1.nam below
  393.         .byte $0F,$00,$10,$30,$0F,$05,$26,$30,$0F,$13,$23,$33,$0F,$1C,$2B,$39 ; palette 2 - aligns with you know what below...
  394.         .byte $0F,$00,$10,$30,$0F,$05,$26,$30,$0F,$13,$23,$33,$0F,$1C,$2B,$39 ; palette 3
  395.         .byte $0F,$00,$10,$30,$0F,$05,$26,$30,$0F,$13,$23,$33,$0F,$1C,$2B,$39 ; palette 4
  396.         .byte $0F,$00,$10,$30,$0F,$05,$26,$30,$0F,$13,$23,$33,$0F,$1C,$2B,$39 ; palette 5
  397.         .byte $0F,$00,$10,$30,$0F,$05,$26,$30,$0F,$13,$23,$33,$0F,$1C,$2B,$39 ; palette 6
  398.         .byte $0F,$00,$10,$30,$0F,$05,$26,$30,$0F,$13,$23,$33,$0F,$1C,$2B,$39 ; palette 7
  399.         .byte $0F,$00,$10,$30,$0F,$05,$26,$30,$0F,$13,$23,$33,$0F,$1C,$2B,$39 ; palette 8
  400.         .byte $0F,$00,$10,$30,$0F,$05,$26,$30,$0F,$13,$23,$33,$0F,$1C,$2B,$39 ; palette 9
  401.  
  402. ;       ----------------------------------------------------
  403.  
  404.                                 ; include picture data
  405.  
  406. pic0:
  407.         .INCBIN "pic0.nam"      ; Boring galleryNES 0.1 splash screen by NO CARRIER, 2009 - http://www.no-carrier.com
  408. pic1:
  409.         .INCBIN "pic1.nam"      ; Rhino (from 'Color Caves' album) by Alex Mauer - http://www.headlessbarbie.com
  410. pic2:
  411.         .INCBIN "pic2.nam"
  412. pic3:
  413.         .INCBIN "pic3.nam"
  414. pic4:
  415.         .INCBIN "pic4.nam"
  416. pic5:
  417.         .INCBIN "pic5.nam"
  418. pic6:
  419.         .INCBIN "pic6.nam"
  420. pic7:
  421.         .INCBIN "pic7.nam"
  422. pic8:
  423.         .INCBIN "pic8.nam"
  424. pic9:
  425.         .INCBIN "pic9.nam"
  426.  
  427. ;       ----------------------------------------------------
  428.  
  429.     .ORG $fffa              ; vectors
  430.     .DW NMI
  431.     .DW Reset
  432.     .DW IRQ
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top