From 0c27d1f5a8f0d952aac0cdd5d513e8b121f1a33b Mon Sep 17 00:00:00 2001 From: Mark Pizzolato Date: Wed, 3 May 2017 15:11:22 -0700 Subject: [PATCH] IBM1130: Convert Tabs to Spaces --- Ibm1130/ibm1130_conin.h | 40 +- Ibm1130/ibm1130_conout.h | 64 +- Ibm1130/ibm1130_cpu.c | 2314 ++++++++-------- Ibm1130/ibm1130_cr.c | 3424 +++++++++++------------ Ibm1130/ibm1130_defs.h | 344 +-- Ibm1130/ibm1130_disk.c | 1132 ++++---- Ibm1130/ibm1130_fmt.c | 428 +-- Ibm1130/ibm1130_fmt.h | 6 +- Ibm1130/ibm1130_gdu.c | 1418 +++++----- Ibm1130/ibm1130_gui.c | 1992 +++++++------- Ibm1130/ibm1130_plot.c | 812 +++--- Ibm1130/ibm1130_prt.c | 1072 ++++---- Ibm1130/ibm1130_prtwheel.h | 200 +- Ibm1130/ibm1130_ptrp.c | 310 +-- Ibm1130/ibm1130_sca.c | 1328 ++++----- Ibm1130/ibm1130_stddev.c | 1450 +++++----- Ibm1130/ibm1130_sys.c | 622 ++--- Ibm1130/ibm1130_t2741.c | 526 ++-- Ibm1130/utils/asm1130.c | 5350 ++++++++++++++++++------------------ Ibm1130/utils/bindump.c | 980 +++---- Ibm1130/utils/checkdisk.c | 310 +-- Ibm1130/utils/diskview.c | 634 ++--- Ibm1130/utils/mkboot.c | 840 +++--- Ibm1130/utils/viewdeck.c | 356 +-- 24 files changed, 12976 insertions(+), 12976 deletions(-) diff --git a/Ibm1130/ibm1130_conin.h b/Ibm1130/ibm1130_conin.h index a142e865..d173d024 100644 --- a/Ibm1130/ibm1130_conin.h +++ b/Ibm1130/ibm1130_conin.h @@ -11,33 +11,33 @@ /* * 03 ctrl-C => Program stop (not handled here) - * 05 ctrl-E => Simulator stop (not handled here) + * 05 ctrl-E => Simulator stop (not handled here) * 08 ctrl-H => Backspace * 0D ctrl-M (Enter) => EOF * 11 ctrl-Q => Interrupt request (not handled here) - * 12 ctrl-R => "cent" (R because that's where cent is on the 1130 keyboard) + * 12 ctrl-R => "cent" (R because that's where cent is on the 1130 keyboard) * 15 ctrl-U => Erase Field * 7E ~ => "not" * FF Del => Backspace again */ -static uint16 ascii_to_conin[] = /* ASCII to ((hollerith << 4) | special key flags) */ +static uint16 ascii_to_conin[] = /* ASCII to ((hollerith << 4) | special key flags) */ { - /* 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F */ - /* 00 */ 0, 0, 0, 0, 0, 0, 0, 0,0x0004, 0, 0, 0, 0,0x0008, 0, 0, - /* 10 */ 0, 0,0x8820, 0, 0,0x0002, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - /* 20 */ 0x0001,0x4820,0x0060,0x0420,0x4420,0x2220,0x8000,0x0120,0x8120,0x4120,0x4220,0x80a0,0x2420,0x4000,0x8420,0x3000, - /* 30 */ 0x2000,0x1000,0x0800,0x0400,0x0200,0x0100,0x0080,0x0040,0x0020,0x0010,0x0820,0x40a0,0x8220,0x00a0,0x20a0,0x2060, - /* 40 */ 0x0220,0x9000,0x8800,0x8400,0x8200,0x8100,0x8080,0x8040,0x8020,0x8010,0x5000,0x4800,0x4400,0x4200,0x4100,0x4080, - /* 50 */ 0x4040,0x4020,0x4010,0x2800,0x2400,0x2200,0x2100,0x2080,0x2040,0x2020,0x2010, 0, 0, 0, 0,0x2120, - /* 60 */ 0,0x9000,0x8800,0x8400,0x8200,0x8100,0x8080,0x8040,0x8020,0x8010,0x5000,0x4800,0x4400,0x4200,0x4100,0x4080, - /* 70 */ 0x4040,0x4020,0x4010,0x2800,0x2400,0x2200,0x2100,0x2080,0x2040,0x2020,0x2010, 0,0xB060, 0, 0,0x0004, - /* 80 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - /* 90 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - /* a0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - /* b0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - /* c0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - /* d0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - /* e0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - /* f0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0x0004, + /* 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F */ + /* 00 */ 0, 0, 0, 0, 0, 0, 0, 0,0x0004, 0, 0, 0, 0,0x0008, 0, 0, + /* 10 */ 0, 0,0x8820, 0, 0,0x0002, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + /* 20 */ 0x0001,0x4820,0x0060,0x0420,0x4420,0x2220,0x8000,0x0120,0x8120,0x4120,0x4220,0x80a0,0x2420,0x4000,0x8420,0x3000, + /* 30 */ 0x2000,0x1000,0x0800,0x0400,0x0200,0x0100,0x0080,0x0040,0x0020,0x0010,0x0820,0x40a0,0x8220,0x00a0,0x20a0,0x2060, + /* 40 */ 0x0220,0x9000,0x8800,0x8400,0x8200,0x8100,0x8080,0x8040,0x8020,0x8010,0x5000,0x4800,0x4400,0x4200,0x4100,0x4080, + /* 50 */ 0x4040,0x4020,0x4010,0x2800,0x2400,0x2200,0x2100,0x2080,0x2040,0x2020,0x2010, 0, 0, 0, 0,0x2120, + /* 60 */ 0,0x9000,0x8800,0x8400,0x8200,0x8100,0x8080,0x8040,0x8020,0x8010,0x5000,0x4800,0x4400,0x4200,0x4100,0x4080, + /* 70 */ 0x4040,0x4020,0x4010,0x2800,0x2400,0x2200,0x2100,0x2080,0x2040,0x2020,0x2010, 0,0xB060, 0, 0,0x0004, + /* 80 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + /* 90 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + /* a0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + /* b0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + /* c0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + /* d0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + /* e0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + /* f0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0x0004, }; diff --git a/Ibm1130/ibm1130_conout.h b/Ibm1130/ibm1130_conout.h index 953017c4..31a03d2f 100644 --- a/Ibm1130/ibm1130_conout.h +++ b/Ibm1130/ibm1130_conout.h @@ -12,47 +12,47 @@ #define _0_ '\0' -#define CENT_ 0xA2 /* cent and not: standard DOS mapping */ -#define NOT_ 0xAC -#define IGNR_ 0xFF -#define CRLF_ '\r' +#define CENT_ 0xA2 /* cent and not: standard DOS mapping */ +#define NOT_ 0xAC +#define IGNR_ 0xFF +#define CRLF_ '\r' -#define COUT_IS_CTRL 0x01 /* conout characters with bit 1 set are controls: */ +#define COUT_IS_CTRL 0x01 /* conout characters with bit 1 set are controls: */ -#define COUT_CTRL_BLACK 0x04 /* none or one of these bits */ -#define COUT_CTRL_RED 0x08 +#define COUT_CTRL_BLACK 0x04 /* none or one of these bits */ +#define COUT_CTRL_RED 0x08 -#define COUT_CTRL_LINEFEED 0x02 /* plus none or one of these bits */ -#define COUT_CTRL_BACKSPACE 0x10 -#define COUT_CTRL_SPACE 0x20 -#define COUT_CTRL_TAB 0x40 -#define COUT_CTRL_RETURN 0x80 +#define COUT_CTRL_LINEFEED 0x02 /* plus none or one of these bits */ +#define COUT_CTRL_BACKSPACE 0x10 +#define COUT_CTRL_SPACE 0x20 +#define COUT_CTRL_TAB 0x40 +#define COUT_CTRL_RETURN 0x80 #ifdef _MSC_VER -# pragma warning(disable:4245) /* enable int->char demotion warning caused by characters with high-bit set */ +# pragma warning(disable:4245) /* enable int->char demotion warning caused by characters with high-bit set */ #endif -static unsigned char conout_to_ascii[] = /* console output code to ASCII */ +static unsigned char conout_to_ascii[] = /* console output code to ASCII */ { - /* 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F */ - /* 00 */ '.', IGNR_,CENT_, '\n', '@', IGNR_,'%', _0_, _0_, IGNR_,_0_, _0_, _0_, _0_, _0_, _0_, - /* 10 */ 'F', '\b', 'f', _0_, 'G', _0_, 'g', _0_, 'B', _0_, 'b', _0_, 'C', _0_, 'c', _0_, - /* 20 */ 'I', ' ', 'i', _0_, 'H', _0_, 'h', _0_, _0_, _0_, _0_, _0_, _0_, _0_, _0_, _0_, - /* 30 */ 'D', _0_, 'd', _0_, 'E', _0_, 'e', _0_, _0_, _0_, _0_, _0_, 'A', _0_, 'a', _0_, - /* 40 */ '$', '\t', '!', _0_, '&', _0_, '>', _0_, _0_, _0_, _0_, _0_, _0_, _0_, _0_, _0_, - /* 50 */ 'O', _0_, 'o', _0_, 'P', _0_, 'o', _0_, 'K', _0_, 'k', _0_, 'L', _0_, 'l', _0_, - /* 60 */ 'R', _0_, 'r', _0_, 'Q', _0_, 'q', _0_, _0_, _0_, _0_, _0_, _0_, _0_, _0_, _0_, - /* 70 */ 'M', _0_, 'm', _0_, 'N', _0_, 'n', _0_, _0_, _0_, _0_, _0_, 'J', _0_, 'j', _0_, - /* 80 */ ',', CRLF_, ':', _0_, '-', _0_, '?', _0_, _0_, _0_, _0_, _0_, _0_, _0_, _0_, _0_, - /* 90 */ 'W', _0_, 'w', _0_, 'X', _0_, 'x', _0_, 'S', _0_, 's', _0_, 'T', _0_, 't', _0_, - /* A0 */ 'Z', _0_, 'z', _0_, 'Y', _0_, 'y', _0_, _0_, _0_, _0_, _0_, _0_, _0_, _0_, _0_, - /* B0 */ 'U', _0_, 'u', _0_, 'V', _0_, 'v', _0_, _0_, _0_, _0_, _0_, '/', _0_, '_', _0_, - /* C0 */ '#', _0_, '=', _0_, '0', _0_, '|', _0_, _0_, _0_, _0_, _0_, 'J', _0_, 'j', _0_, - /* D0 */ '6', _0_, ';', _0_, '7', _0_, '*', _0_, '2', _0_, '+', _0_, '3', _0_, '<', _0_, - /* E0 */ '9', _0_, '"', _0_, '8', _0_, '\'', _0_, _0_, _0_, _0_, _0_, _0_, _0_, _0_, _0_, - /* F0 */ '4', _0_, NOT_, _0_, '5', _0_, ')', _0_, _0_, _0_, _0_, _0_, '1', _0_, '(', _0_, + /* 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F */ + /* 00 */ '.', IGNR_,CENT_, '\n', '@', IGNR_,'%', _0_, _0_, IGNR_,_0_, _0_, _0_, _0_, _0_, _0_, + /* 10 */ 'F', '\b', 'f', _0_, 'G', _0_, 'g', _0_, 'B', _0_, 'b', _0_, 'C', _0_, 'c', _0_, + /* 20 */ 'I', ' ', 'i', _0_, 'H', _0_, 'h', _0_, _0_, _0_, _0_, _0_, _0_, _0_, _0_, _0_, + /* 30 */ 'D', _0_, 'd', _0_, 'E', _0_, 'e', _0_, _0_, _0_, _0_, _0_, 'A', _0_, 'a', _0_, + /* 40 */ '$', '\t', '!', _0_, '&', _0_, '>', _0_, _0_, _0_, _0_, _0_, _0_, _0_, _0_, _0_, + /* 50 */ 'O', _0_, 'o', _0_, 'P', _0_, 'o', _0_, 'K', _0_, 'k', _0_, 'L', _0_, 'l', _0_, + /* 60 */ 'R', _0_, 'r', _0_, 'Q', _0_, 'q', _0_, _0_, _0_, _0_, _0_, _0_, _0_, _0_, _0_, + /* 70 */ 'M', _0_, 'm', _0_, 'N', _0_, 'n', _0_, _0_, _0_, _0_, _0_, 'J', _0_, 'j', _0_, + /* 80 */ ',', CRLF_, ':', _0_, '-', _0_, '?', _0_, _0_, _0_, _0_, _0_, _0_, _0_, _0_, _0_, + /* 90 */ 'W', _0_, 'w', _0_, 'X', _0_, 'x', _0_, 'S', _0_, 's', _0_, 'T', _0_, 't', _0_, + /* A0 */ 'Z', _0_, 'z', _0_, 'Y', _0_, 'y', _0_, _0_, _0_, _0_, _0_, _0_, _0_, _0_, _0_, + /* B0 */ 'U', _0_, 'u', _0_, 'V', _0_, 'v', _0_, _0_, _0_, _0_, _0_, '/', _0_, '_', _0_, + /* C0 */ '#', _0_, '=', _0_, '0', _0_, '|', _0_, _0_, _0_, _0_, _0_, 'J', _0_, 'j', _0_, + /* D0 */ '6', _0_, ';', _0_, '7', _0_, '*', _0_, '2', _0_, '+', _0_, '3', _0_, '<', _0_, + /* E0 */ '9', _0_, '"', _0_, '8', _0_, '\'', _0_, _0_, _0_, _0_, _0_, _0_, _0_, _0_, _0_, + /* F0 */ '4', _0_, NOT_, _0_, '5', _0_, ')', _0_, _0_, _0_, _0_, _0_, '1', _0_, '(', _0_, }; #ifdef _MSC_VER -# pragma warning(default:4245) /* enable int->char demotion warning */ +# pragma warning(default:4245) /* enable int->char demotion warning */ #endif diff --git a/Ibm1130/ibm1130_cpu.c b/Ibm1130/ibm1130_cpu.c index 96c85266..f89758ed 100644 --- a/Ibm1130/ibm1130_cpu.c +++ b/Ibm1130/ibm1130_cpu.c @@ -11,27 +11,27 @@ * This is not a supported product, but I welcome bug reports and fixes. * Mail to simh@ibm1130.org - 25-Jun-01 BLK Written - 10-May-02 BLK Fixed bug in MDX instruction - 27-Mar-02 BLK Made BOSC work even in short form - 16-Aug-02 BLK Fixed bug in multiply instruction; didn't work with negative values - 18-Mar-03 BLK Fixed bug in divide instruction; didn't work with negative values - 23-Jul-03 BLK Prevented tti polling in CGI mode - 24-Nov-03 BLK Fixed carry bit error in subtract and subtract double, found by Bob Flanders - 20-Oct-04 BLK Changed "(unsigned int32)" to "(uint32)" to accomodate improved definitions of simh types - Also commented out my echo command as it's now a standard simh command + 25-Jun-01 BLK Written + 10-May-02 BLK Fixed bug in MDX instruction + 27-Mar-02 BLK Made BOSC work even in short form + 16-Aug-02 BLK Fixed bug in multiply instruction; didn't work with negative values + 18-Mar-03 BLK Fixed bug in divide instruction; didn't work with negative values + 23-Jul-03 BLK Prevented tti polling in CGI mode + 24-Nov-03 BLK Fixed carry bit error in subtract and subtract double, found by Bob Flanders + 20-Oct-04 BLK Changed "(unsigned int32)" to "(uint32)" to accomodate improved definitions of simh types + Also commented out my echo command as it's now a standard simh command 27-Nov-05 BLK Added Arithmetic Factor Register support per Carl Claunch (GUI only) - 06-Dec-06 BLK Moved CGI stuff out of ibm1130_cpu.c - 01-May-07 BLK Changed name of function xio_1142_card to xio_1442_card. Corrected list of - devices in xio_devs[] (used in debugging only). - 24-Mar-11 BLK Got the real IBM 1130 diagnostics (yay!). Fixed two errors detected by the CPU diagnostics: - -- was not resetting overflow bit after testing with BSC short form - (why did I think only the long form reset OV after testing?) - -- failed to detect numeric overflow in Divide instructions - Also fixed bug where simulator performed 2nd word fetch on Long mode instructions - on ops that don't have long mode, blowing out the SAR/SBR display that's important in the - IBM diagnostics. The simulator was decrementing the IAR after the incorrect fetch, so the - instructions worked correctly, but, the GUI display was wrong. + 06-Dec-06 BLK Moved CGI stuff out of ibm1130_cpu.c + 01-May-07 BLK Changed name of function xio_1142_card to xio_1442_card. Corrected list of + devices in xio_devs[] (used in debugging only). + 24-Mar-11 BLK Got the real IBM 1130 diagnostics (yay!). Fixed two errors detected by the CPU diagnostics: + -- was not resetting overflow bit after testing with BSC short form + (why did I think only the long form reset OV after testing?) + -- failed to detect numeric overflow in Divide instructions + Also fixed bug where simulator performed 2nd word fetch on Long mode instructions + on ops that don't have long mode, blowing out the SAR/SBR display that's important in the + IBM diagnostics. The simulator was decrementing the IAR after the incorrect fetch, so the + instructions worked correctly, but, the GUI display was wrong. >> To do: verify actual operands stored in ARF, need to get this from state diagrams in the schematic set Also: determine how many bits are actually stored in the IAR in a real 1130, by forcing wraparound @@ -48,22 +48,22 @@ The register state for the IBM 1130 CPU is: - IAR instruction address register - ACC accumulator - EXT accumulator extension - Oflow overflow bit - Carry carry bit - CES console entry switches - ipl current interrupt level, -1 = non interrupt - iplpending bitmap of pending interrupts - wait_state current CPU state: running or waiting - DSW console run/stop switch device status word - RUNMODE processor step/run mode (may also imply IntRun) - BREAK breakpoint address - WRU simulator-break character - IntRun Int Run flag (causes level 5 interrupt after every instruction) - ILSW0..5 interrupt level status words - XR1, 2, 3 for IBM 1800 only, index registers 1, 2, and 3 + IAR instruction address register + ACC accumulator + EXT accumulator extension + Oflow overflow bit + Carry carry bit + CES console entry switches + ipl current interrupt level, -1 = non interrupt + iplpending bitmap of pending interrupts + wait_state current CPU state: running or waiting + DSW console run/stop switch device status word + RUNMODE processor step/run mode (may also imply IntRun) + BREAK breakpoint address + WRU simulator-break character + IntRun Int Run flag (causes level 5 interrupt after every instruction) + ILSW0..5 interrupt level status words + XR1, 2, 3 for IBM 1800 only, index registers 1, 2, and 3 The SAR (storage address register) and SBR (storage buffer register) are updated but not saved in the CPU state; they matter only to the GUI. @@ -84,7 +84,7 @@ The IBM 1130 instruction formats are - +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ | opcode | F| T | | general format +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ @@ -138,9 +138,9 @@ Adding I/O devices requires modifications to three modules: - ibm1130_defs.h add interrupt request definitions - ibm1130_cpu.c add XIO command linkages - ibm1130_sys.c add to sim_devices array + ibm1130_defs.h add interrupt request definitions + ibm1130_cpu.c add XIO command linkages + ibm1130_sys.c add to sim_devices array */ /* ------------------------------------------------------------------------ @@ -151,12 +151,12 @@ #include "ibm1130_defs.h" -#define save_ibkpt (cpu_unit.u3) /* will be SAVEd */ +#define save_ibkpt (cpu_unit.u3) /* will be SAVEd */ #define UPDATE_BY_TIMER #define ENABLE_BACKTRACE -/* #define USE_MY_ECHO_CMD */ /* simh now has echo command built in */ -#define ENABLE_1800_SUPPORT /* define to enable support for 1800 CPU simulation mode */ +/* #define USE_MY_ECHO_CMD */ /* simh now has echo command built in */ +#define ENABLE_1800_SUPPORT /* define to enable support for 1800 CPU simulation mode */ static void cgi_start(void); static void cgi_stop(t_stat reason); @@ -182,39 +182,39 @@ CTAB x_cmds[MAX_EXTRA_COMMANDS]; #define SIGN_BIT(v) ((v) & 0x8000) #define DWSIGN_BIT(v) ((v) & 0x80000000) -uint16 M[MAXMEMSIZE]; /* core memory, up to 32Kwords (note: don't even think about trying 64K) */ -uint16 ILSW[6] = {0,0,0,0,0,0}; /* interrupt level status words */ -uint16 XR[3] = {0,0,0}; /* IBM 1800 index registers */ -int32 IAR; /* instruction address register */ -int32 prev_IAR; /* instruction address register at start of current instruction */ -int32 SAR, SBR; /* storage address/buffer registers */ -int32 OP, TAG, CCC; /* instruction decoded pieces */ -int32 CES; /* console entry switches */ -int32 ACC, EXT; /* accumulator and extension */ -int32 ARF; /* arithmetic factor, a non-addressable internal CPU register */ -int32 RUNMODE; /* processor run/step mode */ -int32 ipl = -1; /* current interrupt level (-1 = not handling irq) */ -int32 iplpending = 0; /* interrupted IPL's */ -int32 tbit = 0; /* trace flag (causes level 5 IRQ after each instr) */ -int32 V = 0, C = 0; /* condition codes */ -int32 wait_state = 0; /* wait state (waiting for an IRQ) */ -int32 wait_lamp = TRUE; /* alternate indicator to light the wait lamp on the GUI */ -int32 int_req = 0; /* sum of interrupt request levels active */ -int32 int_lamps = 0; /* accumulated version of int_req - gives lamp persistence */ -int32 int_mask; /* current active interrupt mask (ipl sensitive) */ -int32 mem_mask; /* mask for memory address bits based on current memory size */ -int32 cpu_dsw = 0; /* CPU device status word */ -int32 ibkpt_addr = -1; /* breakpoint addr */ -t_bool sim_gui = TRUE; /* enable gui */ -t_bool running = FALSE; /* TRUE if CPU is running */ -t_bool power = TRUE; /* TRUE if CPU power is on */ -t_bool cgi = FALSE; /* TRUE if we are running as a CGI program */ -t_bool cgiwritable = FALSE; /* TRUE if we can write the disk images back to the image file in CGI mode */ -t_bool is_1800 = FALSE; /* TRUE if we are simulating an IBM 1800 processor */ -t_stat reason; /* CPU execution loop control */ +uint16 M[MAXMEMSIZE]; /* core memory, up to 32Kwords (note: don't even think about trying 64K) */ +uint16 ILSW[6] = {0,0,0,0,0,0}; /* interrupt level status words */ +uint16 XR[3] = {0,0,0}; /* IBM 1800 index registers */ +int32 IAR; /* instruction address register */ +int32 prev_IAR; /* instruction address register at start of current instruction */ +int32 SAR, SBR; /* storage address/buffer registers */ +int32 OP, TAG, CCC; /* instruction decoded pieces */ +int32 CES; /* console entry switches */ +int32 ACC, EXT; /* accumulator and extension */ +int32 ARF; /* arithmetic factor, a non-addressable internal CPU register */ +int32 RUNMODE; /* processor run/step mode */ +int32 ipl = -1; /* current interrupt level (-1 = not handling irq) */ +int32 iplpending = 0; /* interrupted IPL's */ +int32 tbit = 0; /* trace flag (causes level 5 IRQ after each instr) */ +int32 V = 0, C = 0; /* condition codes */ +int32 wait_state = 0; /* wait state (waiting for an IRQ) */ +int32 wait_lamp = TRUE; /* alternate indicator to light the wait lamp on the GUI */ +int32 int_req = 0; /* sum of interrupt request levels active */ +int32 int_lamps = 0; /* accumulated version of int_req - gives lamp persistence */ +int32 int_mask; /* current active interrupt mask (ipl sensitive) */ +int32 mem_mask; /* mask for memory address bits based on current memory size */ +int32 cpu_dsw = 0; /* CPU device status word */ +int32 ibkpt_addr = -1; /* breakpoint addr */ +t_bool sim_gui = TRUE; /* enable gui */ +t_bool running = FALSE; /* TRUE if CPU is running */ +t_bool power = TRUE; /* TRUE if CPU power is on */ +t_bool cgi = FALSE; /* TRUE if we are running as a CGI program */ +t_bool cgiwritable = FALSE; /* TRUE if we can write the disk images back to the image file in CGI mode */ +t_bool is_1800 = FALSE; /* TRUE if we are simulating an IBM 1800 processor */ +t_stat reason; /* CPU execution loop control */ static int32 int_masks[6] = { - 0x00, 0x20, 0x30, 0x38, 0x3C, 0x3E /* IPL 0 is highest prio (sees no other interrupts) */ + 0x00, 0x20, 0x30, 0x38, 0x3C, 0x3E /* IPL 0 is highest prio (sees no other interrupts) */ }; /* ------------------------------------------------------------------------ @@ -233,20 +233,20 @@ extern t_stat ts_wr (int32 data, int32 addr, int32 access); extern UNIT cr_unit, prt_unit[]; #ifdef ENABLE_BACKTRACE - static void archive_backtrace(const char *inst); - static void reset_backtrace (void); - static void show_backtrace (int nshow); - static t_stat backtrace_cmd (int32 flag, CONST char *cptr); + static void archive_backtrace(const char *inst); + static void reset_backtrace (void); + static void show_backtrace (int nshow); + static t_stat backtrace_cmd (int32 flag, CONST char *cptr); #else - #define archive_backtrace(inst) - #define reset_backtrace() - #define show_backtrace(ntrace) + #define archive_backtrace(inst) + #define reset_backtrace() + #define show_backtrace(ntrace) #endif #ifdef GUI_SUPPORT -# define ARFSET(v) ARF = (v) & 0xFFFF /* set Arithmetic Factor Register (used for display purposes only) */ +# define ARFSET(v) ARF = (v) & 0xFFFF /* set Arithmetic Factor Register (used for display purposes only) */ #else -# define ARFSET(v) /* without GUI, no need for setting ARF */ +# define ARFSET(v) /* without GUI, no need for setting ARF */ #endif static void init_console_window (void); @@ -259,20 +259,20 @@ static void trace_instruction (void); /* ------------------------------------------------------------------------ * CPU data structures: - * cpu_dev CPU device descriptor - * cpu_unit CPU unit descriptor - * cpu_reg CPU register list - * cpu_mod CPU modifier list + * cpu_dev CPU device descriptor + * cpu_unit CPU unit descriptor + * cpu_reg CPU register list + * cpu_mod CPU modifier list * * The CPU is attachable; attaching a file to it write a log of instructions * and registers * ------------------------------------------------------------------------ */ -#define UNIT_MSIZE (1 << (UNIT_V_UF + 7)) /* flag for memory size setting */ -#define UNIT_1800 (1 << (UNIT_V_UF + 8)) /* flag for 1800 mode */ -#define UNIT_TRACE (3 << (UNIT_V_UF + 9)) /* debugging tracing mode bits */ +#define UNIT_MSIZE (1 << (UNIT_V_UF + 7)) /* flag for memory size setting */ +#define UNIT_1800 (1 << (UNIT_V_UF + 8)) /* flag for 1800 mode */ +#define UNIT_TRACE (3 << (UNIT_V_UF + 9)) /* debugging tracing mode bits */ -#define UNIT_TRACE_NONE 0 +#define UNIT_TRACE_NONE 0 #define UNIT_TRACE_IO (1 << (UNIT_V_UF+9)) #define UNIT_TRACE_INSTR (2 << (UNIT_V_UF+9)) #define UNIT_TRACE_BOTH (3 << (UNIT_V_UF+9)) @@ -280,59 +280,59 @@ static void trace_instruction (void); UNIT cpu_unit = { UDATA (&cpu_svc, UNIT_FIX | UNIT_BINK | UNIT_ATTABLE | UNIT_SEQ | UNIT_TRACE_BOTH, INIMEMSIZE) }; REG cpu_reg[] = { - { HRDATA (IAR, IAR, 32) }, - { HRDATA (ACC, ACC, 32) }, - { HRDATA (EXT, EXT, 32) }, - { FLDATA (Oflow, V, 1) }, - { FLDATA (Carry, C, 1) }, - { HRDATA (CES, CES, 32) }, - { HRDATA (ipl, ipl, 32), REG_RO }, - { HRDATA (iplpending, iplpending, 32), REG_RO }, - { HRDATA (wait_state, wait_state, 32)}, - { HRDATA (DSW, cpu_dsw, 32), REG_RO }, - { HRDATA (RUNMODE, RUNMODE, 32) }, - { HRDATA (BREAK, ibkpt_addr, 32) }, - { ORDATA (WRU, sim_int_char, 8) }, - { FLDATA (IntRun, tbit, 1) }, + { HRDATA (IAR, IAR, 32) }, + { HRDATA (ACC, ACC, 32) }, + { HRDATA (EXT, EXT, 32) }, + { FLDATA (Oflow, V, 1) }, + { FLDATA (Carry, C, 1) }, + { HRDATA (CES, CES, 32) }, + { HRDATA (ipl, ipl, 32), REG_RO }, + { HRDATA (iplpending, iplpending, 32), REG_RO }, + { HRDATA (wait_state, wait_state, 32)}, + { HRDATA (DSW, cpu_dsw, 32), REG_RO }, + { HRDATA (RUNMODE, RUNMODE, 32) }, + { HRDATA (BREAK, ibkpt_addr, 32) }, + { ORDATA (WRU, sim_int_char, 8) }, + { FLDATA (IntRun, tbit, 1) }, - { HRDATA (ILSW0, ILSW[0], 32), REG_RO }, - { HRDATA (ILSW1, ILSW[1], 32), REG_RO }, - { HRDATA (ILSW2, ILSW[2], 32), REG_RO }, - { HRDATA (ILSW3, ILSW[3], 32), REG_RO }, - { HRDATA (ILSW4, ILSW[4], 32), REG_RO }, - { HRDATA (ILSW5, ILSW[5], 32), REG_RO }, + { HRDATA (ILSW0, ILSW[0], 32), REG_RO }, + { HRDATA (ILSW1, ILSW[1], 32), REG_RO }, + { HRDATA (ILSW2, ILSW[2], 32), REG_RO }, + { HRDATA (ILSW3, ILSW[3], 32), REG_RO }, + { HRDATA (ILSW4, ILSW[4], 32), REG_RO }, + { HRDATA (ILSW5, ILSW[5], 32), REG_RO }, #ifdef ENABLE_1800_SUPPORT - { HRDATA (IS_1800, is_1800, 32), REG_RO|REG_HIDDEN}, /* is_1800 flag is part of state, but hidden */ - { HRDATA (XR1, XR[0], 16), REG_RO|REG_HIDDEN}, /* index registers are unhidden if CPU set to 1800 mode */ - { HRDATA (XR2, XR[1], 16), REG_RO|REG_HIDDEN}, - { HRDATA (XR3, XR[2], 16), REG_RO|REG_HIDDEN}, + { HRDATA (IS_1800, is_1800, 32), REG_RO|REG_HIDDEN}, /* is_1800 flag is part of state, but hidden */ + { HRDATA (XR1, XR[0], 16), REG_RO|REG_HIDDEN}, /* index registers are unhidden if CPU set to 1800 mode */ + { HRDATA (XR2, XR[1], 16), REG_RO|REG_HIDDEN}, + { HRDATA (XR3, XR[2], 16), REG_RO|REG_HIDDEN}, #endif - { HRDATA (ARF, ARF, 32) }, - { NULL} + { HRDATA (ARF, ARF, 32) }, + { NULL} }; MTAB cpu_mod[] = { - { UNIT_MSIZE, 4096, NULL, "4KW", &cpu_set_size}, - { UNIT_MSIZE, 8192, NULL, "8KW", &cpu_set_size}, - { UNIT_MSIZE, 16384, NULL, "16KW", &cpu_set_size}, - { UNIT_MSIZE, 32768, NULL, "32KW", &cpu_set_size}, + { UNIT_MSIZE, 4096, NULL, "4KW", &cpu_set_size}, + { UNIT_MSIZE, 8192, NULL, "8KW", &cpu_set_size}, + { UNIT_MSIZE, 16384, NULL, "16KW", &cpu_set_size}, + { UNIT_MSIZE, 32768, NULL, "32KW", &cpu_set_size}, #ifdef ENABLE_1800_SUPPORT - { UNIT_1800, 0, "1130", "1130", &cpu_set_type}, - { UNIT_1800, UNIT_1800, "1800", "1800", &cpu_set_type}, -#endif - { UNIT_TRACE, UNIT_TRACE_NONE, "notrace", "NOTRACE", NULL}, - { UNIT_TRACE, UNIT_TRACE_IO, "traceIO", "TRACEIO", NULL}, - { UNIT_TRACE, UNIT_TRACE_INSTR, "traceInstr", "TRACEINSTR", NULL}, - { UNIT_TRACE, UNIT_TRACE_BOTH, "traceBoth", "TRACEBOTH", NULL}, - { 0 } }; + { UNIT_1800, 0, "1130", "1130", &cpu_set_type}, + { UNIT_1800, UNIT_1800, "1800", "1800", &cpu_set_type}, +#endif + { UNIT_TRACE, UNIT_TRACE_NONE, "notrace", "NOTRACE", NULL}, + { UNIT_TRACE, UNIT_TRACE_IO, "traceIO", "TRACEIO", NULL}, + { UNIT_TRACE, UNIT_TRACE_INSTR, "traceInstr", "TRACEINSTR", NULL}, + { UNIT_TRACE, UNIT_TRACE_BOTH, "traceBoth", "TRACEBOTH", NULL}, + { 0 } }; DEVICE cpu_dev = { - "CPU", &cpu_unit, cpu_reg, cpu_mod, - 1, 16, 16, 1, 16, 16, - &cpu_ex, &cpu_dep, &cpu_reset, - NULL, cpu_attach, NULL}; /* attaching to CPU creates cpu log file */ + "CPU", &cpu_unit, cpu_reg, cpu_mod, + 1, 16, 16, 1, 16, 16, + &cpu_ex, &cpu_dep, &cpu_reset, + NULL, cpu_attach, NULL}; /* attaching to CPU creates cpu log file */ /* ------------------------------------------------------------------------ * Memory read/write -- save SAR and SBR on the way in and out @@ -346,16 +346,16 @@ DEVICE cpu_dev = { int32 ReadW (int32 a) { - SAR = a; - SBR = (int32) M[(a) & mem_mask]; - return SBR; + SAR = a; + SBR = (int32) M[(a) & mem_mask]; + return SBR; } void WriteW (int32 a, int32 d) { - SAR = a; - SBR = d; - M[a & mem_mask] = (int16) d; + SAR = a; + SBR = d; + M[a & mem_mask] = (int16) d; } /* ------------------------------------------------------------------------ @@ -366,27 +366,27 @@ void WriteW (int32 a, int32 d) static uint16 ReadIndex (int32 tag) { #ifdef ENABLE_1800_SUPPORT - if (is_1800) - return XR[tag-1]; /* 1800: fetch from register */ + if (is_1800) + return XR[tag-1]; /* 1800: fetch from register */ #endif - - SAR = tag; /* 1130: ordinary read from memory (like ReadW) */ - SBR = (int32) M[(tag) & mem_mask]; - return SBR; + + SAR = tag; /* 1130: ordinary read from memory (like ReadW) */ + SBR = (int32) M[(tag) & mem_mask]; + return SBR; } static void WriteIndex (int32 tag, int32 d) { #ifdef ENABLE_1800_SUPPORT - if (is_1800) { - XR[tag-1] = d; /* 1800: store in register */ - return; - } + if (is_1800) { + XR[tag-1] = d; /* 1800: store in register */ + return; + } #endif - SAR = tag; /* 1130: ordinary write to memory (same as WriteW) */ - SBR = d; - M[tag & mem_mask] = (int16) d; + SAR = tag; /* 1130: ordinary write to memory (same as WriteW) */ + SBR = d; + M[tag & mem_mask] = (int16) d; } /* ------------------------------------------------------------------------ @@ -395,14 +395,14 @@ static void WriteIndex (int32 tag, int32 d) char *upcase (char *str) { - char *s; + char *s; - for (s = str; *s; s++) { - if (*s >= 'a' && *s <= 'z') - *s -= 32; - } + for (s = str; *s; s++) { + if (*s >= 'a' && *s <= 'z') + *s -= 32; + } - return str; + return str; } /* ------------------------------------------------------------------------ @@ -411,37 +411,37 @@ char *upcase (char *str) * int_req: * bit 5 4 3 2 1 0 * \ \ \ \ \ \ - * \ \ \ \ \ interrupt level 5 pending (lowest priority) + * \ \ \ \ \ interrupt level 5 pending (lowest priority) * \ . . . * interrupt level 0 pending (highest priority) * * int_mask is set according to current interrupt level (ipl) * - * 0 0 0 0 0 0 ipl = 0 (currently servicing highest priority interrupt) - * 1 0 0 0 0 0 1 - * 1 1 0 0 0 0 2 - * 1 1 1 0 0 0 3 - * 1 1 1 1 0 0 4 - * 1 1 1 1 1 0 5 (currently servicing lowest priority interrupt) - * 1 1 1 1 1 1 -1 (not servicing an interrupt) + * 0 0 0 0 0 0 ipl = 0 (currently servicing highest priority interrupt) + * 1 0 0 0 0 0 1 + * 1 1 0 0 0 0 2 + * 1 1 1 0 0 0 3 + * 1 1 1 1 0 0 4 + * 1 1 1 1 1 0 5 (currently servicing lowest priority interrupt) + * 1 1 1 1 1 1 -1 (not servicing an interrupt) * ------------------------------------------------------------------------ */ void calc_ints (void) { - register int i; - register int32 newbits = 0; + register int i; + register int32 newbits = 0; - GUI_BEGIN_CRITICAL_SECTION /* using critical section here so we don't mislead the GUI thread */ + GUI_BEGIN_CRITICAL_SECTION /* using critical section here so we don't mislead the GUI thread */ - for (i = 6; --i >= 0; ) { - newbits >>= 1; - if (ILSW[i]) - newbits |= 0x20; - } + for (i = 6; --i >= 0; ) { + newbits >>= 1; + if (ILSW[i]) + newbits |= 0x20; + } - int_req = newbits; - int_lamps |= int_req; - int_mask = (ipl < 0) ? 0xFFFF : int_masks[ipl]; /* be sure this is set correctly */ + int_req = newbits; + int_lamps |= int_req; + int_mask = (ipl < 0) ? 0xFFFF : int_masks[ipl]; /* be sure this is set correctly */ GUI_END_CRITICAL_SECTION } @@ -450,756 +450,756 @@ void calc_ints (void) * instruction processor * ------------------------------------------------------------------------ */ -#define INCREMENT_IAR IAR = (IAR + 1) & mem_mask +#define INCREMENT_IAR IAR = (IAR + 1) & mem_mask void bail (const char *msg) { - printf("%s\n", msg); - exit(1); + printf("%s\n", msg); + exit(1); } static void weirdop (const char *msg) { - printf("Weird opcode: %s at %04x\n", msg, IAR-1); + printf("Weird opcode: %s at %04x\n", msg, IAR-1); } static const char *xio_devs[] = { - "dev-00?", "console", "1442card", "1134ptape", - "dsk0", "1627plot", "1132print", "switches", - "1231omr", "2501card", "sca", "dev-0b?", - "sys7", "dev-0d?", "dev-0e?", "dev-0f?", - "dev-10?", "dsk1", "dsk2", "dsk3", - "dsk4", "1403prt", "dsk5", "2311drv2", - "dev-18?", "2250disp", "2741term", "dev-1b", - "dev-1c?", "dev-1d?", "dev-1e?", "dev-1f?" + "dev-00?", "console", "1442card", "1134ptape", + "dsk0", "1627plot", "1132print", "switches", + "1231omr", "2501card", "sca", "dev-0b?", + "sys7", "dev-0d?", "dev-0e?", "dev-0f?", + "dev-10?", "dsk1", "dsk2", "dsk3", + "dsk4", "1403prt", "dsk5", "2311drv2", + "dev-18?", "2250disp", "2741term", "dev-1b", + "dev-1c?", "dev-1d?", "dev-1e?", "dev-1f?" }; static const char *xio_funcs[] = { - "func0?", "write", "read", "sense_irq", - "control", "initw", "initr", "sense" + "func0?", "write", "read", "sense_irq", + "control", "initw", "initr", "sense" }; t_stat sim_instr (void) { - int32 i, eaddr, INDIR, IR, F, DSPLC, word2, oldval, newval, src, src2, dst, abit, xbit; - int32 iocc_addr, iocc_op, iocc_dev, iocc_func, iocc_mod, result; - char msg[50]; - int cwincount = 0, status; - static long ninstr = 0; - static const char *intlabel[] = {"INT0","INT1","INT2","INT3","INT4","INT5"}; + int32 i, eaddr, INDIR, IR, F, DSPLC, word2, oldval, newval, src, src2, dst, abit, xbit; + int32 iocc_addr, iocc_op, iocc_dev, iocc_func, iocc_mod, result; + char msg[50]; + int cwincount = 0, status; + static long ninstr = 0; + static const char *intlabel[] = {"INT0","INT1","INT2","INT3","INT4","INT5"}; - /* the F bit indicates a two-word instruction for most instructions except the ones marked FALSE below */ - static t_bool F_bit_used[] = { /* FALSE for those few instructions that don't have a long instr version */ - /*undef XIO SLx SRx LDS STS WAIT undef */ - FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, - /*BSI BSC undef undef LDX STX MDX undef */ - TRUE, TRUE, FALSE, FALSE, TRUE, TRUE, TRUE, FALSE, - /*A AD S SD M D CPU dependent */ - TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, - /*LD LDD STO STD AND OR EOR undef */ - TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE - }; + /* the F bit indicates a two-word instruction for most instructions except the ones marked FALSE below */ + static t_bool F_bit_used[] = { /* FALSE for those few instructions that don't have a long instr version */ + /*undef XIO SLx SRx LDS STS WAIT undef */ + FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, + /*BSI BSC undef undef LDX STX MDX undef */ + TRUE, TRUE, FALSE, FALSE, TRUE, TRUE, TRUE, FALSE, + /*A AD S SD M D CPU dependent */ + TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, + /*LD LDD STO STD AND OR EOR undef */ + TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE + }; #ifdef ENABLE_1800_SUPPORT - F_bit_used[0x16] = is_1800; /* these two are defined and do have long versions on the 1800 */ - F_bit_used[0x17] = is_1800; /* but are undefined on the 1130, so set these accordingly */ + F_bit_used[0x16] = is_1800; /* these two are defined and do have long versions on the 1800 */ + F_bit_used[0x17] = is_1800; /* but are undefined on the 1130, so set these accordingly */ #endif - if (cgi) /* give CGI hook function a chance to do something */ - cgi_start(); + if (cgi) /* give CGI hook function a chance to do something */ + cgi_start(); - if (running) /* this is definitely not reentrant */ - return -1; + if (running) /* this is definitely not reentrant */ + return -1; - if (! power) /* this matters only to the GUI */ - return STOP_POWER_OFF; + if (! power) /* this matters only to the GUI */ + return STOP_POWER_OFF; - running = TRUE; + running = TRUE; - mem_mask = MEMSIZE - 1; /* set other useful variables */ - calc_ints(); + mem_mask = MEMSIZE - 1; /* set other useful variables */ + calc_ints(); - /* Main instruction fetch/decode loop */ + /* Main instruction fetch/decode loop */ - reason = 0; - wait_lamp = 0; /* release lock on wait lamp */ + reason = 0; + wait_lamp = 0; /* release lock on wait lamp */ #ifdef GUI_SUPPORT - update_gui(TRUE); - gui_run(TRUE); + update_gui(TRUE); + gui_run(TRUE); #endif - while (reason == 0) { - IAR &= mem_mask; + while (reason == 0) { + IAR &= mem_mask; #ifdef GUI_SUPPORT #ifndef UPDATE_BY_TIMER #if (UPDATE_INTERVAL > 0) - if (--cwincount <= 0) { - update_gui(FALSE); /* update console lamps only every so many instructions */ - cwincount = UPDATE_INTERVAL + (rand() % MIN(UPDATE_INTERVAL, 32)); - } + if (--cwincount <= 0) { + update_gui(FALSE); /* update console lamps only every so many instructions */ + cwincount = UPDATE_INTERVAL + (rand() % MIN(UPDATE_INTERVAL, 32)); + } #else - update_gui(FALSE); + update_gui(FALSE); #endif /* ifdef UPDATE_INTERVAL */ #endif /* ifndef UPDATE_BY_TIMER */ #endif /* ifdef GUI_SUPPORT */ - if (sim_interval <= 0) { /* any events timed out? */ - if (sim_clock_queue != QUEUE_LIST_END) { - if ((status = sim_process_event()) != 0) - reason = simh_status_to_stopcode(status); + if (sim_interval <= 0) { /* any events timed out? */ + if (sim_clock_queue != QUEUE_LIST_END) { + if ((status = sim_process_event()) != 0) + reason = simh_status_to_stopcode(status); - calc_ints(); - continue; - } - } + calc_ints(); + continue; + } + } - if (int_req & int_mask) { /* any pending interrupts? */ - for (i = 0; i <= 5; i++) /* find highest pending interrupt */ - if ((int_req & int_mask) & (0x20 >> i)) - break; + if (int_req & int_mask) { /* any pending interrupts? */ + for (i = 0; i <= 5; i++) /* find highest pending interrupt */ + if ((int_req & int_mask) & (0x20 >> i)) + break; - if (i >= 6) { /* nothing to do? */ - calc_ints(); /* weird. recalculate */ - continue; /* back to fetch */ - } + if (i >= 6) { /* nothing to do? */ + calc_ints(); /* weird. recalculate */ + continue; /* back to fetch */ + } - GUI_BEGIN_CRITICAL_SECTION + GUI_BEGIN_CRITICAL_SECTION - if (ipl >= 0) /* save previous IPL in bit stack */ - iplpending |= (0x20 >> ipl); + if (ipl >= 0) /* save previous IPL in bit stack */ + iplpending |= (0x20 >> ipl); - ipl = i; /* set new interrupt level */ - int_mask = int_masks[i]; /* set appropriate mask */ + ipl = i; /* set new interrupt level */ + int_mask = int_masks[i]; /* set appropriate mask */ - GUI_END_CRITICAL_SECTION + GUI_END_CRITICAL_SECTION - wait_state = 0; /* exit wait state */ - eaddr = ReadW(8+i); /* get IRQ vector */ - archive_backtrace(intlabel[i]); - WriteW(eaddr, IAR); /* save IAR */ - IAR = (eaddr+1) & mem_mask; /* go to next address */ - continue; /* now continue processing */ - } /* end if int_req */ + wait_state = 0; /* exit wait state */ + eaddr = ReadW(8+i); /* get IRQ vector */ + archive_backtrace(intlabel[i]); + WriteW(eaddr, IAR); /* save IAR */ + IAR = (eaddr+1) & mem_mask; /* go to next address */ + continue; /* now continue processing */ + } /* end if int_req */ - if (wait_state) { /* waiting? */ - sim_interval = 0; /* run the clock out */ + if (wait_state) { /* waiting? */ + sim_interval = 0; /* run the clock out */ - if (sim_qcount() <= (cgi ? 0 : 1)) { /* one routine queued? we're waiting for keyboard only */ - if (keyboard_is_busy()) { /* we are actually waiting for a keystroke */ - if ((status = sim_process_event()) != SCPE_OK) /* get it with wait_state still set */ - reason = simh_status_to_stopcode(status); - } - else { /* CPU is not expecting a keystroke (keyboard interrupt) */ - if (wait_state == WAIT_OP) - reason = STOP_WAIT; /* end the simulation */ - else - reason = STOP_INVALID_INSTR; - } - } + if (sim_qcount() <= (cgi ? 0 : 1)) { /* one routine queued? we're waiting for keyboard only */ + if (keyboard_is_busy()) { /* we are actually waiting for a keystroke */ + if ((status = sim_process_event()) != SCPE_OK) /* get it with wait_state still set */ + reason = simh_status_to_stopcode(status); + } + else { /* CPU is not expecting a keystroke (keyboard interrupt) */ + if (wait_state == WAIT_OP) + reason = STOP_WAIT; /* end the simulation */ + else + reason = STOP_INVALID_INSTR; + } + } - if (gdu_active()) /* but don't stop simulator if 2250 GDU is running */ - reason = 0; + if (gdu_active()) /* but don't stop simulator if 2250 GDU is running */ + reason = 0; - continue; - } + continue; + } - if (IAR == ibkpt_addr) { /* simulator breakpoint? */ - save_ibkpt = ibkpt_addr; /* save bkpt */ - ibkpt_addr = ibkpt_addr | ILL_ADR_FLAG; /* disable */ - sim_activate(&cpu_unit, 1); /* sched re-enable after next instruction */ - reason = STOP_IBKPT; /* stop simulation */ - cwincount = 0; - continue; - } + if (IAR == ibkpt_addr) { /* simulator breakpoint? */ + save_ibkpt = ibkpt_addr; /* save bkpt */ + ibkpt_addr = ibkpt_addr | ILL_ADR_FLAG; /* disable */ + sim_activate(&cpu_unit, 1); /* sched re-enable after next instruction */ + reason = STOP_IBKPT; /* stop simulation */ + cwincount = 0; + continue; + } - ninstr++; - if ((cpu_unit.flags & (UNIT_ATT|UNIT_TRACE_INSTR)) == (UNIT_ATT|UNIT_TRACE_INSTR)) - trace_instruction(); /* log CPU details if logging is enabled */ + ninstr++; + if ((cpu_unit.flags & (UNIT_ATT|UNIT_TRACE_INSTR)) == (UNIT_ATT|UNIT_TRACE_INSTR)) + trace_instruction(); /* log CPU details if logging is enabled */ - prev_IAR = IAR; /* save IAR before incrementing it */ + prev_IAR = IAR; /* save IAR before incrementing it */ - IR = ReadW(IAR); /* fetch 1st word of instruction */ - INCREMENT_IAR; - sim_interval = sim_interval - 1; /* this constitutes one tick of the simulation clock */ + IR = ReadW(IAR); /* fetch 1st word of instruction */ + INCREMENT_IAR; + sim_interval = sim_interval - 1; /* this constitutes one tick of the simulation clock */ - OP = (IR >> 11) & 0x1F; /* opcode */ - F = IR & 0x0400; /* format bit: 1 = long instr */ - TAG = IR & 0x0300; /* tag bits: index reg x */ - if (TAG) - TAG >>= 8; + OP = (IR >> 11) & 0x1F; /* opcode */ + F = IR & 0x0400; /* format bit: 1 = long instr */ + TAG = IR & 0x0300; /* tag bits: index reg x */ + if (TAG) + TAG >>= 8; - /* here I compute the usual effective address on the assumption that the instruction will need it. Some don't. */ + /* here I compute the usual effective address on the assumption that the instruction will need it. Some don't. */ - if (F && F_bit_used[OP]) { /* long instruction, except for a few that don't have a long mode, like WAIT */ - INDIR = IR & 0x0080; /* indirect bit */ - DSPLC = IR & 0x007F; /* displacement or modifier */ - if (DSPLC & 0x0040) - DSPLC |= ~ 0x7F; /* sign extend */ + if (F && F_bit_used[OP]) { /* long instruction, except for a few that don't have a long mode, like WAIT */ + INDIR = IR & 0x0080; /* indirect bit */ + DSPLC = IR & 0x007F; /* displacement or modifier */ + if (DSPLC & 0x0040) + DSPLC |= ~ 0x7F; /* sign extend */ - word2 = ReadW(IAR); /* get reference address */ - INCREMENT_IAR; /* bump the instruction address register */ + word2 = ReadW(IAR); /* get reference address */ + INCREMENT_IAR; /* bump the instruction address register */ - eaddr = word2; /* assume standard addressing & compute effective address */ - if (TAG) /* if indexed */ - eaddr += ReadIndex(TAG); /* add index register value */ - if (INDIR) /* if indirect addressing */ - eaddr = ReadW(eaddr); /* pick up referenced address */ - - /* to do: the previous steps may lead to incorrect GUI SAR/SBR display if the instruction doesn't actually fetch anything. Check this. */ - } - else { /* short instruction, use displacement */ - INDIR = 0; /* never indirect */ - DSPLC = IR & 0x00FF; /* get displacement */ - if (DSPLC & 0x0080) - DSPLC |= ~ 0xFF; + eaddr = word2; /* assume standard addressing & compute effective address */ + if (TAG) /* if indexed */ + eaddr += ReadIndex(TAG); /* add index register value */ + if (INDIR) /* if indirect addressing */ + eaddr = ReadW(eaddr); /* pick up referenced address */ + + /* to do: the previous steps may lead to incorrect GUI SAR/SBR display if the instruction doesn't actually fetch anything. Check this. */ + } + else { /* short instruction, use displacement */ + INDIR = 0; /* never indirect */ + DSPLC = IR & 0x00FF; /* get displacement */ + if (DSPLC & 0x0080) + DSPLC |= ~ 0xFF; - if (TAG) /* if indexed */ - eaddr = ReadIndex(TAG) + DSPLC; /* add index register value */ - else - eaddr = IAR + DSPLC; /* otherwise relative to IAR after fetch */ + if (TAG) /* if indexed */ + eaddr = ReadIndex(TAG) + DSPLC; /* add index register value */ + else + eaddr = IAR + DSPLC; /* otherwise relative to IAR after fetch */ - /* to do: the previous steps may lead to incorrect GUI SAR/SBR display if the instruction doesn't actually fetch the index value. Check this. */ - } + /* to do: the previous steps may lead to incorrect GUI SAR/SBR display if the instruction doesn't actually fetch the index value. Check this. */ + } - switch (OP) { /* decode instruction */ - case 0x01: /* --- XIO --- */ - iocc_addr = ReadW(eaddr); /* get IOCC packet */ - iocc_op = ReadW(eaddr|1); /* note 'or' not plus, address must be even for proper operation */ + switch (OP) { /* decode instruction */ + case 0x01: /* --- XIO --- */ + iocc_addr = ReadW(eaddr); /* get IOCC packet */ + iocc_op = ReadW(eaddr|1); /* note 'or' not plus, address must be even for proper operation */ - iocc_dev = (iocc_op >> 11) & 0x001F; - iocc_func = (iocc_op >> 8) & 0x0007; - iocc_mod = iocc_op & 0x00FF; + iocc_dev = (iocc_op >> 11) & 0x001F; + iocc_func = (iocc_op >> 8) & 0x0007; + iocc_mod = iocc_op & 0x00FF; - if ((cpu_unit.flags & (UNIT_ATT|UNIT_TRACE_IO)) == (UNIT_ATT|UNIT_TRACE_IO)) - trace_io("* XIO %s %s mod %02x addr %04x", xio_funcs[iocc_func], (iocc_func == XIO_SENSE_IRQ) ? "-" : xio_devs[iocc_dev], iocc_mod, iocc_addr); + if ((cpu_unit.flags & (UNIT_ATT|UNIT_TRACE_IO)) == (UNIT_ATT|UNIT_TRACE_IO)) + trace_io("* XIO %s %s mod %02x addr %04x", xio_funcs[iocc_func], (iocc_func == XIO_SENSE_IRQ) ? "-" : xio_devs[iocc_dev], iocc_mod, iocc_addr); - ACC = 0; /* ACC is destroyed, and default XIO_SENSE_DEV result is 0 */ + ACC = 0; /* ACC is destroyed, and default XIO_SENSE_DEV result is 0 */ - switch (iocc_func) { - case XIO_UNUSED: - sprintf(msg, "Unknown XIO op %x on device %02x (%s)", iocc_func, iocc_dev, xio_devs[iocc_dev]); - xio_error(msg); - break; - - case XIO_SENSE_IRQ: /* examine current Interrupt Level Status Word */ - ACC = (ipl >= 0) ? ILSW[ipl] : 0; - break; - - default: /* perform device-specific operation */ - switch (iocc_dev) { - case 0x01: /* console keyboard and printer */ - xio_1131_console(iocc_addr, iocc_func, iocc_mod); - break; - case 0x02: /* 1442 card reader/punch */ - xio_1442_card(iocc_addr, iocc_func, iocc_mod); - break; - case 0x03: /* 1134 paper tape reader/punch */ - xio_1134_papertape(iocc_addr, iocc_func, iocc_mod); - break; - case 0x04: /* CPU disk storage */ - xio_disk(iocc_addr, iocc_func, iocc_mod, 0); - break; - case 0x05: /* 1627 plotter */ - xio_1627_plotter(iocc_addr, iocc_func, iocc_mod); - break; - case 0x06: /* 1132 Printer */ - xio_1132_printer(iocc_addr, iocc_func, iocc_mod); - break; - case 0x07: /* console switches, stop key, run mode */ - xio_1131_switches(iocc_addr, iocc_func, iocc_mod); - break; - case 0x08: /* 1231 optical mark reader */ - xio_1231_optical(iocc_addr, iocc_func, iocc_mod); - break; - case 0x09: /* 2501 card reader */ - xio_2501_card(iocc_addr, iocc_func, iocc_mod); - break; - case 0x0a: /* synchronous comm adapter */ - xio_sca(iocc_addr, iocc_func, iocc_mod); - break; - case 0x0c: /* IBM System/7 interprocessor link */ - xio_system7(iocc_addr, iocc_func, iocc_mod); - break; - case 0x11: /* 2310 Disk Storage, Drive 1, or 2311 Disk Storage Drive. Drive 1, Disk 1 */ - xio_disk(iocc_addr, iocc_func, iocc_mod, 1); - break; - case 0x12: /* 2310 Disk Storage, Drive 2, or 2311 Disk Storage Drive. Drive 1, Disk 2 */ - xio_disk(iocc_addr, iocc_func, iocc_mod, 2); - break; - case 0x13: /* 2310 Disk Storage, Drive 3, or 2311 Disk Storage Drive. Drive 1, Disk 3 */ - xio_disk(iocc_addr, iocc_func, iocc_mod, 3); - break; - case 0x14: /* 2310 Disk Storage, Drive 4, or 2311 Disk Storage Drive. Drive 1, Disk 4 */ - xio_disk(iocc_addr, iocc_func, iocc_mod, 4); - break; - case 0x15: /* 1403 Printer */ - xio_1403_printer(iocc_addr, iocc_func, iocc_mod); - break; - case 0x16: /* 2311 Disk Storage Drive. Drive 1, Disk 5 */ - xio_disk(iocc_addr, iocc_func, iocc_mod, -1); - break; - case 0x17: /* 2311 Disk Storage Drive, Drive 2, Disk 1 through 5 */ - xio_disk(iocc_addr, iocc_func, iocc_mod, -1); - break; - case 0x19: /* 2250 Display Unit */ - xio_2250_display(iocc_addr, iocc_func, iocc_mod); - break; - case 0x1a: /* 2741 Attachment (nonstandard serial interface used by APL\1130 */ - xio_t2741_terminal(iocc_addr, iocc_func, iocc_mod); - break; - default: - sprintf(msg, "unknown device %02x", iocc_dev); - xio_error(msg); - break; - } - } + switch (iocc_func) { + case XIO_UNUSED: + sprintf(msg, "Unknown XIO op %x on device %02x (%s)", iocc_func, iocc_dev, xio_devs[iocc_dev]); + xio_error(msg); + break; + + case XIO_SENSE_IRQ: /* examine current Interrupt Level Status Word */ + ACC = (ipl >= 0) ? ILSW[ipl] : 0; + break; + + default: /* perform device-specific operation */ + switch (iocc_dev) { + case 0x01: /* console keyboard and printer */ + xio_1131_console(iocc_addr, iocc_func, iocc_mod); + break; + case 0x02: /* 1442 card reader/punch */ + xio_1442_card(iocc_addr, iocc_func, iocc_mod); + break; + case 0x03: /* 1134 paper tape reader/punch */ + xio_1134_papertape(iocc_addr, iocc_func, iocc_mod); + break; + case 0x04: /* CPU disk storage */ + xio_disk(iocc_addr, iocc_func, iocc_mod, 0); + break; + case 0x05: /* 1627 plotter */ + xio_1627_plotter(iocc_addr, iocc_func, iocc_mod); + break; + case 0x06: /* 1132 Printer */ + xio_1132_printer(iocc_addr, iocc_func, iocc_mod); + break; + case 0x07: /* console switches, stop key, run mode */ + xio_1131_switches(iocc_addr, iocc_func, iocc_mod); + break; + case 0x08: /* 1231 optical mark reader */ + xio_1231_optical(iocc_addr, iocc_func, iocc_mod); + break; + case 0x09: /* 2501 card reader */ + xio_2501_card(iocc_addr, iocc_func, iocc_mod); + break; + case 0x0a: /* synchronous comm adapter */ + xio_sca(iocc_addr, iocc_func, iocc_mod); + break; + case 0x0c: /* IBM System/7 interprocessor link */ + xio_system7(iocc_addr, iocc_func, iocc_mod); + break; + case 0x11: /* 2310 Disk Storage, Drive 1, or 2311 Disk Storage Drive. Drive 1, Disk 1 */ + xio_disk(iocc_addr, iocc_func, iocc_mod, 1); + break; + case 0x12: /* 2310 Disk Storage, Drive 2, or 2311 Disk Storage Drive. Drive 1, Disk 2 */ + xio_disk(iocc_addr, iocc_func, iocc_mod, 2); + break; + case 0x13: /* 2310 Disk Storage, Drive 3, or 2311 Disk Storage Drive. Drive 1, Disk 3 */ + xio_disk(iocc_addr, iocc_func, iocc_mod, 3); + break; + case 0x14: /* 2310 Disk Storage, Drive 4, or 2311 Disk Storage Drive. Drive 1, Disk 4 */ + xio_disk(iocc_addr, iocc_func, iocc_mod, 4); + break; + case 0x15: /* 1403 Printer */ + xio_1403_printer(iocc_addr, iocc_func, iocc_mod); + break; + case 0x16: /* 2311 Disk Storage Drive. Drive 1, Disk 5 */ + xio_disk(iocc_addr, iocc_func, iocc_mod, -1); + break; + case 0x17: /* 2311 Disk Storage Drive, Drive 2, Disk 1 through 5 */ + xio_disk(iocc_addr, iocc_func, iocc_mod, -1); + break; + case 0x19: /* 2250 Display Unit */ + xio_2250_display(iocc_addr, iocc_func, iocc_mod); + break; + case 0x1a: /* 2741 Attachment (nonstandard serial interface used by APL\1130 */ + xio_t2741_terminal(iocc_addr, iocc_func, iocc_mod); + break; + default: + sprintf(msg, "unknown device %02x", iocc_dev); + xio_error(msg); + break; + } + } - calc_ints(); /* after every XIO, reset int_mask just in case */ - break; + calc_ints(); /* after every XIO, reset int_mask just in case */ + break; - case 0x02: /* --- SLA,SLT,SLC,SLCA,NOP - Shift Left family --- */ - if (F) - weirdop("Long Left Shift"); + case 0x02: /* --- SLA,SLT,SLC,SLCA,NOP - Shift Left family --- */ + if (F) + weirdop("Long Left Shift"); - CCC = ((TAG == 0) ? DSPLC : ReadIndex(TAG)) & 0x003F; - ARFSET(CCC); - if (CCC == 0) - break; /* shift of zero is a NOP */ + CCC = ((TAG == 0) ? DSPLC : ReadIndex(TAG)) & 0x003F; + ARFSET(CCC); + if (CCC == 0) + break; /* shift of zero is a NOP */ - switch (IR & 0x00C0) { - case 0x0040: /* SLCA */ - if (TAG) { - while (CCC > 0 && (ACC & 0x8000) == 0) { - ACC <<= 1; - CCC--; - } - C = (CCC != 0); - WriteIndex(TAG, (ReadIndex(TAG) & 0xFF00) | CCC); /* put low 6 bits back into index register and zero bits 8 and 9 */ - break; - } - /* if TAG == 0, fall through and treat like normal shift SLA */ + switch (IR & 0x00C0) { + case 0x0040: /* SLCA */ + if (TAG) { + while (CCC > 0 && (ACC & 0x8000) == 0) { + ACC <<= 1; + CCC--; + } + C = (CCC != 0); + WriteIndex(TAG, (ReadIndex(TAG) & 0xFF00) | CCC); /* put low 6 bits back into index register and zero bits 8 and 9 */ + break; + } + /* if TAG == 0, fall through and treat like normal shift SLA */ - case 0x0000: /* SLA */ - while (CCC > 0) { - C = (ACC & 0x8000); - ACC = (ACC << 1) & 0xFFFF; - CCC--; - } - break; + case 0x0000: /* SLA */ + while (CCC > 0) { + C = (ACC & 0x8000); + ACC = (ACC << 1) & 0xFFFF; + CCC--; + } + break; - case 0x00C0: /* SLC */ - if (TAG) { - while (CCC > 0 && (ACC & 0x8000) == 0) { - abit = (EXT & 0x8000) >> 15; - ACC = ((ACC << 1) & 0xFFFF) | abit; - EXT = (EXT << 1); - CCC--; - } - C = (CCC != 0); - WriteIndex(TAG, (ReadIndex(TAG) & 0xFF00) | CCC); /* put 6 bits back into low byte of index register */ - break; - } - /* if TAG == 0, fall through and treat like normal shift SLT */ + case 0x00C0: /* SLC */ + if (TAG) { + while (CCC > 0 && (ACC & 0x8000) == 0) { + abit = (EXT & 0x8000) >> 15; + ACC = ((ACC << 1) & 0xFFFF) | abit; + EXT = (EXT << 1); + CCC--; + } + C = (CCC != 0); + WriteIndex(TAG, (ReadIndex(TAG) & 0xFF00) | CCC); /* put 6 bits back into low byte of index register */ + break; + } + /* if TAG == 0, fall through and treat like normal shift SLT */ - case 0x0080: /* SLT */ - while (CCC > 0) { - C = (ACC & 0x8000); - abit = (EXT & 0x8000) >> 15; - ACC = ((ACC << 1) & 0xFFFF) | abit; - EXT = (EXT << 1) & 0xFFFF; - CCC--; - } - break; + case 0x0080: /* SLT */ + while (CCC > 0) { + C = (ACC & 0x8000); + abit = (EXT & 0x8000) >> 15; + ACC = ((ACC << 1) & 0xFFFF) | abit; + EXT = (EXT << 1) & 0xFFFF; + CCC--; + } + break; - default: - bail("SLA switch, can't happen"); - break; - } - break; + default: + bail("SLA switch, can't happen"); + break; + } + break; - case 0x03: /* --- SRA, SRT, RTE - Shift Right family --- */ - if (F) - weirdop("Long Right Shift"); + case 0x03: /* --- SRA, SRT, RTE - Shift Right family --- */ + if (F) + weirdop("Long Right Shift"); - CCC = ((TAG == 0) ? DSPLC : ReadIndex(TAG)) & 0x3F; - ARFSET(CCC); - if (CCC == 0) - break; /* NOP */ + CCC = ((TAG == 0) ? DSPLC : ReadIndex(TAG)) & 0x3F; + ARFSET(CCC); + if (CCC == 0) + break; /* NOP */ - switch (IR & 0x00C0) { - case 0x0000: /* SRA */ - ACC = (CCC < 16) ? ((ACC & 0xFFFF) >> CCC) : 0; - CCC = 0; - break; + switch (IR & 0x00C0) { + case 0x0000: /* SRA */ + ACC = (CCC < 16) ? ((ACC & 0xFFFF) >> CCC) : 0; + CCC = 0; + break; - case 0x0040: /* invalid */ - wait_state = WAIT_INVALID_OP; - break; + case 0x0040: /* invalid */ + wait_state = WAIT_INVALID_OP; + break; - case 0x0080: /* SRT */ - while (CCC > 0) { - xbit = (ACC & 0x0001) << 15; - abit = (ACC & 0x8000); - ACC = ((ACC >> 1) & 0x7FFF) | abit; - EXT = ((EXT >> 1) & 0x7FFF) | xbit; - CCC--; - } - break; + case 0x0080: /* SRT */ + while (CCC > 0) { + xbit = (ACC & 0x0001) << 15; + abit = (ACC & 0x8000); + ACC = ((ACC >> 1) & 0x7FFF) | abit; + EXT = ((EXT >> 1) & 0x7FFF) | xbit; + CCC--; + } + break; - case 0x00C0: /* RTE */ - while (CCC > 0) { - abit = (EXT & 0x0001) << 15; - xbit = (ACC & 0x0001) << 15; - ACC = ((ACC >> 1) & 0x7FFF) | abit; - EXT = ((EXT >> 1) & 0x7FFF) | xbit; - CCC--; - } - break; + case 0x00C0: /* RTE */ + while (CCC > 0) { + abit = (EXT & 0x0001) << 15; + xbit = (ACC & 0x0001) << 15; + ACC = ((ACC >> 1) & 0x7FFF) | abit; + EXT = ((EXT >> 1) & 0x7FFF) | xbit; + CCC--; + } + break; - default: - bail("SRA switch, can't happen"); - break; - } - break; + default: + bail("SRA switch, can't happen"); + break; + } + break; - case 0x04: /* --- LDS - Load Status --- */ - if (F) /* never fetches second word? */ - weirdop("Long LDS"); + case 0x04: /* --- LDS - Load Status --- */ + if (F) /* never fetches second word? */ + weirdop("Long LDS"); - V = (DSPLC & 1); - C = (DSPLC & 2) >> 1; - break; + V = (DSPLC & 1); + C = (DSPLC & 2) >> 1; + break; - case 0x05: /* --- STS - Store Status --- */ - newval = ReadW(eaddr) & 0xFF00; - if (C) - newval |= 2; - if (V) - newval |= 1; + case 0x05: /* --- STS - Store Status --- */ + newval = ReadW(eaddr) & 0xFF00; + if (C) + newval |= 2; + if (V) + newval |= 1; - WriteW(eaddr, newval); - C = V = 0; /* clear flags after storing */ - break; + WriteW(eaddr, newval); + C = V = 0; /* clear flags after storing */ + break; - case 0x06: /* --- WAIT --- */ + case 0x06: /* --- WAIT --- */ /* I am no longer doing the fetch if a long wait is encountered * The 1130 diagnostics use WAIT instructions with the F bit set in some display error codes. * (The wait instruction's opcode is displayed in the Storage Buffer Register on the console display, * since the last thing fetched was the instruction) */ - wait_state = WAIT_OP; + wait_state = WAIT_OP; - SAR = prev_IAR; /* this is a hack; ensure that the SAR/SBR display shows the WAIT instruction fetch */ - SBR = IR; - break; + SAR = prev_IAR; /* this is a hack; ensure that the SAR/SBR display shows the WAIT instruction fetch */ + SBR = IR; + break; - case 0x08: /* --- BSI - Branch and store IAR --- */ - if (F) { - if (bsctest(IR, F)) /* do standard BSC long format testing */ - break; /* if any condition is true, do nothing */ - } - WriteW(eaddr, IAR); /* do subroutine call */ - archive_backtrace("BSI"); /* save info in back-trace buffer */ - IAR = (eaddr + 1) & mem_mask; - break; + case 0x08: /* --- BSI - Branch and store IAR --- */ + if (F) { + if (bsctest(IR, F)) /* do standard BSC long format testing */ + break; /* if any condition is true, do nothing */ + } + WriteW(eaddr, IAR); /* do subroutine call */ + archive_backtrace("BSI"); /* save info in back-trace buffer */ + IAR = (eaddr + 1) & mem_mask; + break; - case 0x09: /* --- BSC - Branch and skip on Condition --- */ - if (F) { - if (bsctest(IR, F)) /* long format; any indicator cancels branch */ - break; + case 0x09: /* --- BSC - Branch and skip on Condition --- */ + if (F) { + if (bsctest(IR, F)) /* long format; any indicator cancels branch */ + break; - archive_backtrace((DSPLC & 0x40) ? "BOSC" : "BSC"); /* save info in back-trace buffer */ - IAR = eaddr; /* no indicator means branch taken */ - } - else { /* short format: skip if any indicator hits */ - if (bsctest(IR, F)) { - archive_backtrace((DSPLC & 0x40) ? "BOSC" : "BSC"); /* save info in back-trace buffer */ - INCREMENT_IAR; - } - } + archive_backtrace((DSPLC & 0x40) ? "BOSC" : "BSC"); /* save info in back-trace buffer */ + IAR = eaddr; /* no indicator means branch taken */ + } + else { /* short format: skip if any indicator hits */ + if (bsctest(IR, F)) { + archive_backtrace((DSPLC & 0x40) ? "BOSC" : "BSC"); /* save info in back-trace buffer */ + INCREMENT_IAR; + } + } /* 27Mar02: moved this test out of the (F) condition; BOSC works even in the * short form. The displacement field in this instruction is always the set of * condition bits, and the interrupt clear bit doesn't collide. */ - if (DSPLC & 0x40) { /* BOSC = exit from interrupt handler */ - exit_irq(); - cwincount = 0; - } - break; + if (DSPLC & 0x40) { /* BOSC = exit from interrupt handler */ + exit_irq(); + cwincount = 0; + } + break; - case 0x0c: /* --- LDX - Load Index --- */ - if (F) - eaddr = (INDIR) ? ReadW(word2) : word2; - else - eaddr = DSPLC; + case 0x0c: /* --- LDX - Load Index --- */ + if (F) + eaddr = (INDIR) ? ReadW(word2) : word2; + else + eaddr = DSPLC; - if (TAG) - WriteIndex(TAG, eaddr); - else { - archive_backtrace("LDX"); /* save info in back-trace buffer */ - IAR = eaddr; /* what happens in short form? can onlyjump to low addresses? */ - } - break; + if (TAG) + WriteIndex(TAG, eaddr); + else { + archive_backtrace("LDX"); /* save info in back-trace buffer */ + IAR = eaddr; /* what happens in short form? can onlyjump to low addresses? */ + } + break; - case 0x0d: /* --- STX - Store Index --- */ - if (F) { /* compute EA without any indexing */ - eaddr = (INDIR) ? ReadW(word2) : word2; - } - else { - eaddr = IAR + DSPLC; - } - WriteW(eaddr, TAG ? ReadIndex(TAG) : IAR); - break; + case 0x0d: /* --- STX - Store Index --- */ + if (F) { /* compute EA without any indexing */ + eaddr = (INDIR) ? ReadW(word2) : word2; + } + else { + eaddr = IAR + DSPLC; + } + WriteW(eaddr, TAG ? ReadIndex(TAG) : IAR); + break; - case 0x0e: /* --- MDX - Modify Index and Skip --- */ - if (F) { /* long format: adjust memory location */ - if (TAG) { - oldval = ReadIndex(TAG); /* add word2 to index */ - newval = oldval + (INDIR ? ReadW(word2) : word2); - WriteIndex(TAG, newval); - } - else { - oldval = ReadW(word2); - DSPLC = IR & 0x00FF; /* use extended displacement (no INDIR bit, it's is part of displacement in this op) */ - if (DSPLC & 0x0080) - DSPLC |= ~ 0xFF; - newval = oldval + DSPLC; /* add modifier to @word2 */ - WriteW(word2, newval); - } - } - else { /* short format: adust IAR or index */ - if (TAG) { - oldval = ReadIndex(TAG); /* add displacement to index */ - newval = oldval + DSPLC; - WriteIndex(TAG, newval); - } - else { - oldval = IAR; /* add displacement to IAR */ - newval = IAR + DSPLC; - archive_backtrace("MDX"); - IAR = newval & mem_mask; - } - } + case 0x0e: /* --- MDX - Modify Index and Skip --- */ + if (F) { /* long format: adjust memory location */ + if (TAG) { + oldval = ReadIndex(TAG); /* add word2 to index */ + newval = oldval + (INDIR ? ReadW(word2) : word2); + WriteIndex(TAG, newval); + } + else { + oldval = ReadW(word2); + DSPLC = IR & 0x00FF; /* use extended displacement (no INDIR bit, it's is part of displacement in this op) */ + if (DSPLC & 0x0080) + DSPLC |= ~ 0xFF; + newval = oldval + DSPLC; /* add modifier to @word2 */ + WriteW(word2, newval); + } + } + else { /* short format: adust IAR or index */ + if (TAG) { + oldval = ReadIndex(TAG); /* add displacement to index */ + newval = oldval + DSPLC; + WriteIndex(TAG, newval); + } + else { + oldval = IAR; /* add displacement to IAR */ + newval = IAR + DSPLC; + archive_backtrace("MDX"); + IAR = newval & mem_mask; + } + } - if ((F || TAG) && (((newval & 0xFFFF) == 0) || ((oldval & 0x8000) != (newval & 0x8000)))) { - archive_backtrace("SKP"); - INCREMENT_IAR; /* skip if index sign change or zero */ - } - break; + if ((F || TAG) && (((newval & 0xFFFF) == 0) || ((oldval & 0x8000) != (newval & 0x8000)))) { + archive_backtrace("SKP"); + INCREMENT_IAR; /* skip if index sign change or zero */ + } + break; - case 0x10: /* --- A - Add --- */ - /* in adds and subtracts, carry is set or cleared, overflow is set only */ - src = ReadW(eaddr); - ARFSET(src); - src2 = ACC; - ACC = (ACC + src) & 0xFFFF; + case 0x10: /* --- A - Add --- */ + /* in adds and subtracts, carry is set or cleared, overflow is set only */ + src = ReadW(eaddr); + ARFSET(src); + src2 = ACC; + ACC = (ACC + src) & 0xFFFF; - C = ACC < src; - if (! V) - V = SIGN_BIT((~src ^ src2) & (src ^ ACC)); - break; + C = ACC < src; + if (! V) + V = SIGN_BIT((~src ^ src2) & (src ^ ACC)); + break; - case 0x11: /* --- AD - Add Double --- */ - src = ((ACC << 16) | (EXT & 0xFFFF)); - ARFSET(EXT); - src2 = (ReadW(eaddr) << 16) + ReadW(eaddr|1); - dst = src + src2; - ACC = (dst >> 16) & 0xFFFF; - EXT = dst & 0xFFFF; + case 0x11: /* --- AD - Add Double --- */ + src = ((ACC << 16) | (EXT & 0xFFFF)); + ARFSET(EXT); + src2 = (ReadW(eaddr) << 16) + ReadW(eaddr|1); + dst = src + src2; + ACC = (dst >> 16) & 0xFFFF; + EXT = dst & 0xFFFF; - C = (uint32) dst < (uint32) src; - if (! V) - V = DWSIGN_BIT((~src ^ src2) & (src ^ dst)); - break; + C = (uint32) dst < (uint32) src; + if (! V) + V = DWSIGN_BIT((~src ^ src2) & (src ^ dst)); + break; - case 0x12: /* --- S - Subtract --- */ - src = ACC; - ARFSET(src); - src2 = ReadW(eaddr); - ACC = (ACC-src2) & 0xFFFF; + case 0x12: /* --- S - Subtract --- */ + src = ACC; + ARFSET(src); + src2 = ReadW(eaddr); + ACC = (ACC-src2) & 0xFFFF; - C = src < src2; - if (! V) - V = SIGN_BIT((src ^ src2) & (src ^ ACC)); - break; + C = src < src2; + if (! V) + V = SIGN_BIT((src ^ src2) & (src ^ ACC)); + break; - case 0x13: /* --- SD - Subtract Double --- */ - src = ((ACC << 16) | (EXT & 0xFFFF)); - ARFSET(EXT); - src2 = (ReadW(eaddr) << 16) + ReadW(eaddr|1); - dst = src - src2; - ACC = (dst >> 16) & 0xFFFF; - EXT = dst & 0xFFFF; + case 0x13: /* --- SD - Subtract Double --- */ + src = ((ACC << 16) | (EXT & 0xFFFF)); + ARFSET(EXT); + src2 = (ReadW(eaddr) << 16) + ReadW(eaddr|1); + dst = src - src2; + ACC = (dst >> 16) & 0xFFFF; + EXT = dst & 0xFFFF; - C = (uint32) src < (uint32) src2; - if (! V) - V = DWSIGN_BIT((src ^ src2) & (src ^ dst)); - break; + C = (uint32) src < (uint32) src2; + if (! V) + V = DWSIGN_BIT((src ^ src2) & (src ^ dst)); + break; - case 0x14: /* --- M - Multiply --- */ - if ((src = ACC & 0xFFFF) & 0x8000) /* sign extend the values */ - src |= ~0xFFFF; - if ((src2 = ReadW(eaddr)) & 0x8000) - src2 |= ~0xFFFF; + case 0x14: /* --- M - Multiply --- */ + if ((src = ACC & 0xFFFF) & 0x8000) /* sign extend the values */ + src |= ~0xFFFF; + if ((src2 = ReadW(eaddr)) & 0x8000) + src2 |= ~0xFFFF; - ARFSET(src2); - dst = src * src2; - ACC = (dst >> 16) & 0xFFFF; /* split the results */ - EXT = dst & 0xFFFF; - break; + ARFSET(src2); + dst = src * src2; + ACC = (dst >> 16) & 0xFFFF; /* split the results */ + EXT = dst & 0xFFFF; + break; - case 0x15: /* --- D - Divide --- */ - src = ((ACC << 16) | (EXT & 0xFFFF)); - if ((src2 = ReadW(eaddr)) & 0x8000) - src2 |= ~0xFFFF; /* oops: sign extend was missing, fixed 18Mar03 */ + case 0x15: /* --- D - Divide --- */ + src = ((ACC << 16) | (EXT & 0xFFFF)); + if ((src2 = ReadW(eaddr)) & 0x8000) + src2 |= ~0xFFFF; /* oops: sign extend was missing, fixed 18Mar03 */ - ARFSET(src2); + ARFSET(src2); - /* 24-Mar-11 - Failed IBM diagnostics because I was not checking for overflow here. Fixed. - * Have to check for special case of -maxint / -1 because Windows (at least) generates an exception - */ - if (src2 == 0) { - V = 1; /* divide by zero just sets overflow, ACC & EXT are undefined */ - } - else if ((src2 == -1) && ((uint32)src == 0x80000000)) { - V = 1; /* another special case: max negative int / -1 also overflows */ - } - else { - result = src / src2; /* compute dividend */ - if ((result > 32767) || (result < -32768)) - V = 1; /* if result does not fit into 16 bits, we have an overflow */ - ACC = result & 0xFFFF; - EXT = (src % src2) & 0xFFFF; - } - break; + /* 24-Mar-11 - Failed IBM diagnostics because I was not checking for overflow here. Fixed. + * Have to check for special case of -maxint / -1 because Windows (at least) generates an exception + */ + if (src2 == 0) { + V = 1; /* divide by zero just sets overflow, ACC & EXT are undefined */ + } + else if ((src2 == -1) && ((uint32)src == 0x80000000)) { + V = 1; /* another special case: max negative int / -1 also overflows */ + } + else { + result = src / src2; /* compute dividend */ + if ((result > 32767) || (result < -32768)) + V = 1; /* if result does not fit into 16 bits, we have an overflow */ + ACC = result & 0xFFFF; + EXT = (src % src2) & 0xFFFF; + } + break; - case 0x18: /* --- LD - Load ACC --- */ - ACC = ReadW(eaddr); - break; + case 0x18: /* --- LD - Load ACC --- */ + ACC = ReadW(eaddr); + break; - case 0x19: /* --- LDD - Load Double --- */ - ACC = ReadW(eaddr); - EXT = ReadW(eaddr|1); /* notice address is |1 not +1 */ - break; + case 0x19: /* --- LDD - Load Double --- */ + ACC = ReadW(eaddr); + EXT = ReadW(eaddr|1); /* notice address is |1 not +1 */ + break; - case 0x1a: /* --- STO - Store ACC --- */ - WriteW(eaddr, ACC); - break; + case 0x1a: /* --- STO - Store ACC --- */ + WriteW(eaddr, ACC); + break; - case 0x1b: /* --- STD - Store Double --- */ - WriteW(eaddr|1, EXT); - WriteW(eaddr, ACC); /* order is important: if odd addr, only ACC is stored */ - break; + case 0x1b: /* --- STD - Store Double --- */ + WriteW(eaddr|1, EXT); + WriteW(eaddr, ACC); /* order is important: if odd addr, only ACC is stored */ + break; - case 0x1c: /* --- AND - Logical AND --- */ - src = ReadW(eaddr); - ARFSET(src); - ACC &= src; - break; + case 0x1c: /* --- AND - Logical AND --- */ + src = ReadW(eaddr); + ARFSET(src); + ACC &= src; + break; - case 0x1d: /* --- OR - Logical OR --- */ - src = ReadW(eaddr); - ARFSET(src); - ACC |= src; - break; + case 0x1d: /* --- OR - Logical OR --- */ + src = ReadW(eaddr); + ARFSET(src); + ACC |= src; + break; - case 0x1e: /* --- EOR - Logical Excl OR --- */ - src = ReadW(eaddr); - ARFSET(src); - ACC ^= src; - break; + case 0x1e: /* --- EOR - Logical Excl OR --- */ + src = ReadW(eaddr); + ARFSET(src); + ACC ^= src; + break; - case 0x16: - case 0x17: + case 0x16: + case 0x17: #ifdef ENABLE_1800_SUPPORT - if (is_1800) { - if (OP == 0x16) { /* --- CMP - Compare --- */ - src = ACC; /* like subtract but result isn't stored */ - src2 = ReadW(eaddr); - dst = (ACC-src2) & 0xFFFF; - C = src < src2; + if (is_1800) { + if (OP == 0x16) { /* --- CMP - Compare --- */ + src = ACC; /* like subtract but result isn't stored */ + src2 = ReadW(eaddr); + dst = (ACC-src2) & 0xFFFF; + C = src < src2; - if (dst & 0x8000) /* if ACC < operand, skip 1 instruction */ - IAR = IAR+1; - else if ((dst & 0xFFFF) == 0) /* if ACC == operand, skip 2 instructions */ - IAR = IAR+2; - } - else { /* --- DCMP - Compare Double --- */ - src = ((ACC << 16) | (EXT & 0xFFFF)); - src2 = (ReadW(eaddr) << 16) + ReadW(eaddr|1); - dst = src - src2; - C = (uint32) src < (uint32) src2; + if (dst & 0x8000) /* if ACC < operand, skip 1 instruction */ + IAR = IAR+1; + else if ((dst & 0xFFFF) == 0) /* if ACC == operand, skip 2 instructions */ + IAR = IAR+2; + } + else { /* --- DCMP - Compare Double --- */ + src = ((ACC << 16) | (EXT & 0xFFFF)); + src2 = (ReadW(eaddr) << 16) + ReadW(eaddr|1); + dst = src - src2; + C = (uint32) src < (uint32) src2; - if (dst & 0x80000000) /* if ACC_EXT < operand, skip 1 instruction */ - IAR = IAR+1; - else if (dst == 0) /* if ACC_EXT == operand, skip 2 instructions */ - IAR = IAR+2; - } + if (dst & 0x80000000) /* if ACC_EXT < operand, skip 1 instruction */ + IAR = IAR+1; + else if (dst == 0) /* if ACC_EXT == operand, skip 2 instructions */ + IAR = IAR+2; + } - break; /* these are legal instructions on the 1800 */ - } + break; /* these are legal instructions on the 1800 */ + } #endif - /* 1130: these are not legal instructions, fall through */ + /* 1130: these are not legal instructions, fall through */ - default: + default: /* all invalid instructions act like waits */ -/* case 0x00: */ -/* case 0x07: */ -/* case 0x0a: */ -/* case 0x0b: */ -/* case 0x0f: */ -/* case 0x1f: */ - wait_state = WAIT_INVALID_OP; - SAR = prev_IAR; /* this is a hack; ensure that the SAR/SBR display shows the WAIT instruction fetch */ - SBR = IR; - break; - } /* end instruction decode switch */ +/* case 0x00: */ +/* case 0x07: */ +/* case 0x0a: */ +/* case 0x0b: */ +/* case 0x0f: */ +/* case 0x1f: */ + wait_state = WAIT_INVALID_OP; + SAR = prev_IAR; /* this is a hack; ensure that the SAR/SBR display shows the WAIT instruction fetch */ + SBR = IR; + break; + } /* end instruction decode switch */ - if (RUNMODE != MODE_RUN && RUNMODE != MODE_INT_RUN) - reason = STOP_WAIT; + if (RUNMODE != MODE_RUN && RUNMODE != MODE_INT_RUN) + reason = STOP_WAIT; - if (tbit && (ipl < 0)) { /* if INT_RUN mode, set IRQ5 after this instr */ - GUI_BEGIN_CRITICAL_SECTION - SETBIT(cpu_dsw, CPU_DSW_INT_RUN); - SETBIT(ILSW[5], ILSW_5_INT_RUN_PROGRAM_STOP); - int_req |= INT_REQ_5; - GUI_END_CRITICAL_SECTION - } - } /* end main loop */ + if (tbit && (ipl < 0)) { /* if INT_RUN mode, set IRQ5 after this instr */ + GUI_BEGIN_CRITICAL_SECTION + SETBIT(cpu_dsw, CPU_DSW_INT_RUN); + SETBIT(ILSW[5], ILSW_5_INT_RUN_PROGRAM_STOP); + int_req |= INT_REQ_5; + GUI_END_CRITICAL_SECTION + } + } /* end main loop */ #ifdef GUI_SUPPORT - gui_run(FALSE); + gui_run(FALSE); #endif - running = FALSE; - int_lamps = 0; /* display only currently active interrupts while halted */ + running = FALSE; + int_lamps = 0; /* display only currently active interrupts while halted */ - if (reason == STOP_WAIT || reason == STOP_INVALID_INSTR) { - wait_state = 0; /* on resume, don't wait */ - wait_lamp = TRUE; /* but keep the lamp lit on the GUI */ + if (reason == STOP_WAIT || reason == STOP_INVALID_INSTR) { + wait_state = 0; /* on resume, don't wait */ + wait_lamp = TRUE; /* but keep the lamp lit on the GUI */ - CLRBIT(cpu_dsw, CPU_DSW_PROGRAM_STOP); /* and on resume, reset program start bit */ - if ((cpu_dsw & CPU_DSW_PROGRAM_STOP) == 0) - CLRBIT(ILSW[5], ILSW_5_INT_RUN_PROGRAM_STOP); - } + CLRBIT(cpu_dsw, CPU_DSW_PROGRAM_STOP); /* and on resume, reset program start bit */ + if ((cpu_dsw & CPU_DSW_PROGRAM_STOP) == 0) + CLRBIT(ILSW[5], ILSW_5_INT_RUN_PROGRAM_STOP); + } - if (cgi) /* give CGI hook function a chance to do something */ - cgi_stop(reason); + if (cgi) /* give CGI hook function a chance to do something */ + cgi_stop(reason); - return reason; + return reason; } /* * simh_status_to_stopcode - convert a SCPE_xxx value from sim_process_event into a STOP_xxx code */ - + static int simh_status_to_stopcode (int status) { - return (status == SCPE_BREAK) ? STOP_BREAK : - (status == SCPE_STOP) ? STOP_IMMEDIATE : - (status == SCPE_STEP) ? STOP_STEP : STOP_OTHER; + return (status == SCPE_BREAK) ? STOP_BREAK : + (status == SCPE_STOP) ? STOP_IMMEDIATE : + (status == SCPE_STEP) ? STOP_STEP : STOP_OTHER; } /* ------------------------------------------------------------------------ @@ -1211,36 +1211,36 @@ static int simh_status_to_stopcode (int status) static t_bool bsctest (int32 DSPLC, t_bool reset_V) { - if (DSPLC & 0x01) { /* Overflow off (note inverted sense) */ - if (! V) - return TRUE; + if (DSPLC & 0x01) { /* Overflow off (note inverted sense) */ + if (! V) + return TRUE; // 24-Mar-11 - V is always reset when tested, in both the long and short forms of the instructions -// else if (reset_V) /* reset after testing */ - V = 0; - } +// else if (reset_V) /* reset after testing */ + V = 0; + } - if (DSPLC & 0x02) { /* Carry off (note inverted sense) */ - if (! C) - return TRUE; - } + if (DSPLC & 0x02) { /* Carry off (note inverted sense) */ + if (! C) + return TRUE; + } - if (DSPLC & 0x04) /* Even */ - if ((ACC & 1) == 0) - return TRUE; + if (DSPLC & 0x04) /* Even */ + if ((ACC & 1) == 0) + return TRUE; - if (DSPLC & 0x08) /* Positive */ - if ((ACC & 0x8000) == 0 && ACC != 0) - return TRUE; + if (DSPLC & 0x08) /* Positive */ + if ((ACC & 0x8000) == 0 && ACC != 0) + return TRUE; - if (DSPLC & 0x10) /* Negative */ - if (ACC & 0x8000) - return TRUE; + if (DSPLC & 0x10) /* Negative */ + if (ACC & 0x8000) + return TRUE; - if (DSPLC & 0x20) /* Zero */ - if ((ACC & 0xFFFF) == 0) - return TRUE; + if (DSPLC & 0x20) /* Zero */ + if ((ACC & 0xFFFF) == 0) + return TRUE; - return FALSE; + return FALSE; } /* ------------------------------------------------------------------------ @@ -1249,39 +1249,39 @@ static t_bool bsctest (int32 DSPLC, t_bool reset_V) static void exit_irq (void) { - int i, bit; - - GUI_BEGIN_CRITICAL_SECTION + int i, bit; + + GUI_BEGIN_CRITICAL_SECTION - if (ipl == 5 && tbit) { /* if we are exiting an INT_RUN interrupt, clear it for the next instruction */ - CLRBIT(cpu_dsw, CPU_DSW_INT_RUN); - if ((cpu_dsw & CPU_DSW_PROGRAM_STOP) == 0) - CLRBIT(ILSW[5], ILSW_5_INT_RUN_PROGRAM_STOP); - } + if (ipl == 5 && tbit) { /* if we are exiting an INT_RUN interrupt, clear it for the next instruction */ + CLRBIT(cpu_dsw, CPU_DSW_INT_RUN); + if ((cpu_dsw & CPU_DSW_PROGRAM_STOP) == 0) + CLRBIT(ILSW[5], ILSW_5_INT_RUN_PROGRAM_STOP); + } - ipl = -1; /* default: return to main processor level */ - int_mask = 0xFFFF; + ipl = -1; /* default: return to main processor level */ + int_mask = 0xFFFF; - if (iplpending) { /* restore previous interrupt status */ - for (i = 0, bit = 0x20; i < 6; i++, bit >>= 1) { - if (iplpending & bit) { - iplpending &= ~bit; - ipl = i; - int_mask = int_masks[i]; - break; - } - } - } - GUI_END_CRITICAL_SECTION + if (iplpending) { /* restore previous interrupt status */ + for (i = 0, bit = 0x20; i < 6; i++, bit >>= 1) { + if (iplpending & bit) { + iplpending &= ~bit; + ipl = i; + int_mask = int_masks[i]; + break; + } + } + } + GUI_END_CRITICAL_SECTION - calc_ints(); /* recompute pending interrupt mask */ -} /* because we probably cleared some ILSW bits before this instruction */ + calc_ints(); /* recompute pending interrupt mask */ +} /* because we probably cleared some ILSW bits before this instruction */ /* let a device halt the simulation */ void break_simulation (t_stat stopreason) { - reason = stopreason; + reason = stopreason; } /* ------------------------------------------------------------------------ @@ -1294,40 +1294,40 @@ void break_simulation (t_stat stopreason) t_stat cpu_reset (DEVICE *dptr) { - wait_state = 0; /* cancel wait */ - wait_lamp = TRUE; /* but keep the wait lamp lit on the GUI */ + wait_state = 0; /* cancel wait */ + wait_lamp = TRUE; /* but keep the wait lamp lit on the GUI */ - if ((cpu_unit.flags & (UNIT_ATT|UNIT_TRACE_INSTR)) == (UNIT_ATT|UNIT_TRACE_INSTR)) { /* record reset in CPU log */ - fseek(cpu_unit.fileref, 0, SEEK_END); - fprintf(cpu_unit.fileref, "---RESET---" CRLF); - } + if ((cpu_unit.flags & (UNIT_ATT|UNIT_TRACE_INSTR)) == (UNIT_ATT|UNIT_TRACE_INSTR)) { /* record reset in CPU log */ + fseek(cpu_unit.fileref, 0, SEEK_END); + fprintf(cpu_unit.fileref, "---RESET---" CRLF); + } - GUI_BEGIN_CRITICAL_SECTION + GUI_BEGIN_CRITICAL_SECTION - CLRBIT(cpu_dsw, CPU_DSW_PROGRAM_STOP|CPU_DSW_INT_RUN); - CLRBIT(ILSW[5], ILSW_5_INT_RUN_PROGRAM_STOP); + CLRBIT(cpu_dsw, CPU_DSW_PROGRAM_STOP|CPU_DSW_INT_RUN); + CLRBIT(ILSW[5], ILSW_5_INT_RUN_PROGRAM_STOP); - reset_backtrace(); + reset_backtrace(); - ipl = -1; - int_mask = 0xFFFF; - int_req = 0; /* hmmm, it SHOULD reset the int req, right? */ - int_lamps = 0; - iplpending = 0; - memset(ILSW, 0, sizeof(ILSW)); + ipl = -1; + int_mask = 0xFFFF; + int_req = 0; /* hmmm, it SHOULD reset the int req, right? */ + int_lamps = 0; + iplpending = 0; + memset(ILSW, 0, sizeof(ILSW)); - cpu_dsw = 0; /* clear int req and prot stop bits */ - tbit = 0; /* cancel INT_RUN mode */ + cpu_dsw = 0; /* clear int req and prot stop bits */ + tbit = 0; /* cancel INT_RUN mode */ - C = V = 0; /* clear processor flags */ - IAR = SAR = SBR = 0; /* clear IAR and other registers */ - ACC = EXT = OP = TAG = CCC = C = V = 0; + C = V = 0; /* clear processor flags */ + IAR = SAR = SBR = 0; /* clear IAR and other registers */ + ACC = EXT = OP = TAG = CCC = C = V = 0; - mem_mask = MEMSIZE - 1; /* wraparound mask */ + mem_mask = MEMSIZE - 1; /* wraparound mask */ - GUI_END_CRITICAL_SECTION + GUI_END_CRITICAL_SECTION - return cpu_svc(&cpu_unit); /* reset breakpoint */ + return cpu_svc(&cpu_unit); /* reset breakpoint */ } /* ------------------------------------------------------------------------ @@ -1336,15 +1336,15 @@ t_stat cpu_reset (DEVICE *dptr) t_stat cpu_ex (t_value *vptr, t_addr addr, UNIT *uptr, int32 sw) { - if (vptr == NULL) return SCPE_ARG; + if (vptr == NULL) return SCPE_ARG; - /* check this out -- save command hits it in weird way */ - /* I wish I remembered what I meant when I wrote that */ - if (addr < MEMSIZE) { - *vptr = M[addr] & 0xFFFF; - return SCPE_OK; - } - return SCPE_NXM; + /* check this out -- save command hits it in weird way */ + /* I wish I remembered what I meant when I wrote that */ + if (addr < MEMSIZE) { + *vptr = M[addr] & 0xFFFF; + return SCPE_OK; + } + return SCPE_NXM; } /* ------------------------------------------------------------------------ @@ -1353,11 +1353,11 @@ t_stat cpu_ex (t_value *vptr, t_addr addr, UNIT *uptr, int32 sw) t_stat cpu_dep (t_value val, t_addr addr, UNIT *uptr, int32 sw) { - if (addr < MEMSIZE) { - M[addr] = (uint16) (val & 0xFFFF); - return SCPE_OK; - } - return SCPE_NXM; + if (addr < MEMSIZE) { + M[addr] = (uint16) (val & 0xFFFF); + return SCPE_OK; + } + return SCPE_NXM; } /* ------------------------------------------------------------------------ @@ -1366,11 +1366,11 @@ t_stat cpu_dep (t_value val, t_addr addr, UNIT *uptr, int32 sw) t_stat cpu_svc (UNIT *uptr) { - if ((ibkpt_addr & ~ILL_ADR_FLAG) == save_ibkpt) - ibkpt_addr = save_ibkpt; + if ((ibkpt_addr & ~ILL_ADR_FLAG) == save_ibkpt) + ibkpt_addr = save_ibkpt; - save_ibkpt = -1; - return SCPE_OK; + save_ibkpt = -1; + return SCPE_OK; } /* ------------------------------------------------------------------------ @@ -1379,49 +1379,49 @@ t_stat cpu_svc (UNIT *uptr) t_stat cpu_set_size (UNIT *uptr, int32 value, CONST char *cptr, void *desc) { - t_bool used; - int32 i; + t_bool used; + int32 i; - if ((value <= 0) || (value > MAXMEMSIZE) || ((value & 0xFFF) != 0)) - return SCPE_ARG; + if ((value <= 0) || (value > MAXMEMSIZE) || ((value & 0xFFF) != 0)) + return SCPE_ARG; - for (i = value, used = FALSE; i < (int32) MEMSIZE; i++) { - if (M[i] != 0) { - used = TRUE; - break; - } - } + for (i = value, used = FALSE; i < (int32) MEMSIZE; i++) { + if (M[i] != 0) { + used = TRUE; + break; + } + } - if (used && ! get_yn ("Really truncate memory [N]?", FALSE)) - return SCPE_OK; + if (used && ! get_yn ("Really truncate memory [N]?", FALSE)) + return SCPE_OK; - for (i = MEMSIZE; i < value; i++) /* clear expanded area */ - M[i] = 0; + for (i = MEMSIZE; i < value; i++) /* clear expanded area */ + M[i] = 0; - MEMSIZE = value; - mem_mask = MEMSIZE - 1; + MEMSIZE = value; + mem_mask = MEMSIZE - 1; - return SCPE_OK; + return SCPE_OK; } /* processor type */ t_stat cpu_set_type (UNIT *uptr, int32 value, CONST char *cptr, void *desc) { - REG *r; + REG *r; - is_1800 = (value & UNIT_1800) != 0; /* set is_1800 mode flag */ + is_1800 = (value & UNIT_1800) != 0; /* set is_1800 mode flag */ - for (r = cpu_reg; r->name != NULL; r++) { /* unhide or hide 1800-specific registers & state */ - if (strnicmp(r->name, "XR", 2) == 0) { - if (value & UNIT_1800) - CLRBIT(r->flags, REG_HIDDEN|REG_RO); - else - SETBIT(r->flags, REG_HIDDEN|REG_RO); - } - } + for (r = cpu_reg; r->name != NULL; r++) { /* unhide or hide 1800-specific registers & state */ + if (strnicmp(r->name, "XR", 2) == 0) { + if (value & UNIT_1800) + CLRBIT(r->flags, REG_HIDDEN|REG_RO); + else + SETBIT(r->flags, REG_HIDDEN|REG_RO); + } + } - return SCPE_OK; + return SCPE_OK; } /* ------------------------------------------------------------------------ @@ -1430,21 +1430,21 @@ t_stat cpu_set_type (UNIT *uptr, int32 value, CONST char *cptr, void *desc) void xio_1131_switches (int32 addr, int32 func, int32 modify) { - char msg[80]; + char msg[80]; - switch (func) { - case XIO_READ: - WriteW(addr, CES); - break; + switch (func) { + case XIO_READ: + WriteW(addr, CES); + break; - case XIO_SENSE_DEV: - ACC = cpu_dsw; - break; + case XIO_SENSE_DEV: + ACC = cpu_dsw; + break; - default: - sprintf(msg, "Invalid console switch function %x", func); - xio_error(msg); - } + default: + sprintf(msg, "Invalid console switch function %x", func); + xio_error(msg); + } } /* ------------------------------------------------------------------------ @@ -1453,9 +1453,9 @@ void xio_1131_switches (int32 addr, int32 func, int32 modify) void xio_error (const char *msg) { - printf("*** XIO error at %04x: %s\n", prev_IAR, msg); - if (cgi) /* if this happens in CGI mode, probably best to halt */ - break_simulation(STOP_CRASH); + printf("*** XIO error at %04x: %s\n", prev_IAR, msg); + if (cgi) /* if this happens in CGI mode, probably best to halt */ + break_simulation(STOP_CRASH); } /* ------------------------------------------------------------------------ @@ -1464,30 +1464,30 @@ void xio_error (const char *msg) t_stat register_cmd (const char *name, t_stat (*action)(int32 flag, CONST char *ptr), int arg, const char *help) { - int i; + int i; - for (i = 0; i < MAX_EXTRA_COMMANDS; i++) { /* find end of command table */ - if (x_cmds[i].action == action) - return SCPE_OK; /* command is already there, just return */ - if (x_cmds[i].name == NULL) - break; - } + for (i = 0; i < MAX_EXTRA_COMMANDS; i++) { /* find end of command table */ + if (x_cmds[i].action == action) + return SCPE_OK; /* command is already there, just return */ + if (x_cmds[i].name == NULL) + break; + } - if (i >= (MAX_EXTRA_COMMANDS-1)) { /* no more room (we need room for the NULL) */ - fprintf(stderr, "The command table is full - rebuild the simulator with more free slots\n"); - return SCPE_ARG; - } + if (i >= (MAX_EXTRA_COMMANDS-1)) { /* no more room (we need room for the NULL) */ + fprintf(stderr, "The command table is full - rebuild the simulator with more free slots\n"); + return SCPE_ARG; + } - x_cmds[i].action = action; /* add new command */ - x_cmds[i].name = name; - x_cmds[i].arg = arg; - x_cmds[i].help = help; + x_cmds[i].action = action; /* add new command */ + x_cmds[i].name = name; + x_cmds[i].arg = arg; + x_cmds[i].help = help; - i++; - x_cmds[i].action = NULL; /* move the NULL terminator */ - x_cmds[i].name = NULL; + i++; + x_cmds[i].action = NULL; /* move the NULL terminator */ + x_cmds[i].name = NULL; - return SCPE_OK; + return SCPE_OK; } #ifdef USE_MY_ECHO_CMD @@ -1497,8 +1497,8 @@ t_stat register_cmd (const char *name, t_stat (*action)(int32 flag, CONST char * static t_stat echo_cmd (int32 flag, CONST char *cptr) { - printf("%s\n", cptr); - return SCPE_OK; + printf("%s\n", cptr); + return SCPE_OK; } #endif @@ -1508,27 +1508,27 @@ static t_stat echo_cmd (int32 flag, CONST char *cptr) void sim_init (void) { - sim_gui = ! (sim_switches & SWMASK('G')); /* -g means no GUI */ + sim_gui = ! (sim_switches & SWMASK('G')); /* -g means no GUI */ - sim_vm_cmd = x_cmds; /* provide list of additional commands */ + sim_vm_cmd = x_cmds; /* provide list of additional commands */ #ifdef GUI_SUPPORT - /* set hook routines for GUI command processing */ - if (sim_gui) { - sim_vm_read = &read_cmdline; - sim_vm_post = &update_gui; - } + /* set hook routines for GUI command processing */ + if (sim_gui) { + sim_vm_read = &read_cmdline; + sim_vm_post = &update_gui; + } #endif #ifdef ENABLE_BACKTRACE - /* add the BACKTRACE command */ - register_cmd("BACKTRACE", &backtrace_cmd, 0, "ba{cktrace} {n} list last n branches/skips/interrupts\n"); + /* add the BACKTRACE command */ + register_cmd("BACKTRACE", &backtrace_cmd, 0, "ba{cktrace} {n} list last n branches/skips/interrupts\n"); #endif - register_cmd("VIEW", &view_cmd, 0, "v{iew} filename view a text file with notepad\n"); + register_cmd("VIEW", &view_cmd, 0, "v{iew} filename view a text file with notepad\n"); #ifdef USE_MY_ECHO_CMD - register_cmd("ECHO", &echo_cmd, 0, "echo args... echo arguments passed to command\n"); + register_cmd("ECHO", &echo_cmd, 0, "echo args... echo arguments passed to command\n"); #endif } @@ -1541,70 +1541,70 @@ void sim_init (void) #define MAXARCHIVE 16 static struct tag_arch { - int iar; - const char *inst; + int iar; + const char *inst; } arch[MAXARCHIVE]; int narchived = 0, archind = 0; static void archive_backtrace (const char *inst) { - static int prevind; + static int prevind; - if (narchived < MAXARCHIVE) - narchived++; + if (narchived < MAXARCHIVE) + narchived++; - if (narchived > 0 && arch[prevind].iar == prev_IAR) - return; + if (narchived > 0 && arch[prevind].iar == prev_IAR) + return; - arch[archind].iar = prev_IAR; - arch[archind].inst = inst; + arch[archind].iar = prev_IAR; + arch[archind].inst = inst; - prevind = archind; - archind = (archind+1) % MAXARCHIVE; + prevind = archind; + archind = (archind+1) % MAXARCHIVE; } static void reset_backtrace (void) { - narchived = 0; - archind = 0; + narchived = 0; + archind = 0; } void void_backtrace (int afrom, int ato) { - int i; + int i; - afrom &= mem_mask; - ato &= mem_mask; + afrom &= mem_mask; + ato &= mem_mask; - for (i = 0; i < narchived; i++) - if (arch[i].iar >= afrom && arch[i].iar <= ato) - arch[i].inst = "OVERWRITTEN"; + for (i = 0; i < narchived; i++) + if (arch[i].iar >= afrom && arch[i].iar <= ato) + arch[i].inst = "OVERWRITTEN"; } static void show_backtrace (int nshow) { - int n = narchived, i = archind; + int n = narchived, i = archind; - if (n > nshow) n = nshow; + if (n > nshow) n = nshow; - while (--n >= 0) { - i = (i > 0) ? (i-1) : (MAXARCHIVE-1); - printf("from %04x (%s) ", arch[i].iar, arch[i].inst); - } + while (--n >= 0) { + i = (i > 0) ? (i-1) : (MAXARCHIVE-1); + printf("from %04x (%s) ", arch[i].iar, arch[i].inst); + } - if (narchived) - putchar('\n'); + if (narchived) + putchar('\n'); } static t_stat backtrace_cmd (int32 flag, CONST char *cptr) { - int n; + int n; - if ((n = atoi(cptr)) <= 0) - n = 6; + if ((n = atoi(cptr)) <= 0) + n = 6; - show_backtrace(n); - return SCPE_OK; + show_backtrace(n); + return SCPE_OK; } #else @@ -1621,10 +1621,10 @@ void void_backtrace (int afrom, int ato) * * Syntax is WEIRD: * - * attach cpu logfile log instructions and registers to file "logfile" - * attach -f cpu cpu.log log instructions, registers and floating point acc - * attach -m cpu mapfile logfile read addresses from "mapfile", log instructions to "logfile" - * attach -f -m cpu mapfile logfile same and log floating point stuff too + * attach cpu logfile log instructions and registers to file "logfile" + * attach -f cpu cpu.log log instructions, registers and floating point acc + * attach -m cpu mapfile logfile read addresses from "mapfile", log instructions to "logfile" + * attach -f -m cpu mapfile logfile same and log floating point stuff too * * mapfile if specified is a list of symbols and addresses of the form: * symbol hexval @@ -1672,9 +1672,9 @@ void void_backtrace (int afrom, int ato) t_stat fprint_sym (FILE *of, t_addr addr, t_value *val, UNIT *uptr, int32 sw); typedef struct tag_symentry { - struct tag_symentry *next; - int addr; - char sym[6]; + struct tag_symentry *next; + int addr; + char sym[6]; } SYMENTRY, *PSYMENTRY; static PSYMENTRY syms = NULL; @@ -1682,233 +1682,233 @@ static t_bool new_log, log_fac; static t_stat cpu_attach (UNIT *uptr, CONST char *cptr) { - char mapfile[200], buf[200], sym[100], gbuf[2*CBUFSIZE]; - int addr; - PSYMENTRY n, prv, s; - FILE *fd; + char mapfile[200], buf[200], sym[100], gbuf[2*CBUFSIZE]; + int addr; + PSYMENTRY n, prv, s; + FILE *fd; - remove(cptr); /* delete old log file, if present */ - new_log = TRUE; - log_fac = sim_switches & SWMASK ('F'); /* display the FAC and the ACC/EXT as fixed point. */ + remove(cptr); /* delete old log file, if present */ + new_log = TRUE; + log_fac = sim_switches & SWMASK ('F'); /* display the FAC and the ACC/EXT as fixed point. */ - for (s = syms; s != NULL; s = n) { /* free any old map entries */ - n = s->next; - free(s); - } - syms = NULL; - - if (sim_switches & SWMASK('M')) { /* use a map file to display relative addresses */ - cptr = get_glyph(cptr, mapfile, 0); - if (! *mapfile) { - printf("/m must be followed by a filename\n"); - return SCPE_ARG; - } - if ((fd = fopen(mapfile, "r")) == NULL) { - sim_perror(mapfile); - return SCPE_OPENERR; - } + for (s = syms; s != NULL; s = n) { /* free any old map entries */ + n = s->next; + free(s); + } + syms = NULL; + + if (sim_switches & SWMASK('M')) { /* use a map file to display relative addresses */ + cptr = get_glyph(cptr, mapfile, 0); + if (! *mapfile) { + printf("/m must be followed by a filename\n"); + return SCPE_ARG; + } + if ((fd = fopen(mapfile, "r")) == NULL) { + sim_perror(mapfile); + return SCPE_OPENERR; + } - while (fgets(buf, sizeof(buf), fd) != NULL) { /* read symbols & addresses, link in descending address order */ - if (sscanf(buf, "%s %x", sym, &addr) != 2) - continue; - if (*buf == ';') - continue; + while (fgets(buf, sizeof(buf), fd) != NULL) { /* read symbols & addresses, link in descending address order */ + if (sscanf(buf, "%s %x", sym, &addr) != 2) + continue; + if (*buf == ';') + continue; - for (prv = NULL, s = syms; s != NULL; prv = s, s = s->next) { - if (s->addr < addr) - break; - } + for (prv = NULL, s = syms; s != NULL; prv = s, s = s->next) { + if (s->addr < addr) + break; + } - if ((n = (PSYMENTRY)malloc(sizeof(SYMENTRY))) == NULL) { - printf("out of memory reading map!\n"); - break; - } + if ((n = (PSYMENTRY)malloc(sizeof(SYMENTRY))) == NULL) { + printf("out of memory reading map!\n"); + break; + } - sym[5] = '\0'; - strcpy(n->sym, sym); - upcase(n->sym); - n->addr = addr; + sym[5] = '\0'; + strcpy(n->sym, sym); + upcase(n->sym); + n->addr = addr; - if (prv == NULL) { - n->next = syms; - syms = n; - } - else { - n->next = prv->next; - prv ->next = n; - } - } - fclose(fd); - } + if (prv == NULL) { + n->next = syms; + syms = n; + } + else { + n->next = prv->next; + prv ->next = n; + } + } + fclose(fd); + } - return attach_unit(uptr, quotefix(cptr, gbuf)); /* fix quotes in filenames & attach */ + return attach_unit(uptr, quotefix(cptr, gbuf)); /* fix quotes in filenames & attach */ } static void trace_instruction (void) { - t_value v[2]; - float fac; - short exp; - int addr; - PSYMENTRY s; - long mant, sign; - char facstr[20], fltstr[20]; + t_value v[2]; + float fac; + short exp; + int addr; + PSYMENTRY s; + long mant, sign; + char facstr[20], fltstr[20]; - if ((cpu_unit.flags & UNIT_ATT) == 0) - return; + if ((cpu_unit.flags & UNIT_ATT) == 0) + return; - if (new_log) { - fseek(cpu_unit.fileref, 0, SEEK_END); - new_log = FALSE; + if (new_log) { + fseek(cpu_unit.fileref, 0, SEEK_END); + new_log = FALSE; - fprintf(cpu_unit.fileref, " IAR%s ACC EXT %s XR1 XR2 XR3 CVI %sOPERATION" CRLF, - syms ? " " : "", log_fac ? " (flt) " : "", log_fac ? " FAC " : ""); - fprintf(cpu_unit.fileref, "----%s ---- ---- %s---- ---- ---- --- %s-----------------------" CRLF, - syms ? "-----------" : "", log_fac ? "-------- " : "", log_fac ? "------------- " : ""); - } + fprintf(cpu_unit.fileref, " IAR%s ACC EXT %s XR1 XR2 XR3 CVI %sOPERATION" CRLF, + syms ? " " : "", log_fac ? " (flt) " : "", log_fac ? " FAC " : ""); + fprintf(cpu_unit.fileref, "----%s ---- ---- %s---- ---- ---- --- %s-----------------------" CRLF, + syms ? "-----------" : "", log_fac ? "-------- " : "", log_fac ? "------------- " : ""); + } - if (! log_fac) - facstr[0] = fltstr[0] = '\0'; - else { - mant = ((ACC & 0xFFFF) << 16) | (EXT & 0xFFFF); - if (mant == 0x80000000) { - sign = TRUE; - fac = 1.f; - } - else { - if ((sign = mant & 0x80000000) != 0) - mant = -mant; - fac = (float) mant * ((float) 1./ (float) (unsigned long) 0x80000000); - } - sprintf(fltstr, "%c%.5f ", sign ? '-' : ' ', fac); + if (! log_fac) + facstr[0] = fltstr[0] = '\0'; + else { + mant = ((ACC & 0xFFFF) << 16) | (EXT & 0xFFFF); + if (mant == 0x80000000) { + sign = TRUE; + fac = 1.f; + } + else { + if ((sign = mant & 0x80000000) != 0) + mant = -mant; + fac = (float) mant * ((float) 1./ (float) (unsigned long) 0x80000000); + } + sprintf(fltstr, "%c%.5f ", sign ? '-' : ' ', fac); - if (BETWEEN(M[3], 0x300, MEMSIZE-128)) { - exp = (short) ((M[M[3]+125] & 0xFF) - 128); - mant = (M[M[3]+126] << 8) | ((M[M[3]+127] >> 8) & 0xFF); - if ((sign = (mant & 0x00800000)) != 0) - mant = (-mant) & 0x00FFFFFF; + if (BETWEEN(M[3], 0x300, MEMSIZE-128)) { + exp = (short) ((M[M[3]+125] & 0xFF) - 128); + mant = (M[M[3]+126] << 8) | ((M[M[3]+127] >> 8) & 0xFF); + if ((sign = (mant & 0x00800000)) != 0) + mant = (-mant) & 0x00FFFFFF; - fac = (float) mant * ((float) 1. / (float) 0x00800000); + fac = (float) mant * ((float) 1. / (float) 0x00800000); - if (exp > 30) { - fac *= (float) (1 << 30); - exp -= 30; - while (exp > 0) - fac *= 2, exp--; - } - else if (exp > 0) - fac *= (float) (1 << exp); - else if (exp < -30) { - fac /= (float) (1 << 30); - exp += 30; - while (exp < 0) - fac /= 2, exp++; - } - else if (exp < 0) - fac /= (float) (1 << -exp); + if (exp > 30) { + fac *= (float) (1 << 30); + exp -= 30; + while (exp > 0) + fac *= 2, exp--; + } + else if (exp > 0) + fac *= (float) (1 << exp); + else if (exp < -30) { + fac /= (float) (1 << 30); + exp += 30; + while (exp < 0) + fac /= 2, exp++; + } + else if (exp < 0) + fac /= (float) (1 << -exp); - sprintf(facstr, "%c%.5e ", sign ? '-' : ' ', fac); - } - else - strcpy(facstr, " "); - } + sprintf(facstr, "%c%.5e ", sign ? '-' : ' ', fac); + } + else + strcpy(facstr, " "); + } - addr = IAR & 0xFFFF; - fprintf(cpu_unit.fileref, "%04x ", addr); + addr = IAR & 0xFFFF; + fprintf(cpu_unit.fileref, "%04x ", addr); - if (syms) { - for (s = syms; s != NULL; s = s->next) - if (s->addr <= addr) - break; - - if (s == NULL) - fprintf(cpu_unit.fileref, " %04x ", addr); - else - fprintf(cpu_unit.fileref, "%-5s+%04x ", s->sym, addr - s->addr); - } + if (syms) { + for (s = syms; s != NULL; s = s->next) + if (s->addr <= addr) + break; + + if (s == NULL) + fprintf(cpu_unit.fileref, " %04x ", addr); + else + fprintf(cpu_unit.fileref, "%-5s+%04x ", s->sym, addr - s->addr); + } - fprintf(cpu_unit.fileref, "%04x %04x %s%04x %04x %04x %c%c%c %s", - ACC & 0xFFFF, EXT & 0xFFFF, fltstr, M[1] & 0xFFFF, M[2] & 0xFFFF, M[3] & 0xFFFF, - C ? 'C' : ' ', V ? 'V' : ' ', (ipl < 0) ? ' ' : (ipl+'0'), facstr); + fprintf(cpu_unit.fileref, "%04x %04x %s%04x %04x %04x %c%c%c %s", + ACC & 0xFFFF, EXT & 0xFFFF, fltstr, M[1] & 0xFFFF, M[2] & 0xFFFF, M[3] & 0xFFFF, + C ? 'C' : ' ', V ? 'V' : ' ', (ipl < 0) ? ' ' : (ipl+'0'), facstr); - v[0] = M[ IAR & mem_mask]; - v[1] = M[(IAR+1) & mem_mask]; - fprint_sym(cpu_unit.fileref, IAR & mem_mask, v, NULL, SWMASK('M')); /* disassemble instruction */ + v[0] = M[ IAR & mem_mask]; + v[1] = M[(IAR+1) & mem_mask]; + fprint_sym(cpu_unit.fileref, IAR & mem_mask, v, NULL, SWMASK('M')); /* disassemble instruction */ - fputs(CRLF, cpu_unit.fileref); + fputs(CRLF, cpu_unit.fileref); } static void trace_common (FILE *fout) { - fprintf(fout, "[IAR %04x IPL %c] ", IAR, (ipl < 0) ? ' ' : ('0' + ipl)); + fprintf(fout, "[IAR %04x IPL %c] ", IAR, (ipl < 0) ? ' ' : ('0' + ipl)); } void trace_io (const char *fmt, ...) { - va_list args; + va_list args; - if ((cpu_unit.flags & UNIT_ATT) == 0) - return; + if ((cpu_unit.flags & UNIT_ATT) == 0) + return; - trace_common(cpu_unit.fileref); - va_start(args, fmt); /* get pointer to argument list */ - vfprintf(cpu_unit.fileref, fmt, args); /* write errors to cpu log file */ - va_end(args); + trace_common(cpu_unit.fileref); + va_start(args, fmt); /* get pointer to argument list */ + vfprintf(cpu_unit.fileref, fmt, args); /* write errors to cpu log file */ + va_end(args); - fputs(CRLF, cpu_unit.fileref); + fputs(CRLF, cpu_unit.fileref); } void trace_both (const char *fmt, ...) { - va_list args; + va_list args; - if (cpu_unit.flags & UNIT_ATT) { - trace_common(cpu_unit.fileref); - va_start(args, fmt); /* get pointer to argument list */ - vfprintf(cpu_unit.fileref, fmt, args); - va_end(args); - fputs(CRLF, cpu_unit.fileref); - } + if (cpu_unit.flags & UNIT_ATT) { + trace_common(cpu_unit.fileref); + va_start(args, fmt); /* get pointer to argument list */ + vfprintf(cpu_unit.fileref, fmt, args); + va_end(args); + fputs(CRLF, cpu_unit.fileref); + } - trace_common(stdout); - va_start(args, fmt); /* get pointer to argument list */ - vfprintf(stdout, fmt, args); - va_end(args); - putchar('\n'); + trace_common(stdout); + va_start(args, fmt); /* get pointer to argument list */ + vfprintf(stdout, fmt, args); + va_end(args); + putchar('\n'); } /* debugging */ void debug_print (const char *fmt, ...) { - va_list args; - FILE *fout = stdout; - t_bool binarymode = FALSE; + va_list args; + FILE *fout = stdout; + t_bool binarymode = FALSE; #define DEBUG_TO_PRINTER #ifdef DEBUG_TO_PRINTER - if (prt_unit[0].fileref != NULL) { /* THIS IS TEMPORARY */ - fout = prt_unit[0].fileref; - binarymode = TRUE; - } + if (prt_unit[0].fileref != NULL) { /* THIS IS TEMPORARY */ + fout = prt_unit[0].fileref; + binarymode = TRUE; + } #endif - va_start(args, fmt); - vfprintf(fout, fmt, args); - if (cpu_unit.flags & UNIT_ATT) - vfprintf(cpu_unit.fileref, fmt, args); - va_end(args); + va_start(args, fmt); + vfprintf(fout, fmt, args); + if (cpu_unit.flags & UNIT_ATT) + vfprintf(cpu_unit.fileref, fmt, args); + va_end(args); - if (strchr(fmt, '\n') == NULL) { /* be sure to emit a newline */ - if (binarymode) - fputs(CRLF, fout); - else - putc('\n', fout); + if (strchr(fmt, '\n') == NULL) { /* be sure to emit a newline */ + if (binarymode) + fputs(CRLF, fout); + else + putc('\n', fout); - if (cpu_unit.flags & UNIT_ATT) - fputs(CRLF, cpu_unit.fileref); - } + if (cpu_unit.flags & UNIT_ATT) + fputs(CRLF, cpu_unit.fileref); + } } #ifdef _WIN32 @@ -1920,27 +1920,27 @@ void debug_print (const char *fmt, ...) static t_stat view_cmd (int32 flag, CONST char *cptr) { #ifdef _WIN32 - char cmdline[256]; + char cmdline[256]; - sprintf(cmdline, "notepad %s", cptr); - WinExec(cmdline, SW_SHOWNORMAL); + sprintf(cmdline, "notepad %s", cptr); + WinExec(cmdline, SW_SHOWNORMAL); #endif - return SCPE_OK; + return SCPE_OK; } /* web server version - hooks for CGI mode. These function pointer can be set by the CGI version's main() routine */ -void (*cgi_start_hook)(void) = NULL; /* these can be defined by a CGI wrapper to do things on start and stop of simulation */ +void (*cgi_start_hook)(void) = NULL; /* these can be defined by a CGI wrapper to do things on start and stop of simulation */ void (*cgi_end_hook)(void) = NULL; static void cgi_start (void) { - if (cgi_start_hook != NULL) - (*cgi_start_hook)(); + if (cgi_start_hook != NULL) + (*cgi_start_hook)(); } static void cgi_stop (t_stat reason) { - if (cgi_end_hook != NULL) - (*cgi_end_hook)(); + if (cgi_end_hook != NULL) + (*cgi_end_hook)(); } diff --git a/Ibm1130/ibm1130_cr.c b/Ibm1130/ibm1130_cr.c index 1dac3f03..c0ce72dc 100644 --- a/Ibm1130/ibm1130_cr.c +++ b/Ibm1130/ibm1130_cr.c @@ -3,7 +3,7 @@ #include #ifdef _WIN32 -# include /* Microsoft puts definition of mktemp into io.h rather than stdlib.h */ +# include /* Microsoft puts definition of mktemp into io.h rather than stdlib.h */ #endif /* ibm1130_cr.c: IBM 1130 1442 Card Reader simulator @@ -23,19 +23,19 @@ * Update 2008-11-24 Made card reader attach always use read-only mode, so if file does not exist it will not be created as an empty file. Fixed bug in BOOT CR (cold start from card) - that resulted in seeing cold card data again when next card was read. (This caused - the DMS load deck to fail, for instance). + that resulted in seeing cold card data again when next card was read. (This caused + the DMS load deck to fail, for instance). * Update 2007-05-01 Changed name of function xio_1142_card to xio_1442_card. - Took six years to notice the mistake. + Took six years to notice the mistake. * Update 2006-01-23 More fixes, in call to mktemp and in 2501 support, also thanks - to Carl Claunch. + to Carl Claunch. * Update 2006-01-03 Fixed bug found by Carl Claunch: feed function does not - cause an operation complete interrupt. Standard DMS routines were not - sensitive to this but DUP uses its own interrupt handler, and this - is why DUP would hang at end of deck. + cause an operation complete interrupt. Standard DMS routines were not + sensitive to this but DUP uses its own interrupt handler, and this + is why DUP would hang at end of deck. * Update 2005-05-19 Added support for 2501 reader @@ -46,10 +46,10 @@ * Update 2004-06-05: Removed "feedcycle" from cr_reset. Reset should not touch the card reader. * Update 2004-04-12: Changed ascii field of CPCODE to unsigned char, caught a couple - other potential problems with signed characters used as subscript indexes. + other potential problems with signed characters used as subscript indexes. * Update 2003-11-25: Physical card reader support working, may not be perfect. - Changed magic filename for stdin to "(stdin)". + Changed magic filename for stdin to "(stdin)". * Update 2003-07-23: Added autodetect for card decks (029 vs binary), made this the default. @@ -73,13 +73,13 @@ -q quiet mode, the simulator will not print the name of each file it opens while processing deck files (which are discussed below). For example, - - ATTACH CR -q @deckfile + + ATTACH CR -q @deckfile -l makes the simulator convert lower case letters in text decks to the IBM lower-case Hollerith character codes. Normally, the simulator - converts lower case input to the uppercase Hollerith character codes. - (Lowercase codes are used in APL\1130 save decks). + converts lower case input to the uppercase Hollerith character codes. + (Lowercase codes are used in APL\1130 save decks). -d prints a lot of simulator debugging information @@ -110,8 +110,8 @@ arguments to ibm1130, or to the "do" command if a "do" script is executing, if the attach command is constructed this way: - attach CR @deckfile %1 %2 %3 - + attach CR @deckfile %1 %2 %3 + This will pass the ibm1130 or do script arguments to attach, which will make them available in the deckfile. Then, for instance the line @@ -123,13 +123,13 @@ Filenames may be followed by whitespace and one or more mode options: The mode options are: - - b forces interpration as raw binary - a forces conversion from ascii to 029 coding, tabs are left alone - af forces 029 ascii conversion, and interprets tabs in Fortran mode - aa forces 029 ascii conversion, and interprets tabs in 1130 Assembler mode - at forces 029 ascii conversion, and interprets tabs with settings every 8 spaces - a# forces 029 ascii conversion, and interprets tabs with settings every # spaces + + b forces interpration as raw binary + a forces conversion from ascii to 029 coding, tabs are left alone + af forces 029 ascii conversion, and interprets tabs in Fortran mode + aa forces 029 ascii conversion, and interprets tabs in 1130 Assembler mode + at forces 029 ascii conversion, and interprets tabs with settings every 8 spaces + a# forces 029 ascii conversion, and interprets tabs with settings every # spaces If "a" or "b" mode is not specified, the device mode setting is used. In this case, if the mode is "auto", the simulator will select binary or 029 by inspecting each @@ -144,9 +144,9 @@ reads filenames from file "decklist," which might contain: file01.for xf - file02.dat a - file03 bin b - file04 bin + file02.dat a + file03 bin b + file04 bin ('a' means 029, so, if you need 026 coding, specify the device default as the correct 026 code and omit the 'a' on the text files lines). @@ -179,11 +179,11 @@ CODE_029, CODE_26F, etc, corresponding to different code sets. Punch and reader modes can be set independently using - set cr binary set cp binary * - set cr 029 set cp 029 - set cr 026f set cp 026f - set cr 026c set cp 026c - set cr auto * + set cr binary set cp binary * + set cr 029 set cp 029 + set cr 026f set cp 026f + set cr 026c set cp 026c + set cr auto * (* = default mode) @@ -198,54 +198,54 @@ with the attach command or in a decklist, as discussed earlier Fortran mode: - Input lines of the form + Input lines of the form - [label]statement + [label]statement - or + or - [label]+continuation + [label]+continuation - (where + is any nonalphabetic character) are rearranged in the - appropriate manner: + (where + is any nonalphabetic character) are rearranged in the + appropriate manner: - 1 2 - 12345678901234567890... - ------------------------ - label statement - label+continuation + 1 2 + 12345678901234567890... + ------------------------ + label statement + label+continuation - However, you must take care that you don't end up with statement text after column 72. + However, you must take care that you don't end up with statement text after column 72. - Input lines with * or C in column 1 (comments and directives) and lines without tabs - are left alone. + Input lines with * or C in column 1 (comments and directives) and lines without tabs + are left alone. - (The ! escape is not used before Fortran directives as before Assembler directives) + (The ! escape is not used before Fortran directives as before Assembler directives) Assembler mode: - Input lines of the form + Input lines of the form - [label][opcode][tag][L][argument] + [label][opcode][tag][L][argument] - are rearranged so that the input fields are placed in the appropriate columns + are rearranged so that the input fields are placed in the appropriate columns - The label must start on the first character of the line. If there is no label, - the first character(s) before the opcode must be whitespace. Following the opcode, there - MUST be a tab character, followed by the format and tag. Following the format and tag - may be exactly one whitespace character, and then starts the argument. + The label must start on the first character of the line. If there is no label, + the first character(s) before the opcode must be whitespace. Following the opcode, there + MUST be a tab character, followed by the format and tag. Following the format and tag + may be exactly one whitespace character, and then starts the argument. - Input lines with * in column 1 and blank lines are turned into Assembler comments, - with the * in the Opcode field. + Input lines with * in column 1 and blank lines are turned into Assembler comments, + with the * in the Opcode field. - Assembler directive lines at the beginning of the deck must be preceded by - ! to indicate that they are not comments. For example, + Assembler directive lines at the beginning of the deck must be preceded by + ! to indicate that they are not comments. For example, - !*LIST - * This is a comment + !*LIST + * This is a comment Plain Tab mode: - Tabs are replaced with spaces. Tab settings are assumed to be eight characters wide, - as is standard for vi, notepad, etc. + Tabs are replaced with spaces. Tab settings are assumed to be eight characters wide, + as is standard for vi, notepad, etc. * CGI mode note: The command @@ -270,9 +270,9 @@ way to solve the problem, the other is to keep DSW up-to-date all the time). The 1442 card read/punch has several cycles: - feed cycle: moves card from hopper to read station - card from read station to punch station - card from punch station to stacker + feed cycle: moves card from hopper to read station + card from read station to punch station + card from punch station to stacker read or punch: operates on card at read or punch station (but not both). @@ -305,8 +305,8 @@ way to solve the problem, the other is to keep DSW up-to-date all the time). Binary format is stored using fxwrite of short ints, in this format: 1 1 - 2 2 0 1 2 3 4 5 6 7 8 9 - * * * * * * * * * * * * 0 0 0 0 + 2 2 0 1 2 3 4 5 6 7 8 9 + * * * * * * * * * * * * 0 0 0 0 MSB LSB byte 0 [ 6] [ 7] [ 8] [ 9] 0 0 0 0 @@ -337,15 +337,15 @@ way to solve the problem, the other is to keep DSW up-to-date all the time). 7 | 8 | 9 | - +------------------ - - - + +------------------ - - - - 12 11 0 1 2 3 4 5 6 7 8 9 <- columns of cold start card - | | | | | 0 0 0 / \ | | | | | | - +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ - | 0| 1| 2| 3| 4| 5| 6| 7| 8| 9|10|11|12|13|14|15| - +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ - | OPCODE | F| Tag | DISPLACEMENT | - +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + 12 11 0 1 2 3 4 5 6 7 8 9 <- columns of cold start card + | | | | | 0 0 0 / \ | | | | | | + +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + | 0| 1| 2| 3| 4| 5| 6| 7| 8| 9|10|11|12|13|14|15| + +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + | OPCODE | F| Tag | DISPLACEMENT | + +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ The zeros mean that all IPL instructions are short form, nonindexed. The 3 column is repeated in bits 8 and 9 so @@ -356,9 +356,9 @@ way to solve the problem, the other is to keep DSW up-to-date all the time). deck isn't allowed. */ -#define READ_DELAY 35 /* see how small a number we can get away with */ -#define PUNCH_DELAY 35 -#define FEED_DELAY 25 +#define READ_DELAY 35 /* see how small a number we can get away with */ +#define PUNCH_DELAY 35 +#define FEED_DELAY 25 #define READ_2501_DELAY 500 /* umm, this is a weird little future project of mine. */ @@ -372,354 +372,354 @@ static t_stat cr_reset (DEVICE *dptr); static t_stat cr_set_code (UNIT *uptr, int32 match, CONST char *cptr, void *desc); static t_stat cr_attach (UNIT *uptr, CONST char *cptr); static int32 guess_cr_code (void); -static void feedcycle (t_bool load, t_bool punching); +static void feedcycle (t_bool load, t_bool punching); -static t_stat cp_reset (DEVICE *dptr); +static t_stat cp_reset (DEVICE *dptr); static t_stat cp_set_code (UNIT *uptr, int32 match, CONST char *cptr, void *desc); static t_stat cp_attach (UNIT *uptr, CONST char *cptr); static t_stat cp_detach (UNIT *uptr); -static int16 cr_dsw = 0; /* device status word */ -static int32 cr_wait = READ_DELAY; /* read per-column wait */ -static int32 cr_wait2501 = READ_2501_DELAY; /* read card wait for 2501 reader */ -static int32 cf_wait = PUNCH_DELAY; /* punch per-column wait */ -static int32 cp_wait = FEED_DELAY; /* feed op wait */ -static int32 cr_count= 0; /* read and punch card count */ +static int16 cr_dsw = 0; /* device status word */ +static int32 cr_wait = READ_DELAY; /* read per-column wait */ +static int32 cr_wait2501 = READ_2501_DELAY; /* read card wait for 2501 reader */ +static int32 cf_wait = PUNCH_DELAY; /* punch per-column wait */ +static int32 cp_wait = FEED_DELAY; /* feed op wait */ +static int32 cr_count= 0; /* read and punch card count */ static int32 cp_count= 0; -static int32 cr_addr = 0; /* 2501 reader transfer address */ -static int32 cr_cols = 0; /* 2501 reader column count */ +static int32 cr_addr = 0; /* 2501 reader transfer address */ +static int32 cr_cols = 0; /* 2501 reader column count */ -#define UNIT_V_OPERATION (UNIT_V_UF + 0) /* operation in progress */ -#define UNIT_V_CODE (UNIT_V_UF + 2) /* three bits */ -#define UNIT_V_CR_EMPTY (UNIT_V_UF + 5) /* NOTE: THIS MUST BE SET IN ibm1130_gui.c too */ -#define UNIT_V_SCRATCH (UNIT_V_UF + 6) +#define UNIT_V_OPERATION (UNIT_V_UF + 0) /* operation in progress */ +#define UNIT_V_CODE (UNIT_V_UF + 2) /* three bits */ +#define UNIT_V_CR_EMPTY (UNIT_V_UF + 5) /* NOTE: THIS MUST BE SET IN ibm1130_gui.c too */ +#define UNIT_V_SCRATCH (UNIT_V_UF + 6) #define UNIT_V_QUIET (UNIT_V_UF + 7) #define UNIT_V_DEBUG (UNIT_V_UF + 8) -#define UNIT_V_PHYSICAL (UNIT_V_UF + 9) /* NOTE: THIS MUST BE SET IN ibm1130_gui.c too */ -#define UNIT_V_LASTPUNCH (UNIT_V_UF + 10) /* used in unit_cp only */ -#define UNIT_V_LOWERCASE (UNIT_V_UF + 10) /* used in unit_cr only */ -#define UNIT_V_ACTCODE (UNIT_V_UF + 11) /* used in unit_cr only, 3 bits */ -#define UNIT_V_2501 (UNIT_V_UF + 14) +#define UNIT_V_PHYSICAL (UNIT_V_UF + 9) /* NOTE: THIS MUST BE SET IN ibm1130_gui.c too */ +#define UNIT_V_LASTPUNCH (UNIT_V_UF + 10) /* used in unit_cp only */ +#define UNIT_V_LOWERCASE (UNIT_V_UF + 10) /* used in unit_cr only */ +#define UNIT_V_ACTCODE (UNIT_V_UF + 11) /* used in unit_cr only, 3 bits */ +#define UNIT_V_2501 (UNIT_V_UF + 14) -#define UNIT_OP (3u << UNIT_V_OPERATION) /* two bits */ -#define UNIT_CODE (7u << UNIT_V_CODE) /* three bits */ -#define UNIT_CR_EMPTY (1u << UNIT_V_CR_EMPTY) -#define UNIT_SCRATCH (1u << UNIT_V_SCRATCH) /* temp file */ +#define UNIT_OP (3u << UNIT_V_OPERATION) /* two bits */ +#define UNIT_CODE (7u << UNIT_V_CODE) /* three bits */ +#define UNIT_CR_EMPTY (1u << UNIT_V_CR_EMPTY) +#define UNIT_SCRATCH (1u << UNIT_V_SCRATCH) /* temp file */ #define UNIT_QUIET (1u << UNIT_V_QUIET) #define UNIT_DEBUG (1u << UNIT_V_DEBUG) -#define UNIT_PHYSICAL (1u << UNIT_V_PHYSICAL) -#define UNIT_LASTPUNCH (1u << UNIT_V_LASTPUNCH) -#define UNIT_LOWERCASE (1u << UNIT_V_LOWERCASE) /* permit lowercase input (needed for APL) */ -#define UNIT_ACTCODE (7u << UNIT_V_ACTCODE) -#define UNIT_2501 (1u << UNIT_V_2501) +#define UNIT_PHYSICAL (1u << UNIT_V_PHYSICAL) +#define UNIT_LASTPUNCH (1u << UNIT_V_LASTPUNCH) +#define UNIT_LOWERCASE (1u << UNIT_V_LOWERCASE) /* permit lowercase input (needed for APL) */ +#define UNIT_ACTCODE (7u << UNIT_V_ACTCODE) +#define UNIT_2501 (1u << UNIT_V_2501) -#define OP_IDLE (0u << UNIT_V_OPERATION) -#define OP_READING (1u << UNIT_V_OPERATION) -#define OP_PUNCHING (2u << UNIT_V_OPERATION) -#define OP_FEEDING (3u << UNIT_V_OPERATION) +#define OP_IDLE (0u << UNIT_V_OPERATION) +#define OP_READING (1u << UNIT_V_OPERATION) +#define OP_PUNCHING (2u << UNIT_V_OPERATION) +#define OP_FEEDING (3u << UNIT_V_OPERATION) -#define SET_OP(op) {cr_unit.flags &= ~UNIT_OP; cr_unit.flags |= (op);} -#define CURRENT_OP (cr_unit.flags & UNIT_OP) +#define SET_OP(op) {cr_unit.flags &= ~UNIT_OP; cr_unit.flags |= (op);} +#define CURRENT_OP (cr_unit.flags & UNIT_OP) -#define CODE_AUTO (0u << UNIT_V_CODE) -#define CODE_029 (1u << UNIT_V_CODE) -#define CODE_026F (2u << UNIT_V_CODE) -#define CODE_026C (3u << UNIT_V_CODE) -#define CODE_BINARY (4u << UNIT_V_CODE) +#define CODE_AUTO (0u << UNIT_V_CODE) +#define CODE_029 (1u << UNIT_V_CODE) +#define CODE_026F (2u << UNIT_V_CODE) +#define CODE_026C (3u << UNIT_V_CODE) +#define CODE_BINARY (4u << UNIT_V_CODE) #define GET_CODE(un) (un.flags & UNIT_CODE) #define SET_CODE(un,cd) {un.flags &= ~UNIT_CODE; un.flags |= (cd);} -#define ACTCODE_029 (CODE_029 << (UNIT_V_ACTCODE-UNIT_V_CODE)) /* these are used ONLY in MTAB. Elsewhere */ -#define ACTCODE_026F (CODE_026F << (UNIT_V_ACTCODE-UNIT_V_CODE)) /* we use values CODE_xxx with macros */ -#define ACTCODE_026C (CODE_026C << (UNIT_V_ACTCODE-UNIT_V_CODE)) /* GET_ACTCODE and SET_ACTCODE. */ -#define ACTCODE_BINARY (CODE_BINARY << (UNIT_V_ACTCODE-UNIT_V_CODE)) +#define ACTCODE_029 (CODE_029 << (UNIT_V_ACTCODE-UNIT_V_CODE)) /* these are used ONLY in MTAB. Elsewhere */ +#define ACTCODE_026F (CODE_026F << (UNIT_V_ACTCODE-UNIT_V_CODE)) /* we use values CODE_xxx with macros */ +#define ACTCODE_026C (CODE_026C << (UNIT_V_ACTCODE-UNIT_V_CODE)) /* GET_ACTCODE and SET_ACTCODE. */ +#define ACTCODE_BINARY (CODE_BINARY << (UNIT_V_ACTCODE-UNIT_V_CODE)) - /* get/set macros for actual-code field, these use values like CODE_029 meant for the UNIT_CODE field */ + /* get/set macros for actual-code field, these use values like CODE_029 meant for the UNIT_CODE field */ #define GET_ACTCODE(un) ((un.flags & UNIT_ACTCODE) >> (UNIT_V_ACTCODE-UNIT_V_CODE)) #define SET_ACTCODE(un,cd) {un.flags &= ~UNIT_ACTCODE; un.flags |= (cd) << (UNIT_V_ACTCODE-UNIT_V_CODE);} -#define COLUMN u4 /* column field in unit record */ +#define COLUMN u4 /* column field in unit record */ UNIT cr_unit = { UDATA (&cr_svc, UNIT_ATTABLE|UNIT_ROABLE|UNIT_CR_EMPTY, 0) }; UNIT cp_unit = { UDATA (NULL, UNIT_ATTABLE, 0) }; MTAB cr_mod[] = { - { UNIT_CODE, CODE_029, "029", "029", &cr_set_code}, - { UNIT_CODE, CODE_026F, "026F", "026F", &cr_set_code}, - { UNIT_CODE, CODE_026C, "026C", "026C", &cr_set_code}, - { UNIT_CODE, CODE_BINARY, "BINARY", "BINARY", &cr_set_code}, - { UNIT_CODE, CODE_AUTO, "AUTO", "AUTO", &cr_set_code}, - { UNIT_ACTCODE, ACTCODE_029, "(029)", NULL, NULL}, /* display-only, shows current mode */ - { UNIT_ACTCODE, ACTCODE_026F, "(026F)", NULL, NULL}, - { UNIT_ACTCODE, ACTCODE_026C, "(026C)", NULL, NULL}, - { UNIT_ACTCODE, ACTCODE_BINARY, "(BINARY)", NULL, NULL}, - { UNIT_2501, 0, "1442", "1442", NULL}, - { UNIT_2501, UNIT_2501, "2501", "2501", NULL}, - { 0 } }; + { UNIT_CODE, CODE_029, "029", "029", &cr_set_code}, + { UNIT_CODE, CODE_026F, "026F", "026F", &cr_set_code}, + { UNIT_CODE, CODE_026C, "026C", "026C", &cr_set_code}, + { UNIT_CODE, CODE_BINARY, "BINARY", "BINARY", &cr_set_code}, + { UNIT_CODE, CODE_AUTO, "AUTO", "AUTO", &cr_set_code}, + { UNIT_ACTCODE, ACTCODE_029, "(029)", NULL, NULL}, /* display-only, shows current mode */ + { UNIT_ACTCODE, ACTCODE_026F, "(026F)", NULL, NULL}, + { UNIT_ACTCODE, ACTCODE_026C, "(026C)", NULL, NULL}, + { UNIT_ACTCODE, ACTCODE_BINARY, "(BINARY)", NULL, NULL}, + { UNIT_2501, 0, "1442", "1442", NULL}, + { UNIT_2501, UNIT_2501, "2501", "2501", NULL}, + { 0 } }; MTAB cp_mod[] = { - { UNIT_CODE, CODE_029, "029", "029", &cp_set_code}, - { UNIT_CODE, CODE_026F, "026F", "026F", &cp_set_code}, - { UNIT_CODE, CODE_026C, "026C", "026C", &cp_set_code}, - { UNIT_CODE, CODE_BINARY, "BINARY", "BINARY", &cp_set_code}, - { 0 } }; + { UNIT_CODE, CODE_029, "029", "029", &cp_set_code}, + { UNIT_CODE, CODE_026F, "026F", "026F", &cp_set_code}, + { UNIT_CODE, CODE_026C, "026C", "026C", &cp_set_code}, + { UNIT_CODE, CODE_BINARY, "BINARY", "BINARY", &cp_set_code}, + { 0 } }; REG cr_reg[] = { - { HRDATA (CRDSW, cr_dsw, 16) }, /* device status word */ - { DRDATA (CRTIME, cr_wait, 24), PV_LEFT }, /* operation wait for 1442 column read*/ - { DRDATA (2501TIME, cr_wait2501, 24), PV_LEFT }, /* operation wait for 2501 whole card read*/ - { DRDATA (CFTIME, cf_wait, 24), PV_LEFT }, /* operation wait */ - { DRDATA (CRCOUNT, cr_count, 32),PV_LEFT }, /* number of cards read since last attach cmd */ - { HRDATA (CRADDR, cr_addr, 32) }, /* 2501 reader transfer address */ - { HRDATA (CRCOLS, cr_cols, 32) }, /* 2501 reader column count */ - { NULL } }; + { HRDATA (CRDSW, cr_dsw, 16) }, /* device status word */ + { DRDATA (CRTIME, cr_wait, 24), PV_LEFT }, /* operation wait for 1442 column read*/ + { DRDATA (2501TIME, cr_wait2501, 24), PV_LEFT }, /* operation wait for 2501 whole card read*/ + { DRDATA (CFTIME, cf_wait, 24), PV_LEFT }, /* operation wait */ + { DRDATA (CRCOUNT, cr_count, 32),PV_LEFT }, /* number of cards read since last attach cmd */ + { HRDATA (CRADDR, cr_addr, 32) }, /* 2501 reader transfer address */ + { HRDATA (CRCOLS, cr_cols, 32) }, /* 2501 reader column count */ + { NULL } }; REG cp_reg[] = { - { DRDATA (CPTIME, cp_wait, 24), PV_LEFT }, /* operation wait */ - { DRDATA (CPCOUNT, cp_count, 32),PV_LEFT }, /* number of cards punched since last attach cmd */ - { NULL } }; + { DRDATA (CPTIME, cp_wait, 24), PV_LEFT }, /* operation wait */ + { DRDATA (CPCOUNT, cp_count, 32),PV_LEFT }, /* number of cards punched since last attach cmd */ + { NULL } }; DEVICE cr_dev = { - "CR", &cr_unit, cr_reg, cr_mod, - 1, 16, 16, 1, 16, 16, - NULL, NULL, cr_reset, - cr_boot, cr_attach, cr_detach}; + "CR", &cr_unit, cr_reg, cr_mod, + 1, 16, 16, 1, 16, 16, + NULL, NULL, cr_reset, + cr_boot, cr_attach, cr_detach}; DEVICE cp_dev = { - "CP", &cp_unit, cp_reg, cp_mod, - 1, 16, 16, 1, 16, 16, - NULL, NULL, cp_reset, - NULL, cp_attach, cp_detach}; + "CP", &cp_unit, cp_reg, cp_mod, + 1, 16, 16, 1, 16, 16, + NULL, NULL, cp_reset, + NULL, cp_attach, cp_detach}; -#define CR_DSW_1442_READ_RESPONSE 0x8000 /* device status word bits */ -#define CR_DSW_1442_PUNCH_RESPONSE 0x4000 -#define CR_DSW_1442_ERROR_CHECK 0x2000 -#define CR_DSW_1442_LAST_CARD 0x1000 -#define CR_DSW_1442_OP_COMPLETE 0x0800 -#define CR_DSW_1442_FEED_CHECK 0x0100 -#define CR_DSW_1442_BUSY 0x0002 -#define CR_DSW_1442_NOT_READY 0x0001 +#define CR_DSW_1442_READ_RESPONSE 0x8000 /* device status word bits */ +#define CR_DSW_1442_PUNCH_RESPONSE 0x4000 +#define CR_DSW_1442_ERROR_CHECK 0x2000 +#define CR_DSW_1442_LAST_CARD 0x1000 +#define CR_DSW_1442_OP_COMPLETE 0x0800 +#define CR_DSW_1442_FEED_CHECK 0x0100 +#define CR_DSW_1442_BUSY 0x0002 +#define CR_DSW_1442_NOT_READY 0x0001 -#define CR_DSW_2501_ERROR_CHECK 0x2000 /* DSW for 2501 reader */ -#define CR_DSW_2501_LAST_CARD 0x1000 -#define CR_DSW_2501_OP_COMPLETE 0x0800 -#define CR_DSW_2501_BUSY 0x0002 -#define CR_DSW_2501_NOT_READY 0x0001 +#define CR_DSW_2501_ERROR_CHECK 0x2000 /* DSW for 2501 reader */ +#define CR_DSW_2501_LAST_CARD 0x1000 +#define CR_DSW_2501_OP_COMPLETE 0x0800 +#define CR_DSW_2501_BUSY 0x0002 +#define CR_DSW_2501_NOT_READY 0x0001 typedef struct { - uint16 hollerith; - unsigned char ascii; + uint16 hollerith; + unsigned char ascii; } CPCODE; static CPCODE cardcode_029[] = { - {0x0000, ' '}, - {0x8000, '&'}, /* + in 026 Fortran */ - {0x4000, '-'}, - {0x2000, '0'}, - {0x1000, '1'}, - {0x0800, '2'}, - {0x0400, '3'}, - {0x0200, '4'}, - {0x0100, '5'}, - {0x0080, '6'}, - {0x0040, '7'}, - {0x0020, '8'}, - {0x0010, '9'}, - {0x9000, 'A'}, - {0x8800, 'B'}, - {0x8400, 'C'}, - {0x8200, 'D'}, - {0x8100, 'E'}, - {0x8080, 'F'}, - {0x8040, 'G'}, - {0x8020, 'H'}, - {0x8010, 'I'}, - {0x5000, 'J'}, - {0x4800, 'K'}, - {0x4400, 'L'}, - {0x4200, 'M'}, - {0x4100, 'N'}, - {0x4080, 'O'}, - {0x4040, 'P'}, - {0x4020, 'Q'}, - {0x4010, 'R'}, - {0x3000, '/'}, - {0x2800, 'S'}, - {0x2400, 'T'}, - {0x2200, 'U'}, - {0x2100, 'V'}, - {0x2080, 'W'}, - {0x2040, 'X'}, - {0x2020, 'Y'}, - {0x2010, 'Z'}, - {0x0820, ':'}, - {0x0420, '#'}, /* = in 026 Fortran */ - {0x0220, '@'}, /* ' in 026 Fortran */ - {0x0120, '\''}, - {0x00A0, '='}, - {0x0060, '"'}, - {0x8820, (unsigned char) '\xA2'}, /* cent, in MS-DOS encoding (this is in guess_cr_code as well) */ - {0x8420, '.'}, - {0x8220, '<'}, /* ) in 026 Fortran */ - {0x8120, '('}, - {0x80A0, '+'}, - {0x8060, '|'}, - {0x4820, '!'}, - {0x4420, '$'}, - {0x4220, '*'}, - {0x4120, ')'}, - {0x40A0, ';'}, - {0x4060, (unsigned char) '\xAC'}, /* not, in MS-DOS encoding (this is in guess_cr_code as well) */ - {0x2420, ','}, - {0x2220, '%'}, /* ( in 026 Fortran */ - {0x2120, '_'}, - {0x20A0, '>'}, - {0xB000, 'a'}, - {0xA800, 'b'}, - {0xA400, 'c'}, - {0xA200, 'd'}, - {0xA100, 'e'}, - {0xA080, 'f'}, - {0xA040, 'g'}, - {0xA020, 'h'}, - {0xA010, 'i'}, - {0xD000, 'j'}, - {0xC800, 'k'}, - {0xC400, 'l'}, - {0xC200, 'm'}, - {0xC100, 'n'}, - {0xC080, 'o'}, - {0xC040, 'p'}, - {0xC020, 'q'}, - {0xC010, 'r'}, - {0x6800, 's'}, - {0x6400, 't'}, - {0x6200, 'u'}, - {0x6100, 'v'}, - {0x6080, 'w'}, - {0x6040, 'x'}, - {0x6020, 'y'}, - {0x6010, 'z'}, /* these odd punch codes are used by APL: */ - {0x1010, '\001'}, /* no corresponding ASCII using ^A */ - {0x0810, '\002'}, /* SYN using ^B */ - {0x0410, '\003'}, /* no corresponding ASCII using ^C */ - {0x0210, '\004'}, /* PUNCH ON using ^D */ - {0x0110, '\005'}, /* READER STOP using ^E */ - {0x0090, '\006'}, /* UPPER CASE using ^F */ - {0x0050, '\013'}, /* EOT using ^K */ - {0x0030, '\016'}, /* no corresponding ASCII using ^N */ - {0x1030, '\017'}, /* no corresponding ASCII using ^O */ - {0x0830, '\020'}, /* no corresponding ASCII using ^P */ + {0x0000, ' '}, + {0x8000, '&'}, /* + in 026 Fortran */ + {0x4000, '-'}, + {0x2000, '0'}, + {0x1000, '1'}, + {0x0800, '2'}, + {0x0400, '3'}, + {0x0200, '4'}, + {0x0100, '5'}, + {0x0080, '6'}, + {0x0040, '7'}, + {0x0020, '8'}, + {0x0010, '9'}, + {0x9000, 'A'}, + {0x8800, 'B'}, + {0x8400, 'C'}, + {0x8200, 'D'}, + {0x8100, 'E'}, + {0x8080, 'F'}, + {0x8040, 'G'}, + {0x8020, 'H'}, + {0x8010, 'I'}, + {0x5000, 'J'}, + {0x4800, 'K'}, + {0x4400, 'L'}, + {0x4200, 'M'}, + {0x4100, 'N'}, + {0x4080, 'O'}, + {0x4040, 'P'}, + {0x4020, 'Q'}, + {0x4010, 'R'}, + {0x3000, '/'}, + {0x2800, 'S'}, + {0x2400, 'T'}, + {0x2200, 'U'}, + {0x2100, 'V'}, + {0x2080, 'W'}, + {0x2040, 'X'}, + {0x2020, 'Y'}, + {0x2010, 'Z'}, + {0x0820, ':'}, + {0x0420, '#'}, /* = in 026 Fortran */ + {0x0220, '@'}, /* ' in 026 Fortran */ + {0x0120, '\''}, + {0x00A0, '='}, + {0x0060, '"'}, + {0x8820, (unsigned char) '\xA2'}, /* cent, in MS-DOS encoding (this is in guess_cr_code as well) */ + {0x8420, '.'}, + {0x8220, '<'}, /* ) in 026 Fortran */ + {0x8120, '('}, + {0x80A0, '+'}, + {0x8060, '|'}, + {0x4820, '!'}, + {0x4420, '$'}, + {0x4220, '*'}, + {0x4120, ')'}, + {0x40A0, ';'}, + {0x4060, (unsigned char) '\xAC'}, /* not, in MS-DOS encoding (this is in guess_cr_code as well) */ + {0x2420, ','}, + {0x2220, '%'}, /* ( in 026 Fortran */ + {0x2120, '_'}, + {0x20A0, '>'}, + {0xB000, 'a'}, + {0xA800, 'b'}, + {0xA400, 'c'}, + {0xA200, 'd'}, + {0xA100, 'e'}, + {0xA080, 'f'}, + {0xA040, 'g'}, + {0xA020, 'h'}, + {0xA010, 'i'}, + {0xD000, 'j'}, + {0xC800, 'k'}, + {0xC400, 'l'}, + {0xC200, 'm'}, + {0xC100, 'n'}, + {0xC080, 'o'}, + {0xC040, 'p'}, + {0xC020, 'q'}, + {0xC010, 'r'}, + {0x6800, 's'}, + {0x6400, 't'}, + {0x6200, 'u'}, + {0x6100, 'v'}, + {0x6080, 'w'}, + {0x6040, 'x'}, + {0x6020, 'y'}, + {0x6010, 'z'}, /* these odd punch codes are used by APL: */ + {0x1010, '\001'}, /* no corresponding ASCII using ^A */ + {0x0810, '\002'}, /* SYN using ^B */ + {0x0410, '\003'}, /* no corresponding ASCII using ^C */ + {0x0210, '\004'}, /* PUNCH ON using ^D */ + {0x0110, '\005'}, /* READER STOP using ^E */ + {0x0090, '\006'}, /* UPPER CASE using ^F */ + {0x0050, '\013'}, /* EOT using ^K */ + {0x0030, '\016'}, /* no corresponding ASCII using ^N */ + {0x1030, '\017'}, /* no corresponding ASCII using ^O */ + {0x0830, '\020'}, /* no corresponding ASCII using ^P */ }; -static CPCODE cardcode_026F[] = /* 026 fortran */ +static CPCODE cardcode_026F[] = /* 026 fortran */ { - {0x0000, ' '}, - {0x8000, '+'}, - {0x4000, '-'}, - {0x2000, '0'}, - {0x1000, '1'}, - {0x0800, '2'}, - {0x0400, '3'}, - {0x0200, '4'}, - {0x0100, '5'}, - {0x0080, '6'}, - {0x0040, '7'}, - {0x0020, '8'}, - {0x0010, '9'}, - {0x9000, 'A'}, - {0x8800, 'B'}, - {0x8400, 'C'}, - {0x8200, 'D'}, - {0x8100, 'E'}, - {0x8080, 'F'}, - {0x8040, 'G'}, - {0x8020, 'H'}, - {0x8010, 'I'}, - {0x5000, 'J'}, - {0x4800, 'K'}, - {0x4400, 'L'}, - {0x4200, 'M'}, - {0x4100, 'N'}, - {0x4080, 'O'}, - {0x4040, 'P'}, - {0x4020, 'Q'}, - {0x4010, 'R'}, - {0x3000, '/'}, - {0x2800, 'S'}, - {0x2400, 'T'}, - {0x2200, 'U'}, - {0x2100, 'V'}, - {0x2080, 'W'}, - {0x2040, 'X'}, - {0x2020, 'Y'}, - {0x2010, 'Z'}, - {0x0420, '='}, - {0x0220, '\''}, - {0x8420, '.'}, - {0x8220, ')'}, - {0x8220, '<'}, /* if ASCII has <, treat like ) */ - {0x4420, '$'}, - {0x4220, '*'}, - {0x2420, ','}, - {0x2220, '('}, - {0x2220, '%'}, /* if ASCII has %, treat like ) */ + {0x0000, ' '}, + {0x8000, '+'}, + {0x4000, '-'}, + {0x2000, '0'}, + {0x1000, '1'}, + {0x0800, '2'}, + {0x0400, '3'}, + {0x0200, '4'}, + {0x0100, '5'}, + {0x0080, '6'}, + {0x0040, '7'}, + {0x0020, '8'}, + {0x0010, '9'}, + {0x9000, 'A'}, + {0x8800, 'B'}, + {0x8400, 'C'}, + {0x8200, 'D'}, + {0x8100, 'E'}, + {0x8080, 'F'}, + {0x8040, 'G'}, + {0x8020, 'H'}, + {0x8010, 'I'}, + {0x5000, 'J'}, + {0x4800, 'K'}, + {0x4400, 'L'}, + {0x4200, 'M'}, + {0x4100, 'N'}, + {0x4080, 'O'}, + {0x4040, 'P'}, + {0x4020, 'Q'}, + {0x4010, 'R'}, + {0x3000, '/'}, + {0x2800, 'S'}, + {0x2400, 'T'}, + {0x2200, 'U'}, + {0x2100, 'V'}, + {0x2080, 'W'}, + {0x2040, 'X'}, + {0x2020, 'Y'}, + {0x2010, 'Z'}, + {0x0420, '='}, + {0x0220, '\''}, + {0x8420, '.'}, + {0x8220, ')'}, + {0x8220, '<'}, /* if ASCII has <, treat like ) */ + {0x4420, '$'}, + {0x4220, '*'}, + {0x2420, ','}, + {0x2220, '('}, + {0x2220, '%'}, /* if ASCII has %, treat like ) */ }; -static CPCODE cardcode_026C[] = /* 026 commercial */ +static CPCODE cardcode_026C[] = /* 026 commercial */ { - {0x0000, ' '}, - {0x8000, '+'}, - {0x4000, '-'}, - {0x2000, '0'}, - {0x1000, '1'}, - {0x0800, '2'}, - {0x0400, '3'}, - {0x0200, '4'}, - {0x0100, '5'}, - {0x0080, '6'}, - {0x0040, '7'}, - {0x0020, '8'}, - {0x0010, '9'}, - {0x9000, 'A'}, - {0x8800, 'B'}, - {0x8400, 'C'}, - {0x8200, 'D'}, - {0x8100, 'E'}, - {0x8080, 'F'}, - {0x8040, 'G'}, - {0x8020, 'H'}, - {0x8010, 'I'}, - {0x5000, 'J'}, - {0x4800, 'K'}, - {0x4400, 'L'}, - {0x4200, 'M'}, - {0x4100, 'N'}, - {0x4080, 'O'}, - {0x4040, 'P'}, - {0x4020, 'Q'}, - {0x4010, 'R'}, - {0x3000, '/'}, - {0x2800, 'S'}, - {0x2400, 'T'}, - {0x2200, 'U'}, - {0x2100, 'V'}, - {0x2080, 'W'}, - {0x2040, 'X'}, - {0x2020, 'Y'}, - {0x2010, 'Z'}, - {0x0420, '='}, - {0x0220, '\''}, - {0x8420, '.'}, - {0x8220, '<'}, - {0x8220, ')'}, /* if ASCII has ), treat like < */ - {0x4420, '$'}, - {0x4220, '*'}, - {0x2420, ','}, - {0x2220, '%'}, - {0x2220, '('}, /* if ASCII has (, treat like % */ + {0x0000, ' '}, + {0x8000, '+'}, + {0x4000, '-'}, + {0x2000, '0'}, + {0x1000, '1'}, + {0x0800, '2'}, + {0x0400, '3'}, + {0x0200, '4'}, + {0x0100, '5'}, + {0x0080, '6'}, + {0x0040, '7'}, + {0x0020, '8'}, + {0x0010, '9'}, + {0x9000, 'A'}, + {0x8800, 'B'}, + {0x8400, 'C'}, + {0x8200, 'D'}, + {0x8100, 'E'}, + {0x8080, 'F'}, + {0x8040, 'G'}, + {0x8020, 'H'}, + {0x8010, 'I'}, + {0x5000, 'J'}, + {0x4800, 'K'}, + {0x4400, 'L'}, + {0x4200, 'M'}, + {0x4100, 'N'}, + {0x4080, 'O'}, + {0x4040, 'P'}, + {0x4020, 'Q'}, + {0x4010, 'R'}, + {0x3000, '/'}, + {0x2800, 'S'}, + {0x2400, 'T'}, + {0x2200, 'U'}, + {0x2100, 'V'}, + {0x2080, 'W'}, + {0x2040, 'X'}, + {0x2020, 'Y'}, + {0x2010, 'Z'}, + {0x0420, '='}, + {0x0220, '\''}, + {0x8420, '.'}, + {0x8220, '<'}, + {0x8220, ')'}, /* if ASCII has ), treat like < */ + {0x4420, '$'}, + {0x4220, '*'}, + {0x2420, ','}, + {0x2220, '%'}, + {0x2220, '('}, /* if ASCII has (, treat like % */ }; extern int cgi; @@ -732,11 +732,11 @@ static FILE *deckfile = NULL; static char tempfile[128]; static int any_punched = 0; -#define MAXARGLEN 80 /* max length of a saved attach command argument */ -#define MAXARGS 10 /* max number of arguments to save */ +#define MAXARGLEN 80 /* max length of a saved attach command argument */ +#define MAXARGS 10 /* max number of arguments to save */ static char list_save[MAXARGS][MAXARGLEN], *list_arg[MAXARGLEN+1]; static int list_nargs = 0; -static const char* (*tab_proc)(char* str, int width) = NULL; /* tab reformatting routine */ +static const char* (*tab_proc)(char* str, int width) = NULL; /* tab reformatting routine */ static int tab_width = 8; static uint16 punchstation[80]; @@ -758,425 +758,425 @@ static void pcr_reset(void); static t_bool lookup_codetable (int32 match, CPCODE **pcode, int *pncode) { - switch (match) { - case CODE_029: - *pcode = cardcode_029; - *pncode = sizeof(cardcode_029) / sizeof(CPCODE); - break; + switch (match) { + case CODE_029: + *pcode = cardcode_029; + *pncode = sizeof(cardcode_029) / sizeof(CPCODE); + break; - case CODE_026F: - *pcode = cardcode_026F; - *pncode = sizeof(cardcode_026F) / sizeof(CPCODE); - break; + case CODE_026F: + *pcode = cardcode_026F; + *pncode = sizeof(cardcode_026F) / sizeof(CPCODE); + break; - case CODE_026C: - *pcode = cardcode_026C; - *pncode = sizeof(cardcode_026C) / sizeof(CPCODE); - break; + case CODE_026C: + *pcode = cardcode_026C; + *pncode = sizeof(cardcode_026C) / sizeof(CPCODE); + break; - case CODE_BINARY: - *pcode = NULL; - *pncode = 0; - break; + case CODE_BINARY: + *pcode = NULL; + *pncode = 0; + break; - default: - printf("Eek! Undefined code table index"); - return FALSE; - } - return TRUE; + default: + printf("Eek! Undefined code table index"); + return FALSE; + } + return TRUE; } t_stat set_active_cr_code (int match) { - CPCODE *code; - int i, ncode; + CPCODE *code; + int i, ncode; - SET_ACTCODE(cr_unit, match); + SET_ACTCODE(cr_unit, match); - if (! lookup_codetable(match, &code, &ncode)) - return SCPE_ARG; + if (! lookup_codetable(match, &code, &ncode)) + return SCPE_ARG; - if (code != NULL) { /* if an ASCII mode was selected */ - memset(ascii_to_card, 0, sizeof(ascii_to_card)); + if (code != NULL) { /* if an ASCII mode was selected */ + memset(ascii_to_card, 0, sizeof(ascii_to_card)); - for (i = 0; i < ncode; i++) /* set ascii to card code table */ - ascii_to_card[code[i].ascii] = code[i].hollerith; - } + for (i = 0; i < ncode; i++) /* set ascii to card code table */ + ascii_to_card[code[i].ascii] = code[i].hollerith; + } - return SCPE_OK; + return SCPE_OK; } static t_stat cr_set_code (UNIT *uptr, int32 match, CONST char *cptr, void *desc) { - if (match == CODE_AUTO) - match = guess_cr_code(); + if (match == CODE_AUTO) + match = guess_cr_code(); - return set_active_cr_code(match); + return set_active_cr_code(match); } static int32 guess_cr_code (void) { - int i; - long filepos; - int32 guess; - union { - uint16 w[80]; /* one card image, viewed as 80 short words */ - char c[160]; /* same, viewed as 160 characters */ - } line; + int i; + long filepos; + int32 guess; + union { + uint16 w[80]; /* one card image, viewed as 80 short words */ + char c[160]; /* same, viewed as 160 characters */ + } line; - /* here, we can see if the attached file is binary or ascii and auto-set the - * mode. If we the file is a binary deck, we should be able to read a record of 80 short - * words, and the low 4 bits of each word must be zero. If the file was an ascii deck, - * then these low 4 bits are the low 4 bits of every other character in the first 160 - * chararacters of the file. They would all only be 0 if all of these characters were - * in the following set: {NUL ^P space 0 @ P ` p} . It seems very unlikely that - * this would happen, as even if the deck consisted of untrimmed card images and - * the first two lines were blank, the 81'st character would be a newline, and it would - * appear at one of the every-other characters seen on little-endian machines, anyway. - * So: if the code mode is AUTO, we can use this test and select either BINARY or 029. - * Might as well also check for the all-blanks and newlines case in case this is a - * big-endian machine. - */ + /* here, we can see if the attached file is binary or ascii and auto-set the + * mode. If we the file is a binary deck, we should be able to read a record of 80 short + * words, and the low 4 bits of each word must be zero. If the file was an ascii deck, + * then these low 4 bits are the low 4 bits of every other character in the first 160 + * chararacters of the file. They would all only be 0 if all of these characters were + * in the following set: {NUL ^P space 0 @ P ` p} . It seems very unlikely that + * this would happen, as even if the deck consisted of untrimmed card images and + * the first two lines were blank, the 81'st character would be a newline, and it would + * appear at one of the every-other characters seen on little-endian machines, anyway. + * So: if the code mode is AUTO, we can use this test and select either BINARY or 029. + * Might as well also check for the all-blanks and newlines case in case this is a + * big-endian machine. + */ - guess = CODE_029; /* assume ASCII, 029 */ + guess = CODE_029; /* assume ASCII, 029 */ - if ((cr_unit.flags & UNIT_ATT) && (cr_unit.fileref != NULL)) { - filepos = ftell(cr_unit.fileref); /* remember current position in file */ - fseek(cr_unit.fileref, 0, SEEK_SET); /* go to first record of file */ - /* read card image; if file too short, leave guess set to 029 */ - if (fxread(line.w, sizeof(line.w[0]), 80, cr_unit.fileref) == 80) { - guess = CODE_BINARY; /* we got a card image, assume binary */ + if ((cr_unit.flags & UNIT_ATT) && (cr_unit.fileref != NULL)) { + filepos = ftell(cr_unit.fileref); /* remember current position in file */ + fseek(cr_unit.fileref, 0, SEEK_SET); /* go to first record of file */ + /* read card image; if file too short, leave guess set to 029 */ + if (fxread(line.w, sizeof(line.w[0]), 80, cr_unit.fileref) == 80) { + guess = CODE_BINARY; /* we got a card image, assume binary */ - for (i = 0; i < 80; i++) { /* make sure low bits are zeroes, which our binary card format promises */ - if (line.w[i] & 0x000F) { - guess = CODE_029; /* low bits set, must be ascii text */ - break; - } - } + for (i = 0; i < 80; i++) { /* make sure low bits are zeroes, which our binary card format promises */ + if (line.w[i] & 0x000F) { + guess = CODE_029; /* low bits set, must be ascii text */ + break; + } + } - if (guess == CODE_BINARY) { /* if we saw no low bits, it could have been all spaces. */ - guess = CODE_029; /* so now assume file is text */ - for (i = 0; i < 160; i++) { /* ensure all 160 characters are 7-bit ASCII (or not or cent) */ - /* 3.0-3, changed test for > 0x7f to & 0x80 */ - if ((strchr("\r\n\t\xA2\xAC", line.c[i]) == NULL) && ((line.c[i] < ' ') || (line.c[i] & 0x80))) { - guess = CODE_BINARY; /* oops, null or weird character, it's binary after all */ - break; - } - } - } - } + if (guess == CODE_BINARY) { /* if we saw no low bits, it could have been all spaces. */ + guess = CODE_029; /* so now assume file is text */ + for (i = 0; i < 160; i++) { /* ensure all 160 characters are 7-bit ASCII (or not or cent) */ + /* 3.0-3, changed test for > 0x7f to & 0x80 */ + if ((strchr("\r\n\t\xA2\xAC", line.c[i]) == NULL) && ((line.c[i] < ' ') || (line.c[i] & 0x80))) { + guess = CODE_BINARY; /* oops, null or weird character, it's binary after all */ + break; + } + } + } + } - fseek(cr_unit.fileref, filepos, SEEK_SET); /* return to original position */ - } + fseek(cr_unit.fileref, filepos, SEEK_SET); /* return to original position */ + } - return guess; + return guess; } static t_stat cp_set_code (UNIT *uptr, int32 match, CONST char *cptr, void *desc) { - CPCODE *code; - int ncode; + CPCODE *code; + int ncode; - if (! lookup_codetable(match, &code, &ncode)) - return SCPE_ARG; + if (! lookup_codetable(match, &code, &ncode)) + return SCPE_ARG; - cardcode = code; /* save code table for punch output */ - ncardcode = ncode; + cardcode = code; /* save code table for punch output */ + ncardcode = ncode; - return SCPE_OK; + return SCPE_OK; } t_stat load_cr_boot (int32 drvno, int switches) { - int i; - const char *name; + int i; + const char *name; char msg[80]; - t_bool expand; - uint16 word, *boot; - static uint16 dms_boot_data[] = { /* DMSV2M12, already expanded to 16 bits */ - 0xc80a, 0x18c2, 0xd008, 0xc019, 0x8007, 0xd017, 0xc033, 0x100a, - 0xd031, 0x7015, 0x000c, 0xe800, 0x0020, 0x08f8, 0x4828, 0x7035, - 0x70fa, 0x4814, 0xf026, 0x2000, 0x8800, 0x9000, 0x9800, 0xa000, - 0xb000, 0xb800, 0xb810, 0xb820, 0xb830, 0xb820, 0x3000, 0x08ea, - 0xc0eb, 0x4828, 0x70fb, 0x9027, 0x4830, 0x70f8, 0x8001, 0xd000, - 0xc0f4, 0xd0d9, 0xc01d, 0x1804, 0xe8d6, 0xd0d9, 0xc8e3, 0x18d3, - 0xd017, 0x18c4, 0xd0d8, 0x9016, 0xd815, 0x90db, 0xe8cc, 0xd0ef, - 0xc016, 0x1807, 0x0035, 0x00d0, 0xc008, 0x1803, 0xe8c4, 0xd00f, - 0x080d, 0x08c4, 0x1003, 0x4810, 0x70d9, 0x3000, 0x08df, 0x3000, - 0x7010, 0x00d1, 0x0028, 0x000a, 0x70f3, 0x0000, 0x00d0, 0xa0c0 - }; - static uint16 apl_boot_data[] = { /* APLIPL, already expanded */ - 0x7021, 0x3000, 0x7038, 0xa0c0, 0x0002, 0x4808, 0x0003, 0x0026, - 0x0001, 0x0001, 0x000c, 0x0000, 0x0000, 0x0800, 0x48f8, 0x0027, - 0x7002, 0x08f2, 0x3800, 0xe0fe, 0x18cc, 0x100e, 0x10c1, 0x4802, - 0x7007, 0x4828, 0x7005, 0x4804, 0x7001, 0x70f3, 0x08e7, 0x70e1, - 0x08ed, 0x70f1, 0xc0e0, 0x1807, 0xd0de, 0xc0df, 0x1801, 0xd0dd, - 0x800d, 0xd00c, 0xc0e3, 0x1005, 0xe80a, 0xd009, 0xc0d8, 0x1008, - 0xd0d6, 0xc0dd, 0x1008, 0x80d4, 0xd0da, 0x1000, 0xb000, 0x00f6, - 0x70e7, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x9000, 0x4004, 0x40c0, 0x8001, 0x4004, 0x40c0, 0x0000, 0x0000 }; - static uint16 aplp_boot_data[] = { /* APLIPL Privileged, already expanded */ - 0x7021, 0x3000, 0x7038, 0xa0c0, 0x0002, 0x4808, 0x0003, 0x0026, - 0x0001, 0x0001, 0x000c, 0x0000, 0x0000, 0x0800, 0x48f8, 0x0027, - 0x7002, 0x08f2, 0x3800, 0xe0fe, 0x18cc, 0x100e, 0x10c1, 0x4802, - 0x7007, 0x4828, 0x7005, 0x4804, 0x7001, 0x70f3, 0x08e7, 0x70e1, - 0x08ed, 0x70f1, 0xc0e0, 0x1807, 0xd0de, 0xc0df, 0x1801, 0xd0dd, - 0x800d, 0xd00c, 0xc0e3, 0x1005, 0xe80a, 0xd009, 0xc0d8, 0x1008, - 0xd0d6, 0xc0dd, 0x1008, 0x80d4, 0xd0da, 0x1002, 0xb000, 0x00f6, - 0x70e7, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x9000, 0x4004, 0x40c0, 0x8001, 0x4004, 0x40c0, 0x4004, 0x4001 - }; + t_bool expand; + uint16 word, *boot; + static uint16 dms_boot_data[] = { /* DMSV2M12, already expanded to 16 bits */ + 0xc80a, 0x18c2, 0xd008, 0xc019, 0x8007, 0xd017, 0xc033, 0x100a, + 0xd031, 0x7015, 0x000c, 0xe800, 0x0020, 0x08f8, 0x4828, 0x7035, + 0x70fa, 0x4814, 0xf026, 0x2000, 0x8800, 0x9000, 0x9800, 0xa000, + 0xb000, 0xb800, 0xb810, 0xb820, 0xb830, 0xb820, 0x3000, 0x08ea, + 0xc0eb, 0x4828, 0x70fb, 0x9027, 0x4830, 0x70f8, 0x8001, 0xd000, + 0xc0f4, 0xd0d9, 0xc01d, 0x1804, 0xe8d6, 0xd0d9, 0xc8e3, 0x18d3, + 0xd017, 0x18c4, 0xd0d8, 0x9016, 0xd815, 0x90db, 0xe8cc, 0xd0ef, + 0xc016, 0x1807, 0x0035, 0x00d0, 0xc008, 0x1803, 0xe8c4, 0xd00f, + 0x080d, 0x08c4, 0x1003, 0x4810, 0x70d9, 0x3000, 0x08df, 0x3000, + 0x7010, 0x00d1, 0x0028, 0x000a, 0x70f3, 0x0000, 0x00d0, 0xa0c0 + }; + static uint16 apl_boot_data[] = { /* APLIPL, already expanded */ + 0x7021, 0x3000, 0x7038, 0xa0c0, 0x0002, 0x4808, 0x0003, 0x0026, + 0x0001, 0x0001, 0x000c, 0x0000, 0x0000, 0x0800, 0x48f8, 0x0027, + 0x7002, 0x08f2, 0x3800, 0xe0fe, 0x18cc, 0x100e, 0x10c1, 0x4802, + 0x7007, 0x4828, 0x7005, 0x4804, 0x7001, 0x70f3, 0x08e7, 0x70e1, + 0x08ed, 0x70f1, 0xc0e0, 0x1807, 0xd0de, 0xc0df, 0x1801, 0xd0dd, + 0x800d, 0xd00c, 0xc0e3, 0x1005, 0xe80a, 0xd009, 0xc0d8, 0x1008, + 0xd0d6, 0xc0dd, 0x1008, 0x80d4, 0xd0da, 0x1000, 0xb000, 0x00f6, + 0x70e7, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x9000, 0x4004, 0x40c0, 0x8001, 0x4004, 0x40c0, 0x0000, 0x0000 }; + static uint16 aplp_boot_data[] = { /* APLIPL Privileged, already expanded */ + 0x7021, 0x3000, 0x7038, 0xa0c0, 0x0002, 0x4808, 0x0003, 0x0026, + 0x0001, 0x0001, 0x000c, 0x0000, 0x0000, 0x0800, 0x48f8, 0x0027, + 0x7002, 0x08f2, 0x3800, 0xe0fe, 0x18cc, 0x100e, 0x10c1, 0x4802, + 0x7007, 0x4828, 0x7005, 0x4804, 0x7001, 0x70f3, 0x08e7, 0x70e1, + 0x08ed, 0x70f1, 0xc0e0, 0x1807, 0xd0de, 0xc0df, 0x1801, 0xd0dd, + 0x800d, 0xd00c, 0xc0e3, 0x1005, 0xe80a, 0xd009, 0xc0d8, 0x1008, + 0xd0d6, 0xc0dd, 0x1008, 0x80d4, 0xd0da, 0x1002, 0xb000, 0x00f6, + 0x70e7, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x9000, 0x4004, 0x40c0, 0x8001, 0x4004, 0x40c0, 0x4004, 0x4001 + }; - if ((switches & SWMASK('A')) && (switches & SWMASK('P'))) { - boot = aplp_boot_data; - name = "APL\\1130 Privileged"; - expand = FALSE; - } - else if (switches & SWMASK('A')) { - boot = apl_boot_data; - name = "APL\\1130"; - expand = FALSE; - } - else { - boot = dms_boot_data; - name = "DMS V2M12"; - expand = FALSE; - } + if ((switches & SWMASK('A')) && (switches & SWMASK('P'))) { + boot = aplp_boot_data; + name = "APL\\1130 Privileged"; + expand = FALSE; + } + else if (switches & SWMASK('A')) { + boot = apl_boot_data; + name = "APL\\1130"; + expand = FALSE; + } + else { + boot = dms_boot_data; + name = "DMS V2M12"; + expand = FALSE; + } - if (drvno >= 0 && ! (switches & SWMASK('S'))) /* if specified, set toggle switches to disk drive no */ - CES = drvno; /* so BOOT DSK1 will work correctly (DMS boot uses this) */ - /* but do not touch switches if -S was specified */ + if (drvno >= 0 && ! (switches & SWMASK('S'))) /* if specified, set toggle switches to disk drive no */ + CES = drvno; /* so BOOT DSK1 will work correctly (DMS boot uses this) */ + /* but do not touch switches if -S was specified */ - IAR = 0; /* clear IAR */ + IAR = 0; /* clear IAR */ - for (i = 0; i < 80; i++) { /* store the boot image to core words 0..79 */ - word = boot[i]; /* expanding the 12-bit card data to 16 bits if not already expanded */ - if (expand) - word = (word & 0xF800) | ((word & 0x0400) ? 0x00C0 : 0x0000) | ((word & 0x03F0) >> 4); + for (i = 0; i < 80; i++) { /* store the boot image to core words 0..79 */ + word = boot[i]; /* expanding the 12-bit card data to 16 bits if not already expanded */ + if (expand) + word = (word & 0xF800) | ((word & 0x0400) ? 0x00C0 : 0x0000) | ((word & 0x03F0) >> 4); - WriteW(i, word); - } - /* quiet switch or CGI mode inhibit the boot remark */ - if (((switches & SWMASK('Q')) == 0) && ! cgi) { /* 3.0-3, parenthesized & operation, per lint check */ - sprintf(msg, "Loaded %s cold start card", name); + WriteW(i, word); + } + /* quiet switch or CGI mode inhibit the boot remark */ + if (((switches & SWMASK('Q')) == 0) && ! cgi) { /* 3.0-3, parenthesized & operation, per lint check */ + sprintf(msg, "Loaded %s cold start card", name); #ifdef GUI_SUPPORT - remark_cmd(msg); + remark_cmd(msg); #else - printf("%s\n", msg); + printf("%s\n", msg); #endif - } + } - return SCPE_OK; + return SCPE_OK; } t_stat cr_boot (int32 unitno, DEVICE *dptr) { - t_stat rval; - int i; + t_stat rval; + int i; - if ((rval = reset_all(0)) != SCPE_OK) - return rval; + if ((rval = reset_all(0)) != SCPE_OK) + return rval; - if (! (cr_unit.flags & UNIT_ATT)) /* no deck; load standard boot anyway */ - return load_cr_boot(-1, 0); + if (! (cr_unit.flags & UNIT_ATT)) /* no deck; load standard boot anyway */ + return load_cr_boot(-1, 0); - if (GET_ACTCODE(cr_unit) != CODE_BINARY) { - printf("Can only boot from card reader when set to BINARY mode\n"); - return SCPE_IOERR; - } + if (GET_ACTCODE(cr_unit) != CODE_BINARY) { + printf("Can only boot from card reader when set to BINARY mode\n"); + return SCPE_IOERR; + } - if (cr_unit.fileref == NULL) /* this will happen if no file in deck file can be opened */ - return SCPE_IOERR; + if (cr_unit.fileref == NULL) /* this will happen if no file in deck file can be opened */ + return SCPE_IOERR; - feedcycle(TRUE, FALSE); + feedcycle(TRUE, FALSE); - if (readstate != STATION_LOADED) { - printf("No cards in reader\n"); - return SCPE_IOERR; - } + if (readstate != STATION_LOADED) { + printf("No cards in reader\n"); + return SCPE_IOERR; + } -/* if (fxread(buf, sizeof(buf[0]), 80, cr_unit.fileref) != 80) */ -/* return SCPE_IOERR; */ +/* if (fxread(buf, sizeof(buf[0]), 80, cr_unit.fileref) != 80) */ +/* return SCPE_IOERR; */ - IAR = 0; /* Program Load sets IAR = 0 */ + IAR = 0; /* Program Load sets IAR = 0 */ - for (i = 0; i < 80; i++) /* shift 12 bits into 16 */ - WriteW(i, (readstation[i] & 0xF800) | ((readstation[i] & 0x0400) ? 0x00C0 : 0x0000) | ((readstation[i] & 0x03F0) >> 4)); + for (i = 0; i < 80; i++) /* shift 12 bits into 16 */ + WriteW(i, (readstation[i] & 0xF800) | ((readstation[i] & 0x0400) ? 0x00C0 : 0x0000) | ((readstation[i] & 0x03F0) >> 4)); - readstate = STATION_READ; /* the current card has been consumed */ - return SCPE_OK; + readstate = STATION_READ; /* the current card has been consumed */ + return SCPE_OK; } char card_to_ascii (uint16 hol) { - int i; + int i; - for (i = 0; i < ncardcode; i++) - if (cardcode[i].hollerith == hol) - return (char) cardcode[i].ascii; + for (i = 0; i < ncardcode; i++) + if (cardcode[i].hollerith == hol) + return (char) cardcode[i].ascii; - return '?'; + return '?'; } /* hollerith_to_ascii - provide a generic conversion for simulator debugging */ char hollerith_to_ascii (uint16 hol) { - int i; + int i; - for (i = 0; i < ncardcode; i++) - if (cardcode_029[i].hollerith == hol) - return (char) cardcode[i].ascii; + for (i = 0; i < ncardcode; i++) + if (cardcode_029[i].hollerith == hol) + return (char) cardcode[i].ascii; - return ' '; + return ' '; } /* feedcycle - move cards to next station */ static void feedcycle (t_bool load, t_bool punching) { - char buf[84], *x; + char buf[84], *x; const char *result; - int i, nread, nwrite, ch; + int i, nread, nwrite, ch; - /* write punched card if punch is attached to a file */ - if (cp_unit.flags & UNIT_ATT) { - if (any_punched && punchstate != STATION_EMPTY) { - if (GET_CODE(cp_unit) == CODE_BINARY) { - fxwrite(punchstation, sizeof(punchstation[0]), 80, cp_unit.fileref); - } - else { - for (i = 80; --i >= 0; ) { /* find last nonblank column */ - if (punchstation[i] != 0) - break; - } + /* write punched card if punch is attached to a file */ + if (cp_unit.flags & UNIT_ATT) { + if (any_punched && punchstate != STATION_EMPTY) { + if (GET_CODE(cp_unit) == CODE_BINARY) { + fxwrite(punchstation, sizeof(punchstation[0]), 80, cp_unit.fileref); + } + else { + for (i = 80; --i >= 0; ) { /* find last nonblank column */ + if (punchstation[i] != 0) + break; + } - /* i is now index of last character to output or -1 if all blank */ + /* i is now index of last character to output or -1 if all blank */ - for (nwrite = 0; nwrite <= i; nwrite++) { /* convert characters */ - buf[nwrite] = card_to_ascii(punchstation[nwrite]); - } + for (nwrite = 0; nwrite <= i; nwrite++) { /* convert characters */ + buf[nwrite] = card_to_ascii(punchstation[nwrite]); + } - /* nwrite is now number of characters to output */ + /* nwrite is now number of characters to output */ #ifdef WIN32 - buf[nwrite++] = '\r'; /* add CR before NL for microsoft */ + buf[nwrite++] = '\r'; /* add CR before NL for microsoft */ #endif - buf[nwrite++] = '\n'; /* append newline */ - fxwrite(buf, sizeof(char), nwrite, cp_unit.fileref); - } - } + buf[nwrite++] = '\n'; /* append newline */ + fxwrite(buf, sizeof(char), nwrite, cp_unit.fileref); + } + } - cp_count++; - } + cp_count++; + } - if (! load) /* all we wanted to do was flush the punch */ - return; + if (! load) /* all we wanted to do was flush the punch */ + return; - /* slide cards from reader to punch. If we know we're punching, - * generate a blank card in any case. Otherwise, it should take two feed - * cycles to get a read card from the hopper to punch station. Also when - * the reader is a 2501, we assume the 1442 is a punch only */ + /* slide cards from reader to punch. If we know we're punching, + * generate a blank card in any case. Otherwise, it should take two feed + * cycles to get a read card from the hopper to punch station. Also when + * the reader is a 2501, we assume the 1442 is a punch only */ - if (readstate == STATION_EMPTY || (cr_unit.flags & UNIT_2501)) { - if (punching) { - memset(punchstation, 0, sizeof(punchstation)); - punchstate = STATION_LOADED; - } - else - punchstate = STATION_EMPTY; - } - else { - memcpy(punchstation, readstation, sizeof(punchstation)); - punchstate = STATION_LOADED; - } + if (readstate == STATION_EMPTY || (cr_unit.flags & UNIT_2501)) { + if (punching) { + memset(punchstation, 0, sizeof(punchstation)); + punchstate = STATION_LOADED; + } + else + punchstate = STATION_EMPTY; + } + else { + memcpy(punchstation, readstation, sizeof(punchstation)); + punchstate = STATION_LOADED; + } - /* load card into read station */ + /* load card into read station */ -again: /* jump here if we've loaded a new deck after emptying the previous one */ +again: /* jump here if we've loaded a new deck after emptying the previous one */ - if (cr_unit.flags & UNIT_ATT) { + if (cr_unit.flags & UNIT_ATT) { - memset(readstation, 0, sizeof(readstation)); /* blank out the card image */ + memset(readstation, 0, sizeof(readstation)); /* blank out the card image */ - if (cr_unit.fileref == NULL) - nread = 0; + if (cr_unit.fileref == NULL) + nread = 0; - else if (GET_ACTCODE(cr_unit) == CODE_BINARY) /* binary read is straightforward */ - nread = fxread(readstation, sizeof(readstation[0]), 80, cr_unit.fileref); + else if (GET_ACTCODE(cr_unit) == CODE_BINARY) /* binary read is straightforward */ + nread = fxread(readstation, sizeof(readstation[0]), 80, cr_unit.fileref); - else if (fgets(buf, sizeof(buf), cr_unit.fileref) == NULL) /* read up to 80 chars */ - nread = 0; /* hmm, end of file */ + else if (fgets(buf, sizeof(buf), cr_unit.fileref) == NULL) /* read up to 80 chars */ + nread = 0; /* hmm, end of file */ - else { /* check for CRLF or newline */ - if ((x = strchr(buf, '\r')) == NULL) - x = strchr(buf, '\n'); + else { /* check for CRLF or newline */ + if ((x = strchr(buf, '\r')) == NULL) + x = strchr(buf, '\n'); - if (x == NULL) { /* there were no delimiters, burn rest of line */ - while ((ch = getc(cr_unit.fileref)) != EOF) { /* get character */ - if (ch == '\n') /* newline, done */ - break; + if (x == NULL) { /* there were no delimiters, burn rest of line */ + while ((ch = getc(cr_unit.fileref)) != EOF) { /* get character */ + if (ch == '\n') /* newline, done */ + break; - if (ch == '\r') { /* CR, try to take newline too */ - ch = getc(cr_unit.fileref); - if (ch != EOF && ch != '\n') /* hmm, put it back */ - ungetc(ch, cr_unit.fileref); + if (ch == '\r') { /* CR, try to take newline too */ + ch = getc(cr_unit.fileref); + if (ch != EOF && ch != '\n') /* hmm, put it back */ + ungetc(ch, cr_unit.fileref); - break; - } - } - if ((nread = strlen(buf)) > 80) /* use the line as read, at most 80 characters */ - nread = 80; - } - else - nread = x-buf; /* reduce length of string */ + break; + } + } + if ((nread = strlen(buf)) > 80) /* use the line as read, at most 80 characters */ + nread = 80; + } + else + nread = x-buf; /* reduce length of string */ - if (! (cr_unit.flags & UNIT_LOWERCASE)) - upcase(buf); /* force uppercase */ + if (! (cr_unit.flags & UNIT_LOWERCASE)) + upcase(buf); /* force uppercase */ - if (tab_proc != NULL) { /* apply tab editing, if specified */ - buf[nread] = '\0'; /* .. be sure string is terminated */ - result = (*tab_proc)(buf, tab_width); /* .. convert tabs spaces */ - nread = strlen(result); /* .. set new read length */ - } - else - result = buf; + if (tab_proc != NULL) { /* apply tab editing, if specified */ + buf[nread] = '\0'; /* .. be sure string is terminated */ + result = (*tab_proc)(buf, tab_width); /* .. convert tabs spaces */ + nread = strlen(result); /* .. set new read length */ + } + else + result = buf; - for (i = 0; i < nread; i++) /* convert ascii to punch code */ - readstation[i] = ascii_to_card[(unsigned char) result[i]]; + for (i = 0; i < nread; i++) /* convert ascii to punch code */ + readstation[i] = ascii_to_card[(unsigned char) result[i]]; - nread = 80; /* even if line was blank consider it present */ - } + nread = 80; /* even if line was blank consider it present */ + } - if (nread <= 0) { /* set hopper flag accordingly */ - if (deckfile != NULL && nextdeck()) - goto again; + if (nread <= 0) { /* set hopper flag accordingly */ + if (deckfile != NULL && nextdeck()) + goto again; - if (punching) /* pretend we loaded a blank card */ - nread = 80; - } + if (punching) /* pretend we loaded a blank card */ + nread = 80; + } - if (nread == 0) { - SETBIT(cr_unit.flags, UNIT_CR_EMPTY); - readstate = STATION_EMPTY; - cr_count = -1; /* nix the card counter */ - } - else { - CLRBIT(cr_unit.flags, UNIT_CR_EMPTY); - readstate = STATION_LOADED; - cr_count++; - cr_unit.pos++; - } - } -/* else */ -/* readstate = STATION_EMPTY; */ + if (nread == 0) { + SETBIT(cr_unit.flags, UNIT_CR_EMPTY); + readstate = STATION_EMPTY; + cr_count = -1; /* nix the card counter */ + } + else { + CLRBIT(cr_unit.flags, UNIT_CR_EMPTY); + readstate = STATION_LOADED; + cr_count++; + cr_unit.pos++; + } + } +/* else */ +/* readstate = STATION_EMPTY; */ - cr_unit.COLUMN = -1; /* neither device is currently cycling */ - cp_unit.COLUMN = -1; + cr_unit.COLUMN = -1; /* neither device is currently cycling */ + cp_unit.COLUMN = -1; } #ifdef NO_USE_FOR_THIS_CURRENTLY @@ -1187,20 +1187,20 @@ again: /* jump here if we've loaded a new deck after emptying the previous one static void npro (void) { - if (cr_unit.flags & UNIT_ATT) - fseek(cr_unit.fileref, 0, SEEK_END); /* push reader to EOF */ - if (deckfile != NULL) - fseek(deckfile, 0, SEEK_END); /* skip to end of deck list */ + if (cr_unit.flags & UNIT_ATT) + fseek(cr_unit.fileref, 0, SEEK_END); /* push reader to EOF */ + if (deckfile != NULL) + fseek(deckfile, 0, SEEK_END); /* skip to end of deck list */ - cr_count = -1; /* nix the card counter */ + cr_count = -1; /* nix the card counter */ - if (punchstate == STATION_PUNCHED) - feedcycle(FALSE, FALSE); /* flush out card just punched */ + if (punchstate == STATION_PUNCHED) + feedcycle(FALSE, FALSE); /* flush out card just punched */ - readstate = punchstate = STATION_EMPTY; - cr_unit.COLUMN = -1; /* neither device is currently cycling */ - cp_unit.COLUMN = -1; - SETBIT(cr_unit.flags, UNIT_CR_EMPTY); /* set hopper empty */ + readstate = punchstate = STATION_EMPTY; + cr_unit.COLUMN = -1; /* neither device is currently cycling */ + cp_unit.COLUMN = -1; + SETBIT(cr_unit.flags, UNIT_CR_EMPTY); /* set hopper empty */ } #endif @@ -1209,898 +1209,898 @@ static void npro (void) static char * skipbl (char *str) { - while (*str && *str <= ' ') - str++; + while (*str && *str <= ' ') + str++; - return str; + return str; } static char * trim (char *str) { - char *s, *lastnb; + char *s, *lastnb; - for (lastnb = str-1, s = str; *s; s++) /* point to last nonblank characteter in string */ - if (*s > ' ') - lastnb = s; + for (lastnb = str-1, s = str; *s; s++) /* point to last nonblank characteter in string */ + if (*s > ' ') + lastnb = s; - lastnb[1] = '\0'; /* clip just after it */ + lastnb[1] = '\0'; /* clip just after it */ - return str; + return str; } /* alltrim - remove all leading and trailing whitespace from a string */ static char * alltrim (char *str) { - char *s, *lastnb; + char *s, *lastnb; - if ((s = skipbl(str)) != str) /* slide down over leading whitespace */ - strcpy(str, s); + if ((s = skipbl(str)) != str) /* slide down over leading whitespace */ + strcpy(str, s); - for (lastnb = str-1, s = str; *s; s++) /* point to last nonblank characteter in string */ - if (*s > ' ') - lastnb = s; + for (lastnb = str-1, s = str; *s; s++) /* point to last nonblank characteter in string */ + if (*s > ' ') + lastnb = s; - lastnb[1] = '\0'; /* clip just after it */ + lastnb[1] = '\0'; /* clip just after it */ - return str; + return str; } /* checkdeck - set hopper empty status based on condition of current reader file */ static void checkdeck (void) { - t_bool empty; + t_bool empty; - if (cr_unit.fileref == NULL) { /* there is no open file */ - empty = TRUE; - } - else { - fseek(cr_unit.fileref, 0, SEEK_END); /* seek to end of file */ - empty = ftell(cr_unit.fileref) <= 0; /* file is empty if there was nothing in it*/ - cr_count = 0; /* reset card counter */ - cr_unit.pos = 0; - fseek(cr_unit.fileref, 0, SEEK_SET); /* rewind deck */ - } + if (cr_unit.fileref == NULL) { /* there is no open file */ + empty = TRUE; + } + else { + fseek(cr_unit.fileref, 0, SEEK_END); /* seek to end of file */ + empty = ftell(cr_unit.fileref) <= 0; /* file is empty if there was nothing in it*/ + cr_count = 0; /* reset card counter */ + cr_unit.pos = 0; + fseek(cr_unit.fileref, 0, SEEK_SET); /* rewind deck */ + } - if (empty) { - SETBIT(cr_unit.flags, UNIT_CR_EMPTY); - if (cr_unit.fileref != NULL) /* real file but it's empty, hmmm, try another */ - nextdeck(); - } - else { - CLRBIT(cr_unit.flags, UNIT_CR_EMPTY); - } + if (empty) { + SETBIT(cr_unit.flags, UNIT_CR_EMPTY); + if (cr_unit.fileref != NULL) /* real file but it's empty, hmmm, try another */ + nextdeck(); + } + else { + CLRBIT(cr_unit.flags, UNIT_CR_EMPTY); + } } /* nextdeck - attempt to load a new file from the deck list into the hopper */ static t_bool nextdeck (void) { - char buf[200], *fname, *c, quote; - int code; - long fpos; + char buf[200], *fname, *c, quote; + int code; + long fpos; - cr_count = 0; /* clear read count */ - cr_unit.pos = 0; + cr_count = 0; /* clear read count */ + cr_unit.pos = 0; - if (deckfile == NULL) /* we can't help */ - return FALSE; + if (deckfile == NULL) /* we can't help */ + return FALSE; - code = GET_CODE(cr_unit); /* default code as set */ + code = GET_CODE(cr_unit); /* default code as set */ - if (cr_unit.fileref != NULL) { /* this pulls the rug out from under scp */ - fclose(cr_unit.fileref); /* since the attach flag is still set. be careful! */ - cr_unit.fileref = NULL; + if (cr_unit.fileref != NULL) { /* this pulls the rug out from under scp */ + fclose(cr_unit.fileref); /* since the attach flag is still set. be careful! */ + cr_unit.fileref = NULL; - if (cr_unit.flags & UNIT_SCRATCH) { - remove(tempfile); - CLRBIT(cr_unit.flags, UNIT_SCRATCH); - } - } + if (cr_unit.flags & UNIT_SCRATCH) { + remove(tempfile); + CLRBIT(cr_unit.flags, UNIT_SCRATCH); + } + } - for (;;) { /* get a filename */ - tab_proc = NULL; /* default: no tab editing */ - tab_width = 8; + for (;;) { /* get a filename */ + tab_proc = NULL; /* default: no tab editing */ + tab_width = 8; - if (fgets(buf, sizeof(buf), deckfile) == NULL) - break; /* oops, no more names */ + if (fgets(buf, sizeof(buf), deckfile) == NULL) + break; /* oops, no more names */ - alltrim(buf); /* remove leading and trailing spaces */ + alltrim(buf); /* remove leading and trailing spaces */ - if (! *buf) - continue; /* empty line */ + if (! *buf) + continue; /* empty line */ - if (*buf == '#' || *buf == '*' || *buf == ';') - continue; /* comment */ + if (*buf == '#' || *buf == '*' || *buf == ';') + continue; /* comment */ - if (strnicmp(buf, "!BREAK", 6) == 0) { /* stop the simulation */ - break_simulation(STOP_DECK_BREAK); - continue; - } + if (strnicmp(buf, "!BREAK", 6) == 0) { /* stop the simulation */ + break_simulation(STOP_DECK_BREAK); + continue; + } - if (buf[0] == '!') { /* literal text line, make a temporary file */ + if (buf[0] == '!') { /* literal text line, make a temporary file */ -#if defined (__GNUC__) && !defined (_WIN32) /* GCC complains about mktemp & always provides mkstemp */ +#if defined (__GNUC__) && !defined (_WIN32) /* GCC complains about mktemp & always provides mkstemp */ - if (*tempfile == '\0') { /* first time, open guaranteed-unique file */ - int fh; + if (*tempfile == '\0') { /* first time, open guaranteed-unique file */ + int fh; - strcpy(tempfile, "tempXXXXXX"); /* get modifiable copy of name template */ + strcpy(tempfile, "tempXXXXXX"); /* get modifiable copy of name template */ - if ((fh = mkstemp(tempfile)) == -1) { /* open file. Actual name is set by side effect */ - printf("Cannot create temporary deck file\n"); - break_simulation(STOP_DECK_BREAK); - return 0; - } - /* get FILE * from the file handle */ - if ((cr_unit.fileref = fdopen(fh, "w+b")) == NULL) { - printf("Cannot use temporary deck file %s\n", tempfile); - break_simulation(STOP_DECK_BREAK); - return 0; - } - } - else { /* on later opens, just reuse the old name */ - if ((cr_unit.fileref = fopen(tempfile, "w+b")) == NULL) { - printf("Cannot create temporary file %s\n", tempfile); - break_simulation(STOP_DECK_BREAK); - return 0; - } - } -#else /* ANSI standard C always provides mktemp */ + if ((fh = mkstemp(tempfile)) == -1) { /* open file. Actual name is set by side effect */ + printf("Cannot create temporary deck file\n"); + break_simulation(STOP_DECK_BREAK); + return 0; + } + /* get FILE * from the file handle */ + if ((cr_unit.fileref = fdopen(fh, "w+b")) == NULL) { + printf("Cannot use temporary deck file %s\n", tempfile); + break_simulation(STOP_DECK_BREAK); + return 0; + } + } + else { /* on later opens, just reuse the old name */ + if ((cr_unit.fileref = fopen(tempfile, "w+b")) == NULL) { + printf("Cannot create temporary file %s\n", tempfile); + break_simulation(STOP_DECK_BREAK); + return 0; + } + } +#else /* ANSI standard C always provides mktemp */ - if (*tempfile == '\0') { /* first time, construct unique name */ - strcpy(tempfile, "tempXXXXXX"); /* make a modifiable copy of the template */ - if (mktemp(tempfile) == NULL) { - printf("Cannot create temporary card file name\n"); - break_simulation(STOP_DECK_BREAK); - return 0; - } - } - /* (re)create file */ - if ((cr_unit.fileref = fopen(tempfile, "w+b")) == NULL) { - printf("Cannot create temporary file %s\n", tempfile); - break_simulation(STOP_DECK_BREAK); - return 0; - } + if (*tempfile == '\0') { /* first time, construct unique name */ + strcpy(tempfile, "tempXXXXXX"); /* make a modifiable copy of the template */ + if (mktemp(tempfile) == NULL) { + printf("Cannot create temporary card file name\n"); + break_simulation(STOP_DECK_BREAK); + return 0; + } + } + /* (re)create file */ + if ((cr_unit.fileref = fopen(tempfile, "w+b")) == NULL) { + printf("Cannot create temporary file %s\n", tempfile); + break_simulation(STOP_DECK_BREAK); + return 0; + } #endif - SETBIT(cr_unit.flags, UNIT_SCRATCH); + SETBIT(cr_unit.flags, UNIT_SCRATCH); - for (;;) { /* store literal cards into temporary file */ - upcase(buf+1); - fputs(buf+1, cr_unit.fileref); - putc('\n', cr_unit.fileref); + for (;;) { /* store literal cards into temporary file */ + upcase(buf+1); + fputs(buf+1, cr_unit.fileref); + putc('\n', cr_unit.fileref); - if (cpu_unit.flags & UNIT_ATT) - trace_io("(Literal card %s\n)", buf+1); - if (! (cr_unit.flags & UNIT_QUIET)) - printf( "(Literal card %s)\n", buf+1); + if (cpu_unit.flags & UNIT_ATT) + trace_io("(Literal card %s\n)", buf+1); + if (! (cr_unit.flags & UNIT_QUIET)) + printf( "(Literal card %s)\n", buf+1); - fpos = ftell(deckfile); - if (fgets(buf, sizeof(buf), deckfile) == NULL) - break; /* oops, end of file */ - if (buf[0] != '!' || strnicmp(buf, "!BREAK", 6) == 0) - break; - alltrim(buf); - } - fseek(deckfile, fpos, SEEK_SET); /* restore deck file to just before non-literal card */ + fpos = ftell(deckfile); + if (fgets(buf, sizeof(buf), deckfile) == NULL) + break; /* oops, end of file */ + if (buf[0] != '!' || strnicmp(buf, "!BREAK", 6) == 0) + break; + alltrim(buf); + } + fseek(deckfile, fpos, SEEK_SET); /* restore deck file to just before non-literal card */ - fseek(cr_unit.fileref, 0, SEEK_SET); /* rewind scratch file for reading */ - code = CODE_029; /* assume literal cards use keycode 029 */ - break; - } + fseek(cr_unit.fileref, 0, SEEK_SET); /* rewind scratch file for reading */ + code = CODE_029; /* assume literal cards use keycode 029 */ + break; + } - sim_sub_args(buf, sizeof(buf), list_arg); /* substitute in stuff from the attach command line */ + sim_sub_args(buf, sizeof(buf), list_arg); /* substitute in stuff from the attach command line */ - c = buf; /* pick filename from string */ + c = buf; /* pick filename from string */ - while (*c && *c <= ' ') /* skip leading blanks (there could be some now after subsitution) */ - c++; + while (*c && *c <= ' ') /* skip leading blanks (there could be some now after subsitution) */ + c++; - fname = c; /* remember start */ + fname = c; /* remember start */ - if (*c == '\'' || *c == '"') { /* quoted string */ - quote = *c++; /* remember the quote type */ - fname++; /* skip the quote */ - while (*c && (*c != quote)) - c++; /* skip to end of quote */ - } - else { /* not quoted; look for terminating whitespace */ - while (*c && (*c > ' ')) - c++; - } + if (*c == '\'' || *c == '"') { /* quoted string */ + quote = *c++; /* remember the quote type */ + fname++; /* skip the quote */ + while (*c && (*c != quote)) + c++; /* skip to end of quote */ + } + else { /* not quoted; look for terminating whitespace */ + while (*c && (*c > ' ')) + c++; + } - if (*c) - *c++ = 0; /* term arg at space or closing quote & move to next character */ + if (*c) + *c++ = 0; /* term arg at space or closing quote & move to next character */ - if (! *fname) /* blank line, no filename */ - continue; + if (! *fname) /* blank line, no filename */ + continue; - if ((cr_unit.fileref = fopen(fname, "rb")) == NULL) { - printf("File '%s' specified in deck file '%s' cannot be opened\n", fname, cr_unit.filename+1); - continue; - } + if ((cr_unit.fileref = fopen(fname, "rb")) == NULL) { + printf("File '%s' specified in deck file '%s' cannot be opened\n", fname, cr_unit.filename+1); + continue; + } - c = skipbl(c); /* skip to next token, which would be mode, if present */ + c = skipbl(c); /* skip to next token, which would be mode, if present */ - switch (*c) { - case 'b': - case 'B': - code = CODE_BINARY; /* force code */ - c++; /* accept mode character by moving past it */ - break; + switch (*c) { + case 'b': + case 'B': + code = CODE_BINARY; /* force code */ + c++; /* accept mode character by moving past it */ + break; - case 'a': - case 'A': - code = CODE_029; - c++; + case 'a': + case 'A': + code = CODE_029; + c++; - switch (*c) { /* is ascii mode followed by another character? */ - case 'F': - case 'f': - tab_proc = EditToFortran; - c++; - break; + switch (*c) { /* is ascii mode followed by another character? */ + case 'F': + case 'f': + tab_proc = EditToFortran; + c++; + break; - case 'A': - case 'a': - tab_proc = EditToAsm; - c++; - break; + case 'A': + case 'a': + tab_proc = EditToAsm; + c++; + break; - case 't': - case 'T': - tab_proc = EditToWhitespace; - c++; - tab_width = 0; /* see if there is a digit after the 4 -- if so use it as tab expansion width */ - while (isdigit(*c)) - tab_width = tab_width*10 + *c++ - '0'; + case 't': + case 'T': + tab_proc = EditToWhitespace; + c++; + tab_width = 0; /* see if there is a digit after the 4 -- if so use it as tab expansion width */ + while (isdigit(*c)) + tab_width = tab_width*10 + *c++ - '0'; - if (tab_width == 0) - tab_width = 8; + if (tab_width == 0) + tab_width = 8; - break; - } - } + break; + } + } - if (code == CODE_AUTO) /* otherwise if mode is auto, guess it, otherwise use default */ - code = guess_cr_code(); + if (code == CODE_AUTO) /* otherwise if mode is auto, guess it, otherwise use default */ + code = guess_cr_code(); - if (cpu_unit.flags & UNIT_ATT) - trace_io("(Opened %s deck %s%s)\n", (code == CODE_BINARY) ? "binary" : "text", fname, tab_proc ? (*tab_proc)(NULL, tab_width) : ""); + if (cpu_unit.flags & UNIT_ATT) + trace_io("(Opened %s deck %s%s)\n", (code == CODE_BINARY) ? "binary" : "text", fname, tab_proc ? (*tab_proc)(NULL, tab_width) : ""); - if (! (cr_unit.flags & UNIT_QUIET)) - printf( "(Opened %s deck %s%s)\n", (code == CODE_BINARY) ? "binary" : "text", fname, tab_proc ? (*tab_proc)(NULL, tab_width) : ""); + if (! (cr_unit.flags & UNIT_QUIET)) + printf( "(Opened %s deck %s%s)\n", (code == CODE_BINARY) ? "binary" : "text", fname, tab_proc ? (*tab_proc)(NULL, tab_width) : ""); - break; - } + break; + } - checkdeck(); + checkdeck(); - if (code != CODE_AUTO) /* if code was determined, set it */ - set_active_cr_code(code); /* (it may be left at CODE_AUTO when deckfile is exhausted */ + if (code != CODE_AUTO) /* if code was determined, set it */ + set_active_cr_code(code); /* (it may be left at CODE_AUTO when deckfile is exhausted */ - return (cr_unit.flags & UNIT_CR_EMPTY) == 0;/* return TRUE if a deck has been loaded */ + return (cr_unit.flags & UNIT_CR_EMPTY) == 0;/* return TRUE if a deck has been loaded */ } static t_stat cr_reset (DEVICE *dptr) { - if (GET_ACTCODE(cr_unit) == CODE_AUTO) - SET_ACTCODE(cr_unit, CODE_029); /* if actual code is not yet set, select 029 for now*/ + if (GET_ACTCODE(cr_unit) == CODE_AUTO) + SET_ACTCODE(cr_unit, CODE_029); /* if actual code is not yet set, select 029 for now*/ - cr_set_code(&cr_unit, GET_ACTCODE(cr_unit), NULL, NULL); /* reset to specified code table */ + cr_set_code(&cr_unit, GET_ACTCODE(cr_unit), NULL, NULL); /* reset to specified code table */ - readstate = STATION_EMPTY; + readstate = STATION_EMPTY; - cr_dsw = 0; - sim_cancel(&cr_unit); /* cancel any pending ops */ - calc_ints(); + cr_dsw = 0; + sim_cancel(&cr_unit); /* cancel any pending ops */ + calc_ints(); - SET_OP(OP_IDLE); + SET_OP(OP_IDLE); - cr_unit.COLUMN = -1; /* neither device is currently cycling */ + cr_unit.COLUMN = -1; /* neither device is currently cycling */ - if (cr_unit.flags & UNIT_PHYSICAL) { - pcr_reset(); - return SCPE_OK; - } + if (cr_unit.flags & UNIT_PHYSICAL) { + pcr_reset(); + return SCPE_OK; + } - return SCPE_OK; + return SCPE_OK; } static t_stat cp_reset (DEVICE *dptr) { - if (GET_CODE(cp_unit) == CODE_AUTO) - SET_CODE(cp_unit, CODE_BINARY); /* punch is never in auto mode; turn it to binary on startup */ + if (GET_CODE(cp_unit) == CODE_AUTO) + SET_CODE(cp_unit, CODE_BINARY); /* punch is never in auto mode; turn it to binary on startup */ - cp_set_code(&cp_unit, GET_CODE(cp_unit), NULL, NULL); - punchstate = STATION_EMPTY; + cp_set_code(&cp_unit, GET_CODE(cp_unit), NULL, NULL); + punchstate = STATION_EMPTY; - cp_unit.COLUMN = -1; - return SCPE_OK; + cp_unit.COLUMN = -1; + return SCPE_OK; } t_stat cr_rewind (void) { - if ((cr_unit.flags & UNIT_ATT) == 0) - return SCPE_UNATT; + if ((cr_unit.flags & UNIT_ATT) == 0) + return SCPE_UNATT; - if (deckfile) { - fseek(deckfile, 0, SEEK_SET); - nextdeck(); - } - else { - fseek(cr_unit.fileref, 0, SEEK_SET); - checkdeck(); - cr_set_code(&cr_unit, GET_CODE(cr_unit), NULL, NULL); - } + if (deckfile) { + fseek(deckfile, 0, SEEK_SET); + nextdeck(); + } + else { + fseek(cr_unit.fileref, 0, SEEK_SET); + checkdeck(); + cr_set_code(&cr_unit, GET_CODE(cr_unit), NULL, NULL); + } - cr_unit.pos = 0; + cr_unit.pos = 0; - /* there is a read pending. Pull the card in to make it go */ - if (CURRENT_OP == OP_READING || CURRENT_OP == OP_PUNCHING || CURRENT_OP == OP_FEEDING) - feedcycle(TRUE, (cp_unit.flags & UNIT_ATT) != 0); + /* there is a read pending. Pull the card in to make it go */ + if (CURRENT_OP == OP_READING || CURRENT_OP == OP_PUNCHING || CURRENT_OP == OP_FEEDING) + feedcycle(TRUE, (cp_unit.flags & UNIT_ATT) != 0); - return SCPE_OK; + return SCPE_OK; } static t_stat cr_attach (UNIT *uptr, CONST char *iptr) { - t_stat rval; - t_bool use_decklist, old_quiet; + t_stat rval; + t_bool use_decklist, old_quiet; char gbuf[4*CBUFSIZE], *cptr = gbuf; - char *c, *arg, quote; + char *c, *arg, quote; - gbuf[sizeof(gbuf)-1] = '\0'; - strncpy(gbuf, iptr, sizeof(gbuf)-1); - cr_detach(uptr); /* detach file and possibly deck file */ + gbuf[sizeof(gbuf)-1] = '\0'; + strncpy(gbuf, iptr, sizeof(gbuf)-1); + cr_detach(uptr); /* detach file and possibly deck file */ - CLRBIT(uptr->flags, UNIT_SCRATCH|UNIT_QUIET|UNIT_DEBUG|UNIT_PHYSICAL|UNIT_LOWERCASE); /* set options */ + CLRBIT(uptr->flags, UNIT_SCRATCH|UNIT_QUIET|UNIT_DEBUG|UNIT_PHYSICAL|UNIT_LOWERCASE); /* set options */ - tab_proc = NULL; - tab_width = 8; - use_decklist = FALSE; + tab_proc = NULL; + tab_width = 8; + use_decklist = FALSE; - sim_switches |= SWMASK('R'); // the card reader is readonly. Don't create an empty file if file does not exist + sim_switches |= SWMASK('R'); // the card reader is readonly. Don't create an empty file if file does not exist - if (sim_switches & SWMASK('D')) SETBIT(uptr->flags, UNIT_DEBUG); - if (sim_switches & SWMASK('Q')) SETBIT(uptr->flags, UNIT_QUIET); - if (sim_switches & SWMASK('L')) SETBIT(uptr->flags, UNIT_LOWERCASE); + if (sim_switches & SWMASK('D')) SETBIT(uptr->flags, UNIT_DEBUG); + if (sim_switches & SWMASK('Q')) SETBIT(uptr->flags, UNIT_QUIET); + if (sim_switches & SWMASK('L')) SETBIT(uptr->flags, UNIT_LOWERCASE); - if (sim_switches & SWMASK('F')) tab_proc = EditToFortran; - if (sim_switches & SWMASK('A')) tab_proc = EditToAsm; - if (sim_switches & SWMASK('T')) tab_proc = EditToWhitespace; + if (sim_switches & SWMASK('F')) tab_proc = EditToFortran; + if (sim_switches & SWMASK('A')) tab_proc = EditToAsm; + if (sim_switches & SWMASK('T')) tab_proc = EditToWhitespace; - /* user can specify multiple names on the CR attach command if using a deck file. The deck file - * can contain %n tokens to pickup the additional name(s). */ + /* user can specify multiple names on the CR attach command if using a deck file. The deck file + * can contain %n tokens to pickup the additional name(s). */ - c = cptr; /* extract arguments */ - for (list_nargs = 0; list_nargs < MAXARGS; list_nargs++) { - while (*c && (*c <= ' ')) /* skip blanks */ - c++; + c = cptr; /* extract arguments */ + for (list_nargs = 0; list_nargs < MAXARGS; list_nargs++) { + while (*c && (*c <= ' ')) /* skip blanks */ + c++; - if (! *c) - break; /* all done */ + if (! *c) + break; /* all done */ - if (list_nargs == 0 && *c == '@') { /* @ might occur before a quoted name; check first */ - c++; - use_decklist = TRUE; - } + if (list_nargs == 0 && *c == '@') { /* @ might occur before a quoted name; check first */ + c++; + use_decklist = TRUE; + } - if (*c == '\'' || *c == '"') { /* quoted string */ - quote = *c++; - arg = c; /* save start */ - while (*c && (*c != quote)) - c++; - } - else { - arg = c; /* save start */ - while (*c && (*c > ' ')) - c++; - } + if (*c == '\'' || *c == '"') { /* quoted string */ + quote = *c++; + arg = c; /* save start */ + while (*c && (*c != quote)) + c++; + } + else { + arg = c; /* save start */ + while (*c && (*c > ' ')) + c++; + } - if (*c) - *c++ = 0; /* term arg at space or closing quote */ + if (*c) + *c++ = 0; /* term arg at space or closing quote */ - list_arg[list_nargs] = list_save[list_nargs]; /* set pointer to permanent storage location */ - strncpy(list_arg[list_nargs], arg, MAXARGLEN); /* store copy */ - } - list_arg[list_nargs] = NULL; /* NULL terminate the end of the argument list */ + list_arg[list_nargs] = list_save[list_nargs]; /* set pointer to permanent storage location */ + strncpy(list_arg[list_nargs], arg, MAXARGLEN); /* store copy */ + } + list_arg[list_nargs] = NULL; /* NULL terminate the end of the argument list */ - if (list_nargs <= 0) /* need at least 1 */ - return SCPE_2FARG; + if (list_nargs <= 0) /* need at least 1 */ + return SCPE_2FARG; - cr_count = 0; /* reset card counter */ + cr_count = 0; /* reset card counter */ - cptr = list_arg[0]; /* filename is first argument */ - if (*cptr == '@') { /* @ might also occur inside a quoted name; check afterwards too */ - use_decklist = TRUE; - cptr++; - } + cptr = list_arg[0]; /* filename is first argument */ + if (*cptr == '@') { /* @ might also occur inside a quoted name; check afterwards too */ + use_decklist = TRUE; + cptr++; + } - else if (sim_switches & SWMASK('P')) { /* open physical card reader device */ - return pcr_attach(uptr, cptr); - } + else if (sim_switches & SWMASK('P')) { /* open physical card reader device */ + return pcr_attach(uptr, cptr); + } - if (list_nargs > 1 && ! use_decklist) /* if not using deck file, there should have been only one name */ - return SCPE_2MARG; + if (list_nargs > 1 && ! use_decklist) /* if not using deck file, there should have been only one name */ + return SCPE_2MARG; - if (strcmp(cptr, "(stdin)") == 0 && ! use_decklist) { /* standard input */ - if (uptr->flags & UNIT_DIS) return SCPE_UDIS; /* disabled? */ - uptr->filename = (char *)calloc(CBUFSIZE, sizeof(char)); - strcpy(uptr->filename, "(stdin)"); - uptr->fileref = stdin; - SETBIT(uptr->flags, UNIT_ATT); - uptr->pos = 0; - } - else { - old_quiet = sim_quiet; /* attach the file, but set sim_quiet so we don't get the "CR is read-only" message */ - sim_quiet = TRUE; - rval = attach_unit(uptr, cptr); - sim_quiet = old_quiet; + if (strcmp(cptr, "(stdin)") == 0 && ! use_decklist) { /* standard input */ + if (uptr->flags & UNIT_DIS) return SCPE_UDIS; /* disabled? */ + uptr->filename = (char *)calloc(CBUFSIZE, sizeof(char)); + strcpy(uptr->filename, "(stdin)"); + uptr->fileref = stdin; + SETBIT(uptr->flags, UNIT_ATT); + uptr->pos = 0; + } + else { + old_quiet = sim_quiet; /* attach the file, but set sim_quiet so we don't get the "CR is read-only" message */ + sim_quiet = TRUE; + rval = attach_unit(uptr, cptr); + sim_quiet = old_quiet; - if (rval != SCPE_OK) /* file did not exist */ - return rval; - } + if (rval != SCPE_OK) /* file did not exist */ + return rval; + } - if (use_decklist) { /* if we skipped the '@', store the actually-specified name */ - uptr->filename[0] = '@'; - strncpy(uptr->filename+1, cptr, CBUFSIZE-1); + if (use_decklist) { /* if we skipped the '@', store the actually-specified name */ + uptr->filename[0] = '@'; + strncpy(uptr->filename+1, cptr, CBUFSIZE-1); - deckfile = cr_unit.fileref; /* save the deck file stream in our local variable */ - cr_unit.fileref = NULL; - nextdeck(); - } - else { - checkdeck(); - cr_set_code(&cr_unit, GET_CODE(cr_unit), NULL, NULL); - } + deckfile = cr_unit.fileref; /* save the deck file stream in our local variable */ + cr_unit.fileref = NULL; + nextdeck(); + } + else { + checkdeck(); + cr_set_code(&cr_unit, GET_CODE(cr_unit), NULL, NULL); + } - /* there is a read pending. Pull the card in to make it go */ - if (CURRENT_OP == OP_READING || CURRENT_OP == OP_PUNCHING || CURRENT_OP == OP_FEEDING) - feedcycle(TRUE, (cp_unit.flags & UNIT_ATT) != 0); + /* there is a read pending. Pull the card in to make it go */ + if (CURRENT_OP == OP_READING || CURRENT_OP == OP_PUNCHING || CURRENT_OP == OP_FEEDING) + feedcycle(TRUE, (cp_unit.flags & UNIT_ATT) != 0); - return SCPE_OK; + return SCPE_OK; } t_stat cr_detach (UNIT *uptr) { - t_stat rval; + t_stat rval; - cr_count = 0; /* clear read count */ + cr_count = 0; /* clear read count */ - if (cr_unit.flags & UNIT_PHYSICAL) - return pcr_detach(uptr); + if (cr_unit.flags & UNIT_PHYSICAL) + return pcr_detach(uptr); - if (cr_unit.flags & UNIT_ATT && deckfile != NULL) { - if (cr_unit.fileref != NULL) /* close the active card deck */ - fclose(cr_unit.fileref); + if (cr_unit.flags & UNIT_ATT && deckfile != NULL) { + if (cr_unit.fileref != NULL) /* close the active card deck */ + fclose(cr_unit.fileref); - if (cr_unit.flags & UNIT_SCRATCH) { - remove(tempfile); - CLRBIT(cr_unit.flags, UNIT_SCRATCH); - } + if (cr_unit.flags & UNIT_SCRATCH) { + remove(tempfile); + CLRBIT(cr_unit.flags, UNIT_SCRATCH); + } - cr_unit.fileref = deckfile; /* give scp a file to close */ - } + cr_unit.fileref = deckfile; /* give scp a file to close */ + } - if (uptr->fileref == stdin) { - CLRBIT(uptr->flags, UNIT_ATT); - free(uptr->filename); - uptr->filename = NULL; - uptr->fileref = NULL; - rval = SCPE_OK; - } - else - rval = detach_unit(uptr); + if (uptr->fileref == stdin) { + CLRBIT(uptr->flags, UNIT_ATT); + free(uptr->filename); + uptr->filename = NULL; + uptr->fileref = NULL; + rval = SCPE_OK; + } + else + rval = detach_unit(uptr); - return rval; + return rval; } static t_stat cp_attach (UNIT *uptr, CONST char *cptr) { char gbuf[2*CBUFSIZE]; - /* if -d is specified turn on debugging (bit is in card reader UNIT) */ - if (sim_switches & SWMASK('D')) SETBIT(cr_unit.flags, UNIT_DEBUG); + /* if -d is specified turn on debugging (bit is in card reader UNIT) */ + if (sim_switches & SWMASK('D')) SETBIT(cr_unit.flags, UNIT_DEBUG); - return attach_unit(uptr, quotefix(cptr, gbuf)); /* fix quotes in filenames & attach */ + return attach_unit(uptr, quotefix(cptr, gbuf)); /* fix quotes in filenames & attach */ } static t_stat cp_detach (UNIT *uptr) { - if (cp_unit.flags & UNIT_ATT) - if (punchstate == STATION_PUNCHED) - feedcycle(FALSE, FALSE); /* flush out card just punched */ + if (cp_unit.flags & UNIT_ATT) + if (punchstate == STATION_PUNCHED) + feedcycle(FALSE, FALSE); /* flush out card just punched */ - any_punched = 0; /* reset punch detected */ - cp_count = 0; /* clear punch count */ + any_punched = 0; /* reset punch detected */ + cp_count = 0; /* clear punch count */ - return detach_unit(uptr); + return detach_unit(uptr); } static void op_done (UNIT *u, const char *opname, t_bool issue_intr) { - if (u->flags & UNIT_DEBUG) - DEBUG_PRINT("!CR %s Op Complete, card %d%s", opname, cr_count, issue_intr ? ", interrupt" : ""); + if (u->flags & UNIT_DEBUG) + DEBUG_PRINT("!CR %s Op Complete, card %d%s", opname, cr_count, issue_intr ? ", interrupt" : ""); - SET_OP(OP_IDLE); + SET_OP(OP_IDLE); - if (u->flags & UNIT_2501) /* we use u-> not cr_unit. because PUNCH is always a 1442 */ - CLRBIT(cr_dsw, CR_DSW_2501_BUSY); - else - CLRBIT(cr_dsw, CR_DSW_1442_BUSY); /* this is trickier. 1442 cr and cp share a dsw */ + if (u->flags & UNIT_2501) /* we use u-> not cr_unit. because PUNCH is always a 1442 */ + CLRBIT(cr_dsw, CR_DSW_2501_BUSY); + else + CLRBIT(cr_dsw, CR_DSW_1442_BUSY); /* this is trickier. 1442 cr and cp share a dsw */ - if (issue_intr) { /* issue op-complete interrupt for read and punch ops but not feed */ - if (u->flags & UNIT_2501) { - SETBIT(cr_dsw, CR_DSW_2501_OP_COMPLETE); - SETBIT(ILSW[4], ILSW_4_2501_CARD); - } - else { - SETBIT(cr_dsw, CR_DSW_1442_OP_COMPLETE); - SETBIT(ILSW[4], ILSW_4_1442_CARD); - } - calc_ints(); - } + if (issue_intr) { /* issue op-complete interrupt for read and punch ops but not feed */ + if (u->flags & UNIT_2501) { + SETBIT(cr_dsw, CR_DSW_2501_OP_COMPLETE); + SETBIT(ILSW[4], ILSW_4_2501_CARD); + } + else { + SETBIT(cr_dsw, CR_DSW_1442_OP_COMPLETE); + SETBIT(ILSW[4], ILSW_4_1442_CARD); + } + calc_ints(); + } } static t_stat cr_svc (UNIT *uptr) { - int i; + int i; - if (uptr->flags & UNIT_PHYSICAL) - return pcr_svc(uptr); + if (uptr->flags & UNIT_PHYSICAL) + return pcr_svc(uptr); - switch (CURRENT_OP) { - case OP_IDLE: - break; + switch (CURRENT_OP) { + case OP_IDLE: + break; - case OP_FEEDING: - op_done(&cr_unit, "feed", FALSE); - break; + case OP_FEEDING: + op_done(&cr_unit, "feed", FALSE); + break; - case OP_READING: - if (readstate == STATION_EMPTY) { /* read active but no cards? hang */ - sim_activate(&cr_unit, cf_wait); - break; - } + case OP_READING: + if (readstate == STATION_EMPTY) { /* read active but no cards? hang */ + sim_activate(&cr_unit, cf_wait); + break; + } - if (cr_unit.flags & UNIT_2501) { /* 2501 transfers entire card then interrupts */ - for (i = 0; i < cr_cols; i++) /* (we wait until end of delay time before transferring data) */ - M[(cr_addr + i) & mem_mask] = readstation[i]; + if (cr_unit.flags & UNIT_2501) { /* 2501 transfers entire card then interrupts */ + for (i = 0; i < cr_cols; i++) /* (we wait until end of delay time before transferring data) */ + M[(cr_addr + i) & mem_mask] = readstation[i]; - readstate = STATION_READ; - op_done(&cr_unit, "read", TRUE); - } - else if (++cr_unit.COLUMN < 80) { /* 1442 interrupts on each column... */ - SETBIT(cr_dsw, CR_DSW_1442_READ_RESPONSE); - SETBIT(ILSW[0], ILSW_0_1442_CARD); - calc_ints(); - sim_activate(&cr_unit, cr_wait); - if (cr_unit.flags & UNIT_DEBUG) - DEBUG_PRINT("!CR Read Response %d : %d", cr_count, cr_unit.COLUMN+1); - } - else { /* ... then issues op-complete */ - readstate = STATION_READ; - op_done(&cr_unit, "read", TRUE); - } - break; + readstate = STATION_READ; + op_done(&cr_unit, "read", TRUE); + } + else if (++cr_unit.COLUMN < 80) { /* 1442 interrupts on each column... */ + SETBIT(cr_dsw, CR_DSW_1442_READ_RESPONSE); + SETBIT(ILSW[0], ILSW_0_1442_CARD); + calc_ints(); + sim_activate(&cr_unit, cr_wait); + if (cr_unit.flags & UNIT_DEBUG) + DEBUG_PRINT("!CR Read Response %d : %d", cr_count, cr_unit.COLUMN+1); + } + else { /* ... then issues op-complete */ + readstate = STATION_READ; + op_done(&cr_unit, "read", TRUE); + } + break; - case OP_PUNCHING: - if (punchstate == STATION_EMPTY) { /* punch active but no cards? hang */ - sim_activate(&cr_unit, cf_wait); - break; - } + case OP_PUNCHING: + if (punchstate == STATION_EMPTY) { /* punch active but no cards? hang */ + sim_activate(&cr_unit, cf_wait); + break; + } - if (cp_unit.flags & UNIT_LASTPUNCH) { - punchstate = STATION_PUNCHED; - op_done(&cp_unit, "punch", TRUE); - } - else if (++cp_unit.COLUMN < 80) { - SETBIT(cr_dsw, CR_DSW_1442_PUNCH_RESPONSE); - SETBIT(ILSW[0], ILSW_0_1442_CARD); - calc_ints(); - sim_activate(&cr_unit, cp_wait); - if (cr_unit.flags & UNIT_DEBUG) - DEBUG_PRINT("!CR Punch Response"); - } - else { - punchstate = STATION_PUNCHED; - op_done(&cp_unit, "punch", TRUE); - } - break; - } + if (cp_unit.flags & UNIT_LASTPUNCH) { + punchstate = STATION_PUNCHED; + op_done(&cp_unit, "punch", TRUE); + } + else if (++cp_unit.COLUMN < 80) { + SETBIT(cr_dsw, CR_DSW_1442_PUNCH_RESPONSE); + SETBIT(ILSW[0], ILSW_0_1442_CARD); + calc_ints(); + sim_activate(&cr_unit, cp_wait); + if (cr_unit.flags & UNIT_DEBUG) + DEBUG_PRINT("!CR Punch Response"); + } + else { + punchstate = STATION_PUNCHED; + op_done(&cp_unit, "punch", TRUE); + } + break; + } - return SCPE_OK; + return SCPE_OK; } void xio_2501_card (int32 addr, int32 func, int32 modify) { - char msg[80]; - int ch; - t_bool lastcard; + char msg[80]; + int ch; + t_bool lastcard; /* it would be nice for simulated reader to be able to use 2501 mode -- much more * efficient. Using the 1403 printer and 2501 reader speeds things up quite considerably. */ - switch (func) { - case XIO_SENSE_DEV: - if (cr_unit.flags & UNIT_PHYSICAL) { - pcr_xio_sense(modify); - break; - } + switch (func) { + case XIO_SENSE_DEV: + if (cr_unit.flags & UNIT_PHYSICAL) { + pcr_xio_sense(modify); + break; + } // the following part is questionable -- the 2501 might need to be more picky about setting // the LAST_CARD bit... - if ((cr_unit.flags & UNIT_ATT) == 0) - lastcard = TRUE; /* if nothing to read, hopper's empty */ - else if (readstate == STATION_LOADED) - lastcard = FALSE; - else if (cr_unit.fileref == NULL) - lastcard = TRUE; - else if ((ch = getc(cr_unit.fileref)) != EOF) { - ungetc(ch, cr_unit.fileref); /* put character back; hopper's not empty */ - lastcard = FALSE; - } - else if (deckfile != NULL && nextdeck()) - lastcard = FALSE; - else - lastcard = TRUE; /* there is nothing left to read for a next card */ + if ((cr_unit.flags & UNIT_ATT) == 0) + lastcard = TRUE; /* if nothing to read, hopper's empty */ + else if (readstate == STATION_LOADED) + lastcard = FALSE; + else if (cr_unit.fileref == NULL) + lastcard = TRUE; + else if ((ch = getc(cr_unit.fileref)) != EOF) { + ungetc(ch, cr_unit.fileref); /* put character back; hopper's not empty */ + lastcard = FALSE; + } + else if (deckfile != NULL && nextdeck()) + lastcard = FALSE; + else + lastcard = TRUE; /* there is nothing left to read for a next card */ - CLRBIT(cr_dsw, CR_DSW_2501_LAST_CARD|CR_DSW_2501_BUSY|CR_DSW_2501_NOT_READY); + CLRBIT(cr_dsw, CR_DSW_2501_LAST_CARD|CR_DSW_2501_BUSY|CR_DSW_2501_NOT_READY); - if (lastcard) - SETBIT(cr_dsw, CR_DSW_2501_LAST_CARD|CR_DSW_2501_NOT_READY); - // don't clear it here -- modify bit must be set before last card can be cleared + if (lastcard) + SETBIT(cr_dsw, CR_DSW_2501_LAST_CARD|CR_DSW_2501_NOT_READY); + // don't clear it here -- modify bit must be set before last card can be cleared - if (CURRENT_OP != OP_IDLE) - SETBIT(cr_dsw, CR_DSW_2501_BUSY|CR_DSW_2501_NOT_READY); + if (CURRENT_OP != OP_IDLE) + SETBIT(cr_dsw, CR_DSW_2501_BUSY|CR_DSW_2501_NOT_READY); - ACC = cr_dsw; /* return the DSW */ + ACC = cr_dsw; /* return the DSW */ - if (cr_unit.flags & UNIT_DEBUG) - DEBUG_PRINT("#CR Sense %04x%s", cr_dsw & 0xFFFF, (modify & 1) ? " RESET" : ""); + if (cr_unit.flags & UNIT_DEBUG) + DEBUG_PRINT("#CR Sense %04x%s", cr_dsw & 0xFFFF, (modify & 1) ? " RESET" : ""); - if (modify & 0x01) { /* reset interrupts */ -// if (! lastcard) /* (lastcard is reset only when modify bit is set) */ - CLRBIT(cr_dsw, CR_DSW_2501_LAST_CARD); - CLRBIT(cr_dsw, CR_DSW_2501_OP_COMPLETE); - CLRBIT(ILSW[4], ILSW_4_2501_CARD); - } - break; + if (modify & 0x01) { /* reset interrupts */ +// if (! lastcard) /* (lastcard is reset only when modify bit is set) */ + CLRBIT(cr_dsw, CR_DSW_2501_LAST_CARD); + CLRBIT(cr_dsw, CR_DSW_2501_OP_COMPLETE); + CLRBIT(ILSW[4], ILSW_4_2501_CARD); + } + break; - case XIO_INITR: - if (cr_unit.flags & UNIT_DEBUG) - DEBUG_PRINT("#CR Start read"); + case XIO_INITR: + if (cr_unit.flags & UNIT_DEBUG) + DEBUG_PRINT("#CR Start read"); - cr_unit.COLUMN = -1; + cr_unit.COLUMN = -1; - cr_cols = M[addr & mem_mask]; /* save column count and transfer address */ - cr_addr = addr+1; + cr_cols = M[addr & mem_mask]; /* save column count and transfer address */ + cr_addr = addr+1; - if ((cr_cols < 0) || (cr_cols > 80)) /* this is questionable -- what would hardware do? */ - cr_cols = 80; + if ((cr_cols < 0) || (cr_cols > 80)) /* this is questionable -- what would hardware do? */ + cr_cols = 80; - if (cr_unit.flags & UNIT_PHYSICAL) { - pcr_xio_startread(); - break; - } + if (cr_unit.flags & UNIT_PHYSICAL) { + pcr_xio_startread(); + break; + } - if (readstate != STATION_LOADED) - feedcycle(TRUE, (cp_unit.flags & UNIT_ATT) != 0); + if (readstate != STATION_LOADED) + feedcycle(TRUE, (cp_unit.flags & UNIT_ATT) != 0); - SET_OP(OP_READING); - sim_cancel(&cr_unit); - sim_activate(&cr_unit, cr_wait2501); - break; + SET_OP(OP_READING); + sim_cancel(&cr_unit); + sim_activate(&cr_unit, cr_wait2501); + break; - default: - sprintf(msg, "Invalid 2501 XIO function %x", func); - xio_error(msg); - break; - } + default: + sprintf(msg, "Invalid 2501 XIO function %x", func); + xio_error(msg); + break; + } } void xio_1442_card (int32 addr, int32 func, int32 modify) { - char msg[80]; - int ch; - uint16 wd; - t_bool lastcard; + char msg[80]; + int ch; + uint16 wd; + t_bool lastcard; - switch (func) { - case XIO_SENSE_DEV: - if (cr_unit.flags & UNIT_PHYSICAL) { - pcr_xio_sense(modify); - break; - } + switch (func) { + case XIO_SENSE_DEV: + if (cr_unit.flags & UNIT_PHYSICAL) { + pcr_xio_sense(modify); + break; + } /* glunk * have to separate out what status is 1442 is punch only and 2501 is the reader */ - if (cp_unit.flags & UNIT_ATT) - lastcard = FALSE; /* if punch file is open, assume infinite blank cards in reader */ - else if ((cr_unit.flags & UNIT_ATT) == 0) - lastcard = TRUE; /* if nothing to read, hopper's empty */ - else if (readstate == STATION_LOADED) - lastcard = FALSE; - else if (cr_unit.fileref == NULL) - lastcard = TRUE; - else if ((ch = getc(cr_unit.fileref)) != EOF) { - ungetc(ch, cr_unit.fileref); /* put character back; hopper's not empty */ - lastcard = FALSE; - } - else if (deckfile != NULL && nextdeck()) - lastcard = FALSE; - else - lastcard = TRUE; /* there is nothing left to read for a next card */ + if (cp_unit.flags & UNIT_ATT) + lastcard = FALSE; /* if punch file is open, assume infinite blank cards in reader */ + else if ((cr_unit.flags & UNIT_ATT) == 0) + lastcard = TRUE; /* if nothing to read, hopper's empty */ + else if (readstate == STATION_LOADED) + lastcard = FALSE; + else if (cr_unit.fileref == NULL) + lastcard = TRUE; + else if ((ch = getc(cr_unit.fileref)) != EOF) { + ungetc(ch, cr_unit.fileref); /* put character back; hopper's not empty */ + lastcard = FALSE; + } + else if (deckfile != NULL && nextdeck()) + lastcard = FALSE; + else + lastcard = TRUE; /* there is nothing left to read for a next card */ - CLRBIT(cr_dsw, CR_DSW_1442_LAST_CARD | CR_DSW_1442_BUSY | CR_DSW_1442_NOT_READY); + CLRBIT(cr_dsw, CR_DSW_1442_LAST_CARD | CR_DSW_1442_BUSY | CR_DSW_1442_NOT_READY); - if (lastcard) - SETBIT(cr_dsw, CR_DSW_1442_LAST_CARD); + if (lastcard) + SETBIT(cr_dsw, CR_DSW_1442_LAST_CARD); - if (CURRENT_OP != OP_IDLE) - SETBIT(cr_dsw, CR_DSW_1442_BUSY | CR_DSW_1442_NOT_READY); - else if (readstate == STATION_EMPTY && punchstate == STATION_EMPTY && lastcard) - SETBIT(cr_dsw, CR_DSW_1442_NOT_READY); + if (CURRENT_OP != OP_IDLE) + SETBIT(cr_dsw, CR_DSW_1442_BUSY | CR_DSW_1442_NOT_READY); + else if (readstate == STATION_EMPTY && punchstate == STATION_EMPTY && lastcard) + SETBIT(cr_dsw, CR_DSW_1442_NOT_READY); - ACC = cr_dsw; /* return the DSW */ + ACC = cr_dsw; /* return the DSW */ - if (cr_unit.flags & UNIT_DEBUG) - DEBUG_PRINT("#CR Sense %04x%s%s", cr_dsw & 0xFFFF, (modify & 1) ? " RESET0" : "", (modify & 2) ? " RESET4" : ""); + if (cr_unit.flags & UNIT_DEBUG) + DEBUG_PRINT("#CR Sense %04x%s%s", cr_dsw & 0xFFFF, (modify & 1) ? " RESET0" : "", (modify & 2) ? " RESET4" : ""); - if (modify & 0x01) { /* reset interrupts */ - CLRBIT(cr_dsw, CR_DSW_1442_READ_RESPONSE | CR_DSW_1442_PUNCH_RESPONSE); - CLRBIT(ILSW[0], ILSW_0_1442_CARD); - } + if (modify & 0x01) { /* reset interrupts */ + CLRBIT(cr_dsw, CR_DSW_1442_READ_RESPONSE | CR_DSW_1442_PUNCH_RESPONSE); + CLRBIT(ILSW[0], ILSW_0_1442_CARD); + } - if (modify & 0x02) { - CLRBIT(cr_dsw, CR_DSW_1442_OP_COMPLETE); - CLRBIT(ILSW[4], ILSW_4_1442_CARD); - } - break; + if (modify & 0x02) { + CLRBIT(cr_dsw, CR_DSW_1442_OP_COMPLETE); + CLRBIT(ILSW[4], ILSW_4_1442_CARD); + } + break; - case XIO_READ: /* get card data into word pointed to in IOCC packet */ - if (cr_unit.flags & OP_READING) { - if (cr_unit.COLUMN < 0) { - xio_error("1442: Premature read!"); - } - else if (cr_unit.COLUMN < 80) { - WriteW(addr, readstation[cr_unit.COLUMN]); - if (cr_unit.flags & UNIT_DEBUG) - DEBUG_PRINT("#CR Read %03x", (readstation[cr_unit.COLUMN] >> 4)); - } - else if (cr_unit.COLUMN == 80) { - xio_error("1442: Read past column 80!"); - cr_unit.COLUMN++; /* don't report it again */ - } - } - else { + case XIO_READ: /* get card data into word pointed to in IOCC packet */ + if (cr_unit.flags & OP_READING) { + if (cr_unit.COLUMN < 0) { + xio_error("1442: Premature read!"); + } + else if (cr_unit.COLUMN < 80) { + WriteW(addr, readstation[cr_unit.COLUMN]); + if (cr_unit.flags & UNIT_DEBUG) + DEBUG_PRINT("#CR Read %03x", (readstation[cr_unit.COLUMN] >> 4)); + } + else if (cr_unit.COLUMN == 80) { + xio_error("1442: Read past column 80!"); + cr_unit.COLUMN++; /* don't report it again */ + } + } + else { /* don't complain: APL\1130 issues both reads and writes on every interrupt * (probably to keep the code small). Apparently it's just ignored if corresponding * control didn't initiate a read cycle. - * xio_error("1442: Read when not in a read cycle!"); */ - } - break; + * xio_error("1442: Read when not in a read cycle!"); */ + } + break; - case XIO_WRITE: - if (cr_unit.flags & OP_PUNCHING) { - if (cp_unit.COLUMN < 0) { - xio_error("1442: Premature write!"); - } - else if (cp_unit.flags & UNIT_LASTPUNCH) { - xio_error("1442: Punch past last-punch column!"); - cp_unit.COLUMN = 81; - } - else if (cp_unit.COLUMN < 80) { - wd = (uint16) ReadW(addr); /* store one word to punch buffer */ - punchstation[cp_unit.COLUMN] = wd & 0xFFF0; - if (wd & 0x0008) /* mark this as last column to be punched */ - SETBIT(cp_unit.flags, UNIT_LASTPUNCH); - if (cr_unit.flags & UNIT_DEBUG) - DEBUG_PRINT("#CR Punch %03x%s", (wd >> 4) & 0xFFF, (wd & 8) ? " LAST" : ""); - } - else if (cp_unit.COLUMN == 80) { - xio_error("1442: Punch past column 80!"); - cp_unit.COLUMN++; /* don't report it again */ - } - } - else { + case XIO_WRITE: + if (cr_unit.flags & OP_PUNCHING) { + if (cp_unit.COLUMN < 0) { + xio_error("1442: Premature write!"); + } + else if (cp_unit.flags & UNIT_LASTPUNCH) { + xio_error("1442: Punch past last-punch column!"); + cp_unit.COLUMN = 81; + } + else if (cp_unit.COLUMN < 80) { + wd = (uint16) ReadW(addr); /* store one word to punch buffer */ + punchstation[cp_unit.COLUMN] = wd & 0xFFF0; + if (wd & 0x0008) /* mark this as last column to be punched */ + SETBIT(cp_unit.flags, UNIT_LASTPUNCH); + if (cr_unit.flags & UNIT_DEBUG) + DEBUG_PRINT("#CR Punch %03x%s", (wd >> 4) & 0xFFF, (wd & 8) ? " LAST" : ""); + } + else if (cp_unit.COLUMN == 80) { + xio_error("1442: Punch past column 80!"); + cp_unit.COLUMN++; /* don't report it again */ + } + } + else { /* don't complain: APL\1130 issues both reads and writes on every interrupt * (probably to keep the code small). Apparently it's just ignored if corresponding * control didn't initiate a punch cycle. - * xio_error("1442: Write when not in a punch cycle!"); */ - } - break; + * xio_error("1442: Write when not in a punch cycle!"); */ + } + break; - case XIO_CONTROL: - switch (modify & 7) { - case 1: /* start punch */ - if (cr_unit.flags & UNIT_DEBUG) - DEBUG_PRINT("#CR Start Punch"); - if (punchstate != STATION_LOADED) - feedcycle(TRUE, TRUE); + case XIO_CONTROL: + switch (modify & 7) { + case 1: /* start punch */ + if (cr_unit.flags & UNIT_DEBUG) + DEBUG_PRINT("#CR Start Punch"); + if (punchstate != STATION_LOADED) + feedcycle(TRUE, TRUE); - SET_OP(OP_PUNCHING); - cp_unit.COLUMN = -1; + SET_OP(OP_PUNCHING); + cp_unit.COLUMN = -1; - CLRBIT(cp_unit.flags, UNIT_LASTPUNCH); + CLRBIT(cp_unit.flags, UNIT_LASTPUNCH); - any_punched = 1; /* we've started punching, so enable writing to output deck file */ + any_punched = 1; /* we've started punching, so enable writing to output deck file */ - sim_cancel(&cr_unit); - sim_activate(&cr_unit, cp_wait); - break; + sim_cancel(&cr_unit); + sim_activate(&cr_unit, cp_wait); + break; - case 2: /* feed cycle */ - if (cr_unit.flags & UNIT_DEBUG) - DEBUG_PRINT("#CR Feed"); + case 2: /* feed cycle */ + if (cr_unit.flags & UNIT_DEBUG) + DEBUG_PRINT("#CR Feed"); - if (cr_unit.flags & UNIT_PHYSICAL) { - pcr_xio_feedcycle(); - break; - } + if (cr_unit.flags & UNIT_PHYSICAL) { + pcr_xio_feedcycle(); + break; + } - feedcycle(TRUE, (cp_unit.flags & UNIT_ATT) != 0); + feedcycle(TRUE, (cp_unit.flags & UNIT_ATT) != 0); - SET_OP(OP_FEEDING); - sim_cancel(&cr_unit); - sim_activate(&cr_unit, cf_wait); - break; + SET_OP(OP_FEEDING); + sim_cancel(&cr_unit); + sim_activate(&cr_unit, cf_wait); + break; - case 4: /* start read */ - if (cr_unit.flags & UNIT_DEBUG) - DEBUG_PRINT("#CR Start read"); + case 4: /* start read */ + if (cr_unit.flags & UNIT_DEBUG) + DEBUG_PRINT("#CR Start read"); - cr_unit.COLUMN = -1; + cr_unit.COLUMN = -1; - if (cr_unit.flags & UNIT_PHYSICAL) { - pcr_xio_startread(); - break; - } + if (cr_unit.flags & UNIT_PHYSICAL) { + pcr_xio_startread(); + break; + } - if (readstate != STATION_LOADED) - feedcycle(TRUE, (cp_unit.flags & UNIT_ATT) != 0); + if (readstate != STATION_LOADED) + feedcycle(TRUE, (cp_unit.flags & UNIT_ATT) != 0); - SET_OP(OP_READING); - sim_cancel(&cr_unit); - sim_activate(&cr_unit, cr_wait); - break; + SET_OP(OP_READING); + sim_cancel(&cr_unit); + sim_activate(&cr_unit, cr_wait); + break; - case 0: - if (cr_unit.flags & UNIT_DEBUG) - DEBUG_PRINT("#CR NOP"); - break; + case 0: + if (cr_unit.flags & UNIT_DEBUG) + DEBUG_PRINT("#CR NOP"); + break; - default: - sprintf(msg, "1442: Multiple operations in XIO_CONTROL: %x", modify); - xio_error(msg); - return; - } + default: + sprintf(msg, "1442: Multiple operations in XIO_CONTROL: %x", modify); + xio_error(msg); + return; + } - break; + break; - default: - sprintf(msg, "Invalid 1442 XIO function %x", func); - xio_error(msg); - break; - } + default: + sprintf(msg, "Invalid 1442 XIO function %x", func); + xio_error(msg); + break; + } } #if ! (defined(ENABLE_PHYSICAL_CARD_READER_SUPPORT) && defined(WIN32)) - /* stub out the physical card reader routines */ + /* stub out the physical card reader routines */ - static t_stat pcr_attach (UNIT *uptr, CONST char *devname) {return SCPE_ARG;} - static t_stat pcr_detach (UNIT *uptr) {return detach_unit(uptr);} - static t_stat pcr_svc (UNIT *uptr) {return SCPE_OK;} - static void pcr_xio_sense (int modify) {} - static void pcr_xio_feedcycle (void) {} - static void pcr_xio_startread (void) {} - static void pcr_reset (void) {} + static t_stat pcr_attach (UNIT *uptr, CONST char *devname) {return SCPE_ARG;} + static t_stat pcr_detach (UNIT *uptr) {return detach_unit(uptr);} + static t_stat pcr_svc (UNIT *uptr) {return SCPE_OK;} + static void pcr_xio_sense (int modify) {} + static void pcr_xio_feedcycle (void) {} + static void pcr_xio_startread (void) {} + static void pcr_reset (void) {} #else @@ -2111,575 +2111,575 @@ void xio_1442_card (int32 addr, int32 func, int32 modify) #include -#define PCR_STATUS_READY 1 /* bits in interface reply byte */ -#define PCR_STATUS_ERROR 2 -#define PCR_STATUS_HEMPTY 4 -#define PCR_STATUS_EOF 8 -#define PCR_STATUS_PICKING 16 +#define PCR_STATUS_READY 1 /* bits in interface reply byte */ +#define PCR_STATUS_ERROR 2 +#define PCR_STATUS_HEMPTY 4 +#define PCR_STATUS_EOF 8 +#define PCR_STATUS_PICKING 16 -#define PCR_STATUS_MSEC 150 /* when idle, get status every 150 msec */ +#define PCR_STATUS_MSEC 150 /* when idle, get status every 150 msec */ typedef enum { - PCR_STATE_IDLE, /* nothing expected from the interface */ - PCR_STATE_WAIT_CMD_RESPONSE, /* waiting for response from any command other than P */ - PCR_STATE_WAIT_PICK_CMD_RESPONSE, /* waiting for response from P command */ - PCR_STATE_WAIT_DATA_START, /* waiting for introduction to data from P command */ - PCR_STATE_WAIT_DATA, /* waiting for data from P command */ - PCR_STATE_WAIT_PICK_FINAL_RESPONSE, /* waiting for status byte after last of the card data */ - PCR_STATE_CLOSED + PCR_STATE_IDLE, /* nothing expected from the interface */ + PCR_STATE_WAIT_CMD_RESPONSE, /* waiting for response from any command other than P */ + PCR_STATE_WAIT_PICK_CMD_RESPONSE, /* waiting for response from P command */ + PCR_STATE_WAIT_DATA_START, /* waiting for introduction to data from P command */ + PCR_STATE_WAIT_DATA, /* waiting for data from P command */ + PCR_STATE_WAIT_PICK_FINAL_RESPONSE, /* waiting for status byte after last of the card data */ + PCR_STATE_CLOSED } PCR_STATE; static void pcr_cmd (char cmd); static DWORD CALLBACK pcr_thread (LPVOID arg); -static BOOL pcr_handle_status_byte (int nrcvd); +static BOOL pcr_handle_status_byte (int nrcvd); static void pcr_trigger_interrupt_0(void); static void begin_pcr_critical_section (void); static void end_pcr_critical_section (void); static void pcr_set_dsw_from_status (BOOL post_pick); static t_stat pcr_open_controller (const char *devname); -static PCR_STATE pcr_state = PCR_STATE_CLOSED; /* current state of connection to physical card reader interface */ -static char pcr_status = 0; /* last status byte received from the interface */ -static int pcr_nleft; /* number of bytes still expected from pick command */ -static int pcr_nready; /* number of bytes waiting in the input buffer for simulator to read */ -static BOOL pcr_done; +static PCR_STATE pcr_state = PCR_STATE_CLOSED; /* current state of connection to physical card reader interface */ +static char pcr_status = 0; /* last status byte received from the interface */ +static int pcr_nleft; /* number of bytes still expected from pick command */ +static int pcr_nready; /* number of bytes waiting in the input buffer for simulator to read */ +static BOOL pcr_done; static HANDLE hpcr = INVALID_HANDLE_VALUE; static HANDLE hPickEvent = INVALID_HANDLE_VALUE; static HANDLE hResetEvent = INVALID_HANDLE_VALUE; -static OVERLAPPED ovRd, ovWr; /* overlapped IO structures for reading from, writing to device */ -static int nwaits; /* number of timeouts waiting for response from interface */ -static char response_byte; /* buffer to receive command/status response byte from overlapped read */ -static char lastcmd = '?'; +static OVERLAPPED ovRd, ovWr; /* overlapped IO structures for reading from, writing to device */ +static int nwaits; /* number of timeouts waiting for response from interface */ +static char response_byte; /* buffer to receive command/status response byte from overlapped read */ +static char lastcmd = '?'; /* pcr_attach - perform attach function to physical card reader */ static t_stat pcr_attach (UNIT *uptr, CONST char *devname) { - DWORD thread_id; - t_stat rval; + DWORD thread_id; + t_stat rval; - pcr_state = PCR_STATE_CLOSED; - sim_cancel(uptr); - cr_unit.COLUMN = -1; /* device is not currently cycling */ + pcr_state = PCR_STATE_CLOSED; + sim_cancel(uptr); + cr_unit.COLUMN = -1; /* device is not currently cycling */ - if ((rval = pcr_open_controller(devname)) != SCPE_OK) - return rval; + if ((rval = pcr_open_controller(devname)) != SCPE_OK) + return rval; - if (hPickEvent == INVALID_HANDLE_VALUE) - hPickEvent = CreateEvent(NULL, FALSE, FALSE, NULL); + if (hPickEvent == INVALID_HANDLE_VALUE) + hPickEvent = CreateEvent(NULL, FALSE, FALSE, NULL); - if (hResetEvent == INVALID_HANDLE_VALUE) - hResetEvent = CreateEvent(NULL, FALSE, FALSE, NULL); + if (hResetEvent == INVALID_HANDLE_VALUE) + hResetEvent = CreateEvent(NULL, FALSE, FALSE, NULL); - pcr_status = PCR_STATUS_HEMPTY; /* set default status: offline, no cards */ - pcr_state = PCR_STATE_IDLE; - pcr_done = FALSE; - cr_dsw = CR_DSW_1442_LAST_CARD | CR_DSW_1442_NOT_READY; + pcr_status = PCR_STATUS_HEMPTY; /* set default status: offline, no cards */ + pcr_state = PCR_STATE_IDLE; + pcr_done = FALSE; + cr_dsw = CR_DSW_1442_LAST_CARD | CR_DSW_1442_NOT_READY; - set_active_cr_code(CODE_BINARY); /* force binary mode */ + set_active_cr_code(CODE_BINARY); /* force binary mode */ - if (CreateThread(NULL, 0, pcr_thread, NULL, 0, &thread_id) == NULL) { - pcr_state = PCR_STATE_CLOSED; - CloseHandle(hpcr); - hpcr = INVALID_HANDLE_VALUE; - printf("Error creating card reader thread\n"); - return SCPE_IERR; - } + if (CreateThread(NULL, 0, pcr_thread, NULL, 0, &thread_id) == NULL) { + pcr_state = PCR_STATE_CLOSED; + CloseHandle(hpcr); + hpcr = INVALID_HANDLE_VALUE; + printf("Error creating card reader thread\n"); + return SCPE_IERR; + } - SETBIT(uptr->flags, UNIT_PHYSICAL|UNIT_ATT); /* mark device as attached */ - uptr->filename = (char *)malloc(strlen(devname)+1); - strcpy(uptr->filename, devname); + SETBIT(uptr->flags, UNIT_PHYSICAL|UNIT_ATT); /* mark device as attached */ + uptr->filename = (char *)malloc(strlen(devname)+1); + strcpy(uptr->filename, devname); - return SCPE_OK; + return SCPE_OK; } /* pcr_open_controller - open the USB device's virtual COM port and configure the interface */ static t_stat pcr_open_controller (const char *devname) { - DCB dcb; - COMMTIMEOUTS cto; - DWORD nerr; + DCB dcb; + COMMTIMEOUTS cto; + DWORD nerr; - if (hpcr != INVALID_HANDLE_VALUE) - return SCPE_OK; - /* open the COM port */ - hpcr = CreateFile(devname, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); - if (hpcr == INVALID_HANDLE_VALUE) - return SCPE_OPENERR; + if (hpcr != INVALID_HANDLE_VALUE) + return SCPE_OK; + /* open the COM port */ + hpcr = CreateFile(devname, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); + if (hpcr == INVALID_HANDLE_VALUE) + return SCPE_OPENERR; - memset(&dcb, 0, sizeof(dcb)); /* set communications parameters */ + memset(&dcb, 0, sizeof(dcb)); /* set communications parameters */ - dcb.DCBlength = sizeof(DCB); - dcb.BaudRate = CBR_115200; /* for the USB virtual com port, baud rate is irrelevant */ - dcb.fBinary = 1; - dcb.fParity = 0; + dcb.DCBlength = sizeof(DCB); + dcb.BaudRate = CBR_115200; /* for the USB virtual com port, baud rate is irrelevant */ + dcb.fBinary = 1; + dcb.fParity = 0; dcb.fOutxCtsFlow = 0; dcb.fOutxDsrFlow = 0; - dcb.fDtrControl = DTR_CONTROL_ENABLE; + dcb.fDtrControl = DTR_CONTROL_ENABLE; dcb.fDsrSensitivity = FALSE; dcb.fTXContinueOnXoff = 0; - dcb.fOutX = 0; - dcb.fInX = 0; - dcb.fErrorChar = 0; - dcb.fNull = 0; - dcb.fRtsControl = RTS_CONTROL_ENABLE; + dcb.fOutX = 0; + dcb.fInX = 0; + dcb.fErrorChar = 0; + dcb.fNull = 0; + dcb.fRtsControl = RTS_CONTROL_ENABLE; dcb.fAbortOnError = 0; - dcb.XonLim = 0; - dcb.XoffLim = 0; - dcb.ByteSize = 8; - dcb.Parity = NOPARITY; - dcb.StopBits = ONESTOPBIT; - dcb.XonChar = 0; - dcb.XoffChar = 0; - dcb.ErrorChar = 0; - dcb.EofChar = 0; - dcb.EvtChar = 0; + dcb.XonLim = 0; + dcb.XoffLim = 0; + dcb.ByteSize = 8; + dcb.Parity = NOPARITY; + dcb.StopBits = ONESTOPBIT; + dcb.XonChar = 0; + dcb.XoffChar = 0; + dcb.ErrorChar = 0; + dcb.EofChar = 0; + dcb.EvtChar = 0; - if (! SetCommState(hpcr, &dcb)) { - CloseHandle(hpcr); - hpcr = INVALID_HANDLE_VALUE; - printf("Call to SetCommState failed\n"); - return SCPE_OPENERR; - } + if (! SetCommState(hpcr, &dcb)) { + CloseHandle(hpcr); + hpcr = INVALID_HANDLE_VALUE; + printf("Call to SetCommState failed\n"); + return SCPE_OPENERR; + } - cto.ReadIntervalTimeout = 100; /* stop if 100 msec elapses between two received bytes */ - cto.ReadTotalTimeoutMultiplier = 0; /* no length sensitivity */ - cto.ReadTotalTimeoutConstant = 400; /* allow 400 msec for a read (reset command can take a while) */ + cto.ReadIntervalTimeout = 100; /* stop if 100 msec elapses between two received bytes */ + cto.ReadTotalTimeoutMultiplier = 0; /* no length sensitivity */ + cto.ReadTotalTimeoutConstant = 400; /* allow 400 msec for a read (reset command can take a while) */ cto.WriteTotalTimeoutMultiplier = 0; - cto.WriteTotalTimeoutConstant = 200; /* allow 200 msec for a write */ + cto.WriteTotalTimeoutConstant = 200; /* allow 200 msec for a write */ - if (! SetCommTimeouts(hpcr, &cto)) { - CloseHandle(hpcr); - hpcr = INVALID_HANDLE_VALUE; - printf("Call to SetCommTimeouts failed\n"); - return SCPE_OPENERR; - } + if (! SetCommTimeouts(hpcr, &cto)) { + CloseHandle(hpcr); + hpcr = INVALID_HANDLE_VALUE; + printf("Call to SetCommTimeouts failed\n"); + return SCPE_OPENERR; + } - PurgeComm(hpcr, PURGE_TXABORT|PURGE_RXABORT|PURGE_TXCLEAR|PURGE_RXCLEAR); - ClearCommError(hpcr, &nerr, NULL); + PurgeComm(hpcr, PURGE_TXABORT|PURGE_RXABORT|PURGE_TXCLEAR|PURGE_RXCLEAR); + ClearCommError(hpcr, &nerr, NULL); - return SCPE_OK; + return SCPE_OK; } /* pcr_detach - detach physical reader from CR device */ static t_stat pcr_detach (UNIT *uptr) { - if (cr_unit.flags & UNIT_ATT) { - CloseHandle(hpcr); /* close the COM port (this will lead to the thread closing) */ - hpcr = INVALID_HANDLE_VALUE; - pcr_state = PCR_STATE_CLOSED; + if (cr_unit.flags & UNIT_ATT) { + CloseHandle(hpcr); /* close the COM port (this will lead to the thread closing) */ + hpcr = INVALID_HANDLE_VALUE; + pcr_state = PCR_STATE_CLOSED; - free(uptr->filename); /* release the name copy */ - uptr->filename = NULL; - } + free(uptr->filename); /* release the name copy */ + uptr->filename = NULL; + } - CLRBIT(cr_unit.flags, UNIT_PHYSICAL|UNIT_ATT); /* drop the attach and physical bits */ - return SCPE_OK; + CLRBIT(cr_unit.flags, UNIT_PHYSICAL|UNIT_ATT); /* drop the attach and physical bits */ + return SCPE_OK; } /* pcr_xio_sense - perform XIO sense function on physical card reader */ static void pcr_xio_sense (int modify) { - if (modify & 0x01) { /* reset simulated interrupts */ - CLRBIT(cr_dsw, CR_DSW_1442_READ_RESPONSE | CR_DSW_1442_PUNCH_RESPONSE); - CLRBIT(ILSW[0], ILSW_0_1442_CARD); - } + if (modify & 0x01) { /* reset simulated interrupts */ + CLRBIT(cr_dsw, CR_DSW_1442_READ_RESPONSE | CR_DSW_1442_PUNCH_RESPONSE); + CLRBIT(ILSW[0], ILSW_0_1442_CARD); + } - if (modify & 0x02) { - CLRBIT(cr_dsw, CR_DSW_1442_OP_COMPLETE); - CLRBIT(ILSW[4], ILSW_4_1442_CARD); - } + if (modify & 0x02) { + CLRBIT(cr_dsw, CR_DSW_1442_OP_COMPLETE); + CLRBIT(ILSW[4], ILSW_4_1442_CARD); + } - ACC = cr_dsw; /* DSW was set in real-time, just return the DSW */ + ACC = cr_dsw; /* DSW was set in real-time, just return the DSW */ - if (cr_unit.flags & UNIT_DEBUG) - DEBUG_PRINT("#CR Sense %04x%s%s", cr_dsw, (modify & 1) ? " RESET0" : "", (modify & 2) ? " RESET4" : ""); + if (cr_unit.flags & UNIT_DEBUG) + DEBUG_PRINT("#CR Sense %04x%s%s", cr_dsw, (modify & 1) ? " RESET0" : "", (modify & 2) ? " RESET4" : ""); } /* report_error - issue detailed report of Windows IO error */ static void report_error (char *msg, DWORD err) { - char *lpMessageBuffer = NULL; - - FormatMessage( - FORMAT_MESSAGE_ALLOCATE_BUFFER | - FORMAT_MESSAGE_FROM_SYSTEM, - NULL, - GetLastError(), - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* The user default language */ - (LPTSTR) &lpMessageBuffer, - 0, - NULL ); + char *lpMessageBuffer = NULL; + + FormatMessage( + FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM, + NULL, + GetLastError(), + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* The user default language */ + (LPTSTR) &lpMessageBuffer, + 0, + NULL ); - printf("GetOverlappedResult failed, %s, %s\n", - msg, lpMessageBuffer); + printf("GetOverlappedResult failed, %s, %s\n", + msg, lpMessageBuffer); - LocalFree(lpMessageBuffer); + LocalFree(lpMessageBuffer); } /* pcr_thread - thread to handle card reader interface communications */ static DWORD CALLBACK pcr_thread (LPVOID arg) { - DWORD event; - long nrcvd, nread, nwritten; - HANDLE objs[4]; - BOOL pick_queued = FALSE, reset_queued = FALSE; + DWORD event; + long nrcvd, nread, nwritten; + HANDLE objs[4]; + BOOL pick_queued = FALSE, reset_queued = FALSE; - nwaits = 0; + nwaits = 0; - ZeroMemory(&ovRd, sizeof(ovRd)); - ZeroMemory(&ovWr, sizeof(ovWr)); - ovRd.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); /* create an event for async IO reads */ - ovWr.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); /* create an event for async IO writes */ + ZeroMemory(&ovRd, sizeof(ovRd)); + ZeroMemory(&ovWr, sizeof(ovWr)); + ovRd.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); /* create an event for async IO reads */ + ovWr.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); /* create an event for async IO writes */ - objs[0] = ovRd.hEvent; - objs[1] = ovWr.hEvent; - objs[2] = hResetEvent; - objs[3] = hPickEvent; + objs[0] = ovRd.hEvent; + objs[1] = ovWr.hEvent; + objs[2] = hResetEvent; + objs[3] = hPickEvent; - while (hpcr != INVALID_HANDLE_VALUE) { - if (pcr_state == PCR_STATE_IDLE) { - if (pick_queued) { - pcr_cmd('P'); - pick_queued = FALSE; - pcr_done = FALSE; - pcr_state = PCR_STATE_WAIT_PICK_CMD_RESPONSE; - } - else if (reset_queued) { - pcr_cmd('X'); - reset_queued = FALSE; - pcr_state = PCR_STATE_WAIT_CMD_RESPONSE; - } - } + while (hpcr != INVALID_HANDLE_VALUE) { + if (pcr_state == PCR_STATE_IDLE) { + if (pick_queued) { + pcr_cmd('P'); + pick_queued = FALSE; + pcr_done = FALSE; + pcr_state = PCR_STATE_WAIT_PICK_CMD_RESPONSE; + } + else if (reset_queued) { + pcr_cmd('X'); + reset_queued = FALSE; + pcr_state = PCR_STATE_WAIT_CMD_RESPONSE; + } + } - event = WaitForMultipleObjects(4, objs, FALSE, PCR_STATUS_MSEC); + event = WaitForMultipleObjects(4, objs, FALSE, PCR_STATUS_MSEC); - switch (event) { - case WAIT_OBJECT_0+0: /* read complete */ - ResetEvent(ovRd.hEvent); - if (! GetOverlappedResult(hpcr, &ovRd, &nrcvd, TRUE)) - report_error("PCR_Read", GetLastError()); - else if (cr_unit.flags & UNIT_DEBUG) - printf("PCR_Read: event, %d rcvd\n", nrcvd); - break; + switch (event) { + case WAIT_OBJECT_0+0: /* read complete */ + ResetEvent(ovRd.hEvent); + if (! GetOverlappedResult(hpcr, &ovRd, &nrcvd, TRUE)) + report_error("PCR_Read", GetLastError()); + else if (cr_unit.flags & UNIT_DEBUG) + printf("PCR_Read: event, %d rcvd\n", nrcvd); + break; - case WAIT_OBJECT_0+1: /* write complete */ - nwritten = 0; - ResetEvent(ovWr.hEvent); - if (! GetOverlappedResult(hpcr, &ovWr, &nwritten, TRUE)) - report_error("PCR_Write", GetLastError()); - else if (cr_unit.flags & UNIT_DEBUG) - printf("PCR_Write: event, %d sent\n", nwritten); - continue; + case WAIT_OBJECT_0+1: /* write complete */ + nwritten = 0; + ResetEvent(ovWr.hEvent); + if (! GetOverlappedResult(hpcr, &ovWr, &nwritten, TRUE)) + report_error("PCR_Write", GetLastError()); + else if (cr_unit.flags & UNIT_DEBUG) + printf("PCR_Write: event, %d sent\n", nwritten); + continue; - case WAIT_OBJECT_0+2: /* reset request from simulator */ - reset_queued = TRUE; - pick_queued = FALSE; - continue; + case WAIT_OBJECT_0+2: /* reset request from simulator */ + reset_queued = TRUE; + pick_queued = FALSE; + continue; - case WAIT_OBJECT_0+3: /* pick request from simulator */ - pick_queued = TRUE; - continue; + case WAIT_OBJECT_0+3: /* pick request from simulator */ + pick_queued = TRUE; + continue; - case WAIT_TIMEOUT: - if (pcr_state == PCR_STATE_IDLE) { - pcr_state = PCR_STATE_WAIT_CMD_RESPONSE; - ovRd.Offset = ovRd.OffsetHigh = 0; - pcr_cmd('S'); - } - else if (pcr_state == PCR_STATE_WAIT_CMD_RESPONSE && ++nwaits >= 6) { - printf("Requesting status again!\n"); - ovRd.Offset = ovRd.OffsetHigh = 0; - pcr_cmd('S'); - } - continue; + case WAIT_TIMEOUT: + if (pcr_state == PCR_STATE_IDLE) { + pcr_state = PCR_STATE_WAIT_CMD_RESPONSE; + ovRd.Offset = ovRd.OffsetHigh = 0; + pcr_cmd('S'); + } + else if (pcr_state == PCR_STATE_WAIT_CMD_RESPONSE && ++nwaits >= 6) { + printf("Requesting status again!\n"); + ovRd.Offset = ovRd.OffsetHigh = 0; + pcr_cmd('S'); + } + continue; - default: - printf("Unexpected pcr_wait result %08lx", event); - continue; - } + default: + printf("Unexpected pcr_wait result %08lx", event); + continue; + } - /* We only get here if read event occurred */ + /* We only get here if read event occurred */ - switch (pcr_state) { - case PCR_STATE_IDLE: /* nothing expected from the interface */ - PurgeComm(hpcr, PURGE_RXCLEAR|PURGE_RXABORT); - break; + switch (pcr_state) { + case PCR_STATE_IDLE: /* nothing expected from the interface */ + PurgeComm(hpcr, PURGE_RXCLEAR|PURGE_RXABORT); + break; - case PCR_STATE_WAIT_CMD_RESPONSE: /* waiting for response from any command other than P */ - if (pcr_handle_status_byte(nrcvd)) - pcr_state = PCR_STATE_IDLE; - break; + case PCR_STATE_WAIT_CMD_RESPONSE: /* waiting for response from any command other than P */ + if (pcr_handle_status_byte(nrcvd)) + pcr_state = PCR_STATE_IDLE; + break; - case PCR_STATE_WAIT_PICK_CMD_RESPONSE: /* waiting for response from P command */ - if (pcr_handle_status_byte(nrcvd)) { - pcr_cmd('\0'); /* queue a response read */ - pcr_state = PCR_STATE_WAIT_DATA_START; - } - break; + case PCR_STATE_WAIT_PICK_CMD_RESPONSE: /* waiting for response from P command */ + if (pcr_handle_status_byte(nrcvd)) { + pcr_cmd('\0'); /* queue a response read */ + pcr_state = PCR_STATE_WAIT_DATA_START; + } + break; - case PCR_STATE_WAIT_DATA_START: /* waiting for leadin character from P command (= or !) */ - if (nrcvd <= 0) { /* (this could take an indefinite amount of time) */ - if (cr_unit.flags & UNIT_DEBUG) - printf("PCR: NO RESP YET\n"); + case PCR_STATE_WAIT_DATA_START: /* waiting for leadin character from P command (= or !) */ + if (nrcvd <= 0) { /* (this could take an indefinite amount of time) */ + if (cr_unit.flags & UNIT_DEBUG) + printf("PCR: NO RESP YET\n"); - continue; /* reader is not ready */ - } + continue; /* reader is not ready */ + } - if (cr_unit.flags & UNIT_DEBUG) /* (this could take an indefinite amount of time) */ - printf("PCR: GOT %c\n", response_byte); + if (cr_unit.flags & UNIT_DEBUG) /* (this could take an indefinite amount of time) */ + printf("PCR: GOT %c\n", response_byte); - switch (response_byte) { - case '=': /* = means pick in progress, 160 bytes of data will be coming */ - pcr_state = PCR_STATE_WAIT_DATA; - ovRd.Offset = ovRd.OffsetHigh = 0; - nread = 20; /* initiate a read */ - ReadFile(hpcr, ((char *) readstation), nread, &nrcvd, &ovRd); - break; + switch (response_byte) { + case '=': /* = means pick in progress, 160 bytes of data will be coming */ + pcr_state = PCR_STATE_WAIT_DATA; + ovRd.Offset = ovRd.OffsetHigh = 0; + nread = 20; /* initiate a read */ + ReadFile(hpcr, ((char *) readstation), nread, &nrcvd, &ovRd); + break; - case '!': /* ! means pick has been canceled, status will be coming next */ - pcr_state = PCR_STATE_WAIT_CMD_RESPONSE; - pcr_cmd('\0'); /* initiate read */ - break; + case '!': /* ! means pick has been canceled, status will be coming next */ + pcr_state = PCR_STATE_WAIT_CMD_RESPONSE; + pcr_cmd('\0'); /* initiate read */ + break; - default: /* anything else is a datacomm error, or something */ - /* indicate read check or something */ -/* pcr_state = PCR_STATE_IDLE; */ - break; - } - break; + default: /* anything else is a datacomm error, or something */ + /* indicate read check or something */ +/* pcr_state = PCR_STATE_IDLE; */ + break; + } + break; - case PCR_STATE_WAIT_DATA: /* waiting for data from P command */ - if (cr_unit.flags & UNIT_DEBUG) - printf((nrcvd <= 0) ? "PCR: NO RESP!\n" : "PCR: GOT %d BYTES\n", nrcvd); + case PCR_STATE_WAIT_DATA: /* waiting for data from P command */ + if (cr_unit.flags & UNIT_DEBUG) + printf((nrcvd <= 0) ? "PCR: NO RESP!\n" : "PCR: GOT %d BYTES\n", nrcvd); - if (nrcvd > 0) { - pcr_nleft -= nrcvd; + if (nrcvd > 0) { + pcr_nleft -= nrcvd; - begin_pcr_critical_section(); - pcr_nready += nrcvd; - end_pcr_critical_section(); - } + begin_pcr_critical_section(); + pcr_nready += nrcvd; + end_pcr_critical_section(); + } - if (pcr_nleft > 0) { - ovRd.Offset = ovRd.OffsetHigh = 0; - nread = min(pcr_nleft, 20); - ReadFile(hpcr, ((char *) readstation)+160-pcr_nleft, nread, &nrcvd, &ovRd); - } - else { - pcr_state = PCR_STATE_WAIT_PICK_FINAL_RESPONSE; - pcr_cmd('\0'); /* queue read */ - } - break; + if (pcr_nleft > 0) { + ovRd.Offset = ovRd.OffsetHigh = 0; + nread = min(pcr_nleft, 20); + ReadFile(hpcr, ((char *) readstation)+160-pcr_nleft, nread, &nrcvd, &ovRd); + } + else { + pcr_state = PCR_STATE_WAIT_PICK_FINAL_RESPONSE; + pcr_cmd('\0'); /* queue read */ + } + break; - case PCR_STATE_WAIT_PICK_FINAL_RESPONSE: /* waiting for status byte after last of the card data */ - if (pcr_handle_status_byte(nrcvd)) { - readstate = STATION_READ; - pcr_state = PCR_STATE_IDLE; - pcr_done = TRUE; - } - break; - } - } + case PCR_STATE_WAIT_PICK_FINAL_RESPONSE: /* waiting for status byte after last of the card data */ + if (pcr_handle_status_byte(nrcvd)) { + readstate = STATION_READ; + pcr_state = PCR_STATE_IDLE; + pcr_done = TRUE; + } + break; + } + } - CloseHandle(ovRd.hEvent); - CloseHandle(ovWr.hEvent); + CloseHandle(ovRd.hEvent); + CloseHandle(ovWr.hEvent); - return 0; + return 0; } /* pcr_cmd - issue command byte to interface. Read of response byte is queued */ static void pcr_cmd (char cmd) { - long nwritten, nrcvd; - int status; + long nwritten, nrcvd; + int status; - if (cmd != '\0') { - if (cr_unit.flags & UNIT_DEBUG /* && (cmd != 'S' || cmd != lastcmd) */) - printf("PCR: SENT %c\n", cmd); + if (cmd != '\0') { + if (cr_unit.flags & UNIT_DEBUG /* && (cmd != 'S' || cmd != lastcmd) */) + printf("PCR: SENT %c\n", cmd); - lastcmd = cmd; + lastcmd = cmd; - ResetEvent(ovWr.hEvent); - ovWr.Offset = ovWr.OffsetHigh = 0; - status = WriteFile(hpcr, &cmd, 1, &nwritten, &ovWr); - if (status == 0 && GetLastError() != ERROR_IO_PENDING) - printf("Error initiating write in pcr_cmd\n"); - } + ResetEvent(ovWr.hEvent); + ovWr.Offset = ovWr.OffsetHigh = 0; + status = WriteFile(hpcr, &cmd, 1, &nwritten, &ovWr); + if (status == 0 && GetLastError() != ERROR_IO_PENDING) + printf("Error initiating write in pcr_cmd\n"); + } - ovRd.Offset = ovRd.OffsetHigh = 0; - status = ReadFile(hpcr, &response_byte, 1, &nrcvd, &ovRd); /* if no bytes ready, just return -- a later wait-event will catch it */ - if (status == 0 && GetLastError() != ERROR_IO_PENDING) - printf("Error initiating read in pcr_cmd\n"); + ovRd.Offset = ovRd.OffsetHigh = 0; + status = ReadFile(hpcr, &response_byte, 1, &nrcvd, &ovRd); /* if no bytes ready, just return -- a later wait-event will catch it */ + if (status == 0 && GetLastError() != ERROR_IO_PENDING) + printf("Error initiating read in pcr_cmd\n"); -/* if (cr_unit.flags & UNIT_DEBUG) - * if (nrcvd == 0) - * printf("PCR: NO RESPONSE\n"); - * else - * printf("PCR: RESPONSE %c\n", response_byte); */ +/* if (cr_unit.flags & UNIT_DEBUG) + * if (nrcvd == 0) + * printf("PCR: NO RESPONSE\n"); + * else + * printf("PCR: RESPONSE %c\n", response_byte); */ - nwaits = 0; + nwaits = 0; } /* pcr_handle_status_byte - handle completion of read of response byte */ static BOOL pcr_handle_status_byte (int nrcvd) { - static char prev_status = '?'; - BOOL show; + static char prev_status = '?'; + BOOL show; - if (nrcvd <= 0) - return FALSE; + if (nrcvd <= 0) + return FALSE; - pcr_status = response_byte; /* save new status */ + pcr_status = response_byte; /* save new status */ - show = lastcmd != 'S' || pcr_status != prev_status; + show = lastcmd != 'S' || pcr_status != prev_status; - if ((cr_unit.flags & UNIT_DEBUG) && show) { - printf("PCR: status %c\n", pcr_status); - prev_status = pcr_status; - } + if ((cr_unit.flags & UNIT_DEBUG) && show) { + printf("PCR: status %c\n", pcr_status); + prev_status = pcr_status; + } - pcr_set_dsw_from_status(FALSE); + pcr_set_dsw_from_status(FALSE); - return TRUE; + return TRUE; } /* pcr_set_dsw_from_status - construct device status word from current physical reader status */ static void pcr_set_dsw_from_status (BOOL post_pick) { - /* set 1130 status word bits */ - CLRBIT(cr_dsw, CR_DSW_1442_LAST_CARD | CR_DSW_1442_BUSY | CR_DSW_1442_NOT_READY | CR_DSW_1442_ERROR_CHECK); + /* set 1130 status word bits */ + CLRBIT(cr_dsw, CR_DSW_1442_LAST_CARD | CR_DSW_1442_BUSY | CR_DSW_1442_NOT_READY | CR_DSW_1442_ERROR_CHECK); - if (pcr_status & PCR_STATUS_HEMPTY) - SETBIT(cr_dsw, CR_DSW_1442_LAST_CARD | CR_DSW_1442_NOT_READY); + if (pcr_status & PCR_STATUS_HEMPTY) + SETBIT(cr_dsw, CR_DSW_1442_LAST_CARD | CR_DSW_1442_NOT_READY); - if (pcr_status & PCR_STATUS_ERROR) - SETBIT(cr_dsw, CR_DSW_1442_ERROR_CHECK); + if (pcr_status & PCR_STATUS_ERROR) + SETBIT(cr_dsw, CR_DSW_1442_ERROR_CHECK); - /* we have a problem -- ready doesn't come back up right away after a pick. */ - /* I think I'll fudge this and not set NOT_READY immediately after a pick */ + /* we have a problem -- ready doesn't come back up right away after a pick. */ + /* I think I'll fudge this and not set NOT_READY immediately after a pick */ - if ((! post_pick) && ! (pcr_status & PCR_STATUS_READY)) - SETBIT(cr_dsw, CR_DSW_1442_NOT_READY); + if ((! post_pick) && ! (pcr_status & PCR_STATUS_READY)) + SETBIT(cr_dsw, CR_DSW_1442_NOT_READY); - if (CURRENT_OP != OP_IDLE) - SETBIT(cr_dsw, CR_DSW_1442_BUSY | CR_DSW_1442_NOT_READY); + if (CURRENT_OP != OP_IDLE) + SETBIT(cr_dsw, CR_DSW_1442_BUSY | CR_DSW_1442_NOT_READY); } static void pcr_xio_feedcycle (void) { - SET_OP(OP_FEEDING); - cr_unit.COLUMN = -1; - SetEvent(hPickEvent); - sim_activate(&cr_unit, cr_wait); /* keep checking frequently */ + SET_OP(OP_FEEDING); + cr_unit.COLUMN = -1; + SetEvent(hPickEvent); + sim_activate(&cr_unit, cr_wait); /* keep checking frequently */ } static void pcr_xio_startread (void) { - SET_OP(OP_READING); - cr_unit.COLUMN = -1; - pcr_nleft = 160; - pcr_nready = 0; - SetEvent(hPickEvent); - sim_activate(&cr_unit, cr_wait); /* keep checking frequently */ + SET_OP(OP_READING); + cr_unit.COLUMN = -1; + pcr_nleft = 160; + pcr_nready = 0; + SetEvent(hPickEvent); + sim_activate(&cr_unit, cr_wait); /* keep checking frequently */ } static void pcr_reset (void) { - pcr_status = PCR_STATUS_HEMPTY; /* set default status: offline, no cards */ - pcr_state = PCR_STATE_IDLE; - cr_dsw = CR_DSW_1442_LAST_CARD | CR_DSW_1442_NOT_READY; + pcr_status = PCR_STATUS_HEMPTY; /* set default status: offline, no cards */ + pcr_state = PCR_STATE_IDLE; + cr_dsw = CR_DSW_1442_LAST_CARD | CR_DSW_1442_NOT_READY; - sim_cancel(&cr_unit); + sim_cancel(&cr_unit); - SetEvent(hResetEvent); + SetEvent(hResetEvent); } /* pcr_trigger_interrupt_0 - simulate a read response interrupt so OS will read queued column data */ static void pcr_trigger_interrupt_0 (void) { - if (++cr_unit.COLUMN < 80) { - SETBIT(cr_dsw, CR_DSW_1442_READ_RESPONSE); - SETBIT(ILSW[0], ILSW_0_1442_CARD); - calc_ints(); + if (++cr_unit.COLUMN < 80) { + SETBIT(cr_dsw, CR_DSW_1442_READ_RESPONSE); + SETBIT(ILSW[0], ILSW_0_1442_CARD); + calc_ints(); - begin_pcr_critical_section(); - pcr_nready -= 2; - end_pcr_critical_section(); + begin_pcr_critical_section(); + pcr_nready -= 2; + end_pcr_critical_section(); - if (cr_unit.flags & UNIT_DEBUG) - printf("SET IRQ0 col %d\n", cr_unit.COLUMN+1); - } + if (cr_unit.flags & UNIT_DEBUG) + printf("SET IRQ0 col %d\n", cr_unit.COLUMN+1); + } } static t_stat pcr_svc (UNIT *uptr) { - switch (CURRENT_OP) { - case OP_IDLE: - break; + switch (CURRENT_OP) { + case OP_IDLE: + break; - case OP_READING: - if (pcr_nready >= 2) { /* if there is a whole column buffered, simulate column interrupt*/ - /* pcr_trigger_interrupt_0 - simulate a read response interrupt so OS will read queued column data */ + case OP_READING: + if (pcr_nready >= 2) { /* if there is a whole column buffered, simulate column interrupt*/ + /* pcr_trigger_interrupt_0 - simulate a read response interrupt so OS will read queued column data */ - pcr_trigger_interrupt_0(); - sim_activate(&cr_unit, cr_wait); /* keep checking frequently */ - } - else if (pcr_done) { - pcr_done = FALSE; - cr_count++; - op_done(&cr_unit, "pcr read", TRUE); - pcr_set_dsw_from_status(TRUE); - } - else - sim_activate(&cr_unit, cr_wait); /* keep checking frequently */ - break; + pcr_trigger_interrupt_0(); + sim_activate(&cr_unit, cr_wait); /* keep checking frequently */ + } + else if (pcr_done) { + pcr_done = FALSE; + cr_count++; + op_done(&cr_unit, "pcr read", TRUE); + pcr_set_dsw_from_status(TRUE); + } + else + sim_activate(&cr_unit, cr_wait); /* keep checking frequently */ + break; - case OP_FEEDING: - if (pcr_done) { - cr_count++; - op_done(&cr_unit, "pcr feed", FALSE); - pcr_set_dsw_from_status(TRUE); - } - else - sim_activate(&cr_unit, cr_wait); /* keep checking frequently */ + case OP_FEEDING: + if (pcr_done) { + cr_count++; + op_done(&cr_unit, "pcr feed", FALSE); + pcr_set_dsw_from_status(TRUE); + } + else + sim_activate(&cr_unit, cr_wait); /* keep checking frequently */ - break; + break; - case OP_PUNCHING: - return cr_svc(uptr); - } + case OP_PUNCHING: + return cr_svc(uptr); + } - return SCPE_OK; + return SCPE_OK; } static CRITICAL_SECTION pcr_critsect; static void begin_pcr_critical_section (void) { - static BOOL mustinit = TRUE; + static BOOL mustinit = TRUE; - if (mustinit) { - InitializeCriticalSection(&pcr_critsect); - mustinit = FALSE; - } + if (mustinit) { + InitializeCriticalSection(&pcr_critsect); + mustinit = FALSE; + } - EnterCriticalSection(&pcr_critsect); + EnterCriticalSection(&pcr_critsect); } static void end_pcr_critical_section (void) { - LeaveCriticalSection(&pcr_critsect); + LeaveCriticalSection(&pcr_critsect); } #endif diff --git a/Ibm1130/ibm1130_defs.h b/Ibm1130/ibm1130_defs.h index 30c8963b..d6dbf06a 100644 --- a/Ibm1130/ibm1130_defs.h +++ b/Ibm1130/ibm1130_defs.h @@ -12,15 +12,15 @@ /* ibm1130_defs.h: IBM-1130 simulator definitions */ -#include "sim_defs.h" /* main SIMH defns (include path should include .., or make a copy) */ -#include "sim_console.h" /* more SIMH defns (include path should include .., or make a copy) */ +#include "sim_defs.h" /* main SIMH defns (include path should include .., or make a copy) */ +#include "sim_console.h" /* more SIMH defns (include path should include .., or make a copy) */ #include #include #include #if defined(VMS) - # include /* to pick up 'unlink' */ + # include /* to pick up 'unlink' */ #endif #define MIN(a,b) (((a) <= (b)) ? (a) : (b)) @@ -31,65 +31,65 @@ int strcmpi (const char *a, const char *b); #endif -/* #define GUI_SUPPORT uncomment to compile the GUI extensions. It's defined in the windows ibm1130.mak makefile */ +/* #define GUI_SUPPORT uncomment to compile the GUI extensions. It's defined in the windows ibm1130.mak makefile */ /* ------------------------------------------------------------------------ */ /* Architectural constants */ -#define MAXMEMSIZE (32768) /* 32Kwords */ -#define INIMEMSIZE (16384) /* 16Kwords */ -#define MEMSIZE (cpu_unit.capac) +#define MAXMEMSIZE (32768) /* 32Kwords */ +#define INIMEMSIZE (16384) /* 16Kwords */ +#define MEMSIZE (cpu_unit.capac) -#define ILL_ADR_FLAG 0x40000000 /* an impossible 1130 address */ +#define ILL_ADR_FLAG 0x40000000 /* an impossible 1130 address */ /* ------------------------------------------------------------------------ */ /* Global state */ -extern int cgi; /* TRUE if we are running as a CGI program */ -extern int cgiwritable; /* TRUE if we can write the disk images back to the image file in CGI mode */ +extern int cgi; /* TRUE if we are running as a CGI program */ +extern int cgiwritable; /* TRUE if we can write the disk images back to the image file in CGI mode */ extern t_bool sim_gui; -extern uint16 M[]; /* core memory, up to 32Kwords (note: don't even think about trying 64K) */ -extern uint16 ILSW[]; /* interrupt level status words */ -extern int32 IAR; /* instruction address register */ -extern int32 prev_IAR; /* instruction address register at start of current instruction */ -extern int32 SAR, SBR; /* storage address/buffer registers */ -extern int32 OP, TAG, CCC; /* instruction decoded pieces */ -extern int32 CES; /* console entry switches */ -extern int32 ACC, EXT; /* accumulator and extension */ -extern int32 ARF; /* arithmetic factor register, a nonaddressable internal CPU register */ -extern int32 RUNMODE; /* processor run/step mode */ -extern int32 ipl; /* current interrupt level (-1 = not handling irq) */ -extern int32 iplpending; /* interrupted IPL's */ -extern int32 tbit; /* trace flag (causes level 5 IRQ after each instr) */ -extern int32 V, C; /* condition codes */ -extern int32 wait_state; /* wait state (waiting for an IRQ) */ -extern int32 wait_lamp; /* alternate indicator to light the wait lamp on the GUI */ -extern int32 int_req; /* sum of interrupt request levels active */ -extern int32 int_lamps; /* accumulated version of int_req - gives lamp persistence */ -extern int32 int_mask; /* current active interrupt mask (ipl sensitive) */ +extern uint16 M[]; /* core memory, up to 32Kwords (note: don't even think about trying 64K) */ +extern uint16 ILSW[]; /* interrupt level status words */ +extern int32 IAR; /* instruction address register */ +extern int32 prev_IAR; /* instruction address register at start of current instruction */ +extern int32 SAR, SBR; /* storage address/buffer registers */ +extern int32 OP, TAG, CCC; /* instruction decoded pieces */ +extern int32 CES; /* console entry switches */ +extern int32 ACC, EXT; /* accumulator and extension */ +extern int32 ARF; /* arithmetic factor register, a nonaddressable internal CPU register */ +extern int32 RUNMODE; /* processor run/step mode */ +extern int32 ipl; /* current interrupt level (-1 = not handling irq) */ +extern int32 iplpending; /* interrupted IPL's */ +extern int32 tbit; /* trace flag (causes level 5 IRQ after each instr) */ +extern int32 V, C; /* condition codes */ +extern int32 wait_state; /* wait state (waiting for an IRQ) */ +extern int32 wait_lamp; /* alternate indicator to light the wait lamp on the GUI */ +extern int32 int_req; /* sum of interrupt request levels active */ +extern int32 int_lamps; /* accumulated version of int_req - gives lamp persistence */ +extern int32 int_mask; /* current active interrupt mask (ipl sensitive) */ extern int32 mem_mask; -extern int32 cpu_dsw; /* CPU device status word */ -extern int32 con_dsw; /* has program stop and int run bits */ +extern int32 cpu_dsw; /* CPU device status word */ +extern int32 con_dsw; /* has program stop and int run bits */ extern t_bool running; extern t_bool power; -extern t_bool cgi; /* TRUE if we are running as a CGI program */ -extern t_bool cgiwritable; /* TRUE if we can write to the disk image file in CGI mode */ -extern t_stat reason; /* CPU execution loop control */ +extern t_bool cgi; /* TRUE if we are running as a CGI program */ +extern t_bool cgiwritable; /* TRUE if we can write to the disk image file in CGI mode */ +extern t_stat reason; /* CPU execution loop control */ -#define WAIT_OP 1 /* wait state causes: wait instruction, invalid instruction*/ +#define WAIT_OP 1 /* wait state causes: wait instruction, invalid instruction*/ #define WAIT_INVALID_OP 2 -#define MODE_SS 3 /* RUNMODE values. SS and SMC are not implemented in this simulator */ -#define MODE_SMC 2 -#define MODE_INT_RUN 1 -#define MODE_RUN 0 -#define MODE_SI -1 -#define MODE_DISP -2 -#define MODE_LOAD -3 +#define MODE_SS 3 /* RUNMODE values. SS and SMC are not implemented in this simulator */ +#define MODE_SMC 2 +#define MODE_INT_RUN 1 +#define MODE_RUN 0 +#define MODE_SI -1 +#define MODE_DISP -2 +#define MODE_LOAD -3 /* ------------------------------------------------------------------------ */ -/* debugging */ +/* debugging */ /* ------------------------------------------------------------------------ */ #define ENABLE_DEBUG_PRINT @@ -123,162 +123,162 @@ void WriteW (int32 a, int32 d); /* ------------------------------------------------------------------------ */ /* Simulator stop codes */ -#define STOP_WAIT 1 /* wait, no events */ -#define STOP_INVALID_INSTR 2 /* bad instruction */ -#define STOP_IBKPT 3 /* simulator breakpoint */ -#define STOP_INCOMPLETE 4 /* simulator coding not complete here */ -#define STOP_POWER_OFF 5 /* no power */ -#define STOP_DECK_BREAK 6 /* !BREAK in deck file */ -#define STOP_PHASE_BREAK 7 /* phase load break */ -#define STOP_CRASH 8 /* program has crashed badly */ -#define STOP_TIMED_OUT 9 /* simulation time limit exceeded */ -#define STOP_IMMEDIATE 10 /* simulator stop key pressed (immediate stop) */ -#define STOP_BREAK 11 /* simulator break key pressed */ -#define STOP_STEP 12 /* step count expired */ -#define STOP_OTHER 13 /* other reason, probably error returned by sim_process_event() */ -#define STOP_PRINT_CHECK 14 /* stop due to printer check (used by CGI version) */ +#define STOP_WAIT 1 /* wait, no events */ +#define STOP_INVALID_INSTR 2 /* bad instruction */ +#define STOP_IBKPT 3 /* simulator breakpoint */ +#define STOP_INCOMPLETE 4 /* simulator coding not complete here */ +#define STOP_POWER_OFF 5 /* no power */ +#define STOP_DECK_BREAK 6 /* !BREAK in deck file */ +#define STOP_PHASE_BREAK 7 /* phase load break */ +#define STOP_CRASH 8 /* program has crashed badly */ +#define STOP_TIMED_OUT 9 /* simulation time limit exceeded */ +#define STOP_IMMEDIATE 10 /* simulator stop key pressed (immediate stop) */ +#define STOP_BREAK 11 /* simulator break key pressed */ +#define STOP_STEP 12 /* step count expired */ +#define STOP_OTHER 13 /* other reason, probably error returned by sim_process_event() */ +#define STOP_PRINT_CHECK 14 /* stop due to printer check (used by CGI version) */ -#define IORETURN(f,v) ((f)? (v): SCPE_OK) /* cond error return */ +#define IORETURN(f,v) ((f)? (v): SCPE_OK) /* cond error return */ -#define INT_REQ_5 0x01 /* bits for interrupt levels (ipl, iplpending, int_req, int_mask) */ -#define INT_REQ_4 0x02 -#define INT_REQ_3 0x04 -#define INT_REQ_2 0x08 -#define INT_REQ_1 0x10 -#define INT_REQ_0 0x20 +#define INT_REQ_5 0x01 /* bits for interrupt levels (ipl, iplpending, int_req, int_mask) */ +#define INT_REQ_4 0x02 +#define INT_REQ_3 0x04 +#define INT_REQ_2 0x08 +#define INT_REQ_1 0x10 +#define INT_REQ_0 0x20 -#define XIO_UNUSED 0x00 /* XIO commands */ -#define XIO_WRITE 0x01 -#define XIO_READ 0x02 -#define XIO_SENSE_IRQ 0x03 -#define XIO_CONTROL 0x04 -#define XIO_INITW 0x05 -#define XIO_INITR 0x06 -#define XIO_SENSE_DEV 0x07 +#define XIO_UNUSED 0x00 /* XIO commands */ +#define XIO_WRITE 0x01 +#define XIO_READ 0x02 +#define XIO_SENSE_IRQ 0x03 +#define XIO_CONTROL 0x04 +#define XIO_INITW 0x05 +#define XIO_INITR 0x06 +#define XIO_SENSE_DEV 0x07 -#define XIO_FAILED 0x20 /* fake function to record error */ +#define XIO_FAILED 0x20 /* fake function to record error */ /* ILSW bits - set by appropriate device whenever an interrupt is outstanding */ -#define ILSW_0_1442_CARD 0x8000 /* ILSW 0 is not really defined on the 1130 */ +#define ILSW_0_1442_CARD 0x8000 /* ILSW 0 is not really defined on the 1130 */ -#define ILSW_1_1132_PRINTER 0x8000 /* had these backwards! */ -#define ILSW_1_SCA 0x4000 +#define ILSW_1_1132_PRINTER 0x8000 /* had these backwards! */ +#define ILSW_1_SCA 0x4000 -#define ILSW_2_1131_DISK 0x8000 +#define ILSW_2_1131_DISK 0x8000 -#define ILSW_2_2310_DRV_1 0x4000 -#define ILSW_2_2310_DRV_2 0x2000 -#define ILSW_2_2310_DRV_3 0x1000 -#define ILSW_2_2310_DRV_4 0x0800 /* can have 2310 or 2311 */ +#define ILSW_2_2310_DRV_1 0x4000 +#define ILSW_2_2310_DRV_2 0x2000 +#define ILSW_2_2310_DRV_3 0x1000 +#define ILSW_2_2310_DRV_4 0x0800 /* can have 2310 or 2311 */ -#define ILSW_2_2311_DRV_1_DISK_1 0x4000 -#define ILSW_2_2311_DRV_1_DISK_2 0x2000 -#define ILSW_2_2311_DRV_1_DISK_3 0x1000 -#define ILSW_2_2311_DRV_1_DISK_4 0x0800 +#define ILSW_2_2311_DRV_1_DISK_1 0x4000 +#define ILSW_2_2311_DRV_1_DISK_2 0x2000 +#define ILSW_2_2311_DRV_1_DISK_3 0x1000 +#define ILSW_2_2311_DRV_1_DISK_4 0x0800 -#define ILSW_2_2311_DRV_1_DISK_5 0x0400 -#define ILSW_2_2311_DRV_2_DISK_1 0x0200 -#define ILSW_2_2311_DRV_2_DISK_2 0x0100 -#define ILSW_2_2311_DRV_2_DISK_3 0x0080 -#define ILSW_2_2311_DRV_2_DISK_4 0x0040 -#define ILSW_2_2311_DRV_2_DISK_5 0x0020 +#define ILSW_2_2311_DRV_1_DISK_5 0x0400 +#define ILSW_2_2311_DRV_2_DISK_1 0x0200 +#define ILSW_2_2311_DRV_2_DISK_2 0x0100 +#define ILSW_2_2311_DRV_2_DISK_3 0x0080 +#define ILSW_2_2311_DRV_2_DISK_4 0x0040 +#define ILSW_2_2311_DRV_2_DISK_5 0x0020 -#define ILSW_2_SAC_BIT_11 0x0010 -#define ILSW_2_SAC_BIT_12 0x0008 -#define ILSW_2_SAC_BIT_13 0x0004 -#define ILSW_2_SAC_BIT_14 0x0002 -#define ILSW_2_SAC_BIT_15 0x0001 +#define ILSW_2_SAC_BIT_11 0x0010 +#define ILSW_2_SAC_BIT_12 0x0008 +#define ILSW_2_SAC_BIT_13 0x0004 +#define ILSW_2_SAC_BIT_14 0x0002 +#define ILSW_2_SAC_BIT_15 0x0001 -#define ILSW_3_1627_PLOTTER 0x8000 -#define ILSW_3_SAC_BIT_01 0x4000 -#define ILSW_3_SAC_BIT_02 0x2000 -#define ILSW_3_SAC_BIT_03 0x1000 -#define ILSW_3_2250_DISPLAY 0x0800 -#define ILSW_3_SYSTEM7 0x0800 -#define ILSW_3_SAC_BIT_05 0x0400 -#define ILSW_3_SAC_BIT_06 0x0200 -#define ILSW_3_SAC_BIT_07 0x0100 -#define ILSW_3_SAC_BIT_08 0x0080 -#define ILSW_3_SAC_BIT_09 0x0040 -#define ILSW_3_SAC_BIT_10 0x0020 -#define ILSW_3_SAC_BIT_11 0x0010 -#define ILSW_3_SAC_BIT_12 0x0008 -#define ILSW_3_SAC_BIT_13 0x0004 -#define ILSW_3_SAC_BIT_14 0x0002 -#define ILSW_3_SAC_BIT_15 0x0001 +#define ILSW_3_1627_PLOTTER 0x8000 +#define ILSW_3_SAC_BIT_01 0x4000 +#define ILSW_3_SAC_BIT_02 0x2000 +#define ILSW_3_SAC_BIT_03 0x1000 +#define ILSW_3_2250_DISPLAY 0x0800 +#define ILSW_3_SYSTEM7 0x0800 +#define ILSW_3_SAC_BIT_05 0x0400 +#define ILSW_3_SAC_BIT_06 0x0200 +#define ILSW_3_SAC_BIT_07 0x0100 +#define ILSW_3_SAC_BIT_08 0x0080 +#define ILSW_3_SAC_BIT_09 0x0040 +#define ILSW_3_SAC_BIT_10 0x0020 +#define ILSW_3_SAC_BIT_11 0x0010 +#define ILSW_3_SAC_BIT_12 0x0008 +#define ILSW_3_SAC_BIT_13 0x0004 +#define ILSW_3_SAC_BIT_14 0x0002 +#define ILSW_3_SAC_BIT_15 0x0001 -#define ILSW_4_1134_TAPE 0x8000 -#define ILSW_4_1055_TAPE 0x8000 -#define ILSW_4_CONSOLE 0x4000 -#define ILSW_4_1442_CARD 0x2000 -#define ILSW_4_2501_CARD 0x1000 -#define ILSW_4_1403_PRINTER 0x0800 -#define ILSW_4_1231_MARK 0x0400 -#define ILSW_4_SAC_BIT_06 0x0200 -#define ILSW_4_SAC_BIT_07 0x0100 -#define ILSW_4_SAC_BIT_08 0x0080 -#define ILSW_4_SAC_BIT_09 0x0040 -#define ILSW_4_SAC_BIT_10 0x0020 -#define ILSW_4_SAC_BIT_11 0x0010 -#define ILSW_4_T2741_TERMINAL 0x0010 /* APL\1130 nonstandard serial interface uses this bit */ -#define ILSW_4_SAC_BIT_12 0x0008 -#define ILSW_4_SAC_BIT_13 0x0004 -#define ILSW_4_SAC_BIT_14 0x0002 -#define ILSW_4_SAC_BIT_15 0x0001 +#define ILSW_4_1134_TAPE 0x8000 +#define ILSW_4_1055_TAPE 0x8000 +#define ILSW_4_CONSOLE 0x4000 +#define ILSW_4_1442_CARD 0x2000 +#define ILSW_4_2501_CARD 0x1000 +#define ILSW_4_1403_PRINTER 0x0800 +#define ILSW_4_1231_MARK 0x0400 +#define ILSW_4_SAC_BIT_06 0x0200 +#define ILSW_4_SAC_BIT_07 0x0100 +#define ILSW_4_SAC_BIT_08 0x0080 +#define ILSW_4_SAC_BIT_09 0x0040 +#define ILSW_4_SAC_BIT_10 0x0020 +#define ILSW_4_SAC_BIT_11 0x0010 +#define ILSW_4_T2741_TERMINAL 0x0010 /* APL\1130 nonstandard serial interface uses this bit */ +#define ILSW_4_SAC_BIT_12 0x0008 +#define ILSW_4_SAC_BIT_13 0x0004 +#define ILSW_4_SAC_BIT_14 0x0002 +#define ILSW_4_SAC_BIT_15 0x0001 -#define ILSW_5_INT_RUN_PROGRAM_STOP 0x8000 /* this replaces both ILSW_5_INT_RUN and ILSW_5_PROGRAM_STOP */ -#define ILSW_5_SAC_BIT_01 0x4000 -#define ILSW_5_SAC_BIT_02 0x2000 -#define ILSW_5_SAC_BIT_03 0x1000 -#define ILSW_5_SAC_BIT_04 0x0800 -#define ILSW_5_SAC_BIT_05 0x0400 -#define ILSW_5_SAC_BIT_06 0x0200 -#define ILSW_5_SAC_BIT_07 0x0100 -#define ILSW_5_SAC_BIT_08 0x0080 -#define ILSW_5_SAC_BIT_09 0x0040 -#define ILSW_5_SAC_BIT_10 0x0020 -#define ILSW_5_SAC_BIT_11 0x0010 -#define ILSW_5_SAC_BIT_12 0x0008 -#define ILSW_5_SAC_BIT_13 0x0004 -#define ILSW_5_SAC_BIT_14 0x0002 -#define ILSW_5_SAC_BIT_15 0x0001 +#define ILSW_5_INT_RUN_PROGRAM_STOP 0x8000 /* this replaces both ILSW_5_INT_RUN and ILSW_5_PROGRAM_STOP */ +#define ILSW_5_SAC_BIT_01 0x4000 +#define ILSW_5_SAC_BIT_02 0x2000 +#define ILSW_5_SAC_BIT_03 0x1000 +#define ILSW_5_SAC_BIT_04 0x0800 +#define ILSW_5_SAC_BIT_05 0x0400 +#define ILSW_5_SAC_BIT_06 0x0200 +#define ILSW_5_SAC_BIT_07 0x0100 +#define ILSW_5_SAC_BIT_08 0x0080 +#define ILSW_5_SAC_BIT_09 0x0040 +#define ILSW_5_SAC_BIT_10 0x0020 +#define ILSW_5_SAC_BIT_11 0x0010 +#define ILSW_5_SAC_BIT_12 0x0008 +#define ILSW_5_SAC_BIT_13 0x0004 +#define ILSW_5_SAC_BIT_14 0x0002 +#define ILSW_5_SAC_BIT_15 0x0001 /* CPU DSW bits */ -#define CPU_DSW_PROGRAM_STOP 0x8000 -#define CPU_DSW_INT_RUN 0x4000 +#define CPU_DSW_PROGRAM_STOP 0x8000 +#define CPU_DSW_INT_RUN 0x4000 /* prototypes: xio handlers */ -void xio_1131_console (int32 addr, int32 func, int32 modify); /* console keyboard and printer */ -void xio_1442_card (int32 addr, int32 func, int32 modify); /* standard card reader/punch */ -void xio_1134_papertape (int32 addr, int32 func, int32 modify); /* paper tape reader/punch */ -void xio_disk (int32 addr, int32 func, int32 modify, int drv); /* internal CPU disk */ -void xio_1627_plotter (int32 addr, int32 func, int32 modify); /* XY plotter */ -void xio_1132_printer (int32 addr, int32 func, int32 modify); /* standard line printer */ -void xio_1131_switches (int32 addr, int32 func, int32 modify); /* console buttons & switches */ -void xio_1231_optical (int32 addr, int32 func, int32 modify); /* optical mark page reader */ -void xio_2501_card (int32 addr, int32 func, int32 modify); /* alternate high-speed card reader */ -void xio_sca (int32 addr, int32 func, int32 modify); /* synchronous communications adapter */ -void xio_system7 (int32 addr, int32 func, int32 modify); /* system/7 interprocessor IO link */ -void xio_1403_printer (int32 addr, int32 func, int32 modify); /* alternate high-speed printer */ -void xio_2250_display (int32 addr, int32 func, int32 modify); /* vector display processor */ -void xio_t2741_terminal (int32 addr, int32 func, int32 modify); /* IO selectric via nonstandard serial interface for APL */ -void xio_error (const char *msg); +void xio_1131_console (int32 addr, int32 func, int32 modify); /* console keyboard and printer */ +void xio_1442_card (int32 addr, int32 func, int32 modify); /* standard card reader/punch */ +void xio_1134_papertape (int32 addr, int32 func, int32 modify); /* paper tape reader/punch */ +void xio_disk (int32 addr, int32 func, int32 modify, int drv); /* internal CPU disk */ +void xio_1627_plotter (int32 addr, int32 func, int32 modify); /* XY plotter */ +void xio_1132_printer (int32 addr, int32 func, int32 modify); /* standard line printer */ +void xio_1131_switches (int32 addr, int32 func, int32 modify); /* console buttons & switches */ +void xio_1231_optical (int32 addr, int32 func, int32 modify); /* optical mark page reader */ +void xio_2501_card (int32 addr, int32 func, int32 modify); /* alternate high-speed card reader */ +void xio_sca (int32 addr, int32 func, int32 modify); /* synchronous communications adapter */ +void xio_system7 (int32 addr, int32 func, int32 modify); /* system/7 interprocessor IO link */ +void xio_1403_printer (int32 addr, int32 func, int32 modify); /* alternate high-speed printer */ +void xio_2250_display (int32 addr, int32 func, int32 modify); /* vector display processor */ +void xio_t2741_terminal (int32 addr, int32 func, int32 modify); /* IO selectric via nonstandard serial interface for APL */ +void xio_error (const char *msg); void bail (const char *msg); t_stat load_cr_boot (int32 drv, int switches); t_stat cr_boot (int32 unitno, DEVICE *dptr); t_stat cr_rewind (void); t_stat cr_detach (UNIT *uptr); -void calc_ints (void); /* recalculate interrupt bitmask */ -void trace_io (const char *fmt, ...); /* debugging printout */ -void trace_both (const char *fmt, ...); /* debugging printout */ -void scp_panic (const char *msg); /* bail out of simulator */ +void calc_ints (void); /* recalculate interrupt bitmask */ +void trace_io (const char *fmt, ...); /* debugging printout */ +void trace_both (const char *fmt, ...); /* debugging printout */ +void scp_panic (const char *msg); /* bail out of simulator */ char *upcase(char *str); -void break_simulation (t_stat reason); /* let a device halt the simulation */ -char hollerith_to_ascii (uint16 hol); /* for debugging use only */ +void break_simulation (t_stat reason); /* let a device halt the simulation */ +char hollerith_to_ascii (uint16 hol); /* for debugging use only */ t_bool gdu_active (void); void remark_cmd (char *remark); void stuff_cmd (char *cmd); @@ -291,9 +291,9 @@ CONST char * quotefix (CONST char *cptr, char * buf); /* GUI interface routines */ t_bool keyboard_is_busy (void); -void forms_check (int set); /* device notification to console lamp display */ +void forms_check (int set); /* device notification to console lamp display */ void print_check (int set); -void keyboard_selected (int select); +void keyboard_selected (int select); void disk_ready (int ready); void disk_unlocked (int unlocked); void gui_run(int running); diff --git a/Ibm1130/ibm1130_disk.c b/Ibm1130/ibm1130_disk.c index e21cf313..82f0bfb1 100644 --- a/Ibm1130/ibm1130_disk.c +++ b/Ibm1130/ibm1130_disk.c @@ -14,20 +14,20 @@ commands may NOT be accurate. This should probably be fixed. * or modifications. * * Revision History - * 05-dec-06 Added cgiwritable mode + * 05-dec-06 Added cgiwritable mode * - * 19-Dec-05 We no longer issue an operation complete interrupt if an INITR, INITW - * or CONTROL operation is attemped on a drive that is not online. DATA_ERROR - * is now only indicated in the DSW when + * 19-Dec-05 We no longer issue an operation complete interrupt if an INITR, INITW + * or CONTROL operation is attemped on a drive that is not online. DATA_ERROR + * is now only indicated in the DSW when * - * 02-Nov-04 Addes -s option to boot to leave switches alone. - * 15-jun-03 moved actual read on XIO read to end of time interval, - * as the APL boot card required 2 instructions to run between the - * time read was initiated and the time the data was read (a jump and a wait) + * 02-Nov-04 Addes -s option to boot to leave switches alone. + * 15-jun-03 moved actual read on XIO read to end of time interval, + * as the APL boot card required 2 instructions to run between the + * time read was initiated and the time the data was read (a jump and a wait) * - * 01-sep-02 corrected treatment of -m and -r flags in dsk_attach - * in cgi mode, so that file is opened readonly but emulated - * disk is writable. + * 01-sep-02 corrected treatment of -m and -r flags in dsk_attach + * in cgi mode, so that file is opened readonly but emulated + * disk is writable. * * This is not a supported product, but I welcome bug reports and fixes. * Mail to simh@ibm1130.org @@ -36,7 +36,7 @@ commands may NOT be accurate. This should probably be fixed. #include "ibm1130_defs.h" #include -#define TRACE_DMS_IO /* define to enable debug of DMS phase IO */ +#define TRACE_DMS_IO /* define to enable debug of DMS phase IO */ #ifdef TRACE_DMS_IO static int trace_dms = 0; @@ -49,40 +49,40 @@ static void enable_dms_tracing (int newsetting); /* Constants */ -#define DSK_NUMWD 321 /* words/sector */ -#define DSK_NUMSC 4 /* sectors/surface */ -#define DSK_NUMSF 2 /* surfaces/cylinder */ -#define DSK_NUMCY 203 /* cylinders/drive */ -#define DSK_NUMTR (DSK_NUMCY * DSK_NUMSF) /* tracks/drive */ -#define DSK_NUMDR 5 /* drives/controller */ +#define DSK_NUMWD 321 /* words/sector */ +#define DSK_NUMSC 4 /* sectors/surface */ +#define DSK_NUMSF 2 /* surfaces/cylinder */ +#define DSK_NUMCY 203 /* cylinders/drive */ +#define DSK_NUMTR (DSK_NUMCY * DSK_NUMSF) /* tracks/drive */ +#define DSK_NUMDR 5 /* drives/controller */ #define DSK_SIZE (DSK_NUMCY * DSK_NUMSF * DSK_NUMSC * DSK_NUMWD) /* words/drive */ -#define UNIT_V_RONLY (UNIT_V_UF + 0) /* hwre write lock */ -#define UNIT_V_OPERR (UNIT_V_UF + 1) /* operation error flag */ -#define UNIT_V_HARDERR (UNIT_V_UF + 2) /* hard error flag (reset on power down) */ -#define UNIT_RONLY (1u << UNIT_V_RONLY) -#define UNIT_OPERR (1u << UNIT_V_OPERR) +#define UNIT_V_RONLY (UNIT_V_UF + 0) /* hwre write lock */ +#define UNIT_V_OPERR (UNIT_V_UF + 1) /* operation error flag */ +#define UNIT_V_HARDERR (UNIT_V_UF + 2) /* hard error flag (reset on power down) */ +#define UNIT_RONLY (1u << UNIT_V_RONLY) +#define UNIT_OPERR (1u << UNIT_V_OPERR) #define UNIT_HARDERR (1u << UNIT_V_HARDERR) -#define MEM_MAPPED(uptr) (uptr->flags & UNIT_BUF) /* disk buffered in memory */ +#define MEM_MAPPED(uptr) (uptr->flags & UNIT_BUF) /* disk buffered in memory */ -#define IO_NONE 0 /* last operation, used to ensure fseek between read and write */ -#define IO_READ 1 -#define IO_WRITE 2 +#define IO_NONE 0 /* last operation, used to ensure fseek between read and write */ +#define IO_READ 1 +#define IO_WRITE 2 -#define DSK_DSW_DATA_ERROR 0x8000 /* device status word bits */ -#define DSK_DSW_OP_COMPLETE 0x4000 -#define DSK_DSW_NOT_READY 0x2000 -#define DSK_DSW_DISK_BUSY 0x1000 -#define DSK_DSW_CARRIAGE_HOME 0x0800 -#define DSK_DSW_SECTOR_MASK 0x0003 +#define DSK_DSW_DATA_ERROR 0x8000 /* device status word bits */ +#define DSK_DSW_OP_COMPLETE 0x4000 +#define DSK_DSW_NOT_READY 0x2000 +#define DSK_DSW_DISK_BUSY 0x1000 +#define DSK_DSW_CARRIAGE_HOME 0x0800 +#define DSK_DSW_SECTOR_MASK 0x0003 - /* device status words */ + /* device status words */ static int16 dsk_dsw[DSK_NUMDR] = {DSK_DSW_NOT_READY, DSK_DSW_NOT_READY, DSK_DSW_NOT_READY, DSK_DSW_NOT_READY, DSK_DSW_NOT_READY}; -static int16 dsk_sec[DSK_NUMDR] = {0}; /* next-sector-up */ -static char dsk_lastio[DSK_NUMDR]; /* last stdio operation: IO_READ or IO_WRITE */ -int32 dsk_swait = 50; /* seek time -- see how short a delay we can get away with */ -int32 dsk_rwait = 50; /* rotate time */ +static int16 dsk_sec[DSK_NUMDR] = {0}; /* next-sector-up */ +static char dsk_lastio[DSK_NUMDR]; /* last stdio operation: IO_READ or IO_WRITE */ +int32 dsk_swait = 50; /* seek time -- see how short a delay we can get away with */ +int32 dsk_rwait = 50; /* rotate time */ static t_bool raw_disk_debug = FALSE; static t_stat dsk_svc (UNIT *uptr); @@ -95,68 +95,68 @@ static void diskfail (UNIT *uptr, int dswflag, int unitflag, t_bool do_interrupt /* DSK data structures - dsk_dev disk device descriptor - dsk_unit unit descriptor - dsk_reg register list + dsk_dev disk device descriptor + dsk_unit unit descriptor + dsk_reg register list */ UNIT dsk_unit[] = { - { UDATA (&dsk_svc, UNIT_FIX+UNIT_ATTABLE+UNIT_DISABLE, DSK_SIZE) }, - { UDATA (&dsk_svc, UNIT_FIX+UNIT_ATTABLE+UNIT_DISABLE, DSK_SIZE) }, - { UDATA (&dsk_svc, UNIT_FIX+UNIT_ATTABLE+UNIT_DISABLE, DSK_SIZE) }, - { UDATA (&dsk_svc, UNIT_FIX+UNIT_ATTABLE+UNIT_DISABLE, DSK_SIZE) }, - { UDATA (&dsk_svc, UNIT_FIX+UNIT_ATTABLE+UNIT_DISABLE, DSK_SIZE) } + { UDATA (&dsk_svc, UNIT_FIX+UNIT_ATTABLE+UNIT_DISABLE, DSK_SIZE) }, + { UDATA (&dsk_svc, UNIT_FIX+UNIT_ATTABLE+UNIT_DISABLE, DSK_SIZE) }, + { UDATA (&dsk_svc, UNIT_FIX+UNIT_ATTABLE+UNIT_DISABLE, DSK_SIZE) }, + { UDATA (&dsk_svc, UNIT_FIX+UNIT_ATTABLE+UNIT_DISABLE, DSK_SIZE) }, + { UDATA (&dsk_svc, UNIT_FIX+UNIT_ATTABLE+UNIT_DISABLE, DSK_SIZE) } }; #define IS_ONLINE(u) (((u)->flags & (UNIT_ATT|UNIT_DIS)) == UNIT_ATT) /* Parameters in the unit descriptor */ -#define CYL u3 /* current cylinder */ -#define FUNC u4 /* current function */ +#define CYL u3 /* current cylinder */ +#define FUNC u4 /* current function */ REG dsk_reg[] = { - { HRDATA (DSKDSW0, dsk_dsw[0], 16) }, - { HRDATA (DSKDSW1, dsk_dsw[1], 16) }, - { HRDATA (DSKDSW2, dsk_dsw[2], 16) }, - { HRDATA (DSKDSW3, dsk_dsw[3], 16) }, - { HRDATA (DSKDSW4, dsk_dsw[4], 16) }, - { DRDATA (STIME, dsk_swait, 24), PV_LEFT }, - { DRDATA (RTIME, dsk_rwait, 24), PV_LEFT }, - { NULL } }; + { HRDATA (DSKDSW0, dsk_dsw[0], 16) }, + { HRDATA (DSKDSW1, dsk_dsw[1], 16) }, + { HRDATA (DSKDSW2, dsk_dsw[2], 16) }, + { HRDATA (DSKDSW3, dsk_dsw[3], 16) }, + { HRDATA (DSKDSW4, dsk_dsw[4], 16) }, + { DRDATA (STIME, dsk_swait, 24), PV_LEFT }, + { DRDATA (RTIME, dsk_rwait, 24), PV_LEFT }, + { NULL } }; MTAB dsk_mod[] = { - { UNIT_RONLY, 0, "write enabled", "ENABLED", NULL }, - { UNIT_RONLY, UNIT_RONLY, "write locked", "LOCKED", NULL }, - { 0 } }; + { UNIT_RONLY, 0, "write enabled", "ENABLED", NULL }, + { UNIT_RONLY, UNIT_RONLY, "write locked", "LOCKED", NULL }, + { 0 } }; DEVICE dsk_dev = { - "DSK", dsk_unit, dsk_reg, dsk_mod, - DSK_NUMDR, 16, 16, 1, 16, 16, - NULL, NULL, &dsk_reset, - dsk_boot, dsk_attach, dsk_detach}; + "DSK", dsk_unit, dsk_reg, dsk_mod, + DSK_NUMDR, 16, 16, 1, 16, 16, + NULL, NULL, &dsk_reset, + dsk_boot, dsk_attach, dsk_detach}; -static int32 dsk_ilswbit[DSK_NUMDR] = { /* interrupt level status word bits for the drives */ - ILSW_2_1131_DISK, - ILSW_2_2310_DRV_1, - ILSW_2_2310_DRV_2, - ILSW_2_2310_DRV_3, - ILSW_2_2310_DRV_4, +static int32 dsk_ilswbit[DSK_NUMDR] = { /* interrupt level status word bits for the drives */ + ILSW_2_1131_DISK, + ILSW_2_2310_DRV_1, + ILSW_2_2310_DRV_2, + ILSW_2_2310_DRV_3, + ILSW_2_2310_DRV_4, }; static int32 dsk_ilswlevel[DSK_NUMDR] = { - 2, /* interrupt levels for the drives */ - 2, 2, 2, 2 + 2, /* interrupt levels for the drives */ + 2, 2, 2, 2 }; typedef enum {DSK_FUNC_IDLE, DSK_FUNC_READ, DSK_FUNC_VERIFY, DSK_FUNC_WRITE, DSK_FUNC_SEEK, DSK_FUNC_FAILED} DSK_FUNC; -static struct tag_dsk_action { /* stores data needed for pending IO activity */ - int32 io_address; - uint32 io_filepos; - int io_nwords; - int io_sector; +static struct tag_dsk_action { /* stores data needed for pending IO activity */ + int32 io_address; + uint32 io_filepos; + int io_nwords; + int io_sector; } dsk_action[DSK_NUMDR]; /* xio_disk - XIO command interpreter for the disk drives */ @@ -164,17 +164,17 @@ static struct tag_dsk_action { /* stores data needed for pending IO activity * device status word: * * 0 data error, occurs when: - * 1. A modulo 4 error is detected during a read, read-check, or write operation. - * 2. The disk storage is in a read or write mode at the leading edge of a sector pulse. - * 3. A seek-incomplete signal is received from the 2311. - * 4. A write select error has occurred in the disk storage drive. - * 5. The power unsafe latch is set in the attachment. - * Conditions 1, 2, and 3 are turned off by a sense device command with modifier bit 15 - * set to 1. Conditions 4 and 5 are turned off by powering the drive off and back on. + * 1. A modulo 4 error is detected during a read, read-check, or write operation. + * 2. The disk storage is in a read or write mode at the leading edge of a sector pulse. + * 3. A seek-incomplete signal is received from the 2311. + * 4. A write select error has occurred in the disk storage drive. + * 5. The power unsafe latch is set in the attachment. + * Conditions 1, 2, and 3 are turned off by a sense device command with modifier bit 15 + * set to 1. Conditions 4 and 5 are turned off by powering the drive off and back on. * 1 operation complete * 2 not ready, occurs when disk not ready or busy or disabled or off-line or - * power unsafe latch set. Also included in the disk not ready is the write select error, - * which can be a result of power unsafe or write select. + * power unsafe latch set. Also included in the disk not ready is the write select error, + * which can be a result of power unsafe or write select. * 3 disk busy * 4 carriage home (on cyl 0) * 15-16: number of next sector spinning into position. @@ -184,407 +184,407 @@ extern void void_backtrace (int afrom, int ato); void xio_disk (int32 iocc_addr, int32 func, int32 modify, int drv) { - int i, rev, nsteps, newcyl, sec, nwords; - uint32 newpos; /* changed from t_addr to uint32 in anticipation of simh 64-bit development */ - char msg[80]; - UNIT *uptr = dsk_unit+drv; - int16 buf[DSK_NUMWD]; + int i, rev, nsteps, newcyl, sec, nwords; + uint32 newpos; /* changed from t_addr to uint32 in anticipation of simh 64-bit development */ + char msg[80]; + UNIT *uptr = dsk_unit+drv; + int16 buf[DSK_NUMWD]; - if (! BETWEEN(drv, 0, DSK_NUMDR-1)) { /* hmmm, invalid drive */ - if (func != XIO_SENSE_DEV) { /* tried to use it, too */ - /* just do nothing, as if the controller isn't there. NAMCRA at N0116300 tests for drives by attempting reads - sprintf(msg, "Op %x on invalid drive number %d", func, drv); - xio_error(msg); - */ - } - return; - } + if (! BETWEEN(drv, 0, DSK_NUMDR-1)) { /* hmmm, invalid drive */ + if (func != XIO_SENSE_DEV) { /* tried to use it, too */ + /* just do nothing, as if the controller isn't there. NAMCRA at N0116300 tests for drives by attempting reads + sprintf(msg, "Op %x on invalid drive number %d", func, drv); + xio_error(msg); + */ + } + return; + } - CLRBIT(uptr->flags, UNIT_OPERR); /* clear pending error flag from previous op, if any */ + CLRBIT(uptr->flags, UNIT_OPERR); /* clear pending error flag from previous op, if any */ - switch (func) { - case XIO_INITR: - if (! IS_ONLINE(uptr)) { /* disk is offline */ - diskfail(uptr, 0, 0, FALSE); - break; - } + switch (func) { + case XIO_INITR: + if (! IS_ONLINE(uptr)) { /* disk is offline */ + diskfail(uptr, 0, 0, FALSE); + break; + } - sim_cancel(uptr); /* cancel any pending ops */ - dsk_dsw[drv] |= DSK_DSW_DISK_BUSY; /* and mark the disk as busy */ + sim_cancel(uptr); /* cancel any pending ops */ + dsk_dsw[drv] |= DSK_DSW_DISK_BUSY; /* and mark the disk as busy */ - nwords = M[iocc_addr++ & mem_mask]; /* get word count w/o upsetting SAR/SBR */ + nwords = M[iocc_addr++ & mem_mask]; /* get word count w/o upsetting SAR/SBR */ - if (nwords == 0) /* this is bad -- on real 1130, this locks up disk controller ! */ - break; + if (nwords == 0) /* this is bad -- on real 1130, this locks up disk controller ! */ + break; - if (! BETWEEN(nwords, 1, DSK_NUMWD)) { /* count bad */ - SETBIT(uptr->flags, UNIT_OPERR); /* set data error DSW bit when op complete */ - nwords = DSK_NUMWD; /* limit xfer to proper sector size */ - } + if (! BETWEEN(nwords, 1, DSK_NUMWD)) { /* count bad */ + SETBIT(uptr->flags, UNIT_OPERR); /* set data error DSW bit when op complete */ + nwords = DSK_NUMWD; /* limit xfer to proper sector size */ + } - sec = modify & 0x07; /* get sector on cylinder */ + sec = modify & 0x07; /* get sector on cylinder */ - if ((modify & 0x0080) == 0) { /* it's a real read if it's not a read check */ - /* ah. We have a problem. The APL boot card counts on there being time for at least one - * more instruction to execute between the XIO read and the time the data starts loading - * into core. So, we have to defer the actual read operation a bit. Might as well wait - * until it's time to issue the operation complete interrupt. This means saving the - * IO information, then performing the actual read in dsk_svc. - */ + if ((modify & 0x0080) == 0) { /* it's a real read if it's not a read check */ + /* ah. We have a problem. The APL boot card counts on there being time for at least one + * more instruction to execute between the XIO read and the time the data starts loading + * into core. So, we have to defer the actual read operation a bit. Might as well wait + * until it's time to issue the operation complete interrupt. This means saving the + * IO information, then performing the actual read in dsk_svc. + */ - newpos = (uptr->CYL*DSK_NUMSC*DSK_NUMSF + sec)*2*DSK_NUMWD; + newpos = (uptr->CYL*DSK_NUMSC*DSK_NUMSF + sec)*2*DSK_NUMWD; - dsk_action[drv].io_address = iocc_addr; - dsk_action[drv].io_nwords = nwords; - dsk_action[drv].io_sector = sec; - dsk_action[drv].io_filepos = newpos; + dsk_action[drv].io_address = iocc_addr; + dsk_action[drv].io_nwords = nwords; + dsk_action[drv].io_sector = sec; + dsk_action[drv].io_filepos = newpos; - uptr->FUNC = DSK_FUNC_READ; - } - else { - trace_io("* DSK%d verify %d.%d (%x)", drv, uptr->CYL, sec, uptr->CYL*8 + sec); + uptr->FUNC = DSK_FUNC_READ; + } + else { + trace_io("* DSK%d verify %d.%d (%x)", drv, uptr->CYL, sec, uptr->CYL*8 + sec); - if (raw_disk_debug) - printf("* DSK%d verify %d.%d (%x)", drv, uptr->CYL, sec, uptr->CYL*8 + sec); + if (raw_disk_debug) + printf("* DSK%d verify %d.%d (%x)", drv, uptr->CYL, sec, uptr->CYL*8 + sec); - uptr->FUNC = DSK_FUNC_VERIFY; - } + uptr->FUNC = DSK_FUNC_VERIFY; + } - sim_activate(uptr, dsk_rwait); - break; + sim_activate(uptr, dsk_rwait); + break; - case XIO_INITW: - if (! IS_ONLINE(uptr)) { /* disk is offline */ - diskfail(uptr, 0, 0, FALSE); - break; - } + case XIO_INITW: + if (! IS_ONLINE(uptr)) { /* disk is offline */ + diskfail(uptr, 0, 0, FALSE); + break; + } - if (uptr->flags & UNIT_RONLY) { /* oops, write to RO disk? permanent error until disk is powered off/on */ - diskfail(uptr, DSK_DSW_DATA_ERROR, UNIT_HARDERR, FALSE); - break; - } + if (uptr->flags & UNIT_RONLY) { /* oops, write to RO disk? permanent error until disk is powered off/on */ + diskfail(uptr, DSK_DSW_DATA_ERROR, UNIT_HARDERR, FALSE); + break; + } - sim_cancel(uptr); /* cancel any pending ops */ - dsk_dsw[drv] |= DSK_DSW_DISK_BUSY; /* and mark drive as busy */ + sim_cancel(uptr); /* cancel any pending ops */ + dsk_dsw[drv] |= DSK_DSW_DISK_BUSY; /* and mark drive as busy */ - nwords = M[iocc_addr++ & mem_mask]; /* get word count w/o upsetting SAR/SBR */ + nwords = M[iocc_addr++ & mem_mask]; /* get word count w/o upsetting SAR/SBR */ - if (nwords == 0) /* this is bad -- locks up disk controller ! */ - break; + if (nwords == 0) /* this is bad -- locks up disk controller ! */ + break; - if (! BETWEEN(nwords, 1, DSK_NUMWD)) { /* count bad */ - SETBIT(uptr->flags, UNIT_OPERR); /* set data error DSW bit when op complete */ - nwords = DSK_NUMWD; /* limit xfer to proper sector size */ - } + if (! BETWEEN(nwords, 1, DSK_NUMWD)) { /* count bad */ + SETBIT(uptr->flags, UNIT_OPERR); /* set data error DSW bit when op complete */ + nwords = DSK_NUMWD; /* limit xfer to proper sector size */ + } - sec = modify & 0x07; /* get sector on cylinder */ - newpos = (uptr->CYL*DSK_NUMSC*DSK_NUMSF + sec)*2*DSK_NUMWD; + sec = modify & 0x07; /* get sector on cylinder */ + newpos = (uptr->CYL*DSK_NUMSC*DSK_NUMSF + sec)*2*DSK_NUMWD; - trace_io("* DSK%d wrote %d words from M[%04x-%04x] to %d.%d (%x, %x)", drv, nwords, iocc_addr & mem_mask, (iocc_addr + nwords - 1) & mem_mask, uptr->CYL, sec, uptr->CYL*8 + sec, newpos); + trace_io("* DSK%d wrote %d words from M[%04x-%04x] to %d.%d (%x, %x)", drv, nwords, iocc_addr & mem_mask, (iocc_addr + nwords - 1) & mem_mask, uptr->CYL, sec, uptr->CYL*8 + sec, newpos); - if (raw_disk_debug) - printf("* DSK%d XIO @ %04x wrote %d words from M[%04x-%04x] to %d.%d (%x, %x)\n", drv, prev_IAR, nwords, iocc_addr & mem_mask, (iocc_addr + nwords - 1) & mem_mask, uptr->CYL, sec, uptr->CYL*8 + sec, newpos); + if (raw_disk_debug) + printf("* DSK%d XIO @ %04x wrote %d words from M[%04x-%04x] to %d.%d (%x, %x)\n", drv, prev_IAR, nwords, iocc_addr & mem_mask, (iocc_addr + nwords - 1) & mem_mask, uptr->CYL, sec, uptr->CYL*8 + sec, newpos); #ifdef TRACE_DMS_IO - if (trace_dms) - tracesector(1, nwords, iocc_addr & mem_mask, uptr->CYL*8 + sec); + if (trace_dms) + tracesector(1, nwords, iocc_addr & mem_mask, uptr->CYL*8 + sec); #endif - for (i = 0; i < nwords; i++) - buf[i] = M[iocc_addr++ & mem_mask]; + for (i = 0; i < nwords; i++) + buf[i] = M[iocc_addr++ & mem_mask]; - for (; i < DSK_NUMWD; i++) /* rest of sector gets zeroed */ - buf[i] = 0; + for (; i < DSK_NUMWD; i++) /* rest of sector gets zeroed */ + buf[i] = 0; - i = uptr->CYL*8 + sec; - if (buf[0] != i) - printf("*DSK writing bad sector#\n"); + i = uptr->CYL*8 + sec; + if (buf[0] != i) + printf("*DSK writing bad sector#\n"); - if (MEM_MAPPED(uptr)) { - memcpy((char *) uptr->filebuf + newpos, buf, 2*DSK_NUMWD); - uptr->hwmark = newpos + 2*DSK_NUMWD; - } - else { - if (uptr->pos != newpos || dsk_lastio[drv] != IO_WRITE) { - fseek(uptr->fileref, newpos, SEEK_SET); - dsk_lastio[drv] = IO_WRITE; - } - - fxwrite(buf, 2, DSK_NUMWD, uptr->fileref); - uptr->pos = newpos + 2*DSK_NUMWD; - } + if (MEM_MAPPED(uptr)) { + memcpy((char *) uptr->filebuf + newpos, buf, 2*DSK_NUMWD); + uptr->hwmark = newpos + 2*DSK_NUMWD; + } + else { + if (uptr->pos != newpos || dsk_lastio[drv] != IO_WRITE) { + fseek(uptr->fileref, newpos, SEEK_SET); + dsk_lastio[drv] = IO_WRITE; + } + + fxwrite(buf, 2, DSK_NUMWD, uptr->fileref); + uptr->pos = newpos + 2*DSK_NUMWD; + } - uptr->FUNC = DSK_FUNC_WRITE; - sim_activate(uptr, dsk_rwait); - break; + uptr->FUNC = DSK_FUNC_WRITE; + sim_activate(uptr, dsk_rwait); + break; - case XIO_CONTROL: /* step fwd/rev */ - if (! IS_ONLINE(uptr)) { - diskfail(uptr, 0, 0, FALSE); - break; - } + case XIO_CONTROL: /* step fwd/rev */ + if (! IS_ONLINE(uptr)) { + diskfail(uptr, 0, 0, FALSE); + break; + } - sim_cancel(uptr); + sim_cancel(uptr); - rev = modify & 4; - nsteps = iocc_addr & 0x00FF; - if (nsteps == 0) /* 0 steps does not cause op complete interrupt */ - break; + rev = modify & 4; + nsteps = iocc_addr & 0x00FF; + if (nsteps == 0) /* 0 steps does not cause op complete interrupt */ + break; - newcyl = uptr->CYL + (rev ? (-nsteps) : nsteps); - if (newcyl < 0) - newcyl = 0; - else if (newcyl >= DSK_NUMCY) - newcyl = DSK_NUMCY-1; + newcyl = uptr->CYL + (rev ? (-nsteps) : nsteps); + if (newcyl < 0) + newcyl = 0; + else if (newcyl >= DSK_NUMCY) + newcyl = DSK_NUMCY-1; - uptr->FUNC = DSK_FUNC_SEEK; - uptr->CYL = newcyl; - sim_activate(uptr, dsk_swait); /* schedule interrupt */ + uptr->FUNC = DSK_FUNC_SEEK; + uptr->CYL = newcyl; + sim_activate(uptr, dsk_swait); /* schedule interrupt */ - dsk_dsw[drv] |= DSK_DSW_DISK_BUSY; - trace_io("* DSK%d at cyl %d", drv, newcyl); - break; + dsk_dsw[drv] |= DSK_DSW_DISK_BUSY; + trace_io("* DSK%d at cyl %d", drv, newcyl); + break; - case XIO_SENSE_DEV: - CLRBIT(dsk_dsw[drv], DSK_DSW_CARRIAGE_HOME|DSK_DSW_NOT_READY); + case XIO_SENSE_DEV: + CLRBIT(dsk_dsw[drv], DSK_DSW_CARRIAGE_HOME|DSK_DSW_NOT_READY); - if ((uptr->flags & UNIT_HARDERR) || (dsk_dsw[drv] & DSK_DSW_DISK_BUSY) || ! IS_ONLINE(uptr)) - SETBIT(dsk_dsw[drv], DSK_DSW_NOT_READY); - else if (uptr->CYL <= 0) { - SETBIT(dsk_dsw[drv], DSK_DSW_CARRIAGE_HOME); - uptr->CYL = 0; - } + if ((uptr->flags & UNIT_HARDERR) || (dsk_dsw[drv] & DSK_DSW_DISK_BUSY) || ! IS_ONLINE(uptr)) + SETBIT(dsk_dsw[drv], DSK_DSW_NOT_READY); + else if (uptr->CYL <= 0) { + SETBIT(dsk_dsw[drv], DSK_DSW_CARRIAGE_HOME); + uptr->CYL = 0; + } - dsk_sec[drv] = (int16) ((dsk_sec[drv] + 1) % 4); /* advance the "next sector" count every time */ - ACC = dsk_dsw[drv] | dsk_sec[drv]; + dsk_sec[drv] = (int16) ((dsk_sec[drv] + 1) % 4); /* advance the "next sector" count every time */ + ACC = dsk_dsw[drv] | dsk_sec[drv]; - if (modify & 0x01) { /* reset interrupts */ - CLRBIT(dsk_dsw[drv], DSK_DSW_OP_COMPLETE|DSK_DSW_DATA_ERROR); - CLRBIT(ILSW[dsk_ilswlevel[drv]], dsk_ilswbit[drv]); - } - break; + if (modify & 0x01) { /* reset interrupts */ + CLRBIT(dsk_dsw[drv], DSK_DSW_OP_COMPLETE|DSK_DSW_DATA_ERROR); + CLRBIT(ILSW[dsk_ilswlevel[drv]], dsk_ilswbit[drv]); + } + break; - default: - sprintf(msg, "Invalid disk XIO function %x", func); - xio_error(msg); - } + default: + sprintf(msg, "Invalid disk XIO function %x", func); + xio_error(msg); + } } /* diskfail - schedule an operation complete that sets the error bit */ static void diskfail (UNIT *uptr, int dswflag, int unitflag, t_bool do_interrupt) { - int drv = uptr - dsk_unit; + int drv = uptr - dsk_unit; - sim_cancel(uptr); /* cancel any pending ops */ - SETBIT(dsk_dsw[drv], dswflag); /* set any specified DSW bits */ - SETBIT(uptr->flags, unitflag); /* set any specified unit flag bits */ - uptr->FUNC = DSK_FUNC_FAILED; /* tell svc routine why it failed */ + sim_cancel(uptr); /* cancel any pending ops */ + SETBIT(dsk_dsw[drv], dswflag); /* set any specified DSW bits */ + SETBIT(uptr->flags, unitflag); /* set any specified unit flag bits */ + uptr->FUNC = DSK_FUNC_FAILED; /* tell svc routine why it failed */ - if (do_interrupt) - sim_activate(uptr, 1); /* schedule an immediate op complete interrupt */ + if (do_interrupt) + sim_activate(uptr, 1); /* schedule an immediate op complete interrupt */ } static t_stat dsk_svc (UNIT *uptr) { - int drv = uptr - dsk_unit, i, nwords, sec; - int16 buf[DSK_NUMWD]; - uint32 newpos; /* changed from t_addr to uint32 in anticipation of simh 64-bit development */ - int32 iocc_addr; - - if (uptr->FUNC == DSK_FUNC_IDLE) /* service function called with no activity? not good, but ignore */ - return SCPE_OK; + int drv = uptr - dsk_unit, i, nwords, sec; + int16 buf[DSK_NUMWD]; + uint32 newpos; /* changed from t_addr to uint32 in anticipation of simh 64-bit development */ + int32 iocc_addr; + + if (uptr->FUNC == DSK_FUNC_IDLE) /* service function called with no activity? not good, but ignore */ + return SCPE_OK; - CLRBIT(dsk_dsw[drv], DSK_DSW_DISK_BUSY); /* activate operation complete interrupt */ - SETBIT(dsk_dsw[drv], DSK_DSW_OP_COMPLETE); + CLRBIT(dsk_dsw[drv], DSK_DSW_DISK_BUSY); /* activate operation complete interrupt */ + SETBIT(dsk_dsw[drv], DSK_DSW_OP_COMPLETE); - if (uptr->flags & (UNIT_OPERR|UNIT_HARDERR)) { /* word count error or data error */ - SETBIT(dsk_dsw[drv], DSK_DSW_DATA_ERROR); - CLRBIT(uptr->flags, UNIT_OPERR); /* soft error is one time occurrence; don't clear hard error */ - } - /* schedule interrupt */ - SETBIT(ILSW[dsk_ilswlevel[drv]], dsk_ilswbit[drv]); + if (uptr->flags & (UNIT_OPERR|UNIT_HARDERR)) { /* word count error or data error */ + SETBIT(dsk_dsw[drv], DSK_DSW_DATA_ERROR); + CLRBIT(uptr->flags, UNIT_OPERR); /* soft error is one time occurrence; don't clear hard error */ + } + /* schedule interrupt */ + SETBIT(ILSW[dsk_ilswlevel[drv]], dsk_ilswbit[drv]); - switch (uptr->FUNC) { /* take care of business */ - case DSK_FUNC_IDLE: - case DSK_FUNC_VERIFY: - case DSK_FUNC_WRITE: - case DSK_FUNC_SEEK: - case DSK_FUNC_FAILED: - break; + switch (uptr->FUNC) { /* take care of business */ + case DSK_FUNC_IDLE: + case DSK_FUNC_VERIFY: + case DSK_FUNC_WRITE: + case DSK_FUNC_SEEK: + case DSK_FUNC_FAILED: + break; - case DSK_FUNC_READ: /* actually read the data into core */ - iocc_addr = dsk_action[drv].io_address; /* recover saved parameters */ - nwords = dsk_action[drv].io_nwords; - newpos = dsk_action[drv].io_filepos; - sec = dsk_action[drv].io_sector; + case DSK_FUNC_READ: /* actually read the data into core */ + iocc_addr = dsk_action[drv].io_address; /* recover saved parameters */ + nwords = dsk_action[drv].io_nwords; + newpos = dsk_action[drv].io_filepos; + sec = dsk_action[drv].io_sector; - if (MEM_MAPPED(uptr)) { - memcpy(buf, (char *) uptr->filebuf + newpos, 2*DSK_NUMWD); - } - else { - if (uptr->pos != newpos || dsk_lastio[drv] != IO_READ) { - fseek(uptr->fileref, newpos, SEEK_SET); - dsk_lastio[drv] = IO_READ; - uptr->pos = newpos; - } - fxread(buf, 2, DSK_NUMWD, uptr->fileref); /* read whole sector so we're in position for next read */ - uptr->pos = newpos + 2*DSK_NUMWD; - } + if (MEM_MAPPED(uptr)) { + memcpy(buf, (char *) uptr->filebuf + newpos, 2*DSK_NUMWD); + } + else { + if (uptr->pos != newpos || dsk_lastio[drv] != IO_READ) { + fseek(uptr->fileref, newpos, SEEK_SET); + dsk_lastio[drv] = IO_READ; + uptr->pos = newpos; + } + fxread(buf, 2, DSK_NUMWD, uptr->fileref); /* read whole sector so we're in position for next read */ + uptr->pos = newpos + 2*DSK_NUMWD; + } - void_backtrace(iocc_addr, iocc_addr + nwords - 1); /* mark prev instruction as altered */ + void_backtrace(iocc_addr, iocc_addr + nwords - 1); /* mark prev instruction as altered */ - trace_io("* DSK%d read %d words from %d.%d (%x, %x) to M[%04x-%04x]", drv, nwords, uptr->CYL, sec, uptr->CYL*8 + sec, newpos, iocc_addr & mem_mask, - (iocc_addr + nwords - 1) & mem_mask); + trace_io("* DSK%d read %d words from %d.%d (%x, %x) to M[%04x-%04x]", drv, nwords, uptr->CYL, sec, uptr->CYL*8 + sec, newpos, iocc_addr & mem_mask, + (iocc_addr + nwords - 1) & mem_mask); - /* this will help debug the monitor by letting me watch phase loading */ - if (raw_disk_debug) - printf("* DSK%d XIO @ %04x read %d words from %d.%d (%x, %x) to M[%04x-%04x]\n", drv, prev_IAR, nwords, uptr->CYL, sec, uptr->CYL*8 + sec, newpos, iocc_addr & mem_mask, - (iocc_addr + nwords - 1) & mem_mask); + /* this will help debug the monitor by letting me watch phase loading */ + if (raw_disk_debug) + printf("* DSK%d XIO @ %04x read %d words from %d.%d (%x, %x) to M[%04x-%04x]\n", drv, prev_IAR, nwords, uptr->CYL, sec, uptr->CYL*8 + sec, newpos, iocc_addr & mem_mask, + (iocc_addr + nwords - 1) & mem_mask); - i = uptr->CYL*8 + sec; - if (buf[0] != i) - printf("*DSK read bad sector #\n"); + i = uptr->CYL*8 + sec; + if (buf[0] != i) + printf("*DSK read bad sector #\n"); - for (i = 0; i < nwords; i++) - M[(iocc_addr+i) & mem_mask] = buf[i]; + for (i = 0; i < nwords; i++) + M[(iocc_addr+i) & mem_mask] = buf[i]; #ifdef TRACE_DMS_IO - if (trace_dms) - tracesector(0, nwords, iocc_addr & mem_mask, uptr->CYL*8 + sec); + if (trace_dms) + tracesector(0, nwords, iocc_addr & mem_mask, uptr->CYL*8 + sec); #endif - break; - - default: - fprintf(stderr, "Unexpected FUNC %x in dsk_svc(%d)\n", uptr->FUNC, drv); - break; - - } + break; + + default: + fprintf(stderr, "Unexpected FUNC %x in dsk_svc(%d)\n", uptr->FUNC, drv); + break; + + } - uptr->FUNC = DSK_FUNC_IDLE; /* we're done with this operation */ + uptr->FUNC = DSK_FUNC_IDLE; /* we're done with this operation */ - return SCPE_OK; + return SCPE_OK; } static t_stat dsk_reset (DEVICE *dptr) { - int drv; - UNIT *uptr; + int drv; + UNIT *uptr; #ifdef TRACE_DMS_IO - /* add the WHERE command. It finds the phase that was loaded at given address and indicates */ - /* the offset in the phase */ - register_cmd("WHERE", &where_cmd, 0, "w{here} address find phase and offset of an address\n"); - register_cmd("PHDEBUG", &phdebug_cmd, 0, "ph{debug} off|phlo phhi break on phase load\n"); - register_cmd("FDUMP", &fdump_cmd, 0, NULL); + /* add the WHERE command. It finds the phase that was loaded at given address and indicates */ + /* the offset in the phase */ + register_cmd("WHERE", &where_cmd, 0, "w{here} address find phase and offset of an address\n"); + register_cmd("PHDEBUG", &phdebug_cmd, 0, "ph{debug} off|phlo phhi break on phase load\n"); + register_cmd("FDUMP", &fdump_cmd, 0, NULL); #endif - for (drv = 0, uptr = dsk_dev.units; drv < DSK_NUMDR; drv++, uptr++) { - sim_cancel(uptr); + for (drv = 0, uptr = dsk_dev.units; drv < DSK_NUMDR; drv++, uptr++) { + sim_cancel(uptr); - CLRBIT(ILSW[2], dsk_ilswbit[drv]); - CLRBIT(uptr->flags, UNIT_OPERR|UNIT_HARDERR); + CLRBIT(ILSW[2], dsk_ilswbit[drv]); + CLRBIT(uptr->flags, UNIT_OPERR|UNIT_HARDERR); - uptr->CYL = 0; - uptr->FUNC = DSK_FUNC_IDLE; - dsk_dsw[drv] = (int16) ((uptr->flags & UNIT_ATT) ? DSK_DSW_CARRIAGE_HOME : 0); - } + uptr->CYL = 0; + uptr->FUNC = DSK_FUNC_IDLE; + dsk_dsw[drv] = (int16) ((uptr->flags & UNIT_ATT) ? DSK_DSW_CARRIAGE_HOME : 0); + } - calc_ints(); + calc_ints(); - return SCPE_OK; + return SCPE_OK; } static t_stat dsk_attach (UNIT *uptr, CONST char *cptr) { - int drv = uptr - dsk_unit; - t_stat rval; + int drv = uptr - dsk_unit; + t_stat rval; char gbuf[2*CBUFSIZE]; - sim_cancel(uptr); /* cancel current IO */ - dsk_lastio[drv] = IO_NONE; + sim_cancel(uptr); /* cancel current IO */ + dsk_lastio[drv] = IO_NONE; - if (uptr->flags & UNIT_ATT) /* dismount current disk */ - if ((rval = dsk_detach(uptr)) != SCPE_OK) - return rval; + if (uptr->flags & UNIT_ATT) /* dismount current disk */ + if ((rval = dsk_detach(uptr)) != SCPE_OK) + return rval; - uptr->CYL = 0; /* reset the device */ - uptr->FUNC = DSK_FUNC_IDLE; - dsk_dsw[drv] = DSK_DSW_CARRIAGE_HOME; + uptr->CYL = 0; /* reset the device */ + uptr->FUNC = DSK_FUNC_IDLE; + dsk_dsw[drv] = DSK_DSW_CARRIAGE_HOME; - CLRBIT(uptr->flags, UNIT_RO|UNIT_ROABLE|UNIT_BUFABLE|UNIT_BUF|UNIT_RONLY|UNIT_OPERR|UNIT_HARDERR); - CLRBIT(ILSW[2], dsk_ilswbit[drv]); - calc_ints(); + CLRBIT(uptr->flags, UNIT_RO|UNIT_ROABLE|UNIT_BUFABLE|UNIT_BUF|UNIT_RONLY|UNIT_OPERR|UNIT_HARDERR); + CLRBIT(ILSW[2], dsk_ilswbit[drv]); + calc_ints(); - if (sim_switches & SWMASK('M')) /* if memory mode (e.g. for CGI), buffer the file */ - SETBIT(uptr->flags, UNIT_BUFABLE|UNIT_MUSTBUF); + if (sim_switches & SWMASK('M')) /* if memory mode (e.g. for CGI), buffer the file */ + SETBIT(uptr->flags, UNIT_BUFABLE|UNIT_MUSTBUF); - if (sim_switches & SWMASK('R')) /* read lock mode */ - SETBIT(uptr->flags, UNIT_RO|UNIT_ROABLE|UNIT_RONLY); + if (sim_switches & SWMASK('R')) /* read lock mode */ + SETBIT(uptr->flags, UNIT_RO|UNIT_ROABLE|UNIT_RONLY); - if (cgi && (sim_switches & SWMASK('M')) && ! cgiwritable) { /* if cgi and memory mode, but writable option not specified */ - sim_switches |= SWMASK('R'); /* have attach_unit open file in readonly mode */ - SETBIT(uptr->flags, UNIT_ROABLE); /* but don't set the UNIT_RONLY flag so DMS can write to the buffered image */ - } + if (cgi && (sim_switches & SWMASK('M')) && ! cgiwritable) { /* if cgi and memory mode, but writable option not specified */ + sim_switches |= SWMASK('R'); /* have attach_unit open file in readonly mode */ + SETBIT(uptr->flags, UNIT_ROABLE); /* but don't set the UNIT_RONLY flag so DMS can write to the buffered image */ + } - if ((rval = attach_unit(uptr, quotefix(cptr, gbuf))) != SCPE_OK) { /* mount new disk */ - SETBIT(dsk_dsw[drv], DSK_DSW_NOT_READY); - return rval; - } + if ((rval = attach_unit(uptr, quotefix(cptr, gbuf))) != SCPE_OK) { /* mount new disk */ + SETBIT(dsk_dsw[drv], DSK_DSW_NOT_READY); + return rval; + } - if (drv == 0) { - disk_ready(TRUE); - disk_unlocked(FALSE); - } + if (drv == 0) { + disk_ready(TRUE); + disk_unlocked(FALSE); + } - enable_dms_tracing(sim_switches & SWMASK('D')); - raw_disk_debug = sim_switches & SWMASK('G'); + enable_dms_tracing(sim_switches & SWMASK('D')); + raw_disk_debug = sim_switches & SWMASK('G'); - return SCPE_OK; + return SCPE_OK; } static t_stat dsk_detach (UNIT *uptr) { - t_stat rval; - int drv = uptr - dsk_unit; + t_stat rval; + int drv = uptr - dsk_unit; - sim_cancel(uptr); + sim_cancel(uptr); - if ((rval = detach_unit(uptr)) != SCPE_OK) - return rval; + if ((rval = detach_unit(uptr)) != SCPE_OK) + return rval; - CLRBIT(ILSW[2], dsk_ilswbit[drv]); - CLRBIT(uptr->flags, UNIT_OPERR|UNIT_HARDERR); - calc_ints(); + CLRBIT(ILSW[2], dsk_ilswbit[drv]); + CLRBIT(uptr->flags, UNIT_OPERR|UNIT_HARDERR); + calc_ints(); - uptr->CYL = 0; - uptr->FUNC = DSK_FUNC_IDLE; - dsk_dsw[drv] = DSK_DSW_NOT_READY; + uptr->CYL = 0; + uptr->FUNC = DSK_FUNC_IDLE; + dsk_dsw[drv] = DSK_DSW_NOT_READY; - if (drv == 0) { - disk_unlocked(TRUE); - disk_ready(FALSE); - } + if (drv == 0) { + disk_unlocked(TRUE); + disk_ready(FALSE); + } - return SCPE_OK; + return SCPE_OK; } /* boot routine - if they type BOOT DSK, load the standard boot card. */ static t_stat dsk_boot (int32 unitno, DEVICE *dptr) { - t_stat rval; + t_stat rval; - if ((rval = reset_all(0)) != SCPE_OK) - return rval; + if ((rval = reset_all(0)) != SCPE_OK) + return rval; - return load_cr_boot(unitno, sim_switches); + return load_cr_boot(unitno, sim_switches); } #ifdef TRACE_DMS_IO static struct { - int phid; - const char *name; + int phid; + const char *name; } phase[] = { # include "dmsr2v12phases.h" {0xFFFF, ""} @@ -593,296 +593,296 @@ static struct { #pragma pack(2) #define MAXSLET ((3*320)/4) struct tag_slet { - int16 phid; - int16 addr; - int16 nwords; - int16 sector; + int16 phid; + int16 addr; + int16 nwords; + int16 sector; } slet[MAXSLET] = { -#include "dmsr2v12slet.h" /* without RPG, use this info until overwritten by actual data from disk */ +#include "dmsr2v12slet.h" /* without RPG, use this info until overwritten by actual data from disk */ }; #pragma pack() #define MAXMSEG 100 struct tag_mseg { - const char *name; - int addr, offset, len, phid; + const char *name; + int addr, offset, len, phid; } mseg[MAXMSEG]; int nseg = 0; static void enable_dms_tracing (int newsetting) { - nseg = 0; /* clear the segment map */ + nseg = 0; /* clear the segment map */ - if ((newsetting && trace_dms) || ! (newsetting || trace_dms)) - return; + if ((newsetting && trace_dms) || ! (newsetting || trace_dms)) + return; - trace_dms = newsetting; - if (! sim_quiet) - printf("DMS disk tracing is now %sabled\n", trace_dms ? "en" : "dis"); + trace_dms = newsetting; + if (! sim_quiet) + printf("DMS disk tracing is now %sabled\n", trace_dms ? "en" : "dis"); } const char * saywhere (int addr) { - int i; - static char buf[150]; + int i; + static char buf[150]; - for (i = 0; i < nseg; i++) { - if (addr >= mseg[i].addr && addr < (mseg[i].addr+mseg[i].len)) { - sprintf(buf, "/%04x = /%04x + /%x in ", addr, mseg[i].addr - mseg[i].offset, addr-mseg[i].addr + mseg[i].offset); - if (mseg[i].phid > 0) - sprintf(buf+strlen(buf), "phase %02x (%s)", mseg[i].phid, mseg[i].name); - else - sprintf(buf+strlen(buf), "%s", mseg[i].name); + for (i = 0; i < nseg; i++) { + if (addr >= mseg[i].addr && addr < (mseg[i].addr+mseg[i].len)) { + sprintf(buf, "/%04x = /%04x + /%x in ", addr, mseg[i].addr - mseg[i].offset, addr-mseg[i].addr + mseg[i].offset); + if (mseg[i].phid > 0) + sprintf(buf+strlen(buf), "phase %02x (%s)", mseg[i].phid, mseg[i].name); + else + sprintf(buf+strlen(buf), "%s", mseg[i].name); - return buf; - } - } - return NULL; + return buf; + } + } + return NULL; } static int phdebug_lo = -1, phdebug_hi = -1; static t_stat phdebug_cmd (int32 flag, CONST char *ptr) { - int val1, val2; + int val1, val2; - if (strcmpi(ptr, "off") == 0) - phdebug_lo = phdebug_hi = -1; - else { - switch(sscanf(ptr, "%x%x", &val1, &val2)) { - case 1: - phdebug_lo = phdebug_hi = val1; - enable_dms_tracing(TRUE); - break; + if (strcmpi(ptr, "off") == 0) + phdebug_lo = phdebug_hi = -1; + else { + switch(sscanf(ptr, "%x%x", &val1, &val2)) { + case 1: + phdebug_lo = phdebug_hi = val1; + enable_dms_tracing(TRUE); + break; - case 2: - phdebug_lo = val1; - phdebug_hi = val2; - enable_dms_tracing(TRUE); - break; + case 2: + phdebug_lo = val1; + phdebug_hi = val2; + enable_dms_tracing(TRUE); + break; - default: - printf("Usage: phdebug off | phdebug phfrom [phto]\n"); - break; - } - } - return SCPE_OK; + default: + printf("Usage: phdebug off | phdebug phfrom [phto]\n"); + break; + } + } + return SCPE_OK; } static t_stat where_cmd (int32 flag, CONST char *ptr) { - int addr; - const char *where; + int addr; + const char *where; - if (! trace_dms) { - printf("Tracing is disabled. To enable, attach disk with -d switch\n"); - return SCPE_OK; - } + if (! trace_dms) { + printf("Tracing is disabled. To enable, attach disk with -d switch\n"); + return SCPE_OK; + } - if (sscanf(ptr, "%x", &addr) != 1) - return SCPE_ARG; + if (sscanf(ptr, "%x", &addr) != 1) + return SCPE_ARG; - if ((where = saywhere(addr)) == NULL) - printf("/%04x not found\n", addr); - else - printf("%s\n", where); + if ((where = saywhere(addr)) == NULL) + printf("/%04x not found\n", addr); + else + printf("%s\n", where); - return SCPE_OK; + return SCPE_OK; } /* savesector - save info on a sector just read. THIS IS NOT YET TESTED */ static void addseg (int i) { - if (! trace_dms) - return; + if (! trace_dms) + return; - if (nseg >= MAXMSEG) { - printf("(Memory map full, disabling tracing)\n"); - trace_dms = 0; - nseg = -1; - return; - } - memcpy(mseg+i+1, mseg+i, (nseg-i)*sizeof(mseg[0])); - nseg++; + if (nseg >= MAXMSEG) { + printf("(Memory map full, disabling tracing)\n"); + trace_dms = 0; + nseg = -1; + return; + } + memcpy(mseg+i+1, mseg+i, (nseg-i)*sizeof(mseg[0])); + nseg++; } static void delseg (int i) { - if (! trace_dms) - return; + if (! trace_dms) + return; - if (nseg > 0) { - nseg--; - memcpy(mseg+i, mseg+i+1, (nseg-i)*sizeof(mseg[0])); - } + if (nseg > 0) { + nseg--; + memcpy(mseg+i, mseg+i+1, (nseg-i)*sizeof(mseg[0])); + } } static void savesector (int addr, int offset, int len, int phid, const char *name) { - int i; + int i; - if (! trace_dms) - return; - - addr++; /* first word is sector address, so account for that */ - len--; + if (! trace_dms) + return; + + addr++; /* first word is sector address, so account for that */ + len--; - for (i = 0; i < nseg; i++) { - if (addr >= (mseg[i].addr+mseg[i].len)) /* entirely after this entry */ - continue; + for (i = 0; i < nseg; i++) { + if (addr >= (mseg[i].addr+mseg[i].len)) /* entirely after this entry */ + continue; - if (mseg[i].addr < addr) { /* old one starts before this. split it */ - addseg(i); - mseg[i].len = addr-mseg[i].addr; - i++; - mseg[i].addr = addr; - mseg[i].len -= mseg[i-1].len; - } + if (mseg[i].addr < addr) { /* old one starts before this. split it */ + addseg(i); + mseg[i].len = addr-mseg[i].addr; + i++; + mseg[i].addr = addr; + mseg[i].len -= mseg[i-1].len; + } - break; - } + break; + } - addseg(i); /* add new segment. Old one ends up after this */ + addseg(i); /* add new segment. Old one ends up after this */ - if (i >= MAXMSEG) - return; + if (i >= MAXMSEG) + return; - mseg[i].addr = addr; - mseg[i].offset = offset; - mseg[i].phid = phid; - mseg[i].len = len; - mseg[i].name = name; + mseg[i].addr = addr; + mseg[i].offset = offset; + mseg[i].phid = phid; + mseg[i].len = len; + mseg[i].name = name; - i++; /* delete any segments completely covered */ + i++; /* delete any segments completely covered */ - while (i < nseg && (mseg[i].addr+mseg[i].len) <= (addr+len)) - delseg(i); + while (i < nseg && (mseg[i].addr+mseg[i].len) <= (addr+len)) + delseg(i); - if (i < nseg && mseg[i].addr < (addr+len)) { /* old one extends past this. Retain the end */ - mseg[i].len = (mseg[i].addr+mseg[i].len) - (addr+len); - mseg[i].addr = addr+len; - } + if (i < nseg && mseg[i].addr < (addr+len)) { /* old one extends past this. Retain the end */ + mseg[i].len = (mseg[i].addr+mseg[i].len) - (addr+len); + mseg[i].addr = addr+len; + } } static void tracesector (int iswrite, int nwords, int addr, int sector) { - int i, phid = 0, offset = 0; - const char *name = NULL; + int i, phid = 0, offset = 0; + const char *name = NULL; - if (nwords < 3 || ! trace_dms) - return; + if (nwords < 3 || ! trace_dms) + return; - switch (sector) { /* explicitly known sector name */ - case 0: name = "ID/COLD START"; break; - case 1: name = "DCOM"; break; - case 2: name = "RESIDENT IMAGE"; break; - case 3: - case 4: - case 5: name = "SLET"; /* save just-read or written SLET info */ - memmove(&slet[(320/4)*(sector-3)], &M[addr+1], nwords*2); - break; - case 6: name = "RELOAD TABLE"; break; - case 7: name = "PAGE HEADER"; break; - } + switch (sector) { /* explicitly known sector name */ + case 0: name = "ID/COLD START"; break; + case 1: name = "DCOM"; break; + case 2: name = "RESIDENT IMAGE"; break; + case 3: + case 4: + case 5: name = "SLET"; /* save just-read or written SLET info */ + memmove(&slet[(320/4)*(sector-3)], &M[addr+1], nwords*2); + break; + case 6: name = "RELOAD TABLE"; break; + case 7: name = "PAGE HEADER"; break; + } - printf("* %04x: %3d /%04x %c %3d.%d ", - prev_IAR, nwords, addr, iswrite ? 'W' : 'R', sector/8, sector%8); + printf("* %04x: %3d /%04x %c %3d.%d ", + prev_IAR, nwords, addr, iswrite ? 'W' : 'R', sector/8, sector%8); - if (name == NULL) { /* look up sector in SLET */ - for (i = 0; i < MAXSLET; i++) { - if (slet[i].phid == 0) /* not found */ - goto done; - else if (slet[i].sector > sector) { - if (--i >= 0) { - if (sector >= slet[i].sector && sector <= (slet[i].sector + slet[i].nwords/320)) { - phid = slet[i].phid; - offset = (sector-slet[i].sector)*320; - break; - } - } - goto done; - } - if (slet[i].sector == sector) { - phid = slet[i].phid; /* we found the starting sector */ - break; - } - } + if (name == NULL) { /* look up sector in SLET */ + for (i = 0; i < MAXSLET; i++) { + if (slet[i].phid == 0) /* not found */ + goto done; + else if (slet[i].sector > sector) { + if (--i >= 0) { + if (sector >= slet[i].sector && sector <= (slet[i].sector + slet[i].nwords/320)) { + phid = slet[i].phid; + offset = (sector-slet[i].sector)*320; + break; + } + } + goto done; + } + if (slet[i].sector == sector) { + phid = slet[i].phid; /* we found the starting sector */ + break; + } + } - if (i >= MAXSLET) /* was not found */ - goto done; + if (i >= MAXSLET) /* was not found */ + goto done; - name = "?"; - for (i = sizeof(phase)/sizeof(phase[0]); --i >= 0; ) { - if (phase[i].phid == phid) { /* look up name */ - name = phase[i].name; - break; - } - } - printf("%02x %s", phid, name); - } - else - printf("%s", name); + name = "?"; + for (i = sizeof(phase)/sizeof(phase[0]); --i >= 0; ) { + if (phase[i].phid == phid) { /* look up name */ + name = phase[i].name; + break; + } + } + printf("%02x %s", phid, name); + } + else + printf("%s", name); done: - putchar('\n'); + putchar('\n'); - if (phid >= phdebug_lo && phid <= phdebug_hi && offset == 0) - break_simulation(STOP_PHASE_BREAK); /* break on read of first sector of indicated phases */ + if (phid >= phdebug_lo && phid <= phdebug_hi && offset == 0) + break_simulation(STOP_PHASE_BREAK); /* break on read of first sector of indicated phases */ - if (name != NULL && *name != '?' && ! iswrite) - savesector(addr, offset, nwords, phid, name); + if (name != NULL && *name != '?' && ! iswrite) + savesector(addr, offset, nwords, phid, name); } static t_stat fdump_cmd (int32 flags, CONST char *cptr) { - int addr = 0x7a24; /* address of next statement */ - int sofst = 0x7a26, symaddr; - int cword, nwords, stype, has_stnum, strel = 1, laststno = 0; + int addr = 0x7a24; /* address of next statement */ + int sofst = 0x7a26, symaddr; + int cword, nwords, stype, has_stnum, strel = 1, laststno = 0; - addr = M[addr & mem_mask] & mem_mask; /* get address of first statement */ - sofst = M[sofst & mem_mask] & mem_mask ; /* get address of symbol table */ + addr = M[addr & mem_mask] & mem_mask; /* get address of first statement */ + sofst = M[sofst & mem_mask] & mem_mask ; /* get address of symbol table */ - for (;;) { - cword = M[addr]; - nwords = (cword >> 2) & 0x01FF; - stype = (cword >> 1) & 0x7C00; - has_stnum = (cword & 1); + for (;;) { + cword = M[addr]; + nwords = (cword >> 2) & 0x01FF; + stype = (cword >> 1) & 0x7C00; + has_stnum = (cword & 1); - if (has_stnum) { - laststno++; - strel = 0; - } + if (has_stnum) { + laststno++; + strel = 0; + } - printf("/%04x [%4d +%3d] %3d - %04x", addr, laststno, strel, nwords, stype); + printf("/%04x [%4d +%3d] %3d - %04x", addr, laststno, strel, nwords, stype); - if (has_stnum) { - addr++; - nwords--; - symaddr = sofst - (M[addr] & 0x7FF)*3 + 3; - printf(" [%04x %04x %04x]", M[symaddr], M[symaddr+1], M[symaddr+2]); - } + if (has_stnum) { + addr++; + nwords--; + symaddr = sofst - (M[addr] & 0x7FF)*3 + 3; + printf(" [%04x %04x %04x]", M[symaddr], M[symaddr+1], M[symaddr+2]); + } - if (stype == 0x5000) { /* error record */ - printf(" (err %d)", M[addr+1]); - } - - if (stype == 0x0800) - break; + if (stype == 0x5000) { /* error record */ + printf(" (err %d)", M[addr+1]); + } + + if (stype == 0x0800) + break; - addr += nwords; - putchar('\n'); + addr += nwords; + putchar('\n'); - if (nwords == 0) { - printf("0 words?\n"); - break; - } - strel++; - } + if (nwords == 0) { + printf("0 words?\n"); + break; + } + strel++; + } - printf("\nEnd found at /%04x, EOFS = /%04x\n", addr, M[0x7a25 & mem_mask]); - return SCPE_OK; + printf("\nEnd found at /%04x, EOFS = /%04x\n", addr, M[0x7a25 & mem_mask]); + return SCPE_OK; } #endif /* TRACE_DMS_IO */ diff --git a/Ibm1130/ibm1130_fmt.c b/Ibm1130/ibm1130_fmt.c index c399d3d8..f18d6df5 100644 --- a/Ibm1130/ibm1130_fmt.c +++ b/Ibm1130/ibm1130_fmt.c @@ -8,53 +8,53 @@ * into the appropriate column format. Three edit modes are recognized: * * Assembler mode: - * Input lines of the form + * Input lines of the form * - * [label][opcode][tag][L][argument] + * [label][opcode][tag][L][argument] * - * are rearranged so that the input fields are placed in the appropriate columns + * are rearranged so that the input fields are placed in the appropriate columns * - * The label must start on the first character of the line. If there is no label, - * the first character(s) before the opcode must be whitespace. Following the opcode, there - * MUST be a tab character, followed by the format and tag. Following the format and tag - * may be exactly one whitespace character, and then starts the argument. + * The label must start on the first character of the line. If there is no label, + * the first character(s) before the opcode must be whitespace. Following the opcode, there + * MUST be a tab character, followed by the format and tag. Following the format and tag + * may be exactly one whitespace character, and then starts the argument. * - * Input lines with * in column 1 and blank lines are turned into Assembler comments, - * with the * in the Opcode field. + * Input lines with * in column 1 and blank lines are turned into Assembler comments, + * with the * in the Opcode field. * - * Assembler directive lines at the beginning of the deck must be preceded by - * ! to indicate that they are not comments. For example, + * Assembler directive lines at the beginning of the deck must be preceded by + * ! to indicate that they are not comments. For example, * - * !*LIST - * * This is a comment + * !*LIST + * * This is a comment * * Fortran mode: - * Input lines of the form + * Input lines of the form * - * [label]statement + * [label]statement * - * or + * or * - * [label]Xcontinuation + * [label]Xcontinuation * - * where X is a non alphabetic contination character are rearranged in the - * appropriate manner: + * where X is a non alphabetic contination character are rearranged in the + * appropriate manner: * - * 1 2 - * 12345678901234567890... - * ------------------------ - * label statement - * labelXcontinuation + * 1 2 + * 12345678901234567890... + * ------------------------ + * label statement + * labelXcontinuation * - * However, you must take care that you don't end up with statement text after column 72. + * However, you must take care that you don't end up with statement text after column 72. * - * Input lines with * or C in column 1 are left alone (comments and directives) + * Input lines with * or C in column 1 are left alone (comments and directives) * - * (The ! escape is not used before Fortran directives as before Assembler directives) + * (The ! escape is not used before Fortran directives as before Assembler directives) * * Tab mode: - * Tabs are replaced with spaces. Tab settings are assumed to be eight characters wide, - * as is standard for vi, notepad, etc. + * Tabs are replaced with spaces. Tab settings are assumed to be eight characters wide, + * as is standard for vi, notepad, etc. *********************************************************************************************/ #include @@ -64,26 +64,26 @@ #include #include "ibm1130_fmt.h" -#define MAXLINE 81 /* maximum output line size */ -#define WORKSZ 256 /* size for tab work area */ -#define TAGOFFSET 12 /* offset for tag field */ -#define FMTOFFSET 11 /* offset for format field */ +#define MAXLINE 81 /* maximum output line size */ +#define WORKSZ 256 /* size for tab work area */ +#define TAGOFFSET 12 /* offset for tag field */ +#define FMTOFFSET 11 /* offset for format field */ -#define MIN(a,b) ((a < b) ? a : b) -#define AMSG " with Assembler Reformat" -#define FMSG " with FORTRAN Reformat" -#define WMSG " with tab replacement" -#define AFORMAT "%20.20s%-60.60s"," " -#define ACOMMENTFMT "%20.20s%-60.60s"," " -#define ABLANKLINE "%20.20s*"," " -#define FFORMAT "%-5.5s %-74.74s" -#define FCONTFMT "%-5.5s%-75.75s" +#define MIN(a,b) ((a < b) ? a : b) +#define AMSG " with Assembler Reformat" +#define FMSG " with FORTRAN Reformat" +#define WMSG " with tab replacement" +#define AFORMAT "%20.20s%-60.60s"," " +#define ACOMMENTFMT "%20.20s%-60.60s"," " +#define ABLANKLINE "%20.20s*"," " +#define FFORMAT "%-5.5s %-74.74s" +#define FCONTFMT "%-5.5s%-75.75s" -static char gszLabel[6]; /* work area for label */ -static char gszArg[MAXLINE]; /* .. argument */ -static char gszOutput[MAXLINE]; /* .. output */ +static char gszLabel[6]; /* work area for label */ +static char gszArg[MAXLINE]; /* .. argument */ +static char gszOutput[MAXLINE]; /* .. output */ static short gaiAsmTabs[] = {7,12,15,20,25,30,35,40,45,52,0};/* tab stops for assembler */ -static short gaiPlainTabs[42]; /* tab stops for plain tabs. Settings will be made later. Max # positions when tabs are every 2 positions */ +static short gaiPlainTabs[42]; /* tab stops for plain tabs. Settings will be made later. Max # positions when tabs are every 2 positions */ static int giPlainTabWidth = 0; /* @@ -94,135 +94,135 @@ static int giPlainTabWidth = 0; * ExpandTabs: Expand tabs to spaces */ -char* ExpandTabs(char* p_szInbuf, /* expand tabs .. input buffer */ - char* p_szOutbuf, /* .. output buffer */ - short* p_aiTabs) /* .. array of tab stops (1 based) -- 0 end of array */ +char* ExpandTabs(char* p_szInbuf, /* expand tabs .. input buffer */ + char* p_szOutbuf, /* .. output buffer */ + short* p_aiTabs) /* .. array of tab stops (1 based) -- 0 end of array */ { -short iI, /* input position */ - iO, /* output position */ - iT; /* next tab stop */ - -char cX; /* character to test */ +short iI, /* input position */ + iO, /* output position */ + iT; /* next tab stop */ + +char cX; /* character to test */ - iI = 0; /* init input position */ - iO = 0; /* init output position */ - iT = 0; /* init tab stop */ - - while ((cX = *(p_szInbuf + iI)) != 0) /* while there are characters */ - { - if (cX == '\t') /* q. tab character? */ - { /* a. yes .. */ - while ((p_aiTabs[iT] <= iO + 1) /* search for next valid stop .. */ - && (p_aiTabs[iT] != 0)) /* .. or end of table */ - iT++; /* .. go to next tab */ - - if (p_aiTabs[iT] != 0) /* q. end of tab array? */ - { /* a. no .. */ - while (iO < (p_aiTabs[iT] - 1)) /* fill to tab with blanks */ - *(p_szOutbuf + iO++) = ' '; /* .. put in a blank */ - - } - else /* Otherwise ... */ - *(p_szOutbuf + iO++) = ' '; /* .. Translate to blank */ - } - else /* Otherwise .. not tab */ - *(p_szOutbuf + iO++) = cX; /* .. save the input char */ - - iI++; /* next input character */ - } - - *(p_szOutbuf + iO) = 0; /* end the string.. */ - return p_szOutbuf; /* .. return output area addr */ + iI = 0; /* init input position */ + iO = 0; /* init output position */ + iT = 0; /* init tab stop */ + + while ((cX = *(p_szInbuf + iI)) != 0) /* while there are characters */ + { + if (cX == '\t') /* q. tab character? */ + { /* a. yes .. */ + while ((p_aiTabs[iT] <= iO + 1) /* search for next valid stop .. */ + && (p_aiTabs[iT] != 0)) /* .. or end of table */ + iT++; /* .. go to next tab */ + + if (p_aiTabs[iT] != 0) /* q. end of tab array? */ + { /* a. no .. */ + while (iO < (p_aiTabs[iT] - 1)) /* fill to tab with blanks */ + *(p_szOutbuf + iO++) = ' '; /* .. put in a blank */ + + } + else /* Otherwise ... */ + *(p_szOutbuf + iO++) = ' '; /* .. Translate to blank */ + } + else /* Otherwise .. not tab */ + *(p_szOutbuf + iO++) = cX; /* .. save the input char */ + + iI++; /* next input character */ + } + + *(p_szOutbuf + iO) = 0; /* end the string.. */ + return p_szOutbuf; /* .. return output area addr */ } /************************************************* * extract next token, modify pointer */ -char* GetToken(char* p_szOut, /* output location */ - int p_iLen, /* max output length */ - char**p_pszToken) /* pointer to input token */ +char* GetToken(char* p_szOut, /* output location */ + int p_iLen, /* max output length */ + char**p_pszToken) /* pointer to input token */ { -int iI; /* work integer */ -char* pszX; /* work pointer */ +int iI; /* work integer */ +char* pszX; /* work pointer */ - pszX = *p_pszToken; /* get pointer to token */ + pszX = *p_pszToken; /* get pointer to token */ - for (iI = 0; *(pszX + iI) && (!isspace(*(pszX + iI)));) /* while not whitespace & not end */ - iI++; /* .. count token length */ + for (iI = 0; *(pszX + iI) && (!isspace(*(pszX + iI)));) /* while not whitespace & not end */ + iI++; /* .. count token length */ - memset(p_szOut, 0, p_iLen); /* zero out output area */ + memset(p_szOut, 0, p_iLen); /* zero out output area */ - if (iI > 0) /* q. any chars? */ - strncpy(p_szOut, *p_pszToken, MIN(iI, p_iLen-1)); /* a. yes.. copy max of p_iLen-1 */ + if (iI > 0) /* q. any chars? */ + strncpy(p_szOut, *p_pszToken, MIN(iI, p_iLen-1)); /* a. yes.. copy max of p_iLen-1 */ - *p_pszToken += iI; /* point beyond token */ - return p_szOut; /* .. return token pointer */ + *p_pszToken += iI; /* point beyond token */ + return p_szOut; /* .. return token pointer */ } /************************************************* * EditToAsm - convert tab-formatted text line to 1130 Assembler format */ -const char *EditToAsm (char* p_pszEdit, int width) /* convert line to 1130 assembler */ +const char *EditToAsm (char* p_pszEdit, int width) /* convert line to 1130 assembler */ { -char pszLine[MAXLINE]; /* source line */ -char pszWork[WORKSZ]; /* work buffer */ -char acTFWrk[2]; /* tag/format work area */ -size_t iI; /* work integer */ +char pszLine[MAXLINE]; /* source line */ +char pszWork[WORKSZ]; /* work buffer */ +char acTFWrk[2]; /* tag/format work area */ +size_t iI; /* work integer */ - if (p_pszEdit == NULL) /* q. null request? */ - return AMSG; /* a. yes .. return display message */ + if (p_pszEdit == NULL) /* q. null request? */ + return AMSG; /* a. yes .. return display message */ - if (*p_pszEdit == '!') /* leave lines starting with ! alone */ - return EditToWhitespace(p_pszEdit+1, width); + if (*p_pszEdit == '!') /* leave lines starting with ! alone */ + return EditToWhitespace(p_pszEdit+1, width); - if (*p_pszEdit == '*') /* q. comment line? */ - { /* a. yes.. */ - strncpy(pszWork, EditToWhitespace(p_pszEdit, width), MAXLINE); /* .. convert any tabs */ - sprintf(gszOutput, ACOMMENTFMT, pszWork); /* .. put the comment out there in the opcode column */ - return gszOutput; /* .. and return it */ - } + if (*p_pszEdit == '*') /* q. comment line? */ + { /* a. yes.. */ + strncpy(pszWork, EditToWhitespace(p_pszEdit, width), MAXLINE); /* .. convert any tabs */ + sprintf(gszOutput, ACOMMENTFMT, pszWork); /* .. put the comment out there in the opcode column */ + return gszOutput; /* .. and return it */ + } - strncpy(pszLine, p_pszEdit, MAXLINE-1); /* copy the line local */ - - ExpandTabs(pszLine, pszWork, gaiAsmTabs); /* expand the tabs */ - strncpy(pszLine, pszWork, MAXLINE-1); /* copy the line back */ - - for (iI = strlen(pszLine); iI--;) /* trim trailing whitespace */ - { - if (*(pszLine + iI) <= ' ') /* q. space or less? */ - *(pszLine + iI) = 0; /* a. yes .. remove it */ - else /* otherwise */ - break; /* .. done. Leave loop. */ - } + strncpy(pszLine, p_pszEdit, MAXLINE-1); /* copy the line local */ + + ExpandTabs(pszLine, pszWork, gaiAsmTabs); /* expand the tabs */ + strncpy(pszLine, pszWork, MAXLINE-1); /* copy the line back */ + + for (iI = strlen(pszLine); iI--;) /* trim trailing whitespace */ + { + if (*(pszLine + iI) <= ' ') /* q. space or less? */ + *(pszLine + iI) = 0; /* a. yes .. remove it */ + else /* otherwise */ + break; /* .. done. Leave loop. */ + } - if (strlen(pszLine) == 0) /* q. blank line? */ - { /* a. yes .. Assembler abhors these so */ - sprintf(gszOutput, ABLANKLINE); /* format as comment statement */ - return gszOutput; /* .. and return it */ - } + if (strlen(pszLine) == 0) /* q. blank line? */ + { /* a. yes .. Assembler abhors these so */ + sprintf(gszOutput, ABLANKLINE); /* format as comment statement */ + return gszOutput; /* .. and return it */ + } - /* TODO: Add code to process a strip switch - * comment? - */ + /* TODO: Add code to process a strip switch + * comment? + */ - if (strlen(pszLine) > (TAGOFFSET + 1)) /* q. line long enough? */ - { /* a. yes.. reorder tag/format */ - memcpy(acTFWrk, pszLine + FMTOFFSET, 2); /* get tag/format */ - memset((pszLine + FMTOFFSET), ' ', 2); /* .. blank 'em out */ - - for (iI = 0; iI < 2; iI ++) - if (isalpha(acTFWrk[iI])) /* q. alpha char? */ - *(pszLine + FMTOFFSET) = acTFWrk[iI]; /* a. yes .. make it format */ - else if (isdigit(acTFWrk[iI])) /* q. digit? */ - *(pszLine + TAGOFFSET) = acTFWrk[iI]; /* a. yes .. make it the tag */ - } + if (strlen(pszLine) > (TAGOFFSET + 1)) /* q. line long enough? */ + { /* a. yes.. reorder tag/format */ + memcpy(acTFWrk, pszLine + FMTOFFSET, 2); /* get tag/format */ + memset((pszLine + FMTOFFSET), ' ', 2); /* .. blank 'em out */ + + for (iI = 0; iI < 2; iI ++) + if (isalpha(acTFWrk[iI])) /* q. alpha char? */ + *(pszLine + FMTOFFSET) = acTFWrk[iI]; /* a. yes .. make it format */ + else if (isdigit(acTFWrk[iI])) /* q. digit? */ + *(pszLine + TAGOFFSET) = acTFWrk[iI]; /* a. yes .. make it the tag */ + } - sprintf(gszOutput, AFORMAT, pszLine); /* format the line */ - - return gszOutput; /* return formatted line */ + sprintf(gszOutput, AFORMAT, pszLine); /* format the line */ + + return gszOutput; /* return formatted line */ } /************************************************* @@ -230,99 +230,99 @@ size_t iI; /* work integer */ * (a la DEC Fortran) */ -const char *EditToFortran(char* p_pszEdit, int width) /* convert line to 1130 assembler */ +const char *EditToFortran(char* p_pszEdit, int width) /* convert line to 1130 assembler */ { -char pszLine[MAXLINE]; /* source line */ -char* pszWork; /* work pointer */ -size_t iI; /* work integer */ -int bContinue; /* true if continue */ +char pszLine[MAXLINE]; /* source line */ +char* pszWork; /* work pointer */ +size_t iI; /* work integer */ +int bContinue; /* true if continue */ - if (p_pszEdit == NULL) /* q. null request? */ - return FMSG; /* a. yes .. return display message */ + if (p_pszEdit == NULL) /* q. null request? */ + return FMSG; /* a. yes .. return display message */ - if (strchr(p_pszEdit, '\t') == NULL) /* q. no tab in the line? */ - return p_pszEdit; /* a. nope, return line as is, assume it's formatted correctly */ + if (strchr(p_pszEdit, '\t') == NULL) /* q. no tab in the line? */ + return p_pszEdit; /* a. nope, return line as is, assume it's formatted correctly */ - if (*p_pszEdit == 'C' || *p_pszEdit == '*' || *p_pszEdit == '\0') /* q. comment or directive or blank line? */ - { /* a. yes.. don't restructure */ - return EditToWhitespace(p_pszEdit, width); - } + if (*p_pszEdit == 'C' || *p_pszEdit == '*' || *p_pszEdit == '\0') /* q. comment or directive or blank line? */ + { /* a. yes.. don't restructure */ + return EditToWhitespace(p_pszEdit, width); + } - strncpy(pszLine, p_pszEdit, MAXLINE-1); /* copy the line local */ + strncpy(pszLine, p_pszEdit, MAXLINE-1); /* copy the line local */ - for (iI = strlen(pszLine); iI--;) /* trim trailing whitespace */ - { - if (*(pszLine + iI) <= ' ') /* q. space or less? */ - *(pszLine + iI) = 0; /* a. yes .. remove it */ - else /* otherwise */ - break; /* .. done. Leave loop. */ - } + for (iI = strlen(pszLine); iI--;) /* trim trailing whitespace */ + { + if (*(pszLine + iI) <= ' ') /* q. space or less? */ + *(pszLine + iI) = 0; /* a. yes .. remove it */ + else /* otherwise */ + break; /* .. done. Leave loop. */ + } - /* - * TODO: Add code to process a strip switch - * comment? - */ + /* + * TODO: Add code to process a strip switch + * comment? + */ - pszWork = (char*) pszLine; /* set pointer to line */ - GetToken(gszLabel, 6, &pszWork); /* get the line, if any. */ + pszWork = (char*) pszLine; /* set pointer to line */ + GetToken(gszLabel, 6, &pszWork); /* get the line, if any. */ - pszWork++; /* skip tab/whitespace */ + pszWork++; /* skip tab/whitespace */ - /* continuation... */ - bContinue = ((isdigit(*pszWork) && (*pszWork != '0')) /* if first char non-zero digit */ - || (!isspace(*pszWork) && !isalpha(*pszWork))); /* .. or non-alpha non-blank */ - - memset(gszArg, 0, MAXLINE); /* .. and arguments */ + /* continuation... */ + bContinue = ((isdigit(*pszWork) && (*pszWork != '0')) /* if first char non-zero digit */ + || (!isspace(*pszWork) && !isalpha(*pszWork))); /* .. or non-alpha non-blank */ + + memset(gszArg, 0, MAXLINE); /* .. and arguments */ - strncpy(gszArg, pszWork, 75); /* copy rest to argument */ + strncpy(gszArg, pszWork, 75); /* copy rest to argument */ - sprintf(gszOutput, (bContinue) ? FCONTFMT : FFORMAT, /* format the line */ - gszLabel, /* .. statement # */ - gszArg); /* .. code */ - - return gszOutput; /* return formatted line */ + sprintf(gszOutput, (bContinue) ? FCONTFMT : FFORMAT, /* format the line */ + gszLabel, /* .. statement # */ + gszArg); /* .. code */ + + return gszOutput; /* return formatted line */ } /************************************************* * EditToWhitespace - expand tabs at n space intervals. */ -const char* EditToWhitespace(char *p_pszEdit, int width) +const char* EditToWhitespace(char *p_pszEdit, int width) { -int iI; /* work integer */ +int iI; /* work integer */ int iPos; /* work integer for settings tab stops */ -char pszLine[MAXLINE]; /* source line */ -char pszWork[WORKSZ]; /* work buffer */ +char pszLine[MAXLINE]; /* source line */ +char pszWork[WORKSZ]; /* work buffer */ - if (p_pszEdit == NULL) /* q. null request? */ - return WMSG; /* a. yes .. return display message */ + if (p_pszEdit == NULL) /* q. null request? */ + return WMSG; /* a. yes .. return display message */ - strncpy(pszLine, p_pszEdit, MAXLINE-1); /* copy the line local */ + strncpy(pszLine, p_pszEdit, MAXLINE-1); /* copy the line local */ - if (width == 0) width = 8; /* default */ + if (width == 0) width = 8; /* default */ - if ((width != giPlainTabWidth) && (width > 1) && (width < 30)) { - giPlainTabWidth = width; /* if width is different, and valid, rebuild tabstop array */ - iI = 0; /* output index */ - iPos = width + 1; /* first tab position */ - while (iPos < 80) { /* fill array up to but not including position 80 */ - gaiPlainTabs[iI++] = iPos; - iPos += width; - } - gaiPlainTabs[iI] = 0; /* mark end of array */ - } - - ExpandTabs(pszLine, pszWork, gaiPlainTabs); /* expand the tabs */ - strncpy(gszOutput, pszWork, MAXLINE-1); /* copy the line back */ - - for (iI = strlen(gszOutput); iI--;) /* look at each character */ - { - if (*(gszOutput + iI) <= ' ') /* q. space or less? */ - *(gszOutput + iI) = 0; /* a. yes .. remove it */ - else /* otherwise */ - break; /* .. done. Leave loop. */ - } + if ((width != giPlainTabWidth) && (width > 1) && (width < 30)) { + giPlainTabWidth = width; /* if width is different, and valid, rebuild tabstop array */ + iI = 0; /* output index */ + iPos = width + 1; /* first tab position */ + while (iPos < 80) { /* fill array up to but not including position 80 */ + gaiPlainTabs[iI++] = iPos; + iPos += width; + } + gaiPlainTabs[iI] = 0; /* mark end of array */ + } + + ExpandTabs(pszLine, pszWork, gaiPlainTabs); /* expand the tabs */ + strncpy(gszOutput, pszWork, MAXLINE-1); /* copy the line back */ + + for (iI = strlen(gszOutput); iI--;) /* look at each character */ + { + if (*(gszOutput + iI) <= ' ') /* q. space or less? */ + *(gszOutput + iI) = 0; /* a. yes .. remove it */ + else /* otherwise */ + break; /* .. done. Leave loop. */ + } - return gszOutput; /* ... return buffer */ + return gszOutput; /* ... return buffer */ } diff --git a/Ibm1130/ibm1130_fmt.h b/Ibm1130/ibm1130_fmt.h index 7248e96a..503b8b19 100644 --- a/Ibm1130/ibm1130_fmt.h +++ b/Ibm1130/ibm1130_fmt.h @@ -12,6 +12,6 @@ /* ibm1130_asm.h: definition of routines in ibm1130_asm.c */ -const char* EditToAsm(char* str, int width); /* convert edit format to 1130 assembler format */ -const char* EditToFortran(char* str, int width); /* convert edit format to Fortran format */ -const char* EditToWhitespace(char* str, int width); /* clean white space, tabstops every 8 positions */ +const char* EditToAsm(char* str, int width); /* convert edit format to 1130 assembler format */ +const char* EditToFortran(char* str, int width); /* convert edit format to Fortran format */ +const char* EditToWhitespace(char* str, int width); /* clean white space, tabstops every 8 positions */ diff --git a/Ibm1130/ibm1130_gdu.c b/Ibm1130/ibm1130_gdu.c index 1bbd3e2d..3a6c971e 100644 --- a/Ibm1130/ibm1130_gdu.c +++ b/Ibm1130/ibm1130_gdu.c @@ -21,82 +21,82 @@ * Mail to simh@ibm1130.org */ -#define BLIT_MODE /* define for better performance, undefine when debugging generate_image() */ -/* #define DEBUG_LIGHTPEN */ /* define to debug light-pen sensing */ +#define BLIT_MODE /* define for better performance, undefine when debugging generate_image() */ +/* #define DEBUG_LIGHTPEN */ /* define to debug light-pen sensing */ -#define DEFAULT_GDU_RATE 20 /* default frame rate */ -#define DEFAULT_PEN_THRESHOLD 3 /* default looseness of light-pen hit */ -#define INDWIDTH 32 /* width of an indicator (there are two columns of these) */ -#define INITSIZE 512 /* initial window size */ +#define DEFAULT_GDU_RATE 20 /* default frame rate */ +#define DEFAULT_PEN_THRESHOLD 3 /* default looseness of light-pen hit */ +#define INDWIDTH 32 /* width of an indicator (there are two columns of these) */ +#define INITSIZE 512 /* initial window size */ -#define GDU_DSW_ORDER_CONTROLLED_INTERRUPT 0x8000 -#define GDU_DSW_KEYBOARD_INTERUPT 0x4000 -#define GDU_DSW_DETECT_INTERRUPT 0x2000 -#define GDU_DSW_CYCLE_STEAL_CHECK 0x1000 -#define GDU_DSW_DETECT_STATUS 0x0800 -#define GDU_DSW_LIGHT_PEN_SWITCH 0x0100 -#define GDU_DSW_BUSY 0x0080 -#define GDU_DSW_CHARACTER_MODE 0x0040 -#define GDU_DSW_POINT_MODE 0x0020 -#define GDU_DSW_ADDR_DISP 0x0003 +#define GDU_DSW_ORDER_CONTROLLED_INTERRUPT 0x8000 +#define GDU_DSW_KEYBOARD_INTERUPT 0x4000 +#define GDU_DSW_DETECT_INTERRUPT 0x2000 +#define GDU_DSW_CYCLE_STEAL_CHECK 0x1000 +#define GDU_DSW_DETECT_STATUS 0x0800 +#define GDU_DSW_LIGHT_PEN_SWITCH 0x0100 +#define GDU_DSW_BUSY 0x0080 +#define GDU_DSW_CHARACTER_MODE 0x0040 +#define GDU_DSW_POINT_MODE 0x0020 +#define GDU_DSW_ADDR_DISP 0x0003 -#define GDU_FKEY_DATA_AVAILABLE 0x8000 -#define GDU_FKEY_KEY_CODE 0x1F00 -#define GDU_FKEY_OVERLAY_CODE 0x00FF +#define GDU_FKEY_DATA_AVAILABLE 0x8000 +#define GDU_FKEY_KEY_CODE 0x1F00 +#define GDU_FKEY_OVERLAY_CODE 0x00FF -#define GDU_AKEY_DATA_AVAILABLE 0x8000 -#define GDU_AKEY_END 0x1000 -#define GDU_AKEY_CANCEL 0x0800 -#define GDU_AKEY_ADVANCE 0x0400 -#define GDU_AKEY_BACKSPACE 0x0200 -#define GDU_AKEY_JUMP 0x0100 -#define GDU_AKEY_KEY_CODE 0x00FF +#define GDU_AKEY_DATA_AVAILABLE 0x8000 +#define GDU_AKEY_END 0x1000 +#define GDU_AKEY_CANCEL 0x0800 +#define GDU_AKEY_ADVANCE 0x0400 +#define GDU_AKEY_BACKSPACE 0x0200 +#define GDU_AKEY_JUMP 0x0100 +#define GDU_AKEY_KEY_CODE 0x00FF /* -------------------------------------------------------------------------------------- */ -#define UNIT_V_DISPLAYED (UNIT_V_UF + 0) -#define UNIT_V_DETECTS_ENABLED (UNIT_V_UF + 1) -#define UNIT_V_INTERRUPTS_DEFERRED (UNIT_V_UF + 2) -#define UNIT_V_LARGE_CHARS (UNIT_V_UF + 3) +#define UNIT_V_DISPLAYED (UNIT_V_UF + 0) +#define UNIT_V_DETECTS_ENABLED (UNIT_V_UF + 1) +#define UNIT_V_INTERRUPTS_DEFERRED (UNIT_V_UF + 2) +#define UNIT_V_LARGE_CHARS (UNIT_V_UF + 3) -#define UNIT_DISPLAYED (1u << UNIT_V_DISPLAYED) /* display windows is up */ -#define UNIT_DETECTS_ENABLED (1u << UNIT_V_DETECTS_ENABLED) /* light pen detects are enabled */ -#define UNIT_INTERRUPTS_DEFERRED (1u << UNIT_V_INTERRUPTS_DEFERRED) /* light pen interrupts are deferred */ -#define UNIT_LARGE_CHARS (1u << UNIT_V_LARGE_CHARS) /* large character mode */ +#define UNIT_DISPLAYED (1u << UNIT_V_DISPLAYED) /* display windows is up */ +#define UNIT_DETECTS_ENABLED (1u << UNIT_V_DETECTS_ENABLED) /* light pen detects are enabled */ +#define UNIT_INTERRUPTS_DEFERRED (1u << UNIT_V_INTERRUPTS_DEFERRED) /* light pen interrupts are deferred */ +#define UNIT_LARGE_CHARS (1u << UNIT_V_LARGE_CHARS) /* large character mode */ static t_stat gdu_reset (DEVICE *dptr); -static int16 gdu_dsw = 1; /* device status word */ -static int16 gdu_ar = 0; /* address register */ -static int16 gdu_x = 0; /* X deflection */ -static int16 gdu_y = 0; /* Y deflection */ -static int16 gdu_fkey = 0; /* function keyboard register */ -static int16 gdu_akey = 0; /* alphanumeric keyboard register */ -static int16 gdu_revert = 0; /* revert address register */ -static int32 gdu_indicators = 0; /* programmed indicator lamps */ -static int32 gdu_threshold = DEFAULT_PEN_THRESHOLD; /* mouse must be within 3/1024 of line to be a hit */ -static int32 gdu_rate = DEFAULT_GDU_RATE; /* refresh rate. 0 = default */ +static int16 gdu_dsw = 1; /* device status word */ +static int16 gdu_ar = 0; /* address register */ +static int16 gdu_x = 0; /* X deflection */ +static int16 gdu_y = 0; /* Y deflection */ +static int16 gdu_fkey = 0; /* function keyboard register */ +static int16 gdu_akey = 0; /* alphanumeric keyboard register */ +static int16 gdu_revert = 0; /* revert address register */ +static int32 gdu_indicators = 0; /* programmed indicator lamps */ +static int32 gdu_threshold = DEFAULT_PEN_THRESHOLD; /* mouse must be within 3/1024 of line to be a hit */ +static int32 gdu_rate = DEFAULT_GDU_RATE; /* refresh rate. 0 = default */ UNIT gdu_unit = { UDATA (NULL, 0, 0) }; REG gdu_reg[] = { - { HRDATA (GDUDSW, gdu_dsw, 16) }, /* device status word */ - { HRDATA (GDUAR, gdu_ar, 16) }, /* address register */ - { HRDATA (GDUXREG, gdu_x, 16) }, /* X deflection register */ - { HRDATA (GDUYREG, gdu_y, 16) }, /* Y deflection register */ - { HRDATA (GDUFKEY, gdu_fkey, 16) }, /* function keyboard register */ - { HRDATA (GDUAKEY, gdu_akey, 16) }, /* alphanumeric keyboard register */ - { HRDATA (GDUREVERT,gdu_revert, 16) }, /* revert address register */ - { HRDATA (GDUAKEY, gdu_indicators, 32) }, /* programmed indicators */ - { DRDATA (GDUTHRESH,gdu_threshold, 32) }, /* mouse closeness threshhold */ - { DRDATA (GDURATE, gdu_rate, 32) }, /* refresh rate in frames/sec */ - { NULL } }; + { HRDATA (GDUDSW, gdu_dsw, 16) }, /* device status word */ + { HRDATA (GDUAR, gdu_ar, 16) }, /* address register */ + { HRDATA (GDUXREG, gdu_x, 16) }, /* X deflection register */ + { HRDATA (GDUYREG, gdu_y, 16) }, /* Y deflection register */ + { HRDATA (GDUFKEY, gdu_fkey, 16) }, /* function keyboard register */ + { HRDATA (GDUAKEY, gdu_akey, 16) }, /* alphanumeric keyboard register */ + { HRDATA (GDUREVERT,gdu_revert, 16) }, /* revert address register */ + { HRDATA (GDUAKEY, gdu_indicators, 32) }, /* programmed indicators */ + { DRDATA (GDUTHRESH,gdu_threshold, 32) }, /* mouse closeness threshhold */ + { DRDATA (GDURATE, gdu_rate, 32) }, /* refresh rate in frames/sec */ + { NULL } }; DEVICE gdu_dev = { - "GDU", &gdu_unit, gdu_reg, NULL, - 1, 16, 16, 1, 16, 16, - NULL, NULL, gdu_reset, - NULL, NULL, NULL}; + "GDU", &gdu_unit, gdu_reg, NULL, + 1, 16, 16, 1, 16, 16, + NULL, NULL, gdu_reset, + NULL, NULL, NULL}; /* -------------------------------------------------------------------------------------- */ @@ -104,29 +104,29 @@ DEVICE gdu_dev = { static t_stat gdu_reset (DEVICE *dptr) { - return SCPE_OK; + return SCPE_OK; } void xio_2250_display (int32 addr, int32 func, int32 modify) { - /* ignore commands if device is nonexistent */ + /* ignore commands if device is nonexistent */ } t_bool gdu_active (void) { - return 0; + return 0; } /* -------------------------------------------------------------------------------------- */ -#else /* GUI_SUPPORT defined */ +#else /* GUI_SUPPORT defined */ /******* PLATFORM INDEPENDENT CODE ********************************************************/ -static int32 gdu_instaddr; // address of first word of instruction -static int xmouse, ymouse, lpen_dist, lpen_dist2; // current mouse pointer, scaled closeness threshhold, same squared -static double sfactor; // current scaling factor -static t_bool last_abs = TRUE; // last positioning instruction was absolute -static t_bool mouse_present = FALSE; // mouse is/is not in the window +static int32 gdu_instaddr; // address of first word of instruction +static int xmouse, ymouse, lpen_dist, lpen_dist2; // current mouse pointer, scaled closeness threshhold, same squared +static double sfactor; // current scaling factor +static t_bool last_abs = TRUE; // last positioning instruction was absolute +static t_bool mouse_present = FALSE; // mouse is/is not in the window static void clear_interrupts (void); static void set_indicators (int32 new_inds); static void start_regeneration (void); @@ -136,12 +136,12 @@ static void notify_window_closed (void); // routines that must be implemented per-platform -static void DrawLine(int x0, int y0, int x1, int y1); -static void DrawPoint(int x, int y); +static void DrawLine(int x0, int y0, int x1, int y1); +static void DrawPoint(int x, int y); static void CheckGDUKeyboard(void); static t_bool CreateGDUWindow(void); -static void StartGDUUpdates(void); -static void StopGDUUpdates(void); +static void StartGDUUpdates(void); +static void StopGDUUpdates(void); static void GetMouseCoordinates(void); static void UpdateGDUIndicators(void); static void ShowPenHit (int x, int y); @@ -151,503 +151,503 @@ static void EraseGDUScreen (void); void xio_2250_display (int32 addr, int32 func, int32 modify) { - if (cgi) return; /* ignore this device in CGI mode */ + if (cgi) return; /* ignore this device in CGI mode */ - switch (func) { - case XIO_SENSE_DEV: - ACC = (gdu_dsw & GDU_DSW_BUSY) ? GDU_DSW_BUSY : gdu_dsw; - if (modify & 1) - clear_interrupts(); - break; + switch (func) { + case XIO_SENSE_DEV: + ACC = (gdu_dsw & GDU_DSW_BUSY) ? GDU_DSW_BUSY : gdu_dsw; + if (modify & 1) + clear_interrupts(); + break; - case XIO_READ: /* store status data into word pointed to by IOCC packet */ - if (gdu_dsw & GDU_DSW_BUSY) /* not permitted while device is busy */ - break; + case XIO_READ: /* store status data into word pointed to by IOCC packet */ + if (gdu_dsw & GDU_DSW_BUSY) /* not permitted while device is busy */ + break; - WriteW(addr, gdu_ar); /* save status information */ - WriteW(addr+1, gdu_dsw); - WriteW(addr+2, gdu_x & 0x7FF); - WriteW(addr+3, gdu_y & 0x7FF); - WriteW(addr+4, gdu_fkey); - WriteW(addr+5, gdu_akey); - gdu_ar = (int16) (addr+6); /* this alters the channel address register? */ + WriteW(addr, gdu_ar); /* save status information */ + WriteW(addr+1, gdu_dsw); + WriteW(addr+2, gdu_x & 0x7FF); + WriteW(addr+3, gdu_y & 0x7FF); + WriteW(addr+4, gdu_fkey); + WriteW(addr+5, gdu_akey); + gdu_ar = (int16) (addr+6); /* this alters the channel address register? */ - clear_interrupts(); /* read status clears the interrupts */ - break; + clear_interrupts(); /* read status clears the interrupts */ + break; - case XIO_WRITE: - if (gdu_dsw & GDU_DSW_BUSY) /* treated as no-op if display is busy */ - break; + case XIO_WRITE: + if (gdu_dsw & GDU_DSW_BUSY) /* treated as no-op if display is busy */ + break; - if (modify & 0x80) { /* bit 8 on means set indicators, 0 means start regeneration */ - set_indicators((ReadW(addr) << 16) | ReadW(addr+1)); - } - else { - gdu_ar = (int16) addr; - gdu_fkey = 0; - gdu_akey = 0; - clear_interrupts(); - start_regeneration(); - } - break; + if (modify & 0x80) { /* bit 8 on means set indicators, 0 means start regeneration */ + set_indicators((ReadW(addr) << 16) | ReadW(addr+1)); + } + else { + gdu_ar = (int16) addr; + gdu_fkey = 0; + gdu_akey = 0; + clear_interrupts(); + start_regeneration(); + } + break; - case XIO_CONTROL: - if (modify & 0x80) { /* bit 8 on means reset, off is no-op */ - gdu_reset(&gdu_dev); - set_indicators((addr << 16) | addr); - } - break; + case XIO_CONTROL: + if (modify & 0x80) { /* bit 8 on means reset, off is no-op */ + gdu_reset(&gdu_dev); + set_indicators((addr << 16) | addr); + } + break; - default: /* all other commands are no-ops */ - break; - } + default: /* all other commands are no-ops */ + break; + } } static t_stat gdu_reset (DEVICE *dptr) { - if (cgi) return SCPE_OK; /* ignore this device in CGI mode */ + if (cgi) return SCPE_OK; /* ignore this device in CGI mode */ - halt_regeneration(); - clear_interrupts(); - set_indicators(0); - gdu_x = gdu_y = 512; - CLRBIT(gdu_unit.flags, UNIT_INTERRUPTS_DEFERRED | UNIT_DETECTS_ENABLED | UNIT_LARGE_CHARS); - gdu_dsw = 1; - return SCPE_OK; + halt_regeneration(); + clear_interrupts(); + set_indicators(0); + gdu_x = gdu_y = 512; + CLRBIT(gdu_unit.flags, UNIT_INTERRUPTS_DEFERRED | UNIT_DETECTS_ENABLED | UNIT_LARGE_CHARS); + gdu_dsw = 1; + return SCPE_OK; } static void clear_interrupts (void) { - CLRBIT(gdu_dsw, GDU_DSW_ORDER_CONTROLLED_INTERRUPT | GDU_DSW_KEYBOARD_INTERUPT | GDU_DSW_DETECT_INTERRUPT); - CLRBIT(ILSW[3], ILSW_3_2250_DISPLAY); - calc_ints(); + CLRBIT(gdu_dsw, GDU_DSW_ORDER_CONTROLLED_INTERRUPT | GDU_DSW_KEYBOARD_INTERUPT | GDU_DSW_DETECT_INTERRUPT); + CLRBIT(ILSW[3], ILSW_3_2250_DISPLAY); + calc_ints(); } static void gdu_interrupt (int32 dswbit) { - SETBIT(gdu_dsw, dswbit); - SETBIT(ILSW[3], ILSW_3_2250_DISPLAY); - calc_ints(); - halt_regeneration(); + SETBIT(gdu_dsw, dswbit); + SETBIT(ILSW[3], ILSW_3_2250_DISPLAY); + calc_ints(); + halt_regeneration(); } static void set_indicators (int32 new_inds) { - gdu_indicators = new_inds; - if (gdu_unit.flags & UNIT_DISPLAYED) - UpdateGDUIndicators(); + gdu_indicators = new_inds; + if (gdu_unit.flags & UNIT_DISPLAYED) + UpdateGDUIndicators(); } static void start_regeneration (void) { - SETBIT(gdu_dsw, GDU_DSW_BUSY); + SETBIT(gdu_dsw, GDU_DSW_BUSY); - if ((gdu_unit.flags & UNIT_DISPLAYED) == 0) { - if (! CreateGDUWindow()) - return; + if ((gdu_unit.flags & UNIT_DISPLAYED) == 0) { + if (! CreateGDUWindow()) + return; - SETBIT(gdu_unit.flags, UNIT_DISPLAYED); - } + SETBIT(gdu_unit.flags, UNIT_DISPLAYED); + } - StartGDUUpdates(); + StartGDUUpdates(); } static void halt_regeneration (void) { - // halt_regeneration gets called at end of every refresh interation, so it should NOT black out the - // screen -- this is why it was flickering so badly. The lower level code (called on a timer) - // should check to see if GDU_DSW_BUSY is clear, and if it it still zero after several msec, - // only then should it black out the screen and call StopGDUUpdates. - if (gdu_dsw & GDU_DSW_BUSY) { - CLRBIT(gdu_dsw, GDU_DSW_BUSY); - } + // halt_regeneration gets called at end of every refresh interation, so it should NOT black out the + // screen -- this is why it was flickering so badly. The lower level code (called on a timer) + // should check to see if GDU_DSW_BUSY is clear, and if it it still zero after several msec, + // only then should it black out the screen and call StopGDUUpdates. + if (gdu_dsw & GDU_DSW_BUSY) { + CLRBIT(gdu_dsw, GDU_DSW_BUSY); + } } static void notify_window_closed (void) { - if (gdu_dsw & GDU_DSW_BUSY) { - StopGDUUpdates(); - CLRBIT(gdu_dsw, GDU_DSW_BUSY); - } + if (gdu_dsw & GDU_DSW_BUSY) { + StopGDUUpdates(); + CLRBIT(gdu_dsw, GDU_DSW_BUSY); + } - CLRBIT(gdu_unit.flags, UNIT_DISPLAYED); + CLRBIT(gdu_unit.flags, UNIT_DISPLAYED); - gdu_reset(&gdu_dev); + gdu_reset(&gdu_dev); } static int32 read_gduword (void) { - int32 w; + int32 w; - w = M[gdu_ar++ & mem_mask]; - gdu_dsw = (int16) ((gdu_dsw & ~GDU_DSW_ADDR_DISP) | ((gdu_ar - gdu_instaddr) & GDU_DSW_ADDR_DISP)); + w = M[gdu_ar++ & mem_mask]; + gdu_dsw = (int16) ((gdu_dsw & ~GDU_DSW_ADDR_DISP) | ((gdu_ar - gdu_instaddr) & GDU_DSW_ADDR_DISP)); - return w; + return w; } #define DIST2(x0,y0,x1,y1) (((x1)-(x0))*((x1)-(x0))+((y1)-(y0))*((y1)-(y0))) static void draw (int32 newx, int32 newy, t_bool beam) { - int xmin, xmax, ymin, ymax, xd, yd; - double s; - int hit = FALSE; + int xmin, xmax, ymin, ymax, xd, yd; + double s; + int hit = FALSE; - if (beam) { - if (gdu_dsw & GDU_DSW_POINT_MODE) { - DrawPoint(newx, newy); + if (beam) { + if (gdu_dsw & GDU_DSW_POINT_MODE) { + DrawPoint(newx, newy); #ifdef DEBUG_LIGHTPEN - if (DIST2(newx, newy, xmouse, ymouse) <= lpen_dist2) - hit = TRUE; + if (DIST2(newx, newy, xmouse, ymouse) <= lpen_dist2) + hit = TRUE; #else - if (gdu_unit.flags & UNIT_DETECTS_ENABLED && mouse_present) - if (DIST2(newx, newy, xmouse, ymouse) <= lpen_dist2) - hit = TRUE; + if (gdu_unit.flags & UNIT_DETECTS_ENABLED && mouse_present) + if (DIST2(newx, newy, xmouse, ymouse) <= lpen_dist2) + hit = TRUE; #endif - } - else { - DrawLine(gdu_x, gdu_y, newx, newy); + } + else { + DrawLine(gdu_x, gdu_y, newx, newy); - // calculate proximity of light pen to the line + // calculate proximity of light pen to the line #ifndef DEBUG_LIGHTPEN - if (gdu_unit.flags & UNIT_DETECTS_ENABLED && mouse_present) { + if (gdu_unit.flags & UNIT_DETECTS_ENABLED && mouse_present) { #endif - if (gdu_x <= newx) - xmin = gdu_x, xmax = newx; - else - xmin = newx, xmax = gdu_x; + if (gdu_x <= newx) + xmin = gdu_x, xmax = newx; + else + xmin = newx, xmax = gdu_x; - if (gdu_y <= newy) - ymin = gdu_y, ymax = newy; - else - ymin = newy, ymax = gdu_y; + if (gdu_y <= newy) + ymin = gdu_y, ymax = newy; + else + ymin = newy, ymax = gdu_y; - if (newx == gdu_x) { - // line is vertical. Nearest point is an endpoint if the mouse is above or - // below the line segment, otherwise the segment point at the same y as the mouse - xd = gdu_x; - yd = (ymouse <= ymin) ? ymin : (ymouse >= ymax) ? ymax : ymouse; + if (newx == gdu_x) { + // line is vertical. Nearest point is an endpoint if the mouse is above or + // below the line segment, otherwise the segment point at the same y as the mouse + xd = gdu_x; + yd = (ymouse <= ymin) ? ymin : (ymouse >= ymax) ? ymax : ymouse; - if (DIST2(xd, yd, xmouse, ymouse) <= lpen_dist2) - hit = TRUE; - } - else if (newy == gdu_y) { - // line is horizontal. Nearest point is an endpoint if the mouse is to the left or - // the right of the line segment, otherwise the segment point at the same x as the mouse - xd = (xmouse <= xmin) ? xmin : (xmouse >= xmax) ? xmax : xmouse; - yd = gdu_y; + if (DIST2(xd, yd, xmouse, ymouse) <= lpen_dist2) + hit = TRUE; + } + else if (newy == gdu_y) { + // line is horizontal. Nearest point is an endpoint if the mouse is to the left or + // the right of the line segment, otherwise the segment point at the same x as the mouse + xd = (xmouse <= xmin) ? xmin : (xmouse >= xmax) ? xmax : xmouse; + yd = gdu_y; - if (DIST2(xd, yd, xmouse, ymouse) <= lpen_dist2) - hit = TRUE; - } - else { - // line is diagonal. See if the mouse is inside the box lpen_dist wider than the line segment's bounding rectangle - if (xmouse >= (xmin-lpen_dist) && xmouse <= (xmax+lpen_dist) && ymouse >= (ymin-lpen_dist) || ymouse <= (ymax+lpen_dist)) { - // compute the point at the intersection of the line through the line segment and the normal - // to that line through the mouse. This is the point on the line through the line segment - // nearest the mouse + if (DIST2(xd, yd, xmouse, ymouse) <= lpen_dist2) + hit = TRUE; + } + else { + // line is diagonal. See if the mouse is inside the box lpen_dist wider than the line segment's bounding rectangle + if (xmouse >= (xmin-lpen_dist) && xmouse <= (xmax+lpen_dist) && ymouse >= (ymin-lpen_dist) || ymouse <= (ymax+lpen_dist)) { + // compute the point at the intersection of the line through the line segment and the normal + // to that line through the mouse. This is the point on the line through the line segment + // nearest the mouse - s = (double)(newy - gdu_y) / (double)(newx - gdu_x); // slope of line segment - xd = (int) ((ymouse + xmouse/s - gdu_y + s*gdu_x) / (s + 1./s) + 0.5); + s = (double)(newy - gdu_y) / (double)(newx - gdu_x); // slope of line segment + xd = (int) ((ymouse + xmouse/s - gdu_y + s*gdu_x) / (s + 1./s) + 0.5); - // if intersection is beyond either end of the line segment, the nearest point to the - // mouse is nearest segment end, otherwise it's the computed intersection point - if (xd < xmin || xd > xmax) { + // if intersection is beyond either end of the line segment, the nearest point to the + // mouse is nearest segment end, otherwise it's the computed intersection point + if (xd < xmin || xd > xmax) { #ifdef DEBUG_LIGHTPEN - // if it's a hit, set xd and yd so we can display the hit - if (DIST2(gdu_x, gdu_y, xmouse, ymouse) <= lpen_dist2) { - hit = TRUE; - xd = gdu_x; - yd = gdu_y; - } - else if (DIST2(newx, newy, xmouse, ymouse) <= lpen_dist2) { - hit = TRUE; - xd = newx; - yd = newy; - } + // if it's a hit, set xd and yd so we can display the hit + if (DIST2(gdu_x, gdu_y, xmouse, ymouse) <= lpen_dist2) { + hit = TRUE; + xd = gdu_x; + yd = gdu_y; + } + else if (DIST2(newx, newy, xmouse, ymouse) <= lpen_dist2) { + hit = TRUE; + xd = newx; + yd = newy; + } #else - if (DIST2(gdu_x, gdu_y, xmouse, ymouse) <= lpen_dist2 || DIST2(newx, newy, xmouse, ymouse) <= lpen_dist2) - hit = TRUE; + if (DIST2(gdu_x, gdu_y, xmouse, ymouse) <= lpen_dist2 || DIST2(newx, newy, xmouse, ymouse) <= lpen_dist2) + hit = TRUE; #endif - } - else { - yd = (int) (gdu_y + s*(xd - gdu_x) + 0.5); - if (DIST2(xd, yd, xmouse, ymouse) <= lpen_dist2) - hit = TRUE; - } - } - } + } + else { + yd = (int) (gdu_y + s*(xd - gdu_x) + 0.5); + if (DIST2(xd, yd, xmouse, ymouse) <= lpen_dist2) + hit = TRUE; + } + } + } #ifndef DEBUG_LIGHTPEN - } + } #endif - } - } + } + } - if (hit) { + if (hit) { #ifdef DEBUG_LIGHTPEN - ShowPenHit(xd, yd); - if (gdu_unit.flags & UNIT_DETECTS_ENABLED && mouse_present) - SETBIT(gdu_dsw, GDU_DSW_DETECT_STATUS); + ShowPenHit(xd, yd); + if (gdu_unit.flags & UNIT_DETECTS_ENABLED && mouse_present) + SETBIT(gdu_dsw, GDU_DSW_DETECT_STATUS); #else - SETBIT(gdu_dsw, GDU_DSW_DETECT_STATUS); + SETBIT(gdu_dsw, GDU_DSW_DETECT_STATUS); #endif - } + } - gdu_x = (int16) newx; - gdu_y = (int16) newy; + gdu_x = (int16) newx; + gdu_y = (int16) newy; } static void generate_image (void) { - int32 instr, new_addr, newx, newy; - t_bool run = TRUE, accept; + int32 instr, new_addr, newx, newy; + t_bool run = TRUE, accept; - if (! (gdu_dsw & GDU_DSW_BUSY)) - return; + if (! (gdu_dsw & GDU_DSW_BUSY)) + return; - GetMouseCoordinates(); + GetMouseCoordinates(); - lpen_dist = (int) (gdu_threshold/sfactor + 0.5); // mouse-to-line threshhold at current scaling factor - lpen_dist2 = lpen_dist * lpen_dist; + lpen_dist = (int) (gdu_threshold/sfactor + 0.5); // mouse-to-line threshhold at current scaling factor + lpen_dist2 = lpen_dist * lpen_dist; - while (run) { - if ((gdu_dsw & GDU_DSW_DETECT_STATUS) && ! (gdu_unit.flags & UNIT_INTERRUPTS_DEFERRED)) { - CLRBIT(gdu_dsw, GDU_DSW_DETECT_STATUS); // clear when interrupt is activated - gdu_interrupt(GDU_DSW_DETECT_INTERRUPT); - run = FALSE; - break; - } + while (run) { + if ((gdu_dsw & GDU_DSW_DETECT_STATUS) && ! (gdu_unit.flags & UNIT_INTERRUPTS_DEFERRED)) { + CLRBIT(gdu_dsw, GDU_DSW_DETECT_STATUS); // clear when interrupt is activated + gdu_interrupt(GDU_DSW_DETECT_INTERRUPT); + run = FALSE; + break; + } - gdu_instaddr = gdu_ar; // remember address of GDU instruction - instr = read_gduword(); // fetch instruction (and we really are cycle stealing here!) + gdu_instaddr = gdu_ar; // remember address of GDU instruction + instr = read_gduword(); // fetch instruction (and we really are cycle stealing here!) - switch ((instr >> 12) & 0xF) { // decode instruction - case 0: // short branch - case 1: - gdu_revert = gdu_ar; // save revert address & get new address - gdu_ar = (int16) (read_gduword() & 0x1FFF); - if (gdu_dsw & GDU_DSW_CHARACTER_MODE) { - draw_characters(); // in character mode this means we are at character data - gdu_ar = gdu_revert; - } - break; + switch ((instr >> 12) & 0xF) { // decode instruction + case 0: // short branch + case 1: + gdu_revert = gdu_ar; // save revert address & get new address + gdu_ar = (int16) (read_gduword() & 0x1FFF); + if (gdu_dsw & GDU_DSW_CHARACTER_MODE) { + draw_characters(); // in character mode this means we are at character data + gdu_ar = gdu_revert; + } + break; - case 2: // long branch/interrupt - new_addr = read_gduword(); // get next word - accept = ((instr & 1) ? (gdu_dsw & GDU_DSW_LIGHT_PEN_SWITCH) : TRUE) && ((instr & 2) ? (gdu_dsw & GDU_DSW_DETECT_STATUS) : TRUE); + case 2: // long branch/interrupt + new_addr = read_gduword(); // get next word + accept = ((instr & 1) ? (gdu_dsw & GDU_DSW_LIGHT_PEN_SWITCH) : TRUE) && ((instr & 2) ? (gdu_dsw & GDU_DSW_DETECT_STATUS) : TRUE); - if (instr & 2) // clear after testing - CLRBIT(gdu_dsw, GDU_DSW_DETECT_STATUS); + if (instr & 2) // clear after testing + CLRBIT(gdu_dsw, GDU_DSW_DETECT_STATUS); - if (instr & 0x0400) // NOP - accept = FALSE; + if (instr & 0x0400) // NOP + accept = FALSE; - if (accept) { - if (instr & 0x0800) { // branch - gdu_revert = gdu_ar; + if (accept) { + if (instr & 0x0800) { // branch + gdu_revert = gdu_ar; - if (instr & 0x0080) // indirect - new_addr = M[new_addr & mem_mask]; + if (instr & 0x0080) // indirect + new_addr = M[new_addr & mem_mask]; - gdu_ar = (int16) new_addr; + gdu_ar = (int16) new_addr; - if (gdu_dsw & GDU_DSW_CHARACTER_MODE) { - draw_characters(); - gdu_ar = gdu_revert; - } - } - else { // interrupt - gdu_interrupt(GDU_DSW_ORDER_CONTROLLED_INTERRUPT); - run = FALSE; - } - } - break; + if (gdu_dsw & GDU_DSW_CHARACTER_MODE) { + draw_characters(); + gdu_ar = gdu_revert; + } + } + else { // interrupt + gdu_interrupt(GDU_DSW_ORDER_CONTROLLED_INTERRUPT); + run = FALSE; + } + } + break; - case 3: // control instructions - CLRBIT(gdu_dsw, GDU_DSW_CHARACTER_MODE); + case 3: // control instructions + CLRBIT(gdu_dsw, GDU_DSW_CHARACTER_MODE); - switch ((instr >> 8) & 0xF) { - case 1: // set pen mode - if ((instr & 0xC) == 8) - SETBIT(gdu_unit.flags, UNIT_DETECTS_ENABLED); - else if ((instr & 0xC) == 4) - CLRBIT(gdu_unit.flags, UNIT_DETECTS_ENABLED); + switch ((instr >> 8) & 0xF) { + case 1: // set pen mode + if ((instr & 0xC) == 8) + SETBIT(gdu_unit.flags, UNIT_DETECTS_ENABLED); + else if ((instr & 0xC) == 4) + CLRBIT(gdu_unit.flags, UNIT_DETECTS_ENABLED); - if ((instr & 0x3) == 2) - SETBIT(gdu_unit.flags, UNIT_INTERRUPTS_DEFERRED); - else if ((instr & 0x3) == 1) - CLRBIT(gdu_unit.flags, UNIT_INTERRUPTS_DEFERRED); - break; + if ((instr & 0x3) == 2) + SETBIT(gdu_unit.flags, UNIT_INTERRUPTS_DEFERRED); + else if ((instr & 0x3) == 1) + CLRBIT(gdu_unit.flags, UNIT_INTERRUPTS_DEFERRED); + break; - case 2: // set graphic mode - if (instr & 1) - SETBIT(gdu_dsw, GDU_DSW_POINT_MODE); - else - CLRBIT(gdu_dsw, GDU_DSW_POINT_MODE); - break; + case 2: // set graphic mode + if (instr & 1) + SETBIT(gdu_dsw, GDU_DSW_POINT_MODE); + else + CLRBIT(gdu_dsw, GDU_DSW_POINT_MODE); + break; - case 3: // set character mode - SETBIT(gdu_dsw, GDU_DSW_CHARACTER_MODE); - if (instr & 1) - SETBIT(gdu_unit.flags, UNIT_LARGE_CHARS); - else - CLRBIT(gdu_unit.flags, UNIT_LARGE_CHARS); - break; + case 3: // set character mode + SETBIT(gdu_dsw, GDU_DSW_CHARACTER_MODE); + if (instr & 1) + SETBIT(gdu_unit.flags, UNIT_LARGE_CHARS); + else + CLRBIT(gdu_unit.flags, UNIT_LARGE_CHARS); + break; - case 4: // start timer - run = FALSE; // (which, for us, means stop processing until next timer message) - CheckGDUKeyboard(); - break; + case 4: // start timer + run = FALSE; // (which, for us, means stop processing until next timer message) + CheckGDUKeyboard(); + break; - case 5: // store revert - M[gdu_ar & mem_mask] = gdu_revert; - read_gduword(); // skip to next address - break; + case 5: // store revert + M[gdu_ar & mem_mask] = gdu_revert; + read_gduword(); // skip to next address + break; - case 6: // revert - gdu_ar = gdu_revert; - break; + case 6: // revert + gdu_ar = gdu_revert; + break; - default: // all others treated as no-ops - break; - } - break; + default: // all others treated as no-ops + break; + } + break; - case 4: // long absolute - case 5: - CLRBIT(gdu_dsw, GDU_DSW_CHARACTER_MODE); - newx = instr & 0x3FF; - newy = read_gduword() & 0x3FF; - draw(newx, newy, instr & 0x1000); - last_abs = TRUE; - break; + case 4: // long absolute + case 5: + CLRBIT(gdu_dsw, GDU_DSW_CHARACTER_MODE); + newx = instr & 0x3FF; + newy = read_gduword() & 0x3FF; + draw(newx, newy, instr & 0x1000); + last_abs = TRUE; + break; - case 6: // short absolute - case 7: - CLRBIT(gdu_dsw, GDU_DSW_CHARACTER_MODE); - newx = gdu_x; - newy = gdu_y; - if (instr & 0x0800) - newy = instr & 0x3FF; - else - newx = instr & 0x3FF; - draw(newx, newy, instr & 0x1000); - last_abs = TRUE; - break; + case 6: // short absolute + case 7: + CLRBIT(gdu_dsw, GDU_DSW_CHARACTER_MODE); + newx = gdu_x; + newy = gdu_y; + if (instr & 0x0800) + newy = instr & 0x3FF; + else + newx = instr & 0x3FF; + draw(newx, newy, instr & 0x1000); + last_abs = TRUE; + break; - default: // high bit set - it's a relative instruction - CLRBIT(gdu_dsw, GDU_DSW_CHARACTER_MODE); - newx = (instr >> 8) & 0x3F; - newy = instr & 0x3F; + default: // high bit set - it's a relative instruction + CLRBIT(gdu_dsw, GDU_DSW_CHARACTER_MODE); + newx = (instr >> 8) & 0x3F; + newy = instr & 0x3F; - if (instr & 0x4000) // sign extend x - values are in 2's complement - newx |= -1 & ~0x3F; // although documentation doesn't make that clear + if (instr & 0x4000) // sign extend x - values are in 2's complement + newx |= -1 & ~0x3F; // although documentation doesn't make that clear - if (instr & 0x0040) // sign extend y - newy |= -1 & ~0x3F; + if (instr & 0x0040) // sign extend y + newy |= -1 & ~0x3F; - newx = gdu_x + newx; - newy = gdu_y + newy; - draw(newx, newy, instr & 0x0080); - last_abs = FALSE; - break; - } - } + newx = gdu_x + newx; + newy = gdu_y + newy; + draw(newx, newy, instr & 0x0080); + last_abs = FALSE; + break; + } + } } -static struct charinfo { // character mode scaling info: - int dx, dy; // character and line spacing - double sx, sy; // scaling factors: character units to screen units - int xoff, yoff; // x and y offset to lower left corner of character - int suby; // subscript/superscript offset +static struct charinfo { // character mode scaling info: + int dx, dy; // character and line spacing + double sx, sy; // scaling factors: character units to screen units + int xoff, yoff; // x and y offset to lower left corner of character + int suby; // subscript/superscript offset } cx[2] = { - {14, 20, 1.7, 2.0, -6, -7, 6}, // regular - {21, 30, 2.5, 3.0, -9, -11, 9} // large + {14, 20, 1.7, 2.0, -6, -7, 6}, // regular + {21, 30, 2.5, 3.0, -9, -11, 9} // large }; static void draw_characters (void) { - int32 w, x0, y0, x1, y1, yoff = 0, ninstr = 0; - t_bool dospace, didstroke = FALSE; - struct charinfo *ci; + int32 w, x0, y0, x1, y1, yoff = 0, ninstr = 0; + t_bool dospace, didstroke = FALSE; + struct charinfo *ci; - ci = &cx[(gdu_unit.flags & UNIT_LARGE_CHARS) ? 1 : 0]; - x0 = gdu_x + ci->xoff; // starting position - y0 = gdu_y + ci->yoff; + ci = &cx[(gdu_unit.flags & UNIT_LARGE_CHARS) ? 1 : 0]; + x0 = gdu_x + ci->xoff; // starting position + y0 = gdu_y + ci->yoff; - do { - if (++ninstr > 29) { // too many control words - gdu_interrupt(GDU_DSW_CYCLE_STEAL_CHECK); - return; - } + do { + if (++ninstr > 29) { // too many control words + gdu_interrupt(GDU_DSW_CYCLE_STEAL_CHECK); + return; + } - dospace = TRUE; - w = M[gdu_ar++ & mem_mask]; // get next stroke or control word + dospace = TRUE; + w = M[gdu_ar++ & mem_mask]; // get next stroke or control word - x1 = (w >> 12) & 7; - y1 = (w >> 8) & 7; + x1 = (w >> 12) & 7; + y1 = (w >> 8) & 7; - if (x1 == 7) { // this is a character control word - dospace = FALSE; // inhibit character spacing + if (x1 == 7) { // this is a character control word + dospace = FALSE; // inhibit character spacing - switch (y1) { - case 1: // subscript - if (yoff == 0) // (ignored if superscript is in effect) - yoff = -ci->suby; - break; + switch (y1) { + case 1: // subscript + if (yoff == 0) // (ignored if superscript is in effect) + yoff = -ci->suby; + break; -// case 2: // no-op or null (nothing to do) -// default: // all unknowns are no-ops -// break; +// case 2: // no-op or null (nothing to do) +// default: // all unknowns are no-ops +// break; - case 4: // superscript - yoff = ci->suby; - break; + case 4: // superscript + yoff = ci->suby; + break; - case 7: // new line - gdu_x = 0; - gdu_y -= (int16) ci->dy; - if (gdu_y < 0 && last_abs) - gdu_y = (int16) (1024 - ci->dy); // this is a guess - break; - } - } - else { // this is stroke data -- extract two strokes - x1 = gdu_x + (int) (x1*ci->sx + 0.5); - y1 = gdu_y + (int) ((y1+yoff)*ci->sy + 0.5); + case 7: // new line + gdu_x = 0; + gdu_y -= (int16) ci->dy; + if (gdu_y < 0 && last_abs) + gdu_y = (int16) (1024 - ci->dy); // this is a guess + break; + } + } + else { // this is stroke data -- extract two strokes + x1 = gdu_x + (int) (x1*ci->sx + 0.5); + y1 = gdu_y + (int) ((y1+yoff)*ci->sy + 0.5); - if (w & 0x0800) { - didstroke = TRUE; - DrawLine(x0, y0, x1, y1); - } + if (w & 0x0800) { + didstroke = TRUE; + DrawLine(x0, y0, x1, y1); + } - x0 = (w >> 4) & 7; - y0 = w & 7; + x0 = (w >> 4) & 7; + y0 = w & 7; - x0 = gdu_x + (int) (x0*ci->sx + 0.5); - y0 = gdu_y + (int) ((y0+yoff)*ci->sy + 0.5); + x0 = gdu_x + (int) (x0*ci->sx + 0.5); + y0 = gdu_y + (int) ((y0+yoff)*ci->sy + 0.5); - if (w & 0x0008) { - didstroke = TRUE; - DrawLine(x1, y1, x0, y0); - } - } + if (w & 0x0008) { + didstroke = TRUE; + DrawLine(x1, y1, x0, y0); + } + } - if (dospace) { - gdu_x += ci->dx; - if (gdu_x > 1023 && last_abs) { // line wrap - gdu_x = 0; - gdu_y -= (int16) ci->dy; - } - } - } while ((w & 0x0080) == 0); // repeat until we hit revert bit + if (dospace) { + gdu_x += ci->dx; + if (gdu_x > 1023 && last_abs) { // line wrap + gdu_x = 0; + gdu_y -= (int16) ci->dy; + } + } + } while ((w & 0x0080) == 0); // repeat until we hit revert bit - if (didstroke && mouse_present && (gdu_unit.flags & UNIT_DETECTS_ENABLED)) { - if (xmouse >= (gdu_x - ci->xoff/2) && xmouse <= (gdu_x + ci->xoff/2) && - ymouse >= (gdu_y - ci->yoff/2) && ymouse <= (gdu_y + ci->yoff/2)) - SETBIT(gdu_dsw, GDU_DSW_DETECT_STATUS); - } + if (didstroke && mouse_present && (gdu_unit.flags & UNIT_DETECTS_ENABLED)) { + if (xmouse >= (gdu_x - ci->xoff/2) && xmouse <= (gdu_x + ci->xoff/2) && + ymouse >= (gdu_y - ci->yoff/2) && ymouse <= (gdu_y + ci->yoff/2)) + SETBIT(gdu_dsw, GDU_DSW_DETECT_STATUS); + } } /******* PLATFORM SPECIFIC CODE ***********************************************************/ @@ -657,9 +657,9 @@ static void draw_characters (void) #include #include -#define APPCLASS "IBM2250GDU" // window class name +#define APPCLASS "IBM2250GDU" // window class name -#define RGB_GREEN RGB(0,255,0) // handy colors +#define RGB_GREEN RGB(0,255,0) // handy colors #define RGB_RED RGB(255,0,0) static HINSTANCE hInstance; @@ -678,7 +678,7 @@ static HPEN hRedPen = NULL; #endif static HBRUSH hGrayBrush, hDarkBrush; static HPEN hBlackPen; -static int halted = 0; // number of time intervals that GDU has been halted w/o a regeneration +static int halted = 0; // number of time intervals that GDU has been halted w/o a regeneration static UINT idTimer = 0; static t_bool painting = FALSE; static LRESULT APIENTRY GDUWndProc (HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam); @@ -686,62 +686,62 @@ static DWORD WINAPI GDUPump (LPVOID arg); static void destroy_GDU_window (void) { - if (hwGDU != NULL) - SendMessage(hwGDU, WM_CLOSE, 0, 0); // cross thread call is OK + if (hwGDU != NULL) + SendMessage(hwGDU, WM_CLOSE, 0, 0); // cross thread call is OK #ifdef XXXX - // let window closure do this - if (hGDUPump != INVALID_HANDLE_VALUE) { // this is not the most graceful way to do it - TerminateThread(hGDUPump, 0); - hGDUPump = INVALID_HANDLE_VALUE; - GDUPumpID = 0; - hwGDU = NULL; - } + // let window closure do this + if (hGDUPump != INVALID_HANDLE_VALUE) { // this is not the most graceful way to do it + TerminateThread(hGDUPump, 0); + hGDUPump = INVALID_HANDLE_VALUE; + GDUPumpID = 0; + hwGDU = NULL; + } - if (hdcGDU != NULL) { - DeleteDC(hdcGDU); - hdcGDU = NULL; - } + if (hdcGDU != NULL) { + DeleteDC(hdcGDU); + hdcGDU = NULL; + } - if (hBmp != NULL) { - DeleteObject(hBmp); - hBmp = NULL; - } + if (hBmp != NULL) { + DeleteObject(hBmp); + hBmp = NULL; + } - if (hGreenPen != NULL) { - DeleteObject(hGreenPen); - hGreenPen = NULL; - } + if (hGreenPen != NULL) { + DeleteObject(hGreenPen); + hGreenPen = NULL; + } - if (hRedBrush != NULL) { - DeleteObject(hRedBrush); - hRedBrush = NULL; - } + if (hRedBrush != NULL) { + DeleteObject(hRedBrush); + hRedBrush = NULL; + } #endif #ifdef DEBUG_LIGHTPEN - if (hRedPen != NULL) { - DeleteObject(hRedPen); - hRedPen = NULL; - } + if (hRedPen != NULL) { + DeleteObject(hRedPen); + hRedPen = NULL; + } #endif } static t_bool CreateGDUWindow (void) { - static BOOL did_atexit = FALSE; + static BOOL did_atexit = FALSE; - hInstance = GetModuleHandle(NULL); + hInstance = GetModuleHandle(NULL); - if (hGDUPump == INVALID_HANDLE_VALUE) - hGDUPump = CreateThread(NULL, 0, GDUPump, 0, 0, &GDUPumpID); + if (hGDUPump == INVALID_HANDLE_VALUE) + hGDUPump = CreateThread(NULL, 0, GDUPump, 0, 0, &GDUPumpID); - if (! did_atexit) { - atexit(destroy_GDU_window); - did_atexit = TRUE; - } + if (! did_atexit) { + atexit(destroy_GDU_window); + did_atexit = TRUE; + } - return TRUE; + return TRUE; } // windows message handlers ---------------------------------------------------- @@ -750,150 +750,150 @@ static t_bool CreateGDUWindow (void) static void gdu_WM_CLOSE (HWND hWnd) { - DestroyWindow(hWnd); + DestroyWindow(hWnd); } // the window is being destroyed static void gdu_WM_DESTROY (HWND hWnd) { - PostMessage(hWnd, WM_QUIT, 0, 0); - if (idTimer != 0) { - KillTimer(hwGDU, 1); - idTimer = 0; - halted = 10000; - painting = FALSE; - } - notify_window_closed(); - hwGDU = NULL; + PostMessage(hWnd, WM_QUIT, 0, 0); + if (idTimer != 0) { + KillTimer(hwGDU, 1); + idTimer = 0; + halted = 10000; + painting = FALSE; + } + notify_window_closed(); + hwGDU = NULL; } // adjust the min and max resizing boundaries static void gdu_WM_GETMINMAXINFO (HWND hWnd, LPMINMAXINFO mm) { - mm->ptMinTrackSize.x = 100 + 2*INDWIDTH; - mm->ptMinTrackSize.y = 100; + mm->ptMinTrackSize.x = 100 + 2*INDWIDTH; + mm->ptMinTrackSize.y = 100; } static void PaintImage (HDC hDC, BOOL draw_indicators) { - HPEN hOldPen; - RECT r; - int wid, ht, x, y, dy, i, j, ycirc; - unsigned long bit; + HPEN hOldPen; + RECT r; + int wid, ht, x, y, dy, i, j, ycirc; + unsigned long bit; - GetClientRect(hwGDU, &r); - wid = r.right+1 - 2*INDWIDTH; - ht = r.bottom+1; - sfactor = (double) MIN(wid,ht) / 1024.; + GetClientRect(hwGDU, &r); + wid = r.right+1 - 2*INDWIDTH; + ht = r.bottom+1; + sfactor = (double) MIN(wid,ht) / 1024.; - if (gdu_dsw & GDU_DSW_BUSY) { + if (gdu_dsw & GDU_DSW_BUSY) { #ifdef BLIT_MODE - // if compiled for BLIT_MODE, draw the image into a memory display context, then - // blit the new image over window. This eliminates the flicker that a normal erase-and- - // repaint would cause. + // if compiled for BLIT_MODE, draw the image into a memory display context, then + // blit the new image over window. This eliminates the flicker that a normal erase-and- + // repaint would cause. - if (wid != curwid || ht != curht) { // dimensions have changed, discard old memory display context - if (hdcGDU != NULL) { - DeleteDC(hdcGDU); - hdcGDU = NULL; - } - curwid = wid; - curht = ht; - } + if (wid != curwid || ht != curht) { // dimensions have changed, discard old memory display context + if (hdcGDU != NULL) { + DeleteDC(hdcGDU); + hdcGDU = NULL; + } + curwid = wid; + curht = ht; + } - if (hdcGDU == NULL) { // allocate memory display context & select a bitmap into it - hdcGDU = CreateCompatibleDC(hDC); - if (hBmp != NULL) - DeleteObject(hBmp); - hBmp = CreateCompatibleBitmap(hDC, wid, ht); - SelectObject(hdcGDU, hBmp); - } + if (hdcGDU == NULL) { // allocate memory display context & select a bitmap into it + hdcGDU = CreateCompatibleDC(hDC); + if (hBmp != NULL) + DeleteObject(hBmp); + hBmp = CreateCompatibleBitmap(hDC, wid, ht); + SelectObject(hdcGDU, hBmp); + } - PatBlt(hdcGDU, 0, 0, wid, ht, BLACKNESS); // start with a black screen + PatBlt(hdcGDU, 0, 0, wid, ht, BLACKNESS); // start with a black screen - hOldPen = SelectObject(hdcGDU, hGreenPen); + hOldPen = SelectObject(hdcGDU, hGreenPen); - SetMapMode(hdcGDU, MM_ANISOTROPIC); - SetWindowExtEx(hdcGDU, 1024, -1024, NULL); - SetViewportExtEx(hdcGDU, wid, ht, NULL); - SetWindowOrgEx(hdcGDU, 0, 1023, NULL); + SetMapMode(hdcGDU, MM_ANISOTROPIC); + SetWindowExtEx(hdcGDU, 1024, -1024, NULL); + SetViewportExtEx(hdcGDU, wid, ht, NULL); + SetWindowOrgEx(hdcGDU, 0, 1023, NULL); - generate_image(); // run the display program to paint the image into the memory context + generate_image(); // run the display program to paint the image into the memory context - SetWindowExtEx(hdcGDU, wid, ht, NULL); // undo the scaling so the blit isn't distorted - SetViewportExtEx(hdcGDU, wid, ht, NULL); - SetWindowOrgEx(hdcGDU, 0, 0, NULL); - BitBlt(hDC, 0, 0, wid, ht, hdcGDU, 0, 0, SRCCOPY); // blit the new image over the old + SetWindowExtEx(hdcGDU, wid, ht, NULL); // undo the scaling so the blit isn't distorted + SetViewportExtEx(hdcGDU, wid, ht, NULL); + SetWindowOrgEx(hdcGDU, 0, 0, NULL); + BitBlt(hDC, 0, 0, wid, ht, hdcGDU, 0, 0, SRCCOPY); // blit the new image over the old - SelectObject(hdcGDU, hOldPen); + SelectObject(hdcGDU, hOldPen); #else - // for testing purposes -- draw the image directly onto the screen. - // Compile this way when you want to single-step through the image drawing routine, - // so you can see the draws occur. - hdcGDU = hDC; - hOldPen = SelectObject(hdcGDU, hGreenPen); + // for testing purposes -- draw the image directly onto the screen. + // Compile this way when you want to single-step through the image drawing routine, + // so you can see the draws occur. + hdcGDU = hDC; + hOldPen = SelectObject(hdcGDU, hGreenPen); - SetMapMode(hdcGDU, MM_ANISOTROPIC); - SetWindowExtEx(hdcGDU, 1024, -1024, NULL); - SetViewportExtEx(hdcGDU, wid, ht, NULL); - SetWindowOrgEx(hdcGDU, 0, 1023, NULL); + SetMapMode(hdcGDU, MM_ANISOTROPIC); + SetWindowExtEx(hdcGDU, 1024, -1024, NULL); + SetViewportExtEx(hdcGDU, wid, ht, NULL); + SetWindowOrgEx(hdcGDU, 0, 1023, NULL); - generate_image(); + generate_image(); - SelectObject(hdcGDU, hOldPen); - hdcGDU = NULL; + SelectObject(hdcGDU, hOldPen); + hdcGDU = NULL; #endif - } + } - if (draw_indicators) { - x = r.right-2*INDWIDTH+1; - dy = ht / 16; - ycirc = MIN(dy-2, 8); + if (draw_indicators) { + x = r.right-2*INDWIDTH+1; + dy = ht / 16; + ycirc = MIN(dy-2, 8); - r.left = x; - FillRect(hDC, &r, hGrayBrush); - SelectObject(hDC, hBlackPen); + r.left = x; + FillRect(hDC, &r, hGrayBrush); + SelectObject(hDC, hBlackPen); - bit = 0x80000000L; - for (i = 0; i < 2; i++) { - MoveToEx(hDC, x, 0, NULL); - LineTo(hDC, x, r.bottom); - y = 0; - for (j = 0; j < 16; j++) { - MoveToEx(hDC, x, y, NULL); - LineTo(hDC, x+INDWIDTH, y); + bit = 0x80000000L; + for (i = 0; i < 2; i++) { + MoveToEx(hDC, x, 0, NULL); + LineTo(hDC, x, r.bottom); + y = 0; + for (j = 0; j < 16; j++) { + MoveToEx(hDC, x, y, NULL); + LineTo(hDC, x+INDWIDTH, y); - SelectObject(hDC, (gdu_indicators & bit) ? hRedBrush : hDarkBrush); - Pie(hDC, x+1, y+1, x+1+ycirc, y+1+ycirc, x+1, y+1, x+1, y+1); + SelectObject(hDC, (gdu_indicators & bit) ? hRedBrush : hDarkBrush); + Pie(hDC, x+1, y+1, x+1+ycirc, y+1+ycirc, x+1, y+1, x+1, y+1); - y += dy; - bit >>= 1; - } - x += INDWIDTH; - } - } + y += dy; + bit >>= 1; + } + x += INDWIDTH; + } + } } // repaint the window static void gdu_WM_PAINT (HWND hWnd) { - PAINTSTRUCT ps; - HDC hDC; - int msec; + PAINTSTRUCT ps; + HDC hDC; + int msec; - // code for display - hDC = BeginPaint(hWnd, &ps); - PaintImage(hDC, TRUE); - EndPaint(hWnd, &ps); + // code for display + hDC = BeginPaint(hWnd, &ps); + PaintImage(hDC, TRUE); + EndPaint(hWnd, &ps); - // set a timer so we keep doing it! - if (idTimer == 0) { - msec = (gdu_rate == 0) ? (1000 / DEFAULT_GDU_RATE) : 1000/gdu_rate; - idTimer = SetTimer(hwGDU, 1, msec, NULL); - } + // set a timer so we keep doing it! + if (idTimer == 0) { + msec = (gdu_rate == 0) ? (1000 / DEFAULT_GDU_RATE) : 1000/gdu_rate; + idTimer = SetTimer(hwGDU, 1, msec, NULL); + } } // the window has been resized @@ -901,9 +901,9 @@ static void gdu_WM_PAINT (HWND hWnd) static void gdu_WM_SIZE (HWND hWnd, UINT state, int cx, int cy) { #ifdef BLIT_MODE - InvalidateRect(hWnd, NULL, FALSE); // in blt mode, we'll paint a full black bitmap over the new screen size + InvalidateRect(hWnd, NULL, FALSE); // in blt mode, we'll paint a full black bitmap over the new screen size #else - InvalidateRect(hWnd, NULL, TRUE); + InvalidateRect(hWnd, NULL, TRUE); #endif } @@ -911,56 +911,56 @@ static void gdu_WM_SIZE (HWND hWnd, UINT state, int cx, int cy) static void gdu_WM_SIZING (HWND hWnd, WPARAM fwSide, LPRECT r) { - switch (fwSide) { - case WMSZ_LEFT: + switch (fwSide) { + case WMSZ_LEFT: case WMSZ_RIGHT: case WMSZ_BOTTOMLEFT: case WMSZ_BOTTOMRIGHT: - r->bottom = r->right - r->left - 2*INDWIDTH + r->top; - break; + r->bottom = r->right - r->left - 2*INDWIDTH + r->top; + break; case WMSZ_TOP: case WMSZ_BOTTOM: case WMSZ_TOPRIGHT: - r->right = r->bottom - r->top + r->left + 2*INDWIDTH; - break; + r->right = r->bottom - r->top + r->left + 2*INDWIDTH; + break; case WMSZ_TOPLEFT: - r->left = r->top - r->bottom + r->right - 2*INDWIDTH; - break; - } + r->left = r->top - r->bottom + r->right - 2*INDWIDTH; + break; + } } // the refresh timer has gone off static void gdu_WM_TIMER (HWND hWnd, UINT id) { - HDC hDC; + HDC hDC; - if (painting) { // if GDU is running, update picture - if ((gdu_dsw & GDU_DSW_BUSY) == 0) { // regeneration is not to occur - if (++halted >= 4) { // stop the timer if four timer intervals go by with the display halted - EraseGDUScreen(); // screen goes black due to cessation of refreshing - StopGDUUpdates(); // might as well kill the timer - return; - } - } - else - halted = 0; + if (painting) { // if GDU is running, update picture + if ((gdu_dsw & GDU_DSW_BUSY) == 0) { // regeneration is not to occur + if (++halted >= 4) { // stop the timer if four timer intervals go by with the display halted + EraseGDUScreen(); // screen goes black due to cessation of refreshing + StopGDUUpdates(); // might as well kill the timer + return; + } + } + else + halted = 0; #ifdef BLIT_MODE - hDC = GetDC(hWnd); // blit the new image right over the old - PaintImage(hDC, FALSE); - ReleaseDC(hWnd, hDC); + hDC = GetDC(hWnd); // blit the new image right over the old + PaintImage(hDC, FALSE); + ReleaseDC(hWnd, hDC); #else - InvalidateRect(hWnd, NULL, TRUE); // repaint + InvalidateRect(hWnd, NULL, TRUE); // repaint #endif } } // window procedure ------------------------------------------------------------ -#define HANDLE(msg) case msg: return HANDLE_##msg(hWnd, wParam, lParam, gdu_##msg); +#define HANDLE(msg) case msg: return HANDLE_##msg(hWnd, wParam, lParam, gdu_##msg); #ifndef HANDLE_WM_SIZING // void Cls_OnSizing(HWND hwnd, UINT fwSide, LPRECT r) @@ -970,176 +970,176 @@ static void gdu_WM_TIMER (HWND hWnd, UINT id) static LRESULT APIENTRY GDUWndProc (HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam) { - switch (iMessage) { - HANDLE(WM_CLOSE); - HANDLE(WM_GETMINMAXINFO); - HANDLE(WM_DESTROY); - HANDLE(WM_PAINT); - HANDLE(WM_SIZE); - HANDLE(WM_SIZING); - HANDLE(WM_TIMER); - default: // any message we don't process - return DefWindowProc(hWnd, iMessage, wParam, lParam); - } - return 0L; + switch (iMessage) { + HANDLE(WM_CLOSE); + HANDLE(WM_GETMINMAXINFO); + HANDLE(WM_DESTROY); + HANDLE(WM_PAINT); + HANDLE(WM_SIZE); + HANDLE(WM_SIZING); + HANDLE(WM_TIMER); + default: // any message we don't process + return DefWindowProc(hWnd, iMessage, wParam, lParam); + } + return 0L; } // graphic calls ---------------------------------------------------------------- -static void DrawLine (int x0, int y0, int x1, int y1) +static void DrawLine (int x0, int y0, int x1, int y1) { - MoveToEx(hdcGDU, x0, y0, NULL); - LineTo(hdcGDU, x1, y1); + MoveToEx(hdcGDU, x0, y0, NULL); + LineTo(hdcGDU, x1, y1); } -static void DrawPoint (int x, int y) +static void DrawPoint (int x, int y) { - SetPixel(hdcGDU, x, y, RGB_GREEN); + SetPixel(hdcGDU, x, y, RGB_GREEN); } static void UpdateGDUIndicators(void) { - if (hwGDU != NULL) - InvalidateRect(hwGDU, NULL, FALSE); // no need to erase the background -- the draw routine fully paints the indicator + if (hwGDU != NULL) + InvalidateRect(hwGDU, NULL, FALSE); // no need to erase the background -- the draw routine fully paints the indicator } static void CheckGDUKeyboard (void) { } -static void StartGDUUpdates (void) +static void StartGDUUpdates (void) { - halted = 0; - painting = TRUE; + halted = 0; + painting = TRUE; } -static void StopGDUUpdates (void) +static void StopGDUUpdates (void) { - painting = FALSE; + painting = FALSE; } static void GetMouseCoordinates() { - POINT p; - RECT r; + POINT p; + RECT r; - GetCursorPos(&p); - GetClientRect(hwGDU, &r); - if (! ScreenToClient(hwGDU, &p)) { - xmouse = ymouse = -2000; - mouse_present = FALSE; - return; - } + GetCursorPos(&p); + GetClientRect(hwGDU, &r); + if (! ScreenToClient(hwGDU, &p)) { + xmouse = ymouse = -2000; + mouse_present = FALSE; + return; + } - if (p.x < r.left || p.x >= r.right || p.y < r.top || p.y > r.bottom) { - mouse_present = FALSE; - return; - } + if (p.x < r.left || p.x >= r.right || p.y < r.top || p.y > r.bottom) { + mouse_present = FALSE; + return; + } - // convert mouse coordinates to scaled coordinates + // convert mouse coordinates to scaled coordinates - xmouse = (int) (1024./(r.right+1.-2*INDWIDTH)*p.x + 0.5); - ymouse = 1023 - (int) (1024./(r.bottom+1.)*p.y + 0.5); - mouse_present = TRUE; + xmouse = (int) (1024./(r.right+1.-2*INDWIDTH)*p.x + 0.5); + ymouse = 1023 - (int) (1024./(r.bottom+1.)*p.y + 0.5); + mouse_present = TRUE; } t_bool gdu_active (void) { - return cgi ? 0 : (gdu_dsw & GDU_DSW_BUSY); + return cgi ? 0 : (gdu_dsw & GDU_DSW_BUSY); } static void EraseGDUScreen (void) { - if (hwGDU != NULL) /* redraw screen. it will be blank if GDU is not running */ - InvalidateRect(hwGDU, NULL, TRUE); + if (hwGDU != NULL) /* redraw screen. it will be blank if GDU is not running */ + InvalidateRect(hwGDU, NULL, TRUE); } /* GDUPump - thread responsible for creating and displaying the graphics window */ static DWORD WINAPI GDUPump (LPVOID arg) { - MSG msg; - WNDCLASS wc; + MSG msg; + WNDCLASS wc; - if (! wcInited) { /* register Window class */ - memset(&wc, 0, sizeof(wc)); - wc.style = CS_NOCLOSE; - wc.lpfnWndProc = GDUWndProc; - wc.hInstance = hInstance; - wc.hCursor = LoadCursor(NULL, IDC_ARROW); - wc.hbrBackground = GetStockObject(BLACK_BRUSH); - wc.lpszClassName = APPCLASS; + if (! wcInited) { /* register Window class */ + memset(&wc, 0, sizeof(wc)); + wc.style = CS_NOCLOSE; + wc.lpfnWndProc = GDUWndProc; + wc.hInstance = hInstance; + wc.hCursor = LoadCursor(NULL, IDC_ARROW); + wc.hbrBackground = GetStockObject(BLACK_BRUSH); + wc.lpszClassName = APPCLASS; - if (! RegisterClass(&wc)) { - GDUPumpID = 0; - return 0; - } + if (! RegisterClass(&wc)) { + GDUPumpID = 0; + return 0; + } - wcInited = TRUE; - } + wcInited = TRUE; + } - if (hGreenPen == NULL) - hGreenPen = CreatePen(PS_SOLID, 1, RGB_GREEN); + if (hGreenPen == NULL) + hGreenPen = CreatePen(PS_SOLID, 1, RGB_GREEN); #ifdef DEBUG_LIGHTPEN - if (hRedPen == NULL) - hRedPen = CreatePen(PS_SOLID, 1, RGB_RED); + if (hRedPen == NULL) + hRedPen = CreatePen(PS_SOLID, 1, RGB_RED); #endif - if (hRedBrush == NULL) - hRedBrush = CreateSolidBrush(RGB_RED); + if (hRedBrush == NULL) + hRedBrush = CreateSolidBrush(RGB_RED); - hGrayBrush = GetStockObject(GRAY_BRUSH); - hDarkBrush = GetStockObject(DKGRAY_BRUSH); - hBlackPen = GetStockObject(BLACK_PEN); + hGrayBrush = GetStockObject(GRAY_BRUSH); + hDarkBrush = GetStockObject(DKGRAY_BRUSH); + hBlackPen = GetStockObject(BLACK_PEN); - if (hwGDU == NULL) { /* create window */ - hwGDU = CreateWindow(APPCLASS, - "2250 Display", - WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN, - CW_USEDEFAULT, CW_USEDEFAULT, // initial x, y position - INITSIZE+2*INDWIDTH, INITSIZE, // initial width and height - NULL, // parent window handle - NULL, // use class menu - hInstance, // program instance handle - NULL); // create parameters + if (hwGDU == NULL) { /* create window */ + hwGDU = CreateWindow(APPCLASS, + "2250 Display", + WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN, + CW_USEDEFAULT, CW_USEDEFAULT, // initial x, y position + INITSIZE+2*INDWIDTH, INITSIZE, // initial width and height + NULL, // parent window handle + NULL, // use class menu + hInstance, // program instance handle + NULL); // create parameters - if (hwGDU == NULL) { - GDUPumpID = 0; - return 0; - } - } + if (hwGDU == NULL) { + GDUPumpID = 0; + return 0; + } + } - ShowWindow(hwGDU, SW_SHOWNOACTIVATE); /* display it */ - UpdateWindow(hwGDU); - - while (GetMessage(&msg, hwGDU, 0, 0)) { /* message pump - this basically loops forevermore */ - TranslateMessage(&msg); - DispatchMessage(&msg); - } + ShowWindow(hwGDU, SW_SHOWNOACTIVATE); /* display it */ + UpdateWindow(hwGDU); + + while (GetMessage(&msg, hwGDU, 0, 0)) { /* message pump - this basically loops forevermore */ + TranslateMessage(&msg); + DispatchMessage(&msg); + } - painting = FALSE; + painting = FALSE; - if (hwGDU != NULL) { - DestroyWindow(hwGDU); /* but if a quit message got posted, clean up */ - hwGDU = NULL; - } + if (hwGDU != NULL) { + DestroyWindow(hwGDU); /* but if a quit message got posted, clean up */ + hwGDU = NULL; + } - GDUPumpID = 0; - return 0; + GDUPumpID = 0; + return 0; } #ifdef DEBUG_LIGHTPEN static void ShowPenHit (int x, int y) { - HPEN hOldPen; + HPEN hOldPen; - hOldPen = SelectObject(hdcGDU, hRedPen); - DrawLine(x-10, y-10, x+10, y+10); - DrawLine(x-10, y+10, x+10, y-10); - SelectObject(hdcGDU, hOldPen); + hOldPen = SelectObject(hdcGDU, hRedPen); + DrawLine(x-10, y-10, x+10, y+10); + DrawLine(x-10, y+10, x+10, y-10); + SelectObject(hdcGDU, hOldPen); } #endif -#endif // _WIN32 defined -#endif // GUI_SUPPORT defined +#endif // _WIN32 defined +#endif // GUI_SUPPORT defined diff --git a/Ibm1130/ibm1130_gui.c b/Ibm1130/ibm1130_gui.c index e17b8f49..7b9363be 100644 --- a/Ibm1130/ibm1130_gui.c +++ b/Ibm1130/ibm1130_gui.c @@ -11,16 +11,16 @@ * This is not a supported product, but I welcome bug reports and fixes. * Mail to simh@ibm1130.org * - * 30-Dec-05 BLK Fixed mask for IAR and SAR register display and added display - * of Arithmetic Factor, per Carl Claunch. + * 30-Dec-05 BLK Fixed mask for IAR and SAR register display and added display + * of Arithmetic Factor, per Carl Claunch. * - * 09-Apr-04 BLK Changed code to use stock windows cursor IDC_HAND if available + * 09-Apr-04 BLK Changed code to use stock windows cursor IDC_HAND if available * - * 02-Dec-02 BLK Changed display, added printer and card reader icons - * Added drag and drop support for scripts and card decks - * Added support for physical card reader and printer (hides icons) + * 02-Dec-02 BLK Changed display, added printer and card reader icons + * Added drag and drop support for scripts and card decks + * Added support for physical card reader and printer (hides icons) * - * 17-May-02 BLK Pulled out of ibm1130_cpu.c + * 17-May-02 BLK Pulled out of ibm1130_cpu.c */ /* ------------------------------------------------------------------------ @@ -37,17 +37,17 @@ #define UPDATE_BY_TIMER #ifdef UPDATE_BY_TIMER -# define UPDATE_INTERVAL 20 /* set to desired number of updates/second */ +# define UPDATE_INTERVAL 20 /* set to desired number of updates/second */ #else -# define UPDATE_INTERVAL 5000 /* GUI: set to 100000/f where f = desired updates/second of 1130 time */ +# define UPDATE_INTERVAL 5000 /* GUI: set to 100000/f where f = desired updates/second of 1130 time */ #endif -#define UNIT_V_CR_EMPTY (UNIT_V_UF + 5) /* NOTE: THESE MUST MATCH THE DEFINITION IN ibm1130_cr.c */ -#define UNIT_CR_EMPTY (1u << UNIT_V_CR_EMPTY) -#define UNIT_V_PHYSICAL (UNIT_V_UF + 9) -#define UNIT_PHYSICAL (1u << UNIT_V_PHYSICAL) +#define UNIT_V_CR_EMPTY (UNIT_V_UF + 5) /* NOTE: THESE MUST MATCH THE DEFINITION IN ibm1130_cr.c */ +#define UNIT_CR_EMPTY (1u << UNIT_V_CR_EMPTY) +#define UNIT_V_PHYSICAL (UNIT_V_UF + 9) +#define UNIT_PHYSICAL (1u << UNIT_V_PHYSICAL) -#define UNIT_V_PHYSICAL_PTR (UNIT_V_UF + 10) /* NOTE: THESE MUST MATCH THE DEFINITION IN ibm1130_prt.c */ +#define UNIT_V_PHYSICAL_PTR (UNIT_V_UF + 10) /* NOTE: THESE MUST MATCH THE DEFINITION IN ibm1130_prt.c */ #define UNIT_PHYSICAL_PTR (1u << UNIT_V_PHYSICAL_PTR) /* I think I had it wrong; Program Load actually does start the processor after @@ -74,107 +74,107 @@ t_stat console_reset (DEVICE *dptr); * ------------------------------------------------------------------------ */ #define UNIT_V_DISPLAY (UNIT_V_UF + 0) -#define UNIT_DISPLAY (1u << UNIT_V_DISPLAY) +#define UNIT_DISPLAY (1u << UNIT_V_DISPLAY) MTAB console_mod[] = { - { UNIT_DISPLAY, 0, "off", "OFF", NULL }, - { UNIT_DISPLAY, UNIT_DISPLAY, "on", "ON", NULL }, - { 0 } + { UNIT_DISPLAY, 0, "off", "OFF", NULL }, + { UNIT_DISPLAY, UNIT_DISPLAY, "on", "ON", NULL }, + { 0 } }; UNIT console_unit = {UDATA (NULL, UNIT_DISABLE|UNIT_DISPLAY, 0) }; DEVICE console_dev = { - "GUI", &console_unit, NULL, console_mod, - 1, 16, 16, 1, 16, 16, - NULL, NULL, console_reset, - NULL, NULL, NULL + "GUI", &console_unit, NULL, console_mod, + 1, 16, 16, 1, 16, 16, + NULL, NULL, console_reset, + NULL, NULL, NULL }; /* reset for the "console" display device */ -extern UNIT cr_unit; /* pointers to 1442 and 1132 (1403) printers */ +extern UNIT cr_unit; /* pointers to 1442 and 1132 (1403) printers */ extern UNIT prt_unit; #ifndef GUI_SUPPORT - void update_gui (int force) {} /* stubs for non-GUI builds */ - void forms_check (int set) {} - void print_check (int set) {} - void keyboard_select (int select) {} - void keyboard_selected (int select) {} - void disk_ready (int ready) {} - void disk_unlocked (int unlocked) {} - void gui_run (int running) {} - static void init_console_window (void) {} - static void destroy_console_window (void) {} + void update_gui (int force) {} /* stubs for non-GUI builds */ + void forms_check (int set) {} + void print_check (int set) {} + void keyboard_select (int select) {} + void keyboard_selected (int select) {} + void disk_ready (int ready) {} + void disk_unlocked (int unlocked) {} + void gui_run (int running) {} + static void init_console_window (void) {} + static void destroy_console_window (void) {} - t_stat console_reset (DEVICE *dptr) {return SCPE_OK;} - void stuff_cmd (char *cmd) {} - t_bool stuff_and_wait (char *cmd, int timeout, int delay) {return FALSE;} - char *read_cmdline (char *ptr, int size, FILE *stream) {return read_line(ptr, size, stream);} - void remark_cmd (char *remark) {sim_printf("%s\n", remark);} + t_stat console_reset (DEVICE *dptr) {return SCPE_OK;} + void stuff_cmd (char *cmd) {} + t_bool stuff_and_wait (char *cmd, int timeout, int delay) {return FALSE;} + char *read_cmdline (char *ptr, int size, FILE *stream) {return read_line(ptr, size, stream);} + void remark_cmd (char *remark) {sim_printf("%s\n", remark);} #else t_stat console_reset (DEVICE *dptr) { - if (! sim_gui) { - SETBIT(console_unit.flags, UNIT_DIS); /* disable the GUI */ - CLRBIT(console_unit.flags, UNIT_DISPLAY); /* turn the GUI off */ - } + if (! sim_gui) { + SETBIT(console_unit.flags, UNIT_DIS); /* disable the GUI */ + CLRBIT(console_unit.flags, UNIT_DISPLAY); /* turn the GUI off */ + } - update_gui(FALSE); - return SCPE_OK; + update_gui(FALSE); + return SCPE_OK; } /* scp_panic - report fatal internal programming error */ void scp_panic (const char *msg) { - fprintf(stderr, "%s\n", msg); - exit(1); + fprintf(stderr, "%s\n", msg); + exit(1); } #ifdef _WIN32 - /* only _WIN32 is defined right now */ + /* only _WIN32 is defined right now */ #include #define BUTTON_WIDTH 90 #define BUTTON_HEIGHT 50 -#define IDC_KEYBOARD_SELECT 0 -#define IDC_DISK_UNLOCK 1 -#define IDC_RUN 2 -#define IDC_PARITY_CHECK 3 -#define IDC_UNUSED 4 -#define IDC_FILE_READY 5 -#define IDC_FORMS_CHECK 6 -#define IDC_POWER_ON 7 -#define IDC_POWER 8 -#define IDC_PROGRAM_START 9 -#define IDC_PROGRAM_STOP 10 -#define IDC_LOAD_IAR 11 -#define IDC_KEYBOARD 12 -#define IDC_IMM_STOP 13 -#define IDC_RESET 14 -#define IDC_PROGRAM_LOAD 15 +#define IDC_KEYBOARD_SELECT 0 +#define IDC_DISK_UNLOCK 1 +#define IDC_RUN 2 +#define IDC_PARITY_CHECK 3 +#define IDC_UNUSED 4 +#define IDC_FILE_READY 5 +#define IDC_FORMS_CHECK 6 +#define IDC_POWER_ON 7 +#define IDC_POWER 8 +#define IDC_PROGRAM_START 9 +#define IDC_PROGRAM_STOP 10 +#define IDC_LOAD_IAR 11 +#define IDC_KEYBOARD 12 +#define IDC_IMM_STOP 13 +#define IDC_RESET 14 +#define IDC_PROGRAM_LOAD 15 -#define IDC_TEAR 16 /* standard button */ -#define IDC_1442 17 /* device images */ -#define IDC_1132 18 +#define IDC_TEAR 16 /* standard button */ +#define IDC_1442 17 /* device images */ +#define IDC_1132 18 -#define LAMPTIME 500 /* 500 msec delay on updating */ +#define LAMPTIME 500 /* 500 msec delay on updating */ #define FLASH_TIMER_ID 1 #define UPDATE_TIMER_ID 2 -#define RUNSWITCH_X 689 /* center of the run mode switch dial */ +#define RUNSWITCH_X 689 /* center of the run mode switch dial */ #define RUNSWITCH_Y 107 -#define TOGGLES_X 122 /* left edge of series of toggle switches */ +#define TOGGLES_X 122 /* left edge of series of toggle switches */ -#define TXTBOX_X 200 /* text labels showing attached devices */ -#define TXTBOX_Y 300 -#define TXTBOX_WIDTH 195 -#define TXTBOX_HEIGHT 12 +#define TXTBOX_X 200 /* text labels showing attached devices */ +#define TXTBOX_Y 300 +#define TXTBOX_WIDTH 195 +#define TXTBOX_HEIGHT 12 static BOOL class_defined = FALSE; static HWND hConsoleWnd = NULL; @@ -207,68 +207,68 @@ static HANDLE hbm1442_full, hbm1442_empty, hbm1442_eof, hbm1442_middle; static HANDLE hbm1132_full, hbm1132_empty; static struct tag_btn { - int x, y, wx, wy; - char *txt; - BOOL pushable, state; - COLORREF clr; - HBRUSH hbrLit, hbrDark; - HWND hBtn; - BOOL subclassed; + int x, y, wx, wy; + char *txt; + BOOL pushable, state; + COLORREF clr; + HBRUSH hbrLit, hbrDark; + HWND hBtn; + BOOL subclassed; } btn[] = { - 0, 0, BUTTON_WIDTH, BUTTON_HEIGHT, "KEYBOARD\nSELECT", FALSE, FALSE, RGB(255,255,180), NULL, NULL, NULL, TRUE, - 0, 1, BUTTON_WIDTH, BUTTON_HEIGHT, "DISK\nUNLOCK", FALSE, TRUE, RGB(255,255,180), NULL, NULL, NULL, TRUE, - 0, 2, BUTTON_WIDTH, BUTTON_HEIGHT, "RUN", FALSE, FALSE, RGB(0,255,0), NULL, NULL, NULL, TRUE, - 0, 3, BUTTON_WIDTH, BUTTON_HEIGHT, "PARITY\nCHECK", FALSE, FALSE, RGB(255,0,0), NULL, NULL, NULL, TRUE, + 0, 0, BUTTON_WIDTH, BUTTON_HEIGHT, "KEYBOARD\nSELECT", FALSE, FALSE, RGB(255,255,180), NULL, NULL, NULL, TRUE, + 0, 1, BUTTON_WIDTH, BUTTON_HEIGHT, "DISK\nUNLOCK", FALSE, TRUE, RGB(255,255,180), NULL, NULL, NULL, TRUE, + 0, 2, BUTTON_WIDTH, BUTTON_HEIGHT, "RUN", FALSE, FALSE, RGB(0,255,0), NULL, NULL, NULL, TRUE, + 0, 3, BUTTON_WIDTH, BUTTON_HEIGHT, "PARITY\nCHECK", FALSE, FALSE, RGB(255,0,0), NULL, NULL, NULL, TRUE, - 1, 0, BUTTON_WIDTH, BUTTON_HEIGHT, "", FALSE, FALSE, RGB(255,255,180), NULL, NULL, NULL, TRUE, - 1, 1, BUTTON_WIDTH, BUTTON_HEIGHT, "FILE\nREADY", FALSE, FALSE, RGB(0,255,0), NULL, NULL, NULL, TRUE, - 1, 2, BUTTON_WIDTH, BUTTON_HEIGHT, "FORMS\nCHECK", FALSE, FALSE, RGB(255,255,0), NULL, NULL, NULL, TRUE, - 1, 3, BUTTON_WIDTH, BUTTON_HEIGHT, "POWER\nON", FALSE, TRUE, RGB(255,255,180), NULL, NULL, NULL, TRUE, + 1, 0, BUTTON_WIDTH, BUTTON_HEIGHT, "", FALSE, FALSE, RGB(255,255,180), NULL, NULL, NULL, TRUE, + 1, 1, BUTTON_WIDTH, BUTTON_HEIGHT, "FILE\nREADY", FALSE, FALSE, RGB(0,255,0), NULL, NULL, NULL, TRUE, + 1, 2, BUTTON_WIDTH, BUTTON_HEIGHT, "FORMS\nCHECK", FALSE, FALSE, RGB(255,255,0), NULL, NULL, NULL, TRUE, + 1, 3, BUTTON_WIDTH, BUTTON_HEIGHT, "POWER\nON", FALSE, TRUE, RGB(255,255,180), NULL, NULL, NULL, TRUE, - 2, 0, BUTTON_WIDTH, BUTTON_HEIGHT, "POWER", TRUE, FALSE, RGB(255,255,180), NULL, NULL, NULL, TRUE, - 2, 1, BUTTON_WIDTH, BUTTON_HEIGHT, "PROGRAM\nSTART", TRUE, FALSE, RGB(0,255,0), NULL, NULL, NULL, TRUE, - 2, 2, BUTTON_WIDTH, BUTTON_HEIGHT, "PROGRAM\nSTOP", TRUE, FALSE, RGB(255,0,0), NULL, NULL, NULL, TRUE, - 2, 3, BUTTON_WIDTH, BUTTON_HEIGHT, "LOAD\nIAR", TRUE, FALSE, RGB(0,0,255), NULL, NULL, NULL, TRUE, + 2, 0, BUTTON_WIDTH, BUTTON_HEIGHT, "POWER", TRUE, FALSE, RGB(255,255,180), NULL, NULL, NULL, TRUE, + 2, 1, BUTTON_WIDTH, BUTTON_HEIGHT, "PROGRAM\nSTART", TRUE, FALSE, RGB(0,255,0), NULL, NULL, NULL, TRUE, + 2, 2, BUTTON_WIDTH, BUTTON_HEIGHT, "PROGRAM\nSTOP", TRUE, FALSE, RGB(255,0,0), NULL, NULL, NULL, TRUE, + 2, 3, BUTTON_WIDTH, BUTTON_HEIGHT, "LOAD\nIAR", TRUE, FALSE, RGB(0,0,255), NULL, NULL, NULL, TRUE, - 3, 0, BUTTON_WIDTH, BUTTON_HEIGHT, "KEYBOARD", TRUE, FALSE, RGB(255,255,180), NULL, NULL, NULL, TRUE, - 3, 1, BUTTON_WIDTH, BUTTON_HEIGHT, "IMM\nSTOP", TRUE, FALSE, RGB(255,0,0), NULL, NULL, NULL, TRUE, - 3, 2, BUTTON_WIDTH, BUTTON_HEIGHT, "CHECK\nRESET", TRUE, FALSE, RGB(0,0,255), NULL, NULL, NULL, TRUE, - 3, 3, BUTTON_WIDTH, BUTTON_HEIGHT, "PROGRAM\nLOAD", TRUE, FALSE, RGB(0,0,255), NULL, NULL, NULL, TRUE, - - TXTBOX_X+40, TXTBOX_Y+25, 35, 12, "Tear", TRUE, FALSE, 0, NULL, NULL, NULL, FALSE, - 635, 238, 110, 110, "EMPTY_1442", TRUE, FALSE, 0, NULL, NULL, NULL, FALSE, - 635, 366, 110, 110, "EMPTY_1132", TRUE, FALSE, 0, NULL, NULL, NULL, FALSE, + 3, 0, BUTTON_WIDTH, BUTTON_HEIGHT, "KEYBOARD", TRUE, FALSE, RGB(255,255,180), NULL, NULL, NULL, TRUE, + 3, 1, BUTTON_WIDTH, BUTTON_HEIGHT, "IMM\nSTOP", TRUE, FALSE, RGB(255,0,0), NULL, NULL, NULL, TRUE, + 3, 2, BUTTON_WIDTH, BUTTON_HEIGHT, "CHECK\nRESET", TRUE, FALSE, RGB(0,0,255), NULL, NULL, NULL, TRUE, + 3, 3, BUTTON_WIDTH, BUTTON_HEIGHT, "PROGRAM\nLOAD", TRUE, FALSE, RGB(0,0,255), NULL, NULL, NULL, TRUE, + + TXTBOX_X+40, TXTBOX_Y+25, 35, 12, "Tear", TRUE, FALSE, 0, NULL, NULL, NULL, FALSE, + 635, 238, 110, 110, "EMPTY_1442", TRUE, FALSE, 0, NULL, NULL, NULL, FALSE, + 635, 366, 110, 110, "EMPTY_1132", TRUE, FALSE, 0, NULL, NULL, NULL, FALSE, }; #define NBUTTONS (sizeof(btn) / sizeof(btn[0])) -#define STATE_1442_EMPTY 0 /* no cards (no file attached) */ -#define STATE_1442_FULL 1 /* cards in hopper (file attached at BOF) */ -#define STATE_1442_MIDDLE 2 /* cards in hopper and stacker (file attached, neither EOF nor BOF) */ -#define STATE_1442_EOF 3 /* cards in stacker (file attached, at EOF) */ -#define STATE_1442_HIDDEN 4 /* simulator is attached to physical card reader */ +#define STATE_1442_EMPTY 0 /* no cards (no file attached) */ +#define STATE_1442_FULL 1 /* cards in hopper (file attached at BOF) */ +#define STATE_1442_MIDDLE 2 /* cards in hopper and stacker (file attached, neither EOF nor BOF) */ +#define STATE_1442_EOF 3 /* cards in stacker (file attached, at EOF) */ +#define STATE_1442_HIDDEN 4 /* simulator is attached to physical card reader */ -#define STATE_1132_EMPTY 0 /* no paper hanging out of printer */ -#define STATE_1132_FULL 1 /* paper hanging out of printer */ -#define STATE_1132_HIDDEN 2 /* printer is attached to physical printer */ +#define STATE_1132_EMPTY 0 /* no paper hanging out of printer */ +#define STATE_1132_FULL 1 /* paper hanging out of printer */ +#define STATE_1132_HIDDEN 2 /* printer is attached to physical printer */ static struct tag_txtbox { - int x, y; - char *txt; - char *unitname; - int idctrl; + int x, y; + char *txt; + char *unitname; + int idctrl; } txtbox[] = { - TXTBOX_X, TXTBOX_Y, "Card Reader", "CR", -1, - TXTBOX_X, TXTBOX_Y+ 25, "Printer", "PRT", IDC_1132, - TXTBOX_X, TXTBOX_Y+ 50, "Disk 1", "DSK0", -1, - TXTBOX_X, TXTBOX_Y+ 75, "Disk 2", "DSK1", -1, - TXTBOX_X, TXTBOX_Y+100, "Disk 3", "DSK2", -1, - TXTBOX_X, TXTBOX_Y+125, "Disk 4", "DSK3", -1, - TXTBOX_X, TXTBOX_Y+150, "Disk 5", "DSK4", -1, + TXTBOX_X, TXTBOX_Y, "Card Reader", "CR", -1, + TXTBOX_X, TXTBOX_Y+ 25, "Printer", "PRT", IDC_1132, + TXTBOX_X, TXTBOX_Y+ 50, "Disk 1", "DSK0", -1, + TXTBOX_X, TXTBOX_Y+ 75, "Disk 2", "DSK1", -1, + TXTBOX_X, TXTBOX_Y+100, "Disk 3", "DSK2", -1, + TXTBOX_X, TXTBOX_Y+125, "Disk 4", "DSK3", -1, + TXTBOX_X, TXTBOX_Y+150, "Disk 5", "DSK4", -1, }; #define NTXTBOXES (sizeof(txtbox) / sizeof(txtbox[0])) -#define TXTBOX_BOTTOM (TXTBOX_Y+150) +#define TXTBOX_BOTTOM (TXTBOX_Y+150) static void init_console_window (void); static void destroy_console_window (void); @@ -286,18 +286,18 @@ static void tear_printer (void); static void init_console_window (void) { - static BOOL did_atexit = FALSE; + static BOOL did_atexit = FALSE; - if (hConsoleWnd != NULL) - return; + if (hConsoleWnd != NULL) + return; - if (PumpID == 0) - hPump = CreateThread(NULL, 0, Pump, 0, 0, &PumpID); + if (PumpID == 0) + hPump = CreateThread(NULL, 0, Pump, 0, 0, &PumpID); - if (! did_atexit) { - atexit(destroy_console_window); - did_atexit = TRUE; - } + if (! did_atexit) { + atexit(destroy_console_window); + did_atexit = TRUE; + } } /* ------------------------------------------------------------------------ @@ -306,42 +306,42 @@ static void init_console_window (void) static void destroy_console_window (void) { - int i; + int i; - if (hConsoleWnd != NULL) - SendMessage(hConsoleWnd, WM_CLOSE, 0, 0); /* cross thread call is OK */ + if (hConsoleWnd != NULL) + SendMessage(hConsoleWnd, WM_CLOSE, 0, 0); /* cross thread call is OK */ - if (hPump != INVALID_HANDLE_VALUE) { /* this is not the most graceful way to do it */ - TerminateThread(hPump, 0); - hPump = INVALID_HANDLE_VALUE; - PumpID = 0; - hConsoleWnd = NULL; - } - if (hCDC != NULL) { - DeleteDC(hCDC); - hCDC = NULL; - } + if (hPump != INVALID_HANDLE_VALUE) { /* this is not the most graceful way to do it */ + TerminateThread(hPump, 0); + hPump = INVALID_HANDLE_VALUE; + PumpID = 0; + hConsoleWnd = NULL; + } + if (hCDC != NULL) { + DeleteDC(hCDC); + hCDC = NULL; + } - NIXOBJECT(hBitmap) - NIXOBJECT(hbLampOut) - NIXOBJECT(hFont) - NIXOBJECT(hBtnFont); - NIXOBJECT(hTinyFont); - NIXOBJECT(hcHand) - NIXOBJECT(hSwitchPen) - NIXOBJECT(hLtGreyPen) - NIXOBJECT(hGreyPen) - NIXOBJECT(hDkGreyPen) + NIXOBJECT(hBitmap) + NIXOBJECT(hbLampOut) + NIXOBJECT(hFont) + NIXOBJECT(hBtnFont); + NIXOBJECT(hTinyFont); + NIXOBJECT(hcHand) + NIXOBJECT(hSwitchPen) + NIXOBJECT(hLtGreyPen) + NIXOBJECT(hGreyPen) + NIXOBJECT(hDkGreyPen) - for (i = 0; i < NBUTTONS; i++) { - NIXOBJECT(btn[i].hbrLit); - NIXOBJECT(btn[i].hbrDark); - } + for (i = 0; i < NBUTTONS; i++) { + NIXOBJECT(btn[i].hbrLit); + NIXOBJECT(btn[i].hbrDark); + } -/* if (class_defined) { - UnregisterClass(hInstance, szConsoleClassName); - class_defined = FALSE; - } +/* if (class_defined) { + UnregisterClass(hInstance, szConsoleClassName); + class_defined = FALSE; + } */ } @@ -360,14 +360,14 @@ static int CND; static void RedrawRegion (HWND hWnd, int left, int top, int right, int bottom) { - RECT r; + RECT r; - r.left = left; - r.top = top; - r.right = right; - r.bottom = bottom; + r.left = left; + r.top = top; + r.right = right; + r.bottom = bottom; - InvalidateRect(hWnd, &r, FALSE); + InvalidateRect(hWnd, &r, FALSE); } /* ------------------------------------------------------------------------ @@ -376,14 +376,14 @@ static void RedrawRegion (HWND hWnd, int left, int top, int right, int bottom) static void RepaintRegion (HWND hWnd, int left, int top, int right, int bottom) { - RECT r; + RECT r; - r.left = left; - r.top = top; - r.right = right; - r.bottom = bottom; + r.left = left; + r.top = top; + r.right = right; + r.bottom = bottom; - InvalidateRect(hWnd, &r, TRUE); + InvalidateRect(hWnd, &r, TRUE); } /* ------------------------------------------------------------------------ @@ -396,159 +396,159 @@ static void RepaintRegion (HWND hWnd, int left, int top, int right, int bottom) * ------------------------------------------------------------------------ */ void update_gui (BOOL force) -{ - int i; - BOOL state; - static int in_here = FALSE; - static int32 displayed = 0; - RECT xin; +{ + int i; + BOOL state; + static int in_here = FALSE; + static int32 displayed = 0; + RECT xin; - if ((int32)(console_unit.flags & UNIT_DISPLAY) != displayed) { /* setting has changed */ - displayed = console_unit.flags & UNIT_DISPLAY; - if (displayed) - init_console_window(); - else - destroy_console_window(); - } + if ((int32)(console_unit.flags & UNIT_DISPLAY) != displayed) { /* setting has changed */ + displayed = console_unit.flags & UNIT_DISPLAY; + if (displayed) + init_console_window(); + else + destroy_console_window(); + } - if (hConsoleWnd == NULL) - return; + if (hConsoleWnd == NULL) + return; - GUI_BEGIN_CRITICAL_SECTION /* only one thread at a time, please */ - if (in_here) { - GUI_END_CRITICAL_SECTION - return; - } - in_here = TRUE; - GUI_END_CRITICAL_SECTION + GUI_BEGIN_CRITICAL_SECTION /* only one thread at a time, please */ + if (in_here) { + GUI_END_CRITICAL_SECTION + return; + } + in_here = TRUE; + GUI_END_CRITICAL_SECTION - CND = 0; /* combine carry and V as two bits */ - if (C) - CND |= 2; - if (V) - CND |= 1; + CND = 0; /* combine carry and V as two bits */ + if (C) + CND |= 2; + if (V) + CND |= 1; - int_lamps |= int_req; - if (ipl >= 0) - int_lamps |= (0x20 >> ipl); + int_lamps |= int_req; + if (ipl >= 0) + int_lamps |= (0x20 >> ipl); - if (RUNMODE == MODE_LOAD) - SBR = CES; /* in load mode, SBR follows the console switches */ + if (RUNMODE == MODE_LOAD) + SBR = CES; /* in load mode, SBR follows the console switches */ - if (IAR != shown_iar) - {shown_iar = IAR; RedrawRegion(hConsoleWnd, 75, 8, 364, 32);} /* lamps: don't bother erasing bkgnd */ - if (SAR != shown_sar) - {shown_sar = SAR; RedrawRegion(hConsoleWnd, 75, 42, 364, 65);} - if (ARF != shown_arf) - {shown_arf = ARF; RedrawRegion(hConsoleWnd, 75, 114, 364, 136);} - if (ACC != shown_acc) - {shown_acc = ACC; RedrawRegion(hConsoleWnd, 75, 141, 364, 164);} - if (EXT != shown_ext) - {shown_ext = EXT; RedrawRegion(hConsoleWnd, 75, 174, 364, 197);} - if (SBR != shown_sbr) - {shown_sbr = SBR; RedrawRegion(hConsoleWnd, 75, 77, 364, 97);} - if (OP != shown_op) - {shown_op = OP; RedrawRegion(hConsoleWnd, 501, 8, 595, 32);} - if (TAG != shown_tag) - {shown_tag = TAG; RedrawRegion(hConsoleWnd, 501, 77, 595, 97);} + if (IAR != shown_iar) + {shown_iar = IAR; RedrawRegion(hConsoleWnd, 75, 8, 364, 32);} /* lamps: don't bother erasing bkgnd */ + if (SAR != shown_sar) + {shown_sar = SAR; RedrawRegion(hConsoleWnd, 75, 42, 364, 65);} + if (ARF != shown_arf) + {shown_arf = ARF; RedrawRegion(hConsoleWnd, 75, 114, 364, 136);} + if (ACC != shown_acc) + {shown_acc = ACC; RedrawRegion(hConsoleWnd, 75, 141, 364, 164);} + if (EXT != shown_ext) + {shown_ext = EXT; RedrawRegion(hConsoleWnd, 75, 174, 364, 197);} + if (SBR != shown_sbr) + {shown_sbr = SBR; RedrawRegion(hConsoleWnd, 75, 77, 364, 97);} + if (OP != shown_op) + {shown_op = OP; RedrawRegion(hConsoleWnd, 501, 8, 595, 32);} + if (TAG != shown_tag) + {shown_tag = TAG; RedrawRegion(hConsoleWnd, 501, 77, 595, 97);} - if (int_lamps != shown_irq) - {shown_irq = int_lamps; RedrawRegion(hConsoleWnd, 501, 108, 595, 130);} + if (int_lamps != shown_irq) + {shown_irq = int_lamps; RedrawRegion(hConsoleWnd, 501, 108, 595, 130);} - if (CCC != shown_ccc) - {shown_ccc = CCC; RedrawRegion(hConsoleWnd, 501, 141, 595, 164);} - if (CND != shown_cnd) - {shown_cnd = CND; RedrawRegion(hConsoleWnd, 501, 174, 595, 197);} - if ((wait_state|wait_lamp) != shown_wait) - {shown_wait= (wait_state|wait_lamp); RedrawRegion(hConsoleWnd, 380, 77, 414, 97);} - if (CES != shown_ces) - {shown_ces = CES; RepaintRegion(hConsoleWnd, TOGGLES_X-7, 230, TOGGLES_X+360, 275);} /* console entry sw: do erase bkgnd */ - if (RUNMODE != shown_runmode) - {shown_runmode = RUNMODE;RepaintRegion(hConsoleWnd, RUNSWITCH_X-50, RUNSWITCH_Y-50, RUNSWITCH_X+50, RUNSWITCH_Y+50);} + if (CCC != shown_ccc) + {shown_ccc = CCC; RedrawRegion(hConsoleWnd, 501, 141, 595, 164);} + if (CND != shown_cnd) + {shown_cnd = CND; RedrawRegion(hConsoleWnd, 501, 174, 595, 197);} + if ((wait_state|wait_lamp) != shown_wait) + {shown_wait= (wait_state|wait_lamp); RedrawRegion(hConsoleWnd, 380, 77, 414, 97);} + if (CES != shown_ces) + {shown_ces = CES; RepaintRegion(hConsoleWnd, TOGGLES_X-7, 230, TOGGLES_X+360, 275);} /* console entry sw: do erase bkgnd */ + if (RUNMODE != shown_runmode) + {shown_runmode = RUNMODE;RepaintRegion(hConsoleWnd, RUNSWITCH_X-50, RUNSWITCH_Y-50, RUNSWITCH_X+50, RUNSWITCH_Y+50);} - int_lamps = 0; + int_lamps = 0; - /* this loop works with lamp buttons that are calculated on-the-fly only */ - for (i = 0; i < NBUTTONS; i++) { - if (btn[i].pushable) - continue; + /* this loop works with lamp buttons that are calculated on-the-fly only */ + for (i = 0; i < NBUTTONS; i++) { + if (btn[i].pushable) + continue; - switch (i) { - case IDC_RUN: - state = hFlashTimer || (running && ! wait_state); - break; + switch (i) { + case IDC_RUN: + state = hFlashTimer || (running && ! wait_state); + break; /* this button is always off - case IDC_PARITY_CHECK + case IDC_PARITY_CHECK */ /* these buttons are enabled/disabled directly - case IDC_POWER_ON: - case IDC_FILE_READY: - case IDC_FORMS_CHECK: - case IDC_KEYBOARD_SELECT: - case IDC_DISK_UNLOCK: + case IDC_POWER_ON: + case IDC_FILE_READY: + case IDC_FORMS_CHECK: + case IDC_KEYBOARD_SELECT: + case IDC_DISK_UNLOCK: */ - default: - continue; - } + default: + continue; + } - if (state != btn[i].state) { /* state has changed */ - EnableWindow(btn[i].hBtn, state); - btn[i].state = state; - } - } + if (state != btn[i].state) { /* state has changed */ + EnableWindow(btn[i].hBtn, state); + btn[i].state = state; + } + } - if (force) { /* if force flag is set, update text region */ - SetRect(&xin, TXTBOX_X, TXTBOX_Y, TXTBOX_X+TXTBOX_WIDTH, TXTBOX_BOTTOM+2*TXTBOX_HEIGHT); - InvalidateRect(hConsoleWnd, &xin, TRUE); - } + if (force) { /* if force flag is set, update text region */ + SetRect(&xin, TXTBOX_X, TXTBOX_Y, TXTBOX_X+TXTBOX_WIDTH, TXTBOX_BOTTOM+2*TXTBOX_HEIGHT); + InvalidateRect(hConsoleWnd, &xin, TRUE); + } - state = ((cr_unit.flags & UNIT_ATT) == 0) ? STATE_1442_EMPTY : - (cr_unit.flags & UNIT_PHYSICAL) ? STATE_1442_HIDDEN : - (cr_unit.flags & UNIT_CR_EMPTY) ? STATE_1442_EOF : - cr_unit.pos ? STATE_1442_MIDDLE : - STATE_1442_FULL; + state = ((cr_unit.flags & UNIT_ATT) == 0) ? STATE_1442_EMPTY : + (cr_unit.flags & UNIT_PHYSICAL) ? STATE_1442_HIDDEN : + (cr_unit.flags & UNIT_CR_EMPTY) ? STATE_1442_EOF : + cr_unit.pos ? STATE_1442_MIDDLE : + STATE_1442_FULL; - if (state != btn[IDC_1442].state) { - if (state == STATE_1442_HIDDEN) - ShowWindow(btn[IDC_1442].hBtn, SW_HIDE); - else { - if (btn[IDC_1442].state == STATE_1442_HIDDEN) - ShowWindow(btn[IDC_1442].hBtn, SW_SHOWNA); + if (state != btn[IDC_1442].state) { + if (state == STATE_1442_HIDDEN) + ShowWindow(btn[IDC_1442].hBtn, SW_HIDE); + else { + if (btn[IDC_1442].state == STATE_1442_HIDDEN) + ShowWindow(btn[IDC_1442].hBtn, SW_SHOWNA); - SendMessage(btn[IDC_1442].hBtn, STM_SETIMAGE, IMAGE_BITMAP, - (LPARAM) ( - (state == STATE_1442_FULL) ? hbm1442_full : - (state == STATE_1442_MIDDLE) ? hbm1442_middle : - (state == STATE_1442_EOF) ? hbm1442_eof : - hbm1442_empty)); - } + SendMessage(btn[IDC_1442].hBtn, STM_SETIMAGE, IMAGE_BITMAP, + (LPARAM) ( + (state == STATE_1442_FULL) ? hbm1442_full : + (state == STATE_1442_MIDDLE) ? hbm1442_middle : + (state == STATE_1442_EOF) ? hbm1442_eof : + hbm1442_empty)); + } - btn[IDC_1442].state = state; - } + btn[IDC_1442].state = state; + } - state = ((prt_unit.flags & UNIT_ATT) == 0) ? STATE_1132_EMPTY : - (prt_unit.flags & UNIT_PHYSICAL_PTR) ? STATE_1132_HIDDEN : - prt_unit.pos ? STATE_1132_FULL : - STATE_1132_EMPTY; + state = ((prt_unit.flags & UNIT_ATT) == 0) ? STATE_1132_EMPTY : + (prt_unit.flags & UNIT_PHYSICAL_PTR) ? STATE_1132_HIDDEN : + prt_unit.pos ? STATE_1132_FULL : + STATE_1132_EMPTY; - if (state != btn[IDC_1132].state) { - if (state == STATE_1132_HIDDEN) - ShowWindow(btn[IDC_1132].hBtn, SW_HIDE); - else { - if (btn[IDC_1132].state == STATE_1132_HIDDEN) - ShowWindow(btn[IDC_1132].hBtn, SW_SHOWNA); + if (state != btn[IDC_1132].state) { + if (state == STATE_1132_HIDDEN) + ShowWindow(btn[IDC_1132].hBtn, SW_HIDE); + else { + if (btn[IDC_1132].state == STATE_1132_HIDDEN) + ShowWindow(btn[IDC_1132].hBtn, SW_SHOWNA); - SendMessage(btn[IDC_1132].hBtn, STM_SETIMAGE, IMAGE_BITMAP, - (LPARAM) ( - (state == STATE_1132_FULL) ? hbm1132_full : hbm1132_empty)); - } + SendMessage(btn[IDC_1132].hBtn, STM_SETIMAGE, IMAGE_BITMAP, + (LPARAM) ( + (state == STATE_1132_FULL) ? hbm1132_full : hbm1132_empty)); + } - btn[IDC_1132].state = state; - } + btn[IDC_1132].state = state; + } - in_here = FALSE; + in_here = FALSE; } WNDPROC oldButtonProc = NULL; @@ -558,20 +558,20 @@ WNDPROC oldButtonProc = NULL; LRESULT CALLBACK ButtonProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { - int i; + int i; - i = GetWindowLong(hWnd, GWL_ID); + i = GetWindowLong(hWnd, GWL_ID); - if (! btn[i].pushable) { - if (uMsg == WM_LBUTTONDOWN || uMsg == WM_LBUTTONUP || uMsg == WM_LBUTTONDBLCLK) - return 0; + if (! btn[i].pushable) { + if (uMsg == WM_LBUTTONDOWN || uMsg == WM_LBUTTONUP || uMsg == WM_LBUTTONDBLCLK) + return 0; - if (uMsg == WM_CHAR) - if ((TCHAR) wParam == ' ') - return 0; - } + if (uMsg == WM_CHAR) + if ((TCHAR) wParam == ' ') + return 0; + } - return CallWindowProc(oldButtonProc, hWnd, uMsg, wParam, lParam); + return CallWindowProc(oldButtonProc, hWnd, uMsg, wParam, lParam); } /* ------------------------------------------------------------------------ @@ -579,13 +579,13 @@ LRESULT CALLBACK ButtonProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) static int occurs (char *txt, char ch) { - int count = 0; + int count = 0; - while (*txt) - if (*txt++ == ch) - count++; + while (*txt) + if (*txt++ == ch) + count++; - return count; + return count; } /* ------------------------------------------------------------------------ @@ -596,135 +596,135 @@ static int occurs (char *txt, char ch) void PaintButton (LPDRAWITEMSTRUCT dis) { - int i = dis->CtlID, nc, nlines, x, y, dy; - BOOL down = dis->itemState & ODS_SELECTED; - HPEN hOldPen; - HFONT hOldFont; - UINT oldAlign; - COLORREF oldBk; - char *txt, *tstart; + int i = dis->CtlID, nc, nlines, x, y, dy; + BOOL down = dis->itemState & ODS_SELECTED; + HPEN hOldPen; + HFONT hOldFont; + UINT oldAlign; + COLORREF oldBk; + char *txt, *tstart; - if (! BETWEEN(i, 0, NBUTTONS-1)) - return; + if (! BETWEEN(i, 0, NBUTTONS-1)) + return; - if (! btn[i].subclassed) - return; + if (! btn[i].subclassed) + return; - FillRect(dis->hDC, &dis->rcItem, ((btn[i].pushable || power) && IsWindowEnabled(btn[i].hBtn)) ? btn[i].hbrLit : btn[i].hbrDark); + FillRect(dis->hDC, &dis->rcItem, ((btn[i].pushable || power) && IsWindowEnabled(btn[i].hBtn)) ? btn[i].hbrLit : btn[i].hbrDark); - if (! btn[i].pushable) { - hOldPen = SelectObject(dis->hDC, hBlackPen); - MoveToEx(dis->hDC, dis->rcItem.left, dis->rcItem.top, NULL); - LineTo(dis->hDC, dis->rcItem.right-1, dis->rcItem.top); - LineTo(dis->hDC, dis->rcItem.right-1, dis->rcItem.bottom-1); - LineTo(dis->hDC, dis->rcItem.left, dis->rcItem.bottom-1); - LineTo(dis->hDC, dis->rcItem.left, dis->rcItem.top); - } - else if (down) { - /* do the three-D thing */ - hOldPen = SelectObject(dis->hDC, hDkGreyPen); - MoveToEx(dis->hDC, dis->rcItem.left, dis->rcItem.bottom-2, NULL); - LineTo(dis->hDC, dis->rcItem.left, dis->rcItem.top); - LineTo(dis->hDC, dis->rcItem.right-1, dis->rcItem.top); + if (! btn[i].pushable) { + hOldPen = SelectObject(dis->hDC, hBlackPen); + MoveToEx(dis->hDC, dis->rcItem.left, dis->rcItem.top, NULL); + LineTo(dis->hDC, dis->rcItem.right-1, dis->rcItem.top); + LineTo(dis->hDC, dis->rcItem.right-1, dis->rcItem.bottom-1); + LineTo(dis->hDC, dis->rcItem.left, dis->rcItem.bottom-1); + LineTo(dis->hDC, dis->rcItem.left, dis->rcItem.top); + } + else if (down) { + /* do the three-D thing */ + hOldPen = SelectObject(dis->hDC, hDkGreyPen); + MoveToEx(dis->hDC, dis->rcItem.left, dis->rcItem.bottom-2, NULL); + LineTo(dis->hDC, dis->rcItem.left, dis->rcItem.top); + LineTo(dis->hDC, dis->rcItem.right-1, dis->rcItem.top); - SelectObject(dis->hDC, hWhitePen); - MoveToEx(dis->hDC, dis->rcItem.left, dis->rcItem.bottom-1, NULL); - LineTo(dis->hDC, dis->rcItem.right-1, dis->rcItem.bottom-1); - LineTo(dis->hDC, dis->rcItem.right-1, dis->rcItem.top); + SelectObject(dis->hDC, hWhitePen); + MoveToEx(dis->hDC, dis->rcItem.left, dis->rcItem.bottom-1, NULL); + LineTo(dis->hDC, dis->rcItem.right-1, dis->rcItem.bottom-1); + LineTo(dis->hDC, dis->rcItem.right-1, dis->rcItem.top); - SelectObject(dis->hDC, hGreyPen); - MoveToEx(dis->hDC, dis->rcItem.left+1, dis->rcItem.bottom-3, NULL); - LineTo(dis->hDC, dis->rcItem.left+1, dis->rcItem.top+1); - LineTo(dis->hDC, dis->rcItem.right-3, dis->rcItem.top+1); - } - else { - hOldPen = SelectObject(dis->hDC, hWhitePen); - MoveToEx(dis->hDC, dis->rcItem.left, dis->rcItem.bottom-2, NULL); - LineTo(dis->hDC, dis->rcItem.left, dis->rcItem.top); - LineTo(dis->hDC, dis->rcItem.right-1, dis->rcItem.top); + SelectObject(dis->hDC, hGreyPen); + MoveToEx(dis->hDC, dis->rcItem.left+1, dis->rcItem.bottom-3, NULL); + LineTo(dis->hDC, dis->rcItem.left+1, dis->rcItem.top+1); + LineTo(dis->hDC, dis->rcItem.right-3, dis->rcItem.top+1); + } + else { + hOldPen = SelectObject(dis->hDC, hWhitePen); + MoveToEx(dis->hDC, dis->rcItem.left, dis->rcItem.bottom-2, NULL); + LineTo(dis->hDC, dis->rcItem.left, dis->rcItem.top); + LineTo(dis->hDC, dis->rcItem.right-1, dis->rcItem.top); - SelectObject(dis->hDC, hDkGreyPen); - MoveToEx(dis->hDC, dis->rcItem.left, dis->rcItem.bottom-1, NULL); - LineTo(dis->hDC, dis->rcItem.right-1, dis->rcItem.bottom-1); - LineTo(dis->hDC, dis->rcItem.right-1, dis->rcItem.top); + SelectObject(dis->hDC, hDkGreyPen); + MoveToEx(dis->hDC, dis->rcItem.left, dis->rcItem.bottom-1, NULL); + LineTo(dis->hDC, dis->rcItem.right-1, dis->rcItem.bottom-1); + LineTo(dis->hDC, dis->rcItem.right-1, dis->rcItem.top); - SelectObject(dis->hDC, hGreyPen); - MoveToEx(dis->hDC, dis->rcItem.left+1, dis->rcItem.bottom-2, NULL); - LineTo(dis->hDC, dis->rcItem.right-2, dis->rcItem.bottom-2); - LineTo(dis->hDC, dis->rcItem.right-2, dis->rcItem.top+1); - } + SelectObject(dis->hDC, hGreyPen); + MoveToEx(dis->hDC, dis->rcItem.left+1, dis->rcItem.bottom-2, NULL); + LineTo(dis->hDC, dis->rcItem.right-2, dis->rcItem.bottom-2); + LineTo(dis->hDC, dis->rcItem.right-2, dis->rcItem.top+1); + } - SelectObject(dis->hDC, hOldPen); + SelectObject(dis->hDC, hOldPen); - hOldFont = SelectObject(dis->hDC, hBtnFont); - oldAlign = SetTextAlign(dis->hDC, TA_CENTER|TA_TOP); - oldBk = SetBkMode(dis->hDC, TRANSPARENT); + hOldFont = SelectObject(dis->hDC, hBtnFont); + oldAlign = SetTextAlign(dis->hDC, TA_CENTER|TA_TOP); + oldBk = SetBkMode(dis->hDC, TRANSPARENT); - txt = btn[i].txt; - nlines = occurs(txt, '\n')+1; - x = (dis->rcItem.left + dis->rcItem.right) / 2; - y = (dis->rcItem.top + dis->rcItem.bottom) / 2; + txt = btn[i].txt; + nlines = occurs(txt, '\n')+1; + x = (dis->rcItem.left + dis->rcItem.right) / 2; + y = (dis->rcItem.top + dis->rcItem.bottom) / 2; - dy = 14; - y = y - (nlines*dy)/2; + dy = 14; + y = y - (nlines*dy)/2; - if (down) { - x += 1; - y += 1; - } + if (down) { + x += 1; + y += 1; + } - for (;;) { - for (nc = 0, tstart = txt; *txt && *txt != '\n'; txt++, nc++) - ; + for (;;) { + for (nc = 0, tstart = txt; *txt && *txt != '\n'; txt++, nc++) + ; - TextOut(dis->hDC, x, y, tstart, nc); + TextOut(dis->hDC, x, y, tstart, nc); - if (*txt == '\0') - break; + if (*txt == '\0') + break; - txt++; - y += dy; - } + txt++; + y += dy; + } - SetTextAlign(dis->hDC, oldAlign); - SetBkMode(dis->hDC, oldBk); - SelectObject(dis->hDC, hOldFont); + SetTextAlign(dis->hDC, oldAlign); + SetBkMode(dis->hDC, oldBk); + SelectObject(dis->hDC, hOldFont); } - + /* ------------------------------------------------------------------------ * ------------------------------------------------------------------------ */ HWND CreateSubclassedButton (HWND hwParent, int i) { - HWND hBtn; - int x, y; - int r, g, b; + HWND hBtn; + int x, y; + int r, g, b; - y = bmht - (4*BUTTON_HEIGHT) + BUTTON_HEIGHT * btn[i].y; - x = (btn[i].x < 2) ? (btn[i].x*BUTTON_WIDTH) : (598 - (4-btn[i].x)*BUTTON_WIDTH); + y = bmht - (4*BUTTON_HEIGHT) + BUTTON_HEIGHT * btn[i].y; + x = (btn[i].x < 2) ? (btn[i].x*BUTTON_WIDTH) : (598 - (4-btn[i].x)*BUTTON_WIDTH); - if ((hBtn = CreateWindow("BUTTON", btn[i].txt, WS_CHILD|WS_VISIBLE|BS_CENTER|BS_MULTILINE|BS_OWNERDRAW, - x, y, BUTTON_WIDTH, BUTTON_HEIGHT, hwParent, (HMENU) i, hInstance, NULL)) == NULL) - return NULL; + if ((hBtn = CreateWindow("BUTTON", btn[i].txt, WS_CHILD|WS_VISIBLE|BS_CENTER|BS_MULTILINE|BS_OWNERDRAW, + x, y, BUTTON_WIDTH, BUTTON_HEIGHT, hwParent, (HMENU) i, hInstance, NULL)) == NULL) + return NULL; - btn[i].hBtn = hBtn; + btn[i].hBtn = hBtn; - if (oldButtonProc == NULL) - oldButtonProc = (WNDPROC) GetWindowLong(hBtn, GWL_WNDPROC); + if (oldButtonProc == NULL) + oldButtonProc = (WNDPROC) GetWindowLong(hBtn, GWL_WNDPROC); - btn[i].hbrLit = CreateSolidBrush(btn[i].clr); + btn[i].hbrLit = CreateSolidBrush(btn[i].clr); - if (! btn[i].pushable) { - r = GetRValue(btn[i].clr) / 4; - g = GetGValue(btn[i].clr) / 4; - b = GetBValue(btn[i].clr) / 4; + if (! btn[i].pushable) { + r = GetRValue(btn[i].clr) / 4; + g = GetGValue(btn[i].clr) / 4; + b = GetBValue(btn[i].clr) / 4; - btn[i].hbrDark = CreateSolidBrush(RGB(r,g,b)); - EnableWindow(hBtn, FALSE); - } + btn[i].hbrDark = CreateSolidBrush(RGB(r,g,b)); + EnableWindow(hBtn, FALSE); + } - SetWindowLong(hBtn, GWL_WNDPROC, (LONG) ButtonProc); - return hBtn; + SetWindowLong(hBtn, GWL_WNDPROC, (LONG) ButtonProc); + return hBtn; } /* ------------------------------------------------------------------------ @@ -735,198 +735,198 @@ HWND CreateSubclassedButton (HWND hwParent, int i) static DWORD WINAPI Pump (LPVOID arg) { - MSG msg; - int wx, wy, i; - RECT r, ra; - BITMAP bm; - WNDCLASS cd; - HDC hDC; - HWND hActWnd; + MSG msg; + int wx, wy, i; + RECT r, ra; + BITMAP bm; + WNDCLASS cd; + HDC hDC; + HWND hActWnd; - hActWnd = GetForegroundWindow(); + hActWnd = GetForegroundWindow(); - if (! class_defined) { /* register Window class */ - hInstance = GetModuleHandle(NULL); + if (! class_defined) { /* register Window class */ + hInstance = GetModuleHandle(NULL); - memset(&cd, 0, sizeof(cd)); - cd.style = CS_NOCLOSE; - cd.lpfnWndProc = ConsoleWndProc; - cd.cbClsExtra = 0; - cd.cbWndExtra = 0; - cd.hInstance = hInstance; - cd.hIcon = NULL; - cd.hCursor = hcArrow; - cd.hbrBackground = NULL; - cd.lpszMenuName = NULL; - cd.lpszClassName = szConsoleClassName; + memset(&cd, 0, sizeof(cd)); + cd.style = CS_NOCLOSE; + cd.lpfnWndProc = ConsoleWndProc; + cd.cbClsExtra = 0; + cd.cbWndExtra = 0; + cd.hInstance = hInstance; + cd.hIcon = NULL; + cd.hCursor = hcArrow; + cd.hbrBackground = NULL; + cd.lpszMenuName = NULL; + cd.lpszClassName = szConsoleClassName; - if (! RegisterClass(&cd)) { - PumpID = 0; - return 0; - } + if (! RegisterClass(&cd)) { + PumpID = 0; + return 0; + } - class_defined = TRUE; - } + class_defined = TRUE; + } - hbWhite = GetStockObject(WHITE_BRUSH); /* create or fetch useful GDI objects */ - hbBlack = GetStockObject(BLACK_BRUSH); /* create or fetch useful GDI objects */ - hbGray = GetStockObject(GRAY_BRUSH); - hSwitchPen = CreatePen(PS_SOLID, 5, RGB(255,255,255)); + hbWhite = GetStockObject(WHITE_BRUSH); /* create or fetch useful GDI objects */ + hbBlack = GetStockObject(BLACK_BRUSH); /* create or fetch useful GDI objects */ + hbGray = GetStockObject(GRAY_BRUSH); + hSwitchPen = CreatePen(PS_SOLID, 5, RGB(255,255,255)); - hWhitePen = GetStockObject(WHITE_PEN); - hBlackPen = GetStockObject(BLACK_PEN); - hLtGreyPen = CreatePen(PS_SOLID, 1, RGB(190,190,190)); - hGreyPen = CreatePen(PS_SOLID, 1, RGB(128,128,128)); - hDkGreyPen = CreatePen(PS_SOLID, 1, RGB(64,64,64)); + hWhitePen = GetStockObject(WHITE_PEN); + hBlackPen = GetStockObject(BLACK_PEN); + hLtGreyPen = CreatePen(PS_SOLID, 1, RGB(190,190,190)); + hGreyPen = CreatePen(PS_SOLID, 1, RGB(128,128,128)); + hDkGreyPen = CreatePen(PS_SOLID, 1, RGB(64,64,64)); - hcArrow = LoadCursor(NULL, IDC_ARROW); + hcArrow = LoadCursor(NULL, IDC_ARROW); #ifdef IDC_HAND - hcHand = LoadCursor(NULL, IDC_HAND); /* use stock object provided by Windows */ - if (hcHand == NULL) - hcHand = LoadCursor(hInstance, MAKEINTRESOURCE(IDC_MYHAND)); + hcHand = LoadCursor(NULL, IDC_HAND); /* use stock object provided by Windows */ + if (hcHand == NULL) + hcHand = LoadCursor(hInstance, MAKEINTRESOURCE(IDC_MYHAND)); #else - hcHand = LoadCursor(hInstance, MAKEINTRESOURCE(IDC_MYHAND)); + hcHand = LoadCursor(hInstance, MAKEINTRESOURCE(IDC_MYHAND)); #endif - if (hBitmap == NULL) - hBitmap = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_CONSOLE)); - if (hbLampOut == NULL) - hbLampOut = CreateSolidBrush(RGB(50,50,50)); - if (hFont == NULL) - hFont = CreateFont(-10, 0, 0, 0, FW_NORMAL, 0, 0, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, FIXED_PITCH, FF_SWISS, "Arial"); - if (hBtnFont == NULL) - hBtnFont = CreateFont(-12, 0, 0, 0, FW_NORMAL, 0, 0, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, FIXED_PITCH, FF_SWISS, "Arial"); - if (hTinyFont == NULL) - hTinyFont = CreateFont(-10, 0, 0, 0, FW_NORMAL, 0, 0, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, FIXED_PITCH, FF_SWISS, "Arial"); + if (hBitmap == NULL) + hBitmap = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_CONSOLE)); + if (hbLampOut == NULL) + hbLampOut = CreateSolidBrush(RGB(50,50,50)); + if (hFont == NULL) + hFont = CreateFont(-10, 0, 0, 0, FW_NORMAL, 0, 0, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, FIXED_PITCH, FF_SWISS, "Arial"); + if (hBtnFont == NULL) + hBtnFont = CreateFont(-12, 0, 0, 0, FW_NORMAL, 0, 0, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, FIXED_PITCH, FF_SWISS, "Arial"); + if (hTinyFont == NULL) + hTinyFont = CreateFont(-10, 0, 0, 0, FW_NORMAL, 0, 0, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, FIXED_PITCH, FF_SWISS, "Arial"); - if (hConsoleWnd == NULL) { /* create window */ - if ((hConsoleWnd = CreateWindow(szConsoleClassName, "IBM 1130", WS_OVERLAPPED|WS_CLIPCHILDREN, 0, 0, 200, 200, NULL, NULL, hInstance, NULL)) == NULL) { - PumpID = 0; - return 0; - } + if (hConsoleWnd == NULL) { /* create window */ + if ((hConsoleWnd = CreateWindow(szConsoleClassName, "IBM 1130", WS_OVERLAPPED|WS_CLIPCHILDREN, 0, 0, 200, 200, NULL, NULL, hInstance, NULL)) == NULL) { + PumpID = 0; + return 0; + } - DragAcceptFiles(hConsoleWnd, TRUE); /* let it accept dragged files (scripts) */ - } + DragAcceptFiles(hConsoleWnd, TRUE); /* let it accept dragged files (scripts) */ + } - GetObject(hBitmap, sizeof(bm), &bm); /* get bitmap size */ - bmwid = bm.bmWidth; - bmht = bm.bmHeight; + GetObject(hBitmap, sizeof(bm), &bm); /* get bitmap size */ + bmwid = bm.bmWidth; + bmht = bm.bmHeight; - for (i = 0; i < NBUTTONS; i++) { - if (! btn[i].subclassed) - continue; + for (i = 0; i < NBUTTONS; i++) { + if (! btn[i].subclassed) + continue; - CreateSubclassedButton(hConsoleWnd, i); - if (! btn[i].pushable) - EnableWindow(btn[i].hBtn, btn[i].state); - } + CreateSubclassedButton(hConsoleWnd, i); + if (! btn[i].pushable) + EnableWindow(btn[i].hBtn, btn[i].state); + } /* This isn't needed anymore, now that we have the big printer icon -- it acts like a button now - * i = IDC_TEAR; - * btn[i].hBtn = CreateWindow("BUTTON", btn[i].txt, WS_CHILD|WS_VISIBLE|BS_CENTER, - * btn[i].x, btn[i].y, btn[i].wx, btn[i].wy, hConsoleWnd, (HMENU) i, hInstance, NULL); + * i = IDC_TEAR; + * btn[i].hBtn = CreateWindow("BUTTON", btn[i].txt, WS_CHILD|WS_VISIBLE|BS_CENTER, + * btn[i].x, btn[i].y, btn[i].wx, btn[i].wy, hConsoleWnd, (HMENU) i, hInstance, NULL); * - * SendMessage(btn[i].hBtn, WM_SETFONT, (WPARAM) hTinyFont, TRUE); + * SendMessage(btn[i].hBtn, WM_SETFONT, (WPARAM) hTinyFont, TRUE); */ - hbm1442_full = LoadBitmap(hInstance, "FULL_1442"); - hbm1442_empty = LoadBitmap(hInstance, "EMPTY_1442"); - hbm1442_eof = LoadBitmap(hInstance, "EOF_1442"); - hbm1442_middle = LoadBitmap(hInstance, "MIDDLE_1442"); - hbm1132_full = LoadBitmap(hInstance, "FULL_1132"); - hbm1132_empty = LoadBitmap(hInstance, "EMPTY_1132"); + hbm1442_full = LoadBitmap(hInstance, "FULL_1442"); + hbm1442_empty = LoadBitmap(hInstance, "EMPTY_1442"); + hbm1442_eof = LoadBitmap(hInstance, "EOF_1442"); + hbm1442_middle = LoadBitmap(hInstance, "MIDDLE_1442"); + hbm1132_full = LoadBitmap(hInstance, "FULL_1132"); + hbm1132_empty = LoadBitmap(hInstance, "EMPTY_1132"); - i = IDC_1442; + i = IDC_1442; - btn[i].hBtn = CreateWindow("STATIC", btn[i].txt, WS_CHILD|WS_VISIBLE|SS_BITMAP|SS_SUNKEN|WS_BORDER|SS_REALSIZEIMAGE|SS_NOTIFY, - btn[i].x, btn[i].y, btn[i].wx, btn[i].wy, hConsoleWnd, (HMENU) i, hInstance, NULL); - btn[i].state = STATE_1442_EMPTY; + btn[i].hBtn = CreateWindow("STATIC", btn[i].txt, WS_CHILD|WS_VISIBLE|SS_BITMAP|SS_SUNKEN|WS_BORDER|SS_REALSIZEIMAGE|SS_NOTIFY, + btn[i].x, btn[i].y, btn[i].wx, btn[i].wy, hConsoleWnd, (HMENU) i, hInstance, NULL); + btn[i].state = STATE_1442_EMPTY; - wx = SendMessage(btn[i].hBtn, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM) hbm1442_empty); + wx = SendMessage(btn[i].hBtn, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM) hbm1442_empty); - i = IDC_1132; + i = IDC_1132; - btn[i].hBtn = CreateWindow("STATIC", btn[i].txt, WS_CHILD|WS_VISIBLE|SS_BITMAP|SS_SUNKEN|WS_BORDER|SS_REALSIZEIMAGE|SS_NOTIFY, - btn[i].x, btn[i].y, btn[i].wx, btn[i].wy, hConsoleWnd, (HMENU) i, hInstance, NULL); - btn[i].state = FALSE; + btn[i].hBtn = CreateWindow("STATIC", btn[i].txt, WS_CHILD|WS_VISIBLE|SS_BITMAP|SS_SUNKEN|WS_BORDER|SS_REALSIZEIMAGE|SS_NOTIFY, + btn[i].x, btn[i].y, btn[i].wx, btn[i].wy, hConsoleWnd, (HMENU) i, hInstance, NULL); + btn[i].state = FALSE; - wx = SendMessage(btn[i].hBtn, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM) hbm1132_empty); + wx = SendMessage(btn[i].hBtn, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM) hbm1132_empty); - GetWindowRect(hConsoleWnd, &r); /* get window size as created */ - wx = r.right - r.left + 1; - wy = r.bottom - r.top + 1; + GetWindowRect(hConsoleWnd, &r); /* get window size as created */ + wx = r.right - r.left + 1; + wy = r.bottom - r.top + 1; - if (hCDC == NULL) { /* get a memory DC and select the bitmap into ti */ - hDC = GetDC(hConsoleWnd); - hCDC = CreateCompatibleDC(hDC); - SelectObject(hCDC, hBitmap); - ReleaseDC(hConsoleWnd, hDC); - } + if (hCDC == NULL) { /* get a memory DC and select the bitmap into ti */ + hDC = GetDC(hConsoleWnd); + hCDC = CreateCompatibleDC(hDC); + SelectObject(hCDC, hBitmap); + ReleaseDC(hConsoleWnd, hDC); + } - GetClientRect(hConsoleWnd, &r); - wx = (wx - r.right - 1) + bmwid; /* compute new desired size based on how client area came out */ - wy = (wy - r.bottom - 1) + bmht; - MoveWindow(hConsoleWnd, 0, 0, wx, wy, FALSE); /* resize window */ + GetClientRect(hConsoleWnd, &r); + wx = (wx - r.right - 1) + bmwid; /* compute new desired size based on how client area came out */ + wy = (wy - r.bottom - 1) + bmht; + MoveWindow(hConsoleWnd, 0, 0, wx, wy, FALSE); /* resize window */ - ShowWindow(hConsoleWnd, SW_SHOWNOACTIVATE); /* display it */ - UpdateWindow(hConsoleWnd); + ShowWindow(hConsoleWnd, SW_SHOWNOACTIVATE); /* display it */ + UpdateWindow(hConsoleWnd); - if (hActWnd != NULL) { /* bring console (sim) window back to top */ - GetWindowRect(hConsoleWnd, &r); - ShowWindow(hActWnd, SW_NORMAL); /* and move it just below the display window */ - SetWindowPos(hActWnd, HWND_TOP, 0, r.bottom, 0, 0, SWP_NOSIZE); - GetWindowRect(hActWnd, &ra); - if (ra.bottom >= GetSystemMetrics(SM_CYSCREEN)) { /* resize if it goes of bottom of screen */ - ra.bottom = GetSystemMetrics(SM_CYSCREEN) - 1; - SetWindowPos(hActWnd, 0, 0, 0, ra.right-ra.left+1, ra.bottom-ra.top+1, SWP_NOZORDER|SWP_NOMOVE); - } - } + if (hActWnd != NULL) { /* bring console (sim) window back to top */ + GetWindowRect(hConsoleWnd, &r); + ShowWindow(hActWnd, SW_NORMAL); /* and move it just below the display window */ + SetWindowPos(hActWnd, HWND_TOP, 0, r.bottom, 0, 0, SWP_NOSIZE); + GetWindowRect(hActWnd, &ra); + if (ra.bottom >= GetSystemMetrics(SM_CYSCREEN)) { /* resize if it goes of bottom of screen */ + ra.bottom = GetSystemMetrics(SM_CYSCREEN) - 1; + SetWindowPos(hActWnd, 0, 0, 0, ra.right-ra.left+1, ra.bottom-ra.top+1, SWP_NOZORDER|SWP_NOMOVE); + } + } - if (running) /* if simulator is already running, start update timer */ - gui_run(TRUE); + if (running) /* if simulator is already running, start update timer */ + gui_run(TRUE); - while (GetMessage(&msg, hConsoleWnd, 0, 0)) { /* message pump - this basically loops forevermore */ - TranslateMessage(&msg); - DispatchMessage(&msg); - } + while (GetMessage(&msg, hConsoleWnd, 0, 0)) { /* message pump - this basically loops forevermore */ + TranslateMessage(&msg); + DispatchMessage(&msg); + } - if (hConsoleWnd != NULL) { - DragAcceptFiles(hConsoleWnd, FALSE); /* unregister as drag/drop target */ - DestroyWindow(hConsoleWnd); /* but if a quit message got posted, clean up */ - hConsoleWnd = NULL; - } + if (hConsoleWnd != NULL) { + DragAcceptFiles(hConsoleWnd, FALSE); /* unregister as drag/drop target */ + DestroyWindow(hConsoleWnd); /* but if a quit message got posted, clean up */ + hConsoleWnd = NULL; + } - PumpID = 0; - return 0; + PumpID = 0; + return 0; } /* ------------------------------------------------------------------------ - * DrawBits - starting at position (x,y), draw lamps for nbits bits of word 'bits', looking only at masked bits + * DrawBits - starting at position (x,y), draw lamps for nbits bits of word 'bits', looking only at masked bits * ------------------------------------------------------------------------ */ static void DrawBits (HDC hDC, int x, int y, int bits, int nbits, int mask, char *syms) { - int i, b = 0x0001 << (nbits-1); + int i, b = 0x0001 << (nbits-1); - for (i = 0; i < nbits; i++, b >>= 1) { - if (mask & b) { /* select white or black lettering then write 2 chars */ - SetTextColor(hDC, (b & bits && power) ? RGB(255,255,255) : RGB(0,0,0)); - TextOut(hDC, x, y, syms, 2); - } - syms += 2; /* go to next symbol pair */ + for (i = 0; i < nbits; i++, b >>= 1) { + if (mask & b) { /* select white or black lettering then write 2 chars */ + SetTextColor(hDC, (b & bits && power) ? RGB(255,255,255) : RGB(0,0,0)); + TextOut(hDC, x, y, syms, 2); + } + syms += 2; /* go to next symbol pair */ - if (i < 10) - x += 15; /* step between lamps */ - else - x += 19; + if (i < 10) + x += 15; /* step between lamps */ + else + x += 19; - if (x < 500) { - if (b & 0x1110) - x += 10; /* step over nibble divisions on left side */ - else if (b & 0x0001) - x += 9; - } - } + if (x < 500) { + if (b & 0x1110) + x += 10; /* step over nibble divisions on left side */ + else if (b & 0x0001) + x += 9; + } + } } /* ------------------------------------------------------------------------ @@ -936,24 +936,24 @@ static void DrawBits (HDC hDC, int x, int y, int bits, int nbits, int mask, char static void DrawToggles (HDC hDC, int bits) { - int b, x; + int b, x; - for (b = 0x8000, x = TOGGLES_X; b != 0; b >>= 1) { - if (shown_ces & b) { /* up */ - SelectObject(hDC, hbWhite); - Rectangle(hDC, x, 232, x+9, 240); - SelectObject(hDC, hbGray); - Rectangle(hDC, x, 239, x+9, 255); - } - else { /* down */ - SelectObject(hDC, hbWhite); - Rectangle(hDC, x, 263, x+9, 271); - SelectObject(hDC, hbGray); - Rectangle(hDC, x, 248, x+9, 264); - } + for (b = 0x8000, x = TOGGLES_X; b != 0; b >>= 1) { + if (shown_ces & b) { /* up */ + SelectObject(hDC, hbWhite); + Rectangle(hDC, x, 232, x+9, 240); + SelectObject(hDC, hbGray); + Rectangle(hDC, x, 239, x+9, 255); + } + else { /* down */ + SelectObject(hDC, hbWhite); + Rectangle(hDC, x, 263, x+9, 271); + SelectObject(hDC, hbGray); + Rectangle(hDC, x, 248, x+9, 264); + } - x += (b & 0x1111) ? 31 : 21; - } + x += (b & 0x1111) ? 31 : 21; + } } /* ------------------------------------------------------------------------ @@ -962,25 +962,25 @@ static void DrawToggles (HDC hDC, int bits) void DrawRunmode (HDC hDC, int mode) { - double angle = (mode*45. + 90.) * 3.1415926 / 180.; /* convert mode position to angle in radians */ - double ca, sa; /* sine and cosine */ - int x0, y0, x1, y1; - HPEN hOldPen; + double angle = (mode*45. + 90.) * 3.1415926 / 180.; /* convert mode position to angle in radians */ + double ca, sa; /* sine and cosine */ + int x0, y0, x1, y1; + HPEN hOldPen; - ca = cos(angle); - sa = sin(angle); + ca = cos(angle); + sa = sin(angle); - x0 = RUNSWITCH_X + (int) (20.*ca + 0.5); /* inner radius */ - y0 = RUNSWITCH_Y - (int) (20.*sa + 0.5); - x1 = RUNSWITCH_X + (int) (25.*ca + 0.5); /* outer radius */ - y1 = RUNSWITCH_Y - (int) (25.*sa + 0.5); + x0 = RUNSWITCH_X + (int) (20.*ca + 0.5); /* inner radius */ + y0 = RUNSWITCH_Y - (int) (20.*sa + 0.5); + x1 = RUNSWITCH_X + (int) (25.*ca + 0.5); /* outer radius */ + y1 = RUNSWITCH_Y - (int) (25.*sa + 0.5); - hOldPen = SelectObject(hDC, hSwitchPen); + hOldPen = SelectObject(hDC, hSwitchPen); - MoveToEx(hDC, x0, y0, NULL); - LineTo(hDC, x1, y1); + MoveToEx(hDC, x0, y0, NULL); + LineTo(hDC, x1, y1); - SelectObject(hDC, hOldPen); + SelectObject(hDC, hOldPen); } /* ------------------------------------------------------------------------ @@ -991,37 +991,37 @@ void DrawRunmode (HDC hDC, int mode) static BOOL HandleClick (HWND hWnd, int xh, int yh, BOOL actual, BOOL rightclick) { - int b, x, r, ang, i; + int b, x, r, ang, i; - for (b = 0x8000, x = TOGGLES_X; b != 0; b >>= 1) { - if (BETWEEN(xh, x-3, x+8+3) && BETWEEN(yh, 230, 275)) { - if (actual) { - CES ^= b; /* a hit. Invert the bit and redisplay */ - update_gui(TRUE); - } - return TRUE; - } - x += (b & 0x1111) ? 31 : 21; - } + for (b = 0x8000, x = TOGGLES_X; b != 0; b >>= 1) { + if (BETWEEN(xh, x-3, x+8+3) && BETWEEN(yh, 230, 275)) { + if (actual) { + CES ^= b; /* a hit. Invert the bit and redisplay */ + update_gui(TRUE); + } + return TRUE; + } + x += (b & 0x1111) ? 31 : 21; + } - if (BETWEEN(xh, RUNSWITCH_X-50, RUNSWITCH_X+50) && BETWEEN(yh, RUNSWITCH_Y-50, RUNSWITCH_Y+50)) { /* hit near rotary switch */ - ang = (int) (atan2(RUNSWITCH_X-xh, RUNSWITCH_Y-yh)*180./3.1415926); /* this does implicit 90 deg rotation by the way */ - r = (int) sqrt((xh-RUNSWITCH_X)*(xh-RUNSWITCH_X)+(yh-RUNSWITCH_Y)*(yh-RUNSWITCH_Y)); - if (r > 12) { - for (i = MODE_LOAD; i <= MODE_INT_RUN; i++) { - if (BETWEEN(ang, i*45-12, i*45+12)) { - if (actual) { - RUNMODE = i; - update_gui(TRUE); - } - return TRUE; - } - } - - } - } + if (BETWEEN(xh, RUNSWITCH_X-50, RUNSWITCH_X+50) && BETWEEN(yh, RUNSWITCH_Y-50, RUNSWITCH_Y+50)) { /* hit near rotary switch */ + ang = (int) (atan2(RUNSWITCH_X-xh, RUNSWITCH_Y-yh)*180./3.1415926); /* this does implicit 90 deg rotation by the way */ + r = (int) sqrt((xh-RUNSWITCH_X)*(xh-RUNSWITCH_X)+(yh-RUNSWITCH_Y)*(yh-RUNSWITCH_Y)); + if (r > 12) { + for (i = MODE_LOAD; i <= MODE_INT_RUN; i++) { + if (BETWEEN(ang, i*45-12, i*45+12)) { + if (actual) { + RUNMODE = i; + update_gui(TRUE); + } + return TRUE; + } + } + + } + } - return FALSE; + return FALSE; } /* ------------------------------------------------------------------------ @@ -1035,85 +1035,85 @@ static BOOL HandleClick (HWND hWnd, int xh, int yh, BOOL actual, BOOL rightclick static void DrawConsole (HDC hDC, PAINTSTRUCT *ps) { - static char digits[] = " 0 1 2 3 4 5 6 7 8 9101112131415"; - static char cccs[] = "3216 8 4 2 1"; - static char cnds[] = " C V"; - static char waits[] = " W"; - HFONT hOldFont, hOldBrush; - RECT xout, xin; - int i, n; - DEVICE *dptr; - UNIT *uptr; - t_bool enab; - char nametemp[50], *dispname; + static char digits[] = " 0 1 2 3 4 5 6 7 8 9101112131415"; + static char cccs[] = "3216 8 4 2 1"; + static char cnds[] = " C V"; + static char waits[] = " W"; + HFONT hOldFont, hOldBrush; + RECT xout, xin; + int i, n; + DEVICE *dptr; + UNIT *uptr; + t_bool enab; + char nametemp[50], *dispname; - hOldFont = SelectObject(hDC, hFont); /* use that tiny font */ - hOldBrush = SelectObject(hDC, hbWhite); + hOldFont = SelectObject(hDC, hFont); /* use that tiny font */ + hOldBrush = SelectObject(hDC, hbWhite); - SetBkMode(hDC, TRANSPARENT); /* overlay letters w/o changing background */ + SetBkMode(hDC, TRANSPARENT); /* overlay letters w/o changing background */ - DrawBits(hDC, 76, 15, shown_iar, 16, mem_mask, digits); /* register holds only 15 bits */ - DrawBits(hDC, 76, 48, shown_sar, 16, mem_mask, digits); /* but let's display only used bits */ - DrawBits(hDC, 76, 81, shown_sbr, 16, 0xFFFF, digits); - DrawBits(hDC, 76, 114, shown_arf, 16, 0xFFFF, digits); - DrawBits(hDC, 76, 147, shown_acc, 16, 0xFFFF, digits); - DrawBits(hDC, 76, 180, shown_ext, 16, 0xFFFF, digits); + DrawBits(hDC, 76, 15, shown_iar, 16, mem_mask, digits); /* register holds only 15 bits */ + DrawBits(hDC, 76, 48, shown_sar, 16, mem_mask, digits); /* but let's display only used bits */ + DrawBits(hDC, 76, 81, shown_sbr, 16, 0xFFFF, digits); + DrawBits(hDC, 76, 114, shown_arf, 16, 0xFFFF, digits); + DrawBits(hDC, 76, 147, shown_acc, 16, 0xFFFF, digits); + DrawBits(hDC, 76, 180, shown_ext, 16, 0xFFFF, digits); - DrawBits(hDC, 506, 15, shown_op, 5, 0x001F, digits); - DrawBits(hDC, 506, 81, shown_tag, 4, 0x0007, digits); - DrawBits(hDC, 506, 114, shown_irq, 6, 0x003F, digits); - DrawBits(hDC, 506, 147, shown_ccc, 6, 0x003F, cccs); - DrawBits(hDC, 506, 180, shown_cnd, 2, 0x0003, cnds); + DrawBits(hDC, 506, 15, shown_op, 5, 0x001F, digits); + DrawBits(hDC, 506, 81, shown_tag, 4, 0x0007, digits); + DrawBits(hDC, 506, 114, shown_irq, 6, 0x003F, digits); + DrawBits(hDC, 506, 147, shown_ccc, 6, 0x003F, cccs); + DrawBits(hDC, 506, 180, shown_cnd, 2, 0x0003, cnds); - DrawBits(hDC, 390, 81, shown_wait?1:0,1, 0x0001, waits); + DrawBits(hDC, 390, 81, shown_wait?1:0,1, 0x0001, waits); - DrawToggles(hDC, shown_ces); + DrawToggles(hDC, shown_ces); - DrawRunmode(hDC, shown_runmode); + DrawRunmode(hDC, shown_runmode); - SelectObject(hDC, hOldFont); - SelectObject(hDC, hOldBrush); + SelectObject(hDC, hOldFont); + SelectObject(hDC, hOldBrush); - SetBkColor(hDC, RGB(0,0,0)); + SetBkColor(hDC, RGB(0,0,0)); - SetRect(&xin, TXTBOX_X, TXTBOX_Y, TXTBOX_X+TXTBOX_WIDTH, TXTBOX_BOTTOM+TXTBOX_HEIGHT); - if (IntersectRect(&xout, &xin, &ps->rcPaint)) { - hOldFont = SelectObject(hDC, hTinyFont); + SetRect(&xin, TXTBOX_X, TXTBOX_Y, TXTBOX_X+TXTBOX_WIDTH, TXTBOX_BOTTOM+TXTBOX_HEIGHT); + if (IntersectRect(&xout, &xin, &ps->rcPaint)) { + hOldFont = SelectObject(hDC, hTinyFont); - for (i = 0; i < NTXTBOXES; i++) { - enab = FALSE; + for (i = 0; i < NTXTBOXES; i++) { + enab = FALSE; - dptr = find_unit(txtbox[i].unitname, &uptr); - if (dptr != NULL && uptr != NULL) { - if (uptr->flags & UNIT_DIS) { - SetTextColor(hDC, RGB(128,0,0)); - } - else if (uptr->flags & UNIT_ATT) { - SetTextColor(hDC, RGB(0,0,255)); - if ((n = strlen(uptr->filename)) > 30) { - strcpy(nametemp, "..."); - strcpy(nametemp+3, uptr->filename+n-30); - dispname = nametemp; - } - else - dispname = uptr->filename; + dptr = find_unit(txtbox[i].unitname, &uptr); + if (dptr != NULL && uptr != NULL) { + if (uptr->flags & UNIT_DIS) { + SetTextColor(hDC, RGB(128,0,0)); + } + else if (uptr->flags & UNIT_ATT) { + SetTextColor(hDC, RGB(0,0,255)); + if ((n = strlen(uptr->filename)) > 30) { + strcpy(nametemp, "..."); + strcpy(nametemp+3, uptr->filename+n-30); + dispname = nametemp; + } + else + dispname = uptr->filename; - TextOut(hDC, txtbox[i].x+25, txtbox[i].y+TXTBOX_HEIGHT, dispname, strlen(dispname)); - SetTextColor(hDC, RGB(255,255,255)); - enab = TRUE; - } - else { - SetTextColor(hDC, RGB(128,128,128)); - } - TextOut(hDC, txtbox[i].x, txtbox[i].y, txtbox[i].txt, strlen(txtbox[i].txt)); - } + TextOut(hDC, txtbox[i].x+25, txtbox[i].y+TXTBOX_HEIGHT, dispname, strlen(dispname)); + SetTextColor(hDC, RGB(255,255,255)); + enab = TRUE; + } + else { + SetTextColor(hDC, RGB(128,128,128)); + } + TextOut(hDC, txtbox[i].x, txtbox[i].y, txtbox[i].txt, strlen(txtbox[i].txt)); + } - if (txtbox[i].idctrl >= 0) - EnableWindow(btn[txtbox[i].idctrl].hBtn, enab); - } + if (txtbox[i].idctrl >= 0) + EnableWindow(btn[txtbox[i].idctrl].hBtn, enab); + } - SelectObject(hDC, hOldFont); - } + SelectObject(hDC, hOldFont); + } } /* ------------------------------------------------------------------------ @@ -1123,146 +1123,146 @@ static void DrawConsole (HDC hDC, PAINTSTRUCT *ps) void flash_run (void) { - EnableWindow(btn[IDC_RUN].hBtn, TRUE); /* enable the run lamp */ + EnableWindow(btn[IDC_RUN].hBtn, TRUE); /* enable the run lamp */ - if (hFlashTimer != 0) - KillTimer(hConsoleWnd, FLASH_TIMER_ID); /* (re)schedule lamp update */ + if (hFlashTimer != 0) + KillTimer(hConsoleWnd, FLASH_TIMER_ID); /* (re)schedule lamp update */ - hFlashTimer = SetTimer(hConsoleWnd, FLASH_TIMER_ID, LAMPTIME, NULL); + hFlashTimer = SetTimer(hConsoleWnd, FLASH_TIMER_ID, LAMPTIME, NULL); } void gui_run (int running) { - if (running && hUpdateTimer == 0 && hConsoleWnd != NULL) { - hUpdateTimer = SetTimer(hConsoleWnd, UPDATE_TIMER_ID, 1000/UPDATE_INTERVAL, NULL); - } - else if (hUpdateTimer != 0 && ! running) { - KillTimer(hConsoleWnd, UPDATE_TIMER_ID); - hUpdateTimer = 0; - } - flash_run(); /* keep run lamp active for a while after we stop running */ + if (running && hUpdateTimer == 0 && hConsoleWnd != NULL) { + hUpdateTimer = SetTimer(hConsoleWnd, UPDATE_TIMER_ID, 1000/UPDATE_INTERVAL, NULL); + } + else if (hUpdateTimer != 0 && ! running) { + KillTimer(hConsoleWnd, UPDATE_TIMER_ID); + hUpdateTimer = 0; + } + flash_run(); /* keep run lamp active for a while after we stop running */ } void HandleCommand (HWND hWnd, WORD wNotify, WORD idCtl, HWND hwCtl) { - int i; + int i; - switch (idCtl) { - case IDC_POWER: /* toggle system power */ - power = ! power; - reset_all(0); - if (running && ! power) { /* turning off */ - reason = STOP_POWER_OFF; - /* wait for execution thread to exit */ + switch (idCtl) { + case IDC_POWER: /* toggle system power */ + power = ! power; + reset_all(0); + if (running && ! power) { /* turning off */ + reason = STOP_POWER_OFF; + /* wait for execution thread to exit */ /* this prevents message pump from running, which unfortunately locks up * the emulator thread when it calls gui_run(FALSE) which calls EnableWindow on the Run lamp - * while (running) - * Sleep(10); - */ - } + * while (running) + * Sleep(10); + */ + } - btn[IDC_POWER_ON].state = power; - EnableWindow(btn[IDC_POWER_ON].hBtn, power); + btn[IDC_POWER_ON].state = power; + EnableWindow(btn[IDC_POWER_ON].hBtn, power); - for (i = 0; i < NBUTTONS; i++) /* repaint all of the lamps */ - if (! btn[i].pushable) - InvalidateRect(btn[i].hBtn, NULL, TRUE); + for (i = 0; i < NBUTTONS; i++) /* repaint all of the lamps */ + if (! btn[i].pushable) + InvalidateRect(btn[i].hBtn, NULL, TRUE); - break; + break; - case IDC_PROGRAM_START: /* begin execution */ - if (! running) { - switch (RUNMODE) { - case MODE_INT_RUN: - case MODE_RUN: - case MODE_SI: - stuff_cmd("cont"); - break; + case IDC_PROGRAM_START: /* begin execution */ + if (! running) { + switch (RUNMODE) { + case MODE_INT_RUN: + case MODE_RUN: + case MODE_SI: + stuff_cmd("cont"); + break; - case MODE_DISP: /* display core and advance IAR */ - ReadW(IAR); - IAR = IAR+1; - flash_run(); /* illuminate run lamp for .5 sec */ - break; + case MODE_DISP: /* display core and advance IAR */ + ReadW(IAR); + IAR = IAR+1; + flash_run(); /* illuminate run lamp for .5 sec */ + break; - case MODE_LOAD: /* store to core and advance IAR */ - WriteW(IAR, CES); - IAR = IAR+1; - flash_run(); - break; - } - } - break; + case MODE_LOAD: /* store to core and advance IAR */ + WriteW(IAR, CES); + IAR = IAR+1; + flash_run(); + break; + } + } + break; - case IDC_PROGRAM_STOP: - if (running) { /* potential race condition here */ - GUI_BEGIN_CRITICAL_SECTION - SETBIT(con_dsw, CPU_DSW_PROGRAM_STOP); - SETBIT(ILSW[5], ILSW_5_INT_RUN_PROGRAM_STOP); - int_req |= INT_REQ_5; /* note: calc_ints() is not needed in this case */ - int_lamps |= INT_REQ_5; - GUI_END_CRITICAL_SECTION - } - break; + case IDC_PROGRAM_STOP: + if (running) { /* potential race condition here */ + GUI_BEGIN_CRITICAL_SECTION + SETBIT(con_dsw, CPU_DSW_PROGRAM_STOP); + SETBIT(ILSW[5], ILSW_5_INT_RUN_PROGRAM_STOP); + int_req |= INT_REQ_5; /* note: calc_ints() is not needed in this case */ + int_lamps |= INT_REQ_5; + GUI_END_CRITICAL_SECTION + } + break; - case IDC_LOAD_IAR: - if (! running) { - IAR = CES & mem_mask; /* set IAR from console entry switches */ - } - break; + case IDC_LOAD_IAR: + if (! running) { + IAR = CES & mem_mask; /* set IAR from console entry switches */ + } + break; - case IDC_KEYBOARD: /* toggle between console/keyboard mode */ - break; + case IDC_KEYBOARD: /* toggle between console/keyboard mode */ + break; - case IDC_IMM_STOP: - if (running) { - reason = STOP_IMMEDIATE; /* terminate execution without setting wait_mode */ - /* wait for execution thread to exit */ + case IDC_IMM_STOP: + if (running) { + reason = STOP_IMMEDIATE; /* terminate execution without setting wait_mode */ + /* wait for execution thread to exit */ /* this prevents message pump from running, which unfortunately locks up * the emulator thread when it calls gui_run(FALSE) which calls EnableWindow on the Run lamp - * while (running) - * Sleep(10); + * while (running) + * Sleep(10); */ - } - break; + } + break; - case IDC_RESET: - if (! running) { /* check-reset is disabled while running */ - reset_all(0); - forms_check(0); /* clear forms-check status */ - print_check(0); - } - break; + case IDC_RESET: + if (! running) { /* check-reset is disabled while running */ + reset_all(0); + forms_check(0); /* clear forms-check status */ + print_check(0); + } + break; - case IDC_PROGRAM_LOAD: - if (! running) { /* if card reader is attached to a file, do cold start read of one card */ - IAR = 0; /* reset IAR */ + case IDC_PROGRAM_LOAD: + if (! running) { /* if card reader is attached to a file, do cold start read of one card */ + IAR = 0; /* reset IAR */ #ifdef PROGRAM_LOAD_STARTS_CPU - stuff_cmd("boot cr"); + stuff_cmd("boot cr"); #else - if (cr_boot(0, NULL) != SCPE_OK) /* load boot card */ - remark_cmd("IPL failed"); + if (cr_boot(0, NULL) != SCPE_OK) /* load boot card */ + remark_cmd("IPL failed"); #endif - } - break; + } + break; - case IDC_TEAR: /* "tear off printer output" */ - case IDC_1132: /* do same if they click on the printer icon */ - if (btn[IDC_1132].state && (wNotify == STN_CLICKED || wNotify == STN_DBLCLK)) - tear_printer(); - break; + case IDC_TEAR: /* "tear off printer output" */ + case IDC_1132: /* do same if they click on the printer icon */ + if (btn[IDC_1132].state && (wNotify == STN_CLICKED || wNotify == STN_DBLCLK)) + tear_printer(); + break; - case IDC_1442: - if (btn[IDC_1442].state == STATE_1442_FULL || wNotify == STN_DBLCLK) - stuff_cmd("detach cr"); - else if (btn[IDC_1442].state != STATE_1442_EMPTY && wNotify == STN_CLICKED) { - cr_rewind(); - update_gui(TRUE); - } - break; - } - - update_gui(FALSE); + case IDC_1442: + if (btn[IDC_1442].state == STATE_1442_FULL || wNotify == STN_DBLCLK) + stuff_cmd("detach cr"); + else if (btn[IDC_1442].state != STATE_1442_EMPTY && wNotify == STN_CLICKED) { + cr_rewind(); + update_gui(TRUE); + } + break; + } + + update_gui(FALSE); } /* ------------------------------------------------------------------------ @@ -1271,223 +1271,223 @@ void HandleCommand (HWND hWnd, WORD wNotify, WORD idCtl, HWND hwCtl) LRESULT CALLBACK ConsoleWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { - HDC hDC; - PAINTSTRUCT ps; - POINT p; - RECT clip, xsect, rbmp; - int i; + HDC hDC; + PAINTSTRUCT ps; + POINT p; + RECT clip, xsect, rbmp; + int i; - switch (uMsg) { - case WM_CLOSE: - DestroyWindow(hWnd); - break; + switch (uMsg) { + case WM_CLOSE: + DestroyWindow(hWnd); + break; - case WM_DESTROY: - gui_run(FALSE); - hConsoleWnd = NULL; - break; + case WM_DESTROY: + gui_run(FALSE); + hConsoleWnd = NULL; + break; - case WM_ERASEBKGND: - hDC = (HDC) wParam; - GetClipBox(hDC, &clip); - SetRect(&rbmp, 0, 0, bmwid, bmht); - if (IntersectRect(&xsect, &clip, &rbmp)) - BitBlt(hDC, xsect.left, xsect.top, xsect.right-xsect.left+1, xsect.bottom-xsect.top+1, hCDC, xsect.left, xsect.top, SRCCOPY); - return TRUE; /* let Paint do this so we know what the update region is (ps.rcPaint) */ + case WM_ERASEBKGND: + hDC = (HDC) wParam; + GetClipBox(hDC, &clip); + SetRect(&rbmp, 0, 0, bmwid, bmht); + if (IntersectRect(&xsect, &clip, &rbmp)) + BitBlt(hDC, xsect.left, xsect.top, xsect.right-xsect.left+1, xsect.bottom-xsect.top+1, hCDC, xsect.left, xsect.top, SRCCOPY); + return TRUE; /* let Paint do this so we know what the update region is (ps.rcPaint) */ - case WM_PAINT: - hDC = BeginPaint(hWnd, &ps); - DrawConsole(hDC, &ps); - EndPaint(hWnd, &ps); - break; + case WM_PAINT: + hDC = BeginPaint(hWnd, &ps); + DrawConsole(hDC, &ps); + EndPaint(hWnd, &ps); + break; - case WM_COMMAND: /* button click */ - HandleCommand(hWnd, HIWORD(wParam), LOWORD(wParam), (HWND) lParam); - break; + case WM_COMMAND: /* button click */ + HandleCommand(hWnd, HIWORD(wParam), LOWORD(wParam), (HWND) lParam); + break; - case WM_CTLCOLOREDIT: /* text color for edit controls */ - SetBkColor((HDC) wParam, RGB(0,0,0)); - SetTextColor((HDC) wParam, RGB(255,255,255)); - break; + case WM_CTLCOLOREDIT: /* text color for edit controls */ + SetBkColor((HDC) wParam, RGB(0,0,0)); + SetTextColor((HDC) wParam, RGB(255,255,255)); + break; - case WM_DRAWITEM: - PaintButton((LPDRAWITEMSTRUCT) lParam); - break; + case WM_DRAWITEM: + PaintButton((LPDRAWITEMSTRUCT) lParam); + break; - case WM_SETCURSOR: - GetCursorPos(&p); - ScreenToClient(hWnd, &p); - SetCursor(HandleClick(hWnd, p.x, p.y, FALSE, FALSE) ? hcHand : hcArrow); - return TRUE; + case WM_SETCURSOR: + GetCursorPos(&p); + ScreenToClient(hWnd, &p); + SetCursor(HandleClick(hWnd, p.x, p.y, FALSE, FALSE) ? hcHand : hcArrow); + return TRUE; - case WM_LBUTTONDOWN: - HandleClick(hWnd, LOWORD(lParam), HIWORD(lParam), TRUE, FALSE); - break; + case WM_LBUTTONDOWN: + HandleClick(hWnd, LOWORD(lParam), HIWORD(lParam), TRUE, FALSE); + break; - case WM_RBUTTONDOWN: - HandleClick(hWnd, LOWORD(lParam), HIWORD(lParam), TRUE, TRUE); - break; + case WM_RBUTTONDOWN: + HandleClick(hWnd, LOWORD(lParam), HIWORD(lParam), TRUE, TRUE); + break; - case WM_CTLCOLORBTN: - i = GetWindowLong((HWND) lParam, GWL_ID); - if (BETWEEN(i, 0, NBUTTONS-1)) - return (LRESULT) (power && IsWindowEnabled((HWND) lParam) ? btn[i].hbrLit : btn[i].hbrDark); + case WM_CTLCOLORBTN: + i = GetWindowLong((HWND) lParam, GWL_ID); + if (BETWEEN(i, 0, NBUTTONS-1)) + return (LRESULT) (power && IsWindowEnabled((HWND) lParam) ? btn[i].hbrLit : btn[i].hbrDark); - case WM_TIMER: - if (wParam == FLASH_TIMER_ID && hFlashTimer != 0) { - KillTimer(hWnd, FLASH_TIMER_ID); - hFlashTimer = 0; - } - update_gui(FALSE); - break; + case WM_TIMER: + if (wParam == FLASH_TIMER_ID && hFlashTimer != 0) { + KillTimer(hWnd, FLASH_TIMER_ID); + hFlashTimer = 0; + } + update_gui(FALSE); + break; - case WM_DROPFILES: - accept_dropped_file((HANDLE) wParam); /* console window - dragged file is a script or card deck */ - break; + case WM_DROPFILES: + accept_dropped_file((HANDLE) wParam); /* console window - dragged file is a script or card deck */ + break; - default: - return DefWindowProc(hWnd, uMsg, wParam, lParam); - } + default: + return DefWindowProc(hWnd, uMsg, wParam, lParam); + } - return 0; + return 0; } enum {PRINTER_OK = 0, FORMS_CHECK = 1, PRINT_CHECK = 2, BOTH_CHECK = 3} printerstatus = PRINTER_OK; void forms_check (int set) { - COLORREF oldcolor = btn[IDC_FORMS_CHECK].clr; + COLORREF oldcolor = btn[IDC_FORMS_CHECK].clr; - if (set) - SETBIT(printerstatus, FORMS_CHECK); - else - CLRBIT(printerstatus, FORMS_CHECK); + if (set) + SETBIT(printerstatus, FORMS_CHECK); + else + CLRBIT(printerstatus, FORMS_CHECK); - btn[IDC_FORMS_CHECK].clr = (printerstatus & PRINT_CHECK) ? RGB(255,0,0) : RGB(255,255,0); + btn[IDC_FORMS_CHECK].clr = (printerstatus & PRINT_CHECK) ? RGB(255,0,0) : RGB(255,255,0); - btn[IDC_FORMS_CHECK].state = printerstatus; + btn[IDC_FORMS_CHECK].state = printerstatus; - if (btn[IDC_FORMS_CHECK].hBtn != NULL) { - EnableWindow(btn[IDC_FORMS_CHECK].hBtn, printerstatus); + if (btn[IDC_FORMS_CHECK].hBtn != NULL) { + EnableWindow(btn[IDC_FORMS_CHECK].hBtn, printerstatus); - if (btn[IDC_FORMS_CHECK].clr != oldcolor) - InvalidateRect(btn[IDC_FORMS_CHECK].hBtn, NULL, TRUE); /* change color in any case */ - } + if (btn[IDC_FORMS_CHECK].clr != oldcolor) + InvalidateRect(btn[IDC_FORMS_CHECK].hBtn, NULL, TRUE); /* change color in any case */ + } } void print_check (int set) { - COLORREF oldcolor = btn[IDC_FORMS_CHECK].clr; + COLORREF oldcolor = btn[IDC_FORMS_CHECK].clr; - if (set) - SETBIT(printerstatus, PRINT_CHECK); - else - CLRBIT(printerstatus, PRINT_CHECK); + if (set) + SETBIT(printerstatus, PRINT_CHECK); + else + CLRBIT(printerstatus, PRINT_CHECK); - btn[IDC_FORMS_CHECK].clr = (printerstatus & PRINT_CHECK) ? RGB(255,0,0) : RGB(255,255,0); + btn[IDC_FORMS_CHECK].clr = (printerstatus & PRINT_CHECK) ? RGB(255,0,0) : RGB(255,255,0); - btn[IDC_FORMS_CHECK].state = printerstatus; + btn[IDC_FORMS_CHECK].state = printerstatus; - if (btn[IDC_FORMS_CHECK].hBtn != NULL) { - EnableWindow(btn[IDC_FORMS_CHECK].hBtn, printerstatus); + if (btn[IDC_FORMS_CHECK].hBtn != NULL) { + EnableWindow(btn[IDC_FORMS_CHECK].hBtn, printerstatus); - if (btn[IDC_FORMS_CHECK].clr != oldcolor) - InvalidateRect(btn[IDC_FORMS_CHECK].hBtn, NULL, TRUE); /* change color in any case */ - } + if (btn[IDC_FORMS_CHECK].clr != oldcolor) + InvalidateRect(btn[IDC_FORMS_CHECK].hBtn, NULL, TRUE); /* change color in any case */ + } } void keyboard_selected (int select) { - btn[IDC_KEYBOARD_SELECT].state = select; + btn[IDC_KEYBOARD_SELECT].state = select; - if (btn[IDC_KEYBOARD_SELECT].hBtn != NULL) - EnableWindow(btn[IDC_KEYBOARD_SELECT].hBtn, select); + if (btn[IDC_KEYBOARD_SELECT].hBtn != NULL) + EnableWindow(btn[IDC_KEYBOARD_SELECT].hBtn, select); } void disk_ready (int ready) { - btn[IDC_FILE_READY].state = ready; + btn[IDC_FILE_READY].state = ready; - if (btn[IDC_FILE_READY].hBtn != NULL) - EnableWindow(btn[IDC_FILE_READY].hBtn, ready); + if (btn[IDC_FILE_READY].hBtn != NULL) + EnableWindow(btn[IDC_FILE_READY].hBtn, ready); } void disk_unlocked (int unlocked) { - btn[IDC_DISK_UNLOCK].state = unlocked; + btn[IDC_DISK_UNLOCK].state = unlocked; - if (btn[IDC_DISK_UNLOCK].hBtn != NULL) - EnableWindow(btn[IDC_DISK_UNLOCK].hBtn, unlocked); + if (btn[IDC_DISK_UNLOCK].hBtn != NULL) + EnableWindow(btn[IDC_DISK_UNLOCK].hBtn, unlocked); } static void accept_dropped_file (HANDLE hDrop) { - int nfiles; - char fname[MAX_PATH], cmd[MAX_PATH+50], *deckfile; - BOOL cardreader; - POINT pt; - HWND hWndDrop; + int nfiles; + char fname[MAX_PATH], cmd[MAX_PATH+50], *deckfile; + BOOL cardreader; + POINT pt; + HWND hWndDrop; - nfiles = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0); /* get file count, */ - DragQueryFile(hDrop, 0, fname, sizeof(fname)); /* get first filename */ - DragQueryPoint(hDrop, &pt); /* get location of drop */ - DragFinish(hDrop); + nfiles = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0); /* get file count, */ + DragQueryFile(hDrop, 0, fname, sizeof(fname)); /* get first filename */ + DragQueryPoint(hDrop, &pt); /* get location of drop */ + DragFinish(hDrop); - if (nfiles <= 0) /* hmm, this seems unlikely to occur, but better check */ - return; + if (nfiles <= 0) /* hmm, this seems unlikely to occur, but better check */ + return; - if (running) { /* can only accept a drop while processor is stopped */ - MessageBeep(0); - return; - } + if (running) { /* can only accept a drop while processor is stopped */ + MessageBeep(0); + return; + } - if ((hWndDrop = ChildWindowFromPoint(hConsoleWnd, pt)) == btn[IDC_1442].hBtn) - cardreader = TRUE; /* file was dropped onto 1442 card reader */ - else if (hWndDrop == NULL || hWndDrop == hConsoleWnd) - cardreader = FALSE; /* file was dropped onto console window, not a button */ - else { - MessageBeep(0); /* file was dropped onto another button */ - return; - } + if ((hWndDrop = ChildWindowFromPoint(hConsoleWnd, pt)) == btn[IDC_1442].hBtn) + cardreader = TRUE; /* file was dropped onto 1442 card reader */ + else if (hWndDrop == NULL || hWndDrop == hConsoleWnd) + cardreader = FALSE; /* file was dropped onto console window, not a button */ + else { + MessageBeep(0); /* file was dropped onto another button */ + return; + } - if (nfiles > 1) { /* oops, we wouldn't know what order to read them in */ - MessageBox(hConsoleWnd, "You may only drop one file at a time", "", MB_OK); - return; - } + if (nfiles > 1) { /* oops, we wouldn't know what order to read them in */ + MessageBox(hConsoleWnd, "You may only drop one file at a time", "", MB_OK); + return; + } - /* if shift key is down, prepend @ to name (make it a deck file) */ - deckfile = ((GetKeyState(VK_SHIFT) & 0x8000) && cardreader) ? "@" : ""; + /* if shift key is down, prepend @ to name (make it a deck file) */ + deckfile = ((GetKeyState(VK_SHIFT) & 0x8000) && cardreader) ? "@" : ""; - sprintf(cmd, "%s \"%s%s\"", cardreader ? "attach cr" : "do", deckfile, fname); - stuff_cmd(cmd); + sprintf(cmd, "%s \"%s%s\"", cardreader ? "attach cr" : "do", deckfile, fname); + stuff_cmd(cmd); } static void tear_printer (void) { - char cmd[MAX_PATH+100], filename[MAX_PATH]; + char cmd[MAX_PATH+100], filename[MAX_PATH]; - if ((prt_unit.flags & UNIT_ATT) == 0) - return; + if ((prt_unit.flags & UNIT_ATT) == 0) + return; - strcpy(filename, prt_unit.filename); /* save current attached filename */ + strcpy(filename, prt_unit.filename); /* save current attached filename */ - if (! stuff_and_wait("detach prt", 1000, 0)) /* detach it */ - return; + if (! stuff_and_wait("detach prt", 1000, 0)) /* detach it */ + return; - sprintf(cmd, "view \"%s\"", filename); /* spawn notepad to view it */ - if (! stuff_and_wait(cmd, 3000, 500)) - return; + sprintf(cmd, "view \"%s\"", filename); /* spawn notepad to view it */ + if (! stuff_and_wait(cmd, 3000, 500)) + return; - remove(filename); /* delete the file */ + remove(filename); /* delete the file */ - sprintf(cmd, "attach prt \"%s\"", filename); /* reattach */ - stuff_cmd(cmd); + sprintf(cmd, "attach prt \"%s\"", filename); /* reattach */ + stuff_cmd(cmd); } #ifdef XXX - if ((hBtn = CreateWindow("BUTTON", btn[i].txt, WS_CHILD|WS_VISIBLE|BS_CENTER|BS_MULTILINE|BS_OWNERDRAW, - x, y, BUTTON_WIDTH, BUTTON_HEIGHT, hwParent, (HMENU) i, hInstance, NULL)) == NULL) - return NULL; + if ((hBtn = CreateWindow("BUTTON", btn[i].txt, WS_CHILD|WS_VISIBLE|BS_CENTER|BS_MULTILINE|BS_OWNERDRAW, + x, y, BUTTON_WIDTH, BUTTON_HEIGHT, hwParent, (HMENU) i, hInstance, NULL)) == NULL) + return NULL; #endif @@ -1495,19 +1495,19 @@ CRITICAL_SECTION critsect; void begin_critical_section (void) { - static BOOL mustinit = TRUE; + static BOOL mustinit = TRUE; - if (mustinit) { - InitializeCriticalSection(&critsect); - mustinit = FALSE; - } + if (mustinit) { + InitializeCriticalSection(&critsect); + mustinit = FALSE; + } - EnterCriticalSection(&critsect); + EnterCriticalSection(&critsect); } void end_critical_section (void) { - LeaveCriticalSection(&critsect); + LeaveCriticalSection(&critsect); } #ifndef MIN @@ -1528,56 +1528,56 @@ static char cmdbuffer[256]; static DWORD WINAPI CmdThread (LPVOID arg) { - for (;;) { - WaitForSingleObject(hCmdReadEvent, INFINITE); /* wait for request */ - read_line(cmdbuffer, sizeof(cmdbuffer), stdin); /* read one line */ - scp_stuffed = FALSE; /* say how we got it */ - scp_reading = FALSE; - SetEvent(hCmdReadyEvent); /* notify main thread a line is ready */ - } - return 0; -} + for (;;) { + WaitForSingleObject(hCmdReadEvent, INFINITE); /* wait for request */ + read_line(cmdbuffer, sizeof(cmdbuffer), stdin); /* read one line */ + scp_stuffed = FALSE; /* say how we got it */ + scp_reading = FALSE; + SetEvent(hCmdReadyEvent); /* notify main thread a line is ready */ + } + return 0; +} char *read_cmdline (char *ptr, int size, FILE *stream) { - char *cptr; + char *cptr; - if (hCmdThread == NULL) { /* set up command-reading thread */ - if ((hCmdReadEvent = CreateEvent(NULL, FALSE, FALSE, NULL)) == NULL) - scp_panic("Can't create command line read event"); + if (hCmdThread == NULL) { /* set up command-reading thread */ + if ((hCmdReadEvent = CreateEvent(NULL, FALSE, FALSE, NULL)) == NULL) + scp_panic("Can't create command line read event"); - if ((hCmdReadyEvent = CreateEvent(NULL, FALSE, FALSE, NULL)) == NULL) - scp_panic("Can't create command line ready event"); - /* start up the command thread */ - if ((hCmdThread = CreateThread(NULL, 0, CmdThread, NULL, 0, &iCmdThreadID)) == NULL) - scp_panic("Unable to create command line reading thread"); - } + if ((hCmdReadyEvent = CreateEvent(NULL, FALSE, FALSE, NULL)) == NULL) + scp_panic("Can't create command line ready event"); + /* start up the command thread */ + if ((hCmdThread = CreateThread(NULL, 0, CmdThread, NULL, 0, &iCmdThreadID)) == NULL) + scp_panic("Unable to create command line reading thread"); + } - scp_reading = TRUE; + scp_reading = TRUE; - SetEvent(hCmdReadEvent); /* let read thread get one line */ - WaitForSingleObject(hCmdReadyEvent, INFINITE); /* wait for read thread or GUI to respond */ - strncpy(ptr, cmdbuffer, MIN(size, sizeof(cmdbuffer))); /* copy line to caller's buffer */ + SetEvent(hCmdReadEvent); /* let read thread get one line */ + WaitForSingleObject(hCmdReadyEvent, INFINITE); /* wait for read thread or GUI to respond */ + strncpy(ptr, cmdbuffer, MIN(size, sizeof(cmdbuffer))); /* copy line to caller's buffer */ - for (cptr = ptr; isspace(*cptr); cptr++) /* absorb spaces */ - ; + for (cptr = ptr; isspace(*cptr); cptr++) /* absorb spaces */ + ; - if (scp_stuffed) { /* stuffed command needs to be echoed */ - sim_printf("%s\n", cptr); - } + if (scp_stuffed) { /* stuffed command needs to be echoed */ + sim_printf("%s\n", cptr); + } - return cptr; + return cptr; } /* stuff_cmd - force a command into the read_cmdline output buffer. Called asynchronously by GUI */ void stuff_cmd (char *cmd) { - strcpy(cmdbuffer, cmd); /* save the string */ - scp_stuffed = TRUE; /* note where it came from */ - scp_reading = FALSE; - ResetEvent(hCmdReadEvent); /* clear read request event */ - SetEvent(hCmdReadyEvent); /* notify main thread a line is ready */ + strcpy(cmdbuffer, cmd); /* save the string */ + scp_stuffed = TRUE; /* note where it came from */ + scp_reading = FALSE; + ResetEvent(hCmdReadEvent); /* clear read request event */ + SetEvent(hCmdReadyEvent); /* notify main thread a line is ready */ } /* my_yield - process GUI messages. It's not apparent why stuff_and_wait would block, @@ -1588,11 +1588,11 @@ void stuff_cmd (char *cmd) */ static void my_yield (void) { - MSG msg; - /* multitask */ + MSG msg; + /* multitask */ while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { - TranslateMessage(&msg); - DispatchMessage(&msg); + TranslateMessage(&msg); + DispatchMessage(&msg); } } @@ -1602,30 +1602,30 @@ static void my_yield (void) t_bool stuff_and_wait (char *cmd, int timeout, int delay) { - scp_reading = FALSE; + scp_reading = FALSE; - stuff_cmd(cmd); + stuff_cmd(cmd); - while (! scp_reading) { - if (timeout < 0) - return FALSE; + while (! scp_reading) { + if (timeout < 0) + return FALSE; - my_yield(); - if (scp_reading) - break; + my_yield(); + if (scp_reading) + break; - Sleep(50); - if (timeout) - if ((timeout -= 50) <= 0) - timeout = -1; + Sleep(50); + if (timeout) + if ((timeout -= 50) <= 0) + timeout = -1; - my_yield(); - } + my_yield(); + } - if (delay) - Sleep(delay); + if (delay) + Sleep(delay); - return TRUE; + return TRUE; } /* remark_cmd - print a remark from inside a command processor. This routine takes @@ -1635,16 +1635,16 @@ t_bool stuff_and_wait (char *cmd, int timeout, int delay) void remark_cmd (char *remark) { - if (scp_reading) { - putchar('\n'); - if (sim_log) putc('\n', sim_log); - } + if (scp_reading) { + putchar('\n'); + if (sim_log) putc('\n', sim_log); + } - sim_printf("%s\n", remark); + sim_printf("%s\n", remark); - if (scp_reading) - sim_printf("%s", sim_prompt); + if (scp_reading) + sim_printf("%s", sim_prompt); } -#endif /* _WIN32 defined */ -#endif /* GUI_SUPPORT defined */ +#endif /* _WIN32 defined */ +#endif /* GUI_SUPPORT defined */ diff --git a/Ibm1130/ibm1130_plot.c b/Ibm1130/ibm1130_plot.c index 07c39347..14b61662 100644 --- a/Ibm1130/ibm1130_plot.c +++ b/Ibm1130/ibm1130_plot.c @@ -23,20 +23,20 @@ #ifndef ENABLE_PLOT_SUPPORT - DEVICE plot_dev = { - "PLOT", NULL, NULL, NULL, - 0, 16, 16, 1, 16, 16, - NULL, NULL, NULL, - NULL, NULL, NULL}; + DEVICE plot_dev = { + "PLOT", NULL, NULL, NULL, + 0, 16, 16, 1, 16, 16, + NULL, NULL, NULL, + NULL, NULL, NULL}; - void xio_1627_plotter (int32 addr, int32 func, int32 modify) - { - /* silently eat any plotter commands */ - } + void xio_1627_plotter (int32 addr, int32 func, int32 modify) + { + /* silently eat any plotter commands */ + } #else -#define NONDLL // I am linking statically to avoid some issues. +#define NONDLL // I am linking statically to avoid some issues. #include "gd.h" /*************************************************************************************** @@ -78,118 +78,118 @@ * licensing issues. * * NOTE: On Windows, you need to either: - * + compile both LIBGD and SIMH to use the static C runtime libraries, compile - * LIBGD to a static library, and link LIBGD into ibm1130.exe (which is - * what we do at IBM1130.org, so that gd is built into the version of ibm1130.exe - * we distribute), or, - * + Compile both LIBGD and IBM1130 to use the DLL version of the C runtime, and compile - * GD to either a static library or a DLL, but, static is easier since you don't - * need to copy LIBGD.DLL along with ibm1130.exe + * + compile both LIBGD and SIMH to use the static C runtime libraries, compile + * LIBGD to a static library, and link LIBGD into ibm1130.exe (which is + * what we do at IBM1130.org, so that gd is built into the version of ibm1130.exe + * we distribute), or, + * + Compile both LIBGD and IBM1130 to use the DLL version of the C runtime, and compile + * GD to either a static library or a DLL, but, static is easier since you don't + * need to copy LIBGD.DLL along with ibm1130.exe * * SIMH commands: * * attach [-w] plot filename.gif - * Creates file filename.gif and attaches the plotter device to it. + * Creates file filename.gif and attaches the plotter device to it. * The file is empty at this point. The pen is raised. If the -w option is specified, and the - * simulator does not draw on the plotter between attach and detach, the gif file will be deleted - * on detach. (This is useful for the the cgi version of the simulator). + * simulator does not draw on the plotter between attach and detach, the gif file will be deleted + * on detach. (This is useful for the the cgi version of the simulator). * * detach plot filename.gif - * Detach the plot device. The gif data is written at this point, not before. - * If the -w flag was used on attach, and there was no plot activity, the gif file will be deleted. + * Detach the plot device. The gif data is written at this point, not before. + * If the -w flag was used on attach, and there was no plot activity, the gif file will be deleted. * * set plot black | red | blue | green | yellow | purple | lgrey | grey - * Sets the pen to the named color. Default is black. + * Sets the pen to the named color. Default is black. * * set plot 1.0 | 2.0 | 3.0 | 4.0 - * Sets the pen thickness to the specified number of hundredths of an inch. Default is 1.0 + * Sets the pen thickness to the specified number of hundredths of an inch. Default is 1.0 * * set plot penup | pendown - * Moves the pen up or down (onto the paper). + * Moves the pen up or down (onto the paper). * * set plot length NNN - * Sets the plot length (plotter X direction, GIF vertical dimension) to the NNN hundredths of - * an inch. Default is 800. The plot width (plotter Y direction, GIF horizontal dimension) is always - * 1100 (11 inches). NOTE: Changing this setting has no affect on the current plot. It takes affect at - * the next "attach plot" command. + * Sets the plot length (plotter X direction, GIF vertical dimension) to the NNN hundredths of + * an inch. Default is 800. The plot width (plotter Y direction, GIF horizontal dimension) is always + * 1100 (11 inches). NOTE: Changing this setting has no affect on the current plot. It takes affect at + * the next "attach plot" command. * * set plot xpos NNN * set plot ypos NNN - * Sets the pen x or y position to NNN hundredths of an inch. + * Sets the pen x or y position to NNN hundredths of an inch. * * (You cannot manually create a plot by issuing set plot pendown, xpos and ypos commands. The xpos and ypos * settings only change the starting point for the simulated program). ***************************************************************************************/ -#define PLOT1627_DSW_OP_COMPLETE 0x8000 -#define PLOT1627_DSW_BUSY 0x0200 -#define PLOT1627_DSW_NOT_READY 0x0100 +#define PLOT1627_DSW_OP_COMPLETE 0x8000 +#define PLOT1627_DSW_BUSY 0x0200 +#define PLOT1627_DSW_NOT_READY 0x0100 #define IS_ONLINE(u) (((u)->flags & (UNIT_ATT|UNIT_DIS)) == UNIT_ATT) -#define IS_DEBUG ((plot_unit->flags & UNIT_DEBUG) == UNIT_DEBUG) -#define IS_PENDOWN ((plot_unit->flags & UNIT_PEN) != 0) +#define IS_DEBUG ((plot_unit->flags & UNIT_DEBUG) == UNIT_DEBUG) +#define IS_PENDOWN ((plot_unit->flags & UNIT_PEN) != 0) -static t_stat plot_svc (UNIT *uptr); /* activity routine */ -static t_stat plot_reset (DEVICE *dptr); /* reset of 1130 */ -static t_stat plot_attach (UNIT *uptr, CONST char *cptr); /* attach, loads plotter */ -static t_stat plot_detach (UNIT *uptr); /* detach and save image */ -static t_stat plot_examine (UNIT *uptr); /* update file with current canvas */ -static t_stat plot_set_length (UNIT *uptr, int32 val, char * ptr, void *desc); /* set paper length */ -static t_stat plot_set_pos (UNIT *uptr, int32 val, CONST char * ptr, void *desc); /* reset current X/Y position */ -static t_stat plot_show_vals(FILE *fp, UNIT *uptr, int32 val, CONST void *descrip); /* print x, y and length */ -static t_stat plot_show_nl(FILE *fp, UNIT *uptr, int32 val, CONST void *descrip); /* overcome wacky simh behavior */ -static void update_pen(void); /* will ensure pen action is correct when changes made */ +static t_stat plot_svc (UNIT *uptr); /* activity routine */ +static t_stat plot_reset (DEVICE *dptr); /* reset of 1130 */ +static t_stat plot_attach (UNIT *uptr, CONST char *cptr); /* attach, loads plotter */ +static t_stat plot_detach (UNIT *uptr); /* detach and save image */ +static t_stat plot_examine (UNIT *uptr); /* update file with current canvas */ +static t_stat plot_set_length (UNIT *uptr, int32 val, char * ptr, void *desc); /* set paper length */ +static t_stat plot_set_pos (UNIT *uptr, int32 val, CONST char * ptr, void *desc); /* reset current X/Y position */ +static t_stat plot_show_vals(FILE *fp, UNIT *uptr, int32 val, CONST void *descrip); /* print x, y and length */ +static t_stat plot_show_nl(FILE *fp, UNIT *uptr, int32 val, CONST void *descrip); /* overcome wacky simh behavior */ +static void update_pen(void); /* will ensure pen action is correct when changes made */ static t_stat plot_validate_change (UNIT *uptr, int32 val, CONST char * ptr, void *desc); /* when set command issued */ -static void process_cmd(void); /* does actual drawing for plotter */ +static void process_cmd(void); /* does actual drawing for plotter */ -static int16 plot_dsw = 0; /* device status word */ -static int16 plot_cmd = 0; /* the command to process */ -static int32 plot_wait = 1000; /* plotter movement wait */ -static int32 plot_xpos = 0; /* current X position */ -static int32 plot_xmax = 799; /* end of paper */ -static int32 plot_ypos = 0; /* current Y position */ -static int32 plot_ymax = 1099; /* right edge of carriage */ +static int16 plot_dsw = 0; /* device status word */ +static int16 plot_cmd = 0; /* the command to process */ +static int32 plot_wait = 1000; /* plotter movement wait */ +static int32 plot_xpos = 0; /* current X position */ +static int32 plot_xmax = 799; /* end of paper */ +static int32 plot_ypos = 0; /* current Y position */ +static int32 plot_ymax = 1099; /* right edge of carriage */ #define PEN_DOWN 0x80000000 #define PEN_UP 0x00000000 -static int32 plot_pen = PEN_UP; /* current pen position. This duplicates the device flag PLOT_PEN. Makes the show dev plot command nicer. */ +static int32 plot_pen = PEN_UP; /* current pen position. This duplicates the device flag PLOT_PEN. Makes the show dev plot command nicer. */ -static int black_pen; /* holds color black */ -static int blue_pen; /* holds color blue */ -static int red_pen; /* holds color red */ -static int green_pen; /* holds color green */ +static int black_pen; /* holds color black */ +static int blue_pen; /* holds color blue */ +static int red_pen; /* holds color red */ +static int green_pen; /* holds color green */ static int yellow_pen; /* holds yellow color */ -static int purple_pen; /* holds color purple */ +static int purple_pen; /* holds color purple */ static int ltgrey_pen; /* holds light grey */ static int grey_pen; /* holds grey */ -static int white_background; /* holds white of paper roll */ -static int plot_pwidth; /* set and display variable */ -static int plot_pcolor; /* set and display variable */ -static int need_update = FALSE; /* flag to force and update_pen() */ -static int plot_used = FALSE; /* flag set to true if anything was actually plotted between attach and detach */ -static int delete_if_unused = FALSE; /* if TRUE and no plotter activity was seen, delete file on detach. This flag is set by -w option on attach command. */ -static gdImagePtr image = NULL; /* pointer to our canvas */ +static int white_background; /* holds white of paper roll */ +static int plot_pwidth; /* set and display variable */ +static int plot_pcolor; /* set and display variable */ +static int need_update = FALSE; /* flag to force and update_pen() */ +static int plot_used = FALSE; /* flag set to true if anything was actually plotted between attach and detach */ +static int delete_if_unused = FALSE; /* if TRUE and no plotter activity was seen, delete file on detach. This flag is set by -w option on attach command. */ +static gdImagePtr image = NULL; /* pointer to our canvas */ -#define UNIT_V_COLOR (UNIT_V_UF + 0) /* color of selected pen - 3 bits */ -#define UNIT_V_WIDTH (UNIT_V_UF + 3) /* width of pen - two bits */ +#define UNIT_V_COLOR (UNIT_V_UF + 0) /* color of selected pen - 3 bits */ +#define UNIT_V_WIDTH (UNIT_V_UF + 3) /* width of pen - two bits */ #define UNIT_V_NOOP (UNIT_V_UF + 5) /* dummy for set/show commands */ #define UNIT_V_DEBUG (UNIT_V_UF + 6) /* for -d switch on attach command */ #define UNIT_V_PEN (UNIT_V_UF + 7) /* track pen state */ -#define UNIT_WIDTH (3u << UNIT_V_WIDTH) /* two bits */ -#define UNIT_COLOR (7u << UNIT_V_COLOR) /* three bits */ +#define UNIT_WIDTH (3u << UNIT_V_WIDTH) /* two bits */ +#define UNIT_COLOR (7u << UNIT_V_COLOR) /* three bits */ #define UNIT_NOOP (1u << UNIT_V_NOOP) /* dummy for set/show */ #define UNIT_DEBUG (1u << UNIT_V_DEBUG) /* shows debug mode on */ #define UNIT_PEN (1u << UNIT_V_PEN) /* the pen state bit */ -#define PEN_BLACK (0u << UNIT_V_COLOR) -#define PEN_RED (1u << UNIT_V_COLOR) -#define PEN_BLUE (2u << UNIT_V_COLOR) -#define PEN_GREEN (3u << UNIT_V_COLOR) -#define PEN_YELLOW (4u << UNIT_V_COLOR) -#define PEN_PURPLE (5u << UNIT_V_COLOR) -#define PEN_LTGREY (6u << UNIT_V_COLOR) -#define PEN_GREY (7u << UNIT_V_COLOR) +#define PEN_BLACK (0u << UNIT_V_COLOR) +#define PEN_RED (1u << UNIT_V_COLOR) +#define PEN_BLUE (2u << UNIT_V_COLOR) +#define PEN_GREEN (3u << UNIT_V_COLOR) +#define PEN_YELLOW (4u << UNIT_V_COLOR) +#define PEN_PURPLE (5u << UNIT_V_COLOR) +#define PEN_LTGREY (6u << UNIT_V_COLOR) +#define PEN_GREY (7u << UNIT_V_COLOR) #define SET_COLOR(op) (plot_unit[0].flags = (plot_unit[0].flags & ~UNIT_COLOR) | (op)) #define GET_COLOR (plot_unit[0].flags & UNIT_COLOR) @@ -204,40 +204,40 @@ static gdImagePtr image = NULL; /* pointer to our canvas */ #define GREY 120,120,120 #define WHITE 255,255,255 -#define PEN_SINGLE (0u << UNIT_V_WIDTH) -#define PEN_DOUBLE (1u << UNIT_V_WIDTH) +#define PEN_SINGLE (0u << UNIT_V_WIDTH) +#define PEN_DOUBLE (1u << UNIT_V_WIDTH) #define PEN_TRIPLE (2u << UNIT_V_WIDTH) -#define PEN_QUAD (3u << UNIT_V_WIDTH) +#define PEN_QUAD (3u << UNIT_V_WIDTH) -#define GET_WIDTH() (plot_unit[0].flags & UNIT_WIDTH) -#define SET_WIDTH(cd) (plot_unit[0].flags = (plot_unit[0].flags & ~UNIT_WIDTH) | (cd)) +#define GET_WIDTH() (plot_unit[0].flags & UNIT_WIDTH) +#define SET_WIDTH(cd) (plot_unit[0].flags = (plot_unit[0].flags & ~UNIT_WIDTH) | (cd)) UNIT plot_unit[] = { - { UDATA (&plot_svc, UNIT_ATTABLE, 0) }, + { UDATA (&plot_svc, UNIT_ATTABLE, 0) }, }; REG plot_reg[] = { - { HRDATA (DSW, plot_dsw, 16) }, /* device status word */ - { DRDATA (WTIME, plot_wait, 24), PV_LEFT }, /* plotter movement wait */ - { DRDATA (Xpos, plot_xpos, 32), PV_LEFT }, /* Current X Position*/ - { DRDATA (Ypos, plot_ypos, 32), PV_LEFT }, /* Current Y Position*/ - { FLDATA (PenDown, plot_pen, 0)}, /* Current pen position: 1 = down */ + { HRDATA (DSW, plot_dsw, 16) }, /* device status word */ + { DRDATA (WTIME, plot_wait, 24), PV_LEFT }, /* plotter movement wait */ + { DRDATA (Xpos, plot_xpos, 32), PV_LEFT }, /* Current X Position*/ + { DRDATA (Ypos, plot_ypos, 32), PV_LEFT }, /* Current Y Position*/ + { FLDATA (PenDown, plot_pen, 0)}, /* Current pen position: 1 = down */ { DRDATA (PaperSize, plot_xmax, 32), PV_LEFT }, /* Length of paper in inches */ - { NULL } }; + { NULL } }; MTAB plot_mod[] = { - { UNIT_COLOR, PEN_BLACK, "black", "BLACK", &plot_validate_change}, - { UNIT_COLOR, PEN_RED, "red", "RED", &plot_validate_change}, - { UNIT_COLOR, PEN_BLUE, "blue", "BLUE", &plot_validate_change}, - { UNIT_COLOR, PEN_GREEN, "green", "GREEN", &plot_validate_change}, - { UNIT_COLOR, PEN_YELLOW, "yellow", "YELLOW", &plot_validate_change}, - { UNIT_COLOR, PEN_PURPLE, "purple", "PURPLE", &plot_validate_change}, - { UNIT_COLOR, PEN_LTGREY, "ltgrey", "LTGREY", &plot_validate_change}, - { UNIT_COLOR, PEN_GREY, "grey", "GREY", &plot_validate_change}, - { UNIT_WIDTH, PEN_SINGLE, "1.0", "1.0", &plot_validate_change}, - { UNIT_WIDTH, PEN_DOUBLE, "2.0", "2.0", &plot_validate_change}, - { UNIT_WIDTH, PEN_TRIPLE, "3.0", "3.0", &plot_validate_change}, - { UNIT_WIDTH, PEN_QUAD, "4.0", "4.0", &plot_validate_change}, + { UNIT_COLOR, PEN_BLACK, "black", "BLACK", &plot_validate_change}, + { UNIT_COLOR, PEN_RED, "red", "RED", &plot_validate_change}, + { UNIT_COLOR, PEN_BLUE, "blue", "BLUE", &plot_validate_change}, + { UNIT_COLOR, PEN_GREEN, "green", "GREEN", &plot_validate_change}, + { UNIT_COLOR, PEN_YELLOW, "yellow", "YELLOW", &plot_validate_change}, + { UNIT_COLOR, PEN_PURPLE, "purple", "PURPLE", &plot_validate_change}, + { UNIT_COLOR, PEN_LTGREY, "ltgrey", "LTGREY", &plot_validate_change}, + { UNIT_COLOR, PEN_GREY, "grey", "GREY", &plot_validate_change}, + { UNIT_WIDTH, PEN_SINGLE, "1.0", "1.0", &plot_validate_change}, + { UNIT_WIDTH, PEN_DOUBLE, "2.0", "2.0", &plot_validate_change}, + { UNIT_WIDTH, PEN_TRIPLE, "3.0", "3.0", &plot_validate_change}, + { UNIT_WIDTH, PEN_QUAD, "4.0", "4.0", &plot_validate_change}, { UNIT_PEN, UNIT_PEN, "pendown", "PENDOWN", &plot_validate_change}, { UNIT_PEN, 0, "penup", "PENUP", &plot_validate_change}, /* below is dummy entry to trigger the show routine and print extended values */ @@ -246,102 +246,102 @@ MTAB plot_mod[] = { * then they will print the value twice for a 'show plot' command * therefore they are set to not display unless explicity requested * and the special dummy NOOP entry will cause the print of these values */ - { MTAB_XTD | MTAB_VAL | MTAB_VUN | MTAB_VDV | MTAB_NMO, 2, - "length", "LENGTH", &plot_set_length, &plot_show_nl, &plot_reg[5]}, - { MTAB_XTD | MTAB_VAL | MTAB_VDV | MTAB_VUN | MTAB_NMO, 0, - "Xpos", "XPOS", &plot_set_pos, &plot_show_nl, &plot_reg[2]}, - { MTAB_XTD | MTAB_VAL | MTAB_VDV | MTAB_VUN | MTAB_NMO, 1, - "Ypos", "YPOS", &plot_set_pos, &plot_show_nl, &plot_reg[3]}, - { 0 } }; + { MTAB_XTD | MTAB_VAL | MTAB_VUN | MTAB_VDV | MTAB_NMO, 2, + "length", "LENGTH", &plot_set_length, &plot_show_nl, &plot_reg[5]}, + { MTAB_XTD | MTAB_VAL | MTAB_VDV | MTAB_VUN | MTAB_NMO, 0, + "Xpos", "XPOS", &plot_set_pos, &plot_show_nl, &plot_reg[2]}, + { MTAB_XTD | MTAB_VAL | MTAB_VDV | MTAB_VUN | MTAB_NMO, 1, + "Ypos", "YPOS", &plot_set_pos, &plot_show_nl, &plot_reg[3]}, + { 0 } }; DEVICE plot_dev = { - "PLOT", plot_unit, plot_reg, plot_mod, - 1, 16, 16, 1, 16, 16, - NULL, NULL, plot_reset, - NULL, plot_attach, plot_detach}; + "PLOT", plot_unit, plot_reg, plot_mod, + 1, 16, 16, 1, 16, 16, + NULL, NULL, plot_reset, + NULL, plot_attach, plot_detach}; /* xio_1627_plotter - XIO command interpreter for the 1627 plotter model 1 */ void xio_1627_plotter (int32 iocc_addr, int32 iocc_func, int32 iocc_mod) { - char msg[80]; - int16 v; + char msg[80]; + int16 v; - if (! IS_ONLINE(plot_unit) ) { - SETBIT(plot_dsw, PLOT1627_DSW_NOT_READY); /* set not ready */ + if (! IS_ONLINE(plot_unit) ) { + SETBIT(plot_dsw, PLOT1627_DSW_NOT_READY); /* set not ready */ if (IS_DEBUG) printf("Plotter has no paper, ignored\n"); - return; /* and ignore */ - } + return; /* and ignore */ + } - switch (iocc_func) { - case XIO_READ: /* read XIO */ - xio_error("Read XIO not supported by 1627 plotter"); - break; + switch (iocc_func) { + case XIO_READ: /* read XIO */ + xio_error("Read XIO not supported by 1627 plotter"); + break; - case XIO_WRITE: /* write: do one plotter operation */ - if ((plot_dsw & PLOT1627_DSW_NOT_READY)) { + case XIO_WRITE: /* write: do one plotter operation */ + if ((plot_dsw & PLOT1627_DSW_NOT_READY)) { if (IS_DEBUG) printf("Wrote to non-ready Plotter\n"); break; } - plot_cmd = (uint16) ( M[iocc_addr & mem_mask] >> 10 ); /* pick up command */ - process_cmd(); /* interpret command */ - sim_activate(plot_unit, plot_wait); /* schedule interrupt */ - SETBIT(plot_dsw, PLOT1627_DSW_BUSY); /* mark it busy */ - break; + plot_cmd = (uint16) ( M[iocc_addr & mem_mask] >> 10 ); /* pick up command */ + process_cmd(); /* interpret command */ + sim_activate(plot_unit, plot_wait); /* schedule interrupt */ + SETBIT(plot_dsw, PLOT1627_DSW_BUSY); /* mark it busy */ + break; - case XIO_SENSE_DEV: /* sense device status */ - ACC = plot_dsw; /* get current status */ - if (iocc_mod & 0x01) { /* reset interrupts */ - CLRBIT(plot_dsw, PLOT1627_DSW_OP_COMPLETE); - CLRBIT(ILSW[3], ILSW_3_1627_PLOTTER); - } - break; + case XIO_SENSE_DEV: /* sense device status */ + ACC = plot_dsw; /* get current status */ + if (iocc_mod & 0x01) { /* reset interrupts */ + CLRBIT(plot_dsw, PLOT1627_DSW_OP_COMPLETE); + CLRBIT(ILSW[3], ILSW_3_1627_PLOTTER); + } + break; - case XIO_CONTROL: /* control XIO */ - // xio_error("Control XIO not supported by 1627 plotter"); - // Well, not on a real 1130. But on our simulator, let's use XIO_CONTROL to - // allow programmatic control of the pen. Nifty, eh? - // - // Functions: XIO_CONTROL 0 clr - sets pen color (0=black, 1=red, 2=blue, 3=green, 4=yellow, 5=purple, 6=ltgrey, 7=grey) - // XIO_CONTRLL 1 wid - sets pen width (1..4) - // XIO_CONTROL 2 xpos - sets pen xpos - // XIO_CONTROL 3 ypos - sets pen ypos + case XIO_CONTROL: /* control XIO */ + // xio_error("Control XIO not supported by 1627 plotter"); + // Well, not on a real 1130. But on our simulator, let's use XIO_CONTROL to + // allow programmatic control of the pen. Nifty, eh? + // + // Functions: XIO_CONTROL 0 clr - sets pen color (0=black, 1=red, 2=blue, 3=green, 4=yellow, 5=purple, 6=ltgrey, 7=grey) + // XIO_CONTRLL 1 wid - sets pen width (1..4) + // XIO_CONTROL 2 xpos - sets pen xpos + // XIO_CONTROL 3 ypos - sets pen ypos - v = (int16) iocc_addr; /* get signed 16 bit value passed in addr arg */ - switch (iocc_mod) { - case 0: /* set pen color */ - if (BETWEEN(v,0,7)) { - SET_COLOR(v << UNIT_V_COLOR); - update_pen(); - } - break; + v = (int16) iocc_addr; /* get signed 16 bit value passed in addr arg */ + switch (iocc_mod) { + case 0: /* set pen color */ + if (BETWEEN(v,0,7)) { + SET_COLOR(v << UNIT_V_COLOR); + update_pen(); + } + break; - case 1: /* set pen width 1..4*/ - if (BETWEEN(v,1,4)) { - SET_WIDTH((v-1) << UNIT_V_WIDTH); - update_pen(); - } - break; + case 1: /* set pen width 1..4*/ + if (BETWEEN(v,1,4)) { + SET_WIDTH((v-1) << UNIT_V_WIDTH); + update_pen(); + } + break; - case 2: /* set xpos. (Programmatic xpos and ypos are probably not that valuable) */ - plot_xpos = v; /* Note that it's possible to move the pen way off the paper */ - break; + case 2: /* set xpos. (Programmatic xpos and ypos are probably not that valuable) */ + plot_xpos = v; /* Note that it's possible to move the pen way off the paper */ + break; - case 3: /* set ypos. Clip to valid range! */ - if (v <= 0) - plot_ypos = 0; - else if (v > plot_ymax) - plot_ypos = plot_ymax; - else - plot_ypos = v; - break; - } - break; + case 3: /* set ypos. Clip to valid range! */ + if (v <= 0) + plot_ypos = 0; + else if (v > plot_ymax) + plot_ypos = plot_ymax; + else + plot_ypos = v; + break; + } + break; - default: - sprintf(msg, "Invalid 1627 Plotter XIO function %x", iocc_func); - xio_error(msg); - } + default: + sprintf(msg, "Invalid 1627 Plotter XIO function %x", iocc_func); + xio_error(msg); + } return; } @@ -349,14 +349,14 @@ void xio_1627_plotter (int32 iocc_addr, int32 iocc_func, int32 iocc_mod) static t_stat plot_svc (UNIT *uptr) { - CLRBIT(plot_dsw, PLOT1627_DSW_BUSY); /* clear reader busy flag */ + CLRBIT(plot_dsw, PLOT1627_DSW_BUSY); /* clear reader busy flag */ - SETBIT(plot_dsw, PLOT1627_DSW_OP_COMPLETE); /* indicate read complete */ + SETBIT(plot_dsw, PLOT1627_DSW_OP_COMPLETE); /* indicate read complete */ - SETBIT(ILSW[3], ILSW_3_1627_PLOTTER); /* initiate interrupt */ - calc_ints(); + SETBIT(ILSW[3], ILSW_3_1627_PLOTTER); /* initiate interrupt */ + calc_ints(); - return SCPE_OK; + return SCPE_OK; } /* plot_reset - reset emulated plotter */ @@ -364,24 +364,24 @@ static t_stat plot_svc (UNIT *uptr) static t_stat plot_reset (DEVICE *dptr) { #ifdef NONDLL - static int show_notice = FALSE; + static int show_notice = FALSE; - if (show_notice && ! cgi) { - printf("Plotter support included. Please see www.libgd.org for libgd copyright information.\n"); - show_notice = FALSE; - } + if (show_notice && ! cgi) { + printf("Plotter support included. Please see www.libgd.org for libgd copyright information.\n"); + show_notice = FALSE; + } #endif - sim_cancel(plot_unit); + sim_cancel(plot_unit); - CLRBIT(plot_dsw, PLOT1627_DSW_BUSY | PLOT1627_DSW_OP_COMPLETE); + CLRBIT(plot_dsw, PLOT1627_DSW_BUSY | PLOT1627_DSW_OP_COMPLETE); if (IS_DEBUG) printf("reset routine for Plotter\n"); - CLRBIT(ILSW[3], ILSW_3_1627_PLOTTER); - calc_ints(); + CLRBIT(ILSW[3], ILSW_3_1627_PLOTTER); + calc_ints(); - return SCPE_OK; + return SCPE_OK; } @@ -389,113 +389,113 @@ static t_stat plot_reset (DEVICE *dptr) static t_stat plot_attach (UNIT *uptr, CONST char *cptr) { - t_stat result; + t_stat result; - SETBIT(plot_dsw, PLOT1627_DSW_NOT_READY); /* assume failure */ + SETBIT(plot_dsw, PLOT1627_DSW_NOT_READY); /* assume failure */ - CLRBIT(uptr->flags, UNIT_DEBUG); - if (sim_switches & SWMASK('D')) SETBIT(uptr->flags, UNIT_DEBUG); + CLRBIT(uptr->flags, UNIT_DEBUG); + if (sim_switches & SWMASK('D')) SETBIT(uptr->flags, UNIT_DEBUG); - if (cptr == NULL || ! *cptr) /* filename must be passed */ - return SCPE_ARG; + if (cptr == NULL || ! *cptr) /* filename must be passed */ + return SCPE_ARG; - /* set up our canvas at the desired size */ - image = gdImageCreate(plot_ymax+1,plot_xmax+1); /* create our canvas */ + /* set up our canvas at the desired size */ + image = gdImageCreate(plot_ymax+1,plot_xmax+1); /* create our canvas */ if (image == NULL) { if (IS_DEBUG) printf("problem creating image canvas\n"); return SCPE_MEM; } - delete_if_unused = (sim_switches & SWMASK('W')) != 0; + delete_if_unused = (sim_switches & SWMASK('W')) != 0; - remove(cptr); /* delete file if it already exists. Otherwise, attach_unit() would open r+w */ - /* get the output file by using regular attach routine */ + remove(cptr); /* delete file if it already exists. Otherwise, attach_unit() would open r+w */ + /* get the output file by using regular attach routine */ result = attach_unit(uptr, cptr); if (result != SCPE_OK) { if (IS_DEBUG) printf("problem attaching file\n"); - gdImageDestroy(image); /* free up the canvas memory */ - image = NULL; + gdImageDestroy(image); /* free up the canvas memory */ + image = NULL; return result; } - /* set up the basic colors after image created */ - /* (by the way, these calls don't allocate any memory in or out of the image buffer. They just populate its "colors-used" table */ - white_background = gdImageColorAllocate(image,WHITE); /* white is background */ - black_pen = gdImageColorAllocate(image,BLACK); /* load up black color */ - blue_pen = gdImageColorAllocate(image,BLUE); /* load up blue color */ - red_pen = gdImageColorAllocate(image,RED); /* load up red color */ - green_pen = gdImageColorAllocate(image,GREEN); /* load up green color */ - yellow_pen = gdImageColorAllocate(image,YELLOW); /* load up yellow color */ - purple_pen = gdImageColorAllocate(image,PURPLE); /* load up purple color */ - ltgrey_pen = gdImageColorAllocate(image,LTGREY); /* load up light grey color */ - grey_pen = gdImageColorAllocate(image,GREY); /* load up grey color */ + /* set up the basic colors after image created */ + /* (by the way, these calls don't allocate any memory in or out of the image buffer. They just populate its "colors-used" table */ + white_background = gdImageColorAllocate(image,WHITE); /* white is background */ + black_pen = gdImageColorAllocate(image,BLACK); /* load up black color */ + blue_pen = gdImageColorAllocate(image,BLUE); /* load up blue color */ + red_pen = gdImageColorAllocate(image,RED); /* load up red color */ + green_pen = gdImageColorAllocate(image,GREEN); /* load up green color */ + yellow_pen = gdImageColorAllocate(image,YELLOW); /* load up yellow color */ + purple_pen = gdImageColorAllocate(image,PURPLE); /* load up purple color */ + ltgrey_pen = gdImageColorAllocate(image,LTGREY); /* load up light grey color */ + grey_pen = gdImageColorAllocate(image,GREY); /* load up grey color */ if ( (white_background == -1) || (black_pen == -1) || - (red_pen == -1) || (blue_pen == -1) || (green_pen == -1) || - (purple_pen == -1) || (ltgrey_pen == -1) || (grey_pen == -1) ) { + (red_pen == -1) || (blue_pen == -1) || (green_pen == -1) || + (purple_pen == -1) || (ltgrey_pen == -1) || (grey_pen == -1) ) { if (IS_DEBUG) printf("problem allocating pen colors\n"); return SCPE_MEM; } - CLRBIT(plot_dsw, PLOT1627_DSW_NOT_READY); /* we're in business */ + CLRBIT(plot_dsw, PLOT1627_DSW_NOT_READY); /* we're in business */ - plot_pen = PEN_UP; - CLRBIT(plot_unit->flags, UNIT_PEN); + plot_pen = PEN_UP; + CLRBIT(plot_unit->flags, UNIT_PEN); - update_pen(); /* routine to ensure pen is okay */ - plot_used = FALSE; /* plotter page is blank */ - return SCPE_OK; + update_pen(); /* routine to ensure pen is okay */ + plot_used = FALSE; /* plotter page is blank */ + return SCPE_OK; } /* pen updating routine, called at attach and whenever we reset the values */ static void update_pen (void) { - int color; - int width; + int color; + int width; if (! IS_ONLINE(plot_unit)) return; /* only do this if attached */ /* pick up latest color as active pen */ color = GET_COLOR; switch (color) { - case PEN_BLACK: - plot_pcolor = black_pen; - break; + case PEN_BLACK: + plot_pcolor = black_pen; + break; - case PEN_RED: - plot_pcolor = red_pen; - break; + case PEN_RED: + plot_pcolor = red_pen; + break; - case PEN_BLUE: - plot_pcolor = blue_pen; - break; + case PEN_BLUE: + plot_pcolor = blue_pen; + break; - case PEN_GREEN: - plot_pcolor = green_pen; - break; + case PEN_GREEN: + plot_pcolor = green_pen; + break; - case PEN_YELLOW: - plot_pcolor = yellow_pen; - break; + case PEN_YELLOW: + plot_pcolor = yellow_pen; + break; - case PEN_PURPLE: - plot_pcolor = purple_pen; - break; + case PEN_PURPLE: + plot_pcolor = purple_pen; + break; - case PEN_LTGREY: - plot_pcolor = ltgrey_pen; - break; + case PEN_LTGREY: + plot_pcolor = ltgrey_pen; + break; - case PEN_GREY: - plot_pcolor = grey_pen; - break; + case PEN_GREY: + plot_pcolor = grey_pen; + break; - default: - if (IS_DEBUG) printf("invalid pen color state\n"); - plot_pcolor = black_pen; - break; + default: + if (IS_DEBUG) printf("invalid pen color state\n"); + plot_pcolor = black_pen; + break; } /* set up anti-aliasing for the line */ @@ -504,27 +504,27 @@ static void update_pen (void) /* pick up latest width for pen */ width = GET_WIDTH(); switch (width) { - case PEN_SINGLE: + case PEN_SINGLE: plot_pwidth = 1; gdImageSetThickness(image, 1); break; - case PEN_TRIPLE: + case PEN_TRIPLE: plot_pwidth = 3; gdImageSetThickness(image, 3); break; - case PEN_DOUBLE: + case PEN_DOUBLE: plot_pwidth = 2; gdImageSetThickness(image, 2); break; - case PEN_QUAD: + case PEN_QUAD: plot_pwidth = 4; gdImageSetThickness(image, 4); break; - default: + default: if (IS_DEBUG) printf("invalid pen width\n"); plot_pwidth = 1; gdImageSetThickness(image, 1); @@ -540,73 +540,73 @@ static void update_pen (void) static t_stat plot_detach (UNIT *uptr) { - char * buf, * fname; - int32 size, result, saveit; - FILE * fp; - t_stat rval = SCPE_OK; /* return value */ + char * buf, * fname; + int32 size, result, saveit; + FILE * fp; + t_stat rval = SCPE_OK; /* return value */ SETBIT(plot_dsw, PLOT1627_DSW_NOT_READY); - if (! (uptr->flags & UNIT_ATT)) /* not currently attached; don't proceed */ - return SCPE_OK; + if (! (uptr->flags & UNIT_ATT)) /* not currently attached; don't proceed */ + return SCPE_OK; - /* if -w flag was passed on attach: save file if there was plotter activity, otherwise delete it */ - /* if -w flag was not passed on attached, always save the file */ - saveit = (plot_used || ! delete_if_unused) && (image != NULL); + /* if -w flag was passed on attach: save file if there was plotter activity, otherwise delete it */ + /* if -w flag was not passed on attached, always save the file */ + saveit = (plot_used || ! delete_if_unused) && (image != NULL); - if (saveit) { /* copy images to files, close files, set device to detached, free gd memory */ - if ((buf = gdImageGifPtr(image,&size)) == NULL) { - if (IS_DEBUG) printf("failure creating GIF in-memory\n"); - return SCPE_MEM; - } + if (saveit) { /* copy images to files, close files, set device to detached, free gd memory */ + if ((buf = gdImageGifPtr(image,&size)) == NULL) { + if (IS_DEBUG) printf("failure creating GIF in-memory\n"); + return SCPE_MEM; + } - fp = uptr->fileref; /* get file attached to unit */ + fp = uptr->fileref; /* get file attached to unit */ - if (fseek(fp,0,SEEK_SET) == 0) { /* first we reset to begin of file */ - if (IS_DEBUG) printf("wrote out GIF to file\n"); - result = fwrite(buf,1,size,fp); /* write out our image to the file */ - } - else - result = 0; /* make it look like the write failed so we return error status */ - - gdFree(buf); /* free up the memory of GIF format */ - } - else { /* make a copy of the filename so we can delete it after detach */ - if ((fname = malloc(strlen(uptr->filename)+1)) != NULL) - strcpy(fname, uptr->filename); - } - - if (image != NULL) { - gdImageDestroy(image); /* free up the canvas memory */ - image = NULL; - } - - rval = detach_unit(uptr); /* have simh close the file */ - - if (saveit) { /* if we wrote the file, check that write was OK */ - if (result != size) { /* report error writing file */ - if (IS_DEBUG) printf("error in write of image file\n"); - rval = SCPE_IOERR; - } + if (fseek(fp,0,SEEK_SET) == 0) { /* first we reset to begin of file */ + if (IS_DEBUG) printf("wrote out GIF to file\n"); + result = fwrite(buf,1,size,fp); /* write out our image to the file */ + } + else + result = 0; /* make it look like the write failed so we return error status */ + + gdFree(buf); /* free up the memory of GIF format */ + } + else { /* make a copy of the filename so we can delete it after detach */ + if ((fname = malloc(strlen(uptr->filename)+1)) != NULL) + strcpy(fname, uptr->filename); } - else { /* if we did not write the file, delete the file */ - if (fname == NULL) { - rval = SCPE_MEM; /* we previously failed to allocate a copy of the filename (this will never happen) */ - } - else { - remove(fname); /* remove the file and free the copy of the filename */ - free(fname); - } - } - return rval; + if (image != NULL) { + gdImageDestroy(image); /* free up the canvas memory */ + image = NULL; + } + + rval = detach_unit(uptr); /* have simh close the file */ + + if (saveit) { /* if we wrote the file, check that write was OK */ + if (result != size) { /* report error writing file */ + if (IS_DEBUG) printf("error in write of image file\n"); + rval = SCPE_IOERR; + } + } + else { /* if we did not write the file, delete the file */ + if (fname == NULL) { + rval = SCPE_MEM; /* we previously failed to allocate a copy of the filename (this will never happen) */ + } + else { + remove(fname); /* remove the file and free the copy of the filename */ + free(fname); + } + } + + return rval; } /* process_cmd - implement the drawing actions of the plotter */ static void process_cmd (void) { - int32 oldx, oldy; + int32 oldx, oldy; /* first see if we set any changes to pen or position, do an update */ if (need_update) { @@ -614,145 +614,145 @@ static void process_cmd (void) need_update = FALSE; } - /* will move pen one step or flip pen up or down */ + /* will move pen one step or flip pen up or down */ oldx = plot_xpos; oldy = plot_ypos; switch (plot_cmd) { - case 1: /* raise pen command */ - plot_pen = PEN_UP; - CLRBIT(plot_unit->flags, UNIT_PEN); - return; - break; + case 1: /* raise pen command */ + plot_pen = PEN_UP; + CLRBIT(plot_unit->flags, UNIT_PEN); + return; + break; - case 2: /* +Y command */ - ++plot_ypos; - break; + case 2: /* +Y command */ + ++plot_ypos; + break; - case 4: /* -Y command */ - --plot_ypos; - break; + case 4: /* -Y command */ + --plot_ypos; + break; - case 8: /* -X command */ - --plot_xpos; - break; + case 8: /* -X command */ + --plot_xpos; + break; - case 10: /* -X +Y command */ - --plot_xpos; - ++plot_ypos; - break; + case 10: /* -X +Y command */ + --plot_xpos; + ++plot_ypos; + break; - case 12: /* -X -Y command */ - --plot_xpos; - --plot_ypos; - break; + case 12: /* -X -Y command */ + --plot_xpos; + --plot_ypos; + break; - case 16: /* +X command */ - ++plot_xpos; - break; + case 16: /* +X command */ + ++plot_xpos; + break; - case 18: /* +X +Y command */ - ++plot_xpos; - ++plot_ypos; - break; + case 18: /* +X +Y command */ + ++plot_xpos; + ++plot_ypos; + break; - case 20: /* +X -Y pen command */ - ++plot_xpos; - --plot_ypos; - break; + case 20: /* +X -Y pen command */ + ++plot_xpos; + --plot_ypos; + break; - case 32: /* lower pen command */ - plot_pen = PEN_DOWN; - SETBIT(plot_unit->flags, UNIT_PEN); - return; - break; + case 32: /* lower pen command */ + plot_pen = PEN_DOWN; + SETBIT(plot_unit->flags, UNIT_PEN); + return; + break; - default: - if (IS_DEBUG) printf("invalid plotter command\n"); - return; - break; + default: + if (IS_DEBUG) printf("invalid plotter command\n"); + return; + break; } - /* On the real plotter, y motions were physically restricted at the ends of travel. - * We simulate this by clipping the plot_ypos value. Three +y movements at the right - * end of travel followed by three -y movements will back up 3 positions, just as it would have on - * the physical plotter. Without clipping, the pen would end up where it started, which - * is incorrect. (Hopefully, good 1130 plotting software would never make this happen anyhow!) - */ + /* On the real plotter, y motions were physically restricted at the ends of travel. + * We simulate this by clipping the plot_ypos value. Three +y movements at the right + * end of travel followed by three -y movements will back up 3 positions, just as it would have on + * the physical plotter. Without clipping, the pen would end up where it started, which + * is incorrect. (Hopefully, good 1130 plotting software would never make this happen anyhow!) + */ - if (plot_ypos < 0) - plot_ypos = 0; - else if (plot_ypos > plot_ymax) - plot_ypos = plot_ymax; + if (plot_ypos < 0) + plot_ypos = 0; + else if (plot_ypos > plot_ymax) + plot_ypos = plot_ymax; - /* We do allow X overtravel though, as the drum simply turned past the end of the paper. Three +x - * movements past the end of the paper followed by three -x movements would put the pen back at the - * edge of the paper. - */ + /* We do allow X overtravel though, as the drum simply turned past the end of the paper. Three +x + * movements past the end of the paper followed by three -x movements would put the pen back at the + * edge of the paper. + */ - if ((plot_xpos < 0) || (plot_xpos > plot_xmax)) { + if ((plot_xpos < 0) || (plot_xpos > plot_xmax)) { /* if so, ignore as 1627 has no way of signalling error */ if (IS_DEBUG) printf( "attempted to move carriage off paper edge %d %d for command %d\n", plot_xpos,plot_ypos,plot_cmd); - return; // no drawing takes place if the pen is off of the paper! + return; // no drawing takes place if the pen is off of the paper! } /* only draw a line if the pen was down during the movement command */ if (plot_pen) { - gdImageLine(image, plot_ymax-plot_ypos, plot_xmax-plot_xpos, plot_ymax-oldy, plot_xmax-oldx, gdAntiAliased); - plot_used = TRUE; /* remember that we drew something */ + gdImageLine(image, plot_ymax-plot_ypos, plot_xmax-plot_xpos, plot_ymax-oldy, plot_xmax-oldx, gdAntiAliased); + plot_used = TRUE; /* remember that we drew something */ /* semantics are 0,0 point is lower right */ } - return; + return; } /* plot_set_length - validate and store the length of the paper */ static t_stat plot_set_length (UNIT *uptr, int32 set, CONST char *ptr, void *desc) { - char *cptr; - int32 val; + char *cptr; + int32 val; #define LONGEST_ROLL 1440000 /* longest is 120', 14400", 1,440,000 .01"s */ - if (ptr == NULL) { /* check for missing argument */ - printf("Command format is: set plot length=nnn\n"); - return SCPE_ARG; - } + if (ptr == NULL) { /* check for missing argument */ + printf("Command format is: set plot length=nnn\n"); + return SCPE_ARG; + } - val = strtotv (ptr, &cptr, (uint32) 10); /* sim routine to get value */ - if ((val < 1) | (val >= LONGEST_ROLL)) { /* check valid range */ - if (IS_DEBUG) printf("setting paper more than 120' or less than 1 inch\n"); - return SCPE_ARG; - } + val = strtotv (ptr, &cptr, (uint32) 10); /* sim routine to get value */ + if ((val < 1) | (val >= LONGEST_ROLL)) { /* check valid range */ + if (IS_DEBUG) printf("setting paper more than 120' or less than 1 inch\n"); + return SCPE_ARG; + } - /* origin zero drawing, reduce by 1 but show command will fudge by adding it back */ - *((int32 *)((REG *) desc)->loc) = val - 1; + /* origin zero drawing, reduce by 1 but show command will fudge by adding it back */ + *((int32 *)((REG *) desc)->loc) = val - 1; - return SCPE_OK; + return SCPE_OK; } /* plot_set_pos - validate and store the new position of the carriage */ static t_stat plot_set_pos (UNIT *uptr, int32 set, CONST char *ptr, void *desc) { - char *cptr; - int32 val; - int32 max; + char *cptr; + int32 val; + int32 max; - max = (set == 1) ? plot_ymax : plot_xmax; - val = strtotv (ptr, &cptr, (uint32) 10); - if ((val < 0) | (val > max)) { - if (IS_DEBUG) printf("error moving carriage off paper edge\n"); - return SCPE_ARG; - } + max = (set == 1) ? plot_ymax : plot_xmax; + val = strtotv (ptr, &cptr, (uint32) 10); + if ((val < 0) | (val > max)) { + if (IS_DEBUG) printf("error moving carriage off paper edge\n"); + return SCPE_ARG; + } - *((int32 *)((REG *) desc)->loc) = val; + *((int32 *)((REG *) desc)->loc) = val; - return SCPE_OK; + return SCPE_OK; } /* routine to display the paper length and carriage position @@ -762,7 +762,7 @@ static t_stat plot_set_pos (UNIT *uptr, int32 set, CONST char *ptr, void *desc) static t_stat plot_show_vals (FILE *fp, UNIT *uptr, int32 val, CONST void *descrip) { - fprintf(fp, "length=%d, Xpos=%d, Ypos=%d",plot_xmax+1, plot_xpos,plot_ypos); + fprintf(fp, "length=%d, Xpos=%d, Ypos=%d",plot_xmax+1, plot_xpos,plot_ypos); return SCPE_OK; } @@ -771,13 +771,13 @@ static t_stat plot_show_vals (FILE *fp, UNIT *uptr, int32 val, CONST void *descr static t_stat plot_show_nl(FILE *fp, UNIT *uptr, int32 val, CONST void *descrip) { - int32 disp; - char *label; + int32 disp; + char *label; - disp = (val == 2) ? plot_xmax + 1 : ((val == 1) ? plot_ypos : plot_xpos); - label = (val == 2) ? "length=" : ((val == 1) ? "Ypos=" : "Xpos="); + disp = (val == 2) ? plot_xmax + 1 : ((val == 1) ? plot_ypos : plot_xpos); + label = (val == 2) ? "length=" : ((val == 1) ? "Ypos=" : "Xpos="); - fprintf(fp, "%s%d\n", label, disp); + fprintf(fp, "%s%d\n", label, disp); return SCPE_OK; } @@ -785,8 +785,8 @@ static t_stat plot_show_nl(FILE *fp, UNIT *uptr, int32 val, CONST void *descrip) static t_stat plot_validate_change (UNIT *uptr, int32 set, CONST char *ptr, void *desc) { - need_update = TRUE; - return SCPE_OK; + need_update = TRUE; + return SCPE_OK; } #endif /* ENABLE_PLOT_SUPPORT */ diff --git a/Ibm1130/ibm1130_prt.c b/Ibm1130/ibm1130_prt.c index 6f0acbd3..015e5df1 100644 --- a/Ibm1130/ibm1130_prt.c +++ b/Ibm1130/ibm1130_prt.c @@ -10,17 +10,17 @@ 2006.07.06 - Made 1403 printer 132 columns wide, was 120 previously 2006.01.03 - Fixed bug in prt_attach, found and fixed by Carl Claunch. Detach followed - by reattach of 1403-mode printer left device permanently not-ready. + by reattach of 1403-mode printer left device permanently not-ready. 2004.11.08 - HACK for demo mode: in physical (-p) mode, multiple consecutive formfeeds are suppressed. - This lets us do a formfeed at the end of a job to kick the last page out - without getting another blank page at the beginning of the next job. + This lets us do a formfeed at the end of a job to kick the last page out + without getting another blank page at the beginning of the next job. 2003.12.02 - Added -p option for physical line printer output (flushes - output buffer after each line). When using a physical printer on - Windows, be sure to set printer to "send output directly to printer" - to disable spooling, otherwise nothing appears until printer is - detatched. + output buffer after each line). When using a physical printer on + Windows, be sure to set printer to "send output directly to printer" + to disable spooling, otherwise nothing appears until printer is + detatched. 2003.11.25 - Changed magic filename for standard output to "(stdout)". @@ -47,41 +47,41 @@ */ #include "ibm1130_defs.h" -#include /* needed for atexit, for cgi mode */ +#include /* needed for atexit, for cgi mode */ /*************************************************************************************** * 1132 PRINTER ***************************************************************************************/ -#define PRT1132_DSW_READ_EMITTER_RESPONSE 0x8000 -#define PRT1132_DSW_SKIP_RESPONSE 0x4000 -#define PRT1132_DSW_SPACE_RESPONSE 0x2000 -#define PRT1132_DSW_CARRIAGE_BUSY 0x1000 -#define PRT1132_DSW_PRINT_SCAN_CHECK 0x0800 -#define PRT1132_DSW_NOT_READY 0x0400 -#define PRT1132_DSW_PRINTER_BUSY 0x0200 +#define PRT1132_DSW_READ_EMITTER_RESPONSE 0x8000 +#define PRT1132_DSW_SKIP_RESPONSE 0x4000 +#define PRT1132_DSW_SPACE_RESPONSE 0x2000 +#define PRT1132_DSW_CARRIAGE_BUSY 0x1000 +#define PRT1132_DSW_PRINT_SCAN_CHECK 0x0800 +#define PRT1132_DSW_NOT_READY 0x0400 +#define PRT1132_DSW_PRINTER_BUSY 0x0200 -#define PRT1132_DSW_CHANNEL_MASK 0x00FF /* 1132 printer DSW bits */ -#define PRT1132_DSW_CHANNEL_1 0x0080 -#define PRT1132_DSW_CHANNEL_2 0x0040 -#define PRT1132_DSW_CHANNEL_3 0x0020 -#define PRT1132_DSW_CHANNEL_4 0x0010 -#define PRT1132_DSW_CHANNEL_5 0x0008 -#define PRT1132_DSW_CHANNEL_6 0x0004 -#define PRT1132_DSW_CHANNEL_9 0x0002 -#define PRT1132_DSW_CHANNEL_12 0x0001 +#define PRT1132_DSW_CHANNEL_MASK 0x00FF /* 1132 printer DSW bits */ +#define PRT1132_DSW_CHANNEL_1 0x0080 +#define PRT1132_DSW_CHANNEL_2 0x0040 +#define PRT1132_DSW_CHANNEL_3 0x0020 +#define PRT1132_DSW_CHANNEL_4 0x0010 +#define PRT1132_DSW_CHANNEL_5 0x0008 +#define PRT1132_DSW_CHANNEL_6 0x0004 +#define PRT1132_DSW_CHANNEL_9 0x0002 +#define PRT1132_DSW_CHANNEL_12 0x0001 -#define PRT1403_DSW_PARITY_CHECK 0x8000 /* 1403 printer DSW bits */ -#define PRT1403_DSW_TRANSFER_COMPLETE 0x4000 -#define PRT1403_DSW_PRINT_COMPLETE 0x2000 -#define PRT1403_DSW_CARRIAGE_COMPLETE 0x1000 -#define PRT1403_DSW_RING_CHECK 0x0400 -#define PRT1403_DSW_SYNC_CHECK 0x0200 -#define PRT1403_DSW_CH9 0x0010 -#define PRT1403_DSW_CH12 0x0008 -#define PRT1403_DSW_CARRIAGE_BUSY 0x0004 -#define PRT1403_DSW_PRINTER_BUSY 0x0002 -#define PRT1403_DSW_NOT_READY 0x0001 +#define PRT1403_DSW_PARITY_CHECK 0x8000 /* 1403 printer DSW bits */ +#define PRT1403_DSW_TRANSFER_COMPLETE 0x4000 +#define PRT1403_DSW_PRINT_COMPLETE 0x2000 +#define PRT1403_DSW_CARRIAGE_COMPLETE 0x1000 +#define PRT1403_DSW_RING_CHECK 0x0400 +#define PRT1403_DSW_SYNC_CHECK 0x0200 +#define PRT1403_DSW_CH9 0x0010 +#define PRT1403_DSW_CH12 0x0008 +#define PRT1403_DSW_CARRIAGE_BUSY 0x0004 +#define PRT1403_DSW_PRINTER_BUSY 0x0002 +#define PRT1403_DSW_NOT_READY 0x0001 #define IS_ONLINE(u) (((u)->flags & (UNIT_ATT|UNIT_DIS)) == UNIT_ATT) @@ -92,117 +92,117 @@ static t_stat prt_reset (DEVICE *dptr); static t_stat prt_attach (UNIT *uptr, CONST char *cptr); static t_stat prt_detach (UNIT *uptr); -static int16 PRT_DSW = 0; /* device status word */ -static int32 prt_swait = 500; /* line skip wait */ -static int32 prt_cwait = 1250; /* character rotation wait */ -static int32 prt_fwait = 100; /* fast wait, for 1403 operations */ -static int32 prt_twait = 50; /* transfer wait, for 1403 operations */ -#define SKIPTARGET (uptr->u4) /* target for skip operation */ +static int16 PRT_DSW = 0; /* device status word */ +static int32 prt_swait = 500; /* line skip wait */ +static int32 prt_cwait = 1250; /* character rotation wait */ +static int32 prt_fwait = 100; /* fast wait, for 1403 operations */ +static int32 prt_twait = 50; /* transfer wait, for 1403 operations */ +#define SKIPTARGET (uptr->u4) /* target for skip operation */ -static t_bool formfed = FALSE; /* last line printed was a formfeed */ +static t_bool formfed = FALSE; /* last line printed was a formfeed */ -#define UNIT_V_FORMCHECK (UNIT_V_UF + 0) /* out of paper error */ -#define UNIT_V_DATACHECK (UNIT_V_UF + 1) /* printer overrun error */ -#define UNIT_V_SKIPPING (UNIT_V_UF + 2) /* printer skipping */ -#define UNIT_V_SPACING (UNIT_V_UF + 3) /* printer is spacing */ -#define UNIT_V_PRINTING (UNIT_V_UF + 4) /* printer printing */ -#define UNIT_V_TRANSFERRING (UNIT_V_UF + 5) /* unit is transferring print buffer (1403 only) */ -#define UNIT_V_1403 (UNIT_V_UF + 6) /* printer model is 1403 rather than 1132 */ -#define UNIT_V_PARITYCHECK (UNIT_V_UF + 7) /* error flags for 1403 */ -#define UNIT_V_RINGCHECK (UNIT_V_UF + 8) -#define UNIT_V_SYNCCHECK (UNIT_V_UF + 9) -#define UNIT_V_PHYSICAL_PTR (UNIT_V_UF + 10) /* this appears in ibm1130_gui as well */ +#define UNIT_V_FORMCHECK (UNIT_V_UF + 0) /* out of paper error */ +#define UNIT_V_DATACHECK (UNIT_V_UF + 1) /* printer overrun error */ +#define UNIT_V_SKIPPING (UNIT_V_UF + 2) /* printer skipping */ +#define UNIT_V_SPACING (UNIT_V_UF + 3) /* printer is spacing */ +#define UNIT_V_PRINTING (UNIT_V_UF + 4) /* printer printing */ +#define UNIT_V_TRANSFERRING (UNIT_V_UF + 5) /* unit is transferring print buffer (1403 only) */ +#define UNIT_V_1403 (UNIT_V_UF + 6) /* printer model is 1403 rather than 1132 */ +#define UNIT_V_PARITYCHECK (UNIT_V_UF + 7) /* error flags for 1403 */ +#define UNIT_V_RINGCHECK (UNIT_V_UF + 8) +#define UNIT_V_SYNCCHECK (UNIT_V_UF + 9) +#define UNIT_V_PHYSICAL_PTR (UNIT_V_UF + 10) /* this appears in ibm1130_gui as well */ #define UNIT_V_TRACE (UNIT_V_UF + 11) -#define UNIT_FORMCHECK (1u << UNIT_V_FORMCHECK) -#define UNIT_DATACHECK (1u << UNIT_V_DATACHECK) -#define UNIT_SKIPPING (1u << UNIT_V_SKIPPING) -#define UNIT_SPACING (1u << UNIT_V_SPACING) -#define UNIT_PRINTING (1u << UNIT_V_PRINTING) +#define UNIT_FORMCHECK (1u << UNIT_V_FORMCHECK) +#define UNIT_DATACHECK (1u << UNIT_V_DATACHECK) +#define UNIT_SKIPPING (1u << UNIT_V_SKIPPING) +#define UNIT_SPACING (1u << UNIT_V_SPACING) +#define UNIT_PRINTING (1u << UNIT_V_PRINTING) #define UNIT_TRANSFERRING (1u << UNIT_V_TRANSFERRING) -#define UNIT_1403 (1u << UNIT_V_1403) -#define UNIT_PARITYCHECK (1u << UNIT_V_PARITYCHECK) -#define UNIT_RINGCHECK (1u << UNIT_V_RINGCHECK) -#define UNIT_SYNCCHECK (1u << UNIT_V_SYNCCHECK) +#define UNIT_1403 (1u << UNIT_V_1403) +#define UNIT_PARITYCHECK (1u << UNIT_V_PARITYCHECK) +#define UNIT_RINGCHECK (1u << UNIT_V_RINGCHECK) +#define UNIT_SYNCCHECK (1u << UNIT_V_SYNCCHECK) #define UNIT_PHYSICAL_PTR (1u << UNIT_V_PHYSICAL_PTR) -#define UNIT_TRACE (1u << UNIT_V_TRACE) +#define UNIT_TRACE (1u << UNIT_V_TRACE) UNIT prt_unit[] = { - { UDATA (&prt_svc, UNIT_ATTABLE, 0) }, + { UDATA (&prt_svc, UNIT_ATTABLE, 0) }, }; -#define IS_1403(uptr) (uptr->flags & UNIT_1403) /* model test */ -#define IS_1132(uptr) ((uptr->flags & UNIT_1403) == 0) /* model test */ +#define IS_1403(uptr) (uptr->flags & UNIT_1403) /* model test */ +#define IS_1132(uptr) ((uptr->flags & UNIT_1403) == 0) /* model test */ #define IS_PHYSICAL(uptr) (uptr->flags & UNIT_PHYSICAL_PTR) -#define DO_TRACE(uptr) (uptr->flags & UNIT_TRACE) +#define DO_TRACE(uptr) (uptr->flags & UNIT_TRACE) /* Parameter in the unit descriptor (1132 printer) */ -#define CMD_NONE 0 -#define CMD_SPACE 1 -#define CMD_SKIP 2 -#define CMD_PRINT 3 +#define CMD_NONE 0 +#define CMD_SPACE 1 +#define CMD_SKIP 2 +#define CMD_PRINT 3 REG prt_reg[] = { - { HRDATA (PRTDSW, PRT_DSW, 16) }, /* device status word */ - { DRDATA (STIME, prt_swait, 24), PV_LEFT }, /* line skip wait */ - { DRDATA (CTIME, prt_cwait, 24), PV_LEFT }, /* character rotation wait */ - { DRDATA (FTIME, prt_fwait, 24), PV_LEFT }, /* 1403 fast wait */ - { DRDATA (TTIME, prt_twait, 24), PV_LEFT }, /* 1403 transfer wait */ - { NULL } }; + { HRDATA (PRTDSW, PRT_DSW, 16) }, /* device status word */ + { DRDATA (STIME, prt_swait, 24), PV_LEFT }, /* line skip wait */ + { DRDATA (CTIME, prt_cwait, 24), PV_LEFT }, /* character rotation wait */ + { DRDATA (FTIME, prt_fwait, 24), PV_LEFT }, /* 1403 fast wait */ + { DRDATA (TTIME, prt_twait, 24), PV_LEFT }, /* 1403 transfer wait */ + { NULL } }; MTAB prt_mod[] = { - { UNIT_1403, 0, "1132", "1132", NULL }, /* model option */ - { UNIT_1403, UNIT_1403, "1403", "1403", NULL }, - { UNIT_TRACE, UNIT_TRACE, "TRACE", "TRACE", NULL }, - { UNIT_TRACE, 0, "NOTRACE", "NOTRACE", NULL }, - { 0 } }; + { UNIT_1403, 0, "1132", "1132", NULL }, /* model option */ + { UNIT_1403, UNIT_1403, "1403", "1403", NULL }, + { UNIT_TRACE, UNIT_TRACE, "TRACE", "TRACE", NULL }, + { UNIT_TRACE, 0, "NOTRACE", "NOTRACE", NULL }, + { 0 } }; DEVICE prt_dev = { - "PRT", prt_unit, prt_reg, prt_mod, - 1, 16, 16, 1, 16, 16, - NULL, NULL, &prt_reset, - NULL, prt_attach, prt_detach}; + "PRT", prt_unit, prt_reg, prt_mod, + 1, 16, 16, 1, 16, 16, + NULL, NULL, &prt_reset, + NULL, prt_attach, prt_detach}; -#define MAX_COLUMNS 120 -#define MAX_OVPRINT 20 +#define MAX_COLUMNS 120 +#define MAX_OVPRINT 20 #define PRT1132_COLUMNS 120 -#define PRT1403_COLUMNS 120 /* the 1130's version of the 1403 printed in 120 columns only (see Functional Characteristics) */ +#define PRT1403_COLUMNS 120 /* the 1130's version of the 1403 printed in 120 columns only (see Functional Characteristics) */ static char prtbuf[MAX_COLUMNS*MAX_OVPRINT]; static int nprint[MAX_COLUMNS], ncol[MAX_OVPRINT], maxnp; -static int prt_nchar, prt_row; /* current printwheel position, current page row */ -static int prt_nnl; /* number of queued newlines */ +static int prt_nchar, prt_row; /* current printwheel position, current page row */ +static int prt_nnl; /* number of queued newlines */ -#define CC_CHANNEL_1 0x0800 /* carriage control tape punch values */ -#define CC_CHANNEL_2 0x0400 -#define CC_CHANNEL_3 0x0200 -#define CC_CHANNEL_4 0x0100 -#define CC_CHANNEL_5 0x0080 -#define CC_CHANNEL_6 0x0040 /* 7, 8, 10 and 11 are not used on 1132 printer */ -#define CC_CHANNEL_7 0x0020 -#define CC_CHANNEL_8 0x0010 -#define CC_CHANNEL_9 0x0008 -#define CC_CHANNEL_10 0x0004 -#define CC_CHANNEL_11 0x0002 -#define CC_CHANNEL_12 0x0001 +#define CC_CHANNEL_1 0x0800 /* carriage control tape punch values */ +#define CC_CHANNEL_2 0x0400 +#define CC_CHANNEL_3 0x0200 +#define CC_CHANNEL_4 0x0100 +#define CC_CHANNEL_5 0x0080 +#define CC_CHANNEL_6 0x0040 /* 7, 8, 10 and 11 are not used on 1132 printer */ +#define CC_CHANNEL_7 0x0020 +#define CC_CHANNEL_8 0x0010 +#define CC_CHANNEL_9 0x0008 +#define CC_CHANNEL_10 0x0004 +#define CC_CHANNEL_11 0x0002 +#define CC_CHANNEL_12 0x0001 -#define CC_1403_BITS 0x0FFF /* all bits for 1403, most for 1132 */ -#define CC_1132_BITS (CC_1403_BITS & ~(CC_CHANNEL_7|CC_CHANNEL_8|CC_CHANNEL_10|CC_CHANNEL_11)) +#define CC_1403_BITS 0x0FFF /* all bits for 1403, most for 1132 */ +#define CC_1132_BITS (CC_1403_BITS & ~(CC_CHANNEL_7|CC_CHANNEL_8|CC_CHANNEL_10|CC_CHANNEL_11)) #define PRT_PAGELENGTH 66 -static int cctape[PRT_PAGELENGTH]; /* standard carriage control tape */ +static int cctape[PRT_PAGELENGTH]; /* standard carriage control tape */ -static struct tag_ccpunches { /* list of rows and punches on tape */ - int row, channels; +static struct tag_ccpunches { /* list of rows and punches on tape */ + int row, channels; } ccpunches[] = { - { 2, CC_CHANNEL_1}, /* channel 1 = top of form */ - {62, CC_CHANNEL_12} /* channel 12 = bottom of form */ + { 2, CC_CHANNEL_1}, /* channel 1 = top of form */ + {62, CC_CHANNEL_12} /* channel 12 = bottom of form */ }, cccgi[] = { - {2, CC_CHANNEL_1} /* channel 1 = top of form; no bottom of form */ + {2, CC_CHANNEL_1} /* channel 1 = top of form; no bottom of form */ }; #include "ibm1130_prtwheel.h" @@ -211,9 +211,9 @@ cccgi[] = { static int cc_format_1132 (int bits) { - return ((bits & (CC_CHANNEL_1|CC_CHANNEL_2|CC_CHANNEL_3|CC_CHANNEL_4|CC_CHANNEL_5|CC_CHANNEL_6)) >> 4) | - ((bits & CC_CHANNEL_9) >> 3) | - (bits & CC_CHANNEL_12); + return ((bits & (CC_CHANNEL_1|CC_CHANNEL_2|CC_CHANNEL_3|CC_CHANNEL_4|CC_CHANNEL_5|CC_CHANNEL_6)) >> 4) | + ((bits & CC_CHANNEL_9) >> 3) | + (bits & CC_CHANNEL_12); } #define cc_format_1403(bits) (bits) @@ -222,42 +222,42 @@ static int cc_format_1132 (int bits) static void reset_prt_line (void) { - memset(nprint, 0, sizeof(nprint)); - memset(ncol, 0, sizeof(ncol)); - maxnp = 0; + memset(nprint, 0, sizeof(nprint)); + memset(ncol, 0, sizeof(ncol)); + maxnp = 0; } /* save_1132_prt_line - fire hammers for character 'ch' */ static t_bool save_1132_prt_line (int ch) { - int i, r, addr = 32; - int32 mask = 0, wd = 0; + int i, r, addr = 32; + int32 mask = 0, wd = 0; - for (i = 0; i < PRT1132_COLUMNS; i++) { - if (mask == 0) { /* fetch next word from memory */ - mask = 0x8000; - wd = M[addr++]; - } + for (i = 0; i < PRT1132_COLUMNS; i++) { + if (mask == 0) { /* fetch next word from memory */ + mask = 0x8000; + wd = M[addr++]; + } - if (wd & mask) { /* hammer is to fire in this column */ - if ((r = nprint[i]) < MAX_OVPRINT) { - if (ncol[r] <= i) { /* we haven't moved this far yet */ - if (ncol[r] == 0) /* first char in this row? */ - memset(prtbuf+r*MAX_COLUMNS, ' ', PRT1132_COLUMNS); /* blank out the new row */ - ncol[r] = i+1; /* remember new row length */ - } - prtbuf[r*MAX_COLUMNS + i] = (char) ch; /* save the character */ + if (wd & mask) { /* hammer is to fire in this column */ + if ((r = nprint[i]) < MAX_OVPRINT) { + if (ncol[r] <= i) { /* we haven't moved this far yet */ + if (ncol[r] == 0) /* first char in this row? */ + memset(prtbuf+r*MAX_COLUMNS, ' ', PRT1132_COLUMNS); /* blank out the new row */ + ncol[r] = i+1; /* remember new row length */ + } + prtbuf[r*MAX_COLUMNS + i] = (char) ch; /* save the character */ - nprint[i]++; /* remember max overprintings for this column */ - maxnp = MAX(maxnp, nprint[i]); - } - } + nprint[i]++; /* remember max overprintings for this column */ + maxnp = MAX(maxnp, nprint[i]); + } + } - mask >>= 1; /* prepare to examine next bit */ - } + mask >>= 1; /* prepare to examine next bit */ + } - return wd & 1; /* return TRUE if the last word has lsb set, which means all bits had been set */ + return wd & 1; /* return TRUE if the last word has lsb set, which means all bits had been set */ } /* write_line - write collected line to output file. No need to trim spaces as the hammers @@ -266,546 +266,546 @@ static t_bool save_1132_prt_line (int ch) static void newpage (FILE *fd, t_bool physical_printer) { - if (cgi) - fputs("
\n", fd); - else if (! formfed) { - putc('\f', fd); - if (physical_printer) { - fflush(fd); /* send the ff out to the printer immediately */ - formfed = TRUE; /* hack: inhibit consecutive ff's */ - } - } + if (cgi) + fputs("
\n", fd); + else if (! formfed) { + putc('\f', fd); + if (physical_printer) { + fflush(fd); /* send the ff out to the printer immediately */ + formfed = TRUE; /* hack: inhibit consecutive ff's */ + } + } } static void flush_prt_line (FILE *fd, int spacemode, t_bool physical_printer) { - int r; + int r; - if (! (spacemode || maxnp)) /* nothing to do */ - return; + if (! (spacemode || maxnp)) /* nothing to do */ + return; - prt_row = (prt_row+1) % PRT_PAGELENGTH; /* NEXT line */ + prt_row = (prt_row+1) % PRT_PAGELENGTH; /* NEXT line */ - if (spacemode && ! maxnp) { /* spacing only */ - if (prt_row == 0 && prt_nnl) { + if (spacemode && ! maxnp) { /* spacing only */ + if (prt_row == 0 && prt_nnl) { #ifdef _WIN32 - if (! cgi) - putc('\r', fd); /* DOS/Windows: end with cr/lf */ + if (! cgi) + putc('\r', fd); /* DOS/Windows: end with cr/lf */ #endif - putc('\n', fd); /* otherwise end with lf */ - if (spacemode & UNIT_SKIPPING) /* add formfeed if we crossed page boundary while skipping */ - newpage(fd, physical_printer); + putc('\n', fd); /* otherwise end with lf */ + if (spacemode & UNIT_SKIPPING) /* add formfeed if we crossed page boundary while skipping */ + newpage(fd, physical_printer); - prt_nnl = 0; - } - else { - prt_nnl++; - formfed = FALSE; - } + prt_nnl = 0; + } + else { + prt_nnl++; + formfed = FALSE; + } - prt_unit->pos++; /* note something written */ - return; - } + prt_unit->pos++; /* note something written */ + return; + } - if (prt_nnl) { /* there are queued newlines */ - while (prt_nnl > 0) { /* spit out queued newlines */ + if (prt_nnl) { /* there are queued newlines */ + while (prt_nnl > 0) { /* spit out queued newlines */ #ifdef _WIN32 - if (! cgi) - putc('\r', fd); /* DOS/Windows: end with cr/lf */ + if (! cgi) + putc('\r', fd); /* DOS/Windows: end with cr/lf */ #endif - putc('\n', fd); /* otherwise end with lf */ - prt_nnl--; - } - } + putc('\n', fd); /* otherwise end with lf */ + prt_nnl--; + } + } - for (r = 0; r < maxnp; r++) { - if (r > 0) - putc('\r', fd); /* carriage return between overprinted lines */ + for (r = 0; r < maxnp; r++) { + if (r > 0) + putc('\r', fd); /* carriage return between overprinted lines */ - fxwrite(&prtbuf[r*MAX_COLUMNS], 1, ncol[r], fd); - } + fxwrite(&prtbuf[r*MAX_COLUMNS], 1, ncol[r], fd); + } - reset_prt_line(); + reset_prt_line(); - prt_unit->pos++; /* note something written */ - prt_nnl++; /* queue a newline */ + prt_unit->pos++; /* note something written */ + prt_nnl++; /* queue a newline */ - if (physical_printer) /* if physical printer, send buffered output to device */ - fflush(fd); + if (physical_printer) /* if physical printer, send buffered output to device */ + fflush(fd); - formfed = FALSE; /* note that something is now on the page */ + formfed = FALSE; /* note that something is now on the page */ } /* 1132 printer commands */ -#define PRT_CMD_START_PRINTER 0x0080 -#define PRT_CMD_STOP_PRINTER 0x0040 -#define PRT_CMD_START_CARRIAGE 0x0004 -#define PRT_CMD_STOP_CARRIAGE 0x0002 -#define PRT_CMD_SPACE 0x0001 +#define PRT_CMD_START_PRINTER 0x0080 +#define PRT_CMD_STOP_PRINTER 0x0040 +#define PRT_CMD_START_CARRIAGE 0x0004 +#define PRT_CMD_STOP_CARRIAGE 0x0002 +#define PRT_CMD_SPACE 0x0001 -#define PRT_CMD_MASK 0x00C7 +#define PRT_CMD_MASK 0x00C7 extern const char * saywhere (int addr); static void mytrace (int start, const char *what) { - const char *where; + const char *where; - if ((where = saywhere(prev_IAR)) == NULL) where = "?"; - trace_io("%s %s at %04x: %s", start ? "start" : "stop", what, prev_IAR, where); + if ((where = saywhere(prev_IAR)) == NULL) where = "?"; + trace_io("%s %s at %04x: %s", start ? "start" : "stop", what, prev_IAR, where); } /* xio_1132_printer - XIO command interpreter for the 1132 printer */ void xio_1132_printer (int32 iocc_addr, int32 func, int32 modify) { - char msg[80]; - UNIT *uptr = &prt_unit[0]; + char msg[80]; + UNIT *uptr = &prt_unit[0]; - switch (func) { - case XIO_READ: - M[iocc_addr & mem_mask] = codewheel1132[prt_nchar].ebcdic << 8; + switch (func) { + case XIO_READ: + M[iocc_addr & mem_mask] = codewheel1132[prt_nchar].ebcdic << 8; - if ((uptr->flags & UNIT_PRINTING) == 0) /* if we're not printing, advance this after every test */ - prt_nchar = (prt_nchar + 1) % WHEELCHARS_1132; - break; + if ((uptr->flags & UNIT_PRINTING) == 0) /* if we're not printing, advance this after every test */ + prt_nchar = (prt_nchar + 1) % WHEELCHARS_1132; + break; - case XIO_SENSE_DEV: - ACC = PRT_DSW; - if (modify & 0x01) { /* reset interrupts */ - CLRBIT(PRT_DSW, PRT1132_DSW_READ_EMITTER_RESPONSE | PRT1132_DSW_SKIP_RESPONSE | PRT1132_DSW_SPACE_RESPONSE); - CLRBIT(ILSW[1], ILSW_1_1132_PRINTER); - } - trace_io("* Printer DSW %04x mod %x", ACC, modify); - break; + case XIO_SENSE_DEV: + ACC = PRT_DSW; + if (modify & 0x01) { /* reset interrupts */ + CLRBIT(PRT_DSW, PRT1132_DSW_READ_EMITTER_RESPONSE | PRT1132_DSW_SKIP_RESPONSE | PRT1132_DSW_SPACE_RESPONSE); + CLRBIT(ILSW[1], ILSW_1_1132_PRINTER); + } + trace_io("* Printer DSW %04x mod %x", ACC, modify); + break; - case XIO_CONTROL: - if (modify & PRT_CMD_START_PRINTER) { - SETBIT(uptr->flags, UNIT_PRINTING); - if (DO_TRACE(uptr)) mytrace(1, "printing"); - } + case XIO_CONTROL: + if (modify & PRT_CMD_START_PRINTER) { + SETBIT(uptr->flags, UNIT_PRINTING); + if (DO_TRACE(uptr)) mytrace(1, "printing"); + } - if (modify & PRT_CMD_STOP_PRINTER) { - CLRBIT(uptr->flags, UNIT_PRINTING); - if (DO_TRACE(uptr)) mytrace(0, "printing"); - } + if (modify & PRT_CMD_STOP_PRINTER) { + CLRBIT(uptr->flags, UNIT_PRINTING); + if (DO_TRACE(uptr)) mytrace(0, "printing"); + } - if (modify & PRT_CMD_START_CARRIAGE) { - SETBIT(uptr->flags, UNIT_SKIPPING); - if (DO_TRACE(uptr)) mytrace(1, "skipping"); - } + if (modify & PRT_CMD_START_CARRIAGE) { + SETBIT(uptr->flags, UNIT_SKIPPING); + if (DO_TRACE(uptr)) mytrace(1, "skipping"); + } - if (modify & PRT_CMD_STOP_CARRIAGE) { - CLRBIT(uptr->flags, UNIT_SKIPPING); - if (DO_TRACE(uptr)) mytrace(0, "skipping"); - } + if (modify & PRT_CMD_STOP_CARRIAGE) { + CLRBIT(uptr->flags, UNIT_SKIPPING); + if (DO_TRACE(uptr)) mytrace(0, "skipping"); + } - if (modify & PRT_CMD_SPACE) { - SETBIT(uptr->flags, UNIT_SPACING); - if (DO_TRACE(uptr)) mytrace(1, "space"); - } + if (modify & PRT_CMD_SPACE) { + SETBIT(uptr->flags, UNIT_SPACING); + if (DO_TRACE(uptr)) mytrace(1, "space"); + } - sim_cancel(uptr); - if (uptr->flags & (UNIT_SKIPPING|UNIT_SPACING|UNIT_PRINTING)) { /* busy bits = doing something */ - SETBIT(PRT_DSW, PRT1132_DSW_PRINTER_BUSY); - sim_activate(uptr, prt_cwait); - } - else - CLRBIT(PRT_DSW, PRT1132_DSW_PRINTER_BUSY); + sim_cancel(uptr); + if (uptr->flags & (UNIT_SKIPPING|UNIT_SPACING|UNIT_PRINTING)) { /* busy bits = doing something */ + SETBIT(PRT_DSW, PRT1132_DSW_PRINTER_BUSY); + sim_activate(uptr, prt_cwait); + } + else + CLRBIT(PRT_DSW, PRT1132_DSW_PRINTER_BUSY); - if (uptr->flags & (UNIT_SKIPPING|UNIT_SPACING)) - SETBIT(PRT_DSW, PRT1132_DSW_CARRIAGE_BUSY); - else - CLRBIT(PRT_DSW, PRT1132_DSW_CARRIAGE_BUSY); - - if ((uptr->flags & (UNIT_SKIPPING|UNIT_SPACING)) == (UNIT_SKIPPING|UNIT_SPACING)) { - sprintf(msg, "1132 printer skip and space at same time?"); - xio_error(msg); - } - break; + if (uptr->flags & (UNIT_SKIPPING|UNIT_SPACING)) + SETBIT(PRT_DSW, PRT1132_DSW_CARRIAGE_BUSY); + else + CLRBIT(PRT_DSW, PRT1132_DSW_CARRIAGE_BUSY); + + if ((uptr->flags & (UNIT_SKIPPING|UNIT_SPACING)) == (UNIT_SKIPPING|UNIT_SPACING)) { + sprintf(msg, "1132 printer skip and space at same time?"); + xio_error(msg); + } + break; - default: - sprintf(msg, "Invalid 1132 printer XIO function %x", func); - xio_error(msg); - } + default: + sprintf(msg, "Invalid 1132 printer XIO function %x", func); + xio_error(msg); + } } #define SET_ACTION(u,a) {(u)->flags &= ~(UNIT_SKIPPING|UNIT_SPACING|UNIT_PRINTING|UNIT_TRANSFERRING); (u)->flags |= a;} static t_stat prt_svc (UNIT *uptr) { - return IS_1403(uptr) ? prt1403_svc(uptr) : prt1132_svc(uptr); + return IS_1403(uptr) ? prt1403_svc(uptr) : prt1132_svc(uptr); } /* prt1132_svc - emulated timeout for 1132 operation */ static t_stat prt1132_svc (UNIT *uptr) { - if (PRT_DSW & PRT1132_DSW_NOT_READY) { /* cancel operation if printer went offline */ - if (DO_TRACE(uptr)) trace_io("1132 form check"); - SETBIT(uptr->flags, UNIT_FORMCHECK); - SET_ACTION(uptr, 0); - forms_check(TRUE); /* and turn on forms check lamp */ - return SCPE_OK; - } + if (PRT_DSW & PRT1132_DSW_NOT_READY) { /* cancel operation if printer went offline */ + if (DO_TRACE(uptr)) trace_io("1132 form check"); + SETBIT(uptr->flags, UNIT_FORMCHECK); + SET_ACTION(uptr, 0); + forms_check(TRUE); /* and turn on forms check lamp */ + return SCPE_OK; + } - if (uptr->flags & UNIT_SPACING) { - flush_prt_line(uptr->fileref, UNIT_SPACING, IS_PHYSICAL(uptr)); + if (uptr->flags & UNIT_SPACING) { + flush_prt_line(uptr->fileref, UNIT_SPACING, IS_PHYSICAL(uptr)); - CLRBIT(PRT_DSW, PRT1132_DSW_CHANNEL_MASK|PRT1132_DSW_PRINTER_BUSY|PRT1132_DSW_CARRIAGE_BUSY); - SETBIT(PRT_DSW, cc_format_1132(cctape[prt_row]) | PRT1132_DSW_SPACE_RESPONSE); - SETBIT(ILSW[1], ILSW_1_1132_PRINTER); - CLRBIT(uptr->flags, UNIT_SPACING); /* done with this */ - calc_ints(); - } + CLRBIT(PRT_DSW, PRT1132_DSW_CHANNEL_MASK|PRT1132_DSW_PRINTER_BUSY|PRT1132_DSW_CARRIAGE_BUSY); + SETBIT(PRT_DSW, cc_format_1132(cctape[prt_row]) | PRT1132_DSW_SPACE_RESPONSE); + SETBIT(ILSW[1], ILSW_1_1132_PRINTER); + CLRBIT(uptr->flags, UNIT_SPACING); /* done with this */ + calc_ints(); + } - if (uptr->flags & UNIT_SKIPPING) { - do { - flush_prt_line(uptr->fileref, UNIT_SKIPPING, IS_PHYSICAL(uptr)); - CLRBIT(PRT_DSW, PRT1132_DSW_CHANNEL_MASK); - SETBIT(PRT_DSW, cc_format_1132(cctape[prt_row])); - } while ((cctape[prt_row] & CC_1132_BITS) == 0); /* slew directly to a cc tape punch */ + if (uptr->flags & UNIT_SKIPPING) { + do { + flush_prt_line(uptr->fileref, UNIT_SKIPPING, IS_PHYSICAL(uptr)); + CLRBIT(PRT_DSW, PRT1132_DSW_CHANNEL_MASK); + SETBIT(PRT_DSW, cc_format_1132(cctape[prt_row])); + } while ((cctape[prt_row] & CC_1132_BITS) == 0); /* slew directly to a cc tape punch */ - SETBIT(PRT_DSW, cc_format_1132(cctape[prt_row]) | PRT1132_DSW_SKIP_RESPONSE); - SETBIT(ILSW[1], ILSW_1_1132_PRINTER); - calc_ints(); - } + SETBIT(PRT_DSW, cc_format_1132(cctape[prt_row]) | PRT1132_DSW_SKIP_RESPONSE); + SETBIT(ILSW[1], ILSW_1_1132_PRINTER); + calc_ints(); + } - if (uptr->flags & UNIT_PRINTING) { - if (! save_1132_prt_line(codewheel1132[prt_nchar].ascii)) { /* save previous printed line */ - trace_io("* Print check -- buffer not set in time"); - SETBIT(uptr->flags, UNIT_DATACHECK); /* buffer wasn't set in time */ - SET_ACTION(uptr, 0); - print_check(TRUE); /* and turn on forms check lamp */ + if (uptr->flags & UNIT_PRINTING) { + if (! save_1132_prt_line(codewheel1132[prt_nchar].ascii)) { /* save previous printed line */ + trace_io("* Print check -- buffer not set in time"); + SETBIT(uptr->flags, UNIT_DATACHECK); /* buffer wasn't set in time */ + SET_ACTION(uptr, 0); + print_check(TRUE); /* and turn on forms check lamp */ -/* if (running) - reason = STOP_IMMEDIATE; // halt on check +/* if (running) + reason = STOP_IMMEDIATE; // halt on check */ - return SCPE_OK; - } + return SCPE_OK; + } - prt_nchar = (prt_nchar + 1) % WHEELCHARS_1132; /* advance print drum */ + prt_nchar = (prt_nchar + 1) % WHEELCHARS_1132; /* advance print drum */ - SETBIT(PRT_DSW, PRT1132_DSW_READ_EMITTER_RESPONSE); /* issue interrupt to tell printer to set buffer */ - SETBIT(ILSW[1], ILSW_1_1132_PRINTER); /* we'll save the printed stuff just before next emitter response (later than on real 1130) */ - calc_ints(); - } + SETBIT(PRT_DSW, PRT1132_DSW_READ_EMITTER_RESPONSE); /* issue interrupt to tell printer to set buffer */ + SETBIT(ILSW[1], ILSW_1_1132_PRINTER); /* we'll save the printed stuff just before next emitter response (later than on real 1130) */ + calc_ints(); + } - if (uptr->flags & (UNIT_SPACING|UNIT_SKIPPING|UNIT_PRINTING)) { /* still doing something */ - SETBIT(PRT_DSW, PRT1132_DSW_PRINTER_BUSY); - sim_activate(uptr, prt_cwait); - } - else - CLRBIT(PRT_DSW, PRT1132_DSW_PRINTER_BUSY); + if (uptr->flags & (UNIT_SPACING|UNIT_SKIPPING|UNIT_PRINTING)) { /* still doing something */ + SETBIT(PRT_DSW, PRT1132_DSW_PRINTER_BUSY); + sim_activate(uptr, prt_cwait); + } + else + CLRBIT(PRT_DSW, PRT1132_DSW_PRINTER_BUSY); - return SCPE_OK; + return SCPE_OK; } void save_1403_prt_line (int32 addr) { - size_t j; - int i, r, ch, even = TRUE; - unsigned char ebcdic; - int32 wd; + size_t j; + int i, r, ch, even = TRUE; + unsigned char ebcdic; + int32 wd; - for (i = 0; i < PRT1403_COLUMNS; i++) { - if (even) { /* fetch next word from memory */ - wd = M[addr++]; - ebcdic = (unsigned char) ((wd >> 8) & 0x7F); - even = FALSE; - } - else { - ebcdic = (unsigned char) (wd & 0x7F); /* use low byte of previously fetched word */ - even = TRUE; - } + for (i = 0; i < PRT1403_COLUMNS; i++) { + if (even) { /* fetch next word from memory */ + wd = M[addr++]; + ebcdic = (unsigned char) ((wd >> 8) & 0x7F); + even = FALSE; + } + else { + ebcdic = (unsigned char) (wd & 0x7F); /* use low byte of previously fetched word */ + even = TRUE; + } - ch = ' '; /* translate ebcdic to ascii. Don't bother checking for parity errors */ - for (j = 0; j < WHEELCHARS_1403; j++) { - if (codewheel1403[j].ebcdic == ebcdic) { - ch = codewheel1403[j].ascii; - break; - } - } + ch = ' '; /* translate ebcdic to ascii. Don't bother checking for parity errors */ + for (j = 0; j < WHEELCHARS_1403; j++) { + if (codewheel1403[j].ebcdic == ebcdic) { + ch = codewheel1403[j].ascii; + break; + } + } - if (ch > ' ') { - if ((r = nprint[i]) < MAX_OVPRINT) { - if (ncol[r] <= i) { /* we haven't moved this far yet */ - if (ncol[r] == 0) /* first char in this row? */ - memset(prtbuf+r*MAX_COLUMNS, ' ', PRT1403_COLUMNS); /* blank out the new row */ - ncol[r] = i+1; /* remember new row length */ - } - prtbuf[r*MAX_COLUMNS + i] = (char) ch; /* save the character */ + if (ch > ' ') { + if ((r = nprint[i]) < MAX_OVPRINT) { + if (ncol[r] <= i) { /* we haven't moved this far yet */ + if (ncol[r] == 0) /* first char in this row? */ + memset(prtbuf+r*MAX_COLUMNS, ' ', PRT1403_COLUMNS); /* blank out the new row */ + ncol[r] = i+1; /* remember new row length */ + } + prtbuf[r*MAX_COLUMNS + i] = (char) ch; /* save the character */ - nprint[i]++; /* remember max overprintings for this column */ - maxnp = MAX(maxnp, nprint[i]); - } - } - } + nprint[i]++; /* remember max overprintings for this column */ + maxnp = MAX(maxnp, nprint[i]); + } + } + } } void xio_1403_printer (int32 iocc_addr, int32 func, int32 modify) { - UNIT *uptr = &prt_unit[0]; + UNIT *uptr = &prt_unit[0]; - switch (func) { - case XIO_INITW: /* print a line */ - save_1403_prt_line(iocc_addr); /* put formatted line into our print buffer */ + switch (func) { + case XIO_INITW: /* print a line */ + save_1403_prt_line(iocc_addr); /* put formatted line into our print buffer */ - SETBIT(uptr->flags, UNIT_TRANSFERRING); /* schedule transfer complete interrupt */ - SETBIT(PRT_DSW, PRT1403_DSW_PRINTER_BUSY); - sim_activate(uptr, prt_twait); - break; + SETBIT(uptr->flags, UNIT_TRANSFERRING); /* schedule transfer complete interrupt */ + SETBIT(PRT_DSW, PRT1403_DSW_PRINTER_BUSY); + sim_activate(uptr, prt_twait); + break; - case XIO_CONTROL: /* initiate single space */ - if (uptr->flags & UNIT_SKIPPING) { - xio_error("1403 printer skip and space at same time?"); - } - else { - SETBIT(uptr->flags, UNIT_SPACING); - SETBIT(PRT_DSW, PRT1403_DSW_CARRIAGE_BUSY); - sim_activate(uptr, prt_fwait); - } - break; + case XIO_CONTROL: /* initiate single space */ + if (uptr->flags & UNIT_SKIPPING) { + xio_error("1403 printer skip and space at same time?"); + } + else { + SETBIT(uptr->flags, UNIT_SPACING); + SETBIT(PRT_DSW, PRT1403_DSW_CARRIAGE_BUSY); + sim_activate(uptr, prt_fwait); + } + break; - case XIO_WRITE: /* initiate skip */ - if (uptr->flags & UNIT_SPACING) { - xio_error("1403 printer skip and space at same time?"); - } - else { - SETBIT(uptr->flags, UNIT_SKIPPING); - SKIPTARGET = ReadW(iocc_addr) & CC_1403_BITS; /* get CC bits that we're to match */ - SETBIT(PRT_DSW, PRT1403_DSW_CARRIAGE_BUSY); - sim_activate(uptr, prt_fwait); - } - break; + case XIO_WRITE: /* initiate skip */ + if (uptr->flags & UNIT_SPACING) { + xio_error("1403 printer skip and space at same time?"); + } + else { + SETBIT(uptr->flags, UNIT_SKIPPING); + SKIPTARGET = ReadW(iocc_addr) & CC_1403_BITS; /* get CC bits that we're to match */ + SETBIT(PRT_DSW, PRT1403_DSW_CARRIAGE_BUSY); + sim_activate(uptr, prt_fwait); + } + break; - case XIO_SENSE_DEV: /* get device status word */ - ACC = PRT_DSW; - if (modify & 0x01) { /* reset interrupts */ - CLRBIT(PRT_DSW, PRT1403_DSW_PARITY_CHECK | PRT1403_DSW_TRANSFER_COMPLETE | - PRT1403_DSW_PRINT_COMPLETE | PRT1403_DSW_CARRIAGE_COMPLETE | - PRT1403_DSW_RING_CHECK | PRT1403_DSW_SYNC_CHECK); - CLRBIT(ILSW[4], ILSW_4_1403_PRINTER); - } - break; - } + case XIO_SENSE_DEV: /* get device status word */ + ACC = PRT_DSW; + if (modify & 0x01) { /* reset interrupts */ + CLRBIT(PRT_DSW, PRT1403_DSW_PARITY_CHECK | PRT1403_DSW_TRANSFER_COMPLETE | + PRT1403_DSW_PRINT_COMPLETE | PRT1403_DSW_CARRIAGE_COMPLETE | + PRT1403_DSW_RING_CHECK | PRT1403_DSW_SYNC_CHECK); + CLRBIT(ILSW[4], ILSW_4_1403_PRINTER); + } + break; + } } static t_stat prt1403_svc(UNIT *uptr) { - if (PRT_DSW & PRT1403_DSW_NOT_READY) { /* cancel operation if printer went offline */ - SET_ACTION(uptr, 0); - if (DO_TRACE(uptr)) trace_io("1403 form check"); - forms_check(TRUE); /* and turn on forms check lamp */ - } - else if (uptr->flags & UNIT_TRANSFERRING) { /* end of transfer */ - CLRBIT(uptr->flags, UNIT_TRANSFERRING); - SETBIT(uptr->flags, UNIT_PRINTING); /* schedule "print complete" */ + if (PRT_DSW & PRT1403_DSW_NOT_READY) { /* cancel operation if printer went offline */ + SET_ACTION(uptr, 0); + if (DO_TRACE(uptr)) trace_io("1403 form check"); + forms_check(TRUE); /* and turn on forms check lamp */ + } + else if (uptr->flags & UNIT_TRANSFERRING) { /* end of transfer */ + CLRBIT(uptr->flags, UNIT_TRANSFERRING); + SETBIT(uptr->flags, UNIT_PRINTING); /* schedule "print complete" */ - SETBIT(PRT_DSW, PRT1403_DSW_TRANSFER_COMPLETE); /* issue transfer complete interrupt */ - SETBIT(ILSW[4], ILSW_4_1403_PRINTER); - } - else if (uptr->flags & UNIT_PRINTING) { - CLRBIT(uptr->flags, UNIT_PRINTING); - CLRBIT(PRT_DSW, PRT1403_DSW_PRINTER_BUSY); + SETBIT(PRT_DSW, PRT1403_DSW_TRANSFER_COMPLETE); /* issue transfer complete interrupt */ + SETBIT(ILSW[4], ILSW_4_1403_PRINTER); + } + else if (uptr->flags & UNIT_PRINTING) { + CLRBIT(uptr->flags, UNIT_PRINTING); + CLRBIT(PRT_DSW, PRT1403_DSW_PRINTER_BUSY); - SETBIT(PRT_DSW, PRT1403_DSW_PRINT_COMPLETE); - SETBIT(ILSW[4], ILSW_4_1403_PRINTER); /* issue print complete interrupt */ - } - else if (uptr->flags & UNIT_SKIPPING) { - do { /* find line with exact match of tape punches */ - flush_prt_line(uptr->fileref, UNIT_SKIPPING, IS_PHYSICAL(uptr)); - } while (cctape[prt_row] != SKIPTARGET); /* slew directly to requested cc tape punch */ + SETBIT(PRT_DSW, PRT1403_DSW_PRINT_COMPLETE); + SETBIT(ILSW[4], ILSW_4_1403_PRINTER); /* issue print complete interrupt */ + } + else if (uptr->flags & UNIT_SKIPPING) { + do { /* find line with exact match of tape punches */ + flush_prt_line(uptr->fileref, UNIT_SKIPPING, IS_PHYSICAL(uptr)); + } while (cctape[prt_row] != SKIPTARGET); /* slew directly to requested cc tape punch */ - CLRBIT(uptr->flags, UNIT_SKIPPING); /* done with this */ - CLRBIT(PRT_DSW, PRT1403_DSW_CARRIAGE_BUSY); + CLRBIT(uptr->flags, UNIT_SKIPPING); /* done with this */ + CLRBIT(PRT_DSW, PRT1403_DSW_CARRIAGE_BUSY); - SETBIT(PRT_DSW, PRT1403_DSW_CARRIAGE_COMPLETE); - SETBIT(ILSW[4], ILSW_4_1403_PRINTER); - } - else if (uptr->flags & UNIT_SPACING) { - flush_prt_line(uptr->fileref, UNIT_SPACING, IS_PHYSICAL(uptr)); + SETBIT(PRT_DSW, PRT1403_DSW_CARRIAGE_COMPLETE); + SETBIT(ILSW[4], ILSW_4_1403_PRINTER); + } + else if (uptr->flags & UNIT_SPACING) { + flush_prt_line(uptr->fileref, UNIT_SPACING, IS_PHYSICAL(uptr)); - CLRBIT(uptr->flags, UNIT_SPACING); /* done with this */ - CLRBIT(PRT_DSW, PRT1403_DSW_CARRIAGE_BUSY); + CLRBIT(uptr->flags, UNIT_SPACING); /* done with this */ + CLRBIT(PRT_DSW, PRT1403_DSW_CARRIAGE_BUSY); - SETBIT(PRT_DSW, PRT1403_DSW_CARRIAGE_COMPLETE); - SETBIT(ILSW[4], ILSW_4_1403_PRINTER); - } + SETBIT(PRT_DSW, PRT1403_DSW_CARRIAGE_COMPLETE); + SETBIT(ILSW[4], ILSW_4_1403_PRINTER); + } - if (uptr->flags & (UNIT_PRINTING|UNIT_SKIPPING|UNIT_SPACING|UNIT_TRANSFERRING)) - sim_activate(uptr, prt_fwait); + if (uptr->flags & (UNIT_PRINTING|UNIT_SKIPPING|UNIT_SPACING|UNIT_TRANSFERRING)) + sim_activate(uptr, prt_fwait); - CLRBIT(PRT_DSW, PRT1403_DSW_CH9|PRT1403_DSW_CH12); /* set the two CC bits in the DSW */ - if (cctape[prt_row] & CC_CHANNEL_9) - SETBIT(PRT_DSW, PRT1403_DSW_CH9); - if (cctape[prt_row] & CC_CHANNEL_12) - SETBIT(PRT_DSW, PRT1403_DSW_CH12); + CLRBIT(PRT_DSW, PRT1403_DSW_CH9|PRT1403_DSW_CH12); /* set the two CC bits in the DSW */ + if (cctape[prt_row] & CC_CHANNEL_9) + SETBIT(PRT_DSW, PRT1403_DSW_CH9); + if (cctape[prt_row] & CC_CHANNEL_12) + SETBIT(PRT_DSW, PRT1403_DSW_CH12); - calc_ints(); - return SCPE_OK; + calc_ints(); + return SCPE_OK; } /* prt_reset - reset emulated printer */ static t_stat prt_reset (DEVICE *dptr) { - UNIT *uptr = &prt_unit[0]; - size_t i; + UNIT *uptr = &prt_unit[0]; + size_t i; - sim_cancel(uptr); + sim_cancel(uptr); - memset(cctape, 0, sizeof(cctape)); /* copy punch list into carriage control tape image */ + memset(cctape, 0, sizeof(cctape)); /* copy punch list into carriage control tape image */ - if (cgi) { - for (i = 0; i < (sizeof(cccgi)/sizeof(cccgi[0])); i++) - cctape[cccgi[i].row-1] |= cccgi[i].channels; - } - else - for (i = 0; i < (sizeof(ccpunches)/sizeof(ccpunches[0])); i++) - cctape[ccpunches[i].row-1] |= ccpunches[i].channels; + if (cgi) { + for (i = 0; i < (sizeof(cccgi)/sizeof(cccgi[0])); i++) + cctape[cccgi[i].row-1] |= cccgi[i].channels; + } + else + for (i = 0; i < (sizeof(ccpunches)/sizeof(ccpunches[0])); i++) + cctape[ccpunches[i].row-1] |= ccpunches[i].channels; - prt_nchar = 0; - prt_row = 0; - prt_nnl = 0; + prt_nchar = 0; + prt_row = 0; + prt_nnl = 0; - CLRBIT(uptr->flags, UNIT_FORMCHECK|UNIT_DATACHECK|UNIT_PRINTING|UNIT_SPACING|UNIT_SKIPPING| - UNIT_TRANSFERRING|UNIT_PARITYCHECK|UNIT_RINGCHECK|UNIT_SYNCCHECK); + CLRBIT(uptr->flags, UNIT_FORMCHECK|UNIT_DATACHECK|UNIT_PRINTING|UNIT_SPACING|UNIT_SKIPPING| + UNIT_TRANSFERRING|UNIT_PARITYCHECK|UNIT_RINGCHECK|UNIT_SYNCCHECK); - if (IS_1132(uptr)) { - CLRBIT(ILSW[1], ILSW_1_1132_PRINTER); - PRT_DSW = cc_format_1132(cctape[prt_row]); - if (! IS_ONLINE(uptr)) - SETBIT(PRT_DSW, PRT1132_DSW_NOT_READY); - } - else { - CLRBIT(ILSW[4], ILSW_4_1403_PRINTER); - PRT_DSW = 0; - if (cctape[prt_row] & CC_CHANNEL_9) - SETBIT(PRT_DSW, PRT1403_DSW_CH9); - if (cctape[prt_row] & CC_CHANNEL_12) - SETBIT(PRT_DSW, PRT1403_DSW_CH12); - if (! IS_ONLINE(uptr)) - SETBIT(PRT_DSW, PRT1403_DSW_NOT_READY); - } + if (IS_1132(uptr)) { + CLRBIT(ILSW[1], ILSW_1_1132_PRINTER); + PRT_DSW = cc_format_1132(cctape[prt_row]); + if (! IS_ONLINE(uptr)) + SETBIT(PRT_DSW, PRT1132_DSW_NOT_READY); + } + else { + CLRBIT(ILSW[4], ILSW_4_1403_PRINTER); + PRT_DSW = 0; + if (cctape[prt_row] & CC_CHANNEL_9) + SETBIT(PRT_DSW, PRT1403_DSW_CH9); + if (cctape[prt_row] & CC_CHANNEL_12) + SETBIT(PRT_DSW, PRT1403_DSW_CH12); + if (! IS_ONLINE(uptr)) + SETBIT(PRT_DSW, PRT1403_DSW_NOT_READY); + } - SET_ACTION(uptr, 0); - calc_ints(); - reset_prt_line(); + SET_ACTION(uptr, 0); + calc_ints(); + reset_prt_line(); - forms_check(FALSE); - return SCPE_OK; + forms_check(FALSE); + return SCPE_OK; } static t_stat prt_attach (UNIT *uptr, CONST char *cptr) { - t_stat rval; + t_stat rval; char gbuf[2*CBUFSIZE]; - /* assume failure */ - SETBIT(PRT_DSW, IS_1132(uptr) ? PRT1132_DSW_NOT_READY : PRT1403_DSW_NOT_READY); - formfed = FALSE; + /* assume failure */ + SETBIT(PRT_DSW, IS_1132(uptr) ? PRT1132_DSW_NOT_READY : PRT1403_DSW_NOT_READY); + formfed = FALSE; - if (uptr->flags & UNIT_ATT) { - if ((rval = prt_detach(uptr)) != SCPE_OK) { - return rval; - } - } + if (uptr->flags & UNIT_ATT) { + if ((rval = prt_detach(uptr)) != SCPE_OK) { + return rval; + } + } - if (sim_switches & SWMASK('P')) /* set physical (unbuffered) printer flag */ - SETBIT(uptr->flags, UNIT_PHYSICAL_PTR); - else - CLRBIT(uptr->flags, UNIT_PHYSICAL_PTR); + if (sim_switches & SWMASK('P')) /* set physical (unbuffered) printer flag */ + SETBIT(uptr->flags, UNIT_PHYSICAL_PTR); + else + CLRBIT(uptr->flags, UNIT_PHYSICAL_PTR); - sim_cancel(uptr); + sim_cancel(uptr); - if (strcmp(cptr, "(stdout)") == 0) { /* connect printer to stdout */ - if (uptr -> flags & UNIT_DIS) return SCPE_UDIS; /* disabled? */ - uptr->filename = (char *)calloc(CBUFSIZE, sizeof(char)); - strcpy(uptr->filename, "(stdout)"); - uptr->fileref = stdout; - SETBIT(uptr->flags, UNIT_ATT); - uptr->pos = 0; - } - else { - if ((rval = attach_unit(uptr, quotefix(cptr, gbuf))) != SCPE_OK) - return rval; - } + if (strcmp(cptr, "(stdout)") == 0) { /* connect printer to stdout */ + if (uptr -> flags & UNIT_DIS) return SCPE_UDIS; /* disabled? */ + uptr->filename = (char *)calloc(CBUFSIZE, sizeof(char)); + strcpy(uptr->filename, "(stdout)"); + uptr->fileref = stdout; + SETBIT(uptr->flags, UNIT_ATT); + uptr->pos = 0; + } + else { + if ((rval = attach_unit(uptr, quotefix(cptr, gbuf))) != SCPE_OK) + return rval; + } - fseek(uptr->fileref, 0, SEEK_END); /* if we opened an existing file, append to it */ - uptr->pos = ftell(uptr->fileref); + fseek(uptr->fileref, 0, SEEK_END); /* if we opened an existing file, append to it */ + uptr->pos = ftell(uptr->fileref); - if (IS_1132(uptr)) { - CLRBIT(ILSW[1], ILSW_1_1132_PRINTER); - CLRBIT(uptr->flags, UNIT_FORMCHECK|UNIT_DATACHECK); - } - else { - CLRBIT(ILSW[4], ILSW_4_1403_PRINTER); - CLRBIT(uptr->flags, UNIT_PARITYCHECK|UNIT_RINGCHECK|UNIT_SYNCCHECK); - } + if (IS_1132(uptr)) { + CLRBIT(ILSW[1], ILSW_1_1132_PRINTER); + CLRBIT(uptr->flags, UNIT_FORMCHECK|UNIT_DATACHECK); + } + else { + CLRBIT(ILSW[4], ILSW_4_1403_PRINTER); + CLRBIT(uptr->flags, UNIT_PARITYCHECK|UNIT_RINGCHECK|UNIT_SYNCCHECK); + } - SET_ACTION(uptr, 0); - calc_ints(); + SET_ACTION(uptr, 0); + calc_ints(); - prt_nchar = 0; - prt_nnl = 0; - prt_row = 0; - reset_prt_line(); + prt_nchar = 0; + prt_nnl = 0; + prt_row = 0; + reset_prt_line(); - if (IS_1132(uptr)) { - PRT_DSW = (PRT_DSW & ~PRT1132_DSW_CHANNEL_MASK) | cc_format_1132(cctape[prt_row]); + if (IS_1132(uptr)) { + PRT_DSW = (PRT_DSW & ~PRT1132_DSW_CHANNEL_MASK) | cc_format_1132(cctape[prt_row]); - if (IS_ONLINE(uptr)) - CLRBIT(PRT_DSW, PRT1132_DSW_NOT_READY); - } - else { - CLRBIT(PRT_DSW, PRT1403_DSW_CH9 | PRT1403_DSW_CH12); - if (cctape[prt_row] & CC_CHANNEL_9) - SETBIT(PRT_DSW, PRT1403_DSW_CH9); - if (cctape[prt_row] & CC_CHANNEL_12) - SETBIT(PRT_DSW, PRT1403_DSW_CH12); + if (IS_ONLINE(uptr)) + CLRBIT(PRT_DSW, PRT1132_DSW_NOT_READY); + } + else { + CLRBIT(PRT_DSW, PRT1403_DSW_CH9 | PRT1403_DSW_CH12); + if (cctape[prt_row] & CC_CHANNEL_9) + SETBIT(PRT_DSW, PRT1403_DSW_CH9); + if (cctape[prt_row] & CC_CHANNEL_12) + SETBIT(PRT_DSW, PRT1403_DSW_CH12); - if (IS_ONLINE(uptr)) - CLRBIT(PRT_DSW, PRT1403_DSW_NOT_READY); /* fixed by Carl Claunch */ - } + if (IS_ONLINE(uptr)) + CLRBIT(PRT_DSW, PRT1403_DSW_NOT_READY); /* fixed by Carl Claunch */ + } - forms_check(FALSE); + forms_check(FALSE); - return SCPE_OK; + return SCPE_OK; } static t_stat prt_detach (UNIT *uptr) { - t_stat rval; + t_stat rval; - if (uptr->flags & UNIT_ATT) - flush_prt_line(uptr->fileref, TRUE, TRUE); + if (uptr->flags & UNIT_ATT) + flush_prt_line(uptr->fileref, TRUE, TRUE); - if (uptr->fileref == stdout) { - CLRBIT(uptr->flags, UNIT_ATT); - free(uptr->filename); - uptr->filename = NULL; - } - else if ((rval = detach_unit(uptr)) != SCPE_OK) - return rval; + if (uptr->fileref == stdout) { + CLRBIT(uptr->flags, UNIT_ATT); + free(uptr->filename); + uptr->filename = NULL; + } + else if ((rval = detach_unit(uptr)) != SCPE_OK) + return rval; - sim_cancel(uptr); + sim_cancel(uptr); - if (IS_1132(uptr)) { - CLRBIT(ILSW[1], ILSW_1_1132_PRINTER); - CLRBIT(uptr->flags, UNIT_FORMCHECK|UNIT_DATACHECK); - SETBIT(PRT_DSW, PRT1132_DSW_NOT_READY); - } - else { - CLRBIT(ILSW[4], ILSW_4_1403_PRINTER); - SETBIT(PRT_DSW, PRT1403_DSW_NOT_READY); - } - SET_ACTION(uptr, 0); + if (IS_1132(uptr)) { + CLRBIT(ILSW[1], ILSW_1_1132_PRINTER); + CLRBIT(uptr->flags, UNIT_FORMCHECK|UNIT_DATACHECK); + SETBIT(PRT_DSW, PRT1132_DSW_NOT_READY); + } + else { + CLRBIT(ILSW[4], ILSW_4_1403_PRINTER); + SETBIT(PRT_DSW, PRT1403_DSW_NOT_READY); + } + SET_ACTION(uptr, 0); - calc_ints(); + calc_ints(); - forms_check(FALSE); - return SCPE_OK; + forms_check(FALSE); + return SCPE_OK; } diff --git a/Ibm1130/ibm1130_prtwheel.h b/Ibm1130/ibm1130_prtwheel.h index 617f693e..97a04bf4 100644 --- a/Ibm1130/ibm1130_prtwheel.h +++ b/Ibm1130/ibm1130_prtwheel.h @@ -10,115 +10,115 @@ */ struct tag_codewheel { - unsigned char ascii; - unsigned char ebcdic; + unsigned char ascii; + unsigned char ebcdic; }; static struct tag_codewheel codewheel1132[] = -{ /* characters and EBCDIC codes in printwheel order */ - {'A', 0xC1}, - {'B', 0xC2}, - {'C', 0xC3}, - {'D', 0xC4}, - {'F', 0xC6}, - {'H', 0xC8}, - {'I', 0xC9}, - {'S', 0xE2}, - {'T', 0xE3}, - {'U', 0xE4}, - {'V', 0xE5}, - {'1', 0xF1}, - {'2', 0xF2}, - {'3', 0xF3}, - {'4', 0xF4}, - {'5', 0xF5}, - {'6', 0xF6}, - {'7', 0xF7}, - {'8', 0xF8}, - {'9', 0xF9}, - {'0', 0xF0}, - {'=', 0x7E}, - {'$', 0x5B}, - {'.', 0x4B}, - {'\'', 0x7D}, - {',', 0x6B}, - {')', 0x5D}, - {'-', 0x60}, - {'(', 0x4D}, - {'+', 0x4E}, - {'/', 0x61}, - {'*', 0x5C}, - {'&', 0x50}, - {'J', 0xD1}, - {'K', 0xD2}, - {'L', 0xD3}, - {'M', 0xD4}, - {'N', 0xD5}, - {'O', 0xD6}, - {'P', 0xD7}, - {'Q', 0xD8}, - {'R', 0xD9}, - {'E', 0xC5}, - {'G', 0xC7}, - {'W', 0xE6}, - {'X', 0xE7}, - {'Y', 0xE8}, - {'Z', 0xE9}, +{ /* characters and EBCDIC codes in printwheel order */ + {'A', 0xC1}, + {'B', 0xC2}, + {'C', 0xC3}, + {'D', 0xC4}, + {'F', 0xC6}, + {'H', 0xC8}, + {'I', 0xC9}, + {'S', 0xE2}, + {'T', 0xE3}, + {'U', 0xE4}, + {'V', 0xE5}, + {'1', 0xF1}, + {'2', 0xF2}, + {'3', 0xF3}, + {'4', 0xF4}, + {'5', 0xF5}, + {'6', 0xF6}, + {'7', 0xF7}, + {'8', 0xF8}, + {'9', 0xF9}, + {'0', 0xF0}, + {'=', 0x7E}, + {'$', 0x5B}, + {'.', 0x4B}, + {'\'', 0x7D}, + {',', 0x6B}, + {')', 0x5D}, + {'-', 0x60}, + {'(', 0x4D}, + {'+', 0x4E}, + {'/', 0x61}, + {'*', 0x5C}, + {'&', 0x50}, + {'J', 0xD1}, + {'K', 0xD2}, + {'L', 0xD3}, + {'M', 0xD4}, + {'N', 0xD5}, + {'O', 0xD6}, + {'P', 0xD7}, + {'Q', 0xD8}, + {'R', 0xD9}, + {'E', 0xC5}, + {'G', 0xC7}, + {'W', 0xE6}, + {'X', 0xE7}, + {'Y', 0xE8}, + {'Z', 0xE9}, }; #define WHEELCHARS_1132 (sizeof(codewheel1132)/sizeof(codewheel1132[0])) static struct tag_codewheel codewheel1403[] = { - {'A', 0x64}, - {'B', 0x25}, - {'C', 0x26}, - {'D', 0x67}, - {'E', 0x68}, - {'F', 0x29}, - {'G', 0x2A}, - {'H', 0x6B}, - {'I', 0x2C}, - {'J', 0x58}, - {'K', 0x19}, - {'L', 0x1A}, - {'M', 0x5B}, - {'N', 0x1C}, - {'O', 0x5D}, - {'P', 0x5E}, - {'Q', 0x1F}, - {'R', 0x20}, - {'S', 0x0D}, - {'T', 0x0E}, - {'U', 0x4F}, - {'V', 0x10}, - {'W', 0x51}, - {'X', 0x52}, - {'Y', 0x13}, - {'Z', 0x54}, - {'0', 0x49}, - {'1', 0x40}, - {'2', 0x01}, - {'3', 0x02}, - {'4', 0x43}, - {'5', 0x04}, - {'6', 0x45}, - {'7', 0x46}, - {'8', 0x07}, - {'9', 0x08}, - {' ', 0x7F}, - {'.', 0x6E}, - {'(', 0x57}, - {'+', 0x6D}, - {'&', 0x15}, - {'$', 0x62}, - {'*', 0x23}, - {')', 0x2F}, - {'-', 0x61}, - {'/', 0x4C}, - {',', 0x16}, - {'\'', 0x0B}, - {'=', 0x4A}, + {'A', 0x64}, + {'B', 0x25}, + {'C', 0x26}, + {'D', 0x67}, + {'E', 0x68}, + {'F', 0x29}, + {'G', 0x2A}, + {'H', 0x6B}, + {'I', 0x2C}, + {'J', 0x58}, + {'K', 0x19}, + {'L', 0x1A}, + {'M', 0x5B}, + {'N', 0x1C}, + {'O', 0x5D}, + {'P', 0x5E}, + {'Q', 0x1F}, + {'R', 0x20}, + {'S', 0x0D}, + {'T', 0x0E}, + {'U', 0x4F}, + {'V', 0x10}, + {'W', 0x51}, + {'X', 0x52}, + {'Y', 0x13}, + {'Z', 0x54}, + {'0', 0x49}, + {'1', 0x40}, + {'2', 0x01}, + {'3', 0x02}, + {'4', 0x43}, + {'5', 0x04}, + {'6', 0x45}, + {'7', 0x46}, + {'8', 0x07}, + {'9', 0x08}, + {' ', 0x7F}, + {'.', 0x6E}, + {'(', 0x57}, + {'+', 0x6D}, + {'&', 0x15}, + {'$', 0x62}, + {'*', 0x23}, + {')', 0x2F}, + {'-', 0x61}, + {'/', 0x4C}, + {',', 0x16}, + {'\'', 0x0B}, + {'=', 0x4A}, }; #define WHEELCHARS_1403 (sizeof(codewheel1403)/sizeof(codewheel1403[0])) diff --git a/Ibm1130/ibm1130_ptrp.c b/Ibm1130/ibm1130_ptrp.c index 2af3e64f..e71b6b48 100644 --- a/Ibm1130/ibm1130_ptrp.c +++ b/Ibm1130/ibm1130_ptrp.c @@ -20,16 +20,16 @@ #include "ibm1130_defs.h" /*************************************************************************************** - * 1134 Paper Tape Reader device PTR - * 1055 Paper Tape Punch device PTP (shares DSW with PTR) + * 1134 Paper Tape Reader device PTR + * 1055 Paper Tape Punch device PTP (shares DSW with PTR) ***************************************************************************************/ -#define PTR1134_DSW_READER_RESPONSE 0x4000 -#define PTR1134_DSW_PUNCH_RESPONSE 0x1000 -#define PTR1134_DSW_READER_BUSY 0x0800 -#define PTR1134_DSW_READER_NOT_READY 0x0400 -#define PTR1134_DSW_PUNCH_BUSY 0x0200 -#define PTR1134_DSW_PUNCH_NOT_READY 0x0100 +#define PTR1134_DSW_READER_RESPONSE 0x4000 +#define PTR1134_DSW_PUNCH_RESPONSE 0x1000 +#define PTR1134_DSW_READER_BUSY 0x0800 +#define PTR1134_DSW_READER_NOT_READY 0x0400 +#define PTR1134_DSW_PUNCH_BUSY 0x0200 +#define PTR1134_DSW_PUNCH_NOT_READY 0x0100 #define IS_ONLINE(u) (((u)->flags & (UNIT_ATT|UNIT_DIS)) == UNIT_ATT) @@ -37,273 +37,273 @@ static t_stat ptr_svc (UNIT *uptr); static t_stat ptr_reset (DEVICE *dptr); static t_stat ptr_attach (UNIT *uptr, CONST char *cptr); static t_stat ptr_detach (UNIT *uptr); -static t_stat ptr_boot (int32 unitno, DEVICE *dptr); +static t_stat ptr_boot (int32 unitno, DEVICE *dptr); static t_stat ptp_svc (UNIT *uptr); static t_stat ptp_reset (DEVICE *dptr); static t_stat ptp_attach (UNIT *uptr, CONST char *cptr); static t_stat ptp_detach (UNIT *uptr); -static int16 ptr_dsw = 0; /* device status word */ -static int32 ptr_wait = 1000; /* character read wait */ -static uint8 ptr_char = 0; /* last character read */ -static int32 ptp_wait = 1000; /* character punch wait */ +static int16 ptr_dsw = 0; /* device status word */ +static int32 ptr_wait = 1000; /* character read wait */ +static uint8 ptr_char = 0; /* last character read */ +static int32 ptp_wait = 1000; /* character punch wait */ UNIT ptr_unit[1] = { - { UDATA (&ptr_svc, UNIT_ATTABLE, 0) }, + { UDATA (&ptr_svc, UNIT_ATTABLE, 0) }, }; REG ptr_reg[] = { - { HRDATA (DSW, ptr_dsw, 16) }, /* device status word */ - { DRDATA (WTIME, ptr_wait, 24), PV_LEFT }, /* character read wait */ - { DRDATA (LASTCHAR, ptr_char, 8), PV_LEFT }, /* last character read */ - { NULL } }; + { HRDATA (DSW, ptr_dsw, 16) }, /* device status word */ + { DRDATA (WTIME, ptr_wait, 24), PV_LEFT }, /* character read wait */ + { DRDATA (LASTCHAR, ptr_char, 8), PV_LEFT }, /* last character read */ + { NULL } }; DEVICE ptr_dev = { - "PTR", ptr_unit, ptr_reg, NULL, - 1, 16, 16, 1, 16, 16, - NULL, NULL, ptr_reset, - ptr_boot, ptr_attach, ptr_detach}; + "PTR", ptr_unit, ptr_reg, NULL, + 1, 16, 16, 1, 16, 16, + NULL, NULL, ptr_reset, + ptr_boot, ptr_attach, ptr_detach}; UNIT ptp_unit[1] = { - { UDATA (&ptp_svc, UNIT_ATTABLE, 0) }, + { UDATA (&ptp_svc, UNIT_ATTABLE, 0) }, }; REG ptp_reg[] = { - { HRDATA (DSW, ptr_dsw, 16) }, /* device status word (this is the same as the reader's!) */ - { DRDATA (WTIME, ptp_wait, 24), PV_LEFT }, /* character punch wait */ - { NULL } }; + { HRDATA (DSW, ptr_dsw, 16) }, /* device status word (this is the same as the reader's!) */ + { DRDATA (WTIME, ptp_wait, 24), PV_LEFT }, /* character punch wait */ + { NULL } }; DEVICE ptp_dev = { - "PTP", ptp_unit, ptp_reg, NULL, - 1, 16, 16, 1, 16, 16, - NULL, NULL, ptp_reset, - NULL, ptp_attach, ptp_detach}; + "PTP", ptp_unit, ptp_reg, NULL, + 1, 16, 16, 1, 16, 16, + NULL, NULL, ptp_reset, + NULL, ptp_attach, ptp_detach}; /* xio_1134_papertape - XIO command interpreter for the 1134 paper tape reader and 1055 paper tape punch */ void xio_1134_papertape (int32 iocc_addr, int32 iocc_func, int32 iocc_mod) { - char msg[80]; + char msg[80]; - switch (iocc_func) { - case XIO_READ: /* read: return last character read */ - M[iocc_addr & mem_mask] = (uint16) (ptr_char << 8); - break; + switch (iocc_func) { + case XIO_READ: /* read: return last character read */ + M[iocc_addr & mem_mask] = (uint16) (ptr_char << 8); + break; - case XIO_WRITE: /* write: initiate punch operation */ - if ((ptr_dsw & PTR1134_DSW_PUNCH_NOT_READY) == 0 && IS_ONLINE(ptp_unit)) { - putc((M[iocc_addr & mem_mask] >> 8) & 0xFF, ptp_unit->fileref); - ptp_unit->pos++; - } - sim_activate(ptp_unit, ptp_wait); /* schedule interrupt */ - SETBIT(ptr_dsw, PTR1134_DSW_PUNCH_NOT_READY | PTR1134_DSW_PUNCH_BUSY); - break; + case XIO_WRITE: /* write: initiate punch operation */ + if ((ptr_dsw & PTR1134_DSW_PUNCH_NOT_READY) == 0 && IS_ONLINE(ptp_unit)) { + putc((M[iocc_addr & mem_mask] >> 8) & 0xFF, ptp_unit->fileref); + ptp_unit->pos++; + } + sim_activate(ptp_unit, ptp_wait); /* schedule interrupt */ + SETBIT(ptr_dsw, PTR1134_DSW_PUNCH_NOT_READY | PTR1134_DSW_PUNCH_BUSY); + break; - case XIO_SENSE_DEV: /* sense device status */ - ACC = ptr_dsw; - if (iocc_mod & 0x01) { /* reset interrupts */ - CLRBIT(ptr_dsw, PTR1134_DSW_READER_RESPONSE | PTR1134_DSW_PUNCH_RESPONSE); - CLRBIT(ILSW[4], ILSW_4_1134_TAPE); - } - break; + case XIO_SENSE_DEV: /* sense device status */ + ACC = ptr_dsw; + if (iocc_mod & 0x01) { /* reset interrupts */ + CLRBIT(ptr_dsw, PTR1134_DSW_READER_RESPONSE | PTR1134_DSW_PUNCH_RESPONSE); + CLRBIT(ILSW[4], ILSW_4_1134_TAPE); + } + break; - case XIO_CONTROL: /* control: initiate character read */ - sim_activate(ptr_unit, ptr_wait); /* schedule interrupt */ - SETBIT(ptr_dsw, PTR1134_DSW_READER_BUSY | PTR1134_DSW_READER_NOT_READY); - break; + case XIO_CONTROL: /* control: initiate character read */ + sim_activate(ptr_unit, ptr_wait); /* schedule interrupt */ + SETBIT(ptr_dsw, PTR1134_DSW_READER_BUSY | PTR1134_DSW_READER_NOT_READY); + break; - default: - sprintf(msg, "Invalid 1134 reader/1055 punch XIO function %x", iocc_func); - xio_error(msg); - } + default: + sprintf(msg, "Invalid 1134 reader/1055 punch XIO function %x", iocc_func); + xio_error(msg); + } } /* ptr_svc - emulated timeout - 1134 read operation complete */ static t_stat ptr_svc (UNIT *uptr) { - CLRBIT(ptr_dsw, PTR1134_DSW_READER_BUSY); /* clear reader busy flag */ - SETBIT(ptr_dsw, PTR1134_DSW_READER_NOT_READY); /* assume at end of file */ + CLRBIT(ptr_dsw, PTR1134_DSW_READER_BUSY); /* clear reader busy flag */ + SETBIT(ptr_dsw, PTR1134_DSW_READER_NOT_READY); /* assume at end of file */ - if (IS_ONLINE(uptr)) { /* fetch character from file */ - ptr_char = getc(uptr->fileref); - uptr->pos++; + if (IS_ONLINE(uptr)) { /* fetch character from file */ + ptr_char = getc(uptr->fileref); + uptr->pos++; - if (! feof(uptr->fileref)) /* there's more left */ - CLRBIT(ptr_dsw, PTR1134_DSW_READER_NOT_READY); - } + if (! feof(uptr->fileref)) /* there's more left */ + CLRBIT(ptr_dsw, PTR1134_DSW_READER_NOT_READY); + } - SETBIT(ptr_dsw, PTR1134_DSW_READER_RESPONSE); /* indicate read complete */ + SETBIT(ptr_dsw, PTR1134_DSW_READER_RESPONSE); /* indicate read complete */ - SETBIT(ILSW[4], ILSW_4_1134_TAPE); /* initiate interrupt */ - calc_ints(); + SETBIT(ILSW[4], ILSW_4_1134_TAPE); /* initiate interrupt */ + calc_ints(); - return SCPE_OK; + return SCPE_OK; } /* ptp_svc - emulated timeout -- 1055 punch operation complete */ static t_stat ptp_svc (UNIT *uptr) { - CLRBIT(ptr_dsw, PTR1134_DSW_PUNCH_BUSY); /* clear punch busy flag */ + CLRBIT(ptr_dsw, PTR1134_DSW_PUNCH_BUSY); /* clear punch busy flag */ - if (IS_ONLINE(uptr)) /* update punch ready status */ - CLRBIT(ptr_dsw, PTR1134_DSW_PUNCH_NOT_READY); - else - SETBIT(ptr_dsw, PTR1134_DSW_PUNCH_NOT_READY); - - SETBIT(ptr_dsw, PTR1134_DSW_PUNCH_RESPONSE); /* indicate punch complete */ + if (IS_ONLINE(uptr)) /* update punch ready status */ + CLRBIT(ptr_dsw, PTR1134_DSW_PUNCH_NOT_READY); + else + SETBIT(ptr_dsw, PTR1134_DSW_PUNCH_NOT_READY); + + SETBIT(ptr_dsw, PTR1134_DSW_PUNCH_RESPONSE); /* indicate punch complete */ - SETBIT(ILSW[4], ILSW_4_1134_TAPE); /* initiate interrupt */ - calc_ints(); + SETBIT(ILSW[4], ILSW_4_1134_TAPE); /* initiate interrupt */ + calc_ints(); - return SCPE_OK; + return SCPE_OK; } /* ptr_reset - reset emulated paper tape reader */ static t_stat ptr_reset (DEVICE *dptr) { - sim_cancel(ptr_unit); + sim_cancel(ptr_unit); - CLRBIT(ptr_dsw, PTR1134_DSW_READER_BUSY | PTR1134_DSW_READER_RESPONSE); - SETBIT(ptr_dsw, PTR1134_DSW_READER_NOT_READY); + CLRBIT(ptr_dsw, PTR1134_DSW_READER_BUSY | PTR1134_DSW_READER_RESPONSE); + SETBIT(ptr_dsw, PTR1134_DSW_READER_NOT_READY); - if (IS_ONLINE(ptr_unit) && ! feof(ptr_unit->fileref)) - CLRBIT(ptr_dsw, PTR1134_DSW_READER_NOT_READY); + if (IS_ONLINE(ptr_unit) && ! feof(ptr_unit->fileref)) + CLRBIT(ptr_dsw, PTR1134_DSW_READER_NOT_READY); - if ((ptr_dsw & PTR1134_DSW_PUNCH_RESPONSE) == 0) { /* punch isn't interrupting either */ - CLRBIT(ILSW[4], ILSW_4_1134_TAPE); - calc_ints(); - } + if ((ptr_dsw & PTR1134_DSW_PUNCH_RESPONSE) == 0) { /* punch isn't interrupting either */ + CLRBIT(ILSW[4], ILSW_4_1134_TAPE); + calc_ints(); + } - return SCPE_OK; + return SCPE_OK; } /* ptp_reset - reset emulated paper tape punch */ static t_stat ptp_reset (DEVICE *dptr) { - sim_cancel(ptp_unit); + sim_cancel(ptp_unit); - CLRBIT(ptr_dsw, PTR1134_DSW_PUNCH_BUSY | PTR1134_DSW_PUNCH_RESPONSE); - SETBIT(ptr_dsw, PTR1134_DSW_PUNCH_NOT_READY); + CLRBIT(ptr_dsw, PTR1134_DSW_PUNCH_BUSY | PTR1134_DSW_PUNCH_RESPONSE); + SETBIT(ptr_dsw, PTR1134_DSW_PUNCH_NOT_READY); - if (IS_ONLINE(ptp_unit)) - CLRBIT(ptr_dsw, PTR1134_DSW_PUNCH_NOT_READY); + if (IS_ONLINE(ptp_unit)) + CLRBIT(ptr_dsw, PTR1134_DSW_PUNCH_NOT_READY); - if ((ptr_dsw & PTR1134_DSW_READER_RESPONSE) == 0) { /* reader isn't interrupting either */ - CLRBIT(ILSW[4], ILSW_4_1134_TAPE); - calc_ints(); - } + if ((ptr_dsw & PTR1134_DSW_READER_RESPONSE) == 0) { /* reader isn't interrupting either */ + CLRBIT(ILSW[4], ILSW_4_1134_TAPE); + calc_ints(); + } - return SCPE_OK; + return SCPE_OK; } /* ptr_attach - attach file to simulated paper tape reader */ static t_stat ptr_attach (UNIT *uptr, CONST char *cptr) { - t_stat rval; + t_stat rval; - SETBIT(ptr_dsw, PTR1134_DSW_READER_NOT_READY); /* assume failure */ + SETBIT(ptr_dsw, PTR1134_DSW_READER_NOT_READY); /* assume failure */ - if ((rval = attach_unit(uptr, cptr)) != SCPE_OK) /* use standard attach */ - return rval; + if ((rval = attach_unit(uptr, cptr)) != SCPE_OK) /* use standard attach */ + return rval; - if ((ptr_dsw & PTR1134_DSW_READER_BUSY) == 0 && ! feof(uptr->fileref)) - CLRBIT(ptr_dsw, PTR1134_DSW_READER_NOT_READY); /* we're in business */ + if ((ptr_dsw & PTR1134_DSW_READER_BUSY) == 0 && ! feof(uptr->fileref)) + CLRBIT(ptr_dsw, PTR1134_DSW_READER_NOT_READY); /* we're in business */ - return SCPE_OK; + return SCPE_OK; } /* ptr_attach - detach file from simulated paper tape reader */ static t_stat ptr_detach (UNIT *uptr) { - SETBIT(ptr_dsw, PTR1134_DSW_READER_NOT_READY); + SETBIT(ptr_dsw, PTR1134_DSW_READER_NOT_READY); - return detach_unit(uptr); + return detach_unit(uptr); } /* ptr_attach - perform paper tape initial program load */ static t_stat ptr_boot (int32 unitno, DEVICE *dptr) { - int ch, nch, val, addr; - t_bool leader = TRUE, start = FALSE; - t_stat rval; + int ch, nch, val, addr; + t_bool leader = TRUE, start = FALSE; + t_stat rval; - addr = 0; - nch = 0; - val = 0; + addr = 0; + nch = 0; + val = 0; - for (;;) { - if ((ch = getc(ptr_unit->fileref)) == EOF) { - printf("EOF on paper tape without finding Channel 5 end-of-load mark\n"); - break; - } + for (;;) { + if ((ch = getc(ptr_unit->fileref)) == EOF) { + printf("EOF on paper tape without finding Channel 5 end-of-load mark\n"); + break; + } - if (leader) { - if ((ch & 0x7F) == 0x7F) /* ignore leading rubouts or "delete" characters */ - continue; + if (leader) { + if ((ch & 0x7F) == 0x7F) /* ignore leading rubouts or "delete" characters */ + continue; - leader = FALSE; /* after first nonrubout, any punch in channel 5 terminates load */ - } + leader = FALSE; /* after first nonrubout, any punch in channel 5 terminates load */ + } - /* this is untested -- not sure of actual byte ordering */ + /* this is untested -- not sure of actual byte ordering */ - val = (val << 4) | (ch & 0x0F); /* get next nybble */ + val = (val << 4) | (ch & 0x0F); /* get next nybble */ - if (++nch == 4) { /* if we now have four nybbles, store the word */ - M[addr & mem_mask] = (uint16) val; + if (++nch == 4) { /* if we now have four nybbles, store the word */ + M[addr & mem_mask] = (uint16) val; - addr++; /* prepare for next word */ - nch = 0; - val = 0; - } + addr++; /* prepare for next word */ + nch = 0; + val = 0; + } - if (ch & 0x10) { /* channel 5 punch terminates load */ - start = TRUE; - break; - } - } + if (ch & 0x10) { /* channel 5 punch terminates load */ + start = TRUE; + break; + } + } - if (! start) /* if we didn't get a valid load, report EOF error */ - return SCPE_EOF; + if (! start) /* if we didn't get a valid load, report EOF error */ + return SCPE_EOF; - if ((rval = reset_all(0)) != SCPE_OK) /* force a reset */ - return rval; + if ((rval = reset_all(0)) != SCPE_OK) /* force a reset */ + return rval; - IAR = 0; /* start running at address 0 */ - return SCPE_OK; + IAR = 0; /* start running at address 0 */ + return SCPE_OK; } /* ptp_attach - attach file to simulated paper tape punch */ static t_stat ptp_attach (UNIT *uptr, CONST char *cptr) { - t_stat rval; + t_stat rval; - SETBIT(ptr_dsw, PTR1134_DSW_PUNCH_NOT_READY); /* assume failure */ + SETBIT(ptr_dsw, PTR1134_DSW_PUNCH_NOT_READY); /* assume failure */ - if ((rval = attach_unit(uptr, cptr)) != SCPE_OK) /* use standard attach */ - return rval; + if ((rval = attach_unit(uptr, cptr)) != SCPE_OK) /* use standard attach */ + return rval; - fseek(uptr->fileref, 0, SEEK_END); /* if we opened an existing file, append to it */ - uptr->pos = ftell(uptr->fileref); + fseek(uptr->fileref, 0, SEEK_END); /* if we opened an existing file, append to it */ + uptr->pos = ftell(uptr->fileref); - if ((ptr_dsw & PTR1134_DSW_PUNCH_BUSY) == 0) - CLRBIT(ptr_dsw, PTR1134_DSW_PUNCH_NOT_READY); /* we're in business */ + if ((ptr_dsw & PTR1134_DSW_PUNCH_BUSY) == 0) + CLRBIT(ptr_dsw, PTR1134_DSW_PUNCH_NOT_READY); /* we're in business */ - return SCPE_OK; + return SCPE_OK; } /* ptp_detach - detach file from simulated paper tape punch */ static t_stat ptp_detach (UNIT *uptr) { - SETBIT(ptr_dsw, PTR1134_DSW_PUNCH_NOT_READY); + SETBIT(ptr_dsw, PTR1134_DSW_PUNCH_NOT_READY); - return detach_unit(uptr); + return detach_unit(uptr); } diff --git a/Ibm1130/ibm1130_sca.c b/Ibm1130/ibm1130_sca.c index 04309390..149a33af 100644 --- a/Ibm1130/ibm1130_sca.c +++ b/Ibm1130/ibm1130_sca.c @@ -19,35 +19,35 @@ /****************************************************************************************************************** * NOTES: - * This module sends raw bisync data over a standard TCP port. It's meant to be - * used with the emulated 2703 device in Hercules. + * This module sends raw bisync data over a standard TCP port. It's meant to be + * used with the emulated 2703 device in Hercules. * * Attach command: * * to establish an outgoing connection: * - * attach sca host connect to named host on default port (initial default port is 2703); or - * attach sca host:### connect to named host on port ###. ### is also set as new default port number. - * >> The simulator waits until the connection is established + * attach sca host connect to named host on default port (initial default port is 2703); or + * attach sca host:### connect to named host on port ###. ### is also set as new default port number. + * >> The simulator waits until the connection is established * * or to set up for incoming connections: * - * attach sca -l dummy listen for a connection on default port (initially 2703); Nonnumeric "dummy" argument is ignored; or - * attach sca -l ### listen for a connection on the port ###. ### is also set as the new default port - * >> The simulator proceeds. When another simulator connects, the READY bit is set in the DSW. + * attach sca -l dummy listen for a connection on default port (initially 2703); Nonnumeric "dummy" argument is ignored; or + * attach sca -l ### listen for a connection on the port ###. ### is also set as the new default port + * >> The simulator proceeds. When another simulator connects, the READY bit is set in the DSW. * - * If the SCA's autoanswer-enable bit has been set, an incoming connection causes an interrupt (untested) + * If the SCA's autoanswer-enable bit has been set, an incoming connection causes an interrupt (untested) * Configuration commands: * - * set sca bsc set bisync mode (default) - * set sca str set synchronous transmit/recieve mode (NOT IMPLEMENTED) + * set sca bsc set bisync mode (default) + * set sca str set synchronous transmit/recieve mode (NOT IMPLEMENTED) * - * set sca ### set simulated baud rate to ###, where ### is 600, 1200, 2000, 2400 or 4800 (4800 is default) + * set sca ### set simulated baud rate to ###, where ### is 600, 1200, 2000, 2400 or 4800 (4800 is default) * - * set sca half set simulated half-duplex mode - * set sca full set simulated full-duplex mode (note: 1130's SCA can't actually send and receive at the same time!) + * set sca half set simulated half-duplex mode + * set sca full set simulated full-duplex mode (note: 1130's SCA can't actually send and receive at the same time!) * - * deposit sca keepalive ### send SYN packets every ### msec when suppressing SYN's, default is 0 (no keepalives) + * deposit sca keepalive ### send SYN packets every ### msec when suppressing SYN's, default is 0 (no keepalives) * * STR/BSC mode is selected by a toggle switch on the 1130, with the SET SCA BSC or SET SET STR command here. * Testable with in_bsc_mode() or in_str_mode() in this module. If necessary, the SET command can be configured @@ -83,160 +83,160 @@ ******************************************************************************************************************/ #include "ibm1130_defs.h" -#include "sim_sock.h" /* include path must include main simh directory */ +#include "sim_sock.h" /* include path must include main simh directory */ #include -#define DEBUG_SCA_FLUSH 0x0001 /* debugging options */ -#define DEBUG_SCA_TRANSMIT 0x0002 -#define DEBUG_SCA_CHECK_INDATA 0x0004 -#define DEBUG_SCA_RECEIVE_SYNC 0x0008 -#define DEBUG_SCA_RECEIVE_DATA 0x0010 -#define DEBUG_SCA_XIO_READ 0x0020 -#define DEBUG_SCA_XIO_WRITE 0x0040 -#define DEBUG_SCA_XIO_CONTROL 0x0080 -#define DEBUG_SCA_XIO_INITW 0x0100 -#define DEBUG_SCA_XIO_INITR 0x0200 -#define DEBUG_SCA_XIO_SENSE_DEV 0x0400 -#define DEBUG_SCA_TIMERS 0x0800 -#define DEBUG_SCA_ALL 0xFFFF +#define DEBUG_SCA_FLUSH 0x0001 /* debugging options */ +#define DEBUG_SCA_TRANSMIT 0x0002 +#define DEBUG_SCA_CHECK_INDATA 0x0004 +#define DEBUG_SCA_RECEIVE_SYNC 0x0008 +#define DEBUG_SCA_RECEIVE_DATA 0x0010 +#define DEBUG_SCA_XIO_READ 0x0020 +#define DEBUG_SCA_XIO_WRITE 0x0040 +#define DEBUG_SCA_XIO_CONTROL 0x0080 +#define DEBUG_SCA_XIO_INITW 0x0100 +#define DEBUG_SCA_XIO_INITR 0x0200 +#define DEBUG_SCA_XIO_SENSE_DEV 0x0400 +#define DEBUG_SCA_TIMERS 0x0800 +#define DEBUG_SCA_ALL 0xFFFF -/* #define DEBUG_SCA (DEBUG_SCA_TIMERS|DEBUG_SCA_FLUSH|DEBUG_SCA_TRANSMIT|DEBUG_SCA_CHECK_INDATA|DEBUG_SCA_RECEIVE_SYNC|DEBUG_SCA_RECEIVE_DATA|DEBUG_SCA_XIO_INITR|DEBUG_SCA_XIO_INITW) */ -#define DEBUG_SCA (DEBUG_SCA_TIMERS|DEBUG_SCA_FLUSH|DEBUG_SCA_CHECK_INDATA|DEBUG_SCA_XIO_INITR|DEBUG_SCA_XIO_INITW) +/* #define DEBUG_SCA (DEBUG_SCA_TIMERS|DEBUG_SCA_FLUSH|DEBUG_SCA_TRANSMIT|DEBUG_SCA_CHECK_INDATA|DEBUG_SCA_RECEIVE_SYNC|DEBUG_SCA_RECEIVE_DATA|DEBUG_SCA_XIO_INITR|DEBUG_SCA_XIO_INITW) */ +#define DEBUG_SCA (DEBUG_SCA_TIMERS|DEBUG_SCA_FLUSH|DEBUG_SCA_CHECK_INDATA|DEBUG_SCA_XIO_INITR|DEBUG_SCA_XIO_INITW) -#define SCA_DEFAULT_PORT "2703" /* default socket, This is the number of the IBM 360's BSC device */ +#define SCA_DEFAULT_PORT "2703" /* default socket, This is the number of the IBM 360's BSC device */ -#define MAX_SYNS 100 /* number of consecutive syn's after which we stop buffering them */ +#define MAX_SYNS 100 /* number of consecutive syn's after which we stop buffering them */ /*************************************************************************************** * SCA ***************************************************************************************/ -#define SCA_DSW_READ_RESPONSE 0x8000 /* receive buffer full interrupt */ -#define SCA_DSW_WRITE_RESPONSE 0x4000 /* transmitter buffer empty interrupt */ -#define SCA_DSW_CHECK 0x2000 /* data overrun or character gap error */ -#define SCA_DSW_TIMEOUT 0x1000 /* timer interrupt, mode specific */ -#define SCA_DSW_AUTOANSWER_REQUEST 0x0800 /* dataset is ringing and autoanswer is enabled */ -#define SCA_DSW_BUSY 0x0400 /* adapter is in either receive or transmit mode */ -#define SCA_DSW_AUTOANSWER_ENABLED 0x0200 /* 1 when autoanswer mode has been enabled */ -#define SCA_DSW_READY 0x0100 /* Carrier detect? Connected and ready to rcv, xmit or sync */ -#define SCA_DSW_RECEIVE_RUN 0x0080 /* used in two-wire half-duplex STR mode only. "Slave" mode (?) */ +#define SCA_DSW_READ_RESPONSE 0x8000 /* receive buffer full interrupt */ +#define SCA_DSW_WRITE_RESPONSE 0x4000 /* transmitter buffer empty interrupt */ +#define SCA_DSW_CHECK 0x2000 /* data overrun or character gap error */ +#define SCA_DSW_TIMEOUT 0x1000 /* timer interrupt, mode specific */ +#define SCA_DSW_AUTOANSWER_REQUEST 0x0800 /* dataset is ringing and autoanswer is enabled */ +#define SCA_DSW_BUSY 0x0400 /* adapter is in either receive or transmit mode */ +#define SCA_DSW_AUTOANSWER_ENABLED 0x0200 /* 1 when autoanswer mode has been enabled */ +#define SCA_DSW_READY 0x0100 /* Carrier detect? Connected and ready to rcv, xmit or sync */ +#define SCA_DSW_RECEIVE_RUN 0x0080 /* used in two-wire half-duplex STR mode only. "Slave" mode (?) */ #define IS_ONLINE(u) (((u)->flags & (UNIT_ATT|UNIT_DIS)) == UNIT_ATT) -typedef enum { /* ms m = mode (0 = idle, 1 = send, 2 = receive), s = substate */ - SCA_STATE_IDLE = 0x00, /* nothing happening */ - SCA_STATE_TURN_SEND = 0x10, /* line turning around to the send state */ - SCA_STATE_SEND_SYNC = 0x11, /* sca is sending syncs */ - SCA_STATE_SEND1 = 0x12, /* have issued write response, waiting for write command */ - SCA_STATE_SEND2 = 0x13, /* write command issued, "sending" byte */ - SCA_STATE_TURN_RECEIVE = 0x20, /* line turnaround to the receive state */ - SCA_STATE_RECEIVE_SYNC = 0x21, /* sca is receiving syncs */ - SCA_STATE_RECEIVE_SYNC2 = 0x22, /* bsc mode, waiting for 2nd SYN */ - SCA_STATE_RECEIVE_SYNC3 = 0x23, /* bsc mode, waiting for 1st non-SYN */ - SCA_STATE_RECEIVE1 = 0x24, /* "receiving" a byte */ - SCA_STATE_RECEIVE2 = 0x25, /* read response issued, "receiving" next byte */ +typedef enum { /* ms m = mode (0 = idle, 1 = send, 2 = receive), s = substate */ + SCA_STATE_IDLE = 0x00, /* nothing happening */ + SCA_STATE_TURN_SEND = 0x10, /* line turning around to the send state */ + SCA_STATE_SEND_SYNC = 0x11, /* sca is sending syncs */ + SCA_STATE_SEND1 = 0x12, /* have issued write response, waiting for write command */ + SCA_STATE_SEND2 = 0x13, /* write command issued, "sending" byte */ + SCA_STATE_TURN_RECEIVE = 0x20, /* line turnaround to the receive state */ + SCA_STATE_RECEIVE_SYNC = 0x21, /* sca is receiving syncs */ + SCA_STATE_RECEIVE_SYNC2 = 0x22, /* bsc mode, waiting for 2nd SYN */ + SCA_STATE_RECEIVE_SYNC3 = 0x23, /* bsc mode, waiting for 1st non-SYN */ + SCA_STATE_RECEIVE1 = 0x24, /* "receiving" a byte */ + SCA_STATE_RECEIVE2 = 0x25, /* read response issued, "receiving" next byte */ } SCA_STATE; #define in_send_state() (sca_state & 0x10) #define in_receive_state() (sca_state & 0x20) -static t_stat sca_svc (UNIT *uptr); /* prototypes */ -static t_stat sca_reset (DEVICE *dptr); -static t_stat sca_attach (UNIT *uptr, CONST char *cptr); -static t_stat sca_detach (UNIT *uptr); -static void sca_start_timer (int n, int msec_now); -static void sca_halt_timer (int n); -static void sca_toggle_timer (int n, int msec_now); - /* timer states, chosen so any_timer_running can be calculated by oring states of all 3 timers */ +static t_stat sca_svc (UNIT *uptr); /* prototypes */ +static t_stat sca_reset (DEVICE *dptr); +static t_stat sca_attach (UNIT *uptr, CONST char *cptr); +static t_stat sca_detach (UNIT *uptr); +static void sca_start_timer (int n, int msec_now); +static void sca_halt_timer (int n); +static void sca_toggle_timer (int n, int msec_now); + /* timer states, chosen so any_timer_running can be calculated by oring states of all 3 timers */ typedef enum {SCA_TIMER_INACTIVE = 0, SCA_TIMER_RUNNING = 1, SCA_TIMER_INHIBITED = 2, SCA_TIMER_TIMEDOUT = 4} SCA_TIMER_STATE; -#define TIMER_3S 0 /* 3 second timer index into sca_timer_xxx arrays */ -#define TIMER_125S 1 /* 1.25 second timer */ -#define TIMER_035S 2 /* 0.35 second timer */ +#define TIMER_3S 0 /* 3 second timer index into sca_timer_xxx arrays */ +#define TIMER_125S 1 /* 1.25 second timer */ +#define TIMER_035S 2 /* 0.35 second timer */ -static uint16 sca_dsw = 0; /* device status word */ -static uint32 sca_cwait = 275; /* inter-character wait */ -static uint32 sca_iwait = 2750; /* idle wait */ +static uint16 sca_dsw = 0; /* device status word */ +static uint32 sca_cwait = 275; /* inter-character wait */ +static uint32 sca_iwait = 2750; /* idle wait */ static uint32 sca_state = SCA_STATE_IDLE; -static uint8 sichar = 0; /* sync/idle character */ -static uint8 rcvd_char = 0; /* most recently received character */ +static uint8 sichar = 0; /* sync/idle character */ +static uint8 rcvd_char = 0; /* most recently received character */ static uint8 sca_frame = 8; static char sca_port[CBUFSIZE]; /* listening port */ -static int32 sca_keepalive = 0; /* keepalive SYN packet period in msec, default = 0 (disabled) */ -static SCA_TIMER_STATE sca_timer_state[3]; /* current timer state */ -static int sca_timer_endtime[3]; /* clocktime when timeout is to occur if state is RUNNING */ -static int sca_timer_timeleft[3]; /* time left in msec if state is INHIBITED */ -static t_bool any_timer_running = FALSE; /* TRUE if at least one timer is running */ -static int sca_timer_msec[3] = {3000, 1250, 350}; /* timebase in msec for the three timers: 3 sec, 1.25 sec, 0.35 sec */ -static t_bool sca_timer_trigger; /* if TRUE, the "timer trigger" is set, the 0.35s timer is running and the 3 sec and 1.25 sec timers are inhibited */ -static int sca_nsyns = 0; /* number of consecutively sent SYN's */ -static int idles_since_last_write = 0; /* used to detect when software has ceased sending data */ +static int32 sca_keepalive = 0; /* keepalive SYN packet period in msec, default = 0 (disabled) */ +static SCA_TIMER_STATE sca_timer_state[3]; /* current timer state */ +static int sca_timer_endtime[3]; /* clocktime when timeout is to occur if state is RUNNING */ +static int sca_timer_timeleft[3]; /* time left in msec if state is INHIBITED */ +static t_bool any_timer_running = FALSE; /* TRUE if at least one timer is running */ +static int sca_timer_msec[3] = {3000, 1250, 350}; /* timebase in msec for the three timers: 3 sec, 1.25 sec, 0.35 sec */ +static t_bool sca_timer_trigger; /* if TRUE, the "timer trigger" is set, the 0.35s timer is running and the 3 sec and 1.25 sec timers are inhibited */ +static int sca_nsyns = 0; /* number of consecutively sent SYN's */ +static int idles_since_last_write = 0; /* used to detect when software has ceased sending data */ static SOCKET sca_lsock = INVALID_SOCKET; static SOCKET sca_sock = INVALID_SOCKET; -#define SCA_SENDBUF_SIZE 145 /* maximum number of bytes to buffer for transmission */ -#define SCA_RCVBUF_SIZE 256 /* max number of bytes to read from socket at a time */ -#define SCA_SEND_THRESHHOLD 140 /* number of bytes to buffer before initiating packet send */ -#define SCA_IDLE_THRESHHOLD 3 /* maximum number of unintentional idles to buffer before initiating send */ +#define SCA_SENDBUF_SIZE 145 /* maximum number of bytes to buffer for transmission */ +#define SCA_RCVBUF_SIZE 256 /* max number of bytes to read from socket at a time */ +#define SCA_SEND_THRESHHOLD 140 /* number of bytes to buffer before initiating packet send */ +#define SCA_IDLE_THRESHHOLD 3 /* maximum number of unintentional idles to buffer before initiating send */ -static uint8 sca_sendbuf[SCA_SENDBUF_SIZE]; /* bytes pending to write to socket */ -static uint8 sca_rcvbuf[SCA_RCVBUF_SIZE]; /* bytes received from socket, to be given to SCA */ -static int sca_n2send = 0; /* number of bytes queued for transmission */ -static int sca_nrcvd = 0; /* number of received bytes in buffer */ -static int sca_rcvptr = 0; /* index of next byte to take from rcvbuf */ +static uint8 sca_sendbuf[SCA_SENDBUF_SIZE]; /* bytes pending to write to socket */ +static uint8 sca_rcvbuf[SCA_RCVBUF_SIZE]; /* bytes received from socket, to be given to SCA */ +static int sca_n2send = 0; /* number of bytes queued for transmission */ +static int sca_nrcvd = 0; /* number of received bytes in buffer */ +static int sca_rcvptr = 0; /* index of next byte to take from rcvbuf */ -#define UNIT_V_BISYNC (UNIT_V_UF + 0) /* BSC (bisync) mode */ -#define UNIT_V_BAUD (UNIT_V_UF + 1) /* 3 bits for baud rate encoding */ +#define UNIT_V_BISYNC (UNIT_V_UF + 0) /* BSC (bisync) mode */ +#define UNIT_V_BAUD (UNIT_V_UF + 1) /* 3 bits for baud rate encoding */ #define UNIT_V_FULLDUPLEX (UNIT_V_UF + 4) #define UNIT_V_AUTOANSWER (UNIT_V_UF + 5) -#define UNIT_V_LISTEN (UNIT_V_UF + 6) /* listen socket mode */ +#define UNIT_V_LISTEN (UNIT_V_UF + 6) /* listen socket mode */ -#define UNIT_BISYNC (1u << UNIT_V_BISYNC) +#define UNIT_BISYNC (1u << UNIT_V_BISYNC) #define UNIT_BAUDMASK (7u << UNIT_V_BAUD) -#define UNIT_BAUD600 (0u << UNIT_V_BAUD) -#define UNIT_BAUD1200 (1u << UNIT_V_BAUD) -#define UNIT_BAUD2000 (2u << UNIT_V_BAUD) -#define UNIT_BAUD2400 (3u << UNIT_V_BAUD) -#define UNIT_BAUD4800 (4u << UNIT_V_BAUD) +#define UNIT_BAUD600 (0u << UNIT_V_BAUD) +#define UNIT_BAUD1200 (1u << UNIT_V_BAUD) +#define UNIT_BAUD2000 (2u << UNIT_V_BAUD) +#define UNIT_BAUD2400 (3u << UNIT_V_BAUD) +#define UNIT_BAUD4800 (4u << UNIT_V_BAUD) #define UNIT_FULLDUPLEX (1u << UNIT_V_FULLDUPLEX) -#define UNIT_AUTOANSWER (1u << UNIT_V_AUTOANSWER) -#define UNIT_LISTEN (1u << UNIT_V_LISTEN) +#define UNIT_AUTOANSWER (1u << UNIT_V_AUTOANSWER) +#define UNIT_LISTEN (1u << UNIT_V_LISTEN) t_stat sca_set_baud (UNIT *uptr, int32 value, CONST char *cptr, void *desc); -UNIT sca_unit = { /* default settings */ - UDATA (sca_svc, UNIT_ATTABLE|UNIT_BISYNC|UNIT_BAUD4800|UNIT_FULLDUPLEX, 0), +UNIT sca_unit = { /* default settings */ + UDATA (sca_svc, UNIT_ATTABLE|UNIT_BISYNC|UNIT_BAUD4800|UNIT_FULLDUPLEX, 0), }; -REG sca_reg[] = { /* DEVICE STATE/SETTABLE PARAMETERS: */ - { HRDATA (SCADSW, sca_dsw, 16) }, /* device status word */ - { DRDATA (SICHAR, sichar, 8), PV_LEFT }, /* sync/idle character */ - { DRDATA (RCVDCHAR, rcvd_char, 8), PV_LEFT }, /* most recently received character */ - { DRDATA (FRAME, sca_frame, 8), PV_LEFT }, /* frame bits (6, 7 or 8) */ - { DRDATA (SCASTATE, sca_state, 32), PV_LEFT }, /* current state */ - { DRDATA (CTIME, sca_cwait, 32), PV_LEFT }, /* inter-character wait */ - { DRDATA (ITIME, sca_iwait, 32), PV_LEFT }, /* idle wait (polling interval for socket connects) */ - { BRDATA (SCASOCKET, sca_port, 8, 8, sizeof(sca_port)) }, /* listening port number */ - { DRDATA (KEEPALIVE, sca_keepalive, 32), PV_LEFT }, /* keepalive packet period in msec */ - { NULL } }; +REG sca_reg[] = { /* DEVICE STATE/SETTABLE PARAMETERS: */ + { HRDATA (SCADSW, sca_dsw, 16) }, /* device status word */ + { DRDATA (SICHAR, sichar, 8), PV_LEFT }, /* sync/idle character */ + { DRDATA (RCVDCHAR, rcvd_char, 8), PV_LEFT }, /* most recently received character */ + { DRDATA (FRAME, sca_frame, 8), PV_LEFT }, /* frame bits (6, 7 or 8) */ + { DRDATA (SCASTATE, sca_state, 32), PV_LEFT }, /* current state */ + { DRDATA (CTIME, sca_cwait, 32), PV_LEFT }, /* inter-character wait */ + { DRDATA (ITIME, sca_iwait, 32), PV_LEFT }, /* idle wait (polling interval for socket connects) */ + { BRDATA (SCASOCKET, sca_port, 8, 8, sizeof(sca_port)) }, /* listening port number */ + { DRDATA (KEEPALIVE, sca_keepalive, 32), PV_LEFT }, /* keepalive packet period in msec */ + { NULL } }; -MTAB sca_mod[] = { /* DEVICE OPTIONS */ - { UNIT_BISYNC, 0, "STR", "STR", NULL }, /* mode option */ - { UNIT_BISYNC, UNIT_BISYNC, "BSC", "BSC", NULL }, - { UNIT_BAUDMASK, UNIT_BAUD600, "600", "600", sca_set_baud }, /* data rate option */ - { UNIT_BAUDMASK, UNIT_BAUD1200, "1200", "1200", sca_set_baud }, - { UNIT_BAUDMASK, UNIT_BAUD2000, "2000", "2000", sca_set_baud }, - { UNIT_BAUDMASK, UNIT_BAUD2400, "2400", "2400", sca_set_baud }, - { UNIT_BAUDMASK, UNIT_BAUD4800, "4800", "4800", sca_set_baud }, - { UNIT_FULLDUPLEX, 0, "HALF", "HALF", NULL }, /* duplex option (does this matter?) */ - { UNIT_FULLDUPLEX, UNIT_FULLDUPLEX, "FULL", "FULL", NULL }, - { 0 } }; +MTAB sca_mod[] = { /* DEVICE OPTIONS */ + { UNIT_BISYNC, 0, "STR", "STR", NULL }, /* mode option */ + { UNIT_BISYNC, UNIT_BISYNC, "BSC", "BSC", NULL }, + { UNIT_BAUDMASK, UNIT_BAUD600, "600", "600", sca_set_baud }, /* data rate option */ + { UNIT_BAUDMASK, UNIT_BAUD1200, "1200", "1200", sca_set_baud }, + { UNIT_BAUDMASK, UNIT_BAUD2000, "2000", "2000", sca_set_baud }, + { UNIT_BAUDMASK, UNIT_BAUD2400, "2400", "2400", sca_set_baud }, + { UNIT_BAUDMASK, UNIT_BAUD4800, "4800", "4800", sca_set_baud }, + { UNIT_FULLDUPLEX, 0, "HALF", "HALF", NULL }, /* duplex option (does this matter?) */ + { UNIT_FULLDUPLEX, UNIT_FULLDUPLEX, "FULL", "FULL", NULL }, + { 0 } }; DEVICE sca_dev = { - "SCA", &sca_unit, sca_reg, sca_mod, - 1, 16, 16, 1, 16, 16, - NULL, NULL, sca_reset, - NULL, sca_attach, sca_detach + "SCA", &sca_unit, sca_reg, sca_mod, + 1, 16, 16, 1, 16, 16, + NULL, NULL, sca_reset, + NULL, sca_attach, sca_detach }; /********************************************************************************************* @@ -245,31 +245,31 @@ DEVICE sca_dev = { t_stat sca_set_baud (UNIT *uptr, int32 value, CONST char *cptr, void *desc) { - uint32 newbits; + uint32 newbits; - switch (value) { - case 600: newbits = UNIT_BAUD600; break; - case 1200: newbits = UNIT_BAUD1200; break; - case 2000: newbits = UNIT_BAUD2000; break; - case 2400: newbits = UNIT_BAUD2400; break; - case 4800: newbits = UNIT_BAUD4800; break; - default: return SCPE_ARG; - } + switch (value) { + case 600: newbits = UNIT_BAUD600; break; + case 1200: newbits = UNIT_BAUD1200; break; + case 2000: newbits = UNIT_BAUD2000; break; + case 2400: newbits = UNIT_BAUD2400; break; + case 4800: newbits = UNIT_BAUD4800; break; + default: return SCPE_ARG; + } - CLRBIT(sca_unit.flags, UNIT_BAUDMASK); - SETBIT(sca_unit.flags, newbits); + CLRBIT(sca_unit.flags, UNIT_BAUDMASK); + SETBIT(sca_unit.flags, newbits); - sca_cwait = 1320000 / value; /* intercharacter wait time in instructions (roughly) */ + sca_cwait = 1320000 / value; /* intercharacter wait time in instructions (roughly) */ - return SCPE_OK; + return SCPE_OK; } /********************************************************************************************* * HANDY MACROS *********************************************************************************************/ -#define in_bsc_mode() (sca_unit.flags & UNIT_BISYNC) /* TRUE if user selected BSC mode */ -#define in_str_mode() ((sca_unit.flags & UNIT_BISYNC) == 0) /* TRUE if user selected STR mode */ +#define in_bsc_mode() (sca_unit.flags & UNIT_BISYNC) /* TRUE if user selected BSC mode */ +#define in_str_mode() ((sca_unit.flags & UNIT_BISYNC) == 0) /* TRUE if user selected STR mode */ /********************************************************************************************* * mstring - allocate a copy of a string @@ -277,16 +277,16 @@ t_stat sca_set_baud (UNIT *uptr, int32 value, CONST char *cptr, void *desc) char *mstring (const char *str) { - int len; - char *m; + int len; + char *m; - len = strlen(str)+1; - if ((m = (char *)malloc(len)) == NULL) { - printf("Out of memory!"); - return (char *)"?"; /* this will of course cause trouble if it's subsequently freed */ - } - strcpy(m, str); - return m; + len = strlen(str)+1; + if ((m = (char *)malloc(len)) == NULL) { + printf("Out of memory!"); + return (char *)"?"; /* this will of course cause trouble if it's subsequently freed */ + } + strcpy(m, str); + return m; } /********************************************************************************************* @@ -295,33 +295,33 @@ char *mstring (const char *str) static void sca_socket_error (void) { - char name[100]; + char name[100]; - /* print diagnostic? */ - printf("SCA socket error, closing connection\n"); + /* print diagnostic? */ + printf("SCA socket error, closing connection\n"); - /* tell 1130 that connection was lost */ - CLRBIT(sca_dsw, SCA_DSW_READY); + /* tell 1130 that connection was lost */ + CLRBIT(sca_dsw, SCA_DSW_READY); - if (sca_sock != INVALID_SOCKET) { - /* close socket, prepare to listen again if in listen mode. It's a "master" socket if it was an outgoing connection */ - sim_close_sock(sca_sock); - sca_sock = INVALID_SOCKET; + if (sca_sock != INVALID_SOCKET) { + /* close socket, prepare to listen again if in listen mode. It's a "master" socket if it was an outgoing connection */ + sim_close_sock(sca_sock); + sca_sock = INVALID_SOCKET; - if (sca_unit.filename != NULL) /* reset filename string in unit record */ - free(sca_unit.filename); + if (sca_unit.filename != NULL) /* reset filename string in unit record */ + free(sca_unit.filename); - if (sca_unit.flags & UNIT_LISTEN) { - sprintf(name, "(Listening on port %s)", sca_port); - sca_unit.filename = mstring(name); - printf("%s\n", name); - } - else - sca_unit.filename = mstring("(connection failed)"); - } + if (sca_unit.flags & UNIT_LISTEN) { + sprintf(name, "(Listening on port %s)", sca_port); + sca_unit.filename = mstring(name); + printf("%s\n", name); + } + else + sca_unit.filename = mstring("(connection failed)"); + } - /* clear buffers */ - sca_nrcvd = sca_rcvptr = sca_n2send = sca_nsyns = 0; + /* clear buffers */ + sca_nrcvd = sca_rcvptr = sca_n2send = sca_nsyns = 0; } /********************************************************************************************* @@ -330,28 +330,28 @@ static void sca_socket_error (void) static void sca_flush (void) { - int nbytes; + int nbytes; - if (sca_n2send > 0) { + if (sca_n2send > 0) { #if (DEBUG_SCA & DEBUG_SCA_FLUSH) - printf("* SCA_FLUSH %d byte%s\n", sca_n2send, (sca_n2send == 1) ? "" : "s"); + printf("* SCA_FLUSH %d byte%s\n", sca_n2send, (sca_n2send == 1) ? "" : "s"); #endif - if (sca_sock != INVALID_SOCKET) { - nbytes = sim_write_sock(sca_sock, (char *) sca_sendbuf, sca_n2send); + if (sca_sock != INVALID_SOCKET) { + nbytes = sim_write_sock(sca_sock, (char *) sca_sendbuf, sca_n2send); - if (nbytes == SOCKET_ERROR) - sca_socket_error(); - else if (nbytes != sca_n2send) - printf("SOCKET BLOCKED -- NEED TO REWRITE IBM1130_SCA.C"); + if (nbytes == SOCKET_ERROR) + sca_socket_error(); + else if (nbytes != sca_n2send) + printf("SOCKET BLOCKED -- NEED TO REWRITE IBM1130_SCA.C"); - /* I'm going to assume that SCA communications on the 1130 will consist entirely */ - /* of back and forth exchanges of short records, and so we should never stuff the pipe so full that */ - /* it blocks. If it does ever block, we'll have to come up with an asychronous buffering mechanism. */ - } + /* I'm going to assume that SCA communications on the 1130 will consist entirely */ + /* of back and forth exchanges of short records, and so we should never stuff the pipe so full that */ + /* it blocks. If it does ever block, we'll have to come up with an asychronous buffering mechanism. */ + } - sca_n2send = 0; /* mark buffer cleared */ - } + sca_n2send = 0; /* mark buffer cleared */ + } } /********************************************************************************************* @@ -360,52 +360,52 @@ static void sca_flush (void) static void sca_transmit_byte (uint8 b) { - uint32 curtime; - static uint32 last_syn_time, next_syn_time; + uint32 curtime; + static uint32 last_syn_time, next_syn_time; #if (DEBUG_SCA & DEBUG_SCA_TRANSMIT) - printf("* SCA_TRANSMIT: %02x\n", b); + printf("* SCA_TRANSMIT: %02x\n", b); #endif - /* write a byte to the socket. Let's assume an 8 bit frame in all cases. - * We buffer them up, then send the packet when (a) it fills up to a certain point - * and/or (b) some time has passed? We handle (b) by: - * checking in sva_svc if several sca_svc calls are made w/o any XIO_WRITES, and - * flushing send buffer on line turnaround, timeouts, or any other significant state change - */ + /* write a byte to the socket. Let's assume an 8 bit frame in all cases. + * We buffer them up, then send the packet when (a) it fills up to a certain point + * and/or (b) some time has passed? We handle (b) by: + * checking in sva_svc if several sca_svc calls are made w/o any XIO_WRITES, and + * flushing send buffer on line turnaround, timeouts, or any other significant state change + */ - /* on socket error, call sca_socket_error(); */ + /* on socket error, call sca_socket_error(); */ - if (b == sichar) { - if (sca_nsyns >= MAX_SYNS) { /* we're suppressing SYN's */ - if (sca_keepalive > 0) { /* we're sending keepalives, though... check to see if it's time */ - curtime = sim_os_msec(); - if (curtime >= next_syn_time || curtime < last_syn_time) { /* check for < last_syn_time because sim_os_msec() can wrap when OS has been running a long time */ - sca_sendbuf[sca_n2send++] = b; - sca_sendbuf[sca_n2send++] = b; /* send 2 of them */ - sca_flush(); - last_syn_time = curtime; - next_syn_time = last_syn_time + sca_keepalive; - } - } - return; - } + if (b == sichar) { + if (sca_nsyns >= MAX_SYNS) { /* we're suppressing SYN's */ + if (sca_keepalive > 0) { /* we're sending keepalives, though... check to see if it's time */ + curtime = sim_os_msec(); + if (curtime >= next_syn_time || curtime < last_syn_time) { /* check for < last_syn_time because sim_os_msec() can wrap when OS has been running a long time */ + sca_sendbuf[sca_n2send++] = b; + sca_sendbuf[sca_n2send++] = b; /* send 2 of them */ + sca_flush(); + last_syn_time = curtime; + next_syn_time = last_syn_time + sca_keepalive; + } + } + return; + } - if (++sca_nsyns == MAX_SYNS) { /* we've sent a bunch of SYN's, time to stop sending them */ - sca_sendbuf[sca_n2send] = b; /* send last one */ - sca_flush(); - last_syn_time = sim_os_msec(); /* remember time, and note time to send next one */ - next_syn_time = last_syn_time + sca_keepalive; - return; - } - } - else - sca_nsyns = 0; + if (++sca_nsyns == MAX_SYNS) { /* we've sent a bunch of SYN's, time to stop sending them */ + sca_sendbuf[sca_n2send] = b; /* send last one */ + sca_flush(); + last_syn_time = sim_os_msec(); /* remember time, and note time to send next one */ + next_syn_time = last_syn_time + sca_keepalive; + return; + } + } + else + sca_nsyns = 0; - sca_sendbuf[sca_n2send] = b; /* store character */ + sca_sendbuf[sca_n2send] = b; /* store character */ - if (++sca_n2send >= SCA_SEND_THRESHHOLD) - sca_flush(); /* buffer is full, send it immediately */ + if (++sca_n2send >= SCA_SEND_THRESHHOLD) + sca_flush(); /* buffer is full, send it immediately */ } /********************************************************************************************* @@ -414,10 +414,10 @@ static void sca_transmit_byte (uint8 b) static void sca_interrupt (int bit) { - sca_dsw |= bit; /* set device status word bit(s) */ - SETBIT(ILSW[1], ILSW_1_SCA); /* set interrupt level status word bit */ + sca_dsw |= bit; /* set device status word bit(s) */ + SETBIT(ILSW[1], ILSW_1_SCA); /* set interrupt level status word bit */ - calc_ints(); /* udpate simulator interrupt status (not really needed if within xio handler, since ibm1130_cpu calls it after xio handler) */ + calc_ints(); /* udpate simulator interrupt status (not really needed if within xio handler, since ibm1130_cpu calls it after xio handler) */ } /********************************************************************************************* @@ -426,21 +426,21 @@ static void sca_interrupt (int bit) static t_stat sca_reset (DEVICE *dptr) { - /* flush any pending data */ - sca_flush(); - sca_nrcvd = sca_rcvptr = sca_n2send = sca_nsyns = 0; + /* flush any pending data */ + sca_flush(); + sca_nrcvd = sca_rcvptr = sca_n2send = sca_nsyns = 0; - /* reset sca activity */ - sca_state = SCA_STATE_IDLE; - CLRBIT(sca_dsw, SCA_DSW_BUSY | SCA_DSW_AUTOANSWER_ENABLED | SCA_DSW_RECEIVE_RUN | SCA_DSW_READ_RESPONSE | SCA_DSW_WRITE_RESPONSE | SCA_DSW_CHECK | SCA_DSW_TIMEOUT | SCA_DSW_AUTOANSWER_REQUEST); - sca_timer_state[0] = sca_timer_state[1] = sca_timer_state[2] = SCA_TIMER_INACTIVE; - any_timer_running = FALSE; - sca_timer_trigger = FALSE; + /* reset sca activity */ + sca_state = SCA_STATE_IDLE; + CLRBIT(sca_dsw, SCA_DSW_BUSY | SCA_DSW_AUTOANSWER_ENABLED | SCA_DSW_RECEIVE_RUN | SCA_DSW_READ_RESPONSE | SCA_DSW_WRITE_RESPONSE | SCA_DSW_CHECK | SCA_DSW_TIMEOUT | SCA_DSW_AUTOANSWER_REQUEST); + sca_timer_state[0] = sca_timer_state[1] = sca_timer_state[2] = SCA_TIMER_INACTIVE; + any_timer_running = FALSE; + sca_timer_trigger = FALSE; - if (sca_unit.flags & UNIT_ATT) /* if unit is attached (or listening) */ - sim_activate(&sca_unit, sca_iwait); /* poll for service. Must do this here as BOOT clears activity queue before resetting all devices */ + if (sca_unit.flags & UNIT_ATT) /* if unit is attached (or listening) */ + sim_activate(&sca_unit, sca_iwait); /* poll for service. Must do this here as BOOT clears activity queue before resetting all devices */ - return SCPE_OK; + return SCPE_OK; } /********************************************************************************************* @@ -450,16 +450,16 @@ static t_stat sca_reset (DEVICE *dptr) static t_stat sca_attach (UNIT *uptr, CONST char *cptr) { char host[CBUFSIZE], port[CBUFSIZE]; - t_bool do_listen; - char name[CBUFSIZE]; + t_bool do_listen; + char name[CBUFSIZE]; t_stat r; - do_listen = sim_switches & SWMASK('L'); /* -l means listen mode */ + do_listen = sim_switches & SWMASK('L'); /* -l means listen mode */ - if (sca_unit.flags & UNIT_ATT) /* if already attached, detach */ - detach_unit(&sca_unit); + if (sca_unit.flags & UNIT_ATT) /* if already attached, detach */ + detach_unit(&sca_unit); - if (do_listen) { /* if listen mode, string specifies port number (only; otherwise it's a dummy argument) */ + if (do_listen) { /* if listen mode, string specifies port number (only; otherwise it's a dummy argument) */ if (sim_parse_addr (cptr, host, sizeof(host), NULL, port, sizeof(port), SCA_DEFAULT_PORT, NULL)) return SCPE_ARG; if ((0 == strcmp(port, cptr)) && (0 == strcmp(port, "dummy"))) @@ -467,28 +467,28 @@ static t_stat sca_attach (UNIT *uptr, CONST char *cptr) sprintf(sca_port, "%s%s%s:%s", strchr(host, ':') ? "[" : "", host, strchr(host, ':') ? "]" : "", port); - /* else if nondigits specified, ignore... but the command has to have something there otherwise the core scp */ - /* attach_cmd() routine complains "too few arguments". */ + /* else if nondigits specified, ignore... but the command has to have something there otherwise the core scp */ + /* attach_cmd() routine complains "too few arguments". */ - sca_lsock = sim_master_sock(sca_port, &r); + sca_lsock = sim_master_sock(sca_port, &r); if (r != SCPE_OK) return r; - if (sca_lsock == INVALID_SOCKET) - return SCPE_OPENERR; - - SETBIT(sca_unit.flags, UNIT_LISTEN); /* note that we are listening, not yet connected */ + if (sca_lsock == INVALID_SOCKET) + return SCPE_OPENERR; + + SETBIT(sca_unit.flags, UNIT_LISTEN); /* note that we are listening, not yet connected */ - sprintf(name, "(Listening on port %s)", sca_port); + sprintf(name, "(Listening on port %s)", sca_port); sca_unit.filename = mstring(name); - printf("%s\n", sca_unit.filename); + printf("%s\n", sca_unit.filename); - } - else { + } + else { while (*cptr && *cptr <= ' ') - cptr++; + cptr++; - if (! *cptr) - return SCPE_2FARG; + if (! *cptr) + return SCPE_2FARG; if (sim_parse_addr (cptr, host, sizeof(host), NULL, port, sizeof(port), SCA_DEFAULT_PORT, NULL)) return SCPE_ARG; @@ -499,45 +499,45 @@ static t_stat sca_attach (UNIT *uptr, CONST char *cptr) sprintf(sca_port, "%s%s%s:%s", strchr(host, ':') ? "[" : "", host, strchr(host, ':') ? "]" : "", port); - if ((sca_sock = sim_connect_sock(sca_port, NULL, NULL)) == INVALID_SOCKET) - return SCPE_OPENERR; + if ((sca_sock = sim_connect_sock(sca_port, NULL, NULL)) == INVALID_SOCKET) + return SCPE_OPENERR; - /* sim_connect_sock() sets socket to nonblocking before initiating the connect, so - * the connect is pending when it returns. For outgoing connections, the attach command should wait - * until the connection succeeds or fails. We use "sim_check_conn" to wait and find out which way it goes... - */ + /* sim_connect_sock() sets socket to nonblocking before initiating the connect, so + * the connect is pending when it returns. For outgoing connections, the attach command should wait + * until the connection succeeds or fails. We use "sim_check_conn" to wait and find out which way it goes... + */ while (0 == sim_check_conn(sca_sock, 0))/* wait for connection to complete or fail */ sim_os_ms_sleep(1000); - if (1 == sim_check_conn(sca_sock, 0)) { /* sca_sock appears in "writable" set -- connect completed */ + if (1 == sim_check_conn(sca_sock, 0)) { /* sca_sock appears in "writable" set -- connect completed */ sprintf(name, "%s%s%s:%s", strchr(host, ':') ? "[" : "", host, strchr(host, ':') ? "]" : "", port); - sca_unit.filename = mstring(name); - SETBIT(sca_dsw, SCA_DSW_READY); - } - else { /* sca_sock appears in "error" set -- connect failed */ - sim_close_sock(sca_sock); - sca_sock = INVALID_SOCKET; - return SCPE_OPENERR; - } - } - - /* set up socket connect or listen. on success, set UNIT_ATT. - * If listen mode, set UNIT_LISTEN. sca_svc will poll for connection - * If connect mode, set dsw SCA_DSW_READY to indicate connection is up - */ - - SETBIT(sca_unit.flags, UNIT_ATT); /* record successful socket binding */ + sca_unit.filename = mstring(name); + SETBIT(sca_dsw, SCA_DSW_READY); + } + else { /* sca_sock appears in "error" set -- connect failed */ + sim_close_sock(sca_sock); + sca_sock = INVALID_SOCKET; + return SCPE_OPENERR; + } + } + + /* set up socket connect or listen. on success, set UNIT_ATT. + * If listen mode, set UNIT_LISTEN. sca_svc will poll for connection + * If connect mode, set dsw SCA_DSW_READY to indicate connection is up + */ + + SETBIT(sca_unit.flags, UNIT_ATT); /* record successful socket binding */ - sca_state = SCA_STATE_IDLE; - sim_activate(&sca_unit, sca_iwait); /* start polling for service */ + sca_state = SCA_STATE_IDLE; + sim_activate(&sca_unit, sca_iwait); /* start polling for service */ - sca_n2send = 0; /* clear buffers */ - sca_nrcvd = 0; - sca_rcvptr = 0; - sca_nsyns = 0; + sca_n2send = 0; /* clear buffers */ + sca_nrcvd = 0; + sca_rcvptr = 0; + sca_nsyns = 0; - return SCPE_OK; + return SCPE_OK; } /********************************************************************************************* @@ -546,31 +546,31 @@ static t_stat sca_attach (UNIT *uptr, CONST char *cptr) static t_stat sca_detach (UNIT *uptr) { - if ((sca_unit.flags & UNIT_ATT) == 0) - return SCPE_OK; + if ((sca_unit.flags & UNIT_ATT) == 0) + return SCPE_OK; - sca_flush(); + sca_flush(); - sca_state = SCA_STATE_IDLE; /* stop processing during service calls */ - sim_cancel(&sca_unit); /* stop polling for service */ + sca_state = SCA_STATE_IDLE; /* stop processing during service calls */ + sim_cancel(&sca_unit); /* stop polling for service */ - CLRBIT(sca_dsw, SCA_DSW_READY); /* indicate offline */ + CLRBIT(sca_dsw, SCA_DSW_READY); /* indicate offline */ - if (sca_sock != INVALID_SOCKET) { /* close connected socket */ - sim_close_sock(sca_sock); - sca_sock = INVALID_SOCKET; - } - if (sca_lsock != INVALID_SOCKET) { /* close listening socket */ - sim_close_sock(sca_lsock); - sca_lsock = INVALID_SOCKET; - } - - free(sca_unit.filename); - sca_unit.filename = NULL; + if (sca_sock != INVALID_SOCKET) { /* close connected socket */ + sim_close_sock(sca_sock); + sca_sock = INVALID_SOCKET; + } + if (sca_lsock != INVALID_SOCKET) { /* close listening socket */ + sim_close_sock(sca_lsock); + sca_lsock = INVALID_SOCKET; + } + + free(sca_unit.filename); + sca_unit.filename = NULL; - CLRBIT(sca_unit.flags, UNIT_ATT|UNIT_LISTEN); + CLRBIT(sca_unit.flags, UNIT_ATT|UNIT_LISTEN); - return SCPE_OK; + return SCPE_OK; } /********************************************************************************************* @@ -579,22 +579,22 @@ static t_stat sca_detach (UNIT *uptr) static void sca_check_connect (void) { - char *connectaddress; + char *connectaddress; - if ((sca_sock = sim_accept_conn(sca_lsock, &connectaddress)) == INVALID_SOCKET) - return; + if ((sca_sock = sim_accept_conn(sca_lsock, &connectaddress)) == INVALID_SOCKET) + return; - printf("(SCA connection from %s)\n", connectaddress); + printf("(SCA connection from %s)\n", connectaddress); - if (sca_unit.filename != NULL) - free(sca_unit.filename); + if (sca_unit.filename != NULL) + free(sca_unit.filename); - sca_unit.filename = connectaddress; + sca_unit.filename = connectaddress; - SETBIT(sca_dsw, SCA_DSW_READY); /* indicate active connection */ + SETBIT(sca_dsw, SCA_DSW_READY); /* indicate active connection */ - if (sca_dsw & SCA_DSW_AUTOANSWER_ENABLED) /* if autoanswer was enabled, I guess we should give them an interrupt. Untested. */ - sca_interrupt(SCA_DSW_AUTOANSWER_REQUEST); + if (sca_dsw & SCA_DSW_AUTOANSWER_ENABLED) /* if autoanswer was enabled, I guess we should give them an interrupt. Untested. */ + sca_interrupt(SCA_DSW_AUTOANSWER_REQUEST); } /********************************************************************************************* @@ -603,34 +603,34 @@ static void sca_check_connect (void) static void sca_check_indata (void) { - int nbytes; + int nbytes; - sca_rcvptr = 0; /* reset pointers and count */ - sca_nrcvd = 0; + sca_rcvptr = 0; /* reset pointers and count */ + sca_nrcvd = 0; #ifdef FAKE_SCA - nbytes = 5; /* FAKE: receive SYN SYN SYN SYN DLE ACK0 */ - sca_rcvbuf[0] = 0x32; - sca_rcvbuf[1] = 0x32; - sca_rcvbuf[2] = 0x32; - sca_rcvbuf[3] = 0x10; - sca_rcvbuf[4] = 0x70; + nbytes = 5; /* FAKE: receive SYN SYN SYN SYN DLE ACK0 */ + sca_rcvbuf[0] = 0x32; + sca_rcvbuf[1] = 0x32; + sca_rcvbuf[2] = 0x32; + sca_rcvbuf[3] = 0x10; + sca_rcvbuf[4] = 0x70; #else - /* read socket; 0 is returned if no data is available */ - nbytes = sim_read_sock(sca_sock, (char *) sca_rcvbuf, SCA_RCVBUF_SIZE); + /* read socket; 0 is returned if no data is available */ + nbytes = sim_read_sock(sca_sock, (char *) sca_rcvbuf, SCA_RCVBUF_SIZE); #endif - if (nbytes < 0) - sca_socket_error(); - else /* zero or more */ - sca_nrcvd = nbytes; + if (nbytes < 0) + sca_socket_error(); + else /* zero or more */ + sca_nrcvd = nbytes; #if (DEBUG_SCA & DEBUG_SCA_CHECK_INDATA) - if (sca_nrcvd > 0) - printf("* SCA_CHECK_INDATA %d byte%s\n", sca_nrcvd, (sca_nrcvd == 1) ? "" : "s"); + if (sca_nrcvd > 0) + printf("* SCA_CHECK_INDATA %d byte%s\n", sca_nrcvd, (sca_nrcvd == 1) ? "" : "s"); #endif } @@ -641,150 +641,150 @@ static void sca_check_indata (void) static t_stat sca_svc (UNIT *uptr) { - t_bool timeout; - int msec_now; - int i; + t_bool timeout; + int msec_now; + int i; - /* if not connected, and if in wait-for-connection mode, check for connection attempt */ - if ((sca_unit.flags & UNIT_LISTEN) && ! (sca_dsw & SCA_DSW_READY)) - sca_check_connect(); + /* if not connected, and if in wait-for-connection mode, check for connection attempt */ + if ((sca_unit.flags & UNIT_LISTEN) && ! (sca_dsw & SCA_DSW_READY)) + sca_check_connect(); - if (any_timer_running) { - msec_now = sim_os_msec(); + if (any_timer_running) { + msec_now = sim_os_msec(); - timeout = FALSE; - for (i = 0; i < 3; i++) { - if (sca_timer_state[i] == SCA_TIMER_RUNNING && msec_now >= sca_timer_endtime[i]) { - timeout = TRUE; - sca_timer_state[i] = SCA_TIMER_TIMEDOUT; + timeout = FALSE; + for (i = 0; i < 3; i++) { + if (sca_timer_state[i] == SCA_TIMER_RUNNING && msec_now >= sca_timer_endtime[i]) { + timeout = TRUE; + sca_timer_state[i] = SCA_TIMER_TIMEDOUT; #if (DEBUG_SCA & DEBUG_SCA_TIMERS) - printf("+ SCA_TIMER %d timed out\n", i); + printf("+ SCA_TIMER %d timed out\n", i); #endif - if (i == TIMER_035S && sca_timer_trigger) { - sca_timer_trigger = FALSE; /* uninhibit the other two timers */ - sca_toggle_timer(TIMER_3S, msec_now); - sca_toggle_timer(TIMER_125S, msec_now); - } - } - } + if (i == TIMER_035S && sca_timer_trigger) { + sca_timer_trigger = FALSE; /* uninhibit the other two timers */ + sca_toggle_timer(TIMER_3S, msec_now); + sca_toggle_timer(TIMER_125S, msec_now); + } + } + } - if (timeout) - sca_interrupt(SCA_DSW_TIMEOUT); + if (timeout) + sca_interrupt(SCA_DSW_TIMEOUT); - any_timer_running = (sca_timer_state[0]| sca_timer_state[1] | sca_timer_state[2]) & SCA_TIMER_RUNNING; - } + any_timer_running = (sca_timer_state[0]| sca_timer_state[1] | sca_timer_state[2]) & SCA_TIMER_RUNNING; + } - if (sca_dsw & SCA_DSW_READY) { /* if connected */ + if (sca_dsw & SCA_DSW_READY) { /* if connected */ - /* if rcvd data buffer is empty, and if in one of the receive states, checÄk for arrival of received data */ - if (in_receive_state() && sca_rcvptr >= sca_nrcvd) - sca_check_indata(); + /* if rcvd data buffer is empty, and if in one of the receive states, checÄk for arrival of received data */ + if (in_receive_state() && sca_rcvptr >= sca_nrcvd) + sca_check_indata(); - switch (sca_state) { - case SCA_STATE_IDLE: - break; + switch (sca_state) { + case SCA_STATE_IDLE: + break; - case SCA_STATE_TURN_SEND: - /* has enough time gone by yet? if so... */ - sca_state = SCA_STATE_SEND1; - sca_interrupt(SCA_DSW_WRITE_RESPONSE); - break; + case SCA_STATE_TURN_SEND: + /* has enough time gone by yet? if so... */ + sca_state = SCA_STATE_SEND1; + sca_interrupt(SCA_DSW_WRITE_RESPONSE); + break; - case SCA_STATE_SEND_SYNC: - sca_transmit_byte(sichar); - break; + case SCA_STATE_SEND_SYNC: + sca_transmit_byte(sichar); + break; - case SCA_STATE_SEND1: - sca_transmit_byte(sichar); /* character interval has passed with no character written? character gap check */ - sca_interrupt(SCA_DSW_CHECK); /* send an idle character (maybe? for socket IO maybe send nothing) and interrupt */ + case SCA_STATE_SEND1: + sca_transmit_byte(sichar); /* character interval has passed with no character written? character gap check */ + sca_interrupt(SCA_DSW_CHECK); /* send an idle character (maybe? for socket IO maybe send nothing) and interrupt */ - if (idles_since_last_write >= 0) { - if (++idles_since_last_write >= SCA_IDLE_THRESHHOLD) { - sca_flush(); - idles_since_last_write = -1; /* don't send a short packet again until real data gets written again */ - sca_nsyns = 0; /* resume sending syns if output starts up again */ - } - } - break; + if (idles_since_last_write >= 0) { + if (++idles_since_last_write >= SCA_IDLE_THRESHHOLD) { + sca_flush(); + idles_since_last_write = -1; /* don't send a short packet again until real data gets written again */ + sca_nsyns = 0; /* resume sending syns if output starts up again */ + } + } + break; - case SCA_STATE_SEND2: - sca_state = SCA_STATE_SEND1; /* character has been sent. Schedule another transmit */ - sca_interrupt(SCA_DSW_WRITE_RESPONSE); - break; + case SCA_STATE_SEND2: + sca_state = SCA_STATE_SEND1; /* character has been sent. Schedule another transmit */ + sca_interrupt(SCA_DSW_WRITE_RESPONSE); + break; - case SCA_STATE_TURN_RECEIVE: - /* has enough time gone by yet? if so... */ - sca_state = SCA_STATE_RECEIVE_SYNC; /* assume a character is coming in */ - break; + case SCA_STATE_TURN_RECEIVE: + /* has enough time gone by yet? if so... */ + sca_state = SCA_STATE_RECEIVE_SYNC; /* assume a character is coming in */ + break; - case SCA_STATE_RECEIVE_SYNC: - if (sca_rcvptr < sca_nrcvd) { - rcvd_char = sca_rcvbuf[sca_rcvptr++]; + case SCA_STATE_RECEIVE_SYNC: + if (sca_rcvptr < sca_nrcvd) { + rcvd_char = sca_rcvbuf[sca_rcvptr++]; #if (DEBUG_SCA & DEBUG_SCA_RECEIVE_SYNC) - printf("* SCA rcvd %02x %s\n", rcvd_char, (rcvd_char == sichar) ? "sync1" : "ignored"); + printf("* SCA rcvd %02x %s\n", rcvd_char, (rcvd_char == sichar) ? "sync1" : "ignored"); #endif - if (in_bsc_mode()) { - if (rcvd_char == sichar) /* count the SYN but don't interrupt */ - sca_state = SCA_STATE_RECEIVE_SYNC2; - } - } - break; + if (in_bsc_mode()) { + if (rcvd_char == sichar) /* count the SYN but don't interrupt */ + sca_state = SCA_STATE_RECEIVE_SYNC2; + } + } + break; - case SCA_STATE_RECEIVE_SYNC2: - if (sca_rcvptr < sca_nrcvd) { - rcvd_char = sca_rcvbuf[sca_rcvptr++]; + case SCA_STATE_RECEIVE_SYNC2: + if (sca_rcvptr < sca_nrcvd) { + rcvd_char = sca_rcvbuf[sca_rcvptr++]; #if (DEBUG_SCA & DEBUG_SCA_RECEIVE_SYNC) - printf("* SCA rcvd %02x %s\n", rcvd_char, (rcvd_char == sichar) ? "sync2" : "ignored"); + printf("* SCA rcvd %02x %s\n", rcvd_char, (rcvd_char == sichar) ? "sync2" : "ignored"); #endif - if (in_bsc_mode()) { - if (rcvd_char == sichar) /* count the SYN but don't interrupt */ - sca_state = SCA_STATE_RECEIVE_SYNC3; - } - } - break; + if (in_bsc_mode()) { + if (rcvd_char == sichar) /* count the SYN but don't interrupt */ + sca_state = SCA_STATE_RECEIVE_SYNC3; + } + } + break; - case SCA_STATE_RECEIVE_SYNC3: - case SCA_STATE_RECEIVE1: - if (sca_rcvptr < sca_nrcvd) { - rcvd_char = sca_rcvbuf[sca_rcvptr++]; + case SCA_STATE_RECEIVE_SYNC3: + case SCA_STATE_RECEIVE1: + if (sca_rcvptr < sca_nrcvd) { + rcvd_char = sca_rcvbuf[sca_rcvptr++]; - if (sca_state == SCA_STATE_RECEIVE_SYNC3 && rcvd_char == sichar) { - /* we're ready for data, but we're still seeing SYNs */ + if (sca_state == SCA_STATE_RECEIVE_SYNC3 && rcvd_char == sichar) { + /* we're ready for data, but we're still seeing SYNs */ #if (DEBUG_SCA & DEBUG_SCA_RECEIVE_SYNC) - printf("* SCA rcvd %02x extra sync\n", rcvd_char); + printf("* SCA rcvd %02x extra sync\n", rcvd_char); #endif - } - else { + } + else { #if (DEBUG_SCA & DEBUG_SCA_RECEIVE_DATA) - printf("* SCA rcvd %02x\n", rcvd_char); + printf("* SCA rcvd %02x\n", rcvd_char); #endif - sca_interrupt(SCA_DSW_READ_RESPONSE); - sca_state = SCA_STATE_RECEIVE2; - } - } - /* otherwise remain in state until data becomes available */ - break; + sca_interrupt(SCA_DSW_READ_RESPONSE); + sca_state = SCA_STATE_RECEIVE2; + } + } + /* otherwise remain in state until data becomes available */ + break; - case SCA_STATE_RECEIVE2: /* if we are still in this state when another service interval has passed */ - if (sca_rcvptr < sca_nrcvd) { - rcvd_char = sca_rcvbuf[sca_rcvptr++]; + case SCA_STATE_RECEIVE2: /* if we are still in this state when another service interval has passed */ + if (sca_rcvptr < sca_nrcvd) { + rcvd_char = sca_rcvbuf[sca_rcvptr++]; - sca_interrupt(SCA_DSW_CHECK); /* overrun error */ - sca_state = SCA_STATE_RECEIVE1; /* another character will come soon */ - } - break; + sca_interrupt(SCA_DSW_CHECK); /* overrun error */ + sca_state = SCA_STATE_RECEIVE1; /* another character will come soon */ + } + break; - default: - printf("Simulator error: unknown state %d in sca_svc\n", sca_state); - sca_state = SCA_STATE_IDLE; - break; - } - } - /* schedule service again */ - sim_activate(&sca_unit, (sca_state == SCA_STATE_IDLE) ? sca_iwait : sca_cwait); + default: + printf("Simulator error: unknown state %d in sca_svc\n", sca_state); + sca_state = SCA_STATE_IDLE; + break; + } + } + /* schedule service again */ + sim_activate(&sca_unit, (sca_state == SCA_STATE_IDLE) ? sca_iwait : sca_cwait); - return SCPE_OK; + return SCPE_OK; } /********************************************************************************************* @@ -793,40 +793,40 @@ static t_stat sca_svc (UNIT *uptr) static void sca_toggle_timer (int n, int msec_now) { - if (sca_timer_state[n] == SCA_TIMER_RUNNING && sca_timer_trigger) { - sca_timer_state[n] = SCA_TIMER_INHIBITED; - sca_timer_timeleft[n] = sca_timer_endtime[n] - msec_now; /* save time left */ + if (sca_timer_state[n] == SCA_TIMER_RUNNING && sca_timer_trigger) { + sca_timer_state[n] = SCA_TIMER_INHIBITED; + sca_timer_timeleft[n] = sca_timer_endtime[n] - msec_now; /* save time left */ #if (DEBUG_SCA & DEBUG_SCA_TIMERS) - printf("+ SCA_TIMER %d inhibited\n", n); + printf("+ SCA_TIMER %d inhibited\n", n); #endif - } - else if (sca_timer_state[n] == SCA_TIMER_INHIBITED && ! sca_timer_trigger) { - sca_timer_state[n] = SCA_TIMER_RUNNING; - sca_timer_endtime[n] = sca_timer_timeleft[n] + msec_now; /* compute new endtime */ + } + else if (sca_timer_state[n] == SCA_TIMER_INHIBITED && ! sca_timer_trigger) { + sca_timer_state[n] = SCA_TIMER_RUNNING; + sca_timer_endtime[n] = sca_timer_timeleft[n] + msec_now; /* compute new endtime */ #if (DEBUG_SCA & DEBUG_SCA_TIMERS) - printf("+ SCA_TIMER %d uninhibited\n", n); + printf("+ SCA_TIMER %d uninhibited\n", n); #endif - } + } } static void sca_start_timer (int n, int msec_now) { - sca_timer_state[n] = SCA_TIMER_RUNNING; - sca_timer_endtime[n] = sca_timer_msec[n] + msec_now; - any_timer_running = TRUE; + sca_timer_state[n] = SCA_TIMER_RUNNING; + sca_timer_endtime[n] = sca_timer_msec[n] + msec_now; + any_timer_running = TRUE; #if (DEBUG_SCA & DEBUG_SCA_TIMERS) - printf("+ SCA_TIMER %d started\n", n); + printf("+ SCA_TIMER %d started\n", n); #endif } static void sca_halt_timer (int n) { #if (DEBUG_SCA & DEBUG_SCA_TIMERS) - if (sca_timer_state[n] != SCA_TIMER_INACTIVE) - printf("+ SCA_TIMER %d stopped\n", n); + if (sca_timer_state[n] != SCA_TIMER_INACTIVE) + printf("+ SCA_TIMER %d stopped\n", n); #endif - sca_timer_state[n] = SCA_TIMER_INACTIVE; + sca_timer_state[n] = SCA_TIMER_INACTIVE; } /********************************************************************************************* @@ -835,32 +835,32 @@ static void sca_halt_timer (int n) void sca_start_transmit (int32 iocc_addr, int32 modify) { - sca_flush(); - sca_nsyns = 0; /* reset SYN suppression */ + sca_flush(); + sca_nsyns = 0; /* reset SYN suppression */ - /* Address bits are used to reset DSW conditions. */ + /* Address bits are used to reset DSW conditions. */ - if (modify & 0x40) /* bit 9. If set, reset all conditions */ - iocc_addr = 0xD800; + if (modify & 0x40) /* bit 9. If set, reset all conditions */ + iocc_addr = 0xD800; - iocc_addr &= 0xD800; /* look at just bits 0, 1, 3 and 4 */ - if (iocc_addr) { /* if set, these bits clear DSW conditions */ - CLRBIT(sca_dsw, iocc_addr); - CLRBIT(ILSW[1], ILSW_1_SCA); /* and I assume clear the interrupt condition too? (Seems unlikely that INITW would */ - } /* be used in an interrupt service routine before SENSE, but who knows?) */ + iocc_addr &= 0xD800; /* look at just bits 0, 1, 3 and 4 */ + if (iocc_addr) { /* if set, these bits clear DSW conditions */ + CLRBIT(sca_dsw, iocc_addr); + CLRBIT(ILSW[1], ILSW_1_SCA); /* and I assume clear the interrupt condition too? (Seems unlikely that INITW would */ + } /* be used in an interrupt service routine before SENSE, but who knows?) */ - if (! in_send_state()) { - sca_state = SCA_STATE_TURN_SEND; /* begin line turnaround */ - } - else { - sca_state = SCA_STATE_SEND1; /* line is */ - sca_interrupt(SCA_DSW_WRITE_RESPONSE); - } + if (! in_send_state()) { + sca_state = SCA_STATE_TURN_SEND; /* begin line turnaround */ + } + else { + sca_state = SCA_STATE_SEND1; /* line is */ + sca_interrupt(SCA_DSW_WRITE_RESPONSE); + } - SETBIT(sca_dsw, SCA_DSW_BUSY); /* SCA is now busy, in transmit mode */ + SETBIT(sca_dsw, SCA_DSW_BUSY); /* SCA is now busy, in transmit mode */ - sim_cancel(&sca_unit); - sim_activate(&sca_unit, sca_cwait); /* start polling frequently */ + sim_cancel(&sca_unit); + sim_activate(&sca_unit, sca_cwait); /* start polling frequently */ } /********************************************************************************************* @@ -869,261 +869,261 @@ void sca_start_transmit (int32 iocc_addr, int32 modify) void xio_sca (int32 iocc_addr, int32 func, int32 modify) { - char msg[80]; - int i, msec_now; + char msg[80]; + int i, msec_now; - switch (func) { - case XIO_READ: /* ***** XIO_READ - store last-received character to memory */ + switch (func) { + case XIO_READ: /* ***** XIO_READ - store last-received character to memory */ #if (DEBUG_SCA & DEBUG_SCA_XIO_READ) - printf("SCA RD addr %04x mod %02x rcvd_char %02x\n", iocc_addr, modify, rcvd_char); + printf("SCA RD addr %04x mod %02x rcvd_char %02x\n", iocc_addr, modify, rcvd_char); #endif - if (modify & 0x03) { /* bits 14 and 15 */ + if (modify & 0x03) { /* bits 14 and 15 */ #if (DEBUG_SCA & DEBUG_SCA_XIO_READ) - printf("(rd diag)\n"); + printf("(rd diag)\n"); #endif - /* if either of low two modifier bits is set, reads diagnostic words. whatever that is */ - } - else { - WriteW(iocc_addr, rcvd_char << 8); /* always return last received character */ + /* if either of low two modifier bits is set, reads diagnostic words. whatever that is */ + } + else { + WriteW(iocc_addr, rcvd_char << 8); /* always return last received character */ - /* note: in read mode, read w/o interrupt (or two reads after an interrupt) causes a check - * so here we have to check the current state and possibly cause an interrupt - * Failure to have read before another arrives (overrun) also causes a check. - */ + /* note: in read mode, read w/o interrupt (or two reads after an interrupt) causes a check + * so here we have to check the current state and possibly cause an interrupt + * Failure to have read before another arrives (overrun) also causes a check. + */ - if (sca_state == SCA_STATE_RECEIVE2)/* XIO_READ should only be done (and only once) after a character interrupt */ - sca_state = SCA_STATE_RECEIVE1; /* assume another character is coming in -- wait for it */ - else - sca_interrupt(SCA_DSW_CHECK); - } - break; + if (sca_state == SCA_STATE_RECEIVE2)/* XIO_READ should only be done (and only once) after a character interrupt */ + sca_state = SCA_STATE_RECEIVE1; /* assume another character is coming in -- wait for it */ + else + sca_interrupt(SCA_DSW_CHECK); + } + break; - case XIO_WRITE: /* ***** XIO_WRITE - transfer character from memory to output shift register */ + case XIO_WRITE: /* ***** XIO_WRITE - transfer character from memory to output shift register */ #if (DEBUG_SCA & DEBUG_SCA_XIO_WRITE) - printf("SCA WRT addr %04x (%04x) mod %02x\n", iocc_addr, M[iocc_addr & mem_mask], modify); + printf("SCA WRT addr %04x (%04x) mod %02x\n", iocc_addr, M[iocc_addr & mem_mask], modify); #endif - if (modify & 0x01) { /* bit 15 */ - /* clear audible alarm trigger */ + if (modify & 0x01) { /* bit 15 */ + /* clear audible alarm trigger */ #if (DEBUG_SCA & DEBUG_SCA_XIO_WRITE) - printf("(clr audible alarm trigger)\n"); + printf("(clr audible alarm trigger)\n"); #endif - } - /* else? or can they all operate in parallel? */ - if (modify & 0x02) { /* bit 14 */ - /* set audible alarm trigger */ + } + /* else? or can they all operate in parallel? */ + if (modify & 0x02) { /* bit 14 */ + /* set audible alarm trigger */ #if (DEBUG_SCA & DEBUG_SCA_XIO_WRITE) - printf("(set audible alarm trigger)\n"); + printf("(set audible alarm trigger)\n"); #endif - } - /* else? */ - if (modify & 0x04) { /* bit 13 */ + } + /* else? */ + if (modify & 0x04) { /* bit 13 */ #if (DEBUG_SCA & DEBUG_SCA_XIO_WRITE) - printf("(set SYN)\n"); + printf("(set SYN)\n"); #endif - /* set sync/idle character */ - sichar = (uint8) (ReadW(iocc_addr) >> 8); - sca_nsyns = 0; /* reset SYN suppression */ - } - /* else? does presence of mod bit preclude sending a character? */ - if ((modify & 0x07) == 0) { /* no modifiers */ - /* transmit character -- - * note: in write mode, failure to write soon enough after a write response interrupt causes a check - * Also, writing w/o interrupt (or two writes after an interrupt) causes a check - * so again, here we have to check the state to be sure that a write is appropriate - * - * note that in this simulator, we transmit the character immediately on XIO_WRITE. Therefore, - * there is no need to delay an end-operation function (XIO_CONTROL bit 13) until after a character time - */ + /* set sync/idle character */ + sichar = (uint8) (ReadW(iocc_addr) >> 8); + sca_nsyns = 0; /* reset SYN suppression */ + } + /* else? does presence of mod bit preclude sending a character? */ + if ((modify & 0x07) == 0) { /* no modifiers */ + /* transmit character -- + * note: in write mode, failure to write soon enough after a write response interrupt causes a check + * Also, writing w/o interrupt (or two writes after an interrupt) causes a check + * so again, here we have to check the state to be sure that a write is appropriate + * + * note that in this simulator, we transmit the character immediately on XIO_WRITE. Therefore, + * there is no need to delay an end-operation function (XIO_CONTROL bit 13) until after a character time + */ - idles_since_last_write = 0; + idles_since_last_write = 0; - switch (sca_state) { - case SCA_STATE_SEND_SYNC: - case SCA_STATE_SEND1: - sca_transmit_byte((uint8) (M[iocc_addr & mem_mask] >> 8)); - sca_state = SCA_STATE_SEND2; - sim_cancel(&sca_unit); - sim_activate(&sca_unit, sca_cwait); /* schedule service after character write time */ - break; + switch (sca_state) { + case SCA_STATE_SEND_SYNC: + case SCA_STATE_SEND1: + sca_transmit_byte((uint8) (M[iocc_addr & mem_mask] >> 8)); + sca_state = SCA_STATE_SEND2; + sim_cancel(&sca_unit); + sim_activate(&sca_unit, sca_cwait); /* schedule service after character write time */ + break; - case SCA_STATE_SEND2: - sca_interrupt(SCA_DSW_CHECK); /* write issued while a character is in progress out? write overrun */ - break; + case SCA_STATE_SEND2: + sca_interrupt(SCA_DSW_CHECK); /* write issued while a character is in progress out? write overrun */ + break; - case SCA_STATE_IDLE: /* wrong time to issue a write, incorrect sca state */ - default: - sca_flush(); - sca_interrupt(SCA_DSW_CHECK); /* ??? or does this just perform a line turnaround and start transmission? */ - break; - } + case SCA_STATE_IDLE: /* wrong time to issue a write, incorrect sca state */ + default: + sca_flush(); + sca_interrupt(SCA_DSW_CHECK); /* ??? or does this just perform a line turnaround and start transmission? */ + break; + } - } - break; + } + break; - case XIO_CONTROL: /* ***** XIO_CONTROL - manipulate interface state */ + case XIO_CONTROL: /* ***** XIO_CONTROL - manipulate interface state */ #if (DEBUG_SCA & DEBUG_SCA_XIO_CONTROL) - printf("SCA CTL addr %04x mod %02x\n", iocc_addr, modify); + printf("SCA CTL addr %04x mod %02x\n", iocc_addr, modify); #endif - if (modify & 0x80) { /* bit 8 */ - /* enable auto answer */ + if (modify & 0x80) { /* bit 8 */ + /* enable auto answer */ #if (DEBUG_SCA & DEBUG_SCA_XIO_CONTROL) - printf("(enable autoanswer)\n"); + printf("(enable autoanswer)\n"); #endif - SETBIT(sca_unit.flags, UNIT_AUTOANSWER); - SETBIT(sca_dsw, SCA_DSW_AUTOANSWER_ENABLED); - } + SETBIT(sca_unit.flags, UNIT_AUTOANSWER); + SETBIT(sca_dsw, SCA_DSW_AUTOANSWER_ENABLED); + } - if (modify & 0x40) { /* bit 9 */ - /* disable auto answer */ + if (modify & 0x40) { /* bit 9 */ + /* disable auto answer */ #if (DEBUG_SCA & DEBUG_SCA_XIO_CONTROL) - printf("(disable autoanswer)\n"); + printf("(disable autoanswer)\n"); #endif - CLRBIT(sca_unit.flags, UNIT_AUTOANSWER); - CLRBIT(sca_dsw, SCA_DSW_AUTOANSWER_ENABLED); - } + CLRBIT(sca_unit.flags, UNIT_AUTOANSWER); + CLRBIT(sca_dsw, SCA_DSW_AUTOANSWER_ENABLED); + } - if (modify & 0x20) { /* bit 10 */ - /* toggle timers, inhibit->run or run->inhibit */ + if (modify & 0x20) { /* bit 10 */ + /* toggle timers, inhibit->run or run->inhibit */ #if (DEBUG_SCA & (DEBUG_SCA_XIO_CONTROL|DEBUG_SCA_TIMERS)) - printf("(toggle timers)\n"); + printf("(toggle timers)\n"); #endif - msec_now = sim_os_msec(); + msec_now = sim_os_msec(); - if (in_bsc_mode()) - sca_timer_trigger = ! sca_timer_trigger; /* toggle the timer trigger */ - if (sca_timer_trigger) /* if we've just set it, we're stopping the other timers and */ - sca_start_timer(TIMER_035S, msec_now); /* starting the 0.35 sec timer */ - else - sca_halt_timer(TIMER_035S); + if (in_bsc_mode()) + sca_timer_trigger = ! sca_timer_trigger; /* toggle the timer trigger */ + if (sca_timer_trigger) /* if we've just set it, we're stopping the other timers and */ + sca_start_timer(TIMER_035S, msec_now); /* starting the 0.35 sec timer */ + else + sca_halt_timer(TIMER_035S); - sca_toggle_timer(TIMER_3S, msec_now); /* toggle the 3 sec and 1.35 sec timers accordingly */ - sca_toggle_timer(TIMER_125S, msec_now); + sca_toggle_timer(TIMER_3S, msec_now); /* toggle the 3 sec and 1.35 sec timers accordingly */ + sca_toggle_timer(TIMER_125S, msec_now); - any_timer_running = (sca_timer_state[0]| sca_timer_state[1] | sca_timer_state[2]) & SCA_TIMER_RUNNING; - } + any_timer_running = (sca_timer_state[0]| sca_timer_state[1] | sca_timer_state[2]) & SCA_TIMER_RUNNING; + } - if (modify & 0x10) { /* bit 11 */ - /* enable sync mode. See references to this in FC manual - * In STR mode only, sends a constant stream of SYN's without any CPU intervention - * In BSC mode, appears to start the 1.25 second timer and otherwise act like INITW? - */ + if (modify & 0x10) { /* bit 11 */ + /* enable sync mode. See references to this in FC manual + * In STR mode only, sends a constant stream of SYN's without any CPU intervention + * In BSC mode, appears to start the 1.25 second timer and otherwise act like INITW? + */ #if (DEBUG_SCA & DEBUG_SCA_XIO_CONTROL) - printf("(enable sync mode)\n"); + printf("(enable sync mode)\n"); #endif - if (in_bsc_mode()) { /* in bsc mode start the 1.25 second timer. not sure what resets it?!? */ - if (! in_send_state()) /* also may cause a line turnaround */ - sca_start_transmit(iocc_addr, 0); + if (in_bsc_mode()) { /* in bsc mode start the 1.25 second timer. not sure what resets it?!? */ + if (! in_send_state()) /* also may cause a line turnaround */ + sca_start_transmit(iocc_addr, 0); - sca_start_timer(TIMER_125S, sim_os_msec()); - } - } + sca_start_timer(TIMER_125S, sim_os_msec()); + } + } - if (modify & 0x08) { /* bit 12 */ - /* diagnostic mode. What does this do?!? */ + if (modify & 0x08) { /* bit 12 */ + /* diagnostic mode. What does this do?!? */ #if (DEBUG_SCA & DEBUG_SCA_XIO_CONTROL) - printf("(diag mode)\n"); + printf("(diag mode)\n"); #endif - } + } - if (modify & 0x04) { /* bit 13 */ - /* end operation (reset adapter. See references to this in FC manual). In transmit mode the real adapter delays this - * function until current character has been sent. We don't need to do that as the character got buffered for transmission - * immediately on XIO_WRITE. - */ + if (modify & 0x04) { /* bit 13 */ + /* end operation (reset adapter. See references to this in FC manual). In transmit mode the real adapter delays this + * function until current character has been sent. We don't need to do that as the character got buffered for transmission + * immediately on XIO_WRITE. + */ #if (DEBUG_SCA & (DEBUG_SCA_XIO_CONTROL|DEBUG_SCA_XIO_INITR|DEBUG_SCA_XIO_INITW)) - printf("(end operation)\n"); + printf("(end operation)\n"); #endif - sca_state = SCA_STATE_IDLE; - sca_timer_state[0] = sca_timer_state[1] = sca_timer_state[2] = SCA_TIMER_INACTIVE; - any_timer_running = FALSE; - sca_timer_trigger = FALSE; - sca_nsyns = 0; /* reset SYN suppression */ - CLRBIT(sca_dsw, SCA_DSW_BUSY); - } + sca_state = SCA_STATE_IDLE; + sca_timer_state[0] = sca_timer_state[1] = sca_timer_state[2] = SCA_TIMER_INACTIVE; + any_timer_running = FALSE; + sca_timer_trigger = FALSE; + sca_nsyns = 0; /* reset SYN suppression */ + CLRBIT(sca_dsw, SCA_DSW_BUSY); + } - if (modify & 0x02) { /* bit 14 */ + if (modify & 0x02) { /* bit 14 */ #if (DEBUG_SCA & DEBUG_SCA_XIO_CONTROL) - printf("(6 bit frame)\n"); + printf("(6 bit frame)\n"); #endif - /* set six bit character frame. This is reset to 8 bits at every line turnaround */ - sca_frame = 6; - } + /* set six bit character frame. This is reset to 8 bits at every line turnaround */ + sca_frame = 6; + } - if (modify & 0x01) { /* bit 15 */ + if (modify & 0x01) { /* bit 15 */ #if (DEBUG_SCA & DEBUG_SCA_XIO_CONTROL) - printf("(7 bit frame)\n"); + printf("(7 bit frame)\n"); #endif - /* set seven bit character frame. This is reset to 8 bits at every line turnaround */ - sca_frame = 7; - } + /* set seven bit character frame. This is reset to 8 bits at every line turnaround */ + sca_frame = 7; + } - sca_flush(); - break; + sca_flush(); + break; - case XIO_INITW: /* ***** XIO_INITW - put SCA in transmit mode */ + case XIO_INITW: /* ***** XIO_INITW - put SCA in transmit mode */ #if (DEBUG_SCA & DEBUG_SCA_XIO_INITW) - printf("SCA INITW addr %04x mod %02x\n", iocc_addr, modify); + printf("SCA INITW addr %04x mod %02x\n", iocc_addr, modify); #endif - /* enter transmit mode. Causes line turnaround. Resets frame to 8 bits. */ - /* (may cause syncing, may involve a fixed timeout?) */ - sca_frame = 8; - sca_start_transmit(iocc_addr, modify); /* this code pulled out to a subroutine cuz transmit can be started from XIO_CONTROL too */ - break; + /* enter transmit mode. Causes line turnaround. Resets frame to 8 bits. */ + /* (may cause syncing, may involve a fixed timeout?) */ + sca_frame = 8; + sca_start_transmit(iocc_addr, modify); /* this code pulled out to a subroutine cuz transmit can be started from XIO_CONTROL too */ + break; - case XIO_INITR: /* ***** XIO_INITR - put SCA in receive mode */ + case XIO_INITR: /* ***** XIO_INITR - put SCA in receive mode */ #if (DEBUG_SCA & DEBUG_SCA_XIO_INITR) - printf("SCA INITR addr %04x mod %02x\n", iocc_addr, modify); + printf("SCA INITR addr %04x mod %02x\n", iocc_addr, modify); #endif - sca_flush(); + sca_flush(); - sca_nrcvd = sca_rcvptr = 0; /* discard any data previously read! */ - sca_nsyns = 0; /* reset SYN suppression */ + sca_nrcvd = sca_rcvptr = 0; /* discard any data previously read! */ + sca_nsyns = 0; /* reset SYN suppression */ - /* enter receive mode. Causes line turnaround (e.g. resets to 8 bit frame). Modifier bits are used here too */ - /* (may cause syncing, may involve a fixed timeout?) */ + /* enter receive mode. Causes line turnaround (e.g. resets to 8 bit frame). Modifier bits are used here too */ + /* (may cause syncing, may involve a fixed timeout?) */ - sca_frame = 8; - if (! in_receive_state()) - sca_state = SCA_STATE_TURN_RECEIVE; /* begin line turnaround */ - else - sca_state = SCA_STATE_RECEIVE_SYNC; + sca_frame = 8; + if (! in_receive_state()) + sca_state = SCA_STATE_TURN_RECEIVE; /* begin line turnaround */ + else + sca_state = SCA_STATE_RECEIVE_SYNC; - SETBIT(sca_dsw, SCA_DSW_BUSY); /* SCA is now busy, in receive mode */ + SETBIT(sca_dsw, SCA_DSW_BUSY); /* SCA is now busy, in receive mode */ - if (in_bsc_mode()) /* in BSC mode, start the 3 second timer when we enter receive mode */ - sca_start_timer(TIMER_3S, sim_os_msec()); + if (in_bsc_mode()) /* in BSC mode, start the 3 second timer when we enter receive mode */ + sca_start_timer(TIMER_3S, sim_os_msec()); - break; + break; - case XIO_SENSE_DEV: /* ***** XIO_SENSE_DEV - read device status word */ + case XIO_SENSE_DEV: /* ***** XIO_SENSE_DEV - read device status word */ #if (DEBUG_SCA & DEBUG_SCA_XIO_SENSE_DEV) - printf("SCA SNS mod %02x dsw %04x\n", modify, sca_dsw); + printf("SCA SNS mod %02x dsw %04x\n", modify, sca_dsw); #endif - ACC = sca_dsw; /* return DSW in accumulator */ + ACC = sca_dsw; /* return DSW in accumulator */ - if (modify & 0x01) { /* bit 15: reset interrupts */ + if (modify & 0x01) { /* bit 15: reset interrupts */ #if (DEBUG_SCA & DEBUG_SCA_XIO_SENSE_DEV) - printf("(reset interrupts)\n"); + printf("(reset interrupts)\n"); #endif - CLRBIT(sca_dsw, SCA_DSW_READ_RESPONSE | SCA_DSW_WRITE_RESPONSE | SCA_DSW_CHECK | SCA_DSW_TIMEOUT | SCA_DSW_AUTOANSWER_REQUEST); - CLRBIT(ILSW[1], ILSW_1_SCA); - } + CLRBIT(sca_dsw, SCA_DSW_READ_RESPONSE | SCA_DSW_WRITE_RESPONSE | SCA_DSW_CHECK | SCA_DSW_TIMEOUT | SCA_DSW_AUTOANSWER_REQUEST); + CLRBIT(ILSW[1], ILSW_1_SCA); + } - if (modify & 0x02) { /* bit 14: restart running timers */ + if (modify & 0x02) { /* bit 14: restart running timers */ #if (DEBUG_SCA & (DEBUG_SCA_XIO_SENSE_DEV|DEBUG_SCA_TIMERS)) - printf("(restart timers)\n"); + printf("(restart timers)\n"); #endif - msec_now = sim_os_msec(); /* restart "any running timer?" All three, really? */ - for (i = 0; i < 3; i++) - if (sca_timer_state[i] == SCA_TIMER_RUNNING || sca_timer_state[i] == SCA_TIMER_TIMEDOUT) - sca_start_timer(i, msec_now); - } - break; + msec_now = sim_os_msec(); /* restart "any running timer?" All three, really? */ + for (i = 0; i < 3; i++) + if (sca_timer_state[i] == SCA_TIMER_RUNNING || sca_timer_state[i] == SCA_TIMER_TIMEDOUT) + sca_start_timer(i, msec_now); + } + break; - default: - sprintf(msg, "Invalid SCA XIO function %x", func); - xio_error(msg); - } + default: + sprintf(msg, "Invalid SCA XIO function %x", func); + xio_error(msg); + } } diff --git a/Ibm1130/ibm1130_stddev.c b/Ibm1130/ibm1130_stddev.c index d9549b17..33e8b697 100644 --- a/Ibm1130/ibm1130_stddev.c +++ b/Ibm1130/ibm1130_stddev.c @@ -9,11 +9,11 @@ 2004.10.22 - Removed stub for xio_1134_papertape as it's now a supported device 2003.11.23 - Fixed bug in new routine "quotefix" that made sim crash - for all non-Windows builds :( + for all non-Windows builds :( 2003.06.15 - added output translation code to accomodate APL font - added input translation feature to assist emulation of 1130 console keyboard for APL - changes to console input and output IO emulation, fixed bugs exposed by APL interpreter + added input translation feature to assist emulation of 1130 console keyboard for APL + changes to console input and output IO emulation, fixed bugs exposed by APL interpreter 2002.09.13 - pulled 1132 printer out of this file into ibm1130_prt.c @@ -33,9 +33,9 @@ * modern APL fonts have separate character codes for the complex characters. * To have APL\1130 output appear correctly, we have to do three things: * - * use simh's telnet feature to connect to the 1130 console stream - * have the telnet program use an APL font - * detect combinations of overstruck symbols, and generate the approrpiate alternate codes. + * use simh's telnet feature to connect to the 1130 console stream + * have the telnet program use an APL font + * detect combinations of overstruck symbols, and generate the approrpiate alternate codes. * * There is a built-in table of font mappings and overstrike mappings, for the APLPLUS.TTF * truetype font widely available on the Internet. An font descriptor file can be used @@ -43,20 +43,20 @@ * * The APL font codes and overstrike mapping can be enabled with the simh command * - * set tto apl + * set tto apl * * and disabled with * - * set tto ascii (this is the default) + * set tto ascii (this is the default) * * APL also uses the red and black ribbon selection. The emulator will output * ansi red/black foreground commands with the setting * - * set tto ansi + * set tto ansi * * The codes can be disabled with * - * set tto noansi (this is the default) + * set tto noansi (this is the default) * * Finally, when APL mode is active, the emulator does some input key translations * to let the standard ASCII keyboard more closely match the physical layout of the @@ -66,20 +66,20 @@ * * The translations are: * FROM - * ASCII Position on keyboard To 1130 Key APL interpretation - * ------------------------------------ -------------------------------- - * [ (key to right of P) \r Enter left arrow - * ; (1st key to right of L) \b Backspace [ - * ' (2nd key to right of L) ^U Erase Fld ] - * 2 (key above Q) @ @ up shift - * 3 (key above W) % % up right shift - * 4 (key above E) * * + - * 5 (key above R) < < multiply - * 8 (key above U) - - Return - * 9 (key above I) / / Backspace - * - (key above P) ^Q INT REQ ATTN - * Enter - - Return - * backsp / / Backspace + * ASCII Position on keyboard To 1130 Key APL interpretation + * ------------------------------------ -------------------------------- + * [ (key to right of P) \r Enter left arrow + * ; (1st key to right of L) \b Backspace [ + * ' (2nd key to right of L) ^U Erase Fld ] + * 2 (key above Q) @ @ up shift + * 3 (key above W) % % up right shift + * 4 (key above E) * * + + * 5 (key above R) < < multiply + * 8 (key above U) - - Return + * 9 (key above I) / / Backspace + * - (key above P) ^Q INT REQ ATTN + * Enter - - Return + * backsp / / Backspace */ #include "ibm1130_defs.h" @@ -97,37 +97,37 @@ static void badio (const char *dev) */ } -void xio_1231_optical (int32 addr, int32 func, int32 modify) {badio("optical mark");} -void xio_system7 (int32 addr, int32 func, int32 modify) {badio("System 7");} +void xio_1231_optical (int32 addr, int32 func, int32 modify) {badio("optical mark");} +void xio_system7 (int32 addr, int32 func, int32 modify) {badio("System 7");} /* ---------------------------------------------------------------------------- */ -#define MAX_OUTPUT_COLUMNS 100 /* width of 1130 console printer */ -#define MAX_OS_CHARS 4 /* maximum number of overstruck characters that can be mapped */ -#define MAX_OS_MAPPINGS 100 /* maximum number of overstrike mappings */ +#define MAX_OUTPUT_COLUMNS 100 /* width of 1130 console printer */ +#define MAX_OS_CHARS 4 /* maximum number of overstruck characters that can be mapped */ +#define MAX_OS_MAPPINGS 100 /* maximum number of overstrike mappings */ -typedef struct tag_os_map { /* os_map = overstrike mapping */ - int ch; /* ch = output character */ - int nin; /* nin = number of overstruck characters */ - unsigned char inlist[MAX_OS_CHARS]; /* inlist = overstruck ASCII characters, sorted. NOT NULL TERMINATED */ +typedef struct tag_os_map { /* os_map = overstrike mapping */ + int ch; /* ch = output character */ + int nin; /* nin = number of overstruck characters */ + unsigned char inlist[MAX_OS_CHARS]; /* inlist = overstruck ASCII characters, sorted. NOT NULL TERMINATED */ } OS_MAP; extern int cgi; -static int32 tti_dsw = 0; /* device status words */ +static int32 tti_dsw = 0; /* device status words */ static int32 tto_dsw = 0; int32 con_dsw = 0; - -static unsigned char conout_map[256]; /* 1130 console code to ASCII translation. 0 = undefined, 0xFF = IGNR_ = no output */ -static unsigned char conin_map[256]; /* input mapping */ -static int curcol = 0; /* current typewriter element column, leftmost = 0 */ -static int maxcol = 0; /* highest curcol seen in this output line */ -static unsigned char black_ribbon[30]; /* output escape sequence for black ribbon shift */ -static unsigned char red_ribbon[30]; /* output escape sequence for red ribbon shift */ + +static unsigned char conout_map[256]; /* 1130 console code to ASCII translation. 0 = undefined, 0xFF = IGNR_ = no output */ +static unsigned char conin_map[256]; /* input mapping */ +static int curcol = 0; /* current typewriter element column, leftmost = 0 */ +static int maxcol = 0; /* highest curcol seen in this output line */ +static unsigned char black_ribbon[30]; /* output escape sequence for black ribbon shift */ +static unsigned char red_ribbon[30]; /* output escape sequence for red ribbon shift */ -static OS_MAP os_buf[MAX_OUTPUT_COLUMNS]; /* current typewriter output line, holds character struck in each column */ -static OS_MAP os_map[MAX_OS_MAPPINGS]; /* overstrike mapping entries */ -static int n_os_mappings; /* number of overstrike mappings */ +static OS_MAP os_buf[MAX_OUTPUT_COLUMNS]; /* current typewriter output line, holds character struck in each column */ +static OS_MAP os_map[MAX_OS_MAPPINGS]; /* overstrike mapping entries */ +static int n_os_mappings; /* number of overstrike mappings */ static t_stat tti_svc(UNIT *uptr); static t_stat tto_svc(UNIT *uptr); @@ -141,304 +141,304 @@ static void set_conout_mapping(int32 flags); static t_stat validate_conout_mapping(UNIT *uptr, int32 match, CONST char *cvptr, void *desc); static void set_default_mapping(int32 flags); static void finish_conout_mapping(int32 flags); -static void strsort (int n, unsigned char *s); /* sorts an array of n characters */ -static int os_map_comp (OS_MAP *a, OS_MAP *b); /* compares two mapping entries */ -static t_stat font_cmd(int32 flag, CONST char *cptr); /* handles font command */ -static void read_map_file(FILE *fd); /* reads a font map file */ +static void strsort (int n, unsigned char *s); /* sorts an array of n characters */ +static int os_map_comp (OS_MAP *a, OS_MAP *b); /* compares two mapping entries */ +static t_stat font_cmd(int32 flag, CONST char *cptr); /* handles font command */ +static void read_map_file(FILE *fd); /* reads a font map file */ static t_bool str_match(const char *str, const char *keyword);/* keyword/string comparison */ -static const char * handle_map_ansi_definition(char **pc); /* input line parsers for map file sections */ +static const char * handle_map_ansi_definition(char **pc); /* input line parsers for map file sections */ static const char * handle_map_input_definition(char **pc); static const char * handle_map_output_definition(char **pc); static const char * handle_map_overstrike_definition(char **pc); -#define UNIT_V_CSET (UNIT_V_UF + 0) /* user flag: character set */ -#define UNIT_V_LOCKED (UNIT_V_UF + 2) /* user flag: keyboard locked */ -#define UNIT_V_ANSI (UNIT_V_UF + 3) +#define UNIT_V_CSET (UNIT_V_UF + 0) /* user flag: character set */ +#define UNIT_V_LOCKED (UNIT_V_UF + 2) /* user flag: keyboard locked */ +#define UNIT_V_ANSI (UNIT_V_UF + 3) -#define CSET_ASCII (0u << UNIT_V_CSET) -#define CSET_1130 (1u << UNIT_V_CSET) -#define CSET_APL (2u << UNIT_V_CSET) -#define CSET_MASK (3u << UNIT_V_CSET) -#define ENABLE_ANSI (1u << UNIT_V_ANSI) +#define CSET_ASCII (0u << UNIT_V_CSET) +#define CSET_1130 (1u << UNIT_V_CSET) +#define CSET_APL (2u << UNIT_V_CSET) +#define CSET_MASK (3u << UNIT_V_CSET) +#define ENABLE_ANSI (1u << UNIT_V_ANSI) -#define KEYBOARD_LOCKED (1u << UNIT_V_LOCKED) +#define KEYBOARD_LOCKED (1u << UNIT_V_LOCKED) -#define IRQ_KEY 0x11 /* ctrl-Q */ -#define PROGRAM_STOP_KEY 0x10 /* ctrl-P */ +#define IRQ_KEY 0x11 /* ctrl-Q */ +#define PROGRAM_STOP_KEY 0x10 /* ctrl-P */ -#include "ibm1130_conout.h" /* conout_to_ascii table */ -#include "ibm1130_conin.h" /* ascii_to_conin table */ +#include "ibm1130_conout.h" /* conout_to_ascii table */ +#include "ibm1130_conin.h" /* ascii_to_conin table */ /* TTI data structures - tti_dev TTI device descriptor - tti_unit TTI unit descriptor - tti_reg TTI register list + tti_dev TTI device descriptor + tti_unit TTI unit descriptor + tti_reg TTI register list */ UNIT tti_unit = { UDATA (&tti_svc, 0, 0), KBD_POLL_WAIT }; REG tti_reg[] = { - { ORDATA (BUF, tti_unit.buf, 16) }, - { ORDATA (DSW, tti_dsw, 16) }, - { DRDATA (POS, tti_unit.pos, 31), PV_LEFT }, - { DRDATA (STIME, tti_unit.wait, 24), REG_NZ + PV_LEFT }, - { NULL } }; + { ORDATA (BUF, tti_unit.buf, 16) }, + { ORDATA (DSW, tti_dsw, 16) }, + { DRDATA (POS, tti_unit.pos, 31), PV_LEFT }, + { DRDATA (STIME, tti_unit.wait, 24), REG_NZ + PV_LEFT }, + { NULL } }; MTAB tti_mod[] = { - { CSET_MASK, CSET_ASCII, "ASCII", "ASCII", NULL}, - { CSET_MASK, CSET_1130, "1130", "1130", NULL}, - { 0 } }; + { CSET_MASK, CSET_ASCII, "ASCII", "ASCII", NULL}, + { CSET_MASK, CSET_1130, "1130", "1130", NULL}, + { 0 } }; DEVICE tti_dev = { - "KEYBOARD", &tti_unit, tti_reg, tti_mod, - 1, 10, 31, 1, 8, 8, - NULL, NULL, &tti_reset, - NULL, basic_attach, NULL }; + "KEYBOARD", &tti_unit, tti_reg, tti_mod, + 1, 10, 31, 1, 8, 8, + NULL, NULL, &tti_reset, + NULL, basic_attach, NULL }; /* TTO data structures - tto_dev TTO device descriptor - tto_unit TTO unit descriptor - tto_reg TTO register list + tto_dev TTO device descriptor + tto_unit TTO unit descriptor + tto_reg TTO register list */ - /* 14-Nov-03 -- the wait time was SERIAL_OUT_WAIT, but recent versions of SIMH reduced - * this to 100, and wouldn't you know it, APL\1130 has about 120 instructions between the XIO WRITE - * to the console and the associated WAIT. - */ + /* 14-Nov-03 -- the wait time was SERIAL_OUT_WAIT, but recent versions of SIMH reduced + * this to 100, and wouldn't you know it, APL\1130 has about 120 instructions between the XIO WRITE + * to the console and the associated WAIT. + */ UNIT tto_unit = { UDATA (&tto_svc, 0, 0), 200 }; REG tto_reg[] = { - { ORDATA (BUF, tto_unit.buf, 16) }, - { ORDATA (DSW, tto_dsw, 16) }, - { DRDATA (POS, tto_unit.pos, 31), PV_LEFT }, - { DRDATA (STIME, tto_unit.wait, 24), PV_LEFT }, - { NULL } }; + { ORDATA (BUF, tto_unit.buf, 16) }, + { ORDATA (DSW, tto_dsw, 16) }, + { DRDATA (POS, tto_unit.pos, 31), PV_LEFT }, + { DRDATA (STIME, tto_unit.wait, 24), PV_LEFT }, + { NULL } }; MTAB tto_mod[] = { - { CSET_MASK, CSET_ASCII, "ASCII", "ASCII", validate_conout_mapping, NULL, NULL}, - { CSET_MASK, CSET_1130, "1130", "1130", validate_conout_mapping, NULL, NULL}, - { CSET_MASK, CSET_APL, "APL", "APL", validate_conout_mapping, NULL, NULL}, - { ENABLE_ANSI,0, "NOANSI", "NOANSI", NULL}, - { ENABLE_ANSI,ENABLE_ANSI, "ANSI", "ANSI", NULL}, - { 0 } }; + { CSET_MASK, CSET_ASCII, "ASCII", "ASCII", validate_conout_mapping, NULL, NULL}, + { CSET_MASK, CSET_1130, "1130", "1130", validate_conout_mapping, NULL, NULL}, + { CSET_MASK, CSET_APL, "APL", "APL", validate_conout_mapping, NULL, NULL}, + { ENABLE_ANSI,0, "NOANSI", "NOANSI", NULL}, + { ENABLE_ANSI,ENABLE_ANSI, "ANSI", "ANSI", NULL}, + { 0 } }; DEVICE tto_dev = { - "TTO", &tto_unit, tto_reg, tto_mod, - 1, 10, 31, 1, 8, 8, - NULL, NULL, &tto_reset, - NULL, basic_attach, NULL }; + "TTO", &tto_unit, tto_reg, tto_mod, + 1, 10, 31, 1, 8, 8, + NULL, NULL, &tto_reset, + NULL, basic_attach, NULL }; /* Terminal input routines - tti_svc process event (character ready) - tti_reset process reset - tto_svc process event (print character) - tto_reset process reset + tti_svc process event (character ready) + tti_reset process reset + tto_svc process event (print character) + tto_reset process reset */ -#define TT_DSW_PRINTER_RESPONSE 0x8000 -#define TT_DSW_KEYBOARD_RESPONSE 0x4000 -#define TT_DSW_INTERRUPT_REQUEST 0x2000 -#define TT_DSW_KEYBOARD_CONSOLE 0x1000 -#define TT_DSW_PRINTER_BUSY 0x0800 -#define TT_DSW_PRINTER_NOT_READY 0x0400 -#define TT_DSW_KEYBOARD_BUSY 0x0200 +#define TT_DSW_PRINTER_RESPONSE 0x8000 +#define TT_DSW_KEYBOARD_RESPONSE 0x4000 +#define TT_DSW_INTERRUPT_REQUEST 0x2000 +#define TT_DSW_KEYBOARD_CONSOLE 0x1000 +#define TT_DSW_PRINTER_BUSY 0x0800 +#define TT_DSW_PRINTER_NOT_READY 0x0400 +#define TT_DSW_KEYBOARD_BUSY 0x0200 void xio_1131_console (int32 iocc_addr, int32 func, int32 modify) { - int ch; - char msg[80]; + int ch; + char msg[80]; - switch (func) { - case XIO_CONTROL: - SETBIT(tti_dsw, TT_DSW_KEYBOARD_BUSY); /* select and unlock the keyboard */ - keyboard_selected(TRUE); - CLRBIT(tti_unit.flags, KEYBOARD_LOCKED); - tti_unit.buf = 0; /* no key character yet */ - break; + switch (func) { + case XIO_CONTROL: + SETBIT(tti_dsw, TT_DSW_KEYBOARD_BUSY); /* select and unlock the keyboard */ + keyboard_selected(TRUE); + CLRBIT(tti_unit.flags, KEYBOARD_LOCKED); + tti_unit.buf = 0; /* no key character yet */ + break; - case XIO_READ: - WriteW(iocc_addr, tti_unit.buf); /* return keycode */ - CLRBIT(tti_dsw, TT_DSW_KEYBOARD_BUSY); /* this ends selected mode */ - keyboard_selected(FALSE); - SETBIT(tti_unit.flags, KEYBOARD_LOCKED); /* keyboard is locked when not selected */ - tti_unit.buf = 0; /* subsequent reads will return zero */ - break; + case XIO_READ: + WriteW(iocc_addr, tti_unit.buf); /* return keycode */ + CLRBIT(tti_dsw, TT_DSW_KEYBOARD_BUSY); /* this ends selected mode */ + keyboard_selected(FALSE); + SETBIT(tti_unit.flags, KEYBOARD_LOCKED); /* keyboard is locked when not selected */ + tti_unit.buf = 0; /* subsequent reads will return zero */ + break; - case XIO_WRITE: - ch = (ReadW(iocc_addr) >> 8) & 0xFF; /* get character to write */ - tto_unit.buf = emit_conout_character(ch); /* output character and save write status */ + case XIO_WRITE: + ch = (ReadW(iocc_addr) >> 8) & 0xFF; /* get character to write */ + tto_unit.buf = emit_conout_character(ch); /* output character and save write status */ -/* fprintf(stderr, "[CONOUT] %02x\n", ch); */ +/* fprintf(stderr, "[CONOUT] %02x\n", ch); */ - SETBIT(tto_dsw, TT_DSW_PRINTER_BUSY); - sim_activate(&tto_unit, tto_unit.wait); /* schedule interrupt */ - break; + SETBIT(tto_dsw, TT_DSW_PRINTER_BUSY); + sim_activate(&tto_unit, tto_unit.wait); /* schedule interrupt */ + break; - case XIO_SENSE_DEV: - ACC = tto_dsw | tti_dsw; - if (modify & 0x01) { /* reset interrupts */ - CLRBIT(tto_dsw, TT_DSW_PRINTER_RESPONSE); - CLRBIT(tti_dsw, TT_DSW_KEYBOARD_RESPONSE); - CLRBIT(tti_dsw, TT_DSW_INTERRUPT_REQUEST); - CLRBIT(ILSW[4], ILSW_4_CONSOLE); - } - break; + case XIO_SENSE_DEV: + ACC = tto_dsw | tti_dsw; + if (modify & 0x01) { /* reset interrupts */ + CLRBIT(tto_dsw, TT_DSW_PRINTER_RESPONSE); + CLRBIT(tti_dsw, TT_DSW_KEYBOARD_RESPONSE); + CLRBIT(tti_dsw, TT_DSW_INTERRUPT_REQUEST); + CLRBIT(ILSW[4], ILSW_4_CONSOLE); + } + break; - default: - sprintf(msg, "Invalid console XIO function %x", func); - xio_error(msg); - } + default: + sprintf(msg, "Invalid console XIO function %x", func); + xio_error(msg); + } -/* fprintf(stderr, "After XIO %04x %04x\n", tti_dsw, tto_dsw); */ +/* fprintf(stderr, "After XIO %04x %04x\n", tti_dsw, tto_dsw); */ } /* emit_conout_character - write character with 1130 console code 'ch' */ static t_stat emit_conout_character (int ch) { - t_stat status; + t_stat status; #ifdef DEBUG_CONSOLE - printf("{%02x}", ch); + printf("{%02x}", ch); #endif - if ((tto_unit.flags & CSET_MASK) == CSET_1130) /* 1130 (binary) mode, write the raw 8-bit value */ - return sim_putchar(ch); + if ((tto_unit.flags & CSET_MASK) == CSET_1130) /* 1130 (binary) mode, write the raw 8-bit value */ + return sim_putchar(ch); - if (ch & COUT_IS_CTRL) { - /* red/black shift can be combined with another control */ - /* if present, emit the color shift characters alone */ + if (ch & COUT_IS_CTRL) { + /* red/black shift can be combined with another control */ + /* if present, emit the color shift characters alone */ - if (ch & COUT_CTRL_BLACK) { - if ((status = map_conout_character(COUT_IS_CTRL|COUT_CTRL_BLACK)) != SCPE_OK) - return status; - } - else if (ch & COUT_CTRL_RED) { - if ((status = map_conout_character(COUT_IS_CTRL|COUT_CTRL_RED)) != SCPE_OK) - return status; - } + if (ch & COUT_CTRL_BLACK) { + if ((status = map_conout_character(COUT_IS_CTRL|COUT_CTRL_BLACK)) != SCPE_OK) + return status; + } + else if (ch & COUT_CTRL_RED) { + if ((status = map_conout_character(COUT_IS_CTRL|COUT_CTRL_RED)) != SCPE_OK) + return status; + } - ch &= ~(COUT_CTRL_BLACK|COUT_CTRL_RED); /* remove the ribbon shift bits */ + ch &= ~(COUT_CTRL_BLACK|COUT_CTRL_RED); /* remove the ribbon shift bits */ - if (ch & ~COUT_IS_CTRL) { /* if another control remains, emit it */ - if ((status = map_conout_character(ch)) != SCPE_OK) - return status; - } + if (ch & ~COUT_IS_CTRL) { /* if another control remains, emit it */ + if ((status = map_conout_character(ch)) != SCPE_OK) + return status; + } - return SCPE_OK; - } + return SCPE_OK; + } - return map_conout_character(ch); + return map_conout_character(ch); } -static void SendBeep (void) /* notify user keyboard was locked or key was bad */ +static void SendBeep (void) /* notify user keyboard was locked or key was bad */ { - sim_putchar(7); + sim_putchar(7); } /* tti_svc - keyboard polling (never stops) */ static t_stat tti_svc (UNIT *uptr) { - int32 temp; + int32 temp; - if (cgi) /* if running in CGI mode, no keyboard and no keyboard polling! */ - return SCPE_OK; - /* otherwise, so ^E can interrupt the simulator, */ - sim_activate(&tti_unit, tti_unit.wait); /* always continue polling keyboard */ + if (cgi) /* if running in CGI mode, no keyboard and no keyboard polling! */ + return SCPE_OK; + /* otherwise, so ^E can interrupt the simulator, */ + sim_activate(&tti_unit, tti_unit.wait); /* always continue polling keyboard */ - assert(sim_clock_queue != QUEUE_LIST_END); + assert(sim_clock_queue != QUEUE_LIST_END); - temp = sim_poll_kbd(); + temp = sim_poll_kbd(); - if (temp < SCPE_KFLAG) - return temp; /* no char or error? */ + if (temp < SCPE_KFLAG) + return temp; /* no char or error? */ - temp &= 0xFF; /* remove SCPE_KFLAG */ + temp &= 0xFF; /* remove SCPE_KFLAG */ - if ((tti_unit.flags & CSET_MASK) == CSET_ASCII) - temp = conin_map[temp] & 0xFF; /* perform input translation */ + if ((tti_unit.flags & CSET_MASK) == CSET_ASCII) + temp = conin_map[temp] & 0xFF; /* perform input translation */ - if (temp == IRQ_KEY) { /* INT REQ (interrupt request) key -- process this even if no keyboard input request pending */ - SETBIT(tti_dsw, TT_DSW_INTERRUPT_REQUEST); /* queue interrupt */ - SETBIT(ILSW[4], ILSW_4_CONSOLE); - calc_ints(); + if (temp == IRQ_KEY) { /* INT REQ (interrupt request) key -- process this even if no keyboard input request pending */ + SETBIT(tti_dsw, TT_DSW_INTERRUPT_REQUEST); /* queue interrupt */ + SETBIT(ILSW[4], ILSW_4_CONSOLE); + calc_ints(); - CLRBIT(tti_unit.flags, KEYBOARD_LOCKED); /* keyboard restore, according to func. char. manual */ + CLRBIT(tti_unit.flags, KEYBOARD_LOCKED); /* keyboard restore, according to func. char. manual */ #ifdef DEBUG_CONSOLE - printf("[*IRQ*]"); + printf("[*IRQ*]"); #endif - tti_unit.buf = 0; /* subsequent reads need to return 0 (required by APL\1130) */ - return SCPE_OK; - } + tti_unit.buf = 0; /* subsequent reads need to return 0 (required by APL\1130) */ + return SCPE_OK; + } - if (temp == PROGRAM_STOP_KEY) { /* simulate the program stop button */ - SETBIT(con_dsw, CPU_DSW_PROGRAM_STOP); - SETBIT(ILSW[5], ILSW_5_INT_RUN_PROGRAM_STOP); - calc_ints(); + if (temp == PROGRAM_STOP_KEY) { /* simulate the program stop button */ + SETBIT(con_dsw, CPU_DSW_PROGRAM_STOP); + SETBIT(ILSW[5], ILSW_5_INT_RUN_PROGRAM_STOP); + calc_ints(); #ifdef DEBUG_CONSOLE - printf("[*PSTOP*]"); + printf("[*PSTOP*]"); #endif - return SCPE_OK; - } - // keyboard is locked or no active input request? - if ((tti_unit.flags & KEYBOARD_LOCKED) || ! (tti_dsw & TT_DSW_KEYBOARD_BUSY)) { - SendBeep(); - calc_ints(); - return SCPE_OK; - } + return SCPE_OK; + } + // keyboard is locked or no active input request? + if ((tti_unit.flags & KEYBOARD_LOCKED) || ! (tti_dsw & TT_DSW_KEYBOARD_BUSY)) { + SendBeep(); + calc_ints(); + return SCPE_OK; + } - if ((tti_unit.flags & CSET_MASK) == CSET_ASCII) - temp = ascii_to_conin[temp]; + if ((tti_unit.flags & CSET_MASK) == CSET_ASCII) + temp = ascii_to_conin[temp]; - if (temp == 0) { /* ignore invalid characters (no mapping to 1130 input code) */ - SendBeep(); - calc_ints(); - return SCPE_OK; - } + if (temp == 0) { /* ignore invalid characters (no mapping to 1130 input code) */ + SendBeep(); + calc_ints(); + return SCPE_OK; + } - tti_unit.buf = temp & 0xFFFE; /* save keystroke except last bit (not defined) */ - tti_unit.pos = tti_unit.pos + 1; /* but it lets us distinguish 0 from no punch ' ' */ + tti_unit.buf = temp & 0xFFFE; /* save keystroke except last bit (not defined) */ + tti_unit.pos = tti_unit.pos + 1; /* but it lets us distinguish 0 from no punch ' ' */ #ifdef DEBUG_CONSOLE - printf("[%04x]", tti_unit.buf & 0xFFFF); + printf("[%04x]", tti_unit.buf & 0xFFFF); #endif - SETBIT(tti_unit.flags, KEYBOARD_LOCKED); /* prevent further keystrokes */ + SETBIT(tti_unit.flags, KEYBOARD_LOCKED); /* prevent further keystrokes */ - SETBIT(tti_dsw, TT_DSW_KEYBOARD_RESPONSE); /* queue interrupt */ - SETBIT(ILSW[4], ILSW_4_CONSOLE); - calc_ints(); + SETBIT(tti_dsw, TT_DSW_KEYBOARD_RESPONSE); /* queue interrupt */ + SETBIT(ILSW[4], ILSW_4_CONSOLE); + calc_ints(); -/* fprintf(stderr, "TTI interrupt svc SET %04x %04x\n", tti_dsw, tto_dsw); */ +/* fprintf(stderr, "TTI interrupt svc SET %04x %04x\n", tti_dsw, tto_dsw); */ - return SCPE_OK; + return SCPE_OK; } static t_stat tti_reset (DEVICE *dptr) { - tti_unit.buf = 0; - tti_dsw = 0; + tti_unit.buf = 0; + tti_dsw = 0; - CLRBIT(ILSW[4], ILSW_4_CONSOLE); - calc_ints(); - keyboard_selected(FALSE); + CLRBIT(ILSW[4], ILSW_4_CONSOLE); + calc_ints(); + keyboard_selected(FALSE); - SETBIT(tti_unit.flags, KEYBOARD_LOCKED); + SETBIT(tti_unit.flags, KEYBOARD_LOCKED); - if (cgi) - sim_cancel(&tti_unit); /* in cgi mode, never poll keyboard */ - else - sim_activate(&tti_unit, tti_unit.wait); /* otherwise, always poll keyboard */ + if (cgi) + sim_cancel(&tti_unit); /* in cgi mode, never poll keyboard */ + else + sim_activate(&tti_unit, tti_unit.wait); /* otherwise, always poll keyboard */ - return SCPE_OK; + return SCPE_OK; } /* basic_attach - fix quotes in filename, then call standard unit attach routine */ @@ -447,7 +447,7 @@ t_stat basic_attach (UNIT *uptr, CONST char *cptr) { char gbuf[2*CBUFSIZE]; - return attach_unit(uptr, quotefix(cptr, gbuf)); /* fix quotes in filenames & attach */ + return attach_unit(uptr, quotefix(cptr, gbuf)); /* fix quotes in filenames & attach */ } /* quotefix - strip off quotes around filename, if present */ @@ -472,85 +472,85 @@ CONST char * quotefix (CONST char *cptr, char * buf) return cptr; /* return pointer to cleaned-up name */ } -t_bool keyboard_is_busy (void) /* return TRUE if keyboard is not expecting a character */ +t_bool keyboard_is_busy (void) /* return TRUE if keyboard is not expecting a character */ { - return (tti_dsw & TT_DSW_KEYBOARD_BUSY); + return (tti_dsw & TT_DSW_KEYBOARD_BUSY); } static t_stat tto_svc (UNIT *uptr) { - CLRBIT(tto_dsw, TT_DSW_PRINTER_BUSY); - SETBIT(tto_dsw, TT_DSW_PRINTER_RESPONSE); + CLRBIT(tto_dsw, TT_DSW_PRINTER_BUSY); + SETBIT(tto_dsw, TT_DSW_PRINTER_RESPONSE); - SETBIT(ILSW[4], ILSW_4_CONSOLE); - calc_ints(); + SETBIT(ILSW[4], ILSW_4_CONSOLE); + calc_ints(); -/* fprintf(stderr, "TTO interrupt svc SET %04x %04x\n", tti_dsw, tto_dsw); */ +/* fprintf(stderr, "TTO interrupt svc SET %04x %04x\n", tti_dsw, tto_dsw); */ - return (t_stat) tto_unit.buf; /* return status saved during output conversion */ + return (t_stat) tto_unit.buf; /* return status saved during output conversion */ } static t_stat tto_reset (DEVICE *dptr) { - tto_unit.buf = 0; - tto_dsw = 0; + tto_unit.buf = 0; + tto_dsw = 0; - CLRBIT(ILSW[4], ILSW_4_CONSOLE); - calc_ints(); + CLRBIT(ILSW[4], ILSW_4_CONSOLE); + calc_ints(); - sim_cancel(&tto_unit); /* deactivate unit */ + sim_cancel(&tto_unit); /* deactivate unit */ - set_conout_mapping(tto_unit.flags); /* initialize the overstrike mappings */ - /* register the font-mapping command */ - register_cmd("FONT", font_cmd, 0, "font MAPFILE use font mapping definitions in MAPFILE\n"); + set_conout_mapping(tto_unit.flags); /* initialize the overstrike mappings */ + /* register the font-mapping command */ + register_cmd("FONT", font_cmd, 0, "font MAPFILE use font mapping definitions in MAPFILE\n"); - return SCPE_OK; + return SCPE_OK; } #ifdef _MSC_VER -# pragma warning(disable:4245) /* disable int->char demotion warning caused by characters with high-bit set */ +# pragma warning(disable:4245) /* disable int->char demotion warning caused by characters with high-bit set */ #endif #ifdef __SUNPRO_C -# pragma error_messages (off, E_INIT_DOES_NOT_FIT) /* disable int->char demotion warning caused by characters with high-bit set */ +# pragma error_messages (off, E_INIT_DOES_NOT_FIT) /* disable int->char demotion warning caused by characters with high-bit set */ #endif -static struct { /* default input mapping for APL */ - unsigned char in; - unsigned char out; +static struct { /* default input mapping for APL */ + unsigned char in; + unsigned char out; } conin_to_APL[] = -{ /* these map input keys to those in like positions on 1130 keyboard */ - {'[', '\r'}, /* enter (EOF) is APL left arrow */ - {';', '\b'}, /* backspace is APL [ */ - {'\'', '\x15'}, /* ctrl-U, erase field, is APL ]*/ - {'2', '@'}, /* APL upshift */ - {'3', '%'}, /* APL rightshift */ - {'4', '*'}, /* APL + and - */ - {'5', '<'}, /* APL x and divide */ - {'8', '-'}, /* APL return */ - {'9', '/'}, /* APL backspace */ - {'-', IRQ_KEY}, /* ctrl-q (INT REQ), APL ATTN */ - {'\r', '-'}, /* APL return */ - {'\b', '/'} /* APL backspace */ +{ /* these map input keys to those in like positions on 1130 keyboard */ + {'[', '\r'}, /* enter (EOF) is APL left arrow */ + {';', '\b'}, /* backspace is APL [ */ + {'\'', '\x15'}, /* ctrl-U, erase field, is APL ]*/ + {'2', '@'}, /* APL upshift */ + {'3', '%'}, /* APL rightshift */ + {'4', '*'}, /* APL + and - */ + {'5', '<'}, /* APL x and divide */ + {'8', '-'}, /* APL return */ + {'9', '/'}, /* APL backspace */ + {'-', IRQ_KEY}, /* ctrl-q (INT REQ), APL ATTN */ + {'\r', '-'}, /* APL return */ + {'\b', '/'} /* APL backspace */ }; #define NCONIN_TO_APL (sizeof(conin_to_APL)/sizeof(conin_to_APL[0])) -static struct { /* default output mapping for APLPLUS font */ - unsigned char in; - unsigned char out; +static struct { /* default output mapping for APLPLUS font */ + unsigned char in; + unsigned char out; } conout_to_APL[] = { - {'\x01', IGNR_}, /* controls */ + {'\x01', IGNR_}, /* controls */ {'\x03', '\n'}, - {'\x05', IGNR_}, /* (black and red are handled by ansi sequences) */ + {'\x05', IGNR_}, /* (black and red are handled by ansi sequences) */ {'\x09', IGNR_}, {'\x11', '\b'}, {'\x21', ' '}, {'\x41', '\t'}, {'\x81', CRLF_}, - {'\xC4', '\x30'}, /* (if you're curious, order here is position on APL typeball) */ + {'\xC4', '\x30'}, /* (if you're curious, order here is position on APL typeball) */ {'\xE4', '\x38'}, {'\xD4', '\x37'}, {'\xF4', '\x35'}, @@ -645,446 +645,446 @@ static struct { /* default output mapping for APLPLUS font */ #define NCONOUT_TO_APL (sizeof(conout_to_APL)/sizeof(conout_to_APL[0])) -static OS_MAP default_os_map[] = /* overstrike mapping for APLPLUS font */ +static OS_MAP default_os_map[] = /* overstrike mapping for APLPLUS font */ { - {'\x8a', 2, "\x5e\x7e"}, - {'\x8b', 2, "\x9f\x7e"}, - {'\x8d', 2, "\x8c\x27"}, - {'\x8e', 3, "\x8c\x2d\x3a"}, - {'\x8f', 2, "\x91\x5f"}, - {'\x90', 2, "\x92\x7e"}, - {'\x93', 2, "\x91\x7c"}, - {'\x94', 2, "\x92\x7c"}, - {'\x95', 2, "\xb0\x82"}, - {'\x96', 2, "\xb0\x83"}, - {'\x99', 2, "\x2d\x5c"}, - {'\x9a', 2, "\x2d\x2f"}, - {'\xae', 2, "\x2c\x2d"}, - {'\xb2', 2, "\xb1\x7c"}, - {'\xb3', 2, "\xb1\x5c"}, - {'\xb4', 2, "\xb1\x2d"}, - {'\xb5', 2, "\xb1\x2a"}, - {'\xba', 2, "\xb9\x5f"}, - {'\xd0', 2, "\x30\x7e"}, - {'\xd8', 2, "\x4f\x2f"}, - {'\x21', 2, "\x27\x2e"}, - {'\xa4', 2, "\xb0\xb1"}, /* map degree in circle to circle cross (APL uses this as character error symbol) */ - {'\xf0', 2, "\xb0\xa8"}, - {'\xfe', 2, "\x3a\xa8"}, + {'\x8a', 2, "\x5e\x7e"}, + {'\x8b', 2, "\x9f\x7e"}, + {'\x8d', 2, "\x8c\x27"}, + {'\x8e', 3, "\x8c\x2d\x3a"}, + {'\x8f', 2, "\x91\x5f"}, + {'\x90', 2, "\x92\x7e"}, + {'\x93', 2, "\x91\x7c"}, + {'\x94', 2, "\x92\x7c"}, + {'\x95', 2, "\xb0\x82"}, + {'\x96', 2, "\xb0\x83"}, + {'\x99', 2, "\x2d\x5c"}, + {'\x9a', 2, "\x2d\x2f"}, + {'\xae', 2, "\x2c\x2d"}, + {'\xb2', 2, "\xb1\x7c"}, + {'\xb3', 2, "\xb1\x5c"}, + {'\xb4', 2, "\xb1\x2d"}, + {'\xb5', 2, "\xb1\x2a"}, + {'\xba', 2, "\xb9\x5f"}, + {'\xd0', 2, "\x30\x7e"}, + {'\xd8', 2, "\x4f\x2f"}, + {'\x21', 2, "\x27\x2e"}, + {'\xa4', 2, "\xb0\xb1"}, /* map degree in circle to circle cross (APL uses this as character error symbol) */ + {'\xf0', 2, "\xb0\xa8"}, + {'\xfe', 2, "\x3a\xa8"}, }; #ifdef __SUNPRO_C -# pragma error_messages (default, E_INIT_DOES_NOT_FIT) /* enable int->char demotion warning caused by characters with high-bit set */ +# pragma error_messages (default, E_INIT_DOES_NOT_FIT) /* enable int->char demotion warning caused by characters with high-bit set */ #endif #ifdef _MSC_VER -# pragma warning(default:4245) /* enable int->char demotion warning */ +# pragma warning(default:4245) /* enable int->char demotion warning */ #endif /* os_map_comp - compare to OS_MAP entries */ static int os_map_comp (OS_MAP *a, OS_MAP *b) { - unsigned char *sa, *sb; - int i; + unsigned char *sa, *sb; + int i; - if (a->nin > b->nin) - return +1; + if (a->nin > b->nin) + return +1; - if (a->nin < b->nin) - return -1; + if (a->nin < b->nin) + return -1; - sa = a->inlist; - sb = b->inlist; + sa = a->inlist; + sb = b->inlist; - for (i = a->nin; --i >= 0;) { - if (*sa > *sb) - return +1; + for (i = a->nin; --i >= 0;) { + if (*sa > *sb) + return +1; - if (*sa < *sb) - return -1; + if (*sa < *sb) + return -1; - sa++; - sb++; - } + sa++; + sb++; + } - return 0; + return 0; } /* strsort - sorts the n characters of array 's' using insertion sort */ static void strsort (int n, unsigned char *s) { - unsigned char temp; - int i, big; + unsigned char temp; + int i, big; - while (--n > 0) { /* repeatedly */ - big = 0; /* find largest value of s[0]...s[n] */ - for (i = 1; i <= n; i++) - if (s[i] > s[big]) big = i; + while (--n > 0) { /* repeatedly */ + big = 0; /* find largest value of s[0]...s[n] */ + for (i = 1; i <= n; i++) + if (s[i] > s[big]) big = i; - temp = s[n]; /* put largest value at end of array */ - s[n] = s[big]; - s[big] = temp; - } + temp = s[n]; /* put largest value at end of array */ + s[n] = s[big]; + s[big] = temp; + } } /* file format: -[font XXX] font named XXX -OUT failure character -OUT IN single character mapping -OUT IN IN ... overstrike mapping +[font XXX] font named XXX +OUT failure character +OUT IN single character mapping +OUT IN IN ... overstrike mapping */ static void set_conout_mapping (int32 flags) { - curcol = 0; - maxcol = 0; + curcol = 0; + maxcol = 0; - /* set the default mappings. We may later override them with settings from an ini file */ + /* set the default mappings. We may later override them with settings from an ini file */ - set_default_mapping(flags); + set_default_mapping(flags); } /* finish_conout_mapping - sort the finalized overstrike mapping */ static void finish_conout_mapping (int32 flags) { - int i, n, big; - OS_MAP temp; + int i, n, big; + OS_MAP temp; - for (i = 0; i < n_os_mappings; i++) /* sort the inlist strings individually */ - strsort(os_map[i].nin, os_map[i].inlist); + for (i = 0; i < n_os_mappings; i++) /* sort the inlist strings individually */ + strsort(os_map[i].nin, os_map[i].inlist); - for (n = n_os_mappings; --n > 0; ) { /* then sort the os_map array itself with insertion sort */ - big = 0; /* find largest value of s[0]...s[n] */ - for (i = 1; i <= n; i++) - if (os_map_comp(os_map+i, os_map+big) > 0) big = i; + for (n = n_os_mappings; --n > 0; ) { /* then sort the os_map array itself with insertion sort */ + big = 0; /* find largest value of s[0]...s[n] */ + for (i = 1; i <= n; i++) + if (os_map_comp(os_map+i, os_map+big) > 0) big = i; - if (big != n) { - temp = os_map[n]; /* put largest value at end of array */ - os_map[n] = os_map[big]; - os_map[big] = temp; - } - } + if (big != n) { + temp = os_map[n]; /* put largest value at end of array */ + os_map[n] = os_map[big]; + os_map[big] = temp; + } + } } /* validate_conout_mapping - called when set command gets a new value */ static t_stat validate_conout_mapping (UNIT *uptr, int32 match, CONST char *cvptr, void *desc) { - set_conout_mapping(match); - return SCPE_OK; + set_conout_mapping(match); + return SCPE_OK; } static void reset_mapping (void) { - int i; + int i; - black_ribbon[0] = '\0'; /* erase the ribbon sequences */ - red_ribbon[0] = '\0'; + black_ribbon[0] = '\0'; /* erase the ribbon sequences */ + red_ribbon[0] = '\0'; - memset(conout_map, 0, sizeof(conout_map)); /* erase output mapping */ + memset(conout_map, 0, sizeof(conout_map)); /* erase output mapping */ - n_os_mappings = 0; /* erase overstrike mapping */ + n_os_mappings = 0; /* erase overstrike mapping */ - for (i = (sizeof(conin_map)/sizeof(conin_map[0])); --i >= 0; ) - conin_map[i] = (unsigned char) i; /* default conin_map is identity map */ + for (i = (sizeof(conin_map)/sizeof(conin_map[0])); --i >= 0; ) + conin_map[i] = (unsigned char) i; /* default conin_map is identity map */ } /* set_default_mapping - create standard font and overstrike map */ static void set_default_mapping (int32 flags) { - int i; + int i; - reset_mapping(); + reset_mapping(); - strcpy((char *) black_ribbon, "\033[30m"); - strcpy((char *) red_ribbon, "\033[31m"); + strcpy((char *) black_ribbon, "\033[30m"); + strcpy((char *) red_ribbon, "\033[31m"); - switch (flags & CSET_MASK) { - case CSET_1130: - break; + switch (flags & CSET_MASK) { + case CSET_1130: + break; - case CSET_ASCII: - memcpy(conout_map, conout_to_ascii, sizeof(conout_to_ascii)); - break; + case CSET_ASCII: + memcpy(conout_map, conout_to_ascii, sizeof(conout_to_ascii)); + break; - case CSET_APL: - for (i = NCONOUT_TO_APL; --i >= 0; ) - conout_map[conout_to_APL[i].in] = conout_to_APL[i].out; + case CSET_APL: + for (i = NCONOUT_TO_APL; --i >= 0; ) + conout_map[conout_to_APL[i].in] = conout_to_APL[i].out; - for (i = NCONIN_TO_APL; --i >= 0; ) - conin_map[conin_to_APL[i].in] = conin_to_APL[i].out; + for (i = NCONIN_TO_APL; --i >= 0; ) + conin_map[conin_to_APL[i].in] = conin_to_APL[i].out; - memcpy(os_map, default_os_map, sizeof(default_os_map)); - n_os_mappings = (sizeof(default_os_map) / sizeof(default_os_map[0])); - break; - } + memcpy(os_map, default_os_map, sizeof(default_os_map)); + n_os_mappings = (sizeof(default_os_map) / sizeof(default_os_map[0])); + break; + } - finish_conout_mapping(flags); /* sort conout mapping if necessary */ + finish_conout_mapping(flags); /* sort conout mapping if necessary */ } /* sim_putstr - write a string to the console */ t_stat sim_putstr (char *s) { - t_stat status; + t_stat status; - while (*s) { - if ((status = sim_putchar(*s)) != SCPE_OK) - return status; + while (*s) { + if ((status = sim_putchar(*s)) != SCPE_OK) + return status; - s++; - } + s++; + } - return SCPE_OK; + return SCPE_OK; } /* map_conout_character - translate and write a single character */ static t_stat map_conout_character (int ch) { - t_stat status; - int i, cmp; + t_stat status; + int i, cmp; - if (ch == (COUT_IS_CTRL|COUT_CTRL_BLACK)) - return (tto_unit.flags & ENABLE_ANSI) ? sim_putstr((char *) black_ribbon) : SCPE_OK; + if (ch == (COUT_IS_CTRL|COUT_CTRL_BLACK)) + return (tto_unit.flags & ENABLE_ANSI) ? sim_putstr((char *) black_ribbon) : SCPE_OK; - if (ch == (COUT_IS_CTRL|COUT_CTRL_RED)) - return (tto_unit.flags & ENABLE_ANSI) ? sim_putstr((char *) red_ribbon) : SCPE_OK; + if (ch == (COUT_IS_CTRL|COUT_CTRL_RED)) + return (tto_unit.flags & ENABLE_ANSI) ? sim_putstr((char *) red_ribbon) : SCPE_OK; - if ((ch = conout_map[ch & 0xFF]) == 0) - ch = '?'; /* unknown character? print ? */ + if ((ch = conout_map[ch & 0xFF]) == 0) + ch = '?'; /* unknown character? print ? */ - if (ch == '\n') { /* newline: reset overstrike buffer */ - curcol = 0; - maxcol = -1; - } - else if (ch == '\r') { /* carriage return: rewind to column 0 */ - curcol = 0; - maxcol = -1; /* assume it advances paper too */ - } - else if (ch == '\b') { /* backspace: back up one character */ - if (curcol > 0) - curcol--; - } - else if (n_os_mappings && ch != (unsigned char) IGNR_) { - if (curcol >= MAX_OUTPUT_COLUMNS) - map_conout_character('\x81'); /* precede with automatic carriage return/line feed, I guess */ - - if (curcol > maxcol) { /* first time in this column, no overstrike possible yet */ - os_buf[curcol].nin = 0; - maxcol = curcol; - } + if (ch == '\n') { /* newline: reset overstrike buffer */ + curcol = 0; + maxcol = -1; + } + else if (ch == '\r') { /* carriage return: rewind to column 0 */ + curcol = 0; + maxcol = -1; /* assume it advances paper too */ + } + else if (ch == '\b') { /* backspace: back up one character */ + if (curcol > 0) + curcol--; + } + else if (n_os_mappings && ch != (unsigned char) IGNR_) { + if (curcol >= MAX_OUTPUT_COLUMNS) + map_conout_character('\x81'); /* precede with automatic carriage return/line feed, I guess */ + + if (curcol > maxcol) { /* first time in this column, no overstrike possible yet */ + os_buf[curcol].nin = 0; + maxcol = curcol; + } - if (ch != ' ' && ch != 0) { /* (if it's not a blank or unknown) */ - os_buf[curcol].inlist[os_buf[curcol].nin] = (unsigned char) ch; - strsort(++os_buf[curcol].nin, os_buf[curcol].inlist); - } + if (ch != ' ' && ch != 0) { /* (if it's not a blank or unknown) */ + os_buf[curcol].inlist[os_buf[curcol].nin] = (unsigned char) ch; + strsort(++os_buf[curcol].nin, os_buf[curcol].inlist); + } - if (os_buf[curcol].nin == 0) /* if nothing but blanks seen, */ - ch = ' '; /* output is a blank */ - else if (os_buf[curcol].nin == 1) { /* if only one printing character seen, display it */ - ch = os_buf[curcol].inlist[0]; - } - else { /* otherwise look up mapping */ - ch = '?'; + if (os_buf[curcol].nin == 0) /* if nothing but blanks seen, */ + ch = ' '; /* output is a blank */ + else if (os_buf[curcol].nin == 1) { /* if only one printing character seen, display it */ + ch = os_buf[curcol].inlist[0]; + } + else { /* otherwise look up mapping */ + ch = '?'; - for (i = 0; i < n_os_mappings; i++) { - cmp = os_map_comp(&os_buf[curcol], &os_map[i]); - if (cmp == 0) { /* a hit */ - ch = os_map[i].ch; - break; - } - else if (cmp < 0) /* not found */ - break; - } - } + for (i = 0; i < n_os_mappings; i++) { + cmp = os_map_comp(&os_buf[curcol], &os_map[i]); + if (cmp == 0) { /* a hit */ + ch = os_map[i].ch; + break; + } + else if (cmp < 0) /* not found */ + break; + } + } - if (curcol < MAX_OUTPUT_COLUMNS) /* this should now never happen, as we automatically return */ - curcol++; - } + if (curcol < MAX_OUTPUT_COLUMNS) /* this should now never happen, as we automatically return */ + curcol++; + } - switch (ch) { - case IGNR_: - break; + switch (ch) { + case IGNR_: + break; - case CRLF_: - if (! cgi) { - if ((status = sim_putchar('\r')) != SCPE_OK) - return status; + case CRLF_: + if (! cgi) { + if ((status = sim_putchar('\r')) != SCPE_OK) + return status; - tto_unit.pos++; - } + tto_unit.pos++; + } - if ((status = sim_putchar('\n')) != SCPE_OK) - return status; + if ((status = sim_putchar('\n')) != SCPE_OK) + return status; - tto_unit.pos++; /* hmm, why do we count these? */ - break; + tto_unit.pos++; /* hmm, why do we count these? */ + break; - default: - if ((status = sim_putchar(ch)) != SCPE_OK) - return status; + default: + if ((status = sim_putchar(ch)) != SCPE_OK) + return status; - tto_unit.pos++; - break; - } + tto_unit.pos++; + break; + } - return SCPE_OK; + return SCPE_OK; } /* font_cmd - parse a font mapping file. Sets input and output translations */ static t_stat font_cmd (int32 flag, CONST char *iptr) { - char *fname, quote; + char *fname, quote; char gbuf[4*CBUFSIZE], *cptr = gbuf; - FILE *fd; + FILE *fd; gbuf[sizeof(gbuf)-1] = '\0'; strncpy(gbuf, iptr, sizeof(gbuf)-1); - while (*cptr && (*cptr <= ' ')) cptr++; /* skip blanks */ - if (! *cptr) return SCPE_2FARG; /* argument missing */ + while (*cptr && (*cptr <= ' ')) cptr++; /* skip blanks */ + if (! *cptr) return SCPE_2FARG; /* argument missing */ - fname = cptr; /* save start */ - if (*cptr == '\'' || *cptr == '"') { /* quoted string */ - quote = *cptr++; /* remember quote character */ - fname++; /* skip the quote */ + fname = cptr; /* save start */ + if (*cptr == '\'' || *cptr == '"') { /* quoted string */ + quote = *cptr++; /* remember quote character */ + fname++; /* skip the quote */ - while (*cptr && (*cptr != quote)) /* find closing quote */ - cptr++; - } - else { - while (*cptr && (*cptr > ' ')) /* find terminating blank */ - cptr++; - } - *cptr = '\0'; /* terminate name */ + while (*cptr && (*cptr != quote)) /* find closing quote */ + cptr++; + } + else { + while (*cptr && (*cptr > ' ')) /* find terminating blank */ + cptr++; + } + *cptr = '\0'; /* terminate name */ - if ((fd = fopen(fname, "r")) == NULL) - return SCPE_OPENERR; + if ((fd = fopen(fname, "r")) == NULL) + return SCPE_OPENERR; - reset_mapping(); /* remove all default mappings */ + reset_mapping(); /* remove all default mappings */ - read_map_file(fd); - fclose(fd); + read_map_file(fd); + fclose(fd); - finish_conout_mapping(tto_unit.flags); - return SCPE_OK; + finish_conout_mapping(tto_unit.flags); + return SCPE_OK; } /* str_match - compare the string str to the keyword, case insensitive */ static t_bool str_match (const char *str, const char *keyword) { - char kch, sch; + char kch, sch; - while (*keyword) { /* see if str matches the keyword... */ - kch = *keyword++; /* get pair of characters */ - sch = *str++; + while (*keyword) { /* see if str matches the keyword... */ + kch = *keyword++; /* get pair of characters */ + sch = *str++; - if (BETWEEN(kch, 'A', 'Z')) kch += 32; /* change upper to lower case */ - if (BETWEEN(sch, 'A', 'Z')) sch += 32; + if (BETWEEN(kch, 'A', 'Z')) kch += 32; /* change upper to lower case */ + if (BETWEEN(sch, 'A', 'Z')) sch += 32; - if (kch != sch) /* characters must match; if not, quit */ - return FALSE; - } + if (kch != sch) /* characters must match; if not, quit */ + return FALSE; + } - return *str <= ' ' || *str == ';'; /* success if the input string ended or is in whitespace or comment */ + return *str <= ' ' || *str == ';'; /* success if the input string ended or is in whitespace or comment */ } /* read_map_file - process definition lines in opened mapping file */ static void read_map_file (FILE *fd) { - char str[256], *c; + char str[256], *c; const char *errmsg; - int lineno = 0; - enum {SECT_UNDEFINED, SECT_DEFAULT, SECT_ANSI, SECT_INPUT, SECT_OUTPUT, SECT_OVERSTRIKE} - section = SECT_UNDEFINED; + int lineno = 0; + enum {SECT_UNDEFINED, SECT_DEFAULT, SECT_ANSI, SECT_INPUT, SECT_OUTPUT, SECT_OVERSTRIKE} + section = SECT_UNDEFINED; - while (fgets(str, sizeof(str), fd) != NULL) { - ++lineno; /* count input lines */ + while (fgets(str, sizeof(str), fd) != NULL) { + ++lineno; /* count input lines */ - if ((c = strchr(str, '\n')) != NULL) /* terminate at newline */ - *c = '\0'; + if ((c = strchr(str, '\n')) != NULL) /* terminate at newline */ + *c = '\0'; - for (c = str; *c && *c <= ' '; c++) /* skip blanks */ - ; + for (c = str; *c && *c <= ' '; c++) /* skip blanks */ + ; - if (c[0] == '\0' || c[0] == ';') /* ignore blank lines and lines starting with ; */ - continue; + if (c[0] == '\0' || c[0] == ';') /* ignore blank lines and lines starting with ; */ + continue; - if (*c == '[') { - if (str_match(c, "[default]")) { /* check for section separators */ - set_default_mapping(tto_unit.flags); - section = SECT_UNDEFINED; - continue; - } - if (str_match(c, "[ansi]")) { - section = SECT_ANSI; - continue; - } - if (str_match(c, "[input]")) { - section = SECT_INPUT; - continue; - } - if (str_match(c, "[output]")) { - section = SECT_OUTPUT; - continue; - } - if (str_match(c, "[overstrike]")) { - section = SECT_OVERSTRIKE; - continue; - } - } + if (*c == '[') { + if (str_match(c, "[default]")) { /* check for section separators */ + set_default_mapping(tto_unit.flags); + section = SECT_UNDEFINED; + continue; + } + if (str_match(c, "[ansi]")) { + section = SECT_ANSI; + continue; + } + if (str_match(c, "[input]")) { + section = SECT_INPUT; + continue; + } + if (str_match(c, "[output]")) { + section = SECT_OUTPUT; + continue; + } + if (str_match(c, "[overstrike]")) { + section = SECT_OVERSTRIKE; + continue; + } + } - switch (section) { /* if we get here, we have a definition line */ - case SECT_ANSI: - errmsg = handle_map_ansi_definition(&c); - break; - case SECT_INPUT: - errmsg = handle_map_input_definition(&c); - break; - case SECT_OUTPUT: - errmsg = handle_map_output_definition(&c); - break; - case SECT_OVERSTRIKE: - errmsg = handle_map_overstrike_definition(&c); - break; - default: - errmsg = "line occurs before valid [section]"; - break; - } + switch (section) { /* if we get here, we have a definition line */ + case SECT_ANSI: + errmsg = handle_map_ansi_definition(&c); + break; + case SECT_INPUT: + errmsg = handle_map_input_definition(&c); + break; + case SECT_OUTPUT: + errmsg = handle_map_output_definition(&c); + break; + case SECT_OVERSTRIKE: + errmsg = handle_map_overstrike_definition(&c); + break; + default: + errmsg = "line occurs before valid [section]"; + break; + } - if (errmsg == NULL) { /* if no other error detected, */ - while (*c && *c <= ' ') /* skip past any whitespace */ - c++; + if (errmsg == NULL) { /* if no other error detected, */ + while (*c && *c <= ' ') /* skip past any whitespace */ + c++; - if (*c && *c != ';') /* if line doesn't end or run into a comment, complain */ - errmsg = "too much stuff on input line"; - } + if (*c && *c != ';') /* if line doesn't end or run into a comment, complain */ + errmsg = "too much stuff on input line"; + } - if (errmsg != NULL) { /* print error message and offending line */ - printf("* Warning: %s", errmsg); + if (errmsg != NULL) { /* print error message and offending line */ + printf("* Warning: %s", errmsg); - switch (section) { /* add section name if possible */ - case SECT_ANSI: errmsg = "ansi"; break; - case SECT_INPUT: errmsg = "input"; break; - case SECT_OUTPUT: errmsg = "output"; break; - case SECT_OVERSTRIKE: errmsg = "overstrike"; break; - default: errmsg = NULL; break; - } - if (errmsg != NULL) - printf(" in [%s] section", errmsg); + switch (section) { /* add section name if possible */ + case SECT_ANSI: errmsg = "ansi"; break; + case SECT_INPUT: errmsg = "input"; break; + case SECT_OUTPUT: errmsg = "output"; break; + case SECT_OVERSTRIKE: errmsg = "overstrike"; break; + default: errmsg = NULL; break; + } + if (errmsg != NULL) + printf(" in [%s] section", errmsg); - printf(", line %d\n%s\n", lineno, str); - } - } + printf(", line %d\n%s\n", lineno, str); + } + } } /* get_num_char - read an octal or hex character specification of exactly 'ndigits' digits @@ -1094,29 +1094,29 @@ static void read_map_file (FILE *fd) static const char * get_num_char (char **pc, unsigned char *out, int ndigits, int base, const char *errmsg) { - int ch = 0, digit; - char *c = *pc; + int ch = 0, digit; + char *c = *pc; - while (--ndigits >= 0) { /* collect specified number of digits */ - if (BETWEEN(*c, '0', '9')) - digit = *c - '0'; - else if (BETWEEN(*c, 'A', 'F')) - digit = *c - 'A' + 10; - else if (BETWEEN(*c, 'a', 'f')) - digit = *c - 'a' + 10; - else - digit = base; + while (--ndigits >= 0) { /* collect specified number of digits */ + if (BETWEEN(*c, '0', '9')) + digit = *c - '0'; + else if (BETWEEN(*c, 'A', 'F')) + digit = *c - 'A' + 10; + else if (BETWEEN(*c, 'a', 'f')) + digit = *c - 'a' + 10; + else + digit = base; - if (digit >= base) /* bad digit */ - return errmsg; + if (digit >= base) /* bad digit */ + return errmsg; - ch = ch * base + digit; /* accumulate digit */ - c++; - } + ch = ch * base + digit; /* accumulate digit */ + c++; + } - *out = (unsigned char) ch; /* return parsed character */ - *pc = c-1; /* make input pointer point to last character seen */ - return NULL; /* no error */ + *out = (unsigned char) ch; /* return parsed character */ + *pc = c-1; /* make input pointer point to last character seen */ + return NULL; /* no error */ } /* get_characters - read character specification(s) from input string pointed to @@ -1127,204 +1127,204 @@ static const char * get_num_char (char **pc, unsigned char *out, int ndigits, in static const char * get_characters (char **pc, unsigned char *outstr, int nmax, int *nout) { - char *c = *pc; + char *c = *pc; const char *errstr; - unsigned char *out = outstr; + unsigned char *out = outstr; - while (*c && *c <= ' ') /* skip leading whitespace */ - c++; + while (*c && *c <= ' ') /* skip leading whitespace */ + c++; - while (--nmax >= 0) { /* get up to maximum number of characters */ - if (*c == ';' || *c <= ' ') /* we ran into a comment, whitespace or end of string: we're done */ - break; + while (--nmax >= 0) { /* get up to maximum number of characters */ + if (*c == ';' || *c <= ' ') /* we ran into a comment, whitespace or end of string: we're done */ + break; - if (*c == '\\') { /* backslash escape of some sort */ - switch (*++c) { - case 'b': /* backspace */ - case 'B': - *out++ = '\b'; - break; + if (*c == '\\') { /* backslash escape of some sort */ + switch (*++c) { + case 'b': /* backspace */ + case 'B': + *out++ = '\b'; + break; - case 'e': /* ascii ESCAPE */ - case 'E': - *out++ = '\033'; - break; + case 'e': /* ascii ESCAPE */ + case 'E': + *out++ = '\033'; + break; - case 'f': /* formfeed */ - case 'F': - *out++ = '\f'; - break; + case 'f': /* formfeed */ + case 'F': + *out++ = '\f'; + break; - case 'n': /* newline */ - case 'N': - *out++ = '\n'; - break; + case 'n': /* newline */ + case 'N': + *out++ = '\n'; + break; - case 'r': /* return */ - case 'R': - *out++ = '\r'; - break; + case 'r': /* return */ + case 'R': + *out++ = '\r'; + break; - case 't': /* tab */ - case 'T': - *out++ = '\t'; - break; + case 't': /* tab */ + case 'T': + *out++ = '\t'; + break; - case 'x': /* hex specification */ - case 'X': - c++; - if ((errstr = get_num_char(&c, out, 2, 16, "bad hex character")) != NULL) - return errstr; + case 'x': /* hex specification */ + case 'X': + c++; + if ((errstr = get_num_char(&c, out, 2, 16, "bad hex character")) != NULL) + return errstr; - out++; /* advance out pointer */ - break; + out++; /* advance out pointer */ + break; - default: /* anything else */ - if (BETWEEN(*c, '0', '7')) { /* octal specification */ - if ((errstr = get_num_char(&c, out, 3, 8, "bad octal character")) != NULL) - return errstr; - - out++; /* advance out pointer */ - } - else if (BETWEEN(*c, 'A', 'Z') || BETWEEN(*c, 'a', 'z')) - return "invalid \\ escape"; /* other \x letters are bad */ - else { - *out++ = (unsigned char) *c;/* otherwise, accept \x as literal character x */ - } - break; - } - } - else if (*c == '^') { /* control character */ - c++; - if (BETWEEN(*c, 'A', 'Z')) /* convert alpha, e.g. A -> 1 */ - *out++ = (unsigned char) (*c - 'A' + 1); - else if (BETWEEN(*c, 'a', 'z')) - *out++ = (unsigned char) (*c - 'z' + 1); - else /* non alpha is bad */ - return "invalid control letter"; - } - else if (str_match(c, "IGNORE")) { /* magic word: a character that will never be output */ - *out++ = (unsigned char) IGNR_; - c += 6; - } - else { - *out++ = (unsigned char) *c; /* save literal character */ - } + default: /* anything else */ + if (BETWEEN(*c, '0', '7')) { /* octal specification */ + if ((errstr = get_num_char(&c, out, 3, 8, "bad octal character")) != NULL) + return errstr; + + out++; /* advance out pointer */ + } + else if (BETWEEN(*c, 'A', 'Z') || BETWEEN(*c, 'a', 'z')) + return "invalid \\ escape"; /* other \x letters are bad */ + else { + *out++ = (unsigned char) *c;/* otherwise, accept \x as literal character x */ + } + break; + } + } + else if (*c == '^') { /* control character */ + c++; + if (BETWEEN(*c, 'A', 'Z')) /* convert alpha, e.g. A -> 1 */ + *out++ = (unsigned char) (*c - 'A' + 1); + else if (BETWEEN(*c, 'a', 'z')) + *out++ = (unsigned char) (*c - 'z' + 1); + else /* non alpha is bad */ + return "invalid control letter"; + } + else if (str_match(c, "IGNORE")) { /* magic word: a character that will never be output */ + *out++ = (unsigned char) IGNR_; + c += 6; + } + else { + *out++ = (unsigned char) *c; /* save literal character */ + } - c++; - } + c++; + } - if (*c && *c != ';' && *c > ' ') /* we should be at end of string, whitespace or comment */ - return "too many characters specified"; + if (*c && *c != ';' && *c > ' ') /* we should be at end of string, whitespace or comment */ + return "too many characters specified"; - *pc = c; /* save advanced pointer */ - *nout = out-outstr; /* save number of characters stored */ + *pc = c; /* save advanced pointer */ + *nout = out-outstr; /* save number of characters stored */ - return NULL; /* no error */ + return NULL; /* no error */ } /* handle_map_ansi_definition - process line in [ansi] section */ static const char * handle_map_ansi_definition (char **pc) { - unsigned char *outstr; - const char *errmsg; - int n; + unsigned char *outstr; + const char *errmsg; + int n; - if (str_match(*pc, "black")) { /* find which string we're setting */ - outstr = black_ribbon; /* this is where we'll save the output string */ - *pc += 5; /* skip over the token */ - } - else if (str_match(*pc, "red")) { - outstr = red_ribbon; - *pc += 3; - } - else - return "invalid variable name"; - /* get list of characters */ - if ((errmsg = get_characters(pc, outstr, sizeof(black_ribbon)-1, &n)) != NULL) - return errmsg; + if (str_match(*pc, "black")) { /* find which string we're setting */ + outstr = black_ribbon; /* this is where we'll save the output string */ + *pc += 5; /* skip over the token */ + } + else if (str_match(*pc, "red")) { + outstr = red_ribbon; + *pc += 3; + } + else + return "invalid variable name"; + /* get list of characters */ + if ((errmsg = get_characters(pc, outstr, sizeof(black_ribbon)-1, &n)) != NULL) + return errmsg; - outstr[n] = '\0'; /* null terminate the string */ + outstr[n] = '\0'; /* null terminate the string */ - return (n > 0) ? NULL : "missing output string"; /* NULL if OK, error msg if no characters */ + return (n > 0) ? NULL : "missing output string"; /* NULL if OK, error msg if no characters */ } /* handle_map_input_definition - process line in [input] section */ static const char * handle_map_input_definition (char **pc) { - unsigned char cin, cout; - const char *errmsg; - int n; + unsigned char cin, cout; + const char *errmsg; + int n; - if ((errmsg = get_characters(pc, &cin, 1, &n)) != NULL) /* get input character */ - return errmsg; + if ((errmsg = get_characters(pc, &cin, 1, &n)) != NULL) /* get input character */ + return errmsg; - if (n != 1) - return "missing input character"; + if (n != 1) + return "missing input character"; - if ((errmsg = get_characters(pc, &cout, 1, &n)) != NULL) /* get output character */ - return errmsg; + if ((errmsg = get_characters(pc, &cout, 1, &n)) != NULL) /* get output character */ + return errmsg; - if (n != 1) - return "missing output character"; + if (n != 1) + return "missing output character"; - conin_map[cin] = cout; /* set the mapping */ - return NULL; + conin_map[cin] = cout; /* set the mapping */ + return NULL; } /* handle_map_output_definition - process line in [output] section */ static const char * handle_map_output_definition (char **pc) { - unsigned char cin, cout; - const char *errmsg; - int n; + unsigned char cin, cout; + const char *errmsg; + int n; - if ((errmsg = get_characters(pc, &cin, 1, &n)) != NULL) /* get input character */ - return errmsg; + if ((errmsg = get_characters(pc, &cin, 1, &n)) != NULL) /* get input character */ + return errmsg; - if (n != 1) - return "missing input character"; + if (n != 1) + return "missing input character"; - if ((errmsg = get_characters(pc, &cout, 1, &n)) != NULL) /* get output character */ - return errmsg; + if ((errmsg = get_characters(pc, &cout, 1, &n)) != NULL) /* get output character */ + return errmsg; - if (n != 1) - return "missing output character"; + if (n != 1) + return "missing output character"; - conout_map[cin] = cout; /* set the mapping */ - return NULL; + conout_map[cin] = cout; /* set the mapping */ + return NULL; } /* handle_map_overstrike_definition - process line in [overstrike] section */ static const char * handle_map_overstrike_definition (char **pc) { - unsigned char ch, inlist[MAX_OS_CHARS]; - const char *errmsg; - int nin; + unsigned char ch, inlist[MAX_OS_CHARS]; + const char *errmsg; + int nin; - if (n_os_mappings >= MAX_OS_MAPPINGS) /* os_map is full, no more room */ - return "too many overstrike mappings"; - /* get output character */ - if ((errmsg = get_characters(pc, &ch, 1, &nin)) != NULL) - return errmsg; + if (n_os_mappings >= MAX_OS_MAPPINGS) /* os_map is full, no more room */ + return "too many overstrike mappings"; + /* get output character */ + if ((errmsg = get_characters(pc, &ch, 1, &nin)) != NULL) + return errmsg; - if (nin != 1) - return "missing output character"; - /* get input list */ - if ((errmsg = get_characters(pc, inlist, MAX_OS_CHARS, &nin)) != NULL) - return errmsg; + if (nin != 1) + return "missing output character"; + /* get input list */ + if ((errmsg = get_characters(pc, inlist, MAX_OS_CHARS, &nin)) != NULL) + return errmsg; - if (nin < 2) /* expect at least two characters overprinted */ - return "missing input list"; + if (nin < 2) /* expect at least two characters overprinted */ + return "missing input list"; - os_map[n_os_mappings].ch = ch; /* save in next os_map slot */ - os_map[n_os_mappings].nin = nin; - memmove(os_map[n_os_mappings].inlist, inlist, nin); + os_map[n_os_mappings].ch = ch; /* save in next os_map slot */ + os_map[n_os_mappings].nin = nin; + memmove(os_map[n_os_mappings].inlist, inlist, nin); - n_os_mappings++; - return NULL; + n_os_mappings++; + return NULL; } diff --git a/Ibm1130/ibm1130_sys.c b/Ibm1130/ibm1130_sys.c index 6da44135..46636b5a 100644 --- a/Ibm1130/ibm1130_sys.c +++ b/Ibm1130/ibm1130_sys.c @@ -5,12 +5,12 @@ Revision History 0.27 2005Mar08 - Added sca device 0.26 2002Apr24 - Added !BREAK in card deck file to stop simulator - 0.25 2002Apr18 - Fixed some card reader problems. It starts the reader - properly if you attach a deck while it's waiting to a read. + 0.25 2002Apr18 - Fixed some card reader problems. It starts the reader + properly if you attach a deck while it's waiting to a read. 0.24 2002Mar27 - Fixed BOSC bug; BOSC works in short instructions too 0.23 2002Feb26 - Added @decklist feature for ATTACH CR. 0.22 2002Feb26 - Replaced "strupr" with "upcase" for compatibility. - 0.21 2002Feb25 - Some compiler compatibiity changes, couple of compiler-detected + 0.21 2002Feb25 - Some compiler compatibiity changes, couple of compiler-detected bugs 0.01 2001Jul31 - Derived from pdp11_sys.c, which carries this disclaimer: @@ -39,12 +39,12 @@ extern t_bool is_1800; /* SCP data structures and interface routines - sim_name simulator name string - sim_PC pointer to saved PC register descriptor - sim_emax number of words for examine - sim_devices array of pointers to simulated devices - sim_stop_messages array of pointers to stop messages - sim_load binary loader + sim_name simulator name string + sim_PC pointer to saved PC register descriptor + sim_emax number of words for examine + sim_devices array of pointers to simulated devices + sim_stop_messages array of pointers to stop messages + sim_load binary loader */ char sim_name[] = "IBM 1130"; @@ -54,38 +54,38 @@ REG *sim_PC = &cpu_reg[0]; int32 sim_emax = 4; DEVICE *sim_devices[] = { - &cpu_dev, /* the cpu */ - &dsk_dev, /* disk drive(s) */ - &cr_dev, /* card reader/punch */ - &cp_dev, - &tti_dev, /* console keyboard, selectric printer */ - &tto_dev, - &prt_dev, /* 1132 printer */ - &ptr_dev, /* 1134 paper tape reader */ - &ptp_dev, /* 1055 paper tape punch */ - &sca_dev, /* Synchronous communications adapter option */ - &console_dev, /* console display (windows GUI) */ - &gdu_dev, /* 2250 display */ - &t2741_dev, /* nonstandard serial interface used by APL\1130 */ - &plot_dev, /* plotter device, in ibm1130_plot.c */ - NULL + &cpu_dev, /* the cpu */ + &dsk_dev, /* disk drive(s) */ + &cr_dev, /* card reader/punch */ + &cp_dev, + &tti_dev, /* console keyboard, selectric printer */ + &tto_dev, + &prt_dev, /* 1132 printer */ + &ptr_dev, /* 1134 paper tape reader */ + &ptp_dev, /* 1055 paper tape punch */ + &sca_dev, /* Synchronous communications adapter option */ + &console_dev, /* console display (windows GUI) */ + &gdu_dev, /* 2250 display */ + &t2741_dev, /* nonstandard serial interface used by APL\1130 */ + &plot_dev, /* plotter device, in ibm1130_plot.c */ + NULL }; const char *sim_stop_messages[] = { - "Unknown error", - "Wait", - "Invalid command", - "Simulator breakpoint", - "Use of incomplete simulator function", - "Power off", - "!BREAK in card deck file", - "Phase load break", - "Program has run amok", - "Run time limit exceeded", - "Immediate Stop key requested", - "Simulator break key pressed", - "Simulator step count expired", - "Simulator IO error", + "Unknown error", + "Wait", + "Invalid command", + "Simulator breakpoint", + "Use of incomplete simulator function", + "Power off", + "!BREAK in card deck file", + "Phase load break", + "Program has run amok", + "Run time limit exceeded", + "Immediate Stop key requested", + "Simulator break key pressed", + "Simulator step count expired", + "Simulator IO error", }; /* Loader. IPL is normally performed by card reader (boot command). This function @@ -93,13 +93,13 @@ const char *sim_stop_messages[] = { * * blank lines or lines starting with ; / or # are ignored as comments * - * @XXXX set load addresss to hex value XXXX - * XXXX store hex word value XXXX at current load address and increment address + * @XXXX set load addresss to hex value XXXX + * XXXX store hex word value XXXX at current load address and increment address * ... - * =XXXX set IAR to hex value XXXX - * ZXXXX zero XXXX words and increment load address - * SXXXX set console entry switches to XXXX. This lets a program specify the - * default value for the toggle switches. + * =XXXX set IAR to hex value XXXX + * ZXXXX zero XXXX words and increment load address + * SXXXX set console entry switches to XXXX. This lets a program specify the + * default value for the toggle switches. * * Multiple @ and data sections may be entered. If more than one = or S value is specified * the last one wins. @@ -111,154 +111,154 @@ const char *sim_stop_messages[] = { t_stat my_load (FILE *fileref, const char *cptr, const char *fnam) { - char line[150], *c; - int iaddr = -1, runaddr = -1, val, nwords; + char line[150], *c; + int iaddr = -1, runaddr = -1, val, nwords; - while (fgets(line, sizeof(line), fileref) != NULL) { - for (c = line; *c && *c <= ' '; c++) /* find first nonblank */ - ; + while (fgets(line, sizeof(line), fileref) != NULL) { + for (c = line; *c && *c <= ' '; c++) /* find first nonblank */ + ; - if (*c == '\0' || *c == '#' || *c == '/' || *c == ';') - continue; /* empty line or comment */ + if (*c == '\0' || *c == '#' || *c == '/' || *c == ';') + continue; /* empty line or comment */ - if (*c == '@') { /* set load address */ - if (sscanf(c+1, "%x", &iaddr) != 1) - return SCPE_FMT; - } - else if (*c == '=') { - if (sscanf(c+1, "%x", &runaddr) != 1) - return SCPE_FMT; - } - else if (*c == 's' || *c == 'S') { - if (sscanf(c+1, "%x", &val) != 1) - return SCPE_FMT; + if (*c == '@') { /* set load address */ + if (sscanf(c+1, "%x", &iaddr) != 1) + return SCPE_FMT; + } + else if (*c == '=') { + if (sscanf(c+1, "%x", &runaddr) != 1) + return SCPE_FMT; + } + else if (*c == 's' || *c == 'S') { + if (sscanf(c+1, "%x", &val) != 1) + return SCPE_FMT; - CES = val & 0xFFFF; /*preload console entry switches */ - } - else if (*c == 'z' || *c == 'Z') { - if (sscanf(c+1, "%x", &nwords) != 1) - return SCPE_FMT; + CES = val & 0xFFFF; /*preload console entry switches */ + } + else if (*c == 'z' || *c == 'Z') { + if (sscanf(c+1, "%x", &nwords) != 1) + return SCPE_FMT; - if (iaddr == -1) - return SCPE_FMT; + if (iaddr == -1) + return SCPE_FMT; - while (--nwords >= 0) { - WriteW(iaddr, 0); - iaddr++; - } - } - else if (strchr("0123456789abcdefABCDEF", *c) != NULL) { - if (sscanf(c, "%x", &val) != 1) - return SCPE_FMT; + while (--nwords >= 0) { + WriteW(iaddr, 0); + iaddr++; + } + } + else if (strchr("0123456789abcdefABCDEF", *c) != NULL) { + if (sscanf(c, "%x", &val) != 1) + return SCPE_FMT; - if (iaddr == -1) - return SCPE_FMT; + if (iaddr == -1) + return SCPE_FMT; - WriteW(iaddr, val); /*store data */ - iaddr++; - } - else - return SCPE_FMT; /*unexpected data */ - } + WriteW(iaddr, val); /*store data */ + iaddr++; + } + else + return SCPE_FMT; /*unexpected data */ + } - if (runaddr != -1) - IAR = runaddr; + if (runaddr != -1) + IAR = runaddr; - return SCPE_OK; + return SCPE_OK; } t_stat my_save (FILE *fileref, const char *cptr, const char *fnam) { - int iaddr, nzeroes = 0, nwords = (int) (MEMSIZE/2), val; + int iaddr, nzeroes = 0, nwords = (int) (MEMSIZE/2), val; - fprintf(fileref, "=%04x\r\n", IAR); - fprintf(fileref, "@0000\r\n"); - for (iaddr = 0; iaddr < nwords; iaddr++) { - val = ReadW(iaddr); - if (val == 0) /*queue up zeroes */ - nzeroes++; - else { - if (nzeroes >= 4) { /*spit out a Z directive */ - fprintf(fileref, "Z%04x\r\n", nzeroes); - nzeroes = 0; - } - else { /*write queued zeroes literally */ - while (nzeroes > 0) { - fprintf(fileref, " 0000\r\n"); - nzeroes--; - } - } - fprintf(fileref, " %04x\r\n", val); - } - } - if (nzeroes >= 4) { /*emit any queued zeroes */ - fprintf(fileref, "Z%04x\r\n", nzeroes); - nzeroes = 0; - } - else { - while (nzeroes > 0) { - fprintf(fileref, " 0000\r\n"); - nzeroes--; - } - } + fprintf(fileref, "=%04x\r\n", IAR); + fprintf(fileref, "@0000\r\n"); + for (iaddr = 0; iaddr < nwords; iaddr++) { + val = ReadW(iaddr); + if (val == 0) /*queue up zeroes */ + nzeroes++; + else { + if (nzeroes >= 4) { /*spit out a Z directive */ + fprintf(fileref, "Z%04x\r\n", nzeroes); + nzeroes = 0; + } + else { /*write queued zeroes literally */ + while (nzeroes > 0) { + fprintf(fileref, " 0000\r\n"); + nzeroes--; + } + } + fprintf(fileref, " %04x\r\n", val); + } + } + if (nzeroes >= 4) { /*emit any queued zeroes */ + fprintf(fileref, "Z%04x\r\n", nzeroes); + nzeroes = 0; + } + else { + while (nzeroes > 0) { + fprintf(fileref, " 0000\r\n"); + nzeroes--; + } + } - return SCPE_OK; + return SCPE_OK; } t_stat sim_load (FILE *fileref, CONST char *cptr, CONST char *fnam, int flag) { - if (flag) - return my_save(fileref, cptr, fnam); - else - return my_load(fileref, cptr, fnam); + if (flag) + return my_save(fileref, cptr, fnam); + else + return my_load(fileref, cptr, fnam); } /* Specifier decode Inputs: - *of = output stream - addr = current PC - spec = specifier - nval = next word - flag = TRUE if decoding for CPU - iflag = TRUE if decoding integer instruction + *of = output stream + addr = current PC + spec = specifier + nval = next word + flag = TRUE if decoding for CPU + iflag = TRUE if decoding integer instruction Outputs: - count = -number of extra words retired + count = -number of extra words retired */ /* Symbolic decode Inputs: - *of = output stream - addr = current PC - *val = values to decode - *uptr = pointer to unit - sw = switches + *of = output stream + addr = current PC + *val = values to decode + *uptr = pointer to unit + sw = switches Outputs: - return = if >= 0, error code - if < 0, number of extra words retired + return = if >= 0, error code + if < 0, number of extra words retired */ static const char *opcode[] = { - "?00 ", "XIO ", "SLA ", "SRA ", - "LDS ", "STS ", "WAIT", "?07 ", - "BSI ", "BSC ", "?0A ", "?0B ", - "LDX ", "STX ", "MDX ", "?0F ", - "A ", "AD ", "S ", "SD ", - "M ", "D ", "?16 ", "?17 ", - "LD ", "LDD ", "STO ", "STD ", - "AND ", "OR ", "EOR ", "?1F ", + "?00 ", "XIO ", "SLA ", "SRA ", + "LDS ", "STS ", "WAIT", "?07 ", + "BSI ", "BSC ", "?0A ", "?0B ", + "LDX ", "STX ", "MDX ", "?0F ", + "A ", "AD ", "S ", "SD ", + "M ", "D ", "?16 ", "?17 ", + "LD ", "LDD ", "STO ", "STD ", + "AND ", "OR ", "EOR ", "?1F ", }; -static char relative[] = { /*true if short mode displacements are IAR relative */ - FALSE, TRUE, FALSE, FALSE, - FALSE, TRUE, FALSE, FALSE, - TRUE, FALSE, FALSE, FALSE, - TRUE, TRUE, TRUE, FALSE, - TRUE, TRUE, TRUE, TRUE, - TRUE, TRUE, FALSE, FALSE, - TRUE, TRUE, TRUE, TRUE, - TRUE, TRUE, TRUE, FALSE +static char relative[] = { /*true if short mode displacements are IAR relative */ + FALSE, TRUE, FALSE, FALSE, + FALSE, TRUE, FALSE, FALSE, + TRUE, FALSE, FALSE, FALSE, + TRUE, TRUE, TRUE, FALSE, + TRUE, TRUE, TRUE, TRUE, + TRUE, TRUE, FALSE, FALSE, + TRUE, TRUE, TRUE, TRUE, + TRUE, TRUE, TRUE, FALSE }; static const char *lsopcode[] = {"SLA ", "SLCA ", "SLT ", "SLC "}; @@ -267,133 +267,133 @@ static const char tagc[] = " 123"; static int ascii_to_ebcdic_table[128] = { - 0x00,0x01,0x02,0x03,0x37,0x2d,0x2e,0x2f, 0x16,0x05,0x25,0x0b,0x0c,0x0d,0x0e,0x0f, - 0x10,0x11,0x12,0x13,0x3c,0x3d,0x32,0x26, 0x18,0x19,0x3f,0x27,0x1c,0x1d,0x1e,0x1f, - 0x40,0x5a,0x7f,0x7b,0x5b,0x6c,0x50,0x7d, 0x4d,0x5d,0x5c,0x4e,0x6b,0x60,0x4b,0x61, - 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7, 0xf8,0xf9,0x7a,0x5e,0x4c,0x7e,0x6e,0x6f, + 0x00,0x01,0x02,0x03,0x37,0x2d,0x2e,0x2f, 0x16,0x05,0x25,0x0b,0x0c,0x0d,0x0e,0x0f, + 0x10,0x11,0x12,0x13,0x3c,0x3d,0x32,0x26, 0x18,0x19,0x3f,0x27,0x1c,0x1d,0x1e,0x1f, + 0x40,0x5a,0x7f,0x7b,0x5b,0x6c,0x50,0x7d, 0x4d,0x5d,0x5c,0x4e,0x6b,0x60,0x4b,0x61, + 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7, 0xf8,0xf9,0x7a,0x5e,0x4c,0x7e,0x6e,0x6f, - 0x7c,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7, 0xc8,0xc9,0xd1,0xd2,0xd3,0xd4,0xd5,0xd6, - 0xd7,0xd8,0xd9,0xe2,0xe3,0xe4,0xe5,0xe6, 0xe7,0xe8,0xe9,0xba,0xe0,0xbb,0xb0,0x6d, - 0x79,0x81,0x82,0x83,0x84,0x85,0x86,0x87, 0x88,0x89,0x91,0x92,0x93,0x94,0x95,0x96, - 0x97,0x98,0x99,0xa2,0xa3,0xa4,0xa5,0xa6, 0xa7,0xa8,0xa9,0xc0,0x4f,0xd0,0xa1,0x07, + 0x7c,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7, 0xc8,0xc9,0xd1,0xd2,0xd3,0xd4,0xd5,0xd6, + 0xd7,0xd8,0xd9,0xe2,0xe3,0xe4,0xe5,0xe6, 0xe7,0xe8,0xe9,0xba,0xe0,0xbb,0xb0,0x6d, + 0x79,0x81,0x82,0x83,0x84,0x85,0x86,0x87, 0x88,0x89,0x91,0x92,0x93,0x94,0x95,0x96, + 0x97,0x98,0x99,0xa2,0xa3,0xa4,0xa5,0xa6, 0xa7,0xa8,0xa9,0xc0,0x4f,0xd0,0xa1,0x07, }; static int ebcdic_to_ascii (int ch) { - int j; + int j; - for (j = 32; j < 128; j++) - if (ascii_to_ebcdic_table[j] == ch) - return j; + for (j = 32; j < 128; j++) + if (ascii_to_ebcdic_table[j] == ch) + return j; - return '?'; + return '?'; } t_stat fprint_sym (FILE *of, t_addr addr, t_value *val, UNIT *uptr, int32 sw) { - int32 ch, OP, F, TAG, INDIR, DSPLC, IR, eaddr; - const char *mnem; + int32 ch, OP, F, TAG, INDIR, DSPLC, IR, eaddr; + const char *mnem; char tst[12]; -/* if (sw & SWMASK ('A')) { // ASCII? not useful - fprintf (of, (c1 < 040)? "<%03o>": "%c", c1); - return SCPE_OK; - } +/* if (sw & SWMASK ('A')) { // ASCII? not useful + fprintf (of, (c1 < 040)? "<%03o>": "%c", c1); + return SCPE_OK; + } */ - if (sw & SWMASK ('C')) /* character? not useful -- make it EBCDIC */ - sw |= SWMASK('E'); + if (sw & SWMASK ('C')) /* character? not useful -- make it EBCDIC */ + sw |= SWMASK('E'); - if (sw & SWMASK ('E')) { /* EBCDIC! */ - ch = ebcdic_to_ascii((val[0] >> 8) & 0xFF); /* take high byte first */ - fprintf (of, (ch < ' ')? "<%03o>": "%c", ch); - ch = ebcdic_to_ascii(val[0] & 0xFF); - fprintf (of, (ch < ' ')? "<%03o>": "%c", ch); - return SCPE_OK; - } + if (sw & SWMASK ('E')) { /* EBCDIC! */ + ch = ebcdic_to_ascii((val[0] >> 8) & 0xFF); /* take high byte first */ + fprintf (of, (ch < ' ')? "<%03o>": "%c", ch); + ch = ebcdic_to_ascii(val[0] & 0xFF); + fprintf (of, (ch < ' ')? "<%03o>": "%c", ch); + return SCPE_OK; + } - if (sw & SWMASK ('H')) { /* HOLLERITH! now THIS is useful! */ - ch = hollerith_to_ascii((int16) val[0]); - fprintf (of, (ch < ' ')? "<%03o>": "%c", ch); - return SCPE_OK; - } + if (sw & SWMASK ('H')) { /* HOLLERITH! now THIS is useful! */ + ch = hollerith_to_ascii((int16) val[0]); + fprintf (of, (ch < ' ')? "<%03o>": "%c", ch); + return SCPE_OK; + } - if (! (sw & SWMASK ('M'))) - return SCPE_ARG; + if (! (sw & SWMASK ('M'))) + return SCPE_ARG; - IR = val[0]; - OP = (IR >> 11) & 0x1F; /* opcode */ - F = IR & 0x0400; /* format bit: 1 = long instr */ - TAG = IR & 0x0300; /* tag bits: index reg select */ - if (TAG) - TAG >>= 8; + IR = val[0]; + OP = (IR >> 11) & 0x1F; /* opcode */ + F = IR & 0x0400; /* format bit: 1 = long instr */ + TAG = IR & 0x0300; /* tag bits: index reg select */ + if (TAG) + TAG >>= 8; - if (F) { /* long instruction, ASSUME it's valid (have to decrement IAR if not) */ - INDIR = IR & 0x0080; /* indirect bit */ - DSPLC = IR & 0x007F; /* displacement or modifier */ - if (DSPLC & 0x0040) - DSPLC |= ~ 0x7F; /* sign extend */ + if (F) { /* long instruction, ASSUME it's valid (have to decrement IAR if not) */ + INDIR = IR & 0x0080; /* indirect bit */ + DSPLC = IR & 0x007F; /* displacement or modifier */ + if (DSPLC & 0x0040) + DSPLC |= ~ 0x7F; /* sign extend */ - eaddr = val[1]; /* get reference address */ - } - else { /* short instruction, use displacement */ - INDIR = 0; /* never indirect */ - DSPLC = IR & 0x00FF; /* get displacement */ - if (DSPLC & 0x0080) - DSPLC |= ~ 0xFF; + eaddr = val[1]; /* get reference address */ + } + else { /* short instruction, use displacement */ + INDIR = 0; /* never indirect */ + DSPLC = IR & 0x00FF; /* get displacement */ + if (DSPLC & 0x0080) + DSPLC |= ~ 0xFF; - eaddr = DSPLC; - if (relative[OP] && ! TAG) - eaddr += addr+1; /* turn displacement into address */ - } + eaddr = DSPLC; + if (relative[OP] && ! TAG) + eaddr += addr+1; /* turn displacement into address */ + } - mnem = opcode[OP]; /* get mnemonic */ - if (is_1800) { /* these two are defined on the 1800 but undefined on the 1130 */ - if (OP == 0x16) - mnem = "CMP "; - else if (OP == 0x17) - mnem = "DCMP"; - } + mnem = opcode[OP]; /* get mnemonic */ + if (is_1800) { /* these two are defined on the 1800 but undefined on the 1130 */ + if (OP == 0x16) + mnem = "CMP "; + else if (OP == 0x17) + mnem = "DCMP"; + } - if (OP == 0x02) { /* left shifts are special */ - mnem = lsopcode[(DSPLC >> 6) & 0x0003]; - DSPLC &= 0x003F; - eaddr = DSPLC; - } - else if (OP == 0x03) { /* right shifts too */ - mnem = rsopcode[(DSPLC >> 6) & 0x0003]; - DSPLC &= 0x003F; - eaddr = DSPLC; - } - else if ((OP == 0x08 && F)|| OP == 0x09) { /* BSI L and BSC any */ - if (OP == 0x09 && (IR & 0x40)) - mnem = "BOSC"; + if (OP == 0x02) { /* left shifts are special */ + mnem = lsopcode[(DSPLC >> 6) & 0x0003]; + DSPLC &= 0x003F; + eaddr = DSPLC; + } + else if (OP == 0x03) { /* right shifts too */ + mnem = rsopcode[(DSPLC >> 6) & 0x0003]; + DSPLC &= 0x003F; + eaddr = DSPLC; + } + else if ((OP == 0x08 && F)|| OP == 0x09) { /* BSI L and BSC any */ + if (OP == 0x09 && (IR & 0x40)) + mnem = "BOSC"; - tst[0] = '\0'; - if (DSPLC & 0x20) strcat(tst, "Z"); - if (DSPLC & 0x10) strcat(tst, "-"); - if (DSPLC & 0x08) strcat(tst, "+"); - if (DSPLC & 0x04) strcat(tst, "E"); - if (DSPLC & 0x02) strcat(tst, "C"); - if (DSPLC & 0x01) strcat(tst, "O"); + tst[0] = '\0'; + if (DSPLC & 0x20) strcat(tst, "Z"); + if (DSPLC & 0x10) strcat(tst, "-"); + if (DSPLC & 0x08) strcat(tst, "+"); + if (DSPLC & 0x04) strcat(tst, "E"); + if (DSPLC & 0x02) strcat(tst, "C"); + if (DSPLC & 0x01) strcat(tst, "O"); - if (F) { - fprintf(of, "%04x %s %c%c %s,%04x ", IR & 0xFFFF, mnem, F ? (INDIR ? 'I' : 'L') : ' ', tagc[TAG], tst, eaddr & 0xFFFF); - return -1; - } - fprintf(of, "%04x %s %c%c %s ", IR & 0xFFFF, mnem, F ? (INDIR ? 'I' : 'L') : ' ', tagc[TAG], tst); - return SCPE_OK; - } - else if (OP == 0x0e && TAG == 0) { /* MDX with no tag => MDM or jump */ - if (F) { - fprintf(of, "%04x %s %c%c %04x,%x (%d) ", IR & 0xFFFF, "MDM ", (INDIR ? 'I' : 'L'), tagc[TAG], eaddr & 0xFFFF, DSPLC & 0xFFFF, DSPLC); - return -1; - } - mnem = "JMP "; - } + if (F) { + fprintf(of, "%04x %s %c%c %s,%04x ", IR & 0xFFFF, mnem, F ? (INDIR ? 'I' : 'L') : ' ', tagc[TAG], tst, eaddr & 0xFFFF); + return -1; + } + fprintf(of, "%04x %s %c%c %s ", IR & 0xFFFF, mnem, F ? (INDIR ? 'I' : 'L') : ' ', tagc[TAG], tst); + return SCPE_OK; + } + else if (OP == 0x0e && TAG == 0) { /* MDX with no tag => MDM or jump */ + if (F) { + fprintf(of, "%04x %s %c%c %04x,%x (%d) ", IR & 0xFFFF, "MDM ", (INDIR ? 'I' : 'L'), tagc[TAG], eaddr & 0xFFFF, DSPLC & 0xFFFF, DSPLC); + return -1; + } + mnem = "JMP "; + } - fprintf(of, "%04x %s %c%c %04x ", IR & 0xFFFF, mnem, F ? (INDIR ? 'I' : 'L') : ' ', tagc[TAG], eaddr & 0xFFFF); - return F ? -1 : SCPE_OK; /* inform how many words we read */ + fprintf(of, "%04x %s %c%c %04x ", IR & 0xFFFF, mnem, F ? (INDIR ? 'I' : 'L') : ' ', tagc[TAG], eaddr & 0xFFFF); + return F ? -1 : SCPE_OK; /* inform how many words we read */ } int32 get_reg (char *cptr, const char *strings[], char mchar) @@ -404,111 +404,111 @@ return -1; /* Number or memory address Inputs: - *cptr = pointer to input string - *dptr = pointer to output displacement - *pflag = pointer to accumulating flags + *cptr = pointer to input string + *dptr = pointer to output displacement + *pflag = pointer to accumulating flags Outputs: - cptr = pointer to next character in input string - NULL if parsing error + cptr = pointer to next character in input string + NULL if parsing error Flags: 0 (no result), A_NUM (number), A_REL (relative) */ char *get_addr (char *cptr, int32 *dptr, int32 *pflag) { - return 0; + return 0; } /* Specifier decode Inputs: - *cptr = pointer to input string - addr = current PC - n1 = 0 if no extra word used - -1 if extra word used in prior decode - *sptr = pointer to output specifier - *dptr = pointer to output displacement - cflag = true if parsing for the CPU - iflag = true if integer specifier + *cptr = pointer to input string + addr = current PC + n1 = 0 if no extra word used + -1 if extra word used in prior decode + *sptr = pointer to output specifier + *dptr = pointer to output displacement + cflag = true if parsing for the CPU + iflag = true if integer specifier Outputs: - status = = -1 extra word decoded - = 0 ok - = +1 error + status = = -1 extra word decoded + = 0 ok + = +1 error */ t_stat get_spec (char *cptr, t_addr addr, int32 n1, int32 *sptr, t_value *dptr, - int32 cflag, int32 iflag) + int32 cflag, int32 iflag) { - return -1; + return -1; } /* Symbolic input Inputs: - *cptr = pointer to input string - addr = current PC - *uptr = pointer to unit - *val = pointer to output values - sw = switches + *cptr = pointer to input string + addr = current PC + *uptr = pointer to unit + *val = pointer to output values + sw = switches Outputs: - status = > 0 error code - <= 0 -number of extra words + status = > 0 error code + <= 0 -number of extra words */ t_stat parse_sym (CONST char *cptr, t_addr addr, UNIT *uptr, t_value *val, int32 sw) { - return SCPE_ARG; + return SCPE_ARG; } #ifndef _WIN32 int strnicmp (const char *a, const char *b, size_t n) { - int ca, cb; + int ca, cb; - if (n == 0) return 0; /* zero length compare is equal */ + if (n == 0) return 0; /* zero length compare is equal */ - for (;;) { - if ((ca = *a) == 0) /* get character, stop on null terminator */ - return *b ? -1 : 0; + for (;;) { + if ((ca = *a) == 0) /* get character, stop on null terminator */ + return *b ? -1 : 0; - if (ca >= 'a' && ca <= 'z') /* fold lowercase to uppercase */ - ca -= 32; + if (ca >= 'a' && ca <= 'z') /* fold lowercase to uppercase */ + ca -= 32; - cb = *b; - if (cb >= 'a' && cb <= 'z') - cb -= 32; + cb = *b; + if (cb >= 'a' && cb <= 'z') + cb -= 32; - if ((ca -= cb) != 0) /* if different, return comparison */ - return ca; + if ((ca -= cb) != 0) /* if different, return comparison */ + return ca; - a++, b++; + a++, b++; - if (--n == 0) /* still equal after n characters? quit now */ - return 0; - } + if (--n == 0) /* still equal after n characters? quit now */ + return 0; + } } int strcmpi (const char *a, const char *b) { - int ca, cb; + int ca, cb; - for (;;) { - if ((ca = *a) == 0) /* get character, stop on null terminator */ - return *b ? -1 : 0; + for (;;) { + if ((ca = *a) == 0) /* get character, stop on null terminator */ + return *b ? -1 : 0; - if (ca >= 'a' && ca <= 'z') /* fold lowercase to uppercase */ - ca -= 32; + if (ca >= 'a' && ca <= 'z') /* fold lowercase to uppercase */ + ca -= 32; - cb = *b; - if (cb >= 'a' && cb <= 'z') - cb -= 32; + cb = *b; + if (cb >= 'a' && cb <= 'z') + cb -= 32; - if ((ca -= cb) != 0) /* if different, return comparison */ - return ca; + if ((ca -= cb) != 0) /* if different, return comparison */ + return ca; - a++, b++; - } + a++, b++; + } } #endif diff --git a/Ibm1130/ibm1130_t2741.c b/Ibm1130/ibm1130_t2741.c index 8cb0d6b2..ec855799 100644 --- a/Ibm1130/ibm1130_t2741.c +++ b/Ibm1130/ibm1130_t2741.c @@ -9,34 +9,34 @@ #define DEBUG_T2741 -static TMLN t2741_ldsc = { 0 }; /* line descr for telnet attachment */ -static TMXR t2741_tmxr = { 1, 0, 0, &t2741_ldsc }; /* line mux for telnet attachment */ +static TMLN t2741_ldsc = { 0 }; /* line descr for telnet attachment */ +static TMXR t2741_tmxr = { 1, 0, 0, &t2741_ldsc }; /* line mux for telnet attachment */ -#define T2741_DSW_TRANSMIT_NOT_READY 0x4000 -#define T2741_DSW_READ_RESPONSE 0x1000 -#define T2741_DSW_READ_OVERRUN 0x0800 -#define T2741_DSW_ATTENTION 0x0010 +#define T2741_DSW_TRANSMIT_NOT_READY 0x4000 +#define T2741_DSW_READ_RESPONSE 0x1000 +#define T2741_DSW_READ_OVERRUN 0x0800 +#define T2741_DSW_ATTENTION 0x0010 #define IS_ONLINE(u) (((u)->flags & (UNIT_ATT|UNIT_DIS)) == UNIT_ATT) -#define UNIT_V_PHYSICAL_TERM (UNIT_V_UF + 0) /* indicates not telnet but attachment to real terminal */ -#define UNIT_V_UPCASE (UNIT_V_UF + 1) /* indicates upshift performed */ -#define UNIT_V_SENDING (UNIT_V_UF + 2) /* indicates not telnet but attachment to real terminal */ -#define UNIT_V_RECEIVING (UNIT_V_UF + 3) /* indicates not telnet but attachment to real terminal */ +#define UNIT_V_PHYSICAL_TERM (UNIT_V_UF + 0) /* indicates not telnet but attachment to real terminal */ +#define UNIT_V_UPCASE (UNIT_V_UF + 1) /* indicates upshift performed */ +#define UNIT_V_SENDING (UNIT_V_UF + 2) /* indicates not telnet but attachment to real terminal */ +#define UNIT_V_RECEIVING (UNIT_V_UF + 3) /* indicates not telnet but attachment to real terminal */ -#define UNIT_PHYSICAL_TERM (1u << UNIT_V_PHYSICAL_TERM) -#define UNIT_UPCASE (1u << UNIT_V_UPCASE) -#define UNIT_SENDING (1u << UNIT_V_SENDING) -#define UNIT_RECEIVING (1u << UNIT_V_RECEIVING) +#define UNIT_PHYSICAL_TERM (1u << UNIT_V_PHYSICAL_TERM) +#define UNIT_UPCASE (1u << UNIT_V_UPCASE) +#define UNIT_SENDING (1u << UNIT_V_SENDING) +#define UNIT_RECEIVING (1u << UNIT_V_RECEIVING) -#define CODE_SHIFTUP 0x1C00 -#define CODE_SHIFTDOWN 0x7C00 -#define CODE_CIRCLEC 0x1F00 -#define CODE_CIRCLED 0x1600 -#define CODE_RETURN 0x5B00 -#define CODE_LINEFEED 0x3B00 -#define CODE_ATTENTION 0x0001 /* pseudocode, never really returned as a received character */ -#define CODE_UNKNOWN 0x0000 +#define CODE_SHIFTUP 0x1C00 +#define CODE_SHIFTDOWN 0x7C00 +#define CODE_CIRCLEC 0x1F00 +#define CODE_CIRCLED 0x1600 +#define CODE_RETURN 0x5B00 +#define CODE_LINEFEED 0x3B00 +#define CODE_ATTENTION 0x0001 /* pseudocode, never really returned as a received character */ +#define CODE_UNKNOWN 0x0000 static t_stat t2741_svc (UNIT *uptr); static t_stat t2741_reset (DEVICE *dptr); @@ -46,343 +46,343 @@ static uint16 ascii_to_t2741 (int ascii); static const char * t2741_to_ascii (uint16 code); static void set_transmit_notready (void); -static uint16 t2741_dsw = T2741_DSW_TRANSMIT_NOT_READY; /* device status word */ -static uint32 t2741_swait = 200; /* character send wait */ -static uint32 t2741_rwait = 2000; /* character receive wait */ -static uint16 t2741_char = 0; /* last character received */ -static int overrun = FALSE; +static uint16 t2741_dsw = T2741_DSW_TRANSMIT_NOT_READY; /* device status word */ +static uint32 t2741_swait = 200; /* character send wait */ +static uint32 t2741_rwait = 2000; /* character receive wait */ +static uint16 t2741_char = 0; /* last character received */ +static int overrun = FALSE; static uint32 t2741_socket = 1130; UNIT t2741_unit[1] = { - { UDATA (&t2741_svc, UNIT_ATTABLE, 0) }, + { UDATA (&t2741_svc, UNIT_ATTABLE, 0) }, }; REG t2741_reg[] = { - { HRDATA (DSW, t2741_dsw, 16) }, /* device status word */ - { DRDATA (RTIME, t2741_rwait, 24), PV_LEFT }, /* character receive wait */ - { DRDATA (STIME, t2741_swait, 24), PV_LEFT }, /* character send wait */ - { DRDATA (SOCKET, t2741_socket,16), PV_LEFT }, /* socket number */ - { HRDATA (LASTCHAR, t2741_char, 16), PV_LEFT }, /* last character read */ - { NULL } }; + { HRDATA (DSW, t2741_dsw, 16) }, /* device status word */ + { DRDATA (RTIME, t2741_rwait, 24), PV_LEFT }, /* character receive wait */ + { DRDATA (STIME, t2741_swait, 24), PV_LEFT }, /* character send wait */ + { DRDATA (SOCKET, t2741_socket,16), PV_LEFT }, /* socket number */ + { HRDATA (LASTCHAR, t2741_char, 16), PV_LEFT }, /* last character read */ + { NULL } }; DEVICE t2741_dev = { - "T2741", t2741_unit, t2741_reg, NULL, - 1, 16, 16, 1, 16, 16, - NULL, NULL, t2741_reset, - NULL, t2741_attach, t2741_detach}; + "T2741", t2741_unit, t2741_reg, NULL, + 1, 16, 16, 1, 16, 16, + NULL, NULL, t2741_reset, + NULL, t2741_attach, t2741_detach}; /* xio_t2741_terminal - XIO command interpreter for the terminal adapter */ void xio_t2741_terminal (int32 iocc_addr, int32 iocc_func, int32 iocc_mod) { - char msg[80]; - uint16 code; + char msg[80]; + uint16 code; - switch (iocc_func) { - case XIO_READ: /* read: return last character read */ - code = t2741_char & 0xFF00; - M[iocc_addr & mem_mask] = code; - overrun = FALSE; + switch (iocc_func) { + case XIO_READ: /* read: return last character read */ + code = t2741_char & 0xFF00; + M[iocc_addr & mem_mask] = code; + overrun = FALSE; #ifdef DEBUG_T2741 -/* trace_both("T2741 %04x READ %02x %s", prev_IAR, code >> 8, t2741_to_ascii(code)); */ +/* trace_both("T2741 %04x READ %02x %s", prev_IAR, code >> 8, t2741_to_ascii(code)); */ #endif - break; + break; - case XIO_WRITE: /* write: initiate character send */ - code = M[iocc_addr & mem_mask] & 0xFF00; + case XIO_WRITE: /* write: initiate character send */ + code = M[iocc_addr & mem_mask] & 0xFF00; #ifdef DEBUG_T2741 - trace_both("T2741 %04x SEND %02x %s", prev_IAR, code >> 8, t2741_to_ascii(code)); + trace_both("T2741 %04x SEND %02x %s", prev_IAR, code >> 8, t2741_to_ascii(code)); #endif - SETBIT(t2741_dsw, T2741_DSW_TRANSMIT_NOT_READY); - SETBIT(t2741_unit->flags, UNIT_SENDING); + SETBIT(t2741_dsw, T2741_DSW_TRANSMIT_NOT_READY); + SETBIT(t2741_unit->flags, UNIT_SENDING); - if (code == CODE_SHIFTUP) - SETBIT(t2741_unit->flags, UNIT_UPCASE); - else if (code == CODE_SHIFTDOWN) - CLRBIT(t2741_unit->flags, UNIT_UPCASE); + if (code == CODE_SHIFTUP) + SETBIT(t2741_unit->flags, UNIT_UPCASE); + else if (code == CODE_SHIFTDOWN) + CLRBIT(t2741_unit->flags, UNIT_UPCASE); - sim_activate(t2741_unit, t2741_swait); /* schedule interrupt */ - break; + sim_activate(t2741_unit, t2741_swait); /* schedule interrupt */ + break; - case XIO_SENSE_DEV: /* sense device status */ - ACC = t2741_dsw; + case XIO_SENSE_DEV: /* sense device status */ + ACC = t2741_dsw; #ifdef DEBUG_T2741 -/* trace_both("T2741 %04x SENS %04x%s", prev_IAR, t2741_dsw, (iocc_mod & 0x01) ? " reset" : ""); */ +/* trace_both("T2741 %04x SENS %04x%s", prev_IAR, t2741_dsw, (iocc_mod & 0x01) ? " reset" : ""); */ #endif - if (iocc_mod & 0x01) { /* reset interrupts */ - CLRBIT(t2741_dsw, T2741_DSW_READ_RESPONSE); - CLRBIT(ILSW[4], ILSW_4_T2741_TERMINAL); - } - break; + if (iocc_mod & 0x01) { /* reset interrupts */ + CLRBIT(t2741_dsw, T2741_DSW_READ_RESPONSE); + CLRBIT(ILSW[4], ILSW_4_T2741_TERMINAL); + } + break; - case XIO_CONTROL: /* control: do something to interface */ + case XIO_CONTROL: /* control: do something to interface */ #ifdef DEBUG_T2741 - trace_both("T2741 %04x CTRL %04x", prev_IAR, iocc_mod &0xFF); + trace_both("T2741 %04x CTRL %04x", prev_IAR, iocc_mod &0xFF); #endif - SETBIT(t2741_unit->flags, UNIT_RECEIVING); /* set mode to receive mode */ - if (IS_ONLINE(t2741_unit) && (t2741_char != 0 || ! feof(t2741_unit->fileref))) { - sim_activate(t2741_unit, t2741_rwait); - t2741_char = (CODE_CIRCLED >> 8); /* first character received after turnaround is circled */ - } - break; + SETBIT(t2741_unit->flags, UNIT_RECEIVING); /* set mode to receive mode */ + if (IS_ONLINE(t2741_unit) && (t2741_char != 0 || ! feof(t2741_unit->fileref))) { + sim_activate(t2741_unit, t2741_rwait); + t2741_char = (CODE_CIRCLED >> 8); /* first character received after turnaround is circled */ + } + break; - default: - sprintf(msg, "Invalid T2741 XIO function %x", iocc_func); - xio_error(msg); - } + default: + sprintf(msg, "Invalid T2741 XIO function %x", iocc_func); + xio_error(msg); + } } static void set_transmit_notready (void) { - if (IS_ONLINE(t2741_unit) && ! (t2741_unit->flags & UNIT_SENDING)) - CLRBIT(t2741_dsw, T2741_DSW_TRANSMIT_NOT_READY); - else - SETBIT(t2741_dsw, T2741_DSW_TRANSMIT_NOT_READY); + if (IS_ONLINE(t2741_unit) && ! (t2741_unit->flags & UNIT_SENDING)) + CLRBIT(t2741_dsw, T2741_DSW_TRANSMIT_NOT_READY); + else + SETBIT(t2741_dsw, T2741_DSW_TRANSMIT_NOT_READY); } static t_stat t2741_svc (UNIT *uptr) { - int ch = EOF; - uint16 code; + int ch = EOF; + uint16 code; - if (uptr->flags & UNIT_SENDING) { /* xmit: no interrupt, as far as I know. just clr busy bit */ - CLRBIT(uptr->flags, UNIT_SENDING); - set_transmit_notready(); - } + if (uptr->flags & UNIT_SENDING) { /* xmit: no interrupt, as far as I know. just clr busy bit */ + CLRBIT(uptr->flags, UNIT_SENDING); + set_transmit_notready(); + } - if (uptr->flags & UNIT_RECEIVING) { /* rcv: fire interrupt */ - t2741_char <<= 8; + if (uptr->flags & UNIT_RECEIVING) { /* rcv: fire interrupt */ + t2741_char <<= 8; - if (t2741_char == 0) { /* there is no 2nd character from previous ascii input */ - if ((ch = getc(t2741_unit->fileref)) == EOF) - t2741_char = 0; - else { - if (ch == '\r') { /* if we get CR, jump to LF */ - if ((ch = getc(t2741_unit->fileref)) != '\n') { - ungetc(ch, t2741_unit->fileref); - ch = '\r'; - } - } + if (t2741_char == 0) { /* there is no 2nd character from previous ascii input */ + if ((ch = getc(t2741_unit->fileref)) == EOF) + t2741_char = 0; + else { + if (ch == '\r') { /* if we get CR, jump to LF */ + if ((ch = getc(t2741_unit->fileref)) != '\n') { + ungetc(ch, t2741_unit->fileref); + ch = '\r'; + } + } - if (ch == '\027') { - t2741_char = CODE_LINEFEED; /* attention key sends line feed character */ + if (ch == '\027') { + t2741_char = CODE_LINEFEED; /* attention key sends line feed character */ #ifdef DEBUG_T2741 - trace_both("T2741 ---- ATTENTION"); + trace_both("T2741 ---- ATTENTION"); #endif - SETBIT(t2741_dsw, T2741_DSW_ATTENTION); /* no character returned ? */ - } - else { - t2741_char = ascii_to_t2741(ch); /* translate to 2741 code(s) */ - } - } - } + SETBIT(t2741_dsw, T2741_DSW_ATTENTION); /* no character returned ? */ + } + else { + t2741_char = ascii_to_t2741(ch); /* translate to 2741 code(s) */ + } + } + } - code = t2741_char & 0xFF00; + code = t2741_char & 0xFF00; - if (t2741_char != 0) { - if (overrun) /* previous character was not picked up! */ - SETBIT(t2741_dsw, T2741_DSW_READ_OVERRUN); + if (t2741_char != 0) { + if (overrun) /* previous character was not picked up! */ + SETBIT(t2741_dsw, T2741_DSW_READ_OVERRUN); - SETBIT(t2741_dsw, T2741_DSW_READ_RESPONSE); - SETBIT(ILSW[4], ILSW_4_T2741_TERMINAL); /* issue interrupt */ - calc_ints(); + SETBIT(t2741_dsw, T2741_DSW_READ_RESPONSE); + SETBIT(ILSW[4], ILSW_4_T2741_TERMINAL); /* issue interrupt */ + calc_ints(); #ifdef DEBUG_T2741 - trace_both("T2741 ---- RCVD %02x '%s' RDRESP%s%s", code >> 8, t2741_to_ascii(code), - (t2741_dsw & T2741_DSW_READ_OVERRUN) ? "|OVERRUN" : "", - (t2741_dsw & T2741_DSW_ATTENTION) ? "|ATTENTION" : ""); + trace_both("T2741 ---- RCVD %02x '%s' RDRESP%s%s", code >> 8, t2741_to_ascii(code), + (t2741_dsw & T2741_DSW_READ_OVERRUN) ? "|OVERRUN" : "", + (t2741_dsw & T2741_DSW_ATTENTION) ? "|ATTENTION" : ""); #endif - overrun = TRUE; /* arm overrun flag */ - } + overrun = TRUE; /* arm overrun flag */ + } - if (t2741_char == CODE_CIRCLEC) /* end of line (CIRCLEC after RETURN) auto downshifts */ - CLRBIT(t2741_unit->flags, UNIT_UPCASE); + if (t2741_char == CODE_CIRCLEC) /* end of line (CIRCLEC after RETURN) auto downshifts */ + CLRBIT(t2741_unit->flags, UNIT_UPCASE); - if (t2741_char == 0 || code == CODE_CIRCLEC) - CLRBIT(uptr->flags, UNIT_RECEIVING); /* on enter or EOF, stop typing */ - else - sim_activate(t2741_unit, t2741_rwait); /* schedule next character to arrive */ - } + if (t2741_char == 0 || code == CODE_CIRCLEC) + CLRBIT(uptr->flags, UNIT_RECEIVING); /* on enter or EOF, stop typing */ + else + sim_activate(t2741_unit, t2741_rwait); /* schedule next character to arrive */ + } - return SCPE_OK; + return SCPE_OK; } static t_stat t2741_attach (UNIT *uptr, CONST char *cptr) { - int rval; + int rval; - if ((rval = attach_unit(uptr, cptr)) == SCPE_OK) { /* use standard attach */ - t2741_char = 0; - overrun = FALSE; + if ((rval = attach_unit(uptr, cptr)) == SCPE_OK) { /* use standard attach */ + t2741_char = 0; + overrun = FALSE; - CLRBIT(t2741_unit->flags, UNIT_UPCASE); + CLRBIT(t2741_unit->flags, UNIT_UPCASE); - if ((t2741_unit->flags & UNIT_RECEIVING) && ! feof(t2741_unit->fileref)) - sim_activate(t2741_unit, t2741_rwait); /* schedule interrupt */ - } + if ((t2741_unit->flags & UNIT_RECEIVING) && ! feof(t2741_unit->fileref)) + sim_activate(t2741_unit, t2741_rwait); /* schedule interrupt */ + } - set_transmit_notready(); + set_transmit_notready(); - return rval; + return rval; } static t_stat t2741_detach (UNIT *uptr) { - t_stat rval; + t_stat rval; - if (t2741_unit->flags & UNIT_RECEIVING) /* if receive was pending, cancel interrupt */ - sim_cancel(t2741_unit); + if (t2741_unit->flags & UNIT_RECEIVING) /* if receive was pending, cancel interrupt */ + sim_cancel(t2741_unit); - t2741_char = 0; - overrun = FALSE; + t2741_char = 0; + overrun = FALSE; - rval = detach_unit(uptr); /* use standard detach */ + rval = detach_unit(uptr); /* use standard detach */ - set_transmit_notready(); + set_transmit_notready(); - return rval; + return rval; } static t_stat t2741_reset (DEVICE *dptr) { - sim_cancel(t2741_unit); + sim_cancel(t2741_unit); - CLRBIT(t2741_unit->flags, UNIT_SENDING|UNIT_RECEIVING|UNIT_UPCASE); + CLRBIT(t2741_unit->flags, UNIT_SENDING|UNIT_RECEIVING|UNIT_UPCASE); - t2741_char = 0; - t2741_dsw = 0; - overrun = FALSE; + t2741_char = 0; + t2741_dsw = 0; + overrun = FALSE; - set_transmit_notready(); + set_transmit_notready(); - CLRBIT(ILSW[4], ILSW_4_T2741_TERMINAL); - calc_ints(); + CLRBIT(ILSW[4], ILSW_4_T2741_TERMINAL); + calc_ints(); - return SCPE_OK; + return SCPE_OK; } static struct tag_t2741_map { - int code; - int lcase, ucase; - t_bool shifts; + int code; + int lcase, ucase; + t_bool shifts; } t2741_map[] = { - {0x4F00, 'A', 'a', TRUE}, - {0x3700, 'B', 'b', TRUE}, - {0x2F00, 'C', 'c', TRUE}, - {0x2A00, 'D', 'd', TRUE}, - {0x2900, 'E', 'e', TRUE}, - {0x6700, 'F', '_', TRUE}, - {0x6200, 'G', 'g', TRUE}, - {0x3200, 'H', 'h', TRUE}, - {0x4C00, 'I', 'i', TRUE}, - {0x6100, 'J', 'j', TRUE}, - {0x2C00, 'K', '\'', TRUE}, - {0x3100, 'L', 'l', TRUE}, - {0x4300, 'M', '|', TRUE}, - {0x2500, 'N', 'n', TRUE}, - {0x5100, 'O', 'o', TRUE}, - {0x6800, 'P', '*', TRUE}, - {0x6D00, 'Q', '?', TRUE}, - {0x4A00, 'R', 'r', TRUE}, - {0x5200, 'S', 's', TRUE}, - {0x2000, 'T', '~', TRUE}, - {0x2600, 'U', 'u', TRUE}, - {0x4600, 'V', 'v', TRUE}, - {0x5700, 'W', 'w', TRUE}, - {0x2300, 'X', 'x', TRUE}, - {0x7300, 'Y', 'y', TRUE}, - {0x1500, 'Z', 'z', TRUE}, - {0x1300, '0', '&', TRUE}, - {0x0200, '1', '?', TRUE}, - {0x0400, '2', '?', TRUE}, - {0x0700, '3', '<', TRUE}, - {0x1000, '4', '?', TRUE}, - {0x0800, '5', '=', TRUE}, - {0x0D00, '6', '?', TRUE}, - {0x0B00, '7', '>', TRUE}, - {0x0E00, '8', '?', TRUE}, - {0x1600, '9', '|', TRUE}, - {0x7000, '/', '\\', TRUE}, - {0x7600, '+', '-', TRUE}, - {0x6400, '?', '?', TRUE}, - {0x4000, '<', '>', TRUE}, - {0x6B00, '[', '(', TRUE}, - {0x4900, ']', ')', TRUE}, - {0x6E00, ',', ';', TRUE}, - {0x4500, '.', ':', TRUE}, - {0x0100, ' ', 0, FALSE}, - {0x5B00, '\r', 0, FALSE}, - {0x3B00, '\n', 0, FALSE}, - {0x5D00, '\b', 0, FALSE}, - {0x5E00, '\t', 0, FALSE}, - {0x0001, '\027', 0, FALSE}, + {0x4F00, 'A', 'a', TRUE}, + {0x3700, 'B', 'b', TRUE}, + {0x2F00, 'C', 'c', TRUE}, + {0x2A00, 'D', 'd', TRUE}, + {0x2900, 'E', 'e', TRUE}, + {0x6700, 'F', '_', TRUE}, + {0x6200, 'G', 'g', TRUE}, + {0x3200, 'H', 'h', TRUE}, + {0x4C00, 'I', 'i', TRUE}, + {0x6100, 'J', 'j', TRUE}, + {0x2C00, 'K', '\'', TRUE}, + {0x3100, 'L', 'l', TRUE}, + {0x4300, 'M', '|', TRUE}, + {0x2500, 'N', 'n', TRUE}, + {0x5100, 'O', 'o', TRUE}, + {0x6800, 'P', '*', TRUE}, + {0x6D00, 'Q', '?', TRUE}, + {0x4A00, 'R', 'r', TRUE}, + {0x5200, 'S', 's', TRUE}, + {0x2000, 'T', '~', TRUE}, + {0x2600, 'U', 'u', TRUE}, + {0x4600, 'V', 'v', TRUE}, + {0x5700, 'W', 'w', TRUE}, + {0x2300, 'X', 'x', TRUE}, + {0x7300, 'Y', 'y', TRUE}, + {0x1500, 'Z', 'z', TRUE}, + {0x1300, '0', '&', TRUE}, + {0x0200, '1', '?', TRUE}, + {0x0400, '2', '?', TRUE}, + {0x0700, '3', '<', TRUE}, + {0x1000, '4', '?', TRUE}, + {0x0800, '5', '=', TRUE}, + {0x0D00, '6', '?', TRUE}, + {0x0B00, '7', '>', TRUE}, + {0x0E00, '8', '?', TRUE}, + {0x1600, '9', '|', TRUE}, + {0x7000, '/', '\\', TRUE}, + {0x7600, '+', '-', TRUE}, + {0x6400, '?', '?', TRUE}, + {0x4000, '<', '>', TRUE}, + {0x6B00, '[', '(', TRUE}, + {0x4900, ']', ')', TRUE}, + {0x6E00, ',', ';', TRUE}, + {0x4500, '.', ':', TRUE}, + {0x0100, ' ', 0, FALSE}, + {0x5B00, '\r', 0, FALSE}, + {0x3B00, '\n', 0, FALSE}, + {0x5D00, '\b', 0, FALSE}, + {0x5E00, '\t', 0, FALSE}, + {0x0001, '\027', 0, FALSE}, }; static uint16 ascii_to_t2741 (int ascii) { - int i; - uint16 rval = 0; + int i; + uint16 rval = 0; - ascii &= 0xFF; + ascii &= 0xFF; - if (ascii == '\n') /* turn newlines into returns + CIRCLED? */ - return CODE_RETURN | (CODE_CIRCLEC >> 8); + if (ascii == '\n') /* turn newlines into returns + CIRCLED? */ + return CODE_RETURN | (CODE_CIRCLEC >> 8); - for (i = sizeof(t2741_map)/sizeof(t2741_map[0]); --i >= 0; ) { - if (t2741_map[i].shifts) { - if (t2741_map[i].lcase == ascii) { - rval = t2741_map[i].code; - if (t2741_unit->flags & UNIT_UPCASE) { - CLRBIT(t2741_unit->flags, UNIT_UPCASE); - rval = CODE_SHIFTDOWN | (rval >> 8); - } - return rval; - } - if (t2741_map[i].ucase == ascii) { - rval = t2741_map[i].code; - if (! (t2741_unit->flags & UNIT_UPCASE)) { - SETBIT(t2741_unit->flags, UNIT_UPCASE); - rval = CODE_SHIFTUP | (rval >> 8); - } - return rval; - } - } - else if (t2741_map[i].lcase == ascii) - return t2741_map[i].code; - } + for (i = sizeof(t2741_map)/sizeof(t2741_map[0]); --i >= 0; ) { + if (t2741_map[i].shifts) { + if (t2741_map[i].lcase == ascii) { + rval = t2741_map[i].code; + if (t2741_unit->flags & UNIT_UPCASE) { + CLRBIT(t2741_unit->flags, UNIT_UPCASE); + rval = CODE_SHIFTDOWN | (rval >> 8); + } + return rval; + } + if (t2741_map[i].ucase == ascii) { + rval = t2741_map[i].code; + if (! (t2741_unit->flags & UNIT_UPCASE)) { + SETBIT(t2741_unit->flags, UNIT_UPCASE); + rval = CODE_SHIFTUP | (rval >> 8); + } + return rval; + } + } + else if (t2741_map[i].lcase == ascii) + return t2741_map[i].code; + } - return CODE_UNKNOWN; + return CODE_UNKNOWN; } static const char * t2741_to_ascii (uint16 code) { - int i; - static char string[2] = {'?', '\0'}; + int i; + static char string[2] = {'?', '\0'}; - switch (code) { - case CODE_SHIFTUP: return "SHIFTUP"; - case CODE_SHIFTDOWN: return "SHIFTDN"; - case CODE_CIRCLEC: return "CIRCLEC"; - case CODE_CIRCLED: return "CIRCLED"; - } + switch (code) { + case CODE_SHIFTUP: return "SHIFTUP"; + case CODE_SHIFTDOWN: return "SHIFTDN"; + case CODE_CIRCLEC: return "CIRCLEC"; + case CODE_CIRCLED: return "CIRCLED"; + } - for (i = sizeof(t2741_map)/sizeof(t2741_map[0]); --i >= 0; ) { - if (t2741_map[i].code == code) { - if (t2741_map[i].shifts) { - string[0] = (t2741_unit->flags & UNIT_UPCASE) ? t2741_map[i].ucase : t2741_map[i].lcase; - return string; - } - switch (t2741_map[i].lcase) { - case ' ': return " "; - case '\r': return "RETURN"; - case '\n': return "LINEFEED"; - case '\b': return "BS"; - case '\t': return "IDLE"; - } - break; - } - } + for (i = sizeof(t2741_map)/sizeof(t2741_map[0]); --i >= 0; ) { + if (t2741_map[i].code == code) { + if (t2741_map[i].shifts) { + string[0] = (t2741_unit->flags & UNIT_UPCASE) ? t2741_map[i].ucase : t2741_map[i].lcase; + return string; + } + switch (t2741_map[i].lcase) { + case ' ': return " "; + case '\r': return "RETURN"; + case '\n': return "LINEFEED"; + case '\b': return "BS"; + case '\t': return "IDLE"; + } + break; + } + } - return "?"; + return "?"; } diff --git a/Ibm1130/utils/asm1130.c b/Ibm1130/utils/asm1130.c index 3cbc2f4c..1f1166be 100644 --- a/Ibm1130/utils/asm1130.c +++ b/Ibm1130/utils/asm1130.c @@ -15,29 +15,29 @@ // ASM1130 - IBM 1130 Cross Assembler // // Version -// 1.14 - 2004Oct22 - Fixed problem with BSS complaining about negative -// sizes. This may be a fundamental problem with my using -// 32-bit expressions, but for now, it appears that just -// truncating the BSS size to 16 bits is sufficient to build DMS. -// 1.13 - 2004Jun05 - Fixed sign extension of constants in expressions. Statements -// like LD /FFFF were being assembled incorrectly. -// 1.12 - 2004Jun04 - Made WAIT instruction take a displacement value. -// Doesn't affect operation, but these are used as indicators -// in the IBM one-card diagnostic programs. -// Also -- should mention that the .IPL directive was -// removed some time ago. To create bootable cards, -// use -b flag to create binary output, and post-process the -// binary output with program "mkboot" -// 1.11 - 2004May22 - Added CMP, DCM, and DECS instructions for 1800, -// thanks to Kevin Everets. -// 1.10 - 2003Dec08 - Fixed opcode value for XCH instruction, thanks to -// Roger Simpson. -// 1.09 - 2003Aug03 - Added fxwrite so asm will write little-endian files -// on all CPUs. +// 1.14 - 2004Oct22 - Fixed problem with BSS complaining about negative +// sizes. This may be a fundamental problem with my using +// 32-bit expressions, but for now, it appears that just +// truncating the BSS size to 16 bits is sufficient to build DMS. +// 1.13 - 2004Jun05 - Fixed sign extension of constants in expressions. Statements +// like LD /FFFF were being assembled incorrectly. +// 1.12 - 2004Jun04 - Made WAIT instruction take a displacement value. +// Doesn't affect operation, but these are used as indicators +// in the IBM one-card diagnostic programs. +// Also -- should mention that the .IPL directive was +// removed some time ago. To create bootable cards, +// use -b flag to create binary output, and post-process the +// binary output with program "mkboot" +// 1.11 - 2004May22 - Added CMP, DCM, and DECS instructions for 1800, +// thanks to Kevin Everets. +// 1.10 - 2003Dec08 - Fixed opcode value for XCH instruction, thanks to +// Roger Simpson. +// 1.09 - 2003Aug03 - Added fxwrite so asm will write little-endian files +// on all CPUs. // 1.08 - 2003Mar18 - Fixed bug that complained about valid MDX displacement of +127 -// 1.07 - 2003Jan05 - Filenames are now left in lower case. SYMBOLS.SYS stays all upper case -// 1.06 - 2002May02 - Fixed bug in ebdic constants (data goes into low byte) -// First stab at adding ISS level # info, this is iffy +// 1.07 - 2003Jan05 - Filenames are now left in lower case. SYMBOLS.SYS stays all upper case +// 1.06 - 2002May02 - Fixed bug in ebdic constants (data goes into low byte) +// First stab at adding ISS level # info, this is iffy // 1.05 - 2002Apr24 - Made negative BSS size a warning not an error, as it // it's looking like it happens twice in PTMASMBL. // This version still doesn't do fixed point numbers and @@ -56,19 +56,19 @@ // --------------------------------------------------------------------------------- // // Usage: -// asm1130 [-bvsx] [-o[file]] [-l[file]] [-rN.M] file... +// asm1130 [-bvsx] [-o[file]] [-l[file]] [-rN.M] file... // // Description: -// -b binary output (.bin, relocatable absolute format) -// -v verbose -// -s print symbol table -// -x print cross references -// -o output file (default is name of first source file + extension .out or .bin) -// -l listing file (default is name of first source file + extension .lst) -// -y preload system symbol table SYMBOLS.SYS (from the current directory) -// -w write the system symbol table SYMBOLS.SYS in the current directory -// -W same as -w but don't prompt to confirm overwriting existing file -// -r set DMS release to release N version M, for sbrk cards +// -b binary output (.bin, relocatable absolute format) +// -v verbose +// -s print symbol table +// -x print cross references +// -o output file (default is name of first source file + extension .out or .bin) +// -l listing file (default is name of first source file + extension .lst) +// -y preload system symbol table SYMBOLS.SYS (from the current directory) +// -w write the system symbol table SYMBOLS.SYS in the current directory +// -W same as -w but don't prompt to confirm overwriting existing file +// -r set DMS release to release N version M, for sbrk cards // // Listing and symbol table output can be turned on by *LIST directives in the source, too // Listing file default extension is .LST @@ -78,15 +78,15 @@ // // Strict specification is: // -// label columns 1 - 5 -// opcode 7 - 10 -// tag 12 -// index 13 -// arguments 15 - 51 +// label columns 1 - 5 +// opcode 7 - 10 +// tag 12 +// index 13 +// arguments 15 - 51 // // Loose, indicated by presence of ascii tab character(s): // -// labelopcodeindex and format indicatorsarguments +// labelopcodeindex and format indicatorsarguments // // In both cases, the IBM convention that the arguments section ends with the // first nonblank applies. This means that ".DC 1, 2, 3" assembles only the 1! @@ -94,10 +94,10 @@ // Output file format is that used by the LOAD command in my 1130 // simulator. Lines are any of the following. All values are in hex: // -// @addr load address for subsequent words is addr -// Znwords Zero the next "nwords" and increment load address by nwords. -// =addr set IAR register to address addr (a convenience) -// value load value at load address and increment load address +// @addr load address for subsequent words is addr +// Znwords Zero the next "nwords" and increment load address by nwords. +// =addr set IAR register to address addr (a convenience) +// value load value at load address and increment load address // // Output file default extension is .OUT or .BIN for binary assemblies // @@ -117,10 +117,10 @@ // but not all directives. // // Revision History -// 16Apr02 1.03 Added sector break, relocation flag output -// 02Apr02 1.02 Fixed bug in BOSC: it CAN be a short instruction. -// Added directives for 1130 and 1800 IPL output formats -// Added conditional assembly directives +// 16Apr02 1.03 Added sector break, relocation flag output +// 02Apr02 1.02 Fixed bug in BOSC: it CAN be a short instruction. +// Added directives for 1130 and 1800 IPL output formats +// Added conditional assembly directives // --------------------------------------------------------------------------------- #include @@ -141,7 +141,7 @@ // Comment out this define to make @ and ' different in symbol names, keep to make equivalent #if defined(VMS) - # include /* to pick up 'unlink' */ + # include /* to pick up 'unlink' */ #endif #define BETWEEN(v,a,b) (((v) >= (a)) && ((v) <= (b))) @@ -153,12 +153,12 @@ int strcmpi (char *a, char *b); #endif -#define FIX_ATS +#define FIX_ATS -#define DMSVERSION "V2M12" /* required 5 characters on sector break card col 67-71 */ +#define DMSVERSION "V2M12" /* required 5 characters on sector break card col 67-71 */ -#define DOLLAREXIT "/38" // hmmm, are these really fixed absolutely in all versions? -#define DOLLARDUMP "/3F" +#define DOLLAREXIT "/38" // hmmm, are these really fixed absolutely in all versions? +#define DOLLARDUMP "/3F" #define SYSTEM_TABLE "SYMBOLS.SYS" @@ -166,66 +166,66 @@ #define TRUE 1 #define FALSE 0 -#define ISTV 0x33 // magic number from DMS R2V12 monitorm symbol @ISTV +#define ISTV 0x33 // magic number from DMS R2V12 monitorm symbol @ISTV -#define MAXLITERALS 300 +#define MAXLITERALS 300 #define MAXENTRIES 14 #define LINEFORMAT " %4ld | %s" #define LEFT_MARGIN " |" - // XXXX XXXX XXXX XXXX XXXX XXXX - // org w1 w2 w3 w4 w5 - // XXXX 1111 2222 3333 4444 LLLL | - // 12345678901234567890123456789012 + // XXXX XXXX XXXX XXXX XXXX XXXX + // org w1 w2 w3 w4 w5 + // XXXX 1111 2222 3333 4444 LLLL | + // 12345678901234567890123456789012 typedef enum {ABSOLUTE = 0, RELATIVE = 1, LIBF = 2, CALL = 3} RELOC; -typedef struct tag_symbol { // symbol table entry: - char *name; // name of symbol - int value; // value (absolute) - int pass; // defined during pass # - int defined; // definition state, see #defines below - RELOC relative; // ABSOLUTE = absolute, RELATIVE = relative - struct tag_symbol *next; // next symbol in list - struct tag_xref *xrefs; // cross references +typedef struct tag_symbol { // symbol table entry: + char *name; // name of symbol + int value; // value (absolute) + int pass; // defined during pass # + int defined; // definition state, see #defines below + RELOC relative; // ABSOLUTE = absolute, RELATIVE = relative + struct tag_symbol *next; // next symbol in list + struct tag_xref *xrefs; // cross references } SYMBOL, *PSYMBOL; -#define S_UNDEFINED 0 // values of 'defined' -#define S_PROVISIONAL 1 // usually an expression with forward references -#define S_DEFINED 2 // ordering must be undef < prov < def +#define S_UNDEFINED 0 // values of 'defined' +#define S_PROVISIONAL 1 // usually an expression with forward references +#define S_DEFINED 2 // ordering must be undef < prov < def -typedef struct tag_xref { // cross reference entry - char *fname; // filename - int lno; // line number - BOOL definition; // true = definition, false = reference - struct tag_xref *next; // next reference +typedef struct tag_xref { // cross reference entry + char *fname; // filename + int lno; // line number + BOOL definition; // true = definition, false = reference + struct tag_xref *next; // next reference } XREF, *PXREF; -typedef struct tag_expr { // expression result: absolute or relative - int value; - RELOC relative; +typedef struct tag_expr { // expression result: absolute or relative + int value; + RELOC relative; } EXPR; typedef enum {PROGTYPE_ABSOLUTE = 1, PROGTYPE_RELOCATABLE = 2, PROGTYPE_LIBF = 3, PROGTYPE_CALL = 4, - PROGTYPE_ISSLIBF = 5, PROGTYPE_ISSCALL = 6, PROGTYPE_ILS = 7} PROGTYPE; + PROGTYPE_ISSLIBF = 5, PROGTYPE_ISSCALL = 6, PROGTYPE_ILS = 7} PROGTYPE; typedef enum {SUBTYPE_INCORE = 0, SUBTYPE_FORDISK = 1, SUBTYPE_ARITH = 2, - SUBTYPE_FORNONDISK = 3, SUBTYPE_FUNCTION=8} SUBTYPE; + SUBTYPE_FORNONDISK = 3, SUBTYPE_FUNCTION=8} SUBTYPE; typedef enum {INTMODE_UNSPECIFIED = 0, INTMODE_MATCHREAL = 0x0080, INTMODE_ONEWORD = 0x0090} INTMODE; typedef enum {REALMODE_UNSPECIFIED = 0, REALMODE_STANDARD = 0x0001, REALMODE_EXTENDED = 0x0002} REALMODE; -#define OP_INDEXED 0x0300 // 1130 opcode modifier bits -#define OP_LONG 0x0400 -#define OP_INDIRECT 0x0080 +#define OP_INDEXED 0x0300 // 1130 opcode modifier bits +#define OP_LONG 0x0400 +#define OP_INDIRECT 0x0080 typedef enum {OUTMODE_LOAD, OUTMODE_1130, OUTMODE_1800, OUTMODE_BINARY} OUTMODE; #ifdef _WIN32 -# define OUTWRITEMODE "wb" // write outfile in binary mode -# define ENDLINE "\r\n" // explictly write CR/LF +# define OUTWRITEMODE "wb" // write outfile in binary mode +# define ENDLINE "\r\n" // explictly write CR/LF #else -# define OUTWRITEMODE "w" // use native mode +# define OUTWRITEMODE "w" // use native mode # define ENDLINE "\n" #endif @@ -247,107 +247,107 @@ char *usestr = "-o set output file; default is first input file + .out or .bin\n" "-l create listing file; default is first input file + .lst\n" "-r set dms version to VN RM for system SBRK cards\n" -"-8 enable IBM 1800 instructions"; // (alternately, rename or link executable to asm1800.exe) +"-8 enable IBM 1800 instructions"; // (alternately, rename or link executable to asm1800.exe) -BOOL verbose = FALSE; // verbose mode flag -BOOL tabformat = FALSE; // TRUE if tabs were seen in the file -BOOL enable_1800 = FALSE; // TRUE if 1800 mode is enabled by flag or executable name -int pass; // current assembler pass (1 or 2) -char curfn[256]; // current input file name -char progname[8]; // base name of primary input file -char *outfn = NULL; // output file name -int lno; // current input file line number -BOOL preload = FALSE; // preload system symbol table -BOOL savetable = FALSE; // write system symbol table -BOOL saveprompt = TRUE; // prompt before overwriting -int nerrors = 0; // count of errors -int nwarnings = 0; // count of warnings -FILE *fin = NULL; // current input file -FILE *fout = NULL; // output file stream -OUTMODE outmode = OUTMODE_LOAD; // output file mode -int outcols = 0; // columns written in using card output +BOOL verbose = FALSE; // verbose mode flag +BOOL tabformat = FALSE; // TRUE if tabs were seen in the file +BOOL enable_1800 = FALSE; // TRUE if 1800 mode is enabled by flag or executable name +int pass; // current assembler pass (1 or 2) +char curfn[256]; // current input file name +char progname[8]; // base name of primary input file +char *outfn = NULL; // output file name +int lno; // current input file line number +BOOL preload = FALSE; // preload system symbol table +BOOL savetable = FALSE; // write system symbol table +BOOL saveprompt = TRUE; // prompt before overwriting +int nerrors = 0; // count of errors +int nwarnings = 0; // count of warnings +FILE *fin = NULL; // current input file +FILE *fout = NULL; // output file stream +OUTMODE outmode = OUTMODE_LOAD; // output file mode +int outcols = 0; // columns written in using card output int maxiplcols = 80; -char cardid[9]; // characters used for IPL card ID -FILE *flist = NULL; // listing file stream -char *listfn = NULL; // listing filename -BOOL do_list = FALSE; // flag: create listing -BOOL passcount = FALSE; // flag: count passes only -BOOL list_on = TRUE; // listing is currently enabled -BOOL do_xref = FALSE; // cross reference listing -BOOL do_syms = FALSE; // symbol table listing -BOOL ended = FALSE; // end of current file -BOOL hasforward = FALSE; // true if there are any forward references -char listline[350]; // output listing line -BOOL line_error; // already saw an error on current line -RELOC relocate = RELATIVE; // relocatable assembly mode -BOOL assembled = FALSE; // true if any output has been generated -int nwout; // number of words written on current line -int org = 0; // output address (origin) -int org_advanced; // if TRUE, * means instruction addr+(value) during evaluation -int pta = -1; // program transfer address -BOOL cexpr = FALSE; // "C" expression syntax -PSYMBOL symbols = NULL; // the symbol table (linear search) -BOOL check_control = TRUE; // check for control cards -PROGTYPE progtype = PROGTYPE_RELOCATABLE; // program type -INTMODE intmode = INTMODE_UNSPECIFIED; // integer mode -REALMODE realmode = REALMODE_UNSPECIFIED; // real mode -int nintlevels = 0; // # of interrupt levels for ISS -int intlevel_primary = 0; // primary level for ISS and level for ILS -int intlevel_secondary = 0; // secondary level for ISS -int iss_number = 0; // ISS number -PSYMBOL entry[MAXENTRIES]; // entries for subroutines +char cardid[9]; // characters used for IPL card ID +FILE *flist = NULL; // listing file stream +char *listfn = NULL; // listing filename +BOOL do_list = FALSE; // flag: create listing +BOOL passcount = FALSE; // flag: count passes only +BOOL list_on = TRUE; // listing is currently enabled +BOOL do_xref = FALSE; // cross reference listing +BOOL do_syms = FALSE; // symbol table listing +BOOL ended = FALSE; // end of current file +BOOL hasforward = FALSE; // true if there are any forward references +char listline[350]; // output listing line +BOOL line_error; // already saw an error on current line +RELOC relocate = RELATIVE; // relocatable assembly mode +BOOL assembled = FALSE; // true if any output has been generated +int nwout; // number of words written on current line +int org = 0; // output address (origin) +int org_advanced; // if TRUE, * means instruction addr+(value) during evaluation +int pta = -1; // program transfer address +BOOL cexpr = FALSE; // "C" expression syntax +PSYMBOL symbols = NULL; // the symbol table (linear search) +BOOL check_control = TRUE; // check for control cards +PROGTYPE progtype = PROGTYPE_RELOCATABLE; // program type +INTMODE intmode = INTMODE_UNSPECIFIED; // integer mode +REALMODE realmode = REALMODE_UNSPECIFIED; // real mode +int nintlevels = 0; // # of interrupt levels for ISS +int intlevel_primary = 0; // primary level for ISS and level for ILS +int intlevel_secondary = 0; // secondary level for ISS +int iss_number = 0; // ISS number +PSYMBOL entry[MAXENTRIES]; // entries for subroutines int nentries = 0; int ndefined_files = 0; -struct lit { // accumulated literals waiting to be output - int value; // constant value - int tagno; // constant symbol tag number (e.g. _L001) - BOOL hex; // constant was expressed in hex - BOOL even; // constant was operand of a double-width instruction (e.g. AD) +struct lit { // accumulated literals waiting to be output + int value; // constant value + int tagno; // constant symbol tag number (e.g. _L001) + BOOL hex; // constant was expressed in hex + BOOL even; // constant was operand of a double-width instruction (e.g. AD) } literal[MAXLITERALS]; int n_literals = 0, lit_tag = 0; -BOOL requires_even_address; // target of current instruction -BOOL dmes_saved; // odd character left over from dmes ending in ' +BOOL requires_even_address; // target of current instruction +BOOL dmes_saved; // odd character left over from dmes ending in ' int dmes_savew; -char opfield[256]; // extracted operand field from source line -char dmsversion[12] = DMSVERSION; // version number for SBRK cards -const char whitespace[] = " \t"; // whitespace +char opfield[256]; // extracted operand field from source line +char dmsversion[12] = DMSVERSION; // version number for SBRK cards +const char whitespace[] = " \t"; // whitespace int ascii_to_ebcdic_table[128] = { // - 0x00,0x01,0x02,0x03,0x37,0x2d,0x2e,0x2f, 0x16,0x05,0x25,0x0b,0x0c,0x0d,0x0e,0x0f, + 0x00,0x01,0x02,0x03,0x37,0x2d,0x2e,0x2f, 0x16,0x05,0x25,0x0b,0x0c,0x0d,0x0e,0x0f, // - 0x10,0x11,0x12,0x13,0x3c,0x3d,0x32,0x26, 0x18,0x19,0x3f,0x27,0x1c,0x1d,0x1e,0x1f, + 0x10,0x11,0x12,0x13,0x3c,0x3d,0x32,0x26, 0x18,0x19,0x3f,0x27,0x1c,0x1d,0x1e,0x1f, // spac ! " # $ % & ' ( ) * + , - . / - 0x40,0x5a,0x7f,0x7b,0x5b,0x6c,0x50,0x7d, 0x4d,0x5d,0x5c,0x4e,0x6b,0x60,0x4b,0x61, + 0x40,0x5a,0x7f,0x7b,0x5b,0x6c,0x50,0x7d, 0x4d,0x5d,0x5c,0x4e,0x6b,0x60,0x4b,0x61, // 0 1 2 3 4 5 6 7 8 9 : ; < = > ? - 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7, 0xf8,0xf9,0x7a,0x5e,0x4c,0x7e,0x6e,0x6f, + 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7, 0xf8,0xf9,0x7a,0x5e,0x4c,0x7e,0x6e,0x6f, // @ A B C D E F G H I J K L M N O - 0x7c,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7, 0xc8,0xc9,0xd1,0xd2,0xd3,0xd4,0xd5,0xd6, + 0x7c,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7, 0xc8,0xc9,0xd1,0xd2,0xd3,0xd4,0xd5,0xd6, // P Q R S T U V W X Y Z [ \ ] & _ - 0xd7,0xd8,0xd9,0xe2,0xe3,0xe4,0xe5,0xe6, 0xe7,0xe8,0xe9,0xba,0xe0,0xbb,0xb0,0x6d, + 0xd7,0xd8,0xd9,0xe2,0xe3,0xe4,0xe5,0xe6, 0xe7,0xe8,0xe9,0xba,0xe0,0xbb,0xb0,0x6d, // a b c d e f g h i j k l m n o - 0x79,0x81,0x82,0x83,0x84,0x85,0x86,0x87, 0x88,0x89,0x91,0x92,0x93,0x94,0x95,0x96, + 0x79,0x81,0x82,0x83,0x84,0x85,0x86,0x87, 0x88,0x89,0x91,0x92,0x93,0x94,0x95,0x96, // p q r s t u v w x y z { | } ~ - 0x97,0x98,0x99,0xa2,0xa3,0xa4,0xa5,0xa6, 0xa7,0xa8,0xa9,0xc0,0x4f,0xd0,0xa1,0x07, + 0x97,0x98,0x99,0xa2,0xa3,0xa4,0xa5,0xa6, 0xa7,0xa8,0xa9,0xc0,0x4f,0xd0,0xa1,0x07, }; int ascii_to_1403_table[128] = { /* 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f */ - 0x7f,0x7f,0x7f,0x7f,0x7f,0x7f,0x7f,0x7f, 0x7f,0x7f,0x7f,0x7f,0x7f,0x7f,0x7f,0x7f, - 0x7f,0x7f,0x7f,0x7f,0x7f,0x7f,0x7f,0x7f, 0x7f,0x7f,0x7f,0x7f,0x7f,0x7f,0x7f,0x7f, - 0x7f,0x7f,0x7f,0x7f,0x62,0x7f,0x15,0x0b, 0x57,0x2f,0x23,0x6d,0x16,0x61,0x6e,0x4c, - 0x49,0x40,0x01,0x02,0x43,0x04,0x45,0x46, 0x07,0x08,0x7f,0x7f,0x7f,0x4a,0x7f,0x7f, - 0x7f,0x64,0x25,0x26,0x67,0x68,0x29,0x2a, 0x6b,0x2c,0x58,0x19,0x1a,0x5b,0x1c,0x5d, - 0x5e,0x1f,0x20,0x0d,0x0e,0x4f,0x10,0x51, 0x52,0x13,0x54,0x7f,0x7f,0x7f,0x7f,0x7f, - 0x7f,0x64,0x25,0x26,0x67,0x68,0x29,0x2a, 0x6b,0x2c,0x58,0x19,0x1a,0x5b,0x1c,0x5d, - 0x5e,0x1f,0x20,0x0d,0x0e,0x4f,0x10,0x51, 0x52,0x13,0x54,0x7f,0x7f,0x7f,0x7f,0x7f + 0x7f,0x7f,0x7f,0x7f,0x7f,0x7f,0x7f,0x7f, 0x7f,0x7f,0x7f,0x7f,0x7f,0x7f,0x7f,0x7f, + 0x7f,0x7f,0x7f,0x7f,0x7f,0x7f,0x7f,0x7f, 0x7f,0x7f,0x7f,0x7f,0x7f,0x7f,0x7f,0x7f, + 0x7f,0x7f,0x7f,0x7f,0x62,0x7f,0x15,0x0b, 0x57,0x2f,0x23,0x6d,0x16,0x61,0x6e,0x4c, + 0x49,0x40,0x01,0x02,0x43,0x04,0x45,0x46, 0x07,0x08,0x7f,0x7f,0x7f,0x4a,0x7f,0x7f, + 0x7f,0x64,0x25,0x26,0x67,0x68,0x29,0x2a, 0x6b,0x2c,0x58,0x19,0x1a,0x5b,0x1c,0x5d, + 0x5e,0x1f,0x20,0x0d,0x0e,0x4f,0x10,0x51, 0x52,0x13,0x54,0x7f,0x7f,0x7f,0x7f,0x7f, + 0x7f,0x64,0x25,0x26,0x67,0x68,0x29,0x2a, 0x6b,0x2c,0x58,0x19,0x1a,0x5b,0x1c,0x5d, + 0x5e,0x1f,0x20,0x0d,0x0e,0x4f,0x10,0x51, 0x52,0x13,0x54,0x7f,0x7f,0x7f,0x7f,0x7f }; -#include "../ibm1130_conout.h" /* conout_to_ascii_table */ -#include "../ibm1130_prtwheel.h" /* 1132 printer printwheel data */ +#include "../ibm1130_conout.h" /* conout_to_ascii_table */ +#include "../ibm1130_prtwheel.h" /* 1132 printer printwheel data */ // --------------------------------------------------------------------------------- // PROTOTYPES @@ -400,68 +400,68 @@ int signextend (int v); int main (int argc, char **argv) { - int i, sawfile = FALSE; + int i, sawfile = FALSE; - init(argc, argv); // initialize, process flags + init(argc, argv); // initialize, process flags - startpass(1); // first pass, process files + startpass(1); // first pass, process files - for (i = 1; i < argc; i++) - if (*argv[i] != '-') - proc(argv[i]), sawfile = TRUE; + for (i = 1; i < argc; i++) + if (*argv[i] != '-') + proc(argv[i]), sawfile = TRUE; - if (! sawfile) // should have seen at least one file - bail(usestr); + if (! sawfile) // should have seen at least one file + bail(usestr); - if (passcount) { - passreport(); - return 0; - } + if (passcount) { + passreport(); + return 0; + } - startpass(2); // second pass, process files again + startpass(2); // second pass, process files again - for (i = 1; i < argc; i++) - if (*argv[i] != '-') - proc(argv[i]); + for (i = 1; i < argc; i++) + if (*argv[i] != '-') + proc(argv[i]); - if (outmode == OUTMODE_LOAD) { - if (pta >= 0) // write start address to the load file - fprintf(fout, "=%04x" ENDLINE, pta & 0xFFFF); - } - else - bincard_endcard(); + if (outmode == OUTMODE_LOAD) { + if (pta >= 0) // write start address to the load file + fprintf(fout, "=%04x" ENDLINE, pta & 0xFFFF); + } + else + bincard_endcard(); - if (flist) { - if (nerrors || nwarnings) { // summarize (or summarise) - if (nerrors == 0) - fprintf(flist, "There %s ", (nwarnings == 1) ? "was" : "were"); - else - fprintf(flist, "\nThere %s %d error%s %s", - (nerrors == 1) ? "was" : "were", nerrors, (nerrors == 1) ? "" : "s", nwarnings ? "and " : ""); + if (flist) { + if (nerrors || nwarnings) { // summarize (or summarise) + if (nerrors == 0) + fprintf(flist, "There %s ", (nwarnings == 1) ? "was" : "were"); + else + fprintf(flist, "\nThere %s %d error%s %s", + (nerrors == 1) ? "was" : "were", nerrors, (nerrors == 1) ? "" : "s", nwarnings ? "and " : ""); - if (nwarnings > 0) - fprintf(flist, "%d warning%s ", nwarnings, (nwarnings == 1) ? "" : "s"); + if (nwarnings > 0) + fprintf(flist, "%d warning%s ", nwarnings, (nwarnings == 1) ? "" : "s"); - fprintf(flist, "in this assembly\n"); - } - else - fprintf(flist, "\nThere were no errors in this assembly\n"); - } + fprintf(flist, "in this assembly\n"); + } + else + fprintf(flist, "\nThere were no errors in this assembly\n"); + } - if (flist) { // finish the listing - if (pta >= 0) - fprintf(flist, "\nProgram transfer address = %04x\n", pta); + if (flist) { // finish the listing + if (pta >= 0) + fprintf(flist, "\nProgram transfer address = %04x\n", pta); - if (do_xref) - xref_list(); - else if (do_syms) - sym_list(); - } + if (do_xref) + xref_list(); + else if (do_syms) + sym_list(); + } - if (savetable) - save_symbols(); + if (savetable) + save_symbols(); - return 0; // all done + return 0; // all done } // --------------------------------------------------------------------------------- @@ -470,13 +470,13 @@ int main (int argc, char **argv) void init (int argc, char **argv) { - int i; + int i; - enable_1800 = strstr(argv[0], "1800") != NULL; // if "1800" appears in the executable name, enable 1800 extensions + enable_1800 = strstr(argv[0], "1800") != NULL; // if "1800" appears in the executable name, enable 1800 extensions - for (i = 1; i < argc; i++) // process command line switches - if (*argv[i] == '-') - flag(argv[i]+1); + for (i = 1; i < argc; i++) // process command line switches + if (*argv[i] == '-') + flag(argv[i]+1); } // --------------------------------------------------------------------------------- @@ -485,67 +485,67 @@ void init (int argc, char **argv) void flag (char *arg) { - int major, minor; + int major, minor; - while (*arg) { - switch (*arg++) { - case 'o': // output (load) file name - if (! *arg) - bail(usestr); - outfn = arg; - return; + while (*arg) { + switch (*arg++) { + case 'o': // output (load) file name + if (! *arg) + bail(usestr); + outfn = arg; + return; - case 'p': - passcount = TRUE; - break; + case 'p': + passcount = TRUE; + break; - case 'v': // mumble while running - verbose = TRUE; - break; + case 'v': // mumble while running + verbose = TRUE; + break; - case 'x': // print cross reference table - do_xref = TRUE; - break; - - case 's': // print symbol table - do_syms = TRUE; - break; + case 'x': // print cross reference table + do_xref = TRUE; + break; + + case 's': // print symbol table + do_syms = TRUE; + break; - case 'l': // listing file name - listfn = (* arg) ? arg : NULL; - do_list = TRUE; - return; + case 'l': // listing file name + listfn = (* arg) ? arg : NULL; + do_list = TRUE; + return; - case 'W': - saveprompt = FALSE; - // fall through - case 'w': - savetable = TRUE; - break; + case 'W': + saveprompt = FALSE; + // fall through + case 'w': + savetable = TRUE; + break; - case 'y': - preload = TRUE; - break; + case 'y': + preload = TRUE; + break; - case 'b': - outmode = OUTMODE_BINARY; - break; + case 'b': + outmode = OUTMODE_BINARY; + break; - case '8': - enable_1800 = TRUE; - break; + case '8': + enable_1800 = TRUE; + break; - case 'r': - if (sscanf(arg, "%d.%d", &major, &minor) != 2) - bail(usestr); - sprintf(dmsversion, "V%01.1dM%02.2d", major, minor); - return; + case 'r': + if (sscanf(arg, "%d.%d", &major, &minor) != 2) + bail(usestr); + sprintf(dmsversion, "V%01.1dM%02.2d", major, minor); + return; - default: - bail(usestr); - break; - } - } + default: + bail(usestr); + break; + } + } } // --------------------------------------------------------------------------------- @@ -554,8 +554,8 @@ void flag (char *arg) void bail (char *msg) { - fprintf(stderr, "%s\n", msg); - exit(1); + fprintf(stderr, "%s\n", msg); + exit(1); } // --------------------------------------------------------------------------------- @@ -564,13 +564,13 @@ void bail (char *msg) void errprintf (char *fmt, ...) { - va_list args; + va_list args; - va_start(args, fmt); // get pointer to argument list + va_start(args, fmt); // get pointer to argument list - vfprintf(stderr, fmt, args); // write errors to terminal (stderr) + vfprintf(stderr, fmt, args); // write errors to terminal (stderr) - va_end(args); + va_end(args); } // --------------------------------------------------------------------------------- @@ -579,28 +579,28 @@ void errprintf (char *fmt, ...) void asm_error (char *fmt, ...) { - va_list args; + va_list args; - if (pass == 1) // only print on pass 2 - return; + if (pass == 1) // only print on pass 2 + return; - va_start(args, fmt); // get pointer to argument list + va_start(args, fmt); // get pointer to argument list - fprintf(stderr, "E: %s (%d): ", curfn, lno); - vfprintf(stderr, fmt, args); // write errors to terminal (stderr) - putc('\n', stderr); + fprintf(stderr, "E: %s (%d): ", curfn, lno); + vfprintf(stderr, fmt, args); // write errors to terminal (stderr) + putc('\n', stderr); - if (flist != NULL && list_on) { - listout(FALSE); - line_error = TRUE; + if (flist != NULL && list_on) { + listout(FALSE); + line_error = TRUE; - fprintf(flist, "**** Error: "); - vfprintf(flist, fmt, args); // write errors to listing file - putc('\n', flist); - } + fprintf(flist, "**** Error: "); + vfprintf(flist, fmt, args); // write errors to listing file + putc('\n', flist); + } - nerrors++; - va_end(args); + nerrors++; + va_end(args); } // --------------------------------------------------------------------------------- @@ -609,27 +609,27 @@ void asm_error (char *fmt, ...) void asm_warning (char *fmt, ...) { - va_list args; + va_list args; - if (pass == 1) // only print on pass 2 - return; + if (pass == 1) // only print on pass 2 + return; - va_start(args, fmt); // get pointer to argument list + va_start(args, fmt); // get pointer to argument list - fprintf(stderr, "W: %s (%d): ", curfn, lno); - vfprintf(stderr, fmt, args); // write errors to terminal (stderr) - putc('\n', stderr); + fprintf(stderr, "W: %s (%d): ", curfn, lno); + vfprintf(stderr, fmt, args); // write errors to terminal (stderr) + putc('\n', stderr); - if (flist != NULL && list_on) { - listout(FALSE); - line_error = TRUE; + if (flist != NULL && list_on) { + listout(FALSE); + line_error = TRUE; - fprintf(flist, "**** Warning: "); - vfprintf(flist, fmt, args); // write errors to listing file - putc('\n', flist); - } + fprintf(flist, "**** Warning: "); + vfprintf(flist, fmt, args); // write errors to listing file + putc('\n', flist); + } - nwarnings++; + nwarnings++; } // --------------------------------------------------------------------------------- @@ -638,31 +638,31 @@ void asm_warning (char *fmt, ...) void sym_list (void) { - PSYMBOL s; - int n = 5; + PSYMBOL s; + int n = 5; - if (symbols == NULL || flist == NULL) - return; + if (symbols == NULL || flist == NULL) + return; - fprintf(flist, "\n=== SYMBOL TABLE ==============================================================\n"); + fprintf(flist, "\n=== SYMBOL TABLE ==============================================================\n"); - for (s = symbols, n = 0; s != NULL; s = s->next) { - if (n >= 5) { - putc('\n', flist); - n = 0; - } - else if (n > 0) - fprintf(flist, " "); + for (s = symbols, n = 0; s != NULL; s = s->next) { + if (n >= 5) { + putc('\n', flist); + n = 0; + } + else if (n > 0) + fprintf(flist, " "); - fprintf(flist, "%-6s ", s->name); - if (s->defined == S_DEFINED) - fprintf(flist, "%04x%s", s->value & 0xFFFF, s->relative ? "R" : " "); - else - fprintf(flist, "UUUU "); + fprintf(flist, "%-6s ", s->name); + if (s->defined == S_DEFINED) + fprintf(flist, "%04x%s", s->value & 0xFFFF, s->relative ? "R" : " "); + else + fprintf(flist, "UUUU "); - n++; - } - fprintf(flist, "\n"); + n++; + } + fprintf(flist, "\n"); } // --------------------------------------------------------------------------------- @@ -671,19 +671,19 @@ void sym_list (void) void passreport (void) { - PSYMBOL s; + PSYMBOL s; - for (s = symbols; s != NULL; s = s->next) { - if (s->defined == S_UNDEFINED || s->defined == S_PROVISIONAL) { - printf("There are undefined symbols. Cannot determine pass requirement.\n"); - return; - } - } + for (s = symbols; s != NULL; s = s->next) { + if (s->defined == S_UNDEFINED || s->defined == S_PROVISIONAL) { + printf("There are undefined symbols. Cannot determine pass requirement.\n"); + return; + } + } - if (hasforward) - printf("There are forward references. Two passes are required.\n"); - else - printf("There are no forward references. Only one pass is required.\n"); + if (hasforward) + printf("There are forward references. Two passes are required.\n"); + else + printf("There are no forward references. Only one pass is required.\n"); } // --------------------------------------------------------------------------------- @@ -692,45 +692,45 @@ void passreport (void) void xref_list (void) { - int n = 0; - PXREF x; - PSYMBOL s; + int n = 0; + PXREF x; + PSYMBOL s; - if (flist == NULL || symbols == NULL) - return; + if (flist == NULL || symbols == NULL) + return; - fprintf(flist, "\n=== CROSS REFERENCES ==========================================================\n"); + fprintf(flist, "\n=== CROSS REFERENCES ==========================================================\n"); - if (symbols == NULL || flist == NULL) - return; + if (symbols == NULL || flist == NULL) + return; - fprintf(flist, "Name Val Defd Referenced\n"); + fprintf(flist, "Name Val Defd Referenced\n"); - for (s = symbols; s != NULL; s = s->next) { - fprintf(flist, "%-5s %04x%s", s->name, s->value & 0xFFFF, s->relative ? "R" : " "); + for (s = symbols; s != NULL; s = s->next) { + fprintf(flist, "%-5s %04x%s", s->name, s->value & 0xFFFF, s->relative ? "R" : " "); - for (x = s->xrefs; x != NULL; x = x->next) - if (x->definition) - break; + for (x = s->xrefs; x != NULL; x = x->next) + if (x->definition) + break; - if (x == NULL) - fprintf(flist, "----"); - else - fprintf(flist, " %4d", x->lno); + if (x == NULL) + fprintf(flist, "----"); + else + fprintf(flist, " %4d", x->lno); - for (n = 0, x = s->xrefs; x != NULL; x = x->next) { - if (x->definition) - continue; + for (n = 0, x = s->xrefs; x != NULL; x = x->next) { + if (x->definition) + continue; - if (n >= 12) { - n = 0; - fprintf(flist, "\n "); - } - fprintf(flist, " %4d", x->lno); - n++; - } - putc('\n', flist); - } + if (n >= 12) { + n = 0; + fprintf(flist, "\n "); + } + fprintf(flist, " %4d", x->lno); + n++; + } + putc('\n', flist); + } } // --------------------------------------------------------------------------------- @@ -740,10 +740,10 @@ void xref_list (void) void listhdr (void) { - time_t t; - - time(&t); - fprintf(flist, "%s -- %s -- %s\n", VERSION, dmsversion, ctime(&t)); + time_t t; + + time(&t); + fprintf(flist, "%s -- %s -- %s\n", VERSION, dmsversion, ctime(&t)); } // --------------------------------------------------------------------------------- @@ -752,17 +752,17 @@ void listhdr (void) char *astring (char *str) { - static char *s = NULL; + static char *s = NULL; - if (s != NULL) - if (strcmp(s, str) == 0) // if same as immediately previous allocation - return s; // return same pointer (why did I do this?) + if (s != NULL) + if (strcmp(s, str) == 0) // if same as immediately previous allocation + return s; // return same pointer (why did I do this?) - if ((s = malloc(strlen(str)+1)) == NULL) - bail("out of memory"); + if ((s = malloc(strlen(str)+1)) == NULL) + bail("out of memory"); - strcpy(s, str); - return s; + strcpy(s, str); + return s; } // --------------------------------------------------------------------------------- @@ -772,48 +772,48 @@ char *astring (char *str) PSYMBOL lookup_symbol (char *name, BOOL define) { - PSYMBOL s, n, prv = NULL; - int c; - char *at; + PSYMBOL s, n, prv = NULL; + int c; + char *at; - if (strlen(name) > 5) { // (sigh) - asm_error("Symbol '%s' is longer than 5 letters", name); - name[5] = '\0'; - } + if (strlen(name) > 5) { // (sigh) + asm_error("Symbol '%s' is longer than 5 letters", name); + name[5] = '\0'; + } #ifdef FIX_ATS - while ((at = strchr(name, '@')) != NULL) - *at = '\''; + while ((at = strchr(name, '@')) != NULL) + *at = '\''; #endif - // search sorted list of symbols - for (s = symbols; s != NULL; prv = s, s = s->next) { - c = strcmpi(s->name, name); - if (c == 0) - return s; - if (c > 0) - break; - } + // search sorted list of symbols + for (s = symbols; s != NULL; prv = s, s = s->next) { + c = strcmpi(s->name, name); + if (c == 0) + return s; + if (c > 0) + break; + } - if (! define) - return NULL; // not found + if (! define) + return NULL; // not found - if ((n = malloc(sizeof(SYMBOL))) == NULL) - bail("out of memory"); + if ((n = malloc(sizeof(SYMBOL))) == NULL) + bail("out of memory"); - n->name = astring(name); // symbol was undefined -- add it now - n->value = 0; - n->defined = FALSE; - n->xrefs = NULL; - n->defined = FALSE; + n->name = astring(name); // symbol was undefined -- add it now + n->value = 0; + n->defined = FALSE; + n->xrefs = NULL; + n->defined = FALSE; - n->next = s; // link in alpha order + n->next = s; // link in alpha order - if (prv == NULL) // we stopped before first item in list - symbols = n; - else - prv->next = n; // insert after item before place we stopped + if (prv == NULL) // we stopped before first item in list + symbols = n; + else + prv->next = n; // insert after item before place we stopped - return n; + return n; } // --------------------------------------------------------------------------------- @@ -822,28 +822,28 @@ PSYMBOL lookup_symbol (char *name, BOOL define) void add_xref (PSYMBOL s, BOOL definition) { - PXREF x, prv = NULL, n; + PXREF x, prv = NULL, n; - if (pass == 1 || ! do_xref) // define only during 2nd pass and only if listing was requested - return; + if (pass == 1 || ! do_xref) // define only during 2nd pass and only if listing was requested + return; - for (x = s->xrefs; x != NULL; prv = x, x = x->next) - if (strcmpi(x->fname, curfn) == 0 && x->lno == lno) - return; // ignore multiple refs on same line + for (x = s->xrefs; x != NULL; prv = x, x = x->next) + if (strcmpi(x->fname, curfn) == 0 && x->lno == lno) + return; // ignore multiple refs on same line - if ((n = malloc(sizeof(XREF))) == NULL) - bail("out of memory"); + if ((n = malloc(sizeof(XREF))) == NULL) + bail("out of memory"); - n->fname = astring(curfn); - n->lno = lno; - n->definition = definition; + n->fname = astring(curfn); + n->lno = lno; + n->definition = definition; - n->next = x; // link at end of existing list + n->next = x; // link at end of existing list - if (prv == NULL) - s->xrefs = n; - else - prv->next = n; + if (prv == NULL) + s->xrefs = n; + else + prv->next = n; } // --------------------------------------------------------------------------------- @@ -852,17 +852,17 @@ void add_xref (PSYMBOL s, BOOL definition) int get_symbol (char *name) { - PSYMBOL s; + PSYMBOL s; - s = lookup_symbol(name, TRUE); // lookup, define if necessary - - if (pass == 2) // should be defined by now - if (! s->defined) - asm_error("Symbol '%s' is undefined", name); + s = lookup_symbol(name, TRUE); // lookup, define if necessary + + if (pass == 2) // should be defined by now + if (! s->defined) + asm_error("Symbol '%s' is undefined", name); - add_xref(s, FALSE); // note the reference + add_xref(s, FALSE); // note the reference - return s->value; + return s->value; } // --------------------------------------------------------------------------------- @@ -873,34 +873,34 @@ int get_symbol (char *name) void set_symbol (char *name, int value, int known, RELOC relative) { - PSYMBOL s; - char *at; + PSYMBOL s; + char *at; - if (strlen(name) > 5) { - asm_error("Symbol '%s' is longer than 5 letters", name); - name[5] = '\0'; - } + if (strlen(name) > 5) { + asm_error("Symbol '%s' is longer than 5 letters", name); + name[5] = '\0'; + } #ifdef FIX_ATS - while ((at = strchr(name, '@')) != NULL) - *at = '\''; + while ((at = strchr(name, '@')) != NULL) + *at = '\''; #endif - s = lookup_symbol(name, TRUE); - - if (s->defined == S_DEFINED) // once defined, it should not change - if (s->value != value) - asm_error("Symbol '%s' %s", name, (s->pass == pass) ? "is multiply defined" : "changed between passes"); + s = lookup_symbol(name, TRUE); + + if (s->defined == S_DEFINED) // once defined, it should not change + if (s->value != value) + asm_error("Symbol '%s' %s", name, (s->pass == pass) ? "is multiply defined" : "changed between passes"); - s->value = value; - s->relative = relative; - s->defined = known ? S_DEFINED : S_PROVISIONAL; - s->pass = pass; + s->value = value; + s->relative = relative; + s->defined = known ? S_DEFINED : S_PROVISIONAL; + s->pass = pass; - if (! known) - hasforward = TRUE; + if (! known) + hasforward = TRUE; - add_xref(s, TRUE); // record the place of definition + add_xref(s, TRUE); // record the place of definition } // --------------------------------------------------------------------------------- @@ -909,10 +909,10 @@ void set_symbol (char *name, int value, int known, RELOC relative) char *skipbl (char *s) { - while (*s && *s <= ' ') - s++; + while (*s && *s <= ' ') + s++; - return s; + return s; } // --------------------------------------------------------------------------------- @@ -920,30 +920,30 @@ char *skipbl (char *s) // stores the token into the buffer tok and returns pointer to same. Returns NULL // when there are no tokens. Best to call repeatedly with a pointer to the source // buffer, e.g. -// char *pbuf = buf; -// while (gtok(&pbuf, token) != NULL) ... +// char *pbuf = buf; +// while (gtok(&pbuf, token) != NULL) ... // --------------------------------------------------------------------------------- char * gtok (char **pc, char *tok) { - char *s = *pc, *otok = tok; + char *s = *pc, *otok = tok; - while (*s && *s <= ' ') // skip blanks - s++; + while (*s && *s <= ' ') // skip blanks + s++; - if (! *s) { // no tokens to be found - *tok = '\0'; - *pc = s; - return NULL; - } + if (! *s) { // no tokens to be found + *tok = '\0'; + *pc = s; + return NULL; + } - while (*s > ' ') // save nonblanks into 'tok' - *tok++ = *s++; + while (*s > ' ') // save nonblanks into 'tok' + *tok++ = *s++; - *tok = '\0'; // terminate - *pc = s; // adjust caller's pointer + *tok = '\0'; // terminate + *pc = s; // adjust caller's pointer - return otok; // return pointer to token + return otok; // return pointer to token } // listing format: @@ -957,14 +957,14 @@ char * gtok (char **pc, char *tok) char *trim (char *s) { - char *os = s, *nb; + char *os = s, *nb; - for (nb = s-1; *s; s++) - if (*s > ' ') - nb = s; + for (nb = s-1; *s; s++) + if (*s > ' ') + nb = s; - nb[1] = '\0'; - return os; + nb[1] = '\0'; + return os; } // --------------------------------------------------------------------------------- @@ -975,13 +975,13 @@ char *trim (char *s) void listout (BOOL reset) { - if (flist && list_on && ! line_error) { - trim(listline); - fputs(listline, flist); - putc('\n', flist); - if (reset) - sprintf(listline, LEFT_MARGIN, org); - } + if (flist && list_on && ! line_error) { + trim(listline); + fputs(listline, flist); + putc('\n', flist); + if (reset) + sprintf(listline, LEFT_MARGIN, org); + } } // --------------------------------------------------------------------------------- @@ -991,27 +991,27 @@ void listout (BOOL reset) void storew (int word, RELOC relative) { - if (pass == 2) { // save in output (load) file. - switch (outmode) { - case OUTMODE_BINARY: - bincard_writew(word, relative); - break; + if (pass == 2) { // save in output (load) file. + switch (outmode) { + case OUTMODE_BINARY: + bincard_writew(word, relative); + break; - case OUTMODE_LOAD: - fprintf(fout, " %04x%s" ENDLINE, word & 0xFFFF, - (relative == ABSOLUTE) ? "" : (relative == RELATIVE) ? "R" : - (relative == LIBF) ? "L" : (relative == CALL) ? "$" : "?"); - break; + case OUTMODE_LOAD: + fprintf(fout, " %04x%s" ENDLINE, word & 0xFFFF, + (relative == ABSOLUTE) ? "" : (relative == RELATIVE) ? "R" : + (relative == LIBF) ? "L" : (relative == CALL) ? "$" : "?"); + break; - default: - bail("in storew, can't happen"); - } - } + default: + bail("in storew, can't happen"); + } + } - if (relative != LIBF) - org++; + if (relative != LIBF) + org++; - assembled = TRUE; // remember that we wrote something + assembled = TRUE; // remember that we wrote something } // --------------------------------------------------------------------------------- @@ -1020,21 +1020,21 @@ void storew (int word, RELOC relative) void setw (int pos, int word, RELOC relative) { - char tok[10], *p; - int i; - - if (flist == NULL || ! list_on) - return; + char tok[10], *p; + int i; + + if (flist == NULL || ! list_on) + return; - sprintf(tok, "%04x", word & 0xFFFF); + sprintf(tok, "%04x", word & 0xFFFF); - for (i = 0, p = listline + 5*pos; i < 4; i++) - p[i] = tok[i]; + for (i = 0, p = listline + 5*pos; i < 4; i++) + p[i] = tok[i]; - if (relative == RELATIVE) - p[i] = 'R'; - else if (relative != ABSOLUTE) - p[i] = '*'; + if (relative == RELATIVE) + p[i] = 'R'; + else if (relative != ABSOLUTE) + p[i] = '*'; } // --------------------------------------------------------------------------------- @@ -1043,19 +1043,19 @@ void setw (int pos, int word, RELOC relative) // --------------------------------------------------------------------------------- void writew (int word, RELOC relative) -{ // first, the listing stuff... - if (nwout == 0) { // on first output word, display address in column 0 - setw(0, org, FALSE); - } - else if (nwout >= 4) { // if 4 words have already been written, start new line - listout(TRUE); - nwout = 0; - } +{ // first, the listing stuff... + if (nwout == 0) { // on first output word, display address in column 0 + setw(0, org, FALSE); + } + else if (nwout >= 4) { // if 4 words have already been written, start new line + listout(TRUE); + nwout = 0; + } - nwout++; - setw(nwout, word, relative); // display word in the listing line + nwout++; + setw(nwout, word, relative); // display word in the listing line - storew(word, relative); // write it to the output medium + storew(word, relative); // write it to the output medium } // --------------------------------------------------------------------------------- @@ -1064,18 +1064,18 @@ void writew (int word, RELOC relative) void setorg (int neworg) { - if (pass == 2) { - setw(0, neworg, FALSE); // display in listing file in column 0 + if (pass == 2) { + setw(0, neworg, FALSE); // display in listing file in column 0 - if (outmode == OUTMODE_LOAD) { // write new load address to the output file - fprintf(fout, "@%04x%s" ENDLINE, neworg & 0xFFFF, relocate ? "R" : ""); - } - else { - bincard_setorg(neworg); - } - } + if (outmode == OUTMODE_LOAD) { // write new load address to the output file + fprintf(fout, "@%04x%s" ENDLINE, neworg & 0xFFFF, relocate ? "R" : ""); + } + else { + bincard_setorg(neworg); + } + } - org = neworg; + org = neworg; } // --------------------------------------------------------------------------------- @@ -1084,8 +1084,8 @@ void setorg (int neworg) void org_even (void) { - if (org & 1) - setorg(org+1); + if (org & 1) + setorg(org+1); } // --------------------------------------------------------------------------------- @@ -1097,38 +1097,38 @@ void org_even (void) void tabtok (char *c, char *tok, int i, char *save) { - *tok = '\0'; + *tok = '\0'; - while (--i >= 0) { // skip to i'th tab-delimited field - if ((c = strchr(c, '\t')) == NULL) { - if (save) // was none - *save = '\0'; - return; - } - c++; - } + while (--i >= 0) { // skip to i'th tab-delimited field + if ((c = strchr(c, '\t')) == NULL) { + if (save) // was none + *save = '\0'; + return; + } + c++; + } - while (*c == ' ') // skip leading blanks - c++; + while (*c == ' ') // skip leading blanks + c++; - if (save != NULL) // save copy of entire remainder - strcpy(save, c); + if (save != NULL) // save copy of entire remainder + strcpy(save, c); - while (*c > ' ') { // take up to any whitespace - if (*c == '(') { // if we start with a paren, take all up to closing paren including spaces - while (*c && *c != ')') - *tok++ = *c++; - } - else if (*c == '.') { // period means literal character following - *tok++ = *c++; - if (*c) - *tok++ = *c++; - } - else - *tok++ = *c++; - } + while (*c > ' ') { // take up to any whitespace + if (*c == '(') { // if we start with a paren, take all up to closing paren including spaces + while (*c && *c != ')') + *tok++ = *c++; + } + else if (*c == '.') { // period means literal character following + *tok++ = *c++; + if (*c) + *tok++ = *c++; + } + else + *tok++ = *c++; + } - *tok = '\0'; + *tok = '\0'; } // --------------------------------------------------------------------------------- @@ -1146,55 +1146,55 @@ void tabtok (char *c, char *tok, int i, char *save) void coltok (char *c, char *tok, int ifrom, int ito, BOOL condense, char *save) { - char *otok = tok; - int i; + char *otok = tok; + int i; - ifrom--; - ito--; + ifrom--; + ito--; - for (i = 0; i < ifrom; i++) { - if (c[i] == '\0') { // line ended before this column - *tok = '\0'; - if (save) - *save = '\0'; - return; - } - } + for (i = 0; i < ifrom; i++) { + if (c[i] == '\0') { // line ended before this column + *tok = '\0'; + if (save) + *save = '\0'; + return; + } + } - if (save) // save from ifrom on - strcpy(save, c+i); + if (save) // save from ifrom on + strcpy(save, c+i); - if (condense) { - for (; i <= ito; i++) { // save only nonwhite characters - if (c[i] > ' ') - *tok++ = c[i]; - } - } - else { - if (c[i] == ' ' && save != NULL)// if it starts with a space, it's empty - *save = '\0'; + if (condense) { + for (; i <= ito; i++) { // save only nonwhite characters + if (c[i] > ' ') + *tok++ = c[i]; + } + } + else { + if (c[i] == ' ' && save != NULL)// if it starts with a space, it's empty + *save = '\0'; - while (i <= ito) { // take up to any whitespace - if (c[i] <= ' ') - break; - else if (c[i] == '(') { // starts with paren? take to close paren - while (i <= ito && c[i]) { - if ((*tok++ = c[i++]) == ')') - break; - } - } - else if (c[i] == '.') { // period means literal character following - *tok++ = c[i++]; - if (i <= ito && c[i]) - *tok++ = c[i++]; - } - else - *tok++ = c[i++]; - } - } + while (i <= ito) { // take up to any whitespace + if (c[i] <= ' ') + break; + else if (c[i] == '(') { // starts with paren? take to close paren + while (i <= ito && c[i]) { + if ((*tok++ = c[i++]) == ')') + break; + } + } + else if (c[i] == '.') { // period means literal character following + *tok++ = c[i++]; + if (i <= ito && c[i]) + *tok++ = c[i++]; + } + else + *tok++ = c[i++]; + } + } - *tok = '\0'; - trim(otok); + *tok = '\0'; + trim(otok); } // --------------------------------------------------------------------------------- @@ -1203,34 +1203,34 @@ void coltok (char *c, char *tok, int ifrom, int ito, BOOL condense, char *save) // modifiers for the opcode definition table: -#define L "L" // long -#define X "X" // absolute displacement -#define I "I" // indirect -#define IDX "0123" // indexed (some LDX commands in the DMS source say LDX L0, so accept 0 -#define E "E" // even address -#define NONE "" -#define ALL L X I IDX // hope non-Microsoft C accepts and concatenates strings like this -#define ANY "\xFF" -#define NUMS "0123456789" +#define L "L" // long +#define X "X" // absolute displacement +#define I "I" // indirect +#define IDX "0123" // indexed (some LDX commands in the DMS source say LDX L0, so accept 0 +#define E "E" // even address +#define NONE "" +#define ALL L X I IDX // hope non-Microsoft C accepts and concatenates strings like this +#define ANY "\xFF" +#define NUMS "0123456789" -#define IS_DBL 0x0001 // double word operand implies even address -#define IS_ABS 0x0002 // always uses absolute addressing mode (implied X) -#define NO_IDX 0x0004 // even with 1 or 2 modifier, this is not really indexed (for STX/LDX) -#define NO_ARGS 0x0008 // statement takes no arguments -#define IS_1800 0x0010 // 1800-only directive or instruction, flagged if 1800 mode is not enabled -#define TRAP 0x1000 // debug this instruction +#define IS_DBL 0x0001 // double word operand implies even address +#define IS_ABS 0x0002 // always uses absolute addressing mode (implied X) +#define NO_IDX 0x0004 // even with 1 or 2 modifier, this is not really indexed (for STX/LDX) +#define NO_ARGS 0x0008 // statement takes no arguments +#define IS_1800 0x0010 // 1800-only directive or instruction, flagged if 1800 mode is not enabled +#define TRAP 0x1000 // debug this instruction -struct tag_op { // OPCODE TABLE - char *mnem; - int opcode; - void (*handler)(struct tag_op *op, char *label, char *mods, char *arg); - char *mods_allowed; - char *mods_implied; - int flags; +struct tag_op { // OPCODE TABLE + char *mnem; + int opcode; + void (*handler)(struct tag_op *op, char *label, char *mods, char *arg); + char *mods_allowed; + char *mods_implied; + int flags; }; - // special opcode handlers + // special opcode handlers void std_op (struct tag_op *op, char *label, char *mods, char *arg); -void b_op (struct tag_op *op, char *label, char *mods, char *arg); +void b_op (struct tag_op *op, char *label, char *mods, char *arg); void bsc_op (struct tag_op *op, char *label, char *mods, char *arg); void bsi_op (struct tag_op *op, char *label, char *mods, char *arg); void mdx_op (struct tag_op *op, char *label, char *mods, char *arg); @@ -1278,100 +1278,100 @@ void x_trap (struct tag_op *op, char *label, char *mods, char *arg); void x_xflc (struct tag_op *op, char *label, char *mods, char *arg); struct tag_op ops[] = { - ".OPT", 0, x_opt, NONE, NONE, 0, // non-IBM extensions - "TRAP", 0, x_trap, NONE, NONE, 0, // assembler breakpoint trap - ".CES", 0, x_ces, NONE, NONE, 0, // lets us specify simulated console entry switch values for startup + ".OPT", 0, x_opt, NONE, NONE, 0, // non-IBM extensions + "TRAP", 0, x_trap, NONE, NONE, 0, // assembler breakpoint trap + ".CES", 0, x_ces, NONE, NONE, 0, // lets us specify simulated console entry switch values for startup - "ABS", 0, x_abs, NONE, NONE, 0, - "BES", 0, x_bes, E, NONE, 0, // standard pseudo-ops - "BSS", 0, x_bss, E, NONE, 0, - "DC", 0, x_dc, NONE, NONE, 0, - "DEC", 0, x_dec, E, E, IS_DBL, - "DECS", 0, x_decs, E, E, IS_DBL, // this is an IBM 1800 directive - "DMES", 0, x_dmes, ANY, NONE, 0, - "DN", 0, x_dn, NONE, NONE, 0, - "DSA", 0, x_dsa, NONE, NONE, 0, - "DUMP", 0, x_dump, NONE, NONE, 0, - "EBC", 0, x_ebc, NONE, NONE, 0, - "EJCT", 0, x_ejct, NONE, NONE, 0, - "END", 0, x_end, NONE, NONE, 0, - "ENT", 0, x_ent, NONE, NONE, 0, - "EPR", 0, x_epr, NONE, NONE, 0, - "EQU", 0, x_equ, NONE, NONE, 0, - "EXIT", 0, x_exit, NONE, NONE, 0, // alias for call $exit since we don't have macros yet - "FILE", 0, x_file, NONE, NONE, 0, - "HDNG", 0, x_hdng, ANY, NONE, 0, - "ILS", 0, x_ils, NUMS, NONE, 0, - "ISS", 0, x_iss, NUMS, NONE, 0, - "LIBF", 0, x_libf, NONE, NONE, 0, - "LIBR", 0, x_libr, NONE, NONE, 0, - "LINK", 0, x_link, NONE, NONE, 0, - "LIST", 0, x_list, NONE, NONE, 0, - "LORG", 0, x_lorg, NONE, NONE, 0, - "ORG", 0, x_org, NONE, NONE, 0, - "PDMP", 0, x_pdmp, NONE, NONE, 0, - "SPAC", 0, x_spac, NONE, NONE, 0, - "SPR", 0, x_spr, NONE, NONE, 0, - "XFLC", 0, x_xflc, NONE, NONE, 0, + "ABS", 0, x_abs, NONE, NONE, 0, + "BES", 0, x_bes, E, NONE, 0, // standard pseudo-ops + "BSS", 0, x_bss, E, NONE, 0, + "DC", 0, x_dc, NONE, NONE, 0, + "DEC", 0, x_dec, E, E, IS_DBL, + "DECS", 0, x_decs, E, E, IS_DBL, // this is an IBM 1800 directive + "DMES", 0, x_dmes, ANY, NONE, 0, + "DN", 0, x_dn, NONE, NONE, 0, + "DSA", 0, x_dsa, NONE, NONE, 0, + "DUMP", 0, x_dump, NONE, NONE, 0, + "EBC", 0, x_ebc, NONE, NONE, 0, + "EJCT", 0, x_ejct, NONE, NONE, 0, + "END", 0, x_end, NONE, NONE, 0, + "ENT", 0, x_ent, NONE, NONE, 0, + "EPR", 0, x_epr, NONE, NONE, 0, + "EQU", 0, x_equ, NONE, NONE, 0, + "EXIT", 0, x_exit, NONE, NONE, 0, // alias for call $exit since we don't have macros yet + "FILE", 0, x_file, NONE, NONE, 0, + "HDNG", 0, x_hdng, ANY, NONE, 0, + "ILS", 0, x_ils, NUMS, NONE, 0, + "ISS", 0, x_iss, NUMS, NONE, 0, + "LIBF", 0, x_libf, NONE, NONE, 0, + "LIBR", 0, x_libr, NONE, NONE, 0, + "LINK", 0, x_link, NONE, NONE, 0, + "LIST", 0, x_list, NONE, NONE, 0, + "LORG", 0, x_lorg, NONE, NONE, 0, + "ORG", 0, x_org, NONE, NONE, 0, + "PDMP", 0, x_pdmp, NONE, NONE, 0, + "SPAC", 0, x_spac, NONE, NONE, 0, + "SPR", 0, x_spr, NONE, NONE, 0, + "XFLC", 0, x_xflc, NONE, NONE, 0, - "A", 0x8000, std_op, ALL, NONE, 0, // standard addressing ops - "AD", 0x8800, std_op, ALL, NONE, IS_DBL, - "AND", 0xE000, std_op, ALL, NONE, 0, - "BSI", 0x4000, bsi_op, ALL, NONE, 0, - "CALL", 0x4000, x_call, ALL, L, 0, // alias for BSI L, or external call - "CMP", 0xB000, std_op, ALL, NONE, IS_1800, // this is an IBM 1800-only instruction - "DCM", 0xB800, std_op, ALL, NONE, IS_1800, // this is an IBM 1800-only instruction - "D" , 0xA800, std_op, ALL, NONE, 0, - "EOR", 0xF000, std_op, ALL, NONE, 0, - "LD", 0xC000, std_op, ALL, NONE, 0, - "LDD", 0xC800, std_op, ALL, NONE, IS_DBL, - "LDS", 0x2000, std_op, NONE, NONE, IS_ABS, - "LDX", 0x6000, std_op, ALL, NONE, IS_ABS|NO_IDX, - "M", 0xA000, std_op, ALL, NONE, 0, - "MDX", 0x7000, mdx_op, ALL, NONE, 0, - "MDM", 0x7000, mdx_op, L, L, 0, // like MDX L - "NOP", 0x1000, std_op, NONE, NONE, NO_ARGS, - "OR", 0xE800, std_op, ALL, NONE, 0, - "S", 0x9000, std_op, ALL, NONE, 0, - "SD", 0x9800, std_op, ALL, NONE, IS_DBL, - "STD", 0xD800, std_op, ALL, NONE, IS_DBL, - "STO", 0xD000, std_op, ALL, NONE, 0, - "STS", 0x2800, std_op, ALL, NONE, 0, - "STX", 0x6800, std_op, ALL, NONE, NO_IDX, - "WAIT", 0x3000, std_op, NONE, NONE, IS_ABS, - "XCH", 0x18D0, std_op, NONE, NONE, 0, // same as RTE 16, 18C0 + 10 - "XIO", 0x0800, std_op, ALL, NONE, IS_DBL, + "A", 0x8000, std_op, ALL, NONE, 0, // standard addressing ops + "AD", 0x8800, std_op, ALL, NONE, IS_DBL, + "AND", 0xE000, std_op, ALL, NONE, 0, + "BSI", 0x4000, bsi_op, ALL, NONE, 0, + "CALL", 0x4000, x_call, ALL, L, 0, // alias for BSI L, or external call + "CMP", 0xB000, std_op, ALL, NONE, IS_1800, // this is an IBM 1800-only instruction + "DCM", 0xB800, std_op, ALL, NONE, IS_1800, // this is an IBM 1800-only instruction + "D" , 0xA800, std_op, ALL, NONE, 0, + "EOR", 0xF000, std_op, ALL, NONE, 0, + "LD", 0xC000, std_op, ALL, NONE, 0, + "LDD", 0xC800, std_op, ALL, NONE, IS_DBL, + "LDS", 0x2000, std_op, NONE, NONE, IS_ABS, + "LDX", 0x6000, std_op, ALL, NONE, IS_ABS|NO_IDX, + "M", 0xA000, std_op, ALL, NONE, 0, + "MDX", 0x7000, mdx_op, ALL, NONE, 0, + "MDM", 0x7000, mdx_op, L, L, 0, // like MDX L + "NOP", 0x1000, std_op, NONE, NONE, NO_ARGS, + "OR", 0xE800, std_op, ALL, NONE, 0, + "S", 0x9000, std_op, ALL, NONE, 0, + "SD", 0x9800, std_op, ALL, NONE, IS_DBL, + "STD", 0xD800, std_op, ALL, NONE, IS_DBL, + "STO", 0xD000, std_op, ALL, NONE, 0, + "STS", 0x2800, std_op, ALL, NONE, 0, + "STX", 0x6800, std_op, ALL, NONE, NO_IDX, + "WAIT", 0x3000, std_op, NONE, NONE, IS_ABS, + "XCH", 0x18D0, std_op, NONE, NONE, 0, // same as RTE 16, 18C0 + 10 + "XIO", 0x0800, std_op, ALL, NONE, IS_DBL, - "BSC", 0x4800, bsc_op, ALL, NONE, 0, // branch family - "BOSC", 0x4840, bsc_op, ALL, NONE, 0, // is BOSC always long form? No. - "SKP", 0x4800, bsc_op, NONE, NONE, 0, // alias for BSC one word version + "BSC", 0x4800, bsc_op, ALL, NONE, 0, // branch family + "BOSC", 0x4840, bsc_op, ALL, NONE, 0, // is BOSC always long form? No. + "SKP", 0x4800, bsc_op, NONE, NONE, 0, // alias for BSC one word version - "B", 0x4800, b_op, ALL, NONE, 0, // alias for MDX or BSC L - "BC", 0x4802, std_op, ALL, L, 0, // alias for BSC L - "BN", 0x4828, std_op, ALL, L, 0, // alias for BSC L - "BNN", 0x4810, std_op, ALL, L, 0, // alias for BSC L - "BNP", 0x4808, std_op, ALL, L, 0, // alias for BSC L - "BNZ", 0x4820, std_op, ALL, L, 0, // alias for BSC L - "BO", 0x4801, std_op, ALL, L, 0, // alias for BSC L - "BOD", 0x4840, std_op, ALL, L, 0, // alias for BSC L - "BP", 0x4830, std_op, ALL, L, 0, // alias for BSC L - "BZ", 0x4818, std_op, ALL, L, 0, // alias for BSC L + "B", 0x4800, b_op, ALL, NONE, 0, // alias for MDX or BSC L + "BC", 0x4802, std_op, ALL, L, 0, // alias for BSC L + "BN", 0x4828, std_op, ALL, L, 0, // alias for BSC L + "BNN", 0x4810, std_op, ALL, L, 0, // alias for BSC L + "BNP", 0x4808, std_op, ALL, L, 0, // alias for BSC L + "BNZ", 0x4820, std_op, ALL, L, 0, // alias for BSC L + "BO", 0x4801, std_op, ALL, L, 0, // alias for BSC L + "BOD", 0x4840, std_op, ALL, L, 0, // alias for BSC L + "BP", 0x4830, std_op, ALL, L, 0, // alias for BSC L + "BZ", 0x4818, std_op, ALL, L, 0, // alias for BSC L - "RTE", 0x18C0, shf_op, IDX X, X, 0, // shift family - "SLA", 0x1000, shf_op, IDX X, X, 0, - "SLC", 0x10C0, shf_op, IDX X, X, 0, - "SLCA", 0x1040, shf_op, IDX X, X, 0, - "SLT", 0x1080, shf_op, IDX X, X, 0, - "SRA", 0x1800, shf_op, IDX X, X, 0, - "SRT", 0x1880, shf_op, IDX X, X, 0, + "RTE", 0x18C0, shf_op, IDX X, X, 0, // shift family + "SLA", 0x1000, shf_op, IDX X, X, 0, + "SLC", 0x10C0, shf_op, IDX X, X, 0, + "SLCA", 0x1040, shf_op, IDX X, X, 0, + "SLT", 0x1080, shf_op, IDX X, X, 0, + "SRA", 0x1800, shf_op, IDX X, X, 0, + "SRT", 0x1880, shf_op, IDX X, X, 0, - "AIF", 0, x_aif, NONE, NONE, 0, // assemble if - "AIFB", 0, x_aifb, NONE, NONE, 0, // assemble if - "AGO", 0, x_ago, NONE, NONE, 0, // assemble goto - "AGOB", 0, x_agob, NONE, NONE, 0, // assemble goto - "ANOP", 0, x_anop, NONE, NONE, 0, // assemble target + "AIF", 0, x_aif, NONE, NONE, 0, // assemble if + "AIFB", 0, x_aifb, NONE, NONE, 0, // assemble if + "AGO", 0, x_ago, NONE, NONE, 0, // assemble goto + "AGOB", 0, x_agob, NONE, NONE, 0, // assemble goto + "ANOP", 0, x_anop, NONE, NONE, 0, // assemble target - NULL // end of table + NULL // end of table }; // --------------------------------------------------------------------------------- @@ -1381,22 +1381,22 @@ struct tag_op ops[] = { char *addextn (char *fname, char *extn, char *outbuf) { - char *buf, line[500], *c; + char *buf, line[500], *c; - buf = (outbuf == NULL) ? line : outbuf; + buf = (outbuf == NULL) ? line : outbuf; - strcpy(buf, fname); // create listfn from first source filename (e.g. xxx.lst); - if ((c = strrchr(buf, '\\')) == NULL) - if ((c = strrchr(buf, '/')) == NULL) - if ((c = strrchr(buf, ':')) == NULL) - c = buf; + strcpy(buf, fname); // create listfn from first source filename (e.g. xxx.lst); + if ((c = strrchr(buf, '\\')) == NULL) + if ((c = strrchr(buf, '/')) == NULL) + if ((c = strrchr(buf, ':')) == NULL) + c = buf; - if ((c = strrchr(c, '.')) == NULL) - strcat(buf, extn); - else - strcpy(c, extn); + if ((c = strrchr(c, '.')) == NULL) + strcat(buf, extn); + else + strcpy(c, extn); - return (outbuf == NULL) ? astring(line) : outbuf; + return (outbuf == NULL) ? astring(line) : outbuf; } // --------------------------------------------------------------------------------- @@ -1405,33 +1405,33 @@ char *addextn (char *fname, char *extn, char *outbuf) BOOL controlcard (char *line) { - if (strnicmp(line, "*LIST", 5) == 0) { // turn on listing file even if not specified on command line - do_list = list_on = TRUE; - return TRUE; - } - - if (strnicmp(line, "*XREF", 5) == 0) { - do_xref = TRUE; - return TRUE; - } + if (strnicmp(line, "*LIST", 5) == 0) { // turn on listing file even if not specified on command line + do_list = list_on = TRUE; + return TRUE; + } + + if (strnicmp(line, "*XREF", 5) == 0) { + do_xref = TRUE; + return TRUE; + } - if (strnicmp(line, "*PRINT SYMBOL TABLE", 19) == 0) { - do_syms = TRUE; - return TRUE; - } + if (strnicmp(line, "*PRINT SYMBOL TABLE", 19) == 0) { + do_syms = TRUE; + return TRUE; + } - if (strnicmp(line, "*SAVE SYMBOL TABLE", 18) == 0) { - savetable = TRUE; - return TRUE; - } + if (strnicmp(line, "*SAVE SYMBOL TABLE", 18) == 0) { + savetable = TRUE; + return TRUE; + } - if (strnicmp(line, "*SYSTEM SYMBOL TABLE", 20) == 0) { - preload = TRUE; - preload_symbols(); - return TRUE; - } + if (strnicmp(line, "*SYSTEM SYMBOL TABLE", 20) == 0) { + preload = TRUE; + preload_symbols(); + return TRUE; + } - return FALSE; + return FALSE; } // --------------------------------------------------------------------------------- @@ -1440,13 +1440,13 @@ BOOL controlcard (char *line) void stuff (char *buf, char *tok, int maxchars) { - while (*tok) { - *buf++ = *tok++; - - if (maxchars) - if (--maxchars <= 0) - break; - } + while (*tok) { + *buf++ = *tok++; + + if (maxchars) + if (--maxchars <= 0) + break; + } } // --------------------------------------------------------------------------------- @@ -1455,21 +1455,21 @@ void stuff (char *buf, char *tok, int maxchars) void format_line (char *buf, char *label, char *op, char *mods, char *args, char *remarks) { - int i; + int i; - if (tabformat) { - sprintf(buf, "%s\t%s\t%s\t%s\t%s", label, op, mods, args, remarks); - } - else { - for (i = 0; i < 72; i++) - buf[i] = ' '; - buf[i] = '\0'; + if (tabformat) { + sprintf(buf, "%s\t%s\t%s\t%s\t%s", label, op, mods, args, remarks); + } + else { + for (i = 0; i < 72; i++) + buf[i] = ' '; + buf[i] = '\0'; - stuff(buf+20, label, 5); - stuff(buf+26, op, 4); - stuff(buf+31, mods, 2); - stuff(buf+34, args, 72-34); - } + stuff(buf+20, label, 5); + stuff(buf+26, op, 4); + stuff(buf+31, mods, 2); + stuff(buf+34, args, 72-34); + } } // --------------------------------------------------------------------------------- @@ -1478,40 +1478,40 @@ void format_line (char *buf, char *label, char *op, char *mods, char *args, char struct tag_op * lookup_op (char *mnem) { - struct tag_op *op; - int i; + struct tag_op *op; + int i; - for (op = ops; op->mnem != NULL; op++) { - if ((i = strcmp(op->mnem, mnem)) == 0) - return op; + for (op = ops; op->mnem != NULL; op++) { + if ((i = strcmp(op->mnem, mnem)) == 0) + return op; - if (i > 0) - break; - } - return NULL; + if (i > 0) + break; + } + return NULL; } // --------------------------------------------------------------------------------- // bincard - routines to write IBM 1130 Card object format // --------------------------------------------------------------------------------- -unsigned short bincard[54]; // the 54 data words that can fit on a binary format card -char binflag[45]; // the relocation flags of the 45 buffered object words (0, 1, 2, 3) -int bincard_n = 0; // number of object words stored in bincard (0-45) -int bincard_seq = 0; // card output sequence number -int bincard_org = 0; // origin of current card-full +unsigned short bincard[54]; // the 54 data words that can fit on a binary format card +char binflag[45]; // the relocation flags of the 45 buffered object words (0, 1, 2, 3) +int bincard_n = 0; // number of object words stored in bincard (0-45) +int bincard_seq = 0; // card output sequence number +int bincard_org = 0; // origin of current card-full int bincard_maxaddr = 0; -BOOL bincard_first = TRUE; // TRUE when we're to write the program type card +BOOL bincard_first = TRUE; // TRUE when we're to write the program type card // bincard_init - prepare a new object data output card void bincard_init (void) { - memset(bincard, 0, sizeof(bincard)); // clear card data - memset(binflag, 0, sizeof(binflag)); // clear relocation data - bincard_n = 0; // no data - bincard[0] = bincard_org; // store load address - bincard_maxaddr = MAX(bincard_maxaddr, bincard_org-1); // save highest address written-to (this may be a BSS) + memset(bincard, 0, sizeof(bincard)); // clear card data + memset(binflag, 0, sizeof(binflag)); // clear relocation data + bincard_n = 0; // no data + bincard[0] = bincard_org; // store load address + bincard_maxaddr = MAX(bincard_maxaddr, bincard_org-1); // save highest address written-to (this may be a BSS) } // binard_writecard - emit a card. sbrk_text = NULL for normal data cards, points to comment text for sbrk card @@ -1519,211 +1519,211 @@ void bincard_init (void) void bincard_writecard (char *sbrk_text) { - unsigned short binout[80]; - char ident[12]; - int i, j; + unsigned short binout[80]; + char ident[12]; + int i, j; - if (sbrk_text != NULL) { // sbrk card has 4 binary words followed by comment text - for (j = 66; j < 71; j++) // be sure input columns 67..71 are nonblank (have version number) - if (sbrk_text[j] <= ' ') - break; - - if (j < 71) // sbrk card didn't have the info, stuff in current release - for (j = 0; j < 5; j++) - sbrk_text[66+j] = dmsversion[j]; + if (sbrk_text != NULL) { // sbrk card has 4 binary words followed by comment text + for (j = 66; j < 71; j++) // be sure input columns 67..71 are nonblank (have version number) + if (sbrk_text[j] <= ' ') + break; + + if (j < 71) // sbrk card didn't have the info, stuff in current release + for (j = 0; j < 5; j++) + sbrk_text[66+j] = dmsversion[j]; - binout[0] = 0; - binout[1] = 0; - binout[2] = 0; - binout[3] = 0x1000; + binout[0] = 0; + binout[1] = 0; + binout[2] = 0; + binout[3] = 0x1000; - sbrk_text += 5; // start at the real column 6 (after *SBRK - for (j = 5; j < 72; j++) - binout[j] = (*sbrk_text) ? ascii_to_hollerith(*sbrk_text++) : 0; + sbrk_text += 5; // start at the real column 6 (after *SBRK + for (j = 5; j < 72; j++) + binout[j] = (*sbrk_text) ? ascii_to_hollerith(*sbrk_text++) : 0; - } - else { // binary card format packs 54 words into 72 columns - for (i = j = 0; i < 54; i += 3, j += 4) { - binout[j ] = ( bincard[i] & 0xFFF0); - binout[j+1] = ((bincard[i] << 12) & 0xF000) | ((bincard[i+1] >> 4) & 0x0FF0); - binout[j+2] = ((bincard[i+1] << 8) & 0xFF00) | ((bincard[i+2] >> 8) & 0x00F0); - binout[j+3] = ((bincard[i+2] << 4) & 0xFFF0); - } - } + } + else { // binary card format packs 54 words into 72 columns + for (i = j = 0; i < 54; i += 3, j += 4) { + binout[j ] = ( bincard[i] & 0xFFF0); + binout[j+1] = ((bincard[i] << 12) & 0xF000) | ((bincard[i+1] >> 4) & 0x0FF0); + binout[j+2] = ((bincard[i+1] << 8) & 0xFF00) | ((bincard[i+2] >> 8) & 0x00F0); + binout[j+3] = ((bincard[i+2] << 4) & 0xFFF0); + } + } - sprintf(ident, "%08ld", ++bincard_seq); // append sequence text - memmove(ident, progname, MIN(strlen(progname), 4)); + sprintf(ident, "%08ld", ++bincard_seq); // append sequence text + memmove(ident, progname, MIN(strlen(progname), 4)); - for (i = 0; i < 8; i++) - binout[j++] = ascii_to_hollerith(ident[i]); - - fxwrite(binout, sizeof(binout[0]), 80, fout); // write card image + for (i = 0; i < 8; i++) + binout[j++] = ascii_to_hollerith(ident[i]); + + fxwrite(binout, sizeof(binout[0]), 80, fout); // write card image } // binard_writedata - emit an object data card void bincard_writedata (void) { - unsigned short rflag = 0; - int i, j, nflag = 0; + unsigned short rflag = 0; + int i, j, nflag = 0; - bincard[1] = 0; // checksum - bincard[2] = 0x0A00 | bincard_n; // data card type + word count + bincard[1] = 0; // checksum + bincard[2] = 0x0A00 | bincard_n; // data card type + word count - for (i = 0, j = 3; i < bincard_n; i++) { // construct relocation indicator bitmap - if (nflag == 8) { - bincard[j++] = rflag; - rflag = 0; - nflag = 0; - } - rflag = (rflag << 2) | (binflag[i] & 3); - nflag++; - } + for (i = 0, j = 3; i < bincard_n; i++) { // construct relocation indicator bitmap + if (nflag == 8) { + bincard[j++] = rflag; + rflag = 0; + nflag = 0; + } + rflag = (rflag << 2) | (binflag[i] & 3); + nflag++; + } - if (nflag > 0) - bincard[j] = rflag << (16 - 2*nflag); + if (nflag > 0) + bincard[j] = rflag << (16 - 2*nflag); - bincard_writecard(FALSE); // emit the card + bincard_writecard(FALSE); // emit the card } // bincard_flush - flush any pending binary data void bincard_flush (void) { - if (bincard_n > 0) - bincard_writedata(); + if (bincard_n > 0) + bincard_writedata(); - bincard_init(); + bincard_init(); } // bincard_sbrk - emit an SBRK card void bincard_sbrk (char *line) { - if (bincard_first) - bincard_typecard(); - else - bincard_flush(); + if (bincard_first) + bincard_typecard(); + else + bincard_flush(); - bincard_writecard(line); + bincard_writecard(line); } // bincard_setorg - set the origin void bincard_setorg (int neworg) { - bincard_org = neworg; // set origin for next card - bincard_flush(); // flush any current data & store origin + bincard_org = neworg; // set origin for next card + bincard_flush(); // flush any current data & store origin } // bincard_endcard - write end of program card void bincard_endcard (void) { - bincard_flush(); + bincard_flush(); - bincard[0] = (bincard_maxaddr + 2) & ~1; // effective length: add 1 to max origin, then 1 more to round up - bincard[1] = 0; - bincard[2] = 0x0F00; - bincard[3] = pta & 0xFFFF; + bincard[0] = (bincard_maxaddr + 2) & ~1; // effective length: add 1 to max origin, then 1 more to round up + bincard[1] = 0; + bincard[2] = 0x0F00; + bincard[3] = pta & 0xFFFF; - bincard_writecard(NULL); + bincard_writecard(NULL); } // bincard_typecard - write the program type void bincard_typecard (void) { - int i; + int i; - if (! bincard_first) - return; + if (! bincard_first) + return; - bincard_first = FALSE; + bincard_first = FALSE; - memset(bincard, 0, sizeof(bincard)); + memset(bincard, 0, sizeof(bincard)); - bincard[2] = (unsigned short) ((progtype << 8) | intmode | realmode); + bincard[2] = (unsigned short) ((progtype << 8) | intmode | realmode); // all indices not listed are documented as 'reserved' - switch (progtype) { - case PROGTYPE_ABSOLUTE: - case PROGTYPE_RELOCATABLE: -// bincard[ 4] = 0; // length of common (fortran only) - bincard[ 5] = 0x0003; -// bincard[ 6] = 0; // length of work area (fortran only) - bincard[ 8] = ndefined_files; - namecode(&bincard[9], progname); - bincard[11] = (pta < 0) ? 0 : pta; - break; + switch (progtype) { + case PROGTYPE_ABSOLUTE: + case PROGTYPE_RELOCATABLE: +// bincard[ 4] = 0; // length of common (fortran only) + bincard[ 5] = 0x0003; +// bincard[ 6] = 0; // length of work area (fortran only) + bincard[ 8] = ndefined_files; + namecode(&bincard[9], progname); + bincard[11] = (pta < 0) ? 0 : pta; + break; - case PROGTYPE_LIBF: - case PROGTYPE_CALL: - bincard[ 5] = 3*nentries; - for (i = 0; i < nentries; i++) { - namecode(&bincard[9+3*i], entry[i]->name); - bincard[11+3*i] = entry[i]->value; - } - break; + case PROGTYPE_LIBF: + case PROGTYPE_CALL: + bincard[ 5] = 3*nentries; + for (i = 0; i < nentries; i++) { + namecode(&bincard[9+3*i], entry[i]->name); + bincard[11+3*i] = entry[i]->value; + } + break; - case PROGTYPE_ISSLIBF: - case PROGTYPE_ISSCALL: - bincard[ 5] = 6+nintlevels; - namecode(&bincard[9], entry[0]->name); - bincard[11] = entry[0]->value; - bincard[12] = iss_number + ISTV; // magic number ISTV is 0x33 in DMS R2V12 - bincard[13] = iss_number; - bincard[14] = nintlevels; - bincard[15] = intlevel_primary; - bincard[16] = intlevel_secondary; - bincard[29] = 1; - break; + case PROGTYPE_ISSLIBF: + case PROGTYPE_ISSCALL: + bincard[ 5] = 6+nintlevels; + namecode(&bincard[9], entry[0]->name); + bincard[11] = entry[0]->value; + bincard[12] = iss_number + ISTV; // magic number ISTV is 0x33 in DMS R2V12 + bincard[13] = iss_number; + bincard[14] = nintlevels; + bincard[15] = intlevel_primary; + bincard[16] = intlevel_secondary; + bincard[29] = 1; + break; - case PROGTYPE_ILS: - bincard[ 2] = (unsigned short) (progtype << 8); - bincard[ 5] = 4; - bincard[12] = intlevel_primary; - break; + case PROGTYPE_ILS: + bincard[ 2] = (unsigned short) (progtype << 8); + bincard[ 5] = 4; + bincard[12] = intlevel_primary; + break; - default: - bail("in bincard_typecard, can't happen"); - } + default: + bail("in bincard_typecard, can't happen"); + } - bincard[1] = 0; // checksum + bincard[1] = 0; // checksum - bincard_writecard(NULL); + bincard_writecard(NULL); - bincard_init(); + bincard_init(); } // bincard_writew - write a word to the current output card. void bincard_writew (int word, RELOC relative) { - if (pass != 2) - return; + if (pass != 2) + return; - if (bincard_first) - bincard_typecard(); - else if (bincard_n >= 45) // flush full card buffer - bincard_flush(); + if (bincard_first) + bincard_typecard(); + else if (bincard_n >= 45) // flush full card buffer + bincard_flush(); - binflag[bincard_n] = relative & 3; // store relocation bits and data word - bincard[9+bincard_n++] = word; + binflag[bincard_n] = relative & 3; // store relocation bits and data word + bincard[9+bincard_n++] = word; - if (relative != LIBF) { - bincard_maxaddr = MAX(bincard_maxaddr, bincard_org); - bincard_org++; - } + if (relative != LIBF) { + bincard_maxaddr = MAX(bincard_maxaddr, bincard_org); + bincard_org++; + } } // writetwo - notification that we are about to write two words which must stay together void writetwo (void) { - if (pass == 2 && outmode == OUTMODE_BINARY && bincard_n >= 44) - bincard_flush(); + if (pass == 2 && outmode == OUTMODE_BINARY && bincard_n >= 44) + bincard_flush(); } // handle_sbrk - handle an SBRK directive. @@ -1731,27 +1731,27 @@ void writetwo (void) void handle_sbrk (char *line) { - char rline[90]; + char rline[90]; - if (pass != 2) - return; + if (pass != 2) + return; - strncpy(rline, line, 81); // get a copy and pad it if necessary to 80 characters - rline[80] = '\0'; - while (strlen(rline) < 80) - strcat(rline, " "); + strncpy(rline, line, 81); // get a copy and pad it if necessary to 80 characters + rline[80] = '\0'; + while (strlen(rline) < 80) + strcat(rline, " "); - switch (outmode) { - case OUTMODE_LOAD: - fprintf(fout, "#SBRK%s\n", trim(rline+5)); + switch (outmode) { + case OUTMODE_LOAD: + fprintf(fout, "#SBRK%s\n", trim(rline+5)); - case OUTMODE_BINARY: - bincard_sbrk(rline); - break; + case OUTMODE_BINARY: + bincard_sbrk(rline); + break; - default: - bail("in handle_sbrk, can't happen"); - } + default: + bail("in handle_sbrk, can't happen"); + } } // --------------------------------------------------------------------------------- @@ -1760,20 +1760,20 @@ void handle_sbrk (char *line) void namecode (unsigned short *words, char *tok) { - long val = 0; - int i, ch; + long val = 0; + int i, ch; - for (i = 0; i < 5; i++) { // pick up bits - if (*tok) - ch = *tok++; - else - ch = ' '; + for (i = 0; i < 5; i++) { // pick up bits + if (*tok) + ch = *tok++; + else + ch = ' '; - val = (val << 6) | (ascii_to_ebcdic_table[ch] & 0x3F); - } + val = (val << 6) | (ascii_to_ebcdic_table[ch] & 0x3F); + } - words[0] = (unsigned short) (val >> 16); - words[1] = (unsigned short) val; + words[0] = (unsigned short) (val >> 16); + words[1] = (unsigned short) val; } // --------------------------------------------------------------------------------- @@ -1782,105 +1782,105 @@ void namecode (unsigned short *words, char *tok) void parse_line (char *line) { - char label[100], mnem[100], arg[200], mods[20], *c; - struct tag_op *op; + char label[100], mnem[100], arg[200], mods[20], *c; + struct tag_op *op; - if (line[0] == '/' && line[1] == '/') // job control card? probably best to ignore it - return; + if (line[0] == '/' && line[1] == '/') // job control card? probably best to ignore it + return; - if (line[0] == '*') { // control card comment or comment in tab-format file - if (check_control) // pay attention to control cards only at top of file - if (! controlcard(line)) - check_control = FALSE; // first non-control card shuts off sensitivity to them + if (line[0] == '*') { // control card comment or comment in tab-format file + if (check_control) // pay attention to control cards only at top of file + if (! controlcard(line)) + check_control = FALSE; // first non-control card shuts off sensitivity to them - if (strnicmp(line+1, "SBRK", 4) == 0) - handle_sbrk(line); + if (strnicmp(line+1, "SBRK", 4) == 0) + handle_sbrk(line); - return; - } + return; + } - check_control = FALSE; // non-control card, consider them no more + check_control = FALSE; // non-control card, consider them no more - label[0] = '\0'; // prepare to extract fields - mods[0] = '\0'; - mnem[0] = '\0'; - arg[0] = '\0'; + label[0] = '\0'; // prepare to extract fields + mods[0] = '\0'; + mnem[0] = '\0'; + arg[0] = '\0'; - if (tabformat || strchr(line, '\t') != NULL) { // if input line has tabs, parse loosely - tabformat = TRUE; // this is a tab-formatted file + if (tabformat || strchr(line, '\t') != NULL) { // if input line has tabs, parse loosely + tabformat = TRUE; // this is a tab-formatted file - for (c = line; *c && *c <= ' '; c++) // find first nonblank - ; + for (c = line; *c && *c <= ' '; c++) // find first nonblank + ; - if (*c == '*' || ! *c) // ignore as a comment - return; + if (*c == '*' || ! *c) // ignore as a comment + return; - tabtok(line, label, 0, NULL); - tabtok(line, mnem, 1, NULL); - tabtok(line, mods, 2, NULL); - tabtok(line, arg, 3, opfield); - } - else { // if no tabs, use strict card-column format - if (line[20] == '*') // comment - return; + tabtok(line, label, 0, NULL); + tabtok(line, mnem, 1, NULL); + tabtok(line, mods, 2, NULL); + tabtok(line, arg, 3, opfield); + } + else { // if no tabs, use strict card-column format + if (line[20] == '*') // comment + return; - line[72] = '\0'; // clip off sequence + line[72] = '\0'; // clip off sequence - coltok(line, label, 21, 25, TRUE, NULL); - coltok(line, mnem, 27, 30, TRUE, NULL); - coltok(line, mods, 32, 33, TRUE, NULL); - coltok(line, arg, 35, 72, FALSE, opfield); - } + coltok(line, label, 21, 25, TRUE, NULL); + coltok(line, mnem, 27, 30, TRUE, NULL); + coltok(line, mods, 32, 33, TRUE, NULL); + coltok(line, arg, 35, 72, FALSE, opfield); + } // I don't know where I got this idea, but it's wrong... -// if (strchr(mods, '1') || strchr(mods, '2') || strchr(mods, '3')) { // index + X means ignore X -// if ((c = strchr(mods, 'X')) != NULL) -// strcpy(c, c+1); // remove the X -// } +// if (strchr(mods, '1') || strchr(mods, '2') || strchr(mods, '3')) { // index + X means ignore X +// if ((c = strchr(mods, 'X')) != NULL) +// strcpy(c, c+1); // remove the X +// } - if (*label) // display org in any line with a label - setw(0, org, FALSE); + if (*label) // display org in any line with a label + setw(0, org, FALSE); - if (! *mnem) { // label w/o mnemonic, just define the symbol - if (*label) - set_symbol(label, org, TRUE, relocate); - return; - } + if (! *mnem) { // label w/o mnemonic, just define the symbol + if (*label) + set_symbol(label, org, TRUE, relocate); + return; + } - if ((op = lookup_op(mnem)) == NULL) { // look up mnemonic - if (*label) - set_symbol(label, org, TRUE, relocate);// at least define the label + if ((op = lookup_op(mnem)) == NULL) { // look up mnemonic + if (*label) + set_symbol(label, org, TRUE, relocate);// at least define the label - asm_error("Unknown opcode '%s'", mnem); - return; - } + asm_error("Unknown opcode '%s'", mnem); + return; + } - if (op->flags & TRAP) // assembler debugging breakpoint - x_trap(op, label, mods, arg); + if (op->flags & TRAP) // assembler debugging breakpoint + x_trap(op, label, mods, arg); - if (*op->mods_allowed != '\xFF') { // validate modifiers against list of allowed characters - for (c = mods; *c; ) { - if (strchr(op->mods_allowed, *c) == NULL) { - asm_warning("Modifier '%c' not permitted", *c); - strcpy(c, c+1); // remove it and keep parsing - } - else - c++; - } - } + if (*op->mods_allowed != '\xFF') { // validate modifiers against list of allowed characters + for (c = mods; *c; ) { + if (strchr(op->mods_allowed, *c) == NULL) { + asm_warning("Modifier '%c' not permitted", *c); + strcpy(c, c+1); // remove it and keep parsing + } + else + c++; + } + } - strcat(mods, op->mods_implied); // tack on implied modifiers + strcat(mods, op->mods_implied); // tack on implied modifiers - if (strchr(mods, 'I')) // indirect implies long - strcat(mods, "L"); + if (strchr(mods, 'I')) // indirect implies long + strcat(mods, "L"); - requires_even_address = op->flags & IS_DBL; + requires_even_address = op->flags & IS_DBL; - org_advanced = strchr(mods, 'L') ? 2 : 1; // by default, * means address + 1 or 2. Sometimes it doesn't - (op->handler)(op, label, mods, arg); + org_advanced = strchr(mods, 'L') ? 2 : 1; // by default, * means address + 1 or 2. Sometimes it doesn't + (op->handler)(op, label, mods, arg); - if ((op->flags & IS_1800) && ! enable_1800) - asm_warning("%s is IBM 1800-specific; use the -8 command line option", op->mnem); + if ((op->flags & IS_1800) && ! enable_1800) + asm_warning("%s is IBM 1800-specific; use the -8 command line option", op->mnem); } // --------------------------------------------------------------------------------- @@ -1889,19 +1889,19 @@ void parse_line (char *line) BOOL get_line (char *buf, int nbuf, BOOL onelevel) { - char *retval; + char *retval; - if (ended) // we hit the END command - return FALSE; - - // if macro active, return line from macro buffer, otherwise read from file - // do not pop end-of-macro if onelevel is TRUE + if (ended) // we hit the END command + return FALSE; + + // if macro active, return line from macro buffer, otherwise read from file + // do not pop end-of-macro if onelevel is TRUE - if ((retval = fgets(buf, nbuf, fin)) == NULL) - return FALSE; + if ((retval = fgets(buf, nbuf, fin)) == NULL) + return FALSE; - lno++; // count the line - return TRUE; + lno++; // count the line + return TRUE; } // --------------------------------------------------------------------------------- @@ -1909,68 +1909,68 @@ BOOL get_line (char *buf, int nbuf, BOOL onelevel) // --------------------------------------------------------------------------------- void proc (char *fname) -{ - char line[256], *c; - int i; +{ + char line[256], *c; + int i; - if (strchr(fname, '.') == NULL) // if input file has no extension, - addextn(fname, ".asm", curfn); // set appropriate file extension - else - strcpy(curfn, fname); // otherwise use extension specified + if (strchr(fname, '.') == NULL) // if input file has no extension, + addextn(fname, ".asm", curfn); // set appropriate file extension + else + strcpy(curfn, fname); // otherwise use extension specified // let's leave filename case alone even if it doesn't matter //#if (defined(_WIN32) || defined(VMS)) -// upcase(curfn); // only force uppercase of name on Windows and VMS +// upcase(curfn); // only force uppercase of name on Windows and VMS //#endif - if (progname[0] == '\0') { // pick up primary filename - if ((c = strrchr(curfn, '\\')) == NULL) - if ((c = strrchr(curfn, '/')) == NULL) - if ((c = strrchr(curfn, ':')) == NULL) - c = curfn; + if (progname[0] == '\0') { // pick up primary filename + if ((c = strrchr(curfn, '\\')) == NULL) + if ((c = strrchr(curfn, '/')) == NULL) + if ((c = strrchr(curfn, ':')) == NULL) + c = curfn; - strncpy(progname, c, sizeof(progname)); // take name after path - progname[sizeof(progname)-1] = '\0'; - if ((c = strchr(progname, '.')) != NULL)// remove extension - *c = '\0'; - } + strncpy(progname, c, sizeof(progname)); // take name after path + progname[sizeof(progname)-1] = '\0'; + if ((c = strchr(progname, '.')) != NULL)// remove extension + *c = '\0'; + } - lno = 0; // reset global input line number - ended = FALSE; // have not seen END statement + lno = 0; // reset global input line number + ended = FALSE; // have not seen END statement - if (listfn == NULL) // if list file name is undefined, - listfn = addextn(fname, ".lst", NULL); // create from first filename + if (listfn == NULL) // if list file name is undefined, + listfn = addextn(fname, ".lst", NULL); // create from first filename - if (verbose) - fprintf(stderr, "--- Starting file %s pass %d\n", curfn, pass); + if (verbose) + fprintf(stderr, "--- Starting file %s pass %d\n", curfn, pass); - if ((fin = fopen(curfn, "r")) == NULL) { - perror(curfn); // oops - exit(1); - } + if ((fin = fopen(curfn, "r")) == NULL) { + perror(curfn); // oops + exit(1); + } - if (flist) { // put banner in listing file - strcpy(listline,"=== FILE ======================================================================"); - for (i = 9, c = curfn; *c;) - listline[i++] = *c++; - listline[i] = ' '; - fputs(listline, flist); - putc('\n', flist); - list_on = TRUE; - } - // read all lines till EOF or END statement - while (get_line(line, sizeof(line), FALSE)) { - prep_line(line); // preform standard line prep - parse_line(line); // parse - listout(FALSE); // complete the listing - } + if (flist) { // put banner in listing file + strcpy(listline,"=== FILE ======================================================================"); + for (i = 9, c = curfn; *c;) + listline[i++] = *c++; + listline[i] = ' '; + fputs(listline, flist); + putc('\n', flist); + list_on = TRUE; + } + // read all lines till EOF or END statement + while (get_line(line, sizeof(line), FALSE)) { + prep_line(line); // preform standard line prep + parse_line(line); // parse + listout(FALSE); // complete the listing + } - fclose(fin); + fclose(fin); - if (n_literals > 0) { // force out any pending literal constants at end of file - output_literals(TRUE); - listout(FALSE); - } + if (n_literals > 0) { // force out any pending literal constants at end of file + output_literals(TRUE); + listout(FALSE); + } } // --------------------------------------------------------------------------------- @@ -1979,32 +1979,32 @@ void proc (char *fname) void prep_line (char *line) { - char *c; + char *c; - upcase(line); // uppercase it - nwout = 0; // number of words output so far - line_error = FALSE; // no errors on this line so far + upcase(line); // uppercase it + nwout = 0; // number of words output so far + line_error = FALSE; // no errors on this line so far - for (c = line; *c; c++) { // truncate at newline - if (*c == '\r' || *c == '\n') { - *c = '\0'; - break; - } - } + for (c = line; *c; c++) { // truncate at newline + if (*c == '\r' || *c == '\n') { + *c = '\0'; + break; + } + } - if (flist && list_on) { // construct beginning of listing line - if (tabformat) - sprintf(listline, LINEFORMAT, lno, detab(line)); - else { - if (strlen(line) > 20) // get the part where the commands start - c = line+20; - else - c = ""; + if (flist && list_on) { // construct beginning of listing line + if (tabformat) + sprintf(listline, LINEFORMAT, lno, detab(line)); + else { + if (strlen(line) > 20) // get the part where the commands start + c = line+20; + else + c = ""; - sprintf(listline, LINEFORMAT, lno, c); - stuff(listline, line, 20); // stuff the left margin in to the left side - } - } + sprintf(listline, LINEFORMAT, lno, c); + stuff(listline, line, 20); // stuff the left margin in to the left side + } + } } // --------------------------------------------------------------------------------- @@ -2013,7 +2013,7 @@ void prep_line (char *line) int opcmp (const void *a, const void *b) { - return strcmp(((struct tag_op *) a)->mnem, ((struct tag_op *) b)->mnem); + return strcmp(((struct tag_op *) a)->mnem, ((struct tag_op *) b)->mnem); } // --------------------------------------------------------------------------------- @@ -2022,25 +2022,25 @@ int opcmp (const void *a, const void *b) void preload_symbols (void) { - FILE *fd; - char str[200], sym[20]; - int v; - static BOOL preloaded_already = FALSE; + FILE *fd; + char str[200], sym[20]; + int v; + static BOOL preloaded_already = FALSE; - if (pass > 1 || preloaded_already) - return; + if (pass > 1 || preloaded_already) + return; - preloaded_already = TRUE; + preloaded_already = TRUE; - if ((fd = fopen(SYSTEM_TABLE, "r")) == NULL) // read the system symbol tabl - perror(SYSTEM_TABLE); - else { - while (fgets(str, sizeof(str), fd) != NULL) { - if (sscanf(str, "%s %x", sym, &v) == 2) - set_symbol(sym, v, TRUE, FALSE); - } - fclose(fd); - } + if ((fd = fopen(SYSTEM_TABLE, "r")) == NULL) // read the system symbol tabl + perror(SYSTEM_TABLE); + else { + while (fgets(str, sizeof(str), fd) != NULL) { + if (sscanf(str, "%s %x", sym, &v) == 2) + set_symbol(sym, v, TRUE, FALSE); + } + fclose(fd); + } } // --------------------------------------------------------------------------------- @@ -2049,35 +2049,35 @@ void preload_symbols (void) void save_symbols (void) { - FILE *fd; - char str[20]; - PSYMBOL s; + FILE *fd; + char str[20]; + PSYMBOL s; - if (relocate) { - fprintf(stderr, "Can't save symbol table unless ABS assembly\n"); - return; - } + if (relocate) { + fprintf(stderr, "Can't save symbol table unless ABS assembly\n"); + return; + } - if ((fd = fopen(SYSTEM_TABLE, "r")) != NULL) { - fclose(fd); - if (saveprompt) { - printf("Overwrite system symbol table %s? ", SYSTEM_TABLE); - fgets(str, sizeof(str), stdin); - if (str[0] != 'y' && str[0] != 'Y') - return; - } - unlink(SYSTEM_TABLE); - } + if ((fd = fopen(SYSTEM_TABLE, "r")) != NULL) { + fclose(fd); + if (saveprompt) { + printf("Overwrite system symbol table %s? ", SYSTEM_TABLE); + fgets(str, sizeof(str), stdin); + if (str[0] != 'y' && str[0] != 'Y') + return; + } + unlink(SYSTEM_TABLE); + } - if ((fd = fopen(SYSTEM_TABLE, "w")) == NULL) { - perror(SYSTEM_TABLE); - return; - } + if ((fd = fopen(SYSTEM_TABLE, "w")) == NULL) { + perror(SYSTEM_TABLE); + return; + } - for (s = symbols; s != NULL; s = s->next) - fprintf(fd, "%-5s %04x\n", s->name, s->value); + for (s = symbols; s != NULL; s = s->next) + fprintf(fd, "%-5s %04x\n", s->name, s->value); - fclose(fd); + fclose(fd); } // --------------------------------------------------------------------------------- @@ -2086,47 +2086,47 @@ void save_symbols (void) void startpass (int n) { - int nops; - struct tag_op *p; + int nops; + struct tag_op *p; - pass = n; // reset globals: pass number - nerrors = 0; // error count - org = 0; // load address (origin) - lno = 0; // input line number - relocate = TRUE; // relocatable assembly mode - assembled = FALSE; // true if any output has been generated - list_on = do_list; // listing enable - dmes_saved = FALSE; // partial character strings output + pass = n; // reset globals: pass number + nerrors = 0; // error count + org = 0; // load address (origin) + lno = 0; // input line number + relocate = TRUE; // relocatable assembly mode + assembled = FALSE; // true if any output has been generated + list_on = do_list; // listing enable + dmes_saved = FALSE; // partial character strings output - n_literals = 0; // literal values pending output - lit_tag = 0; + n_literals = 0; // literal values pending output + lit_tag = 0; - if (pass == 1) { // first pass only - for (nops = 0, p = ops; p->mnem != NULL; p++, nops++) // count opcodes - ; + if (pass == 1) { // first pass only + for (nops = 0, p = ops; p->mnem != NULL; p++, nops++) // count opcodes + ; - qsort(ops, nops, sizeof(*p), opcmp); // sort the opcode table + qsort(ops, nops, sizeof(*p), opcmp); // sort the opcode table - if (preload) - preload_symbols(); - } - else { // second pass only - if (outfn == NULL) - outfn = addextn(curfn, (outmode == OUTMODE_LOAD) ? ".out" : ".bin" , NULL); + if (preload) + preload_symbols(); + } + else { // second pass only + if (outfn == NULL) + outfn = addextn(curfn, (outmode == OUTMODE_LOAD) ? ".out" : ".bin" , NULL); - if ((fout = fopen(outfn, OUTWRITEMODE)) == NULL) { // open output file - perror(outfn); - exit(1); - } + if ((fout = fopen(outfn, OUTWRITEMODE)) == NULL) { // open output file + perror(outfn); + exit(1); + } - if (do_list) { // open listing file - if ((flist = fopen(listfn, "w")) == NULL) { - perror(listfn); - exit(1); - } - listhdr(); // print banner - } - } + if (do_list) { // open listing file + if ((flist = fopen(listfn, "w")) == NULL) { + perror(listfn); + exit(1); + } + listhdr(); // print banner + } + } } // --------------------------------------------------------------------------------- @@ -2134,37 +2134,37 @@ void startpass (int n) // --------------------------------------------------------------------------------- void x_dc (struct tag_op *op, char *label, char *mods, char *arg) -{ - EXPR expr; -// char *tok; +{ + EXPR expr; +// char *tok; - org_advanced = 1; // assume * means this address+1 + org_advanced = 1; // assume * means this address+1 // doesn't make sense, but I think I found DMS listings to support it - if (strchr(mods, 'E') != NULL) // force even address - org_even(); + if (strchr(mods, 'E') != NULL) // force even address + org_even(); - setw(0, org, FALSE); // display org in listing line + setw(0, org, FALSE); // display org in listing line - if (*label) // define label - set_symbol(label, org, TRUE, relocate); + if (*label) // define label + set_symbol(label, org, TRUE, relocate); // just one!? - getexpr(arg, FALSE, &expr); - writew(expr.value, expr.relative); // store value + getexpr(arg, FALSE, &expr); + writew(expr.value, expr.relative); // store value - // pick up values, comma delimited -// for (tok = strtok(arg, ","); tok != NULL; tok = strtok(NULL, ",")) { -// getexpr(tok, FALSE, &expr); -// writew(expr.value, expr.relative); // store value -// } + // pick up values, comma delimited +// for (tok = strtok(arg, ","); tok != NULL; tok = strtok(NULL, ",")) { +// getexpr(tok, FALSE, &expr); +// writew(expr.value, expr.relative); // store value +// } } // --------------------------------------------------------------------------------- // x_dec - DEC define double word constant directive. // --------------------------------------------------------------------------------- -// wd[0]: 8 unused bits | characteristic (= exponent+128) +// wd[0]: 8 unused bits | characteristic (= exponent+128) // wd[1]: sign + 15 msb of mantissa in 2's complement // wd[2]: 16 lsb of mantissa @@ -2172,41 +2172,41 @@ void x_dc (struct tag_op *op, char *label, char *mods, char *arg) void convert_double_to_extended (double d, unsigned short *wd) { - int neg, exp; - unsigned long mantissa; - unsigned char *byte = (unsigned char *) &d; + int neg, exp; + unsigned long mantissa; + unsigned char *byte = (unsigned char *) &d; - if (d == 0.) { - wd[0] = wd[1] = wd[2] = 0; - return; - } - // 7 6 5 4 0 - // d = ansi real*8 SXXX XXXX XXXX MMMM MMMM MMMM MMMM MMMM ... MMMM MMMM + if (d == 0.) { + wd[0] = wd[1] = wd[2] = 0; + return; + } + // 7 6 5 4 0 + // d = ansi real*8 SXXX XXXX XXXX MMMM MMMM MMMM MMMM MMMM ... MMMM MMMM - neg = byte[7] & 0x80; - exp = ((byte[7] & 0x7F) << 4) | ((byte[6] & 0xF0) >> 4); // extract exponent - exp -= 1023; // remove bias + neg = byte[7] & 0x80; + exp = ((byte[7] & 0x7F) << 4) | ((byte[6] & 0xF0) >> 4); // extract exponent + exp -= 1023; // remove bias - exp++; // shift to account for implied 1 we added + exp++; // shift to account for implied 1 we added - // get 32 bits worth of mantissa. add the implied point - mantissa = 0x80000000L | ((byte[6] & 0x0F) << 27) | (byte[5] << 19) | (byte[4] << 11) | (byte[3] << 3) | ((byte[2] & 0xE0) >> 5); + // get 32 bits worth of mantissa. add the implied point + mantissa = 0x80000000L | ((byte[6] & 0x0F) << 27) | (byte[5] << 19) | (byte[4] << 11) | (byte[3] << 3) | ((byte[2] & 0xE0) >> 5); - if (mantissa & (0x80000000L >> 31)) // keep 31 bits, round if necessary - mantissa += (0x80000000L >> 31); + if (mantissa & (0x80000000L >> 31)) // keep 31 bits, round if necessary + mantissa += (0x80000000L >> 31); - mantissa >>= (32-31); // get into low 31 bits + mantissa >>= (32-31); // get into low 31 bits - // now turn into IBM 1130 extended precision + // now turn into IBM 1130 extended precision - exp += 128; + exp += 128; - if (neg) - mantissa = (unsigned long) (- (long) mantissa); // two's complement + if (neg) + mantissa = (unsigned long) (- (long) mantissa); // two's complement - wd[0] = (unsigned short) (exp & 0xFF); - wd[1] = (unsigned short) ((neg ? 0x8000 : 0) | ((mantissa >> (31-15)) & 0x7FFF)); - wd[2] = (unsigned short) (mantissa & 0xFFFF); + wd[0] = (unsigned short) (exp & 0xFF); + wd[1] = (unsigned short) ((neg ? 0x8000 : 0) | ((mantissa >> (31-15)) & 0x7FFF)); + wd[2] = (unsigned short) (mantissa & 0xFFFF); } // --------------------------------------------------------------------------------- @@ -2214,43 +2214,43 @@ void convert_double_to_extended (double d, unsigned short *wd) void convert_double_to_standard (double d, unsigned short *wd) { - int neg, exp; - unsigned long mantissa; - unsigned char *byte = (unsigned char *) &d; + int neg, exp; + unsigned long mantissa; + unsigned char *byte = (unsigned char *) &d; - if (d == 0.) { - wd[0] = wd[1] = 0; - return; - } - // 7 6 5 4 0 - // d = ansi real*8 SXXX XXXX XXXX MMMM MMMM MMMM MMMM MMMM ... MMMM MMMM + if (d == 0.) { + wd[0] = wd[1] = 0; + return; + } + // 7 6 5 4 0 + // d = ansi real*8 SXXX XXXX XXXX MMMM MMMM MMMM MMMM MMMM ... MMMM MMMM - neg = byte[7] & 0x80; - exp = ((byte[7] & 0x7F) << 4) | ((byte[6] & 0xF0) >> 4); // extract exponent - exp -= 1023; // remove bias + neg = byte[7] & 0x80; + exp = ((byte[7] & 0x7F) << 4) | ((byte[6] & 0xF0) >> 4); // extract exponent + exp -= 1023; // remove bias - exp++; // shift to account for implied 1 we added + exp++; // shift to account for implied 1 we added - // get 32 bits worth of mantissa. add the implied point - mantissa = 0x80000000L | ((byte[6] & 0x0F) << 27) | (byte[5] << 19) | (byte[4] << 11) | (byte[3] << 3) | ((byte[2] & 0xE0) >> 5); + // get 32 bits worth of mantissa. add the implied point + mantissa = 0x80000000L | ((byte[6] & 0x0F) << 27) | (byte[5] << 19) | (byte[4] << 11) | (byte[3] << 3) | ((byte[2] & 0xE0) >> 5); -// if (mantissa & (0x80000000L >> 23)) // keep 23 bits, round if necessary -// mantissa += (0x80000000L >> 23); +// if (mantissa & (0x80000000L >> 23)) // keep 23 bits, round if necessary +// mantissa += (0x80000000L >> 23); // DEBUG // printf("%8.4lf: %08lx %d\n", d, mantissa, exp); - mantissa >>= (32-23); // get into low 23 bits + mantissa >>= (32-23); // get into low 23 bits - // now turn into IBM 1130 standard precision + // now turn into IBM 1130 standard precision - exp += 128; + exp += 128; - if (neg) - mantissa = (unsigned long) (- (long) mantissa); // two's complement + if (neg) + mantissa = (unsigned long) (- (long) mantissa); // two's complement - wd[0] = (unsigned short) ((neg ? 0x8000 : 0) | ((mantissa >> (23-15)) & 0x7FFF)); - wd[1] = (unsigned short) ((mantissa & 0x00FF) << 8) | (exp & 0xFF); + wd[0] = (unsigned short) ((neg ? 0x8000 : 0) | ((mantissa >> (23-15)) & 0x7FFF)); + wd[1] = (unsigned short) ((mantissa & 0x00FF) << 8) | (exp & 0xFF); // DEBUG // printf(" D %04x%04x\n", wd[0], wd[1]); @@ -2261,52 +2261,52 @@ void convert_double_to_standard (double d, unsigned short *wd) void convert_double_to_fixed (double d, unsigned short *wd, int bexp) { - int neg, exp, rshift; - unsigned long mantissa; - unsigned char *byte = (unsigned char *) &d; + int neg, exp, rshift; + unsigned long mantissa; + unsigned char *byte = (unsigned char *) &d; - if (d == 0.) { - wd[0] = wd[1] = 0; - return; - } + if (d == 0.) { + wd[0] = wd[1] = 0; + return; + } - // note: we assume that this computer uses ANSI floating point + // note: we assume that this computer uses ANSI floating point - // 7 6 5 4 0 - // d = ansi real*8 SXXX XXXX XXXX MMMM MMMM MMMM MMMM MMMM ... MMMM MMMM + // 7 6 5 4 0 + // d = ansi real*8 SXXX XXXX XXXX MMMM MMMM MMMM MMMM MMMM ... MMMM MMMM - neg = byte[7] & 0x80; - exp = ((byte[7] & 0x7F) << 4) | ((byte[6] & 0xF0) >> 4); // extract exponent - exp -= 1023; // remove bias + neg = byte[7] & 0x80; + exp = ((byte[7] & 0x7F) << 4) | ((byte[6] & 0xF0) >> 4); // extract exponent + exp -= 1023; // remove bias - exp++; // shift to account for implied 1 we added + exp++; // shift to account for implied 1 we added - // get 32 bits worth of mantissa. add the implied point - mantissa = 0x80000000L | ((byte[6] & 0x0F) << 27) | (byte[5] << 19) | (byte[4] << 11) | (byte[3] << 3) | ((byte[2] & 0xE0) >> 5); + // get 32 bits worth of mantissa. add the implied point + mantissa = 0x80000000L | ((byte[6] & 0x0F) << 27) | (byte[5] << 19) | (byte[4] << 11) | (byte[3] << 3) | ((byte[2] & 0xE0) >> 5); - mantissa >>= 1; // shift it out of the sign bit + mantissa >>= 1; // shift it out of the sign bit // DEBUG // printf("%8.4lf: %08lx %d\n", d, mantissa, exp); - rshift = bexp - exp; + rshift = bexp - exp; - if (rshift > 0) { - mantissa >>= rshift; - } - else if (rshift < 0) { - mantissa >>= (-rshift); - asm_warning("Fixed point overflow"); - } + if (rshift > 0) { + mantissa >>= rshift; + } + else if (rshift < 0) { + mantissa >>= (-rshift); + asm_warning("Fixed point overflow"); + } - if (neg) - mantissa = (unsigned long) (- (long) mantissa); // two's complement + if (neg) + mantissa = (unsigned long) (- (long) mantissa); // two's complement // DEBUG // printf(" B %08lx\n", mantissa); - wd[0] = (unsigned short) ((mantissa >> 16) & 0xFFFF); // return all of the bits; no exponent here - wd[1] = (unsigned short) (mantissa & 0xFFFF); + wd[0] = (unsigned short) ((mantissa >> 16) & 0xFFFF); // return all of the bits; no exponent here + wd[1] = (unsigned short) (mantissa & 0xFFFF); } // --------------------------------------------------------------------------------- @@ -2314,45 +2314,45 @@ void convert_double_to_fixed (double d, unsigned short *wd, int bexp) void getDconstant (char *tok, unsigned short *wd) { - unsigned long l; - char *b, *fmt; - double d; - int bexp, fixed; + unsigned long l; + char *b, *fmt; + double d; + int bexp, fixed; - wd[0] = 0; - wd[1] = 0; + wd[0] = 0; + wd[1] = 0; - if (strchr(tok, '.') == NULL && strchr(tok, 'B') == NULL && strchr(tok, 'E') == NULL) { - fmt = "%ld"; - if (*tok == '/') { // I don't see that this is legal but can't hurt to allow it - fmt = "%lx"; - tok++; - } - if (sscanf(tok, fmt, &l) != 1) { // no decimal means it's an integer? - asm_error("Syntax error in constant"); - } - else { - wd[0] = (unsigned short) ((l >> 16) & 0xFFFF); // high word - wd[1] = (unsigned short) (l & 0xFFFF); // low word - } - return; - } + if (strchr(tok, '.') == NULL && strchr(tok, 'B') == NULL && strchr(tok, 'E') == NULL) { + fmt = "%ld"; + if (*tok == '/') { // I don't see that this is legal but can't hurt to allow it + fmt = "%lx"; + tok++; + } + if (sscanf(tok, fmt, &l) != 1) { // no decimal means it's an integer? + asm_error("Syntax error in constant"); + } + else { + wd[0] = (unsigned short) ((l >> 16) & 0xFFFF); // high word + wd[1] = (unsigned short) (l & 0xFFFF); // low word + } + return; + } - fixed = 0; - if ((b = strchr(tok, 'B')) != NULL) { - fixed = 1; - bexp = atoi(b+1); - *b = '\0'; // truncate at the b - } - if (sscanf(tok, "%lg", &d) != 1) { - asm_error("Syntax error in constant"); - return; - } + fixed = 0; + if ((b = strchr(tok, 'B')) != NULL) { + fixed = 1; + bexp = atoi(b+1); + *b = '\0'; // truncate at the b + } + if (sscanf(tok, "%lg", &d) != 1) { + asm_error("Syntax error in constant"); + return; + } - if (fixed) - convert_double_to_fixed(d, wd, bexp); - else - convert_double_to_standard(d, wd); + if (fixed) + convert_double_to_fixed(d, wd, bexp); + else + convert_double_to_standard(d, wd); } // --------------------------------------------------------------------------------- @@ -2363,28 +2363,28 @@ void getDconstant (char *tok, unsigned short *wd) // --------------------------------------------------------------------------------- void x_dec (struct tag_op *op, char *label, char *mods, char *arg) -{ - unsigned short wd[2]; +{ + unsigned short wd[2]; - org_advanced = 2; // assume * means address after this location, since it's +1 for dc? + org_advanced = 2; // assume * means address after this location, since it's +1 for dc? - org_even(); // even address is implied - setw(0, org, FALSE); // display the origin + org_even(); // even address is implied + setw(0, org, FALSE); // display the origin - if (*label) // define label - set_symbol(label, org, TRUE, relocate); + if (*label) // define label + set_symbol(label, org, TRUE, relocate); // just one!? - getDconstant(arg, wd); - writew(wd[0], FALSE); // write hiword, then loword - writew(wd[1], FALSE); + getDconstant(arg, wd); + writew(wd[0], FALSE); // write hiword, then loword + writew(wd[1], FALSE); - // pick up values, comma delimited -// for (tok = strtok(arg, ","); tok != NULL; tok = strtok(NULL, ",")) { -// getDconstant(tok, wd); + // pick up values, comma delimited +// for (tok = strtok(arg, ","); tok != NULL; tok = strtok(NULL, ",")) { +// getDconstant(tok, wd); // -// writew(wd[0], FALSE); // write hiword, then loword -// writew(wd[1], FALSE); +// writew(wd[0], FALSE); // write hiword, then loword +// writew(wd[1], FALSE); } // --------------------------------------------------------------------------------- @@ -2392,57 +2392,57 @@ void x_dec (struct tag_op *op, char *label, char *mods, char *arg) // --------------------------------------------------------------------------------- void x_decs (struct tag_op *op, char *label, char *mods, char *arg) -{ - unsigned short wd[2]; +{ + unsigned short wd[2]; - org_advanced = 1; // assume * means address after this location + org_advanced = 1; // assume * means address after this location - setw(0, org, FALSE); // display the origin + setw(0, org, FALSE); // display the origin - if (*label) // define label - set_symbol(label, org, TRUE, relocate); + if (*label) // define label + set_symbol(label, org, TRUE, relocate); - getDconstant(arg, wd); - writew(wd[0], FALSE); // write hiword ONLY + getDconstant(arg, wd); + writew(wd[0], FALSE); // write hiword ONLY } // --------------------------------------------------------------------------------- // --------------------------------------------------------------------------------- void x_xflc (struct tag_op *op, char *label, char *mods, char *arg) -{ - char *tok, *b; - double d; - int bexp, fixed; - unsigned short wd[3]; +{ + char *tok, *b; + double d; + int bexp, fixed; + unsigned short wd[3]; - org_advanced = 2; // who knows? + org_advanced = 2; // who knows? - setw(0, org, FALSE); // display the origin + setw(0, org, FALSE); // display the origin - if (*label) // define label - set_symbol(label, org, TRUE, relocate); - // pick up values, comma delimited - for (tok = strtok(arg, ","); tok != NULL; tok = strtok(NULL, ",")) { - bexp = 0; - if ((b = strchr(tok, 'B')) != NULL) { - bexp = atoi(b+1); - fixed = TRUE; - *b = '\0'; // truncate at the b - asm_warning("Fixed point extended floating constant?"); - } + if (*label) // define label + set_symbol(label, org, TRUE, relocate); + // pick up values, comma delimited + for (tok = strtok(arg, ","); tok != NULL; tok = strtok(NULL, ",")) { + bexp = 0; + if ((b = strchr(tok, 'B')) != NULL) { + bexp = atoi(b+1); + fixed = TRUE; + *b = '\0'; // truncate at the b + asm_warning("Fixed point extended floating constant?"); + } - if (sscanf(tok, "%lg", &d) != 1) { - asm_error("Syntax error in constant"); - d = 0.; - } + if (sscanf(tok, "%lg", &d) != 1) { + asm_error("Syntax error in constant"); + d = 0.; + } - convert_double_to_extended(d, wd); + convert_double_to_extended(d, wd); - writew(wd[0], ABSOLUTE); - writew(wd[1], ABSOLUTE); - writew(wd[2], ABSOLUTE); - } + writew(wd[0], ABSOLUTE); + writew(wd[1], ABSOLUTE); + writew(wd[2], ABSOLUTE); + } } // --------------------------------------------------------------------------------- @@ -2450,19 +2450,19 @@ void x_xflc (struct tag_op *op, char *label, char *mods, char *arg) // --------------------------------------------------------------------------------- void x_equ (struct tag_op *op, char *label, char *mods, char *arg) -{ - EXPR expr; +{ + EXPR expr; - org_advanced = FALSE; // * means this address, not incremented + org_advanced = FALSE; // * means this address, not incremented - getexpr(arg, FALSE, &expr); + getexpr(arg, FALSE, &expr); - setw(0, expr.value, expr.relative); // show this as address + setw(0, expr.value, expr.relative); // show this as address - if (*label) // EQU is all about defining labels, better have one - set_symbol(label, expr.value, TRUE, expr.relative); -// else // IBM assembler doesn't complain about this -// asm_error("EQU without label?"); + if (*label) // EQU is all about defining labels, better have one + set_symbol(label, expr.value, TRUE, expr.relative); +// else // IBM assembler doesn't complain about this +// asm_error("EQU without label?"); } // --------------------------------------------------------------------------------- @@ -2471,8 +2471,8 @@ void x_equ (struct tag_op *op, char *label, char *mods, char *arg) void x_lorg (struct tag_op *op, char *label, char *mods, char *arg) { - org_advanced = FALSE; // * means this address (not used, though) - output_literals(FALSE); // generate .DC's for queued literal values + org_advanced = FALSE; // * means this address (not used, though) + output_literals(FALSE); // generate .DC's for queued literal values } // --------------------------------------------------------------------------------- @@ -2481,28 +2481,28 @@ void x_lorg (struct tag_op *op, char *label, char *mods, char *arg) void x_abs (struct tag_op *op, char *label, char *mods, char *arg) { - if (assembled) - asm_error("ABS must be first statement"); + if (assembled) + asm_error("ABS must be first statement"); - relocate = ABSOLUTE; + relocate = ABSOLUTE; - switch (progtype) { - case PROGTYPE_ABSOLUTE: - case PROGTYPE_RELOCATABLE: - progtype = PROGTYPE_ABSOLUTE; // change program type, still assumed to be mainline - break; + switch (progtype) { + case PROGTYPE_ABSOLUTE: + case PROGTYPE_RELOCATABLE: + progtype = PROGTYPE_ABSOLUTE; // change program type, still assumed to be mainline + break; - case PROGTYPE_LIBF: - case PROGTYPE_CALL: - case PROGTYPE_ISSLIBF: - case PROGTYPE_ISSCALL: - case PROGTYPE_ILS: - asm_error("ABS not allowed with LIBF, ENT, ILS or ISS"); - break; + case PROGTYPE_LIBF: + case PROGTYPE_CALL: + case PROGTYPE_ISSLIBF: + case PROGTYPE_ISSCALL: + case PROGTYPE_ILS: + asm_error("ABS not allowed with LIBF, ENT, ILS or ISS"); + break; - default: - bail("in x_libr, can't happen"); - } + default: + bail("in x_libr, can't happen"); + } } // --------------------------------------------------------------------------------- @@ -2511,38 +2511,38 @@ void x_abs (struct tag_op *op, char *label, char *mods, char *arg) void x_call (struct tag_op *op, char *label, char *mods, char *arg) { - unsigned short words[2]; - static struct tag_op *bsi = NULL; + unsigned short words[2]; + static struct tag_op *bsi = NULL; - if (*label) // define label - set_symbol(label, org, TRUE, relocate); + if (*label) // define label + set_symbol(label, org, TRUE, relocate); - if (! *arg) { - asm_error("CALL missing argument"); - return; - } + if (! *arg) { + asm_error("CALL missing argument"); + return; + } - if (pass == 1) { // it will take two words in any case - org += 2; - return; - } + if (pass == 1) { // it will take two words in any case + org += 2; + return; + } - setw(0, org, FALSE); // display origin + setw(0, org, FALSE); // display origin - if (lookup_symbol(arg, FALSE) != NULL) { // it's a defined symbol? - if (bsi == NULL) - if ((bsi = lookup_op("BSI")) == NULL) - bail("Can't find BSI op"); + if (lookup_symbol(arg, FALSE) != NULL) { // it's a defined symbol? + if (bsi == NULL) + if ((bsi = lookup_op("BSI")) == NULL) + bail("Can't find BSI op"); - (bsi->handler)(bsi, "", "L", arg); - } - else { - namecode(words, arg); // emit namecode for loader + (bsi->handler)(bsi, "", "L", arg); + } + else { + namecode(words, arg); // emit namecode for loader - writetwo(); - writew(words[0], CALL); - writew(words[1], ABSOLUTE); - } + writetwo(); + writew(words[0], CALL); + writew(words[1], ABSOLUTE); + } } // --------------------------------------------------------------------------------- @@ -2551,17 +2551,17 @@ void x_call (struct tag_op *op, char *label, char *mods, char *arg) void x_org (struct tag_op *op, char *label, char *mods, char *arg) { - EXPR expr; + EXPR expr; - org_advanced = FALSE; // * means this address + org_advanced = FALSE; // * means this address - if (*label) // label is defined BEFORE the new origin is set!!! - set_symbol(label, org, TRUE, relocate); + if (*label) // label is defined BEFORE the new origin is set!!! + set_symbol(label, org, TRUE, relocate); - if (getexpr(arg, FALSE, &expr) != S_DEFINED) - return; + if (getexpr(arg, FALSE, &expr) != S_DEFINED) + return; - setorg(expr.value); // set origin to this value + setorg(expr.value); // set origin to this value } // --------------------------------------------------------------------------------- @@ -2570,21 +2570,21 @@ void x_org (struct tag_op *op, char *label, char *mods, char *arg) void x_end (struct tag_op *op, char *label, char *mods, char *arg) { - EXPR expr; + EXPR expr; - org_advanced = FALSE; // * means this address + org_advanced = FALSE; // * means this address - if (*arg) { // they're specifing the program start address - if (getexpr(arg, FALSE, &expr) == S_DEFINED) - pta = expr.value; - } + if (*arg) { // they're specifing the program start address + if (getexpr(arg, FALSE, &expr) == S_DEFINED) + pta = expr.value; + } - if (*label) // define label - set_symbol(label, org, TRUE, relocate); + if (*label) // define label + set_symbol(label, org, TRUE, relocate); - setw(0, org, FALSE); // display origin + setw(0, org, FALSE); // display origin - ended = TRUE; // assembly is done, stop reading file + ended = TRUE; // assembly is done, stop reading file } // --------------------------------------------------------------------------------- @@ -2593,48 +2593,48 @@ void x_end (struct tag_op *op, char *label, char *mods, char *arg) void x_ent (struct tag_op *op, char *label, char *mods, char *arg) { - PSYMBOL s; + PSYMBOL s; - org_advanced = FALSE; // * means this address + org_advanced = FALSE; // * means this address - if (pass < 2) - return; + if (pass < 2) + return; -// if (*label) // define label -// set_symbol(label, org, TRUE, relocate); +// if (*label) // define label +// set_symbol(label, org, TRUE, relocate); // -// setw(0, org, FALSE); // display origin +// setw(0, org, FALSE); // display origin - if (! *arg) - asm_error("No entry label specified"); + if (! *arg) + asm_error("No entry label specified"); - else if ((s = lookup_symbol(arg, FALSE)) == NULL) - asm_error("Entry symbol %s not defined", arg); + else if ((s = lookup_symbol(arg, FALSE)) == NULL) + asm_error("Entry symbol %s not defined", arg); - else if (nentries >= MAXENTRIES) - asm_error("Too many entries, limit is %d", MAXENTRIES); + else if (nentries >= MAXENTRIES) + asm_error("Too many entries, limit is %d", MAXENTRIES); - else - entry[nentries++] = s; // save symbol pointer + else + entry[nentries++] = s; // save symbol pointer - switch (progtype) { - case PROGTYPE_ABSOLUTE: - asm_error("ENT not allowed with ABS"); - break; - case PROGTYPE_RELOCATABLE: - progtype = PROGTYPE_CALL; - break; - case PROGTYPE_LIBF: - case PROGTYPE_CALL: - case PROGTYPE_ISSLIBF: - case PROGTYPE_ISSCALL: - break; - case PROGTYPE_ILS: - asm_error("Can't mix ENT and ILS, can you?"); - break; - default: - bail("in x_libr, can't happen"); - } + switch (progtype) { + case PROGTYPE_ABSOLUTE: + asm_error("ENT not allowed with ABS"); + break; + case PROGTYPE_RELOCATABLE: + progtype = PROGTYPE_CALL; + break; + case PROGTYPE_LIBF: + case PROGTYPE_CALL: + case PROGTYPE_ISSLIBF: + case PROGTYPE_ISSCALL: + break; + case PROGTYPE_ILS: + asm_error("Can't mix ENT and ILS, can you?"); + break; + default: + bail("in x_libr, can't happen"); + } } // --------------------------------------------------------------------------------- @@ -2643,25 +2643,25 @@ void x_ent (struct tag_op *op, char *label, char *mods, char *arg) void x_libr (struct tag_op *op, char *label, char *mods, char *arg) { - switch (progtype) { - case PROGTYPE_ABSOLUTE: - asm_error("LIBR not allowed with ABS"); - break; - case PROGTYPE_RELOCATABLE: - case PROGTYPE_LIBF: - case PROGTYPE_CALL: - progtype = PROGTYPE_LIBF; - break; - case PROGTYPE_ISSLIBF: - case PROGTYPE_ISSCALL: - progtype = PROGTYPE_ISSLIBF; - break; - case PROGTYPE_ILS: - asm_error("Can't use LIBR in an ILS"); - break; - default: - bail("in x_libr, can't happen"); - } + switch (progtype) { + case PROGTYPE_ABSOLUTE: + asm_error("LIBR not allowed with ABS"); + break; + case PROGTYPE_RELOCATABLE: + case PROGTYPE_LIBF: + case PROGTYPE_CALL: + progtype = PROGTYPE_LIBF; + break; + case PROGTYPE_ISSLIBF: + case PROGTYPE_ISSCALL: + progtype = PROGTYPE_ISSLIBF; + break; + case PROGTYPE_ILS: + asm_error("Can't use LIBR in an ILS"); + break; + default: + bail("in x_libr, can't happen"); + } } // --------------------------------------------------------------------------------- @@ -2670,26 +2670,26 @@ void x_libr (struct tag_op *op, char *label, char *mods, char *arg) void x_ils (struct tag_op *op, char *label, char *mods, char *arg) { - switch (progtype) { - case PROGTYPE_ABSOLUTE: - asm_error("ILS not allowed with ABS"); - break; - case PROGTYPE_RELOCATABLE: - case PROGTYPE_ILS: - progtype = PROGTYPE_ILS; - break; - case PROGTYPE_LIBF: - case PROGTYPE_CALL: - asm_error("Invalid placement of ILS"); - break; - case PROGTYPE_ISSLIBF: - case PROGTYPE_ISSCALL: - break; - default: - bail("in x_libr, can't happen"); - } + switch (progtype) { + case PROGTYPE_ABSOLUTE: + asm_error("ILS not allowed with ABS"); + break; + case PROGTYPE_RELOCATABLE: + case PROGTYPE_ILS: + progtype = PROGTYPE_ILS; + break; + case PROGTYPE_LIBF: + case PROGTYPE_CALL: + asm_error("Invalid placement of ILS"); + break; + case PROGTYPE_ISSLIBF: + case PROGTYPE_ISSCALL: + break; + default: + bail("in x_libr, can't happen"); + } - intlevel_primary = atoi(mods); + intlevel_primary = atoi(mods); } // --------------------------------------------------------------------------------- @@ -2698,168 +2698,168 @@ void x_ils (struct tag_op *op, char *label, char *mods, char *arg) void x_iss (struct tag_op *op, char *label, char *mods, char *arg) { - char *tok; + char *tok; - switch (progtype) { - case PROGTYPE_ABSOLUTE: - asm_error("ISS not allowed with ABS"); - break; - case PROGTYPE_RELOCATABLE: - case PROGTYPE_CALL: - case PROGTYPE_ISSCALL: - progtype = PROGTYPE_ISSCALL; - break; - case PROGTYPE_LIBF: - case PROGTYPE_ISSLIBF: - progtype = PROGTYPE_ISSLIBF; - break; - case PROGTYPE_ILS: - asm_error("Can't mix ISS and ILS"); - default: - bail("in x_libr, can't happen"); - } + switch (progtype) { + case PROGTYPE_ABSOLUTE: + asm_error("ISS not allowed with ABS"); + break; + case PROGTYPE_RELOCATABLE: + case PROGTYPE_CALL: + case PROGTYPE_ISSCALL: + progtype = PROGTYPE_ISSCALL; + break; + case PROGTYPE_LIBF: + case PROGTYPE_ISSLIBF: + progtype = PROGTYPE_ISSLIBF; + break; + case PROGTYPE_ILS: + asm_error("Can't mix ISS and ILS"); + default: + bail("in x_libr, can't happen"); + } - iss_number = atoi(mods); // get ISS number + iss_number = atoi(mods); // get ISS number - opfield[16] = '\0'; // be sure not to look too far into this + opfield[16] = '\0'; // be sure not to look too far into this - nintlevels = 0; // # of interrupt levels for ISS - intlevel_primary = 0; // primary level for ISS and level for ILS - intlevel_secondary = 0; // secondary level for ISS + nintlevels = 0; // # of interrupt levels for ISS + intlevel_primary = 0; // primary level for ISS and level for ILS + intlevel_secondary = 0; // secondary level for ISS - if ((tok = strtok(opfield, " ")) == NULL) - asm_error("ISS missing entry label"); - else - x_ent(NULL, label, "", arg); // process as an ENT + if ((tok = strtok(opfield, " ")) == NULL) + asm_error("ISS missing entry label"); + else + x_ent(NULL, label, "", arg); // process as an ENT - if ((tok = strtok(NULL, " ")) != NULL) { // get associated levels - nintlevels++; - intlevel_primary = atoi(tok); - } + if ((tok = strtok(NULL, " ")) != NULL) { // get associated levels + nintlevels++; + intlevel_primary = atoi(tok); + } - if ((tok = strtok(NULL, " ")) != NULL) { - nintlevels++; - intlevel_secondary = atoi(tok); - } + if ((tok = strtok(NULL, " ")) != NULL) { + nintlevels++; + intlevel_secondary = atoi(tok); + } } void x_spr (struct tag_op *op, char *label, char *mods, char *arg) { - realmode = REALMODE_STANDARD; + realmode = REALMODE_STANDARD; } void x_epr (struct tag_op *op, char *label, char *mods, char *arg) { - realmode = REALMODE_EXTENDED; + realmode = REALMODE_EXTENDED; } void x_dsa (struct tag_op *op, char *label, char *mods, char *arg) { - unsigned short words[2]; + unsigned short words[2]; - setw(0, org, FALSE); // display origin + setw(0, org, FALSE); // display origin - if (*label) // define label - set_symbol(label, org, TRUE, relocate); + if (*label) // define label + set_symbol(label, org, TRUE, relocate); - if (! *arg) { - asm_error("DSA missing filename"); - } - else { - namecode(words, arg); - writetwo(); - writew(words[0], CALL); // special relocation bits here 3 and 1 - writew(words[1], RELATIVE); - } + if (! *arg) { + asm_error("DSA missing filename"); + } + else { + namecode(words, arg); + writetwo(); + writew(words[0], CALL); // special relocation bits here 3 and 1 + writew(words[1], RELATIVE); + } } void x_link (struct tag_op *op, char *label, char *mods, char *arg) { - unsigned short words[2]; - char nline[128]; + unsigned short words[2]; + char nline[128]; - setw(0, org, FALSE); // display origin + setw(0, org, FALSE); // display origin - if (*label) // define label - set_symbol(label, org, TRUE, relocate); + if (*label) // define label + set_symbol(label, org, TRUE, relocate); - if (! *arg) { - asm_error("LINK missing program name"); - } - else { - format_line(nline, label, "CALL", "", "$LINK", ""); - parse_line(nline); + if (! *arg) { + asm_error("LINK missing program name"); + } + else { + format_line(nline, label, "CALL", "", "$LINK", ""); + parse_line(nline); - namecode(words, arg); - writew(words[0], ABSOLUTE); // special relocation bits here 3 and 1 - writew(words[1], ABSOLUTE); - } + namecode(words, arg); + writew(words[0], ABSOLUTE); // special relocation bits here 3 and 1 + writew(words[1], ABSOLUTE); + } } void x_libf (struct tag_op *op, char *label, char *mods, char *arg) { - unsigned short words[2]; + unsigned short words[2]; - if (*label) // define label - set_symbol(label, org, TRUE, relocate); + if (*label) // define label + set_symbol(label, org, TRUE, relocate); - if (! *arg) { - asm_error("LIBF missing argument"); - return; - } + if (! *arg) { + asm_error("LIBF missing argument"); + return; + } - if (pass == 1) { // it will take one words in any case - org++; - return; - } + if (pass == 1) { // it will take one words in any case + org++; + return; + } - setw(0, org, FALSE); // display origin + setw(0, org, FALSE); // display origin - namecode(words, arg); // emit namecode for loader + namecode(words, arg); // emit namecode for loader - writetwo(); - writew(words[0], LIBF); // this one does NOT advance org! - writew(words[1], ABSOLUTE); + writetwo(); + writew(words[0], LIBF); // this one does NOT advance org! + writew(words[1], ABSOLUTE); } void x_file (struct tag_op *op, char *label, char *mods, char *arg) { - int i, n, r; - EXPR vals[5]; - char *tok; + int i, n, r; + EXPR vals[5]; + char *tok; - for (i = 0; i < 5; i++) { - if ((tok = strtok(arg, ",")) == NULL) { - asm_error("FILE has insufficient arguments"); - return; - } - arg = NULL; // for next strtok call + for (i = 0; i < 5; i++) { + if ((tok = strtok(arg, ",")) == NULL) { + asm_error("FILE has insufficient arguments"); + return; + } + arg = NULL; // for next strtok call - if (i == 3) { - if (strcmpi(tok, "U") != 0) - asm_error("Argument 4 must be the letter U"); - } - else if (getexpr(tok, FALSE, &vals[i]) == S_DEFINED) { - if (i <= 3 && vals[i].relative) - asm_error("Argument %d must be absolute", i+1); - else if (pass == 2 && vals[i].value == 0) - asm_error("Argument %d must be nonzero", i+1); - } - } + if (i == 3) { + if (strcmpi(tok, "U") != 0) + asm_error("Argument 4 must be the letter U"); + } + else if (getexpr(tok, FALSE, &vals[i]) == S_DEFINED) { + if (i <= 3 && vals[i].relative) + asm_error("Argument %d must be absolute", i+1); + else if (pass == 2 && vals[i].value == 0) + asm_error("Argument %d must be nonzero", i+1); + } + } - writew(vals[0].value, ABSOLUTE); - writew(vals[1].value, ABSOLUTE); - writew(vals[2].value, ABSOLUTE); - writew(vals[4].value, vals[i].relative); - writew(0, ABSOLUTE); - n = MAX(1, vals[2].value); - r = 320/n; - writew(r, ABSOLUTE); - r = MAX(1, r); - writew((16*vals[1].value)/r, ABSOLUTE); + writew(vals[0].value, ABSOLUTE); + writew(vals[1].value, ABSOLUTE); + writew(vals[2].value, ABSOLUTE); + writew(vals[4].value, vals[i].relative); + writew(0, ABSOLUTE); + n = MAX(1, vals[2].value); + r = 320/n; + writew(r, ABSOLUTE); + r = MAX(1, r); + writew((16*vals[1].value)/r, ABSOLUTE); - if (pass == 2) - ndefined_files++; + if (pass == 2) + ndefined_files++; } // --------------------------------------------------------------------------------- @@ -2868,7 +2868,7 @@ void x_file (struct tag_op *op, char *label, char *mods, char *arg) void x_trap (struct tag_op *op, char *label, char *mods, char *arg) { - // debugging breakpoint + // debugging breakpoint } // --------------------------------------------------------------------------------- @@ -2880,16 +2880,16 @@ void x_trap (struct tag_op *op, char *label, char *mods, char *arg) void x_ces (struct tag_op *op, char *label, char *mods, char *arg) { - EXPR expr; + EXPR expr; - if (outmode != OUTMODE_LOAD) // this works only in our loader format - return; + if (outmode != OUTMODE_LOAD) // this works only in our loader format + return; - if (getexpr(arg, FALSE, &expr) != S_DEFINED) - return; + if (getexpr(arg, FALSE, &expr) != S_DEFINED) + return; - if (pass == 2) - fprintf(fout, "S%04x" ENDLINE, expr.value & 0xFFFF); + if (pass == 2) + fprintf(fout, "S%04x" ENDLINE, expr.value & 0xFFFF); } // --------------------------------------------------------------------------------- @@ -2898,44 +2898,44 @@ void x_ces (struct tag_op *op, char *label, char *mods, char *arg) void x_bss (struct tag_op *op, char *label, char *mods, char *arg) { - EXPR expr; + EXPR expr; - org_advanced = FALSE; // * means this address + org_advanced = FALSE; // * means this address - if (! *arg) { - expr.value = 0; - expr.relative = ABSOLUTE; - } - else if (getexpr(arg, FALSE, &expr) != S_DEFINED) - return; + if (! *arg) { + expr.value = 0; + expr.relative = ABSOLUTE; + } + else if (getexpr(arg, FALSE, &expr) != S_DEFINED) + return; - if (strchr(mods, 'E') != NULL) // force even address - org_even(); + if (strchr(mods, 'E') != NULL) // force even address + org_even(); - if (expr.relative) - asm_error("BSS size must be an absolute value"); + if (expr.relative) + asm_error("BSS size must be an absolute value"); - setw(0, org, FALSE); // display origin + setw(0, org, FALSE); // display origin - if (*label) // define label - set_symbol(label, org, TRUE, relocate); + if (*label) // define label + set_symbol(label, org, TRUE, relocate); - expr.value &= 0xFFFF; // truncate to 16 bits + expr.value &= 0xFFFF; // truncate to 16 bits - if (expr.value & 0x8000) - asm_warning("Negative BSS size"); - else if (expr.value > 0) { - if (outmode == OUTMODE_LOAD) { - org += expr.value; // advance the origin by appropriate number of words - if (pass == 2) // emit new load address in output file - fprintf(fout, "@%04x%s" ENDLINE, org & 0xFFFF, relocate ? "R" : ""); - } - else { - org += expr.value; // advance the origin by appropriate number of words - if (pass == 2) - bincard_setorg(org); - } - } + if (expr.value & 0x8000) + asm_warning("Negative BSS size"); + else if (expr.value > 0) { + if (outmode == OUTMODE_LOAD) { + org += expr.value; // advance the origin by appropriate number of words + if (pass == 2) // emit new load address in output file + fprintf(fout, "@%04x%s" ENDLINE, org & 0xFFFF, relocate ? "R" : ""); + } + else { + org += expr.value; // advance the origin by appropriate number of words + if (pass == 2) + bincard_setorg(org); + } + } } // --------------------------------------------------------------------------------- @@ -2944,42 +2944,42 @@ void x_bss (struct tag_op *op, char *label, char *mods, char *arg) void x_bes (struct tag_op *op, char *label, char *mods, char *arg) { - EXPR expr; + EXPR expr; - org_advanced = FALSE; // * means this address + org_advanced = FALSE; // * means this address - if (! *arg) { // arg field = space - expr.value = 0; - expr.relative = ABSOLUTE; - } - else if (getexpr(arg, FALSE, &expr) != S_DEFINED) - return; + if (! *arg) { // arg field = space + expr.value = 0; + expr.relative = ABSOLUTE; + } + else if (getexpr(arg, FALSE, &expr) != S_DEFINED) + return; - if (strchr(mods, 'E') != NULL && (org & 1) != 0) - org_even(); // force even address + if (strchr(mods, 'E') != NULL && (org & 1) != 0) + org_even(); // force even address - if (expr.relative) - asm_error("BES size must be an absolute value"); + if (expr.relative) + asm_error("BES size must be an absolute value"); - if (expr.value < 0) - asm_warning("Negative BES size"); + if (expr.value < 0) + asm_warning("Negative BES size"); - else if (expr.value > 0) { - setw(0, org+expr.value, FALSE); // display NEW origin + else if (expr.value > 0) { + setw(0, org+expr.value, FALSE); // display NEW origin - if (outmode == OUTMODE_LOAD) { - org += expr.value; // advance the origin - if (pass == 2) // emit new load address in output file - fprintf(fout, "@%04x%s" ENDLINE, org & 0xFFFF, relocate ? "R" : ""); - } - else { - org += expr.value; // advance the origin - bincard_setorg(org); - } - } + if (outmode == OUTMODE_LOAD) { + org += expr.value; // advance the origin + if (pass == 2) // emit new load address in output file + fprintf(fout, "@%04x%s" ENDLINE, org & 0xFFFF, relocate ? "R" : ""); + } + else { + org += expr.value; // advance the origin + bincard_setorg(org); + } + } - if (*label) // NOW define the label - set_symbol(label, org, TRUE, relocate); + if (*label) // NOW define the label + set_symbol(label, org, TRUE, relocate); } // --------------------------------------------------------------------------------- @@ -2993,125 +2993,125 @@ void stuff_dmes (int ch, int rpt); void x_dmes (struct tag_op *op, char *label, char *mods, char *arg) { - int rpt; - char *c = opfield; - BOOL cont = FALSE; + int rpt; + char *c = opfield; + BOOL cont = FALSE; - if (dmes_saved) { // previous DMES had an odd character saved - dmes_wd = dmes_savew; - dmes_nc = 1; // stick it into the outbut buffer - } - else - dmes_nc = dmes_wd = 0; // clear output buffer + if (dmes_saved) { // previous DMES had an odd character saved + dmes_wd = dmes_savew; + dmes_nc = 1; // stick it into the outbut buffer + } + else + dmes_nc = dmes_wd = 0; // clear output buffer - trim(opfield); // remove trailing blanks from rest of input line (use whole thing) - setw(0, org, FALSE); // display origin + trim(opfield); // remove trailing blanks from rest of input line (use whole thing) + setw(0, org, FALSE); // display origin - if (*label) // define label - set_symbol(label, org, TRUE, relocate); + if (*label) // define label + set_symbol(label, org, TRUE, relocate); - if (strchr(mods, '1') != NULL) // determine the encoding scheme - dmes_cs = CODESET_1403; - else if (strchr(mods, '2') != NULL) - dmes_cs = CODESET_1132; - else if (strchr(mods, '0') != NULL || ! *mods) - dmes_cs = CODESET_CONSOLE; - else { - asm_error("Invalid printer code in tag field"); - dmes_cs = CODESET_EBCDIC; - } + if (strchr(mods, '1') != NULL) // determine the encoding scheme + dmes_cs = CODESET_1403; + else if (strchr(mods, '2') != NULL) + dmes_cs = CODESET_1132; + else if (strchr(mods, '0') != NULL || ! *mods) + dmes_cs = CODESET_CONSOLE; + else { + asm_error("Invalid printer code in tag field"); + dmes_cs = CODESET_EBCDIC; + } - while (*c) { // pick up characters - if (*c == '\'') { // quote (') is the escape character - c++; + while (*c) { // pick up characters + if (*c == '\'') { // quote (') is the escape character + c++; - rpt = 0; // get repeat count - while (BETWEEN(*c, '0', '9')) { - rpt = rpt*10 + *c++ - '0'; - } - if (rpt <= 0) // no count = insert one copy - rpt = 1; + rpt = 0; // get repeat count + while (BETWEEN(*c, '0', '9')) { + rpt = rpt*10 + *c++ - '0'; + } + if (rpt <= 0) // no count = insert one copy + rpt = 1; - switch (*c) { // handle escape codes - case '\'': - stuff_dmes(*c, 1); - break; + switch (*c) { // handle escape codes + case '\'': + stuff_dmes(*c, 1); + break; - case 'E': - *c = '\0'; // end - break; + case 'E': + *c = '\0'; // end + break; - case 'X': - case 'S': - stuff_dmes(' ', rpt); - break; + case 'X': + case 'S': + stuff_dmes(' ', rpt); + break; - case 'F': - stuff_dmes(*++c, rpt); // repeat character - break; + case 'F': + stuff_dmes(*++c, rpt); // repeat character + break; - case ' ': - case '\0': - cont = TRUE; - *c = '\0'; // end - break; + case ' ': + case '\0': + cont = TRUE; + *c = '\0'; // end + break; - case 'T': - if (dmes_cs != CODESET_CONSOLE) { -badcode: asm_error("Invalid ' escape for selected printer"); - break; - } - stuff_dmes(0x41, -rpt); // tab - break; + case 'T': + if (dmes_cs != CODESET_CONSOLE) { +badcode: asm_error("Invalid ' escape for selected printer"); + break; + } + stuff_dmes(0x41, -rpt); // tab + break; - case 'D': - if (dmes_cs != CODESET_CONSOLE) goto badcode; - stuff_dmes(0x11, -rpt); // backspace - break; + case 'D': + if (dmes_cs != CODESET_CONSOLE) goto badcode; + stuff_dmes(0x11, -rpt); // backspace + break; - case 'B': - if (dmes_cs != CODESET_CONSOLE) goto badcode; - stuff_dmes(0x05, -rpt); // black - break; + case 'B': + if (dmes_cs != CODESET_CONSOLE) goto badcode; + stuff_dmes(0x05, -rpt); // black + break; - case 'A': - if (dmes_cs != CODESET_CONSOLE) goto badcode; - stuff_dmes(0x09, -rpt); // red - break; + case 'A': + if (dmes_cs != CODESET_CONSOLE) goto badcode; + stuff_dmes(0x09, -rpt); // red + break; - case 'R': - if (dmes_cs != CODESET_CONSOLE) goto badcode; - stuff_dmes(0x81, -rpt); // return - break; + case 'R': + if (dmes_cs != CODESET_CONSOLE) goto badcode; + stuff_dmes(0x81, -rpt); // return + break; - case 'L': - if (dmes_cs != CODESET_CONSOLE) goto badcode; - stuff_dmes(0x03, -rpt); // line feed - break; - - default: - asm_error("Invalid ' escape in DMES"); - *c = '\0'; - break; - } - } - else // just copy literal character - stuff_dmes(*c, 1); + case 'L': + if (dmes_cs != CODESET_CONSOLE) goto badcode; + stuff_dmes(0x03, -rpt); // line feed + break; + + default: + asm_error("Invalid ' escape in DMES"); + *c = '\0'; + break; + } + } + else // just copy literal character + stuff_dmes(*c, 1); - if (*c) - c++; - } + if (*c) + c++; + } - dmes_saved = FALSE; + dmes_saved = FALSE; - if (dmes_nc) { // odd number of characters - if (cont) { - dmes_saved = TRUE; - dmes_savew = dmes_wd; // save for next time - } - else - stuff_dmes(' ', 1); // pad with a space to force out even # of characters - } + if (dmes_nc) { // odd number of characters + if (cont) { + dmes_saved = TRUE; + dmes_savew = dmes_wd; // save for next time + } + else + stuff_dmes(' ', 1); // pad with a space to force out even # of characters + } } // --------------------------------------------------------------------------------- @@ -3120,63 +3120,63 @@ badcode: asm_error("Invalid ' escape for selected printer"); void stuff_dmes (int ch, int rpt) { - int nch, i; // nch is translated output value + int nch, i; // nch is translated output value - if (rpt < 0) { // negative repeat means no translation needed - rpt = -rpt; - nch = ch; - } - else { - switch (dmes_cs) { - case CODESET_CONSOLE: - nch = 0x21; - for (i = 0; i < 256; i++) { - if (conout_to_ascii[i] == ch) { - nch = i; - break; - } - } - break; + if (rpt < 0) { // negative repeat means no translation needed + rpt = -rpt; + nch = ch; + } + else { + switch (dmes_cs) { + case CODESET_CONSOLE: + nch = 0x21; + for (i = 0; i < 256; i++) { + if (conout_to_ascii[i] == ch) { + nch = i; + break; + } + } + break; - case CODESET_EBCDIC: - nch = ascii_to_ebcdic_table[ch & 0x7F]; - if (nch == 0) - nch = 0x7F; - break; + case CODESET_EBCDIC: + nch = ascii_to_ebcdic_table[ch & 0x7F]; + if (nch == 0) + nch = 0x7F; + break; - case CODESET_1403: - nch = ascii_to_1403_table[ch & 0x7F]; - if (nch == 0) - nch = 0x7F; - break; + case CODESET_1403: + nch = ascii_to_1403_table[ch & 0x7F]; + if (nch == 0) + nch = 0x7F; + break; - case CODESET_1132: - nch = 0x40; - for (i = 0; i < WHEELCHARS_1132; i++) { - if (codewheel1132[i].ascii == ch) { - nch = codewheel1132[i].ebcdic; - break; - } - } - break; + case CODESET_1132: + nch = 0x40; + for (i = 0; i < WHEELCHARS_1132; i++) { + if (codewheel1132[i].ascii == ch) { + nch = codewheel1132[i].ebcdic; + break; + } + } + break; - default: - bail("bad cs in x_dmes, can't happen"); - break; - } - } - - while (--rpt >= 0) { // pack them into words, output when we have two - if (dmes_nc == 0) { - dmes_wd = (nch & 0xFF) << 8; - dmes_nc = 1; - } - else { - dmes_wd |= (nch & 0xFF); - writew(dmes_wd, FALSE); - dmes_nc = 0; - } - } + default: + bail("bad cs in x_dmes, can't happen"); + break; + } + } + + while (--rpt >= 0) { // pack them into words, output when we have two + if (dmes_nc == 0) { + dmes_wd = (nch & 0xFF) << 8; + dmes_nc = 1; + } + else { + dmes_wd |= (nch & 0xFF); + writew(dmes_wd, FALSE); + dmes_nc = 0; + } + } } // --------------------------------------------------------------------------------- @@ -3185,31 +3185,31 @@ void stuff_dmes (int ch, int rpt) void x_ebc (struct tag_op *op, char *label, char *mods, char *arg) { - char *p; + char *p; -// setw(0, org, FALSE); - if (*label) - set_symbol(label, org, TRUE, relocate); +// setw(0, org, FALSE); + if (*label) + set_symbol(label, org, TRUE, relocate); - p = trim(opfield); // remove trailing blanks from rest of input line (use whole thing) + p = trim(opfield); // remove trailing blanks from rest of input line (use whole thing) - if (*p != '.') { - asm_error("EBC data must start with ."); - return; - } - p++; // skip leading period + if (*p != '.') { + asm_error("EBC data must start with ."); + return; + } + p++; // skip leading period - dmes_nc = dmes_wd = 0; // clear output buffer (we're borrowing the DMES packer) - dmes_cs = CODESET_EBCDIC; + dmes_nc = dmes_wd = 0; // clear output buffer (we're borrowing the DMES packer) + dmes_cs = CODESET_EBCDIC; - while (*p && *p != '.') // store packed ebcdic - stuff_dmes(*p++, 1); + while (*p && *p != '.') // store packed ebcdic + stuff_dmes(*p++, 1); - if (dmes_nc) // odd number of characters - stuff_dmes(' ', 1); // pad with a space to force out even # of characters + if (dmes_nc) // odd number of characters + stuff_dmes(' ', 1); // pad with a space to force out even # of characters - if (*p != '.') - asm_error("EBC missing closing ."); + if (*p != '.') + asm_error("EBC missing closing ."); } // --------------------------------------------------------------------------------- @@ -3219,17 +3219,17 @@ void x_ebc (struct tag_op *op, char *label, char *mods, char *arg) void x_dn (struct tag_op *op, char *label, char *mods, char *arg) { - unsigned short words[2]; + unsigned short words[2]; - setw(0, org, FALSE); // display origin + setw(0, org, FALSE); // display origin - if (*label) // define label - set_symbol(label, org, TRUE, relocate); + if (*label) // define label + set_symbol(label, org, TRUE, relocate); - namecode(words, arg); + namecode(words, arg); - writew(words[0], ABSOLUTE); - writew(words[1], ABSOLUTE); + writew(words[0], ABSOLUTE); + writew(words[1], ABSOLUTE); } // --------------------------------------------------------------------------------- @@ -3238,8 +3238,8 @@ void x_dn (struct tag_op *op, char *label, char *mods, char *arg) void x_dump (struct tag_op *op, char *label, char *mods, char *arg) { - x_pdmp(op, label, mods, arg); - x_exit(NULL, "", "", ""); // compile "call $exit" + x_pdmp(op, label, mods, arg); + x_exit(NULL, "", "", ""); // compile "call $exit" } // --------------------------------------------------------------------------------- @@ -3248,25 +3248,25 @@ void x_dump (struct tag_op *op, char *label, char *mods, char *arg) void x_pdmp (struct tag_op *op, char *label, char *mods, char *arg) { - char nline[200], *tok; - EXPR addr[3]; - int i; + char nline[200], *tok; + EXPR addr[3]; + int i; - for (i = 0, tok = strtok(arg, ","); i < 3 && tok != NULL; i++, tok = strtok(NULL, ",")) { - if (getexpr(tok, FALSE, addr+i) != S_DEFINED) { - addr[i].value = (i == 1) ? 0x3FFF : 0; - addr[i].relative = ABSOLUTE; - } - } + for (i = 0, tok = strtok(arg, ","); i < 3 && tok != NULL; i++, tok = strtok(NULL, ",")) { + if (getexpr(tok, FALSE, addr+i) != S_DEFINED) { + addr[i].value = (i == 1) ? 0x3FFF : 0; + addr[i].relative = ABSOLUTE; + } + } - org_advanced = FALSE; // * means this address+1 + org_advanced = FALSE; // * means this address+1 - format_line(nline, label, "BSI", "L", DOLLARDUMP, ""); - parse_line(nline); // compile "call $dump" + format_line(nline, label, "BSI", "L", DOLLARDUMP, ""); + parse_line(nline); // compile "call $dump" - writew(addr[2].value, ABSOLUTE); // append arguments (0, start, end address) - writew(addr[0].value, addr[0].relative); - writew(addr[1].value, addr[1].relative); + writew(addr[2].value, ABSOLUTE); // append arguments (0, start, end address) + writew(addr[0].value, addr[0].relative); + writew(addr[1].value, addr[1].relative); } // --------------------------------------------------------------------------------- @@ -3275,20 +3275,20 @@ void x_pdmp (struct tag_op *op, char *label, char *mods, char *arg) void x_hdng (struct tag_op *op, char *label, char *mods, char *arg) { - char *c; + char *c; - // label is not entered into the symbol table + // label is not entered into the symbol table - if (flist == NULL || ! list_on) { - line_error = TRUE; // inhibit listing: don't print the HDNG statement - return; - } + if (flist == NULL || ! list_on) { + line_error = TRUE; // inhibit listing: don't print the HDNG statement + return; + } - line_error = TRUE; // don't print the statement + line_error = TRUE; // don't print the statement - c = skipbl(opfield); - trim(c); - fprintf(flist, "\f%s\n\n", c); // print page header + c = skipbl(opfield); + trim(c); + fprintf(flist, "\f%s\n\n", c); // print page header } // --------------------------------------------------------------------------------- @@ -3297,24 +3297,24 @@ void x_hdng (struct tag_op *op, char *label, char *mods, char *arg) void x_list (struct tag_op *op, char *label, char *mods, char *arg) { - BOOL on; + BOOL on; - // label is not entered into the symbol table + // label is not entered into the symbol table - line_error = TRUE; // don't print the LIST statement + line_error = TRUE; // don't print the LIST statement - if (flist == NULL || ! list_on) { - return; - } + if (flist == NULL || ! list_on) { + return; + } - if (strcmpi(arg, "ON") == 0) - on = TRUE; - else if (strcmpi(arg, "OFF") == 0) - on = FALSE; - else - on = do_list; + if (strcmpi(arg, "ON") == 0) + on = TRUE; + else if (strcmpi(arg, "OFF") == 0) + on = FALSE; + else + on = do_list; - list_on = on; + list_on = on; } // --------------------------------------------------------------------------------- @@ -3323,22 +3323,22 @@ void x_list (struct tag_op *op, char *label, char *mods, char *arg) void x_spac (struct tag_op *op, char *label, char *mods, char *arg) { - EXPR expr; + EXPR expr; - // label is not entered into the symbol table + // label is not entered into the symbol table - if (flist == NULL || ! list_on) { - line_error = TRUE; // don't print the SPAC statement - return; - } + if (flist == NULL || ! list_on) { + line_error = TRUE; // don't print the SPAC statement + return; + } - if (getexpr(arg, FALSE, &expr) != S_DEFINED) - return; + if (getexpr(arg, FALSE, &expr) != S_DEFINED) + return; - line_error = TRUE; // don't print the statement + line_error = TRUE; // don't print the statement - while (--expr.value >= 0) - putc('\n', flist); + while (--expr.value >= 0) + putc('\n', flist); } // --------------------------------------------------------------------------------- @@ -3347,16 +3347,16 @@ void x_spac (struct tag_op *op, char *label, char *mods, char *arg) void x_ejct (struct tag_op *op, char *label, char *mods, char *arg) { - // label is not entered into the symbol table + // label is not entered into the symbol table - if (flist == NULL || ! list_on) { - line_error = TRUE; // don't print the EJCT statement - return; - } + if (flist == NULL || ! list_on) { + line_error = TRUE; // don't print the EJCT statement + return; + } - line_error = TRUE; // don't print the statement + line_error = TRUE; // don't print the statement - putc('\f', flist); + putc('\f', flist); } // --------------------------------------------------------------------------------- @@ -3365,22 +3365,22 @@ void x_ejct (struct tag_op *op, char *label, char *mods, char *arg) int basic_opcode (struct tag_op *op, char *mods) { - int opcode = op->opcode; // basic code value + int opcode = op->opcode; // basic code value - if (strchr(mods, '1') != 0) // indexing - opcode |= 0x0100; - else if (strchr(mods, '2') != 0) - opcode |= 0x0200; - else if (strchr(mods, '3') != 0) - opcode |= 0x0300; + if (strchr(mods, '1') != 0) // indexing + opcode |= 0x0100; + else if (strchr(mods, '2') != 0) + opcode |= 0x0200; + else if (strchr(mods, '3') != 0) + opcode |= 0x0300; - if (strchr(mods, 'L')) { // two-word format - opcode |= OP_LONG; - if (strchr(mods, 'I') != 0) // and indirect to boot - opcode |= OP_INDIRECT; - } + if (strchr(mods, 'L')) { // two-word format + opcode |= OP_LONG; + if (strchr(mods, 'I') != 0) // and indirect to boot + opcode |= OP_INDIRECT; + } - return opcode; + return opcode; } // --------------------------------------------------------------------------------- @@ -3389,40 +3389,40 @@ int basic_opcode (struct tag_op *op, char *mods) void std_op (struct tag_op *op, char *label, char *mods, char *arg) { - EXPR expr; - int opcode = basic_opcode(op, mods); - BOOL val_ok = FALSE; + EXPR expr; + int opcode = basic_opcode(op, mods); + BOOL val_ok = FALSE; - if (*label) // define label - set_symbol(label, org, TRUE, relocate); + if (*label) // define label + set_symbol(label, org, TRUE, relocate); - if (*arg && ! (op->flags & NO_ARGS)) { // get value argument - if (getexpr(arg, FALSE, &expr) == S_DEFINED) - val_ok = TRUE; - } - else { - expr.value = 0; - expr.relative = FALSE; - } + if (*arg && ! (op->flags & NO_ARGS)) { // get value argument + if (getexpr(arg, FALSE, &expr) == S_DEFINED) + val_ok = TRUE; + } + else { + expr.value = 0; + expr.relative = FALSE; + } - if (opcode & OP_LONG) { // two-word format, just write code and value - writew(opcode, FALSE); - writew(expr.value, expr.relative); - } - else { // one-word format - if (strchr(mods, 'I') != 0) - asm_error("Indirect mode not permitted on one-word instructions"); + if (opcode & OP_LONG) { // two-word format, just write code and value + writew(opcode, FALSE); + writew(expr.value, expr.relative); + } + else { // one-word format + if (strchr(mods, 'I') != 0) + asm_error("Indirect mode not permitted on one-word instructions"); - if (val_ok && ! (strchr(mods, 'X') || (op->flags & IS_ABS) || ((opcode & OP_INDEXED) && ! (op->flags & NO_IDX)))) - expr.value -= (org+1); // compute displacement + if (val_ok && ! (strchr(mods, 'X') || (op->flags & IS_ABS) || ((opcode & OP_INDEXED) && ! (op->flags & NO_IDX)))) + expr.value -= (org+1); // compute displacement - if (expr.value < -128 || expr.value > 127) {// check range - asm_error("Offset of %d is too large", expr.value); - expr.value = 0; - } + if (expr.value < -128 || expr.value > 127) {// check range + asm_error("Offset of %d is too large", expr.value); + expr.value = 0; + } - writew(opcode | (expr.value & 0x00FF), FALSE);// that's the code - } + writew(opcode | (expr.value & 0x00FF), FALSE);// that's the code + } } // --------------------------------------------------------------------------------- @@ -3431,61 +3431,61 @@ void std_op (struct tag_op *op, char *label, char *mods, char *arg) void mdx_op (struct tag_op *op, char *label, char *mods, char *arg) { - EXPR dest, incr = {0, FALSE}; - int opcode = basic_opcode(op, mods); - char *tok; + EXPR dest, incr = {0, FALSE}; + int opcode = basic_opcode(op, mods); + char *tok; - if (*label) // define label - set_symbol(label, org, TRUE, relocate); + if (*label) // define label + set_symbol(label, org, TRUE, relocate); - if ((tok = strtok(arg, ",")) == NULL) { // argument format is dest[,increment] -// asm_error("Destination not specified"); // seems not to be an error, IBM omits it sometimes - dest.value = 0; - dest.relative = ABSOLUTE; - } - else - getexpr(tok, FALSE, &dest); // parse the address + if ((tok = strtok(arg, ",")) == NULL) { // argument format is dest[,increment] +// asm_error("Destination not specified"); // seems not to be an error, IBM omits it sometimes + dest.value = 0; + dest.relative = ABSOLUTE; + } + else + getexpr(tok, FALSE, &dest); // parse the address - tok = strtok(NULL, ","); // look for second argument + tok = strtok(NULL, ","); // look for second argument - if (opcode & OP_LONG) { // two word format - if (opcode & OP_INDEXED) { // format: MDX 2 dest - if (tok != NULL) - asm_error("This format takes only one argument"); - } - else { // format: MDX dest,increment - if (opcode & OP_INDIRECT) - asm_error("Indirect can't be used without indexing"); + if (opcode & OP_LONG) { // two word format + if (opcode & OP_INDEXED) { // format: MDX 2 dest + if (tok != NULL) + asm_error("This format takes only one argument"); + } + else { // format: MDX dest,increment + if (opcode & OP_INDIRECT) + asm_error("Indirect can't be used without indexing"); - if (tok == NULL) { -// asm_error("This format takes two arguments"); - incr.value = 0; - incr.relative = ABSOLUTE; - } - else - getexpr(tok, FALSE, &incr); + if (tok == NULL) { +// asm_error("This format takes two arguments"); + incr.value = 0; + incr.relative = ABSOLUTE; + } + else + getexpr(tok, FALSE, &incr); - if (incr.value < -128 || incr.value > 127) // displacement style (fixed in ver 1.08) - asm_error("Invalid increment value (8 bits signed)"); + if (incr.value < -128 || incr.value > 127) // displacement style (fixed in ver 1.08) + asm_error("Invalid increment value (8 bits signed)"); - opcode |= (incr.value & 0xFF); - } + opcode |= (incr.value & 0xFF); + } - writew(opcode, ABSOLUTE); - writew(dest.value, dest.relative); - } - else { // one word format MDX val - if (tok != NULL) - asm_error("This format takes only one argument"); + writew(opcode, ABSOLUTE); + writew(dest.value, dest.relative); + } + else { // one word format MDX val + if (tok != NULL) + asm_error("This format takes only one argument"); - if (! (strchr(mods, 'X') || (opcode & OP_INDEXED))) - dest.value -= (org+1); // compute displacement + if (! (strchr(mods, 'X') || (opcode & OP_INDEXED))) + dest.value -= (org+1); // compute displacement - if (dest.value < -128 || dest.value > 127) - asm_error("Offset/Increment of %d is too large", dest.value); + if (dest.value < -128 || dest.value > 127) + asm_error("Offset/Increment of %d is too large", dest.value); - writew(opcode | (dest.value & 0xFF), FALSE); - } + writew(opcode | (dest.value & 0xFF), FALSE); + } } // --------------------------------------------------------------------------------- @@ -3494,10 +3494,10 @@ void mdx_op (struct tag_op *op, char *label, char *mods, char *arg) void bsi_op (struct tag_op *op, char *label, char *mods, char *arg) { - if (strchr(mods, 'L') || strchr(mods, 'I')) - bsc_op(op, label, mods, arg); - else - std_op(op, label, mods, arg); + if (strchr(mods, 'L') || strchr(mods, 'I')) + bsc_op(op, label, mods, arg); + else + std_op(op, label, mods, arg); } // --------------------------------------------------------------------------------- @@ -3506,18 +3506,18 @@ void bsi_op (struct tag_op *op, char *label, char *mods, char *arg) void b_op (struct tag_op *op, char *label, char *mods, char *arg) { - static struct tag_op *mdx = NULL; + static struct tag_op *mdx = NULL; - if (strchr(mods, 'L') || strchr(mods, 'I')) { - bsi_op(op, label, mods, arg); - return; - } + if (strchr(mods, 'L') || strchr(mods, 'I')) { + bsi_op(op, label, mods, arg); + return; + } - if (mdx == NULL) - if ((mdx = lookup_op("MDX")) == NULL) - bail("Can't find MDX op"); + if (mdx == NULL) + if ((mdx = lookup_op("MDX")) == NULL) + bail("Can't find MDX op"); - (mdx->handler)(mdx, label, mods, arg); + (mdx->handler)(mdx, label, mods, arg); } // --------------------------------------------------------------------------------- @@ -3526,47 +3526,47 @@ void b_op (struct tag_op *op, char *label, char *mods, char *arg) void bsc_op (struct tag_op *op, char *label, char *mods, char *arg) { - EXPR dest; - int opcode = basic_opcode(op, mods); - char *tok, *tests; + EXPR dest; + int opcode = basic_opcode(op, mods); + char *tok, *tests; - if (*label) // define label - set_symbol(label, org, TRUE, relocate); + if (*label) // define label + set_symbol(label, org, TRUE, relocate); - if (opcode & OP_LONG) { // two word format - if ((tok = strtok(arg, ",")) == NULL) { // format is BSC dest[,tests] - asm_error("Destination not specified"); - dest.value = 0; - dest.relative = ABSOLUTE; - } - else - getexpr(tok, FALSE, &dest); + if (opcode & OP_LONG) { // two word format + if ((tok = strtok(arg, ",")) == NULL) { // format is BSC dest[,tests] + asm_error("Destination not specified"); + dest.value = 0; + dest.relative = ABSOLUTE; + } + else + getexpr(tok, FALSE, &dest); - tests = strtok(NULL, ","); // get test characters - } - else - tests = arg; // short format is BSC tests + tests = strtok(NULL, ","); // get test characters + } + else + tests = arg; // short format is BSC tests - if (tests != NULL) { // stick in the testing bits - for (; *tests; tests++) { - switch (*tests) { - // bit 0x40 is the BOSC bit - case 'Z': opcode |= 0x20; break; - case '-': opcode |= 0x10; break; - case '+': - case '&': opcode |= 0x08; break; - case 'E': opcode |= 0x04; break; - case 'C': opcode |= 0x02; break; - case 'O': opcode |= 0x01; break; - default: - asm_error("Invalid test flag: '%c'", *tests); - } - } - } + if (tests != NULL) { // stick in the testing bits + for (; *tests; tests++) { + switch (*tests) { + // bit 0x40 is the BOSC bit + case 'Z': opcode |= 0x20; break; + case '-': opcode |= 0x10; break; + case '+': + case '&': opcode |= 0x08; break; + case 'E': opcode |= 0x04; break; + case 'C': opcode |= 0x02; break; + case 'O': opcode |= 0x01; break; + default: + asm_error("Invalid test flag: '%c'", *tests); + } + } + } - writew(opcode, ABSOLUTE); // emit code - if (opcode & OP_LONG) - writew(dest.value, dest.relative); + writew(opcode, ABSOLUTE); // emit code + if (opcode & OP_LONG) + writew(dest.value, dest.relative); } // --------------------------------------------------------------------------------- @@ -3575,30 +3575,30 @@ void bsc_op (struct tag_op *op, char *label, char *mods, char *arg) void shf_op (struct tag_op *op, char *label, char *mods, char *arg) { - EXPR expr; - int opcode = basic_opcode(op, mods); + EXPR expr; + int opcode = basic_opcode(op, mods); - if (*label) // define label - set_symbol(label, org, TRUE, relocate); + if (*label) // define label + set_symbol(label, org, TRUE, relocate); - if (opcode & OP_INDEXED) { // shift value comes from index register - expr.value = 0; - expr.relative = ABSOLUTE; - } - else - getexpr(arg, FALSE, &expr); + if (opcode & OP_INDEXED) { // shift value comes from index register + expr.value = 0; + expr.relative = ABSOLUTE; + } + else + getexpr(arg, FALSE, &expr); - if (expr.relative) { - asm_error("Shift value is a relative address"); - expr.relative = ABSOLUTE; - } + if (expr.relative) { + asm_error("Shift value is a relative address"); + expr.relative = ABSOLUTE; + } - if (expr.value < 0 || expr.value > 32) { // check range - asm_error("Shift count of %d is invalid", expr.value); - expr.value = 0; - } + if (expr.value < 0 || expr.value > 32) { // check range + asm_error("Shift count of %d is invalid", expr.value); + expr.value = 0; + } - writew(opcode | (expr.value & 0x3F), FALSE); // put shift count into displacement field + writew(opcode | (expr.value & 0x3F), FALSE); // put shift count into displacement field } // --------------------------------------------------------------------------------- @@ -3607,12 +3607,12 @@ void shf_op (struct tag_op *op, char *label, char *mods, char *arg) void x_mdm (struct tag_op *op, char *label, char *mods, char *arg) { - int opcode = basic_opcode(op, mods); + int opcode = basic_opcode(op, mods); - if (*label) // define label - set_symbol(label, org, TRUE, relocate); - // oh dear: bug here - asm_error("'%s' is not yet supported", op->mnem); + if (*label) // define label + set_symbol(label, org, TRUE, relocate); + // oh dear: bug here + asm_error("'%s' is not yet supported", op->mnem); } // --------------------------------------------------------------------------------- @@ -3622,10 +3622,10 @@ void x_mdm (struct tag_op *op, char *label, char *mods, char *arg) void x_exit (struct tag_op *op, char *label, char *mods, char *arg) { - char nline[120]; + char nline[120]; - format_line(nline, label, "LDX", "X", DOLLAREXIT, ""); - parse_line(nline); + format_line(nline, label, "LDX", "X", DOLLAREXIT, ""); + parse_line(nline); } // --------------------------------------------------------------------------------- @@ -3636,22 +3636,22 @@ void x_exit (struct tag_op *op, char *label, char *mods, char *arg) void x_opt (struct tag_op *op, char *label, char *mods, char *arg) { - char *tok; + char *tok; - org_advanced = FALSE; // * means this address + org_advanced = FALSE; // * means this address - if (*label) { - asm_error("Label not permitted on .OPT statement"); - return; - } - // look for OPT arguments - for (tok = strtok(arg, ","); tok != NULL; tok = strtok(NULL, ",")) { - if (strcmp(tok, "CEXPR") == 0) { - cexpr = TRUE; // use C expression precedence (untested) - } - else - asm_error("Unknown .OPT: '%s'", tok); - } + if (*label) { + asm_error("Label not permitted on .OPT statement"); + return; + } + // look for OPT arguments + for (tok = strtok(arg, ","); tok != NULL; tok = strtok(NULL, ",")) { + if (strcmp(tok, "CEXPR") == 0) { + cexpr = TRUE; // use C expression precedence (untested) + } + else + asm_error("Unknown .OPT: '%s'", tok); + } } // --------------------------------------------------------------------------------- @@ -3660,28 +3660,28 @@ void x_opt (struct tag_op *op, char *label, char *mods, char *arg) void askip (char *target) { - char nline[200], cur_label[20], *c; + char nline[200], cur_label[20], *c; - while (get_line(nline, sizeof(nline), TRUE)) { // read next line (but don't exit a macro) - listout(FALSE); // end listing of previous input line + while (get_line(nline, sizeof(nline), TRUE)) { // read next line (but don't exit a macro) + listout(FALSE); // end listing of previous input line - prep_line(nline); // preform standard line prep + prep_line(nline); // preform standard line prep - strncpy(cur_label, nline, 6); // get first 5 characters - cur_label[5] = '\0'; + strncpy(cur_label, nline, 6); // get first 5 characters + cur_label[5] = '\0'; - for (c = cur_label; *c > ' '; c++) // truncate at first whitespace - ; - *c = '\0'; - // stop if there's a match - if ((target == NULL) ? (cur_label[0] == '\0') : strcmp(target, cur_label) == 0) { - parse_line(nline); // process this line - return; - } - } + for (c = cur_label; *c > ' '; c++) // truncate at first whitespace + ; + *c = '\0'; + // stop if there's a match + if ((target == NULL) ? (cur_label[0] == '\0') : strcmp(target, cur_label) == 0) { + parse_line(nline); // process this line + return; + } + } - if (target != NULL) - asm_error("Label %s not found", target); + if (target != NULL) + asm_error("Label %s not found", target); } // --------------------------------------------------------------------------------- @@ -3690,77 +3690,77 @@ void askip (char *target) void x_aif (struct tag_op *op, char *label, char *mods, char *arg) { - char *target, *tok; - EXPR expr1, expr2; - BOOL istrue; - enum {OP_EQ, OP_LT, OP_GT, OP_NE, OP_LE, OP_GE} cmp_op; + char *target, *tok; + EXPR expr1, expr2; + BOOL istrue; + enum {OP_EQ, OP_LT, OP_GT, OP_NE, OP_LE, OP_GE} cmp_op; - // label is not entered into the symbol table + // label is not entered into the symbol table - arg = skipbl(arg); - if (*arg != '(') { - asm_error("AIF operand must start with ("); - return; - } + arg = skipbl(arg); + if (*arg != '(') { + asm_error("AIF operand must start with ("); + return; + } - arg++; // skip the paren + arg++; // skip the paren - // normally whitespace is never found in the arg string (see tabtok and coltok). - // However, spaces inside parens are permitted. + // normally whitespace is never found in the arg string (see tabtok and coltok). + // However, spaces inside parens are permitted. - if ((tok = strtok(arg, whitespace)) == NULL) { - asm_error("AIF missing first expression"); - return; - } + if ((tok = strtok(arg, whitespace)) == NULL) { + asm_error("AIF missing first expression"); + return; + } - getexpr(tok, FALSE, &expr1); + getexpr(tok, FALSE, &expr1); - if ((tok = strtok(NULL, whitespace)) == NULL) { - asm_error("AIF missing conditional operator"); - return; - } + if ((tok = strtok(NULL, whitespace)) == NULL) { + asm_error("AIF missing conditional operator"); + return; + } - if (strcmp(tok, "EQ") == 0) - cmp_op = OP_EQ; - else if (strcmp(tok, "LT") == 0) - cmp_op = OP_LT; - else if (strcmp(tok, "GT") == 0) - cmp_op = OP_GT; - else if (strcmp(tok, "NE") == 0) - cmp_op = OP_NE; - else if (strcmp(tok, "LE") == 0) - cmp_op = OP_LE; - else if (strcmp(tok, "GE") == 0) - cmp_op = OP_GE; - else { - asm_error("AIF: %s is not a valid conditional operator", tok); - return; - } + if (strcmp(tok, "EQ") == 0) + cmp_op = OP_EQ; + else if (strcmp(tok, "LT") == 0) + cmp_op = OP_LT; + else if (strcmp(tok, "GT") == 0) + cmp_op = OP_GT; + else if (strcmp(tok, "NE") == 0) + cmp_op = OP_NE; + else if (strcmp(tok, "LE") == 0) + cmp_op = OP_LE; + else if (strcmp(tok, "GE") == 0) + cmp_op = OP_GE; + else { + asm_error("AIF: %s is not a valid conditional operator", tok); + return; + } - if ((tok = strtok(NULL, ")")) == NULL) { - asm_error("AIF missing second expression"); - return; - } + if ((tok = strtok(NULL, ")")) == NULL) { + asm_error("AIF missing second expression"); + return; + } - getexpr(tok, FALSE, &expr2); + getexpr(tok, FALSE, &expr2); - switch (cmp_op) { // test the condition - case OP_EQ: istrue = expr1.value == expr2.value; break; - case OP_LT: istrue = expr1.value < expr2.value; break; - case OP_GT: istrue = expr1.value > expr2.value; break; - case OP_NE: istrue = expr1.value != expr2.value; break; - case OP_LE: istrue = expr1.value <= expr2.value; break; - case OP_GE: istrue = expr1.value >= expr2.value; break; - default: bail("in aif, can't happen"); - } + switch (cmp_op) { // test the condition + case OP_EQ: istrue = expr1.value == expr2.value; break; + case OP_LT: istrue = expr1.value < expr2.value; break; + case OP_GT: istrue = expr1.value > expr2.value; break; + case OP_NE: istrue = expr1.value != expr2.value; break; + case OP_LE: istrue = expr1.value <= expr2.value; break; + case OP_GE: istrue = expr1.value >= expr2.value; break; + default: bail("in aif, can't happen"); + } - // After the closing paren coltok and tabtok guarantee we will have no whitespace + // After the closing paren coltok and tabtok guarantee we will have no whitespace - if ((target = strtok(arg, ",")) == NULL) // get target label - asm_warning("Missing target label"); + if ((target = strtok(arg, ",")) == NULL) // get target label + asm_warning("Missing target label"); - if (istrue) - askip(target); // skip to the target + if (istrue) + askip(target); // skip to the target } // --------------------------------------------------------------------------------- @@ -3769,7 +3769,7 @@ void x_aif (struct tag_op *op, char *label, char *mods, char *arg) void x_aifb (struct tag_op *op, char *label, char *mods, char *arg) { - asm_error("aifb valid in macros only and not implemented in any case"); + asm_error("aifb valid in macros only and not implemented in any case"); } // --------------------------------------------------------------------------------- @@ -3778,16 +3778,16 @@ void x_aifb (struct tag_op *op, char *label, char *mods, char *arg) void x_ago (struct tag_op *op, char *label, char *mods, char *arg) { - char *target; + char *target; - // label is not entered into the symbol table + // label is not entered into the symbol table - // handle differently in a macro + // handle differently in a macro - if ((target = strtok(arg, ",")) == NULL) // get target label - asm_warning("Missing target label"); + if ((target = strtok(arg, ",")) == NULL) // get target label + asm_warning("Missing target label"); - askip(target); // skip to the target + askip(target); // skip to the target } // --------------------------------------------------------------------------------- @@ -3795,7 +3795,7 @@ void x_ago (struct tag_op *op, char *label, char *mods, char *arg) void x_agob (struct tag_op *op, char *label, char *mods, char *arg) { - asm_error("agob valid in macros only and not implemented in any case"); + asm_error("agob valid in macros only and not implemented in any case"); } // --------------------------------------------------------------------------------- @@ -3803,8 +3803,8 @@ void x_agob (struct tag_op *op, char *label, char *mods, char *arg) void x_anop (struct tag_op *op, char *label, char *mods, char *arg) { - // label is not entered into the symbol table - // do nothing else + // label is not entered into the symbol table + // do nothing else } // --------------------------------------------------------------------------------- @@ -3816,14 +3816,14 @@ char *exprptr, *oexprptr; #define GETNEXT (*exprptr++) #define UNGET --exprptr -#define LETTER 0 /* character types */ -#define DIGIT 1 -#define ETC 2 -#define ILL 3 -#define SPACE 4 -#define MULOP 5 -#define ADDOP 6 -#define EXPOP 7 +#define LETTER 0 /* character types */ +#define DIGIT 1 +#define ETC 2 +#define ILL 3 +#define SPACE 4 +#define MULOP 5 +#define ADDOP 6 +#define EXPOP 7 int getnb (void); void c_expr (EXPR *ap); @@ -3837,54 +3837,54 @@ int c_esc (int c); void exprerr (int n); void a1130_expr (EXPR *ap); void a1130_term (EXPR *ap); - -char ctype[128] = { // character types -/*^0ABCDEFG */ ILL, ILL, ILL, ILL, ILL, ILL, ILL, ILL, -/*^HIJKLMNO */ ILL, SPACE, SPACE, ILL, SPACE, SPACE, ILL, ILL, -/*^PQRSTUVW */ ILL, ILL, ILL, ILL, ILL, ILL, ILL, ILL, -/*^XYZ */ ILL, ILL, ILL, ILL, ILL, ILL, ILL, ILL, -/* !"#$%&' */ SPACE, ETC, ETC, LETTER, LETTER, MULOP, MULOP, LETTER, /* $ # @ and ' are letters here */ -/* ()*+,-./ */ ETC, ETC, MULOP, ADDOP, ETC, ADDOP, ETC, MULOP, -/* 01234567 */ DIGIT, DIGIT, DIGIT, DIGIT, DIGIT, DIGIT, DIGIT, DIGIT, -/* 89:;<=>? */ DIGIT, DIGIT, ETC, ETC, MULOP, ETC, MULOP, ETC, -/* @ABCDEFG */ LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, -/* HIJKLMNO */ LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, -/* PQRSTUVW */ LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, -/* XYZ[\]^_ */ LETTER, LETTER, LETTER, ETC, ETC, ETC, EXPOP, LETTER, -/* `abcdefg */ ETC, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, -/* hijklmno */ LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, -/* pqrstuvw */ LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, -/* xyz{|}~ */ LETTER, LETTER, LETTER, ETC, ADDOP, ETC, ETC, ETC + +char ctype[128] = { // character types +/*^0ABCDEFG */ ILL, ILL, ILL, ILL, ILL, ILL, ILL, ILL, +/*^HIJKLMNO */ ILL, SPACE, SPACE, ILL, SPACE, SPACE, ILL, ILL, +/*^PQRSTUVW */ ILL, ILL, ILL, ILL, ILL, ILL, ILL, ILL, +/*^XYZ */ ILL, ILL, ILL, ILL, ILL, ILL, ILL, ILL, +/* !"#$%&' */ SPACE, ETC, ETC, LETTER, LETTER, MULOP, MULOP, LETTER, /* $ # @ and ' are letters here */ +/* ()*+,-./ */ ETC, ETC, MULOP, ADDOP, ETC, ADDOP, ETC, MULOP, +/* 01234567 */ DIGIT, DIGIT, DIGIT, DIGIT, DIGIT, DIGIT, DIGIT, DIGIT, +/* 89:;<=>? */ DIGIT, DIGIT, ETC, ETC, MULOP, ETC, MULOP, ETC, +/* @ABCDEFG */ LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, +/* HIJKLMNO */ LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, +/* PQRSTUVW */ LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, +/* XYZ[\]^_ */ LETTER, LETTER, LETTER, ETC, ETC, ETC, EXPOP, LETTER, +/* `abcdefg */ ETC, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, +/* hijklmno */ LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, +/* pqrstuvw */ LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, +/* xyz{|}~ */ LETTER, LETTER, LETTER, ETC, ADDOP, ETC, ETC, ETC }; char *errstr[] = { - "Missing exponent", // 0 - "Undefined symbol", // 1 - "Division by zero", // 2 - "Illegal operator", // 3 - ") expected", // 4 - "Char expected after '", // 5 - "Char expected after .", // 6 - "Number expected after =", // 7 - "Syntax error", // 8 - "Number syntax", // 9 - "Char expected after \\", // 10 - "Relocation error" // 11 + "Missing exponent", // 0 + "Undefined symbol", // 1 + "Division by zero", // 2 + "Illegal operator", // 3 + ") expected", // 4 + "Char expected after '", // 5 + "Char expected after .", // 6 + "Number expected after =", // 7 + "Syntax error", // 8 + "Number syntax", // 9 + "Char expected after \\", // 10 + "Relocation error" // 11 }; int getnb () { - int c; + int c; - if (cexpr) { // in C mode, handle normally - while (ctype[(c = GETNEXT)] == SPACE) - ; - } // in 1130 mode, a space terminates the expression. Here, eat the rest - else if ((c = GETNEXT) == ' ') { - while ((c = GETNEXT) != '\0') - ; - } + if (cexpr) { // in C mode, handle normally + while (ctype[(c = GETNEXT)] == SPACE) + ; + } // in 1130 mode, a space terminates the expression. Here, eat the rest + else if ((c = GETNEXT) == ' ') { + while ((c = GETNEXT) != '\0') + ; + } - return c; + return c; } int symbest, exprerrno; @@ -3896,36 +3896,36 @@ jmp_buf exprjmp; int getexpr (char *pc, BOOL undefined_ok, EXPR *pval) { - symbest = S_DEFINED; // assume no questionable symbols + symbest = S_DEFINED; // assume no questionable symbols - pval->value = 0; - pval->relative = ABSOLUTE; + pval->value = 0; + pval->relative = ABSOLUTE; - if (! *pc) // blank expression is same as zero, ok? - return S_DEFINED; + if (! *pc) // blank expression is same as zero, ok? + return S_DEFINED; - if (setjmp(exprjmp) != 0) { // encountered a syntax error & bailed - pval->value = 0; - pval->relative = ABSOLUTE; - return S_UNDEFINED; - } + if (setjmp(exprjmp) != 0) { // encountered a syntax error & bailed + pval->value = 0; + pval->relative = ABSOLUTE; + return S_UNDEFINED; + } - exprptr = oexprptr = pc; // make global the buffer pointer + exprptr = oexprptr = pc; // make global the buffer pointer - c_expr(pval); + c_expr(pval); - if (GETNEXT) // expression should have been entirely eaten - exprerr(8); // if characters are left, it's an error + if (GETNEXT) // expression should have been entirely eaten + exprerr(8); // if characters are left, it's an error - if (pval->relative < 0 || pval->relative > 1) - exprerr(11); // has to work out to an absolute or a single relative term + if (pval->relative < 0 || pval->relative > 1) + exprerr(11); // has to work out to an absolute or a single relative term - if (symbest == S_DEFINED) // tell how it came out - return S_DEFINED; + if (symbest == S_DEFINED) // tell how it came out + return S_DEFINED; - pval->value = 0; - pval->relative = ABSOLUTE; - return (pass == 1 && undefined_ok) ? S_PROVISIONAL : S_UNDEFINED; + pval->value = 0; + pval->relative = ABSOLUTE; + return (pass == 1 && undefined_ok) ? S_PROVISIONAL : S_UNDEFINED; } // --------------------------------------------------------------------------------- @@ -3935,38 +3935,38 @@ int getexpr (char *pc, BOOL undefined_ok, EXPR *pval) void output_literals (BOOL eof) { - char line[120], label[12], num[20]; - int i; + char line[120], label[12], num[20]; + int i; - for (i = 0; i < n_literals; i++) { // generate DC statements for any pending literal constants - if (literal[i].even && literal[i].hex) // create the value string - sprintf(num, "/%08lx", literal[i].value); - else if (literal[i].even) - sprintf(num, "%ld", literal[i].value); - else if (literal[i].hex) - sprintf(num, "/%04x", literal[i].value & 0xFFFF); - else - sprintf(num, "%d", literal[i].value); + for (i = 0; i < n_literals; i++) { // generate DC statements for any pending literal constants + if (literal[i].even && literal[i].hex) // create the value string + sprintf(num, "/%08lx", literal[i].value); + else if (literal[i].even) + sprintf(num, "%ld", literal[i].value); + else if (literal[i].hex) + sprintf(num, "/%04x", literal[i].value & 0xFFFF); + else + sprintf(num, "%d", literal[i].value); - sprintf(label, "_L%03d", literal[i].tagno); - format_line(line, label, literal[i].even ? "DEC" : "DC", "", num, "GENERATED LITERAL CONSTANT"); + sprintf(label, "_L%03d", literal[i].tagno); + format_line(line, label, literal[i].even ? "DEC" : "DC", "", num, "GENERATED LITERAL CONSTANT"); - if (eof) { - eof = FALSE; // at end of file, for first literal, only prepare blank line - sprintf(listline, LEFT_MARGIN, org); - } - else - listout(TRUE); // push out any pending line(s) + if (eof) { + eof = FALSE; // at end of file, for first literal, only prepare blank line + sprintf(listline, LEFT_MARGIN, org); + } + else + listout(TRUE); // push out any pending line(s) - if (flist && list_on) // this makes stuff appear in the listing - sprintf(listline, LEFT_MARGIN " %s", detab(line)); + if (flist && list_on) // this makes stuff appear in the listing + sprintf(listline, LEFT_MARGIN " %s", detab(line)); - nwout = 0; + nwout = 0; - parse_line(line); // assemble the constant definition - } + parse_line(line); // assemble the constant definition + } - n_literals = 0; // clear list + n_literals = 0; // clear list } // --------------------------------------------------------------------------------- @@ -3975,66 +3975,66 @@ void output_literals (BOOL eof) void a1130_term (EXPR *ap) { - PSYMBOL s; - char token[80], *t; - int c; + PSYMBOL s; + char token[80], *t; + int c; - if (cexpr) { // use C syntax - c_term(ap); - return; - } + if (cexpr) { // use C syntax + c_term(ap); + return; + } c = GETNEXT; - if (ctype[c] == DIGIT) { /* number */ - ap->value = signextend(c_number(c,10,-1)); - ap->relative = ABSOLUTE; - } - else if (c == '+') { /* unary + */ - a1130_term(ap); - } - else if (c == '-') { /* unary - */ - a1130_term(ap); - ap->value = - ap->value; - } - else if (c == '/') { /* / starts a hex constant */ - ap->value = signextend(c_number(c,16,-1)); - ap->relative = ABSOLUTE; - } - else if (c == '*') { /* asterisk alone = org */ - ap->value = org + org_advanced; // here is where that offset matters! - ap->relative = relocate; - } - else if (c == '.') { /* EBCDIC constant */ - c = GETNEXT; - if (c == '\0') { - UNGET; - c = ' '; - } - c = ascii_to_ebcdic_table[c]; - ap->value = c; // VALUE IS IN LOW BYTE!!! - ap->relative = ABSOLUTE; - } - else if (ctype[c] == LETTER) { /* symbol */ - t = token; - do { - *t++ = c; - c = GETNEXT; - } while (ctype[c] == LETTER || ctype[c] == DIGIT); - UNGET; - *t++ = '\0'; + if (ctype[c] == DIGIT) { /* number */ + ap->value = signextend(c_number(c,10,-1)); + ap->relative = ABSOLUTE; + } + else if (c == '+') { /* unary + */ + a1130_term(ap); + } + else if (c == '-') { /* unary - */ + a1130_term(ap); + ap->value = - ap->value; + } + else if (c == '/') { /* / starts a hex constant */ + ap->value = signextend(c_number(c,16,-1)); + ap->relative = ABSOLUTE; + } + else if (c == '*') { /* asterisk alone = org */ + ap->value = org + org_advanced; // here is where that offset matters! + ap->relative = relocate; + } + else if (c == '.') { /* EBCDIC constant */ + c = GETNEXT; + if (c == '\0') { + UNGET; + c = ' '; + } + c = ascii_to_ebcdic_table[c]; + ap->value = c; // VALUE IS IN LOW BYTE!!! + ap->relative = ABSOLUTE; + } + else if (ctype[c] == LETTER) { /* symbol */ + t = token; + do { + *t++ = c; + c = GETNEXT; + } while (ctype[c] == LETTER || ctype[c] == DIGIT); + UNGET; + *t++ = '\0'; - s = lookup_symbol(token, TRUE); - add_xref(s, FALSE); - ap->value = s->value; - ap->relative = s->relative; + s = lookup_symbol(token, TRUE); + add_xref(s, FALSE); + ap->value = s->value; + ap->relative = s->relative; - symbest = MIN(symbest, s->defined); // this goes to lowest value (undefined < provisional < defined) - if (pass == 2 && s->defined != S_DEFINED) - exprerr(1); - } - else - exprerr(8); + symbest = MIN(symbest, s->defined); // this goes to lowest value (undefined < provisional < defined) + if (pass == 2 && s->defined != S_DEFINED) + exprerr(1); + } + else + exprerr(8); } // --------------------------------------------------------------------------------- @@ -4043,12 +4043,12 @@ void a1130_term (EXPR *ap) int signextend (int v) { - v &= 0xFFFF; // clip to 16 bits (this may not be necessary, but best to be safe?) + v &= 0xFFFF; // clip to 16 bits (this may not be necessary, but best to be safe?) - if (v & 0x8000) // if sign bit is set - v |= ~0xFFFF; // sign extend + if (v & 0x8000) // if sign bit is set + v |= ~0xFFFF; // sign extend - return v; + return v; } // --------------------------------------------------------------------------------- @@ -4057,37 +4057,37 @@ int signextend (int v) void c_expr (EXPR *ap) { - int c; - EXPR rop; + int c; + EXPR rop; - c_expr_m(ap); // get combined multiplicative terms - for (;;) { // handle +/- precedence operators - if (ctype[c=getnb()] != ADDOP) { - UNGET; - break; - } - c_expr_m(&rop); // right hand operand - switch (c) { - case '+': - ap->value += rop.value; - ap->relative += rop.relative; - break; + c_expr_m(ap); // get combined multiplicative terms + for (;;) { // handle +/- precedence operators + if (ctype[c=getnb()] != ADDOP) { + UNGET; + break; + } + c_expr_m(&rop); // right hand operand + switch (c) { + case '+': + ap->value += rop.value; + ap->relative += rop.relative; + break; - case '-': - ap->value -= rop.value; - ap->relative -= rop.relative; - break; + case '-': + ap->value -= rop.value; + ap->relative -= rop.relative; + break; - case '|': - if (ap->relative || rop.relative) - exprerr(11); - ap->value = ((long) (ap->value)) | ((long) rop.value); - break; + case '|': + if (ap->relative || rop.relative) + exprerr(11); + ap->value = ((long) (ap->value)) | ((long) rop.value); + break; - default: - printf("In expr, can't happen\n"); - } - } + default: + printf("In expr, can't happen\n"); + } + } } // --------------------------------------------------------------------------------- @@ -4096,73 +4096,73 @@ void c_expr (EXPR *ap) void c_expr_m (EXPR *ap) { - int c; - EXPR rop; + int c; + EXPR rop; - c_expr_e(ap); // get exponential precedence term - for (;;) { // get operator - c = getnb(); - if ((c=='<') || (c=='>')) - if (c != getnb()) // << or >> - exprerr(3); - if (ctype[c] != MULOP) { - UNGET; - break; - } - c_expr_e(&rop); // right hand operand + c_expr_e(ap); // get exponential precedence term + for (;;) { // get operator + c = getnb(); + if ((c=='<') || (c=='>')) + if (c != getnb()) // << or >> + exprerr(3); + if (ctype[c] != MULOP) { + UNGET; + break; + } + c_expr_e(&rop); // right hand operand - switch(c) { - case '*': - if (ap->relative && rop.relative) - exprerr(11); + switch(c) { + case '*': + if (ap->relative && rop.relative) + exprerr(11); - ap->value *= rop.value; - ap->relative = (ap->relative || rop.relative) ? RELATIVE : ABSOLUTE; - break; + ap->value *= rop.value; + ap->relative = (ap->relative || rop.relative) ? RELATIVE : ABSOLUTE; + break; - case '/': - if (rop.value == 0) - exprerr(2); - if (ap->relative || rop.relative) - exprerr(11); + case '/': + if (rop.value == 0) + exprerr(2); + if (ap->relative || rop.relative) + exprerr(11); - ap->value /= rop.value; - break; + ap->value /= rop.value; + break; - case '%': - if (rop.value == 0) - exprerr(2); - if (ap->relative || rop.relative) - exprerr(11); + case '%': + if (rop.value == 0) + exprerr(2); + if (ap->relative || rop.relative) + exprerr(11); - ap->value = ((long) (ap->value)) % ((long) rop.value); - break; + ap->value = ((long) (ap->value)) % ((long) rop.value); + break; - case '&': - if (ap->relative || rop.relative) - exprerr(11); + case '&': + if (ap->relative || rop.relative) + exprerr(11); - ap->value = ((long) (ap->value)) & ((long) rop.value); - break; + ap->value = ((long) (ap->value)) & ((long) rop.value); + break; - case '>': - if (ap->relative || rop.relative) - exprerr(11); + case '>': + if (ap->relative || rop.relative) + exprerr(11); - ap->value = ((long) (ap->value)) >> ((long) rop.value); - break; + ap->value = ((long) (ap->value)) >> ((long) rop.value); + break; - case '<': - if (ap->relative || rop.relative) - exprerr(11); + case '<': + if (ap->relative || rop.relative) + exprerr(11); - ap->value = ((long) (ap->value)) << ((long) rop.value); - break; + ap->value = ((long) (ap->value)) << ((long) rop.value); + break; - default: - printf("In expr_m, can't happen\n"); - } - } + default: + printf("In expr_m, can't happen\n"); + } + } } // --------------------------------------------------------------------------------- @@ -4171,33 +4171,33 @@ void c_expr_m (EXPR *ap) void c_expr_e (EXPR *ap) { - int c, i, v; - EXPR rop; + int c, i, v; + EXPR rop; - c_expr_u(ap); - for (;;) { - c = getnb(); - if (ctype[c] != EXPOP) { - UNGET; - break; - } - c_expr_u(&rop); + c_expr_u(ap); + for (;;) { + c = getnb(); + if (ctype[c] != EXPOP) { + UNGET; + break; + } + c_expr_u(&rop); - switch(c) { - case '^': - if (ap->relative || rop.relative) - exprerr(11); + switch(c) { + case '^': + if (ap->relative || rop.relative) + exprerr(11); - v = ap->value; - ap->value = 1; - for (i = 0; i < rop.value; i++) - ap->value *= v; - break; + v = ap->value; + ap->value = 1; + for (i = 0; i < rop.value; i++) + ap->value *= v; + break; - default: - printf("In expr_e, can't happen\n"); - } - } + default: + printf("In expr_e, can't happen\n"); + } + } } // --------------------------------------------------------------------------------- @@ -4206,24 +4206,24 @@ void c_expr_e (EXPR *ap) void c_expr_u (EXPR *ap) { - int c; + int c; - if ((c = getnb()) == '!') { - a1130_term(ap); - ap->value = ~ ((long)(ap->value)); - if (ap->relative) - exprerr(11); - } - else if (c == '-') { - a1130_term(ap); - ap->value = - ap->value; - if (ap->relative) - exprerr(11); - } - else { - UNGET; - a1130_term(ap); - } + if ((c = getnb()) == '!') { + a1130_term(ap); + ap->value = ~ ((long)(ap->value)); + if (ap->relative) + exprerr(11); + } + else if (c == '-') { + a1130_term(ap); + ap->value = - ap->value; + if (ap->relative) + exprerr(11); + } + else { + UNGET; + a1130_term(ap); + } } // --------------------------------------------------------------------------------- @@ -4232,58 +4232,58 @@ void c_expr_u (EXPR *ap) void c_term (EXPR *ap) { - int c, cc; - PSYMBOL s; - char token[80], *t; + int c, cc; + PSYMBOL s; + char token[80], *t; - ap->relative = ABSOLUTE; /* assume absolute */ + ap->relative = ABSOLUTE; /* assume absolute */ - if ((c = getnb()) == '(') { /* parenthesized expr */ - c_expr(ap); /* start over at the top! */ - if ((cc = getnb()) != ')') - exprerr(4); - } - else if (c == '\'') { /* single quote: char */ - if ((c = GETNEXT) == '\0') - c = ' '; - ap->value = c_esc(c); - } - else if (ctype[c] == DIGIT) { /* number */ - ap->value = signextend(c_number(c,10,-1)); - } - else if (c == '0') { /* 0 starts a hex or octal constant */ - if ((c = GETNEXT) == 'x') { - c = GETNEXT; - ap->value = signextend(c_number(c,16,-1)); - } - else { - ap->value = signextend(c_number(c,8,-1)); - } - } - else if (c == '*') { /* asterisk alone = org */ - ap->value = org + org_advanced; - ap->relative = relocate; - } - else if (ctype[c] == LETTER) { /* symbol */ - t = token; - do { - *t++ = c; - c = GETNEXT; - } while (ctype[c] == LETTER || ctype[c] == DIGIT); - UNGET; - *t++ = '\0'; + if ((c = getnb()) == '(') { /* parenthesized expr */ + c_expr(ap); /* start over at the top! */ + if ((cc = getnb()) != ')') + exprerr(4); + } + else if (c == '\'') { /* single quote: char */ + if ((c = GETNEXT) == '\0') + c = ' '; + ap->value = c_esc(c); + } + else if (ctype[c] == DIGIT) { /* number */ + ap->value = signextend(c_number(c,10,-1)); + } + else if (c == '0') { /* 0 starts a hex or octal constant */ + if ((c = GETNEXT) == 'x') { + c = GETNEXT; + ap->value = signextend(c_number(c,16,-1)); + } + else { + ap->value = signextend(c_number(c,8,-1)); + } + } + else if (c == '*') { /* asterisk alone = org */ + ap->value = org + org_advanced; + ap->relative = relocate; + } + else if (ctype[c] == LETTER) { /* symbol */ + t = token; + do { + *t++ = c; + c = GETNEXT; + } while (ctype[c] == LETTER || ctype[c] == DIGIT); + UNGET; + *t++ = '\0'; - s = lookup_symbol(token, TRUE); - ap->value = s->value; - ap->relative = s->relative; - add_xref(s, FALSE); - symbest = MIN(symbest, s->defined); // this goes to lowest value (undefined < provisional < defined) + s = lookup_symbol(token, TRUE); + ap->value = s->value; + ap->relative = s->relative; + add_xref(s, FALSE); + symbest = MIN(symbest, s->defined); // this goes to lowest value (undefined < provisional < defined) - if (pass == 2 && s->defined != S_DEFINED) - exprerr(1); - } - else - exprerr(8); + if (pass == 2 && s->defined != S_DEFINED) + exprerr(1); + } + else + exprerr(8); } // --------------------------------------------------------------------------------- @@ -4292,43 +4292,43 @@ void c_term (EXPR *ap) int c_number (int c, int r, int nchar) { - int v, n; + int v, n; - nchar--; + nchar--; - if (c == '/' && ! cexpr) { /* special radix stuff */ - r = 16; - c = GETNEXT; - } - else if (r == 10 && c == '0' && cexpr) { /* accept C style 0x## also */ - c = GETNEXT; - if (c == 'x') { - r = 16; - c = GETNEXT; - } - else { - r = 8; - UNGET; - c = '0'; - } - } + if (c == '/' && ! cexpr) { /* special radix stuff */ + r = 16; + c = GETNEXT; + } + else if (r == 10 && c == '0' && cexpr) { /* accept C style 0x## also */ + c = GETNEXT; + if (c == 'x') { + r = 16; + c = GETNEXT; + } + else { + r = 8; + UNGET; + c = '0'; + } + } - n = 0; /* decode number */ - while ((nchar-- != 0) && (v = digit(c, r)) >= 0) { - if (v >= r) /* out of range! */ - exprerr(9); + n = 0; /* decode number */ + while ((nchar-- != 0) && (v = digit(c, r)) >= 0) { + if (v >= r) /* out of range! */ + exprerr(9); - n = r*n + v; + n = r*n + v; - c = GETNEXT; - if (c == '.') { // maybe make it decimal? - c = GETNEXT; - break; - } - } + c = GETNEXT; + if (c == '.') { // maybe make it decimal? + c = GETNEXT; + break; + } + } - UNGET; - return (n); + UNGET; + return (n); } // --------------------------------------------------------------------------------- @@ -4337,15 +4337,15 @@ int c_number (int c, int r, int nchar) int digit (int c, int r) { - if (r == 16) { - if (c >= 'A' && c <= 'F') - return (c - 'A' + 10); - } + if (r == 16) { + if (c >= 'A' && c <= 'F') + return (c - 'A' + 10); + } - if (c >= '0' && c <= '9') - return (c - '0'); + if (c >= '0' && c <= '9') + return (c - '0'); - return (-1); + return (-1); } // --------------------------------------------------------------------------------- @@ -4354,27 +4354,27 @@ int digit (int c, int r) int c_esc (int c) { - if (c != '\\') /* not escaped */ - return(c); + if (c != '\\') /* not escaped */ + return(c); - if ((c = GETNEXT) == '\0') /* must be followed by something */ - exprerr(10); - if ((c >= 'A') && (c <= 'Z')) /* handle upper case */ - c += 'a'-'A'; - if (ctype[c] == LETTER) /* control character abbrevs */ - switch (c) { - case 'b': c = '\b'; break; /* backspace */ - case 'e': c = 27 ; break; /* escape */ - case 'f': c = '\f'; break; /* formfeed */ - case 'n': c = '\n'; break; /* newline */ - case 'r': c = '\r'; break; /* return */ - case 't': c = '\t'; break; /* horiz. tab */ - } - else if (ctype[c] == DIGIT) { /* get character by the numbers */ - c = c_number(c,8,3); /* force octal */ - } + if ((c = GETNEXT) == '\0') /* must be followed by something */ + exprerr(10); + if ((c >= 'A') && (c <= 'Z')) /* handle upper case */ + c += 'a'-'A'; + if (ctype[c] == LETTER) /* control character abbrevs */ + switch (c) { + case 'b': c = '\b'; break; /* backspace */ + case 'e': c = 27 ; break; /* escape */ + case 'f': c = '\f'; break; /* formfeed */ + case 'n': c = '\n'; break; /* newline */ + case 'r': c = '\r'; break; /* return */ + case 't': c = '\t'; break; /* horiz. tab */ + } + else if (ctype[c] == DIGIT) { /* get character by the numbers */ + c = c_number(c,8,3); /* force octal */ + } - return c; + return c; } // --------------------------------------------------------------------------------- @@ -4383,18 +4383,18 @@ int c_esc (int c) void exprerr (int n) { - char msg[256]; - int nex = exprptr-oexprptr; + char msg[256]; + int nex = exprptr-oexprptr; - strncpy(msg, oexprptr, nex); // show where the problem was - msg[nex] = '\0'; - strcat(msg, " << "); - strcat(msg, errstr[n]); + strncpy(msg, oexprptr, nex); // show where the problem was + msg[nex] = '\0'; + strcat(msg, " << "); + strcat(msg, errstr[n]); - asm_error(msg); + asm_error(msg); - exprerrno = n; - longjmp(exprjmp, 1); + exprerrno = n; + longjmp(exprjmp, 1); } /* ------------------------------------------------------------------------ @@ -4403,14 +4403,14 @@ void exprerr (int n) char *upcase (char *str) { - char *s; + char *s; - for (s = str; *s; s++) { - if (*s >= 'a' && *s <= 'z') - *s -= 32; - } + for (s = str; *s; s++) { + if (*s >= 'a' && *s <= 'z') + *s -= 32; + } - return str; + return str; } /* ------------------------------------------------------------------------ @@ -4418,87 +4418,87 @@ char *upcase (char *str) * ------------------------------------------------------------------------ */ typedef struct { - int hollerith; - char ascii; + int hollerith; + char ascii; } CPCODE; static CPCODE cardcode_029[] = { - 0x0000, ' ', - 0x8000, '&', // + in 026 Fortran - 0x4000, '-', - 0x2000, '0', - 0x1000, '1', - 0x0800, '2', - 0x0400, '3', - 0x0200, '4', - 0x0100, '5', - 0x0080, '6', - 0x0040, '7', - 0x0020, '8', - 0x0010, '9', - 0x9000, 'A', - 0x8800, 'B', - 0x8400, 'C', - 0x8200, 'D', - 0x8100, 'E', - 0x8080, 'F', - 0x8040, 'G', - 0x8020, 'H', - 0x8010, 'I', - 0x5000, 'J', - 0x4800, 'K', - 0x4400, 'L', - 0x4200, 'M', - 0x4100, 'N', - 0x4080, 'O', - 0x4040, 'P', - 0x4020, 'Q', - 0x4010, 'R', - 0x3000, '/', - 0x2800, 'S', - 0x2400, 'T', - 0x2200, 'U', - 0x2100, 'V', - 0x2080, 'W', - 0x2040, 'X', - 0x2020, 'Y', - 0x2010, 'Z', - 0x0820, ':', - 0x0420, '#', // = in 026 Fortran - 0x0220, '@', // ' in 026 Fortran - 0x0120, '\'', - 0x00A0, '=', - 0x0060, '"', - 0x8820, 'c', // cent - 0x8420, '.', - 0x8220, '<', // ) in 026 Fortran - 0x8120, '(', - 0x80A0, '+', - 0x8060, '|', - 0x4820, '!', - 0x4420, '$', - 0x4220, '*', - 0x4120, ')', - 0x40A0, ';', - 0x4060, 'n', // not - 0x2820, 'x', // what? - 0x2420, ',', - 0x2220, '%', // ( in 026 Fortran - 0x2120, '_', - 0x20A0, '>', - 0x2060, '>', + 0x0000, ' ', + 0x8000, '&', // + in 026 Fortran + 0x4000, '-', + 0x2000, '0', + 0x1000, '1', + 0x0800, '2', + 0x0400, '3', + 0x0200, '4', + 0x0100, '5', + 0x0080, '6', + 0x0040, '7', + 0x0020, '8', + 0x0010, '9', + 0x9000, 'A', + 0x8800, 'B', + 0x8400, 'C', + 0x8200, 'D', + 0x8100, 'E', + 0x8080, 'F', + 0x8040, 'G', + 0x8020, 'H', + 0x8010, 'I', + 0x5000, 'J', + 0x4800, 'K', + 0x4400, 'L', + 0x4200, 'M', + 0x4100, 'N', + 0x4080, 'O', + 0x4040, 'P', + 0x4020, 'Q', + 0x4010, 'R', + 0x3000, '/', + 0x2800, 'S', + 0x2400, 'T', + 0x2200, 'U', + 0x2100, 'V', + 0x2080, 'W', + 0x2040, 'X', + 0x2020, 'Y', + 0x2010, 'Z', + 0x0820, ':', + 0x0420, '#', // = in 026 Fortran + 0x0220, '@', // ' in 026 Fortran + 0x0120, '\'', + 0x00A0, '=', + 0x0060, '"', + 0x8820, 'c', // cent + 0x8420, '.', + 0x8220, '<', // ) in 026 Fortran + 0x8120, '(', + 0x80A0, '+', + 0x8060, '|', + 0x4820, '!', + 0x4420, '$', + 0x4220, '*', + 0x4120, ')', + 0x40A0, ';', + 0x4060, 'n', // not + 0x2820, 'x', // what? + 0x2420, ',', + 0x2220, '%', // ( in 026 Fortran + 0x2120, '_', + 0x20A0, '>', + 0x2060, '>', }; int ascii_to_hollerith (int ch) { - int i; + int i; - for (i = 0; i < sizeof(cardcode_029) / sizeof(CPCODE); i++) - if (cardcode_029[i].ascii == ch) - return cardcode_029[i].hollerith; + for (i = 0; i < sizeof(cardcode_029) / sizeof(CPCODE); i++) + if (cardcode_029[i].ascii == ch) + return cardcode_029[i].hollerith; - return 0; + return 0; } /* ------------------------------------------------------------------------ @@ -4507,78 +4507,78 @@ int ascii_to_hollerith (int ch) char *detab (char *instr) { - static char outstr[256]; - char *out = outstr; - int col = 0; + static char outstr[256]; + char *out = outstr; + int col = 0; - while (*instr) { - if (*instr == '\t') { - do { - *out++ = ' '; - col++; - } - while (col & 7); - } - else { - *out++ = *instr; - col++; - } + while (*instr) { + if (*instr == '\t') { + do { + *out++ = ' '; + col++; + } + while (col & 7); + } + else { + *out++ = *instr; + col++; + } - instr++; - } - - *out = '\0'; + instr++; + } + + *out = '\0'; - return outstr; + return outstr; } #ifndef _WIN32 int strnicmp (char *a, char *b, int n) { - int ca, cb; + int ca, cb; - for (;;) { - if (--n < 0) // still equal after n characters? quit now - return 0; + for (;;) { + if (--n < 0) // still equal after n characters? quit now + return 0; - if ((ca = *a) == 0) // get character, stop on null terminator - return *b ? -1 : 0; + if ((ca = *a) == 0) // get character, stop on null terminator + return *b ? -1 : 0; - if (ca >= 'a' && ca <= 'z') // fold lowercase to uppercase - ca -= 32; + if (ca >= 'a' && ca <= 'z') // fold lowercase to uppercase + ca -= 32; - cb = *b; - if (cb >= 'a' && cb <= 'z') - cb -= 32; + cb = *b; + if (cb >= 'a' && cb <= 'z') + cb -= 32; - if ((ca -= cb) != 0) // if different, return comparison - return ca; + if ((ca -= cb) != 0) // if different, return comparison + return ca; - a++, b++; - } + a++, b++; + } } int strcmpi (char *a, char *b) { - int ca, cb; + int ca, cb; - for (;;) { - if ((ca = *a) == 0) // get character, stop on null terminator - return *b ? -1 : 0; + for (;;) { + if ((ca = *a) == 0) // get character, stop on null terminator + return *b ? -1 : 0; - if (ca >= 'a' && ca <= 'z') // fold lowercase to uppercase - ca -= 32; + if (ca >= 'a' && ca <= 'z') // fold lowercase to uppercase + ca -= 32; - cb = *b; - if (cb >= 'a' && cb <= 'z') - cb -= 32; + cb = *b; + if (cb >= 'a' && cb <= 'z') + cb -= 32; - if ((ca -= cb) != 0) // if different, return comparison - return ca; + if ((ca -= cb) != 0) // if different, return comparison + return ca; - a++, b++; - } + a++, b++; + } } #endif diff --git a/Ibm1130/utils/bindump.c b/Ibm1130/utils/bindump.c index a5f8ea64..8efa8ccf 100644 --- a/Ibm1130/utils/bindump.c +++ b/Ibm1130/utils/bindump.c @@ -13,10 +13,10 @@ // BINDUMP - dumps card deck files in assembler object format // // Usage: -/// bindump deckfile lists object header info & sector break cards -// bindump -v deckfile lists object data records as well -// bindump -p deckfile for system program, lists phase IDs in the deck -// bindump -s deckfile >outfile for system program, sorts the phases & writes to stdout +/// bindump deckfile lists object header info & sector break cards +// bindump -v deckfile lists object data records as well +// bindump -p deckfile for system program, lists phase IDs in the deck +// bindump -s deckfile >outfile for system program, sorts the phases & writes to stdout #include #include @@ -68,486 +68,486 @@ void verify_checksum(unsigned short *buf); int main (int argc, char **argv) { - char *arg; - static char usestr[] = "Usage: bindump [-psv] filename..."; - int i; + char *arg; + static char usestr[] = "Usage: bindump [-psv] filename..."; + int i; - for (i = 1; i < argc; i++) { - arg = argv[i]; - if (*arg == '-') { - arg++; - while (*arg) { - switch (*arg++) { - case 'v': - verbose = TRUE; - break; - case 'p': - phid = TRUE; // print only phase ID's - break; - case 's': - sort = TRUE; // sort deck by phases, writing to stdout - break; - default: - bail(usestr); - } - } - } - } + for (i = 1; i < argc; i++) { + arg = argv[i]; + if (*arg == '-') { + arg++; + while (*arg) { + switch (*arg++) { + case 'v': + verbose = TRUE; + break; + case 'p': + phid = TRUE; // print only phase ID's + break; + case 's': + sort = TRUE; // sort deck by phases, writing to stdout + break; + default: + bail(usestr); + } + } + } + } - for (i = 1; i < argc; i++) { - arg = argv[i]; - if (*arg != '-') - process(arg); - } - return 0; + for (i = 1; i < argc; i++) { + arg = argv[i]; + if (*arg != '-') + process(arg); + } + return 0; } void process (char *nm) { #ifdef _WIN32 - WIN32_FIND_DATA fd; - HANDLE hFind; - char *c, buf[256]; + WIN32_FIND_DATA fd; + HANDLE hFind; + char *c, buf[256]; - if (strchr(nm, '*') == NULL && strchr(nm, '?') == NULL) - dump(nm); + if (strchr(nm, '*') == NULL && strchr(nm, '?') == NULL) + dump(nm); - else if ((hFind = FindFirstFile(nm, &fd)) == INVALID_HANDLE_VALUE) - fprintf(stderr, "No files matching '%s'\n", nm); + else if ((hFind = FindFirstFile(nm, &fd)) == INVALID_HANDLE_VALUE) + fprintf(stderr, "No files matching '%s'\n", nm); - else { - if ((c = strrchr(nm, '\\')) == NULL) - c = strrchr(nm, ':'); + else { + if ((c = strrchr(nm, '\\')) == NULL) + c = strrchr(nm, ':'); - do { - if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) - continue; + do { + if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) + continue; - if (c == NULL) - dump(fd.cFileName); - else { - strcpy(buf, nm); - strcpy(buf + (c-nm+1), fd.cFileName); - dump(buf); - } - - } while (FindNextFile(hFind, &fd)); + if (c == NULL) + dump(fd.cFileName); + else { + strcpy(buf, nm); + strcpy(buf + (c-nm+1), fd.cFileName); + dump(buf); + } + + } while (FindNextFile(hFind, &fd)); - FindClose(hFind); - } + FindClose(hFind); + } #else - dump(nm); // on unices, sh globs for us + dump(nm); // on unices, sh globs for us #endif } void dump (char *fname) { - if (sort) - sort_phases(fname); - else if (phid) - dump_phids(fname); - else - dump_data(fname); + if (sort) + sort_phases(fname); + else if (phid) + dump_phids(fname); + else + dump_data(fname); } struct tag_card { - int phid, seq; - unsigned short card[80]; + int phid, seq; + unsigned short card[80]; }; int cardcomp (const void *a, const void *b) { - short diff; + short diff; - diff = ((struct tag_card *) a)->phid - ((struct tag_card *) b)->phid; + diff = ((struct tag_card *) a)->phid - ((struct tag_card *) b)->phid; - return diff ? diff : (((struct tag_card *) a)->seq - ((struct tag_card *) b)->seq); + return diff ? diff : (((struct tag_card *) a)->seq - ((struct tag_card *) b)->seq); } void sort_phases (char *fname) { - int i, ncards, cardtype, len, seq = 0, phid; - struct tag_card *deck; - FILE *fd; - BOOL saw_sbrk = TRUE; + int i, ncards, cardtype, len, seq = 0, phid; + struct tag_card *deck; + FILE *fd; + BOOL saw_sbrk = TRUE; - if ((fd = fopen(fname, "rb")) == NULL) { - perror(fname); - return; - } + if ((fd = fopen(fname, "rb")) == NULL) { + perror(fname); + return; + } - fseek(fd, 0, SEEK_END); - len = ftell(fd); // get length of file - fseek(fd, 0, SEEK_SET); + fseek(fd, 0, SEEK_END); + len = ftell(fd); // get length of file + fseek(fd, 0, SEEK_SET); - if (len <= 0 || (len % 160) != 0) { - fprintf(stderr, "%s is not a binard deck image\n"); - fclose(fd); - return; - } + if (len <= 0 || (len % 160) != 0) { + fprintf(stderr, "%s is not a binard deck image\n"); + fclose(fd); + return; + } - ncards = len / 160; + ncards = len / 160; - if ((deck = (struct tag_card *) malloc(ncards*sizeof(struct tag_card))) == NULL) { - fprintf(stderr, "%s: can't sort, insufficient memory\n"); - fclose(fd); - return; - } + if ((deck = (struct tag_card *) malloc(ncards*sizeof(struct tag_card))) == NULL) { + fprintf(stderr, "%s: can't sort, insufficient memory\n"); + fclose(fd); + return; + } - phid = 0; - for (i = 0; i < ncards; i++) { - if (fxread(deck[i].card, sizeof(card[0]), 80, fd) != 80) { - free(deck); - fprintf(stderr, "%s: error reading deck\n"); - fclose(fd); - return; - } + phid = 0; + for (i = 0; i < ncards; i++) { + if (fxread(deck[i].card, sizeof(card[0]), 80, fd) != 80) { + free(deck); + fprintf(stderr, "%s: error reading deck\n"); + fclose(fd); + return; + } - unpack(deck[i].card, buf); - deck[i].seq = seq++; - deck[i].phid = phid; + unpack(deck[i].card, buf); + deck[i].seq = seq++; + deck[i].phid = phid; - verify_checksum(buf); + verify_checksum(buf); - cardtype = (buf[2] >> 8) & 0xFF; + cardtype = (buf[2] >> 8) & 0xFF; - if (cardtype == 1 || cardtype == 2) { // start of deck is same as sector break - saw_sbrk = TRUE; - } - else if (cardtype == 0) { - fprintf(stderr, "%s is a core image deck\n"); - free(deck); - fclose(fd); - return; - } - else if (cardtype == 0x0A && saw_sbrk) { - phid = (int) (signed short) buf[10]; - if (phid < 0) - phid = -phid; + if (cardtype == 1 || cardtype == 2) { // start of deck is same as sector break + saw_sbrk = TRUE; + } + else if (cardtype == 0) { + fprintf(stderr, "%s is a core image deck\n"); + free(deck); + fclose(fd); + return; + } + else if (cardtype == 0x0A && saw_sbrk) { + phid = (int) (signed short) buf[10]; + if (phid < 0) + phid = -phid; - deck[i].phid = phid; // this belongs to the new phase - deck[i-1].phid = phid; // as does previous card - saw_sbrk = FALSE; - } - } - fclose(fd); + deck[i].phid = phid; // this belongs to the new phase + deck[i-1].phid = phid; // as does previous card + saw_sbrk = FALSE; + } + } + fclose(fd); - qsort(deck, ncards, sizeof(struct tag_card), cardcomp); // sort the deck + qsort(deck, ncards, sizeof(struct tag_card), cardcomp); // sort the deck #ifdef _WIN32 - _setmode(_fileno(stdout), _O_BINARY); // set standard output to binary mode + _setmode(_fileno(stdout), _O_BINARY); // set standard output to binary mode #endif - for (i = 0; i < ncards; i++) // write to stdout - fxwrite(deck[i].card, sizeof(card[0]), 80, stdout); + for (i = 0; i < ncards; i++) // write to stdout + fxwrite(deck[i].card, sizeof(card[0]), 80, stdout); - free(deck); + free(deck); } void dump_phids (char *fname) { - FILE *fp; - BOOL first = TRUE; - BOOL saw_sbrk = TRUE, neg; - short id; + FILE *fp; + BOOL first = TRUE; + BOOL saw_sbrk = TRUE, neg; + short id; - if ((fp = fopen(fname, "rb")) == NULL) { - perror(fname); - return; - } - - printf("\n%s:\n", fname); + if ((fp = fopen(fname, "rb")) == NULL) { + perror(fname); + return; + } + + printf("\n%s:\n", fname); - while (fxread(card, sizeof(card[0]), 80, fp) > 0) { - unpack(card, buf); - verify_checksum(buf); + while (fxread(card, sizeof(card[0]), 80, fp) > 0) { + unpack(card, buf); + verify_checksum(buf); - cardtype = (buf[2] >> 8) & 0xFF; + cardtype = (buf[2] >> 8) & 0xFF; - if (cardtype == 1 && ! first) { // sector break - saw_sbrk = TRUE; - continue; - } - else { - switch (cardtype) { - case 0x00: - printf(" This is a core image deck\n"); - goto done; - break; - case 0x01: - case 0x02: - case 0x03: - case 0x04: - case 0x05: - case 0x06: - case 0x07: - case 0x0F: - break; + if (cardtype == 1 && ! first) { // sector break + saw_sbrk = TRUE; + continue; + } + else { + switch (cardtype) { + case 0x00: + printf(" This is a core image deck\n"); + goto done; + break; + case 0x01: + case 0x02: + case 0x03: + case 0x04: + case 0x05: + case 0x06: + case 0x07: + case 0x0F: + break; - case 0x0A: - if (saw_sbrk) { - id = buf[10]; - if (id < 0) - id = -id, neg = TRUE; - else - neg = FALSE; - printf(" : %3d / %02x%s\n", id, id, neg ? " (neg)" : ""); - saw_sbrk = FALSE; - } - break; + case 0x0A: + if (saw_sbrk) { + id = buf[10]; + if (id < 0) + id = -id, neg = TRUE; + else + neg = FALSE; + printf(" : %3d / %02x%s\n", id, id, neg ? " (neg)" : ""); + saw_sbrk = FALSE; + } + break; - default: - show_raw("??? "); - } - } + default: + show_raw("??? "); + } + } done: - first = FALSE; - } + first = FALSE; + } - fclose(fp); + fclose(fp); } void dump_data (char *fname) { - FILE *fp; - BOOL first = TRUE; - char str[80]; - int i; + FILE *fp; + BOOL first = TRUE; + char str[80]; + int i; - if ((fp = fopen(fname, "rb")) == NULL) { - perror(fname); - return; - } - - printf("\n%s:\n", fname); + if ((fp = fopen(fname, "rb")) == NULL) { + perror(fname); + return; + } + + printf("\n%s:\n", fname); - while (fxread(card, sizeof(card[0]), 80, fp) > 0) { - unpack(card, buf); - verify_checksum(buf); + while (fxread(card, sizeof(card[0]), 80, fp) > 0) { + unpack(card, buf); + verify_checksum(buf); - cardtype = (buf[2] >> 8) & 0xFF; + cardtype = (buf[2] >> 8) & 0xFF; - if (cardtype == 1 && ! first) { // sector break - for (i = 4; i < 72; i++) - str[i] = hollerith_to_ascii(card[i]); + if (cardtype == 1 && ! first) { // sector break + for (i = 4; i < 72; i++) + str[i] = hollerith_to_ascii(card[i]); - str[i] = '\0'; - trim(str+4); - printf("*SBRK %s\n", str+4); - continue; - } - else { - switch (cardtype) { - case 0x00: - if (first) - show_raw("CORE"); - if (verbose) - show_core(); - break; + str[i] = '\0'; + trim(str+4); + printf("*SBRK %s\n", str+4); + continue; + } + else { + switch (cardtype) { + case 0x00: + if (first) + show_raw("CORE"); + if (verbose) + show_core(); + break; - case 0x01: - show_raw("ABS "); - show_main(); - break; - case 0x02: - show_raw("REL "); - show_main(); - break; - case 0x03: - show_raw("LIB "); - show_sub(); - break; - case 0x04: - show_raw("SUB "); - show_sub(); - break; - case 0x05: - show_raw("ISSL"); - show_iss(); - break; - case 0x06: - show_raw("ISSC"); - show_iss(); - break; - case 0x07: - show_raw("ILS "); - show_ils(); - break; - case 0x0F: - show_raw("END "); - show_end(); - break; - case 0x80: - show_raw("ENDC"); - show_endc(); - break; - case 0x81: - show_raw("81 "); - show_81(); - break; - case 0x0A: - if (verbose) - show_data(); - break; - default: - show_raw("??? "); - } - } + case 0x01: + show_raw("ABS "); + show_main(); + break; + case 0x02: + show_raw("REL "); + show_main(); + break; + case 0x03: + show_raw("LIB "); + show_sub(); + break; + case 0x04: + show_raw("SUB "); + show_sub(); + break; + case 0x05: + show_raw("ISSL"); + show_iss(); + break; + case 0x06: + show_raw("ISSC"); + show_iss(); + break; + case 0x07: + show_raw("ILS "); + show_ils(); + break; + case 0x0F: + show_raw("END "); + show_end(); + break; + case 0x80: + show_raw("ENDC"); + show_endc(); + break; + case 0x81: + show_raw("81 "); + show_81(); + break; + case 0x0A: + if (verbose) + show_data(); + break; + default: + show_raw("??? "); + } + } - first = FALSE; - } + first = FALSE; + } - fclose(fp); + fclose(fp); } void show_data (void) { - int i, n, jrel, rflag, nout, ch, reloc; - BOOL first = TRUE; + int i, n, jrel, rflag, nout, ch, reloc; + BOOL first = TRUE; - n = buf[2] & 0x00FF; + n = buf[2] & 0x00FF; - printf("%04x: ", buf[0]); + printf("%04x: ", buf[0]); - jrel = 3; - nout = 0; - rflag = buf[jrel++]; - for (i = 0; i < n; i++) { - if (nout >= 8) { - rflag = buf[jrel++]; - if (first) { - printf(" %s", getseq()); - first = FALSE; - } - printf("\n "); - nout = 0; - } - reloc = (rflag >> 14) & 0x03; - ch = (reloc == R_ABSOLUTE) ? ' ' : - (reloc == R_RELATIVE) ? 'R' : - (reloc == R_LIBF) ? 'L' : '@'; + jrel = 3; + nout = 0; + rflag = buf[jrel++]; + for (i = 0; i < n; i++) { + if (nout >= 8) { + rflag = buf[jrel++]; + if (first) { + printf(" %s", getseq()); + first = FALSE; + } + printf("\n "); + nout = 0; + } + reloc = (rflag >> 14) & 0x03; + ch = (reloc == R_ABSOLUTE) ? ' ' : + (reloc == R_RELATIVE) ? 'R' : + (reloc == R_LIBF) ? 'L' : '@'; - printf("%04x%c ", buf[9+i], ch); - rflag <<= 2; - nout++; - } - putchar('\n'); + printf("%04x%c ", buf[9+i], ch); + rflag <<= 2; + nout++; + } + putchar('\n'); } void show_core (void) { - int i, n, nout; - BOOL first = TRUE; + int i, n, nout; + BOOL first = TRUE; - n = buf[2] & 0x00FF; + n = buf[2] & 0x00FF; - printf("%04x: ", buf[0]); + printf("%04x: ", buf[0]); - nout = 0; - for (i = 0; i < n; i++) { - if (nout >= 8) { - if (first) { - printf(" %s", getseq()); - first = FALSE; - } - printf("\n "); - nout = 0; - } - printf("%04x ", buf[9+i]); - nout++; - } - putchar('\n'); + nout = 0; + for (i = 0; i < n; i++) { + if (nout >= 8) { + if (first) { + printf(" %s", getseq()); + first = FALSE; + } + printf("\n "); + nout = 0; + } + printf("%04x ", buf[9+i]); + nout++; + } + putchar('\n'); } void info (int i, char *nm, char type) { - if (nm) - printf("%s ", nm); + if (nm) + printf("%s ", nm); - switch (type) { - case 'd': - printf("%d ", buf[i]); - break; + switch (type) { + case 'd': + printf("%d ", buf[i]); + break; - case 'x': - printf("%04x ", buf[i]); - break; + case 'x': + printf("%04x ", buf[i]); + break; - case 'b': - printf("%02x ", buf[i] & 0xFF); - break; + case 'b': + printf("%02x ", buf[i] & 0xFF); + break; - case 'n': - printf("%s ", getname(buf+i)); - break; + case 'n': + printf("%s ", getname(buf+i)); + break; - default: - bail("BAD TYPE"); - } + default: + bail("BAD TYPE"); + } } void show_main (void) { - printf(" "); - info(2, "prec", 'b'); - info(4, "common", 'd'); - info(6, "work", 'd'); - info(8, "files", 'd'); - info(9, "name", 'n'); - info(11, "pta", 'x'); - putchar('\n'); + printf(" "); + info(2, "prec", 'b'); + info(4, "common", 'd'); + info(6, "work", 'd'); + info(8, "files", 'd'); + info(9, "name", 'n'); + info(11, "pta", 'x'); + putchar('\n'); } void show_sub (void) { - int i, n; + int i, n; - printf(" "); - info( 2, "prec", 'b'); + printf(" "); + info( 2, "prec", 'b'); - n = buf[5] / 3; - for (i = 0; i < n; i++) { - info( 9+3*i, "ent", 'n'); - info(11+3*i, NULL, 'x'); - } + n = buf[5] / 3; + for (i = 0; i < n; i++) { + info( 9+3*i, "ent", 'n'); + info(11+3*i, NULL, 'x'); + } - putchar('\n'); + putchar('\n'); } void show_iss (void) { - printf(" "); - info(12, "level", 'd'); - putchar('\n'); + printf(" "); + info(12, "level", 'd'); + putchar('\n'); } void show_ils (void) { - printf(" "); - info( 2, "prec", 'b'); - info( 5, "nint6", 'd'); - info( 9, "ent", 'n'); - info(11, NULL, 'x'); - info(14, "nint", 'd'); - info(15, "il1", 'd'); - info(16, "il2", 'd'); - putchar('\n'); + printf(" "); + info( 2, "prec", 'b'); + info( 5, "nint6", 'd'); + info( 9, "ent", 'n'); + info(11, NULL, 'x'); + info(14, "nint", 'd'); + info(15, "il1", 'd'); + info(16, "il2", 'd'); + putchar('\n'); } void show_end (void) { - printf(" "); - info(0, "size", 'd'); - info(3, "pta", 'x'); - putchar('\n'); + printf(" "); + info(0, "size", 'd'); + info(3, "pta", 'x'); + putchar('\n'); } void show_endc(void) { - printf(" "); - info(52, "IX3", 'x'); - info(53, "pta", 'x'); - putchar('\n'); + printf(" "); + info(52, "IX3", 'x'); + info(53, "pta", 'x'); + putchar('\n'); } void show_81(void) @@ -556,146 +556,146 @@ void show_81(void) void show_raw (char *name) { - int i; - printf("*%s", name); + int i; + printf("*%s", name); - for (i = 0; i < 12; i++) - printf(" %04x", buf[i]); + for (i = 0; i < 12; i++) + printf(" %04x", buf[i]); - printf(" %s\n", getseq()); + printf(" %s\n", getseq()); } char * getseq (void) { - static char seq[10]; - int i; + static char seq[10]; + int i; - for (i = 0; i < 8; i++) - seq[i] = hollerith_to_ascii(card[72+i]); + for (i = 0; i < 8; i++) + seq[i] = hollerith_to_ascii(card[72+i]); seq[i] = '\0'; - return seq; + return seq; } void bail (char *msg) { - fprintf(stderr, "%s\n", msg); - exit(1); + fprintf(stderr, "%s\n", msg); + exit(1); } void unpack (unsigned short *icard, unsigned short *obuf) { - int i, j; - unsigned short wd1, wd2, wd3, wd4; + int i, j; + unsigned short wd1, wd2, wd3, wd4; - for (i = j = 0; i < 54; i += 3, j += 4) { - wd1 = icard[j]; - wd2 = icard[j+1]; - wd3 = icard[j+2]; - wd4 = icard[j+3]; + for (i = j = 0; i < 54; i += 3, j += 4) { + wd1 = icard[j]; + wd2 = icard[j+1]; + wd3 = icard[j+2]; + wd4 = icard[j+3]; - obuf[i ] = (wd1 & 0xFFF0) | ((wd2 >> 12) & 0x000F); - obuf[i+1] = ((wd2 << 4) & 0xFF00) | ((wd3 >> 8) & 0x00FF); - obuf[i+2] = ((wd3 << 8) & 0xF000) | ((wd4 >> 4) & 0x0FFF); - } + obuf[i ] = (wd1 & 0xFFF0) | ((wd2 >> 12) & 0x000F); + obuf[i+1] = ((wd2 << 4) & 0xFF00) | ((wd3 >> 8) & 0x00FF); + obuf[i+2] = ((wd3 << 8) & 0xF000) | ((wd4 >> 4) & 0x0FFF); + } } void verify_checksum (unsigned short *obuf) { -// unsigned short sum; +// unsigned short sum; - if (obuf[1] == 0) // no checksum - return; + if (obuf[1] == 0) // no checksum + return; -// if (sum != card[1]) -// printf("Checksum %04x doesn't match card %04x\n", sum, card[1]); +// if (sum != card[1]) +// printf("Checksum %04x doesn't match card %04x\n", sum, card[1]); } typedef struct { - unsigned short hollerith; - char ascii; + unsigned short hollerith; + char ascii; } CPCODE; static CPCODE cardcode_029[] = { - 0x0000, ' ', - 0x8000, '&', // + in 026 Fortran - 0x4000, '-', - 0x2000, '0', - 0x1000, '1', - 0x0800, '2', - 0x0400, '3', - 0x0200, '4', - 0x0100, '5', - 0x0080, '6', - 0x0040, '7', - 0x0020, '8', - 0x0010, '9', - 0x9000, 'A', - 0x8800, 'B', - 0x8400, 'C', - 0x8200, 'D', - 0x8100, 'E', - 0x8080, 'F', - 0x8040, 'G', - 0x8020, 'H', - 0x8010, 'I', - 0x5000, 'J', - 0x4800, 'K', - 0x4400, 'L', - 0x4200, 'M', - 0x4100, 'N', - 0x4080, 'O', - 0x4040, 'P', - 0x4020, 'Q', - 0x4010, 'R', - 0x3000, '/', - 0x2800, 'S', - 0x2400, 'T', - 0x2200, 'U', - 0x2100, 'V', - 0x2080, 'W', - 0x2040, 'X', - 0x2020, 'Y', - 0x2010, 'Z', - 0x0820, ':', - 0x0420, '#', // = in 026 Fortran - 0x0220, '@', // ' in 026 Fortran - 0x0120, '\'', - 0x00A0, '=', - 0x0060, '"', - 0x8820, 'c', // cent - 0x8420, '.', - 0x8220, '<', // ) in 026 Fortran - 0x8120, '(', - 0x80A0, '+', - 0x8060, '|', - 0x4820, '!', - 0x4420, '$', - 0x4220, '*', - 0x4120, ')', - 0x40A0, ';', - 0x4060, 'n', // not - 0x2820, 'x', // what? - 0x2420, ',', - 0x2220, '%', // ( in 026 Fortran - 0x2120, '_', - 0x20A0, '>', - 0x2060, '>', + 0x0000, ' ', + 0x8000, '&', // + in 026 Fortran + 0x4000, '-', + 0x2000, '0', + 0x1000, '1', + 0x0800, '2', + 0x0400, '3', + 0x0200, '4', + 0x0100, '5', + 0x0080, '6', + 0x0040, '7', + 0x0020, '8', + 0x0010, '9', + 0x9000, 'A', + 0x8800, 'B', + 0x8400, 'C', + 0x8200, 'D', + 0x8100, 'E', + 0x8080, 'F', + 0x8040, 'G', + 0x8020, 'H', + 0x8010, 'I', + 0x5000, 'J', + 0x4800, 'K', + 0x4400, 'L', + 0x4200, 'M', + 0x4100, 'N', + 0x4080, 'O', + 0x4040, 'P', + 0x4020, 'Q', + 0x4010, 'R', + 0x3000, '/', + 0x2800, 'S', + 0x2400, 'T', + 0x2200, 'U', + 0x2100, 'V', + 0x2080, 'W', + 0x2040, 'X', + 0x2020, 'Y', + 0x2010, 'Z', + 0x0820, ':', + 0x0420, '#', // = in 026 Fortran + 0x0220, '@', // ' in 026 Fortran + 0x0120, '\'', + 0x00A0, '=', + 0x0060, '"', + 0x8820, 'c', // cent + 0x8420, '.', + 0x8220, '<', // ) in 026 Fortran + 0x8120, '(', + 0x80A0, '+', + 0x8060, '|', + 0x4820, '!', + 0x4420, '$', + 0x4220, '*', + 0x4120, ')', + 0x40A0, ';', + 0x4060, 'n', // not + 0x2820, 'x', // what? + 0x2420, ',', + 0x2220, '%', // ( in 026 Fortran + 0x2120, '_', + 0x20A0, '>', + 0x2060, '>', }; int hollerith_to_ascii (unsigned short h) { - int i; + int i; - h &= 0xFFF0; + h &= 0xFFF0; - for (i = 0; i < sizeof(cardcode_029) / sizeof(CPCODE); i++) - if (cardcode_029[i].hollerith == h) - return cardcode_029[i].ascii; + for (i = 0; i < sizeof(cardcode_029) / sizeof(CPCODE); i++) + if (cardcode_029[i].hollerith == h) + return cardcode_029[i].ascii; - return '?'; + return '?'; } // --------------------------------------------------------------------------------- @@ -704,52 +704,52 @@ int hollerith_to_ascii (unsigned short h) void trim (char *s) { - char *nb; + char *nb; - for (nb = s-1; *s; s++) - if (*s > ' ') - nb = s; + for (nb = s-1; *s; s++) + if (*s > ' ') + nb = s; - nb[1] = '\0'; + nb[1] = '\0'; } int ascii_to_ebcdic_table[128] = { - 0x00,0x01,0x02,0x03,0x37,0x2d,0x2e,0x2f, 0x16,0x05,0x25,0x0b,0x0c,0x0d,0x0e,0x0f, - 0x10,0x11,0x12,0x13,0x3c,0x3d,0x32,0x26, 0x18,0x19,0x3f,0x27,0x1c,0x1d,0x1e,0x1f, - 0x40,0x5a,0x7f,0x7b,0x5b,0x6c,0x50,0x7d, 0x4d,0x5d,0x5c,0x4e,0x6b,0x60,0x4b,0x61, - 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7, 0xf8,0xf9,0x7a,0x5e,0x4c,0x7e,0x6e,0x6f, + 0x00,0x01,0x02,0x03,0x37,0x2d,0x2e,0x2f, 0x16,0x05,0x25,0x0b,0x0c,0x0d,0x0e,0x0f, + 0x10,0x11,0x12,0x13,0x3c,0x3d,0x32,0x26, 0x18,0x19,0x3f,0x27,0x1c,0x1d,0x1e,0x1f, + 0x40,0x5a,0x7f,0x7b,0x5b,0x6c,0x50,0x7d, 0x4d,0x5d,0x5c,0x4e,0x6b,0x60,0x4b,0x61, + 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7, 0xf8,0xf9,0x7a,0x5e,0x4c,0x7e,0x6e,0x6f, - 0x7c,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7, 0xc8,0xc9,0xd1,0xd2,0xd3,0xd4,0xd5,0xd6, - 0xd7,0xd8,0xd9,0xe2,0xe3,0xe4,0xe5,0xe6, 0xe7,0xe8,0xe9,0xba,0xe0,0xbb,0xb0,0x6d, - 0x79,0x81,0x82,0x83,0x84,0x85,0x86,0x87, 0x88,0x89,0x91,0x92,0x93,0x94,0x95,0x96, - 0x97,0x98,0x99,0xa2,0xa3,0xa4,0xa5,0xa6, 0xa7,0xa8,0xa9,0xc0,0x4f,0xd0,0xa1,0x07, + 0x7c,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7, 0xc8,0xc9,0xd1,0xd2,0xd3,0xd4,0xd5,0xd6, + 0xd7,0xd8,0xd9,0xe2,0xe3,0xe4,0xe5,0xe6, 0xe7,0xe8,0xe9,0xba,0xe0,0xbb,0xb0,0x6d, + 0x79,0x81,0x82,0x83,0x84,0x85,0x86,0x87, 0x88,0x89,0x91,0x92,0x93,0x94,0x95,0x96, + 0x97,0x98,0x99,0xa2,0xa3,0xa4,0xa5,0xa6, 0xa7,0xa8,0xa9,0xc0,0x4f,0xd0,0xa1,0x07, }; char *getname (unsigned short *ptr) { - static char str[6]; - int i, j, ch; - long v; + static char str[6]; + int i, j, ch; + long v; - v = (ptr[0] << 16L) | ptr[1]; + v = (ptr[0] << 16L) | ptr[1]; - for (i = 0; i < 5; i++) { - ch = ((v >> 24) & 0x3F) | 0xC0; // recover those lost two bits - v <<= 6; + for (i = 0; i < 5; i++) { + ch = ((v >> 24) & 0x3F) | 0xC0; // recover those lost two bits + v <<= 6; - str[i] = ' '; + str[i] = ' '; - for (j = 0; j < (sizeof(ascii_to_ebcdic_table)/sizeof(ascii_to_ebcdic_table[0])); j++) { - if (ascii_to_ebcdic_table[j] == ch) { - str[i] = j; - break; - } - } - } + for (j = 0; j < (sizeof(ascii_to_ebcdic_table)/sizeof(ascii_to_ebcdic_table[0])); j++) { + if (ascii_to_ebcdic_table[j] == ch) { + str[i] = j; + break; + } + } + } - str[5] = '\0'; - return str; + str[5] = '\0'; + return str; } diff --git a/Ibm1130/utils/checkdisk.c b/Ibm1130/utils/checkdisk.c index bf775d00..e41c405b 100644 --- a/Ibm1130/utils/checkdisk.c +++ b/Ibm1130/utils/checkdisk.c @@ -12,23 +12,23 @@ // checkdisk - validates and optionally dumps an IBM1130 DMS2 disk image file // // Usage: -// checkdisk [-f] [-d cyl.sec|abssec] [-n count] filename +// checkdisk [-f] [-d cyl.sec|abssec] [-n count] filename // // Examples: -// checkdisk file.dsk -// report any misnumbered sectors in file.dsk +// checkdisk file.dsk +// report any misnumbered sectors in file.dsk // -// checkdisk -f file.dsk -// report and fix any misnumbered sectors +// checkdisk -f file.dsk +// report and fix any misnumbered sectors // -// checkdisk -d 198.0 file.dsk -// dump cylinder 198 sector 0 +// checkdisk -d 198.0 file.dsk +// dump cylinder 198 sector 0 // -// checkdisk -d 0 file.dsk -// dump absolute sector 0 +// checkdisk -d 0 file.dsk +// dump absolute sector 0 // -// checkdisk -d 198.0 -n 4 file.dsk -// dump 4 sectors starting at m.n +// checkdisk -d 198.0 -n 4 file.dsk +// dump 4 sectors starting at m.n // ----------------------------------------------------------------------------------------- #include #include @@ -38,7 +38,7 @@ #ifdef _WIN32 # include #else - long filelength (int fno); + long filelength (int fno); # include # include #endif @@ -49,11 +49,11 @@ # define FALSE 0 #endif -#define DSK_NUMWD 321 /* words/sector */ -#define DSK_NUMSC 4 /* sectors/surface */ -#define DSK_NUMSF 2 /* surfaces/cylinder */ -#define DSK_NUMCY 203 /* cylinders/drive */ -#define DSK_NUMDR 5 /* drives/controller */ +#define DSK_NUMWD 321 /* words/sector */ +#define DSK_NUMSC 4 /* sectors/surface */ +#define DSK_NUMSF 2 /* surfaces/cylinder */ +#define DSK_NUMCY 203 /* cylinders/drive */ +#define DSK_NUMDR 5 /* drives/controller */ #define DSK_SIZE (DSK_NUMCY * DSK_NUMSF * DSK_NUMSC * DSK_NUMWD) /* words/drive */ char *usestr = "Usage: checkdisk [-f] [-d cyl.sec|abssec] [-n count] diskfile"; @@ -64,171 +64,171 @@ char *lowcase (char *str); int main (int argc, char **argv) { - FILE *fp; - char *fname = NULL, *arg, *argval; - int i, j, cyl, sec, pos, asec, retry, nbad = 0, nfixed = 0, nline; - BOOL fixit = FALSE, dump = FALSE; - int dsec, nsec = 1; - unsigned short wd, buf[DSK_NUMWD]; + FILE *fp; + char *fname = NULL, *arg, *argval; + int i, j, cyl, sec, pos, asec, retry, nbad = 0, nfixed = 0, nline; + BOOL fixit = FALSE, dump = FALSE; + int dsec, nsec = 1; + unsigned short wd, buf[DSK_NUMWD]; - for (i = 1; i < argc;) { - arg = argv[i++]; - if (*arg == '-') { - arg++; - lowcase(arg); - while (*arg) { - switch (*arg++) { - case 'f': - fixit = TRUE; - break; + for (i = 1; i < argc;) { + arg = argv[i++]; + if (*arg == '-') { + arg++; + lowcase(arg); + while (*arg) { + switch (*arg++) { + case 'f': + fixit = TRUE; + break; - case 'd': - dump = TRUE; + case 'd': + dump = TRUE; - if (i >= argc) - bail(usestr); + if (i >= argc) + bail(usestr); - argval = argv[i++]; - if (strchr(argval, '.') != NULL) { - if (sscanf(argval, "%d.%d", &cyl, &sec) != 2) - bail(usestr); + argval = argv[i++]; + if (strchr(argval, '.') != NULL) { + if (sscanf(argval, "%d.%d", &cyl, &sec) != 2) + bail(usestr); - dsec = cyl*(DSK_NUMSF*DSK_NUMSC) + sec; - } - else if (sscanf(argval, "%d", &dsec) != 1) - bail(usestr); + dsec = cyl*(DSK_NUMSF*DSK_NUMSC) + sec; + } + else if (sscanf(argval, "%d", &dsec) != 1) + bail(usestr); - if (dsec < 0 || dsec >= (DSK_NUMCY*DSK_NUMSF*DSK_NUMSC)) - bail("No such sector"); + if (dsec < 0 || dsec >= (DSK_NUMCY*DSK_NUMSF*DSK_NUMSC)) + bail("No such sector"); - break; + break; - case 'n': - if (i >= argc) - bail(usestr); + case 'n': + if (i >= argc) + bail(usestr); - argval = argv[i++]; - if (sscanf(argval, "%d", &nsec) != 1) - bail(usestr); + argval = argv[i++]; + if (sscanf(argval, "%d", &nsec) != 1) + bail(usestr); - if (nsec <= 0) - bail(usestr); + if (nsec <= 0) + bail(usestr); - break; + break; - default: - bail(usestr); - } - } - } - else if (fname == NULL) - fname = arg; - else - bail(usestr); - } + default: + bail(usestr); + } + } + } + else if (fname == NULL) + fname = arg; + else + bail(usestr); + } - if (fname == NULL) - bail(usestr); + if (fname == NULL) + bail(usestr); - if ((fp = fopen(fname, "rb+")) == NULL) { - perror(fname); - return 1; - } + if ((fp = fopen(fname, "rb+")) == NULL) { + perror(fname); + return 1; + } - if (filelength(fileno(fp)) != 2*DSK_SIZE) { - fprintf(stderr, "File is wrong length, expected %d\n", DSK_SIZE); - bail(baddisk); - } + if (filelength(fileno(fp)) != 2*DSK_SIZE) { + fprintf(stderr, "File is wrong length, expected %d\n", DSK_SIZE); + bail(baddisk); + } - for (cyl = 0; cyl < DSK_NUMCY; cyl++) { - for (sec = 0; sec < (DSK_NUMSF*DSK_NUMSC); sec++) { - retry = 1; + for (cyl = 0; cyl < DSK_NUMCY; cyl++) { + for (sec = 0; sec < (DSK_NUMSF*DSK_NUMSC); sec++) { + retry = 1; again: - asec = cyl*(DSK_NUMSF*DSK_NUMSC) + sec; - pos = asec*2*DSK_NUMWD; + asec = cyl*(DSK_NUMSF*DSK_NUMSC) + sec; + pos = asec*2*DSK_NUMWD; - if (fseek(fp, pos, SEEK_SET) != 0) { - fprintf(stderr, "Error seeking to pos %x\n", pos); - bail(baddisk); - } + if (fseek(fp, pos, SEEK_SET) != 0) { + fprintf(stderr, "Error seeking to pos %x\n", pos); + bail(baddisk); + } - if (fxread(&wd, sizeof(wd), 1, fp) != 1) { - fprintf(stderr, "Error reading word at abs sec %x, cyl %x, sec %x at offset %x\n", asec, cyl, sec, pos); - bail(baddisk); - } + if (fxread(&wd, sizeof(wd), 1, fp) != 1) { + fprintf(stderr, "Error reading word at abs sec %x, cyl %x, sec %x at offset %x\n", asec, cyl, sec, pos); + bail(baddisk); + } - if (wd != asec) { - fprintf(stderr, "Bad sector #%x at abs sec %x, cyl %x, sec %x at offset %x\n", wd, asec, cyl, sec, pos); - nbad++; + if (wd != asec) { + fprintf(stderr, "Bad sector #%x at abs sec %x, cyl %x, sec %x at offset %x\n", wd, asec, cyl, sec, pos); + nbad++; - if (fixit) { - if (fseek(fp, pos, SEEK_SET) != 0) { - fprintf(stderr, "Error seeking to pos %x\n", pos); - bail(baddisk); - } + if (fixit) { + if (fseek(fp, pos, SEEK_SET) != 0) { + fprintf(stderr, "Error seeking to pos %x\n", pos); + bail(baddisk); + } - if (fxwrite(&asec, sizeof(wd), 1, fp) != 1) { - fprintf(stderr, "Error writing sector # to abs sec %x, cyl %x, sec %x at offset %x\n", asec, cyl, sec, pos); - bail(baddisk); - } + if (fxwrite(&asec, sizeof(wd), 1, fp) != 1) { + fprintf(stderr, "Error writing sector # to abs sec %x, cyl %x, sec %x at offset %x\n", asec, cyl, sec, pos); + bail(baddisk); + } - if (retry) { - retry = 0; - nfixed++; - goto again; - } - - fprintf(stderr, "Failed after retry\n"); - bail(baddisk); - } - } - } - } + if (retry) { + retry = 0; + nfixed++; + goto again; + } + + fprintf(stderr, "Failed after retry\n"); + bail(baddisk); + } + } + } + } - if (nbad) - printf("%d bad sector mark%s %s\n", nbad, (nbad == 1) ? "" : "s", fixit ? "fixed" : "found"); - else if (! dump) - printf("All sector marks OK\n"); + if (nbad) + printf("%d bad sector mark%s %s\n", nbad, (nbad == 1) ? "" : "s", fixit ? "fixed" : "found"); + else if (! dump) + printf("All sector marks OK\n"); - if (! dump) - return 0; + if (! dump) + return 0; - pos = dsec*2*DSK_NUMWD; - if (fseek(fp, pos, SEEK_SET) != 0) { - fprintf(stderr, "Error seeking to pos %x\n", pos); - bail(baddisk); - } + pos = dsec*2*DSK_NUMWD; + if (fseek(fp, pos, SEEK_SET) != 0) { + fprintf(stderr, "Error seeking to pos %x\n", pos); + bail(baddisk); + } - for (i = 0; i < nsec; i++) { - cyl = dsec / (DSK_NUMSF*DSK_NUMSC); - sec = dsec - cyl*(DSK_NUMSF*DSK_NUMSC); + for (i = 0; i < nsec; i++) { + cyl = dsec / (DSK_NUMSF*DSK_NUMSC); + sec = dsec - cyl*(DSK_NUMSF*DSK_NUMSC); - if (fxread(&buf, sizeof(buf[0]), DSK_NUMWD, fp) != DSK_NUMWD) { - fprintf(stderr, "Error reading abs sec %x, cyl %x, sec %x at offset %x\n", dsec, cyl, sec, pos); - bail(baddisk); - } + if (fxread(&buf, sizeof(buf[0]), DSK_NUMWD, fp) != DSK_NUMWD) { + fprintf(stderr, "Error reading abs sec %x, cyl %x, sec %x at offset %x\n", dsec, cyl, sec, pos); + bail(baddisk); + } - printf("\nSector %d.%d - %d - /%04x label %04x\n", cyl, sec, dsec, dsec, buf[0]); - for (nline = 0, j = 1; j < DSK_NUMWD; j++) { - printf("%04x", buf[j]); - if (++nline == 16) { - putchar('\n'); - nline = 0; - } - else - putchar(' '); - } + printf("\nSector %d.%d - %d - /%04x label %04x\n", cyl, sec, dsec, dsec, buf[0]); + for (nline = 0, j = 1; j < DSK_NUMWD; j++) { + printf("%04x", buf[j]); + if (++nline == 16) { + putchar('\n'); + nline = 0; + } + else + putchar(' '); + } - dsec++; - } + dsec++; + } - return 0; + return 0; } void bail (char *msg) { - fprintf(stderr, "%s\n", msg); - exit(1); + fprintf(stderr, "%s\n", msg); + exit(1); } /* ------------------------------------------------------------------------ @@ -237,14 +237,14 @@ void bail (char *msg) char *lowcase (char *str) { - char *s; + char *s; - for (s = str; *s; s++) { - if (*s >= 'A' && *s <= 'Z') - *s += 32; - } + for (s = str; *s; s++) { + if (*s >= 'A' && *s <= 'Z') + *s += 32; + } - return str; + return str; } #ifndef _WIN32 @@ -254,9 +254,9 @@ long filelength (int fno) struct stat sb; if (fstat(fno, &sb) != 0) - return 0; + return 0; - return (long) sb.st_size; + return (long) sb.st_size; } #endif diff --git a/Ibm1130/utils/diskview.c b/Ibm1130/utils/diskview.c index 42fa37d2..6a093a24 100644 --- a/Ibm1130/utils/diskview.c +++ b/Ibm1130/utils/diskview.c @@ -13,7 +13,7 @@ // needs LET/SLET listing routine. // // usage: -// diskview -v diskfile +// diskview -v diskfile #include #include @@ -31,13 +31,13 @@ # define BOOL int #endif -#define NOT_DEF 0x0658 // defective cylinder table entry means no defect +#define NOT_DEF 0x0658 // defective cylinder table entry means no defect -#define DSK_NUMWD 321 /* words/sector */ -#define DSK_NUMCY 203 /* cylinders/drive */ -#define DSK_SECCYL 8 /* sectors per cylinder */ -#define SECLEN 320 /* data words per sector */ -#define SLETLEN ((3*SECLEN)/4) /* length of slet in records */ +#define DSK_NUMWD 321 /* words/sector */ +#define DSK_NUMCY 203 /* cylinders/drive */ +#define DSK_SECCYL 8 /* sectors per cylinder */ +#define SECLEN 320 /* data words per sector */ +#define SLETLEN ((3*SECLEN)/4) /* length of slet in records */ typedef unsigned short WORD; @@ -47,10 +47,10 @@ WORD dcom[DSK_NUMWD]; #pragma pack(2) struct tag_slet { - WORD phid; - WORD addr; - WORD nwords; - WORD sector; + WORD phid; + WORD addr; + WORD nwords; + WORD sector; } slet[SLETLEN]; #pragma pack() @@ -77,188 +77,188 @@ char *trim (char *s); int main (int argc, char **argv) { - char *fname = NULL, *arg; - static char usestr[] = "Usage: diskview [-v] filename"; - int i; + char *fname = NULL, *arg; + static char usestr[] = "Usage: diskview [-v] filename"; + int i; - for (i = 1; i < argc;) { - arg = argv[i++]; - if (*arg == '-') { - arg++; - lowcase(arg); - while (*arg) { - switch (*arg++) { - case 'v': - verbose = TRUE; - break; + for (i = 1; i < argc;) { + arg = argv[i++]; + if (*arg == '-') { + arg++; + lowcase(arg); + while (*arg) { + switch (*arg++) { + case 'v': + verbose = TRUE; + break; - default: - bail(usestr); - } - } - } - else if (fname == NULL) - fname = arg; - else - bail(usestr); - } + default: + bail(usestr); + } + } + } + else if (fname == NULL) + fname = arg; + else + bail(usestr); + } - if (fname == NULL) - bail(usestr); + if (fname == NULL) + bail(usestr); - if ((fp = fopen(fname, "rb")) == NULL) { - perror(fname); - return 2; - } + if ((fp = fopen(fname, "rb")) == NULL) { + perror(fname); + return 2; + } - printf("%s:\n", fname); + printf("%s:\n", fname); - checksectors(); - getdcyl(); + checksectors(); + getdcyl(); - dump_id(); // ID & coldstart - dump_dcom(); // DCOM - dump_resmon(); // resident image - dump_slet(); // SLET - dump_hdng(); // heading sector - dump_scra(); - dump_flet(); - dump_cib(); - dump_let(); + dump_id(); // ID & coldstart + dump_dcom(); // DCOM + dump_resmon(); // resident image + dump_slet(); // SLET + dump_hdng(); // heading sector + dump_scra(); + dump_flet(); + dump_cib(); + dump_let(); - fclose(fp); - return 0; + fclose(fp); + return 0; } // checksectors - verify that all sectors are properly numbered void checksectors () { - WORD sec = 0; + WORD sec = 0; - fseek(fp, 0, SEEK_SET); + fseek(fp, 0, SEEK_SET); - for (sec = 0; sec < DSK_NUMCY*DSK_SECCYL; sec++) { - if (fxread(buf, sizeof(WORD), DSK_NUMWD, fp) != DSK_NUMWD) - bail("File read error or not a disk image file"); + for (sec = 0; sec < DSK_NUMCY*DSK_SECCYL; sec++) { + if (fxread(buf, sizeof(WORD), DSK_NUMWD, fp) != DSK_NUMWD) + bail("File read error or not a disk image file"); - if (buf[0] != sec) - bail("Sector /%x is misnumbered, run checkdisk [-f]", sec); - } + if (buf[0] != sec) + bail("Sector /%x is misnumbered, run checkdisk [-f]", sec); + } } // get defective cylinder list void getdcyl (void) { - fseek(fp, sizeof(WORD), SEEK_SET); // skip sector count - if (fxread(dcyl, sizeof(WORD), 3, fp) != 3) - bail("Unable to read defective cylinder table"); + fseek(fp, sizeof(WORD), SEEK_SET); // skip sector count + if (fxread(dcyl, sizeof(WORD), 3, fp) != 3) + bail("Unable to read defective cylinder table"); } // getsector - read specified absolute sector void getsector (int sec, WORD *sbuf) { - int i, cyl, ssec; + int i, cyl, ssec; - sec &= 0x7FF; // mask of drive bits, if any + sec &= 0x7FF; // mask of drive bits, if any - cyl = sec / DSK_SECCYL; // get cylinder - ssec = sec & ~(DSK_SECCYL-1); // mask to get starting sector of cylinder - for (i = 0; i < 3; i++) { // map through defective cylinder table - if (dcyl[i] == ssec) { - sec &= (DSK_SECCYL-1); // mask to get base sector - cyl = DSK_NUMCY-3+i; // replacements are last three on disk - sec += cyl*DSK_SECCYL; // add new cylinder offset - break; - } - } - // read the sector - if (fseek(fp, (sec*DSK_NUMWD+1)*sizeof(WORD), SEEK_SET) != 0) - bail("File seek failed"); + cyl = sec / DSK_SECCYL; // get cylinder + ssec = sec & ~(DSK_SECCYL-1); // mask to get starting sector of cylinder + for (i = 0; i < 3; i++) { // map through defective cylinder table + if (dcyl[i] == ssec) { + sec &= (DSK_SECCYL-1); // mask to get base sector + cyl = DSK_NUMCY-3+i; // replacements are last three on disk + sec += cyl*DSK_SECCYL; // add new cylinder offset + break; + } + } + // read the sector + if (fseek(fp, (sec*DSK_NUMWD+1)*sizeof(WORD), SEEK_SET) != 0) + bail("File seek failed"); - if (fxread(sbuf, sizeof(WORD), DSK_NUMWD, fp) != DSK_NUMWD) - bail("File read error or not a disk image file"); + if (fxread(sbuf, sizeof(WORD), DSK_NUMWD, fp) != DSK_NUMWD) + bail("File read error or not a disk image file"); } void dump (int nwords) { - int i, nline = 0; + int i, nline = 0; - for (i = 0; i < nwords; i++) { - if (nline == 16) { - putchar('\n'); - nline = 0; - } + for (i = 0; i < nwords; i++) { + if (nline == 16) { + putchar('\n'); + nline = 0; + } - printf("%04x", buf[i]); - nline++; - } - putchar('\n'); + printf("%04x", buf[i]); + nline++; + } + putchar('\n'); } void showmajor (char *label) { - int i; + int i; - printf("\n--- %s ", label); + printf("\n--- %s ", label); - for (i = strlen(label); i < 40; i++) - putchar('-'); + for (i = strlen(label); i < 40; i++) + putchar('-'); - putchar('\n'); - putchar('\n'); + putchar('\n'); + putchar('\n'); } void name (char *label) { - printf("%-32.32s ", label); + printf("%-32.32s ", label); } void pbf (char *label, WORD *buf, int nwords) { - int i, nout; + int i, nout; - name(label); + name(label); - for (i = nout = 0; i < nwords; i++, nout++) { - if (nout == 8) { - putchar('\n'); - name(""); - nout = 0; - } - printf(" %04x", buf[i]); - } + for (i = nout = 0; i < nwords; i++, nout++) { + if (nout == 8) { + putchar('\n'); + name(""); + nout = 0; + } + printf(" %04x", buf[i]); + } - putchar('\n'); + putchar('\n'); } void prt (char *label, char *fmt, ...) { - va_list args; + va_list args; - name(label); + name(label); - putchar(' '); - va_start(args, fmt); - vprintf(fmt, args); - va_end(args); + putchar(' '); + va_start(args, fmt); + vprintf(fmt, args); + va_end(args); - putchar('\n'); + putchar('\n'); } void dump_id (void) { - showmajor("Sector 0 - ID & coldstart"); - getsector(0, buf); + showmajor("Sector 0 - ID & coldstart"); + getsector(0, buf); - pbf("DCYL def cyl table", buf+ 0, 3); - pbf("CIDN cart id", buf+ 3, 1); - pbf(" copy code", buf+ 4, 1); - pbf("DTYP disk type", buf+ 7, 1); - pbf(" diskz copy", buf+ 30, 8); - pbf(" cold start pgm",buf+270, 8); + pbf("DCYL def cyl table", buf+ 0, 3); + pbf("CIDN cart id", buf+ 3, 1); + pbf(" copy code", buf+ 4, 1); + pbf("DTYP disk type", buf+ 7, 1); + pbf(" diskz copy", buf+ 30, 8); + pbf(" cold start pgm",buf+270, 8); } // EQUIVALENCES FOR DCOM PARAMETERS @@ -304,257 +304,257 @@ void dump_id (void) #define CSHN 90 // NO. SCTRS IN CUSHION AREA struct tag_dcominfo { - char *nm; - int offset; - char *descr; + char *nm; + int offset; + char *descr; } dcominfo[] = { - "NAME", 4, "NAME OF PROGRAM/CORE LOAD", - "DBCT", 6, "BLOCK CT OF PROGRAM/CORE LOAD", - "FCNT", 7, "FILES SWITCH", - "SYSC", 8, "SYSTEM/NON-SYSTEM CARTRIDGE INDR", - "JBSW", 9, "JOBT SWITCH", - "CBSW", 10, "CLB-RETURN SWITCH", - "LCNT", 11, "NO. OF LOCALS", - "MPSW", 12, "CORE MAP SWITCH", - "MDF1", 13, "NO. DUP CTRL RECORDS (MODIF)", - "MDF2", 14, "ADDR OF MODIF BUFFER", - "NCNT", 15, "NO. OF NOCALS", - "ENTY", 16, "RLTV ENTRY ADDR OF PROGRAM", - "RP67", 17, "1442-5 SWITCH", - "TODR", 18, "OBJECT WORK STORAGE DRIVE CODE", - "FHOL", 20, "ADDR LARGEST HOLE IN FIXED AREA", - "FSZE", 21, "BLK CNT LARGEST HOLE IN FXA", - "UHOL", 22, "ADDR LAST HOLE IN USER AREA", - "USZE", 23, "BLK CNT LAST HOLE IN UA", - "DCSW", 24, "DUP CALL SWITCH", - "PIOD", 25, "PRINCIPAL I/O DEVICE INDICATOR", - "PPTR", 26, "PRINCIPAL PRINT DEVICE INDICATOR", - "CIAD", 27, "RLTV ADDR IN @STRT OF CIL ADDR", - "ACIN", 28, "AVAILABLE CARTRIDGE INDICATOR", - "GRPH", 29, "2250 INDICATOR", - "GCNT", 30, "NO. G2250 RECORDS", - "LOSW", 31, "LOCAL-CALLS-LOCAL SWITCH", - "X3SW", 32, "SPECIAL ILS SWITCH", - "ECNT", 33, "NO. OF *EQUAT RCDS", - "ANDU", 35, "1+BLK ADDR END OF UA (ADJUSTED)", - "BNDU", 40, "1+BLK ADDR END OF UA (BASE)", - "FPAD", 45, "FILE PROTECT ADDR", - "PCID", 50, "CARTRIDGE ID, PHYSICAL DRIVE", - "CIDN", 55, "CARTRIDGE ID, LOGICAL DRIVE", - "CIBA", 60, "SCTR ADDR OF CIB", - "SCRA", 65, "SCTR ADDR OF SCRA", - "FMAT", 70, "FORMAT OF PROG IN WORKING STG", - "FLET", 75, "SCTR ADDR 1ST SCTR OF FLET", - "ULET", 80, "SCTR ADDR 1ST SCTR OF LET", - "WSCT", 85, "BLK CNT OF PROG IN WORKING STG", - "CSHN", 90, "NO. SCTRS IN CUSHION AREA", - NULL + "NAME", 4, "NAME OF PROGRAM/CORE LOAD", + "DBCT", 6, "BLOCK CT OF PROGRAM/CORE LOAD", + "FCNT", 7, "FILES SWITCH", + "SYSC", 8, "SYSTEM/NON-SYSTEM CARTRIDGE INDR", + "JBSW", 9, "JOBT SWITCH", + "CBSW", 10, "CLB-RETURN SWITCH", + "LCNT", 11, "NO. OF LOCALS", + "MPSW", 12, "CORE MAP SWITCH", + "MDF1", 13, "NO. DUP CTRL RECORDS (MODIF)", + "MDF2", 14, "ADDR OF MODIF BUFFER", + "NCNT", 15, "NO. OF NOCALS", + "ENTY", 16, "RLTV ENTRY ADDR OF PROGRAM", + "RP67", 17, "1442-5 SWITCH", + "TODR", 18, "OBJECT WORK STORAGE DRIVE CODE", + "FHOL", 20, "ADDR LARGEST HOLE IN FIXED AREA", + "FSZE", 21, "BLK CNT LARGEST HOLE IN FXA", + "UHOL", 22, "ADDR LAST HOLE IN USER AREA", + "USZE", 23, "BLK CNT LAST HOLE IN UA", + "DCSW", 24, "DUP CALL SWITCH", + "PIOD", 25, "PRINCIPAL I/O DEVICE INDICATOR", + "PPTR", 26, "PRINCIPAL PRINT DEVICE INDICATOR", + "CIAD", 27, "RLTV ADDR IN @STRT OF CIL ADDR", + "ACIN", 28, "AVAILABLE CARTRIDGE INDICATOR", + "GRPH", 29, "2250 INDICATOR", + "GCNT", 30, "NO. G2250 RECORDS", + "LOSW", 31, "LOCAL-CALLS-LOCAL SWITCH", + "X3SW", 32, "SPECIAL ILS SWITCH", + "ECNT", 33, "NO. OF *EQUAT RCDS", + "ANDU", 35, "1+BLK ADDR END OF UA (ADJUSTED)", + "BNDU", 40, "1+BLK ADDR END OF UA (BASE)", + "FPAD", 45, "FILE PROTECT ADDR", + "PCID", 50, "CARTRIDGE ID, PHYSICAL DRIVE", + "CIDN", 55, "CARTRIDGE ID, LOGICAL DRIVE", + "CIBA", 60, "SCTR ADDR OF CIB", + "SCRA", 65, "SCTR ADDR OF SCRA", + "FMAT", 70, "FORMAT OF PROG IN WORKING STG", + "FLET", 75, "SCTR ADDR 1ST SCTR OF FLET", + "ULET", 80, "SCTR ADDR 1ST SCTR OF LET", + "WSCT", 85, "BLK CNT OF PROG IN WORKING STG", + "CSHN", 90, "NO. SCTRS IN CUSHION AREA", + NULL }; void dump_dcom (void) { - struct tag_dcominfo *d; - char txt[50]; + struct tag_dcominfo *d; + char txt[50]; - showmajor("Sector 1 - DCOM"); - getsector(1, dcom); + showmajor("Sector 1 - DCOM"); + getsector(1, dcom); - for (d = dcominfo; d->nm != NULL; d++) { - sprintf(txt, "%-4.4s %s", d->nm, d->descr); - pbf(txt, dcom+d->offset, 1); - } + for (d = dcominfo; d->nm != NULL; d++) { + sprintf(txt, "%-4.4s %s", d->nm, d->descr); + pbf(txt, dcom+d->offset, 1); + } } void dump_resmon (void) { - showmajor("Sector 2 - Resident Image"); - getsector(2, buf); - dump(verbose ? SECLEN : 32); + showmajor("Sector 2 - Resident Image"); + getsector(2, buf); + dump(verbose ? SECLEN : 32); } struct { - int pfrom, pto; - int printed; - char *name; + int pfrom, pto; + int printed; + char *name; } sletinfo[] = { - 0x01, 0x12, FALSE, "DUP", - 0x1F, 0x39, FALSE, "Fortran", - 0x51, 0x5C, FALSE, "Cobol", - 0x6E, 0x74, FALSE, "Supervisor", - 0x78, 0x84, FALSE, "Core Load Builder", - 0x8C, 0x8C, FALSE, "Sys 1403 prt", - 0x8D, 0x8D, FALSE, "Sys 1132 prt", - 0x8E, 0x8E, FALSE, "Sys console prt", - 0x8F, 0x8F, FALSE, "Sys 2501 rdr", - 0x90, 0x90, FALSE, "Sys 1442 rdr/pun", - 0x91, 0x91, FALSE, "Sys 1134 paper tape", - 0x92, 0x92, FALSE, "Sys kbd", - 0x93, 0x93, FALSE, "Sys 2501/1442 conv", - 0x94, 0x94, FALSE, "Sys 1134 conv", - 0x95, 0x95, FALSE, "Sys kbd conv", - 0x96, 0x96, FALSE, "Sys diskz", - 0x97, 0x97, FALSE, "Sys disk1", - 0x98, 0x98, FALSE, "Sys diskn", - 0x99, 0x99, FALSE, "(primary print)", - 0x9A, 0x9A, FALSE, "(primary input)", - 0x9B, 0x9B, FALSE, "(primary input excl kbd)", - 0x9C, 0x9C, FALSE, "(primary sys conv)", - 0x9D, 0x9D, FALSE, "(primary conv excl kbd)", - 0xA0, 0xA1, FALSE, "Core Image Loader", - 0xB0, 0xCC, FALSE, "RPG", - 0xCD, 0xCE, FALSE, "Dup Part 2", - 0xCF, 0xF6, FALSE, "Macro Assembler", - 0 + 0x01, 0x12, FALSE, "DUP", + 0x1F, 0x39, FALSE, "Fortran", + 0x51, 0x5C, FALSE, "Cobol", + 0x6E, 0x74, FALSE, "Supervisor", + 0x78, 0x84, FALSE, "Core Load Builder", + 0x8C, 0x8C, FALSE, "Sys 1403 prt", + 0x8D, 0x8D, FALSE, "Sys 1132 prt", + 0x8E, 0x8E, FALSE, "Sys console prt", + 0x8F, 0x8F, FALSE, "Sys 2501 rdr", + 0x90, 0x90, FALSE, "Sys 1442 rdr/pun", + 0x91, 0x91, FALSE, "Sys 1134 paper tape", + 0x92, 0x92, FALSE, "Sys kbd", + 0x93, 0x93, FALSE, "Sys 2501/1442 conv", + 0x94, 0x94, FALSE, "Sys 1134 conv", + 0x95, 0x95, FALSE, "Sys kbd conv", + 0x96, 0x96, FALSE, "Sys diskz", + 0x97, 0x97, FALSE, "Sys disk1", + 0x98, 0x98, FALSE, "Sys diskn", + 0x99, 0x99, FALSE, "(primary print)", + 0x9A, 0x9A, FALSE, "(primary input)", + 0x9B, 0x9B, FALSE, "(primary input excl kbd)", + 0x9C, 0x9C, FALSE, "(primary sys conv)", + 0x9D, 0x9D, FALSE, "(primary conv excl kbd)", + 0xA0, 0xA1, FALSE, "Core Image Loader", + 0xB0, 0xCC, FALSE, "RPG", + 0xCD, 0xCE, FALSE, "Dup Part 2", + 0xCF, 0xF6, FALSE, "Macro Assembler", + 0 }; void dump_slet (void) { - int i, j, iphase, nsecs, sec, max_sec = 0; - char sstr[16], *smark; + int i, j, iphase, nsecs, sec, max_sec = 0; + char sstr[16], *smark; - showmajor("Sectors 3-5 - SLET"); - for (i = 0; i < 3; i++) { - getsector(3+i, buf); - memmove(((WORD *) slet)+SECLEN*i, buf, SECLEN*sizeof(WORD)); - } + showmajor("Sectors 3-5 - SLET"); + for (i = 0; i < 3; i++) { + getsector(3+i, buf); + memmove(((WORD *) slet)+SECLEN*i, buf, SECLEN*sizeof(WORD)); + } printf("# PHID Addr Len Sector Secs\n"); - printf("------------------------------------------\n"); - for (i = 0; i < SLETLEN; i++) { - if (slet[i].phid == 0) - break; + printf("------------------------------------------\n"); + for (i = 0; i < SLETLEN; i++) { + if (slet[i].phid == 0) + break; - sec = slet[i].sector; - iphase = (int) (signed short) slet[i].phid; - nsecs = (slet[i].nwords + SECLEN-1)/SECLEN; + sec = slet[i].sector; + iphase = (int) (signed short) slet[i].phid; + nsecs = (slet[i].nwords + SECLEN-1)/SECLEN; - if (sec & 0xF800) { - smark = "*"; - sec &= 0x7FF; - } - else - smark = " "; + if (sec & 0xF800) { + smark = "*"; + sec &= 0x7FF; + } + else + smark = " "; - for (j = 0; sletinfo[j].pfrom != 0; j++) - if (sletinfo[j].pfrom <= iphase && sletinfo[j].pto >= iphase) - break; + for (j = 0; sletinfo[j].pfrom != 0; j++) + if (sletinfo[j].pfrom <= iphase && sletinfo[j].pto >= iphase) + break; - sprintf(sstr, "(%d.%d)", sec / DSK_SECCYL, slet[i].sector % DSK_SECCYL); + sprintf(sstr, "(%d.%d)", sec / DSK_SECCYL, slet[i].sector % DSK_SECCYL); - printf("%3d %04x %4d %04x %04x %04x %s %-7s %3x", - i, slet[i].phid, iphase, slet[i].addr, slet[i].nwords, slet[i].sector, smark, sstr, nsecs); + printf("%3d %04x %4d %04x %04x %04x %s %-7s %3x", + i, slet[i].phid, iphase, slet[i].addr, slet[i].nwords, slet[i].sector, smark, sstr, nsecs); - if (iphase < 0) - iphase = -iphase; + if (iphase < 0) + iphase = -iphase; - if (sletinfo[j].pfrom == 0) - printf(" ???"); - else if (! sletinfo[j].printed) { - printf(" %s", sletinfo[j].name); - sletinfo[j].printed = TRUE; - } + if (sletinfo[j].pfrom == 0) + printf(" ???"); + else if (! sletinfo[j].printed) { + printf(" %s", sletinfo[j].name); + sletinfo[j].printed = TRUE; + } - for (j = 0; j < i; j++) { - if (sec == (slet[j].sector & 0x7FF)) { - printf(" (same as %04x)", slet[j].phid); - break; - } - } + for (j = 0; j < i; j++) { + if (sec == (slet[j].sector & 0x7FF)) { + printf(" (same as %04x)", slet[j].phid); + break; + } + } - max_sec = MAX(max_sec, sec+nsecs-1); // find last sector used + max_sec = MAX(max_sec, sec+nsecs-1); // find last sector used - putchar('\n'); + putchar('\n'); - if (i >= 15 && ! verbose) { - printf("...\n"); - break; - } - } + if (i >= 15 && ! verbose) { + printf("...\n"); + break; + } + } } int ascii_to_ebcdic_table[128] = { - 0x00,0x01,0x02,0x03,0x37,0x2d,0x2e,0x2f, 0x16,0x05,0x25,0x0b,0x0c,0x0d,0x0e,0x0f, - 0x10,0x11,0x12,0x13,0x3c,0x3d,0x32,0x26, 0x18,0x19,0x3f,0x27,0x1c,0x1d,0x1e,0x1f, - 0x40,0x5a,0x7f,0x7b,0x5b,0x6c,0x50,0x7d, 0x4d,0x5d,0x5c,0x4e,0x6b,0x60,0x4b,0x61, - 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7, 0xf8,0xf9,0x7a,0x5e,0x4c,0x7e,0x6e,0x6f, + 0x00,0x01,0x02,0x03,0x37,0x2d,0x2e,0x2f, 0x16,0x05,0x25,0x0b,0x0c,0x0d,0x0e,0x0f, + 0x10,0x11,0x12,0x13,0x3c,0x3d,0x32,0x26, 0x18,0x19,0x3f,0x27,0x1c,0x1d,0x1e,0x1f, + 0x40,0x5a,0x7f,0x7b,0x5b,0x6c,0x50,0x7d, 0x4d,0x5d,0x5c,0x4e,0x6b,0x60,0x4b,0x61, + 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7, 0xf8,0xf9,0x7a,0x5e,0x4c,0x7e,0x6e,0x6f, - 0x7c,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7, 0xc8,0xc9,0xd1,0xd2,0xd3,0xd4,0xd5,0xd6, - 0xd7,0xd8,0xd9,0xe2,0xe3,0xe4,0xe5,0xe6, 0xe7,0xe8,0xe9,0xba,0xe0,0xbb,0xb0,0x6d, - 0x79,0x81,0x82,0x83,0x84,0x85,0x86,0x87, 0x88,0x89,0x91,0x92,0x93,0x94,0x95,0x96, - 0x97,0x98,0x99,0xa2,0xa3,0xa4,0xa5,0xa6, 0xa7,0xa8,0xa9,0xc0,0x4f,0xd0,0xa1,0x07, + 0x7c,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7, 0xc8,0xc9,0xd1,0xd2,0xd3,0xd4,0xd5,0xd6, + 0xd7,0xd8,0xd9,0xe2,0xe3,0xe4,0xe5,0xe6, 0xe7,0xe8,0xe9,0xba,0xe0,0xbb,0xb0,0x6d, + 0x79,0x81,0x82,0x83,0x84,0x85,0x86,0x87, 0x88,0x89,0x91,0x92,0x93,0x94,0x95,0x96, + 0x97,0x98,0x99,0xa2,0xa3,0xa4,0xa5,0xa6, 0xa7,0xa8,0xa9,0xc0,0x4f,0xd0,0xa1,0x07, }; int ebcdic_to_ascii (int ch) { - int j; + int j; - for (j = 32; j < 128; j++) - if (ascii_to_ebcdic_table[j] == ch) - return j; + for (j = 32; j < 128; j++) + if (ascii_to_ebcdic_table[j] == ch) + return j; - return '?'; + return '?'; } #define HDR_LEN 120 void dump_hdng(void) { - int i; - char str[HDR_LEN+1], *p = str; + int i; + char str[HDR_LEN+1], *p = str; - showmajor("Sector 7 - Heading"); - getsector(7, buf); + showmajor("Sector 7 - Heading"); + getsector(7, buf); - for (i = 0; i < (HDR_LEN/2); i++) { - *p++ = ebcdic_to_ascii((buf[i] >> 8) & 0xFF); - *p++ = ebcdic_to_ascii( buf[i] & 0xFF); - } + for (i = 0; i < (HDR_LEN/2); i++) { + *p++ = ebcdic_to_ascii((buf[i] >> 8) & 0xFF); + *p++ = ebcdic_to_ascii( buf[i] & 0xFF); + } - *p = '\0'; - trim(str); - printf("%s\n", str); + *p = '\0'; + trim(str); + printf("%s\n", str); } BOOL mget (int offset, char *name) { - char title[80]; + char title[80]; - if (dcom[offset] == 0) - return FALSE; + if (dcom[offset] == 0) + return FALSE; - getsector(dcom[offset], buf); - sprintf(title, "Sector %x - %s", dcom[offset], name); - showmajor(title); - return TRUE; + getsector(dcom[offset], buf); + sprintf(title, "Sector %x - %s", dcom[offset], name); + showmajor(title); + return TRUE; } void dump_scra (void) { - if (! mget(SCRA, "SCRA")) - return; + if (! mget(SCRA, "SCRA")) + return; - dump(verbose ? SECLEN : 32); + dump(verbose ? SECLEN : 32); } void dump_let (void) { - if (! mget(ULET, "LET")) - return; + if (! mget(ULET, "LET")) + return; } void dump_flet (void) { - if (! mget(FLET, "FLET")) - return; + if (! mget(FLET, "FLET")) + return; } void dump_cib (void) { - if (! mget(CIBA, "CIB")) - return; + if (! mget(CIBA, "CIB")) + return; - dump(verbose ? SECLEN : 32); + dump(verbose ? SECLEN : 32); } #define LFHD 5 // WORD COUNT OF LET/FLET HEADER PMN09970 @@ -568,14 +568,14 @@ void dump_cib (void) void bail (char *fmt, ...) { - va_list args; + va_list args; - va_start(args, fmt); - fprintf(stderr, fmt, args); - va_end(args); - putchar('\n'); + va_start(args, fmt); + fprintf(stderr, fmt, args); + va_end(args); + putchar('\n'); - exit(1); + exit(1); } // --------------------------------------------------------------------------------- @@ -584,14 +584,14 @@ void bail (char *fmt, ...) char *trim (char *s) { - char *os = s, *nb; + char *os = s, *nb; - for (nb = s-1; *s; s++) - if (*s > ' ') - nb = s; + for (nb = s-1; *s; s++) + if (*s > ' ') + nb = s; - nb[1] = '\0'; - return os; + nb[1] = '\0'; + return os; } /* ------------------------------------------------------------------------ @@ -600,13 +600,13 @@ char *trim (char *s) char *lowcase (char *str) { - char *s; + char *s; - for (s = str; *s; s++) { - if (*s >= 'A' && *s <= 'Z') - *s += 32; - } + for (s = str; *s; s++) { + if (*s >= 'A' && *s <= 'Z') + *s += 32; + } - return str; + return str; } diff --git a/Ibm1130/utils/mkboot.c b/Ibm1130/utils/mkboot.c index 470e21fb..284f633d 100644 --- a/Ibm1130/utils/mkboot.c +++ b/Ibm1130/utils/mkboot.c @@ -16,34 +16,34 @@ // Usage: mkboot [-v] binfile outfile [1130|1800|core [loaddr [hiaddr [ident]]]]" // // Arguments: -// binfile - name of assembler output file (card loader format, absolute output) -// outfile - name of output file to create -// mode - output mode, default is 1130 IPL format -// loaddr - low address to dump. Default is lowest address loaded from binfile -// hiaddr - high address to dump. Defult is highest address loaded from binfile -// ident - ident string to write in last 8 columns. Omit when when writing an -// 1130 IPL card that requires all 80 columns of data. +// binfile - name of assembler output file (card loader format, absolute output) +// outfile - name of output file to create +// mode - output mode, default is 1130 IPL format +// loaddr - low address to dump. Default is lowest address loaded from binfile +// hiaddr - high address to dump. Defult is highest address loaded from binfile +// ident - ident string to write in last 8 columns. Omit when when writing an +// 1130 IPL card that requires all 80 columns of data. // // Examples: -// mkboot somefile.bin somefile.ipl 1130 +// mkboot somefile.bin somefile.ipl 1130 // -// loads somefile.bin, writes object in 1130 IPL format to somefile.ipl -// Up to 80 columns will be written depending on what the object actually uses +// loads somefile.bin, writes object in 1130 IPL format to somefile.ipl +// Up to 80 columns will be written depending on what the object actually uses // -// mkboot somefile.bin somefile.ipl 1130 /0 /47 SOMEF +// mkboot somefile.bin somefile.ipl 1130 /0 /47 SOMEF // -// loads somefile.bin. Writes 72 columns (hex 0 to hex 47), with ident columns 73-80 = SOMEF001 +// loads somefile.bin. Writes 72 columns (hex 0 to hex 47), with ident columns 73-80 = SOMEF001 // -// mkboot somefile.bin somefile.dat core 0 0 SOMEF001 +// mkboot somefile.bin somefile.dat core 0 0 SOMEF001 // -// loads somefile.bin and writes a core image format deck with ident SOMEF001, SOMEF002, etc +// loads somefile.bin and writes a core image format deck with ident SOMEF001, SOMEF002, etc // -// For other examples of usage, see MKDMS.BAT +// For other examples of usage, see MKDMS.BAT // // 1.00 - 2002Apr18 - first release. Tested only under Win32. The core image -// loader format is almost certainly wrong. Cannot handle -// relocatable input decks, but it works well enough to -// load DSYSLDR1 which is what we are after here. +// loader format is almost certainly wrong. Cannot handle +// relocatable input decks, but it works well enough to +// load DSYSLDR1 which is what we are after here. // --------------------------------------------------------------------------------- #include @@ -77,13 +77,13 @@ BOOL verbose = FALSE; char *infile = NULL, *outfile = NULL; BOOTMODE mode = B_1130; int addr_from = 0, addr_to = 79; -int outcols = 0; // columns written in using card output +int outcols = 0; // columns written in using card output int maxiplcols = 80; -char cardid[9]; // characters used for IPL card ID +char cardid[9]; // characters used for IPL card ID int pta = 0; int load_low = 0x7FFFFFF; int load_high = 0; -unsigned short mem[MAXADDR]; // small core! +unsigned short mem[MAXADDR]; // small core! // mkboot - load a binary object deck into core and dump requested bytes as a boot card @@ -111,531 +111,531 @@ FILE *fout; int main (int argc, char **argv) { - char *arg; - static char usestr[] = "Usage: mkboot [-v] binfile outfile [1130|1800|core [loaddr [hiaddr [ident]]]]"; - int i, ano = 0, ok; + char *arg; + static char usestr[] = "Usage: mkboot [-v] binfile outfile [1130|1800|core [loaddr [hiaddr [ident]]]]"; + int i, ano = 0, ok; - for (i = 1; i < argc; i++) { - arg = argv[i]; - if (*arg == '-') { - arg++; - while (*arg) { - switch (*arg++) { - case 'v': - verbose = TRUE; - break; - default: - bail(usestr); - } - } - } - else { - switch (ano++) { - case 0: - infile = arg; - break; + for (i = 1; i < argc; i++) { + arg = argv[i]; + if (*arg == '-') { + arg++; + while (*arg) { + switch (*arg++) { + case 'v': + verbose = TRUE; + break; + default: + bail(usestr); + } + } + } + else { + switch (ano++) { + case 0: + infile = arg; + break; - case 1: - outfile = arg; - break; + case 1: + outfile = arg; + break; - case 2: - if (strcmp(arg, "1130") == 0) mode = B_1130; - else if (strcmp(arg, "1800") == 0) mode = B_1800; - else if (strcmpi(arg, "core") == 0) mode = B_CORE; - else bail(usestr); - break; + case 2: + if (strcmp(arg, "1130") == 0) mode = B_1130; + else if (strcmp(arg, "1800") == 0) mode = B_1800; + else if (strcmpi(arg, "core") == 0) mode = B_CORE; + else bail(usestr); + break; - case 3: - if (strnicmp(arg, "0x", 2) == 0) ok = sscanf(arg+2, "%x", &addr_from); - else if (arg[0] == '/') ok = sscanf(arg+1, "%x", &addr_from); - else ok = sscanf(arg, "%d", &addr_from); - if (ok != 1) bail(usestr); - break; + case 3: + if (strnicmp(arg, "0x", 2) == 0) ok = sscanf(arg+2, "%x", &addr_from); + else if (arg[0] == '/') ok = sscanf(arg+1, "%x", &addr_from); + else ok = sscanf(arg, "%d", &addr_from); + if (ok != 1) bail(usestr); + break; - case 4: - if (strnicmp(arg, "0x", 2) == 0) ok = sscanf(arg+2, "%x", &addr_to); - else if (arg[0] == '/') ok = sscanf(arg+1, "%x", &addr_to); - else ok = sscanf(arg, "%d", &addr_to); - if (ok != 1) bail(usestr); - break; + case 4: + if (strnicmp(arg, "0x", 2) == 0) ok = sscanf(arg+2, "%x", &addr_to); + else if (arg[0] == '/') ok = sscanf(arg+1, "%x", &addr_to); + else ok = sscanf(arg, "%d", &addr_to); + if (ok != 1) bail(usestr); + break; - case 5: - strncpy(cardid, arg, 9); - cardid[8] = '\0'; - upcase(cardid); - break; + case 5: + strncpy(cardid, arg, 9); + cardid[8] = '\0'; + upcase(cardid); + break; - default: - bail(usestr); - } - } - } + default: + bail(usestr); + } + } + } - if (*cardid == '\0') - maxiplcols = (mode == B_1130) ? 80 : 72; - else { - while (strlen(cardid) < 8) - strcat(cardid, "0"); - maxiplcols = 72; - } + if (*cardid == '\0') + maxiplcols = (mode == B_1130) ? 80 : 72; + else { + while (strlen(cardid) < 8) + strcat(cardid, "0"); + maxiplcols = 72; + } - loaddata(infile); + loaddata(infile); - if (mode == B_1800) - write_1800(); - else if (mode == B_CORE) - write_core(); - else - write_1130(); + if (mode == B_1800) + write_1800(); + else if (mode == B_CORE) + write_core(); + else + write_1130(); - return 0; + return 0; } void write_1130 (void) { - int addr; - unsigned short word; + int addr; + unsigned short word; - if ((fout = fopen(outfile, "wb")) == NULL) { - perror(outfile); - exit(1); - } + if ((fout = fopen(outfile, "wb")) == NULL) { + perror(outfile); + exit(1); + } - for (addr = addr_from; addr <= addr_to; addr++) { - if (outcols >= maxiplcols) - flushcard(); + for (addr = addr_from; addr <= addr_to; addr++) { + if (outcols >= maxiplcols) + flushcard(); - word = mem[addr]; + word = mem[addr]; - // if F or L bits are set, or if high 2 bits of displacement are unequal, it's bad - if ((word & 0x0700) || ! (((word & 0x00C0) == 0) || ((word & 0x00C0) == 0x00C0))) - printf("Warning: word %04x @ %04x may not IPL properly\n", word & 0xFFFF, addr); + // if F or L bits are set, or if high 2 bits of displacement are unequal, it's bad + if ((word & 0x0700) || ! (((word & 0x00C0) == 0) || ((word & 0x00C0) == 0x00C0))) + printf("Warning: word %04x @ %04x may not IPL properly\n", word & 0xFFFF, addr); - word = ((word & 0xF800) >> 4) | (word & 0x7F); // convert to 1130 IPL format + word = ((word & 0xF800) >> 4) | (word & 0x7F); // convert to 1130 IPL format - putc((word & 0x000F) << 4, fout); // write the 12 bits in little-endian binary AABBCC00 as CC00 AABB - putc((word & 0x0FF0) >> 4, fout); - outcols++; - } - flushcard(); - fclose(fout); + putc((word & 0x000F) << 4, fout); // write the 12 bits in little-endian binary AABBCC00 as CC00 AABB + putc((word & 0x0FF0) >> 4, fout); + outcols++; + } + flushcard(); + fclose(fout); } void write_1800 (void) { - int addr; - unsigned short word; + int addr; + unsigned short word; - if ((fout = fopen(outfile, "wb")) == NULL) { - perror(outfile); - exit(1); - } + if ((fout = fopen(outfile, "wb")) == NULL) { + perror(outfile); + exit(1); + } - for (addr = addr_from; addr <= addr_to; addr++) { - word = mem[addr]; + for (addr = addr_from; addr <= addr_to; addr++) { + word = mem[addr]; - if (outcols >= maxiplcols) - flushcard(); + if (outcols >= maxiplcols) + flushcard(); - putc(0, fout); - putc(word & 0xFF, fout); // write the low 8 bits in little-endian binary - outcols++; + putc(0, fout); + putc(word & 0xFF, fout); // write the low 8 bits in little-endian binary + outcols++; - putc(0, fout); - putc((word >> 8) & 0xFF, fout); // write the high 8 bits in little-endian binary - outcols++; - } - flushcard(); - fclose(fout); + putc(0, fout); + putc((word >> 8) & 0xFF, fout); // write the high 8 bits in little-endian binary + outcols++; + } + flushcard(); + fclose(fout); } void write_core (void) { - int addr; + int addr; - if ((fout = fopen(outfile, "wb")) == NULL) { - perror(outfile); - exit(1); - } + if ((fout = fopen(outfile, "wb")) == NULL) { + perror(outfile); + exit(1); + } - addr_from = load_low; - addr_to = load_high; + addr_from = load_low; + addr_to = load_high; - maxiplcols = 72; - corecard_init(); - corecard_setorg(addr_from); + maxiplcols = 72; + corecard_init(); + corecard_setorg(addr_from); - for (addr = addr_from; addr <= addr_to; addr++) { - corecard_writew(mem[addr], 0); - } + for (addr = addr_from; addr <= addr_to; addr++) { + corecard_writew(mem[addr], 0); + } - corecard_flush(); - corecard_endcard(); - fclose(fout); + corecard_flush(); + corecard_endcard(); + fclose(fout); } void flushcard (void) { - int i, hol, ndig; - char fmt[20], newdig[20]; + int i, hol, ndig; + char fmt[20], newdig[20]; - if (outcols <= 0) - return; // nothing to flush + if (outcols <= 0) + return; // nothing to flush - while (outcols < maxiplcols) { // pad to required number of columns with blanks (no punches) - putc(0, fout); - putc(0, fout); - outcols++; - } + while (outcols < maxiplcols) { // pad to required number of columns with blanks (no punches) + putc(0, fout); + putc(0, fout); + outcols++; + } - if (*cardid) { // add label - for (i = 0; i < 8; i++) { // write label as specified - hol = ascii_to_hollerith(cardid[i] & 0x7F); - putc(hol & 0xFF, fout); - putc((hol >> 8) & 0xFF, fout); - } + if (*cardid) { // add label + for (i = 0; i < 8; i++) { // write label as specified + hol = ascii_to_hollerith(cardid[i] & 0x7F); + putc(hol & 0xFF, fout); + putc((hol >> 8) & 0xFF, fout); + } - ndig = 0; // count trailing digits in the label - for (i = 8; --i >= 0; ndig++) - if (! isdigit(cardid[i])) - break; + ndig = 0; // count trailing digits in the label + for (i = 8; --i >= 0; ndig++) + if (! isdigit(cardid[i])) + break; - i++; // index of first digit in trailing sequence + i++; // index of first digit in trailing sequence - if (ndig > 0) { // if any, increment them - sprintf(fmt, "%%0%dd", ndig); // make, e.g. %03d - sprintf(newdig, fmt, atoi(cardid+i)+1); - newdig[ndig] = '\0'; // clip if necessary - strcpy(cardid+i, newdig); // replace for next card's sequence number - } - } + if (ndig > 0) { // if any, increment them + sprintf(fmt, "%%0%dd", ndig); // make, e.g. %03d + sprintf(newdig, fmt, atoi(cardid+i)+1); + newdig[ndig] = '\0'; // clip if necessary + strcpy(cardid+i, newdig); // replace for next card's sequence number + } + } - outcols = 0; + outcols = 0; } void show_data (unsigned short *buf) { - int i, n, jrel, rflag, nout, ch, reloc; + int i, n, jrel, rflag, nout, ch, reloc; - n = buf[2] & 0x00FF; + n = buf[2] & 0x00FF; - printf("%04x: ", buf[0]); + printf("%04x: ", buf[0]); - jrel = 3; - nout = 0; - rflag = buf[jrel++]; - for (i = 0; i < n; i++) { - if (nout >= 8) { - rflag = buf[jrel++]; - putchar('\n'); - printf(" "); - nout = 0; - } - reloc = (rflag >> 14) & 0x03; - ch = (reloc == R_ABSOLUTE) ? ' ' : - (reloc == R_RELATIVE) ? 'R' : - (reloc == R_LIBF) ? 'L' : '@'; + jrel = 3; + nout = 0; + rflag = buf[jrel++]; + for (i = 0; i < n; i++) { + if (nout >= 8) { + rflag = buf[jrel++]; + putchar('\n'); + printf(" "); + nout = 0; + } + reloc = (rflag >> 14) & 0x03; + ch = (reloc == R_ABSOLUTE) ? ' ' : + (reloc == R_RELATIVE) ? 'R' : + (reloc == R_LIBF) ? 'L' : '@'; - printf("%04x%c ", buf[9+i], ch); - rflag <<= 2; - nout++; - } - putchar('\n'); + printf("%04x%c ", buf[9+i], ch); + rflag <<= 2; + nout++; + } + putchar('\n'); } void loadcard (unsigned short *buf) { - int addr, n, i; - - addr = buf[0]; - n = buf[2] & 0x00FF; + int addr, n, i; + + addr = buf[0]; + n = buf[2] & 0x00FF; - for (i = 0; i < n; i++) { - if (addr >= MAXADDR) - bail("Program doesn't fit into 4K"); - mem[addr] = buf[9+i]; + for (i = 0; i < n; i++) { + if (addr >= MAXADDR) + bail("Program doesn't fit into 4K"); + mem[addr] = buf[9+i]; - load_low = MIN(addr, load_low); - load_high = MAX(addr, load_high); - addr++; - } + load_low = MIN(addr, load_low); + load_high = MAX(addr, load_high); + addr++; + } } void loaddata (char *fname) { - FILE *fp; - BOOL first = TRUE; - unsigned short card[80], buf[54], cardtype; + FILE *fp; + BOOL first = TRUE; + unsigned short card[80], buf[54], cardtype; - if ((fp = fopen(fname, "rb")) == NULL) { - perror(fname); - exit(1); - } + if ((fp = fopen(fname, "rb")) == NULL) { + perror(fname); + exit(1); + } - if (verbose) - printf("\n%s:\n", fname); + if (verbose) + printf("\n%s:\n", fname); - while (fxread(card, sizeof(card[0]), 80, fp) > 0) { - unpack(card, buf); - verify_checksum(card); + while (fxread(card, sizeof(card[0]), 80, fp) > 0) { + unpack(card, buf); + verify_checksum(card); - cardtype = (buf[2] >> 8) & 0xFF; + cardtype = (buf[2] >> 8) & 0xFF; - if (cardtype == 1 && ! first) { // sector break - if (verbose) - printf("*SBRK\n"); - continue; - } - else { - switch (cardtype) { - case 0x01: - if (verbose) - printf("*ABS\n"); - break; - case 0x02: - case 0x03: - case 0x04: - case 0x05: - case 0x06: - case 0x07: - bail("Data must be in absolute format"); - break; + if (cardtype == 1 && ! first) { // sector break + if (verbose) + printf("*SBRK\n"); + continue; + } + else { + switch (cardtype) { + case 0x01: + if (verbose) + printf("*ABS\n"); + break; + case 0x02: + case 0x03: + case 0x04: + case 0x05: + case 0x06: + case 0x07: + bail("Data must be in absolute format"); + break; - case 0x0F: - pta = buf[3]; // save program transfer address - if (verbose) - printf("*END\n"); - break; + case 0x0F: + pta = buf[3]; // save program transfer address + if (verbose) + printf("*END\n"); + break; - case 0x0A: - if (verbose) - show_data(buf); - loadcard(buf); - break; - default: - bail("Unexpected card type"); - } - } - first = FALSE; - } + case 0x0A: + if (verbose) + show_data(buf); + loadcard(buf); + break; + default: + bail("Unexpected card type"); + } + } + first = FALSE; + } - fclose(fp); + fclose(fp); } void bail (char *msg) { - fprintf(stderr, "%s\n", msg); - exit(1); + fprintf(stderr, "%s\n", msg); + exit(1); } void unpack (unsigned short *card, unsigned short *buf) { - int i, j; - unsigned short wd1, wd2, wd3, wd4; + int i, j; + unsigned short wd1, wd2, wd3, wd4; - for (i = j = 0; i < 54; i += 3, j += 4) { - wd1 = card[j]; - wd2 = card[j+1]; - wd3 = card[j+2]; - wd4 = card[j+3]; + for (i = j = 0; i < 54; i += 3, j += 4) { + wd1 = card[j]; + wd2 = card[j+1]; + wd3 = card[j+2]; + wd4 = card[j+3]; - buf[i ] = (wd1 & 0xFFF0) | ((wd2 >> 12) & 0x000F); - buf[i+1] = ((wd2 << 4) & 0xFF00) | ((wd3 >> 8) & 0x00FF); - buf[i+2] = ((wd3 << 8) & 0xF000) | ((wd4 >> 4) & 0x0FFF); - } + buf[i ] = (wd1 & 0xFFF0) | ((wd2 >> 12) & 0x000F); + buf[i+1] = ((wd2 << 4) & 0xFF00) | ((wd3 >> 8) & 0x00FF); + buf[i+2] = ((wd3 << 8) & 0xF000) | ((wd4 >> 4) & 0x0FFF); + } } void verify_checksum (unsigned short *card) { -// unsigned short sum; +// unsigned short sum; - if (card[1] == 0) // no checksum - return; + if (card[1] == 0) // no checksum + return; -// if (sum != card[1]) -// printf("Checksum %04x doesn't match card %04x\n", sum, card[1]); +// if (sum != card[1]) +// printf("Checksum %04x doesn't match card %04x\n", sum, card[1]); } typedef struct { - int hollerith; - char ascii; + int hollerith; + char ascii; } CPCODE; static CPCODE cardcode_029[] = { - 0x0000, ' ', - 0x8000, '&', // + in 026 Fortran - 0x4000, '-', - 0x2000, '0', - 0x1000, '1', - 0x0800, '2', - 0x0400, '3', - 0x0200, '4', - 0x0100, '5', - 0x0080, '6', - 0x0040, '7', - 0x0020, '8', - 0x0010, '9', - 0x9000, 'A', - 0x8800, 'B', - 0x8400, 'C', - 0x8200, 'D', - 0x8100, 'E', - 0x8080, 'F', - 0x8040, 'G', - 0x8020, 'H', - 0x8010, 'I', - 0x5000, 'J', - 0x4800, 'K', - 0x4400, 'L', - 0x4200, 'M', - 0x4100, 'N', - 0x4080, 'O', - 0x4040, 'P', - 0x4020, 'Q', - 0x4010, 'R', - 0x3000, '/', - 0x2800, 'S', - 0x2400, 'T', - 0x2200, 'U', - 0x2100, 'V', - 0x2080, 'W', - 0x2040, 'X', - 0x2020, 'Y', - 0x2010, 'Z', - 0x0820, ':', - 0x0420, '#', // = in 026 Fortran - 0x0220, '@', // ' in 026 Fortran - 0x0120, '\'', - 0x00A0, '=', - 0x0060, '"', - 0x8820, 'c', // cent - 0x8420, '.', - 0x8220, '<', // ) in 026 Fortran - 0x8120, '(', - 0x80A0, '+', - 0x8060, '|', - 0x4820, '!', - 0x4420, '$', - 0x4220, '*', - 0x4120, ')', - 0x40A0, ';', - 0x4060, 'n', // not - 0x2820, 'x', // what? - 0x2420, ',', - 0x2220, '%', // ( in 026 Fortran - 0x2120, '_', - 0x20A0, '>', - 0x2060, '>', + 0x0000, ' ', + 0x8000, '&', // + in 026 Fortran + 0x4000, '-', + 0x2000, '0', + 0x1000, '1', + 0x0800, '2', + 0x0400, '3', + 0x0200, '4', + 0x0100, '5', + 0x0080, '6', + 0x0040, '7', + 0x0020, '8', + 0x0010, '9', + 0x9000, 'A', + 0x8800, 'B', + 0x8400, 'C', + 0x8200, 'D', + 0x8100, 'E', + 0x8080, 'F', + 0x8040, 'G', + 0x8020, 'H', + 0x8010, 'I', + 0x5000, 'J', + 0x4800, 'K', + 0x4400, 'L', + 0x4200, 'M', + 0x4100, 'N', + 0x4080, 'O', + 0x4040, 'P', + 0x4020, 'Q', + 0x4010, 'R', + 0x3000, '/', + 0x2800, 'S', + 0x2400, 'T', + 0x2200, 'U', + 0x2100, 'V', + 0x2080, 'W', + 0x2040, 'X', + 0x2020, 'Y', + 0x2010, 'Z', + 0x0820, ':', + 0x0420, '#', // = in 026 Fortran + 0x0220, '@', // ' in 026 Fortran + 0x0120, '\'', + 0x00A0, '=', + 0x0060, '"', + 0x8820, 'c', // cent + 0x8420, '.', + 0x8220, '<', // ) in 026 Fortran + 0x8120, '(', + 0x80A0, '+', + 0x8060, '|', + 0x4820, '!', + 0x4420, '$', + 0x4220, '*', + 0x4120, ')', + 0x40A0, ';', + 0x4060, 'n', // not + 0x2820, 'x', // what? + 0x2420, ',', + 0x2220, '%', // ( in 026 Fortran + 0x2120, '_', + 0x20A0, '>', + 0x2060, '>', }; int ascii_to_hollerith (int ch) { - int i; + int i; - for (i = 0; i < sizeof(cardcode_029) / sizeof(CPCODE); i++) - if (cardcode_029[i].ascii == ch) - return cardcode_029[i].hollerith; + for (i = 0; i < sizeof(cardcode_029) / sizeof(CPCODE); i++) + if (cardcode_029[i].ascii == ch) + return cardcode_029[i].hollerith; - return 0; + return 0; } // --------------------------------------------------------------------------------- // corecard - routines to write IBM 1130 Card object format // --------------------------------------------------------------------------------- -unsigned short corecard[54]; // the 54 data words that can fit on a binary format card -int corecard_n = 0; // number of object words stored in corecard (0-45) -int corecard_seq = 1; // card output sequence number -int corecard_org = 0; // origin of current card-full +unsigned short corecard[54]; // the 54 data words that can fit on a binary format card +int corecard_n = 0; // number of object words stored in corecard (0-45) +int corecard_seq = 1; // card output sequence number +int corecard_org = 0; // origin of current card-full int corecard_maxaddr = 0; -BOOL corecard_first = TRUE; // TRUE when we're to write the program type card +BOOL corecard_first = TRUE; // TRUE when we're to write the program type card // corecard_init - prepare a new object data output card void corecard_init (void) { - memset(corecard, 0, sizeof(corecard)); // clear card data - corecard_n = 0; // no data - corecard[0] = corecard_org; // store load address - corecard_maxaddr = MAX(corecard_maxaddr, corecard_org-1); // save highest address written-to (this may be a BSS) + memset(corecard, 0, sizeof(corecard)); // clear card data + corecard_n = 0; // no data + corecard[0] = corecard_org; // store load address + corecard_maxaddr = MAX(corecard_maxaddr, corecard_org-1); // save highest address written-to (this may be a BSS) } // binard_writecard - emit a card. sbrk_text = NULL for normal data cards, points to comment text for sbrk card void corecard_writecard (char *sbrk_text) { - unsigned short binout[80]; - int i, j; + unsigned short binout[80]; + int i, j; - for (i = j = 0; i < 54; i += 3, j += 4) { - binout[j ] = ( corecard[i] & 0xFFF0); - binout[j+1] = ((corecard[i] << 12) & 0xF000) | ((corecard[i+1] >> 4) & 0x0FF0); - binout[j+2] = ((corecard[i+1] << 8) & 0xFF00) | ((corecard[i+2] >> 8) & 0x00F0); - binout[j+3] = ((corecard[i+2] << 4) & 0xFFF0); - } + for (i = j = 0; i < 54; i += 3, j += 4) { + binout[j ] = ( corecard[i] & 0xFFF0); + binout[j+1] = ((corecard[i] << 12) & 0xF000) | ((corecard[i+1] >> 4) & 0x0FF0); + binout[j+2] = ((corecard[i+1] << 8) & 0xFF00) | ((corecard[i+2] >> 8) & 0x00F0); + binout[j+3] = ((corecard[i+2] << 4) & 0xFFF0); + } - for (i = 0; i < 72; i++) { - putc(binout[i] & 0xFF, fout); - putc((binout[i] >> 8) & 0xFF, fout); - } + for (i = 0; i < 72; i++) { + putc(binout[i] & 0xFF, fout); + putc((binout[i] >> 8) & 0xFF, fout); + } - outcols = 72; // add the ident - flushcard(); + outcols = 72; // add the ident + flushcard(); } // binard_writedata - emit an object data card void corecard_writedata (void) { - corecard[1] = 0; // checksum - corecard[2] = 0x0000 | corecard_n; // data card type + word count - corecard_writecard(FALSE); // emit the card + corecard[1] = 0; // checksum + corecard[2] = 0x0000 | corecard_n; // data card type + word count + corecard_writecard(FALSE); // emit the card } // corecard_flush - flush any pending binary data void corecard_flush (void) { - if (corecard_n > 0) - corecard_writedata(); + if (corecard_n > 0) + corecard_writedata(); - corecard_init(); + corecard_init(); } // corecard_setorg - set the origin void corecard_setorg (int neworg) { - corecard_org = neworg; // set origin for next card - corecard_flush(); // flush any current data & store origin + corecard_org = neworg; // set origin for next card + corecard_flush(); // flush any current data & store origin } // corecard_writew - write a word to the current output card. void corecard_writew (int word, RELOC relative) { - if (corecard_n >= 50) // flush full card buffer (must be even) - corecard_flush(); + if (corecard_n >= 50) // flush full card buffer (must be even) + corecard_flush(); - corecard[3+corecard_n++] = word; - corecard_org++; + corecard[3+corecard_n++] = word; + corecard_org++; } // corecard_endcard - write end of program card void corecard_endcard (void) { - corecard_flush(); + corecard_flush(); - corecard[0] = 0; // effective length: add 1 to max origin, then 1 more to round up - corecard[1] = 0; - corecard[2] = 0x8000; // they look for negative bit but all else must be zero - corecard[52] = 0xabcd; // index register 3 value, this is for fun - corecard[53] = pta; // hmmm + corecard[0] = 0; // effective length: add 1 to max origin, then 1 more to round up + corecard[1] = 0; + corecard[2] = 0x8000; // they look for negative bit but all else must be zero + corecard[52] = 0xabcd; // index register 3 value, this is for fun + corecard[53] = pta; // hmmm - corecard_writecard(NULL); + corecard_writecard(NULL); } /* ------------------------------------------------------------------------ @@ -644,63 +644,63 @@ void corecard_endcard (void) char *upcase (char *str) { - char *s; + char *s; - for (s = str; *s; s++) { - if (*s >= 'a' && *s <= 'z') - *s -= 32; - } + for (s = str; *s; s++) { + if (*s >= 'a' && *s <= 'z') + *s -= 32; + } - return str; + return str; } #ifndef _WIN32 int strnicmp (char *a, char *b, int n) { - int ca, cb; + int ca, cb; - for (;;) { - if (--n < 0) // still equal after n characters? quit now - return 0; + for (;;) { + if (--n < 0) // still equal after n characters? quit now + return 0; - if ((ca = *a) == 0) // get character, stop on null terminator - return *b ? -1 : 0; + if ((ca = *a) == 0) // get character, stop on null terminator + return *b ? -1 : 0; - if (ca >= 'a' && ca <= 'z') // fold lowercase to uppercase - ca -= 32; + if (ca >= 'a' && ca <= 'z') // fold lowercase to uppercase + ca -= 32; - cb = *b; - if (cb >= 'a' && cb <= 'z') - cb -= 32; + cb = *b; + if (cb >= 'a' && cb <= 'z') + cb -= 32; - if ((ca -= cb) != 0) // if different, return comparison - return ca; + if ((ca -= cb) != 0) // if different, return comparison + return ca; - a++, b++; - } + a++, b++; + } } int strcmpi (char *a, char *b) { - int ca, cb; + int ca, cb; - for (;;) { - if ((ca = *a) == 0) // get character, stop on null terminator - return *b ? -1 : 0; + for (;;) { + if ((ca = *a) == 0) // get character, stop on null terminator + return *b ? -1 : 0; - if (ca >= 'a' && ca <= 'z') // fold lowercase to uppercase - ca -= 32; + if (ca >= 'a' && ca <= 'z') // fold lowercase to uppercase + ca -= 32; - cb = *b; - if (cb >= 'a' && cb <= 'z') - cb -= 32; + cb = *b; + if (cb >= 'a' && cb <= 'z') + cb -= 32; - if ((ca -= cb) != 0) // if different, return comparison - return ca; + if ((ca -= cb) != 0) // if different, return comparison + return ca; - a++, b++; - } + a++, b++; + } } #endif diff --git a/Ibm1130/utils/viewdeck.c b/Ibm1130/utils/viewdeck.c index 894d7aea..a58e7306 100644 --- a/Ibm1130/utils/viewdeck.c +++ b/Ibm1130/utils/viewdeck.c @@ -26,218 +26,218 @@ void format_coldstart (unsigned short *buf); int main (int argc, char **argv) { - FILE *fd; - char *fname = NULL, line[82], *arg; - BOOL coldstart = FALSE; - unsigned short buf[80]; - int i, lastnb; - static char usestr[] = - "Usage: viewdeck [-c] deckfile\n" - "\n" - "-c: convert cold start card to 16-bit format as a C array initializer\n"; + FILE *fd; + char *fname = NULL, line[82], *arg; + BOOL coldstart = FALSE; + unsigned short buf[80]; + int i, lastnb; + static char usestr[] = + "Usage: viewdeck [-c] deckfile\n" + "\n" + "-c: convert cold start card to 16-bit format as a C array initializer\n"; - for (i = 1; i < argc; i++) { // process command line arguments - arg = argv[i]; + for (i = 1; i < argc; i++) { // process command line arguments + arg = argv[i]; - if (*arg == '-') { - arg++; - while (*arg) { - switch (*arg++) { - case 'c': - coldstart = TRUE; - break; - default: - bail(usestr); - } - } - } - else if (fname == NULL) // first non-switch arg is file name - fname = arg; - else - bail(usestr); // there can be only one name - } + if (*arg == '-') { + arg++; + while (*arg) { + switch (*arg++) { + case 'c': + coldstart = TRUE; + break; + default: + bail(usestr); + } + } + } + else if (fname == NULL) // first non-switch arg is file name + fname = arg; + else + bail(usestr); // there can be only one name + } - if (fname == NULL) // there must be a name - bail(usestr); + if (fname == NULL) // there must be a name + bail(usestr); - if ((fd = fopen(fname, "rb")) == NULL) { - perror(fname); - return 1; - } + if ((fd = fopen(fname, "rb")) == NULL) { + perror(fname); + return 1; + } - while (fxread(buf, sizeof(short), 80, fd) == 80) { - if (coldstart) { - format_coldstart(buf); - break; - } + while (fxread(buf, sizeof(short), 80, fd) == 80) { + if (coldstart) { + format_coldstart(buf); + break; + } - lastnb = -1; - for (i = 0; i < 80; i++) { - line[i] = hollerith_to_ascii(buf[i]); - if (line[i] > ' ') - lastnb = i; - } - line[++lastnb] = '\n'; - line[++lastnb] = '\0'; - fputs(line, stdout); - } + lastnb = -1; + for (i = 0; i < 80; i++) { + line[i] = hollerith_to_ascii(buf[i]); + if (line[i] > ' ') + lastnb = i; + } + line[++lastnb] = '\n'; + line[++lastnb] = '\0'; + fputs(line, stdout); + } - if (coldstart) { - if (fxread(buf, sizeof(short), 1, fd) == 1) - bail("Coldstart deck has more than one card"); - } + if (coldstart) { + if (fxread(buf, sizeof(short), 1, fd) == 1) + bail("Coldstart deck has more than one card"); + } - fclose(fd); + fclose(fd); - return 0; + return 0; } void format_coldstart (unsigned short *buf) { - int i, nout = 0; - unsigned short word; + int i, nout = 0; + unsigned short word; - for (i = 0; i < 80; i++) { - word = buf[i]; // expand 12-bit card data to 16-bit instruction - word = (word & 0xF800) | ((word & 0x0400) ? 0x00C0 : 0x0000) | ((word & 0x03F0) >> 4); + for (i = 0; i < 80; i++) { + word = buf[i]; // expand 12-bit card data to 16-bit instruction + word = (word & 0xF800) | ((word & 0x0400) ? 0x00C0 : 0x0000) | ((word & 0x03F0) >> 4); - if (nout >= 8) { - fputs(",\n", stdout); - nout = 0; - } - else if (i > 0) - fputs(", ", stdout); + if (nout >= 8) { + fputs(",\n", stdout); + nout = 0; + } + else if (i > 0) + fputs(", ", stdout); - printf("0x%04x", word); - nout++; - } + printf("0x%04x", word); + nout++; + } - putchar('\n'); + putchar('\n'); } typedef struct { - unsigned short hollerith; - char ascii; + unsigned short hollerith; + char ascii; } CPCODE; static CPCODE cardcode_029[] = { - 0x0000, ' ', - 0x8000, '&', // + in 026 Fortran - 0x4000, '-', - 0x2000, '0', - 0x1000, '1', - 0x0800, '2', - 0x0400, '3', - 0x0200, '4', - 0x0100, '5', - 0x0080, '6', - 0x0040, '7', - 0x0020, '8', - 0x0010, '9', - 0x9000, 'A', - 0x8800, 'B', - 0x8400, 'C', - 0x8200, 'D', - 0x8100, 'E', - 0x8080, 'F', - 0x8040, 'G', - 0x8020, 'H', - 0x8010, 'I', - 0x5000, 'J', - 0x4800, 'K', - 0x4400, 'L', - 0x4200, 'M', - 0x4100, 'N', - 0x4080, 'O', - 0x4040, 'P', - 0x4020, 'Q', - 0x4010, 'R', - 0x3000, '/', - 0x2800, 'S', - 0x2400, 'T', - 0x2200, 'U', - 0x2100, 'V', - 0x2080, 'W', - 0x2040, 'X', - 0x2020, 'Y', - 0x2010, 'Z', - 0x0820, ':', - 0x0420, '#', // = in 026 Fortran - 0x0220, '@', // ' in 026 Fortran - 0x0120, '\'', - 0x00A0, '=', - 0x0060, '"', - 0x8820, '\xA2', // cent, in MS-DOS encoding - 0x8420, '.', - 0x8220, '<', // ) in 026 Fortran - 0x8120, '(', - 0x80A0, '+', - 0x8060, '|', - 0x4820, '!', - 0x4420, '$', - 0x4220, '*', - 0x4120, ')', - 0x40A0, ';', - 0x4060, '\xAC', // not, in MS-DOS encoding - 0x2420, ',', - 0x2220, '%', // ( in 026 Fortran - 0x2120, '_', - 0x20A0, '>', - 0xB000, 'a', - 0xA800, 'b', - 0xA400, 'c', - 0xA200, 'd', - 0xA100, 'e', - 0xA080, 'f', - 0xA040, 'g', - 0xA020, 'h', - 0xA010, 'i', - 0xD000, 'j', - 0xC800, 'k', - 0xC400, 'l', - 0xC200, 'm', - 0xC100, 'n', - 0xC080, 'o', - 0xC040, 'p', - 0xC020, 'q', - 0xC010, 'r', - 0x6800, 's', - 0x6400, 't', - 0x6200, 'u', - 0x6100, 'v', - 0x6080, 'w', - 0x6040, 'x', - 0x6020, 'y', - 0x6010, 'z', // these odd punch codes are used by APL: - 0x1010, '\001', // no corresponding ASCII using ^A - 0x0810, '\002', // SYN using ^B - 0x0410, '\003', // no corresponding ASCII using ^C - 0x0210, '\004', // PUNCH ON using ^D - 0x0110, '\005', // READER STOP using ^E - 0x0090, '\006', // UPPER CASE using ^F - 0x0050, '\013', // EOT using ^K - 0x0030, '\016', // no corresponding ASCII using ^N - 0x1030, '\017', // no corresponding ASCII using ^O - 0x0830, '\020', // no corresponding ASCII using ^P + 0x0000, ' ', + 0x8000, '&', // + in 026 Fortran + 0x4000, '-', + 0x2000, '0', + 0x1000, '1', + 0x0800, '2', + 0x0400, '3', + 0x0200, '4', + 0x0100, '5', + 0x0080, '6', + 0x0040, '7', + 0x0020, '8', + 0x0010, '9', + 0x9000, 'A', + 0x8800, 'B', + 0x8400, 'C', + 0x8200, 'D', + 0x8100, 'E', + 0x8080, 'F', + 0x8040, 'G', + 0x8020, 'H', + 0x8010, 'I', + 0x5000, 'J', + 0x4800, 'K', + 0x4400, 'L', + 0x4200, 'M', + 0x4100, 'N', + 0x4080, 'O', + 0x4040, 'P', + 0x4020, 'Q', + 0x4010, 'R', + 0x3000, '/', + 0x2800, 'S', + 0x2400, 'T', + 0x2200, 'U', + 0x2100, 'V', + 0x2080, 'W', + 0x2040, 'X', + 0x2020, 'Y', + 0x2010, 'Z', + 0x0820, ':', + 0x0420, '#', // = in 026 Fortran + 0x0220, '@', // ' in 026 Fortran + 0x0120, '\'', + 0x00A0, '=', + 0x0060, '"', + 0x8820, '\xA2', // cent, in MS-DOS encoding + 0x8420, '.', + 0x8220, '<', // ) in 026 Fortran + 0x8120, '(', + 0x80A0, '+', + 0x8060, '|', + 0x4820, '!', + 0x4420, '$', + 0x4220, '*', + 0x4120, ')', + 0x40A0, ';', + 0x4060, '\xAC', // not, in MS-DOS encoding + 0x2420, ',', + 0x2220, '%', // ( in 026 Fortran + 0x2120, '_', + 0x20A0, '>', + 0xB000, 'a', + 0xA800, 'b', + 0xA400, 'c', + 0xA200, 'd', + 0xA100, 'e', + 0xA080, 'f', + 0xA040, 'g', + 0xA020, 'h', + 0xA010, 'i', + 0xD000, 'j', + 0xC800, 'k', + 0xC400, 'l', + 0xC200, 'm', + 0xC100, 'n', + 0xC080, 'o', + 0xC040, 'p', + 0xC020, 'q', + 0xC010, 'r', + 0x6800, 's', + 0x6400, 't', + 0x6200, 'u', + 0x6100, 'v', + 0x6080, 'w', + 0x6040, 'x', + 0x6020, 'y', + 0x6010, 'z', // these odd punch codes are used by APL: + 0x1010, '\001', // no corresponding ASCII using ^A + 0x0810, '\002', // SYN using ^B + 0x0410, '\003', // no corresponding ASCII using ^C + 0x0210, '\004', // PUNCH ON using ^D + 0x0110, '\005', // READER STOP using ^E + 0x0090, '\006', // UPPER CASE using ^F + 0x0050, '\013', // EOT using ^K + 0x0030, '\016', // no corresponding ASCII using ^N + 0x1030, '\017', // no corresponding ASCII using ^O + 0x0830, '\020', // no corresponding ASCII using ^P }; int hollerith_to_ascii (unsigned short h) { - int i; + int i; - h &= 0xFFF0; + h &= 0xFFF0; - for (i = 0; i < sizeof(cardcode_029) / sizeof(CPCODE); i++) - if (cardcode_029[i].hollerith == h) - return cardcode_029[i].ascii; + for (i = 0; i < sizeof(cardcode_029) / sizeof(CPCODE); i++) + if (cardcode_029[i].hollerith == h) + return cardcode_029[i].ascii; - return '?'; + return '?'; } void bail (char *msg) { - fprintf(stderr, "%s\n", msg); - exit(1); + fprintf(stderr, "%s\n", msg); + exit(1); }