- VBE specific case for graphics snapshot can be used for >= 8 bpp modes only

- palette data for snapshot is now dword aligned to simplify code
- prepared snapshot code to support 4 bpp EGA/VGA memory layout (not yet complete)
This commit is contained in:
Volker Ruppert 2011-08-06 13:08:31 +00:00
parent c7f63fca93
commit bce6a17b98
4 changed files with 35 additions and 17 deletions

View File

@ -419,7 +419,7 @@ void bx_gui_c::snapshot_handler(void)
int fd, i, j, mode, pitch;
Bit8u *snapshot_ptr = NULL, *palette_ptr = NULL;
Bit8u *row_buffer, *pixel_ptr, *row_ptr;
Bit8u bmp_header[54], pal_entry[4], iBits, b1, b2;
Bit8u bmp_header[54], iBits, b1, b2;
Bit32u ilen, len, rlen;
char filename[BX_PATHNAME_LEN];
unsigned iHeight, iWidth, iDepth;
@ -450,6 +450,7 @@ void bx_gui_c::snapshot_handler(void)
"Save snapshot as...", "snapshot.bmp",
bx_param_string_c::SAVE_FILE_DIALOG);
if (ret < 0) { // cancelled
if (palette_ptr != NULL) free(palette_ptr);
free(snapshot_ptr);
return;
}
@ -464,6 +465,7 @@ void bx_gui_c::snapshot_handler(void)
);
if (fd < 0) {
BX_ERROR(("snapshot button failed: cannot create BMP file"));
if (palette_ptr != NULL) free(palette_ptr);
free(snapshot_ptr);
return;
}
@ -487,14 +489,7 @@ void bx_gui_c::snapshot_handler(void)
bmp_header[28] = iBits;
write(fd, bmp_header, 54);
if ((iDepth == 8) && (palette_ptr != NULL)) {
pal_entry[3] = 0;
pixel_ptr = palette_ptr;
for (i = 0; i < 256; i++) {
pal_entry[0] = *(pixel_ptr++);
pal_entry[1] = *(pixel_ptr++);
pal_entry[2] = *(pixel_ptr++);
write(fd, pal_entry, 4);
}
write(fd, palette_ptr, 256 * 4);
}
pitch = iWidth * ((iDepth + 1) >> 3);
row_buffer = (Bit8u*)malloc(rlen);
@ -534,7 +529,7 @@ void bx_gui_c::snapshot_handler(void)
if (palette_ptr != NULL) free(palette_ptr);
free(snapshot_ptr);
} else {
BX_ERROR(("snapshot button failed: VGA mode not implemented"));
BX_ERROR(("snapshot button failed: unsupported VGA mode"));
}
}

View File

@ -49,8 +49,8 @@
#define BX_GUI_MT_CTRL_ALT (BX_MT_KEY_CTRL | BX_MT_KEY_ALT)
// snapshot feature
#define BX_GUI_SNAPSHOT_TXT 0
#define BX_GUI_SNAPSHOT_VGA 1
#define BX_GUI_SNAPSHOT_UNSUP 0
#define BX_GUI_SNAPSHOT_TXT 1
#define BX_GUI_SNAPSHOT_GFX 2
typedef struct {

View File

@ -851,12 +851,13 @@ Bit32u bx_svga_cirrus_c::get_gfx_snapshot(Bit8u **snapshot_ptr, Bit8u **palette_
dst_ptr += len1;
}
if (*iDepth == 8) {
*palette_ptr = (Bit8u*)malloc(256 * 3);
*palette_ptr = (Bit8u*)malloc(256 * 4);
dst_ptr = *palette_ptr;
for (i = 0; i < 256; i++) {
*(dst_ptr++) = (BX_CIRRUS_THIS s.pel.data[i].blue << 2);
*(dst_ptr++) = (BX_CIRRUS_THIS s.pel.data[i].green << 2);
*(dst_ptr++) = (BX_CIRRUS_THIS s.pel.data[i].red << 2);
*(dst_ptr++) = 0;
}
}
return len;

View File

@ -2716,12 +2716,16 @@ void bx_vga_c::mem_write(bx_phy_address addr, Bit8u value)
int bx_vga_c::get_snapshot_mode()
{
if (BX_VGA_THIS vbe.enabled) {
if ((BX_VGA_THIS vbe.enabled) && (BX_VGA_THIS vbe.bpp >= 8)) {
return BX_GUI_SNAPSHOT_GFX;
} else if (!BX_VGA_THIS s.graphics_ctrl.graphics_alpha) {
return BX_GUI_SNAPSHOT_TXT;
} else if ((BX_VGA_THIS s.graphics_ctrl.shift_reg == 0) &&
(BX_VGA_THIS s.graphics_ctrl.memory_mapping != 3)) {
// TODO: standard EGA/VGA memory layout
return BX_GUI_SNAPSHOT_UNSUP;
} else {
return BX_GUI_SNAPSHOT_VGA;
return BX_GUI_SNAPSHOT_UNSUP;
}
}
@ -2749,7 +2753,7 @@ Bit32u bx_vga_c::get_gfx_snapshot(Bit8u **snapshot_ptr, Bit8u **palette_ptr,
unsigned i, shift;
Bit8u *dst_ptr, *src_ptr;
if (BX_VGA_THIS vbe.enabled) {
if ((BX_VGA_THIS vbe.enabled) && (BX_VGA_THIS vbe.bpp >= 8)) {
*iHeight = BX_VGA_THIS vbe.yres;
*iWidth = BX_VGA_THIS vbe.xres;
*iDepth = BX_VGA_THIS vbe.bpp;
@ -2764,7 +2768,7 @@ Bit32u bx_vga_c::get_gfx_snapshot(Bit8u **snapshot_ptr, Bit8u **palette_ptr,
dst_ptr += len1;
}
if (*iDepth == 8) {
*palette_ptr = (Bit8u*)malloc(256 * 3);
*palette_ptr = (Bit8u*)malloc(256 * 4);
dst_ptr = *palette_ptr;
if (BX_VGA_THIS vbe.dac_8bit) {
shift = 0;
@ -2775,9 +2779,27 @@ Bit32u bx_vga_c::get_gfx_snapshot(Bit8u **snapshot_ptr, Bit8u **palette_ptr,
*(dst_ptr++) = (BX_VGA_THIS s.pel.data[i].blue << shift);
*(dst_ptr++) = (BX_VGA_THIS s.pel.data[i].green << shift);
*(dst_ptr++) = (BX_VGA_THIS s.pel.data[i].red << shift);
*(dst_ptr++) = 0;
}
}
return len;
} else if ((BX_VGA_THIS s.graphics_ctrl.shift_reg == 0) &&
(BX_VGA_THIS s.graphics_ctrl.memory_mapping != 3)) {
*iHeight = old_iHeight;
*iWidth = old_iWidth;
*iDepth = 8;
len = (old_iWidth * old_iHeight);
*snapshot_ptr = (Bit8u*)malloc(len);
// TODO: standard EGA/VGA memory layout
*palette_ptr = (Bit8u*)malloc(256 * 4);
dst_ptr = *palette_ptr;
for (i = 0; i < 256; i++) {
*(dst_ptr++) = (BX_VGA_THIS s.pel.data[i].blue << 2);
*(dst_ptr++) = (BX_VGA_THIS s.pel.data[i].green << 2);
*(dst_ptr++) = (BX_VGA_THIS s.pel.data[i].red << 2);
*(dst_ptr++) = 0;
}
return len;
} else {
*iHeight = 0;
*iWidth = 0;