Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .enum $0000 ;;start variables at ram location 0
- graphicslobyte .dsb 1
- graphicshibyte .dsb 1
- screennumber .dsb 1
- nametable .dsb 1
- framenumber .dsb 1
- framecounter .dsb 1
- picpointer .dsb 2
- ppuhibyte .dsb 1
- ppulobyte .dsb 1
- frameodd .dsb 1
- .ende
- tilestowrite = $78
- maxframes = $08
- ; ----------------------------------------------------
- .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 #%00000001 ; 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 nametable
- sta framecounter
- sta framenumber
- sta frameodd
- lda #$01
- sta nametable
- lda #$24
- sta ppuhibyte
- lda #$00
- sta ppulobyte
- ; ----------------------------------------------------
- LDX #$02 ; warm up
- WarmUp:
- BIT $2002
- BPL WarmUp
- DEX
- BNE WarmUp
- LDY #$04 ; clear nametables
- ClearName:
- LDX #$00
- lda #$00
- ppuloop:
- sta $2007
- DEX
- BNE ppuloop
- DEY
- BNE ClearName
- LoadnewPalette:
- LDX #$00 ; load palette lookup value
- LDY #$00
- lda #$3F
- sta $2006
- lda #$00
- sta $2006
- LoadPalette: ; load palette
- lda palette, x
- sta $2007
- INX
- INY
- CPY #$10
- BNE LoadPalette
- jsr loadnewscreen
- ; ----------------------------------------------------
- jsr Vblank ; turn on screen
- ; ----------------------------------------------------
- InfLoop: ; loop forever, program now controlled by NMI routine
- JMP InfLoop
- ; ----------------------------------------------------
- NMI:
- pha ; ??? back up registers
- ; jsr loadnewscreen
- lda ppuhibyte ; load ppu hi - set as current name table for this frame
- sta $2006
- lda ppulobyte ; load ppu - set as current name table for this frame
- sta $2006
- jsr writetiles
- jsr incaddress ; set address to write tiles to
- ; jsr animation
- ; This is the PPU clean up section, so rendering the next frame starts properly.
- lda #$00
- sta $2006 ; clean up PPU address registers
- sta $2006
- lda frameodd ; load either 4 or 0
- lsr ; move 4 down to 1
- lsr
- ora #$80 ; turn on bit 7 and leave bit 0 as is
- sta $2000
- LDA #%00011110
- STA $2001
- lda #$00
- sta $2005 ; no horizontal scrolling
- sta $2005 ; no vertical scrolling
- pla ; restore registers
- RTI
- IRQ:
- RTI
- ;-------------------------------------------------------------------------------------------
- loadnewscreen:
- lda #%00000000 ; disable NMI's and screen display
- sta $2000
- lda #%00000000
- sta $2001
- lda screennumber ; load the screen number
- asl a ; x2 for word indexing
- tax ; use the game screen # as our index
- lda loadpic,x ; store the screennumber as a pointer.
- sta picpointer
- lda loadpic+1,x
- sta picpointer+1
- jmp (picpointer)
- rts ; back to normal program flow
- screen00:
- lda #<pic0 ; load low byte of picture
- sta graphicslobyte
- lda #>pic0 ; load high byte of picture
- sta graphicshibyte
- rts
- screen01:
- lda #<pic1
- sta graphicslobyte
- lda #>pic1
- sta graphicshibyte
- rts
- screen02:
- lda #<pic2
- sta graphicslobyte
- lda #>pic2
- sta graphicshibyte
- rts
- screen03:
- lda #<pic3
- sta graphicslobyte
- lda #>pic3
- sta graphicshibyte
- rts
- screen04:
- lda #<pic4
- sta graphicslobyte
- lda #>pic4
- sta graphicshibyte
- rts
- screen05:
- lda #<pic5
- sta graphicslobyte
- lda #>pic5
- sta graphicshibyte
- rts
- screen06:
- lda #<pic6
- sta graphicslobyte
- lda #>pic6
- sta graphicshibyte
- rts
- screen07:
- lda #<pic7
- sta graphicslobyte
- lda #>pic7
- sta graphicshibyte
- rts
- ;-------------------------------------------------------------------
- animation:
- inc screennumber
- lda screennumber
- cmp #08
- bne done
- lda #0
- sta screennumber
- done:
- rts
- incaddress:
- lda #tilestowrite ; load the number of tiles to draw each frame
- clc ; clc for good adc
- adc ppulobyte ; add it to the current low ppu name table location
- sta ppulobyte ; save it
- lda #$00 ; empty accumulator - we only want to add the carry
- adc ppuhibyte ; if carry, it gets added to the name table address
- sta ppuhibyte ; save the result
- lda ppuhibyte ; check ppuhibyte for the end of a name table block
- and #%11111011 ; test for $23 or $27 as upper PPU address (??)
- ; $23 - %00100011 , $27 - %00100111 (chops to 23)
- cmp #$23 ; if not 23, go to the notppu section
- bne notppuoverflow
- lda ppulobyte ; load ppulobyte
- cmp #$C0 ; equal to $C0? (192 - 2nd write to name table)
- bne notppuoverflow
- lda #$20 ; (32 or %00100000)
- clc ; clear carry
- adc frameodd ; add the current frameodd to 32
- sta ppuhibyte ; save as the ppu hi address
- lda #$00 ; set ppu lo back to 00
- sta ppulobyte
- inc framecounter
- lda #$04 ; %00000100 ; frameodd starts at zero at run time start
- ; 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.
- eor frameodd ; exclusive or with frameodd (flips bit 2)
- sta frameodd ; save it
- notppuoverflow
- lda #tilestowrite ; 96 - number of tiles to write
- clc ; clc for good adc
- adc graphicslobyte ; add to the lo byte of the name table data pointer
- sta graphicslobyte
- lda #$00 ; 16bit Maths on the pointer.
- adc graphicshibyte
- sta graphicshibyte
- ; 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
- lda framecounter ; what frame are we on?
- cmp #maxframes ; if it's been #maxframes, reset name table pointers
- bne animationnotfinished ; if not, this subroutine is done
- lda #<pic0 ; load low byte of picture
- sta graphicslobyte
- lda #>pic0 ; load high byte of picture
- sta graphicshibyte
- lda #$00
- sta framecounter ; reset the table counter
- animationnotfinished
- rts
- Vblank: ; turn on the screen
- BIT $2002
- BPL Vblank
- LDX #$00
- STX $2005
- STX $2005
- lda #%10001000
- sta $2000
- lda #%00011110
- sta $2001
- rts
- writetiles:
- ldx #tilestowrite
- LDY #$00
- tileloop: ; loop to write X tiles to nametable
- lda (graphicslobyte),y
- sta $2007
- INY
- dex
- BNE tileloop
- rts
- ; ----------------------------------------------------
- loadpic:
- .word screen00,screen01,screen02,screen03,screen04,screen05,screen06,screen07
- palette: ; palette data
- .byte $0F,$f0,$f0,$f0,$0F,$30,$30,$30,$0F,$30,$30,$30,$0F,$30,$30,$30
- ; ----------------------------------------------------
- ; include picture data
- pic0:
- .INCBIN "pic0.nam"
- 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"
- ; ----------------------------------------------------
- ; ----------------------------------------------------
- .ORG $fffa ; vectors
- .DW NMI
- .DW Reset
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement