[SDL] use 'return' instead of 'exit' in main, removed useless buffer

This commit is contained in:
Clownacy 2016-10-20 23:26:58 +01:00
parent d01c8bed7d
commit 1cbf897ed1

View File

@ -14,7 +14,7 @@
#define SOUND_FREQUENCY 48000 #define SOUND_FREQUENCY 48000
#define SOUND_SAMPLES_SIZE 2048 #define SOUND_SAMPLES_SIZE 2048
#define VIDEO_WIDTH 320 #define VIDEO_WIDTH 320
#define VIDEO_HEIGHT 240 #define VIDEO_HEIGHT 240
int joynum = 0; int joynum = 0;
@ -67,7 +67,7 @@ static int sdl_sound_init()
{ {
int n; int n;
SDL_AudioSpec as_desired, as_obtained; SDL_AudioSpec as_desired, as_obtained;
if(SDL_Init(SDL_INIT_AUDIO) < 0) { if(SDL_Init(SDL_INIT_AUDIO) < 0) {
MessageBox(NULL, "SDL Audio initialization failed", "Error", 0); MessageBox(NULL, "SDL Audio initialization failed", "Error", 0);
return 0; return 0;
@ -104,7 +104,7 @@ static int sdl_sound_init()
static void sdl_sound_update(int enabled) static void sdl_sound_update(int enabled)
{ {
int size = audio_update(soundframe) * 2; int size = audio_update(soundframe) * 2;
if (enabled) if (enabled)
{ {
int i; int i;
@ -126,7 +126,7 @@ static void sdl_sound_close()
{ {
SDL_PauseAudio(1); SDL_PauseAudio(1);
SDL_CloseAudio(); SDL_CloseAudio();
if (sdl_sound.buffer) if (sdl_sound.buffer)
free(sdl_sound.buffer); free(sdl_sound.buffer);
} }
@ -196,7 +196,7 @@ static void sdl_video_update()
sdl_video.drect.h = sdl_video.srect.h; sdl_video.drect.h = sdl_video.srect.h;
sdl_video.drect.x = (VIDEO_WIDTH - sdl_video.drect.w) / 2; 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.y = (VIDEO_HEIGHT - sdl_video.drect.h) / 2;
/* clear destination surface */ /* clear destination surface */
SDL_FillRect(sdl_video.surf_screen, 0, 0); SDL_FillRect(sdl_video.surf_screen, 0, 0);
@ -304,7 +304,7 @@ static void sdl_sync_close()
SDL_DestroySemaphore(sdl_sync.sem_sync); SDL_DestroySemaphore(sdl_sync.sem_sync);
} }
static const uint16 vc_table[4][2] = static const uint16 vc_table[4][2] =
{ {
/* NTSC, PAL */ /* NTSC, PAL */
{0xDA , 0xF2}, /* Mode 4 (192 lines) */ {0xDA , 0xF2}, /* Mode 4 (192 lines) */
@ -496,7 +496,7 @@ int sdl_input_update(void)
/* reset input */ /* reset input */
input.pad[joynum] = 0; input.pad[joynum] = 0;
switch (input.dev[joynum]) switch (input.dev[joynum])
{ {
case DEVICE_LIGHTGUN: case DEVICE_LIGHTGUN:
@ -514,7 +514,7 @@ int sdl_input_update(void)
/* TRIGGER, B, C (Menacer only), START (Menacer & Justifier only) */ /* TRIGGER, B, C (Menacer only), START (Menacer & Justifier only) */
if(state & SDL_BUTTON_LMASK) input.pad[joynum] |= INPUT_A; if(state & SDL_BUTTON_LMASK) input.pad[joynum] |= INPUT_A;
if(state & SDL_BUTTON_RMASK) input.pad[joynum] |= INPUT_B; if(state & SDL_BUTTON_RMASK) input.pad[joynum] |= INPUT_B;
if(state & SDL_BUTTON_MMASK) input.pad[joynum] |= INPUT_C; if(state & SDL_BUTTON_MMASK) input.pad[joynum] |= INPUT_C;
if(keystate[SDLK_f]) input.pad[joynum] |= INPUT_START; if(keystate[SDLK_f]) input.pad[joynum] |= INPUT_START;
break; break;
} }
@ -585,7 +585,7 @@ int sdl_input_update(void)
if(keystate[SDLK_x]) input.pad[joynum] |= INPUT_X; if(keystate[SDLK_x]) input.pad[joynum] |= INPUT_X;
if(keystate[SDLK_c]) input.pad[joynum] |= INPUT_MODE; if(keystate[SDLK_c]) input.pad[joynum] |= INPUT_MODE;
if(keystate[SDLK_v]) input.pad[joynum] |= INPUT_Z; if(keystate[SDLK_v]) input.pad[joynum] |= INPUT_Z;
/* Left Analog Stick (bidirectional) */ /* Left Analog Stick (bidirectional) */
if(keystate[SDLK_UP]) input.analog[joynum][1]-=2; if(keystate[SDLK_UP]) input.analog[joynum][1]-=2;
else if(keystate[SDLK_DOWN]) input.analog[joynum][1]+=2; else if(keystate[SDLK_DOWN]) input.analog[joynum][1]+=2;
@ -623,7 +623,7 @@ int sdl_input_update(void)
/* Calculate X Y axis values */ /* Calculate X Y axis values */
input.analog[0][0] = 0x3c + (x * (0x17c-0x03c+1)) / VIDEO_WIDTH; 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][1] = 0x1fc + (y * (0x2f7-0x1fc+1)) / VIDEO_HEIGHT;
/* Map mouse buttons to player #1 inputs */ /* Map mouse buttons to player #1 inputs */
if(state & SDL_BUTTON_MMASK) pico_current = (pico_current + 1) & 7; if(state & SDL_BUTTON_MMASK) pico_current = (pico_current + 1) & 7;
if(state & SDL_BUTTON_RMASK) input.pad[0] |= INPUT_PICO_RED; if(state & SDL_BUTTON_RMASK) input.pad[0] |= INPUT_PICO_RED;
@ -641,7 +641,7 @@ int sdl_input_update(void)
/* Calculate X Y axis values */ /* Calculate X Y axis values */
input.analog[0][0] = (x * 250) / VIDEO_WIDTH; input.analog[0][0] = (x * 250) / VIDEO_WIDTH;
input.analog[0][1] = (y * 250) / VIDEO_HEIGHT; input.analog[0][1] = (y * 250) / VIDEO_HEIGHT;
/* Map mouse buttons to player #1 inputs */ /* Map mouse buttons to player #1 inputs */
if(state & SDL_BUTTON_RMASK) input.pad[0] |= INPUT_B; if(state & SDL_BUTTON_RMASK) input.pad[0] |= INPUT_B;
@ -657,7 +657,7 @@ int sdl_input_update(void)
/* Calculate X Y axis values */ /* Calculate X Y axis values */
input.analog[0][0] = (x * 255) / VIDEO_WIDTH; input.analog[0][0] = (x * 255) / VIDEO_WIDTH;
input.analog[0][1] = (y * 255) / VIDEO_HEIGHT; input.analog[0][1] = (y * 255) / VIDEO_HEIGHT;
/* Map mouse buttons to player #1 inputs */ /* Map mouse buttons to player #1 inputs */
if(state & SDL_BUTTON_LMASK) input.pad[0] |= INPUT_GRAPHIC_PEN; if(state & SDL_BUTTON_LMASK) input.pad[0] |= INPUT_GRAPHIC_PEN;
if(state & SDL_BUTTON_RMASK) input.pad[0] |= INPUT_GRAPHIC_MENU; if(state & SDL_BUTTON_RMASK) input.pad[0] |= INPUT_GRAPHIC_MENU;
@ -710,7 +710,7 @@ int main (int argc, char **argv)
char caption[256]; char caption[256];
sprintf(caption, "Genesis Plus GX\\SDL\nusage: %s gamename\n", argv[0]); sprintf(caption, "Genesis Plus GX\\SDL\nusage: %s gamename\n", argv[0]);
MessageBox(NULL, caption, "Information", 0); MessageBox(NULL, caption, "Information", 0);
exit(1); return 1;
} }
/* set default config */ /* set default config */
@ -750,10 +750,8 @@ int main (int argc, char **argv)
/* initialize SDL */ /* initialize SDL */
if(SDL_Init(0) < 0) if(SDL_Init(0) < 0)
{ {
char caption[256]; MessageBox(NULL, "SDL initialization failed", "Error", 0);
sprintf(caption, "SDL initialization failed"); return 1;
MessageBox(NULL, caption, "Error", 0);
exit(1);
} }
sdl_video_init(); sdl_video_init();
if (use_sound) sdl_sound_init(); if (use_sound) sdl_sound_init();
@ -783,7 +781,7 @@ int main (int argc, char **argv)
char caption[256]; char caption[256];
sprintf(caption, "Error loading file `%s'.", argv[1]); sprintf(caption, "Error loading file `%s'.", argv[1]);
MessageBox(NULL, caption, "Error", 0); MessageBox(NULL, caption, "Error", 0);
exit(1); return 1;
} }
/* initialize system hardware */ /* initialize system hardware */
@ -865,13 +863,13 @@ int main (int argc, char **argv)
while(running) while(running)
{ {
SDL_Event event; SDL_Event event;
if (SDL_PollEvent(&event)) if (SDL_PollEvent(&event))
{ {
switch(event.type) switch(event.type)
{ {
case SDL_USEREVENT: case SDL_USEREVENT:
{ {
char caption[100]; char caption[100];
sprintf(caption,"Genesis Plus GX - %d fps - %s", event.user.code, (rominfo.international[0] != 0x20) ? rominfo.international : rominfo.domestic); sprintf(caption,"Genesis Plus GX - %d fps - %s", event.user.code, (rominfo.international[0] != 0x20) ? rominfo.international : rominfo.domestic);
SDL_WM_SetCaption(caption, NULL); SDL_WM_SetCaption(caption, NULL);
break; break;