diff --git a/dcb-exe/src/func.rs b/dcb-exe/src/func.rs index c73baa8..0ccabf3 100644 --- a/dcb-exe/src/func.rs +++ b/dcb-exe/src/func.rs @@ -6,9 +6,11 @@ //! type. // Modules +pub mod kind; pub mod table; // Exports +pub use kind::FuncKind; pub use table::FuncTable; // Imports @@ -54,6 +56,9 @@ pub struct Func { /// End position (non-inclusive) pub end_pos: Pos, + + /// Kind + pub kind: FuncKind, } impl Func { @@ -201,6 +206,7 @@ impl Func { labels, start_pos: func_pos, end_pos, + kind: FuncKind::Heuristics, }; assert!(cur_funcs.insert(func)); } diff --git a/dcb-exe/src/func/kind.rs b/dcb-exe/src/func/kind.rs new file mode 100644 index 0000000..b3f38fb --- /dev/null +++ b/dcb-exe/src/func/kind.rs @@ -0,0 +1,38 @@ +//! Function kind + +/// Function kind +#[derive(PartialEq, Eq, Clone, Copy, Debug)] +#[derive(serde::Serialize, serde::Deserialize)] +pub enum FuncKind { + /// Known + Known, + + /// Heuristics + Heuristics, +} + +impl FuncKind { + /// Returns `Self::Known` + #[must_use] + pub const fn known() -> Self { + Self::Known + } + + /// Returns `Self::Heuristics` + #[must_use] + pub const fn heuristics() -> Self { + Self::Heuristics + } + + /// Returns `true` if the function kind is [`Known`](Self::Known). + #[must_use] + pub const fn is_known(self) -> bool { + matches!(self, Self::Known) + } + + /// Returns `true` if the function kind is [`Heuristics`](Self::Heuristics). + #[must_use] + pub const fn is_heuristics(self) -> bool { + matches!(self, Self::Heuristics) + } +} diff --git a/resources/game_funcs.yaml b/resources/game_funcs.yaml index 0666c74..b3a6b72 100644 --- a/resources/game_funcs.yaml +++ b/resources/game_funcs.yaml @@ -16,6 +16,7 @@ 0x80056280: zero_loop start_pos: 0x80056270 end_pos: 0x80056330 + kind: Known # Main game loop - name: main_loop @@ -36,6 +37,7 @@ 0x80013f8c: "4" start_pos: 0x80013e4c end_pos: 0x80013fa4 + kind: Known # ??? - name: something1 @@ -51,6 +53,7 @@ 0x80056370: skip start_pos: 0x80056330 end_pos: 0x80056388 + kind: Known - name: call_func_arr desc: |- @@ -73,6 +76,7 @@ 0x800563d0: exit start_pos: 0x80056388 end_pos: 0x800563e4 + kind: Known # ? - name: something3 @@ -83,6 +87,7 @@ 0x8005660c: "Calls FuncList1[3] (i.e. something5)" start_pos: 0x800565f4 end_pos: 0x80056624 + kind: Known # ? - name: something5 @@ -107,6 +112,7 @@ 0x80056800: skip_call start_pos: 0x80056788 end_pos: 0x80056860 + kind: Known # ? - name: something6 @@ -139,6 +145,7 @@ 0x80056548: exit start_pos: 0x800563e4 end_pos: 0x8005655c + kind: Known # ? - name: something7 @@ -156,6 +163,7 @@ 0x800565e4: exit start_pos: 0x8005655c end_pos: 0x800565f4 + kind: Known #? - name: something4 @@ -171,6 +179,7 @@ 0x80056b58: "7" start_pos: 0x80056a30 end_pos: 0x80056b78 + kind: Known - name: memset_zero signature: "fn(u32* ptr, u32 size)" @@ -187,18 +196,21 @@ 0x80056cac: exit start_pos: 0x80056c90 end_pos: 0x80056cb4 + kind: Known - name: save_registers signature: fn(u32* pos) desc: "Saves the following registers in `pos[0x0 .. 0x30]`.\n$ra, $gp, $sp, $fp,\n$s0, $s1, $s2, $s3,\n$s4, $s5, $s6, $s7,\n" start_pos: 0x8006a674 end_pos: 0x8006a6b0 + kind: Known - name: load_registers signature: fn(u32* pos) desc: "Loads the following registers from `pos[0x0 .. 0x30]`.\n$ra, $gp, $sp, $fp,\n$s0, $s1, $s2, $s3,\n$s4, $s5, $s6, $s7,\n" start_pos: 0x8006a6b0 end_pos: 0x8006a6fc + kind: Known - name: prng_next signature: fn() @@ -207,6 +219,7 @@ Returns `cur_prng_value << 0x10 | 0x7fff`. start_pos: 0x80069124 end_pos: 0x80069154 + kind: Known - name: something8 signature: "fn(a: u32, b: u32, c: u32, d: u32)" @@ -215,6 +228,7 @@ 0x80061910: "args: ($s1, $s0, c & 0xffff, d & 0xffff)" start_pos: 0x800618e4 end_pos: 0x80061954 + kind: Known - name: modify_spu_delay1 signature: "fn() -> u32" @@ -226,6 +240,7 @@ 0x8004b474: "*SPU_DELAY = $v0" start_pos: 0x8004b428 end_pos: 0x8004b450 + kind: Known - name: modify_spu_delay2 signature: "fn() -> u32" @@ -237,6 +252,7 @@ 0x8004b474: "*SPU_DELAY = $v0" start_pos: 0x8004b450 end_pos: 0x8004b478 + kind: Known - name: calc_0x890e6fbd signature: "fn() -> u32" @@ -260,10 +276,12 @@ 0x8004b4b8: "while_condition" start_pos: 0x8004b478 end_pos: 0x8004b4d4 + kind: Known - name: something9 start_pos: 0x80013fa4 end_pos: 0x800141b8 + kind: Known labels: 0x80013fe4: "0" 0x80014058: "1" @@ -275,6 +293,7 @@ - name: something10 start_pos: 0x800141b8 end_pos: 0x800142d0 + kind: Known labels: 0x800141ec: "0" 0x80014268: "1" @@ -284,6 +303,7 @@ - name: something11 start_pos: 0x800142d0 end_pos: 0x80014364 + kind: Known labels: 0x8001431c: "0" 0x80014320: "1" @@ -292,126 +312,157 @@ - name: something12 start_pos: 0x80015328 end_pos: 0x800157b0 + kind: Known - name: something13 start_pos: 0x800148f8 end_pos: 0x80014970 + kind: Known - name: something14 start_pos: 0x80014b94 end_pos: 0x80014c08 + kind: Known - name: something15 start_pos: 0x8002a7cc end_pos: 0x8002ab5c + kind: Known - name: something16 start_pos: 0x8001b358 end_pos: 0x8001b438 + kind: Known - name: something17 start_pos: 0x8002c1c0 end_pos: 0x8002cc44 + kind: Known - name: something18 start_pos: 0x80015a3c end_pos: 0x80015ad8 + kind: Known - name: something19 start_pos: 0x800162f0 end_pos: 0x80016878 + kind: Known - name: something20 start_pos: 0x8001963c end_pos: 0x80019ea4 + kind: Known - name: something21 start_pos: 0x8001a1d8 end_pos: 0x8001a600 + kind: Known - name: something22 start_pos: 0x8001a870 end_pos: 0x8001a9b0 + kind: Known - name: something23 start_pos: 0x8001b088 end_pos: 0x8001b10c + kind: Known - name: something24 start_pos: 0x8001b734 end_pos: 0x8001b90c + kind: Known - name: something25 start_pos: 0x8001bb44 end_pos: 0x8001bb94 + kind: Known - name: something26 start_pos: 0x8001bc38 end_pos: 0x8001bca4 + kind: Known - name: something27 start_pos: 0x8001c0a8 end_pos: 0x8001c1e0 + kind: Known - name: something28 start_pos: 0x8001c220 end_pos: 0x8001d900 + kind: Known - name: something29 start_pos: 0x8001da24 end_pos: 0x8001dfe0 + kind: Known - name: something30 start_pos: 0x8001e180 end_pos: 0x8001e53c + kind: Known - name: something31 start_pos: 0x8001e850 end_pos: 0x8001e894 + kind: Known - name: something32 start_pos: 0x8001f094 end_pos: 0x8001f3c0 + kind: Known - name: something33 start_pos: 0x8001f5cc end_pos: 0x8001f5fc + kind: Known - name: something34 start_pos: 0x8001f630 end_pos: 0x8001f660 + kind: Known - name: something35 start_pos: 0x8001f6c4 end_pos: 0x8001f768 + kind: Known - name: something36 start_pos: 0x8001f768 end_pos: 0x8001f824 + kind: Known - name: something37 start_pos: 0x8001f824 end_pos: 0x8001f8b0 + kind: Known - name: something38 start_pos: 0x8001f8b0 end_pos: 0x8001f94c + kind: Known - name: something39 start_pos: 0x8005aa7c end_pos: 0x8005ab4c + kind: Known - name: something40 start_pos: 0x8005a7d4 end_pos: 0x8005a808 + kind: Known - name: something41 start_pos: 0x80049e80 end_pos: 0x80049ef8 + kind: Known - name: something42 start_pos: 0x8004b2f0 end_pos: 0x8004b394 + kind: Known inline_comments: 0x8004b2f0: "Division by 0" @@ -424,36 +475,43 @@ 0x8006a73c: "arg: 0x39" start_pos: 0x8006a734 end_pos: 0x8006a744 + kind: Known - name: FlushCache signature: "fn()" desc: Calls A(0x44) start_pos: 0x8006a744 end_pos: 0x8006a754 + kind: Known - name: GPU_cw signature: "fn(cmd: u32)" desc: Calls A(0x49) start_pos: 0x8006a754 end_pos: 0x8006a764 + kind: Known - name: _bu_init signature: "fn()" desc: Calls A(0x70) start_pos: 0x80068804 end_pos: 0x80068814 + kind: Known - name: CdRemove signature: "fn()" desc: Calls A(0x72) start_pos: 0x8006a76c end_pos: 0x8006a77c + kind: Known - name: _card_info signature: "fn(port: u32)" desc: Calls A(0xab) start_pos: 0x80068814 end_pos: 0x80068824 + kind: Known - name: _card_async_load_directory signature: "fn(port: u32)" desc: Calls A(0xac) start_pos: 0x80068824 end_pos: 0x80068834 + kind: Known # B Functions - name: DeliverEvent @@ -461,131 +519,157 @@ desc: Calls B(0x07) start_pos: 0x8006a784 end_pos: 0x8006a794 + kind: Known - name: OpenEvent signature: "fn(class: u32, spec: u32, mode: u32, func: u32)" desc: Calls B(0x08) start_pos: 0x8006a794 end_pos: 0x8006a7a4 + kind: Known - name: WaitEvent signature: "fn(event: u32)" desc: Calls B(0x0a) start_pos: 0x8006a7a4 end_pos: 0x8006a7b4 + kind: Known - name: TestEvent signature: "fn(event: u32)" desc: Calls B(0x0b) start_pos: 0x8006a7b4 end_pos: 0x8006a7c4 + kind: Known - name: EnableEvent signature: "fn(event: u32)" desc: Calls B(0x0c) start_pos: 0x8006a7c4 end_pos: 0x8006a7d4 + kind: Known - name: InitPad signature: "fn(buf1: *mut u8, size1: u32, buf2: *mut u8, size2: u32)" desc: Calls B(0x12) start_pos: 0x8006af54 end_pos: 0x8006af64 + kind: Known - name: StartPad signature: "fn()" desc: Calls B(0x13) start_pos: 0x8006af64 end_pos: 0x8006af74 + kind: Known - name: OutdatedPadInitAndStart signature: "fn(type: u32, button_dest: *mut u8, unused1: u32, unused2: u32)" desc: Calls B(0x15) start_pos: 0x8006af74 end_pos: 0x8006af84 + kind: Known - name: ReturnFromException signature: "fn()" desc: Calls B(0x17) start_pos: 0x8006a7d4 end_pos: 0x8006a7e4 + kind: Known - name: SetDefaultExitFromException signature: "fn()" desc: Calls B(0x18) start_pos: 0x8006a7e4 end_pos: 0x8006a7f4 + kind: Known - name: SetCustomExitFromException signature: "fn(addr: fn())" desc: Calls B(0x19) start_pos: 0x8006a7f4 end_pos: 0x8006a804 + kind: Known - name: FileOpen signature: "fn(filename: *const str, access_mode: u32)" desc: Calls B(0x32) start_pos: 0x8006a824 end_pos: 0x8006a834 + kind: Known - name: FileSeek signature: "fn(fd: u32, offset: u32, seek_type: u32)" desc: Calls B(0x33) start_pos: 0x8006a834 end_pos: 0x8006a844 + kind: Known - name: FileRead signature: "fn(fd: u32, dst: *mut u8, length: u32)" desc: Calls B(0x34) start_pos: 0x8006a844 end_pos: 0x8006a854 + kind: Known - name: FileWrite signature: "fn(fd: u32, src: *const u8, length: u32)" desc: Calls B(0x35) start_pos: 0x8006a854 end_pos: 0x8006a864 + kind: Known - name: FileClose signature: "fn(fd: u32)" desc: Calls B(0x36) start_pos: 0x8006a864 end_pos: 0x8006a874 + kind: Known - name: firstfile signature: "fn(filename: *const str, dir_entry: u32)" desc: Calls B(0x42) start_pos: 0x8006acb4 end_pos: 0x8006acc4 + kind: Known - name: nextfile signature: "fn(dir_entry: u32)" desc: Calls B(0x43) start_pos: 0x8006a874 end_pos: 0x8006a884 + kind: Known - name: InitCard signature: "fn(pad_enable: u32)" desc: Calls B(0x4a) start_pos: 0x80068994 end_pos: 0x800689a4 + kind: Known - name: StartCard signature: "fn()" desc: Calls B(0x4b) start_pos: 0x800689a4 end_pos: 0x800689b4 + kind: Known - name: StopCard signature: "fn()" desc: Calls B(0x4c) start_pos: 0x800689b4 end_pos: 0x800689c4 + kind: Known - name: write_card_sector signature: "fn(port: u32, sector: u32, src: *const u8)" desc: Calls B(0x4e) start_pos: 0x80068874 end_pos: 0x80068884 + kind: Known - name: read_card_sector signature: "fn(port: u32, sector: u32, dst: *mut u8)" desc: Calls B(0x4f) start_pos: 0x80069024 end_pos: 0x80069034 + kind: Known - name: allow_new_card signature: "fn()" desc: Calls B(0x50) start_pos: 0x80068884 end_pos: 0x80068894 + kind: Known - name: ChangeClearPad signature: "fn(pad: u32)" desc: Calls B(0x5b) start_pos: 0x8006a884 end_pos: 0x8006a894 + kind: Known - name: get_card_status signature: "fn(slot: u32)" desc: Calls B(0x5c) start_pos: 0x80069034 end_pos: 0x80069044 + kind: Known # C Functions - name: SysEnqIntRP @@ -593,16 +677,19 @@ desc: Calls C(0x02) start_pos: 0x8006af84 end_pos: 0x8006af94 + kind: Known - name: SysDeqIntRP signature: "fn(priority: u32, struct: u32)" desc: Calls C(0x03) start_pos: 0x8006af94 end_pos: 0x8006afa4 + kind: Known - name: ChangeClearRCnt signature: "fn(t: u32, flag: u32)" desc: Calls C(0x0a) start_pos: 0x8006a894 end_pos: 0x8006a8a0 + kind: Known # Std - name: sprintf @@ -685,6 +772,7 @@ 0x8006a570: "65" start_pos: 0x80069d24 end_pos: 0x8006a5a4 + kind: Known - name: memcpy_args_reversed signature: "fn(src: *const u8, dst: *mut u8, len: u32) -> *mut u8" @@ -708,6 +796,7 @@ 0x80069070: "on_null" start_pos: 0x80069044 end_pos: 0x80069078 + kind: Known - name: mem_zero signature: "fn(dst: *mut u8, len: u32) -> *mut u8" @@ -733,6 +822,7 @@ 0x800690ac: "end" start_pos: 0x80069084 end_pos: 0x800690b4 + kind: Known - name: memcpy signature: "fn(dst: *mut u8, src: *const u8, len: u32) -> *mut u8" @@ -754,6 +844,7 @@ 0x800690e0: "on_null" start_pos: 0x800690b4 end_pos: 0x800690e8 + kind: Known - name: memset signature: "fn(dst: *mut u8, value: u32, len: u32) -> *mut u8" @@ -775,6 +866,7 @@ 0x8006911c: "end" start_pos: 0x800690f4 end_pos: 0x80069124 + kind: Known - name: strcat signature: "fn(dst: *mut u8, src: *const u8) -> *mut u8" @@ -817,6 +909,7 @@ 0x800691f0: "exit" start_pos: 0x80069164 end_pos: 0x80069208 + kind: Known - name: strlen signature: "fn(ptr: *const u8) -> u32" @@ -829,6 +922,7 @@ 0x80069300: "on_null" start_pos: 0x800692d4 end_pos: 0x80069308 + kind: Known # TODO: Investigate this more, seems weird - name: strcmp @@ -867,6 +961,7 @@ 0x80069270: "exit" start_pos: 0x80069214 end_pos: 0x80069278 + kind: Known - name: strcpy signature: "fn(dst: *mut u8, src: *const u8) -> *mut u8" @@ -897,3 +992,4 @@ 0x800692c0: "on_null" start_pos: 0x80069284 end_pos: 0x800692c8 + kind: Known