Thank you, that is all helpful information!
Right now I'm trying to load the first 3 sprites for the background, I can't seem to figure out why it won't load the palette info and the right background sprites? I keep getting this image below - which is just the first background sprite printed over and over in only gray.
Attachment:
can't figure it out.png [ 23.38 KiB | Viewed 996 times ]
tokumaru, I'm using your template btw - thank you for those!
I'm not sure if I'm not using the correct ASM6 syntax coming from NESASM.
Do you have any suggestions on this?
Code:
;----------------------------------------------------------------
; constants
;----------------------------------------------------------------
PRG_COUNT = 1 ;1 = 16KB, 2 = 32KB
MIRRORING = %0001 ;%0000 = horizontal, %0001 = vertical, %1000 = four-screen
STATETITLE = $00
STATEPLAYING = $01
STATEGAMEOVER = $02
;----------------------------------------------------------------
; variables
;----------------------------------------------------------------
.enum $0000
;NOTE: declare variables using the DSB and DSW directives, like this:
;MyVariable0 .dsb 1
;MyVariable1 .dsb 3
oam .dsw 1,$0200 ;shadow oam
gamestate .dsb 1
soft2000 .dsb 1
soft2001 .dsb 1
sleeping .dsb 1
needma .dsb 1
needdraw .dsb 1
needppureg .dsb 1
needoam .dsb 1
buttons1 .dsb 1
buttons2 .dsb 1
bufflength .dsb 1
.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)
;; .include "clearmem.asm"
.include "macros.asm"
;; .include "colorbuffers.asm" ;palette & attribute data
;; .include "background.asm"
RESET:
SEI
CLD
LDX #$40
STX $4017
LDX #$FE
TXS
INX
STX $2000
STX $2001
STX $4010
;; JMP ClearMem
;; JMP LoadBackground
vblankwait1:
BIT $2002
BPL vblankwait1
clrmem:
LDA #$00
STA $0000, x
STA $0100, x
STA $0300, x
STA $0400, x
STA $0500, x
STA $0600, x
STA $0700, x
LDA #$FE
STA $0200, x ;shadow OAM
INX
BNE clrmem
vblankwait2:
BIT $2002
BPL vblankwait2
LoadPalettes:
LDA $2002 ; read PPU status to reset the high/low latch
LDA #$3F
STA $2006 ; write the high byte of $3F00 address
LDA #$00
STA $2006 ; write the low byte of $3F00 address
LDX #$00 ; start out at 0
LoadPalettesLoop:
LDA palette, x
STA $2007 ; write to PPU
INX
CPX #$20
BNE LoadPalettesLoop
LoadAttribute:
LDA $2002 ; read PPU status to reset the high/low latch
LDA #$23
STA $2006 ; write the high byte of $23C0 address
LDA #$C0
STA $2006 ; write the low byte of $23C0 address
LDX #$00 ; start out at 0
LoadAttributeLoop:
LDA attribute, x ; load data from address (attribute + the value in x)
STA $2007 ; write to PPU
INX ; X = X + 1
CPX #$28 ; Compare X to hex $08, decimal 8 - copying 8 bytes
BNE LoadAttributeLoop ; Branch to LoadAttributeLoop if compare was Not Equal to zero
LoadBackground:
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
LDX #$00 ; start out at 0
LoadBackgroundLoop1:
LDA background, x
STA $2007
INX
CPX #$00
BNE LoadBackgroundLoop1
LDA #%10010000
STA $2000
LDA #%00011110
STA $2001
GameEngineRunning:
Forever:
JMP Forever
WaitFrame:
inc sleeping
loop:
lda sleeping
bne loop
rts
;--------------------------------------
; DoFrame - same idea as WaitFrame, but also does some other stuff
; that the game logic will want done every frame. Things that
; shouldn't be put in NMI
DoFrame:
lda #1
sta needdraw
sta needoam
sta needppureg
jsr WaitFrame
jmp UpdateJoypadData
RTS
;---------------------------------------
; NMI
;---------------------------------------
NMI:
PushAll
LDA needma
BEQ NeedDraw
LDA #$00
STA $2003
LDA oam
STA $4014
NeedDraw:
LDA needdraw
BEQ NeedPpuReg
BIT $2002
JSR DoDrawing
DEC needdraw
NeedPpuReg:
LDA needppureg
BEQ Next
LDA soft2001
STA $2001
LDA soft2000
STA $2000
Next:
BIT $2002
LDA #$00
STA $2005
STA $2005
;; Optional
;; 7)run music code
;; 8)wait for sprite 0 hit and change the VRAM address
;; Optional
LDA #0 ;reset sleeping to 0 so WaitFrame exits
STA sleeping
;; 9)pull registers/status flags off stack
PullAll
RTI
DoDrawing:
;; draw the stuff needed to draw to the drawingbuf variable ($0300)
;; DoFrame to wait for the next VBLANK for it to write
;; LDX #$00
;; LDA $2002
;; OuterLoop:
;; LDA testbuffer, X
;; BEQ DoDrawingDone
;; STA bufflength
;; INX
;; LDA testbuffer, X
;; STA $2006
;; INX
;; LDA testbuffer, X
;; STA $2006
;; INX
;; ;X should be at #$03 right now (in bytes to load)
;; BuffLoop:
;; LDA testbuffer, X
;; STA $2007
;; INX
;; CPX bufflength
;; BNE BuffLoop
DoDrawingDone:
RTS
UpdateJoypadData:
LDA #$01
STA $4016
LDA #$00
STA $4016
LDX #$08
ReadController1Loop:
LDA $4016
LSR A ; bit0 -> Carry
ROL buttons1 ; bit0 <- Carry
DEX
BNE ReadController1Loop
RTS
testbuffer:
.db $03,$20,$00,$00,$01,$02
background:
.db $00,$01,$02,$03
palette:
.db $20,$29,$1A,$0F, $20,$36,$17,$0F, $20,$30,$21,$0F, $20,$27,$17,$0F ;;background palette
.db $20,$16,$27,$18, $20,$02,$38,$3C, $20,$1C,$15,$14, $20,$02,$38,$3C ;;sprite palette
attribute:
.db %00000000, %00010000, %01010000, %00010000, %00000000, %00000000, %00000000, %00110000
.db $01,$01,$01,$01, $01,$01,$01,$01 ,$01,$01,$47,$47, $47,$47,$24,$24 ,$24,$24,$24,$24 ,$24,$24,$24,$24, $24,$24,$24,$24, $55,$56,$24,$24
.db $01,$01,$01,$01, $24,$24,$24,$24 ,$24,$24,$24,$24, $24,$24,$24,$24 ,$24,$24,$24,$24 ,$24,$24,$24,$24, $24,$24,$24,$24, $24,$24,$24,$24
;----------------------------------------------------------------
; interrupt vectors
;----------------------------------------------------------------
.org $fffa
.dw NMI
.dw RESET
.dw 0
;----------------------------------------------------------------
; CHR-ROM bank
;----------------------------------------------------------------
.incbin "gamer.chr"