1 #ifndef _window__hpp__included__
2 #define _window__hpp__included__
4 #include "core/keymapper.hpp"
5 #include "library/messagebuffer.hpp"
6 #include "library/emustatus.hpp"
7 #include "library/framebuffer.hpp"
13 class emulator_status
;
21 * Hold mutex RAII-style.
25 holder(mutex
& m
) throw();
31 * Create a mutex. The returned mutex can be deleted using delete.
33 static mutex
& aquire() throw(std::bad_alloc
);
35 * Create a recursive mutex. The returned mutex can be deleted using delete.
37 static mutex
& aquire_rec() throw(std::bad_alloc
);
41 virtual ~mutex() throw();
45 virtual void lock() throw() = 0;
49 virtual void unlock() throw() = 0;
60 * Create a condition variable. The returned condition can be freed using delete.
62 static condition
& aquire(mutex
& m
) throw(std::bad_alloc
);
64 * Destroy a condition.
66 virtual ~condition() throw();
68 * Return associated mutex.
70 mutex
& associated() throw();
72 * Wait for condition. The associate mutex must be locked.
74 virtual bool wait(uint64_t max_usec
) throw() = 0;
76 * Signal a condition. The associated mutex should be locked.
78 virtual void signal() throw() = 0;
90 * Return thread id for this thread. Can be freed with delete.
92 static thread_id
& me() throw(std::bad_alloc
);
96 virtual ~thread_id() throw();
100 virtual bool is_me() throw() = 0;
111 * Create a thread, jumping to specified starting point.
113 static thread
& create(void* (*entrypoint
)(void* arg
), void* arg
) throw(std::bad_alloc
, std::runtime_error
);
115 * Destroy a thread, first joining it (if not already joined).
117 virtual ~thread() throw();
119 * Is this thread still alive?
121 bool is_alive() throw();
125 void* join() throw();
129 * Notify that this thread has quit.
131 void notify_quit(void* retval
) throw();
135 virtual void _join() throw() = 0;
143 * Information about keypress.
148 * Create null keypress (no modifiers, NULL key and released).
152 * Create new keypress.
154 keypress(keyboard_modifier_set mod
, keyboard_key
& _key
, short _value
);
156 * Create new keypress (two keys).
158 keypress(keyboard_modifier_set mod
, keyboard_key
& _key
, keyboard_key
& _key2
, short _value
);
162 keyboard_modifier_set modifiers
;
164 * The actual key (first)
168 * The actual key (second)
172 * Value for the press
178 * Functions implemented by the graphics plugin.
180 * Unless explicitly noted otherwise, all the methods are to be called from emulation thread if that exists, otherwise
181 * from the main thread.
183 struct graphics_plugin
186 * Graphics initialization function.
188 * - The first initialization function to be called by platform::init().
190 static void init() throw();
192 * Graphics quit function.
194 * - The last quit function to be called by platform::quit().
196 static void quit() throw();
198 * Notification when messages get updated.
200 static void notify_message() throw();
202 * Notification when status gets updated.
204 static void notify_status() throw();
206 * Notification when main screen gets updated.
208 static void notify_screen() throw();
210 * Show modal message dialog.
212 * Parameter text: The text for dialog.
213 * Parameter confirm: If true, display confirmation dialog, if false, display notification dialog.
214 * Returns: True if confirmation dialog was confirmed, otherwise false.
216 static bool modal_message(const std::string
& text
, bool confirm
= false) throw();
218 * Displays fatal error message.
220 * - After this routine returns, the program will quit.
221 * - The call can occur in any thread.
223 static void fatal_error() throw();
225 * Identification for graphics plugin.
227 static const char* name
;
231 * Functions implemented by the joystick plugin.
233 * Unless explicitly noted otherwise, all the methods are to be called from emulation thread if that exists, otherwise
234 * from the main thread.
236 struct joystick_plugin
239 * Joystick initialization function.
241 * - The third initialization function to be called by window_init().
242 * - The call occurs in the main thread.
243 * - Implemented by the joystick plugin.
245 static void init() throw();
247 * Joystick quit function.
249 * - The third last quit function to be called by window_quit().
250 * - The call occurs in the main thread.
251 * - Implemented by the joystick plugin.
253 static void quit() throw();
255 * This thread becomes the joystick polling thread.
257 * - Called in joystick polling thread.
259 static void thread_fn() throw();
261 * Signal the joystick thread to quit.
263 static void signal() throw();
265 * Identification for joystick plugin.
267 static const char* name
;
271 * Platform-specific-related functions.
276 * Initialize the system.
281 * Shut down the system.
285 * Get output stream printing into message queue.
287 * Note that lines printed there should be terminated by '\n'.
289 * Implemented by the generic window code.
291 * returns: The output stream.
292 * throws std::bad_alloc: Not enough memory.
294 static std::ostream
& out() throw(std::bad_alloc
);
296 * Get emulator status area
298 * returns: Emulator status area.
300 static emulator_status
& get_emustatus() throw();
304 static messagebuffer msgbuf
;
306 * Get message buffer lock.
308 static mutex
& msgbuf_lock() throw();
310 * Set palette used on screen.
312 static void screen_set_palette(unsigned rshift
, unsigned gshift
, unsigned bshift
) throw();
314 * Adds a messages to mesage queue to be shown.
316 * Implemented by the generic window code.
318 * parameter msg: The messages to add (split by '\n').
319 * throws std::bad_alloc: Not enough memory.
321 static void message(const std::string
& msg
) throw(std::bad_alloc
);
324 * Displays fatal error message, quitting after the user acks it (called by fatal_error()).
326 * Needs to be implemented by the graphics plugin.
328 static void fatal_error() throw();
330 * Enable or disable sound.
332 * Implemented by the generic window code.
334 * parameter enable: Enable sounds if true, otherwise disable sounds.
336 static void sound_enable(bool enable
) throw();
338 * Are sounds enabled?
340 static bool is_sound_enabled() throw();
344 static void set_sound_device(const std::string
& dev
) throw();
346 * Show modal message dialog.
348 * Parameter text: The text for dialog.
349 * Parameter confirm: If true, display confirmation dialog, if false, display notification dialog.
350 * Returns: True, if confirmation dialog was confirmed, otherwise false.
352 static bool modal_message(const std::string
& text
, bool confirm
= false) throw()
354 return graphics_plugin::modal_message(text
, confirm
);
357 * Process command and keypress queues.
359 * - If emulating normally, this routine returns fast.
360 * - If emulator is in pause mode, this routine will block until emulator has left pause mode.
361 * - If emulator is in some special mode, this routine can block until said mode is left.
363 static void flush_command_queue() throw();
365 * Enable/Disable pause mode.
367 * - This function doesn't actually block. For actual paused blocking, use flush_command_queue().
369 * Parameter enable: Enable pause mode if true, disable pause mode if false.
371 static void set_paused(bool enable
) throw();
373 * Wait specified number of milliseconds before returning.
375 * - The command and keypresses queues are processed while waiting.
377 * Parameter usec: The number of microseconds to wait.
379 static void wait(uint64_t usec
) throw();
381 * Cause call to wait() to return immediately.
383 static void cancel_wait() throw();
385 * Notify received message.
387 static void notify_message() throw()
389 graphics_plugin::notify_message();
392 * Notify changed status.
394 static void notify_status() throw()
396 graphics_plugin::notify_status();
399 * Notify changed screen.
401 static void notify_screen() throw()
403 graphics_plugin::notify_screen();
406 * Set modal pause mode.
408 * - Modal pause works like ordinary pause, except it uses a separate flag.
410 * Parameter enable: If true, enable modal pause, else disable it.
412 static void set_modal_pause(bool enable
) throw();
416 * - Can be called from any thread.
418 * Parameter k: The keypress to queue.
420 static void queue(const keypress
& k
) throw(std::bad_alloc
);
424 * - Can be called from any thread.
426 * Parameter c: The command to queue.
428 static void queue(const std::string
& c
) throw(std::bad_alloc
);
430 * Queue function to be called in emulation thread.
432 * - Can be called from any thread (exception: Synchronous mode can not be used from emulation nor main threads).
434 * Parameter f: The function to execute.
435 * Parameter arg: Argument to pass to the function.
436 * Parameter sync: If true, execute function call synchronously, else asynchronously.
438 static void queue(void (*f
)(void* arg
), void* arg
, bool sync
) throw(std::bad_alloc
);
442 static void run_queues() throw();
444 static bool pausing_allowed
;
445 static double global_volume
;
446 static volatile bool do_exit_dummy_event_loop
;
447 static void dummy_event_loop() throw();
448 static void exit_dummy_event_loop() throw();
451 class modal_pause_holder
454 modal_pause_holder();
455 ~modal_pause_holder();
457 modal_pause_holder(const modal_pause_holder
&);
458 modal_pause_holder
& operator=(const modal_pause_holder
&);
462 void functor_call_helper(void* args
)
464 (*reinterpret_cast<T
*>(args
))();
470 platform::queue(functor_call_helper
<T
>, &fn
, true);
474 * If set, queueing synchronous function produces a warning.
476 extern volatile bool queue_synchronous_fn_warning
;