refactor out GP2X specific stuff completely
authornotaz <notasas@gmail.com>
Sun, 9 Sep 2012 23:17:38 +0000 (02:17 +0300)
committernotaz <notasas@gmail.com>
Sat, 15 Sep 2012 17:22:36 +0000 (20:22 +0300)
Makefile.sdl
drivers/common/main.c
drivers/common/sound-oss.c [new file with mode: 0644]
drivers/sdl/minimal.c [deleted file]
drivers/sdl/sdl.c

index 85da117..9e08fff 100644 (file)
@@ -1,10 +1,9 @@
-CROSS  = 
-CC     = $(CROSS)gcc
-STRIP  = $(CROSS)strip
+#CROSS_COMPILE =
+CC     = $(CROSS_COMPILE)gcc
+STRIP  = $(CROSS_COMPILE)strip
 TFLAGS  = -Winline -Izlib -DLSB_FIRST -DUNIX -DPSS_STYLE=1 -DHAVE_ASPRINTF -DZLIB -DFRAMESKIP -D_REENTRANT `sdl-config --cflags`
 RM     = rm -f
 C      = drivers/common/
-G      = drivers/gp2x/
 L      = drivers/libpicofe/
 
 DEBUG   = 1
@@ -26,10 +25,10 @@ all:                fceu
 
 include zlib/Makefile
 
-OBJDRIVER = drivers/sdl/sdl.o drivers/sdl/minimal.o drivers/sdl/throttle.o \
-       ${G}gp2x-sound.o ${G}gp2x-video.o ${G}usbjoy.o \
+OBJDRIVER = drivers/sdl/sdl.o drivers/sdl/throttle.o \
        ${L}fonts.o ${L}readpng.o ${L}input.o ${L}in_sdl.o ${L}linux/plat.o \
-       ${C}main.o ${C}menu.o \
+       ${L}linux/sndout_oss.o \
+       ${C}main.o ${C}menu.o ${C}sound-oss.o \
        ${C}cheat.o ${C}config.o ${C}args.o ${C}vidblit.o ${C}unix-netplay.o \
        ${UNZIPOBJS} \
        ppu.o movie.o fceu098.o ppu098.o
@@ -42,9 +41,6 @@ x6502.o: x6502.c x6502.h ops.h fce.h sound.h dprintf.h
 include Makefile.base
 
 ${C}menu.o:            ${C}revision.h
-${B}main.o:            ${B}main.c ${B}main.h ${B}usage.h ${B}input.c
-${B}gp2x.o:            ${B}gp2x.c ${B}gp2x.h ${B}rev.h
-${B}throttle.o:         ${B}throttle.c ${B}main.h ${B}throttle.h
 ppu.o:                 ppu.c ppu.h
 
 ${C}revision.h: FORCE
index 616b7c6..d9ee833 100644 (file)
@@ -413,7 +413,6 @@ int main(int argc, char *argv[])
         LoadConfig(NULL);
         last_arg_parsed=DoArgs(argc-1,&argv[1]);
        platform_late_init();
-       in_probe();
 
        LoadLLGN();
        FCEUI_SetNTSCTH(ntsccol, ntsctint, ntschue);
diff --git a/drivers/common/sound-oss.c b/drivers/common/sound-oss.c
new file mode 100644 (file)
index 0000000..864741b
--- /dev/null
@@ -0,0 +1,62 @@
+/* FCE Ultra - NES/Famicom Emulator
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <stdio.h>
+
+#include "../../driver.h"
+#include "../common/settings.h"
+#include "../common/throttle.h"
+#include "../libpicofe/linux/sndout_oss.h"
+
+
+extern int soundvol;
+
+void WriteSound(int16 *Buffer, int Count)
+{
+       sndout_oss_write_nb(Buffer, Count * 2);
+}
+
+void SilenceSound(int n)
+{
+       soundvol = 0;
+}
+
+int InitSound(void)
+{
+       FCEUI_Sound(Settings.sound_rate);
+       sndout_oss_init();
+       return 1;
+}
+
+uint32 GetMaxSound(void)
+{
+       return(4096);
+}
+
+uint32 GetWriteSound(void)
+{
+       return 1024;
+}
+
+void StartSound(void)
+{
+        sndout_oss_start(Settings.sound_rate, 0, 2);
+}
+
+int KillSound(void)
+{
+       //FCEUI_Sound(0);
+
+       return 1;
+}
+
diff --git a/drivers/sdl/minimal.c b/drivers/sdl/minimal.c
deleted file mode 100644 (file)
index 57c98f6..0000000
+++ /dev/null
@@ -1,315 +0,0 @@
-/* emulate minimal lib using SDL */
-
-#include <stdio.h>
-#include <SDL.h>
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <sys/ioctl.h>
-#include <sys/soundcard.h>
-#include <errno.h>
-
-#include "../gp2x/minimal.h"
-#include "../gp2x/usbjoy.h"
-#include "../gp2x/cpuctrl.h"
-
-SDL_Surface *screen;
-void *gp2x_screen;
-static int sounddev = 0;
-
-
-/* video stuff */
-void gp2x_video_flip(void)
-{
-       if(SDL_MUSTLOCK(screen))
-               SDL_LockSurface(screen);
-
-       memcpy(screen->pixels, gp2x_screen, 320*240*screen->format->BytesPerPixel);
-
-       if(SDL_MUSTLOCK(screen))
-               SDL_UnlockSurface(screen);
-
-       SDL_UpdateRect(screen, 0, 0, 0, 0);
-}
-
-
-void gp2x_video_changemode2(int bpp)
-{
-       const SDL_VideoInfo *vinf;
-       int flags=0;
-
-       vinf=SDL_GetVideoInfo();
-
-       if(vinf->hw_available)
-               flags|=SDL_HWSURFACE;
-
-       if (bpp == 8)
-               flags|=SDL_HWPALETTE;
-
-       screen = SDL_SetVideoMode(320, 240, bpp, flags);
-       if(!screen)
-       {
-               puts(SDL_GetError());
-               return;
-       }
-
-       SDL_WM_SetCaption("FCE Ultra","FCE Ultra");
-}
-
-
-static SDL_Color psdl[256];
-
-void gp2x_video_changemode(int bpp)
-{
-       gp2x_video_changemode2(bpp);
-       if (bpp == 8)
-               SDL_SetPalette(screen,SDL_PHYSPAL,psdl,0,256);
-       gp2x_video_flip();
-}
-
-
-void gp2x_video_setpalette(int *pal, int len)
-{
-       int i;
-
-       for (i = 0; i < len; i++)
-       {
-               psdl[i].r = pal[i] >> 16;
-               psdl[i].g = pal[i] >> 8;
-               psdl[i].b = pal[i];
-       }
-
-       SDL_SetPalette(screen,SDL_PHYSPAL,psdl,0,len);
-}
-
-
-void gp2x_video_RGB_setscaling(int W, int H)
-{
-}
-
-void gp2x_video_set_offs(int offs)
-{
-}
-
-void gp2x_video_flush_cache(void)
-{
-}
-
-void gp2x_memcpy_buffers(int buffers, void *data, int offset, int len)
-{
-}
-
-
-void gp2x_memcpy_all_buffers(void *data, int offset, int len)
-{
-}
-
-
-void gp2x_memset_all_buffers(int offset, int byte, int len)
-{
-       memset((char *)gp2x_screen + offset, byte, len);
-}
-
-
-unsigned long gp2x_joystick_read(int allow_usb_joy)
-{
-       unsigned long keys_out = 0;
-       Uint8 *keys;
-       int i;
-
-       SDL_PumpEvents();
-       keys = SDL_GetKeyState(NULL);
-
-       if (keys[SDLK_UP])      keys_out |= GP2X_UP;
-       if (keys[SDLK_LEFT])    keys_out |= GP2X_LEFT;
-       if (keys[SDLK_DOWN])    keys_out |= GP2X_DOWN;
-       if (keys[SDLK_RIGHT])   keys_out |= GP2X_RIGHT;
-       if (keys[SDLK_RETURN])  keys_out |= GP2X_START;
-       if (keys[SDLK_BACKSLASH]) keys_out |= GP2X_SELECT;
-       if (keys[SDLK_s])       keys_out |= GP2X_L;
-       if (keys[SDLK_d])       keys_out |= GP2X_R;
-       if (keys[SDLK_z])       keys_out |= GP2X_A;
-       if (keys[SDLK_x])       keys_out |= GP2X_X;
-       if (keys[SDLK_c])       keys_out |= GP2X_B;
-       if (keys[SDLK_v])       keys_out |= GP2X_Y;
-       if (keys[SDLK_q])       keys_out |= GP2X_VOL_DOWN;
-       if (keys[SDLK_w])       keys_out |= GP2X_VOL_UP;
-       if (keys[SDLK_RIGHTBRACKET]) keys_out |= GP2X_PUSH;
-
-       if (allow_usb_joy && num_of_joys > 0) {
-               // check the usb joy as well..
-               gp2x_usbjoy_update();
-               for (i = 0; i < num_of_joys; i++)
-                       keys_out |= gp2x_usbjoy_check(i);
-       }
-
-       return keys_out;
-}
-
-static int s_oldrate = 0, s_oldbits = 0, s_oldstereo = 0;
-
-void gp2x_start_sound(int rate, int bits, int stereo)
-{
-       int frag = 0, bsize, buffers;
-
-       // if no settings change, we don't need to do anything
-       if (rate == s_oldrate && s_oldbits == bits && s_oldstereo == stereo) return;
-
-       if (sounddev > 0) close(sounddev);
-       sounddev = open("/dev/dsp", O_WRONLY|O_ASYNC);
-       if (sounddev == -1)
-       {
-               printf("open(\"/dev/dsp\") failed with %i\n", errno);
-               return;
-       }
-
-       ioctl(sounddev, SNDCTL_DSP_SPEED,  &rate);
-       ioctl(sounddev, SNDCTL_DSP_SETFMT, &bits);
-       ioctl(sounddev, SNDCTL_DSP_STEREO, &stereo);
-       // calculate buffer size
-       buffers = 16;
-       bsize = rate / 32;
-       if (rate > 22050) { bsize*=4; buffers*=2; } // 44k mode seems to be very demanding
-       while ((bsize>>=1)) frag++;
-       frag |= buffers<<16; // 16 buffers
-       ioctl(sounddev, SNDCTL_DSP_SETFRAGMENT, &frag);
-       printf("gp2x_set_sound: %i/%ibit/%s, %i buffers of %i bytes\n",
-               rate, bits, stereo?"stereo":"mono", frag>>16, 1<<(frag&0xffff));
-
-       s_oldrate = rate; s_oldbits = bits; s_oldstereo = stereo;
-       usleep(100000);
-}
-
-
-void gp2x_sound_write(void *buff, int len)
-{
-       if (sounddev > 0)
-               write(sounddev, buff, len);
-}
-
-void gp2x_sound_sync(void)
-{
-       if (sounddev > 0)
-               ioctl(sounddev, SOUND_PCM_SYNC, 0);
-}
-
-void gp2x_sound_volume(int l, int r)
-{
-}
-
-
-void gp2x_init(void)
-{
-       printf("entering init()\n"); fflush(stdout);
-
-       gp2x_screen = malloc(320*240*2 + 32);
-       if(gp2x_screen == NULL) return;
-       memset(gp2x_screen, 0, 320*240*2 + 32);
-
-       if(SDL_Init(SDL_INIT_NOPARACHUTE))
-       {
-        printf("Could not initialize SDL: %s.\n", SDL_GetError());
-        return;
-       }
-
-       if(SDL_InitSubSystem(SDL_INIT_VIDEO)==-1)
-       {
-               puts(SDL_GetError());
-               return;
-       }
-
-       SDL_ShowCursor(0);
-
-       gp2x_video_changemode(8);
-
-       /* init usb joys -GnoStiC */
-       gp2x_usbjoy_init();
-
-       SDL_PumpEvents();
-
-       printf("gp2x_init done.\n");
-}
-
-
-char *ext_menu = 0, *ext_state = 0;
-
-void gp2x_deinit(void)
-{
-       SDL_QuitSubSystem(SDL_INIT_VIDEO);
-       SDL_Quit();
-
-       free(gp2x_screen);
-       if (sounddev > 0) close(sounddev);
-       gp2x_usbjoy_deinit();
-}
-
-
-/* other stuff to be faked */
-void cpuctrl_init(void)
-{
-}
-
-void cpuctrl_deinit(void)
-{
-}
-
-void set_FCLK(unsigned MHZ)
-{
-}
-
-void set_RAM_Timings(int tRC, int tRAS, int tWR, int tMRD, int tRFC, int tRP, int tRCD)
-{
-}
-
-void set_gamma(int g100)
-{
-}
-
-void set_LCD_custom_rate(lcd_rate_t rate)
-{
-}
-
-void unset_LCD_custom_rate(void)
-{
-}
-
-
-int mmuhack(void)
-{
-       return 1;
-}
-
-int mmuunhack(void)
-{
-       return 1;
-}
-
-void memset32(int *dest, int c, int count)
-{
-       memset(dest, c, count*4);
-}
-
-void spend_cycles(int c)
-{
-       usleep(c/200);
-}
-
-void convert2RGB555(unsigned short *dst, unsigned char *src, unsigned short *pal, int count)
-{
-       while (count--)
-               *dst++ = pal[*src++];
-}
-
-/* don't scale, just convert */
-void soft_scale(void *dst, unsigned short *pal, int line_offs, int lines)
-{
-       unsigned char *src = (unsigned char *)dst + (line_offs + lines) * 320;
-       unsigned short *dest = (unsigned short *)dst + (line_offs + lines) * 320;
-       int count = lines*320;
-
-       while (count--)
-               *(--dest) = pal[*(--src)];
-}
-
index db4d5c1..300916e 100644 (file)
@@ -3,9 +3,11 @@
 #include "../common/args.h"
 #include "../common/settings.h"
 #include "../common/input.h"
+#include "../common/main.h"
 #include "../libpicofe/menu.h"
 #include "../libpicofe/input.h"
 #include "../libpicofe/in_sdl.h"
+#include "../../video.h"
 
 static const struct in_default_bind in_sdl_defbinds[] = {
   { SDLK_UP,     IN_BINDTYPE_PLAYER12, NKEYB_UP },
@@ -16,11 +18,39 @@ static const struct in_default_bind in_sdl_defbinds[] = {
   { SDLK_x,      IN_BINDTYPE_PLAYER12, NKEYB_A },
   { SDLK_a,      IN_BINDTYPE_PLAYER12, NKEYB_B_TURBO },
   { SDLK_s,      IN_BINDTYPE_PLAYER12, NKEYB_A_TURBO },
+  { SDLK_c,      IN_BINDTYPE_PLAYER12, NKEYB_SELECT },
+  { SDLK_v,      IN_BINDTYPE_PLAYER12, NKEYB_START },
   { SDLK_ESCAPE, IN_BINDTYPE_EMU, EACTB_ENTER_MENU },
   { 0, 0, 0 }
 };
 
-SDL_Surface *screen;
+static SDL_Surface *screen;
+static char fps_str[32];
+static SDL_Color psdl[256];
+
+static int changemode(int bpp)
+{
+       const SDL_VideoInfo *vinf;
+       int flags = 0;
+
+       vinf = SDL_GetVideoInfo();
+
+       if(vinf->hw_available)
+               flags |= SDL_HWSURFACE;
+
+       if (bpp == 8)
+               flags |= SDL_HWPALETTE;
+
+       screen = SDL_SetVideoMode(320, 240, bpp, flags);
+       if (!screen)
+       {
+               puts(SDL_GetError());
+               return -1;
+       }
+
+       SDL_WM_SetCaption("FCE Ultra", "FCE Ultra");
+       return 0;
+}
 
 void platform_init(void)
 {
@@ -31,36 +61,115 @@ void platform_init(void)
        Settings.gamma = 100;
        Settings.sstate_confirm = 1;
 
-       g_menuscreen_w = 320;
-       g_menuscreen_h = 240;
-
-       // tmp
+       if (SDL_Init(SDL_INIT_NOPARACHUTE | SDL_INIT_VIDEO))
        {
-               extern void gp2x_init();
-               gp2x_init();
+               printf("Could not initialize SDL: %s.\n", SDL_GetError());
+               exit(1);
        }
+
+       g_menuscreen_w = 320;
+       g_menuscreen_h = 240;
+       if (changemode(8) != 0)
+               exit(1);
 }
 
 void platform_late_init(void)
 {
        in_sdl_init(in_sdl_defbinds);
+       in_probe();
 }
 
-void platform_apply_config(void)
+// video
+static void flip(void)
 {
+       SDL_Flip(screen);
+       XBuf = screen->pixels;
 }
 
-void platform_set_volume(int val)
+void CleanSurface(void)
 {
+       memset(screen->pixels, 0, 320 * 240 * screen->format->BytesPerPixel);
+       flip();
 }
 
-void platform_finish(void)
+void KillVideo(void)
+{
+}
+
+int InitVideo(void)
+{
+       fps_str[0] = 0;
+
+       CleanSurface();
+
+       srendline = 0;
+       erendline = 239;
+
+       return 1;
+}
+
+void FCEUD_SetPalette(uint8 index, uint8 r, uint8 g, uint8 b)
+{
+       psdl[index].r = r;
+       psdl[index].g = g;
+       psdl[index].b = b;
+
+       SDL_SetPalette(screen, SDL_PHYSPAL, &psdl[index], index, 1);
+}
+
+void FCEUD_GetPalette(uint8 index, uint8 * r, uint8 * g, uint8 * b)
+{
+       // dummy, will break snapshots
+       *r = *g = *b = 0;
+}
+
+void BlitPrepare(int skip)
+{
+       if (skip) {
+               return;
+       }
+
+       if (eoptions & EO_CLIPSIDES)
+       {
+               int i, *p = (int *) ((char *)screen->pixels + 32);
+               for (i = 240; i; i--, p += 320/4)
+               {
+                       p[0] = p[1] = p[62] = p[63] = 0;
+               }
+       }
+
+       if (Settings.accurate_mode && Settings.scaling < 2)
+       {
+               int i, *p = (int *)screen->pixels + 32/4;
+               if (srendline > 0)
+                       for (i = srendline; i > 0; i--, p += 320/4)
+                               memset(p, 0, 256);
+               if (erendline < 239)
+               {
+                       int *p = (int *)screen->pixels + erendline*320/4 + 32/4;
+                       for (i = 239-srendline; i > 0; i--, p += 320/4)
+                               memset(p, 0, 256);
+               }
+       }
+}
+
+void BlitScreen(int skip)
+{
+       if (!skip)
+               flip();
+}
+
+void platform_apply_config(void)
+{
+}
+
+void platform_set_volume(int val)
 {
 }
 
 void plat_video_menu_enter(int is_rom_loaded)
 {
-       screen = SDL_SetVideoMode(320, 240, 16, 0);
+       changemode(16);
 }
 
 void plat_video_menu_begin(void)
@@ -75,6 +184,8 @@ void plat_video_menu_end(void)
 
 void plat_video_menu_leave(void)
 {
+       changemode(8);
+       SDL_SetPalette(screen, SDL_PHYSPAL, psdl, 0, 256);
 }
 
 char *DriverUsage="";
@@ -89,5 +200,10 @@ void DoDriverArgs(void)
 
 void GetBaseDirectory(char *BaseDirectory)
 {
- strcpy(BaseDirectory, "fceultra");
+       strcpy(BaseDirectory, "fceultra");
+}
+
+void platform_finish(void)
+{
+       SDL_Quit();
 }