Joined: 7/17/2004
Posts: 985
Location: The FLOATING CASTLE
The number of lightning strikes is at 01E6. Still figuring out how that gets set. There may be ways to tweak it besides timing.
Ah, that's on the stack. Makes it harder to trace the code.
Joined: 7/17/2004
Posts: 985
Location: The FLOATING CASTLE
All right, it looks like Shadowgate's RNG subroutine is at $CB3A. The seed is at $0036. $0035 is always that number with the two nibbles reversed. Here is that subroutine:
LDA $0036 = #$55
CLC
ADC #$01
STA $0035 = #$55
CLC
ADC $0035 = #$56
CLC
ADC $0035 = #$56
CLC
ADC $0035 = #$56
CLC
ADC $0035 = #$56
STA $0036 = #$55
LSR
LSR
LSR
LSR
STA $0035 = #$56
LDA $0036 = #$AE
ASL
ASL
ASL
ASL
ORA $0035 = #$0A
STA $0035 = #$0A
RTS
Essentially, it takes the value at $0036 and adds one. Then that result gets multiplied by 5 with anything past a byte getting thrown away.
For the case of the lightning strikes it takes just the lower two bits of that result and adds 3. So you'll always get between 3 and 6 bolts. This code runs before it grabs that value and maybe multiple times, so the value that you see in $0036 the frame before isn't necessarily the one used. But if you hack that you'll be able to change your luck.
That randomization code seems to run every few frames when you wait. So you are able to get the right number of strikes by waiting.
So my advice to getting things to happen faster is to figure out ways you can change that seed at $0036 without taking time or taking less time. For example, you may be able to add fewer wait frames in other rooms to get the luck you need then.
Joined: 4/20/2005
Posts: 2161
Location: Norrköping, Sweden
Thank you very much for analyzing this, TheAxeMan. I'll see what I can do with it.
EDIT: On a related note, multiplying by 5 and adding 1 is exactly how randomness works in both Deja Vu and Uninvited. It seems they used that method for all 3 games.
EDIT2: Oh, I almost forgot - in my memory watch file, I have RAM address 04F5, and it appears that 0036 changes whenever this hits 0. Maybe that helps?
Joined: 4/20/2005
Posts: 2161
Location: Norrköping, Sweden
I have tried displacing the waiting frames to earlier parts of the run, but with no success of waiting shorter. It seems that no matter where I choose to wait, it won't make the RNG go faster.
I have a few things I want to check about the glasses trick, but other than that, I feel satisfied with the current product. ZenicReverie, do you have any more improvement ideas?
None at this time.
Something about the glasses glitching: at some point while you're glitching, the blank spaces will actually map back to functions rather than items. Using different actions on these blank spaces may do something different. Same with the items, but less likely.
Some examples. torch = 1 appeared, I closed it, and the beginning of the game text triggered. Motari appeared and I used it, and it thought I dropped bag 3 into the oil room. I tried to open it and I appeared in the room with the globe, but it glitched out completely and everything slowed down to a crawl. Good luck with this.
I'm going to look at the new video later today.
Joined: 4/20/2005
Posts: 2161
Location: Norrköping, Sweden
Yeah, I've looked into this, so I have a good idea on what can happen and what items you can get. You can also get bottle 5, flute, cloak, and bag 3 (including all the coins). And as you said, your inventory list will eventually start filling up with game state addresses (that determine what doors are open and such), and this means that you can also overwrite these values by picking up more and more glasses. I have also encountered that all sprites suddenly disappear from screen. I don't know exactly how this is triggered though. The game also crashes once you start overwriting the RNG addresses.
I have not actually been able to use this trick for something that can save time...
EDIT: I am making a list of all 256 possible item values, and what happens when you interact with them. So far I've found some interesting things, such as items acting as the oil (you can discard items into this item), items teleporting you just like the sphinx, and other random effects. Many items make the game crash when you interact with them. So far no effect is anything that could be useful in the TAS or speedrun. The best I've come is to get the orb this way, which is nice, but it's still faster to get it normally. Anyway, I'm still looking into this, maybe I will eventually find something useful...
EDIT2: Oooh, I found out how to get the staff this way! Maybe that can save time...
Joined: 4/20/2005
Posts: 2161
Location: Norrköping, Sweden
Sorry for double posting, but I have quite big news: I managed to beat the game in an entirely different way, using the glasses trick to get the staff. This is why I pick up more stones, since this sets RAM address 04DD to the Staff value, giving me access to it. This means that I did no backtracking, allowing me to skip Humana, Sword, Bottle2, Wand, and more. The downside is of course that it takes some time to perform the glasses trick. Still, I think it will save time. I played this in real time, just to check if it works, which it luckily did. Here's the movie file:
http://dehacked.2y.net/microstorage.php/info/1002746702/shadowgate_glasses_run.fm2
Suggestions and ideas are as always welcome!
EDIT: Slightly faster version here, where I figured out that it's faster to reach the staff at the end of the run by taking glasses again:
http://dehacked.2y.net/microstorage.php/info/1962722347/shadowgate_glasses_run_v1b.fm2
I will work on an optimized version of this route. It will be very interesting to see if it saves any time.
Joined: 4/20/2005
Posts: 2161
Location: Norrköping, Sweden
Hmm, yeah, you might have a point. I'll check that out.
EDIT: I'm kinda in a hurry, but I can inform you that I managed to improve the current run by 19.2 seconds with this new route:
http://dehacked.2y.net/microstorage.php/info/1744840148/shadowgate_glasses_run_v2.fm2
That means that this run is 27.6 seconds faster than the published run. The movie file above ends after using the staff on the behemoth, but the rest of the input is identical to all other versions. There are probably more potential improvements hiding in this run, since it is only the first optimized version of this new route, so expect an even bigger improvement before I submit anything. :)
Note: There is no luck involved in this new route (except for the lightnings at the end of the game), so it's also a very safe route for the console speedrun.
EDIT: 2.42 seconds saved by taking glasses to scroll to the end of the item list at the end of the run. This is now 1802 frames, 30.03 seconds, faster than the published run. Nice!
http://dehacked.2y.net/microstorage.php/info/1743735795/shadowgate_glasses_run_v2b.fm2
I also tried to edit in taking water after flute and ring, since this would save some time in the horn room, but this caused me to have really bad luck on the lightning scene for some reason...
Nice job taking advantage of the last room not using torch charges. It makes the TAS even more hilarious when the secret is revealed.
Ooh, big nasty behemoth. Wait, aren't I missing something?
*rifles through inventory*
Hold on, I know I've got something in here.
*warlock sits there with his arms up in the air*
Ha-ha! I have cobbled together a mystic Staff of Ages from 56 pairs of glasses! Take, that behemoth!
*behemoth screams in disbelief*
Congratulations on breaking Shadowgate.
Joined: 4/20/2005
Posts: 2161
Location: Norrköping, Sweden
BoursinBurger wrote:
Nice job taking advantage of the last room not using torch charges. It makes the TAS even more hilarious when the secret is revealed.
Ooh, big nasty behemoth. Wait, aren't I missing something?
*rifles through inventory*
Hold on, I know I've got something in here.
*warlock sits there with his arms up in the air*
Ha-ha! I have cobbled together a mystic Staff of Ages from 56 pairs of glasses! Take, that behemoth!
*behemoth screams in disbelief*
Congratulations on breaking Shadowgate.
Hi Randil,
I haven't found much, hopefully some of this helps.
Should be 2 frames:
when hitting the stone, go down twice and on to the screen instead of going up three times and on to the screen
These are less likely, but some ideas...
after taking the last stone, going down to the menu and back on to the screen.
starting in the Epor room use cloak on self, use torch=1, use Epor, take torch=1, take broom, use hammer, use key 3... this puts the torch on page 2 for use right before the broom or arrow depending on how far using the torch early can carry you.
Side question:
why do you go right twice when you use the torch=2? is this to burn the RNG?
Joined: 4/20/2005
Posts: 2161
Location: Norrköping, Sweden
ZenicReverie wrote:
when hitting the stone, go down twice and on to the screen instead of going up three times and on to the screen
...
after taking the last stone, going down to the menu and back on to the screen.
Thanks, these two combined saved 11 frames.
ZenicReverie wrote:
starting in the Epor room use cloak on self, use torch=1, use Epor, take torch=1, take broom, use hammer, use key 3... this puts the torch on page 2 for use right before the broom or arrow depending on how far using the torch early can carry you.
Very good idea, looking back at this section makes me think that my way of doing it was quite bad. I combined this with learning epor later, after having manually switched to the spells page, saving me some page scrolling. I got to use the torch right before the broom, which was very convenient. All this saved 79 frames! Amazing!
ZenicReverie wrote:
why do you go right twice when you use the torch=2? is this to burn the RNG?
You mentioned before that taking the water after the flute and ring would help, but be bad for the RNG for the lightnings. Is this still the case? Will it always be the case?
Joined: 4/20/2005
Posts: 2161
Location: Norrköping, Sweden
ZenicReverie wrote:
You mentioned before that taking the water after the flute and ring would help, but be bad for the RNG for the lightnings. Is this still the case? Will it always be the case?
Taking the water after the flute is faster since it saves a page scroll in the hell hound room, it. The reason it causes the bad RNG is that during this page scroll, the RNG stands still, and taking the water after the flute takes a few more "playing time", i.e. time that the RNG timer ticks - basically, although taking the water after the flute takes less frames, it takes more "RNG frames" so to say, so once I reach the warlock those frames where there are only 3 lightnings have already passed.
EDIT: If an improvement is found earlier in the run, it might be the case that taking the water after the flute will be faster, but as the RNG is in the TAS right now, it is not.
I see, so for a console run, I should swap the order since I can't really manipulate the RNG in the first place. Good to know. I'll be taking a final look tonight, but I think the video is mature enough to put; we'll see if I find anything else. Thanks for the acknowledgement, and congratulations on breaking the game so well. :D
Timed the route for my console run and I gained more time than I thought my just adding this in (about 20 seconds). This will definitely drive the console run below 14.
So, some things I've noticed that may save time in the TAS...
I've been opening the door in the Sphere room from the mini-map when I first enter instead of waiting until after I take the Sphere. Does this help any?
Key 4 is on page 3, does it make sense to use this key until after getting the talisman? I've been doing it to save a charge on the torch since it's such a tight point, and any actions I could potentially push off until later seem to be worth it.
Joined: 4/20/2005
Posts: 2161
Location: Norrköping, Sweden
Hello again! I'm glad to hear you're getting such good times with this route.
ZenicReverie wrote:
I've been opening the door in the Sphere room from the mini-map when I first enter instead of waiting until after I take the Sphere. Does this help any?
This won't save any time since you would still move the cursor to the very same position on the photo when entering the dragon room. Of course, since opening the door on the minimap isn't out of the way, doing it this way should be exactly as fast.
ZenicReverie wrote:
Key 4 is on page 3, does it make sense to use this key until after getting the talisman? I've been doing it to save a charge on the torch since it's such a tight point, and any actions I could potentially push off until later seem to be worth it.
I did a detailed comparison, and doing it this way is 11 frames (0.18 sec) slower than the way it's done in the TAS, so it's a very close call.
Yeah, they were long shots, as well as this one.
Quick thought though... using a stone on the sling just before we page flip to the scepter. This would put the orb on the second page after we use the blade. Not sure if it would save any significant time.
The extra dialogue probably makes it slower, but I just hate having to flip the page to get to the orb.
Joined: 4/20/2005
Posts: 2161
Location: Norrköping, Sweden
ZenicReverie wrote:
Quick thought though... using a stone on the sling just before we page flip to the scepter. This would put the orb on the second page after we use the blade. Not sure if it would save any significant time.
After having used the blade, we will still need to switch pages the same number of times until we reach the staff, so it won't save many frames (it will probably save a few due to shorter menu movement, but not a lot), and the extra dialogue will, as you said, negate this. My guess is that it will be slightly under a second slower, so it might be worth it in the speedrun if it's more convenient and less prone to mistakes.
Quick thought though... using a stone on the sling just before we page flip to the scepter. This would put the orb on the second page after we use the blade. Not sure if it would save any significant time.
After having used the blade, we will still need to switch pages the same number of times until we reach the staff, so it won't save many frames (it will probably save a few due to shorter menu movement, but not a lot), and the extra dialogue will, as you said, negate this. My guess is that it will be slightly under a second slower, so it might be worth it in the speedrun if it's more convenient and less prone to mistakes.
Yeah, I might try it to see if it helps at all since in the console run menu navigation is much slower. Looking back at the run though, it's possible to do this as early as the cyclops, but also when using the red gem. Something else I just thought of though, which probably negates this whole idea, is having one less thing in my inventory means I have to take 1 more pair of glasses to offset it. Yeah, I'm pretty much out of ideas for improving the run.