loader: try large mmap first
[ginge.git] / common / host_fb.c
... / ...
CommitLineData
1// vim:shiftwidth=2:expandtab
2#include <string.h>
3#ifdef LOADER
4#include "../loader/realfuncs.h"
5#endif
6
7#include "host_fb.h"
8
9static void *host_screen;
10static int host_stride;
11
12#if defined(PND)
13
14#include "linux/fbdev.c"
15
16static struct vout_fbdev *fbdev;
17static unsigned short host_pal[256];
18
19void *host_video_flip(void)
20{
21 host_screen = vout_fbdev_flip(fbdev);
22 return host_screen;
23}
24
25int host_video_init(int *stride, int no_dblbuf)
26{
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 w = h = 0;
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();
43
44 return 0;
45}
46
47void host_video_finish(void)
48{
49 vout_fbdev_finish(fbdev);
50 fbdev = NULL;
51}
52
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)
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
69void host_video_change_bpp(int bpp)
70{
71}
72
73void host_video_blit4(const unsigned char *src, int w, int h, int stride)
74{
75 unsigned short *dst = host_screen;
76 unsigned short *hpal = host_pal;
77 int i, u;
78
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];
83 }
84 }
85
86 host_video_flip();
87}
88
89void host_video_blit8(const unsigned char *src, int w, int h, int stride)
90{
91 unsigned short *dst = host_screen;
92 unsigned short *hpal = host_pal;
93 int i, u;
94
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]];
101 }
102 }
103
104 host_video_flip();
105}
106
107void host_video_blit16(const unsigned short *src, int w, int h, int stride)
108{
109 unsigned short *dst = host_screen;
110 int i;
111
112 for (i = 0; i < 240; i++, dst += host_stride / 2, src += stride / 2)
113 memcpy(dst, src, w*2);
114
115 host_video_flip();
116}
117
118#elif defined(WIZ)
119
120#include "warm/warm.c"
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
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)
158{
159 vout_gp2x_set_palette32(pal, 256);
160}
161
162void host_video_change_bpp(int bpp)
163{
164 vout_gp2x_set_mode(bpp, 1);
165}
166
167#ifdef LOADER
168void host_video_blit4(const unsigned char *src, int w, int h, int stride)
169{
170 memcpy(host_screen, src, 320*240/2); // FIXME
171 host_video_flip();
172}
173
174void host_video_blit8(const unsigned char *src, int w, int h, int stride)
175{
176 extern void rotated_blit8(void *dst, const void *linesx4);
177
178 rotated_blit8(host_screen, src);
179 host_video_flip();
180}
181
182void host_video_blit16(const unsigned short *src, int w, int h, int stride)
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