From c1ca74d657fb11b67435d6e5679ab6482c4c5516 Mon Sep 17 00:00:00 2001 From: robojumper Date: Mon, 20 May 2024 23:22:31 +0200 Subject: [PATCH] DynamicLink --- config/SOUE01/splits.txt | 16 +- config/SOUE01/symbols.txt | 168 ++++++++--------- configure.py | 4 + include/DynamicLink.h | 96 ++++++++++ include/d/d_dvd.h | 41 +++++ include/d/d_dvd_unk.h | 26 +++ include/d/d_dylink.h | 12 ++ include/m/m_dvd.h | 18 +- include/rvl/OS/OSLink.h | 109 ++++++++++- src/DynamicLink.cpp | 373 ++++++++++++++++++++++++++++++++++++++ src/d/d_dvd.cpp | 62 +++++++ src/d/d_dvd_unk.cpp | 44 +++++ src/d/d_dylink.cpp | 130 +++++++++++++ src/m/m_dvd.cpp | 21 +-- 14 files changed, 1013 insertions(+), 107 deletions(-) create mode 100644 include/DynamicLink.h create mode 100644 include/d/d_dvd.h create mode 100644 include/d/d_dvd_unk.h create mode 100644 include/d/d_dylink.h create mode 100644 src/DynamicLink.cpp create mode 100644 src/d/d_dvd.cpp create mode 100644 src/d/d_dvd_unk.cpp create mode 100644 src/d/d_dylink.cpp diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index bedcd3d5..5ca0c46b 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -55,11 +55,19 @@ d/d_cc.cpp: .text start:0x80050A20 end:0x800520F0 d/d_dvd.cpp: - .text start:0x800520F0 end:0x80052E00 + .text start:0x800520F0 end:0x800522FC + .data start:0x805033F0 end:0x80503400 + .sdata start:0x80571C10 end:0x80571C20 + +d/d_dvd_unk.cpp: + .text start:0x80052300 end:0x80052E00 + .sbss start:0x805750D0 end:0x805750D8 d/d_dylink.cpp: .text start:0x80052E00 end:0x80053A30 .ctors start:0x804DB674 end:0x804DB678 + .data start:0x8050D2D8 end:0x8050D30C + .sbss start:0x805750E0 end:0x805750FC d/d_fader.cpp: .text start:0x80053A30 end:0x80053E70 @@ -183,6 +191,12 @@ toBeSorted/counters/extra_wallet_counter.cpp: .data start:0x805280B0 end:0x805280D0 .sbss start:0x80575640 end:0x80575648 +DynamicLink.cpp: + .text start:0x802DF100 end:0x802DFCB0 + .data start:0x805419E8 end:0x80541A70 + .sdata start:0x80573F78 end:0x80573FB0 + .sbss start:0x80575B80 end:0x80575BA0 + c/c_list.cpp: .text start:0x802E08C0 end:0x802E0A10 diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index 71a0c2b2..1ae97d22 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -2140,16 +2140,16 @@ fn_80052060 = .text:0x80052060; // type:function size:0x10 fn_80052070 = .text:0x80052070; // type:function size:0x10 fn_80052080 = .text:0x80052080; // type:function size:0x10 fn_80052090 = .text:0x80052090; // type:function size:0x60 -fn_800520F0 = .text:0x800520F0; // type:function size:0x4 -fn_80052100 = .text:0x80052100; // type:function size:0x28 -fn_80052130 = .text:0x80052130; // type:function size:0x40 -fn_80052170 = .text:0x80052170; // type:function size:0x128 -fn_800522A0 = .text:0x800522A0; // type:function size:0x5C -fn_80052300 = .text:0x80052300; // type:function size:0x34 -fn_80052340 = .text:0x80052340; // type:function size:0x8 -fn_80052350 = .text:0x80052350; // type:function size:0x35C +create__4dDvdFlPQ23EGG4HeapPQ23EGG4HeapPQ23EGG4Heap = .text:0x800520F0; // type:function size:0x4 +__ct__Q24dDvd8loader_cFv = .text:0x80052100; // type:function size:0x28 +__dt__Q24dDvd8loader_cFv = .text:0x80052130; // type:function size:0x40 +request__Q24dDvd8loader_cFPCcUcPQ23EGG4Heap = .text:0x80052170; // type:function size:0x128 +remove__Q24dDvd8loader_cFv = .text:0x800522A0; // type:function size:0x5C +create__Q24dDvd11unkstruct_cFPQ23EGG4Heap = .text:0x80052300; // type:function size:0x34 +getUnk__Q24dDvd11unkstruct_cFv = .text:0x80052340; // type:function size:0x8 +draw__Q27dDvdUnk11unkstruct_cFv = .text:0x80052350; // type:function size:0x35C fn_800526B0 = .text:0x800526B0; // type:function size:0x98 -fn_80052750 = .text:0x80052750; // type:function size:0x10 +init__Q24dDvd11unkstruct_cFv = .text:0x80052750; // type:function size:0x10 fn_80052760 = .text:0x80052760; // type:function size:0x88 fn_800527F0 = .text:0x800527F0; // type:function size:0x11C fn_80052910 = .text:0x80052910; // type:function size:0x48 @@ -2169,7 +2169,7 @@ fn_80052D50 = .text:0x80052D50; // type:function size:0x78 fn_80052DD0 = .text:0x80052DD0; // type:function size:0x2C fn_80052E00 = .text:0x80052E00; // type:function size:0x1A0 fn_80052FA0 = .text:0x80052FA0; // type:function size:0x30 -fn_80052FD0 = .text:0x80052FD0; // type:function size:0x20 +Unlink__4dDylFUs = .text:0x80052FD0; // type:function size:0x20 fn_80052FF0 = .text:0x80052FF0; // type:function size:0x84 fn_80053080 = .text:0x80053080; // type:function size:0x58 fn_800530E0 = .text:0x800530E0; // type:function size:0x7C @@ -2182,9 +2182,9 @@ fn_80053780 = .text:0x80053780; // type:function size:0x54 fn_800537E0 = .text:0x800537E0; // type:function size:0x30 fn_80053810 = .text:0x80053810; // type:function size:0x6C fn_80053880 = .text:0x80053880; // type:function size:0xC -fn_80053890 = .text:0x80053890; // type:function size:0xA0 +do_link__21dDynamicModuleControlFv = .text:0x80053890; // type:function size:0xA0 fn_80053930 = .text:0x80053930; // type:function size:0x9C -fn_800539D0 = .text:0x800539D0; // type:function size:0x54 +__sinit_\d_dylink_cpp = .text:0x800539D0; // type:function size:0x54 fn_80053A30 = .text:0x80053A30; // type:function size:0xE4 fn_80053B20 = .text:0x80053B20; // type:function size:0x128 fn_80053C50 = .text:0x80053C50; // type:function size:0x198 @@ -17229,42 +17229,42 @@ fn_802DEFE0 = .text:0x802DEFE0; // type:function size:0x80 OSReport = .text:0x802DF060; // type:function size:0x80 scope:weak OSVReport = .text:0x802DF0E0; // type:function size:0x4 scope:global fn_802DF0F0 = .text:0x802DF0F0; // type:function size:0x10 -fn_802DF100 = .text:0x802DF100; // type:function size:0xA0 -fn_802DF1A0 = .text:0x802DF1A0; // type:function size:0x48 -fn_802DF1F0 = .text:0x802DF1F0; // type:function size:0x94 -fn_802DF290 = .text:0x802DF290; // type:function size:0x74 -fn_802DF310 = .text:0x802DF310; // type:function size:0x24 -fn_802DF340 = .text:0x802DF340; // type:function size:0x8 -fn_802DF350 = .text:0x802DF350; // type:function size:0x8 -fn_802DF360 = .text:0x802DF360; // type:function size:0x8 -fn_802DF370 = .text:0x802DF370; // type:function size:0x4 -fn_802DF380 = .text:0x802DF380; // type:function size:0x8 -fn_802DF390 = .text:0x802DF390; // type:function size:0x8 -fn_802DF3A0 = .text:0x802DF3A0; // type:function size:0x8 -fn_802DF3B0 = .text:0x802DF3B0; // type:function size:0x8 -fn_802DF3C0 = .text:0x802DF3C0; // type:function size:0x8 -fn_802DF3D0 = .text:0x802DF3D0; // type:function size:0x80 -fn_802DF450 = .text:0x802DF450; // type:function size:0x68 -fn_802DF4C0 = .text:0x802DF4C0; // type:function size:0x8 -fn_802DF4D0 = .text:0x802DF4D0; // type:function size:0x5C -fn_802DF530 = .text:0x802DF530; // type:function size:0x10 -fn_802DF540 = .text:0x802DF540; // type:function size:0x84 -fn_802DF5D0 = .text:0x802DF5D0; // type:function size:0x138 -fn_802DF710 = .text:0x802DF710; // type:function size:0x8C -fn_802DF7A0 = .text:0x802DF7A0; // type:function size:0x54 -fn_802DF800 = .text:0x802DF800; // type:function size:0x4 -fn_802DF810 = .text:0x802DF810; // type:function size:0x250 -fn_802DFA60 = .text:0x802DFA60; // type:function size:0xA4 -fn_802DFB10 = .text:0x802DFB10; // type:function size:0x5C -fn_802DFB70 = .text:0x802DFB70; // type:function size:0x18 -fn_802DFB90 = .text:0x802DFB90; // type:function size:0x60 -fn_802DFBF0 = .text:0x802DFBF0; // type:function size:0x70 -fn_802DFC60 = .text:0x802DFC60; // type:function size:0x50 -fn_802DFCB0 = .text:0x802DFCB0; // type:function size:0x4 -fn_802DFCC0 = .text:0x802DFCC0; // type:function size:0x4 -fn_802DFCD0 = .text:0x802DFCD0; // type:function size:0x4 -fn_802DFCE0 = .text:0x802DFCE0; // type:function size:0x44 -fn_802DFD30 = .text:0x802DFD30; // type:function size:0x44 +__dt__24DynamicModuleControlBaseFv = .text:0x802DF100; // type:function size:0xA0 +__ct__24DynamicModuleControlBaseFv = .text:0x802DF1A0; // type:function size:0x48 +link__24DynamicModuleControlBaseFv = .text:0x802DF1F0; // type:function size:0x94 +unlink__24DynamicModuleControlBaseFv = .text:0x802DF290; // type:function size:0x74 +load_async__24DynamicModuleControlBaseFv = .text:0x802DF310; // type:function size:0x24 +getModuleName__24DynamicModuleControlBaseCFv = .text:0x802DF340; // type:function size:0x8 +getModuleSize__24DynamicModuleControlBaseCFv = .text:0x802DF350; // type:function size:0x8 +getModuleTypeString__24DynamicModuleControlBaseCFv = .text:0x802DF360; // type:function size:0x8 +dump__24DynamicModuleControlBaseFv = .text:0x802DF370; // type:function size:0x4 +do_load__24DynamicModuleControlBaseFv = .text:0x802DF380; // type:function size:0x8 +do_load_async__24DynamicModuleControlBaseFv = .text:0x802DF390; // type:function size:0x8 +do_unload__24DynamicModuleControlBaseFv = .text:0x802DF3A0; // type:function size:0x8 +do_link__24DynamicModuleControlBaseFv = .text:0x802DF3B0; // type:function size:0x8 +do_unlink__24DynamicModuleControlBaseFv = .text:0x802DF3C0; // type:function size:0x8 +__ct__20DynamicModuleControlFPCcPQ23EGG7ExpHeap = .text:0x802DF3D0; // type:function size:0x80 +__dt__20DynamicModuleControlFv = .text:0x802DF450; // type:function size:0x68 +getModuleName__20DynamicModuleControlCFv = .text:0x802DF4C0; // type:function size:0x8 +initialize__20DynamicModuleControlFPQ23EGG7ExpHeap = .text:0x802DF4D0; // type:function size:0x5C +callback__20DynamicModuleControlFPv = .text:0x802DF530; // type:function size:0x10 +checkHeapStatus__20DynamicModuleControlFv = .text:0x802DF540; // type:function size:0x84 +do_load__20DynamicModuleControlFv = .text:0x802DF5D0; // type:function size:0x138 +do_load_async__20DynamicModuleControlFv = .text:0x802DF710; // type:function size:0x8C +do_unload__20DynamicModuleControlFv = .text:0x802DF7A0; // type:function size:0x54 +dump__20DynamicModuleControlFv = .text:0x802DF800; // type:function size:0x4 +do_link__20DynamicModuleControlFv = .text:0x802DF810; // type:function size:0x250 +do_unlink__20DynamicModuleControlFv = .text:0x802DFA60; // type:function size:0xA4 +getModuleSize__20DynamicModuleControlCFv = .text:0x802DFB10; // type:function size:0x5C +getModuleTypeString__20DynamicModuleControlCFv = .text:0x802DFB70; // type:function size:0x18 +__dt__9DbMapFileFv = .text:0x802DFB90; // type:function size:0x60 +RegisterOnDvd__9DbMapFileFPCcPC12OSModuleInfo = .text:0x802DFBF0; // type:function size:0x70 +Unregister__9DbMapFileFv = .text:0x802DFC60; // type:function size:0x50 +ModuleProlog = .text:0x802DFCB0; // type:function size:0x4 +ModuleEpilog = .text:0x802DFCC0; // type:function size:0x4 +ModuleUnresolved = .text:0x802DFCD0; // type:function size:0x4 +ModuleConstructorsX = .text:0x802DFCE0; // type:function size:0x44 +ModuleDestructorsX = .text:0x802DFD30; // type:function size:0x44 fn_802DFD80 = .text:0x802DFD80; // type:function size:0x4 fn_802DFD90 = .text:0x802DFD90; // type:function size:0x234 fn_802DFFD0 = .text:0x802DFFD0; // type:function size:0x1B8 @@ -17755,11 +17755,11 @@ mainLoop__12mDvd_param_cFv = .text:0x802EF410; // type:function size:0x4C __ct__14mDvd_command_cFv = .text:0x802EF460; // type:function size:0x1C fn_802EF480 = .text:0x802EF480; // type:function size:0x20 destroy__14mDvd_command_cFPP14mDvd_command_c = .text:0x802EF4A0; // type:function size:0x54 -__dt__25mDvdCommandReadCallback_cFv = .text:0x802EF500; // type:function size:0x58 -__ct__25mDvdCommandReadCallback_cFPFPv_PvPv = .text:0x802EF560; // type:function size:0x64 -create__25mDvdCommandReadCallback_cFPFPv_PvPv = .text:0x802EF5D0; // type:function size:0x78 +__dt__15mDvd_callback_cFv = .text:0x802EF500; // type:function size:0x58 +__ct__15mDvd_callback_cFPFPv_bPv = .text:0x802EF560; // type:function size:0x64 +create__15mDvd_callback_cFPFPv_bPv = .text:0x802EF5D0; // type:function size:0x78 fn_802EF650 = .text:0x802EF650; // type:function size:0x30 -execute__25mDvdCommandReadCallback_cFv = .text:0x802EF680; // type:function size:0x54 +execute__15mDvd_callback_cFv = .text:0x802EF680; // type:function size:0x54 __dt__22mDvd_mountMemArchive_cFv = .text:0x802EF6E0; // type:function size:0x58 __ct__22mDvd_mountMemArchive_cFi = .text:0x802EF740; // type:function size:0x74 findPathWithCompressedExtension__FPCcPUc = .text:0x802EF7C0; // type:function size:0x16C @@ -21970,10 +21970,10 @@ fn_803A9500 = .text:0x803A9500; // type:function size:0x4 fn_803A9510 = .text:0x803A9510; // type:function size:0xC fn_803A9520 = .text:0x803A9520; // type:function size:0x2C4 fn_803A97F0 = .text:0x803A97F0; // type:function size:0x2E8 -fn_803A9AE0 = .text:0x803A9AE0; // type:function size:0x8 -fn_803A9AF0 = .text:0x803A9AF0; // type:function size:0x1C +OSLink = .text:0x803A9AE0; // type:function size:0x8 +OSLinkFixed = .text:0x803A9AF0; // type:function size:0x1C fn_803A9B10 = .text:0x803A9B10; // type:function size:0x240 -fn_803A9D50 = .text:0x803A9D50; // type:function size:0x1D4 +OSUnlink = .text:0x803A9D50; // type:function size:0x1D4 __OSModuleInit = .text:0x803A9F30; // type:function size:0x18 scope:global fn_803A9F50 = .text:0x803A9F50; // type:function size:0xA4 OSInitMessageQueue = .text:0x803AA000; // type:function size:0x60 @@ -30061,7 +30061,7 @@ lbl_80503314 = .data:0x80503314; // type:object size:0x6C __vt__7dBase_c = .data:0x80503380; // type:object size:0x4C lbl_805033D0 = .data:0x805033D0; // type:object size:0x10 lbl_805033E0 = .data:0x805033E0; // type:object size:0x10 -lbl_805033F0 = .data:0x805033F0; // type:object size:0x10 +__vt__Q24dDvd8loader_c = .data:0x805033F0; // type:object size:0x10 lbl_80503400 = .data:0x80503400; // type:object size:0x40 lbl_80503440 = .data:0x80503440; // type:object size:0x6DF8 lbl_8050A238 = .data:0x8050A238; // type:object size:0x14 @@ -30695,7 +30695,7 @@ lbl_8050D290 = .data:0x8050D290; // type:object size:0x14 lbl_8050D2A4 = .data:0x8050D2A4; // type:object size:0x14 lbl_8050D2B8 = .data:0x8050D2B8; // type:object size:0x14 lbl_8050D2CC = .data:0x8050D2CC; // type:object size:0xC -lbl_8050D2D8 = .data:0x8050D2D8; // type:object size:0x34 +lbl_8050D2D8 = .data:0x8050D2D8; // type:object size:0x32 data:string lbl_8050D30C = .data:0x8050D30C; // type:object size:0x14 lbl_8050D320 = .data:0x8050D320; // type:object size:0x10 lbl_8050D330 = .data:0x8050D330; // type:object size:0xC @@ -35665,8 +35665,8 @@ lbl_805419A8 = .data:0x805419A8; // type:object size:0x40 lbl_805419E8 = .data:0x805419E8; // type:object size:0xC data:string lbl_805419F4 = .data:0x805419F4; // type:object size:0xC data:string lbl_80541A00 = .data:0x80541A00; // type:object size:0x10 -lbl_80541A10 = .data:0x80541A10; // type:object size:0x30 -lbl_80541A40 = .data:0x80541A40; // type:object size:0x30 +__vt__20DynamicModuleControl = .data:0x80541A10; // type:object size:0x30 +__vt__24DynamicModuleControlBase = .data:0x80541A40; // type:object size:0x30 lbl_80541A70 = .data:0x80541A70; // type:object size:0x808 lbl_80542278 = .data:0x80542278; // type:object size:0xB4 data:4byte lbl_8054232C = .data:0x8054232C; // type:object size:0x30 @@ -35722,7 +35722,7 @@ __vt__23mDvd_toMainRam_normal_c = .data:0x80542888; // type:object size:0x14 __vt__20mDvd_toMainRam_arc_c = .data:0x8054289C; // type:object size:0x14 __vt__21mDvd_toMainRam_base_c = .data:0x805428B0; // type:object size:0x14 __vt__22mDvd_mountMemArchive_c = .data:0x805428C4; // type:object size:0x14 -__vt__25mDvdCommandReadCallback_c = .data:0x805428D8; // type:object size:0x14 +__vt__15mDvd_callback_c = .data:0x805428D8; // type:object size:0x14 __vt__14mDvd_command_c = .data:0x805428EC; // type:object size:0x14 __vt__Q24mDvd41TUncompressInfo_c = .data:0x80542900; // type:object size:0x14 __vt__Q24mDvd42TUncompressInfo_c = .data:0x80542914; // type:object size:0x14 @@ -37570,8 +37570,8 @@ lbl_80571BF8 = .sdata:0x80571BF8; // type:object size:0x8 lbl_80571C00 = .sdata:0x80571C00; // type:object size:0x4 data:4byte lbl_80571C04 = .sdata:0x80571C04; // type:object size:0x4 data:4byte lbl_80571C08 = .sdata:0x80571C08; // type:object size:0x8 data:4byte -lbl_80571C10 = .sdata:0x80571C10; // type:object size:0x8 -lbl_80571C18 = .sdata:0x80571C18; // type:object size:0x8 +lbl_80571C10 = .sdata:0x80571C10; // type:object size:0x5 data:string +lbl_80571C18 = .sdata:0x80571C18; // type:object size:0x3 data:string lbl_80571C20 = .sdata:0x80571C20; // type:object size:0x8 data:string lbl_80571C28 = .sdata:0x80571C28; // type:object size:0x8 lbl_80571C30 = .sdata:0x80571C30; // type:object size:0x8 data:string @@ -39012,14 +39012,14 @@ lbl_80573F58 = .sdata:0x80573F58; // type:object size:0x8 lbl_80573F60 = .sdata:0x80573F60; // type:object size:0x8 lbl_80573F68 = .sdata:0x80573F68; // type:object size:0x8 data:4byte lbl_80573F70 = .sdata:0x80573F70; // type:object size:0x8 data:4byte -lbl_80573F78 = .sdata:0x80573F78; // type:object size:0x8 -lbl_80573F80 = .sdata:0x80573F80; // type:object size:0x8 -lbl_80573F88 = .sdata:0x80573F88; // type:object size:0x4 data:4byte -lbl_80573F8C = .sdata:0x80573F8C; // type:object size:0x8 -lbl_80573F94 = .sdata:0x80573F94; // type:object size:0x8 +lbl_80573F78 = .sdata:0x80573F78; // type:object size:0x5 data:string +lbl_80573F80 = .sdata:0x80573F80; // type:object size:0x6 data:string +sRelsDir__20DynamicModuleControl = .sdata:0x80573F88; // type:object size:0x4 data:4byte +lbl_80573F8C = .sdata:0x80573F8C; // type:object size:0x6 data:string +lbl_80573F94 = .sdata:0x80573F94; // type:object size:0x5 data:string lbl_80573F9C = .sdata:0x80573F9C; // type:object size:0x4 data:string -lbl_80573FA0 = .sdata:0x80573FA0; // type:object size:0x8 -lbl_80573FA8 = .sdata:0x80573FA8; // type:object size:0x8 +lbl_80573FA0 = .sdata:0x80573FA0; // type:object size:0x5 data:string +lbl_80573FA8 = .sdata:0x80573FA8; // type:object size:0x4 data:string lbl_80573FB0 = .sdata:0x80573FB0; // type:object size:0x4 data:4byte lbl_80573FB4 = .sdata:0x80573FB4; // type:object size:0x4 data:4byte m_rootUniqueID__7fBase_c = .sdata:0x80573FB8; // type:object size:0x4 data:4byte @@ -39689,13 +39689,13 @@ s_DrawControlFlags__7dBase_c = .sbss:0x805750C4; // type:object size:0x4 data:4b s_NextExecuteControlFlags__7dBase_c = .sbss:0x805750C8; // type:object size:0x4 data:4byte lbl_805750D0 = .sbss:0x805750D0; // type:object size:0x8 data:4byte lbl_805750D8 = .sbss:0x805750D8; // type:object size:0x8 data:4byte -lbl_805750E0 = .sbss:0x805750E0; // type:object size:0x4 data:4byte -lbl_805750E4 = .sbss:0x805750E4; // type:object size:0x4 data:4byte -lbl_805750E8 = .sbss:0x805750E8; // type:object size:0x4 data:4byte -lbl_805750EC = .sbss:0x805750EC; // type:object size:0x4 data:4byte -lbl_805750F0 = .sbss:0x805750F0; // type:object size:0x4 data:4byte -lbl_805750F4 = .sbss:0x805750F4; // type:object size:0x4 data:4byte -lbl_805750F8 = .sbss:0x805750F8; // type:object size:0x8 data:4byte +pDynamicNameTable = .sbss:0x805750E0; // type:object size:0x4 data:4byte +nDynamicNameTable = .sbss:0x805750E4; // type:object size:0x4 data:4byte +pDMC__4dDyl = .sbss:0x805750E8; // type:object size:0x4 data:4byte +nDMC__4dDyl = .sbss:0x805750EC; // type:object size:0x4 data:4byte +cCc_frmHeap__4dDyl = .sbss:0x805750F0; // type:object size:0x4 data:4byte +Initialized__4dDyl = .sbss:0x805750F4; // type:object size:0x1 data:byte +DVD__4dDyl = .sbss:0x805750F8; // type:object size:0x4 data:4byte lbl_80575100 = .sbss:0x80575100; // type:object size:0x8 data:byte lbl_80575108 = .sbss:0x80575108; // type:object size:0x8 data:byte lbl_80575110 = .sbss:0x80575110; // type:object size:0x8 data:4byte @@ -40231,14 +40231,14 @@ lbl_80575B68 = .sbss:0x80575B68; // type:object size:0x8 data:4byte lbl_80575B70 = .sbss:0x80575B70; // type:object size:0x8 data:4byte lbl_80575B78 = .sbss:0x80575B78; // type:object size:0x4 data:4byte lbl_80575B7C = .sbss:0x80575B7C; // type:object size:0x4 data:4byte -lbl_80575B80 = .sbss:0x80575B80; // type:object size:0x4 data:4byte -lbl_80575B84 = .sbss:0x80575B84; // type:object size:0x4 data:4byte -lbl_80575B88 = .sbss:0x80575B88; // type:object size:0x4 data:4byte -lbl_80575B8C = .sbss:0x80575B8C; // type:object size:0x4 data:4byte -lbl_80575B90 = .sbss:0x80575B90; // type:object size:0x4 data:4byte -lbl_80575B94 = .sbss:0x80575B94; // type:object size:0x4 data:4byte -lbl_80575B98 = .sbss:0x80575B98; // type:object size:0x4 data:4byte -lbl_80575B9C = .sbss:0x80575B9C; // type:object size:0x4 data:4byte +mFirst__24DynamicModuleControlBase = .sbss:0x80575B80; // type:object size:0x4 data:4byte +mLast__24DynamicModuleControlBase = .sbss:0x80575B84; // type:object size:0x4 data:4byte +sAllocBytes__20DynamicModuleControl = .sbss:0x80575B88; // type:object size:0x4 data:4byte +sDvdFile__20DynamicModuleControl = .sbss:0x80575B8C; // type:object size:0x4 data:4byte +sDylinkHeap__20DynamicModuleControl = .sbss:0x80575B90; // type:object size:0x4 data:4byte +sCurrentAllocatableSize__20DynamicModuleControl = .sbss:0x80575B94; // type:object size:0x4 data:4byte +sTotalFreeSize__20DynamicModuleControl = .sbss:0x80575B98; // type:object size:0x4 data:4byte +sArchive__20DynamicModuleControl = .sbss:0x80575B9C; // type:object size:0x4 data:4byte lbl_80575BA0 = .sbss:0x80575BA0; // type:object size:0x8 data:4byte m_forceExecuteList__7fBase_c = .sbss:0x80575BA8; // type:object size:0x8 data:4byte sLoadAsyncCallback__7fBase_c = .sbss:0x80575BB0; // type:object size:0x4 data:4byte diff --git a/configure.py b/configure.py index 30824191..d5e19ed9 100644 --- a/configure.py +++ b/configure.py @@ -281,6 +281,9 @@ config.libs = [ Object(Matching, "c/c_list.cpp"), Object(Matching, "c/c_tree.cpp"), Object(Matching, "d/d_base.cpp"), + Object(Matching, "d/d_dvd.cpp"), + Object(NonMatching, "d/d_dvd_unk.cpp"), + Object(NonMatching, "d/d_dylink.cpp"), Object(NonMatching, "d/d_heap.cpp"), Object(NonMatching, "d/d_stage.cpp"), Object(NonMatching, "d/d_sys.cpp"), @@ -304,6 +307,7 @@ config.libs = [ Object(NonMatching, "m/m_dvd.cpp"), Object(Matching, "m/m_heap.cpp"), Object(NonMatching, "m/m_mtx.cpp"), + Object(Matching, "DynamicLink.cpp"), # framework (f_name) # d stuff (d_name) ], diff --git a/include/DynamicLink.h b/include/DynamicLink.h new file mode 100644 index 00000000..109f4821 --- /dev/null +++ b/include/DynamicLink.h @@ -0,0 +1,96 @@ +#ifndef DYNAMICLINK_H +#define DYNAMICLINK_H + +#include +#include +#include + +class DbMapFile { +public: + DbMapFile(): unk_0(0) {} + ~DbMapFile(); + + void RegisterOnDvd(const char *, const OSModuleInfo *); + void Unregister(); +private: + UNKWORD unk_0; +}; + +// https://github.com/zeldaret/tp/blob/main/include/DynamicLink.h + +struct DynamicModuleControlBase { + /* 0x00 */ u16 mLinkCount; + /* 0x02 */ u16 mDoLinkCount; + /* 0x04 */ DynamicModuleControlBase* mPrev; + /* 0x08 */ DynamicModuleControlBase* mNext; + + /* 0x0C */ /*vtable*/ + /* 802df100 */ virtual ~DynamicModuleControlBase(); + /* 802df340 */ virtual const char* getModuleName() const; + /* 802df350 */ virtual int getModuleSize() const; + /* 802df360 */ virtual const char* getModuleTypeString() const; + /* 802df370 */ virtual void dump(); + /* 802df380 */ virtual bool do_load(); + /* 802df390 */ virtual BOOL do_load_async(); + /* 802df3a0 */ virtual bool do_unload(); + /* 802df3b0 */ virtual BOOL do_link(); + /* 802df3c0 */ virtual bool do_unlink(); + /* 802df1a0 */ DynamicModuleControlBase(); + /* 802df1f0 */ BOOL link(); + /* 802df290 */ BOOL unlink(); + /* 802df310 */ BOOL load_async(); + + static inline DynamicModuleControlBase* getFirstClass() { return mFirst; } + inline DynamicModuleControlBase* getNextClass() { return mNext; } + bool isLinked() const { return mLinkCount != 0; } + + static DynamicModuleControlBase* mFirst; + static DynamicModuleControlBase* mLast; +}; + +struct DynamicModuleControl : DynamicModuleControlBase { + /* 802df4c0 */ virtual const char* getModuleName() const; + /* 802df450 */ virtual ~DynamicModuleControl(); + /* 802dfb10 */ virtual int getModuleSize() const; + /* 802dfb70 */ virtual const char* getModuleTypeString() const; + /* 802df800 */ virtual void dump(); + /* 802df5d0 */ virtual bool do_load(); + /* 802df710 */ virtual BOOL do_load_async(); + /* 802df7a0 */ virtual bool do_unload(); + /* 802df810 */ virtual BOOL do_link(); + /* 802dfa60 */ virtual bool do_unlink(); + /* 802df3d0 */ DynamicModuleControl(char const*, EGG::ExpHeap *); + /* 802df4d0 */ static void initialize(EGG::ExpHeap *heap); + /* 802df530 */ static bool callback(void*); + void checkHeapStatus(); + + /* 0x10 */ UNKWORD unk_16; + /* 0x14 */ OSModuleHeader *mModule; + /* 0x18 */ void *mBss; + /* 0x1C */ UNKWORD unk_24; + /* 0x20 */ const char *mName; + /* 0x24 */ u8 mResourceType; + /* 0x25 */ u8 unk_33; + /* 0x28 */ UNKWORD unk_40; + /* 0x2C */ mDvd_callback_c *mDvdCallbackRequest; + /* 0x30 */ EGG::ExpHeap *mHeap; + /* 0x34 */ DbMapFile mpRelMapFile; + // Some of these might be members of DbMapFile + UNKWORD unk1; + UNKWORD unk2; + UNKWORD unk3; + UNKWORD unk4; + UNKWORD unk5; + UNKWORD unk6; + + static u32 sAllocBytes; + static mDvd_toMainRam_base_c *sDvdFile; + static EGG::ExpHeap *sDylinkHeap; + static u32 sCurrentAllocatableSize; + static u32 sTotalFreeSize; + static EGG::Archive *sArchive; + + static const char *sRelsDir; +}; + +#endif diff --git a/include/d/d_dvd.h b/include/d/d_dvd.h new file mode 100644 index 00000000..56fb848c --- /dev/null +++ b/include/d/d_dvd.h @@ -0,0 +1,41 @@ +#ifndef D_DVD_H +#define D_DVD_H + +#include +#include +#include + +namespace dDvd { + +// difference to NSMBW: additional heap arg +void create(s32 priority, EGG::Heap*, EGG::Heap*, EGG::Heap*); + +class loader_c { +public: + loader_c(); + /** vtable at 0x805033F0 */ + virtual ~loader_c(); + void *request(const char *path, u8 mountDirection, EGG::Heap *heap); + virtual void remove(); + +private: + u32 mSize; + mDvd_toMainRam_normal_c *mpCommand; + EGG::Heap* mpHeap; + void* mpBuffer; +}; + +class unkstruct_c { +public: + static unkstruct_c *create(EGG::Heap *heap); + void init(); + char getUnk(); + +private: + UNKWORD field_0x0; + char field_0x4; +}; + +} // dDvd + +#endif diff --git a/include/d/d_dvd_unk.h b/include/d/d_dvd_unk.h new file mode 100644 index 00000000..080a6eb6 --- /dev/null +++ b/include/d/d_dvd_unk.h @@ -0,0 +1,26 @@ +#ifndef D_DVD_UNK_H +#define D_DVD_UNK_H + +#include +#include + +namespace dDvdUnk { + +class unkstruct_c { +public: + static unkstruct_c *create(EGG::Heap *heap); + void draw(); + void execute(); + void init(); + char getUnk(); + + static void createFont(EGG::Heap *heap); + +private: + UNKWORD field_0x0; + char field_0x4; +}; + +} // dDvdUnk + +#endif diff --git a/include/d/d_dylink.h b/include/d/d_dylink.h new file mode 100644 index 00000000..c7a0a6a2 --- /dev/null +++ b/include/d/d_dylink.h @@ -0,0 +1,12 @@ +#ifndef D_DYLINK_H +#define D_DYLINK_H + +#include + +namespace dDyl { + +bool Unlink(u16 relId); + +} // dDyl + +#endif diff --git a/include/m/m_dvd.h b/include/m/m_dvd.h index dee59241..86be5449 100644 --- a/include/m/m_dvd.h +++ b/include/m/m_dvd.h @@ -1,6 +1,8 @@ #ifndef M_DVD_H #define M_DVD_H +#include +#include #include #include #include @@ -64,19 +66,19 @@ public: u8 mCompressionType; }; -typedef void *(*dvdReadCallback)(void *); +typedef bool (*dvdReadCallback)(void *); -class mDvdCommandReadCallback_c : public mDvd_command_c { +class mDvd_callback_c : public mDvd_command_c { public: - mDvdCommandReadCallback_c(dvdReadCallback cb, void *cbData); - virtual ~mDvdCommandReadCallback_c(); + mDvd_callback_c(dvdReadCallback cb, void *cbData); + virtual ~mDvd_callback_c(); virtual u32 execute() override; - static mDvdCommandReadCallback_c *create(dvdReadCallback cb, void *cbData); + static mDvd_callback_c *create(dvdReadCallback cb, void *cbData); dvdReadCallback mCallback; void *mCallbackData; - void *mDataPtr; + BOOL mSuccess; }; class mDvd_mountMemArchive_c : public mDvd_command_c { @@ -176,4 +178,8 @@ public: }; } // namespace mDvd +extern "C" void fn_802EF480(mDvd_command_c *cmd); +extern "C" mDvd_toMainRam_normal_c *fn_802F0030(const char *path, int mountDirection, EGG::Heap *heap); +extern "C" mDvd_toMainRam_arc_c *fn_802EFE90(EGG::Archive *arc, const char *path, int mountDirection, EGG::Heap *heap); + #endif diff --git a/include/rvl/OS/OSLink.h b/include/rvl/OS/OSLink.h index 0736a590..aa2a86cf 100644 --- a/include/rvl/OS/OSLink.h +++ b/include/rvl/OS/OSLink.h @@ -1,13 +1,112 @@ -#ifndef RVL_SDK_OS_LINK_H -#define RVL_SDK_OS_LINK_H -#include +#ifndef OSLINK_H +#define OSLINK_H + + #ifdef __cplusplus extern "C" { #endif +#define OS_MODULE_VERSION 3 + +typedef struct OSModuleHeader OSModuleHeader; + +typedef u32 OSModuleID; +typedef struct OSModuleQueue OSModuleQueue; +typedef struct OSModuleLink OSModuleLink; +typedef struct OSModuleInfo OSModuleInfo; +typedef struct OSSectionInfo OSSectionInfo; +typedef struct OSImportInfo OSImportInfo; +typedef struct OSRel OSRel; + +// OSModuleQueue __OSModuleList : 0x800030C8; +// void* __OSStringTable : 0x800030D0; +extern OSModuleQueue __OSModuleList; +extern void * __OSStringTable; + +struct OSModuleQueue { + OSModuleInfo* head; + OSModuleInfo* tail; +}; + +struct OSModuleLink { + OSModuleInfo* next; + OSModuleInfo* prev; +}; + +struct OSSectionInfo { + u32 offset; + u32 size; +}; + +struct OSModuleInfo { + OSModuleID id; // unique identifier for the module + OSModuleLink link; // doubly linked list of modules + u32 numSections; // # of sections + u32 sectionInfoOffset; // offset to section info table + u32 nameOffset; // offset to module name + u32 nameSize; // size of module name + u32 version; // version number +}; + +struct OSModuleHeader { + // CAUTION: info must be the 1st member + OSModuleInfo info; + + // OS_MODULE_VERSION == 1 + u32 bssSize; // total size of bss sections in bytes + u32 relOffset; + u32 impOffset; + u32 impSize; // size in bytes + u8 prologSection; // section # for prolog function + u8 epilogSection; // section # for epilog function + u8 unresolvedSection; // section # for unresolved function + u8 bssSection; // section # for bss section (set at run-time) + u32 prolog; // prolog function offset + u32 epilog; // epilog function offset + u32 unresolved; // unresolved function offset + + // OS_MODULE_VERSION == 2 +#if (2 <= OS_MODULE_VERSION) + u32 align; // module alignment constraint + u32 bssAlign; // bss alignment constraint +#endif + + // OS_MODULE_VERSION == 3 +#if (3 <= OS_MODULE_VERSION) + u32 fixSize; +#endif +}; + +#define OSGetSectionInfo(module) ((OSSectionInfo*)(((OSModuleInfo*)(module))->sectionInfoOffset)) + +#define OS_SECTIONINFO_EXEC 0x1 +#define OS_SECTIONINFO_OFFSET(offset) ((offset) & ~0x1) + +struct OSImportInfo { + OSModuleID id; // external module id + u32 offset; // offset to OSRel instructions +}; + +struct OSRel { + u16 offset; // byte offset from the previous entry + u8 type; + u8 section; + u32 addend; +}; + +#define R_DOLPHIN_NOP 201 // C9h current offset += OSRel.offset +#define R_DOLPHIN_SECTION 202 // CAh current section = OSRel.section +#define R_DOLPHIN_END 203 // CBh +#define R_DOLPHIN_MRKREF 204 // CCh + +BOOL OSLink(OSModuleInfo* newModule, void* bss); +BOOL OSLinkFixed(OSModuleInfo* newModule, void* bss); +BOOL OSUnlink(OSModuleInfo* module); +void OSSetStringTable(void* string_table); void __OSModuleInit(void); #ifdef __cplusplus -} -#endif +}; #endif + +#endif /* OSLINK_H */ diff --git a/src/DynamicLink.cpp b/src/DynamicLink.cpp new file mode 100644 index 00000000..2898ab14 --- /dev/null +++ b/src/DynamicLink.cpp @@ -0,0 +1,373 @@ +#include + +DynamicModuleControlBase *DynamicModuleControlBase::mFirst; +DynamicModuleControlBase *DynamicModuleControlBase::mLast; + +DynamicModuleControlBase::~DynamicModuleControlBase() { + if (mPrev != nullptr) { + mPrev->mNext = mNext; + } + if (mNext != nullptr) { + mNext->mPrev = mPrev; + } + if (mFirst == this) { + mFirst = mNext; + } + if (mLast == this) { + mLast = mPrev; + } + mNext = nullptr; + mPrev = nullptr; +} + +DynamicModuleControlBase::DynamicModuleControlBase() { + mLinkCount = 0; + mDoLinkCount = 0; + mNext = nullptr; + if (mFirst == nullptr) { + mFirst = this; + } + DynamicModuleControlBase *last = mLast; + mPrev = last; + if (last != nullptr) { + last->mNext = this; + } + mLast = this; +} + +BOOL DynamicModuleControlBase::link() { + if (mLinkCount == 0) { + do_load(); + if (!do_link()) { + return false; + } + + if (mDoLinkCount < 0xFFFF) { + mDoLinkCount++; + } + } + + if (mLinkCount < 0xFFFF) { + mLinkCount++; + } + + return true; +} + +BOOL DynamicModuleControlBase::unlink() { + if (mLinkCount != 0) { + if (mLinkCount < 0xFFFF && --mLinkCount == 0) { + do_unlink(); + do_unload(); + } + } + + return true; +} + +BOOL DynamicModuleControlBase::load_async() { + if (mLinkCount == 0) { + return do_load_async(); + } + return true; +} + +const char *DynamicModuleControlBase::getModuleName() const { + return nullptr; +} + +int DynamicModuleControlBase::getModuleSize() const { + return 0; +} + +const char *DynamicModuleControlBase::getModuleTypeString() const { + return "Base"; +} + +void DynamicModuleControlBase::dump() {} + +bool DynamicModuleControlBase::do_load() { + return true; +} + +BOOL DynamicModuleControlBase::do_load_async() { + return true; +} + +bool DynamicModuleControlBase::do_unload() { + return true; +} + +BOOL DynamicModuleControlBase::do_link() { + return true; +} + +bool DynamicModuleControlBase::do_unlink() { + return true; +} + +u32 DynamicModuleControl::sAllocBytes; +mDvd_toMainRam_base_c *DynamicModuleControl::sDvdFile; +EGG::ExpHeap *DynamicModuleControl::sDylinkHeap; +u32 DynamicModuleControl::sCurrentAllocatableSize; +u32 DynamicModuleControl::sTotalFreeSize; +EGG::Archive *DynamicModuleControl::sArchive; + +DynamicModuleControl::DynamicModuleControl(const char *name, EGG::ExpHeap *heap) + : mModule(nullptr), mBss(nullptr), unk_24(0), mName(name), mResourceType(0), unk_33(0), unk_40(0), + mDvdCallbackRequest(0), mHeap(heap), mpRelMapFile() {} + +DynamicModuleControl::~DynamicModuleControl() {} + +const char *DynamicModuleControl::getModuleName() const { + return mName; +} + +void DynamicModuleControl::initialize(EGG::ExpHeap *heap) { + sDylinkHeap = heap; + sCurrentAllocatableSize = heap->getAllocatableSize(4); + sTotalFreeSize = heap->getTotalFreeSize(); +} + +bool DynamicModuleControl::callback(void *arg) { + return static_cast(arg)->do_load(); +} + +void DynamicModuleControl::checkHeapStatus() { + if (mHeap == sDylinkHeap) { + int size = mHeap->getAllocatableSize(4); + if (sCurrentAllocatableSize > size) { + sCurrentAllocatableSize = size; + } + size = mHeap->getTotalFreeSize(); + if (sTotalFreeSize > size) { + sTotalFreeSize = size; + } + } +} + +const char *DynamicModuleControl::sRelsDir = "/rels"; + +bool DynamicModuleControl::do_load() { + char buf[64]; + if (mModule != nullptr) { + return true; + } + if (mHeap == nullptr) { + mHeap = sDylinkHeap; + } + snprintf(buf, sizeof(buf), "%s/%sNP.rel", sRelsDir, mName); + if (mModule == nullptr) { + if (sArchive != nullptr) { + sDvdFile = fn_802EFE90(sArchive, buf, 1, mHeap); + } else { + sDvdFile = fn_802F0030(buf, 1, mHeap); + } + + if (sDvdFile != nullptr) { + sDvdFile->waitUntilDone(); + checkHeapStatus(); + void *ptr = sDvdFile->mDataPtr; + sDvdFile->mDataPtr = nullptr; + mModule = static_cast(ptr); + fn_802EF480(sDvdFile); + sDvdFile = nullptr; + if (mModule != nullptr) { + unk_40 = 0; + mResourceType = 3; + } + } + } + + if (mModule == nullptr) { + return false; + } + if (unk_33 < 0xFF) { + unk_33++; + } + checkHeapStatus(); + return true; +} + +BOOL DynamicModuleControl::do_load_async() { + if (mDvdCallbackRequest == nullptr) { + if (mModule != nullptr) { + return true; + } + mDvdCallbackRequest = mDvd_callback_c::create(callback, this); + } + + if (mDvdCallbackRequest != nullptr && mDvdCallbackRequest->mStatus != 0) { + fn_802EF480(mDvdCallbackRequest); + mDvdCallbackRequest = nullptr; + return true; + } else { + return false; + } +} + +bool DynamicModuleControl::do_unload() { + if (mModule != nullptr) { + mHeap->free(mModule); + mModule = nullptr; + } + + return true; +} + +void DynamicModuleControl::dump() {} + +BOOL DynamicModuleControl::do_link() { + char mapPath[64]; + + if (mModule != nullptr) { + int alignedFixSize = ROUND_UP(mModule->fixSize, 0x20); + int alignedFixPtr = (int)&mModule->info + alignedFixSize; + int totalSize = EGG::ExpHeap::getSizeForMBlock(mModule); + BOOL result; + if (totalSize == 0) { + void *bss = mHeap->alloc(mModule->bssSize, 0x20); + if (bss == nullptr) { + goto error; + } + mBss = bss; + result = OSLink(&mModule->info, bss); + if (!result) { + goto error; + } + } else { + if (alignedFixSize + mModule->bssSize < totalSize) { + result = OSLinkFixed(&mModule->info, (void *)alignedFixPtr); + if (!result) { + goto error; + } + mHeap->resizeForMBlock(mModule, alignedFixSize + mModule->bssSize); + } else if ((int)mHeap->resizeForMBlock(mModule, alignedFixSize + mModule->bssSize) > 0) { + // TODO resizeForMBlock should maybe return int? + result = OSLinkFixed(&mModule->info, (void *)alignedFixPtr); + if (!result) { + goto error; + } + } else { + void *bss = mHeap->alloc(mModule->bssSize, 0x20); + if (!bss) { + goto error; + } + mBss = bss; + result = OSLinkFixed(&mModule->info, bss); + if (!result) { + goto error; + } + mHeap->resizeForMBlock(mModule, alignedFixSize); + } + } + + sAllocBytes = sAllocBytes + getModuleSize(); + snprintf(mapPath, sizeof(mapPath), "%s/%sNP.map", "/maps", mName); + mpRelMapFile.RegisterOnDvd(mapPath, &mModule->info); + unk_24 = ((UNKWORD(*)())mModule->prolog)(); + checkHeapStatus(); + return true; + } + +error: + unk_33 = 0; + if (mBss != nullptr) { + mHeap->free(mBss); + mBss = nullptr; + } + if (mModule != nullptr) { + mHeap->free(mModule); + mModule = nullptr; + } + return false; +} + +bool DynamicModuleControl::do_unlink() { + ((void (*)())mModule->epilog)(); + mpRelMapFile.Unregister(); + if (!OSUnlink(&mModule->info)) { + return false; + } + sAllocBytes -= getModuleSize(); + if (mBss != nullptr) { + mHeap->free(mBss); + mBss = nullptr; + } + return true; +} + +int DynamicModuleControl::getModuleSize() const { + if (mModule != nullptr) { + int size = EGG::ExpHeap::getSizeForMBlock(mModule); + if (mBss != nullptr) { + size += mModule->bssSize; + } + + return size; + } + return 0; +} + +const char *DynamicModuleControl::getModuleTypeString() const { + static const char *REL_LOAD_TYPES[4] = { + "????", + "MEM", + "ARAM", + "DVD", + }; + return REL_LOAD_TYPES[mResourceType & 3]; +} + +DbMapFile::~DbMapFile() { + if (unk_0) { + Unregister(); + } +} + +namespace nw4r { +namespace db { +// TODO +typedef struct MapFile { +} MapFile; +extern MapFile *MapFile_RegistOnDvd(void *arg, const char *buf, const OSModuleInfo *info); +extern void *MapFile_Unregist(MapFile *); +} // namespace db +} // namespace nw4r + +void DbMapFile::RegisterOnDvd(const char *path, const OSModuleInfo *info) { + if (mDvd::IsExistPath(path)) { + unk_0 = (UNKWORD)nw4r::db::MapFile_RegistOnDvd(((int *)this) + 1, path, info); + } else { + unk_0 = 0xffffffff; + } +} + +void DbMapFile::Unregister() { + if (unk_0 != 0) { + if (unk_0 != 0xffffffff) { + nw4r::db::MapFile_Unregist((nw4r::db::MapFile *)unk_0); + } + unk_0 = 0; + } +} +/* +// probably part of a different file +extern "C" void ModuleProlog() {} + +extern "C" void ModuleEpilog() {} + +extern "C" void ModuleUnresolved() {} + +extern "C" void ModuleConstructorsX(void (**ptrs)()) { + for (; *ptrs != nullptr; ptrs++) { + (*ptrs)(); + } +} + +extern "C" void ModuleDestructorsX(void (**ptrs)()) { + for (; *ptrs != nullptr; ptrs++) { + (*ptrs)(); + } +} +*/ diff --git a/src/d/d_dvd.cpp b/src/d/d_dvd.cpp new file mode 100644 index 00000000..afe8d10f --- /dev/null +++ b/src/d/d_dvd.cpp @@ -0,0 +1,62 @@ +#include +#include + +namespace dDvd { + +/** 800520f0 */ +void create(s32 priority, EGG::Heap *archiveHeap, EGG::Heap *commandHeap, EGG::Heap *threadHeap) { + mDvd::create(priority, archiveHeap, commandHeap, threadHeap); +} + +/** 80052100 */ +loader_c::loader_c() { + mpCommand = nullptr; + mSize = -1; + mpHeap = nullptr; + mpBuffer = nullptr; +} + +/** 80052130 */ +loader_c::~loader_c() {} + +// sprintf2 +extern "C" void fn_8003D650(char *out, const char *fmt, ...); + +/** 80052170 */ +void *loader_c::request(const char *path, u8 mountDirection, EGG::Heap *heap) { + char buf[128]; + + if (mpBuffer != nullptr) { + return mpBuffer; + } + if (mpCommand == 0) { + mSize = -1; + mpHeap = heap != nullptr ? heap : mDvd::getArchiveHeap(); + buf[0] = '\0'; + fn_8003D650(buf, "US%s", path); + if (!mDvd::IsExistPath(buf)) { + fn_8003D650(buf, "%s", path); + } + mpCommand = mDvd_toMainRam_normal_c::create(buf, mountDirection, heap); + } + if (mpCommand != nullptr && mpCommand->mStatus != 0) { + mpBuffer = mpCommand->mDataPtr; + mSize = mpCommand->mAmountRead; + mpCommand->mDataPtr = nullptr; + fn_802EF480(mpCommand); + mpCommand = nullptr; + return mpBuffer; + } else { + return nullptr; + } +} + +/** 800522a0 */ +void loader_c::remove() { + if (mpHeap != nullptr && mpBuffer != nullptr) { + mpHeap->free(mpBuffer); + mpBuffer = nullptr; + } +} + +} // namespace dDvd diff --git a/src/d/d_dvd_unk.cpp b/src/d/d_dvd_unk.cpp new file mode 100644 index 00000000..b4ab12d4 --- /dev/null +++ b/src/d/d_dvd_unk.cpp @@ -0,0 +1,44 @@ +#include +#include +#include + +namespace dDvdUnk { + +/** 805750d0 */ +static unkstruct_c *singleton; + +static nw4r::ut::ResFont *fontPtr; + +/** 80052300 */ +unkstruct_c *unkstruct_c::create(EGG::Heap *heap) { + singleton = new (heap, 0x04) unkstruct_c(); + singleton->init(); +} + +/** 80052340 */ +char unkstruct_c::getUnk() { + return field_0x4; +} + +/** 80052350 */ +void unkstruct_c::draw() { + // EGG:: +} + +/** 800526b0 */ +void unkstruct_c::execute() { + +} + +/** 80052750 */ +void unkstruct_c::init() { + field_0x0 = 0; + field_0x4 = 0; +} + + +void unkstruct_c::createFont(EGG::Heap *heap) { + fontPtr = new (heap, 0x04) nw4r::ut::ResFont(); +} + +} // namespace dDvdUnk diff --git a/src/d/d_dylink.cpp b/src/d/d_dylink.cpp new file mode 100644 index 00000000..a0e742d0 --- /dev/null +++ b/src/d/d_dylink.cpp @@ -0,0 +1,130 @@ +#include +#include +#include +#include +// clang-format off +#include +// clang-format on + +struct RelNamePtr { + u16 relId; + const char *name; +}; + +struct DynamicModuleControl { + u16 loadCount; + + DynamicModuleControl *mpPrev; + DynamicModuleControl *mpNext; + + DynamicModuleControl(const char *name, EGG::Heap *heap); + virtual ~DynamicModuleControl(); + virtual const char *getModuleName(); + virtual UNKWORD getModuleSize(); + virtual const char *getModuleTypeString(); + virtual void dump(); + virtual bool do_load(); + virtual bool do_load_async(); + virtual bool do_unload(); + virtual bool do_link(); + virtual bool do_unlink(); + + bool link(); + bool unlink(); + bool load_async(); + + void *rel; + void *bss; + bool dataFromProlog; + const char *name; + bool includesType; + mDvd_callback_c *dvdCallbackRequest; + EGG::Heap *heap; + bool relMapFile; + UNKWORD unk1; + UNKWORD unk2; + UNKWORD unk3; + UNKWORD unk4; + UNKWORD unk5; + UNKWORD unk6; +}; + +static RelNamePtr *pDynamicNameTable; +static int nDynamicNameTable; + +namespace dDyl { + +DynamicModuleControl **pDMC; +int nDMC; +EGG::Heap *cCc_frmHeap; +u32 Initialized; +mDvd_callback_c *DVD; + +// initDylinkHeap +extern "C" int fn_80052E00(int maxRelId, RelNamePtr *dynNameTable, int dynNameTableNum, EGG::Heap *parentHeap) { + cCc_frmHeap = mHeap::createFrmHeap(maxRelId * 0x10 + dynNameTableNum * 0x48, parentHeap, + "ダイナミックリンク制御用ヒープ(dDyl::cCc_frmHeap)", 0x20, 0); + + mHeap _guard(cCc_frmHeap); + + nDMC = maxRelId; + pDMC = new DynamicModuleControl *[maxRelId](); + memset(pDMC, 0, sizeof(void *) * nDMC); + + pDynamicNameTable = dynNameTable; + nDynamicNameTable = dynNameTableNum; + + for (int i = 0; i < nDynamicNameTable; i++) { + RelNamePtr *rel = &pDynamicNameTable[i]; + if (rel->name != nullptr) { + for (int j = 0; j < nDMC; j++) { + DynamicModuleControl **dmc = &pDMC[j]; + if (*dmc != nullptr) { + const char *nm = (*dmc)->getModuleName(); + if (!strcmp(rel->name, nm)) { + pDMC[rel->relId] = pDMC[j]; + break; + } + } + } + if (pDMC[rel->relId] == nullptr) { + pDMC[rel->relId] = new DynamicModuleControl(rel->name, nullptr); + } + } + } + cCc_frmHeap->adjust(); + return 1; +} + +// isLoaded? +extern "C" bool fn_80052FA0(u16 relId) { + return pDMC[relId] != nullptr ? (bool)pDMC[relId]->loadCount : true; +} + +bool dDyl::Unlink(u16 relId) { + DynamicModuleControl *dmc = pDMC[relId]; + if (dmc != nullptr) { + return dmc->unlink(); + } + + return false; +} + +extern "C" int fn_80052FF0(u16 relId) { + if (!Initialized) { + return 0; + } + + DynamicModuleControl *dmc = pDMC[relId]; + if (dmc != nullptr) { + if (dmc->load_async()) { + return (bool)dmc->link() + 2; + } else { + return 0; + } + } else { + return 1; + } +} + +} // namespace dDyl diff --git a/src/m/m_dvd.cpp b/src/m/m_dvd.cpp index ef4819d2..a4c9ff04 100644 --- a/src/m/m_dvd.cpp +++ b/src/m/m_dvd.cpp @@ -324,19 +324,18 @@ void mDvd_command_c::destroy(mDvd_command_c **cmd) { } /** 802ef500 */ -mDvdCommandReadCallback_c::~mDvdCommandReadCallback_c() {} +mDvd_callback_c::~mDvd_callback_c() {} /** 802ef560 */ -mDvdCommandReadCallback_c::mDvdCommandReadCallback_c(dvdReadCallback cb, void *cbData) { +mDvd_callback_c::mDvd_callback_c(dvdReadCallback cb, void *cbData) { mCallback = cb; mCallbackData = cbData; - mDataPtr = nullptr; + mSuccess = false; } /* 802ef5d0 */ -mDvdCommandReadCallback_c *mDvdCommandReadCallback_c::create(dvdReadCallback cb, void *cbData) { - // TODO instshuffle - mDvdCommandReadCallback_c *cmd = new mDvdCommandReadCallback_c(cb, cbData); +mDvd_callback_c *mDvd_callback_c::create(dvdReadCallback cb, void *cbData) { + mDvd_callback_c *cmd = new mDvd_callback_c(cb, cbData); if (cmd != nullptr) { mDvd_param_c::mInstance->addCommand(cmd); } @@ -344,17 +343,17 @@ mDvdCommandReadCallback_c *mDvdCommandReadCallback_c::create(dvdReadCallback cb, } /** 802ef650 */ -extern "C" mDvdCommandReadCallback_c *fn_802EF650(dvdReadCallback cb, void *cbData) { - mDvdCommandReadCallback_c *cmd = mDvdCommandReadCallback_c::create(cb, cbData); +extern "C" mDvd_callback_c *fn_802EF650(dvdReadCallback cb, void *cbData) { + mDvd_callback_c *cmd = mDvd_callback_c::create(cb, cbData); while (!cmd) {} return cmd; } /** 802ef680 */ -u32 mDvdCommandReadCallback_c::execute() { - mDataPtr = (mCallback)(mCallbackData); +u32 mDvd_callback_c::execute() { + mSuccess = (mCallback)(mCallbackData); waitDone(); - return (bool)mDataPtr; + return (bool)mSuccess; } /** 802ef6e0 */