2011-09-13 17:50:18 +03:00
|
|
|
#ifndef _window__hpp__included__
|
|
|
|
#define _window__hpp__included__
|
|
|
|
|
2012-01-06 17:28:01 +02:00
|
|
|
#include "core/keymapper.hpp"
|
2013-08-25 17:32:56 +03:00
|
|
|
#include "interface/romtype.hpp"
|
2012-10-13 15:55:00 +03:00
|
|
|
#include "library/messagebuffer.hpp"
|
2012-10-13 16:03:29 +03:00
|
|
|
#include "library/emustatus.hpp"
|
2012-06-20 17:40:27 +03:00
|
|
|
#include "library/framebuffer.hpp"
|
2011-09-13 17:50:18 +03:00
|
|
|
#include <string>
|
|
|
|
#include <map>
|
|
|
|
#include <list>
|
|
|
|
#include <stdexcept>
|
|
|
|
|
2012-01-06 17:28:01 +02:00
|
|
|
class emulator_status;
|
2011-09-13 17:50:18 +03:00
|
|
|
|
2012-01-06 17:28:01 +02:00
|
|
|
/**
|
|
|
|
* Information about keypress.
|
|
|
|
*/
|
|
|
|
struct keypress
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Create null keypress (no modifiers, NULL key and released).
|
|
|
|
*/
|
|
|
|
keypress();
|
|
|
|
/**
|
|
|
|
* Create new keypress.
|
|
|
|
*/
|
2012-12-16 20:45:16 +02:00
|
|
|
keypress(keyboard_modifier_set mod, keyboard_key& _key, short _value);
|
2012-01-06 17:28:01 +02:00
|
|
|
/**
|
|
|
|
* Create new keypress (two keys).
|
|
|
|
*/
|
2012-12-16 20:45:16 +02:00
|
|
|
keypress(keyboard_modifier_set mod, keyboard_key& _key, keyboard_key& _key2, short _value);
|
2012-01-06 17:28:01 +02:00
|
|
|
/**
|
|
|
|
* Modifier set.
|
|
|
|
*/
|
2012-12-14 17:52:03 +02:00
|
|
|
keyboard_modifier_set modifiers;
|
2012-01-06 17:28:01 +02:00
|
|
|
/**
|
|
|
|
* The actual key (first)
|
|
|
|
*/
|
2012-12-16 20:45:16 +02:00
|
|
|
keyboard_key* key1;
|
2012-01-06 17:28:01 +02:00
|
|
|
/**
|
|
|
|
* The actual key (second)
|
|
|
|
*/
|
2012-12-16 20:45:16 +02:00
|
|
|
keyboard_key* key2;
|
2012-01-06 17:28:01 +02:00
|
|
|
/**
|
|
|
|
* Value for the press
|
|
|
|
*/
|
|
|
|
short value;
|
|
|
|
};
|
2011-09-13 17:50:18 +03:00
|
|
|
|
2013-08-25 17:32:56 +03:00
|
|
|
//ROM request.
|
|
|
|
struct rom_request
|
|
|
|
{
|
|
|
|
//List of core types.
|
|
|
|
std::vector<core_type*> cores;
|
|
|
|
//Selected core (default core on call).
|
|
|
|
size_t selected;
|
2013-09-14 16:28:43 +03:00
|
|
|
//Filename selected (on entry, filename hint).
|
2013-08-25 17:32:56 +03:00
|
|
|
std::string filename;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-01-22 08:06:28 +02:00
|
|
|
//Various methods corresponding to graphics_driver_*
|
|
|
|
struct _graphics_driver
|
|
|
|
{
|
|
|
|
void (*init)();
|
|
|
|
void (*quit)();
|
|
|
|
void (*notify_message)();
|
|
|
|
void (*notify_status)();
|
|
|
|
void (*notify_screen)();
|
2013-07-19 17:21:52 +03:00
|
|
|
void (*error_message)(const std::string& text);
|
2013-01-22 08:06:28 +02:00
|
|
|
void (*fatal_error)();
|
|
|
|
const char* (*name)();
|
2013-07-04 18:17:07 +03:00
|
|
|
void (*action_updated)();
|
2013-08-25 17:32:56 +03:00
|
|
|
void (*request_rom)(rom_request& req);
|
2013-01-22 08:06:28 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct graphics_driver
|
|
|
|
{
|
|
|
|
graphics_driver(_graphics_driver drv);
|
|
|
|
};
|
|
|
|
|
|
|
|
//Is dummy graphics plugin.
|
|
|
|
bool graphics_driver_is_dummy();
|
2012-01-06 17:28:01 +02:00
|
|
|
/**
|
|
|
|
* Graphics initialization function.
|
2011-10-31 21:05:54 +02:00
|
|
|
*
|
2012-01-06 17:28:01 +02:00
|
|
|
* - The first initialization function to be called by platform::init().
|
|
|
|
*/
|
2013-01-21 19:06:28 +02:00
|
|
|
void graphics_driver_init() throw();
|
2012-01-06 17:28:01 +02:00
|
|
|
/**
|
|
|
|
* Graphics quit function.
|
|
|
|
*
|
|
|
|
* - The last quit function to be called by platform::quit().
|
|
|
|
*/
|
2013-01-21 19:06:28 +02:00
|
|
|
void graphics_driver_quit() throw();
|
2012-01-06 17:28:01 +02:00
|
|
|
/**
|
|
|
|
* Notification when messages get updated.
|
|
|
|
*/
|
2013-01-21 19:06:28 +02:00
|
|
|
void graphics_driver_notify_message() throw();
|
2012-01-06 17:28:01 +02:00
|
|
|
/**
|
|
|
|
* Notification when status gets updated.
|
2011-10-28 20:26:40 +03:00
|
|
|
*/
|
2013-01-21 19:06:28 +02:00
|
|
|
void graphics_driver_notify_status() throw();
|
2012-01-06 17:28:01 +02:00
|
|
|
/**
|
|
|
|
* Notification when main screen gets updated.
|
|
|
|
*/
|
2013-01-21 19:06:28 +02:00
|
|
|
void graphics_driver_notify_screen() throw();
|
2012-01-06 17:28:01 +02:00
|
|
|
/**
|
2013-07-19 17:21:52 +03:00
|
|
|
* Show error message dialog when UI thread is free.
|
2012-01-06 17:28:01 +02:00
|
|
|
*
|
|
|
|
* Parameter text: The text for dialog.
|
|
|
|
*/
|
2013-07-19 17:21:52 +03:00
|
|
|
void graphics_driver_error_message(const std::string& text) throw();
|
2012-01-06 17:28:01 +02:00
|
|
|
/**
|
|
|
|
* Displays fatal error message.
|
|
|
|
*
|
|
|
|
* - After this routine returns, the program will quit.
|
|
|
|
* - The call can occur in any thread.
|
|
|
|
*/
|
2013-01-21 19:06:28 +02:00
|
|
|
void graphics_driver_fatal_error() throw();
|
2012-01-06 17:28:01 +02:00
|
|
|
/**
|
|
|
|
* Identification for graphics plugin.
|
|
|
|
*/
|
2013-01-22 08:06:28 +02:00
|
|
|
const char* graphics_driver_name();
|
2013-06-30 13:20:23 +03:00
|
|
|
/**
|
|
|
|
* Enable/Disable an action.
|
|
|
|
*/
|
2013-07-04 18:17:07 +03:00
|
|
|
void graphics_driver_action_updated();
|
2013-08-25 17:32:56 +03:00
|
|
|
/**
|
|
|
|
* Request a ROM image.
|
|
|
|
*/
|
|
|
|
void graphics_driver_request_rom(rom_request& req);
|
2011-10-28 20:26:40 +03:00
|
|
|
|
2012-01-06 17:28:01 +02:00
|
|
|
/**
|
|
|
|
* Platform-specific-related functions.
|
|
|
|
*/
|
|
|
|
struct platform
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Initialize the system.
|
2011-09-15 15:12:26 +03:00
|
|
|
*/
|
2011-09-17 01:05:41 +03:00
|
|
|
static void init();
|
2011-09-15 15:12:26 +03:00
|
|
|
|
|
|
|
/**
|
2012-01-06 17:28:01 +02:00
|
|
|
* Shut down the system.
|
2011-09-15 15:12:26 +03:00
|
|
|
*/
|
2011-09-17 01:05:41 +03:00
|
|
|
static void quit();
|
2011-09-13 17:50:18 +03:00
|
|
|
/**
|
2011-10-31 21:05:54 +02:00
|
|
|
* Get output stream printing into message queue.
|
2011-09-15 22:56:33 +03:00
|
|
|
*
|
2011-10-31 21:05:54 +02:00
|
|
|
* Note that lines printed there should be terminated by '\n'.
|
|
|
|
*
|
|
|
|
* Implemented by the generic window code.
|
|
|
|
*
|
|
|
|
* returns: The output stream.
|
2011-09-15 15:12:26 +03:00
|
|
|
* throws std::bad_alloc: Not enough memory.
|
2011-09-13 17:50:18 +03:00
|
|
|
*/
|
2011-10-31 21:05:54 +02:00
|
|
|
static std::ostream& out() throw(std::bad_alloc);
|
2011-09-13 17:50:18 +03:00
|
|
|
/**
|
2011-10-31 21:05:54 +02:00
|
|
|
* Get emulator status area
|
2011-09-15 22:56:33 +03:00
|
|
|
*
|
2011-10-31 21:05:54 +02:00
|
|
|
* returns: Emulator status area.
|
|
|
|
*/
|
2012-01-06 17:28:01 +02:00
|
|
|
static emulator_status& get_emustatus() throw();
|
2011-11-01 14:58:27 +02:00
|
|
|
/**
|
|
|
|
* Message buffer.
|
|
|
|
*/
|
|
|
|
static messagebuffer msgbuf;
|
2012-01-06 17:28:01 +02:00
|
|
|
/**
|
|
|
|
* Get message buffer lock.
|
|
|
|
*/
|
2013-01-21 09:24:46 +02:00
|
|
|
static mutex_class& msgbuf_lock() throw();
|
2012-01-06 17:28:01 +02:00
|
|
|
/**
|
|
|
|
* Set palette used on screen.
|
|
|
|
*/
|
|
|
|
static void screen_set_palette(unsigned rshift, unsigned gshift, unsigned bshift) throw();
|
2011-10-31 21:05:54 +02:00
|
|
|
/**
|
|
|
|
* Adds a messages to mesage queue to be shown.
|
2011-09-15 22:56:33 +03:00
|
|
|
*
|
2011-11-01 14:58:27 +02:00
|
|
|
* Implemented by the generic window code.
|
2011-10-31 21:05:54 +02:00
|
|
|
*
|
|
|
|
* parameter msg: The messages to add (split by '\n').
|
2011-09-15 15:12:26 +03:00
|
|
|
* throws std::bad_alloc: Not enough memory.
|
2011-09-13 17:50:18 +03:00
|
|
|
*/
|
2011-10-31 21:05:54 +02:00
|
|
|
static void message(const std::string& msg) throw(std::bad_alloc);
|
2011-09-13 17:50:18 +03:00
|
|
|
|
2011-11-01 14:58:27 +02:00
|
|
|
/**
|
|
|
|
* Displays fatal error message, quitting after the user acks it (called by fatal_error()).
|
|
|
|
*
|
|
|
|
* Needs to be implemented by the graphics plugin.
|
|
|
|
*/
|
|
|
|
static void fatal_error() throw();
|
2011-11-03 17:49:23 +02:00
|
|
|
/**
|
|
|
|
* Enable or disable sound.
|
|
|
|
*
|
|
|
|
* Implemented by the generic window code.
|
|
|
|
*
|
|
|
|
* parameter enable: Enable sounds if true, otherwise disable sounds.
|
|
|
|
*/
|
|
|
|
static void sound_enable(bool enable) throw();
|
|
|
|
/**
|
|
|
|
* Are sounds enabled?
|
|
|
|
*/
|
|
|
|
static bool is_sound_enabled() throw();
|
|
|
|
/**
|
|
|
|
* Set sound device.
|
|
|
|
*/
|
2013-01-28 13:01:05 +02:00
|
|
|
static void set_sound_device(const std::string& pdev, const std::string& rdev) throw();
|
2011-09-13 17:50:18 +03:00
|
|
|
/**
|
2013-07-19 17:21:52 +03:00
|
|
|
* Show error message dialog after UI thread becomes free.
|
2011-10-31 21:05:54 +02:00
|
|
|
*
|
2012-01-06 17:28:01 +02:00
|
|
|
* Parameter text: The text for dialog.
|
2011-09-13 17:50:18 +03:00
|
|
|
*/
|
2013-07-19 17:21:52 +03:00
|
|
|
static void error_message(const std::string& text) throw()
|
2012-01-06 17:28:01 +02:00
|
|
|
{
|
2013-07-19 17:21:52 +03:00
|
|
|
return graphics_driver_error_message(text);
|
2012-01-06 17:28:01 +02:00
|
|
|
}
|
2011-09-13 17:50:18 +03:00
|
|
|
/**
|
2012-01-06 17:28:01 +02:00
|
|
|
* Process command and keypress queues.
|
2011-11-03 17:57:46 +02:00
|
|
|
*
|
2012-01-06 17:28:01 +02:00
|
|
|
* - If emulating normally, this routine returns fast.
|
|
|
|
* - If emulator is in pause mode, this routine will block until emulator has left pause mode.
|
|
|
|
* - If emulator is in some special mode, this routine can block until said mode is left.
|
2011-09-13 17:50:18 +03:00
|
|
|
*/
|
2012-01-06 17:28:01 +02:00
|
|
|
static void flush_command_queue() throw();
|
2011-09-13 17:50:18 +03:00
|
|
|
/**
|
2011-09-15 15:12:26 +03:00
|
|
|
* Enable/Disable pause mode.
|
2011-09-15 22:56:33 +03:00
|
|
|
*
|
2012-01-06 17:28:01 +02:00
|
|
|
* - This function doesn't actually block. For actual paused blocking, use flush_command_queue().
|
2011-10-31 21:05:54 +02:00
|
|
|
*
|
2012-01-06 17:28:01 +02:00
|
|
|
* Parameter enable: Enable pause mode if true, disable pause mode if false.
|
2011-09-13 17:50:18 +03:00
|
|
|
*/
|
2012-01-06 17:28:01 +02:00
|
|
|
static void set_paused(bool enable) throw();
|
2011-09-13 17:50:18 +03:00
|
|
|
/**
|
2012-01-06 17:28:01 +02:00
|
|
|
* Wait specified number of milliseconds before returning.
|
2011-09-15 22:56:33 +03:00
|
|
|
*
|
2012-01-06 17:28:01 +02:00
|
|
|
* - The command and keypresses queues are processed while waiting.
|
2011-11-03 17:57:46 +02:00
|
|
|
*
|
2012-01-06 17:28:01 +02:00
|
|
|
* Parameter usec: The number of microseconds to wait.
|
2011-09-13 17:50:18 +03:00
|
|
|
*/
|
2012-01-06 17:28:01 +02:00
|
|
|
static void wait(uint64_t usec) throw();
|
2011-09-13 17:50:18 +03:00
|
|
|
/**
|
2012-01-06 17:28:01 +02:00
|
|
|
* Cause call to wait() to return immediately.
|
2011-09-15 15:12:26 +03:00
|
|
|
*/
|
2011-09-17 01:05:41 +03:00
|
|
|
static void cancel_wait() throw();
|
2011-09-15 15:12:26 +03:00
|
|
|
/**
|
2012-01-06 17:28:01 +02:00
|
|
|
* Notify received message.
|
2011-09-13 17:50:18 +03:00
|
|
|
*/
|
2012-01-06 17:28:01 +02:00
|
|
|
static void notify_message() throw()
|
|
|
|
{
|
2013-01-21 14:03:40 +02:00
|
|
|
graphics_driver_notify_message();
|
2012-01-06 17:28:01 +02:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Notify changed status.
|
|
|
|
*/
|
|
|
|
static void notify_status() throw()
|
|
|
|
{
|
2013-01-21 14:03:40 +02:00
|
|
|
graphics_driver_notify_status();
|
2012-01-06 17:28:01 +02:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Notify changed screen.
|
|
|
|
*/
|
|
|
|
static void notify_screen() throw()
|
|
|
|
{
|
2013-01-21 14:03:40 +02:00
|
|
|
graphics_driver_notify_screen();
|
2012-01-06 17:28:01 +02:00
|
|
|
}
|
2011-10-29 14:32:25 +03:00
|
|
|
/**
|
2012-01-06 17:28:01 +02:00
|
|
|
* Set modal pause mode.
|
2011-10-31 21:05:54 +02:00
|
|
|
*
|
2012-01-06 17:28:01 +02:00
|
|
|
* - Modal pause works like ordinary pause, except it uses a separate flag.
|
|
|
|
*
|
|
|
|
* Parameter enable: If true, enable modal pause, else disable it.
|
2011-10-29 14:32:25 +03:00
|
|
|
*/
|
2012-01-06 17:28:01 +02:00
|
|
|
static void set_modal_pause(bool enable) throw();
|
2011-10-29 14:32:25 +03:00
|
|
|
/**
|
2012-01-06 17:28:01 +02:00
|
|
|
* Queue keypress.
|
|
|
|
*
|
|
|
|
* - Can be called from any thread.
|
2011-10-31 21:05:54 +02:00
|
|
|
*
|
2012-01-06 17:28:01 +02:00
|
|
|
* Parameter k: The keypress to queue.
|
2011-10-29 14:32:25 +03:00
|
|
|
*/
|
2012-01-06 17:28:01 +02:00
|
|
|
static void queue(const keypress& k) throw(std::bad_alloc);
|
2011-10-29 14:32:25 +03:00
|
|
|
/**
|
2012-01-06 17:28:01 +02:00
|
|
|
* Queue command.
|
|
|
|
*
|
|
|
|
* - Can be called from any thread.
|
2011-10-31 21:05:54 +02:00
|
|
|
*
|
2012-01-06 17:28:01 +02:00
|
|
|
* Parameter c: The command to queue.
|
2011-10-29 14:32:25 +03:00
|
|
|
*/
|
2012-01-06 17:28:01 +02:00
|
|
|
static void queue(const std::string& c) throw(std::bad_alloc);
|
2011-10-29 14:32:25 +03:00
|
|
|
/**
|
2012-01-06 17:28:01 +02:00
|
|
|
* Queue function to be called in emulation thread.
|
2011-10-31 21:05:54 +02:00
|
|
|
*
|
2012-01-06 17:28:01 +02:00
|
|
|
* - Can be called from any thread (exception: Synchronous mode can not be used from emulation nor main threads).
|
|
|
|
*
|
|
|
|
* Parameter f: The function to execute.
|
|
|
|
* Parameter arg: Argument to pass to the function.
|
|
|
|
* Parameter sync: If true, execute function call synchronously, else asynchronously.
|
2011-10-29 14:32:25 +03:00
|
|
|
*/
|
2012-01-06 17:28:01 +02:00
|
|
|
static void queue(void (*f)(void* arg), void* arg, bool sync) throw(std::bad_alloc);
|
2011-10-31 21:05:54 +02:00
|
|
|
/**
|
2012-01-06 17:28:01 +02:00
|
|
|
* Run all queues.
|
2011-10-31 21:05:54 +02:00
|
|
|
*/
|
2012-01-06 17:28:01 +02:00
|
|
|
static void run_queues() throw();
|
2012-01-23 01:30:24 +02:00
|
|
|
|
|
|
|
static bool pausing_allowed;
|
2012-03-26 21:55:02 +03:00
|
|
|
static double global_volume;
|
2012-04-19 12:35:25 +03:00
|
|
|
static volatile bool do_exit_dummy_event_loop;
|
|
|
|
static void dummy_event_loop() throw();
|
|
|
|
static void exit_dummy_event_loop() throw();
|
2011-09-13 17:50:18 +03:00
|
|
|
};
|
|
|
|
|
2012-01-20 14:09:38 +02:00
|
|
|
class modal_pause_holder
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
modal_pause_holder();
|
|
|
|
~modal_pause_holder();
|
|
|
|
private:
|
|
|
|
modal_pause_holder(const modal_pause_holder&);
|
|
|
|
modal_pause_holder& operator=(const modal_pause_holder&);
|
|
|
|
};
|
|
|
|
|
2012-01-06 17:28:01 +02:00
|
|
|
template<typename T>
|
|
|
|
void functor_call_helper(void* args)
|
|
|
|
{
|
|
|
|
(*reinterpret_cast<T*>(args))();
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
void runemufn(T fn)
|
|
|
|
{
|
|
|
|
platform::queue(functor_call_helper<T>, &fn, true);
|
|
|
|
}
|
|
|
|
|
2012-01-15 20:47:57 +02:00
|
|
|
/**
|
|
|
|
* If set, queueing synchronous function produces a warning.
|
|
|
|
*/
|
|
|
|
extern volatile bool queue_synchronous_fn_warning;
|
2011-10-28 21:01:29 +03:00
|
|
|
|
2011-09-13 17:50:18 +03:00
|
|
|
#endif
|