Page 1 of 1
.db directive
Posted: Tue Dec 18, 2012 3:58 pm
by Johnny Starr
Due to the poor NES dev documentiation, I am having to decipher what little demo apps there are out there.
I came accross a simple demo that loads the color palette and I am trying to understand the .db directive.
I don't have the code infront of me here at work, but I will try to express the gist of it:
The palette uses .db
Code: Select all
palette:
.db $0F, $0C, $0E ... (etc)
It actually has 32 entries. This makes sense if there are 32 colours to choose from.
The part of the code that calls the palette sub routine looks something like this:
Code: Select all
LDX #$00
LoadPalette:
LDA palette, X
STA $2013 ; store at PPU
CMP #$20 ; compare to decimal 32
BNE LoadPalette ; continue to loop
Like I said, its not 100% accurate.
It seems that using .db is like an array of some sort? Every time you iterate through the loop, you load the accumulator
with the data that is next in the stream. Then you store the PPU with what rests at A?
Hopefully, I'm understanding this right. Could someone elaborate?
Re: .db directive
Posted: Tue Dec 18, 2012 4:08 pm
by leeeeee
.db is define byte(s) and is followed by one or more byte sized constants.
Lee.
Re: .db directive
Posted: Tue Dec 18, 2012 5:57 pm
by whartung
Yea, it's just cycling through the data starting at the label 'palette', and storing them in to $2013 one by one until it encounters the $20 byte.
.db stuff the data in to memory. Other assemblers might use .byte for that.
Re: .db directive
Posted: Tue Dec 18, 2012 6:44 pm
by GARTHWILSON
If your assembler puts out a .lst (list) file, you can see there exactly what goes down. .db, DB, .byte, etc. lay down the exact bytes you specify, as data and not as instructions (although you could also use it to lay down something like CMOS instructions that an NMOS assembler doesn't have).
Re: .db directive
Posted: Tue Dec 18, 2012 7:45 pm
by BigDumbDinosaur
.db, DB, .byte, etc. lay down the exact bytes you specify, as data and not as instructions (although you could also use it to lay down something like CMOS instructions that an NMOS assembler doesn't have).
That's how I implement the 65C816 instructions in my macros for the Kowalski simulator...just a bunch of .byte and .word instructions.
BTW, in the original MOS Technology reference assembler (on which Commodore's MADS was based) only the first three characters in a pseudo-op were parsed. So one could use .byt in place of .byte and .wor in place of .word. Pseudo-ops like .db and .dw came much later.
Re: .db directive
Posted: Thu Dec 20, 2012 1:03 am
by clockpulse
That's how I implement the 65C816 instructions in my
macros for the Kowalski simulator...just a bunch of .byte and .word instructions.
Thanks, your macros are working out beautifully!

Re: .db directive
Posted: Thu Dec 20, 2012 4:23 pm
by BigDumbDinosaur
That's how I implement the 65C816 instructions in my
macros for the Kowalski simulator...just a bunch of .byte and .word instructions.
Thanks, your macros are working out beautifully!

You're welcome. Sometimes we dinosaurs fool humans with our smarts routine. 
Re: .db directive
Posted: Sun Dec 30, 2012 10:46 am
by DoNotWant
Hello!
I just registered here, nice to meet you all.
http://nintendoage.com/forum/messagevie ... eadid=7155
Introduction to programming the NES, also some more advanced concepts later on.
Also a tutorial on how to make a sound driver for the NES.
http://nintendoage.com/forum/messagevie ... adid=33287
Game engine programming for the NES(meta sprites, meta tiles, RLE compression, collision detection, e.t.c.)
http://nintendoage.com/forum/categories.cfm?catid=22
Forum for NES homebrewers.
http://nesdev.com/
NES homebrew forum/wiki
Just wanted to give some handy information since you can't seem to find any good NES documentation.

Re: links to NES tutorials and information
Posted: Sun Dec 30, 2012 5:31 pm
by BigEd
Hi DNW, and welcome!
It would be good if you'd edit your post to add a few explanatory words for each link: it will make it easier to find this thread and help your post show up in search results.
I only glanced at the first link, but it seems to be listing a 24-part tutorial on NES programming. I had a quick look at the one about 6502 assembly language programming, and it looks good to me.
Cheers
Ed
Re: .db directive
Posted: Sun Dec 30, 2012 7:51 pm
by BigDumbDinosaur
Welcome to our 6502 world. It amazes me that after all these years NES is still popular and people are still cranking out code for it.
Re: .db directive
Posted: Sun Dec 30, 2012 9:19 pm
by DoNotWant
Thanks, I added some info about the links.

Re: .db directive
Posted: Sun Dec 30, 2012 9:27 pm
by BigEd
Great - thanks!