| 1 | /* |
| 2 | * (C) notaz, 2010 |
| 3 | * |
| 4 | * This work is licensed under the terms of the GNU GPLv2 or later. |
| 5 | * See the COPYING file in the top-level directory. |
| 6 | */ |
| 7 | |
| 8 | #define _IN_DRAW |
| 9 | |
| 10 | #include "gpu.h" |
| 11 | |
| 12 | #include "plugin_lib.h" |
| 13 | #include "arm_utils.h" |
| 14 | #include "pcnt.h" |
| 15 | |
| 16 | // misc globals |
| 17 | long lLowerpart; |
| 18 | BOOL bCheckMask = FALSE; |
| 19 | unsigned short sSetMask; |
| 20 | unsigned long lSetMask; |
| 21 | |
| 22 | static void blit(void) |
| 23 | { |
| 24 | int px = PSXDisplay.DisplayPosition.x & ~3; // XXX: align needed by bgr*_to_... |
| 25 | int py = PSXDisplay.DisplayPosition.y; |
| 26 | int w = PreviousPSXDisplay.Range.x1; |
| 27 | int h = PreviousPSXDisplay.DisplayMode.y; |
| 28 | int pitch = PreviousPSXDisplay.DisplayMode.x; |
| 29 | unsigned short *srcs = psxVuw + py * 1024 + px; |
| 30 | unsigned char *dest = pl_fbdev_buf; |
| 31 | |
| 32 | if (w <= 0) |
| 33 | return; |
| 34 | |
| 35 | #ifndef MAEMO |
| 36 | pitch *= PSXDisplay.RGB24 ? 3 : 2; |
| 37 | #else |
| 38 | // n900 doesn't do rgb24 for some reason |
| 39 | pitch *= 2; |
| 40 | #define bgr888_to_rgb888 bgr888_to_rgb565 |
| 41 | #endif |
| 42 | |
| 43 | // account for centering |
| 44 | h -= PreviousPSXDisplay.Range.y0; |
| 45 | dest += PreviousPSXDisplay.Range.y0 / 2 * pitch; |
| 46 | dest += (PreviousPSXDisplay.Range.x0 & ~3) * 2; // must align here too.. |
| 47 | |
| 48 | if (PSXDisplay.RGB24) |
| 49 | { |
| 50 | for (; h-- > 0; dest += pitch, srcs += 1024) |
| 51 | { |
| 52 | bgr888_to_rgb888(dest, srcs, w * 3); |
| 53 | } |
| 54 | } |
| 55 | else |
| 56 | { |
| 57 | for (; h-- > 0; dest += pitch, srcs += 1024) |
| 58 | { |
| 59 | bgr555_to_rgb565(dest, srcs, w * 2); |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | void DoBufferSwap(void) |
| 65 | { |
| 66 | static int fbw, fbh, fb24bpp; |
| 67 | |
| 68 | if (PreviousPSXDisplay.DisplayMode.x == 0 || PreviousPSXDisplay.DisplayMode.y == 0) |
| 69 | return; |
| 70 | |
| 71 | /* careful if rearranging this code, we try to set mode and flip |
| 72 | * to get the hardware apply both changes at the same time */ |
| 73 | if (PreviousPSXDisplay.DisplayMode.x != fbw || PreviousPSXDisplay.DisplayMode.y != fbh |
| 74 | || PSXDisplay.RGB24 != fb24bpp) { |
| 75 | fbw = PreviousPSXDisplay.DisplayMode.x; |
| 76 | fbh = PreviousPSXDisplay.DisplayMode.y; |
| 77 | fb24bpp = PSXDisplay.RGB24; |
| 78 | pl_fbdev_set_mode(fbw, fbh, fb24bpp ? 24 : 16); |
| 79 | } |
| 80 | |
| 81 | pcnt_start(PCNT_BLIT); |
| 82 | blit(); |
| 83 | pcnt_end(PCNT_BLIT); |
| 84 | |
| 85 | pl_fbdev_flip(); |
| 86 | } |
| 87 | |
| 88 | void DoClearScreenBuffer(void) |
| 89 | { |
| 90 | } |
| 91 | |
| 92 | unsigned long ulInitDisplay(void) |
| 93 | { |
| 94 | if (pl_fbdev_open() != 0) |
| 95 | return 0; |
| 96 | |
| 97 | return 1; /* ok */ |
| 98 | } |
| 99 | |
| 100 | void CloseDisplay(void) |
| 101 | { |
| 102 | pl_fbdev_close(); |
| 103 | } |
| 104 | |