updated SDL/DOS port

This commit is contained in:
ekeeke31 2008-08-24 19:58:37 +00:00
parent fb9c8eeb19
commit 201c5eb922
4 changed files with 157 additions and 94 deletions

View File

@ -76,7 +76,7 @@ void set_option_defaults(void)
option.video_height = 480; option.video_height = 480;
option.video_depth = 16; option.video_depth = 16;
option.remap = 1; option.remap = 0;
option.scanlines = 0; option.scanlines = 0;
option.scale = 0; option.scale = 0;

View File

@ -75,10 +75,9 @@ int main (int argc, char *argv[])
return (0); return (0);
} }
/* load BIOS */ /* load BIOS */
memset(bios_rom, 0, sizeof(bios_rom)); memset(bios_rom, 0, sizeof(bios_rom));
f = fopen("./BIOS.bin", "rb"); FILE *f = fopen("./BIOS.bin", "rb");
if (f!=NULL) if (f!=NULL)
{ {
fread(&bios_rom, 0x800,1,f); fread(&bios_rom, 0x800,1,f);
@ -90,7 +89,7 @@ int main (int argc, char *argv[])
bios_rom[i] = bios_rom[i+1]; bios_rom[i] = bios_rom[i+1];
bios_rom[i+1] = temp; bios_rom[i+1] = temp;
} }
config.bios_enabled = 3; config.bios_enabled |= 2;
} }
else config.bios_enabled = 0; else config.bios_enabled = 0;
@ -103,11 +102,6 @@ int main (int argc, char *argv[])
input.system[1] = SYSTEM_GAMEPAD; input.system[1] = SYSTEM_GAMEPAD;
/* initialize emulation */ /* initialize emulation */
int buf_len = (option.sndrate * 4) / vdp_rate;
snd.buffer[0] = malloc (buf_len/2);
snd.buffer[1] = malloc (buf_len/2);
memset (snd.buffer[0], 0, buf_len/2);
memset (snd.buffer[1], 0, buf_len/2);
system_init(); system_init();
audio_init(option.sndrate); audio_init(option.sndrate);
@ -117,8 +111,8 @@ int main (int argc, char *argv[])
fread(&sram.sram,0x10000,1, f); fread(&sram.sram,0x10000,1, f);
fclose(f); fclose(f);
} }
/* reset emulation */
system_reset(); system_reset();
/* emulation loop */ /* emulation loop */
@ -137,8 +131,6 @@ int main (int argc, char *argv[])
system_frame(1); system_frame(1);
} }
if(option.sound) dos_update_audio(); if(option.sound) dos_update_audio();
//error("%d\n", frame_rate);
} }
f = fopen("./game.srm", "wb"); f = fopen("./game.srm", "wb");
@ -151,6 +143,8 @@ int main (int argc, char *argv[])
trash_machine(); trash_machine();
system_shutdown(); system_shutdown();
error_shutdown(); error_shutdown();
free(cart_rom);
return (0); return (0);
} }
@ -279,10 +273,8 @@ void dos_update_input(void)
if(key[KEY_X]) input.pad[joynum] |= INPUT_Y; if(key[KEY_X]) input.pad[joynum] |= INPUT_Y;
if(key[KEY_C]) input.pad[joynum] |= INPUT_Z; if(key[KEY_C]) input.pad[joynum] |= INPUT_Z;
if(key[KEY_V]) input.pad[joynum] |= INPUT_MODE; if(key[KEY_V]) input.pad[joynum] |= INPUT_MODE;
if(key[KEY_F]) input.pad[joynum] |= INPUT_START;
if(key[KEY_F]) input.pad[joynum] |= INPUT_START;
extern uint8 pico_current; extern uint8 pico_current;
if (input.dev[joynum] == DEVICE_LIGHTGUN) if (input.dev[joynum] == DEVICE_LIGHTGUN)
{ {
@ -301,8 +293,8 @@ void dos_update_input(void)
} }
else if (input.dev[joynum] == DEVICE_MOUSE) else if (input.dev[joynum] == DEVICE_MOUSE)
{ {
/* Poll mouse if necessary */ /* Poll mouse if necessary */
if(mouse_needs_poll() == TRUE) if(mouse_needs_poll() == TRUE)
poll_mouse(); poll_mouse();
/* Get X & Y quantity of movement */ /* Get X & Y quantity of movement */
@ -387,10 +379,7 @@ void dos_update_input(void)
bitmap.viewport.changed = 1; bitmap.viewport.changed = 1;
} }
if(check_key(KEY_F10)) if(check_key(KEY_F10)) system_reset();
system_reset();
if(check_key(KEY_TAB)) set_softreset(); if(check_key(KEY_TAB)) set_softreset();
} }
@ -400,7 +389,8 @@ void dos_update_audio(void)
osd_play_streamed_sample_16(option.swap ^ 1, snd.buffer[1], snd.buffer_size * 2, option.sndrate, FRAMES_PER_SECOND, 100); osd_play_streamed_sample_16(option.swap ^ 1, snd.buffer[1], snd.buffer_size * 2, option.sndrate, FRAMES_PER_SECOND, 100);
} }
/*void dos_update_palette(void) #if 0
void dos_update_palette(void)
{ {
if(is_border_dirty) if(is_border_dirty)
{ {
@ -458,7 +448,8 @@ void dos_update_audio(void)
} }
} }
} }
}*/ }
#endif
void dos_update_video(void) void dos_update_video(void)
{ {
@ -483,11 +474,12 @@ void dos_update_video(void)
} }
} }
/*if(bitmap.remap == 0) #if 0
if(bitmap.remap == 0)
{ {
dos_update_palette(); dos_update_palette();
}*/ }
#endif
msg_print(2, 2, "offset = 0x%x", hc_latch/*frame_rate*/); msg_print(2, 2, "offset = 0x%x", hc_latch/*frame_rate*/);
@ -501,10 +493,7 @@ void dos_update_video(void)
} }
else else
{ {
stretch_blit(gen_bmp, screen, 0, 0, width, height, (SCREEN_W-352)/2, (SCREEN_H-240)/2, 352,240 << (interlaced ? 1:0));
//blit(gen_bmp, screen, 0x0, 0, center_x, center_y, width, height);
stretch_blit(gen_bmp, screen, 0, 0, width, height, (SCREEN_W-352)/2, (SCREEN_H-240)/2, 352,240 << (interlaced ? 1:0));
} }
} }

View File

@ -1,3 +1,3 @@
COmpile with DJGPP. Compile with DJGPP.
You will also need to install Allegro and Seal libraries. You will also need to install Allegro and Seal libraries.
Zlib is required for zipped rom support. Zlib is required for zipped rom support.

View File

@ -3,6 +3,8 @@
#include <SDL.h> #include <SDL.h>
#include "shared.h" #include "shared.h"
#define SOUND_FREQUENCY 48000
int timer_count = 0; int timer_count = 0;
int old_timer_count = 0; int old_timer_count = 0;
int paused = 0; int paused = 0;
@ -14,10 +16,36 @@ int update_input(void);
unsigned char *keystate; unsigned char *keystate;
unsigned char buf[0x24000]; unsigned char buf[0x24000];
uint8 log_error = 0; SDL_AudioSpec audio;
uint8 debug_on = 0; static uint8 soundbuffer[2][3840];
static uint8 mixbuffer[16000];
static int mixhead = 0;
static int mixtail = 0;
static int whichab = 0;
uint8 log_error = 1;
uint8 debug_on = 0;
uint8 turbo_mode = 0; uint8 turbo_mode = 0;
static int mixercollect( uint8 *outbuffer, int len )
{
uint32 *dst = (uint32 *)outbuffer;
uint32 *src = (uint32 *)mixbuffer;
int done = 0;
/*** Always clear output buffer ***/
memset(outbuffer, 0, len);
while ( ( mixtail != mixhead ) && ( done < len ) )
{
*dst++ = src[mixtail++];
if (mixtail == 4000) mixtail = 0;
done += 4;
}
return done;
}
Uint32 fps_callback(Uint32 interval) Uint32 fps_callback(Uint32 interval)
{ {
if(paused) return 1000/vdp_rate; if(paused) return 1000/vdp_rate;
@ -39,6 +67,48 @@ Uint32 fps_callback(Uint32 interval)
return 1000/vdp_rate; return 1000/vdp_rate;
} }
static void sdl_sound_callback(void *userdata, Uint8 *stream, int len)
{
int actuallen = mixercollect( soundbuffer[whichab], len );
memcpy(stream, soundbuffer[whichab], len);
whichab ^= 1;
}
int sdl_sound_init()
{
SDL_InitSubSystem(SDL_INIT_AUDIO);
SDL_AudioSpec as;
as.freq = SOUND_FREQUENCY;
as.format = AUDIO_S16;
as.channels = 2;
as.samples = SOUND_FREQUENCY/vdp_rate;
as.callback = sdl_sound_callback;
if(SDL_OpenAudio(&as, 0) == -1) {
char caption[256];
sprintf(caption, "can't open audio");
MessageBox(NULL, caption, "Error", 0);
return 0;
}
return 1;
}
static void sdl_sound_update()
{
int i;
// SDL_LockAudio();
uint32 *dst = (uint32 *)mixbuffer;
for(i = 0; i < snd.buffer_size; ++i)
{
dst[mixhead++] = (snd.buffer[0][i] << 16) | snd.buffer[1][i];
if (mixhead == 4000) mixhead = 0;
}
// SDL_UnlockAudio();
}
int main (int argc, char **argv) int main (int argc, char **argv)
{ {
@ -85,32 +155,36 @@ int main (int argc, char **argv)
bios_rom[i] = bios_rom[i+1]; bios_rom[i] = bios_rom[i+1];
bios_rom[i+1] = temp; bios_rom[i+1] = temp;
} }
config.bios_enabled = 3; config.bios_enabled |= 2;
} }
else config.bios_enabled = 0; else config.bios_enabled = 0;
/* initialize SDL */ /* initialize SDL */
viewport.x = 0;
viewport.y = 0;
viewport.w = 640;
viewport.h = 480;
src.x = 0;
src.y = 0;
src.w = viewport.w;
src.h = viewport.h;
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0) 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); exit(1);
} }
SDL_WM_SetCaption("Genesis Plus/SDL", NULL); SDL_WM_SetCaption("Genesis Plus/SDL", NULL);
screen = SDL_SetVideoMode(viewport.w, viewport.h, 16, SDL_HWSURFACE); SDL_ShowCursor(0);
viewport.x = 0;
viewport.y = 0;
/* initialize SDL video */
viewport.w = 640;
viewport.h = 480;
screen = SDL_SetVideoMode(viewport.w, viewport.h, 16, SDL_ANYFORMAT | SDL_HWPALETTE | SDL_HWSURFACE/* | SDL_FULLSCREEN*/);
bmp = SDL_CreateRGBSurface(SDL_SWSURFACE, 360, 576, 16, 0xF800, 0x07E0, 0x001F, 0x0000); bmp = SDL_CreateRGBSurface(SDL_SWSURFACE, 360, 576, 16, 0xF800, 0x07E0, 0x001F, 0x0000);
if (!bmp || !screen)
{
char caption[256];
sprintf(caption, "Video initialization failed");
MessageBox(NULL, caption, "Error", 0);
exit(1);
}
/* initialize Genesis screen */ /* initialize Genesis display */
memset(&bitmap, 0, sizeof(t_bitmap)); memset(&bitmap, 0, sizeof(t_bitmap));
bitmap.width = 360; bitmap.width = 360;
bitmap.height = 576; bitmap.height = 576;
@ -124,36 +198,32 @@ int main (int argc, char **argv)
bitmap.viewport.y = 0; bitmap.viewport.y = 0;
bitmap.remap = 1; bitmap.remap = 1;
/* default config */ /* set default config */
set_config_defaults(); set_config_defaults();
input.system[0] = SYSTEM_GAMEPAD; input.system[0] = SYSTEM_GAMEPAD;
input.system[1] = SYSTEM_GAMEPAD; input.system[1] = SYSTEM_GAMEPAD;
/* initialize emulation */ /* initialize emulation */
system_init(); system_init();
int buf_len = (48000 * 4) / vdp_rate; audio_init(SOUND_FREQUENCY);
snd.buffer[0] = malloc (buf_len/2);
snd.buffer[1] = malloc (buf_len/2); /* initialize SDL audio */
memset (snd.buffer[0], 0, buf_len/2); //sdl_sound_init();
memset (snd.buffer[1], 0, buf_len/2);
audio_init(48000);
/* load SRAM */ /* load SRAM */
f = fopen("./game.srm", "rb"); f = fopen("./game.srm", "rb");
if (f!=NULL) if (f!=NULL)
{ {
fread(&sram.sram,0x10000,1, f); fread(&sram.sram,0x10000,1, f);
fclose(f); fclose(f);
} }
/* reset emulation */ /* reset emulation */
system_reset(); system_reset();
/* emulation loop */ /* start emulation loop */
SDL_SetTimer(1000/vdp_rate, fps_callback); SDL_SetTimer(1000/vdp_rate, fps_callback);
SDL_ShowCursor(0); //SDL_PauseAudio(1);
int now, prev = SDL_GetTicks();
while(running) while(running)
{ {
@ -169,6 +239,7 @@ int main (int argc, char **argv)
if(event.active.state & (SDL_APPINPUTFOCUS | SDL_APPACTIVE)) if(event.active.state & (SDL_APPINPUTFOCUS | SDL_APPACTIVE))
{ {
paused = !event.active.gain; paused = !event.active.gain;
//SDL_PauseAudio(paused);
} }
break; break;
@ -176,8 +247,8 @@ int main (int argc, char **argv)
sym = event.key.keysym.sym; sym = event.key.keysym.sym;
if(sym == SDLK_TAB) system_reset(); if(sym == SDLK_TAB) system_reset();
if(sym == SDLK_F5) log_error ^=1; else if(sym == SDLK_F5) log_error ^=1;
if(sym == SDLK_F6) else if(sym == SDLK_F6)
{ {
turbo_mode ^=1; turbo_mode ^=1;
frameticker = 0; frameticker = 0;
@ -208,7 +279,7 @@ int main (int argc, char **argv)
/* reinitialize timings */ /* reinitialize timings */
system_init (); system_init ();
audio_init(48000); audio_init(audio.freq);
fm_restore(); fm_restore();
/* reinitialize HVC tables */ /* reinitialize HVC tables */
@ -243,11 +314,11 @@ int main (int argc, char **argv)
default: default:
break; break;
} }
} }
if(!paused) if(!paused)
{ {
if (frameticker > 1) if (frameticker > 1)
{ {
/* Frame skipping */ /* Frame skipping */
@ -257,39 +328,42 @@ int main (int argc, char **argv)
else else
{ {
/* Delay */ /* Delay */
while (!frameticker && !turbo_mode) SDL_Delay(1); while (!frameticker && !turbo_mode) SDL_Delay(0);
system_frame (0); system_frame (0);
frame_count++; frame_count++;
} }
frameticker--; frameticker--;
if(bitmap.viewport.changed) if(bitmap.viewport.changed)
{ {
bitmap.viewport.changed = 0; bitmap.viewport.changed = 0;
src.w = (bitmap.viewport.w + 2 * bitmap.viewport.x); src.w = (bitmap.viewport.w + 2 * bitmap.viewport.x);
src.h = (bitmap.viewport.w + 2*bitmap.viewport.x) << ((config.render && interlaced) ? 1:0); src.h = (bitmap.viewport.h + 2 * bitmap.viewport.y) << ((config.render && interlaced) ? 1:0);
viewport.w = bitmap.viewport.w + 2*bitmap.viewport.x;
viewport.h = bitmap.viewport.h + 2*bitmap.viewport.y;
viewport.x = (640 - viewport.w)/2;
viewport.y = ((480 - viewport.h)/2);
}
viewport.w = bitmap.viewport.w + 2*bitmap.viewport.x; sdl_sound_update();
viewport.h = bitmap.viewport.h + 2*bitmap.viewport.y; SDL_BlitSurface(bmp, &src, screen, &viewport);
viewport.x = (640 - viewport.w)/2;
viewport.y = ((480 - viewport.h)/2);
}
SDL_BlitSurface(bmp, &src, screen, &viewport);
//SDL_Flip(screen); //SDL_Flip(screen);
SDL_UpdateRect(screen, viewport.x, viewport.y, viewport.w, viewport.h); SDL_UpdateRect(screen, viewport.x, viewport.y, viewport.w, viewport.h);
}
} }
}
system_shutdown();
system_shutdown();
SDL_PauseAudio(1);
SDL_CloseAudio();
SDL_FreeSurface(bmp); SDL_FreeSurface(bmp);
SDL_FreeSurface(screen); SDL_FreeSurface(screen);
SDL_Quit(); SDL_Quit();
error_shutdown(); error_shutdown();
free(cart_rom);
return 0; return 0;
} }
int update_input(void) int update_input(void)
@ -297,7 +371,7 @@ int update_input(void)
keystate = SDL_GetKeyState(NULL); keystate = SDL_GetKeyState(NULL);
while (input.dev[joynum] == NO_DEVICE) while (input.dev[joynum] == NO_DEVICE)
{ {
joynum ++; joynum ++;
if (joynum > MAX_DEVICES - 1) joynum = 0; if (joynum > MAX_DEVICES - 1) joynum = 0;
} }
@ -312,7 +386,7 @@ int update_input(void)
if(keystate[SDLK_LEFT]) input.pad[joynum] |= INPUT_LEFT; if(keystate[SDLK_LEFT]) input.pad[joynum] |= INPUT_LEFT;
else else
if(keystate[SDLK_RIGHT]) input.pad[joynum] |= INPUT_RIGHT; if(keystate[SDLK_RIGHT]) input.pad[joynum] |= INPUT_RIGHT;
if(keystate[SDLK_a]) input.pad[joynum] |= INPUT_A; if(keystate[SDLK_a]) input.pad[joynum] |= INPUT_A;
if(keystate[SDLK_s]) input.pad[joynum] |= INPUT_B; if(keystate[SDLK_s]) input.pad[joynum] |= INPUT_B;
if(keystate[SDLK_d]) input.pad[joynum] |= INPUT_C; if(keystate[SDLK_d]) input.pad[joynum] |= INPUT_C;
@ -339,7 +413,7 @@ int update_input(void)
if(state & SDL_BUTTON_LMASK) input.pad[joynum] |= INPUT_A; if(state & SDL_BUTTON_LMASK) input.pad[joynum] |= INPUT_A;
} }
else if (input.dev[joynum] == DEVICE_MOUSE) else if (input.dev[joynum] == DEVICE_MOUSE)
{ {
/* get mouse (relative values) */ /* get mouse (relative values) */
int x,y; int x,y;
int state = SDL_GetRelativeMouseState(&x,&y); int state = SDL_GetRelativeMouseState(&x,&y);
@ -365,7 +439,7 @@ int update_input(void)
/* Calculate X Y axis values */ /* Calculate X Y axis values */
input.analog[0][0] = 0x3c + (x * (0x17c-0x03c+1)) / 640; input.analog[0][0] = 0x3c + (x * (0x17c-0x03c+1)) / 640;
input.analog[0][1] = 0x1fc + (y * (0x2f7-0x1fc+1)) / 480; input.analog[0][1] = 0x1fc + (y * (0x2f7-0x1fc+1)) / 480;
/* Map mouse buttons to player #1 inputs */ /* Map mouse buttons to player #1 inputs */
if(state & SDL_BUTTON_MMASK) pico_current++; if(state & SDL_BUTTON_MMASK) pico_current++;
if(state & SDL_BUTTON_RMASK) input.pad[joynum] |= INPUT_A; if(state & SDL_BUTTON_RMASK) input.pad[joynum] |= INPUT_A;