handle another palette write
[ginge.git] / common / host_fb.c
CommitLineData
499bf01c 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 */
4d045184 7#include <string.h>
3adc9ccb 8#ifdef LOADER
9#include "../loader/realfuncs.h"
10#endif
11
3adc9ccb 12#include "host_fb.h"
13
4d045184 14static void *host_screen;
15static int host_stride;
16
17#if defined(PND)
18
15a2d3ea 19#include "libpicofe/linux/fbdev.c"
4d045184 20
3adc9ccb 21static struct vout_fbdev *fbdev;
6ca08393 22static unsigned short host_pal[256];
3adc9ccb 23
4d045184 24void *host_video_flip(void)
25{
26 host_screen = vout_fbdev_flip(fbdev);
27 return host_screen;
28}
29
3adc9ccb 30int host_video_init(int *stride, int no_dblbuf)
31{
4d045184 32 const char *fbdev_name;
33 int w, h;
34
35 fbdev_name = getenv("FBDEV");
36 if (fbdev_name == NULL)
37 fbdev_name = "/dev/fb1";
38
eb058b48 39 w = h = 0;
8424752c 40 fbdev = vout_fbdev_init(fbdev_name, &w, &h, 16, no_dblbuf ? 1 : 3);
4d045184 41 if (fbdev == NULL)
42 return -1;
43
44 host_stride = w * 2;
45 if (stride != 0)
46 *stride = host_stride;
47 host_video_flip();
3adc9ccb 48
4d045184 49 return 0;
3adc9ccb 50}
51
6ca08393 52void host_video_finish(void)
3adc9ccb 53{
6ca08393 54 vout_fbdev_finish(fbdev);
55 fbdev = NULL;
4d045184 56}
57
7000b522 58void host_video_update_pal16(unsigned short *pal)
59{
60 memcpy(host_pal, pal, sizeof(host_pal));
61}
62
63void host_video_update_pal32(unsigned int *pal)
4d045184 64{
65 unsigned short *dstp = host_pal;
66 int i;
67
68 for (i = 0; i < 256; i++, pal++, dstp++) {
69 unsigned int t = *pal;
70 *dstp = ((t >> 8) & 0xf800) | ((t >> 5) & 0x07e0) | ((t >> 3) & 0x001f);
71 }
72}
73
6ca08393 74void host_video_change_bpp(int bpp)
75{
76}
77
7000b522 78void host_video_blit4(const unsigned char *src, int w, int h, int stride)
4d045184 79{
80 unsigned short *dst = host_screen;
81 unsigned short *hpal = host_pal;
82 int i, u;
83
7000b522 84 for (i = 0; i < 240; i++, dst += host_stride / 2, src += stride) {
85 for (u = 0; i < w / 2; u++) {
86 dst[u*2 + 0] = hpal[src[u] >> 4];
87 dst[u*2 + 1] = hpal[src[u] & 0x0f];
4d045184 88 }
89 }
90
91 host_video_flip();
3adc9ccb 92}
4d045184 93
7000b522 94void host_video_blit8(const unsigned char *src, int w, int h, int stride)
4d045184 95{
96 unsigned short *dst = host_screen;
97 unsigned short *hpal = host_pal;
98 int i, u;
99
7000b522 100 for (i = 0; i < 240; i++, dst += host_stride / 2, src += stride) {
101 for (u = 0; u < w; u += 4) {
102 dst[u + 0] = hpal[src[u + 0]];
103 dst[u + 1] = hpal[src[u + 1]];
104 dst[u + 2] = hpal[src[u + 2]];
105 dst[u + 3] = hpal[src[u + 3]];
4d045184 106 }
107 }
108
109 host_video_flip();
110}
111
7000b522 112void host_video_blit16(const unsigned short *src, int w, int h, int stride)
4d045184 113{
114 unsigned short *dst = host_screen;
115 int i;
116
7000b522 117 for (i = 0; i < 240; i++, dst += host_stride / 2, src += stride / 2)
118 memcpy(dst, src, w*2);
4d045184 119
120 host_video_flip();
121}
122
6ca08393 123#elif defined(WIZ)
124
eb058b48 125#include "warm/warm.c"
6ca08393 126#include "wiz_video.c"
127
128void *host_video_flip(void)
129{
130 vout_gp2x_flip();
131 host_screen = g_screen_ptr;
132 return host_screen;
133}
134
135int host_video_init(int *stride, int no_dblbuf)
136{
137 int ret;
138
139 host_stride = 320 * 2;
140 if (stride != 0)
141 *stride = host_stride;
142
143 ret = vout_gp2x_init(no_dblbuf);
144 if (ret != 0)
145 return ret;
146
147 vout_gp2x_set_mode(16, !no_dblbuf);
148 host_video_flip();
149 return 0;
150}
151
152void host_video_finish(void)
153{
154 vout_gp2x_finish();
155}
156
7000b522 157void host_video_update_pal16(unsigned short *pal)
158{
159 vout_gp2x_set_palette16(pal, 256);
160}
161
162void host_video_update_pal32(unsigned int *pal)
6ca08393 163{
7000b522 164 vout_gp2x_set_palette32(pal, 256);
6ca08393 165}
166
167void host_video_change_bpp(int bpp)
168{
169 vout_gp2x_set_mode(bpp, 1);
170}
171
172#ifdef LOADER
7000b522 173void host_video_blit4(const unsigned char *src, int w, int h, int stride)
6ca08393 174{
175 memcpy(host_screen, src, 320*240/2); // FIXME
176 host_video_flip();
177}
178
7000b522 179void host_video_blit8(const unsigned char *src, int w, int h, int stride)
6ca08393 180{
2798b18c 181 if (probably_caanoo) {
182 unsigned char *dst = host_screen;
183 int i;
184 for (i = 0; i < 240; i++, dst += 320, src += stride)
185 memcpy(dst, src, w);
186 }
187 else {
188 extern void rotated_blit8(void *dst, const void *linesx4);
189 rotated_blit8(host_screen, src);
190 }
6ca08393 191
6ca08393 192 host_video_flip();
193}
194
7000b522 195void host_video_blit16(const unsigned short *src, int w, int h, int stride)
6ca08393 196{
2798b18c 197 if (probably_caanoo) {
198 unsigned short *dst = host_screen;
199 int i;
200 for (i = 0; i < 240; i++, dst += 320, src += stride / 2)
201 memcpy(dst, src, w*2);
202 }
203 else {
204 extern void rotated_blit16(void *dst, const void *linesx4);
205 rotated_blit16(host_screen, src);
206 }
6ca08393 207
6ca08393 208 host_video_flip();
209}
210#endif // LOADER
211
212#endif // WIZ
213
499bf01c 214// vim:shiftwidth=2:expandtab