More fixes

This commit is contained in:
Themaister 2010-12-29 19:43:17 +01:00
parent 2da6a4e2cc
commit 80d98f765e
6 changed files with 58 additions and 46 deletions

View File

@ -65,6 +65,7 @@ uninstall: $(TARGET)
clean:
rm -f *.o
rm -f audio/*.o
rm -f conf/*.o
rm -f gfx/*.o
rm -f hqflt/*.o
rm -f hqflt/snes_ntsc/*.o

View File

@ -155,7 +155,7 @@ config_file_t *config_file_new(const char *path)
}
fclose(file);
//print_config(conf);
print_config(conf);
return conf;
}

View File

@ -17,9 +17,9 @@
#include "driver.h"
#include "config.h"
#include "general.h"
#include <stdio.h>
#include <string.h>
void init_drivers(void)
{
@ -35,28 +35,28 @@ void uninit_drivers(void)
void init_audio(void)
{
if (!audio_enable)
if (!g_settings.audio.enable)
{
g_extern.audio_active = false;
return;
}
driver.audio_data = driver.audio->init(audio_device, out_rate, out_latency);
driver.audio_data = driver.audio->init(strlen(g_settings.audio.device) ? g_settings.audio.device : NULL, g_settings.audio.out_rate, g_settings.audio.latency);
if ( driver.audio_data == NULL )
g_extern.audio_active = false;
if (!audio_sync && g_extern.audio_active)
if (!g_settings.audio.sync && g_extern.audio_active)
driver.audio->set_nonblock_state(driver.audio_data, true);
int err;
g_extern.source = src_new(SAMPLERATE_QUALITY, 2, &err);
g_extern.source = src_new(g_settings.audio.src_quality, 2, &err);
if (!g_extern.source)
g_extern.audio_active = false;
}
void uninit_audio(void)
{
if (!audio_enable)
if (!g_settings.audio.enable)
{
g_extern.audio_active = false;
return;
@ -74,6 +74,7 @@ void init_video_input(void)
int scale;
// We multiply scales with 2 to allow for hi-res games.
#if 0
#if VIDEO_FILTER == FILTER_NONE
scale = 2;
#elif VIDEO_FILTER == FILTER_HQ2X
@ -89,14 +90,16 @@ void init_video_input(void)
#else
scale = 2;
#endif
#endif
scale = 2;
video_info_t video = {
.width = (fullscreen) ? fullscreen_x : (296 * xscale),
.height = (fullscreen) ? fullscreen_y : (224 * yscale),
.fullscreen = fullscreen,
.vsync = vsync,
.force_aspect = force_aspect,
.smooth = video_smooth,
.width = (g_settings.video.fullscreen) ? g_settings.video.fullscreen_x : (296 * g_settings.video.xscale),
.height = (g_settings.video.fullscreen) ? g_settings.video.fullscreen_y : (224 * g_settings.video.yscale),
.fullscreen = g_settings.video.fullscreen,
.vsync = g_settings.video.vsync,
.force_aspect = g_settings.video.force_aspect,
.smooth = g_settings.video.smooth,
.input_scale = scale,
};
@ -146,12 +149,12 @@ driver_t driver = {
#error "Define a valid video driver in config.h"
#endif
#if AUDIO_DRIVER == AUDIO_RSOUND
#if AUDIO_DRIVER == AUDIO_ALSA
.audio = &audio_alsa,
#elif AUDIO_DRIVER == AUDIO_RSOUND
.audio = &audio_rsound,
#elif AUDIO_DRIVER == AUDIO_OSS
.audio = &audio_oss,
#elif AUDIO_DRIVER == AUDIO_ALSA
.audio = &audio_alsa,
#elif AUDIO_DRIVER == AUDIO_ROAR
.audio = &audio_roar,
#elif AUDIO_DRIVER == AUDIO_AL

View File

@ -22,6 +22,7 @@
#include <stdbool.h>
#include <samplerate.h>
#include "driver.h"
#include <stdio.h>
#define MAX_PLAYERS 2
@ -56,6 +57,9 @@ struct settings
struct
{
struct snes_keybind binds[MAX_PLAYERS][MAX_BINDS];
int save_state_key;
int load_state_key;
int toggle_fullscreen_key;
} input;
};
@ -65,6 +69,10 @@ struct global
SRC_STATE *source;
bool audio_active;
bool video_active;
FILE *rom_file;
char savefile_name_srm[256];
char cg_shader_path[256];
};
void parse_config(void);

View File

@ -34,6 +34,10 @@ static void set_defaults(void)
assert(sizeof(g_settings.input.binds[1]) >= sizeof(snes_keybinds_2));
memcpy(g_settings.input.binds[0], snes_keybinds_1, sizeof(snes_keybinds_1));
memcpy(g_settings.input.binds[1], snes_keybinds_2, sizeof(snes_keybinds_2));
g_settings.input.save_state_key = SAVE_STATE_KEY;
g_settings.input.load_state_key = LOAD_STATE_KEY;
g_settings.input.toggle_fullscreen_key = TOGGLE_FULLSCREEN;
}
void parse_config(void)

56
ssnes.c
View File

@ -24,7 +24,6 @@
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include "config.h"
#include "driver.h"
#include "file.h"
#include "hqflt/pastlib.h"
@ -53,7 +52,7 @@ void set_fast_forward_button(bool new_button_state)
if (g_extern.video_active)
driver.video->set_nonblock_state(driver.video_data, syncing_state);
if (g_extern.audio_active)
driver.audio->set_nonblock_state(driver.audio_data, (audio_sync) ? syncing_state : true);
driver.audio->set_nonblock_state(driver.audio_data, (g_settings.audio.sync) ? syncing_state : true);
if (syncing_state)
audio_chunk_size = AUDIO_CHUNK_SIZE_NONBLOCKING;
else
@ -86,6 +85,7 @@ static void video_frame(const uint16_t *data, unsigned width, unsigned height)
if ( !g_extern.video_active )
return;
#if 0
#if VIDEO_FILTER == FILTER_HQ2X
uint16_t outputHQ2x[width * height * 2 * 2];
#elif VIDEO_FILTER == FILTER_HQ4X
@ -122,8 +122,11 @@ static void video_frame(const uint16_t *data, unsigned width, unsigned height)
#else
if ( !driver.video->frame(driver.video_data, data, width, height, (height == 448 || height == 478) ? 1024 : 2048) )
g_extern.video_active = false;
#endif
#endif
if ( !driver.video->frame(driver.video_data, data, width, height, (height == 448 || height == 478) ? 1024 : 2048) )
g_extern.video_active = false;
}
static void audio_sample(uint16_t left, uint16_t right)
@ -149,7 +152,7 @@ static void audio_sample(uint16_t left, uint16_t right)
src_data.input_frames = audio_chunk_size / 2;
src_data.output_frames = audio_chunk_size * 8;
src_data.end_of_input = 0;
src_data.src_ratio = (double)out_rate / (double)in_rate;
src_data.src_ratio = (double)g_settings.audio.out_rate / (double)g_settings.audio.in_rate;
src_process(g_extern.source, &src_data);
@ -172,7 +175,7 @@ static void input_poll(void)
static int16_t input_state(bool port, unsigned device, unsigned index, unsigned id)
{
const struct snes_keybind *binds[] = { snes_keybinds_1, snes_keybinds_2 };
const struct snes_keybind *binds[] = { g_settings.input.binds[0], g_settings.input.binds[1] };
return driver.input->input_state(driver.input_data, binds, port, device, index, id);
}
@ -202,13 +205,6 @@ static void print_help(void)
puts("\t-v/--verbose: Verbose logging");
}
static FILE* rom_file = NULL;
static char savefile_name_srm[256] = {0};
bool verbose = false;
#ifdef HAVE_CG
char cg_shader_path[256] = DEFAULT_CG_SHADER;
#endif
static void parse_input(int argc, char *argv[])
{
if (argc < 2)
@ -247,18 +243,18 @@ static void parse_input(int argc, char *argv[])
exit(0);
case 's':
strncpy(savefile_name_srm, optarg, sizeof(savefile_name_srm));
savefile_name_srm[sizeof(savefile_name_srm)-1] = '\0';
strncpy(g_extern.savefile_name_srm, optarg, sizeof(g_extern.savefile_name_srm));
g_extern.savefile_name_srm[sizeof(g_extern.savefile_name_srm)-1] = '\0';
break;
#ifdef HAVE_CG
case 'f':
strncpy(cg_shader_path, optarg, sizeof(cg_shader_path) - 1);
strncpy(g_extern.cg_shader_path, optarg, sizeof(g_extern.cg_shader_path) - 1);
break;
#endif
case 'v':
verbose = true;
g_extern.verbose = true;
break;
case '?':
@ -285,16 +281,16 @@ static void parse_input(int argc, char *argv[])
snes_set_cartridge_basename(tmp);
SSNES_LOG("Opening file: \"%s\"\n", argv[optind]);
rom_file = fopen(argv[optind], "rb");
if (rom_file == NULL)
g_extern.rom_file = fopen(argv[optind], "rb");
if (g_extern.rom_file == NULL)
{
SSNES_ERR("Could not open file: \"%s\"\n", optarg);
exit(1);
}
if (strlen(savefile_name_srm) == 0)
fill_pathname(savefile_name_srm, argv[optind], ".srm");
if (strlen(g_extern.savefile_name_srm) == 0)
fill_pathname(g_extern.savefile_name_srm, argv[optind], ".srm");
}
else if (strlen(savefile_name_srm) == 0)
else if (strlen(g_extern.savefile_name_srm) == 0)
{
SSNES_ERR("Need savefile argument when reading rom from stdin.\n");
print_help();
@ -310,18 +306,18 @@ int main(int argc, char *argv[])
void *rom_buf;
ssize_t rom_len = 0;
if ((rom_len = read_file(rom_file, &rom_buf)) == -1)
if ((rom_len = read_file(g_extern.rom_file, &rom_buf)) == -1)
{
SSNES_ERR("Could not read ROM file.\n");
exit(1);
}
SSNES_LOG("ROM size: %zi bytes\n", rom_len);
if (rom_file != NULL)
fclose(rom_file);
if (g_extern.rom_file != NULL)
fclose(g_extern.rom_file);
char statefile_name[strlen(savefile_name_srm)+strlen(".state")+1];
char savefile_name_rtc[strlen(savefile_name_srm)+strlen(".rtc")+1];
char statefile_name[strlen(g_extern.savefile_name_srm)+strlen(".state")+1];
char savefile_name_rtc[strlen(g_extern.savefile_name_srm)+strlen(".rtc")+1];
fill_pathname(statefile_name, argv[1], ".state");
fill_pathname(savefile_name_rtc, argv[1], ".rtc");
@ -349,7 +345,7 @@ int main(int argc, char *argv[])
goto error;
}
load_save_file(savefile_name_srm, SNES_MEMORY_CARTRIDGE_RAM);
load_save_file(g_extern.savefile_name_srm, SNES_MEMORY_CARTRIDGE_RAM);
load_save_file(savefile_name_rtc, SNES_MEMORY_CARTRIDGE_RTC);
///// TODO: Modular friendly!!!
@ -360,15 +356,15 @@ int main(int argc, char *argv[])
if ( quitting )
break;
if ( glfwGetKey( SAVE_STATE_KEY ))
if ( glfwGetKey( g_settings.input.save_state_key ))
{
write_file(statefile_name, serial_data, serial_size);
}
else if ( glfwGetKey( LOAD_STATE_KEY ) )
else if ( glfwGetKey( g_settings.input.load_state_key ) )
load_state(statefile_name, serial_data, serial_size);
else if ( glfwGetKey( TOGGLE_FULLSCREEN ) )
else if ( glfwGetKey( g_settings.input.toggle_fullscreen_key ) )
{
g_settings.video.fullscreen = !g_settings.video.fullscreen;
uninit_drivers();
@ -378,7 +374,7 @@ int main(int argc, char *argv[])
snes_run();
}
save_file(savefile_name_srm, SNES_MEMORY_CARTRIDGE_RAM);
save_file(g_extern.savefile_name_srm, SNES_MEMORY_CARTRIDGE_RAM);
save_file(savefile_name_rtc, SNES_MEMORY_CARTRIDGE_RTC);
snes_unload_cartridge();