remove "done" folders, label "bs/droneenter, bs/dronelook, and bs/dronevanish files and functions"
This commit is contained in:
12
src/core1/io/ai.c
Normal file
12
src/core1/io/ai.c
Normal file
@@ -0,0 +1,12 @@
|
||||
#include <os_internal.h>
|
||||
#include <rcp.h>
|
||||
|
||||
s32 __osAiDeviceBusy(void)
|
||||
{
|
||||
register s32 status = IO_READ(AI_STATUS_REG);
|
||||
if (status & AI_STATUS_FIFO_FULL)
|
||||
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
6
src/core1/io/aigetlen.c
Normal file
6
src/core1/io/aigetlen.c
Normal file
@@ -0,0 +1,6 @@
|
||||
#include <rcp.h>
|
||||
|
||||
u32 osAiGetLength(void)
|
||||
{
|
||||
return IO_READ(AI_LEN_REG);
|
||||
}
|
20
src/core1/io/aisetfreq.c
Normal file
20
src/core1/io/aisetfreq.c
Normal file
@@ -0,0 +1,20 @@
|
||||
#include <rcp.h>
|
||||
#include "osint.h"
|
||||
|
||||
s32 osAiSetFrequency(u32 frequency)
|
||||
{
|
||||
register unsigned int dacRate;
|
||||
register int bitRate;
|
||||
register float f;
|
||||
f = osViClock / (float)frequency + .5f;
|
||||
dacRate = f;
|
||||
if (dacRate < AI_MIN_DAC_RATE)
|
||||
return -1;
|
||||
bitRate = (dacRate / 66) & 0xFF;
|
||||
if (bitRate > AI_MAX_BIT_RATE)
|
||||
bitRate = AI_MAX_BIT_RATE;
|
||||
IO_WRITE(AI_DACRATE_REG, dacRate - 1);
|
||||
IO_WRITE(AI_BITRATE_REG, bitRate - 1);
|
||||
IO_WRITE(AI_CONTROL_REG, AI_CONTROL_DMA_ON);
|
||||
return osViClock / (s32)dacRate;
|
||||
}
|
23
src/core1/io/aisetnextbuf.c
Normal file
23
src/core1/io/aisetnextbuf.c
Normal file
@@ -0,0 +1,23 @@
|
||||
#include <os_internal.h>
|
||||
#include <rcp.h>
|
||||
#include "osint.h"
|
||||
|
||||
s32 osAiSetNextBuffer(void *bufPtr, u32 size)
|
||||
{
|
||||
static u8 hdwrBugFlag = 0;
|
||||
char *bptr = bufPtr;
|
||||
if (hdwrBugFlag != 0)
|
||||
bptr -= 0x2000;
|
||||
|
||||
if ((((u32)bufPtr + size) & 0x3fff) == 0x2000)
|
||||
hdwrBugFlag = 1;
|
||||
else
|
||||
hdwrBugFlag = 0;
|
||||
|
||||
if (__osAiDeviceBusy())
|
||||
return -1;
|
||||
|
||||
IO_WRITE(AI_DRAM_ADDR_REG, osVirtualToPhysical(bptr));
|
||||
IO_WRITE(AI_LEN_REG, size);
|
||||
return 0;
|
||||
}
|
36
src/core1/io/cartrominit.c
Normal file
36
src/core1/io/cartrominit.c
Normal file
@@ -0,0 +1,36 @@
|
||||
#include <ultra64.h>
|
||||
#include "functions.h"
|
||||
#include "variables.h"
|
||||
|
||||
extern OSPiHandle *__osPiTable;
|
||||
|
||||
OSPiHandle CartRomHandle;
|
||||
OSPiHandle *osCartRomInit(void)
|
||||
{
|
||||
u32 domain;
|
||||
u32 saveMask;
|
||||
|
||||
domain = 0;
|
||||
|
||||
if (CartRomHandle.baseAddress == PHYS_TO_K1(PI_DOM1_ADDR2))
|
||||
return &CartRomHandle;
|
||||
|
||||
CartRomHandle.type = DEVICE_TYPE_CART;
|
||||
CartRomHandle.baseAddress = PHYS_TO_K1(PI_DOM1_ADDR2);
|
||||
osPiRawReadIo(NULL, &domain);
|
||||
CartRomHandle.latency = domain & 0xff;
|
||||
CartRomHandle.pulse = (domain >> 8) & 0xff;
|
||||
CartRomHandle.pageSize = (domain >> 0x10) & 0xf;
|
||||
CartRomHandle.relDuration = (domain >> 0x14) & 0xf;
|
||||
CartRomHandle.domain = PI_DOMAIN1;
|
||||
CartRomHandle.speed = 0;
|
||||
|
||||
bzero(&CartRomHandle.transferInfo, sizeof(__OSTranxInfo));
|
||||
|
||||
saveMask = __osDisableInt();
|
||||
CartRomHandle.next = __osPiTable;
|
||||
__osPiTable = &CartRomHandle;
|
||||
__osRestoreInt(saveMask);
|
||||
|
||||
return &CartRomHandle;
|
||||
}//*/
|
15
src/core1/io/conteeplongread.c
Normal file
15
src/core1/io/conteeplongread.c
Normal file
@@ -0,0 +1,15 @@
|
||||
#include <os_internal.h>
|
||||
#include "controller.h"
|
||||
s32 osEepromLongRead(OSMesgQueue *mq, u8 address, u8 *buffer, int length)
|
||||
{
|
||||
s32 ret;
|
||||
ret = 0;
|
||||
while (length > 0)
|
||||
{
|
||||
ERRCK(osEepromRead(mq, address, buffer));
|
||||
length -= EEPROM_BLOCK_SIZE;
|
||||
address++;
|
||||
buffer += EEPROM_BLOCK_SIZE;
|
||||
}
|
||||
return ret;
|
||||
}
|
18
src/core1/io/conteeplongwrite.c
Normal file
18
src/core1/io/conteeplongwrite.c
Normal file
@@ -0,0 +1,18 @@
|
||||
#include <os_internal.h>
|
||||
#include "controller.h"
|
||||
|
||||
s32 osEepromLongWrite(OSMesgQueue *mq, u8 address, u8 *buffer, int length)
|
||||
{
|
||||
s32 ret;
|
||||
ret = 0;
|
||||
while (length > 0)
|
||||
{
|
||||
ERRCK(osEepromWrite(mq, address, buffer));
|
||||
length -= EEPROM_BLOCK_SIZE;
|
||||
address++;
|
||||
buffer += EEPROM_BLOCK_SIZE;
|
||||
osSetTimer(&__osEepromTimer, 12000 * osClockRate / 1000000, 0, &__osEepromTimerQ, &__osEepromTimerMsg);
|
||||
osRecvMesg(&__osEepromTimerQ, NULL, OS_MESG_BLOCK);
|
||||
}
|
||||
return ret;
|
||||
}
|
106
src/core1/io/conteepread.c
Normal file
106
src/core1/io/conteepread.c
Normal file
@@ -0,0 +1,106 @@
|
||||
#include <rcp.h>
|
||||
#include "controller.h"
|
||||
#include "siint.h"
|
||||
|
||||
static void __osPackEepReadData(u8 address);
|
||||
OSPifRam __osEepPifRam; // todo bss
|
||||
s32 osEepromRead(OSMesgQueue *mq, u8 address, u8 *buffer)
|
||||
{
|
||||
s32 ret;
|
||||
int i;
|
||||
u16 type;
|
||||
u8 *ptr;
|
||||
OSContStatus sdata;
|
||||
__OSContEepromFormat eepromformat;
|
||||
ret = 0;
|
||||
i = 0;
|
||||
ptr = (u8 *)&__osEepPifRam.ramarray;
|
||||
__osSiGetAccess();
|
||||
ret = __osEepStatus(mq, &sdata);
|
||||
type = sdata.type & (CONT_EEPROM | CONT_EEP16K);
|
||||
|
||||
if (ret != 0)
|
||||
{
|
||||
__osSiRelAccess();
|
||||
return CONT_NO_RESPONSE_ERROR;
|
||||
}
|
||||
switch (type)
|
||||
{
|
||||
case CONT_EEPROM:
|
||||
if (address > EEPROM_MAXBLOCKS)
|
||||
{
|
||||
__osSiRelAccess();
|
||||
return -1;
|
||||
}
|
||||
|
||||
break;
|
||||
case CONT_EEPROM | CONT_EEP16K:
|
||||
if (address > EEP16K_MAXBLOCKS) //not technically possible
|
||||
{
|
||||
__osSiRelAccess();
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
__osSiRelAccess();
|
||||
return CONT_NO_RESPONSE_ERROR;
|
||||
break;
|
||||
}
|
||||
while (sdata.status & CONT_EEPROM_BUSY)
|
||||
{
|
||||
__osEepStatus(mq, &sdata);
|
||||
}
|
||||
__osPackEepReadData(address);
|
||||
ret = __osSiRawStartDma(OS_WRITE, &__osEepPifRam); //send command to pif
|
||||
osRecvMesg(mq, NULL, OS_MESG_BLOCK);
|
||||
for (i = 0; i < ARRLEN(__osEepPifRam.ramarray) + 1; i++) {
|
||||
__osEepPifRam.ramarray[i] = 0xFF;
|
||||
}
|
||||
__osEepPifRam.pifstatus = 0;
|
||||
ret = __osSiRawStartDma(OS_READ, &__osEepPifRam); //recv response
|
||||
__osContLastCmd = CONT_CMD_READ_EEPROM;
|
||||
osRecvMesg(mq, NULL, OS_MESG_BLOCK);
|
||||
for (i = 0; i < 4; i++) //skip the first 4 bytes
|
||||
{
|
||||
ptr++;
|
||||
}
|
||||
eepromformat = *(__OSContEepromFormat *)ptr;
|
||||
|
||||
ret = CHNL_ERR(eepromformat);
|
||||
|
||||
if (ret == 0)
|
||||
for (i = 0; i < ARRLEN(eepromformat.data); i++)
|
||||
*buffer++ = eepromformat.data[i];
|
||||
|
||||
__osSiRelAccess();
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void __osPackEepReadData(u8 address)
|
||||
{
|
||||
u8 *ptr;
|
||||
__OSContEepromFormat eepromformat;
|
||||
int i;
|
||||
ptr = (u8 *)&__osEepPifRam.ramarray;
|
||||
for (i = 0; i < ARRLEN(__osEepPifRam.ramarray) + 1; i++)
|
||||
{
|
||||
__osEepPifRam.ramarray[i] = CONT_CMD_NOP;
|
||||
}
|
||||
__osEepPifRam.pifstatus = CONT_CMD_EXE;
|
||||
|
||||
eepromformat.txsize = CONT_CMD_READ_EEPROM_TX;
|
||||
eepromformat.rxsize = CONT_CMD_READ_EEPROM_RX;
|
||||
eepromformat.cmd = CONT_CMD_READ_EEPROM;
|
||||
eepromformat.address = address;
|
||||
for (i = 0; i < ARRLEN(eepromformat.data); i++)
|
||||
{
|
||||
eepromformat.data[i] = 0;
|
||||
}
|
||||
for (i = 0; i < 4; i++) //skip the first 4 bytes
|
||||
{
|
||||
*ptr++ = 0;
|
||||
}
|
||||
*(__OSContEepromFormat *)(ptr) = eepromformat;
|
||||
ptr += sizeof(__OSContEepromFormat);
|
||||
ptr[0] = CONT_CMD_END;
|
||||
}
|
167
src/core1/io/conteepwrite.c
Normal file
167
src/core1/io/conteepwrite.c
Normal file
@@ -0,0 +1,167 @@
|
||||
#include <os_internal.h>
|
||||
#include "controller.h"
|
||||
#include "siint.h"
|
||||
#include <rcp.h>
|
||||
|
||||
static void __osPackEepWriteData(u8 address, u8 *buffer);
|
||||
s32 osEepromWrite(OSMesgQueue *mq, u8 address, u8 *buffer)
|
||||
{
|
||||
|
||||
s32 ret;
|
||||
int i;
|
||||
u16 type;
|
||||
u8 *ptr;
|
||||
__OSContEepromFormat eepromformat;
|
||||
OSContStatus sdata;
|
||||
|
||||
ret = 0;
|
||||
ptr = (u8 *)&__osEepPifRam.ramarray;
|
||||
__osSiGetAccess();
|
||||
ret = __osEepStatus(mq, &sdata); //why is this duplicated?
|
||||
ret = __osEepStatus(mq, &sdata);
|
||||
|
||||
type = sdata.type & (CONT_EEPROM | CONT_EEP16K);
|
||||
|
||||
if (ret != 0)
|
||||
{
|
||||
__osSiRelAccess();
|
||||
return CONT_NO_RESPONSE_ERROR;
|
||||
}
|
||||
switch (type)
|
||||
{
|
||||
case CONT_EEPROM:
|
||||
if (address > EEPROM_MAXBLOCKS)
|
||||
{
|
||||
__osSiRelAccess();
|
||||
return -1;
|
||||
}
|
||||
|
||||
break;
|
||||
case CONT_EEPROM | CONT_EEP16K:
|
||||
if (address > EEP16K_MAXBLOCKS) //not technically possible
|
||||
{
|
||||
__osSiRelAccess();
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
__osSiRelAccess();
|
||||
return CONT_NO_RESPONSE_ERROR;
|
||||
break;
|
||||
}
|
||||
while (sdata.status & CONT_EEPROM_BUSY)
|
||||
{
|
||||
__osEepStatus(mq, &sdata);
|
||||
}
|
||||
__osPackEepWriteData(address, buffer);
|
||||
ret = __osSiRawStartDma(OS_WRITE, &__osEepPifRam); //send command to pif
|
||||
osRecvMesg(mq, NULL, OS_MESG_BLOCK);
|
||||
|
||||
for (i = 0; i < ARRLEN(__osEepPifRam.ramarray) + 1; i++) {
|
||||
__osEepPifRam.ramarray[i] = 0xFF;
|
||||
}
|
||||
|
||||
__osEepPifRam.pifstatus = 0;
|
||||
|
||||
ret = __osSiRawStartDma(OS_READ, &__osEepPifRam); //recv response
|
||||
__osContLastCmd = CONT_CMD_WRITE_EEPROM;
|
||||
osRecvMesg(mq, NULL, OS_MESG_BLOCK);
|
||||
for (i = 0; i < 4; i++) //skip the first 4 bytes
|
||||
{
|
||||
ptr++;
|
||||
}
|
||||
eepromformat = *(__OSContEepromFormat *)ptr;
|
||||
|
||||
//probably indicates an error, from PIF
|
||||
ret = CHNL_ERR(eepromformat); //TODO: remove magic constants
|
||||
|
||||
__osSiRelAccess();
|
||||
return ret;
|
||||
}
|
||||
static void __osPackEepWriteData(u8 address, u8 *buffer)
|
||||
{
|
||||
u8 *ptr;
|
||||
__OSContEepromFormat eepromformat;
|
||||
int i;
|
||||
ptr = (u8 *)&__osEepPifRam.ramarray;
|
||||
for (i = 0; i < ARRLEN(__osEepPifRam.ramarray) + 1; i++)
|
||||
{
|
||||
__osEepPifRam.ramarray[i] = CONT_CMD_NOP;
|
||||
}
|
||||
__osEepPifRam.pifstatus = CONT_CMD_EXE;
|
||||
|
||||
eepromformat.txsize = CONT_CMD_WRITE_EEPROM_TX;
|
||||
eepromformat.rxsize = CONT_CMD_WRITE_EEPROM_RX;
|
||||
eepromformat.cmd = CONT_CMD_WRITE_EEPROM;
|
||||
eepromformat.address = address;
|
||||
for (i = 0; i < ARRLEN(eepromformat.data); i++)
|
||||
{
|
||||
eepromformat.data[i] = *buffer++;
|
||||
}
|
||||
for (i = 0; i < 4; i++) //skip the first 4 bytes
|
||||
{
|
||||
*ptr++ = 0;
|
||||
}
|
||||
*(__OSContEepromFormat *)(ptr) = eepromformat;
|
||||
ptr += sizeof(__OSContEepromFormat);
|
||||
ptr[0] = CONT_CMD_END;
|
||||
}
|
||||
s32 __osEepStatus(OSMesgQueue *mq, OSContStatus *data)
|
||||
{
|
||||
s32 ret;
|
||||
int i;
|
||||
u8 *ptr;
|
||||
__OSContRequesFormat requestformat;
|
||||
|
||||
//addiu sp,sp,-48
|
||||
//lui t6,__osEepPifRam
|
||||
//addiu t6,t6,__osEepPifRam
|
||||
//sw ra,20(sp)
|
||||
//sw a0,48(sp)
|
||||
//sw a1,52(sp)
|
||||
//sw zero,44(sp)
|
||||
ret = 0;
|
||||
//sw t6,36(sp)
|
||||
ptr = (u8 *)__osEepPifRam.ramarray;
|
||||
//could be bset or bzero intrinsic
|
||||
for (i = 0; i < ARRLEN(__osEepPifRam.ramarray) + 1; i++) //still has the buffer overflow =/, just sets status to 0
|
||||
{
|
||||
__osEepPifRam.ramarray[i] = 0;
|
||||
}
|
||||
__osEepPifRam.pifstatus = CONT_CMD_EXE;
|
||||
ptr = (u8 *)__osEepPifRam.ramarray;
|
||||
for (i = 0; i < 4; i++) //zero 4 bytes?
|
||||
*ptr++ = 0;
|
||||
requestformat.dummy = CONT_CMD_NOP;
|
||||
requestformat.txsize = CONT_CMD_REQUEST_STATUS_TX;
|
||||
requestformat.rxsize = CONT_CMD_REQUEST_STATUS_RX;
|
||||
requestformat.cmd = CONT_CMD_REQUEST_STATUS;
|
||||
requestformat.typeh = CONT_CMD_NOP;
|
||||
requestformat.typel = CONT_CMD_NOP;
|
||||
requestformat.status = CONT_CMD_NOP;
|
||||
requestformat.dummy1 = CONT_CMD_NOP;
|
||||
*(__OSContRequesFormat *)ptr = requestformat;
|
||||
ptr += sizeof(__OSContRequesFormat);
|
||||
*ptr = CONT_CMD_END;
|
||||
|
||||
ret = __osSiRawStartDma(OS_WRITE, &__osEepPifRam);
|
||||
osRecvMesg(mq, NULL, OS_MESG_BLOCK);
|
||||
__osContLastCmd = CONT_CMD_REQUEST_STATUS;
|
||||
ret = __osSiRawStartDma(OS_READ, &__osEepPifRam);
|
||||
osRecvMesg(mq, NULL, OS_MESG_BLOCK);
|
||||
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
|
||||
ptr = (u8 *)&__osEepPifRam;
|
||||
for (i = 0; i < 4; i++)
|
||||
*ptr++ = 0;
|
||||
|
||||
requestformat = *(__OSContRequesFormat *)ptr;
|
||||
data->errno = CHNL_ERR(requestformat);
|
||||
data->type = (requestformat.typel << 8) | requestformat.typeh;
|
||||
data->status = requestformat.status;
|
||||
if (data->errno != 0)
|
||||
return data->errno;
|
||||
return 0;
|
||||
}
|
302
src/core1/io/contpfs.c
Normal file
302
src/core1/io/contpfs.c
Normal file
@@ -0,0 +1,302 @@
|
||||
#include <ultra64.h>
|
||||
#include "functions.h"
|
||||
#include "variables.h"
|
||||
#include "controller.h"
|
||||
|
||||
u16 __osSumcalc(u8 *ptr, int length)
|
||||
{
|
||||
int i;
|
||||
u32 sum;
|
||||
u8 *tmp;
|
||||
|
||||
sum = 0;
|
||||
tmp = ptr;
|
||||
for (i = 0; i < length; i++)
|
||||
{
|
||||
sum += *tmp++;
|
||||
sum &= 0xffff;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
s32 __osIdCheckSum(u16 *ptr, u16 *csum, u16 *icsum)
|
||||
{
|
||||
u16 data;
|
||||
u32 j;
|
||||
data = 0;
|
||||
*icsum = 0;
|
||||
*csum = *icsum;
|
||||
for (j = 0; j < 28; j += 2)
|
||||
{
|
||||
//feels like this should be a compiler optimization not manual..
|
||||
//but it doesn't match and I'm pretty sure this is just -O1
|
||||
data = *(u16 *)((u8 *)ptr + j);
|
||||
//data = ptr[j]
|
||||
*csum += data;
|
||||
*icsum += ~data;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
s32 __osRepairPackId(OSPfs *pfs, __OSPackId *badid, __OSPackId *newid)
|
||||
{
|
||||
|
||||
s32 ret;
|
||||
u8 temp[32];
|
||||
u8 comp[32];
|
||||
u8 mask;
|
||||
int i;
|
||||
int j;
|
||||
u16 index[4];
|
||||
|
||||
ret = 0;
|
||||
mask = 0;
|
||||
SET_ACTIVEBANK_TO_ZERO;
|
||||
newid->repaired = -1;
|
||||
newid->random = osGetCount();
|
||||
newid->serial_mid = badid->serial_mid;
|
||||
newid->serial_low = badid->serial_low;
|
||||
for (j = 0; j < PFS_MAX_BANKS;)
|
||||
{
|
||||
pfs->activebank = j;
|
||||
ERRCK(__osPfsSelectBank(pfs))
|
||||
ERRCK(__osContRamRead(pfs->queue, pfs->channel, 0, (u8*)&temp)); //TODO: fix magic number
|
||||
temp[0] = j | 0x80;
|
||||
for (i = 1; i < ARRLEN(temp); i++)
|
||||
{
|
||||
|
||||
temp[i] = ~temp[i];
|
||||
}
|
||||
|
||||
ERRCK(__osContRamWrite(pfs->queue, pfs->channel, 0, (u8*)temp, FALSE)); //oddr 0, don't force
|
||||
ERRCK(__osContRamRead(pfs->queue, pfs->channel, 0, (u8*)&comp));
|
||||
|
||||
for (i = 0; i < ARRLEN(temp); i++)
|
||||
{
|
||||
if (comp[i] != temp[i])
|
||||
break;
|
||||
}
|
||||
if (i != ARRLEN(temp))
|
||||
break;
|
||||
if (j > 0)
|
||||
{
|
||||
pfs->activebank = 0;
|
||||
ERRCK(__osPfsSelectBank(pfs));
|
||||
ERRCK(__osContRamRead(pfs->queue, pfs->channel, 0, (u8*)temp));
|
||||
if (temp[0] != 128)
|
||||
break; //TODO: remove magic constant
|
||||
}
|
||||
j++;
|
||||
}
|
||||
pfs->activebank = 0;
|
||||
ERRCK(__osPfsSelectBank(pfs));
|
||||
if (j > 0)
|
||||
mask = 1;
|
||||
else
|
||||
mask = 0;
|
||||
newid->deviceid = (badid->deviceid & (u16)~1) | mask;
|
||||
newid->banks = j;
|
||||
newid->version = badid->version;
|
||||
__osIdCheckSum((u16*)newid, &newid->checksum, &newid->inverted_checksum);
|
||||
index[0] = 1;
|
||||
index[1] = 3;
|
||||
index[2] = 4;
|
||||
index[3] = 6;
|
||||
for (i = 0; i < ARRLEN(index); i++)
|
||||
{
|
||||
ERRCK(__osContRamWrite(pfs->queue, pfs->channel, index[i], (u8*)newid, TRUE));
|
||||
}
|
||||
ERRCK(__osContRamRead(pfs->queue, pfs->channel, 1, (u8*)temp));
|
||||
for (i = 0; i < ARRLEN(temp); i++)
|
||||
{
|
||||
if (temp[i] != ((u8 *)newid)[i])
|
||||
return PFS_ERR_ID_FATAL;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
s32 __osCheckPackId(OSPfs *pfs, __OSPackId *temp)
|
||||
{
|
||||
u16 index[4];
|
||||
s32 ret;
|
||||
u16 sum;
|
||||
u16 isum;
|
||||
int i;
|
||||
int j;
|
||||
|
||||
ret = 0;
|
||||
SET_ACTIVEBANK_TO_ZERO;
|
||||
index[0] = 1;
|
||||
index[1] = 3;
|
||||
index[2] = 4;
|
||||
index[3] = 6;
|
||||
for (i = 1; i < ARRLEN(index); i++)
|
||||
{
|
||||
ERRCK(__osContRamRead(pfs->queue, pfs->channel, index[i], (u8*)temp));
|
||||
__osIdCheckSum((u16 *)temp, &sum, &isum);
|
||||
if (temp->checksum == sum && temp->inverted_checksum == isum)
|
||||
break;
|
||||
}
|
||||
if (i == ARRLEN(index))
|
||||
return PFS_ERR_ID_FATAL;
|
||||
|
||||
for (j = 0; j < ARRLEN(index); j++)
|
||||
{
|
||||
if (j != i)
|
||||
{
|
||||
ERRCK(__osContRamWrite(pfs->queue, pfs->channel, index[j], (u8*)temp, TRUE));
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
s32 __osGetId(OSPfs *pfs)
|
||||
{
|
||||
int k;
|
||||
u16 sum;
|
||||
u16 isum;
|
||||
u8 temp[32];
|
||||
__OSPackId newid;
|
||||
s32 ret;
|
||||
__OSPackId *id;
|
||||
|
||||
SET_ACTIVEBANK_TO_ZERO;
|
||||
ERRCK(__osContRamRead(pfs->queue, pfs->channel, 1, (u8*)temp));
|
||||
__osIdCheckSum((u16*)temp, &sum, &isum);
|
||||
id = (__OSPackId*)temp;
|
||||
if (id->checksum != sum || id->inverted_checksum != isum)
|
||||
{
|
||||
ret = __osCheckPackId(pfs, id);
|
||||
if (ret == PFS_ERR_ID_FATAL)
|
||||
{
|
||||
ERRCK(__osRepairPackId(pfs, id, &newid));
|
||||
id = &newid;
|
||||
}
|
||||
else if (ret != 0)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
if ((id->deviceid & 1) == 0) //TODO: remove magic constant
|
||||
{
|
||||
ERRCK(__osRepairPackId(pfs, id, &newid));
|
||||
id = &newid;
|
||||
if ((id->deviceid & 1) == 0)
|
||||
return PFS_ERR_DEVICE;
|
||||
}
|
||||
for (k = 0; k < ARRLEN(pfs->id); k++)
|
||||
{
|
||||
pfs->id[k] = ((u8 *)id)[k];
|
||||
}
|
||||
pfs->version = id->version;
|
||||
pfs->banks = id->banks;
|
||||
pfs->inode_start_page = pfs->banks * 2 + 3; //TODO: loads of magic constants..
|
||||
pfs->dir_size = 16;
|
||||
pfs->inode_table = 8;
|
||||
pfs->minode_table = pfs->banks * PFS_ONE_PAGE + 8;
|
||||
pfs->dir_table = pfs->minode_table + pfs->banks * PFS_ONE_PAGE;
|
||||
ERRCK(__osContRamRead(pfs->queue, pfs->channel, 7, pfs->label));
|
||||
return 0;
|
||||
}
|
||||
|
||||
s32 __osCheckId(OSPfs *pfs)
|
||||
{
|
||||
int k;
|
||||
u8 temp[32];
|
||||
s32 ret;
|
||||
|
||||
SET_ACTIVEBANK_TO_ZERO;
|
||||
ret = __osContRamRead(pfs->queue, pfs->channel, 1, (u8*)temp);
|
||||
if (ret != 0)
|
||||
{
|
||||
if (ret != 2)
|
||||
return ret;
|
||||
else
|
||||
ERRCK(__osContRamRead(pfs->queue, pfs->channel, 1, (u8*)temp));
|
||||
}
|
||||
|
||||
for (k = 0; k < ARRLEN(temp); k++)
|
||||
{
|
||||
if (pfs->id[k] != temp[k])
|
||||
return PFS_ERR_NEW_PACK;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
s32 __osPfsRWInode(OSPfs *pfs, __OSInode *inode, u8 flag, u8 bank)
|
||||
{
|
||||
u8 sum;
|
||||
int j;
|
||||
s32 ret;
|
||||
int offset;
|
||||
u8 *addr;
|
||||
|
||||
SET_ACTIVEBANK_TO_ZERO;
|
||||
|
||||
if (bank > 0)
|
||||
offset = 1;
|
||||
else
|
||||
offset = pfs->inode_start_page;
|
||||
|
||||
if (flag == PFS_WRITE)
|
||||
inode->inode_page[0].inode_t.page = __osSumcalc((u8*)&inode->inode_page[offset], (-offset) * 2 + 256);
|
||||
|
||||
for (j = 0; j < 8; j++)
|
||||
{
|
||||
addr = ((u8 *)inode->inode_page + j * 32); //TODO: don't like this =/ //maybe &inode->inode_table[j*PFS_ONE_PAGE].ipage or something
|
||||
if (flag == PFS_WRITE)
|
||||
{
|
||||
ret = __osContRamWrite(pfs->queue, pfs->channel, pfs->inode_table + bank * 8 + j, addr, FALSE);
|
||||
ret = __osContRamWrite(pfs->queue, pfs->channel, pfs->minode_table + bank * 8 + j, addr, FALSE);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = __osContRamRead(pfs->queue, pfs->channel, pfs->inode_table + bank * 8 + j, addr);
|
||||
}
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
}
|
||||
if (flag == PFS_READ)
|
||||
{
|
||||
sum = __osSumcalc((u8*)&inode->inode_page[offset], (-offset) * 2 + 256);
|
||||
if (sum != inode->inode_page[0].inode_t.page)
|
||||
{
|
||||
for (j = 0; j < PFS_ONE_PAGE; j++)
|
||||
{
|
||||
addr = ((u8 *)inode->inode_page + j * 32);
|
||||
ret = __osContRamRead(pfs->queue, pfs->channel, pfs->minode_table + bank * PFS_ONE_PAGE + j, addr);
|
||||
}
|
||||
if (sum != inode->inode_page[0].inode_t.page)
|
||||
return PFS_ERR_INCONSISTENT;
|
||||
for (j = 0; j < PFS_ONE_PAGE; j++)
|
||||
{
|
||||
addr = ((u8 *)inode->inode_page + j * 32);
|
||||
ret = __osContRamWrite(pfs->queue, pfs->channel, pfs->inode_table + bank * PFS_ONE_PAGE + j, addr, FALSE);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (j = 0; j < PFS_ONE_PAGE; j++)
|
||||
{
|
||||
addr = ((u8 *)inode->inode_page + j * 32);
|
||||
ret = __osContRamWrite(pfs->queue, pfs->channel, pfs->minode_table + bank * PFS_ONE_PAGE + j, addr, FALSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
s32 __osPfsSelectBank(OSPfs *pfs)
|
||||
{
|
||||
u8 temp[BLOCKSIZE];
|
||||
int i;
|
||||
s32 ret;
|
||||
ret = 0;
|
||||
for (i = 0; i < ARRLEN(temp); i++)
|
||||
{
|
||||
temp[i] = pfs->activebank;
|
||||
}
|
||||
ret = __osContRamWrite(pfs->queue, pfs->channel, 1024, (u8*)temp, FALSE);
|
||||
return ret;
|
||||
}
|
102
src/core1/io/contramread.c
Normal file
102
src/core1/io/contramread.c
Normal file
@@ -0,0 +1,102 @@
|
||||
#include <os_internal.h>
|
||||
#include <rcp.h>
|
||||
#include "controller.h"
|
||||
#include "siint.h"
|
||||
|
||||
static void __osPackRamReadData(int channel, u16 address);
|
||||
s32 __osContRamRead(OSMesgQueue *mq, int channel, u16 address, u8 *buffer)
|
||||
{
|
||||
s32 ret;
|
||||
int i;
|
||||
u8 *ptr;
|
||||
__OSContRamReadFormat ramreadformat;
|
||||
int retry;
|
||||
ret = 0;
|
||||
ptr = (u8 *)&__osPfsPifRam;
|
||||
retry = 2;
|
||||
__osSiGetAccess();
|
||||
__osContLastCmd = CONT_CMD_READ_MEMPACK;
|
||||
__osPackRamReadData(channel, address);
|
||||
ret = __osSiRawStartDma(OS_WRITE, &__osPfsPifRam);
|
||||
osRecvMesg(mq, NULL, OS_MESG_BLOCK);
|
||||
do
|
||||
{
|
||||
ret = __osSiRawStartDma(OS_READ, &__osPfsPifRam);
|
||||
osRecvMesg(mq, NULL, OS_MESG_BLOCK);
|
||||
ptr = (u8 *)&__osPfsPifRam;
|
||||
if (channel != 0)
|
||||
{
|
||||
for (i = 0; i < channel; i++)
|
||||
{
|
||||
ptr++;
|
||||
}
|
||||
}
|
||||
ramreadformat = *(__OSContRamReadFormat *)ptr;
|
||||
ret = CHNL_ERR(ramreadformat);
|
||||
if (ret == 0)
|
||||
{
|
||||
u8 c;
|
||||
c = __osContDataCrc((u8*)&ramreadformat.data);
|
||||
if (c != ramreadformat.datacrc)
|
||||
{
|
||||
ret = __osPfsGetStatus(mq, channel);
|
||||
if (ret != 0)
|
||||
{
|
||||
__osSiRelAccess();
|
||||
return ret;
|
||||
}
|
||||
ret = PFS_ERR_CONTRFAIL;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i < ARRLEN(ramreadformat.data); i++)
|
||||
{
|
||||
*buffer++ = ramreadformat.data[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = PFS_ERR_NOPACK;
|
||||
}
|
||||
if (ret != PFS_ERR_CONTRFAIL)
|
||||
break;
|
||||
} while (retry-- >= 0);
|
||||
__osSiRelAccess();
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void __osPackRamReadData(int channel, u16 address)
|
||||
{
|
||||
u8 *ptr;
|
||||
__OSContRamReadFormat ramreadformat;
|
||||
int i;
|
||||
|
||||
ptr = (u8 *)__osPfsPifRam.ramarray;
|
||||
|
||||
for (i = 0; i < ARRLEN(__osPfsPifRam.ramarray) + 1; i++) { // also clear pifstatus
|
||||
__osPfsPifRam.ramarray[i] = 0;
|
||||
}
|
||||
|
||||
__osPfsPifRam.pifstatus = CONT_CMD_EXE;
|
||||
ramreadformat.dummy = CONT_CMD_NOP;
|
||||
ramreadformat.txsize = CONT_CMD_READ_MEMPACK_TX;
|
||||
ramreadformat.rxsize = CONT_CMD_READ_MEMPACK_RX;
|
||||
ramreadformat.cmd = CONT_CMD_READ_MEMPACK;
|
||||
ramreadformat.address = (address << 0x5) | __osContAddressCrc(address);
|
||||
ramreadformat.datacrc = CONT_CMD_NOP;
|
||||
for (i = 0; i < ARRLEN(ramreadformat.data); i++)
|
||||
{
|
||||
ramreadformat.data[i] = CONT_CMD_NOP;
|
||||
}
|
||||
if (channel != 0)
|
||||
{
|
||||
for (i = 0; i < channel; i++)
|
||||
{
|
||||
*ptr++ = 0;
|
||||
}
|
||||
}
|
||||
*(__OSContRamReadFormat *)ptr = ramreadformat;
|
||||
ptr += sizeof(__OSContRamReadFormat);
|
||||
ptr[0] = CONT_CMD_END;
|
||||
}
|
94
src/core1/io/contramwrite.c
Normal file
94
src/core1/io/contramwrite.c
Normal file
@@ -0,0 +1,94 @@
|
||||
#include <os_internal.h>
|
||||
#include <rcp.h>
|
||||
#include "controller.h"
|
||||
#include "siint.h"
|
||||
|
||||
static void __osPackRamWriteData(int channel, u16 address, u8 *buffer);
|
||||
s32 __osContRamWrite(OSMesgQueue *mq, int channel, u16 address, u8 *buffer, int force)
|
||||
{
|
||||
s32 ret;
|
||||
int i;
|
||||
u8 *ptr;
|
||||
__OSContRamReadFormat ramreadformat;
|
||||
int retry;
|
||||
|
||||
ret = 0;
|
||||
ptr = (u8 *)&__osPfsPifRam;
|
||||
retry = 2;
|
||||
if (force != 1 && address < 7 && address != 0)
|
||||
return 0;
|
||||
__osSiGetAccess();
|
||||
__osContLastCmd = CONT_CMD_WRITE_MEMPACK;
|
||||
__osPackRamWriteData(channel, address, buffer);
|
||||
ret = __osSiRawStartDma(OS_WRITE, &__osPfsPifRam);
|
||||
osRecvMesg(mq, NULL, OS_MESG_BLOCK);
|
||||
do
|
||||
{
|
||||
ret = __osSiRawStartDma(OS_READ, &__osPfsPifRam);
|
||||
osRecvMesg(mq, NULL, OS_MESG_BLOCK);
|
||||
ptr = (u8 *)&__osPfsPifRam;
|
||||
if (channel != 0)
|
||||
for (i = 0; i < channel; i++)
|
||||
ptr++;
|
||||
|
||||
ramreadformat = *(__OSContRamReadFormat *)ptr;
|
||||
|
||||
ret = CHNL_ERR(ramreadformat);
|
||||
if (ret == 0)
|
||||
{
|
||||
if (__osContDataCrc(buffer) != ramreadformat.datacrc)
|
||||
{
|
||||
ret = __osPfsGetStatus(mq, channel);
|
||||
if (ret != 0)
|
||||
{
|
||||
__osSiRelAccess();
|
||||
return ret;
|
||||
}
|
||||
ret = PFS_ERR_CONTRFAIL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = PFS_ERR_NOPACK;
|
||||
}
|
||||
if (ret != PFS_ERR_CONTRFAIL)
|
||||
break;
|
||||
} while ((retry-- >= 0));
|
||||
__osSiRelAccess();
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void __osPackRamWriteData(int channel, u16 address, u8 *buffer)
|
||||
{
|
||||
u8 *ptr;
|
||||
__OSContRamReadFormat ramreadformat;
|
||||
int i;
|
||||
|
||||
ptr = (u8 *)__osPfsPifRam.ramarray;
|
||||
|
||||
for (i = 0; i < ARRLEN(__osPfsPifRam.ramarray) + 1; i++) { // also clear pifstatus
|
||||
__osPfsPifRam.ramarray[i] = 0;
|
||||
}
|
||||
|
||||
__osPfsPifRam.pifstatus = CONT_CMD_EXE;
|
||||
ramreadformat.dummy = CONT_CMD_NOP;
|
||||
ramreadformat.txsize = CONT_CMD_WRITE_MEMPACK_TX;
|
||||
ramreadformat.rxsize = CONT_CMD_WRITE_MEMPACK_RX;
|
||||
ramreadformat.cmd = CONT_CMD_WRITE_MEMPACK;
|
||||
ramreadformat.address = (address << 0x5) | __osContAddressCrc(address);
|
||||
ramreadformat.datacrc = CONT_CMD_NOP;
|
||||
for (i = 0; i < ARRLEN(ramreadformat.data); i++)
|
||||
{
|
||||
ramreadformat.data[i] = *buffer++;
|
||||
}
|
||||
if (channel != 0)
|
||||
{
|
||||
for (i = 0; i < channel; i++)
|
||||
{
|
||||
*ptr++ = 0;
|
||||
}
|
||||
}
|
||||
*(__OSContRamReadFormat *)ptr = ramreadformat;
|
||||
ptr += sizeof(__OSContRamReadFormat);
|
||||
ptr[0] = CONT_CMD_END;
|
||||
}
|
75
src/core1/io/contreaddata.c
Normal file
75
src/core1/io/contreaddata.c
Normal file
@@ -0,0 +1,75 @@
|
||||
#include <os_internal.h>
|
||||
#include <rcp.h>
|
||||
#include "siint.h"
|
||||
#include "controller.h"
|
||||
|
||||
static void __osPackReadData(void);
|
||||
s32 osContStartReadData(OSMesgQueue *mq)
|
||||
{
|
||||
s32 ret;
|
||||
int i;
|
||||
|
||||
ret = 0;
|
||||
__osSiGetAccess();
|
||||
if (__osContLastCmd != CONT_CMD_READ_BUTTON)
|
||||
{
|
||||
__osPackReadData();
|
||||
ret = __osSiRawStartDma(OS_WRITE, &__osContPifRam);
|
||||
osRecvMesg(mq, NULL, OS_MESG_BLOCK);
|
||||
}
|
||||
for (i = 0; i < ARRLEN(__osContPifRam.ramarray) + 1; i++)
|
||||
{
|
||||
__osContPifRam.ramarray[i] = 0xFF;
|
||||
}
|
||||
__osContPifRam.pifstatus = 0;
|
||||
ret = __osSiRawStartDma(OS_READ, &__osContPifRam);
|
||||
|
||||
__osContLastCmd = CONT_CMD_READ_BUTTON;
|
||||
__osSiRelAccess();
|
||||
return ret;
|
||||
}
|
||||
|
||||
void osContGetReadData(OSContPad *data)
|
||||
{
|
||||
u8 *ptr;
|
||||
__OSContReadFormat readformat;
|
||||
int i;
|
||||
ptr = (u8 *)&__osContPifRam.ramarray;
|
||||
for (i = 0; i < __osMaxControllers; i++, ptr += sizeof(__OSContReadFormat), data++)
|
||||
{
|
||||
readformat = *(__OSContReadFormat *)ptr;
|
||||
data->errno = CHNL_ERR(readformat);
|
||||
if (data->errno == 0)
|
||||
{
|
||||
data->button = readformat.button;
|
||||
data->stick_x = readformat.stick_x;
|
||||
data->stick_y = readformat.stick_y;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void __osPackReadData(void)
|
||||
{
|
||||
u8 *ptr;
|
||||
__OSContReadFormat readformat;
|
||||
int i;
|
||||
|
||||
ptr = (u8*)&__osContPifRam.ramarray;
|
||||
for (i = 0; i < ARRLEN(__osContPifRam.ramarray) + 1; i++)
|
||||
{
|
||||
__osContPifRam.ramarray[i] = 0;
|
||||
}
|
||||
__osContPifRam.pifstatus = CONT_CMD_EXE;
|
||||
readformat.dummy = CONT_CMD_NOP;
|
||||
readformat.txsize = CONT_CMD_READ_BUTTON_TX;
|
||||
readformat.rxsize = CONT_CMD_READ_BUTTON_RX;
|
||||
readformat.cmd = CONT_CMD_READ_BUTTON;
|
||||
readformat.button = -1;
|
||||
readformat.stick_x = -1;
|
||||
readformat.stick_y = -1;
|
||||
for(i=0; i < __osMaxControllers; i++){
|
||||
*(__OSContReadFormat*)ptr = readformat;
|
||||
ptr += sizeof(__OSContReadFormat);
|
||||
}
|
||||
*ptr = CONT_CMD_END;
|
||||
}
|
95
src/core1/io/controller.c
Normal file
95
src/core1/io/controller.c
Normal file
@@ -0,0 +1,95 @@
|
||||
#include <os_internal.h>
|
||||
#include <rcp.h>
|
||||
#include "controller.h"
|
||||
#include "siint.h"
|
||||
|
||||
#define HALF_A_SECOND OS_USEC_TO_CYCLES(500000)
|
||||
|
||||
u32 __osContinitialized = 0;
|
||||
OSPifRam __osContPifRam;
|
||||
u8 __osContLastCmd;
|
||||
u8 __osMaxControllers;
|
||||
OSTimer __osEepromTimer;
|
||||
OSMesgQueue __osEepromTimerQ;
|
||||
OSMesg __osEepromTimerMsg;
|
||||
s32 osContInit(OSMesgQueue *mq, u8 *bitpattern, OSContStatus *data)
|
||||
{
|
||||
OSMesg dummy;
|
||||
s32 ret;
|
||||
OSTime t;
|
||||
OSTimer mytimer;
|
||||
OSMesgQueue timerMesgQueue;
|
||||
|
||||
ret = 0;
|
||||
if (__osContinitialized)
|
||||
return ret;
|
||||
__osContinitialized = TRUE;
|
||||
t = osGetTime();
|
||||
if (500000 * osClockRate / 1000000 > t)
|
||||
{
|
||||
osCreateMesgQueue(&timerMesgQueue, &dummy, 1);
|
||||
osSetTimer(&mytimer, 500000 * osClockRate / 1000000 - t, 0, &timerMesgQueue, &dummy);
|
||||
osRecvMesg(&timerMesgQueue, &dummy, OS_MESG_BLOCK);
|
||||
}
|
||||
__osMaxControllers = MAXCONTROLLERS;
|
||||
__osPackRequestData(CONT_CMD_REQUEST_STATUS);
|
||||
|
||||
ret = __osSiRawStartDma(OS_WRITE, &__osContPifRam);
|
||||
osRecvMesg(mq, &dummy, OS_MESG_BLOCK);
|
||||
|
||||
ret = __osSiRawStartDma(OS_READ, &__osContPifRam);
|
||||
osRecvMesg(mq, &dummy, OS_MESG_BLOCK);
|
||||
__osContGetInitData(bitpattern, data);
|
||||
__osContLastCmd = CONT_CMD_REQUEST_STATUS;
|
||||
__osSiCreateAccessQueue();
|
||||
osCreateMesgQueue(&__osEepromTimerQ, &__osEepromTimerMsg, 1);
|
||||
return ret;
|
||||
}
|
||||
void __osContGetInitData(u8 *pattern, OSContStatus *data)
|
||||
{
|
||||
u8 *ptr;
|
||||
__OSContRequesFormat requestformat;
|
||||
int i;
|
||||
u8 bits;
|
||||
bits = 0;
|
||||
ptr = (u8 *)&__osContPifRam;
|
||||
for (i = 0; i < __osMaxControllers; i++, ptr += sizeof(__OSContRequesFormat), data++)
|
||||
{
|
||||
requestformat = *(__OSContRequesFormat *)ptr;
|
||||
data->errno = CHNL_ERR(requestformat);
|
||||
if (data->errno == 0)
|
||||
{
|
||||
data->type = (requestformat.typel << 8) | requestformat.typeh;
|
||||
data->status = requestformat.status;
|
||||
bits |= 1 << i;
|
||||
}
|
||||
}
|
||||
*pattern = bits;
|
||||
}
|
||||
void __osPackRequestData(u8 cmd)
|
||||
{
|
||||
u8 *ptr;
|
||||
__OSContRequesFormat requestformat;
|
||||
int i;
|
||||
for (i = 0; i < ARRLEN(__osContPifRam.ramarray) + 1; i++)
|
||||
{
|
||||
__osContPifRam.ramarray[i] = 0;
|
||||
}
|
||||
__osContPifRam.pifstatus = CONT_CMD_EXE;
|
||||
ptr = (u8 *)&__osContPifRam.ramarray;
|
||||
requestformat.dummy = CONT_CMD_NOP;
|
||||
requestformat.txsize = CONT_CMD_REQUEST_STATUS_TX;
|
||||
requestformat.rxsize = CONT_CMD_REQUEST_STATUS_RX;
|
||||
requestformat.cmd = cmd;
|
||||
requestformat.typeh = CONT_CMD_NOP;
|
||||
requestformat.typel = CONT_CMD_NOP;
|
||||
requestformat.status = CONT_CMD_NOP;
|
||||
requestformat.dummy1 = CONT_CMD_NOP;
|
||||
|
||||
for (i = 0; i < __osMaxControllers; i++)
|
||||
{
|
||||
*(__OSContRequesFormat *)ptr = requestformat;
|
||||
ptr += sizeof(__OSContRequesFormat);
|
||||
}
|
||||
ptr[0] = CONT_CMD_END;
|
||||
}
|
207
src/core1/io/controller.h
Executable file
207
src/core1/io/controller.h
Executable file
@@ -0,0 +1,207 @@
|
||||
#ifndef _CONTROLLER_H
|
||||
#define _CONTROLLER_H
|
||||
#include <os_internal.h>
|
||||
#include <rcp.h>
|
||||
|
||||
//should go somewhere else but
|
||||
#define ARRLEN(x) ((s32)(sizeof(x) / sizeof(x[0])))
|
||||
#define CHNL_ERR(format) ((format.rxsize & CHNL_ERR_MASK) >> 4)
|
||||
|
||||
typedef struct
|
||||
{
|
||||
/* 0x0 */ u32 ramarray[15];
|
||||
/* 0x3C */ u32 pifstatus;
|
||||
} OSPifRam;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
/* 0x0 */ u8 dummy;
|
||||
/* 0x1 */ u8 txsize;
|
||||
/* 0x2 */ u8 rxsize;
|
||||
/* 0x3 */ u8 cmd;
|
||||
/* 0x4 */ u16 button;
|
||||
/* 0x6 */ s8 stick_x;
|
||||
/* 0x7 */ s8 stick_y;
|
||||
} __OSContReadFormat;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
/* 0x0 */ u8 dummy;
|
||||
/* 0x1 */ u8 txsize;
|
||||
/* 0x2 */ u8 rxsize;
|
||||
/* 0x3 */ u8 cmd;
|
||||
/* 0x4 */ u8 typeh;
|
||||
/* 0x5 */ u8 typel;
|
||||
/* 0x6 */ u8 status;
|
||||
/* 0x7 */ u8 dummy1;
|
||||
} __OSContRequesFormat;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
/* 0x0 */ u8 txsize;
|
||||
/* 0x1 */ u8 rxsize;
|
||||
/* 0x2 */ u8 cmd;
|
||||
/* 0x3 */ u8 typeh;
|
||||
/* 0x4 */ u8 typel;
|
||||
/* 0x5 */ u8 status;
|
||||
} __OSContRequesFormatShort;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
/* 0x0 */ u8 dummy;
|
||||
/* 0x1 */ u8 txsize;
|
||||
/* 0x2 */ u8 rxsize;
|
||||
/* 0x3 */ u8 cmd;
|
||||
/* 0x4 */ u16 address;
|
||||
/* 0x6 */ u8 data[BLOCKSIZE];
|
||||
/* 0x26 */ u8 datacrc;
|
||||
} __OSContRamReadFormat;
|
||||
|
||||
typedef union {
|
||||
/* 0x0 */ struct
|
||||
{
|
||||
/* 0x0 */ u8 bank;
|
||||
/* 0x1 */ u8 page;
|
||||
} inode_t;
|
||||
/* 0x0 */ u16 ipage;
|
||||
} __OSInodeUnit;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
/* 0x0 */ u32 game_code;
|
||||
/* 0x4 */ u16 company_code;
|
||||
/* 0x6 */ __OSInodeUnit start_page;
|
||||
/* 0x8 */ u8 status;
|
||||
/* 0x9 */ s8 reserved;
|
||||
/* 0xA */ u16 data_sum;
|
||||
/* 0xC */ u8 ext_name[PFS_FILE_EXT_LEN];
|
||||
/* 0x10 */ u8 game_name[PFS_FILE_NAME_LEN];
|
||||
} __OSDir;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
/* 0x0 */ __OSInodeUnit inode_page[128];
|
||||
} __OSInode;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
/* 0x0 */ u32 repaired;
|
||||
/* 0x4 */ u32 random;
|
||||
/* 0x8 */ u64 serial_mid;
|
||||
/* 0x10 */ u64 serial_low;
|
||||
/* 0x18 */ u16 deviceid;
|
||||
/* 0x1A */ u8 banks;
|
||||
/* 0x1B */ u8 version;
|
||||
/* 0x1C */ u16 checksum;
|
||||
/* 0x1E */ u16 inverted_checksum;
|
||||
} __OSPackId;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
/* 0x0 */ u8 txsize;
|
||||
/* 0x1 */ u8 rxsize;
|
||||
/* 0x2 */ u8 cmd;
|
||||
/* 0x3 */ u8 address;
|
||||
/* 0x4 */ u8 data[EEPROM_BLOCK_SIZE];
|
||||
} __OSContEepromFormat;
|
||||
|
||||
//from: http://en64.shoutwiki.com/wiki/SI_Registers_Detailed#CONT_CMD_Usage
|
||||
#define CONT_CMD_REQUEST_STATUS 0
|
||||
#define CONT_CMD_READ_BUTTON 1
|
||||
#define CONT_CMD_READ_MEMPACK 2
|
||||
#define CONT_CMD_WRITE_MEMPACK 3
|
||||
#define CONT_CMD_READ_EEPROM 4
|
||||
#define CONT_CMD_WRITE_EEPROM 5
|
||||
#define CONT_CMD_RESET 0xff
|
||||
|
||||
#define CONT_CMD_REQUEST_STATUS_TX 1
|
||||
#define CONT_CMD_READ_BUTTON_TX 1
|
||||
#define CONT_CMD_READ_MEMPACK_TX 3
|
||||
#define CONT_CMD_WRITE_MEMPACK_TX 35
|
||||
#define CONT_CMD_READ_EEPROM_TX 2
|
||||
#define CONT_CMD_WRITE_EEPROM_TX 10
|
||||
#define CONT_CMD_RESET_TX 1
|
||||
|
||||
#define CONT_CMD_REQUEST_STATUS_RX 3
|
||||
#define CONT_CMD_READ_BUTTON_RX 4
|
||||
#define CONT_CMD_READ_MEMPACK_RX 33
|
||||
#define CONT_CMD_WRITE_MEMPACK_RX 1
|
||||
#define CONT_CMD_READ_EEPROM_RX 8
|
||||
#define CONT_CMD_WRITE_EEPROM_RX 1
|
||||
#define CONT_CMD_RESET_RX 3
|
||||
|
||||
#define CONT_CMD_NOP 0xff
|
||||
#define CONT_CMD_END 0xfe //indicates end of a command
|
||||
#define CONT_CMD_EXE 1 //set pif ram status byte to this to do a command
|
||||
|
||||
#define DIR_STATUS_EMPTY 0
|
||||
#define DIR_STATUS_UNKNOWN 1
|
||||
#define DIR_STATUS_OCCUPIED 2
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
/* 0x0 */ __OSInode inode;
|
||||
/* 0x100 */ u8 bank;
|
||||
/* 0x101 */ u8 map[256];
|
||||
} __OSInodeCache;
|
||||
|
||||
extern s32 __osEepStatus(OSMesgQueue *, OSContStatus *);
|
||||
u16 __osSumcalc(u8 *ptr, int length);
|
||||
s32 __osIdCheckSum(u16 *ptr, u16 *csum, u16 *icsum);
|
||||
s32 __osRepairPackId(OSPfs *pfs, __OSPackId *badid, __OSPackId *newid);
|
||||
s32 __osCheckPackId(OSPfs *pfs, __OSPackId *temp);
|
||||
s32 __osGetId(OSPfs *pfs);
|
||||
s32 __osCheckId(OSPfs *pfs);
|
||||
s32 __osPfsRWInode(OSPfs *pfs, __OSInode *inode, u8 flag, u8 bank);
|
||||
s32 __osPfsSelectBank(OSPfs *pfs);
|
||||
s32 __osPfsDeclearPage(OSPfs *pfs, __OSInode *inode, int file_size_in_pages, int *first_page, u8 bank, int *decleared, int *last_page);
|
||||
s32 __osPfsReleasePages(OSPfs *pfs, __OSInode *inode, u8 start_page, u16 *sum, u8 bank, __OSInodeUnit *last_page, int flag);
|
||||
s32 __osBlockSum(OSPfs *pfs, u8 page_no, u16 *sum, u8 bank);
|
||||
s32 __osContRamRead(OSMesgQueue *mq, int channel, u16 address, u8 *buffer);
|
||||
s32 __osContRamWrite(OSMesgQueue *mq, int channel, u16 address, u8 *buffer, int force);
|
||||
void __osContGetInitData(u8 *pattern, OSContStatus *data);
|
||||
void __osPackRequestData(u8 cmd);
|
||||
void __osPfsRequestData(u8 cmd);
|
||||
void __osPfsGetInitData(u8* pattern, OSContStatus* data);
|
||||
u8 __osContAddressCrc(u16 addr);
|
||||
u8 __osContDataCrc(u8 *data);
|
||||
s32 __osPfsGetStatus(OSMesgQueue *queue, int channel);
|
||||
|
||||
extern u8 __osContLastCmd;
|
||||
extern OSTimer __osEepromTimer;
|
||||
extern OSMesg __osEepromTimerMsg;
|
||||
extern OSMesgQueue __osEepromTimerQ;
|
||||
extern OSPifRam __osEepPifRam;
|
||||
extern OSPifRam __osContPifRam;
|
||||
extern OSPifRam __osPfsPifRam;
|
||||
extern u8 __osMaxControllers;
|
||||
|
||||
//some version of this almost certainly existed since there's plenty of times where it's used right before a return 0
|
||||
#define ERRCK(fn) \
|
||||
ret = fn; \
|
||||
if (ret != 0) \
|
||||
return ret;
|
||||
|
||||
#define SET_ACTIVEBANK_TO_ZERO \
|
||||
if (pfs->activebank != 0) \
|
||||
{ \
|
||||
pfs->activebank = 0; \
|
||||
ERRCK(__osPfsSelectBank(pfs)) \
|
||||
}
|
||||
|
||||
#define PFS_CHECK_ID \
|
||||
if (__osCheckId(pfs) == PFS_ERR_NEW_PACK) \
|
||||
return PFS_ERR_NEW_PACK;
|
||||
#endif
|
||||
|
||||
#define PFS_CHECK_STATUS \
|
||||
if ((pfs->status & PFS_INITIALIZED) == 0) \
|
||||
return PFS_ERR_INVALID;
|
||||
|
||||
#define PFS_GET_STATUS \
|
||||
__osSiGetAccess(); \
|
||||
ret = __osPfsGetStatus(queue, channel); \
|
||||
__osSiRelAccess(); \
|
||||
if (ret != 0) \
|
||||
return ret;
|
21
src/core1/io/contsetch.c
Normal file
21
src/core1/io/contsetch.c
Normal file
@@ -0,0 +1,21 @@
|
||||
#include <os_internal.h>
|
||||
#include "controller.h"
|
||||
#include "siint.h"
|
||||
|
||||
s32 osContSetCh(u8 ch)
|
||||
{
|
||||
s32 ret;
|
||||
ret = 0;
|
||||
__osSiGetAccess();
|
||||
if (ch > MAXCONTROLLERS)
|
||||
{
|
||||
__osMaxControllers = 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
__osMaxControllers = ch;
|
||||
}
|
||||
__osContLastCmd = CONT_CMD_END; //TODO: is this right?
|
||||
__osSiRelAccess();
|
||||
return ret;
|
||||
}
|
47
src/core1/io/crc.c
Normal file
47
src/core1/io/crc.c
Normal file
@@ -0,0 +1,47 @@
|
||||
#include <os_internal.h>
|
||||
|
||||
u8 __osContAddressCrc(u16 addr)
|
||||
{
|
||||
u8 temp;
|
||||
u8 temp2;
|
||||
int i;
|
||||
temp = 0;
|
||||
for (i = 0; i < 16; i++)
|
||||
{
|
||||
if (temp & 0x10)
|
||||
temp2 = 21;
|
||||
else
|
||||
temp2 = 0;
|
||||
|
||||
temp <<= 1;
|
||||
temp |= (u8)((addr & 0x400) ? 1 : 0);
|
||||
addr <<= 1;
|
||||
temp ^= temp2;
|
||||
}
|
||||
return temp & 0x1f;
|
||||
}
|
||||
u8 __osContDataCrc(u8 *data)
|
||||
{
|
||||
u8 temp;
|
||||
u8 temp2;
|
||||
int i;
|
||||
int j;
|
||||
temp = 0;
|
||||
for (i = 0; i <= 32; i++, data++)
|
||||
{
|
||||
for (j = 7; j >= 0; j--)
|
||||
{
|
||||
if (temp & 0x80)
|
||||
temp2 = 133;
|
||||
else
|
||||
temp2 = 0;
|
||||
temp <<= 1;
|
||||
if (i == 32)
|
||||
temp &= -1;
|
||||
else
|
||||
temp |= ((*data & (1 << j)) ? 1 : 0);
|
||||
temp ^= temp2;
|
||||
}
|
||||
}
|
||||
return temp;
|
||||
}
|
113
src/core1/io/devmgr.c
Normal file
113
src/core1/io/devmgr.c
Normal file
@@ -0,0 +1,113 @@
|
||||
#include <ultra64.h>
|
||||
#include "piint.h"
|
||||
|
||||
void __osDevMgrMain(void *args)
|
||||
{
|
||||
OSIoMesg *mb;
|
||||
OSMesg em;
|
||||
OSMesg dummy;
|
||||
s32 ret;
|
||||
OSDevMgr *dm;
|
||||
s32 messageSend;
|
||||
|
||||
messageSend = 0;
|
||||
mb = NULL;
|
||||
ret = 0;
|
||||
dm = (OSDevMgr *)args;
|
||||
while (TRUE)
|
||||
{
|
||||
osRecvMesg(dm->cmdQueue, (OSMesg)&mb, OS_MESG_BLOCK);
|
||||
if (mb->piHandle != NULL &&
|
||||
mb->piHandle->type == DEVICE_TYPE_64DD &&
|
||||
(mb->piHandle->transferInfo.cmdType == LEO_CMD_TYPE_0 ||
|
||||
mb->piHandle->transferInfo.cmdType == LEO_CMD_TYPE_1))
|
||||
{
|
||||
__OSBlockInfo *blockInfo;
|
||||
__OSTranxInfo *info;
|
||||
info = &mb->piHandle->transferInfo;
|
||||
blockInfo = &info->block[info->blockNum];
|
||||
info->sectorNum = -1;
|
||||
if (info->transferMode != LEO_SECTOR_MODE)
|
||||
{
|
||||
blockInfo->dramAddr = (void *)((u32)blockInfo->dramAddr - blockInfo->sectorSize);
|
||||
}
|
||||
if (info->transferMode == LEO_TRACK_MODE && mb->piHandle->transferInfo.cmdType == LEO_CMD_TYPE_0)
|
||||
messageSend = 1;
|
||||
else
|
||||
messageSend = 0;
|
||||
osRecvMesg(dm->acsQueue, &dummy, OS_MESG_BLOCK);
|
||||
__osResetGlobalIntMask(OS_IM_PI);
|
||||
osEPiRawWriteIo(mb->piHandle, LEO_BM_CTL, (info->bmCtlShadow | 0x80000000));
|
||||
while (TRUE)
|
||||
{
|
||||
|
||||
osRecvMesg(dm->evtQueue, &em, OS_MESG_BLOCK);
|
||||
info = &mb->piHandle->transferInfo;
|
||||
blockInfo = &info->block[info->blockNum];
|
||||
if (blockInfo->errStatus == LEO_ERROR_29)
|
||||
{
|
||||
u32 stat;
|
||||
osEPiRawWriteIo(mb->piHandle, LEO_BM_CTL, info->bmCtlShadow | LEO_BM_CTL_RESET); //TODO: remove magic constants
|
||||
osEPiRawWriteIo(mb->piHandle, LEO_BM_CTL, info->bmCtlShadow);
|
||||
osEPiRawReadIo(mb->piHandle, LEO_STATUS, &stat);
|
||||
|
||||
if (stat & LEO_STATUS_MECHANIC_INTERRUPT) //TODO: remove magic constants
|
||||
{
|
||||
osEPiRawWriteIo(mb->piHandle, LEO_BM_CTL, info->bmCtlShadow | LEO_BM_CTL_CLR_MECHANIC_INTR);
|
||||
}
|
||||
|
||||
blockInfo->errStatus = LEO_ERROR_4;
|
||||
IO_WRITE(PI_STATUS_REG, PI_CLR_INTR);
|
||||
__osSetGlobalIntMask(OS_IM_PI | SR_IBIT4);
|
||||
}
|
||||
osSendMesg(mb->hdr.retQueue, mb, OS_MESG_NOBLOCK);
|
||||
|
||||
if (messageSend != 1)
|
||||
break;
|
||||
if (mb->piHandle->transferInfo.block[0].errStatus != LEO_ERROR_GOOD)
|
||||
break;
|
||||
messageSend = 0;
|
||||
}
|
||||
osSendMesg(dm->acsQueue, NULL, OS_MESG_NOBLOCK);
|
||||
if (mb->piHandle->transferInfo.blockNum == 1)
|
||||
osYieldThread();
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (mb->hdr.type)
|
||||
{
|
||||
case OS_MESG_TYPE_DMAREAD:
|
||||
osRecvMesg(dm->acsQueue, &dummy, OS_MESG_BLOCK);
|
||||
ret = dm->dma(OS_READ, mb->devAddr, mb->dramAddr, mb->size);
|
||||
break;
|
||||
case OS_MESG_TYPE_DMAWRITE:
|
||||
osRecvMesg(dm->acsQueue, &dummy, OS_MESG_BLOCK);
|
||||
ret = dm->dma(OS_WRITE, mb->devAddr, mb->dramAddr, mb->size);
|
||||
break;
|
||||
case OS_MESG_TYPE_EDMAREAD:
|
||||
osRecvMesg(dm->acsQueue, &dummy, OS_MESG_BLOCK);
|
||||
ret = dm->edma(mb->piHandle, OS_READ, mb->devAddr, mb->dramAddr,
|
||||
mb->size);
|
||||
break;
|
||||
case OS_MESG_TYPE_EDMAWRITE:
|
||||
osRecvMesg(dm->acsQueue, &dummy, OS_MESG_BLOCK);
|
||||
ret = dm->edma(mb->piHandle, OS_WRITE, mb->devAddr, mb->dramAddr,
|
||||
mb->size);
|
||||
break;
|
||||
case OS_MESG_TYPE_LOOPBACK:
|
||||
osSendMesg(mb->hdr.retQueue, mb, OS_MESG_NOBLOCK);
|
||||
ret = -1;
|
||||
break;
|
||||
default:
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
if (ret == 0)
|
||||
{
|
||||
osRecvMesg(dm->evtQueue, &em, OS_MESG_BLOCK);
|
||||
osSendMesg(mb->hdr.retQueue, mb, OS_MESG_NOBLOCK);
|
||||
osSendMesg(dm->acsQueue, NULL, OS_MESG_NOBLOCK);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
6
src/core1/io/dpgetstat.c
Normal file
6
src/core1/io/dpgetstat.c
Normal file
@@ -0,0 +1,6 @@
|
||||
#include <os_internal.h>
|
||||
#include <rcp.h>
|
||||
|
||||
u32 osDpGetStatus(){
|
||||
return IO_READ(DPC_STATUS_REG);
|
||||
}
|
7
src/core1/io/dpsetstat.c
Normal file
7
src/core1/io/dpsetstat.c
Normal file
@@ -0,0 +1,7 @@
|
||||
#include <os_internal.h>
|
||||
#include <rcp.h>
|
||||
|
||||
void osDpSetStatus(u32 data)
|
||||
{
|
||||
IO_WRITE(DPC_STATUS_REG, data);
|
||||
}
|
66
src/core1/io/epirawdma.c
Normal file
66
src/core1/io/epirawdma.c
Normal file
@@ -0,0 +1,66 @@
|
||||
#include <ultra64.h>
|
||||
#include "functions.h"
|
||||
#include "variables.h"
|
||||
|
||||
extern OSPiHandle *__osCurrentHandle[2];
|
||||
|
||||
#define OS_RAMROM_STACKSIZE 1024
|
||||
|
||||
#ifndef WAIT_ON_IOBUSY
|
||||
#define WAIT_ON_IOBUSY(stat) \
|
||||
stat = IO_READ(PI_STATUS_REG); \
|
||||
while (stat & (PI_STATUS_IO_BUSY | PI_STATUS_DMA_BUSY)) \
|
||||
stat = IO_READ(PI_STATUS_REG);
|
||||
#endif
|
||||
|
||||
#define UPDATE_REG(reg, var) \
|
||||
if (cHandle->var != pihandle->var) \
|
||||
IO_WRITE(reg, pihandle->var);
|
||||
|
||||
#define EPI_SYNC(pihandle, stat, domain) \
|
||||
\
|
||||
WAIT_ON_IOBUSY(stat) \
|
||||
\
|
||||
domain = pihandle->domain; \
|
||||
if (__osCurrentHandle[domain] != pihandle) \
|
||||
{ \
|
||||
OSPiHandle *cHandle = __osCurrentHandle[domain]; \
|
||||
if (domain == PI_DOMAIN1) \
|
||||
{ \
|
||||
UPDATE_REG(PI_BSD_DOM1_LAT_REG, latency); \
|
||||
UPDATE_REG(PI_BSD_DOM1_PGS_REG, pageSize); \
|
||||
UPDATE_REG(PI_BSD_DOM1_RLS_REG, relDuration); \
|
||||
UPDATE_REG(PI_BSD_DOM1_PWD_REG, pulse); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
UPDATE_REG(PI_BSD_DOM2_LAT_REG, latency); \
|
||||
UPDATE_REG(PI_BSD_DOM2_PGS_REG, pageSize); \
|
||||
UPDATE_REG(PI_BSD_DOM2_RLS_REG, relDuration); \
|
||||
UPDATE_REG(PI_BSD_DOM2_PWD_REG, pulse); \
|
||||
} \
|
||||
__osCurrentHandle[domain] = pihandle; \
|
||||
}
|
||||
|
||||
s32 osEPiRawStartDma(OSPiHandle *pihandle, s32 direction, u32 devAddr, void *dramAddr, u32 size)
|
||||
{
|
||||
u32 stat;
|
||||
u32 domain;
|
||||
|
||||
EPI_SYNC(pihandle, stat, domain);
|
||||
|
||||
IO_WRITE(PI_DRAM_ADDR_REG, osVirtualToPhysical(dramAddr));
|
||||
IO_WRITE(PI_CART_ADDR_REG, K1_TO_PHYS(pihandle->baseAddress | devAddr));
|
||||
switch (direction)
|
||||
{
|
||||
case OS_READ:
|
||||
IO_WRITE(PI_WR_LEN_REG, size - 1);
|
||||
break;
|
||||
case OS_WRITE:
|
||||
IO_WRITE(PI_RD_LEN_REG, size - 1);
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
14
src/core1/io/epirawread.c
Normal file
14
src/core1/io/epirawread.c
Normal file
@@ -0,0 +1,14 @@
|
||||
#include <os_internal.h>
|
||||
#include <rcp.h>
|
||||
#include "piint.h"
|
||||
|
||||
s32 osEPiRawReadIo(OSPiHandle *pihandle, u32 devAddr, u32 *data)
|
||||
{
|
||||
register u32 stat;
|
||||
register u32 domain;
|
||||
|
||||
WAIT_ON_IOBUSY(stat);
|
||||
|
||||
*data = IO_READ(pihandle->baseAddress | devAddr);
|
||||
return 0;
|
||||
}
|
13
src/core1/io/epirawwrite.c
Normal file
13
src/core1/io/epirawwrite.c
Normal file
@@ -0,0 +1,13 @@
|
||||
#include <os_internal.h>
|
||||
#include "piint.h"
|
||||
|
||||
s32 osEPiRawWriteIo(OSPiHandle *pihandle, u32 devAddr, u32 data)
|
||||
{
|
||||
register u32 stat;
|
||||
register u32 domain;
|
||||
|
||||
WAIT_ON_IOBUSY(stat);
|
||||
|
||||
IO_WRITE(pihandle->baseAddress | devAddr, data);
|
||||
return 0;
|
||||
}
|
29
src/core1/io/leodiskinit.c
Normal file
29
src/core1/io/leodiskinit.c
Normal file
@@ -0,0 +1,29 @@
|
||||
#include <os_internal.h>
|
||||
#include <rcp.h>
|
||||
#include <os_libc.h>
|
||||
|
||||
OSPiHandle LeoDiskHandle;
|
||||
OSPiHandle *__osDiskHandle;
|
||||
OSPiHandle *osLeoDiskInit()
|
||||
{
|
||||
u32 saveMask;
|
||||
LeoDiskHandle.type = DEVICE_TYPE_64DD;
|
||||
LeoDiskHandle.baseAddress = PHYS_TO_K1(PI_DOM2_ADDR1);
|
||||
LeoDiskHandle.latency = 3;
|
||||
LeoDiskHandle.pulse = 6;
|
||||
LeoDiskHandle.pageSize = 6;
|
||||
LeoDiskHandle.relDuration = 2;
|
||||
LeoDiskHandle.domain = PI_DOMAIN2;
|
||||
IO_WRITE(PI_BSD_DOM2_LAT_REG, LeoDiskHandle.latency);
|
||||
IO_WRITE(PI_BSD_DOM2_PWD_REG, LeoDiskHandle.pulse);
|
||||
IO_WRITE(PI_BSD_DOM2_PGS_REG, LeoDiskHandle.pageSize);
|
||||
IO_WRITE(PI_BSD_DOM2_RLS_REG, LeoDiskHandle.relDuration);
|
||||
LeoDiskHandle.speed = 0;
|
||||
bzero(&LeoDiskHandle.transferInfo, sizeof(__OSTranxInfo));
|
||||
saveMask = __osDisableInt();
|
||||
LeoDiskHandle.next = __osPiTable;
|
||||
__osPiTable = &LeoDiskHandle;
|
||||
__osDiskHandle = &LeoDiskHandle;
|
||||
__osRestoreInt(saveMask);
|
||||
return &LeoDiskHandle;
|
||||
}
|
214
src/core1/io/leointerrupt.c
Normal file
214
src/core1/io/leointerrupt.c
Normal file
@@ -0,0 +1,214 @@
|
||||
#include <ultra64.h>
|
||||
#include "osint.h"
|
||||
#include "piint.h"
|
||||
|
||||
#define WAIT_ON_IOBUSY2(stat) \
|
||||
stat = IO_READ(PI_STATUS_REG); \
|
||||
while (stat & (PI_STATUS_IO_BUSY | PI_STATUS_DMA_BUSY)) \
|
||||
stat = IO_READ(PI_STATUS_REG);
|
||||
|
||||
static void __osLeoResume(void);
|
||||
static void __osLeoAbnormalResume(void);
|
||||
|
||||
extern OSThread *__osRunQueue;
|
||||
extern OSIntMask __OSGlobalIntMask;
|
||||
extern OSPiHandle *__osDiskHandle;
|
||||
|
||||
u8 leoDiskStack[OS_PIM_STACKSIZE];
|
||||
s32 __osLeoInterrupt()
|
||||
{
|
||||
u32 stat;
|
||||
volatile u32 pi_stat;
|
||||
u32 bm_stat;
|
||||
__OSTranxInfo *info;
|
||||
__OSBlockInfo *blockInfo;
|
||||
stat = 0;
|
||||
info = &__osDiskHandle->transferInfo;
|
||||
blockInfo = &info->block[info->blockNum];
|
||||
pi_stat = IO_READ(PI_STATUS_REG);
|
||||
if (pi_stat & PI_STATUS_DMA_BUSY)
|
||||
{
|
||||
__OSGlobalIntMask = __OSGlobalIntMask & ~SR_IBIT4; //cartridge interrupt
|
||||
blockInfo->errStatus = LEO_ERROR_29;
|
||||
__osLeoResume();
|
||||
return 1;
|
||||
}
|
||||
WAIT_ON_IOBUSY(pi_stat);
|
||||
stat = IO_READ(LEO_STATUS);
|
||||
if (stat & LEO_STATUS_MECHANIC_INTERRUPT)
|
||||
{
|
||||
WAIT_ON_IOBUSY(pi_stat);
|
||||
IO_WRITE(LEO_BM_CTL, info->bmCtlShadow | LEO_BM_CTL_CLR_MECHANIC_INTR);
|
||||
blockInfo->errStatus = LEO_ERROR_GOOD;
|
||||
return 0;
|
||||
}
|
||||
if (info->cmdType == LEO_CMD_TYPE_2)
|
||||
return 1;
|
||||
if (stat & LEO_STATUS_BUFFER_MANAGER_ERROR)
|
||||
{
|
||||
WAIT_ON_IOBUSY(pi_stat);
|
||||
stat = IO_READ(LEO_STATUS);
|
||||
blockInfo->errStatus = LEO_ERROR_22;
|
||||
__osLeoResume();
|
||||
IO_WRITE(PI_STATUS_REG, PI_STATUS_CLR_INTR);
|
||||
__OSGlobalIntMask |= OS_IM_PI;
|
||||
return 1;
|
||||
}
|
||||
if (info->cmdType == LEO_CMD_TYPE_1)
|
||||
{
|
||||
if ((stat & LEO_STATUS_DATA_REQUEST) == 0)
|
||||
{
|
||||
if (info->sectorNum + 1 != info->transferMode * 85)
|
||||
{
|
||||
blockInfo->errStatus = LEO_ERROR_24;
|
||||
__osLeoAbnormalResume();
|
||||
return 1;
|
||||
}
|
||||
IO_WRITE(PI_STATUS_REG, PI_STATUS_CLR_INTR);
|
||||
__OSGlobalIntMask |= OS_IM_PI;
|
||||
blockInfo->errStatus = LEO_ERROR_GOOD;
|
||||
__osLeoResume();
|
||||
return 1;
|
||||
}
|
||||
blockInfo->dramAddr = (void *)((u32)blockInfo->dramAddr + blockInfo->sectorSize);
|
||||
info->sectorNum++;
|
||||
osEPiRawStartDma(__osDiskHandle, OS_WRITE, LEO_SECTOR_BUFF, blockInfo->dramAddr, blockInfo->sectorSize);
|
||||
return 1;
|
||||
}
|
||||
if (info->cmdType == LEO_CMD_TYPE_0)
|
||||
{
|
||||
if (info->transferMode == LEO_SECTOR_MODE)
|
||||
{
|
||||
if ((s32)blockInfo->C1ErrNum + 17 < info->sectorNum)
|
||||
{
|
||||
blockInfo->errStatus = LEO_ERROR_GOOD;
|
||||
__osLeoAbnormalResume();
|
||||
return 1;
|
||||
}
|
||||
if ((stat & LEO_STATUS_DATA_REQUEST) == 0)
|
||||
{
|
||||
blockInfo->errStatus = LEO_ERROR_23;
|
||||
__osLeoAbnormalResume();
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
blockInfo->dramAddr = (void *)((u32)blockInfo->dramAddr + blockInfo->sectorSize);
|
||||
}
|
||||
bm_stat = IO_READ(LEO_BM_STATUS);
|
||||
if ((bm_stat & LEO_BM_STATUS_C1SINGLE && bm_stat & LEO_BM_STATUS_C1DOUBLE) || bm_stat & LEO_BM_STATUS_MICRO)
|
||||
{
|
||||
if (blockInfo->C1ErrNum > 3)
|
||||
{
|
||||
if (info->transferMode != LEO_SECTOR_MODE || info->sectorNum > 0x52)
|
||||
{
|
||||
blockInfo->errStatus = LEO_ERROR_23;
|
||||
__osLeoAbnormalResume();
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int errNum = blockInfo->C1ErrNum;
|
||||
blockInfo->C1ErrSector[errNum] = info->sectorNum + 1;
|
||||
}
|
||||
blockInfo->C1ErrNum += 1;
|
||||
}
|
||||
if (stat & LEO_STATUS_C2_TRANSFER)
|
||||
{
|
||||
if (info->sectorNum + 1 != 88)
|
||||
{
|
||||
blockInfo->errStatus = LEO_ERROR_24;
|
||||
__osLeoAbnormalResume();
|
||||
}
|
||||
if (info->transferMode == LEO_TRACK_MODE && info->blockNum == 0)
|
||||
{
|
||||
info->blockNum = 1;
|
||||
info->sectorNum = -1;
|
||||
info->block[1].dramAddr = (void *)((u32)info->block[1].dramAddr - info->block[1].sectorSize);
|
||||
|
||||
blockInfo->errStatus = LEO_ERROR_22;
|
||||
}
|
||||
else
|
||||
{
|
||||
IO_WRITE(PI_STATUS_REG, PI_STATUS_CLR_INTR);
|
||||
__OSGlobalIntMask |= OS_IM_PI;
|
||||
info->cmdType = LEO_CMD_TYPE_2;
|
||||
blockInfo->errStatus = LEO_ERROR_GOOD;
|
||||
}
|
||||
osEPiRawStartDma(__osDiskHandle, OS_READ, LEO_C2_BUFF, blockInfo->C2Addr, blockInfo->sectorSize * 4);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (info->sectorNum == -1 && info->transferMode == LEO_TRACK_MODE && info->blockNum == 1)
|
||||
{
|
||||
__OSBlockInfo *bptr = &info->block[0];
|
||||
if (bptr->C1ErrNum == 0)
|
||||
{
|
||||
if (((u32 *)bptr->C2Addr)[0] | ((u32 *)bptr->C2Addr)[1] | ((u32 *)bptr->C2Addr)[2] | ((u32 *)bptr->C2Addr)[3])
|
||||
{
|
||||
bptr->errStatus = LEO_ERROR_24;
|
||||
__osLeoAbnormalResume();
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
bptr->errStatus = 0;
|
||||
__osLeoResume();
|
||||
}
|
||||
info->sectorNum++;
|
||||
if (stat & LEO_STATUS_DATA_REQUEST)
|
||||
{
|
||||
if (info->sectorNum > 0x54)
|
||||
{
|
||||
blockInfo->errStatus = LEO_ERROR_24;
|
||||
__osLeoAbnormalResume();
|
||||
return 1;
|
||||
}
|
||||
osEPiRawStartDma(__osDiskHandle, 0, LEO_SECTOR_BUFF, blockInfo->dramAddr, blockInfo->sectorSize);
|
||||
blockInfo->errStatus = LEO_ERROR_GOOD;
|
||||
return 1;
|
||||
}
|
||||
if (info->sectorNum <= 0x54)
|
||||
{
|
||||
blockInfo->errStatus = LEO_ERROR_24;
|
||||
__osLeoAbnormalResume();
|
||||
return 1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
blockInfo->errStatus = LEO_ERROR_4;
|
||||
__osLeoAbnormalResume();
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void __osLeoAbnormalResume(void)
|
||||
{
|
||||
__OSTranxInfo *info;
|
||||
u32 pi_stat;
|
||||
info = &__osDiskHandle->transferInfo;
|
||||
pi_stat = pi_stat;
|
||||
WAIT_ON_IOBUSY2(pi_stat);
|
||||
IO_WRITE(LEO_BM_CTL, info->bmCtlShadow | LEO_BM_CTL_RESET);
|
||||
WAIT_ON_IOBUSY2(pi_stat);
|
||||
IO_WRITE(LEO_BM_CTL, info->bmCtlShadow);
|
||||
__osLeoResume();
|
||||
IO_WRITE(PI_STATUS_REG, PI_STATUS_CLR_INTR);
|
||||
__OSGlobalIntMask |= OS_IM_PI;
|
||||
}
|
||||
|
||||
static void __osLeoResume(void)
|
||||
{
|
||||
__OSEventState *es;
|
||||
OSMesgQueue *mq;
|
||||
s32 last;
|
||||
es = &__osEventStateTab[OS_EVENT_PI];
|
||||
mq = es->messageQueue;
|
||||
if (mq == NULL || MQ_IS_FULL(mq))
|
||||
return;
|
||||
last = (mq->first + mq->validCount) % mq->msgCount;
|
||||
mq->msg[last] = es->message;
|
||||
mq->validCount++;
|
||||
if (mq->mtqueue->next != NULL)
|
||||
__osEnqueueThread(&__osRunQueue, __osPopThread(&mq->mtqueue));
|
||||
}
|
170
src/core1/io/motor.c
Normal file
170
src/core1/io/motor.c
Normal file
@@ -0,0 +1,170 @@
|
||||
#include <os_internal.h>
|
||||
#include "controller.h"
|
||||
#include "siint.h"
|
||||
|
||||
static void _MakeMotorData(int channel, u16 address, u8 *buffer, OSPifRam *mdata);
|
||||
// u32 __osMotorinitialized[MAXCONTROLLERS] = {0, 0, 0, 0};
|
||||
OSPifRam _MotorStopData[MAXCONTROLLERS];
|
||||
OSPifRam _MotorStartData[MAXCONTROLLERS];
|
||||
u8 _motorstopbuf[32];
|
||||
u8 _motorstartbuf[32];
|
||||
s32 osMotorStop(OSPfs *pfs)
|
||||
{
|
||||
int i;
|
||||
s32 ret;
|
||||
u8 *ptr;
|
||||
__OSContRamReadFormat ramreadformat;
|
||||
|
||||
ptr = (u8 *)&__osPfsPifRam;
|
||||
|
||||
// if (!__osMotorinitialized[pfs->channel])
|
||||
// return PFS_ERR_INVALID;
|
||||
|
||||
__osSiGetAccess();
|
||||
|
||||
__osContLastCmd = CONT_CMD_WRITE_MEMPACK;
|
||||
__osSiRawStartDma(OS_WRITE, &_MotorStopData[pfs->channel]);
|
||||
osRecvMesg(pfs->queue, NULL, OS_MESG_BLOCK);
|
||||
ret = __osSiRawStartDma(OS_READ, &__osPfsPifRam);
|
||||
osRecvMesg(pfs->queue, NULL, OS_MESG_BLOCK);
|
||||
ptr = (u8 *)&__osPfsPifRam;
|
||||
|
||||
if (pfs->channel != 0)
|
||||
for (i = 0; i < pfs->channel; i++)
|
||||
ptr++;
|
||||
|
||||
ramreadformat = *(__OSContRamReadFormat *)ptr;
|
||||
ret = CHNL_ERR(ramreadformat);
|
||||
if (ret == 0 && ramreadformat.datacrc != 0) //!= __osContDataCrc((u8*)&_motorstopbuf))
|
||||
{
|
||||
ret = PFS_ERR_CONTRFAIL;
|
||||
}
|
||||
__osSiRelAccess();
|
||||
return ret;
|
||||
}
|
||||
|
||||
s32 osMotorStart(OSPfs *pfs)
|
||||
{
|
||||
|
||||
int i;
|
||||
s32 ret;
|
||||
u8 *ptr;
|
||||
__OSContRamReadFormat ramreadformat;
|
||||
|
||||
ptr = (u8 *)&__osPfsPifRam;
|
||||
|
||||
// if (!__osMotorinitialized[pfs->channel])
|
||||
// return PFS_ERR_INVALID;
|
||||
|
||||
__osSiGetAccess();
|
||||
|
||||
__osContLastCmd = CONT_CMD_WRITE_MEMPACK;
|
||||
__osSiRawStartDma(OS_WRITE, &_MotorStartData[pfs->channel]);
|
||||
osRecvMesg(pfs->queue, NULL, OS_MESG_BLOCK);
|
||||
ret = __osSiRawStartDma(OS_READ, &__osPfsPifRam);
|
||||
osRecvMesg(pfs->queue, NULL, OS_MESG_BLOCK);
|
||||
ptr = (u8 *)&__osPfsPifRam;
|
||||
|
||||
if (pfs->channel != 0)
|
||||
for (i = 0; i < pfs->channel; i++)
|
||||
ptr++;
|
||||
|
||||
ramreadformat = *(__OSContRamReadFormat *)ptr;
|
||||
ret = CHNL_ERR(ramreadformat);
|
||||
if (ret == 0 && ramreadformat.datacrc != 0xEB)//__osContDataCrc((u8*)&_motorstartbuf))
|
||||
{
|
||||
ret = PFS_ERR_CONTRFAIL;
|
||||
}
|
||||
__osSiRelAccess();
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void _MakeMotorData(int channel, u16 address, u8 *buffer, OSPifRam *mdata)
|
||||
{
|
||||
u8 *ptr;
|
||||
__OSContRamReadFormat ramreadformat;
|
||||
int i;
|
||||
|
||||
ptr = (u8 *)mdata->ramarray;
|
||||
for (i = 0; i < ARRLEN(mdata->ramarray); i++)
|
||||
mdata->ramarray[i] = 0;
|
||||
mdata->pifstatus = CONT_CMD_EXE;
|
||||
ramreadformat.dummy = CONT_CMD_NOP;
|
||||
ramreadformat.txsize = CONT_CMD_WRITE_MEMPACK_TX;
|
||||
ramreadformat.rxsize = CONT_CMD_WRITE_MEMPACK_RX;
|
||||
ramreadformat.cmd = CONT_CMD_WRITE_MEMPACK;
|
||||
|
||||
ramreadformat.address = (address << 0x5) | __osContAddressCrc(address);
|
||||
ramreadformat.datacrc = CONT_CMD_NOP;
|
||||
for (i = 0; i < ARRLEN(ramreadformat.data); i++)
|
||||
|
||||
ramreadformat.data[i] = *buffer++;
|
||||
if (channel != 0)
|
||||
{
|
||||
for (i = 0; i < channel; i++)
|
||||
{
|
||||
*ptr++ = 0;
|
||||
}
|
||||
}
|
||||
*(__OSContRamReadFormat *)ptr = ramreadformat;
|
||||
ptr += sizeof(__OSContRamReadFormat);
|
||||
ptr[0] = CONT_CMD_END;
|
||||
}
|
||||
|
||||
s32 osMotorInit(OSMesgQueue *mq, OSPfs *pfs, int channel)
|
||||
{
|
||||
int i;
|
||||
s32 ret;
|
||||
u8 temp[32];
|
||||
pfs->queue = mq;
|
||||
pfs->channel = channel;
|
||||
pfs->status = 0;
|
||||
pfs->activebank = 128;
|
||||
|
||||
for (i = 0; i < ARRLEN(temp); i++)
|
||||
temp[i] = 0x80;
|
||||
|
||||
ret = __osContRamWrite(mq, channel, 1024, temp, FALSE);
|
||||
if (ret == 2) //TODO: remove magic constant
|
||||
ret = __osContRamWrite(mq, channel, 1024, temp, FALSE);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
|
||||
ret = __osContRamRead(mq, channel, 1024, temp);
|
||||
if (ret == 2)
|
||||
ret = PFS_ERR_CONTRFAIL; //is this right?
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
if (temp[31] != 0x80)
|
||||
return PFS_ERR_DEVICE;
|
||||
|
||||
// for (i = 0; i < ARRLEN(temp); i++)
|
||||
// temp[i] = 128;
|
||||
|
||||
// ret = __osContRamWrite(mq, channel, 1024, temp, FALSE);
|
||||
// if (ret == 2)
|
||||
// ret = __osContRamWrite(mq, channel, 1024, temp, FALSE);
|
||||
// if (ret != 0)
|
||||
// return ret;
|
||||
|
||||
// ret = __osContRamRead(mq, channel, 1024, temp);
|
||||
// if (ret == 2)
|
||||
// ret = PFS_ERR_CONTRFAIL;
|
||||
// if (ret != 0)
|
||||
// return ret;
|
||||
// if (temp[31] != 128)
|
||||
// return PFS_ERR_DEVICE;
|
||||
|
||||
// if (!__osMotorinitialized[channel])
|
||||
// {
|
||||
for (i = 0; i < ARRLEN(_motorstartbuf); i++)
|
||||
{
|
||||
_motorstartbuf[i] = 1;
|
||||
_motorstopbuf[i] = 0;
|
||||
}
|
||||
_MakeMotorData(channel, 1536, _motorstartbuf, &_MotorStartData[channel]);
|
||||
_MakeMotorData(channel, 1536, _motorstopbuf, &_MotorStopData[channel]);
|
||||
// __osMotorinitialized[channel] = 1;
|
||||
// }
|
||||
return 0;
|
||||
}
|
207
src/core1/io/pfschecker.c
Normal file
207
src/core1/io/pfschecker.c
Normal file
@@ -0,0 +1,207 @@
|
||||
#include <os_internal.h>
|
||||
#include "controller.h"
|
||||
|
||||
s32 corrupted_init(OSPfs *pfs, __OSInodeCache *cache);
|
||||
s32 corrupted(OSPfs *pfs, __OSInodeUnit fpage, __OSInodeCache *cache);
|
||||
s32 osPfsChecker(OSPfs *pfs)
|
||||
{
|
||||
int j; //1156
|
||||
s32 ret; //1152
|
||||
__OSInodeUnit next_page;
|
||||
__OSInode checked_inode;
|
||||
__OSInode tmp_inode; //636
|
||||
__OSDir tmp_dir;
|
||||
__OSInodeUnit file_next_node[16];
|
||||
__OSInodeCache cache; //56
|
||||
int fixed; //52
|
||||
u8 bank; //51
|
||||
s32 cc; //44
|
||||
s32 cl; //40
|
||||
int offset; //36
|
||||
|
||||
fixed = 0;
|
||||
ret = __osCheckId(pfs);
|
||||
if (ret == PFS_ERR_NEW_PACK)
|
||||
ret = __osGetId(pfs);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
ERRCK(corrupted_init(pfs, &cache));
|
||||
for (j = 0; j < pfs->dir_size; j++)
|
||||
{
|
||||
ERRCK(__osContRamRead(pfs->queue, pfs->channel, pfs->dir_table + j, (u8*)&tmp_dir));
|
||||
if (tmp_dir.company_code != 0 && tmp_dir.game_code != 0)
|
||||
{
|
||||
next_page = tmp_dir.start_page;
|
||||
cc = 0;
|
||||
cl = 0;
|
||||
bank = 255;
|
||||
while (next_page.ipage >= pfs->inode_start_page && next_page.inode_t.bank < pfs->banks && next_page.inode_t.page > 0 && next_page.inode_t.page < 128)
|
||||
{
|
||||
if (bank != next_page.inode_t.bank)
|
||||
{
|
||||
bank = next_page.inode_t.bank;
|
||||
ret = __osPfsRWInode(pfs, &tmp_inode, OS_READ, bank);
|
||||
if (ret != 0 && ret != PFS_ERR_INCONSISTENT)
|
||||
return ret;
|
||||
}
|
||||
cc = corrupted(pfs, next_page, &cache) - cl;
|
||||
if (cc != 0)
|
||||
break;
|
||||
cl = 1;
|
||||
next_page = tmp_inode.inode_page[next_page.inode_t.page];
|
||||
}
|
||||
if (cc == 0 && next_page.ipage == 1)
|
||||
continue;
|
||||
|
||||
tmp_dir.company_code = 0;
|
||||
tmp_dir.game_code = 0;
|
||||
tmp_dir.start_page.ipage = 0;
|
||||
tmp_dir.status = DIR_STATUS_EMPTY;
|
||||
tmp_dir.data_sum = 0;
|
||||
SET_ACTIVEBANK_TO_ZERO;
|
||||
ERRCK(__osContRamWrite(pfs->queue, pfs->channel, pfs->dir_table + j, (u8*)&tmp_dir, FALSE));
|
||||
fixed++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (tmp_dir.company_code == 0 && tmp_dir.game_code == 0)
|
||||
continue;
|
||||
tmp_dir.company_code = 0;
|
||||
tmp_dir.game_code = 0;
|
||||
tmp_dir.start_page.ipage = 0;
|
||||
tmp_dir.status = DIR_STATUS_EMPTY;
|
||||
tmp_dir.data_sum = 0;
|
||||
|
||||
SET_ACTIVEBANK_TO_ZERO;
|
||||
ERRCK(__osContRamWrite(pfs->queue, pfs->channel, pfs->dir_table + j, (u8*)&tmp_dir, FALSE));
|
||||
fixed++;
|
||||
}
|
||||
}
|
||||
for (j = 0; j < pfs->dir_size; j++)
|
||||
{
|
||||
ERRCK(__osContRamRead(pfs->queue, pfs->channel, pfs->dir_table + j, (u8*)&tmp_dir));
|
||||
|
||||
if (tmp_dir.company_code != 0 && tmp_dir.game_code != 0 &&
|
||||
tmp_dir.start_page.ipage >= ((__OSInodeUnit *)&(pfs->inode_start_page) + 1)->ipage) //weird
|
||||
{
|
||||
file_next_node[j].ipage = tmp_dir.start_page.ipage;
|
||||
}
|
||||
else
|
||||
{
|
||||
file_next_node[j].ipage = 0;
|
||||
}
|
||||
}
|
||||
for (bank = 0; bank < pfs->banks; bank++)
|
||||
{
|
||||
ret = __osPfsRWInode(pfs, &tmp_inode, 0, bank);
|
||||
if (ret != 0 && ret != PFS_ERR_INCONSISTENT)
|
||||
return ret;
|
||||
if (bank > 0)
|
||||
{
|
||||
offset = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
offset = pfs->inode_start_page;
|
||||
}
|
||||
for (j = 0; j < offset; j++)
|
||||
{
|
||||
checked_inode.inode_page[j].ipage = tmp_inode.inode_page[j].ipage;
|
||||
}
|
||||
for (; j < 128; j++)
|
||||
{
|
||||
checked_inode.inode_page[j].ipage = 3;
|
||||
}
|
||||
for (j = 0; j < pfs->dir_size; j++)
|
||||
{
|
||||
while (file_next_node[j].inode_t.bank == bank && file_next_node[j].ipage >= ((__OSInodeUnit *)&(pfs->inode_start_page) + 1)->ipage)
|
||||
{
|
||||
u8 pp = file_next_node[j].inode_t.page;
|
||||
file_next_node[j] = checked_inode.inode_page[pp] = tmp_inode.inode_page[pp];
|
||||
}
|
||||
}
|
||||
ERRCK(__osPfsRWInode(pfs, &checked_inode, OS_WRITE, bank));
|
||||
}
|
||||
if (fixed)
|
||||
pfs->status |= PFS_CORRUPTED;
|
||||
else
|
||||
pfs->status &= ~PFS_CORRUPTED;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
s32 corrupted_init(OSPfs *pfs, __OSInodeCache *cache)
|
||||
{
|
||||
int i;
|
||||
int n;
|
||||
int offset;
|
||||
u8 bank;
|
||||
__OSInodeUnit tpage;
|
||||
__OSInode tmp_inode;
|
||||
s32 ret;
|
||||
|
||||
for (i = 0; i < ARRLEN(cache->map); i++)
|
||||
cache->map[i] = 0;
|
||||
cache->bank = -1;
|
||||
for (bank = 0; bank < pfs->banks; bank++)
|
||||
{
|
||||
if (bank > 0)
|
||||
offset = 1;
|
||||
else
|
||||
offset = pfs->inode_start_page;
|
||||
|
||||
ret = __osPfsRWInode(pfs, &tmp_inode, OS_READ, bank);
|
||||
if (ret != 0 && ret != PFS_ERR_INCONSISTENT)
|
||||
return ret;
|
||||
for (i = offset; i < ARRLEN(tmp_inode.inode_page); i++)
|
||||
{
|
||||
tpage = tmp_inode.inode_page[i];
|
||||
if (tpage.ipage >= pfs->inode_start_page && tpage.inode_t.bank != bank)
|
||||
{
|
||||
n = (tpage.inode_t.page / 4) + ((tpage.inode_t.bank % PFS_ONE_PAGE) * BLOCKSIZE);
|
||||
cache->map[n] |= 1 << (bank % PFS_ONE_PAGE);
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
s32 corrupted(OSPfs *pfs, __OSInodeUnit fpage, __OSInodeCache *cache)
|
||||
{
|
||||
int j;
|
||||
int n;
|
||||
int hit;
|
||||
u8 bank;
|
||||
int offset;
|
||||
s32 ret;
|
||||
|
||||
hit = 0;
|
||||
ret = 0;
|
||||
n = (fpage.inode_t.page / 4) + (fpage.inode_t.bank % 8) * BLOCKSIZE;
|
||||
for (bank = 0; bank < pfs->banks; bank++)
|
||||
{
|
||||
if (bank > 0)
|
||||
offset = 1;
|
||||
else
|
||||
offset = pfs->inode_start_page;
|
||||
if (bank == fpage.inode_t.bank || cache->map[n] & (1 << (bank % 8)))
|
||||
{
|
||||
if (bank != cache->bank)
|
||||
{
|
||||
ret = __osPfsRWInode(pfs, &cache->inode, 0, bank);
|
||||
if (ret != 0 && ret != PFS_ERR_INCONSISTENT)
|
||||
return ret;
|
||||
cache->bank = bank;
|
||||
}
|
||||
|
||||
for (j = offset; hit < 2 && (j < ARRLEN(cache->inode.inode_page)); j++)
|
||||
{
|
||||
if (cache->inode.inode_page[j].ipage == fpage.ipage)
|
||||
hit++;
|
||||
}
|
||||
if (1 < hit)
|
||||
return PFS_ERR_NEW_PACK;
|
||||
}
|
||||
}
|
||||
return hit;
|
||||
}
|
26
src/core1/io/pfsgetstatus.c
Normal file
26
src/core1/io/pfsgetstatus.c
Normal file
@@ -0,0 +1,26 @@
|
||||
#include <os_internal.h>
|
||||
#include "controller.h"
|
||||
#include "siint.h"
|
||||
|
||||
extern OSPifRam __osPfsPifRam;
|
||||
s32 __osPfsGetStatus(OSMesgQueue *queue, int channel)
|
||||
{
|
||||
s32 ret;
|
||||
OSMesg dummy;
|
||||
u8 pattern;
|
||||
OSContStatus data[4];
|
||||
ret = 0;
|
||||
__osPfsRequestData(CONT_CMD_REQUEST_STATUS);
|
||||
ret = __osSiRawStartDma(OS_WRITE, &__osPfsPifRam);
|
||||
osRecvMesg(queue, &dummy, OS_MESG_BLOCK);
|
||||
ret = __osSiRawStartDma(OS_READ, &__osPfsPifRam);
|
||||
osRecvMesg(queue, &dummy, OS_MESG_BLOCK);
|
||||
__osPfsGetInitData(&pattern, data);
|
||||
if (((data[channel].status & CONT_CARD_ON) != 0) && ((data[channel].status & CONT_CARD_PULL) != 0))
|
||||
return PFS_ERR_NEW_PACK;
|
||||
if ((data[channel].errno != 0) || ((data[channel].status & CONT_CARD_ON) == 0))
|
||||
return PFS_ERR_NOPACK;
|
||||
if ((data[channel].status & CONT_ADDR_CRC_ER) != 0)
|
||||
return PFS_ERR_CONTRFAIL;
|
||||
return ret;
|
||||
}
|
24
src/core1/io/pfsinit.c
Normal file
24
src/core1/io/pfsinit.c
Normal file
@@ -0,0 +1,24 @@
|
||||
#include <os_internal.h>
|
||||
#include "controller.h"
|
||||
#include "siint.h"
|
||||
|
||||
s32 osPfsInit(OSMesgQueue *queue, OSPfs *pfs, int channel)
|
||||
{
|
||||
s32 ret;
|
||||
ret = 0;
|
||||
__osSiGetAccess();
|
||||
ret = __osPfsGetStatus(queue, channel);
|
||||
__osSiRelAccess();
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
|
||||
pfs->queue = queue;
|
||||
pfs->channel = channel;
|
||||
pfs->status = 0;
|
||||
pfs->activebank = -1;
|
||||
ERRCK(__osGetId(pfs));
|
||||
|
||||
ret = osPfsChecker(pfs);
|
||||
pfs->status |= PFS_INITIALIZED;
|
||||
return ret;
|
||||
}
|
99
src/core1/io/pfsisplug.c
Normal file
99
src/core1/io/pfsisplug.c
Normal file
@@ -0,0 +1,99 @@
|
||||
#include <os_internal.h>
|
||||
#include "controller.h"
|
||||
#include "siint.h"
|
||||
|
||||
OSPifRam __osPfsPifRam; // TODO bss
|
||||
s32 osPfsIsPlug(OSMesgQueue *queue, u8 *pattern)
|
||||
{
|
||||
s32 ret;
|
||||
OSMesg dummy;
|
||||
u8 bitpattern;
|
||||
OSContStatus data[MAXCONTROLLERS];
|
||||
int channel;
|
||||
u8 bits;
|
||||
int crc_error_cnt;
|
||||
ret = 0;
|
||||
bits = 0;
|
||||
crc_error_cnt = 3;
|
||||
__osSiGetAccess();
|
||||
while (TRUE)
|
||||
{
|
||||
__osPfsRequestData(CONT_CMD_REQUEST_STATUS);
|
||||
ret = __osSiRawStartDma(OS_WRITE, &__osPfsPifRam);
|
||||
osRecvMesg(queue, &dummy, OS_MESG_BLOCK);
|
||||
ret = __osSiRawStartDma(OS_READ, &__osPfsPifRam);
|
||||
osRecvMesg(queue, &dummy, OS_MESG_BLOCK);
|
||||
__osPfsGetInitData(&bitpattern, data);
|
||||
for (channel = 0; channel < __osMaxControllers; channel++)
|
||||
{
|
||||
if ((data[channel].status & CONT_ADDR_CRC_ER) == 0)
|
||||
{
|
||||
crc_error_cnt--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (__osMaxControllers == channel)
|
||||
crc_error_cnt = 0;
|
||||
if (crc_error_cnt < 1)
|
||||
{
|
||||
for (channel = 0; channel < __osMaxControllers; channel++)
|
||||
{
|
||||
if (data[channel].errno == 0 && (data[channel].status & CONT_CARD_ON) != 0)
|
||||
bits |= 1 << channel;
|
||||
}
|
||||
__osSiRelAccess();
|
||||
*pattern = bits;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
void __osPfsRequestData(u8 cmd)
|
||||
{
|
||||
u8 *ptr;
|
||||
__OSContRequesFormat requestformat;
|
||||
int i;
|
||||
__osContLastCmd = cmd;
|
||||
|
||||
for (i = 0; i < ARRLEN(__osPfsPifRam.ramarray) + 1; i++) { // also clear pifstatus
|
||||
__osPfsPifRam.ramarray[i] = 0;
|
||||
}
|
||||
|
||||
__osPfsPifRam.pifstatus = CONT_CMD_EXE;
|
||||
ptr = (u8 *)&__osPfsPifRam;
|
||||
requestformat.dummy = CONT_CMD_NOP;
|
||||
requestformat.txsize = CONT_CMD_REQUEST_STATUS_TX;
|
||||
requestformat.rxsize = CONT_CMD_REQUEST_STATUS_RX;
|
||||
requestformat.cmd = cmd;
|
||||
requestformat.typeh = CONT_CMD_NOP;
|
||||
requestformat.typel = CONT_CMD_NOP;
|
||||
requestformat.status = CONT_CMD_NOP;
|
||||
requestformat.dummy1 = CONT_CMD_NOP;
|
||||
for (i = 0; i < __osMaxControllers; i++)
|
||||
{
|
||||
*(__OSContRequesFormat *)ptr = requestformat;
|
||||
ptr += sizeof(__OSContRequesFormat);
|
||||
}
|
||||
*ptr = CONT_CMD_END;
|
||||
}
|
||||
void __osPfsGetInitData(u8 *pattern, OSContStatus *data)
|
||||
{
|
||||
u8 *ptr;
|
||||
__OSContRequesFormat requestformat;
|
||||
int i;
|
||||
u8 bits;
|
||||
bits = 0;
|
||||
ptr = (u8 *)&__osPfsPifRam;
|
||||
for (i = 0; i < __osMaxControllers; i++, ptr += sizeof(__OSContRequesFormat))
|
||||
{
|
||||
requestformat = *(__OSContRequesFormat *)ptr;
|
||||
data->errno = CHNL_ERR(requestformat);
|
||||
if (data->errno == 0)
|
||||
{
|
||||
data->type = (requestformat.typel << 8) | (requestformat.typeh);
|
||||
data->status = requestformat.status;
|
||||
bits |= 1 << i;
|
||||
}
|
||||
data++;
|
||||
}
|
||||
*pattern = bits;
|
||||
}
|
24
src/core1/io/piacs.c
Normal file
24
src/core1/io/piacs.c
Normal file
@@ -0,0 +1,24 @@
|
||||
#include <os_internal.h>
|
||||
|
||||
#define PI_Q_BUF_LEN 1
|
||||
u32 __osPiAccessQueueEnabled = 0;
|
||||
OSMesg piAccessBuf[PI_Q_BUF_LEN]; // todo bss
|
||||
OSMesgQueue __osPiAccessQueue;
|
||||
void __osPiCreateAccessQueue(void)
|
||||
{
|
||||
|
||||
__osPiAccessQueueEnabled = 1;
|
||||
osCreateMesgQueue(&__osPiAccessQueue, piAccessBuf, PI_Q_BUF_LEN);
|
||||
osSendMesg(&__osPiAccessQueue, NULL, OS_MESG_NOBLOCK);
|
||||
}
|
||||
void __osPiGetAccess(void)
|
||||
{
|
||||
OSMesg dummyMesg;
|
||||
if (!__osPiAccessQueueEnabled)
|
||||
__osPiCreateAccessQueue();
|
||||
osRecvMesg(&__osPiAccessQueue, &dummyMesg, OS_MESG_BLOCK);
|
||||
}
|
||||
void __osPiRelAccess(void)
|
||||
{
|
||||
osSendMesg(&__osPiAccessQueue, NULL, OS_MESG_NOBLOCK);
|
||||
}
|
11
src/core1/io/pigetcmdq.c
Normal file
11
src/core1/io/pigetcmdq.c
Normal file
@@ -0,0 +1,11 @@
|
||||
#include <ultra64.h>
|
||||
#include "functions.h"
|
||||
#include "variables.h"
|
||||
|
||||
extern OSDevMgr __osPiDevMgr;
|
||||
|
||||
OSMesgQueue *osPiGetCmdQueue(void){
|
||||
if (!__osPiDevMgr.active)
|
||||
return NULL;
|
||||
return __osPiDevMgr.cmdQueue;
|
||||
}
|
52
src/core1/io/pimgr.c
Normal file
52
src/core1/io/pimgr.c
Normal file
@@ -0,0 +1,52 @@
|
||||
#include <ultra64.h>
|
||||
#include "piint.h"
|
||||
|
||||
|
||||
extern u32 __osPiAccessQueueEnabled;
|
||||
|
||||
OSDevMgr __osPiDevMgr = {0};
|
||||
OSPiHandle *__osPiTable = NULL;
|
||||
OSPiHandle *__osCurrentHandle[2] = {&CartRomHandle, &LeoDiskHandle};
|
||||
|
||||
/* .bss */
|
||||
OSThread piThread;
|
||||
char piThreadStack[OS_PIM_STACKSIZE];
|
||||
OSMesgQueue piEventQueue;
|
||||
OSMesg piEventBuf;
|
||||
|
||||
void osCreatePiManager(OSPri pri, OSMesgQueue *cmdQ, OSMesg *cmdBuf, s32 cmdMsgCnt)
|
||||
{
|
||||
u32 savedMask;
|
||||
OSPri oldPri;
|
||||
OSPri myPri;
|
||||
if (!__osPiDevMgr.active)
|
||||
{
|
||||
osCreateMesgQueue(cmdQ, cmdBuf, cmdMsgCnt);
|
||||
osCreateMesgQueue(&piEventQueue, (OSMesg*)&piEventBuf, 1);
|
||||
if (!__osPiAccessQueueEnabled)
|
||||
__osPiCreateAccessQueue();
|
||||
osSetEventMesg(OS_EVENT_PI, &piEventQueue, (OSMesg)0x22222222);
|
||||
oldPri = -1;
|
||||
myPri = osGetThreadPri(NULL);
|
||||
if (myPri < pri)
|
||||
{
|
||||
oldPri = myPri;
|
||||
osSetThreadPri(NULL, pri);
|
||||
}
|
||||
savedMask = __osDisableInt();
|
||||
__osPiDevMgr.active = 1;
|
||||
__osPiDevMgr.thread = &piThread;
|
||||
__osPiDevMgr.cmdQueue = cmdQ;
|
||||
__osPiDevMgr.evtQueue = &piEventQueue;
|
||||
__osPiDevMgr.acsQueue = &__osPiAccessQueue;
|
||||
__osPiDevMgr.dma = osPiRawStartDma;
|
||||
__osPiDevMgr.edma = osEPiRawStartDma;
|
||||
osCreateThread(&piThread, 0, __osDevMgrMain, &__osPiDevMgr, &piThreadStack[OS_PIM_STACKSIZE], pri);
|
||||
osStartThread(&piThread);
|
||||
__osRestoreInt(savedMask);
|
||||
if (oldPri != -1)
|
||||
{
|
||||
osSetThreadPri(NULL, oldPri);
|
||||
}
|
||||
}
|
||||
}
|
28
src/core1/io/pirawdma.c
Normal file
28
src/core1/io/pirawdma.c
Normal file
@@ -0,0 +1,28 @@
|
||||
#include <ultra64.h>
|
||||
|
||||
#ifndef WAIT_ON_IOBUSY
|
||||
#define WAIT_ON_IOBUSY(stat) \
|
||||
stat = IO_READ(PI_STATUS_REG); \
|
||||
while (stat & (PI_STATUS_IO_BUSY | PI_STATUS_DMA_BUSY)) \
|
||||
stat = IO_READ(PI_STATUS_REG);
|
||||
#endif
|
||||
|
||||
s32 osPiRawStartDma(s32 direction, u32 devAddr, void *dramAddr, u32 size)
|
||||
{
|
||||
register u32 stat;
|
||||
WAIT_ON_IOBUSY(stat);
|
||||
IO_WRITE(PI_DRAM_ADDR_REG, osVirtualToPhysical(dramAddr));
|
||||
IO_WRITE(PI_CART_ADDR_REG, K1_TO_PHYS((u32)osRomBase | devAddr));
|
||||
switch (direction)
|
||||
{
|
||||
case OS_READ:
|
||||
IO_WRITE(PI_WR_LEN_REG, size - 1);
|
||||
break;
|
||||
case OS_WRITE:
|
||||
IO_WRITE(PI_RD_LEN_REG, size - 1);
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
11
src/core1/io/pirawread.c
Normal file
11
src/core1/io/pirawread.c
Normal file
@@ -0,0 +1,11 @@
|
||||
#include <ultra64.h>
|
||||
#include "piint.h"
|
||||
|
||||
s32 osPiRawReadIo(u32 devAddr, u32 *data)
|
||||
{
|
||||
register u32 stat;
|
||||
WAIT_ON_IOBUSY(stat);
|
||||
*data = IO_READ((u32)osRomBase | devAddr);
|
||||
return 0;
|
||||
}
|
||||
|
11
src/core1/io/piread.c
Normal file
11
src/core1/io/piread.c
Normal file
@@ -0,0 +1,11 @@
|
||||
#include <os_internal.h>
|
||||
#include "piint.h"
|
||||
|
||||
s32 osPiReadIo(u32 devAddr, u32 *data)
|
||||
{
|
||||
register s32 ret;
|
||||
__osPiGetAccess();
|
||||
ret = osPiRawReadIo(devAddr, data);
|
||||
__osPiRelAccess();
|
||||
return ret;
|
||||
}
|
11
src/core1/io/si.c
Normal file
11
src/core1/io/si.c
Normal file
@@ -0,0 +1,11 @@
|
||||
#include <ultra64.h>
|
||||
#include "functions.h"
|
||||
#include "variables.h"
|
||||
|
||||
int __osSiDeviceBusy()
|
||||
{
|
||||
register u32 stat = IO_READ(SI_STATUS_REG);
|
||||
if (stat & (SI_STATUS_DMA_BUSY | SI_STATUS_RD_BUSY))
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
24
src/core1/io/siacs.c
Normal file
24
src/core1/io/siacs.c
Normal file
@@ -0,0 +1,24 @@
|
||||
#include <ultra64.h>
|
||||
|
||||
#define SI_Q_BUF_LEN 1
|
||||
u32 __osSiAccessQueueEnabled = 0;
|
||||
OSMesg siAccessBuf[SI_Q_BUF_LEN];
|
||||
OSMesgQueue __osSiAccessQueue;
|
||||
|
||||
void __osSiCreateAccessQueue(void)
|
||||
{
|
||||
__osSiAccessQueueEnabled = 1;
|
||||
osCreateMesgQueue(&__osSiAccessQueue, siAccessBuf, SI_Q_BUF_LEN);
|
||||
osSendMesg(&__osSiAccessQueue, NULL, OS_MESG_NOBLOCK);
|
||||
}
|
||||
void __osSiGetAccess(void)
|
||||
{
|
||||
OSMesg dummyMesg;
|
||||
if (!__osSiAccessQueueEnabled)
|
||||
__osSiCreateAccessQueue();
|
||||
osRecvMesg(&__osSiAccessQueue, &dummyMesg, OS_MESG_BLOCK);
|
||||
}
|
||||
void __osSiRelAccess(void)
|
||||
{
|
||||
osSendMesg(&__osSiAccessQueue, NULL, OS_MESG_NOBLOCK);
|
||||
}
|
10
src/core1/io/siint.h
Normal file
10
src/core1/io/siint.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#ifndef _SIINT_H
|
||||
#define _SIINT_H
|
||||
#include <os_internal.h>
|
||||
#include <rcp.h>
|
||||
|
||||
void __osSiGetAccess(void);
|
||||
void __osSiRelAccess(void);
|
||||
int __osSiDeviceBusy(void);
|
||||
void __osSiCreateAccessQueue(void);
|
||||
#endif
|
22
src/core1/io/sirawdma.c
Normal file
22
src/core1/io/sirawdma.c
Normal file
@@ -0,0 +1,22 @@
|
||||
#include <ultra64.h>
|
||||
|
||||
s32 __osSiRawStartDma(s32 direction, void *dramAddr)
|
||||
{
|
||||
if (__osSiDeviceBusy())
|
||||
return -1;
|
||||
|
||||
if (direction == OS_WRITE)
|
||||
osWritebackDCache(dramAddr, 64);
|
||||
|
||||
IO_WRITE(SI_DRAM_ADDR_REG, osVirtualToPhysical(dramAddr));
|
||||
|
||||
if (direction == OS_READ)
|
||||
IO_WRITE(SI_PIF_ADDR_RD64B_REG, 0x1FC007C0);
|
||||
else
|
||||
IO_WRITE(SI_PIF_ADDR_WR64B_REG, 0x1FC007C0);
|
||||
|
||||
if (direction == OS_READ)
|
||||
osInvalDCache(dramAddr, 64);//bzero(dramAddr, 64);
|
||||
|
||||
return 0;
|
||||
}
|
9
src/core1/io/sirawread.c
Normal file
9
src/core1/io/sirawread.c
Normal file
@@ -0,0 +1,9 @@
|
||||
#include <ultra64.h>
|
||||
|
||||
s32 __osSiRawReadIo(u32 devAddr, u32 *data)
|
||||
{
|
||||
if (__osSiDeviceBusy())
|
||||
return -1;
|
||||
*data = IO_READ(devAddr);
|
||||
return 0;
|
||||
}
|
10
src/core1/io/sirawwrite.c
Normal file
10
src/core1/io/sirawwrite.c
Normal file
@@ -0,0 +1,10 @@
|
||||
#include <ultra64.h>
|
||||
|
||||
s32 __osSiRawWriteIo(u32 devAddr, u32 data)
|
||||
{
|
||||
|
||||
if (__osSiDeviceBusy())
|
||||
return -1;
|
||||
IO_WRITE(devAddr, data);
|
||||
return 0;
|
||||
}
|
12
src/core1/io/sp.c
Normal file
12
src/core1/io/sp.c
Normal file
@@ -0,0 +1,12 @@
|
||||
#include <os_internal.h>
|
||||
#include <rcp.h>
|
||||
#include <sptask.h>
|
||||
#include "osint.h"
|
||||
|
||||
int __osSpDeviceBusy()
|
||||
{
|
||||
register u32 stat = IO_READ(SP_STATUS_REG);
|
||||
if (stat & (SP_STATUS_DMA_BUSY | SP_STATUS_DMA_FULL | SP_STATUS_IO_FULL))
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
7
src/core1/io/spgetstat.c
Normal file
7
src/core1/io/spgetstat.c
Normal file
@@ -0,0 +1,7 @@
|
||||
#include <os_internal.h>
|
||||
#include <rcp.h>
|
||||
|
||||
u32 __osSpGetStatus()
|
||||
{
|
||||
return IO_READ(SP_STATUS_REG);
|
||||
}
|
16
src/core1/io/sprawdma.c
Normal file
16
src/core1/io/sprawdma.c
Normal file
@@ -0,0 +1,16 @@
|
||||
#include <os_internal.h>
|
||||
#include <rcp.h>
|
||||
#include "osint.h"
|
||||
|
||||
s32 __osSpRawStartDma(s32 direction, u32 devAddr, void *dramAddr, u32 size)
|
||||
{
|
||||
if (__osSpDeviceBusy())
|
||||
return -1;
|
||||
IO_WRITE(SP_MEM_ADDR_REG, devAddr);
|
||||
IO_WRITE(SP_DRAM_ADDR_REG, osVirtualToPhysical(dramAddr));
|
||||
if (direction == OS_READ)
|
||||
IO_WRITE(SP_WR_LEN_REG, size - 1);
|
||||
else
|
||||
IO_WRITE(SP_RD_LEN_REG, size - 1);
|
||||
return 0;
|
||||
}
|
14
src/core1/io/spsetpc.c
Normal file
14
src/core1/io/spsetpc.c
Normal file
@@ -0,0 +1,14 @@
|
||||
#include <os_internal.h>
|
||||
#include <rcp.h>
|
||||
|
||||
s32 __osSpSetPc(u32 data)
|
||||
{
|
||||
register u32 stat = IO_READ(SP_STATUS_REG);
|
||||
if (!(stat & SP_STATUS_HALT))
|
||||
return -1;
|
||||
else
|
||||
{
|
||||
IO_WRITE(SP_PC_REG, data);
|
||||
}
|
||||
return 0;
|
||||
}
|
6
src/core1/io/spsetstat.c
Normal file
6
src/core1/io/spsetstat.c
Normal file
@@ -0,0 +1,6 @@
|
||||
#include <os_internal.h>
|
||||
#include <rcp.h>
|
||||
|
||||
void __osSpSetStatus(u32 data){
|
||||
IO_WRITE(SP_STATUS_REG, data);
|
||||
}
|
63
src/core1/io/sptask.c
Normal file
63
src/core1/io/sptask.c
Normal file
@@ -0,0 +1,63 @@
|
||||
#include <ultra64.h>
|
||||
|
||||
#define _osVirtualToPhysical(ptr) \
|
||||
if (ptr != NULL) \
|
||||
{ \
|
||||
ptr = (void *)osVirtualToPhysical(ptr); \
|
||||
}
|
||||
|
||||
OSTask tmp_task; // TODO bss (static)
|
||||
|
||||
static OSTask *_VirtualToPhysicalTask(OSTask *intp)
|
||||
{
|
||||
OSTask *tp;
|
||||
tp = &tmp_task;
|
||||
bcopy(intp, tp, sizeof(OSTask));
|
||||
|
||||
_osVirtualToPhysical(tp->t.ucode);
|
||||
_osVirtualToPhysical(tp->t.ucode_data);
|
||||
_osVirtualToPhysical(tp->t.dram_stack);
|
||||
_osVirtualToPhysical(tp->t.output_buff);
|
||||
_osVirtualToPhysical(tp->t.output_buff_size);
|
||||
_osVirtualToPhysical(tp->t.data_ptr);
|
||||
_osVirtualToPhysical(tp->t.yield_data_ptr);
|
||||
return tp;
|
||||
}
|
||||
void osSpTaskLoad(OSTask *intp)
|
||||
{
|
||||
|
||||
OSTask *tp;
|
||||
tp = _VirtualToPhysicalTask(intp);
|
||||
if (tp->t.flags & OS_TASK_YIELDED)
|
||||
{
|
||||
tp->t.ucode_data = tp->t.yield_data_ptr;
|
||||
tp->t.ucode_data_size = tp->t.yield_data_size;
|
||||
intp->t.flags &= ~OS_TASK_YIELDED;
|
||||
if (tp->t.flags & OS_TASK_LOADABLE)
|
||||
tp->t.ucode = (u64 *)IO_READ((u32)intp->t.yield_data_ptr + OS_YIELD_DATA_SIZE - 4);
|
||||
}
|
||||
osWritebackDCache(tp, sizeof(OSTask));
|
||||
__osSpSetStatus(SP_CLR_YIELD | SP_CLR_YIELDED | SP_CLR_TASKDONE | SP_SET_INTR_BREAK);
|
||||
while (__osSpSetPc(SP_IMEM_START) == -1)
|
||||
;
|
||||
|
||||
while (__osSpRawStartDma(1, (SP_IMEM_START - sizeof(*tp)), tp,
|
||||
sizeof(OSTask)) == -1)
|
||||
;
|
||||
|
||||
while (__osSpDeviceBusy())
|
||||
;
|
||||
|
||||
while (__osSpRawStartDma(1, SP_IMEM_START, tp->t.ucode_boot,
|
||||
tp->t.ucode_boot_size) == -1)
|
||||
;
|
||||
}
|
||||
void osSpTaskStartGo(OSTask *tp)
|
||||
{
|
||||
|
||||
while (__osSpDeviceBusy())
|
||||
;
|
||||
|
||||
__osSpSetStatus(SP_SET_INTR_BREAK | SP_CLR_SSTEP | SP_CLR_BROKE | SP_CLR_HALT);
|
||||
|
||||
}
|
7
src/core1/io/sptaskyield.c
Normal file
7
src/core1/io/sptaskyield.c
Normal file
@@ -0,0 +1,7 @@
|
||||
#include <os_internal.h>
|
||||
#include <rcp.h>
|
||||
|
||||
void osSpTaskYield(void)
|
||||
{
|
||||
__osSpSetStatus(SP_SET_YIELD);
|
||||
}
|
20
src/core1/io/sptaskyielded.c
Normal file
20
src/core1/io/sptaskyielded.c
Normal file
@@ -0,0 +1,20 @@
|
||||
#include <os_internal.h>
|
||||
#include <rcp.h>
|
||||
#include <sptask.h>
|
||||
|
||||
OSYieldResult osSpTaskYielded(OSTask *tp)
|
||||
{
|
||||
u32 status;
|
||||
OSYieldResult result;
|
||||
status = __osSpGetStatus();
|
||||
if (status & SP_STATUS_YIELDED)
|
||||
result = OS_TASK_YIELDED;
|
||||
else
|
||||
result = 0;
|
||||
if (status & SP_STATUS_YIELD)
|
||||
{
|
||||
tp->t.flags |= result;
|
||||
tp->t.flags &= ~(OS_TASK_DP_WAIT);
|
||||
}
|
||||
return result;
|
||||
}
|
36
src/core1/io/vi.c
Normal file
36
src/core1/io/vi.c
Normal file
@@ -0,0 +1,36 @@
|
||||
#include <os_internal.h>
|
||||
#include <R4300.h>
|
||||
#include <rcp.h>
|
||||
#include "viint.h"
|
||||
|
||||
static __OSViContext vi[2] = {0};
|
||||
__OSViContext *__osViCurr = &vi[0];
|
||||
__OSViContext *__osViNext = &vi[1];
|
||||
void __osViInit(void)
|
||||
{
|
||||
bzero(vi, sizeof(vi));
|
||||
__osViCurr = &vi[0];
|
||||
__osViNext = &vi[1];
|
||||
__osViNext->retraceCount = 1;
|
||||
__osViCurr->retraceCount = 1;
|
||||
__osViNext->framep = (void*)K0BASE;
|
||||
__osViCurr->framep = (void*)K0BASE;
|
||||
if (osTvType == OS_TV_TYPE_PAL)
|
||||
{
|
||||
__osViNext->modep = &osViModePalLan1;
|
||||
}
|
||||
else if (osTvType == OS_TV_TYPE_MPAL)
|
||||
{
|
||||
__osViNext->modep = &osViModeMpalLan1;
|
||||
}
|
||||
else
|
||||
{
|
||||
__osViNext->modep = &osViModeNtscLan1;
|
||||
}
|
||||
__osViNext->state = VI_STATE_BLACK;
|
||||
__osViNext->control = __osViNext->modep->comRegs.ctrl;
|
||||
while (IO_READ(VI_CURRENT_REG) > 10) //wait for vsync?
|
||||
;
|
||||
IO_WRITE(VI_CONTROL_REG, 0); //pixel size blank (no data, no sync)
|
||||
__osViSwapContext();
|
||||
}
|
14
src/core1/io/viblack.c
Normal file
14
src/core1/io/viblack.c
Normal file
@@ -0,0 +1,14 @@
|
||||
#include <ultra64.h>
|
||||
#include "functions.h"
|
||||
#include "variables.h"
|
||||
#include "viint.h"
|
||||
|
||||
void osViBlack(u8 active)
|
||||
{
|
||||
register u32 saveMask = __osDisableInt();
|
||||
if (active)
|
||||
__osViNext->state |= VI_STATE_BLACK;
|
||||
else
|
||||
__osViNext->state &= ~VI_STATE_BLACK;
|
||||
__osRestoreInt(saveMask);
|
||||
}
|
7
src/core1/io/vigetcurrcontext.c
Normal file
7
src/core1/io/vigetcurrcontext.c
Normal file
@@ -0,0 +1,7 @@
|
||||
#include <os_internal.h>
|
||||
#include "viint.h"
|
||||
|
||||
__OSViContext *__osViGetCurrentContext(void)
|
||||
{
|
||||
return __osViCurr;
|
||||
}
|
12
src/core1/io/vigetcurrframebuf.c
Normal file
12
src/core1/io/vigetcurrframebuf.c
Normal file
@@ -0,0 +1,12 @@
|
||||
#include <ultra64.h>
|
||||
#include "viint.h"
|
||||
|
||||
void *osViGetCurrentFramebuffer(void)
|
||||
{
|
||||
register u32 saveMask;
|
||||
void *framep;
|
||||
saveMask = __osDisableInt();
|
||||
framep = __osViCurr->framep;
|
||||
__osRestoreInt(saveMask);
|
||||
return framep;
|
||||
}
|
14
src/core1/io/vigetnextframebuf.c
Normal file
14
src/core1/io/vigetnextframebuf.c
Normal file
@@ -0,0 +1,14 @@
|
||||
#include <ultra64.h>
|
||||
#include "functions.h"
|
||||
#include "variables.h"
|
||||
#include "viint.h"
|
||||
|
||||
void *osViGetNextFramebuffer(void)
|
||||
{
|
||||
register u32 saveMask;
|
||||
void *framep;
|
||||
saveMask = __osDisableInt();
|
||||
framep = __osViNext->framep;
|
||||
__osRestoreInt(saveMask);
|
||||
return framep;
|
||||
}
|
109
src/core1/io/vimgr.c
Normal file
109
src/core1/io/vimgr.c
Normal file
@@ -0,0 +1,109 @@
|
||||
#include <os_internal.h>
|
||||
#include <rcp.h>
|
||||
#include "viint.h"
|
||||
#include "osint.h"
|
||||
|
||||
OSDevMgr __osViDevMgr = {0};
|
||||
|
||||
/* .bss */
|
||||
/*static*/ OSThread viThread;
|
||||
/*static*/ unsigned char viThreadStack[OS_VIM_STACKSIZE];
|
||||
/*static*/ OSMesgQueue viEventQueue;
|
||||
/*static*/ OSMesg viEventBuf[5];
|
||||
/*static*/ OSIoMesg viRetraceMsg;
|
||||
/*static*/ OSIoMesg viCounterMsg;
|
||||
|
||||
static void viMgrMain(void *arg);
|
||||
void osCreateViManager(OSPri pri)
|
||||
{
|
||||
u32 savedMask;
|
||||
OSPri oldPri;
|
||||
OSPri myPri;
|
||||
if (__osViDevMgr.active == 0)
|
||||
{
|
||||
__osTimerServicesInit();
|
||||
osCreateMesgQueue(&viEventQueue, viEventBuf, 5);
|
||||
viRetraceMsg.hdr.type = OS_MESG_TYPE_VRETRACE;
|
||||
viRetraceMsg.hdr.pri = OS_MESG_PRI_NORMAL;
|
||||
viRetraceMsg.hdr.retQueue = NULL;
|
||||
viCounterMsg.hdr.type = OS_MESG_TYPE_COUNTER;
|
||||
viCounterMsg.hdr.pri = OS_MESG_PRI_NORMAL;
|
||||
viCounterMsg.hdr.retQueue = NULL;
|
||||
osSetEventMesg(OS_EVENT_VI, &viEventQueue, &viRetraceMsg);
|
||||
osSetEventMesg(OS_EVENT_COUNTER, &viEventQueue, &viCounterMsg);
|
||||
oldPri = -1;
|
||||
myPri = osGetThreadPri(NULL);
|
||||
if (myPri < pri)
|
||||
{
|
||||
oldPri = myPri;
|
||||
osSetThreadPri(NULL, pri);
|
||||
}
|
||||
savedMask = __osDisableInt();
|
||||
__osViDevMgr.active = 1;
|
||||
__osViDevMgr.thread = &viThread;
|
||||
__osViDevMgr.cmdQueue = &viEventQueue;
|
||||
__osViDevMgr.evtQueue = &viEventQueue;
|
||||
__osViDevMgr.acsQueue = NULL;
|
||||
__osViDevMgr.dma = NULL;
|
||||
__osViDevMgr.edma = NULL;
|
||||
osCreateThread(&viThread, 0, viMgrMain, &__osViDevMgr, &viThreadStack[OS_VIM_STACKSIZE], pri);
|
||||
__osViInit();
|
||||
osStartThread(&viThread);
|
||||
__osRestoreInt(savedMask);
|
||||
if (oldPri != -1)
|
||||
{
|
||||
osSetThreadPri(0, oldPri);
|
||||
}
|
||||
}
|
||||
}
|
||||
u16 retrace;
|
||||
static void viMgrMain(void *arg)
|
||||
{
|
||||
__OSViContext *vc;
|
||||
OSDevMgr *dm;
|
||||
OSIoMesg *mb;
|
||||
// static u16 retrace;
|
||||
s32 first;
|
||||
u32 count;
|
||||
|
||||
mb = NULL;
|
||||
first = 0;
|
||||
vc = __osViGetCurrentContext();
|
||||
retrace = vc->retraceCount;
|
||||
if (retrace == 0)
|
||||
retrace = 1;
|
||||
dm = (OSDevMgr *)arg;
|
||||
while (TRUE)
|
||||
{
|
||||
osRecvMesg(dm->evtQueue, (OSMesg)&mb, OS_MESG_BLOCK);
|
||||
switch (mb->hdr.type)
|
||||
{
|
||||
case OS_MESG_TYPE_VRETRACE:
|
||||
__osViSwapContext();
|
||||
retrace--;
|
||||
if (retrace == 0)
|
||||
{
|
||||
vc = __osViGetCurrentContext();
|
||||
if (vc->msgq != NULL)
|
||||
osSendMesg(vc->msgq, vc->msg, OS_MESG_NOBLOCK);
|
||||
retrace = vc->retraceCount;
|
||||
}
|
||||
__osViIntrCount++;
|
||||
if (first)
|
||||
{
|
||||
|
||||
count = osGetCount();
|
||||
__osCurrentTime = count;
|
||||
first = 0;
|
||||
}
|
||||
count = __osBaseCounter;
|
||||
__osBaseCounter = osGetCount();
|
||||
count = __osBaseCounter - count;
|
||||
__osCurrentTime = __osCurrentTime + count;
|
||||
break;
|
||||
case OS_MESG_TYPE_COUNTER:
|
||||
__osTimerInterrupt();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
36
src/core1/io/vimodempallan1.c
Normal file
36
src/core1/io/vimodempallan1.c
Normal file
@@ -0,0 +1,36 @@
|
||||
#include <os.h>
|
||||
#include <rcp.h>
|
||||
#include "viint.h"
|
||||
|
||||
OSViMode osViModeMpalLan1 = {
|
||||
OS_VI_MPAL_LAN1, // type
|
||||
{
|
||||
// comRegs
|
||||
VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON |
|
||||
VI_CTRL_DIVOT_ON | VI_CTRL_ANTIALIAS_MODE_1 | 0x3000, // ctrl
|
||||
WIDTH(320), // width
|
||||
BURST(57, 30, 5, 70), // burst
|
||||
VSYNC(525), // vSync
|
||||
HSYNC(3089, 4), // hSync
|
||||
LEAP(3097, 3098), // leap
|
||||
HSTART(108, 748), // hStart
|
||||
SCALE(2, 0), // xScale
|
||||
VCURRENT(0), // vCurrent
|
||||
},
|
||||
{// fldRegs
|
||||
{
|
||||
//[0]
|
||||
ORIGIN(640), // origin
|
||||
SCALE(1, 0), // yScale
|
||||
HSTART(37, 511), // vStart
|
||||
BURST(4, 2, 14, 0), // vBurst
|
||||
VINTR(2), // vIntr
|
||||
},
|
||||
{
|
||||
//[1]
|
||||
ORIGIN(640), // origin
|
||||
SCALE(1, 0), // yScale
|
||||
HSTART(37, 511), // vStart
|
||||
BURST(4, 2, 14, 0), // vBurst
|
||||
VINTR(2), // vIntr
|
||||
}}};
|
36
src/core1/io/vimodentsclan1.c
Normal file
36
src/core1/io/vimodentsclan1.c
Normal file
@@ -0,0 +1,36 @@
|
||||
#include <os.h>
|
||||
#include <rcp.h>
|
||||
#include "viint.h"
|
||||
|
||||
OSViMode osViModeNtscLan1 = {
|
||||
OS_VI_NTSC_LAN1, // type
|
||||
{
|
||||
// comRegs
|
||||
VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON |
|
||||
VI_CTRL_DIVOT_ON | VI_CTRL_ANTIALIAS_MODE_1 | 0x3000, // ctrl
|
||||
WIDTH(320), // width
|
||||
BURST(57, 34, 5, 62), // burst
|
||||
VSYNC(525), // vSync
|
||||
HSYNC(3093, 0), // hSync
|
||||
LEAP(3093, 3093), // leap
|
||||
HSTART(108, 748), // hStart
|
||||
SCALE(2, 0), // xScale
|
||||
VCURRENT(0), // vCurrent
|
||||
},
|
||||
{// fldRegs
|
||||
{
|
||||
//[0]
|
||||
ORIGIN(640), // origin
|
||||
SCALE(1, 0), // yScale
|
||||
HSTART(37, 511), // vStart
|
||||
BURST(4, 2, 14, 0), // vBurst
|
||||
VINTR(2), // vIntr
|
||||
},
|
||||
{
|
||||
//[1]
|
||||
ORIGIN(640), // origin
|
||||
SCALE(1, 0), // yScale
|
||||
HSTART(37, 511), // vStart
|
||||
BURST(4, 2, 14, 0), // vBurst
|
||||
VINTR(2), // vIntr
|
||||
}}};
|
36
src/core1/io/vimodepallan1.c
Normal file
36
src/core1/io/vimodepallan1.c
Normal file
@@ -0,0 +1,36 @@
|
||||
#include <os.h>
|
||||
#include <rcp.h>
|
||||
#include "viint.h"
|
||||
|
||||
OSViMode osViModePalLan1 = {
|
||||
OS_VI_PAL_LAN1, // type
|
||||
{
|
||||
// comRegs
|
||||
VI_CTRL_TYPE_16 | VI_CTRL_GAMMA_DITHER_ON | VI_CTRL_GAMMA_ON |
|
||||
VI_CTRL_DIVOT_ON | VI_CTRL_ANTIALIAS_MODE_1 | 0x3000, // ctrl
|
||||
WIDTH(320), // width
|
||||
BURST(58, 30, 4, 69), // burst
|
||||
VSYNC(625), // vSync
|
||||
HSYNC(3177, 23), // hSync
|
||||
LEAP(3183, 3181), // leap
|
||||
HSTART(128, 768), // hStart
|
||||
SCALE(2, 0), // xScale
|
||||
VCURRENT(0), // vCurrent
|
||||
},
|
||||
{// fldRegs
|
||||
{
|
||||
//[0]
|
||||
ORIGIN(640), // origin
|
||||
SCALE(1, 0), // yScale
|
||||
HSTART(95, 569), // vStart
|
||||
BURST(107, 2, 9, 0), // vBurst
|
||||
VINTR(2), // vIntr
|
||||
},
|
||||
{
|
||||
//[1]
|
||||
ORIGIN(640), // origin
|
||||
SCALE(1, 0), // yScale
|
||||
HSTART(95, 569), // vStart
|
||||
BURST(107, 2, 9, 0), // vBurst
|
||||
VINTR(2), // vIntr
|
||||
}}};
|
13
src/core1/io/visetevent.c
Normal file
13
src/core1/io/visetevent.c
Normal file
@@ -0,0 +1,13 @@
|
||||
#include <ultra64.h>
|
||||
#include "functions.h"
|
||||
#include "variables.h"
|
||||
#include "viint.h"
|
||||
|
||||
void osViSetEvent(OSMesgQueue *mq, OSMesg m, u32 retraceCount){
|
||||
register u32 saveMask;
|
||||
saveMask = __osDisableInt();
|
||||
__osViNext->msgq = mq;
|
||||
__osViNext->msg = m;
|
||||
__osViNext->retraceCount = retraceCount;
|
||||
__osRestoreInt(saveMask);
|
||||
}
|
12
src/core1/io/visetmode.c
Normal file
12
src/core1/io/visetmode.c
Normal file
@@ -0,0 +1,12 @@
|
||||
#include <os_internal.h>
|
||||
#include "viint.h"
|
||||
|
||||
void osViSetMode(OSViMode *modep)
|
||||
{
|
||||
register u32 saveMask;
|
||||
saveMask = __osDisableInt();
|
||||
__osViNext->modep = modep;
|
||||
__osViNext->state = VI_STATE_01;
|
||||
__osViNext->control = __osViNext->modep->comRegs.ctrl;
|
||||
__osRestoreInt(saveMask);
|
||||
}
|
38
src/core1/io/visetspecial.c
Normal file
38
src/core1/io/visetspecial.c
Normal file
@@ -0,0 +1,38 @@
|
||||
#include <os_internal.h>
|
||||
#include <rcp.h>
|
||||
#include "viint.h"
|
||||
|
||||
void osViSetSpecialFeatures(u32 func){
|
||||
|
||||
register u32 saveMask;
|
||||
saveMask = __osDisableInt();
|
||||
if ((func & OS_VI_GAMMA_ON) != 0) {
|
||||
__osViNext->control |= VI_CTRL_GAMMA_ON;
|
||||
}
|
||||
if ((func & OS_VI_GAMMA_OFF) != 0) {
|
||||
__osViNext->control &= ~VI_CTRL_GAMMA_ON;
|
||||
}
|
||||
if ((func & OS_VI_GAMMA_DITHER_ON) != 0) {
|
||||
__osViNext->control |= VI_CTRL_GAMMA_DITHER_ON;
|
||||
}
|
||||
if ((func & OS_VI_GAMMA_DITHER_OFF) != 0) {
|
||||
__osViNext->control &= ~VI_CTRL_GAMMA_DITHER_ON;
|
||||
}
|
||||
if ((func & OS_VI_DIVOT_ON) != 0) {
|
||||
__osViNext->control |= VI_CTRL_DIVOT_ON;
|
||||
}
|
||||
if ((func & OS_VI_DIVOT_OFF) != 0) {
|
||||
__osViNext->control &= ~VI_CTRL_DIVOT_ON;
|
||||
}
|
||||
if ((func & OS_VI_DITHER_FILTER_ON) != 0) {
|
||||
__osViNext->control |= VI_CTRL_DITHER_FILTER_ON;
|
||||
__osViNext->control &= ~VI_CTRL_ANTIALIAS_MASK;
|
||||
}
|
||||
if ((func & OS_VI_DITHER_FILTER_OFF) != 0) {
|
||||
__osViNext->control &= ~VI_CTRL_DITHER_FILTER_ON;
|
||||
__osViNext->control |= __osViNext->modep->comRegs.ctrl & VI_CTRL_ANTIALIAS_MASK;
|
||||
}
|
||||
__osViNext->state |= VI_STATE_08;
|
||||
|
||||
__osRestoreInt(saveMask);
|
||||
}
|
11
src/core1/io/viswapbuf.c
Normal file
11
src/core1/io/viswapbuf.c
Normal file
@@ -0,0 +1,11 @@
|
||||
#include <ultra64.h>
|
||||
#include "functions.h"
|
||||
#include "variables.h"
|
||||
#include "viint.h"
|
||||
|
||||
void osViSwapBuffer(void* frameBufPtr){
|
||||
u32 saveMask = __osDisableInt();
|
||||
__osViNext->framep = frameBufPtr;
|
||||
__osViNext->state |= VI_STATE_10;
|
||||
__osRestoreInt(saveMask);
|
||||
}
|
71
src/core1/io/viswapcontext.c
Normal file
71
src/core1/io/viswapcontext.c
Normal file
@@ -0,0 +1,71 @@
|
||||
#include <os_internal.h>
|
||||
#include <rcp.h>
|
||||
#include "viint.h"
|
||||
|
||||
void __osViSwapContext()
|
||||
{
|
||||
register OSViMode *vm;
|
||||
register __OSViContext *vc;
|
||||
u32 origin;
|
||||
u32 hStart;
|
||||
u32 nomValue;
|
||||
u32 field;
|
||||
|
||||
field = 0;
|
||||
vc = __osViNext;
|
||||
vm = vc->modep;
|
||||
|
||||
field = IO_READ(VI_CURRENT_REG) & 1; //field num
|
||||
|
||||
origin = osVirtualToPhysical(vc->framep) + (vm->fldRegs[field].origin);
|
||||
if (vc->state & VI_STATE_XSCALE_UPDATED)
|
||||
{
|
||||
vc->x.scale |= (vm->comRegs.xScale & ~VI_SCALE_MASK);
|
||||
}
|
||||
else
|
||||
{
|
||||
vc->x.scale = vm->comRegs.xScale;
|
||||
}
|
||||
if (vc->state & VI_STATE_YSCALE_UPDATED)
|
||||
{
|
||||
nomValue = vm->fldRegs[field].yScale & VI_SCALE_MASK;
|
||||
vc->y.scale = vc->y.factor * nomValue;
|
||||
vc->y.scale |= vm->fldRegs[field].yScale & ~VI_SCALE_MASK;
|
||||
}
|
||||
else
|
||||
{
|
||||
vc->y.scale = vm->fldRegs[field].yScale;
|
||||
}
|
||||
hStart = vm->comRegs.hStart;
|
||||
if (vc->state & VI_STATE_BLACK)
|
||||
{
|
||||
hStart = 0;
|
||||
}
|
||||
if (vc->state & VI_STATE_REPEATLINE)
|
||||
{
|
||||
vc->y.scale = 0;
|
||||
origin = osVirtualToPhysical(vc->framep);
|
||||
}
|
||||
if (vc->state & VI_STATE_FADE)
|
||||
{
|
||||
vc->y.scale = (vc->y.offset << VI_SUBPIXEL_SH) & (VI_2_10_FPART_MASK << VI_SUBPIXEL_SH);
|
||||
origin = osVirtualToPhysical(vc->framep);
|
||||
}
|
||||
IO_WRITE(VI_ORIGIN_REG, origin);
|
||||
IO_WRITE(VI_WIDTH_REG, vm->comRegs.width);
|
||||
IO_WRITE(VI_BURST_REG, vm->comRegs.burst);
|
||||
IO_WRITE(VI_V_SYNC_REG, vm->comRegs.vSync);
|
||||
IO_WRITE(VI_H_SYNC_REG, vm->comRegs.hSync);
|
||||
IO_WRITE(VI_LEAP_REG, vm->comRegs.leap);
|
||||
IO_WRITE(VI_H_START_REG, hStart);
|
||||
IO_WRITE(VI_V_START_REG, vm->fldRegs[field].vStart);
|
||||
IO_WRITE(VI_V_BURST_REG, vm->fldRegs[field].vBurst);
|
||||
IO_WRITE(VI_INTR_REG, vm->fldRegs[field].vIntr);
|
||||
IO_WRITE(VI_X_SCALE_REG, vc->x.scale);
|
||||
IO_WRITE(VI_Y_SCALE_REG, vc->y.scale);
|
||||
IO_WRITE(VI_CONTROL_REG, vc->control);
|
||||
|
||||
__osViNext = __osViCurr;
|
||||
__osViCurr = vc;
|
||||
*__osViNext = *__osViCurr;
|
||||
}
|
Reference in New Issue
Block a user