diff --git a/src/device/keyboard_at.c b/src/device/keyboard_at.c index 1164c7007..e63b5175d 100644 --- a/src/device/keyboard_at.c +++ b/src/device/keyboard_at.c @@ -86,6 +86,7 @@ #define KBC_VEN_IBM_PS1 0x18 #define KBC_VEN_ACER 0x1c #define KBC_VEN_INTEL_AMI 0x20 +#define KBC_VEN_OLIVETTI 0x24 #define KBC_VEN_MASK 0x3c @@ -830,6 +831,8 @@ add_data_kbd(uint16_t val) int translate = (keyboard_mode & 0x40); uint8_t fake_shift[4]; uint8_t num_lock = 0, shift_states = 0; + uint8_t kbc_ven = 0x0; + kbc_ven = dev->flags & KBC_VEN_MASK; if (dev->reset_delay) return; @@ -855,7 +858,7 @@ add_data_kbd(uint16_t val) } /* Test for T3100E 'Fn' key (Right Alt / Right Ctrl) */ - if ((dev != NULL) && ((dev->flags & KBC_VEN_MASK) == KBC_VEN_TOSHIBA) && + if ((dev != NULL) && (kbc_ven == KBC_VEN_TOSHIBA) && (keyboard_recv(0xb8) || keyboard_recv(0x9d))) switch (val) { case 0x4f: t3100e_notify_set(0x01); break; /* End */ case 0x50: t3100e_notify_set(0x02); break; /* Down */ @@ -1065,6 +1068,8 @@ static void write_cmd(atkbd_t *dev, uint8_t val) { kbd_log("ATkbc: write command byte: %02X (old: %02X)\n", val, dev->mem[0]); + uint8_t kbc_ven = 0x0; + kbc_ven = dev->flags & KBC_VEN_MASK; if ((val & 1) && (dev->status & STAT_OFULL)) dev->wantirq = 1; @@ -1086,7 +1091,7 @@ write_cmd(atkbd_t *dev, uint8_t val) /* ISA AT keyboard controllers use bit 5 for keyboard mode (1 = PC/XT, 2 = AT); PS/2 (and EISA/PCI) keyboard controllers use it as the PS/2 mouse enable switch. The AMIKEY firmware apparently uses this bit for something else. */ - if (((dev->flags & KBC_VEN_MASK) == KBC_VEN_AMI) || + if ((kbc_ven == KBC_VEN_AMI) || ((dev->flags & KBC_TYPE_MASK) >= KBC_TYPE_PS2_NOREF)) { keyboard_mode &= ~CCB_PCMODE; @@ -1138,6 +1143,9 @@ write64_generic(void *priv, uint8_t val) { atkbd_t *dev = (atkbd_t *)priv; uint8_t current_drive, fixed_bits; + uint8_t kbc_ven = 0x0; + kbc_ven = dev->flags & KBC_VEN_MASK; + switch (val) { case 0xa4: /* check if password installed */ @@ -1181,9 +1189,9 @@ write64_generic(void *priv, uint8_t val) kbd_log("ATkbc: read input port\n"); fixed_bits = 4; /* The SMM handlers of Intel AMI Pentium BIOS'es expect bit 6 to be set. */ - if ((dev->flags & KBC_VEN_MASK) == KBC_VEN_INTEL_AMI) + if (kbc_ven == KBC_VEN_INTEL_AMI) fixed_bits |= 0x40; - if ((dev->flags & KBC_VEN_MASK) == KBC_VEN_IBM_PS1) { + if (kbc_ven == KBC_VEN_IBM_PS1) { current_drive = fdc_get_current_drive(); add_to_kbc_queue_front(dev, dev->input_port | fixed_bits | (fdd_is_525(current_drive) ? 0x40 : 0x00)); dev->input_port = ((dev->input_port + 1) & 3) | @@ -1616,8 +1624,11 @@ kbd_write(uint16_t port, uint8_t val, void *priv) int i = 0; int bad = 1; uint8_t mask; + uint8_t kbc_ven = 0x0; + kbc_ven = dev->flags & KBC_VEN_MASK; - if (((dev->flags & KBC_VEN_MASK) == KBC_VEN_XI8088) && (port == 0x63)) + + if ((kbc_ven == KBC_VEN_XI8088) && (port == 0x63)) port = 0x61; kbd_log((port == 0x61) ? "" : "ATkbc: write(%04X, %02X)\n", port, val); @@ -1894,7 +1905,7 @@ kbd_write(uint16_t port, uint8_t val, void *priv) was_speaker_enable = 1; pit_ctr_set_gate(&pit->counters[2], val & 1); - if ((dev->flags & KBC_VEN_MASK) == KBC_VEN_XI8088) + if (kbc_ven == KBC_VEN_XI8088) xi8088_turbo_set(!!(val & 0x04)); break; @@ -1930,7 +1941,7 @@ kbd_write(uint16_t port, uint8_t val, void *priv) case 0xaa: /* self-test */ kbd_log("ATkbc: self-test\n"); - if ((dev->flags & KBC_VEN_MASK) == KBC_VEN_TOSHIBA) + if (kbc_ven == KBC_VEN_TOSHIBA) dev->status |= STAT_IFULL; if (! dev->initialized) { kbd_log("ATkbc: self-test reinitialization\n"); @@ -2045,11 +2056,13 @@ kbd_read(uint16_t port, void *priv) { atkbd_t *dev = (atkbd_t *)priv; uint8_t ret = 0xff; + uint8_t kbc_ven = 0x0; + kbc_ven = dev->flags & KBC_VEN_MASK; if ((dev->flags & KBC_TYPE_MASK) >= KBC_TYPE_PS2_NOREF) cycles -= ISA_CYCLES(8); - if (((dev->flags & KBC_VEN_MASK) == KBC_VEN_XI8088) && (port == 0x63)) + if ((kbc_ven == KBC_VEN_XI8088) && (port == 0x63)) port = 0x61; switch (port) { @@ -2078,14 +2091,47 @@ kbd_read(uint16_t port, void *priv) else ret &= ~0x10; } - if ((dev->flags & KBC_VEN_MASK) == KBC_VEN_XI8088) { + if (kbc_ven == KBC_VEN_XI8088) { if (xi8088_turbo_get()) - ret |= 0x04; - else - ret &= ~0x04; - } + ret |= 0x04; + else + ret &= ~0x04; + } break; + case 0x62: + ret = 0xff; + if (kbc_ven == KBC_VEN_OLIVETTI) { + /* SWA on Olivetti M240 mainboard (off=1) */ + ret = 0x00; + if (ppi.pb & 0x8) { + /* Switches 4, 5 - floppy drives (number) */ + int i, fdd_count = 0; + for (i = 0; i < FDD_NUM; i++) { + if (fdd_get_flags(i)) + fdd_count++; + } + if (!fdd_count) + ret |= 0x00; + else + ret |= ((fdd_count - 1) << 2); + /* Switches 6, 7 - monitor type */ + if (video_is_mda()) + ret |= 0x3; + else if (video_is_cga()) + ret |= 0x2; /* 0x10 would be 40x25 */ + else + ret |= 0x0; + ret = 0xff; + } else { + /* bit 2 always on */ + ret |= 0x4; + /* Switch 8 - 8087 FPU. */ + if (hasfpu) + ret |= 0x02; + } + } + break; case 0x64: ret = (dev->status & 0xfb); if (dev->mem[0] & STAT_SYSFLAG) @@ -2094,7 +2140,7 @@ kbd_read(uint16_t port, void *priv) PS/2 controller, it is the keyboard/mouse output source bit. */ dev->status &= ~STAT_RTIMEOUT; if (((dev->flags & KBC_TYPE_MASK) > KBC_TYPE_PS2_NOREF) && - ((dev->flags & KBC_VEN_MASK) != KBC_VEN_IBM_MCA)) + (kbc_ven != KBC_VEN_IBM_MCA)) dev->status &= ~STAT_TTIMEOUT; break; @@ -2124,6 +2170,8 @@ kbd_reset(void *priv) { atkbd_t *dev = (atkbd_t *)priv; int i; + uint8_t kbc_ven = 0x0; + kbc_ven = dev->flags & KBC_VEN_MASK; dev->initialized = 0; dev->first_write = 1; @@ -2139,10 +2187,10 @@ kbd_reset(void *priv) dev->key_wantdata = 0; /* Set up the correct Video Type bits. */ - if (((dev->flags & KBC_VEN_MASK) == KBC_VEN_XI8088) || ((dev->flags & KBC_VEN_MASK) == KBC_VEN_ACER)) - dev->input_port = video_is_mda() ? 0xb0 : 0xf0; + if ((kbc_ven == KBC_VEN_XI8088) || (kbc_ven == KBC_VEN_ACER)) + dev->input_port = video_is_mda() ? 0xb0 : 0xf0; else - dev->input_port = video_is_mda() ? 0xf0 : 0xb0; + dev->input_port = video_is_mda() ? 0xf0 : 0xb0; kbd_log("ATkbc: input port = %02x\n", dev->input_port); keyboard_mode = 0x02 | (dev->mem[0] & CCB_TRANSLATE); @@ -2228,6 +2276,7 @@ kbd_init(const device_t *info) switch(dev->flags & KBC_VEN_MASK) { case KBC_VEN_ACER: case KBC_VEN_GENERIC: + case KBC_VEN_OLIVETTI: case KBC_VEN_IBM_PS1: case KBC_VEN_XI8088: dev->write64_ven = write64_generic; @@ -2291,6 +2340,16 @@ const device_t keyboard_at_toshiba_device = { { NULL }, NULL, NULL, NULL }; +const device_t keyboard_at_olivetti_device = { + "PC/AT Keyboard (Olivetti)", + 0, + KBC_TYPE_ISA | KBC_VEN_OLIVETTI, + kbd_init, + kbd_close, + kbd_reset, + { NULL }, NULL, NULL, NULL +}; + const device_t keyboard_ps2_device = { "PS/2 Keyboard", 0, diff --git a/src/device/keyboard_xt.c b/src/device/keyboard_xt.c index c46d02c87..9a234b6eb 100644 --- a/src/device/keyboard_xt.c +++ b/src/device/keyboard_xt.c @@ -13,10 +13,12 @@ * Authors: Sarah Walker, * Miran Grca, * Fred N. van Kempen, + * EngiNerd, * * Copyright 2008-2019 Sarah Walker. * Copyright 2016-2019 Miran Grca. * Copyright 2017-2019 Fred N. van kempen. + * Copyright 2020 EngiNerd. */ #include #include @@ -551,7 +553,15 @@ kbd_read(uint16_t port, void *priv) ret = ((mem_size-64) / 32) & 0x0f; else ret = ((mem_size-64) / 32) >> 4; - } else { + } + else if (kbd->type == 8) { + /* Olivetti M19 */ + if (kbd->pb & 0x04) + ret = kbd->pd; + else + ret = kbd->pd >> 4; + } + else { if (kbd->pb & 0x08) ret = kbd->pd >> 4; else { @@ -623,82 +633,94 @@ kbd_init(const device_t *info) video_reset(gfxcard); - if (kbd->type <= 3) { - for (i = 0; i < FDD_NUM; i++) { - if (fdd_get_flags(i)) - fdd_count++; - } + if (kbd->type <= 3 || kbd-> type == 8) { + for (i = 0; i < FDD_NUM; i++) { + if (fdd_get_flags(i)) + fdd_count++; + } - /* DIP switch readout: bit set = OFF, clear = ON. */ - /* Switches 7, 8 - floppy drives. */ - if (!fdd_count) - kbd->pd = 0x00; - else - kbd->pd = ((fdd_count - 1) << 6) | 0x01; - /* Switches 5, 6 - video. */ - if (video_is_mda()) - kbd->pd |= 0x30; - else if (video_is_cga()) - kbd->pd |= 0x20; /* 0x10 would be 40x25 */ - else - kbd->pd |= 0x00; - /* Switches 3, 4 - memory size. */ - if ((kbd->type == 3) || (kbd->type == 4) || (kbd->type == 6)) { - switch (mem_size) { - case 256: - kbd->pd |= 0x00; - break; - case 512: - kbd->pd |= 0x04; - break; - case 576: - kbd->pd |= 0x08; - break; - case 640: - default: - kbd->pd |= 0x0c; - break; - } - } else if (kbd->type >= 1) { - switch (mem_size) { - case 64: - kbd->pd |= 0x00; - break; - case 128: - kbd->pd |= 0x04; - break; - case 192: - kbd->pd |= 0x08; - break; - case 256: - default: - kbd->pd |= 0x0c; - break; - } - } else { - switch (mem_size) { - case 16: - kbd->pd |= 0x00; - break; - case 32: - kbd->pd |= 0x04; - break; - case 48: - kbd->pd |= 0x08; - break; - case 64: - default: - kbd->pd |= 0x0c; - break; - } - } + /* DIP switch readout: bit set = OFF, clear = ON. */ + if (kbd->type != 8) + /* Switches 7, 8 - floppy drives. */ + if (!fdd_count) + kbd->pd = 0x00; + else + kbd->pd = ((fdd_count - 1) << 6) | 0x01; + else + /* Jumpers J1, J2 - monitor type. + * 01 - mono (high-res) + * 10 - color (low-res, disables 640x400x2 mode) + * 00 - autoswitching + */ + kbd->pd |= 0x00; + + /* Switches 5, 6 - video. */ + if (video_is_mda()) + kbd->pd |= 0x30; + else if (video_is_cga()) + kbd->pd |= 0x20; /* 0x10 would be 40x25 */ + else + kbd->pd |= 0x00; + + /* Switches 3, 4 - memory size. */ + // Note to Compaq/Toshiba keyboard maintainers: type 4 and 6 will never be activated in this block + // Should the top if be closed right after setting floppy drive count? + if ((kbd->type == 3) || (kbd->type == 4) || (kbd->type == 6)) { + switch (mem_size) { + case 256: + kbd->pd |= 0x00; + break; + case 512: + kbd->pd |= 0x04; + break; + case 576: + kbd->pd |= 0x08; + break; + case 640: + default: + kbd->pd |= 0x0c; + break; + } + } else if (kbd->type >= 1) { + switch (mem_size) { + case 64: + kbd->pd |= 0x00; + break; + case 128: + kbd->pd |= 0x04; + break; + case 192: + kbd->pd |= 0x08; + break; + case 256: + default: + kbd->pd |= 0x0c; + break; + } + } else { + switch (mem_size) { + case 16: + kbd->pd |= 0x00; + break; + case 32: + kbd->pd |= 0x04; + break; + case 48: + kbd->pd |= 0x08; + break; + case 64: + default: + kbd->pd |= 0x0c; + break; + } + } - /* Switch 2 - 8087 FPU. */ - if (hasfpu) - kbd->pd |= 0x02; + /* Switch 2 - 8087 FPU. */ + if (hasfpu) + kbd->pd |= 0x02; - /* Switch 1 - always off. */ - kbd->pd |= 0x01; + /* Switch 1 - always off. */ + kbd->pd |= 0x01; } timer_add(&kbd->send_delay_timer, kbd_poll, kbd, 1); @@ -812,3 +834,13 @@ const device_t keyboard_xt_lxt3_device = { { NULL }, NULL, NULL }; #endif + +const device_t keyboard_xt_olivetti_device = { + "Olivetti XT Keyboard", + 0, + 8, + kbd_init, + kbd_close, + kbd_reset, + { NULL }, NULL, NULL +}; diff --git a/src/include/86box/keyboard.h b/src/include/86box/keyboard.h index 90a3ab095..3785a8f6d 100644 --- a/src/include/86box/keyboard.h +++ b/src/include/86box/keyboard.h @@ -68,9 +68,11 @@ extern const device_t keyboard_tandy_device; #if defined(DEV_BRANCH) && defined(USE_LASERXT) extern const device_t keyboard_xt_lxt3_device; #endif +extern const device_t keyboard_xt_olivetti_device; extern const device_t keyboard_at_device; extern const device_t keyboard_at_ami_device; extern const device_t keyboard_at_toshiba_device; +extern const device_t keyboard_at_olivetti_device; extern const device_t keyboard_ps2_device; extern const device_t keyboard_ps2_ps1_device; extern const device_t keyboard_ps2_ps1_pci_device; diff --git a/src/include/86box/machine.h b/src/include/86box/machine.h index 9e63418c7..380aacaf8 100644 --- a/src/include/86box/machine.h +++ b/src/include/86box/machine.h @@ -509,8 +509,10 @@ extern int machine_europc_init(const machine_t *); extern const device_t europc_device; #endif -/* m_oivetti_m24.c */ -extern int machine_olim24_init(const machine_t *); +/* m_xt_olivetti.c */ +extern int machine_xt_olim24_init(const machine_t *); +extern int machine_xt_olim240_init(const machine_t *); +extern int machine_xt_olim19_init(const machine_t *); #ifdef EMU_DEVICE_H extern const device_t *m24_get_device(void); #endif diff --git a/src/include/86box/vid_ogc.h b/src/include/86box/vid_ogc.h new file mode 100644 index 000000000..2fffa65c3 --- /dev/null +++ b/src/include/86box/vid_ogc.h @@ -0,0 +1,48 @@ +/* + * 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 Olivetti OGC 8-bit ISA (GO708) and + * M21/M24/M28 16-bit bus (GO317/318/380/709) video cards. + * + * + * + * Authors: Sarah Walker, + * Miran Grca, + * Fred N. van Kempen, + * EngiNerd, + * + * Copyright 2008-2019 Sarah Walker. + * Copyright 2016-2019 Miran Grca. + * Copyright 2017-2019 Fred N. van Kempen. + * Copyright 2020 EngiNerd. + */ + +typedef struct ogc_t { + cga_t cga; + /* unused in OGC, required for M19 video card structure idiom */ + uint8_t ctrl_3dd; + uint8_t ctrl_3de; + uint32_t base; + int lineff; + int mono_display; +} ogc_t; + +void ogc_recalctimings(ogc_t *ogc); +void ogc_out(uint16_t addr, uint8_t val, void *priv); +uint8_t ogc_in(uint16_t addr, void *priv); +void ogc_write(uint32_t addr, uint8_t val, void *priv); +uint8_t ogc_read(uint32_t addr, void *priv); +void ogc_poll(void *priv); +void ogc_close(void *priv); +void ogc_mdaattr_rebuild(); + + +#ifdef EMU_DEVICE_H +extern const device_config_t ogc_config[]; +extern const device_t ogc_device; +#endif diff --git a/src/include/86box/video.h b/src/include/86box/video.h index 6640827ce..959912ac4 100644 --- a/src/include/86box/video.h +++ b/src/include/86box/video.h @@ -241,6 +241,10 @@ extern const device_t gd5480_pci_device; extern const device_t compaq_cga_device; extern const device_t compaq_cga_2_device; +/* Olivetti OGC */ +extern const device_t ogc_device; +extern const device_t ogc_m24_device; + /* Tseng ET4000AX */ extern const device_t et4000_isa_device; extern const device_t et4000k_isa_device; diff --git a/src/machine/m_olivetti_m24.c b/src/machine/m_olivetti_m24.c deleted file mode 100644 index 216e926f3..000000000 --- a/src/machine/m_olivetti_m24.c +++ /dev/null @@ -1,910 +0,0 @@ -/* - * 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 Olivetti M24. - * - * - * - * Authors: Sarah Walker, - * Miran Grca, - * Fred N. van Kempen, - * - * Copyright 2008-2019 Sarah Walker. - * Copyright 2016-2019 Miran Grca. - * Copyright 2017-2019 Fred N. van Kempen. - */ -#include -#include -#include -#include -#include -#include -#include <86box/86box.h> -#include <86box/timer.h> -#include <86box/io.h> -#include <86box/pic.h> -#include <86box/pit.h> -#include <86box/ppi.h> -#include <86box/nmi.h> -#include <86box/mem.h> -#include <86box/device.h> -#include <86box/nvr.h> -#include <86box/keyboard.h> -#include <86box/mouse.h> -#include <86box/rom.h> -#include <86box/fdd.h> -#include <86box/fdc.h> -#include <86box/gameport.h> -#include <86box/sound.h> -#include <86box/snd_speaker.h> -#include <86box/video.h> -#include <86box/machine.h> - - -#define STAT_PARITY 0x80 -#define STAT_RTIMEOUT 0x40 -#define STAT_TTIMEOUT 0x20 -#define STAT_LOCK 0x10 -#define STAT_CD 0x08 -#define STAT_SYSFLAG 0x04 -#define STAT_IFULL 0x02 -#define STAT_OFULL 0x01 - - -typedef struct { - /* Video stuff. */ - mem_mapping_t mapping; - uint8_t crtc[32]; - int crtcreg; - uint8_t monitor_type, port_23c6; - uint8_t *vram; - uint8_t charbuffer[256]; - uint8_t ctrl; - uint32_t base; - uint8_t cgamode, cgacol; - uint8_t stat; - int linepos, displine; - int sc, vc; - int con, coff, cursoron, blink; - int vsynctime; - int vadj; - int lineff; - uint16_t ma, maback; - int dispon; - uint64_t dispontime, dispofftime; - pc_timer_t timer; - int firstline, lastline; - - /* Keyboard stuff. */ - int wantirq; - uint8_t command; - uint8_t status; - uint8_t out; - uint8_t output_port; - int param, - param_total; - uint8_t params[16]; - uint8_t scan[7]; - - /* Mouse stuff. */ - int mouse_mode; - int x, y, b; - pc_timer_t send_delay_timer; -} olim24_t; - -static video_timings_t timing_m24 = {VIDEO_ISA, 8,16,32, 8,16,32}; - - -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 uint8_t key_queue[16]; -static int key_queue_start = 0, - key_queue_end = 0; - - - -#ifdef ENABLE_M24VID_LOG -int m24vid_do_log = ENABLE_M24VID_LOG; - - -static void -m24_log(const char *fmt, ...) -{ - va_list ap; - - if (m24vid_do_log) { - va_start(ap, fmt); - vfprintf(stdlog, fmt, ap); - va_end(ap); - fflush(stdlog); - } -} -#else -#define m24_log(fmt, ...) -#endif - - -static void -recalc_timings(olim24_t *m24) -{ - double _dispontime, _dispofftime, disptime; - - if (m24->cgamode & 1) { - disptime = m24->crtc[0] + 1; - _dispontime = m24->crtc[1]; - } else { - disptime = (m24->crtc[0] + 1) << 1; - _dispontime = m24->crtc[1] << 1; - } - - _dispofftime = disptime - _dispontime; - _dispontime *= CGACONST / 2; - _dispofftime *= CGACONST / 2; - m24->dispontime = (uint64_t)(_dispontime); - m24->dispofftime = (uint64_t)(_dispofftime); -} - - -static void -vid_out(uint16_t addr, uint8_t val, void *priv) -{ - olim24_t *m24 = (olim24_t *)priv; - uint8_t old; - - switch (addr) { - case 0x3d4: - m24->crtcreg = val & 31; - break; - - case 0x3d5: - old = m24->crtc[m24->crtcreg]; - m24->crtc[m24->crtcreg] = val & crtcmask[m24->crtcreg]; - if (old != val) { - if (m24->crtcreg < 0xe || m24->crtcreg > 0x10) { - fullchange = changeframecount; - recalc_timings(m24); - } - } - break; - - case 0x3d8: - m24->cgamode = val; - break; - - case 0x3d9: - m24->cgacol = val; - break; - - case 0x3de: - m24->ctrl = val; - m24->base = (val & 0x08) ? 0x4000 : 0; - break; - - case 0x13c6: - m24->monitor_type = val; - break; - - case 0x23c6: - m24->port_23c6 = val; - break; - } -} - - -static uint8_t -vid_in(uint16_t addr, void *priv) -{ - olim24_t *m24 = (olim24_t *)priv; - uint8_t ret = 0xff; - - switch (addr) { - case 0x3d4: - ret = m24->crtcreg; - break; - - case 0x3d5: - ret = m24->crtc[m24->crtcreg]; - break; - - case 0x3da: - ret = m24->stat; - break; - - case 0x13c6: - ret = m24->monitor_type; - break; - - case 0x23c6: - ret = m24->port_23c6; - break; - } - - return(ret); -} - - -static void -vid_write(uint32_t addr, uint8_t val, void *priv) -{ - olim24_t *m24 = (olim24_t *)priv; - int offset; - - m24->vram[addr & 0x7FFF]=val; - offset = ((timer_get_remaining_u64(&m24->timer) / CGACONST) * 4) & 0xfc; - m24->charbuffer[offset] = m24->vram[addr & 0x7fff]; - m24->charbuffer[offset | 1] = m24->vram[addr & 0x7fff]; -} - - -static uint8_t -vid_read(uint32_t addr, void *priv) -{ - olim24_t *m24 = (olim24_t *)priv; - - return(m24->vram[addr & 0x7FFF]); -} - - -static void -vid_poll(void *priv) -{ - olim24_t *m24 = (olim24_t *)priv; - uint16_t ca = (m24->crtc[15] | (m24->crtc[14] << 8)) & 0x3fff; - int drawcursor; - int x, c, xs_temp, ys_temp; - int oldvc; - uint8_t chr, attr; - uint16_t dat, dat2; - int cols[4]; - int col; - int oldsc; - - if (!m24->linepos) { - timer_advance_u64(&m24->timer, m24->dispofftime); - m24->stat |= 1; - m24->linepos = 1; - oldsc = m24->sc; - if ((m24->crtc[8] & 3) == 3) - m24->sc = (m24->sc << 1) & 7; - if (m24->dispon) { - if (m24->displine < m24->firstline) { - m24->firstline = m24->displine; - } - m24->lastline = m24->displine; - for (c = 0; c < 8; c++) - { - if ((m24->cgamode & 0x12) == 0x12) { - ((uint32_t *)buffer32->line[m24->displine])[c] = 0; - if (m24->cgamode & 1) - ((uint32_t *)buffer32->line[m24->displine])[c + (m24->crtc[1] << 3) + 8] = 0; - else - ((uint32_t *)buffer32->line[m24->displine])[c + (m24->crtc[1] << 4) + 8] = 0; - } else { - ((uint32_t *)buffer32->line[m24->displine])[c] = (m24->cgacol & 15) + 16; - if (m24->cgamode & 1) - ((uint32_t *)buffer32->line[m24->displine])[c + (m24->crtc[1] << 3) + 8] = (m24->cgacol & 15) + 16; - else - ((uint32_t *)buffer32->line[m24->displine])[c + (m24->crtc[1] << 4) + 8] = (m24->cgacol & 15) + 16; - } - } - if (m24->cgamode & 1) { - for (x = 0; x < m24->crtc[1]; x++) { - chr = m24->charbuffer[ x << 1]; - attr = m24->charbuffer[(x << 1) + 1]; - drawcursor = ((m24->ma == ca) && m24->con && m24->cursoron); - if (m24->cgamode & 0x20) { - cols[1] = (attr & 15) + 16; - cols[0] = ((attr >> 4) & 7) + 16; - if ((m24->blink & 16) && (attr & 0x80) && !drawcursor) - cols[1] = cols[0]; - } else { - cols[1] = (attr & 15) + 16; - cols[0] = (attr >> 4) + 16; - } - if (drawcursor) { - for (c = 0; c < 8; c++) - ((uint32_t *)buffer32->line[m24->displine])[(x << 3) + c + 8] = cols[(fontdatm[chr][((m24->sc & 7) << 1) | m24->lineff] & (1 << (c ^ 7))) ? 1 : 0] ^ 15; - } else { - for (c = 0; c < 8; c++) - ((uint32_t *)buffer32->line[m24->displine])[(x << 3) + c + 8] = cols[(fontdatm[chr][((m24->sc & 7) << 1) | m24->lineff] & (1 << (c ^ 7))) ? 1 : 0]; - } - m24->ma++; - } - } else if (!(m24->cgamode & 2)) { - for (x = 0; x < m24->crtc[1]; x++) { - chr = m24->vram[((m24->ma << 1) & 0x3fff) + m24->base]; - attr = m24->vram[(((m24->ma << 1) + 1) & 0x3fff) + m24->base]; - drawcursor = ((m24->ma == ca) && m24->con && m24->cursoron); - if (m24->cgamode & 0x20) { - cols[1] = (attr & 15) + 16; - cols[0] = ((attr >> 4) & 7) + 16; - if ((m24->blink & 16) && (attr & 0x80)) - cols[1] = cols[0]; - } else { - cols[1] = (attr & 15) + 16; - cols[0] = (attr >> 4) + 16; - } - m24->ma++; - if (drawcursor) { - for (c = 0; c < 8; c++) - ((uint32_t *)buffer32->line[m24->displine])[(x << 4) + (c << 1) + 8] = - ((uint32_t *)buffer32->line[m24->displine])[(x << 4) + (c << 1) + 1 + 8] = cols[(fontdatm[chr][((m24->sc & 7) << 1) | m24->lineff] & (1 << (c ^ 7))) ? 1 : 0] ^ 15; - } else { - for (c = 0; c < 8; c++) - ((uint32_t *)buffer32->line[m24->displine])[(x << 4) + (c << 1) + 8] = - ((uint32_t *)buffer32->line[m24->displine])[(x << 4) + (c << 1) + 1 + 8] = cols[(fontdatm[chr][((m24->sc & 7) << 1) | m24->lineff] & (1 << (c ^ 7))) ? 1 : 0]; - } - } - } else if (!(m24->cgamode & 16)) { - cols[0] = (m24->cgacol & 15) | 16; - col = (m24->cgacol & 16) ? 24 : 16; - if (m24->cgamode & 4) { - cols[1] = col | 3; - cols[2] = col | 4; - cols[3] = col | 7; - } else if (m24->cgacol & 32) { - cols[1] = col | 3; - cols[2] = col | 5; - cols[3] = col | 7; - } else { - cols[1] = col | 2; - cols[2] = col | 4; - cols[3] = col | 6; - } - for (x = 0; x < m24->crtc[1]; x++) { - dat = (m24->vram[((m24->ma << 1) & 0x1fff) + ((m24->sc & 1) * 0x2000) + m24->base] << 8) | - m24->vram[((m24->ma << 1) & 0x1fff) + ((m24->sc & 1) * 0x2000) + 1 + m24->base]; - m24->ma++; - for (c = 0; c < 8; c++) { - ((uint32_t *)buffer32->line[m24->displine])[(x << 4) + (c << 1) + 8] = - ((uint32_t *)buffer32->line[m24->displine])[(x << 4) + (c << 1) + 1 + 8] = cols[dat >> 14]; - dat <<= 2; - } - } - } else { - if (m24->ctrl & 1 || ((m24->monitor_type & 8) && (m24->port_23c6 & 1))) { - dat2 = ((m24->sc & 1) * 0x4000) | (m24->lineff * 0x2000); - cols[0] = 0; cols[1] = /*(m24->cgacol & 15)*/15 + 16; - } else { - dat2 = (m24->sc & 1) * 0x2000; - cols[0] = 0; cols[1] = (m24->cgacol & 15) + 16; - } - - for (x = 0; x < m24->crtc[1]; x++) { - dat = (m24->vram[((m24->ma << 1) & 0x1fff) + dat2] << 8) | m24->vram[((m24->ma << 1) & 0x1fff) + dat2 + 1]; - m24->ma++; - for (c = 0; c < 16; c++) { - ((uint32_t *)buffer32->line[m24->displine])[(x << 4) + c + 8] = cols[dat >> 15]; - dat <<= 1; - } - } - } - } else { - cols[0] = ((m24->cgamode & 0x12) == 0x12) ? 0 : (m24->cgacol & 15) + 16; - if (m24->cgamode & 1) hline(buffer32, 0, m24->displine, (m24->crtc[1] << 3) + 16, cols[0]); - else hline(buffer32, 0, m24->displine, (m24->crtc[1] << 4) + 16, cols[0]); - } - - if (m24->cgamode & 1) - x = (m24->crtc[1] << 3) + 16; - else - x = (m24->crtc[1] << 4) + 16; - - m24->sc = oldsc; - if (m24->vc == m24->crtc[7] && !m24->sc) - m24->stat |= 8; - m24->displine++; - if (m24->displine >= 720) m24->displine = 0; - } else { - timer_advance_u64(&m24->timer, m24->dispontime); - if (m24->dispon) m24->stat &= ~1; - m24->linepos = 0; - m24->lineff ^= 1; - if (m24->lineff) { - m24->ma = m24->maback; - } else { - if (m24->vsynctime) { - m24->vsynctime--; - if (!m24->vsynctime) - m24->stat &= ~8; - } - if (m24->sc == (m24->crtc[11] & 31) || ((m24->crtc[8] & 3) == 3 && m24->sc == ((m24->crtc[11] & 31) >> 1))) { - m24->con = 0; - m24->coff = 1; - } - if (m24->vadj) { - m24->sc++; - m24->sc &= 31; - m24->ma = m24->maback; - m24->vadj--; - if (!m24->vadj) { - m24->dispon = 1; - m24->ma = m24->maback = (m24->crtc[13] | (m24->crtc[12] << 8)) & 0x3fff; - m24->sc = 0; - } - } else if (m24->sc == m24->crtc[9] || ((m24->crtc[8] & 3) == 3 && m24->sc == (m24->crtc[9] >> 1))) { - m24->maback = m24->ma; - m24->sc = 0; - oldvc = m24->vc; - m24->vc++; - m24->vc &= 127; - - if (m24->vc == m24->crtc[6]) - m24->dispon=0; - - if (oldvc == m24->crtc[4]) { - m24->vc = 0; - m24->vadj = m24->crtc[5]; - if (!m24->vadj) m24->dispon = 1; - if (!m24->vadj) m24->ma = m24->maback = (m24->crtc[13] | (m24->crtc[12] << 8)) & 0x3fff; - if ((m24->crtc[10] & 0x60) == 0x20) - m24->cursoron = 0; - else - m24->cursoron = m24->blink & 16; - } - - if (m24->vc == m24->crtc[7]) { - m24->dispon = 0; - m24->displine = 0; - m24->vsynctime = (m24->crtc[3] >> 4) + 1; - if (m24->crtc[7]) { - if (m24->cgamode & 1) - x = (m24->crtc[1] << 3) + 16; - else - x = (m24->crtc[1] << 4) + 16; - m24->lastline++; - - xs_temp = x; - ys_temp = (m24->lastline - m24->firstline); - - if ((xs_temp > 0) && (ys_temp > 0)) { - if (xsize < 64) xs_temp = 656; - if (ysize < 32) ys_temp = 200; - if (!enable_overscan) - xs_temp -= 16; - - if ((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_8(0, m24->firstline - 8, 0, (m24->lastline - m24->firstline) + 16, - xsize, (m24->lastline - m24->firstline) + 16); - } else - video_blit_memtoscreen_8(8, m24->firstline, 0, (m24->lastline - m24->firstline), - xsize, (m24->lastline - m24->firstline)); - } - - frames++; - - video_res_x = xsize; - video_res_y = ysize; - if (m24->cgamode & 1) { - video_res_x /= 8; - video_res_y /= (m24->crtc[9] + 1) * 2; - video_bpp = 0; - } else if (!(m24->cgamode & 2)) { - video_res_x /= 16; - video_res_y /= (m24->crtc[9] + 1) * 2; - video_bpp = 0; - } else if (!(m24->cgamode & 16)) { - video_res_x /= 2; - video_res_y /= 2; - video_bpp = 2; - } else if (!(m24->ctrl & 1)) { - video_res_y /= 2; - video_bpp = 1; - } - } - m24->firstline = 1000; - m24->lastline = 0; - m24->blink++; - } - } else { - m24->sc++; - m24->sc &= 31; - m24->ma = m24->maback; - } - if ((m24->sc == (m24->crtc[10] & 31) || ((m24->crtc[8] & 3) == 3 && m24->sc == ((m24->crtc[10] & 31) >> 1)))) - m24->con = 1; - } - if (m24->dispon && (m24->cgamode & 1)) { - for (x = 0; x < (m24->crtc[1] << 1); x++) - m24->charbuffer[x] = m24->vram[(((m24->ma << 1) + x) & 0x3fff) + m24->base]; - } - } -} - - -static void -speed_changed(void *priv) -{ - olim24_t *m24 = (olim24_t *)priv; - - recalc_timings(m24); -} - - -static void -kbd_poll(void *priv) -{ - olim24_t *m24 = (olim24_t *)priv; - - timer_advance_u64(&m24->send_delay_timer, 1000 * TIMER_USEC); - if (m24->wantirq) { - m24->wantirq = 0; - picint(2); -#if ENABLE_KEYBOARD_LOG - m24_log("M24: take IRQ\n"); -#endif - } - - if (!(m24->status & STAT_OFULL) && key_queue_start != key_queue_end) { -#if ENABLE_KEYBOARD_LOG - m24_log("Reading %02X from the key queue at %i\n", - m24->out, key_queue_start); -#endif - m24->out = key_queue[key_queue_start]; - key_queue_start = (key_queue_start + 1) & 0xf; - m24->status |= STAT_OFULL; - m24->status &= ~STAT_IFULL; - m24->wantirq = 1; - } -} - - -static void -kbd_adddata(uint16_t val) -{ - key_queue[key_queue_end] = val; - key_queue_end = (key_queue_end + 1) & 0xf; -} - - -static void -kbd_adddata_ex(uint16_t val) -{ - kbd_adddata_process(val, kbd_adddata); -} - - -static void -kbd_write(uint16_t port, uint8_t val, void *priv) -{ - olim24_t *m24 = (olim24_t *)priv; - -#if ENABLE_KEYBOARD_LOG - m24_log("M24: write %04X %02X\n", port, val); -#endif - -#if 0 - if (ram[8] == 0xc3) { - output = 3; - } -#endif - switch (port) { - case 0x60: - if (m24->param != m24->param_total) { - m24->params[m24->param++] = val; - if (m24->param == m24->param_total) { - switch (m24->command) { - case 0x11: - m24->mouse_mode = 0; - m24->scan[0] = m24->params[0]; - m24->scan[1] = m24->params[1]; - m24->scan[2] = m24->params[2]; - m24->scan[3] = m24->params[3]; - m24->scan[4] = m24->params[4]; - m24->scan[5] = m24->params[5]; - m24->scan[6] = m24->params[6]; - break; - - case 0x12: - m24->mouse_mode = 1; - m24->scan[0] = m24->params[0]; - m24->scan[1] = m24->params[1]; - m24->scan[2] = m24->params[2]; - break; - - default: - m24_log("M24: bad keyboard command complete %02X\n", m24->command); - } - } - } else { - m24->command = val; - switch (val) { - case 0x01: /*Self-test*/ - break; - - case 0x05: /*Read ID*/ - kbd_adddata(0x00); - break; - - case 0x11: - m24->param = 0; - m24->param_total = 9; - break; - - case 0x12: - m24->param = 0; - m24->param_total = 4; - break; - - default: - m24_log("M24: bad keyboard command %02X\n", val); - } - } - break; - - case 0x61: - ppi.pb = val; - - speaker_update(); - speaker_gated = val & 1; - speaker_enable = val & 2; - if (speaker_enable) - was_speaker_enable = 1; - pit_ctr_set_gate(&pit->counters[2], val & 1); - break; - } -} - - -static uint8_t -kbd_read(uint16_t port, void *priv) -{ - olim24_t *m24 = (olim24_t *)priv; - uint8_t ret = 0xff; - - switch (port) { - case 0x60: - ret = m24->out; - if (key_queue_start == key_queue_end) { - m24->status &= ~STAT_OFULL; - m24->wantirq = 0; - } else { - m24->out = key_queue[key_queue_start]; - key_queue_start = (key_queue_start + 1) & 0xf; - m24->status |= STAT_OFULL; - m24->status &= ~STAT_IFULL; - m24->wantirq = 1; - } - break; - - case 0x61: - ret = ppi.pb; - break; - - case 0x64: - ret = m24->status; - m24->status &= ~(STAT_RTIMEOUT | STAT_TTIMEOUT); - break; - - default: - m24_log("\nBad M24 keyboard read %04X\n", port); - } - - return(ret); -} - - -static int -ms_poll(int x, int y, int z, int b, void *priv) -{ - olim24_t *m24 = (olim24_t *)priv; - - m24->x += x; - m24->y += y; - - if (((key_queue_end - key_queue_start) & 0xf) > 14) return(0xff); - - if ((b & 1) && !(m24->b & 1)) - kbd_adddata(m24->scan[0]); - if (!(b & 1) && (m24->b & 1)) - kbd_adddata(m24->scan[0] | 0x80); - m24->b = (m24->b & ~1) | (b & 1); - - if (((key_queue_end - key_queue_start) & 0xf) > 14) return(0xff); - - if ((b & 2) && !(m24->b & 2)) - kbd_adddata(m24->scan[2]); - if (!(b & 2) && (m24->b & 2)) - kbd_adddata(m24->scan[2] | 0x80); - m24->b = (m24->b & ~2) | (b & 2); - - if (((key_queue_end - key_queue_start) & 0xf) > 14) return(0xff); - - if ((b & 4) && !(m24->b & 4)) - kbd_adddata(m24->scan[1]); - if (!(b & 4) && (m24->b & 4)) - kbd_adddata(m24->scan[1] | 0x80); - m24->b = (m24->b & ~4) | (b & 4); - - if (m24->mouse_mode) { - if (((key_queue_end - key_queue_start) & 0xf) > 12) return(0xff); - - if (!m24->x && !m24->y) return(0xff); - - m24->y = -m24->y; - - if (m24->x < -127) m24->x = -127; - if (m24->x > 127) m24->x = 127; - if (m24->x < -127) m24->x = 0x80 | ((-m24->x) & 0x7f); - - if (m24->y < -127) m24->y = -127; - if (m24->y > 127) m24->y = 127; - if (m24->y < -127) m24->y = 0x80 | ((-m24->y) & 0x7f); - - kbd_adddata(0xfe); - kbd_adddata(m24->x); - kbd_adddata(m24->y); - - m24->x = m24->y = 0; - } else { - while (m24->x < -4) { - if (((key_queue_end - key_queue_start) & 0xf) > 14) - return(0xff); - m24->x += 4; - kbd_adddata(m24->scan[3]); - } - while (m24->x > 4) { - if (((key_queue_end - key_queue_start) & 0xf) > 14) - return(0xff); - m24->x -= 4; - kbd_adddata(m24->scan[4]); - } - while (m24->y < -4) { - if (((key_queue_end - key_queue_start) & 0xf) > 14) - return(0xff); - m24->y += 4; - kbd_adddata(m24->scan[5]); - } - while (m24->y > 4) { - if (((key_queue_end - key_queue_start) & 0xf) > 14) - return(0xff); - m24->y -= 4; - kbd_adddata(m24->scan[6]); - } - } - - return(0); -} - - -static uint8_t -m24_read(uint16_t port, void *priv) -{ - switch (port) { - case 0x66: - return 0x00; - case 0x67: - return 0x20 | 0x40 | 0x0C; - } - - return(0xff); -} - -static void -vid_close(void *priv) -{ - olim24_t *m24 = (olim24_t *)priv; - - free(m24->vram); - - free(m24); -} - -const device_t m24_device = { - "Olivetti M24", - 0, 0, - NULL, vid_close, NULL, - { NULL }, - speed_changed, - NULL, - NULL -}; - -const device_t * -m24_get_device(void) -{ - return &m24_device; -} - - -static void -kbd_reset(void *priv) -{ - olim24_t *m24 = (olim24_t *)priv; - - /* Initialize the keyboard. */ - m24->status = STAT_LOCK | STAT_CD; - m24->wantirq = 0; - keyboard_scan = 1; - m24->param = m24->param_total = 0; - m24->mouse_mode = 0; - m24->scan[0] = 0x1c; - m24->scan[1] = 0x53; - m24->scan[2] = 0x01; - m24->scan[3] = 0x4b; - m24->scan[4] = 0x4d; - m24->scan[5] = 0x48; - m24->scan[6] = 0x50; -} - - -int -machine_olim24_init(const machine_t *model) -{ - int ret; - - ret = bios_load_interleaved(L"roms/machines/olivetti_m24/olivetti_m24_version_1.43_low.bin", - L"roms/machines/olivetti_m24/olivetti_m24_version_1.43_high.bin", - 0x000fc000, 16384, 0); - - if (bios_only || !ret) - return ret; - - olim24_t *m24; - - m24 = (olim24_t *)malloc(sizeof(olim24_t)); - memset(m24, 0x00, sizeof(olim24_t)); - - machine_common_init(model); - device_add(&fdc_xt_device); - - io_sethandler(0x0066, 2, m24_read, NULL, NULL, NULL, NULL, NULL, m24); - - /* Initialize the video adapter. */ - // loadfont(L"roms/machines/olivetti_m24/ATT-FONT-DUMPED-VERIFIED.BIN", 1); - loadfont(L"roms/machines/olivetti_m24/m24 graphics board go380 258 pqbq.bin", 1); - m24->vram = malloc(0x8000); - overscan_x = overscan_y = 16; - mem_mapping_add(&m24->mapping, 0xb8000, 0x08000, - vid_read, NULL, NULL, - vid_write, NULL, NULL, NULL, 0, m24); - io_sethandler(0x03d0, 16, vid_in, NULL, NULL, vid_out, NULL, NULL, m24); - timer_add(&m24->timer, vid_poll, m24, 1); - device_add_ex(&m24_device, m24); - video_inform(VIDEO_FLAG_TYPE_CGA, &timing_m24); - cga_palette = 0; - cgapal_rebuild(); - - /* Initialize the keyboard. */ - io_sethandler(0x0060, 2, - kbd_read, NULL, NULL, kbd_write, NULL, NULL, m24); - io_sethandler(0x0064, 1, - kbd_read, NULL, NULL, kbd_write, NULL, NULL, m24); - keyboard_send = kbd_adddata_ex; - kbd_reset(m24); - timer_add(&m24->send_delay_timer, kbd_poll, m24, 1); - - /* Tell mouse driver about our internal mouse. */ - mouse_reset(); - mouse_set_poll(ms_poll, m24); - - keyboard_set_table(scancode_xt); - - if (joystick_type != JOYSTICK_TYPE_NONE) - device_add(&gameport_device); - - /* FIXME: make sure this is correct?? */ - device_add(&at_nvr_device); - - nmi_init(); - - return ret; -} diff --git a/src/machine/m_xt_olivetti.c b/src/machine/m_xt_olivetti.c new file mode 100644 index 000000000..fec71f8ff --- /dev/null +++ b/src/machine/m_xt_olivetti.c @@ -0,0 +1,842 @@ +/* + * 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 Olivetti XT-compatible machines. + * + * + * + * Authors: Sarah Walker, + * Miran Grca, + * Fred N. van Kempen, + * EngiNerd + * + * Copyright 2008-2019 Sarah Walker. + * Copyright 2016-2019 Miran Grca. + * Copyright 2017-2019 Fred N. van Kempen. + * Copyright 2020 EngiNerd. + */ + +#include +#include +#include +#include +#include +#include +#include <86box/86box.h> +#include <86box/timer.h> +#include <86box/io.h> +#include <86box/pic.h> +#include <86box/pit.h> +#include <86box/ppi.h> +#include <86box/nmi.h> +#include <86box/mem.h> +#include <86box/device.h> +#include <86box/nvr.h> +#include <86box/keyboard.h> +#include <86box/mouse.h> +#include <86box/rom.h> +#include <86box/fdd.h> +#include <86box/fdc.h> +#include <86box/fdc_ext.h> +#include <86box/gameport.h> +#include <86box/sound.h> +#include <86box/snd_speaker.h> +#include <86box/video.h> +#include <86box/machine.h> +#include <86box/vid_cga.h> +#include <86box/vid_ogc.h> +#include <86box/vid_colorplus.h> +#include <86box/vid_cga_comp.h> + +#define STAT_PARITY 0x80 +#define STAT_RTIMEOUT 0x40 +#define STAT_TTIMEOUT 0x20 +#define STAT_LOCK 0x10 +#define STAT_CD 0x08 +#define STAT_SYSFLAG 0x04 +#define STAT_IFULL 0x02 +#define STAT_OFULL 0x01 + +#define PLANTRONICS_MODE 1 +#define OLIVETTI_OGC_MODE 0 + +#define CGA_RGB 0 +#define CGA_COMPOSITE 1 + +typedef struct { + /* Keyboard stuff. */ + int wantirq; + uint8_t command; + uint8_t status; + uint8_t out; + uint8_t output_port; + int param, + param_total; + uint8_t params[16]; + uint8_t scan[7]; + + /* Mouse stuff. */ + int mouse_mode; + int x, y, b; + pc_timer_t send_delay_timer; +} olim24_kbd_t; + +typedef struct { + ogc_t ogc; + colorplus_t colorplus; + int mode; +} olim19_vid_t; + +static uint8_t key_queue[16]; +static int key_queue_start = 0, + key_queue_end = 0; + +video_timings_t timing_m19_vid = {VIDEO_ISA, 8, 16, 32, 8, 16, 32}; + +#ifdef ENABLE_M24VID_LOG +int m24vid_do_log = ENABLE_M24VID_LOG; + + +static void +m24_log(const char *fmt, ...) +{ + va_list ap; + + if (m24vid_do_log) { + va_start(ap, fmt); + vfprintf(stdlog, fmt, ap); + va_end(ap); + fflush(stdlog); + } +} +#else +#define m24_log(fmt, ...) +#endif + +static void +m24_kbd_poll(void *priv) +{ + olim24_kbd_t *m24_kbd = (olim24_kbd_t *)priv; + + timer_advance_u64(&m24_kbd->send_delay_timer, 1000 * TIMER_USEC); + if (m24_kbd->wantirq) { + m24_kbd->wantirq = 0; + picint(2); +#if ENABLE_KEYBOARD_LOG + m24_log("M24: take IRQ\n"); +#endif + } + + if (!(m24_kbd->status & STAT_OFULL) && key_queue_start != key_queue_end) { +#if ENABLE_KEYBOARD_LOG + m24_log("Reading %02X from the key queue at %i\n", + m24_kbd->out, key_queue_start); +#endif + m24_kbd->out = key_queue[key_queue_start]; + key_queue_start = (key_queue_start + 1) & 0xf; + m24_kbd->status |= STAT_OFULL; + m24_kbd->status &= ~STAT_IFULL; + m24_kbd->wantirq = 1; + } +} + + +static void +m24_kbd_adddata(uint16_t val) +{ + key_queue[key_queue_end] = val; + key_queue_end = (key_queue_end + 1) & 0xf; +} + + +static void +m24_kbd_adddata_ex(uint16_t val) +{ + kbd_adddata_process(val, m24_kbd_adddata); +} + + +static void +m24_kbd_write(uint16_t port, uint8_t val, void *priv) +{ + olim24_kbd_t *m24_kbd = (olim24_kbd_t *)priv; + +#if ENABLE_KEYBOARD_LOG + m24_log("M24: write %04X %02X\n", port, val); +#endif + +#if 0 + if (ram[8] == 0xc3) { + output = 3; + } +#endif + switch (port) { + case 0x60: + if (m24_kbd->param != m24_kbd->param_total) { + m24_kbd->params[m24_kbd->param++] = val; + if (m24_kbd->param == m24_kbd->param_total) { + switch (m24_kbd->command) { + case 0x11: + m24_kbd->mouse_mode = 0; + m24_kbd->scan[0] = m24_kbd->params[0]; + m24_kbd->scan[1] = m24_kbd->params[1]; + m24_kbd->scan[2] = m24_kbd->params[2]; + m24_kbd->scan[3] = m24_kbd->params[3]; + m24_kbd->scan[4] = m24_kbd->params[4]; + m24_kbd->scan[5] = m24_kbd->params[5]; + m24_kbd->scan[6] = m24_kbd->params[6]; + break; + + case 0x12: + m24_kbd->mouse_mode = 1; + m24_kbd->scan[0] = m24_kbd->params[0]; + m24_kbd->scan[1] = m24_kbd->params[1]; + m24_kbd->scan[2] = m24_kbd->params[2]; + break; + + default: + m24_log("M24: bad keyboard command complete %02X\n", m24_kbd->command); + } + } + } else { + m24_kbd->command = val; + switch (val) { + case 0x01: /*Self-test*/ + break; + + case 0x05: /*Read ID*/ + m24_kbd_adddata(0x00); + break; + + case 0x11: + m24_kbd->param = 0; + m24_kbd->param_total = 9; + break; + + case 0x12: + m24_kbd->param = 0; + m24_kbd->param_total = 4; + break; + + default: + m24_log("M24: bad keyboard command %02X\n", val); + } + } + break; + + case 0x61: + ppi.pb = val; + + speaker_update(); + speaker_gated = val & 1; + speaker_enable = val & 2; + if (speaker_enable) + was_speaker_enable = 1; + pit_ctr_set_gate(&pit->counters[2], val & 1); + break; + } +} + +static uint8_t +m24_kbd_read(uint16_t port, void *priv) +{ + olim24_kbd_t *m24_kbd = (olim24_kbd_t *)priv; + uint8_t ret = 0xff; + + switch (port) { + case 0x60: + ret = m24_kbd->out; + if (key_queue_start == key_queue_end) { + m24_kbd->status &= ~STAT_OFULL; + m24_kbd->wantirq = 0; + } else { + m24_kbd->out = key_queue[key_queue_start]; + key_queue_start = (key_queue_start + 1) & 0xf; + m24_kbd->status |= STAT_OFULL; + m24_kbd->status &= ~STAT_IFULL; + m24_kbd->wantirq = 1; + } + break; + + case 0x61: + ret = ppi.pb; + break; + + case 0x64: + ret = m24_kbd->status; + m24_kbd->status &= ~(STAT_RTIMEOUT | STAT_TTIMEOUT); + break; + + default: + m24_log("\nBad M24 keyboard read %04X\n", port); + } + + return(ret); +} + +static void +m24_kbd_close(void *priv) +{ + olim24_kbd_t *kbd = (olim24_kbd_t *)priv; + /* Stop the timer. */ + timer_disable(&kbd->send_delay_timer); + + /* Disable scanning. */ + keyboard_scan = 0; + + keyboard_send = NULL; + + io_removehandler(0x0060, 2, + m24_kbd_read, NULL, NULL, m24_kbd_write, NULL, NULL, kbd); + io_removehandler(0x0064, 1, + m24_kbd_read, NULL, NULL, m24_kbd_write, NULL, NULL, kbd); + + free(kbd); +} + +static void +m24_kbd_reset(void *priv) +{ + olim24_kbd_t *m24_kbd = (olim24_kbd_t *)priv; + + /* Initialize the keyboard. */ + m24_kbd->status = STAT_LOCK | STAT_CD; + m24_kbd->wantirq = 0; + keyboard_scan = 1; + m24_kbd->param = m24_kbd->param_total = 0; + m24_kbd->mouse_mode = 0; + m24_kbd->scan[0] = 0x1c; + m24_kbd->scan[1] = 0x53; + m24_kbd->scan[2] = 0x01; + m24_kbd->scan[3] = 0x4b; + m24_kbd->scan[4] = 0x4d; + m24_kbd->scan[5] = 0x48; + m24_kbd->scan[6] = 0x50; +} + +static int +ms_poll(int x, int y, int z, int b, void *priv) +{ + olim24_kbd_t *m24_kbd = (olim24_kbd_t *)priv; + + m24_kbd->x += x; + m24_kbd->y += y; + + if (((key_queue_end - key_queue_start) & 0xf) > 14) return(0xff); + + if ((b & 1) && !(m24_kbd->b & 1)) + m24_kbd_adddata(m24_kbd->scan[0]); + if (!(b & 1) && (m24_kbd->b & 1)) + m24_kbd_adddata(m24_kbd->scan[0] | 0x80); + m24_kbd->b = (m24_kbd->b & ~1) | (b & 1); + + if (((key_queue_end - key_queue_start) & 0xf) > 14) return(0xff); + + if ((b & 2) && !(m24_kbd->b & 2)) + m24_kbd_adddata(m24_kbd->scan[2]); + if (!(b & 2) && (m24_kbd->b & 2)) + m24_kbd_adddata(m24_kbd->scan[2] | 0x80); + m24_kbd->b = (m24_kbd->b & ~2) | (b & 2); + + if (((key_queue_end - key_queue_start) & 0xf) > 14) return(0xff); + + if ((b & 4) && !(m24_kbd->b & 4)) + m24_kbd_adddata(m24_kbd->scan[1]); + if (!(b & 4) && (m24_kbd->b & 4)) + m24_kbd_adddata(m24_kbd->scan[1] | 0x80); + m24_kbd->b = (m24_kbd->b & ~4) | (b & 4); + + if (m24_kbd->mouse_mode) { + if (((key_queue_end - key_queue_start) & 0xf) > 12) return(0xff); + + if (!m24_kbd->x && !m24_kbd->y) return(0xff); + + m24_kbd->y = -m24_kbd->y; + + if (m24_kbd->x < -127) m24_kbd->x = -127; + if (m24_kbd->x > 127) m24_kbd->x = 127; + if (m24_kbd->x < -127) m24_kbd->x = 0x80 | ((-m24_kbd->x) & 0x7f); + + if (m24_kbd->y < -127) m24_kbd->y = -127; + if (m24_kbd->y > 127) m24_kbd->y = 127; + if (m24_kbd->y < -127) m24_kbd->y = 0x80 | ((-m24_kbd->y) & 0x7f); + + m24_kbd_adddata(0xfe); + m24_kbd_adddata(m24_kbd->x); + m24_kbd_adddata(m24_kbd->y); + + m24_kbd->x = m24_kbd->y = 0; + } else { + while (m24_kbd->x < -4) { + if (((key_queue_end - key_queue_start) & 0xf) > 14) + return(0xff); + m24_kbd->x += 4; + m24_kbd_adddata(m24_kbd->scan[3]); + } + while (m24_kbd->x > 4) { + if (((key_queue_end - key_queue_start) & 0xf) > 14) + return(0xff); + m24_kbd->x -= 4; + m24_kbd_adddata(m24_kbd->scan[4]); + } + while (m24_kbd->y < -4) { + if (((key_queue_end - key_queue_start) & 0xf) > 14) + return(0xff); + m24_kbd->y += 4; + m24_kbd_adddata(m24_kbd->scan[5]); + } + while (m24_kbd->y > 4) { + if (((key_queue_end - key_queue_start) & 0xf) > 14) + return(0xff); + m24_kbd->y -= 4; + m24_kbd_adddata(m24_kbd->scan[6]); + } + } + + return(0); +} + +static void +m24_kbd_init(olim24_kbd_t *kbd){ + + /* Initialize the keyboard. */ + io_sethandler(0x0060, 2, + m24_kbd_read, NULL, NULL, m24_kbd_write, NULL, NULL, kbd); + io_sethandler(0x0064, 1, + m24_kbd_read, NULL, NULL, m24_kbd_write, NULL, NULL, kbd); + keyboard_send = m24_kbd_adddata_ex; + m24_kbd_reset(kbd); + timer_add(&kbd->send_delay_timer, m24_kbd_poll, kbd, 1); + + /* Tell mouse driver about our internal mouse. */ + mouse_reset(); + mouse_set_poll(ms_poll, kbd); + + keyboard_set_table(scancode_xt); + +} + +static void +m19_vid_out(uint16_t addr, uint8_t val, void *priv) +{ + olim19_vid_t *vid = (olim19_vid_t *)priv; + int oldmode = vid->mode; + + /* activating plantronics mode */ + if (addr == 0x3dd){ + /* already in graphics mode */ + if ((val & 0x30) && (vid->ogc.cga.cgamode & 0x2)) { + vid->mode = PLANTRONICS_MODE; + } else { + vid->mode = OLIVETTI_OGC_MODE; +} + /* setting graphics mode */ + } else if (addr == 0x3d8) { + if ((val & 0x2) && (vid->colorplus.control & 0x30)){ + vid->mode = PLANTRONICS_MODE; + } else { + vid->mode = OLIVETTI_OGC_MODE; + } + } + /* video mode changed */ + if(oldmode != vid->mode){ + /* activate Plantronics emulation */ + if (vid->mode == PLANTRONICS_MODE){ + timer_disable(&vid->ogc.cga.timer); + timer_set_delay_u64(&vid->colorplus.cga.timer, 0); + /* return to OGC mode */ + } else { + timer_disable(&vid->colorplus.cga.timer); + timer_set_delay_u64(&vid->ogc.cga.timer, 0); + } + colorplus_recalctimings(&vid->colorplus); + ogc_recalctimings(&vid->ogc); + } + colorplus_out(addr, val, &vid->colorplus); + ogc_out(addr, val, &vid->ogc); +} + +static uint8_t +m19_vid_in(uint16_t addr, void *priv) +{ + olim19_vid_t *vid = (olim19_vid_t *)priv; + if ( vid->mode == PLANTRONICS_MODE ) { + return colorplus_in(addr, &vid->colorplus); + } else { + return ogc_in(addr, &vid->ogc); +} + +} + +static uint8_t +m19_vid_read(uint32_t addr, void *priv) +{ + olim19_vid_t *vid = (olim19_vid_t *)priv; + vid->colorplus.cga.mapping = vid->ogc.cga.mapping; + if ( vid->mode == PLANTRONICS_MODE ) { + return colorplus_read(addr, &vid->colorplus); + } else { + return ogc_read(addr, &vid->ogc); +} +} + +static void +m19_vid_write(uint32_t addr, uint8_t val, void *priv) +{ + olim19_vid_t *vid = (olim19_vid_t *)priv; + colorplus_write(addr, val, &vid->colorplus); + ogc_write(addr, val, &vid->ogc); +} + + +static void +m19_vid_close(void *priv) +{ + olim19_vid_t *vid = (olim19_vid_t *)priv; + free(vid->ogc.cga.vram); + free(vid->colorplus.cga.vram); + free(vid); +} + +static void +m19_vid_speed_changed(void *priv) +{ + olim19_vid_t *vid = (olim19_vid_t *)priv; + colorplus_recalctimings(&vid->colorplus); + ogc_recalctimings(&vid->ogc); +} + +static void +m19_vid_init(olim19_vid_t *vid){ + + //int display_type; + vid->mode = OLIVETTI_OGC_MODE; + + video_inform(VIDEO_FLAG_TYPE_CGA, &timing_m19_vid); + + //display_type = device_get_config_int("display_type"); + + /* OGC emulation part begin */ + loadfont(L"roms/machines/olivetti_m19/BIOS.BIN", 10); + /* composite is not working yet */ + vid->ogc.cga.composite = 0; // (display_type != CGA_RGB); + //vid->ogc.cga.snow_enabled = device_get_config_int("snow_enabled"); + + vid->ogc.cga.vram = malloc(0x8000); + + //cga_comp_init(vid->ogc.cga.revision); + + //vid->ogc.cga.rgb_type = device_get_config_int("rgb_type"); + //cga_palette = (vid->ogc.cga.rgb_type << 1); + cga_palette = 0; + cgapal_rebuild(); + ogc_mdaattr_rebuild(); + + /* color display */ + // if (device_get_config_int("rgb_type")==0 || device_get_config_int("rgb_type") == 4) + vid->ogc.mono_display = 1; + // else + // vid->ogc.mono_display = 1; + /* OGC emulation part end */ + + /* Plantronics emulation part begin*/ + /* composite is not working yet */ + vid->colorplus.cga.composite = 0; //(display_type != CGA_RGB); + // vid->colorplus.cga.snow_enabled = device_get_config_int("snow_enabled"); + + vid->colorplus.cga.vram = malloc(0x8000); + + //vid->colorplus.cga.cgamode = 0x1; + /* Plantronics emulation part end*/ + + timer_add(&vid->ogc.cga.timer, ogc_poll, &vid->ogc, 1); + timer_add(&vid->colorplus.cga.timer, colorplus_poll, &vid->colorplus, 1); + timer_disable(&vid->colorplus.cga.timer); + mem_mapping_add(&vid->ogc.cga.mapping, 0xb8000, 0x08000, m19_vid_read, NULL, NULL, m19_vid_write, NULL, NULL, NULL, MEM_MAPPING_EXTERNAL, vid); + io_sethandler(0x03d0, 0x0010, m19_vid_in, NULL, NULL, m19_vid_out, NULL, NULL, vid); + + vid->mode = OLIVETTI_OGC_MODE; + +} + +const device_t m24_kbd_device = { + "Olivetti M24 keyboard and mouse", + 0, + 0, + NULL, + m24_kbd_close, + m24_kbd_reset, + { NULL }, NULL, NULL +}; + +const device_t m19_vid_device = { + "Olivetti M19 graphics card", + 0, 0, + NULL, m19_vid_close, NULL, + { NULL }, + m19_vid_speed_changed, + NULL, + NULL +}; + +const device_t * +m19_get_device(void) +{ + return &m19_vid_device; +} + +static uint8_t +m24_read(uint16_t port, void *priv) +{ + uint8_t ret = 0x00; + int i, fdd_count = 0; + switch (port) { + /* + * port 66: + * DIPSW-0 on mainboard (off=present=1) + * bit 7 - 2764 (off) / 2732 (on) ROM (BIOS < 1.36) + * bit 7 - Use (off) / do not use (on) memory bank 1 (BIOS >= 1.36) + * bit 6 - n/a + * bit 5 - 8530 (off) / 8250 (on) SCC + * bit 4 - 8087 present + * bits 3-0 - installed memory + */ + case 0x66: + /* Switch 5 - 8087 present */ + if (hasfpu) + ret |= 0x10; + /* + * Switches 1, 2, 3, 4 - installed memory + * Switch 8 - Use memory bank 1 + */ + switch (mem_size) { + case 128: + ret |= 0x1; + break; + case 256: + ret |= 0x2|0x80; + break; + case 384: + ret |= 0x1|0x2|0x80; + break; + case 512: + ret |= 0x8; + break; + case 640: + default: + ret |= 0x1|0x8|0x80; + break; + } + /* + * port 67: + * DIPSW-1 on mainboard (off=present=1) + * bits 7-6 - number of drives + * bits 5-4 - display adapter + * bit 3 - video scroll CPU (on) / slow scroll (off) + * bit 2 - BIOS HD on mainboard (on) / on controller (off) + * bit 1 - FDD fast (off) / slow (on) start drive + * bit 0 - 96 TPI (720 KB 3.5") (off) / 48 TPI (360 KB 5.25") FDD drive + * + * Display adapter: + * off off 80x25 mono + * off on 40x25 color + * on off 80x25 color + * on on EGA/VGA (works only for BIOS ROM 1.43) + */ + case 0x67: + for (i = 0; i < FDD_NUM; i++) { + if (fdd_get_flags(i)) { + fdd_count++; + } + } + + /* Switches 7, 8 - floppy drives. */ + if (!fdd_count) + ret |= 0x00; + else + ret |= ((fdd_count - 1) << 6); + + /* Switches 5, 6 - monitor type */ + if (video_is_mda()) + ret |= 0x30; + else if (video_is_cga()) + ret |= 0x20; /* 0x10 would be 40x25 */ + else + ret |= 0x0; + + /* Switch 3 - Disable internal BIOS HD */ + ret |= 0x4; + + /* Switch 2 - Set fast startup */ + ret |= 0x2; +} + + return(ret); +} + +const device_t * +m24_get_device(void) +{ + return &ogc_m24_device; +} + +int +machine_xt_olim24_init(const machine_t *model) +{ + int ret; + + ret = bios_load_interleaved(L"roms/machines/olivetti_m24/olivetti_m24_version_1.43_low.bin", + L"roms/machines/olivetti_m24/olivetti_m24_version_1.43_high.bin", + 0x000fc000, 16384, 0); + + if (bios_only || !ret) + return ret; + + if (gfxcard == VID_INTERNAL) + device_add(&ogc_m24_device); + + olim24_kbd_t *m24_kbd; + + m24_kbd = (olim24_kbd_t *)malloc(sizeof(olim24_kbd_t)); + memset(m24_kbd, 0x00, sizeof(olim24_kbd_t)); + + machine_common_init(model); + device_add(&fdc_xt_device); + + //address 66-67 = mainboard dip-switch settings + io_sethandler(0x0066, 2, m24_read, NULL, NULL, NULL, NULL, NULL, NULL); + + m24_kbd_init(m24_kbd); + device_add_ex(&m24_kbd_device, m24_kbd); + + /* FIXME: make sure this is correct?? */ + device_add(&at_nvr_device); + + if (joystick_type != JOYSTICK_TYPE_NONE) + device_add(&gameport_device); + + nmi_init(); + + + return ret; +} + +/* + * Current bugs: + * - handles only 360kb floppy drives (drive type and capacity selectable with jumpers mapped to unknown memory locations) + */ +int +machine_xt_olim240_init(const machine_t *model) +{ + int ret; + + ret = bios_load_interleaved(L"roms/machines/olivetti_m240/olivetti_m240_pch6_2.04_low.bin", + L"roms/machines/olivetti_m240/olivetti_m240_pch5_2.04_high.bin", + 0x000f8000, 32768, 0); + + if (bios_only || !ret) + return ret; + + machine_common_init(model); + + pit_ctr_set_out_func(&pit->counters[1], pit_refresh_timer_xt); + + /* + * port 60: should return jumper settings only under unknown conditions + * SWB on mainboard (off=1) + * bit 7 - use BIOS HD on mainboard (on) / on controller (off) + * bit 6 - use OCG/CGA display adapter (on) / other display adapter (off) + */ + device_add(&keyboard_at_olivetti_device); + + /* FIXME: make sure this is correct?? */ + device_add(&at_nvr_device); + + if (fdc_type == FDC_INTERNAL) + device_add(&fdc_xt_device); + + if (joystick_type != JOYSTICK_TYPE_NONE) + device_add(&gameport_device); + + nmi_init(); + + return ret; +} + + +/* + * Current bugs: + * - 640x400x2 graphics mode not supported (bit 0 of register 0x3de cannot be set) + * - optional mouse emulation missing + */ +int +machine_xt_olim19_init(const machine_t *model) +{ + int ret; + + ret = bios_load_linear(L"roms/machines/olivetti_m19/BIOS.BIN", + 0x000fc000, 16384, 0); + + if (bios_only || !ret) + return ret; + + olim19_vid_t *vid; + + /* do not move memory allocation elsewhere */ + vid = (olim19_vid_t *)malloc(sizeof(olim19_vid_t)); + memset(vid, 0x00, sizeof(olim19_vid_t)); + + machine_common_init(model); + device_add(&fdc_xt_device); + + m19_vid_init(vid); + device_add_ex(&m19_vid_device, vid); + + device_add(&keyboard_xt_olivetti_device); + + nmi_init(); + + return ret; + +} + + +/* not working, returns timer error */ +/* it appears to be a rebadged Hitachi HL 320 laptop */ +int +machine_xt_olim15_init(const machine_t *model) +{ + int ret; + + ret = bios_load_linear(L"roms/machines/olivetti_m15/oliv_m15.bin", + 0x000fc000, 16384, 0); + + if (bios_only || !ret) + return ret; + + machine_common_init(model); + + pit_ctr_set_out_func(&pit->counters[1], pit_refresh_timer_xt); + + device_add(&keyboard_xt_olivetti_device); + + device_add(&cga_device); + + /* FIXME: make sure this is correct?? */ + //device_add(&at_nvr_device); + + if (fdc_type == FDC_INTERNAL) + device_add(&fdc_xt_device); + + if (joystick_type != JOYSTICK_TYPE_NONE) + device_add(&gameport_device); + + nmi_init(); + + return ret; +} \ No newline at end of file diff --git a/src/machine/machine_table.c b/src/machine/machine_table.c index 0ff7afeec..4eccb6661 100644 --- a/src/machine/machine_table.c +++ b/src/machine/machine_table.c @@ -79,6 +79,7 @@ const machine_t machines[] = { { "[8088] Xi8088", "xi8088", MACHINE_TYPE_8088, CPU_PKG_8088, 0, 0, 0, 0, 0, 0, 0, MACHINE_AT | MACHINE_BUS_PS2, 64, 1024, 128, 127, machine_xt_xi8088_init, xi8088_get_device }, { "[8088] Zenith Data SupersPort", "zdsupers", MACHINE_TYPE_8088, CPU_PKG_8088, 0, 0, 0, 0, 0, 0, 0, MACHINE_PC, 128, 640, 128, 0, machine_xt_zenith_init, NULL }, + { "[8088] Olivetti M19", "olivetti_m19", MACHINE_TYPE_8088, CPU_PKG_8088, 0, 0, 0, 0, 0, 0, 0, MACHINE_PC | MACHINE_VIDEO_FIXED, 256, 640, 256, 0, machine_xt_olim19_init, NULL }, /* 8086 Machines */ { "[8086] Amstrad PC1512", "pc1512", MACHINE_TYPE_8086, CPU_PKG_8086, 0, 8000000, 8000000, 0, 0, 0, 0, MACHINE_PC | MACHINE_VIDEO_FIXED | MACHINE_MOUSE, 512, 640, 128, 63, machine_pc1512_init, pc1512_get_device }, { "[8086] Amstrad PC1640", "pc1640", MACHINE_TYPE_8086, CPU_PKG_8086, 0, 0, 0, 0, 0, 0, 0, MACHINE_PC | MACHINE_VIDEO | MACHINE_MOUSE, 640, 640, 0, 63, machine_pc1640_init, pc1640_get_device }, @@ -87,11 +88,13 @@ const machine_t machines[] = { { "[8086] Amstrad PC20(0)", "pc200", MACHINE_TYPE_8086, CPU_PKG_8086, 0, 0, 0, 0, 0, 0, 0, MACHINE_PC | MACHINE_VIDEO | MACHINE_MOUSE | MACHINE_NONMI, 512, 640, 128, 63, machine_pc200_init, pc200_get_device }, { "[8086] Amstrad PPC512/640", "ppc512", MACHINE_TYPE_8086, CPU_PKG_8086, 0, 0, 0, 0, 0, 0, 0, MACHINE_PC | MACHINE_VIDEO | MACHINE_MOUSE | MACHINE_NONMI, 512, 640, 128, 63, machine_ppc512_init, ppc512_get_device }, { "[8086] Compaq Deskpro", "deskpro", MACHINE_TYPE_8086, CPU_PKG_8086, 0, 0, 0, 0, 0, 0, 0, MACHINE_PC, 128, 640, 128, 0, machine_xt_compaq_deskpro_init, NULL }, - { "[8086] Olivetti M24", "olivetti_m24", MACHINE_TYPE_8086, CPU_PKG_8086, 0, 0, 0, 0, 0, 0, 0, MACHINE_PC | MACHINE_VIDEO_FIXED | MACHINE_MOUSE, 128, 640, 128, 0, machine_olim24_init, m24_get_device }, + { "[8086] Olivetti M24", "olivetti_m24", MACHINE_TYPE_8086, CPU_PKG_8086, 0, 0, 0, 0, 0, 0, 0, MACHINE_PC | MACHINE_VIDEO | MACHINE_MOUSE, 128, 640, 128, 0, machine_xt_olim24_init, m24_get_device }, { "[8086] Schetmash Iskra-3104", "iskra3104", MACHINE_TYPE_8086, CPU_PKG_8086, 0, 0, 0, 0, 0, 0, 0, MACHINE_PC, 128, 640, 128, 0, machine_xt_iskra3104_init, NULL }, { "[8086] Tandy 1000 SL/2", "tandy1000sl2", MACHINE_TYPE_8086, CPU_PKG_8086, 0, 0, 0, 0, 0, 0, 0, MACHINE_PC | MACHINE_VIDEO_FIXED, 512, 768, 128, 0, machine_tandy1000sl2_init, tandy1k_sl_get_device }, { "[8086] Toshiba T1200", "t1200", MACHINE_TYPE_8086, CPU_PKG_8086, 0, 0, 0, 0, 0, 0, 0, MACHINE_PC | MACHINE_VIDEO, 1024, 2048,1024, 63, machine_xt_t1200_init, t1200_get_device }, + { "[8086] Olivetti M240", "olivetti_m240", MACHINE_TYPE_8086, CPU_PKG_8086, 0, 0, 0, 0, 0, 0, 0, MACHINE_PC, 128, 640, 128, 0, machine_xt_olim240_init, NULL }, + #if defined(DEV_BRANCH) && defined(USE_LASERXT) { "[8086] VTech Laser XT3", "lxt3", MACHINE_TYPE_8086, CPU_PKG_8086, 0, 0, 0, 0, 0, 0, 0, MACHINE_PC, 256, 640, 256, 0, machine_xt_lxt3_init, NULL }, #endif diff --git a/src/video/vid_ogc.c b/src/video/vid_ogc.c new file mode 100644 index 000000000..89c443ffe --- /dev/null +++ b/src/video/vid_ogc.c @@ -0,0 +1,693 @@ +/* + * 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 Olivetti OGC 8-bit ISA (GO708) and + * M21/M24/M28 16-bit bus (GO317/318/380/709) video cards. + * + * + * + * Authors: Sarah Walker, + * Miran Grca, + * Fred N. van Kempen, + * EngiNerd, + * + * Copyright 2008-2019 Sarah Walker. + * Copyright 2016-2019 Miran Grca. + * Copyright 2017-2019 Fred N. van Kempen. + * Copyright 2020 EngiNerd. + */ + +#include +#include +#include +#include +#include +#include +#include <86box/io.h> +#include <86box/video.h> +#include <86box/86box.h> +#include <86box/timer.h> +#include <86box/mem.h> +#include <86box/pit.h> +#include <86box/rom.h> +#include <86box/device.h> +#include <86box/vid_cga.h> +#include <86box/vid_ogc.h> +#include <86box/vid_cga_comp.h> + + + +/* + * Current bugs: + * - Olivetti diagnostics fail with errors: 6845 crtc write / read error out 0000 in 00ff + * - Dark blue (almost black) picture in composite mode + */ + +#define CGA_RGB 0 +#define CGA_COMPOSITE 1 + +#define COMPOSITE_OLD 0 +#define COMPOSITE_NEW 1 + + + +static video_timings_t timing_ogc = {VIDEO_ISA, 8,16,32, 8,16,32}; + +static uint8_t mdaattr[256][2][2]; + +void +ogc_recalctimings(ogc_t *ogc) +{ + double _dispontime, _dispofftime, disptime; + + if (ogc->cga.cgamode & 1) { + disptime = ogc->cga.crtc[0] + 1; + _dispontime = ogc->cga.crtc[1]; + } else { + disptime = (ogc->cga.crtc[0] + 1) << 1; + _dispontime = ogc->cga.crtc[1] << 1; + } + + _dispofftime = disptime - _dispontime; + _dispontime *= CGACONST / 2; + _dispofftime *= CGACONST / 2; + ogc->cga.dispontime = (uint64_t)(_dispontime); + ogc->cga.dispofftime = (uint64_t)(_dispofftime); +} + +void +ogc_out(uint16_t addr, uint8_t val, void *priv) +{ + ogc_t *ogc = (ogc_t *)priv; + + // if (addr >= 0x3c0 && addr <= 0x3cf){ + // addr = addr + 16; + // } + + switch (addr) { + case 0x3d4: + case 0x3d5: + case 0x3d8: + case 0x3d9: + cga_out(addr, val, &ogc->cga); + break; + + case 0x3de: + /* set control register */ + ogc->ctrl_3de = val; + /* select 1st or 2nd 16k vram block to be used */ + ogc->base = (val & 0x08) ? 0x4000 : 0; + break; + } +} + +uint8_t +ogc_in(uint16_t addr, void *priv) +{ + ogc_t *ogc = (ogc_t *)priv; + + // if (addr >= 0x3c0 && addr <= 0x3cf){ + // addr = addr + 16; + // } + + uint8_t ret = 0xff; + + switch (addr) { + case 0x3d4: + case 0x3d5: + case 0x3da: + /* + * bits 6-7: 3 = no DEB expansion board installed + * bits 4-5: 2 color, 3 mono + * bit 3: high during 1st half of vertical retrace in character mode (CCA standard) + * bit 2: lightpen switch (CGA standard) + * bit 1: lightpen strobe (CGA standard) + * bit 0: high during retrace (CGA standard) + */ + ret = cga_in(addr, &ogc->cga); + ret = ret | 0xe0; + if (ogc->mono_display) + ret = ret | 0x10; + break; + } + + return(ret); +} + + +void +ogc_waitstates(void *p) +{ + int ws_array[16] = {3, 4, 5, 6, 7, 8, 4, 5, 6, 7, 8, 4, 5, 6, 7, 8}; + int ws; + + ws = ws_array[cycles & 0xf]; + sub_cycles(ws); +} + + +void +ogc_write(uint32_t addr, uint8_t val, void *priv) +{ + ogc_t *ogc = (ogc_t *)priv; + int offset; + + ogc->cga.vram[addr & 0x7FFF]=val; + if (ogc->cga.snow_enabled) { + /* recreate snow effect */ + offset = ((timer_get_remaining_u64(&ogc->cga.timer) / CGACONST) * 4) & 0xfc; + ogc->cga.charbuffer[offset] = ogc->cga.vram[addr & 0x7fff]; + ogc->cga.charbuffer[offset | 1] = ogc->cga.vram[addr & 0x7fff]; + } + egawrites++; + ogc_waitstates(&ogc->cga); +} + +uint8_t +ogc_read(uint32_t addr, void *priv) +{ + + ogc_t *ogc = (ogc_t *)priv; + int offset; + + ogc_waitstates(&ogc->cga); + + if (ogc->cga.snow_enabled) { + /* recreate snow effect */ + offset = ((timer_get_remaining_u64(&ogc->cga.timer) / CGACONST) * 4) & 0xfc; + ogc->cga.charbuffer[offset] = ogc->cga.vram[addr & 0x7fff]; + ogc->cga.charbuffer[offset | 1] = ogc->cga.vram[addr & 0x7fff]; + } + + egareads++; + return(ogc->cga.vram[addr & 0x7FFF]); +} + +void +ogc_poll(void *priv) +{ + ogc_t *ogc = (ogc_t *)priv; + uint16_t ca = (ogc->cga.crtc[15] | (ogc->cga.crtc[14] << 8)) & 0x3fff; + int drawcursor; + int x, c, xs_temp, ys_temp; + int oldvc; + uint8_t chr, attr; + uint16_t dat, dat2; + int cols[4]; + int oldsc; + int blink = 0; + int underline = 0; + uint8_t border; + + //composito colore appare blu scuro + + /* graphic mode and not mode 40h */ + if (!(ogc->ctrl_3de & 0x1 || !(ogc->cga.cgamode & 2))) { + /* standard cga mode */ + cga_poll(&ogc->cga); + return; + } else { + /* mode 40h or text mode */ + if (!ogc->cga.linepos) { + timer_advance_u64(&ogc->cga.timer, ogc->cga.dispofftime); + ogc->cga.cgastat |= 1; + ogc->cga.linepos = 1; + oldsc = ogc->cga.sc; + if ((ogc->cga.crtc[8] & 3) == 3) + ogc->cga.sc = ((ogc->cga.sc << 1) + ogc->cga.oddeven) & 7; + if (ogc->cga.cgadispon) { + if (ogc->cga.displine < ogc->cga.firstline) { + ogc->cga.firstline = ogc->cga.displine; + video_wait_for_buffer(); + } + ogc->cga.lastline = ogc->cga.displine; + /* 80-col */ + if (ogc->cga.cgamode & 1) { + /* for each text column */ + for (x = 0; x < ogc->cga.crtc[1]; x++) { + /* video output enabled */ + if (ogc->cga.cgamode & 8) { + /* character */ + chr = ogc->cga.charbuffer[x << 1]; + /* text attributes */ + attr = ogc->cga.charbuffer[(x << 1) + 1]; + } else + chr = attr = 0; + /* check if cursor has to be drawn */ + drawcursor = ((ogc->cga.ma == ca) && ogc->cga.con && ogc->cga.cursoron); + /* check if character underline mode should be set */ + underline = ((ogc->ctrl_3de & 0x40) && (attr & 0x1) && !(attr & 0x6)); + if (underline) { + /* set forecolor to white */ + attr = attr | 0x7; + } + blink = 0; + /* set foreground */ + cols[1] = (attr & 15) + 16; + /* blink active */ + if (ogc->cga.cgamode & 0x20) { + cols[0] = ((attr >> 4) & 7) + 16; + /* attribute 7 active and not cursor */ + if ((ogc->cga.cgablink & 8) && (attr & 0x80) && !ogc->cga.drawcursor) { + /* set blinking */ + cols[1] = cols[0]; + blink = 1; + } + } else { + /* Set intensity bit */ + cols[0] = (attr >> 4) + 16; + blink = (attr & 0x80) * 8 + 7 + 16; + } + /* character underline active and 7th row of pixels in character height being drawn */ + if (underline && (ogc->cga.sc == 7)) { + /* for each pixel in character width */ + for (c = 0; c < 8; c++) + buffer32->line[ogc->cga.displine][(x << 3) + c + 8] = mdaattr[attr][blink][1]; + } else if (drawcursor) { + for (c = 0; c < 8; c++) + buffer32->line[ogc->cga.displine][(x << 3) + c + 8] = cols[(fontdatm[chr][((ogc->cga.sc & 7) << 1) | ogc->lineff] & (1 << (c ^ 7))) ? 1 : 0] ^ 15; + } else { + for (c = 0; c < 8; c++) + buffer32->line[ogc->cga.displine][(x << 3) + c + 8] = cols[(fontdatm[chr][((ogc->cga.sc & 7) << 1) | ogc->lineff] & (1 << (c ^ 7))) ? 1 : 0]; + } + + ogc->cga.ma++; + } + } + /* 40-col */ + else if (!(ogc->cga.cgamode & 2)) { + for (x = 0; x < ogc->cga.crtc[1]; x++) { + if (ogc->cga.cgamode & 8) { + chr = ogc->cga.vram[((ogc->cga.ma << 1) & 0x3fff) + ogc->base]; + attr = ogc->cga.vram[(((ogc->cga.ma << 1) + 1) & 0x3fff) + ogc->base]; + } else { + chr = attr = 0; + } + drawcursor = ((ogc->cga.ma == ca) && ogc->cga.con && ogc->cga.cursoron); + /* check if character underline mode should be set */ + underline = ((ogc->ctrl_3de & 0x40) && (attr & 0x1) && !(attr & 0x6)); + if (underline) { + /* set forecolor to white */ + attr = attr | 0x7; + } + blink = 0; + /* set foreground */ + cols[1] = (attr & 15) + 16; + /* blink active */ + if (ogc->cga.cgamode & 0x20) { + cols[0] = ((attr >> 4) & 7) + 16; + if ((ogc->cga.cgablink & 8) && (attr & 0x80) && !ogc->cga.drawcursor) { + /* set blinking */ + cols[1] = cols[0]; + blink = 1; + } + } else { + /* Set intensity bit */ + cols[0] = (attr >> 4) + 16; + blink = (attr & 0x80) * 8 + 7 + 16; + } + + + /* character underline active and 7th row of pixels in character height being drawn */ + if (underline && (ogc->cga.sc == 7)) { + /* for each pixel in character width */ + for (c = 0; c < 8; c++) + buffer32->line[ogc->cga.displine][(x << 4) + (c << 1) + 8] = + buffer32->line[ogc->cga.displine][(x << 4) + (c << 1) + 1 + 8] = mdaattr[attr][blink][1]; + } else if (drawcursor) { + for (c = 0; c < 8; c++) + buffer32->line[ogc->cga.displine][(x << 4) + (c << 1) + 8] = + buffer32->line[ogc->cga.displine][(x << 4) + (c << 1) + 1 + 8] = cols[(fontdatm[chr][((ogc->cga.sc & 7) << 1) | ogc->lineff] & (1 << (c ^ 7))) ? 1 : 0] ^ 15; + } else { + for (c = 0; c < 8; c++) + buffer32->line[ogc->cga.displine][(x << 4) + (c << 1) + 8] = + buffer32->line[ogc->cga.displine][(x << 4) + (c << 1) + 1 + 8] = cols[(fontdatm[chr][((ogc->cga.sc & 7) << 1) | ogc->lineff] & (1 << (c ^ 7))) ? 1 : 0]; + } + + ogc->cga.ma++; + + } + } else { + /* 640x400 mode */ + if (ogc->ctrl_3de & 1 ) { + dat2 = ((ogc->cga.sc & 1) * 0x4000) | (ogc->lineff * 0x2000); + cols[0] = 0; cols[1] = 15 + 16; + } + else { + dat2 = (ogc->cga.sc & 1) * 0x2000; + cols[0] = 0; cols[1] = (ogc->cga.cgacol & 15) + 16; + } + + for (x = 0; x < ogc->cga.crtc[1]; x++) { + /* video out */ + if (ogc->cga.cgamode & 8) { + dat = (ogc->cga.vram[((ogc->cga.ma << 1) & 0x1fff) + dat2] << 8) | ogc->cga.vram[((ogc->cga.ma << 1) & 0x1fff) + dat2 + 1]; + } else { + dat = 0; + } + ogc->cga.ma++; + + for (c = 0; c < 16; c++) { + buffer32->line[ogc->cga.displine][(x << 4) + c + 8] = cols[dat >> 15]; + dat <<= 1; + } + } + } + } else { + + /* ogc specific */ + cols[0] = ((ogc->cga.cgamode & 0x12) == 0x12) ? 0 : (ogc->cga.cgacol & 15) + 16; + if (ogc->cga.cgamode & 1) { + hline(buffer32, 0, (ogc->cga.displine << 1), ((ogc->cga.crtc[1] << 3) + 16) << 2, cols[0]); + hline(buffer32, 0, (ogc->cga.displine << 1) + 1, ((ogc->cga.crtc[1] << 3) + 16) << 2, cols[0]); + } else { + hline(buffer32, 0, (ogc->cga.displine << 1), ((ogc->cga.crtc[1] << 4) + 16) << 2, cols[0]); + hline(buffer32, 0, (ogc->cga.displine << 1) + 1, ((ogc->cga.crtc[1] << 4) + 16) << 2, cols[0]); + } + + } + + /* 80 columns */ + if (ogc->cga.cgamode & 1) + x = (ogc->cga.crtc[1] << 3) + 16; + else + x = (ogc->cga.crtc[1] << 4) + 16; + + if (ogc->cga.composite) { + if (ogc->cga.cgamode & 0x10) + border = 0x00; + else + border = ogc->cga.cgacol & 0x0f; + + Composite_Process(ogc->cga.cgamode, border, x >> 2, buffer32->line[(ogc->cga.displine << 1)]); + Composite_Process(ogc->cga.cgamode, border, x >> 2, buffer32->line[(ogc->cga.displine << 1) + 1]); + } + + + ogc->cga.sc = oldsc; + if (ogc->cga.vc == ogc->cga.crtc[7] && !ogc->cga.sc) + ogc->cga.cgastat |= 8; + ogc->cga.displine++; + if (ogc->cga.displine >= 720) + ogc->cga.displine = 0; + } else { + timer_advance_u64(&ogc->cga.timer, ogc->cga.dispontime); + if (ogc->cga.cgadispon) ogc->cga.cgastat &= ~1; + ogc->cga.linepos = 0; + /* ogc specific */ + ogc->lineff ^= 1; + if (ogc->lineff) { + ogc->cga.ma = ogc->cga.maback; + } else { + if (ogc->cga.vsynctime) { + ogc->cga.vsynctime--; + if (!ogc->cga.vsynctime) + ogc->cga.cgastat &= ~8; + } + if (ogc->cga.sc == (ogc->cga.crtc[11] & 31) || ((ogc->cga.crtc[8] & 3) == 3 && ogc->cga.sc == ((ogc->cga.crtc[11] & 31) >> 1))) { + ogc->cga.con = 0; + ogc->cga.coff = 1; + } + if ((ogc->cga.crtc[8] & 3) == 3 && ogc->cga.sc == (ogc->cga.crtc[9] >> 1)) + ogc->cga.maback = ogc->cga.ma; + if (ogc->cga.vadj) { + ogc->cga.sc++; + ogc->cga.sc &= 31; + ogc->cga.ma = ogc->cga.maback; + ogc->cga.vadj--; + if (!ogc->cga.vadj) { + ogc->cga.cgadispon = 1; + ogc->cga.ma = ogc->cga.maback = (ogc->cga.crtc[13] | (ogc->cga.crtc[12] << 8)) & 0x3fff; + ogc->cga.sc = 0; + } + } else if (ogc->cga.sc == ogc->cga.crtc[9] || ((ogc->cga.crtc[8] & 3) == 3 && ogc->cga.sc == (ogc->cga.crtc[9] >> 1))) { + ogc->cga.maback = ogc->cga.ma; + ogc->cga.sc = 0; + oldvc = ogc->cga.vc; + ogc->cga.vc++; + ogc->cga.vc &= 127; + + if (ogc->cga.vc == ogc->cga.crtc[6]) + ogc->cga.cgadispon=0; + + if (oldvc == ogc->cga.crtc[4]) { + ogc->cga.vc = 0; + ogc->cga.vadj = ogc->cga.crtc[5]; + if (!ogc->cga.vadj) { + ogc->cga.cgadispon = 1; + ogc->cga.ma = ogc->cga.maback = (ogc->cga.crtc[13] | (ogc->cga.crtc[12] << 8)) & 0x3fff; + } + switch (ogc->cga.crtc[10] & 0x60) { + case 0x20: + ogc->cga.cursoron = 0; + break; + case 0x60: + ogc->cga.cursoron = ogc->cga.cgablink & 0x10; + break; + default: + ogc->cga.cursoron = ogc->cga.cgablink & 0x08; + break; + } + } + if (ogc->cga.vc == ogc->cga.crtc[7]) { + ogc->cga.cgadispon = 0; + ogc->cga.displine = 0; + /* ogc specific */ + ogc->cga.vsynctime = (ogc->cga.crtc[3] >> 4) + 1; + if (ogc->cga.crtc[7]) { + if (ogc->cga.cgamode & 1) + x = (ogc->cga.crtc[1] << 3) + 16; + else + x = (ogc->cga.crtc[1] << 4) + 16; + ogc->cga.lastline++; + + xs_temp = x; + ys_temp = (ogc->cga.lastline - ogc->cga.firstline); + + if ((xs_temp > 0) && (ys_temp > 0)) { + if (xsize < 64) xs_temp = 656; + /* ogc specific */ + if (ysize < 32) ys_temp = 200; + if (!enable_overscan) + xs_temp -= 16; + + + if ((ogc->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); + } + /* ogc specific */ + if (enable_overscan) { + if (ogc->cga.composite) + video_blit_memtoscreen(0, (ogc->cga.firstline - 8), 0, (ogc->cga.lastline - ogc->cga.firstline) + 16, + xsize, (ogc->cga.lastline - ogc->cga.firstline) + 16); + else + video_blit_memtoscreen_8(0, (ogc->cga.firstline - 8), 0, (ogc->cga.lastline - ogc->cga.firstline) + 16, + xsize, (ogc->cga.lastline - ogc->cga.firstline) + 16); + } else { + if (ogc->cga.composite) + video_blit_memtoscreen(8, ogc->cga.firstline, 0, (ogc->cga.lastline - ogc->cga.firstline), + xsize, (ogc->cga.lastline - ogc->cga.firstline)); + else + video_blit_memtoscreen_8(8, ogc->cga.firstline, 0, (ogc->cga.lastline - ogc->cga.firstline), + xsize, (ogc->cga.lastline - ogc->cga.firstline)); + } + } + frames++; + + video_res_x = xsize; + video_res_y = ysize; + /* 80-col */ + if (ogc->cga.cgamode & 1) { + video_res_x /= 8; + video_res_y /= (ogc->cga.crtc[9] + 1) * 2; + video_bpp = 0; + /* 40-col */ + } else if (!(ogc->cga.cgamode & 2)) { + video_res_x /= 16; + video_res_y /= (ogc->cga.crtc[9] + 1) * 2; + video_bpp = 0; + } else if (!(ogc->ctrl_3de & 1)) { + video_res_y /= 2; + video_bpp = 1; + } + } + ogc->cga.firstline = 1000; + ogc->cga.lastline = 0; + ogc->cga.cgablink++; + ogc->cga.oddeven ^= 1; + } + } else { + ogc->cga.sc++; + ogc->cga.sc &= 31; + ogc->cga.ma = ogc->cga.maback; + } + + if (ogc->cga.cgadispon) + ogc->cga.cgastat &= ~1; + + if ((ogc->cga.sc == (ogc->cga.crtc[10] & 31) || ((ogc->cga.crtc[8] & 3) == 3 && ogc->cga.sc == ((ogc->cga.crtc[10] & 31) >> 1)))) + ogc->cga.con = 1; + } + /* 80-columns */ + if (ogc->cga.cgadispon && (ogc->cga.cgamode & 1)) { + for (x = 0; x < (ogc->cga.crtc[1] << 1); x++) + ogc->cga.charbuffer[x] = ogc->cga.vram[(((ogc->cga.ma << 1) + x) & 0x3fff) + ogc->base]; + } + } + } +} + +void +ogc_close(void *priv) +{ + ogc_t *ogc = (ogc_t *)priv; + + free(ogc->cga.vram); + free(ogc); +} + +void +ogc_speed_changed(void *priv) +{ + ogc_t *ogc = (ogc_t *)priv; + + ogc_recalctimings(ogc); +} + +void +ogc_mdaattr_rebuild(){ + int c; + + for (c = 0; c < 256; c++) { + mdaattr[c][0][0] = mdaattr[c][1][0] = mdaattr[c][1][1] = 16; + if (c & 8) mdaattr[c][0][1] = 15 + 16; + else mdaattr[c][0][1] = 7 + 16; + } + + mdaattr[0x70][0][1] = 16; + mdaattr[0x70][0][0] = mdaattr[0x70][1][0] = mdaattr[0x70][1][1] = 16 + 15; + mdaattr[0xF0][0][1] = 16; + mdaattr[0xF0][0][0] = mdaattr[0xF0][1][0] = mdaattr[0xF0][1][1] = 16 + 15; + mdaattr[0x78][0][1] = 16 + 7; + mdaattr[0x78][0][0] = mdaattr[0x78][1][0] = mdaattr[0x78][1][1] = 16 + 15; + mdaattr[0xF8][0][1] = 16 + 7; + mdaattr[0xF8][0][0] = mdaattr[0xF8][1][0] = mdaattr[0xF8][1][1] = 16 + 15; + mdaattr[0x00][0][1] = mdaattr[0x00][1][1] = 16; + mdaattr[0x08][0][1] = mdaattr[0x08][1][1] = 16; + mdaattr[0x80][0][1] = mdaattr[0x80][1][1] = 16; + mdaattr[0x88][0][1] = mdaattr[0x88][1][1] = 16; +} + +/* + * Missing features + * - Composite video mode not working + * - Optional EGC expansion board (which handles 640x400x16) not implemented + */ +void * +ogc_init(const device_t *info) +{ + // int display_type; + ogc_t *ogc = (ogc_t *)malloc(sizeof(ogc_t)); + + memset(ogc, 0x00, sizeof(ogc_t)); + video_inform(VIDEO_FLAG_TYPE_CGA, &timing_ogc); + + loadfont(L"roms/video/ogc/ogc graphics board go380 258 pqbq.bin", 1); + + /* composite is not working yet */ + // display_type = device_get_config_int("display_type"); + ogc->cga.composite = 0; // (display_type != CGA_RGB); + ogc->cga.revision = device_get_config_int("composite_type"); + ogc->cga.snow_enabled = device_get_config_int("snow_enabled"); + + ogc->cga.vram = malloc(0x8000); + + cga_comp_init(ogc->cga.revision); + timer_add(&ogc->cga.timer, ogc_poll, ogc, 1); + mem_mapping_add(&ogc->cga.mapping, 0xb8000, 0x08000, + ogc_read, NULL, NULL, + ogc_write, NULL, NULL, NULL, 0, ogc); + io_sethandler(0x03d0, 16, ogc_in, NULL, NULL, ogc_out, NULL, NULL, ogc); + + overscan_x = overscan_y = 16; + ogc->cga.rgb_type = device_get_config_int("rgb_type"); + cga_palette = (ogc->cga.rgb_type << 1); + cgapal_rebuild(); + ogc_mdaattr_rebuild(); + + /* color display */ + if (device_get_config_int("rgb_type")==0 || device_get_config_int("rgb_type") == 4) + ogc->mono_display = 0; + else + ogc->mono_display = 1; + + return ogc; +} + + +const device_config_t ogc_m24_config[] = +{ + { + /* Olivetti / ATT compatible displays */ + "rgb_type", "RGB type", CONFIG_SELECTION, "", CGA_RGB, "", { 0 }, + { + { + "Color", 0 + }, + { + "Green Monochrome", 1 + }, + { + "Amber Monochrome", 2 + }, + { + "Gray Monochrome", 3 + }, + { + "" + } + } + }, + { + "snow_enabled", "Snow emulation", CONFIG_BINARY, "", 1, + }, + { + "", "", -1 + } +}; + +const device_t ogc_m24_device = +{ + "Olivetti M21/M24/M28 (GO317/318/380/709) video card", + DEVICE_ISA, 0, + ogc_init, + ogc_close, + NULL, + { NULL }, + ogc_speed_changed, + NULL, + ogc_m24_config +}; + +const device_t ogc_device = +{ + "Olivetti OGC (GO708)", + DEVICE_ISA, 0, + ogc_init, + ogc_close, + NULL, + { NULL }, + ogc_speed_changed, + NULL, + cga_config +}; \ No newline at end of file diff --git a/src/video/vid_table.c b/src/video/vid_table.c index e8605e16d..b332326de 100644 --- a/src/video/vid_table.c +++ b/src/video/vid_table.c @@ -177,6 +177,7 @@ video_cards[] = { { "virge375_vbe20_vlb", &s3_virge_375_4_vlb_device }, { "tgui9400cxi_vlb", &tgui9400cxi_device }, { "tgui9440_vlb", &tgui9440_vlb_device }, + { "ogc", &ogc_device }, { "", NULL } }; diff --git a/src/video/video.c b/src/video/video.c index 2b1a9bcd5..f99040210 100644 --- a/src/video/video.c +++ b/src/video/video.c @@ -1038,7 +1038,21 @@ loadfont(wchar_t *s, int format) for (c = 0; c < 256; c++) fread(&fontdat12x18[c][0], 1, 36, f); break; - } + + case 10: /* Olivetti M19 */ + fseek(f, 90, SEEK_SET); + for (d = 0; d < 4; d++) { + /* There are 4 fonts in the ROM */ + for (c = 0; c < 256; c++) /* 8x14 MDA in 8x16 cell */ + fread(&fontdatm[256*d + c][0], 1, 16, f); + for (c = 0; c < 256; c++) { /* 8x8 CGA in 8x16 cell */ + fread(&fontdat[256*d + c][0], 1, 8, f); + fseek(f, 8, SEEK_CUR); + } + } + break; + + } (void)fclose(f); } diff --git a/src/win/Makefile.mingw b/src/win/Makefile.mingw index 1c541c254..c5bd44a22 100644 --- a/src/win/Makefile.mingw +++ b/src/win/Makefile.mingw @@ -637,7 +637,7 @@ MCHOBJ := machine.o machine_table.o \ m_xt_xi8088.o m_xt_zenith.o \ m_pcjr.o \ m_amstrad.o m_europc.o \ - m_olivetti_m24.o m_tandy.o \ + m_xt_olivetti.o m_tandy.o \ m_at.o m_at_commodore.o \ m_at_t3100e.o m_at_t3100e_vid.o \ m_ps1.o m_ps1_hdc.o \ @@ -781,7 +781,8 @@ VIDOBJ := video.o \ vid_voodoo_display.o vid_voodoo_fb.o \ vid_voodoo_fifo.o vid_voodoo_reg.o \ vid_voodoo_render.o vid_voodoo_setup.o \ - vid_voodoo_texture.o + vid_voodoo_texture.o \ + vid_ogc.o PLATOBJ := win.o \ win_dynld.o win_thread.o \