Files
86Box/src/video/vid_ega.c

1707 lines
54 KiB
C
Raw Normal View History

/*
2023-01-06 15:36:05 -05:00
* 86Box A hypervisor and IBM PC system emulator that specializes in
* running old operating systems and software designed for IBM
* PC systems and compatibles from 1981 through fairly recent
* system designs based on the PCI bus.
*
2023-01-06 15:36:05 -05:00
* This file is part of the 86Box distribution.
*
2023-01-06 15:36:05 -05:00
* Emulation of the EGA and Chips & Technologies SuperEGA
* graphics cards.
*
2020-03-25 00:46:02 +02:00
*
*
2023-01-06 15:36:29 -05:00
* Authors: Sarah Walker, <https://pcem-emulator.co.uk/>
2023-01-06 15:36:05 -05:00
* Miran Grca, <mgrca8@gmail.com>
*
2023-01-06 15:36:05 -05:00
* Copyright 2008-2019 Sarah Walker.
* Copyright 2016-2019 Miran Grca.
*/
#include <stdbool.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include <wchar.h>
#include <86box/86box.h>
2020-02-29 19:12:23 +01:00
#include "cpu.h"
#include <86box/io.h>
#include <86box/timer.h>
#include <86box/pic.h>
#include <86box/pit.h>
#include <86box/mem.h>
#include <86box/rom.h>
#include <86box/device.h>
#include <86box/video.h>
#include <86box/vid_ati_eeprom.h>
#include <86box/vid_ega.h>
void ega_doblit(int wx, int wy, ega_t *ega);
2022-08-31 19:19:29 -04:00
#define BIOS_IBM_PATH "roms/video/ega/ibm_6277356_ega_card_u44_27128.bin"
#define BIOS_CPQ_PATH "roms/video/ega/108281-001.bin"
#define BIOS_SEGA_PATH "roms/video/ega/lega.vbi"
#define BIOS_ATIEGA800P_PATH "roms/video/ega/ATI EGA Wonder 800+ N1.00.BIN"
2022-08-31 19:19:29 -04:00
#define BIOS_ISKRA_PATH "roms/video/ega/143-02.bin", "roms/video/ega/143-03.bin"
#define BIOS_TSENG_PATH "roms/video/ega/EGA ET2000.BIN"
enum {
EGA_IBM = 0,
EGA_COMPAQ,
EGA_SUPEREGA,
EGA_ATI800P,
EGA_ISKRA,
EGA_TSENG
};
2022-08-31 19:19:29 -04:00
static video_timings_t timing_ega = { .type = VIDEO_ISA, .write_b = 8, .write_w = 16, .write_l = 32, .read_b = 8, .read_w = 16, .read_l = 32 };
static uint8_t ega_rotate[8][256];
2023-06-01 18:32:25 -04:00
static uint32_t pallook16[256];
static uint32_t pallook64[256];
2023-07-31 14:43:33 -04:00
static int ega_type = 0;
2023-06-01 18:32:25 -04:00
static int old_overscan_color = 0;
/* 3C2 controls default mode on EGA. On VGA, it determines monitor type (mono or colour):
7=CGA mode (200 lines), 9=EGA mode (350 lines), 8=EGA mode (200 lines). */
2023-06-01 18:32:25 -04:00
int egaswitchread;
2023-07-31 14:43:33 -04:00
int egaswitches = 9;
2022-08-31 19:19:29 -04:00
int update_overscan = 0;
2021-12-08 22:43:23 +01:00
2023-06-09 23:46:54 -04:00
uint8_t ega_in(uint16_t addr, void *priv);
2021-12-08 22:43:23 +01:00
void
2023-06-09 23:46:54 -04:00
ega_out(uint16_t addr, uint8_t val, void *priv)
{
2023-06-09 23:46:54 -04:00
ega_t *ega = (ega_t *) priv;
2023-06-01 18:32:25 -04:00
uint8_t o;
uint8_t old;
2022-02-20 02:26:27 -05:00
if (((addr & 0xfff0) == 0x3d0 || (addr & 0xfff0) == 0x3b0) && !(ega->miscout & 1))
2022-08-31 19:19:29 -04:00
addr ^= 0x60;
switch (addr) {
case 0x1ce:
ega->index = val;
break;
case 0x1cf:
ega->regs[ega->index] = val;
switch (ega->index) {
case 0xb0:
ega_recalctimings(ega);
break;
case 0xb3:
ati_eeprom_write((ati_eeprom_t *) ega->eeprom, val & 8, val & 2, val & 1);
break;
default:
break;
}
break;
2022-08-31 19:19:29 -04:00
case 0x3c0:
case 0x3c1:
if (!ega->attrff) {
ega->attraddr = val & 31;
if ((val & 0x20) != ega->attr_palette_enable) {
ega->fullchange = 3;
ega->attr_palette_enable = val & 0x20;
ega_recalctimings(ega);
}
} else {
if ((ega->attraddr == 0x13) && (ega->attrregs[0x13] != val))
ega->fullchange = changeframecount;
2022-08-31 19:19:29 -04:00
o = ega->attrregs[ega->attraddr & 31];
ega->attrregs[ega->attraddr & 31] = val;
if (ega->attraddr < 16)
ega->fullchange = changeframecount;
if (ega->attraddr == 0x10 || ega->attraddr == 0x14 || ega->attraddr < 0x10) {
2023-06-01 18:32:25 -04:00
for (uint8_t c = 0; c < 16; c++) {
2022-08-31 19:19:29 -04:00
if (ega->attrregs[0x10] & 0x80)
ega->egapal[c] = (ega->attrregs[c] & 0xf) | ((ega->attrregs[0x14] & 0xf) << 4);
else
ega->egapal[c] = (ega->attrregs[c] & 0x3f) | ((ega->attrregs[0x14] & 0xc) << 4);
}
ega->fullchange = changeframecount;
2022-08-31 19:19:29 -04:00
}
/* Recalculate timings on change of attribute register 0x11
(overscan border color) too. */
if (ega->attraddr == 0x10) {
if (o != val)
ega_recalctimings(ega);
} else if (ega->attraddr == 0x11) {
ega->overscan_color = ega->vres ? pallook16[val & 0x0f] : pallook64[val & 0x3f];
if (o != val)
ega_recalctimings(ega);
} else if (ega->attraddr == 0x12)
ega->plane_mask = val & 0xf;
}
ega->attrff ^= 1;
break;
case 0x3c2:
o = ega->miscout;
egaswitchread = (val & 0xc) >> 2;
ega->vres = !(val & 0x80);
ega->pallook = ega->vres ? pallook16 : pallook64;
ega->vidclock = val & 4;
ega->miscout = val;
ega->overscan_color = ega->vres ? pallook16[ega->attrregs[0x11] & 0x0f] : pallook64[ega->attrregs[0x11] & 0x3f];
io_removehandler(0x03a0, 0x0020, ega_in, NULL, NULL, ega_out, NULL, NULL, ega);
if (!(val & 1))
io_sethandler(0x03a0, 0x0020, ega_in, NULL, NULL, ega_out, NULL, NULL, ega);
ega_recalctimings(ega);
2022-08-31 19:19:29 -04:00
break;
case 0x3c4:
ega->seqaddr = val;
break;
case 0x3c5:
o = ega->seqregs[ega->seqaddr & 0xf];
ega->seqregs[ega->seqaddr & 0xf] = val;
if (o != val && (ega->seqaddr & 0xf) == 1)
ega_recalctimings(ega);
switch (ega->seqaddr & 0xf) {
case 1:
if (ega->scrblank && !(val & 0x20))
ega->fullchange = 3;
ega->scrblank = (ega->scrblank & ~0x20) | (val & 0x20);
break;
case 2:
ega->writemask = val & 0xf;
break;
case 3:
ega->charsetb = (((val >> 2) & 3) * 0x10000) + 2;
ega->charseta = ((val & 3) * 0x10000) + 2;
break;
case 4:
ega->chain2_write = !(val & 4);
break;
2023-07-31 14:43:33 -04:00
default:
break;
2022-08-31 19:19:29 -04:00
}
break;
case 0x3c6:
if (ega_type == 2)
ega->ctl_mode = val;
break;
2022-08-31 19:19:29 -04:00
case 0x3ce:
ega->gdcaddr = val;
break;
case 0x3cf:
ega->gdcreg[ega->gdcaddr & 15] = val;
switch (ega->gdcaddr & 15) {
case 2:
ega->colourcompare = val;
break;
case 4:
ega->readplane = val & 3;
break;
case 5:
ega->writemode = val & 3;
ega->readmode = val & 8;
ega->chain2_read = val & 0x10;
break;
case 6:
switch (val & 0xc) {
case 0x0: /*128k at A0000*/
mem_mapping_set_addr(&ega->mapping, 0xa0000, 0x20000);
break;
case 0x4: /*64k at A0000*/
mem_mapping_set_addr(&ega->mapping, 0xa0000, 0x10000);
break;
case 0x8: /*32k at B0000*/
mem_mapping_set_addr(&ega->mapping, 0xb0000, 0x08000);
break;
case 0xC: /*32k at B8000*/
mem_mapping_set_addr(&ega->mapping, 0xb8000, 0x08000);
break;
2023-07-31 14:43:33 -04:00
default:
break;
2022-08-31 19:19:29 -04:00
}
break;
case 7:
ega->colournocare = val;
break;
2023-07-31 14:43:33 -04:00
default:
break;
2022-08-31 19:19:29 -04:00
}
break;
case 0x3d0:
case 0x3d4:
if (ega->chipset)
ega->crtcreg = val & 0x3f;
else
ega->crtcreg = val & 0x1f;
2022-08-31 19:19:29 -04:00
return;
case 0x3d1:
case 0x3d5:
if (ega->chipset) {
if ((ega->crtcreg < 7) && (ega->crtc[0x11] & 0x80) && !(ega->regs[0xb4] & 0x80))
return;
if ((ega->crtcreg == 7) && (ega->crtc[0x11] & 0x80) && !(ega->regs[0xb4] & 0x80))
val = (ega->crtc[7] & ~0x10) | (val & 0x10);
} else {
if ((ega->crtcreg < 7) && (ega->crtc[0x11] & 0x80))
return;
if ((ega->crtcreg == 7) && (ega->crtc[0x11] & 0x80))
val = (ega->crtc[7] & ~0x10) | (val & 0x10);
}
2022-08-31 19:19:29 -04:00
old = ega->crtc[ega->crtcreg];
ega->crtc[ega->crtcreg] = val;
if (old != val) {
if (ega->crtcreg < 0xe || ega->crtcreg > 0x10) {
if ((ega->crtcreg == 0xc) || (ega->crtcreg == 0xd)) {
ega->fullchange = 3;
ega->ma_latch = ((ega->crtc[0xc] << 8) | ega->crtc[0xd]) + ((ega->crtc[8] & 0x60) >> 5);
} else {
ega->fullchange = changeframecount;
ega_recalctimings(ega);
}
}
}
break;
2023-07-31 14:43:33 -04:00
default:
break;
}
}
2021-12-08 22:43:23 +01:00
uint8_t
2023-06-09 23:46:54 -04:00
ega_in(uint16_t addr, void *priv)
{
2023-06-09 23:46:54 -04:00
ega_t *ega = (ega_t *) priv;
uint8_t ret = 0xff;
2022-02-20 02:26:27 -05:00
if (((addr & 0xfff0) == 0x3d0 || (addr & 0xfff0) == 0x3b0) && !(ega->miscout & 1))
2022-08-31 19:19:29 -04:00
addr ^= 0x60;
switch (addr) {
case 0x1ce:
ret = ega->index;
break;
case 0x1cf:
switch (ega->index) {
case 0xb7:
ret = ega->regs[ega->index] & ~8;
if (ati_eeprom_read((ati_eeprom_t *) ega->eeprom))
ret |= 8;
break;
default:
ret = ega->regs[ega->index];
break;
}
break;
2022-08-31 19:19:29 -04:00
case 0x3c0:
if (ega_type == 1)
2022-08-31 19:19:29 -04:00
ret = ega->attraddr | ega->attr_palette_enable;
break;
case 0x3c1:
if (ega_type == 1)
2022-08-31 19:19:29 -04:00
ret = ega->attrregs[ega->attraddr];
break;
case 0x3c2:
ret = (egaswitches & (8 >> egaswitchread)) ? 0x10 : 0x00;
break;
2022-08-31 19:19:29 -04:00
case 0x3c4:
if (ega_type == 1)
2022-08-31 19:19:29 -04:00
ret = ega->seqaddr;
break;
case 0x3c5:
if (ega_type == 1)
2022-08-31 19:19:29 -04:00
ret = ega->seqregs[ega->seqaddr & 0xf];
break;
case 0x3c6:
if (ega_type == 2)
ret = ega->ctl_mode;
break;
2022-08-31 19:19:29 -04:00
case 0x3c8:
if (ega_type == 1)
2022-08-31 19:19:29 -04:00
ret = 2;
break;
case 0x3cc:
if (ega_type == 1)
2022-08-31 19:19:29 -04:00
ret = ega->miscout;
break;
case 0x3ce:
if (ega_type == 1)
2022-08-31 19:19:29 -04:00
ret = ega->gdcaddr;
break;
case 0x3cf:
if (ega_type == 1)
2022-08-31 19:19:29 -04:00
ret = ega->gdcreg[ega->gdcaddr & 0xf];
break;
case 0x3d0:
case 0x3d4:
if (ega_type == 1)
2022-08-31 19:19:29 -04:00
ret = ega->crtcreg;
break;
case 0x3d1:
case 0x3d5:
2023-07-31 14:43:33 -04:00
switch (ega->crtcreg) {
case 0xc:
case 0xd:
case 0xe:
case 0xf:
ret = ega->crtc[ega->crtcreg];
break;
case 0x10:
if (ega_type == 1)
ret = ega->crtc[ega->crtcreg];
else
ret = ega->light_pen >> 8;
break;
case 0x11:
if (ega_type == 1)
ret = ega->crtc[ega->crtcreg];
else
ret = ega->light_pen & 0xff;
break;
default:
if (ega_type == 1)
ret = ega->crtc[ega->crtcreg];
break;
}
2022-08-31 19:19:29 -04:00
break;
case 0x3da:
ega->attrff = 0;
if (ega_type == 2) {
ret = ega->stat & 0xcf;
switch ((ega->attrregs[0x12] >> 4) & 0x03) {
case 0x00:
/* 00 = Pri. Red (5), Pri. Blue (4) */
ret |= (ega->color_mux & 0x04) ? 0x20 : 0x00;
ret |= (ega->color_mux & 0x01) ? 0x10 : 0x00;
break;
case 0x01:
case 0x03:
/* 01 = Sec. Red (5), Sec. Green (4) */
/* 11 = Sec. Red (5), Sec. Green (4) */
ret |= (ega->color_mux & 0x20) ? 0x20 : 0x00;
ret |= (ega->color_mux & 0x10) ? 0x10 : 0x00;
break;
case 0x02:
/* 10 = Sec. Blue (5), Pri. Green (4) */
ret |= (ega->color_mux & 0x08) ? 0x20 : 0x00;
ret |= (ega->color_mux & 0x02) ? 0x10 : 0x00;
break;
}
} else {
ega->stat ^= 0x30; /* Fools IBM EGA video BIOS self-test. */
ret = ega->stat;
}
2022-08-31 19:19:29 -04:00
break;
case 0x7c6:
ret = 0xfd; /* EGA mode supported. */
break;
case 0xbc6:
/* 0000 = None;
0001 = Compaq Dual-Mode (DM) Monitor;
0010 = RGBI Color Monitor;
2023-08-11 20:32:56 -04:00
0011 = COMPAQ Color Monitor (RrGgBb) or Compatible;
0100 - 1111 = Reserved. */
ret = 0x01;
break;
case 0xfc6:
ret = 0xfd;
break;
2023-07-31 14:43:33 -04:00
default:
break;
}
return ret;
}
void
ega_recalctimings(ega_t *ega)
{
int clksel;
int color;
2023-06-01 18:32:25 -04:00
double _dispontime;
double _dispofftime;
double disptime;
double crtcconst;
2022-08-31 19:19:29 -04:00
ega->vtotal = ega->crtc[6];
ega->dispend = ega->crtc[0x12];
ega->vsyncstart = ega->crtc[0x10];
2022-08-31 19:19:29 -04:00
ega->split = ega->crtc[0x18];
2022-08-31 19:19:29 -04:00
if (ega->crtc[7] & 1)
ega->vtotal |= 0x100;
if (ega->crtc[7] & 32)
ega->vtotal |= 0x200;
ega->vtotal += 2;
2022-08-31 19:19:29 -04:00
if (ega->crtc[7] & 2)
ega->dispend |= 0x100;
if (ega->crtc[7] & 64)
ega->dispend |= 0x200;
ega->dispend++;
2022-08-31 19:19:29 -04:00
if (ega->crtc[7] & 4)
ega->vsyncstart |= 0x100;
if (ega->crtc[7] & 128)
ega->vsyncstart |= 0x200;
ega->vsyncstart++;
2022-08-31 19:19:29 -04:00
if (ega->crtc[7] & 0x10)
ega->split |= 0x100;
if (ega->crtc[9] & 0x40)
ega->split |= 0x200;
ega->split++;
ega->hdisp = ega->crtc[1];
ega->hdisp++;
ega->rowoffset = ega->crtc[0x13];
2022-08-31 19:19:29 -04:00
ega->linedbl = ega->crtc[9] & 0x80;
ega->rowcount = ega->crtc[9] & 0x1f;
if (ega_type == 2) {
color = (ega->miscout & 1);
clksel = ((ega->miscout & 0xc) >> 2);
if (color) {
if (ega->vidclock)
crtcconst = (cpuclock / 16257000.0 * (double) (1ULL << 32));
else
crtcconst = (cpuclock / (157500000.0 / 11.0) * (double) (1ULL << 32));
} else {
if (ega->vidclock)
crtcconst = (cpuclock / 18981000.0 * (double) (1ULL << 32));
else
crtcconst = (cpuclock / 16872000.0 * (double) (1ULL << 32));
}
if (!(ega->seqregs[1] & 1))
crtcconst *= 9.0;
else
crtcconst *= 8.0;
} else if (ega->eeprom) {
clksel = ((ega->miscout & 0xc) >> 2) | ((ega->regs[0xbe] & 0x10) ? 4 : 0);
switch (clksel) {
case 0:
crtcconst = (cpuclock / 25175000.0 * (double) (1ULL << 32));
break;
case 1:
crtcconst = (cpuclock / 28322000.0 * (double) (1ULL << 32));
break;
case 4:
crtcconst = (cpuclock / 14318181.0 * (double) (1ULL << 32));
break;
case 5:
crtcconst = (cpuclock / 16257000.0 * (double) (1ULL << 32));
break;
case 7:
default:
crtcconst = (cpuclock / 36000000.0 * (double) (1ULL << 32));
break;
}
if (!(ega->seqregs[1] & 1))
crtcconst *= 9.0;
else
crtcconst *= 8.0;
} else {
2022-08-31 19:19:29 -04:00
if (ega->vidclock)
crtcconst = (ega->seqregs[1] & 1) ? MDACONST : (MDACONST * (9.0 / 8.0));
else
crtcconst = (ega->seqregs[1] & 1) ? CGACONST : (CGACONST * (9.0 / 8.0));
}
if (!(ega->seqregs[1] & 1))
ega->dot_clock = crtcconst / 9.0;
else
ega->dot_clock = crtcconst / 8.0;
ega->interlace = 0;
ega->ma_latch = (ega->crtc[0xc] << 8) | ega->crtc[0xd];
ega->render = ega_render_blank;
if (!ega->scrblank && ega->attr_palette_enable) {
2022-08-31 19:19:29 -04:00
if (!(ega->gdcreg[6] & 1)) {
2023-03-23 17:06:12 +13:00
if (ega->seqregs[1] & 8)
2022-08-31 19:19:29 -04:00
ega->hdisp *= (ega->seqregs[1] & 1) ? 16 : 18;
2023-03-23 17:06:12 +13:00
else
2022-08-31 19:19:29 -04:00
ega->hdisp *= (ega->seqregs[1] & 1) ? 8 : 9;
2023-07-31 14:43:33 -04:00
ega->render = ega_render_text;
2022-08-31 19:19:29 -04:00
ega->hdisp_old = ega->hdisp;
} else {
ega->hdisp *= (ega->seqregs[1] & 8) ? 16 : 8;
2023-07-31 14:43:33 -04:00
ega->render = ega_render_graphics;
2022-08-31 19:19:29 -04:00
ega->hdisp_old = ega->hdisp;
}
}
if (ega->chipset) {
if (ega->hdisp > 640) {
ega->dispend <<= 1;
ega->vtotal <<= 1;
ega->split <<= 1;
ega->vsyncstart <<= 1;
}
}
overscan_y = (ega->rowcount + 1) << 1;
if (overscan_y < 16)
overscan_y = 16;
overscan_x = (ega->seqregs[1] & 1) ? 16 : 18;
if (ega->vres)
overscan_y <<= 1;
2022-02-20 02:26:27 -05:00
if (ega->seqregs[1] & 8)
2022-08-31 19:19:29 -04:00
overscan_x <<= 1;
ega->y_add = (overscan_y >> 1);
ega->x_add = (overscan_x >> 1) - ega->scrollcache;
if (ega->vres)
ega->y_add >>= 1;
if (ega->seqregs[1] & 8) {
2022-08-31 19:19:29 -04:00
disptime = (double) ((ega->crtc[0] + 2) << 1);
_dispontime = (double) ((ega->crtc[1] + 1) << 1);
} else {
2022-08-31 19:19:29 -04:00
disptime = (double) (ega->crtc[0] + 2);
_dispontime = (double) (ega->crtc[1] + 1);
}
_dispofftime = disptime - _dispontime;
_dispontime *= crtcconst;
_dispofftime *= crtcconst;
2022-08-31 19:19:29 -04:00
ega->dispontime = (uint64_t) (_dispontime);
ega->dispofftime = (uint64_t) (_dispofftime);
if (ega->dispontime < TIMER_USEC)
2022-08-31 19:19:29 -04:00
ega->dispontime = TIMER_USEC;
if (ega->dispofftime < TIMER_USEC)
2022-08-31 19:19:29 -04:00
ega->dispofftime = TIMER_USEC;
ega->dot_time = (uint64_t) (ega->dot_clock);
if (ega->dot_time < TIMER_USEC)
ega->dot_time = TIMER_USEC;
ega_recalc_remap_func(ega);
}
/* This is needed for the Compaq EGA so that it can pass the 3DA
palette mux part of the self-test. */
void
ega_dot_poll(void *priv)
{
ega_t *ega = (ega_t *) priv;
static uint8_t chr;
static uint8_t attr;
const bool doublewidth = ((ega->seqregs[1] & 8) != 0);
const bool attrblink = ((ega->attrregs[0x10] & 8) != 0);
const bool attrlinechars = (ega->attrregs[0x10] & 4);
const bool crtcreset = ((ega->crtc[0x17] & 0x80) == 0);
const bool seq9dot = ((ega->seqregs[1] & 1) == 0);
const bool blinked = ega->blink & 0x10;
const int dwshift = doublewidth ? 1 : 0;
const int dotwidth = 1 << dwshift;
const int charwidth = dotwidth * (seq9dot ? 9 : 8);
const int cursoron = (ega->sc == (ega->crtc[10] & 31));
const int cursoraddr = (ega->crtc[0xe] << 8) | ega->crtc[0xf];
uint32_t addr;
int drawcursor;
uint32_t charaddr;
static int fg;
static int bg;
static uint32_t dat;
static int disptime;
static int _dispontime;
static int _dispofftime;
static int cclock = 0;
static int active = 0;
if (ega->seqregs[1] & 8) {
disptime = ((ega->crtc[0] + 2) << 1);
_dispontime = ((ega->crtc[1] + 1) << 1);
} else {
disptime = (ega->crtc[0] + 2);
_dispontime = (ega->crtc[1] + 1);
}
_dispofftime = disptime - _dispontime;
timer_advance_u64(&ega->dot_timer, ega->dot_time);
if (ega->render == ega_render_text)
ega->color_mux = (dat & (0x100 >> (ega->dot >> dwshift))) ? fg : bg;
else
ega->color_mux = 0x00;
addr = ega->remap_func(ega, ega->cca) & ega->vrammask;
if (!crtcreset) {
chr = ega->vram[addr];
attr = ega->vram[addr + 1];
} else
chr = attr = 0;
drawcursor = ((ega->cca == cursoraddr) && cursoron && ega->cursoron);
if (attr & 8)
charaddr = ega->charsetb + (chr * 0x80);
else
charaddr = ega->charseta + (chr * 0x80);
dat = ega->vram[charaddr + (ega->sc << 2)];
dat <<= 1;
if ((chr & ~0x1F) == 0xC0 && attrlinechars)
dat |= (dat >> 1) & 1;
if (!active)
dat = 0x200;
if (drawcursor) {
bg = ega->egapal[attr & 0x0f];
fg = ega->egapal[attr >> 4];
} else {
fg = ega->egapal[attr & 0x0f];
bg = ega->egapal[attr >> 4];
if ((attr & 0x80) && attrblink) {
bg = ega->egapal[(attr >> 4) & 7];
if (blinked)
fg = bg;
}
}
ega->dot = (ega->dot + 1) % charwidth;
if (ega->dot == 0) {
ega->cca = (ega->cca + 4) & 0x3ffff;
cclock++;
if (active && (cclock == _dispofftime))
active = 0;
else if (!active && (cclock == _dispontime))
active = 1;
}
}
void
2023-06-09 23:46:54 -04:00
ega_poll(void *priv)
{
2023-06-09 23:46:54 -04:00
ega_t *ega = (ega_t *) priv;
2024-01-09 17:20:31 +13:00
int x, y;
2023-06-01 18:32:25 -04:00
int old_ma;
int wx = 640;
int wy = 350;
uint32_t blink_delay;
if (!ega->linepos) {
2022-08-31 19:19:29 -04:00
timer_advance_u64(&ega->timer, ega->dispofftime);
ega->stat |= 1;
ega->linepos = 1;
if (ega->dispon) {
ega->hdisp_on = 1;
ega->ma &= ega->vrammask;
if (ega->firstline == 2000) {
ega->firstline = ega->displine;
video_wait_for_buffer();
}
2024-01-09 17:20:31 +13:00
old_ma = ega->ma;
ega->displine *= ega->vres + 1;
ega->y_add *= ega->vres + 1;
for (y = 0; y <= ega->vres; y++) {
/* Render scanline */
2022-08-31 19:19:29 -04:00
ega->render(ega);
2024-01-09 17:20:31 +13:00
/* Render overscan */
2022-08-31 19:19:29 -04:00
ega->x_add = (overscan_x >> 1);
ega_render_overscan_left(ega);
ega_render_overscan_right(ega);
ega->x_add = (overscan_x >> 1) - ega->scrollcache;
2024-01-09 17:20:31 +13:00
if (y != ega->vres) {
ega->ma = old_ma;
ega->displine++;
}
2022-08-31 19:19:29 -04:00
}
2024-01-09 17:20:31 +13:00
ega->displine /= ega->vres + 1;
ega->y_add /= ega->vres + 1;
2022-08-31 19:19:29 -04:00
if (ega->lastline < ega->displine)
ega->lastline = ega->displine;
}
ega->displine++;
if (ega->interlace)
ega->displine++;
if ((ega->stat & 8) && ((ega->displine & 15) == (ega->crtc[0x11] & 15)) && ega->vslines)
ega->stat &= ~8;
ega->vslines++;
if (ega->chipset) {
if (ega->hdisp > 640) {
if (ega->displine > 2000)
ega->displine = 0;
} else {
if (ega->displine > 500)
ega->displine = 0;
}
} else {
if (ega->displine > 500)
ega->displine = 0;
}
} else {
2022-08-31 19:19:29 -04:00
timer_advance_u64(&ega->timer, ega->dispontime);
if (ega->dispon)
ega->stat &= ~1;
ega->hdisp_on = 0;
ega->linepos = 0;
if ((ega->sc == (ega->crtc[11] & 31)) || (ega->sc == ega->rowcount))
ega->con = 0;
if (ega->dispon) {
/* TODO: Verify real hardware behaviour for out-of-range fine vertical scroll */
2022-08-31 19:19:29 -04:00
if (ega->linedbl && !ega->linecountff) {
ega->linecountff = 1;
ega->ma = ega->maback;
ega->cca = ega->maback;
2022-08-31 19:19:29 -04:00
}
if (ega->sc == (ega->crtc[9] & 31)) {
ega->linecountff = 0;
ega->sc = 0;
ega->maback += (ega->rowoffset << 3);
if (ega->interlace)
ega->maback += (ega->rowoffset << 3);
ega->maback &= ega->vrammask;
ega->ma = ega->maback;
ega->cca = ega->maback;
2022-08-31 19:19:29 -04:00
} else {
ega->linecountff = 0;
ega->sc++;
ega->sc &= 31;
ega->ma = ega->maback;
ega->cca = ega->maback;
2022-08-31 19:19:29 -04:00
}
}
ega->vc++;
if (ega->chipset) {
if (ega->hdisp > 640)
ega->vc &= 1023;
else
ega->vc &= 511;
} else
ega->vc &= 511;
2022-08-31 19:19:29 -04:00
if (ega->vc == ega->split) {
// TODO: Implement the hardware bug where the first scanline is drawn twice when the split happens
2022-08-31 19:19:29 -04:00
if (ega->interlace && ega->oddeven)
ega->ma = ega->maback = ega->rowoffset << 1;
2022-08-31 19:19:29 -04:00
else
ega->ma = ega->maback = 0;
2022-08-31 19:19:29 -04:00
ega->ma <<= 2;
ega->cca = ega->ma;
2022-08-31 19:19:29 -04:00
ega->maback <<= 2;
ega->sc = 0;
}
if (ega->vc == ega->dispend) {
ega->dispon = 0;
blink_delay = (ega->crtc[11] & 0x60) >> 5;
if (ega->crtc[10] & 0x20)
ega->cursoron = 0;
else if (blink_delay == 2)
ega->cursoron = ((ega->blink % 96) >= 48);
else
ega->cursoron = ega->blink & (16 + (16 * blink_delay));
if (!(ega->gdcreg[6] & 1) && !(ega->blink & 15))
ega->fullchange = 2;
ega->blink = (ega->blink + 1) & 0x7f;
if (ega->fullchange)
ega->fullchange--;
}
if (ega->vc == ega->vsyncstart) {
ega->dispon = 0;
ega->stat |= 8;
2023-08-21 20:25:05 -04:00
#if 0
picint(1 << 2);
#endif
2022-08-31 19:19:29 -04:00
x = ega->hdisp;
if (ega->interlace && !ega->oddeven)
ega->lastline++;
if (ega->interlace && ega->oddeven)
ega->firstline--;
wx = x;
if (ega->vres) {
wy = (ega->lastline - ega->firstline) << 1;
ega_doblit(wx, wy, ega);
} else {
wy = ega->lastline - ega->firstline;
ega_doblit(wx, wy, ega);
}
frames++;
ega->firstline = 2000;
ega->lastline = 0;
ega->firstline_draw = 2000;
ega->lastline_draw = 0;
ega->oddeven ^= 1;
changeframecount = ega->interlace ? 3 : 2;
ega->vslines = 0;
if (ega->interlace && ega->oddeven)
ega->ma = ega->maback = ega->ma_latch + (ega->rowoffset << 1);
else
ega->ma = ega->maback = ega->ma_latch;
ega->ca = (ega->crtc[0xe] << 8) | ega->crtc[0xf];
ega->ma <<= 2;
ega->maback <<= 2;
ega->ca <<= 2;
ega->cca = ega->ma;
2022-08-31 19:19:29 -04:00
}
if (ega->vc == ega->vtotal) {
ega->vc = 0;
ega->sc = (ega->crtc[0x8] & 0x1f);
2022-08-31 19:19:29 -04:00
ega->dispon = 1;
ega->displine = (ega->interlace && ega->oddeven) ? 1 : 0;
ega->scrollcache = (ega->attrregs[0x13] & 0x0f);
2024-01-09 17:20:31 +13:00
if (ega->scrollcache >= 0x8)
ega->scrollcache = 0;
else
ega->scrollcache++;
2022-08-31 19:19:29 -04:00
if (ega->seqregs[1] & 8)
ega->scrollcache <<= 1;
ega->x_add = (overscan_x >> 1) - ega->scrollcache;
ega->linecountff = 0;
}
if (ega->sc == (ega->crtc[10] & 31))
ega->con = 1;
}
}
void
ega_doblit(int wx, int wy, ega_t *ega)
{
int unscaled_overscan_y = ega->vres ? overscan_y >> 1 : overscan_y;
int y_add = enable_overscan ? unscaled_overscan_y : 0;
2023-06-01 18:32:25 -04:00
int x_add = enable_overscan ? overscan_x : 0;
int y_start = enable_overscan ? 0 : (unscaled_overscan_y >> 1);
2023-06-01 18:32:25 -04:00
int x_start = enable_overscan ? 0 : (overscan_x >> 1);
int bottom = (unscaled_overscan_y >> 1);
uint32_t *p;
2023-06-01 18:32:25 -04:00
int i;
int j;
int xs_temp;
int ys_temp;
if (ega->vres) {
2022-08-31 19:19:29 -04:00
y_add <<= 1;
y_start <<= 1;
bottom <<= 1;
}
if ((wx <= 0) || (wy <= 0))
2022-08-31 19:19:29 -04:00
return;
if (ega->vres)
2022-08-31 19:19:29 -04:00
ega->y_add <<= 1;
xs_temp = wx;
ys_temp = wy + 1;
if (ega->vres)
2022-08-31 19:19:29 -04:00
ys_temp++;
if (xs_temp < 64)
2022-08-31 19:19:29 -04:00
xs_temp = 640;
if (ys_temp < 32)
2022-08-31 19:19:29 -04:00
ys_temp = 200;
if ((ega->crtc[0x17] & 0x80) && ((xs_temp != xsize) || (ys_temp != ysize) || video_force_resize_get())) {
2022-08-31 19:19:29 -04:00
/* Screen res has changed.. fix up, and let them know. */
xsize = xs_temp;
ysize = ys_temp;
if ((xsize > 1984) || (ysize > 2016)) {
/* 2048x2048 is the biggest safe render texture, to account for overscan,
we suppress overscan starting from x 1984 and y 2016. */
x_add = 0;
y_add = 0;
suppress_overscan = 1;
} else
suppress_overscan = 0;
set_screen_size(xsize + x_add, ysize + y_add);
if (video_force_resize_get())
video_force_resize_set(0);
}
if ((wx >= 160) && ((wy + 1) >= 120)) {
2022-08-31 19:19:29 -04:00
/* Draw (overscan_size - scroll size) lines of overscan on top and bottom. */
for (i = 0; i < ega->y_add; i++) {
p = &buffer32->line[i & 0x7ff][0];
2022-08-31 19:19:29 -04:00
for (j = 0; j < (xsize + x_add); j++)
p[j] = ega->overscan_color;
}
2022-08-31 19:19:29 -04:00
for (i = 0; i < bottom; i++) {
p = &buffer32->line[(ysize + ega->y_add + i) & 0x7ff][0];
2022-08-31 19:19:29 -04:00
for (j = 0; j < (xsize + x_add); j++)
p[j] = ega->overscan_color;
}
}
video_blit_memtoscreen(x_start, y_start, xsize + x_add, ysize + y_add);
if (ega->vres)
2022-08-31 19:19:29 -04:00
ega->y_add >>= 1;
}
uint32_t
ega_remap_cpu_addr(uint32_t inaddr, ega_t *ega)
{
int a0mux;
uint32_t addr = inaddr;
// The CPU A0 line is multiplexed via a 3-to-8 mux.
// Input bits are:
// bit 0: 1 = 64K, 0 = 128K+ (from memory expansion connector)
// bit 1: 1 = Odd/Even mode, 0 = normal mode (from GC reg 6 bit 1)
// bit 2: 1 = 128K mapping, 0 = other mapping (from memory decode PROM)
a0mux = 0;
if (ega->gdcreg[6] & 2) {
a0mux |= 2;
}
2023-07-31 14:43:33 -04:00
if (ega->vram_limit <= 64 * 1024) {
a0mux |= 1;
}
2023-06-01 18:32:25 -04:00
switch (ega->gdcreg[6] & 0xC) {
case 0x0: // 128K A000
addr &= 0xFFFF;
// TODO: Confirm the behaviour of this on actual hardware
a0mux |= 4;
break;
case 0x4: // 64K A000
addr &= 0xFFFF;
break;
case 0x8: // 32K B000
addr &= 0x7FFF;
break;
case 0xC: // 32K B800
addr &= 0x7FFF;
break;
2023-07-31 14:43:33 -04:00
default:
break;
}
switch (a0mux) {
case 0:
case 1:
case 4:
case 5:
case 7: // A0 becomes A0
break;
case 2:
// A0 becomes the inversion of PGSEL (reg 0x3C2, miscout, bit 5)
// That is, 1 selects the "low" 64k, and 0 selects the "high" 64k.
addr &= ~1;
2023-07-31 14:43:33 -04:00
addr |= (~ega->miscout >> 5) & 1;
break;
case 3: // A0 becomes A14
addr &= ~1;
2023-07-31 14:43:33 -04:00
addr |= (inaddr >> 14) & 1;
break;
case 6: // A0 becomes A16
addr &= ~1;
2023-07-31 14:43:33 -04:00
addr |= (inaddr >> 16) & 1;
break;
default:
break;
}
// In 64k mode, only select the first 16Kword/64KB bank
if (!(ega->seqregs[4] & 2)) {
addr &= 0x3FFF;
}
return addr;
}
void
2023-06-09 23:46:54 -04:00
ega_write(uint32_t addr, uint8_t val, void *priv)
{
2023-06-09 23:46:54 -04:00
ega_t *ega = (ega_t *) priv;
2023-06-01 18:32:25 -04:00
uint8_t vala;
uint8_t valb;
uint8_t valc;
uint8_t vald;
2022-08-31 19:19:29 -04:00
int writemask2 = ega->writemask;
cycles -= video_timing_write_b;
if (ega->chain2_write) {
2022-08-31 19:19:29 -04:00
writemask2 &= ~0xa;
if (addr & 1)
writemask2 <<= 1;
}
addr = ega_remap_cpu_addr(addr, ega);
addr <<= 2;
if (addr >= ega->vram_limit)
2022-08-31 19:19:29 -04:00
return;
2022-02-20 02:26:27 -05:00
if (!(ega->gdcreg[6] & 1))
2022-08-31 19:19:29 -04:00
ega->fullchange = 2;
switch (ega->writemode) {
2022-08-31 19:19:29 -04:00
case 1:
if (writemask2 & 1)
ega->vram[addr] = ega->la;
if (writemask2 & 2)
ega->vram[addr | 0x1] = ega->lb;
if (writemask2 & 4)
ega->vram[addr | 0x2] = ega->lc;
if (writemask2 & 8)
ega->vram[addr | 0x3] = ega->ld;
break;
case 0:
if (ega->gdcreg[3] & 7)
val = ega_rotate[ega->gdcreg[3] & 7][val];
if ((ega->gdcreg[8] == 0xff) && !(ega->gdcreg[3] & 0x18) && !ega->gdcreg[1]) {
if (writemask2 & 1)
ega->vram[addr] = val;
if (writemask2 & 2)
ega->vram[addr | 0x1] = val;
if (writemask2 & 4)
ega->vram[addr | 0x2] = val;
if (writemask2 & 8)
ega->vram[addr | 0x3] = val;
} else {
if (ega->gdcreg[1] & 1)
vala = (ega->gdcreg[0] & 1) ? 0xff : 0;
else
vala = val;
if (ega->gdcreg[1] & 2)
valb = (ega->gdcreg[0] & 2) ? 0xff : 0;
else
valb = val;
if (ega->gdcreg[1] & 4)
valc = (ega->gdcreg[0] & 4) ? 0xff : 0;
else
valc = val;
if (ega->gdcreg[1] & 8)
vald = (ega->gdcreg[0] & 8) ? 0xff : 0;
else
vald = val;
switch (ega->gdcreg[3] & 0x18) {
case 0: /*Set*/
if (writemask2 & 1)
ega->vram[addr] = (vala & ega->gdcreg[8]) | (ega->la & ~ega->gdcreg[8]);
if (writemask2 & 2)
ega->vram[addr | 0x1] = (valb & ega->gdcreg[8]) | (ega->lb & ~ega->gdcreg[8]);
if (writemask2 & 4)
ega->vram[addr | 0x2] = (valc & ega->gdcreg[8]) | (ega->lc & ~ega->gdcreg[8]);
if (writemask2 & 8)
ega->vram[addr | 0x3] = (vald & ega->gdcreg[8]) | (ega->ld & ~ega->gdcreg[8]);
break;
case 8: /*AND*/
if (writemask2 & 1)
ega->vram[addr] = (vala | ~ega->gdcreg[8]) & ega->la;
if (writemask2 & 2)
ega->vram[addr | 0x1] = (valb | ~ega->gdcreg[8]) & ega->lb;
if (writemask2 & 4)
ega->vram[addr | 0x2] = (valc | ~ega->gdcreg[8]) & ega->lc;
if (writemask2 & 8)
ega->vram[addr | 0x3] = (vald | ~ega->gdcreg[8]) & ega->ld;
break;
case 0x10: /*OR*/
if (writemask2 & 1)
ega->vram[addr] = (vala & ega->gdcreg[8]) | ega->la;
if (writemask2 & 2)
ega->vram[addr | 0x1] = (valb & ega->gdcreg[8]) | ega->lb;
if (writemask2 & 4)
ega->vram[addr | 0x2] = (valc & ega->gdcreg[8]) | ega->lc;
if (writemask2 & 8)
ega->vram[addr | 0x3] = (vald & ega->gdcreg[8]) | ega->ld;
break;
case 0x18: /*XOR*/
if (writemask2 & 1)
ega->vram[addr] = (vala & ega->gdcreg[8]) ^ ega->la;
if (writemask2 & 2)
ega->vram[addr | 0x1] = (valb & ega->gdcreg[8]) ^ ega->lb;
if (writemask2 & 4)
ega->vram[addr | 0x2] = (valc & ega->gdcreg[8]) ^ ega->lc;
if (writemask2 & 8)
ega->vram[addr | 0x3] = (vald & ega->gdcreg[8]) ^ ega->ld;
break;
2023-07-31 14:43:33 -04:00
default:
break;
2022-08-31 19:19:29 -04:00
}
}
break;
case 2:
if (!(ega->gdcreg[3] & 0x18) && !ega->gdcreg[1]) {
if (writemask2 & 1)
ega->vram[addr] = (((val & 1) ? 0xff : 0) & ega->gdcreg[8]) | (ega->la & ~ega->gdcreg[8]);
if (writemask2 & 2)
ega->vram[addr | 0x1] = (((val & 2) ? 0xff : 0) & ega->gdcreg[8]) | (ega->lb & ~ega->gdcreg[8]);
if (writemask2 & 4)
ega->vram[addr | 0x2] = (((val & 4) ? 0xff : 0) & ega->gdcreg[8]) | (ega->lc & ~ega->gdcreg[8]);
if (writemask2 & 8)
ega->vram[addr | 0x3] = (((val & 8) ? 0xff : 0) & ega->gdcreg[8]) | (ega->ld & ~ega->gdcreg[8]);
} else {
vala = ((val & 1) ? 0xff : 0);
valb = ((val & 2) ? 0xff : 0);
valc = ((val & 4) ? 0xff : 0);
vald = ((val & 8) ? 0xff : 0);
switch (ega->gdcreg[3] & 0x18) {
case 0: /*Set*/
if (writemask2 & 1)
ega->vram[addr] = (vala & ega->gdcreg[8]) | (ega->la & ~ega->gdcreg[8]);
if (writemask2 & 2)
ega->vram[addr | 0x1] = (valb & ega->gdcreg[8]) | (ega->lb & ~ega->gdcreg[8]);
if (writemask2 & 4)
ega->vram[addr | 0x2] = (valc & ega->gdcreg[8]) | (ega->lc & ~ega->gdcreg[8]);
if (writemask2 & 8)
ega->vram[addr | 0x3] = (vald & ega->gdcreg[8]) | (ega->ld & ~ega->gdcreg[8]);
break;
case 8: /*AND*/
if (writemask2 & 1)
ega->vram[addr] = (vala | ~ega->gdcreg[8]) & ega->la;
if (writemask2 & 2)
ega->vram[addr | 0x1] = (valb | ~ega->gdcreg[8]) & ega->lb;
if (writemask2 & 4)
ega->vram[addr | 0x2] = (valc | ~ega->gdcreg[8]) & ega->lc;
if (writemask2 & 8)
ega->vram[addr | 0x3] = (vald | ~ega->gdcreg[8]) & ega->ld;
break;
case 0x10: /*OR*/
if (writemask2 & 1)
ega->vram[addr] = (vala & ega->gdcreg[8]) | ega->la;
if (writemask2 & 2)
ega->vram[addr | 0x1] = (valb & ega->gdcreg[8]) | ega->lb;
if (writemask2 & 4)
ega->vram[addr | 0x2] = (valc & ega->gdcreg[8]) | ega->lc;
if (writemask2 & 8)
ega->vram[addr | 0x3] = (vald & ega->gdcreg[8]) | ega->ld;
break;
case 0x18: /*XOR*/
if (writemask2 & 1)
ega->vram[addr] = (vala & ega->gdcreg[8]) ^ ega->la;
if (writemask2 & 2)
ega->vram[addr | 0x1] = (valb & ega->gdcreg[8]) ^ ega->lb;
if (writemask2 & 4)
ega->vram[addr | 0x2] = (valc & ega->gdcreg[8]) ^ ega->lc;
if (writemask2 & 8)
ega->vram[addr | 0x3] = (vald & ega->gdcreg[8]) ^ ega->ld;
break;
2023-07-31 14:43:33 -04:00
default:
break;
2022-08-31 19:19:29 -04:00
}
}
break;
2023-07-31 14:43:33 -04:00
default:
break;
}
}
uint8_t
2023-06-09 23:46:54 -04:00
ega_read(uint32_t addr, void *priv)
{
2023-06-09 23:46:54 -04:00
ega_t *ega = (ega_t *) priv;
2023-06-01 18:32:25 -04:00
uint8_t temp;
uint8_t temp2;
uint8_t temp3;
uint8_t temp4;
2022-08-31 19:19:29 -04:00
int readplane = ega->readplane;
cycles -= video_timing_read_b;
if (ega->chain2_read) {
2022-08-31 19:19:29 -04:00
readplane = (readplane & 2) | (addr & 1);
}
addr = ega_remap_cpu_addr(addr, ega);
addr <<= 2;
if (addr >= ega->vram_limit)
2022-08-31 19:19:29 -04:00
return 0xff;
ega->la = ega->vram[addr];
ega->lb = ega->vram[addr | 0x1];
ega->lc = ega->vram[addr | 0x2];
ega->ld = ega->vram[addr | 0x3];
if (ega->readmode) {
2022-08-31 19:19:29 -04:00
temp = ega->la;
temp ^= (ega->colourcompare & 1) ? 0xff : 0;
temp &= (ega->colournocare & 1) ? 0xff : 0;
temp2 = ega->lb;
temp2 ^= (ega->colourcompare & 2) ? 0xff : 0;
temp2 &= (ega->colournocare & 2) ? 0xff : 0;
temp3 = ega->lc;
temp3 ^= (ega->colourcompare & 4) ? 0xff : 0;
temp3 &= (ega->colournocare & 4) ? 0xff : 0;
temp4 = ega->ld;
temp4 ^= (ega->colourcompare & 8) ? 0xff : 0;
temp4 &= (ega->colournocare & 8) ? 0xff : 0;
return ~(temp | temp2 | temp3 | temp4);
}
return ega->vram[addr | readplane];
}
void
ega_init(ega_t *ega, int monitor_type, int is_mono)
{
2023-06-01 18:32:25 -04:00
int c;
int d;
int e;
2022-08-31 19:19:29 -04:00
ega->vram = malloc(0x40000);
ega->vrammask = 0x3ffff;
for (c = 0; c < 256; c++) {
2022-08-31 19:19:29 -04:00
e = c;
for (d = 0; d < 8; d++) {
ega_rotate[d][c] = e;
e = (e >> 1) | ((e & 1) ? 0x80 : 0);
}
}
if (is_mono) {
2022-08-31 19:19:29 -04:00
for (c = 0; c < 256; c++) {
if (((c >> 3) & 3) == 0)
pallook64[c] = pallook16[c] = makecol32(0, 0, 0);
else
switch (monitor_type >> 4) {
case DISPLAY_GREEN:
switch ((c >> 3) & 3) {
case 1:
pallook64[c] = pallook16[c] = makecol32(0x08, 0xc7, 0x2c);
break;
case 2:
pallook64[c] = pallook16[c] = makecol32(0x04, 0x8a, 0x20);
break;
case 3:
pallook64[c] = pallook16[c] = makecol32(0x34, 0xff, 0x5d);
break;
2023-07-31 14:43:33 -04:00
default:
break;
2022-08-31 19:19:29 -04:00
}
break;
case DISPLAY_AMBER:
switch ((c >> 3) & 3) {
case 1:
pallook64[c] = pallook16[c] = makecol32(0xef, 0x79, 0x00);
break;
case 2:
pallook64[c] = pallook16[c] = makecol32(0xb2, 0x4d, 0x00);
break;
case 3:
pallook64[c] = pallook16[c] = makecol32(0xff, 0xe3, 0x34);
break;
2023-07-31 14:43:33 -04:00
default:
break;
2022-08-31 19:19:29 -04:00
}
break;
case DISPLAY_WHITE:
default:
switch ((c >> 3) & 3) {
case 1:
pallook64[c] = pallook16[c] = makecol32(0xaf, 0xb3, 0xb0);
break;
case 2:
pallook64[c] = pallook16[c] = makecol32(0x7a, 0x81, 0x83);
break;
case 3:
pallook64[c] = pallook16[c] = makecol32(0xff, 0xfd, 0xed);
break;
2023-07-31 14:43:33 -04:00
default:
break;
2022-08-31 19:19:29 -04:00
}
break;
}
}
io_sethandler(0x03a0, 0x0020, ega_in, NULL, NULL, ega_out, NULL, NULL, ega);
} else {
2022-08-31 19:19:29 -04:00
for (c = 0; c < 256; c++) {
pallook64[c] = makecol32(((c >> 2) & 1) * 0xaa, ((c >> 1) & 1) * 0xaa, (c & 1) * 0xaa);
pallook64[c] += makecol32(((c >> 5) & 1) * 0x55, ((c >> 4) & 1) * 0x55, ((c >> 3) & 1) * 0x55);
pallook16[c] = makecol32(((c >> 2) & 1) * 0xaa, ((c >> 1) & 1) * 0xaa, (c & 1) * 0xaa);
pallook16[c] += makecol32(((c >> 4) & 1) * 0x55, ((c >> 4) & 1) * 0x55, ((c >> 4) & 1) * 0x55);
if ((c & 0x17) == 6)
pallook16[c] = makecol32(0xaa, 0x55, 0);
}
ega->miscout |= 1;
}
ega->pallook = pallook16;
egaswitches = monitor_type & 0xf;
ega->vram_limit = 256 * 1024;
2022-08-31 19:19:29 -04:00
ega->vrammask = ega->vram_limit - 1;
old_overscan_color = 0;
ega->miscout |= 0x22;
ega->oddeven_page = 0;
ega->seqregs[4] |= 2;
ega->extvram = 1;
update_overscan = 0;
ega->crtc[0] = 63;
ega->crtc[6] = 255;
Added the IBM 5161 ISA expansion for PC and XT; Cleaned up the parallel port emulation, added IRQ support, and made enabling/disabling per port; Added the Award 430NX and the Intel Classic/PCI (Alfredo, 420TX); Finished the 586MC1; Added 8087 emulation; Moved Cyrix 6x86'es to the Dev branch; Sanitized/cleaned up memregs.c/h and intel.c/h; Split the chipsets from machines and sanitized Port 92 emulation; Added support for the 15bpp mode to the Compaq ATI 28800; Moved the MR 386DX and 486 machines to the Dev branch; Ported the new dynamic recompiler from PCem, but it remains in Dev branch until after v2.00; Ported the new timer code from PCem; Cleaned up the CPU table of unused stuff and better optimized its structure; Ported the Open-XT and Open-AT from VARCem, the Open-AT is in the Dev branch; Ported the XT MFM controller rewrite and adding of more controllers (incl. two RLL ones), from VARCem; Added the AHA-1540A and the BusTek BT-542B; Moved the Sumo SCSI-AT to the Dev branch; Minor IDE, FDC, and floppy drive code clean-ups; Made NCR 5380/53C400-based cards' BIOS address configurable; Got rid of the legacy romset variable; Unified (video) buffer and buffer32 into one and make the unified buffer 32-bit; Added the Amstead PPC512 per PCem patch by John Elliott; Switched memory mapping granularity from 16k to 4k (less than 1k not possible due to internal pages); Rewrote the CL-GD 54xx blitter, fixes Win-OS/2 on the 54x6 among other thing; Added the Image Manager 1024 and Professional Graphics Controller per PCem patch by John Elliott and work done on VARCem; Added Headland HT-216, GC-205 and Video 7 VGA 1024i emulation based on PCem commit; Implemented the fuction keys for the Toshiba T1000/T1200/T3100 enhancement; Amstrad MegaPC does now works correctly with non-internal graphics card; The SLiRP code no longer casts a packed struct type to a non-packed struct type; The Xi8088 and PB410a no longer hang on 86Box when PS/2 mouse is not present; The S3 Virge on BeOS is no longer broken (was broken by build #1591); OS/2 2.0 build 6.167 now sees key presses again; Xi8088 now work on CGA again; 86F images converted from either the old or new variants of the HxC MFM format now work correctly; Hardware interrupts with a vector of 0xFF are now handled correctly; OPTi 495SX boards no longer incorrectly have 64 MB maximum RAM when 32 MB is correct; Fixed VNC keyboard input bugs; Fixed AT RTC periodic interrupt - Chicago 58s / 73f / 73g / 81 MIDI play no longer hangs with the build's own VTD driver; Fixed mouse polling with internal mice - Amstrad and Olivetti mice now work correctly; Triones ATAPI DMA driver now correctly reads a file at the end of a CD image with a sectors number not divisible by 4; Compaq Portable now works with all graphics cards; Fixed various MDSI Genius bugs; Added segment limit checks and improved page fault checks for several CPU instructions - Memphis 15xx WINSETUP and Chicago 58s WINDISK.CPL no longer issue a GPF, and some S3 drivers that used to have glitches, now work correctly; Further improved the 808x emulation, also fixes the noticably choppy sound when using 808x CPU's, also fixes #355; OS/2 installer no logner locks up on splash screen on PS/2 Model 70 and 80, fixes #400. Fixed several Amstead bugs, GEM no longer crashes on the Amstrad 1640, fixes #391. Ported John Elliott's Amstrad fixes and improvement from PCem, and fixed the default language so it's correctly Engliish, fixes #278, fixes #389. Fixed a minor IDE timing bug, fixes #388. Fixed Toshiba T1000 RAM issues, fixes #379. Fixed EGA/(S)VGA overscan border handling, fixes #378; Got rid of the now long useless IDE channel 2 auto-removal, fixes #370; Fixed the BIOS files used by the AMSTRAD PC1512, fixes #366; Ported the Unicode CD image file name fix from VARCem, fixes #365; Fixed high density floppy disks on the Xi8088, fixes #359; Fixed some bugs in the Hercules emulation, fixes #346, fixes #358; Fixed the SCSI hard disk mode sense pages, fixes #356; Removed the AMI Unknown 386SX because of impossibility to identify the chipset, closes #349; Fixed bugs in the serial mouse emulation, fixes #344; Compiled 86Box binaries now include all the required .DLL's, fixes #341; Made some combo boxes in the Settings dialog slightly wider, fixes #276.
2019-09-20 14:02:30 +02:00
timer_add(&ega->timer, ega_poll, ega, 1);
if (ega_type == 2)
timer_add(&ega->dot_timer, ega_dot_poll, ega, 1);
}
static void *
ega_standalone_init(const device_t *info)
{
ega_t *ega = malloc(sizeof(ega_t));
2023-06-01 18:32:25 -04:00
int monitor_type;
memset(ega, 0x00, sizeof(ega_t));
video_inform(VIDEO_FLAG_TYPE_SPECIAL, &timing_ega);
overscan_x = 16;
overscan_y = 28;
ega->x_add = 8;
ega->y_add = 14;
2022-08-31 19:19:29 -04:00
if ((info->local == EGA_IBM) || (info->local == EGA_ISKRA) || (info->local == EGA_TSENG))
ega_type = 0;
else if (info->local == EGA_COMPAQ)
ega_type = 2;
else
2022-08-31 19:19:29 -04:00
ega_type = 1;
ega->actual_type = info->local;
ega->chipset = 0;
2022-08-31 19:19:29 -04:00
switch (info->local) {
default:
2023-07-31 14:43:33 -04:00
case EGA_IBM:
2022-08-31 19:19:29 -04:00
rom_init(&ega->bios_rom, BIOS_IBM_PATH,
0xc0000, 0x8000, 0x7fff, 0, MEM_MAPPING_EXTERNAL);
break;
case EGA_COMPAQ:
ega->ctl_mode = 0x21;
2022-08-31 19:19:29 -04:00
rom_init(&ega->bios_rom, BIOS_CPQ_PATH,
0xc0000, 0x8000, 0x7fff, 0, MEM_MAPPING_EXTERNAL);
break;
case EGA_SUPEREGA:
rom_init(&ega->bios_rom, BIOS_SEGA_PATH,
0xc0000, 0x8000, 0x7fff, 0, MEM_MAPPING_EXTERNAL);
break;
case EGA_ATI800P:
rom_init(&ega->bios_rom, BIOS_ATIEGA800P_PATH,
0xc0000, 0x8000, 0x7fff, 0, MEM_MAPPING_EXTERNAL);
ega->chipset = 1;
break;
2022-08-31 19:19:29 -04:00
case EGA_ISKRA:
rom_init_interleaved(&ega->bios_rom, BIOS_ISKRA_PATH,
0xc0000, 0x8000, 0x7fff, 0, MEM_MAPPING_EXTERNAL);
break;
case EGA_TSENG:
rom_init(&ega->bios_rom, BIOS_TSENG_PATH,
0xc0000, 0x8000, 0x7fff, 0, MEM_MAPPING_EXTERNAL);
break;
}
if ((ega->bios_rom.rom[0x3ffe] == 0xaa) && (ega->bios_rom.rom[0x3fff] == 0x55)) {
2023-06-01 18:32:25 -04:00
for (uint16_t c = 0; c < 0x2000; c++) {
2022-08-31 19:19:29 -04:00
uint8_t temp = ega->bios_rom.rom[c];
ega->bios_rom.rom[c] = ega->bios_rom.rom[0x3fff - c];
ega->bios_rom.rom[0x3fff - c] = temp;
}
}
monitor_type = device_get_config_int("monitor_type");
ega_init(ega, monitor_type, (monitor_type & 0x0F) == 0x0B);
ega->vram_limit = device_get_config_int("memory") * 1024;
2022-08-31 19:19:29 -04:00
ega->vrammask = ega->vram_limit - 1;
mem_mapping_add(&ega->mapping, 0xa0000, 0x20000, ega_read, NULL, NULL, ega_write, NULL, NULL, NULL, MEM_MAPPING_EXTERNAL, ega);
2021-12-08 22:43:23 +01:00
io_sethandler(0x03c0, 0x0020, ega_in, NULL, NULL, ega_out, NULL, NULL, ega);
if (ega->chipset) {
io_sethandler(0x01ce, 0x0002, ega_in, NULL, NULL, ega_out, NULL, NULL, ega);
ega->eeprom = malloc(sizeof(ati_eeprom_t));
memset(ega->eeprom, 0, sizeof(ati_eeprom_t));
ati_eeprom_load((ati_eeprom_t *) ega->eeprom, "egawonder800p.nvr", 0);
} else if (info->local == EGA_COMPAQ) {
io_sethandler(0x0084, 0x0001, ega_in, NULL, NULL, ega_out, NULL, NULL, ega);
io_sethandler(0x07c6, 0x0001, ega_in, NULL, NULL, ega_out, NULL, NULL, ega);
io_sethandler(0x0bc6, 0x0001, ega_in, NULL, NULL, ega_out, NULL, NULL, ega);
io_sethandler(0x0fc6, 0x0001, ega_in, NULL, NULL, ega_out, NULL, NULL, ega);
}
return ega;
}
static int
ega_standalone_available(void)
{
return rom_present(BIOS_IBM_PATH);
}
static int
cpqega_standalone_available(void)
{
return rom_present(BIOS_CPQ_PATH);
}
static int
sega_standalone_available(void)
{
return rom_present(BIOS_SEGA_PATH);
}
static int
atiega800p_standalone_available(void)
{
return rom_present(BIOS_ATIEGA800P_PATH);
}
static int
iskra_ega_standalone_available(void)
{
return rom_present("roms/video/ega/143-02.bin") && rom_present("roms/video/ega/143-03.bin");
}
static int
et2000_standalone_available(void)
{
return rom_present(BIOS_TSENG_PATH);
}
static void
2023-06-09 23:46:54 -04:00
ega_close(void *priv)
{
2023-06-09 23:46:54 -04:00
ega_t *ega = (ega_t *) priv;
if (ega->eeprom)
free(ega->eeprom);
free(ega->vram);
free(ega);
}
static void
2023-06-09 23:46:54 -04:00
ega_speed_changed(void *priv)
{
2023-06-09 23:46:54 -04:00
ega_t *ega = (ega_t *) priv;
ega_recalctimings(ega);
}
/* SW1 SW2 SW3 SW4
2023-08-11 20:32:56 -04:00
OFF OFF ON OFF Monochrome (5151) 1011 0x0B
ON OFF OFF ON Color 40x25 (5153) 0110 0x06
OFF OFF OFF ON Color 80x25 (5153) 0111 0x07
ON ON ON OFF Enhanced Color - Normal Mode (5154) 1000 0x08
OFF ON ON OFF Enhanced Color - Enhanced Mode (5154) 1001 0x09
0 = Switch closed (ON);
1 = Switch open (OFF). */
2022-02-26 23:31:28 -05:00
static const device_config_t ega_config[] = {
2022-08-31 19:19:29 -04:00
// clang-format off
2022-02-26 23:31:28 -05:00
{
2022-04-09 20:09:14 -04:00
.name = "memory",
.description = "Memory size",
.type = CONFIG_SELECTION,
.default_int = 256,
.selection = {
{
.description = "32 kB",
.value = 32
},
{
.description = "64 kB",
.value = 64
},
{
.description = "128 kB",
.value = 128
},
{
.description = "256 kB",
.value = 256
},
{
.description = ""
}
}
2022-02-26 23:31:28 -05:00
},
{
.name = "monitor_type",
.description = "Monitor type",
.type = CONFIG_SELECTION,
.selection = {
{
.description = "Monochrome (5151/MDA) (white)",
.value = 0x0B | (DISPLAY_WHITE << 4)
},
{
.description = "Monochrome (5151/MDA) (green)",
.value = 0x0B | (DISPLAY_GREEN << 4)
},
{
.description = "Monochrome (5151/MDA) (amber)",
.value = 0x0B | (DISPLAY_AMBER << 4)
},
{
.description = "Color 40x25 (5153/CGA)",
.value = 0x06
},
{
.description = "Color 80x25 (5153/CGA)",
.value = 0x07
},
{
.description = "Enhanced Color - Normal Mode (5154/ECD)",
.value = 0x08
},
{
.description = "Enhanced Color - Enhanced Mode (5154/ECD)",
.value = 0x09
},
{
.description = ""
}
},
.default_int = 9
},
{
2022-04-09 20:09:14 -04:00
.type = CONFIG_END
2022-02-26 23:31:28 -05:00
}
2022-11-19 08:49:04 -05:00
// clang-format on
};
2022-03-13 21:43:45 -04:00
const device_t ega_device = {
.name = "IBM EGA",
2022-03-13 21:43:45 -04:00
.internal_name = "ega",
2022-08-31 19:19:29 -04:00
.flags = DEVICE_ISA,
.local = EGA_IBM,
.init = ega_standalone_init,
.close = ega_close,
.reset = NULL,
2022-03-13 21:43:45 -04:00
{ .available = ega_standalone_available },
.speed_changed = ega_speed_changed,
2022-08-31 19:19:29 -04:00
.force_redraw = NULL,
.config = ega_config
};
2022-03-13 21:43:45 -04:00
const device_t cpqega_device = {
2022-08-31 19:19:29 -04:00
.name = "Compaq EGA",
2022-03-13 21:43:45 -04:00
.internal_name = "compaq_ega",
2022-08-31 19:19:29 -04:00
.flags = DEVICE_ISA,
.local = EGA_COMPAQ,
.init = ega_standalone_init,
.close = ega_close,
.reset = NULL,
2022-03-13 21:43:45 -04:00
{ .available = cpqega_standalone_available },
.speed_changed = ega_speed_changed,
2022-08-31 19:19:29 -04:00
.force_redraw = NULL,
.config = ega_config
};
2022-03-13 21:43:45 -04:00
const device_t sega_device = {
2022-08-31 19:19:29 -04:00
.name = "SuperEGA",
2022-03-13 21:43:45 -04:00
.internal_name = "superega",
2022-08-31 19:19:29 -04:00
.flags = DEVICE_ISA,
.local = EGA_SUPEREGA,
.init = ega_standalone_init,
.close = ega_close,
.reset = NULL,
2022-03-13 21:43:45 -04:00
{ .available = sega_standalone_available },
.speed_changed = ega_speed_changed,
2022-08-31 19:19:29 -04:00
.force_redraw = NULL,
.config = ega_config
};
const device_t atiega800p_device = {
.name = "ATI EGA Wonder 800+",
.internal_name = "egawonder800p",
.flags = DEVICE_ISA,
.local = EGA_ATI800P,
.init = ega_standalone_init,
.close = ega_close,
.reset = NULL,
{ .available = atiega800p_standalone_available },
.speed_changed = ega_speed_changed,
.force_redraw = NULL,
.config = ega_config
};
2022-03-13 21:43:45 -04:00
const device_t iskra_ega_device = {
2022-08-31 19:19:29 -04:00
.name = "Iskra EGA (Cyrillic ROM)",
2022-03-13 21:43:45 -04:00
.internal_name = "iskra_ega",
2022-08-31 19:19:29 -04:00
.flags = DEVICE_ISA,
.local = EGA_ISKRA,
.init = ega_standalone_init,
.close = ega_close,
.reset = NULL,
2022-03-13 21:43:45 -04:00
{ .available = iskra_ega_standalone_available },
.speed_changed = ega_speed_changed,
2022-08-31 19:19:29 -04:00
.force_redraw = NULL,
.config = ega_config
};
2022-03-13 21:43:45 -04:00
const device_t et2000_device = {
2022-08-31 19:19:29 -04:00
.name = "Tseng Labs ET2000",
2022-03-13 21:43:45 -04:00
.internal_name = "et2000",
2022-08-31 19:19:29 -04:00
.flags = DEVICE_ISA,
.local = EGA_TSENG,
.init = ega_standalone_init,
.close = ega_close,
.reset = NULL,
2022-03-13 21:43:45 -04:00
{ .available = et2000_standalone_available },
.speed_changed = ega_speed_changed,
2022-08-31 19:19:29 -04:00
.force_redraw = NULL,
.config = ega_config
};