.db directive

Programming the 6502 microprocessor and its relatives in assembly and other languages.
Post Reply
User avatar
Johnny Starr
Posts: 58
Joined: 30 May 2012
Location: Dallas, TX
Contact:

.db directive

Post 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?
leeeeee
In Memoriam
Posts: 347
Joined: 30 Aug 2002
Location: UK
Contact:

Re: .db directive

Post by leeeeee »

.db is define byte(s) and is followed by one or more byte sized constants.

Lee.
whartung
Posts: 1004
Joined: 13 Dec 2003

Re: .db directive

Post 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.
User avatar
GARTHWILSON
Forum Moderator
Posts: 8773
Joined: 30 Aug 2002
Location: Southern California
Contact:

Re: .db directive

Post 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).
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
User avatar
BigDumbDinosaur
Posts: 9425
Joined: 28 May 2009
Location: Midwestern USA (JB Pritzker’s dystopia)
Contact:

Re: .db directive

Post by BigDumbDinosaur »

GARTHWILSON wrote:
.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.
x86?  We ain't got no x86.  We don't NEED no stinking x86!
clockpulse
Posts: 87
Joined: 20 Oct 2012
Location: San Diego

Re: .db directive

Post by clockpulse »

BigDumbDinosaur wrote:
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! :D
User avatar
BigDumbDinosaur
Posts: 9425
Joined: 28 May 2009
Location: Midwestern USA (JB Pritzker’s dystopia)
Contact:

Re: .db directive

Post by BigDumbDinosaur »

clockpulse wrote:
BigDumbDinosaur wrote:
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! :D

You're welcome. Sometimes we dinosaurs fool humans with our smarts routine. :D
x86?  We ain't got no x86.  We don't NEED no stinking x86!
DoNotWant
Posts: 2
Joined: 30 Dec 2012

Re: .db directive

Post 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. :)
Last edited by DoNotWant on Sun Dec 30, 2012 9:19 pm, edited 1 time in total.
User avatar
BigEd
Posts: 11463
Joined: 11 Dec 2008
Location: England
Contact:

Re: links to NES tutorials and information

Post 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
User avatar
BigDumbDinosaur
Posts: 9425
Joined: 28 May 2009
Location: Midwestern USA (JB Pritzker’s dystopia)
Contact:

Re: .db directive

Post by BigDumbDinosaur »

DoNotWant wrote:
Hello!
I just registered here, nice to meet you all.

http://nintendoage.com/forum/messagevie ... eadid=7155
http://nintendoage.com/forum/messagevie ... adid=33287
http://nintendoage.com/forum/categories.cfm?catid=22
http://nesdev.com/

Just wanted to give some handy information since you can't seem to find any good NES documentation. :)

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.
x86?  We ain't got no x86.  We don't NEED no stinking x86!
DoNotWant
Posts: 2
Joined: 30 Dec 2012

Re: .db directive

Post by DoNotWant »

Thanks, I added some info about the links. :)
User avatar
BigEd
Posts: 11463
Joined: 11 Dec 2008
Location: England
Contact:

Re: .db directive

Post by BigEd »

Great - thanks!
Post Reply