mirror of
https://github.com/dgis/emu48android
synced 2024-12-26 09:58:49 +01:00
This commit is contained in:
parent
c6d1648cd7
commit
0ad9b3b54c
3 changed files with 92 additions and 21 deletions
|
@ -2154,8 +2154,12 @@ BOOL emu48Start()
|
|||
hWindowDC = CreateCompatibleDC(NULL);
|
||||
|
||||
// initialization
|
||||
LARGE_INTEGER lAppStart2; // high performance counter value at Appl. start
|
||||
|
||||
QueryPerformanceFrequency(&lFreq); // init high resolution counter
|
||||
QueryPerformanceCounter(&lAppStart);
|
||||
Sleep(1000);
|
||||
QueryPerformanceCounter(&lAppStart2);
|
||||
|
||||
szCurrentKml[0] = 0; // no KML file selected
|
||||
SetSpeed(bRealSpeed); // set speed
|
||||
|
|
|
@ -9,18 +9,28 @@
|
|||
|
||||
#include "pch.h"
|
||||
|
||||
JavaVM *java_machine;
|
||||
JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved) {
|
||||
java_machine = vm;
|
||||
return JNI_VERSION_1_6;
|
||||
}
|
||||
|
||||
extern void emu48Start();
|
||||
extern AAssetManager * assetManager;
|
||||
static jobject viewToUpdate = NULL;
|
||||
jobject bitmapMainScreen;
|
||||
AndroidBitmapInfo androidBitmapInfo;
|
||||
|
||||
extern void win32Init();
|
||||
|
||||
extern void draw();
|
||||
extern void buttonDown(int x, int y);
|
||||
extern void buttonUp(int x, int y);
|
||||
extern void keyDown(int virtKey);
|
||||
extern void keyUp(int virtKey);
|
||||
|
||||
|
||||
JavaVM *java_machine;
|
||||
JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved) {
|
||||
java_machine = vm;
|
||||
win32Init();
|
||||
return JNI_VERSION_1_6;
|
||||
}
|
||||
|
||||
// https://stackoverflow.com/questions/9630134/jni-how-to-callback-from-c-or-c-to-java
|
||||
void mainViewUpdateCallback() {
|
||||
if (viewToUpdate) {
|
||||
|
@ -76,12 +86,6 @@ JNIEXPORT void JNICALL Java_com_regis_cosnier_emu48_NativeLib_resize(JNIEnv *env
|
|||
|
||||
}
|
||||
|
||||
extern void draw();
|
||||
extern void buttonDown(int x, int y);
|
||||
extern void buttonUp(int x, int y);
|
||||
extern void keyDown(int virtKey);
|
||||
extern void keyUp(int virtKey);
|
||||
|
||||
JNIEXPORT void JNICALL Java_com_regis_cosnier_emu48_NativeLib_draw(JNIEnv *env, jobject thisz) {
|
||||
draw();
|
||||
}
|
||||
|
|
|
@ -472,9 +472,11 @@ BOOL WINAPI CloseHandle(HANDLE hObject) {
|
|||
|
||||
void Sleep(int ms)
|
||||
{
|
||||
time_t seconds = ms / 1000;
|
||||
long milliseconds = ms - 1000 * seconds;
|
||||
struct timespec timeOut, remains;
|
||||
timeOut.tv_sec = 0;
|
||||
timeOut.tv_nsec = ms * 1000000; /* 50 milliseconds */
|
||||
timeOut.tv_sec = seconds;
|
||||
timeOut.tv_nsec = milliseconds * 1000000; /* 50 milliseconds */
|
||||
nanosleep(&timeOut, &remains);
|
||||
}
|
||||
|
||||
|
@ -495,7 +497,7 @@ BOOL QueryPerformanceCounter(PLARGE_INTEGER l)
|
|||
long tv_nsec; /* nanoseconds */
|
||||
} time;
|
||||
int result = clock_gettime(CLOCK_MONOTONIC, &time);
|
||||
l->QuadPart = 1e9 * time.tv_sec + time.tv_nsec;
|
||||
l->QuadPart = (1e9 * time.tv_sec + time.tv_nsec) / 1000;
|
||||
return TRUE;
|
||||
}
|
||||
void EnterCriticalSection(CRITICAL_SECTION *lock)
|
||||
|
@ -970,16 +972,77 @@ HANDLE WINAPI GetClipboardData(UINT uFormat) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
struct timerEvent {
|
||||
BOOL valid;
|
||||
int timerId;
|
||||
LPTIMECALLBACK fptc;
|
||||
DWORD_PTR dwUser;
|
||||
timer_t timer;
|
||||
};
|
||||
|
||||
#define MAX_TIMER 10
|
||||
struct timerEvent timerEvents[MAX_TIMER];
|
||||
|
||||
void win32Init() {
|
||||
for (int i = 0; i < MAX_TIMER; ++i) {
|
||||
timerEvents[i].valid = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
void timerCallback(int timerId) {
|
||||
if(timerId >= 0 && timerId < MAX_TIMER && timerEvents[timerId].valid) {
|
||||
timerEvents[timerId].fptc(timerId + 1, 0, timerEvents[timerId].dwUser, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
MMRESULT timeSetEvent(UINT uDelay, UINT uResolution, LPTIMECALLBACK fptc, DWORD_PTR dwUser, UINT fuEvent) {
|
||||
//TODO
|
||||
return 0; //No error
|
||||
|
||||
// Find a timer id
|
||||
int timerId = -1;
|
||||
for (int i = 0; i < MAX_TIMER; ++i) {
|
||||
if(!timerEvents[i].valid) {
|
||||
timerId = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
timerEvents[timerId].timerId = timerId;
|
||||
timerEvents[timerId].fptc = fptc;
|
||||
timerEvents[timerId].dwUser = dwUser;
|
||||
|
||||
|
||||
struct sigevent sev;
|
||||
sev.sigev_notify = SIGEV_THREAD;
|
||||
sev.sigev_notify_function = timerCallback; //this function will be called when timer expires
|
||||
sev.sigev_value.sival_int = timerEvents[timerId].timerId;//this argument will be passed to cbf
|
||||
sev.sigev_notify_attributes = NULL;
|
||||
timer_t * timer = &(timerEvents[timerId].timer);
|
||||
//if (timer_create(CLOCK_REALTIME, &sev, &timer) == -1)
|
||||
if (timer_create(CLOCK_REALTIME, &sev, timer) == -1)
|
||||
return NULL;
|
||||
|
||||
long long freq_nanosecs = uDelay * 1000000;
|
||||
struct itimerspec its;
|
||||
its.it_value.tv_sec = freq_nanosecs / 1000000000;
|
||||
its.it_value.tv_nsec = freq_nanosecs % 1000000000;
|
||||
its.it_interval.tv_sec = its.it_value.tv_sec;
|
||||
its.it_interval.tv_nsec = its.it_value.tv_nsec;
|
||||
if (timer_settime(timerEvents[timerId].timer, 0, &its, NULL) == -1) {
|
||||
timer_delete(timerEvents[timerId].timer);
|
||||
return NULL;
|
||||
}
|
||||
timerEvents[timerId].valid = TRUE;
|
||||
return timerId + 1; //No error
|
||||
}
|
||||
MMRESULT timeKillEvent(UINT uTimerID) {
|
||||
//TODO
|
||||
timer_delete(timerEvents[uTimerID - 1].timer);
|
||||
timerEvents[uTimerID - 1].valid = FALSE;
|
||||
return 0; //No error
|
||||
}
|
||||
MMRESULT timeGetDevCaps(LPTIMECAPS ptc, UINT cbtc) {
|
||||
//TODO
|
||||
if(ptc) {
|
||||
ptc->wPeriodMin = 1; // ms
|
||||
ptc->wPeriodMax = 1000000; // ms -> 1000s
|
||||
}
|
||||
return 0; //No error
|
||||
}
|
||||
MMRESULT timeBeginPeriod(UINT uPeriod) {
|
||||
|
|
Loading…
Reference in a new issue