Hello,
I was the entire day on the IRC with people helping me to improve my code(adding DMA, NMI..., special thanks for jero32 and jsr), but now I want to have a background(thing that is very important to a game), then I've got a code like this:
And here are all the files used:
But when I emulate this I got a monochome background(because I don't have a pallete for it):
Then I want to know some simple things:
Best Regards,
Nathan Paulino Campos
I was the entire day on the IRC with people helping me to improve my code(adding DMA, NMI..., special thanks for jero32 and jsr), but now I want to have a background(thing that is very important to a game), then I've got a code like this:
Code:
.inesprg 1 ; 1 bank of code
.ineschr 1 ; 1 bank of spr/bkg data
.inesmir 1 ; something always 1
.inesmap 0 ; we use mapper 0
.bank 0 ; bank 0 - our place for code.
.org $0000
Sprite1_X .db 50 ; a X position for our sprite, start at 20
Sprite1_Y .db 20 ; a Y position for our sprite, start at 20
Sprite2_X .db 50 ; a X position for our sprite, start at 20
Sprite2_Y .db 20 ; a Y position for our sprite, start at 20
.org $8000 ; code starts at $8000
Start:
lda #%10001000 ; do the setup of PPU
sta $2000 ; that we
ldx #$00 ; clear X
lda #$3F ; have $2006 tell
sta $2006 ; $2007 to start
lda #$00 ; at $3F00 (pallete).
sta $2006
loadpal: ; this is a freaky loop
lda tilepal, x ; that gives 32 numbers
sta $2007 ; to $2007, ending when
inx ; X is 32, meaning we
cpx #32 ; are done.
bne loadpal ; if X isn't =32, goto "loadpal:" line.
lda #$20
sta $2006 ; give $2006 both parts of address $2020.
sta $2006
ldx #$00
loadNames:
lda ourMap, X ; load A with a byte from address (ourMap + X)
inx
sta $2007
cpx #64 ; map in previous section 64 bytes long
bne loadNames ; if not all 64 done, loop and do some more
waitblank1:
lda $2002 ; these 3 lines wait for VBlank, this loop will actually miss VBlank
bpl waitblank1 ; alot, in a later Day, I'll give a better way
txa
clrmem:
sta $000,x
sta $100,x
sta $200,x
sta $300,x
sta $400,x
sta $500,x
sta $600,x
sta $700,x ; Remove this if you're storing reset-persistent data
inx
bne clrmem
waitblank2:
lda $2002 ; these 3 lines wait for VBlank, this loop will actually miss VBlank
bpl waitblank2 ; alot, in a later Day, I'll give a better way
lda #%00011110
sta $2001
loop:
jmp loop
infinite: ; a label to start our infinite loop
nmi:
; Load Sprite1
lda Sprite1_Y
sta $0300
lda #$11
sta $0301
lda #$00
sta $0302
lda Sprite1_X
sta $0303
; Load Sprite2
lda Sprite2_Y
sta $0304
lda #$12
sta $0305
lda #$00
sta $0306
lda Sprite2_X
sta $0307
lda #$01 ; these
sta $4016 ; lines
lda #$00 ; setup/strobe the
sta $4016 ; keypad.
lda $4016 ; load Abutton Status ; note that whatever we ain't interested
lda $4016 ; load Bbutton Status ; in we just load so it'll go to the next one.
lda $4016 ; load Select button status
lda $4016 ; load Start button status
lda $4016 ; load UP button status
and #1 ; AND status with #1
bne UPKEYdown ; for some reason (not gonna reveal yet), need to use NotEquals
;with ANDs. So it'll jump (branch) if key was down.
lda $4016 ; load DOWN button status
and #1 ; AND status with #1
bne DOWNKEYdown
lda $4016 ; load LEFT button status
and #1 ; AND status with #1
bne LEFTKEYdown
lda $4016 ; load RIGHT button status
and #1 ; AND status with #1
bne RIGHTKEYdown
jmp NOTHINGdown ; if nothing was down, we just jump (no check for conditions)
; down past the rest of everything.
UPKEYdown:
lda Sprite1_Y ; load A with Y position
sbc #1 ; subtract 1 from A. Only can do math on A register. SBC (Subtract with Borrow)
sta Sprite1_Y ; store back to memory
lda Sprite2_Y ; load A with Y position
sbc #1 ; subtract 1 from A. Only can do math on A register. SBC (Subtract with Borrow)
sta Sprite2_Y ; store back to memory
jmp NOTHINGdown ; jump over the rest of the handling code.
DOWNKEYdown:
lda Sprite1_Y
adc #1 ; add 1 to A. ADC (Add with Carry)((to A register))
sta Sprite1_Y
jmp NOTHINGdown ; jump over the rest of handling code.
LEFTKEYdown:
lda Sprite1_X
sbc #1
sta Sprite1_X
jmp NOTHINGdown
;the left and right handling code does the same as UP and Down except.. well.. with
; left and right. :)
RIGHTKEYdown:
lda Sprite1_X
adc #1
sta Sprite1_X
; don't need to jump to NOTHINGdown, it's right below. Saved several bytes of
; PRG-Bank space! :)
NOTHINGdown:
lda #$03
sta $4014
rti
tilepal:
.incbin "our.pal" ; include and label our pallete
ourMap:
.incbin "our.map" ; assuming our.map is the binary map file.
.bank 1 ; following goes in bank 1
.org $FFFA ; start at $FFFA
.dw nmi ; dw stands for Define Word and we give 0 as address for NMI routine
.dw Start ; give address of start of our code for execution on reset of NES.
.dw 0 ; give 0 for address of VBlank interrupt handler, we tell PPU not to
; make an interrupt for VBlank.
.bank 2 ; switch to bank 2
.org $0000 ; start at $0000
.incbin "our.bkg" ; empty background first
.incbin "our.spr" ; our sprite pic data
.ineschr 1 ; 1 bank of spr/bkg data
.inesmir 1 ; something always 1
.inesmap 0 ; we use mapper 0
.bank 0 ; bank 0 - our place for code.
.org $0000
Sprite1_X .db 50 ; a X position for our sprite, start at 20
Sprite1_Y .db 20 ; a Y position for our sprite, start at 20
Sprite2_X .db 50 ; a X position for our sprite, start at 20
Sprite2_Y .db 20 ; a Y position for our sprite, start at 20
.org $8000 ; code starts at $8000
Start:
lda #%10001000 ; do the setup of PPU
sta $2000 ; that we
ldx #$00 ; clear X
lda #$3F ; have $2006 tell
sta $2006 ; $2007 to start
lda #$00 ; at $3F00 (pallete).
sta $2006
loadpal: ; this is a freaky loop
lda tilepal, x ; that gives 32 numbers
sta $2007 ; to $2007, ending when
inx ; X is 32, meaning we
cpx #32 ; are done.
bne loadpal ; if X isn't =32, goto "loadpal:" line.
lda #$20
sta $2006 ; give $2006 both parts of address $2020.
sta $2006
ldx #$00
loadNames:
lda ourMap, X ; load A with a byte from address (ourMap + X)
inx
sta $2007
cpx #64 ; map in previous section 64 bytes long
bne loadNames ; if not all 64 done, loop and do some more
waitblank1:
lda $2002 ; these 3 lines wait for VBlank, this loop will actually miss VBlank
bpl waitblank1 ; alot, in a later Day, I'll give a better way
txa
clrmem:
sta $000,x
sta $100,x
sta $200,x
sta $300,x
sta $400,x
sta $500,x
sta $600,x
sta $700,x ; Remove this if you're storing reset-persistent data
inx
bne clrmem
waitblank2:
lda $2002 ; these 3 lines wait for VBlank, this loop will actually miss VBlank
bpl waitblank2 ; alot, in a later Day, I'll give a better way
lda #%00011110
sta $2001
loop:
jmp loop
infinite: ; a label to start our infinite loop
nmi:
; Load Sprite1
lda Sprite1_Y
sta $0300
lda #$11
sta $0301
lda #$00
sta $0302
lda Sprite1_X
sta $0303
; Load Sprite2
lda Sprite2_Y
sta $0304
lda #$12
sta $0305
lda #$00
sta $0306
lda Sprite2_X
sta $0307
lda #$01 ; these
sta $4016 ; lines
lda #$00 ; setup/strobe the
sta $4016 ; keypad.
lda $4016 ; load Abutton Status ; note that whatever we ain't interested
lda $4016 ; load Bbutton Status ; in we just load so it'll go to the next one.
lda $4016 ; load Select button status
lda $4016 ; load Start button status
lda $4016 ; load UP button status
and #1 ; AND status with #1
bne UPKEYdown ; for some reason (not gonna reveal yet), need to use NotEquals
;with ANDs. So it'll jump (branch) if key was down.
lda $4016 ; load DOWN button status
and #1 ; AND status with #1
bne DOWNKEYdown
lda $4016 ; load LEFT button status
and #1 ; AND status with #1
bne LEFTKEYdown
lda $4016 ; load RIGHT button status
and #1 ; AND status with #1
bne RIGHTKEYdown
jmp NOTHINGdown ; if nothing was down, we just jump (no check for conditions)
; down past the rest of everything.
UPKEYdown:
lda Sprite1_Y ; load A with Y position
sbc #1 ; subtract 1 from A. Only can do math on A register. SBC (Subtract with Borrow)
sta Sprite1_Y ; store back to memory
lda Sprite2_Y ; load A with Y position
sbc #1 ; subtract 1 from A. Only can do math on A register. SBC (Subtract with Borrow)
sta Sprite2_Y ; store back to memory
jmp NOTHINGdown ; jump over the rest of the handling code.
DOWNKEYdown:
lda Sprite1_Y
adc #1 ; add 1 to A. ADC (Add with Carry)((to A register))
sta Sprite1_Y
jmp NOTHINGdown ; jump over the rest of handling code.
LEFTKEYdown:
lda Sprite1_X
sbc #1
sta Sprite1_X
jmp NOTHINGdown
;the left and right handling code does the same as UP and Down except.. well.. with
; left and right. :)
RIGHTKEYdown:
lda Sprite1_X
adc #1
sta Sprite1_X
; don't need to jump to NOTHINGdown, it's right below. Saved several bytes of
; PRG-Bank space! :)
NOTHINGdown:
lda #$03
sta $4014
rti
tilepal:
.incbin "our.pal" ; include and label our pallete
ourMap:
.incbin "our.map" ; assuming our.map is the binary map file.
.bank 1 ; following goes in bank 1
.org $FFFA ; start at $FFFA
.dw nmi ; dw stands for Define Word and we give 0 as address for NMI routine
.dw Start ; give address of start of our code for execution on reset of NES.
.dw 0 ; give 0 for address of VBlank interrupt handler, we tell PPU not to
; make an interrupt for VBlank.
.bank 2 ; switch to bank 2
.org $0000 ; start at $0000
.incbin "our.bkg" ; empty background first
.incbin "our.spr" ; our sprite pic data
And here are all the files used:
But when I emulate this I got a monochome background(because I don't have a pallete for it):
Then I want to know some simple things:
- What is the simplest way to define a pallete for the background?
- How can I arrange the background to have a smile(of 4 tiles) that isn't tiled(repeated line by line)?
Best Regards,
Nathan Paulino Campos