sync with latest warm
[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;
17
4d045184 18void *host_video_flip(void)
19{
20 host_screen = vout_fbdev_flip(fbdev);
21 return host_screen;
22}
23
3adc9ccb 24int host_video_init(int *stride, int no_dblbuf)
25{
4d045184 26 const char *fbdev_name;
27 int w, h;
28
29 fbdev_name = getenv("FBDEV");
30 if (fbdev_name == NULL)
31 fbdev_name = "/dev/fb1";
32
33 fbdev = vout_fbdev_init(fbdev_name, &w, &h, no_dblbuf);
34 if (fbdev == NULL)
35 return -1;
36
37 host_stride = w * 2;
38 if (stride != 0)
39 *stride = host_stride;
40 host_video_flip();
3adc9ccb 41
4d045184 42 return 0;
3adc9ccb 43}
44
4d045184 45#elif defined(WIZ)
46
47#include "warm.c"
48#include "wiz_video.c"
49
3adc9ccb 50void *host_video_flip(void)
51{
4d045184 52 vout_gp2x_flip();
53 host_screen = g_screen_ptr;
54 return host_screen;
55}
56
57int host_video_init(int *stride, int no_dblbuf)
58{
59 int ret;
60
61 host_stride = 320 * 2;
62 if (stride != 0)
63 *stride = host_stride;
64
65 ret = vout_gp2x_init(no_dblbuf);
66 if (ret != 0)
67 return ret;
68
69 host_video_flip();
70 return 0;
71}
72
73#endif
74
75static unsigned short host_pal[256];
76
77static void host_update_pal(unsigned int *pal)
78{
79 unsigned short *dstp = host_pal;
80 int i;
81
82 for (i = 0; i < 256; i++, pal++, dstp++) {
83 unsigned int t = *pal;
84 *dstp = ((t >> 8) & 0xf800) | ((t >> 5) & 0x07e0) | ((t >> 3) & 0x001f);
85 }
86}
87
88void host_video_blit4(const unsigned char *src, int w, int h, unsigned int *pal)
89{
90 unsigned short *dst = host_screen;
91 unsigned short *hpal = host_pal;
92 int i, u;
93
94 if (pal != NULL)
95 host_update_pal(pal);
96
97 for (i = 0; i < 240; i++, dst += host_stride / 2 - 320) {
98 for (u = 320 / 2; u > 0; u--, src++) {
99 *dst++ = hpal[*src >> 4];
100 *dst++ = hpal[*src & 0x0f];
101 }
102 }
103
104 host_video_flip();
3adc9ccb 105}
4d045184 106
107void host_video_blit8(const unsigned char *src, int w, int h, unsigned int *pal)
108{
109 unsigned short *dst = host_screen;
110 unsigned short *hpal = host_pal;
111 int i, u;
112
113 if (pal != NULL)
114 host_update_pal(pal);
115
116 for (i = 0; i < 240; i++, dst += host_stride / 2 - 320) {
117 for (u = 320 / 4; u > 0; u--) {
118 *dst++ = hpal[*src++];
119 *dst++ = hpal[*src++];
120 *dst++ = hpal[*src++];
121 *dst++ = hpal[*src++];
122 }
123 }
124
125 host_video_flip();
126}
127
128void host_video_blit16(const unsigned short *src, int w, int h)
129{
130 unsigned short *dst = host_screen;
131 int i;
132
133 for (i = 0; i < 240; i++, dst += host_stride / 2, src += 320)
134 memcpy(dst, src, 320*2);
135
136 host_video_flip();
137}
138