(Link to AcmlmWiki) Offline: thank ||bass
Register | Login
Views: 13,040,846
Main | Memberlist | Active users | Calendar | Chat | Online users
Ranks | FAQ | ACS | Stats | Color Chart | Search | Photo album
06-21-24 09:55 PM
0 users currently in SMW Hacking.
Acmlm's Board - I3 Archive - SMW Hacking - Level Loader Sub-Routine New poll | |
Add to favorites | Next newer thread | Next older thread
User Post
1169

Red Goomba


 





Since: 03-27-06
From: Gold Coast, Australia

Last post: 6647 days
Last view: 6647 days
Posted on 04-06-06 02:36 AM Link | Quote
I looked through all the ROM maps I know of, and couldn't find this information . . . so if anyone knows it, any info would be much appreciated.

I am looking for a sub-routine that gets called when levels are loaded (not just from the overworld . . . from secondary exits as well. (I need to programmatically change sprite palettes).

In a post by Glyph Phoenix I read that x213B8 is called when levels load; but in a reply another poster pointed out it only gets called if you enter via the overworld.

I also need to know what level I am currently in. 7E13BF tells you the overworld level number, but this doesn't seem to correspond to the loaded level number.

I am posting this from work in the hope I will get a nice simple reply . . . otherwise it looks like I will have a nice long night of tracing ahead of me :/
BMF54123
WARNING: MOOD LEVEL CRITICAL








Since: 11-18-05
From: MOOGLES

Last post: 6333 days
Last view: 6332 days
Posted on 04-06-06 04:53 AM Link | Quote
Just set a breakpoint on writes to $7EC800. This is the start of the level layout in RAM, and it's initialized to #$25 every time a new level is loaded (from both the overworld and secondary exits). I'm sure you know what to do from there.

As for the level number, this patch will store it at $10B (16-bit). This is the "real" number reported by Lunar Magic, and it works for all levels, not just those loaded from the overworld. (If you're using my LevelASM system, you should already have this installed.)
1169

Red Goomba


 





Since: 03-27-06
From: Gold Coast, Australia

Last post: 6647 days
Last view: 6647 days
Posted on 04-06-06 05:41 AM Link | Quote
Excellent, thanks.

edit 1: added where I found a nice spot

edit 2: blah

Doh, I should have tested my locations before posting. My trace was 1 byte off so I screwed the disassembly up.

I found a new spot thought, and tested it.

It is a real pain in the arse to find a spot that is a) long enough; b) has ops which have long alternatives; and c) only get called once at the start of a level.

There are plenty of places near where 7EC800 gets written which get called 3 times at the start of each level, but that doesn't sit right with me.

I found a spot that only gets called once . . . thought it requires changing two other locations in ROM which isn't great; but works.

0583B2 to 0583B7

It is 2 JSRs - when you replicate them you obviously have to make them JSLs.

To make this work though you have to also go to:

0585D7 and change the RTS to a RTL; then go to
0582c7 and change the RTS to a RTL

Not ideal; but seems to work great.

====

While the above works fine, and it is good enough for what I want to do . . . if anyone else is looking to do similar and wants to find a spot that doesn't require changing the RTSs, I recommend starting in the 0581fb to 0582c7 block. It JMPs off to a few other locations which might be goot pickings. 0581fb to 0582c7 is only called once per level load as well.

I had a quick look through, but most of the ops didn't have long alternatives ):

By the way, all my addresses are as the SNES sees them, so use Lunar Address to get the PC addresses.


(edited by lynch82 on 04-06-06 07:13 AM)
(edited by lynch82 on 04-06-06 07:14 AM)
(edited by lynch82 on 04-06-06 10:19 AM)
(edited by lynch82 on 04-06-06 10:30 AM)
BMF54123
WARNING: MOOD LEVEL CRITICAL








Since: 11-18-05
From: MOOGLES

Last post: 6333 days
Last view: 6332 days
Posted on 04-09-06 04:37 AM Link | Quote
Generally, when I need to hook a JSR in order to JSL to my own code (which I keep in SNES bank $3F), I copy the original JSR to an empty space in the same ROM bank, along with my new JSL, then change the original JSR to point to the new location, like so:

JSR EmptySpace ;original JSR was here

:EmptySpace
JSR OriginalRoutine
JSL NewRoutine
RTS

I don't feel comfortable changing RTSes to RTLs because there's always the chance that the game will call the same routine later on, but from a different point, and using a JSR.
HyperHacker

Star Mario
Finally being paid to code in VB! If only I still enjoyed that. <_<
Wii #7182 6487 4198 1828


 





Since: 11-18-05
From: Canada, w00t!
My computer's specs, if anyone gives a damn.
STOP TRUNCATING THIS >8^(

Last post: 6333 days
Last view: 6333 days
Posted on 04-11-06 02:14 AM Link | Quote
That does work, but you need to put your code in the same bank which can be difficult. I prefer to just replace however many instructions I need with a JSL:

<original>
LDA $06
TAX
INX

<new>
JSL EmptySpace

EmptySpace:
LDA $06
TAX
INX
[do something cool here]
RTL

As long as they aren't stack-related instructions, you're fine (and if they are, you can sometimes get away with BRAnching to the new code and back).
BMF54123
WARNING: MOOD LEVEL CRITICAL








Since: 11-18-05
From: MOOGLES

Last post: 6333 days
Last view: 6332 days
Posted on 04-11-06 06:23 AM Link | Quote
Well, yeah, I use that method as much as possible...the method I posted is for those (thankfully) rare occasions when you need to hook the code at a specific point (like after a certain subroutine runs), and there simply isn't enough room for a JSL. Example:

JSR blah
STA $bleh
RTS

In this case, I need to intercept and modify the results from blah before they are stored to $bleh (I ran into such a situation last night when fixing gravity for layer 2 platforms). I can't JSL here because the original JSR needs to be called from the same bank. The only way I can do that is to redirect blah to an empty spot in the same bank, as explained in my previous post:

JSR emptyspot
STA $bleh
RTS

:emptyspot
JSR blah
JSL blarg ;this modifies A before storing to $bleh
RTS
Add to favorites | Next newer thread | Next older thread
Acmlm's Board - I3 Archive - SMW Hacking - Level Loader Sub-Routine |


ABII

Acmlmboard 1.92.999, 9/17/2006
©2000-2006 Acmlm, Emuz, Blades, Xkeeper

Page rendered in 0.038 seconds; used 377.72 kB (max 456.05 kB)