Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decomp: DvdArchive [WIP] #188

Merged
merged 1 commit into from
Jun 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pack/rel_objects.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ out/rel/data_808b2bd0_808b2c30.o
out/rel/bss_809bd6e0_809bd6e8.o
out/JmpResourceCourse.o
out/rel/text_805127ec_80518cc0.o
out/rel/data_808b2c3c_808b2c78.o
out/DvdArchive.o
out/rel/text_80519670_8051c088.o
out/rel/data_808b2c3c_808b2d38.o
out/rel/data_808b2c88_808b2d38.o
out/GhostFile.o
out/rel/text_8051d4d4_8052a098.o
out/MultiDvdArchive.o
Expand Down
2 changes: 1 addition & 1 deletion pack/rel_slices.csv
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
enabled,name,textStart,textEnd,ctorsStart,ctorsEnd,dtorsStart,dtorsEnd,rodataStart,rodataEnd,dataStart,dataEnd,bssStart,bssEnd
1,source/game/jmap/JmpResourceCourse.cpp,0x80512694,0x805127ec,,,,,,,0x808B2C30,0x808B2C3C,0x809BD6E8,0x809BD6EC
1,source/game/system/DvdArchive.cpp,0x80518CC0,0x80519670,,,,,,,,,,
1,source/game/system/DvdArchive.cpp,0x80518CC0,0x80519670,,,,,,,0x808B2C78,0x808B2C88,,
1,source/game/system/GhostFile.cpp,0x8051c088,0x8051d4d4,,,,,,,0x808b2d38,0x808b2d50,,
1,source/game/system/MultiDvdArchive.cpp,0x8052a098,0x8052ae5c,,,,,,,,,,
1,source/game/util/Random.cpp,0x80555464,0x8055572c,,,,,0x80891370,0x80891380,0x808b42e0,0x808b42ec,,
Expand Down
101 changes: 16 additions & 85 deletions source/game/system/DvdArchive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,93 +4,24 @@
// PAL: 0x805553b0
extern UNKNOWN_FUNCTION(unk_805553b0);

// Symbol: DvdArchive_ct
// PAL: 0x80518cc0..0x80518cf4
MARK_BINARY_BLOB(DvdArchive_ct, 0x80518cc0, 0x80518cf4);
asm UNKNOWN_FUNCTION(DvdArchive_ct) {
// clang-format off
nofralloc;
lis r4, 0;
li r0, 0;
addi r4, r4, 0;
stw r4, 0(r3);
stw r0, 4(r3);
stw r0, 8(r3);
stw r0, 0xc(r3);
stw r0, 0x10(r3);
stw r0, 0x14(r3);
stw r0, 0x18(r3);
stw r0, 0x1c(r3);
stw r0, 0x20(r3);
blr;
// clang-format on
DvdArchive::DvdArchive() {
mArchive = nullptr;
mArchiveStart = nullptr;
mArchiveSize = NULL;
mArchiveHeap = nullptr;
mFileStart = nullptr;
mFileSize = NULL;
mFileHeap = nullptr;
mStatus = DVD_ARCHIVE_STATE_CLEARED;
}

// Symbol: DvdArchive_dt
// PAL: 0x80518cf4..0x80518dcc
MARK_BINARY_BLOB(DvdArchive_dt, 0x80518cf4, 0x80518dcc);
asm UNKNOWN_FUNCTION(DvdArchive_dt) {
// clang-format off
nofralloc;
stwu r1, -0x10(r1);
mflr r0;
cmpwi r3, 0;
stw r0, 0x14(r1);
stw r31, 0xc(r1);
mr r31, r4;
stw r30, 8(r1);
mr r30, r3;
beq lbl_80518db0;
lwz r0, 0x20(r3);
lis r4, 0;
addi r4, r4, 0;
stw r4, 0(r3);
cmpwi r0, 4;
bne lbl_80518d38;
lwz r3, 4(r3);
bl unk_805553b0;
lbl_80518d38:
lwz r4, 8(r30);
cmpwi r4, 0;
beq lbl_80518d68;
lwz r3, 0x10(r30);
lwz r12, 0(r3);
lwz r12, 0x18(r12);
mtctr r12;
bctrl;
li r0, 0;
stw r0, 8(r30);
stw r0, 0xc(r30);
stw r0, 0x10(r30);
lbl_80518d68:
lwz r4, 0x14(r30);
cmpwi r4, 0;
beq lbl_80518d98;
lwz r3, 0x1c(r30);
lwz r12, 0(r3);
lwz r12, 0x18(r12);
mtctr r12;
bctrl;
li r0, 0;
stw r0, 0x14(r30);
stw r0, 0x18(r30);
stw r0, 0x1c(r30);
lbl_80518d98:
cmpwi r31, 0;
li r0, 0;
stw r0, 0x20(r30);
ble lbl_80518db0;
mr r3, r30;
bl unk_805553b0;
lbl_80518db0:
mr r3, r30;
lwz r31, 0xc(r1);
lwz r30, 8(r1);
lwz r0, 0x14(r1);
mtlr r0;
addi r1, r1, 0x10;
blr;
// clang-format on
DvdArchive::~DvdArchive() {
if (mStatus == DVD_ARCHIVE_STATE_MOUNTED) {
mArchive->unmount();
}
DvdArchive::clearArchive();
DvdArchive::clearFile();
mStatus = DVD_ARCHIVE_STATE_CLEARED;
}

// Symbol: DvdArchive_mount
Expand Down
45 changes: 45 additions & 0 deletions source/game/system/DvdArchive.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,51 @@

#include <decomp.h>

#include <egg/core/eggArchive.hpp>
#include <egg/core/eggHeap.hpp>

enum ArchiveState {
DVD_ARCHIVE_STATE_CLEARED = 0,
DVD_ARCHIVE_STATE_RIPPED = 2,
DVD_ARCHIVE_STATE_DECOMPRESSED = 3,
DVD_ARCHIVE_STATE_MOUNTED = 4
};

class DvdArchive {
public:
DvdArchive();
virtual ~DvdArchive();
virtual void init() = 0;
private:
EGG::Archive *mArchive;
void *mArchiveStart;
u32 mArchiveSize;
EGG::Heap *mArchiveHeap;
void *mFileStart;
u32 mFileSize;
EGG::Heap *mFileHeap;
volatile ArchiveState mStatus;

inline void clearArchive() {
if (!mArchiveStart) return;

mArchiveHeap->free(mArchiveStart);
mArchiveStart = nullptr;
mArchiveSize = NULL;
mArchiveHeap = nullptr;
return;
}
inline void clearFile() {
if (!mFileStart) return;

mFileHeap->free(mFileStart);
mFileStart = nullptr;
mFileSize = NULL;
mFileHeap = nullptr;
return;
}
};

#ifdef __cplusplus
extern "C" {
#endif
Expand Down