2020-08-22 22:30:12 -04:00
|
|
|
#include "iop.h"
|
2022-06-22 23:37:46 -04:00
|
|
|
|
|
|
|
#include <cstring>
|
|
|
|
|
2022-02-08 19:02:47 -05:00
|
|
|
#include "common/util/Assert.h"
|
2020-08-22 22:30:12 -04:00
|
|
|
|
2022-06-22 23:37:46 -04:00
|
|
|
#include "game/system/iop_thread.h"
|
|
|
|
|
2020-08-22 22:30:12 -04:00
|
|
|
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) {
|
2022-02-08 19:02:47 -05:00
|
|
|
ASSERT(mode == 0);
|
2020-08-22 22:30:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Flush Data Cache
|
|
|
|
*/
|
|
|
|
void FlushDcache() {
|
2020-08-26 01:21:33 -04:00
|
|
|
// Do nothing! The data cache does not need to be flushed on x86 as we have no DMA which bypasses
|
|
|
|
// cache.
|
2020-08-22 22:30:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Enable CPU Interrupts
|
|
|
|
*/
|
2020-08-26 01:21:33 -04:00
|
|
|
void CpuDisableIntr() {}
|
2020-08-22 22:30:12 -04:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* Disable CPU Interrupts
|
|
|
|
*/
|
2020-08-26 01:21:33 -04:00
|
|
|
void CpuEnableIntr() {}
|
2020-08-22 22:30:12 -04:00
|
|
|
|
|
|
|
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() {
|
2020-08-26 01:21:33 -04:00
|
|
|
// 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.
|
2020-08-22 22:30:12 -04:00
|
|
|
return 0x100000;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
2020-08-26 01:21:33 -04:00
|
|
|
* Allocate memory.
|
|
|
|
*/
|
|
|
|
void* AllocSysMemory(int type, unsigned long size, void* addr) {
|
2022-02-08 19:02:47 -05:00
|
|
|
ASSERT(type == SMEM_Low);
|
|
|
|
ASSERT(addr == nullptr);
|
2020-08-22 22:30:12 -04:00
|
|
|
return iop->iop_alloc(size);
|
|
|
|
}
|
|
|
|
|
2023-04-29 16:13:57 -04:00
|
|
|
/*!
|
|
|
|
* 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);
|
|
|
|
}
|
|
|
|
|
2020-08-22 22:30:12 -04:00
|
|
|
/*!
|
|
|
|
* Create a new thread
|
|
|
|
*/
|
|
|
|
s32 CreateThread(ThreadParam* param) {
|
2022-07-26 21:15:37 -04:00
|
|
|
return iop->kernel.CreateThread(param->name, (void (*)())param->entry, param->initPriority);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Exit current thread
|
|
|
|
*/
|
|
|
|
s32 ExitThread() {
|
|
|
|
return iop->kernel.ExitThread();
|
2020-08-22 22:30:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Create a new message box.
|
|
|
|
*/
|
|
|
|
s32 CreateMbx(MbxParam* param) {
|
|
|
|
(void)param;
|
|
|
|
return iop->kernel.CreateMbx();
|
|
|
|
}
|
|
|
|
|
|
|
|
s32 StartThread(s32 thid, u32 arg) {
|
2022-02-08 19:02:47 -05:00
|
|
|
ASSERT(!arg);
|
2020-08-22 22:30:12 -04:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2020-08-26 01:21:33 -04:00
|
|
|
void sceSifRegisterRpc(sceSifServeData* serve,
|
|
|
|
unsigned int request,
|
|
|
|
sceSifRpcFunc func,
|
|
|
|
void* buff,
|
2024-04-05 00:07:39 -04:00
|
|
|
int buff_size,
|
2020-08-26 01:21:33 -04:00
|
|
|
sceSifRpcFunc cfunc,
|
|
|
|
void* cbuff,
|
|
|
|
sceSifQueueData* qd) {
|
2020-08-22 22:30:12 -04:00
|
|
|
serve->command = request;
|
|
|
|
serve->func = func;
|
|
|
|
serve->buff = buff;
|
2024-04-05 00:07:39 -04:00
|
|
|
serve->buff_size = buff_size;
|
2020-08-22 22:30:12 -04:00
|
|
|
(void)cfunc;
|
|
|
|
(void)cbuff;
|
2022-02-08 19:02:47 -05:00
|
|
|
ASSERT(!cfunc);
|
|
|
|
ASSERT(!cbuff);
|
2020-08-22 22:30:12 -04:00
|
|
|
qd->serve_data = serve;
|
|
|
|
}
|
|
|
|
|
|
|
|
void sceSifRpcLoop(sceSifQueueData* pd) {
|
|
|
|
iop->kernel.rpc_loop(pd);
|
|
|
|
}
|
|
|
|
|
|
|
|
int sceCdSync(int mode) {
|
|
|
|
(void)mode;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int sceCdGetError() {
|
2020-08-26 01:21:33 -04:00
|
|
|
return 0; // no error
|
2020-08-22 22:30:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int sceCdGetDiskType() {
|
2020-08-26 01:21:33 -04:00
|
|
|
return SCECdPS2DVD; // always a DVD (for now)
|
2020-08-22 22:30:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int sceCdMmode(int media) {
|
|
|
|
(void)media;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DelayThread(u32 usec) {
|
2022-07-26 21:15:37 -04:00
|
|
|
iop->kernel.DelayThread(usec);
|
2020-08-22 22:30:12 -04:00
|
|
|
}
|
|
|
|
|
2024-07-26 09:42:28 -04:00
|
|
|
void YieldThread() {
|
|
|
|
iop->kernel.YieldThread();
|
|
|
|
}
|
|
|
|
|
2020-08-22 22:30:12 -04:00
|
|
|
int sceCdBreak() {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int sceCdDiskReady(int mode) {
|
|
|
|
(void)mode;
|
|
|
|
return SCECdComplete;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 sceSifSetDma(sceSifDmaData* sdd, int len) {
|
2022-02-08 19:02:47 -05:00
|
|
|
ASSERT(len == 1);
|
|
|
|
ASSERT(len <= 0xc000);
|
2020-08-22 22:30:12 -04:00
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
|
2024-07-26 09:42:28 -04:00
|
|
|
s32 ReceiveMbx(MsgPacket** recvmsg, int mbxid) {
|
|
|
|
return iop->kernel.ReceiveMbx((void**)recvmsg, mbxid);
|
|
|
|
}
|
|
|
|
|
2023-04-29 16:13:57 -04:00
|
|
|
s32 PeekMbx(s32 mbx) {
|
|
|
|
return iop->kernel.PeekMbx(mbx);
|
|
|
|
}
|
|
|
|
|
2024-07-26 09:42:28 -04:00
|
|
|
s32 MbxSize(s32 mbx) {
|
|
|
|
return iop->kernel.MbxSize(mbx);
|
|
|
|
}
|
2020-08-22 22:30:12 -04:00
|
|
|
|
2024-07-26 09:42:28 -04:00
|
|
|
u32 GetSystemTimeLow() {
|
|
|
|
return iop->kernel.GetSystemTimeLow();
|
2020-08-22 22:30:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void SleepThread() {
|
|
|
|
iop->kernel.SleepThread();
|
|
|
|
}
|
|
|
|
|
|
|
|
s32 CreateSema(SemaParam* param) {
|
2024-07-26 09:42:28 -04:00
|
|
|
return iop->kernel.CreateSema(param->attr, param->option, param->init_count, param->max_count);
|
2020-08-22 22:30:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
s32 WaitSema(s32 sema) {
|
2022-08-14 13:51:00 -04:00
|
|
|
return iop->kernel.WaitSema(sema);
|
2020-08-22 22:30:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
s32 SignalSema(s32 sema) {
|
2022-08-14 13:51:00 -04:00
|
|
|
return iop->kernel.SignalSema(sema);
|
|
|
|
}
|
|
|
|
|
|
|
|
s32 PollSema(s32 sema) {
|
|
|
|
return iop->kernel.PollSema(sema);
|
2020-08-22 22:30:12 -04:00
|
|
|
}
|
|
|
|
|
2024-07-26 09:42:28 -04:00
|
|
|
s32 CreateEventFlag(const EventFlagParam* param) {
|
|
|
|
return iop->kernel.CreateEventFlag(param->attr, param->option, param->init_pattern);
|
|
|
|
}
|
|
|
|
|
|
|
|
s32 ClearEventFlag(s32 flag, u32 pattern) {
|
|
|
|
return iop->kernel.ClearEventFlag(flag, pattern);
|
|
|
|
}
|
|
|
|
|
|
|
|
s32 WaitEventFlag(s32 flag, u32 pattern, u32 mode) {
|
|
|
|
return iop->kernel.WaitEventFlag(flag, pattern, mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
s32 SetEventFlag(s32 flag, u32 pattern) {
|
|
|
|
return iop->kernel.SetEventFlag(flag, pattern);
|
|
|
|
}
|
|
|
|
|
2020-08-22 22:30:12 -04:00
|
|
|
s32 WakeupThread(s32 thid) {
|
|
|
|
iop->kernel.WakeupThread(thid);
|
|
|
|
return 0;
|
|
|
|
}
|
2022-08-14 17:21:02 -04:00
|
|
|
|
2023-04-29 16:13:57 -04:00
|
|
|
s32 iWakeupThread(s32 thid) {
|
|
|
|
iop->kernel.iWakeupThread(thid);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-09-05 20:29:12 -04:00
|
|
|
s32 RegisterVblankHandler(int edge, int priority, int (*handler)(void*), void* /*userdata*/) {
|
2022-08-14 17:21:02 -04:00
|
|
|
(void)edge;
|
|
|
|
(void)priority;
|
|
|
|
return iop->kernel.RegisterVblankHandler(handler);
|
|
|
|
}
|
|
|
|
|
2021-12-09 18:39:40 -05:00
|
|
|
} // namespace iop
|