mirror of
https://github.com/ekeeke/Genesis-Plus-GX.git
synced 2024-11-04 18:05:06 +01:00
~fixed VDP bug from last revision
~updated DOS & WIN32 ports to reflect recent changes
This commit is contained in:
parent
32ac31a997
commit
a0fe59e1fc
@ -1,6 +1,6 @@
|
||||
/***************************************************************************************
|
||||
* Genesis Plus
|
||||
* Backup SRAM support
|
||||
* Backup RAM support
|
||||
*
|
||||
* Copyright (C) 2007, 2008, 2009 Eke-Eke (GCN/Wii port)
|
||||
*
|
||||
|
@ -1,6 +1,6 @@
|
||||
/***************************************************************************************
|
||||
* Genesis Plus
|
||||
* Backup SRAM support
|
||||
* Backup RAM support
|
||||
*
|
||||
* Copyright (C) 2007, 2008, 2009 Eke-Eke (GCN/Wii port)
|
||||
*
|
||||
|
@ -42,10 +42,6 @@ typedef struct
|
||||
}clip_t;
|
||||
|
||||
/* Function prototypes */
|
||||
/*--------------------------------------------------------------------------*/
|
||||
/* Color update functions */
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
static void palette_init(void);
|
||||
static void make_name_lut(void);
|
||||
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;
|
||||
|
||||
/* display OFF */
|
||||
if (!(reg[0] & 0x01)) return;
|
||||
if (reg[0] & 0x01) return;
|
||||
|
||||
/* background color (blanked display or vertical borders) */
|
||||
if (!(reg[1] & 0x40) || overscan)
|
||||
|
@ -59,9 +59,6 @@ void SN76489_Init(int PSGClockValue, int SamplingRate)
|
||||
{
|
||||
SN76489_Context *p = &SN76489;
|
||||
|
||||
/* first unallocate memory */
|
||||
SN76489_Shutdown();
|
||||
|
||||
/* SamplingRate*16 instead of PSGClockValue/16 since division would lose some
|
||||
precision. blip_alloc doesn't care about the absolute sampling rate, just the
|
||||
ratio to clock rate. */
|
||||
|
@ -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
|
||||
**
|
||||
** Copyright (C) 2001, 2002, 2003 Jarek Burczynski (bujar at mame dot net)
|
||||
|
@ -70,7 +70,7 @@ void audio_update (int size)
|
||||
int fm_preamp = config.fm_preamp;
|
||||
int filter = config.filter;
|
||||
|
||||
#ifndef DOS
|
||||
#ifdef NGC
|
||||
int16 *sb = (int16 *) soundbuffer[mixbuffer];
|
||||
#endif
|
||||
|
||||
@ -148,12 +148,9 @@ void audio_update (int size)
|
||||
else if (r < -32768) r = -32768;
|
||||
|
||||
/* update sound buffer */
|
||||
#ifdef DOS
|
||||
#ifndef NGC
|
||||
snd.buffer[0][i] = l;
|
||||
snd.buffer[1][i] = r;
|
||||
#elif LSB_FIRST
|
||||
*sb++ = l;
|
||||
*sb++ = r;
|
||||
#else
|
||||
*sb++ = r;
|
||||
*sb++ = l;
|
||||
@ -178,10 +175,13 @@ int audio_init (int rate)
|
||||
snd.sample_rate = rate;
|
||||
|
||||
/* Calculate the sound buffer size (for one frame) */
|
||||
#ifdef NGC
|
||||
snd.buffer_size = (rate / vdp_rate) + 8;
|
||||
|
||||
#ifdef DOS
|
||||
/* output buffers */
|
||||
#else
|
||||
snd.buffer_size = (rate / vdp_rate);
|
||||
|
||||
/* allocate output buffers */
|
||||
snd.buffer[0] = (int16 *) malloc(SND_SIZE);
|
||||
snd.buffer[1] = (int16 *) malloc(SND_SIZE);
|
||||
if (!snd.buffer[0] || !snd.buffer[1]) return (-1);
|
||||
@ -243,9 +243,12 @@ void audio_shutdown(void)
|
||||
if (snd.fm.buffer[1]) free(snd.fm.buffer[1]);
|
||||
if (snd.psg.buffer) free(snd.psg.buffer);
|
||||
|
||||
/* SRC*/
|
||||
/* SRC */
|
||||
if (src_data.data_in) free(src_data.data_in);
|
||||
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 ();
|
||||
vdp_shutdown ();
|
||||
render_shutdown ();
|
||||
SN76489_Shutdown();
|
||||
}
|
||||
|
||||
/****************************************************************
|
||||
|
@ -15,6 +15,7 @@
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#undef uint8
|
||||
#undef uint16
|
||||
#undef uint32
|
||||
|
@ -24,7 +24,6 @@ OBJ = obj/z80.o
|
||||
OBJ += obj/m68kcpu.o \
|
||||
obj/m68kops.o
|
||||
|
||||
|
||||
OBJ += obj/genesis.o \
|
||||
obj/vdp.o \
|
||||
obj/render.o \
|
||||
@ -35,18 +34,20 @@ OBJ += obj/genesis.o \
|
||||
obj/memz80.o \
|
||||
obj/membnk.o \
|
||||
obj/state.o
|
||||
|
||||
|
||||
OBJ += obj/sound.o \
|
||||
obj/fm.o \
|
||||
obj/sn76489.o \
|
||||
obj/ym2612.o
|
||||
|
||||
|
||||
OBJ += obj/samplerate.o \
|
||||
obj/src_linear.o \
|
||||
obj/src_sinc.o \
|
||||
obj/src_zoh.o \
|
||||
|
||||
OBJ += obj/blip.o \
|
||||
|
||||
OBJ += obj/eq.o \
|
||||
|
||||
OBJ += obj/sram.o \
|
||||
obj/eeprom.o \
|
||||
obj/svp.o \
|
||||
|
@ -1,8 +1,6 @@
|
||||
|
||||
#include "osd.h"
|
||||
|
||||
#define CONFIG_VERSION "GENPLUS 1.2.1 "
|
||||
|
||||
t_option option;
|
||||
t_config config;
|
||||
|
||||
@ -92,15 +90,20 @@ void set_option_defaults(void)
|
||||
option.joy_driver = JOY_TYPE_NONE;
|
||||
}
|
||||
|
||||
|
||||
void set_config_defaults(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* sound options */
|
||||
config.psg_preamp = 1.5;
|
||||
config.fm_preamp = 1.0;
|
||||
config.boost = 1;
|
||||
config.filter = 0;
|
||||
config.hq_fm = 1;
|
||||
config.fm_core = 0;
|
||||
config.psg_preamp = 150;
|
||||
config.fm_preamp = 100;
|
||||
config.hq_fm = 1;
|
||||
config.psgBoostNoise = 0;
|
||||
config.filter = 1;
|
||||
config.lg = 1.0;
|
||||
config.mg = 1.0;
|
||||
config.hg = 1.0;
|
||||
|
||||
/* system options */
|
||||
config.region_detect = 0;
|
||||
@ -108,15 +111,20 @@ void set_config_defaults(void)
|
||||
config.bios_enabled = 0;
|
||||
|
||||
/* display options */
|
||||
config.aspect = 1;
|
||||
config.overscan = 1;
|
||||
config.render = 0;
|
||||
config.render = 1;
|
||||
|
||||
/* controllers options */
|
||||
config.gun_cursor = 1;
|
||||
config.invert_mouse = 0;
|
||||
input.system[0] = SYSTEM_GAMEPAD;
|
||||
input.system[1] = SYSTEM_GAMEPAD;
|
||||
config.gun_cursor[0] = 1;
|
||||
config.gun_cursor[1] = 1;
|
||||
config.invert_mouse = 0;
|
||||
for (i=0;i<MAX_INPUTS;i++)
|
||||
config.input[i].padtype = DEVICE_3BUTTON;
|
||||
}
|
||||
|
||||
|
||||
void print_options(void)
|
||||
{
|
||||
printf(" -vdriver <s> \t Select video driver (auto)\n");
|
||||
|
@ -54,20 +54,27 @@ typedef struct
|
||||
****************************************************************************/
|
||||
typedef struct
|
||||
{
|
||||
double psg_preamp;
|
||||
double fm_preamp;
|
||||
uint8 boost;
|
||||
uint8 filter;
|
||||
uint8 padtype;
|
||||
} t_input_c;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
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 force_dtack;
|
||||
uint8 bios_enabled;
|
||||
uint8 tv_mode;
|
||||
uint8 aspect;
|
||||
uint8 overscan;
|
||||
uint8 render;
|
||||
uint8 gun_cursor;
|
||||
uint8 ntsc;
|
||||
t_input_c input[MAX_INPUTS];
|
||||
uint8 gun_cursor[2];
|
||||
uint8 invert_mouse;
|
||||
} t_config;
|
||||
|
||||
|
@ -22,7 +22,7 @@ volatile int old_tick_count = 0;
|
||||
volatile int skip = 0;
|
||||
|
||||
int quit = 0;
|
||||
unsigned char buf[0x24000];
|
||||
unsigned char buf[STATE_SIZE];
|
||||
|
||||
uint8 log_error = 1;
|
||||
uint8 debug_on = 0;
|
||||
@ -100,8 +100,6 @@ int main (int argc, char *argv[])
|
||||
/* default config */
|
||||
do_config("genplus.cfg");
|
||||
set_config_defaults();
|
||||
input.system[0] = SYSTEM_GAMEPAD;
|
||||
input.system[1] = SYSTEM_GAMEPAD;
|
||||
|
||||
/* initialize emulation */
|
||||
system_init();
|
||||
@ -131,8 +129,10 @@ int main (int argc, char *argv[])
|
||||
}
|
||||
else
|
||||
{
|
||||
system_frame(1,reset_line);
|
||||
system_frame(1);
|
||||
}
|
||||
|
||||
audio_update(snd.buffer_size);
|
||||
if(option.sound) dos_update_audio();
|
||||
}
|
||||
|
||||
@ -345,7 +345,7 @@ void dos_update_input(void)
|
||||
f = fopen("game.gpz","r+b");
|
||||
if (f)
|
||||
{
|
||||
fread(&buf, 0x23000, 1, f);
|
||||
fread(&buf, STATE_SIZE, 1, f);
|
||||
state_load(buf);
|
||||
fclose(f);
|
||||
}
|
||||
@ -357,7 +357,7 @@ void dos_update_input(void)
|
||||
if (f)
|
||||
{
|
||||
state_save(buf);
|
||||
fwrite(&buf, 0x23000, 1, f);
|
||||
fwrite(&buf, STATE_SIZE, 1, f);
|
||||
fclose(f);
|
||||
}
|
||||
}
|
||||
@ -368,8 +368,14 @@ void dos_update_input(void)
|
||||
|
||||
/* reinitialize timings */
|
||||
system_init ();
|
||||
audio_init(option.sndrate);
|
||||
fm_restore();
|
||||
unsigned char *temp = malloc(YM2612GetContextSize());
|
||||
if (temp) memcpy(temp, YM2612GetContextPtr(), YM2612GetContextSize());
|
||||
audio_init(48000);
|
||||
if (temp)
|
||||
{
|
||||
YM2612Restore(temp);
|
||||
free(temp);
|
||||
}
|
||||
|
||||
/* reinitialize HVC tables */
|
||||
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 */
|
||||
bitmap.viewport.x = config.overscan ? 14 : 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();
|
||||
|
@ -34,7 +34,6 @@ OBJECTS += obj/genesis.o \
|
||||
obj/state.o
|
||||
|
||||
OBJECTS += obj/sound.o \
|
||||
obj/fm.o \
|
||||
obj/sn76489.o \
|
||||
obj/ym2612.o
|
||||
|
||||
@ -43,6 +42,11 @@ OBJECTS += obj/samplerate.o \
|
||||
obj/src_sinc.o \
|
||||
obj/src_zoh.o \
|
||||
|
||||
OBJECTS += obj/blip.o \
|
||||
|
||||
OBJECTS += obj/eq.o \
|
||||
|
||||
OBJECTS += obj/filters.o \
|
||||
|
||||
OBJECTS += obj/sram.o \
|
||||
obj/eeprom.o \
|
||||
|
@ -6,12 +6,17 @@ t_config config;
|
||||
|
||||
void set_config_defaults(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* sound options */
|
||||
config.psg_preamp = 150;
|
||||
config.fm_preamp = 100;
|
||||
config.boost = 1;
|
||||
config.filter = 1;
|
||||
config.hq_fm = 1;
|
||||
config.psg_preamp = 150;
|
||||
config.fm_preamp = 100;
|
||||
config.hq_fm = 1;
|
||||
config.psgBoostNoise = 0;
|
||||
config.filter = 1;
|
||||
config.lg = 1.0;
|
||||
config.mg = 1.0;
|
||||
config.hg = 1.0;
|
||||
|
||||
/* system options */
|
||||
config.region_detect = 0;
|
||||
@ -19,13 +24,16 @@ void set_config_defaults(void)
|
||||
config.bios_enabled = 0;
|
||||
|
||||
/* display options */
|
||||
config.aspect = 1;
|
||||
config.overscan = 1;
|
||||
config.render = 1;
|
||||
config.ntsc = 0;
|
||||
|
||||
/* controllers options */
|
||||
config.gun_cursor = 1;
|
||||
config.invert_mouse = 0;
|
||||
input.system[0] = SYSTEM_GAMEPAD;
|
||||
input.system[1] = SYSTEM_GAMEPAD;
|
||||
config.gun_cursor[0] = 1;
|
||||
config.gun_cursor[1] = 1;
|
||||
config.invert_mouse = 0;
|
||||
for (i=0;i<MAX_INPUTS;i++)
|
||||
config.input[i].padtype = DEVICE_3BUTTON;
|
||||
}
|
||||
|
||||
|
@ -8,21 +8,27 @@
|
||||
****************************************************************************/
|
||||
typedef struct
|
||||
{
|
||||
double psg_preamp;
|
||||
double fm_preamp;
|
||||
uint8 boost;
|
||||
uint8 filter;
|
||||
uint8 padtype;
|
||||
} t_input_c;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
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 force_dtack;
|
||||
uint8 bios_enabled;
|
||||
uint8 tv_mode;
|
||||
uint8 aspect;
|
||||
uint8 overscan;
|
||||
uint8 render;
|
||||
uint8 ntsc;
|
||||
uint8 gun_cursor;
|
||||
t_input_c input[MAX_INPUTS];
|
||||
uint8 gun_cursor[2];
|
||||
uint8 invert_mouse;
|
||||
} t_config;
|
||||
|
||||
|
@ -5,7 +5,8 @@
|
||||
#include "sms_ntsc.h"
|
||||
#include "md_ntsc.h"
|
||||
|
||||
#define SOUND_FREQUENCY 48000
|
||||
#define SOUND_FREQUENCY 48000
|
||||
#define SOUND_SAMPLES_SIZE 2048
|
||||
|
||||
int timer_count = 0;
|
||||
int old_timer_count = 0;
|
||||
@ -16,11 +17,7 @@ int joynum = 0;
|
||||
|
||||
int update_input(void);
|
||||
uint8 *keystate;
|
||||
uint8 buf[0x24000];
|
||||
|
||||
uint8 soundbuffer[16][3840];
|
||||
int mixbuffer = 0;
|
||||
int playbuffer = 0;
|
||||
uint8 buf[STATE_SIZE];
|
||||
|
||||
uint8 log_error = 0;
|
||||
uint8 debug_on = 0;
|
||||
@ -28,56 +25,95 @@ uint8 turbo_mode = 1;
|
||||
uint8 use_sound = 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)
|
||||
{
|
||||
audio_len = len;
|
||||
memcpy(stream, soundbuffer[playbuffer], len);
|
||||
|
||||
/* increment soundbuffers index */
|
||||
playbuffer++;
|
||||
playbuffer &= 0xf;
|
||||
if (playbuffer == mixbuffer)
|
||||
{
|
||||
playbuffer--;
|
||||
if ( playbuffer < 0 ) playbuffer = 15;
|
||||
if(sdl_sound.current_emulated_samples < len) {
|
||||
memset(stream, 0, len);
|
||||
}
|
||||
else {
|
||||
memcpy(stream, sdl_sound.buffer, len);
|
||||
/* loop to compensate desync */
|
||||
do {
|
||||
sdl_sound.current_emulated_samples -= len;
|
||||
} while(sdl_sound.current_emulated_samples > 2 * len);
|
||||
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()
|
||||
{
|
||||
SDL_AudioSpec audio;
|
||||
int n;
|
||||
SDL_AudioSpec as_desired, as_obtained;
|
||||
|
||||
if(SDL_Init(SDL_INIT_AUDIO) < 0)
|
||||
{
|
||||
char caption[256];
|
||||
sprintf(caption, "SDL audio can't initialize");
|
||||
MessageBox(NULL, caption, "Error", 0);
|
||||
if(SDL_Init(SDL_INIT_AUDIO) < 0) {
|
||||
printf("ERROR: %s.\n", SDL_GetError());
|
||||
return 0;
|
||||
}
|
||||
|
||||
audio.freq = SOUND_FREQUENCY;
|
||||
audio.format = AUDIO_S16LSB;
|
||||
audio.channels = 2;
|
||||
audio.samples = snd.buffer_size;
|
||||
audio.callback = sdl_sound_callback;
|
||||
as_desired.freq = SOUND_FREQUENCY;
|
||||
as_desired.format = AUDIO_S16LSB;
|
||||
as_desired.channels = 2;
|
||||
as_desired.samples = SOUND_SAMPLES_SIZE;
|
||||
as_desired.callback = sdl_sound_callback;
|
||||
|
||||
if(SDL_OpenAudio(&audio, NULL) == -1)
|
||||
{
|
||||
char caption[256];
|
||||
sprintf(caption, "SDL can't open audio");
|
||||
MessageBox(NULL, caption, "Error", 0);
|
||||
if(SDL_OpenAudio(&as_desired, &as_obtained) == -1) {
|
||||
printf("ERROR: can't open audio: %s.\n", SDL_GetError());
|
||||
return 0;
|
||||
}
|
||||
|
||||
memset(soundbuffer, 0, 16 * 3840);
|
||||
mixbuffer = 0;
|
||||
playbuffer = 0;
|
||||
if(as_desired.samples != as_obtained.samples) {
|
||||
printf("ERROR: soundcard driver does not accept specified samples size.\n");
|
||||
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;
|
||||
}
|
||||
|
||||
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_Surface* screen;
|
||||
static SDL_Surface* surface;
|
||||
@ -97,7 +133,7 @@ Uint32 fps_callback(Uint32 interval)
|
||||
if (region_code == REGION_USA) sprintf(region,"USA");
|
||||
else if (region_code == REGION_EUROPE) sprintf(region,"EUR");
|
||||
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);
|
||||
frame_count = 0;
|
||||
|
||||
@ -105,15 +141,6 @@ Uint32 fps_callback(Uint32 interval)
|
||||
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 )
|
||||
{
|
||||
SDL_Rect dest;
|
||||
@ -121,7 +148,6 @@ void display_output( void )
|
||||
dest.h=rect.h;
|
||||
dest.x=(640-rect.w)/2;
|
||||
dest.y=(480-rect.h)/2;
|
||||
//SDL_UnlockSurface( surface );
|
||||
if ( SDL_BlitSurface( surface, &rect, screen, &dest ) < 0 || SDL_Flip( screen ) < 0 )
|
||||
MessageBox(NULL, "SDL blit failed", "Error", 0);
|
||||
}
|
||||
@ -136,8 +162,6 @@ int main (int argc, char **argv)
|
||||
md_ntsc_setup_t md_setup;
|
||||
sms_ntsc_setup_t sms_setup;
|
||||
|
||||
SDL_Event event;
|
||||
|
||||
error_init();
|
||||
|
||||
/* Print help if no game specified */
|
||||
@ -149,9 +173,12 @@ int main (int argc, char **argv)
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* set default config */
|
||||
set_config_defaults();
|
||||
|
||||
/* Load game */
|
||||
cart_rom = malloc(0xA00000);
|
||||
memset(cart_rom, 0, 0xA00000);
|
||||
cart_rom = malloc(10*1024*1024);
|
||||
memset(cart_rom, 0, 10*1024*1024);
|
||||
if(!load_rom(argv[1]))
|
||||
{
|
||||
char caption[256];
|
||||
@ -159,7 +186,7 @@ int main (int argc, char **argv)
|
||||
MessageBox(NULL, caption, "Error", 0);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
/* initialize SDL */
|
||||
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0)
|
||||
{
|
||||
@ -192,11 +219,6 @@ int main (int argc, char **argv)
|
||||
bitmap.viewport.x = 0;
|
||||
bitmap.viewport.y = 0;
|
||||
|
||||
/* set default config */
|
||||
set_config_defaults();
|
||||
input.system[0] = SYSTEM_GAMEPAD;
|
||||
input.system[1] = SYSTEM_GAMEPAD;
|
||||
|
||||
/* load BIOS */
|
||||
memset(bios_rom, 0, sizeof(bios_rom));
|
||||
FILE *f = fopen("./BIOS.bin", "rb");
|
||||
@ -238,7 +260,8 @@ int main (int argc, char **argv)
|
||||
|
||||
while(running)
|
||||
{
|
||||
while (SDL_PollEvent(&event))
|
||||
SDL_Event event;
|
||||
if (SDL_PollEvent(&event))
|
||||
{
|
||||
switch(event.type)
|
||||
{
|
||||
@ -246,14 +269,6 @@ int main (int argc, char **argv)
|
||||
running = 0;
|
||||
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 */
|
||||
sym = event.key.keysym.sym;
|
||||
|
||||
@ -283,7 +298,7 @@ int main (int argc, char **argv)
|
||||
f = fopen("game.gpz","r+b");
|
||||
if (f)
|
||||
{
|
||||
fread(&buf, 0x23000, 1, f);
|
||||
fread(&buf, STATE_SIZE, 1, f);
|
||||
state_load(buf);
|
||||
fclose(f);
|
||||
}
|
||||
@ -294,7 +309,7 @@ int main (int argc, char **argv)
|
||||
if (f)
|
||||
{
|
||||
state_save(buf);
|
||||
fwrite(&buf, 0x23000, 1, f);
|
||||
fwrite(&buf, STATE_SIZE, 1, f);
|
||||
fclose(f);
|
||||
}
|
||||
}
|
||||
@ -304,9 +319,15 @@ int main (int argc, char **argv)
|
||||
|
||||
/* reinitialize timings */
|
||||
system_init ();
|
||||
audio_init(SOUND_FREQUENCY);
|
||||
fm_restore();
|
||||
|
||||
unsigned char *temp = malloc(YM2612GetContextSize());
|
||||
if (temp) memcpy(temp, YM2612GetContextPtr(), YM2612GetContextSize());
|
||||
audio_init(48000);
|
||||
if (temp)
|
||||
{
|
||||
YM2612Restore(temp);
|
||||
free(temp);
|
||||
}
|
||||
|
||||
/* reinitialize HVC tables */
|
||||
vctab = (vdp_pal) ? ((reg[1] & 8) ? vc_pal_240 : vc_pal_224) : vc_ntsc_224;
|
||||
hctab = (reg[12] & 1) ? cycle2hc40 : cycle2hc32;
|
||||
@ -314,7 +335,6 @@ int main (int argc, char **argv)
|
||||
/* reinitialize overscan area */
|
||||
bitmap.viewport.x = config.overscan ? 14 : 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_F11)
|
||||
@ -331,7 +351,7 @@ int main (int argc, char **argv)
|
||||
else if(sym == SDLK_F12)
|
||||
{
|
||||
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.changed = 1;
|
||||
}
|
||||
@ -355,18 +375,21 @@ int main (int argc, char **argv)
|
||||
{
|
||||
/* Delay */
|
||||
while (!frameticker && !turbo_mode) SDL_Delay(0);
|
||||
|
||||
//SDL_FillRect( surface, 0, 0 );
|
||||
|
||||
system_frame (0);
|
||||
frame_count++;
|
||||
}
|
||||
update_input();
|
||||
|
||||
frameticker--;
|
||||
|
||||
/* Sound Update */
|
||||
audio_update(snd.buffer_size);
|
||||
if (use_sound) sdl_sound_update();
|
||||
|
||||
/* Video update */
|
||||
if(bitmap.viewport.changed)
|
||||
{
|
||||
bitmap.viewport.changed = 0;
|
||||
bitmap.viewport.changed = 0;
|
||||
rect.w = bitmap.viewport.w+2*bitmap.viewport.x;
|
||||
rect.h = bitmap.viewport.h+2*bitmap.viewport.y;
|
||||
if (config.render && (interlaced || config.ntsc)) rect.h *= 2;
|
||||
@ -408,8 +431,7 @@ int main (int argc, char **argv)
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
SDL_PauseAudio(1);
|
||||
SDL_CloseAudio();
|
||||
if (use_sound) sdl_sound_close();
|
||||
SDL_FreeSurface(surface);
|
||||
SDL_FreeSurface(screen);
|
||||
SDL_Quit();
|
||||
@ -425,9 +447,9 @@ int update_input(void)
|
||||
keystate = SDL_GetKeyState(NULL);
|
||||
|
||||
while (input.dev[joynum] == NO_DEVICE)
|
||||
{
|
||||
joynum ++;
|
||||
if (joynum > MAX_DEVICES - 1) joynum = 0;
|
||||
{
|
||||
joynum ++;
|
||||
if (joynum > MAX_DEVICES - 1) joynum = 0;
|
||||
}
|
||||
|
||||
/* reset input */
|
||||
|
@ -4,12 +4,7 @@
|
||||
|
||||
#define MAX_INPUTS 8
|
||||
|
||||
|
||||
extern uint8 debug_on;
|
||||
extern uint8 log_error;
|
||||
extern int frame_count;
|
||||
|
||||
extern uint8 soundbuffer[16][3840];
|
||||
extern int mixbuffer;
|
||||
|
||||
#endif /* _MAIN_H_ */
|
||||
|
Loading…
Reference in New Issue
Block a user