osCartRomInit.c (2771B)
1 #include "PR/os_internal.h" 2 #include "PR/R4300.h" 3 #include "PR/rcp.h" 4 #include "PR/os_pi.h" 5 #include "PR/os.h" 6 #include "libultra_internal.h" 7 #include "piint.h" 8 9 OSPiHandle __Dom1SpeedParam; 10 11 #ifdef VERSION_CN 12 13 OSPiHandle __CartRomHandle; 14 15 OSPiHandle* osCartRomInit(void) { 16 register u32 a; 17 register s32 status; 18 register u32 prevInt; 19 register u32 lastLatency; 20 register u32 lastPageSize; 21 register u32 lastRelDuration; 22 register u32 lastPulse; 23 24 static u32 notInitialized = 1; 25 26 __osPiGetAccess(); 27 28 if (!notInitialized) { 29 __osPiRelAccess(); 30 return &__CartRomHandle; 31 } 32 33 notInitialized = 0; 34 __CartRomHandle.type = DEVICE_TYPE_CART; 35 __CartRomHandle.baseAddress = PHYS_TO_K1(PI_DOM1_ADDR2); 36 __CartRomHandle.domain = 0; 37 __CartRomHandle.speed = 0; 38 bzero(&__CartRomHandle.transferInfo, sizeof(__OSTranxInfo)); 39 40 WAIT_ON_IO_BUSY(status); 41 42 lastLatency = IO_READ(PI_BSD_DOM1_LAT_REG); 43 lastPageSize = IO_READ(PI_BSD_DOM1_PGS_REG); 44 lastRelDuration = IO_READ(PI_BSD_DOM1_RLS_REG); 45 lastPulse = IO_READ(PI_BSD_DOM1_PWD_REG); 46 47 IO_WRITE(PI_BSD_DOM1_LAT_REG, 0xff); 48 IO_WRITE(PI_BSD_DOM1_PGS_REG, 0); 49 IO_WRITE(PI_BSD_DOM1_RLS_REG, 3); 50 IO_WRITE(PI_BSD_DOM1_PWD_REG, 0xff); 51 52 a = IO_READ(__CartRomHandle.baseAddress); 53 __CartRomHandle.latency = a & 0xFF; 54 __CartRomHandle.pageSize = (a >> 0x10) & 0xF; 55 __CartRomHandle.relDuration = (a >> 0x14) & 0xF; 56 __CartRomHandle.pulse = (a >> 8) & 0xFF; 57 58 IO_WRITE(PI_BSD_DOM1_LAT_REG, lastLatency); 59 IO_WRITE(PI_BSD_DOM1_PGS_REG, lastPageSize); 60 IO_WRITE(PI_BSD_DOM1_RLS_REG, lastRelDuration); 61 IO_WRITE(PI_BSD_DOM1_PWD_REG, lastPulse); 62 63 prevInt = __osDisableInt(); 64 __CartRomHandle.next = __osPiTable; 65 __osPiTable = &__CartRomHandle; 66 __osRestoreInt(prevInt); 67 __osPiRelAccess(); 68 69 return &__CartRomHandle; 70 } 71 72 #else 73 74 OSPiHandle *osCartRomInit(void) { 75 u32 domain; 76 u32 saveMask; 77 78 domain = 0; 79 80 if (__Dom1SpeedParam.baseAddress == PHYS_TO_K1(PI_DOM1_ADDR2)) { 81 return &__Dom1SpeedParam; 82 } 83 84 __Dom1SpeedParam.type = DEVICE_TYPE_CART; 85 __Dom1SpeedParam.baseAddress = PHYS_TO_K1(PI_DOM1_ADDR2); 86 osPiRawReadIo(0, &domain); 87 __Dom1SpeedParam.latency = domain & 0xff; 88 __Dom1SpeedParam.pulse = (domain >> 8) & 0xff; 89 __Dom1SpeedParam.pageSize = (domain >> 0x10) & 0xf; 90 __Dom1SpeedParam.relDuration = (domain >> 0x14) & 0xf; 91 __Dom1SpeedParam.domain = PI_DOMAIN1; 92 //__Dom1SpeedParam.speed = 0; 93 94 bzero(&__Dom1SpeedParam.transferInfo, sizeof(__OSTranxInfo)); 95 96 saveMask = __osDisableInt(); 97 __Dom1SpeedParam.next = __osPiTable; 98 __osPiTable = &__Dom1SpeedParam; 99 __osRestoreInt(saveMask); 100 101 return &__Dom1SpeedParam; 102 } 103 104 #endif