| 1 | /*\r |
| 2 | * (C) Copyright 2002, Brian Knittel.\r |
| 3 | * You may freely use this program, but: it offered strictly on an AS-IS, AT YOUR OWN\r |
| 4 | * RISK basis, there is no warranty of fitness for any purpose, and the rest of the\r |
| 5 | * usual yada-yada. Please keep this notice and the copyright in any distributions\r |
| 6 | * or modifications.\r |
| 7 | *\r |
| 8 | * This is not a supported product, but I welcome bug reports and fixes.\r |
| 9 | * Mail to sim@ibm1130.org\r |
| 10 | */\r |
| 11 | \r |
| 12 | /* ibm1130_defs.h: IBM-1130 simulator definitions\r |
| 13 | */\r |
| 14 | \r |
| 15 | #include "sim_defs.h" /* main SIMH defns (include path should include .., or make a copy) */\r |
| 16 | #include "sim_console.h" /* more SIMH defns (include path should include .., or make a copy) */\r |
| 17 | \r |
| 18 | #include <setjmp.h>\r |
| 19 | #include <assert.h>\r |
| 20 | #include <stdlib.h>\r |
| 21 | \r |
| 22 | #if defined(VMS)\r |
| 23 | # include <unistd.h> /* to pick up 'unlink' */\r |
| 24 | #endif\r |
| 25 | \r |
| 26 | #define MIN(a,b) (((a) <= (b)) ? (a) : (b))\r |
| 27 | #define MAX(a,b) (((a) >= (b)) ? (a) : (b))\r |
| 28 | \r |
| 29 | #ifndef _WIN32\r |
| 30 | int strnicmp (const char *a, const char *b, int n);\r |
| 31 | int strcmpi (const char *a, const char *b);\r |
| 32 | #endif\r |
| 33 | \r |
| 34 | /* #define GUI_SUPPORT uncomment to compile the GUI extensions. It's defined in the windows ibm1130.mak makefile */\r |
| 35 | \r |
| 36 | /* ------------------------------------------------------------------------ */\r |
| 37 | /* Architectural constants */\r |
| 38 | \r |
| 39 | #define MAXMEMSIZE (32768) /* 32Kwords */\r |
| 40 | #define INIMEMSIZE (16384) /* 16Kwords */\r |
| 41 | #define MEMSIZE (cpu_unit.capac)\r |
| 42 | \r |
| 43 | #define ILL_ADR_FLAG 0x40000000 /* an impossible 1130 address */\r |
| 44 | \r |
| 45 | /* ------------------------------------------------------------------------ */\r |
| 46 | /* Global state */\r |
| 47 | \r |
| 48 | extern int cgi; /* TRUE if we are running as a CGI program */\r |
| 49 | extern int cgiwritable; /* TRUE if we can write the disk images back to the image file in CGI mode */\r |
| 50 | extern int sim_gui;\r |
| 51 | \r |
| 52 | extern uint16 M[]; /* core memory, up to 32Kwords (note: don't even think about trying 64K) */\r |
| 53 | extern uint16 ILSW[]; /* interrupt level status words */\r |
| 54 | extern int32 IAR; /* instruction address register */\r |
| 55 | extern int32 prev_IAR; /* instruction address register at start of current instruction */\r |
| 56 | extern int32 SAR, SBR; /* storage address/buffer registers */\r |
| 57 | extern int32 OP, TAG, CCC; /* instruction decoded pieces */\r |
| 58 | extern int32 CES; /* console entry switches */\r |
| 59 | extern int32 ACC, EXT; /* accumulator and extension */\r |
| 60 | extern int32 ARF; /* arithmetic factor register, a nonaddressable internal CPU register */\r |
| 61 | extern int32 RUNMODE; /* processor run/step mode */\r |
| 62 | extern int32 ipl; /* current interrupt level (-1 = not handling irq) */\r |
| 63 | extern int32 iplpending; /* interrupted IPL's */\r |
| 64 | extern int32 tbit; /* trace flag (causes level 5 IRQ after each instr) */\r |
| 65 | extern int32 V, C; /* condition codes */\r |
| 66 | extern int32 wait_state; /* wait state (waiting for an IRQ) */\r |
| 67 | extern int32 wait_lamp; /* alternate indicator to light the wait lamp on the GUI */\r |
| 68 | extern int32 int_req; /* sum of interrupt request levels active */\r |
| 69 | extern int32 int_lamps; /* accumulated version of int_req - gives lamp persistence */\r |
| 70 | extern int32 int_mask; /* current active interrupt mask (ipl sensitive) */\r |
| 71 | extern int32 mem_mask;\r |
| 72 | extern int32 cpu_dsw; /* CPU device status word */\r |
| 73 | extern int32 sim_int_char; /* interrupt character */\r |
| 74 | extern int32 con_dsw; /* has program stop and int run bits */\r |
| 75 | extern t_bool running;\r |
| 76 | extern t_bool power;\r |
| 77 | extern t_bool cgi; /* TRUE if we are running as a CGI program */\r |
| 78 | extern t_bool cgiwritable; /* TRUE if we can write to the disk image file in CGI mode */\r |
| 79 | extern t_stat reason; /* CPU execution loop control */\r |
| 80 | \r |
| 81 | #define WAIT_OP 1 /* wait state causes: wait instruction, invalid instruction*/\r |
| 82 | #define WAIT_INVALID_OP 2\r |
| 83 | \r |
| 84 | #define MODE_SS 3 /* RUNMODE values. SS and SMC are not implemented in this simulator */\r |
| 85 | #define MODE_SMC 2\r |
| 86 | #define MODE_INT_RUN 1\r |
| 87 | #define MODE_RUN 0\r |
| 88 | #define MODE_SI -1\r |
| 89 | #define MODE_DISP -2\r |
| 90 | #define MODE_LOAD -3\r |
| 91 | \r |
| 92 | /* ------------------------------------------------------------------------ */\r |
| 93 | /* debugging */\r |
| 94 | /* ------------------------------------------------------------------------ */\r |
| 95 | \r |
| 96 | #define ENABLE_DEBUG_PRINT\r |
| 97 | #define ENABLE_DEBUG_TO_LOG\r |
| 98 | \r |
| 99 | #ifdef ENABLE_DEBUG_PRINT\r |
| 100 | # define DEBUG_PRINT debug_print\r |
| 101 | #else\r |
| 102 | # ifdef ENABLE_DEBUG_TO_LOG\r |
| 103 | # define DEBUG_PRINT trace_io\r |
| 104 | # else\r |
| 105 | # define DEBUG_PRINT if (0) debug_print\r |
| 106 | # endif\r |
| 107 | #endif\r |
| 108 | \r |
| 109 | void debug_print(char *fmt, ...);\r |
| 110 | \r |
| 111 | /* ------------------------------------------------------------------------ */\r |
| 112 | /* memory IO routines */\r |
| 113 | \r |
| 114 | int32 ReadW (int32 a); \r |
| 115 | void WriteW (int32 a, int32 d);\r |
| 116 | \r |
| 117 | /* ------------------------------------------------------------------------ */\r |
| 118 | /* handy macros */\r |
| 119 | \r |
| 120 | #define CLRBIT(v,b) ((v) &= ~(b))\r |
| 121 | #define SETBIT(v,b) ((v) |= (b))\r |
| 122 | #define BETWEEN(v,a,b) (((v) >= (a)) && ((v) <= (b)))\r |
| 123 | \r |
| 124 | /* ------------------------------------------------------------------------ */\r |
| 125 | /* Simulator stop codes */\r |
| 126 | \r |
| 127 | #define STOP_WAIT 1 /* wait, no events */\r |
| 128 | #define STOP_INVALID_INSTR 2 /* bad instruction */\r |
| 129 | #define STOP_IBKPT 3 /* simulator breakpoint */\r |
| 130 | #define STOP_INCOMPLETE 4 /* simulator coding not complete here */\r |
| 131 | #define STOP_POWER_OFF 5 /* no power */\r |
| 132 | #define STOP_DECK_BREAK 6 /* !BREAK in deck file */\r |
| 133 | #define STOP_PHASE_BREAK 7 /* phase load break */\r |
| 134 | #define STOP_CRASH 8 /* program has crashed badly */\r |
| 135 | #define STOP_TIMED_OUT 9 /* simulation time limit exceeded */\r |
| 136 | #define STOP_IMMEDIATE 10 /* simulator stop key pressed (immediate stop) */\r |
| 137 | #define STOP_BREAK 11 /* simulator break key pressed */\r |
| 138 | #define STOP_STEP 12 /* step count expired */\r |
| 139 | #define STOP_OTHER 13 /* other reason, probably error returned by sim_process_event() */\r |
| 140 | \r |
| 141 | #define IORETURN(f,v) ((f)? (v): SCPE_OK) /* cond error return */\r |
| 142 | \r |
| 143 | #define INT_REQ_5 0x01 /* bits for interrupt levels (ipl, iplpending, int_req, int_mask) */\r |
| 144 | #define INT_REQ_4 0x02\r |
| 145 | #define INT_REQ_3 0x04\r |
| 146 | #define INT_REQ_2 0x08\r |
| 147 | #define INT_REQ_1 0x10\r |
| 148 | #define INT_REQ_0 0x20\r |
| 149 | \r |
| 150 | #define XIO_UNUSED 0x00 /* XIO commands */\r |
| 151 | #define XIO_WRITE 0x01\r |
| 152 | #define XIO_READ 0x02\r |
| 153 | #define XIO_SENSE_IRQ 0x03\r |
| 154 | #define XIO_CONTROL 0x04\r |
| 155 | #define XIO_INITW 0x05\r |
| 156 | #define XIO_INITR 0x06\r |
| 157 | #define XIO_SENSE_DEV 0x07\r |
| 158 | \r |
| 159 | #define XIO_FAILED 0x20 /* fake function to record error */\r |
| 160 | \r |
| 161 | /* ILSW bits - set by appropriate device whenever an interrupt is outstanding */\r |
| 162 | \r |
| 163 | #define ILSW_0_1442_CARD 0x8000 /* ILSW 0 is not really defined on the 1130 */\r |
| 164 | \r |
| 165 | #define ILSW_1_1132_PRINTER 0x8000 /* had these backwards! */\r |
| 166 | #define ILSW_1_SCA 0x4000\r |
| 167 | \r |
| 168 | #define ILSW_2_1131_DISK 0x8000\r |
| 169 | \r |
| 170 | #define ILSW_2_2310_DRV_1 0x4000\r |
| 171 | #define ILSW_2_2310_DRV_2 0x2000\r |
| 172 | #define ILSW_2_2310_DRV_3 0x1000\r |
| 173 | #define ILSW_2_2310_DRV_4 0x0800 /* can have 2310 or 2311 */\r |
| 174 | \r |
| 175 | #define ILSW_2_2311_DRV_1_DISK_1 0x4000\r |
| 176 | #define ILSW_2_2311_DRV_1_DISK_2 0x2000\r |
| 177 | #define ILSW_2_2311_DRV_1_DISK_3 0x1000\r |
| 178 | #define ILSW_2_2311_DRV_1_DISK_4 0x0800\r |
| 179 | \r |
| 180 | #define ILSW_2_2311_DRV_1_DISK_5 0x0400\r |
| 181 | #define ILSW_2_2311_DRV_2_DISK_1 0x0200\r |
| 182 | #define ILSW_2_2311_DRV_2_DISK_2 0x0100\r |
| 183 | #define ILSW_2_2311_DRV_2_DISK_3 0x0080\r |
| 184 | #define ILSW_2_2311_DRV_2_DISK_4 0x0040\r |
| 185 | #define ILSW_2_2311_DRV_2_DISK_5 0x0020\r |
| 186 | \r |
| 187 | #define ILSW_2_SAC_BIT_11 0x0010\r |
| 188 | #define ILSW_2_SAC_BIT_12 0x0008\r |
| 189 | #define ILSW_2_SAC_BIT_13 0x0004\r |
| 190 | #define ILSW_2_SAC_BIT_14 0x0002\r |
| 191 | #define ILSW_2_SAC_BIT_15 0x0001\r |
| 192 | \r |
| 193 | #define ILSW_3_1627_PLOTTER 0x8000\r |
| 194 | #define ILSW_3_SAC_BIT_01 0x4000\r |
| 195 | #define ILSW_3_SAC_BIT_02 0x2000\r |
| 196 | #define ILSW_3_SAC_BIT_03 0x1000\r |
| 197 | #define ILSW_3_2250_DISPLAY 0x0800\r |
| 198 | #define ILSW_3_SYSTEM7 0x0800\r |
| 199 | #define ILSW_3_SAC_BIT_05 0x0400\r |
| 200 | #define ILSW_3_SAC_BIT_06 0x0200\r |
| 201 | #define ILSW_3_SAC_BIT_07 0x0100\r |
| 202 | #define ILSW_3_SAC_BIT_08 0x0080\r |
| 203 | #define ILSW_3_SAC_BIT_09 0x0040\r |
| 204 | #define ILSW_3_SAC_BIT_10 0x0020\r |
| 205 | #define ILSW_3_SAC_BIT_11 0x0010\r |
| 206 | #define ILSW_3_SAC_BIT_12 0x0008\r |
| 207 | #define ILSW_3_SAC_BIT_13 0x0004\r |
| 208 | #define ILSW_3_SAC_BIT_14 0x0002\r |
| 209 | #define ILSW_3_SAC_BIT_15 0x0001\r |
| 210 | \r |
| 211 | #define ILSW_4_1134_TAPE 0x8000\r |
| 212 | #define ILSW_4_1055_TAPE 0x8000\r |
| 213 | #define ILSW_4_CONSOLE 0x4000\r |
| 214 | #define ILSW_4_1442_CARD 0x2000\r |
| 215 | #define ILSW_4_2501_CARD 0x1000\r |
| 216 | #define ILSW_4_1403_PRINTER 0x0800\r |
| 217 | #define ILSW_4_1231_MARK 0x0400\r |
| 218 | #define ILSW_4_SAC_BIT_06 0x0200\r |
| 219 | #define ILSW_4_SAC_BIT_07 0x0100\r |
| 220 | #define ILSW_4_SAC_BIT_08 0x0080\r |
| 221 | #define ILSW_4_SAC_BIT_09 0x0040\r |
| 222 | #define ILSW_4_SAC_BIT_10 0x0020\r |
| 223 | #define ILSW_4_SAC_BIT_11 0x0010\r |
| 224 | #define ILSW_4_T2741_TERMINAL 0x0010 /* APL\1130 nonstandard serial interface uses this bit */\r |
| 225 | #define ILSW_4_SAC_BIT_12 0x0008\r |
| 226 | #define ILSW_4_SAC_BIT_13 0x0004\r |
| 227 | #define ILSW_4_SAC_BIT_14 0x0002\r |
| 228 | #define ILSW_4_SAC_BIT_15 0x0001\r |
| 229 | \r |
| 230 | #define ILSW_5_INT_RUN_PROGRAM_STOP 0x8000 /* this replaces both ILSW_5_INT_RUN and ILSW_5_PROGRAM_STOP */\r |
| 231 | #define ILSW_5_SAC_BIT_01 0x4000\r |
| 232 | #define ILSW_5_SAC_BIT_02 0x2000\r |
| 233 | #define ILSW_5_SAC_BIT_03 0x1000\r |
| 234 | #define ILSW_5_SAC_BIT_04 0x0800\r |
| 235 | #define ILSW_5_SAC_BIT_05 0x0400\r |
| 236 | #define ILSW_5_SAC_BIT_06 0x0200\r |
| 237 | #define ILSW_5_SAC_BIT_07 0x0100\r |
| 238 | #define ILSW_5_SAC_BIT_08 0x0080\r |
| 239 | #define ILSW_5_SAC_BIT_09 0x0040\r |
| 240 | #define ILSW_5_SAC_BIT_10 0x0020\r |
| 241 | #define ILSW_5_SAC_BIT_11 0x0010\r |
| 242 | #define ILSW_5_SAC_BIT_12 0x0008\r |
| 243 | #define ILSW_5_SAC_BIT_13 0x0004\r |
| 244 | #define ILSW_5_SAC_BIT_14 0x0002\r |
| 245 | #define ILSW_5_SAC_BIT_15 0x0001\r |
| 246 | \r |
| 247 | /* CPU DSW bits */\r |
| 248 | \r |
| 249 | #define CPU_DSW_PROGRAM_STOP 0x8000\r |
| 250 | #define CPU_DSW_INT_RUN 0x4000\r |
| 251 | \r |
| 252 | /* prototypes: xio handlers */\r |
| 253 | \r |
| 254 | void xio_1131_console (int32 addr, int32 func, int32 modify); /* console keyboard and printer */\r |
| 255 | void xio_1142_card (int32 addr, int32 func, int32 modify); /* standard card reader/punch */\r |
| 256 | void xio_1134_papertape (int32 addr, int32 func, int32 modify); /* paper tape reader/punch */\r |
| 257 | void xio_disk (int32 addr, int32 func, int32 modify, int drv); /* internal CPU disk */\r |
| 258 | void xio_1627_plotter (int32 addr, int32 func, int32 modify); /* XY plotter */\r |
| 259 | void xio_1132_printer (int32 addr, int32 func, int32 modify); /* standard line printer */\r |
| 260 | void xio_1131_switches (int32 addr, int32 func, int32 modify); /* console buttons & switches */\r |
| 261 | void xio_1231_optical (int32 addr, int32 func, int32 modify); /* optical mark page reader */\r |
| 262 | void xio_2501_card (int32 addr, int32 func, int32 modify); /* alternate high-speed card reader */\r |
| 263 | void xio_sca (int32 addr, int32 func, int32 modify); /* synchronous communications adapter */\r |
| 264 | void xio_system7 (int32 addr, int32 func, int32 modify); /* system/7 interprocessor IO link */\r |
| 265 | void xio_1403_printer (int32 addr, int32 func, int32 modify); /* alternate high-speed printer */\r |
| 266 | void xio_2250_display (int32 addr, int32 func, int32 modify); /* vector display processor */\r |
| 267 | void xio_t2741_terminal (int32 addr, int32 func, int32 modify); /* IO selectric via nonstandard serial interface for APL */\r |
| 268 | void xio_error (char *msg);\r |
| 269 | \r |
| 270 | void bail (char *msg);\r |
| 271 | t_stat load_cr_boot (int drv, int switches);\r |
| 272 | t_stat cr_boot (int unitno, DEVICE *dptr);\r |
| 273 | t_stat cr_rewind (void);\r |
| 274 | t_stat cr_detach (UNIT *uptr);\r |
| 275 | void calc_ints (void); /* recalculate interrupt bitmask */\r |
| 276 | void trace_io (char *fmt, ...); /* debugging printout */\r |
| 277 | void trace_both (char *fmt, ...); /* debugging printout */\r |
| 278 | t_stat register_cmd (char *name, t_stat (*action)(int32 flag, char *ptr), int arg, char *help);\r |
| 279 | void scp_panic (char *msg); /* bail out of simulator */\r |
| 280 | char *upcase(char *str);\r |
| 281 | void break_simulation (t_stat reason); /* let a device halt the simulation */\r |
| 282 | char hollerith_to_ascii (uint16 hol); /* for debugging use only */\r |
| 283 | t_bool gdu_active (void);\r |
| 284 | void remark_cmd (char *remark);\r |
| 285 | void stuff_cmd (char *cmd);\r |
| 286 | t_bool stuff_and_wait (char *cmd, int timeout, int delay);\r |
| 287 | void update_gui (t_bool force);\r |
| 288 | void sim_init (void);\r |
| 289 | t_stat register_cmd (char *name, t_stat (*action)(int32 flag, char *ptr), int arg, char *help);\r |
| 290 | t_stat basic_attach (UNIT *uptr, char *cptr);\r |
| 291 | char * quotefix (char * cptr);\r |
| 292 | \r |
| 293 | /* GUI interface routines */\r |
| 294 | t_bool keyboard_is_busy (void);\r |
| 295 | void forms_check (int set); /* device notification to console lamp display */\r |
| 296 | void print_check (int set);\r |
| 297 | void keyboard_selected (int select); \r |
| 298 | void disk_ready (int ready);\r |
| 299 | void disk_unlocked (int unlocked);\r |
| 300 | void gui_run(int running);\r |
| 301 | char *read_cmdline (char *ptr, int size, FILE *stream);\r |
| 302 | \r |
| 303 | #ifdef GUI_SUPPORT\r |
| 304 | # define GUI_BEGIN_CRITICAL_SECTION begin_critical_section();\r |
| 305 | # define GUI_END_CRITICAL_SECTION end_critical_section();\r |
| 306 | void begin_critical_section (void);\r |
| 307 | void end_critical_section (void);\r |
| 308 | #else\r |
| 309 | # define GUI_BEGIN_CRITICAL_SECTION\r |
| 310 | # define GUI_END_CRITICAL_SECTION\r |
| 311 | #endif\r |