499bf01c |
1 | /* |
2 | * GINGE - GINGE Is Not Gp2x Emulator |
3 | * (C) notaz, 2010-2011 |
4 | * |
5 | * This work is licensed under the MAME license, see COPYING file for details. |
6 | */ |
4d045184 |
7 | #include <string.h> |
3adc9ccb |
8 | #ifdef LOADER |
9 | #include "../loader/realfuncs.h" |
10 | #endif |
11 | |
3adc9ccb |
12 | #include "host_fb.h" |
13 | |
4d045184 |
14 | static void *host_screen; |
15 | static int host_stride; |
16 | |
17 | #if defined(PND) |
18 | |
15a2d3ea |
19 | #include "libpicofe/linux/fbdev.c" |
88d814e3 |
20 | #include "omapfb.h" |
4d045184 |
21 | |
3adc9ccb |
22 | static struct vout_fbdev *fbdev; |
6ca08393 |
23 | static unsigned short host_pal[256]; |
3adc9ccb |
24 | |
88d814e3 |
25 | static int get_layer_size(int *x, int *y, int *w, int *h) |
26 | { |
27 | struct omapfb_plane_info pi; |
28 | int ret; |
29 | |
30 | ret = ioctl(vout_fbdev_get_fd(fbdev), OMAPFB_QUERY_PLANE, &pi); |
31 | if (ret != 0) { |
32 | perror("OMAPFB_QUERY_PLANE"); |
33 | return -1; |
34 | } |
35 | |
36 | *x = pi.pos_x; |
37 | *y = pi.pos_y; |
38 | *w = pi.out_width; |
39 | *h = pi.out_height; |
40 | printf("layer: %d,%d %dx%d\n", *x, *y, *w, *h); |
41 | |
42 | return 0; |
43 | } |
44 | |
4d045184 |
45 | void *host_video_flip(void) |
46 | { |
47 | host_screen = vout_fbdev_flip(fbdev); |
48 | return host_screen; |
49 | } |
50 | |
3adc9ccb |
51 | int host_video_init(int *stride, int no_dblbuf) |
52 | { |
4d045184 |
53 | const char *fbdev_name; |
54 | int w, h; |
55 | |
56 | fbdev_name = getenv("FBDEV"); |
57 | if (fbdev_name == NULL) |
58 | fbdev_name = "/dev/fb1"; |
59 | |
eb058b48 |
60 | w = h = 0; |
8424752c |
61 | fbdev = vout_fbdev_init(fbdev_name, &w, &h, 16, no_dblbuf ? 1 : 3); |
4d045184 |
62 | if (fbdev == NULL) |
63 | return -1; |
64 | |
65 | host_stride = w * 2; |
66 | if (stride != 0) |
67 | *stride = host_stride; |
68 | host_video_flip(); |
3adc9ccb |
69 | |
4d045184 |
70 | return 0; |
3adc9ccb |
71 | } |
72 | |
6ca08393 |
73 | void host_video_finish(void) |
3adc9ccb |
74 | { |
6ca08393 |
75 | vout_fbdev_finish(fbdev); |
76 | fbdev = NULL; |
4d045184 |
77 | } |
78 | |
7000b522 |
79 | void host_video_update_pal16(unsigned short *pal) |
80 | { |
81 | memcpy(host_pal, pal, sizeof(host_pal)); |
82 | } |
83 | |
84 | void host_video_update_pal32(unsigned int *pal) |
4d045184 |
85 | { |
86 | unsigned short *dstp = host_pal; |
87 | int i; |
88 | |
89 | for (i = 0; i < 256; i++, pal++, dstp++) { |
90 | unsigned int t = *pal; |
91 | *dstp = ((t >> 8) & 0xf800) | ((t >> 5) & 0x07e0) | ((t >> 3) & 0x001f); |
92 | } |
93 | } |
94 | |
6ca08393 |
95 | void host_video_change_bpp(int bpp) |
96 | { |
97 | } |
98 | |
7000b522 |
99 | void host_video_blit4(const unsigned char *src, int w, int h, int stride) |
4d045184 |
100 | { |
101 | unsigned short *dst = host_screen; |
102 | unsigned short *hpal = host_pal; |
103 | int i, u; |
104 | |
7000b522 |
105 | for (i = 0; i < 240; i++, dst += host_stride / 2, src += stride) { |
106 | for (u = 0; i < w / 2; u++) { |
107 | dst[u*2 + 0] = hpal[src[u] >> 4]; |
108 | dst[u*2 + 1] = hpal[src[u] & 0x0f]; |
4d045184 |
109 | } |
110 | } |
111 | |
112 | host_video_flip(); |
3adc9ccb |
113 | } |
4d045184 |
114 | |
7000b522 |
115 | void host_video_blit8(const unsigned char *src, int w, int h, int stride) |
4d045184 |
116 | { |
117 | unsigned short *dst = host_screen; |
118 | unsigned short *hpal = host_pal; |
119 | int i, u; |
120 | |
7000b522 |
121 | for (i = 0; i < 240; i++, dst += host_stride / 2, src += stride) { |
122 | for (u = 0; u < w; u += 4) { |
123 | dst[u + 0] = hpal[src[u + 0]]; |
124 | dst[u + 1] = hpal[src[u + 1]]; |
125 | dst[u + 2] = hpal[src[u + 2]]; |
126 | dst[u + 3] = hpal[src[u + 3]]; |
4d045184 |
127 | } |
128 | } |
129 | |
130 | host_video_flip(); |
131 | } |
132 | |
7000b522 |
133 | void host_video_blit16(const unsigned short *src, int w, int h, int stride) |
4d045184 |
134 | { |
135 | unsigned short *dst = host_screen; |
136 | int i; |
137 | |
7000b522 |
138 | for (i = 0; i < 240; i++, dst += host_stride / 2, src += stride / 2) |
139 | memcpy(dst, src, w*2); |
4d045184 |
140 | |
141 | host_video_flip(); |
142 | } |
143 | |
88d814e3 |
144 | void host_video_normalize_ts(int *x1024, int *y1024) |
145 | { |
146 | static int lx, ly, lw = 800, lh = 480, checked; |
147 | |
148 | if (!checked) { |
149 | get_layer_size(&lx, &ly, &lw, &lh); |
150 | checked = 1; // XXX: might change, so may need to recheck |
151 | } |
152 | *x1024 = (*x1024 - lx) * 1024 / lw; |
153 | *y1024 = (*y1024 - ly) * 1024 / lh; |
154 | } |
155 | |
6ca08393 |
156 | #elif defined(WIZ) |
157 | |
eb058b48 |
158 | #include "warm/warm.c" |
6ca08393 |
159 | #include "wiz_video.c" |
160 | |
161 | void *host_video_flip(void) |
162 | { |
163 | vout_gp2x_flip(); |
164 | host_screen = g_screen_ptr; |
165 | return host_screen; |
166 | } |
167 | |
168 | int host_video_init(int *stride, int no_dblbuf) |
169 | { |
170 | int ret; |
171 | |
172 | host_stride = 320 * 2; |
173 | if (stride != 0) |
174 | *stride = host_stride; |
175 | |
176 | ret = vout_gp2x_init(no_dblbuf); |
177 | if (ret != 0) |
178 | return ret; |
179 | |
180 | vout_gp2x_set_mode(16, !no_dblbuf); |
181 | host_video_flip(); |
182 | return 0; |
183 | } |
184 | |
185 | void host_video_finish(void) |
186 | { |
187 | vout_gp2x_finish(); |
188 | } |
189 | |
7000b522 |
190 | void host_video_update_pal16(unsigned short *pal) |
191 | { |
192 | vout_gp2x_set_palette16(pal, 256); |
193 | } |
194 | |
195 | void host_video_update_pal32(unsigned int *pal) |
6ca08393 |
196 | { |
7000b522 |
197 | vout_gp2x_set_palette32(pal, 256); |
6ca08393 |
198 | } |
199 | |
200 | void host_video_change_bpp(int bpp) |
201 | { |
202 | vout_gp2x_set_mode(bpp, 1); |
203 | } |
204 | |
205 | #ifdef LOADER |
7000b522 |
206 | void host_video_blit4(const unsigned char *src, int w, int h, int stride) |
6ca08393 |
207 | { |
208 | memcpy(host_screen, src, 320*240/2); // FIXME |
209 | host_video_flip(); |
210 | } |
211 | |
7000b522 |
212 | void host_video_blit8(const unsigned char *src, int w, int h, int stride) |
6ca08393 |
213 | { |
2798b18c |
214 | if (probably_caanoo) { |
215 | unsigned char *dst = host_screen; |
216 | int i; |
217 | for (i = 0; i < 240; i++, dst += 320, src += stride) |
218 | memcpy(dst, src, w); |
219 | } |
220 | else { |
221 | extern void rotated_blit8(void *dst, const void *linesx4); |
222 | rotated_blit8(host_screen, src); |
223 | } |
6ca08393 |
224 | |
6ca08393 |
225 | host_video_flip(); |
226 | } |
227 | |
7000b522 |
228 | void host_video_blit16(const unsigned short *src, int w, int h, int stride) |
6ca08393 |
229 | { |
2798b18c |
230 | if (probably_caanoo) { |
231 | unsigned short *dst = host_screen; |
232 | int i; |
233 | for (i = 0; i < 240; i++, dst += 320, src += stride / 2) |
234 | memcpy(dst, src, w*2); |
235 | } |
236 | else { |
237 | extern void rotated_blit16(void *dst, const void *linesx4); |
238 | rotated_blit16(host_screen, src); |
239 | } |
6ca08393 |
240 | |
6ca08393 |
241 | host_video_flip(); |
242 | } |
243 | #endif // LOADER |
244 | |
88d814e3 |
245 | void host_video_normalize_ts(int *x1024, int *y1024) |
246 | { |
247 | *x1024 = *x1024 * 1024 / 320; |
248 | *y1024 = *y1024 * 1024 / 240; |
249 | } |
250 | |
6ca08393 |
251 | #endif // WIZ |
252 | |
499bf01c |
253 | // vim:shiftwidth=2:expandtab |