Page 1 of 2

I don't understand palletes and name and pattern tables.

Posted: Tue Jan 23, 2007 9:36 am
by mog123
Okay, i try to run do a simple demo, but none of this stupid poop works.


Which one of the codes are right for loading the pallete:


Code1

Code: Select all

;these are the writes that setup the palette
        lda #$01
        sta $2007
        lda #$02 
        sta $2007
        lda #$03
        sta $2007
        lda #$04
        sta $2007
        lda #$05
        sta $2007
        lda #$06
        sta $2007
        lda #$07
        sta $2007
        lda #$08
        sta $2007
        lda #$09     ;stop here
        sta $2007
        lda #$0A
        sta $2007
        lda #$0B
        sta $2007
        lda #$0C
        sta $2007
        lda #$0D
        sta $2007
        lda #$0E
        sta $2007
        lda #$0F
        sta $2007
        lda #$11
        sta $2007
        lda #$12    ;Start sprite colors
        sta $2007
        lda #$13
        sta $2007
        lda #$14
        sta $2007
        lda #$15
        sta $2007
        lda #$16
        sta $2007
        lda #$17
        sta $2007
        lda #$18
        sta $2007
        lda #$19
        sta $2007
        lda #$1A
        sta $2007
        lda #$1B
        sta $2007
        lda #$1C
        sta $2007
        lda #$1D
        sta $2007
        lda #$1E
        sta $2007
        lda #$1F

Code2

Code: Select all

	;these are the writes that setup the palette
        lda #$01
        sta $2007
        lda #$02 
        sta $2007
        lda #$03
        sta $2007
        lda #$04
        sta $2007
        lda #$05
        sta $2007
        lda #$06
        sta $2007
        lda #$07
        sta $2007
        lda #$08
        sta $2007
        lda #$01     ;stop here
        sta $2007
        lda #$08
        sta $2007
        lda #$09
        sta $2007
        lda #$0A
        sta $2007
        lda #$01
        sta $2007
        lda #$0B
        sta $2007
        lda #$0C
        sta $2007
        lda #$0D
        sta $2007
        lda #$01    ;Start sprite colors
        sta $2007
        lda #$0D
        sta $2007
        lda #$08
        sta $2007
        lda #$2B
        sta $2007
        lda #$01
        sta $2007
        lda #$05
        sta $2007
        lda #$06
        sta $2007
        lda #$07
        sta $2007
        lda #$01
        sta $2007
        lda #$08
        sta $2007
        lda #$09
        sta $2007
        lda #$0A
        sta $2007
        lda #$01
        sta $2007
        lda #$0B
        sta $2007
        lda #$0C
        sta $2007
        lda #$0D
        sta $2007
Or this one:

Code: Select all

loadpal:                 ;loading pallette
	lda tilepal, x
	sta $2007
	inx
	cpx #$21
	bne loadpal

Every each of these loading routines, gives me a different pallete, but i always use the same .pal file

The yoshi doc is hard to understand for me(because i'm not a native english speaker). And My background always loads the first tile, and copies it through all the space.
And the nes has 16 colors for this and that, so how can i choose which color of the 4color image in the chr file would be green or blue?

Example:

my tile file looks like this(a 4x4 pixel tile, just for an example):

XXXX white
XXXX light gray
XXXX dark grey
XXXX black/trnsparent

And how do i make it look on the screen like:

XXXX blue
XXXX yellow
XXXX red
XXXX black/trnsparent

Because i always get some colors(that even aren't in the palette!)

Please help

Posted: Tue Jan 23, 2007 9:45 am
by tepples
Are you setting the VRAM address to $3F00 before all three routines and setting X to 0 before the third? The following code will do both:

Code: Select all

  ldx #$3F
  stx $2006
  ldx #$00
  stx $2006
(EDIT: address corrected. I use labels for memory-mapped registers in my own code, and sometimes I get the numeric addresses confused.)

Anyway, your first two loading routines write a constant palette to the PPU, and the two routines are different.


As for picking which parts of the palette are used, that's the job of the attribute table:
  1. If the attribute is set to 0, the colors used will be 0, 1, 2, and 3.
  2. If the attribute is set to 1, the colors used will be 0, 5, 6, and 7.
  3. If the attribute is set to 2, the colors used will be 0, 9, 10, and 11.
  4. If the attribute is set to 3, the colors used will be 0, 13, 14, and 15.
For now, set the main nametable's attribute bytes ($23C0 through $23FF) to constant values of $00, $55, $AA, or $FF.

Posted: Tue Jan 23, 2007 10:24 am
by Bregalad
You just must set the PPU pointer to the palette before writing anything to $2007, just tepples said exept that you have to replace $2007 writes per $2006 writes (misspeling I think).
Here you are the simplest way to do it :
WritePalette
lda #$3f
sta $2006
lda #$00
sta $2006
tay
_palLoop
lda Palette,Y
sta $2007
iny
cpy #$20
bne _palLoop
rts
Well, "Palette" can refer to anything in ROM (constant) or in RAM (variable). I prefer to always fist load colors in RAM so that they can be freely acessed by the program, and then to write that buffer to the actual palette in VBlank (or on screen loading routines) to keep thing done proprely.

Posted: Tue Jan 23, 2007 11:07 am
by mog123
yeah, i do the 2 stores to 2007
and clear X
I'm not that stupid lolz
I just can't understand how the heck the colors appear.
Are they the hex values i load to 2006?
If yes, why do i need the *.pal file?
Because even if i have the full pallete set to red, i get a blue white and 2 black colors ;f

I just can't understand it

Posted: Tue Jan 23, 2007 11:36 am
by Bregalad
I assume you wrote your adress to $2006 did you ?
Then if you did it after disabling both BG and sprites to $2001, and re-enabling them later ?
If so everything should be fine, just double-check your work.

BTW the 3 ways of writing the palette are equivalent, the first two are just plain stupid, UNLESS you're want your code to be very very fast for some reason and you're probably not wanting that.
The third is correct, but I assume you would draw cpx #$20 instead of cpx #$21.

Posted: Tue Jan 23, 2007 11:41 am
by mog123
I didn't understand a word you said now ;p

Are the hex values that i load into 2006, the color values?

If yes, then why the hell i need the .pal file?

Posted: Tue Jan 23, 2007 12:01 pm
by never-obsolete
If yes, then why the hell i need the .pal file?
you don't have to use external files for data, it just leaves less clutter in your source.
I didn't understand a word you said now ;p
all those

Code: Select all

    ...
    lda #$xx
    sta $2007
    ...
execute faster then a loop, but waste space. i believe that is what he meant.

Posted: Tue Jan 23, 2007 12:08 pm
by mog123
i really don't understand now :x


Can someone please teach me how to load the pallete into the rom?

I always get some blueish color, even though my whole .pal file has red colors

I'll make a pack of everything i have done to make this work, and tell me what's wrong

Posted: Tue Jan 23, 2007 12:12 pm
by never-obsolete

Code: Select all

	; load the palette into vram
	lda #$3F
	sta $2006
	ldx #00
	stx $2006
palloop:	lda Palette,x
	sta $2007
	inx
	cpx #$20
	bne palloop

Code: Select all

	; palette data
Palette:	.incbin "Game.pal"
verbatim from my Pitfall! port

Posted: Tue Jan 23, 2007 12:18 pm
by mog123
http://urashima.cydonianknight.com/infile.zip

this is my work till now.

I'm going to check your code now.

Zomgds, your code worked ;p

can you tell me my mistake?

Posted: Tue Jan 23, 2007 12:19 pm
by Disch
mog123 wrote:I always get some blueish color, even though my whole .pal file has red colors
Just to cover all the bases here....

You shouldn't be using the same kind of .pal file that emulators use. Emulators use it to fill in RGB values for the NES's palette. As a NES developer, you cannot use RGB values. Each value has a given color associated with it:

$00 is grey
$0F is black
$30 is white
$01 is blue
$09 is green
(there are docs which have the whole palette listed)

Posted: Tue Jan 23, 2007 12:23 pm
by tokumaru
The writes to $2006 define the destination address of the data you are about to write to $2007. So, if you want to change the palette, you have to set $2006 to point to the palette area, which is at $3F00. So, first write $3F to $2006, and then $00.

Now you're ready to write the color values to $2007. Where to get the values from is up to you. There are infinite ways to read the palette (which means all the examples you posted are valid ways of getting the palette), with or without external files, using different addressing modes and so on.

The simplest way, I'd say is to just LDA the color value and store it in $2007. But this is really a 6502 thing now, so you have to study some 6502 ASM to get things going.

For the PPU it doesn't matter how, but you have to set the address using $2006 first, and then write the data (in your case, color values) to $2007.

Posted: Tue Jan 23, 2007 12:27 pm
by never-obsolete
i don't see the problem, your palette is loaded correctly. two things i see in your code:

1. you don't wait for the ppu to "warm up" before writing to vram
2. you don't disable bkg/spr rendering before you write the palette into vram

Posted: Tue Jan 23, 2007 12:31 pm
by tokumaru
mog123 wrote:can you tell me my mistake?
Your mistake was you were not using the file with your color values at all. Although you had the data included in the ROM, you were not using it.

When you did this:

Code: Select all

 lda #$00
 sta $2007
you were always getting color $00 (gray) as the first palette color, completely ignoring the included .pal file. But when you use "lda Palette,x" you're actually loading from the values inside the .pal file, since the label "Palette" points to the part of the ROM where your included palette is.

Posted: Tue Jan 23, 2007 12:31 pm
by mog123
so, i use either of these methods:

load a pal file

or load the values by hand to the 2007?

because i still don't know how to make the background display the colors that i want it to display ;f

this is my effect till now:

http://img46.imageshack.us/my.php?image=qwe8vx.jpg