diff --git a/src/86box.h b/src/86box.h index 7df924036..30a5088e1 100644 --- a/src/86box.h +++ b/src/86box.h @@ -99,6 +99,7 @@ extern int vid_cga_contrast, /* (C) video */ gfxcard; /* (C) graphics/video card */ extern int serial_enabled[], /* (C) enable serial ports */ bugger_enabled, /* (C) enable ISAbugger */ + postcard_enabled, /* (C) enable POST card */ isamem_type[], /* (C) enable ISA mem cards */ isartc_type; /* (C) enable ISA RTC card */ extern int sound_is_float, /* (C) sound uses FP values */ diff --git a/src/config.c b/src/config.c index 707bf0534..6daa573aa 100644 --- a/src/config.c +++ b/src/config.c @@ -806,6 +806,7 @@ load_other_peripherals(void) ide_qua_enabled = !!config_get_int(cat, "ide_qua", 0); bugger_enabled = !!config_get_int(cat, "bugger_enabled", 0); + postcard_enabled = !!config_get_int(cat, "postcard_enabled", 0); for (c = 0; c < ISAMEM_MAX; c++) { sprintf(temp, "isamem%d_type", c); @@ -1686,6 +1687,11 @@ save_other_peripherals(void) else config_set_int(cat, "bugger_enabled", bugger_enabled); + if (postcard_enabled == 0) + config_delete_var(cat, "postcard_enabled"); + else + config_set_int(cat, "postcard_enabled", postcard_enabled); + for (c = 0; c < ISAMEM_MAX; c++) { sprintf(temp, "isamem%d_type", c); if (isamem_type[c] == 0) diff --git a/src/pc.c b/src/pc.c index 5fbf1b3a2..3c67989c0 100644 --- a/src/pc.c +++ b/src/pc.c @@ -49,6 +49,7 @@ #include "nvr.h" #include "machine.h" #include "bugger.h" +#include "postcard.h" #include "isamem.h" #include "isartc.h" #include "lpt.h" @@ -112,6 +113,7 @@ int vid_cga_contrast = 0, /* (C) video */ force_43 = 0; /* (C) video */ int serial_enabled[SERIAL_MAX] = {0,0}, /* (C) enable serial ports */ bugger_enabled = 0, /* (C) enable ISAbugger */ + postcard_enabled = 0, /* (C) enable POST card */ isamem_type[ISAMEM_MAX] = { 0,0,0,0 }, /* (C) enable ISA mem cards */ isartc_type = 0; /* (C) enable ISA RTC card */ int gfxcard = 0; /* (C) graphics/video card */ @@ -779,7 +781,9 @@ pc_reset_hard_init(void) /* Needs the status bar... */ if (bugger_enabled) - device_add(&bugger_device); + device_add(&bugger_device); + if (postcard_enabled) + device_add(&postcard_device); /* Reset the CPU module. */ resetx86(); diff --git a/src/postcard.c b/src/postcard.c new file mode 100644 index 000000000..9662d3ae6 --- /dev/null +++ b/src/postcard.c @@ -0,0 +1,142 @@ +/* + * 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. + * + * Implementation of a port 80h POST diagnostic card. + * + * Version: @(#)postcard.c 1.0.0 2020/03/23 + * + * Author: RichardG, + * Copyright 2020 RichardG. + */ +#include +#include +#include +#include +#include +#define HAVE_STDARG_H +#include "86box.h" +#include "86box_io.h" +#include "device.h" +#include "machine.h" +#include "plat.h" +#include "ui.h" +#include "postcard.h" + + +static uint16_t postcard_port; +static uint8_t postcard_written; +static uint8_t postcard_code, postcard_prev_code; +#define UISTR_LEN 13 +static char postcard_str[UISTR_LEN]; /* UI output string */ + + +extern void ui_sb_bugui(char *__str); + + +#ifdef ENABLE_POSTCARD_LOG +int postcard_do_log = ENABLE_POSTCARD_LOG; + + +static void +postcard_log(const char *fmt, ...) +{ + va_list ap; + + if (postcard_do_log) { + va_start(ap, fmt); + pclog_ex(fmt, ap); + va_end(ap); + } +} +#else +int postcard_do_log = 0; + +#define postcard_log(fmt, ...) +#endif + + +static void +postcard_setui(void) +{ + if (!postcard_written) + sprintf(postcard_str, "POST: -- --"); + else if (postcard_written == 1) + sprintf(postcard_str, "POST: %02X --", postcard_code); + else + sprintf(postcard_str, "POST: %02X %02X", postcard_code, postcard_prev_code); + + ui_sb_bugui(postcard_str); + + if (postcard_do_log) { + /* log same string sent to the UI */ + int len = strlen(postcard_str); + postcard_str[len + 1] = '\0'; + postcard_str[len] = '\n'; + postcard_log(postcard_str); + } +} + + +static void +postcard_reset(void) +{ + postcard_written = 0; + postcard_code = postcard_prev_code = 0x00; + + postcard_setui(); +} + + +static void +postcard_write(uint16_t port, uint8_t val, void *priv) +{ + postcard_prev_code = postcard_code; + postcard_code = val; + if (postcard_written < 2) + postcard_written++; + + postcard_setui(); +} + + +static void * +postcard_init(const device_t *info) +{ + postcard_reset(); + + if (machines[machine].flags & MACHINE_MCA) + postcard_port = 0x680; /* MCA machines */ + else if (strstr(machines[machine].name, " PS/2 ")) + postcard_port = 0x90; /* ISA PS/2 machines */ + else + postcard_port = 0x80; /* AT and clone machines */ + postcard_log("POST card initializing on port %04Xh\n", postcard_port); + + if (postcard_port) io_sethandler(postcard_port, 1, + NULL, NULL, NULL, postcard_write, NULL, NULL, NULL); + + return postcard_write; +} + + +static void +postcard_close(UNUSED(void *priv)) +{ + if (postcard_port) io_removehandler(postcard_port, 1, + NULL, NULL, NULL, postcard_write, NULL, NULL, NULL); +} + + +const device_t postcard_device = { + "POST Card", + DEVICE_ISA, + 0, + postcard_init, postcard_close, NULL, + NULL, NULL, NULL, + NULL +}; diff --git a/src/postcard.h b/src/postcard.h new file mode 100644 index 000000000..4bfc912f5 --- /dev/null +++ b/src/postcard.h @@ -0,0 +1,35 @@ +/* + * 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. + * + * Implementation of a port 80h POST diagnostic card. + * + * Version: @(#)postcard.c 1.0.0 2020/03/23 + * + * Author: RichardG, + * Copyright 2020 RichardG. + */ +#ifndef POSTCARD_H +# define POSTCARD_H + + +#ifdef __cplusplus +extern "C" { +#endif + +/* Global variables. */ +extern const device_t postcard_device; + + +/* Functions. */ + +#ifdef __cplusplus +} +#endif + + +#endif /*BUGGER_H*/ diff --git a/src/win/86Box.rc b/src/win/86Box.rc index 851b7d287..fe204a04b 100644 --- a/src/win/86Box.rc +++ b/src/win/86Box.rc @@ -474,6 +474,9 @@ BEGIN CONTROL "ISABugger device",IDC_CHECK_BUGGER,"Button", BS_AUTOCHECKBOX | WS_TABSTOP,7,80,94,10 + CONTROL "POST card",IDC_CHECK_POSTCARD,"Button", + BS_AUTOCHECKBOX | WS_TABSTOP,147,80,94,10 + LTEXT "ISA RTC",IDT_1767,7,99,48,10 COMBOBOX IDC_COMBO_ISARTC,64,98,155,120, CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP diff --git a/src/win/Makefile.mingw b/src/win/Makefile.mingw index 6e4587712..bac5a2839 100644 --- a/src/win/Makefile.mingw +++ b/src/win/Makefile.mingw @@ -597,7 +597,7 @@ MCHOBJ := machine.o machine_table.o \ m_at_286_386sx.o m_at_386dx_486.o \ m_at_socket4_5.o m_at_socket7_s7.o -DEVOBJ := bugger.o hwm.o hwm_w83781d.o ibm_5161.o isamem.o isartc.o lpt.o $(SERIAL) \ +DEVOBJ := bugger.o hwm.o hwm_w83781d.o ibm_5161.o isamem.o isartc.o lpt.o postcard.o $(SERIAL) \ sio_acc3221.o \ sio_fdc37c66x.o sio_fdc37c669.o \ sio_fdc37c93x.o \ diff --git a/src/win/Makefile_ndr.mingw b/src/win/Makefile_ndr.mingw index ca7bed3ee..8e8b82a5d 100644 --- a/src/win/Makefile_ndr.mingw +++ b/src/win/Makefile_ndr.mingw @@ -602,7 +602,7 @@ MCHOBJ := machine.o machine_table.o \ m_at_286_386sx.o m_at_386dx_486.o \ m_at_socket4_5.o m_at_socket7_s7.o -DEVOBJ := bugger.o hwm.o hwm_w83781d.o ibm_5161.o isamem.o isartc.o lpt.o $(SERIAL) \ +DEVOBJ := bugger.o hwm.o hwm_w83781d.o ibm_5161.o isamem.o isartc.o lpt.o postcard.o $(SERIAL) \ sio_acc3221.o \ sio_fdc37c66x.o sio_fdc37c669.o \ sio_fdc37c93x.o \ diff --git a/src/win/resource.h b/src/win/resource.h index 8e11ed62a..c4ffc2728 100644 --- a/src/win/resource.h +++ b/src/win/resource.h @@ -175,7 +175,7 @@ #define IDC_CHECK_IDE_QUA 1127 #define IDC_BUTTON_IDE_QUA 1128 #define IDC_CHECK_BUGGER 1129 -#define IDC_CONFIGURE_BUGGER 1130 +#define IDC_CHECK_POSTCARD 1130 #define IDC_COMBO_ISARTC 1131 #define IDC_CONFIGURE_ISARTC 1132 #define IDC_GROUP_ISAMEM 1140 diff --git a/src/win/win_settings.c b/src/win/win_settings.c index 0d79a7124..6d5476295 100644 --- a/src/win/win_settings.c +++ b/src/win/win_settings.c @@ -97,6 +97,7 @@ static int temp_serial[2], temp_lpt[3]; /* Other peripherals category */ static int temp_hdc, temp_scsi_card, temp_ide_ter, temp_ide_qua; static int temp_bugger; +static int temp_postcard; static int temp_isartc; static int temp_isamem[ISAMEM_MAX]; @@ -248,6 +249,7 @@ win_settings_init(void) temp_ide_ter = ide_ter_enabled; temp_ide_qua = ide_qua_enabled; temp_bugger = bugger_enabled; + temp_postcard = postcard_enabled; temp_isartc = isartc_type; /* ISA memory boards. */ @@ -356,6 +358,7 @@ win_settings_changed(void) i = i || (temp_ide_ter != ide_ter_enabled); i = i || (temp_ide_qua != ide_qua_enabled); i = i || (temp_bugger != bugger_enabled); + i = i || (temp_postcard != postcard_enabled); i = i || (temp_isartc != isartc_type); /* ISA memory boards. */ @@ -460,6 +463,7 @@ win_settings_save(void) ide_ter_enabled = temp_ide_ter; ide_qua_enabled = temp_ide_qua; bugger_enabled = temp_bugger; + postcard_enabled = temp_postcard; isartc_type = temp_isartc; /* ISA memory boards. */ @@ -1594,6 +1598,9 @@ win_settings_peripherals_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lPa h=GetDlgItem(hdlg, IDC_CHECK_BUGGER); SendMessage(h, BM_SETCHECK, temp_bugger, 0); + h=GetDlgItem(hdlg, IDC_CHECK_POSTCARD); + SendMessage(h, BM_SETCHECK, temp_postcard, 0); + /* Populate the ISA RTC card dropdown. */ e = 0; h = GetDlgItem(hdlg, IDC_COMBO_ISARTC); @@ -1797,6 +1804,9 @@ win_settings_peripherals_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lPa h = GetDlgItem(hdlg, IDC_CHECK_BUGGER); temp_bugger = SendMessage(h, BM_GETCHECK, 0, 0); + h = GetDlgItem(hdlg, IDC_CHECK_POSTCARD); + temp_postcard = SendMessage(h, BM_GETCHECK, 0, 0); + free(stransi); free(lptsTemp);