rpcsx/rpcs3/Emu/SysCalls/lv2/SC_Timer.cpp
Alexandro Sánchez Bach 60261408c2 Merge branch 'master' of https://github.com/AlexAltea/rpcs3
NOTE: I included some changes of the forks of O1L and Dante38490 to my
fork. However, a conflict appeared while merging their sources with the
ones of DH. I had to resolve this conflict manually and push all the
changes like a new commit, that's why there changes weren't recorded
individually and (probably) won't appear at in the commits list. I am
very sorry for this, I'll try to avoid this in the future.

In order to preserve the authors of those commits, I write this list
here:
O1L: Dummy Modules (cellAudio, cellSaveData, and more)

23ece01a0b

784fc571b3

Dante38490: Spotted and fixed an issue in git-version-gen.cmd

44e8867125

Regarding my changes:
* New lv2 SysCalls implemented (and others improved)
* SDATA unpacker implemented
* Changed layout of sc_table
2013-11-09 02:05:58 +01:00

110 lines
3.1 KiB
C++

#include "stdafx.h"
#include "SC_Timer.h"
#include "Emu/SysCalls/SysCalls.h"
#include "Emu/event.h"
SysCallBase sys_timer("sys_timer");
int sys_timer_create(mem32_t timer_id)
{
sys_timer.Warning("sys_timer_create(timer_id_addr=0x%x)", timer_id.GetAddr());
if(!Memory.IsGoodAddr(timer_id.GetAddr())) return CELL_EFAULT;
timer_id = sys_timer.GetNewId(new timer);
return CELL_OK;
}
int sys_timer_destroy(u32 timer_id)
{
sys_timer.Warning("TODO: sys_timer_destroy(timer_id=%d)", timer_id);
if(!sys_timer.CheckId(timer_id)) return CELL_ESRCH;
Emu.GetIdManager().RemoveID(timer_id);
return CELL_OK;
}
int sys_timer_get_information(u32 timer_id, mem_struct_ptr_t<sys_timer_information_t> info)
{
sys_timer.Warning("sys_timer_get_information(timer_id=%d, info_addr=0x%x)", timer_id, info.GetAddr());
timer* timer_data = nullptr;
if(!sys_timer.CheckId(timer_id, timer_data)) return CELL_ESRCH;
info = timer_data->timer_information_t;
return CELL_OK;
}
int sys_timer_start(u32 timer_id, s64 base_time, u64 period)
{
sys_timer.Warning("sys_timer_start_periodic_absolute(timer_id=%d, basetime=%lld, period=%llu)", timer_id, base_time, period);
timer* timer_data = nullptr;
if(!sys_timer.CheckId(timer_id, timer_data)) return CELL_ESRCH;
if(timer_data->timer_information_t.timer_state != SYS_TIMER_STATE_STOP) return CELL_EBUSY;
if(period < 100) return CELL_EINVAL;
//TODO: if (timer is not connected to an event queue) return CELL_ENOTCONN;
timer_data->timer_information_t.next_expiration_time = base_time;
timer_data->timer_information_t.period = period;
timer_data->timer_information_t.timer_state = SYS_TIMER_STATE_RUN;
//TODO: ?
timer_data->tmr.Start();
return CELL_OK;
}
int sys_timer_stop(u32 timer_id)
{
sys_timer.Warning("TODO: sys_timer_stop()");
timer* timer_data = nullptr;
if(!sys_timer.CheckId(timer_id, timer_data)) return CELL_ESRCH;
timer_data->timer_information_t.timer_state = SYS_TIMER_STATE_STOP;
timer_data->tmr.Stop();
return CELL_OK;
}
int sys_timer_connect_event_queue(u32 timer_id, u32 queue_id, u64 name, u64 data1, u64 data2)
{
sys_timer.Warning("sys_timer_connect_event_queue(timer_id=%d, queue_id=%d, name=%llu, data1=%llu, data2=%llu)",
timer_id, queue_id, name, data1, data2);
timer* timer_data = nullptr;
EventQueue* equeue = nullptr;
if(!sys_timer.CheckId(timer_id, timer_data)) return CELL_ESRCH;
if(!sys_timer.CheckId(queue_id, equeue)) return CELL_ESRCH;
//TODO: ?
return CELL_OK;
}
int sys_timer_disconnect_event_queue(u32 timer_id)
{
sys_timer.Warning("TODO: sys_timer_disconnect_event_queue(timer_id=%d)", timer_id);
timer* timer_data = nullptr;
if(!sys_timer.CheckId(timer_id, timer_data)) return CELL_ESRCH;
//TODO: ?
return CELL_OK;
}
int sys_timer_sleep(u32 sleep_time)
{
sys_timer.Warning("sys_timer_sleep(sleep_time=%d)", sleep_time);
wxSleep(sleep_time);
return CELL_OK;
}
int sys_timer_usleep(u64 sleep_time)
{
sys_timer.Warning("sys_timer_usleep(sleep_time=%lld)", sleep_time);
if (sleep_time > 0xFFFFFFFFFFFF) sleep_time = 0xFFFFFFFFFFFF; //2^48-1
wxMicroSleep(sleep_time); //TODO: If (sleep_time >= 2^32) shit may happen
return CELL_OK;
}