fbdev output for xvideo, basic ARM build
authornotaz <notasas@gmail.com>
Thu, 18 Nov 2010 23:56:51 +0000 (01:56 +0200)
committernotaz <notasas@gmail.com>
Thu, 18 Nov 2010 23:56:51 +0000 (01:56 +0200)
.gitignore
Makefile
frontend/X11/keysym.h [new file with mode: 0644]
frontend/linux/fbdev.c [new file with mode: 0644]
frontend/linux/fbdev.h [new file with mode: 0644]
frontend/main.c
frontend/plugin_lib.c [new file with mode: 0644]
frontend/plugin_lib.h [new file with mode: 0644]
plugins/dfxvideo/draw_fb.c [new file with mode: 0644]
plugins/dfxvideo/externals.h

index 3c2904e..645bb34 100644 (file)
@@ -1,3 +1,4 @@
 *.o
+frontend/linux
 tags
 cscope.out
index 50b7b60..0dd79ee 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,9 +1,12 @@
-CROSS_COMPILE=
+#CROSS_COMPILE=
 CC = $(CROSS_COMPILE)gcc
 LD = $(CROSS_COMPILE)ld
 
 CFLAGS += -Wall -ggdb -Ifrontend
 LDFLAGS += -lz -lpthread -ldl
+ifdef CROSS_COMPILE
+CFLAGS += -O2 -mcpu=cortex-a8 -mtune=cortex-a8 -mfloat-abi=softfp -ffast-math
+endif
 TARGET = pcsx
 
 all: $(TARGET)
@@ -21,14 +24,20 @@ OBJS += plugins/dfsound/adsr.o plugins/dfsound/dma.o plugins/dfsound/oss.o plugi
        plugins/dfsound/spu.o
 # gpu
 OBJS += plugins/dfxvideo/cfg.o plugins/dfxvideo/fps.o plugins/dfxvideo/key.o plugins/dfxvideo/prim.o \
-       plugins/dfxvideo/zn.o plugins/dfxvideo/draw.o plugins/dfxvideo/gpu.o plugins/dfxvideo/menu.o \
-       plugins/dfxvideo/soft.o
-LDFLAGS += -lz -lpthread -lX11 -lXv
+       plugins/dfxvideo/gpu.o plugins/dfxvideo/menu.o plugins/dfxvideo/soft.o plugins/dfxvideo/zn.o
+ifdef X11
+LDFLAGS += -lX11 -lXv
+OBJS += plugins/dfxvideo/draw.o
+else
+CFLAGS += -D_MACGL # disables X in dfxvideo
+OBJS += plugins/dfxvideo/draw_fb.o
+endif
 
 # gui
 OBJS += gui/Config.o gui/Plugin.o
 
-OBJS += frontend/main.o frontend/plugin.o
+OBJS += frontend/main.o frontend/plugin.o frontend/plugin_lib.o
+OBJS += frontend/linux/fbdev.o
 
 $(TARGET): $(OBJS)
        $(CC) -o $@ $^ $(LDFLAGS)
diff --git a/frontend/X11/keysym.h b/frontend/X11/keysym.h
new file mode 100644 (file)
index 0000000..31ad461
--- /dev/null
@@ -0,0 +1,24 @@
+
+#define XK_Return                        0xff0d  /* Return, enter */
+#define XK_Escape                        0xff1b
+#define XK_Control_L                     0xffe3  /* Left control */
+#define XK_Control_R                     0xffe4  /* Right control */
+#define XK_Alt_L                         0xffe9  /* Left alt */
+#define XK_Alt_R                         0xffea  /* Right alt */
+#define XK_0                             0x0030  /* U+0030 DIGIT ZERO */
+#define XK_1                             0x0031  /* U+0031 DIGIT ONE */
+#define XK_2                             0x0032  /* U+0032 DIGIT TWO */
+#define XK_3                             0x0033  /* U+0033 DIGIT THREE */
+#define XK_4                             0x0034  /* U+0034 DIGIT FOUR */
+#define XK_5                             0x0035  /* U+0035 DIGIT FIVE */
+#define XK_F1                            0xffbe
+#define XK_F2                            0xffbf
+#define XK_F3                            0xffc0
+#define XK_F4                            0xffc1
+#define XK_F5                            0xffc2
+#define XK_F6                            0xffc3
+#define XK_F7                            0xffc4
+#define XK_F8                            0xffc5
+#define XK_F9                            0xffc6
+#define XK_F10                           0xffc7
+
diff --git a/frontend/linux/fbdev.c b/frontend/linux/fbdev.c
new file mode 100644 (file)
index 0000000..6ae0c77
--- /dev/null
@@ -0,0 +1,240 @@
+/*
+ * (C) GraÅžvydas "notaz" Ignotas, 2009-2010
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <sys/mman.h>
+#include <unistd.h>
+#include <linux/fb.h>
+#include <linux/matroxfb.h>
+
+#include "fbdev.h"
+
+#define FBDEV_MAX_BUFFERS 3
+
+struct vout_fbdev {
+       int     fd;
+       void    *mem;
+       size_t  mem_size;
+       struct  fb_var_screeninfo fbvar_old;
+       struct  fb_var_screeninfo fbvar_new;
+       int     buffer_write;
+       int     fb_size;
+       int     buffer_count;
+       int     top_border, bottom_border;
+};
+
+void *vout_fbdev_flip(struct vout_fbdev *fbdev)
+{
+       int draw_buf;
+
+       if (fbdev->buffer_count < 2)
+               return fbdev->mem;
+
+       draw_buf = fbdev->buffer_write;
+       fbdev->buffer_write++;
+       if (fbdev->buffer_write >= fbdev->buffer_count)
+               fbdev->buffer_write = 0;
+
+       fbdev->fbvar_new.yoffset = 
+               (fbdev->top_border + fbdev->fbvar_new.yres + fbdev->bottom_border) * draw_buf +
+               fbdev->top_border;
+
+       ioctl(fbdev->fd, FBIOPAN_DISPLAY, &fbdev->fbvar_new);
+
+       return (char *)fbdev->mem + fbdev->fb_size * fbdev->buffer_write;
+}
+
+void vout_fbdev_wait_vsync(struct vout_fbdev *fbdev)
+{
+       int arg = 0;
+       ioctl(fbdev->fd, FBIO_WAITFORVSYNC, &arg);
+}
+
+int vout_fbdev_resize(struct vout_fbdev *fbdev, int w, int h,
+                     int left_border, int right_border, int top_border, int bottom_border, int no_dblbuf)
+{
+       int w_total = left_border + w + right_border;
+       int h_total = top_border + h + bottom_border;
+       size_t mem_size;
+       int ret;
+
+       // unblank to be sure the mode is really accepted
+       ioctl(fbdev->fd, FBIOBLANK, FB_BLANK_UNBLANK);
+
+       if (fbdev->fbvar_new.bits_per_pixel != 16 ||
+                       w != fbdev->fbvar_new.xres ||
+                       h != fbdev->fbvar_new.yres ||
+                       w_total != fbdev->fbvar_new.xres_virtual ||
+                       h_total > fbdev->fbvar_new.yres_virtual ||
+                       left_border != fbdev->fbvar_new.xoffset) {
+               fbdev->fbvar_new.xres = w;
+               fbdev->fbvar_new.yres = h;
+               fbdev->fbvar_new.xres_virtual = w_total;
+               fbdev->fbvar_new.yres_virtual = h_total;
+               fbdev->fbvar_new.xoffset = left_border;
+               fbdev->fbvar_new.bits_per_pixel = 16;
+               printf(" switching to %dx%d@16\n", w, h);
+               ret = ioctl(fbdev->fd, FBIOPUT_VSCREENINFO, &fbdev->fbvar_new);
+               if (ret == -1) {
+                       perror("FBIOPUT_VSCREENINFO ioctl");
+                       return -1;
+               }
+       }
+
+       fbdev->buffer_count = FBDEV_MAX_BUFFERS; // be optimistic
+       if (no_dblbuf)
+               fbdev->buffer_count = 1;
+
+       if (fbdev->fbvar_new.yres_virtual < h_total * fbdev->buffer_count) {
+               fbdev->fbvar_new.yres_virtual = h_total * fbdev->buffer_count;
+               ret = ioctl(fbdev->fd, FBIOPUT_VSCREENINFO, &fbdev->fbvar_new);
+               if (ret == -1) {
+                       fbdev->buffer_count = 1;
+                       fprintf(stderr, "Warning: failed to increase virtual resolution, "
+                                       "doublebuffering disabled\n");
+               }
+       }
+
+       fbdev->fb_size = w_total * h_total * 2;
+       fbdev->top_border = top_border;
+       fbdev->bottom_border = bottom_border;
+
+       mem_size = fbdev->fb_size * fbdev->buffer_count;
+       if (fbdev->mem_size >= mem_size)
+               return 0;
+
+       if (fbdev->mem != NULL)
+               munmap(fbdev->mem, fbdev->mem_size);
+
+       fbdev->mem = mmap(0, mem_size, PROT_WRITE|PROT_READ, MAP_SHARED, fbdev->fd, 0);
+       if (fbdev->mem == MAP_FAILED && fbdev->buffer_count > 1) {
+               fprintf(stderr, "Warning: can't map %zd bytes, doublebuffering disabled\n", fbdev->mem_size);
+               fbdev->buffer_count = 1;
+               mem_size = fbdev->fb_size;
+               fbdev->mem = mmap(0, mem_size, PROT_WRITE|PROT_READ, MAP_SHARED, fbdev->fd, 0);
+       }
+       if (fbdev->mem == MAP_FAILED) {
+               fbdev->mem = NULL;
+               fbdev->mem_size = 0;
+               perror("mmap framebuffer");
+               return -1;
+       }
+
+       fbdev->mem_size = mem_size;
+       return 0;
+}
+
+void vout_fbdev_clear(struct vout_fbdev *fbdev)
+{
+       memset(fbdev->mem, 0, fbdev->mem_size);
+}
+
+void vout_fbdev_clear_lines(struct vout_fbdev *fbdev, int y, int count)
+{
+       int stride = fbdev->fbvar_new.xres_virtual * fbdev->fbvar_new.bits_per_pixel / 8;
+       int i;
+
+       if (y + count > fbdev->top_border + fbdev->fbvar_new.yres)
+               count = fbdev->top_border + fbdev->fbvar_new.yres - y;
+
+       if (y >= 0 && count > 0)
+               for (i = 0; i < fbdev->buffer_count; i++)
+                       memset((char *)fbdev->mem + fbdev->fb_size * i + y * stride, 0, stride * count);
+}
+
+int vout_fbdev_get_fd(struct vout_fbdev *fbdev)
+{
+       return fbdev->fd;
+}
+
+struct vout_fbdev *vout_fbdev_init(const char *fbdev_name, int *w, int *h, int no_dblbuf)
+{
+       struct vout_fbdev *fbdev;
+       int req_w, req_h;
+       int ret;
+
+       fbdev = calloc(1, sizeof(*fbdev));
+       if (fbdev == NULL)
+               return NULL;
+
+       fbdev->fd = open(fbdev_name, O_RDWR);
+       if (fbdev->fd == -1) {
+               fprintf(stderr, "%s: ", fbdev_name);
+               perror("open");
+               goto fail_open;
+       }
+
+       ret = ioctl(fbdev->fd, FBIOGET_VSCREENINFO, &fbdev->fbvar_old);
+       if (ret == -1) {
+               perror("FBIOGET_VSCREENINFO ioctl");
+               goto fail;
+       }
+
+       fbdev->fbvar_new = fbdev->fbvar_old;
+
+       req_w = fbdev->fbvar_new.xres;
+       if (*w != 0)
+               req_w = *w;
+       req_h = fbdev->fbvar_new.yres;
+       if (*h != 0)
+               req_h = *h;
+
+       ret = vout_fbdev_resize(fbdev, req_w, req_h, 0, 0, 0, 0, no_dblbuf);
+       if (ret != 0)
+               goto fail;
+
+       printf("%s: %ix%i@%d\n", fbdev_name, fbdev->fbvar_new.xres, fbdev->fbvar_new.yres,
+               fbdev->fbvar_new.bits_per_pixel);
+       *w = fbdev->fbvar_new.xres;
+       *h = fbdev->fbvar_new.yres;
+
+       memset(fbdev->mem, 0, fbdev->mem_size);
+
+       // some checks
+       ret = 0;
+       ret = ioctl(fbdev->fd, FBIO_WAITFORVSYNC, &ret);
+       if (ret != 0)
+               fprintf(stderr, "Warning: vsync doesn't seem to be supported\n");
+
+       if (fbdev->buffer_count > 1) {
+               fbdev->buffer_write = 0;
+               fbdev->fbvar_new.yoffset = fbdev->fbvar_new.yres * (fbdev->buffer_count - 1);
+               ret = ioctl(fbdev->fd, FBIOPAN_DISPLAY, &fbdev->fbvar_new);
+               if (ret != 0) {
+                       fbdev->buffer_count = 1;
+                       fprintf(stderr, "Warning: can't pan display, doublebuffering disabled\n");
+               }
+       }
+
+       printf("fbdev initialized.\n");
+       return fbdev;
+
+fail:
+       close(fbdev->fd);
+fail_open:
+       free(fbdev);
+       return NULL;
+}
+
+void vout_fbdev_finish(struct vout_fbdev *fbdev)
+{
+       ioctl(fbdev->fd, FBIOPUT_VSCREENINFO, &fbdev->fbvar_old);
+       if (fbdev->mem != MAP_FAILED)
+               munmap(fbdev->mem, fbdev->mem_size);
+       if (fbdev->fd >= 0)
+               close(fbdev->fd);
+       fbdev->mem = NULL;
+       fbdev->fd = -1;
+       free(fbdev);
+}
+
diff --git a/frontend/linux/fbdev.h b/frontend/linux/fbdev.h
new file mode 100644 (file)
index 0000000..fa163aa
--- /dev/null
@@ -0,0 +1,12 @@
+struct vout_fbdev;
+
+struct vout_fbdev *vout_fbdev_init(const char *fbdev_name, int *w, int *h, int no_dblbuf);
+void *vout_fbdev_flip(struct vout_fbdev *fbdev);
+void  vout_fbdev_wait_vsync(struct vout_fbdev *fbdev);
+int   vout_fbdev_resize(struct vout_fbdev *fbdev, int w, int h,
+                       int left_border, int right_border, int top_border, int bottom_border,
+                       int no_dblbuf);
+void  vout_fbdev_clear(struct vout_fbdev *fbdev);
+void  vout_fbdev_clear_lines(struct vout_fbdev *fbdev, int y, int count);
+int   vout_fbdev_get_fd(struct vout_fbdev *fbdev);
+void  vout_fbdev_finish(struct vout_fbdev *fbdev);
index 6ee0b2f..e36ad48 100644 (file)
@@ -18,6 +18,7 @@
 #include "../libpcsxcore/misc.h"
 
 int UseGui;
+static char *(*real_getenv)(const char *name);
 
 static void make_path(char *buf, size_t size, const char *dir, const char *fname)
 {
@@ -67,8 +68,18 @@ int main(int argc, char *argv[])
        char path[MAXPATHLEN];
        int runcd = 0;
        int loadst = 0;
+       void *tmp;
        int i;
 
+       tmp = dlopen("/lib/libdl.so.2", RTLD_LAZY);
+       if (tmp != NULL)
+               real_getenv = dlsym(tmp, "getenv");
+       if (real_getenv == NULL) {
+               fprintf(stderr, "%s\n", dlerror());
+               return 1;
+       }
+       dlclose(tmp);
+
        // what is the name of the config file?
        // it may be redefined by -cfg on the command line
        strcpy(cfgfile_basename, "pcsx.cfg");
@@ -376,14 +387,10 @@ char *getenv(const char *name)
 {
        static char ret[8] = ".";
 
-       // HACK
-       if (name && strcmp(name, "DISPLAY") == 0)
-               return ":0";
-
-       if (name && strcmp(name, "HOME") != 0)
-               fprintf(stderr, "getenv called with %s\n", name);
+       if (name && strcmp(name, "HOME") == 0)
+               return ret;
 
-       return ret;
+       return real_getenv(name);
 }
 #endif
 
diff --git a/frontend/plugin_lib.c b/frontend/plugin_lib.c
new file mode 100644 (file)
index 0000000..5fd80cd
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * (C) notaz, 2010
+ *
+ * This work is licensed under the terms of the GNU GPLv2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "linux/fbdev.h"
+
+static struct vout_fbdev *fbdev;
+void *pl_fbdev_buf;
+
+int pl_fbdev_init(void)
+{
+  const char *fbdev_name;
+  int w, h;
+
+  fbdev_name = getenv("FBDEV");
+  if (fbdev_name == NULL)
+    fbdev_name = "/dev/fb0";
+
+  w = 640;
+  h = 512; // ??
+  fbdev = vout_fbdev_init(fbdev_name, &w, &h, 0);
+  if (fbdev == NULL)
+    return -1;
+
+  pl_fbdev_buf = vout_fbdev_flip(fbdev);
+
+  return 0;
+}
+
+int pl_fbdev_set_mode(int w, int h, int bpp)
+{
+  printf("set mode %dx%d@%d\n", w, h, bpp);
+  return vout_fbdev_resize(fbdev, w, h, 0, 0, 0, 0, 0);
+}
+
+void *pl_fbdev_flip(void)
+{
+  pl_fbdev_buf = vout_fbdev_flip(fbdev);
+  return pl_fbdev_buf;
+}
+
+void pl_fbdev_finish(void)
+{
+  if (fbdev != NULL)
+    vout_fbdev_finish(fbdev);
+  fbdev = NULL;
+}
+
diff --git a/frontend/plugin_lib.h b/frontend/plugin_lib.h
new file mode 100644 (file)
index 0000000..03afc86
--- /dev/null
@@ -0,0 +1,7 @@
+
+extern void *pl_fbdev_buf;
+
+int   pl_fbdev_init(void);
+int   pl_fbdev_set_mode(int w, int h, int bpp);
+void *pl_fbdev_flip(void);
+void  pl_fbdev_finish(void);
diff --git a/plugins/dfxvideo/draw_fb.c b/plugins/dfxvideo/draw_fb.c
new file mode 100644 (file)
index 0000000..39be291
--- /dev/null
@@ -0,0 +1,143 @@
+/*
+ * (C) notaz, 2010
+ *
+ * This work is licensed under the terms of the GNU GPLv2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#define _IN_DRAW
+
+#include "externals.h"
+#include "gpu.h"
+#include "draw.h"
+#include "prim.h"
+#include "menu.h"
+#include "interp.h"
+#include "swap.h"
+
+#include "plugin_lib.h"
+
+// misc globals
+int            iResX;
+int            iResY;
+long           lLowerpart;
+BOOL           bIsFirstFrame = TRUE;
+BOOL           bCheckMask = FALSE;
+unsigned short sSetMask = 0;
+unsigned long  lSetMask = 0;
+int            iDesktopCol = 16;
+int            iShowFPS = 0;
+int            iWinSize; 
+int            iMaintainAspect = 0;
+int            iUseNoStretchBlt = 0;
+int            iFastFwd = 0;
+int            iFVDisplay = 0;
+PSXPoint_t     ptCursorPoint[8];
+unsigned short usCursorActive = 0;
+char *         pCaptionText;
+
+
+static void blit(void)
+{
+ int x = PSXDisplay.DisplayPosition.x;
+ int y = PSXDisplay.DisplayPosition.y;
+ int w = PreviousPSXDisplay.Range.x1;
+ int h = PreviousPSXDisplay.DisplayMode.y;
+ int pitch = PreviousPSXDisplay.DisplayMode.x * 2;
+ unsigned char *dest = pl_fbdev_buf;
+
+ // TODO: clear border if centering
+
+ // account for centering
+ h -= PreviousPSXDisplay.Range.y0;
+ dest += PreviousPSXDisplay.Range.y0 / 2 * pitch;
+ dest += PreviousPSXDisplay.Range.x0 * 2; // XXX
+
+ {
+   unsigned short *srcs = psxVuw + y * 1024 + x;
+   for (; h-- > 0; dest += pitch, srcs += 1024)
+   {
+     memcpy(dest, srcs, w * 2);
+   }
+ }
+}
+
+static int fbw, fbh, fb24bpp;
+
+void DoBufferSwap(void)
+{
+ static float fps_old;
+ if (PSXDisplay.DisplayMode.x == 0 || PSXDisplay.DisplayMode.y == 0)
+  return;
+
+ if (PSXDisplay.DisplayMode.x != fbw || PSXDisplay.DisplayMode.y != fbh
+     || PSXDisplay.RGB24 != fb24bpp) {
+  fbw = PSXDisplay.DisplayMode.x;
+  fbh = PSXDisplay.DisplayMode.y;
+  fb24bpp = PSXDisplay.RGB24;
+  pl_fbdev_set_mode(fbw, fbh, fb24bpp ? 24 : 16);
+ }
+
+ if (fps_cur != fps_old) {
+  printf("%2.1f\n", fps_cur);
+  fps_old = fps_cur;
+ }
+
+ blit();
+ pl_fbdev_flip();
+}
+
+void DoClearScreenBuffer(void)                         // CLEAR DX BUFFER
+{
+}
+
+void DoClearFrontBuffer(void)                          // CLEAR DX BUFFER
+{
+}
+
+static int initialize(void)
+{
+ iDesktopCol=32;
+
+ bUsingTWin=FALSE;
+ bIsFirstFrame = FALSE;                                // done
+
+ if(iShowFPS)
+  {
+   iShowFPS=0;
+   ulKeybits|=KEY_SHOWFPS;
+   szDispBuf[0]=0;
+   BuildDispMenu(0);
+  }
+
+ return 0;
+}
+
+unsigned long ulInitDisplay(void)
+{
+ iShowFPS=1;
+ initialize();
+
+ if (pl_fbdev_init() != 0)
+  return 0;
+
+ return 1; /* ok */
+}
+
+void CloseDisplay(void)
+{
+ CloseMenu();
+ pl_fbdev_finish();
+}
+
+void CreatePic(unsigned char * pMem)
+{
+}
+
+void DestroyPic(void)
+{
+}
+
+void HandleKey(int keycode)
+{
+}
index 2c29faf..89c48bf 100644 (file)
@@ -64,9 +64,9 @@
 #ifndef _MACGL
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
+#include <X11/cursorfont.h>
 #endif
 #include <math.h>
-#include <X11/cursorfont.h>
 #include <stdint.h>
 
 /////////////////////////////////////////////////////////////////////////////