Refresh 13

This commit is contained in:
n64
2020-12-03 14:26:38 -05:00
parent 209a85cfa6
commit da72f38b87
552 changed files with 32958 additions and 18073 deletions
+20 -19
View File
@@ -2,7 +2,8 @@
#include "hardware.h"
#include "new_func.h"
#include "macros.h"
#if defined(VERSION_EU) || defined(VERSION_SH)
#if defined(VERSION_EU)
u32 D_802F4380() {
u32 sp3c;
u32 sp38;
@@ -25,7 +26,7 @@ u32 D_802F4380() {
WAIT_ON_IOBUSY(sp38);
HW_REG(ASIC_BM_CTL, u32) = sp30->bmCtlShadow | MECHANIC_INTERRUPT_RESET;
}
sp30->unk10 = 75;
sp30->errStatus = 75;
func_802F4A20();
return 1;
}
@@ -34,24 +35,24 @@ u32 D_802F4380() {
if (sp3c & MECHANIC_INTERRUPT) {
WAIT_ON_IOBUSY(sp38);
HW_REG(ASIC_BM_CTL, u32) = sp30->bmCtlShadow | MECHANIC_INTERRUPT_RESET;
sp30->unk10 = 0;
sp30->errStatus = 0;
return 0;
}
if (sp3c & BUFFER_MANAGER_ERROR) {
sp30->unk10 = 3;
sp30->errStatus = 3;
func_802F4A20();
return 1;
}
if (sp30->cmdType == 1) {
if ((sp3c & DATA_REQUEST) == 0) {
if (sp30->sectorNum + 1 != sp30->transferMode * 85) {
sp30->unk10 = 6;
sp30->errStatus = 6;
func_802F4A20();
return 1;
}
HW_REG(PI_STATUS_REG, u32) = PI_STATUS_CLEAR_INTR;
D_8030208C |= 0x00100401;
sp30->unk10 = 0;
__OSGlobalIntMask |= 0x00100401;
sp30->errStatus = 0;
func_802F4B08();
return 1;
}
@@ -63,12 +64,12 @@ u32 D_802F4380() {
if (sp30->cmdType == 0) {
if (sp30->transferMode == 3) {
if ((s32)(sp2c->C1ErrNum + 17) < sp30->sectorNum) {
sp30->unk10 = 0;
sp30->errStatus = 0;
func_802F4A20();
return 1;
}
if ((sp3c & DATA_REQUEST) == 0) {
sp30->unk10 = 17;
sp30->errStatus = 17;
func_802F4A20();
return 1;
}
@@ -80,7 +81,7 @@ u32 D_802F4380() {
{
if (sp2c->C1ErrNum > 3) {
if (sp30->transferMode != 3 || sp30->sectorNum > 0x52) {
sp30->unk10 = 17;
sp30->errStatus = 17;
func_802F4A20();
return 1;
}
@@ -92,7 +93,7 @@ u32 D_802F4380() {
}
if (sp3c & C2_TRANSFER) {
if (sp30->sectorNum != 87) {
sp30->unk10 = 6;
sp30->errStatus = 6;
func_802F4A20();
}
if (sp30->transferMode == 2 && sp30->blockNum == 0) {
@@ -102,10 +103,10 @@ u32 D_802F4380() {
(void *) ((u32) sp30->block[1].dramAddr - sp30->block[1].sectorSize);
} else {
HW_REG(PI_STATUS_REG, u32) = PI_STATUS_CLEAR_INTR;
D_8030208C |= 0x00100401;
__OSGlobalIntMask |= 0x00100401;
}
osEPiRawStartDma(__osDiskHandle, 0, 0x5000000, sp2c->C2Addr, sp2c->sectorSize * 4);
sp30->unk10 = 0;
sp30->errStatus = 0;
return 1;
}
@@ -114,33 +115,33 @@ u32 D_802F4380() {
if (sp30->block[0].C1ErrNum == 0) {
if (((u32 *) sp30->block[0].C2Addr)[0] | ((u32 *) sp30->block[0].C2Addr)[1]
| ((u32 *) sp30->block[0].C2Addr)[2] | ((u32 *) sp30->block[0].C2Addr)[3]) {
sp30->unk10 = 6;
sp30->errStatus = 6;
func_802F4A20();
return 1;
}
}
sp30->unk10 = 0;
sp30->errStatus = 0;
func_802F4B08();
}
sp30->sectorNum += 1;
if (sp3c & DATA_REQUEST) {
if (sp30->sectorNum > 0x54) {
sp30->unk10 = 6;
sp30->errStatus = 6;
func_802F4A20();
return 1;
}
osEPiRawStartDma(__osDiskHandle, 0, 0x05000400, sp2c->dramAddr, sp2c->sectorSize);
sp30->unk10 = 0;
sp30->errStatus = 0;
return 1;
}
if (sp30->sectorNum <= 0x54) {
sp30->unk10 = 6;
sp30->errStatus = 6;
func_802F4A20();
return 1;
}
return 1;
}
sp30->unk10 = 75;
sp30->errStatus = 75;
func_802F4A20();
return 1;
}
+8 -1
View File
@@ -41,14 +41,21 @@ s32 _Printf(char *(*prout)(char *, const char *, size_t), char *dst, const char
u8 sp4c[0x20]; // probably a buffer?
s32 sp48, sp44, sp40, sp3c, sp38, sp34, sp30, sp2c, sp28, sp24;
sp78.size = 0;
while (1) {
while (TRUE) {
fmt_ptr = (u8 *) fmt;
#ifdef VERSION_SH
// new version: don't point fmt_ptr beyond NUL character
while ((c = *fmt_ptr) != 0 && c != '%') {
fmt_ptr++;
}
#else
while ((c = *fmt_ptr++) > 0) {
if (c == '%') {
fmt_ptr--;
break;
}
}
#endif
_PROUT(dst, fmt, fmt_ptr - (u8 *) fmt);
if (c == 0) {
return sp78.size;
+85 -50
View File
@@ -1,83 +1,118 @@
#include "libultra_internal.h"
#include "macros.h"
#if defined(VERSION_EU)
#if defined(VERSION_EU) || defined(VERSION_SH)
#include "new_func.h"
void __osDevMgrMain(void *args) {
OSIoMesg *sp44;
OSMesg sp40;
OSMesg sp3c;
s32 sp38;
OSIoMesg *mb;
OSMesg em;
OSMesg dummy;
s32 ret;
OSMgrArgs *sp34;
#ifndef VERSION_SH
UNUSED u32 sp30;
#endif
u32 sp2c;
__OSBlockInfo *sp28;
__OSTranxInfo *sp24;
#ifdef VERSION_SH
u32 tmp;
#endif
#ifndef VERSION_SH
sp30 = 0;
#endif
sp2c = 0;
sp44 = NULL;
sp38 = 0;
mb = NULL;
ret = 0;
sp34 = (OSMgrArgs *) args;
while (1) {
osRecvMesg(sp34->unk08, (OSMesg) &sp44, OS_MESG_BLOCK);
if (sp44->piHandle != NULL && sp44->piHandle->type == 2
&& (sp44->piHandle->transferInfo.cmdType == 0
|| sp44->piHandle->transferInfo.cmdType == 1)) {
sp24 = &sp44->piHandle->transferInfo;
while (TRUE) {
osRecvMesg(sp34->cmdQueue, (OSMesg) &mb, OS_MESG_BLOCK);
if (mb->piHandle != NULL && mb->piHandle->type == 2
&& (mb->piHandle->transferInfo.cmdType == 0
|| mb->piHandle->transferInfo.cmdType == 1)) {
sp24 = &mb->piHandle->transferInfo;
sp28 = &sp24->block[sp24->blockNum];
sp24->sectorNum = -1;
if (sp24->transferMode != 3) {
sp28->dramAddr = (void *) ((u32) sp28->dramAddr - sp28->sectorSize);
}
if (sp24->transferMode == 2 && sp44->piHandle->transferInfo.cmdType == 0)
if (sp24->transferMode == 2 && mb->piHandle->transferInfo.cmdType == 0) {
sp2c = 1;
else
sp2c = 0;
osRecvMesg(sp34->unk10, &sp3c, OS_MESG_BLOCK);
func_802F7140(0x00100401); // remove magic constant!
func_802F71A0(sp44->piHandle, 0x05000510, (sp24->bmCtlShadow | 0x80000000));
while (1) {
osRecvMesg(sp34->unk0c, &sp40, OS_MESG_BLOCK);
sp30 = osSendMesg(sp44->hdr.retQueue, sp44, OS_MESG_NOBLOCK);
if (sp2c != 1 || sp44->piHandle->transferInfo.unk10 != 0)
break;
} else {
sp2c = 0;
}
osSendMesg(sp34->unk10, NULL, OS_MESG_NOBLOCK);
if (sp44->piHandle->transferInfo.blockNum == 1)
osRecvMesg(sp34->accessQueue, &dummy, OS_MESG_BLOCK);
__osResetGlobalIntMask(0x00100401); // remove magic constant!
__osEPiRawWriteIo(mb->piHandle, 0x05000510, (sp24->bmCtlShadow | 0x80000000));
while (TRUE) {
osRecvMesg(sp34->eventQueue, &em, OS_MESG_BLOCK);
#ifdef VERSION_SH
sp24 = &mb->piHandle->transferInfo;
sp28 = &sp24->block[sp24->blockNum];
if (sp28->errStatus == 0x1D) {
__osEPiRawWriteIo(mb->piHandle, 0x5000510, sp24->bmCtlShadow | 0x10000000);
__osEPiRawWriteIo(mb->piHandle, 0x5000510, sp24->bmCtlShadow);
__osEPiRawReadIo(mb->piHandle, 0x5000508, &tmp);
if ((tmp & 0x2000000) != 0) {
__osEPiRawWriteIo(mb->piHandle, 0x5000510, sp24->bmCtlShadow | 0x1000000);
}
sp28->errStatus = 4;
HW_REG(PI_STATUS_REG, u32) = PI_STATUS_CLEAR_INTR;
__osSetGlobalIntMask(0x100C01);
}
osSendMesg(mb->hdr.retQueue, mb, OS_MESG_NOBLOCK);
if (sp2c != 1 || mb->piHandle->transferInfo.block[0].errStatus != 0) {
break;
}
#else
sp30 = osSendMesg(mb->hdr.retQueue, mb, OS_MESG_NOBLOCK);
if (sp2c != 1 || mb->piHandle->transferInfo.errStatus != 0) {
break;
}
#endif
sp2c = 0;
}
osSendMesg(sp34->accessQueue, NULL, OS_MESG_NOBLOCK);
if (mb->piHandle->transferInfo.blockNum == 1) {
func_802F71F0();
}
} else {
switch (sp44->hdr.type) {
switch (mb->hdr.type) {
case 11:
osRecvMesg(sp34->unk10, &sp3c, OS_MESG_BLOCK);
sp38 = sp34->dma_func(OS_READ, sp44->devAddr, sp44->dramAddr, sp44->size);
osRecvMesg(sp34->accessQueue, &dummy, OS_MESG_BLOCK);
ret = sp34->dma_func(OS_READ, mb->devAddr, mb->dramAddr, mb->size);
break;
case 12:
osRecvMesg(sp34->unk10, &sp3c, OS_MESG_BLOCK);
sp38 = sp34->dma_func(OS_WRITE, sp44->devAddr, sp44->dramAddr, sp44->size);
osRecvMesg(sp34->accessQueue, &dummy, OS_MESG_BLOCK);
ret = sp34->dma_func(OS_WRITE, mb->devAddr, mb->dramAddr, mb->size);
break;
case 15:
osRecvMesg(sp34->unk10, &sp3c, OS_MESG_BLOCK);
sp38 = sp34->edma_func(sp44->piHandle, OS_READ, sp44->devAddr, sp44->dramAddr,
sp44->size);
osRecvMesg(sp34->accessQueue, &dummy, OS_MESG_BLOCK);
ret = sp34->edma_func(mb->piHandle, OS_READ, mb->devAddr, mb->dramAddr,
mb->size);
break;
case 16:
osRecvMesg(sp34->unk10, &sp3c, OS_MESG_BLOCK);
sp38 = sp34->edma_func(sp44->piHandle, OS_WRITE, sp44->devAddr, sp44->dramAddr,
sp44->size);
osRecvMesg(sp34->accessQueue, &dummy, OS_MESG_BLOCK);
ret = sp34->edma_func(mb->piHandle, OS_WRITE, mb->devAddr, mb->dramAddr,
mb->size);
break;
case 10:
osSendMesg(sp44->hdr.retQueue, sp44, OS_MESG_NOBLOCK);
sp38 = -1;
osSendMesg(mb->hdr.retQueue, mb, OS_MESG_NOBLOCK);
ret = -1;
break;
break;
default:
sp38 = -1;
ret = -1;
break;
}
if (sp38 == 0) {
osRecvMesg(sp34->unk0c, &sp40, OS_MESG_BLOCK);
sp30 = osSendMesg(sp44->hdr.retQueue, sp44, OS_MESG_NOBLOCK);
osSendMesg(sp34->unk10, NULL, OS_MESG_NOBLOCK);
if (ret == 0) {
osRecvMesg(sp34->eventQueue, &em, OS_MESG_BLOCK);
#ifndef VERSION_SH
sp30 =
#endif
osSendMesg(mb->hdr.retQueue, mb, OS_MESG_NOBLOCK);
osSendMesg(sp34->accessQueue, NULL, OS_MESG_NOBLOCK);
}
}
}
@@ -92,15 +127,15 @@ void __osDevMgrMain(void *args) {
sp34 = NULL;
sp28 = 0;
sp24 = (OSMgrArgs *) args;
while (1) {
osRecvMesg(sp24->unk08, (OSMesg) &sp34, OS_MESG_BLOCK);
while (TRUE) {
osRecvMesg(sp24->cmdQueue, (OSMesg) &sp34, OS_MESG_BLOCK);
switch (sp34->hdr.type) {
case 11:
osRecvMesg(sp24->unk10, &sp2c, OS_MESG_BLOCK);
osRecvMesg(sp24->accessQueue, &sp2c, OS_MESG_BLOCK);
sp28 = sp24->dma_func(OS_READ, sp34->devAddr, sp34->dramAddr, sp34->size);
break;
case 12:
osRecvMesg(sp24->unk10, &sp2c, OS_MESG_BLOCK);
osRecvMesg(sp24->accessQueue, &sp2c, OS_MESG_BLOCK);
sp28 = sp24->dma_func(OS_WRITE, sp34->devAddr, sp34->dramAddr, sp34->size);
break;
case 10:
@@ -112,9 +147,9 @@ void __osDevMgrMain(void *args) {
break;
}
if (sp28 == 0) {
osRecvMesg(sp24->unk0c, &sp30, OS_MESG_BLOCK);
osRecvMesg(sp24->eventQueue, &sp30, OS_MESG_BLOCK);
osSendMesg(sp34->hdr.retQueue, sp34, OS_MESG_NOBLOCK);
osSendMesg(sp24->unk10, NULL, OS_MESG_NOBLOCK);
osSendMesg(sp24->accessQueue, NULL, OS_MESG_NOBLOCK);
}
}
}
+11
View File
@@ -0,0 +1,11 @@
#include "libultra_internal.h"
#include "hardware.h"
s32 __osEPiRawReadIo(OSPiHandle *arg0, u32 devAddr, u32 *data) {
register s32 stat;
while (stat = HW_REG(PI_STATUS_REG, s32), stat & (PI_STATUS_BUSY | PI_STATUS_IOBUSY | PI_STATUS_ERROR)) {
;
}
*data = HW_REG(arg0->baseAddress | devAddr, s32);
return 0;
}
@@ -1,8 +1,7 @@
#include "libultra_internal.h"
#include "hardware.h"
//possibly osEpiWriteIo
s32 func_802F71A0(OSPiHandle *a0, u32 a1, u32 a2) {
s32 __osEPiRawWriteIo(OSPiHandle *a0, u32 a1, u32 a2) {
register u32 a3 = HW_REG(PI_STATUS_REG, u32);
while (a3 & PI_STATUS_ERROR)
a3 = HW_REG(PI_STATUS_REG, u32);
+9
View File
@@ -0,0 +1,9 @@
#include "libultra_internal.h"
#include "new_func.h"
void __osResetGlobalIntMask(u32 mask) {
register u32 prev;
prev = __osDisableInt();
__OSGlobalIntMask &= ~(-0x402 & mask);
__osRestoreInt(prev);
}
+9
View File
@@ -0,0 +1,9 @@
#include "libultra_internal.h"
#include "hardware.h"
#include "new_func.h"
void __osSetGlobalIntMask(s32 arg0) {
register u32 prev = __osDisableInt();
__OSGlobalIntMask |= arg0;
__osRestoreInt(prev);
}
+3 -1
View File
@@ -1,9 +1,11 @@
#include "libultra_internal.h"
#define SIAccessQueueSize 2
OSMesg osSiMesgBuff[SIAccessQueueSize];
OSMesgQueue gOsSiMessageQueue;
u32 gOsSiAccessQueueCreated = 0;
void __osSiCreateAccessQueue() {
gOsSiAccessQueueCreated = 1;
osCreateMesgQueue(&gOsSiMessageQueue, &osSiMesgBuff[0], SIAccessQueueSize - 1);
+1
View File
@@ -1,5 +1,6 @@
#include "libultra_internal.h"
#include "hardware.h"
s32 __osSiRawReadIo(void *a0, u32 *a1) {
if (__osSiDeviceBusy()) {
return -1;
+1
View File
@@ -1,5 +1,6 @@
#include "libultra_internal.h"
#include "hardware.h"
s32 __osSiRawWriteIo(void *a0, u32 a1) {
if (__osSiDeviceBusy()) {
return -1;
+1
View File
@@ -1,5 +1,6 @@
#include "libultra_internal.h"
#include "hardware.h"
u32 __osSpGetStatus() {
return HW_REG(SP_STATUS_REG, u32);
}
+1
View File
@@ -1,5 +1,6 @@
#include "libultra_internal.h"
#include "hardware.h"
void __osSpSetStatus(u32 status) {
HW_REG(SP_STATUS_REG, u32) = status;
}
+4 -2
View File
@@ -1,5 +1,7 @@
#include "libultra_internal.h"
extern OSViContext *D_80334910;
extern OSViContext *__osViCurr;
OSViContext *__osViGetCurrentContext() {
return D_80334910;
return __osViCurr;
}
+52 -34
View File
@@ -1,71 +1,89 @@
#include "libultra_internal.h"
#include "hardware.h"
#ifdef VERSION_SH
extern s32 D_SH_80000300; // Potentially a TV type
#endif
#ifndef VERSION_JP
extern u32 osTvType;
#endif
OSViContext D_803348B0[2] = { 0 };
OSViContext *D_80334910 = &D_803348B0[0];
OSViContext *D_80334914 = &D_803348B0[1];
OSViContext sViContexts[2] = { 0 };
OSViContext *__osViCurr = &sViContexts[0];
OSViContext *__osViNext = &sViContexts[1];
#ifdef VERSION_EU
u32 D_8033491C = 0x02E6D354;
u32 D_80334918 = TV_TYPE_PAL;
#else
u32 D_80334918 = TV_TYPE_NTSC;
u32 D_8033491C = 0x02E6D354;
u32 osViClock = 0x02E6D354; // used for audio frequency calculations
u32 sTvType = TV_TYPE_PAL;
#elif !defined(VERSION_SH)
u32 sTvType = TV_TYPE_NTSC;
u32 osViClock = 0x02E6D354;
#endif
extern OSViMode D_80334990;
extern OSViMode D_803349E0;
#ifdef VERSION_EU
#if defined(VERSION_EU) || defined(VERSION_SH)
extern OSViMode D_80302FD0;
#endif
void __osViInit(void) {
//#ifdef VERSION_JP
#ifdef VERSION_US
D_80334918 = osTvType;
sTvType = osTvType;
#endif
bzero(D_803348B0, sizeof(D_803348B0));
D_80334910 = &D_803348B0[0];
D_80334914 = &D_803348B0[1];
D_80334914->retraceCount = 1;
D_80334910->retraceCount = 1;
bzero(sViContexts, sizeof(sViContexts));
__osViCurr = &sViContexts[0];
__osViNext = &sViContexts[1];
__osViNext->retraceCount = 1;
__osViCurr->retraceCount = 1;
#ifdef VERSION_EU
#if defined(VERSION_EU)
if (osTvType == TV_TYPE_PAL) {
D_80334914->unk08 = &D_80334990;
D_8033491C = 0x02F5B2D2;
__osViNext->modep = &D_80334990;
osViClock = 0x02F5B2D2;
} else if (osTvType == TV_TYPE_MPAL) {
D_80334914->unk08 = &D_803349E0;
D_8033491C = 0x02E6025C;
__osViNext->modep = &D_803349E0;
osViClock = 0x02E6025C;
} else {
D_80334914->unk08 = &D_80302FD0;
D_8033491C = 0x02E6D354;
}
__osViNext->modep = &D_80302FD0;
osViClock = 0x02E6D354;
}
#elif defined(VERSION_SH)
__osViNext->buffer = (void *) 0x80000000;
__osViCurr->buffer = (void *) 0x80000000;
if (osTvType == TV_TYPE_PAL) {
__osViNext->modep = &D_80334990;
} else if (osTvType == TV_TYPE_MPAL) {
__osViNext->modep = &D_803349E0;
} else {
__osViNext->modep = &D_80302FD0;
}
#else
#ifdef VERSION_JP
if (D_80334918 != TV_TYPE_PAL)
if (sTvType != TV_TYPE_PAL)
#else
if (D_80334918 == TV_TYPE_NTSC)
if (sTvType == TV_TYPE_NTSC)
#endif
{
D_80334914->unk08 = &D_80334990;
D_8033491C = 0x02E6D354;
__osViNext->modep = &D_80334990;
osViClock = 0x02E6D354;
} else {
D_80334914->unk08 = &D_803349E0;
#ifdef VERSION_JP
D_8033491C = 0x02F5B2D2;
#else
D_8033491C = 0x02E6025C;
__osViNext->modep = &D_803349E0;
#if defined(VERSION_JP)
osViClock = 0x02F5B2D2;
#elif defined(VERSION_US)
osViClock = 0x02E6025C;
#endif
}
#endif
D_80334914->unk00 = 32;
D_80334914->features = D_80334914->unk08->comRegs.ctrl;
__osViNext->unk00 = 0x20;
__osViNext->features = __osViNext->modep->comRegs.ctrl;
#ifndef VERSION_JP
while (HW_REG(VI_CURRENT_REG, u32) > 0xa) {
;
+9 -7
View File
@@ -1,7 +1,9 @@
#include "libultra_internal.h"
#include "hardware.h"
extern OSViContext *D_80334914;
extern OSViContext *D_80334910;
extern OSViContext *__osViNext;
extern OSViContext *__osViCurr;
void __osViSwapContext() {
register OSViMode *s0;
register OSViContext *s1;
@@ -11,8 +13,8 @@ void __osViSwapContext() {
u32 field;
register u32 s2;
field = 0;
s1 = D_80334914;
s0 = s1->unk08;
s1 = __osViNext;
s0 = s1->modep;
field = HW_REG(VI_V_CURRENT_LINE_REG, u32) & 1;
s2 = osVirtualToPhysical(s1->buffer);
origin = (s0->fldRegs[field].origin) + s2;
@@ -53,7 +55,7 @@ void __osViSwapContext() {
HW_REG(VI_X_SCALE_REG, u32) = s1->unk20;
HW_REG(VI_Y_SCALE_REG, u32) = s1->unk2c;
HW_REG(VI_CONTROL_REG, u32) = s1->features;
D_80334914 = D_80334910;
D_80334910 = s1;
*D_80334914 = *D_80334910;
__osViNext = __osViCurr;
__osViCurr = s1;
*__osViNext = *__osViCurr;
}
+36
View File
@@ -0,0 +1,36 @@
#ifndef __BSTRING_H__
#define __BSTRING_H__
#ifdef __cplusplus
extern "C" {
#endif
/*
* bstring(3C) -- byte string operations
*
* Copyright 1990, Silicon Graphics, Inc.
* All Rights Reserved.
*
* This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
* the contents of this file may not be disclosed to third parties, copied or
* duplicated in any form, in whole or in part, without the prior written
* permission of Silicon Graphics, Inc.
*
* RESTRICTED RIGHTS LEGEND:
* Use, duplication or disclosure by the Government is subject to restrictions
* as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
* and Computer Software clause at DFARS 252.227-7013, and/or in similar or
* successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
* rights reserved under the Copyright Laws of the United States.
*/
#ident "$Revision: 1.4 $"
extern void bcopy(const void *, void *, size_t);
extern int bcmp(const void *, const void *, int);
extern void bzero(void *, size_t);
extern void blkclr(void *, int);
#ifdef __cplusplus
}
#endif
#endif /* !__BSTRING_H__ */
+90
View File
@@ -0,0 +1,90 @@
#include "libultra_internal.h"
#include "PR/rcp.h"
#include "controller.h"
#ifdef VERSION_SH
extern s32 func_8030A5C0(OSMesgQueue *, s32);
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();
_osLastSentSiCmd = 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 = func_8030A5C0(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;
}
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;
}
#endif
+90
View File
@@ -0,0 +1,90 @@
#include "libultra_internal.h"
#include "PR/rcp.h"
#include "controller.h"
#ifdef VERSION_SH
extern s32 func_8030A5C0(OSMesgQueue *, s32);
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();
_osLastSentSiCmd = 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 = func_8030A5C0(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;
}
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;
}
#endif
+208
View File
@@ -0,0 +1,208 @@
#ifndef _CONTROLLER_H
#define _CONTROLLER_H
#include "PR/os_internal.h"
#include "os.h"
#include "PR/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 _osLastSentSiCmd;
extern OSTimer __osEepromTimer;
extern OSMesg __osEepromTimerMsg;
extern OSMesgQueue __osEepromTimerQ;
extern OSPifRam __osEepPifRam;
extern OSPifRam __osContPifRam;
extern OSPifRam __osPfsPifRam;
extern u8 _osContNumControllers;
//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;
+48
View File
@@ -0,0 +1,48 @@
#include "libultra_internal.h"
#ifdef VERSION_SH
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;
}
#endif

Some files were not shown because too many files have changed in this diff Show More