/* 1A command with optional raw load This patch allows the level script engine's 1A command to load raw data. If the third byte of the command is 01, the texture block is loaded as raw data instead of MIO0 data. This allows ROM extenders to decompress MIO0 blocks used by 1A commands without making fake MIO0 headers. Usage in level scripts: 1A 0C [MM] [XX] [YYYYYYYY] [ZZZZZZZZ] M = 00 Standard MIO0 load, 01 Raw data load X = RAM segment number Y = ROM start address Z = ROM end address */ .definelabel LevelTextureBuffer, 0x801C1000 .org 0x8037EDF8 LevelScript1A: addiu sp, sp, -0x18 sw ra, 0x14 (sp) lui t6, 0x8039 lw t6, 0xBE28 (t6) // cmdptr lbu a0, 0x03 (t6) // segment lw a1, 0x04 (t6) // romstart lw a2, 0x08 (t6) // romend jal LoadLevelTextures lbu a3, 0x02 (t6) // mode lui t0, 0x8039 lw t1, 0xBE28 (t0) // cmdptr lbu t2, 0x01 (t1) // length byte addu t1, t1, t2 // cmdptr + length sw t1, 0xBE28 (t0) // inc cmdptr lw ra, 0x14 (sp) jr ra addiu sp, sp, 0x18 nop nop nop .org 0x802788B4 LoadLevelTextures: // void (a0 segment, a1 romstart, a2 romend, a3 mode = 00 mio0 | 01 raw) addiu sp, sp, -0x38 sw ra, 0x14 (sp) sw a0, 0x1C (sp) // segment sw a1, 0x20 (sp) // romstart sw a2, 0x24 (sp) // romend sw a3, 0x28 (sp) // mode (3rd byte from command) li a0, LevelTextureBuffer bnez a3, @@dma // skip mio0buf allocation if mode 1 (raw) sw a0, 0x30 (sp) // 0x801C1000 constant // if mode 00 (mio0): subu a0, a2, a1 // a0 = romstart - romend addiu a0, a0, 0x000F addiu at, r0, 0xFFF0 and a0, a0, at // a0 = aligned size ((romend - romstart) + 0x0F) & 0xFFFFFFF0 jal 0x80278120 // mio0buf = allocate(aligned size, 1) addiu a1, r0, 0x01 sw v0, 0x2C (sp) // save mio0buf for dealloc add a0, v0, r0 // replace 0x801C1000 with mio0buf for the dmacopy @@dma: lw a1, 0x20 (sp) jal 0x80278504 // dmacopy(mio0buf | 0x801C1000, romstart, romend) lw a2, 0x24 (sp) lw at, 0x28 (sp) // mode bnez at, @@end // skip mio0decode() and free() if mode 01 (raw) nop // if mode 00 (mio0): lw a0, 0x2C (sp) jal 0x8027F4E0 // mio0decode(mio0buf, 0x801C1000) lw a1, 0x30 (sp) jal 0x80278238 // free(mio0buf) lw a0, 0x2C (sp) @@end: lw a0, 0x1C (sp) jal 0x80277EE0 // setsegment(segment, 0x801C1000) lw a1, 0x30 (sp) lw v0, 0x30 (sp) // return 0x801C1000 lw ra, 0x14 (sp) jr ra addiu sp, sp, 0x38 nop nop nop nop nop nop nop nop _____________________________________________________________________________ /* Segment 02 raw load This patch makes the segment 02 loader use raw data instead of MIO0. This allows ROM extenders to decompress the segment 02 MIO0 block without making a fake MIO0 header. */ .orga 0x3AC0 lui a1, 0x0011 lui a2, 0x0011 addiu a2, a2, 0x4750 addiu a1, a1, 0x8A40 jal 0x8027868C addiu a0, r0, 0x02 /* For tweaking by tools: 0x3AC2: 0x0011 rom end address hi16 0x3AC6: 0x0011 rom start address hi16 0x3ACA: 0x4750 rom start address lo16 0x3ACE: 0x8A40 rom end address lo16 0x3AD0: For MIO0: 0x0C09E1F6 (jal 0x802787D8), decompress mio0 to segment For Raw: 0x0C09E1A3 (jal 0x8027868C), dma to segment */