move blit to core, allow filtering while blitting
[pcsx_rearmed.git] / frontend / plat_pollux.c
index 57031d8..52a09b1 100644 (file)
@@ -305,12 +305,13 @@ static void spend_cycles(int loops)
 #define DMA_REG(x) memregl[(DMA_BASE6 + x) >> 2]
 
 /* this takes ~1.5ms, while ldm/stm ~1.95ms */
-static void raw_flip_dma(int x, int y)
+static void raw_flip_dma(const void *vram, int stride, int bgr24, int w, int h)
 {
+       unsigned int pixel_offset = psx_vram - (unsigned short *)vram;
        unsigned int dst = fb_paddrs[fb_work_buf] +
                        (fb_offset_y * 320 + fb_offset_x) * psx_bpp / 8;
-       int spsx_line = y + psx_offset_y;
-       int spsx_offset = (x + psx_offset_x) & 0x3f8;
+       int spsx_line = pixel_offset / 1024 + psx_offset_y;
+       int spsx_offset = (pixel_offset + psx_offset_x) & 0x3f8;
        int dst_stride = 320 * psx_bpp / 8;
        int len = psx_src_width * psx_bpp / 8;
        int i;
@@ -344,7 +345,7 @@ static void raw_flip_dma(int x, int y)
 
        if (psx_bpp == 16) {
                pl_vout_buf = g_menuscreen_ptr;
-               pl_print_hud(fb_offset_x);
+               pl_print_hud(w, h, fb_offset_x);
        }
 
        g_menuscreen_ptr = fb_flip();
@@ -354,26 +355,24 @@ static void raw_flip_dma(int x, int y)
 }
 
 #define make_flip_func(name, blitfunc)                                                  \
-static void name(int x, int y)                                                          \
+static void name(const void *vram_, int stride, int bgr24, int w, int h)                \
 {                                                                                       \
-        unsigned short *vram = psx_vram;                                                \
+        const unsigned short *vram = vram_;                                             \
         unsigned char *dst = (unsigned char *)g_menuscreen_ptr +                        \
                         (fb_offset_y * 320 + fb_offset_x) * psx_bpp / 8;                \
-        unsigned int src = (y + psx_offset_y) * 1024 + x + psx_offset_x;                \
         int dst_stride = 320 * psx_bpp / 8;                                             \
         int len = psx_src_width * psx_bpp / 8;                                          \
         int i;                                                                          \
                                                                                         \
         pcnt_start(PCNT_BLIT);                                                          \
                                                                                         \
-        for (i = psx_src_height; i > 0; i--, src += psx_step * 1024, dst += dst_stride) { \
-                src &= 1024*512-1;                                                      \
-                blitfunc(dst, vram + src, len);                                         \
-        }                                                                               \
+        vram += psx_offset_y * 1024 + psx_offset_x;                                     \
+        for (i = psx_src_height; i > 0; i--, vram += psx_step * 1024, dst += dst_stride)\
+                blitfunc(dst, vram, len);                                               \
                                                                                         \
         if (psx_bpp == 16) {                                                            \
                 pl_vout_buf = g_menuscreen_ptr;                                         \
-                pl_print_hud(fb_offset_x);                                              \
+                pl_print_hud(w, h, fb_offset_x);                                        \
         }                                                                               \
                                                                                         \
         g_menuscreen_ptr = fb_flip();                                                   \
@@ -402,20 +401,20 @@ void *plat_gvideo_set_mode(int *w_, int *h_, int *bpp_)
 
        switch (w + (bpp != 16) + !soft_scaling) {
        case 640:
-               pl_rearmed_cbs.pl_vout_raw_flip = raw_flip_soft_640;
+               pl_rearmed_cbs.pl_vout_flip = raw_flip_soft_640;
                w_max = 640;
                break;
        case 512:
-               pl_rearmed_cbs.pl_vout_raw_flip = raw_flip_soft_512;
+               pl_rearmed_cbs.pl_vout_flip = raw_flip_soft_512;
                w_max = 512;
                break;
        case 384:
        case 368:
-               pl_rearmed_cbs.pl_vout_raw_flip = raw_flip_soft_368;
+               pl_rearmed_cbs.pl_vout_flip = raw_flip_soft_368;
                w_max = 368;
                break;
        default:
-               pl_rearmed_cbs.pl_vout_raw_flip = have_warm ? raw_flip_dma : raw_flip_soft;
+               pl_rearmed_cbs.pl_vout_flip = have_warm ? raw_flip_dma : raw_flip_soft;
                w_max = 320;
                break;
        }
@@ -440,7 +439,7 @@ void *plat_gvideo_set_mode(int *w_, int *h_, int *bpp_)
        }
        fb_offset_y = 240/2 - h / 2;
 
-       psx_offset_x = poff_w;
+       psx_offset_x = poff_w * psx_bpp/8 / 2;
        psx_offset_y = poff_h;
        psx_src_width = w;
        psx_src_height = h;
@@ -621,7 +620,7 @@ void plat_init(void)
        if (mixerdev == -1)
                perror("open(/dev/mixer)");
 
-       pl_rearmed_cbs.pl_vout_raw_flip = have_warm ? raw_flip_dma : raw_flip_soft;
+       pl_rearmed_cbs.pl_vout_flip = have_warm ? raw_flip_dma : raw_flip_soft;
        pl_rearmed_cbs.pl_vout_set_raw_vram = pl_vout_set_raw_vram;
 
        psx_src_width = 320;
@@ -653,6 +652,22 @@ void plat_finish(void)
        close(memdev);
 }
 
+/* WIZ RAM lack workaround */
+void *memtab_mmap(void *addr, size_t size)
+{
+       void *ret;
+
+       if (gp2x_dev_id != GP2X_DEV_WIZ)
+               return mmap(addr, size, PROT_READ | PROT_WRITE,
+                       MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0);
+
+       ret = mmap(addr, size, PROT_READ | PROT_WRITE,
+               MAP_SHARED | MAP_FIXED, memdev, 0x03000000);
+       if (ret != MAP_FAILED)
+               warm_change_cb_range(WCB_C_BIT | WCB_B_BIT, 1, ret, size);
+       return ret;
+}
+
 /* Caanoo stuff, perhaps move later */
 static const char * const caanoo_keys[KEY_MAX + 1] = {
        [0 ... KEY_MAX] = NULL,