News:

Don't forget to visit the main site! There's lots of helpful docs, patches, and more!

Main Menu

[SM] [HEX] Adding New States

Started by Zero One, February 10, 2012, 02:49:06 PM

Previous topic - Next topic

Zero One

First off, I'm aware that there is a guide for doing this and there is also SMAll. SMAll looks pretty complex for me, and I prefer working with hex directly. However, I'm having trouble following JAM's guide. This is my room header, with the same legend that JAM uses:

[spoiler=Header]
78000: 00 00 21 00 09 05 70 A0 00 57 80 E6 E5 00 80 C3
78010: 00 0C 00 00 80 00 80 00 80 00 00 27 80 00 00 00
78020: 00 00 80 00 00 00 E0 02 02 02 02 02 02 02 02 02
78030: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02
78040: 02 02 02 02 02 02 02 02 02 02 02 00 00 00 00 00
78050: 00 02 02 02 28 02 80 00 95 10 95 20 95 30 95 00
78060: 00

Legend:
Green: Offset
Pink: Door Out Pointer
Blue: Door Array
Orange: Scroll Array
Brown: Special Scroll Data
Red: Pointer for Level Data
Teal: States
[/spoiler]

What I want to do is add a new state to this room. It will use the same dimensions and the same scrolls, so I won't need to change the pointers for those. What I need to know is, where do I insert the data and what is the data?

squishy_ichigo

#1
ok, I'm use more or less the same colors you used.
This is the MDB data, and I will label each part of it to better explain it.

78000: 00 00 21 00 09 05 70 A0 00 57 80 E6 E5 00 80 C3
78010: 00 0C 00 00 80 00 80 00 80 00 00 27 80 00 00 00
78020: 00 00 80 00 00 00 E0 02 02 02 02 02 02 02 02 02
78040: 02 02 02 02 02 02 02 02 02 02 02 00 00 00 00 00
78050: 00 02 02 02 28 02 80 00 95 10 95 20 95 30 95 00
78060: 00

White: Hex Offset
Pink:  MDB Header (11 bytes)
Teal: State Selection (variable, 2 bytes minimum)
Red: Room State (26 bytes each)
Orange: Scroll Data (variable)
Brown: Scroll PLM Data (variable)
Blue: Door_out Data (variable)

ok. Now, what you want to do, is add another state. This means you will need to extend the State Selection beyond the 2 byte minimum. 
The game reads the next two bytes after the MDB Header to know what to do with states.
E6 E5 tells the game that the next 26 bytes is being used for the Room State.
12 E6 is used for event bit states, while other none event bit states use a different pointer. I will not be explaining those states at this time. After 12 E6, is a single byte, which tells the game which event bit to check. If set, it will use the next two bytes as a pointer to the Room State, otherwise, it will continue. So, for example:

12E6 0E 4893 <-- 'second' event state
12E6 00 2E93 <-- 'first' event state
E6E5  <-- next 26 bytes are standard state

Now to explain the pointers to the Room States. Each state can have its own pointers. IE. Room data, FX1, enemies, plms, scrolls, etc. All this is held in the Room State. After E6 E5, the game uses the next 26 bytes as the Standard state, but to reach any other states, you need to point to them with the State Selection pointer.  Just take the offset that the Room State for the next state starts at, and stick it here.

Now, to do all the work for you, so you can understand it. :D

78000: 00 00 21 00 09 05 70 A0 00 57 80 12 E6 0E 2C 80
78010: E6 E5 00 80 C3 00 0C 00 00 80 00 80 00 80 00 00
78020: 27 80 00 00 00 00 00 80 00 00 00 E0 00 80 C3 00
78030: 0C 00 00 80 00 80 00 80 00 00 27 80 00 00 00 00
78040: 00 80 00 00 00 E0 02 02 02 02 02 02 02 02 02 02
78050: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02
78060: 02 02 02 02 02 02 02 02 02 02 00 00 00 00 00 00
78070: 02 02 02 28 02 80 00 95 10 95 20 95 30 95 00 00


Green: New State

Note the State Selection here. 0E is the event bit to check, and it points to 7802C, which is the new Room State.

Now, You'll be wanting to change changing the scroll, door_out, pointers since they have now shifted to what ever the new offset for them is. I didn't do that for you in the example, just use SMILEs pointer popup.

Reference Material

JAM

#2
OK, this is already solved. But you may need extra info. Alternate state pointer may lead to any place in the bank $8F, not also to the same MDB header. Can be useful if insert alternate state check in existing room