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