Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;----------------------------------------------------------------
- ; DEFINES
- ;----------------------------------------------------------------
- PPU_CTRL = $2000
- PPU_MASK = $2001
- PPU_STATUS = $2002
- PPU_OAM_ADDR = $2003
- PPU_OAM_DATA = $2004
- PPU_SCROLL = $2005
- PPU_ADDRESS = $2006
- PPU_DATA = $2007
- DMC_REG_1 = $4010
- PPU_OAM_DMA = $4014
- CONTROLLER_1 = $4016
- CONTROLLER_2 = $4017
- ;----------------------------------------------------------------
- ; constants
- ;----------------------------------------------------------------
- frameCounter = $0900
- playerSpeed = $0500
- PRG_COUNT = 1 ;1 = 16KB, 2 = 32KB
- MIRRORING = %0001 ;%0000 = horizontal, %0001 = vertical, %1000 = four-screen
- ;----------------------------------------------------------------
- ; variables
- ;----------------------------------------------------------------
- .enum $0000
- ;NOTE: declare variables using the DSB and DSW directives, like this:
- ;MyVariable0 .dsb 1
- ;MyVariable1 .dsb 3
- .ende
- ;NOTE: you can also split the variable declarations into individual pages, like this:
- ;.enum $0100
- ;.ende
- ;.enum $0200
- ;.ende
- ;----------------------------------------------------------------
- ; iNES header
- ;----------------------------------------------------------------
- .db "NES", $1a ;identification of the iNES header
- .db PRG_COUNT ;number of 16KB PRG-ROM pages
- .db $01 ;number of 8KB CHR-ROM pages
- .db $00|MIRRORING ;mapper 0 and mirroring
- .dsb 9, $00 ;clear the remaining bytes
- ;----------------------------------------------------------------
- ; program bank(s)
- ;----------------------------------------------------------------
- .base $10000-(PRG_COUNT*$4000)
- palettes:
- .db $0f,$00,$10,$30,$0f,$01,$12,$38,$0f,$04,$15,$26,$0f,$0f,$2d,$3d
- .db $0f,$00,$10,$30,$0f,$01,$12,$38,$0f,$04,$15,$26,$0f,$0f,$2d,$3d
- ; VERT-TILE-ATTR-HORIZ
- player_mSPRITE:
- .db $80, $00, $00, $80
- .db $80, $01, $00, $88
- .db $80, $02, $00, $90
- .db $88, $10, $00, $80
- .db $88, $11, $00, $88
- .db $88, $12, $00, $90
- Reset:
- SEI ;Disable IRQs
- CLD ;Disable Decimal mode
- LDX #$40 ;Hex for binary flag 0100 0000 which inhibits and clears the frame interrupt flag
- STX $4017 ;Disable Audio Processor frame IRQ
- LDX #$FF ;Load 255 to stack
- TXS ;-----------------
- INX ;Overflow X to 0
- STX PPU_CTRL ;Set PPU CTRL flags to 0
- STX PPU_MASK ;Set PPU Mask flags to 0
- STX DMC_REG_1 ;Set DMC flags to 0
- ;NOTE: initialization code goes here
- VBlankWait1:
- BIT PPU_STATUS
- BPL VBlankWait1
- ClearMemory:
- LDA #$00
- STA $0000, x ;Basically this clears out every RAM register by loading in 0
- STA $0100, x
- STA $0300, x
- STA $0400, x
- STA $0500, x
- STA $0600, x
- STA $0700, x
- LDA #$FE
- STA $0200, x
- INX
- BNE ClearMemory
- VBlankWait2:
- BIT PPU_STATUS
- BPL VBlankWait2
- ;This code tells the PPU to start accepting Background Palette data.
- InitPalettes:
- LDA PPU_STATUS ;Reads the PPU Status to reset the high/low latch
- LDA #$3F ;Write the high byte of the PPU address
- STA PPU_ADDRESS
- LDA #$00 ;Write the low byte of the PPU address
- STA PPU_ADDRESS
- LDX #$00
- LoadPalettes:
- LDA palettes, x ;Load the current index of the palette using X as the index number;
- STA PPU_DATA ;Write the current index to the PPU Memory;
- INX ;Increment the index
- CPX #$20 ;Compare the index against hex value 20(decimal: 32)
- BNE LoadPalettes;Continue the loop until the index until the index hits hex 20(decimal: 32)
- InitSprites:
- LDX #$00
- LoadSprites:
- LDA player_mSPRITE, x ;Same deal as the palette, but this time for the metasprite
- STA $0200, x ;Increment through each bit of RAM
- INX
- CPX #$18
- BNE LoadSprites
- PPUStart:
- LDA #%10000000
- STA PPU_CTRL
- LDA #%00010000
- STA PPU_MASK
- LDX #$00
- Update:
- JMP Update
- NMI:
- LDA #$00 ;OAM low read write address value
- STA PPU_OAM_ADDR;Set the low byte (00) of the RAM address
- LDA #$02 ;OAM high address value
- STA PPU_OAM_DMA ;Set the high byte (02) of the RAM address, start the transfer
- INC frameCounter
- ;NOTE: NMI code goes here
- LatchController:
- LDA #$01
- STA CONTROLLER_1
- LDA #$00
- STA CONTROLLER_1
- ;==================================
- ;READ A BUTTON
- ;==================================
- ReadContA:
- LDA CONTROLLER_1
- AND #%00000001
- BEQ ReadContADone
- ReadContADone:
- ;==================================
- ;READ B BUTTON
- ;==================================
- ReadContB:
- LDA CONTROLLER_1
- AND #%00000001
- BEQ ReadContBDone
- ReadContBDone:
- ;==================================
- ;READ SELECT BUTTON
- ;==================================
- ReadContSelect:
- LDA CONTROLLER_1
- AND #%00000001
- BEQ ReadContSelectDone
- ReadContSelectDone:
- ;==================================
- ;READ START BUTTON
- ;==================================
- ReadContStart:
- LDA CONTROLLER_1
- AND #%00000001
- BEQ ReadContStartDone
- ReadContStartDone:
- ;==================================
- ;READ UP BUTTON
- ;==================================
- ReadContUp:
- LDA CONTROLLER_1
- AND #%00000001
- BEQ ReadContUpDone
- ReadContUpDone:
- ;==================================
- ;READ DOWN BUTTON
- ;==================================
- ReadContDown:
- LDA CONTROLLER_1
- AND #%00000001
- BEQ ReadContDownDone
- ReadContDownDone:
- ;==================================
- ;READ LEFT BUTTON
- ;==================================
- ReadContLeft:
- LDA CONTROLLER_1
- AND #%00000001
- BEQ ReadContLeftDone
- LDA $0203
- SEC
- SBC #$01
- STA $0203
- LDA $0207
- SEC
- SBC #$01
- STA $0207
- LDA $020B
- SEC
- SBC #$01
- STA $020B
- LDA $020F
- SEC
- SBC #$01
- STA $020F
- ReadContLeftDone:
- ;==================================
- ;READ RIGHT BUTTON
- ;==================================
- ReadContRight:
- LDA CONTROLLER_1
- AND #%00000001
- BEQ ReadContRightDone
- LDA $0203
- CLC
- ADC #$01
- STA $0203
- LDA $0207
- CLC
- ADC #$01
- STA $0207
- LDA $020B
- CLC
- ADC #$01
- STA $020B
- LDA $020F
- CLC
- ADC #$01
- STA $020F
- ReadContRightDone:
- IRQ:
- ;NOTE: IRQ code goes here
- ;----------------------------------------------------------------
- ; interrupt vectors
- ;----------------------------------------------------------------
- .org $fffa
- .dw NMI
- .dw Reset
- .dw IRQ
- ;----------------------------------------------------------------
- ; CHR-ROM bank
- ;----------------------------------------------------------------
- .incbin "tiles.chr"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement