Hello,
I'm using a background, but I want to use a different pallete for it, because at the time I only have one pallete assigned, but on the source folder I have another one called bkg.pal, that is a pallete for the background. But my code is like this now:
Then I want to know how can I assign a pallete only for the background.
Best Regards,
Nathan Paulino Campos
I'm using a background, but I want to use a different pallete for it, because at the time I only have one pallete assigned, but on the source folder I have another one called bkg.pal, that is a pallete for the background. But my code is like this now:
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
addrLO = $10
addrHI = $11
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
Map_Load:
LDA $2002 ; read PPU status to reset the high/low latch
LDA #$20
STA $2006 ; write the high byte of $2000 address
LDA #$00
STA $2006 ; write the low byte of $2000 address
lda #low(ourMap)
sta addrLO
lda #high(ourMap) ; start out at 0
sta addrHI
ldx #4
ldy #0
Map_Load_loop:
LDA [addrLO], y ; load data from address (background + the value in x)
STA $2007 ; write to PPU
INy ; X = X + 1
BNE Map_Load_loop ; Branch to LoadBackgroundLoop if compare was Not Equal to zero
inc addrHI
dex
bne Map_Load_loop
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" ; background data
.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
addrLO = $10
addrHI = $11
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
Map_Load:
LDA $2002 ; read PPU status to reset the high/low latch
LDA #$20
STA $2006 ; write the high byte of $2000 address
LDA #$00
STA $2006 ; write the low byte of $2000 address
lda #low(ourMap)
sta addrLO
lda #high(ourMap) ; start out at 0
sta addrHI
ldx #4
ldy #0
Map_Load_loop:
LDA [addrLO], y ; load data from address (background + the value in x)
STA $2007 ; write to PPU
INy ; X = X + 1
BNE Map_Load_loop ; Branch to LoadBackgroundLoop if compare was Not Equal to zero
inc addrHI
dex
bne Map_Load_loop
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" ; background data
.incbin "our.spr" ; our sprite pic data
Then I want to know how can I assign a pallete only for the background.
Best Regards,
Nathan Paulino Campos