Either won't load: bg pattern or nametable

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
User avatar
FrankenGraphics
Formerly WheelInventor
Posts: 2064
Joined: Thu Apr 14, 2016 2:55 am
Location: Gothenburg, Sweden
Contact:

Either won't load: bg pattern or nametable

Post by FrankenGraphics »

I thought i had this down. It's a bit embarrasing. I've managed sprites on their own, and backgrounds on their own. The aim is a simple still picture comprised of both sprite and bg layer.

My include list looks like this:

Code: Select all

.segment "CHRROM"
.incbin "spritesheet.chr" ;4k
.incbin "bgsheet.chr" ;4k
.incbin "nametable.nam" ;1k
Palette is hardcoded for now.
BG loading code looks like this:

Code: Select all

lda #$90     ; CPU addr $8000+ 4kB offset
sta ptr+1     
sty ptr+0  ;y reg is known to be zero 
    
lda #$10   ;headache be here, i think?
sta PPUADDR    
sty PPUADDR  
 
ldx #20      ; + 20 pages' worth - 16 for bg chr and 4 for nt 

loop:	
	lda (ptr), y
	sta PPUDATA 
	iny   
	bne loop    ; done a page yet?  (y reg)
	inc ptr+1    
	dex       
	bne loop    ; done all pages yet? (x reg) 
This this seems to put the NT where i want it (i can tell by the attribute table), but not the pattern table. If i change PPU addr to $0000 via sty PPUADDR sty PPUADDR (the way i had it originally), i can get the pattern but not the attribute/name table. What have i done to not get both?
Last edited by FrankenGraphics on Thu Jul 27, 2017 4:28 pm, edited 1 time in total.
lidnariq
Posts: 11432
Joined: Sun Apr 13, 2008 11:12 am

Re: Either won't load: bg pattern or nametable

Post by lidnariq »

Why are your tiles and nametable both in a chrrom segment? Is that just a misnomer?

Have you set $2000 correctly for rendering? (It shouldn't affect loading tiles, tho...)
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Either won't load: bg pattern or nametable

Post by tokumaru »

Is your "CHRROM" segment in PRG-ROM and you're in fact using CHR-RAM? That's confusing... Anyway, I can't tell what's wrong just from this section of code... The full code or even the ROM would make debugging easier.
User avatar
FrankenGraphics
Formerly WheelInventor
Posts: 2064
Joined: Thu Apr 14, 2016 2:55 am
Location: Gothenburg, Sweden
Contact:

Re: Either won't load: bg pattern or nametable

Post by FrankenGraphics »

Oh, that's a misnomer i accidentally carried across from studying a config file to get clues on how to do it. Which was NROM, i realize now. It should be RODATA. It's late here but i'll update tomorrow! Thanks so far on the leads
Rahsennor
Posts: 479
Joined: Thu Aug 20, 2015 3:09 am

Re: Either won't load: bg pattern or nametable

Post by Rahsennor »

What's in your NMI? Sounds like you're not resetting the scroll after writing the pattern table.
User avatar
thefox
Posts: 3134
Joined: Mon Jan 03, 2005 10:36 am
Location: 🇫🇮
Contact:

Re: Either won't load: bg pattern or nametable

Post by thefox »

Try stepping through the code in an emulator's debugger. For example in FCEUX you can have the hex editor (set to PPU Memory) open while stepping to verify that the data is going where it should.

As for the actual issue, my guess is the same as Rahsennor's.
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi
User avatar
FrankenGraphics
Formerly WheelInventor
Posts: 2064
Joined: Thu Apr 14, 2016 2:55 am
Location: Gothenburg, Sweden
Contact:

Re: Either won't load: bg pattern or nametable

Post by FrankenGraphics »

Thanks, all!

Allright, here's the project in a zip (source, assets, rom). Both patterns are loaded, so is nametable and palette. So it's "working", but feels a bit rickety.
NMI currently got cut as it doesn't do anything useful just yet. The config got a few mistakes ironed out, too. But i think the problem was an erronously set bit in PPUCTRL and/or having data in the "wrong" bank (suspicious).

New questions:
-Why does the problem persist when i try to move the graphics data to bank0? (from line 190 to line 42).
-Why do i have to load the palette address at line 103?
-In the config, what good does the align setting do?

Pardon the nonexistent init.
Attachments
dungeon_companion.zip
(19.06 KiB) Downloaded 105 times
User avatar
thefox
Posts: 3134
Joined: Mon Jan 03, 2005 10:36 am
Location: 🇫🇮
Contact:

Re: Either won't load: bg pattern or nametable

Post by thefox »

Code: Select all

	clc ;set a known condition
loop_forever:
	bcs loop_forever
See anything wrong? :)
FrankenGraphics wrote:-In the config, what good does the align setting do?
It aligns the segment in the MEMORY block where it was assigned. In your case since the OAM segment is the only thing that goes into the OAM memory block, you don't really need it. Note, however, that if you want to use .align in code, cc65 requires that the corresponding segment is aligned (in the linker configuration) to some multiple of the value given to .align.
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi
User avatar
FrankenGraphics
Formerly WheelInventor
Posts: 2064
Joined: Thu Apr 14, 2016 2:55 am
Location: Gothenburg, Sweden
Contact:

Re: Either won't load: bg pattern or nametable

Post by FrankenGraphics »

Haha! *makes a known condition* *actively ignores it*

Ah, thanks. That makes sense. But segments will never overwrite each other, since the PC can't move backwards at assembly time, right?

In case someone doesn't want to download, here's the code:
https://pastebin.com/KJAfVTaz

And the whole thing again with that loop fix.
170729.zip
(19.08 KiB) Downloaded 97 times
User avatar
thefox
Posts: 3134
Joined: Mon Jan 03, 2005 10:36 am
Location: 🇫🇮
Contact:

Re: Either won't load: bg pattern or nametable

Post by thefox »

FrankenGraphics wrote:But segments will never overwrite each other, since the PC can't move backwards at assembly time, right?
They don't.
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi
Post Reply