Now that I know how to draw a sprite on the screen, as well as how to animate it in a simple way, My next goal is for FCEUX to respond to controls. I have not inserted any code related to the controller inputs; I'm simply giving the code for making the sprite appear:
What code should I add to enable the capability to control the sprite looking like a tongue face (:p)? I've heard something about register $4016, but whenever I press the assigned keys, nothing happens nor do the values change in the hex editor for that address. Can someone help me with this? Thanks!
P.S.
I've attached the "ball.chr" just in case anyone is interested.
Code:
.segment "HEADER"
.byte "NES"
.byte $1a
.byte $02
.byte $01
.byte %00000000
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00,$00,$00,$00,$00
.segment "STARTUP"
.segment "CODE"
WAITVBLANK:
:
BIT $2002
BPL :-
RTS
RESET:
SEI ; disable IRQs
CLD ; disable decimal mode
LDX #$40
STX $4017 ; disable APU frame IRQ
LDX #$FF
TXS ; Set up stack
INX ; now X = 0
STX $2000 ; disable NMI
STX $2001 ; disable rendering
STX $4010 ; disable DMC IRQs
JSR WAITVBLANK
clrmem:
LDA #$00
STA $0000, x
STA $0100, x
STA $0200, x
STA $0400, x
STA $0500, x
STA $0600, x
STA $0700, x
STA $0300, x
INX
BNE clrmem
JSR WAITVBLANK
Main:
LDX #$00
JSR StartupSprite
JSR LoadSprite
LDA #%10010000
STA $2000
LDA #%00010000
STA $2001
Forever:
JMP Forever
StartupSprite:
LDA #$80 ;Y coordinate
STA $10
LDA #$80 ;X coordinate
STA $11
RTS
LoadSprite:
LoadSpritePalette:
LDA #$3F
STA $2006
LDA #$00
STA $2006
LDA #$0F
STA $2007
LDA #$28
STA $2007
LDA #$16
STA $2007
LoadSpriteProperties:
LDA $10
STA $0200
LDA #$20
STA $0201
LDA #$00
STA $0202
LDA $11
STA $0203
RTS
VBLANK: ;What should happen during a v-blank or nmi?
LDA #$00
STA $2003
LDA #$02
STA $4014
RTI
.segment "VECTORS"
.word VBLANK
.word RESET
.word 0
.segment "CHARS"
.incbin "ball.chr"
.byte "NES"
.byte $1a
.byte $02
.byte $01
.byte %00000000
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00,$00,$00,$00,$00
.segment "STARTUP"
.segment "CODE"
WAITVBLANK:
:
BIT $2002
BPL :-
RTS
RESET:
SEI ; disable IRQs
CLD ; disable decimal mode
LDX #$40
STX $4017 ; disable APU frame IRQ
LDX #$FF
TXS ; Set up stack
INX ; now X = 0
STX $2000 ; disable NMI
STX $2001 ; disable rendering
STX $4010 ; disable DMC IRQs
JSR WAITVBLANK
clrmem:
LDA #$00
STA $0000, x
STA $0100, x
STA $0200, x
STA $0400, x
STA $0500, x
STA $0600, x
STA $0700, x
STA $0300, x
INX
BNE clrmem
JSR WAITVBLANK
Main:
LDX #$00
JSR StartupSprite
JSR LoadSprite
LDA #%10010000
STA $2000
LDA #%00010000
STA $2001
Forever:
JMP Forever
StartupSprite:
LDA #$80 ;Y coordinate
STA $10
LDA #$80 ;X coordinate
STA $11
RTS
LoadSprite:
LoadSpritePalette:
LDA #$3F
STA $2006
LDA #$00
STA $2006
LDA #$0F
STA $2007
LDA #$28
STA $2007
LDA #$16
STA $2007
LoadSpriteProperties:
LDA $10
STA $0200
LDA #$20
STA $0201
LDA #$00
STA $0202
LDA $11
STA $0203
RTS
VBLANK: ;What should happen during a v-blank or nmi?
LDA #$00
STA $2003
LDA #$02
STA $4014
RTI
.segment "VECTORS"
.word VBLANK
.word RESET
.word 0
.segment "CHARS"
.incbin "ball.chr"
What code should I add to enable the capability to control the sprite looking like a tongue face (:p)? I've heard something about register $4016, but whenever I press the assigned keys, nothing happens nor do the values change in the hex editor for that address. Can someone help me with this? Thanks!
P.S.
I've attached the "ball.chr" just in case anyone is interested.