øAslickproductions.org/forum/index.php?PHPSESSID=5f0fck550j2m4m2fpbtkj2vkm1&topic=2337.0e:/My Web Sites/Slick Productions - FFIV Message Board/slickproductions.org/forum/indexdad2-2.htmlslickproductions.org/forum/index.php?PHPSESSID=5f0fck550j2m4m2fpbtkj2vkm1&board=8.20e:/My Web Sites/Slick Productions - FFIV Message Board/slickproductions.org/forum/indexdad2-2.html.zx7$h^ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÈ ,/%OKtext/htmlISO-8859-1gzip0|Ö%ÿÿÿÿÿÿÿÿTue, 10 Mar 2020 23:51:43 GMT0ó°° ®0®P®€§²ð®6$h^ÿÿÿÿÿÿÿÿc0% Zelda 3: Attempting on-more-often Lamp/Lantern

Author Topic: Zelda 3: Attempting on-more-often Lamp/Lantern  (Read 1446 times)

assassin

  • Bane of Retards
  • *
  • Posts: 1,033
  • space bears are not gentle!
    • View Profile
    • My Barren Webpage
Zelda 3: Attempting on-more-often Lamp/Lantern
« on: February 07, 2017, 10:45:15 AM »
the SNES game gets rid of the lamp/lantern spotlight as soon as you light one torch.  that means the area around Link actually gets somewhat _darker_ when the rest of the room gets lighter.  this is dumb.  why should the Lamp/Lantern lose its perpetual burning ability just because you lit a torch?  the game's already docking you MP for said lighting, and it's possible you lit it with Fire Rod anyway.

the GBA version remedies this silliness by keeping the spotlight until slightly after you've lit 3 torches, and restoring it whenever the third goes out.

here is my pending attempt to do the same thing on SNES:

http://assassin17.brinkster.net/forum-posts/zelda-torches/torch-alpha1.zip

see contents-readme.txt for explanation of the files included.

applying both light-torch-new1.asm and torch-go-out-new1.asm will keep the original spotlight until you've lit 3 torches, and restore it whenever the third goes out.  however, it has an issue of a darkened ring around Link once two torches are lit, because it doesn't alter the perimeter of the spotlight as the room gets brighter.

the game achieves ambient room darkening/brightening and the lamp/lantern spotlight with color translucency math, specifically subtraction of a value ranging from 0 to 31.  if you turn off Transparency effects in Snes9x, you can see the black and dark gray spotlight on BG #1.  black has color components of zero value, so when it's subtracted from the room background, you keep full brightness, while subtracting gray makes it a little dimmer.  everything outside this spotlight overlay is subject to the room-wide color reducer, which is determined by different target values based on # of torches lit: 0 torches = 31, 1 = 8, 2 = 4, 3+ = 0 .  the reducer isn't immediately set to these values, but gradually adjusted to meet them.

finding the black and gray overlay in ROM and drawing a larger alternate would make a nice feature for a Super Lamp, btw.

i considered dealing with the darkened ring around Link by having alternate-colored overlays depending on the lit torch count, but this'd take a bit of extra ROM space.  also, it wouldn't match the GBA's nice behavior of having the outer edge of the spotlight change gradually in response to torch lighting/extinguishing, much as the rest of the room already does.

dynamically redrawing the gray pixels would be too slow and involved, so i went at it a third way: the outer spotlight's palette.  it's Palette 11h, and has default color component values of 6.  i modify it from an interrupt routine based on the ambient color reducer.  hopefully, entry 11h is always used for the spotlight, it has 6s everywhere it's used, and it's not used for anything else; otherwise, there'll be omissions and side effects.  the fact that 11h is outside the range of entries in the 7E/C500 palette table that get darkened then gradually lightened when you enter a room gives me some confidence that it's a special case and there won't be conflicts.

also, having my new code run 60 times a second in a speed-sensitive routine might cause issues, though it seems alright in Snes9x.  calling it this often does allow me to gradually alter the outer ring.

there are three versions of the palette adjuster included.

i welcome feedback on all files, and discussion of the optimal color adjustment.  it'd be damned cool to have a "master formula" based on the color reducer's distance from 31, as well as its distance from the default value of the region being altered.  but that might be too elusive to pin down, or too involved to code.  so individually deciding the result of all 32 input values is also an option.

even with the patch, the SNES version still gets rid of the overlay as soon as the 3rd torch is lit, so there'll be a few frames where the area around Link is darker than it was just before.  in contrast, the GBA gradually phases out the spotlight.  (i'm impressed by what they did on that version, even if the outer portion of the spotlight has that silly checkering.)  ways to match this might be keeping the overlay on all the time (a bit CPU-intensive), or creating a custom "overlay removal pending" variable (harder to code).

finally, help in making sense of Function 0D/FA33 and Variable $0458 would be appreciated.

Xenovant

  • Tunnel Armor
  • *
  • Posts: 154
  • (ಠ_ಠ)
    • View Profile
Re: Zelda 3: Attempting on-more-often Lamp/Lantern
« Reply #1 on: February 07, 2017, 12:34:26 PM »
I'm interested on this patch, I have a "minor hack" of alttp and it would be a great addition :P

I have tested the 3 patches (all of them work, of course) and I prefer the 5B one, it looks perfect, at least for me.

finally, help in making sense of Function 0D/FA33 and Variable $0458 would be appreciated.

You could ask at Zeldix. Here, I don't know if someone else, besides me, is interested on "hacking" this game, and I don't know a sh*t about its code...  :happy:
« Last Edit: February 07, 2017, 12:40:26 PM by Xenovant »

Lenophis

  • Forum Overlord
  • *
  • Posts: 1,688
  • Gender: Male
  • I sad
    • View Profile
    • Slick Productions
Re: Zelda 3: Attempting on-more-often Lamp/Lantern
« Reply #2 on: February 07, 2017, 12:55:35 PM »
MathOnNapkins, who knows a great deal about the inner workings of Link to the Past, has said he will get to responding shortly. How long that is, we'll never know.

119 bugs fixed and counting.

assassin

  • Bane of Retards
  • *
  • Posts: 1,033
  • space bears are not gentle!
    • View Profile
    • My Barren Webpage
Re: Zelda 3: Attempting on-more-often Lamp/Lantern
« Reply #3 on: February 07, 2017, 02:07:41 PM »
Xenovant: thanks for testing.  if you have the time and patience, can you go through frame-by-frame when torches are being lit/extinguished (preferably in a debugger with variables 00/009C, 009D, and 009E being displayed), and see if it looks good at every step?  "good" can be defined by common sense, your understanding of how the light physics should work, or both.  i've tried, and as mentioned in file-contents.txt, am a bit on the fence as for changing the last few thresholds for outer palette lowering (read: brightening) from 1, 3, and 5 to 2, 4, and 6.  this wouldn't affect the "resting" brightness for a given torch level, but would affect transitional ones with 1 to 3 torches lit.  other thresholds are also on the table, of course.

if not, also fine, as i realize it's tedious.

Xenovant

  • Tunnel Armor
  • *
  • Posts: 154
  • (ಠ_ಠ)
    • View Profile
Re: Zelda 3: Attempting on-more-often Lamp/Lantern
« Reply #4 on: February 07, 2017, 02:25:12 PM »
Sure, I'll do it tonight. Right now I was looking for something to do today xD

Xenovant

  • Tunnel Armor
  • *
  • Posts: 154
  • (ಠ_ಠ)
    • View Profile
Re: Zelda 3: Attempting on-more-often Lamp/Lantern
« Reply #5 on: February 07, 2017, 05:52:06 PM »
Done  :tongue:

I think 2,4,6 seems more natural. The map's darkness/light should affect the "outer light" first, since it's weaker, and then the inner one. Using 1,3,5 it's the opposite, it seems to affect the inner light first.

assassin

  • Bane of Retards
  • *
  • Posts: 1,033
  • space bears are not gentle!
    • View Profile
    • My Barren Webpage
Re: Zelda 3: Attempting on-more-often Lamp/Lantern
« Reply #6 on: February 07, 2017, 06:58:28 PM »
thanks!  to be sure, the inner light is always the same: zero being subtracted from the map's backgrounds and the sprites, aka full brightness.  though the outer light changing too slow or fast can provide less than plausible or aesthetic contrasts from the inner.

on the topic of the surrounding map's darkness/light affecting the "outer light"...  one reason i have for minimal palette changes at higher color reducer values (i.e. darker rooms) in 5B is that if the outer light is already at 6 value due to residual brightness from the inner light's 0 value, without any help from room torches, then the surrounding room going from 31 down to let's say 28 shouldn't budge anything because both levels are so far from the outer light's level.  whereas going from 28 to 25 is more "relevant" because those are closer to 6.

but it's possible things don't work that way, and the reasoning is complete bullshit.  in which case i have the more proven fallback of "gamma correction". :D

Xenovant

  • Tunnel Armor
  • *
  • Posts: 154
  • (ಠ_ಠ)
    • View Profile
Re: Zelda 3: Attempting on-more-often Lamp/Lantern
« Reply #7 on: February 07, 2017, 07:43:40 PM »
What you should worry about now, is this, the dark rooms where the character doesn't use the lamp  :laugh: . I don't know if it happens to you too, but now, they make me feel uneasy xD

Quote
the inner light is always the same: zero being subtracted from the map's backgrounds and the sprites, aka full brightness.

Oops, true:P

assassin

  • Bane of Retards
  • *
  • Posts: 1,033
  • space bears are not gentle!
    • View Profile
    • My Barren Webpage
Re: Zelda 3: Attempting on-more-often Lamp/Lantern
« Reply #8 on: February 07, 2017, 08:42:22 PM »
good catch..  i'd read about some rooms defaulting to torches on, but didn't know which.  studying this one, which apparently starts at 2 invisible lit torches, might help me understand Function 0D/FA33 better.

i'd regard correct behavior in such a room as giving some spotlight -- provided you have the Lamp.  said function does check for the item, so entering the room shouldn't give premature spotlight, but the torch lighting/extinguishing ones don't.  so a hack that lets you get Fire Rod before the Lamp/Lantern could pose problems in those -- with and without my patch.

once i understand this function (particularly Variable $0458), i'll need to edit it, probably to exit on 3+ lit torches.

Xenovant

  • Tunnel Armor
  • *
  • Posts: 154
  • (ಠ_ಠ)
    • View Profile
Re: Zelda 3: Attempting on-more-often Lamp/Lantern
« Reply #9 on: February 08, 2017, 09:21:16 AM »
I was wondering something... Precisely on that chest, you can get the lamp if you didn't get it earlier at the character's home. What would happen if you add the spotlight/lamp check to that room and get the lamp there?

If the check is executed just when you enter a room you would need to exit and reenter the room for seeing the spotlight (or light a torch), and you'd have to fix that.


assassin

  • Bane of Retards
  • *
  • Posts: 1,033
  • space bears are not gentle!
    • View Profile
    • My Barren Webpage
Re: Zelda 3: Attempting on-more-often Lamp/Lantern
« Reply #10 on: February 08, 2017, 11:06:53 AM »
oh man, guess i'll have to hook the chest-opening code, and if Lamp was awarded, call a new special function.  hopefully, Variables $18, $11, and $B0 are just torch-specific, and i won't have to understand how they work nor alter them.  but i will probably need to understand $0414 and $0458.

as for 0D/FA33, it seems to be called when you enter a room (or twice if you fall into it.. why?!), which doesn't include transitions within 4x4-grid areas (as viewed in Hyrule Magic).

assassin

  • Bane of Retards
  • *
  • Posts: 1,033
  • space bears are not gentle!
    • View Profile
    • My Barren Webpage
Re: Zelda 3: Attempting on-more-often Lamp/Lantern
« Reply #11 on: February 08, 2017, 04:50:26 PM »
argh, it's gonna be more complicated.

in some dark rooms, you can see spotlight overlays in Hyrule Magic if you change the BG2 property from "Dark Room" to "Normal" (or various others) and toggle the BG1 or BG2 checkboxes.  two rooms that don't have them show up are:

1) Ganon battle room.  it has 02h in Variable $0414 (which is BG related per MathOnNapkins' RAM doc).  it has 3 torches lit to start, with one being an offscreen torch that always stays on.  the room works a bit weird in that once you light the two torches, then when they each go out, having one (visible one) on is no brighter than having two.

trying with my patch enabled doesn't cause any differences i can see..  probably because the game constantly overwrites the overlay variable with 0 in most cases, or 2 if you have one visible torch lit.  (a value of 1 is what enables the spotlight, though it likely wouldn't work in this room anyway.)

2) the Uncle/Lamp one you brought up.  it does not have 02h in Variable $0414, and while there are 2 torches lit somewhere, i can't tell where in Hyrule Magic.  using my current patch will present problems after i light a torch, and it goes out.  the doorways are too dark, and there is subtle bluish stuff on top of various areas.

--------

so i want to avoid enabling the spotlight in these places, and anywhere that doesn't support it.  and i want to avoid hardcoded Room ID checks like the plague, because even if they didn't bloat the code, using them would make me a worthless jagoff who needs to commit suicide.

while Nintendo got away with not checking Variables $0414 and $0458 for the torch lighting and extinguishing, that might be because they use 0/1 torches lit as their spotlight cutoff.  i'm using 2/3, which changes things.  for the Ganon battle, i can check for ($0414 == 2) like Nintendo already does in Function 0D/FA33, or maybe use $0458.  for the Uncle/Lamp room, the former's not an option, so i'd need to check $0458.

a theoretical way would be checking if the room's "original" lit torch count is above zero, but that information won't be available to me for torch lighting and extinguishing, so i need to deduce it from other variables.

-------

0D/FA33 mysteries:

does it exit when $0458 is nonzero purely to avoid incrementing that variable twice, or are there situations where it can actually stop Var $1D from becoming 1?

is the Var $0414 check after the $0458 increment for a reason; i.e. are there rooms where Var $0414 is 2 but you'd actually want $0458 to be 1?

-------

rattle off as many partially-lit rooms as you can think of.  i should check whether ANY of these enable the spotlight overlay when entering, and whether they can support it if put there.

to start things, there's Aginah's room, and i think the old man's cave on Death Mountain.
« Last Edit: February 08, 2017, 04:57:10 PM by assassin »

Xenovant

  • Tunnel Armor
  • *
  • Posts: 154
  • (ಠ_ಠ)
    • View Profile
Re: Zelda 3: Attempting on-more-often Lamp/Lantern
« Reply #12 on: February 08, 2017, 05:25:08 PM »
I was going to joke, saying that you should fix, too, the spotlight when Link exits a room (for example using the stairs up or down), because it isn't centered on the character, but reading your posts I think that right now, you would kill me xDD

If I were the one trying to make the patch, I would be like this




Quote
and while there are 2 torches lit somewhere, i can't tell where in Hyrule Magic.

I have found them, the torches are hidden on the upper part of the map

« Last Edit: February 08, 2017, 06:17:18 PM by Xenovant »

assassin

  • Bane of Retards
  • *
  • Posts: 1,033
  • space bears are not gentle!
    • View Profile
    • My Barren Webpage
Re: Zelda 3: Attempting on-more-often Lamp/Lantern
« Reply #13 on: February 08, 2017, 07:08:34 PM »
thanks; that makes sense of at least one aspect.

@ picture: haha..  i knew it had to be harder than the smooth sailing it's been so far.  just hooking an interrupt to do what i want would be ballsy in a game i knew very well, like FF6.  and i don't know Zelda 3 that well, so this was begging for a lightning bolt.  now, the current problem has nothing to do with the interrupt, but it all balances out cosmically. :P

i just visited the Lamp/Uncle room on GBA (Euro version, as that's what has the uber savestate), and there's no spotlight, both before and after lighting/expiring the torch.  as mentioned, this version of the game is pretty robust on how it handles the spotlight (i.e. changes it gradually, even after lighting the third torch), so i don't feel the need to exceed their high bar.  there might well be technological reasons why certain rooms don't have it to start with, as translucency is a hardware feature (at least on SNES; while GBA supports it too, i dunno if the port implements any through software instead).  so that solidifies my decision to disable the spotlight on that room.  of course, the details of how to do so are still pending.

assassin

  • Bane of Retards
  • *
  • Posts: 1,033
  • space bears are not gentle!
    • View Profile
    • My Barren Webpage
Re: Zelda 3: Attempting on-more-often Lamp/Lantern
« Reply #14 on: February 08, 2017, 08:58:48 PM »
huh.. looks like GBA has the torch count of 2 in Aginah's room and the old man's cave, but then ignores it and has the rooms at full brightness.  weird.