From ecb5f0617b926eea27a22b1f42d7d966ffbc2eb9 Mon Sep 17 00:00:00 2001 From: ekeeke31 Date: Sun, 22 Nov 2009 16:35:41 +0000 Subject: [PATCH] updated SDL/Win32 sourcecode --- source/mem68k.c | 4 +- source/unused/win/Makefile | 7 +- source/unused/win/config.c | 5 +- source/unused/win/config.h | 2 + source/unused/win/main.c | 752 ++++++++++++++++++++----------------- source/unused/win/main.h | 4 +- source/unused/win/osd.h | 2 + 7 files changed, 426 insertions(+), 350 deletions(-) diff --git a/source/mem68k.c b/source/mem68k.c index 82e183f..91d980a 100644 --- a/source/mem68k.c +++ b/source/mem68k.c @@ -141,7 +141,7 @@ void eeprom_write_word(uint32 address, uint32 data) uint32 z80_read_byte(uint32 address) { if (zbusack) return m68k_read_bus_8(address); - + switch ((address >> 13) & 3) { case 2: /* YM2612 */ @@ -159,7 +159,7 @@ uint32 z80_read_byte(uint32 address) uint32 z80_read_word(uint32 address) { if (zbusack) return m68k_read_bus_16(address); - + switch ((address >> 13) & 3) { case 2: /* YM2612 */ diff --git a/source/unused/win/Makefile b/source/unused/win/Makefile index d1f743c..d01b540 100644 --- a/source/unused/win/Makefile +++ b/source/unused/win/Makefile @@ -8,7 +8,7 @@ # LSB_FIRST : for little endian systems. # X86_ASM : enable x86 assembly optimizations -NAME = ../gen_sdl.exe +NAME = gen_sdl.exe CC = gcc CFLAGS = `sdl-config --cflags` -O6 -march=i686 -fomit-frame-pointer @@ -37,13 +37,10 @@ OBJECTS += obj/sound.o \ obj/sn76489.o \ obj/ym2612.o -OBJECTS += obj/blip.o \ - obj/Fir_Resampler.o +OBJECTS += obj/Fir_Resampler.o \ OBJECTS += obj/eq.o \ -OBJECTS += obj/filters.o \ - OBJECTS += obj/sram.o \ obj/eeprom.o \ obj/svp.o \ diff --git a/source/unused/win/config.c b/source/unused/win/config.c index 6077d80..209f03c 100644 --- a/source/unused/win/config.c +++ b/source/unused/win/config.c @@ -11,7 +11,7 @@ void set_config_defaults(void) /* sound options */ config.psg_preamp = 150; config.fm_preamp = 100; - config.hq_fm = 0; + config.hq_fm = 1; config.psgBoostNoise = 0; config.filter = 1; config.low_freq = 200; @@ -19,6 +19,7 @@ void set_config_defaults(void) config.lg = 1.0; config.mg = 1.0; config.hg = 1.0; + config.lp_range = 50; /* system options */ config.region_detect = 0; @@ -26,7 +27,7 @@ void set_config_defaults(void) config.addr_error = 1; config.bios_enabled = 0; config.lock_on = 0; - config.romtype = 0; + config.romtype = 0; /* display options */ config.overscan = 1; diff --git a/source/unused/win/config.h b/source/unused/win/config.h index f91a2d4..ca026ab 100644 --- a/source/unused/win/config.h +++ b/source/unused/win/config.h @@ -20,6 +20,7 @@ typedef struct uint8 filter; uint16 low_freq; uint16 high_freq; + uint8 lp_range; float lg; float mg; float hg; @@ -39,6 +40,7 @@ typedef struct /* Global variables */ extern t_config config; +extern void set_config_defaults(void); #endif /* _CONFIG_H_ */ diff --git a/source/unused/win/main.c b/source/unused/win/main.c index c31aed3..082d510 100644 --- a/source/unused/win/main.c +++ b/source/unused/win/main.c @@ -1,29 +1,25 @@ #include -#include + +#include "SDL.h" +#include "SDL_thread.h" #include "shared.h" #include "sms_ntsc.h" #include "md_ntsc.h" #define SOUND_FREQUENCY 48000 -#define SOUND_SAMPLES_SIZE 2048 +#define SOUND_SAMPLES_SIZE 2048 + +#define VIDEO_WIDTH 640 +#define VIDEO_HEIGHT 480 -int timer_count = 0; -int old_timer_count = 0; -int paused = 0; -int frame_count = 0; -int frameticker = 0; int joynum = 0; -int update_input(void); -uint8 *keystate; -uint8 buf[STATE_SIZE]; - -uint8 log_error = 0; -uint8 debug_on = 0; -uint8 turbo_mode = 1; -uint8 use_sound = 0; -uint8 fullscreen = 0; +int log_error = 0; +int debug_on = 0; +int turbo_mode = 0; +int use_sound = 1; +int fullscreen = 0; /* SDL_FULLSCREEN */ /* sound */ @@ -57,23 +53,23 @@ static int sdl_sound_init() SDL_AudioSpec as_desired, as_obtained; if(SDL_Init(SDL_INIT_AUDIO) < 0) { - printf("ERROR: %s.\n", SDL_GetError()); + MessageBox(NULL, "SDL Audio initialization failed", "Error", 0); return 0; } - as_desired.freq = SOUND_FREQUENCY; - as_desired.format = AUDIO_S16LSB; + as_desired.freq = SOUND_FREQUENCY; + as_desired.format = AUDIO_S16LSB; as_desired.channels = 2; - as_desired.samples = SOUND_SAMPLES_SIZE; + as_desired.samples = SOUND_SAMPLES_SIZE; as_desired.callback = sdl_sound_callback; if(SDL_OpenAudio(&as_desired, &as_obtained) == -1) { - printf("ERROR: can't open audio: %s.\n", SDL_GetError()); + MessageBox(NULL, "SDL Audio open failed", "Error", 0); return 0; } if(as_desired.samples != as_obtained.samples) { - printf("ERROR: soundcard driver does not accept specified samples size.\n"); + MessageBox(NULL, "SDL Audio wrong setup", "Error", 0); return 0; } @@ -81,7 +77,7 @@ static int sdl_sound_init() 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"); + MessageBox(NULL, "Can't allocate audio buffer", "Error", 0); return 0; } memset(sdl_sound.buffer, 0, n); @@ -111,58 +107,360 @@ 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; -static unsigned char* output_pixels; /* 16-bit RGB */ -static long output_pitch; - -Uint32 fps_callback(Uint32 interval) -{ - if(paused) return 1000/vdp_rate; - timer_count++; - frameticker ++; - if(timer_count % vdp_rate == 0) - { - int fps = frame_count + 1; - char caption[100]; - char region[10]; - 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 - 0x%04X", rominfo.international, region, fps, realchecksum); - SDL_WM_SetCaption(caption, NULL); - frame_count = 0; - - } - return 1000/vdp_rate; -} - -void display_output( void ) -{ - SDL_Rect dest; - dest.w=rect.w; - dest.h=rect.h; - dest.x=(640-rect.w)/2; - dest.y=(480-rect.h)/2; - if ( SDL_BlitSurface( surface, &rect, screen, &dest ) < 0 || SDL_Flip( screen ) < 0 ) - MessageBox(NULL, "SDL blit failed", "Error", 0); + if (sdl_sound.buffer) + free(sdl_sound.buffer); } +/* video */ md_ntsc_t md_ntsc; sms_ntsc_t sms_ntsc; +struct { + SDL_Surface* surf_screen; + SDL_Surface* surf_bitmap; + Uint32 frames_rendered; +} sdl_video; + +static int sdl_video_init() +{ + if(SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) { + MessageBox(NULL, "SDL Video initialization failed", "Error", 0); + return 0; + } + sdl_video.surf_screen = SDL_SetVideoMode(VIDEO_WIDTH, VIDEO_HEIGHT, 16, SDL_SWSURFACE | fullscreen); + sdl_video.surf_bitmap = SDL_CreateRGBSurface(SDL_SWSURFACE, 720, 576, 16, 0, 0, 0, 0); + sdl_video.frames_rendered = 0; + SDL_WM_SetCaption("Genesis Plus/SDL", NULL); + SDL_ShowCursor(0); + + return 1; +} + +static void sdl_video_update() +{ + SDL_Rect rect; + + system_frame(0); + + /* viewport size changed */ + if(bitmap.viewport.changed) + { + 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; + if (config.ntsc) rect.w = (reg[12]&1) ? MD_NTSC_OUT_WIDTH(rect.w) : SMS_NTSC_OUT_WIDTH(rect.w); + rect.x=(VIDEO_WIDTH-rect.w)/2; + rect.y=(VIDEO_HEIGHT-rect.h)/2; + + /* init NTSC filter */ + md_ntsc_setup_t md_setup; + sms_ntsc_setup_t sms_setup; + if (config.ntsc == 1) + { + sms_setup = sms_ntsc_composite; + md_setup = md_ntsc_composite; + sms_ntsc_init( &sms_ntsc, &sms_setup ); + md_ntsc_init( &md_ntsc, &md_setup ); + } + else if (config.ntsc == 2) + { + sms_setup = sms_ntsc_svideo; + md_setup = md_ntsc_svideo; + sms_ntsc_init( &sms_ntsc, &sms_setup ); + md_ntsc_init( &md_ntsc, &md_setup ); + } + else if (config.ntsc == 3) + { + sms_setup = sms_ntsc_rgb; + md_setup = md_ntsc_rgb; + sms_ntsc_init( &sms_ntsc, &sms_setup ); + md_ntsc_init( &md_ntsc, &md_setup ); + } + } + + SDL_BlitSurface(sdl_video.surf_bitmap, NULL, sdl_video.surf_screen, &rect); + SDL_UpdateRect(sdl_video.surf_screen, 0, 0, 0, 0); + + ++sdl_video.frames_rendered; + +} + +static void sdl_video_close() +{ + if (sdl_video.surf_bitmap) SDL_FreeSurface(sdl_video.surf_bitmap); + if (sdl_video.surf_screen) SDL_FreeSurface(sdl_video.surf_screen); +} + +/* Timer Sync */ + +struct { + SDL_sem* sem_sync; +} sdl_sync; + +/* sync */ + +static Uint32 sdl_sync_timer_callback(Uint32 interval) +{ + /*char caption[100]; + char region[10]; + 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 - 0x%04X", rominfo.international, region, vdp_rate, realchecksum); + SDL_WM_SetCaption(caption, NULL);*/ + SDL_SemPost(sdl_sync.sem_sync); + return interval; +} + +static int sdl_sync_init() +{ + if(SDL_InitSubSystem(SDL_INIT_TIMER|SDL_INIT_EVENTTHREAD) < 0) { + MessageBox(NULL, "SDL Timer initialization failed", "Error", 0); + return 0; + } + sdl_sync.sem_sync = SDL_CreateSemaphore(0); + return 1; +} + +static void sdl_sync_close() +{ + if(sdl_sync.sem_sync) + SDL_DestroySemaphore(sdl_sync.sem_sync); +} + +static int sdl_control_update(SDLKey keystate) +{ + switch (keystate) + { + case SDLK_TAB: + { + system_reset(); + break; + } + + case SDLK_F2: + { + if (fullscreen) fullscreen = 0; + else fullscreen = SDL_FULLSCREEN; + sdl_video.surf_screen = SDL_SetVideoMode(VIDEO_WIDTH, VIDEO_HEIGHT, 16, SDL_SWSURFACE | fullscreen); + break; + } + + case SDLK_F3: + { + config.render ^=1; + break; + } + + case SDLK_F4: + { + SDL_FillRect(sdl_video.surf_screen, 0, 0); + config.ntsc ++; + if (config.ntsc > 3) config.ntsc = 0; + bitmap.viewport.changed = 1; + break; + } + + case SDLK_F5: + { + log_error ^= 1; + break; + } + + case SDLK_F6: + { + turbo_mode ^=1; + break; + } + + case SDLK_F7: + { + FILE *f = fopen("game.gpz","r+b"); + if (f) + { + uint8 buf[STATE_SIZE]; + fread(&buf, STATE_SIZE, 1, f); + state_load(buf); + fclose(f); + } + break; + } + + case SDLK_F8: + { + FILE *f = fopen("game.gpz","w+b"); + if (f) + { + uint8 buf[STATE_SIZE]; + state_save(buf); + fwrite(&buf, STATE_SIZE, 1, f); + fclose(f); + } + break; + } + + case SDLK_F9: + { + vdp_pal ^= 1; + + /* reinitialize timings */ + system_init (); + unsigned char *temp = malloc(YM2612GetContextSize()); + if (temp) memcpy(temp, YM2612GetContextPtr(), YM2612GetContextSize()); + audio_init(SOUND_FREQUENCY); + 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; + + /* 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; + + break; + } + + case SDLK_F10: + { + set_softreset(); + break; + } + + case SDLK_F11: + { + joynum ++; + if (joynum > MAX_DEVICES - 1) + joynum = 0; + break; + } + + case SDLK_F12: + { + config.overscan ^= 1; + 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; + break; + } + + case SDLK_ESCAPE: + { + return 0; + } + + default: + break; + } + + return 1; +} + +int sdl_input_update(void) +{ + uint8 *keystate = SDL_GetKeyState(NULL); + while (input.dev[joynum] == NO_DEVICE) + { + joynum ++; + if (joynum > MAX_DEVICES - 1) joynum = 0; + } + + /* reset input */ + input.pad[joynum] = 0; + + /* keyboard */ + if(keystate[SDLK_a]) input.pad[joynum] |= INPUT_A; + if(keystate[SDLK_s]) input.pad[joynum] |= INPUT_B; + if(keystate[SDLK_d]) input.pad[joynum] |= INPUT_C; + if(keystate[SDLK_f]) input.pad[joynum] |= INPUT_START; + if(keystate[SDLK_z]) input.pad[joynum] |= INPUT_X; + if(keystate[SDLK_x]) input.pad[joynum] |= INPUT_Y; + if(keystate[SDLK_c]) input.pad[joynum] |= INPUT_Z; + if(keystate[SDLK_v]) input.pad[joynum] |= INPUT_MODE; + + switch (input.dev[joynum]) + { + case DEVICE_LIGHTGUN: + { + /* get mouse (absolute values) */ + int x,y; + int state = SDL_GetMouseState(&x,&y); + + /* Calculate X Y axis values */ + input.analog[joynum - 4][0] = (x * bitmap.viewport.w) / 640; + input.analog[joynum - 4][1] = (y * bitmap.viewport.h) / 480; + + /* Map mouse buttons to player #1 inputs */ + if(state & SDL_BUTTON_MMASK) input.pad[joynum] |= INPUT_C; + if(state & SDL_BUTTON_RMASK) input.pad[joynum] |= INPUT_B; + if(state & SDL_BUTTON_LMASK) input.pad[joynum] |= INPUT_A; + + break; + } + + case DEVICE_MOUSE: + { + /* get mouse (relative values) */ + int x,y; + int state = SDL_GetRelativeMouseState(&x,&y); + + /* Sega Mouse range is -256;+256 */ + input.analog[2][0] = x; + input.analog[2][1] = y; + + /* Vertical movement is upsidedown */ + if (!config.invert_mouse) input.analog[2][1] = 0 - input.analog[2][1]; + + /* Map mouse buttons to player #1 inputs */ + if(state & SDL_BUTTON_MMASK) input.pad[joynum] |= INPUT_C; + if(state & SDL_BUTTON_RMASK) input.pad[joynum] |= INPUT_B; + if(state & SDL_BUTTON_LMASK) input.pad[joynum] |= INPUT_A; + + break; + } + + default: + { + if(keystate[SDLK_UP]) input.pad[joynum] |= INPUT_UP; + else + if(keystate[SDLK_DOWN]) input.pad[joynum] |= INPUT_DOWN; + if(keystate[SDLK_LEFT]) input.pad[joynum] |= INPUT_LEFT; + else + if(keystate[SDLK_RIGHT]) input.pad[joynum] |= INPUT_RIGHT; + + break; + } + } + + if (system_hw == SYSTEM_PICO) + { + /* get mouse (absolute values) */ + int x,y; + int state = SDL_GetMouseState(&x,&y); + + /* Calculate X Y axis values */ + input.analog[0][0] = 0x3c + (x * (0x17c-0x03c+1)) / 640; + input.analog[0][1] = 0x1fc + (y * (0x2f7-0x1fc+1)) / 480; + + /* Map mouse buttons to player #1 inputs */ + if(state & SDL_BUTTON_MMASK) pico_current++; + if(state & SDL_BUTTON_RMASK) input.pad[joynum] |= INPUT_B; + if(state & SDL_BUTTON_LMASK) input.pad[joynum] |= INPUT_A; + } + + free (keystate); + return 1; +} + + int main (int argc, char **argv) { int running = 1; - int sym; - md_ntsc_setup_t md_setup; - sms_ntsc_setup_t sms_setup; - - error_init(); /* Print help if no game specified */ if(argc < 2) @@ -174,9 +472,10 @@ int main (int argc, char **argv) } /* set default config */ + error_init(); set_config_defaults(); - /* Load game */ + /* Load ROM file */ cart.rom = malloc(10*1024*1024); memset(cart.rom, 0, 10*1024*1024); if(!load_rom(argv[1])) @@ -187,38 +486,6 @@ int main (int argc, char **argv) exit(1); } - /* initialize SDL */ - if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0) - { - char caption[256]; - sprintf(caption, "SDL initialization failed"); - MessageBox(NULL, caption, "Error", 0); - exit(1); - } - SDL_WM_SetCaption("Genesis Plus/SDL", NULL); - SDL_ShowCursor(0); - - screen = SDL_SetVideoMode(640, 480, 16, fullscreen ? (SDL_HWSURFACE|SDL_FULLSCREEN): (SDL_HWSURFACE)); - surface = SDL_CreateRGBSurface(SDL_HWSURFACE, 720, 576, 16, 0, 0, 0, 0); - if (!screen || !surface) - { - MessageBox(NULL, "Video initialization failed", "Error", 0); - exit(1); - } - - /* initialize Genesis display */ - memset(&bitmap, 0, sizeof(t_bitmap)); - bitmap.width = 720; - bitmap.height = 576; - bitmap.depth = 16; - bitmap.granularity = 2; - bitmap.pitch = (bitmap.width * bitmap.granularity); - bitmap.data = surface->pixels; - bitmap.viewport.w = 256; - bitmap.viewport.h = 224; - bitmap.viewport.x = 0; - bitmap.viewport.y = 0; - /* load BIOS */ memset(bios_rom, 0, sizeof(bios_rom)); FILE *f = fopen(OS_ROM, "rb"); @@ -236,13 +503,34 @@ int main (int argc, char **argv) config.bios_enabled |= 2; } + /* initialize SDL */ + if(SDL_Init(0) < 0) + { + char caption[256]; + sprintf(caption, "SDL initialization failed"); + MessageBox(NULL, caption, "Error", 0); + exit(1); + } + sdl_video_init(); + if (use_sound) + sdl_sound_init(); + sdl_sync_init(); + + /* initialize Genesis virtual system */ + SDL_LockSurface(sdl_video.surf_bitmap); + memset(&bitmap, 0, sizeof(t_bitmap)); + bitmap.width = 720; + bitmap.height = 576; + bitmap.depth = 16; + bitmap.granularity = 2; + bitmap.pitch = (bitmap.width * bitmap.granularity); + bitmap.data = sdl_video.surf_bitmap->pixels; + SDL_UnlockSurface(sdl_video.surf_bitmap); + /* initialize emulation */ system_init(); audio_init(SOUND_FREQUENCY); - /* initialize SDL audio */ - if (use_sound) use_sound = sdl_sound_init(); - /* load SRAM */ f = fopen("./game.srm", "rb"); if (f!=NULL) @@ -254,10 +542,13 @@ int main (int argc, char **argv) /* reset emulation */ system_reset(); - /* start emulation loop */ - SDL_SetTimer(1000/vdp_rate, fps_callback); - if (use_sound) SDL_PauseAudio(0); + if(use_sound) + SDL_PauseAudio(0); + if(sdl_sync.sem_sync) + SDL_SetTimer(vdp_pal ? 60 : 50, sdl_sync_timer_callback); /* 3 frames = 50 ms (60hz) or 60 ms (50hz) */ + + /* emulation loop */ while(running) { SDL_Event event; @@ -265,162 +556,26 @@ int main (int argc, char **argv) { switch(event.type) { - case SDL_QUIT: /* Windows was closed */ + case SDL_QUIT: running = 0; break; - case SDL_KEYDOWN: /* user options */ - sym = event.key.keysym.sym; - - if(sym == SDLK_TAB) system_reset(); - else if (sym == SDLK_RETURN) - { - fullscreen ^=1; - screen = SDL_SetVideoMode(640, 480, 16, fullscreen ? (SDL_HWSURFACE|SDL_FULLSCREEN): (SDL_HWSURFACE)); - - } - else if(sym == SDLK_F3) config.render ^=1; - else if(sym == SDLK_F4) - { - SDL_FillRect( screen, 0, 0 ); - config.ntsc ++; - if (config.ntsc > 3) config.ntsc = 0; - bitmap.viewport.changed = 1; - } - else if(sym == SDLK_F5) log_error ^=1; - else if(sym == SDLK_F6) - { - turbo_mode ^=1; - frameticker = 0; - } - else if(sym == SDLK_F7) - { - f = fopen("game.gpz","r+b"); - if (f) - { - fread(&buf, STATE_SIZE, 1, f); - state_load(buf); - fclose(f); - } - } - else if(sym == SDLK_F8) - { - f = fopen("game.gpz","w+b"); - if (f) - { - state_save(buf); - fwrite(&buf, STATE_SIZE, 1, f); - fclose(f); - } - } - else if(sym == SDLK_F9) - { - vdp_pal ^= 1; - - /* reinitialize timings */ - system_init (); - 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; - - /* 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; - } - else if(sym == SDLK_F10) set_softreset(); - else if(sym == SDLK_F11) - { - joynum ++; - if (joynum > MAX_DEVICES - 1) joynum = 0; - while (input.dev[joynum] == NO_DEVICE) - { - joynum ++; - if (joynum > MAX_DEVICES - 1) joynum = 0; - } - } - else if(sym == SDLK_ESCAPE) running = 0; - else if(sym == SDLK_F12) - { - config.overscan ^= 1; - 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; - } - break; - - default: + case SDL_KEYDOWN: + running = sdl_control_update(event.key.keysym.sym); break; } } + sdl_video_update(); + audio_update(snd.buffer_size); + if(use_sound) + sdl_sound_update(); - if(!paused) + if(!turbo_mode && sdl_sync.sem_sync && sdl_video.frames_rendered % 3 == 0) { - if (frameticker > 1) - { - /* Frame skipping */ - frameticker--; - system_frame (1); - } - else - { - /* Delay */ - while (!frameticker && !turbo_mode) SDL_Delay(0); - - system_frame (0); - frame_count++; - } - - frameticker--; - - /* Sound Update */ - audio_update(snd.buffer_size); - if (use_sound) sdl_sound_update(); - - /* Video update */ - if(bitmap.viewport.changed) - { - 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; - if (config.ntsc) rect.w = (reg[12]&1) ? MD_NTSC_OUT_WIDTH(rect.w) : SMS_NTSC_OUT_WIDTH(rect.w); - - /* init NTSC filter */ - if (config.ntsc == 1) - { - sms_setup = sms_ntsc_composite; - md_setup = md_ntsc_composite; - sms_ntsc_init( &sms_ntsc, &sms_setup ); - md_ntsc_init( &md_ntsc, &md_setup ); - } - else if (config.ntsc == 2) - { - sms_setup = sms_ntsc_svideo; - md_setup = md_ntsc_svideo; - sms_ntsc_init( &sms_ntsc, &sms_setup ); - md_ntsc_init( &md_ntsc, &md_setup ); - } - else if (config.ntsc == 3) - { - sms_setup = sms_ntsc_rgb; - md_setup = md_ntsc_rgb; - sms_ntsc_init( &sms_ntsc, &sms_setup ); - md_ntsc_init( &md_ntsc, &md_setup ); - } - } - - display_output(); + SDL_SemWait(sdl_sync.sem_sync); } + } /* save SRAM */ @@ -431,97 +586,16 @@ int main (int argc, char **argv) fclose(f); } - if (use_sound) sdl_sound_close(); - SDL_FreeSurface(surface); - SDL_FreeSurface(screen); - SDL_Quit(); system_shutdown(); audio_shutdown(); error_shutdown(); free(cart.rom); + sdl_video_close(); + if (use_sound) + sdl_sound_close(); + sdl_sync_close(); + SDL_Quit(); + return 0; } - -int update_input(void) -{ - keystate = SDL_GetKeyState(NULL); - - while (input.dev[joynum] == NO_DEVICE) - { - joynum ++; - if (joynum > MAX_DEVICES - 1) joynum = 0; - } - - /* reset input */ - input.pad[joynum] = 0; - - /* keyboard */ - if(keystate[SDLK_UP]) input.pad[joynum] |= INPUT_UP; - else - if(keystate[SDLK_DOWN]) input.pad[joynum] |= INPUT_DOWN; - if(keystate[SDLK_LEFT]) input.pad[joynum] |= INPUT_LEFT; - else - if(keystate[SDLK_RIGHT]) input.pad[joynum] |= INPUT_RIGHT; - - if(keystate[SDLK_a]) input.pad[joynum] |= INPUT_A; - if(keystate[SDLK_s]) input.pad[joynum] |= INPUT_B; - if(keystate[SDLK_d]) input.pad[joynum] |= INPUT_C; - if(keystate[SDLK_f]) input.pad[joynum] |= INPUT_START; - if(keystate[SDLK_z]) input.pad[joynum] |= INPUT_X; - if(keystate[SDLK_x]) input.pad[joynum] |= INPUT_Y; - if(keystate[SDLK_c]) input.pad[joynum] |= INPUT_Z; - if(keystate[SDLK_v]) input.pad[joynum] |= INPUT_MODE; - - if (input.dev[joynum] == DEVICE_LIGHTGUN) - { - /* get mouse (absolute values) */ - int x,y; - int state = SDL_GetMouseState(&x,&y); - - /* Calculate X Y axis values */ - input.analog[joynum - 4][0] = (x * bitmap.viewport.w) / 640; - input.analog[joynum - 4][1] = (y * bitmap.viewport.h) / 480; - - /* Map mouse buttons to player #1 inputs */ - if(state & SDL_BUTTON_MMASK) input.pad[joynum] |= INPUT_C; - if(state & SDL_BUTTON_RMASK) input.pad[joynum] |= INPUT_B; - if(state & SDL_BUTTON_LMASK) input.pad[joynum] |= INPUT_A; - } - else if (input.dev[joynum] == DEVICE_MOUSE) -{ - /* get mouse (relative values) */ - int x,y; - int state = SDL_GetRelativeMouseState(&x,&y); - - /* Sega Mouse range is -256;+256 */ - input.analog[2][0] = x; - input.analog[2][1] = y; - - /* Vertical movement is upsidedown */ - if (!config.invert_mouse) input.analog[2][1] = 0 - input.analog[2][1]; - - /* Map mouse buttons to player #1 inputs */ - if(state & SDL_BUTTON_MMASK) input.pad[joynum] |= INPUT_C; - if(state & SDL_BUTTON_RMASK) input.pad[joynum] |= INPUT_B; - if(state & SDL_BUTTON_LMASK) input.pad[joynum] |= INPUT_A; - } - else if (system_hw == SYSTEM_PICO) - { - /* get mouse (absolute values) */ - int x,y; - int state = SDL_GetMouseState(&x,&y); - - /* Calculate X Y axis values */ - input.analog[0][0] = 0x3c + (x * (0x17c-0x03c+1)) / 640; - input.analog[0][1] = 0x1fc + (y * (0x2f7-0x1fc+1)) / 480; - - /* Map mouse buttons to player #1 inputs */ - if(state & SDL_BUTTON_MMASK) pico_current++; - if(state & SDL_BUTTON_RMASK) input.pad[joynum] |= INPUT_B; - if(state & SDL_BUTTON_LMASK) input.pad[joynum] |= INPUT_A; - } - - /* options */ - return (1); -} diff --git a/source/unused/win/main.h b/source/unused/win/main.h index af3fd5e..e2e531f 100644 --- a/source/unused/win/main.h +++ b/source/unused/win/main.h @@ -4,7 +4,7 @@ #define MAX_INPUTS 8 -extern uint8 debug_on; -extern uint8 log_error; +extern int debug_on; +extern int log_error; #endif /* _MAIN_H_ */ diff --git a/source/unused/win/osd.h b/source/unused/win/osd.h index f250a31..2ec2e2d 100644 --- a/source/unused/win/osd.h +++ b/source/unused/win/osd.h @@ -18,6 +18,8 @@ #include "unzip.h" #include "fileio.h" +#define osd_input_Update sdl_input_update + #define GG_ROM "./ggenie.bin" #define AR_ROM "./areplay.bin" #define OS_ROM "./bios.bin"