| 1 | /* |
| 2 | * GINGE - GINGE Is Not Gp2x Emulator |
| 3 | * (C) notaz, 2010-2011 |
| 4 | * |
| 5 | * This work is licensed under the MAME license, see COPYING file for details. |
| 6 | */ |
| 7 | #include <string.h> |
| 8 | #ifdef LOADER |
| 9 | #include "../loader/realfuncs.h" |
| 10 | #endif |
| 11 | |
| 12 | #include "host_fb.h" |
| 13 | |
| 14 | static void *host_screen; |
| 15 | static int host_stride; |
| 16 | |
| 17 | #if defined(PND) |
| 18 | |
| 19 | #include "libpicofe/linux/fbdev.c" |
| 20 | #include "omapfb.h" |
| 21 | |
| 22 | static struct vout_fbdev *fbdev; |
| 23 | static unsigned short host_pal[256]; |
| 24 | |
| 25 | static int get_layer_size(int *x, int *y, int *w, int *h) |
| 26 | { |
| 27 | struct omapfb_plane_info pi; |
| 28 | int ret; |
| 29 | |
| 30 | ret = ioctl(vout_fbdev_get_fd(fbdev), OMAPFB_QUERY_PLANE, &pi); |
| 31 | if (ret != 0) { |
| 32 | perror("OMAPFB_QUERY_PLANE"); |
| 33 | return -1; |
| 34 | } |
| 35 | |
| 36 | *x = pi.pos_x; |
| 37 | *y = pi.pos_y; |
| 38 | *w = pi.out_width; |
| 39 | *h = pi.out_height; |
| 40 | printf("layer: %d,%d %dx%d\n", *x, *y, *w, *h); |
| 41 | |
| 42 | return 0; |
| 43 | } |
| 44 | |
| 45 | void *host_video_flip(void) |
| 46 | { |
| 47 | host_screen = vout_fbdev_flip(fbdev); |
| 48 | return host_screen; |
| 49 | } |
| 50 | |
| 51 | int host_video_init(int *stride, int no_dblbuf) |
| 52 | { |
| 53 | const char *fbdev_name; |
| 54 | int w, h; |
| 55 | |
| 56 | fbdev_name = getenv("FBDEV"); |
| 57 | if (fbdev_name == NULL) |
| 58 | fbdev_name = "/dev/fb1"; |
| 59 | |
| 60 | w = h = 0; |
| 61 | fbdev = vout_fbdev_init(fbdev_name, &w, &h, 16, no_dblbuf ? 1 : 3); |
| 62 | if (fbdev == NULL) |
| 63 | return -1; |
| 64 | |
| 65 | host_stride = w * 2; |
| 66 | if (stride != 0) |
| 67 | *stride = host_stride; |
| 68 | host_video_flip(); |
| 69 | |
| 70 | return 0; |
| 71 | } |
| 72 | |
| 73 | void host_video_finish(void) |
| 74 | { |
| 75 | vout_fbdev_finish(fbdev); |
| 76 | fbdev = NULL; |
| 77 | } |
| 78 | |
| 79 | void host_video_update_pal16(unsigned short *pal) |
| 80 | { |
| 81 | memcpy(host_pal, pal, sizeof(host_pal)); |
| 82 | } |
| 83 | |
| 84 | void host_video_update_pal32(unsigned int *pal) |
| 85 | { |
| 86 | unsigned short *dstp = host_pal; |
| 87 | int i; |
| 88 | |
| 89 | for (i = 0; i < 256; i++, pal++, dstp++) { |
| 90 | unsigned int t = *pal; |
| 91 | *dstp = ((t >> 8) & 0xf800) | ((t >> 5) & 0x07e0) | ((t >> 3) & 0x001f); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | void host_video_change_bpp(int bpp) |
| 96 | { |
| 97 | } |
| 98 | |
| 99 | void host_video_blit4(const unsigned char *src, int w, int h, int stride) |
| 100 | { |
| 101 | unsigned short *dst = host_screen; |
| 102 | unsigned short *hpal = host_pal; |
| 103 | int i, u; |
| 104 | |
| 105 | for (i = 0; i < 240; i++, dst += host_stride / 2, src += stride) { |
| 106 | for (u = 0; i < w / 2; u++) { |
| 107 | dst[u*2 + 0] = hpal[src[u] >> 4]; |
| 108 | dst[u*2 + 1] = hpal[src[u] & 0x0f]; |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | host_video_flip(); |
| 113 | } |
| 114 | |
| 115 | void host_video_blit8(const unsigned char *src, int w, int h, int stride) |
| 116 | { |
| 117 | unsigned short *dst = host_screen; |
| 118 | unsigned short *hpal = host_pal; |
| 119 | int i, u; |
| 120 | |
| 121 | for (i = 0; i < 240; i++, dst += host_stride / 2, src += stride) { |
| 122 | for (u = 0; u < w; u += 4) { |
| 123 | dst[u + 0] = hpal[src[u + 0]]; |
| 124 | dst[u + 1] = hpal[src[u + 1]]; |
| 125 | dst[u + 2] = hpal[src[u + 2]]; |
| 126 | dst[u + 3] = hpal[src[u + 3]]; |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | host_video_flip(); |
| 131 | } |
| 132 | |
| 133 | void host_video_blit16(const unsigned short *src, int w, int h, int stride) |
| 134 | { |
| 135 | unsigned short *dst = host_screen; |
| 136 | int i; |
| 137 | |
| 138 | for (i = 0; i < 240; i++, dst += host_stride / 2, src += stride / 2) |
| 139 | memcpy(dst, src, w*2); |
| 140 | |
| 141 | host_video_flip(); |
| 142 | } |
| 143 | |
| 144 | void host_video_normalize_ts(int *x1024, int *y1024) |
| 145 | { |
| 146 | static int lx, ly, lw = 800, lh = 480, checked; |
| 147 | |
| 148 | if (!checked) { |
| 149 | get_layer_size(&lx, &ly, &lw, &lh); |
| 150 | checked = 1; // XXX: might change, so may need to recheck |
| 151 | } |
| 152 | *x1024 = (*x1024 - lx) * 1024 / lw; |
| 153 | *y1024 = (*y1024 - ly) * 1024 / lh; |
| 154 | } |
| 155 | |
| 156 | #elif defined(WIZ) |
| 157 | |
| 158 | #include "warm/warm.c" |
| 159 | #include "wiz_video.c" |
| 160 | |
| 161 | void *host_video_flip(void) |
| 162 | { |
| 163 | vout_gp2x_flip(); |
| 164 | host_screen = g_screen_ptr; |
| 165 | return host_screen; |
| 166 | } |
| 167 | |
| 168 | int host_video_init(int *stride, int no_dblbuf) |
| 169 | { |
| 170 | int ret; |
| 171 | |
| 172 | host_stride = 320 * 2; |
| 173 | if (stride != 0) |
| 174 | *stride = host_stride; |
| 175 | |
| 176 | ret = vout_gp2x_init(no_dblbuf); |
| 177 | if (ret != 0) |
| 178 | return ret; |
| 179 | |
| 180 | vout_gp2x_set_mode(16, !no_dblbuf); |
| 181 | host_video_flip(); |
| 182 | return 0; |
| 183 | } |
| 184 | |
| 185 | void host_video_finish(void) |
| 186 | { |
| 187 | vout_gp2x_finish(); |
| 188 | } |
| 189 | |
| 190 | void host_video_update_pal16(unsigned short *pal) |
| 191 | { |
| 192 | vout_gp2x_set_palette16(pal, 256); |
| 193 | } |
| 194 | |
| 195 | void host_video_update_pal32(unsigned int *pal) |
| 196 | { |
| 197 | vout_gp2x_set_palette32(pal, 256); |
| 198 | } |
| 199 | |
| 200 | void host_video_change_bpp(int bpp) |
| 201 | { |
| 202 | vout_gp2x_set_mode(bpp, 1); |
| 203 | } |
| 204 | |
| 205 | #ifdef LOADER |
| 206 | void host_video_blit4(const unsigned char *src, int w, int h, int stride) |
| 207 | { |
| 208 | memcpy(host_screen, src, 320*240/2); // FIXME |
| 209 | host_video_flip(); |
| 210 | } |
| 211 | |
| 212 | void host_video_blit8(const unsigned char *src, int w, int h, int stride) |
| 213 | { |
| 214 | if (probably_caanoo) { |
| 215 | unsigned char *dst = host_screen; |
| 216 | int i; |
| 217 | for (i = 0; i < 240; i++, dst += 320, src += stride) |
| 218 | memcpy(dst, src, w); |
| 219 | } |
| 220 | else { |
| 221 | extern void rotated_blit8(void *dst, const void *linesx4); |
| 222 | rotated_blit8(host_screen, src); |
| 223 | } |
| 224 | |
| 225 | host_video_flip(); |
| 226 | } |
| 227 | |
| 228 | void host_video_blit16(const unsigned short *src, int w, int h, int stride) |
| 229 | { |
| 230 | if (probably_caanoo) { |
| 231 | unsigned short *dst = host_screen; |
| 232 | int i; |
| 233 | for (i = 0; i < 240; i++, dst += 320, src += stride / 2) |
| 234 | memcpy(dst, src, w*2); |
| 235 | } |
| 236 | else { |
| 237 | extern void rotated_blit16(void *dst, const void *linesx4); |
| 238 | rotated_blit16(host_screen, src); |
| 239 | } |
| 240 | |
| 241 | host_video_flip(); |
| 242 | } |
| 243 | #endif // LOADER |
| 244 | |
| 245 | void host_video_normalize_ts(int *x1024, int *y1024) |
| 246 | { |
| 247 | *x1024 = *x1024 * 1024 / 320; |
| 248 | *y1024 = *y1024 * 1024 / 240; |
| 249 | } |
| 250 | |
| 251 | #endif // WIZ |
| 252 | |
| 253 | // vim:shiftwidth=2:expandtab |