DGen/SDL
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Classes | Macros | Typedefs | Enumerations | Functions | Variables
sdl.cpp File Reference
#include <sys/time.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <strings.h>
#include <stdarg.h>
#include <unistd.h>
#include <errno.h>
#include <ctype.h>
#include <assert.h>
#include <SDL.h>
#include <SDL_audio.h>
#include <SDL_opengl.h>
#include "md.h"
#include "rc.h"
#include "rc-vars.h"
#include "pd.h"
#include "pd-defs.h"
#include "font.h"
#include "system.h"
#include "prompt.h"
#include "romload.h"
#include "splash.h"
#include "hqx.h"
#include "scalebit.h"

Classes

union  bpp_t
 Generic type for supported colour depths. More...
struct  texture
 Framebuffer texture. More...
struct  screen
struct  cbuf_t
 Circular buffer and related functions. More...
struct  prompt_command
struct  filter_data
struct  filter
struct  filter_scale_data
struct  filter_stretch_data
struct  kb_input_t
 Keyboard input. More...
struct  ctl

Macros

#define HQX_NO_UINT24
 SDL interface.
#define MESSAGE_LIFE   3000000
 Number of microseconds to sustain messages.
#define PROMPT_RET_CONT   0x01
 Prompt return values.
#define PROMPT_RET_EXIT   0x02
 leave prompt normally
#define PROMPT_RET_ERROR   0x04
 leave prompt with error
#define PROMPT_RET_ENTER   0x10
 previous line entered
#define PROMPT_RET_MSG   0x80
 pd_message() has been used
#define CMD_OK   0x00
 Extra commands return values.
#define CMD_EINVAL   0x01
 invalid argument
#define CMD_FAIL   0x02
 command failed
#define CMD_ERROR   0x03
 fatal error, DGen should exit
#define CMD_MSG   0x80
 pd_message() has been used
#define TEXTURE_16_TYPE   GL_UNSIGNED_SHORT_5_6_5
#define TEXTURE_32_TYPE   GL_UNSIGNED_BYTE
#define FILTER_TEXT_ESCAPE   "\033"
 Special characters interpreted by filter_text().
#define FILTER_TEXT_BG_NONE   FILTER_TEXT_ESCAPE "\x01\x01"
#define FILTER_TEXT_BG_BLACK   FILTER_TEXT_ESCAPE "\x01\x02"
#define FILTER_TEXT_7X6   FILTER_TEXT_ESCAPE "\x02\x01"
#define FILTER_TEXT_8X13   FILTER_TEXT_ESCAPE "\x02\x02"
#define FILTER_TEXT_16X26   FILTER_TEXT_ESCAPE "\x02\x03"
#define FILTER_TEXT_CENTER   FILTER_TEXT_ESCAPE "\x03\x01"
#define FILTER_TEXT_LEFT   FILTER_TEXT_ESCAPE "\x03\x02"
#define FILTER_TEXT_RIGHT   FILTER_TEXT_ESCAPE "\x03\x03"
#define FILTER_TEXT_IS(f)
#define HISTORY_LEN   32
#define DEF   0, 0, 0, 0
#define MOUSE_MOTION_RELEASE_IS_ENABLED(which)   (mouse_motion_release.enabled[(which) / 8] & (1 << ((which) % 8)))
#define MOUSE_MOTION_RELEASE_DISABLE(which)   (mouse_motion_release.enabled[(which) / 8] &= ~(1 << ((which) % 8)))
#define MOUSE_MOTION_RELEASE_ENABLE(which)   (mouse_motion_release.enabled[(which) / 8] |= (1 << ((which) % 8)))
#define MOUSE_SHOW_USECS   (unsigned long)(2 * 1000000)
#define CE(i, s)   { i, s, sizeof(s) }

Typedefs

typedef void filter_func_t (const struct filter_data *in, struct filter_data *out)

Enumerations

enum  events {
  STARTED, STOPPED, STOPPED_PROMPT, STOPPED_GAME_GENIE,
  PROMPT, GAME_GENIE
}
 Events handling status. More...
enum  kb_input { KB_INPUT_ABORTED, KB_INPUT_ENTERED, KB_INPUT_CONSUMED, KB_INPUT_IGNORED }
 Keyboard input results. More...
enum  ctl_e {
  CTL_PAD1_UP, CTL_PAD1_DOWN, CTL_PAD1_LEFT, CTL_PAD1_RIGHT,
  CTL_PAD1_A, CTL_PAD1_B, CTL_PAD1_C, CTL_PAD1_X,
  CTL_PAD1_Y, CTL_PAD1_Z, CTL_PAD1_MODE, CTL_PAD1_START,
  CTL_PAD2_UP, CTL_PAD2_DOWN, CTL_PAD2_LEFT, CTL_PAD2_RIGHT,
  CTL_PAD2_A, CTL_PAD2_B, CTL_PAD2_C, CTL_PAD2_X,
  CTL_PAD2_Y, CTL_PAD2_Z, CTL_PAD2_MODE, CTL_PAD2_START,
  CTL_DGEN_QUIT, CTL_DGEN_CRAPTV_TOGGLE, CTL_DGEN_SCALING_TOGGLE, CTL_DGEN_RESET,
  CTL_DGEN_SLOT0, CTL_DGEN_SLOT1, CTL_DGEN_SLOT2, CTL_DGEN_SLOT3,
  CTL_DGEN_SLOT4, CTL_DGEN_SLOT5, CTL_DGEN_SLOT6, CTL_DGEN_SLOT7,
  CTL_DGEN_SLOT8, CTL_DGEN_SLOT9, CTL_DGEN_SLOT_NEXT, CTL_DGEN_SLOT_PREV,
  CTL_DGEN_SAVE, CTL_DGEN_LOAD, CTL_DGEN_Z80_TOGGLE, CTL_DGEN_CPU_TOGGLE,
  CTL_DGEN_STOP, CTL_DGEN_PROMPT, CTL_DGEN_GAME_GENIE, CTL_DGEN_VOLUME_INC,
  CTL_DGEN_VOLUME_DEC, CTL_DGEN_FULLSCREEN_TOGGLE, CTL_DGEN_FIX_CHECKSUM, CTL_DGEN_SCREENSHOT,
  CTL_DGEN_DEBUG_ENTER, CTL_
}

Functions

static void pd_message_process (void)
 Process status bar message.
static size_t pd_message_write (const char *msg, size_t len, unsigned int mark)
static size_t pd_message_display (const char *msg, size_t len, unsigned int mark, bool update)
static void pd_message_postpone (const char *msg)
 Postpone a message.
static void pd_message_cursor (unsigned int mark, const char *msg,...)
 Write a message to the status bar while displaying a cursor and without buffering.
static void release_texture (struct texture &)
static int init_texture (struct screen *)
static void update_texture (struct texture &)
static int screen_lock ()
 Call this before accessing screen.buf.
static void screen_unlock ()
 Call this after accessing screen.buf.
static void screen_update_once ()
 Do not call this directly, use screen_update() instead.
static void screen_update ()
 Call this after writing into screen.buf.
static void screen_clear ()
 Clear screen.
void md_save (md &megad)
void md_load (md &megad)
static void mdscr_splash ()
 Display splash screen.
size_t cbuf_write (cbuf_t *cbuf, uint8_t *src, size_t size)
 Write/copy data into a circular buffer.
size_t cbuf_read (uint8_t *dst, cbuf_t *cbuf, size_t size)
 Read bytes out of a circular buffer.
static int prompt_cmd_exit (class md &, unsigned int, const char **)
 Prompt "exit" command handler.
static int prompt_cmd_load (class md &md, unsigned int ac, const char **av)
 Prompt "load" command handler.
static char * prompt_cmpl_load (class md &, unsigned int, const char **, unsigned int)
static int prompt_cmd_unload (class md &, unsigned int, const char **)
static int prompt_cmd_reset (class md &, unsigned int, const char **)
static int prompt_cmd_unbind (class md &, unsigned int, const char **)
static char * prompt_cmpl_unbind (class md &, unsigned int, const char **, unsigned int)
static int prompt_cmd_filter_push (class md &, unsigned int, const char **)
static char * prompt_cmpl_filter_push (class md &, unsigned int, const char **, unsigned int)
static int prompt_cmd_filter_pop (class md &, unsigned int, const char **)
static int prompt_cmd_filter_none (class md &, unsigned int, const char **)
static int prompt_cmd_calibrate (class md &, unsigned int n_args, const char **args)
 Interactively calibrate a controller.
static int prompt_cmd_config_load (class md &md, unsigned int ac, const char **av)
 Prompt "config_load" command handler.
static int prompt_cmd_config_save (class md &md, unsigned int ac, const char **av)
 Prompt "config_save" command handler.
static char * prompt_cmpl_config_file (class md &, unsigned int, const char **, unsigned int)
static int stop_events (md &megad, enum events status)
static void restart_events (md &megad)
static void freeze (bool toggle)
unsigned long pd_usecs (void)
 Elapsed time in microseconds.
static void rehash_prompt_complete_common ()
static int prompt_rehash_rc_field (const struct rc_field *rc, md &megad)
 Rehash rc vars that require special handling (see "SH" in rc.cpp).
static void set_swab ()
static struct filterfilters_find (const char *name)
 Return filter structure associated with name.
static void filters_stack_update ()
 Update filters data, reallocate extra buffers if necessary.
static void filters_push (const struct filter *f)
 Add filter to stack.
static void filters_insert (const struct filter *f)
 Insert filter at the bottom of the stack.
static void filters_pop ()
 Remove last filter from stack.
static void filters_remove (unsigned int index)
 Remove a filter from anywhere in the stack.
static void filters_pluck (const struct filter *f)
 Remove all occurences of filter from the stack.
static void filters_pluck_ctv ()
 Remove all occurences of CTV filters from the stack.
static void filters_empty ()
 Empty filters stack.
static void do_screenshot (md &megad)
 Take a screenshot.
void pd_help ()
 SDL flags help.
void pd_rc ()
 Handle rc variables.
void pd_option (char c, const char *)
 Handle the switches.
static void texture_init_id (struct texture &texture)
static void texture_init_dlist (struct texture &texture)
static uint32_t roundup2 (uint32_t v)
 Round a value up to nearest power of two.
static void filter_off (const struct filter_data *in, struct filter_data *out)
 This filter passes input to output unchanged, only centered or truncated if necessary.
template<typename uintX_t >
static void filter_scale_X (const struct filter_data *in, struct filter_data *out)
static void filter_scale_3 (const struct filter_data *in, struct filter_data *out)
static void filter_scale (const struct filter_data *in, struct filter_data *out)
 This filter attempts to rescale according to screen X/Y factors.
template<typename uintX_t >
static void filter_stretch_X (const struct filter_data *in, struct filter_data *out)
static void filter_stretch_3 (const struct filter_data *in, struct filter_data *out)
static void filter_stretch (const struct filter_data *in, struct filter_data *out)
 This filter stretches the input buffer to fill the entire output.
static void filter_hqx (const struct filter_data *in, struct filter_data *out)
 This filter attempts to rescale with HQX.
static void filter_scale2x (const struct filter_data *in, struct filter_data *out)
 This filter attempts to rescale with Scale2x.
static void filter_blur_32 (const struct filter_data *in, struct filter_data *out)
static void filter_blur_24 (const struct filter_data *in, struct filter_data *out)
static void filter_blur_16 (const struct filter_data *in, struct filter_data *out)
static void filter_blur_15 (const struct filter_data *in, struct filter_data *out)
static void filter_blur (const struct filter_data *in, struct filter_data *out)
static void filter_scanline_frame (const struct filter_data *in, struct filter_data *out)
static void filter_scanline (const struct filter_data *in, struct filter_data *out)
static void filter_interlace (const struct filter_data *in, struct filter_data *out)
static void filter_swab (const struct filter_data *in, struct filter_data *out)
static void filter_text_msg (const char *fmt,...)
 Append message to filter_text_str[].
static void filter_text (const struct filter_data *in, struct filter_data *out)
 Text overlay filter.
static void manage_calibration (enum rc_binding_type type, intptr_t code)
 Handle input during calibration process.
static int set_scaling (const char *name)
static int screen_init (unsigned int width, unsigned int height)
 Initialize screen.
static int set_fullscreen (int toggle)
 Set fullscreen mode.
int pd_graphics_init (int want_sound, int want_pal, int hz)
 Initialize SDL, and the graphics.
int pd_graphics_reinit (int, int want_pal, int hz)
 Reinitialize graphics.
void pd_graphics_palette_update ()
 Update palette.
void pd_graphics_update (bool update)
 Display screen.
static void snd_callback (void *, Uint8 *stream, int len)
 Callback for sound.
int pd_sound_init (long &freq, unsigned int &samples)
 Initialize the sound.
void pd_sound_deinit ()
 Deinitialize sound subsystem.
unsigned int pd_sound_rp ()
 Return samples read/write indices in the buffer.
unsigned int pd_sound_wp ()
void pd_sound_write ()
 Write contents of sndi to sound.cbuf.
int pd_stopped ()
 Tells whether DGen stopped intentionally so emulation can resume without skipping frames.
static enum kb_input kb_input (kb_input_t *input, uint32_t ksym, uint16_t ksym_uni)
 Manage text input with some rudimentary history.
static void prompt_show_rc_field (const struct rc_field *rc)
static int handle_prompt_enter (class md &md)
static void handle_prompt_complete_clear ()
static int handle_prompt_complete (class md &md, bool rwd)
static int handle_prompt (uint32_t ksym, uint16_t ksym_uni, md &megad)
static int ctl_pad1 (struct ctl &ctl, md &megad)
static int ctl_pad1_release (struct ctl &ctl, md &megad)
static int ctl_pad2 (struct ctl &ctl, md &megad)
static int ctl_pad2_release (struct ctl &ctl, md &megad)
static int ctl_dgen_quit (struct ctl &, md &)
static int ctl_dgen_craptv_toggle (struct ctl &, md &)
static int ctl_dgen_scaling_toggle (struct ctl &, md &)
static int ctl_dgen_reset (struct ctl &, md &megad)
static int ctl_dgen_slot (struct ctl &ctl, md &)
static int ctl_dgen_slot_next (struct ctl &, md &)
static int ctl_dgen_slot_prev (struct ctl &, md &)
static int ctl_dgen_save (struct ctl &, md &megad)
static int ctl_dgen_load (struct ctl &, md &megad)
static int ctl_dgen_z80_toggle (struct ctl &, md &megad)
static int ctl_dgen_cpu_toggle (struct ctl &, md &megad)
static int ctl_dgen_stop (struct ctl &, md &megad)
static int ctl_dgen_prompt (struct ctl &, md &megad)
static int ctl_dgen_game_genie (struct ctl &, md &megad)
static int ctl_dgen_volume (struct ctl &ctl, md &)
static int ctl_dgen_fullscreen_toggle (struct ctl &, md &)
static int ctl_dgen_fix_checksum (struct ctl &, md &megad)
static int ctl_dgen_screenshot (struct ctl &, md &megad)
static int ctl_dgen_debug_enter (struct ctl &, md &megad)
static void manage_combos (md &md, bool pressed, enum rc_binding_type type, intptr_t code)
static bool check_combos (md &md, struct rc_binding_item item[], unsigned int num)
static int manage_bindings (md &md, bool pressed, enum rc_binding_type type, intptr_t code)
static int manage_game_genie (md &megad, intptr_t ksym, intptr_t ksym_uni)
static bool mouse_is_grabbed ()
static void mouse_grab (bool grab)
static void mouse_motion_delay_release (unsigned int which, bool enable)
static bool mouse_motion_released (SDL_Event *event)
int pd_handle_events (md &megad)
void pd_message (const char *msg,...)
 Write a message to the status bar.
void pd_clear_message ()
void pd_show_carthead (md &megad)
void pd_quit ()

Variables

static struct screen screen
struct {
   const unsigned int   width
 320
   unsigned int   height
 224 or 240 (NTSC_VBLANK or PAL_VBLANK)
   unsigned int   hz
 refresh rate
   unsigned int   is_pal: 1
 PAL enabled.
   uint8_t   palette [256]
 palette for 8bpp modes (mdpal)
video
int slot
struct bmap mdscr
unsigned char * mdpal = NULL
struct sndinfo sndi
const char * pd_options = "fX:Y:S:G:"
struct {
   unsigned int   rate
 samples rate
   unsigned int   samples
 number of samples required by the callback
   cbuf_t   cbuf
 circular buffer
sound
 Sound.
struct {
   unsigned int   displayed:1
 whether message is currently displayed
   unsigned long   since
 since this number of microseconds
   size_t   length
 remaining length to display
   char   message [2048]
 message
info
 Messages.
struct {
   struct prompt   status
 prompt status
   char **   complete
 completion results array
   unsigned int   skip
 number of entries to skip in the array
   unsigned int   common
 common length of all entries
prompt
 Prompt.
static struct prompt_command prompt_command []
 List of commands to auto complete.
static int stopped = 0
 Stopped flag used by pd_stopped()
static enum events events
static const char stopped_str [] = "STOPPED."
 Messages shown whenever events are stopped.
static const char prompt_str [] = ":"
static const char game_genie_str [] = "Enter Game Genie/Hex code: "
bool pd_freeze = false
 Enable emulation by default.
static unsigned int pd_freeze_ref = 0
static filter_func_t filter_scale
static filter_func_t filter_off
static filter_func_t filter_stretch
static filter_func_t filter_scale2x
static filter_func_t filter_hqx
static filter_func_t filter_blur
static filter_func_t filter_scanline
static filter_func_t filter_interlace
static filter_func_t filter_swab
static struct filter filters_available []
static unsigned int filters_stack_size
static bool filters_stack_default
static struct filterfilters_stack [64]
static bpp_t filters_stack_data_buf [2]
static struct filter_data filters_stack_data [1+elemof(filters_stack)]
static char filter_text_str [2048]
static struct filter filter_text_def
static bool calibrating = false
static unsigned int calibrating_controller
 Controller being calibrated.
static struct ctl control []
struct {
   char const *   name
 Controller button name.
   enum ctl_e const   id [2]
 Controls indices in control[].
   bool   once
 If button has been pressed once.
   bool   twice
 If button has been pressed twice.
   enum rc_binding_type   type
 Type of code.
   intptr_t   code
 Temporary code.
calibration_steps []
static struct rc_binding_item combos [64]
struct {
   unsigned long   when [0x100]
   uint8_t   enabled [0x100/8]
   unsigned int   count
mouse_motion_release

Macro Definition Documentation

#define CE (   i,
 
)    { i, s, sizeof(s) }
#define CMD_EINVAL   0x01

invalid argument

#define CMD_ERROR   0x03

fatal error, DGen should exit

#define CMD_FAIL   0x02

command failed

#define CMD_MSG   0x80

pd_message() has been used

#define CMD_OK   0x00

Extra commands return values.

command successful

#define DEF   0, 0, 0, 0
#define FILTER_TEXT_16X26   FILTER_TEXT_ESCAPE "\x02\x03"
#define FILTER_TEXT_7X6   FILTER_TEXT_ESCAPE "\x02\x01"
#define FILTER_TEXT_8X13   FILTER_TEXT_ESCAPE "\x02\x02"
#define FILTER_TEXT_BG_BLACK   FILTER_TEXT_ESCAPE "\x01\x02"
#define FILTER_TEXT_BG_NONE   FILTER_TEXT_ESCAPE "\x01\x01"
#define FILTER_TEXT_CENTER   FILTER_TEXT_ESCAPE "\x03\x01"
#define FILTER_TEXT_ESCAPE   "\033"

Special characters interpreted by filter_text().

FILTER_TEXT_BG_NONE transparent background. FILTER_TEXT_BG_BLACK black background. FILTER_TEXT_7X6 use 7x6 font. FILTER_TEXT_8X13 use 8x13 font. FILTER_TEXT_16X26 use 16x26 font. FILTER_TEXT_CENTER center justify. FILTER_TEXT_LEFT left justify. FILTER_TEXT_RIGHT right justify.

#define FILTER_TEXT_IS (   f)
Value:
(tmp = (f), sz = strlen(f), \
!strncmp(tmp, next, sz))
#define FILTER_TEXT_LEFT   FILTER_TEXT_ESCAPE "\x03\x02"
#define FILTER_TEXT_RIGHT   FILTER_TEXT_ESCAPE "\x03\x03"
#define HISTORY_LEN   32
#define HQX_NO_UINT24

SDL interface.

#define MESSAGE_LIFE   3000000

Number of microseconds to sustain messages.

#define MOUSE_MOTION_RELEASE_DISABLE (   which)    (mouse_motion_release.enabled[(which) / 8] &= ~(1 << ((which) % 8)))
#define MOUSE_MOTION_RELEASE_ENABLE (   which)    (mouse_motion_release.enabled[(which) / 8] |= (1 << ((which) % 8)))
#define MOUSE_MOTION_RELEASE_IS_ENABLED (   which)    (mouse_motion_release.enabled[(which) / 8] & (1 << ((which) % 8)))
#define MOUSE_SHOW_USECS   (unsigned long)(2 * 1000000)
#define PROMPT_RET_CONT   0x01

Prompt return values.

waiting for more input

#define PROMPT_RET_ENTER   0x10

previous line entered

#define PROMPT_RET_ERROR   0x04

leave prompt with error

#define PROMPT_RET_EXIT   0x02

leave prompt normally

#define PROMPT_RET_MSG   0x80

pd_message() has been used

#define TEXTURE_16_TYPE   GL_UNSIGNED_SHORT_5_6_5
#define TEXTURE_32_TYPE   GL_UNSIGNED_BYTE

Typedef Documentation

typedef void filter_func_t(const struct filter_data *in, struct filter_data *out)

Enumeration Type Documentation

enum ctl_e
Enumerator:
CTL_PAD1_UP 
CTL_PAD1_DOWN 
CTL_PAD1_LEFT 
CTL_PAD1_RIGHT 
CTL_PAD1_A 
CTL_PAD1_B 
CTL_PAD1_C 
CTL_PAD1_X 
CTL_PAD1_Y 
CTL_PAD1_Z 
CTL_PAD1_MODE 
CTL_PAD1_START 
CTL_PAD2_UP 
CTL_PAD2_DOWN 
CTL_PAD2_LEFT 
CTL_PAD2_RIGHT 
CTL_PAD2_A 
CTL_PAD2_B 
CTL_PAD2_C 
CTL_PAD2_X 
CTL_PAD2_Y 
CTL_PAD2_Z 
CTL_PAD2_MODE 
CTL_PAD2_START 
CTL_DGEN_QUIT 
CTL_DGEN_CRAPTV_TOGGLE 
CTL_DGEN_SCALING_TOGGLE 
CTL_DGEN_RESET 
CTL_DGEN_SLOT0 
CTL_DGEN_SLOT1 
CTL_DGEN_SLOT2 
CTL_DGEN_SLOT3 
CTL_DGEN_SLOT4 
CTL_DGEN_SLOT5 
CTL_DGEN_SLOT6 
CTL_DGEN_SLOT7 
CTL_DGEN_SLOT8 
CTL_DGEN_SLOT9 
CTL_DGEN_SLOT_NEXT 
CTL_DGEN_SLOT_PREV 
CTL_DGEN_SAVE 
CTL_DGEN_LOAD 
CTL_DGEN_Z80_TOGGLE 
CTL_DGEN_CPU_TOGGLE 
CTL_DGEN_STOP 
CTL_DGEN_PROMPT 
CTL_DGEN_GAME_GENIE 
CTL_DGEN_VOLUME_INC 
CTL_DGEN_VOLUME_DEC 
CTL_DGEN_FULLSCREEN_TOGGLE 
CTL_DGEN_FIX_CHECKSUM 
CTL_DGEN_SCREENSHOT 
CTL_DGEN_DEBUG_ENTER 
CTL_ 
enum events

Events handling status.

Enumerator:
STARTED 
STOPPED 
STOPPED_PROMPT 
STOPPED_GAME_GENIE 
PROMPT 
GAME_GENIE 
enum kb_input

Keyboard input results.

Enumerator:
KB_INPUT_ABORTED 
KB_INPUT_ENTERED 
KB_INPUT_CONSUMED 
KB_INPUT_IGNORED 

Function Documentation

size_t cbuf_read ( uint8_t *  dst,
cbuf_t cbuf,
size_t  size 
)

Read bytes out of a circular buffer.

Parameters:
[out]dstDestination buffer.
[in,out]cbufCircular buffer to read from.
sizeMaximum number of bytes to copy to dst.
Returns:
Number of bytes copied.
size_t cbuf_write ( cbuf_t cbuf,
uint8_t *  src,
size_t  size 
)

Write/copy data into a circular buffer.

Parameters:
[in,out]cbufDestination buffer.
[in]srcBuffer to copy from.
sizeSize of src.
Returns:
Number of bytes copied.
static bool check_combos ( md md,
struct rc_binding_item  item[],
unsigned int  num 
)
static
static int ctl_dgen_cpu_toggle ( struct ctl ,
md megad 
)
static
static int ctl_dgen_craptv_toggle ( struct ctl ,
md  
)
static
static int ctl_dgen_debug_enter ( struct ctl ,
md megad 
)
static
static int ctl_dgen_fix_checksum ( struct ctl ,
md megad 
)
static
static int ctl_dgen_fullscreen_toggle ( struct ctl ,
md  
)
static
static int ctl_dgen_game_genie ( struct ctl ,
md megad 
)
static
static int ctl_dgen_load ( struct ctl ,
md megad 
)
static
static int ctl_dgen_prompt ( struct ctl ,
md megad 
)
static
static int ctl_dgen_quit ( struct ctl ,
md  
)
static
static int ctl_dgen_reset ( struct ctl ,
md megad 
)
static
static int ctl_dgen_save ( struct ctl ,
md megad 
)
static
static int ctl_dgen_scaling_toggle ( struct ctl ,
md  
)
static
static int ctl_dgen_screenshot ( struct ctl ,
md megad 
)
static
static int ctl_dgen_slot ( struct ctl ctl,
md  
)
static
static int ctl_dgen_slot_next ( struct ctl ,
md  
)
static
static int ctl_dgen_slot_prev ( struct ctl ,
md  
)
static
static int ctl_dgen_stop ( struct ctl ,
md megad 
)
static
static int ctl_dgen_volume ( struct ctl ctl,
md  
)
static
static int ctl_dgen_z80_toggle ( struct ctl ,
md megad 
)
static
static int ctl_pad1 ( struct ctl ctl,
md megad 
)
static
static int ctl_pad1_release ( struct ctl ctl,
md megad 
)
static
static int ctl_pad2 ( struct ctl ctl,
md megad 
)
static
static int ctl_pad2_release ( struct ctl ctl,
md megad 
)
static
static void do_screenshot ( md megad)
static

Take a screenshot.

static void filter_blur ( const struct filter_data in,
struct filter_data out 
)
static
static void filter_blur_15 ( const struct filter_data in,
struct filter_data out 
)
static
static void filter_blur_16 ( const struct filter_data in,
struct filter_data out 
)
static
static void filter_blur_24 ( const struct filter_data in,
struct filter_data out 
)
static
static void filter_blur_32 ( const struct filter_data in,
struct filter_data out 
)
static
static void filter_hqx ( const struct filter_data in,
struct filter_data out 
)
static

This filter attempts to rescale with HQX.

Parameters:
inInput buffer data.
outOutput buffer data.
static void filter_interlace ( const struct filter_data in,
struct filter_data out 
)
static
static void filter_off ( const struct filter_data in,
struct filter_data out 
)
static

This filter passes input to output unchanged, only centered or truncated if necessary.

Doesn't have any fallback, thus cannot fail.

Parameters:
inInput buffer data.
outOutput buffer data.
static void filter_scale ( const struct filter_data in,
struct filter_data out 
)
static

This filter attempts to rescale according to screen X/Y factors.

Parameters:
inInput buffer data.
outOutput buffer data.
static void filter_scale2x ( const struct filter_data in,
struct filter_data out 
)
static

This filter attempts to rescale with Scale2x.

Parameters:
inInput buffer data.
outOutput buffer data.
static void filter_scale_3 ( const struct filter_data in,
struct filter_data out 
)
static
template<typename uintX_t >
static void filter_scale_X ( const struct filter_data in,
struct filter_data out 
)
static
static void filter_scanline ( const struct filter_data in,
struct filter_data out 
)
static
static void filter_scanline_frame ( const struct filter_data in,
struct filter_data out 
)
static
static void filter_stretch ( const struct filter_data in,
struct filter_data out 
)
static

This filter stretches the input buffer to fill the entire output.

Parameters:
inInput buffer data.
outOutput buffer data.
static void filter_stretch_3 ( const struct filter_data in,
struct filter_data out 
)
static
template<typename uintX_t >
static void filter_stretch_X ( const struct filter_data in,
struct filter_data out 
)
static
static void filter_swab ( const struct filter_data in,
struct filter_data out 
)
static
static void filter_text ( const struct filter_data in,
struct filter_data out 
)
static

Text overlay filter.

Parameters:
inInput buffer data.
outOutput buffer data.
static void filter_text_msg ( const char *  fmt,
  ... 
)
static

Append message to filter_text_str[].

static void filters_empty ( )
static

Empty filters stack.

static struct filter* filters_find ( const char *  name)
staticread

Return filter structure associated with name.

Parameters:
nameName of filter.
Returns:
Pointer to filter or NULL if not found.
static void filters_insert ( const struct filter f)
static

Insert filter at the bottom of the stack.

Parameters:
fFilter to insert.
static void filters_pluck ( const struct filter f)
static

Remove all occurences of filter from the stack.

Parameters:
fFilter to remove.
static void filters_pluck_ctv ( )
static

Remove all occurences of CTV filters from the stack.

static void filters_pop ( )
static

Remove last filter from stack.

static void filters_push ( const struct filter f)
static

Add filter to stack.

Parameters:
fFilter to add.
static void filters_remove ( unsigned int  index)
static

Remove a filter from anywhere in the stack.

Parameters:
indexFilters stack index.
static void filters_stack_update ( )
static

Update filters data, reallocate extra buffers if necessary.

static void freeze ( bool  toggle)
static
static int handle_prompt ( uint32_t  ksym,
uint16_t  ksym_uni,
md megad 
)
static
static int handle_prompt_complete ( class md md,
bool  rwd 
)
static
static void handle_prompt_complete_clear ( )
static
static int handle_prompt_enter ( class md md)
static
static int init_texture ( struct screen screen)
static
static enum kb_input kb_input ( kb_input_t input,
uint32_t  ksym,
uint16_t  ksym_uni 
)
static

Manage text input with some rudimentary history.

Parameters:
inputInput buffer.
ksymKeyboard symbol.
ksym_uniUnicode translation for keyboard symbol.
Returns:
Input result.
static int manage_bindings ( md md,
bool  pressed,
enum rc_binding_type  type,
intptr_t  code 
)
static
static void manage_calibration ( enum rc_binding_type  type,
intptr_t  code 
)
static

Handle input during calibration process.

Parameters:
typeType of code.
codeCode to process.
static void manage_combos ( md md,
bool  pressed,
enum rc_binding_type  type,
intptr_t  code 
)
static
static int manage_game_genie ( md megad,
intptr_t  ksym,
intptr_t  ksym_uni 
)
static
void md_load ( md megad)
void md_save ( md megad)
static void mdscr_splash ( )
static

Display splash screen.

static void mouse_grab ( bool  grab)
static
static bool mouse_is_grabbed ( )
static
static void mouse_motion_delay_release ( unsigned int  which,
bool  enable 
)
static
static bool mouse_motion_released ( SDL_Event *  event)
static
void pd_clear_message ( )
int pd_graphics_init ( int  want_sound,
int  want_pal,
int  hz 
)

Initialize SDL, and the graphics.

Parameters:
want_soundNonzero if we want sound.
want_palNonzero for PAL mode.
hzRequested frame rate (between 0 and 1000).
Returns:
Nonzero if successful.
void pd_graphics_palette_update ( )

Update palette.

int pd_graphics_reinit ( int  ,
int  want_pal,
int  hz 
)

Reinitialize graphics.

Parameters:
want_palNonzero for PAL mode.
hzRequested frame rate (between 0 and 1000).
Returns:
Nonzero if successful.
void pd_graphics_update ( bool  update)

Display screen.

Parameters:
updateFalse if screen buffer is garbage and must be updated first.
int pd_handle_events ( md megad)
void pd_help ( )

SDL flags help.

void pd_message ( const char *  msg,
  ... 
)

Write a message to the status bar.

static void pd_message_cursor ( unsigned int  mark,
const char *  msg,
  ... 
)
static

Write a message to the status bar while displaying a cursor and without buffering.

static size_t pd_message_display ( const char *  msg,
size_t  len,
unsigned int  mark,
bool  update 
)
static
static void pd_message_postpone ( const char *  msg)
static

Postpone a message.

static void pd_message_process ( void  )
static

Process status bar message.

static size_t pd_message_write ( const char *  msg,
size_t  len,
unsigned int  mark 
)
static
void pd_option ( char  c,
const char *   
)

Handle the switches.

Parameters:
cSwitch's value.
void pd_quit ( )
void pd_rc ( )

Handle rc variables.

void pd_show_carthead ( md megad)
void pd_sound_deinit ( )

Deinitialize sound subsystem.

int pd_sound_init ( long &  freq,
unsigned int &  samples 
)

Initialize the sound.

Parameters:
freqSound samples rate.
[in,out]samplesMinimum buffer size in samples.
Returns:
Nonzero on success.
unsigned int pd_sound_rp ( )

Return samples read/write indices in the buffer.

unsigned int pd_sound_wp ( )
void pd_sound_write ( )

Write contents of sndi to sound.cbuf.

int pd_stopped ( )

Tells whether DGen stopped intentionally so emulation can resume without skipping frames.

unsigned long pd_usecs ( void  )

Elapsed time in microseconds.

Returns:
Microseconds.
static int prompt_cmd_calibrate ( class md ,
unsigned int  n_args,
const char **  args 
)
static

Interactively calibrate a controller.

If n_args == 1, controller 0 will be configured. If n_args == 2, configure controller in string args[1].

Parameters:
n_argsNumber of arguments.
[in]argsList of arguments.
Returns:
Status code.
static int prompt_cmd_config_load ( class md md,
unsigned int  ac,
const char **  av 
)
static

Prompt "config_load" command handler.

Parameters:
mdContext.
acNumber of arguments in av.
avArguments.
Returns:
Status code.
static int prompt_cmd_config_save ( class md md,
unsigned int  ac,
const char **  av 
)
static

Prompt "config_save" command handler.

Parameters:
mdContext.
acNumber of arguments in av.
avArguments.
Returns:
Status code.
static int prompt_cmd_exit ( class md ,
unsigned  int,
const char **   
)
static

Prompt "exit" command handler.

Returns:
Error status to make DGen exit.
static int prompt_cmd_filter_none ( class md ,
unsigned int  ac,
const char **   
)
static
static int prompt_cmd_filter_pop ( class md ,
unsigned int  ac,
const char **   
)
static
static int prompt_cmd_filter_push ( class md ,
unsigned int  ac,
const char **  av 
)
static
static int prompt_cmd_load ( class md md,
unsigned int  ac,
const char **  av 
)
static

Prompt "load" command handler.

Parameters:
mdContext.
acNumber of arguments in av.
avArguments.
Returns:
Status code.
static int prompt_cmd_reset ( class md md,
unsigned  int,
const char **   
)
static
static int prompt_cmd_unbind ( class md ,
unsigned int  ac,
const char **  av 
)
static
static int prompt_cmd_unload ( class md md,
unsigned  int,
const char **   
)
static
static char * prompt_cmpl_config_file ( class md md,
unsigned int  ac,
const char **  av,
unsigned int  len 
)
static
static char * prompt_cmpl_filter_push ( class md ,
unsigned int  ac,
const char **  av,
unsigned int  len 
)
static
static char * prompt_cmpl_load ( class md md,
unsigned int  ac,
const char **  av,
unsigned int  len 
)
static
static char * prompt_cmpl_unbind ( class md ,
unsigned int  ac,
const char **  av,
unsigned int  len 
)
static
static int prompt_rehash_rc_field ( const struct rc_field rc,
md megad 
)
static

Rehash rc vars that require special handling (see "SH" in rc.cpp).

static void prompt_show_rc_field ( const struct rc_field rc)
static
static void rehash_prompt_complete_common ( )
static
static void release_texture ( struct texture texture)
static
static void restart_events ( md megad)
static
static uint32_t roundup2 ( uint32_t  v)
static

Round a value up to nearest power of two.

Parameters:
vValue.
Returns:
Rounded value.
static void screen_clear ( )
static

Clear screen.

static int screen_init ( unsigned int  width,
unsigned int  height 
)
static

Initialize screen.

Parameters:
widthWidth of display.
heightHeight of display.
Returns:
0 on success, -1 if screen could not be initialized with current options but remains in its previous state, -2 if screen is unusable.
static int screen_lock ( )
static

Call this before accessing screen.buf.

No syscalls allowed before screen_unlock().

static void screen_unlock ( )
static

Call this after accessing screen.buf.

static void screen_update ( )
static

Call this after writing into screen.buf.

static void screen_update_once ( )
static

Do not call this directly, use screen_update() instead.

static int set_fullscreen ( int  toggle)
static

Set fullscreen mode.

Parameters:
toggleNonzero to enable fullscreen, otherwise disable it.
Returns:
0 on success.
static int set_scaling ( const char *  name)
static
static void set_swab ( )
static
static void snd_callback ( void *  ,
Uint8 *  stream,
int  len 
)
static

Callback for sound.

Parameters:
streamSound destination buffer.
lenLength of destination buffer.
static int stop_events ( md megad,
enum events  status 
)
static
static void texture_init_dlist ( struct texture texture)
static
static void texture_init_id ( struct texture texture)
static
static void update_texture ( struct texture texture)
static

Variable Documentation

bool calibrating = false
static
unsigned int calibrating_controller
static

Controller being calibrated.

struct { ... } calibration_steps[]
cbuf_t cbuf

circular buffer

intptr_t code

Temporary code.

struct rc_binding_item combos[64]
static
unsigned int common

common length of all entries

char** complete

completion results array

struct ctl control[]
static
unsigned int count
unsigned int displayed

whether message is currently displayed

uint8_t enabled[0x100/8]
enum events events
static
filter_func_t filter_blur
static
filter_func_t filter_hqx
static
filter_func_t filter_interlace
static
filter_func_t filter_off
static
filter_func_t filter_scale
static
filter_func_t filter_scale2x
static
filter_func_t filter_scanline
static
filter_func_t filter_stretch
static
filter_func_t filter_swab
static
struct filter filter_text_def
static
Initial value:
{
"text", filter_text, true, false, false
}
char filter_text_str[2048]
static
struct filter filters_available[]
static
Initial value:
{
{ "stretch", filter_stretch, false, false, true },
{ "scale", filter_scale, false, false, true },
{ "scale2x", filter_scale2x, false, false, true },
{ "hqx", filter_hqx, false, false, true },
{ "none", filter_off, true, false, true },
{ "off", filter_off, true, true, false },
{ "blur", filter_blur, true, true, false },
{ "scanline", filter_scanline, true, true, false },
{ "interlace", filter_interlace, true, true, false },
{ "swab", filter_swab, true, true, false },
}
struct filter* filters_stack[64]
static
struct filter_data filters_stack_data[1+elemof(filters_stack)]
static
bpp_t filters_stack_data_buf[2]
static
bool filters_stack_default
static
unsigned int filters_stack_size
static
const char game_genie_str[] = "Enter Game Genie/Hex code: "
static
unsigned int height

224 or 240 (NTSC_VBLANK or PAL_VBLANK)

unsigned int hz

refresh rate

enum ctl_e const id[2]

Controls indices in control[].

struct { ... } info

Messages.

unsigned int is_pal

PAL enabled.

size_t length

remaining length to display

unsigned char* mdpal = NULL
struct bmap mdscr
char message[2048]

message

struct { ... } mouse_motion_release
char const* name

Controller button name.

bool once

If button has been pressed once.

uint8_t palette[256]

palette for 8bpp modes (mdpal)

bool pd_freeze = false

Enable emulation by default.

unsigned int pd_freeze_ref = 0
static
const char* pd_options = "fX:Y:S:G:"
struct { ... } prompt

Prompt.

struct prompt_command prompt_command[]
static
Initial value:
{
{ "quit", prompt_cmd_exit, NULL },
{ "q", prompt_cmd_exit, NULL },
{ "exit", prompt_cmd_exit, NULL },
{ "unload", prompt_cmd_unload, NULL },
{ "close", prompt_cmd_unload, NULL },
{ "unplug", prompt_cmd_unload, NULL },
{ "reset", prompt_cmd_reset, NULL },
{ "ctv_pop", prompt_cmd_filter_pop, NULL },
{ "ctv_none", prompt_cmd_filter_none, NULL },
{ "calibrate", prompt_cmd_calibrate, NULL },
{ "calibrate_js", prompt_cmd_calibrate, NULL },
{ NULL, NULL, NULL }
}

List of commands to auto complete.

const char prompt_str[] = ":"
static
unsigned int rate

samples rate

unsigned int samples

number of samples required by the callback

struct screen screen
static
unsigned long since

since this number of microseconds

unsigned int skip

number of entries to skip in the array

int slot
struct sndinfo sndi
struct { ... } sound

Sound.

struct prompt status

prompt status

int stopped = 0
static

Stopped flag used by pd_stopped()

const char stopped_str[] = "STOPPED."
static

Messages shown whenever events are stopped.

bool twice

If button has been pressed twice.

enum rc_binding_type type

Type of code.

struct { ... } video
unsigned long when[0x100]
const unsigned int width

320