1 |
/* |
/* |
2 |
* Copyright (C) 2003-2005 Anders Gavare. All rights reserved. |
* Copyright (C) 2003-2006 Anders Gavare. All rights reserved. |
3 |
* |
* |
4 |
* Redistribution and use in source and binary forms, with or without |
* Redistribution and use in source and binary forms, with or without |
5 |
* modification, are permitted provided that the following conditions are met: |
* modification, are permitted provided that the following conditions are met: |
25 |
* SUCH DAMAGE. |
* SUCH DAMAGE. |
26 |
* |
* |
27 |
* |
* |
28 |
* $Id: dev_fb.c,v 1.90 2005/03/29 09:46:06 debug Exp $ |
* $Id: dev_fb.c,v 1.121 2006/07/08 12:30:02 debug Exp $ |
29 |
* |
* |
30 |
* Generic framebuffer device. |
* Generic framebuffer device. |
31 |
* |
* |
32 |
* DECstation VFB01 monochrome framebuffer, 1024x864 |
* DECstation VFB01 monochrome framebuffer, 1024x864 |
33 |
* DECstation VFB02 8-bit color framebuffer, 1024x864 |
* DECstation VFB02 8-bit color framebuffer, 1024x864 |
34 |
* DECstation Maxine, 1024x768 8-bit color |
* DECstation Maxine, 1024x768 8-bit color |
35 |
* HPCmips framebuffer |
* HPC (mips, arm, ..) framebuffer |
36 |
* Playstation 2 (24-bit color) |
* Playstation 2 (24-bit color) |
37 |
* generic (any resolution, several bit depths possible) |
* Generic (any resolution, several bit depths possible, useful for |
38 |
|
* testmachines) |
39 |
* |
* |
40 |
* |
* |
41 |
* TODO: There is still a bug when redrawing the cursor. The underlying |
* TODO: This should actually be independent of X11, but that |
|
* image is moved 1 pixel (?), or something like that. |
|
|
* |
|
|
* TODO: This should actually be independant of X11, but that |
|
42 |
* might be too hard to do right now. |
* might be too hard to do right now. |
43 |
* |
* |
44 |
* TODO: playstation 2 pixels are stored in another format, actually |
* TODO: playstation 2 pixels are stored in another format, actually |
63 |
#endif |
#endif |
64 |
|
|
65 |
|
|
66 |
#define FB_TICK_SHIFT 18 |
#define FB_TICK_SHIFT 19 |
|
|
|
|
#define LOGO_XSIZE 256 |
|
|
#define LOGO_YSIZE 256 |
|
|
#define LOGO_BOTTOM_MARGIN 60 |
|
|
/* This must be a 256*256 pixels P4 ppm: */ |
|
|
#include "fb_logo.c" |
|
|
unsigned char *fb_logo = fb_logo_ppm + 11; |
|
67 |
|
|
68 |
|
|
69 |
/* #define FB_DEBUG */ |
/* #define FB_DEBUG */ |
105 |
} |
} |
106 |
|
|
107 |
|
|
108 |
|
static void set_title(struct vfb_data *d) |
109 |
|
{ |
110 |
|
snprintf(d->title, sizeof(d->title),"GXemul: %ix%ix%i %s framebuffer", |
111 |
|
d->visible_xsize, d->visible_ysize, d->bit_depth, d->name); |
112 |
|
d->title[sizeof(d->title)-1] = '\0'; |
113 |
|
} |
114 |
|
|
115 |
|
|
116 |
|
/* |
117 |
|
* dev_fb_resize(): |
118 |
|
* |
119 |
|
* Resize a framebuffer window. (This functionality is probably a bit buggy, |
120 |
|
* because I didn't think of including it from the start.) |
121 |
|
* |
122 |
|
* SUPER-IMPORTANT: Anyone who resizes a framebuffer by calling this function |
123 |
|
* must also clear all dyntrans address translations manually, in all cpus |
124 |
|
* which might have access to the framebuffer! |
125 |
|
*/ |
126 |
|
void dev_fb_resize(struct vfb_data *d, int new_xsize, int new_ysize) |
127 |
|
{ |
128 |
|
unsigned char *new_framebuffer; |
129 |
|
int y, new_bytes_per_line; |
130 |
|
size_t size; |
131 |
|
|
132 |
|
if (d == NULL) { |
133 |
|
fatal("dev_fb_resize(): d == NULL\n"); |
134 |
|
return; |
135 |
|
} |
136 |
|
|
137 |
|
if (new_xsize < 10 || new_ysize < 10) { |
138 |
|
fatal("dev_fb_resize(): size too small.\n"); |
139 |
|
exit(1); |
140 |
|
} |
141 |
|
|
142 |
|
new_bytes_per_line = new_xsize * d->bit_depth / 8; |
143 |
|
size = new_ysize * new_bytes_per_line; |
144 |
|
|
145 |
|
new_framebuffer = malloc(size); |
146 |
|
if (new_framebuffer == NULL) { |
147 |
|
fprintf(stderr, "dev_fb_resize(): out of memory\n"); |
148 |
|
exit(1); |
149 |
|
} |
150 |
|
|
151 |
|
/* Copy the old framebuffer to the new: */ |
152 |
|
if (d->framebuffer != NULL) { |
153 |
|
for (y=0; y<new_ysize; y++) { |
154 |
|
size_t fromofs = d->bytes_per_line * y; |
155 |
|
size_t toofs = new_bytes_per_line * y; |
156 |
|
size_t len_to_copy = d->bytes_per_line < |
157 |
|
new_bytes_per_line? d->bytes_per_line |
158 |
|
: new_bytes_per_line; |
159 |
|
memset(new_framebuffer + toofs, 0, new_bytes_per_line); |
160 |
|
if (y < d->x11_ysize) |
161 |
|
memmove(new_framebuffer + toofs, |
162 |
|
d->framebuffer + fromofs, len_to_copy); |
163 |
|
} |
164 |
|
|
165 |
|
free(d->framebuffer); |
166 |
|
} |
167 |
|
|
168 |
|
d->framebuffer = new_framebuffer; |
169 |
|
d->framebuffer_size = size; |
170 |
|
|
171 |
|
if (new_xsize > d->xsize || new_ysize > d->ysize) { |
172 |
|
d->update_x1 = d->update_y1 = 0; |
173 |
|
d->update_x2 = new_xsize - 1; |
174 |
|
d->update_y2 = new_ysize - 1; |
175 |
|
} |
176 |
|
|
177 |
|
d->bytes_per_line = new_bytes_per_line; |
178 |
|
d->xsize = d->visible_xsize = new_xsize; |
179 |
|
d->ysize = d->visible_ysize = new_ysize; |
180 |
|
|
181 |
|
d->x11_xsize = d->xsize / d->vfb_scaledown; |
182 |
|
d->x11_ysize = d->ysize / d->vfb_scaledown; |
183 |
|
|
184 |
|
memory_device_update_data(d->memory, d, d->framebuffer); |
185 |
|
|
186 |
|
set_title(d); |
187 |
|
|
188 |
|
#ifdef WITH_X11 |
189 |
|
if (d->fb_window != NULL) { |
190 |
|
x11_fb_resize(d->fb_window, new_xsize, new_ysize); |
191 |
|
x11_set_standard_properties(d->fb_window, d->title); |
192 |
|
} |
193 |
|
#endif |
194 |
|
} |
195 |
|
|
196 |
|
|
197 |
/* |
/* |
198 |
* dev_fb_setcursor(): |
* dev_fb_setcursor(): |
199 |
*/ |
*/ |
272 |
int x; |
int x; |
273 |
char buf[8192 * 3]; |
char buf[8192 * 3]; |
274 |
if (d->bit_depth == 24) |
if (d->bit_depth == 24) |
275 |
for (x=0; x<linelen; x+=3) { |
for (x=0; x<linelen && x<sizeof(buf); |
276 |
|
x += 3) { |
277 |
buf[x] = fill_r; |
buf[x] = fill_r; |
278 |
buf[x+1] = fill_g; |
buf[x+1] = fill_g; |
279 |
buf[x+2] = fill_b; |
buf[x+2] = fill_b; |
280 |
} |
} |
281 |
else |
else { |
282 |
printf("TODO: fill for non-24-bit" |
fatal("[ fb: TODO: fill for non-24-bit" |
283 |
" modes\n"); |
" modes ]\n"); |
284 |
|
} |
285 |
|
|
286 |
memmove(d->framebuffer + dest_ofs, buf, |
memmove(d->framebuffer + dest_ofs, buf, |
287 |
linelen); |
linelen); |
316 |
|
|
317 |
|
|
318 |
#ifdef WITH_X11 |
#ifdef WITH_X11 |
|
#define macro_put_pixel() { \ |
|
|
/* Combine the color into an X11 long and display it: */ \ |
|
|
/* TODO: construct color in a more portable way: */ \ |
|
|
switch (d->fb_window->x11_screen_depth) { \ |
|
|
case 24: \ |
|
|
if (d->fb_window->fb_ximage->byte_order) \ |
|
|
color = (b << 16) + (g << 8) + r; \ |
|
|
else \ |
|
|
color = (r << 16) + (g << 8) + b; \ |
|
|
break; \ |
|
|
case 16: \ |
|
|
r >>= 3; g >>= 2; b >>= 3; \ |
|
|
if (d->fb_window->fb_ximage->byte_order) { \ |
|
|
/* Big endian 16-bit X server: */ \ |
|
|
static int first = 1; \ |
|
|
if (first) { \ |
|
|
fprintf(stderr, "\n*** Please report to the author whether 16-bit X11 colors are rendered correctly or not!\n\n"); \ |
|
|
first = 0; \ |
|
|
} \ |
|
|
color = (b << 11) + (g << 5) + r; \ |
|
|
} else { \ |
|
|
/* Little endian (eg PC) X servers: */ \ |
|
|
color = (r << 11) + (g << 5) + b; \ |
|
|
} \ |
|
|
break; \ |
|
|
case 15: \ |
|
|
r >>= 3; g >>= 3; b >>= 3; \ |
|
|
if (d->fb_window->fb_ximage->byte_order) { \ |
|
|
/* Big endian 15-bit X server: */ \ |
|
|
static int first = 1; \ |
|
|
if (first) { \ |
|
|
fprintf(stderr, "\n*** Please report to the author whether 15-bit X11 colors are rendered correctly or not!\n\n"); \ |
|
|
first = 0; \ |
|
|
} \ |
|
|
color = (b << 10) + (g << 5) + r; \ |
|
|
} else { \ |
|
|
/* Little endian (eg PC) X servers: */ \ |
|
|
color = (r << 10) + (g << 5) + b; \ |
|
|
} \ |
|
|
break; \ |
|
|
default: \ |
|
|
color = d->fb_window->x11_graycolor[15 * (r + g + b) / (255 * 3)].pixel; \ |
|
|
} \ |
|
|
if (x>=0 && x<d->x11_xsize && y>=0 && y<d->x11_ysize) \ |
|
|
XPutPixel(d->fb_window->fb_ximage, x, y, color); \ |
|
|
} |
|
|
#else |
|
|
/* If not WITH_X11: */ |
|
|
#define macro_put_pixel() { } |
|
|
#endif |
|
319 |
|
|
320 |
|
#define REDRAW redraw_fallback |
321 |
|
#include "fb_include.c" |
322 |
|
#undef REDRAW |
323 |
|
|
324 |
|
#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 |
|
|
340 |
|
#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 |
|
|
358 |
|
#define FB_SCALEDOWN |
359 |
|
|
360 |
|
#define REDRAW redraw_fallback_sd |
361 |
|
#include "fb_include.c" |
362 |
|
#undef REDRAW |
363 |
|
|
364 |
|
#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 |
|
|
380 |
|
#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 |
|
|
398 |
|
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 |
|
|
408 |
/* |
#endif /* WITH_X11 */ |
|
* update_framebuffer(): |
|
|
* |
|
|
* The framebuffer memory has been updated. This function tries to make |
|
|
* sure that the XImage is also updated (1 or more pixels). |
|
|
*/ |
|
|
void update_framebuffer(struct vfb_data *d, int addr, int len) |
|
|
{ |
|
|
int x, y, pixel, npixels; |
|
|
long color_r, color_g, color_b; |
|
|
#ifdef WITH_X11 |
|
|
long color; |
|
|
#endif |
|
|
int scaledown = d->vfb_scaledown; |
|
|
int scaledownXscaledown = 1; |
|
|
|
|
|
if (scaledown == 1) { |
|
|
/* Which framebuffer pixel does addr correspond to? */ |
|
|
pixel = addr * 8 / d->bit_depth; |
|
|
y = pixel / d->xsize; |
|
|
x = pixel % d->xsize; |
|
|
|
|
|
/* How many framebuffer pixels? */ |
|
|
npixels = len * 8 / d->bit_depth; |
|
|
if (npixels == 0) |
|
|
npixels = 1; |
|
|
|
|
|
if (d->bit_depth < 8) { |
|
|
for (pixel=0; pixel<npixels; pixel++) { |
|
|
int fb_addr, c, r, g, b; |
|
|
color_r = color_g = color_b = 0; |
|
|
|
|
|
fb_addr = (y * d->xsize + x) * d->bit_depth; |
|
|
/* fb_addr is now which _bit_ in |
|
|
the framebuffer */ |
|
|
|
|
|
c = d->framebuffer[fb_addr >> 3]; |
|
|
fb_addr &= 7; |
|
|
|
|
|
/* HPCmips is reverse: */ |
|
|
if (d->vfb_type == VFB_HPCMIPS) |
|
|
fb_addr = 8 - d->bit_depth - fb_addr; |
|
|
|
|
|
c = (c >> fb_addr) & ((1<<d->bit_depth) - 1); |
|
|
/* c <<= (8 - d->bit_depth); */ |
|
|
|
|
|
r = d->rgb_palette[c*3 + 0]; |
|
|
g = d->rgb_palette[c*3 + 1]; |
|
|
b = d->rgb_palette[c*3 + 2]; |
|
|
|
|
|
macro_put_pixel(); |
|
|
x++; |
|
|
} |
|
|
} else if (d->bit_depth == 8) { |
|
|
for (pixel=0; pixel<npixels; pixel++) { |
|
|
int fb_addr, c, r, g, b; |
|
|
color_r = color_g = color_b = 0; |
|
|
|
|
|
fb_addr = y * d->xsize + x; |
|
|
/* fb_addr is now which byte in framebuffer */ |
|
|
c = d->framebuffer[fb_addr]; |
|
|
r = d->rgb_palette[c*3 + 0]; |
|
|
g = d->rgb_palette[c*3 + 1]; |
|
|
b = d->rgb_palette[c*3 + 2]; |
|
|
|
|
|
macro_put_pixel(); |
|
|
x++; |
|
|
} |
|
|
} else { /* d->bit_depth > 8 */ |
|
|
for (pixel=0; pixel<npixels; pixel++) { |
|
|
int fb_addr, r, g, b; |
|
|
color_r = color_g = color_b = 0; |
|
|
|
|
|
fb_addr = (y * d->xsize + x) * d->bit_depth; |
|
|
/* fb_addr is now which byte in framebuffer */ |
|
|
|
|
|
/* > 8 bits color. */ |
|
|
fb_addr >>= 3; |
|
|
switch (d->bit_depth) { |
|
|
case 24: |
|
|
r = d->framebuffer[fb_addr]; |
|
|
g = d->framebuffer[fb_addr + 1]; |
|
|
b = d->framebuffer[fb_addr + 2]; |
|
|
break; |
|
|
/* TODO: copy to the scaledown code below */ |
|
|
case 16: |
|
|
if (d->vfb_type == VFB_HPCMIPS) { |
|
|
b = d->framebuffer[fb_addr] + |
|
|
(d->framebuffer[fb_addr+1] << 8); |
|
|
|
|
|
if (d->color32k) { |
|
|
r = b >> 11; |
|
|
g = b >> 5; |
|
|
r = r & 31; |
|
|
g = (g & 31) * 2; |
|
|
b = b & 31; |
|
|
} else { |
|
|
r = (b >> 11) & 0x1f; |
|
|
g = (b >> 5) & 0x3f; |
|
|
b = b & 0x1f; |
|
|
} |
|
|
} else { |
|
|
r = d->framebuffer[fb_addr] >> 3; |
|
|
g = (d->framebuffer[fb_addr] << 5) + |
|
|
(d->framebuffer[fb_addr + 1] >> 5); |
|
|
b = d->framebuffer[fb_addr + 1] & 0x1f; |
|
|
} |
|
|
|
|
|
r *= 8; |
|
|
g *= 4; |
|
|
b *= 8; |
|
|
break; |
|
|
default: |
|
|
r = g = b = random() & 255; |
|
|
} |
|
|
|
|
|
macro_put_pixel(); |
|
|
x++; |
|
|
} |
|
|
} |
|
|
|
|
|
return; |
|
|
} |
|
|
|
|
|
/* scaledown != 1: */ |
|
|
|
|
|
scaledown = d->vfb_scaledown; |
|
|
scaledownXscaledown = scaledown * scaledown; |
|
|
|
|
|
/* Which framebuffer pixel does addr correspond to? */ |
|
|
pixel = addr * 8 / d->bit_depth; |
|
|
y = pixel / d->xsize; |
|
|
x = pixel % d->xsize; |
|
|
|
|
|
/* How many framebuffer pixels? */ |
|
|
npixels = len * 8 / d->bit_depth; |
|
|
|
|
|
/* Which x11 pixel? */ |
|
|
x /= scaledown; |
|
|
y /= scaledown; |
|
|
|
|
|
/* How many x11 pixels: */ |
|
|
npixels /= scaledown; |
|
|
if (npixels == 0) |
|
|
npixels = 1; |
|
|
|
|
|
if (d->bit_depth < 8) { |
|
|
for (pixel=0; pixel<npixels; pixel++) { |
|
|
int subx, suby, r, g, b; |
|
|
color_r = color_g = color_b = 0; |
|
|
for (suby=0; suby<scaledown; suby++) |
|
|
for (subx=0; subx<scaledown; subx++) { |
|
|
int fb_x, fb_y, fb_addr, c; |
|
|
|
|
|
fb_x = x * scaledown + subx; |
|
|
fb_y = y * scaledown + suby; |
|
|
fb_addr = fb_y * d->xsize + fb_x; |
|
|
fb_addr = fb_addr * d->bit_depth; |
|
|
/* fb_addr is now which _bit_ in |
|
|
the framebuffer */ |
|
|
|
|
|
c = d->framebuffer[fb_addr >> 3]; |
|
|
fb_addr &= 7; |
|
|
|
|
|
/* HPCmips is reverse: */ |
|
|
if (d->vfb_type == VFB_HPCMIPS) |
|
|
fb_addr = 8 - d->bit_depth - fb_addr; |
|
|
|
|
|
c = (c >> fb_addr) & ((1<<d->bit_depth) - 1); |
|
|
/* c <<= (8 - d->bit_depth); */ |
|
|
|
|
|
r = d->rgb_palette[c*3 + 0]; |
|
|
g = d->rgb_palette[c*3 + 1]; |
|
|
b = d->rgb_palette[c*3 + 2]; |
|
|
|
|
|
color_r += r; |
|
|
color_g += g; |
|
|
color_b += b; |
|
|
} |
|
|
|
|
|
r = color_r / scaledownXscaledown; |
|
|
g = color_g / scaledownXscaledown; |
|
|
b = color_b / scaledownXscaledown; |
|
|
macro_put_pixel(); |
|
|
x++; |
|
|
} |
|
|
} else if (d->bit_depth == 8) { |
|
|
for (pixel=0; pixel<npixels; pixel++) { |
|
|
int subx, suby, r, g, b; |
|
|
color_r = color_g = color_b = 0; |
|
|
for (suby=0; suby<scaledown; suby++) |
|
|
for (subx=0; subx<scaledown; subx++) { |
|
|
int fb_x, fb_y, fb_addr, c; |
|
|
|
|
|
fb_x = x * scaledown + subx; |
|
|
fb_y = y * scaledown + suby; |
|
|
fb_addr = fb_y * d->xsize + fb_x; |
|
|
/* fb_addr is which _byte_ in framebuffer */ |
|
|
c = d->framebuffer[fb_addr] * 3; |
|
|
r = d->rgb_palette[c + 0]; |
|
|
g = d->rgb_palette[c + 1]; |
|
|
b = d->rgb_palette[c + 2]; |
|
|
color_r += r; |
|
|
color_g += g; |
|
|
color_b += b; |
|
|
} |
|
|
|
|
|
r = color_r / scaledownXscaledown; |
|
|
g = color_g / scaledownXscaledown; |
|
|
b = color_b / scaledownXscaledown; |
|
|
macro_put_pixel(); |
|
|
x++; |
|
|
} |
|
|
} else { |
|
|
/* Generic > 8 bit bit-depth: */ |
|
|
for (pixel=0; pixel<npixels; pixel++) { |
|
|
int subx, suby, r, g, b; |
|
|
color_r = color_g = color_b = 0; |
|
|
for (suby=0; suby<scaledown; suby++) |
|
|
for (subx=0; subx<scaledown; subx++) { |
|
|
int fb_x, fb_y, fb_addr; |
|
|
|
|
|
fb_x = x * scaledown + subx; |
|
|
fb_y = y * scaledown + suby; |
|
|
fb_addr = fb_y * d->xsize + fb_x; |
|
|
fb_addr = (fb_addr * d->bit_depth) >> 3; |
|
|
/* fb_addr is which _byte_ in framebuffer */ |
|
|
|
|
|
/* > 8 bits color. */ |
|
|
switch (d->bit_depth) { |
|
|
case 24: |
|
|
r = d->framebuffer[fb_addr]; |
|
|
g = d->framebuffer[fb_addr + 1]; |
|
|
b = d->framebuffer[fb_addr + 2]; |
|
|
break; |
|
|
default: |
|
|
r = g = b = random() & 255; |
|
|
} |
|
|
color_r += r; |
|
|
color_g += g; |
|
|
color_b += b; |
|
|
} |
|
|
r = color_r / scaledownXscaledown; |
|
|
g = color_g / scaledownXscaledown; |
|
|
b = color_b / scaledownXscaledown; |
|
|
macro_put_pixel(); |
|
|
x++; |
|
|
} |
|
|
} |
|
|
} |
|
409 |
|
|
410 |
|
|
411 |
/* |
/* |
423 |
if (!cpu->machine->use_x11) |
if (!cpu->machine->use_x11) |
424 |
return; |
return; |
425 |
|
|
|
#ifdef BINTRANS |
|
426 |
do { |
do { |
427 |
uint64_t low = -1, high; |
uint64_t high, low = (uint64_t)(int64_t) -1; |
428 |
int x, y; |
int x, y; |
429 |
|
|
430 |
memory_device_bintrans_access(cpu, cpu->mem, |
memory_device_dyntrans_access(cpu, cpu->mem, |
431 |
extra, &low, &high); |
extra, &low, &high); |
432 |
if ((int64_t)low == -1) |
if ((int64_t)low == -1) |
433 |
break; |
break; |
488 |
d->update_x2 = d->xsize-1; |
d->update_x2 = d->xsize-1; |
489 |
} |
} |
490 |
} while (0); |
} while (0); |
|
#endif |
|
491 |
|
|
492 |
#ifdef WITH_X11 |
#ifdef WITH_X11 |
493 |
/* Do we need to redraw the cursor? */ |
/* Do we need to redraw the cursor? */ |
499 |
need_to_redraw_cursor = 1; |
need_to_redraw_cursor = 1; |
500 |
|
|
501 |
if (d->update_x2 != -1) { |
if (d->update_x2 != -1) { |
502 |
if ( (d->update_x1 >= d->fb_window->OLD_cursor_x && |
if (((d->update_x1 >= d->fb_window->OLD_cursor_x && |
503 |
d->update_x1 < (d->fb_window->OLD_cursor_x + d->fb_window->OLD_cursor_xsize)) || |
d->update_x1 < (d->fb_window->OLD_cursor_x + |
504 |
|
d->fb_window->OLD_cursor_xsize)) || |
505 |
(d->update_x2 >= d->fb_window->OLD_cursor_x && |
(d->update_x2 >= d->fb_window->OLD_cursor_x && |
506 |
d->update_x2 < (d->fb_window->OLD_cursor_x + d->fb_window->OLD_cursor_xsize)) || |
d->update_x2 < (d->fb_window->OLD_cursor_x + |
507 |
|
d->fb_window->OLD_cursor_xsize)) || |
508 |
(d->update_x1 < d->fb_window->OLD_cursor_x && |
(d->update_x1 < d->fb_window->OLD_cursor_x && |
509 |
d->update_x2 >= (d->fb_window->OLD_cursor_x + d->fb_window->OLD_cursor_xsize)) ) { |
d->update_x2 >= (d->fb_window->OLD_cursor_x + |
510 |
if ( (d->update_y1 >= d->fb_window->OLD_cursor_y && |
d->fb_window->OLD_cursor_xsize)) ) && |
511 |
d->update_y1 < (d->fb_window->OLD_cursor_y + d->fb_window->OLD_cursor_ysize)) || |
( (d->update_y1 >= d->fb_window->OLD_cursor_y && |
512 |
(d->update_y2 >= d->fb_window->OLD_cursor_y && |
d->update_y1 < (d->fb_window->OLD_cursor_y + |
513 |
d->update_y2 < (d->fb_window->OLD_cursor_y + d->fb_window->OLD_cursor_ysize)) || |
d->fb_window->OLD_cursor_ysize)) || |
514 |
(d->update_y1 < d->fb_window->OLD_cursor_y && |
(d->update_y2 >= d->fb_window->OLD_cursor_y && |
515 |
d->update_y2 >= (d->fb_window->OLD_cursor_y + d->fb_window->OLD_cursor_ysize)) ) |
d->update_y2 < (d->fb_window->OLD_cursor_y + |
516 |
need_to_redraw_cursor = 1; |
d->fb_window->OLD_cursor_ysize)) || |
517 |
} |
(d->update_y1 < d->fb_window->OLD_cursor_y && |
518 |
|
d->update_y2 >= (d->fb_window->OLD_cursor_y + |
519 |
|
d->fb_window->OLD_cursor_ysize)) ) ) |
520 |
|
need_to_redraw_cursor = 1; |
521 |
} |
} |
522 |
|
|
523 |
if (need_to_redraw_cursor) { |
if (need_to_redraw_cursor) { |
531 |
d->fb_window->OLD_cursor_x/d->vfb_scaledown, |
d->fb_window->OLD_cursor_x/d->vfb_scaledown, |
532 |
d->fb_window->OLD_cursor_y/d->vfb_scaledown, |
d->fb_window->OLD_cursor_y/d->vfb_scaledown, |
533 |
d->fb_window->OLD_cursor_xsize/d->vfb_scaledown + 1, |
d->fb_window->OLD_cursor_xsize/d->vfb_scaledown + 1, |
534 |
d->fb_window->OLD_cursor_ysize/d->vfb_scaledown + 1); |
d->fb_window->OLD_cursor_ysize/d->vfb_scaledown +1); |
535 |
} |
} |
536 |
} |
} |
537 |
#endif |
#endif |
538 |
|
|
539 |
if (d->update_x2 != -1) { |
if (d->update_x2 != -1) { |
540 |
int y, addr, addr2, q = d->vfb_scaledown; |
#ifdef WITH_X11 |
541 |
|
int y; |
542 |
|
#endif |
543 |
|
int addr, addr2, q = d->vfb_scaledown; |
544 |
|
|
545 |
if (d->update_x1 >= d->visible_xsize) d->update_x1 = d->visible_xsize - 1; |
if (d->update_x1 >= d->visible_xsize) |
546 |
if (d->update_x2 >= d->visible_xsize) d->update_x2 = d->visible_xsize - 1; |
d->update_x1 = d->visible_xsize - 1; |
547 |
if (d->update_y1 >= d->visible_ysize) d->update_y1 = d->visible_ysize - 1; |
if (d->update_x2 >= d->visible_xsize) |
548 |
if (d->update_y2 >= d->visible_ysize) d->update_y2 = d->visible_ysize - 1; |
d->update_x2 = d->visible_xsize - 1; |
549 |
|
if (d->update_y1 >= d->visible_ysize) |
550 |
|
d->update_y1 = d->visible_ysize - 1; |
551 |
|
if (d->update_y2 >= d->visible_ysize) |
552 |
|
d->update_y2 = d->visible_ysize - 1; |
553 |
|
|
554 |
/* Without these, we might miss the right most / bottom pixel: */ |
/* Without these, we might miss the rightmost/bottom pixel: */ |
555 |
d->update_x2 += (q - 1); |
d->update_x2 += (q - 1); |
556 |
d->update_y2 += (q - 1); |
d->update_y2 += (q - 1); |
557 |
|
|
560 |
d->update_y1 = d->update_y1 / q * q; |
d->update_y1 = d->update_y1 / q * q; |
561 |
d->update_y2 = d->update_y2 / q * q; |
d->update_y2 = d->update_y2 / q * q; |
562 |
|
|
563 |
addr = d->update_y1 * d->bytes_per_line + d->update_x1 * d->bit_depth / 8; |
addr = d->update_y1 * d->bytes_per_line + |
564 |
addr2 = d->update_y1 * d->bytes_per_line + d->update_x2 * d->bit_depth / 8; |
d->update_x1 * d->bit_depth / 8; |
565 |
|
addr2 = d->update_y1 * d->bytes_per_line + |
566 |
|
d->update_x2 * d->bit_depth / 8; |
567 |
|
|
568 |
|
#ifdef WITH_X11 |
569 |
for (y=d->update_y1; y<=d->update_y2; y+=q) { |
for (y=d->update_y1; y<=d->update_y2; y+=q) { |
570 |
update_framebuffer(d, addr, addr2 - addr); |
d->redraw_func(d, addr, addr2 - addr); |
571 |
addr += d->bytes_per_line * q; |
addr += d->bytes_per_line * q; |
572 |
addr2 += d->bytes_per_line * q; |
addr2 += d->bytes_per_line * q; |
573 |
} |
} |
574 |
|
|
575 |
#ifdef WITH_X11 |
XPutImage(d->fb_window->x11_display, d->fb_window-> |
576 |
XPutImage(d->fb_window->x11_display, d->fb_window->x11_fb_window, d->fb_window->x11_fb_gc, d->fb_window->fb_ximage, |
x11_fb_window, d->fb_window->x11_fb_gc, d->fb_window-> |
577 |
d->update_x1/d->vfb_scaledown, d->update_y1/d->vfb_scaledown, |
fb_ximage, d->update_x1/d->vfb_scaledown, d->update_y1/ |
578 |
d->update_x1/d->vfb_scaledown, d->update_y1/d->vfb_scaledown, |
d->vfb_scaledown, d->update_x1/d->vfb_scaledown, |
579 |
|
d->update_y1/d->vfb_scaledown, |
580 |
(d->update_x2 - d->update_x1)/d->vfb_scaledown + 1, |
(d->update_x2 - d->update_x1)/d->vfb_scaledown + 1, |
581 |
(d->update_y2 - d->update_y1)/d->vfb_scaledown + 1); |
(d->update_y2 - d->update_y1)/d->vfb_scaledown + 1); |
582 |
|
|
591 |
if (need_to_redraw_cursor) { |
if (need_to_redraw_cursor) { |
592 |
/* Paint new cursor: */ |
/* Paint new cursor: */ |
593 |
if (d->fb_window->cursor_on) { |
if (d->fb_window->cursor_on) { |
594 |
x11_redraw_cursor(cpu->machine, d->fb_window->fb_number); |
x11_redraw_cursor(cpu->machine, |
595 |
|
d->fb_window->fb_number); |
596 |
d->fb_window->OLD_cursor_on = d->fb_window->cursor_on; |
d->fb_window->OLD_cursor_on = d->fb_window->cursor_on; |
597 |
d->fb_window->OLD_cursor_x = d->fb_window->cursor_x; |
d->fb_window->OLD_cursor_x = d->fb_window->cursor_x; |
598 |
d->fb_window->OLD_cursor_y = d->fb_window->cursor_y; |
d->fb_window->OLD_cursor_y = d->fb_window->cursor_y; |
599 |
d->fb_window->OLD_cursor_xsize = d->fb_window->cursor_xsize; |
d->fb_window->OLD_cursor_xsize = d->fb_window-> |
600 |
d->fb_window->OLD_cursor_ysize = d->fb_window->cursor_ysize; |
cursor_xsize; |
601 |
|
d->fb_window->OLD_cursor_ysize = d->fb_window-> |
602 |
|
cursor_ysize; |
603 |
|
need_to_flush_x11 = 1; |
604 |
} |
} |
605 |
} |
} |
606 |
#endif |
#endif |
615 |
/* |
/* |
616 |
* dev_fb_access(): |
* dev_fb_access(): |
617 |
*/ |
*/ |
618 |
int dev_fb_access(struct cpu *cpu, struct memory *mem, |
DEVICE_ACCESS(fb) |
|
uint64_t relative_addr, unsigned char *data, size_t len, |
|
|
int writeflag, void *extra) |
|
619 |
{ |
{ |
620 |
struct vfb_data *d = extra; |
struct vfb_data *d = extra; |
621 |
int i; |
size_t i; |
622 |
|
|
623 |
#ifdef FB_DEBUG |
#ifdef FB_DEBUG |
624 |
if (writeflag == MEM_WRITE) { if (data[0]) { |
if (writeflag == MEM_WRITE) { if (data[0]) { |
636 |
} |
} |
637 |
#endif |
#endif |
638 |
|
|
639 |
|
if (relative_addr >= d->framebuffer_size) |
640 |
|
return 0; |
641 |
|
|
642 |
/* See if a write actually modifies the framebuffer contents: */ |
/* See if a write actually modifies the framebuffer contents: */ |
643 |
if (writeflag == MEM_WRITE) { |
if (writeflag == MEM_WRITE) { |
644 |
for (i=0; i<len; i++) { |
for (i=0; i<len; i++) { |
647 |
|
|
648 |
/* If all bytes are equal to what is already stored |
/* If all bytes are equal to what is already stored |
649 |
in the framebuffer, then simply return: */ |
in the framebuffer, then simply return: */ |
650 |
if (i==len-1) |
if (i == len-1) |
651 |
return 1; |
return 1; |
652 |
} |
} |
653 |
} |
} |
706 |
if (writeflag == MEM_WRITE) { |
if (writeflag == MEM_WRITE) { |
707 |
if (len > 8) |
if (len > 8) |
708 |
memcpy(d->framebuffer + relative_addr, data, len); |
memcpy(d->framebuffer + relative_addr, data, len); |
709 |
else |
else { |
710 |
for (i=0; i<len; i++) |
for (i=0; i<len; i++) |
711 |
d->framebuffer[relative_addr + i] = data[i]; |
d->framebuffer[relative_addr + i] = data[i]; |
712 |
|
} |
713 |
} else { |
} else { |
714 |
if (len > 8) |
if (len > 8) |
715 |
memcpy(data, d->framebuffer + relative_addr, len); |
memcpy(data, d->framebuffer + relative_addr, len); |
716 |
else |
else { |
717 |
for (i=0; i<len; i++) |
for (i=0; i<len; i++) |
718 |
data[i] = d->framebuffer[relative_addr + i]; |
data[i] = d->framebuffer[relative_addr + i]; |
719 |
|
} |
720 |
} |
} |
721 |
|
|
722 |
return 1; |
return 1; |
726 |
/* |
/* |
727 |
* dev_fb_init(): |
* dev_fb_init(): |
728 |
* |
* |
729 |
* xsize and ysize are ignored if vfb_type is VFB_DEC_VFB01 or 02. |
* This function is big and ugly, but the point is to initialize a framebuffer |
730 |
|
* device. :-) |
731 |
|
* |
732 |
|
* visible_xsize and visible_ysize are the sizes of the visible display area. |
733 |
|
* xsize and ysize tell how much memory is actually allocated (for example |
734 |
|
* visible_xsize could be 640, but xsize could be 1024, for better alignment). |
735 |
|
* |
736 |
|
* vfb_type is useful for selecting special features. |
737 |
|
* |
738 |
|
* type = VFB_GENERIC is the most useful type, especially when bit_depth = 24. |
739 |
|
* |
740 |
|
* VFB_DEC_VFB01, _VFB02, and VFB_DEC_MAXINE are DECstation specific. |
741 |
|
* |
742 |
|
* If type is VFB_HPC, then color encoding differs from the generic case. |
743 |
|
* |
744 |
|
* If bit_depth = -15 (note the minus sign), then a special hack is used for |
745 |
|
* the Playstation Portable's 5-bit R, 5-bit G, 5-bit B. |
746 |
*/ |
*/ |
747 |
struct vfb_data *dev_fb_init(struct machine *machine, struct memory *mem, |
struct vfb_data *dev_fb_init(struct machine *machine, struct memory *mem, |
748 |
uint64_t baseaddr, int vfb_type, int visible_xsize, int visible_ysize, |
uint64_t baseaddr, int vfb_type, int visible_xsize, int visible_ysize, |
749 |
int xsize, int ysize, int bit_depth, char *name, int logo) |
int xsize, int ysize, int bit_depth, char *name) |
750 |
{ |
{ |
751 |
struct vfb_data *d; |
struct vfb_data *d; |
752 |
size_t size; |
size_t size, nlen; |
|
int x, y; |
|
|
char title[400]; |
|
|
char *name2; |
|
753 |
int flags; |
int flags; |
754 |
|
int reverse_start = 0; |
755 |
|
char *name2; |
756 |
|
|
757 |
d = malloc(sizeof(struct vfb_data)); |
d = malloc(sizeof(struct vfb_data)); |
758 |
if (d == NULL) { |
if (d == NULL) { |
761 |
} |
} |
762 |
memset(d, 0, sizeof(struct vfb_data)); |
memset(d, 0, sizeof(struct vfb_data)); |
763 |
|
|
764 |
|
if (vfb_type & VFB_REVERSE_START) { |
765 |
|
vfb_type &= ~VFB_REVERSE_START; |
766 |
|
reverse_start = 1; |
767 |
|
} |
768 |
|
|
769 |
|
d->memory = mem; |
770 |
d->vfb_type = vfb_type; |
d->vfb_type = vfb_type; |
771 |
|
|
772 |
/* Defaults: */ |
/* Defaults: */ |
778 |
if (bit_depth == 15) { |
if (bit_depth == 15) { |
779 |
d->color32k = 1; |
d->color32k = 1; |
780 |
bit_depth = d->bit_depth = 16; |
bit_depth = d->bit_depth = 16; |
781 |
|
} else if (bit_depth == -15) { |
782 |
|
d->psp_15bit = 1; |
783 |
|
bit_depth = d->bit_depth = 16; |
784 |
} |
} |
785 |
|
|
786 |
/* Specific types: */ |
/* Specific types: */ |
809 |
d->ysize = ysize; d->visible_ysize = d->ysize; |
d->ysize = ysize; d->visible_ysize = d->ysize; |
810 |
d->bit_depth = 24; |
d->bit_depth = 24; |
811 |
break; |
break; |
|
default: |
|
|
; |
|
812 |
} |
} |
813 |
|
|
814 |
if (d->bit_depth == 2 || d->bit_depth == 4) |
if (d->bit_depth == 2 || d->bit_depth == 4) |
829 |
|
|
830 |
/* Clear the framebuffer (all black pixels): */ |
/* Clear the framebuffer (all black pixels): */ |
831 |
d->framebuffer_size = size; |
d->framebuffer_size = size; |
832 |
memset(d->framebuffer, 0, size); |
memset(d->framebuffer, reverse_start? 255 : 0, size); |
833 |
|
|
834 |
d->x11_xsize = d->visible_xsize / d->vfb_scaledown; |
d->x11_xsize = d->visible_xsize / d->vfb_scaledown; |
835 |
d->x11_ysize = d->visible_ysize / d->vfb_scaledown; |
d->x11_ysize = d->visible_ysize / d->vfb_scaledown; |
836 |
|
|
837 |
d->update_x1 = d->update_y1 = 99999; |
/* Only "update" from the start if we need to fill with white. */ |
838 |
d->update_x2 = d->update_y2 = -1; |
/* (The Ximage will be black from the start anyway.) */ |
839 |
|
if (reverse_start) { |
840 |
|
d->update_x1 = d->update_y1 = 0; |
841 |
/* A nice bootup logo: */ |
d->update_x2 = d->xsize - 1; |
842 |
if (logo) { |
d->update_y2 = d->ysize - 1; |
843 |
int logo_bottom_margin = LOGO_BOTTOM_MARGIN; |
} else { |
844 |
|
d->update_x1 = d->update_y1 = 99999; |
845 |
d->update_x1 = 0; |
d->update_x2 = d->update_y2 = -1; |
|
d->update_x2 = LOGO_XSIZE-1; |
|
|
d->update_y1 = d->visible_ysize-LOGO_YSIZE-logo_bottom_margin; |
|
|
d->update_y2 = d->visible_ysize-logo_bottom_margin; |
|
|
for (y=0; y<LOGO_YSIZE; y++) |
|
|
for (x=0; x<LOGO_XSIZE; x++) { |
|
|
int s, a = ((y + d->visible_ysize - LOGO_YSIZE |
|
|
- logo_bottom_margin)*d->xsize + x) |
|
|
* d->bit_depth / 8; |
|
|
int b = fb_logo[(y*LOGO_XSIZE+x) / 8] & |
|
|
(128 >> (x&7)); |
|
|
for (s=0; s<d->bit_depth / 8; s++) |
|
|
d->framebuffer[a+s] = b? 0 : 255; |
|
|
} |
|
846 |
} |
} |
847 |
|
|
848 |
snprintf(title, sizeof(title), "GXemul: %ix%ix%i %s framebuffer", |
d->name = strdup(name); |
849 |
d->visible_xsize, d->visible_ysize, d->bit_depth, name); |
set_title(d); |
|
title[sizeof(title)-1] = '\0'; |
|
850 |
|
|
851 |
#ifdef WITH_X11 |
#ifdef WITH_X11 |
852 |
if (machine->use_x11) |
if (machine->use_x11) { |
853 |
|
int i = 0; |
854 |
d->fb_window = x11_fb_init(d->x11_xsize, d->x11_ysize, |
d->fb_window = x11_fb_init(d->x11_xsize, d->x11_ysize, |
855 |
title, machine->x11_scaledown, machine); |
d->title, machine->x11_scaledown, machine); |
856 |
else |
switch (d->fb_window->x11_screen_depth) { |
857 |
|
case 15: i = 2; break; |
858 |
|
case 16: i = 4; break; |
859 |
|
case 24: i = 6; break; |
860 |
|
} |
861 |
|
if (d->fb_window->fb_ximage->byte_order) |
862 |
|
i ++; |
863 |
|
if (d->vfb_scaledown > 1) |
864 |
|
i += 8; |
865 |
|
d->redraw_func = redraw[i]; |
866 |
|
} else |
867 |
#endif |
#endif |
868 |
d->fb_window = NULL; |
d->fb_window = NULL; |
869 |
|
|
870 |
name2 = malloc(strlen(name) + 10); |
nlen = strlen(name) + 10; |
871 |
|
name2 = malloc(nlen); |
872 |
if (name2 == NULL) { |
if (name2 == NULL) { |
873 |
fprintf(stderr, "out of memory in dev_fb_init()\n"); |
fprintf(stderr, "out of memory in dev_fb_init()\n"); |
874 |
exit(1); |
exit(1); |
875 |
} |
} |
876 |
sprintf(name2, "fb [%s]", name); |
snprintf(name2, nlen, "fb [%s]", name); |
877 |
|
|
878 |
flags = MEM_DEFAULT; |
flags = DM_DEFAULT; |
879 |
if ((baseaddr & 0xfff) == 0) |
if ((baseaddr & 0xfff) == 0) |
880 |
flags = MEM_BINTRANS_OK | MEM_BINTRANS_WRITE_OK; |
flags = DM_DYNTRANS_OK | DM_DYNTRANS_WRITE_OK; |
881 |
|
|
882 |
|
flags |= DM_READS_HAVE_NO_SIDE_EFFECTS; |
883 |
|
|
884 |
memory_device_register(mem, name2, baseaddr, size, dev_fb_access, |
memory_device_register(mem, name2, baseaddr, size, dev_fb_access, |
885 |
d, flags, d->framebuffer); |
d, flags, d->framebuffer); |
886 |
|
|
887 |
machine_add_tickfunction(machine, dev_fb_tick, d, FB_TICK_SHIFT); |
machine_add_tickfunction(machine, dev_fb_tick, d, FB_TICK_SHIFT, 0.0); |
888 |
return d; |
return d; |
889 |
} |
} |
890 |
|
|