mirror of
https://github.com/siemens-mobile-hacks/elfloader3-linux.git
synced 2026-11-25 23:57:20 +00:00
fix timers
This commit is contained in:
parent
8aa90f4972
commit
ff5af75862
3 changed files with 24 additions and 8 deletions
|
|
@ -214,7 +214,7 @@ void loader_init_switab() {
|
|||
switab_functions[0x004D] = (void *) GBS_StartTimerProc;
|
||||
switab_functions[0x0143] = (void *) GBS_StartTimer;
|
||||
switab_functions[0x0144] = (void *) GBS_StopTimer;
|
||||
switab_functions[0x01A6] = (void *) GBS_IsTimerRunning;
|
||||
switab_functions[0x01A6] = (void *) GBS_IsTimerProcessing;
|
||||
switab_functions[0x0105] = (void *) GBS_CreateProc;
|
||||
switab_functions[0x0145] = (void *) GBS_GetCurCepid;
|
||||
switab_functions[0x0154] = (void *) GBS_KillProc;
|
||||
|
|
|
|||
|
|
@ -287,6 +287,9 @@ typedef struct {
|
|||
void *data1;
|
||||
} GBS_MSG;
|
||||
|
||||
#define GBS_TMR_CREATED 0x74696d72
|
||||
#define GBS_TMR_DELETED 0x756e6466
|
||||
|
||||
typedef struct {
|
||||
int param0;
|
||||
int param1;
|
||||
|
|
@ -303,7 +306,7 @@ typedef void (*GbsTimerCallback)(GBSTMR *);
|
|||
void GBS_StartTimerProc(GBSTMR *tmr, long ms, GbsTimerCallback callback);
|
||||
void GBS_StartTimer(GBSTMR *tmr, int ms, int msg, int unk, int cepid);
|
||||
void GBS_StopTimer(GBSTMR *tmr);
|
||||
int GBS_IsTimerRunning(GBSTMR * param1);
|
||||
int GBS_IsTimerProcessing(GBSTMR * param1);
|
||||
void GBS_RunInContext(int cepid, std::function<void()> callback);
|
||||
void GBS_CreateProc(int cepid, const char *name, GbsProcCallback on_msg, int prio, int unk_zero);
|
||||
int GBS_GetCurCepid(void);
|
||||
|
|
|
|||
|
|
@ -50,6 +50,8 @@ void GBS_StartTimerProc(GBSTMR *tmr, long ticks, GbsTimerCallback callback) {
|
|||
assert(tmr != nullptr);
|
||||
assert(GBS_GetCurCepid() != -1);
|
||||
|
||||
GBS_DelTimer(tmr);
|
||||
|
||||
GbsTimerData *tmr_data = new GbsTimerData;
|
||||
tmr_data->callback = callback;
|
||||
tmr_data->cepid = GBS_GetCurCepid();
|
||||
|
|
@ -61,10 +63,14 @@ void GBS_StartTimerProc(GBSTMR *tmr, long ticks, GbsTimerCallback callback) {
|
|||
}, (ticks * 1000) / 216, false);
|
||||
|
||||
tmr->param0 = reinterpret_cast<int>(tmr_data);
|
||||
tmr->param1 = GBS_TMR_CREATED;
|
||||
}
|
||||
|
||||
void GBS_StartTimer(GBSTMR *tmr, int ticks, int msg, int unk, int cepid) {
|
||||
assert(tmr != nullptr);
|
||||
|
||||
GBS_DelTimer(tmr);
|
||||
|
||||
GbsTimerData *tmr_data = new GbsTimerData;
|
||||
tmr_data->callback = nullptr;
|
||||
tmr_data->cepid = cepid;
|
||||
|
|
@ -76,24 +82,31 @@ void GBS_StartTimer(GBSTMR *tmr, int ticks, int msg, int unk, int cepid) {
|
|||
}, (ticks * 1000) / 216, false);
|
||||
|
||||
tmr->param0 = reinterpret_cast<int>(tmr_data);
|
||||
tmr->param1 = GBS_TMR_CREATED;
|
||||
}
|
||||
|
||||
void GBS_StopTimer(GBSTMR *tmr) {
|
||||
GBS_DelTimer(tmr);
|
||||
if (GBS_IsTimerProcessing(tmr)) {
|
||||
auto *tmr_data = reinterpret_cast<GbsTimerData *>(tmr->param0);
|
||||
if (tmr_data->timer_id != -1) {
|
||||
Loop::instance()->removeTimer(tmr_data->timer_id);
|
||||
tmr_data->timer_id = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int GBS_IsTimerRunning(GBSTMR *tmr) {
|
||||
assert(tmr != nullptr);
|
||||
return tmr->param0 != 0;
|
||||
int GBS_IsTimerProcessing(GBSTMR *tmr) {
|
||||
return tmr->param1 == GBS_TMR_CREATED && tmr->param0 != 0;
|
||||
}
|
||||
|
||||
void GBS_DelTimer(GBSTMR *tmr) {
|
||||
auto *tmr_data = reinterpret_cast<GbsTimerData *>(tmr->param0);
|
||||
if (tmr_data) {
|
||||
if (GBS_IsTimerProcessing(tmr)) {
|
||||
auto *tmr_data = reinterpret_cast<GbsTimerData *>(tmr->param0);
|
||||
if (tmr_data->timer_id != -1)
|
||||
Loop::instance()->removeTimer(tmr_data->timer_id);
|
||||
delete tmr_data;
|
||||
tmr->param0 = 0;
|
||||
tmr->param1 = GBS_TMR_DELETED;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue