From 1d5f2a1a7ef4bbc70b23ad3bedbf47f0b59860f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Hrdli=C4=8Dka?= Date: Fri, 14 Jul 2017 23:34:10 +0200 Subject: [PATCH 1/7] Fixed editable Mouse dropdown in Settings --- src/WIN/86Box.rc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/WIN/86Box.rc b/src/WIN/86Box.rc index 28a4f1ca0..65029741d 100644 --- a/src/WIN/86Box.rc +++ b/src/WIN/86Box.rc @@ -278,7 +278,7 @@ STYLE DS_CONTROL | WS_CHILD FONT 9, "Segoe UI" BEGIN LTEXT "Mouse :",IDT_1709,7,8,57,10 - COMBOBOX IDC_COMBO_MOUSE,71,7,189,120,CBS_DROPDOWN | WS_VSCROLL | + COMBOBOX IDC_COMBO_MOUSE,71,7,189,120,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP LTEXT "Joystick :",IDT_1710,7,26,58,10 COMBOBOX IDC_COMBO_JOYSTICK,71,25,189,120,CBS_DROPDOWNLIST | @@ -916,7 +916,7 @@ BEGIN VALUE "FileDescription", "86Box - an emulator for X86-based systems\0" VALUE "FileVersion", "2.00\0" VALUE "InternalName", "86Box\0" - VALUE "LegalCopyright", "Copyright © SoftHistory, Sarah Walker, 2007-2017, Released under the GNU GPL v2\0" + VALUE "LegalCopyright", "Copyright � SoftHistory, Sarah Walker, 2007-2017, Released under the GNU GPL v2\0" VALUE "LegalTrademarks", "\0" VALUE "OriginalFilename", "86Box.exe\0" VALUE "PrivateBuild", "\0" From ccea4a189a9d3202b0a5dcd5617ac92be7426a95 Mon Sep 17 00:00:00 2001 From: basic2004 Date: Mon, 17 Jul 2017 23:04:50 +0900 Subject: [PATCH 2/7] Added VGA grayscale and choose screen type VGA render can transform to grayscale and applying color. Green, amber and white. --- src/VIDEO/vid_svga_render.c | 61 +++++++++++++++++++++++++++++++++---- src/WIN/86Box.rc | 10 +++++- src/WIN/resource.h | 5 +++ src/WIN/win.c | 13 ++++++++ src/config.c | 11 ++++++- src/ibm.h | 1 + 6 files changed, 93 insertions(+), 8 deletions(-) diff --git a/src/VIDEO/vid_svga_render.c b/src/VIDEO/vid_svga_render.c index 4c0c5c617..87bac9840 100644 --- a/src/VIDEO/vid_svga_render.c +++ b/src/VIDEO/vid_svga_render.c @@ -17,6 +17,7 @@ */ #include +#include #include "../ibm.h" #include "../mem.h" #include "video.h" @@ -25,21 +26,69 @@ int invert_display = 0; - +int video_grayscale = 0; uint32_t svga_color_transform(uint32_t color) { uint32_t temp = 0; + temp = color; + if (video_grayscale != 0) + { + temp = ((77 * (color & 0xff0000)) >> 24) + ((150 * (color & 0xff00)) >> 16) + ((29 * (color & 0xff)) >> 8); + if (temp > 0xff) + temp = 0xff; + + float temp_r = 0; + float temp_g = 0; + float temp_b = 0; + temp_r = temp_g = temp_b = ((float)temp) / 256; + switch (video_grayscale) + { + case 2: + temp_r = pow(temp_r, 0.6); + temp_g = 0.9 * pow(temp_g, 2); + temp_b = 0.2 * pow(temp_b, 6); + break; + case 3: + temp_r = 0.225 * pow(temp_r, 4); + temp_g = pow(temp_g, 0.75); + temp_b = 0.375 * pow(temp_b, 2); + break; + case 4: + temp_r = pow(temp_r, 1.05); + temp_g = 0.99 * temp_g; + temp_b = 0.925 * pow(temp_b, 0.9); + break; + } + if (temp_r >= 1) + temp = 0xff0000; + else if (temp_r <= 0) + temp = 0x000000; + else + temp = (int)(temp_r * 256) << 16; + + if (temp_g >= 1) + temp |= 0x00ff00; + else if (temp_g <= 0) + temp &= 0xff00ff; + else + temp = temp + ((int)(temp_g * 256) << 8); + + if (temp_b >= 1) + temp |= 0x0000ff; + else if (temp_b <= 0) + temp &= 0xffff00; + else + temp = temp + (int)(temp_b * 256); + + color = temp; + } if (invert_display) { - temp |= (0xff - (color & 0xff)); + temp = (0xff - (color & 0xff)); temp |= (0xff00 - (color & 0xff00)); temp |= (0xff0000 - (color & 0xff0000)); } - else - { - temp = color; - } return temp; } diff --git a/src/WIN/86Box.rc b/src/WIN/86Box.rc index ce74b432f..693244026 100644 --- a/src/WIN/86Box.rc +++ b/src/WIN/86Box.rc @@ -46,7 +46,7 @@ BEGIN BEGIN MENUITEM "&Hard Reset", IDM_ACTION_HRESET MENUITEM "&Ctrl+Alt+Del\tCtrl+F12", IDM_ACTION_RESET_CAD - MENUITEM "&Ctrl+Alt+Esc", IDM_ACTION_CTRL_ALT_ESC + MENUITEM "Ctrl+Alt+&Esc", IDM_ACTION_CTRL_ALT_ESC MENUITEM SEPARATOR MENUITEM "E&xit", IDM_ACTION_EXIT END @@ -81,6 +81,14 @@ BEGIN BEGIN MENUITEM "&Inverted VGA monitor", IDM_VID_INVERT MENUITEM "E&GA/(S)VGA overscan", IDM_VID_OVERSCAN + POPUP "VGA Screen &type" + BEGIN + MENUITEM "RGB &Color", IDM_VID_GRAY_RGB + MENUITEM "&RGB Grayscale", IDM_VID_GRAY_MONO + MENUITEM "&Amber monitor", IDM_VID_GRAY_AMBER + MENUITEM "&Green monitor", IDM_VID_GRAY_GREEN + MENUITEM "&White monitor", IDM_VID_GRAY_WHITE + END END MENUITEM SEPARATOR MENUITEM "F&orce 4:3 display ratio", IDM_VID_FORCE43 diff --git a/src/WIN/resource.h b/src/WIN/resource.h index e5c181fa5..fb918a06f 100644 --- a/src/WIN/resource.h +++ b/src/WIN/resource.h @@ -410,6 +410,11 @@ #define IDM_VID_OVERSCAN 40076 #define IDM_VID_INVERT 40079 #define IDM_VID_CGACON 40080 +#define IDM_VID_GRAY_RGB 40090 +#define IDM_VID_GRAY_MONO 40091 +#define IDM_VID_GRAY_AMBER 40092 +#define IDM_VID_GRAY_GREEN 40093 +#define IDM_VID_GRAY_WHITE 40094 #define IDM_LOG_BREAKPOINT 51201 #define IDM_DUMP_VRAM 51202 // should be an Action diff --git a/src/WIN/win.c b/src/WIN/win.c index 4c19e70e1..9ec9977df 100644 --- a/src/WIN/win.c +++ b/src/WIN/win.c @@ -1532,6 +1532,7 @@ int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpsz CheckMenuItem(menu, IDM_VID_SCALE_1X + scale, MF_CHECKED); CheckMenuItem(menu, IDM_VID_CGACON, vid_cga_contrast ? MF_CHECKED : MF_UNCHECKED); + CheckMenuItem(menu, IDM_VID_GRAY_RGB + video_grayscale, MF_CHECKED); d=romset; for (c=0;c Date: Mon, 17 Jul 2017 16:26:53 +0200 Subject: [PATCH 3/7] Fixed the paths to the MDA and WY700 character ROM's. --- src/CPU/x86seg.c | 8 +++----- src/mem.c | 4 ++-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/CPU/x86seg.c b/src/CPU/x86seg.c index 62ef17da4..d14ac1445 100644 --- a/src/CPU/x86seg.c +++ b/src/CPU/x86seg.c @@ -426,7 +426,6 @@ void loadseg(uint16_t seg, x86seg *s) if (s->base == 0 && s->limit_low == 0 && s->limit_high == 0xffffffff) cpu_cur_status |= CPU_STATUS_FLATDS; else - cpu_cur_status &= ~CPU_STATUS_FLATDS; } if (s == &_ss) @@ -625,6 +624,7 @@ void loadcsjmp(uint16_t seg, uint32_t oxpc) { if (!(segdat[2]&0x8000)) { + x86np("Load CS JMP system selector not present\n", seg & 0xfffc); return; } type=segdat[2]&0xF00; @@ -637,14 +637,12 @@ void loadcsjmp(uint16_t seg, uint32_t oxpc) cgate32=(type&0x800); cgate16=!cgate32; oldcs=CS; - cpu_state.oldpc=cpu_state.pc; -#if 0 + cpu_state.oldpc = cpu_state.pc; if ((DPL < CPL) || (DPL < (seg&3))) { x86gpf(NULL,seg&~3); return; } -#endif if (DPL < CPL) { x86gpf("loadcsjmp(): ex DPL < CPL",seg&~3); @@ -939,7 +937,7 @@ void loadcscall(uint16_t seg) cgate16=!cgate32; oldcs=CS; count=segdat[2]&31; - if ((DPL < CPL)) + if (DPL < CPL) { x86gpf("loadcscall(): ex DPL < CPL",seg&~3); return; diff --git a/src/mem.c b/src/mem.c index 59042049b..fb6b701d6 100644 --- a/src/mem.c +++ b/src/mem.c @@ -97,8 +97,8 @@ int loadbios() FILE *f=NULL,*ff=NULL; int c; - loadfont(L"roms/graphics/mda/mda.rom", 0); - loadfont(L"roms/graphics/wyse700/wy700.rom", 3); + loadfont(L"roms/video/mda/mda.rom", 0); + loadfont(L"roms/video/wyse700/wy700.rom", 3); biosmask = 0xffff; From 95ac6ebe1d7d9810f246423dc24b563582c1d19d Mon Sep 17 00:00:00 2001 From: OBattler Date: Tue, 18 Jul 2017 14:55:09 +0200 Subject: [PATCH 4/7] Temporarily reverted to the PCem serial code (but kept waltje's in, optionally enabled by running make with WALTJE=y parameter); Applied another A20 patch from Greatpsycho. --- src/Makefile.mingw | 16 ++- src/mem.c | 8 +- src/model.c | 1 - src/mouse_serial.c | 193 ++++++++++++++++++++++++++ src/pc.c | 3 + src/serial.h | 44 +++++- src/serial_old.c | 327 +++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 585 insertions(+), 7 deletions(-) create mode 100644 src/serial_old.c diff --git a/src/Makefile.mingw b/src/Makefile.mingw index 3870b99c8..7019473a8 100644 --- a/src/Makefile.mingw +++ b/src/Makefile.mingw @@ -131,6 +131,14 @@ PLATCG = codegen_x86.o endif +ifeq ($(WALTJE), y) +SERIAL = serial.o +WFLAGS = -DWALTJE +else +SERIAL = serial_old.o +endif + + MAINOBJ = pc.o config.o device.o timer.o dma.o io.o nmi.o pic.o \ mca.o mcr.o pit.o ppi.o pci.o sio.o intel.o rom.o mem.o \ memregs.o intel_flash.o rtc.o nvr.o ps2_nvr.o @@ -153,7 +161,7 @@ SYSOBJ = model.o \ compaq.o laserxt.o jim.o \ olivetti_m24.o ps1.o ps2.o ps2_mca.o \ tandy_eeprom.o tandy_rom.o -DEVOBJ = bugger.o lpt.o serial.o \ +DEVOBJ = bugger.o lpt.o $(SERIAL) \ fdc37c665.o fdc37c669.o fdc37c932fr.o \ pc87306.o sis85c471.o w83877f.o \ keyboard.o \ @@ -252,15 +260,15 @@ LIBS = -mwindows \ # Build rules. %.o: %.c @echo $< - @$(CC) $(CFLAGS) -c $< + @$(CC) $(CFLAGS) $(WFLAGS) -c $< %.o: %.cc @echo $< - @$(CPP) $(CFLAGS) -c $< + @$(CPP) $(CFLAGS) $(WFLAGS) -c $< %.o: %.cpp @echo $< - @$(CPP) $(CFLAGS) -c $< + @$(CPP) $(CFLAGS) $(WFLAGS) -c $< all: $(PROG).exe pcap_if.exe diff --git a/src/mem.c b/src/mem.c index fb6b701d6..cedac258f 100644 --- a/src/mem.c +++ b/src/mem.c @@ -2179,7 +2179,12 @@ void mem_init() if (mem_size > 768) mem_mapping_add(&ram_mid_mapping, 0xc0000, 0x40000, mem_read_ram, mem_read_ramw, mem_read_raml, mem_write_ram, mem_write_ramw, mem_write_raml, ram + 0xc0000, MEM_MAPPING_INTERNAL, NULL); - mem_mapping_add(&romext_mapping, 0xc8000, 0x08000, mem_read_romext, mem_read_romextw, mem_read_romextl, NULL, NULL, NULL, romext, 0, NULL); + if (romset == ROM_IBMPS1_2011) + mem_mapping_add(&romext_mapping, 0xc8000, 0x08000, mem_read_romext, mem_read_romextw, mem_read_romextl, NULL, NULL, NULL, romext, 0, NULL); + + mem_a20_key = 2; + mem_a20_alt = 0; + mem_a20_recalc(); } static void mem_remap_top(int max_size) @@ -2274,6 +2279,7 @@ void mem_resize() mem_mapping_add(&romext_mapping, 0xc8000, 0x08000, mem_read_romext, mem_read_romextw, mem_read_romextl, NULL, NULL, NULL, romext, 0, NULL); mem_a20_key = 2; + mem_a20_alt = 0; mem_a20_recalc(); } diff --git a/src/model.c b/src/model.c index c0f31f1f7..311bb1af5 100644 --- a/src/model.c +++ b/src/model.c @@ -415,7 +415,6 @@ void xt_laserxt_init(void) void at_init(void) { AT = 1; - mem_a20_key = mem_a20_alt = 0; common_init(); if (lpt_enabled) { diff --git a/src/mouse_serial.c b/src/mouse_serial.c index 04f23a8d9..208f95378 100644 --- a/src/mouse_serial.c +++ b/src/mouse_serial.c @@ -22,6 +22,7 @@ #include "mouse_serial.h" +#ifdef WALTJE #define SERMOUSE_TYPE_MSYSTEMS 1 /* Mouse Systems */ #define SERMOUSE_TYPE_MICROSOFT 2 /* Microsoft */ #define SERMOUSE_TYPE_LOGITECH 3 /* Logitech */ @@ -228,3 +229,195 @@ mouse_t mouse_serial_logitech = { sermouse_close, sermouse_poll }; + + +#else + + +typedef struct mouse_serial_t +{ + int mousepos, mousedelay; + int oldb; + int type; + SERIAL *serial; +} mouse_serial_t; + +uint8_t mouse_serial_poll(int x, int y, int z, int b, void *p) +{ + mouse_serial_t *mouse = (mouse_serial_t *)p; + SERIAL *serial = mouse->serial; + uint8_t mousedat[4]; + + if (!(serial->ier & 1)) + return 0xff; + if (!x && !y && b == mouse->oldb) + return 0xff; + + mouse->oldb = b; + if (x>127) x=127; + if (y>127) y=127; + if (x<-128) x=-128; + if (y<-128) y=-128; + + /*Use Microsoft format*/ + mousedat[0]=0x40; + mousedat[0]|=(((y>>6)&3)<<2); + mousedat[0]|=((x>>6)&3); + if (b&1) mousedat[0]|=0x20; + if (b&2) mousedat[0]|=0x10; + mousedat[1]=x&0x3F; + mousedat[2]=y&0x3F; + + if (!(serial->mctrl & 0x10)) + { + serial_write_fifo(mouse->serial, mousedat[0]); + serial_write_fifo(mouse->serial, mousedat[1]); + serial_write_fifo(mouse->serial, mousedat[2]); + if ((b&0x04) && mouse->type) + { + serial_write_fifo(mouse->serial, 0x20); + } + } + + return 0; +} + +uint8_t mouse_serial_msystems_poll(int x, int y, int z, int b, void *p) +{ + mouse_serial_t *mouse = (mouse_serial_t *)p; + SERIAL *serial = mouse->serial; + uint8_t mousedat[4]; + + if (!(serial->ier & 1)) + return 0xff; + if (!x && !y && b == mouse->oldb) + return 0xff; + + y = -y; + + mouse->oldb = b; + if (x>127) x=127; + if (y>127) y=127; + if (x<-128) x=-128; + if (y<-128) y=-128; + + /*Use Mouse Systems format*/ + mousedat[0] = 0x80; + mousedat[0] |= (b&0x01) ? 0x00 : 0x04; /* left button */ + mousedat[0] |= (b&0x02) ? 0x00 : 0x01; /* middle button */ + mousedat[0] |= (b&0x04) ? 0x00 : 0x02; /* right button */ + mousedat[1] = x; + mousedat[2] = y; + mousedat[3] = x; /* same as byte 1 */ + mousedat[4] = y; /* same as byte 2 */ + + if (!(serial->mctrl & 0x10)) + { + serial_write_fifo(mouse->serial, mousedat[0]); + serial_write_fifo(mouse->serial, mousedat[1]); + serial_write_fifo(mouse->serial, mousedat[2]); + serial_write_fifo(mouse->serial, mousedat[3]); + serial_write_fifo(mouse->serial, mousedat[4]); + } + + return 0; +} + +void mouse_serial_rcr(struct SERIAL *serial, void *p) +{ + mouse_serial_t *mouse = (mouse_serial_t *)p; + + mouse->mousepos = -1; + mouse->mousedelay = 5000 * (1 << TIMER_SHIFT); +} + +void mousecallback(void *p) +{ + mouse_serial_t *mouse = (mouse_serial_t *)p; + + mouse->mousedelay = 0; + if (mouse->mousepos == -1) + { + mouse->mousepos = 0; + if (mouse->type < 2) + { + serial_write_fifo(mouse->serial, 'M'); + if (mouse->type == 1) + { + serial_write_fifo(mouse->serial, '3'); + } + } + } +} + +void *mouse_serial_common_init(int type) +{ + mouse_serial_t *mouse = (mouse_serial_t *)malloc(sizeof(mouse_serial_t)); + memset(mouse, 0, sizeof(mouse_serial_t)); + + mouse->serial = &serial1; + serial1.rcr_callback = mouse_serial_rcr; + serial1.rcr_callback_p = mouse; + timer_add(mousecallback, &mouse->mousedelay, &mouse->mousedelay, mouse); + + mouse->type = type; + + return mouse; +} + +void *mouse_serial_init() +{ + return mouse_serial_common_init(0); +} + +void *mouse_serial_logitech_init() +{ + return mouse_serial_common_init(1); +} + +void *mouse_serial_msystems_init() +{ + return mouse_serial_common_init(2); +} + +void mouse_serial_close(void *p) +{ + mouse_serial_t *mouse = (mouse_serial_t *)p; + + free(mouse); + + serial1.rcr_callback = NULL; +} + +mouse_t mouse_serial_microsoft = +{ + "Microsoft 2-button mouse (serial)", + "msserial", + MOUSE_TYPE_SERIAL, + mouse_serial_init, + mouse_serial_close, + mouse_serial_poll +}; + +mouse_t mouse_serial_logitech = +{ + "Logitech 3-button mouse (serial)", + "lserial", + MOUSE_TYPE_SERIAL | MOUSE_TYPE_3BUTTON, + mouse_serial_logitech_init, + mouse_serial_close, + mouse_serial_poll +}; + +mouse_t mouse_msystems = +{ + "Mouse Systems Mouse (serial)", + "mssystems", + MOUSE_TYPE_MSYSTEMS, + mouse_serial_msystems_init, + mouse_serial_close, + mouse_serial_msystems_poll +}; + + +#endif \ No newline at end of file diff --git a/src/pc.c b/src/pc.c index d62a1cfb2..dc4ba68ae 100644 --- a/src/pc.c +++ b/src/pc.c @@ -512,6 +512,9 @@ void resetpchard_init(void) fdc_init(); disc_reset(); +#ifndef WALTJE + serial_init(); +#endif model_init(); video_init(); speaker_init(); diff --git a/src/serial.h b/src/serial.h index fec2d2b5c..4decfec6f 100644 --- a/src/serial.h +++ b/src/serial.h @@ -17,6 +17,7 @@ # define EMU_SERIAL_H +#ifdef WALTJE /* Default settings for the standard ports. */ #define SERIAL1_ADDR 0x03f8 #define SERIAL1_IRQ 4 @@ -72,4 +73,45 @@ extern int serial_link(int, char *); extern void serial_write_fifo(SERIAL *, uint8_t, int); -#endif /*EMU_SERIAL_H*/ +#else + + +void serial_remove(int port); +void serial_setup(int port, uint16_t addr, int irq); +void serial_init(void); +void serial_reset(); + +struct SERIAL; + +typedef struct +{ + uint8_t lsr,thr,mctrl,rcr,iir,ier,lcr,msr; + uint8_t dlab1,dlab2; + uint8_t dat; + uint8_t int_status; + uint8_t scratch; + uint8_t fcr; + + int irq; + + void (*rcr_callback)(struct SERIAL *serial, void *p); + void *rcr_callback_p; + uint8_t fifo[256]; + int fifo_read, fifo_write; + + int recieve_delay; +} SERIAL; + +void serial_write_fifo(SERIAL *serial, uint8_t dat); + +extern SERIAL serial1, serial2; + +/* Default settings for the standard ports. */ +#define SERIAL1_ADDR 0x03f8 +#define SERIAL1_IRQ 4 +#define SERIAL2_ADDR 0x02f8 +#define SERIAL2_IRQ 3 +#endif + + +#endif /*EMU_SERIAL_H*/ \ No newline at end of file diff --git a/src/serial_old.c b/src/serial_old.c new file mode 100644 index 000000000..639c792cd --- /dev/null +++ b/src/serial_old.c @@ -0,0 +1,327 @@ +#include + +#include "ibm.h" +#include "io.h" +#include "mouse.h" +#include "pic.h" +#include "serial.h" +#include "timer.h" + +enum +{ + SERIAL_INT_LSR = 1, + SERIAL_INT_RECEIVE = 2, + SERIAL_INT_TRANSMIT = 4, + SERIAL_INT_MSR = 8 +}; + +SERIAL serial1, serial2; + + +void serial_reset() +{ + serial1.iir = serial1.ier = serial1.lcr = 0; + serial2.iir = serial2.ier = serial2.lcr = 0; + serial1.fifo_read = serial1.fifo_write = 0; + serial2.fifo_read = serial2.fifo_write = 0; +} + +void serial_update_ints(SERIAL *serial) +{ + int stat = 0; + + serial->iir = 1; + + if ((serial->ier & 4) && (serial->int_status & SERIAL_INT_LSR)) /*Line status interrupt*/ + { + stat = 1; + serial->iir = 6; + } + else if ((serial->ier & 1) && (serial->int_status & SERIAL_INT_RECEIVE)) /*Recieved data available*/ + { + stat = 1; + serial->iir = 4; + } + else if ((serial->ier & 2) && (serial->int_status & SERIAL_INT_TRANSMIT)) /*Transmit data empty*/ + { + stat = 1; + serial->iir = 2; + } + else if ((serial->ier & 8) && (serial->int_status & SERIAL_INT_MSR)) /*Modem status interrupt*/ + { + stat = 1; + serial->iir = 0; + } + + if (stat && ((serial->mctrl & 8) || PCJR)) + picintlevel(1 << serial->irq); + else + picintc(1 << serial->irq); +} + +void serial_write_fifo(SERIAL *serial, uint8_t dat) +{ + serial->fifo[serial->fifo_write] = dat; + serial->fifo_write = (serial->fifo_write + 1) & 0xFF; + if (!(serial->lsr & 1)) + { + serial->lsr |= 1; + serial->int_status |= SERIAL_INT_RECEIVE; + serial_update_ints(serial); + } +} + +uint8_t serial_read_fifo(SERIAL *serial) +{ + if (serial->fifo_read != serial->fifo_write) + { + serial->dat = serial->fifo[serial->fifo_read]; + serial->fifo_read = (serial->fifo_read + 1) & 0xFF; + } + return serial->dat; +} + +void serial_write(uint16_t addr, uint8_t val, void *p) +{ + SERIAL *serial = (SERIAL *)p; + switch (addr&7) + { + case 0: + if (serial->lcr & 0x80) + { + serial->dlab1 = val; + return; + } + serial->thr = val; + serial->lsr |= 0x20; + serial->int_status |= SERIAL_INT_TRANSMIT; + serial_update_ints(serial); + if (serial->mctrl & 0x10) + { + serial_write_fifo(serial, val); + } + break; + case 1: + if (serial->lcr & 0x80) + { + serial->dlab2 = val; + return; + } + serial->ier = val & 0xf; + serial_update_ints(serial); + break; + case 2: + serial->fcr = val; + break; + case 3: + serial->lcr = val; + break; + case 4: + if ((val & 2) && !(serial->mctrl & 2)) + { + if (serial->rcr_callback) + serial->rcr_callback((struct SERIAL *)serial, serial->rcr_callback_p); + } + serial->mctrl = val; + if (val & 0x10) + { + uint8_t new_msr; + + new_msr = (val & 0x0c) << 4; + new_msr |= (val & 0x02) ? 0x10: 0; + new_msr |= (val & 0x01) ? 0x20: 0; + + if ((serial->msr ^ new_msr) & 0x10) + new_msr |= 0x01; + if ((serial->msr ^ new_msr) & 0x20) + new_msr |= 0x02; + if ((serial->msr ^ new_msr) & 0x80) + new_msr |= 0x08; + if ((serial->msr & 0x40) && !(new_msr & 0x40)) + new_msr |= 0x04; + + serial->msr = new_msr; + } + break; + case 5: + serial->lsr = val; + if (serial->lsr & 0x01) + serial->int_status |= SERIAL_INT_RECEIVE; + if (serial->lsr & 0x1e) + serial->int_status |= SERIAL_INT_LSR; + if (serial->lsr & 0x20) + serial->int_status |= SERIAL_INT_TRANSMIT; + serial_update_ints(serial); + break; + case 6: + serial->msr = val; + if (serial->msr & 0x0f) + serial->int_status |= SERIAL_INT_MSR; + serial_update_ints(serial); + break; + case 7: + serial->scratch = val; + break; + } +} + +uint8_t serial_read(uint16_t addr, void *p) +{ + SERIAL *serial = (SERIAL *)p; + uint8_t temp = 0; + switch (addr&7) + { + case 0: + if (serial->lcr & 0x80) + { + temp = serial->dlab1; + break; + } + + serial->lsr &= ~1; + serial->int_status &= ~SERIAL_INT_RECEIVE; + serial_update_ints(serial); + temp = serial_read_fifo(serial); + if (serial->fifo_read != serial->fifo_write) + serial->recieve_delay = 1000 * TIMER_USEC; + break; + case 1: + if (serial->lcr & 0x80) + temp = serial->dlab2; + else + temp = serial->ier; + break; + case 2: + temp = serial->iir; + if ((temp & 0xe) == 2) + { + serial->int_status &= ~SERIAL_INT_TRANSMIT; + serial_update_ints(serial); + } + if (serial->fcr & 1) + temp |= 0xc0; + break; + case 3: + temp = serial->lcr; + break; + case 4: + temp = serial->mctrl; + break; + case 5: + if (serial->lsr & 0x20) + serial->lsr |= 0x40; + serial->lsr |= 0x20; + temp = serial->lsr; + if (serial->lsr & 0x1f) + serial->lsr &= ~0x1e; + serial->int_status &= ~SERIAL_INT_LSR; + serial_update_ints(serial); + break; + case 6: + temp = serial->msr; + serial->msr &= ~0x0f; + serial->int_status &= ~SERIAL_INT_MSR; + serial_update_ints(serial); + break; + case 7: + temp = serial->scratch; + break; + } + return temp; +} + +void serial_recieve_callback(void *p) +{ + SERIAL *serial = (SERIAL *)p; + + serial->recieve_delay = 0; + + if (serial->fifo_read != serial->fifo_write) + { + serial->lsr |= 1; + serial->int_status |= SERIAL_INT_RECEIVE; + serial_update_ints(serial); + } +} + +uint16_t base_address[2] = { 0x3f8, 0x2f8 }; + +void serial_remove(int port) +{ + if ((port < 1) || (port > 2)) + { + fatal("serial_remove(): Invalid serial port: %i\n", port); + exit(-1); + } + + if (!serial_enabled[port - 1]) + { + return; + } + + pclog("Removing serial port %i at %04X...\n", port, base_address[port - 1]); + + io_removehandler(base_address[port - 1], 0x0008, serial_read, NULL, NULL, serial_write, NULL, NULL, (port == 1) ? &serial1 : &serial2); + base_address[port - 1] = 0x0000; +} + +void serial_setup(int port, uint16_t addr, int irq) +{ + SERIAL *p; + + if ((port < 1) || (port > 2)) + { + fatal("serial_setup(): Invalid serial port: %i\n", port); + exit(-1); + } + + if (!serial_enabled[port - 1]) + { + return; + } + + if (base_address[port - 1] != 0x0000) + { + serial_remove(port); + } + + if (addr == 0x0000) + { + pclog("Serial port %i at %04X, ignoring...\n", port, base_address[port - 1]); + return; + } + + if (port == 1) + { + p = &serial1; + } + else if (port == 2) + { + p = &serial2; + } + + pclog("Adding serial port %i at %04X...\n", port, addr); + + base_address[port - 1] = addr; + io_sethandler(base_address[port - 1], 0x0008, serial_read, NULL, NULL, serial_write, NULL, NULL, p); + + p->irq = irq; +} + +void serial_init(void) +{ + if (serial_enabled[0]) + { + pclog("Adding serial port 1...\n"); + serial_setup(1, 0x3f8, 4); + serial1.rcr_callback = NULL; + timer_add(serial_recieve_callback, &serial1.recieve_delay, &serial1.recieve_delay, &serial1); + } + if (serial_enabled[1]) + { + pclog("Adding serial port 2...\n"); + serial_setup(2, 0x2f8, 3); + serial2.rcr_callback = NULL; + timer_add(serial_recieve_callback, &serial2.recieve_delay, &serial2.recieve_delay, &serial2); + } +} From 89fd3e467f15644b72a8c5b0893ddee544f6b699 Mon Sep 17 00:00:00 2001 From: OBattler Date: Tue, 18 Jul 2017 19:22:16 +0200 Subject: [PATCH 5/7] Increased maximum number of timers to 64; Redid some things in serial_old.c; Made win_serial.c only compile and link if make is started with WALTJE=y; The NVR path text box in the Settings dialog now has ES_AUTOHSCROLL set. --- src/Makefile.mingw | 3 +- src/WIN/86Box.rc | 2 +- src/gameport.c | 2 +- src/pc.c | 2 + src/serial_old.c | 98 ++++++++++++++++++++++++++-------------------- src/timer.c | 2 +- 6 files changed, 63 insertions(+), 46 deletions(-) diff --git a/src/Makefile.mingw b/src/Makefile.mingw index 7019473a8..76c61c83b 100644 --- a/src/Makefile.mingw +++ b/src/Makefile.mingw @@ -133,6 +133,7 @@ endif ifeq ($(WALTJE), y) SERIAL = serial.o +WSERIAL = win_serial.o WFLAGS = -DWALTJE else SERIAL = serial_old.o @@ -241,7 +242,7 @@ WINOBJ = win.o \ win_ddraw.o win_ddraw_fs.o win_ddraw_screenshot.o \ win_d3d.o win_d3d_fs.o \ win_language.o win_status.o win_opendir.o win_dynld.o \ - win_video.o win_serial.o win_keyboard.o win_mouse.o \ + win_video.o $(WSERIAL) win_keyboard.o win_mouse.o \ win_iodev.o win_joystick.o win_midi.o \ win_settings.o win_deviceconfig.o win_joystickconfig.o \ 86Box.res diff --git a/src/WIN/86Box.rc b/src/WIN/86Box.rc index 693244026..7e79008c3 100644 --- a/src/WIN/86Box.rc +++ b/src/WIN/86Box.rc @@ -255,7 +255,7 @@ BEGIN 12,12 LTEXT "MB",IDT_1705,123,64,10,10 LTEXT "Memory:",IDT_1706,7,64,30,10 - LTEXT "NVR Path:",IDT_1700,7,83,60,10 + LTEXT "NVR Path:",IDT_1700,7,83,60,10,ES_AUTOHSCROLL EDITTEXT IDC_EDIT_NVR_PATH,71,82,138,12 PUSHBUTTON "&Specify...",IDC_BUTTON_NVR_PATH,214,82,46,12 CONTROL "Dynamic Recompiler",IDC_CHECK_DYNAREC,"Button", diff --git a/src/gameport.c b/src/gameport.c index a80d962b7..7cb0e0142 100644 --- a/src/gameport.c +++ b/src/gameport.c @@ -204,7 +204,7 @@ void gameport_update_joystick_type() void *gameport_init() { - gameport_t *gameport; + gameport_t *gameport = NULL; if (joystick_type == 7) { diff --git a/src/pc.c b/src/pc.c index dc4ba68ae..0df42a936 100644 --- a/src/pc.c +++ b/src/pc.c @@ -366,7 +366,9 @@ void initmodules(void) /* Initialize modules. */ network_init(); mouse_init(); +#ifdef WALTJE serial_init(); +#endif disc_random_init(); joystick_init(); diff --git a/src/serial_old.c b/src/serial_old.c index 639c792cd..c6bc83e4c 100644 --- a/src/serial_old.c +++ b/src/serial_old.c @@ -244,7 +244,7 @@ void serial_recieve_callback(void *p) } } -uint16_t base_address[2] = { 0x3f8, 0x2f8 }; +uint16_t base_address[2] = { 0x0000, 0x0000 }; void serial_remove(int port) { @@ -259,68 +259,82 @@ void serial_remove(int port) return; } + if (!base_address[port - 1]) + { + return; + } + pclog("Removing serial port %i at %04X...\n", port, base_address[port - 1]); - io_removehandler(base_address[port - 1], 0x0008, serial_read, NULL, NULL, serial_write, NULL, NULL, (port == 1) ? &serial1 : &serial2); - base_address[port - 1] = 0x0000; + switch(port) + { + case 1: + io_removehandler(base_address[0], 0x0008, serial_read, NULL, NULL, serial_write, NULL, NULL, &serial1); + base_address[0] = 0x0000; + break; + case 2: + io_removehandler(base_address[1], 0x0008, serial_read, NULL, NULL, serial_write, NULL, NULL, &serial2); + base_address[1] = 0x0000; + break; + } } void serial_setup(int port, uint16_t addr, int irq) { - SERIAL *p; - - if ((port < 1) || (port > 2)) - { - fatal("serial_setup(): Invalid serial port: %i\n", port); - exit(-1); - } - - if (!serial_enabled[port - 1]) - { - return; - } - - if (base_address[port - 1] != 0x0000) - { - serial_remove(port); - } - - if (addr == 0x0000) - { - pclog("Serial port %i at %04X, ignoring...\n", port, base_address[port - 1]); - return; - } - - if (port == 1) - { - p = &serial1; - } - else if (port == 2) - { - p = &serial2; - } - pclog("Adding serial port %i at %04X...\n", port, addr); - base_address[port - 1] = addr; - io_sethandler(base_address[port - 1], 0x0008, serial_read, NULL, NULL, serial_write, NULL, NULL, p); - - p->irq = irq; + switch(port) + { + case 1: + if (base_address[0] != 0x0000) + { + serial_remove(port); + } + if (addr != 0x0000) + { + base_address[0] = addr; + io_sethandler(addr, 0x0008, serial_read, NULL, NULL, serial_write, NULL, NULL, &serial1); + } + serial1.irq = irq; + break; + case 2: + if (base_address[1] != 0x0000) + { + serial_remove(port); + } + if (addr != 0x0000) + { + base_address[1] = addr; + io_sethandler(addr, 0x0008, serial_read, NULL, NULL, serial_write, NULL, NULL, &serial2); + } + serial2.irq = irq; + break; + default: + fatal("serial_setup(): Invalid serial port: %i\n", port); + break; + } } void serial_init(void) { + base_address[0] = 0x03f8; + base_address[1] = 0x02f8; + if (serial_enabled[0]) { pclog("Adding serial port 1...\n"); - serial_setup(1, 0x3f8, 4); + memset(&serial1, 0, sizeof(serial1)); + io_sethandler(0x3f8, 0x0008, serial_read, NULL, NULL, serial_write, NULL, NULL, &serial1); + serial1.irq = 4; serial1.rcr_callback = NULL; timer_add(serial_recieve_callback, &serial1.recieve_delay, &serial1.recieve_delay, &serial1); } if (serial_enabled[1]) { pclog("Adding serial port 2...\n"); - serial_setup(2, 0x2f8, 3); + memset(&serial2, 0, sizeof(serial2)); + io_sethandler(0x2f8, 0x0008, serial_read, NULL, NULL, serial_write, NULL, NULL, &serial2); + serial2.irq = 3; serial2.rcr_callback = NULL; timer_add(serial_recieve_callback, &serial2.recieve_delay, &serial2.recieve_delay, &serial2); } diff --git a/src/timer.c b/src/timer.c index d3fd618a7..82eabe39c 100644 --- a/src/timer.c +++ b/src/timer.c @@ -8,7 +8,7 @@ #include "sound_wss.h"*/ #include "timer.h" -#define TIMERS_MAX 32 +#define TIMERS_MAX 64 int TIMER_USEC; From d47364fd3eca5d2635fb2852357df971d5fe38bd Mon Sep 17 00:00:00 2001 From: OBattler Date: Tue, 18 Jul 2017 20:32:27 +0200 Subject: [PATCH 6/7] ES_AUTOHSCROLL now applied to the correct control. --- src/WIN/86Box.rc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/WIN/86Box.rc b/src/WIN/86Box.rc index b79e73d78..06f48c95b 100644 --- a/src/WIN/86Box.rc +++ b/src/WIN/86Box.rc @@ -1,4 +1,4 @@ -/* +/* * 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 @@ -255,8 +255,8 @@ BEGIN 12,12 LTEXT "MB",IDT_1705,123,64,10,10 LTEXT "Memory:",IDT_1706,7,64,30,10 - LTEXT "NVR Path:",IDT_1700,7,83,60,10,ES_AUTOHSCROLL - EDITTEXT IDC_EDIT_NVR_PATH,71,82,138,12 + LTEXT "NVR Path:",IDT_1700,7,83,60,10 + EDITTEXT IDC_EDIT_NVR_PATH,71,82,138,12,ES_AUTOHSCROLL PUSHBUTTON "&Specify...",IDC_BUTTON_NVR_PATH,214,82,46,12 CONTROL "Dynamic Recompiler",IDC_CHECK_DYNAREC,"Button", BS_AUTOCHECKBOX | WS_TABSTOP,7,100,94,10 From 1168c6c63ce1dfa2bad35ffad16e4328120cd043 Mon Sep 17 00:00:00 2001 From: OBattler Date: Tue, 18 Jul 2017 21:44:42 +0200 Subject: [PATCH 7/7] Applied two EGA-related commits from mainline PCem. --- src/VIDEO/vid_ega.c | 2 ++ src/VIDEO/video.c | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/src/VIDEO/vid_ega.c b/src/VIDEO/vid_ega.c index 0a2e60944..70201c18a 100644 --- a/src/VIDEO/vid_ega.c +++ b/src/VIDEO/vid_ega.c @@ -591,6 +591,8 @@ void ega_poll(void *p) if (ega->sc == (ega->crtc[9] & 31)) { ega->sc = 0; + if (ega->sc == (ega->crtc[11] & 31)) + ega->con = 0; ega->maback += (ega->rowoffset << 3); ega->maback &= ega->vrammask; diff --git a/src/VIDEO/video.c b/src/VIDEO/video.c index 6e63ad81b..5a7d2dc78 100644 --- a/src/VIDEO/video.c +++ b/src/VIDEO/video.c @@ -643,6 +643,8 @@ void video_wait_for_buffer() void video_blit_memtoscreen(int x, int y, int y1, int y2, int w, int h) { + if (h <= 0) + return; video_wait_for_blit(); blit_data.busy = 1; blit_data.buffer_in_use = 1; @@ -658,6 +660,8 @@ void video_blit_memtoscreen(int x, int y, int y1, int y2, int w, int h) void video_blit_memtoscreen_8(int x, int y, int w, int h) { + if (h <= 0) + return; video_wait_for_blit(); blit_data.busy = 1; blit_data.x = x;