; ----------------------------------------------------
; logoNES - version 0.1
; Copyright 2010 Don Miller
; For more information, visit: http://www.no-carrier.com
; This program is free software: you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation, either version 3 of the License, or
; (at your option) any later version.
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
; You should have received a copy of the GNU General Public License
; along with this program. If not, see <http://www.gnu.org/licenses/>.
; ----------------------------------------------------
NewButtons = $41
OldButtons = $42
JustPressed = $43
ScreenNumber = $44
OldScreen = $45
PaletteNumber = $46
scroll_h = $c0
scroll_v = $c4
scroll_dir = $d0
cc_toggle = $d1
PalNumber = $d2
PalCounter =$d3
Color0 = $d4
Color1 = $d5
Color2 = $d6
Color3 = $d7
animation_timer = $d8
animation_on_off = $d9
; ----------------------------------------------------
.ORG $7ff0
Header: ; 16 byte .NES header (iNES format)
.DB "NES", $1a
.DB $02 ; size of PRG ROM in 16kb units
.DB $01 ; size of CHR ROM in 8kb units
.DB #%00000000 ; mapper 0
.DB #%00000000 ; mapper 0
.DB $00
.DB $00
.DB $00
.DB $00
.DB $00
.DB $00
.DB $00
.DB $00
.ORG $8000
; ----------------------------------------------------
Reset: ; reset routine
SEI
CLD
LDX #$00
STX $2000
STX $2001
DEX
TXS
LDX #0
TXA
ClearMemory:
STA 0, X
STA $100, X
STA $200, X
STA $300, X
STA $400, X
STA $500, X
STA $600, X
STA $700, X
STA $800, X
STA $900, X
INX
BNE ClearMemory
; ----------------------------------------------------
LDA #$00 ; setting up variables
STA ScreenNumber
STA PaletteNumber
sta scroll_h
sta scroll_v
sta scroll_dir
sta cc_toggle
LDA #$FF
sta animation_timer
LDA #$00
sta animation_on_off
lda #6 ; lower this number to increase
sta PalNumber ; the speed of the color cycle
sta PalCounter
lda #$01 ; these are the 4 colors
sta Color0 ; that will cycle when you
lda #$11 ; hit the "start" button
sta Color1
lda #$21
sta Color2
lda #$31
sta Color3
; ----------------------------------------------------
LDX #$02 ; warm up
WarmUp:
BIT $2002
BPL WarmUp
DEX
BNE WarmUp
LDA #$3F
STA $2006
LDA #$00
STA $2006
TAX
LoadPal: ; load palette
LDA palette, x
STA $2007
INX
CPX #$10
BNE LoadPal
LDA #$20
STA $2006
LDA #$00
STA $2006
LDY #$04 ; clear nametables
ClearName:
LDX #$00
LDA #$00
PPULoop:
STA $2007
DEX
BNE PPULoop
DEY
BNE ClearName
; ----------------------------------------------------
LDA #<pic0 ; load low byte of first picture
STA $10
LDA #>pic0 ; load high byte of first picture
STA $11
; ----------------------------------------------------
JSR DrawScreen ; draw initial nametable
JSR LoadScreen
JSR DrawScreen2 ; draw initial nametable
JSR Vblank ; turn on screen
; ----------------------------------------------------
InfLoop: ; loop forever, program now controlled by NMI routine
JMP InfLoop
; ----------------------------------------------------
LoadNewPalette:
LDX PaletteNumber ; load palette lookup value
LDY #$00
LDA #$3F
STA $2006
LDA #$00
STA $2006
LoadNewPal: ; load palette
LDA palette, x
STA $2007
INX
INY
CPY #$10
BNE LoadNewPal
RTS
; ----------------------------------------------------
DrawScreen:
LDA #$20 ; set to beginning of first nametable
STA $2006
LDA #$00
STA $2006
LDY #$00
LDX #$04
NameLoop: ; loop to draw entire nametable
LDA ($10),y
STA $2007
INY
BNE NameLoop
INC $11
DEX
BNE NameLoop
RTS
; ----------------------------------------------------
DrawScreen2:
LDA #$28 ; set to beginning of first nametable
STA $2006
LDA #$00
STA $2006
LDY #$00
LDX #$04
NameLoop2: ; loop to draw entire nametable
LDA ($10),y
STA $2007
INY
BNE NameLoop2
INC $11
DEX
BNE NameLoop2
RTS
; ----------------------------------------------------
Vblank: ; turn on the screen and start the party
BIT $2002
BPL Vblank
LDX scroll_h
STX $2005
LDX scroll_v
STX $2005
LDA #%10001000
STA $2000
LDA #%00001110
STA $2001
RTS
; ----------------------------------------------------
LoadScreen:
LDA #%00000000 ; disable NMI's and screen display
STA $2000
LDA #%00000000
STA $2001
LDA ScreenNumber
Test0:
CMP #0 ; compare ScreenNumber to find out which picture / palette to load
BNE Test1
LDA #<pic0 ; load low byte of picture
STA $10
LDA #>pic0 ; load high byte of picture
STA $11
LDA #$00
STA PaletteNumber ; set palette lookup location
RTS
Test1:
CMP #1
BNE Test2
LDA #<pic1
STA $10
LDA #>pic1
STA $11
LDA #$10
STA PaletteNumber
RTS
Test2:
CMP #2
BNE Test3
LDA #<pic2
STA $10
LDA #>pic2
STA $11
LDA #$20
STA PaletteNumber
RTS
Test3:
CMP #3
BNE Test4
LDA #<pic3
STA $10
LDA #>pic3
STA $11
LDA #$30
STA PaletteNumber
RTS
Test4:
CMP #4
BNE Test5
LDA #<pic4
STA $10
LDA #>pic4
STA $11
LDA #$40
STA PaletteNumber
RTS
Test5:
CMP #5
BNE Test6
LDA #<pic5
STA $10
LDA #>pic5
STA $11
LDA #$50
STA PaletteNumber
RTS
Test6:
CMP #6
BNE Test7
LDA #<pic6
STA $10
LDA #>pic6
STA $11
LDA #$60
STA PaletteNumber
RTS
Test7:
CMP #7
BNE Test8
LDA #<pic7
STA $10
LDA #>pic7
STA $11
LDA #$70
STA PaletteNumber
RTS
Test8:
CMP #8
BNE Test9
LDA #<pic8
STA $10
LDA #>pic8
STA $11
LDA #$80
STA PaletteNumber
RTS
Test9:
LDA #<pic9
STA $10
LDA #>pic9
STA $11
LDA #$90
STA PaletteNumber
RTS
; ----------------------------------------------------
ControllerTest:
LDA NewButtons
STA OldButtons
LDX #$00
LDA #$01 ; strobe joypad
STA $4016
LDA #$00
STA $4016
ConLoop:
LDA $4016 ; check the state of each button
LSR
ROR NewButtons
INX
CPX #$08
bne ConLoop
LDA OldButtons ; invert bits
EOR #$FF
AND NewButtons
STA JustPressed
;button ( 0 0 0 0 0 0 0 0 )
;layout ( R L D U St Sl B A )
CheckSelect:
LDA #%00000100
AND OldButtons
BEQ CheckStart
lda #$00
sta scroll_dir ; stops scrolling
LDA #%00001000
AND JustPressed
BEQ CheckLeft
lda animation_on_off
eor #$01
sta animation_on_off ; toggles animation
jmp CheckLeft
CheckStart:
LDA #%00001000
AND JustPressed
BEQ CheckLeft
lda cc_toggle
eor #$01
sta cc_toggle ; toggles color cycling
CheckLeft:
LDA #%01000000
AND JustPressed
BEQ CheckRight
lda #3
sta scroll_dir ; scrolls left
CheckRight:
LDA #%10000000
AND JustPressed
BEQ CheckDown
lda #4
sta scroll_dir ; scrolls right
CheckDown:
LDA #%00100000
AND JustPressed
BEQ CheckUp
lda #2
sta scroll_dir ; scrolls down
CheckUp:
LDA #%00010000
AND JustPressed
BEQ CheckB
lda #1
sta scroll_dir ; scrolls up
CheckB:
LDA #%00000010
AND JustPressed
BEQ CheckA
DEC ScreenNumber ; decrement screen number here
BPL CheckA
LDA #9 ; equal to total # of screens, starting from 0
STA ScreenNumber
CheckA:
LDA #%00000001
AND JustPressed
BEQ EndDrawChk
INC ScreenNumber ; increment screen number here
LDA ScreenNumber
CMP #10 ; equal to total # of screens +1, starting from 0
BNE EndDrawChk
LDA #0
STA ScreenNumber
EndDrawChk:
LDA ScreenNumber ; has screen number changed? if not, skip redraw
CMP OldScreen
BEQ CheckOver
JSR LoadScreen ; turn off and load new screen data
JSR LoadNewPalette ; load new palette
JSR DrawScreen ; draw new screen
JSR LoadScreen ; turn off and load new screen data
JSR DrawScreen2 ; draw new screen
JSR Vblank ; turn the screen back on
CheckOver:
RTS
; ----------------------------------------------------
ScrollCheck:
LDA scroll_dir
ScrollUp:
CMP #1
BNE ScrollDown
INC scroll_v
lda scroll_v
cmp #240
bne ScrollOver
lda #0
sta scroll_v
JMP ScrollOver
ScrollDown:
CMP #2
BNE ScrollLeft
DEC scroll_v
LDA scroll_v
cmp #255
bne ScrollOver
lda #239
sta scroll_v
JMP ScrollOver
ScrollLeft:
CMP #3
BNE ScrollRight
INC scroll_h
JMP ScrollOver
ScrollRight:
DEC scroll_h
ScrollOver:
JMP Scroll_Done
; ----------------------------------------------------
color_cycle:
DEC PalCounter ; decrement counter, skip if not 0
BNE NoCycling
LDA Color3 ; rotate the color values
LDX Color0
STA Color0
LDA Color1
STX Color1
LDX Color2
STA Color2
STX Color3
LDA #$3F ; point to palette, the last three values of
STA $2006 ; the fourth background palette - does not
LDA #$0d ; overwrite color zero (see readme.txt)
STA $2006
LDA Color1 ; write the rotated palette to the PPU
STA $2007
LDA Color2
STA $2007
LDA Color3
STA $2007
LDA PalNumber
STA PalCounter
NoCycling:
jmp cc_over
; ----------------------------------------------------
NMI:
LDA ScreenNumber ; save old screen number for later compare
STA OldScreen
lda animation_on_off
cmp #$00
beq more_nmi_stuff
inc animation_timer
lda animation_timer
cmp #$20 ; change this number to change the speed of the animation
bne more_nmi_stuff
lda #0
sta animation_timer
inc ScreenNumber
lda ScreenNumber
cmp #10
bne more_nmi_stuff
lda #0
sta ScreenNumber
more_nmi_stuff:
JSR ControllerTest ; check for user input
lda cc_toggle
beq no_cc
jmp color_cycle
no_cc:
JSR LoadNewPalette
cc_over:
LDA scroll_dir
cmp #$00
BEQ Scroll_Done
jmp ScrollCheck
Scroll_Done:
lda scroll_h
sta $2005
lda scroll_v
sta $2005
RTI
IRQ:
RTI
; ----------------------------------------------------
palette: ; palette data
.byte $0F,$00,$10,$30,$0F,$05,$26,$30,$0F,$13,$23,$33,$0F,$01,$11,$21 ; palette 0 - aligns with pic0.nam below
.byte $0F,$00,$10,$30,$0F,$05,$26,$30,$0F,$13,$23,$33,$0F,$1C,$2B,$39 ; palette 1 - alings with pic1.nam below
.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...
.byte $0F,$00,$10,$30,$0F,$05,$26,$30,$0F,$13,$23,$33,$0F,$1C,$2B,$39 ; palette 3
.byte $0F,$00,$10,$30,$0F,$05,$26,$30,$0F,$13,$23,$33,$0F,$1C,$2B,$39 ; palette 4
.byte $0F,$00,$10,$30,$0F,$05,$26,$30,$0F,$13,$23,$33,$0F,$1C,$2B,$39 ; palette 5
.byte $0F,$00,$10,$30,$0F,$05,$26,$30,$0F,$13,$23,$33,$0F,$1C,$2B,$39 ; palette 6
.byte $0F,$00,$10,$30,$0F,$05,$26,$30,$0F,$13,$23,$33,$0F,$1C,$2B,$39 ; palette 7
.byte $0F,$00,$10,$30,$0F,$05,$26,$30,$0F,$13,$23,$33,$0F,$1C,$2B,$39 ; palette 8
.byte $0F,$00,$10,$30,$0F,$05,$26,$30,$0F,$13,$23,$33,$0F,$1C,$2B,$39 ; palette 9
; ----------------------------------------------------
; include picture data
pic0:
.INCBIN "pic0.nam" ; logoNES 0.1 splash screen by enso, 2009 - http://enso.tumblr.com
pic1:
.INCBIN "pic1.nam"
pic2:
.INCBIN "pic2.nam"
pic3:
.INCBIN "pic3.nam"
pic4:
.INCBIN "pic4.nam"
pic5:
.INCBIN "pic5.nam"
pic6:
.INCBIN "pic6.nam"
pic7:
.INCBIN "pic7.nam"
pic8:
.INCBIN "pic8.nam"
pic9:
.INCBIN "pic9.nam"
; ----------------------------------------------------
.ORG $fffa ; vectors
.DW NMI
.DW Reset
.DW IRQ