Trying to figure out what I'm doing wrong

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

Post Reply
mattheweston
Posts: 25
Joined: Tue Feb 09, 2010 5:48 pm

Trying to figure out what I'm doing wrong

Post by mattheweston »

Ok, by using the debugging tools, I can tell that the PPU and Nametables have what they are supposed to, but I'm missing a step somewhere because I'm not getting anything on the screen. Any constructive feedback is welcomed as I'm trying to learn how all this works together. Any improvements or explanations about parts of the code would be welcome.

Code: Select all

	; INES header stuff
	.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 1   ; following goes in bank 1
	.org $FFFA  ; start at $FFFA
	.dw 0    ; 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 0   ; bank 0 - our place for code.
	.org $8000  ; code starts at $8000
	
Start:  
	lda #%00001000  ; do the setup of PPU
	sta $2000       ; that we
	lda #%00011110  ; talked about
	sta $2001       ; on a previous day

	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
	lda #$20
	sta $2006
	
	ldx #$00
	
loadNames:
	lda #$00
	sta $2007
	inx
	cpx #64
	bne loadNames
		
	lda #$02
	sta $2007
	lda #$02
	sta $2007
	lda #$03
	sta $2007
	lda #$04
	sta $2007
	lda #$05
	sta $2007
	lda #$03
	sta $2007
	lda #$00
	sta $2007
	lda #$00
	sta $2007
	
waitblank:         ; this is the wait for VBlank code from above
	lda $2002  ; load A with value at location $2002
	bpl waitblank  ; if bit 7 is not set (not VBlank) keep checking

	lda #$00   ; these lines tell $2003
	sta $2003  ; to tell
	lda #$00   ; $2004 to start
	sta $2003  ; at $0000.

	lda #50  ; load Y value
	sta $2004 ; store Y value
	lda #$00  ; tile number 0
	sta $2004 ; store tile number
	lda #$00 ; no special junk
	sta $2004 ; store special junk
	lda #20  ; load X value
	sta $2004 ; store X value
	; and yes, it MUST go in that order.

infin:
	jmp infin   ; JuMP to infin. note that this loop never ends. :)

tilepal: .incbin "our.pal" ; include and label our pallete
ourMap: .incbin "our1.map" ; binary map file (NameTable aka TileMap)

	.bank 2   ; switch to bank 2
	.org $0000  ; start at $0000
	.incbin "our.bkg"  ; empty background first
	.incbin "our.spr"  ; our sprite pic data
	; note these MUST be in that order.
JRoatch
Formerly 43110
Posts: 394
Joined: Wed Feb 05, 2014 7:01 am
Location: us-east
Contact:

Re: Trying to figure out what I'm doing wrong

Post by JRoatch »

You should wait 2 vblanks before loading stuff to the PPU. Also you need to set scroll during vblank or forced blank and after anything that effects PPU_ADDR to view the correct part of the nameables.

Later on, keep in mind when doing bulk updates that the ppu pointer effectively scrambles during screen rendering and the way to avoid that is to turn off the screen by writing 0 to $2001 before or during vblank.
mattheweston
Posts: 25
Joined: Tue Feb 09, 2010 5:48 pm

Re: Trying to figure out what I'm doing wrong

Post by mattheweston »

Ok, I figured it had to be either timing or I wasn't loading something correctly into memory.
User avatar
Quietust
Posts: 1787
Joined: Sun Sep 19, 2004 10:59 pm
Contact:

Re: Trying to figure out what I'm doing wrong

Post by Quietust »

Your test program seems awfully familiar, and a quick search comfirms that it was taken from the old GBAGuy NESASM tutorials - if you are actually following those, please stop immediately and use a proper tutorial because the GBAGuy tutorials are outdated and wrong (for example, right after 'waitvblank' it clears the OAM address by writing to $2003 twice because GBAGuy mistakenly thought that it was a 16-bit register like $2006) and will produce programs that do not actually work on modern emulators, let alone real hardware.
Quietust, QMT Productions
P.S. If you don't get this note, let me know and I'll write you another.
mikaelmoizt
Posts: 120
Joined: Sat Apr 12, 2014 12:11 pm
Location: Gothenburg, Sweden

Re: Trying to figure out what I'm doing wrong

Post by mikaelmoizt »

I'm a NES newbie too, but I might be able to help a little. I am not using NESASM anymore. Right now I use Context editor with NESASM highlighter + ASM6.

Code: Select all

   .bank 1   ; following goes in bank 1
   .org $FFFA  ; start at $FFFA
   .dw 0    ; 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
Okay, so you write 0 to NMI vector. Meaning you don't want/care about NMI by pointing to $0000?
As RESET vector "Start". That routine is missing some stuff. Check http://wiki.nesdev.com/w/index.php/Init_code
The last line is messed up. That is the IRQ/BRK vector. It doesn't have anything to do with NMI.

Code: Select all

waitblank:         ; this is the wait for VBlank code from above
   lda $2002  ; load A with value at location $2002
   bpl waitblank  ; if bit 7 is not set (not VBlank) keep checking
Do this twice. Or even better

Code: Select all

waitblank:     
      bit $2002
      bpl waitblank
This part is... eh.. weird.

Code: Select all

   lda #$00   ; these lines tell $2003
   sta $2003  ; to tell
   lda #$00   ; $2004 to start
   sta $2003  ; at $0000. <--------------------- So sprites will be put into zeropage? I dont follow.

   lda #50  ; load Y value
   sta $2004 ; store Y value
   lda #$00  ; tile number 0
   sta $2004 ; store tile number
   lda #$00 ; no special junk
   sta $2004 ; store special junk
   lda #20  ; load X value
   sta $2004 ; store X value
   ; and yes, it MUST go in that order.
This method of transferring OAM data is not my strong side. It looks pretty hard to do aswell. Consider using $4014 instead.

In your case this would be a lot simpler

Code: Select all

  
  lda sprites data from somewhere in a loop (probably where "our.spr" resides)
  sta into zero page in a loop

  lda #$00
  sta $2003       ; Sprites low RAM location (=00XX)
  lda #$00
  sta $4014       ; Sprites hight RAM location (=XX00) and transfer bytes.
Also you need to

Code: Select all

 lda #00
 sta $2005
 sta $2005
The PPU wiki page is really great. http://wiki.nesdev.com/w/index.php/PPU_registers
I´ve got %01100011 problems but the BITs aint one.
User avatar
rainwarrior
Posts: 8062
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Trying to figure out what I'm doing wrong

Post by rainwarrior »

mikaelmoizt wrote:This method of transferring OAM data is not my strong side. It looks pretty hard to do aswell. Consider using $4014 instead.
There's an additional problem here that most of OAM has not been initialized, so on startup you might have random sprites scattered about. Probably this won't show up on emulators, but it will happen on an NES. The $4014 DMA is really the only effective way to set up sprites. Doing something with just $2004 that works properly outside of an emulator is very tricky. Stick with $4014, and only use it during vblank.
mattheweston
Posts: 25
Joined: Tue Feb 09, 2010 5:48 pm

Re: Trying to figure out what I'm doing wrong

Post by mattheweston »

Sounds like I need to find some better tutorials. Anyone got any recommendations? Does anyone have a source file they wouldn't mind sharing so I can at least get off on the right foot?
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Trying to figure out what I'm doing wrong

Post by tepples »

mattheweston wrote:Sounds like I need to find some better tutorials. Anyone got any recommendations?
Nerdy Nights is probably the most well-known that is reasonably accurate.
Does anyone have a source file they wouldn't mind sharing so I can at least get off on the right foot?
Where we're going, you won't need feet.
User avatar
rainwarrior
Posts: 8062
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Trying to figure out what I'm doing wrong

Post by rainwarrior »

I posted an example program here: viewtopic.php?f=10&t=11151
lidnariq
Posts: 10677
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: Trying to figure out what I'm doing wrong

Post by lidnariq »

The $2003/$2004 approach to uploading sprites is full of horrific hardware bugs, and should basically never be used.
(Yes, I've written a workaround.. Don't use it unless you really need it.)
Post Reply