Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; // Summary
- ; // A Very Basic NES ROM that displays 1 color: Blue
- .segment "INESHDR"
- .byt "NES",$1A
- .byt 1 ; 1 x 16kB PRG block.
- .byt 1 ; 1 x 8kB CHR block.
- .segment "VECTORS"
- .addr nmi, reset, irq
- .segment "ZEROPAGE"
- retraces: .res 1
- ; Variables
- .segment "BSS"
- xframes: .res 1
- buttons: .res 1 ; Reserve 1 byte for storing the data read from controller.
- .segment "CODE"
- ; Procedures
- ; -----------------------------------------------------------------------------
- .proc reset
- ; Disable Interrupts
- SEI
- ; Basic Initialization
- LDX #0
- STX $2000 ; General init state; NMIs (bit 7) disabled.
- STX $2001 ; Disable rendering, i.e. turn off background & sprites.
- ; PPU Warmup (29658 Cycles)
- BIT $2002 ; Clear the VPL Flag if it was set at reset time.
- vwait1:
- BIT $2002 ; 27384 Cycles has passed.
- BPL vwait1
- vwait2:
- BIT $2002 ; 57165 Cycles has passed.
- BPL vwait2
- ; Clear lingering interrupts since before reset.
- ; BIT $2002 ; Ack VBLANK NMI (if one was left over after reset); bit 7.
- LDA #%00100000 ; Intensify reds
- STA $2001
- LDA #%10000000
- STA $2000
- waitfora:
- ; call subroutine to read current button state
- JSR readjoy
- ; check if bit 7 of buttons is set
- LDA #$80
- BIT buttons
- ; if not, loop to wait
- BNE waitfora
- LDA #%01000000 ; Intensify greens
- STA $2001
- LDA #%10000000
- STA $2000
- LDX #30
- JSR waitxframes
- LDA #%10000000 ; Intensify blues
- STA $2001
- LDA #%10000000
- STA $2000
- LDX #30
- JSR waitxframes
- forever:
- JMP forever ; Infinite loop
- .endproc
- .proc readjoy
- LDA #$01
- STA $4016
- STA buttons ; We use our variable!
- LSR A
- STA $4016
- loop:
- LDA $4016
- LSR A ; Bit 0 -> Carry
- ROL buttons ; Carry -> Bit 0; Bit 7 -> Carry
- BCC loop ; Branch if Carry Clear
- RTS
- .endproc
- .proc nmi
- INC xframes
- RTI
- .endproc
- .proc irq
- RTI
- .endproc
- .proc waitxframes
- wait: ; Wait for a frame
- LDA xframes
- waitonce:
- CMP xframes
- BEQ waitonce
- DEX ; X = X - 1
- BNE wait ; if X is not zero, keep going...
- RTS
- .endproc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement