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:
;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:
;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:
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
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:
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:
- If the attribute is set to 0, the colors used will be 0, 1, 2, and 3.
- If the attribute is set to 1, the colors used will be 0, 5, 6, and 7.
- If the attribute is set to 2, the colors used will be 0, 9, 10, and 11.
- 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.
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 :
Quote:
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.
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
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.
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?
Quote:
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.
Quote:
I didn't understand a word you said now ;p
all those
Code:
...
lda #$xx
sta $2007
...
execute faster then a loop, but waste space. i believe that is what he meant.
i really don't understand now
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
Code:
; 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:
; palette data
Palette: .incbin "Game.pal"
verbatim from my Pitfall! port
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?
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)
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.
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
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:
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.
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
attribute tables allow you to change where portions of your background get their colors from.
aah, i still don't understand.
how do i know which pallete color I'm using? what colors is the background using? random colors from my palette?
I just ****ing cant get it and im close to depression.
http://img109.imageshack.us/my.php?image=qweqwe6wk.png
This is my pallette file
None of the colors from my screen shot earlier are close to each other, i can't understand this.
Would loading a palette like this work? :
Code:
lda #$3F
sta $2006
lda #00
sta $2006
lda #$0F ;load black
sta #2007 ;into 2007
lda #$3F
sta $2006
lda #01
sta $2006
lda #$30 ;white
sta #2007 ;into 2007
and so on?
mog123 wrote:
so, i use either of these methods:
load a pal file
or load the values by hand to the 2007?
Yup. The code you posted was loading each value directly, not using the included file. To change the palette that way you'd have to change the number after each LDA command to the numbers of the colors you want.
Quote:
http://img46.imageshack.us/my.php?image=qwe8vx.jpg
What you see here is most likely the first tile in your CHR file, repeated all over the screen using the first palette. This is because the emulator you are using probably clears all the PPU memory, so you get tile $00 using palette $00.
In order to have a blank screen, you have to fill the name table being displayed with a blank tile, of the color you'd like to display. And also, fill the attribute tables with the indexes of the palettes you wish to use.
Writing to the name tables and attribute tables is done exactly as it is for the palette: set the address through $2006 and then write the data to $2007.
This code will fill the first name table with a specific tile:
Code:
lda #$20 ;set the address of the first name table
sta $2006
lda #$00
sta $2006
lda #$80 ;the number of the tile - change the number to test
ldx #$F0 ;repeat 240 times
ClearNT:
sta $2007 ;240 * 4 writes = 960 (number of tiles in a name table)
sta $2007
sta $2007
sta $2007
dex
bne ClearNT
Just look for a blank tile and use it in place of the #$80 I used above.
mog123 wrote:
Would loading a palette like this work? :
Code:
lda #$3F
sta $2006
lda #00
sta $2006
lda #$0F ;load black
sta #2007 ;into 2007
lda #$3F
sta $2006
lda #01
sta $2006
lda #$30 ;white
sta #2007 ;into 2007
and so on?
Yes, but this is wasteful, since the PPU address is incremented automatically after each write to $2007. So, after the first write to $2007 (that places your color value at PPU address $3F00), the PPU address register will already be pointing to $3F01, so there is no need to set it to that value.
read my next post.
the problem is that i don't know which palette value is which x.x
they aren't signed in anyway(see the link from my last reply)
I just have some colors and that's all
about the first tile, i knew it was all repeated.
But why does it use those colors?
because your attribute table is full of zeros, so the whole background uses palette "group" 0. go read up on attribute tables.
mog123 wrote:
But why does it use those colors?
Those must be the first colors in your palette.
How did you make that .pal file, and why aren't those the colors you expected?
Just for reference, here are the numbers of all colors:
Please explain why those weren't the ones you expected.
but which one is the palette group 0?
from where to where is group 0, then group 1, 2 ,3?
tokumaru wrote:
Please explain why those weren't the ones you expected.
http://img329.imageshack.us/my.php?imag ... qwe3yc.jpg
because they are the first 4 colours so i thought they are the 0 group
Well, mog123, you should definitely go read a miminum amount of tutorials before coming asking questions. About each starter kit out there include some sample code to clear name tables, attributes tables, set a known palette and so on. Some tutorials contains minor errors, but after all we cannot teach all basics to each individuall wich just refuses to read tutorials.
So yeah, there is nothing complicated for a newbie in clearing the name table, attribute table and set the palette, just type down the code some of us posted above after having done the standard reset procedure, then turn the screen 'on' via $2001.
I've read yoshi's nestech.txt, gbaguy's nes tutorials and the NESPrgmn, and I'm stuck with doing the palette.
I just don't know why are the colors used, insead of those i showed in the border on the screenshot.
Because everyone is telling that the colors from group 0 are loaded, It's logical that the first ones are always loaded, but which ones are the first ones
tell me that by looking at the screen i posted.
Well, if those are not the colors in the first palette (the first 4 colors) maybe the attribute table was not cleared with 0's. You should try doing it yourself (BTW, never rely on unitialized values! If you expect memory to have certain values, put the values there yourself!).
Have $2006 point to $23C0 and then write 64 0's to $2007, and see if then you get the colors in the first palette.
HA! I've made it! I'm so darn happy
I loaded the pallete repeatedly, with:
white ; 30
red ; 16
black; 0F
blue; 01
And here's my result:
http://img440.imageshack.us/img440/2672/qw6fs.jpg
Thank you everybody for the supportive help.
Now(tomorrow) i'm going to go with name tables, and assigning palette groups.
If i'll have some questions, i'll ask here.
mog123 wrote:
I loaded the pallete repeatedly, with:
white ; 30
red ; 16
black; 0F
blue; 01
Well, if you only want to use one palette, that's one way to do it! =) Like this you don't have to even worry about the attribute tables (it doesn't matter what palette is pointed by them, since they're all the same).
But as soon as you want to use different palettes you have to master the attribute tables.