sm64

A Super Mario 64 decompilation
Log | Files | Refs | README | LICENSE

piint.h (8329B)


      1 #ifndef _PIINT_H
      2 #define _PIINT_H
      3 #include "PR/os_internal.h"
      4 #include "PR/rcp.h"
      5 #include "PR/os_pi.h"
      6 #include "PR/os.h"
      7 
      8 //https://github.com/LuigiBlood/64dd/wiki/Memory-Map
      9 
     10 #define LEO_BASE_REG 0x05000000
     11 
     12 #define LEO_CMD (LEO_BASE_REG + 0x508)
     13 #define LEO_STATUS (LEO_BASE_REG + 0x508)
     14 
     15 #define LEO_BM_CTL (LEO_BASE_REG + 0x510)
     16 #define LEO_BM_STATUS (LEO_BASE_REG + 0x510)
     17 
     18 #define LEO_SEQ_CTL (LEO_BASE_REG + 0x518)
     19 #define LEO_SEQ_STATUS (LEO_BASE_REG + 0x518)
     20 
     21 #define LEO_C2_BUFF (LEO_BASE_REG + 0x000)      //C2 Sector Buffer
     22 #define LEO_SECTOR_BUFF (LEO_BASE_REG + 0x400)  //Data Sector Buffer
     23 #define LEO_DATA (LEO_BASE_REG + 0x500)         //Data
     24 #define LEO_MISC_REG (LEO_BASE_REG + 0x504)     //Misc Register
     25 #define LEO_CUR_TK (LEO_BASE_REG + 0x50C)       //Current Track
     26 #define LEO_ERR_SECTOR (LEO_BASE_REG + 0x514)   //Sector Error Status
     27 #define LEO_CUR_SECTOR (LEO_BASE_REG + 0x51C)   //Current Sector
     28 #define LEO_HARD_RESET (LEO_BASE_REG + 0x520)   //Hard Reset
     29 #define LEO_C1_S0 (LEO_BASE_REG + 0x524)        //C1
     30 #define LEO_HOST_SECBYTE (LEO_BASE_REG + 0x528) //Sector Size (in bytes)
     31 #define LEO_C1_S2 (LEO_BASE_REG + 0x52C)        //C1
     32 #define LEO_SEC_BYTE (LEO_BASE_REG + 0x530)     //Sectors per Block, Full Size
     33 #define LEO_C1_S4 (LEO_BASE_REG + 0x534)        //C1
     34 #define LEO_C1_S6 (LEO_BASE_REG + 0x538)        //C1
     35 #define LEO_CUR_ADDR (LEO_BASE_REG + 0x53C)     //Current Address?
     36 #define LEO_ID_REG (LEO_BASE_REG + 0x540)       //ID
     37 #define LEO_TEST_REG (LEO_BASE_REG + 0x544)     //Test Read
     38 #define LEO_TEST_PIN_SEL (LEO_BASE_REG + 0x548) //Test Write
     39 #define LEO_RAM_ADDR (LEO_BASE_REG + 0x580)     //Microsequencer RAM
     40 
     41 #define LEO_STATUS_PRESENCE_MASK 0xFFFF
     42 
     43 #define LEO_STATUS_DATA_REQUEST 0x40000000
     44 #define LEO_STATUS_C2_TRANSFER 0x10000000
     45 #define LEO_STATUS_BUFFER_MANAGER_ERROR 0x08000000
     46 #define LEO_STATUS_BUFFER_MANAGER_INTERRUPT 0x04000000
     47 #define LEO_STATUS_MECHANIC_INTERRUPT 0x02000000
     48 #define LEO_STATUS_DISK_PRESENT 0x01000000
     49 #define LEO_STATUS_BUSY_STATE 0x00800000
     50 #define LEO_STATUS_RESET_STATE 0x00400000
     51 #define LEO_STATUS_MOTOR_NOT_SPINNING 0x00100000
     52 #define LEO_STATUS_HEAD_RETRACTED 0x00080000
     53 #define LEO_STATUS_WRITE_PROTECT_ERROR 0x00040000
     54 #define LEO_STATUS_MECHANIC_ERROR 0x00020000
     55 #define LEO_STATUS_DISK_CHANGE 0x00010000
     56 
     57 #define LEO_STATUS_MODE_MASK (LEO_STATUS_MOTOR_NOT_SPINNING | LEO_STATUS_HEAD_RETRACTED)
     58 #define LEO_STATUS_MODE_SLEEP (LEO_STATUS_MOTOR_NOT_SPINNING | LEO_STATUS_HEAD_RETRACTED)
     59 #define LEO_STATUS_MODE_STANDBY (LEO_STATUS_HEAD_RETRACTED)
     60 #define LEO_STATUS_MODE_ACTIVE 0
     61 
     62 #define LEO_CUR_TK_INDEX_LOCK 0x60000000
     63 
     64 #define LEO_BM_STATUS_RUNNING 0x80000000      //Running
     65 #define LEO_BM_STATUS_ERROR 0x04000000        //Error
     66 #define LEO_BM_STATUS_MICRO 0x02000000        //Micro Status?
     67 #define LEO_BM_STATUS_BLOCK 0x01000000        //Block Transfer
     68 #define LEO_BM_STATUS_C1CORRECTION 0x00800000 //C1 Correction
     69 #define LEO_BM_STATUS_C1DOUBLE 0x00400000     //C1 Double
     70 #define LEO_BM_STATUS_C1SINGLE 0x00200000     //C1 Single
     71 #define LEO_BM_STATUS_C1ERROR 0x00010000      //C1 Error
     72 
     73 #define LEO_BM_CTL_START 0x80000000             //Start Buffer Manager
     74 #define LEO_BM_CTL_MODE 0x40000000              //Buffer Manager Mode
     75 #define LEO_BM_CTL_IMASK 0x20000000             //BM Interrupt Mask
     76 #define LEO_BM_CTL_RESET 0x10000000             //Buffer Manager Reset
     77 #define LEO_BM_CTL_DISABLE_OR 0x08000000        //Disable OR Check?
     78 #define LEO_BM_CTL_DISABLE_C1 0x04000000        //Disable C1 Correction
     79 #define LEO_BM_CTL_BLOCK 0x02000000             //Block Transfer
     80 #define LEO_BM_CTL_CLR_MECHANIC_INTR 0x01000000 //Mechanic Interrupt Reset
     81 
     82 #define LEO_BM_CTL_CONTROL_MASK 0xFF000000
     83 #define LEO_BM_CTL_SECTOR_MASK 0x00FF0000
     84 #define LEO_BM_CTL_SECTOR_SHIFT 16
     85 
     86 #define LEO_CMD_TYPE_0 0 //TODO: name
     87 #define LEO_CMD_TYPE_1 1 //TODO: name
     88 #define LEO_CMD_TYPE_2 2 //TODO: name
     89 
     90 #define LEO_ERROR_GOOD 0
     91 #define LEO_ERROR_3 3 //
     92 #define LEO_ERROR_4 4   //maybe busy?
     93 #define LEO_ERROR_6 6 //
     94 #define LEO_ERROR_17 17 //
     95 #define LEO_ERROR_22 22 //
     96 #define LEO_ERROR_23 23 //unrecovered read error?
     97 #define LEO_ERROR_24 24 //no reference position found?
     98 #define LEO_ERROR_29 29 //
     99 #define LEO_ERROR_75 75 //
    100 
    101 extern OSDevMgr __osPiDevMgr;
    102 extern OSPiHandle *__osCurrentHandle[2];
    103 extern OSPiHandle __Dom1SpeedParam;
    104 extern OSPiHandle __Dom2SpeedParam;
    105 extern OSMesgQueue __osPiAccessQueue;
    106 extern u32 __osPiAccessQueueEnabled;
    107 
    108 int __osPiDeviceBusy(void);
    109 void __osDevMgrMain(void *);
    110 void __osPiCreateAccessQueue(void);
    111 void __osPiRelAccess(void);
    112 void __osPiGetAccess(void);
    113 OSMesgQueue *osPiGetCmdQueue(void);
    114 
    115 #define OS_RAMROM_STACKSIZE 1024
    116 
    117 #define WAIT_ON_IO_BUSY(stat)                               \
    118     stat = IO_READ(PI_STATUS_REG);                          \
    119     while (stat & (PI_STATUS_IO_BUSY | PI_STATUS_DMA_BUSY)) \
    120         stat = IO_READ(PI_STATUS_REG);
    121 
    122 #ifdef VERSION_EU
    123 #define WAIT_ON_LEO_IO_BUSY(stat)    \
    124     stat = IO_READ(PI_STATUS_REG);   \
    125     while (stat & PI_STATUS_IO_BUSY) \
    126         stat = IO_READ(PI_STATUS_REG);
    127 #else
    128 #define WAIT_ON_LEO_IO_BUSY WAIT_ON_IO_BUSY
    129 #endif
    130 
    131 #define UPDATE_REG(reg, var)           \
    132     if (cHandle->var != pihandle->var) \
    133         IO_WRITE(reg, pihandle->var);
    134 
    135 #ifdef VERSION_CN
    136 #define EPI_SYNC(pihandle, stat, domain)                   \
    137                                                            \
    138     WAIT_ON_IO_BUSY(stat)                                  \
    139                                                            \
    140     domain = pihandle->domain;                             \
    141     if (__osCurrentHandle[domain]->type != pihandle->type) \
    142     {                                                      \
    143         OSPiHandle *cHandle = __osCurrentHandle[domain];   \
    144         if (domain == PI_DOMAIN1)                          \
    145         {                                                  \
    146             UPDATE_REG(PI_BSD_DOM1_LAT_REG, latency);      \
    147             UPDATE_REG(PI_BSD_DOM1_PGS_REG, pageSize);     \
    148             UPDATE_REG(PI_BSD_DOM1_RLS_REG, relDuration);  \
    149             UPDATE_REG(PI_BSD_DOM1_PWD_REG, pulse);        \
    150         }                                                  \
    151         else                                               \
    152         {                                                  \
    153             UPDATE_REG(PI_BSD_DOM2_LAT_REG, latency);      \
    154             UPDATE_REG(PI_BSD_DOM2_PGS_REG, pageSize);     \
    155             UPDATE_REG(PI_BSD_DOM2_RLS_REG, relDuration);  \
    156             UPDATE_REG(PI_BSD_DOM2_PWD_REG, pulse);        \
    157         }                                                  \
    158         cHandle->type = pihandle->type;                    \
    159         cHandle->latency = pihandle->latency;              \
    160         cHandle->pageSize = pihandle->pageSize;            \
    161         cHandle->relDuration = pihandle->relDuration;      \
    162         cHandle->pulse = pihandle->pulse;                  \
    163     }
    164 #else
    165 #define EPI_SYNC(pihandle, stat, domain)                   \
    166                                                            \
    167     WAIT_ON_IO_BUSY(stat)                                  \
    168                                                            \
    169     domain = pihandle->domain;                             \
    170     if (__osCurrentHandle[domain] != pihandle)             \
    171     {                                                      \
    172         OSPiHandle *cHandle = __osCurrentHandle[domain];   \
    173         if (domain == PI_DOMAIN1)                          \
    174         {                                                  \
    175             UPDATE_REG(PI_BSD_DOM1_LAT_REG, latency);      \
    176             UPDATE_REG(PI_BSD_DOM1_PGS_REG, pageSize);     \
    177             UPDATE_REG(PI_BSD_DOM1_RLS_REG, relDuration);  \
    178             UPDATE_REG(PI_BSD_DOM1_PWD_REG, pulse);        \
    179         }                                                  \
    180         else                                               \
    181         {                                                  \
    182             UPDATE_REG(PI_BSD_DOM2_LAT_REG, latency);      \
    183             UPDATE_REG(PI_BSD_DOM2_PGS_REG, pageSize);     \
    184             UPDATE_REG(PI_BSD_DOM2_RLS_REG, relDuration);  \
    185             UPDATE_REG(PI_BSD_DOM2_PWD_REG, pulse);        \
    186         }                                                  \
    187         __osCurrentHandle[domain] = pihandle;              \
    188     }
    189 #endif
    190 
    191 #endif