wiz blitters, fb restore, tweaks
[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
6ca08393 52void host_video_update_pal(unsigned int *pal)
4d045184 53{
54 unsigned short *dstp = host_pal;
55 int i;
56
57 for (i = 0; i < 256; i++, pal++, dstp++) {
58 unsigned int t = *pal;
59 *dstp = ((t >> 8) & 0xf800) | ((t >> 5) & 0x07e0) | ((t >> 3) & 0x001f);
60 }
61}
62
6ca08393 63void host_video_change_bpp(int bpp)
64{
65}
66
67void host_video_blit4(const unsigned char *src, int w, int h)
4d045184 68{
69 unsigned short *dst = host_screen;
70 unsigned short *hpal = host_pal;
71 int i, u;
72
4d045184 73 for (i = 0; i < 240; i++, dst += host_stride / 2 - 320) {
74 for (u = 320 / 2; u > 0; u--, src++) {
75 *dst++ = hpal[*src >> 4];
76 *dst++ = hpal[*src & 0x0f];
77 }
78 }
79
80 host_video_flip();
3adc9ccb 81}
4d045184 82
6ca08393 83void host_video_blit8(const unsigned char *src, int w, int h)
4d045184 84{
85 unsigned short *dst = host_screen;
86 unsigned short *hpal = host_pal;
87 int i, u;
88
4d045184 89 for (i = 0; i < 240; i++, dst += host_stride / 2 - 320) {
90 for (u = 320 / 4; u > 0; u--) {
91 *dst++ = hpal[*src++];
92 *dst++ = hpal[*src++];
93 *dst++ = hpal[*src++];
94 *dst++ = hpal[*src++];
95 }
96 }
97
98 host_video_flip();
99}
100
101void host_video_blit16(const unsigned short *src, int w, int h)
102{
103 unsigned short *dst = host_screen;
104 int i;
105
106 for (i = 0; i < 240; i++, dst += host_stride / 2, src += 320)
107 memcpy(dst, src, 320*2);
108
109 host_video_flip();
110}
111
6ca08393 112#elif defined(WIZ)
113
114#include "warm.c"
115#include "wiz_video.c"
116
117void *host_video_flip(void)
118{
119 vout_gp2x_flip();
120 host_screen = g_screen_ptr;
121 return host_screen;
122}
123
124int host_video_init(int *stride, int no_dblbuf)
125{
126 int ret;
127
128 host_stride = 320 * 2;
129 if (stride != 0)
130 *stride = host_stride;
131
132 ret = vout_gp2x_init(no_dblbuf);
133 if (ret != 0)
134 return ret;
135
136 vout_gp2x_set_mode(16, !no_dblbuf);
137 host_video_flip();
138 return 0;
139}
140
141void host_video_finish(void)
142{
143 vout_gp2x_finish();
144}
145
146void host_video_update_pal(unsigned int *pal)
147{
148 vout_gp2x_set_palette(pal, 256);
149}
150
151void host_video_change_bpp(int bpp)
152{
153 vout_gp2x_set_mode(bpp, 1);
154}
155
156#ifdef LOADER
157void host_video_blit4(const unsigned char *src, int w, int h)
158{
159 memcpy(host_screen, src, 320*240/2); // FIXME
160 host_video_flip();
161}
162
163void host_video_blit8(const unsigned char *src, int w, int h)
164{
165 extern void rotated_blit8(void *dst, const void *linesx4);
166
167 rotated_blit8(host_screen, src);
168 host_video_flip();
169}
170
171void host_video_blit16(const unsigned short *src, int w, int h)
172{
173 extern void rotated_blit16(void *dst, const void *linesx4);
174
175 rotated_blit16(host_screen, src);
176 host_video_flip();
177}
178#endif // LOADER
179
180#endif // WIZ
181