Added more sanity checks to the CGA, EGA, and SVGA polls, fixes #399.

This commit is contained in:
OBattler
2019-09-26 16:00:43 +02:00
parent 6daab888d0
commit 88a619fd47
3 changed files with 96 additions and 76 deletions

View File

@@ -186,7 +186,7 @@ cga_poll(void *p)
cga_t *cga = (cga_t *)p; cga_t *cga = (cga_t *)p;
uint16_t ca = (cga->crtc[15] | (cga->crtc[14] << 8)) & 0x3fff; uint16_t ca = (cga->crtc[15] | (cga->crtc[14] << 8)) & 0x3fff;
int drawcursor; int drawcursor;
int x, c; int x, c, xs_temp, ys_temp;
int oldvc; int oldvc;
uint8_t chr, attr; uint8_t chr, attr;
uint8_t border; uint8_t border;
@@ -438,25 +438,35 @@ cga_poll(void *p)
else else
x = (cga->crtc[1] << 4) + 16; x = (cga->crtc[1] << 4) + 16;
cga->lastline++; cga->lastline++;
if ((cga->cgamode & 8) && x && (cga->lastline - cga->firstline) &&
((x != xsize) || (((cga->lastline - cga->firstline) << 1) != ysize) ||
video_force_resize_get())) {
xsize = x;
ysize = (cga->lastline - cga->firstline) << 1;
if (xsize < 64) xsize = 656;
if (ysize < 32) ysize = 400;
set_screen_size(xsize, ysize + 16);
if (video_force_resize_get()) xs_temp = x;
video_force_resize_set(0); ys_temp = (cga->lastline - cga->firstline) << 1;
if ((xs_temp > 0) && (ys_temp > 0)) {
if (xsize < 64) xs_temp = 656;
if (ysize < 32) ys_temp = 400;
if ((cga->cgamode & 8) && x && (cga->lastline - cga->firstline) &&
((xs_temp != xsize) || (ys_temp != ysize) ||
video_force_resize_get())) {
xsize = xs_temp;
ysize = ys_temp;
if (xsize < 64) xsize = 656;
if (ysize < 32) ysize = 400;
set_screen_size(xsize, ysize + 16);
if (video_force_resize_get())
video_force_resize_set(0);
}
if (cga->composite)
video_blit_memtoscreen(0, (cga->firstline - 4) << 1, 0, ((cga->lastline - cga->firstline) + 8) << 1,
xsize, ((cga->lastline - cga->firstline) + 8) << 1);
else
video_blit_memtoscreen_8(0, (cga->firstline - 4) << 1, 0, ((cga->lastline - cga->firstline) + 8) << 1,
xsize, ((cga->lastline - cga->firstline) + 8) << 1);
} }
if (cga->composite)
video_blit_memtoscreen(0, (cga->firstline - 4) << 1, 0, ((cga->lastline - cga->firstline) + 8) << 1,
xsize, ((cga->lastline - cga->firstline) + 8) << 1);
else
video_blit_memtoscreen_8(0, (cga->firstline - 4) << 1, 0, ((cga->lastline - cga->firstline) + 8) << 1,
xsize, ((cga->lastline - cga->firstline) + 8) << 1);
frames++; frames++;
video_res_x = xsize - 16; video_res_x = xsize - 16;

View File

@@ -9,14 +9,14 @@
* Emulation of the EGA, Chips & Technologies SuperEGA, and * Emulation of the EGA, Chips & Technologies SuperEGA, and
* AX JEGA graphics cards. * AX JEGA graphics cards.
* *
* Version: @(#)vid_ega.c 1.0.19 2018/12/31 * Version: @(#)vid_ega.c 1.0.20 2019/09/26
* *
* Authors: Sarah Walker, <http://pcem-emulator.co.uk/> * Authors: Sarah Walker, <http://pcem-emulator.co.uk/>
* Miran Grca, <mgrca8@gmail.com> * Miran Grca, <mgrca8@gmail.com>
* akm * akm
* *
* Copyright 2008-2018 Sarah Walker. * Copyright 2008-2019 Sarah Walker.
* Copyright 2016-2018 Miran Grca. * Copyright 2016-2019 Miran Grca.
*/ */
#include <stdio.h> #include <stdio.h>
#include <stdint.h> #include <stdint.h>
@@ -413,6 +413,7 @@ void ega_poll(void *p)
{ {
ega_t *ega = (ega_t *)p; ega_t *ega = (ega_t *)p;
int x; int x;
int xs_temp, ys_temp;
int drawcursor = 0; int drawcursor = 0;
int y_add = enable_overscan ? (overscan_y >> 1) : 0; int y_add = enable_overscan ? (overscan_y >> 1) : 0;
int x_add = enable_overscan ? 8 : 0; int x_add = enable_overscan ? 8 : 0;
@@ -549,65 +550,70 @@ void ega_poll(void *p)
if (ega->interlace && !ega->oddeven) ega->lastline++; if (ega->interlace && !ega->oddeven) ega->lastline++;
if (ega->interlace && ega->oddeven) ega->firstline--; if (ega->interlace && ega->oddeven) ega->firstline--;
x_add = enable_overscan ? 8 : 0; xs_temp = x;
y_add = enable_overscan ? overscan_y : 0; ys_temp = ega->lastline - ega->firstline + 1;
x_add_ex = enable_overscan ? 16 : 0;
y_add_ex = y_add << 1;
if ((xsize > 2032) || ((ysize + y_add_ex) > 2048)) { if ((xs_temp > 0) && (ys_temp > 1)) {
x_add = x_add_ex = 0; x_add = enable_overscan ? 8 : 0;
y_add = y_add_ex = 0; y_add = enable_overscan ? overscan_y : 0;
suppress_overscan = 1; x_add_ex = enable_overscan ? 16 : 0;
} else y_add_ex = y_add << 1;
suppress_overscan = 0;
if ((x != xsize) || ((ega->lastline - ega->firstline + 1) != ysize) || video_force_resize_get()) { if ((xsize > 2032) || ((ysize + y_add_ex) > 2048)) {
xsize = x; x_add = x_add_ex = 0;
ysize = ega->lastline - ega->firstline + 1; y_add = y_add_ex = 0;
if (xsize < 64) suppress_overscan = 1;
xsize = 640; } else
if (ysize < 32) suppress_overscan = 0;
ysize = 200;
if (ega->vres) xs_temp = x;
set_screen_size(xsize + x_add_ex, (ysize << 1) + y_add_ex); ys_temp = ega->lastline - ega->firstline + 1;
else if (xs_temp < 64)
set_screen_size(xsize + x_add_ex, ysize + y_add_ex); xs_temp = 640;
if (ys_temp < 32)
ys_temp = 200;
if (video_force_resize_get()) if ((xs_temp != xsize) || (ys_temp != ysize) || video_force_resize_get()) {
video_force_resize_set(0); if (ega->vres)
} set_screen_size(xsize + x_add_ex, (ysize << 1) + y_add_ex);
else
set_screen_size(xsize + x_add_ex, ysize + y_add_ex);
if (enable_overscan && !suppress_overscan) { if (video_force_resize_get())
if ((x >= 160) && ((ega->lastline - ega->firstline + 1) >= 120)) { video_force_resize_set(0);
/* Draw (overscan_size - scroll size) lines of overscan on top. */ }
for (i = 0; i < y_add; i++) {
q = &buffer32->line[i & 0x7ff][32];
for (j = 0; j < (xsize + x_add_ex); j++) if (enable_overscan && !suppress_overscan) {
q[j] = ega->overscan_color; if ((x >= 160) && ((ega->lastline - ega->firstline + 1) >= 120)) {
} /* Draw (overscan_size - scroll size) lines of overscan on top. */
for (i = 0; i < y_add; i++) {
q = &buffer32->line[i & 0x7ff][32];
/* Draw (overscan_size + scroll size) lines of overscan on the bottom. */ for (j = 0; j < (xsize + x_add_ex); j++)
for (i = 0; i < y_add_ex; i++) { q[j] = ega->overscan_color;
q = &buffer32->line[(ysize + y_add + i) & 0x7ff][32]; }
for (j = 0; j < (xsize + x_add_ex); j++) /* Draw (overscan_size + scroll size) lines of overscan on the bottom. */
q[j] = ega->overscan_color; for (i = 0; i < y_add_ex; i++) {
} q = &buffer32->line[(ysize + y_add + i) & 0x7ff][32];
for (i = y_add_ex; i < (ysize + y_add); i ++) { for (j = 0; j < (xsize + x_add_ex); j++)
q = &buffer32->line[i & 0x7ff][32]; q[j] = ega->overscan_color;
}
for (j = 0; j < x_add; j++) { for (i = y_add_ex; i < (ysize + y_add); i ++) {
q[j] = ega->overscan_color; q = &buffer32->line[i & 0x7ff][32];
q[xsize + x_add + j] = ega->overscan_color;
for (j = 0; j < x_add; j++) {
q[j] = ega->overscan_color;
q[xsize + x_add + j] = ega->overscan_color;
}
} }
} }
} }
}
video_blit_memtoscreen(32, 0, ega->firstline, ega->lastline + 1 + y_add_ex, xsize + x_add_ex, ega->lastline - ega->firstline + 1 + y_add_ex); video_blit_memtoscreen(32, 0, ega->firstline, ega->lastline + 1 + y_add_ex, xsize + x_add_ex, ega->lastline - ega->firstline + 1 + y_add_ex);
}
frames++; frames++;

View File

@@ -11,13 +11,13 @@
* This is intended to be used by another SVGA driver, * This is intended to be used by another SVGA driver,
* and not as a card in it's own right. * and not as a card in it's own right.
* *
* Version: @(#)vid_svga.c 1.0.35 2018/10/21 * Version: @(#)vid_svga.c 1.0.36 2019/09/26
* *
* Authors: Sarah Walker, <http://pcem-emulator.co.uk/> * Authors: Sarah Walker, <http://pcem-emulator.co.uk/>
* Miran Grca, <mgrca8@gmail.com> * Miran Grca, <mgrca8@gmail.com>
* *
* Copyright 2008-2018 Sarah Walker. * Copyright 2008-2019 Sarah Walker.
* Copyright 2016-2018 Miran Grca. * Copyright 2016-2019 Miran Grca.
*/ */
#include <inttypes.h> #include <inttypes.h>
#include <stdio.h> #include <stdio.h>
@@ -711,7 +711,7 @@ svga_poll(void *p)
wx = x; wx = x;
wy = svga->lastline - svga->firstline; wy = svga->lastline - svga->firstline;
if (!svga->override) if (!svga->override && (wx > 0) && (wy > 0))
svga_doblit(svga->firstline_draw, svga->lastline_draw + 1, wx, wy, svga); svga_doblit(svga->firstline_draw, svga->lastline_draw + 1, wx, wy, svga);
svga->firstline = 2000; svga->firstline = 2000;
@@ -1123,6 +1123,7 @@ svga_doblit(int y1, int y2, int wx, int wy, svga_t *svga)
int x_add = (enable_overscan) ? 16 : 0; int x_add = (enable_overscan) ? 16 : 0;
uint32_t *p; uint32_t *p;
int i, j; int i, j;
int xs_temp, ys_temp;
if ((xsize > 2032) || (ysize > 2032)) { if ((xsize > 2032) || (ysize > 2032)) {
x_add = 0; x_add = 0;
@@ -1136,14 +1137,17 @@ svga_doblit(int y1, int y2, int wx, int wy, svga_t *svga)
return; return;
} }
if ((wx != xsize) || ((wy + 1) != ysize) || video_force_resize_get()) { xs_temp = wx;
ys_temp = wy + 1;
if (xs_temp < 64)
xs_temp = 640;
if (ys_temp < 32)
ys_temp = 200;
if ((xs_temp != xsize) || (ys_temp != ysize) || video_force_resize_get()) {
/* Screen res has changed.. fix up, and let them know. */ /* Screen res has changed.. fix up, and let them know. */
xsize = wx; xsize = xs_temp;
ysize = wy + 1; ysize = ys_temp;
if (xsize < 64)
xsize = 640;
if (ysize < 32)
ysize = 200;
set_screen_size(xsize+x_add,ysize+y_add); set_screen_size(xsize+x_add,ysize+y_add);