Can someone explain palettes more in-depth to me?

Discussion of hardware and software development for Super NES and Super Famicom. See the SNESdev wiki for more information.

Moderator: Moderators

Forum rules
  • For making cartridges of your Super NES games, see Reproduction.
Rai
Posts: 9
Joined: Sun Jul 15, 2012 8:19 pm

Can someone explain palettes more in-depth to me?

Post by Rai »

Hey, Rai here. Recently, I've been trying to code the asm to display a sprite on the screen.

I've mostly been going off the walker.asm example in the snes starter kit.

Now, I've gotten the sprite to display, but unless I put the palette at 100 bytes after the DMA address; the palette will be weird.

In this case, the palette is at 81A000 and that's the address I DMA to CGRAM. But unless I put the palette at 81A100, it won't send the correct palette.

This is weird because I did store 0 to the color register, so I thought that meant that the game should use the first palette?

You can download the asm file for the sprite routine here:
http://www.mediafire.com/download.php?sb9bmmpnozdl1jc
User avatar
Ramsis
Posts: 341
Joined: Sun Jul 01, 2012 6:44 am
Location: Lion's den :3
Contact:

Re: Can someone explain palettes more in-depth to me?

Post by Ramsis »

Hey, Rai,

great, welcome to the coding club! I'm still a newbie too. :) But I just took a look at your code nonetheless.
Rai wrote:Now, I've gotten the sprite to display, but unless I put the palette at 100 bytes after the DMA address; the palette will be weird.

In this case, the palette is at 81A000 and that's the address I DMA to CGRAM. But unless I put the palette at 81A100, it won't send the correct palette.
Beware of hex numbers -- $100 = 256 bytes! :wink:


Then there's this small, mysterious loop:

Code: Select all

LDX #$0100

Loopingtwo:
STZ $2122
DEX
BNE Loopingtwo
Remember that writing to $2122 auto-increments the address! So it's likely possible that by simply removing that Loopingtwo thingy (which is probably useless anyway), you'll solve your problem. :)
Some of my projects:
Furry RPG!
Unofficial SNES PowerPak firmware
(See my GitHub profile for more)
Rai
Posts: 9
Joined: Sun Jul 15, 2012 8:19 pm

Re: Can someone explain palettes more in-depth to me?

Post by Rai »

Ramsis wrote:Hey, Rai,

great, welcome to the coding club! I'm still a newbie too. :) But I just took a look at your code nonetheless.
Rai wrote:Now, I've gotten the sprite to display, but unless I put the palette at 100 bytes after the DMA address; the palette will be weird.

In this case, the palette is at 81A000 and that's the address I DMA to CGRAM. But unless I put the palette at 81A100, it won't send the correct palette.
Beware of hex numbers -- $100 = 256 bytes! :wink:


Then there's this small, mysterious loop:

Code: Select all

LDX #$0100

Loopingtwo:
STZ $2122
DEX
BNE Loopingtwo
Remember that writing to $2122 auto-increments the address! So it's likely possible that by simply removing that Loopingtwo thingy (which is probably useless anyway), you'll solve your problem. :)
Hmm... well after doing some research, I think this may just be something to do with CGRAM.

I've looked at another game and it only uses the first 256 bytes of CGRAM for backgrounds. It uses the latter 256 bytes for sprites. But is this is true or just a coindence?

Infact yeah, I think that's it. It's because color 128 starts at $100 in cgram and sprites can only use the latter 128 colors.

I only found one document clarifying this though...
The background can use the first 128 colors in BG modes 0,1,2,5,6, and all
256 colors in BG modes 3,4,7 when not in direct color mode. Sprites always
use the latter 128 colors. Specific details about palette use and selection
for each mode will be described later.
User avatar
Ramsis
Posts: 341
Joined: Sun Jul 01, 2012 6:44 am
Location: Lion's den :3
Contact:

Re: Can someone explain palettes more in-depth to me?

Post by Ramsis »

Well, nocash's in-depth fullsnes documentation gives you an overview of palette indices. Looks like your assumption is right (and I was wrong). :)
Some of my projects:
Furry RPG!
Unofficial SNES PowerPak firmware
(See my GitHub profile for more)
Rai
Posts: 9
Joined: Sun Jul 15, 2012 8:19 pm

Re: Can someone explain palettes more in-depth to me?

Post by Rai »

Ramsis wrote:Well, nocash's in-depth fullsnes documentation gives you an overview of palette indices. Looks like your assumption is right (and I was wrong). :)
Thanks for that.

Unfortunately, I'm beginning to realize why there's not much SNES homebrew out there. There's a lack of asm examples on how to do things and the examples out there, make things too confusing.

Even with all the docs, you still mostly have to figure out everything yourself.

For instance, I've been trying to understand how simply move a sprite up and searching on google hasn't brung up anything good. I feel as though the only way I can figure it out is to figure out how a commercial snes game does it.
Last edited by Rai on Mon Mar 04, 2013 12:27 pm, edited 1 time in total.
User avatar
Ramsis
Posts: 341
Joined: Sun Jul 01, 2012 6:44 am
Location: Lion's den :3
Contact:

Re: Can someone explain palettes more in-depth to me?

Post by Ramsis »

Rai wrote:Even with all the docs, you still mostly have to figure out everything yourself.
Yeah, but that's part of the fun. :D
Some of my projects:
Furry RPG!
Unofficial SNES PowerPak firmware
(See my GitHub profile for more)
Rai
Posts: 9
Joined: Sun Jul 15, 2012 8:19 pm

Re: Can someone explain palettes more in-depth to me?

Post by Rai »

Ramsis wrote:
Rai wrote:Even with all the docs, you still mostly have to figure out everything yourself.
Yeah, but that's part of the fun. :D
Perhaps, but sometimes the only way to figure out clearly how to do a simple thing, is going into a commercial game and figuring it out.

Even doing something as simple reading joypad input is confusing with the current documents out there.

I might make my own SNES homebrew tutorial one day with ASM examples that are clear and have detailed comments.

Heck, I'm an experienced ASM hacker and still have trouble figuring out simple things even with all the docs out there. Imagine how hard it would be for a completely newbie.

Or maybe I'm just looking in the wrong places.
User avatar
Ramsis
Posts: 341
Joined: Sun Jul 01, 2012 6:44 am
Location: Lion's den :3
Contact:

Re: Can someone explain palettes more in-depth to me?

Post by Ramsis »

Rai wrote:sometimes the only way to figure out clearly how to do a simple thing, is going into a commercial game and figuring it out.
There's another approach: Make changes in an example like walker.asm, recompile it, and see what happens. This helped me a lot in the beginning anyway. :)
Rai wrote:I might make my own SNES homebrew tutorial one day with ASM examples that are clear and have detailed comments.
Yes, please do! :)
Rai wrote:Heck, I'm an experienced ASM hacker and still have trouble figuring out simple things even with all the docs out there. Imagine how hard it would be for a completely newbie.
True. And still, I think if you really want to do it, and learn to make good use of the docs that are out there, and study a lot of existing sourcecode -- then I think that even against all odds, you can get really far. :)
Some of my projects:
Furry RPG!
Unofficial SNES PowerPak firmware
(See my GitHub profile for more)
Rai
Posts: 9
Joined: Sun Jul 15, 2012 8:19 pm

Re: Can someone explain palettes more in-depth to me?

Post by Rai »

Ramsis wrote:
Rai wrote:sometimes the only way to figure out clearly how to do a simple thing, is going into a commercial game and figuring it out.
There's another approach: Make changes in an example like walker.asm, recompile it, and see what happens. This helped me a lot in the beginning anyway. :)
Rai wrote:I might make my own SNES homebrew tutorial one day with ASM examples that are clear and have detailed comments.
Yes, please do! :)
Rai wrote:Heck, I'm an experienced ASM hacker and still have trouble figuring out simple things even with all the docs out there. Imagine how hard it would be for a completely newbie.
True. And still, I think if you really want to do it, and learn to make good use of the docs that are out there, and study a lot of existing sourcecode -- then I think that even against all odds, you can get really far. :)
Well do you know any good examples of using the joypad?

I've looked and looked and looked and none of the examples have worked.
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Can someone explain palettes more in-depth to me?

Post by tepples »

Have you tried programming the NES first? Following an NES tutorial just might twist your brain into the right state to become able to generalize the knowledge to the Super NES.
psycopathicteen
Posts: 3140
Joined: Wed May 19, 2010 6:12 pm

Re: Can someone explain palettes more in-depth to me?

Post by psycopathicteen »

Rai wrote:
You can download the asm file for the sprite routine here:
http://www.mediafire.com/download.php?sb9bmmpnozdl1jc
Is that supposed to be your reset routine (routine that runs at bootup), or your nmi routine (routine that runs every frame)? This is how roughly your code should look like:

Code: Select all

reset:
jsr initialization
wai

nmi
jsr vblank
jsr gameplay
wai

org $00ffe0
interrupt_vectors:
dw 0,0,0,0,0,nmi,reset,0
dw 0,0,0,0,0,nmi,reset,0
BTW, "org" is not really an ASM instruction. I don't know what assembler your using, but on xkas, the "org" command tells xkas what address to write code to.
Rai
Posts: 9
Joined: Sun Jul 15, 2012 8:19 pm

Re: Can someone explain palettes more in-depth to me?

Post by Rai »

tepples wrote:Have you tried programming the NES first? Following an NES tutorial just might twist your brain into the right state to become able to generalize the knowledge to the Super NES.
It's nothing to do with the SNES, but more a lack of clear ASM samples on how to do anything.

I mean I've made several ASM hacks to SNES games, such as adding compression to text and even adding advance hacks like VWF's.

It's not that I don't understand ASM, it's not understanding one part of a particular code. Myself, I've done everything the examples have said, initialized all the joypad registers and the joypad register still loads zero.

But I certainly will write a homebrew document. If only so novice ASM guys can understand how to do simple things.
DoNotWant
Posts: 83
Joined: Sun Sep 30, 2012 3:44 am

Re: Can someone explain palettes more in-depth to me?

Post by DoNotWant »

I have been trying to wrap my head around SNES programming lately, have you had a look at these pages?
http://wiki.superfamicom.org/snes/show/HomePage
http://en.wikibooks.org/wiki/Super_NES_Programming

Also, this example file is nice. http://filebin.ca/T4jRsOzndk0
psycopathicteen
Posts: 3140
Joined: Wed May 19, 2010 6:12 pm

Re: Can someone explain palettes more in-depth to me?

Post by psycopathicteen »

Code: Select all

fetch_joypad:

lda #$01
sta $4200

wait_for_joypad:
lda $4212
and #$01
bne wait_for_joypad

lda $4218
sta !joypad1
lda $4219
sta !joypad1hi
lda $421a
sta !joypad2
lda $421b
sta !joypad2hi
rts
Here is the code I use.
mic_
Posts: 922
Joined: Thu Oct 05, 2006 6:29 am

Re: Can someone explain palettes more in-depth to me?

Post by mic_ »

My VGM player for the SNES uses a lot of stuff that a typical game would include: joypad input, audio playback, hdma effects, sprites, etc. The full (assembly) source code is available here.

To find the subroutine responsible for updating the OAM (sprites), search for UpdateOAM in t700c.asm.
Post Reply