Level Script Engine Commands & Info 1 2 »
Users browsing this thread: 1 Guest(s)

We could use a level script engine thread

Commands: (with dirty pseudo code notes)
0x00 (8037E2C4): Load raw data to RAM segment and jump
 00 10 00 [XX] [YY YY YY YY] [ZZ ZZ ZZ ZZ] [AA AA AA AA]
 X = RAM segment number
 Y = ROM address start
 Z = ROM address end
 A = Segment offset of jump target
 
 Used for loading level scripts and then jumping to an offset in them

 Does stuff with 8039b8b0,b8b4
 Call 802783E8
 Call 8027868C (A0 = X, A1 = Y, A2 = Z, A3 = 0)
 Call 80277F50 (A0 = A)
   Command pointer = return value
______________________________________________________________________________________________________
0x01 (8037E388): Load raw data to RAM segment and jump
 01 10 00 [XX] [YY YY YY YY] [ZZ ZZ ZZ ZZ] [AA AA AA AA]
 X = RAM segment number
 Y = ROM address start
 Z = ROM address end
 A = Segment offset of jump target
 
 The only difference between this command and 0x00 is a call to 0x80278498
 
 Does stuff with 8039b8b0,b8b4
 Call 80278498
 Call 802783E8
 Call 8027868C (A0 = X, A1 = Y, A2 = Z, A3 = 0)
 Call 80277F50 (A0 = A)
   Command pointer = return value
______________________________________________________________________________________________________
0x02 (8037E404): ?
 02 04 00 00
   Always followed by null padding, last command in a script?
   performs a jump using 8038b8a0,b8b4
______________________________________________________________________________________________________
0x03 (8037E47C): ?
0x04 (8037E4FC): ?
0x05 (8037E580): ?
0x06 (8037E5B8): ?
______________________________________________________________________________________________________
0x07 (8037E620): ?
 t6 = w@ 8038B8B0
 t7 = (t6 - 4)
 w@ 8038B8B0 = t7
 Command pointer = w@ t7
______________________________________________________________________________________________________
0x08 (8037E650): ?
0x09 (8037E6D4): ?
0x0A (8037E780): ?
0x0B (8037E7F8): ?
0x0C (8037E878): ?
0x0D (8037E8E8): ?
______________________________________________________________________________________________________
0x0E (8037E988): ?
 0E 08 [XX] 00 [YY YY YY YY]
______________________________________________________________________________________________________
0x0F (8037EA18): Skip next command ??
 0F [XX] ...
 Increment command pointer by X
 If next command is 0x10, recurse
 Else, skip next command
______________________________________________________________________________________________________
0x10 (8037EA70): No operation
 10 [XX] ...
 Increment command pointer by X
______________________________________________________________________________________________________
0x11 (8037EA98): Call assembly routine once
 11 08 [XX XX] [YY YY YY YY]
 Call assembly routine Y (A0 = word from 0x8038BE24, A1 = halfword X)
   Store return value at 0x8038BE24
 
   Game startup: 8016F5B0
   File select: 801766DC
   File select -> Castle grounds: 8024BD5C
   Other levels: 8024BE14, 8024BCD8
______________________________________________________________________________________________________
0x12 (8037EB04): Actively call assembly routine
 12 08 [XX XX] [YY YY YY YY]
 Call assembly routine Y (A0 = word from 0x8038BE24, A1 = halfword X)
   Store return value at 0x8038BE24
   If return value is 0, set upper halfword @ 0x8039BE20 = 0 and do not continue to next command
   Else, set upper halfword @ 0x8039BE20 = 1 and continue to the next command

   Demo screen: 8016F5B0
   File select: 801768A0
   Other levels: 8024BCD8
______________________________________________________________________________________________________
0x13 (8037EB98): Set accumulator value
 13 04 [XX XX]
 Store X at 0x8038BE24 (32bit)
______________________________________________________________________________________________________
0x14 (8037EBD4): ?
 14 04 00 00
 Call 0x802783E8
______________________________________________________________________________________________________
0x15 (8037EC14): ?
 15 04 00 00
 Call 0x80278498
______________________________________________________________________________________________________
0x16 (8037EC54): Load raw data from ROM to absolute RAM address
 16 10 00 00 [XX XX XX XX] [YY YY YY YY] [ZZ ZZ ZZ ZZ]
 X = RAM address
 Y = ROM address start
 Z = ROM address end
 Call 0x802786F0 (A0 = X, A1 = Y, A2 = Z)
______________________________________________________________________________________________________
0x17 (8037ECA4): Load raw data from ROM to RAM segment (The segment table is at 8033B400 in RAM)
 17 0C 00 [XX] [YY YY YY YY] [ZZ ZZ ZZ ZZ]
 X = RAM segment number
 Y = ROM address start
 Z = ROM address end
______________________________________________________________________________________________________
0x18 (8037ECF8): Load and decompress MIO0 data from ROM to RAM segment
 18 0C 00 [XX] [YY YY YY YY] [ZZ ZZ ZZ ZZ]
 X = RAM segment number
 Y = ROM address start
 Z = ROM address end
______________________________________________________________________________________________________
0x19 (8037ED48): Create Mario face for the demo screen
 19 04 00 [XX]
 X Settings: 01 No face, 02 Regular face, 03 Game over face

 Call 0x80278120 (A0 = 0x000E1000, A1 = 0); allocate 0xE1000 bytes for mario face settings
   If allocation was successful:
     Call 0x8019C450(A0 = 0x000E1000, A1 = pointer to allocated area in ram)
     Call 0x8019C418(A0 = 0x80000400, A1 = 0x00025800)
     Call 0x8019C418(A0 = 0x8039F800, A1 = 0x00070800)
     Call 0x8019C4EC ; data gets loaded into 80000400 and 8039F800 after this call
     Call 0x8019C684(A0 = X)
______________________________________________________________________________________________________
0x1A (8037EDF8): Load and decompress MIO0 data from ROM to RAM segment (level terrain textures)
 1A 0C 00 [XX] [YY YY YY YY] [ZZ ZZ ZZ ZZ]
 X = RAM segment number
 Y = ROM address start
 Z = ROM address end
______________________________________________________________________________________________________
0x1B (8037EE48): Start load sequence
 1B 04 00 00
 Used before a chain of load commands
 Call 0x8037B448 (A0 = 0, A1 = 0x8038BD88)
 Call 0x8029D1E8
 Call 0x8027AB04
 Call 0x802783E8
______________________________________________________________________________________________________
0x1C (8037EEA8): ?? always follows 0x12 command
 1C 04 00 00
 Call 0x8029D1E8
 Call 0x8027AD74
 Call 0x80278498
______________________________________________________________________________________________________
0x1D (8037EF00): End load sequence
 1D 04 00 00
 Used after a chain of load commands
 If word @ 0x8038B8A0 is not 0 then:
   Call 0x802783C8
     S0 = return value
     Call 0x80278A14 (A0 = S0+0xFFF0, A1 = 0)
       Store return value at 0x8038B8A0
______________________________________________________________________________________________________
0x1E (8037EF70):
______________________________________________________________________________________________________
0x1F (8037F010): Start of an area
 1F 08 [XX] 00 [YY YY YY YY]
 
 XX = Area number
 YY = Segment offset address of geometry layout
______________________________________________________________________________________________________
0x20 (8037F130): End of an area
 Set upper halfword @ 8038B8AC = 0xFFFF
______________________________________________________________________________________________________
0x21 (8037F164): Load polygon data without a geometry layout
 21 08 [??] [ID] [XX XX XX XX]
 
 ?? = Unknown use. I've seen it so far as: 0x10, 0x40, 0x50, and 0x60.
 ID = Id of the model to be used with 3D objects.
 XX = Segment offset address
______________________________________________________________________________________________________
0x22 (8037F214): Loads polygon data with a geometry layout
 22 08 00 [ID] [XX XX XX XX]

 ID = Id of the model to be used with 3D objects.
 XX = Segment offset address
______________________________________________________________________________________________________
0x23 (8037F2A4):
______________________________________________________________________________________________________
0x24 (8037F45C): Places a 3D object in the level
 24 18 [AA] [ID] [XX XX] [YY YY] [ZZ ZZ] [RX RX] [RY RY] [RZ RZ] [B1 B1] [B2 B2] [BS] [BO BO BO]
 
 AA = Act(s) in which this object will appear in (Binary value)
 ID = Id of the model to use for this object. (Defined by commands 0x21 and 0x22)
 XX = X position of object (Signed 16-bits)
 YY = Y position of object (Signed 16-bits)
 ZZ = Z position of object (Signed 16-bits)
 RX = Rotation across X axis (Signed 16-bits)
 RY = Rotation across Y axis (Signed 16-bits)
 RZ = Rotation across Z axis (Signed 16-bits)
 B1 = Behavior parameter 1
 B2 = Behavior parameter 2
 BS = Ram segment for behavior script
 BO = Offset of the ram segment
______________________________________________________________________________________________________
0x25 (8037F36C): Loads the Mario Object
 Always: 25 0C 00 01 00 00 00 01 13 00 2E C0
 25 0C 00 [ID] [?? ?? ?? ??] [XX XX XX XX]
 
 ID = Id of the model to use for Mario. (Defined by commands 0x21 and 0x22)
 ?? = Some parameters, not sure what they do.
 XX = Segment offset address of behavior script
______________________________________________________________________________________________________
0x26 (8037F67C): Connect warps
 26 08 [AA] [BB] [CC] [DD] 00 00
 
 AA = Warp ID to jump from (warp ID's are defined with some previous 0x24 commands using specific behaviors)
 BB = Course ID number to warp to (Course ID's are defined from previous 0x0C commands)
 CC = Course area to jump to
 DD = Warp ID number in destination level area
______________________________________________________________________________________________________
0x27 (8037F994): Define level warps for paintings inside the Castle
 27 08 [AA] [BB] [CC] [DD] 00 00
 
 AA = Warp ID to jump from (warp ID's are defined with some previous 0x24 commands using specific behaviors)
 BB = Course ID number to warp to (Course ID's are defined from previous 0x0C commands)
 CC = Course area to jump to
 DD = Warp ID number in destination level area
______________________________________________________________________________________________________
0x28 (8037F790): Transport Mario to an area
 28 0C [??] [AA] [XX XX] [YY YY] [ZZ ZZ] 00 00
 ?? = I don't know what this byte does exactly.
 AA = Course area # to go to
 XX = Teleport Mario by this amount on the X axis (Signed 16-bits)
 YY = Teleport Mario by this amount on the Y axis (Signed 16-bits)
 ZZ = Teleport Mario by this amount on the Z axis (Signed 16-bits)
______________________________________________________________________________________________________
0x29 (80380014):
______________________________________________________________________________________________________
0x2A (8038007C):
 2A 04 00 00
 Call 0x8027AF48
______________________________________________________________________________________________________
0x2B (803800BC):
______________________________________________________________________________________________________
0x2C (80380160):
 2C 04 00 00
 Call 0x8027B038
______________________________________________________________________________________________________
0x2D (803801A0):
 2D 04 00 00
 Call 0x8027B164
______________________________________________________________________________________________________
0x2E (8037FE94):
______________________________________________________________________________________________________
0x2F (8037FF14): Decides which area of the level geometry to render
 2F 08 00 00 [XX XX XX XX]

 XX = Segment offset pointer to ??
______________________________________________________________________________________________________
0x30 (80380274):
______________________________________________________________________________________________________
0x31 (8037F920): Set default terrain
 31 04 00 [XX]
 XX = 00 Normal A, 01 Normal B, 02 Snow, 03 Sand, 04 Haunted house, 05 Water levels, 06 Slippery Slide

 If 0x8038B8AC is 0xFFFF continue to next command
______________________________________________________________________________________________________
0x32 (8038024C): No operation
 32 [XX] ...
 Increment command pointer by X
______________________________________________________________________________________________________
0x33 (803801E0): Fade/overlay screen with color
 33 08 [XX] [YY] [RR] [GG] [BB] 00
 X = 01 Enable, 00 Disable
 Y = Controls duration? usually 0x10
 R,G,B = rgb colors

 Call 0x8027B1A0 (A0 = X, A1 = Y, A2 = Z, A3 = A, sp_x10 = B)
______________________________________________________________________________________________________
0x34 (8037FDE4):
 34 04 [XX] 00
 Call 0x80323340 (A0 = X)
______________________________________________________________________________________________________
0x35 (8037FE2C):
 35 04 [XX] 00
 If X is 0, call 0x803733B0 (A0 = 2)
 Else, call 0x803733B0 (A0 = 1)
______________________________________________________________________________________________________
0x36 (80380300): Set music
t0 = w@ 8038B8AC
t7 = w@ 8038BE28
t9 = w@ 8032DDC8
______________________________________________________________________________________________________
0x37 (8038039C): Set music
 37 04 00 [XX]
 X = Song ID
 
 Call 0x80249178 (A0 = 0, A1 = X, A2 = 0)
______________________________________________________________________________________________________
0x38 (803803EC):
 38 04 [XX XX]
 Call 0x8024922C (A0 = X)
 ______________________________________________________________________________________________________
0x39 (8037FF94): Place macro objects
 39 08 00 00 [XX XX XX XX]
 X = Segment offset pointer to object placement list

 List format: (each entry is 10 bytes)
  [BB BB] [XX XX] [YY YY] [ZZ ZZ] [?? ??]
  B = Object type ID (behavior, model, etc)
  X,Y,Z = Coordinates
  ?? = Always 00 00 ?
______________________________________________________________________________________________________
0x3A (8037FB18):
0x3B (8037FC38):
0x3C (80380434):

Engine variables:
8038BE20: Statuses?
8038BE24: Accumulator
8038BE28: Pointer to current command
8038B8A0: ?
8038B8AC: ?
8038B8B0: Primary stack pointer
8038B8B4: Secondary stack pointer?

Relevant functions:
803805C8: Command interpreter
Arguments (A0 = pointer to command) ; uses the jump table at 8038B8B0

~~~~

80277F50: Uses the segments table to convert a given segment offset address to a RAM address
Arguments (A0 = segment offset address)
Returns (V0 = RAM address)

802783E8: () ?
80278498: () ?

802786F0: Load raw data to RAM address
Arguments (A0 = RAM address, A1 = ROM address start, A2 = ROM address end)

Spoiler: Song IDs for the music commands
00 No music
01 Collect star
02 Demo screen
03 Grassy level
04 Inside castle
05 Water
06 Fire/Desert
07 Bowser fight
08 Snow
09 Slide/race
0A Haunted
0B Lullaby
0C Cave
0D Star select
0E Wing cap
0F Metal cap
10 Bowser warning
11 Bowser course
12 New record
13 Merry go round
14 Race start
15 Star unlocked
16 Mini boss
17 Collected Key
18 Endless stairs
19 Bowser fight (final)
1A Credits
1B Solved puzzle
1C Toad dialogue
1D Peach dialogue
1E Intro theme
1F End game
20 End game 2
21 File select
22 Intro theme 2
(This post was last modified: 27-07-2015, 05:36 PM by shygoo.)

I was wondering when we were going to have a level script thread.  Tongue

To fill in some of the blanks:
Spoiler: Level Script Commands
Spoiler: 0x1F
0x1F (8037F010): Start of an area
1F 08 [XX] 00 [YY] [ZZ ZZ ZZ]

XX = Area number.
YY = Ram segment for the Geometry Layout
ZZ = Offset of segment.
Spoiler: 0x20
0x20 (8037F130): End of the area
20 04 00 00

Set upper halfword @ 8038B8AC = 0xFFFF
Spoiler: 0x21 (incomplete)
0x21 (8037F164): Loads polygon data without a geometry layout.
21 08 [??] [ID] [XX] [YY YY YY]

?? = Unknown use. I've seen it so far as: 0x10, 0x40, 0x50, and 0x60.
ID = Id of the model to be used with 3D objects.
XX = Ram segment
YY = Offset of segment
Spoiler: 0x22
0x22 (8037F214): Loads polygon data with a geometry layout.
22 08 00 [ID] [XX] [YY YY YY]

ID = Id of the model to be used with 3D objects.
XX = Ram segment
YY = Offset of segment
Spoiler: 0x24
0x24 (8037F45C): Places a 3D object in the level
24 18 [AA] [ID] [XX XX] [YY YY] [ZZ ZZ] [RX RX] [RY RY] [RZ RZ] [B1 B1] [B2 B2] [BS] [BO BO BO]

AA = Act(s) in which this object will appear in (Binary value)
ID = Id of the model to use for this object. (Defined by commands 0x21 and 0x22)
XX = X position of object (Signed 16-bits)
YY = Y position of object (Signed 16-bits)
ZZ = Z position of object (Signed 16-bits)
RX = Rotation across X axis (Signed 16-bits)
RY = Rotation across Y axis (Signed 16-bits)
RZ = Rotation across Z axis (Signed 16-bits)
B1 = Behavior parameter 1
B2 = Behavior parameter 2
BS = Ram segment for behavior script
BO = Offset of the ram segment
Spoiler: 0x25 (incomplete)
0x25 (8037F36C): Loads the Mario Object
Always: 25 0C 00 01 00 00 00 01 13 00 2E C0
25 0C 00 [ID] [?? ?? ?? ??] [XX] [YY YY YY]

ID =  Id of the model to use for Mario. (Defined by commands 0x21 and 0x22)
?? = Some parameters, not sure what they do.
XX = Ram segment for behavior script
YY = Offset of the ram segment
Spoiler: 0x26
(From Kaze's website)

0x26 (8037F67C): Connect Warps
26 08 [AA] [BB] [CC] [DD] 00 00

AA = Warp ID to jump from (warp ID's are defined with some previous 0x24 commands using specific behaviors)
BB = Course ID number to warp to (Course ID's are defined from previous 0x0C commands)
CC = Course area to jump to
DD = Warp ID number in destination level area
Spoiler: 0x27
(From Kaze's website)

0x27 (8037F994): Define level warps for paintings inside the Castle.
27 08 [AA] [BB] [CC] [DD] 00 00

AA = Warp ID to jump from (warp ID's are defined with some previous 0x24 commands using specific behaviors)
BB = Course ID number to warp to (Course ID's are defined from previous 0x0C commands)
CC = Course area to jump to
DD = Warp ID number in destination level area
Spoiler: 0x28 (incomplete)
0x28 (8037F130): Instantly transport Mario to an area.
28 0C [??] [AA] [XX XX] [YY YY] [ZZ ZZ] 00 00

?? = I don't know what this byte does exactly.
AA = Course area # to go to
XX = Teleport Mario by this amount on the X axis (Signed 16-bits)
YY = Teleport Mario by this amount on the Y axis (Signed 16-bits)
ZZ = Teleport Mario by this amount on the Z axis (Signed 16-bits)

I still don't know how the teleport gets triggered in-game.
Spoiler: 0x29 (incomplete)
0x29 (80380014): ???

I've only seen this command once (in segment 0x14).
002A62A0 / 14000180: [ 29 04 02 00 ]
Spoiler: 0x2E
0x2E (8037FE94): Loads the collision map, places Special 3D objects in the level, and defines water boxes.
2E 08 00 00 [XX] [YY YY YY]

XX = Ram segment
YY = Offset of segment

You can view this post by Kaze to figure out how to process the 0x2E command: http://smwc.me/1207297
You can learn more about Special 3D objects here: http://smwc.me/1207463
Spoiler: 0x2F (incomplete)
0x2F (8037FF14): Decides which part of the geometry to render
2F 08 00 00 [XX] [YY YY YY]

XX = Ram segment (Usually RAM segment 0x07)
YY = Offset of segment

[Image: ue1Ao0H.png][Image: taJj4ra.png]

This command is only used in the 3 big levels. Big Boo's Haunt, Inside Castle, and Hazy Maze Cave.

Big Boo's Haunt, Area #1
382E20 / 0E000560: [ 2F 08 00 00 07 02 60 5C ]
Inside Castle, Area #1
3CFDB4 / 0E000CE4: [ 2F 08 00 00 07 07 78 2C ]
Inside Castle, Area #2 (Upstairs)
3CFE9C / 0E000DCC: [ 2F 08 00 00 07 07 80 8C ]
Inside Castle, Area #3 (Downstairs)
3CFF80 / 0E000EB0: [ 2F 08 00 00 07 07 88 70 ]
Hazy Maze Cave, Area #1
3E6EEC / 0E0004EC: [ 2F 08 00 00 07 02 AD C4 ]

(This command needs more research)
Spoiler: 0x30 (incomplete)
0x30 (8037FF14): ???
30 04 00 [??]

?? = Some value that differs per level.
Spoiler: levels
Big Boo's Haunt
382E28 / 0E000568: [ 30 04 00 62 ]
Cool Cool Mountain
395FC4 / 0E000334: [ 30 04 00 30 ]
Bob-omb's Battlefield
405E5C / 0E0003FC: [ 30 04 00 00 ]
Bowser 1
45C2D4 / 0E000374: [ 30 04 00 5A ]
Vanish Cap
4613D0 / 0E0001B0: [ 30 04 00 81 ]
Lethal Lava Land
48D2E0 / 0E000930: [ 30 04 00 61 ]
Whomp's Fortress
49E1F0 / 0E0007A0: [ 30 04 00 1E ]
Metal Cap
4BEB34 / 0E000154: [ 30 04 00 82 ]
Wing Cap
4C2818 / 0E000118: [ 30 04 00 83 ]
(This command needs more research)
Spoiler: 0x31
0x31 (8037F920): Defines the default terrain for the level
31 04 00 [XX]

XX = Terrain type {
00 = Normal A
01 = Normal B
02 = Snow
03 = Sand
04 = Haunted house
05 = Water levels
06 = Slippery Slide
}
Spoiler: 0x39
0x39 (8037FF94): Places Macro 3D Objects in the level
39 08 00 00 [XX] [YY YY YY]

XX = Ram segment (Usually RAM segment 0x07)
YY = Offset of segment

You can learn more about Macro 3D objects here: http://smwc.me/1207463
I wish I knew how the 0x28 command was triggered in the levels. Being able to switch between areas in a level instantly would be a nice feature for rom hacks.

Thanks David, list is updated

I took a stab at decoding some of the uncommon level scripts.  I am attaching my manually decompiled versions and also dumped them here. There is one difference in 0x11: the order of X and 0x8038BE24.  (Also, I stole some of your style ideas again, shygoo.  Thanks!).

0x03 (8037E47C): delay frames
03 04 [XX XX]
 X = delay frames
 sets s16 flag (8038BE20) to 0 before delay and 1 after
 does not increment level script pointer until after delay

0x04 (8037E4FC): delay frames and signal end
04 04 [XX XX]
X = delay frames
identical to 0x03, except for flag set at start:
sets s16 flag (8038BE20) to -1 before delay and 1 after
does not increment level pointer until after delay

0x05 (8037E580): jump to level script at segmented address
05 08 00 00 [XX XX XX XX]
X = segmented address of jump

0x06 (8037E580): push script stack and jump to level script at segmented address
06 08 00 00 [XX XX XX XX]
X = segmented address of jump
similar to 0x05, but also pushes current place on script stack so it can be popped later

0x07 (8037E620): pop script stack, returns to where previous 0x06 or 0x0C pushed from
07 04 00 00

0x08 (8037E620): push script stack and 16-bit value on stack
08 04 [XX XX]
X = 16 bit value pushed on script stack after current address
this command is never used in any of the level scripts

0x09 (8037E6D4): pops script stack and param (possibly from previous 0x08 or 0x0A)
09 04 00 00
this command is never used in any of the level scripts

0x0A (8037E780): pushes next level command on script stack and param 0x00000000
0A 04 00 00
this command is only used once in main level scripts

0x0B (8037E7F8): if result of operation is true, pop stack
0B 08 [XX] 00 [YY YY YY YY]
X = operation, a0 to 8037E1A0 (unsigned 8)
  0: script_accum & argument
  1: (script_accum & argument) < 1
  2: (script_accum ^ argument) < 1
  3: (script_accum ^ argument) > 0
  4: script_accum < argument
  5: script_accum <= argument
  6: script_accum > argument
  7: script_accum >= argument
Y = argument, a1 to 8037E1A0 (signed 32)
this command is only used once in main level scripts

0x0C (8037E878): if result of operation is true, jumps to segmented address
0C 0C [XX] 00 [YY YY YY YY] [ZZ ZZ ZZ ZZ]
X = operation, a0 to 8037E1A0 (unsigned 8).  see 0x0B for valid operation values
Y = argument, a1 to 8037E1A0 (signed 32)
Z = segment address of jump

0x0D (8037E8E8): if result of operation is true, pushes next command on stack and jumps to segmented address
0D 0C [XX] 00 [YY YY YY YY] [ZZ ZZ ZZ ZZ]
X = operation, a0 to 8037E1A0 (unsigned 8).  see 0x0B for valid operation values
Y = argument, a1 to 8037E1A0 (signed 32)
Z = segment address of jump

0x0E (8037E988): if result of operation is false, skips over following 0xF, 0x10 commands
0E 08 [XX] 00 [YY YY YY YY]
X = operation, a0 to 8037E1A0 (unsigned 8).  see 0x0B for valid operation values
Y = argument, a1 to 8037E1A0 (signed 32)
this command is never used in any of the level scripts

0x0F (8037EA18): skips over the following 0x10 commands
0F 04 00 00
this command is never used in any of the level scripts

0x10 (8037EA70): doesn't do anything, nop
10 04 00 00
this command is never used in any of the level scripts

0x11 (8037EA98): updates level accumulator (8038BE24) from assembly routine
11 08 [XX XX] [YY YY YY YY]
X = argument passed to assembly routine
Y = assembly routine
level_accum = Y(X, level_accum);


Attached Files
Size: 9.33 KB / Downloads: 111 .c   sm64_level_scripts_decompiled.c


I spent admittedly too much time on trying to figure out what is going on with level command 0x21.  First, just to recap what shygoo has:

0x21 (8037F164): load polygon data without a geometry layout
21 08 [X0] [YY] [ZZ ZZ ZZ ZZ]
X = drawing layer
Y = ID of the model to be used with 3D objects
Z = segment offset address of polygon data

I can only find this command being used 11 times in the main level scripts stored at 0x2ABCA0:
21 08 40 A4 04 032A18 - texture 04032780
21 08 40 9F 03 02BCD0 - texture 0302BAD0
21 08 40 A1 03 01CB00 - texture 0301C300
21 08 40 9E 03 02C8A0 - texture 0302C6A0
21 08 40 84 08 025F08 - texture 08025A80
21 08 10 DA 08 024BB8 - texture 08023998
21 08 10 C9 08 0048E0 - texture 08004058
21 08 50 57 05 013CB8 - texture 05012848
21 08 60 54 05 000840 - texture 05000040
21 08 40 54 05 002E00 - texture 05001C48
21 08 10 56 05 003120 - texture 05002C48

Segment 03 is full of common textures and polygon data (door, trees, coins, etc.) and 04 is mario's segment and these always seem to be loaded.  The other segments are loaded in the other level scripts: 05 varies by level and 08 is always the MIO0 block 0x1F2200 (common enemies, boxes, etc.).  Looking at these segmented addresses, I found references to textures indicated in the notes above.  Some are textures that I don't really recognize:
[Image: level21.png]

Jedi suspected the X is the drawing layer (see Geometry Layout Commands), and this fits since the complete opaque textures (cannon door and box) are 1, the ones with alpha are 4 and the transparent one is 5 and the shadow is 6.  I tried to prove this out by changing the X value of the mole hole from 6 to 1 (byte @ 2AC48A from 60 to 10) and here are the results:
Layer 06Layer 01
[Image: mole_hole_layer_06.png][Image: mole_hole_layer_01.png]

Also for reference attaching my updated level script notes that include 21 and 22.


Attached Files
Size: 13.16 KB / Downloads: 154 .c   sm64_level_scripts_decompiled.c


here is my list:

00 load and jump
[1] load and jump
[4] segment to load into
[5-8] Rom start
[9-12] ROm end
[13-16] segemnted offset to jump to

- still adds the length byte. why?
----------------------------------------------
01 loads and jumps
[4] segment to load into
[5-8] rom start
[9-12] rom end
[13-16] segmented address to jump to
----------------------------------------------------
02 End of level layout data
[3,4]: Always 00
------------------------------------
03 delay frames
[3] also frames?
[4] frames
----------------------------------------------------
04 Some commands used near the end of level layout
[3,4]: Always 00
-------------------------------------
05 goto
[5-8] jump address
-------------------------------------
06 Makes the Level layout script jump to another address
[5 - 8] address to jump to
------------------------------------
07 Jumps back to after the last 0x06 or 0x0C command was called
[3,4]: Always 00
------------------------------------
0A Jumps back to after the last 0x06 command was called
[3,4]: Always 00
------------------------------------------
0C conditional jump if level ID
[3] 02?...if not less than 8, whole commad does nothing?
[4-8] level ID
[9-12] jump destination
------------------------------------
[10] [10] [00] [07] [80 50 00 00] [01 21 00 00] [01 2E 00 00]
00. Command
02. Unused
03. Target segment
04-07: RAM Address Target
08-11: ROM Block start
12-16: ROM Block end
-----------------------------------------------------------------
11 call function?
[4,5,6,7]: Some RAM address
--------------------------------------------------------
12 call function?
[4,5,6,7]: Some RAM address
-------------------------------------------------------------------------
16 Loads ASM code into RAM at 8016F000
[3,4] IDK
[5,6,7,8] Destination Address
[9,10,11,12] Rom start
[13,14,15,16] Rom end
----------------------------------------------------------------------------
17 Copy uncompressed data from ROM to a RAM segment
[4]: RAM segment to copy data to
[5,6,7,8]: Start address in ROM of uncompressed data
[9,10,11,12]: End address in ROM of uncompressed data
------------------------------------
18 Decompress MIO0 data from ROM and copy it into a RAM segment
[4]: RAM segment to copy data to
[5,6,7,8]: Start address in ROM of MIO0 data
[9,10,11,12]: End address in ROM of MIO0 data
------------------------------------
19 decompress something?
------------------------------------
1A Decompress MIO0 data from ROM and copy it into a RAM segment (Used for texture only segments?)
[4]: RAM segment to copy data to
[5,6,7,8]: Start address in ROM of MIO0 data
[9,10,11,12]: End address in ROM of MIO0 data
------------------------------------
1B Starts a RAM loading sequence (for command 0x17, 0x18 and 0x1A)
[3,4]: Always 00
------------------------------------
1C Some commands used near the end of level layout
[3,4]: Always 00
------------------------------------
1D Ends a RAM loading sequence (for command 0x17, 0x18 and 0x1A)
[3,4]: Always 00
------------------------------------
1E Some commands used near the end of level layout - builds level collision?
[3,4]: Always 00
--------------------------------------
1F Start Area
[3]: Area number in level
[4]: Always 00?
[5-8]: segmented pointer to geo layout
------------------------------------
20 End Area
[3,4]: Always 00
------------------------------------
21 Loads polygon object data directly without using geometry
layout data
[3]: ??
[4]: ID number that will be used to insert object in level using
command 0x24
[5]: RAM segment number where to find geometry layout data
[6,7,8]: Offset in segment number
------------------------------------
22 Loads polygon object using geometry layout data found at
address and assigns an ID number.
[3]: Always 00?
[4]: ID number that will be used to insert object in level
using command 0x24
[5]: RAM segment number in RAM where to find geometry layout data
[6,7,8]: Offset in segment number
------------------------------------
24 Places an object in level
[3]: Act(s) on which the object will appear, as binary value
[4]: ID number of the object, as defined by a previous 0x22 command
[5,6][7,8][9,10]: X Y and Z position in level as 16-bit signed integers
[11,12][13,14][15,16]: X Y and Z rotation as 16-bit signed integers
[17,18,19,20]: Parameters to be fed into the behavior code
[21,22,23,24]: segmented pointer to behavior
------------------------------------
25 Loads Mario object, points to it's behavior code.
[3,4,5,6,7,8]: ?? some parameters to be fed into the behavior code
[9,10,11,12]: Behavior code address, including segment number
------------------------------------
26 connect warps
[3]: Warp ID to jump from (warp ID's are defined with some previous
0x24 commands using specific behaviors)
[4]: Course ID number to warp to
(Course ID's are defined from previous 0x0C commands)
[5]: Course area to jump to
[6]: Warp ID number in destination level area
[7,8]: Always 00 00?
------------------------------------
27 define level warps for paintings inside the Castle.
[3]: Warp ID to jump from (warp ID's are defined with
some previous 0x24 commands using specific behaviors)
[4]: Course ID number to warp to (Course ID's are defined
from previous 0x0C commands)
[5]: Course area to jump to
[6]: Warp ID number in destination level area
[7,8]: Always 00 00?
------------------------------------
28 Sometimes seen after 0x26 commands, near the end,idk
[3-12]: ??
------------------------------------
2B Some command used near the end of level layout
[3-12]: No Idea what it does
------------------------------------
2E Loads terrain collision data for level, and other special
models to be placed in the level.
[5-8] segmented collision pointer
------------------------------------
30 Some command sometimes used near the end of level layout
[3,4]: Always 00
------------------------------------
31 Defines how different terrain types behave.
[3,4]: Always 00
------------------------------------
34 blackout screen?
------------------------------------
36 Music command
[3,4,5]: Other music parameters
[6]: Sequence number
------------------------------------
[37] Music command.
[4]: Sequence Number.
------------------------------------
39 Inserts multiple objects found inside main MIO0 level segment.
[5]:RAM segment number (usually 07, the main level polygon data segment)
[6,7,8]: Offset in segment
LOOK AT EC7E0
--------------------------------------------------
3B 0C 00 00 F3 9A EC CD 00 66 00 14
[3,4] idk
[5,6] X position
[7,8] Y position
[9,10] Z Position
[11,12] intensity. negative means repulsion, positive means succion
__________________________________________________
3C get put remote values?

I got one! My first contribution to the knowledge of the community! Big Grin

Code:
0x2B: Set Mario's default position in the level (or, Load Mario into the game?)
2B 0C 01 00 [RY RY] [XX XX] [YY YY] [ZZ ZZ]

01 00 = Not sure what this means or does but all 30 levels use this value
RY = Rotation across Y axis (Signed 16-bits) [I'm pretty sure]
XX = X position of Mario (Signed 16-bits)
YY = Y position of Mario (Signed 16-bits)
ZZ = Z position of Mario (Signed 16-bits)

I haven't played with this command extensively, but it looks like it has no practical impact beyond the castle grounds. That's because from the castle, you get to every destination via a warp, so in practice Mario always loads into the next level at some warp destination, not the default position this command sets. But I could be very wrong on this - I've barely studied warps.

The position set by this command does take effect if you skip the castle grounds and jump straight to a particular level directly via hacking. I'm guessing it was helpful to have this feature during the game's development process.

If this command isn't being used by a level (because you warped there), it can safely be replaced (tested by replacing with 0x32's in BOB). If the level is being loaded directly (castle_grounds or via hacking) the game will crash without this command.

I used all of our notes to make a nearly-complete parse of all the level scripts: http://pastebin.com/raw.php?i=DQjCtKk3
Tables of all constant names and values are included at the bottom

I'll release the parser and its source after I clean up the code and we find out what those last few commands do.

Edit: see http://origami64.net/showthread.php?tid=160&pid=6890#pid6890
(This post was last modified: 07-02-2017, 12:50 AM by shygoo.)

(19-07-2015, 01:47 PM)Kaze Wrote: 34 blackout screen?

To clarify this, 0x34 calls osViBlack(bool), passing it the third level byte, which is a boolean (1 = blackout, 0 = cancel blackout):

Code:
typedef struct {
  u8 cmd;
  u8 len;
  u8 blank;
  u8 unused;
} Level34;
void LevelScript34(void) // 8037FDE4/0FCB64
{
  Level34 *script = (Level34 *)level_ptr;
  osViBlack(script->blank); // 80323340
  level_ptr += script->len;
}

(21-07-2015, 01:11 PM)Jedi Wrote: I got one! My first contribution to the knowledge of the community! Big Grin

Code:
0x2B: Set Mario's default position in the level (or, Load Mario into the game?)
2B 0C [AA] 00 [RY RY] [XX XX] [YY YY] [ZZ ZZ]

AA = Starting course area number
RY = Rotation across Y axis (Signed 16-bits) [I'm pretty sure]
XX = X position of Mario (Signed 16-bits)
YY = Y position of Mario (Signed 16-bits)
ZZ = Z position of Mario (Signed 16-bits)
Nice!  I verified this and figured out that the third byte is the starting area number, as updated in your comment in the code block above.  This command is definitely useful while testing levels, skipping the main menu and castle grounds.  This is also the Mario spawn location if you use the debug level select menu (again, bypassing the warps).

For what it's worth, I'll also post this here.  Level command 0x13 (set accumulator value) as is used in the main level scripts is actually used to set the starting level number.  You can just change this value instead of the asm hack that the level importer uses.  Note you'll want to change it in both places (26A0C4 and 2A6224) depending on if you skip the main menu or not.

I've got updates for 2 commands: 0x28 and 0x30

Code:
0x28: Setup instant area warp
Allows Mario to be instantly teleported to another area within the current level. The warp is triggered if Mario is on/above a collision triangle with a specific ID.

28 0C [CC] [AA] [XX XX] [YY YY] [ZZ ZZ] 00 00

CC = Which collision ID to use starting with 0x1B (00 = 0x1B, 01 = 0x1C, 02 = 0x1D, 03 = 0x1E)
AA = Course area # to go to
XX = Teleport Mario by this amount on the X axis (s16)
YY = Teleport Mario by this amount on the Y axis (s16)
ZZ = Teleport Mario by this amount on the Z axis (s16)
--- The 0x28 cmds used in level scripts ---
Endless staircase warp backward (Inside Castle area 2):
003CFEAC / 0E000DDC [ 28 0C 00 02 00 00 FF 33 01 9A 00 00 ]
Warp to Eyerock boss room (Shifting Sand Land area 2):
003FBEA0 / 0E000510 [ 28 0C 03 03 00 00 00 00 00 00 00 00 ]
Warp to WDW town area (Wet Dry World area 1):
0041A460 / 0E0004D0 [ 28 0C 01 02 00 00 00 00 00 00 00 00 ]
Warp to WDW start area (Wet Dry World area 2):
0041A4B4 / 0E000524 [ 28 0C 00 01 00 00 00 00 00 00 00 00 ]
Warp to DDD submarine area (Dire Dire Docks area 1):
00495DDC / 0E00037C [ 28 0C 03 02 E0 00 00 00 00 00 00 00 ]
Warp to DDD start area (Dire Dire Docks area 2):
00495E58 / 0E0003F8 [ 28 0C 02 01 20 00 00 00 00 00 00 00 ]
Warp to TTM slide part 2 (Tall Tall Mountain area 2):
004EB804 / 0E000614 [ 28 0C 02 03 28 00 1C 00 28 00 00 00 ]
Warp to TTM slide part 3 (Tall Tall Mountain area 3):
004EB850 / 0E000660 [ 28 0C 03 04 D4 00 34 00 0C 00 00 00 ]

Code:
0x30: Show dialog
Shows a dialog at the start of a level.

30 04 00 [ID]

ID = Dialog ID
--- The 0x30 cmds used in level scripts ---
Bob-Omb's Battlefield:
00405E5C / 0E0003FC [ 30 04 00 00 ] = "Wow! You're smack in the middle of the battlefield. You'll find..."
Whomp's Fortress:
0049E1F0 / 0E0007A0 [ 30 04 00 1E ] = "Hello! The Lakitu Bros., cutting in with a live update on Mario's..."
Bowser 1 Course:
0045C2D4 / 0E000374 [ 30 04 00 5A ] = "Bwa ha ha ha! You've stepped right into my trap, just as I knew..."
Vanish Cap:
004613D0 / 0E0001B0 [ 30 04 00 81 ] = "Welcome to the Vanish Cap Switch Course! All of the blue blocks..." 
Metal Cap:
004BEB34 / 0E000154 [ 30 04 00 82 ] = "Welcome to the Metal Cap Switch Course! Once you step on the..."
Wing Cap:
004C2818 / 0E000118 [ 30 04 00 83 ] = "Welcome to the Wing Cap Course! Step on the red switch at the..."
(This post was last modified: 05-06-2016, 12:09 AM by David.)

Level Script Engine Commands & Info 1 2 »
Users browsing this thread: 1 Guest(s)