News: 11 March 2016 - Forum Rules

Author Topic: Tales of Phantasia - Palette Issue  (Read 7207 times)

justin3009

  • Hero Member
  • *****
  • Posts: 1666
  • Welp
    • View Profile
Tales of Phantasia - Palette Issue
« on: January 23, 2013, 10:45:53 pm »
Basically what I'm doing is trying to make the Layer 3 effect of water reflections, shadows, etc.. use the same palette that's originally there for the PC's.  The palette in BOTH locations is exactly the same.

7FCC60 the Elven Village is PC/NPC palettes
7FCCE0 is the same thing but for Shadows/water reflections.  EXACTLY the same palette mind you.



This is what happens when altering to force it to load the original palette.  What the heck would cause this effect to happen?  I can't really seem to locate the data for it.

Code: [Select]
$C2/0800 BD 09 00    LDA $0009,x[$7E:2149]   A:0020 X:2140 Y:0006 P:envMxdizC - Load palette #
$C2/0803 0A          ASL A                   A:0007 X:2140 Y:0006 P:envMxdizC - 07 is it.  Set it to 03 and only reflection shows with lighter hue
$C2/0804 05 2B       ORA $2B    [$00:002B]   A:000E X:2140 Y:0006 P:envMxdizc
$C2/0806 49 80       EOR #$80                A:002E X:2140 Y:0006 P:envMxdizc
$C2/0808 29 CF       AND #$CF                A:00AE X:2140 Y:0006 P:eNvMxdizc
$C2/080A 09 10       ORA #$10                A:008E X:2140 Y:0006 P:eNvMxdizc
$C2/080C 85 2B       STA $2B    [$00:002B]   A:009E X:2140 Y:0006 P:eNvMxdizc

Note: 7E002B is never loaded again except just for that ORA.

Code: [Select]
$C2/0442 A5 30       LDA $30    [$00:0030]   A:0212 X:25F0 Y:000E P:envMxdiZc
$C2/0444 38          SEC                     A:0217 X:25F0 Y:000E P:envMxdizc
$C2/0445 E9 04       SBC #$04                A:0217 X:25F0 Y:000E P:envMxdizC
$C2/0447 85 30       STA $30    [$00:0030]   A:0213 X:25F0 Y:000E P:envMxdizC
- NOP this and set 7E2149 to 03 (PC palette) and he'll still appear above the other Layers and will take layer effects. Layer 3 is just screwed up still.
« Last Edit: January 24, 2013, 08:17:13 am by justin3009 »
'We have to find some way to incorporate the general civilians in the plot.'

'We'll kill off children in the Juuban district with an infection where they cough up blood and are found hanging themselves from cherry blossom trees.'

Nightcrawler

  • Hero Member
  • *****
  • Posts: 5795
    • View Profile
    • Nightcrawler's Translation Corporation
Re: Tales of Phantasia - Palette Issue
« Reply #1 on: January 24, 2013, 09:12:25 am »
Only sprites with palettes 4-7 participate in color math. That's why the game uses 0-3 for the main sprites and 4-7 for the reflection sprites.

I would advise some good reading on how transparency works, with a good register doc. Follow that up with some examinations of the screen in VSNES (fantastic learning tool for how the screen is built). When you are able to see the building blocks of the screen and register tinkering like you can in VSNES, these types of problems become much easier to diagnose. A good debugger that can show you all PPU registers is also useful.

Items of Interest:
TransCorp - Over 20 years of community dedication.
Dual Orb 2, Wozz, Emerald Dragon, Tenshi No Uta, Glory of Heracles IV SFC/SNES Translations

justin3009

  • Hero Member
  • *****
  • Posts: 1666
  • Welp
    • View Profile
Re: Tales of Phantasia - Palette Issue
« Reply #2 on: January 24, 2013, 04:22:43 pm »
I'm reading some of it and it's kind of making me question a bit.  Does that mean if I want to use fully expanded palettes I will have to COMPLETELY drop off water, mirror and shadow transparency or something? :/ 
'We have to find some way to incorporate the general civilians in the plot.'

'We'll kill off children in the Juuban district with an infection where they cough up blood and are found hanging themselves from cherry blossom trees.'

Nightcrawler

  • Hero Member
  • *****
  • Posts: 5795
    • View Profile
    • Nightcrawler's Translation Corporation
Re: Tales of Phantasia - Palette Issue
« Reply #3 on: January 24, 2013, 08:42:05 pm »
I'm not sure what you mean by 'expanded palettes'. This is a hardware limitation. Each sprite (in any game) can normally only use 1 of the 16 palettes. However, if you plan to use color math (transparency) features with it, you can only choose palettes 4-7. This is the way the hardware works.
TransCorp - Over 20 years of community dedication.
Dual Orb 2, Wozz, Emerald Dragon, Tenshi No Uta, Glory of Heracles IV SFC/SNES Translations

justin3009

  • Hero Member
  • *****
  • Posts: 1666
  • Welp
    • View Profile
Re: Tales of Phantasia - Palette Issue
« Reply #4 on: January 24, 2013, 09:54:45 pm »
By expanded palettes I mean using the entirety of the sprite palette set.  4-7 is the same palette as 0-3.  Legitimately exactly the same.  But since Color Math is only 4-7.. it.. really screws a lot of things over.

And by the transparency stuff, the reason the game uses the limited palettes is for that effect exactly.  Since NPC/PC's all shared the same palette, they all had reflections in mirrors, water, etc..  But if I want to fully use the area WITHOUT repeated palettes and color math, I'd have to drop the water transparency, mirror reflections, etc..

« Last Edit: January 24, 2013, 10:33:21 pm by justin3009 »
'We have to find some way to incorporate the general civilians in the plot.'

'We'll kill off children in the Juuban district with an infection where they cough up blood and are found hanging themselves from cherry blossom trees.'

Nightcrawler

  • Hero Member
  • *****
  • Posts: 5795
    • View Profile
    • Nightcrawler's Translation Corporation
Re: Tales of Phantasia - Palette Issue
« Reply #5 on: January 25, 2013, 08:31:26 am »
Yes, that's pretty much true. I'm not sure how you could get around needing the duplication easily.

What did you intend to do with the extra palettes out of curiosity?
TransCorp - Over 20 years of community dedication.
Dual Orb 2, Wozz, Emerald Dragon, Tenshi No Uta, Glory of Heracles IV SFC/SNES Translations

Bregalad

  • Hero Member
  • *****
  • Posts: 2763
    • View Profile
Re: Tales of Phantasia - Palette Issue
« Reply #6 on: January 25, 2013, 09:53:28 am »
Another way would be to invert the color math layers, and make the water transparent.

Remember, the SNES basically does

(sprite + water) / 2

to make the transparent sprite in the water, so if instead it does

(water + sprite) / 2

it will of course be the same result.

If by luck the water layer is only used by water then you could hack the game to do this. But I think it's probably not the case.

justin3009

  • Hero Member
  • *****
  • Posts: 1666
  • Welp
    • View Profile
Re: Tales of Phantasia - Palette Issue
« Reply #7 on: January 25, 2013, 10:02:03 am »
It's not the case sadly.

 And I'm planning to import the psx sprites.  Seeing as there's a lot more palette usage there, I kinda have to drop those extra effects unless I can find some way for the characters to ask share one or two in areas with reflections
'We have to find some way to incorporate the general civilians in the plot.'

'We'll kill off children in the Juuban district with an infection where they cough up blood and are found hanging themselves from cherry blossom trees.'

Bregalad

  • Hero Member
  • *****
  • Posts: 2763
    • View Profile
Re: Tales of Phantasia - Palette Issue
« Reply #8 on: January 25, 2013, 10:08:57 am »
OK I've analyzed this further with SNES9x debug.
Tales of phantasia uses this (at least at the place I've checked it) :

Main screen (always on): BG0,BG1,BG2,OBJ,
Sub-screen (always on): BG2,
Subscreen addition(half):BG0,BG1,OBJ,

In other words - when a BG0, BG1, or OBJ palette 4-7 pixel is present in the main screen, it is averaged with the subscreen (BG2) (if applicable) then output to the screen. When only a BG2 pixel or OBJ with palette 0-3 is present (which is the case inside the water) the BG2 is send right through screen.

You could get the same configuration with the following setup (theoretical) :
Main screen (always on): BG0,BG1,BG2,OBJ,
Sub-screen (always on): BG0,BG1,OBJ,
Subscreen addition(half):BG2

This means - when a non-transparent BG2 pixel is present in the main screen, it is halved with BG0/BG1/OBJ (all palettes) and output to screen. If no BG0/BG1/OBJ pixel is present, the BG2 will be send right through the screen without being averaged (middle of the water) and if no BG2 pixel is present (a normal place) it is also sent to the screen without being averaged.

The problem is that *all* sprites will now be transparent with the water. What remains is that you could set the pirority bit in the BG2 so that it is above the spritres (= transparent) at the north of the water pool, and it is below the sprites (= non transparent) at the south of the water pool (so that the head of the characters won't look like it's in the water). This could cause problems with fishes suddently appearing non-transparent if they go too close of a south border of the pool, though.

justin3009

  • Hero Member
  • *****
  • Posts: 1666
  • Welp
    • View Profile
Re: Tales of Phantasia - Palette Issue
« Reply #9 on: January 25, 2013, 01:42:42 pm »
If I'm able to do that, I most definitely will.  The fish issue honestly wouldn't be a big problem.  If it came like that, could always use some sort of 'cheap' method to make them work.

January 30, 2013, 11:16:25 am - (Auto Merged - Double Posts are not allowed before 7 days.)
I'm trying to see if I can apply those settings you listed while forcing the PC's to load palette 0-4 as a test to see if it'll work.  I haven't exactly figured out how to set priority.. not sure how I can trace that through everything but I have found out some details.

7E13B5 - Layers on map.
7E13B6 - Layer 3 on map.  Change to 00, load menu and leave, no more shadows.

Setting this to 13 will load Layer 1/2 and Layer 3 will not load.
Setting this to 17 will load Layer 1/2 and Layer 3 WILL load up.

It reads farther in RAM where the data is written.  Each new layer is represented at 7F0000 by a '00 0F 00 0F xx xx xx xx' type sequence.

I wrote data into the Layer 3 bit as a test, nothing loaded.  Set 7E13B5 to 17 and sure as hell, Layer 3 showed up BUT the PC didn't appear BELOW Layer 3, he was ABOVE it.  I'm still very unsure how to make the priority of the sprite below Layer 3 in general.

The layer 3 I'm talking about right now ISN'T the reflections of the water, but rather the shadows given off in many areas.  Treant's Forest, Elven village etc.. The PC will appear above them annoyingly when the palette is set to 03 and that needs to be fixed before I go onto doing anything else.

Edit: 7E2150.  Set to 01 and you'll be below ALL layers and even be covered by shadows! Only issue, as said, you're below every single layer.

Actually, it seems what this does is flip the palette values.  So if you use 0-3, it'll now flip it to be value 4-7.  Basically used for invisibility type things I think.

Edit 2: If you force 7E214D to 17, you will be below layer 3 but normal on the other layers IF your palette # is 0-3.  However 4-7 will be ABOVE it now.  I'm trying to forcefully have all palettes 0-7 be BELOW Layer 3 but it's proving to be quite an ass.
« Last Edit: January 30, 2013, 12:46:23 pm by justin3009 »
'We have to find some way to incorporate the general civilians in the plot.'

'We'll kill off children in the Juuban district with an infection where they cough up blood and are found hanging themselves from cherry blossom trees.'

Bregalad

  • Hero Member
  • *****
  • Posts: 2763
    • View Profile
Re: Tales of Phantasia - Palette Issue
« Reply #10 on: January 30, 2013, 05:32:30 pm »
Oh, I forgot to mention, you should hack the game so that he sets the "priority bit" in the BGMODE register.

This registers should change from $01 to $09.

This way the priority will be changed from

SPRITES(3) -> BG1(HI) -> SPRITES(2) -> BG2(HI) -> BG1(LO) -> SPRITES(1) -> BG2(LO) -> BG3(HI) -> SPRITES(0) -> BG3(LO)

to

BG3(HI) -> SPRITES(3) -> BG1(HI) -> SPRITES(2) -> BG2(HI) -> BG1(LO) -> SPRITES(1) -> BG2(LO) -> SPRITES(0) -> BG3(LO)

I'm not 100% sure about the order but from memory it should be that. In one case BG3 is behind everything exept pehaps some sprites (which is what TOP originally uses), in the second case BG3 is either behind everything or above everything depending on the priority bit in the tile map.

What I was suggesting is having shadows and most of the waters with the priority bit to '1' so that all BG and sprites are behind it (transparent) with the exception of the south tiles of a water pool which should have their priority bit to '0' so that sprites are above it (no transparent).

Since reflexions can't ever be seen on the south of the pool, this should not cause problems. Same with the tiles just north of a bridge etc.... Any water tile at the north of a discontinuity should have it's priority bit become clear so that the head of the characters doesn't look like it's in water.

This is however not a trivial change to make in the game, and requires hacking a lot of maps.

justin3009

  • Hero Member
  • *****
  • Posts: 1666
  • Welp
    • View Profile
Re: Tales of Phantasia - Palette Issue
« Reply #11 on: January 30, 2013, 05:42:46 pm »
The main issue in itself right now is even trying to find how it sets the priority for the tiles.  I can't even seem to figure that out exactly which is causing a huge string of issues.
'We have to find some way to incorporate the general civilians in the plot.'

'We'll kill off children in the Juuban district with an infection where they cough up blood and are found hanging themselves from cherry blossom trees.'

Bregalad

  • Hero Member
  • *****
  • Posts: 2763
    • View Profile
Re: Tales of Phantasia - Palette Issue
« Reply #12 on: January 30, 2013, 05:46:53 pm »
I don't know but searching for the code that loads the map tiles to VRAM might be a good start. Also it's quite likely the priority is hard-coded for BG3 as they originally didn't use this bit (I think). But if they wanted it to be compatible with BG1/2 map format then pehaps you can change priorities without ASM hacking (in this case you're lucky).

justin3009

  • Hero Member
  • *****
  • Posts: 1666
  • Welp
    • View Profile
Re: Tales of Phantasia - Palette Issue
« Reply #13 on: January 30, 2013, 08:37:38 pm »
I found where they get stored into RAM and I THINK how they're loaded in general, but it doesn't help with the priority or anything as I can't quite understand how it works.  It's kinda like the menu where one byte can destroy the entire thing.
'We have to find some way to incorporate the general civilians in the plot.'

'We'll kill off children in the Juuban district with an infection where they cough up blood and are found hanging themselves from cherry blossom trees.'