25 |
* SUCH DAMAGE. |
* SUCH DAMAGE. |
26 |
* |
* |
27 |
* |
* |
28 |
* $Id: dev_fb.c,v 1.116 2006/02/05 10:26:36 debug Exp $ |
* $Id: dev_fb.c,v 1.127 2006/10/22 04:20:53 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 |
|
* HPC (mips, arm, ..) framebuffer |
|
35 |
* Playstation 2 (24-bit color) |
* Playstation 2 (24-bit color) |
36 |
* generic (any resolution, several bit depths possible) |
* Generic (any resolution, several bit depths possible, useful for |
37 |
|
* testmachines) |
38 |
* |
* |
39 |
* |
* |
40 |
* TODO: This should actually be independent of X11, but that |
* TODO: This should actually be independent of X11, but that |
62 |
#endif |
#endif |
63 |
|
|
64 |
|
|
65 |
#define FB_TICK_SHIFT 18 |
#define FB_TICK_SHIFT 19 |
66 |
|
|
67 |
|
|
68 |
/* #define FB_DEBUG */ |
/* #define FB_DEBUG */ |
104 |
} |
} |
105 |
|
|
106 |
|
|
107 |
|
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 |
/* |
/* |
116 |
* dev_fb_resize(): |
* dev_fb_resize(): |
117 |
* |
* |
118 |
* Resize a framebuffer window. (This functionality is probably a bit buggy, |
* Resize a framebuffer window. (This functionality is probably a bit buggy, |
119 |
* because I didn't think of including it from the start.) |
* because I didn't think of including it from the start.) |
120 |
|
* |
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 |
*/ |
*/ |
125 |
void dev_fb_resize(struct vfb_data *d, int new_xsize, int new_ysize) |
void dev_fb_resize(struct vfb_data *d, int new_xsize, int new_ysize) |
126 |
{ |
{ |
133 |
return; |
return; |
134 |
} |
} |
135 |
|
|
136 |
|
if (new_xsize < 10 || new_ysize < 10) { |
137 |
|
fatal("dev_fb_resize(): size too small.\n"); |
138 |
|
exit(1); |
139 |
|
} |
140 |
|
|
141 |
new_bytes_per_line = new_xsize * d->bit_depth / 8; |
new_bytes_per_line = new_xsize * d->bit_depth / 8; |
142 |
size = new_ysize * new_bytes_per_line; |
size = new_ysize * new_bytes_per_line; |
143 |
|
|
180 |
d->x11_xsize = d->xsize / d->vfb_scaledown; |
d->x11_xsize = d->xsize / d->vfb_scaledown; |
181 |
d->x11_ysize = d->ysize / d->vfb_scaledown; |
d->x11_ysize = d->ysize / d->vfb_scaledown; |
182 |
|
|
183 |
|
memory_device_update_data(d->memory, d, d->framebuffer); |
184 |
|
|
185 |
|
set_title(d); |
186 |
|
|
187 |
#ifdef WITH_X11 |
#ifdef WITH_X11 |
188 |
if (d->fb_window != NULL) |
if (d->fb_window != NULL) { |
189 |
x11_fb_resize(d->fb_window, new_xsize, new_ysize); |
x11_fb_resize(d->fb_window, new_xsize, new_ysize); |
190 |
|
x11_set_standard_properties(d->fb_window, d->title); |
191 |
|
} |
192 |
#endif |
#endif |
193 |
} |
} |
194 |
|
|
218 |
} |
} |
219 |
#endif |
#endif |
220 |
|
|
|
if (d->fb_window != NULL) |
|
|
console_set_framebuffer_mouse(cursor_x, cursor_y, |
|
|
d->fb_window->fb_number); |
|
|
|
|
221 |
/* debug("dev_fb_setcursor(%i,%i, size %i,%i, on=%i)\n", |
/* debug("dev_fb_setcursor(%i,%i, size %i,%i, on=%i)\n", |
222 |
cursor_x, cursor_y, cursor_xsize, cursor_ysize, on); */ |
cursor_x, cursor_y, cursor_xsize, cursor_ysize, on); */ |
223 |
} |
} |
230 |
* block copy/fill. |
* block copy/fill. |
231 |
* |
* |
232 |
* If fillflag is non-zero, then fill_[rgb] should contain the color |
* If fillflag is non-zero, then fill_[rgb] should contain the color |
233 |
* with which to fill. |
* with which to fill. (In 8-bit mode, only fill_r is used.) |
234 |
* |
* |
235 |
* If fillflag is zero, copy mode is used, and from_[xy] should contain |
* If fillflag is zero, copy mode is used, and from_[xy] should contain |
236 |
* the offset on the framebuffer where we should copy from. |
* the offset on the framebuffer where we should copy from. |
241 |
int fill_g, int fill_b, int x1, int y1, int x2, int y2, |
int fill_g, int fill_b, int x1, int y1, int x2, int y2, |
242 |
int from_x, int from_y) |
int from_x, int from_y) |
243 |
{ |
{ |
244 |
int y; |
int x, y; |
245 |
long from_ofs, dest_ofs, linelen; |
long from_ofs, dest_ofs, linelen; |
246 |
|
|
247 |
if (fillflag) |
if (fillflag) |
264 |
if (fillflag) { |
if (fillflag) { |
265 |
for (y=y1; y<=y2; y++) { |
for (y=y1; y<=y2; y++) { |
266 |
if (y>=0 && y<d->ysize) { |
if (y>=0 && y<d->ysize) { |
267 |
int x; |
unsigned char *buf = |
268 |
char buf[8192 * 3]; |
d->framebuffer + dest_ofs; |
269 |
if (d->bit_depth == 24) |
|
270 |
|
if (d->bit_depth == 24) { |
271 |
for (x=0; x<linelen && x<sizeof(buf); |
for (x=0; x<linelen && x<sizeof(buf); |
272 |
x += 3) { |
x += 3) { |
273 |
buf[x] = fill_r; |
buf[x] = fill_r; |
274 |
buf[x+1] = fill_g; |
buf[x+1] = fill_g; |
275 |
buf[x+2] = fill_b; |
buf[x+2] = fill_b; |
276 |
} |
} |
277 |
else { |
} else if (d->bit_depth == 8) { |
278 |
fatal("[ fb: TODO: fill for non-24-bit" |
memset(buf, fill_r, linelen); |
279 |
" modes ]\n"); |
} else { |
280 |
|
fatal("Unimplemented bit-depth (%i)" |
281 |
|
" for fb fill\n", d->bit_depth); |
282 |
|
exit(1); |
283 |
} |
} |
|
|
|
|
memmove(d->framebuffer + dest_ofs, buf, |
|
|
linelen); |
|
284 |
} |
} |
285 |
|
|
286 |
dest_ofs += d->bytes_per_line; |
dest_ofs += d->bytes_per_line; |
288 |
} else { |
} else { |
289 |
from_ofs = d->bytes_per_line * from_y + |
from_ofs = d->bytes_per_line * from_y + |
290 |
(d->bit_depth/8) * from_x; |
(d->bit_depth/8) * from_x; |
|
|
|
291 |
for (y=y1; y<=y2; y++) { |
for (y=y1; y<=y2; y++) { |
292 |
if (y>=0 && y<d->ysize) |
if (y >= 0 && y < d->ysize) { |
293 |
memmove(d->framebuffer + dest_ofs, |
if (from_y >= 0 && from_y < d->ysize) |
294 |
d->framebuffer + from_ofs, linelen); |
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 |
from_ofs += d->bytes_per_line; |
from_ofs += d->bytes_per_line; |
302 |
dest_ofs += d->bytes_per_line; |
dest_ofs += d->bytes_per_line; |
303 |
} |
} |
408 |
#endif /* WITH_X11 */ |
#endif /* WITH_X11 */ |
409 |
|
|
410 |
|
|
411 |
/* |
DEVICE_TICK(fb) |
|
* dev_fb_tick(): |
|
|
* |
|
|
*/ |
|
|
void dev_fb_tick(struct cpu *cpu, void *extra) |
|
412 |
{ |
{ |
413 |
struct vfb_data *d = extra; |
struct vfb_data *d = extra; |
414 |
#ifdef WITH_X11 |
#ifdef WITH_X11 |
533 |
#endif |
#endif |
534 |
|
|
535 |
if (d->update_x2 != -1) { |
if (d->update_x2 != -1) { |
536 |
int y, addr, addr2, q = d->vfb_scaledown; |
#ifdef WITH_X11 |
537 |
|
int y; |
538 |
|
#endif |
539 |
|
int addr, addr2, q = d->vfb_scaledown; |
540 |
|
|
541 |
if (d->update_x1 >= d->visible_xsize) |
if (d->update_x1 >= d->visible_xsize) |
542 |
d->update_x1 = d->visible_xsize - 1; |
d->update_x1 = d->visible_xsize - 1; |
608 |
} |
} |
609 |
|
|
610 |
|
|
|
/* |
|
|
* dev_fb_access(): |
|
|
*/ |
|
611 |
DEVICE_ACCESS(fb) |
DEVICE_ACCESS(fb) |
612 |
{ |
{ |
613 |
struct vfb_data *d = extra; |
struct vfb_data *d = extra; |
732 |
* |
* |
733 |
* VFB_DEC_VFB01, _VFB02, and VFB_DEC_MAXINE are DECstation specific. |
* VFB_DEC_VFB01, _VFB02, and VFB_DEC_MAXINE are DECstation specific. |
734 |
* |
* |
735 |
* If type is VFB_HPC, then color encoding differs from the generic case. |
* VFB_HPC is like generic, but the color encoding is done as on HPCmips |
736 |
|
* and Dreamcast. |
737 |
* |
* |
738 |
* If bit_depth = -15 (note the minus sign), then a special hack is used for |
* 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. |
* the Playstation Portable's 5-bit R, 5-bit G, 5-bit B. |
746 |
size_t size, nlen; |
size_t size, nlen; |
747 |
int flags; |
int flags; |
748 |
int reverse_start = 0; |
int reverse_start = 0; |
|
char title[400]; |
|
749 |
char *name2; |
char *name2; |
750 |
|
|
751 |
d = malloc(sizeof(struct vfb_data)); |
d = malloc(sizeof(struct vfb_data)); |
760 |
reverse_start = 1; |
reverse_start = 1; |
761 |
} |
} |
762 |
|
|
763 |
|
d->memory = mem; |
764 |
d->vfb_type = vfb_type; |
d->vfb_type = vfb_type; |
765 |
|
|
766 |
/* Defaults: */ |
/* Defaults: */ |
839 |
d->update_x2 = d->update_y2 = -1; |
d->update_x2 = d->update_y2 = -1; |
840 |
} |
} |
841 |
|
|
842 |
/* Don't set the title to include the size of the framebuffer for |
d->name = strdup(name); |
843 |
VGA, since then the resolution might change during runtime. */ |
set_title(d); |
|
if (strcmp(name, "VGA") == 0) |
|
|
snprintf(title, sizeof(title),"GXemul: %s framebuffer", name); |
|
|
else |
|
|
snprintf(title, sizeof(title),"GXemul: %ix%ix%i %s framebuffer", |
|
|
d->visible_xsize, d->visible_ysize, d->bit_depth, name); |
|
|
title[sizeof(title)-1] = '\0'; |
|
844 |
|
|
845 |
#ifdef WITH_X11 |
#ifdef WITH_X11 |
846 |
if (machine->use_x11) { |
if (machine->use_x11) { |
847 |
int i = 0; |
int i = 0; |
848 |
d->fb_window = x11_fb_init(d->x11_xsize, d->x11_ysize, |
d->fb_window = x11_fb_init(d->x11_xsize, d->x11_ysize, |
849 |
title, machine->x11_scaledown, machine); |
d->title, machine->x11_scaledown, machine); |
850 |
switch (d->fb_window->x11_screen_depth) { |
switch (d->fb_window->x11_screen_depth) { |
851 |
case 15: i = 2; break; |
case 15: i = 2; break; |
852 |
case 16: i = 4; break; |
case 16: i = 4; break; |
878 |
memory_device_register(mem, name2, baseaddr, size, dev_fb_access, |
memory_device_register(mem, name2, baseaddr, size, dev_fb_access, |
879 |
d, flags, d->framebuffer); |
d, flags, d->framebuffer); |
880 |
|
|
881 |
machine_add_tickfunction(machine, dev_fb_tick, d, FB_TICK_SHIFT); |
machine_add_tickfunction(machine, dev_fb_tick, d, FB_TICK_SHIFT, 0.0); |
882 |
return d; |
return d; |
883 |
} |
} |
884 |
|
|