Added ATI Korean VGA emulation. Patch from Greatpsycho.

This commit is contained in:
SarahW 2018-03-11 15:46:24 +00:00
commit 2567c30353
8 changed files with 371 additions and 41 deletions

View file

@ -478,6 +478,7 @@ enum
GFX_TGUI9440, /*Trident TGUI9440*/
GFX_VGA, /*IBM VGA*/
GFX_VGAEDGE16, /*ATI VGA Edge-16 (18800-1)*/
GFX_ATIKOREANVGA, /*ATI Korean VGA (28800-5)*/
GFX_VGACHARGER, /*ATI VGA Charger (28800-5)*/
GFX_OTI067, /*Oak OTI-067*/
GFX_MACH64GX, /*ATI Graphics Pro Turbo (Mach64)*/

View file

@ -1,4 +1,4 @@
/*ATI 28800 emulation (VGA Charger)*/
/*ATI 28800 emulation (VGA Charger & Korean VGA)*/
#include <stdlib.h>
#include "ibm.h"
#include "device.h"
@ -20,6 +20,14 @@ typedef struct ati28800_t
uint8_t regs[256];
int index;
uint8_t port_03dd_val;
uint16_t get_korean_font_kind;
int in_get_korean_font_kind_set;
int get_korean_font_enabled;
int get_korean_font_index;
uint16_t get_korean_font_base;
int ksc5601_mode_enabled;
} ati28800_t;
void ati28800_out(uint16_t addr, uint8_t val, void *p)
@ -39,6 +47,7 @@ void ati28800_out(uint16_t addr, uint8_t val, void *p)
ati28800->index = val;
break;
case 0x1cf:
old = ati28800->regs[ati28800->index];
ati28800->regs[ati28800->index] = val;
switch (ati28800->index)
{
@ -51,10 +60,24 @@ void ati28800_out(uint16_t addr, uint8_t val, void *p)
}
else /*Single bank mode*/
svga->read_bank = svga->write_bank = ((ati28800->regs[0xb2] >> 1) & 7) * 0x10000;
if (ati28800->index == 0xbe && ((old ^ val) & 0x10))
svga_recalctimings(svga);
break;
case 0xb3:
ati_eeprom_write(&ati28800->eeprom, val & 8, val & 2, val & 1);
break;
case 0xb6:
if ((old ^ val) & 0x10)
svga_recalctimings(svga);
break;
case 0xb8:
if ((old ^ val) & 0x40)
svga_recalctimings(svga);
break;
case 0xb9:
if ((old ^ val) & 2)
svga_recalctimings(svga);
break;
}
break;
@ -81,6 +104,63 @@ void ati28800_out(uint16_t addr, uint8_t val, void *p)
svga_out(addr, val, svga);
}
void ati28800k_out(uint16_t addr, uint8_t val, void *p)
{
ati28800_t *ati28800 = (ati28800_t *)p;
svga_t *svga = &ati28800->svga;
uint16_t oldaddr = addr;
if (((addr&0xFFF0) == 0x3D0 || (addr&0xFFF0) == 0x3B0) && !(svga->miscout&1))
addr ^= 0x60;
switch (addr)
{
case 0x1CF:
if (ati28800->index == 0xBF && ((ati28800->regs[0xBF] ^ val) & 0x20))
{
ati28800->ksc5601_mode_enabled = val & 0x20;
// pclog("Switching mode to %s at %04X:%04X\n", ksc5601_mode_enabled ? "DBCS" : "SBCS", CS, cpu_state.oldpc);
svga_recalctimings(svga);
}
ati28800_out(oldaddr, val, p);
break;
case 0x3DD:
// pclog("ati28800k_out : set port 03DD to %02X at %04X:%04X\n", val, CS, cpu_state.oldpc);
ati28800->port_03dd_val = val;
if (val == 1)
ati28800->get_korean_font_enabled = 0;
if (ati28800->in_get_korean_font_kind_set)
{
ati28800->get_korean_font_kind = (val << 8) | (ati28800->get_korean_font_kind & 0xFF);
ati28800->get_korean_font_enabled = 1;
ati28800->get_korean_font_index = 0;
ati28800->in_get_korean_font_kind_set = 0;
}
break;
case 0x3DE:
// pclog("ati28800k_out : set port 03DE to %02X at %04X:%04X\n", val, CS, cpu_state.oldpc);
ati28800->in_get_korean_font_kind_set = 0;
switch (ati28800->port_03dd_val)
{
case 0x10:
ati28800->get_korean_font_base = ((val & 0x7F) << 7) | (ati28800->get_korean_font_base & 0x7F);
break;
case 8:
ati28800->get_korean_font_base = (ati28800->get_korean_font_base & 0x3F80) | (val & 0x7F);
break;
case 1:
ati28800->get_korean_font_kind = (ati28800->get_korean_font_kind & 0xFF00) | val;
if (val & 2)
ati28800->in_get_korean_font_kind_set = 1;
break;
}
break;
default:
ati28800_out(oldaddr, val, p);
break;
}
}
uint8_t ati28800_in(uint16_t addr, void *p)
{
ati28800_t *ati28800 = (ati28800_t *)p;
@ -127,7 +207,45 @@ uint8_t ati28800_in(uint16_t addr, void *p)
temp = svga_in(addr, svga);
break;
}
if (addr != 0x3da) pclog("%02X %04X:%04X\n", temp, CS,cpu_state.pc);
// if (addr != 0x3da) pclog("%02X %04X:%04X\n", temp, CS,cpu_state.pc);
return temp;
}
uint8_t ati28800k_in(uint16_t addr, void *p)
{
ati28800_t *ati28800 = (ati28800_t *)p;
svga_t *svga = &ati28800->svga;
uint16_t oldaddr = addr;
uint8_t temp = 0xFF;
// if (addr != 0x3da) pclog("ati28800_in : %04X ", addr);
if (((addr&0xFFF0) == 0x3D0 || (addr&0xFFF0) == 0x3B0) && !(svga->miscout&1)) addr ^= 0x60;
switch (addr)
{
case 0x3DE:
if (ati28800->get_korean_font_enabled && (ati28800->regs[0xBF] & 0x20))
{
switch (ati28800->get_korean_font_kind >> 8)
{
case 4: /* ROM font */
temp = fontdatksc5601[ati28800->get_korean_font_base][ati28800->get_korean_font_index++];
break;
case 2: /* User defined font - TODO : Should be implemented later */
temp = 0;
break;
default:
break;
}
ati28800->get_korean_font_index &= 0x1F;
}
break;
default:
temp = ati28800_in(oldaddr, p);
break;
}
// if (addr != 0x3da) pclog("%02X %04X:%04X\n", temp, CS,cpu_state.pc);
return temp;
}
@ -135,6 +253,43 @@ void ati28800_recalctimings(svga_t *svga)
{
ati28800_t *ati28800 = (ati28800_t *)svga->p;
pclog("ati28800_recalctimings\n");
switch (((ati28800->regs[0xbe] & 0x10) >> 1) | ((ati28800->regs[0xb9] & 2) << 1) | ((svga->miscout & 0x0C) >> 2))
{
case 0x00: svga->clock = cpuclock / 42954000.0; break;
case 0x01: svga->clock = cpuclock / 48771000.0; break;
case 0x03: svga->clock = cpuclock / 36000000.0; break;
case 0x04: svga->clock = cpuclock / 50350000.0; break;
case 0x05: svga->clock = cpuclock / 56640000.0; break;
case 0x07: svga->clock = cpuclock / 44900000.0; break;
case 0x08: svga->clock = cpuclock / 30240000.0; break;
case 0x09: svga->clock = cpuclock / 32000000.0; break;
case 0x0A: svga->clock = cpuclock / 37500000.0; break;
case 0x0B: svga->clock = cpuclock / 39000000.0; break;
case 0x0C: svga->clock = cpuclock / 40000000.0; break;
case 0x0D: svga->clock = cpuclock / 56644000.0; break;
case 0x0E: svga->clock = cpuclock / 75000000.0; break;
case 0x0F: svga->clock = cpuclock / 65000000.0; break;
default: break;
}
if (ati28800->regs[0xb8] & 0x40)
svga->clock *= 2;
if (ati28800->regs[0xb6] & 0x10)
{
svga->hdisp <<= 1;
svga->htotal <<= 1;
svga->rowoffset <<= 1;
}
if (svga->crtc[0x17] & 4)
{
svga->vtotal <<= 1;
svga->dispend <<= 1;
svga->vsyncstart <<= 1;
svga->split <<= 1;
svga->vblankstart <<= 1;
}
if (!svga->scrblank && (ati28800->regs[0xb0] & 0x20)) /*Extended 256 colour modes*/
{
pclog("8bpp_highres\n");
@ -144,6 +299,18 @@ void ati28800_recalctimings(svga_t *svga)
}
}
void ati28800k_recalctimings(svga_t *svga)
{
ati28800_t *ati28800 = (ati28800_t *)svga->p;
ati28800_recalctimings(svga);
if (svga->render == svga_render_text_80 && ati28800->ksc5601_mode_enabled)
{
svga->render = svga_render_text_80_ksc5601;
}
}
void *ati28800_init()
{
ati28800_t *ati28800 = malloc(sizeof(ati28800_t));
@ -167,11 +334,48 @@ void *ati28800_init()
return ati28800;
}
void *ati28800k_init()
{
ati28800_t *ati28800 = malloc(sizeof(ati28800_t));
memset(ati28800, 0, sizeof(ati28800_t));
ati28800->port_03dd_val = 0;
ati28800->get_korean_font_base = 0;
ati28800->get_korean_font_index = 0;
ati28800->get_korean_font_enabled = 0;
ati28800->get_korean_font_kind = 0;
ati28800->in_get_korean_font_kind_set = 0;
ati28800->ksc5601_mode_enabled = 0;
rom_init(&ati28800->bios_rom, "atikorvga.bin", 0xc0000, 0x8000, 0x7fff, 0, MEM_MAPPING_EXTERNAL);
loadfont("ati_ksc5601.rom", 6);
svga_init(&ati28800->svga, ati28800, 1 << 19, /*512kb*/
ati28800k_recalctimings,
ati28800k_in, ati28800k_out,
NULL,
NULL);
io_sethandler(0x01ce, 0x0002, ati28800k_in, NULL, NULL, ati28800k_out, NULL, NULL, ati28800);
io_sethandler(0x03c0, 0x0020, ati28800k_in, NULL, NULL, ati28800k_out, NULL, NULL, ati28800);
ati28800->svga.miscout = 1;
ati_eeprom_load(&ati28800->eeprom, "atikorvga.nvr", 0);
return ati28800;
}
static int ati28800_available()
{
return rom_present("bios.bin");
}
static int ati28800k_available()
{
return rom_present("atikorvga.bin") && rom_present("ati_ksc5601.rom");
}
void ati28800_close(void *p)
{
ati28800_t *ati28800 = (ati28800_t *)p;
@ -202,6 +406,17 @@ void ati28800_add_status_info(char *s, int max_len, void *p)
svga_add_status_info(s, max_len, &ati28800->svga);
}
void ati28800k_add_status_info(char *s, int max_len, void *p)
{
ati28800_t *ati28800 = (ati28800_t *)p;
char temps[128];
svga_add_status_info(s, max_len, &ati28800->svga);
sprintf(temps, "Korean SVGA mode enabled : %s\n\n", ati28800->ksc5601_mode_enabled ? "Yes" : "No");
strncat(s, temps, max_len);
}
device_t ati28800_device =
{
"ATI-28800",
@ -213,3 +428,15 @@ device_t ati28800_device =
ati28800_force_redraw,
ati28800_add_status_info
};
device_t ati28800k_device =
{
"ATI Korean VGA",
0,
ati28800k_init,
ati28800_close,
ati28800k_available,
ati28800_speed_changed,
ati28800_force_redraw,
ati28800k_add_status_info
};

View file

@ -1 +1,2 @@
extern device_t ati28800_device;
extern device_t ati28800k_device;

View file

@ -372,7 +372,7 @@ void svga_recalctimings(svga_t *svga)
svga->render = svga_render_blank;
if (!svga->scrblank && svga->attr_palette_enable)
{
if (!(svga->gdcreg[6] & 1)) /*Text mode*/
if (!(svga->gdcreg[6] & 1) && !(svga->attrregs[0x10] & 1)) /*Text mode*/
{
if (svga->seqregs[1] & 8) /*40 column*/
{
@ -680,7 +680,7 @@ void svga_poll(void *p)
svga->video_res_x = wx;
svga->video_res_y = wy + 1;
// pclog("%i %i %i\n", svga->video_res_x, svga->video_res_y, svga->lowres);
if (!(svga->gdcreg[6] & 1)) /*Text mode*/
if (!(svga->gdcreg[6] & 1) && !(svga->attrregs[0x10] & 1)) /*Text mode*/
{
svga->video_res_x /= (svga->seqregs[1] & 1) ? 8 : 9;
svga->video_res_y /= (svga->crtc[9] & 31) + 1;
@ -690,7 +690,9 @@ void svga_poll(void *p)
{
if (svga->crtc[9] & 0x80)
svga->video_res_y /= 2;
if (!(svga->crtc[0x17] & 1))
if (!(svga->crtc[0x17] & 2))
svga->video_res_y *= 4;
else if (!(svga->crtc[0x17] & 1))
svga->video_res_y *= 2;
svga->video_res_y /= (svga->crtc[9] & 31) + 1;
if (svga->lowres)

View file

@ -158,14 +158,125 @@ void svga_render_text_80(svga_t *svga)
}
}
void svga_render_text_80_ksc5601(svga_t *svga)
{
if (svga->firstline_draw == 2000)
svga->firstline_draw = svga->displine;
svga->lastline_draw = svga->displine;
if (svga->fullchange)
{
uint32_t *p = &((uint32_t *)buffer32->line[svga->displine])[32];
int x, xx;
int drawcursor;
uint8_t chr, attr, dat, nextchr;
uint32_t charaddr;
int fg, bg;
int xinc = (svga->seqregs[1] & 1) ? 8 : 9;
for (x = 0; x < svga->hdisp; x += xinc)
{
drawcursor = ((svga->ma == svga->ca) && svga->con && svga->cursoron);
chr = svga->vram[(svga->ma << 1) & svga->vram_display_mask];
nextchr = svga->vram[((svga->ma + 4) << 1) & svga->vram_display_mask];
attr = svga->vram[((svga->ma << 1) + 1) & svga->vram_display_mask];
if (drawcursor)
{
bg = svga->pallook[svga->egapal[attr & 15]];
fg = svga->pallook[svga->egapal[attr >> 4]];
}
else
{
fg = svga->pallook[svga->egapal[attr & 15]];
bg = svga->pallook[svga->egapal[attr >> 4]];
if (attr & 0x80 && svga->attrregs[0x10] & 8)
{
bg = svga->pallook[svga->egapal[(attr >> 4) & 7]];
if (svga->blink & 16)
fg = bg;
}
}
if(x + xinc < svga->hdisp && (chr & nextchr & 0x80))
{
dat = fontdatksc5601[((chr & 0x7F) << 7) | (nextchr & 0x7F)][svga->sc];
}
else
{
if (attr & 8) charaddr = svga->charsetb + (chr * 128);
else charaddr = svga->charseta + (chr * 128);
dat = svga->vram[charaddr + (svga->sc << 2)];
}
if (svga->seqregs[1] & 1)
{
for (xx = 0; xx < 8; xx++)
p[xx] = (dat & (0x80 >> xx)) ? fg : bg;
}
else
{
for (xx = 0; xx < 8; xx++)
p[xx] = (dat & (0x80 >> xx)) ? fg : bg;
if ((chr & ~0x1F) != 0xC0 || !(svga->attrregs[0x10] & 4))
p[8] = bg;
else
p[8] = (dat & 1) ? fg : bg;
}
svga->ma += 4;
p += xinc;
if(x + xinc < svga->hdisp && (chr & nextchr & 0x80))
{
attr = svga->vram[((svga->ma << 1) + 1) & svga->vram_display_mask];
if (drawcursor)
{
bg = svga->pallook[svga->egapal[attr & 15]];
fg = svga->pallook[svga->egapal[attr >> 4]];
}
else
{
fg = svga->pallook[svga->egapal[attr & 15]];
bg = svga->pallook[svga->egapal[attr >> 4]];
if (attr & 0x80 && svga->attrregs[0x10] & 8)
{
bg = svga->pallook[svga->egapal[(attr >> 4) & 7]];
if (svga->blink & 16)
fg = bg;
}
}
dat = fontdatksc5601[((chr & 0x7F) << 7) | (nextchr & 0x7F)][svga->sc + 16];
if (svga->seqregs[1] & 1)
{
for (xx = 0; xx < 8; xx++)
p[xx] = (dat & (0x80 >> xx)) ? fg : bg;
}
else
{
for (xx = 0; xx < 8; xx++)
p[xx] = (dat & (0x80 >> xx)) ? fg : bg;
if ((chr & ~0x1F) != 0xC0 || !(svga->attrregs[0x10] & 4))
p[8] = bg;
else
p[8] = (dat & 1) ? fg : bg;
}
svga->ma += 4;
p += xinc;
x += xinc;
}
}
svga->ma &= svga->vram_display_mask;
}
}
void svga_render_2bpp_lowres(svga_t *svga)
{
int changed_offset;
if (svga->sc & 1 && !(svga->crtc[0x17] & 1))
changed_offset = (svga->ma << 1) >> 12;
else
changed_offset = ((svga->ma << 1) + 0x8000) >> 12;
changed_offset = ((svga->ma << 1) + (svga->sc & ~svga->crtc[0x17] & 3) * 0x8000) >> 12;
if (svga->changedvram[changed_offset] || svga->changedvram[changed_offset + 1] || svga->fullchange)
{
@ -181,16 +292,8 @@ void svga_render_2bpp_lowres(svga_t *svga)
{
uint8_t dat[2];
if (svga->sc & 1 && !(svga->crtc[0x17] & 1))
{
dat[0] = svga->vram[(svga->ma << 1) + 0x8000];
dat[1] = svga->vram[(svga->ma << 1) + 0x8001];
}
else
{
dat[0] = svga->vram[(svga->ma << 1)];
dat[1] = svga->vram[(svga->ma << 1) + 1];
}
dat[0] = svga->vram[(svga->ma << 1) + ((svga->sc & ~svga->crtc[0x17] & 3)) * 0x8000];
dat[1] = svga->vram[(svga->ma << 1) + ((svga->sc & ~svga->crtc[0x17] & 3)) * 0x8000 + 1];
svga->ma += 4;
svga->ma &= svga->vram_display_mask;
@ -212,10 +315,7 @@ void svga_render_2bpp_highres(svga_t *svga)
{
int changed_offset;
if (svga->sc & 1 && !(svga->crtc[0x17] & 1))
changed_offset = ((svga->ma << 1) | 0x8000) >> 12;
else
changed_offset = (svga->ma << 1) >> 12;
changed_offset = ((svga->ma << 1) + (svga->sc & ~svga->crtc[0x17] & 3) * 0x8000) >> 12;
if (svga->changedvram[changed_offset] || svga->changedvram[changed_offset + 1] || svga->fullchange)
{
@ -231,16 +331,8 @@ void svga_render_2bpp_highres(svga_t *svga)
{
uint8_t dat[2];
if (svga->sc & 1 && !(svga->crtc[0x17] & 1))
{
dat[0] = svga->vram[(svga->ma << 1) + 0x8000];
dat[1] = svga->vram[(svga->ma << 1) + 0x8001];
}
else
{
dat[0] = svga->vram[(svga->ma << 1)];
dat[1] = svga->vram[(svga->ma << 1) + 1];
}
dat[0] = svga->vram[(svga->ma << 1) + ((svga->sc & ~svga->crtc[0x17] & 3)) * 0x8000];
dat[1] = svga->vram[(svga->ma << 1) + ((svga->sc & ~svga->crtc[0x17] & 3)) * 0x8000 + 1];
svga->ma += 4;
svga->ma &= svga->vram_display_mask;
@ -301,10 +393,7 @@ void svga_render_4bpp_highres(svga_t *svga)
{
int changed_offset;
if (svga->sc & 1 && !(svga->crtc[0x17] & 1))
changed_offset = (svga->ma | 0x8000) >> 12;
else
changed_offset = svga->ma >> 12;
changed_offset = (svga->ma + (svga->sc & ~svga->crtc[0x17] & 3) * 0x8000) >> 12;
if (svga->changedvram[changed_offset] || svga->changedvram[changed_offset + 1] || svga->fullchange)
{
@ -321,10 +410,7 @@ void svga_render_4bpp_highres(svga_t *svga)
uint8_t edat[4];
uint8_t dat;
if (svga->sc & 1 && !(svga->crtc[0x17] & 1))
*(uint32_t *)(&edat[0]) = *(uint32_t *)(&svga->vram[svga->ma | 0x8000]);
else
*(uint32_t *)(&edat[0]) = *(uint32_t *)(&svga->vram[svga->ma]);
*(uint32_t *)(&edat[0]) = *(uint32_t *)(&svga->vram[svga->ma | ((svga->sc & ~svga->crtc[0x17] & 3)) * 0x8000]);
svga->ma += 4;
svga->ma &= svga->vram_display_mask;

View file

@ -12,6 +12,7 @@ extern uint8_t edatlookup[4][4];
void svga_render_blank(svga_t *svga);
void svga_render_text_40(svga_t *svga);
void svga_render_text_80(svga_t *svga);
void svga_render_text_80_ksc5601(svga_t *svga);
void svga_render_2bpp_lowres(svga_t *svga);
void svga_render_2bpp_highres(svga_t *svga);

View file

@ -79,6 +79,7 @@ static VIDEO_CARD video_cards[] =
{
{"ATI Graphics Pro Turbo (Mach64 GX)", "mach64gx", &mach64gx_device, GFX_MACH64GX, VIDEO_FLAG_TYPE_SPECIAL, {VIDEO_BUS, 2, 2, 1, 20, 20, 21}},
{"ATI Video Xpression (Mach64 VT2)", "mach64vt2", &mach64vt2_device, GFX_MACH64VT2, VIDEO_FLAG_TYPE_SPECIAL, {VIDEO_BUS, 2, 2, 1, 20, 20, 21}},
{"ATI Korean VGA (ATI-28800)", "ati28800k", &ati28800k_device, GFX_ATIKOREANVGA, VIDEO_FLAG_TYPE_SPECIAL, {VIDEO_ISA, 3, 3, 6, 5, 5, 10}},
{"ATI VGA Charger (ATI-28800)", "ati28800", &ati28800_device, GFX_VGACHARGER, VIDEO_FLAG_TYPE_SPECIAL, {VIDEO_ISA, 3, 3, 6, 5, 5, 10}},
{"ATI VGA Edge-16 (ATI-18800)", "ati18800", &ati18800_device, GFX_VGAEDGE16, VIDEO_FLAG_TYPE_SPECIAL, {VIDEO_ISA, 8, 16, 32, 8, 16, 32}},
{"CGA", "cga", &cga_device, GFX_CGA, VIDEO_FLAG_TYPE_CGA, {VIDEO_ISA, 8, 16, 32, 8, 16, 32}},
@ -744,6 +745,7 @@ uint8_t fontdat[2048][8];
uint8_t fontdatm[2048][16];
uint8_t fontdatw[512][32]; /* Wyse700 font */
uint8_t fontdat8x12[256][16]; /* MDSI Genius font */
uint8_t fontdatksc5601[16384][32]; /* Korean KSC-5601 font */
int xsize=1,ysize=1;
@ -866,6 +868,15 @@ void loadfont(char *s, int format)
}
}
break;
case 6: /* Korean KSC-5601 */
for (c=0;c<16384;c++)
{
for (d=0;d<32;d++)
{
fontdatksc5601[c][d]=getc(f);
}
}
break;
}
fclose(f);

View file

@ -53,6 +53,7 @@ extern int changeframecount;
extern uint8_t fontdat[2048][8];
extern uint8_t fontdatm[2048][16];
extern uint8_t fontdatksc5601[16384][32];
extern uint32_t *video_15to32, *video_16to32;