mirror of
https://github.com/open-goal/jak-project
synced 2026-05-27 08:09:29 -04:00
93afb02cf4
This includes all the collision stuff needed to spawn `target`, decompiles the sparticle code and adds some of the PC hacks needed for merc to run (it doesn't work quite right and looks bad, likely due to a combination of code copied from Jak 2 and the time of day hacks). There are a bunch of temporary hacks (see commits) in place to prevent the game from crashing quite as much, but it is still extremely prone to doing so due to lots of missing functions/potentially bad decomp. --------- Co-authored-by: water <awaterford111445@gmail.com>
251 lines
4.6 KiB
C++
251 lines
4.6 KiB
C++
#include "iop.h"
|
|
|
|
#include <cstring>
|
|
|
|
#include "common/util/Assert.h"
|
|
|
|
#include "game/system/iop_thread.h"
|
|
|
|
namespace iop {
|
|
/*!
|
|
* Is the SIF initialized?
|
|
*/
|
|
u32 sceSifCheckInit() {
|
|
// the SIF is always initialized by the time OVERLORD starts.
|
|
// it would only be on an ancient dev kit where this might not be true.
|
|
return 1;
|
|
}
|
|
|
|
/*!
|
|
* Initialize SIF
|
|
*/
|
|
void sceSifInit() {
|
|
// do nothing!
|
|
}
|
|
|
|
/*!
|
|
* Initialize RPC
|
|
*/
|
|
void sceSifInitRpc(int mode) {
|
|
ASSERT(mode == 0);
|
|
}
|
|
|
|
/*!
|
|
* Flush Data Cache
|
|
*/
|
|
void FlushDcache() {
|
|
// Do nothing! The data cache does not need to be flushed on x86 as we have no DMA which bypasses
|
|
// cache.
|
|
}
|
|
|
|
/*!
|
|
* Enable CPU Interrupts
|
|
*/
|
|
void CpuDisableIntr() {}
|
|
|
|
/*!
|
|
* Disable CPU Interrupts
|
|
*/
|
|
void CpuEnableIntr() {}
|
|
|
|
namespace {
|
|
::IOP* iop;
|
|
}
|
|
|
|
void LIBRARY_INIT() {
|
|
iop = nullptr;
|
|
}
|
|
|
|
void LIBRARY_register(::IOP* i) {
|
|
iop = i;
|
|
}
|
|
|
|
void LIBRARY_kill() {
|
|
iop->kill_from_ee();
|
|
}
|
|
|
|
/*!
|
|
* How much free memory is there, in bytes?
|
|
*/
|
|
int QueryTotalFreeMemSize() {
|
|
// this value is somewhat arbitrary - it's a lot, but not enough to make OVERLORD think it is
|
|
// running on an 8MB-of-IOP-RAM development machine.
|
|
return 0x100000;
|
|
}
|
|
|
|
/*!
|
|
* Allocate memory.
|
|
*/
|
|
void* AllocSysMemory(int type, unsigned long size, void* addr) {
|
|
ASSERT(type == SMEM_Low);
|
|
ASSERT(addr == nullptr);
|
|
return iop->iop_alloc(size);
|
|
}
|
|
|
|
/*!
|
|
* Allocate the 1 kB scratchpad memory. On PS2, this would give you a pointer to the actual
|
|
* scratchpad of the IOP, but this is just normal memory.
|
|
*/
|
|
void* AllocScratchPad(int mode) {
|
|
ASSERT(mode == 0);
|
|
constexpr int kScratchpadSize = 1024 * 16;
|
|
return iop->iop_alloc(kScratchpadSize);
|
|
}
|
|
|
|
/*!
|
|
* Create a new thread
|
|
*/
|
|
s32 CreateThread(ThreadParam* param) {
|
|
return iop->kernel.CreateThread(param->name, (void (*)())param->entry, param->initPriority);
|
|
}
|
|
|
|
/*!
|
|
* Exit current thread
|
|
*/
|
|
s32 ExitThread() {
|
|
return iop->kernel.ExitThread();
|
|
}
|
|
|
|
/*!
|
|
* Create a new message box.
|
|
*/
|
|
s32 CreateMbx(MbxParam* param) {
|
|
(void)param;
|
|
return iop->kernel.CreateMbx();
|
|
}
|
|
|
|
s32 StartThread(s32 thid, u32 arg) {
|
|
ASSERT(!arg);
|
|
iop->kernel.StartThread(thid);
|
|
return 0;
|
|
}
|
|
|
|
int GetThreadId() {
|
|
return iop->kernel.getCurrentThread();
|
|
}
|
|
|
|
void sceSifSetRpcQueue(sceSifQueueData* dq, int key) {
|
|
dq->key = key;
|
|
iop->kernel.set_rpc_queue(dq, key);
|
|
}
|
|
|
|
void sceSifRegisterRpc(sceSifServeData* serve,
|
|
unsigned int request,
|
|
sceSifRpcFunc func,
|
|
void* buff,
|
|
int buff_size,
|
|
sceSifRpcFunc cfunc,
|
|
void* cbuff,
|
|
sceSifQueueData* qd) {
|
|
serve->command = request;
|
|
serve->func = func;
|
|
serve->buff = buff;
|
|
serve->buff_size = buff_size;
|
|
(void)cfunc;
|
|
(void)cbuff;
|
|
ASSERT(!cfunc);
|
|
ASSERT(!cbuff);
|
|
qd->serve_data = serve;
|
|
}
|
|
|
|
void sceSifRpcLoop(sceSifQueueData* pd) {
|
|
iop->kernel.rpc_loop(pd);
|
|
}
|
|
|
|
int sceCdSync(int mode) {
|
|
(void)mode;
|
|
return 0;
|
|
}
|
|
|
|
int sceCdGetError() {
|
|
return 0; // no error
|
|
}
|
|
|
|
int sceCdGetDiskType() {
|
|
return SCECdPS2DVD; // always a DVD (for now)
|
|
}
|
|
|
|
int sceCdMmode(int media) {
|
|
(void)media;
|
|
return 1;
|
|
}
|
|
|
|
void DelayThread(u32 usec) {
|
|
iop->kernel.DelayThread(usec);
|
|
}
|
|
|
|
int sceCdBreak() {
|
|
return 1;
|
|
}
|
|
|
|
int sceCdDiskReady(int mode) {
|
|
(void)mode;
|
|
return SCECdComplete;
|
|
}
|
|
|
|
u32 sceSifSetDma(sceSifDmaData* sdd, int len) {
|
|
ASSERT(len == 1);
|
|
ASSERT(len <= 0xc000);
|
|
// todo - sanity check the destination address.
|
|
memcpy(iop->ee_main_mem + (u64)(sdd->addr), sdd->data, sdd->size);
|
|
return 1;
|
|
}
|
|
|
|
s32 SendMbx(s32 mbxid, void* sendmsg) {
|
|
return iop->kernel.SendMbx(mbxid, sendmsg);
|
|
}
|
|
|
|
s32 PollMbx(MsgPacket** recvmsg, int mbxid) {
|
|
return iop->kernel.PollMbx((void**)recvmsg, mbxid);
|
|
}
|
|
|
|
s32 PeekMbx(s32 mbx) {
|
|
return iop->kernel.PeekMbx(mbx);
|
|
}
|
|
|
|
static int now = 0;
|
|
|
|
void GetSystemTime(SysClock* time) {
|
|
time->lo = 0;
|
|
time->hi = now;
|
|
now += 10;
|
|
}
|
|
|
|
void SleepThread() {
|
|
iop->kernel.SleepThread();
|
|
}
|
|
|
|
s32 CreateSema(SemaParam* param) {
|
|
return iop->kernel.CreateSema(param->attr, param->option, param->max_count, param->init_count);
|
|
}
|
|
|
|
s32 WaitSema(s32 sema) {
|
|
return iop->kernel.WaitSema(sema);
|
|
}
|
|
|
|
s32 SignalSema(s32 sema) {
|
|
return iop->kernel.SignalSema(sema);
|
|
}
|
|
|
|
s32 PollSema(s32 sema) {
|
|
return iop->kernel.PollSema(sema);
|
|
}
|
|
|
|
s32 WakeupThread(s32 thid) {
|
|
iop->kernel.WakeupThread(thid);
|
|
return 0;
|
|
}
|
|
|
|
s32 iWakeupThread(s32 thid) {
|
|
iop->kernel.iWakeupThread(thid);
|
|
return 0;
|
|
}
|
|
|
|
s32 RegisterVblankHandler(int edge, int priority, int (*handler)(void*), void* /*userdata*/) {
|
|
(void)edge;
|
|
(void)priority;
|
|
return iop->kernel.RegisterVblankHandler(handler);
|
|
}
|
|
|
|
} // namespace iop
|