diff --git a/splat.yaml b/splat.yaml new file mode 100644 index 0000000..df8bbee --- /dev/null +++ b/splat.yaml @@ -0,0 +1,1021 @@ +name: Ogrebattle64 (North America) +sha1: 9cd0cfb50b883edb068e0c30d213193b9cf89895 +options: + basename: ogrebattle64 + target_path: baserom.z64 + base_path: . + compiler: GCC + find_file_boundaries: True + header_encoding: ASCII + platform: n64 + asm_inc_header: "" + # undefined_funcs_auto: True + # undefined_funcs_auto_path: undefined_funcs_auto.txt + # undefined_syms_auto: True + # undefined_syms_auto_path: undefined_syms_auto.txt + # symbol_addrs_path: symbol_addrs.txt + # asm_path: asm + # src_path: src + # build_path: build + extensions_path: tools/splat_ext + # mips_abi_float_regs: o32 + # section_order: [".text", ".data", ".rodata", ".bss"] + # auto_all_sections: [".data", ".rodata", ".bss"] + # libultra_symbols: True + # hardware_regs: True +segments: + - name: header + type: header + start: 0x0 + + - name: boot + type: bin + start: 0x40 + + - name: entry + type: code + start: 0x1000 + vram: 0x80070C00 + subsegments: + - [0x1000, hasm, entry] + + - name: main + type: code + start: 0x1060 + vram: 0x80070C60 + follows_vram: entry + bss_size: 0x3AE70 + subsegments: + - [0x1060, asm, "main"] + - [0x4AC0, asm] + - [0x5FC0, asm] + - [0x68E0, asm] + - [0x8700, asm] + - [0xA370, asm] + - [0xFC80, c, "boot"] + - [0xFDC0, asm] + - [0xFF10, asm] + - [0x10110, asm] + - [0x10190, asm] + - [0x10250, asm] + - [0x102E0, asm] + - [0x10340, asm] + - [0x103D0, asm] + - [0x10420, asm] + - [0x10440, asm] + - [0x10480, asm] + - [0x104C0, asm] + - [0x10500, asm] + - [0x10550, asm] + - [0x10590, asm] + - [0x105D0, asm] + - [0x10610, asm] + - [0x10680, asm] + - [0x10CF0, asm] + - [0x10D70, asm] + - [0x10E70, asm] + - [0x11170, asm] + - [0x11440, asm] + - [0x11480, asm] + - [0x114F0, c, "mus"] + - [0x155C0, asm] + - [0x15A20, asm] + - [0x15BD0, asm] + - [0x15E90, asm] + - [0x16100, asm] + - [0x17090, asm] + - [0x177B0, asm] + - [0x17990, asm] + - [0x18380, asm] + - [0x18400, asm] + - [0x18450, asm] + - [0x18630, asm] + - [0x186E0, asm] + - [0x18780, asm] + - [0x18810, asm] + - [0x188C0, asm] + - [0x18950, asm] + - [0x189D0, asm] + - [0x18F30, asm] + - [0x18F80, asm] + - [0x19050, asm, "libultra/sched/sched"] + - [0x19DD0, c] + - [0x19E10, asm] + - [0x19E30, asm, "dma_load_loop"] + - [0x19EB0, asm] + - [0x19FC0, asm] + - [0x1A050, c] + - [0x1A4F0, asm] + - [0x1A5B0, asm] + - [0x1A660, c] + - [0x1A9A0, asm] + - [0x1AA00, asm, "copy_global_controller_data"] + - [0x1AAA0, asm] + - [0x1AD10, asm] + - [0x1AFD0, asm] + - [0x1B030, asm] + - [0x1B070, asm] + - [0x1B160, asm] + - [0x1B240, asm] + - [0x1B290, asm] + - [0x1B2E0, asm] + - [0x1B320, asm] + - [0x1B360, asm] + - [0x1B3A0, asm] + - [0x1B3E0, asm] + - [0x1B510, asm] + - [0x1B530, asm] + - [0x1B650, asm] + - [0x1B7A0, asm] + - [0x1B940, asm] + - [0x1C040, asm, "libultra/io/epidma"] + - [0x1C0E0, asm] + - [0x1C130, asm, "libultra/os/cartrominit"] + - [0x1C2B0, asm] + - [0x1C670, asm, "libultra/io/piacs"] + - [0x1C760, asm, "libultra/io/pidma"] + - [0x1C810, asm] + - [0x1C950, asm] + - [0x1C9F0, asm] + - [0x1D220, asm] + - [0x1DD30, asm] + - [0x1DE40, asm] + - [0x1EB10, asm] + - [0x1EF30, asm] + - [0x1FAD0, asm, "libultra/audio/save"] + - [0x1FC50, asm] + - [0x1FC90, asm] + - [0x1FCE0, asm] + - [0x1FD20, asm] + - [0x20360, asm, "libultra/audio/syndelete"] + - [0x20370, asm, "libultra/audio/synallocfx"] + - [0x20410, asm, "libultra/os/invaldcache"] + - [0x20540, asm, "libultra/os/writebackdcache"] + - [0x205C0, asm, "libultra/os/writebackdcacheall"] + - [0x205F0, asm, "libultra/os/contquery"] + - [0x20870, asm, "libultra/io/controller"] + - [0x20B80, asm, "libultra/os/virtualtophysical"] + - [0x20BE0, asm, "libultra/os/sqrtf"] + - [0x20BF0, asm, "libultra/gu/cosf"] + - [0x21450, asm, "libultra/gu/lookathil"] + - [0x21EB0, asm, "libultra/gu/lookatref"] + - [0x224A0, asm, "libultra/gu/ortho"] + - [0x22720, asm, "libultra/gu/perspective"] + - [0x22AA0, asm, "libultra/gu/position"] + - [0x22E60, asm] + - [0x22E90, asm, "libultra/gu/rotateRPY"] + - [0x231B0, asm, "libultra/gu/sinf"] + - [0x23780, asm, "libc/bzero"] + - [0x238B0, asm] + - [0x23940, asm] + - [0x23970, asm, "libultra/os/createmesgqueue"] + - [0x239A0, asm, "libultra/os/jammesg"] + - [0x23AE0, asm, "libultra/os/recvmesg"] + - [0x23C10, asm, "libultra/os/sendmesg"] + - [0x23DF0, asm] + - [0x24040, asm] + - [0x24060, asm] + - [0x240B0, asm] + - [0x24B70, asm, "libultra/io/siacs"] + - [0x24C60, asm, "libultra/os/createthread"] + - [0x24D50, asm, "libultra/os/setthreadpri"] + - [0x24E20, asm, "libultra/os/startthread"] + - [0x24F40, asm] + - [0x25000, asm] + - [0x25040, asm, "libultra/os/yieldthread"] + - [0x25090, asm, "libultra/os/gettime"] + - [0x25120, asm] + - [0x25140, asm, "libultra/os/settimer"] + - [0x251E0, asm] + - [0x254E0, asm, "libultra/os/probetlb"] + - [0x255A0, asm] + - [0x255E0, asm] + - [0x25620, asm, "libultra/io/vimgr"] + - [0x25960, asm] + - [0x259C0, asm] + - [0x25A10, asm] + - [0x25B80, asm] + - [0x25BD0, asm] + - [0x25C20, asm, "libultra/io/viswapcontext"] + - [0x25F30, asm] + - [0x25F90, asm] + - [0x263C0, asm] + - [0x265E0, asm] + - [0x26BC0, asm] + - [0x26D80, asm] + - [0x26E90, asm] + - [0x27260, asm] + - [0x272C0, asm] + - [0x274D0, asm] + - [0x27540, asm] + - [0x27FD0, asm] + - [0x281C0, asm] + - [0x28430, asm] + - [0x28450, asm, "libultra/os/initialize"] + - [0x28740, asm, "libultra/gu/mtxcatl"] + - [0x287C0, asm, "libultra/gu/mtxxfml"] + - [0x28850, asm, "libultra/gu/mtxxfmf"] + - [0x28900, asm, "libultra/gu/rotate"] + - [0x28BE0, asm, "libultra/gu/ident"] + - [0x28C40, asm, "libultra/gu/mtxidentf"] + - [0x28CA0, asm, "libultra/gu/mtxf2l"] + - [0x28D20, asm, "libultra/gu/mtxl2f"] + - [0x28DA0, asm, "libultra/gu/mtxcatf"] + - [0x28EA0, asm] + - [0x28F60, asm, "libultra/gu/scalef"] + - [0x28FC0, asm, "libultra/gu/normalize"] + - [0x29020, asm] + - [0x29100, asm, "libultra/gu/translatef"] + - [0x29160, asm] + - [0x29AD0, asm, "libultra/os/disableint"] + - [0x29AD0, asm] + - [0x29B60, asm] + - [0x29BF0, asm] + - [0x29E50, asm] + - [0x29FC0, asm] + - [0x29FE0, asm] + - [0x2AAD0, hasm, "libreultra/os/getcause"] + - [0x2AAE0, hasm, "libreultra/os/getcount"] + - [0x2AAF0, hasm, "libreultra/os/getsr"] + - [0x2AB00, hasm, "libreultra/os/setcompare"] + - [0x2AB10, hasm, "libreultra/os/setfpccsr"] + - [0x2AB60, asm] + - [0x2AC30, asm] + - [0x2AC80, asm] + - [0x2ACD0, asm] + - [0x2ADC0, asm, "libultra/os/destroythread"] + - [0x2AEA0, hasm, "libultra/os/maptlbrdb"] + - [0x2AF00, hasm, "libultra/os/unmaptlball"] + - [0x2AF50, asm, "libultra/io/vi"] + - [0x2B060, asm] + - [0x2B070, asm] + - [0x2BA70, asm] + - [0x2C750, asm] + - [0x2C770, asm] + - [0x2C790, asm] + - [0x2C950, asm] + - [0x2C990, asm] + - [0x2C9E0, asm] + - [0x2CA20, asm] + - [0x2CB50, asm] + - [0x2CBC0, asm] + - [0x2CC00, asm] + - [0x2CD70, asm] + - [0x2CDA0, asm] + - [0x2CEF0, asm] + + - [0x2D220, asm] + - [0x2D300, asm] + - [0x2D3E0, asm] + - [0x2D680, asm] + - [0x2D7A0, asm] + - [0x2D7B0, asm] + - [0x2D7C0, asm] + - [0x2D7D0, asm] + - [0x2D7E0, asm] + - [0x2D7F0, asm] + - [0x2DC80, asm] + - [0x2DDF0, asm] + - [0x2DE10, asm] + - [0x3A800, asm] + - [0x3A840, asm] + - [0x3AB10, asm] + - [0x3AB20, asm] + - [0x3AB90, asm] + - [0x3ABC0, asm] + + # - [0x3E198, rodata, "isallocatedpointer"] + # - [0x3E278, rodata] + # - [0x3E330, rodata] + # - [0x3E460, rodata, "logs_file_read_error"] + # - [0x3E7C0, rodata] + # - [0x3E7D0, rodata] + # - [0x3E7F0, rodata] + # - [0x3E810, rodata] + # - [0x3E8F0, rodata] + # - [0x3E930, rodata] + # - [0x3E9A0, rodata] + # - [0x3E9B0, rodata] + # - [0x3E9F0, rodata] + # - [0x3EAC0, rodata] + # - [0x3EB00, rodata, "libultra/gu/cosf"] + # - [0x3ECF0, rodata, "libultra/gu/lookat"] + # - [0x3ED40, rodata, "libultra/gu/lookathil"] + # - [0x3EDF0, rodata] + # - [0x3EE20, rodata] + # - [0x3EE70, rodata] + # - [0x3EE80, rodata] + # - [0x3EEA0, rodata] + # - [0x3F000, rodata, "libultra/io/vi"] + # - [0x3F070, rodata, heapcheck] + # - [0x3F0C0, rodata, heapcheck] + # - [0x3F140, rodata, heapcheck] + # - [0x3F170, rodata, heapcheck] + + # - { start: 0x3F1B0, type: bss, vram: 0x800E9C20 } + + - type: code + dir: overlays/overlay0 + start: 0x3F1B0 + vram: 0x800E9C20 + subsegments: + - [0x3F1B0, c] + - [0x3FE70, asm] + - [0x40640, asm] + + - [0x40E80, bin] + # - type: code + # dir: overlays/overlay1 + # start: 0x40E80 + # vram: 0x8016AF80 + # subsegments: + # - [0x40E80, asm] + # - [0x420D0, asm] + # - [0x42C30, asm] + # - [0x42C90, asm] + # - [0x43100, asm] + # - [0x45CB0, asm] + # - [0x46090, asm] + # - [0x49510, asm] + # - [0x495E0, asm] + # - [0x49820, asm] + # - [0x49A30, asm] + # - [0x4D5C0, asm] + # - [0x4D938, asm] + + # - [0x66E10, bin] + + # - type: code + # dir: overlays/unknown + # start: 0x1CE070 + # vram: 0x80197B70 + # subsegments: + # - [0x1CE070, asm] + # - [0x1D4700, asm] + # - [0x1D8850, asm] + # - [0x1DAAB0, asm] + # - [0x1DBF70, asm] + # - [0x1E3440, asm] + # - [0x1E9E00, asm] + # - [0x1ED1D0, asm] + # - [0x1EE580, asm] + # - [0x1EE590, asm] + + # - type: code + # dir: overlays/overlay2 + # start: 0x213B10 + # vram: 0x801D0840 + # subsegments: + # - [0x213B10, asm] + # - [0x213B50, asm] + # - [0x21C970, asm] + # - [0x21D7F0, asm] + # - [0x222190, asm] + # - [0x224F30, asm] + # - [0x228D70, asm] + + # - type: code + # dir: overlays/overlay5 + # start: 0x22A280 + # vram: 0x801E6FB0 + # subsegments: + # - [0x22A280, asm] + # - [0x233210, asm] + # - [0x239BA0, asm] + + # - type: code + # dir: overlays/overlay4 + # start: 0x23A3A0 + # vram: 0x801D0840 + # subsegments: + # - [0x23A3A0, asm] + # - [0x23B220, asm] + + + # - type: code + # dir: overlays/overlay3 + # start: 0x23B220 + # vram: 0x801E6FB0 + # subsegments: + # - [0x23B220, asm] + # - [0x23B3E0, asm] + # - [0x23B680, asm] + # - [0x23D090, asm] + # - [0x241610, asm] + # - [0x243F20, asm] + + - [0x2447A0, bin] + + + - type: code + dir: overlays/overlay99 + name: overlay99 + start: 0x002AE3C0 + vram: 0x8031DFC0 + follows_vram: main + exclusive_ram_id: ovl_99 + subsegments: + - [0x2AE3C0, asm] + - [0x2B5230, asm] + - [0x2B6F40, asm] + - [0x2B8610, asm] + + - [0x2B89C0, bin] + + - [0x2B8BA0, bin, "n64_ptr_tables_v2_00"] + - [0x2BF250, bin, "n64_wave_table_00"] # N64 WaveTable + - [0x423FF0, bin, "n64_ptr_tables_v2_01"] + - [0x429CD0, bin, "n64_wave_table_01"] + - [0x4E3140, bin] + + - [0x4F0FB0, bin] + + - [0x636784, bin, "last_battle_test.n64"] + - [0x64A04C, bin, "makai_battle_bg1.n64"] + - [0x65DCC6, bin, "kyoukai.n64"] + - [0x670ECA, bin, "snowtown.n64"] + - [0x68A110, bin, "slam.n64"] + - [0x699BDE, bin, "town_enter.n64"] + - [0x6b07b4, bin, "malformed_6b07b4"] + - [0x6C4EB8, bin, "kaigi_re.n64"] + - [0x6D16F6, bin, "witch_house01.n64"] + - [0x6E9332, bin, "haioku.bg2"] + - [0x6FC2D2, bin, "1_6FC2D2"] + - [0x70A376, bin, "sakaba2.n64"] + + - [0x72BCF6, bin, "S_1.bg2"] + - [0x75F248, bin, "W_1.bg2"] + - [0x7A85C8, bin, "M_3.bg2"] + + - [0x7F2138, bin, "camp.n64"] + + - [0x827c90, bin, "btl_bg01_a2.bg2"] + - [0x828942, bin, "btl_bg03_a2.bg2"] + - [0x82D222, bin, "btl_bg03_b2.bg2"] + - [0x82FF80, bin, "btl_bg04_a2.bg2"] + - [0x83257A, bin, "btl_bg04_b2.bg2"] + - [0x834CF2, bin, "btl_bg05_a2.bg2"] + - [0x835F58, bin, "btl_bg06_a2.bg2"] + - [0x837A72, bin, "btl_bg06_b2.bg2"] + - [0x838C62, bin, "btl_bg07_a2.bg2"] + - [0x83BA60, bin, "btl_bg07_b2.bg2"] + - [0x84176E, bin, "btl_bg08_a2.bg2"] + - [0x84634C, bin, "btl_bg08_b2.bg2"] + - [0x84BA08, bin, "btl_bg09_a2.bg2"] + - [0x84DF82, bin, "btl_bg09_b2.bg2"] + - [0x84FEDE, bin, "btl_bg10_a2.bg2"] + - [0x85435C, bin, "btl_bg10_b2.bg2"] + - [0x85817A, bin, "btl_bg11_a2.bg2"] + - [0x85C8BC, bin, "btl_bg11_b2.bg2"] + - [0x85FBDA, bin, "btl_bg12_a2.bg2"] + - [0x863E0C, bin, "btl_bg13_a2.bg2"] + - [0x868E0C, bin, "btl_bg13_b2.bg2"] + - [0x86C34A, bin, "btl_bg14_a2.bg2"] + - [0x870C16, bin, "btl_bg14_b2.bg2"] + - [0x871CE8, bin, "btl_bg15_a2.bg2"] + - [0x876CC0, bin, "makai_battle_bg2.bg2"] + - [0x87B410, bin, "kyoukai.bg2"] + - [0x87D0B0, bin, "slam_alpha.bg2"] + - [0x87FAB0, bin, "witch_house02.bg2"] + + - [0x883538, bin, "malformed_883538"] + - [0x8860E4, bin, "malformed_8860E4"] + - [0x88B0B0, bin, "malformed_88B0B0"] + - [0x88E480, bin, "malformed_88E480"] + - [0x8939F2, bin, "malformed_8939F2"] + - [0x8986E8, bin, "malformed_8986E8"] + - [0x89D090, bin, "malformed_89D090"] + + - [0x8A2240, bin, "f.bg2"] + + - [0x8BFDE2, bin, "1_8BFDE2"] + - [0x8BFE1C, bin, "1_8BFE1C"] + - [0x8BFE9C, bin, "1_8BFE9C"] + - [0x8BFF38, bin, "1_8BFF38"] + - [0x8BFFAA, bin, "1_8BFFAA"] + - [0x8C04E4, bin, "1_8C04E4"] + - [0x8C0C3C, bin, "1_8C0C3C"] + - [0x8C2C96, bin] + - [0x8C5A98, bin] + - [0x8D63B4, bin] + - [0x8E9D4A, bin] + - [0x8EED88, bin] + - [0x8EF0DC, bin] + - [0x8EF43C, bin] + - [0x8EF7AA, bin] + - [0x8EFCB4, bin] + - [0x8F03F2, bin] + - [0x8F6EA0, bin] + - [0x8FDC26, bin] + - [0x8FDD98, bin] + - [0x8FE026, bin] + - [0x8FE26C, bin] + - [0x8FE2F4, bin] + - [0x8FEC24, bin] + - [0x8FED16, bin] + - [0x8FEE20, bin] + - [0x902C96, bin] + - [0x904AE8, bin] + - [0x906992, bin] + - [0x908862, bin] + - [0x9089A5, bin] + - [0x908B63, bin] + - [0x908D44, bin] + - [0x908F3E, bin] + - [0x90927A, bin] + - [0x909423, bin] + - [0x9095BB, bin] + - [0x909710, bin] + - [0x9099B5, bin] + - [0x909C61, bin] + - [0x90BE32, bin] + - [0x925482, bin] + + # Found in DMA log (N64 startup) + - [0x94AF50, bin] + + - [0x1C4801C, bin, "kaigi_base.bg2"] + - [0x1C67F34, bin, "P_room_base.bg2"] + - [0x1C91072, bin, "P_room_desk.bg2"] + - [0x1C96D60, bin, "M4_L_meeting_room_all.bg2"] + - [0x1CBE614, bin, "M4_L_meeting_room_table.bg2"] + - [0x1CC57CE, bin, "S_L_meeting_room_base.bg2"] + - [0x1CF6A30, bin, "souko.bg2"] + - [0x1D10382, bin, "saikutu_01.bg2"] + - [0x1D3F7BE, bin, "1_1D3F7BE"] + - [0x1D4D95E, bin, "1_1D4D95E"] + - [0x1D58BBE, bin, "1_1D58BBE"] + - [0x1D63A9E, bin, "1_1D63A9E"] + - [0x1D7092E, bin, "1_1D7092E"] + - [0x1D78ABE, bin, "1_1D78ABE"] + - [0x1D953E2, bin, "After_Baza_shrine_00.bg2"] + - [0x1DEC89A, bin, "kaigi_re_campus1.bg2"] + - [0x1DED93C, bin, "kaigi_re_table.bg2"] + - [0x1DEE4B8, bin, "kaigi_re_campus3.bg2"] + - [0x1DEF53E, bin, "kaigi_re_campus2.bg2"] + - [0x1DF05B6, bin, "kouya_back.bg2"] + - [0x1E04A0E, bin, "koya_ue_gake.bg2"] + + - [0x1E0A810, bin, "malformed_1E0A810"] + + - [0x1E17488, bin, "Nintendo.bg2"] + - [0x1E179BE, bin, "Quest.bg2"] + - [0x1E18498, bin, "episode_VI.bg2"] + - [0x1E18DDC, bin, "person.bg2"] + + # Missing s_map01.n64 + - [0x1E5134E, bin, "s_map_02"] + - [0x1E54FD0, bin, "s_map_03"] + - [0x1E58FE2, bin, "s_map_04"] + - [0x1E5F20E, bin, "s_map_05"] + - [0x1E67310, bin, "s_map_06"] + - [0x1E6CB7A, bin, "s_map_07"] + - [0x1E7027A, bin, "s_map_08"] + - [0x1E7768C, bin, "s_map_09"] + # Missing s_map10.n64 + - [0x1E7AF64, bin, "s_map_11"] + - [0x1E80340, bin, "s_map_12"] + # Missing s_map13.n64 + - [0x1E8849A, bin, "s_map_14"] + # Missing s_map15.n64 + - [0x1E8DCCC, bin, "s_map_16"] + - [0x1E93506, bin, "s_map_17"] + - [0x1E97E2A, bin, "s_map_18"] + # Missing s_map19.n64 + - [0x1E9EFF0, bin, "s_map_20"] + - [0x1EA6702, bin, "s_map_21"] + - [0x1EAA6FA, bin, "s_map_22"] + - [0x1EAF49A, bin, "s_map_23"] + - [0x1EB4F9E, bin, "s_map_24"] + - [0x1EB94BC, bin, "s_map_25"] + - [0x1EC1374, bin, "s_map_26"] + - [0x1EC4F40, bin, "s_map_27"] + - [0x1EC89F2, bin, "s_map_28"] + - [0x1ECF458, bin, "s_map_30"] + - [0x1ED57C6, bin, "s_map_31"] + # Missing s_map32.n64 + - [0x1ED9A18, bin, "s_map_33"] + - [0x1EE16A2, bin, "s_map_34"] + - [0x1EEB10A, bin, "s_map_35"] + - [0x1EF45D8, bin, "s_map_36"] + - [0x1EF884A, bin, "s_map_37"] + - [0x1EFF12A, bin, "s_map_38"] + - [0x1F08340, bin, "s_map_39"] + - [0x1F0BD56, bin, "s_map_40"] + # Missing s_map41.n64 + # Missing s_map42.n64 + - [0x1F10EF6, bin, "s_map_43"] + - [0x1F1710E, bin, "s_map_44"] + # Missing s_map45.n64 + - [0x1F1B3FA, bin, "s_map_46"] + - [0x1F29602, bin, "s_map_47"] + - [0x1F33F7A, bin, "s_map_48"] + + # serifu apparantly means dialogue from Japanese. + # Dialogs + - [0x1FD0216, bin, "serifu_00_0"] + - [0x1FD0376, bin, "serifu_00_1"] + - [0x1FD0626, bin, "serifu_00_2"] + - [0x1FD0958, bin, "serifu_01_0"] + - [0x1FD0C9E, bin, "serifu_01_1"] + - [0x1FD0FF8, bin, "serifu_01_2"] + - [0x1FD1656, bin, "serifu_03_4"] + - [0x1FD1894, bin, "serifu_01_4"] + - [0x1FD1A62, bin, "serifu_01_5"] + - [0x1FD1E46, bin, "serifu_02_0"] + - [0x1FD2296, bin, "serifu_02_1"] + - [0x1FD29B4, bin, "serifu_02_2"] + - [0x1FD2C56, bin, "serifu_02_3"] + - [0x1FD3336, bin, "serifu_03_0"] + - [0x1FD3784, bin, "serifu_03_1"] + - [0x1FD3B28, bin, "serifu_03_2"] + - [0x1FD3BEE, bin, "serifu_03_3"] + - [0x1FD3EF4, bin, "serifu_04_0"] + - [0x1FD401E, bin, "serifu_04_1"] + - [0x1FD440A, bin, "serifu_04_2"] + - [0x1FD4670, bin, "serifu_04_3"] + - [0x1FD4AEE, bin, "serifu_04_4"] + - [0x1FD509C, bin, "serifu_05_0"] + - [0x1FD523E, bin, "serifu_05_1"] + - [0x1FD55D0, bin, "serifu_05_2"] + - [0x1FD5B74, bin, "serifu_06_0"] + - [0x1FD6116, bin, "serifu_27_5"] + - [0x1FD6540, bin, "serifu_06_2"] + - [0x1FD66EA, bin, "serifu_06_3"] + - [0x1FD6FB2, bin, "serifu_07_0"] + - [0x1FD79BC, bin, "serifu_07_1"] + - [0x1FD7F1C, bin, "serifu_29_6"] + - [0x1FD8436, bin, "serifu_07_3"] + - [0x1FD86DA, bin, "serifu_07_4"] + - [0x1FD8B88, bin, "serifu_08_0"] + - [0x1FD8E06, bin, "serifu_08_1"] + - [0x1FD91A4, bin, "serifu_30_5"] + - [0x1FD9550, bin, "serifu_08_3"] + - [0x1FD9738, bin, "serifu_39_6"] + - [0x1FD99B4, bin, "serifu_08_5"] + - [0x1FD9D0E, bin, "serifu_09_0"] + - [0x1FDA05A, bin, "serifu_49_3"] + - [0x1FDA14E, bin, "serifu_09_2"] + - [0x1FDA7B8, bin, "serifu_ch1"] + - [0x1FDA9BA, bin, "serifu_ch2"] + - [0x1FDABB2, bin, "serifu_ch3"] + - [0x1FDADDE, bin, "serifu_ch4"] + - [0x1FDB03C, bin, "serifu_51_4"] + - [0x1FDB2A6, bin, "serifu_44_6"] + - [0x1FDB686, bin, "serifu_06_1"] + - [0x1FDB982, bin, "serifu_ch1_2"] + - [0x1FDBC2E, bin, "serifu_13_0"] + - [0x1FDC454, bin, "serifu_13_3"] + - [0x1FDC81C, bin, "serifu_13_4"] + - [0x1FDCED8, bin, "serifu_14_1"] + - [0x1FDCFB2, bin, "serifu_14_3"] + - [0x1FDD42A, bin, "serifu_15_1"] + - [0x1FDD594, bin, "serifu_15_2"] + - [0x1FDD8C8, bin, "serifu_15_3"] + - [0x1FDDCA2, bin, "serifu_16_0"] + - [0x1FDDE5E, bin, "serifu_16_3"] + - [0x1FDE330, bin, "serifu_16_4"] + - [0x1FDE760, bin, "serifu_17_0"] + - [0x1FDE9CA, bin, "serifu_17_1"] + - [0x1FDEC50, bin, "serifu_17_3"] + - [0x1FDED58, bin, "serifu_17_4"] + - [0x1FDF1C0, bin, "serifu_18_0"] + - [0x1FDF3F6, bin, "serifu_19_0"] + - [0x1FDF980, bin, "serifu_19_1"] + - [0x1FDFAC0, bin, "serifu_19_3"] + - [0x1FE005E, bin, "serifu_19_4"] + - [0x1FE0ACE, bin, "serifu_20_1"] + - [0x1FE0F80, bin, "serifu_21_1"] + - [0x1FE1020, bin, "serifu_21_2"] + - [0x1FE157A, bin, "serifu_21_4"] + - [0x1FE17EE, bin, "serifu_21_5"] + - [0x1FE1AD4, bin, "serifu_22_1"] + - [0x1FE1BBA, bin, "serifu_22_3"] + - [0x1FE1C9C, bin, "serifu_23_0"] + - [0x1FE239A, bin, "serifu_23_1"] + - [0x1FE2864, bin, "serifu_23_2"] + - [0x1FE2952, bin, "serifu_23_3"] + - [0x1FE2AEE, bin, "serifu_24_0"] + - [0x1FE2C5A, bin, "serifu_24_1"] + - [0x1FE30B4, bin, "serifu_24_2"] + - [0x1FE31C6, bin, "serifu_25_3"] + - [0x1FE3B9C, bin, "serifu_26_0"] + - [0x1FE3ED2, bin, "serifu_26_4"] + - [0x1FE4270, bin, "serifu_26_5"] + - [0x1FE4564, bin, "serifu_ch2_3"] + - [0x1FE4D46, bin, "serifu_27_0"] + - [0x1FE57E6, bin, "serifu_27_4"] + - [0x1FE5B10, bin, "serifu_28_0"] + - [0x1FE5DC4, bin, "serifu_28_1"] + - [0x1FE5ED4, bin, "serifu_28_3"] + - [0x1FE6222, bin, "serifu_28_4"] + - [0x1FE6854, bin, "serifu_29_1"] + - [0x1FE7098, bin, "serifu_29_5"] + - [0x1FE7414, bin, "serifu_30_1"] + - [0x1FE768A, bin, "serifu_30_4"] + - [0x1FE7D4C, bin, "serifu_31_2"] + - [0x1FE81C8, bin, "serifu_31_4"] + - [0x1FE882A, bin, "serifu_33_0"] + - [0x1FE8BB6, bin, "serifu_33_1"] + - [0x1FE9116, bin, "serifu_33_4"] + - [0x1FE94E6, bin, "serifu_33_5"] + - [0x1FE9CAA, bin, "serifu_34_2"] + - [0x1FEA1E0, bin, "serifu_34_4"] + - [0x1FEA312, bin, "serifu_36_0"] + - [0x1FEA462, bin, "serifu_36_4"] + - [0x1FEA67C, bin, "serifu_36_5"] + - [0x1FEAA0C, bin, "serifu_37_1"] + - [0x1FEAEFE, bin, "serifu_37_3"] + - [0x1FEB834, bin, "serifu_37_5"] + - [0x1FEB99E, bin, "serifu_37_6"] + - [0x1FEBB56, bin, "serifu_38_2"] + - [0x1FEC056, bin, "serifu_38_4"] + - [0x1FEC42C, bin, "serifu_ch3_4"] + - [0x1FEC98C, bin, "serifu_39_0"] + - [0x1FED038, bin, "serifu_39_2"] + - [0x1FED40C, bin, "serifu_39_3"] + - [0x1FED9F0, bin, "serifu_39_5"] + - [0x1FEDC30, bin, "serifu_40_1"] + - [0x1FEDE66, bin, "serifu_40_3"] + - [0x1FEEA0E, bin, "serifu_41_2"] + - [0x1FEF136, bin, "serifu_41_3"] + - [0x1FEF90C, bin, "serifu_42_2"] + - [0x1FEFA5E, bin, "serifu_42_5"] + - [0x1FEFE2C, bin, "serifu_42_6"] + - [0x1FF01CC, bin, "serifu_43_3"] + - [0x1FF069C, bin, "serifu_44_2"] + - [0x1FF0AE6, bin, "serifu_44_4"] + - [0x1FF0E72, bin, "serifu_44_5"] + - [0x1FF139A, bin, "serifu_45_1"] + - [0x1FF15EC, bin, "serifu_45_3"] + - [0x1FF1A30, bin, "serifu_47_2"] + - [0x1FF1FEE, bin, "serifu_48_3"] + - [0x1FF2522, bin, "serifu_49_0"] + - [0x1FF2724, bin, "serifu_49_1"] + - [0x1FF2B46, bin, "serifu_49_2"] + - [0x1FF2E94, bin, "serifu_50_1"] + - [0x1FF3654, bin, "serifu_50_3"] + - [0x1FF3D88, bin, "serifu_50_4"] + - [0x1FF5602, bin, "serifu_51_0"] + - [0x1FF58F8, bin, "serifu_51_1"] + - [0x1FF5BD6, bin, "serifu_51_3"] + - [0x1FF5FC6, bin, "serifu_52_0"] + - [0x1FF6228, bin, "serifu_52_3"] + - [0x1FF6780, bin, "serifu_53_0"] + - [0x1FF68FC, bin, "serifu_53_3"] + - [0x1FF75DE, bin, "serifu_53_4"] + - [0x1FF7848, bin, "serifu_54_0"] + - [0x1FF7A96, bin, "serifu_54_1"] + - [0x1FF7F1A, bin, "serifu_54_2"] + - [0x1FF832E, bin, "serifu_54_5"] + - [0x1FF8ADA, bin, "serifu_54_6"] + - [0x1FF9666, bin, "serifu_55_3"] + - [0x1FF99F0, bin, "serifu_57_3"] + - [0x1FF9D88, bin, "serifu_60_0"] + - [0x1FFA3D4, bin, "serifu_60_1"] + - [0x1FFAB92, bin, "serifu_60_2"] + - [0x1FFAED2, bin, "serifu_60_3"] + - [0x1FFB4BC, bin, "serifu_60_4"] + - [0x1FFB8C0, bin, "serifu_60_5"] + - [0x1FFBB32, bin, "serifu_60_6"] + - [0x1FFBD18, bin, "serifu_60_7"] + - [0x1FFC14C, bin, "serifu_60_8"] + - [0x1FFC240, bin, "serifu_60_9"] + - [0x1FFC42C, bin, "serifu_61_0"] + - [0x1FFC5CE, bin, "serifu_61_1"] + - [0x1FFC9AC, bin, "serifu_61_2"] + - [0x1FFD1BA, bin, "serifu_61_3"] + - [0x1FFD2EA, bin, "serifu_61_4"] + - [0x1FFD5A4, bin, "serifu_62_0"] + - [0x1FFD9FE, bin, "serifu_tuto_1"] + + - [0x1FFDF10, bin, "Serifu_t_info1"] + - [0x1FFE39A, bin, "Serifu_00_dark"] + - [0x1FFE6FC, bin, "Serifu_01_holy"] + - [0x1FFEB74, bin, "Serifu_02_brave"] + - [0x1FFED0E, bin, "Serifu_03_cross"] + - [0x1FFEFEC, bin, "Serifu_04_southern"] + - [0x1FFF3BC, bin, "Serifu_05_hint"] + - [0x1FFF61C, bin, "Serifu_06_helm"] + - [0x1FFFB22, bin, "Serifu_07_armor"] + + + - [0x200009C, bin, "Serifu_08_divine"] + - [0x2000758, bin, "Serifu_09_dress"] + - [0x2000D80, bin, "Serifu_10_crown"] + - [0x20014C8, bin, "Serifu_11_ring"] + - [0x200171A, bin, "Serifu_12_brood"] + - [0x2002106, bin, "Serifu_13_needle"] + - [0x2002398, bin, "Serifu_14_altar"] + - [0x2002774, bin, "Serifu_15_meteorite"] + + - [0x2002A54, bin, "Serifu_birth_00"] + - [0x2002DA2, bin, "Serifu_birth_01"] + - [0x200308C, bin, "Serifu_birth_02"] + - [0x200336A, bin, "Serifu_birth_03"] + - [0x2003648, bin, "Serifu_birth_04"] + - [0x2003946, bin, "Serifu_birth_05"] + - [0x2003C9C, bin, "Serifu_birth_06"] + - [0x2004014, bin, "Serifu_birth_07"] + - [0x20043FE, bin, "Serifu_birth_08"] + - [0x200475A, bin, "Serifu_birth_09"] + - [0x2004AE6, bin, "Serifu_birth_10"] + - [0x2004E30, bin, "Serifu_birth_11"] + - [0x2005188, bin, "Serifu_birth_12"] + - [0x20054F8, bin, "Serifu_birth_13"] + - [0x2005824, bin, "Serifu_birth_14"] + - [0x2005B2A, bin, "Serifu_birth_15"] + - [0x2005EB6, bin, "Serifu_birth_16"] + - [0x200621E, bin, "Serifu_birth_17"] + + - [0x200660A, bin, "serifu/M_0_0.bin"] + - [0x200680C, bin, "serifu/M_0_1.bin"] + - [0x2006ABA, bin, "serifu/M_0_2.bin"] + - [0x2006C88, bin, "serifu/M_1_1.bin"] + - [0x2006E6E, bin, "serifu/M_1_2.bin"] + - [0x20070E6, bin, "serifu/M_1_3.bin"] + - [0x2007338, bin, "serifu/M_1_4.bin"] + - [0x20076B0, bin, "serifu/M_1_5.bin"] + - [0x20078B4, bin, "serifu/M_1_6.bin"] + - [0x2007AA4, bin, "serifu/M_1_7.bin"] + - [0x2007C12, bin, "serifu/M_2_1.bin"] + - [0x2007D88, bin, "serifu/M_2_2.bin"] + - [0x2008052, bin, "serifu/M_2_3.bin"] + - [0x2008400, bin, "serifu/M_2_4.bin"] + - [0x200855A, bin, "serifu/M_2_5a.bin"] + - [0x20086C0, bin, "serifu/M_2_5b.bin"] + - [0x2008842, bin, "serifu/M_2_6.bin"] + - [0x20089FC, bin, "serifu/M_2_7.bin"] + - [0x2008BAE, bin, "serifu/M_2_8.bin"] + - [0x2008DA8, bin, "serifu/M_2_9a.bin"] + - [0x2008F48, bin, "serifu/M_2_9b.bin"] + - [0x2009154, bin, "serifu/M_3_1.bin"] + - [0x2009356, bin, "serifu/M_3_2.bin"] + - [0x2009580, bin, "serifu/M_3_3.bin"] + - [0x200971C, bin, "serifu/M_3_4.bin"] + - [0x200994A, bin, "serifu/M_3_5.bin"] + - [0x2009B08, bin, "serifu/M_3_6a.bin"] + - [0x2009C58, bin, "serifu/M_3_7a.bin"] + - [0x2009ECA, bin, "serifu/M_3_8.bin"] + - [0x200A066, bin, "serifu/M_3_9.bin"] + - [0x200A254, bin, "serifu/M_3_10.bin"] + - [0x200A3AE, bin, "serifu/M_4_1.bin"] + - [0x200A550, bin, "serifu/M_4_2a.bin"] + - [0x200A6C8, bin, "serifu/M_4_3.bin"] + - [0x200A9AC, bin, "serifu/M_4_4a.bin"] + - [0x200ABB2, bin, "serifu/M_4_5.bin"] + - [0x200AD4E, bin, "serifu/M_4_6.bin"] + - [0x200AF9E, bin, "serifu/M_4_7a.bin"] + - [0x200B212, bin, "serifu/M_4_8a.bin"] + - [0x200B4AE, bin, "serifu/M_4_9a.bin"] + - [0x200B646, bin, "serifu/M_4_10a.bin"] + - [0x200B940, bin, "serifu/M_4_11.bin"] + - [0x200BBBA, bin, "serifu/M_4_12.bin"] + - [0x200BDD4, bin, "serifu/M_4_13.bin"] + - [0x200C080, bin, "serifu/M_4_14.bin"] + - [0x200C1A8, bin, "serifu/Present.bin"] + - [0x200D1D6, bin, "serifu/M_4_15.bin"] + - [0x200D334, bin, "serifu/Encounter.bin"] + + - [0x200D99E, bin, "Serifu_info_01"] + - [0x200DE30, bin, "Serifu_info_02"] + - [0x200E1B0, bin, "Serifu_info_03"] + - [0x200E37E, bin, "Serifu_info_04"] + - [0x200E6AC, bin, "Serifu_info_05"] + - [0x200E8E2, bin, "Serifu_info_06"] + - [0x200ECDA, bin, "Serifu_info_07"] + - [0x200EFF2, bin, "Serifu_info_08"] + - [0x200F2A8, bin, "Serifu_info_09"] + - [0x200F4DA, bin, "Serifu_info_11"] + - [0x200F6A2, bin, "Serifu_info_12"] + - [0x200FA2A, bin, "Serifu_info_13"] + - [0x200FCEE, bin, "Serifu_info_14"] + - [0x201002C, bin, "Serifu_info_15"] + - [0x20103CE, bin, "Serifu_info_16"] + - [0x2010786, bin, "Serifu_info_17"] + - [0x2010BA0, bin, "Serifu_info_18"] + - [0x2010E88, bin, "Serifu_info_19"] + - [0x20111D4, bin, "Serifu_info_20"] + - [0x20116B2, bin, "Serifu_info_21"] + - [0x2011B3E, bin, "Serifu_info_23"] + - [0x2011EBE, bin, "Serifu_info_24"] + - [0x20122A6, bin, "Serifu_info_25"] + - [0x2012582, bin, "Serifu_info_26"] + - [0x2012922, bin, "Serifu_info_27"] + - [0x2012D1A, bin, "Serifu_info_28"] + - [0x201303E, bin, "Serifu_info_29"] + - [0x2013364, bin, "Serifu_info_30"] + - [0x2013626, bin, "Serifu_info_31"] + - [0x20138F0, bin, "Serifu_info_32"] + - [0x2013BBE, bin, "Serifu_info_33"] + - [0x2013ED0, bin, "Serifu_info_34"] + - [0x20140D8, bin, "Serifu_info_36"] + - [0x2014414, bin, "Serifu_info_37"] + - [0x201466C, bin, "Serifu_info_38"] + - [0x20148D0, bin, "Serifu_info_40"] + - [0x2014BEE, bin, "Serifu_info_41"] + - [0x2014FF8, bin, "Serifu_info_42"] + - [0x20153C4, bin, "Serifu_info_43"] + - [0x2015734, bin, "Serifu_info_44"] + - [0x20159D8, bin, "Serifu_info_45"] + - [0x2015C42, bin, "Serifu_info_46"] + - [0x2015ED6, bin, "Serifu_info_49"] + - [0x2016234, bin, "Serifu_info_50"] + - [0x20164F4, bin, "Serifu_info_52"] + - [0x201678A, bin, "Serifu_info_54"] + - [0x2016B26, bin, "Serifu_info_59"] + - [0x2016FCA, bin, "Serifu_info_55"] + - [0x20172DC, bin, "Serifu_info_56"] + - [0x2017700, bin, "Serifu_info_57"] + - [0x2017A72, bin, "Serifu_info_58"] + + - [0x2017E1A, bin, "Serifu_After_01"] + - [0x2018268, bin, "Serifu_After_02"] + - [0x20185FE, bin, "Serifu_After_03"] + - [0x20188A6, bin, "Serifu_After_04"] + - [0x2018CC2, bin, "Serifu_After_05"] + - [0x2018FFC, bin, "Serifu_After_06"] + - [0x2019368, bin, "Serifu_After_07"] + - [0x2019804, bin, "Serifu_After_08"] + - [0x2019C82, bin, "Serifu_After_09"] + - [0x2019FC2, bin, "Serifu_After_11"] + - [0x201A2FE, bin, "Serifu_After_12"] + - [0x201A7FC, bin, "Serifu_After_13"] + - [0x201AC18, bin, "Serifu_After_14"] + - [0x201AFAC, bin, "Serifu_After_15"] + - [0x201B384, bin, "Serifu_After_17"] + - [0x201B87C, bin, "Serifu_After_18"] + - [0x201BC1C, bin, "Serifu_After_19"] + - [0x201BFA6, bin, "Serifu_After_23"] + - [0x201C3BE, bin, "Serifu_After_24"] + - [0x201C7C0, bin, "Serifu_After_25"] + - [0x201CAF8, bin, "Serifu_After_26"] + - [0x201D0C6, bin, "Serifu_After_27"] + - [0x201D58E, bin, "Serifu_After_28"] + - [0x201DA72, bin, "Serifu_After_30"] + - [0x201DD3A, bin, "Serifu_After_32"] + - [0x201E0FA, bin, "Serifu_After_33"] + - [0x201E5B8, bin, "Serifu_After_36"] + - [0x201EA5C, bin, "Serifu_After_37"] + - [0x201EE36, bin, "Serifu_After_40"] + - [0x201F24A, bin, "Serifu_After_41"] + - [0x201F6E4, bin, "Serifu_After_42"] + - [0x201FC38, bin, "Serifu_After_43"] + - [0x202008C, bin, "Serifu_After_44"] + - [0x20204CC, bin, "Serifu_After_45"] + - [0x2020A90, bin, "Serifu_After_49"] + - [0x2020F32, bin, "Serifu_After_50"] + - [0x2021364, bin, "Serifu_After_16"] + + - [0x2021732, bin, "serifu_reconfirm"] + - [0x2021928, bin, "serifu_M_den"] + # Malformed archive name + - [0x2024746, bin] + + # Found in DMA log (N64 startup) + - [0x238E8B2, bin] + # Found in DMA log (N64 startup) + - [0x238f7ba, bin] + + - [0x26FF9F0, bin, "viewdata"] + - [0x26FFC28, bin, "viewdata1"] + - [0x26FFD48, bin, "viewdata2"] + + - [0x26FFE72, bin, "b_circle"] + - [0x26FFEEC, bin, "point1"] + - [0x27000DA, bin, "Alp_Grad"] + - [0x2700170, bin, "ground_mm"] + + # Found in DMA log (N64 startup) + - [0x2700C62, bin] + # Suspected end of above + - [0x2702516, bin] + + - [0x2722CAC, bin, "ab"] + - [0x27256D6, bin, "icon_waku"] + - [0x2728556, bin, "field_timer2"] + - [0x2729F86, bin, "kanjo"] + - [0x272A17E, bin, "battlecom"] + - [0x272BD52, bin, "fild_efe"] + - [0x272FBE4, bin, "hurt_kira"] + - [0x27302CE, bin, "cur"] + - [0x2730A5A, bin, "curshade"] + - [0x2730AFE, bin, "kdat"] + - [0x273FDFE, bin, "kmarks"] + # treasure, trline, congra, zombichk + - [0x2740698, bin, "treasure"] + - [0x2741762, bin, "mission"] + - [0x274266C, bin, "regnum"] + + - [0x274288A, bin, "actionp"] + - [0x27429D8, bin, "enemydat.bin"] + + - [0x2744DD0, bin, "spmap"] + - [0x27451AE, bin, "scincsv"] + - [0x2747619, bin, "shopcsv"] + - [0x274783E, bin, "eset"] + - [0x274CE30, bin, "MESWIN00.BIN"] + - [0x274F57A, bin, "szdata.sbd"] + # to_ele, to_ali, godmask, godsname + - [0x27518A4, bin, "to_ele.lha"] + - [0x2800000] diff --git a/src/19DD0.c b/src/19DD0.c new file mode 100644 index 0000000..3599d40 --- /dev/null +++ b/src/19DD0.c @@ -0,0 +1,13 @@ +#include "common.h" + +#include + +extern s32 FP_800A9E84; + +void __set_fp_800A9E84(s32 arg0) { + s32 mask; + + mask = osSetIntMask(OS_IM_NONE); + FP_800A9E84 = arg0; + osSetIntMask(mask); +} diff --git a/src/1A050.c b/src/1A050.c new file mode 100644 index 0000000..c20d05a --- /dev/null +++ b/src/1A050.c @@ -0,0 +1,28 @@ +#include "common.h" + +#include + +OSPiHandle* CART_HANDLE; +OSMesgQueue MQ_800BE030; +OSMesg OSMESG_800BE048[0x32]; + +INCLUDE_ASM(const s32, "1A050", func_80089C50); + +INCLUDE_ASM(const s32, "1A050", __init_controllers); + +INCLUDE_ASM(const s32, "1A050", func_80089CF8); + +INCLUDE_ASM(const s32, "1A050", func_80089D5C); + +INCLUDE_ASM(const s32, "1A050", __start_controller_thread); + +INCLUDE_ASM(const s32, "1A050", __controller_thread_80089D9C); + +void initialise(void) { + osCreatePiManager(OS_PRIORITY_PIMGR, &MQ_800BE030, OSMESG_800BE048, sizeof(OSMESG_800BE048) / sizeof(OSMesg)); + CART_HANDLE = osCartRomInit(); +} + +INCLUDE_ASM(const s32, "1A050", romCopy); + +INCLUDE_ASM(const s32, "1A050", func_8008A040); diff --git a/src/1A660.c b/src/1A660.c new file mode 100644 index 0000000..5eb00b2 --- /dev/null +++ b/src/1A660.c @@ -0,0 +1,47 @@ +#include "common.h" + +#include + +extern void func_8008A354(); +extern void func_8008A37C(); + +extern u32 D_800C4B30; +extern OSMesgQueue MQ_CONTROLLER; + +INCLUDE_ASM(const s32, "1A660", func_8008A260); + +INCLUDE_ASM(const s32, "1A660", func_8008A334); + +INCLUDE_ASM(const s32, "1A660", __start_copy_global_controller_data); + +INCLUDE_ASM(const s32, "1A660", __end_copy_global_controller_data); + +// INCLUDE_ASM(const s32, "1A660", __read_controller); + + +s32 __read_controller(OSContPad* data, u32 arg1) { + s32 res; + + res = osContStartReadData(&MQ_CONTROLLER); + if(res != 0) + return res; + + osRecvMesg(&MQ_CONTROLLER, NULL, OS_MESG_BLOCK); + if (!(arg1 & D_800C4B30)) { + func_8008A354(); + osContGetReadData(data); + func_8008A37C(); + return 0; + } + + return 0; +} + + +INCLUDE_ASM(const s32, "1A660", __real_read_controller); + +INCLUDE_ASM(const s32, "1A660", __calls_read_controller_0); + +INCLUDE_ASM(const s32, "1A660", __calls_read_controller_1); + +INCLUDE_ASM(const s32, "1A660", __calls_read_controller_2); diff --git a/src/boot.c b/src/boot.c new file mode 100644 index 0000000..939b163 --- /dev/null +++ b/src/boot.c @@ -0,0 +1,18 @@ +#include "common.h" + +#include + +void idle(void* arg); + +// static OSThread IDLE_THREAD; +// static char SP_THREAD_IDLE[OS_PIM_STACKSIZE]; + +// void boot(void) { +// osInitialize(); +// osCreateThread(&IDLE_THREAD, 1, idle, NULL, &SP_THREAD_IDLE, 0xA); +// osStartThread(&IDLE_THREAD); +// } + +INCLUDE_ASM(const s32, "boot", boot); + +INCLUDE_ASM(const s32, "boot", idle); \ No newline at end of file diff --git a/src/character.c b/src/character.c new file mode 100644 index 0000000..ce2e115 --- /dev/null +++ b/src/character.c @@ -0,0 +1,32 @@ +#ifndef __CHARACTER_H__ +#define __CHARACTER_H__ + +#include + +typedef struct { + // Possible data still undiscovered: + // - Element + // - Gender + // - Alignment + // - Held items (four u16's) + + /* 0x00 */ s8 name[0x10]; + /* 0x10 */ u16 portrait; + /* 0x12 */ u8 class; + /* 0x13 */ u8 level; + /* 0x14 */ u8 field_0x14[0x2]; + /* 0x16 */ u16 max_hp; + /* 0x18 */ u16 cur_hp; + /* 0x1A */ u8 field_0x1a[0x2]; + /* 0x1C */ u16 strength; + /* 0x1E */ u16 vitality; + /* 0x20 */ u16 intelligence; + /* 0x22 */ u16 mem; + /* 0x24 */ u16 agility; + /* 0x26 */ u16 dexterity; + /* 0x28 */ u8 field_0x28[0x10]; +} CharacterSlot; + +// const int __size = sizeof(CharacterSlot); + +#endif __CHARACTER_H__ \ No newline at end of file diff --git a/src/common.h b/src/common.h new file mode 100644 index 0000000..03cdfcc --- /dev/null +++ b/src/common.h @@ -0,0 +1,6 @@ +#ifndef __COMMON_H__ +#define __COMMON_H__ + +#include "include_asm.h" + +#endif \ No newline at end of file diff --git a/src/ctx.h b/src/ctx.h new file mode 100644 index 0000000..cecb347 --- /dev/null +++ b/src/ctx.h @@ -0,0 +1,338 @@ +typedef unsigned char u8; /* unsigned 8-bit */ +typedef unsigned short u16; /* unsigned 16-bit */ +typedef unsigned long u32; /* unsigned 32-bit */ +typedef unsigned long long u64; /* unsigned 64-bit */ + +typedef signed char s8; /* signed 8-bit */ +typedef short s16; /* signed 16-bit */ +typedef long s32; /* signed 32-bit */ +typedef long long s64; /* signed 64-bit */ + +typedef volatile unsigned char vu8; /* unsigned 8-bit */ +typedef volatile unsigned short vu16; /* unsigned 16-bit */ +typedef volatile unsigned long vu32; /* unsigned 32-bit */ +typedef volatile unsigned long long vu64; /* unsigned 64-bit */ + +typedef volatile signed char vs8; /* signed 8-bit */ +typedef volatile short vs16; /* signed 16-bit */ +typedef volatile long vs32; /* signed 32-bit */ +typedef volatile long long vs64; /* signed 64-bit */ + +typedef float f32; /* single prec floating point */ +typedef double f64; /* double prec floating point */ + +typedef unsigned long size_t; + +#define NULL 0 + +#define true 1 +#define false 0 + + +/* Flags to turn blocking on/off when sending/receiving message */ +#define OS_MESG_NOBLOCK 0 +#define OS_MESG_BLOCK 1 + +/* Recommended thread priorities for the system threads */ +#define OS_PRIORITY_MAX 255 +#define OS_PRIORITY_VIMGR 254 +#define OS_PRIORITY_RMON 250 +#define OS_PRIORITY_RMONSPIN 200 +#define OS_PRIORITY_PIMGR 150 +#define OS_PRIORITY_SIMGR 140 +#define OS_PRIORITY_APPMAX 127 +#define OS_PRIORITY_IDLE 0 /* Must be 0 */ + +typedef s32 OSPri; +typedef s32 OSId; +typedef union { struct { f32 f_odd; f32 f_even; } f; f64 d; } __OSfp; + +typedef struct { + u64 at, v0, v1, a0, a1, a2, a3; + u64 t0, t1, t2, t3, t4, t5, t6, t7; + u64 s0, s1, s2, s3, s4, s5, s6, s7; + u64 t8, t9, gp, sp, s8, ra; + u64 lo, hi; + u32 sr, pc, cause, badvaddr, rcp; + u32 fpcsr; + __OSfp fp0, fp2, fp4, fp6, fp8, fp10, fp12, fp14; + __OSfp fp16, fp18, fp20, fp22, fp24, fp26, fp28, fp30; +} __OSThreadContext; + +typedef struct OSThread_s { + struct OSThread_s *next; /* run/mesg queue link */ + OSPri priority; /* run/mesg queue priority */ + struct OSThread_s **queue; /* queue thread is on */ + struct OSThread_s *tlnext; /* all threads queue link */ + u16 state; /* OS_STATE_* */ + u16 flags; /* flags for rmon */ + OSId id; /* id for debugging */ + int fp; /* thread has used fp unit */ + __OSThreadContext context; /* register/interrupt mask */ +} OSThread; +/* + * Structure for message + */ +typedef void* OSMesg; + +typedef struct { + u16 button; + s8 stick_x; /* -80 <= stick_x <= 80 */ + s8 stick_y; /* -80 <= stick_y <= 80 */ + u8 errno; +} OSContPad; + +/* + * Structure for message queue + */ +typedef struct OSMesgQueue_s { + OSThread *mtqueue; /* Queue to store threads blocked + on empty mailboxes (receive) */ + OSThread *fullqueue; /* Queue to store threads blocked + on full mailboxes (send) */ + s32 validCount; /* Contains number of valid message */ + s32 first; /* Points to first valid message */ + s32 msgCount; /* Contains total # of messages */ + OSMesg *msg; /* Points to message buffer array */ +} OSMesgQueue; + +/* + * OSTranxInfo is set up for Leo Disk DMA. This info will be maintained + * by exception handler. This is how the PIMGR and the ISR communicate. + */ +typedef struct { + u32 errStatus; /* error status */ + void *dramAddr; /* RDRAM buffer address (DMA) */ + void *C2Addr; /* C2 buffer address */ + u32 sectorSize; /* size of transfering sector */ + u32 C1ErrNum; /* total # of C1 errors */ + u32 C1ErrSector[4]; /* error sectors */ +} __OSBlockInfo; + +typedef struct { + u32 cmdType; /* for disk only */ + u16 transferMode; /* Block, Track, or sector? */ + u16 blockNum; /* which block is transfering */ + s32 sectorNum; /* which sector is transfering */ + u32 devAddr; /* Device buffer address */ + u32 bmCtlShadow; /* asic bm_ctl(510) register shadow ram */ + u32 seqCtlShadow; /* asic seq_ctl(518) register shadow ram */ + __OSBlockInfo block[2]; /* bolck transfer info */ +} __OSTranxInfo; + + +typedef struct OSPiHandle_s { + struct OSPiHandle_s *next; /* point to next handle on the table */ + u8 type; /* DEVICE_TYPE_BULK for disk */ + u8 latency; /* domain latency */ + u8 pageSize; /* domain page size */ + u8 relDuration; /* domain release duration */ + u8 pulse; /* domain pulse width */ + u8 domain; /* which domain */ + u32 baseAddress; /* Domain address */ + u32 speed; /* for roms only */ + /* The following are "private" elements" */ + __OSTranxInfo transferInfo; /* for disk only */ +} OSPiHandle; + +/* + * Structure for I/O message block + */ +typedef struct { + u16 type; /* Message type */ + u8 pri; /* Message priority (High or Normal) */ + u8 status; /* Return status */ + OSMesgQueue *retQueue; /* Return message queue to notify I/O + * completion */ +} OSIoMesgHdr; + +typedef struct { + OSIoMesgHdr hdr; /* Message header */ + void * dramAddr; /* RDRAM buffer address (DMA) */ + u32 devAddr; /* Device buffer address (DMA) */ + u32 size; /* DMA transfer size in bytes */ + OSPiHandle *piHandle; /* PI device handle */ +} OSIoMesg; + +/* + * Structure for device manager block + */ +typedef struct { + s32 active; /* Status flag */ + OSThread *thread; /* Calling thread */ + OSMesgQueue *cmdQueue; /* Command queue */ + OSMesgQueue *evtQueue; /* Event queue */ + OSMesgQueue *acsQueue; /* Access queue */ + /* Raw DMA routine */ + s32 (*dma)(s32, u32, void *, u32); + s32 (*edma)(OSPiHandle *, s32, u32, void *, u32); +} OSDevMgr; + + +#define OS_SC_STACKSIZE 0x2000 + +#define OS_SC_RETRACE_MSG 1 +#define OS_SC_DONE_MSG 2 +#define OS_SC_RDP_DONE_MSG 3 +#define OS_SC_PRE_NMI_MSG 4 +#define OS_SC_LAST_MSG 4 /* this should have highest number */ +#define OS_SC_MAX_MESGS 8 + +typedef struct { + short type; + char misc[30]; +} OSScMsg; + +typedef struct { + u32 type; + u32 flags; + + u64 *ucode_boot; + u32 ucode_boot_size; + + u64 *ucode; + u32 ucode_size; + + u64 *ucode_data; + u32 ucode_data_size; + + u64 *dram_stack; + u32 dram_stack_size; + + u64 *output_buff; + u64 *output_buff_size; + + u64 *data_ptr; + u32 data_size; + + u64 *yield_data_ptr; + u32 yield_data_size; + +} OSTask_t; + +typedef union { + OSTask_t t; + long long int force_structure_alignment; +} OSTask; + +typedef struct OSScTask_s { + struct OSScTask_s *next; /* note: this must be first */ + u32 state; + u32 flags; + void *framebuffer; /* used by graphics tasks */ + + OSTask list; + OSMesgQueue *msgQ; + OSMesg msg; +} OSScTask; /* non FINALROM code */ + +/* + * OSScTask flags: + */ +#define OS_SC_NEEDS_RDP 0x0001 /* uses the RDP */ +#define OS_SC_NEEDS_RSP 0x0002 /* uses the RSP */ +#define OS_SC_DRAM_DLIST 0x0004 /* SP & DP communicate through DRAM */ +#define OS_SC_PARALLEL_TASK 0x0010 /* must be first gfx task on list */ +#define OS_SC_LAST_TASK 0x0020 /* last task in queue for frame */ +#define OS_SC_SWAPBUFFER 0x0040 /* swapbuffers when gfx task done */ + +#define OS_SC_RCP_MASK 0x0003 /* mask for needs bits */ +#define OS_SC_TYPE_MASK 0x0007 /* complete type mask */ +/* + * OSScClient: + * + * Data structure used by threads that wish to communicate to the + * scheduling thread + * + */ +typedef struct SCClient_s { + struct SCClient_s *next; /* next client in the list */ + OSMesgQueue *msgQ; /* where to send the frame msg */ +} OSScClient; + +typedef struct { + OSScMsg retraceMsg; + OSScMsg prenmiMsg; + OSMesgQueue interruptQ; + OSMesg intBuf[8]; + OSMesgQueue cmdQ; + OSMesg cmdMsgBuf[8]; + OSThread thread; + OSScClient *clientList; + OSScTask *audioListHead; + OSScTask *gfxListHead; + OSScTask *audioListTail; + OSScTask *gfxListTail; + OSScTask *curRSPTask; + OSScTask *curRDPTask; + u32 frameCount; + s32 doAudio; +} OSSched; + +/* Buttons */ +#define CONT_A 0x8000 +#define CONT_B 0x4000 +#define CONT_G 0x2000 +#define CONT_START 0x1000 +#define CONT_UP 0x0800 +#define CONT_DOWN 0x0400 +#define CONT_LEFT 0x0200 +#define CONT_RIGHT 0x0100 +#define CONT_L 0x0020 +#define CONT_R 0x0010 +#define CONT_E 0x0008 +#define CONT_D 0x0004 +#define CONT_C 0x0002 +#define CONT_F 0x0001 + +/* Nintendo's official button names */ +#define A_BUTTON CONT_A +#define B_BUTTON CONT_B +#define L_TRIG CONT_L +#define R_TRIG CONT_R +#define Z_TRIG CONT_G +#define START_BUTTON CONT_START +#define U_JPAD CONT_UP +#define L_JPAD CONT_LEFT +#define R_JPAD CONT_RIGHT +#define D_JPAD CONT_DOWN +#define U_CBUTTONS CONT_E +#define L_CBUTTONS CONT_C +#define R_CBUTTONS CONT_F +#define D_CBUTTONS CONT_D + +extern void osContGetReadData(OSContPad* data); +extern s32 osContStartReadData(OSMesgQueue *mq); +extern s32 osRecvMesg(OSMesgQueue *mq, OSMesg *msg, s32 flags); +extern void osCreateThread(OSThread *t, OSId id, void (*entry)(void *), void *arg, void *sp, OSPri p); +extern void osSetThreadPri(OSThread *t, OSPri pri); +extern void osStartThread(OSThread *t); +extern void osCreateScheduler(OSSched *s, void *stack, OSPri priority, u8 mode, u8 retraceCount); + +extern void osCreateMesgQueue(OSMesgQueue *mq, OSMesg *msg, s32 count); +extern void osSendMesg(OSMesgQueue *mq, OSMesg msg, s32 flag); +extern void osJamMesg(OSMesgQueue *mq, OSMesg msg, s32 flag); +extern s32 osRecvMesg(OSMesgQueue *mq, OSMesg *msg, s32 flag); + +extern void osInvalDCache(void *vaddr, s32 nbytes); + +extern OSPiHandle* CART_HANDLE; +extern s32 osEPiStartDma(OSPiHandle *pihandle, OSIoMesg *mb, s32 direction); +extern s32 osEPiWriteIo(OSPiHandle *pihandle, u32 devAddr, u32 data); +extern s32 osEPiReadIo(OSPiHandle *pihandle, u32 devAddr, u32 *data); + +extern void osInitialize(void); + +extern void MusFxBankSetPtrBank(void *ifxbank, void *ipbank); +extern void MusSetMasterVolume(unsigned long flags, int volume); +extern void MusFxBankInitialize(void *fxbank); + +extern void osViSetSpecialFeatures(u32 func); + +extern void boot(void* arg); +extern void idle(void* arg); +extern void main_(void* arg); + +extern void romCopy(u8* src, u8* dst, u32 len); + +extern void __calls_romCopy_8009DA50(u8* src, u8* dst, u32 len); \ No newline at end of file diff --git a/src/mus.c b/src/mus.c new file mode 100644 index 0000000..2057673 --- /dev/null +++ b/src/mus.c @@ -0,0 +1,259 @@ +#include "common.h" + +#include + + +extern void* musCurrentPtrBank; + +void func_8008350C(); + +INCLUDE_ASM(const s32, "mus", func_800810F0); + +INCLUDE_ASM(const s32, "mus", func_8008123C); + +INCLUDE_ASM(const s32, "mus", MusSetMasterVolume); + +INCLUDE_ASM(const s32, "mus", MusStartSong); + +INCLUDE_ASM(const s32, "mus", func_80081520); + +INCLUDE_ASM(const s32, "mus", func_80081770); + +INCLUDE_ASM(const s32, "mus", func_800817F0); + +INCLUDE_ASM(const s32, "mus", func_80081908); + +INCLUDE_ASM(const s32, "mus", __dma_load_loop_check); + +INCLUDE_ASM(const s32, "mus", func_80081A54); + +INCLUDE_ASM(const s32, "mus", func_80081B08); + +INCLUDE_ASM(const s32, "mus", func_80081B60); + +INCLUDE_ASM(const s32, "mus", func_80081BC0); + +INCLUDE_ASM(const s32, "mus", func_80081C30); + +INCLUDE_ASM(const s32, "mus", func_80081CA0); + +INCLUDE_ASM(const s32, "mus", func_80081D2C); + +void __something_music(void* arg0) { + func_8008350C(); + + if (musCurrentPtrBank == 0) { + musCurrentPtrBank = arg0; + } +} + +// INCLUDE_ASM(const s32, "mus", func_80081DF0); +extern void* D_800B1828; + +void* func_80081DF0(void* arg0) { + if ((arg0 != NULL) && ((*(s32*)(arg0 + 0x10)) < 0)) { + D_800B1828 = arg0; + } + return D_800B1828; +} + + +INCLUDE_ASM(const s32, "mus", MusPtrBankSetCurrent); + +// void MusPtrBankSetCurrent(void* arg0) { +// if ((arg0 != NULL) && (arg0->unk10 < 0)) { +// D_800B182C = arg0; +// } +// } + +INCLUDE_ASM(const s32, "mus", func_80081E3C); + +INCLUDE_ASM(const s32, "mus", func_80081E48); + +INCLUDE_ASM(const s32, "mus", MusHandlePause); + +INCLUDE_ASM(const s32, "mus", MusHandleUnpause); + +INCLUDE_ASM(const s32, "mus", MusSetFxType); + +INCLUDE_ASM(const s32, "mus", func_80081F20); + +INCLUDE_ASM(const s32, "mus", MusFxBankInitialize); + +INCLUDE_ASM(const s32, "mus", MusFxBankNumberOfEffects); + +INCLUDE_ASM(const s32, "mus", func_80082008); + +INCLUDE_ASM(const s32, "mus", func_80082014); + +INCLUDE_ASM(const s32, "mus", func_80082020); + +INCLUDE_ASM(const s32, "mus", MusFxBankSetPtrBank); + +INCLUDE_ASM(const s32, "mus", MusFxBankGetPtrBank); + +INCLUDE_ASM(const s32, "mus", func_8008203C); + +INCLUDE_ASM(const s32, "mus", func_80082048); + +INCLUDE_ASM(const s32, "mus", func_800820AC); + +INCLUDE_ASM(const s32, "mus", func_80082124); + +INCLUDE_ASM(const s32, "mus", func_80082130); + +INCLUDE_ASM(const s32, "mus", func_80082194); + +INCLUDE_ASM(const s32, "mus", func_80082214); + +INCLUDE_ASM(const s32, "mus", func_800822AC); + +INCLUDE_ASM(const s32, "mus", func_8008259C); + +INCLUDE_ASM(const s32, "mus", func_80082AE8); + +INCLUDE_ASM(const s32, "mus", func_80082B64); + +INCLUDE_ASM(const s32, "mus", func_80082CB8); + +INCLUDE_ASM(const s32, "mus", func_80082DC4); + +INCLUDE_ASM(const s32, "mus", func_80082E34); + +INCLUDE_ASM(const s32, "mus", __MusIntInitSweep); + +INCLUDE_ASM(const s32, "mus", func_8008302C); + +INCLUDE_ASM(const s32, "mus", func_800830E4); + +INCLUDE_ASM(const s32, "mus", func_8008313C); + +INCLUDE_ASM(const s32, "mus", func_800831A0); + +INCLUDE_ASM(const s32, "mus", func_80083264); + +INCLUDE_ASM(const s32, "mus", func_80083378); + +INCLUDE_ASM(const s32, "mus", func_8008350C); + +INCLUDE_ASM(const s32, "mus", func_800836A4); + +INCLUDE_ASM(const s32, "mus", func_80083738); + +INCLUDE_ASM(const s32, "mus", func_80083874); + +INCLUDE_ASM(const s32, "mus", func_80083A3C); + +INCLUDE_ASM(const s32, "mus", func_80083A74); + +INCLUDE_ASM(const s32, "mus", func_80083B24); + +INCLUDE_ASM(const s32, "mus", func_80083CCC); + +INCLUDE_ASM(const s32, "mus", func_80083F38); + +INCLUDE_ASM(const s32, "mus", func_80083F8C); + +INCLUDE_ASM(const s32, "mus", func_80083FAC); + +INCLUDE_ASM(const s32, "mus", func_80083FDC); + +INCLUDE_ASM(const s32, "mus", func_80083FFC); + +INCLUDE_ASM(const s32, "mus", func_80084008); + +INCLUDE_ASM(const s32, "mus", func_80084130); + +INCLUDE_ASM(const s32, "mus", func_80084214); + +INCLUDE_ASM(const s32, "mus", func_80084228); + +INCLUDE_ASM(const s32, "mus", func_8008424C); + +INCLUDE_ASM(const s32, "mus", func_800842BC); + +INCLUDE_ASM(const s32, "mus", func_80084330); + +INCLUDE_ASM(const s32, "mus", func_80084340); + +INCLUDE_ASM(const s32, "mus", func_80084370); + +INCLUDE_ASM(const s32, "mus", func_80084380); + +INCLUDE_ASM(const s32, "mus", func_80084390); + +INCLUDE_ASM(const s32, "mus", func_800843A0); + +INCLUDE_ASM(const s32, "mus", func_800843F8); + +INCLUDE_ASM(const s32, "mus", func_80084408); + +INCLUDE_ASM(const s32, "mus", func_80084414); + +INCLUDE_ASM(const s32, "mus", func_80084424); + +INCLUDE_ASM(const s32, "mus", func_80084430); + +INCLUDE_ASM(const s32, "mus", func_8008449C); + +INCLUDE_ASM(const s32, "mus", func_80084538); + +INCLUDE_ASM(const s32, "mus", func_80084560); + +INCLUDE_ASM(const s32, "mus", func_8008456C); + +INCLUDE_ASM(const s32, "mus", func_8008457C); + +INCLUDE_ASM(const s32, "mus", func_80084588); + +INCLUDE_ASM(const s32, "mus", func_8008459C); + +INCLUDE_ASM(const s32, "mus", func_800845B0); + +INCLUDE_ASM(const s32, "mus", func_800845B8); + +INCLUDE_ASM(const s32, "mus", func_80084600); + +INCLUDE_ASM(const s32, "mus", func_8008460C); + +INCLUDE_ASM(const s32, "mus", func_80084614); + +INCLUDE_ASM(const s32, "mus", func_80084684); + +INCLUDE_ASM(const s32, "mus", func_80084694); + +INCLUDE_ASM(const s32, "mus", func_800846E4); + +INCLUDE_ASM(const s32, "mus", func_80084734); + +INCLUDE_ASM(const s32, "mus", func_80084784); + +INCLUDE_ASM(const s32, "mus", func_80084794); + +INCLUDE_ASM(const s32, "mus", func_80084864); + +INCLUDE_ASM(const s32, "mus", func_800848A0); + +INCLUDE_ASM(const s32, "mus", func_800848B0); + +INCLUDE_ASM(const s32, "mus", func_800848F4); + +INCLUDE_ASM(const s32, "mus", func_80084964); + +INCLUDE_ASM(const s32, "mus", func_80084970); + +INCLUDE_ASM(const s32, "mus", func_800849D8); + +INCLUDE_ASM(const s32, "mus", func_80084C48); + +INCLUDE_ASM(const s32, "mus", func_80084C98); + +INCLUDE_ASM(const s32, "mus", func_80084DE0); + +INCLUDE_ASM(const s32, "mus", func_800850C0); + +INCLUDE_ASM(const s32, "mus", func_800850D8); + +INCLUDE_ASM(const s32, "mus", func_8008511C); + +INCLUDE_ASM(const s32, "mus", func_80085160); diff --git a/src/overlays/overlay0/3F1B0.c b/src/overlays/overlay0/3F1B0.c new file mode 100644 index 0000000..e462b9e --- /dev/null +++ b/src/overlays/overlay0/3F1B0.c @@ -0,0 +1,75 @@ +#include "common.h" + +#include + +INCLUDE_ASM(const s32, "overlays/overlay0/3F1B0", func_800E9C20); + +// extern u8 D_2B8BA0; +// extern u8 D_2BF250; +// extern u8 D_423FF0; +// extern u8 D_429CD0; +// extern u8 D_4E3140; +// extern u8 D_4F0FB0; +// extern u8 D_80104710; +// extern u8 D_8010A760; +// extern u8 D_80164770; + +// extern void romCopy(u8* src, u8* dst, u32 len); +// extern void __something_music(u8*, u8*); +// extern void MusFxBankInitialize(u8*); +// extern void MusFxBankSetPtrBank(u8*, u8*); + +// void func_800E9C20(void) { +// romCopy(&D_2B8BA0, &D_80164770, &D_2BF250 - &D_2B8BA0); +// romCopy(&D_423FF0, &D_80104710, &D_429CD0 - &D_423FF0); +// romCopy(&D_4E3140, &D_8010A760, &D_4F0FB0 - &D_4E3140); +// __something_music(&D_80164770, &D_2BF250); +// __something_music(&D_80104710, &D_429CD0); +// MusFxBankInitialize(&D_8010A760); +// MusFxBankSetPtrBank(&D_8010A760, &D_80104710); +// } + + +INCLUDE_ASM(const s32, "overlays/overlay0/3F1B0", func_800E9CEC); + +INCLUDE_ASM(const s32, "overlays/overlay0/3F1B0", func_800E9E34); + +INCLUDE_ASM(const s32, "overlays/overlay0/3F1B0", func_800EA0E4); + +INCLUDE_ASM(const s32, "overlays/overlay0/3F1B0", func_800EA1C8); + +INCLUDE_ASM(const s32, "overlays/overlay0/3F1B0", func_800EA3BC); + +INCLUDE_ASM(const s32, "overlays/overlay0/3F1B0", func_800EA3E4); + +INCLUDE_ASM(const s32, "overlays/overlay0/3F1B0", func_800EA488); + +INCLUDE_ASM(const s32, "overlays/overlay0/3F1B0", func_800EA568); + +INCLUDE_ASM(const s32, "overlays/overlay0/3F1B0", func_800EA604); + +INCLUDE_ASM(const s32, "overlays/overlay0/3F1B0", func_800EA6B0); + +INCLUDE_ASM(const s32, "overlays/overlay0/3F1B0", func_800EA6C8); + +INCLUDE_ASM(const s32, "overlays/overlay0/3F1B0", func_800EA714); + +INCLUDE_ASM(const s32, "overlays/overlay0/3F1B0", func_800EA76C); + +INCLUDE_ASM(const s32, "overlays/overlay0/3F1B0", func_800EA7AC); + +INCLUDE_ASM(const s32, "overlays/overlay0/3F1B0", func_800EA7E4); + +INCLUDE_ASM(const s32, "overlays/overlay0/3F1B0", func_800EA838); + +INCLUDE_ASM(const s32, "overlays/overlay0/3F1B0", func_800EA850); + +INCLUDE_ASM(const s32, "overlays/overlay0/3F1B0", func_800EA86C); + +INCLUDE_ASM(const s32, "overlays/overlay0/3F1B0", func_800EA884); + +INCLUDE_ASM(const s32, "overlays/overlay0/3F1B0", func_800EA89C); + +INCLUDE_ASM(const s32, "overlays/overlay0/3F1B0", func_800EA8B4); + +INCLUDE_ASM(const s32, "overlays/overlay0/3F1B0", func_800EA8CC); diff --git a/symbol_addrs.txt b/symbol_addrs.txt new file mode 100644 index 0000000..6f5f551 --- /dev/null +++ b/symbol_addrs.txt @@ -0,0 +1,337 @@ + +maybe_boot_01 = 0x800851C0; + +__CONTROLLER_0_BUTTON = 0x800E8700; +__menu_handle_input = 0x8019B8AC; // type:func + +__MENU_TIMER = 0x801BA540; // type:u32 +__inc_menu_timer = 0x8019BCEC; // type:func rom:0x1D21EC +__calls_inc_menu_timer = 0x80177A38; // rom:0x4D938 +__MENU_INDEX = 0x801BA94C; + +musCurrentPtrBank = 0x800B182C; + +osViModeTable = 0x800AA7E0; +osViSetMode = 0x800955C0; +osViSetEvent = 0x80095560; +osCreateScheduler = 0x80088C50; +osViBlack = 0x80089BE4; +osViSetSpecialFeatures = 0x80095610; + +__init_controllers = 0x80089C60; + +MusFxBankInitialize = 0x80081F7C; + +osGetCause = 0x8009A6D0; +osGetSR = 0x8009A6F0; +osSetCompare = 0x8009A700; +osSetFpcCsr = 0x8009A710; +osSetSR = 0x8009A720; +osUnmapTLBAll = 0x8009AB00; +osMapTLBRdb = 0x8009AAA0; + + +__something_music = 0x80081DB4; + +__real_read_controller = 0x8008A42C; + +__calls_romCopy_8009DA50 = 0x8009DA50; +__calls_romCopy_8009DAF4 = 0x8009DAF4; +__calls_romCopy_8009DBB8 = 0x8009DBB8; +__calls_romCopy_8009DD38 = 0x8009DD38; +__calls_romCopy_8009DE40 = 0x8009DE40; +__calls_romCopy_8009DF48 = 0x8009DF48; + +__start_thread_800BE1C0 = 0x8008B0B0; +__start_thread_800B9C88 = 0x80089660; + +magnitude = 0x8009C780; + +main_ = 0x80071EB0; + +__dma_load_loop = 0x80089A30; +__dma_load_loop_check = 0x800819D4; + +__MUS_MEM_800B18A4 = 0x800B18A4; // size:0x58 +__MUS_MEM_800B186C = 0x800B186C; +__MUS_MEM_800B1870 = 0x800B1870; +__MUS_MEM_800B1868 = 0x800B1868; + +MQ_CONTROLLER = 0x800E9B88; +MQ_800E7988 = 0x800E7988; +MQ_800C4A00 = 0x800C4A00; +MQ_800E9BF0 = 0x800E9BF0; +MQ_800C4C28 = 0x800C4C28; +MQ_800C35A0 = 0x800C35A0; +MQ_800AF320 = 0x800AF320; +MQ_800B1880 = 0x800B1880; +MQ_800E79C8 = 0x800E79C8; +MQ_800C49E8 = 0x800C49E8; +MQ_800BE030 = 0x800BE030; +MQ_800E8B84 = 0x800E8B84; +MQ_800B9C40 = 0x800B9C40; +MQ_800E8B4C = 0x800E8B4C; + +OSMESG_800BE190 = 0x800BE190; +OSMESG_800BE194 = 0x800BE194; +OSMESG_800BE1A0 = 0x800BE1A0; +OSMESG_800B1870 = 0x800B1870; +OSMESG_800B17D0 = 0x800B17D0; +OSMESG_800B17E0 = 0x800B17E0; +OSMESG_800BE048 = 0x800BE048; +OSMESG_800B9C58 = 0x800B9C58; +OSMESG_800B9C80 = 0x800B9C80; + +SP_THREAD_IDLE = 0x800B17A0; +SP_THREAD_FIRST_DMA_LOAD = 0x800C6D60; +SP_THREAD_800BE1C0 = 0x800C2370; +SP_THREAD_800B9C88 = 0x800BBE40; + +THREAD_CONTROLLER = 0x800BBE80; +THREAD_FIRST_DMA_LOAD = 0x800AF5F0; +THREAD_800B7A90 = 0x800B7A90; +THREAD_800BE1C0 = 0x800BE1C0; +THREAD_800B9C88 = 0x800B9C88; + +__thread_8007AC30 = 0x8007AC30; +__thread_8008AFE0 = 0x8008AFE0; +__thread_80093EE8 = 0x80093EE8; +__thread_80088F08 = 0x80088F08; +__thread_80089200 = 0x80089200; +__thread_800893C0 = 0x800893C0; +__thread_80089540 = 0x80089540; + +__scMain = 0x80089358; + +FP_800A9E84 = 0x800A9E84; + +__set_fp_800A9E84 = 0x800899D0; + +romCopy = 0x80089F80; +CART_HANDLE = 0x800E7A20; +__CART_HANDLE_800B1898 = 0x800B1898; + +__GLOBAL_CONTROLLER_DATA = 0x0800C4BF0; // size:0x18 +__GLOBAL_CONTROLLER_DATA_COPY = 0x0800AEE78; // size:0x18 + +__start_controller_thread = 0x80089D7C; +__calls_copy_controller_data = 0x8007297C; +__copy_global_controller_data = 0x8008A600; +__start_copy_global_controller_data = 0x8008A354; +__end_copy_global_controller_data = 0x8008A37C; +__read_controller = 0x8008A3A4; +__calls_read_controller_0 = 0x8008A47C; +__calls_read_controller_1 = 0x8008A508; +__calls_read_controller_2 = 0x8008A528; + +__CRC_ERROR = 0x800AE2A0; +__FILE_WRITE_ERROR = 0x800AE348; +__FILE_READ_ERROR = 0x800AE378; +__logs_read_error = 0x8007C590; +__file_read = 0x8007F570; +___FILE_WRITE_ERROR = 0x800AE38C; +__file_write = 0x08007F5D8; +__ERROR_BAD_TABLE = 0x800AE338; +__VIRTUAL_MEMORY_EXHAUSTED = 0x800AE35C; +__some_logging = 0x80093540; +__virtual_mem_alloc = 0x80070F30; + +__controller_thread_80089D9C = 0x80089D9C; +__Mus_thread_80085908 = 0x80085908; + + + +THREAD_IDLE = 0x800AF440; +idle = 0x8007F8E4; + +initialise = 0x80089F40; + +boot = 0x8007F880; +entry = 0x80070C00; + +guRotateRPYF = 0x80092A90; + + +CHARACTER_SLOT_MAGNUS = 0x80193BF8; // size:0x38 +CHARACTER_SLOT_01 = 0x80193C30; // size:0x38 +CHARACTER_SLOT_02 = 0x80193C68; // size:0x38 + +PERSPECTIVE_MATRIX_00 = 0x801969b0; +PERSPECTIVE_MATRIX_01 = 0x800C4BE4; + +AddHeap = 0x80070D20; +HIsAllocatedPointer = 0x800714D4; +can_log_crc_error = 0x8007B88C; + +proutSprintf = 0x80093508; +osSyncPrintf = 0x80093540; +rmonPrintf = 0x80093554; + +bzero = 0x80093380; +strchr = 0x80093420; +strlen = 0x80093460; +memcpy = 0x80093484; + +_bcmp = 0x80092F50; +_bcopy = 0x80093060; + +MusHandlePause = 0x80081EA4; +MusHandleUnpause = 0x80081EC8; +MusSetFxType = 0x80081EF0; +MusFxBankNumberOfEffects = 0x80082000; +MusFxBankSetPtrBank = 0x8008202C; +MusFxBankGetPtrBank = 0x80082034; +MusSetMasterVolume = 0x800814C4; +MusStartSong = 0x800814F0; +MusPtrBankSetCurrent = 0x80081E18; + +__MusIntInitSweep = 0x80083010; +__MusIntMemMalloc = 0x80085ADC; + +alSynAllocFX = 0x8008FF70; +alFxNew = 0x8008C694; +alFxParam = 0x8008EEA4; +alMainBusParam = 0x8008E850; +alInit = 0x8008F7A0; +alUnlink = 0x8008F81C; +alClose = 0x8008F7CC; +alLink = 0x8008F7FC; +alGlobals = 0x800AA710; +alSynNew = 0x8008F920; +alCopy = 0x8008F8E0; +alSavePull = 0x8008F6D0; +alSaveParam = 0x8008F778; +alSynDelete = 0x8008FF60; + +sqrtf = 0x800907E0; +sinf = 0x80092DB0; +cosf = 0x800907F0; + +guOrthoF = 0x800920A0; +guOrtho = 0x800921D0; +guPerspectiveF = 0x80092320; +guPerspective = 0x800924D0; +guPositionF = 0x800926A0; +guPosition = 0x80092878; +guRotateRPY = 0x80092C18; +guMtxF2L = 0x800988A0; +guMtxL2F = 0x80098920; +guMtxCatF = 0x800989A0; +guMtxCatL = 0x80098340; +guMtxXFML = 0x800983C0; +guMtxXFMF = 0x80098450; +guNormalize = 0x80098BC0; +guMtxIdent = 0x800987E0; +guMtxIdentF = 0x80098840; +guRotateF = 0x80098500; +guRotate = 0x80098660; +guScaleF = 0x80098B60; +guTranslateF = 0x80098D00; +guLookAtF = 0x80090940; +guLookAt = 0x80090CC0; +guLookAtHiliteF = 0x80091050; +guLookAtHilite = 0x800919D4; +guLookAtReflectF = 0x80091AB0; +guLookAtReflect = 0x80092028; + +CartRomHandle = 0x800C4C54; + +osTvType = 0x80000300; // type:s32 +osRomBase = 0x80000308; // type:s32 + +osInitialize = 0x80098050; +osInvalICache = 0x800900C0; +osGetCount = 0x8009A6E0; +osCreateViManager = 0x80095220; +osCreateMesgQueue = 0x80093570; +osVirtualToPhysical = 0x80090780; +osContGetReadData = 0x80090318; +osContGetQuery = 0x80090270; +osGetTime = 0x80094C90; +osSetTimer = 0x80094D40; +osYieldThread = 0x80094C40; +osGetThreadPri = 0x80094930; +osSetThreadPri = 0x80094950; +osWritebackDCache = 0x80090140; +osWritebackDCacheAll = 0x800901C0; +osSetIntMask = 0x8008B820; +osCartRomInit = 0x8008BD30; +osStartThread = 0x80094A20; +osJamMesg = 0x800935A0; +osRecvMesg = 0x800936E0; +osSendMesg = 0x80093810; +osSetEventMesg = 0x80093940; +osContStartQuery = 0x800901F0; +osContInit = 0x80090470; +osContStartReadData = 0x80090290; +osCreateThread = 0x80094860; +osCreatePiManager = 0x8008B8C0; +osInvalDCache = 0x80090010; +osDestroyThread = 0x8009A9C0; + +__osDevMgrMain = 0x8008BEB0; +__osPackReadData = 0x800903B4; +__osProbeTLB = 0x800950E0; +__osEnqueueAndYield = 0x800993DC; +__osDisableInt = 0x800996D0; +__osRestoreInt = 0x80099740; +__osPopThread = 0x8009952C; +__osThreadTail = 0x800AA790; +__osContLastCmd = 0x800E79A8; +__osPackRequestData = 0x800906C0; +__osContPifRam = 0x800C4A20; // size:0x40 +__osContGetInitData = 0x8009060C; +__osViGetCurrentContext = 0x8009AC60; +__osViSwapContext = 0x80095820; +__osTimerInterrupt = 0x80094E34; +__osViIntrCount = 0x800C4BA8; +__osDequeueThread = 0x80094C00; +__osRunningThread = 0x800AA7A0; +__osDispatchThread = 0x8009953C; +__osActiveQueue = 0x800AA79C; +__osTimerServicesInit = 0x80094DE0; +__osSiAccessQueue = 0x800E9BC8; +__osViInit = 0x8009AB50; +__osBaseCounter = 0x800C4814; +__osCurrentTime = 0x800C4C40; +__osContinitialized = 0x800AA720; +__osMaxControllers = 0x800C4C1C; +__osSiCreateAccessQueue = 0x80094770; +__osEepromTimerQ = 0x800E99D0; +__osEepromTimerMsg = 0x800E79B8; + +piAccessBuf = 0x800C3550; +piEventQueue = 0x800C3530; +piEventBuf = 0x800C3548; +piThread = 0x800C2380; + +osPiStartDma = 0x8008C360; +osEPiStartDma = 0x8008BC40; +osPiGetCmdQueue = 0x800998C0; + +__osPiCreateAccessQueue = 0x8008C270; +__osPiRelAccess = 0x8008C330; +__osPiGetAccess = 0x8008C2C4; +__osPiAccessQueueEnabled = 0x800AA440; +__osPiAccessQueue = 0x800C4CC8; +__osPiDevMgr = 0x800AA400; // size:0x1C + +siAccessBuf = 0x800C35A0; + +__osSiRawStartDma = 0x800946C0; +__osSiRawStartDma = 0x800946C0; +__osSiRelAccess = 0x80094830; +__osSiGetAccess = 0x800947C4; +__osSiAccessQueueEnabled = 0x800AA780; + +__osSpGetStatus = 0x800939F0; + +viMgrMain = 0x800953C0; + +viEventQueue = 0x800C4770; +viEventBuf = 0x800C4788; +viRetraceMsg = 0x800C47A0; // size:0x18 +viCounterMsg = 0x800C47B8; // size:0x18 + +__osViDevMgr = 0x800AA7C0; // size:0x1C + diff --git a/tools/data_structure.py b/tools/data_structure.py new file mode 100644 index 0000000..3491871 --- /dev/null +++ b/tools/data_structure.py @@ -0,0 +1,271 @@ +import struct +from collections import namedtuple + +CLASS_NAME = { + 0x01: "Soldier", + 0x02: "Fighter", + 0x03: "Lycanthrope", + 0x04: "Amazon", + 0x05: "Knight", + 0x06: "Berserker", + 0x07: "Fencer", + 0x08: "Phalanx", + 0x09: "BeastTamer", + 0x0A: "DollMaster", + 0x0B: "Ninja", + 0x0C: "Wizard", + 0x0D: "Archer", + 0x0E: "DragonTamer", + 0x0F: "Valkyrie", + 0x10: "Witch", + 0x11: "Sorceress", + 0x12: "Cleric", + 0x13: "Paladin", + 0x14: "Dragoon", + 0x15: "BlackKnight", + 0x16: "SwordMaster", + 0x17: "Cataphract", + 0x18: "BeastMaster", + 0x19: "Enchanter", + 0x1A: "NinjaMaster", + 0x1B: "Archmage", + 0x1C: "Diana", + 0x1D: "DragonMaster", + 0x1E: "Freya", + 0x1F: "Siren", + 0x20: "Priest", + 0x21: "Princess", + 0x22: "Centurion", + 0x23: "Centurion", + 0x24: "AngelKnight", + 0x25: "Seraph", + 0x26: "Lich", + 0x27: "Hawkman", + 0x28: "Vultan", + 0x29: "Raven", + 0x2A: "Werewolf", + 0x2B: "Vampire", + 0x2C: "Vampire", + 0x2D: "Zombie", + 0x2E: "Zombie", + 0x2F: "Skeleton", + 0x30: "Ghost", + 0x31: "Gorgon", + 0x32: "Pumpkinhead", + 0x33: "Faerie", + 0x34: "Gremlin", + 0x35: "Goblin", + 0x36: "Saturos", + 0x37: "Ogre", + 0x38: "YoungDragon", + 0x39: "ThunderDragon", + 0x3A: "RedDragon", + 0x3B: "EarthDragon", + 0x3C: "BlueDragon", + 0x3D: "PlatinumDragon", + 0x3E: "BlackDragon", + 0x3F: "Quetzalcoatl", + 0x40: "Flarebrass", + 0x41: "AhziDahaka", + 0x42: "Hydra", + 0x43: "Bahamut", + 0x44: "Tiamat", + 0x45: "Wyrm", + 0x46: "Wyvern", + 0x47: "Griffin", + 0x48: "Opinincus", + 0x49: "Cockatrice", + 0x4A: "Sphinx", + 0x4B: "Hellhound", + 0x4C: "Cerberus", + 0x4D: "Giant", + 0x4E: "Golem", + 0x4F: "StoneGolem", + 0x50: "BaldrGolem", + 0x51: "Gladiator", + 0x52: "Vanguard", + 0x53: "General", + 0x54: "Gladiator", + 0x55: "Warrior", + 0x56: "BlazeKnight", + 0x57: "RuneKnight", + 0x58: "Lord", + 0x59: "General", + 0x5A: "BeastMaster", + 0x5B: "Priest", + 0x5C: "Warlock", + 0x5D: "Grappler", + 0x5E: "Centurion", + 0x5F: "Lycanthrope", + 0x60: "Werewolf", + 0x61: "Solidblade", + 0x62: "Overlord", + 0x63: "DarkPrince", + 0x64: "SpecialClass", + 0x65: "FlailMonarch", + 0x66: "DeathTemplar", + 0x67: "TempleCommander", + 0x68: "TempleCommander", + 0x69: "TempleCommander", + 0x6A: "TempleCommander", + 0x6B: "TempleCommander", + 0x6C: "Vanity", + 0x6D: "Vanity", + 0x6E: "Vanity", + 0x6F: "SuperiorKnight", + 0x70: "SuperiorKnight", + 0x71: "Gatekeeper", + 0x72: "Grappler", + 0x73: "KnightTemplar", + 0x74: "Daemon", + 0x75: "Phalanx", + 0x76: "Berserker", + 0x77: "Cleric", + 0x78: "Archer", + 0x79: "Hawkman", + 0x7A: "Siren", + 0x7B: "Enchanter", + 0x7C: "BlackKnight", + 0x7D: "SpecialClass", + 0x7E: "SpecialClass", + 0x7F: "SpecialClass", + 0x80: "SpecialClass", + 0x81: "SpecialClass", + 0x82: "Barkeep", + 0x83: "ElderlyMan", + 0x84: "Commoner", + 0x85: "Commoner", + 0x86: "Danika", + 0x87: "Danika_01", + 0x88: "Danika_02", + 0x89: "Archer", + 0x8A: "Berserker", + 0x8B: "BeastTamer", + 0x8C: "Valkyrie", + 0x8D: "Wizard", + 0x8E: "Phalanx", + 0x8F: "Berserker", + 0x90: "Knight", + 0x91: "NinjaMaster", + 0x92: "DollMaster", + 0x93: "KnightTemplar", + 0x94: "Archmage", + 0x95: "Priest", + 0x96: "BlackKnight", + 0x97: "DragonMaster", + 0x98: "Siren", + 0x99: "Saturos", + 0x9A: "SwordMaster", + 0x9B: "KnightTemplar", + 0x9C: "Dragoon", + 0x9D: "Gorgon", + 0x9E: "Lich", + 0x9F: "Daemon", + 0xA0: "Plaladin", + 0xA1: "Danika", + 0xA2: "Paladin", + 0xA3: "Witch", + 0xA4: "DeathBahamut", +} + +pattern = """4D61676E 75730000 00000000 00000000 +00515104 00000059 00590132 0041003D +003C003C 003F003F 37000000 00000000 +00000002 01000000 41726E6F 6C640000 +00000000 00000000 00020203 00000053 +00370332 003A003B 00370039 0031003B +37000000 00000000 00000000 02000000 +4D612764 6F670000 00000000 00000000 +00020203 00000051 00510432 003A003C +00360039 0031003B 37000000 00000000 +00000000 03000000 486F6C6C 79000000 +00000000 00000000 00040403 01000049 +00490132 003D0033 003A003B 003D0042 +37000000 00000000 00000000 04000000 +4A65616E 6E650000 00000000 00000000 +00040403 01000049 00490432 00390033 +003B003D 003C0040 37000000 00000000 +00000000 05000000 446F726F 74687900 +00000000 00000000 00111103 0100004C +004C0123 003B0032 003C003D 003B0042 +37000000 00000000 00000002 06000000 +41737261 00000000 00000000 00000000 +00020203 00000054 00540332 003C0039 +00350039 0031003C 37000000 00000000 +00000000 07000000 436C7964 65000000 +00000000 00000000 00020203 00000052 +00520332 003C003A 0038003A 0032003B +37000000 00000000 00000000 08000000 +42727961 6E000000 00000000 00000000 +00020203 00000051 00510232 003C0038 +00350039 0031003A 38000000 00000000 +00000000 09000000 4976616E 00000000 +00000000 00000000 000A0A03 0000004F +004F0332 003D003A 0037003A 0033003C +36000000 00000000 00000002 0A000000 +48616E6E 61000000 00000000 00000000 +00040403 0100004B 004B0232 003D0034 +0039003C 003A0042 36000000 00000000 +00000000 0B000000 44696F00 00000000 +00000000 00000000 00545404 00000054 +0054012A 003E003B 00310035 00300036 +32000000 00000000 00000002 0C000000 +50697474 00000000 00000000 00000000 +00020203 00000051 00510432 003B0037 +002F0034 002D0034 32000000 00000000 +00000000 0D000000 41627261 68616D00 +00000000 00000000 00020203 00000050 +00500432 00390037 002E0035 002F0034 +32000000 00000000 00000000 0E000000 +56617564 76696C6C 65000000 00000000 +00020203 00000050 00500332 003B0039 +002D0033 002F0033 32000000 00000000 +00000000 0F000000 53657261 66696E61 +00000000 00000000 00040403 0100004A +004A0432 003A0030 00330036 00360039 +32000000 00000000 00000000 10000000 +4B726973 00000000 00000000 00000000 +00111103 01000049 00490323 003D0032 +003B003A 003C0042 37000000 00000000 +00000002 11000000 5A696567 6C657200 +00000000 00000000 00080803 00000054 +00540332 003D003B 00360038 0033003A +37000000 00000000 00000002 12000000 +4F6D6567 61000000 00000000 00000000 +004E4E03 02000071 00710332 004B005B +002C002D 002A0039 36000000 00000000 +00000000 13000000""" + +data = bytes.fromhex(pattern) + +while len(data) > 0: + name = data[:0x10].decode("utf-8") + (portrait,) = struct.unpack_from('>h', data[0x10:]) + (clazz,) = struct.unpack_from('>b', data[0x12:]) + (level,) = struct.unpack_from('>b', data[0x13:]) + (max_hp,) = struct.unpack_from('>h', data[0x16:]) + (cur_hp,) = struct.unpack_from('>h', data[0x18:]) + (strr,) = struct.unpack_from('>h', data[0x1C:]) + (vit,) = struct.unpack_from('>h', data[0x1E:]) + (intt,) = struct.unpack_from('>h', data[0x20:]) + (mem,) = struct.unpack_from('>h', data[0x22:]) + (agi,) = struct.unpack_from('>h', data[0x24:]) + (dex,) = struct.unpack_from('>h', data[0x26:]) + + print(f"name= {name}") + print(f"portrait= {portrait}") + print(f"class= {CLASS_NAME[clazz]} ({clazz})") + print(f"max_health= {max_hp}") + print(f"current_health= {cur_hp}") + print(f"level= {level}") + print(f"str= {strr}") + print(f"vit= {vit}") + print(f"int= {intt}") + print(f"mem= {agi}") + print(f"agi= {agi}") + print(f"dex= {dex}") + print(f"rest= {data[0x26:0x38].hex()}") + print(" ") + + data = data[0x38:] + diff --git a/tools/splat_ext/__pycache__/lha.cpython-310.pyc b/tools/splat_ext/__pycache__/lha.cpython-310.pyc new file mode 100644 index 0000000..fe9d98e Binary files /dev/null and b/tools/splat_ext/__pycache__/lha.cpython-310.pyc differ diff --git a/tools/splat_ext/lha.py b/tools/splat_ext/lha.py new file mode 100644 index 0000000..945c111 --- /dev/null +++ b/tools/splat_ext/lha.py @@ -0,0 +1,44 @@ +from pathlib import Path +from typing import Optional + +from segtypes.n64.segment import N64Segment +from segtypes.n64.rgba16 import N64SegRgba16 +from segtypes.n64.i4 import N64SegI4 + +from util import options, log + +import lhafile + +import sys +sys.path.append(str(options.opts.base_path / "tools")) + +class N64SegLha(N64Segment): + def __init__(self, rom_start, rom_end, type, name, vram_start, args, yaml): + super().__init__(rom_start, rom_end, type, name, vram_start, args=args, yaml=yaml), + + log.write(f"LHA decompression initialised with {self.name}") + + def out_path(self) -> Optional[Path]: + return options.opts.asset_path / self.dir / f"{self.name}" + + def split(self, rom_bytes): + data_bytes = rom_bytes[self.rom_start:self.rom_end] + + path = self.out_path() + path.parent.mkdir(parents=True, exist_ok=True) + + with path.open("wb") as f: + f.write(data_bytes) + f.close() + + # Create Lhafile instance from filename + archive = lhafile.Lhafile(str(path)) + + # Print each file informaion in archive file. + for info in archive.infolist(): + print(info.filename) + + log.write(f"LHA decompression got {len(data_bytes)}") + + log.write(data_bytes) + \ No newline at end of file diff --git a/tools/splat_ext/lib/lhafile/COPYING.txt b/tools/splat_ext/lib/lhafile/COPYING.txt new file mode 100644 index 0000000..274d585 --- /dev/null +++ b/tools/splat_ext/lib/lhafile/COPYING.txt @@ -0,0 +1,30 @@ +Copyright (c) 2010 Hidekazu Ohnishi. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + + * Neither the name of the author nor the names of its contributors + may be used to endorse or promote products derived from this + software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/tools/splat_ext/lib/lhafile/MANIFEST.in b/tools/splat_ext/lib/lhafile/MANIFEST.in new file mode 100644 index 0000000..a504d08 --- /dev/null +++ b/tools/splat_ext/lib/lhafile/MANIFEST.in @@ -0,0 +1,2 @@ +include COPYING.txt +include MANIFEST.in diff --git a/tools/splat_ext/lib/lhafile/PKG-INFO b/tools/splat_ext/lib/lhafile/PKG-INFO new file mode 100644 index 0000000..348fdf0 --- /dev/null +++ b/tools/splat_ext/lib/lhafile/PKG-INFO @@ -0,0 +1,19 @@ +Metadata-Version: 1.0 +Name: lhafile +Version: 0.1 +Summary: LHA(.lzh) file extract interface +Home-page: http://trac.neotitans.net/wiki/lhafile +Author: Hidekazu Ohnishi +Author-email: the-o@neotitans.net +License: BSD +Download-URL: http://trac.neotitans.net/wiki/lhafile +Description: Extract LHA(.lzh) file extension. + Its interface is likely zipfile extension is included in regular + python distribution. +Platform: UNKNOWN +Classifier: Development Status :: 4 - Beta +Classifier: Envrionment :: Other Environment +Classifier: Intended Audience :: Developers +Classifier: License :: OSI Approved :: BSD License +Classifier: Operating System :: OS IndependentProgramming Language :: Python +Classifier: Topic :: Software Development diff --git a/tools/splat_ext/lib/lhafile/README.txt b/tools/splat_ext/lib/lhafile/README.txt new file mode 100644 index 0000000..7ce8224 --- /dev/null +++ b/tools/splat_ext/lib/lhafile/README.txt @@ -0,0 +1,5 @@ +Readme for lhafile + +Lhafile is extension that extract lha file(.lzh). + +Its interface is likey zipfile module which is include regular python distribution. diff --git a/tools/splat_ext/lib/lhafile/build/lib.linux-x86_64-3.10/lhafile/__init__.py b/tools/splat_ext/lib/lhafile/build/lib.linux-x86_64-3.10/lhafile/__init__.py new file mode 100644 index 0000000..f5d90ff --- /dev/null +++ b/tools/splat_ext/lib/lhafile/build/lib.linux-x86_64-3.10/lhafile/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- +from lhafile import * diff --git a/tools/splat_ext/lib/lhafile/build/lib.linux-x86_64-3.10/lhafile/lhafile.py b/tools/splat_ext/lib/lhafile/build/lib.linux-x86_64-3.10/lhafile/lhafile.py new file mode 100644 index 0000000..a4124ff --- /dev/null +++ b/tools/splat_ext/lib/lhafile/build/lib.linux-x86_64-3.10/lhafile/lhafile.py @@ -0,0 +1,337 @@ +# -*- coding:utf-8 -*- +# Copyright (c) 2010 Hidekazu Ohnishi. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# +# * Neither the name of the author nor the names of its contributors +# may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +"""Lhafile, extension extract lzh file. + +Its interface is likey zipfile module is include in regular python environment. +""" + +import cStringIO +import datetime +import os +import os.path +import struct +import sys + +import lzhlib +crc16 = lzhlib.crc16 + +def is_lhafile(filename): + try: + Lhafile(filename) + except: + return False + return True + +class BadLhafile(Exception): + pass + +class LhaInfo(object): + __slots__ = ( + 'orig_filename', + 'filename', + 'directory', + 'date_time', + 'compress_type', + 'comment', + 'extra', + 'create_system', + 'create_version', + 'extract_version', + 'reserved', + 'flag_bits', + 'volume', + 'internal_attr', + 'external_attr', + 'header_offset', + 'file_offset', + 'CRC', + 'compress_size', + 'file_size', + ) + + def __init__(self): + self.orig_filename = None + self.filename = None + self.directory = None + self.date_time = None + self.compress_type = None + self.comment = None + self.extra = None + self.create_system = None + self.create_version = None + self.extract_version = None + self.reserved = None + self.flag_bits = None + self.volume = None + self.internal_attr = None + self.external_attr = None + self.header_offset = None + self.file_offset = None + self.CRC = None + self.compress_size = None + self.file_size = None + + def __str__(self): + return '%s %s %08X %d %04X' % (self.filename, self.file_size, + self.file_offset, self.compress_size, self.CRC) + + def __getstate__(self): + return (self.orig_filename, self.filename, self.directory, self.date_time, + self.compress_type, self.comment, self.extra, self.create_system, + self.create_version, self.extract_version, self.reserved, + self.flag_bits, self.volume, self.internal_attr, self.external_attr, + self.header_offset, self.file_offset, self.CRC, self.compress_size, + self.file_size) + + def __setstate__(self, state): + (self.orig_filename, self.filename, self.directory, self.date_time, + self.compress_type, self.comment, self.extra, self.create_system, + self.create_version, self.extract_version, self.reserved, + self.flag_bits, self.volume, self.internal_attr, self.external_attr, + self.header_offset, self.file_offset, self.CRC, self.compress_size, + self.file_size) = state + + +class Lhafile: + """ + """ + + SUPPORTED_COMPRESS_TYPE = ('-lhd-', '-lh0-', '-lh5-', '-lh6-', '-lh7-'); + + def __init__(self, file, mode="r", compression=None, callback=None, args=None): + """ Open the LZH file """ + self.filelist = [] + self.NameToInfo = {} + self.mode = key = mode.replace('b', '')[0] + + if isinstance(file, basestring): + self._fileParsed = 0 + self.filename = file + modeDict = {'r' : 'rb'} + self.fp = open(file, modeDict[mode]) + else: + self._fileParsed = 1 + self.fp = file + self.filename = getattr(file, 'name', None) + + # Get file size + initial_pos = self.fp.tell() + self.fp.seek(0, 2) + self.filesize = self.fp.tell() + self.fp.seek(initial_pos, 0) + + if key == 'r': + self._GetContents(callback=callback,args=args) + else: + if not self._fileParsed: + self.fp.close() + self.fp = None + raise RuntimeError, 'Mode must be "r"' + + def _GetContents(self, callback=None, args=None): + try: + info = self._RealGetContent() + while info: + if not info.compress_type in Lhafile.SUPPORTED_COMPRESS_TYPE: + raise RuntimeError, "Unsupported file is contained %s" % (info.compress_type,) + if callback: + callback(args, self.fp.tell(), self.filesize, info) + self.filelist.append(info) + self.NameToInfo[info.filename] = info + info = self._RealGetContent() + except BadLhafile, e: + raise + if not self._fileParsed: + self.fp.close() + self.fp = None + + def _RealGetContent(self): + fp = self.fp + filesize = self.filesize + initial_pos = fp.tell() + is_read = lambda x: fp.tell() + (x) < filesize + if fp.tell() == filesize - 1: + return None + if not is_read(26): + raise BadLhafile, "Header is broken" + # Check OS level + os_level = ord(fp.read(21)[20]) + fp.seek(-21, 1) + if not os_level in (0, 1, 2): + raise BadLhafile, "this file level is out of support range %d" % os_level + if os_level in (0, 1): + header_size, checksum, signature, skip_size, \ + file_size, modify_time, reserved , os_level, \ + filename_length = struct.unpack('> 1) + 1980 + month = ((ord(modify_time[3]) << 8 | ord(modify_time[2])) >> 5) & 0x0F + day = ord(modify_time[2]) & 0x1F + hour = ord(modify_time[1]) >> 3 + minute = ((ord(modify_time[1]) << 8 | ord(modify_time[0])) >> 5) & 0x2F + second = (ord(modify_time[0]) & 0x1F) * 2 + date_time = datetime.datetime(year, month, day, hour, minute, second) + create_time = date_time + elif os_level in (2,): + dummy_date = datetime.datetime(1970,1,1) + date_time = dummy_date.fromtimestamp(modify_time) + create_time = date_time + info = LhaInfo() + if directory is None: + # for lhaplus archive + sjisname = unicode(filename, 'cp932') + if '\\' in sjisname: + sjispath = [s.encode('cp932') for s in sjisname.split(u'\\')] + filename = os.sep.join(sjispath) + directory = os.sep.join(sjispath[:-1]) + else: + directory = os.sep.join(directory.split('\xff')) + filename = os.path.join(directory, filename) + info.directory = directory + info.filename = filename + info.compress_size = compress_size + info.file_size = file_size + info.CRC = crc + info.header_offset = initial_pos + info.file_offset = file_offset + info.external_attr = None + info.internal_attr = None + info.reserved = 0 + info.comment = comment + info.compress_type = signature + info.date_time = date_time + return info + + def lhaname(self): + return self.filename + + def namelist(self): + if self.filelist: + return [d.filename for d in self.filelist \ + if d.compress_type in Lhafile.SUPPORTED_COMPRESS_TYPE] + return None + + def infolist(self): + return self.filelist + + def read(self, name): + """Return file bytes (as a string) for 'name'. """ + if not self.fp: + raise RuntimeError, \ + "Attempt to read LZH archive that was already closed" + info = self.NameToInfo[name] + if info.compress_type in Lhafile.SUPPORTED_COMPRESS_TYPE: + self.fp.seek(info.file_offset) + fin = cStringIO.StringIO(self.fp.read(info.compress_size)) + fout = cStringIO.StringIO() + try: + session = lzhlib.LZHDecodeSession(fin, fout, info) + while session.do_next() == False: + pass + outsize = session.output_pos + crc = session.crc16 + except Exception, e: + raise e + if outsize != info.file_size: + raise BadLhafile, "%s output_size is not matched %d/%d %s" % \ + (name, outsize, info.file_size, info.compress_type) + if crc != info.CRC: + raise BadLhafile, "crc is not matched" + + fout.seek(0) + bytes = fout.read() + elif info.commpress_type == '-lhd-': + raise RuntimeError, \ + "name is directory" + else: + raise RuntimeError, \ + "Unsupport format" + return bytes + diff --git a/tools/splat_ext/lib/lhafile/lhafile/__init__.py b/tools/splat_ext/lib/lhafile/lhafile/__init__.py new file mode 100644 index 0000000..f5d90ff --- /dev/null +++ b/tools/splat_ext/lib/lhafile/lhafile/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- +from lhafile import * diff --git a/tools/splat_ext/lib/lhafile/lhafile/lhafile.py b/tools/splat_ext/lib/lhafile/lhafile/lhafile.py new file mode 100644 index 0000000..a4124ff --- /dev/null +++ b/tools/splat_ext/lib/lhafile/lhafile/lhafile.py @@ -0,0 +1,337 @@ +# -*- coding:utf-8 -*- +# Copyright (c) 2010 Hidekazu Ohnishi. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# +# * Neither the name of the author nor the names of its contributors +# may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +"""Lhafile, extension extract lzh file. + +Its interface is likey zipfile module is include in regular python environment. +""" + +import cStringIO +import datetime +import os +import os.path +import struct +import sys + +import lzhlib +crc16 = lzhlib.crc16 + +def is_lhafile(filename): + try: + Lhafile(filename) + except: + return False + return True + +class BadLhafile(Exception): + pass + +class LhaInfo(object): + __slots__ = ( + 'orig_filename', + 'filename', + 'directory', + 'date_time', + 'compress_type', + 'comment', + 'extra', + 'create_system', + 'create_version', + 'extract_version', + 'reserved', + 'flag_bits', + 'volume', + 'internal_attr', + 'external_attr', + 'header_offset', + 'file_offset', + 'CRC', + 'compress_size', + 'file_size', + ) + + def __init__(self): + self.orig_filename = None + self.filename = None + self.directory = None + self.date_time = None + self.compress_type = None + self.comment = None + self.extra = None + self.create_system = None + self.create_version = None + self.extract_version = None + self.reserved = None + self.flag_bits = None + self.volume = None + self.internal_attr = None + self.external_attr = None + self.header_offset = None + self.file_offset = None + self.CRC = None + self.compress_size = None + self.file_size = None + + def __str__(self): + return '%s %s %08X %d %04X' % (self.filename, self.file_size, + self.file_offset, self.compress_size, self.CRC) + + def __getstate__(self): + return (self.orig_filename, self.filename, self.directory, self.date_time, + self.compress_type, self.comment, self.extra, self.create_system, + self.create_version, self.extract_version, self.reserved, + self.flag_bits, self.volume, self.internal_attr, self.external_attr, + self.header_offset, self.file_offset, self.CRC, self.compress_size, + self.file_size) + + def __setstate__(self, state): + (self.orig_filename, self.filename, self.directory, self.date_time, + self.compress_type, self.comment, self.extra, self.create_system, + self.create_version, self.extract_version, self.reserved, + self.flag_bits, self.volume, self.internal_attr, self.external_attr, + self.header_offset, self.file_offset, self.CRC, self.compress_size, + self.file_size) = state + + +class Lhafile: + """ + """ + + SUPPORTED_COMPRESS_TYPE = ('-lhd-', '-lh0-', '-lh5-', '-lh6-', '-lh7-'); + + def __init__(self, file, mode="r", compression=None, callback=None, args=None): + """ Open the LZH file """ + self.filelist = [] + self.NameToInfo = {} + self.mode = key = mode.replace('b', '')[0] + + if isinstance(file, basestring): + self._fileParsed = 0 + self.filename = file + modeDict = {'r' : 'rb'} + self.fp = open(file, modeDict[mode]) + else: + self._fileParsed = 1 + self.fp = file + self.filename = getattr(file, 'name', None) + + # Get file size + initial_pos = self.fp.tell() + self.fp.seek(0, 2) + self.filesize = self.fp.tell() + self.fp.seek(initial_pos, 0) + + if key == 'r': + self._GetContents(callback=callback,args=args) + else: + if not self._fileParsed: + self.fp.close() + self.fp = None + raise RuntimeError, 'Mode must be "r"' + + def _GetContents(self, callback=None, args=None): + try: + info = self._RealGetContent() + while info: + if not info.compress_type in Lhafile.SUPPORTED_COMPRESS_TYPE: + raise RuntimeError, "Unsupported file is contained %s" % (info.compress_type,) + if callback: + callback(args, self.fp.tell(), self.filesize, info) + self.filelist.append(info) + self.NameToInfo[info.filename] = info + info = self._RealGetContent() + except BadLhafile, e: + raise + if not self._fileParsed: + self.fp.close() + self.fp = None + + def _RealGetContent(self): + fp = self.fp + filesize = self.filesize + initial_pos = fp.tell() + is_read = lambda x: fp.tell() + (x) < filesize + if fp.tell() == filesize - 1: + return None + if not is_read(26): + raise BadLhafile, "Header is broken" + # Check OS level + os_level = ord(fp.read(21)[20]) + fp.seek(-21, 1) + if not os_level in (0, 1, 2): + raise BadLhafile, "this file level is out of support range %d" % os_level + if os_level in (0, 1): + header_size, checksum, signature, skip_size, \ + file_size, modify_time, reserved , os_level, \ + filename_length = struct.unpack('> 1) + 1980 + month = ((ord(modify_time[3]) << 8 | ord(modify_time[2])) >> 5) & 0x0F + day = ord(modify_time[2]) & 0x1F + hour = ord(modify_time[1]) >> 3 + minute = ((ord(modify_time[1]) << 8 | ord(modify_time[0])) >> 5) & 0x2F + second = (ord(modify_time[0]) & 0x1F) * 2 + date_time = datetime.datetime(year, month, day, hour, minute, second) + create_time = date_time + elif os_level in (2,): + dummy_date = datetime.datetime(1970,1,1) + date_time = dummy_date.fromtimestamp(modify_time) + create_time = date_time + info = LhaInfo() + if directory is None: + # for lhaplus archive + sjisname = unicode(filename, 'cp932') + if '\\' in sjisname: + sjispath = [s.encode('cp932') for s in sjisname.split(u'\\')] + filename = os.sep.join(sjispath) + directory = os.sep.join(sjispath[:-1]) + else: + directory = os.sep.join(directory.split('\xff')) + filename = os.path.join(directory, filename) + info.directory = directory + info.filename = filename + info.compress_size = compress_size + info.file_size = file_size + info.CRC = crc + info.header_offset = initial_pos + info.file_offset = file_offset + info.external_attr = None + info.internal_attr = None + info.reserved = 0 + info.comment = comment + info.compress_type = signature + info.date_time = date_time + return info + + def lhaname(self): + return self.filename + + def namelist(self): + if self.filelist: + return [d.filename for d in self.filelist \ + if d.compress_type in Lhafile.SUPPORTED_COMPRESS_TYPE] + return None + + def infolist(self): + return self.filelist + + def read(self, name): + """Return file bytes (as a string) for 'name'. """ + if not self.fp: + raise RuntimeError, \ + "Attempt to read LZH archive that was already closed" + info = self.NameToInfo[name] + if info.compress_type in Lhafile.SUPPORTED_COMPRESS_TYPE: + self.fp.seek(info.file_offset) + fin = cStringIO.StringIO(self.fp.read(info.compress_size)) + fout = cStringIO.StringIO() + try: + session = lzhlib.LZHDecodeSession(fin, fout, info) + while session.do_next() == False: + pass + outsize = session.output_pos + crc = session.crc16 + except Exception, e: + raise e + if outsize != info.file_size: + raise BadLhafile, "%s output_size is not matched %d/%d %s" % \ + (name, outsize, info.file_size, info.compress_type) + if crc != info.CRC: + raise BadLhafile, "crc is not matched" + + fout.seek(0) + bytes = fout.read() + elif info.commpress_type == '-lhd-': + raise RuntimeError, \ + "name is directory" + else: + raise RuntimeError, \ + "Unsupport format" + return bytes + diff --git a/tools/splat_ext/lib/lhafile/lhafile/lzhlib.c b/tools/splat_ext/lib/lhafile/lhafile/lzhlib.c new file mode 100644 index 0000000..c0530ff --- /dev/null +++ b/tools/splat_ext/lib/lhafile/lhafile/lzhlib.c @@ -0,0 +1,1411 @@ +/* +lzhlib - lzh library modules for lhafile + +Copyright (c) 2010 Hidekazu Ohnishi. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + + * Neither the name of the author nor the names of its contributors + may be used to endorse or promote products derived from this + software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include "Python.h" +#include "structmember.h" + +static char __author__[] = +"The lzhlib python module was written by:\n\ +\n\ + Hidekazu Ohnishi\n\ +"; + +#ifdef MS_WINDOWS +#define inline __inline +#endif + +typedef long long Py_off_t; + +#define FILE_BUFFER_SIZE (64*1024) + +/* ===================================================================== */ +/* Constant definitions. */ + +typedef enum { + COMPRESS_TYPE_LH0 = 1, + COMPRESS_TYPE_LH5, + COMPRESS_TYPE_LH6, + COMPRESS_TYPE_LH7, +} lzhlib_compress_type; + +typedef enum { + ERR_UNEXPECT_EOF = 1, + ERR_OUT_OF_RANGE, + ERR_VALUE_ERROR, + ERR_OUT_OF_MEMORY, + ERR_IO_ERROR, + ERR_BIT_LENGTH_TABLE_ERROR, + ERR_BIT_PATTERN_TABLE_ERROR, + ERR_BIT_LENGTH_SIZE_ERROR, + ERR_DATA_ERROR, + ERR_BUFFER_OVER_FLOW, +} lzhlib_error; + +const char *lzhlib_error_msg[] = { + "Unexpehct EOF. It is seemed this file is broken", + "It is seemd the compressed data is too short", + "Input argument error", + "Out of mwmoey", + "I/O error is happend", + "Lzh file is seemed broken", + "Lzh file is seemed broken", + "Lzh file is seemed broken", + "Can't write file", + "Buffer overflow will happened", +}; + +typedef enum { + BIT_STREAM_ERR_OVERFLOW = 0x01, + BIT_STREAM_ERR_IOERROR = 0x02, +} bit_stream_err_type; + + +/* ===================================================================== */ +/* Structure definitions. */ + +typedef struct { + PyObject *fp; + PyObject *read_buf; + unsigned char *buf, *end; + unsigned int cache; + int bit; + int remain_bit; + Py_off_t pos; + int eof; +} bit_stream_reader; + +typedef struct { + PyObject *fp; + PyObject *write_buf; + unsigned char *start,*buf,*end; + Py_off_t pos; + int crc16; + bit_stream_err_type error; +} bit_stream_writer; + +typedef struct { + int len; + unsigned char *s; +} string; + +typedef struct{ + string *table; + int bitMax; +} bit_length_table; + +typedef struct{ + int table[510]; + int len; + int _freqTable[17]; + int _weight[17]; + int _startPattern[17]; +} bit_pattern_table; + +typedef struct{ + int bitMax; + int bitlength; + unsigned short blen_code[65536]; + bit_length_table _blt; + bit_pattern_table _bpt; +} huffman_decoder; + + + +/* ===================================================================== */ +/* crc16 */ + +const static int _crc16Table[256] = +{ + 0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241, + 0xC601, 0x06C0, 0x0780, 0xC741, 0x0500, 0xC5C1, 0xC481, 0x0440, + 0xCC01, 0x0CC0, 0x0D80, 0xCD41, 0x0F00, 0xCFC1, 0xCE81, 0x0E40, + 0x0A00, 0xCAC1, 0xCB81, 0x0B40, 0xC901, 0x09C0, 0x0880, 0xC841, + 0xD801, 0x18C0, 0x1980, 0xD941, 0x1B00, 0xDBC1, 0xDA81, 0x1A40, + 0x1E00, 0xDEC1, 0xDF81, 0x1F40, 0xDD01, 0x1DC0, 0x1C80, 0xDC41, + 0x1400, 0xD4C1, 0xD581, 0x1540, 0xD701, 0x17C0, 0x1680, 0xD641, + 0xD201, 0x12C0, 0x1380, 0xD341, 0x1100, 0xD1C1, 0xD081, 0x1040, + 0xF001, 0x30C0, 0x3180, 0xF141, 0x3300, 0xF3C1, 0xF281, 0x3240, + 0x3600, 0xF6C1, 0xF781, 0x3740, 0xF501, 0x35C0, 0x3480, 0xF441, + 0x3C00, 0xFCC1, 0xFD81, 0x3D40, 0xFF01, 0x3FC0, 0x3E80, 0xFE41, + 0xFA01, 0x3AC0, 0x3B80, 0xFB41, 0x3900, 0xF9C1, 0xF881, 0x3840, + 0x2800, 0xE8C1, 0xE981, 0x2940, 0xEB01, 0x2BC0, 0x2A80, 0xEA41, + 0xEE01, 0x2EC0, 0x2F80, 0xEF41, 0x2D00, 0xEDC1, 0xEC81, 0x2C40, + 0xE401, 0x24C0, 0x2580, 0xE541, 0x2700, 0xE7C1, 0xE681, 0x2640, + 0x2200, 0xE2C1, 0xE381, 0x2340, 0xE101, 0x21C0, 0x2080, 0xE041, + 0xA001, 0x60C0, 0x6180, 0xA141, 0x6300, 0xA3C1, 0xA281, 0x6240, + 0x6600, 0xA6C1, 0xA781, 0x6740, 0xA501, 0x65C0, 0x6480, 0xA441, + 0x6C00, 0xACC1, 0xAD81, 0x6D40, 0xAF01, 0x6FC0, 0x6E80, 0xAE41, + 0xAA01, 0x6AC0, 0x6B80, 0xAB41, 0x6900, 0xA9C1, 0xA881, 0x6840, + 0x7800, 0xB8C1, 0xB981, 0x7940, 0xBB01, 0x7BC0, 0x7A80, 0xBA41, + 0xBE01, 0x7EC0, 0x7F80, 0xBF41, 0x7D00, 0xBDC1, 0xBC81, 0x7C40, + 0xB401, 0x74C0, 0x7580, 0xB541, 0x7700, 0xB7C1, 0xB681, 0x7640, + 0x7200, 0xB2C1, 0xB381, 0x7340, 0xB101, 0x71C0, 0x7080, 0xB041, + 0x5000, 0x90C1, 0x9181, 0x5140, 0x9301, 0x53C0, 0x5280, 0x9241, + 0x9601, 0x56C0, 0x5780, 0x9741, 0x5500, 0x95C1, 0x9481, 0x5440, + 0x9C01, 0x5CC0, 0x5D80, 0x9D41, 0x5F00, 0x9FC1, 0x9E81, 0x5E40, + 0x5A00, 0x9AC1, 0x9B81, 0x5B40, 0x9901, 0x59C0, 0x5880, 0x9841, + 0x8801, 0x48C0, 0x4980, 0x8941, 0x4B00, 0x8BC1, 0x8A81, 0x4A40, + 0x4E00, 0x8EC1, 0x8F81, 0x4F40, 0x8D01, 0x4DC0, 0x4C80, 0x8C41, + 0x4400, 0x84C1, 0x8581, 0x4540, 0x8701, 0x47C0, 0x4680, 0x8641, + 0x8201, 0x42C0, 0x4380, 0x8341, 0x4100, 0x81C1, 0x8081, 0x4040, +}; + +static inline int +crc16(unsigned char *data, int len, int crc){ + for(; len > 0 ; data++, len--){ + crc = (crc >> 8) ^ _crc16Table[(crc ^ *data) & 0xFF]; + } + + return crc; +} + +/* ===================================================================== */ +/* lzh decode */ + +/* STRING OPERATIONS */ + +static inline void +string_init(string *self, unsigned char*s, int len) +{ + self->s = s; + self->len = len; +} + +static inline int +string_len(string *self){ + return self->len; +} + +static inline unsigned char * +string_str(string *self){ + return self->s; +} + +static inline int +string_get(string *self, int i){ + return (int)(self->s[i]); +} + +static inline void +string_set(string *self, int i, int c){ + self->s[i] = (unsigned char)c; +} + +static inline void +string_clear(string *self){ + int i; + for(i = 0; i < self->len; i++){ + self->s[i] = 0; + } +} + +static inline string* +new_string(int len){ + string *s; + unsigned char *str; + + str = PyMem_Malloc(len * sizeof(unsigned char)); + if(str == NULL){ + return NULL; + } + + s = PyMem_Malloc(sizeof(string)); + if(s == NULL){ + PyMem_Free(str); + return NULL; + } + + string_init(s, str, len); + + return s; +} + +static inline void +del_string(string *s){ + if(s != NULL){ + if(s->s != NULL){ + PyMem_Free(s->s); + } + PyMem_Free(s); + } +} + + +/* BITSTREAM OPERATIONS */ + +static inline int +bit_stream_reader_init_fileio(bit_stream_reader *self, PyObject *file) +{ + int error_no = 0; + int i; + unsigned char *buf, *end; + unsigned int cache; + PyObject *read_obj = NULL; + + /* Argument check */ + if(!file){ error_no = ERR_VALUE_ERROR; goto error;} + + /* Read ahead data */ + read_obj = PyObject_CallMethod(file, "read", "(i)", FILE_BUFFER_SIZE); + if(!read_obj){ error_no = ERR_VALUE_ERROR; goto error;} + + self->fp = file; + self->read_buf = read_obj; + self->bit = 0; + self->pos = 0; + + buf = (unsigned char*)PyString_AsString(read_obj); + end = buf + PyString_Size(read_obj); + + /* Fill Cache */ + cache = 0; + self->remain_bit = 0; + for(i=0; i < sizeof(unsigned int) && buf != end; i++){ + cache = (cache << 8) | *buf++; + self->remain_bit += 8; + } + + self->buf = buf; + self->end = end; + self->cache = cache; + if(buf == end){ + self->eof = 1; + self->cache <<= (8 * sizeof(unsigned int) - self->remain_bit); + }else{ + self->remain_bit = 0; + self->eof = 0; + } + + return 0; + +error: + Py_XDECREF(read_obj); + + return error_no; +} + + +static inline void +bit_stream_reader_close(bit_stream_reader *self) +{ + Py_XDECREF(self->read_buf); + self->read_buf = NULL; +} + +static inline Py_off_t +bit_stream_reader_pos(bit_stream_reader *self) +{ + return self->pos; +} + +static inline int +bit_stream_reader_pre_fetch(bit_stream_reader *self, int n) +{ + return (int)(self->cache >> (8 * sizeof(int) - n)); +} + +static inline int +bit_stream_reader_fetch(bit_stream_reader *self, int n) +{ + int ret; + + if(n > 16 || n <= 0){ + if(n == 0){ + return 0; + } + return -2; + } + + ret = (int)(self->cache >> (8 * sizeof(int) - n)); + self->cache <<= n; + self->bit += n; + + if(self->eof){ + if(self->bit > self->remain_bit){ + return -1; + } + }else if(sizeof(unsigned int) * 8 - self->bit <= 16){ + self->cache >>= self->bit; + + /* if remain data cahce size is under 16 then read ahead */ + while(sizeof(unsigned int) * 8 - self->bit <= 16){ + if(self->buf == self->end){ + PyGILState_STATE state; + PyObject *read_obj = NULL; + + state = PyGILState_Ensure(); + + /* free old buffer */ + Py_DECREF(self->read_buf); + self->read_buf = NULL; + + /* read ahead data*/ + read_obj = PyObject_CallMethod(self->fp, "read", "(i)", FILE_BUFFER_SIZE); + if(!read_obj){ + ret = ERR_VALUE_ERROR; + goto error; + } + + self->buf = (unsigned char*)PyString_AsString(read_obj); + self->end = self->buf + PyString_Size(read_obj); + + if(self->buf != self->end){ + self->read_buf = read_obj; + }else{ + /* this condition means eof */ + self->eof = 1; + self->remain_bit = sizeof(unsigned int) * 8; + Py_DECREF(read_obj); + PyGILState_Release(state); + break; + } + + PyGILState_Release(state); + + } + self->cache <<= 8; + self->cache |= *self->buf++; + self->bit -= 8; + self->pos += 1; + } + + self->cache <<= self->bit; + } + +error: + return ret; +} + + +static inline bit_stream_reader * +new_bit_stream_reader(void) +{ + return PyMem_Malloc(sizeof(bit_stream_reader)); +} + + +/* */ + +static inline int +bit_stream_writer_init_fileio(bit_stream_writer *self, PyObject *file) +{ + int error_no = 0; + + PyObject *write_obj = NULL; + unsigned char *buf, *end; + + /* Argument check */ + if(!file){ error_no = ERR_VALUE_ERROR; goto error;} + + /* Allocate write buffer */ + write_obj = PyString_FromStringAndSize(NULL, 65556); + if(!write_obj){ error_no = ERR_OUT_OF_MEMORY; goto error;} + + self->fp = file; + self->write_buf = write_obj; + self->crc16 = 0; + self->pos = 0; + + buf = (unsigned char*)PyString_AsString(write_obj); + end = buf + PyString_Size(write_obj); + + self->start = buf; + self->buf = buf; + self->end = end; + + self->error = 0; + + return 0; + +error: + Py_XDECREF(write_obj); + + return error_no; +} + +static inline int +bit_stream_writer_flush(bit_stream_writer *self) +{ + int error_no = 0; + PyObject *ret = NULL, *write_obj = NULL; + int s; + + if(self->write_buf){ + s = (int)(self->buf - self->start); + + if(s > 0){ + self->crc16 = crc16(self->start, s, self->crc16); + write_obj = PyString_FromStringAndSize(PyString_AsString(self->write_buf), s); + if(!write_obj){ error_no = ERR_OUT_OF_MEMORY; goto error; } + + ret = PyObject_CallMethod(self->fp, "write", "(O)", write_obj); + + Py_DECREF(write_obj); + Py_DECREF(ret); + + ret = PyErr_Occurred(); + if(ret){ + PyErr_Clear(); + error_no = ERR_IO_ERROR; + goto error; + } + } + + self->buf = self->start; + } + +error: + + return error_no; +} + +static inline int +bit_stream_writer_close(bit_stream_writer *self) +{ + int error_no = 0; + + error_no = bit_stream_writer_flush(self); + + Py_XDECREF(self->write_buf); + self->write_buf = NULL; + + return error_no; +} + + +static inline int +bit_stream_writer_overflow(bit_stream_writer *self) +{ + return ((self->error & BIT_STREAM_ERR_OVERFLOW) != 0); +} + +static inline int +bit_stream_writer_ioerror(bit_stream_writer *self) +{ + return ((self->error & BIT_STREAM_ERR_IOERROR) != 0); +} + +static inline Py_off_t +bit_stream_writer_pos(bit_stream_writer *self) +{ + return self->pos; +} + +static inline int +bit_stream_writer_crc(bit_stream_writer *self) +{ + return self->crc16; +} + +static inline void +bit_stream_writer_write(bit_stream_writer *self, int c) +{ + self->pos++; + *self->buf++ = (unsigned char)c; + + if(self->buf == self->end){ + int s; + + s = (int)(self->buf - self->start); + self->crc16 = crc16(self->start, s, self->crc16); + + { + PyObject *ret; + PyGILState_STATE state; + + state = PyGILState_Ensure(); + + ret = PyObject_CallMethod(self->fp, "write", "(O)", self->write_buf); + Py_DECREF(ret); + + ret = PyErr_Occurred(); + if(ret){ + self->error |= BIT_STREAM_ERR_OVERFLOW; + PyErr_Clear(); + } + + PyGILState_Release(state); + } + + self->buf = self->start; + } +} + + +/* BIT LENGTH TABLE OPERATIONS */ + +static inline int +bit_length_table_init(bit_length_table *self, string *s) +{ + int error_no = 0; + int bitMax = 0; + int blen, i; + + for(i = 0; i < string_len(s); i++){ + blen = string_get(s, i); + if(bitMax < blen){ + bitMax = blen; + } + } + + if( bitMax == 0 || bitMax > 16 || string_len(s) == 0){ + error_no = ERR_BIT_LENGTH_TABLE_ERROR; + goto error; + } + + self->table = s; + self->bitMax = bitMax; + +error: + return error_no; +} + +static inline string* +bit_length_table_table(bit_length_table *self){ + return self->table; +} + +static inline int +bit_length_table_bitMax(bit_length_table *self){ + return self->bitMax; +} + +static inline int +bit_length_table_table_num(bit_length_table *self, int i){ + return string_get(self->table, i); +} + + +/* BIT PATTERN TABLE OPERATIONS */ + +static inline int +bit_pattern_table_init(bit_pattern_table *self, bit_length_table *blt) +{ + int error_no = 0; + int i, ptn, w, bl; + int bitMax, tableMax; + + int *table = self->table; + int *freqTable = self->_freqTable; + int *weight = self->_weight; + int *startPattern = self->_startPattern; + + bitMax = bit_length_table_bitMax(blt); + tableMax = string_len(bit_length_table_table(blt)); + + memset(freqTable, 0, sizeof(int) * (bitMax + 1)); + memset(weight, 0, sizeof(int) * (bitMax + 1)); + memset(startPattern, 0, sizeof(int) * (bitMax + 1)); + + for(i = 0; i < string_len(bit_length_table_table(blt)); i++){ + bl = bit_length_table_table_num(blt, i); + if(bl == 0){ + continue; + } + freqTable[bl] += 1; + } + + ptn = 0; + w = 1 << (bitMax - 1); + for(i = 1; i <= bitMax ; i++){ + startPattern[i] = ptn; + weight[i] = w; + + ptn += (w * freqTable[i]); + w >>= 1; + } + + if(ptn > (1 << bitMax)){ + error_no = ERR_BIT_PATTERN_TABLE_ERROR; + goto error; + } + + /* Make bit pattern table */ + for(i = 0 ; i < tableMax ; i++){ + bl = bit_length_table_table_num(blt, i); + if(bl == 0){ + table[i] = 0; + continue; + } + + ptn = startPattern[bl]; + table[i] = ptn >> (bitMax - bl); + startPattern[bl] += weight[bl]; + } + + self->len = tableMax; + +error: + return error_no; +} + +static inline int +bit_pattern_table_table_num(bit_pattern_table *self, int i){ + return self->table[i]; +} + + +/* HUFFMAN DECODER OPERATIONS */ + +static int +huffman_decoder_init(huffman_decoder *self, string *s) +{ + int error_no = 0; + int i; + int bitMax; + int ptn, blen; + unsigned short *blen_code = self->blen_code; + + bit_length_table *blt = &self->_blt; + bit_pattern_table *bpt = &self->_bpt; + + error_no = bit_length_table_init(blt, s); + if(error_no != 0){ + goto error; + } + + error_no = bit_pattern_table_init(bpt, blt); + if(error_no != 0){ + goto error; + } + + bitMax = bit_length_table_bitMax(blt); + + memset(blen_code, 0, (sizeof(unsigned short) * (1 << (int)bitMax))); + + for(i = 0; i < string_len(bit_length_table_table(blt)); i++){ + blen = bit_length_table_table_num(blt, i); + if(blen == 0){ + continue; + } + + ptn = bit_pattern_table_table_num(bpt, i) << (bitMax - blen); + + blen_code[ptn] = (blen << 11) | i; + + } + + if(bitMax == 1){ + if(blen_code[1] == 0){ + blen_code[0] &= 0x1FF; + } + } + + blen = *blen_code++; + for(i = 1; i < (1 << bitMax) ; i++, blen_code++){ + if(*blen_code == 0){ + *blen_code = blen; + }else{ + blen = *blen_code; + } + } + + self->bitMax = bitMax; + +error: + return error_no; +} + +static inline int +huffman_decoder_decode(huffman_decoder *self, bit_stream_reader *bs) +{ + int bits, blen, code; + + bits = bit_stream_reader_pre_fetch(bs, self->bitMax); + blen = self->blen_code[bits] >> 11; + code = self->blen_code[bits] & 0x1FF; + bit_stream_reader_fetch(bs, blen); + + return code; +} + +static inline huffman_decoder * +new_huffman_decoder(void){ + return (huffman_decoder *)PyMem_Malloc(sizeof(huffman_decoder)); +} + +static inline void +del_huffman_decoder(huffman_decoder *d){ + if(d != NULL){ + PyMem_Free(d); + } +} + +/* LZH DECODE OPERATIONS */ + +#define EOF_CHECK(c) \ + if(c < 0){ \ + if(c == -1){ \ + error_no = ERR_UNEXPECT_EOF; \ + goto error; \ + }else if(c == -2){ \ + error_no = ERR_OUT_OF_RANGE; \ + goto error; \ + } \ + } + + +static inline int +decodeUnary7(bit_stream_reader *bs, int *unary_code) +{ + int error_no = 0; + int c, code; + + code = bit_stream_reader_fetch(bs, 3); + EOF_CHECK(code); + + if(code == 7){ + while((c = bit_stream_reader_fetch(bs, 1)) == 1){ + code += 1; + } + EOF_CHECK(c); + } + + *unary_code = code; + +error: + return error_no; +} + + +static inline int +decodeBitLengthDecoder(bit_stream_reader *bs, string *blenlen19) +{ + int error_no = 0; + int i, c; + int blenSize, blenLeafCode, nmax; + + + blenSize = bit_stream_reader_fetch(bs, 5); + EOF_CHECK(blenSize); + if(blenSize > 19){ + error_no = ERR_BIT_LENGTH_SIZE_ERROR; + goto error; + } + + if(blenSize == 0){ + blenLeafCode = bit_stream_reader_fetch(bs, 5); + EOF_CHECK(blenLeafCode); + if(blenLeafCode >= 19){ + error_no = ERR_BIT_LENGTH_SIZE_ERROR; + goto error; + } + string_clear(blenlen19); + string_set(blenlen19, blenLeafCode, 1); + }else{ + i = 0; + + while(i < blenSize){ + error_no = decodeUnary7(bs, &c); + + if(error_no != 0){ + goto error; + } + + string_set(blenlen19, i, c); + i += 1; + + if(i == 3){ + nmax = bit_stream_reader_fetch(bs, 2); + EOF_CHECK(nmax); + + while(nmax > 0){ + string_set(blenlen19, i, 0); + i += 1; + nmax -= 1; + } + } + } + + while(i < 19){ + string_set(blenlen19, i, 0); + i += 1; + } + } + +error: + return error_no; + +} + +static int +decodeBitLengthLiteral(bit_stream_reader *bs, string *blenlen510, huffman_decoder *bitlen_decoder) +{ + int error_no = 0; + int i, n, code, c, leafCode; + + n = bit_stream_reader_fetch(bs, 9); + EOF_CHECK(n); + + if(n == 0){ + leafCode = bit_stream_reader_fetch(bs, 9); + EOF_CHECK(leafCode); + + string_clear(blenlen510); + string_set(blenlen510, leafCode, 1); + }else{ + i = 0; + + while(i < n){ + code = huffman_decoder_decode(bitlen_decoder, bs); + + if(code > 2){ + string_set(blenlen510, i, code - 2); + i += 1; + continue; + }else if(code == 0){ + string_set(blenlen510, i, 0); + i += 1; + continue; + }else if(code == 1){ + c = bit_stream_reader_fetch(bs, 4); + EOF_CHECK(c); + c += 3; + }else if(code == 2){ + c = bit_stream_reader_fetch(bs, 9); + EOF_CHECK(c); + c += 20; + }else{ + error_no = ERR_DATA_ERROR; + goto error; + } + + while(c > 0){ + c -= 1; + string_set(blenlen510, i, 0); + i += 1; + } + } + + while(i < 510){ + string_set(blenlen510, i, 0); + i += 1; + } + } + +error: + return error_no; +} + +static inline int +decodeBitLengthDistance(bit_stream_reader *bs, string *blenlen_distance, int dispos_bit, int dis_bit) +{ + int error_no = 0; + int i, unary; + int leafCode, tableSize; + + tableSize = bit_stream_reader_fetch(bs, dis_bit); + EOF_CHECK(tableSize); + + if(tableSize == 0){ + leafCode = bit_stream_reader_fetch(bs, dis_bit); + EOF_CHECK(leafCode); + + string_clear(blenlen_distance); + string_set(blenlen_distance, leafCode, 1); + }else{ + i = 0; + + while(i < tableSize){ + error_no = decodeUnary7(bs, &unary); + if(error_no != 0){ + goto error; + } + string_set(blenlen_distance, i, unary); + + i += 1; + } + + while(i <= dispos_bit){ + string_set(blenlen_distance, i, 0); + i += 1; + } + } + +error: + return error_no; +} + + +/* + * + */ + +typedef struct { + PyObject_HEAD + /* */ + PyObject *fin; + PyObject *fout; + lzhlib_compress_type compress_type; + Py_off_t info_compress_size; + Py_off_t info_file_size; + int info_crc; + + + bit_stream_reader *in; + bit_stream_writer *out; + + huffman_decoder *bitlen_decoder; + huffman_decoder *literal_decoder; + huffman_decoder *distance_decoder; + + string *bitlen_distance; + string *bitlen19; + string *bitlen510; + + unsigned char *dic_buf; + int dic_pos; + int dic_size; + int blockSize; + + int finish; + int error_no; + + int dic_bit; + int dispos_bit; + int dis_bit; + + /* buffer instances */ + bit_stream_reader _in; + bit_stream_writer _out; + string _bitlen_distance; + string _bitlen19; + string _bitlen510; + huffman_decoder _literal_decoder; + huffman_decoder _distance_decoder; + unsigned char _bitlen_distance_buf[18]; + unsigned char _bitlen19_buf[19]; + unsigned char _bitlen510_buf[510]; + unsigned char _dic_buf[65536]; +} LZHDecodeSessionObject; + + +PyDoc_STRVAR(LZHDecodeSession_do_next__doc__, +""); + +static PyObject * +LZHDecodeSession_do_next(LZHDecodeSessionObject *self) +{ + int error_no = 0; + int loop, code, srcpos, mlen, bitl, dist; + PyObject *ret; + + /* */ + if(self->error_no){ + goto exception; + } + + if(self->finish){ + Py_INCREF(Py_True); + return Py_True; + } + + /* */ + Py_BEGIN_ALLOW_THREADS + + loop = 64*1024; + + if(self->compress_type == COMPRESS_TYPE_LH0){ + /* This code is slow, but this happens a little */ + while(loop > 0){ + code = bit_stream_reader_fetch(self->in, 8); + if(code == -1){ + self->finish = 1; + break; + } + bit_stream_writer_write(self->out, code); + loop -= 1; + } + }else{ + while(loop > 0){ + if(self->blockSize <= 0){ + /* Delayed check for tuning */ + if(bit_stream_writer_overflow(self->out) != 0){ + error_no = ERR_BUFFER_OVER_FLOW; + break; + } + + if(bit_stream_writer_ioerror(self->out) != 0){ + error_no = ERR_IO_ERROR; + break; + } + + /* Read blockSize */ + self->blockSize = bit_stream_reader_fetch(self->in, 16); + + if(self->blockSize == -1){ + self->finish = 1; + break; + }else{ + /* Create bitlen_decoder for literal_decoder */ + error_no = decodeBitLengthDecoder(self->in, self->bitlen19); + if(error_no != 0){goto error;} + + error_no = huffman_decoder_init(self->bitlen_decoder, self->bitlen19); + if(error_no != 0){goto error;} + + /* Create literal decoder */ + error_no = decodeBitLengthLiteral(self->in, self->bitlen510, self->bitlen_decoder); + if(error_no != 0){goto error;} + + error_no = huffman_decoder_init(self->literal_decoder, self->bitlen510); + if(error_no != 0){goto error;} + + /* Create distance decoder */ + error_no = decodeBitLengthDistance(self->in, self->bitlen_distance, self->dispos_bit, self->dis_bit); + if(error_no != 0){goto error;} + + error_no = huffman_decoder_init(self->distance_decoder, self->bitlen_distance); + if(error_no != 0){goto error;} + + } + } + + code = huffman_decoder_decode(self->literal_decoder, self->in); + self->blockSize -= 1; + + if(code < 256){ + self->dic_buf[self->dic_pos++] = code; + bit_stream_writer_write(self->out, code); + loop -=1; + + self->dic_pos &= (self->dic_size -1); + continue; + } + + mlen = code - 256 + 3; + bitl = huffman_decoder_decode(self->distance_decoder, self->in); + + if(bitl == 0){ + dist = 1; + }else{ + dist = bit_stream_reader_fetch(self->in, bitl - 1); + EOF_CHECK(dist); + dist += (1 << (bitl - 1)); + dist += 1; + } + + srcpos = self->dic_pos - dist; + if(srcpos < 0){ + srcpos += self->dic_size; + } + + for(; mlen > 0 ; mlen--){ + code = self->dic_buf[self->dic_pos++] = self->dic_buf[srcpos++]; + bit_stream_writer_write(self->out, code); + loop -= 1; + + self->dic_pos &= (self->dic_size -1); + srcpos &= (self->dic_size -1); + } + } + } + +error: + Py_END_ALLOW_THREADS + + if(error_no != 0){ + self->error_no = error_no; + bit_stream_reader_close(self->in); + bit_stream_writer_close(self->out); + goto exception; + } + + if(self->finish){ + bit_stream_reader_close(self->in); + error_no = bit_stream_writer_close(self->out); + if(error_no != 0){ + self->error_no = error_no; + goto exception; + } + + Py_INCREF(Py_True); + ret = Py_True; + }else{ + Py_INCREF(Py_False); + ret = Py_False; + } + return ret; + +exception: + return PyErr_Format(PyExc_RuntimeError, "internal error code = %d", self->error_no); +} + +static PyMethodDef LZHDecodeSession_methods[] = { + {"do_next", (PyCFunction)LZHDecodeSession_do_next, METH_NOARGS, LZHDecodeSession_do_next__doc__}, + {NULL, NULL} +}; + +static PyMemberDef LZHDecodeSession_members[] = { + {"input_file_size", T_LONGLONG, offsetof(LZHDecodeSessionObject, info_compress_size), RO}, + {"input_pos", T_LONGLONG, offsetof(LZHDecodeSessionObject, _in) + offsetof(bit_stream_reader, pos), RO}, + {"output_file_size", T_LONGLONG, offsetof(LZHDecodeSessionObject, info_file_size), RO}, + {"output_pos", T_LONGLONG, offsetof(LZHDecodeSessionObject, _out) + offsetof(bit_stream_writer, pos), RO}, + {"crc16", T_LONG, offsetof(LZHDecodeSessionObject, _out) + offsetof(bit_stream_writer, crc16), RO}, + {NULL} +}; + + +static long long +LhaInfo_GetAttr(PyObject *info, const char *attr_name){ + PyObject *attr, *value; + long long num; + + attr = PyString_FromString(attr_name); + if(!attr){ goto error; } + + value = PyObject_GetAttr(info, attr); + Py_DECREF(attr); + if(!value){ goto error; } + + if(PyInt_Check(value)){ + num = (Py_off_t)PyInt_AsLong(value); + }else if(PyLong_Check(value)){ + num = (Py_off_t)PyLong_AsLongLong(value); + }else{ + Py_DECREF(value); + goto error; + } + Py_DECREF(value); + + return num; +error: + return -1; +} + + +static int +LZHDecodeSession_init(LZHDecodeSessionObject *self, PyObject *args, PyObject *kwargs) +{ + PyObject *fin, *fout, *info, *value, *attr; + int error_no; + + /* Parse arguments */ + if(!PyArg_ParseTuple(args, "OOO", &fin, &fout, &info)){ + goto error; + } + + /* compress_type */ + attr = PyString_FromString("compress_type"); + if(!attr){ goto error; } + + value = PyObject_GetAttr(info, attr); + + Py_DECREF(attr); + if(!value){ goto error; } + + if(memcmp(PyString_AsString(value), "-lh0-\x00", 6) == 0){ + self->compress_type = COMPRESS_TYPE_LH0; + self->dic_size = 0; + }else if(memcmp(PyString_AsString(value), "-lh5-\x00", 6) == 0){ + self->compress_type = COMPRESS_TYPE_LH5; + self->dic_size = 8192; + self->dic_bit = 13; + self->dispos_bit = 14; + self->dis_bit = 4; + }else if(memcmp(PyString_AsString(value), "-lh6-\x00", 6) == 0){ + self->compress_type = COMPRESS_TYPE_LH6; + self->dic_size = 32768; + self->dic_bit = 15; + self->dispos_bit = 16; + self->dis_bit = 5; + }else if(memcmp(PyString_AsString(value), "-lh7-\x00", 6) == 0){ + self->compress_type = COMPRESS_TYPE_LH7; + self->dic_size = 65536; + self->dic_bit = 16; + self->dispos_bit = 17; + self->dis_bit = 5; + }else{ + goto error; + } + Py_DECREF(value); + + /* Initialize each buffer and decoder */ + string_init(&self->_bitlen_distance, self->_bitlen_distance_buf, self->dispos_bit + 1); + string_init(&self->_bitlen19, self->_bitlen19_buf, 19); + string_init(&self->_bitlen510, self->_bitlen510_buf, 510); + + /* */ + self->finish = 0; + self->error_no = 0; + + self->in = &self->_in; + self->out = &self->_out; + + self->bitlen_distance = &self->_bitlen_distance; + self->bitlen19 = &self->_bitlen19; + self->bitlen510 = &self->_bitlen510; + + self->literal_decoder = &self->_literal_decoder; + self->distance_decoder = &self->_distance_decoder; + self->bitlen_decoder = &self->_distance_decoder; + + self->dic_buf = self->_dic_buf; + self->dic_pos = 0; + + self->blockSize = 0; + + self->info_compress_size = (Py_off_t)LhaInfo_GetAttr(info, "compress_size"); + self->info_file_size = (Py_off_t)LhaInfo_GetAttr(info, "file_size"); + self->info_crc = (int)LhaInfo_GetAttr(info, "CRC"); + + self->fin = fin; + self->fout = fout; + + error_no = bit_stream_reader_init_fileio(self->in, self->fin); + if(error_no != 0){ + goto error; + } + + error_no = bit_stream_writer_init_fileio(self->out, self->fout); + if(error_no != 0){ + bit_stream_reader_close(self->in); + goto error; + } + + Py_INCREF(self->fin); + Py_INCREF(self->fout); + + return 0; + +error: + return -1; +} + + +static void +LZHDecodeSession_dealloc(LZHDecodeSessionObject *self) +{ + /* If deocde is not finished */ + if(!self->finish && self->error_no == 0){ + bit_stream_reader_close(self->in); + bit_stream_writer_close(self->out); + } + + Py_DECREF(self->fin); + Py_DECREF(self->fout); + + self->ob_type->tp_free((PyObject *)self); +} + + +static PyTypeObject LZHDecodeSession_Type = { + PyObject_HEAD_INIT(NULL) + 0, /*ob_size*/ + "lhafile.LZHDecodeSession", /*tp_name*/ + sizeof(LZHDecodeSessionObject), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + (destructor)LZHDecodeSession_dealloc, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + 0, /*tp_compare*/ + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + PyObject_GenericGetAttr, /*tp_getattro*/ + PyObject_GenericSetAttr, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /*tp_flags*/ + 0, /*tp_doc*/ + 0, /*tp_traverse*/ + 0, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + LZHDecodeSession_methods, /*tp_methods*/ + LZHDecodeSession_members, /*tp_members*/ + 0, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + 0, /*tp_dictoffset*/ + (initproc)LZHDecodeSession_init, /*tp_init*/ + PyType_GenericAlloc, /*tp_alloc*/ + PyType_GenericNew, /*tp_new*/ + _PyObject_Del, /*tp_free*/ + 0, /*tp_is_gc*/ +}; + + +/* + * + */ + +static PyObject* +lzhlib_crc16(PyObject* self, PyObject* args) +{ + unsigned char *data; + int len; + int crc; + + crc = 0; + if(!PyArg_ParseTuple(args, "s#|i", &data, &len, &crc)){ + return NULL; + } + + crc = crc16(data, len, crc); + + return Py_BuildValue("i", (int)crc); +} + +static PyMethodDef lzhlib_methods[] = { + {"crc16", lzhlib_crc16, METH_VARARGS, + "Execute crc16 function: (s, crc) -> crc"}, + { NULL, NULL, 0, NULL} +}; + +PyMODINIT_FUNC +initlzhlib(void) +{ + PyObject *m; + + LZHDecodeSession_Type.ob_type = &PyType_Type; + + m = Py_InitModule("lzhlib", lzhlib_methods); + if (m == NULL) + return; + + PyModule_AddObject(m, "__author__", PyString_FromString(__author__)); + + Py_INCREF(&LZHDecodeSession_Type); + PyModule_AddObject(m, "LZHDecodeSession", (PyObject *)&LZHDecodeSession_Type); +} diff --git a/tools/splat_ext/lib/lhafile/setup.py b/tools/splat_ext/lib/lhafile/setup.py new file mode 100644 index 0000000..ad1faed --- /dev/null +++ b/tools/splat_ext/lib/lhafile/setup.py @@ -0,0 +1,36 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2010 Hidekazu Ohnishi +# +# This software is released under the terms of the BSD license. +# For more information see the COPYING.txt file in this directory. + +from distutils.core import setup, Extension + +lzhlib = Extension('lzhlib', + define_macros=[('MAJOR_VERSION', '0'), + ('MINOR_VERSION', '1')], + sources=['lhafile/lzhlib.c']) + +setup(name="lhafile", + packages=['lhafile'], + version='0.1', + description="LHA(.lzh) file extract interface", + long_description="""Extract LHA(.lzh) file extension. +Its interface is likely zipfile extension is included in regular +python distribution.""", + author='Hidekazu Ohnishi', + author_email='the-o@neotitans.net', + url='http://trac.neotitans.net/wiki/lhafile', + download_url='http://trac.neotitans.net/wiki/lhafile', + license='BSD', + keywords = [], + classifiers = [ + 'Development Status :: 4 - Beta', + 'Envrionment :: Other Environment', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: BSD License', + 'Operating System :: OS Independent' + 'Programming Language :: Python', + 'Topic :: Software Development'], + ext_modules=[lzhlib]) diff --git a/undefined_funcs.txt b/undefined_funcs.txt new file mode 100644 index 0000000..0549b34 --- /dev/null +++ b/undefined_funcs.txt @@ -0,0 +1,107 @@ +func_840010BC = 0x840010BC; +func_8008A37C = 0x8008A37C; +func_8008A354 = 0x8008A354; + +func_8023A05C = 0x8023A05C; +func_8023A150 = 0x8023A150; +func_8023A0F0 = 0x8023A0F0; +func_8023A608 = 0x8023A608; +func_8023A7A0 = 0x8023A7A0; +func_8023A7A0 = 0x8023A7A0; +func_8023A884 = 0x8023A884; +func_8023A884 = 0x8023A884; +func_8023A8A8 = 0x8023A8A8; +func_8023B4A0 = 0x8023B4A0; +func_8023B894 = 0x8023B894; +func_8023B928 = 0x8023B928; +func_8023B928 = 0x8023B928; +func_8023BBF0 = 0x8023BBF0; +func_8023BB78 = 0x8023BB78; +func_8023BBCC = 0x8023BBCC; +func_8023BD3C = 0x8023BD3C; +func_8023BCC8 = 0x8023BCC8; +func_8023BD1C = 0x8023BD1C; +func_8023BDB0 = 0x8023BDB0; +func_8023BF00 = 0x8023BF00; +func_8023C030 = 0x8023C030; +func_8023C1E8 = 0x8023C1E8; +func_8023C2E0 = 0x8023C2E0; +func_8023C304 = 0x8023C304; +func_8023C70C = 0x8023C70C; +func_8023D304 = 0x8023D304; +func_8023D7A0 = 0x8023D7A0; +func_8023D908 = 0x8023D908; +func_8023D90C = 0x8023D90C; +func_8023D90C = 0x8023D90C; +func_8023E4E8 = 0x8023E4E8; +func_8023DD90 = 0x8023DD90; +func_8023DE84 = 0x8023DE84; +func_8023E154 = 0x8023E154; +func_8023E7A4 = 0x8023E7A4; +func_8023E990 = 0x8023E990; +func_8023EAC8 = 0x8023EAC8; +func_8023EBF8 = 0x8023EBF8; +func_8023EDB8 = 0x8023EDB8; +func_8023EDB8 = 0x8023EDB8; +func_8023EEA0 = 0x8023EEA0; +func_8023F3E8 = 0x8023F3E8; +func_8023F3E8 = 0x8023F3E8; +func_8023F48C = 0x8023F48C; +func_8023F48C = 0x8023F48C; +func_8023F958 = 0x8023F958; +func_8023FA6C = 0x8023FA6C; +func_8023FC98 = 0x8023FC98; +func_8023FC98 = 0x8023FC98; +func_8023FC94 = 0x8023FC94; +func_8023FC98 = 0x8023FC98; +func_8023FC98 = 0x8023FC98; +func_8023FF34 = 0x8023FF34; +func_80240004 = 0x80240004; +func_80240144 = 0x80240144; +func_80240168 = 0x80240168; +func_80240180 = 0x80240180; +func_80240238 = 0x80240238; +func_80240474 = 0x80240474; +func_802406AC = 0x802406AC; +func_80240860 = 0x80240860; +func_802408E4 = 0x802408E4; +func_80240958 = 0x80240958; +func_802409BC = 0x802409BC; +func_80240C68 = 0x80240C68; +func_80240F18 = 0x80240F18; +func_80240EE4 = 0x80240EE4; +func_80240EF0 = 0x80240EF0; +func_80240F84 = 0x80240F84; +func_802415D4 = 0x802415D4; +func_80241698 = 0x80241698; +func_8024169C = 0x8024169C; +func_80241724 = 0x80241724; +func_80241744 = 0x80241744; +func_80241AE4 = 0x80241AE4; +func_80241BF0 = 0x80241BF0; +func_80241DE0 = 0x80241DE0; +func_80242010 = 0x80242010; +func_80242010 = 0x80242010; +func_80242404 = 0x80242404; +func_80242404 = 0x80242404; +func_80242400 = 0x80242400; +func_80242400 = 0x80242400; +func_80242400 = 0x80242400; +func_802424C4 = 0x802424C4; +func_802424C4 = 0x802424C4; +func_802424C0 = 0x802424C0; +func_802424C0 = 0x802424C0; +func_802424C0 = 0x802424C0; +func_80242E44 = 0x80242E44; +func_80242F14 = 0x80242F14; +func_8024304C = 0x8024304C; +func_80243048 = 0x80243048; +func_80243034 = 0x80243034; +func_8024339C = 0x8024339C; +func_80243424 = 0x80243424; +func_802434B4 = 0x802434B4; +func_80243510 = 0x80243510; +func_80243600 = 0x80243600; +func_8024366C = 0x8024366C; +func_802439E0 = 0x802439E0; +func_80243B94 = 0x80243B94; \ No newline at end of file diff --git a/undefined_syms.txt b/undefined_syms.txt new file mode 100644 index 0000000..795a487 --- /dev/null +++ b/undefined_syms.txt @@ -0,0 +1,39 @@ +D_800AEC70 = 0x800AEC70; +D_800AEC78 = 0x800AEC78; +D_800AEC80 = 0x800AEC80; +D_800AEC88 = 0x800AEC88; +D_800AEC90 = 0x800AEC90; +D_800AEC98 = 0x800AEC98; +D_800AECA0 = 0x800AECA0; +D_800AECA8 = 0x800AECA8; +D_800AECB0 = 0x800AECB0; +D_800AECC0 = 0x800AECC0; +D_800AECC8 = 0x800AECC8; +D_800AECD0 = 0x800AECD0; +D_800AECD8 = 0x800AECD8; +D_800AECE0 = 0x800AECE0; +D_800AECE8 = 0x800AECE8; +D_800AECF0 = 0x800AECF0; +D_800AECF8 = 0x800AECF8; +D_800AED00 = 0x800AED00; +D_800AED08 = 0x800AED08; +D_800AED10 = 0x800AED10; +D_800AED18 = 0x800AED18; +D_800AED20 = 0x800AED20; +D_800AED28 = 0x800AED28; +D_800AED30 = 0x800AED30; +D_800AED38 = 0x800AED38; +D_800AED40 = 0x800AED40; +D_800AED44 = 0x800AED44; +D_800AED48 = 0x800AED48; +D_800AED50 = 0x800AED50; +D_800AED58 = 0x800AED58; +D_800AED60 = 0x800AED60; +D_800EB8F4 = 0x800EB8F4; +D_800EB970 = 0x800EB970; +D_800EB9F4 = 0x800EB9F4; +D_800A8210 = 0x800A8210; +D_80187020 = 0x80187020; +D_80187030 = 0x80187030; +D_8018F1A0 = 0x8018F1A0; +D_8018FC18 = 0x8018FC18; \ No newline at end of file