6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Fri Apr 26, 2024 3:30 pm

All times are UTC




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: .db directive
PostPosted: Tue Dec 18, 2012 3:58 pm 
Offline
User avatar

Joined: Wed May 30, 2012 7:45 pm
Posts: 58
Location: Dallas, TX
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:
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:
   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?

_________________
http://www.thestarrlab.com


Top
 Profile  
Reply with quote  
 Post subject: Re: .db directive
PostPosted: Tue Dec 18, 2012 4:08 pm 
Offline

Joined: Fri Aug 30, 2002 2:05 pm
Posts: 347
Location: UK
.db is define byte(s) and is followed by one or more byte sized constants.

Lee.


Top
 Profile  
Reply with quote  
 Post subject: Re: .db directive
PostPosted: Tue Dec 18, 2012 5:57 pm 
Offline

Joined: Sat Dec 13, 2003 3:37 pm
Posts: 1004
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: .db directive
PostPosted: Tue Dec 18, 2012 6:44 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8428
Location: Southern California
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?


Top
 Profile  
Reply with quote  
 Post subject: Re: .db directive
PostPosted: Tue Dec 18, 2012 7:45 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8143
Location: Midwestern USA
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!


Top
 Profile  
Reply with quote  
 Post subject: Re: .db directive
PostPosted: Thu Dec 20, 2012 1:03 am 
Offline

Joined: Sat Oct 20, 2012 8:41 pm
Posts: 87
Location: San Diego
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


Top
 Profile  
Reply with quote  
 Post subject: Re: .db directive
PostPosted: Thu Dec 20, 2012 4:23 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8143
Location: Midwestern USA
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!


Top
 Profile  
Reply with quote  
 Post subject: Re: .db directive
PostPosted: Sun Dec 30, 2012 10:46 am 
Offline

Joined: Sun Dec 30, 2012 10:41 am
Posts: 2
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.

Top
 Profile  
Reply with quote  
PostPosted: Sun Dec 30, 2012 5:31 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10793
Location: England
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


Top
 Profile  
Reply with quote  
 Post subject: Re: .db directive
PostPosted: Sun Dec 30, 2012 7:51 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8143
Location: Midwestern USA
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!


Top
 Profile  
Reply with quote  
 Post subject: Re: .db directive
PostPosted: Sun Dec 30, 2012 9:19 pm 
Offline

Joined: Sun Dec 30, 2012 10:41 am
Posts: 2
Thanks, I added some info about the links. :)


Top
 Profile  
Reply with quote  
 Post subject: Re: .db directive
PostPosted: Sun Dec 30, 2012 9:27 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10793
Location: England
Great - thanks!


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 17 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: