1 #ifndef _window__hpp__included__
2 #define _window__hpp__included__
4 #include "core/rom.hpp"
5 #include "interface/romtype.hpp"
6 #include "library/keyboard.hpp"
7 #include "library/messagebuffer.hpp"
8 #include "library/framebuffer.hpp"
15 * Information about keypress.
20 * Create null keypress (no modifiers, NULL key and released).
24 * Create new keypress.
26 keypress(keyboard::modifier_set mod
, keyboard::key
& _key
, short _value
);
28 * Create new keypress (two keys).
30 keypress(keyboard::modifier_set mod
, keyboard::key
& _key
, keyboard::key
& _key2
, short _value
);
34 keyboard::modifier_set modifiers
;
36 * The actual key (first)
40 * The actual key (second)
53 std::vector
<core_type
*> cores
;
54 //Selected core (default core on call).
57 //Filename selected (on entry, filename hint).
58 bool has_slot
[ROM_SLOT_COUNT
];
59 bool guessed
[ROM_SLOT_COUNT
];
60 std::string filename
[ROM_SLOT_COUNT
];
61 std::string hash
[ROM_SLOT_COUNT
];
62 std::string hashxml
[ROM_SLOT_COUNT
];
68 //Various methods corresponding to graphics_driver_*
69 struct _graphics_driver
73 void (*notify_message
)();
74 void (*notify_status
)();
75 void (*notify_screen
)();
76 void (*error_message
)(const std::string
& text
);
77 void (*fatal_error
)();
78 const char* (*name
)();
79 void (*action_updated
)();
80 void (*request_rom
)(rom_request
& req
);
83 struct graphics_driver
85 graphics_driver(_graphics_driver drv
);
88 //Is dummy graphics plugin.
89 bool graphics_driver_is_dummy();
91 * Graphics initialization function.
93 * - The first initialization function to be called by platform::init().
95 void graphics_driver_init() throw();
97 * Graphics quit function.
99 * - The last quit function to be called by platform::quit().
101 void graphics_driver_quit() throw();
103 * Notification when messages get updated.
105 void graphics_driver_notify_message() throw();
107 * Notification when status gets updated.
109 void graphics_driver_notify_status() throw();
111 * Notification when main screen gets updated.
113 void graphics_driver_notify_screen() throw();
115 * Show error message dialog when UI thread is free.
117 * Parameter text: The text for dialog.
119 void graphics_driver_error_message(const std::string
& text
) throw();
121 * Displays fatal error message.
123 * - After this routine returns, the program will quit.
124 * - The call can occur in any thread.
126 void graphics_driver_fatal_error() throw();
128 * Identification for graphics plugin.
130 const char* graphics_driver_name();
132 * Enable/Disable an action.
134 void graphics_driver_action_updated();
136 * Request a ROM image.
138 void graphics_driver_request_rom(rom_request
& req
);
141 * Platform-specific-related functions.
146 * Initialize the system.
151 * Shut down the system.
155 * Get output stream printing into message queue.
157 * Note that lines printed there should be terminated by '\n'.
159 * Implemented by the generic window code.
161 * returns: The output stream.
162 * throws std::bad_alloc: Not enough memory.
164 static std::ostream
& out() throw(std::bad_alloc
);
168 static messagebuffer msgbuf
;
170 * Get message buffer lock.
172 static threads::lock
& msgbuf_lock() throw();
174 * Adds a messages to mesage queue to be shown.
176 * Implemented by the generic window code.
178 * parameter msg: The messages to add (split by '\n').
179 * throws std::bad_alloc: Not enough memory.
181 static void message(const std::string
& msg
) throw(std::bad_alloc
);
184 * Displays fatal error message, quitting after the user acks it (called by fatal_error()).
186 * Needs to be implemented by the graphics plugin.
188 static void fatal_error() throw();
190 * Enable or disable sound.
192 * Implemented by the generic window code.
194 * parameter enable: Enable sounds if true, otherwise disable sounds.
196 static void sound_enable(bool enable
) throw();
198 * Are sounds enabled?
200 static bool is_sound_enabled() throw();
204 static void set_sound_device(const std::string
& pdev
, const std::string
& rdev
) throw();
206 * Show error message dialog after UI thread becomes free.
208 * Parameter text: The text for dialog.
210 static void error_message(const std::string
& text
) throw()
212 return graphics_driver_error_message(text
);
215 * Process command and keypress queues.
217 * - If emulating normally, this routine returns fast.
218 * - If emulator is in pause mode, this routine will block until emulator has left pause mode.
219 * - If emulator is in some special mode, this routine can block until said mode is left.
221 static void flush_command_queue() throw();
223 * Enable/Disable pause mode.
225 * - This function doesn't actually block. For actual paused blocking, use flush_command_queue().
227 * Parameter enable: Enable pause mode if true, disable pause mode if false.
229 static void set_paused(bool enable
) throw();
231 * Wait specified number of milliseconds before returning.
233 * - The command and keypresses queues are processed while waiting.
235 * Parameter usec: The number of microseconds to wait.
237 static void wait(uint64_t usec
) throw();
239 * Cause call to wait() to return immediately.
241 static void cancel_wait() throw();
243 * Notify received message.
245 static void notify_message() throw()
247 graphics_driver_notify_message();
250 * Notify changed status.
252 static void notify_status() throw()
254 graphics_driver_notify_status();
257 * Notify changed screen.
259 static void notify_screen() throw()
261 graphics_driver_notify_screen();
264 * Set modal pause mode.
266 * - Modal pause works like ordinary pause, except it uses a separate flag.
268 * Parameter enable: If true, enable modal pause, else disable it.
270 static void set_modal_pause(bool enable
) throw();
274 * - Can be called from any thread.
276 * Parameter k: The keypress to queue.
278 static void queue(const keypress
& k
) throw(std::bad_alloc
);
282 * - Can be called from any thread.
284 * Parameter c: The command to queue.
286 static void queue(const std::string
& c
) throw(std::bad_alloc
);
288 * Queue function to be called in emulation thread.
290 * - Can be called from any thread (exception: Synchronous mode can not be used from emulation nor main threads).
292 * Parameter f: The function to execute.
293 * Parameter arg: Argument to pass to the function.
294 * Parameter sync: If true, execute function call synchronously, else asynchronously.
296 static void queue(void (*f
)(void* arg
), void* arg
, bool sync
) throw(std::bad_alloc
);
300 static void run_queues() throw();
302 * Set availablinty of system thread.
304 static void system_thread_available(bool av
) throw();
306 static bool pausing_allowed
;
307 static double global_volume
;
308 static volatile bool do_exit_dummy_event_loop
;
309 static void dummy_event_loop() throw();
310 static void exit_dummy_event_loop() throw();
313 class modal_pause_holder
316 modal_pause_holder();
317 ~modal_pause_holder();
319 modal_pause_holder(const modal_pause_holder
&);
320 modal_pause_holder
& operator=(const modal_pause_holder
&);
324 void functor_call_helper(void* args
)
326 (*reinterpret_cast<T
*>(args
))();
332 platform::queue(functor_call_helper
<T
>, &fn
, true);
336 * If set, queueing synchronous function produces a warning.
338 extern volatile bool queue_synchronous_fn_warning
;