Match __osLeoInterrupt.c (#457)

* Match __osLeoInterrupt.c

* fix formatting

---------

Co-authored-by: MegaMech <MegaMech@users.noreply.github.com>
This commit is contained in:
AloXado320
2023-10-11 20:00:21 -05:00
committed by GitHub
parent 740efaa303
commit 364f0776c6
5 changed files with 178 additions and 814 deletions
+166 -195
View File
@@ -1,9 +1,6 @@
// not matching
#include "libultra_internal.h"
#include "ultra64.h"
#include "osint.h"
#include "piint.h"
#include "ultra64.h"
extern OSThread *__osRunQueue;
static void __osLeoResume(void);
@@ -12,202 +9,176 @@ extern u8 leoDiskStack[OS_PIM_STACKSIZE]; //technically should have a OS_LEO_STA
extern u32 D_800EA5F0;
s32 __osLeoInterrupt()
{
u32 stat;
volatile u32 pi_stat;
u32 bm_stat;
__OSTranxInfo *info;
__OSBlockInfo *blockInfo;
s32 __osLeoInterrupt() {
u32 stat;
volatile u32 pistat;
u32 bmstat;
__OSTranxInfo *info;
__OSBlockInfo *blockInfo;
// addition to mk64
if (D_800EA5F0 == 0) return 0;
if (!D_800EA5F0) {
return 0;
}
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 != 87)
{
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);
info = &__osDiskHandle->transferInfo;
blockInfo = &info->block[info->blockNum];
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;
}
pistat = IO_READ(PI_STATUS_REG);
if (pistat & PI_STATUS_DMA_BUSY) {
IO_WRITE(PI_STATUS_REG, PI_STATUS_RESET | PI_STATUS_CLR_INTR);
WAIT_ON_LEO_IO_BUSY(pistat);
stat = IO_READ(LEO_STATUS);
if (stat & LEO_STATUS_MECHANIC_INTERRUPT) {
WAIT_ON_LEO_IO_BUSY(pistat);
IO_WRITE(LEO_BM_CTL, info->bmCtlShadow | LEO_BM_CTL_CLR_MECHANIC_INTR);
}
info->errStatus = LEO_ERROR_75;
__osLeoAbnormalResume();
return 1;
}
WAIT_ON_LEO_IO_BUSY(pistat);
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;
stat = IO_READ(LEO_STATUS);
if (stat & LEO_STATUS_MECHANIC_INTERRUPT) {
WAIT_ON_LEO_IO_BUSY(pistat);
IO_WRITE(LEO_BM_CTL, info->bmCtlShadow | LEO_BM_CTL_CLR_MECHANIC_INTR);
info->errStatus = LEO_ERROR_GOOD;
return 0;
}
if (stat & LEO_STATUS_BUFFER_MANAGER_ERROR) {
info->errStatus = LEO_ERROR_3;
__osLeoAbnormalResume();
return 1;
}
if (info->cmdType == LEO_CMD_TYPE_1) {
if ((stat & LEO_STATUS_DATA_REQUEST) == 0) {
if (info->sectorNum + 1 != info->transferMode * 85) {
info->errStatus = LEO_ERROR_6;
__osLeoAbnormalResume();
return 1;
}
IO_WRITE(PI_STATUS_REG, PI_STATUS_CLR_INTR);
__OSGlobalIntMask |= OS_IM_PI;
info->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) {
info->errStatus = LEO_ERROR_GOOD;
__osLeoAbnormalResume();
return 1;
}
if ((stat & LEO_STATUS_DATA_REQUEST) == 0) {
info->errStatus = LEO_ERROR_17;
__osLeoAbnormalResume();
return 1;
}
} else {
blockInfo->dramAddr = (void *)((u32)blockInfo->dramAddr + blockInfo->sectorSize);
}
bmstat = IO_READ(LEO_BM_STATUS);
if ((bmstat & LEO_BM_STATUS_C1SINGLE && bmstat & LEO_BM_STATUS_C1DOUBLE) || bmstat & LEO_BM_STATUS_MICRO) {
if (blockInfo->C1ErrNum > 3) {
if (info->transferMode != LEO_SECTOR_MODE || info->sectorNum > 0x52) {
info->errStatus = LEO_ERROR_17;
__osLeoAbnormalResume();
return 1;
}
} else {
s32 errNum = blockInfo->C1ErrNum;
blockInfo->C1ErrSector[errNum] = info->sectorNum + 1;
}
blockInfo->C1ErrNum++;
}
if (stat & LEO_STATUS_C2_TRANSFER) {
if (info->sectorNum != 87) {
info->errStatus = LEO_ERROR_6;
__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);
} else {
IO_WRITE(PI_STATUS_REG, PI_STATUS_CLR_INTR);
__OSGlobalIntMask |= OS_IM_PI;
}
osEPiRawStartDma(__osDiskHandle, OS_READ, LEO_C2_BUFF, blockInfo->C2Addr, blockInfo->sectorSize * 4);
info->errStatus = LEO_ERROR_GOOD;
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]) {
info->errStatus = LEO_ERROR_6;
__osLeoAbnormalResume();
return 1;
}
}
info->errStatus = LEO_ERROR_GOOD;
__osLeoResume();
}
info->sectorNum++;
if (stat & LEO_STATUS_DATA_REQUEST) {
if (info->sectorNum > 0x54) {
info->errStatus = LEO_ERROR_6;
__osLeoAbnormalResume();
return 1;
}
osEPiRawStartDma(__osDiskHandle, 0, LEO_SECTOR_BUFF, blockInfo->dramAddr, blockInfo->sectorSize);
info->errStatus = LEO_ERROR_GOOD;
return 1;
}
if (info->sectorNum <= 0x54) {
info->errStatus = LEO_ERROR_6;
__osLeoAbnormalResume();
return 1;
}
return 1;
}
info->errStatus = LEO_ERROR_75;
__osLeoAbnormalResume();
return 1;
}
void __osLeoAbnormalResume(void)
{
__OSTranxInfo *info;
u32 pi_stat;
info = &__osDiskHandle->transferInfo;
WAIT_ON_IOBUSY(pi_stat);
IO_WRITE(LEO_BM_CTL, info->bmCtlShadow | LEO_BM_CTL_RESET);
WAIT_ON_IOBUSY(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 __osLeoAbnormalResume(void) {
__OSTranxInfo *info;
u32 pistat;
info = &__osDiskHandle->transferInfo;
WAIT_ON_LEO_IO_BUSY(pistat);
IO_WRITE(LEO_BM_CTL, info->bmCtlShadow | LEO_BM_CTL_RESET);
WAIT_ON_LEO_IO_BUSY(pistat);
IO_WRITE(LEO_BM_CTL, info->bmCtlShadow);
__osLeoResume();
IO_WRITE(PI_STATUS_REG, PI_STATUS_CLR_INTR);
__OSGlobalIntMask |= OS_IM_PI;
}
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));
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));
}
}
+11 -2
View File
@@ -88,11 +88,15 @@
#define LEO_CMD_TYPE_2 2 //TODO: name
#define LEO_ERROR_GOOD 0
#define LEO_ERROR_3 3
#define LEO_ERROR_4 4 //maybe busy?
#define LEO_ERROR_22 22 //
#define LEO_ERROR_6 6
#define LEO_ERROR_17 17
#define LEO_ERROR_22 22
#define LEO_ERROR_23 23 //unrecovered read error?
#define LEO_ERROR_24 24 //no reference position found?
#define LEO_ERROR_29 29 //
#define LEO_ERROR_29 29
#define LEO_ERROR_75 75
extern OSDevMgr __osPiDevMgr;
extern OSPiHandle *__osCurrentHandle[2];
@@ -110,6 +114,11 @@ OSMesgQueue *osPiGetCmdQueue(void);
#define OS_RAMROM_STACKSIZE 1024
#define WAIT_ON_LEO_IO_BUSY(stat) \
stat = IO_READ(PI_STATUS_REG); \
while (stat & PI_STATUS_IO_BUSY) \
stat = IO_READ(PI_STATUS_REG);
#define WAIT_ON_IOBUSY(stat) \
stat = IO_READ(PI_STATUS_REG); \
while (stat & (PI_STATUS_IO_BUSY | PI_STATUS_DMA_BUSY)) \