1
0
mirror of https://github.com/zeldaret/oot.git synced 2024-09-22 21:35:27 +00:00
oot/src/libultra_boot_O2/osDriveRomInit.c

60 lines
1.9 KiB
C
Raw Normal View History

2020-03-17 04:31:30 +00:00
#include <global.h>
#include <ultra64/hardware.h>
OSPiHandle __DriveRomHandle;
2020-03-22 21:19:43 +00:00
OSPiHandle* osDriveRomInit() {
2020-03-17 04:31:30 +00:00
register s32 status;
register u32 a;
register s32 prevInt;
static u32 D_8000AC70 = 1;
__osPiGetAccess();
2020-03-22 21:19:43 +00:00
if (!D_8000AC70) {
2020-03-17 04:31:30 +00:00
__osPiRelAccess();
return &__DriveRomHandle;
}
D_8000AC70 = 0;
__DriveRomHandle.type = DEVICE_TYPE_BULK;
__DriveRomHandle.baseAddress = 0xa6000000;
__DriveRomHandle.domain = 0;
__DriveRomHandle.speed = 0;
bzero(&__DriveRomHandle.transferInfo, sizeof(__OSTranxInfo));
2020-03-22 21:19:43 +00:00
while (status = HW_REG(PI_STATUS_REG, u32), status & PI_STATUS_ERROR) {
2020-03-17 04:31:30 +00:00
;
2020-03-22 21:19:43 +00:00
}
2020-03-17 04:31:30 +00:00
HW_REG(PI_BSD_DOM1_LAT_REG, u32) = 0xff;
HW_REG(PI_BSD_DOM1_PGS_REG, u32) = 0;
HW_REG(PI_BSD_DOM1_RLS_REG, u32) = 3;
HW_REG(PI_BSD_DOM1_PWD_REG, u32) = 0xff;
a = HW_REG(__DriveRomHandle.baseAddress, u32);
__DriveRomHandle.latency = a & 0xFF;
__DriveRomHandle.pulse = (a >> 8) & 0xFF;
__DriveRomHandle.pageSize = (a >> 0x10) & 0xF;
__DriveRomHandle.relDuration = (a >> 0x14) & 0xF;
HW_REG(PI_BSD_DOM1_LAT_REG, u32) = (u8)a;
HW_REG(PI_BSD_DOM1_PGS_REG, u32) = __DriveRomHandle.pageSize;
HW_REG(PI_BSD_DOM1_RLS_REG, u32) = __DriveRomHandle.relDuration;
HW_REG(PI_BSD_DOM1_PWD_REG, u32) = __DriveRomHandle.pulse;
__osCurrentHandle[__DriveRomHandle.domain]->type = __DriveRomHandle.type;
__osCurrentHandle[__DriveRomHandle.domain]->latency = __DriveRomHandle.latency;
__osCurrentHandle[__DriveRomHandle.domain]->pageSize = __DriveRomHandle.pageSize;
__osCurrentHandle[__DriveRomHandle.domain]->relDuration = __DriveRomHandle.relDuration;
__osCurrentHandle[__DriveRomHandle.domain]->pulse = __DriveRomHandle.pulse;
prevInt = __osDisableInt();
__DriveRomHandle.next = __osPiTable;
__osPiTable = &__DriveRomHandle;
__osRestoreInt(prevInt);
__osPiRelAccess();
return &__DriveRomHandle;
}