aboutsummaryrefslogtreecommitdiff
path: root/backends/platform/PalmOS/Src/be_os5ex.cpp
blob: 1a5ea2bf78f45f4f48b29689f3908768d567b965 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * $URL$
 * $Id$
 *
 */

// for DAL.h
#define ALLOW_ACCESS_TO_INTERNALS_OF_BITMAPS

#include "be_os5ex.h"
#include "palmdefs.h"

#include <System/WIP.h>
#include <System/DAL.h>

static TimerExType _timerEx;

OSystem_PalmOS5Ex::OSystem_PalmOS5Ex() : OSystem_PalmOS5() {
	_timerEx.timerID = 0;
	_timerEx.timer = &_timer;
	_timerEx.ticks = SysTicksPerSecond();
}

static SYSTEM_CALLBACK void timer_handler(void *userDataP) {
	CALLBACK_PROLOGUE
	TimerExPtr _timerEx = (TimerExPtr)userDataP;
	TimerPtr _timer = _timerEx->timer;
	_timer->duration = _timer->callback(_timer->duration);
	KALTimerSet(_timerEx->timerID, (_timer->duration * _timerEx->ticks / 1000));
	CALLBACK_EPILOGUE
}

void OSystem_PalmOS5Ex::setTimerCallback(TimerProc callback, int timer) {
	if (_timer.active && _timerEx.timerID)
		KALTimerDelete(_timerEx.timerID);

	if (callback != NULL) {
		Err e;
		CALLBACK_INIT(_timerEx);
		_timer.duration = timer;
		_timer.callback = callback;

		// create the timer
		e = KALTimerCreate(&_timerEx.timerID, appFileCreator, &::timer_handler, &_timerEx);
		if (!e) {
			e = KALTimerSet(_timerEx.timerID, (timer * _timerEx.ticks / 1000));
			if (e) KALTimerDelete(_timerEx.timerID);
		}
		_timer.active = (!e);

	} else {
		_timer.active = false;
	}
	
	if (!_timer.active)
		_timerEx.timerID = 0;
}

OSystem::MutexRef OSystem_PalmOS5Ex::createMutex() {
	UInt32 mutexID;
	Err e = KALMutexCreate(&mutexID, appFileCreator);
	return (MutexRef)(e ? NULL : mutexID);

}

void OSystem_PalmOS5Ex::lockMutex(MutexRef mutex) {
	if (mutex)
		KALMutexReserve((UInt32)mutex);
}

void OSystem_PalmOS5Ex::unlockMutex(MutexRef mutex) {
	if (mutex)
		KALMutexRelease((UInt32)mutex, 0);
}

void OSystem_PalmOS5Ex::deleteMutex(MutexRef mutex) {
	if (mutex)
		KALMutexDelete((UInt32)mutex);
}

void OSystem_PalmOS5Ex::int_quit() {
	if (_timerEx.timerID)
		KALTimerDelete(_timerEx.timerID);
}