32 |
|
* - Force relative mode in Grab mode even if SDL provides absolute coordinates? |
33 |
|
* - Fullscreen mode |
34 |
|
* - Gamma tables support is likely to be broken here |
35 |
+ |
* - Events processing is bound to the general emulation thread as SDL requires |
36 |
+ |
* to PumpEvents() within the same thread as the one that called SetVideoMode(). |
37 |
+ |
* Besides, there can't seem to be a way to call SetVideoMode() from a child thread. |
38 |
|
*/ |
39 |
|
|
40 |
|
#include "sysdeps.h" |
105 |
|
static int screen_depth; // Depth of current screen |
106 |
|
static SDL_Color sdl_palette[256]; // Color palette to be used as CLUT and gamma table |
107 |
|
static bool sdl_palette_changed = false; // Flag: Palette changed, redraw thread must set new colors |
108 |
+ |
static const int sdl_eventmask = SDL_MOUSEBUTTONDOWNMASK | SDL_MOUSEBUTTONUPMASK | SDL_MOUSEMOTIONMASK | SDL_KEYUPMASK | SDL_KEYDOWNMASK | SDL_VIDEOEXPOSEMASK | SDL_QUITMASK; |
109 |
|
|
110 |
|
// Mutex to protect palette |
111 |
|
static SDL_mutex *sdl_palette_lock = NULL; |
608 |
|
|
609 |
|
// Start redraw/input thread |
610 |
|
redraw_thread_cancel = false; |
611 |
< |
redraw_thread_active = (SDL_CreateThread(redraw_func, NULL) != NULL); |
611 |
> |
redraw_thread_active = ((redraw_thread = SDL_CreateThread(redraw_func, NULL)) != NULL); |
612 |
|
if (!redraw_thread_active) { |
613 |
|
printf("FATAL: cannot create redraw thread\n"); |
614 |
|
return false; |
750 |
|
// Stop redraw thread |
751 |
|
if (redraw_thread_active) { |
752 |
|
redraw_thread_cancel = true; |
753 |
< |
// SDL_WaitThread(redraw_thread, NULL); doesn't work |
750 |
< |
while (redraw_thread_cancel); |
753 |
> |
SDL_WaitThread(redraw_thread, NULL); |
754 |
|
} |
755 |
|
redraw_thread_active = false; |
756 |
|
|
802 |
|
|
803 |
|
void VideoInterrupt(void) |
804 |
|
{ |
805 |
+ |
// We must fill in the events queue in the same thread that did call SDL_SetVideoMode() |
806 |
+ |
SDL_PumpEvents(); |
807 |
+ |
|
808 |
|
// Emergency quit requested? Then quit |
809 |
|
if (emerg_quit) |
810 |
|
QuitEmulator(); |
1027 |
|
|
1028 |
|
static void handle_events(void) |
1029 |
|
{ |
1030 |
< |
SDL_Event event; |
1031 |
< |
while (SDL_PollEvent(&event)) { |
1032 |
< |
switch (event.type) { |
1030 |
> |
SDL_Event events[10]; |
1031 |
> |
const int n_max_events = sizeof(events) / sizeof(events[0]); |
1032 |
> |
int n_events; |
1033 |
> |
|
1034 |
> |
while ((n_events = SDL_PeepEvents(events, n_max_events, SDL_GETEVENT, sdl_eventmask)) > 0) { |
1035 |
> |
for (int i = 0; i < n_events; i++) { |
1036 |
> |
SDL_Event const & event = events[i]; |
1037 |
> |
switch (event.type) { |
1038 |
|
|
1039 |
|
// Mouse button |
1040 |
|
case SDL_MOUSEBUTTONDOWN: { |
1134 |
|
ADBKeyDown(0x7f); // Power key |
1135 |
|
ADBKeyUp(0x7f); |
1136 |
|
break; |
1137 |
+ |
} |
1138 |
|
} |
1139 |
|
} |
1140 |
|
} |
1436 |
|
|
1437 |
|
uint64 end = GetTicks_usec(); |
1438 |
|
D(bug("%lld refreshes in %lld usec = %f refreshes/sec\n", ticks, end - start, ticks * 1000000.0 / (end - start))); |
1427 |
– |
redraw_thread_cancel = false; |
1439 |
|
return 0; |
1440 |
|
} |