1 |
dpavlin |
4 |
/* |
2 |
dpavlin |
34 |
* Copyright (C) 2003-2007 Anders Gavare. All rights reserved. |
3 |
dpavlin |
4 |
* |
4 |
|
|
* Redistribution and use in source and binary forms, with or without |
5 |
|
|
* modification, are permitted provided that the following conditions are met: |
6 |
|
|
* |
7 |
|
|
* 1. Redistributions of source code must retain the above copyright |
8 |
|
|
* notice, this list of conditions and the following disclaimer. |
9 |
|
|
* 2. Redistributions in binary form must reproduce the above copyright |
10 |
|
|
* notice, this list of conditions and the following disclaimer in the |
11 |
|
|
* documentation and/or other materials provided with the distribution. |
12 |
|
|
* 3. The name of the author may not be used to endorse or promote products |
13 |
|
|
* derived from this software without specific prior written permission. |
14 |
|
|
* |
15 |
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
16 |
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
17 |
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
18 |
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
19 |
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
20 |
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
21 |
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
22 |
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
23 |
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
24 |
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
25 |
|
|
* SUCH DAMAGE. |
26 |
|
|
* |
27 |
|
|
* |
28 |
dpavlin |
34 |
* $Id: dev_fb.c,v 1.128 2006/12/30 13:30:57 debug Exp $ |
29 |
dpavlin |
4 |
* |
30 |
|
|
* Generic framebuffer device. |
31 |
|
|
* |
32 |
|
|
* DECstation VFB01 monochrome framebuffer, 1024x864 |
33 |
|
|
* DECstation VFB02 8-bit color framebuffer, 1024x864 |
34 |
|
|
* DECstation Maxine, 1024x768 8-bit color |
35 |
|
|
* Playstation 2 (24-bit color) |
36 |
dpavlin |
28 |
* Generic (any resolution, several bit depths possible, useful for |
37 |
|
|
* testmachines) |
38 |
dpavlin |
4 |
* |
39 |
|
|
* |
40 |
dpavlin |
22 |
* TODO: This should actually be independent of X11, but that |
41 |
dpavlin |
4 |
* might be too hard to do right now. |
42 |
|
|
* |
43 |
|
|
* TODO: playstation 2 pixels are stored in another format, actually |
44 |
|
|
*/ |
45 |
|
|
|
46 |
|
|
#include <stdio.h> |
47 |
|
|
#include <stdlib.h> |
48 |
|
|
#include <string.h> |
49 |
|
|
|
50 |
|
|
#include "console.h" |
51 |
|
|
#include "cpu.h" |
52 |
|
|
#include "devices.h" |
53 |
|
|
#include "machine.h" |
54 |
|
|
#include "memory.h" |
55 |
|
|
#include "misc.h" |
56 |
|
|
#include "x11.h" |
57 |
|
|
|
58 |
|
|
#ifdef WITH_X11 |
59 |
|
|
#include <X11/Xlib.h> |
60 |
|
|
#include <X11/Xos.h> |
61 |
|
|
#include <X11/Xutil.h> |
62 |
|
|
#endif |
63 |
|
|
|
64 |
|
|
|
65 |
dpavlin |
28 |
#define FB_TICK_SHIFT 19 |
66 |
dpavlin |
4 |
|
67 |
|
|
|
68 |
|
|
/* #define FB_DEBUG */ |
69 |
|
|
|
70 |
|
|
/* |
71 |
|
|
* set_grayscale_palette(): |
72 |
|
|
* |
73 |
|
|
* Fill d->rgb_palette with grayscale values. ncolors should |
74 |
|
|
* be something like 2, 4, 16, or 256. |
75 |
|
|
*/ |
76 |
|
|
void set_grayscale_palette(struct vfb_data *d, int ncolors) |
77 |
|
|
{ |
78 |
|
|
int i, gray; |
79 |
|
|
|
80 |
|
|
for (i=0; i<256; i++) { |
81 |
|
|
gray = 255*i/(ncolors-1); |
82 |
|
|
d->rgb_palette[i*3 + 0] = gray; |
83 |
|
|
d->rgb_palette[i*3 + 1] = gray; |
84 |
|
|
d->rgb_palette[i*3 + 2] = gray; |
85 |
|
|
} |
86 |
|
|
} |
87 |
|
|
|
88 |
|
|
|
89 |
|
|
/* |
90 |
|
|
* set_blackwhite_palette(): |
91 |
|
|
* |
92 |
|
|
* Set color 0 = black, all others to white. |
93 |
|
|
*/ |
94 |
|
|
void set_blackwhite_palette(struct vfb_data *d, int ncolors) |
95 |
|
|
{ |
96 |
|
|
int i, gray; |
97 |
|
|
|
98 |
|
|
for (i=0; i<256; i++) { |
99 |
|
|
gray = i==0? 0 : 255; |
100 |
|
|
d->rgb_palette[i*3 + 0] = gray; |
101 |
|
|
d->rgb_palette[i*3 + 1] = gray; |
102 |
|
|
d->rgb_palette[i*3 + 2] = gray; |
103 |
|
|
} |
104 |
|
|
} |
105 |
|
|
|
106 |
|
|
|
107 |
dpavlin |
28 |
static void set_title(struct vfb_data *d) |
108 |
|
|
{ |
109 |
|
|
snprintf(d->title, sizeof(d->title),"GXemul: %ix%ix%i %s framebuffer", |
110 |
|
|
d->visible_xsize, d->visible_ysize, d->bit_depth, d->name); |
111 |
|
|
d->title[sizeof(d->title)-1] = '\0'; |
112 |
|
|
} |
113 |
|
|
|
114 |
|
|
|
115 |
dpavlin |
4 |
/* |
116 |
dpavlin |
6 |
* dev_fb_resize(): |
117 |
|
|
* |
118 |
|
|
* Resize a framebuffer window. (This functionality is probably a bit buggy, |
119 |
|
|
* because I didn't think of including it from the start.) |
120 |
dpavlin |
28 |
* |
121 |
|
|
* SUPER-IMPORTANT: Anyone who resizes a framebuffer by calling this function |
122 |
|
|
* must also clear all dyntrans address translations manually, in all cpus |
123 |
|
|
* which might have access to the framebuffer! |
124 |
dpavlin |
6 |
*/ |
125 |
|
|
void dev_fb_resize(struct vfb_data *d, int new_xsize, int new_ysize) |
126 |
|
|
{ |
127 |
|
|
unsigned char *new_framebuffer; |
128 |
|
|
int y, new_bytes_per_line; |
129 |
|
|
size_t size; |
130 |
|
|
|
131 |
|
|
if (d == NULL) { |
132 |
|
|
fatal("dev_fb_resize(): d == NULL\n"); |
133 |
|
|
return; |
134 |
|
|
} |
135 |
|
|
|
136 |
dpavlin |
28 |
if (new_xsize < 10 || new_ysize < 10) { |
137 |
|
|
fatal("dev_fb_resize(): size too small.\n"); |
138 |
|
|
exit(1); |
139 |
|
|
} |
140 |
|
|
|
141 |
dpavlin |
6 |
new_bytes_per_line = new_xsize * d->bit_depth / 8; |
142 |
|
|
size = new_ysize * new_bytes_per_line; |
143 |
|
|
|
144 |
|
|
new_framebuffer = malloc(size); |
145 |
|
|
if (new_framebuffer == NULL) { |
146 |
|
|
fprintf(stderr, "dev_fb_resize(): out of memory\n"); |
147 |
|
|
exit(1); |
148 |
|
|
} |
149 |
|
|
|
150 |
|
|
/* Copy the old framebuffer to the new: */ |
151 |
|
|
if (d->framebuffer != NULL) { |
152 |
|
|
for (y=0; y<new_ysize; y++) { |
153 |
|
|
size_t fromofs = d->bytes_per_line * y; |
154 |
|
|
size_t toofs = new_bytes_per_line * y; |
155 |
|
|
size_t len_to_copy = d->bytes_per_line < |
156 |
|
|
new_bytes_per_line? d->bytes_per_line |
157 |
|
|
: new_bytes_per_line; |
158 |
|
|
memset(new_framebuffer + toofs, 0, new_bytes_per_line); |
159 |
|
|
if (y < d->x11_ysize) |
160 |
|
|
memmove(new_framebuffer + toofs, |
161 |
|
|
d->framebuffer + fromofs, len_to_copy); |
162 |
|
|
} |
163 |
|
|
|
164 |
|
|
free(d->framebuffer); |
165 |
|
|
} |
166 |
|
|
|
167 |
|
|
d->framebuffer = new_framebuffer; |
168 |
|
|
d->framebuffer_size = size; |
169 |
|
|
|
170 |
dpavlin |
22 |
if (new_xsize > d->xsize || new_ysize > d->ysize) { |
171 |
dpavlin |
6 |
d->update_x1 = d->update_y1 = 0; |
172 |
|
|
d->update_x2 = new_xsize - 1; |
173 |
|
|
d->update_y2 = new_ysize - 1; |
174 |
|
|
} |
175 |
|
|
|
176 |
|
|
d->bytes_per_line = new_bytes_per_line; |
177 |
dpavlin |
22 |
d->xsize = d->visible_xsize = new_xsize; |
178 |
|
|
d->ysize = d->visible_ysize = new_ysize; |
179 |
dpavlin |
6 |
|
180 |
dpavlin |
22 |
d->x11_xsize = d->xsize / d->vfb_scaledown; |
181 |
|
|
d->x11_ysize = d->ysize / d->vfb_scaledown; |
182 |
|
|
|
183 |
dpavlin |
28 |
memory_device_update_data(d->memory, d, d->framebuffer); |
184 |
|
|
|
185 |
|
|
set_title(d); |
186 |
|
|
|
187 |
dpavlin |
6 |
#ifdef WITH_X11 |
188 |
dpavlin |
28 |
if (d->fb_window != NULL) { |
189 |
dpavlin |
6 |
x11_fb_resize(d->fb_window, new_xsize, new_ysize); |
190 |
dpavlin |
28 |
x11_set_standard_properties(d->fb_window, d->title); |
191 |
|
|
} |
192 |
dpavlin |
6 |
#endif |
193 |
|
|
} |
194 |
|
|
|
195 |
|
|
|
196 |
|
|
/* |
197 |
dpavlin |
4 |
* dev_fb_setcursor(): |
198 |
|
|
*/ |
199 |
|
|
void dev_fb_setcursor(struct vfb_data *d, int cursor_x, int cursor_y, int on, |
200 |
|
|
int cursor_xsize, int cursor_ysize) |
201 |
|
|
{ |
202 |
|
|
if (cursor_x < 0) |
203 |
|
|
cursor_x = 0; |
204 |
|
|
if (cursor_y < 0) |
205 |
|
|
cursor_y = 0; |
206 |
|
|
if (cursor_x + cursor_xsize >= d->xsize) |
207 |
|
|
cursor_x = d->xsize - cursor_xsize; |
208 |
|
|
if (cursor_y + cursor_ysize >= d->ysize) |
209 |
|
|
cursor_y = d->ysize - cursor_ysize; |
210 |
|
|
|
211 |
|
|
#ifdef WITH_X11 |
212 |
|
|
if (d->fb_window != NULL) { |
213 |
|
|
d->fb_window->cursor_x = cursor_x; |
214 |
|
|
d->fb_window->cursor_y = cursor_y; |
215 |
|
|
d->fb_window->cursor_on = on; |
216 |
|
|
d->fb_window->cursor_xsize = cursor_xsize; |
217 |
|
|
d->fb_window->cursor_ysize = cursor_ysize; |
218 |
|
|
} |
219 |
|
|
#endif |
220 |
|
|
|
221 |
|
|
/* debug("dev_fb_setcursor(%i,%i, size %i,%i, on=%i)\n", |
222 |
|
|
cursor_x, cursor_y, cursor_xsize, cursor_ysize, on); */ |
223 |
|
|
} |
224 |
|
|
|
225 |
|
|
|
226 |
|
|
/* |
227 |
|
|
* framebuffer_blockcopyfill(): |
228 |
|
|
* |
229 |
|
|
* This function should be used by devices that are capable of doing |
230 |
|
|
* block copy/fill. |
231 |
|
|
* |
232 |
|
|
* If fillflag is non-zero, then fill_[rgb] should contain the color |
233 |
dpavlin |
30 |
* with which to fill. (In 8-bit mode, only fill_r is used.) |
234 |
dpavlin |
4 |
* |
235 |
|
|
* If fillflag is zero, copy mode is used, and from_[xy] should contain |
236 |
|
|
* the offset on the framebuffer where we should copy from. |
237 |
|
|
* |
238 |
|
|
* NOTE: Overlapping copies are undefined! |
239 |
|
|
*/ |
240 |
|
|
void framebuffer_blockcopyfill(struct vfb_data *d, int fillflag, int fill_r, |
241 |
|
|
int fill_g, int fill_b, int x1, int y1, int x2, int y2, |
242 |
|
|
int from_x, int from_y) |
243 |
|
|
{ |
244 |
dpavlin |
30 |
int x, y; |
245 |
dpavlin |
4 |
long from_ofs, dest_ofs, linelen; |
246 |
|
|
|
247 |
|
|
if (fillflag) |
248 |
|
|
debug("framebuffer_blockcopyfill(FILL, %i,%i, %i,%i, " |
249 |
|
|
"color %i,%i,%i)\n", x1,y1, x2,y2, fill_r, fill_g, fill_b); |
250 |
|
|
else |
251 |
|
|
debug("framebuffer_blockcopyfill(COPY, %i,%i, %i,%i, from " |
252 |
|
|
"%i,%i)\n", x1,y1, x2,y2, from_x,from_y); |
253 |
|
|
|
254 |
|
|
/* Clip x: */ |
255 |
|
|
if (x1 < 0) x1 = 0; |
256 |
|
|
if (x1 >= d->xsize) x1 = d->xsize-1; |
257 |
|
|
if (x2 < 0) x2 = 0; |
258 |
|
|
if (x2 >= d->xsize) x2 = d->xsize-1; |
259 |
|
|
|
260 |
|
|
dest_ofs = d->bytes_per_line * y1 + (d->bit_depth/8) * x1; |
261 |
|
|
linelen = (x2-x1 + 1) * (d->bit_depth/8); |
262 |
|
|
/* NOTE: linelen is nr of bytes, not pixels */ |
263 |
|
|
|
264 |
|
|
if (fillflag) { |
265 |
|
|
for (y=y1; y<=y2; y++) { |
266 |
|
|
if (y>=0 && y<d->ysize) { |
267 |
dpavlin |
30 |
unsigned char *buf = |
268 |
|
|
d->framebuffer + dest_ofs; |
269 |
|
|
|
270 |
|
|
if (d->bit_depth == 24) { |
271 |
dpavlin |
22 |
for (x=0; x<linelen && x<sizeof(buf); |
272 |
|
|
x += 3) { |
273 |
dpavlin |
4 |
buf[x] = fill_r; |
274 |
|
|
buf[x+1] = fill_g; |
275 |
|
|
buf[x+2] = fill_b; |
276 |
|
|
} |
277 |
dpavlin |
30 |
} else if (d->bit_depth == 8) { |
278 |
|
|
memset(buf, fill_r, linelen); |
279 |
|
|
} else { |
280 |
|
|
fatal("Unimplemented bit-depth (%i)" |
281 |
|
|
" for fb fill\n", d->bit_depth); |
282 |
|
|
exit(1); |
283 |
dpavlin |
22 |
} |
284 |
dpavlin |
4 |
} |
285 |
|
|
|
286 |
|
|
dest_ofs += d->bytes_per_line; |
287 |
|
|
} |
288 |
|
|
} else { |
289 |
|
|
from_ofs = d->bytes_per_line * from_y + |
290 |
|
|
(d->bit_depth/8) * from_x; |
291 |
|
|
for (y=y1; y<=y2; y++) { |
292 |
dpavlin |
30 |
if (y >= 0 && y < d->ysize) { |
293 |
|
|
if (from_y >= 0 && from_y < d->ysize) |
294 |
|
|
memmove(d->framebuffer + dest_ofs, |
295 |
|
|
d->framebuffer + from_ofs, linelen); |
296 |
|
|
else |
297 |
|
|
memset(d->framebuffer + dest_ofs, |
298 |
|
|
0, linelen); |
299 |
|
|
} |
300 |
|
|
from_y ++; |
301 |
dpavlin |
4 |
from_ofs += d->bytes_per_line; |
302 |
|
|
dest_ofs += d->bytes_per_line; |
303 |
|
|
} |
304 |
|
|
} |
305 |
|
|
|
306 |
|
|
if (x1 < d->update_x1 || d->update_x1 == -1) d->update_x1 = x1; |
307 |
|
|
if (x1 > d->update_x2 || d->update_x2 == -1) d->update_x2 = x1; |
308 |
|
|
if (x2 < d->update_x1 || d->update_x1 == -1) d->update_x1 = x2; |
309 |
|
|
if (x2 > d->update_x2 || d->update_x2 == -1) d->update_x2 = x2; |
310 |
|
|
|
311 |
|
|
if (y1 < d->update_y1 || d->update_y1 == -1) d->update_y1 = y1; |
312 |
|
|
if (y1 > d->update_y2 || d->update_y2 == -1) d->update_y2 = y1; |
313 |
|
|
if (y2 < d->update_y1 || d->update_y1 == -1) d->update_y1 = y2; |
314 |
|
|
if (y2 > d->update_y2 || d->update_y2 == -1) d->update_y2 = y2; |
315 |
|
|
} |
316 |
|
|
|
317 |
|
|
|
318 |
|
|
#ifdef WITH_X11 |
319 |
|
|
|
320 |
dpavlin |
22 |
#define REDRAW redraw_fallback |
321 |
|
|
#include "fb_include.c" |
322 |
|
|
#undef REDRAW |
323 |
dpavlin |
4 |
|
324 |
dpavlin |
22 |
#define FB_24 |
325 |
|
|
#define REDRAW redraw_24 |
326 |
|
|
#include "fb_include.c" |
327 |
|
|
#undef REDRAW |
328 |
|
|
#undef FB_24 |
329 |
|
|
#define FB_16 |
330 |
|
|
#define REDRAW redraw_16 |
331 |
|
|
#include "fb_include.c" |
332 |
|
|
#undef FB_16 |
333 |
|
|
#undef REDRAW |
334 |
|
|
#define FB_15 |
335 |
|
|
#define REDRAW redraw_15 |
336 |
|
|
#include "fb_include.c" |
337 |
|
|
#undef REDRAW |
338 |
|
|
#undef FB_15 |
339 |
dpavlin |
4 |
|
340 |
dpavlin |
22 |
#define FB_BO |
341 |
|
|
#define FB_24 |
342 |
|
|
#define REDRAW redraw_24_bo |
343 |
|
|
#include "fb_include.c" |
344 |
|
|
#undef REDRAW |
345 |
|
|
#undef FB_24 |
346 |
|
|
#define FB_16 |
347 |
|
|
#define REDRAW redraw_16_bo |
348 |
|
|
#include "fb_include.c" |
349 |
|
|
#undef FB_16 |
350 |
|
|
#undef REDRAW |
351 |
|
|
#define FB_15 |
352 |
|
|
#define REDRAW redraw_15_bo |
353 |
|
|
#include "fb_include.c" |
354 |
|
|
#undef REDRAW |
355 |
|
|
#undef FB_15 |
356 |
|
|
#undef FB_BO |
357 |
dpavlin |
4 |
|
358 |
dpavlin |
22 |
#define FB_SCALEDOWN |
359 |
dpavlin |
4 |
|
360 |
dpavlin |
22 |
#define REDRAW redraw_fallback_sd |
361 |
|
|
#include "fb_include.c" |
362 |
|
|
#undef REDRAW |
363 |
dpavlin |
4 |
|
364 |
dpavlin |
22 |
#define FB_24 |
365 |
|
|
#define REDRAW redraw_24_sd |
366 |
|
|
#include "fb_include.c" |
367 |
|
|
#undef REDRAW |
368 |
|
|
#undef FB_24 |
369 |
|
|
#define FB_16 |
370 |
|
|
#define REDRAW redraw_16_sd |
371 |
|
|
#include "fb_include.c" |
372 |
|
|
#undef FB_16 |
373 |
|
|
#undef REDRAW |
374 |
|
|
#define FB_15 |
375 |
|
|
#define REDRAW redraw_15_sd |
376 |
|
|
#include "fb_include.c" |
377 |
|
|
#undef REDRAW |
378 |
|
|
#undef FB_15 |
379 |
dpavlin |
4 |
|
380 |
dpavlin |
22 |
#define FB_BO |
381 |
|
|
#define FB_24 |
382 |
|
|
#define REDRAW redraw_24_bo_sd |
383 |
|
|
#include "fb_include.c" |
384 |
|
|
#undef REDRAW |
385 |
|
|
#undef FB_24 |
386 |
|
|
#define FB_16 |
387 |
|
|
#define REDRAW redraw_16_bo_sd |
388 |
|
|
#include "fb_include.c" |
389 |
|
|
#undef FB_16 |
390 |
|
|
#undef REDRAW |
391 |
|
|
#define FB_15 |
392 |
|
|
#define REDRAW redraw_15_bo_sd |
393 |
|
|
#include "fb_include.c" |
394 |
|
|
#undef REDRAW |
395 |
|
|
#undef FB_15 |
396 |
|
|
#undef FB_BO |
397 |
dpavlin |
4 |
|
398 |
dpavlin |
22 |
void (*redraw[2 * 4 * 2])(struct vfb_data *, int, int) = { |
399 |
|
|
redraw_fallback, redraw_fallback, |
400 |
|
|
redraw_15, redraw_15_bo, |
401 |
|
|
redraw_16, redraw_16_bo, |
402 |
|
|
redraw_24, redraw_24_bo, |
403 |
|
|
redraw_fallback_sd, redraw_fallback_sd, |
404 |
|
|
redraw_15_sd, redraw_15_bo_sd, |
405 |
|
|
redraw_16_sd, redraw_16_bo_sd, |
406 |
|
|
redraw_24_sd, redraw_24_bo_sd }; |
407 |
dpavlin |
4 |
|
408 |
dpavlin |
22 |
#endif /* WITH_X11 */ |
409 |
dpavlin |
4 |
|
410 |
|
|
|
411 |
dpavlin |
32 |
DEVICE_TICK(fb) |
412 |
dpavlin |
4 |
{ |
413 |
|
|
struct vfb_data *d = extra; |
414 |
|
|
#ifdef WITH_X11 |
415 |
|
|
int need_to_flush_x11 = 0; |
416 |
|
|
int need_to_redraw_cursor = 0; |
417 |
|
|
#endif |
418 |
|
|
|
419 |
|
|
if (!cpu->machine->use_x11) |
420 |
|
|
return; |
421 |
|
|
|
422 |
|
|
do { |
423 |
dpavlin |
12 |
uint64_t high, low = (uint64_t)(int64_t) -1; |
424 |
dpavlin |
4 |
int x, y; |
425 |
|
|
|
426 |
dpavlin |
12 |
memory_device_dyntrans_access(cpu, cpu->mem, |
427 |
dpavlin |
4 |
extra, &low, &high); |
428 |
|
|
if ((int64_t)low == -1) |
429 |
|
|
break; |
430 |
|
|
|
431 |
|
|
/* printf("low=%016llx high=%016llx\n", |
432 |
|
|
(long long)low, (long long)high); */ |
433 |
|
|
|
434 |
|
|
x = (low % d->bytes_per_line) * 8 / d->bit_depth; |
435 |
|
|
y = low / d->bytes_per_line; |
436 |
|
|
if (x < d->update_x1 || d->update_x1 == -1) |
437 |
|
|
d->update_x1 = x; |
438 |
|
|
if (x > d->update_x2 || d->update_x2 == -1) |
439 |
|
|
d->update_x2 = x; |
440 |
|
|
if (y < d->update_y1 || d->update_y1 == -1) |
441 |
|
|
d->update_y1 = y; |
442 |
|
|
if (y > d->update_y2 || d->update_y2 == -1) |
443 |
|
|
d->update_y2 = y; |
444 |
|
|
|
445 |
|
|
x = ((low+7) % d->bytes_per_line) * 8 / d->bit_depth; |
446 |
|
|
y = (low+7) / d->bytes_per_line; |
447 |
|
|
if (x < d->update_x1 || d->update_x1 == -1) |
448 |
|
|
d->update_x1 = x; |
449 |
|
|
if (x > d->update_x2 || d->update_x2 == -1) |
450 |
|
|
d->update_x2 = x; |
451 |
|
|
if (y < d->update_y1 || d->update_y1 == -1) |
452 |
|
|
d->update_y1 = y; |
453 |
|
|
if (y > d->update_y2 || d->update_y2 == -1) |
454 |
|
|
d->update_y2 = y; |
455 |
|
|
|
456 |
|
|
x = (high % d->bytes_per_line) * 8 / d->bit_depth; |
457 |
|
|
y = high / d->bytes_per_line; |
458 |
|
|
if (x < d->update_x1 || d->update_x1 == -1) |
459 |
|
|
d->update_x1 = x; |
460 |
|
|
if (x > d->update_x2 || d->update_x2 == -1) |
461 |
|
|
d->update_x2 = x; |
462 |
|
|
if (y < d->update_y1 || d->update_y1 == -1) |
463 |
|
|
d->update_y1 = y; |
464 |
|
|
if (y > d->update_y2 || d->update_y2 == -1) |
465 |
|
|
d->update_y2 = y; |
466 |
|
|
|
467 |
|
|
x = ((high+7) % d->bytes_per_line) * 8 / d->bit_depth; |
468 |
|
|
y = (high+7) / d->bytes_per_line; |
469 |
|
|
if (x < d->update_x1 || d->update_x1 == -1) |
470 |
|
|
d->update_x1 = x; |
471 |
|
|
if (x > d->update_x2 || d->update_x2 == -1) |
472 |
|
|
d->update_x2 = x; |
473 |
|
|
if (y < d->update_y1 || d->update_y1 == -1) |
474 |
|
|
d->update_y1 = y; |
475 |
|
|
if (y > d->update_y2 || d->update_y2 == -1) |
476 |
|
|
d->update_y2 = y; |
477 |
|
|
|
478 |
|
|
/* |
479 |
|
|
* An update covering more than one line will automatically |
480 |
|
|
* force an update of all the affected lines: |
481 |
|
|
*/ |
482 |
|
|
if (d->update_y1 != d->update_y2) { |
483 |
|
|
d->update_x1 = 0; |
484 |
|
|
d->update_x2 = d->xsize-1; |
485 |
|
|
} |
486 |
|
|
} while (0); |
487 |
|
|
|
488 |
|
|
#ifdef WITH_X11 |
489 |
|
|
/* Do we need to redraw the cursor? */ |
490 |
|
|
if (d->fb_window->cursor_on != d->fb_window->OLD_cursor_on || |
491 |
|
|
d->fb_window->cursor_x != d->fb_window->OLD_cursor_x || |
492 |
|
|
d->fb_window->cursor_y != d->fb_window->OLD_cursor_y || |
493 |
|
|
d->fb_window->cursor_xsize != d->fb_window->OLD_cursor_xsize || |
494 |
|
|
d->fb_window->cursor_ysize != d->fb_window->OLD_cursor_ysize) |
495 |
|
|
need_to_redraw_cursor = 1; |
496 |
|
|
|
497 |
|
|
if (d->update_x2 != -1) { |
498 |
dpavlin |
14 |
if (((d->update_x1 >= d->fb_window->OLD_cursor_x && |
499 |
|
|
d->update_x1 < (d->fb_window->OLD_cursor_x + |
500 |
|
|
d->fb_window->OLD_cursor_xsize)) || |
501 |
dpavlin |
4 |
(d->update_x2 >= d->fb_window->OLD_cursor_x && |
502 |
dpavlin |
14 |
d->update_x2 < (d->fb_window->OLD_cursor_x + |
503 |
|
|
d->fb_window->OLD_cursor_xsize)) || |
504 |
dpavlin |
4 |
(d->update_x1 < d->fb_window->OLD_cursor_x && |
505 |
dpavlin |
14 |
d->update_x2 >= (d->fb_window->OLD_cursor_x + |
506 |
|
|
d->fb_window->OLD_cursor_xsize)) ) && |
507 |
|
|
( (d->update_y1 >= d->fb_window->OLD_cursor_y && |
508 |
|
|
d->update_y1 < (d->fb_window->OLD_cursor_y + |
509 |
|
|
d->fb_window->OLD_cursor_ysize)) || |
510 |
|
|
(d->update_y2 >= d->fb_window->OLD_cursor_y && |
511 |
|
|
d->update_y2 < (d->fb_window->OLD_cursor_y + |
512 |
|
|
d->fb_window->OLD_cursor_ysize)) || |
513 |
|
|
(d->update_y1 < d->fb_window->OLD_cursor_y && |
514 |
|
|
d->update_y2 >= (d->fb_window->OLD_cursor_y + |
515 |
|
|
d->fb_window->OLD_cursor_ysize)) ) ) |
516 |
|
|
need_to_redraw_cursor = 1; |
517 |
dpavlin |
4 |
} |
518 |
|
|
|
519 |
|
|
if (need_to_redraw_cursor) { |
520 |
|
|
/* Remove old cursor, if any: */ |
521 |
|
|
if (d->fb_window->OLD_cursor_on) { |
522 |
|
|
XPutImage(d->fb_window->x11_display, |
523 |
|
|
d->fb_window->x11_fb_window, |
524 |
|
|
d->fb_window->x11_fb_gc, d->fb_window->fb_ximage, |
525 |
|
|
d->fb_window->OLD_cursor_x/d->vfb_scaledown, |
526 |
|
|
d->fb_window->OLD_cursor_y/d->vfb_scaledown, |
527 |
|
|
d->fb_window->OLD_cursor_x/d->vfb_scaledown, |
528 |
|
|
d->fb_window->OLD_cursor_y/d->vfb_scaledown, |
529 |
|
|
d->fb_window->OLD_cursor_xsize/d->vfb_scaledown + 1, |
530 |
dpavlin |
14 |
d->fb_window->OLD_cursor_ysize/d->vfb_scaledown +1); |
531 |
dpavlin |
4 |
} |
532 |
|
|
} |
533 |
|
|
#endif |
534 |
|
|
|
535 |
|
|
if (d->update_x2 != -1) { |
536 |
dpavlin |
24 |
#ifdef WITH_X11 |
537 |
|
|
int y; |
538 |
|
|
#endif |
539 |
|
|
int addr, addr2, q = d->vfb_scaledown; |
540 |
dpavlin |
4 |
|
541 |
dpavlin |
14 |
if (d->update_x1 >= d->visible_xsize) |
542 |
|
|
d->update_x1 = d->visible_xsize - 1; |
543 |
|
|
if (d->update_x2 >= d->visible_xsize) |
544 |
|
|
d->update_x2 = d->visible_xsize - 1; |
545 |
|
|
if (d->update_y1 >= d->visible_ysize) |
546 |
|
|
d->update_y1 = d->visible_ysize - 1; |
547 |
|
|
if (d->update_y2 >= d->visible_ysize) |
548 |
|
|
d->update_y2 = d->visible_ysize - 1; |
549 |
dpavlin |
4 |
|
550 |
dpavlin |
14 |
/* Without these, we might miss the rightmost/bottom pixel: */ |
551 |
dpavlin |
4 |
d->update_x2 += (q - 1); |
552 |
|
|
d->update_y2 += (q - 1); |
553 |
|
|
|
554 |
|
|
d->update_x1 = d->update_x1 / q * q; |
555 |
|
|
d->update_x2 = d->update_x2 / q * q; |
556 |
|
|
d->update_y1 = d->update_y1 / q * q; |
557 |
|
|
d->update_y2 = d->update_y2 / q * q; |
558 |
|
|
|
559 |
dpavlin |
14 |
addr = d->update_y1 * d->bytes_per_line + |
560 |
|
|
d->update_x1 * d->bit_depth / 8; |
561 |
|
|
addr2 = d->update_y1 * d->bytes_per_line + |
562 |
|
|
d->update_x2 * d->bit_depth / 8; |
563 |
dpavlin |
4 |
|
564 |
dpavlin |
22 |
#ifdef WITH_X11 |
565 |
dpavlin |
4 |
for (y=d->update_y1; y<=d->update_y2; y+=q) { |
566 |
dpavlin |
22 |
d->redraw_func(d, addr, addr2 - addr); |
567 |
dpavlin |
4 |
addr += d->bytes_per_line * q; |
568 |
|
|
addr2 += d->bytes_per_line * q; |
569 |
|
|
} |
570 |
|
|
|
571 |
dpavlin |
14 |
XPutImage(d->fb_window->x11_display, d->fb_window-> |
572 |
|
|
x11_fb_window, d->fb_window->x11_fb_gc, d->fb_window-> |
573 |
|
|
fb_ximage, d->update_x1/d->vfb_scaledown, d->update_y1/ |
574 |
|
|
d->vfb_scaledown, d->update_x1/d->vfb_scaledown, |
575 |
|
|
d->update_y1/d->vfb_scaledown, |
576 |
dpavlin |
4 |
(d->update_x2 - d->update_x1)/d->vfb_scaledown + 1, |
577 |
|
|
(d->update_y2 - d->update_y1)/d->vfb_scaledown + 1); |
578 |
|
|
|
579 |
|
|
need_to_flush_x11 = 1; |
580 |
|
|
#endif |
581 |
|
|
|
582 |
|
|
d->update_x1 = d->update_y1 = 99999; |
583 |
|
|
d->update_x2 = d->update_y2 = -1; |
584 |
|
|
} |
585 |
|
|
|
586 |
|
|
#ifdef WITH_X11 |
587 |
|
|
if (need_to_redraw_cursor) { |
588 |
|
|
/* Paint new cursor: */ |
589 |
|
|
if (d->fb_window->cursor_on) { |
590 |
dpavlin |
14 |
x11_redraw_cursor(cpu->machine, |
591 |
|
|
d->fb_window->fb_number); |
592 |
dpavlin |
4 |
d->fb_window->OLD_cursor_on = d->fb_window->cursor_on; |
593 |
|
|
d->fb_window->OLD_cursor_x = d->fb_window->cursor_x; |
594 |
|
|
d->fb_window->OLD_cursor_y = d->fb_window->cursor_y; |
595 |
dpavlin |
14 |
d->fb_window->OLD_cursor_xsize = d->fb_window-> |
596 |
|
|
cursor_xsize; |
597 |
|
|
d->fb_window->OLD_cursor_ysize = d->fb_window-> |
598 |
|
|
cursor_ysize; |
599 |
dpavlin |
22 |
need_to_flush_x11 = 1; |
600 |
dpavlin |
4 |
} |
601 |
|
|
} |
602 |
|
|
#endif |
603 |
|
|
|
604 |
|
|
#ifdef WITH_X11 |
605 |
|
|
if (need_to_flush_x11) |
606 |
|
|
XFlush(d->fb_window->x11_display); |
607 |
|
|
#endif |
608 |
|
|
} |
609 |
|
|
|
610 |
|
|
|
611 |
dpavlin |
22 |
DEVICE_ACCESS(fb) |
612 |
dpavlin |
4 |
{ |
613 |
|
|
struct vfb_data *d = extra; |
614 |
dpavlin |
22 |
size_t i; |
615 |
dpavlin |
4 |
|
616 |
|
|
#ifdef FB_DEBUG |
617 |
|
|
if (writeflag == MEM_WRITE) { if (data[0]) { |
618 |
|
|
fatal("[ dev_fb: write to addr=%08lx, data = ", |
619 |
|
|
(long)relative_addr); |
620 |
|
|
for (i=0; i<len; i++) |
621 |
|
|
fatal("%02x ", data[i]); |
622 |
|
|
fatal("]\n"); |
623 |
|
|
} else { |
624 |
|
|
fatal("[ dev_fb: read from addr=%08lx, data = ", |
625 |
|
|
(long)relative_addr); |
626 |
|
|
for (i=0; i<len; i++) |
627 |
|
|
fatal("%02x ", d->framebuffer[relative_addr + i]); |
628 |
|
|
fatal("]\n"); |
629 |
|
|
} |
630 |
|
|
#endif |
631 |
|
|
|
632 |
dpavlin |
6 |
if (relative_addr >= d->framebuffer_size) |
633 |
|
|
return 0; |
634 |
|
|
|
635 |
dpavlin |
4 |
/* See if a write actually modifies the framebuffer contents: */ |
636 |
|
|
if (writeflag == MEM_WRITE) { |
637 |
|
|
for (i=0; i<len; i++) { |
638 |
|
|
if (data[i] != d->framebuffer[relative_addr + i]) |
639 |
|
|
break; |
640 |
|
|
|
641 |
|
|
/* If all bytes are equal to what is already stored |
642 |
|
|
in the framebuffer, then simply return: */ |
643 |
dpavlin |
22 |
if (i == len-1) |
644 |
dpavlin |
4 |
return 1; |
645 |
|
|
} |
646 |
|
|
} |
647 |
|
|
|
648 |
|
|
/* |
649 |
|
|
* If the framebuffer is modified, then we should keep a track |
650 |
|
|
* of which area(s) we modify, so that the display isn't updated |
651 |
|
|
* unnecessarily. |
652 |
|
|
*/ |
653 |
|
|
if (writeflag == MEM_WRITE && cpu->machine->use_x11) { |
654 |
|
|
int x, y, x2,y2; |
655 |
|
|
|
656 |
|
|
x = (relative_addr % d->bytes_per_line) * 8 / d->bit_depth; |
657 |
|
|
y = relative_addr / d->bytes_per_line; |
658 |
|
|
x2 = ((relative_addr + len) % d->bytes_per_line) |
659 |
|
|
* 8 / d->bit_depth; |
660 |
|
|
y2 = (relative_addr + len) / d->bytes_per_line; |
661 |
|
|
|
662 |
|
|
if (x < d->update_x1 || d->update_x1 == -1) |
663 |
|
|
d->update_x1 = x; |
664 |
|
|
if (x > d->update_x2 || d->update_x2 == -1) |
665 |
|
|
d->update_x2 = x; |
666 |
|
|
|
667 |
|
|
if (y < d->update_y1 || d->update_y1 == -1) |
668 |
|
|
d->update_y1 = y; |
669 |
|
|
if (y > d->update_y2 || d->update_y2 == -1) |
670 |
|
|
d->update_y2 = y; |
671 |
|
|
|
672 |
|
|
if (x2 < d->update_x1 || d->update_x1 == -1) |
673 |
|
|
d->update_x1 = x2; |
674 |
|
|
if (x2 > d->update_x2 || d->update_x2 == -1) |
675 |
|
|
d->update_x2 = x2; |
676 |
|
|
|
677 |
|
|
if (y2 < d->update_y1 || d->update_y1 == -1) |
678 |
|
|
d->update_y1 = y2; |
679 |
|
|
if (y2 > d->update_y2 || d->update_y2 == -1) |
680 |
|
|
d->update_y2 = y2; |
681 |
|
|
|
682 |
|
|
/* |
683 |
|
|
* An update covering more than one line will automatically |
684 |
|
|
* force an update of all the affected lines: |
685 |
|
|
*/ |
686 |
|
|
if (y != y2) { |
687 |
|
|
d->update_x1 = 0; |
688 |
|
|
d->update_x2 = d->xsize-1; |
689 |
|
|
} |
690 |
|
|
} |
691 |
|
|
|
692 |
|
|
/* |
693 |
|
|
* Read from/write to the framebuffer: |
694 |
|
|
* (TODO: take the color_plane_mask into account) |
695 |
|
|
* |
696 |
|
|
* Calling memcpy() is probably overkill, as it usually is just one |
697 |
|
|
* or a few bytes that are read/written at a time. |
698 |
|
|
*/ |
699 |
|
|
if (writeflag == MEM_WRITE) { |
700 |
|
|
if (len > 8) |
701 |
|
|
memcpy(d->framebuffer + relative_addr, data, len); |
702 |
dpavlin |
22 |
else { |
703 |
dpavlin |
4 |
for (i=0; i<len; i++) |
704 |
|
|
d->framebuffer[relative_addr + i] = data[i]; |
705 |
dpavlin |
22 |
} |
706 |
dpavlin |
4 |
} else { |
707 |
|
|
if (len > 8) |
708 |
|
|
memcpy(data, d->framebuffer + relative_addr, len); |
709 |
dpavlin |
22 |
else { |
710 |
dpavlin |
4 |
for (i=0; i<len; i++) |
711 |
|
|
data[i] = d->framebuffer[relative_addr + i]; |
712 |
dpavlin |
22 |
} |
713 |
dpavlin |
4 |
} |
714 |
|
|
|
715 |
|
|
return 1; |
716 |
|
|
} |
717 |
|
|
|
718 |
|
|
|
719 |
|
|
/* |
720 |
|
|
* dev_fb_init(): |
721 |
|
|
* |
722 |
dpavlin |
10 |
* This function is big and ugly, but the point is to initialize a framebuffer |
723 |
|
|
* device. :-) |
724 |
|
|
* |
725 |
|
|
* visible_xsize and visible_ysize are the sizes of the visible display area. |
726 |
|
|
* xsize and ysize tell how much memory is actually allocated (for example |
727 |
|
|
* visible_xsize could be 640, but xsize could be 1024, for better alignment). |
728 |
|
|
* |
729 |
|
|
* vfb_type is useful for selecting special features. |
730 |
|
|
* |
731 |
|
|
* type = VFB_GENERIC is the most useful type, especially when bit_depth = 24. |
732 |
|
|
* |
733 |
|
|
* VFB_DEC_VFB01, _VFB02, and VFB_DEC_MAXINE are DECstation specific. |
734 |
|
|
* |
735 |
dpavlin |
32 |
* VFB_HPC is like generic, but the color encoding is done as on HPCmips |
736 |
|
|
* and Dreamcast. |
737 |
dpavlin |
10 |
* |
738 |
|
|
* If bit_depth = -15 (note the minus sign), then a special hack is used for |
739 |
|
|
* the Playstation Portable's 5-bit R, 5-bit G, 5-bit B. |
740 |
dpavlin |
4 |
*/ |
741 |
|
|
struct vfb_data *dev_fb_init(struct machine *machine, struct memory *mem, |
742 |
|
|
uint64_t baseaddr, int vfb_type, int visible_xsize, int visible_ysize, |
743 |
dpavlin |
12 |
int xsize, int ysize, int bit_depth, char *name) |
744 |
dpavlin |
4 |
{ |
745 |
|
|
struct vfb_data *d; |
746 |
dpavlin |
10 |
size_t size, nlen; |
747 |
dpavlin |
12 |
int flags; |
748 |
dpavlin |
22 |
int reverse_start = 0; |
749 |
dpavlin |
4 |
char *name2; |
750 |
|
|
|
751 |
|
|
d = malloc(sizeof(struct vfb_data)); |
752 |
|
|
if (d == NULL) { |
753 |
|
|
fprintf(stderr, "out of memory\n"); |
754 |
|
|
exit(1); |
755 |
|
|
} |
756 |
|
|
memset(d, 0, sizeof(struct vfb_data)); |
757 |
|
|
|
758 |
dpavlin |
22 |
if (vfb_type & VFB_REVERSE_START) { |
759 |
|
|
vfb_type &= ~VFB_REVERSE_START; |
760 |
|
|
reverse_start = 1; |
761 |
|
|
} |
762 |
|
|
|
763 |
dpavlin |
28 |
d->memory = mem; |
764 |
dpavlin |
4 |
d->vfb_type = vfb_type; |
765 |
|
|
|
766 |
|
|
/* Defaults: */ |
767 |
|
|
d->xsize = xsize; d->visible_xsize = visible_xsize; |
768 |
|
|
d->ysize = ysize; d->visible_ysize = visible_ysize; |
769 |
|
|
|
770 |
|
|
d->bit_depth = bit_depth; |
771 |
|
|
|
772 |
|
|
if (bit_depth == 15) { |
773 |
|
|
d->color32k = 1; |
774 |
|
|
bit_depth = d->bit_depth = 16; |
775 |
dpavlin |
10 |
} else if (bit_depth == -15) { |
776 |
|
|
d->psp_15bit = 1; |
777 |
|
|
bit_depth = d->bit_depth = 16; |
778 |
dpavlin |
4 |
} |
779 |
|
|
|
780 |
|
|
/* Specific types: */ |
781 |
|
|
switch (vfb_type) { |
782 |
|
|
case VFB_DEC_VFB01: |
783 |
|
|
/* DECstation VFB01 (monochrome) */ |
784 |
|
|
d->xsize = 2048; d->visible_xsize = 1024; |
785 |
|
|
d->ysize = 1024; d->visible_ysize = 864; |
786 |
|
|
d->bit_depth = 1; |
787 |
|
|
break; |
788 |
|
|
case VFB_DEC_VFB02: |
789 |
|
|
/* DECstation VFB02 (color) */ |
790 |
|
|
d->xsize = 1024; d->visible_xsize = 1024; |
791 |
|
|
d->ysize = 1024; d->visible_ysize = 864; |
792 |
|
|
d->bit_depth = 8; |
793 |
|
|
break; |
794 |
|
|
case VFB_DEC_MAXINE: |
795 |
|
|
/* DECstation Maxine (1024x768x8) */ |
796 |
|
|
d->xsize = 1024; d->visible_xsize = d->xsize; |
797 |
|
|
d->ysize = 768; d->visible_ysize = d->ysize; |
798 |
|
|
d->bit_depth = 8; |
799 |
|
|
break; |
800 |
|
|
case VFB_PLAYSTATION2: |
801 |
|
|
/* Playstation 2 */ |
802 |
|
|
d->xsize = xsize; d->visible_xsize = d->xsize; |
803 |
|
|
d->ysize = ysize; d->visible_ysize = d->ysize; |
804 |
|
|
d->bit_depth = 24; |
805 |
|
|
break; |
806 |
|
|
} |
807 |
|
|
|
808 |
|
|
if (d->bit_depth == 2 || d->bit_depth == 4) |
809 |
|
|
set_grayscale_palette(d, 1 << d->bit_depth); |
810 |
|
|
else if (d->bit_depth == 8 || d->bit_depth == 1) |
811 |
|
|
set_blackwhite_palette(d, 1 << d->bit_depth); |
812 |
|
|
|
813 |
|
|
d->vfb_scaledown = machine->x11_scaledown; |
814 |
|
|
|
815 |
|
|
d->bytes_per_line = d->xsize * d->bit_depth / 8; |
816 |
|
|
size = d->ysize * d->bytes_per_line; |
817 |
|
|
|
818 |
|
|
d->framebuffer = malloc(size); |
819 |
|
|
if (d->framebuffer == NULL) { |
820 |
|
|
fprintf(stderr, "out of memory\n"); |
821 |
|
|
exit(1); |
822 |
|
|
} |
823 |
|
|
|
824 |
|
|
/* Clear the framebuffer (all black pixels): */ |
825 |
|
|
d->framebuffer_size = size; |
826 |
dpavlin |
22 |
memset(d->framebuffer, reverse_start? 255 : 0, size); |
827 |
dpavlin |
4 |
|
828 |
|
|
d->x11_xsize = d->visible_xsize / d->vfb_scaledown; |
829 |
|
|
d->x11_ysize = d->visible_ysize / d->vfb_scaledown; |
830 |
|
|
|
831 |
dpavlin |
22 |
/* Only "update" from the start if we need to fill with white. */ |
832 |
|
|
/* (The Ximage will be black from the start anyway.) */ |
833 |
|
|
if (reverse_start) { |
834 |
|
|
d->update_x1 = d->update_y1 = 0; |
835 |
|
|
d->update_x2 = d->xsize - 1; |
836 |
|
|
d->update_y2 = d->ysize - 1; |
837 |
|
|
} else { |
838 |
|
|
d->update_x1 = d->update_y1 = 99999; |
839 |
|
|
d->update_x2 = d->update_y2 = -1; |
840 |
|
|
} |
841 |
dpavlin |
4 |
|
842 |
dpavlin |
28 |
d->name = strdup(name); |
843 |
|
|
set_title(d); |
844 |
dpavlin |
4 |
|
845 |
|
|
#ifdef WITH_X11 |
846 |
dpavlin |
22 |
if (machine->use_x11) { |
847 |
|
|
int i = 0; |
848 |
dpavlin |
4 |
d->fb_window = x11_fb_init(d->x11_xsize, d->x11_ysize, |
849 |
dpavlin |
28 |
d->title, machine->x11_scaledown, machine); |
850 |
dpavlin |
22 |
switch (d->fb_window->x11_screen_depth) { |
851 |
|
|
case 15: i = 2; break; |
852 |
|
|
case 16: i = 4; break; |
853 |
|
|
case 24: i = 6; break; |
854 |
|
|
} |
855 |
|
|
if (d->fb_window->fb_ximage->byte_order) |
856 |
|
|
i ++; |
857 |
|
|
if (d->vfb_scaledown > 1) |
858 |
|
|
i += 8; |
859 |
|
|
d->redraw_func = redraw[i]; |
860 |
|
|
} else |
861 |
dpavlin |
4 |
#endif |
862 |
|
|
d->fb_window = NULL; |
863 |
|
|
|
864 |
dpavlin |
10 |
nlen = strlen(name) + 10; |
865 |
|
|
name2 = malloc(nlen); |
866 |
dpavlin |
4 |
if (name2 == NULL) { |
867 |
|
|
fprintf(stderr, "out of memory in dev_fb_init()\n"); |
868 |
|
|
exit(1); |
869 |
|
|
} |
870 |
dpavlin |
10 |
snprintf(name2, nlen, "fb [%s]", name); |
871 |
dpavlin |
4 |
|
872 |
dpavlin |
20 |
flags = DM_DEFAULT; |
873 |
dpavlin |
4 |
if ((baseaddr & 0xfff) == 0) |
874 |
dpavlin |
20 |
flags = DM_DYNTRANS_OK | DM_DYNTRANS_WRITE_OK; |
875 |
dpavlin |
4 |
|
876 |
dpavlin |
20 |
flags |= DM_READS_HAVE_NO_SIDE_EFFECTS; |
877 |
dpavlin |
6 |
|
878 |
dpavlin |
4 |
memory_device_register(mem, name2, baseaddr, size, dev_fb_access, |
879 |
|
|
d, flags, d->framebuffer); |
880 |
|
|
|
881 |
dpavlin |
24 |
machine_add_tickfunction(machine, dev_fb_tick, d, FB_TICK_SHIFT, 0.0); |
882 |
dpavlin |
4 |
return d; |
883 |
|
|
} |
884 |
|
|
|