From 28a4b75d39bf19bc9c1d0890294897b8e060fcf1 Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Sat, 10 Sep 2022 20:18:17 -0700 Subject: [PATCH] Link CARDOpen.c --- asm/Dolphin/card/CARDDelete.s | 2 +- asm/Dolphin/card/CARDMount.s | 35 ++++------ asm/Dolphin/card/CARDNet.s | 7 ++ asm/Dolphin/card/CARDOpen.s | 8 +-- asm/Dolphin/card/CARDRead.s | 2 +- asm/Dolphin/card/CARDStat.s | 2 +- obj_files.mk | 2 +- src/Dolphin/card/CARDOpen.c | 125 ++++++++++++++++++++++++++++++++++ 8 files changed, 154 insertions(+), 29 deletions(-) create mode 100644 src/Dolphin/card/CARDOpen.c diff --git a/asm/Dolphin/card/CARDDelete.s b/asm/Dolphin/card/CARDDelete.s index 8121e9ca..5b6c0b87 100644 --- a/asm/Dolphin/card/CARDDelete.s +++ b/asm/Dolphin/card/CARDDelete.s @@ -155,7 +155,7 @@ lbl_803BDE7C: /* 803BDE7C 003BADDC 80 61 00 18 */ lwz r3, 0x18(r1) /* 803BDE80 003BADE0 38 9D 00 00 */ addi r4, r29, 0 /* 803BDE84 003BADE4 38 A1 00 14 */ addi r5, r1, 0x14 -/* 803BDE88 003BADE8 4B FF F0 15 */ bl sub_803bce9c +/* 803BDE88 003BADE8 4B FF F0 15 */ bl __CARDGetFileNo /* 803BDE8C 003BADEC 7C 64 1B 79 */ or. r4, r3, r3 /* 803BDE90 003BADF0 40 80 00 10 */ bge lbl_803BDEA0 /* 803BDE94 003BADF4 80 61 00 18 */ lwz r3, 0x18(r1) diff --git a/asm/Dolphin/card/CARDMount.s b/asm/Dolphin/card/CARDMount.s index ca860439..9928a75b 100644 --- a/asm/Dolphin/card/CARDMount.s +++ b/asm/Dolphin/card/CARDMount.s @@ -3,8 +3,8 @@ .section .data, "wa" .balign 8 -.global lbl_803F6E60 -lbl_803F6E60: +.global SectorSizeTable +SectorSizeTable: .4byte 0x00002000 .4byte 0x00004000 .4byte 0x00008000 @@ -14,8 +14,8 @@ lbl_803F6E60: .4byte 0x00000000 .4byte 0x00000000 -.global lbl_803F6E80 -lbl_803F6E80: +.global LatencyTable +LatencyTable: .4byte 0x00000004 .4byte 0x00000008 .4byte 0x00000010 @@ -25,13 +25,6 @@ lbl_803F6E80: .4byte 0x00000100 .4byte 0x00000200 -.section .sdata, "wa" -.balign 8 -.global lbl_805A8C00 -lbl_805A8C00: - .2byte 0xFFFF - .balign 4 - .section .text, "ax" .global IsCard @@ -41,7 +34,7 @@ IsCard: /* 803BBB18 003B8A78 3C 03 80 00 */ addis r0, r3, 0x8000 /* 803BBB1C 003B8A7C 28 00 00 04 */ cmplwi r0, 4 /* 803BBB20 003B8A80 40 82 00 10 */ bne lbl_803BBB30 -/* 803BBB24 003B8A84 A0 0D A0 40 */ lhz r0, lbl_805A8C00@sda21(r13) +/* 803BBB24 003B8A84 A0 0D A0 40 */ lhz r0, __CARDVendorID@sda21(r13) /* 803BBB28 003B8A88 28 00 FF FF */ cmplwi r0, 0xffff /* 803BBB2C 003B8A8C 40 82 00 0C */ bne lbl_803BBB38 lbl_803BBB30: @@ -77,9 +70,9 @@ lbl_803BBB90: /* 803BBB90 003B8AF0 38 60 00 00 */ li r3, 0 /* 803BBB94 003B8AF4 4E 80 00 20 */ blr lbl_803BBB98: -/* 803BBB98 003B8AF8 3C 80 80 3F */ lis r4, lbl_803F6E60@ha +/* 803BBB98 003B8AF8 3C 80 80 3F */ lis r4, SectorSizeTable@ha /* 803BBB9C 003B8AFC 54 63 BE FA */ rlwinm r3, r3, 0x17, 0x1b, 0x1d -/* 803BBBA0 003B8B00 38 04 6E 60 */ addi r0, r4, lbl_803F6E60@l +/* 803BBBA0 003B8B00 38 04 6E 60 */ addi r0, r4, SectorSizeTable@l /* 803BBBA4 003B8B04 7C 60 1A 14 */ add r3, r0, r3 /* 803BBBA8 003B8B08 80 63 00 00 */ lwz r3, 0(r3) /* 803BBBAC 003B8B0C 2C 03 00 00 */ cmpwi r3, 0 @@ -189,8 +182,8 @@ lbl_803BBD08: /* 803BBD08 003B8C68 28 1F 00 00 */ cmplwi r31, 0 /* 803BBD0C 003B8C6C 41 82 00 20 */ beq lbl_803BBD2C /* 803BBD10 003B8C70 80 81 00 14 */ lwz r4, 0x14(r1) -/* 803BBD14 003B8C74 3C 60 80 3F */ lis r3, lbl_803F6E60@ha -/* 803BBD18 003B8C78 38 03 6E 60 */ addi r0, r3, lbl_803F6E60@l +/* 803BBD14 003B8C74 3C 60 80 3F */ lis r3, SectorSizeTable@ha +/* 803BBD18 003B8C78 38 03 6E 60 */ addi r0, r3, SectorSizeTable@l /* 803BBD1C 003B8C7C 54 83 BE FA */ rlwinm r3, r4, 0x17, 0x1b, 0x1d /* 803BBD20 003B8C80 7C 60 1A 14 */ add r3, r0, r3 /* 803BBD24 003B8C84 80 03 00 00 */ lwz r0, 0(r3) @@ -250,11 +243,11 @@ lbl_803BBDD4: /* 803BBDD4 003B8D34 2C 1E 00 00 */ cmpwi r30, 0 /* 803BBDD8 003B8D38 41 80 03 44 */ blt lbl_803BC11C /* 803BBDDC 003B8D3C 80 01 00 18 */ lwz r0, 0x18(r1) -/* 803BBDE0 003B8D40 3C 80 80 3F */ lis r4, lbl_803F6E60@ha -/* 803BBDE4 003B8D44 38 84 6E 60 */ addi r4, r4, lbl_803F6E60@l +/* 803BBDE0 003B8D40 3C 80 80 3F */ lis r4, SectorSizeTable@ha +/* 803BBDE4 003B8D44 38 84 6E 60 */ addi r4, r4, SectorSizeTable@l /* 803BBDE8 003B8D48 90 1F 01 08 */ stw r0, 0x108(r31) -/* 803BBDEC 003B8D4C 3C 60 80 3F */ lis r3, lbl_803F6E80@ha -/* 803BBDF0 003B8D50 38 03 6E 80 */ addi r0, r3, lbl_803F6E80@l +/* 803BBDEC 003B8D4C 3C 60 80 3F */ lis r3, LatencyTable@ha +/* 803BBDF0 003B8D50 38 03 6E 80 */ addi r0, r3, LatencyTable@l /* 803BBDF4 003B8D54 80 A1 00 18 */ lwz r5, 0x18(r1) /* 803BBDF8 003B8D58 38 7D 00 00 */ addi r3, r29, 0 /* 803BBDFC 003B8D5C 54 A5 06 3A */ rlwinm r5, r5, 0, 0x18, 0x1d @@ -423,7 +416,7 @@ lbl_803BC040: /* 803BC064 003B8FC4 7F 83 02 2E */ lhzx r28, r3, r0 /* 803BC068 003B8FC8 38 60 00 00 */ li r3, 0 /* 803BC06C 003B8FCC 4B FC 7E 4D */ bl __OSUnlockSramEx -/* 803BC070 003B8FD0 A0 0D A0 40 */ lhz r0, lbl_805A8C00@sda21(r13) +/* 803BC070 003B8FD0 A0 0D A0 40 */ lhz r0, __CARDVendorID@sda21(r13) /* 803BC074 003B8FD4 28 00 FF FF */ cmplwi r0, 0xffff /* 803BC078 003B8FD8 41 82 00 0C */ beq lbl_803BC084 /* 803BC07C 003B8FDC 7C 1C 00 40 */ cmplw r28, r0 diff --git a/asm/Dolphin/card/CARDNet.s b/asm/Dolphin/card/CARDNet.s index 9bdf10da..2d8cd04c 100644 --- a/asm/Dolphin/card/CARDNet.s +++ b/asm/Dolphin/card/CARDNet.s @@ -1,5 +1,12 @@ .include "macros.inc" +.section .sdata, "wa" +.balign 8 +.global __CARDVendorID +__CARDVendorID: + .2byte 0xFFFF + .balign 4 + .section .text, "ax" .global CARDGetSerialNo diff --git a/asm/Dolphin/card/CARDOpen.s b/asm/Dolphin/card/CARDOpen.s index 8487c731..25a1a1d3 100644 --- a/asm/Dolphin/card/CARDOpen.s +++ b/asm/Dolphin/card/CARDOpen.s @@ -80,8 +80,8 @@ lbl_803BCE54: /* 803BCE64 003B9DC4 7C 08 03 A6 */ mtlr r0 /* 803BCE68 003B9DC8 4E 80 00 20 */ blr -.global sub_803bce6c -sub_803bce6c: +.global __CARDIsWritable +__CARDIsWritable: /* 803BCE6C 003B9DCC 88 03 00 00 */ lbz r0, 0(r3) /* 803BCE70 003B9DD0 28 00 00 FF */ cmplwi r0, 0xff /* 803BCE74 003B9DD4 40 82 00 0C */ bne lbl_803BCE80 @@ -97,8 +97,8 @@ lbl_803BCE94: /* 803BCE94 003B9DF4 38 60 FF F6 */ li r3, -10 /* 803BCE98 003B9DF8 4E 80 00 20 */ blr -.global sub_803bce9c -sub_803bce9c: +.global __CARDGetFileNo +__CARDGetFileNo: /* 803BCE9C 003B9DFC 7C 08 02 A6 */ mflr r0 /* 803BCEA0 003B9E00 90 01 00 04 */ stw r0, 4(r1) /* 803BCEA4 003B9E04 94 21 FF D0 */ stwu r1, -0x30(r1) diff --git a/asm/Dolphin/card/CARDRead.s b/asm/Dolphin/card/CARDRead.s index 7aafda34..c219781a 100644 --- a/asm/Dolphin/card/CARDRead.s +++ b/asm/Dolphin/card/CARDRead.s @@ -250,7 +250,7 @@ lbl_803BD850: /* 803BD874 003BA7D4 2C 04 FF F6 */ cmpwi r4, -10 /* 803BD878 003BA7D8 40 82 00 10 */ bne lbl_803BD888 /* 803BD87C 003BA7DC 7F 83 E3 78 */ mr r3, r28 -/* 803BD880 003BA7E0 4B FF F5 ED */ bl sub_803bce6c +/* 803BD880 003BA7E0 4B FF F5 ED */ bl __CARDIsWritable /* 803BD884 003BA7E4 7C 64 1B 78 */ mr r4, r3 lbl_803BD888: /* 803BD888 003BA7E8 2C 04 00 00 */ cmpwi r4, 0 diff --git a/asm/Dolphin/card/CARDStat.s b/asm/Dolphin/card/CARDStat.s index 154ec374..95534130 100644 --- a/asm/Dolphin/card/CARDStat.s +++ b/asm/Dolphin/card/CARDStat.s @@ -189,7 +189,7 @@ lbl_803BE194: /* 803BE1B4 003BB114 2C 1E FF F6 */ cmpwi r30, -10 /* 803BE1B8 003BB118 40 82 00 10 */ bne lbl_803BE1C8 /* 803BE1BC 003BB11C 7F A3 EB 78 */ mr r3, r29 -/* 803BE1C0 003BB120 4B FF EC AD */ bl sub_803bce6c +/* 803BE1C0 003BB120 4B FF EC AD */ bl __CARDIsWritable /* 803BE1C4 003BB124 7C 7E 1B 78 */ mr r30, r3 lbl_803BE1C8: /* 803BE1C8 003BB128 2C 1E 00 00 */ cmpwi r30, 0 diff --git a/obj_files.mk b/obj_files.mk index 1ab89283..fbf55506 100644 --- a/obj_files.mk +++ b/obj_files.mk @@ -823,7 +823,7 @@ CARD_FILES :=\ $(BUILD_DIR)/asm/Dolphin/card/CARDCheck.o\ $(BUILD_DIR)/asm/Dolphin/card/CARDMount.o\ $(BUILD_DIR)/asm/Dolphin/card/CARDFormat.o\ - $(BUILD_DIR)/asm/Dolphin/card/CARDOpen.o\ + $(BUILD_DIR)/src/Dolphin/card/CARDOpen.ep.o\ $(BUILD_DIR)/asm/Dolphin/card/CARDCreate.o\ $(BUILD_DIR)/asm/Dolphin/card/CARDRead.o\ $(BUILD_DIR)/asm/Dolphin/card/CARDWrite.o\ diff --git a/src/Dolphin/card/CARDOpen.c b/src/Dolphin/card/CARDOpen.c new file mode 100644 index 00000000..2f5a3f4f --- /dev/null +++ b/src/Dolphin/card/CARDOpen.c @@ -0,0 +1,125 @@ +#include +#include +#include +#include + +#include + +BOOL __CARDCompareFileName(CARDDir* ent, const char* fileName) { + char* entName; + char c1; + char c2; + int n; + + entName = (char*)ent->fileName; + n = CARD_FILENAME_MAX; + while (0 <= --n) { + if ((c1 = *entName++) != (c2 = *fileName++)) { + return FALSE; + } else if (c2 == '\0') { + return TRUE; + } + } + + if (*fileName == '\0') { + return TRUE; + } + + return FALSE; +} + +s32 __CARDAccess(CARDControl* card, CARDDir* ent) { + if (ent->gameName[0] == 0xFF) { + return CARD_RESULT_NOFILE; + } + + if (card->diskID == &__CARDDiskNone || + (memcmp(ent->gameName, card->diskID->gameName, 4) == 0 && memcmp(ent->company, card->diskID->company, 2) == 0)) { + return CARD_RESULT_READY; + } + + return CARD_RESULT_NOPERM; +} + +BOOL __CARDIsWritable(CARDDir* ent) { + if (ent->gameName[0] == 0xFF) { + return CARD_RESULT_NOFILE; + } + + if ((ent->permission & CARD_ATTR_PUBLIC) != 0) { + return CARD_RESULT_READY; + } + + return CARD_RESULT_NOPERM; +} + +s32 __CARDGetFileNo(CARDControl* card, const char* fileName, s32* pfileNo) { + CARDDir* dir; + CARDDir* ent; + s32 fileNo; + s32 result; + + if (!card->attached) { + return CARD_RESULT_NOCARD; + } + + dir = __CARDGetDirBlock(card); + for (fileNo = 0; fileNo < CARD_MAX_FILE; fileNo++) { + ent = &dir[fileNo]; + result = __CARDAccess(card, ent); + if (result < 0) { + continue; + } + if (__CARDCompareFileName(ent, fileName)) { + *pfileNo = fileNo; + return CARD_RESULT_READY; + } + } + + return CARD_RESULT_NOFILE; +} + +s32 CARDOpen(s32 chan, const char* fileName, CARDFileInfo* fileInfo) { + CARDControl* card; + CARDDir* dir; + CARDDir* ent; + s32 result; + s32 fileNo; + + fileInfo->chan = -1; + result = __CARDGetControlBlock(chan, &card); + if (result < 0) { + return result; + } + result = __CARDGetFileNo(card, fileName, &fileNo); + if (0 <= result) { + dir = __CARDGetDirBlock(card); + ent = &dir[fileNo]; + if (!CARDIsValidBlockNo(card, ent->startBlock)) { + result = CARD_RESULT_BROKEN; + } else { + fileInfo->chan = chan; + fileInfo->fileNo = fileNo; + fileInfo->offset = 0; + fileInfo->iBlock = ent->startBlock; + } + } + return __CARDPutControlBlock(card, result); +} + +s32 CARDClose(CARDFileInfo* fileInfo) { + CARDControl* card; + s32 result; + + result = __CARDGetControlBlock(fileInfo->chan, &card); + if (result < 0) { + return result; + } + + fileInfo->chan = -1; + return __CARDPutControlBlock(card, CARD_RESULT_READY); +} + +BOOL __CARDIsOpened(CARDControl* card, s32 fileNo) { + return FALSE; +}