~fixed VDP bug from last revision

~updated DOS & WIN32 ports to reflect recent changes
This commit is contained in:
ekeeke31 2009-06-02 18:12:31 +00:00
parent 32ac31a997
commit a0fe59e1fc
16 changed files with 210 additions and 158 deletions

View File

@ -1,6 +1,6 @@
/*************************************************************************************** /***************************************************************************************
* Genesis Plus * Genesis Plus
* Backup SRAM support * Backup RAM support
* *
* Copyright (C) 2007, 2008, 2009 Eke-Eke (GCN/Wii port) * Copyright (C) 2007, 2008, 2009 Eke-Eke (GCN/Wii port)
* *

View File

@ -1,6 +1,6 @@
/*************************************************************************************** /***************************************************************************************
* Genesis Plus * Genesis Plus
* Backup SRAM support * Backup RAM support
* *
* Copyright (C) 2007, 2008, 2009 Eke-Eke (GCN/Wii port) * Copyright (C) 2007, 2008, 2009 Eke-Eke (GCN/Wii port)
* *

View File

@ -42,10 +42,6 @@ typedef struct
}clip_t; }clip_t;
/* Function prototypes */ /* Function prototypes */
/*--------------------------------------------------------------------------*/
/* Color update functions */
/*--------------------------------------------------------------------------*/
static void palette_init(void); static void palette_init(void);
static void make_name_lut(void); static void make_name_lut(void);
static uint32 make_lut_bg(uint32 bx, uint32 ax); static uint32 make_lut_bg(uint32 bx, uint32 ax);
@ -542,7 +538,7 @@ void render_line(uint32 line, uint32 overscan)
uint32 x_offset = bitmap.viewport.x; uint32 x_offset = bitmap.viewport.x;
/* display OFF */ /* display OFF */
if (!(reg[0] & 0x01)) return; if (reg[0] & 0x01) return;
/* background color (blanked display or vertical borders) */ /* background color (blanked display or vertical borders) */
if (!(reg[1] & 0x40) || overscan) if (!(reg[1] & 0x40) || overscan)

View File

@ -59,9 +59,6 @@ void SN76489_Init(int PSGClockValue, int SamplingRate)
{ {
SN76489_Context *p = &SN76489; SN76489_Context *p = &SN76489;
/* first unallocate memory */
SN76489_Shutdown();
/* SamplingRate*16 instead of PSGClockValue/16 since division would lose some /* SamplingRate*16 instead of PSGClockValue/16 since division would lose some
precision. blip_alloc doesn't care about the absolute sampling rate, just the precision. blip_alloc doesn't care about the absolute sampling rate, just the
ratio to clock rate. */ ratio to clock rate. */

View File

@ -1,6 +1,6 @@
/* /*
** **
** File: fm_ym2612.h -- header for ym2612.c ** File: ym2612.h -- header for ym2612.c
** software implementation of Yamaha FM sound generator ** software implementation of Yamaha FM sound generator
** **
** Copyright (C) 2001, 2002, 2003 Jarek Burczynski (bujar at mame dot net) ** Copyright (C) 2001, 2002, 2003 Jarek Burczynski (bujar at mame dot net)

View File

@ -70,7 +70,7 @@ void audio_update (int size)
int fm_preamp = config.fm_preamp; int fm_preamp = config.fm_preamp;
int filter = config.filter; int filter = config.filter;
#ifndef DOS #ifdef NGC
int16 *sb = (int16 *) soundbuffer[mixbuffer]; int16 *sb = (int16 *) soundbuffer[mixbuffer];
#endif #endif
@ -148,12 +148,9 @@ void audio_update (int size)
else if (r < -32768) r = -32768; else if (r < -32768) r = -32768;
/* update sound buffer */ /* update sound buffer */
#ifdef DOS #ifndef NGC
snd.buffer[0][i] = l; snd.buffer[0][i] = l;
snd.buffer[1][i] = r; snd.buffer[1][i] = r;
#elif LSB_FIRST
*sb++ = l;
*sb++ = r;
#else #else
*sb++ = r; *sb++ = r;
*sb++ = l; *sb++ = l;
@ -178,10 +175,13 @@ int audio_init (int rate)
snd.sample_rate = rate; snd.sample_rate = rate;
/* Calculate the sound buffer size (for one frame) */ /* Calculate the sound buffer size (for one frame) */
#ifdef NGC
snd.buffer_size = (rate / vdp_rate) + 8; snd.buffer_size = (rate / vdp_rate) + 8;
#ifdef DOS #else
/* output buffers */ snd.buffer_size = (rate / vdp_rate);
/* allocate output buffers */
snd.buffer[0] = (int16 *) malloc(SND_SIZE); snd.buffer[0] = (int16 *) malloc(SND_SIZE);
snd.buffer[1] = (int16 *) malloc(SND_SIZE); snd.buffer[1] = (int16 *) malloc(SND_SIZE);
if (!snd.buffer[0] || !snd.buffer[1]) return (-1); if (!snd.buffer[0] || !snd.buffer[1]) return (-1);
@ -246,6 +246,9 @@ void audio_shutdown(void)
/* SRC */ /* SRC */
if (src_data.data_in) free(src_data.data_in); if (src_data.data_in) free(src_data.data_in);
if (src_data.data_out) free(src_data.data_out); if (src_data.data_out) free(src_data.data_out);
/* sn76489 chip (Blip Buffer allocated memory) */
SN76489_Shutdown();
} }
/**************************************************************** /****************************************************************
@ -288,7 +291,6 @@ void system_shutdown (void)
gen_shutdown (); gen_shutdown ();
vdp_shutdown (); vdp_shutdown ();
render_shutdown (); render_shutdown ();
SN76489_Shutdown();
} }
/**************************************************************** /****************************************************************

View File

@ -15,6 +15,7 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#undef uint8 #undef uint8
#undef uint16 #undef uint16
#undef uint32 #undef uint32

View File

@ -24,7 +24,6 @@ OBJ = obj/z80.o
OBJ += obj/m68kcpu.o \ OBJ += obj/m68kcpu.o \
obj/m68kops.o obj/m68kops.o
OBJ += obj/genesis.o \ OBJ += obj/genesis.o \
obj/vdp.o \ obj/vdp.o \
obj/render.o \ obj/render.o \
@ -37,16 +36,18 @@ OBJ += obj/genesis.o \
obj/state.o obj/state.o
OBJ += obj/sound.o \ OBJ += obj/sound.o \
obj/fm.o \
obj/sn76489.o \ obj/sn76489.o \
obj/ym2612.o obj/ym2612.o
OBJ += obj/samplerate.o \ OBJ += obj/samplerate.o \
obj/src_linear.o \ obj/src_linear.o \
obj/src_sinc.o \ obj/src_sinc.o \
obj/src_zoh.o \ obj/src_zoh.o \
OBJ += obj/blip.o \
OBJ += obj/eq.o \
OBJ += obj/sram.o \ OBJ += obj/sram.o \
obj/eeprom.o \ obj/eeprom.o \
obj/svp.o \ obj/svp.o \

View File

@ -1,8 +1,6 @@
#include "osd.h" #include "osd.h"
#define CONFIG_VERSION "GENPLUS 1.2.1 "
t_option option; t_option option;
t_config config; t_config config;
@ -92,15 +90,20 @@ void set_option_defaults(void)
option.joy_driver = JOY_TYPE_NONE; option.joy_driver = JOY_TYPE_NONE;
} }
void set_config_defaults(void) void set_config_defaults(void)
{ {
int i;
/* sound options */ /* sound options */
config.psg_preamp = 1.5; config.psg_preamp = 150;
config.fm_preamp = 1.0; config.fm_preamp = 100;
config.boost = 1;
config.filter = 0;
config.hq_fm = 1; config.hq_fm = 1;
config.fm_core = 0; config.psgBoostNoise = 0;
config.filter = 1;
config.lg = 1.0;
config.mg = 1.0;
config.hg = 1.0;
/* system options */ /* system options */
config.region_detect = 0; config.region_detect = 0;
@ -108,15 +111,20 @@ void set_config_defaults(void)
config.bios_enabled = 0; config.bios_enabled = 0;
/* display options */ /* display options */
config.aspect = 1;
config.overscan = 1; config.overscan = 1;
config.render = 0; config.render = 1;
/* controllers options */ /* controllers options */
config.gun_cursor = 1; input.system[0] = SYSTEM_GAMEPAD;
input.system[1] = SYSTEM_GAMEPAD;
config.gun_cursor[0] = 1;
config.gun_cursor[1] = 1;
config.invert_mouse = 0; config.invert_mouse = 0;
for (i=0;i<MAX_INPUTS;i++)
config.input[i].padtype = DEVICE_3BUTTON;
} }
void print_options(void) void print_options(void)
{ {
printf(" -vdriver <s> \t Select video driver (auto)\n"); printf(" -vdriver <s> \t Select video driver (auto)\n");

View File

@ -54,20 +54,27 @@ typedef struct
****************************************************************************/ ****************************************************************************/
typedef struct typedef struct
{ {
double psg_preamp; uint8 padtype;
double fm_preamp; } t_input_c;
uint8 boost;
uint8 filter; typedef struct
{
uint8 hq_fm; uint8 hq_fm;
uint8 fm_core; uint8 psgBoostNoise;
int32 psg_preamp;
int32 fm_preamp;
uint8 filter;
float lg;
float mg;
float hg;
uint8 region_detect; uint8 region_detect;
uint8 force_dtack; uint8 force_dtack;
uint8 bios_enabled; uint8 bios_enabled;
uint8 tv_mode;
uint8 aspect;
uint8 overscan; uint8 overscan;
uint8 render; uint8 render;
uint8 gun_cursor; uint8 ntsc;
t_input_c input[MAX_INPUTS];
uint8 gun_cursor[2];
uint8 invert_mouse; uint8 invert_mouse;
} t_config; } t_config;

View File

@ -22,7 +22,7 @@ volatile int old_tick_count = 0;
volatile int skip = 0; volatile int skip = 0;
int quit = 0; int quit = 0;
unsigned char buf[0x24000]; unsigned char buf[STATE_SIZE];
uint8 log_error = 1; uint8 log_error = 1;
uint8 debug_on = 0; uint8 debug_on = 0;
@ -100,8 +100,6 @@ int main (int argc, char *argv[])
/* default config */ /* default config */
do_config("genplus.cfg"); do_config("genplus.cfg");
set_config_defaults(); set_config_defaults();
input.system[0] = SYSTEM_GAMEPAD;
input.system[1] = SYSTEM_GAMEPAD;
/* initialize emulation */ /* initialize emulation */
system_init(); system_init();
@ -131,8 +129,10 @@ int main (int argc, char *argv[])
} }
else else
{ {
system_frame(1,reset_line); system_frame(1);
} }
audio_update(snd.buffer_size);
if(option.sound) dos_update_audio(); if(option.sound) dos_update_audio();
} }
@ -345,7 +345,7 @@ void dos_update_input(void)
f = fopen("game.gpz","r+b"); f = fopen("game.gpz","r+b");
if (f) if (f)
{ {
fread(&buf, 0x23000, 1, f); fread(&buf, STATE_SIZE, 1, f);
state_load(buf); state_load(buf);
fclose(f); fclose(f);
} }
@ -357,7 +357,7 @@ void dos_update_input(void)
if (f) if (f)
{ {
state_save(buf); state_save(buf);
fwrite(&buf, 0x23000, 1, f); fwrite(&buf, STATE_SIZE, 1, f);
fclose(f); fclose(f);
} }
} }
@ -368,8 +368,14 @@ void dos_update_input(void)
/* reinitialize timings */ /* reinitialize timings */
system_init (); system_init ();
audio_init(option.sndrate); unsigned char *temp = malloc(YM2612GetContextSize());
fm_restore(); if (temp) memcpy(temp, YM2612GetContextPtr(), YM2612GetContextSize());
audio_init(48000);
if (temp)
{
YM2612Restore(temp);
free(temp);
}
/* reinitialize HVC tables */ /* reinitialize HVC tables */
vctab = (vdp_pal) ? ((reg[1] & 8) ? vc_pal_240 : vc_pal_224) : vc_ntsc_224; vctab = (vdp_pal) ? ((reg[1] & 8) ? vc_pal_240 : vc_pal_224) : vc_ntsc_224;
@ -378,7 +384,6 @@ void dos_update_input(void)
/* reinitialize overscan area */ /* reinitialize overscan area */
bitmap.viewport.x = config.overscan ? 14 : 0; bitmap.viewport.x = config.overscan ? 14 : 0;
bitmap.viewport.y = config.overscan ? (((reg[1] & 8) ? 0 : 8) + (vdp_pal ? 24 : 0)) : 0; bitmap.viewport.y = config.overscan ? (((reg[1] & 8) ? 0 : 8) + (vdp_pal ? 24 : 0)) : 0;
bitmap.viewport.changed = 1;
} }
if(check_key(KEY_F10)) set_softreset(); if(check_key(KEY_F10)) set_softreset();

View File

@ -34,7 +34,6 @@ OBJECTS += obj/genesis.o \
obj/state.o obj/state.o
OBJECTS += obj/sound.o \ OBJECTS += obj/sound.o \
obj/fm.o \
obj/sn76489.o \ obj/sn76489.o \
obj/ym2612.o obj/ym2612.o
@ -43,6 +42,11 @@ OBJECTS += obj/samplerate.o \
obj/src_sinc.o \ obj/src_sinc.o \
obj/src_zoh.o \ obj/src_zoh.o \
OBJECTS += obj/blip.o \
OBJECTS += obj/eq.o \
OBJECTS += obj/filters.o \
OBJECTS += obj/sram.o \ OBJECTS += obj/sram.o \
obj/eeprom.o \ obj/eeprom.o \

View File

@ -6,12 +6,17 @@ t_config config;
void set_config_defaults(void) void set_config_defaults(void)
{ {
int i;
/* sound options */ /* sound options */
config.psg_preamp = 150; config.psg_preamp = 150;
config.fm_preamp = 100; config.fm_preamp = 100;
config.boost = 1;
config.filter = 1;
config.hq_fm = 1; config.hq_fm = 1;
config.psgBoostNoise = 0;
config.filter = 1;
config.lg = 1.0;
config.mg = 1.0;
config.hg = 1.0;
/* system options */ /* system options */
config.region_detect = 0; config.region_detect = 0;
@ -19,13 +24,16 @@ void set_config_defaults(void)
config.bios_enabled = 0; config.bios_enabled = 0;
/* display options */ /* display options */
config.aspect = 1;
config.overscan = 1; config.overscan = 1;
config.render = 1; config.render = 1;
config.ntsc = 0;
/* controllers options */ /* controllers options */
config.gun_cursor = 1; input.system[0] = SYSTEM_GAMEPAD;
input.system[1] = SYSTEM_GAMEPAD;
config.gun_cursor[0] = 1;
config.gun_cursor[1] = 1;
config.invert_mouse = 0; config.invert_mouse = 0;
for (i=0;i<MAX_INPUTS;i++)
config.input[i].padtype = DEVICE_3BUTTON;
} }

View File

@ -8,21 +8,27 @@
****************************************************************************/ ****************************************************************************/
typedef struct typedef struct
{ {
double psg_preamp; uint8 padtype;
double fm_preamp; } t_input_c;
uint8 boost;
uint8 filter; typedef struct
{
uint8 hq_fm; uint8 hq_fm;
uint8 fm_core; uint8 psgBoostNoise;
int32 psg_preamp;
int32 fm_preamp;
uint8 filter;
float lg;
float mg;
float hg;
uint8 region_detect; uint8 region_detect;
uint8 force_dtack; uint8 force_dtack;
uint8 bios_enabled; uint8 bios_enabled;
uint8 tv_mode;
uint8 aspect;
uint8 overscan; uint8 overscan;
uint8 render; uint8 render;
uint8 ntsc; uint8 ntsc;
uint8 gun_cursor; t_input_c input[MAX_INPUTS];
uint8 gun_cursor[2];
uint8 invert_mouse; uint8 invert_mouse;
} t_config; } t_config;

View File

@ -6,6 +6,7 @@
#include "md_ntsc.h" #include "md_ntsc.h"
#define SOUND_FREQUENCY 48000 #define SOUND_FREQUENCY 48000
#define SOUND_SAMPLES_SIZE 2048
int timer_count = 0; int timer_count = 0;
int old_timer_count = 0; int old_timer_count = 0;
@ -16,11 +17,7 @@ int joynum = 0;
int update_input(void); int update_input(void);
uint8 *keystate; uint8 *keystate;
uint8 buf[0x24000]; uint8 buf[STATE_SIZE];
uint8 soundbuffer[16][3840];
int mixbuffer = 0;
int playbuffer = 0;
uint8 log_error = 0; uint8 log_error = 0;
uint8 debug_on = 0; uint8 debug_on = 0;
@ -28,56 +25,95 @@ uint8 turbo_mode = 1;
uint8 use_sound = 0; uint8 use_sound = 0;
uint8 fullscreen = 0; uint8 fullscreen = 0;
int audio_len; /* sound */
struct {
char* current_pos;
char* buffer;
int current_emulated_samples;
} sdl_sound;
static void sdl_sound_callback(void *userdata, Uint8 *stream, int len) static void sdl_sound_callback(void *userdata, Uint8 *stream, int len)
{ {
audio_len = len; if(sdl_sound.current_emulated_samples < len) {
memcpy(stream, soundbuffer[playbuffer], len); memset(stream, 0, len);
}
/* increment soundbuffers index */ else {
playbuffer++; memcpy(stream, sdl_sound.buffer, len);
playbuffer &= 0xf; /* loop to compensate desync */
if (playbuffer == mixbuffer) do {
{ sdl_sound.current_emulated_samples -= len;
playbuffer--; } while(sdl_sound.current_emulated_samples > 2 * len);
if ( playbuffer < 0 ) playbuffer = 15; memcpy(sdl_sound.buffer,
sdl_sound.current_pos - sdl_sound.current_emulated_samples,
sdl_sound.current_emulated_samples);
sdl_sound.current_pos = sdl_sound.buffer + sdl_sound.current_emulated_samples;
} }
} }
static int sdl_sound_init() static int sdl_sound_init()
{ {
SDL_AudioSpec audio; int n;
SDL_AudioSpec as_desired, as_obtained;
if(SDL_Init(SDL_INIT_AUDIO) < 0) if(SDL_Init(SDL_INIT_AUDIO) < 0) {
{ printf("ERROR: %s.\n", SDL_GetError());
char caption[256];
sprintf(caption, "SDL audio can't initialize");
MessageBox(NULL, caption, "Error", 0);
return 0; return 0;
} }
audio.freq = SOUND_FREQUENCY; as_desired.freq = SOUND_FREQUENCY;
audio.format = AUDIO_S16LSB; as_desired.format = AUDIO_S16LSB;
audio.channels = 2; as_desired.channels = 2;
audio.samples = snd.buffer_size; as_desired.samples = SOUND_SAMPLES_SIZE;
audio.callback = sdl_sound_callback; as_desired.callback = sdl_sound_callback;
if(SDL_OpenAudio(&audio, NULL) == -1) if(SDL_OpenAudio(&as_desired, &as_obtained) == -1) {
{ printf("ERROR: can't open audio: %s.\n", SDL_GetError());
char caption[256];
sprintf(caption, "SDL can't open audio");
MessageBox(NULL, caption, "Error", 0);
return 0; return 0;
} }
memset(soundbuffer, 0, 16 * 3840); if(as_desired.samples != as_obtained.samples) {
mixbuffer = 0; printf("ERROR: soundcard driver does not accept specified samples size.\n");
playbuffer = 0; return 0;
}
sdl_sound.current_emulated_samples = 0;
n = SOUND_SAMPLES_SIZE * 2 * sizeof(short) * 11;
sdl_sound.buffer = (char*)malloc(n);
if(!sdl_sound.buffer) {
printf("ERROR: can't allocate memory for sound.\n");
return 0;
}
memset(sdl_sound.buffer, 0, n);
sdl_sound.current_pos = sdl_sound.buffer;
return 1; return 1;
} }
static void sdl_sound_update()
{
int i;
short* p;
SDL_LockAudio();
p = (short*)sdl_sound.current_pos;
for(i = 0; i < snd.buffer_size; ++i) {
*p = snd.buffer[0][i];
++p;
*p = snd.buffer[1][i];
++p;
}
sdl_sound.current_pos = (char*)p;
sdl_sound.current_emulated_samples += snd.buffer_size * 2 * sizeof(short);
SDL_UnlockAudio();
}
static void sdl_sound_close()
{
SDL_PauseAudio(1);
SDL_CloseAudio();
free(sdl_sound.buffer);
}
static SDL_Rect rect; static SDL_Rect rect;
static SDL_Surface* screen; static SDL_Surface* screen;
static SDL_Surface* surface; static SDL_Surface* surface;
@ -97,7 +133,7 @@ Uint32 fps_callback(Uint32 interval)
if (region_code == REGION_USA) sprintf(region,"USA"); if (region_code == REGION_USA) sprintf(region,"USA");
else if (region_code == REGION_EUROPE) sprintf(region,"EUR"); else if (region_code == REGION_EUROPE) sprintf(region,"EUR");
else sprintf(region,"JAP"); else sprintf(region,"JAP");
sprintf(caption, "Genesis Plus/SDL - %s (%s) - %d fps", rominfo.international, region, fps); sprintf(caption, "Genesis Plus/SDL - %s (%s) - %d fps - xoffset = %d", rominfo.international, region, fps,input.x_offset);
SDL_WM_SetCaption(caption, NULL); SDL_WM_SetCaption(caption, NULL);
frame_count = 0; frame_count = 0;
@ -105,15 +141,6 @@ Uint32 fps_callback(Uint32 interval)
return 1000/vdp_rate; return 1000/vdp_rate;
} }
void lock_pixels( void )
{
if ( SDL_LockSurface( surface ) < 0 )
MessageBox(NULL, "Couldn't lock surface", "Error", 0);
SDL_FillRect( surface, 0, 0 );
output_pitch = surface->pitch;
output_pixels = (unsigned char*) surface->pixels;
}
void display_output( void ) void display_output( void )
{ {
SDL_Rect dest; SDL_Rect dest;
@ -121,7 +148,6 @@ void display_output( void )
dest.h=rect.h; dest.h=rect.h;
dest.x=(640-rect.w)/2; dest.x=(640-rect.w)/2;
dest.y=(480-rect.h)/2; dest.y=(480-rect.h)/2;
//SDL_UnlockSurface( surface );
if ( SDL_BlitSurface( surface, &rect, screen, &dest ) < 0 || SDL_Flip( screen ) < 0 ) if ( SDL_BlitSurface( surface, &rect, screen, &dest ) < 0 || SDL_Flip( screen ) < 0 )
MessageBox(NULL, "SDL blit failed", "Error", 0); MessageBox(NULL, "SDL blit failed", "Error", 0);
} }
@ -136,8 +162,6 @@ int main (int argc, char **argv)
md_ntsc_setup_t md_setup; md_ntsc_setup_t md_setup;
sms_ntsc_setup_t sms_setup; sms_ntsc_setup_t sms_setup;
SDL_Event event;
error_init(); error_init();
/* Print help if no game specified */ /* Print help if no game specified */
@ -149,9 +173,12 @@ int main (int argc, char **argv)
exit(1); exit(1);
} }
/* set default config */
set_config_defaults();
/* Load game */ /* Load game */
cart_rom = malloc(0xA00000); cart_rom = malloc(10*1024*1024);
memset(cart_rom, 0, 0xA00000); memset(cart_rom, 0, 10*1024*1024);
if(!load_rom(argv[1])) if(!load_rom(argv[1]))
{ {
char caption[256]; char caption[256];
@ -192,11 +219,6 @@ int main (int argc, char **argv)
bitmap.viewport.x = 0; bitmap.viewport.x = 0;
bitmap.viewport.y = 0; bitmap.viewport.y = 0;
/* set default config */
set_config_defaults();
input.system[0] = SYSTEM_GAMEPAD;
input.system[1] = SYSTEM_GAMEPAD;
/* load BIOS */ /* load BIOS */
memset(bios_rom, 0, sizeof(bios_rom)); memset(bios_rom, 0, sizeof(bios_rom));
FILE *f = fopen("./BIOS.bin", "rb"); FILE *f = fopen("./BIOS.bin", "rb");
@ -238,7 +260,8 @@ int main (int argc, char **argv)
while(running) while(running)
{ {
while (SDL_PollEvent(&event)) SDL_Event event;
if (SDL_PollEvent(&event))
{ {
switch(event.type) switch(event.type)
{ {
@ -246,14 +269,6 @@ int main (int argc, char **argv)
running = 0; running = 0;
break; break;
case SDL_ACTIVEEVENT: /* Window focus changed or was minimized */
if(event.active.state & (SDL_APPINPUTFOCUS | SDL_APPACTIVE))
{
paused = !event.active.gain;
if (use_sound) SDL_PauseAudio(paused);
}
break;
case SDL_KEYDOWN: /* user options */ case SDL_KEYDOWN: /* user options */
sym = event.key.keysym.sym; sym = event.key.keysym.sym;
@ -283,7 +298,7 @@ int main (int argc, char **argv)
f = fopen("game.gpz","r+b"); f = fopen("game.gpz","r+b");
if (f) if (f)
{ {
fread(&buf, 0x23000, 1, f); fread(&buf, STATE_SIZE, 1, f);
state_load(buf); state_load(buf);
fclose(f); fclose(f);
} }
@ -294,7 +309,7 @@ int main (int argc, char **argv)
if (f) if (f)
{ {
state_save(buf); state_save(buf);
fwrite(&buf, 0x23000, 1, f); fwrite(&buf, STATE_SIZE, 1, f);
fclose(f); fclose(f);
} }
} }
@ -304,8 +319,14 @@ int main (int argc, char **argv)
/* reinitialize timings */ /* reinitialize timings */
system_init (); system_init ();
audio_init(SOUND_FREQUENCY); unsigned char *temp = malloc(YM2612GetContextSize());
fm_restore(); if (temp) memcpy(temp, YM2612GetContextPtr(), YM2612GetContextSize());
audio_init(48000);
if (temp)
{
YM2612Restore(temp);
free(temp);
}
/* reinitialize HVC tables */ /* reinitialize HVC tables */
vctab = (vdp_pal) ? ((reg[1] & 8) ? vc_pal_240 : vc_pal_224) : vc_ntsc_224; vctab = (vdp_pal) ? ((reg[1] & 8) ? vc_pal_240 : vc_pal_224) : vc_ntsc_224;
@ -314,7 +335,6 @@ int main (int argc, char **argv)
/* reinitialize overscan area */ /* reinitialize overscan area */
bitmap.viewport.x = config.overscan ? 14 : 0; bitmap.viewport.x = config.overscan ? 14 : 0;
bitmap.viewport.y = config.overscan ? (((reg[1] & 8) ? 0 : 8) + (vdp_pal ? 24 : 0)) : 0; bitmap.viewport.y = config.overscan ? (((reg[1] & 8) ? 0 : 8) + (vdp_pal ? 24 : 0)) : 0;
bitmap.viewport.changed = 1;
} }
else if(sym == SDLK_F10) set_softreset(); else if(sym == SDLK_F10) set_softreset();
else if(sym == SDLK_F11) else if(sym == SDLK_F11)
@ -331,7 +351,7 @@ int main (int argc, char **argv)
else if(sym == SDLK_F12) else if(sym == SDLK_F12)
{ {
config.overscan ^= 1; config.overscan ^= 1;
bitmap.viewport.x = config.overscan ? 14 : 0; bitmap.viewport.x = config.overscan ? ((reg[12] & 1) ? 16 : 12) : 0;
bitmap.viewport.y = config.overscan ? (((reg[1] & 8) ? 0 : 8) + (vdp_pal ? 24 : 0)) : 0; bitmap.viewport.y = config.overscan ? (((reg[1] & 8) ? 0 : 8) + (vdp_pal ? 24 : 0)) : 0;
bitmap.viewport.changed = 1; bitmap.viewport.changed = 1;
} }
@ -356,14 +376,17 @@ int main (int argc, char **argv)
/* Delay */ /* Delay */
while (!frameticker && !turbo_mode) SDL_Delay(0); while (!frameticker && !turbo_mode) SDL_Delay(0);
//SDL_FillRect( surface, 0, 0 );
system_frame (0); system_frame (0);
frame_count++; frame_count++;
} }
update_input();
frameticker--; frameticker--;
/* Sound Update */
audio_update(snd.buffer_size);
if (use_sound) sdl_sound_update();
/* Video update */
if(bitmap.viewport.changed) if(bitmap.viewport.changed)
{ {
bitmap.viewport.changed = 0; bitmap.viewport.changed = 0;
@ -408,8 +431,7 @@ int main (int argc, char **argv)
fclose(f); fclose(f);
} }
SDL_PauseAudio(1); if (use_sound) sdl_sound_close();
SDL_CloseAudio();
SDL_FreeSurface(surface); SDL_FreeSurface(surface);
SDL_FreeSurface(screen); SDL_FreeSurface(screen);
SDL_Quit(); SDL_Quit();

View File

@ -4,12 +4,7 @@
#define MAX_INPUTS 8 #define MAX_INPUTS 8
extern uint8 debug_on; extern uint8 debug_on;
extern uint8 log_error; extern uint8 log_error;
extern int frame_count;
extern uint8 soundbuffer[16][3840];
extern int mixbuffer;
#endif /* _MAIN_H_ */ #endif /* _MAIN_H_ */