From 901a75bb5dba8eacbb4ec1f0ea5f47f2f30af7d1 Mon Sep 17 00:00:00 2001 From: EngiNerd89 Date: Tue, 8 Dec 2020 18:33:20 +0100 Subject: [PATCH] Ported NCR PC4i from PCem. Implemented NCR NGA (640x400 extended CGA) graphic card. --- src/include/86box/machine.h | 1 + src/include/86box/vid_nga.h | 48 +++ src/include/86box/video.h | 4 + src/machine/m_xt.c | 19 + src/machine/m_xt_olivetti.c | 2 +- src/machine/machine_table.c | 4 +- src/video/vid_nga.c | 683 ++++++++++++++++++++++++++++++++++++ src/video/vid_ogc.c | 11 +- src/video/vid_table.c | 1 + src/video/video.c | 46 +-- src/win/Makefile.mingw | 3 +- 11 files changed, 792 insertions(+), 30 deletions(-) create mode 100644 src/include/86box/vid_nga.h create mode 100644 src/video/vid_nga.c diff --git a/src/include/86box/machine.h b/src/include/86box/machine.h index 380aacaf8..d920ef494 100644 --- a/src/include/86box/machine.h +++ b/src/include/86box/machine.h @@ -578,6 +578,7 @@ extern int machine_xt_dtk_init(const machine_t *); extern int machine_xt_jukopc_init(const machine_t *); extern int machine_xt_open_xt_init(const machine_t *); extern int machine_xt_pxxt_init(const machine_t *); +extern int machine_xt_ncrpc4i_init(const machine_t *); extern int machine_xt_iskra3104_init(const machine_t *); diff --git a/src/include/86box/vid_nga.h b/src/include/86box/vid_nga.h new file mode 100644 index 000000000..1c8bd786e --- /dev/null +++ b/src/include/86box/vid_nga.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 nga_t { + cga_t cga; + /* unused in OGC, required for M19 video card structure idiom */ + uint32_t base; + int lineff; + int page; + uint8_t *vram_64k; + mem_mapping_t mapping_64k; +} nga_t; + +void nga_recalctimings(nga_t *ogc); +void nga_out(uint16_t addr, uint8_t val, void *priv); +uint8_t nga_in(uint16_t addr, void *priv); +void nga_write(uint32_t addr, uint8_t val, void *priv); +uint8_t nga_read(uint32_t addr, void *priv); +void nga_poll(void *priv); +void nga_close(void *priv); +void nga_mdaattr_rebuild(); + + +#ifdef EMU_DEVICE_H +extern const device_config_t nga_config[]; +extern const device_t nga_device; +#endif diff --git a/src/include/86box/video.h b/src/include/86box/video.h index 959912ac4..8b1917ae5 100644 --- a/src/include/86box/video.h +++ b/src/include/86box/video.h @@ -173,6 +173,7 @@ extern uint8_t video_force_resize_get(void); extern void video_force_resize_set(uint8_t res); extern void video_update_timing(void); +extern void loadfont_ex(wchar_t *s, int format, int offset); extern void loadfont(wchar_t *s, int format); extern int get_actual_size_x(void); @@ -245,6 +246,9 @@ extern const device_t compaq_cga_2_device; extern const device_t ogc_device; extern const device_t ogc_m24_device; +/* NCR NGA */ +extern const device_t nga_device; + /* Tseng ET4000AX */ extern const device_t et4000_isa_device; extern const device_t et4000k_isa_device; diff --git a/src/machine/m_xt.c b/src/machine/m_xt.c index fbf3f0891..310a5fa37 100644 --- a/src/machine/m_xt.c +++ b/src/machine/m_xt.c @@ -322,3 +322,22 @@ machine_xt_iskra3104_init(const machine_t *model) return ret; } + +int +machine_xt_ncrpc4i_init(const machine_t *model) +{ + int ret; + + ret = bios_load_linear(L"roms/machines/ncr_pc4i/NCR_PC4i_BIOSROM_1985.bin", + 0x000fc000, 16384, 0); + + if (bios_only || !ret) + return ret; + + machine_xt_clone_init(model); + + return ret; +} + + + diff --git a/src/machine/m_xt_olivetti.c b/src/machine/m_xt_olivetti.c index fec71f8ff..4e2184371 100644 --- a/src/machine/m_xt_olivetti.c +++ b/src/machine/m_xt_olivetti.c @@ -522,7 +522,7 @@ m19_vid_init(olim19_vid_t *vid){ //display_type = device_get_config_int("display_type"); /* OGC emulation part begin */ - loadfont(L"roms/machines/olivetti_m19/BIOS.BIN", 10); + loadfont_ex(L"roms/machines/olivetti_m19/BIOS.BIN", 1, 90); /* 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"); diff --git a/src/machine/machine_table.c b/src/machine/machine_table.c index 4eccb6661..905793b09 100644 --- a/src/machine/machine_table.c +++ b/src/machine/machine_table.c @@ -80,6 +80,8 @@ const machine_t machines[] = { { "[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 }, + { "[8088] NCR PC4i", "ncr_pc4i", MACHINE_TYPE_8088, CPU_PKG_8088, 0, 0, 0, 0, 0, 0, 0, MACHINE_PC, 256, 640, 256, 0, machine_xt_ncrpc4i_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 }, @@ -88,7 +90,7 @@ 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 | MACHINE_MOUSE, 128, 640, 128, 0, machine_xt_olim24_init, m24_get_device }, + { "[8086] Olivetti M21/24/24SP", "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 }, diff --git a/src/video/vid_nga.c b/src/video/vid_nga.c new file mode 100644 index 000000000..6b1b60dcb --- /dev/null +++ b/src/video/vid_nga.c @@ -0,0 +1,683 @@ +/* + * 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 NCR NGA (K511, K201) 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_nga.h> +#include <86box/vid_cga_comp.h> + + + +#define CGA_RGB 0 +#define CGA_COMPOSITE 1 + +#define COMPOSITE_OLD 0 +#define COMPOSITE_NEW 1 + + + +static video_timings_t timing_nga = {VIDEO_ISA, 8,16,32, 8,16,32}; + +void +nga_recalctimings(nga_t *nga) +{ + double _dispontime, _dispofftime, disptime; + + if ((nga->cga.cgamode & 1) ) { + disptime = nga->cga.crtc[0] + 1; + _dispontime = nga->cga.crtc[1]; + } else { + disptime = (nga->cga.crtc[0] + 1) << 1; + _dispontime = nga->cga.crtc[1] << 1; + } + + _dispofftime = disptime - _dispontime; + _dispontime *= CGACONST / 2; + _dispofftime *= CGACONST / 2; + nga->cga.dispontime = (uint64_t)(_dispontime); + nga->cga.dispofftime = (uint64_t)(_dispofftime); +} + +void +nga_out(uint16_t addr, uint8_t val, void *priv) +{ + nga_t *nga = (nga_t *)priv; + + cga_out(addr, val, &nga->cga); + +} + +uint8_t +nga_in(uint16_t addr, void *priv) +{ + nga_t *nga = (nga_t *)priv; + + return cga_in(addr, &nga->cga); +} + + +void +nga_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 +nga_write(uint32_t addr, uint8_t val, void *priv) +{ + nga_t *nga = (nga_t *)priv; + int offset; + /* a8000-affff */ + if(!(addr & 0x10000)) + nga->vram_64k[addr & 0x7FFF]=val; + /* b8000-bffff */ + else + nga->cga.vram[addr & 0x7FFF]=val; + + if (nga->cga.snow_enabled) { + /* recreate snow effect */ + offset = ((timer_get_remaining_u64(&nga->cga.timer) / CGACONST) * 4) & 0xfc; + nga->cga.charbuffer[offset] = nga->cga.vram[addr & 0x7fff]; + nga->cga.charbuffer[offset | 1] = nga->cga.vram[addr & 0x7fff]; + } + egawrites++; + nga_waitstates(&nga->cga); +} + +uint8_t +nga_read(uint32_t addr, void *priv) +{ + + nga_t *nga = (nga_t *)priv; + int offset; + uint8_t ret; + /* a8000-affff */ + if(!(addr & 0x10000)) + ret = nga->vram_64k[addr & 0x7FFF]; + else + ret = nga->cga.vram[addr & 0x7FFF]; + + nga_waitstates(&nga->cga); + + if (nga->cga.snow_enabled) { + /* recreate snow effect */ + offset = ((timer_get_remaining_u64(&nga->cga.timer) / CGACONST) * 4) & 0xfc; + nga->cga.charbuffer[offset] = nga->cga.vram[addr & 0x7fff]; + nga->cga.charbuffer[offset | 1] = nga->cga.vram[addr & 0x7fff]; + } + + egareads++; + return(ret); +} + +void +nga_poll(void *priv) +{ + nga_t *nga = (nga_t *)priv; + /* set cursor position in memory */ + uint16_t ca = (nga->cga.crtc[15] | (nga->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 col; + int oldsc; + + /* graphic mode and not high-res modes */ + if ((nga->cga.cgamode & 2) && !(nga->cga.cgamode & 0x40)) { + /* standard cga mode */ + cga_poll(&nga->cga); + return; + } else { + /* high-res or text mode */ + if (!nga->cga.linepos) { + timer_advance_u64(&nga->cga.timer, nga->cga.dispofftime); + nga->cga.cgastat |= 1; + nga->cga.linepos = 1; + oldsc = nga->cga.sc; + /* if interlaced */ + if ((nga->cga.crtc[8] & 3) == 3) + nga->cga.sc = ((nga->cga.sc << 1) + nga->cga.oddeven) & 7; + if (nga->cga.cgadispon) { + if (nga->cga.displine < nga->cga.firstline) { + nga->cga.firstline = nga->cga.displine; + video_wait_for_buffer(); + } + nga->cga.lastline = nga->cga.displine; + /* 80-col */ + if ((nga->cga.cgamode & 1) && !(nga->cga.cgamode & 2)) { + /* for each text column */ + for (x = 0; x < nga->cga.crtc[1]; x++) { + /* video output enabled */ + if (nga->cga.cgamode & 8) { + /* character */ + chr = nga->cga.charbuffer[x << 1]; + /* text attributes */ + attr = nga->cga.charbuffer[(x << 1) + 1]; + } else + chr = attr = 0; + /* check if cursor has to be drawn */ + drawcursor = ((nga->cga.ma == ca) && nga->cga.con && nga->cga.cursoron); + /* set foreground */ + cols[1] = (attr & 15) + 16; + /* blink active */ + if (nga->cga.cgamode & 0x20) { + cols[0] = ((attr >> 4) & 7) + 16; + /* attribute 7 active and not cursor */ + if ((nga->cga.cgablink & 8) && (attr & 0x80) && !nga->cga.drawcursor) { + /* set blinking */ + cols[1] = cols[0]; + } + } else { + /* Set intensity bit */ + cols[0] = (attr >> 4) + 16; + } + if (drawcursor) { + for (c = 0; c < 8; c++) + buffer32->line[nga->cga.displine][(x << 3) + c + 8] = cols[(fontdatm[chr][((nga->cga.sc & 7) << 1) | nga->lineff] & (1 << (c ^ 7))) ? 1 : 0] ^ 15; + } else { + for (c = 0; c < 8; c++) + buffer32->line[nga->cga.displine][(x << 3) + c + 8] = cols[(fontdatm[chr][((nga->cga.sc & 7) << 1) | nga->lineff] & (1 << (c ^ 7))) ? 1 : 0]; + } + + nga->cga.ma++; + } + } + /* 40-col */ + else if (!(nga->cga.cgamode & 2)) { + /* for each text column */ + for (x = 0; x < nga->cga.crtc[1]; x++) { + if (nga->cga.cgamode & 8) { + chr = nga->cga.vram[((nga->cga.ma << 1) & 0x3fff) + nga->base]; + attr = nga->cga.vram[(((nga->cga.ma << 1) + 1) & 0x3fff) + nga->base]; + } else { + chr = attr = 0; + } + drawcursor = ((nga->cga.ma == ca) && nga->cga.con && nga->cga.cursoron); + /* set foreground */ + cols[1] = (attr & 15) + 16; + /* blink active */ + if (nga->cga.cgamode & 0x20) { + cols[0] = ((attr >> 4) & 7) + 16; + if ((nga->cga.cgablink & 8) && (attr & 0x80) && !nga->cga.drawcursor) { + /* set blinking */ + cols[1] = cols[0]; + } + } else { + /* Set intensity bit */ + cols[0] = (attr >> 4) + 16; + } + + if (drawcursor) { + for (c = 0; c < 8; c++) + buffer32->line[nga->cga.displine][(x << 4) + (c << 1) + 8] = + buffer32->line[nga->cga.displine][(x << 4) + (c << 1) + 1 + 8] = cols[(fontdatm[chr][((nga->cga.sc & 7) << 1) | nga->lineff] & (1 << (c ^ 7))) ? 1 : 0] ^ 15; + } else { + for (c = 0; c < 8; c++) + buffer32->line[nga->cga.displine][(x << 4) + (c << 1) + 8] = + buffer32->line[nga->cga.displine][(x << 4) + (c << 1) + 1 + 8] = cols[(fontdatm[chr][((nga->cga.sc & 7) << 1) | nga->lineff] & (1 << (c ^ 7))) ? 1 : 0]; + } + + nga->cga.ma++; + + } + } else { + /* high res modes */ + if (nga->cga.cgamode & 0x40) { + /* 640x400x2 mode */ + if (nga->cga.cgamode & 0x4 || nga->cga.cgamode & 0x10) { + /* + * Scanlines are read in the following order: + * 0b8000-0b9f3f even scans (0,4,...) + * 0ba000-0bbf3f odd scans (2,6,...) + * 0bc000-0bdf3f even scans (1,5,...) + * 0be000-0bff3f odd scans (3,7,...) + */ + dat2 = ((nga->cga.sc & 1) * 0x2000) | (nga->lineff * 0x4000); + cols[0] = 0; cols[1] = 15 + 16; + /* 640x400x4 mode */ + } else { + cols[0] = (nga->cga.cgacol & 15) | 16; + col = (nga->cga.cgacol & 16) ? 24 : 16; + if (nga->cga.cgamode & 4) { + cols[1] = col | 3; /* Cyan */ + cols[2] = col | 4; /* Red */ + cols[3] = col | 7; /* White */ + } else if (nga->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 */ + } + /* + * Scanlines are read in the following order: + * 0b8000-0bbf3f even scans (0,4,...) + * 0bc000-0bff3f odd scans (1,5,...) + * 0a8000-0abf3f even scans (2,6,...) + * 0ac000-0aff3f odd scans (3,7,...) + */ + dat2 = (nga->cga.sc & 1) * 0x4000; + } + } + else { + dat2 = (nga->cga.sc & 1) * 0x2000; + cols[0] = 0; cols[1] = (nga->cga.cgacol & 15) + 16; + } + + /* for each text column */ + for (x = 0; x < nga->cga.crtc[1]; x++) { + /* video out */ + if (nga->cga.cgamode & 8) { + /* 640x400x2 */ + if (nga->cga.cgamode & 0x4 || nga->cga.cgamode & 0x10) { + /* read two bytes at a time */ + dat = (nga->cga.vram[((nga->cga.ma << 1) & 0x1fff) + dat2] << 8) | nga->cga.vram[((nga->cga.ma << 1) & 0x1fff) + dat2 + 1]; + /* each pixel is represented by one bit, so draw 16 pixels at a time */ + /* crtc[1] is 40 column, so 40x16=640 pixels */ + for (c = 0; c < 16; c++) { + buffer32->line[nga->cga.displine][(x << 4) + c + 8] = cols[dat >> 15]; + dat <<= 1; + } + /* 640x400x4 */ + } else { + /* lines 2,3,6,7,etc. */ + if (nga->cga.sc & 2) + /* read two bytes at a time */ + dat = (nga->vram_64k[((nga->cga.ma << 1) & 0x7fff) + dat2] << 8) | nga->vram_64k[((nga->cga.ma << 1) & 0x7fff) + dat2 + 1]; + /* lines 0,1,4,5,etc. */ + else + /* read two bytes at a time */ + dat = (nga->cga.vram[((nga->cga.ma << 1) & 0x7fff) + dat2] << 8) | nga->cga.vram[((nga->cga.ma << 1) & 0x7fff) + dat2 + 1]; + /* each pixel is represented by two bits, so draw 8 pixels at a time */ + /* crtc[1] is 80 column, so 80x8=640 pixels */ + for (c = 0; c < 8; c++) { + buffer32->line[nga->cga.displine][(x << 3) + c + 8] = cols[dat >> 14]; + dat <<= 2; + } + } + } else { + dat = 0; + } + nga->cga.ma++; + } + } + } else { + + /* nga specific */ + cols[0] = ((nga->cga.cgamode & 0x12) == 0x12) ? 0 : (nga->cga.cgacol & 15) + 16; + /* 80-col */ + if ((nga->cga.cgamode & 1) ) { + hline(buffer32, 0, (nga->cga.displine << 1), ((nga->cga.crtc[1] << 3) + 16) << 2, cols[0]); + hline(buffer32, 0, (nga->cga.displine << 1) + 1, ((nga->cga.crtc[1] << 3) + 16) << 2, cols[0]); + } else { + hline(buffer32, 0, (nga->cga.displine << 1), ((nga->cga.crtc[1] << 4) + 16) << 2, cols[0]); + hline(buffer32, 0, (nga->cga.displine << 1) + 1, ((nga->cga.crtc[1] << 4) + 16) << 2, cols[0]); + } + + } + + nga->cga.sc = oldsc; + /* vertical sync */ + if (nga->cga.vc == nga->cga.crtc[7] && !nga->cga.sc) + nga->cga.cgastat |= 8; + nga->cga.displine++; + if (nga->cga.displine >= 720) + nga->cga.displine = 0; + } else { + timer_advance_u64(&nga->cga.timer, nga->cga.dispontime); + if (nga->cga.cgadispon) nga->cga.cgastat &= ~1; + nga->cga.linepos = 0; + /* nga specific */ + nga->lineff ^= 1; + + /* text mode or 640x400x2 */ + if (nga->lineff && !((nga->cga.cgamode & 1) && (nga->cga.cgamode & 0x40))) { + nga->cga.ma = nga->cga.maback; + /* 640x400x4 */ + } else { + if (nga->cga.vsynctime) { + nga->cga.vsynctime--; + if (!nga->cga.vsynctime) + nga->cga.cgastat &= ~8; + } + /* cursor stop scanline */ + if (nga->cga.sc == (nga->cga.crtc[11] & 31) || ((nga->cga.crtc[8] & 3) == 3 && nga->cga.sc == ((nga->cga.crtc[11] & 31) >> 1))) { + nga->cga.con = 0; + nga->cga.coff = 1; + } + /* interlaced and max scanline per char reached */ + if ((nga->cga.crtc[8] & 3) == 3 && nga->cga.sc == (nga->cga.crtc[9] >> 1)) + nga->cga.maback = nga->cga.ma; + + if (nga->cga.vadj) { + nga->cga.sc++; + nga->cga.sc &= 31; + nga->cga.ma = nga->cga.maback; + nga->cga.vadj--; + if (!nga->cga.vadj) { + nga->cga.cgadispon = 1; + /* change start of displayed page (crtc 12-13) */ + nga->cga.ma = nga->cga.maback = (nga->cga.crtc[13] | (nga->cga.crtc[12] << 8)) & 0x7fff; + nga->cga.sc = 0; + } + /* nga specific */ + /* end of character line reached */ + } else if (nga->cga.sc == nga->cga.crtc[9] || ((nga->cga.crtc[8] & 3) == 3 && nga->cga.sc == (nga->cga.crtc[9] >> 1))) { + nga->cga.maback = nga->cga.ma; + nga->cga.sc = 0; + oldvc = nga->cga.vc; + nga->cga.vc++; + nga->cga.vc &= 127; + + /* lines of character displayed */ + if (nga->cga.vc == nga->cga.crtc[6]) + nga->cga.cgadispon=0; + + /* total vertical lines */ + if (oldvc == nga->cga.crtc[4]) { + nga->cga.vc = 0; + /* adjust vertical lines */ + nga->cga.vadj = nga->cga.crtc[5]; + if (!nga->cga.vadj) { + nga->cga.cgadispon = 1; + /* change start of displayed page (crtc 12-13) */ + nga->cga.ma = nga->cga.maback = (nga->cga.crtc[13] | (nga->cga.crtc[12] << 8)) & 0x7fff; + } + /* cursor start */ + switch (nga->cga.crtc[10] & 0x60) { + case 0x20: + nga->cga.cursoron = 0; + break; + case 0x60: + nga->cga.cursoron = nga->cga.cgablink & 0x10; + break; + default: + nga->cga.cursoron = nga->cga.cgablink & 0x08; + break; + } + } + /* vertical line position */ + if (nga->cga.vc == nga->cga.crtc[7]) { + nga->cga.cgadispon = 0; + nga->cga.displine = 0; + /* nga specific */ + nga->cga.vsynctime = 16; + /* vsync pos */ + if (nga->cga.crtc[7]) { + if ((nga->cga.cgamode & 1)) + /* set screen width */ + x = (nga->cga.crtc[1] << 3) + 16; + else + x = (nga->cga.crtc[1] << 4) + 16; + nga->cga.lastline++; + + xs_temp = x; + ys_temp = (nga->cga.lastline - nga->cga.firstline); + + if ((xs_temp > 0) && (ys_temp > 0)) { + if (xsize < 64) xs_temp = 656; + /* nga specific */ + if (ysize < 32) ys_temp = 400; + if (!enable_overscan) + xs_temp -= 16; + + + if ((nga->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); + } + /* nga specific */ + if (enable_overscan) { + if (nga->cga.composite) + video_blit_memtoscreen(0, (nga->cga.firstline - 8), 0, (nga->cga.lastline - nga->cga.firstline) + 16, + xsize, (nga->cga.lastline - nga->cga.firstline) + 16); + else + video_blit_memtoscreen_8(0, (nga->cga.firstline - 8), 0, (nga->cga.lastline - nga->cga.firstline) + 16, + xsize, (nga->cga.lastline - nga->cga.firstline) + 16); + } else { + if (nga->cga.composite) + video_blit_memtoscreen(8, nga->cga.firstline, 0, (nga->cga.lastline - nga->cga.firstline), + xsize, (nga->cga.lastline - nga->cga.firstline)); + else + video_blit_memtoscreen_8(8, nga->cga.firstline, 0, (nga->cga.lastline - nga->cga.firstline), + xsize, (nga->cga.lastline - nga->cga.firstline)); + } + } + frames++; + + video_res_x = xsize; + video_res_y = ysize; + /* 80-col */ + if ((nga->cga.cgamode & 1) && !(nga->cga.cgamode & 0x40)) { + video_res_x /= 8; + video_res_y /= (nga->cga.crtc[9] + 1) * 2; + video_bpp = 0; + /* 40-col */ + } else if (!(nga->cga.cgamode & 2)) { + video_res_x /= 16; + video_res_y /= (nga->cga.crtc[9] + 1) * 2; + video_bpp = 0; + } + else if (nga->cga.cgamode & 0x40) { + video_res_x /= 8; + video_res_y /= 2; + video_bpp = 1; + } + } + nga->cga.firstline = 1000; + nga->cga.lastline = 0; + nga->cga.cgablink++; + nga->cga.oddeven ^= 1; + } + } else { + nga->cga.sc++; + nga->cga.sc &= 31; + nga->cga.ma = nga->cga.maback; + } + + if (nga->cga.cgadispon) + nga->cga.cgastat &= ~1; + + /* enable cursor if its scanline was reached */ + if ((nga->cga.sc == (nga->cga.crtc[10] & 31) || ((nga->cga.crtc[8] & 3) == 3 && nga->cga.sc == ((nga->cga.crtc[10] & 31) >> 1)))) + nga->cga.con = 1; + } + /* 80-columns */ + if (nga->cga.cgadispon && (nga->cga.cgamode & 1) ) { + /* for each character per line */ + for (x = 0; x < (nga->cga.crtc[1] << 1); x++) + nga->cga.charbuffer[x] = nga->cga.vram[(((nga->cga.ma << 1) + x) & 0x3fff) + nga->base]; + } + } + } +} + +void +nga_close(void *priv) +{ + nga_t *nga = (nga_t *)priv; + free(nga->vram_64k); + free(nga->cga.vram); + free(nga); +} + +void +nga_speed_changed(void *priv) +{ + nga_t *nga = (nga_t *)priv; + + nga_recalctimings(nga); +} + +void * +nga_init(const device_t *info) +{ + int mem; + uint8_t charset; + nga_t *nga = (nga_t *)malloc(sizeof(nga_t)); + + memset(nga, 0x00, sizeof(nga_t)); + video_inform(VIDEO_FLAG_TYPE_CGA, &timing_nga); + + charset = device_get_config_int("charset"); + + loadfont_ex(L"roms/video/nga/ncr_nga_35122.bin", 1, 4096 * charset); + + nga->cga.composite = 0; + nga->cga.snow_enabled = device_get_config_int("snow_enabled"); + + nga->cga.vram = malloc(0x8000); + nga->vram_64k = malloc(0x8000); + + timer_add(&nga->cga.timer, nga_poll, nga, 1); + mem_mapping_add(&nga->cga.mapping, 0xb8000, 0x8000, + nga_read, NULL, NULL, + nga_write, NULL, NULL, NULL, 0, nga); + + mem = device_get_config_int("memory"); + + if (mem > 32) { + /* make optional 32KB addessable */ + mem_mapping_add(&nga->mapping_64k, 0xa8000, 0x8000, + nga_read, NULL, NULL, + nga_write, NULL, NULL, NULL, 0, nga); + } + + io_sethandler(0x03d0, 16, nga_in, NULL, NULL, nga_out, NULL, NULL, nga); + + overscan_x = overscan_y = 16; + nga->cga.rgb_type = device_get_config_int("rgb_type"); + cga_palette = (nga->cga.rgb_type << 1); + cgapal_rebuild(); + + return nga; +} + + +const device_config_t nga_config[] = +{ + { + "rgb_type", "RGB type", CONFIG_SELECTION, "", 0, "", { 0 }, + { + { + "Color", 0 + }, + { + "Green Monochrome", 1 + }, + { + "Amber Monochrome", 2 + }, + { + "Gray Monochrome", 3 + }, + { + "Color (no brown)", 4 + }, + { + "" + } + } + }, + { + "snow_enabled", "Snow emulation", CONFIG_BINARY, "", 1 + }, + { + "memory", "Memory size", CONFIG_SELECTION, "", 64, "", { 0 }, + { + { + "32 KB", 32 + }, + { + "64 KB", 64 + }, + { + "" + } + } + }, + { + "charset", "Character set", CONFIG_SELECTION, "", 0, "", { 0 }, + { + { + "U.S. English", 0 + }, + { + "Scandinavian", 1 + }, + { + "Other languages", 2 + }, + { + "E.F. Hutton", 3 + }, + { + "" + } + } + }, + { + "", "", -1 + } +}; + + +const device_t nga_device = +{ + "NCR NGA", + DEVICE_ISA, 0, + nga_init, + nga_close, + NULL, + { NULL }, + nga_speed_changed, + NULL, + nga_config +}; \ No newline at end of file diff --git a/src/video/vid_ogc.c b/src/video/vid_ogc.c index 89c443ffe..b15565718 100644 --- a/src/video/vid_ogc.c +++ b/src/video/vid_ogc.c @@ -130,10 +130,12 @@ ogc_in(uint16_t addr, void *priv) * bit 0: high during retrace (CGA standard) */ ret = cga_in(addr, &ogc->cga); - ret = ret | 0xe0; - if (ogc->mono_display) - ret = ret | 0x10; - break; + if (addr == 0x3da){ + ret = ret | 0xe0; + if (ogc->mono_display) + ret = ret | 0x10; + break; + } } return(ret); @@ -425,6 +427,7 @@ ogc_poll(void *priv) ogc->cga.ma = ogc->cga.maback = (ogc->cga.crtc[13] | (ogc->cga.crtc[12] << 8)) & 0x3fff; ogc->cga.sc = 0; } + // potrebbe dare problemi con composito } 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; diff --git a/src/video/vid_table.c b/src/video/vid_table.c index b332326de..e6d2ca2c7 100644 --- a/src/video/vid_table.c +++ b/src/video/vid_table.c @@ -178,6 +178,7 @@ video_cards[] = { { "tgui9400cxi_vlb", &tgui9400cxi_device }, { "tgui9440_vlb", &tgui9440_vlb_device }, { "ogc", &ogc_device }, + { "nga", &nga_device }, { "", NULL } }; diff --git a/src/video/video.c b/src/video/video.c index f99040210..678e7771b 100644 --- a/src/video/video.c +++ b/src/video/video.c @@ -914,18 +914,12 @@ video_force_resize_set(uint8_t res) video_force_resize = res; } - void -loadfont(wchar_t *s, int format) +loadfont_common(FILE *f, int format) { - FILE *f; int c, d; - - f = rom_fopen(s, L"rb"); - if (f == NULL) - return; - - switch (format) { + + switch (format) { case 0: /* MDA */ for (c=0; c<256; c++) for (d=0; d<8; d++) @@ -1038,25 +1032,31 @@ 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); } +void +loadfont_ex(wchar_t *s, int format, int offset) +{ + FILE *f; + + f = rom_fopen(s, L"rb"); + if (f == NULL) + return; + + fseek(f, offset, SEEK_SET); + loadfont_common(f, format); + +} + +void +loadfont(wchar_t *s, int format) +{ + loadfont_ex(s, format, 0); +} uint32_t video_color_transform(uint32_t color) diff --git a/src/win/Makefile.mingw b/src/win/Makefile.mingw index c5bd44a22..23dee4930 100644 --- a/src/win/Makefile.mingw +++ b/src/win/Makefile.mingw @@ -782,7 +782,8 @@ VIDOBJ := video.o \ vid_voodoo_fifo.o vid_voodoo_reg.o \ vid_voodoo_render.o vid_voodoo_setup.o \ vid_voodoo_texture.o \ - vid_ogc.o + vid_ogc.o \ + vid_nga.o PLATOBJ := win.o \ win_dynld.o win_thread.o \