Wrap nonmatching functions and link OSRtc

This commit is contained in:
Phillip Stephens 2022-12-09 18:13:03 -08:00
parent 357278d214
commit 254fff51db
2 changed files with 224 additions and 6 deletions

View File

@ -820,7 +820,7 @@ LIBS = [
"Dolphin/os/OSReboot",
["Dolphin/os/OSReset", True],
"Dolphin/os/OSResetSW",
["Dolphin/os/OSRtc", False],
["Dolphin/os/OSRtc", True],
["Dolphin/os/OSSync", True],
["Dolphin/os/OSThread", True],
["Dolphin/os/OSTime", True],

View File

@ -172,7 +172,44 @@ static void* LockSram(u32 offset) {
return Scb.sram + offset;
}
#if NONMATCHING
OSSram* __OSLockSram() { return LockSram(0); }
#else
/* clang-format off */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm OSSram* __OSLockSram() {
nofralloc
mflr r0
lis r3, Scb@ha
stw r0, 4(r1)
stwu r1, -0x10(r1)
stw r31, 0xc(r1)
addi r31, r3, Scb@l
bl OSDisableInterrupts
lwz r0, 0x48(r31)
addi r4, r31, 0x48
cmpwi r0, 0
beq lbl_80383B0C
bl OSRestoreInterrupts
li r31, 0
b lbl_80383B18
lbl_80383B0C:
stw r3, 0x44(r31)
li r0, 1
stw r0, 0(r4)
lbl_80383B18:
mr r3, r31
lwz r0, 0x14(r1)
lwz r31, 0xc(r1)
addi r1, r1, 0x10
mtlr r0
blr
}
/* clang-format on */
#pragma pop
#endif
OSSramEx* __OSLockSramEx() { return LockSram(sizeof(OSSram)); }
@ -240,22 +277,71 @@ BOOL __OSReadROM(void* buffer, s32 length, s32 offset) {
return !err;
}
inline OSSram* __OSLockSramHACK() { return LockSram(0); }
#if NONMATCHING
u32 OSGetSoundMode() {
OSSram* sram;
u32 mode;
sram = __OSLockSram();
sram = __OSLockSramHACK();
mode = (sram->flags & 0x4) ? OS_SOUND_MODE_STEREO : OS_SOUND_MODE_MONO;
__OSUnlockSram(FALSE);
return mode;
}
#else
/* clang-format off */
#pragma push
#pragma optimization_level
#pragma optimizewithasm off
asm u32 OSGetSoundMode() {
nofralloc
mflr r0
lis r3, Scb@ha
stw r0, 4(r1)
stwu r1, -0x20(r1)
stw r31, 0x1c(r1)
addi r31, r3, Scb@l
bl OSDisableInterrupts
lwz r0, 0x48(r31)
addi r4, r31, 0x48
cmpwi r0, 0
beq lbl_80384048
bl OSRestoreInterrupts
li r31, 0
b lbl_80384054
lbl_80384048:
stw r3, 0x44(r31)
li r0, 1
stw r0, 0(r4)
lbl_80384054:
lbz r0, 0x13(r31)
rlwinm. r0, r0, 0, 0x1d, 0x1d
beq lbl_80384068
li r31, 1
b lbl_8038406C
lbl_80384068:
li r31, 0
lbl_8038406C:
li r3, 0
li r4, 0
bl UnlockSram
mr r3, r31
lwz r0, 0x24(r1)
lwz r31, 0x1c(r1)
addi r1, r1, 0x20
mtlr r0
blr
}
#pragma pop
/* clang-format on */
#endif
void OSSetSoundMode(u32 mode) {
OSSram* sram;
mode <<= 2;
mode &= 4;
sram = __OSLockSram();
sram = __OSLockSramHACK();
if (mode == (sram->flags & 4)) {
__OSUnlockSram(FALSE);
return;
@ -266,22 +352,64 @@ void OSSetSoundMode(u32 mode) {
__OSUnlockSram(TRUE);
}
#if NONMATCHING
u32 OSGetProgressiveMode() {
OSSram* sram;
u32 mode;
sram = __OSLockSram();
sram = __OSLockSramHACK();
mode = (sram->flags & 0x80) >> 7;
__OSUnlockSram(FALSE);
return mode;
}
#else
/* clang-format off */
#pragma push
#pragma optimization_level
#pragma optimizewithasm off
asm u32 OSGetProgressiveMode() {
nofralloc
/* 80384134 00381094 7C 08 02 A6 */ mflr r0
/* 80384138 00381098 3C 60 80 54 */ lis r3, Scb@ha
/* 8038413C 0038109C 90 01 00 04 */ stw r0, 4(r1)
/* 80384140 003810A0 94 21 FF E8 */ stwu r1, -0x18(r1)
/* 80384144 003810A4 93 E1 00 14 */ stw r31, 0x14(r1)
/* 80384148 003810A8 3B E3 15 A0 */ addi r31, r3, Scb@l
/* 8038414C 003810AC 4B FF D5 15 */ bl OSDisableInterrupts
/* 80384150 003810B0 80 1F 00 48 */ lwz r0, 0x48(r31)
/* 80384154 003810B4 38 9F 00 48 */ addi r4, r31, 0x48
/* 80384158 003810B8 2C 00 00 00 */ cmpwi r0, 0
/* 8038415C 003810BC 41 82 00 10 */ beq lbl_8038416C
/* 80384160 003810C0 4B FF D5 29 */ bl OSRestoreInterrupts
/* 80384164 003810C4 3B E0 00 00 */ li r31, 0
/* 80384168 003810C8 48 00 00 10 */ b lbl_80384178
lbl_8038416C:
/* 8038416C 003810CC 90 7F 00 44 */ stw r3, 0x44(r31)
/* 80384170 003810D0 38 00 00 01 */ li r0, 1
/* 80384174 003810D4 90 04 00 00 */ stw r0, 0(r4)
lbl_80384178:
/* 80384178 003810D8 88 1F 00 13 */ lbz r0, 0x13(r31)
/* 8038417C 003810DC 38 60 00 00 */ li r3, 0
/* 80384180 003810E0 38 80 00 00 */ li r4, 0
/* 80384184 003810E4 54 1F CF FE */ rlwinm r31, r0, 0x19, 0x1f, 0x1f
/* 80384188 003810E8 4B FF FA 05 */ bl UnlockSram
/* 8038418C 003810EC 7F E3 FB 78 */ mr r3, r31
/* 80384190 003810F0 80 01 00 1C */ lwz r0, 0x1c(r1)
/* 80384194 003810F4 83 E1 00 14 */ lwz r31, 0x14(r1)
/* 80384198 003810F8 38 21 00 18 */ addi r1, r1, 0x18
/* 8038419C 003810FC 7C 08 03 A6 */ mtlr r0
/* 803841A0 00381100 4E 80 00 20 */ blr
}
#pragma pop
/* clang-format on */
#endif
void OSSetProgressiveMode(u32 mode) {
OSSram* sram;
mode <<= 7;
mode &= 0x80;
sram = __OSLockSram();
sram = __OSLockSramHACK();
if (mode == (sram->flags & 0x80)) {
__OSUnlockSram(FALSE);
return;
@ -292,16 +420,58 @@ void OSSetProgressiveMode(u32 mode) {
__OSUnlockSram(TRUE);
}
#if NONMATCHING
u8 OSGetLanguage() {
OSSram* sram;
u8 language;
sram = __OSLockSram();
sram = __OSLockSramHACK();
language = sram->language;
__OSUnlockSram(FALSE);
return language;
}
#else
/* clang-format off */
#pragma push
#pragma optimization_level
#pragma optimizewithasm off
asm u8 OSGetLanguage() {
nofralloc
mflr r0
lis r3, Scb@ha
stw r0, 4(r1)
stwu r1, -0x18(r1)
stw r31, 0x14(r1)
addi r31, r3, Scb@l
bl OSDisableInterrupts
lwz r0, 0x48(r31)
addi r4, r31, 0x48
cmpwi r0, 0
beq lbl_80384280
bl OSRestoreInterrupts
li r31, 0
b lbl_8038428C
lbl_80384280:
stw r3, 0x44(r31)
li r0, 1
stw r0, 0(r4)
lbl_8038428C:
lbz r31, 0x12(r31)
li r3, 0
li r4, 0
bl UnlockSram
mr r3, r31
lwz r0, 0x1c(r1)
lwz r31, 0x14(r1)
addi r1, r1, 0x18
mtlr r0
blr
}
#pragma pop
/* clang-format on */
#endif
#if NONMATCHING
u32 OSGetWirelessID(u32 channel) {
OSSramEx* sram;
u16 id;
@ -311,6 +481,54 @@ u32 OSGetWirelessID(u32 channel) {
__OSUnlockSramEx(FALSE);
return id;
}
#else
/* clang-format off */
#pragma push
#pragma optimization_level
#pragma optimizewithasm off
asm u32 OSGetWirelessID(u32 channel) {
nofralloc
mflr r0
lis r4, Scb@ha
stw r0, 4(r1)
stwu r1, -0x20(r1)
stw r31, 0x1c(r1)
addi r31, r4, Scb@l
stw r30, 0x18(r1)
addi r30, r3, 0
bl OSDisableInterrupts
lwz r0, 0x48(r31)
addi r4, r31, 0x48
cmpwi r0, 0
beq lbl_803842F4
bl OSRestoreInterrupts
li r3, 0
b lbl_80384304
lbl_803842F4:
stw r3, 0x44(r31)
li r0, 1
addi r3, r31, 0x14
stw r0, 0(r4)
lbl_80384304:
slwi r0, r30, 1
add r3, r3, r0
lhz r31, 0x1c(r3)
li r3, 0
li r4, 0x14
bl UnlockSram
mr r3, r31
lwz r0, 0x24(r1)
lwz r31, 0x1c(r1)
lwz r30, 0x18(r1)
addi r1, r1, 0x20
mtlr r0
blr
}
#pragma pop
/* clang-format on */
#endif
void OSSetWirelessID(u32 channel, u16 id) {
OSSramEx* sram;