From 3f07a192321ebfc8b13fe239a3f80e43701268ba Mon Sep 17 00:00:00 2001 From: LuigiBlood Date: Sun, 30 Jul 2023 22:21:00 +0200 Subject: [PATCH] osDriveRomInit match --- splat.yaml | 2 ++ src/libleo/driverominit.c | 53 ++++++++++++++++++++++----------------- 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/splat.yaml b/splat.yaml index 2388688..263bb73 100644 --- a/splat.yaml +++ b/splat.yaml @@ -327,6 +327,8 @@ segments: - [0x6A3B0, bin, rom_data_6A3B0] - [0x6A3D0, .data, gb_tower] - [0x6A3E0, bin, rom_data_6A3E0] + - [0x7A180, .data, libleo/driverominit] + - [0x7A190, bin, rom_data_7A190] - [0x7A2A0, .data, libultra/os/initialize] - [0x7A2C0, .data, libultra/al/reverb] - [0x7A2E0, bin, rom_data_7A2E0] diff --git a/src/libleo/driverominit.c b/src/libleo/driverominit.c index 42924ec..37bfac2 100644 --- a/src/libleo/driverominit.c +++ b/src/libleo/driverominit.c @@ -4,22 +4,21 @@ void __osPiRelAccess(void); void __osPiGetAccess(void); -extern OSPiHandle* __osCurrentHandle[]; -extern OSPiHandle __DriveRomHandle; +OSPiHandle __DriveRomHandle; -#ifdef NON_MATCHING -// https://decomp.me/scratch/uNZ73 OSPiHandle* osDriveRomInit(void) { - register s32 saveMask; - register u32 value; - register s32 status; - static s32 first = 1; // D_80079580 + register s32 status; + register s32 saveMask; + register u32 value; + static s32 first = 1; // D_80079580 + u32 latency, pageSize, release, pulse; - __osPiGetAccess(); - if (!first) { - __osPiRelAccess(); - return &__DriveRomHandle; - } + __osPiGetAccess(); + if (!first) { + __osPiRelAccess(); + return &__DriveRomHandle; + } + first = 0; __DriveRomHandle.type = DEVICE_TYPE_BULK; __DriveRomHandle.baseAddress = PHYS_TO_K1(PI_DOM1_ADDR1); @@ -27,31 +26,39 @@ OSPiHandle* osDriveRomInit(void) { __DriveRomHandle.speed = 0; bzero(&__DriveRomHandle.transferInfo, sizeof(__OSTranxInfo)); - while (status = HW_REG(PI_STATUS_REG, u32), status & (PI_STATUS_IO_BUSY | PI_STATUS_DMA_BUSY)) {} + while (status = HW_REG(PI_STATUS_REG, u32), status & (PI_STATUS_IO_BUSY | PI_STATUS_DMA_BUSY)) {} + //Keep the previous PI settings as we go to into the safest settings to read the PI info from DDROM. + latency = HW_REG(PI_BSD_DOM1_LAT_REG, u32); + pageSize = HW_REG(PI_BSD_DOM1_PGS_REG, u32); + release = HW_REG(PI_BSD_DOM1_RLS_REG, u32); + pulse = HW_REG(PI_BSD_DOM1_PWD_REG, u32); + + //Set the safest PI settings 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; + //Read the PI settings from DDROM and put it in __DriveRomHandle value = HW_REG(__DriveRomHandle.baseAddress, u32); __DriveRomHandle.latency = value & 0xFF; - __DriveRomHandle.pulse = (value >> 8) & 0xFF; __DriveRomHandle.pageSize = (value >> 0x10) & 0xF; __DriveRomHandle.relDuration = (value >> 0x14) & 0xF; + __DriveRomHandle.pulse = (value >> 8) & 0xFF; + + //Put back the previous PI settings + HW_REG(PI_BSD_DOM1_LAT_REG, u32) = latency; + HW_REG(PI_BSD_DOM1_PGS_REG, u32) = pageSize; + HW_REG(PI_BSD_DOM1_RLS_REG, u32) = release; + HW_REG(PI_BSD_DOM1_PWD_REG, u32) = pulse; - HW_REG(PI_BSD_DOM1_LAT_REG, u32) = (u8)value; - 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; saveMask = __osDisableInt(); __DriveRomHandle.next = __osPiTable; __osPiTable = &__DriveRomHandle; __osRestoreInt(saveMask); __osPiRelAccess(); - return &__DriveRomHandle; + + return &__DriveRomHandle; } -#else -#pragma GLOBAL_ASM("asm/nonmatchings/libleo/driverominit/osDriveRomInit.s") -#endif