linux compat
This commit is contained in:
@ -59,6 +59,7 @@ typedef struct {
|
||||
|
||||
void cart_load_state(const cart_state*);
|
||||
void cart_save_state(cart_state*);
|
||||
bool cart_init();
|
||||
|
||||
bool cart_load(char *cart);
|
||||
|
||||
@ -73,4 +74,4 @@ bool cart_need_save();
|
||||
bool cart_battery_load();
|
||||
bool cart_battery_save();
|
||||
|
||||
u8 cart_get_rom_bank();
|
||||
u8 cart_get_rom_bank();
|
||||
|
@ -67,7 +67,7 @@ u8 cpu_read_reg8(reg_type rt);
|
||||
|
||||
void cpu_set_reg8(reg_type rt, u8 val);
|
||||
|
||||
void fetch_data();
|
||||
void fetch_data(cpu_context*);
|
||||
|
||||
u8 cpu_get_ie_register();
|
||||
void cpu_set_ie_register(u8 ie);
|
||||
@ -79,4 +79,4 @@ void cpu_set_int_flags(u8 value);
|
||||
|
||||
void inst_to_str(cpu_context *ctx, char *str);
|
||||
|
||||
void cpu_set_flags(cpu_context *ctx, int8_t z, int8_t n, int8_t h, int8_t c);
|
||||
void cpu_set_flags(cpu_context *ctx, int8_t z, int8_t n, int8_t h, int8_t c);
|
||||
|
@ -134,7 +134,7 @@ void audio_init(){
|
||||
if (err != paNoError) goto error;
|
||||
output_parameters.device = Pa_GetDefaultOutputDevice();
|
||||
if(output_parameters.device == paNoDevice) {
|
||||
fprintf(stderr, "No default audio device!\n");
|
||||
fprintf(stderr, "No default audio device! Number of devices: %d\n", Pa_GetDeviceCount());
|
||||
goto error;
|
||||
}
|
||||
output_parameters.channelCount = 2;
|
||||
@ -157,6 +157,7 @@ void audio_init(){
|
||||
error:
|
||||
Pa_Terminate();
|
||||
fprintf(stderr, "portaudio stream error\n\tError Number: %d\n\tError Message: %s\n", err, Pa_GetErrorText(err));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void sq1_sweep() {
|
||||
@ -1004,4 +1005,4 @@ void audio_load_state(const audio_state* state) {
|
||||
ctx = state->ctx;
|
||||
ctx.left_audio_buffer = malloc(sizeof(float) * FRAMES_PER_BUFFER);
|
||||
ctx.right_audio_buffer = malloc(sizeof(float) * FRAMES_PER_BUFFER);
|
||||
}
|
||||
}
|
||||
|
20
lib/cart.c
20
lib/cart.c
@ -287,6 +287,7 @@ bool cart_load(char *cart) {
|
||||
if(ctx.battery) {
|
||||
cart_battery_load();
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -493,11 +494,21 @@ void cart_write(u16 address, u8 value){
|
||||
}
|
||||
|
||||
bool cart_battery_load(){
|
||||
#ifdef __windows__
|
||||
char *filename = strrchr(ctx.filename, '\\');
|
||||
#else
|
||||
char *filename = strrchr(ctx.filename, '/');
|
||||
#endif
|
||||
filename++;
|
||||
char fn[1048];
|
||||
#ifdef __windows__
|
||||
char *profile = getenv("USERPROFILE");
|
||||
sprintf(fn, "%s/Documents/gbemu/saves/%s.battery", profile, filename);
|
||||
#else
|
||||
char *profile = getenv("HOME");
|
||||
sprintf(fn, "%s/.config/gbemu/saves/%s.battery", profile, filename);
|
||||
#endif
|
||||
printf("loading %s\n", fn);
|
||||
FILE *fp = fopen(fn, "rb");
|
||||
|
||||
if(!fp) {
|
||||
@ -510,11 +521,20 @@ bool cart_battery_load(){
|
||||
}
|
||||
|
||||
bool cart_battery_save(){
|
||||
#ifdef __windows__
|
||||
char *filename = strrchr(ctx.filename, '\\');
|
||||
#else
|
||||
char *filename = strrchr(ctx.filename, '/');
|
||||
#endif
|
||||
filename++;
|
||||
char fn[1048];
|
||||
#ifdef __windows__
|
||||
char *profile = getenv("USERPROFILE");
|
||||
sprintf(fn, "%s/Documents/gbemu/saves/%s.battery", profile, filename);
|
||||
#else
|
||||
char *profile = getenv("HOME");
|
||||
sprintf(fn, "%s/.config/gbemu/saves/%s.battery", profile, filename);
|
||||
#endif
|
||||
FILE *fp = fopen(fn, "wb");
|
||||
|
||||
if(!fp) {
|
||||
|
32
lib/emu.c
32
lib/emu.c
@ -16,10 +16,15 @@
|
||||
#else
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
|
||||
static emu_context ctx;
|
||||
#ifdef __windows__
|
||||
static HANDLE thread;
|
||||
#else
|
||||
static pthread_t thread;
|
||||
#endif
|
||||
|
||||
emu_context *emu_get_context() {
|
||||
return &ctx;
|
||||
@ -61,7 +66,12 @@ void sleep_ms(int milis) {
|
||||
|
||||
void emu_stop() {
|
||||
ctx.running = false;
|
||||
#ifdef __windows__
|
||||
WaitForSingleObject(thread, INFINITE);
|
||||
#else
|
||||
pthread_join(thread, NULL);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
void emu_reset() {
|
||||
@ -74,7 +84,11 @@ void emu_reset() {
|
||||
}
|
||||
|
||||
void emu_start() {
|
||||
#ifdef __windows__
|
||||
thread = CreateThread(NULL, 0, cpu_run, NULL, 0, NULL);
|
||||
#else
|
||||
pthread_create(&thread, NULL, cpu_run, NULL);
|
||||
#endif
|
||||
if(!thread) {
|
||||
fprintf(stderr, "Unable to create main CPU thread!\n");
|
||||
}
|
||||
@ -92,6 +106,7 @@ int emu_run(int argc, char **argv) {
|
||||
}
|
||||
|
||||
char fn[1048];
|
||||
#ifdef __windows__
|
||||
char *profile = getenv("USERPROFILE");
|
||||
sprintf(fn, "%s\\Documents\\gbemu", profile);
|
||||
CreateDirectory(fn, NULL);
|
||||
@ -99,21 +114,22 @@ int emu_run(int argc, char **argv) {
|
||||
CreateDirectory(fn, NULL);
|
||||
sprintf(fn, "%s\\Documents\\gbemu\\states", profile);
|
||||
CreateDirectory(fn, NULL);
|
||||
#else
|
||||
char *profile = getenv("HOME");
|
||||
sprintf(fn, "%s/.config/gbemu", profile);
|
||||
mkdir(fn, 0755);
|
||||
sprintf(fn, "%s/.config/gbemu/saves", profile);
|
||||
mkdir(fn, 0755);
|
||||
sprintf(fn, "%s/.config/gbemu/states", profile);
|
||||
mkdir(fn, 0755);
|
||||
#endif
|
||||
|
||||
printf("Cart loaded..\n");
|
||||
ctx.app_path = argv[0];
|
||||
|
||||
ui_init();
|
||||
#ifdef _WIN32
|
||||
emu_reset();
|
||||
emu_start();
|
||||
#else
|
||||
pthread_t t1;
|
||||
if(pthread_create(&t1, NULL, cpu_run, NULL)) {
|
||||
fprintf(stderr, "Unable to create main CPU thread!\n");
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
u32 prev_frame = 0;
|
||||
debug_init();
|
||||
|
19
lib/state.c
19
lib/state.c
@ -1,5 +1,10 @@
|
||||
#include <state.h>
|
||||
#include <string.h>
|
||||
#ifdef __windows__
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
|
||||
void state_save(save_state* state) {
|
||||
printf("Saving state\n");
|
||||
@ -33,10 +38,17 @@ void state_save_file(u8 slot) {
|
||||
char *filename = strrchr(cart_get_context()->filename, '\\');
|
||||
filename++;
|
||||
char fn[1048];
|
||||
#ifdef __windows__
|
||||
char *profile = getenv("USERPROFILE");
|
||||
sprintf(fn, "%s/Documents/gbemu/states/%s", profile, filename);
|
||||
CreateDirectory(fn, NULL);
|
||||
sprintf(fn, "%s/Documents/gbemu/states/%s/%d.state", profile, filename, slot);
|
||||
#else
|
||||
char *profile = getenv("HOME");
|
||||
sprintf(fn, "%s/.config/gbemu/states/%s", profile, filename);
|
||||
mkdir(fn, 0755);
|
||||
sprintf(fn, "%s/.config/gbemu/states/%s/%d.state", profile, filename, slot);
|
||||
#endif
|
||||
FILE *fp = fopen(fn, "wb");
|
||||
|
||||
if(!fp) {
|
||||
@ -53,8 +65,13 @@ void state_load_file(u8 slot) {
|
||||
char *filename = strrchr(cart_get_context()->filename, '\\');
|
||||
filename++;
|
||||
char fn[1048];
|
||||
#ifdef __windows__
|
||||
char *profile = getenv("USERPROFILE");
|
||||
sprintf(fn, "%s/Documents/gbemu/states/%s/%d.state", profile, filename, slot);
|
||||
#else
|
||||
char *profile = getenv("HOME");
|
||||
sprintf(fn, "%s/.config/gbemu/states/%s/%d.state", profile, filename, slot);
|
||||
#endif
|
||||
FILE *fp = fopen(fn, "rb");
|
||||
|
||||
if(!fp) {
|
||||
@ -65,4 +82,4 @@ void state_load_file(u8 slot) {
|
||||
fread(state, sizeof(*state), 1, fp);
|
||||
fclose(fp);
|
||||
state_load(state);
|
||||
}
|
||||
}
|
||||
|
10
lib/ui.c
10
lib/ui.c
@ -46,11 +46,11 @@ void ui_init(){
|
||||
//SDL_JoystickOpen(0);
|
||||
SDL_GameControllerOpen(0);
|
||||
|
||||
char buffer[1024];
|
||||
strcpy(buffer, emu_get_context()->app_path);
|
||||
*strrchr(buffer, '\\') = 0;
|
||||
strcat(buffer,"/Sans.ttf");
|
||||
sans = TTF_OpenFont(buffer, 24);
|
||||
//char buffer[1024];
|
||||
//strcpy(buffer, emu_get_context()->app_path);
|
||||
//*strrchr(buffer, '\\') = 0;
|
||||
//strcat(buffer,"/Sans.ttf");
|
||||
sans = TTF_OpenFont("Sans.ttf", 24);
|
||||
if ( !sans ) {
|
||||
printf("Failed to load font: %s\n", TTF_GetError());
|
||||
}
|
||||
|
Reference in New Issue
Block a user