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;
uint16_t ca = (cga->crtc[15] | (cga->crtc[14] << 8)) & 0x3fff;
int drawcursor;
int x, c;
int x, c, xs_temp, ys_temp;
int oldvc;
uint8_t chr, attr;
uint8_t border;
@@ -438,11 +438,19 @@ cga_poll(void *p)
else
x = (cga->crtc[1] << 4) + 16;
cga->lastline++;
xs_temp = x;
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) &&
((x != xsize) || (((cga->lastline - cga->firstline) << 1) != ysize) ||
((xs_temp != xsize) || (ys_temp != ysize) ||
video_force_resize_get())) {
xsize = x;
ysize = (cga->lastline - cga->firstline) << 1;
xsize = xs_temp;
ysize = ys_temp;
if (xsize < 64) xsize = 656;
if (ysize < 32) ysize = 400;
set_screen_size(xsize, ysize + 16);
@@ -457,6 +465,8 @@ cga_poll(void *p)
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++;
video_res_x = xsize - 16;

View File

@@ -9,14 +9,14 @@
* Emulation of the EGA, Chips & Technologies SuperEGA, and
* 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/>
* Miran Grca, <mgrca8@gmail.com>
* akm
*
* Copyright 2008-2018 Sarah Walker.
* Copyright 2016-2018 Miran Grca.
* Copyright 2008-2019 Sarah Walker.
* Copyright 2016-2019 Miran Grca.
*/
#include <stdio.h>
#include <stdint.h>
@@ -413,6 +413,7 @@ void ega_poll(void *p)
{
ega_t *ega = (ega_t *)p;
int x;
int xs_temp, ys_temp;
int drawcursor = 0;
int y_add = enable_overscan ? (overscan_y >> 1) : 0;
int x_add = enable_overscan ? 8 : 0;
@@ -549,6 +550,10 @@ void ega_poll(void *p)
if (ega->interlace && !ega->oddeven) ega->lastline++;
if (ega->interlace && ega->oddeven) ega->firstline--;
xs_temp = x;
ys_temp = ega->lastline - ega->firstline + 1;
if ((xs_temp > 0) && (ys_temp > 1)) {
x_add = enable_overscan ? 8 : 0;
y_add = enable_overscan ? overscan_y : 0;
x_add_ex = enable_overscan ? 16 : 0;
@@ -561,14 +566,14 @@ void ega_poll(void *p)
} else
suppress_overscan = 0;
if ((x != xsize) || ((ega->lastline - ega->firstline + 1) != ysize) || video_force_resize_get()) {
xsize = x;
ysize = ega->lastline - ega->firstline + 1;
if (xsize < 64)
xsize = 640;
if (ysize < 32)
ysize = 200;
xs_temp = x;
ys_temp = ega->lastline - ega->firstline + 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()) {
if (ega->vres)
set_screen_size(xsize + x_add_ex, (ysize << 1) + y_add_ex);
else
@@ -608,6 +613,7 @@ void ega_poll(void *p)
}
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++;

View File

@@ -11,13 +11,13 @@
* This is intended to be used by another SVGA driver,
* 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/>
* Miran Grca, <mgrca8@gmail.com>
*
* Copyright 2008-2018 Sarah Walker.
* Copyright 2016-2018 Miran Grca.
* Copyright 2008-2019 Sarah Walker.
* Copyright 2016-2019 Miran Grca.
*/
#include <inttypes.h>
#include <stdio.h>
@@ -711,7 +711,7 @@ svga_poll(void *p)
wx = x;
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->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;
uint32_t *p;
int i, j;
int xs_temp, ys_temp;
if ((xsize > 2032) || (ysize > 2032)) {
x_add = 0;
@@ -1136,14 +1137,17 @@ svga_doblit(int y1, int y2, int wx, int wy, svga_t *svga)
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. */
xsize = wx;
ysize = wy + 1;
if (xsize < 64)
xsize = 640;
if (ysize < 32)
ysize = 200;
xsize = xs_temp;
ysize = ys_temp;
set_screen_size(xsize+x_add,ysize+y_add);