remove "done" folders, label "bs/droneenter, bs/dronelook, and bs/dronevanish files and functions"

This commit is contained in:
Banjo Kazooie
2023-01-21 20:13:03 -06:00
parent 0ecaa54b4a
commit c004632915
190 changed files with 645 additions and 644 deletions

View File

@@ -0,0 +1,19 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
extern struct __osThreadTail
{
OSThread *next;
OSPri priority;
} __osThreadTail;
void osCreateMesgQueue(OSMesgQueue *mq, OSMesg *msg, s32 msgCount)
{
mq->mtqueue = (OSThread *)&__osThreadTail;
mq->fullqueue = (OSThread *)&__osThreadTail;
mq->validCount = 0;
mq->first = 0;
mq->msgCount = msgCount;
mq->msg = msg;
}

View File

@@ -0,0 +1,31 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
void __osCleanupThread(void);
extern OSThread *__osActiveQueue;
void osCreateThread(OSThread *t, OSId id, void (*entry)(void *), void *arg, void *sp, OSPri p)
{
register u32 saveMask;
OSIntMask mask;
t->id = id;
t->priority = p;
t->next = NULL;
t->queue = NULL;
t->context.pc = (u32)entry;
t->context.a0 = (u64)arg;
t->context.sp = (u64)sp - 16;
t->context.ra = (u64)__osCleanupThread;
// t->context.ra = (u64)func_8026ABE0;
mask = OS_IM_ALL;
t->context.sr = SR_IMASK | SR_EXL | SR_IE;
t->context.rcp = (mask & RCP_IMASK) >> RCP_IMASKSHIFT;
t->context.fpcsr = (u32)(FPCSR_FS | FPCSR_EV);
t->fp = 0;
t->state = OS_STATE_STOPPED;
t->flags = 0;
saveMask = __osDisableInt();
t->tlnext = __osActiveQueue;
__osActiveQueue = t;
__osRestoreInt(saveMask);
}

View File

@@ -0,0 +1,48 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
extern OSThread *__osRunningThread;
extern OSThread *__osActiveQueue;
extern void __osDispatchThread(void);
void osDestroyThread(OSThread *t)
{
register u32 saveMask;
register OSThread *pred;
register OSThread *succ;
saveMask = __osDisableInt();
if (t == NULL)
{
t = __osRunningThread;
}
else
{
if (t->state != OS_STATE_STOPPED)
{
__osDequeueThread(t->queue, t);
}
}
if (__osActiveQueue == t)
{
__osActiveQueue = __osActiveQueue->tlnext;
}
else
{
pred = __osActiveQueue;
while (succ = pred->tlnext)
{
if (succ == t)
{
pred->tlnext = t->tlnext;
break;
}
pred = succ;
}
}
if (t == __osRunningThread)
{
__osDispatchThread();
}
__osRestoreInt(saveMask);
}

View File

@@ -0,0 +1,12 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
extern OSThread *__osRunningThread;
OSPri osGetThreadPri(OSThread *thread)
{
if (thread == NULL)
thread = __osRunningThread;
return thread->priority;
}

17
src/core1/os/gettime.c Normal file
View File

@@ -0,0 +1,17 @@
#include <os_internal.h>
#include "osint.h"
OSTime osGetTime()
{
u32 tmptime;
u32 elapseCount;
OSTime currentCount;
register u32 saveMask;
saveMask = __osDisableInt();
tmptime = osGetCount();
elapseCount = tmptime - __osBaseCounter;
currentCount = __osCurrentTime;
__osRestoreInt(saveMask);
return currentCount + elapseCount;
}

33
src/core1/os/jammesg.c Normal file
View File

@@ -0,0 +1,33 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
extern OSThread *__osRunningThread;
s32 osJamMesg(OSMesgQueue *mq, OSMesg msg, s32 flag)
{
register u32 saveMask = __osDisableInt();
while (mq->validCount >= mq->msgCount)
{
if (flag == OS_MESG_BLOCK)
{
__osRunningThread->state = OS_STATE_WAITING;
__osEnqueueAndYield(&mq->fullqueue);
}
else
{
__osRestoreInt(saveMask);
return -1;
}
}
mq->first = (mq->first + mq->msgCount - 1) % mq->msgCount;
mq->msg[mq->first] = msg;
mq->validCount++;
if (mq->mtqueue->next != NULL)
{
osStartThread(__osPopThread(&mq->mtqueue));
}
__osRestoreInt(saveMask);
return 0;
}

31
src/core1/os/pidma.c Normal file
View File

@@ -0,0 +1,31 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
extern OSDevMgr __osPiDevMgr;
s32 osPiStartDma(OSIoMesg *mb, s32 priority, s32 direction, u32 devAddr, void *dramAddr, u32 size, OSMesgQueue *mq)
{
register s32 ret;
if (!__osPiDevMgr.active)
return -1;
if (direction == OS_READ)
mb->hdr.type = OS_MESG_TYPE_DMAREAD;
else
mb->hdr.type = OS_MESG_TYPE_DMAWRITE;
mb->hdr.pri = priority;
mb->hdr.retQueue = mq;
mb->dramAddr = dramAddr;
mb->devAddr = devAddr;
mb->size = size;
mb->piHandle = NULL;
if (priority == OS_MESG_PRI_HIGH)
{
ret = osJamMesg(osPiGetCmdQueue(), (OSMesg)mb, OS_MESG_NOBLOCK);
}
else
{
ret = osSendMesg(osPiGetCmdQueue(), (OSMesg)mb, OS_MESG_NOBLOCK);
}
return ret;
}

35
src/core1/os/recvmesg.c Normal file
View File

@@ -0,0 +1,35 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
extern OSThread *__osRunningThread;//_osRunningThread;
s32 osRecvMesg(OSMesgQueue *mq, OSMesg *msg, s32 flags)
{
register u32 saveMask;
saveMask = __osDisableInt();
while (MQ_IS_EMPTY(mq))
{
if (flags == OS_MESG_NOBLOCK)
{
__osRestoreInt(saveMask);
return -1;
}
__osRunningThread->state = OS_STATE_WAITING;
__osEnqueueAndYield(&mq->mtqueue);
}
if (msg != NULL)
{
*msg = mq->msg[mq->first];
}
mq->first = (mq->first + 1) % mq->msgCount;
mq->validCount--;
if (mq->fullqueue->next != NULL)
{
osStartThread(__osPopThread(&mq->fullqueue));
}
__osRestoreInt(saveMask);
return 0;
}

View File

@@ -0,0 +1,13 @@
#include <os_internal.h>
#include <R4300.h>
void __osResetGlobalIntMask(OSHWIntr interrupt)
{
register u32 saveMask = __osDisableInt();
//not sure about these constants, SR_IBIT3 is external level 3 INT0, which I think corresponds to the rcp
//os.h has several masks defined that end in 401 but non that are just 401
__OSGlobalIntMask &= ~(interrupt & ~(SR_IBIT3 | SR_IE));
__osRestoreInt(saveMask);
}

34
src/core1/os/sendmesg.c Normal file
View File

@@ -0,0 +1,34 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
extern OSThread *__osRunningThread;
s32 osSendMesg(OSMesgQueue *mq, OSMesg msg, s32 flags)
{
register u32 saveMask;
register s32 last;
saveMask = __osDisableInt();
while (MQ_IS_FULL(mq))
{
if (flags == OS_MESG_BLOCK)
{
__osRunningThread->state = OS_STATE_WAITING;
__osEnqueueAndYield(&mq->fullqueue);
}
else
{
__osRestoreInt(saveMask);
return -1;
}
}
last = (mq->first + mq->validCount) % mq->msgCount;
mq->msg[last] = msg;
mq->validCount++;
if (mq->mtqueue->next != NULL)
{
osStartThread(__osPopThread(&mq->mtqueue));
}
__osRestoreInt(saveMask);
return 0;
}

View File

@@ -0,0 +1,14 @@
#include <os_internal.h>
#include "osint.h"
__OSEventState __osEventStateTab[OS_NUM_EVENTS];
void osSetEventMesg(OSEvent event, OSMesgQueue *mq, OSMesg msg)
{
register u32 saveMask = __osDisableInt();
__OSEventState *es;
es = &__osEventStateTab[event];
es->messageQueue = mq;
es->message = msg;
__osRestoreInt(saveMask);
}

View File

@@ -0,0 +1,9 @@
#include <os_internal.h>
#include <R4300.h>
void __osSetGlobalIntMask(OSHWIntr mask)
{
register u32 saveMask = __osDisableInt();
__OSGlobalIntMask |= mask;
__osRestoreInt(saveMask);
}

19
src/core1/os/settimer.c Normal file
View File

@@ -0,0 +1,19 @@
#include <os_internal.h>
#include "osint.h"
int osSetTimer(OSTimer *t, OSTime value, OSTime interval, OSMesgQueue *mq, OSMesg msg)
{
OSTime time;
t->next = NULL;
t->prev = NULL;
t->interval = interval;
if(value != 0) t->value = value;
else t->value = interval;
t->mq = mq;
t->msg = msg;
time = __osInsertTimer(t);
if(__osTimerList->next == t) {
__osSetTimerIntr(time);
}
return 0;
}

View File

@@ -0,0 +1,28 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
extern OSThread *__osRunningThread;
extern OSThread *__osRunQueue;
void osSetThreadPri(OSThread *t, OSPri pri)
{
register u32 saveMask = __osDisableInt();
if (t == NULL)
t = __osRunningThread;
if (t->priority != pri)
{
t->priority = pri;
if (t != __osRunningThread && t->state != OS_STATE_STOPPED)
{
__osDequeueThread(t->queue, t);
__osEnqueueThread(t->queue, t);
}
if (__osRunningThread->priority < __osRunQueue->priority)
{
__osRunningThread->state = OS_STATE_RUNNABLE;
__osEnqueueAndYield(&__osRunQueue);
}
}
__osRestoreInt(saveMask);
}

View File

@@ -0,0 +1,45 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
extern OSThread * __osRunQueue;
extern OSThread * __osRunningThread;
void osStartThread(OSThread *t)
{
register u32 saveMask = __osDisableInt();
switch (t->state)
{
case OS_STATE_WAITING:
t->state = OS_STATE_RUNNABLE;
__osEnqueueThread(&__osRunQueue, t);
break;
case OS_STATE_STOPPED:
if (t->queue == NULL || t->queue == &__osRunQueue)
{
t->state = OS_STATE_RUNNABLE;
__osEnqueueThread(&__osRunQueue, t);
}
else
{
t->state = OS_STATE_WAITING;
__osEnqueueThread(t->queue, t);
__osEnqueueThread(&__osRunQueue, __osPopThread(t->queue));
}
break;
}
if (__osRunningThread == NULL)
{
__osDispatchThread();
}
else
{
if (__osRunningThread->priority < __osRunQueue->priority)
{
__osRunningThread->state = OS_STATE_RUNNABLE;
__osEnqueueAndYield(&__osRunQueue);
}
}
__osRestoreInt(saveMask);
}

32
src/core1/os/stopthread.c Normal file
View File

@@ -0,0 +1,32 @@
#include <ultra64.h>
#include "functions.h"
#include "variables.h"
extern OSThread *__osRunningThread;
void osStopThread(OSThread *t)
{
register u32 saveMask = __osDisableInt();
register u16 state;
if (t == NULL)
{
state = OS_STATE_RUNNING;
}
else
{
state = t->state;
}
switch (state)
{
case OS_STATE_RUNNING:
__osRunningThread->state = OS_STATE_STOPPED;
__osEnqueueAndYield(NULL);
break;
case OS_STATE_RUNNABLE:
case OS_STATE_WAITING:
t->state = OS_STATE_STOPPED;
__osDequeueThread(t->queue, t);
break;
}
__osRestoreInt(saveMask);
}

27
src/core1/os/stoptimer.c Normal file
View File

@@ -0,0 +1,27 @@
#include <ultra64.h>
#include "osint.h"
int osStopTimer(OSTimer *t)
{
register u32 savedMask;
OSTimer *timep;
if (t->next == NULL)
return -1;
savedMask = __osDisableInt();
timep = t->next;
if (timep != __osTimerList)
{
timep->value += t->value;
}
t->prev->next = t->next;
t->next->prev = t->prev;
t->next = NULL;
t->prev = NULL;
if (__osTimerList->next == __osTimerList)
{
__osSetCompare(0);
}
__osRestoreInt(savedMask);
return 0;
}

26
src/core1/os/thread.c Normal file
View File

@@ -0,0 +1,26 @@
#include <os_internal.h>
#include "osint.h"
struct __osThreadTail __osThreadTail = {0, -1};
OSThread *__osRunQueue = (OSThread *)&__osThreadTail;
OSThread *__osActiveQueue = (OSThread *)&__osThreadTail;
OSThread *__osRunningThread = {0};
OSThread *__osFaultedThread = {0};
void __osDequeueThread(OSThread **queue, OSThread *t)
{
register OSThread *pred;
register OSThread *succ;
pred = (OSThread *)queue; //this is actually legit..
succ = pred->next;
while (succ != NULL)
{
if (succ == t)
{
pred->next = t->next;
return;
}
pred = succ;
succ = pred->next;
}
}

99
src/core1/os/timerintr.c Normal file
View File

@@ -0,0 +1,99 @@
#include <os_internal.h>
#include "osint.h"
OSTimer *__osTimerList = &__osBaseTimer;
OSTimer __osBaseTimer;
OSTime __osCurrentTime;
u32 __osBaseCounter;
u32 __osViIntrCount;
u32 __osTimerCounter;
void __osTimerServicesInit(void)
{
__osCurrentTime = 0;
__osBaseCounter = 0;
__osViIntrCount = 0;
__osTimerList->prev = __osTimerList;
__osTimerList->next = __osTimerList->prev;
__osTimerList->value = 0;
__osTimerList->interval = __osTimerList->value;
__osTimerList->mq = NULL;
__osTimerList->msg = 0;
}
void __osTimerInterrupt(void)
{
OSTimer *t;
u32 count;
u32 elapsed_cycles;
if (__osTimerList->next == __osTimerList)
return;
while (1)
{
t = __osTimerList->next;
if (t == __osTimerList)
{
__osSetCompare(0);
__osTimerCounter = 0;
break;
}
count = osGetCount();
elapsed_cycles = count - __osTimerCounter;
__osTimerCounter = count;
if (elapsed_cycles < t->value)
{
t->value -= elapsed_cycles;
__osSetTimerIntr(t->value);
return;
}
else
{
t->prev->next = t->next;
t->next->prev = t->prev;
t->next = NULL;
t->prev = NULL;
if (t->mq != NULL)
{
osSendMesg(t->mq, t->msg, OS_MESG_NOBLOCK);
}
if (t->interval != 0)
{
t->value = t->interval;
__osInsertTimer(t);
}
}
}
}
//
void __osSetTimerIntr(OSTime tim)
{
OSTime NewTime;
u32 savedMask;
savedMask = __osDisableInt();
__osTimerCounter = osGetCount();
NewTime = tim + __osTimerCounter;
__osSetCompare(NewTime);
__osRestoreInt(savedMask);
}
OSTime __osInsertTimer(OSTimer *t)
{
OSTimer *timep;
OSTime tim;
u32 savedMask;
savedMask = __osDisableInt();
for (timep = __osTimerList->next, tim = t->value;
timep != __osTimerList && tim > timep->value;
tim -= timep->value, timep = timep->next)
{
;
}
t->value = tim;
if (timep != __osTimerList)
timep->value -= tim;
t->next = timep;
t->prev = timep->prev;
timep->prev->next = t;
timep->prev = t;
__osRestoreInt(savedMask);
return tim;
}

View File

@@ -0,0 +1,19 @@
#include <os_internal.h>
#include <R4300.h>
#include "osint.h"
u32 osVirtualToPhysical(void *addr)
{
if (IS_KSEG0(addr))
{
return K0_TO_PHYS(addr);
}
else if (IS_KSEG1(addr))
{
return K1_TO_PHYS(addr);
}
else
{
return __osProbeTLB(addr);
}
}

View File

@@ -0,0 +1,9 @@
#include <ultra64.h>
#include "osint.h"
void osYieldThread(void){
register u32 saveMask = __osDisableInt();
__osRunningThread->state = OS_STATE_RUNNABLE;
__osEnqueueAndYield(&__osRunQueue);
__osRestoreInt(saveMask);
}