From aeb3a98df2bfd1aea15e9dfc2aa21eea21c79d47 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Sun, 1 Jul 2018 16:30:58 +0100 Subject: [PATCH 1/5] [SDL] don't include libchdr The makefiles don't reference any of its sources, leading to build errors. I'd fix this myself, but even when adding the relevant sources, I get errors about multiply-defined types. --- sdl/Makefile.sdl1 | 2 +- sdl/Makefile.sdl2 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sdl/Makefile.sdl1 b/sdl/Makefile.sdl1 index 51e4d9c..1bc2c25 100644 --- a/sdl/Makefile.sdl1 +++ b/sdl/Makefile.sdl1 @@ -32,7 +32,7 @@ CFLAGS = `sdl-config --cflags` -march=i686 -O6 -fomit-frame-pointer -Wall -Wn #-g -ggdb -pg #-fomit-frame-pointer #LDFLAGS = -pg -DEFINES = -DLSB_FIRST -DUSE_16BPP_RENDERING -DUSE_LIBTREMOR -DUSE_LIBCHDR -DMAXROMSIZE=33554432 -DHAVE_YM3438_CORE +DEFINES = -DLSB_FIRST -DUSE_16BPP_RENDERING -DUSE_LIBTREMOR -DMAXROMSIZE=33554432 -DHAVE_YM3438_CORE ifneq ($(OS),Windows_NT) DEFINES += -DHAVE_ALLOCA_H diff --git a/sdl/Makefile.sdl2 b/sdl/Makefile.sdl2 index 52543c9..ae10b68 100644 --- a/sdl/Makefile.sdl2 +++ b/sdl/Makefile.sdl2 @@ -32,7 +32,7 @@ CFLAGS = `sdl2-config --cflags` -march=i686 -O6 -fomit-frame-pointer -Wall -W #-g -ggdb -pg #-fomit-frame-pointer #LDFLAGS = -pg -DEFINES = -DLSB_FIRST -DUSE_16BPP_RENDERING -DUSE_LIBTREMOR -DUSE_LIBCHDR -DMAXROMSIZE=33554432 -DHAVE_YM3438_CORE +DEFINES = -DLSB_FIRST -DUSE_16BPP_RENDERING -DUSE_LIBTREMOR -DMAXROMSIZE=33554432 -DHAVE_YM3438_CORE ifneq ($(OS),Windows_NT) DEFINES += -DHAVE_ALLOCA_H From cb5b682872996b24be51661ec8ecbb3c57c63fab Mon Sep 17 00:00:00 2001 From: Clownacy Date: Sun, 1 Jul 2018 16:40:36 +0100 Subject: [PATCH 2/5] [SDL] don't accept alternate audio formats On my PC, the SDL2 build doesn't 'obtain' the S16 format it requests, but since the rest of the SDL2 frontend expects S16, this causes the audio to fail. So, instead, I force SDL to accept S16, and just convert to the native format implicitly. I also applied this to every sound format setting, since I imagine the frontend doesn't support obtaining only one channel, or a non 48kHz frequency. --- sdl/sdl1/main.c | 9 ++------- sdl/sdl2/main.c | 9 ++------- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/sdl/sdl1/main.c b/sdl/sdl1/main.c index 6831229..c4ab724 100644 --- a/sdl/sdl1/main.c +++ b/sdl/sdl1/main.c @@ -66,7 +66,7 @@ static void sdl_sound_callback(void *userdata, Uint8 *stream, int len) static int sdl_sound_init() { int n; - SDL_AudioSpec as_desired, as_obtained; + SDL_AudioSpec as_desired; if(SDL_Init(SDL_INIT_AUDIO) < 0) { MessageBox(NULL, "SDL Audio initialization failed", "Error", 0); @@ -79,16 +79,11 @@ static int sdl_sound_init() as_desired.samples = SOUND_SAMPLES_SIZE; as_desired.callback = sdl_sound_callback; - if(SDL_OpenAudio(&as_desired, &as_obtained) == -1) { + if(SDL_OpenAudio(&as_desired, NULL) == -1) { MessageBox(NULL, "SDL Audio open failed", "Error", 0); return 0; } - if(as_desired.samples != as_obtained.samples) { - MessageBox(NULL, "SDL Audio wrong setup", "Error", 0); - return 0; - } - sdl_sound.current_emulated_samples = 0; n = SOUND_SAMPLES_SIZE * 2 * sizeof(short) * 20; sdl_sound.buffer = (char*)malloc(n); diff --git a/sdl/sdl2/main.c b/sdl/sdl2/main.c index 7224276..6489ca8 100644 --- a/sdl/sdl2/main.c +++ b/sdl/sdl2/main.c @@ -69,7 +69,7 @@ static void sdl_sound_callback(void *userdata, Uint8 *stream, int len) static int sdl_sound_init() { int n; - SDL_AudioSpec as_desired, as_obtained; + SDL_AudioSpec as_desired; if(SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) { SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", "SDL Audio initialization failed", sdl_video.window); @@ -82,16 +82,11 @@ static int sdl_sound_init() as_desired.samples = SOUND_SAMPLES_SIZE; as_desired.callback = sdl_sound_callback; - if(SDL_OpenAudio(&as_desired, &as_obtained) == -1) { + if(SDL_OpenAudio(&as_desired, NULL) == -1) { SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", "SDL Audio open failed", sdl_video.window); return 0; } - if(as_desired.samples != as_obtained.samples) { - SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", "SDL Audio wrong setup", sdl_video.window); - return 0; - } - sdl_sound.current_emulated_samples = 0; n = SOUND_SAMPLES_SIZE * 2 * sizeof(short) * 20; sdl_sound.buffer = (char*)malloc(n); From 6e9cb90da4bb98d8cfe4dc17a1991d615969039a Mon Sep 17 00:00:00 2001 From: Clownacy Date: Sun, 1 Jul 2018 21:33:30 +0100 Subject: [PATCH 3/5] [SDL] SDL_OpenAudio returns negative error codes in SDL2 SDL1.2 just returns -1, which this code was still checking for --- sdl/sdl2/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdl/sdl2/main.c b/sdl/sdl2/main.c index 6489ca8..52d4b83 100644 --- a/sdl/sdl2/main.c +++ b/sdl/sdl2/main.c @@ -82,7 +82,7 @@ static int sdl_sound_init() as_desired.samples = SOUND_SAMPLES_SIZE; as_desired.callback = sdl_sound_callback; - if(SDL_OpenAudio(&as_desired, NULL) == -1) { + if(SDL_OpenAudio(&as_desired, NULL) < 0) { SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", "SDL Audio open failed", sdl_video.window); return 0; } From 0569355cb52acb2d39c65261d6e1207b53a48786 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Sun, 1 Jul 2018 22:40:30 +0100 Subject: [PATCH 4/5] [SDL] make SDL2 build support 8, 15, and 32BPP rendering --- sdl/sdl2/main.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/sdl/sdl2/main.c b/sdl/sdl2/main.c index 52d4b83..daf0b90 100644 --- a/sdl/sdl2/main.c +++ b/sdl/sdl2/main.c @@ -134,13 +134,23 @@ sms_ntsc_t *sms_ntsc; static int sdl_video_init() { +#if defined(USE_8BPP_RENDERING) + const unsigned long surface_format = SDL_PIXELFORMAT_RGB332; +#elif defined(USE_15BPP_RENDERING) + const unsigned long surface_format = SDL_PIXELFORMAT_RGB555; +#elif defined(USE_16BPP_RENDERING) + const unsigned long surface_format = SDL_PIXELFORMAT_RGB565; +#elif defined(USE_32BPP_RENDERING) + const unsigned long surface_format = SDL_PIXELFORMAT_RGB888; +#endif + if(SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) { SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", "SDL Video initialization failed", sdl_video.window); return 0; } sdl_video.window = SDL_CreateWindow("Genesis Plus GX", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, VIDEO_WIDTH, VIDEO_HEIGHT, 0); sdl_video.surf_screen = SDL_GetWindowSurface(sdl_video.window); - sdl_video.surf_bitmap = SDL_CreateRGBSurface(SDL_SWSURFACE, 720, 576, 16, 0, 0, 0, 0); + sdl_video.surf_bitmap = SDL_CreateRGBSurfaceWithFormat(SDL_SWSURFACE, 720, 576, SDL_BITSPERPIXEL(surface_format), surface_format); sdl_video.frames_rendered = 0; SDL_ShowCursor(0); return 1; From b68d016aa53df3421831ea3856baacb81cfe4f76 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Sun, 1 Jul 2018 23:44:24 +0100 Subject: [PATCH 5/5] [SDL] fixed fullscreen in SDL2 build --- sdl/sdl2/main.c | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/sdl/sdl2/main.c b/sdl/sdl2/main.c index daf0b90..6121f71 100644 --- a/sdl/sdl2/main.c +++ b/sdl/sdl2/main.c @@ -148,7 +148,7 @@ static int sdl_video_init() SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", "SDL Video initialization failed", sdl_video.window); return 0; } - sdl_video.window = SDL_CreateWindow("Genesis Plus GX", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, VIDEO_WIDTH, VIDEO_HEIGHT, 0); + sdl_video.window = SDL_CreateWindow("Genesis Plus GX", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, VIDEO_WIDTH, VIDEO_HEIGHT, fullscreen); sdl_video.surf_screen = SDL_GetWindowSurface(sdl_video.window); sdl_video.surf_bitmap = SDL_CreateRGBSurfaceWithFormat(SDL_SWSURFACE, 720, 576, SDL_BITSPERPIXEL(surface_format), surface_format); sdl_video.frames_rendered = 0; @@ -181,22 +181,22 @@ static void sdl_video_update() sdl_video.srect.h = bitmap.viewport.h+2*bitmap.viewport.y; sdl_video.srect.x = 0; sdl_video.srect.y = 0; - if (sdl_video.srect.w > VIDEO_WIDTH) + if (sdl_video.srect.w > sdl_video.surf_screen->w) { - sdl_video.srect.x = (sdl_video.srect.w - VIDEO_WIDTH) / 2; - sdl_video.srect.w = VIDEO_WIDTH; + sdl_video.srect.x = (sdl_video.srect.w - sdl_video.surf_screen->w) / 2; + sdl_video.srect.w = sdl_video.surf_screen->w; } - if (sdl_video.srect.h > VIDEO_HEIGHT) + if (sdl_video.srect.h > sdl_video.surf_screen->h) { - sdl_video.srect.y = (sdl_video.srect.h - VIDEO_HEIGHT) / 2; - sdl_video.srect.h = VIDEO_HEIGHT; + sdl_video.srect.y = (sdl_video.srect.h - sdl_video.surf_screen->h) / 2; + sdl_video.srect.h = sdl_video.surf_screen->h; } /* destination bitmap */ sdl_video.drect.w = sdl_video.srect.w; sdl_video.drect.h = sdl_video.srect.h; - sdl_video.drect.x = (VIDEO_WIDTH - sdl_video.drect.w) / 2; - sdl_video.drect.y = (VIDEO_HEIGHT - sdl_video.drect.h) / 2; + sdl_video.drect.x = (sdl_video.surf_screen->w - sdl_video.drect.w) / 2; + sdl_video.drect.y = (sdl_video.surf_screen->h - sdl_video.drect.h) / 2; /* clear destination surface */ SDL_FillRect(sdl_video.surf_screen, 0, 0); @@ -334,7 +334,9 @@ static int sdl_control_update(SDL_Keycode keystate) case SDLK_F2: { fullscreen = (fullscreen ? 0 : SDL_WINDOW_FULLSCREEN); - SDL_SetWindowFullscreen(sdl_video.window, fullscreen); + SDL_SetWindowFullscreen(sdl_video.window, fullscreen); + sdl_video.surf_screen = SDL_GetWindowSurface(sdl_video.window); + bitmap.viewport.changed = 1; break; } @@ -507,10 +509,10 @@ int sdl_input_update(void) int state = SDL_GetMouseState(&x,&y); /* X axis */ - input.analog[joynum][0] = x - (VIDEO_WIDTH-bitmap.viewport.w)/2; + input.analog[joynum][0] = x - (sdl_video.surf_screen->w-bitmap.viewport.w)/2; /* Y axis */ - input.analog[joynum][1] = y - (VIDEO_HEIGHT-bitmap.viewport.h)/2; + input.analog[joynum][1] = y - (sdl_video.surf_screen->h-bitmap.viewport.h)/2; /* TRIGGER, B, C (Menacer only), START (Menacer & Justifier only) */ if(state & SDL_BUTTON_LMASK) input.pad[joynum] |= INPUT_A; @@ -527,7 +529,7 @@ int sdl_input_update(void) int state = SDL_GetMouseState(&x, NULL); /* Range is [0;256], 128 being middle position */ - input.analog[joynum][0] = x * 256 /VIDEO_WIDTH; + input.analog[joynum][0] = x * 256 /sdl_video.surf_screen->w; /* Button I -> 0 0 0 0 0 0 0 I*/ if(state & SDL_BUTTON_LMASK) input.pad[joynum] |= INPUT_B; @@ -622,8 +624,8 @@ int sdl_input_update(void) int state = SDL_GetMouseState(&x,&y); /* Calculate X Y axis values */ - input.analog[0][0] = 0x3c + (x * (0x17c-0x03c+1)) / VIDEO_WIDTH; - input.analog[0][1] = 0x1fc + (y * (0x2f7-0x1fc+1)) / VIDEO_HEIGHT; + input.analog[0][0] = 0x3c + (x * (0x17c-0x03c+1)) / sdl_video.surf_screen->w; + input.analog[0][1] = 0x1fc + (y * (0x2f7-0x1fc+1)) / sdl_video.surf_screen->h; /* Map mouse buttons to player #1 inputs */ if(state & SDL_BUTTON_MMASK) pico_current = (pico_current + 1) & 7; @@ -640,8 +642,8 @@ int sdl_input_update(void) int state = SDL_GetMouseState(&x,&y); /* Calculate X Y axis values */ - input.analog[0][0] = (x * 250) / VIDEO_WIDTH; - input.analog[0][1] = (y * 250) / VIDEO_HEIGHT; + input.analog[0][0] = (x * 250) / sdl_video.surf_screen->w; + input.analog[0][1] = (y * 250) / sdl_video.surf_screen->h; /* Map mouse buttons to player #1 inputs */ if(state & SDL_BUTTON_RMASK) input.pad[0] |= INPUT_B; @@ -656,8 +658,8 @@ int sdl_input_update(void) int state = SDL_GetMouseState(&x,&y); /* Calculate X Y axis values */ - input.analog[0][0] = (x * 255) / VIDEO_WIDTH; - input.analog[0][1] = (y * 255) / VIDEO_HEIGHT; + input.analog[0][0] = (x * 255) / sdl_video.surf_screen->w; + input.analog[0][1] = (y * 255) / sdl_video.surf_screen->h; /* Map mouse buttons to player #1 inputs */ if(state & SDL_BUTTON_LMASK) input.pad[0] |= INPUT_GRAPHIC_PEN;