From 4562408a5f57fe6c580181a534cb95e7ecf63632 Mon Sep 17 00:00:00 2001 From: Bob Supnik Date: Mon, 12 Dec 2022 12:00:00 -0500 Subject: [PATCH] Common code: various bugfixes; Mac "Classic" and OS/2 support has been removed --- descrip.mms | 2 +- makefile | 58 +++++++--- scp.c | 12 +- sim_console.c | 302 ++++---------------------------------------------- sim_console.h | 4 +- sim_defs.h | 17 ++- sim_tape.c | 31 +++++- sim_timer.c | 93 +--------------- 8 files changed, 124 insertions(+), 395 deletions(-) diff --git a/descrip.mms b/descrip.mms index 482ef691..3534466e 100644 --- a/descrip.mms +++ b/descrip.mms @@ -490,7 +490,7 @@ ID16_SOURCE = $(ID16_DIR)ID16_CPU.C,$(ID16_DIR)ID16_SYS.C,$(ID16_DIR)ID_DP.C,\ $(ID16_DIR)ID_IO.C,$(ID16_DIR)ID_LP.C,$(ID16_DIR)ID_MT.C,\ $(ID16_DIR)ID_PAS.C,$(ID16_DIR)ID_PT.C,$(ID16_DIR)ID_TT.C,\ $(ID16_DIR)ID_UVC.C,$(ID16_DIR)ID16_DBOOT.C,$(ID16_DIR)ID_TTP.C -ID16_OPTIONS = /INCL=($(SIMH_DIR),$(ID16_DIR))/DEF=($(CC_DEFS)) +ID16_OPTIONS = /INCL=($(SIMH_DIR),$(ID16_DIR))/DEF=($(CC_DEFS),"IFP_IN_MEM=1") # # Interdata 32-bit CPU. diff --git a/makefile b/makefile index f26bc118..c63a60b2 100644 --- a/makefile +++ b/makefile @@ -111,12 +111,32 @@ ifneq (,${GREP_OPTIONS}) $(info unset the GREP_OPTIONS environment variable to use this makefile) $(error 1) endif -ifeq (old,$(shell gmake --version /dev/null 2>&1 | grep 'GNU Make' | awk '{ if ($$3 < "3.81") {print "old"} }')) - GMAKE_VERSION = $(shell gmake --version /dev/null 2>&1 | grep 'GNU Make' | awk '{ print $$3 }') +ifneq ($(findstring Windows,${OS}),) + ifeq ($(findstring .exe,${SHELL}),.exe) + # MinGW + WIN32 := 1 + # Tests don't run under MinGW + TESTS := 0 + else # Msys or cygwin + ifeq (MINGW,$(findstring MINGW,$(shell uname))) + $(info *** This makefile can not be used with the Msys bash shell) + $(error Use build_mingw.bat ${MAKECMDGOALS} from a Windows command prompt) + endif + endif +endif +ifeq ($(WIN32),) + SIM_MAJOR=$(shell grep SIM_MAJOR sim_rev.h | awk '{ print $$3 }') + GMAKE_VERSION = $(shell $(MAKE) --version /dev/null 2>&1 | grep 'GNU Make' | awk '{ print $$3 }') + OLD = $(shell echo $(GMAKE_VERSION) | awk '{ if ($$1 < "3.81") {print "old"} }') +else + SIM_MAJOR=$(shell for /F "tokens=3" %%i in ('findstr /c:"SIM_MAJOR" sim_rev.h') do echo %%i) + GMAKE_VERSION = $(shell for /F "tokens=3" %%i in ('$(MAKE) --version ^| findstr /c:"GNU Make"') do echo %%i) + OLD = $(shell cmd /e:on /c "if $(GMAKE_VERSION) LSS 3.81 echo old") +endif +ifeq ($(OLD),old) $(warning *** Warning *** GNU Make Version $(GMAKE_VERSION) is too old to) $(warning *** Warning *** fully process this makefile) endif -SIM_MAJOR=$(shell grep SIM_MAJOR sim_rev.h | awk '{ print $$3 }') BUILD_SINGLE := ${MAKECMDGOALS} $(BLANK_SUFFIX) BUILD_MULTIPLE_VERB = is # building the pdp1, pdp11, tx-0, or any microvax simulator could use video support @@ -195,6 +215,10 @@ ifneq ($(findstring Windows,${OS}),) endif endif endif +ifeq (3,${SIM_MAJOR}) + # simh v3 DOES not have any video support + VIDEO_USEFUL = +endif find_exe = $(abspath $(strip $(firstword $(foreach dir,$(strip $(subst :, ,${PATH})),$(wildcard $(dir)/$(1)))))) find_lib = $(firstword $(abspath $(strip $(firstword $(foreach dir,$(strip ${LIBPATH}),$(foreach ext,$(strip ${LIBEXT}),$(wildcard $(dir)/lib$(1).$(ext)))))))) @@ -1206,18 +1230,20 @@ else $(info Cloning the windows-build dependencies into $(abspath ..)/windows-build) $(shell git clone https://github.com/simh/windows-build ../windows-build) else - $(info ***********************************************************************) - $(info ***********************************************************************) - $(info ** This build is operating without the required windows-build **) - $(info ** components and therefore will produce less than optimal **) - $(info ** simulator operation and features. **) - $(info ** Download the file: **) - $(info ** https://github.com/simh/windows-build/archive/windows-build.zip **) - $(info ** Extract the windows-build-windows-build folder it contains to **) - $(info ** $(abspath ..\) **) - $(info ***********************************************************************) - $(info ***********************************************************************) - $(info .) + ifneq (3,${SIM_MAJOR}) + $(info ***********************************************************************) + $(info ***********************************************************************) + $(info ** This build is operating without the required windows-build **) + $(info ** components and therefore will produce less than optimal **) + $(info ** simulator operation and features. **) + $(info ** Download the file: **) + $(info ** https://github.com/simh/windows-build/archive/windows-build.zip **) + $(info ** Extract the windows-build-windows-build folder it contains to **) + $(info ** $(abspath ..\) **) + $(info ***********************************************************************) + $(info ***********************************************************************) + $(info .) + endif endif else # Version check on windows-build @@ -1819,7 +1845,7 @@ ID16 = ${ID16D}/id16_cpu.c ${ID16D}/id16_sys.c ${ID16D}/id_dp.c \ ${ID16D}/id_fd.c ${ID16D}/id_fp.c ${ID16D}/id_idc.c ${ID16D}/id_io.c \ ${ID16D}/id_lp.c ${ID16D}/id_mt.c ${ID16D}/id_pas.c ${ID16D}/id_pt.c \ ${ID16D}/id_tt.c ${ID16D}/id_uvc.c ${ID16D}/id16_dboot.c ${ID16D}/id_ttp.c -ID16_OPT = -I ${ID16D} +ID16_OPT = -DIFP_IN_MEM -I ${ID16D} ID32D = ${SIMHD}/Interdata diff --git a/scp.c b/scp.c index e2673efa..290c2619 100644 --- a/scp.c +++ b/scp.c @@ -23,6 +23,9 @@ used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from Robert M Supnik. + 01-Oct-22 RMS Replaced readline with editline due to licensing issues (Paul Koning) + 15-Aug-22 RMS Fixed inconsistent SIM_HAVE_DLOPEN naming (Walter Mueller) + 06-Mar-22 RMS Removed UNIT_RAW support 21-Oct-21 RMS Fixed bug in byte deposits if aincr > 1 16-Feb-21 JDB Rewrote get_rval, put_rval to support arrays of structures 25-Jan-21 JDB REG "size" field now determines access size @@ -2734,10 +2737,6 @@ t_bool register_check = FALSE; t_stat stat = SCPE_OK; CTAB *docmdp = NULL; -#if defined (__MWERKS__) && defined (macintosh) -argc = ccommand (&argv); -#endif - /* Make sure that argv has at least 10 elements and that it ends in a NULL pointer */ targv = (char **)calloc (1+MAX(10, argc), sizeof(*targv)); for (i=0; i - -static t_stat sim_os_ttinit (void) -{ -return SCPE_OK; -} - -static t_stat sim_os_ttrun (void) -{ -return SCPE_OK; -} - -static t_stat sim_os_ttcmd (void) -{ -return SCPE_OK; -} - -static t_stat sim_os_ttclose (void) -{ -return SCPE_OK; -} - -static t_bool sim_os_fd_isatty (int fd) -{ -return 1; -} - -static t_stat sim_os_poll_kbd (void) -{ -int c; - -sim_debug (DBG_TRC, &sim_con_telnet, "sim_os_poll_kbd()\n"); - -#if defined (__EMX__) -switch (c = _read_kbd(0,0,0)) { /* EMX has _read_kbd */ - - case -1: /* no char*/ - return SCPE_OK; - - case 0: /* char pending */ - c = _read_kbd(0,1,0); - break; - - default: /* got char */ - break; - } -#else -if (!kbhit ()) - return SCPE_OK; -c = getch(); -#endif -if ((c & 0177) == sim_del_char) - c = 0177; -if ((c & 0177) == sim_int_char) - return SCPE_STOP; -if (sim_brk_char && ((c & 0177) == sim_brk_char)) - return SCPE_BREAK; -return c | SCPE_KFLAG; -} - -static t_bool sim_os_poll_kbd_ready (int ms_timeout) /* Don't know how to do this on this platform */ -{ -sim_os_ms_sleep (MIN(20,ms_timeout)); /* Wait a little */ -return TRUE; /* force a poll */ -} - -static t_stat sim_os_putchar (int32 c) -{ -if (c != 0177) { -#if defined (__EMX__) - putchar (c); -#else - putch (c); -#endif - fflush (stdout); - } -return SCPE_OK; -} - -/* Metrowerks CodeWarrior Macintosh routines, from Louis Chretien and - Peter Schorn */ - -#elif defined (__MWERKS__) && defined (macintosh) - -#include -#include -#include -#include -#include -#include -#include -#include - -/* function prototypes */ - -Boolean SIOUXIsAppWindow(WindowPtr window); -void SIOUXDoMenuChoice(long menuValue); -void SIOUXUpdateMenuItems(void); -void SIOUXUpdateScrollbar(void); -int ps_kbhit(void); -int ps_getch(void); - -extern pSIOUXWin SIOUXTextWindow; -static CursHandle iBeamCursorH = NULL; /* contains the iBeamCursor */ - -static void updateCursor(void) { - WindowPtr window; - window = FrontWindow(); - if (SIOUXIsAppWindow(window)) { - GrafPtr savePort; - Point localMouse; - GetPort(&savePort); - SetPort(window); -#if TARGET_API_MAC_CARBON - GetGlobalMouse(&localMouse); -#else - localMouse = LMGetMouseLocation(); -#endif - GlobalToLocal(&localMouse); - if (PtInRect(localMouse, &(*SIOUXTextWindow->edit)->viewRect) && iBeamCursorH) { - SetCursor(*iBeamCursorH); - } - else { - SetCursor(&qd.arrow); - } - TEIdle(SIOUXTextWindow->edit); - SetPort(savePort); - } - else { - SetCursor(&qd.arrow); - TEIdle(SIOUXTextWindow->edit); - } - return; -} - -int ps_kbhit(void) { - EventRecord event; - int c; - updateCursor(); - SIOUXUpdateScrollbar(); - while (GetNextEvent(updateMask | osMask | mDownMask | mUpMask | activMask | - highLevelEventMask | diskEvt, &event)) { - SIOUXHandleOneEvent(&event); - } - if (SIOUXQuitting) { - exit(1); - } - if (EventAvail(keyDownMask,&event)) { - c = event.message&charCodeMask; - if ((event.modifiers & cmdKey) && (c > 0x20)) { - GetNextEvent(keyDownMask, &event); - SIOUXHandleOneEvent(&event); - if (SIOUXQuitting) { - exit(1); - } - return false; - } - return true; - } - else { - return false; - } -} - -int ps_getch(void) { - int c; - EventRecord event; - fflush(stdout); - updateCursor(); - while(!GetNextEvent(keyDownMask,&event)) { - if (GetNextEvent(updateMask | osMask | mDownMask | mUpMask | activMask | - highLevelEventMask | diskEvt, &event)) { - SIOUXUpdateScrollbar(); - SIOUXHandleOneEvent(&event); - } - } - if (SIOUXQuitting) { - exit(1); - } - c = event.message&charCodeMask; - if ((event.modifiers & cmdKey) && (c > 0x20)) { - SIOUXUpdateMenuItems(); - SIOUXDoMenuChoice(MenuKey(c)); - } - if (SIOUXQuitting) { - exit(1); - } - return c; -} - -/* Note that this only works if the call to sim_ttinit comes before any output to the console */ - -static t_stat sim_os_ttinit (void) -{ - int i; - - sim_debug (DBG_TRC, &sim_con_telnet, "sim_os_ttinit()\n"); - - /* this blank will later be replaced by the number of characters */ - char title[50] = " "; - unsigned char ptitle[50]; - SIOUXSettings.autocloseonquit = TRUE; - SIOUXSettings.asktosaveonclose = FALSE; - SIOUXSettings.showstatusline = FALSE; - SIOUXSettings.columns = 80; - SIOUXSettings.rows = 40; - SIOUXSettings.toppixel = 42; - SIOUXSettings.leftpixel = 6; - iBeamCursorH = GetCursor(iBeamCursor); - strlcat(title, sim_name, sizeof(title)); - strlcat(title, " Simulator", sizeof(title)); - title[0] = strlen(title) - 1; /* Pascal string done */ - for (i = 0; i <= title[0]; i++) { /* copy to unsigned char */ - ptitle[i] = title[i]; - } - SIOUXSetTitle(ptitle); - return SCPE_OK; -} - -static t_stat sim_os_ttrun (void) -{ -return SCPE_OK; -} - -static t_stat sim_os_ttcmd (void) -{ -return SCPE_OK; -} - -static t_stat sim_os_ttclose (void) -{ -return SCPE_OK; -} - -static t_bool sim_os_fd_isatty (int fd) -{ -return 1; -} - -static t_stat sim_os_poll_kbd (void) -{ -int c; - -sim_debug (DBG_TRC, &sim_con_telnet, "sim_os_poll_kbd()\n"); - -if (!ps_kbhit ()) - return SCPE_OK; -c = ps_getch(); -if ((c & 0177) == sim_del_char) - c = 0177; -if ((c & 0177) == sim_int_char) - return SCPE_STOP; -if (sim_brk_char && ((c & 0177) == sim_brk_char)) - return SCPE_BREAK; -return c | SCPE_KFLAG; -} - -static t_bool sim_os_poll_kbd_ready (int ms_timeout) /* Don't know how to do this on this platform */ -{ -sim_os_ms_sleep (MIN(20,ms_timeout)); /* Wait a little */ -return TRUE; /* force a poll */ -} - -static t_stat sim_os_putchar (int32 c) -{ -if (c != 0177) { - putchar (c); - fflush (stdout); - } -return SCPE_OK; -} - -/* BSD UNIX routines */ - #elif defined (BSDTTY) #include diff --git a/sim_console.h b/sim_console.h index b73348ee..12a8b68b 100644 --- a/sim_console.h +++ b/sim_console.h @@ -1,6 +1,6 @@ /* sim_console.h: simulator console I/O library headers - Copyright (c) 1993-2014, Robert M Supnik + Copyright (c) 1993-2022, Robert M Supnik Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), @@ -23,6 +23,8 @@ used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from Robert M Supnik. + 27-Sep-22 RMS Added sim_ttisatty + 14-Dec-14 JDB [4.0] Added sim_*_char externals 02-Jan-14 RMS Added tab stop routines 17-Jan-11 MP Added buffered line capabilities 22-Jun-06 RMS Implemented SET/SHOW PCHAR diff --git a/sim_defs.h b/sim_defs.h index eb5968d1..e7b844f6 100644 --- a/sim_defs.h +++ b/sim_defs.h @@ -23,6 +23,17 @@ used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from Robert M Supnik. + 06-Jun-22 RMS Deprecated UNIT_TEXT, deleted UNIT_RAW + 10-Mar-22 JDB Modified REG macros to fix "stringizing" problem + 12-Nov-21 JDB Added UNIT_EXTEND dynamic flag + 17-Mar-21 JDB Added UNIT_PIPE dynamic flag + 16-Feb-21 JDB Added "stride" to REG to support arrays of structures + Modified REG macros to initialize strides + 21-Jan-21 JDB Added "size" and "maxval" fields to the REG structure + Modified REG macros to initialize access sizes + 09-Nov-20 RMS More V4.X compatibility hooks (Mark Pizzolato) + 26-Oct-19 RMS Removed MTAB_VAL definition + 23-Jun-17 RMS Added #include sim_rev.h (Mark Pizzolato) 25-Sep-16 RMS Removed KBD_WAIT and friends 08-Mar-16 RMS Added shutdown invisible switch 24-Dec-14 JDB Added T_ADDR_FMT @@ -647,8 +658,10 @@ struct UNIT { #define UNIT_WLK 0100000 /* hardware write lock */ #define UNIT_WPRT (UNIT_WLK|UNIT_RO)/* write protect */ -/* Unused/meaningless flags */ -#define UNIT_TEXT 0000000 /* text mode - no effect */ +/* Deleted or deprecated */ + +// #define UNIT_RAW 000000 /* raw mode */ +#define UNIT_TEXT 000000 /* text mode */ #define UNIT_UFMASK_31 (((1u << UNIT_V_RSV) - 1) & ~((1u << UNIT_V_UF_31) - 1)) #define UNIT_UFMASK (((1u << UNIT_V_RSV) - 1) & ~((1u << UNIT_V_UF) - 1)) diff --git a/sim_tape.c b/sim_tape.c index c05a4226..4dd0c89c 100644 --- a/sim_tape.c +++ b/sim_tape.c @@ -2370,7 +2370,36 @@ return r; Implementation notes: - 1. Erase gaps are currently supported only in SIMH (MTUF_F_STD) tape format. + 1. Erase gaps are currently supported only in standard and extended SIMH + tape formats. + + 2. Metadatum reads either succeed and return 1 or fail and return 0. If a + read fails, and "ferror" returns false, then it must have read into the + end of the file (only these three outcomes are possible). + + 3. The area scan is necessary for tape image integrity to ensure that a data + record straddling the end of the erasure is truncated appropriately. The + scan is guaranteed to succeed only if it begins at a valid metadatum. If + it begins in the middle of a previously overwritten data record, then the + scan will interpret old data values as tape formatting markers. The data + record sanity checks attempt to recover from this situation, but it is + still possible to corrupt valid data that follows an erasure of an + invalid area (e.g., if the leading and trailing length words happen + to match but actually represent previously recorded data rather than + record metadata). If an application knows that the erased area will + not contain valid formatting, the "sim_tape_erase" routine should be used + instead, as it erases without first scanning the area. + + 4. Truncating an existing data record corresponds to overwriting part of a + record on a real tape. Reading such a record on a real drive would + produce CRC errors, due to the lost portion. In simulation, we could + change a good record (Class 0) to a bad record (Class 8). However, this + is not possible for private or reserved record classes, as that would + change the classification (consider that a private class that had + been ignored would not be once it had been truncated and changed to Class + 8). Given that there is no good general solution, we do not modify + classes for truncated records, as reading a partially erased record is an + "all bets are off" operation. */ static t_stat tape_erase_fwd (UNIT *uptr, t_mtrlnt gap_size) diff --git a/sim_timer.c b/sim_timer.c index 227399b7..6a170560 100644 --- a/sim_timer.c +++ b/sim_timer.c @@ -1,6 +1,6 @@ /* sim_timer.c: simulator timer library - Copyright (c) 1993-2010, Robert M Supnik + Copyright (c) 1993-2022, Robert M Supnik Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), @@ -23,6 +23,11 @@ used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from Robert M Supnik. + 27-Sep-22 RMS Removed OS/2 and Mac "Classic" support + 01-Feb-21 JDB Added cast for down-conversion + 22-May-17 RMS Hacked for V4.0 CONST compatibility + 23-Nov-15 RMS Fixed calibration lost path to reinitialize timer + 28-Mar-15 RMS Revised to use sim_printf 21-Oct-11 MP Fixed throttling in several ways: - Sleep for the observed clock tick size while throttling - Recompute the throttling wait once every 10 seconds @@ -536,92 +541,6 @@ return 0; } #endif -#elif defined (__OS2__) - -/* OS/2 routines, from Bruce Ray */ - -const t_bool rtc_avail = FALSE; - -uint32 sim_os_msec (void) -{ -return 0; -} - -void sim_os_sleep (unsigned int sec) -{ -} - -uint32 sim_os_ms_sleep_init (void) -{ -return 0; -} - -uint32 sim_os_ms_sleep (unsigned int msec) -{ -return 0; -} - -/* Metrowerks CodeWarrior Macintosh routines, from Ben Supnik */ - -#elif defined (__MWERKS__) && defined (macintosh) - -#include -#include -#include -#include -#include -#define NANOS_PER_MILLI 1000000 -#define MILLIS_PER_SEC 1000 - -const t_bool rtc_avail = TRUE; - -uint32 sim_os_msec (void) -{ -unsigned long long micros; -UnsignedWide macMicros; -unsigned long millis; - -Microseconds (&macMicros); -micros = *((unsigned long long *) &macMicros); -millis = micros / 1000LL; -return (uint32) millis; -} - -void sim_os_sleep (unsigned int sec) -{ -sleep (sec); -} - -uint32 sim_os_ms_sleep_init (void) -{ -return _compute_minimum_sleep (); -} - -uint32 sim_os_ms_sleep (unsigned int milliseconds) -{ -uint32 stime = sim_os_msec (); -struct timespec treq; - -treq.tv_sec = milliseconds / MILLIS_PER_SEC; -treq.tv_nsec = (milliseconds % MILLIS_PER_SEC) * NANOS_PER_MILLI; -(void) nanosleep (&treq, NULL); -return sim_os_msec () - stime; -} - -#if defined(NEED_CLOCK_GETTIME) -int clock_gettime(int clk_id, struct timespec *tp) -{ -struct timeval cur; - -if (clk_id != CLOCK_REALTIME) - return -1; -gettimeofday (&cur, NULL); -tp->tv_sec = cur.tv_sec; -tp->tv_nsec = cur.tv_usec*1000; -return 0; -} -#endif - #else /* UNIX routines */