94910ec8b31abd23b6868de63adc44afd6a04c58
[ginge.git] / common / host_fb.c
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
9 static void *host_screen;
10 static int host_stride;
11
12 #if defined(PND)
13
14 #include "fbdev.c"
15
16 static struct vout_fbdev *fbdev;
17 static unsigned short host_pal[256];
18
19 void *host_video_flip(void)
20 {
21   host_screen = vout_fbdev_flip(fbdev);
22   return host_screen;
23 }
24
25 int 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   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();
42
43   return 0;
44 }
45
46 void host_video_finish(void)
47 {
48   vout_fbdev_finish(fbdev);
49   fbdev = NULL;
50 }
51
52 void host_video_update_pal(unsigned int *pal)
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
63 void host_video_change_bpp(int bpp)
64 {
65 }
66
67 void host_video_blit4(const unsigned char *src, int w, int h)
68 {
69   unsigned short *dst = host_screen;
70   unsigned short *hpal = host_pal;
71   int i, u;
72
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();
81 }
82
83 void host_video_blit8(const unsigned char *src, int w, int h)
84 {
85   unsigned short *dst = host_screen;
86   unsigned short *hpal = host_pal;
87   int i, u;
88
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
101 void 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
112 #elif defined(WIZ)
113
114 #include "warm.c"
115 #include "wiz_video.c"
116
117 void *host_video_flip(void)
118 {
119   vout_gp2x_flip();
120   host_screen = g_screen_ptr;
121   return host_screen;
122 }
123
124 int 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
141 void host_video_finish(void)
142 {
143   vout_gp2x_finish();
144 }
145
146 void host_video_update_pal(unsigned int *pal)
147 {
148   vout_gp2x_set_palette(pal, 256);
149 }
150
151 void host_video_change_bpp(int bpp)
152 {
153   vout_gp2x_set_mode(bpp, 1);
154 }
155
156 #ifdef LOADER
157 void 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
163 void 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
171 void 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