diff --git a/AltairZ80/altairz80_cpu.c b/AltairZ80/altairz80_cpu.c index 123c3ef8..2e3f078a 100644 --- a/AltairZ80/altairz80_cpu.c +++ b/AltairZ80/altairz80_cpu.c @@ -1,6 +1,6 @@ /* altairz80_cpu.c: MITS Altair CPU (8080 and Z80) - Copyright (c) 2002-2013, Peter Schorn + Copyright (c) 2002-2014, Peter Schorn Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), @@ -6508,7 +6508,8 @@ static t_stat cpu_show(FILE *st, UNIT *uptr, int32 val, void *desc) { static void cpu_clear(void) { uint32 i; - for (i = 0; i < MAXMEMORY; i++) M[i] = 0; + for (i = 0; i < MAXMEMORY; i++) + M[i] = 0; for (i = 0; i < (MAXMEMORY >> LOG2PAGESIZE); i++) mmu_table[i] = RAM_PAGE; for (i = (MEMORYSIZE >> LOG2PAGESIZE); i < (MAXMEMORY >> LOG2PAGESIZE); i++) @@ -6852,9 +6853,14 @@ static t_stat cpu_set_memory(UNIT *uptr, int32 value, char *cptr, void *desc) { return SCPE_ARG; } +t_value altairz80_pc_value (void) { + return (t_value)PCX; +} + /* AltairZ80 Simulator initialization */ void altairz80_init(void) { cpu_clear(); + sim_vm_pc_value = &altairz80_pc_value; /* altairz80_print_tables(); */ } diff --git a/AltairZ80/altairz80_cpu_nommu.c b/AltairZ80/altairz80_cpu_nommu.c index 460b5166..7e5be792 100644 --- a/AltairZ80/altairz80_cpu_nommu.c +++ b/AltairZ80/altairz80_cpu_nommu.c @@ -1,6 +1,6 @@ /* altairz80_cpu_opt.c: MITS Altair CPU (8080 and Z80) - Copyright (c) 2002-2013, Peter Schorn + Copyright (c) 2002-2014, Peter Schorn Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), diff --git a/AltairZ80/altairz80_defs.h b/AltairZ80/altairz80_defs.h index 3d92b492..ef229502 100644 --- a/AltairZ80/altairz80_defs.h +++ b/AltairZ80/altairz80_defs.h @@ -1,6 +1,6 @@ /* altairz80_defs.h: MITS Altair simulator definitions - Copyright (c) 2002-2013, Peter Schorn + Copyright (c) 2002-2014, Peter Schorn Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), diff --git a/AltairZ80/altairz80_doc.pdf b/AltairZ80/altairz80_doc.pdf index 3497e9b3..a6aa2d5e 100644 Binary files a/AltairZ80/altairz80_doc.pdf and b/AltairZ80/altairz80_doc.pdf differ diff --git a/AltairZ80/altairz80_dsk.c b/AltairZ80/altairz80_dsk.c index 1dcd3358..1fb93559 100644 --- a/AltairZ80/altairz80_dsk.c +++ b/AltairZ80/altairz80_dsk.c @@ -1,6 +1,6 @@ /* altairz80_dsk.c: MITS Altair 88-DISK Simulator - Copyright (c) 2002-2013, Peter Schorn + Copyright (c) 2002-2014, Peter Schorn Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), @@ -306,7 +306,9 @@ static t_stat dsk_reset(DEVICE *dptr) { } void install_ALTAIRbootROM(void) { - ASSURE(install_bootrom(bootrom_dsk, BOOTROM_SIZE_DSK, ALTAIR_ROM_LOW, TRUE) == SCPE_OK); + const t_bool result = (install_bootrom(bootrom_dsk, BOOTROM_SIZE_DSK, ALTAIR_ROM_LOW, TRUE) == + SCPE_OK); + assert(result); } /* The boot routine modifies the boot ROM in such a way that subsequently diff --git a/AltairZ80/altairz80_hdsk.c b/AltairZ80/altairz80_hdsk.c index e779752f..7fa0d749 100644 --- a/AltairZ80/altairz80_hdsk.c +++ b/AltairZ80/altairz80_hdsk.c @@ -1,6 +1,6 @@ /* altairz80_hdsk.c: simulated hard disk device to increase capacity - Copyright (c) 2002-2013, Peter Schorn + Copyright (c) 2002-2014, Peter Schorn Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), @@ -595,6 +595,7 @@ static int32 bootrom_hdsk[BOOTROM_SIZE_HDSK] = { }; static t_stat hdsk_boot(int32 unitno, DEVICE *dptr) { + t_bool installSuccessful; if (MEMORYSIZE < 24*KB) { printf("Need at least 24KB RAM to boot from hard disk.\n"); return SCPE_ARG; @@ -609,7 +610,9 @@ static t_stat hdsk_boot(int32 unitno, DEVICE *dptr) { } install_ALTAIRbootROM(); /* install modified ROM */ } - ASSURE(install_bootrom(bootrom_hdsk, BOOTROM_SIZE_HDSK, HDSK_BOOT_ADDRESS, FALSE) == SCPE_OK); + installSuccessful = (install_bootrom(bootrom_hdsk, BOOTROM_SIZE_HDSK, HDSK_BOOT_ADDRESS, + FALSE) == SCPE_OK); + assert(installSuccessful); *((int32 *) sim_PC -> loc) = HDSK_BOOT_ADDRESS; return SCPE_OK; } diff --git a/AltairZ80/altairz80_mhdsk.c b/AltairZ80/altairz80_mhdsk.c new file mode 100755 index 00000000..18eb1f84 --- /dev/null +++ b/AltairZ80/altairz80_mhdsk.c @@ -0,0 +1,453 @@ +/* altairz80_mhdsk.c: MITS 88-HDSK Hard Disk simulator + + Copyright (c) 2002-2014, Peter Schorn + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + PETER SCHORN BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + Except as contained in this notice, the name of Peter Schorn shall not + be used in advertising or otherwise to promote the sale, use or other dealings + in this Software without prior written authorization from Peter Schorn. + +------------------------------------------------------------------------------ + + The 88-HDSK from MITS/Pertec consists of a 5mb removable platter and + a fixed 5mb platter. Each platter is double sided. Head 0 and 1 are the + top and bottom surface of the removable platter and head 2 and 3 are the + top and bottom surface of the fixed platter. Hard disk BASIC treats the + two platters as two separate drives. Each platter has 406 cylinders + with 24 sectors per track and 256 bytes per sector. + + The disk image file starts with head 0, track 0, sector 0 (0,0,0) through + (0,0,23), followed by head 1, track 0, sector 0 (1,0,0) through (1,0,23). + The pattern then repeats starting with (0,1,0). + + The external hard disk is accessed through eight ports of a 4-PIO card + at I/O addresses A0h-A7h. + + Written by Mike Douglas March, 2014 + Disk images provided by Martin Eberhard + +------------------------------------------------------------------------------- +*/ +#include "altairz80_defs.h" +#include + +/** Typedefs & Defines **************************************/ +#define HDSK_SECTOR_SIZE 256 /* size of sector */ +#define HDSK_SECTORS_PER_TRACK 24 /* sectors per track */ +#define HDSK_NUM_HEADS 2 /* heads per disk */ +#define HDSK_NUM_TRACKS 406 /* tracks per surface */ +#define HDSK_TRACK_SIZE (HDSK_SECTOR_SIZE * HDSK_SECTORS_PER_TRACK) +#define HDSK_CYLINDER_SIZE (HDSK_TRACK_SIZE * 2) +#define HDSK_CAPACITY (HDSK_CYLINDER_SIZE * HDSK_NUM_TRACKS) +#define HDSK_NUMBER 8 /* number of hard disks */ +#define IO_IN 0 /* I/O operation is input */ +#define IO_OUT 1 /* I/O operation is output */ +#define UNIT_V_DSK_WLK (UNIT_V_UF + 0) /* write locked */ +#define UNIT_DSK_WLK (1 << UNIT_V_DSK_WLK) + +/* boot related */ +#define BOOTROM_SIZE_MHDSK 256 +#define MHDSK_BOOT_ADDRESS 0xfc00 +static t_stat mhdsk_boot(int32 unitno, DEVICE *dptr); +extern t_stat install_bootrom(int32 bootrom[], int32 size, int32 addr, int32 makeROM); + +// Disk controller commands are in upper nibble of command high byte. + +#define CMD_SHIFT 4 // shift right 4 places +#define CMD_MASK 0x0f // mask after shifting +#define CMD_SEEK 0 // seek to track +#define CMD_WRITE_SEC 2 // write sector from buf n +#define CMD_READ_SEC 3 // read sector into buf n +#define CMD_WRITE_BUF 4 // load buffer n from CPU +#define CMD_READ_BUF 5 // read buffer n into CPU +#define CMD_READ_STATUS 6 // read controller IV byte +#define CMD_SET_IV_BYTE 8 // set controller IV byte +#define CMD_READ_UNFMT 10 // read unformatted sector +#define CMD_FORMAT 12 +#define CMD_INITIALIZE 14 + +// Other disk controller bit fields + +#define UNIT_SHIFT 2 // shift right 2 places +#define UNIT_MASK 0x03 // mask after shifting + +#define BUFFER_MASK 0x03 // mask - no shift needed + +#define TRACK_SHIFTH 8 // shift left 8 places into MSbyte +#define TRACK_MASKH 0x01 // msb of track number +#define TRACK_MASKL 0xff // entire lsb of track number + +#define HEAD_SHIFT 5 // shift right 5 places +#define HEAD_MASK 0x03 // mask after shifting (no heads 4-7) + +#define SECTOR_MASK 0x1f // mask - no shift needed + +// Command status equates + +#define CSTAT_WRITE_PROTECT 0x80 // disk is write protected +#define CSTAT_NOT_READY 0x01 // drive not ready +#define CSTAT_BAD_SECTOR 0x02 // invalid sector number + + +/** Module Globals - Private ********************************/ +static uint32 selectedDisk = 0; // current active disk +static uint32 selectedSector = 0; // current sector +static uint32 selectedTrack = 0; // current track +static uint32 selectedHead = 0; // current head +static uint32 selectedBuffer = 0; // current buffer # in use +static uint32 bufferIdx = 0; // current index into selected buffer +static uint32 maxBufferIdx = 256; // maximum buffer index allowed +static uint32 cmdLowByte = 0; // low byte of command + +// Controller status bytes + +static uint8 cstat = 0; // command status from controller + +// The hard disk controller support four 256 byte disk buffers */ + +static uint8 diskBuf1[HDSK_SECTOR_SIZE]; +static uint8 diskBuf2[HDSK_SECTOR_SIZE]; +static uint8 diskBuf3[HDSK_SECTOR_SIZE]; +static uint8 diskBuf4[HDSK_SECTOR_SIZE]; +static uint8 *diskBuf[] = { diskBuf1, diskBuf2, diskBuf3, diskBuf4 }; + +/** Forward and external Prototypes **************************************/ + +static int32 hdReturnReady(const int32 port, const int32 io, const int32 data); +static int32 hdCstat(const int32 port, const int32 io, const int32 data); +static int32 hdAcmd(const int32 port, const int32 io, const int32 data); +static int32 hdCdata(const int32 port, const int32 io, const int32 data); +static int32 hdAdata(const int32 port, const int32 io, const int32 data); +static void doRead(void); +static void doWrite(void); +static t_stat dsk_reset(DEVICE *dptr); +extern uint32 sim_map_resource(uint32 baseaddr, uint32 size, uint32 resource_type, + int32 (*routine)(const int32, const int32, const int32), uint8 unmap); + +/* 88DSK Standard I/O Data Structures */ + +static UNIT dsk_unit[] = { + { UDATA (NULL, UNIT_FIX + UNIT_ATTABLE + UNIT_DISABLE + UNIT_ROABLE, HDSK_CAPACITY) }, + { UDATA (NULL, UNIT_FIX + UNIT_ATTABLE + UNIT_DISABLE + UNIT_ROABLE, HDSK_CAPACITY) }, + { UDATA (NULL, UNIT_FIX + UNIT_ATTABLE + UNIT_DISABLE + UNIT_ROABLE, HDSK_CAPACITY) }, + { UDATA (NULL, UNIT_FIX + UNIT_ATTABLE + UNIT_DISABLE + UNIT_ROABLE, HDSK_CAPACITY) }, + { UDATA (NULL, UNIT_FIX + UNIT_ATTABLE + UNIT_DISABLE + UNIT_ROABLE, HDSK_CAPACITY) }, + { UDATA (NULL, UNIT_FIX + UNIT_ATTABLE + UNIT_DISABLE + UNIT_ROABLE, HDSK_CAPACITY) }, + { UDATA (NULL, UNIT_FIX + UNIT_ATTABLE + UNIT_DISABLE + UNIT_ROABLE, HDSK_CAPACITY) }, + { UDATA (NULL, UNIT_FIX + UNIT_ATTABLE + UNIT_DISABLE + UNIT_ROABLE, HDSK_CAPACITY) }}; + +static MTAB dsk_mod[] = { + { UNIT_DSK_WLK, 0, "WRTENB", "WRTENB", NULL }, + { UNIT_DSK_WLK, UNIT_DSK_WLK, "WRTLCK", "WRTLCK", NULL }, + { 0 } +}; + +DEVICE mhdsk_dev = { + "MHDSK", dsk_unit, NULL, dsk_mod, + HDSK_NUMBER, 10, 31, 1, 8, 8, + NULL, NULL, &dsk_reset, + &mhdsk_boot, NULL, NULL, + NULL, (DEV_DISABLE | DEV_DEBUG), 0, + NULL, NULL, "MITS Hard Disk MHDSK" +}; + +static int32 bootrom_mhdsk[BOOTROM_SIZE_MHDSK] = { + 0xf3, 0x31, 0x00, 0xf8, 0x21, 0x1b, 0x41, 0x2b, /* fc00-fc07 */ + 0x7c, 0xb5, 0xc2, 0x07, 0xfc, 0xe5, 0xd3, 0xa0, /* fc08-fc0f */ + 0xd3, 0xa2, 0xd3, 0xa4, 0xd3, 0xa6, 0xd3, 0xa1, /* fc10-fc17 */ + 0xd3, 0xa5, 0x2f, 0xd3, 0xa3, 0xd3, 0xa7, 0x3e, /* fc18-fc1f */ + 0x2c, 0xd3, 0xa0, 0xd3, 0xa4, 0xd3, 0xa6, 0x3e, /* fc20-fc27 */ + 0x24, 0xd3, 0xa2, 0xdb, 0xa1, 0x3e, 0x03, 0xd3, /* fc28-fc2f */ + 0x10, 0x3e, 0x11, 0xd3, 0x10, 0xcd, 0xe5, 0xfc, /* fc30-fc37 */ + 0x0d, 0x0a, 0x48, 0x44, 0x42, 0x4c, 0x20, 0x31, /* fc38-fc3f */ + 0x2e, 0x30, 0xb1, 0xcd, 0x77, 0xfc, 0x11, 0x2c, /* fc40-fc47 */ + 0x00, 0x7a, 0xbb, 0xdb, 0xa5, 0xd2, 0x54, 0xfc, /* fc48-fc4f */ + 0x6c, 0x61, 0x48, 0x47, 0x14, 0xc2, 0x49, 0xfc, /* fc50-fc57 */ + 0xcd, 0xe5, 0xfc, 0x0d, 0x0a, 0x4c, 0x4f, 0x41, /* fc58-fc5f */ + 0x44, 0x49, 0x4e, 0xc7, 0xd1, 0xd5, 0xcd, 0x77, /* fc60-fc67 */ + 0xfc, 0xdb, 0xa5, 0x12, 0x13, 0x05, 0xc2, 0x69, /* fc68-fc6f */ + 0xfc, 0x23, 0x0d, 0xc2, 0x66, 0xfc, 0xc9, 0xe5, /* fc70-fc77 */ + 0xd5, 0xc5, 0x01, 0xd0, 0xff, 0x11, 0xff, 0xff, /* fc78-fc7f */ + 0x13, 0x09, 0xda, 0x80, 0xfc, 0x7d, 0xc6, 0x30, /* fc80-fc87 */ + 0xeb, 0xfe, 0x18, 0xda, 0x90, 0xfc, 0xc6, 0x08, /* fc88-fc8f */ + 0x47, 0xcd, 0xaf, 0xfc, 0x26, 0x30, 0xdb, 0xff, /* fc90-fc97 */ + 0xe6, 0x03, 0x0f, 0x0f, 0xb0, 0xcd, 0xb0, 0xfc, /* fc98-fc9f */ + 0xdb, 0xa5, 0xdb, 0xa3, 0xaf, 0xd3, 0xa7, 0x3e, /* fca0-fca7 */ + 0x50, 0xd3, 0xa3, 0xc1, 0xd1, 0xe1, 0xc9, 0x7d, /* fca8-fcaf */ + 0xd3, 0xa7, 0xdb, 0xa1, 0xdb, 0xa3, 0xdb, 0xff, /* fcb0-fcb7 */ + 0xe6, 0x00, 0xb4, 0xd3, 0xa3, 0xdb, 0xa0, 0x07, /* fcb8-fcbf */ + 0xd2, 0xbd, 0xfc, 0xdb, 0xa1, 0xe6, 0x7f, 0xc8, /* fcc0-fcc7 */ + 0xfb, 0xf5, 0xcd, 0xe5, 0xfc, 0x0d, 0x0a, 0x4c, /* fcc8-fccf */ + 0x4f, 0x41, 0x44, 0x20, 0x45, 0x52, 0x52, 0x4f, /* fcd0-fcd7 */ + 0x52, 0xba, 0x21, 0x00, 0xfd, 0x34, 0xca, 0xde, /* fcd8-fcdf */ + 0xfc, 0xe3, 0xc3, 0xcf, 0xfd, 0xe3, 0xdb, 0x10, /* fce0-fce7 */ + 0xe6, 0x02, 0xca, 0xe6, 0xfc, 0x7e, 0xe6, 0x7f, /* fce8-fcef */ + 0xd3, 0x11, 0xbe, 0x23, 0xca, 0xe6, 0xfc, 0xe3, /* fcf0-fcf7 */ + 0xc9, 0x70, 0x4a, 0x01, 0x00, 0xd4, 0xb4, 0x13, /* fcf8-fcff */ +}; + +static t_stat mhdsk_boot(int32 unitno, DEVICE *dptr) { + const t_bool installSuccessful = (install_bootrom(bootrom_mhdsk, BOOTROM_SIZE_MHDSK, + MHDSK_BOOT_ADDRESS, FALSE) == SCPE_OK); + assert(installSuccessful); + *((int32 *) sim_PC -> loc) = MHDSK_BOOT_ADDRESS; + return SCPE_OK; +} + +/*---------------------------------------------------------------------------------- + + dsk_reset - install I/O handlers and initialize variables. + + ----------------------------------------------------------------------------------*/ + +static t_stat dsk_reset(DEVICE *dptr) { + sim_map_resource(0xA0, 1, RESOURCE_TYPE_IO, &hdReturnReady, dptr->flags & DEV_DIS); + sim_map_resource(0xA1, 1, RESOURCE_TYPE_IO, &hdCstat, dptr->flags & DEV_DIS); + sim_map_resource(0xA2, 1, RESOURCE_TYPE_IO, &hdReturnReady, dptr->flags & DEV_DIS); + sim_map_resource(0xA3, 1, RESOURCE_TYPE_IO, &hdAcmd, dptr->flags & DEV_DIS); + sim_map_resource(0xA4, 1, RESOURCE_TYPE_IO, &hdReturnReady, dptr->flags & DEV_DIS); + sim_map_resource(0xA5, 1, RESOURCE_TYPE_IO, &hdCdata, dptr->flags & DEV_DIS); + sim_map_resource(0xA6, 1, RESOURCE_TYPE_IO, &hdReturnReady, dptr->flags & DEV_DIS); + sim_map_resource(0xA7, 1, RESOURCE_TYPE_IO, &hdAdata, dptr->flags & DEV_DIS); + + selectedSector = 0; // current sector + selectedTrack = 0; // current track + selectedHead = 0; // current head + selectedBuffer = 0; // current buffer # in use + bufferIdx = 0; // current index into selected buffer + maxBufferIdx = 256; // maximum buffer index allowed + cmdLowByte = 0; // low byte of command + + return SCPE_OK; +} + +/*------------------------------------------------------------------------------------- + hdReturnReady - common I/O handler for several hard disk status ports which set + bit 7 when the corresponding hard disk function is ready. In the emulator, + we're always ready for the next step, so we simply return ready all the time. + + 0xA0 - CREADY register. Accessed through the status/control register of 4-PIO + port 1-A. Returns the "ready for command" status byte. + + 0xA2 - ACSTA register. Accessed through the status/control register of 4-PIO + port 1-B. Returns the "command received" status byte. + + 0xA4 - CDSTA register. Accessed through the status/control register of 4-PIO + port 2-A. Returns the "command data available" status byte. + + 0xA6 - ADSTA register. Accessed through the status/control register of 4-PIO + port 2-B. Returns the "available to write" status byte. + +---------------------------------------------------------------------------------------*/ +static int32 hdReturnReady(const int32 port, const int32 io, const int32 data) +{ + return(0x80); // always indicate ready + +// output operations have no effect +} + +/*------------------------------------------------------------ + hdCstat (0xA1) CSTAT register. Accessed through the + data register of 4-PIO port 1-A. + + Comments: Returns error code byte of the most recent + operation. Reading this byte also clears + the CRDY bit, but this isn't actually done + in the emulation since we're always ready. +-------------------------------------------------------------*/ +static int32 hdCstat(const int32 port, const int32 io, const int32 data) +{ + return(cstat); + +// output operations have no effect +} + +/*------------------------------------------------------------ + hdAcmd (0xA3) ACMD register. Accessed through the + data register of 4-PIO port 1-B. + + Comments: The high byte of a command is written to + this register and initiates the command. + The low byte of a command is assumed to + have already been written and stored in + cmdLowByte; +-------------------------------------------------------------*/ +static int32 hdAcmd(const int32 port, const int32 io, const int32 data) +{ + uint32 command; // command field from command msb + uint32 unit; // unit number from command msb + uint32 buffer; // buffer number from command msb + +// if not an OUT command, exit + + if (io != IO_OUT) + return(0); + +// extract command and possible unit and buffer fields. + + cstat = 0; // assume command success + command = (data >> CMD_SHIFT) & CMD_MASK; + unit = (data >> UNIT_SHIFT) & UNIT_MASK; + buffer = data & BUFFER_MASK; + +// SEEK command. Updated selectedTrack. + + if (command == CMD_SEEK) { + selectedTrack = cmdLowByte + ((data & TRACK_MASKH) << TRACK_SHIFTH); + if (selectedTrack >= HDSK_NUM_TRACKS) + selectedTrack = HDSK_NUM_TRACKS-1; + } + +// READ, READ UNFORMATTED or WRITE SECTOR command. + + else if ((command==CMD_WRITE_SEC) || (command==CMD_READ_SEC) || (command==CMD_READ_UNFMT)) { + selectedHead = (cmdLowByte >> HEAD_SHIFT) & HEAD_MASK; + selectedDisk = (selectedHead >> 1) + unit * 2 ; + selectedSector = cmdLowByte & SECTOR_MASK; + selectedBuffer = buffer; + if (mhdsk_dev.units[selectedDisk].fileref == NULL) // make sure a file is attached + cstat = CSTAT_NOT_READY; + else { + if (command == CMD_WRITE_SEC) + doWrite(); + else + doRead(); + } + } + +// READ or WRITE BUFFER command. Initiates reading/loading specified buffer. + + else if ((command == CMD_WRITE_BUF) || (command == CMD_READ_BUF)) { + selectedBuffer = buffer; + maxBufferIdx = cmdLowByte; + if (maxBufferIdx == 0) + maxBufferIdx = 256; + bufferIdx = 0; + } + +// READ STATUS command (read IV byte) + + else if (command == CMD_READ_STATUS) { + } + +// SET IV byte command + + else if (command == CMD_SET_IV_BYTE) { + } + +// FORMAT command + + else if (command == CMD_FORMAT) { + } + +// INITIALIZE command + + else if (command == CMD_INITIALIZE) { + } + + return(0); +} + +/*------------------------------------------------------------ + hdCdata (0xA5) Cdata register. Accessed through the + data register of 4-PIO port 1-B. + + Comments: Returns data from the read buffer +-------------------------------------------------------------*/ +static int32 hdCdata(const int32 port, const int32 io, const int32 data) +{ + if (io == IO_IN) { + if (bufferIdx < maxBufferIdx) + return(diskBuf[selectedBuffer][bufferIdx++]); + } + return(0); + +// output operations have no effect +} + + +/*------------------------------------------------------------ + hdAdata (0xA7) ADATA register. Accessed through the + data register of 4-PIO port 2-B. + + Comments: Accepts data into the current buffer + and is also the low byte of a command. +-------------------------------------------------------------*/ +static int32 hdAdata(const int32 port, const int32 io, const int32 data) +{ + if (io == IO_OUT) { + cmdLowByte = data & 0xff; + if (bufferIdx < maxBufferIdx) + diskBuf[selectedBuffer][bufferIdx++] = data; + } + return(0); +} + +/*-- doRead ------------------------------------------------- + Performs read from MITS Hard Disk image file + + Params: nothing + Uses: selectedTrack, selectedHead, selectedSector + selectedDisk, diskBuf[], mhdsk_dev + Returns: nothing (updates cstat directly) + Comments: +-------------------------------------------------------------*/ +static void doRead(void) +{ + UNIT *uptr; + uint32 fileOffset; + + uptr = mhdsk_dev.units + selectedDisk; + fileOffset = HDSK_CYLINDER_SIZE * selectedTrack + + HDSK_TRACK_SIZE * (selectedHead & 0x01) + + HDSK_SECTOR_SIZE * selectedSector; + if (sim_fseek(uptr->fileref, fileOffset, SEEK_SET)) + cstat = CSTAT_NOT_READY; /* seek error */ + else if (sim_fread(diskBuf[selectedBuffer], 1, HDSK_SECTOR_SIZE, uptr->fileref) != HDSK_SECTOR_SIZE) + cstat = CSTAT_NOT_READY; /* write error */ +} + + +/*-- doWrite ------------------------------------------------ + Performs write to MITS Hard Disk image file + + Params: none + Uses: selectedTrack, selectedHead, selectedSector + selectedDisk, diskBuf[], mhdsk_dev + Returns: nothing (updates cstat directly) + Comments: +-------------------------------------------------------------*/ +static void doWrite(void) +{ + UNIT *uptr; + uint32 fileOffset; + + uptr = mhdsk_dev.units + selectedDisk; + if (((uptr->flags) & UNIT_DSK_WLK) == 0) { /* write enabled */ + fileOffset = HDSK_CYLINDER_SIZE * selectedTrack + + HDSK_TRACK_SIZE * (selectedHead & 0x01) + + HDSK_SECTOR_SIZE * selectedSector; + if (sim_fseek(uptr->fileref, fileOffset, SEEK_SET)) + cstat = CSTAT_NOT_READY; /* seek error */ + else if (sim_fwrite(diskBuf[selectedBuffer], 1, HDSK_SECTOR_SIZE, uptr->fileref) != HDSK_SECTOR_SIZE) + cstat = CSTAT_NOT_READY; /* write error */ + } + else + cstat = CSTAT_WRITE_PROTECT; +} diff --git a/AltairZ80/altairz80_net.c b/AltairZ80/altairz80_net.c index 9c1c4edd..fe5074be 100644 --- a/AltairZ80/altairz80_net.c +++ b/AltairZ80/altairz80_net.c @@ -1,6 +1,6 @@ /* altairz80_net.c: networking capability - Copyright (c) 2002-2013, Peter Schorn + Copyright (c) 2002-2014, Peter Schorn Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), diff --git a/AltairZ80/altairz80_sio.c b/AltairZ80/altairz80_sio.c index fbbe79a2..c864a14e 100644 --- a/AltairZ80/altairz80_sio.c +++ b/AltairZ80/altairz80_sio.c @@ -1,6 +1,6 @@ /* altairz80_sio.c: MITS Altair serial I/O card - Copyright (c) 2002-2013, Peter Schorn + Copyright (c) 2002-2014, Peter Schorn Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), diff --git a/AltairZ80/altairz80_sys.c b/AltairZ80/altairz80_sys.c index ced454b6..72f7038a 100644 --- a/AltairZ80/altairz80_sys.c +++ b/AltairZ80/altairz80_sys.c @@ -1,6 +1,6 @@ /* altairz80_sys.c: MITS Altair system interface - Copyright (c) 2002-2013, Peter Schorn + Copyright (c) 2002-2014, Peter Schorn Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), @@ -25,6 +25,8 @@ Based on work by Charles E Owen (c) 1997 Disassembler from Marat Fayzullin ((c) 1995, 1996, 1997 - Commercial use prohibited) + + 03/27/14 -- MWD Add MITS Hard Disk device (mhdsk_dev) */ #include @@ -40,6 +42,7 @@ extern DEVICE simh_device; extern DEVICE ptr_dev; extern DEVICE ptp_dev; extern DEVICE dsk_dev; +extern DEVICE mhdsk_dev; extern DEVICE hdsk_dev; extern DEVICE net_dev; @@ -100,7 +103,7 @@ int32 sim_emax = SIM_EMAX; DEVICE *sim_devices[] = { /* AltairZ80 Devices */ &cpu_dev, &sio_dev, &simh_device, &ptr_dev, &ptp_dev, &dsk_dev, - &hdsk_dev, &net_dev, + &mhdsk_dev, &hdsk_dev, &net_dev, /* Advanced Digital (ADC) Devices */ &adcs6_dev, &hdc1001_dev, @@ -360,6 +363,15 @@ void prepareInstructionMessage(const t_addr loc, const uint32 op) { (chiptype == CHIP_TYPE_Z80 ? MnemonicsZ80[op & 0xff] : "???"), loc); } +/* Ensure that hex number starts with a digit when printed */ +static void printHex2(char* string, const uint32 value) { + sprintf(string, (value <= 0x9f ? "%02X" : "%03X"), value); +} + +static void printHex4(char* string, const uint32 value) { + sprintf(string, (value <= 0x9fff ? "%04X" : "%05X"), value); +} + /* Symbolic disassembler Inputs: @@ -416,7 +428,7 @@ static int32 DAsm(char *S, const uint32 *val, const int32 useZ80Mnemonics, const if ( (P = strchr(T, '^')) ) { strncpy(R, T, P - T); R[P - T] = '\0'; - sprintf(H, "%02X", val[B++]); + printHex2(H, val[B++]); strcat(R, H); strcat(R, P + 1); } @@ -431,7 +443,7 @@ static int32 DAsm(char *S, const uint32 *val, const int32 useZ80Mnemonics, const if ( (P = strchr(R, '*')) ) { strncpy(S, R, P - R); S[P - R] = '\0'; - sprintf(H, "%02X", val[B++]); + printHex2(H, val[B++]); strcat(S, H); strcat(S, P + 1); } @@ -442,7 +454,7 @@ static int32 DAsm(char *S, const uint32 *val, const int32 useZ80Mnemonics, const Offset = val[B++]; strcat(S, Offset & 0x80 ? "-" : "+"); J = Offset & 0x80 ? 256 - Offset : Offset; - sprintf(H, "%02X", J); + printHex2(H, J); strcat(S, H); strcat(S, P + 1); } @@ -450,14 +462,14 @@ static int32 DAsm(char *S, const uint32 *val, const int32 useZ80Mnemonics, const strncpy(S, R, P - R); S[P - R] = '\0'; Offset = val[B++]; - sprintf(H, "%04X", (addr + 2 + (Offset & 0x80 ? (Offset - 256) : Offset)) & 0xFFFF); + printHex4(H, (addr + 2 + (Offset & 0x80 ? (Offset - 256) : Offset)) & 0xFFFF); strcat(S, H); strcat(S, P + 1); } else if ( (P = strchr(R, '#')) ) { strncpy(S, R, P - R); S[P - R] = '\0'; - sprintf(H, "%04X", val[B] + 256 * val[B + 1]); + printHex4(H, val[B] + 256 * val[B + 1]); strcat(S, H); strcat(S, P + 1); B += 2; diff --git a/AltairZ80/s100_fif.c b/AltairZ80/s100_fif.c index 9795e160..d6e2a309 100644 --- a/AltairZ80/s100_fif.c +++ b/AltairZ80/s100_fif.c @@ -2,7 +2,7 @@ IMSAI FIF Disk Controller by Ernie Price - Based on altairz80_dsk.c, Copyright (c) 2002-2013, Peter Schorn + Based on altairz80_dsk.c, Copyright (c) 2002-2014, Peter Schorn Plug-n-Play added by Howard M. Harte diff --git a/PDP10/pdp10_ksio.c b/PDP10/pdp10_ksio.c index 1737332b..bf0ce7ba 100644 --- a/PDP10/pdp10_ksio.c +++ b/PDP10/pdp10_ksio.c @@ -1548,11 +1548,8 @@ for (i = 0; (dptr = sim_devices[i]) != NULL; i++) { /* loop thru dev */ (curr->ba < (dibp->ba + dibp->lnt))) || ((end >= dibp->ba) && /* overlap end? */ (end < (dibp->ba + dibp->lnt)))) { - printf ("Device %s address conflict at %08o\n", - sim_dname (dptr), dibp->ba); - if (sim_log) - fprintf (sim_log, "Device %s address conflict at %08o\n", - sim_dname (dptr), dibp->ba); + sim_printf ("Device %s address conflict at %08o\n", + sim_dname (dptr), dibp->ba); return TRUE; } } diff --git a/PDP10/pdp10_sys.c b/PDP10/pdp10_sys.c index 8b6094d9..2aeaed21 100644 --- a/PDP10/pdp10_sys.c +++ b/PDP10/pdp10_sys.c @@ -383,7 +383,7 @@ switch (fmt) { /* case fmt */ return load_exe (fileref); } -printf ("Can't determine load file format\n"); +sim_printf ("Can't determine load file format\n"); return SCPE_FMT; } diff --git a/PDP11/pdp11_cpumod.c b/PDP11/pdp11_cpumod.c index 935d2fb5..80263765 100644 --- a/PDP11/pdp11_cpumod.c +++ b/PDP11/pdp11_cpumod.c @@ -1185,9 +1185,7 @@ for (i = 0; (dptr = sim_devices[i]) != NULL; i++) { if ((dptr->flags & DEV_DISABLE) && /* disable-able? */ !(dptr->flags & DEV_DIS) && /* enabled? */ ((dptr->flags & mask) == 0)) { /* not allowed? */ - printf ("Disabling %s\n", sim_dname (dptr)); - if (sim_log) - fprintf (sim_log, "Disabling %s\n", sim_dname (dptr)); + sim_printf ("Disabling %s\n", sim_dname (dptr)); dptr->flags = dptr->flags | DEV_DIS; } } diff --git a/PDP11/pdp11_ddcmp.h b/PDP11/pdp11_ddcmp.h index 96721b0a..39c0a79f 100644 --- a/PDP11/pdp11_ddcmp.h +++ b/PDP11/pdp11_ddcmp.h @@ -60,7 +60,7 @@ #define DDCMP_DBG_PXMT TMXR_DBG_PXMT /* Debug Transmitted Packet Header Contents */ #define DDCMP_DBG_PRCV TMXR_DBG_PRCV /* Debug Received Packet Header Contents */ -#define DDCMP_DBG_PDAT 0x1000000 /* Debug Packet Data */ +#define DDCMP_DBG_PDAT 0x4000000 /* Debug Packet Data */ /* Support routines */ diff --git a/PDP11/pdp11_dmc.c b/PDP11/pdp11_dmc.c index 653ed6b0..a2d39bef 100644 --- a/PDP11/pdp11_dmc.c +++ b/PDP11/pdp11_dmc.c @@ -1149,7 +1149,7 @@ DEVICE dmc_dev = #endif dmc_units, dmc_reg, dmc_mod, 3, DMC_RDX, 8, 1, DMC_RDX, 8, NULL, NULL, &dmc_reset, NULL, &dmc_attach, &dmc_detach, - &dmc_dib, DEV_DISABLE | DEV_DIS | DEV_UBUS | DEV_DEBUG, 0, dmc_debug, + &dmc_dib, DEV_DISABLE | DEV_DIS | DEV_UBUS | DEV_DEBUG | DEV_DONTAUTO, 0, dmc_debug, NULL, NULL, &dmc_help, &dmc_help_attach, NULL, &dmc_description }; /* @@ -1168,13 +1168,13 @@ DEVICE dmc_dev = DEVICE dmp_dev = { "DMP", dmp_units, dmp_reg, dmp_mod, 3, DMC_RDX, 8, 1, DMC_RDX, 8, NULL, NULL, &dmc_reset, NULL, &dmc_attach, &dmc_detach, - &dmp_dib, DEV_DISABLE | DEV_DIS | DEV_UBUS | DEV_DEBUG, 0, dmc_debug, + &dmp_dib, DEV_DISABLE | DEV_DIS | DEV_UBUS | DEV_DEBUG | DEV_DONTAUTO, 0, dmc_debug, NULL, NULL, &dmc_help, &dmc_help_attach, NULL, &dmp_description }; DEVICE dmv_dev = { "DMV", dmp_units, dmp_reg, dmv_mod, 3, DMC_RDX, 8, 1, DMC_RDX, 8, NULL, NULL, &dmc_reset, NULL, &dmc_attach, &dmc_detach, - &dmp_dib, DEV_DISABLE | DEV_DIS | DEV_QBUS | DEV_DEBUG, 0, dmc_debug, + &dmp_dib, DEV_DISABLE | DEV_DIS | DEV_QBUS | DEV_DEBUG | DEV_DONTAUTO, 0, dmc_debug, NULL, NULL, &dmc_help, &dmc_help_attach, NULL, &dmp_description }; CTLR dmc_ctrls[DMC_NUMDEVICE + DMP_NUMDEVICE]; @@ -1514,7 +1514,7 @@ controller->control_out_operations_completed = 0; controller->ddcmp_control_packets_received = 0; controller->ddcmp_control_packets_sent = 0; -printf("Statistics reset\n" ); +sim_printf("Statistics reset\n"); return SCPE_OK; } @@ -1585,6 +1585,7 @@ dptr->units[newln].ctlr = &dmc_ctrls[(dptr == &dmc_dev) ? 0 : DMC_NUMDEVICE]; dptr->units[newln+1] = dmc_timer_unit_template; dptr->units[newln+1].ctlr = &dmc_ctrls[(dptr == &dmc_dev) ? 0 : DMC_NUMDEVICE]; mp->lines = newln; +mp->uptr = dptr->units + newln; /* Identify polling unit */ return dmc_reset ((DEVICE *)desc); /* setup devices and auto config */ } @@ -2569,6 +2570,15 @@ if (!buffer) { dmc_showddcmp (sim_log, controller->unit, 0, NULL); fflush (sim_log); } + if (sim_deb) { + fprintf (sim_deb, "DDCMP Buffer allocation failure.\n"); + fprintf (sim_deb, "This is a fatal error which should never happen.\n"); + fprintf (sim_deb, "Please submit this output when you report this bug.\n"); + dmc_showqueues (sim_deb, controller->unit, 0, NULL); + dmc_showstats (sim_deb, controller->unit, 0, NULL); + dmc_showddcmp (sim_deb, controller->unit, 0, NULL); + fflush (sim_deb); + } return buffer; } buffer->address = 0; @@ -3676,6 +3686,8 @@ if (0 == dmc_units[0].flags) { /* First Time Initializations */ ans = auto_config (dptr->name, (dptr->flags & DEV_DIS) ? 0 : dptr->numunits - 2); if (!(dptr->flags & DEV_DIS)) { + int32 attached = 0; + for (i = 0; i < DMC_NUMDEVICE + DMP_NUMDEVICE; i++) { if (dmc_ctrls[i].device == dptr) { BUFFER *buffer; @@ -3709,12 +3721,16 @@ if (!(dptr->flags & DEV_DIS)) { dmc_buffer_queue_init_all(controller); dmc_clrinint(controller); dmc_clroutint(controller); - for (j=0; jnumunits-1; j++) + for (j=0; jnumunits-1; j++) { sim_cancel (&dptr->units[j]); /* stop poll */ + if (dptr->units[j].flags & UNIT_ATT) + ++attached; + } dmc_process_master_clear(controller); } } - sim_activate_after (dptr->units+dptr->numunits-2, DMC_CONNECT_POLL*1000000);/* start poll */ + if (attached) + sim_activate_after (dptr->units+(dptr->numunits-2), DMC_CONNECT_POLL*1000000);/* start poll */ } return ans; @@ -3735,9 +3751,7 @@ if (!cptr || !*cptr) if (!(uptr->flags & UNIT_ATTABLE)) return SCPE_NOATT; if (!peer[0]) { - printf ("Peer must be specified before attach\n"); - if (sim_log) - fprintf (sim_log, "Peer must be specified before attach\n"); + sim_printf ("Peer must be specified before attach\n"); return SCPE_ARG; } sprintf (attach_string, "Line=%d,Connect=%s,%s", dmc, peer, cptr); @@ -3748,7 +3762,7 @@ strncpy (port, cptr, CBUFSIZE-1); uptr->filename = (char *)malloc (strlen(port)+1); strcpy (uptr->filename, port); uptr->flags |= UNIT_ATT; -sim_activate_after (dptr->units+mp->lines, DMC_CONNECT_POLL*1000000);/* start poll */ +sim_activate_after (dptr->units+(dptr->numunits-2), DMC_CONNECT_POLL*1000000);/* start poll */ return ans; } @@ -3759,6 +3773,7 @@ int32 dmc = (int32)(uptr-dptr->units); TMXR *mp = (dptr == &dmc_dev) ? &dmc_desc : &dmp_desc; TMLN *lp = &mp->ldsc[dmc]; int32 i, attached; +t_stat r; if (!(uptr->flags & UNIT_ATT)) /* attached? */ return SCPE_OK; @@ -3767,11 +3782,14 @@ uptr->flags &= ~UNIT_ATT; for (i=attached=0; ilines; i++) if (dptr->units[i].flags & UNIT_ATT) ++attached; -if (!attached) +if (!attached) { sim_cancel (dptr->units+mp->lines); /* stop poll on last detach */ + sim_cancel (dptr->units+(mp->lines+1)); /* stop timer on last detach */ + } +r = tmxr_detach_ln (lp); free (uptr->filename); uptr->filename = NULL; -return tmxr_detach_ln (lp); +return r; } char *dmc_description (DEVICE *dptr) diff --git a/PDP11/pdp11_dup.c b/PDP11/pdp11_dup.c index 3aa22b90..673ddc05 100644 --- a/PDP11/pdp11_dup.c +++ b/PDP11/pdp11_dup.c @@ -414,7 +414,7 @@ static MTAB dup_mod[] = { #define DBG_PKT (TMXR_DBG_PXMT|TMXR_DBG_PRCV) /* display packets */ #define DBG_XMT TMXR_DBG_XMT /* display Transmitted Data */ #define DBG_RCV TMXR_DBG_RCV /* display Received Data */ -#define DBG_MDM 0x0004 /* display Modem SignalTransitions */ +#define DBG_MDM TMXR_DBG_MDM /* display Modem SignalTransitions */ #define DBG_CON TMXR_DBG_CON /* display connection activities */ #define DBG_TRC TMXR_DBG_TRC /* display trace routine calls */ #define DBG_ASY TMXR_DBG_ASY /* display Asynchronous Activities */ @@ -454,7 +454,7 @@ DEVICE dup_dev = { 2, 10, 31, 1, DEV_RDX, 8, NULL, NULL, &dup_reset, NULL, &dup_attach, &dup_detach, - &dup_dib, DEV_DIS | DEV_DISABLE | DEV_UBUS | DEV_DEBUG, 0, + &dup_dib, DEV_DIS | DEV_DISABLE | DEV_UBUS | DEV_DEBUG | DEV_DONTAUTO, 0, dup_debug, NULL, NULL, &dup_help, dup_help_attach, &dup_desc, &dup_description }; @@ -464,7 +464,7 @@ DEVICE dpv_dev = { 2, 10, 31, 1, DEV_RDX, 8, NULL, NULL, &dup_reset, NULL, &dup_attach, &dup_detach, - &dup_dib, DEV_DIS | DEV_DISABLE | DEV_QBUS | DEV_DEBUG, 0, + &dup_dib, DEV_DIS | DEV_DISABLE | DEV_QBUS | DEV_DEBUG | DEV_DONTAUTO, 0, dup_debug, NULL, NULL, &dup_help, dup_help_attach, &dup_desc, &dup_description }; @@ -1191,14 +1191,16 @@ return SCPE_OK; static t_stat dup_reset (DEVICE *dptr) { -int32 i, ndev; +t_stat r; +int32 i, ndev, attached = 0; sim_debug(DBG_TRC, dptr, "dup_reset()\n"); dup_desc.packet = TRUE; +dup_desc.buffered = 16384; if ((UNIBUS) && (dptr == &dpv_dev)) { if (!(dptr->flags & DEV_DIS)) { - printf ("Can't enable Qbus device on Unibus system\n"); + sim_printf ("Can't enable Qbus device on Unibus system\n"); dptr->flags |= DEV_DIS; return SCPE_ARG; } @@ -1207,7 +1209,7 @@ if ((UNIBUS) && (dptr == &dpv_dev)) { if ((!UNIBUS) && (dptr == &dup_dev)) { if (!(dptr->flags & DEV_DIS)) { - printf ("Can't enable Unibus device on Qbus system\n"); + sim_printf ("Can't enable Unibus device on Qbus system\n"); dptr->flags |= DEV_DIS; return SCPE_ARG; } @@ -1216,8 +1218,11 @@ if ((!UNIBUS) && (dptr == &dup_dev)) { if (dup_ldsc == NULL) { /* First time startup */ dup_desc.ldsc = dup_ldsc = (TMLN *)calloc (dup_desc.lines, sizeof(*dup_ldsc)); - for (i = 0; i < dup_desc.lines; i++) /* init each line */ + for (i = 0; i < dup_desc.lines; i++) { /* init each line */ dup_units[i] = dup_unit_template; + if (dup_units[i].flags & UNIT_ATT) + ++attached; + } dup_units[dup_desc.lines] = dup_poll_unit_template; /* Initialize to standard factory Option Jumper Settings */ for (i = 0; i < DUP_LINES; i++) { @@ -1226,8 +1231,11 @@ if (dup_ldsc == NULL) { /* First time startup */ dup_W6[i] = TRUE; } } -for (i = 0; i < dup_desc.lines; i++) /* init each line */ +for (i = 0; i < dup_desc.lines; i++) { /* init each line */ dup_clear (i, TRUE); + if (dup_units[i].flags & UNIT_ATT) + ++attached; + } dup_rxi = dup_txi = 0; /* clr master int */ CLR_INT (DUPRX); CLR_INT (DUPTX); @@ -1237,9 +1245,10 @@ dup_desc.dptr = DUPDPTR; /* Connect appropriate d dup_desc.uptr = dup_units+dup_desc.lines; /* Identify polling unit */ sim_cancel (dup_units+dup_desc.lines); /* stop poll */ ndev = ((dptr->flags & DEV_DIS)? 0: dup_desc.lines ); -if (ndev) - sim_activate_after (dup_units+dup_desc.lines, DUP_CONNECT_POLL*1000000); -return auto_config (dptr->name, ndev); /* auto config */ +r = auto_config (dptr->name, ndev); /* auto config */ +if ((r == SCPE_OK) && (attached)) + sim_activate_after (dup_units+dup_desc.lines, DUP_CONNECT_POLL*1000000);/* start poll */ +return r; } static t_stat dup_attach (UNIT *uptr, char *cptr) @@ -1253,7 +1262,7 @@ if (!cptr || !*cptr) return SCPE_ARG; if (!(uptr->flags & UNIT_ATTABLE)) return SCPE_NOATT; -sprintf (attach_string, "Line=%d,Buffered=16384,%s", dup, cptr); +sprintf (attach_string, "Line=%d,%s", dup, cptr); r = tmxr_open_master (&dup_desc, attach_string); /* open master socket */ free (uptr->filename); uptr->filename = tmxr_line_attach_string(&dup_desc.ldsc[dup]); @@ -1270,6 +1279,7 @@ DEVICE *dptr = DUPDPTR; int32 dup = (int32)(uptr-dptr->units); TMLN *lp = &dup_ldsc[dup]; int32 i, attached; +t_stat r; if (!(uptr->flags & UNIT_ATT)) /* attached? */ return SCPE_OK; @@ -1280,6 +1290,7 @@ for (i=attached=0; ifilename); uptr->filename = NULL; free (dup_rcvpacket[dup]); @@ -1290,7 +1301,7 @@ free (dup_xmtpacket[dup]); dup_xmtpacket[dup] = NULL; dup_xmtpksize[dup] = 0; dup_xmtpkoffset[dup] = 0; -return tmxr_detach_ln (lp); +return r; } /* SET/SHOW SPEED processor */ @@ -1450,6 +1461,7 @@ for (l=dup_desc.lines; l < newln; l++) { } dup_units[newln] = dup_poll_unit_template; dup_desc.lines = newln; +dup_desc.uptr = dptr->units + newln; /* Identify polling unit */ dptr->numunits = newln + 1; return dup_reset (dptr); /* setup lines and auto config */ } diff --git a/PDP11/pdp11_dz.c b/PDP11/pdp11_dz.c index c18d792f..6e7bb748 100644 --- a/PDP11/pdp11_dz.c +++ b/PDP11/pdp11_dz.c @@ -769,14 +769,10 @@ if (r != SCPE_OK) { /* error? */ } if (sim_switches & SWMASK ('M')) { /* modem control? */ dz_mctl = 1; - printf ("Modem control activated\n"); - if (sim_log) - fprintf (sim_log, "Modem control activated\n"); + sim_printf ("Modem control activated\n"); if (sim_switches & SWMASK ('A')) { /* autodisconnect? */ dz_auto = 1; - printf ("Auto disconnect activated\n"); - if (sim_log) - fprintf (sim_log, "Auto disconnect activated\n"); + sim_printf ("Auto disconnect activated\n"); } } diff --git a/PDP11/pdp11_io_lib.c b/PDP11/pdp11_io_lib.c index 0cbfce9d..665f23a9 100644 --- a/PDP11/pdp11_io_lib.c +++ b/PDP11/pdp11_io_lib.c @@ -313,16 +313,10 @@ if (vec && !(sim_switches & SWMASK ('P'))) { if (!cdname) { cdname = "CPU"; } - printf ("Device %s interrupt vector conflict with %s at ", - sim_dname (dptr), cdname); - fprint_val (stdout, (t_value) dibp->vec, DEV_RDX, 32, PV_LEFT); - printf ("\n"); - if (sim_log) { - fprintf (sim_log, "Device %s interrupt vector conflict with %s at ", - sim_dname (dptr), cdname); - fprint_val (sim_log, (t_value) dibp->vec, DEV_RDX, 32, PV_LEFT); - fprintf (sim_log, "\n"); - } + sim_printf ("Device %s interrupt vector conflict with %s at ", + sim_dname (dptr), cdname); + sim_print_val ((t_value) dibp->vec, DEV_RDX, 32, PV_LEFT); + sim_printf ("\n"); return SCPE_STOP; } } @@ -336,11 +330,8 @@ for (i = 0; i < dibp->vnum; i++) { /* loop thru vec */ (int_ack[ilvl][ibit] != dibp->ack[i])) || (int_vec[ilvl][ibit] && vec && (int_vec[ilvl][ibit] != vec))) { - printf ("Device %s interrupt slot conflict at %d\n", - sim_dname (dptr), idx); - if (sim_log) - fprintf (sim_log, "Device %s interrupt slot conflict at %d\n", - sim_dname (dptr), idx); + sim_printf ("Device %s interrupt slot conflict at %d\n", + sim_dname (dptr), idx); return SCPE_STOP; } if (dibp->ack[i]) @@ -373,15 +364,9 @@ for (i = 0; i < (int32) dibp->lnt; i = i + 2) { /* create entries */ if (!cdname) { cdname = "CPU"; } - printf ("Device %s address conflict with %s at ", sim_dname (dptr), cdname); - fprint_val (stdout, (t_value) dibp->ba, DEV_RDX, 32, PV_LEFT); - printf ("\n"); - if (sim_log) { - fprintf (sim_log, "Device %s address conflict with %s at ", sim_dname (dptr), - cdname); - fprint_val (sim_log, (t_value) dibp->ba, DEV_RDX, 32, PV_LEFT); - fprintf (sim_log, "\n"); - } + sim_printf ("Device %s address conflict with %s at ", sim_dname (dptr), cdname); + sim_print_val ((t_value) dibp->ba, DEV_RDX, 32, PV_LEFT); + sim_printf ("\n"); return SCPE_STOP; } if (dibp->rd) /* set rd dispatch */ @@ -812,9 +797,7 @@ for (autp = auto_tab; autp->numc >= 0; autp++) { /* loop thru table */ dptr->flags |= DEV_DIS; if (sim_switches & SWMASK ('P')) continue; - printf ("%s device not compatible with system bus\n", sim_dname(dptr)); - if (sim_log) - fprintf (sim_log, "%s device not compatible with system bus\n", sim_dname(dptr)); + sim_printf ("%s device not compatible with system bus\n", sim_dname(dptr)); return SCPE_NOFNC; } dibp = (DIB *) dptr->ctxt; /* get DIB */ diff --git a/PDP11/pdp11_pt.c b/PDP11/pdp11_pt.c index 1ad71e09..27a21201 100644 --- a/PDP11/pdp11_pt.c +++ b/PDP11/pdp11_pt.c @@ -242,7 +242,7 @@ if ((ptr_unit.flags & UNIT_ATT) == 0) if ((temp = getc (ptr_unit.fileref)) == EOF) { if (feof (ptr_unit.fileref)) { if (ptr_stopioe) - printf ("PTR end of file\n"); + sim_printf ("PTR end of file\n"); else return SCPE_OK; } else perror ("PTR I/O error"); diff --git a/PDP11/pdp11_rh.c b/PDP11/pdp11_rh.c index 2c8218a3..2bc094bf 100644 --- a/PDP11/pdp11_rh.c +++ b/PDP11/pdp11_rh.c @@ -908,11 +908,8 @@ if ((mbregR[idx] && dibp->rd && /* conflict? */ (mbregW[idx] != dibp->wr)) || (mbabort[idx] && dibp->ack[0] && (mbabort[idx] != dibp->ack[0]))) { - printf ("Massbus %s assignment conflict at %d\n", - sim_dname (dptr), dibp->ba); - if (sim_log) - fprintf (sim_log, "Massbus %s assignment conflict at %d\n", - sim_dname (dptr), dibp->ba); + sim_printf ("Massbus %s assignment conflict at %d\n", + sim_dname (dptr), dibp->ba); return SCPE_STOP; } if (dibp->rd) /* set rd dispatch */ diff --git a/PDP11/pdp11_tc.c b/PDP11/pdp11_tc.c index 46d00670..1672c4c4 100644 --- a/PDP11/pdp11_tc.c +++ b/PDP11/pdp11_tc.c @@ -1242,13 +1242,13 @@ if (uptr->filebuf == NULL) { /* can't alloc? */ return SCPE_MEM; } fbuf = (uint32 *) uptr->filebuf; /* file buffer */ -printf ("%s%d: ", sim_dname (&dt_dev), u); +sim_printf ("%s%d: ", sim_dname (&dt_dev), u); if (uptr->flags & UNIT_8FMT) - printf ("12b format"); + sim_printf ("12b format"); else if (uptr->flags & UNIT_11FMT) - printf ("16b format"); -else printf ("18b/36b format"); -printf (", buffering file in memory\n"); + sim_printf ("16b format"); +else sim_printf ("18b/36b format"); +sim_printf (", buffering file in memory\n"); uptr->io_flush = dt_flush; if (uptr->flags & UNIT_8FMT) { /* 12b? */ for (ba = 0; ba < uptr->capac; ) { /* loop thru file */ @@ -1356,7 +1356,7 @@ if (sim_is_active (uptr)) { /* active? cancel op */ uptr->STATE = uptr->pos = 0; } if (uptr->hwmark && ((uptr->flags & UNIT_RO) == 0)) { /* any data? */ - printf ("%s%d: writing buffer to file\n", sim_dname (&dt_dev), u); + sim_printf ("%s%d: writing buffer to file\n", sim_dname (&dt_dev), u); dt_flush (uptr); } /* end if hwmark */ free (uptr->filebuf); /* release buf */ diff --git a/PDP11/pdp11_xq.c b/PDP11/pdp11_xq.c index ff551b16..8d4ab2d7 100644 --- a/PDP11/pdp11_xq.c +++ b/PDP11/pdp11_xq.c @@ -2705,8 +2705,7 @@ t_stat xq_attach(UNIT* uptr, char* cptr) char buf[32]; eth_mac_fmt(&xq->var->mac, buf); /* format ethernet mac address */ - printf("%s: MAC Address Conflict on LAN for address %s, change the MAC address to a unique value\n", xq->dev->name, buf); - if (sim_log) fprintf (sim_log, "%s: MAC Address Conflict on LAN for address %s, change the MAC address to a unique value\n", xq->dev->name, buf); + sim_printf("%s: MAC Address Conflict on LAN for address %s, change the MAC address to a unique value\n", xq->dev->name, buf); eth_close(xq->var->etherface); free(tptr); free(xq->var->etherface); diff --git a/PDP11/pdp11_xu.c b/PDP11/pdp11_xu.c index 36e7161a..1d78b7bd 100644 --- a/PDP11/pdp11_xu.c +++ b/PDP11/pdp11_xu.c @@ -1078,7 +1078,7 @@ int32 xu_command(CTLR* xu) break; default: /* Unknown (unimplemented) command. */ - printf("%s: unknown ancilliary command 0%o requested !\n", xu->dev->name, fnc); + sim_printf("%s: unknown ancilliary command 0%o requested !\n", xu->dev->name, fnc); return PCSR0_PCEI; break; @@ -1497,8 +1497,7 @@ void xu_port_command (CTLR* xu) case CMD_BOOT: /* BOOT */ /* not implemented */ msg = "%s: BOOT command not implemented!\n"; - printf (msg, xu->dev->name); - if (sim_log) fprintf(sim_log, msg, xu->dev->name); + sim_printf (msg, xu->dev->name); xu->var->pcsr0 |= PCSR0_PCEI; break; @@ -1660,8 +1659,7 @@ t_stat xu_attach(UNIT* uptr, char* cptr) char buf[32]; eth_mac_fmt(&xu->var->mac, buf); /* format ethernet mac address */ - printf("%s: MAC Address Conflict on LAN for address %s\n", xu->dev->name, buf); - if (sim_log) fprintf (sim_log, "%s: MAC Address Conflict on LAN for address %s\n", xu->dev->name, buf); + sim_printf("%s: MAC Address Conflict on LAN for address %s\n", xu->dev->name, buf); eth_close(xu->var->etherface); free(tptr); free(xu->var->etherface); @@ -1760,7 +1758,7 @@ void xu_dump_rxring (CTLR* xu) { int i; int rrlen = xu->var->rrlen; - printf ("receive ring[%s]: base address: %08x headers: %d, header size: %d, current: %d\n", xu->dev->name, xu->var->rdrb, xu->var->rrlen, xu->var->relen, xu->var->rxnext); + sim_printf ("receive ring[%s]: base address: %08x headers: %d, header size: %d, current: %d\n", xu->dev->name, xu->var->rdrb, xu->var->rrlen, xu->var->relen, xu->var->rxnext); for (i=0; ivar->rdrb + (xu->var->relen * 2) * i; @@ -1769,7 +1767,7 @@ void xu_dump_rxring (CTLR* xu) int len = rxhdr[0]; uint32 addr = rxhdr[1] + ((rxhdr[2] & 3) << 16); if (rstatus == 0) - printf (" header[%d]: own:%d, len:%d, address:%08x data:{%04x,%04x,%04x,%04x}\n", i, own, len, addr, rxhdr[0], rxhdr[1], rxhdr[2], rxhdr[3]); + sim_printf (" header[%d]: own:%d, len:%d, address:%08x data:{%04x,%04x,%04x,%04x}\n", i, own, len, addr, rxhdr[0], rxhdr[1], rxhdr[2], rxhdr[3]); } } @@ -1777,7 +1775,7 @@ void xu_dump_txring (CTLR* xu) { int i; int trlen = xu->var->trlen; - printf ("transmit ring[%s]: base address: %08x headers: %d, header size: %d, current: %d\n", xu->dev->name, xu->var->tdrb, xu->var->trlen, xu->var->telen, xu->var->txnext); + sim_printf ("transmit ring[%s]: base address: %08x headers: %d, header size: %d, current: %d\n", xu->dev->name, xu->var->tdrb, xu->var->trlen, xu->var->telen, xu->var->txnext); for (i=0; ivar->tdrb + (xu->var->telen * 2) * i; @@ -1786,7 +1784,7 @@ void xu_dump_txring (CTLR* xu) int len = txhdr[0]; uint32 addr = txhdr[1] + ((txhdr[2] & 3) << 16); if (tstatus == 0) - printf (" header[%d]: own:%d, len:%d, address:%08x data:{%04x,%04x,%04x,%04x}\n", i, own, len, addr, txhdr[0], txhdr[1], txhdr[2], txhdr[3]); + sim_printf (" header[%d]: own:%d, len:%d, address:%08x data:{%04x,%04x,%04x,%04x}\n", i, own, len, addr, txhdr[0], txhdr[1], txhdr[2], txhdr[3]); } } diff --git a/PDP18B/pdp18b_cpu.c b/PDP18B/pdp18b_cpu.c index 20bcc2f2..3e2f0cd1 100644 --- a/PDP18B/pdp18b_cpu.c +++ b/PDP18B/pdp18b_cpu.c @@ -2259,11 +2259,8 @@ for (i = p = 0; (dptr = sim_devices[i]) != NULL; i++) { /* add devices * for (j = 0; j < dibp->num; j++) { /* loop thru disp */ if (dibp->dsp[j]) { /* any dispatch? */ if (dev_tab[dibp->dev + j]) { /* already filled? */ - printf ("%s device number conflict at %02o\n", - sim_dname (dptr), dibp->dev + j); - if (sim_log) - fprintf (sim_log, "%s device number conflict at %02o\n", - sim_dname (dptr), dibp->dev + j); + sim_printf ("%s device number conflict at %02o\n", + sim_dname (dptr), dibp->dev + j); return TRUE; } dev_tab[dibp->dev + j] = dibp->dsp[j]; /* fill */ diff --git a/PDP18B/pdp18b_dt.c b/PDP18B/pdp18b_dt.c index 09d920ba..cdea389c 100644 --- a/PDP18B/pdp18b_dt.c +++ b/PDP18B/pdp18b_dt.c @@ -1436,13 +1436,13 @@ if (uptr->filebuf == NULL) { /* can't alloc? */ return SCPE_MEM; } fbuf = (uint32 *) uptr->filebuf; /* file buffer */ -printf ("%s%d: ", sim_dname (&dt_dev), u); +sim_printf ("%s%d: ", sim_dname (&dt_dev), u); if (uptr->flags & UNIT_8FMT) - printf ("12b format"); + sim_printf ("12b format"); else if (uptr->flags & UNIT_11FMT) - printf ("16b format"); -else printf ("18b/36b format"); -printf (", buffering file in memory\n"); + sim_printf ("16b format"); +else sim_printf ("18b/36b format"); +sim_printf (", buffering file in memory\n"); uptr->io_flush = dt_flush; if (uptr->flags & UNIT_8FMT) { /* 12b? */ for (ba = 0; ba < uptr->capac; ) { /* loop thru file */ @@ -1548,7 +1548,7 @@ if (sim_is_active (uptr)) { uptr->STATE = uptr->pos = 0; } if (uptr->hwmark && ((uptr->flags & UNIT_RO) == 0)) { /* any data? */ - printf ("%s%d: writing buffer to file\n", sim_dname (&dt_dev), u); + sim_printf ("%s%d: writing buffer to file\n", sim_dname (&dt_dev), u); dt_flush (uptr); } /* end if hwmark */ free (uptr->filebuf); /* release buf */ diff --git a/PDP18B/pdp18b_stddev.c b/PDP18B/pdp18b_stddev.c index fd1959e3..4b202d31 100644 --- a/PDP18B/pdp18b_stddev.c +++ b/PDP18B/pdp18b_stddev.c @@ -573,7 +573,7 @@ if ((temp = getc (ptr_unit.fileref)) == EOF) { /* end of file? */ #endif if (feof (ptr_unit.fileref)) { if (ptr_stopioe) - printf ("PTR end of file\n"); + sim_printf ("PTR end of file\n"); else return SCPE_OK; } else perror ("PTR I/O error"); diff --git a/PDP8/pdp8_cpu.c b/PDP8/pdp8_cpu.c index 67b74fe7..cb4471c3 100644 --- a/PDP8/pdp8_cpu.c +++ b/PDP8/pdp8_cpu.c @@ -1499,12 +1499,9 @@ for (i = 0; (dptr = sim_devices[i]) != NULL; i++) { /* add devices */ for (j = 0; j < dibp->num; j++) { /* loop thru disp */ if (dibp->dsp[j]) { /* any dispatch? */ if (dev_tab[dibp->dev + j]) { /* already filled? */ - printf ("%s device number conflict at %02o\n", - sim_dname (dptr), dibp->dev + j); - if (sim_log) - fprintf (sim_log, "%s device number conflict at %02o\n", - sim_dname (dptr), dibp->dev + j); - return TRUE; + sim_printf ("%s device number conflict at %02o\n", + sim_dname (dptr), dibp->dev + j); + return TRUE; } dev_tab[dibp->dev + j] = dibp->dsp[j]; /* fill */ } /* end if dsp */ diff --git a/PDP8/pdp8_dt.c b/PDP8/pdp8_dt.c index 2c846655..f77840b2 100644 --- a/PDP8/pdp8_dt.c +++ b/PDP8/pdp8_dt.c @@ -1234,13 +1234,13 @@ if (uptr->filebuf == NULL) { /* can't alloc? */ return SCPE_MEM; } fbuf = (uint16 *) uptr->filebuf; /* file buffer */ -printf ("%s%d: ", sim_dname (&dt_dev), u); +sim_printf ("%s%d: ", sim_dname (&dt_dev), u); if (uptr->flags & UNIT_8FMT) - printf ("12b format"); + sim_printf ("12b format"); else if (uptr->flags & UNIT_11FMT) - printf ("16b format"); -else printf ("18b/36b format"); -printf (", buffering file in memory\n"); + sim_printf ("16b format"); +else sim_printf ("18b/36b format"); +sim_printf (", buffering file in memory\n"); uptr->io_flush = dt_flush; if (uptr->flags & UNIT_8FMT) /* 12b? */ uptr->hwmark = fxread (uptr->filebuf, sizeof (uint16), @@ -1332,7 +1332,7 @@ if (sim_is_active (uptr)) { uptr->STATE = uptr->pos = 0; } if (uptr->hwmark && ((uptr->flags & UNIT_RO)== 0)) { /* any data? */ - printf ("%s%d: writing buffer to file\n", sim_dname (&dt_dev), u); + sim_printf ("%s%d: writing buffer to file\n", sim_dname (&dt_dev), u); dt_flush (uptr); } /* end if hwmark */ free (uptr->filebuf); /* release buf */ diff --git a/PDP8/pdp8_sys.c b/PDP8/pdp8_sys.c index 3c0c9d95..ef308605 100644 --- a/PDP8/pdp8_sys.c +++ b/PDP8/pdp8_sys.c @@ -196,12 +196,14 @@ int32 sections_read = 0; for (;;) { csum = origin = field = newf = 0; /* init */ do { /* skip leader */ - if ((hi = sim_bin_getc (fi, &newf)) == EOF) + if ((hi = sim_bin_getc (fi, &newf)) == EOF) { if (sections_read != 0) { - printf ("%d sections sucessfully read\n\r", sections_read); + sim_printf ("%d sections sucessfully read\n\r", sections_read); return SCPE_OK; - } else + } + else return SCPE_FMT; + } } while ((hi == 0) || (hi >= 0200)); for (;;) { /* data blocks */ if ((lo = sim_bin_getc (fi, &newf)) == EOF) /* low char */ @@ -213,7 +215,7 @@ for (;;) { if (hi == 0200) { /* end of tape? */ if ((csum - wd) & 07777) { /* valid csum? */ if (sections_read != 0) - printf ("%d sections sucessfully read\n\r", sections_read); + sim_printf ("%d sections sucessfully read\n\r", sections_read); return SCPE_CSUM; } if (!(sim_switches & SWMASK ('A'))) /* Load all sections? */ diff --git a/SDS/sds_io.c b/SDS/sds_io.c index 9d6c0cac..d9f9fffc 100644 --- a/SDS/sds_io.c +++ b/SDS/sds_io.c @@ -982,11 +982,8 @@ for (i = 0; (dptr = sim_devices[i]); i++) { /* loop thru devices */ for (j = 0; j < tplp->num; j++) { /* repeat as needed */ doff = dev + tplp->off + j; /* get offset dnum */ if (dev_map[doff][ch]) { /* slot in use? */ - printf ("Device number conflict, chan = %s, devno = %02o\n", - chname[ch], doff); - if (sim_log) - fprintf (sim_log, "Device number conflict, chan = %s, dev = %02o\n", - chname[ch], doff); + sim_printf ("Device number conflict, chan = %s, devno = %02o\n", + chname[ch], doff); return TRUE; } dev_map[doff][ch] = dibp->xfr; /* set xfr flag */ diff --git a/SDS/sds_stddev.c b/SDS/sds_stddev.c index b35cbdbf..672ed363 100644 --- a/SDS/sds_stddev.c +++ b/SDS/sds_stddev.c @@ -278,7 +278,7 @@ if ((temp = getc (ptr_unit.fileref)) == EOF) { /* end of file? */ ptr_set_err (); /* yes, err, disc */ if (feof (ptr_unit.fileref)) { /* end of file? */ if (ptr_stopioe) - printf ("PTR end of file\n"); + sim_printf ("PTR end of file\n"); else return SCPE_OK; } else perror ("PTR I/O error"); /* I/O error */ diff --git a/VAX/vax610_sysdev.c b/VAX/vax610_sysdev.c index 2036f366..7c99025b 100644 --- a/VAX/vax610_sysdev.c +++ b/VAX/vax610_sysdev.c @@ -379,9 +379,7 @@ t_stat r; r = vax610_boot_parse (flag, ptr); /* parse the boot cmd */ if (r != SCPE_OK) { /* error? */ if (r >= SCPE_BASE) { /* message available? */ - printf ("%s\n", sim_error_text (r)); - if (sim_log) - fprintf (sim_log, "%s\n", sim_error_text (r)); + sim_printf ("%s\n", sim_error_text (r)); r |= SCPE_NOMESSAGE; } return r; @@ -504,9 +502,7 @@ if ((cpu_boot_cmd[0] == 0) || /* saved boot cmd? */ (reset_all (0) != SCPE_OK) || /* reset the world */ (cpu_boot (0, NULL) != SCPE_OK)) /* set up boot code */ ABORT (STOP_BOOT); /* any error? */ -printf ("Rebooting...\n"); -if (sim_log) - fprintf (sim_log, "Rebooting...\n"); +sim_printf ("Rebooting...\n"); return cc; } diff --git a/VAX/vax730_stddev.c b/VAX/vax730_stddev.c index fb3bedae..956000bd 100644 --- a/VAX/vax730_stddev.c +++ b/VAX/vax730_stddev.c @@ -489,7 +489,7 @@ switch (opcode) { case TD_OPDAT: if (td_state != TD_WRITE1) { /* expecting data? */ - printf("TU58 protocol error 1\n"); + sim_printf("TU58 protocol error 1\n"); return; } if (td_ibptr < 2) { /* whole packet read? */ @@ -502,7 +502,7 @@ switch (opcode) { case TD_OPCMD: if (td_state != TD_IDLE) { /* expecting command? */ - printf("TU58 protocol error 2\n"); + sim_printf("TU58 protocol error 2\n"); return; } if (td_ibptr < 2) { /* whole packet read? */ @@ -521,7 +521,7 @@ switch (opcode) { break; case TD_CMDINI: - printf("Warning: TU58 command 'INIT' not implemented\n"); + sim_printf("Warning: TU58 command 'INIT' not implemented\n"); break; case TD_CMDRD: @@ -543,11 +543,11 @@ switch (opcode) { break; case TD_CMDPOS: - printf("Warning: TU58 command 'Position' not implemented\n"); + sim_printf("Warning: TU58 command 'Position' not implemented\n"); break; case TD_CMDDIA: - printf("Warning: TU58 command 'Diagnose' not implemented\n"); + sim_printf("Warning: TU58 command 'Diagnose' not implemented\n"); break; case TD_CMDMRSP: /* MRSP supported? */ @@ -574,7 +574,7 @@ switch (opcode) { case TD_OPBOO: if (td_state != TD_IDLE) { - printf("TU58 protocol error 3\n"); + sim_printf("TU58 protocol error 3\n"); return; } if (td_ibptr < 2) { /* whole packet read? */ diff --git a/VAX/vax730_sys.c b/VAX/vax730_sys.c index 6454c477..0d641ba4 100644 --- a/VAX/vax730_sys.c +++ b/VAX/vax730_sys.c @@ -465,9 +465,7 @@ if ((cpu_boot_cmd[0] == 0) || /* saved boot cmd? */ (reset_all (0) != SCPE_OK) || /* reset the world */ (cpu_boot (0, NULL) != SCPE_OK)) /* set up boot code */ ABORT (STOP_BOOT); /* any error? */ -printf ("Rebooting...\n"); -if (sim_log) - fprintf (sim_log, "Rebooting...\n"); +sim_printf ("Rebooting...\n"); return cc; } @@ -485,9 +483,7 @@ t_stat r; r = vax730_boot_parse (flag, ptr); /* parse the boot cmd */ if (r != SCPE_OK) { /* error? */ if (r >= SCPE_BASE) { /* message available? */ - printf ("%s\n", sim_error_text (r)); - if (sim_log) - fprintf (sim_log, "%s\n", sim_error_text (r)); + sim_printf ("%s\n", sim_error_text (r)); r |= SCPE_NOMESSAGE; } return r; @@ -633,9 +629,7 @@ if ((nexusR[idx] && dibp->rd && /* conflict? */ (nexusR[idx] != dibp->rd)) || (nexusW[idx] && dibp->wr && (nexusW[idx] != dibp->wr))) { - printf ("Nexus %s conflict at %d\n", sim_dname (dptr), dibp->ba); - if (sim_log) - fprintf (sim_log, "Nexus %s conflict at %d\n", sim_dname (dptr), dibp->ba); + sim_printf ("Nexus %s conflict at %d\n", sim_dname (dptr), dibp->ba); return SCPE_STOP; } if (dibp->rd) /* set rd dispatch */ diff --git a/VAX/vax730_uba.c b/VAX/vax730_uba.c index e19563d7..72094503 100644 --- a/VAX/vax730_uba.c +++ b/VAX/vax730_uba.c @@ -192,7 +192,7 @@ t_stat uba_rdreg (int32 *val, int32 pa, int32 lnt) int32 idx, ofs; if ((pa & 3) || (lnt != L_LONG)) { /* unaligned or not lw? */ - printf (">>UBA: invalid adapter read mask, pa = %X, lnt = %d\r\n", pa, lnt); + sim_printf (">>UBA: invalid adapter read mask, pa = %X, lnt = %d\r\n", pa, lnt); // **FIXME** - Set error bit? return SCPE_OK; } @@ -243,7 +243,7 @@ t_stat uba_wrreg (int32 val, int32 pa, int32 lnt) int32 idx, ofs; if ((pa & 3) || (lnt != L_LONG)) { /* unaligned or not lw? */ - printf (">>UBA: invalid adapter write mask, pa = %X, lnt = %d\r\n", pa, lnt); + sim_printf (">>UBA: invalid adapter write mask, pa = %X, lnt = %d\r\n", pa, lnt); // **FIXME** - Set error bit? return SCPE_OK; } @@ -335,7 +335,7 @@ if ((lnt == L_BYTE) || /* byte? */ iod = iod << 16; } else { - printf (">>UBA: invalid read mask, pa = %x, lnt = %d\n", pa, lnt); + sim_printf (">>UBA: invalid read mask, pa = %x, lnt = %d\n", pa, lnt); // **FIXME** - Set error bit? iod = 0; } @@ -360,7 +360,7 @@ if (lnt == L_BYTE) /* byte? DATOB */ else if ((lnt == L_WORD) && ((pa & 1) == 0)) /* aligned word? */ WriteUb (pa, val, WRITE); /* DATO */ else { - printf (">>UBA: invalid write mask, pa = %x, lnt = %d\n", pa, lnt); + sim_printf (">>UBA: invalid write mask, pa = %x, lnt = %d\n", pa, lnt); // **FIXME** - Set error bit? } SET_IRQL; /* update ints */ diff --git a/VAX/vax750_cmi.c b/VAX/vax750_cmi.c index 91e460bd..2251b0a2 100644 --- a/VAX/vax750_cmi.c +++ b/VAX/vax750_cmi.c @@ -549,9 +549,7 @@ if ((cpu_boot_cmd[0] == 0) || /* saved boot cmd? */ (reset_all (0) != SCPE_OK) || /* reset the world */ (cpu_boot (0, NULL) != SCPE_OK)) /* set up boot code */ ABORT (STOP_BOOT); /* any error? */ -printf ("Rebooting...\n"); -if (sim_log) - fprintf (sim_log, "Rebooting...\n"); +sim_printf ("Rebooting...\n"); return cc; } @@ -569,9 +567,7 @@ t_stat r; r = vax750_boot_parse (flag, ptr); /* parse the boot cmd */ if (r != SCPE_OK) { /* error? */ if (r >= SCPE_BASE) { /* message available? */ - printf ("%s\n", sim_error_text (r)); - if (sim_log) - fprintf (sim_log, "%s\n", sim_error_text (r)); + sim_printf ("%s\n", sim_error_text (r)); r |= SCPE_NOMESSAGE; } return r; @@ -720,9 +716,7 @@ if ((nexusR[idx] && dibp->rd && /* conflict? */ (nexusR[idx] != dibp->rd)) || (nexusW[idx] && dibp->wr && (nexusW[idx] != dibp->wr))) { - printf ("Nexus %s conflict at %d\n", sim_dname (dptr), dibp->ba); - if (sim_log) - fprintf (sim_log, "Nexus %s conflict at %d\n", sim_dname (dptr), dibp->ba); + sim_printf ("Nexus %s conflict at %d\n", sim_dname (dptr), dibp->ba); return SCPE_STOP; } if (dibp->rd) /* set rd dispatch */ diff --git a/VAX/vax750_stddev.c b/VAX/vax750_stddev.c index bddb2a5a..5be2a8bf 100644 --- a/VAX/vax750_stddev.c +++ b/VAX/vax750_stddev.c @@ -487,7 +487,7 @@ switch (opcode) { case TD_OPDAT: if (td_state != TD_WRITE1) { /* expecting data? */ - printf("TU58 protocol error 1\n"); + sim_printf("TU58 protocol error 1\n"); return; } if (td_ibptr < 2) { /* whole packet read? */ @@ -500,7 +500,7 @@ switch (opcode) { case TD_OPCMD: if (td_state != TD_IDLE) { /* expecting command? */ - printf("TU58 protocol error 2\n"); + sim_printf("TU58 protocol error 2\n"); return; } if (td_ibptr < 2) { /* whole packet read? */ @@ -518,7 +518,7 @@ switch (opcode) { break; case TD_CMDINI: - printf("Warning: TU58 command 'INIT' not implemented\n"); + sim_printf("Warning: TU58 command 'INIT' not implemented\n"); break; case TD_CMDRD: @@ -538,11 +538,11 @@ switch (opcode) { break; case TD_CMDPOS: - printf("Warning: TU58 command 'Position' not implemented\n"); + sim_printf("Warning: TU58 command 'Position' not implemented\n"); break; case TD_CMDDIA: - printf("Warning: TU58 command 'Diagnose' not implemented\n"); + sim_printf("Warning: TU58 command 'Diagnose' not implemented\n"); break; case TD_CMDMRSP: @@ -568,7 +568,7 @@ switch (opcode) { case TD_OPBOO: if (td_state != TD_IDLE) { - printf("TU58 protocol error 3\n"); + sim_printf("TU58 protocol error 3\n"); return; } if (td_ibptr < 2) { /* whole packet read? */ diff --git a/VAX/vax750_uba.c b/VAX/vax750_uba.c index 17b4fe11..a6225bd1 100644 --- a/VAX/vax750_uba.c +++ b/VAX/vax750_uba.c @@ -193,7 +193,7 @@ t_stat uba_rdreg (int32 *val, int32 pa, int32 lnt) int32 idx, ofs; if ((pa & 3) || (lnt != L_LONG)) { /* unaligned or not lw? */ - printf (">>UBA: invalid adapter read mask, pa = %X, lnt = %d\r\n", pa, lnt); + sim_printf (">>UBA: invalid adapter read mask, pa = %X, lnt = %d\r\n", pa, lnt); /* FIXME: set appropriate error bits */ return SCPE_OK; } @@ -242,7 +242,7 @@ t_stat uba_wrreg (int32 val, int32 pa, int32 lnt) int32 idx, ofs; if ((pa & 3) || (lnt != L_LONG)) { /* unaligned or not lw? */ - printf (">>UBA: invalid adapter write mask, pa = %X, lnt = %d\r\n", pa, lnt); + sim_printf (">>UBA: invalid adapter write mask, pa = %X, lnt = %d\r\n", pa, lnt); /* FIXME: set appropriate error bits */ return SCPE_OK; } @@ -339,7 +339,7 @@ if ((lnt == L_BYTE) || /* byte? */ iod = iod << 16; } else { - printf (">>UBA: invalid read mask, pa = %x, lnt = %d\n", pa, lnt); + sim_printf (">>UBA: invalid read mask, pa = %x, lnt = %d\n", pa, lnt); /* FIXME: set appropriate error bits */ iod = 0; } @@ -364,7 +364,7 @@ if (lnt == L_BYTE) /* byte? DATOB */ else if ((lnt == L_WORD) && ((pa & 1) == 0)) /* aligned word? */ WriteUb (pa, val, WRITE); /* DATO */ else { - printf (">>UBA: invalid write mask, pa = %x, lnt = %d\n", pa, lnt); + sim_printf (">>UBA: invalid write mask, pa = %x, lnt = %d\n", pa, lnt); /* FIXME: set appropriate error bits */ } SET_IRQL; /* update ints */ diff --git a/VAX/vax780_mem.c b/VAX/vax780_mem.c index a79d999f..2ef245ab 100644 --- a/VAX/vax780_mem.c +++ b/VAX/vax780_mem.c @@ -168,7 +168,7 @@ int32 mctl, ofs; t_bool extmem = MEMSIZE > MAXMEMSIZE; if ((pa & 3) || (lnt != L_LONG)) { /* unaligned or not lw? */ - printf (">>MCTL: invalid adapter read mask, pa = %X, lnt = %d\r\n", pa, lnt); + sim_printf (">>MCTL: invalid adapter read mask, pa = %X, lnt = %d\r\n", pa, lnt); sbi_set_errcnf (); /* err confirmation */ return SCPE_OK; } @@ -213,7 +213,7 @@ int32 mctl, ofs, mask; t_bool extmem = MEMSIZE > MAXMEMSIZE; if ((pa & 3) || (lnt != L_LONG)) { /* unaligned or not lw? */ - printf (">>MCTL: invalid adapter write mask, pa = %X, lnt = %d\r\n", pa, lnt); + sim_printf (">>MCTL: invalid adapter write mask, pa = %X, lnt = %d\r\n", pa, lnt); sbi_set_errcnf (); /* err confirmation */ return SCPE_OK; } diff --git a/VAX/vax780_sbi.c b/VAX/vax780_sbi.c index ac554d5b..02e56bb4 100644 --- a/VAX/vax780_sbi.c +++ b/VAX/vax780_sbi.c @@ -615,9 +615,7 @@ if ((cpu_boot_cmd[0] == 0) || /* saved boot cmd? */ (reset_all (0) != SCPE_OK) || /* reset the world */ (cpu_boot (0, NULL) != SCPE_OK)) /* set up boot code */ ABORT (STOP_BOOT); /* any error? */ -printf ("Rebooting...\n"); -if (sim_log) - fprintf (sim_log, "Rebooting...\n"); +sim_printf ("Rebooting...\n"); return cc; } @@ -635,9 +633,7 @@ t_stat r; r = vax780_boot_parse (flag, ptr); /* parse the boot cmd */ if (r != SCPE_OK) { /* error? */ if (r >= SCPE_BASE) { /* message available? */ - printf ("%s\n", sim_error_text (r)); - if (sim_log) - fprintf (sim_log, "%s\n", sim_error_text (r)); + sim_printf ("%s\n", sim_error_text (r)); r |= SCPE_NOMESSAGE; } return r; @@ -792,9 +788,7 @@ if ((nexusR[idx] && dibp->rd && /* conflict? */ (nexusR[idx] != dibp->rd)) || (nexusW[idx] && dibp->wr && (nexusW[idx] != dibp->wr))) { - printf ("Nexus %s conflict at %d\n", sim_dname (dptr), dibp->ba); - if (sim_log) - fprintf (sim_log, "Nexus %s conflict at %d\n", sim_dname (dptr), dibp->ba); + sim_printf ("Nexus %s conflict at %d\n", sim_dname (dptr), dibp->ba); return SCPE_STOP; } if (dibp->rd) /* set rd dispatch */ diff --git a/VAX/vax780_uba.c b/VAX/vax780_uba.c index 3b78a057..dbbe8797 100644 --- a/VAX/vax780_uba.c +++ b/VAX/vax780_uba.c @@ -304,7 +304,7 @@ t_stat uba_rdreg (int32 *val, int32 pa, int32 lnt) int32 idx, ofs; if ((pa & 3) || (lnt != L_LONG)) { /* unaligned or not lw? */ - printf (">>UBA: invalid adapter read mask, pa = %X, lnt = %d\r\n", pa, lnt); + sim_printf (">>UBA: invalid adapter read mask, pa = %X, lnt = %d\r\n", pa, lnt); sbi_set_errcnf (); /* err confirmation */ return SCPE_OK; } @@ -393,7 +393,7 @@ t_stat uba_wrreg (int32 val, int32 pa, int32 lnt) int32 idx, ofs, old_cr; if ((pa & 3) || (lnt != L_LONG)) { /* unaligned or not lw? */ - printf (">>UBA: invalid adapter write mask, pa = %X, lnt = %d\r\n", pa, lnt); + sim_printf (">>UBA: invalid adapter write mask, pa = %X, lnt = %d\r\n", pa, lnt); sbi_set_errcnf (); /* err confirmation */ return SCPE_OK; } @@ -526,7 +526,7 @@ if ((lnt == L_BYTE) || /* byte? */ iod = iod << 16; } else { - printf (">>UBA: invalid read mask, pa = %x, lnt = %d\n", pa, lnt); + sim_printf (">>UBA: invalid read mask, pa = %x, lnt = %d\n", pa, lnt); sbi_set_errcnf (); /* err confirmation */ iod = 0; } @@ -551,7 +551,7 @@ if (lnt == L_BYTE) /* byte? DATOB */ else if ((lnt == L_WORD) && ((pa & 1) == 0)) /* aligned word? */ WriteUb (pa, val, WRITE); /* DATO */ else { - printf (">>UBA: invalid write mask, pa = %x, lnt = %d\n", pa, lnt); + sim_printf (">>UBA: invalid write mask, pa = %x, lnt = %d\n", pa, lnt); sbi_set_errcnf (); /* err confirmation */ } SET_IRQL; /* update ints */ diff --git a/VAX/vax7x0_mba.c b/VAX/vax7x0_mba.c index 0bc4d493..f52d11b1 100644 --- a/VAX/vax7x0_mba.c +++ b/VAX/vax7x0_mba.c @@ -366,7 +366,7 @@ t_stat r; mb = NEXUS_GETNEX (pa) - TR_MBA0; /* get MBA */ if ((pa & 3) || (lnt != L_LONG)) { /* unaligned or not lw? */ - printf (">>MBA%d: invalid adapter read mask, pa = 0x%X, lnt = %d\r\n", mb, pa, lnt); + sim_printf (">>MBA%d: invalid adapter read mask, pa = 0x%X, lnt = %d\r\n", mb, pa, lnt); #if defined(VAX_780) sbi_set_errcnf (); /* err confirmation */ #endif @@ -460,7 +460,7 @@ t_bool cs1dt; mb = NEXUS_GETNEX (pa) - TR_MBA0; /* get MBA */ if ((pa & 3) || (lnt != L_LONG)) { /* unaligned or not lw? */ - printf (">>MBA%d: invalid adapter write mask, pa = 0x%X, lnt = %d\r\n", mb, pa, lnt); + sim_printf (">>MBA%d: invalid adapter write mask, pa = 0x%X, lnt = %d\r\n", mb, pa, lnt); #if defined(VAX_780) sbi_set_errcnf (); /* err confirmation */ #endif @@ -935,11 +935,8 @@ if ((mbregR[idx] && dibp->rd && /* conflict? */ (mbregW[idx] != dibp->wr)) || (mbabort[idx] && dibp->ack[0] && (mbabort[idx] != dibp->ack[0]))) { - printf ("Massbus %s assignment conflict at %d\n", - sim_dname (dptr), dibp->ba); - if (sim_log) - fprintf (sim_log, "Massbus %s assignment conflict at %d\n", - sim_dname (dptr), dibp->ba); + sim_printf ("Massbus %s assignment conflict at %d\n", + sim_dname (dptr), dibp->ba); return SCPE_STOP; } if (dibp->rd) /* set rd dispatch */ diff --git a/VAX/vax860_abus.c b/VAX/vax860_abus.c index 1f720ef0..60284a9c 100644 --- a/VAX/vax860_abus.c +++ b/VAX/vax860_abus.c @@ -682,9 +682,7 @@ if ((cpu_boot_cmd[0] == 0) || /* saved boot cmd? */ (reset_all (0) != SCPE_OK) || /* reset the world */ (cpu_boot (0, NULL) != SCPE_OK)) /* set up boot code */ ABORT (STOP_BOOT); /* any error? */ -printf ("Rebooting...\n"); -if (sim_log) - fprintf (sim_log, "Rebooting...\n"); +sim_printf ("Rebooting...\n"); return cc; } @@ -702,9 +700,7 @@ t_stat r; r = vax860_boot_parse (flag, ptr); /* parse the boot cmd */ if (r != SCPE_OK) { /* error? */ if (r >= SCPE_BASE) { /* message available? */ - printf ("%s\n", sim_error_text (r)); - if (sim_log) - fprintf (sim_log, "%s\n", sim_error_text (r)); + sim_printf ("%s\n", sim_error_text (r)); r |= SCPE_NOMESSAGE; } return r; diff --git a/VAX/vax860_sbia.c b/VAX/vax860_sbia.c index 47c652ef..b54ec421 100644 --- a/VAX/vax860_sbia.c +++ b/VAX/vax860_sbia.c @@ -186,7 +186,7 @@ void sbia_wr (int32 pa, int32 val, int32 lnt) break; case 1: /* SBICSR */ - printf ("sbi_csr wr: %08X\n", val); + sim_printf ("sbi_csr wr: %08X\n", val); sbi_csr = sbi_csr & SBICSR_WR; break; @@ -350,9 +350,7 @@ if ((nexusR[idx] && dibp->rd && /* conflict? */ (nexusR[idx] != dibp->rd)) || (nexusW[idx] && dibp->wr && (nexusW[idx] != dibp->wr))) { - printf ("Nexus %s conflict at %d\n", sim_dname (dptr), dibp->ba); - if (sim_log) - fprintf (sim_log, "Nexus %s conflict at %d\n", sim_dname (dptr), dibp->ba); + sim_printf ("Nexus %s conflict at %d\n", sim_dname (dptr), dibp->ba); return SCPE_STOP; } if (dibp->rd) /* set rd dispatch */ diff --git a/VAX/vax860_stddev.c b/VAX/vax860_stddev.c index a5e04be8..ec404fb7 100644 --- a/VAX/vax860_stddev.c +++ b/VAX/vax860_stddev.c @@ -558,7 +558,7 @@ switch (fnc) { break; default: - printf ("CS: Unknown Command: %d\n", fnc); + sim_printf ("CS: Unknown Command: %d\n", fnc); } } @@ -1073,7 +1073,7 @@ else switch (lc_fnc) { /* idle, case */ break; default: /* all others */ - printf ("TTO3: Unknown console command: %X\n", lc_fnc); + sim_printf ("TTO3: Unknown console command: %X\n", lc_fnc); break; } return SCPE_OK; diff --git a/VAX/vax_cpu.c b/VAX/vax_cpu.c index 99491b08..2eab04ec 100644 --- a/VAX/vax_cpu.c +++ b/VAX/vax_cpu.c @@ -3514,9 +3514,7 @@ t_stat cpu_load_bootcode (const char *filename, const unsigned char *builtin_cod char args[CBUFSIZE]; t_stat r; -printf ("Loading boot code from %s\n", filename); -if (sim_log) - fprintf (sim_log, "Loading boot code from %s\n", filename); +sim_printf ("Loading boot code from %s\n", filename); if (rom) sprintf (args, "-R %s", filename); else @@ -3527,14 +3525,10 @@ if (r != SCPE_OK) { FILE *f; if ((f = sim_fopen (filename, "wb"))) { - printf ("Saving boot code to %s\n", filename); - if (sim_log) - fprintf (sim_log, "Saving boot code to %s\n", filename); + sim_printf ("Saving boot code to %s\n", filename); sim_fwrite ((void *)builtin_code, 1, size, f); fclose (f); - printf ("Loading boot code from %s\n", filename); - if (sim_log) - fprintf (sim_log, "Loading boot code from %s\n", filename); + sim_printf ("Loading boot code from %s\n", filename); r = load_cmd (0, args); } } diff --git a/VAX/vax_lk.c b/VAX/vax_lk.c index 5afe3242..29b6ef58 100644 --- a/VAX/vax_lk.c +++ b/VAX/vax_lk.c @@ -354,7 +354,7 @@ if (lk_rbuf[0] & 1) { /* peripheral command */ break; default: - printf ("lk: unknown cmd %02X\n", lk_rbuf[0]); + sim_printf ("lk: unknown cmd %02X\n", lk_rbuf[0]); break; } } diff --git a/Visual Studio Projects/AltairZ80.vcproj b/Visual Studio Projects/AltairZ80.vcproj index f7ebeecc..a37e5099 100644 --- a/Visual Studio Projects/AltairZ80.vcproj +++ b/Visual Studio Projects/AltairZ80.vcproj @@ -197,6 +197,10 @@ RelativePath="..\AltairZ80\altairz80_hdsk.c" > + + diff --git a/descrip.mms b/descrip.mms index 73c5ebed..6abd1298 100644 --- a/descrip.mms +++ b/descrip.mms @@ -330,7 +330,7 @@ ALTAIRZ80_SOURCE2 = $(ALTAIRZ80_DIR)S100_DISK1A.C,$(ALTAIRZ80_DIR)S100_DISK2.C,\ $(ALTAIRZ80_DIR)S100_SCP300F.C,$(ALTAIRZ80_DIR)SIM_IMD.C,\ $(ALTAIRZ80_DIR)WD179X.C,$(ALTAIRZ80_DIR)S100_DISK3.C,\ $(ALTAIRZ80_DIR)S100_ADCS6.C,$(ALTAIRZ80_DIR)S100_HDC1001.C,\ - $(ALTAIRZ80_DIR)S100_IF3.C + $(ALTAIRZ80_DIR)S100_IF3.C,$(ALTAIRZ80_DIR)ALTAIRZ80_MHDSK.C ALTAIRZ80_OPTIONS = /INCL=($(SIMH_DIR),$(ALTAIRZ80_DIR))/DEF=($(CC_DEFS)) # diff --git a/display/vt11.c b/display/vt11.c index dd52e549..20b3f11c 100644 --- a/display/vt11.c +++ b/display/vt11.c @@ -1224,7 +1224,7 @@ point3(int i, int32 x1, int32 y1, int32 z1, int detect_edge) edge_indic &= !ONSCREEN(x1, y1); /* second test */ edge_flag &= ONSCREEN(x1, y1); /* second test */ edge_flag |= edge_indic; - if (edge_flag) + if (edge_flag) { if (edge_intr_ena) { edge_xpos = x1; edge_ypos = y1; @@ -1235,12 +1235,14 @@ point3(int i, int32 x1, int32 y1, int32 z1, int detect_edge) #endif } else edge_flag = 0; + } } - if (i && ONSCREEN(x1, y1)) + if (i && ONSCREEN(x1, y1)) { if (menu) illum3(x1 + MENU_OFFSET, y1, z1); else illum3(x1, y1, z1); + } } #define point2(i,x,y,e) point3(i, x, y, zpos, e) @@ -1262,7 +1264,7 @@ lpoint(int32 x, int32 y, int32 z) { int i, on = (line_type == SOLID) || stroking; /* on for sure */ - if (!on) /* see if in visible portion of cycle */ + if (!on) { /* see if in visible portion of cycle */ for (i = 0; i < reduce; ++i) { switch (line_type) { case LONG_DASH: @@ -1279,10 +1281,13 @@ lpoint(int32 x, int32 y, int32 z) && !(line_counter & LC3)) || !(line_counter & LC4)) on = 1; break; + case SOLID: + break; } --line_counter; } + } if (on) /* convert back from actual screen pixels to emulated CRT coordinates */ @@ -1586,11 +1591,12 @@ clip3(int32 x0, int32 y0, int32 z0, int32 x1, int32 y1, int32 z1) else if ( x1 < 0 ) code1 |= 8; - if (code0 == code1) /* endpoints lie in same region */ + if (code0 == code1) { /* endpoints lie in same region */ if (code0 == 0) /* ON to ON; trivially visible */ return -1; else /* OFF to OFF and trivially invisible */ return 0; + } /* Endpoints are now known to lie in different regions. */ @@ -1725,21 +1731,23 @@ clip3(int32 x0, int32 y0, int32 z0, int32 x1, int32 y1, int32 z1) */ if (rdx < 0) { - if (x0 <= 0 && x0 >= rdx) + if (x0 <= 0 && x0 >= rdx) { if (tPEd > 0) { if (x0 * (long)tPEd < (long)tPEn * rdx) tPEn = x0, tPEd = rdx; } else /* tPEd < 0 */ if (x0 * (long)tPEd > (long)tPEn * rdx) tPEn = x0, tPEd = rdx; + } } else /* rdx > 0 */ - if (x0 >= 0 && x0 <= rdx) + if (x0 >= 0 && x0 <= rdx) { if (tPLd > 0) { if (x0 * (long)tPLd < (long)tPLn * rdx) tPLn = x0, tPLd = rdx; } else /* tPLd < 0 */ if (x0 * (long)tPLd > (long)tPLn * rdx) tPLn = x0, tPLd = rdx; + } /* * Right: tR = NR . (PR - P0) / NR . (P1 - P0) @@ -1775,21 +1783,23 @@ clip3(int32 x0, int32 y0, int32 z0, int32 x1, int32 y1, int32 z1) tn = x0 - CLIPXMAX; if (rdx < 0) { - if (tn <= 0 && tn >= rdx) + if (tn <= 0 && tn >= rdx) { if (tPLd > 0) { if (tn * (long)tPLd > (long)tPLn * rdx) tPLn = tn, tPLd = rdx; } else /* tPLd < 0 */ if (tn * (long)tPLd < (long)tPLn * rdx) tPLn = tn, tPLd = rdx; + } } else /* rdx > 0 */ - if (tn >= 0 && tn <= rdx) + if (tn >= 0 && tn <= rdx) { if (tPEd > 0) { if (tn * (long)tPEd > (long)tPEn * rdx) tPEn = tn, tPEd = rdx; } else /* tPEd < 0 */ if (tn * (long)tPEd < (long)tPEn * rdx) tPEn = tn, tPEd = rdx; + } /* * Bottom: tB = NB . (PB - P0) / NB . (P1 - P0) @@ -1823,21 +1833,23 @@ clip3(int32 x0, int32 y0, int32 z0, int32 x1, int32 y1, int32 z1) */ if (rdy < 0) { - if (y0 <= 0 && y0 >= rdy) + if (y0 <= 0 && y0 >= rdy) { if (tPEd > 0) { if (y0 * (long)tPEd < (long)tPEn * rdy) tPEn = y0, tPEd = rdy; } else /* tPEd < 0 */ if (y0 * (long)tPEd > (long)tPEn * rdy) tPEn = y0, tPEd = rdy; + } } else /* rdy > 0 */ - if (y0 >= 0 && y0 <= rdy) + if (y0 >= 0 && y0 <= rdy) { if (tPLd > 0) { if (y0 * (long)tPLd < (long)tPLn * rdy) tPLn = y0, tPLd = rdy; } else /* tPLd < 0 */ if (y0 * (long)tPLd > (long)tPLn * rdy) tPLn = y0, tPLd = rdy; + } /* * Top: tT = NT . (PT - P0) / NT . (P1 - P0) @@ -1873,15 +1885,16 @@ clip3(int32 x0, int32 y0, int32 z0, int32 x1, int32 y1, int32 z1) tn = y0 - CLIPYMAX; if (rdy < 0) { - if (tn <= 0 && tn >= rdy) + if (tn <= 0 && tn >= rdy) { if (tPLd > 0) { if (tn * (long)tPLd > (long)tPLn * rdy) tPLn = tn, tPLd = rdy; } else /* tPLd < 0 */ if (tn * (long)tPLd < (long)tPLn * rdy) tPLn = tn, tPLd = rdy; + } } else /* rdy > 0 */ - if (tn >= 0 && tn <= rdy) + if (tn >= 0 && tn <= rdy) { if (tPEd > 0) { if (tn * (long)tPEd > (long)tPEn * rdy) tPEn = tn, tPEd = rdy; @@ -1889,6 +1902,7 @@ clip3(int32 x0, int32 y0, int32 z0, int32 x1, int32 y1, int32 z1) if (tn * (long)tPEd < (long)tPEn * rdy) tPEn = tn, tPEd = rdy; + } /* * if ( tPL < tPE ) * invisible @@ -1901,7 +1915,7 @@ clip3(int32 x0, int32 y0, int32 z0, int32 x1, int32 y1, int32 z1) * invis */ - if (tPLd > 0 && tPEd < 0 || tPLd < 0 && tPEd > 0) { + if (((tPLd > 0) && (tPEd < 0)) || ((tPLd < 0) && (tPEd > 0))) { if (tPLn * (long)tPEd > (long)tPEn * tPLd) return 0; /* invisible */ } else @@ -1979,11 +1993,12 @@ vector3(int i, int32 dx, int32 dy, int32 dz) /* unscaled display-file units */ i, (long)x0,(long)y0, (long)x1,(long)y1)); if (dx == 0 && dy == 0) { /* just display a point */ - if (i) + if (i) { if (menu) illum3(x0 + MENU_OFFSET, y0, z0); else illum3(x0, y0, z0); /* illum3() checks ONCRT, int0_scope */ + } return; } } else { @@ -2078,11 +2093,12 @@ vector3(int i, int32 dx, int32 dy, int32 dz) /* unscaled display-file units */ /* draw OK even when Maintenance Switch 3 is set */ /* (but updated position registers must not be used to draw vector) */ - if (i && int0_scope && !clip_vect) /* clipped vector drawn by vt_cycle() */ + if (i && int0_scope && !clip_vect) {/* clipped vector drawn by vt_cycle() */ if (menu) lineTwoStep(x0 + MENU_OFFSET, y0, z0, x1 + MENU_OFFSET, y1, z1); else lineTwoStep(x0, y0, z0, x1, y1, z1); + } /* * In case of LP hit, recompute coords using "tangent register", because: @@ -2244,7 +2260,7 @@ conic3(int i, int32 dcx, int32 dcy, int32 dcz, int32 dex, int32 dey, int32 dez) one = ONSCREEN(xe, ye); edge_indic = ons && !one; edge_flag = edge_indic || (!ons && one); - if (edge_flag) + if (edge_flag) { if (edge_intr_ena) { /* need to clip to viewport */ /* XXX edge positions aren't right; need proper clipping */ edge_xpos = xe; @@ -2254,6 +2270,7 @@ conic3(int i, int32 dcx, int32 dcy, int32 dcz, int32 dex, int32 dey, int32 dez) goto done; } else edge_flag = 0; + } /* XXX for now, resort to scissoring: illuminates only pixels that lie in the visible display area */ @@ -2812,15 +2829,16 @@ character(int c) edge_indic = ONSCREEN(xbase, ybase) && !ONSCREEN(xnext, ynext); edge_flag = edge_indic || - !ONSCREEN(xbase, ybase) && ONSCREEN(xnext, ynext); + ((!ONSCREEN(xbase, ybase)) && ONSCREEN(xnext, ynext)); /* (scaling cannot make spacing so large that it crosses the "working surface" while going from offscreen to offscreen) */ - if (edge_flag) + if (edge_flag) { if (edge_intr_ena) { edge_irq = 1; goto space; } else edge_flag = 0; + } if (!ONSCREEN(xbase, ybase) || !ONSCREEN(xnext, ynext)) goto space; @@ -3023,13 +3041,14 @@ vt11_cycle(int us, int slowdown) (long)clip_x1, (long)clip_y1, (long)clip_z1)); if (VS60 /* XXX assuming VT11 doesn't display */ && (dx != 0 || dy != 0 || dz != 0) /* hardware skips null vects */ - && clip_i && int0_scope) /* show it */ + && clip_i && int0_scope) { /* show it */ if (menu) lineTwoStep(clip_x0 + MENU_OFFSET, clip_y0, clip_z0, clip_x1 + MENU_OFFSET, clip_y1, clip_z1); else lineTwoStep(clip_x0, clip_y0, clip_z0, clip_x1, clip_y1, clip_z1); + } /* * In case of LP hit, recompute coords using "tangent register", * because: diff --git a/makefile b/makefile index f8afd828..25903b28 100644 --- a/makefile +++ b/makefile @@ -1011,9 +1011,9 @@ ALTAIRZ80 = ${ALTAIRZ80D}/altairz80_cpu.c ${ALTAIRZ80D}/altairz80_cpu_nommu.c \ ${ALTAIRZ80D}/altairz80_hdsk.c ${ALTAIRZ80D}/altairz80_net.c \ ${ALTAIRZ80D}/flashwriter2.c ${ALTAIRZ80D}/i86_decode.c \ ${ALTAIRZ80D}/i86_ops.c ${ALTAIRZ80D}/i86_prim_ops.c \ - ${ALTAIRZ80D}/i8272.c ${ALTAIRZ80D}/insnsd.c \ + ${ALTAIRZ80D}/i8272.c ${ALTAIRZ80D}/insnsd.c ${ALTAIRZ80D}/altairz80_mhdsk.c \ ${ALTAIRZ80D}/mfdc.c ${ALTAIRZ80D}/n8vem.c ${ALTAIRZ80D}/vfdhd.c \ - ${ALTAIRZ80D}/s100_disk1a.c ${ALTAIRZ80D}/s100_disk2.c ${ALTAIRZ80D}/s100_disk3.c\ + ${ALTAIRZ80D}/s100_disk1a.c ${ALTAIRZ80D}/s100_disk2.c ${ALTAIRZ80D}/s100_disk3.c \ ${ALTAIRZ80D}/s100_fif.c ${ALTAIRZ80D}/s100_mdriveh.c \ ${ALTAIRZ80D}/s100_mdsad.c ${ALTAIRZ80D}/s100_selchan.c \ ${ALTAIRZ80D}/s100_ss1.c ${ALTAIRZ80D}/s100_64fdc.c \ diff --git a/scp.c b/scp.c index 734f8533..33f9fe0b 100644 --- a/scp.c +++ b/scp.c @@ -1717,11 +1717,8 @@ while (stat != SCPE_EXIT) { /* in case exit */ if (cmdp && (cmdp->message)) /* special message handler? */ cmdp->message (NULL, stat); /* let it deal with display */ else - if (stat >= SCPE_BASE) { /* error? */ - printf ("%s\n", sim_error_text (stat)); - if (sim_log) - fprintf (sim_log, "%s\n", sim_error_text (stat)); - } + if (stat >= SCPE_BASE) /* error? */ + sim_printf ("%s\n", sim_error_text (stat)); } if (sim_vm_post != NULL) (*sim_vm_post) (TRUE); @@ -2297,6 +2294,8 @@ if ((cptr == NULL) || (strlen (cptr) == 0)) fflush(stdout); /* flush stdout */ if (sim_log) /* flush log if enabled */ fflush (sim_log); +if (sim_deb) /* flush debug if enabled */ + fflush (sim_deb); status = system (cptr); #if defined (VMS) printf ("\n"); @@ -3892,7 +3891,7 @@ if (dptr->flags & DEV_DEBUG) { else { fputs ("Debug=", st); for (dep = dptr->debflags; dep->name != NULL; dep++) { - if (dptr->dctrl & dep->mask) { + if ((dptr->dctrl & dep->mask) == dep->mask) { if (any) fputc (';', st); fputs (dep->name, st); @@ -4041,7 +4040,7 @@ if ((!cptr) || (*cptr == 0)) return SCPE_2FARG; sim_trim_endspc(cptr); if (chdir(cptr) != 0) { - printf("Unable to change to: %s\n", cptr); + sim_printf("Unable to directory change to: %s\n", cptr); return SCPE_IOERR & SCPE_NOMESSAGE; } return SCPE_OK; @@ -4087,57 +4086,37 @@ if ((hFind = FindFirstFileA (cptr, &File)) != INVALID_HANDLE_VALUE) { else { getcwd(DirName, PATH_MAX); } - printf (" Directory of %s\n\n", DirName); - if (sim_log) - fprintf (sim_log, " Directory of %s\n\n", DirName); + sim_printf (" Directory of %s\n\n", DirName); do { FileSize = (((t_int64)(File.nFileSizeHigh)) << 32) | File.nFileSizeLow; sprintf (FileName, "%s%c%s", DirName, pathsep, File.cFileName); stat (FileName, &filestat); local = localtime (&filestat.st_mtime); - printf ("%02d/%02d/%04d %02d:%02d %s ", local->tm_mon+1, local->tm_mday, 1900+local->tm_year, local->tm_hour%12, local->tm_min, (local->tm_hour >= 12) ? "PM" : "AM"); - if (sim_log) - fprintf (sim_log, "%02d/%02d/%04d %02d:%02d %s ", local->tm_mon+1, local->tm_mday, 1900+local->tm_year, local->tm_hour%12, local->tm_min, (local->tm_hour >= 12) ? "PM" : "AM"); + sim_printf ("%02d/%02d/%04d %02d:%02d %s ", local->tm_mon+1, local->tm_mday, 1900+local->tm_year, local->tm_hour%12, local->tm_min, (local->tm_hour >= 12) ? "PM" : "AM"); if (filestat.st_mode & S_IFDIR) { ++DirCount; - printf (" "); - if (sim_log) - fprintf (sim_log, " "); + sim_printf (" "); } else { if (filestat.st_mode & S_IFREG) { ++FileCount; - fprint_val (stdout, (t_value) FileSize, 10, 17, PV_RCOMMA); - if (sim_log) - fprint_val (sim_log, (t_value) FileSize, 10, 17, PV_RCOMMA); + sim_print_val ((t_value) FileSize, 10, 17, PV_RCOMMA); TotalSize += FileSize; } else { - printf ("%17s", ""); - if (sim_log) - fprintf (sim_log, "%17s", ""); + sim_printf ("%17s", ""); } } - printf (" %s\n", File.cFileName); - if (sim_log) - fprintf (sim_log, " %s\n", File.cFileName); + sim_printf (" %s\n", File.cFileName); } while (FindNextFile (hFind, &File)); - printf ("%16d File(s)", FileCount); - fprint_val (stdout, (t_value) TotalSize, 10, 15, PV_RCOMMA); - printf (" bytes\n"); - printf ("%16d Dir(s)\n", DirCount); - if (sim_log) { - fprintf (sim_log, "%16d File(s)", FileCount); - fprint_val (sim_log, (t_value) TotalSize, 10, 15, PV_RCOMMA); - fprintf (sim_log, " bytes\n"); - fprintf (sim_log, "%16d Dir(s)\n", DirCount); - } + sim_printf ("%16d File(s)", FileCount); + sim_print_val ((t_value) TotalSize, 10, 15, PV_RCOMMA); + sim_printf (" bytes\n"); + sim_printf ("%16d Dir(s)\n", DirCount); FindClose (hFind); } else { - printf ("Can't list files for %s\n", cptr); - if (sim_log) - fprintf (sim_log, "Can't list files for %s\n", cptr); + sim_printf ("Can't list files for %s\n", cptr); return SCPE_ARG; } return SCPE_OK; @@ -4227,9 +4206,7 @@ if (dir) { #endif MatchName = 1 + strrchr (cptr, '/'); - printf (" Directory of %s\n\n", DirName[0] ? DirName : "/"); - if (sim_log) - fprintf (sim_log, " Directory of %s\n\n", DirName[0] ? DirName : "/"); + sim_printf (" Directory of %s\n\n", DirName[0] ? DirName : "/"); #if defined (HAVE_GLOB) for (i=0; itm_mon+1, local->tm_mday, 1900+local->tm_year, local->tm_hour%12, local->tm_min, (local->tm_hour >= 12) ? "PM" : "AM"); - if (sim_log) - fprintf (sim_log, "%02d/%02d/%04d %02d:%02d %s ", local->tm_mon+1, local->tm_mday, 1900+local->tm_year, local->tm_hour%12, local->tm_min, (local->tm_hour >= 12) ? "PM" : "AM"); + sim_printf ("%02d/%02d/%04d %02d:%02d %s ", local->tm_mon+1, local->tm_mday, 1900+local->tm_year, local->tm_hour%12, local->tm_min, (local->tm_hour >= 12) ? "PM" : "AM"); if (filestat.st_mode & S_IFDIR) { ++DirCount; - printf (" "); - if (sim_log) - fprintf (sim_log, " "); + sim_printf (" "); } else { if (filestat.st_mode & S_IFREG) { ++FileCount; FileSize = sim_fsize_name_ex (FileName); - fprint_val (stdout, (t_value) FileSize, 10, 17, PV_RCOMMA); - if (sim_log) - fprint_val (sim_log, (t_value) FileSize, 10, 17, PV_RCOMMA); + sim_print_val ((t_value) FileSize, 10, 17, PV_RCOMMA); TotalSize += FileSize; } else { - printf ("%17s", ""); - if (sim_log) - fprintf (sim_log, "%17s", ""); + sim_printf ("%17s", ""); } } c = strrchr (FileName, '/'); - printf (" %s\n", c ? c + 1 : FileName); - if (sim_log) - fprintf (sim_log, " %s\n", c ? c + 1 : FileName); + sim_printf (" %s\n", c ? c + 1 : FileName); } if (FileCount) { - printf ("%16d File(s)", FileCount); - fprint_val (stdout, (t_value) TotalSize, 10, 15, PV_RCOMMA); - printf (" bytes\n"); - printf ("%16d Dir(s)\n", DirCount); - if (sim_log) { - fprintf (sim_log, "%16d File(s)", FileCount); - fprint_val (sim_log, (t_value) TotalSize, 10, 15, PV_RCOMMA); - fprintf (sim_log, " bytes\n"); - fprintf (sim_log, "%16d Dir(s)\n", DirCount); - } + sim_printf ("%16d File(s)", FileCount); + sim_print_val ((t_value) TotalSize, 10, 15, PV_RCOMMA); + sim_printf (" bytes\n"); + sim_printf ("%16d Dir(s)\n", DirCount); } else { - printf ("File Not Found\n"); - if (sim_log) - fprintf (sim_log, "File Not Found\n"); + sim_printf ("File Not Found\n"); } #if defined (HAVE_GLOB) globfree (&paths); @@ -4296,9 +4255,7 @@ if (dir) { #endif } else { - printf ("Can't list files for %s\n", cptr); - if (sim_log) - fprintf (sim_log, "Can't list files for %s\n", cptr); + sim_printf ("Can't list files for %s\n", cptr); return SCPE_ARG; } return SCPE_OK; @@ -4569,9 +4526,7 @@ if (sim_switches & SWMASK ('R')) { /* read only? */ return attach_err (uptr, SCPE_OPENERR); /* yes, error */ uptr->flags = uptr->flags | UNIT_RO; /* set rd only */ if (!sim_quiet) { - printf ("%s: unit is read only\n", sim_dname (dptr)); - if (sim_log) - fprintf (sim_log, "%s: unit is read only\n", sim_dname (dptr)); + sim_printf ("%s: unit is read only\n", sim_dname (dptr)); } } else { @@ -4580,9 +4535,7 @@ else { if (uptr->fileref == NULL) /* open fail? */ return attach_err (uptr, SCPE_OPENERR); /* yes, error */ if (!sim_quiet) { - printf ("%s: creating new file\n", sim_dname (dptr)); - if (sim_log) - fprintf (sim_log, "%s: creating new file\n", sim_dname (dptr)); + sim_printf ("%s: creating new file\n", sim_dname (dptr)); } } else { /* normal */ @@ -4600,9 +4553,7 @@ else { return attach_err (uptr, SCPE_OPENERR); /* yes, error */ uptr->flags = uptr->flags | UNIT_RO; /* set rd only */ if (!sim_quiet) { - printf ("%s: unit is read only\n", sim_dname (dptr)); - if (sim_log) - fprintf (sim_log, "%s: unit is read only\n", sim_dname (dptr)); + sim_printf ("%s: unit is read only\n", sim_dname (dptr)); } } else { /* doesn't exist */ @@ -4612,9 +4563,7 @@ else { if (uptr->fileref == NULL) /* open fail? */ return attach_err (uptr, SCPE_OPENERR); /* yes, error */ if (!sim_quiet) { - printf ("%s: creating new file\n", sim_dname (dptr)); - if (sim_log) - fprintf (sim_log, "%s: creating new file\n", sim_dname (dptr)); + sim_printf ("%s: creating new file\n", sim_dname (dptr)); } } } /* end if null */ @@ -4627,9 +4576,7 @@ if (uptr->flags & UNIT_BUFABLE) { /* buffer? */ if (uptr->filebuf == NULL) /* no buffer? */ return attach_err (uptr, SCPE_MEM); /* error */ if (!sim_quiet) { - printf ("%s: buffering file in memory\n", sim_dname (dptr)); - if (sim_log) - fprintf (sim_log, "%s: buffering file in memory\n", sim_dname (dptr)); + sim_printf ("%s: buffering file in memory\n", sim_dname (dptr)); } uptr->hwmark = (uint32)sim_fread (uptr->filebuf, /* read file */ SZ_D (dptr), cap, uptr->fileref); @@ -4745,9 +4692,7 @@ if (uptr->flags & UNIT_BUF) { uint32 cap = (uptr->hwmark + dptr->aincr - 1) / dptr->aincr; if (uptr->hwmark && ((uptr->flags & UNIT_RO) == 0)) { if (!sim_quiet) { - printf ("%s: writing buffer to file\n", sim_dname (dptr)); - if (sim_log) - fprintf (sim_log, "%s: writing buffer to file\n", sim_dname (dptr)); + sim_printf ("%s: writing buffer to file\n", sim_dname (dptr)); } rewind (uptr->fileref); sim_fwrite (uptr->filebuf, SZ_D (dptr), cap, uptr->fileref); @@ -5043,31 +4988,23 @@ if (strcmp (buf, save_vercur) == 0) /* version 3.5? */ else if (strcmp (buf, save_ver32) == 0) /* version 3.2? */ v32 = TRUE; else if (strcmp (buf, save_ver30) != 0) { /* version 3.0? */ - printf ("Invalid file version: %s\n", buf); - if (sim_log) - fprintf (sim_log, "Invalid file version: %s\n", buf); + sim_printf ("Invalid file version: %s\n", buf); return SCPE_INCOMP; } READ_S (buf); /* read sim name */ if (strcmp (buf, sim_name)) { /* name match? */ - printf ("Wrong system type: %s\n", buf); - if (sim_log) - fprintf (sim_log, "Wrong system type: %s\n", buf); + sim_printf ("Wrong system type: %s\n", buf); return SCPE_INCOMP; } if (v35) { /* [V3.5+] options */ READ_S (buf); /* integer size */ if (strcmp (buf, sim_si64) != 0) { - printf ("Incompatible integer size, save file = %s\n", buf); - if (sim_log) - fprintf (sim_log, "Incompatible integer size, save file = %s\n", buf); + sim_printf ("Incompatible integer size, save file = %s\n", buf); return SCPE_INCOMP; } READ_S (buf); /* address size */ if (strcmp (buf, sim_sa64) != 0) { - printf ("Incompatible address size, save file = %s\n", buf); - if (sim_log) - fprintf (sim_log, "Incompatible address size, save file = %s\n", buf); + sim_printf ("Incompatible address size, save file = %s\n", buf); return SCPE_INCOMP; } READ_S (buf); /* Ethernet */ @@ -5084,9 +5021,7 @@ for ( ;; ) { /* device loop */ if (buf[0] == 0) /* last? */ break; if ((dptr = find_dev (buf)) == NULL) { /* locate device */ - printf ("Invalid device name: %s\n", buf); - if (sim_log) - fprintf (sim_log, "Invalid device name: %s\n", buf); + sim_printf ("Invalid device name: %s\n", buf); return SCPE_INCOMP; } READ_S (buf); /* [V3.0+] logical name */ @@ -5106,9 +5041,7 @@ for ( ;; ) { /* device loop */ if (unitno < 0) /* end units? */ break; if ((uint32) unitno >= dptr->numunits) { /* too big? */ - printf ("Invalid unit number: %s%d\n", sim_dname (dptr), unitno); - if (sim_log) - fprintf (sim_log, "Invalid unit number: %s%d\n", sim_dname (dptr), unitno); + sim_printf ("Invalid unit number: %s%d\n", sim_dname (dptr), unitno); return SCPE_INCOMP; } READ_I (time); /* event time */ @@ -5157,9 +5090,7 @@ for ( ;; ) { /* device loop */ if (high > 0) { /* [V2.5+] any memory? */ if (((uptr->flags & (UNIT_FIX + UNIT_ATTABLE)) != UNIT_FIX) || (dptr->deposit == NULL)) { - printf ("Can't restore memory: %s%d\n", sim_dname (dptr), unitno); - if (sim_log) - fprintf (sim_log, "Can't restore memory: %s%d\n", sim_dname (dptr), unitno); + sim_printf ("Can't restore memory: %s%d\n", sim_dname (dptr), unitno); return SCPE_INCOMP; } if (high != old_capac) { /* size change? */ @@ -5167,11 +5098,8 @@ for ( ;; ) { /* device loop */ if ((dptr->flags & DEV_DYNM) && ((dptr->msize == NULL) || (dptr->msize (uptr, (int32) high, NULL, NULL) != SCPE_OK))) { - printf ("Can't change memory size: %s%d\n", - sim_dname (dptr), unitno); - if (sim_log) - fprintf (sim_log, "Can't change memory size: %s%d\n", - sim_dname (dptr), unitno); + sim_printf ("Can't change memory size: %s%d\n", + sim_dname (dptr), unitno); return SCPE_INCOMP; } uptr->capac = high; /* new memory size */ @@ -5219,28 +5147,21 @@ for ( ;; ) { /* device loop */ break; READ_I (depth); /* [V2.10+] depth */ if ((rptr = find_reg (buf, NULL, dptr)) == NULL) { - printf ("Invalid register name: %s %s\n", sim_dname (dptr), buf); - if (sim_log) - fprintf (sim_log, "Invalid register name: %s %s\n", sim_dname (dptr), buf); + sim_printf ("Invalid register name: %s %s\n", sim_dname (dptr), buf); for (us = 0; us < depth; us++) { /* skip values */ READ_I (val); } continue; } if (depth != rptr->depth) { /* [V2.10+] mismatch? */ - printf ("Register depth mismatch: %s %s, file = %d, sim = %d\n", - sim_dname (dptr), buf, depth, rptr->depth); - if (sim_log) - fprintf (sim_log, "Register depth mismatch: %s %s, file = %d, sim = %d\n", - sim_dname (dptr), buf, depth, rptr->depth); + sim_printf ("Register depth mismatch: %s %s, file = %d, sim = %d\n", + sim_dname (dptr), buf, depth, rptr->depth); } mask = width_mask[rptr->width]; /* get mask */ for (us = 0; us < depth; us++) { /* loop thru values */ READ_I (val); /* read value */ if (val > mask) { /* value ok? */ - printf ("Invalid register value: %s %s\n", sim_dname (dptr), buf); - if (sim_log) - fprintf (sim_log, "Invalid register value: %s %s\n", sim_dname (dptr), buf); + sim_printf ("Invalid register value: %s %s\n", sim_dname (dptr), buf); } else if (us < rptr->depth) /* in range? */ put_rval (rptr, us, val); @@ -5260,23 +5181,16 @@ for (j=0, r = SCPE_OK; j rstat.st_mtime + 30) { r = SCPE_INCOMP; - printf ("Error Attaching %s to %s - the restore state is %d seconds older than the attach file\n", sim_dname (dptr), attnames[j], (int)(fstat.st_mtime - rstat.st_mtime)); - printf ("restore with the -F switch to override this sanity check\n"); - if (sim_log) { - fprintf (sim_log, "Error Attaching %s to %s - the restore state is %d seconds older than the attach file\n", sim_dname (dptr), attnames[j], (int)(fstat.st_mtime - rstat.st_mtime)); - fprintf (sim_log, "restore with the -F switch to override this sanity check\n"); - } + sim_printf ("Error Attaching %s to %s - the restore state is %d seconds older than the attach file\n", sim_dname (dptr), attnames[j], (int)(fstat.st_mtime - rstat.st_mtime)); + sim_printf ("restore with the -F switch to override this sanity check\n"); continue; } saved_pos = attunits[j]->pos; sim_switches = attswitches[j]; r = scp_attach_unit (dptr, attunits[j], attnames[j]);/* reattach unit */ attunits[j]->pos = saved_pos; - if (r != SCPE_OK) { - printf ("Error Attaching %s to %s\n", sim_dname (dptr), attnames[j]); - if (sim_log) - fprintf (sim_log, "Error Attaching %s to %s\n", sim_dname (dptr), attnames[j]); - } + if (r != SCPE_OK) + sim_printf ("Error Attaching %s to %s\n", sim_dname (dptr), attnames[j]); } free (attnames[j]); } @@ -5463,6 +5377,8 @@ if (unechoed_cmdline) { fprint_stopped (stdout, r); /* print msg */ if (sim_log) /* log if enabled */ fprint_stopped (sim_log, r); +if (sim_deb) /* log if enabled */ + fprint_stopped (sim_deb, r); } /* Common setup for RUN or BOOT */ @@ -7074,6 +6990,25 @@ if (fputs (dbuf, stream) == EOF) return SCPE_OK; } +t_stat sim_print_val (t_value val, uint32 radix, + uint32 width, uint32 format) +{ +char dbuf[MAX_WIDTH + 1]; + +if (width > MAX_WIDTH) + width = MAX_WIDTH; +sprint_val (dbuf, val, radix, width, format); +if (fputs (dbuf, stdout) == EOF) + return SCPE_IOERR; +if (sim_log && (sim_log != stdout)) + if (fputs (dbuf, sim_log) == EOF) + return SCPE_IOERR; +if (sim_deb && (sim_deb != stdout)) + if (fputs (dbuf, sim_deb) == EOF) + return SCPE_IOERR; +return SCPE_OK; +} + /* Event queue package sim_activate add entry to event queue @@ -7892,6 +7827,65 @@ if (sim_deb && (dptr->dctrl & dbits)) { } } +/* Print message to stdout, sim_log (if enabled) and sim_deb (if enabled) */ +void sim_printf (const char* fmt, ...) +{ +char stackbuf[STACKBUFSIZE]; +int32 bufsize = sizeof(stackbuf); +char *buf = stackbuf; +int32 len; +va_list arglist; + +while (1) { /* format passed string, args */ + va_start (arglist, fmt); +#if defined(NO_vsnprintf) +#if defined(HAS_vsprintf_void) + +/* Note, this could blow beyond the buffer, and we couldn't tell */ +/* That is a limitation of the C runtime library available on this platform */ + + vsprintf (buf, fmt, arglist); + for (len = 0; len < bufsize-1; len++) + if (buf[len] == 0) break; +#else + len = vsprintf (buf, fmt, arglist); +#endif /* HAS_vsprintf_void */ +#else /* NO_vsnprintf */ +#if defined(HAS_vsnprintf_void) + vsnprintf (buf, bufsize-1, fmt, arglist); + for (len = 0; len < bufsize-1; len++) + if (buf[len] == 0) break; +#else + len = vsnprintf (buf, bufsize-1, fmt, arglist); +#endif /* HAS_vsnprintf_void */ +#endif /* NO_vsnprintf */ + va_end (arglist); + +/* If the formatted result didn't fit into the buffer, then grow the buffer and try again */ + + if ((len < 0) || (len >= bufsize-1)) { + if (buf != stackbuf) + free (buf); + bufsize = bufsize * 2; + buf = (char *) malloc (bufsize); + if (buf == NULL) /* out of memory */ + return; + buf[bufsize-1] = '\0'; + continue; + } + break; + } + +printf("%s", buf); +if (sim_log && (sim_log != stdout)) + fprintf (sim_log, "%s", buf); +if (sim_deb && (sim_deb != stdout)) + fprintf (sim_deb, "%s", buf); + +if (buf != stackbuf) + free (buf); +} + /* Inline debugging - will print debug message if debug file is set and the bitmask matches the current device debug options. Extra returns are added for un*x systems, since the output diff --git a/scp.h b/scp.h index fbd28c4b..3bb6e473 100644 --- a/scp.h +++ b/scp.h @@ -118,6 +118,7 @@ char *get_range (DEVICE *dptr, char *cptr, t_addr *lo, t_addr *hi, uint32 rdx, t_addr max, char term); t_value strtotv (const char *cptr, char **endptr, uint32 radix); t_stat fprint_val (FILE *stream, t_value val, uint32 rdx, uint32 wid, uint32 fmt); +t_stat sim_print_val (t_value val, uint32 radix, uint32 width, uint32 format); char *read_line (char *cptr, int32 size, FILE *stream); void fprint_reg_help (FILE *st, DEVICE *dptr); void fprint_set_help (FILE *st, DEVICE *dptr); @@ -142,6 +143,7 @@ t_stat show_dev_debug (FILE *st, DEVICE *dptr, UNIT *uptr, int32 flag, char *cpt const char *sim_error_text (t_stat stat); t_stat sim_string_to_stat (char *cptr, t_stat *cond); t_stat sim_cancel_step (void); +void sim_printf (const char* fmt, ...); void sim_debug_bits (uint32 dbits, DEVICE* dptr, BITFIELD* bitdefs, uint32 before, uint32 after, int terminate); #if defined (__DECC) && defined (__VMS) && (defined (__VAX) || (__DECC_VER < 60590001)) diff --git a/sim_disk.c b/sim_disk.c index 4ee7e759..9d5fd4e4 100644 --- a/sim_disk.c +++ b/sim_disk.c @@ -444,8 +444,7 @@ t_stat sim_disk_set_async (UNIT *uptr, int latency) { #if !defined(SIM_ASYNCH_IO) char *msg = "Disk: can't operate asynchronously\r\n"; -printf ("%s", msg); -if (sim_log) fprintf (sim_log, "%s", msg); +sim_printf ("%s", msg); return SCPE_NOFNC; #else struct disk_context *ctx = (struct disk_context *)uptr->disk_ctx; @@ -877,17 +876,13 @@ if (sim_switches & SWMASK ('C')) { /* create vhd disk & cop return r; } if (!sim_quiet) { - printf ("%s%d: creating new virtual disk '%s'\n", sim_dname (dptr), (int)(uptr-dptr->units), gbuf); - if (sim_log) - fprintf (sim_log, "%s%d: creating new virtual disk '%s'\n", sim_dname (dptr), (int)(uptr-dptr->units), gbuf); + sim_printf ("%s%d: creating new virtual disk '%s'\n", sim_dname (dptr), (int)(uptr-dptr->units), gbuf); } capac_factor = ((dptr->dwidth / dptr->aincr) == 16) ? 2 : 1; /* capacity units (word: 2, byte: 1) */ vhd = sim_vhd_disk_create (gbuf, ((t_offset)uptr->capac)*capac_factor*((dptr->flags & DEV_SECTORS) ? 512 : 1)); if (!vhd) { if (!sim_quiet) { - printf ("%s%d: can't create virtual disk '%s'\n", sim_dname (dptr), (int)(uptr-dptr->units), gbuf); - if (sim_log) - fprintf (sim_log, "%s%d: can't create virtual disk '%s'\n", sim_dname (dptr), (int)(uptr-dptr->units), gbuf); + sim_printf ("%s%d: can't create virtual disk '%s'\n", sim_dname (dptr), (int)(uptr-dptr->units), gbuf); } return SCPE_OPENERR; } @@ -904,11 +899,8 @@ if (sim_switches & SWMASK ('C')) { /* create vhd disk & cop return SCPE_MEM; } for (lba = 0; (lba < total_sectors) && (r == SCPE_OK); lba += sects) { - if (!sim_quiet) { - printf ("%s%d: Copied %dMB. %d%% complete.\r", sim_dname (dptr), (int)(uptr-dptr->units), (int)((((float)lba)*sector_size)/1000000), (int)((((float)lba)*100)/total_sectors)); - if (sim_log) - fprintf (sim_log, "%s%d: Copied %dMB. %d%% complete.\r", sim_dname (dptr), (int)(uptr-dptr->units), (int)((((float)lba)*sector_size)/1000000), (int)((((float)lba)*100)/total_sectors)); - } + if (!sim_quiet) + sim_printf ("%s%d: Copied %dMB. %d%% complete.\r", sim_dname (dptr), (int)(uptr-dptr->units), (int)((((float)lba)*sector_size)/1000000), (int)((((float)lba)*100)/total_sectors)); sects = sectors_per_buffer; if (lba + sects > total_sectors) sects = total_sectors - lba; @@ -925,16 +917,10 @@ if (sim_switches & SWMASK ('C')) { /* create vhd disk & cop } } if (!sim_quiet) { - if (r == SCPE_OK) { - printf ("\n%s%d: Copied %dMB. Done.\n", sim_dname (dptr), (int)(uptr-dptr->units), (int)(((t_offset)lba*sector_size)/1000000)); - if (sim_log) - fprintf (sim_log, "\n%s%d: Copied %dMB. Done.\n", sim_dname (dptr), (int)(uptr-dptr->units), (int)(((t_offset)lba*sector_size)/1000000)); - } - else { - printf ("\n%s%d: Error copying: %s.\n", sim_dname (dptr), (int)(uptr-dptr->units), sim_error_text (r)); - if (sim_log) - fprintf (sim_log, "\n%s%d: Error copying: %s.\n", sim_dname (dptr), (int)(uptr-dptr->units), sim_error_text (r)); - } + if (r == SCPE_OK) + sim_printf ("\n%s%d: Copied %dMB. Done.\n", sim_dname (dptr), (int)(uptr-dptr->units), (int)(((t_offset)lba*sector_size)/1000000)); + else + sim_printf ("\n%s%d: Error copying: %s.\n", sim_dname (dptr), (int)(uptr-dptr->units), sim_error_text (r)); } if ((r == SCPE_OK) && (sim_switches & SWMASK ('V'))) { uint8 *verify_buf = (uint8*) malloc (1024*1024); @@ -946,11 +932,8 @@ if (sim_switches & SWMASK ('C')) { /* create vhd disk & cop return SCPE_MEM; } for (lba = 0; (lba < total_sectors) && (r == SCPE_OK); lba += sects) { - if (!sim_quiet) { - printf ("%s%d: Verified %dMB. %d%% complete.\r", sim_dname (dptr), (int)(uptr-dptr->units), (int)((((float)lba)*sector_size)/1000000), (int)((((float)lba)*100)/total_sectors)); - if (sim_log) - fprintf (sim_log, "%s%d: Verified %dMB. %d%% complete.\r", sim_dname (dptr), (int)(uptr-dptr->units), (int)((((float)lba)*sector_size)/1000000), (int)((((float)lba)*100)/total_sectors)); - } + if (!sim_quiet) + sim_printf ("%s%d: Verified %dMB. %d%% complete.\r", sim_dname (dptr), (int)(uptr-dptr->units), (int)((((float)lba)*sector_size)/1000000), (int)((((float)lba)*100)/total_sectors)); sects = sectors_per_buffer; if (lba + sects > total_sectors) sects = total_sectors - lba; @@ -971,11 +954,8 @@ if (sim_switches & SWMASK ('C')) { /* create vhd disk & cop } } if (!sim_quiet) { - if (r == SCPE_OK) { - printf ("\n%s%d: Verified %dMB. Done.\n", sim_dname (dptr), (int)(uptr-dptr->units), (int)(((t_offset)lba*sector_size)/1000000)); - if (sim_log) - fprintf (sim_log, "\n%s%d: Verified %dMB. Done.\n", sim_dname (dptr), (int)(uptr-dptr->units), (int)(((t_offset)lba*sector_size)/1000000)); - } + if (r == SCPE_OK) + sim_printf ("\n%s%d: Verified %dMB. Done.\n", sim_dname (dptr), (int)(uptr-dptr->units), (int)(((t_offset)lba*sector_size)/1000000)); else { t_lba i; uint32 save_dctrl = dptr->dctrl; @@ -984,9 +964,7 @@ if (sim_switches & SWMASK ('C')) { /* create vhd disk & cop for (i = 0; i < (1024*1024/sector_size); ++i) if (0 != memcmp (copy_buf+i*sector_size, verify_buf+i*sector_size, sector_size)) break; - printf ("\n%s%d: Verification Error on lbn %d.\n", sim_dname (dptr), (int)(uptr-dptr->units), lba+i); - if (sim_log) - fprintf (sim_log, "\n%s%d: Verification Error on lbn %d.\n", sim_dname (dptr), (int)(uptr-dptr->units), lba+i); + sim_printf ("\n%s%d: Verification Error on lbn %d.\n", sim_dname (dptr), (int)(uptr-dptr->units), lba+i); dptr->dctrl = 0xFFFFFFFF; sim_deb = stdout; sim_disk_data_trace (uptr, copy_buf+i*sector_size, lba+i, sector_size, "Expected", TRUE, 1); @@ -1076,9 +1054,7 @@ if (sim_switches & SWMASK ('R')) { /* read only? */ return _err_return (uptr, SCPE_OPENERR); /* yes, error */ uptr->flags = uptr->flags | UNIT_RO; /* set rd only */ if (!sim_quiet) { - printf ("%s%d: unit is read only\n", sim_dname (dptr), (int)(uptr-dptr->units)); - if (sim_log) - fprintf (sim_log, "%s%d: unit is read only\n", sim_dname (dptr), (int)(uptr-dptr->units)); + sim_printf ("%s%d: unit is read only\n", sim_dname (dptr), (int)(uptr-dptr->units)); } } else { /* normal */ @@ -1092,7 +1068,7 @@ else { /* normal */ return _err_return (uptr, SCPE_OPENERR);/* yes, error */ uptr->flags = uptr->flags | UNIT_RO; /* set rd only */ if (!sim_quiet) - printf ("%s%d: unit is read only\n", sim_dname (dptr), (int)(uptr-dptr->units)); + sim_printf ("%s%d: unit is read only\n", sim_dname (dptr), (int)(uptr-dptr->units)); } else { /* doesn't exist */ if (sim_switches & SWMASK ('E')) /* must exist? */ @@ -1104,7 +1080,7 @@ else { /* normal */ if (uptr->fileref == NULL) /* open fail? */ return _err_return (uptr, SCPE_OPENERR);/* yes, error */ if (!sim_quiet) - printf ("%s%d: creating new file\n", sim_dname (dptr), (int)(uptr-dptr->units)); + sim_printf ("%s%d: creating new file\n", sim_dname (dptr), (int)(uptr-dptr->units)); created = TRUE; } } /* end if null */ @@ -1162,18 +1138,11 @@ if (capac && (capac != (t_offset)-1)) { if (dontautosize) { if ((capac < (((t_offset)uptr->capac)*ctx->capac_factor*((dptr->flags & DEV_SECTORS) ? 512 : 1))) && (DKUF_F_STD != DK_GET_FMT (uptr))) { if (!sim_quiet) { - printf ("%s%d: non expandable disk %s is smaller than simulated device (", sim_dname (dptr), (int)(uptr-dptr->units), cptr); - fprint_val (stdout, (t_addr)(capac/ctx->capac_factor), 10, T_ADDR_W, PV_LEFT); - printf ("%s < ", (ctx->capac_factor == 2) ? "W" : ""); - fprint_val (stdout, uptr->capac*((dptr->flags & DEV_SECTORS) ? 512 : 1), 10, T_ADDR_W, PV_LEFT); - printf ("%s)\n", (ctx->capac_factor == 2) ? "W" : ""); - if (sim_log) { - fprintf (sim_log, "%s%d: non expandable disk %s is smaller than simulated device (", sim_dname (dptr), (int)(uptr-dptr->units), cptr); - fprint_val (sim_log, (t_addr)(capac/ctx->capac_factor), 10, T_ADDR_W, PV_LEFT); - fprintf (sim_log, "%s < ", (ctx->capac_factor == 2) ? "W" : ""); - fprint_val (sim_log, uptr->capac*((dptr->flags & DEV_SECTORS) ? 512 : 1), 10, T_ADDR_W, PV_LEFT); - fprintf (sim_log, "%s)\n", (ctx->capac_factor == 2) ? "W" : ""); - } + sim_printf ("%s%d: non expandable disk %s is smaller than simulated device (", sim_dname (dptr), (int)(uptr-dptr->units), cptr); + sim_print_val ((t_addr)(capac/ctx->capac_factor), 10, T_ADDR_W, PV_LEFT); + sim_printf ("%s < ", (ctx->capac_factor == 2) ? "W" : ""); + sim_print_val (uptr->capac*((dptr->flags & DEV_SECTORS) ? 512 : 1), 10, T_ADDR_W, PV_LEFT); + sim_printf ("%s)\n", (ctx->capac_factor == 2) ? "W" : ""); } } } @@ -1461,11 +1430,11 @@ if ((namebuf = (char *) malloc (1 + strlen (uptr->filename))) == NULL) { } strcpy (namebuf, uptr->filename); if ((c = strrchr (namebuf, '/'))) - strcpy (namebuf, c+1); + memcpy (namebuf, c+1, strlen(c+1)+1); if ((c = strrchr (namebuf, '\\'))) - strcpy (namebuf, c+1); + memcpy (namebuf, c+1, strlen(c+1)+1); if ((c = strrchr (namebuf, ']'))) - strcpy (namebuf, c+1); + memcpy (namebuf, c+1, strlen(c+1)+1); packid = eth_crc32(0, namebuf, strlen (namebuf)); buf[0] = (uint16)packid; buf[1] = (uint16)(packid >> 16) & 0x7FFF; /* Make sure MSB is clear */ @@ -2815,7 +2784,7 @@ if ((sDynamic) && } if (!*szParentVHDPath) { Return = EINVAL; /* File Corrupt */ - fprintf (stderr, "Error Invalid Parent VHD for Differencing VHD\n"); + sim_printf ("Error Invalid Parent VHD for Differencing VHD\n"); } } } @@ -3024,7 +2993,7 @@ static FILE *sim_vhd_disk_merge (const char *szVHDPath, char **ParentVHD) ++BlocksToMerge; } if (!sim_quiet) - printf ("Merging %s\ninto %s\n", szVHDPath, hVHD->ParentVHDPath); + sim_printf ("Merging %s\ninto %s\n", szVHDPath, hVHD->ParentVHDPath); for (BlockNumber=NeededBlock=0; BlockNumber < NtoHl (hVHD->Dynamic.MaxTableEntries); ++BlockNumber) { uint32 BlockSectors = SectorsPerBlock; @@ -3048,7 +3017,7 @@ static FILE *sim_vhd_disk_merge (const char *szVHDPath, char **ParentVHD) SectorsPerBlock*BlockNumber)) break; if (!sim_quiet) - printf ("Merged %dMB. %d%% complete.\r", (int)((((float)NeededBlock)*SectorsPerBlock)*SectorSize/1000000), (int)((((float)NeededBlock)*100)/BlocksToMerge)); + sim_printf ("Merged %dMB. %d%% complete.\r", (int)((((float)NeededBlock)*SectorsPerBlock)*SectorSize/1000000), (int)((((float)NeededBlock)*100)/BlocksToMerge)); hVHD->BAT[BlockNumber] = VHD_BAT_FREE_ENTRY; } if (BlockNumber < NtoHl (hVHD->Dynamic.MaxTableEntries)) { @@ -3057,7 +3026,7 @@ static FILE *sim_vhd_disk_merge (const char *szVHDPath, char **ParentVHD) else { Status = 0; if (!sim_quiet) - printf ("Merged %dMB. 100%% complete.\n", (int)((((float)NeededBlock)*SectorsPerBlock)*SectorSize/1000000)); + sim_printf ("Merged %dMB. 100%% complete.\n", (int)((((float)NeededBlock)*SectorsPerBlock)*SectorSize/1000000)); fclose (hVHD->File); hVHD->File = NULL; remove (szVHDPath); @@ -3373,7 +3342,7 @@ if ((szFileSpec[0] != '/') || (strchr (szFileSpec, ':'))) else strncpy (szFullFileSpecBuffer, szFileSpec, BufferSize); if ((c = strstr (szFullFileSpecBuffer, "]/"))) - strcpy (c+1, c+2); + memcpy (c+1, c+2, strlen(c+2)+1); memset (szFullFileSpecBuffer + strlen (szFullFileSpecBuffer), 0, BufferSize - strlen (szFullFileSpecBuffer)); #endif } @@ -3386,6 +3355,8 @@ HostPathToVhdPath (const char *szHostPath, char *c, *d; strncpy (szVhdPath, szHostPath, VhdPathSize-1); +if ((szVhdPath[1] == ':') && islower(szVhdPath[0])) + szVhdPath[0] = toupper(szVhdPath[0]); szVhdPath[VhdPathSize-1] = '\0'; if ((c = strrchr (szVhdPath, ']'))) { *c = '\0'; @@ -3399,14 +3370,14 @@ if ((c = strrchr (szVhdPath, ']'))) { while ((c = strchr (szVhdPath, '/'))) *c = '\\'; for (c = strstr (szVhdPath, "\\.\\"); c; c = strstr (szVhdPath, "\\.\\")) - strcpy (c, c+2); + memcpy (c, c+2, strlen(c+2)+1); for (c = strstr (szVhdPath, "\\\\"); c; c = strstr (szVhdPath, "\\\\")) - strcpy (c, c+1); + memcpy (c, c+1, strlen(c+1)+1); while ((c = strstr (szVhdPath, "\\..\\"))) { *c = '\0'; d = strrchr (szVhdPath, '\\'); if (d) - strcpy (d, c+3); + memcpy (d, c+3, strlen(c+3)+1); else return d; } @@ -3460,6 +3431,7 @@ char *FullParentVHDPath = NULL; char *RelativeParentVHDPathUnicode = NULL; char *FullParentVHDPathUnicode = NULL; char *FullVHDPath = NULL; +char *TempPath = NULL; size_t i, RelativeMatch, UpDirectories, LocatorsWritten = 0; int64 LocatorPosition; @@ -3486,14 +3458,15 @@ FullParentVHDPath = (char*) calloc (1, BytesPerSector+2); RelativeParentVHDPathUnicode = (char*) calloc (1, BytesPerSector+2); FullParentVHDPathUnicode = (char*) calloc (1, BytesPerSector+2); FullVHDPath = (char*) calloc (1, BytesPerSector+2); -ExpandToFullPath (szParentVHDPath, FullParentVHDPath, BytesPerSector); -HostPathToVhdPath (FullParentVHDPath, FullParentVHDPath, BytesPerSector); +TempPath = (char*) calloc (1, BytesPerSector+2); +ExpandToFullPath (szParentVHDPath, TempPath, BytesPerSector); +HostPathToVhdPath (TempPath, FullParentVHDPath, BytesPerSector); for (i=0; i < strlen (FullParentVHDPath); i++) hVHD->Dynamic.ParentUnicodeName[i*2+1] = FullParentVHDPath[i]; /* Big Endian Unicode */ for (i=0; i < strlen (FullParentVHDPath); i++) FullParentVHDPathUnicode[i*2] = FullParentVHDPath[i]; /* Little Endian Unicode */ -ExpandToFullPath (szVHDPath, FullVHDPath, BytesPerSector); -HostPathToVhdPath (FullVHDPath, FullVHDPath, BytesPerSector); +ExpandToFullPath (szVHDPath, TempPath, BytesPerSector); +HostPathToVhdPath (TempPath, FullVHDPath, BytesPerSector); for (i=0, RelativeMatch=UpDirectories=0; iDynamic.TableOffset = NtoHll (((LocatorPosition+LocatorsWritten*BytesPerSector + VHD_DATA_BLOCK_ALIGNMENT - 1)/VHD_DATA_BLOCK_ALIGNMENT)*VHD_DATA_BLOCK_ALIGNMENT); +hVHD->Dynamic.Checksum = 0; hVHD->Dynamic.Checksum = NtoHl (CalculateVhdFooterChecksum (&hVHD->Dynamic, sizeof(hVHD->Dynamic))); hVHD->Footer.Checksum = 0; hVHD->Footer.DiskType = NtoHl (VHD_DT_Differencing); @@ -3595,6 +3569,7 @@ free (FullParentVHDPath); free (RelativeParentVHDPathUnicode); free (FullParentVHDPathUnicode); free (FullVHDPath); +free (TempPath); sim_vhd_disk_close ((FILE *)hVHD); hVHD = NULL; if (Status) { diff --git a/sim_ether.c b/sim_ether.c index e62c3051..2cd6b1d8 100644 --- a/sim_ether.c +++ b/sim_ether.c @@ -735,8 +735,7 @@ t_stat ethq_init(ETH_QUE* que, int max) if (!que->item) { /* failed to allocate memory */ char* msg = "EthQ: failed to allocate dynamic queue[%d]\r\n"; - printf(msg, max); - if (sim_log) fprintf(sim_log, msg, max); + sim_printf(msg, max); return SCPE_MEM; }; que->max = max; @@ -1005,8 +1004,7 @@ static void load_function(char* function, _func* func_ptr) { if (*func_ptr == 0) { char* msg = "Eth: Failed to find function '%s' in %s\r\n"; - printf (msg, function, lib_name); - if (sim_log) fprintf (sim_log, msg, function, lib_name); + sim_printf (msg, function, lib_name); lib_loaded = 3; } } @@ -1031,12 +1029,8 @@ int load_pcap(void) { "Eth: You must install libpcap to use networking\r\n"; #endif - printf (msg, lib_name); - printf ("%s", msg2); - if (sim_log) { - fprintf (sim_log, msg, lib_name); - fprintf (sim_log, "%s", msg2); - } + sim_printf (msg, lib_name); + sim_printf ("%s", msg2); lib_loaded = 2; break; } else { @@ -1071,10 +1065,7 @@ int load_pcap(void) { if (lib_loaded == 1) { /* log successful load */ - char* version = p_pcap_lib_version(); - printf("%s\n", version); - if (sim_log) - fprintf(sim_log, "%s\n", version); + sim_printf("%s\n", p_pcap_lib_version()); } break; default: /* loaded or failed */ @@ -1693,8 +1684,7 @@ t_stat eth_set_async (ETH_DEV *dev, int latency) { #if !defined(USE_READER_THREAD) || !defined(SIM_ASYNCH_IO) char *msg = "Eth: can't operate asynchronously, must poll\r\n"; -printf ("%s", msg); -if (sim_log) fprintf (sim_log, "%s", msg); +sim_printf ("%s", msg); return SCPE_NOFNC; #else int wakeup_needed; @@ -1772,8 +1762,7 @@ if (0 == strncmp("tap:", savname, 4)) { #if defined(HAVE_TAP_NETWORK) if (!strcmp(savname, "tap:tapN")) { msg = "Eth: Must specify actual tap device name (i.e. tap:tap0)\r\n"; - printf (msg, errbuf); - if (sim_log) fprintf (sim_log, msg, errbuf); + sim_printf (msg, errbuf); return SCPE_OPENERR; } #endif @@ -1858,8 +1847,7 @@ else memset(&voa, 0, sizeof(voa)); if (!strcmp(savname, "vde:vdedevice")) { msg = "Eth: Must specify actual vde device name (i.e. vde:/tmp/switch)\r\n"; - printf (msg, errbuf); - if (sim_log) fprintf (sim_log, msg, errbuf); + sim_printf (msg, errbuf); return SCPE_OPENERR; } if (!(dev->handle = (void*) vde_open(savname+4, "simh", &voa))) @@ -1879,8 +1867,7 @@ else if (!strcmp(savname, "udp:sourceport:remotehost:remoteport")) { msg = "Eth: Must specify actual udp host and ports(i.e. udp:1224:somehost.com:2234)\r\n"; - printf (msg, errbuf); - if (sim_log) fprintf (sim_log, msg, errbuf); + sim_printf (msg, errbuf); return SCPE_OPENERR; } @@ -1893,8 +1880,7 @@ else if ((SCPE_OK == sim_parse_addr (hostport, NULL, 0, NULL, NULL, 0, NULL, "localhost")) && (0 == strcmp (localport, port))) { msg = "Eth: Must specify different udp localhost ports\r\n"; - printf (msg, errbuf); - if (sim_log) fprintf (sim_log, msg, errbuf); + sim_printf (msg, errbuf); return SCPE_OPENERR; } dev->fd_handle = sim_connect_sock_ex (localport, hostport, NULL, NULL, TRUE, FALSE); @@ -1908,8 +1894,7 @@ else dev->handle = (void*) pcap_open_live(savname, bufsz, ETH_PROMISC, PCAP_READ_TIMEOUT, errbuf); if (!dev->handle) { /* can't open device */ msg = "Eth: pcap_open_live error - %s\r\n"; - printf (msg, errbuf); - if (sim_log) fprintf (sim_log, msg, errbuf); + sim_printf (msg, errbuf); return SCPE_OPENERR; } dev->eth_api = ETH_API_PCAP; @@ -1920,13 +1905,11 @@ else } if (errbuf[0]) { msg = "Eth: open error - %s\r\n"; - printf (msg, errbuf); - if (sim_log) fprintf (sim_log, msg, errbuf); + sim_printf (msg, errbuf); return SCPE_OPENERR; } msg = "Eth: opened OS device %s\r\n"; -printf (msg, savname); -if (sim_log) fprintf (sim_log, msg, savname); +sim_printf (msg, savname); /* get the NIC's hardware MAC address */ eth_get_nic_hw_addr(dev, savname); @@ -1982,8 +1965,7 @@ if (1) { /* set ethernet device non-blocking so pcap_dispatch() doesn't hang */ if ((dev->eth_api == ETH_API_PCAP) && (pcap_setnonblock (dev->handle, 1, errbuf) == -1)) { msg = "Eth: Failed to set non-blocking: %s\r\n"; - printf (msg, errbuf); - if (sim_log) fprintf (sim_log, msg, errbuf); + sim_printf (msg, errbuf); } #endif #endif /* !defined (USE_READER_THREAD */ @@ -2065,8 +2047,7 @@ switch (dev->eth_api) { break; #endif } -printf (msg, dev->name); -if (sim_log) fprintf (sim_log, msg, dev->name); +sim_printf (msg, dev->name); /* clean up the mess */ free(dev->name); @@ -2183,8 +2164,7 @@ if (status != SCPE_OK) { "which is at least 0.9 from your OS vendor or www.tcpdump.org\r\n" : "Eth: Error Transmitting packet: %s\r\n" "You may need to run as root.\r\n"; - printf(msg, strerror(errno)); - if (sim_log) fprintf (sim_log, msg, strerror(errno)); + sim_printf(msg, strerror(errno)); return status; } @@ -3216,22 +3196,17 @@ if (dev->eth_api == ETH_API_PCAP) { if ((status = pcap_compile(dev->handle, &bpf, buf, 1, bpf_netmask)) < 0) { sprintf(errbuf, "%s", pcap_geterr(dev->handle)); msg = "Eth: pcap_compile error: %s\r\n"; - printf(msg, errbuf); - if (sim_log) fprintf (sim_log, msg, errbuf); - sim_debug(dev->dbit, dev->dptr, "Eth: pcap_compile error: %s\n", errbuf); + sim_printf(msg, errbuf); /* show erroneous BPF string */ msg = "Eth: BPF string is: |%s|\r\n"; - printf (msg, buf); - if (sim_log) fprintf (sim_log, msg, buf); + sim_printf (msg, buf); } else { /* apply compiled filter string */ if ((status = pcap_setfilter(dev->handle, &bpf)) < 0) { sprintf(errbuf, "%s", pcap_geterr(dev->handle)); msg = "Eth: pcap_setfilter error: %s\r\n"; - printf(msg, errbuf); - if (sim_log) fprintf (sim_log, msg, errbuf); - sim_debug(dev->dbit, dev->dptr, "Eth: pcap_setfilter error: %s\n", errbuf); + sim_printf(msg, errbuf); } else { #ifdef USE_SETNONBLOCK @@ -3382,8 +3357,7 @@ errbuf[0] = '\0'; /* retrieve the device list */ if (pcap_findalldevs(&alldevs, errbuf) == -1) { char* msg = "Eth: error in pcap_findalldevs: %s\r\n"; - printf (msg, errbuf); - if (sim_log) fprintf (sim_log, msg, errbuf); + sim_printf (msg, errbuf); } else { /* copy device list into the passed structure */ @@ -3407,8 +3381,7 @@ i = eth_host_devices(i, max, list); /* If no devices were found and an error message was left in the buffer, display it */ if ((i == 0) && (errbuf[0])) { char* msg = "Eth: pcap_findalldevs warning: %s\r\n"; - printf (msg, errbuf); - if (sim_log) fprintf (sim_log, msg, errbuf); + sim_printf (msg, errbuf); } /* return device count */ diff --git a/sim_serial.c b/sim_serial.c index c7af62f5..703b171b 100644 --- a/sim_serial.c +++ b/sim_serial.c @@ -215,9 +215,7 @@ for (i=0; itape_ctx; diff --git a/sim_timer.c b/sim_timer.c index 4663c509..d79929a0 100644 --- a/sim_timer.c +++ b/sim_timer.c @@ -118,12 +118,14 @@ UNIT sim_throt_unit = { UDATA (&sim_throt_svc, 0, 0) }; #define DBG_TRC 0x004 /* tracing */ #define DBG_CAL 0x008 /* calibration activities */ #define DBG_TIM 0x010 /* timer thread activities */ +#define DBG_THR 0x020 /* throttle activities */ DEBTAB sim_timer_debug[] = { {"TRACE", DBG_TRC}, {"IDLE", DBG_IDL}, {"QUEUE", DBG_QUE}, {"CALIB", DBG_CAL}, {"TIME", DBG_TIM}, + {"THROT", DBG_THR}, {0} }; @@ -907,15 +909,11 @@ t_stat r; uint32 v; if (sim_idle_rate_ms == 0) { - printf ("Idling is not available, Minimum OS sleep time is %dms\n", sim_os_sleep_min_ms); - if (sim_log) - fprintf (sim_log, "Idling is not available, Minimum OS sleep time is %dms\n", sim_os_sleep_min_ms); + sim_printf ("Idling is not available, Minimum OS sleep time is %dms\n", sim_os_sleep_min_ms); return SCPE_NOFNC; } if ((val != 0) && (sim_idle_rate_ms > (uint32) val)) { - printf ("Idling is not available, Minimum OS sleep time is %dms, Requied minimum OS sleep is %dms\n", sim_os_sleep_min_ms, val); - if (sim_log) - fprintf (sim_log, "Idling is not available, Minimum OS sleep time is %dms, Requied minimum OS sleep is %dms\n", sim_os_sleep_min_ms, val); + sim_printf ("Idling is not available, Minimum OS sleep time is %dms, Requied minimum OS sleep is %dms\n", sim_os_sleep_min_ms, val); return SCPE_NOFNC; } if (cptr) { @@ -927,9 +925,7 @@ if (cptr) { sim_idle_enab = TRUE; if (sim_throt_type != SIM_THROT_NONE) { sim_set_throt (0, NULL); - printf ("Throttling disabled\n"); - if (sim_log) - fprintf (sim_log, "Throttling disabled\n"); + sim_printf ("Throttling disabled\n"); } return SCPE_OK; } @@ -969,9 +965,7 @@ if (arg == 0) { sim_throt_cancel (); } else if (sim_idle_rate_ms == 0) { - printf ("Throttling is not available, Minimum OS sleep time is %dms\n", sim_os_sleep_min_ms); - if (sim_log) - fprintf (sim_log, "Throttling is not available, Minimum OS sleep time is %dms\n", sim_os_sleep_min_ms); + sim_printf ("Throttling is not available, Minimum OS sleep time is %dms\n", sim_os_sleep_min_ms); return SCPE_NOFNC; } else { @@ -995,9 +989,7 @@ else { } else return SCPE_ARG; if (sim_idle_enab) { - printf ("Idling disabled\n"); - if (sim_log) - fprintf (sim_log, "Idling disabled\n"); + sim_printf ("Idling disabled\n"); sim_clr_idle (NULL, 0, NULL, NULL); } sim_throt_val = (uint32) val; @@ -1121,8 +1113,8 @@ switch (sim_throt_state) { } sim_throt_ms_start = sim_throt_ms_stop; sim_throt_state = 2; -// fprintf (stderr, "Throttle values a_cps = %f, d_cps = %f, wait = %d\n", -// a_cps, d_cps, sim_throt_wait); + sim_debug (DBG_THR, &sim_timer_dev, "sim_throt_svc() Throttle values a_cps = %f, d_cps = %f, wait = %d\n", + a_cps, d_cps, sim_throt_wait); } break; diff --git a/sim_tmxr.c b/sim_tmxr.c index 9f34f976..a4214a8f 100644 --- a/sim_tmxr.c +++ b/sim_tmxr.c @@ -826,8 +826,6 @@ if (tptr == NULL) /* no more mem? */ if (mp->port) /* copy port */ sprintf (growstring(&tptr, 13 + strlen (mp->port)), "%s%s", mp->port, mp->notelnet ? ";notelnet" : ""); -if (mp->buffered) - sprintf (growstring(&tptr, 32), ",Buffered=%d", mp->buffered); if (mp->logfiletmpl[0]) /* logfile info */ sprintf (growstring(&tptr, 7 + strlen (mp->logfiletmpl)), ",Log=%s", mp->logfiletmpl); while ((*tptr == ',') || (*tptr == ' ')) @@ -1377,12 +1375,12 @@ if ((lp->sock) || (lp->serport) || (lp->loopback)) { else if ((lp->master) || (lp->mp && lp->mp->master) || (lp->port && lp->destination)) - incoming_state = TMXR_MDM_DCD | TMXR_MDM_DSR; + incoming_state = TMXR_MDM_DSR; else incoming_state = 0; lp->modembits |= incoming_state; dptr = (lp->dptr ? lp->dptr : (lp->mp ? lp->mp->dptr : NULL)); -if (sim_deb && lp->mp && dptr) { +if ((lp->modembits != before_modem_bits) && (sim_deb && lp->mp && dptr)) { sim_debug_bits (TMXR_DBG_MDM, dptr, tmxr_modem_bits, before_modem_bits, lp->modembits, FALSE); sim_debug (TMXR_DBG_MDM, dptr, " - Line %d - %p\n", (int)(lp-lp->mp->ldsc), lp->txb); } @@ -2024,19 +2022,27 @@ if (lp->serport) { /* close current serial connection * lp->destination = NULL; } tmxr_set_line_loopback (lp, FALSE); -if ((lp->mp->uptr) && ((lp->uptr == NULL) || (lp->uptr == lp->mp->uptr))) { - /* Revise the unit's connect string to reflect the current attachments */ - lp->mp->uptr->filename = tmxr_mux_attach_string (lp->mp->uptr->filename, lp->mp); - /* No connections or listeners exist, then we're equivalent to being fully detached. We should reflect that */ - if (lp->mp->uptr->filename == NULL) - tmxr_detach (lp->mp, lp->mp->uptr); - } } t_stat tmxr_detach_ln (TMLN *lp) { -tmxr_debug_trace_line (lp, "tmxr_detaach_ln()"); +UNIT *uptr = NULL; + +tmxr_debug_trace_line (lp, "tmxr_detach_ln()"); _mux_detach_line (lp, TRUE, TRUE); +if (lp->mp) + if (lp->uptr) + uptr = lp->uptr; + else + if (lp->mp->uptr) + uptr = lp->mp->uptr; +if (uptr && uptr->filename) { + /* Revise the unit's connect string to reflect the current attachments */ + uptr->filename = tmxr_mux_attach_string (uptr->filename, lp->mp); + /* No connections or listeners exist, then we're equivalent to being fully detached. We should reflect that */ + if (uptr->filename == NULL) + tmxr_detach (lp->mp, uptr); + } return SCPE_OK; } @@ -2061,7 +2067,7 @@ char tbuf[CBUFSIZE], listen[CBUFSIZE], destination[CBUFSIZE], SOCKET sock; SERHANDLE serport; char *tptr = cptr; -t_bool nolog, notelnet, listennotelnet, unbuffered, modem_control, loopback, datagram, packet; +t_bool nolog, notelnet, listennotelnet, modem_control, loopback, datagram, packet; TMLN *lp; t_stat r = SCPE_ARG; @@ -2079,9 +2085,11 @@ while (*tptr) { memset(buffered, '\0', sizeof(buffered)); memset(port, '\0', sizeof(port)); memset(option, '\0', sizeof(option)); - nolog = notelnet = listennotelnet = unbuffered = loopback = FALSE; + nolog = notelnet = listennotelnet = loopback = FALSE; datagram = mp->datagram; packet = mp->packet; + if (mp->buffered) + sprintf(buffered, "%d", mp->buffered); if (line != -1) notelnet = listennotelnet = mp->notelnet; modem_control = mp->modem_control; @@ -2119,7 +2127,7 @@ while (*tptr) { (0 == MATCH_CMD (gbuf, "UNBUFFERED"))) { if ((NULL != cptr) && ('\0' != *cptr)) return SCPE_2MARG; - unbuffered = TRUE; + buffered[0] = '\0'; continue; } if (0 == MATCH_CMD (gbuf, "BUFFERED")) { @@ -2265,32 +2273,22 @@ while (*tptr) { } } } - if (unbuffered) { - if (mp->buffered) { - mp->buffered = 0; - for (i = 0; i < mp->lines; i++) { /* default line buffers */ - lp = mp->ldsc + i; - lp->rxbsz = TMXR_MAXBUF; - lp->rxb = (char *)realloc(lp->rxb, lp->rxbsz); - lp->rbr = (char *)realloc(lp->rbr, lp->rxbsz); - lp->txbsz = TMXR_MAXBUF; - lp->txb = (char *)realloc(lp->txb, lp->txbsz); - lp->txbfd = lp->txbpi = lp->txbpr = 0; - } - } - } - if (buffered[0]) { - mp->buffered = atoi(buffered); - for (i = 0; i < mp->lines; i++) { /* initialize line buffers */ - lp = mp->ldsc + i; - lp->txbsz = mp->buffered; + for (i = 0; i < mp->lines; i++) { /* initialize line buffers */ + lp = mp->ldsc + i; + if (buffered[0]) { + lp->txbsz = atoi(buffered); lp->txbfd = 1; - lp->txb = (char *)realloc(lp->txb, lp->txbsz); - lp->txbpi = lp->txbpr = 0; - lp->rxbsz = mp->buffered; - lp->rxb = (char *)realloc(lp->rxb, lp->rxbsz); - lp->rbr = (char *)realloc(lp->rbr, lp->rxbsz); + lp->rxbsz = atoi(buffered); } + else { + lp->txbsz = TMXR_MAXBUF; + lp->txbfd = 0; + lp->rxbsz = TMXR_MAXBUF; + } + lp->txbpi = lp->txbpr = 0; + lp->txb = (char *)realloc(lp->txb, lp->txbsz); + lp->rxb = (char *)realloc(lp->rxb, lp->rxbsz); + lp->rbr = (char *)realloc(lp->rbr, lp->rxbsz); } if (nolog) { mp->logfiletmpl[0] = '\0'; @@ -2316,9 +2314,7 @@ while (*tptr) { free (mp->port); mp->port = NULL; } - printf ("Listening on port %s\n", listen); - if (sim_log) - fprintf (sim_log, "Listening on port %s\n", listen); + sim_printf ("Listening on port %s\n", listen); mp->port = (char *)realloc (mp->port, 1 + strlen (listen)); strcpy (mp->port, listen); /* save port */ mp->master = sock; /* save master socket */ @@ -2343,9 +2339,7 @@ while (*tptr) { if (loopback) { if (mp->lines > 1) return SCPE_ARG; /* ambiguous */ - printf ("Operating in loopback mode\n"); - if (sim_log) - fprintf (sim_log, "Operating in loopback mode\n"); + sim_printf ("Operating in loopback mode\n"); for (i = 0; i < mp->lines; i++) { lp = mp->ldsc + i; tmxr_set_line_loopback (lp, loopback); @@ -2429,23 +2423,19 @@ while (*tptr) { return r; } } - if (unbuffered) { - lp->txbsz = TMXR_MAXBUF; - lp->txb = (char *)realloc (lp->txb, lp->txbsz); - lp->txbfd = lp->txbpi = lp->txbpr = 0; - lp->rxbsz = lp->txbsz; - lp->rxb = (char *)realloc(lp->rxb, lp->rxbsz); - lp->rbr = (char *)realloc(lp->rbr, lp->rxbsz); + if (buffered[0] == '\0') { + lp->rxbsz = lp->txbsz = TMXR_MAXBUF; + lp->txbfd = 0; } - if (buffered[0]) { - lp->txbsz = atoi(buffered); + else { + lp->rxbsz = lp->txbsz = atoi(buffered); lp->txbfd = 1; - lp->txb = (char *)realloc (lp->txb, lp->txbsz); - lp->txbpi = lp->txbpr = 0; - lp->rxbsz = lp->txbsz; - lp->rxb = (char *)realloc(lp->rxb, lp->rxbsz); - lp->rbr = (char *)realloc(lp->rbr, lp->rxbsz); } + lp->txbpi = lp->txbpr = 0; + lp->txb = (char *)realloc (lp->txb, lp->txbsz); + lp->rxb = (char *)realloc(lp->rxb, lp->rxbsz); + lp->rbr = (char *)realloc(lp->rbr, lp->rxbsz); + lp->packet = packet; if (nolog) { free(lp->txlogname); lp->txlogname = NULL; @@ -2463,9 +2453,7 @@ while (*tptr) { if (sock == INVALID_SOCKET) /* open error */ return SCPE_OPENERR; _mux_detach_line (lp, TRUE, FALSE); - printf ("Line %d Listening on port %s\n", line, listen); - if (sim_log) - fprintf (sim_log, "Line %d Listening on port %s\n", line, listen); + sim_printf ("Line %d Listening on port %s\n", line, listen); lp->port = (char *)realloc (lp->port, 1 + strlen (listen)); strcpy (lp->port, listen); /* save port */ lp->master = sock; /* save master socket */ @@ -2502,7 +2490,6 @@ while (*tptr) { else return SCPE_ARG; } - lp->packet = packet; sock = sim_connect_sock_ex (datagram ? listen : NULL, destination, "localhost", NULL, datagram, packet); if (sock != INVALID_SOCKET) { _mux_detach_line (lp, FALSE, TRUE); @@ -2524,9 +2511,7 @@ while (*tptr) { } if (loopback) { tmxr_set_line_loopback (lp, loopback); - printf ("Line %d operating in loopback mode\n", line); - if (sim_log) - fprintf (sim_log, "Line %d operating in loopback mode\n", line); + sim_printf ("Line %d operating in loopback mode\n", line); } lp->modem_control = modem_control; r = SCPE_OK; @@ -2805,7 +2790,7 @@ while (sim_asynch_enabled) { wait_count = 0; if (select_errno == EINTR) break; - fprintf (stderr, "select() returned -1, errno=%d - %s\r\n", select_errno, strerror(select_errno)); + sim_printf ("select() returned -1, errno=%d - %s\r\n", select_errno, strerror(select_errno)); abort(); break; default: @@ -2926,7 +2911,7 @@ while (sim_asynch_enabled) { pthread_mutex_lock (&sim_tmxr_poll_lock); switch (status) { case WAIT_FAILED: - fprintf (stderr, "WaitForMultipleObjects() Failed, LastError=%d\r\n", GetLastError()); + sim_printf ("WaitForMultipleObjects() Failed, LastError=%d\r\n", GetLastError()); abort(); break; case WAIT_TIMEOUT: @@ -3041,7 +3026,7 @@ while (sim_asynch_enabled) { IO$_READLBLK | IO$M_NOECHO | IO$M_NOFILTR | IO$M_TIMED | IO$M_TRMNOECHO, &iosb, 0, 0, buf, 1, 1, term, 0, 0); if (status != SS$_NORMAL) { - fprintf (stderr, "_tmxr_serial_line_poll() - QIO Failed, Status=%d\r\n", status); + sim_printf ("_tmxr_serial_line_poll() - QIO Failed, Status=%d\r\n", status); abort(); } wait_count = 0; @@ -3307,20 +3292,27 @@ else { TMLN *lp; char *attach; - fprintf(st, "Multiplexer device: %s, ", (mp->dptr ? sim_dname (mp->dptr) : "")); - attach = tmxr_mux_attach_string (NULL, mp); - fprintf(st, "attached to %s, ", attach); - free (attach); + fprintf(st, "Multiplexer device: %s", (mp->dptr ? sim_dname (mp->dptr) : "")); if (mp->lines > 1) { - tmxr_show_lines(st, NULL, 0, mp); fprintf(st, ", "); + tmxr_show_lines(st, NULL, 0, mp); } - tmxr_show_summ(st, NULL, 0, mp); - fprintf(st, ", sessions=%d", mp->sessions); - if (mp->modem_control) - fprintf(st, ", ModemControl=enabled"); + if (mp->packet) + fprintf(st, ", Packet"); + if (mp->datagram) + fprintf(st, ", UDP"); if (mp->notelnet) fprintf(st, ", Telnet=disabled"); + if (mp->modem_control) + fprintf(st, ", ModemControl=enabled"); + if (mp->buffered) + fprintf(st, ", Buffered=%d", mp->buffered); + attach = tmxr_mux_attach_string (NULL, mp); + if (attach) + fprintf(st, ",\n attached to %s, ", attach); + free (attach); + tmxr_show_summ(st, NULL, 0, mp); + fprintf(st, ", sessions=%d", mp->sessions); fprintf(st, "\n"); for (j = 0; j < mp->lines; j++) { lp = mp->ldsc + j; @@ -3395,6 +3387,7 @@ for (i = 0; i < mp->lines; i++) { /* loop thru conn */ free (lp->port); lp->port = NULL; } + lp->txbfd = 0; free (lp->txb); lp->txb = NULL; free (lp->rxb); @@ -4165,7 +4158,7 @@ for (i = t = 0; i < mp->lines; i++) if ((mp->ldsc[i].sock != 0) || (mp->ldsc[i].serport != 0)) t = t + 1; if (mp->lines > 1) - fprintf (st, "%d connection%s", t, (t != 1) ? "s" : ""); + fprintf (st, "%d current connection%s", t, (t != 1) ? "s" : ""); else fprintf (st, "%s", (t == 1) ? "connected" : "disconnected"); return SCPE_OK; diff --git a/sim_video.c b/sim_video.c index a4bbb8b9..b5210b82 100644 --- a/sim_video.c +++ b/sim_video.c @@ -1521,9 +1521,7 @@ SDL_Init (SDL_INIT_VIDEO); SDL_CreateWindowAndRenderer (vid_width, vid_height, SDL_WINDOW_SHOWN, &vid_window, &vid_renderer); if ((vid_window == NULL) || (vid_renderer == NULL)) { - printf ("%s: Error Creating Video Window: %s\b", sim_dname(vid_dev), SDL_GetError()); - if (sim_log) - fprintf (sim_log, "%s: Error Creating Video Window: %s\b", sim_dname(vid_dev), SDL_GetError()); + sim_printf ("%s: Error Creating Video Window: %s\b", sim_dname(vid_dev), SDL_GetError()); SDL_Quit (); return 0; } @@ -1537,9 +1535,7 @@ vid_texture = SDL_CreateTexture (vid_renderer, SDL_TEXTUREACCESS_STREAMING, vid_width, vid_height); if (!vid_texture) { - printf ("%s: Error configuring Video environment: %s\b", sim_dname(vid_dev), SDL_GetError()); - if (sim_log) - fprintf (sim_log, "%s: Error configuring Video environment: %s\b", sim_dname(vid_dev), SDL_GetError()); + sim_printf ("%s: Error configuring Video environment: %s\b", sim_dname(vid_dev), SDL_GetError()); SDL_DestroyRenderer(vid_renderer); vid_renderer = NULL; SDL_DestroyWindow(vid_window);