Difference between revisions of "Map Script Format"

From Terranigma Wiki
Jump to navigation Jump to search
(updated 0x40, added 0x04, updated 0x08)
(Updated with new information)
Line 71: Line 71:
| 1
| 1
| 1
| 1
| Entry ID?
| Track ID
|-
|-
| 2
| 2
Line 82: Line 82:
| 0x04
| 0x04
| 5
| 5
| Load data
| Load unknown data
{| class="wikitable"
{| class="wikitable"
|-
|-
Line 105: Line 105:
| 0x08
| 0x08
| variable
| variable
| run sub command  
| Run sub command  
{| class="wikitable"
{| class="wikitable"
|-
|-
Line 111: Line 111:
! Argument length (byte)
! Argument length (byte)
! Function
! Function
|-
| 0x00
| 6
|
|-
|-
| 0xF8
| 0xF8
| ?
| 1
|
| Return from sub function
|-
|-
| 0xF9
| 0xF9
| 2  
| 2  
|
| Call map script
|-
|-
| 0xFA
| 0xFA
| 2  
| 2  
|
| Push map script address
|-  
|-  
| 0xFC
| 0xFC
Line 134: Line 130:
| 0xFD
| 0xFD
| 4  
| 4  
| 3 byte address, 1 byte unknown
| Call map script when flag is true
|-
|-
| 0xFE
| 0xFE
| 2  
| 2  
|
| Return from script
|-
|-
| 0xFF
| 0xFF
| 0  
| 0  
| End of script
| End of script
|-
| default
| 2
| ?
|-
|-
|}
|}
Line 164: Line 156:
| 0x00 - Tiles
| 0x00 - Tiles
   
   
0x01 - Map Layer 0
0x01 - Map layer 0
   
   
0x02 - Map Layer 1
0x02 - Map layer 1
|-
|-
| 1
| 1
| 3
| 3
| Offset of data
| Address
|}
|}


Line 176: Line 168:
| 0x20
| 0x20
| 7
| 7
| Load MapTile/Collision data
| Load collision data or tile maps
{| class="wikitable"
{| class="wikitable"
|-
|-
Line 185: Line 177:
| 0
| 0
| 1
| 1
| Unknown
| Seek
|-
| 1
| 1
| Size
|-
|-
| 2
| 1
| 1
| Offset
|-
| 3
| 1
| 1
| Type
| Layer ID


{| class="wikitable"
{| class="wikitable"
|-
|-
! 0x08
! 0x80 set
! 0x40
! 0x80 clear
|-
|-
| Load collision data
| Collision data
| Load MapTile data
| Map tiles
|}
|}
|-
| 2
| 1
| Unknown
|-
| 3
| 1
| Layer ID
|-
|-
| 4
| 4
| 3
| 3
| Offset
| Address
|}
|}


Line 218: Line 209:
| 0x40
| 0x40
| 6
| 6
| Set palette for map
| Load palette


{| class="wikitable"
{| class="wikitable"
Line 236: Line 227:
| 2
| 2
| 1
| 1
| Pal offset in memory
| Pal offset
|-
|-
| 3
| 3
| 3
| 3
| Offset of palette
| Address
|}
|}


Line 246: Line 237:
|-
|-
| 0x80
| 0x80
| 6
| 9
| Load Tile Data
| Load tile data
 
{| class="wikitable"
{| class="wikitable"
|-
|-
Line 257: Line 247:
| 0
| 0
| 1
| 1
| Unknown
| Seek
|-
|-
| 1
| 1
| 1
| 1
| Unknown
| Size
|-
|-
| 2
| 2
| 1
| 1
| Unknown
| Tile mode
|-
|-
| 3
| 3
| 3
| 3
| Offset of Tile Data
| Address
|-
|-
| 6
| 6
| 2
| 2
| Bank
|-
| 7
| 1
| Unknown  
| Unknown  
|-
|-

Revision as of 20:23, 20 February 2016

When the game loads a map it looks at a pointer table at 0x06959C and runs a some kind of script to load the map parts.

There seem to be 1314(check) entries.

For some reason offsets are not directly read but calculated via this code: (don't ask!)

i.e. when loading map id 0 the first offset is 0x83FF05 which after the code is run turns into 0xA5FF83 (0x25FF83 ROM).


u32 Background::GetAddress()
{ 
	u32 AdrLow = GetBytei(); 
	u16 AdrHigh = GetWordi();

	u8 push = AdrHigh & 0x7F;
	
	AdrHigh = push ^ AdrHigh;
	AdrHigh<<= 1;
	AdrHigh |= 0x80;
	AdrHigh |= push;
	AdrHigh += (((ROMOffset|(1<<23)) & 0xFF0000) >> 8);

	if( (AdrHigh & 0xFF00) >= 0xC000 )
		AdrHigh &= 0xFF7F;
	
	return (AdrHigh<<8)|AdrLow;
}

Map script #0

This map script is used to select a song to be played by the 08 FC command

Commands

Opcode Argument length (byte) Function
0x00 2 Run map script
Offset Length (Byte) Name
0 2 Map ID


0x02 5 Play SPC data
Offset Length (Byte) Name
0 1 Unknown
1 1 Track ID
2 3 SPC data Offset


0x04 5 Load unknown data
Offset Length (Byte) Name
0 3 Offset
3 1 Unknown
4 1 Unknown
0x08 variable Run sub command
Opcode Argument length (byte) Function
0xF8 1 Return from sub function
0xF9 2 Call map script
0xFA 2 Push map script address
0xFC 2 Calls map script #0 which then plays the selected song id
0xFD 4 Call map script when flag is true
0xFE 2 Return from script
0xFF 0 End of script
0x10 4 Load data
Offset Length (Byte) Name
0 1 0x00 - Tiles

0x01 - Map layer 0

0x02 - Map layer 1

1 3 Address
0x20 7 Load collision data or tile maps
Offset Length (Byte) Name
0 1 Seek
1 1 Size
2 1 Offset
3 1 Layer ID
0x80 set 0x80 clear
Collision data Map tiles
4 3 Address


0x40 6 Load palette
Offset Length (Byte) Name
0 1 Pal index
1 1 Pal size
2 1 Pal offset
3 3 Address


0x80 9 Load tile data
Offset Length (Byte) Name
0 1 Seek
1 1 Size
2 1 Tile mode
3 3 Address
6 2 Bank
7 1 Unknown