nesdev.com
http://forums.nesdev.com/

Can someone explain palettes more in-depth to me?
http://forums.nesdev.com/viewtopic.php?f=12&t=9882
Page 1 of 2

Author:  Rai [ Mon Mar 04, 2013 7:21 am ]
Post subject:  Can someone explain palettes more in-depth to me?

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

Author:  Ramsis [ Mon Mar 04, 2013 10:23 am ]
Post subject:  Re: Can someone explain palettes more in-depth to me?

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:
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. :)

Author:  Rai [ Mon Mar 04, 2013 10:42 am ]
Post subject:  Re: Can someone explain palettes more in-depth to me?

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:
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...
Quote:
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.

Author:  Ramsis [ Mon Mar 04, 2013 11:08 am ]
Post subject:  Re: Can someone explain palettes more in-depth to me?

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

Author:  Rai [ Mon Mar 04, 2013 12:13 pm ]
Post subject:  Re: Can someone explain palettes more in-depth to me?

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.

Author:  Ramsis [ Mon Mar 04, 2013 12:27 pm ]
Post subject:  Re: Can someone explain palettes more in-depth to me?

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

Author:  Rai [ Mon Mar 04, 2013 12:34 pm ]
Post subject:  Re: Can someone explain palettes more in-depth to me?

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.

Author:  Ramsis [ Mon Mar 04, 2013 12:55 pm ]
Post subject:  Re: Can someone explain palettes more in-depth to me?

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. :)

Author:  Rai [ Mon Mar 04, 2013 2:25 pm ]
Post subject:  Re: Can someone explain palettes more in-depth to me?

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.

Author:  tepples [ Mon Mar 04, 2013 2:48 pm ]
Post subject:  Re: Can someone explain palettes more in-depth to me?

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.

Author:  psycopathicteen [ Mon Mar 04, 2013 6:07 pm ]
Post subject:  Re: Can someone explain palettes more in-depth to me?

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:
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.

Author:  Rai [ Tue Mar 05, 2013 5:27 am ]
Post subject:  Re: Can someone explain palettes more in-depth to me?

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.

Author:  DoNotWant [ Tue Mar 05, 2013 11:51 am ]
Post subject:  Re: Can someone explain palettes more in-depth to me?

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

Author:  psycopathicteen [ Tue Mar 05, 2013 4:02 pm ]
Post subject:  Re: Can someone explain palettes more in-depth to me?

Code:
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.

Author:  mic_ [ Wed Mar 06, 2013 8:04 am ]
Post subject:  Re: Can someone explain palettes more in-depth to me?

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.

Page 1 of 2 All times are UTC - 7 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/