DGen/SDL
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Classes | Macros | 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 <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  cbuf_t
 Circular buffer and related functions. More...
struct  prompt_command
struct  filter
 Filter that works on an output frame. More...
struct  scaling
struct  kb_input_t
 Keyboard input. More...
struct  ctl

Macros

#define HQX_NO_UINT24
 SDL interface.
#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
 stop_events_msg() 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
 stop_events_msg() has been used
#define MESSAGE_LIFE   3000000
 Number of microseconds to sustain messages.
#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 CE(i, s)   { i, s, sizeof(s) }

Enumerations

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_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 release_texture ()
static int init_texture ()
static void update_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.
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.
unsigned long pd_usecs (void)
 Elapsed time in microseconds.
static void stop_events_msg (unsigned int mark, const char *msg,...)
static void rehash_prompt_complete_common ()
static void filters_push (const struct filter **stack, const struct filter *f)
 Add filter to stack.
static void filters_push_once (const struct filter **stack, const struct filter *f)
 Add filter to stack if not already in it.
static void filters_pop (const struct filter **stack)
 Remove last filter from stack.
static void filters_pluck (const struct filter **stack, const struct filter *f)
 Remove all occurences of filter from the stack.
static void filters_empty (const struct filter **stack)
 Empty filters stack.
static void set_swab ()
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 ()
static void texture_init_dlist ()
static uint32_t roundup2 (uint32_t v)
 Round a value up to nearest power of two.
static void rescale_32_1x1 (uint32_t *dst, unsigned int dst_pitch, uint32_t *src, unsigned int src_pitch, unsigned int xsize, unsigned int xscale, unsigned int ysize, unsigned int yscale)
static void rescale_32_any (uint32_t *dst, unsigned int dst_pitch, uint32_t *src, unsigned int src_pitch, unsigned int xsize, unsigned int xscale, unsigned int ysize, unsigned int yscale)
static void rescale_24_1x1 (uint24_t *dst, unsigned int dst_pitch, uint24_t *src, unsigned int src_pitch, unsigned int xsize, unsigned int xscale, unsigned int ysize, unsigned int yscale)
static void rescale_24_any (uint24_t *dst, unsigned int dst_pitch, uint24_t *src, unsigned int src_pitch, unsigned int xsize, unsigned int xscale, unsigned int ysize, unsigned int yscale)
static void rescale_16_1x1 (uint16_t *dst, unsigned int dst_pitch, uint16_t *src, unsigned int src_pitch, unsigned int xsize, unsigned int xscale, unsigned int ysize, unsigned int yscale)
static void rescale_16_any (uint16_t *dst, unsigned int dst_pitch, uint16_t *src, unsigned int src_pitch, unsigned int xsize, unsigned int xscale, unsigned int ysize, unsigned int yscale)
static void rescale_8_1x1 (uint8_t *dst, unsigned int dst_pitch, uint8_t *src, unsigned int src_pitch, unsigned int xsize, unsigned int xscale, unsigned int ysize, unsigned int yscale)
static void rescale_8_any (uint8_t *dst, unsigned int dst_pitch, uint8_t *src, unsigned int src_pitch, unsigned int xsize, unsigned int xscale, unsigned int ysize, unsigned int yscale)
static void rescale_1x1 (bpp_t dst, unsigned int dst_pitch, bpp_t src, unsigned int src_pitch, unsigned int xsize, unsigned int xscale, unsigned int ysize, unsigned int yscale, unsigned int bpp)
static void rescale_any (bpp_t dst, unsigned int dst_pitch, bpp_t src, unsigned int src_pitch, unsigned int xsize, unsigned int xscale, unsigned int ysize, unsigned int yscale, unsigned int bpp)
static void rescale_hqx (bpp_t dst, unsigned int dst_pitch, bpp_t src, unsigned int src_pitch, unsigned int xsize, unsigned int xscale, unsigned int ysize, unsigned int yscale, unsigned int bpp)
static void rescale_scale2x (bpp_t dst, unsigned int dst_pitch, bpp_t src, unsigned int src_pitch, unsigned int xsize, unsigned int xscale, unsigned int ysize, unsigned int yscale, unsigned int bpp)
static void filter_blur_u32 (uint32_t *buf, unsigned int buf_pitch, unsigned int xsize, unsigned int ysize)
static void filter_blur_u24 (uint24_t *buf, unsigned int buf_pitch, unsigned int xsize, unsigned int ysize)
static void filter_blur_u16 (uint16_t *buf, unsigned int buf_pitch, unsigned int xsize, unsigned int ysize)
static void filter_blur_u15 (uint16_t *buf, unsigned int buf_pitch, unsigned int xsize, unsigned int ysize)
static void filter_blur (bpp_t buf, unsigned int buf_pitch, unsigned int xsize, unsigned int ysize, unsigned int bpp)
static void filter_scanline_frame (bpp_t buf, unsigned int buf_pitch, unsigned int xsize, unsigned int ysize, unsigned int bpp, unsigned int frame)
static void filter_scanline (bpp_t buf, unsigned int buf_pitch, unsigned int xsize, unsigned int ysize, unsigned int bpp)
static void filter_interlace (bpp_t buf, unsigned int buf_pitch, unsigned int xsize, unsigned int ysize, unsigned int bpp)
static void filter_swab (bpp_t buf, unsigned int buf_pitch, unsigned int xsize, unsigned int ysize, unsigned int bpp)
static void filter_text_msg (const char *fmt,...)
 Append message to filter_text_str[].
static void filter_text (bpp_t buf, unsigned int buf_pitch, unsigned int xsize, unsigned int ysize, unsigned int bpp)
 Text overlay filter.
static void filter_off (bpp_t buf, unsigned int buf_pitch, unsigned int xsize, unsigned int ysize, unsigned int bpp)
 No-op filter.
static void manage_calibration (bool 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.
void pd_sound_start ()
 Start/stop audio processing.
void pd_sound_pause ()
 Pause sound.
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 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 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 stop_events (md &megad, int gg)
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_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 int manage_bindings (md &md, bool pressed, bool type, intptr_t code)
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

struct {
   unsigned int   width
 texture width
   unsigned int   height
 texture height
   unsigned int   vis_width
 visible width
   unsigned int   vis_height
 visible height
   GLuint   id
 texture identifier
   GLuint   dlist
 display list
   unsigned int   u32:1
 texture is 32-bit
   unsigned int   linear:1
 linear filtering is enabled
   union {
      uint16_t *   u16
      uint32_t *   u32
   }   buf
 16 or 32-bit buffer
texture
 Framebuffer texture.
struct {
   unsigned int   width
 window width
   unsigned int   height
 window height
   unsigned int   bpp
 bits per pixel
   unsigned int   Bpp
 bytes per pixel
   unsigned int   x_offset
 horizontal offset
   unsigned int   y_offset
 vertical offset
   unsigned int   info_height
 message bar height
   bpp_t   buf
 generic pointer to pixel data
   unsigned int   pitch
 number of bytes per line in buf
   SDL_Surface *   surface
 SDL surface.
   unsigned int   want_fullscreen:1
 want fullscreen
   unsigned int   is_fullscreen:1
 fullscreen enabled
   unsigned int   last_video_height
 last video.height value
   unsigned int   want_opengl:1
 want OpenGL
   unsigned int   is_opengl:1
 OpenGL enabled.
   unsigned int   opengl_ok:1
 if textures are initialized
   SDL_Color   color [64]
 SDL colors for 8bpp modes.
screen
struct {
   const unsigned int   width
 320
   unsigned int   height
 224 or 240 (NTSC_VBLANK or PAL_VBLANK)
   unsigned int   x_scale
 scale horizontally
   unsigned int   y_scale
 scale vertically
   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()
bool pd_freeze = false
 Enable emulation by default.
static struct filterfilters_prescale [64]
static struct filterfilters_postscale [64]
static void(* scaling )(bpp_t dst, unsigned int dst_pitch, bpp_t src, unsigned int src_pitch, unsigned int xsize, unsigned int xscale, unsigned int ysize, unsigned int yscale, unsigned int bpp)
static char filter_text_str [2048]
static struct filter filter_text_def = { "text", filter_text }
static struct filter filters_list []
 List of available filters.
static bool calibrating = false
static unsigned int calibrating_controller
 Controller being calibrated.
static struct scaling scaling_list []
static uint16_t kpress [0x100]
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.
   bool   type
 Type of code, false for keysym, true for joypad.
   intptr_t   code
 Temporary keysym or joypad code.
calibration_steps []

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

stop_events_msg() has been used

#define CMD_OK   0x00

Extra commands return values.

command successful

#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 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

stop_events_msg() has been used

#define TEXTURE_16_TYPE   GL_UNSIGNED_SHORT_5_6_5
#define TEXTURE_32_TYPE   GL_UNSIGNED_BYTE

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_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 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 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_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 ( bpp_t  buf,
unsigned int  buf_pitch,
unsigned int  xsize,
unsigned int  ysize,
unsigned int  bpp 
)
static
static void filter_blur_u15 ( uint16_t *  buf,
unsigned int  buf_pitch,
unsigned int  xsize,
unsigned int  ysize 
)
static
static void filter_blur_u16 ( uint16_t *  buf,
unsigned int  buf_pitch,
unsigned int  xsize,
unsigned int  ysize 
)
static
static void filter_blur_u24 ( uint24_t buf,
unsigned int  buf_pitch,
unsigned int  xsize,
unsigned int  ysize 
)
static
static void filter_blur_u32 ( uint32_t *  buf,
unsigned int  buf_pitch,
unsigned int  xsize,
unsigned int  ysize 
)
static
static void filter_interlace ( bpp_t  buf,
unsigned int  buf_pitch,
unsigned int  xsize,
unsigned int  ysize,
unsigned int  bpp 
)
static
static void filter_off ( bpp_t  buf,
unsigned int  buf_pitch,
unsigned int  xsize,
unsigned int  ysize,
unsigned int  bpp 
)
static

No-op filter.

static void filter_scanline ( bpp_t  buf,
unsigned int  buf_pitch,
unsigned int  xsize,
unsigned int  ysize,
unsigned int  bpp 
)
static
static void filter_scanline_frame ( bpp_t  buf,
unsigned int  buf_pitch,
unsigned int  xsize,
unsigned int  ysize,
unsigned int  bpp,
unsigned int  frame 
)
static
static void filter_swab ( bpp_t  buf,
unsigned int  buf_pitch,
unsigned int  xsize,
unsigned int  ysize,
unsigned int  bpp 
)
static
static void filter_text ( bpp_t  buf,
unsigned int  buf_pitch,
unsigned int  xsize,
unsigned int  ysize,
unsigned int  bpp 
)
static

Text overlay filter.

static void filter_text_msg ( const char *  fmt,
  ... 
)
static

Append message to filter_text_str[].

static void filters_empty ( const struct filter **  stack)
static

Empty filters stack.

Parameters:
stackStack of filters.
static void filters_pluck ( const struct filter **  stack,
const struct filter f 
)
static

Remove all occurences of filter from the stack.

Parameters:
stackStack of current filters.
fFilter to remove.
static void filters_pop ( const struct filter **  stack)
static

Remove last filter from stack.

Parameters:
stackStack of filters.
static void filters_push ( const struct filter **  stack,
const struct filter f 
)
static

Add filter to stack.

Parameters:
stackStack of filters.
fFilter to add.
static void filters_push_once ( const struct filter **  stack,
const struct filter f 
)
static

Add filter to stack if not already in it.

Parameters:
stackStack of filters.
fFilter to add.
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 ( )
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,
bool  type,
intptr_t  code 
)
static
static void manage_calibration ( bool  type,
intptr_t  code 
)
static

Handle input during calibration process.

Parameters:
typeType of code (false for keysym, true for joypad).
codekeysym/joypad code to process.
void md_load ( md megad)
void md_save ( md megad)
static void mdscr_splash ( )
static

Display splash screen.

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 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.
void pd_sound_pause ( )

Pause sound.

unsigned int pd_sound_rp ( )

Return samples read/write indices in the buffer.

void pd_sound_start ( )

Start/stop audio processing.

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_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_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 ( )
static
static void rescale_16_1x1 ( uint16_t *  dst,
unsigned int  dst_pitch,
uint16_t *  src,
unsigned int  src_pitch,
unsigned int  xsize,
unsigned int  xscale,
unsigned int  ysize,
unsigned int  yscale 
)
static
static void rescale_16_any ( uint16_t *  dst,
unsigned int  dst_pitch,
uint16_t *  src,
unsigned int  src_pitch,
unsigned int  xsize,
unsigned int  xscale,
unsigned int  ysize,
unsigned int  yscale 
)
static
static void rescale_1x1 ( bpp_t  dst,
unsigned int  dst_pitch,
bpp_t  src,
unsigned int  src_pitch,
unsigned int  xsize,
unsigned int  xscale,
unsigned int  ysize,
unsigned int  yscale,
unsigned int  bpp 
)
static
static void rescale_24_1x1 ( uint24_t dst,
unsigned int  dst_pitch,
uint24_t src,
unsigned int  src_pitch,
unsigned int  xsize,
unsigned int  xscale,
unsigned int  ysize,
unsigned int  yscale 
)
static
static void rescale_24_any ( uint24_t dst,
unsigned int  dst_pitch,
uint24_t src,
unsigned int  src_pitch,
unsigned int  xsize,
unsigned int  xscale,
unsigned int  ysize,
unsigned int  yscale 
)
static
static void rescale_32_1x1 ( uint32_t *  dst,
unsigned int  dst_pitch,
uint32_t *  src,
unsigned int  src_pitch,
unsigned int  xsize,
unsigned int  xscale,
unsigned int  ysize,
unsigned int  yscale 
)
static
static void rescale_32_any ( uint32_t *  dst,
unsigned int  dst_pitch,
uint32_t *  src,
unsigned int  src_pitch,
unsigned int  xsize,
unsigned int  xscale,
unsigned int  ysize,
unsigned int  yscale 
)
static
static void rescale_8_1x1 ( uint8_t *  dst,
unsigned int  dst_pitch,
uint8_t *  src,
unsigned int  src_pitch,
unsigned int  xsize,
unsigned int  xscale,
unsigned int  ysize,
unsigned int  yscale 
)
static
static void rescale_8_any ( uint8_t *  dst,
unsigned int  dst_pitch,
uint8_t *  src,
unsigned int  src_pitch,
unsigned int  xsize,
unsigned int  xscale,
unsigned int  ysize,
unsigned int  yscale 
)
static
static void rescale_any ( bpp_t  dst,
unsigned int  dst_pitch,
bpp_t  src,
unsigned int  src_pitch,
unsigned int  xsize,
unsigned int  xscale,
unsigned int  ysize,
unsigned int  yscale,
unsigned int  bpp 
)
static
static void rescale_hqx ( bpp_t  dst,
unsigned int  dst_pitch,
bpp_t  src,
unsigned int  src_pitch,
unsigned int  xsize,
unsigned int  xscale,
unsigned int  ysize,
unsigned int  yscale,
unsigned int  bpp 
)
static
static void rescale_scale2x ( bpp_t  dst,
unsigned int  dst_pitch,
bpp_t  src,
unsigned int  src_pitch,
unsigned int  xsize,
unsigned int  xscale,
unsigned int  ysize,
unsigned int  yscale,
unsigned int  bpp 
)
static
static uint32_t roundup2 ( uint32_t  v)
static

Round a value up to nearest power of two.

Parameters:
vValue.
Returns:
Rounded value.
static int screen_init ( unsigned int  width,
unsigned int  height 
)
static

Initialize screen.

Parameters:
widthWidth of display.
heightHeight of display.
Returns:
0 on success, nonzero on error.
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,
int  gg 
)
static
static void stop_events_msg ( unsigned int  mark,
const char *  msg,
  ... 
)
static
static void texture_init_dlist ( )
static
static void texture_init_id ( )
static
static void update_texture ( )
static

Variable Documentation

unsigned int bpp

bits per pixel

unsigned int Bpp

bytes per pixel

bpp_t buf

16 or 32-bit buffer

generic pointer to pixel data

bool calibrating = false
static
unsigned int calibrating_controller
static

Controller being calibrated.

struct { ... } calibration_steps[]
cbuf_t cbuf

circular buffer

intptr_t code

Temporary keysym or joypad code.

SDL_Color color[64]

SDL colors for 8bpp modes.

unsigned int common

common length of all entries

char** complete

completion results array

struct ctl control[]
static
unsigned int displayed

whether message is currently displayed

GLuint dlist

display list

struct filter filter_text_def = { "text", filter_text }
static
char filter_text_str[2048]
static
struct filter filters_list[]
static
Initial value:
{
{ "off", filter_off },
{ "blur", filter_blur },
{ "scanline", filter_scanline },
{ "interlace", filter_interlace },
{ "swab", filter_swab },
{ NULL, NULL }
}

List of available filters.

struct filter* filters_postscale[64]
static
struct filter* filters_prescale[64]
static
unsigned int height

texture height

224 or 240 (NTSC_VBLANK or PAL_VBLANK)

window height

unsigned int hz

refresh rate

enum ctl_e const id[2]

texture identifier

Controls indices in control[].

struct { ... } info

Messages.

unsigned int info_height

message bar height

unsigned int is_fullscreen

fullscreen enabled

unsigned int is_opengl

OpenGL enabled.

unsigned int is_pal

PAL enabled.

uint16_t kpress[0x100]
static
unsigned int last_video_height

last video.height value

size_t length

remaining length to display

unsigned int linear

linear filtering is enabled

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

message

char const* name

Controller button name.

bool once

If button has been pressed once.

unsigned int opengl_ok

if textures are initialized

uint8_t palette[256]

palette for 8bpp modes (mdpal)

bool pd_freeze = false

Enable emulation by default.

const char* pd_options = "fX:Y:S:G:"
unsigned int pitch

number of bytes per line in buf

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.

unsigned int rate

samples rate

unsigned int samples

number of samples required by the callback

void(* scaling)(bpp_t dst, unsigned int dst_pitch, bpp_t src, unsigned int src_pitch, unsigned int xsize, unsigned int xscale, unsigned int ysize, unsigned int yscale, unsigned int bpp)
static
struct scaling scaling_list[]
static
Initial value:
{
{ "default", rescale_any },
{ "hqx", rescale_hqx },
{ "scale2x", rescale_scale2x },
{ NULL, NULL }
}
struct { ... } screen
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()

SDL_Surface* surface

SDL surface.

struct { ... } texture

Framebuffer texture.

bool twice

If button has been pressed twice.

bool type

Type of code, false for keysym, true for joypad.

uint16_t* u16
uint32_t* u32

texture is 32-bit

struct { ... } video
unsigned int vis_height

visible height

unsigned int vis_width

visible width

unsigned int want_fullscreen

want fullscreen

unsigned int want_opengl

want OpenGL

const unsigned int width

texture width

320

window width

unsigned int x_offset

horizontal offset

unsigned int x_scale

scale horizontally

unsigned int y_offset

vertical offset

unsigned int y_scale

scale vertically