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