1 |
/* |
/* |
2 |
* Copyright (C) 2003-2006 Anders Gavare. All rights reserved. |
* Copyright (C) 2003-2007 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.121 2006/07/08 12:30:02 debug Exp $ |
* $Id: dev_fb.c,v 1.132 2007/06/15 19:11:15 debug Exp $ |
29 |
* |
* |
30 |
* Generic framebuffer device. |
* COMMENT: 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, useful for |
* Generic (any resolution, several bit depths possible, useful for |
37 |
* testmachines) |
* testmachines) |
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 |
|
|
144 |
new_framebuffer = malloc(size); |
CHECK_ALLOCATION(new_framebuffer = malloc(size)); |
|
if (new_framebuffer == NULL) { |
|
|
fprintf(stderr, "dev_fb_resize(): out of memory\n"); |
|
|
exit(1); |
|
|
} |
|
145 |
|
|
146 |
/* Copy the old framebuffer to the new: */ |
/* Copy the old framebuffer to the new: */ |
147 |
if (d->framebuffer != NULL) { |
if (d->framebuffer != NULL) { |
214 |
} |
} |
215 |
#endif |
#endif |
216 |
|
|
|
if (d->fb_window != NULL) |
|
|
console_set_framebuffer_mouse(cursor_x, cursor_y, |
|
|
d->fb_window->fb_number); |
|
|
|
|
217 |
/* debug("dev_fb_setcursor(%i,%i, size %i,%i, on=%i)\n", |
/* debug("dev_fb_setcursor(%i,%i, size %i,%i, on=%i)\n", |
218 |
cursor_x, cursor_y, cursor_xsize, cursor_ysize, on); */ |
cursor_x, cursor_y, cursor_xsize, cursor_ysize, on); */ |
219 |
} |
} |
226 |
* block copy/fill. |
* block copy/fill. |
227 |
* |
* |
228 |
* If fillflag is non-zero, then fill_[rgb] should contain the color |
* If fillflag is non-zero, then fill_[rgb] should contain the color |
229 |
* with which to fill. |
* with which to fill. (In 8-bit mode, only fill_r is used.) |
230 |
* |
* |
231 |
* 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 |
232 |
* the offset on the framebuffer where we should copy from. |
* the offset on the framebuffer where we should copy from. |
237 |
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, |
238 |
int from_x, int from_y) |
int from_x, int from_y) |
239 |
{ |
{ |
240 |
int y; |
int x, y; |
241 |
long from_ofs, dest_ofs, linelen; |
long from_ofs, dest_ofs, linelen; |
242 |
|
|
243 |
if (fillflag) |
if (fillflag) |
260 |
if (fillflag) { |
if (fillflag) { |
261 |
for (y=y1; y<=y2; y++) { |
for (y=y1; y<=y2; y++) { |
262 |
if (y>=0 && y<d->ysize) { |
if (y>=0 && y<d->ysize) { |
263 |
int x; |
unsigned char *buf = |
264 |
char buf[8192 * 3]; |
d->framebuffer + dest_ofs; |
265 |
if (d->bit_depth == 24) |
|
266 |
for (x=0; x<linelen && x<sizeof(buf); |
if (d->bit_depth == 24) { |
267 |
x += 3) { |
for (x=0; x<linelen && x < |
268 |
|
(int) sizeof(buf); x += 3) { |
269 |
buf[x] = fill_r; |
buf[x] = fill_r; |
270 |
buf[x+1] = fill_g; |
buf[x+1] = fill_g; |
271 |
buf[x+2] = fill_b; |
buf[x+2] = fill_b; |
272 |
} |
} |
273 |
else { |
} else if (d->bit_depth == 8) { |
274 |
fatal("[ fb: TODO: fill for non-24-bit" |
memset(buf, fill_r, linelen); |
275 |
" modes ]\n"); |
} else { |
276 |
|
fatal("Unimplemented bit-depth (%i)" |
277 |
|
" for fb fill\n", d->bit_depth); |
278 |
|
exit(1); |
279 |
} |
} |
|
|
|
|
memmove(d->framebuffer + dest_ofs, buf, |
|
|
linelen); |
|
280 |
} |
} |
281 |
|
|
282 |
dest_ofs += d->bytes_per_line; |
dest_ofs += d->bytes_per_line; |
284 |
} else { |
} else { |
285 |
from_ofs = d->bytes_per_line * from_y + |
from_ofs = d->bytes_per_line * from_y + |
286 |
(d->bit_depth/8) * from_x; |
(d->bit_depth/8) * from_x; |
|
|
|
287 |
for (y=y1; y<=y2; y++) { |
for (y=y1; y<=y2; y++) { |
288 |
if (y>=0 && y<d->ysize) |
if (y >= 0 && y < d->ysize) { |
289 |
memmove(d->framebuffer + dest_ofs, |
if (from_y >= 0 && from_y < d->ysize) |
290 |
d->framebuffer + from_ofs, linelen); |
memmove(d->framebuffer + dest_ofs, |
291 |
|
d->framebuffer + from_ofs, linelen); |
292 |
|
else |
293 |
|
memset(d->framebuffer + dest_ofs, |
294 |
|
0, linelen); |
295 |
|
} |
296 |
|
from_y ++; |
297 |
from_ofs += d->bytes_per_line; |
from_ofs += d->bytes_per_line; |
298 |
dest_ofs += d->bytes_per_line; |
dest_ofs += d->bytes_per_line; |
299 |
} |
} |
404 |
#endif /* WITH_X11 */ |
#endif /* WITH_X11 */ |
405 |
|
|
406 |
|
|
407 |
/* |
DEVICE_TICK(fb) |
|
* dev_fb_tick(): |
|
|
* |
|
|
*/ |
|
|
void dev_fb_tick(struct cpu *cpu, void *extra) |
|
408 |
{ |
{ |
409 |
struct vfb_data *d = extra; |
struct vfb_data *d = extra; |
410 |
#ifdef WITH_X11 |
#ifdef WITH_X11 |
412 |
int need_to_redraw_cursor = 0; |
int need_to_redraw_cursor = 0; |
413 |
#endif |
#endif |
414 |
|
|
415 |
if (!cpu->machine->use_x11) |
if (!cpu->machine->x11_md.in_use) |
416 |
return; |
return; |
417 |
|
|
418 |
do { |
do { |
604 |
} |
} |
605 |
|
|
606 |
|
|
|
/* |
|
|
* dev_fb_access(): |
|
|
*/ |
|
607 |
DEVICE_ACCESS(fb) |
DEVICE_ACCESS(fb) |
608 |
{ |
{ |
609 |
struct vfb_data *d = extra; |
struct vfb_data *d = extra; |
646 |
* of which area(s) we modify, so that the display isn't updated |
* of which area(s) we modify, so that the display isn't updated |
647 |
* unnecessarily. |
* unnecessarily. |
648 |
*/ |
*/ |
649 |
if (writeflag == MEM_WRITE && cpu->machine->use_x11) { |
if (writeflag == MEM_WRITE && cpu->machine->x11_md.in_use) { |
650 |
int x, y, x2,y2; |
int x, y, x2,y2; |
651 |
|
|
652 |
x = (relative_addr % d->bytes_per_line) * 8 / d->bit_depth; |
x = (relative_addr % d->bytes_per_line) * 8 / d->bit_depth; |
728 |
* |
* |
729 |
* VFB_DEC_VFB01, _VFB02, and VFB_DEC_MAXINE are DECstation specific. |
* VFB_DEC_VFB01, _VFB02, and VFB_DEC_MAXINE are DECstation specific. |
730 |
* |
* |
731 |
* 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 |
732 |
|
* and Dreamcast. |
733 |
* |
* |
734 |
* 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 |
735 |
* 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. |
744 |
int reverse_start = 0; |
int reverse_start = 0; |
745 |
char *name2; |
char *name2; |
746 |
|
|
747 |
d = malloc(sizeof(struct vfb_data)); |
CHECK_ALLOCATION(d = malloc(sizeof(struct vfb_data))); |
|
if (d == NULL) { |
|
|
fprintf(stderr, "out of memory\n"); |
|
|
exit(1); |
|
|
} |
|
748 |
memset(d, 0, sizeof(struct vfb_data)); |
memset(d, 0, sizeof(struct vfb_data)); |
749 |
|
|
750 |
if (vfb_type & VFB_REVERSE_START) { |
if (vfb_type & VFB_REVERSE_START) { |
802 |
else if (d->bit_depth == 8 || d->bit_depth == 1) |
else if (d->bit_depth == 8 || d->bit_depth == 1) |
803 |
set_blackwhite_palette(d, 1 << d->bit_depth); |
set_blackwhite_palette(d, 1 << d->bit_depth); |
804 |
|
|
805 |
d->vfb_scaledown = machine->x11_scaledown; |
d->vfb_scaledown = machine->x11_md.scaledown; |
806 |
|
|
807 |
d->bytes_per_line = d->xsize * d->bit_depth / 8; |
d->bytes_per_line = d->xsize * d->bit_depth / 8; |
808 |
size = d->ysize * d->bytes_per_line; |
size = d->ysize * d->bytes_per_line; |
809 |
|
|
810 |
d->framebuffer = malloc(size); |
CHECK_ALLOCATION(d->framebuffer = malloc(size)); |
|
if (d->framebuffer == NULL) { |
|
|
fprintf(stderr, "out of memory\n"); |
|
|
exit(1); |
|
|
} |
|
811 |
|
|
812 |
/* Clear the framebuffer (all black pixels): */ |
/* Clear the framebuffer (all black pixels): */ |
813 |
d->framebuffer_size = size; |
d->framebuffer_size = size; |
827 |
d->update_x2 = d->update_y2 = -1; |
d->update_x2 = d->update_y2 = -1; |
828 |
} |
} |
829 |
|
|
830 |
d->name = strdup(name); |
CHECK_ALLOCATION(d->name = strdup(name)); |
831 |
set_title(d); |
set_title(d); |
832 |
|
|
833 |
#ifdef WITH_X11 |
#ifdef WITH_X11 |
834 |
if (machine->use_x11) { |
if (machine->x11_md.in_use) { |
835 |
int i = 0; |
int i = 0; |
836 |
d->fb_window = x11_fb_init(d->x11_xsize, d->x11_ysize, |
d->fb_window = x11_fb_init(d->x11_xsize, d->x11_ysize, |
837 |
d->title, machine->x11_scaledown, machine); |
d->title, machine->x11_md.scaledown, machine); |
838 |
switch (d->fb_window->x11_screen_depth) { |
switch (d->fb_window->x11_screen_depth) { |
839 |
case 15: i = 2; break; |
case 15: i = 2; break; |
840 |
case 16: i = 4; break; |
case 16: i = 4; break; |
850 |
d->fb_window = NULL; |
d->fb_window = NULL; |
851 |
|
|
852 |
nlen = strlen(name) + 10; |
nlen = strlen(name) + 10; |
853 |
name2 = malloc(nlen); |
CHECK_ALLOCATION(name2 = malloc(nlen)); |
854 |
if (name2 == NULL) { |
|
|
fprintf(stderr, "out of memory in dev_fb_init()\n"); |
|
|
exit(1); |
|
|
} |
|
855 |
snprintf(name2, nlen, "fb [%s]", name); |
snprintf(name2, nlen, "fb [%s]", name); |
856 |
|
|
857 |
flags = DM_DEFAULT; |
flags = DM_DEFAULT; |
863 |
memory_device_register(mem, name2, baseaddr, size, dev_fb_access, |
memory_device_register(mem, name2, baseaddr, size, dev_fb_access, |
864 |
d, flags, d->framebuffer); |
d, flags, d->framebuffer); |
865 |
|
|
866 |
machine_add_tickfunction(machine, dev_fb_tick, d, FB_TICK_SHIFT, 0.0); |
machine_add_tickfunction(machine, dev_fb_tick, d, FB_TICK_SHIFT); |
867 |
|
|
868 |
return d; |
return d; |
869 |
} |
} |
870 |
|
|