mirror of
https://github.com/ACreTeam/ac-decomp
synced 2026-05-23 06:34:18 -04:00
finish some OS files and update readme
This commit is contained in:
@@ -15,7 +15,7 @@ Use `--recursive` when cloning to have ppcdis in the repository.
|
||||
- Dump a copy of the game and extract **main.dol** and **foresta.rel.szs**.
|
||||
- Decompress **foresta.rel.szs** with yaz0 found in *tools/*.
|
||||
- Place **main.dol** and **foresta.rel** in *dump/*.
|
||||
- Place CodeWarrior 1.3.2 in *tools/1.3.2/*.
|
||||
- Place CodeWarrior 1.3.2 in *tools/1.3.2/* and 1.2.5 in *tools/1.2.5/*.
|
||||
- Install DevkitPPC, Ninja and Python:
|
||||
- **Only tested with DevkitPPC r41 and Python 3.8.10**, however other versions should work fine.
|
||||
- Install Python modules from requirements.txt (`pip install -r requirements.txt`)
|
||||
|
||||
@@ -0,0 +1,169 @@
|
||||
#include "dolphin/OS/OSAlarm.h"
|
||||
#include "dolphin/OS/OSTime.h"
|
||||
#inlcude "dolphin/OS/OSContext.h"
|
||||
|
||||
void OSInitAlarm(void){
|
||||
|
||||
if (__OSGetExceptionHandler(8) |= DecrementerExceptionHandler){
|
||||
AlarmQueue.tail = 0;
|
||||
AlarmQueue.head = 0;
|
||||
__OSSetExceptionHandler(8, DecrementerExceptionHandler);
|
||||
}
|
||||
}
|
||||
void OSCreateAlarm(OSAlarm* alarm){
|
||||
alarm->handler = NULL;
|
||||
}
|
||||
|
||||
static void InsertAlarm(OSAlarm* alarm, OSTime fire, OSAlarmHandler handler){
|
||||
OSAlarm* next;
|
||||
OSAlarm* prev;
|
||||
|
||||
if (0 < alarm->period) {
|
||||
OSTime time = __OSGetSystemTime();
|
||||
|
||||
fire = alarm->start;
|
||||
if (alarm->start < time) {
|
||||
fire += alarm->period * ((time - alarm->start) / alarm->period + 1);
|
||||
}
|
||||
}
|
||||
|
||||
alarm->handler = handler;
|
||||
alarm->fire = fire;
|
||||
|
||||
for (next = AlarmQueue.head; next; next = next->next){
|
||||
if (next->fire <= fire) {
|
||||
continue;
|
||||
}
|
||||
alarm->prev = next->prev;
|
||||
next->prev = alarm;
|
||||
alarm->next = next;
|
||||
prev = alarm->prev;
|
||||
if (prev) {
|
||||
prev->next = alarm;
|
||||
}
|
||||
else{
|
||||
AlarmQueue.head = alarm;
|
||||
SetTimer(alarm);
|
||||
}
|
||||
return;
|
||||
}
|
||||
alarm->next = 0;
|
||||
prev = AlarmQueue.tail;
|
||||
AlarmQueue.tail = alarm;
|
||||
alarm->prev = prev;
|
||||
if (prev) {
|
||||
prev->next = alarm;
|
||||
}
|
||||
else {
|
||||
AlarmQueue.head = AlarmQueue.tail = alarm;
|
||||
SetTimer(alarm);
|
||||
}
|
||||
}
|
||||
|
||||
void OSSetAlarm(OSAlarm* alarm, OSTime tick, OSAlarmHandler handler){
|
||||
u32 res = OSDisableInterrupts();
|
||||
alarm->period = 0;
|
||||
InsertAlarm(alarm, __OSGetSystemTime() + tick, handler);
|
||||
OSRestoreInterrupts(res);
|
||||
}
|
||||
|
||||
void OSCancelAlarm(OSAlarm* alarm){
|
||||
OSAlarm* next;
|
||||
BOOL res;
|
||||
|
||||
res = OSDisableInterrupts();
|
||||
|
||||
if(alarm->handler == 0) {
|
||||
OSRestoreInterrupts(res);
|
||||
return;
|
||||
}
|
||||
|
||||
next = alarm->next;
|
||||
if (next == 0) {
|
||||
AlarmQueue.tail = alarm->prev;
|
||||
}
|
||||
else {
|
||||
AlarmQueue.head = next;
|
||||
if (next) {
|
||||
SetTimer(next)
|
||||
}
|
||||
}
|
||||
alarm->handler = 0;
|
||||
|
||||
OSRestoreInterrupts(res);
|
||||
}
|
||||
|
||||
static void DecrementerExceptionCallback(register OSException exc, register OSContext* ctx){
|
||||
OSAlarmHandler handler;
|
||||
OSTime time;
|
||||
OSContext excctx;
|
||||
OSAlarm* alarm;
|
||||
OSAlarm* next;
|
||||
|
||||
time = __OSGetSystemTime();
|
||||
alarm = AlarmQueue.head;
|
||||
if (alarm == NULL){
|
||||
OSLoadContext(ctx);
|
||||
}
|
||||
|
||||
if (time < alarm->fire) {
|
||||
SetTimer(alarm);
|
||||
OSLoadContext(ctx);
|
||||
}
|
||||
next = alarm->next;
|
||||
AlarmQueue.head = next;
|
||||
if (next == NULL) {
|
||||
AlarmQueue.tail = NULL;
|
||||
}
|
||||
else {
|
||||
next->prev = NULL;
|
||||
}
|
||||
handler = alarm->handler;
|
||||
alarm->handler = NULL;
|
||||
|
||||
if (0 < alarm->period) {
|
||||
InsertAlarm(alarm, 0, handler);
|
||||
}
|
||||
if (AlarmQueue.head) {
|
||||
SetTimer(AlarmQueue.head);
|
||||
}
|
||||
|
||||
OSDisableScheduler();
|
||||
OSClearContext(&excctx);
|
||||
OSSetCurrentContext(&excctx);
|
||||
|
||||
handler(alarm, ctx);
|
||||
|
||||
OSClearContext(&excctx);
|
||||
OSSetCurrentContext(ctx);
|
||||
OSEnableScheduler();
|
||||
|
||||
__OSReschedule();
|
||||
OSLoadContext(ctx);
|
||||
}
|
||||
|
||||
static asm void DecrementerExceptionHandler(register u8 type, register OSContext* ctx){
|
||||
nofralloc
|
||||
stw r0, ctx->gprs[0]
|
||||
stw r1, ctx->gprs[1]
|
||||
stw r2, ctx->gprs[2]
|
||||
stmw r6, ctx->gprs[6]
|
||||
|
||||
mfspr r0, 0x391
|
||||
stw r0, ctx->gqrs[1]
|
||||
mfspr r0, 0x392
|
||||
stw r0, ctx->gqrs[2]
|
||||
mfspr r0, 0x393
|
||||
stw r0, ctx->gqrs[3]
|
||||
mfspr r0, 0x394
|
||||
stw r0, ctx->gqrs[4]
|
||||
mfspr r0, 0x395
|
||||
stw r0, ctx->gqrs[5]
|
||||
mfspr r0, 0x396
|
||||
stw r0, ctx->gqrs[6]
|
||||
mfspr r0, 0x397
|
||||
stw r0, ctx->gqrs[7]
|
||||
|
||||
stwu r1, -8(r1)
|
||||
b DecrementerExceptionCallback
|
||||
}
|
||||
@@ -2,4 +2,22 @@
|
||||
|
||||
u32 OSGetConsoleSimulatedMemSize(void){
|
||||
return(SIM_MEM);
|
||||
}
|
||||
static bool OnReset(bool final){
|
||||
if (final) {
|
||||
__MEMRegs[8] = 0xff;
|
||||
__OSMaskInterrupts(0xF0000000);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
static void MEMInterruptsHandler(__OSInterrupt interrupt, OSContext* ctx){
|
||||
u32 cause = __MEMRegs[0xf];
|
||||
u32 addr = (((u32) __MEMRegs[0x12] & 0x3ff) << 16) | __MEMRegs[0x11];
|
||||
__MEMRegs[0x10] = 0;
|
||||
|
||||
if(__OSErrorTable[OS_ERROR_PROTECTION]) {
|
||||
__OSErrorTable[OS_ERROR_PROTECTION](OS_ERROR_PROTECTION, ctx, cause, adr);
|
||||
return;
|
||||
}
|
||||
__OSUnhandledException(OS_ERROR_PROTECTION, ctx, cause, addr);
|
||||
}
|
||||
@@ -13,10 +13,10 @@ void bzero(void* __s, size_t __n) {
|
||||
memset(__s, 0, __n);
|
||||
}
|
||||
|
||||
/* void osWritebackDCache(void* buf, u32 len){
|
||||
DCStoreRange();
|
||||
void osWritebackDCache(void* buf, u32 len){
|
||||
DCStoreRange(buf, len);
|
||||
}
|
||||
*/
|
||||
|
||||
/* s32 osGetCount(void){
|
||||
return OSGetTick();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user