More Sound Blaster 16+ / ViBRA 16 fixes, added optional PC speaker control via the Sound Blaster 16+ / ViBRA 16, and removed some left-over temporary code from device.c.

This commit is contained in:
OBattler
2023-10-21 06:53:11 +02:00
parent f3ca2a6dcd
commit 28e2eb3ce5
347 changed files with 250776 additions and 101 deletions

View File

@@ -0,0 +1,701 @@
/*
* 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.
*
* This file is part of the 86Box distribution.
*
* Emulation of the old and new IBM CGA graphics cards.
*
*
*
* Authors: Sarah Walker, <https://pcem-emulator.co.uk/>
* Miran Grca, <mgrca8@gmail.com>
*
* Copyright 2008-2019 Sarah Walker.
* Copyright 2016-2019 Miran Grca.
*/
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include <wchar.h>
#include <math.h>
#include <86box/86box.h>
#include "cpu.h"
#include <86box/io.h>
#include <86box/timer.h>
#include <86box/pit.h>
#include <86box/mem.h>
#include <86box/rom.h>
#include <86box/device.h>
#include <86box/video.h>
#include <86box/vid_cga.h>
#include <86box/vid_cga_comp.h>
#define CGA_RGB 0
#define CGA_COMPOSITE 1
#define COMPOSITE_OLD 0
#define COMPOSITE_NEW 1
static uint8_t crtcmask[32] = {
0xff, 0xff, 0xff, 0xff, 0x7f, 0x1f, 0x7f, 0x7f, 0xf3, 0x1f, 0x7f, 0x1f, 0x3f, 0xff, 0x3f, 0xff,
0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
static video_timings_t timing_cga = { .type = VIDEO_ISA, .write_b = 8, .write_w = 16, .write_l = 32, .read_b = 8, .read_w = 16, .read_l = 32 };
void cga_recalctimings(cga_t *cga);
void
cga_out(uint16_t addr, uint8_t val, void *p)
{
cga_t *cga = (cga_t *) p;
uint8_t old;
if ((addr >= 0x3d0) && (addr <= 0x3d7))
addr = (addr & 0xff9) | 0x004;
switch (addr) {
case 0x3D4:
cga->crtcreg = val & 31;
return;
case 0x3D5:
old = cga->crtc[cga->crtcreg];
cga->crtc[cga->crtcreg] = val & crtcmask[cga->crtcreg];
if (old != val) {
if ((cga->crtcreg < 0xe) || (cga->crtcreg > 0x10)) {
cga->fullchange = changeframecount;
cga_recalctimings(cga);
}
}
return;
case 0x3D8:
old = cga->cgamode;
cga->cgamode = val;
if (old ^ val) {
if ((old ^ val) & 0x07)
update_cga16_color(val);
cga_recalctimings(cga);
}
return;
case 0x3D9:
old = cga->cgacol;
cga->cgacol = val;
if (old ^ val)
cga_recalctimings(cga);
return;
}
}
uint8_t
cga_in(uint16_t addr, void *p)
{
cga_t *cga = (cga_t *) p;
uint8_t ret = 0xff;
if ((addr >= 0x3d0) && (addr <= 0x3d7))
addr = (addr & 0xff9) | 0x004;
switch (addr) {
case 0x3D4:
ret = cga->crtcreg;
break;
case 0x3D5:
ret = cga->crtc[cga->crtcreg];
break;
case 0x3DA:
ret = cga->cgastat;
break;
}
return ret;
}
void
cga_pravetz_out(uint16_t addr, uint8_t val, void *p)
{
cga_t *cga = (cga_t *) p;
cga->fontbase = (((unsigned int) val) << 8);
}
uint8_t
cga_pravetz_in(uint16_t addr, void *p)
{
cga_t *cga = (cga_t *) p;
return (cga->fontbase >> 8);
}
void
cga_waitstates(void *p)
{
cga_t *cga = (cga_t *) p;
int ws_array[16] = { 3, 4, 5, 6, 7, 8, 4, 5, 6, 7, 8, 4, 5, 6, 7, 8 };
int ws;
int q_array[16] = { 5, 5, 4, 4, 4, 3, 8, 8, 8, 7, 7, 7, 6, 6, 6, 5 };
int q;
if (is286) {
ws = ws_array[cycles & 0xf];
cycles -= ws;
} else {
q = 15 - (((int) (timer_get_remaining_u64(&cga->q_timer) >> 32ULL)) & 0x0f);
cycles -= q_array[q];
// pclog("Subtracting %i cycles at index %i\n", q_array[q], q);
}
}
void
cga_write(uint32_t addr, uint8_t val, void *p)
{
cga_t *cga = (cga_t *) p;
cga->vram[addr & 0x3fff] = val;
if (cga->snow_enabled) {
int offset = ((timer_get_remaining_u64(&cga->timer) / CGACONST) * 2) & 0xfc;
cga->charbuffer[offset] = cga->vram[addr & 0x3fff];
cga->charbuffer[offset | 1] = cga->vram[addr & 0x3fff];
}
cga_waitstates(cga);
}
uint8_t
cga_read(uint32_t addr, void *p)
{
cga_t *cga = (cga_t *) p;
cga_waitstates(cga);
if (cga->snow_enabled) {
int offset = ((timer_get_remaining_u64(&cga->timer) / CGACONST) * 2) & 0xfc;
cga->charbuffer[offset] = cga->vram[addr & 0x3fff];
cga->charbuffer[offset | 1] = cga->vram[addr & 0x3fff];
}
return cga->vram[addr & 0x3fff];
}
void
cga_recalctimings(cga_t *cga)
{
double disptime;
double _dispontime;
double _dispofftime;
if (cga->cgamode & 1) {
disptime = (double) (cga->crtc[0] + 1);
_dispontime = (double) cga->crtc[1];
} else {
disptime = (double) ((cga->crtc[0] + 1) << 1);
_dispontime = (double) (cga->crtc[1] << 1);
}
_dispofftime = disptime - _dispontime;
_dispontime = _dispontime * CGACONST;
_dispofftime = _dispofftime * CGACONST;
cga->dispontime = (uint64_t) (_dispontime);
cga->dispofftime = (uint64_t) (_dispofftime);
}
void
cga_q_tick(void *p)
{
cga_t *cga = (cga_t *) p;
timer_advance_u64(&cga->q_timer, CGACONST << 1);
}
void
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;
int c;
int xs_temp;
int ys_temp;
int oldvc;
uint8_t chr;
uint8_t attr;
uint8_t border;
uint16_t dat;
int cols[4];
int col;
int oldsc;
if (!cga->linepos) {
timer_advance_u64(&cga->timer, cga->dispofftime);
cga->cgastat |= 1;
cga->linepos = 1;
oldsc = cga->sc;
if ((cga->crtc[8] & 3) == 3)
cga->sc = ((cga->sc << 1) + cga->oddeven) & 7;
if (cga->cgadispon) {
if (cga->displine < cga->firstline) {
cga->firstline = cga->displine;
video_wait_for_buffer();
}
cga->lastline = cga->displine;
for (c = 0; c < 8; c++) {
if ((cga->cgamode & 0x12) == 0x12) {
buffer32->line[cga->displine << 1][c] = buffer32->line[(cga->displine << 1) + 1][c] = 0;
if (cga->cgamode & 1) {
buffer32->line[cga->displine << 1][c + (cga->crtc[1] << 3) + 8] = buffer32->line[(cga->displine << 1) + 1][c + (cga->crtc[1] << 3) + 8] = 0;
} else {
buffer32->line[cga->displine << 1][c + (cga->crtc[1] << 4) + 8] = buffer32->line[(cga->displine << 1) + 1][c + (cga->crtc[1] << 4) + 8] = 0;
}
} else {
buffer32->line[cga->displine << 1][c] = buffer32->line[(cga->displine << 1) + 1][c] = (cga->cgacol & 15) + 16;
if (cga->cgamode & 1) {
buffer32->line[cga->displine << 1][c + (cga->crtc[1] << 3) + 8] = buffer32->line[(cga->displine << 1) + 1][c + (cga->crtc[1] << 3) + 8] = (cga->cgacol & 15) + 16;
} else {
buffer32->line[cga->displine << 1][c + (cga->crtc[1] << 4) + 8] = buffer32->line[(cga->displine << 1) + 1][c + (cga->crtc[1] << 4) + 8] = (cga->cgacol & 15) + 16;
}
}
}
if (cga->cgamode & 1) {
for (x = 0; x < cga->crtc[1]; x++) {
if (cga->cgamode & 8) {
chr = cga->charbuffer[x << 1];
attr = cga->charbuffer[(x << 1) + 1];
} else
chr = attr = 0;
drawcursor = ((cga->ma == ca) && cga->con && cga->cursoron);
cols[1] = (attr & 15) + 16;
if (cga->cgamode & 0x20) {
cols[0] = ((attr >> 4) & 7) + 16;
if ((cga->cgablink & 8) && (attr & 0x80) && !cga->drawcursor)
cols[1] = cols[0];
} else
cols[0] = (attr >> 4) + 16;
if (drawcursor) {
for (c = 0; c < 8; c++) {
buffer32->line[cga->displine << 1][(x << 3) + c + 8] = buffer32->line[(cga->displine << 1) + 1][(x << 3) + c + 8] = cols[(fontdat[chr + cga->fontbase][cga->sc & 7] & (1 << (c ^ 7))) ? 1 : 0] ^ 15;
}
} else {
for (c = 0; c < 8; c++) {
buffer32->line[cga->displine << 1][(x << 3) + c + 8] = buffer32->line[(cga->displine << 1) + 1][(x << 3) + c + 8] = cols[(fontdat[chr + cga->fontbase][cga->sc & 7] & (1 << (c ^ 7))) ? 1 : 0];
}
}
cga->ma++;
}
} else if (!(cga->cgamode & 2)) {
for (x = 0; x < cga->crtc[1]; x++) {
if (cga->cgamode & 8) {
chr = cga->vram[(cga->ma << 1) & 0x3fff];
attr = cga->vram[((cga->ma << 1) + 1) & 0x3fff];
} else
chr = attr = 0;
drawcursor = ((cga->ma == ca) && cga->con && cga->cursoron);
cols[1] = (attr & 15) + 16;
if (cga->cgamode & 0x20) {
cols[0] = ((attr >> 4) & 7) + 16;
if ((cga->cgablink & 8) && (attr & 0x80))
cols[1] = cols[0];
} else
cols[0] = (attr >> 4) + 16;
cga->ma++;
if (drawcursor) {
for (c = 0; c < 8; c++) {
buffer32->line[cga->displine << 1][(x << 4) + (c << 1) + 8] = buffer32->line[cga->displine << 1][(x << 4) + (c << 1) + 1 + 8] = buffer32->line[(cga->displine << 1) + 1][(x << 4) + (c << 1) + 8] = buffer32->line[(cga->displine << 1) + 1][(x << 4) + (c << 1) + 1 + 8] = cols[(fontdat[chr + cga->fontbase][cga->sc & 7] & (1 << (c ^ 7))) ? 1 : 0] ^ 15;
}
} else {
for (c = 0; c < 8; c++) {
buffer32->line[cga->displine << 1][(x << 4) + (c << 1) + 8] = buffer32->line[cga->displine << 1][(x << 4) + (c << 1) + 1 + 8] = buffer32->line[(cga->displine << 1) + 1][(x << 4) + (c << 1) + 8] = buffer32->line[(cga->displine << 1) + 1][(x << 4) + (c << 1) + 1 + 8] = cols[(fontdat[chr + cga->fontbase][cga->sc & 7] & (1 << (c ^ 7))) ? 1 : 0];
}
}
}
} else if (!(cga->cgamode & 16)) {
cols[0] = (cga->cgacol & 15) | 16;
col = (cga->cgacol & 16) ? 24 : 16;
if (cga->cgamode & 4) {
cols[1] = col | 3; /* Cyan */
cols[2] = col | 4; /* Red */
cols[3] = col | 7; /* White */
} else if (cga->cgacol & 32) {
cols[1] = col | 3; /* Cyan */
cols[2] = col | 5; /* Magenta */
cols[3] = col | 7; /* White */
} else {
cols[1] = col | 2; /* Green */
cols[2] = col | 4; /* Red */
cols[3] = col | 6; /* Yellow */
}
for (x = 0; x < cga->crtc[1]; x++) {
if (cga->cgamode & 8)
dat = (cga->vram[((cga->ma << 1) & 0x1fff) + ((cga->sc & 1) * 0x2000)] << 8) | cga->vram[((cga->ma << 1) & 0x1fff) + ((cga->sc & 1) * 0x2000) + 1];
else
dat = 0;
cga->ma++;
for (c = 0; c < 8; c++) {
buffer32->line[cga->displine << 1][(x << 4) + (c << 1) + 8] = buffer32->line[cga->displine << 1][(x << 4) + (c << 1) + 1 + 8] = buffer32->line[(cga->displine << 1) + 1][(x << 4) + (c << 1) + 8] = buffer32->line[(cga->displine << 1) + 1][(x << 4) + (c << 1) + 1 + 8] = cols[dat >> 14];
dat <<= 2;
}
}
} else {
cols[0] = 0;
cols[1] = (cga->cgacol & 15) + 16;
for (x = 0; x < cga->crtc[1]; x++) {
if (cga->cgamode & 8)
dat = (cga->vram[((cga->ma << 1) & 0x1fff) + ((cga->sc & 1) * 0x2000)] << 8) | cga->vram[((cga->ma << 1) & 0x1fff) + ((cga->sc & 1) * 0x2000) + 1];
else
dat = 0;
cga->ma++;
for (c = 0; c < 16; c++) {
buffer32->line[cga->displine << 1][(x << 4) + c + 8] = buffer32->line[(cga->displine << 1) + 1][(x << 4) + c + 8] = cols[dat >> 15];
dat <<= 1;
}
}
}
} else {
cols[0] = ((cga->cgamode & 0x12) == 0x12) ? 0 : (cga->cgacol & 15) + 16;
if (cga->cgamode & 1) {
hline(buffer32, 0, (cga->displine << 1), ((cga->crtc[1] << 3) + 16) << 2, cols[0]);
hline(buffer32, 0, (cga->displine << 1) + 1, ((cga->crtc[1] << 3) + 16) << 2, cols[0]);
} else {
hline(buffer32, 0, (cga->displine << 1), ((cga->crtc[1] << 4) + 16) << 2, cols[0]);
hline(buffer32, 0, (cga->displine << 1) + 1, ((cga->crtc[1] << 4) + 16) << 2, cols[0]);
}
}
if (cga->cgamode & 1)
x = (cga->crtc[1] << 3) + 16;
else
x = (cga->crtc[1] << 4) + 16;
if (cga->composite) {
border = ((cga->cgamode & 0x12) == 0x12) ? 0 : (cga->cgacol & 15);
Composite_Process(cga->cgamode, border, x >> 2, buffer32->line[cga->displine << 1]);
Composite_Process(cga->cgamode, border, x >> 2, buffer32->line[(cga->displine << 1) + 1]);
} else {
video_process_8(x, cga->displine << 1);
video_process_8(x, (cga->displine << 1) + 1);
}
cga->sc = oldsc;
if (cga->vc == cga->crtc[7] && !cga->sc)
cga->cgastat |= 8;
cga->displine++;
if (cga->displine >= 360)
cga->displine = 0;
} else {
timer_advance_u64(&cga->timer, cga->dispontime);
cga->linepos = 0;
if (cga->vsynctime) {
cga->vsynctime--;
if (!cga->vsynctime)
cga->cgastat &= ~8;
}
if (cga->sc == (cga->crtc[11] & 31) || ((cga->crtc[8] & 3) == 3 && cga->sc == ((cga->crtc[11] & 31) >> 1))) {
cga->con = 0;
cga->coff = 1;
}
if ((cga->crtc[8] & 3) == 3 && cga->sc == (cga->crtc[9] >> 1))
cga->maback = cga->ma;
if (cga->vadj) {
cga->sc++;
cga->sc &= 31;
cga->ma = cga->maback;
cga->vadj--;
if (!cga->vadj) {
cga->cgadispon = 1;
cga->ma = cga->maback = (cga->crtc[13] | (cga->crtc[12] << 8)) & 0x3fff;
cga->sc = 0;
}
} else if (cga->sc == cga->crtc[9]) {
cga->maback = cga->ma;
cga->sc = 0;
oldvc = cga->vc;
cga->vc++;
cga->vc &= 127;
if (cga->vc == cga->crtc[6])
cga->cgadispon = 0;
if (oldvc == cga->crtc[4]) {
cga->vc = 0;
cga->vadj = cga->crtc[5];
if (!cga->vadj) {
cga->cgadispon = 1;
cga->ma = cga->maback = (cga->crtc[13] | (cga->crtc[12] << 8)) & 0x3fff;
}
switch (cga->crtc[10] & 0x60) {
case 0x20:
cga->cursoron = 0;
break;
case 0x60:
cga->cursoron = cga->cgablink & 0x10;
break;
default:
cga->cursoron = cga->cgablink & 0x08;
break;
}
}
if (cga->vc == cga->crtc[7]) {
cga->cgadispon = 0;
cga->displine = 0;
cga->vsynctime = 16;
if (cga->crtc[7]) {
if (cga->cgamode & 1)
x = (cga->crtc[1] << 3) + 16;
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 (xs_temp < 64)
xs_temp = 656;
if (ys_temp < 32)
ys_temp = 400;
if (!enable_overscan)
xs_temp -= 16;
if ((cga->cgamode & 8) && ((xs_temp != xsize) || (ys_temp != ysize) || video_force_resize_get())) {
xsize = xs_temp;
ysize = ys_temp;
set_screen_size(xsize, ysize + (enable_overscan ? 16 : 0));
if (video_force_resize_get())
video_force_resize_set(0);
}
if (enable_overscan) {
video_blit_memtoscreen(0, (cga->firstline - 4) << 1,
xsize, ((cga->lastline - cga->firstline) + 8) << 1);
} else {
video_blit_memtoscreen(8, cga->firstline << 1,
xsize, (cga->lastline - cga->firstline) << 1);
}
}
frames++;
video_res_x = xsize;
video_res_y = ysize;
if (cga->cgamode & 1) {
video_res_x /= 8;
video_res_y /= cga->crtc[9] + 1;
video_bpp = 0;
} else if (!(cga->cgamode & 2)) {
video_res_x /= 16;
video_res_y /= cga->crtc[9] + 1;
video_bpp = 0;
} else if (!(cga->cgamode & 16)) {
video_res_x /= 2;
video_bpp = 2;
} else
video_bpp = 1;
}
cga->firstline = 1000;
cga->lastline = 0;
cga->cgablink++;
cga->oddeven ^= 1;
}
} else {
cga->sc++;
cga->sc &= 31;
cga->ma = cga->maback;
}
if (cga->cgadispon)
cga->cgastat &= ~1;
if (cga->sc == (cga->crtc[10] & 31) || ((cga->crtc[8] & 3) == 3 && cga->sc == ((cga->crtc[10] & 31) >> 1)))
cga->con = 1;
if (cga->cgadispon && (cga->cgamode & 1)) {
for (x = 0; x < (cga->crtc[1] << 1); x++)
cga->charbuffer[x] = cga->vram[((cga->ma << 1) + x) & 0x3fff];
}
}
}
void
cga_init(cga_t *cga)
{
timer_add(&cga->timer, cga_poll, cga, 1);
cga->composite = 0;
}
void *
cga_standalone_init(const device_t *info)
{
int display_type;
cga_t *cga = malloc(sizeof(cga_t));
memset(cga, 0, sizeof(cga_t));
video_inform(VIDEO_FLAG_TYPE_CGA, &timing_cga);
display_type = device_get_config_int("display_type");
cga->composite = (display_type != CGA_RGB);
cga->revision = device_get_config_int("composite_type");
cga->snow_enabled = device_get_config_int("snow_enabled");
cga->vram = malloc(0x4000);
cga_comp_init(cga->revision);
timer_add(&cga->timer, cga_poll, cga, 1);
if (!is286)
timer_add(&cga->q_timer, cga_q_tick, cga, 1);
mem_mapping_add(&cga->mapping, 0xb8000, 0x08000, cga_read, NULL, NULL, cga_write, NULL, NULL, NULL /*cga->vram*/, MEM_MAPPING_EXTERNAL, cga);
io_sethandler(0x03d0, 0x0010, cga_in, NULL, NULL, cga_out, NULL, NULL, cga);
overscan_x = overscan_y = 16;
cga->rgb_type = device_get_config_int("rgb_type");
cga_palette = (cga->rgb_type << 1);
cgapal_rebuild();
update_cga16_color(cga->cgamode);
return cga;
}
void *
cga_pravetz_init(const device_t *info)
{
cga_t *cga = cga_standalone_init(info);
loadfont("roms/video/cga/PRAVETZ-VDC2.BIN", 10);
io_removehandler(0x03dd, 0x0001, cga_in, NULL, NULL, cga_out, NULL, NULL, cga);
io_sethandler(0x03dd, 0x0001, cga_pravetz_in, NULL, NULL, cga_pravetz_out, NULL, NULL, cga);
cga->fontbase = 0x0300;
return cga;
}
void
cga_close(void *p)
{
cga_t *cga = (cga_t *) p;
free(cga->vram);
free(cga);
}
void
cga_speed_changed(void *p)
{
cga_t *cga = (cga_t *) p;
cga_recalctimings(cga);
}
// clang-format off
const device_config_t cga_config[] = {
{
.name = "display_type",
.description = "Display type",
.type = CONFIG_SELECTION,
.default_int = CGA_RGB,
.selection = {
{
.description = "RGB",
.value = CGA_RGB
},
{
.description = "Composite",
.value = CGA_COMPOSITE
},
{
.description = ""
}
}
},
{
.name = "composite_type",
.description = "Composite type",
.type = CONFIG_SELECTION,
.default_int = COMPOSITE_OLD,
.selection = {
{
.description = "Old",
.value = COMPOSITE_OLD
},
{
.description = "New",
.value = COMPOSITE_NEW
},
{
.description = ""
}
}
},
{
.name = "rgb_type",
.description = "RGB type",
.type = CONFIG_SELECTION,
.default_int = 0,
.selection = {
{
.description = "Color",
.value = 0
},
{
.description = "Green Monochrome",
.value = 1
},
{
.description = "Amber Monochrome",
.value = 2
},
{
.description = "Gray Monochrome",
.value = 3
},
{
.description = "Color (no brown)",
.value = 4
},
{
.description = ""
}
}
},
{
.name = "snow_enabled",
.description = "Snow emulation",
.type = CONFIG_BINARY,
.default_int = 1
},
{
.type = CONFIG_END
}
};
// clang-format on
const device_t cga_device = {
.name = "CGA",
.internal_name = "cga",
.flags = DEVICE_ISA,
.local = 0,
.init = cga_standalone_init,
.close = cga_close,
.reset = NULL,
{ .available = NULL },
.speed_changed = cga_speed_changed,
.force_redraw = NULL,
.config = cga_config
};
const device_t cga_pravetz_device = {
.name = "Pravetz VDC-2",
.internal_name = "cga_pravetz",
.flags = DEVICE_ISA,
.local = 0,
.init = cga_pravetz_init,
.close = cga_close,
.reset = NULL,
{ .available = NULL },
.speed_changed = cga_speed_changed,
.force_redraw = NULL,
.config = cga_config
};

View File

@@ -0,0 +1,519 @@
/*
* 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.
*
* This file is part of the 86Box distribution.
*
* MDA emulation.
*
*
*
* Authors: Sarah Walker, <https://pcem-emulator.co.uk/>
* Miran Grca, <mgrca8@gmail.com>
*
* Copyright 2008-2019 Sarah Walker.
* Copyright 2016-2019 Miran Grca.
*/
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include <wchar.h>
#include <86box/86box.h>
#include <86box/io.h>
#include <86box/timer.h>
#include <86box/lpt.h>
#include <86box/pit.h>
#include <86box/mem.h>
#include <86box/rom.h>
#include <86box/device.h>
#include <86box/video.h>
#include <86box/vid_mda.h>
#include <86box/plat_unused.h>
static int mdacols[256][2][2];
static video_timings_t timing_mda = { .type = VIDEO_ISA, .write_b = 8, .write_w = 16, .write_l = 32, .read_b = 8, .read_w = 16, .read_l = 32 };
static double dot_clock = 0.0;
void mda_recalctimings(mda_t *mda);
void
mda_out(uint16_t addr, uint8_t val, void *priv)
{
mda_t *mda = (mda_t *) priv;
// pclog("[W] %04X = %02X\n", addr, val);
switch (addr) {
case 0x3b0:
case 0x3b2:
case 0x3b4:
case 0x3b6:
mda->crtcreg = val & 31;
return;
case 0x3b1:
case 0x3b3:
case 0x3b5:
case 0x3b7:
mda->crtc[mda->crtcreg] = val;
#if 0
if (mda->crtc[10] == 6 && mda->crtc[11] == 7) /*Fix for Generic Turbo XT BIOS, which sets up cursor registers wrong*/
{
mda->crtc[10] = 0xb;
mda->crtc[11] = 0xc;
}
#endif
mda_recalctimings(mda);
return;
case 0x3b8:
mda->ctrl = val;
return;
default:
break;
}
}
uint8_t
mda_in(uint16_t addr, void *priv)
{
const mda_t *mda = (mda_t *) priv;
uint8_t ret = 0xff;
switch (addr) {
case 0x3b0:
case 0x3b2:
case 0x3b4:
case 0x3b6:
ret = mda->crtcreg;
break;
case 0x3b1:
case 0x3b3:
case 0x3b5:
case 0x3b7:
ret = mda->crtc[mda->crtcreg];
break;
case 0x3ba:
ret = mda->stat;
// if (mda->ctrl & 0x08)
// ret |= (mda->stat & 0x80) ? 0x08 : 0x00;
// return mda->stat | 0xF0;
break;
default:
break;
}
// pclog("[R] %04X = %02X\n", addr, ret);
return ret;
}
void
mda_write(uint32_t addr, uint8_t val, void *priv)
{
mda_t *mda = (mda_t *) priv;
mda->vram[addr & 0xfff] = val;
}
uint8_t
mda_read(uint32_t addr, void *priv)
{
const mda_t *mda = (mda_t *) priv;
return mda->vram[addr & 0xfff];
}
void
mda_recalctimings(mda_t *mda)
{
double _dispontime;
double _dispofftime;
double disptime;
disptime = mda->crtc[0] + 1;
_dispontime = mda->crtc[1] + 1;
_dispofftime = disptime - _dispontime;
_dispontime *= MDACONST;
_dispofftime *= MDACONST;
mda->dispontime = (uint64_t) (_dispontime);
mda->dispofftime = (uint64_t) (_dispofftime);
dot_clock = ((double) MDACONST) / 9.0;
}
void
mda_dot_poll(void *priv)
{
mda_t *mda = (mda_t *) priv;
uint16_t ca = (mda->crtc[15] | (mda->crtc[14] << 8)) & 0x3fff;
int drawcursor;
int blink;
timer_advance_u64(&mda->dot_timer, (uint64_t) dot_clock);
static uint8_t chr;
static uint8_t attr;
static uint8_t color;
static uint16_t dot = 0x0008;
static uint16_t ch = 0x0000;
static uint16_t line = 0x0000;
static uint16_t sc = 0x0000;
static int sctotal;
static int vtotal;
static int hslast;
static int vslast;
static int ma = 0x000;
sctotal = ((int) mda->crtc[0x09]) + 1;
vtotal = (((int) mda->crtc[0x04]) + ((int) mda->crtc[0x05])) * sctotal;
hslast = ((int) mda->crtc[0x02]) + ((int) mda->crtc[0x03]) - 1;
vslast = ((int) mda->crtc[0x07]) + 16 - 1;
chr = mda->vram[ma & 0xfff];
attr = mda->vram[(ma + 1) & 0xfff];
drawcursor = (mda->ctrl & 0x08) ? ((ma == ca) && mda->con && mda->cursoron) : 0x00;
blink = (mda->ctrl & 0x08) ? ((mda->blink & 16) && (mda->ctrl & 0x20) &&
(attr & 0x80) && !drawcursor) : 0x00;
if ((mda->sc == 12) && ((attr & 7) == 1))
color = mdacols[attr][blink][1];
else {
if (dot == 0) {
if ((chr & ~0x1f) == 0xc0)
color = mdacols[attr][blink][fontdatm[chr][sc] & 1];
else
color = mdacols[attr][blink][0];
} else
color = mdacols[attr][blink][(fontdatm[chr][sc] & (1 << (dot - 1))) ? 1 : 0];
}
if (drawcursor)
color ^= mdacols[attr][0][1];
if (!(mda->ctrl & 0x08) || !(mda->stat & 0x81) || (ch > mda->crtc[1]) || (line > mda->crtc[6]))
mda->stat &= 0xe7;
else
mda->stat = (mda->stat & 0xe7) | ((color & 0x01) << 3) | ((color & 0x08) << 1);
dot--;
if (dot == 0xffff) {
dot = 8;
if (ch == mda->crtc[0x00]) {
ch = 0;
line++;
if (line == vtotal)
line = 0;
sc++;
if (sc == sctotal)
sc = 0;
} else
ch++;
}
if (ch >= mda->crtc[0x02])
mda->stat &= 0xfe;
else if ((hslast >= mda->crtc[0x02]) && (ch >= mda->crtc[0x02]) && (ch <= hslast))
mda->stat &= 0xfe;
else if ((hslast < mda->crtc[0x02]) && (ch <= hslast))
mda->stat &= 0xfe;
else
mda->stat |= 0x01;
if (line >= mda->crtc[0x07])
mda->stat &= 0x7f;
else if ((vslast >= mda->crtc[0x07]) && (line >= mda->crtc[0x07]) && (line <= vslast))
mda->stat &= 0x7f;
else if ((vslast < mda->crtc[0x07]) && (line <= vslast))
mda->stat &= 0x7f;
else
mda->stat |= 0x80;
ma += 2;
if (ma > 0xfff)
ma = 0;
if (!(mda->stat & 0x81))
ma = 0;
}
void
mda_poll(void *priv)
{
mda_t *mda = (mda_t *) priv;
uint16_t ca = (mda->crtc[15] | (mda->crtc[14] << 8)) & 0x3fff;
int drawcursor;
int x;
int c;
int oldvc;
uint8_t chr;
uint8_t attr;
int oldsc;
int blink;
VIDEO_MONITOR_PROLOGUE()
if (!mda->linepos) {
timer_advance_u64(&mda->timer, mda->dispofftime);
// mda->stat |= 1;
mda->linepos = 1;
oldsc = mda->sc;
if ((mda->crtc[8] & 3) == 3)
mda->sc = (mda->sc << 1) & 7;
if (mda->dispon) {
if (mda->displine < mda->firstline) {
mda->firstline = mda->displine;
video_wait_for_buffer();
}
mda->lastline = mda->displine;
for (x = 0; x < mda->crtc[1]; x++) {
chr = (mda->ctrl & 0x08) ? mda->vram[(mda->ma << 1) & 0xfff] : 0x00;
attr = (mda->ctrl & 0x08) ? mda->vram[((mda->ma << 1) + 1) & 0xfff] : 0x00;
drawcursor = (mda->ctrl & 0x08) ? ((mda->ma == ca) && mda->con && mda->cursoron) : 0x00;
blink = (mda->ctrl & 0x08) ? ((mda->blink & 16) && (mda->ctrl & 0x20) &&
(attr & 0x80) && !drawcursor) : 0x00;
if (mda->sc == 12 && ((attr & 7) == 1)) {
for (c = 0; c < 9; c++)
buffer32->line[mda->displine][(x * 9) + c] = mdacols[attr][blink][1];
} else {
for (c = 0; c < 8; c++)
buffer32->line[mda->displine][(x * 9) + c] = mdacols[attr][blink][(fontdatm[chr][mda->sc] & (1 << (c ^ 7))) ? 1 : 0];
if ((chr & ~0x1f) == 0xc0)
buffer32->line[mda->displine][(x * 9) + 8] = mdacols[attr][blink][fontdatm[chr][mda->sc] & 1];
else
buffer32->line[mda->displine][(x * 9) + 8] = mdacols[attr][blink][0];
}
mda->ma++;
if (drawcursor) {
for (c = 0; c < 9; c++)
buffer32->line[mda->displine][(x * 9) + c] ^= mdacols[attr][0][1];
}
}
video_process_8(mda->crtc[1] * 9, mda->displine);
}
mda->sc = oldsc;
// if (mda->vc == mda->crtc[7] && !mda->sc) {
// mda->stat |= 0x80;
// }
mda->displine++;
if (mda->displine >= 500)
mda->displine = 0;
} else {
timer_advance_u64(&mda->timer, mda->dispontime);
// if (mda->dispon)
// mda->stat &= ~1;
mda->linepos = 0;
if (mda->vsynctime) {
mda->vsynctime--;
// if (!mda->vsynctime) {
// mda->stat &= ~0x80;
// }
}
if (mda->sc == (mda->crtc[11] & 31) || ((mda->crtc[8] & 3) == 3 && mda->sc == ((mda->crtc[11] & 31) >> 1))) {
mda->con = 0;
mda->coff = 1;
}
if (mda->vadj) {
mda->sc++;
mda->sc &= 31;
mda->ma = mda->maback;
mda->vadj--;
if (!mda->vadj) {
mda->dispon = 1;
mda->ma = mda->maback = (mda->crtc[13] | (mda->crtc[12] << 8)) & 0x3fff;
mda->sc = 0;
}
} else if (mda->sc == mda->crtc[9] || ((mda->crtc[8] & 3) == 3 && mda->sc == (mda->crtc[9] >> 1))) {
mda->maback = mda->ma;
mda->sc = 0;
oldvc = mda->vc;
mda->vc++;
mda->vc &= 127;
if (mda->vc == mda->crtc[6])
mda->dispon = 0;
if (oldvc == mda->crtc[4]) {
mda->vc = 0;
mda->vadj = mda->crtc[5];
if (!mda->vadj)
mda->dispon = 1;
if (!mda->vadj)
mda->ma = mda->maback = (mda->crtc[13] | (mda->crtc[12] << 8)) & 0x3fff;
if ((mda->crtc[10] & 0x60) == 0x20)
mda->cursoron = 0;
else
mda->cursoron = mda->blink & 16;
}
if (mda->vc == mda->crtc[7]) {
mda->dispon = 0;
mda->displine = 0;
mda->vsynctime = 16;
if (mda->crtc[7]) {
x = mda->crtc[1] * 9;
mda->lastline++;
if ((x != xsize) || ((mda->lastline - mda->firstline) != ysize) || video_force_resize_get()) {
xsize = x;
ysize = mda->lastline - mda->firstline;
if (xsize < 64)
xsize = 656;
if (ysize < 32)
ysize = 200;
set_screen_size(xsize, ysize);
if (video_force_resize_get())
video_force_resize_set(0);
}
video_blit_memtoscreen(0, mda->firstline, xsize, ysize);
frames++;
video_res_x = mda->crtc[1];
video_res_y = mda->crtc[6];
video_bpp = 0;
}
mda->firstline = 1000;
mda->lastline = 0;
mda->blink++;
}
} else {
mda->sc++;
mda->sc &= 31;
mda->ma = mda->maback;
}
if (mda->sc == (mda->crtc[10] & 31) || ((mda->crtc[8] & 3) == 3 && mda->sc == ((mda->crtc[10] & 31) >> 1))) {
mda->con = 1;
}
}
VIDEO_MONITOR_EPILOGUE();
}
void
mda_init(mda_t *mda)
{
for (uint16_t c = 0; c < 256; c++) {
mdacols[c][0][0] = mdacols[c][1][0] = mdacols[c][1][1] = 16;
if (c & 8)
mdacols[c][0][1] = 15 + 16;
else
mdacols[c][0][1] = 7 + 16;
}
mdacols[0x70][0][1] = 16;
mdacols[0x70][0][0] = mdacols[0x70][1][0] = mdacols[0x70][1][1] = 16 + 15;
mdacols[0xF0][0][1] = 16;
mdacols[0xF0][0][0] = mdacols[0xF0][1][0] = mdacols[0xF0][1][1] = 16 + 15;
mdacols[0x78][0][1] = 16 + 7;
mdacols[0x78][0][0] = mdacols[0x78][1][0] = mdacols[0x78][1][1] = 16 + 15;
mdacols[0xF8][0][1] = 16 + 7;
mdacols[0xF8][0][0] = mdacols[0xF8][1][0] = mdacols[0xF8][1][1] = 16 + 15;
mdacols[0x00][0][1] = mdacols[0x00][1][1] = 16;
mdacols[0x08][0][1] = mdacols[0x08][1][1] = 16;
mdacols[0x80][0][1] = mdacols[0x80][1][1] = 16;
mdacols[0x88][0][1] = mdacols[0x88][1][1] = 16;
overscan_x = overscan_y = 0;
mda->monitor_index = monitor_index_global;
cga_palette = device_get_config_int("rgb_type") << 1;
if (cga_palette > 6) {
cga_palette = 0;
}
cgapal_rebuild();
timer_add(&mda->timer, mda_poll, mda, 1);
timer_add(&mda->dot_timer, mda_dot_poll, mda, 1);
}
void *
mda_standalone_init(UNUSED(const device_t *info))
{
mda_t *mda = malloc(sizeof(mda_t));
memset(mda, 0, sizeof(mda_t));
video_inform(VIDEO_FLAG_TYPE_MDA, &timing_mda);
mda->vram = malloc(0x1000);
mem_mapping_add(&mda->mapping, 0xb0000, 0x08000, mda_read, NULL, NULL, mda_write, NULL, NULL, NULL, MEM_MAPPING_EXTERNAL, mda);
io_sethandler(0x03b0, 0x0010, mda_in, NULL, NULL, mda_out, NULL, NULL, mda);
mda_init(mda);
lpt3_init(0x3BC);
return mda;
}
void
mda_setcol(int chr, int blink, int fg, uint8_t cga_ink)
{
mdacols[chr][blink][fg] = 16 + cga_ink;
}
void
mda_close(void *priv)
{
mda_t *mda = (mda_t *) priv;
free(mda->vram);
free(mda);
}
void
mda_speed_changed(void *priv)
{
mda_t *mda = (mda_t *) priv;
mda_recalctimings(mda);
}
static const device_config_t mda_config[] = {
// clang-format off
{
.name = "rgb_type",
.description = "Display type",
.type = CONFIG_SELECTION,
.default_int = 0,
.selection = {
{
.description = "Default",
.value = 0
},
{
.description = "Green",
.value = 1
},
{
.description = "Amber",
.value = 2
},
{
.description = "Gray",
.value = 3
},
{
.description = ""
}
}
},
{
.type = CONFIG_END
}
// clang-format on
};
const device_t mda_device = {
.name = "MDA",
.internal_name = "mda",
.flags = DEVICE_ISA,
.local = 0,
.init = mda_standalone_init,
.close = mda_close,
.reset = NULL,
{ .available = NULL },
.speed_changed = mda_speed_changed,
.force_redraw = NULL,
.config = mda_config
};

View File

@@ -0,0 +1,738 @@
/*
* 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.
*
* This file is part of the 86Box distribution.
*
* Oak OTI037C/67/077 emulation.
*
*
*
* Authors: Sarah Walker, <https://pcem-emulator.co.uk/>
* Miran Grca, <mgrca8@gmail.com>
*
* Copyright 2008-2018 Sarah Walker.
* Copyright 2016-2018 Miran Grca.
*/
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <wchar.h>
#include <86box/86box.h>
#include <86box/io.h>
#include <86box/timer.h>
#include <86box/mem.h>
#include <86box/rom.h>
#include <86box/device.h>
#include <86box/video.h>
#include <86box/vid_svga.h>
#include <86box/vid_svga_render.h>
#include <86box/plat_unused.h>
#define BIOS_037C_PATH "roms/video/oti/bios.bin"
#define BIOS_067_AMA932J_PATH "roms/machines/ama932j/OTI067.BIN"
#define BIOS_067_M300_08_PATH "roms/machines/m30008/EVC_BIOS.ROM"
#define BIOS_067_M300_15_PATH "roms/machines/m30015/EVC_BIOS.ROM"
#define BIOS_077_PATH "roms/video/oti/oti077.vbi"
enum {
OTI_037C = 0,
OTI_067 = 2,
OTI_067_AMA932J = 3,
OTI_067_M300 = 4,
OTI_077 = 5
};
typedef struct {
svga_t svga;
rom_t bios_rom;
int index;
uint8_t regs[32];
uint8_t chip_id;
uint8_t pos;
uint8_t enable_register;
uint8_t dipswitch_val;
uint32_t vram_size;
uint32_t vram_mask;
} oti_t;
static video_timings_t timing_oti = { .type = VIDEO_ISA, .write_b = 6, .write_w = 8, .write_l = 16, .read_b = 6, .read_w = 8, .read_l = 16 };
static void
oti_out(uint16_t addr, uint8_t val, void *priv)
{
oti_t *oti = (oti_t *) priv;
svga_t *svga = &oti->svga;
uint8_t old;
uint8_t idx;
uint8_t enable = 0;
uint16_t page = 0x0000;
if (!oti->chip_id && !(oti->enable_register & 1) && (addr != 0x3C3))
return;
if ((((addr & 0xFFF0) == 0x3D0 || (addr & 0xFFF0) == 0x3B0) && addr < 0x3de) && !(svga->miscout & 1))
addr ^= 0x60;
switch (addr) {
case 0x3C3:
if (!oti->chip_id) {
oti->enable_register = val & 1;
return;
}
svga_out(addr, val, svga);
return;
case 0x3c6:
case 0x3c7:
case 0x3c8:
case 0x3c9:
if (oti->chip_id == OTI_077)
sc1148x_ramdac_out(addr, 0, val, svga->ramdac, svga);
else
svga_out(addr, val, svga);
return;
case 0x3D4:
if (oti->chip_id)
svga->crtcreg = val & 0x3f;
else
svga->crtcreg = val; /* FIXME: The BIOS wants to set the test bit? */
return;
case 0x3D5:
if (oti->chip_id && (svga->crtcreg & 0x20))
return;
idx = svga->crtcreg;
if (!oti->chip_id)
idx &= 0x1f;
if ((idx < 7) && (svga->crtc[0x11] & 0x80))
return;
if ((idx == 7) && (svga->crtc[0x11] & 0x80))
val = (svga->crtc[7] & ~0x10) | (val & 0x10);
old = svga->crtc[idx];
svga->crtc[idx] = val;
if (old != val) {
if ((idx < 0x0e) || (idx > 0x10)) {
if (idx == 0x0c || idx == 0x0d) {
svga->fullchange = 3;
svga->ma_latch = ((svga->crtc[0xc] << 8) | svga->crtc[0xd]) + ((svga->crtc[8] & 0x60) >> 5);
} else {
svga->fullchange = changeframecount;
svga_recalctimings(svga);
}
}
}
break;
case 0x3DE:
if (oti->chip_id)
oti->index = val & 0x1f;
else
oti->index = val;
return;
case 0x3DF:
idx = oti->index;
if (!oti->chip_id)
idx &= 0x1f;
oti->regs[idx] = val;
switch (idx) {
case 0xD:
if (oti->chip_id == OTI_067) {
svga->vram_display_mask = (val & 0x0c) ? oti->vram_mask : 0x3ffff;
switch ((val & 0x80) >> 7) {
case 0x00: /* 256 kB of memory */
default:
enable = (oti->vram_size >= 256);
if (val & 0x0c)
svga->vram_display_mask = MIN(oti->vram_mask, 0x3ffff);
break;
case 0x01: /* 512 kB of memory */
enable = (oti->vram_size >= 512);
if (val & 0x0c)
svga->vram_display_mask = MIN(oti->vram_mask, 0x7ffff);
break;
}
if (enable)
mem_mapping_enable(&svga->mapping);
else
mem_mapping_disable(&svga->mapping);
} else if (oti->chip_id == OTI_077) {
svga->vram_display_mask = (val & 0x0c) ? oti->vram_mask : 0x3ffff;
switch ((val & 0xc0) >> 6) {
default:
case 0x00: /* 256 kB of memory */
enable = (oti->vram_size >= 256);
if (val & 0x0c)
svga->vram_display_mask = MIN(oti->vram_mask, 0x3ffff);
break;
case 0x01: /* 1 MB of memory */
case 0x03:
enable = (oti->vram_size >= 1024);
if (val & 0x0c)
svga->vram_display_mask = MIN(oti->vram_mask, 0xfffff);
break;
case 0x02: /* 512 kB of memory */
enable = (oti->vram_size >= 512);
if (val & 0x0c)
svga->vram_display_mask = MIN(oti->vram_mask, 0x7ffff);
break;
}
} else {
if (val & 0x80)
mem_mapping_disable(&svga->mapping);
else
mem_mapping_enable(&svga->mapping);
}
break;
case 0x11:
if (oti->chip_id >= OTI_067) {
page = (((uint16_t) oti->regs[0x14] & 0x40) >> 6);
if (oti->chip_id == OTI_077)
page |= (((uint16_t) oti->regs[0x16] & 0x40) >> 5);
page <<= 18;
}
svga->read_bank = ((uint16_t) oti->regs[0x11] & 0xf) << 14;
svga->write_bank = ((uint16_t) oti->regs[0x11] >> 4) << 14;
svga->read_bank |= page;
svga->write_bank |= page;
break;
case 0x14:
if (oti->chip_id >= OTI_067) {
page = (((uint16_t) oti->regs[0x14] & 0x40) >> 6);
if (oti->chip_id == OTI_077)
page |= (((uint16_t) oti->regs[0x16] & 0x40) >> 5);
page <<= 18;
svga->read_bank = ((uint16_t) oti->regs[0x11] & 0xf) << 14;
svga->write_bank = ((uint16_t) oti->regs[0x11] >> 4) << 14;
svga->read_bank |= page;
svga->write_bank |= page;
}
break;
case 0x16:
if (oti->chip_id == OTI_077) {
page = (((uint16_t) oti->regs[0x14] & 0x40) >> 6);
page |= (((uint16_t) oti->regs[0x16] & 0x40) >> 5);
page <<= 18;
svga->read_bank = ((uint16_t) oti->regs[0x11] & 0xf) << 14;
svga->write_bank = ((uint16_t) oti->regs[0x11] >> 4) << 14;
svga->read_bank |= page;
svga->write_bank |= page;
}
break;
default:
break;
}
return;
default:
break;
}
svga_out(addr, val, svga);
}
static uint8_t
oti_in(uint16_t addr, void *priv)
{
oti_t *oti = (oti_t *) priv;
svga_t *svga = &oti->svga;
uint8_t idx;
uint8_t temp;
if (!oti->chip_id && !(oti->enable_register & 1) && (addr != 0x3C3))
return 0xff;
if ((((addr & 0xFFF0) == 0x3D0 || (addr & 0xFFF0) == 0x3B0) && addr < 0x3de) && !(svga->miscout & 1))
addr ^= 0x60;
switch (addr) {
case 0x3C2:
if ((svga->vgapal[0].r + svga->vgapal[0].g + svga->vgapal[0].b) >= 0x50)
temp = 0;
else
temp = 0x10;
break;
case 0x3C3:
if (oti->chip_id)
temp = svga_in(addr, svga);
else
temp = oti->enable_register;
break;
case 0x3c6:
case 0x3c7:
case 0x3c8:
case 0x3c9:
if (oti->chip_id == OTI_077)
return sc1148x_ramdac_in(addr, 0, svga->ramdac, svga);
return svga_in(addr, svga);
case 0x3CF:
return svga->gdcreg[svga->gdcaddr & 0xf];
case 0x3D4:
temp = svga->crtcreg;
break;
case 0x3D5:
if (oti->chip_id) {
if (svga->crtcreg & 0x20)
temp = 0xff;
else
temp = svga->crtc[svga->crtcreg];
} else
temp = svga->crtc[svga->crtcreg & 0x1f];
break;
case 0x3DA:
if (oti->chip_id) {
temp = svga_in(addr, svga);
break;
}
svga->attrff = 0;
/*The OTI-037C BIOS waits for bits 0 and 3 in 0x3da to go low, then reads 0x3da again
and expects the diagnostic bits to equal the current border colour. As I understand
it, the 0x3da active enable status does not include the border time, so this may be
an area where OTI-037C is not entirely VGA compatible.*/
svga->cgastat &= ~0x30;
/* copy color diagnostic info from the overscan color register */
switch (svga->attrregs[0x12] & 0x30) {
case 0x00: /* P0 and P2 */
if (svga->attrregs[0x11] & 0x01)
svga->cgastat |= 0x10;
if (svga->attrregs[0x11] & 0x04)
svga->cgastat |= 0x20;
break;
case 0x10: /* P4 and P5 */
if (svga->attrregs[0x11] & 0x10)
svga->cgastat |= 0x10;
if (svga->attrregs[0x11] & 0x20)
svga->cgastat |= 0x20;
break;
case 0x20: /* P1 and P3 */
if (svga->attrregs[0x11] & 0x02)
svga->cgastat |= 0x10;
if (svga->attrregs[0x11] & 0x08)
svga->cgastat |= 0x20;
break;
case 0x30: /* P6 and P7 */
if (svga->attrregs[0x11] & 0x40)
svga->cgastat |= 0x10;
if (svga->attrregs[0x11] & 0x80)
svga->cgastat |= 0x20;
break;
default:
break;
}
temp = svga->cgastat;
break;
case 0x3DE:
temp = oti->index;
if (oti->chip_id)
temp |= (oti->chip_id << 5);
break;
case 0x3DF:
idx = oti->index;
if (!oti->chip_id)
idx &= 0x1f;
if (idx == 0x10)
temp = oti->dipswitch_val;
else
temp = oti->regs[idx];
break;
default:
temp = svga_in(addr, svga);
break;
}
return temp;
}
static void
oti_pos_out(UNUSED(uint16_t addr), uint8_t val, void *priv)
{
oti_t *oti = (oti_t *) priv;
if ((val ^ oti->pos) & 8) {
if (val & 8)
io_sethandler(0x03c0, 32, oti_in, NULL, NULL,
oti_out, NULL, NULL, oti);
else
io_removehandler(0x03c0, 32, oti_in, NULL, NULL,
oti_out, NULL, NULL, oti);
}
oti->pos = val;
}
static uint8_t
oti_pos_in(UNUSED(uint16_t addr), void *priv)
{
const oti_t *oti = (oti_t *) priv;
return (oti->pos);
}
static float
oti_getclock(int clock)
{
float ret = 0.0;
switch (clock) {
default:
case 0:
ret = 25175000.0;
break;
case 1:
ret = 28322000.0;
break;
case 4:
ret = 14318000.0;
break;
case 5:
ret = 16257000.0;
break;
case 7:
ret = 35500000.0;
break;
}
return ret;
}
static void
oti_recalctimings(svga_t *svga)
{
const oti_t *oti = (oti_t *) svga->priv;
int clk_sel = ((svga->miscout >> 2) & 3) | ((oti->regs[0x0d] & 0x20) >> 3);
svga->clock = (cpuclock * (double) (1ULL << 32)) / oti_getclock(clk_sel);
if (oti->chip_id > 0) {
if (oti->regs[0x14] & 0x08)
svga->ma_latch |= 0x10000;
if (oti->regs[0x16] & 0x08)
svga->ma_latch |= 0x20000;
if (oti->regs[0x14] & 0x01)
svga->vtotal += 0x400;
if (oti->regs[0x14] & 0x02)
svga->dispend += 0x400;
if (oti->regs[0x14] & 0x04)
svga->vsyncstart += 0x400;
svga->interlace = oti->regs[0x14] & 0x80;
}
if ((oti->regs[0x0d] & 0x0c) && !(oti->regs[0x0d] & 0x10))
svga->rowoffset <<= 1;
if (svga->bpp == 16) {
svga->render = svga_render_16bpp_highres;
svga->hdisp >>= 1;
} else if (svga->bpp == 15) {
svga->render = svga_render_15bpp_highres;
svga->hdisp >>= 1;
}
}
static void *
oti_init(const device_t *info)
{
oti_t *oti = malloc(sizeof(oti_t));
const char *romfn = NULL;
memset(oti, 0x00, sizeof(oti_t));
oti->chip_id = info->local;
oti->dipswitch_val = 0x18;
switch (oti->chip_id) {
case OTI_037C:
romfn = BIOS_037C_PATH;
oti->vram_size = 256;
oti->regs[0] = 0x08; /* FIXME: The BIOS wants to read this at index 0? This index is undocumented. */
#if 0
io_sethandler(0x03c0, 32,
oti_in, NULL, NULL, oti_out, NULL, NULL, oti);
#endif
break;
case OTI_067_AMA932J:
romfn = BIOS_067_AMA932J_PATH;
oti->chip_id = 2;
oti->vram_size = device_get_config_int("memory");
oti->dipswitch_val |= 0x20;
oti->pos = 0x08; /* Tell the BIOS the I/O ports are already enabled to avoid a double I/O handler mess. */
io_sethandler(0x46e8, 1, oti_pos_in, NULL, NULL, oti_pos_out, NULL, NULL, oti);
break;
case OTI_067_M300:
if (rom_present(BIOS_067_M300_15_PATH))
romfn = BIOS_067_M300_15_PATH;
else
romfn = BIOS_067_M300_08_PATH;
oti->vram_size = device_get_config_int("memory");
oti->pos = 0x08; /* Tell the BIOS the I/O ports are already enabled to avoid a double I/O handler mess. */
io_sethandler(0x46e8, 1, oti_pos_in, NULL, NULL, oti_pos_out, NULL, NULL, oti);
break;
case OTI_067:
case OTI_077:
romfn = BIOS_077_PATH;
oti->vram_size = device_get_config_int("memory");
oti->pos = 0x08; /* Tell the BIOS the I/O ports are already enabled to avoid a double I/O handler mess. */
io_sethandler(0x46e8, 1, oti_pos_in, NULL, NULL, oti_pos_out, NULL, NULL, oti);
break;
default:
break;
}
if (romfn != NULL) {
rom_init(&oti->bios_rom, romfn,
0xc0000, 0x8000, 0x7fff, 0, MEM_MAPPING_EXTERNAL);
}
video_inform(VIDEO_FLAG_TYPE_SPECIAL, &timing_oti);
svga_init(info, &oti->svga, oti, oti->vram_size << 10,
oti_recalctimings, oti_in, oti_out, NULL, NULL);
oti->vram_mask = (oti->vram_size << 10) - 1;
if (oti->chip_id == OTI_077)
oti->svga.ramdac = device_add(&sc11487_ramdac_device); /*Actually a 82c487, probably a clone.*/
io_sethandler(0x03c0, 32,
oti_in, NULL, NULL, oti_out, NULL, NULL, oti);
oti->svga.miscout = 1;
oti->svga.packed_chain4 = 1;
return oti;
}
static void
oti_close(void *priv)
{
oti_t *oti = (oti_t *) priv;
svga_close(&oti->svga);
free(oti);
}
static void
oti_speed_changed(void *priv)
{
oti_t *oti = (oti_t *) priv;
svga_recalctimings(&oti->svga);
}
static void
oti_force_redraw(void *priv)
{
oti_t *oti = (oti_t *) priv;
oti->svga.fullchange = changeframecount;
}
static int
oti037c_available(void)
{
return (rom_present(BIOS_037C_PATH));
}
static int
oti067_ama932j_available(void)
{
return (rom_present(BIOS_067_AMA932J_PATH));
}
static int
oti067_077_available(void)
{
return (rom_present(BIOS_077_PATH));
}
static int
oti067_m300_available(void)
{
if (rom_present(BIOS_067_M300_15_PATH))
return (rom_present(BIOS_067_M300_15_PATH));
else
return (rom_present(BIOS_067_M300_08_PATH));
}
// clang-format off
static const device_config_t oti067_config[] = {
{
.name = "memory",
.description = "Memory size",
.type = CONFIG_SELECTION,
.default_int = 512,
.selection = {
{
.description = "256 kB",
.value = 256
},
{
.description = "512 kB",
.value = 512
},
{
.description = ""
}
}
},
{
.type = CONFIG_END
}
};
static const device_config_t oti067_ama932j_config[] = {
{
.name = "memory",
.description = "Memory size",
.type = CONFIG_SELECTION,
.default_int = 256,
.selection = {
{
.description = "256 kB",
.value = 256
},
{
.description = "512 kB",
.value = 512
},
{
.description = ""
}
}
},
{
.type = CONFIG_END
}
};
static const device_config_t oti077_config[] = {
{
.name = "memory",
.description = "Memory size",
.type = CONFIG_SELECTION,
.default_int = 1024,
.selection = {
{
.description = "256 kB",
.value = 256
},
{
.description = "512 kB",
.value = 512
},
{
.description = "1 MB",
.value = 1024
},
{
.description = ""
}
}
},
{
.type = CONFIG_END
}
};
// clang-format on
const device_t oti037c_device = {
.name = "Oak OTI-037C",
.internal_name = "oti037c",
.flags = DEVICE_ISA,
.local = 0,
.init = oti_init,
.close = oti_close,
.reset = NULL,
{ .available = oti037c_available },
.speed_changed = oti_speed_changed,
.force_redraw = oti_force_redraw,
.config = NULL
};
const device_t oti067_device = {
.name = "Oak OTI-067",
.internal_name = "oti067",
.flags = DEVICE_ISA,
.local = 2,
.init = oti_init,
.close = oti_close,
.reset = NULL,
{ .available = oti067_077_available },
.speed_changed = oti_speed_changed,
.force_redraw = oti_force_redraw,
.config = oti067_config
};
const device_t oti067_m300_device = {
.name = "Oak OTI-067 (Olivetti M300-08/15)",
.internal_name = "oti067_m300",
.flags = DEVICE_ISA,
.local = 4,
.init = oti_init,
.close = oti_close,
.reset = NULL,
{ .available = oti067_m300_available },
.speed_changed = oti_speed_changed,
.force_redraw = oti_force_redraw,
.config = oti067_config
};
const device_t oti067_ama932j_device = {
.name = "Oak OTI-067 (AMA-932J)",
.internal_name = "oti067_ama932j",
.flags = DEVICE_ISA,
.local = 3,
.init = oti_init,
.close = oti_close,
.reset = NULL,
{ .available = oti067_ama932j_available },
.speed_changed = oti_speed_changed,
.force_redraw = oti_force_redraw,
.config = oti067_ama932j_config
};
const device_t oti077_device = {
.name = "Oak OTI-077",
.internal_name = "oti077",
.flags = DEVICE_ISA,
.local = 5,
.init = oti_init,
.close = oti_close,
.reset = NULL,
{ .available = oti067_077_available },
.speed_changed = oti_speed_changed,
.force_redraw = oti_force_redraw,
.config = oti077_config
};