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

Nice finds, especially the dialog. I always thought it sucked not to have it for all levels
#PowerAbuseEveryday#

While looking into what it would take to relocate the general memory pool (0x8005C000-0x801C1000) to expansion RAM, I noticed something odd with Level script 0x16 that caused the game to crash. From shygoo's notes:

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)

This is 100% correct. However, the function it calls (FixedCopy/802786F0) makes a large assumption that the destination RAM address is within the memory pool range. SM64 only uses this level script for copying the main menu asm code to RAM. I spent some time decompiling the FixedCopy routine, which you can find below. There are two problems with the code for general use: 1. it calls _pool_alloc() and 2. it computes the length to copy from pool_tail - ram instead of rom_end - rom_start. Without some modifications, this makes it practically unusable for anything but what SM64 already uses it for.

I'm also attaching an updated decompiled level scripts C file which includes some more level scripts and all the _pool_alloc(), _pool_free() and related data structures.

Code:
pool_t *pool_tail; // 0x8033B490
u32 FixedCopy(u32 ram, u32 rom_start, u32 rom_end) // begin 802786F0/0336F0
{
  (void)ram;        // 0x28($sp)
  (void)rom_start;  // 0x2c($sp)
  (void)rom_end;    // 0x30($sp)
  u32 ret_addr = 0; // 0x24($sp)
  u32 len;          // 0x20($sp)
  u32 pool_len;     // 0x1c($sp)

  len = ((rom_end - rom_start) + 0xF) & 0xFFFFFFF0);
  pool_len = (pool_tail - ram) + 0xF) & 0xFFFFFFF0);

  if (pool_len >= len) {
     ret_addr = _pool_alloc(pool_len, 1);
     if (ret_addr != NULL) {
        bzero(ret_addr, pool_len);
        osWriteBackDCacheAll();
        DmaCopy(ret_addr, rom_start, rom_end);
        osInvalCache(ret_addr, pool_len);
        osInvalDCache(ret_addr, pool_len);
     }
  }

  return ret_addr;
}


Attached Files
Size: 20.64 KB / Downloads: 28 .c   sm64_level_scripts_decompiled.c


For what it's worth, here's that decoder I said I would release a millennium ago
https://github.com/shygoo/sm64-lsdec
https://github.com/shygoo/sm64-lsdec/releases/download/v0/lsdec.zip
(This post was last modified: 05-02-2017, 01:49 AM by shygoo.)


Attached Files
Size: 36.9 KB / Downloads: 16 .zip   level-scripts-decoded.zip


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