diff --git a/0readme_39.txt b/0readme_39.txt index e5b3509e..1dfc5fa6 100644 --- a/0readme_39.txt +++ b/0readme_39.txt @@ -34,25 +34,25 @@ components and build network capable simulators if they are available. 1.1.4 PDP11 and VAX (Mark Pizzolato) - - Added DELQA-Plus device. + - added DELQA-Plus device 1.1.5 IA64 VMS Ethernet Support - - Identified compiler version issues and added IA64 support (Matt Burke) + - identified compiler version issues and added IA64 support (Matt Burke) -1.1.6 Visual Studio Projects (Mark Pizzolato) 2. Bugs Fixed Please see the revision history on http://simh.trailing-edge.com or in the source module sim_rev.h. + 3. Status Report -This is the last release of SimH for which I will be sole editor. After this +This is the last release of SimH for which I will be lead editor. After this release, the source is moving to a public repository: - +https://github.com/markpizz/simh under the general editorship of Dave Hittner and Mark Pizzolato. The status of the individual simulators is as follows: @@ -113,7 +113,7 @@ Stable and working; runs available software. 3.13 IBM 1620 -Hand debug only. No software for it has been found or tested. +Hand debug only. No software for it has been found or tested. 3.14 IBM 7094 @@ -126,7 +126,7 @@ Stable and working, but not really supported. Runs available software. 3.16 IBM 1130 -Stable and working; runs available software. Supported and edited by +Stable and working; runs available software. Supported and edited by Brian Knittel. 3.17 HP 2100/1000 @@ -140,7 +140,7 @@ Stable and working; runs available software. 3.19 GRI-909/99 -Hand debug only. No software for it has been found or tested. +Hand debug only. No software for it has been found or tested. 3.20 SDS-940 @@ -168,10 +168,23 @@ Bill Beech 3.25 Sigma 32b Incomplete; more work is needed on the peripherals for accuracy. +Included in the beta simulators package. 3.26 Alpha -Incomplete; essentially just an EV-5 (21164) chip emulator. +Incomplete; essentially just an EV-5 (21164) chip emulator. Included +in the beta simulators package. + +3.27 SAGE + +Incomplete. Included in the beta simulators package. + +3.28 SC1 + +Internal simulator for SiCortex supercomputer; intended as an example +of implementing an SMP system in the current SimH structure. Included +in the beta simulators package. + 4. Suggestions for Future Work @@ -198,4 +211,3 @@ Incomplete; essentially just an EV-5 (21164) chip emulator. - Data General MV8000 (if a hobbyist license can be obtained for AOS) - Alpha simulator - HP 3000 (16b) simulator with MPE - diff --git a/0readme_ethernet.txt b/0readme_ethernet.txt index 841079e2..eaa2709f 100644 --- a/0readme_ethernet.txt +++ b/0readme_ethernet.txt @@ -156,9 +156,9 @@ Note 2: Root access will likely be needed to configure or start the vde Note 3: Simulators running using VDE networking can run without root privilege. -Linux (Ubuntu 10.04): +Linux (Ubuntu 11.10): apt-get install make - apt-get install libvdeplug-dev + apt-get install libvdeplug2-dev apt-get install vde2 vde_switch -s /tmp/switch1 -tap tap0 -m 666 @@ -207,7 +207,7 @@ Building on Windows: The contents of the windows-build directory can be downloaded from: - https://github.com/downloads/markpizz/simh/windows-build.zip + https://github.com/downloads/simh/simh/windows-build.zip There are Windows batch files provided to initiate compiles using the MinGW diff --git a/ALTAIR/altair_cpu.c b/ALTAIR/altair_cpu.c index 80fce7d6..196893c4 100644 --- a/ALTAIR/altair_cpu.c +++ b/ALTAIR/altair_cpu.c @@ -313,7 +313,7 @@ int32 sim_instr (void) while (reason == 0) { /* loop until halted */ if (sim_interval <= 0) { /* check clock queue */ - if (reason = sim_process_event ()) break; + if ((reason = sim_process_event ())) break; } if (int_req > 0) { /* interrupt? */ diff --git a/ALTAIR/altair_dsk.c b/ALTAIR/altair_dsk.c index 64ef739c..1d1f092c 100644 --- a/ALTAIR/altair_dsk.c +++ b/ALTAIR/altair_dsk.c @@ -218,8 +218,8 @@ int32 dsk10(int32 io, int32 data) cur_disk = data & 0x0F; if (data & 0x80) { cur_flags[cur_disk] = 0; /* Disable drive */ - cur_sect[cur_disk = 0377]; - cur_byte[cur_disk = 0377]; + cur_sect[cur_disk] = 0377; + cur_byte[cur_disk] = 0377; return (0); } cur_flags[cur_disk] = 0x1A; /* Enable: head move true */ diff --git a/AltairZ80/altairz80_net.c b/AltairZ80/altairz80_net.c index fa5e5103..1a815486 100644 --- a/AltairZ80/altairz80_net.c +++ b/AltairZ80/altairz80_net.c @@ -150,36 +150,33 @@ static t_stat net_reset(DEVICE *dptr) { } static t_stat net_attach(UNIT *uptr, char *cptr) { - uint32 i, ipa, ipp; - t_stat r = get_ipaddr(cptr, &ipa, &ipp); + uint32 i; + char host[CBUFSIZE], port[CBUFSIZE]; + t_stat r; + + r = sim_parse_addr (cptr, host, sizeof(host), "localhost", port, sizeof(port), "3000"); if (r != SCPE_OK) return SCPE_ARG; - if (ipa == 0) - ipa = 0x7F000001; /* localhost = 127.0.0.1 */ - if (ipp == 0) - ipp = 3000; - net_unit.u3 = ipp; - net_unit.u4 = ipa; net_reset(&net_dev); for (i = 0; i <= MAX_CONNECTIONS; i++) serviceDescriptor[i].ioSocket = 0; if (net_unit.flags & UNIT_SERVER) { net_unit.wait = NET_INIT_POLL_SERVER; - serviceDescriptor[1].masterSocket = sim_master_sock(ipp); + serviceDescriptor[1].masterSocket = sim_master_sock(cptr, NULL); if (serviceDescriptor[1].masterSocket == INVALID_SOCKET) return SCPE_IOERR; } else { net_unit.wait = NET_INIT_POLL_CLIENT; - serviceDescriptor[0].ioSocket = sim_connect_sock(ipa, ipp); + serviceDescriptor[0].ioSocket = sim_connect_sock(cptr, "localhost", "3000"); if (serviceDescriptor[0].ioSocket == INVALID_SOCKET) return SCPE_IOERR; } net_unit.flags |= UNIT_ATT; - net_unit.filename = (char *) calloc(CBUFSIZE, sizeof (char)); /* alloc name buf */ + net_unit.filename = (char *) calloc(1, strlen(cptr)+1); /* alloc name buf */ if (net_unit.filename == NULL) return SCPE_MEM; - strncpy(net_unit.filename, cptr, CBUFSIZE); /* save name */ + strcpy(net_unit.filename, cptr); /* save name */ return SCPE_OK; } @@ -216,7 +213,7 @@ static t_stat net_svc(UNIT *uptr) { } } else if (serviceDescriptor[0].ioSocket == 0) { - serviceDescriptor[0].ioSocket = sim_connect_sock(net_unit.u4, net_unit.u3); + serviceDescriptor[0].ioSocket = sim_connect_sock(net_unit.filename, "localhost", "3000"); if (serviceDescriptor[0].ioSocket == INVALID_SOCKET) return SCPE_IOERR; printf("\rWaiting for server ... Type g (possibly twice) when ready" NLP); diff --git a/GRI/gri_cpu.c b/GRI/gri_cpu.c index 3eb3fa2e..e173f306 100644 --- a/GRI/gri_cpu.c +++ b/GRI/gri_cpu.c @@ -421,7 +421,7 @@ ao_update (); /* update AO */ while (reason == 0) { /* loop until halted */ if (sim_interval <= 0) { /* check clock queue */ - if (reason = sim_process_event ()) + if ((reason = sim_process_event ())) break; } diff --git a/H316/h316_cpu.c b/H316/h316_cpu.c index b1ba29bb..d09a0654 100644 --- a/H316/h316_cpu.c +++ b/H316/h316_cpu.c @@ -424,7 +424,7 @@ reason = 0; while (reason == 0) { /* loop until halted */ if (sim_interval <= 0) { /* check clock queue */ - if (reason = sim_process_event ()) + if ((reason = sim_process_event ())) break; } @@ -458,7 +458,7 @@ if (chan_req) { /* channel request? */ t = iotab[dev] (ioOTA, 0, Read (ad), dev); /* output word */ if ((t & IOT_SKIP) == 0) return STOP_DMAER; - if (r = (t >> IOT_V_REASON)) + if ((r = (t >> IOT_V_REASON))) return r; } if (Q_DMA (i)) { /* DMA? */ @@ -528,7 +528,7 @@ if (hst_lnt) { /* instr hist? */ switch (I_GETOP (MB)) { /* case on <1:6> */ case 001: case 021: case 041: case 061: /* JMP */ - if (reason = Ea (MB, &Y)) /* eff addr */ + if ((reason = Ea (MB, &Y))) /* eff addr */ break; PCQ_ENTRY; /* save PC */ PC = NEWA (PC, Y); /* set new PC */ @@ -537,7 +537,7 @@ switch (I_GETOP (MB)) { /* case on <1:6> */ break; case 002: case 022: case 042: case 062: /* LDA */ - if (reason = Ea (MB, &Y)) /* eff addr */ + if ((reason = Ea (MB, &Y))) /* eff addr */ break; if (dp) { /* double prec? */ AR = Read (Y & ~1); /* get doubleword */ @@ -548,13 +548,13 @@ switch (I_GETOP (MB)) { /* case on <1:6> */ break; case 003: case 023: case 043: case 063: /* ANA */ - if (reason = Ea (MB, &Y)) /* eff addr */ + if ((reason = Ea (MB, &Y))) /* eff addr */ break; AR = AR & Read (Y); break; case 004: case 024: case 044: case 064: /* STA */ - if (reason = Ea (MB, &Y)) /* eff addr */ + if ((reason = Ea (MB, &Y))) /* eff addr */ break; Write (Y, AR); /* store A */ if (dp) { /* double prec? */ @@ -564,13 +564,13 @@ switch (I_GETOP (MB)) { /* case on <1:6> */ break; case 005: case 025: case 045: case 065: /* ERA */ - if (reason = Ea (MB, &Y)) /* eff addr */ + if ((reason = Ea (MB, &Y))) /* eff addr */ break; AR = AR ^ Read (Y); break; case 006: case 026: case 046: case 066: /* ADD */ - if (reason = Ea (MB, &Y)) /* eff addr */ + if ((reason = Ea (MB, &Y))) /* eff addr */ break; if (dp) { /* double prec? */ t1 = GETDBL_S (AR, BR); /* get A'B */ @@ -583,7 +583,7 @@ switch (I_GETOP (MB)) { /* case on <1:6> */ break; case 007: case 027: case 047: case 067: /* SUB */ - if (reason = Ea (MB, &Y)) /* eff addr */ + if ((reason = Ea (MB, &Y))) /* eff addr */ break; if (dp) { /* double prec? */ t1 = GETDBL_S (AR, BR); /* get A'B */ @@ -596,7 +596,7 @@ switch (I_GETOP (MB)) { /* case on <1:6> */ break; case 010: case 030: case 050: case 070: /* JST */ - if (reason = Ea (MB, &Y)) /* eff addr */ + if ((reason = Ea (MB, &Y))) /* eff addr */ break; MB = NEWA (Read (Y), PC); /* merge old PC */ Write (Y, MB); @@ -605,7 +605,7 @@ switch (I_GETOP (MB)) { /* case on <1:6> */ break; case 011: case 031: case 051: case 071: /* CAS */ - if (reason = Ea (MB, &Y)) /* eff addr */ + if ((reason = Ea (MB, &Y))) /* eff addr */ break; MB = Read (Y); if (AR == MB) @@ -615,7 +615,7 @@ switch (I_GETOP (MB)) { /* case on <1:6> */ break; case 012: case 032: case 052: case 072: /* IRS */ - if (reason = Ea (MB, &Y)) /* eff addr */ + if ((reason = Ea (MB, &Y))) /* eff addr */ break; MB = (Read (Y) + 1) & DMASK; /* incr, rewrite */ Write (Y, MB); @@ -624,7 +624,7 @@ switch (I_GETOP (MB)) { /* case on <1:6> */ break; case 013: case 033: case 053: case 073: /* IMA */ - if (reason = Ea (MB, &Y)) /* eff addr */ + if ((reason = Ea (MB, &Y))) /* eff addr */ break; MB = Read (Y); Write (Y, AR); /* A to mem */ @@ -632,13 +632,13 @@ switch (I_GETOP (MB)) { /* case on <1:6> */ break; case 015: case 055: /* STX */ - if (reason = Ea (MB & ~IDX, &Y)) /* eff addr */ + if ((reason = Ea (MB & ~IDX, &Y))) /* eff addr */ break; Write (Y, XR); /* store XR */ break; case 035: case 075: /* LDX */ - if (reason = Ea (MB & ~IDX, &Y)) /* eff addr */ + if ((reason = Ea (MB & ~IDX, &Y))) /* eff addr */ break; XR = Read (Y); /* load XR */ M[M_XR] = XR; /* update mem too */ @@ -646,7 +646,7 @@ switch (I_GETOP (MB)) { /* case on <1:6> */ case 016: case 036: case 056: case 076: /* MPY */ if (cpu_unit.flags & UNIT_HSA) { /* installed? */ - if (reason = Ea (MB, &Y)) /* eff addr */ + if ((reason = Ea (MB, &Y))) /* eff addr */ break; t1 = SEXT (AR) * SEXT (Read (Y)); PUTDBL_Z (t1); @@ -657,7 +657,7 @@ switch (I_GETOP (MB)) { /* case on <1:6> */ case 017: case 037: case 057: case 077: /* DIV */ if (cpu_unit.flags & UNIT_HSA) { /* installed? */ - if (reason = Ea (MB, &Y)) /* eff addr */ + if ((reason = Ea (MB, &Y))) /* eff addr */ break; t2 = SEXT (Read (Y)); /* divr */ if (t2) { /* divr != 0? */ @@ -826,7 +826,7 @@ switch (I_GETOP (MB)) { /* case on <1:6> */ break; case 003: /* "long right arot" */ - if (reason = stop_inst) /* stop on undef? */ + if ((reason = stop_inst)) /* stop on undef? */ break; for (t2 = 0; t2 < t1; t2++) { /* bit by bit */ C = BR & 1; /* C = last out */ @@ -859,7 +859,7 @@ switch (I_GETOP (MB)) { /* case on <1:6> */ break; case 007: /* "short right arot" */ - if (reason = stop_inst) /* stop on undef? */ + if ((reason = stop_inst)) /* stop on undef? */ break; for (t2 = 0; t2 < t1; t2++) { /* bit by bit */ C = AR & 1; /* C = last out */ @@ -899,7 +899,7 @@ switch (I_GETOP (MB)) { /* case on <1:6> */ break; case 013: /* "long left arot" */ - if (reason = stop_inst) /* stop on undef? */ + if ((reason = stop_inst)) /* stop on undef? */ break; for (t2 = 0; t2 < t1; t2++) { /* bit by bit */ AR = (AR << 1) | ((BR >> 14) & 1); @@ -935,7 +935,7 @@ switch (I_GETOP (MB)) { /* case on <1:6> */ break; case 017: /* "short left arot" */ - if (reason = stop_inst) /* stop on undef? */ + if ((reason = stop_inst)) /* stop on undef? */ break; for (t2 = 0; t2 < t1; t2++) { /* bit by bit */ if ((AR & SIGN) != ((AR << 1) & SIGN)) C = 1; @@ -1003,7 +1003,7 @@ switch (I_GETOP (MB)) { /* case on <1:6> */ AR = (AR << 8) & DMASK; else if (MB == 0141340) /* ICA */ AR = ((AR << 8) | (AR >> 8)) & DMASK; - else if (reason = stop_inst) + else if ((reason = stop_inst)) break; else AR = Operate (MB, AR); /* undefined */ break; @@ -1500,7 +1500,7 @@ for (i = 0; i < DEV_MAX; i++) iotab[i] = NULL; for (i = 0; i < (DMA_MAX + DMC_MAX); i++) chan_map[i] = 0; -for (i = 0; dptr = sim_devices[i]; i++) { /* loop thru devices */ +for (i = 0; (dptr = sim_devices[i]); i++) { /* loop thru devices */ dibp = (DIB *) dptr->ctxt; /* get DIB */ if ((dibp == NULL) || (dptr->flags & DEV_DIS)) /* exist, enabled? */ continue; diff --git a/H316/h316_dp.c b/H316/h316_dp.c index 40468675..533c3a86 100644 --- a/H316/h316_dp.c +++ b/H316/h316_dp.c @@ -617,7 +617,7 @@ switch (uptr->FNC) { /* case on function */ case FNC_RCA: /* read current addr */ if (h >= dp_tab[dp_ctype].surf) /* invalid head? */ return dp_done (1, STA_ADRER); /* error */ - if (r = dp_rdtrk (uptr, dpxb, uptr->CYL, h)) /* get track; error? */ + if ((r = dp_rdtrk (uptr, dpxb, uptr->CYL, h))) /* get track; error? */ return r; dp_rptr = 0; /* init rec ptr */ if (dpxb[dp_rptr + REC_LNT] == 0) /* unformated? */ @@ -722,7 +722,7 @@ switch (uptr->FNC) { /* case on function */ case FNC_RW: /* read/write */ if (h >= dp_tab[dp_ctype].surf) /* invalid head? */ return dp_done (1, STA_ADRER); /* error */ - if (r = dp_rdtrk (uptr, dpxb, uptr->CYL, h)) /* get track; error? */ + if ((r = dp_rdtrk (uptr, dpxb, uptr->CYL, h))) /* get track; error? */ return r; if (!dp_findrec (dp_cw2)) /* find rec; error? */ return dp_done (1, STA_ADRER); /* address error */ @@ -750,7 +750,7 @@ switch (uptr->FNC) { /* case on function */ if (dp_cw1 & CW1_RW) { /* write? */ if (dp_sta & STA_RDY) /* timing failure? */ return dp_wrdone (uptr, STA_DTRER); /* yes, error */ - if (r = dp_wrwd (uptr, dp_buf)) /* wr word, error? */ + if ((r = dp_wrwd (uptr, dp_buf))) /* wr word, error? */ return r; if (dp_eor) { /* transfer done? */ dpxb[dp_rptr + REC_DATA + dp_wptr] = dp_csum; @@ -855,7 +855,7 @@ if (dp_wptr < (lnt + REC_MAXEXT)) { } dpxb[dp_rptr + REC_DATA + dp_wptr] = dp_csum; /* write csum */ dpxb[dp_rptr + lnt + REC_OVHD] = 0; /* zap rest of track */ -if (r = dp_wrdone (uptr, STA_UNSER)) /* dump track */ +if ((r = dp_wrdone (uptr, STA_UNSER))) /* dump track */ return r; return STOP_DPOVR; } @@ -1017,7 +1017,7 @@ for (c = cntr = 0; c < dp_tab[dp_ctype].cyl; c++) { else tbuf[rptr + REC_ADDR] = (c << 8) + (h << 3) + i; rptr = rptr + nw + REC_OVHD; } - if (r = dp_wrtrk (uptr, tbuf, c, h)) + if ((r = dp_wrtrk (uptr, tbuf, c, h))) return r; } } @@ -1043,7 +1043,7 @@ if ((uptr->flags & UNIT_ATT) == 0) return SCPE_UNATT; for (c = 0; c < dp_tab[dp_ctype].cyl; c++) { for (h = 0; h < dp_tab[dp_ctype].surf; h++) { - if (r = dp_rdtrk (uptr, tbuf, c, h)) + if ((r = dp_rdtrk (uptr, tbuf, c, h))) return r; rptr = 0; rlnt = tbuf[rptr + REC_LNT]; diff --git a/H316/h316_mt.c b/H316/h316_mt.c index 125945a9..22ceb6b4 100644 --- a/H316/h316_mt.c +++ b/H316/h316_mt.c @@ -371,17 +371,17 @@ switch (uptr->FNC) { /* case on function */ return SCPE_OK; case FNC_WEOF: /* write file mark */ - if (st = sim_tape_wrtmk (uptr)) /* write tmk, err? */ + if ((st = sim_tape_wrtmk (uptr))) /* write tmk, err? */ r = mt_map_err (uptr, st); /* map error */ break; /* sched end motion */ case FNC_FSR: /* space fwd rec */ - if (st = sim_tape_sprecf (uptr, &tbc)) /* space fwd, err? */ + if ((st = sim_tape_sprecf (uptr, &tbc))) /* space fwd, err? */ r = mt_map_err (uptr, st); /* map error */ break; /* sched end motion */ case FNC_BSR: /* space rev rec */ - if (st = sim_tape_sprecr (uptr, &tbc)) /* space rev, err? */ + if ((st = sim_tape_sprecr (uptr, &tbc))) /* space rev, err? */ r = mt_map_err (uptr, st); /* map error */ break; /* sched end motion */ @@ -455,7 +455,7 @@ switch (uptr->FNC) { /* case on function */ mt_wrwd (uptr, mt_buf); else mt_rdy = 0; /* rdy must be clr */ if (mt_ptr) { /* any data? */ - if (st = sim_tape_wrrecf (uptr, mtxb, mt_ptr)) /* write, err? */ + if ((st = sim_tape_wrrecf (uptr, mtxb, mt_ptr)))/* write, err? */ r = mt_map_err (uptr, st); /* map error */ } break; /* sched end motion */ diff --git a/H316/h316_stddev.c b/H316/h316_stddev.c index c358841e..beb3585c 100644 --- a/H316/h316_stddev.c +++ b/H316/h316_stddev.c @@ -390,7 +390,7 @@ t_stat r; if (!(uptr->flags & UNIT_ATTABLE)) return SCPE_NOFNC; -if (r = attach_unit (uptr, cptr)) +if ((r = attach_unit (uptr, cptr))) return r; if (sim_switches & SWMASK ('A')) /* -a? ASCII */ uptr->flags |= UNIT_ASC; diff --git a/H316/h316_sys.c b/H316/h316_sys.c index ca4ff61e..c9b6e54e 100644 --- a/H316/h316_sys.c +++ b/H316/h316_sys.c @@ -364,11 +364,11 @@ switch (j) { /* case on class */ case I_V_MRF: case I_V_MRX: /* mem ref */ cptr = get_glyph (cptr, gbuf, ','); /* get next field */ - if (k = (strcmp (gbuf, "C") == 0)) { /* C specified? */ + if ((k = (strcmp (gbuf, "C") == 0))) { /* C specified? */ val[0] = val[0] | SC; cptr = get_glyph (cptr, gbuf, 0); } - else if (k = (strcmp (gbuf, "Z") == 0)) { /* Z specified? */ + else if ((k = (strcmp (gbuf, "Z") == 0))) { /* Z specified? */ cptr = get_glyph (cptr, gbuf, ','); } d = get_uint (gbuf, 8, X_AMASK, &r); /* construe as addr */ diff --git a/HP2100/hp2100_bugfixes.txt b/HP2100/hp2100_bugfixes.txt index 80793696..117dd525 100644 --- a/HP2100/hp2100_bugfixes.txt +++ b/HP2100/hp2100_bugfixes.txt @@ -1,6 +1,6 @@ HP 2100 SIMULATOR BUG FIX WRITEUPS ================================== - Last update: 2012-03-25 + Last update: 2012-05-07 1. PROBLEM: Booting from magnetic tape reports "HALT instruction, P: 77756 @@ -6280,3 +6280,29 @@ (hp2100_mt.c). STATUS: Fixed in version 3.9-0. + + + +247. PROBLEM: The ICD disc read end-of-track delay is not optimal. + + VERSION: 3.9-0 + + OBSERVATION: To avoid End of Cylinder errors when reading the last sector + of a track, the ICD controller must delay more than the usual intersector + time to allow the OS driver to send an Untalk if a read is to be + terminated. Currently, the longer delay is used if an end-of-cylinder + condition is present. However, the delay is needed only if the resulting + seek attempt would cause an error if the read is continued; the normal + delay should be used if the seek is permitted and would succeed. + + Also, if the host does send an Untalk during this time, the longer delay + should be cancelled, and command termination should be scheduled for + immediate processing. + + CAUSE: Suboptimal implementation. + + RESOLUTION: Modify "end_read" (hp_disclib.c) to use the longer time only + if the seek would fail, and modify "complete_read" (hp2100_di_da.c) to + cancel the intersector delay and schedule the completion phase immediately. + + STATUS: Patches prepared 2012-05-07. diff --git a/HP2100/hp2100_cpu.c b/HP2100/hp2100_cpu.c index 7ccb3c4e..3dbe7bf8 100644 --- a/HP2100/hp2100_cpu.c +++ b/HP2100/hp2100_cpu.c @@ -29,6 +29,7 @@ DMA1,DMA2 12607B/12578A/12895A direct memory access controller DCPC1,DCPC2 12897B dual channel port controller + 09-May-12 JDB Separated assignments from conditional expressions 13-Jan-12 JDB Minor speedup in "is_mapped" Added casts to cpu_mod, dmasio, dmapio, cpu_reset, dma_reset 07-Apr-11 JDB Fixed I/O return status bug for DMA cycles @@ -1054,7 +1055,8 @@ for (i = OPTDEV; i <= MAXDEV; i++) /* default optional devi dtab [PWR] = &pwrf_dib; /* for now, powerfail is always present */ -for (i = 0; dptr = sim_devices [i]; i++) { /* loop thru dev */ +for (i = 0; sim_devices [i] != NULL; i++) { /* loop thru dev */ + dptr = sim_devices [i]; dibptr = (DIB *) dptr->ctxt; /* get DIB */ if (dibptr && !(dptr->flags & DEV_DIS)) { /* handler exists and device is enabled? */ @@ -3609,30 +3611,32 @@ DEVICE *dptr; DIB *dibptr; uint32 i, j, k; t_bool is_conflict = FALSE; -uint32 conflicts[MAXDEV + 1] = { 0 }; +uint32 conflicts [MAXDEV + 1] = { 0 }; -for (i = 0; dptr = sim_devices[i]; i++) { +for (i = 0; sim_devices [i] != NULL; i++) { + dptr = sim_devices [i]; dibptr = (DIB *) dptr->ctxt; if (dibptr && !(dptr->flags & DEV_DIS)) - if (++conflicts[dibptr->select_code] > 1) + if (++conflicts [dibptr->select_code] > 1) is_conflict = TRUE; } if (is_conflict) { sim_ttcmd(); for (i = 0; i <= MAXDEV; i++) { - if (conflicts[i] > 1) { - k = conflicts[i]; + if (conflicts [i] > 1) { + k = conflicts [i]; printf ("Select code %o conflict:", i); if (sim_log) fprintf (sim_log, "Select code %o conflict:", i); - for (j = 0; dptr = sim_devices[j]; j++) { + for (j = 0; sim_devices [j] != NULL; j++) { + dptr = sim_devices [j]; dibptr = (DIB *) dptr->ctxt; - if (dibptr && !(dptr->flags & DEV_DIS) && (i == dibptr->select_code)) { - if (k < conflicts[i]) { + if (dibptr && !(dptr->flags & DEV_DIS) && i == dibptr->select_code) { + if (k < conflicts [i]) { printf (" and"); if (sim_log) diff --git a/HP2100/hp2100_cpu0.c b/HP2100/hp2100_cpu0.c index 838d2883..a7769901 100644 --- a/HP2100/hp2100_cpu0.c +++ b/HP2100/hp2100_cpu0.c @@ -1,6 +1,6 @@ /* hp2100_cpu0.c: HP 1000 user microcode and unimplemented instruction set stubs - Copyright (c) 2006-2010, J. David Bryan + Copyright (c) 2006-2012, J. David Bryan 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,7 @@ CPU0 User microcode and unimplemented firmware options + 09-May-12 JDB Separated assignments from conditional expressions 04-Nov-10 JDB Removed DS note regarding PIF card (is now implemented) 18-Sep-08 JDB .FLUN and self-tests for VIS and SIGNAL are NOP if not present 11-Sep-08 JDB Moved microcode function prototypes to hp2100_cpu1.h @@ -129,9 +130,11 @@ uint32 entry; entry = IR & 017; /* mask to entry point */ -if (op_ds[entry] != OP_N) - if (reason = cpu_ops (op_ds[entry], op, intrq)) /* get instruction operands */ - return reason; +if (op_ds [entry] != OP_N) { + reason = cpu_ops (op_ds[entry], op, intrq); /* get instruction operands */ + if (reason != SCPE_OK) /* did the evaluation fail? */ + return reason; /* return the reason for failure */ + } switch (entry) { /* decode IR<3:0> */ @@ -191,23 +194,23 @@ switch (IR) { switch ((IR >> 4) & 037) { /* decode IR<8:4> */ -/* case 000: /* 105000-105017 */ -/* return cpu_user_00 (IR, intrq); /* uncomment to handle instruction */ +/* case 000: ** 105000-105017 */ +/* return cpu_user_00 (IR, intrq); ** uncomment to handle instruction */ -/* case 001: /* 105020-105037 */ -/* return cpu_user_01 (IR, intrq); /* uncomment to handle instruction */ +/* case 001: ** 105020-105037 */ +/* return cpu_user_01 (IR, intrq); ** uncomment to handle instruction */ -/* case 0nn: /* other cases as needed */ -/* return cpu_user_nn (IR, intrq); /* uncomment to handle instruction */ +/* case 0nn: ** other cases as needed */ +/* return cpu_user_nn (IR, intrq); ** uncomment to handle instruction */ case 020: /* 10x400-10x417 */ return cpu_user_20 (IR, intrq); /* call sample dispatcher */ -/* case 021: /* 10x420-10x437 */ -/* return cpu_user_21 (IR, intrq); /* uncomment to handle instruction */ +/* case 021: ** 10x420-10x437 */ +/* return cpu_user_21 (IR, intrq); ** uncomment to handle instruction */ -/* case 0nn: /* other cases as needed */ -/* return cpu_user_nn (IR, intrq); /* uncomment to handle instruction */ +/* case 0nn: ** other cases as needed */ +/* return cpu_user_nn (IR, intrq); ** uncomment to handle instruction */ default: /* others undefined */ reason = stop_inst; @@ -243,20 +246,22 @@ uint32 entry; entry = IR & 017; /* mask to entry point */ -if (op_user_20 [entry] != OP_N) - if (reason = cpu_ops (op_user_20 [entry], op, intrq)) /* get instruction operands */ - return reason; +if (op_user_20 [entry] != OP_N) { + reason = cpu_ops (op_user_20 [entry], op, intrq); /* get instruction operands */ + if (reason != SCPE_OK) /* did the evaluation fail? */ + return reason; /* return the reason for failure */ + } switch (entry) { /* decode IR<4:0> */ case 000: /* 10x400 */ -/* break; /* uncomment to handle instruction */ +/* break; ** uncomment to handle instruction */ case 001: /* 10x401 */ -/* break; /* uncomment to handle instruction */ +/* break; ** uncomment to handle instruction */ -/* case 0nn: /* other cases as needed */ -/* break; /* uncomment to handle instruction */ +/* case 0nn: ** other cases as needed */ +/* break; ** uncomment to handle instruction */ default: /* others undefined */ reason = stop_inst; diff --git a/HP2100/hp2100_cpu1.c b/HP2100/hp2100_cpu1.c index d176db83..0096e6e6 100644 --- a/HP2100/hp2100_cpu1.c +++ b/HP2100/hp2100_cpu1.c @@ -1,6 +1,6 @@ /* hp2100_cpu1.c: HP 2100/1000 EAU simulator and UIG dispatcher - Copyright (c) 2005-2008, Robert M. Supnik + Copyright (c) 2005-2012, Robert M. Supnik Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), @@ -25,6 +25,7 @@ CPU1 Extended arithmetic and optional microcode dispatchers + 09-May-12 JDB Separated assignments from conditional expressions 11-Sep-08 JDB Moved microcode function prototypes to hp2100_cpu1.h 05-Sep-08 JDB Moved option-present tests to UIG dispatchers Call "user microcode" dispatcher for unclaimed UIG instructions @@ -245,14 +246,15 @@ switch ((IR >> 8) & 0377) { /* decode IR<15:8> */ case 010: /* MPY 100200 (OP_K) */ MPY: - if (reason = cpu_ops (OP_K, op, intrq)) /* get operand */ - break; - sop1 = SEXT (AR); /* sext AR */ - sop2 = SEXT (op[0].word); /* sext mem */ - sop1 = sop1 * sop2; /* signed mpy */ - BR = (sop1 >> 16) & DMASK; /* to BR'AR */ - AR = sop1 & DMASK; - O = 0; /* no overflow */ + reason = cpu_ops (OP_K, op, intrq); /* get operand */ + if (reason == SCPE_OK) { /* successful eval? */ + sop1 = SEXT (AR); /* sext AR */ + sop2 = SEXT (op[0].word); /* sext mem */ + sop1 = sop1 * sop2; /* signed mpy */ + BR = (sop1 >> 16) & DMASK; /* to BR'AR */ + AR = sop1 & DMASK; + O = 0; /* no overflow */ + } break; default: /* others undefined */ @@ -262,9 +264,11 @@ switch ((IR >> 8) & 0377) { /* decode IR<15:8> */ break; case 0201: /* DIV 100400 (OP_K) */ - if (reason = cpu_ops (OP_K, op, intrq)) /* get operand */ + reason = cpu_ops (OP_K, op, intrq); /* get operand */ + if (reason != SCPE_OK) /* eval failed? */ break; - if (rs = qs = BR & SIGN) { /* save divd sign, neg? */ + rs = qs = BR & SIGN; /* save divd sign */ + if (rs) { /* neg? */ AR = (~AR + 1) & DMASK; /* make B'A pos */ BR = (~BR + (AR == 0)) & DMASK; /* make divd pos */ } @@ -317,17 +321,19 @@ switch ((IR >> 8) & 0377) { /* decode IR<15:8> */ break; case 0210: /* DLD 104200 (OP_D) */ - if (reason = cpu_ops (OP_D, op, intrq)) /* get operand */ - break; - AR = (op[0].dword >> 16) & DMASK; /* load AR */ - BR = op[0].dword & DMASK; /* load BR */ + reason = cpu_ops (OP_D, op, intrq); /* get operand */ + if (reason == SCPE_OK) { /* successful eval? */ + AR = (op[0].dword >> 16) & DMASK; /* load AR */ + BR = op[0].dword & DMASK; /* load BR */ + } break; case 0211: /* DST 104400 (OP_A) */ - if (reason = cpu_ops (OP_A, op, intrq)) /* get operand */ - break; - WriteW (op[0].word, AR); /* store AR */ - WriteW ((op[0].word + 1) & VAMASK, BR); /* store BR */ + reason = cpu_ops (OP_A, op, intrq); /* get operand */ + if (reason == SCPE_OK) { /* successful eval? */ + WriteW (op[0].word, AR); /* store AR */ + WriteW ((op[0].word + 1) & VAMASK, BR); /* store BR */ + } break; default: /* should never get here */ @@ -733,9 +739,11 @@ uint32 i, MA; for (i = 0; i < OP_N_F; i++) { flags = pattern & OP_M_FLAGS; /* get operand pattern */ - if (flags >= OP_ADR) /* address operand? */ - if (reason = resolve (ReadW (PC), &MA, irq)) /* resolve indirects */ + if (flags >= OP_ADR) { /* address operand? */ + reason = resolve (ReadW (PC), &MA, irq); /* resolve indirects */ + if (reason != SCPE_OK) /* resolution failed? */ return reason; + } switch (flags) { case OP_NUL: /* null operand */ diff --git a/HP2100/hp2100_cpu2.c b/HP2100/hp2100_cpu2.c index e5dac17c..a55cf656 100644 --- a/HP2100/hp2100_cpu2.c +++ b/HP2100/hp2100_cpu2.c @@ -1,6 +1,6 @@ /* hp2100_cpu2.c: HP 2100/1000 FP/DMS/EIG/IOP instructions - Copyright (c) 2005-2008, Robert M. Supnik + Copyright (c) 2005-2012, Robert M. Supnik Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), @@ -26,6 +26,7 @@ CPU2 Floating-point, dynamic mapping, extended, and I/O processor instructions + 09-May-12 JDB Separated assignments from conditional expressions 11-Sep-08 JDB Moved microcode function prototypes to hp2100_cpu1.h 05-Sep-08 JDB Removed option-present tests (now in UIG dispatchers) 05-Aug-08 JDB Updated mp_dms_jmp calling sequence @@ -243,9 +244,12 @@ uint32 i, t, mapi, mapj; absel = (IR & I_AB)? 1: 0; /* get A/B select */ entry = IR & 037; /* mask to entry point */ -if (op_dms[entry] != OP_N) - if (reason = cpu_ops (op_dms[entry], op, intrq)) /* get instruction operands */ - return reason; +if (op_dms [entry] != OP_N) { + reason = cpu_ops (op_dms [entry], op, intrq); /* get instruction operands */ + + if (reason != SCPE_OK) /* evaluation failed? */ + return reason; /* return reason for failure */ + } switch (entry) { /* decode IR<3:0> */ @@ -609,9 +613,12 @@ int32 sop1, sop2; absel = (IR & I_AB)? 1: 0; /* get A/B select */ entry = IR & 037; /* mask to entry point */ -if (op_eig[entry] != OP_N) - if (reason = cpu_ops (op_eig[entry], op, intrq)) /* get instruction operands */ - return reason; +if (op_eig [entry] != OP_N) { + reason = cpu_ops (op_eig [entry], op, intrq); /* get instruction operands */ + + if (reason != SCPE_OK) /* evaluation failed? */ + return reason; /* return reason for failure */ + } switch (entry) { /* decode IR<4:0> */ @@ -988,9 +995,12 @@ else if (entry <= 057) /* IR = 10x440-457? */ entry = entry - 060; /* offset 10x460-477 */ -if (op_iop[entry] != OP_N) - if (reason = cpu_ops (op_iop[entry], op, intrq)) /* get instruction operands */ - return reason; +if (op_iop [entry] != OP_N) { + reason = cpu_ops (op_iop [entry], op, intrq); /* get instruction operands */ + + if (reason != SCPE_OK) /* evaluation failed? */ + return reason; /* return reason for failure */ + } switch (entry) { /* decode IR<5:0> */ diff --git a/HP2100/hp2100_cpu3.c b/HP2100/hp2100_cpu3.c index 028e6857..3e201aea 100644 --- a/HP2100/hp2100_cpu3.c +++ b/HP2100/hp2100_cpu3.c @@ -25,6 +25,7 @@ CPU3 Fast FORTRAN and Double Integer instructions + 09-May-12 JDB Separated assignments from conditional expressions 11-Sep-08 JDB Moved microcode function prototypes to hp2100_cpu1.h 05-Sep-08 JDB Removed option-present tests (now in UIG dispatchers) 05-Aug-08 JDB Updated mp_dms_jmp calling sequence @@ -185,17 +186,23 @@ int32 i; entry = IR & 037; /* mask to entry point */ if (UNIT_CPU_MODEL != UNIT_1000_F) { /* 2100/M/E-Series? */ - if (op_ffp_e[entry] != OP_N) - if (reason = cpu_ops (op_ffp_e[entry], op, intrq)) /* get instruction operands */ - return reason; + if (op_ffp_e [entry] != OP_N) { + reason = cpu_ops (op_ffp_e [entry], op, intrq); /* get instruction operands */ + + if (reason != SCPE_OK) /* evaluation failed? */ + return reason; /* return reason for failure */ + } } #if defined (HAVE_INT64) /* int64 support available */ else { /* F-Series */ - if (op_ffp_f[entry] != OP_N) - if (reason = cpu_ops (op_ffp_f[entry], op, intrq)) /* get instruction operands */ - return reason; + if (op_ffp_f [entry] != OP_N) { + reason = cpu_ops (op_ffp_f [entry], op, intrq); /* get instruction operands */ + + if (reason != SCPE_OK) /* evaluation failed? */ + return reason; /* return reason for failure */ + } switch (entry) { /* decode IR<4:0> */ @@ -417,7 +424,8 @@ switch (entry) { /* decode IR<4:0> */ sa = op[0].word - 1; da = ReadW (sa); /* get jump target */ - if (reason = resolve (da, &MA, intrq)) { /* resolve indirects */ + reason = resolve (da, &MA, intrq); /* resolve indirects */ + if (reason != SCPE_OK) { /* resolution failed? */ PC = err_PC; /* irq restarts instruction */ break; } @@ -435,7 +443,8 @@ switch (entry) { /* decode IR<4:0> */ op[1].word = op[1].word + /* compute element offset */ (op[2].word - 1) * op[3].word; else { /* 3-dim access */ - if (reason = cpu_ops (OP_KK, op2, intrq)) { /* get 1st, 2nd ranges */ + reason = cpu_ops (OP_KK, op2, intrq); /* get 1st, 2nd ranges */ + if (reason != SCPE_OK) { /* evaluation failed? */ PC = err_PC; /* irq restarts instruction */ break; } @@ -461,7 +470,8 @@ switch (entry) { /* decode IR<4:0> */ for (j = 0; j < sc; j++) { MA = ReadW (sa++); /* get addr of actual */ - if (reason = resolve (MA, &MA, intrq)) { /* resolve indirect */ + reason = resolve (MA, &MA, intrq); /* resolve indirect */ + if (reason != SCPE_OK) { /* resolution failed? */ PC = err_PC; /* irq restarts instruction */ break; } @@ -643,9 +653,11 @@ t_stat reason = SCPE_OK; entry = IR & 017; /* mask to entry point */ -if (op_dbi[entry] != OP_N) - if (reason = cpu_ops (op_dbi[entry], op, intrq)) /* get instruction operands */ - return reason; +if (op_dbi[entry] != OP_N) { + reason = cpu_ops (op_dbi [entry], op, intrq); /* get instruction operands */ + if (reason != SCPE_OK) /* evaluation failed? */ + return reason; /* return reason for failure */ + } switch (entry) { /* decode IR<3:0> */ diff --git a/HP2100/hp2100_cpu4.c b/HP2100/hp2100_cpu4.c index 3da7a9d3..ea294664 100644 --- a/HP2100/hp2100_cpu4.c +++ b/HP2100/hp2100_cpu4.c @@ -25,6 +25,7 @@ CPU4 Floating Point Processor and Scientific Instruction Set + 09-May-12 JDB Separated assignments from conditional expressions 06-Feb-12 JDB Added OPSIZE casts to fp_accum calls in .FPWR/.TPWR 11-Sep-08 JDB Moved microcode function prototypes to hp2100_cpu1.h 05-Sep-08 JDB Removed option-present tests (now in UIG dispatchers) @@ -260,9 +261,12 @@ else entry = opcode & 0177; /* map to <6:0> */ -if (op_fpp[entry] != OP_N) - if (reason = cpu_ops (op_fpp[entry], op, intrq)) /* get instruction operands */ - return reason; +if (op_fpp [entry] != OP_N) { + reason = cpu_ops (op_fpp [entry], op, intrq); /* get instruction operands */ + + if (reason != SCPE_OK) /* evaluation failed? */ + return reason; /* return reason for failure */ + } switch (entry) { /* decode IR<6:0> */ case 0000: /* FAD 105000 (OP_RF) */ @@ -599,9 +603,12 @@ static const OP t_one = { { 0040000, 0000000, 0000000, 0000002 } }; /* DEY 1. entry = IR & 017; /* mask to entry point */ -if (op_sis[entry] != OP_N) - if (reason = cpu_ops (op_sis[entry], op, intrq)) /* get instruction operands */ - return reason; +if (op_sis [entry] != OP_N) { + reason = cpu_ops (op_sis [entry], op, intrq); /* get instruction operands */ + + if (reason != SCPE_OK) /* evaluation failed? */ + return reason; /* return reason for failure */ + } switch (entry) { /* decode IR<3:0> */ diff --git a/HP2100/hp2100_cpu5.c b/HP2100/hp2100_cpu5.c index 9865f47a..31c381c6 100644 --- a/HP2100/hp2100_cpu5.c +++ b/HP2100/hp2100_cpu5.c @@ -26,6 +26,7 @@ CPU5 RTE-6/VM and RTE-IV firmware option instructions + 09-May-12 JDB Separated assignments from conditional expressions 23-Mar-12 JDB Added sign extension for dim count in "cpu_ema_resolve" 28-Dec-11 JDB Eliminated unused variable in "cpu_ema_vset" 11-Sep-08 JDB Moved microcode function prototypes to hp2100_cpu1.h @@ -649,9 +650,11 @@ t_bool debug = DEBUG_PRI (cpu_dev, DEB_VMA); entry = IR & 017; /* mask to entry point */ pattern = op_vma[entry]; /* get operand pattern */ -if (pattern != OP_N) - if (reason = cpu_ops (pattern, op, intrq)) /* get instruction operands */ - return reason; +if (pattern != OP_N) { + reason = cpu_ops (pattern, op, intrq); /* get instruction operands */ + if (reason != SCPE_OK) /* evaluation failed? */ + return reason; /* return reason for failure */ + } if (debug) { /* debugging? */ fprintf (sim_deb, ">>CPU VMA: IR = %06o (", IR); /* print preamble and IR */ @@ -1360,9 +1363,11 @@ t_bool debug = DEBUG_PRI (cpu_dev, DEB_EMA); entry = IR & 017; /* mask to entry point */ pattern = op_ema[entry]; /* get operand pattern */ -if (pattern != OP_N) - if (reason = cpu_ops (pattern, op, intrq)) /* get instruction operands */ - return reason; +if (pattern != OP_N) { + reason = cpu_ops (pattern, op, intrq); /* get instruction operands */ + if (reason != SCPE_OK) /* evaluation failed? */ + return reason; /* return reason for failure */ + } if (debug) { /* debugging? */ fprintf (sim_deb, ">>CPU EMA: PC = %06o, IR = %06o (", err_PC,IR); /* print preamble and IR */ diff --git a/HP2100/hp2100_cpu6.c b/HP2100/hp2100_cpu6.c index 5606a178..b3dc34aa 100644 --- a/HP2100/hp2100_cpu6.c +++ b/HP2100/hp2100_cpu6.c @@ -1,6 +1,6 @@ /* hp2100_cpu6.c: HP 1000 RTE-6/VM OS instructions - Copyright (c) 2006-2010, J. David Bryan + Copyright (c) 2006-2012, J. David Bryan 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,7 @@ CPU6 RTE-6/VM OS instructions + 09-May-12 JDB Separated assignments from conditional expressions 29-Oct-10 JDB DMA channels renamed from 0,1 to 1,2 to match documentation 18-Sep-08 JDB Corrected .SIP debug formatting 11-Sep-08 JDB Moved microcode function prototypes to hp2100_cpu1.h @@ -393,9 +394,12 @@ static t_bool tbg_tick = FALSE; /* set if processing TBG entry = IR & 017; /* mask to entry point */ pattern = op_os[entry]; /* get operand pattern */ -if (pattern != OP_N) - if (reason = cpu_ops (pattern, op, intrq)) /* get instruction operands */ - return reason; +if (pattern != OP_N) { + reason = cpu_ops (pattern, op, intrq); /* get instruction operands */ + + if (reason != SCPE_OK) /* evaluation failed? */ + return reason; /* return reason for failure */ + } tbg_tick = tbg_tick || (IR == 0105357) && iotrap; /* set TBG interrupting flag */ @@ -544,7 +548,9 @@ switch (entry) { /* decode IR<3:0> */ for (i = 0; i < count; i++) { ma = ReadW (PC); /* get operand address */ - if (reason = resolve (ma, &ma, intrq)) { /* resolve indirect */ + reason = resolve (ma, &ma, intrq); /* resolve indirect */ + + if (reason != SCPE_OK) { /* resolution failed? */ PC = err_PC; /* IRQ restarts instruction */ break; } @@ -710,8 +716,10 @@ switch (entry) { /* decode IR<3:0> */ ma = ReadW (sa); /* get addr of actual */ sa = (sa + 1) & VAMASK; /* increment address */ - if (reason = resolve (ma, &ma, intrq)) { /* resolve indirect */ - PC = err_PC; /* irq restarts instruction */ + reason = resolve (ma, &ma, intrq); /* resolve indirect */ + + if (reason != SCPE_OK) { /* resolution failed? */ + PC = err_PC; /* irq restarts instruction */ break; } diff --git a/HP2100/hp2100_cpu7.c b/HP2100/hp2100_cpu7.c index ada35eab..84fb1163 100644 --- a/HP2100/hp2100_cpu7.c +++ b/HP2100/hp2100_cpu7.c @@ -26,6 +26,7 @@ CPU7 Vector Instruction Set and SIGNAL firmware + 09-May-12 JDB Separated assignments from conditional expressions 06-Feb-12 JDB Corrected "opsize" parameter type in vis_abs 11-Sep-08 JDB Moved microcode function prototypes to hp2100_cpu1.h 05-Sep-08 JDB Removed option-present tests (now in UIG dispatchers) @@ -383,16 +384,18 @@ if (entry==0) { /* retrieve sub opcode subcode = AR; /* for reentry */ PC = (PC + 1) & VAMASK; /* bump to real argument list */ pattern = (subcode & 0400) ? OP_AAKAKK : OP_AKAKAKK; /* scalar or vector operation */ -} + } -if (pattern != OP_N) +if (pattern != OP_N) { if (op_ftnret[entry]) { /* most VIS instrs ignore RTN addr */ ret = ReadOp(PC, in_s); rtn = rtn1 = ret.word; /* but save it just in case */ PC = (PC + 1) & VAMASK; /* move to next argument */ + } + reason = cpu_ops (pattern, op, intrq); /* get instruction operands */ + if (reason != SCPE_OK) /* evaluation failed? */ + return reason; /* return reason for failure */ } - if (reason = cpu_ops (pattern, op, intrq)) /* get instruction operands */ - return reason; if (debug) { /* debugging? */ fprintf (sim_deb, ">>CPU VIS: IR = %06o/%06o (", /* print preamble and IR */ @@ -652,9 +655,11 @@ t_bool debug = DEBUG_PRI (cpu_dev, DEB_SIG); entry = IR & 017; /* mask to entry point */ -if (op_signal[entry] != OP_N) - if (reason = cpu_ops (op_signal[entry], op, intrq)) /* get instruction operands */ - return reason; +if (op_signal [entry] != OP_N) { + reason = cpu_ops (op_signal [entry], op, intrq); /* get instruction operands */ + if (reason != SCPE_OK) /* evaluation failed? */ + return reason; /* return reason for failure */ + } if (debug) { /* debugging? */ fprintf (sim_deb, ">>CPU SIG: IR = %06o (", IR); /* print preamble and IR */ diff --git a/HP2100/hp2100_defs.h b/HP2100/hp2100_defs.h index 8bed6467..89b9a408 100644 --- a/HP2100/hp2100_defs.h +++ b/HP2100/hp2100_defs.h @@ -23,6 +23,9 @@ be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from Robert M Supnik. + 12-May-12 JDB Added pragmas to suppress logical operator precedence warnings + 12-Feb-12 JDB Added MA device select code assignment + Added ma_boot_ext() declaration 10-Feb-12 JDB Added hp_setsc, hp_showsc functions to support SC modifier 28-Mar-11 JDB Tidied up signal handling 29-Oct-10 JDB DMA channels renamed from 0,1 to 1,2 to match documentation @@ -73,6 +76,15 @@ #include "sim_defs.h" /* simulator defns */ +/* Required to quell clang precedence warnings */ + +#if defined (__GNUC__) +#pragma GCC diagnostic ignored "-Wunknown-pragmas" +#pragma GCC diagnostic ignored "-Wpragmas" +#pragma GCC diagnostic ignored "-Wlogical-op-parentheses" +#endif + + /* Simulator stop and notification codes */ #define STOP_RSRV 1 /* must be 1 */ @@ -175,6 +187,7 @@ typedef enum { INITIAL, SERVICE } POLLMODE; /* poll synchronization #define MUXC 042 /* 12920A control */ #define DI_DA 043 /* 12821A Disc Interface with Amigo disc devices */ #define DI_DC 044 /* 12821A Disc Interface with CS/80 disc and tape devices */ +#define DI_MA 045 /* 12821A Disc Interface with Amigo mag tape devices */ #define OPTDEV 002 /* start of optional devices */ #define CRSDEV 006 /* start of devices that receive CRS */ @@ -466,6 +479,7 @@ extern t_stat hp_showdev (FILE *st, UNIT *uptr, int32 val, void *desc); /* Device-specific functions */ -extern int32 sync_poll (POLLMODE poll_mode); +extern int32 sync_poll (POLLMODE poll_mode); +extern t_stat ma_boot_ext (uint32 SR); #endif diff --git a/HP2100/hp2100_di_da.c b/HP2100/hp2100_di_da.c index 005a6215..9ce38860 100644 --- a/HP2100/hp2100_di_da.c +++ b/HP2100/hp2100_di_da.c @@ -25,6 +25,7 @@ DA 12821A Disc Interface with Amigo disc drives + 07-May-12 JDB Cancel the intersector delay if an untalk is received 29-Mar-12 JDB First release 04-Nov-11 JDB Created DA device @@ -1962,6 +1963,11 @@ return; 2. There is no need to test if we are processing a disc command, as the controller would not be busy otherwise. + + 3. If an auto-seek will be needed to continue the read, but the seek will + fail, then an extra delay is inserted before the service call to start + the next sector. Once an Untalk is received, this delay is no longer + needed, so it is cancelled before rescheduling the service routine. */ static void complete_read (uint32 unit) @@ -1974,7 +1980,9 @@ if ((if_state [unit] == command_exec /* is a command exec if_state [unit] = command_exec; /* set to execute */ da_unit [unit].PHASE = end_phase; /* the completion phase */ - da_unit [unit].wait = icd_cntlr [unit].data_time; /* ensure that the controller will finish */ + + sim_cancel (&da_unit [unit]); /* cancel the EOT delay */ + da_unit [unit].wait = icd_cntlr [unit].data_time; /* reschedule for completion */ } return; diff --git a/HP2100/hp2100_dp.c b/HP2100/hp2100_dp.c index c26d16e6..3b3f2bcc 100644 --- a/HP2100/hp2100_dp.c +++ b/HP2100/hp2100_dp.c @@ -26,6 +26,7 @@ DP 12557A 2871 disk subsystem 13210A 7900 disk subsystem + 09-May-12 JDB Separated assignments from conditional expressions 10-Feb-12 JDB Deprecated DEVNO in favor of SC Added CNTLR_TYPE cast to dp_settype 28-Mar-11 JDB Tidied up signal handling @@ -190,7 +191,7 @@ #define STA_PROT 0002000 /* protected (13210) */ #define STA_SKI 0001000 /* incomplete NI (u) */ #define STA_SKE 0000400 /* seek error */ -/* 0000200 /* unused */ +/* 0000200 (unused) */ #define STA_NRDY 0000100 /* not ready (d) */ #define STA_EOC 0000040 /* end of cylinder */ #define STA_AER 0000020 /* addr error */ @@ -694,7 +695,8 @@ void dp_goc (int32 fnc, int32 drv, int32 time) { int32 t; -if (t = sim_is_active (&dpc_unit[drv])) { /* still seeking? */ +t = sim_is_active (&dpc_unit[drv]); +if (t) { /* still seeking? */ sim_cancel (&dpc_unit[drv]); /* stop seek */ dpc_sta[drv] = dpc_sta[drv] & ~STA_BSY; /* clear busy */ time = time + t; /* include seek time */ @@ -906,10 +908,13 @@ switch (uptr->FNC) { /* case function */ dpc_rarh = dpc_rarh ^ 1; /* incr head */ dpc_eoc = ((dpc_rarh & 1) == 0); /* calc eoc */ } - if (err = fseek (uptr->fileref, da * sizeof (int16), - SEEK_SET)) break; + err = fseek (uptr->fileref, da * sizeof (int16), SEEK_SET); + if (err) /* error? */ + break; fxread (dpxb, sizeof (int16), DP_NUMWD, uptr->fileref); - if (err = ferror (uptr->fileref)) break; + err = ferror (uptr->fileref); + if (err) /* error? */ + break; } dpd_ibuf = dpxb[dp_ptr++]; /* get word */ if (dp_ptr >= DP_NUMWD) { /* end of sector? */ @@ -953,10 +958,13 @@ switch (uptr->FNC) { /* case function */ dpc_rarh = dpc_rarh ^ 1; /* incr head */ dpc_eoc = ((dpc_rarh & 1) == 0); /* calc eoc */ } - if (err = fseek (uptr->fileref, da * sizeof (int16), - SEEK_SET)) break; + err = fseek (uptr->fileref, da * sizeof (int16), SEEK_SET); + if (err) /* error? */ + break; fxwrite (dpxb, sizeof (int16), DP_NUMWD, uptr->fileref); - if (err = ferror (uptr->fileref)) break; /* error? */ + err = ferror (uptr->fileref); + if (err) /* error? */ + break; dp_ptr = 0; /* next sector */ } if (dpd.command && dpd_xfer) /* dch on, xfer? */ diff --git a/HP2100/hp2100_dq.c b/HP2100/hp2100_dq.c index 06c92b2b..4ca85689 100644 --- a/HP2100/hp2100_dq.c +++ b/HP2100/hp2100_dq.c @@ -26,6 +26,7 @@ DQ 12565A 2883 disk system + 09-May-12 JDB Separated assignments from conditional expressions 10-Feb-12 JDB Deprecated DEVNO in favor of SC 28-Mar-11 JDB Tidied up signal handling 26-Oct-10 JDB Changed I/O signal handler for revised signal model @@ -100,7 +101,7 @@ #define CW_V_FNC 12 /* function */ #define CW_M_FNC 017 #define CW_GETFNC(x) (((x) >> CW_V_FNC) & CW_M_FNC) -/* 000 /* unused */ +/* 000 (unused) */ #define FNC_STA 001 /* status check */ #define FNC_RCL 002 /* recalibrate */ #define FNC_SEEK 003 /* seek */ @@ -530,7 +531,9 @@ void dq_goc (int32 fnc, int32 drv, int32 time) { int32 t; -if (t = sim_is_active (&dqc_unit[drv])) { /* still seeking? */ +t = sim_is_active (&dqc_unit[drv]); + +if (t) { /* still seeking? */ sim_cancel (&dqc_unit[drv]); /* cancel */ time = time + t; /* include seek time */ } @@ -740,10 +743,13 @@ switch (uptr->FNC) { /* case function */ dqc_rars = (dqc_rars + 1) % DQ_NUMSC; /* incr sector */ if (dqc_rars == 0) /* wrap? incr head */ dqc_uhed[drv] = dqc_rarh = dqc_rarh + 1; - if (err = fseek (uptr->fileref, da * sizeof (int16), - SEEK_SET)) break; + err = fseek (uptr->fileref, da * sizeof (int16), SEEK_SET); + if (err) + break; fxread (dqxb, sizeof (int16), DQ_NUMWD, uptr->fileref); - if (err = ferror (uptr->fileref)) break; + err = ferror (uptr->fileref); + if (err) + break; } dqd_ibuf = dqxb[dq_ptr++]; /* get word */ if (dq_ptr >= DQ_NUMWD) { /* end of sector? */ @@ -786,10 +792,13 @@ switch (uptr->FNC) { /* case function */ dqc_rars = (dqc_rars + 1) % DQ_NUMSC; /* incr sector */ if (dqc_rars == 0) /* wrap? incr head */ dqc_uhed[drv] = dqc_rarh = dqc_rarh + 1; - if (err = fseek (uptr->fileref, da * sizeof (int16), - SEEK_SET)) return TRUE; + err = fseek (uptr->fileref, da * sizeof (int16), SEEK_SET); + if (err) + break; fxwrite (dqxb, sizeof (int16), DQ_NUMWD, uptr->fileref); - if (err = ferror (uptr->fileref)) break; + err = ferror (uptr->fileref); + if (err) + break; dq_ptr = 0; } if (dqd.command && dqd_xfer) { /* dch on, xfer? */ diff --git a/HP2100/hp2100_ipl.c b/HP2100/hp2100_ipl.c index 595d47e9..d20d0678 100644 --- a/HP2100/hp2100_ipl.c +++ b/HP2100/hp2100_ipl.c @@ -25,6 +25,7 @@ IPLI, IPLO 12875A interprocessor link + 09-May-12 JDB Separated assignments from conditional expressions 10-Feb-12 JDB Deprecated DEVNO in favor of SC Added CARD_INDEX casts to dib.card_index 07-Apr-11 JDB A failed STC may now be retried @@ -569,61 +570,62 @@ return SCPE_OK; t_stat ipl_attach (UNIT *uptr, char *cptr) { SOCKET newsock; -uint32 i, t, ipa, ipp, oldf; -char *tptr; +uint32 i, t, oldf; +char host[CBUFSIZE], port[CBUFSIZE], hostport[2*CBUFSIZE+3]; +char *tptr = NULL; t_stat r; -r = get_ipaddr (cptr, &ipa, &ipp); -if ((r != SCPE_OK) || (ipp == 0)) - return SCPE_ARG; oldf = uptr->flags; if (oldf & UNIT_ATT) ipl_detach (uptr); if ((sim_switches & SWMASK ('C')) || ((sim_switches & SIM_SW_REST) && (oldf & UNIT_ACTV))) { - if (ipa == 0) - ipa = 0x7F000001; - newsock = sim_connect_sock (ipa, ipp); + r = sim_parse_addr (cptr, host, sizeof(host), "localhost", port, sizeof(port), NULL); + if ((r != SCPE_OK) || (port[0] == '\0')) + return SCPE_ARG; + sprintf(hostport, "%s%s%s%s%s", strchr(host, ':') ? "[" : "", host, strchr(host, ':') ? "]" : "", host[0] ? ":" : "", port); + newsock = sim_connect_sock (hostport, NULL, NULL); if (newsock == INVALID_SOCKET) return SCPE_IOERR; - printf ("Connecting to IP address %d.%d.%d.%d, port %d\n", - (ipa >> 24) & 0xff, (ipa >> 16) & 0xff, - (ipa >> 8) & 0xff, ipa & 0xff, ipp); + printf ("Connecting to %s\n", hostport); if (sim_log) fprintf (sim_log, - "Connecting to IP address %d.%d.%d.%d, port %d\n", - (ipa >> 24) & 0xff, (ipa >> 16) & 0xff, - (ipa >> 8) & 0xff, ipa & 0xff, ipp); + "Connecting to %s\n", hostport); uptr->flags = uptr->flags | UNIT_ACTV; uptr->LSOCKET = 0; uptr->DSOCKET = newsock; } else { - if (ipa != 0) + r = sim_parse_addr (cptr, host, sizeof(host), NULL, port, sizeof(port), NULL); + if (r != SCPE_OK) return SCPE_ARG; - newsock = sim_master_sock (ipp); + sprintf(hostport, "%s%s%s%s%s", strchr(host, ':') ? "[" : "", host, strchr(host, ':') ? "]" : "", host[0] ? ":" : "", port); + newsock = sim_master_sock (hostport, &r); + if (r != SCPE_OK) + return r; if (newsock == INVALID_SOCKET) return SCPE_IOERR; - printf ("Listening on port %d\n", ipp); + printf ("Listening on port %s\n", hostport); if (sim_log) - fprintf (sim_log, "Listening on port %d\n", ipp); + fprintf (sim_log, "Listening on port %s\n", hostport); uptr->flags = uptr->flags & ~UNIT_ACTV; uptr->LSOCKET = newsock; uptr->DSOCKET = 0; } uptr->IBUF = uptr->OBUF = 0; uptr->flags = (uptr->flags | UNIT_ATT) & ~(UNIT_ESTB | UNIT_HOLD); -tptr = (char *) malloc (strlen (cptr) + 1); /* get string buf */ +tptr = (char *) malloc (strlen (hostport) + 1); /* get string buf */ if (tptr == NULL) { /* no memory? */ ipl_detach (uptr); /* close sockets */ return SCPE_MEM; } -strcpy (tptr, cptr); /* copy ipaddr:port */ +strcpy (tptr, hostport); /* copy ipaddr:port */ uptr->filename = tptr; /* save */ sim_activate (uptr, POLL_FIRST); /* activate first poll "immediately" */ if (sim_switches & SWMASK ('W')) { /* wait? */ for (i = 0; i < 30; i++) { /* check for 30 sec */ - if (t = ipl_check_conn (uptr)) /* established? */ + t = ipl_check_conn (uptr); + if (t) /* established? */ break; if ((i % 10) == 0) /* status every 10 sec */ printf ("Waiting for connnection\n"); diff --git a/HP2100/hp2100_ms.c b/HP2100/hp2100_ms.c index c78c5e0c..daf35448 100644 --- a/HP2100/hp2100_ms.c +++ b/HP2100/hp2100_ms.c @@ -26,6 +26,7 @@ MS 13181A 7970B 800bpi nine track magnetic tape 13183A 7970E 1600bpi nine track magnetic tape + 09-May-12 JDB Separated assignments from conditional expressions 10-Feb-12 JDB Deprecated DEVNO in favor of SC Added CNTLR_TYPE cast to ms_settype 28-Mar-11 JDB Tidied up signal handling @@ -737,7 +738,8 @@ switch (uptr->FNC) { /* case on function */ fprintf (sim_deb, ">>MSC svc: Unit %d wrote initial gap\n", unum); - if (st = ms_write_gap (uptr)) { /* write initial gap; error? */ + st = ms_write_gap (uptr); /* write initial gap*/ + if (st != MTSE_OK) { /* error? */ r = ms_map_err (uptr, st); /* map error */ break; /* terminate operation */ } @@ -747,13 +749,15 @@ switch (uptr->FNC) { /* case on function */ fprintf (sim_deb, ">>MSC svc: Unit %d wrote file mark\n", unum); - if (st = sim_tape_wrtmk (uptr)) /* write tmk, err? */ + st = sim_tape_wrtmk (uptr); /* write tmk */ + if (st != MTSE_OK) /* error? */ r = ms_map_err (uptr, st); /* map error */ msc_sta = STA_EOF; /* set EOF status */ break; case FNC_FSR: /* space forward */ - if (st = sim_tape_sprecf (uptr, &tbc)) /* space rec fwd, err? */ + st = sim_tape_sprecf (uptr, &tbc); /* space rec fwd */ + if (st != MTSE_OK) /* error? */ r = ms_map_err (uptr, st); /* map error */ if (tbc & 1) msc_sta = msc_sta | STA_ODD; @@ -761,7 +765,8 @@ switch (uptr->FNC) { /* case on function */ break; case FNC_BSR: /* space reverse */ - if (st = sim_tape_sprecr (uptr, &tbc)) /* space rec rev, err? */ + st = sim_tape_sprecr (uptr, &tbc); /* space rec rev*/ + if (st != MTSE_OK) /* error? */ r = ms_map_err (uptr, st); /* map error */ if (tbc & 1) msc_sta = msc_sta | STA_ODD; @@ -831,7 +836,8 @@ switch (uptr->FNC) { /* case on function */ fprintf (sim_deb, ">>MSC svc: Unit %d wrote initial gap\n", unum); - if (st = ms_write_gap (uptr)) { /* write initial gap; error? */ + st = ms_write_gap (uptr); /* write initial gap */ + if (st != MTSE_OK) { /* error? */ r = ms_map_err (uptr, st); /* map error */ break; /* terminate operation */ } @@ -855,7 +861,8 @@ switch (uptr->FNC) { /* case on function */ fprintf (sim_deb, ">>MSC svc: Unit %d wrote %d word record\n", unum, ms_ptr / 2); - if (st = sim_tape_wrrecf (uptr, msxb, ms_ptr)) { /* write, err? */ + st = sim_tape_wrrecf (uptr, msxb, ms_ptr); /* write */ + if (st != MTSE_OK) { r = ms_map_err (uptr, st); /* map error */ break; } @@ -894,7 +901,9 @@ t_stat st; uint32 gap_len = ms_ctype ? GAP_13183 : GAP_13181; /* establish gap length */ uint32 tape_bpi = ms_ctype ? BPI_13183 : BPI_13181; /* establish nominal bpi */ -if (st = sim_tape_wrgap (uptr, gap_len, tape_bpi)) /* write gap */ +st = sim_tape_wrgap (uptr, gap_len, tape_bpi); /* write gap */ + +if (st != MTSE_OK) return ms_map_err (uptr, st); /* map error if failure */ else return SCPE_OK; @@ -974,7 +983,9 @@ for (i = 0; i < MS_NUMDR; i++) { /* look for write in pro fprintf (sim_deb, ">>MSC rws: Unit %d wrote %d word partial record\n", i, ms_ptr / 2); - if (st = sim_tape_wrrecf (uptr, msxb, ms_ptr | MTR_ERF)) + st = sim_tape_wrrecf (uptr, msxb, ms_ptr | MTR_ERF); + + if (st != MTSE_OK) ms_map_err (uptr, st); /* discard any error */ ms_ptr = 0; /* clear partial */ diff --git a/HP2100/hp2100_mt.c b/HP2100/hp2100_mt.c index 72066de9..3e7cc1cf 100644 --- a/HP2100/hp2100_mt.c +++ b/HP2100/hp2100_mt.c @@ -25,6 +25,7 @@ MT 12559A 3030 nine track magnetic tape + 09-May-12 JDB Separated assignments from conditional expressions 25-Mar-12 JDB Removed redundant MTAB_VUN from "format" MTAB entry 10-Feb-12 JDB Deprecated DEVNO in favor of SC 28-Mar-11 JDB Tidied up signal handling @@ -495,7 +496,8 @@ switch (mtc_fnc) { /* case on function */ return sim_tape_detach (uptr); /* don't set cch flg */ case FNC_WFM: /* write file mark */ - if (st = sim_tape_wrtmk (uptr)) /* write tmk, err? */ + st = sim_tape_wrtmk (uptr); /* write tmk */ + if (st != MTSE_OK) /* error? */ r = mt_map_err (uptr, st); /* map error */ mtc_sta = STA_EOF; /* set EOF status */ break; @@ -504,12 +506,14 @@ switch (mtc_fnc) { /* case on function */ break; case FNC_FSR: /* space forward */ - if (st = sim_tape_sprecf (uptr, &tbc)) /* space rec fwd, err? */ + st = sim_tape_sprecf (uptr, &tbc); /* space rec fwd */ + if (st != MTSE_OK) /* error? */ r = mt_map_err (uptr, st); /* map error */ break; case FNC_BSR: /* space reverse */ - if (st = sim_tape_sprecr (uptr, &tbc)) /* space rec rev, err? */ + st = sim_tape_sprecr (uptr, &tbc); /* space rec rev */ + if (st != MTSE_OK) /* error? */ r = mt_map_err (uptr, st); /* map error */ break; @@ -558,7 +562,8 @@ switch (mtc_fnc) { /* case on function */ return SCPE_OK; } if (mt_ptr) { /* write buffer */ - if (st = sim_tape_wrrecf (uptr, mtxb, mt_ptr)) { /* write, err? */ + st = sim_tape_wrrecf (uptr, mtxb, mt_ptr); /* write */ + if (st != MTSE_OK) { /* error? */ r = mt_map_err (uptr, st); /* map error */ break; /* done */ } @@ -627,7 +632,8 @@ t_stat st; if (sim_is_active (&mtc_unit) && /* write in prog? */ (mtc_fnc == FNC_WC) && (mt_ptr > 0)) { /* yes, bad rec */ - if (st = sim_tape_wrrecf (&mtc_unit, mtxb, mt_ptr | MTR_ERF)) + st = sim_tape_wrrecf (&mtc_unit, mtxb, mt_ptr | MTR_ERF); + if (st != MTSE_OK) mt_map_err (&mtc_unit, st); } diff --git a/HP2100/hp2100_stddev.c b/HP2100/hp2100_stddev.c index 92208b00..edf44c2c 100644 --- a/HP2100/hp2100_stddev.c +++ b/HP2100/hp2100_stddev.c @@ -28,6 +28,7 @@ TTY 12531C buffered teleprinter interface CLK 12539C time base generator + 09-May-12 JDB Separated assignments from conditional expressions 12-Feb-12 JDB Add TBG as a logical name for the CLK device 10-Feb-12 JDB Deprecated DEVNO in favor of SC 28-Mar-11 JDB Tidied up signal handling @@ -942,7 +943,9 @@ t_stat r; if (tty_mode & TM_PRI) { /* printing? */ c = sim_tt_outcvt (c, TT_GET_MODE (tty_unit[TTO].flags)); if (c >= 0) { /* valid? */ - if (r = sim_putchar_s (c)) return r; /* output char */ + r = sim_putchar_s (c); /* output char */ + if (r != SCPE_OK) + return r; tty_unit[TTO].pos = tty_unit[TTO].pos + 1; } } @@ -1114,7 +1117,7 @@ while (working_set) { if ((clk_unit.flags & UNIT_DIAG) == 0) /* calibrated? */ if (clk_select == 2) /* 10 msec. interval? */ - clk_tick = sync_poll (INITIAL); /* sync poll */ + clk_tick = sync_poll (INITIAL); /* sync poll */ else sim_rtcn_init (clk_tick, TMR_CLK); /* initialize timer */ diff --git a/HP2100/hp2100_sys.c b/HP2100/hp2100_sys.c index c6cd201c..c8681731 100644 --- a/HP2100/hp2100_sys.c +++ b/HP2100/hp2100_sys.c @@ -23,6 +23,7 @@ used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from Robert M Supnik. + 09-May-12 JDB Quieted warnings for assignments in conditional expressions 10-Feb-12 JDB Deprecated DEVNO in favor of SC Added hp_setsc, hp_showsc functions to support SC modifier 15-Dec-11 JDB Added DA and dummy DC devices @@ -608,11 +609,11 @@ if (opcode[i]) { /* found opcode? */ case I_V_MRF: /* mem ref */ cptr = get_glyph (cptr, gbuf, 0); /* get next field */ - if (k = (strcmp (gbuf, "C") == 0)) { /* C specified? */ + if ((k = (strcmp (gbuf, "C") == 0))) { /* C specified? */ val[0] = val[0] | I_CP; cptr = get_glyph (cptr, gbuf, 0); } - else if (k = (strcmp (gbuf, "Z") == 0)) { /* Z specified? */ + else if ((k = (strcmp (gbuf, "Z") == 0))) { /* Z specified? */ cptr = get_glyph (cptr, gbuf, ','); } if ((d = get_addr (gbuf)) < 0) return SCPE_ARG; diff --git a/HP2100/hp_disclib.c b/HP2100/hp_disclib.c index f5218ff6..ea51945e 100644 --- a/HP2100/hp_disclib.c +++ b/HP2100/hp_disclib.c @@ -24,7 +24,8 @@ used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from the authors. - 28-Mar-12 JDB First release + 07-May-12 JDB Corrected end-of-track delay time logic + 02-May-12 JDB First release 09-Nov-11 JDB Created disc controller common library from DS simulator References: @@ -1817,28 +1818,61 @@ return SCPE_OK; /* the read was successf On entry, the end-of-data flag is checked. If it is set, the current read is completed. Otherwise, the command phase is reset to start the next sector, - and the disc service is scheduled to allow for the intersector delay. + and the disc service is set to allow for the intersector delay. Implementation notes: - 1. The intersector time is required to allow the ICD interface to set the - end-of-data flag before the next sector begins. The CPU must have enough - time to receive the last byte of the current sector and then unaddress - the disc controller before the first byte of the next sector is sent. If - the time is not long enough, the sector address will be incremented twice - (e.g., a 128-word read of sector 0 will terminate with sector 2 as the - next sector instead of sector 1). + 1. The CPU indicates the end of a read data transfer to an ICD controller by + untalking the drive. The untalk is done by the driver as soon as the + DCPC completion interrupt is processed. However, the time from the final + DCPC transfer through driver entry to the point where the untalk is + asserted on the bus varies from 80 instructions (RTE-6/VM with OS + microcode and the buffer in the system map) to 152 instructions (RTE-IVB + with the buffer in the user map). The untalk must occur before the start + of the next sector, or the drive will begin the data transfer. + + Normally, this is not a problem, as the driver clears the FIFO of any + received data after DCPC completion. However, if the read terminates + after the last sector of a track, and accessing the next sector would + require an intervening seek, and the file mask disables auto-seeking or + an enabled seek would move the positioner beyond the drive limits, then + the controller will indicate an End of Cylinder error if the untalk does + not arrive before the seek is initiated. + + The RTE driver (DVA32) and various utilities that manage the disc + directly (e.g., SWTCH) do not appear to account for these bogus errors, + so the ICD controller hardware must avoid them in some unknown manner. + We work around the issue by extending the intersector delay to allow time + for a potential untalk whenever the next access would otherwise fail. + + Note that this issue does not occur with writes because DCPC completion + asserts EOI concurrently with the final data byte to terminate the + command. */ static void end_read (CVPTR cvptr, UNIT *uptr) { +uint32 limit; + if (cvptr->eod == SET) /* is the end of data indicated? */ dl_end_command (cvptr, normal_completion); /* complete the command */ else { /* reading continues */ uptr->PHASE = start_phase; /* reset to the start phase */ uptr->wait = cvptr->sector_time; /* delay for the intersector time */ + + if (cvptr->eoc == SET && cvptr->type == ICD) { /* seek will be required and controller is ICD? */ + if (!(cvptr->file_mask & DL_FAUTSK)) /* if auto-seek is disabled */ + limit = cvptr->cylinder; /* then the limit is the current cylinder */ + else if (cvptr->file_mask & DL_FDECR) /* else if enabled and decremental seek */ + limit = 0; /* then the limit is cylinder 0 */ + else /* else the enabled limit is the last cylinder */ + limit = drive_props [GET_MODEL (uptr->flags)].cylinders; + + if (cvptr->cylinder == limit) /* is positioner at the limit? */ + uptr->wait = cvptr->eot_time; /* seek will fail; delay to allow CPU to untalk */ + } } return; @@ -1964,12 +1998,12 @@ return SCPE_OK; /* Position the disc image file at the current sector. - The image file is positioned at the byte address corresponding to the - controller's current cylinder, head, and sector address. Positioning may - involve an auto-seek if a prior read or write addressed the final sector in a - cylinder. If a seek is initiated or an error is detected, the routine - returns FALSE to indicate that the positioning was not performed. If the - file was positioned, the routine returns TRUE. + The image file is positioned at the byte address corresponding to the drive's + current cylinder and the controller's current head and sector addresses. + Positioning may involve an auto-seek if a prior read or write addressed the + final sector of a cylinder. If a seek is initiated or an error is detected, + the routine returns FALSE to indicate that the positioning was not performed. + If the file was positioned, the routine returns TRUE. On entry, if the controller's end-of-cylinder flag is set, a prior read or write addressed the final sector in the current cylinder. If the file mask @@ -1983,21 +2017,23 @@ return SCPE_OK; seek completion and the command state unchanged. When the service is reentered, the read or write will continue on the new cylinder. - If the EOC flag was not set, the drive position is checked against the - controller position. If they are different (as may occur with an Address - Record command that specified a different location than the last Seek - command), a seek is started to the correct cylinder, and the routine returns - with the disc service scheduled for seek completion as above. + If the EOC flag was not set, the drive's position is checked against the + controller's position if address verification is requested. If they are + different (as may occur with an Address Record command that specified a + different location than the last Seek command), a seek is started to the + correct cylinder, and the routine returns with the disc service scheduled for + seek completion as above. - If the drive and controller positions agree, the controller CHS address is - validated against the drive limits. If they are invalid, Seek Check status - is set, and the command is terminated with an error. + If the drive and controller positions agree or verification is not requested, + the CHS addresses are validated against the drive limits. If they are + invalid, Seek Check status is set, and the command is terminated with an + error. - If the address is valid, the drive is checked to ensure that it is ready for - positioning. If it is, the the byte offset in the image file is calculated - from the CHS address, and the file is positioned. The disc service is - scheduled to begin the data transfer, and the routine returns TRUE to - indicate that the file position was set. + If the addresses are valid, the drive is checked to ensure that it is ready + for positioning. If it is, the the byte offset in the image file is + calculated from the CHS address, and the file is positioned. The disc + service is scheduled to begin the data transfer, and the routine returns TRUE + to indicate that the file position was set. Implementation notes: diff --git a/HP2100/hp_disclib.h b/HP2100/hp_disclib.h index 315fc6ec..90b2d82b 100644 --- a/HP2100/hp_disclib.h +++ b/HP2100/hp_disclib.h @@ -24,7 +24,8 @@ used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from the authors. - 30-Mar-12 JDB First release + 07-May-12 JDB Added end-of-track delay time as a controller variable + 02-May-12 JDB First release 09-Nov-11 JDB Created disc controller common library from DS simulator @@ -53,6 +54,7 @@ /* Default controller times */ +#define DL_EOT_TIME 160 /* end-of-track delay time */ #define DL_SEEK_TIME 100 /* seek delay time (per cylinder) */ #define DL_SECTOR_TIME 27 /* intersector delay time */ #define DL_CMD_TIME 3 /* command start delay time */ @@ -330,6 +332,7 @@ typedef struct { uint32 index; /* data buffer current index */ uint32 length; /* data buffer valid length */ UNIT *aux; /* MAC auxiliary units (controller and timer) */ + int32 eot_time; /* end-of-track read delay time */ int32 seek_time; /* per-cylinder seek delay time */ int32 sector_time; /* intersector delay time */ int32 cmd_time; /* command response time */ @@ -354,7 +357,7 @@ typedef CNTLR_VARS *CVPTR; /* pointer to controller CLEAR, CLEAR, \ 0, 0, 0, 0, 0, 0, 0, 0, \ (bufptr), 0, 0, (auxptr), \ - DL_SEEK_TIME, DL_SECTOR_TIME, \ + DL_EOT_TIME, DL_SEEK_TIME, DL_SECTOR_TIME, \ DL_CMD_TIME, DL_DATA_TIME, DL_WAIT_TIME diff --git a/I1401/i1401_cd.c b/I1401/i1401_cd.c index 0c7eaa5b..7bd64b70 100644 --- a/I1401/i1401_cd.c +++ b/I1401/i1401_cd.c @@ -184,7 +184,7 @@ t_stat r; if (sim_is_active (&cdr_unit)) { /* busy? */ sim_cancel (&cdr_unit); /* cancel */ - if (r = cdr_svc (&cdr_unit)) /* process */ + if ((r = cdr_svc (&cdr_unit))) /* process */ return r; } if ((cdr_unit.flags & UNIT_ATT) == 0) /* attached? */ diff --git a/I1401/i1401_cpu.c b/I1401/i1401_cpu.c index 6868556b..fdc787bd 100644 --- a/I1401/i1401_cpu.c +++ b/I1401/i1401_cpu.c @@ -547,7 +547,7 @@ while (reason == 0) { /* loop until halted */ saved_IS = IS; /* commit prev instr */ if (sim_interval <= 0) { /* check clock queue */ - if (reason = sim_process_event ()) + if ((reason = sim_process_event ())) break; } @@ -1039,7 +1039,7 @@ CHECK_LENGTH: */ case OP_R: /* read */ - if (reason = iomod (ilnt, D, r_mod)) /* valid modifier? */ + if ((reason = iomod (ilnt, D, r_mod))) /* valid modifier? */ break; reason = read_card (ilnt, D); /* read card */ BS = CDR_BUF + CDR_WIDTH; @@ -1049,7 +1049,7 @@ CHECK_LENGTH: break; case OP_W: /* write */ - if (reason = iomod (ilnt, D, w_mod)) /* valid modifier? */ + if ((reason = iomod (ilnt, D, w_mod))) /* valid modifier? */ break; reason = write_line (ilnt, D); /* print line */ BS = LPT_BUF + LPT_WIDTH; @@ -1059,7 +1059,7 @@ CHECK_LENGTH: break; case OP_P: /* punch */ - if (reason = iomod (ilnt, D, p_mod)) /* valid modifier? */ + if ((reason = iomod (ilnt, D, p_mod))) /* valid modifier? */ break; reason = punch_card (ilnt, D); /* punch card */ BS = CDP_BUF + CDP_WIDTH; @@ -1069,7 +1069,7 @@ CHECK_LENGTH: break; case OP_WR: /* write and read */ - if (reason = iomod (ilnt, D, w_mod)) /* valid modifier? */ + if ((reason = iomod (ilnt, D, w_mod))) /* valid modifier? */ break; reason = write_line (ilnt, D); /* print line */ r1 = read_card (ilnt, D); /* read card */ @@ -1082,7 +1082,7 @@ CHECK_LENGTH: break; case OP_WP: /* write and punch */ - if (reason = iomod (ilnt, D, w_mod)) /* valid modifier? */ + if ((reason = iomod (ilnt, D, w_mod))) /* valid modifier? */ break; reason = write_line (ilnt, D); /* print line */ r1 = punch_card (ilnt, D); /* punch card */ @@ -1095,7 +1095,7 @@ CHECK_LENGTH: break; case OP_RP: /* read and punch */ - if (reason = iomod (ilnt, D, NULL)) /* valid modifier? */ + if ((reason = iomod (ilnt, D, NULL))) /* valid modifier? */ break; reason = read_card (ilnt, D); /* read card */ r1 = punch_card (ilnt, D); /* punch card */ @@ -1108,7 +1108,7 @@ CHECK_LENGTH: break; case OP_WRP: /* write, read, punch */ - if (reason = iomod (ilnt, D, w_mod)) /* valid modifier? */ + if ((reason = iomod (ilnt, D, w_mod))) /* valid modifier? */ break; reason = write_line (ilnt, D); /* print line */ r1 = read_card (ilnt, D); /* read card */ @@ -1122,9 +1122,9 @@ CHECK_LENGTH: break; case OP_SS: /* select stacker */ - if (reason = iomod (ilnt, D, ss_mod)) /* valid modifier? */ + if ((reason = iomod (ilnt, D, ss_mod))) /* valid modifier? */ break; - if (reason = select_stack (D)) /* sel stack, error? */ + if ((reason = select_stack (D))) /* sel stack, error? */ break; if ((ilnt == 4) || (ilnt == 5)) { /* check for branch */ BRANCH; @@ -1132,7 +1132,7 @@ CHECK_LENGTH: break; case OP_CC: /* carriage control */ - if (reason = carriage_control (D)) /* car ctrl, error? */ + if ((reason = carriage_control (D))) /* car ctrl, error? */ break; if ((ilnt == 4) || (ilnt == 5)) { /* check for branch */ BRANCH; @@ -1154,7 +1154,7 @@ CHECK_LENGTH: reason = STOP_INVL; else if (ioind != BCD_PERCNT) /* valid dev addr? */ reason = STOP_INVA; - else if (reason = iomod (ilnt, D, mtf_mod)) /* valid modifier? */ + else if ((reason = iomod (ilnt, D, mtf_mod))) /* valid modifier? */ break; if (dev == IO_MT) /* BCD? */ reason = mt_func (unit, 0, D); diff --git a/I1401/i1401_dp.c b/I1401/i1401_dp.c index 81739b94..d45c8287 100644 --- a/I1401/i1401_dp.c +++ b/I1401/i1401_dp.c @@ -269,7 +269,7 @@ switch (fnc) { /* case on function */ for (;;) { /* loop */ qzr = (--cnt == 0); /* set zero latch */ dp_cvt_bin (dcf + DCF_CNT, DCF_CNT_LEN, cnt, MD_WM); /* redo count */ - if (r = dp_rdsec (uptr, psec, flg, qwc)) /* read sector */ + if ((r = dp_rdsec (uptr, psec, flg, qwc))) /* read sector */ break; cnt = dp_get_cnt (dcf); /* get new count */ if (cnt < 0) /* bad count? */ @@ -278,7 +278,7 @@ switch (fnc) { /* case on function */ break; sec++; psec++; /* next sector */ dp_cvt_bin (dcf + DCF_SEC, DCF_SEC_LEN, sec, flg); /* rewr sec */ - if (r = dp_nexsec (uptr, psec, dcf)) /* find next */ + if ((r = dp_nexsec (uptr, psec, dcf))) /* find next */ break; } break; /* done, clean up */ @@ -289,9 +289,9 @@ switch (fnc) { /* case on function */ for (;;) { /* loop */ qzr = (--cnt == 0); /* set zero latch */ dp_cvt_bin (dcf + DCF_CNT, DCF_CNT_LEN, cnt, MD_WM); /* redo count */ - if (r = dp_rdadr (uptr, psec, flg, qwc)) /* read addr */ + if ((r = dp_rdadr (uptr, psec, flg, qwc))) /* read addr */ break; /* error? */ - if (r = dp_rdsec (uptr, psec, flg, qwc)) /* read data */ + if ((r = dp_rdsec (uptr, psec, flg, qwc))) /* read data */ break; /* error? */ cnt = dp_get_cnt (dcf); /* get new count */ if (cnt < 0) /* bad count? */ @@ -312,13 +312,13 @@ switch (fnc) { /* case on function */ for (;;) { /* loop */ qzr = (--cnt == 0); /* set zero latch */ dp_cvt_bin (dcf + DCF_CNT, DCF_CNT_LEN, cnt, MD_WM); /* rewr cnt */ - if (r = dp_wrsec (uptr, psec, flg)) /* write data */ + if ((r = dp_wrsec (uptr, psec, flg))) /* write data */ break; if (qzr) /* zero latch? done */ break; sec++; psec++; /* next sector */ dp_cvt_bin (dcf + DCF_SEC, DCF_SEC_LEN, sec, flg); /* rewr sec */ - if (r = dp_nexsec (uptr, psec, dcf)) /* find next */ + if ((r = dp_nexsec (uptr, psec, dcf))) /* find next */ break; } break; /* done, clean up */ @@ -331,9 +331,9 @@ switch (fnc) { /* case on function */ for (;;) { /* loop */ qzr = (--cnt == 0); /* set zero latch */ dp_cvt_bin (dcf + DCF_CNT, DCF_CNT_LEN, cnt, MD_WM); /* redo count */ - if (r = dp_wradr (uptr, psec, flg)) /* write addr */ + if ((r = dp_wradr (uptr, psec, flg))) /* write addr */ break; - if (r = dp_wrsec (uptr, psec, flg)) /* write data */ + if ((r = dp_wrsec (uptr, psec, flg))) /* write data */ break; if (qzr) /* zero latch? done */ break; diff --git a/I1401/i1401_iq.c b/I1401/i1401_iq.c index e0fa7eb9..99556db6 100644 --- a/I1401/i1401_iq.c +++ b/I1401/i1401_iq.c @@ -93,8 +93,8 @@ ind[IN_INC] = 0; /* clear inq clear */ switch (mod) { /* case on mod */ case BCD_R: /* input */ -/* if (ind[IN_INR] == 0) -/* return SCPE_OK; /* return if no req */ +/* if (ind[IN_INR] == 0) */ +/* return SCPE_OK; *//* return if no req */ ind[IN_INR] = 0; /* clear req */ puts_tty ("[Enter]\r\n"); /* prompt */ for (i = 0; M[BS] != (BCD_GRPMRK + WM); i++) { /* until GM + WM */ diff --git a/I1401/i1401_mt.c b/I1401/i1401_mt.c index fcd2dea1..df7b8574 100644 --- a/I1401/i1401_mt.c +++ b/I1401/i1401_mt.c @@ -451,7 +451,7 @@ int32 i; UNIT *uptr; for (i = 0; i < MT_NUMDR; i++) { /* per drive resets */ - if (uptr = mt_sel_unit (i)) { + if ((uptr = mt_sel_unit (i))) { MT_CLR_PNU (uptr); /* clear pos flag */ } } diff --git a/I1401/i1401_sys.c b/I1401/i1401_sys.c index bab227f3..94976277 100644 --- a/I1401/i1401_sys.c +++ b/I1401/i1401_sys.c @@ -402,7 +402,7 @@ if (op >= 64) /* successful? */ return SCPE_ARG; val[0] = op | WM; /* store opcode */ cptr = get_glyph (cptr, gbuf, 0); /* get addr or d */ -if (((op_table[op] && IO) && (get_io (gbuf, &val[1]) == SCPE_OK)) || +if (((op_table[op] & IO) && (get_io (gbuf, &val[1]) == SCPE_OK)) || (get_addr (gbuf, &val[1]) == SCPE_OK)) { cptr = get_glyph (cptr, gbuf, 0); /* get addr or d */ if (get_addr (gbuf, &val[4]) == SCPE_OK) { diff --git a/I1620/i1620_cd.c b/I1620/i1620_cd.c index ebb9ccc5..2e6ba2c4 100644 --- a/I1620/i1620_cd.c +++ b/I1620/i1620_cd.c @@ -109,7 +109,7 @@ DEVICE cdp_dev = { - Can punch both 11 (-) and 11-0 (uses ]). On input, the nul and nl generated by C are converted to spaces; tabs and line feeds are also converted to spaces. - +*/ /* Card reader (ASCII) to numeric (one digit) */ const char cdr_to_num[128] = { diff --git a/I1620/i1620_cpu.c b/I1620/i1620_cpu.c index 4bf36b49..49b02106 100644 --- a/I1620/i1620_cpu.c +++ b/I1620/i1620_cpu.c @@ -476,7 +476,7 @@ while (reason == 0) { /* loop until halted */ saved_PC = PC; /* commit prev instr */ if (sim_interval <= 0) { /* check clock queue */ - if (reason = sim_process_event ()) + if ((reason = sim_process_event ())) break; } diff --git a/I1620/i1620_dp.c b/I1620/i1620_dp.c index 1f8390cb..c524eac7 100644 --- a/I1620/i1620_dp.c +++ b/I1620/i1620_dp.c @@ -206,7 +206,7 @@ switch (f1 & ~(FNC_WCH | FNC_NRL)) { /* case on function */ if (psec < 0) /* error? */ CRETIOE (dp_stop, STOP_DACERR); do { /* loop on count */ - if (r = dp_rdsec (uptr, psec, qnr, qwc)) /* read sector */ + if ((r = dp_rdsec (uptr, psec, qnr, qwc))) /* read sector */ break; sec++; psec++; /* next sector */ } while ((--cnt > 0) && @@ -216,9 +216,9 @@ switch (f1 & ~(FNC_WCH | FNC_NRL)) { /* case on function */ case FNC_TRK: /* read track */ psec = dp_trkop (drv, sec); /* start of track */ for (cnt = 0; cnt < DP_NUMSC; cnt++) { /* full track */ - if (r = dp_rdadr (uptr, psec, qnr, qwc)) /* read addr */ + if ((r = dp_rdadr (uptr, psec, qnr, qwc))) /* read addr */ break; /* error? */ - if (r = dp_rdsec (uptr, psec, qnr, qwc)) /* read data */ + if ((r = dp_rdsec (uptr, psec, qnr, qwc))) /* read data */ break; /* error? */ psec = dp_trkop (drv, sec) + ((psec + 1) % DP_NUMSC); } @@ -231,9 +231,9 @@ switch (f1 & ~(FNC_WCH | FNC_NRL)) { /* case on function */ if (psec < 0) /* error? */ CRETIOE (dp_stop, STOP_DACERR); do { /* loop on count */ - if (r = dp_tstgm (M[dp_ba], qnr)) /* start with gm? */ + if ((r = dp_tstgm (M[dp_ba], qnr))) /* start with gm? */ break; - if (r = dp_wrsec (uptr, psec, qnr)) /* write data */ + if ((r = dp_wrsec (uptr, psec, qnr))) /* write data */ break; sec++; psec++; /* next sector */ } while ((--cnt > 0) && @@ -245,11 +245,11 @@ switch (f1 & ~(FNC_WCH | FNC_NRL)) { /* case on function */ return STOP_WRADIS; psec = dp_trkop (drv, sec); /* start of track */ for (cnt = 0; cnt < DP_NUMSC; cnt++) { /* full track */ - if (r = dp_tstgm (M[dp_ba], qnr)) /* start with gm? */ + if ((r = dp_tstgm (M[dp_ba], qnr))) /* start with gm? */ break; - if (r = dp_wradr (uptr, psec, qnr)) /* write addr */ + if ((r = dp_wradr (uptr, psec, qnr))) /* write addr */ break; - if (r = dp_wrsec (uptr, psec, qnr)) /* write data */ + if ((r = dp_wrsec (uptr, psec, qnr))) /* write data */ break; psec = dp_trkop (drv, sec) + ((psec + 1) % DP_NUMSC); } diff --git a/I1620/i1620_sys.c b/I1620/i1620_sys.c index df247342..198d29e7 100644 --- a/I1620/i1620_sys.c +++ b/I1620/i1620_sys.c @@ -552,7 +552,7 @@ if (I_GETQP (opfl) != I_M_QNP) { /* Q field allowed? */ cptr = get_glyph (cptr, fptr = gbuf, ' '); /* get flag field */ last = -1; /* none yet */ -while (t = *fptr++) { /* loop through */ +while ((t = *fptr++)) { /* loop through */ if ((t < '0') || (t > '9')) /* must be digit */ return SCPE_ARG; t = t - '0'; /* convert */ diff --git a/I1620/i1620_tty.c b/I1620/i1620_tty.c index 648beeef..ac4a1021 100644 --- a/I1620/i1620_tty.c +++ b/I1620/i1620_tty.c @@ -260,7 +260,7 @@ do { *c = 0x7F; else if ((raw == '~') || (raw == '`')) /* flag? mark */ flg = FLAG; - else if (cp = strchr (tti_to_num, raw)) /* legal? */ + else if ((cp = strchr (tti_to_num, raw))) /* legal? */ *c = ((int8) (cp - tti_to_num)) | flg; /* assemble char */ else raw = 007; /* beep! */ tto_write (raw); /* echo */ diff --git a/I7094/i7094_com.c b/I7094/i7094_com.c index b5c7b29d..8f0d4e7c 100644 --- a/I7094/i7094_com.c +++ b/I7094/i7094_com.c @@ -1175,7 +1175,7 @@ char name[20]; ln = uptr - coml_dev.units; sprintf (name, val? "Output queue %d": "Input queue %d", ln); lh = val? &com_outq[ln]: &com_inpq[ln]; -if (entc = com_show_qsumm (st, lh, name)) { +if ((entc = com_show_qsumm (st, lh, name))) { for (i = 0, next = lh->head; next != 0; i++, next = com_pkt[next].next) { if ((i % 8) == 0) diff --git a/I7094/i7094_cpu.c b/I7094/i7094_cpu.c index f1d46462..4dbd5882 100644 --- a/I7094/i7094_cpu.c +++ b/I7094/i7094_cpu.c @@ -664,14 +664,14 @@ while (reason == SCPE_OK) { /* loop until error */ } if (sim_interval <= 0) { /* intv cnt expired? */ - if (reason = sim_process_event ()) /* process events */ + if ((reason = sim_process_event ())) /* process events */ break; chtr_pend = chtr_eval (NULL); /* eval chan traps */ } for (i = 0; ch_req && (i < NUM_CHAN); i++) { /* loop thru channels */ if (ch_req & REQ_CH (i)) { /* channel request? */ - if (reason = ch_proc (i)) + if ((reason = ch_proc (i))) break; } chtr_pend = chtr_eval (NULL); @@ -1973,13 +1973,13 @@ while (reason == SCPE_OK) { /* loop until error */ t_stat r; for (i = 0; (i < HALT_IO_LIMIT) && !ch_qidle (); i++) { sim_interval = 0; - if (r = sim_process_event ()) /* process events */ + if ((r = sim_process_event ())) /* process events */ return r; chtr_pend = chtr_eval (NULL); /* eval chan traps */ while (ch_req) { /* until no ch req */ for (j = 0; j < NUM_CHAN; j++) { /* loop thru channels */ if (ch_req & REQ_CH (j)) { /* channel request? */ - if (r = ch_proc (j)) + if ((r = ch_proc (j))) return r; } chtr_pend = chtr_eval (NULL); @@ -2438,7 +2438,7 @@ if (pc & HIST_PC) { /* instruction? */ } fputc ('\n', st); /* end line */ } /* end if instruction */ -else if (ch = HIST_CH (pc)) { /* channel? */ +else if ((ch = HIST_CH (pc))) { /* channel? */ fprintf (st, "CH%c ", 'A' + ch - 1); fprintf (st, "%05o ", pc & AMASK); fputs (" ", st); diff --git a/I7094/i7094_dsk.c b/I7094/i7094_dsk.c index 4c605c81..70107ca9 100644 --- a/I7094/i7094_dsk.c +++ b/I7094/i7094_dsk.c @@ -693,14 +693,14 @@ trk = uaptr->TRK; /* get access track */ switch (dsk_sta) { /* case on state */ case CHSL_RDS: /* read start */ - if (r = dsk_init_trk (udptr, trk)) { /* read track, err? */ + if ((r = dsk_init_trk (udptr, trk))) { /* read track, err? */ return ((r == ERR_NRCF)? SCPE_OK: r); /* rec not fnd ok */ } dsk_sta = CHSL_RDS|CHSL_2ND; /* next state */ break; case CHSL_RDS|CHSL_2ND: /* read data transmit */ - if (r = dsk_xfer_done (uaptr, dtyp)) { /* transfer done? */ + if ((r = dsk_xfer_done (uaptr, dtyp))) { /* transfer done? */ if (r != ERR_ENDRC) /* error? */ return r; dsk_sta = CHSL_RDS|CHSL_3RD; /* next state */ @@ -721,7 +721,7 @@ switch (dsk_sta) { /* case on state */ break; case CHSL_WRS: /* write start */ - if (r = dsk_init_trk (udptr, trk)) { /* read track, err? */ + if ((r = dsk_init_trk (udptr, trk))) { /* read track, err? */ return ((r == ERR_NRCF)? SCPE_OK: r); /* rec not fnd ok */ } ch_req |= REQ_CH (dsk_ch); /* first request */ @@ -742,7 +742,7 @@ switch (dsk_sta) { /* case on state */ else dsk_buf[dsk_rptr++] = dsk_chob; /* write, store word */ if (dsk_rptr == T1STREC) /* if THA, skip after HA */ dsk_rptr++; - if (r = dsk_xfer_done (uaptr, dtyp)) { /* transfer done? */ + if ((r = dsk_xfer_done (uaptr, dtyp))) { /* transfer done? */ if (r != ERR_ENDRC) /* error? */ return r; dsk_sta = CHSL_WRS|CHSL_3RD; /* next state */ @@ -755,7 +755,7 @@ switch (dsk_sta) { /* case on state */ case CHSL_WRS|CHSL_3RD: /* write done */ if (!dsk_wchk) { /* if write */ - if (r = dsk_wr_trk (udptr, trk)) /* write track; err? */ + if ((r = dsk_wr_trk (udptr, trk))) /* write track; err? */ return r; } if (dsk_qdone (dsk_ch)) /* done? exit */ @@ -846,7 +846,7 @@ switch (dsk_sta) { /* case on state */ if (!dsk_wchk) { /* actual write? */ trk = trk - (trk % dsk_tab[dtyp].trkpc); /* cyl start */ for (i = 0; i < dsk_tab[dtyp].trkpc; i++) { /* do all tracks */ - if (r = dsk_wr_trk (udptr, trk + i)) /* wr track; err? */ + if ((r = dsk_wr_trk (udptr, trk + i))) /* wr track; err? */ return r; } } diff --git a/I7094/i7094_io.c b/I7094/i7094_io.c index e4e81d13..391debfa 100644 --- a/I7094/i7094_io.c +++ b/I7094/i7094_io.c @@ -795,7 +795,7 @@ switch (ch_sta[ch]) { /* case on chan state */ if (ch_dev[ch].flags & DEV_7289) { /* drum channel? */ ir = ReadP (clc); /* read addr */ ch_clc[ch] = CHAINC (clc); /* incr chan pc */ - if (r = ch9_wr (ch, ir, 0)) /* write to dev */ + if ((r = ch9_wr (ch, ir, 0))) /* write to dev */ return r; } else ch_clc[ch] = clc; /* set clc */ @@ -1003,7 +1003,7 @@ if (ch_dev[ch].flags & DEV_7909) { /* 7909 */ return SCPE_OK; case CH9_SNS: /* sense */ - if (r = ch9_sel (ch, CHSL_SNS)) /* send sense to dev */ + if ((r = ch9_sel (ch, CHSL_SNS))) /* send sense to dev */ return r; ch_flags[ch] |= CHF_PRD; /* prepare to read */ break; /* next command */ @@ -1019,13 +1019,13 @@ if (ch_dev[ch].flags & DEV_7909) { /* 7909 */ } ch_flags[ch] &= ~CHF_EOR; /* clear end */ if (ch_op[ch] == CH9_CTLR) { /* CTLR? */ - if (r = ch9_sel (ch, CHSL_RDS)) /* send read sel */ + if ((r = ch9_sel (ch, CHSL_RDS))) /* send read sel */ return r; ch_flags[ch] |= CHF_PRD; /* prep to read */ ch_idf[ch] = 0; } else if (ch_op[ch] == CH9_CTLW) { /* CTLW? */ - if (r = ch9_sel (ch, CHSL_WRS)) /* end write sel */ + if ((r = ch9_sel (ch, CHSL_WRS))) /* end write sel */ return r; ch_flags[ch] |= CHF_PWR; /* prep to write */ } @@ -1035,7 +1035,7 @@ if (ch_dev[ch].flags & DEV_7909) { /* 7909 */ if ((ch_wc[ch] == 0) || (ch_flags[ch] & CHF_EOR)) { /* wc == 0 or EOR? */ if (ch_flags[ch] & (CHF_PRD|CHF_PWR|CHF_RDS|CHF_WRS)) { ch_flags[ch] &= ~(CHF_PRD|CHF_PWR|CHF_RDS|CHF_WRS); - if (r = ch9_wr (ch, 0, CH9DF_STOP)) /* send stop */ + if ((r = ch9_wr (ch, 0, CH9DF_STOP))) /* send stop */ return r; } if (ch_flags[ch] & CHF_EOR) { /* EOR? */ @@ -1055,7 +1055,7 @@ if (ch_dev[ch].flags & DEV_7909) { /* 7909 */ ch_flags[ch] &= ~CHF_EOR; /* ignore */ else if (ch_flags[ch] & CHF_RDS) /* read? */ ch9_rd_putw (ch); - else if (r = ch9_wr_getw (ch)) /* no, write */ + else if ((r = ch9_wr_getw (ch))) /* no, write */ return r; if (ch_wc[ch] == 0) /* done? get next */ break; @@ -1164,7 +1164,7 @@ else { /* 7607 write */ case CH6_IOCD: /* IOCD */ if (ch_wc[ch]) { /* wc > 0? */ - if (r = ch6_wr_getw (ch, TRUE)) /* send wd to dev; err? */ + if ((r = ch6_wr_getw (ch, TRUE))) /* send wd to dev; err? */ return r; if (ch_wc[ch]) /* more to do? */ return SCPE_OK; @@ -1174,7 +1174,7 @@ else { /* 7607 write */ case CH6_IOCP: /* IOCP */ case CH6_IOSP: /* IOSP */ if (ch_wc[ch]) { /* wc > 0? */ - if (r = ch6_wr_getw (ch, FALSE)) /* send wd to dev; err? */ + if ((r = ch6_wr_getw (ch, FALSE))) /* send wd to dev; err? */ return r; if (ch_wc[ch]) /* more to do? */ return SCPE_OK; @@ -1184,7 +1184,7 @@ else { /* 7607 write */ case CH6_IOCT: /* IOCT */ case CH6_IOST: /* IOST */ if (ch_wc[ch]) { /* wc > 0? */ - if (r = ch6_wr_getw (ch, FALSE)) /* send wd to dev; err? */ + if ((r = ch6_wr_getw (ch, FALSE))) /* send wd to dev; err? */ return r; if (ch_wc[ch]) /* more to do? */ return SCPE_OK; @@ -1193,7 +1193,7 @@ else { /* 7607 write */ case CH6_IORP: /* IORP */ if (!(ch_flags[ch] & CHF_EOR) && ch_wc[ch]) { /* not EOR? (cdp, lpt) */ - if (r = ch6_wr_getw (ch, TRUE)) /* send wd to dev; err? */ + if ((r = ch6_wr_getw (ch, TRUE))) /* send wd to dev; err? */ return r; if (ch_wc[ch]) /* more to do? */ return SCPE_OK; @@ -1203,7 +1203,7 @@ else { /* 7607 write */ case CH6_IORT: /* IORT */ if (!(ch_flags[ch] & CHF_EOR) && ch_wc[ch]) { /* not EOR? (cdp, lpt) */ - if (r = ch6_wr_getw (ch, TRUE)) /* send wd to dev; err? */ + if ((r = ch6_wr_getw (ch, TRUE))) /* send wd to dev; err? */ return r; if (ch_wc[ch]) /* more to do? */ return SCPE_OK; diff --git a/I7094/i7094_mt.c b/I7094/i7094_mt.c index edf1d06b..dddf2531 100644 --- a/I7094/i7094_mt.c +++ b/I7094/i7094_mt.c @@ -564,7 +564,7 @@ switch (uptr->UST) { /* case on state */ bc = chrono_rd (xb, MT_MAXFR); /* read clock */ else { /* real tape */ r = sim_tape_rdrecf (uptr, xb, &bc, MT_MAXFR); /* read record */ - if (r = mt_map_err (uptr, r)) /* map status */ + if ((r = mt_map_err (uptr, r))) /* map status */ return r; if (mt_unit[ch] == 0) /* disconnected? */ return SCPE_OK; @@ -736,7 +736,7 @@ if (mt_bptr[ch]) { /* any data? */ if (xb == NULL) return SCPE_IERR; r = sim_tape_wrrecf (uptr, xb, mt_bptr[ch]); /* write record */ - if (r = mt_map_err (uptr, r)) /* map error */ + if ((r = mt_map_err (uptr, r))) /* map error */ return r; } uptr->UST = CHSL_WRS|CHSL_3RD; /* next state */ diff --git a/Ibm1130/ibm1130_cr.c b/Ibm1130/ibm1130_cr.c index 62230842..cc01d941 100644 --- a/Ibm1130/ibm1130_cr.c +++ b/Ibm1130/ibm1130_cr.c @@ -2580,7 +2580,8 @@ static t_stat pcr_svc (UNIT *uptr) break; case OP_READING: - if (pcr_nready >= 2) { /* if there is a whole column buffered, simulate column interrupt/* pcr_trigger_interrupt_0 - simulate a read response interrupt so OS will read queued column data */ + if (pcr_nready >= 2) { /* if there is a whole column buffered, simulate column interrupt*/ + /* pcr_trigger_interrupt_0 - simulate a read response interrupt so OS will read queued column data */ pcr_trigger_interrupt_0(); sim_activate(&cr_unit, cr_wait); /* keep checking frequently */ diff --git a/Ibm1130/ibm1130_sca.c b/Ibm1130/ibm1130_sca.c index 1e41d3c8..60e850a6 100644 --- a/Ibm1130/ibm1130_sca.c +++ b/Ibm1130/ibm1130_sca.c @@ -85,9 +85,6 @@ #include "ibm1130_defs.h" #include "sim_sock.h" /* include path must include main simh directory */ #include -#ifndef INADDR_NONE -#define INADDR_NONE ((unsigned long)-1) -#endif #define DEBUG_SCA_FLUSH 0x0001 /* debugging options */ #define DEBUG_SCA_TRANSMIT 0x0002 @@ -106,7 +103,7 @@ /* #define DEBUG_SCA (DEBUG_SCA_TIMERS|DEBUG_SCA_FLUSH|DEBUG_SCA_TRANSMIT|DEBUG_SCA_CHECK_INDATA|DEBUG_SCA_RECEIVE_SYNC|DEBUG_SCA_RECEIVE_DATA|DEBUG_SCA_XIO_INITR|DEBUG_SCA_XIO_INITW) */ #define DEBUG_SCA (DEBUG_SCA_TIMERS|DEBUG_SCA_FLUSH|DEBUG_SCA_CHECK_INDATA|DEBUG_SCA_XIO_INITR|DEBUG_SCA_XIO_INITW) -#define SCA_DEFAULT_PORT 2703 /* default socket, This is the number of the IBM 360's BSC device */ +#define SCA_DEFAULT_PORT "2703" /* default socket, This is the number of the IBM 360's BSC device */ #define MAX_SYNS 100 /* number of consecutive syn's after which we stop buffering them */ @@ -164,7 +161,7 @@ static uint32 sca_state = SCA_STATE_IDLE; static uint8 sichar = 0; /* sync/idle character */ static uint8 rcvd_char = 0; /* most recently received character */ static uint8 sca_frame = 8; -static uint16 sca_port = SCA_DEFAULT_PORT; /* listening port number */ +static char sca_port[CBUFSIZE]; /* listening port */ static int32 sca_keepalive = 0; /* keepalive SYN packet period in msec, default = 0 (disabled) */ static SCA_TIMER_STATE sca_timer_state[3]; /* current timer state */ static int sca_timer_endtime[3]; /* clocktime when timeout is to occur if state is RUNNING */ @@ -217,11 +214,11 @@ REG sca_reg[] = { /* DEVICE STATE/SETTABLE PARAMETERS: */ { HRDATA (SCADSW, sca_dsw, 16) }, /* device status word */ { DRDATA (SICHAR, sichar, 8), PV_LEFT }, /* sync/idle character */ { DRDATA (RCVDCHAR, rcvd_char, 8), PV_LEFT }, /* most recently received character */ - { DRDATA (FRAME, sca_frame, 8), PV_LEFT }, /* frame bits (6, 7 or 8) + { DRDATA (FRAME, sca_frame, 8), PV_LEFT }, /* frame bits (6, 7 or 8) */ { DRDATA (SCASTATE, sca_state, 32), PV_LEFT }, /* current state */ { DRDATA (CTIME, sca_cwait, 32), PV_LEFT }, /* inter-character wait */ { DRDATA (ITIME, sca_iwait, 32), PV_LEFT }, /* idle wait (polling interval for socket connects) */ - { DRDATA (SCASOCKET, sca_port, 16), PV_LEFT }, /* listening port number */ + { BRDATA (SCASOCKET, sca_port, 8, 8, sizeof(sca_port)) }, /* listening port number */ { DRDATA (KEEPALIVE, sca_keepalive, 32), PV_LEFT }, /* keepalive packet period in msec */ { NULL } }; @@ -317,7 +314,7 @@ static void sca_socket_error (void) free(sca_unit.filename); if (sca_unit.flags & UNIT_LISTEN) { - sprintf(name, "(Listening on port %d)", sca_port); + sprintf(name, "(Listening on port %s)", sca_port); sca_unit.filename = mstring(name); printf("%s\n", name); } @@ -454,99 +451,75 @@ static t_stat sca_reset (DEVICE *dptr) static t_stat sca_attach (UNIT *uptr, char *cptr) { + char host[CBUFSIZE], port[CBUFSIZE]; t_bool do_listen; - char *colon; - uint32 ipaddr; - int32 port; - struct hostent *he; - char name[256]; - static SOCKET sdummy = INVALID_SOCKET; - fd_set wr_set, err_set; + char name[CBUFSIZE]; + t_stat r; do_listen = sim_switches & SWMASK('L'); /* -l means listen mode */ if (sca_unit.flags & UNIT_ATT) /* if already attached, detach */ detach_unit(&sca_unit); - if (do_listen) { /* if listen mode, string specifies socket number (only; otherwise it's a dummy argument) */ - if (isdigit(*cptr)) { /* if digits specified, extract port number */ - port = atoi(cptr); - if (port <= 0 || port > 65535) - return SCPE_ARG; - else - sca_port = port; - } + if (do_listen) { /* if listen mode, string specifies port number (only; otherwise it's a dummy argument) */ + r = sim_parse_addr (cptr, host, sizeof(host), NULL, port, sizeof(port), SCA_DEFAULT_PORT); + if (r != SCPE_OK) + return r; + if ((0 == strcmp(port, cptr)) && (0 == strcmp(port, "dummy"))) + strcpy(port, SCA_DEFAULT_PORT); + + sprintf(sca_port, "%s%s%s:%s", strchr(host, ':') ? "[" : "", host, strchr(host, ':') ? "]" : "", port); + /* else if nondigits specified, ignore... but the command has to have something there otherwise the core scp */ /* attach_cmd() routine complains "too few arguments". */ - if ((sca_lsock = sim_master_sock(sca_port)) == INVALID_SOCKET) + sca_lsock = sim_master_sock(sca_port, &r); + if (r != SCPE_OK) + return r; + if (sca_lsock == INVALID_SOCKET) return SCPE_OPENERR; SETBIT(sca_unit.flags, UNIT_LISTEN); /* note that we are listening, not yet connected */ - sprintf(name, "(Listening on port %d)", sca_port); - sca_unit.filename = mstring(name); - printf("%s\n", name); + sprintf(name, "(Listening on port %s)", sca_port); + sca_unit.filename = mstring(name); + printf("%s\n", sca_unit.filename); } else { - while (*cptr && *cptr <= ' ') + while (*cptr && *cptr <= ' ') cptr++; if (! *cptr) return SCPE_2FARG; - if ((colon = strchr(cptr, ':')) != NULL) { - *colon++ = '\0'; /* clip hostname at colon */ + r = sim_parse_addr (cptr, host, sizeof(host), NULL, port, sizeof(port), SCA_DEFAULT_PORT); + if (r != SCPE_OK) + return r; + if ((0 == strcmp(cptr, port)) && (0 == strcmp(host, ""))) { + strcpy(host, port); + strcpy(port, SCA_DEFAULT_PORT); + } - port = atoi(colon); /* extract port number that follows it */ - if (port <= 0 || port > 65535) - return SCPE_ARG; - else - sca_port = port; - } + sprintf(sca_port, "%s%s%s:%s", strchr(host, ':') ? "[" : "", host, strchr(host, ':') ? "]" : "", port); - if (sdummy == INVALID_SOCKET) - if ((sdummy = sim_create_sock()) == INVALID_SOCKET) /* create and keep a socket, to force initialization */ - return SCPE_IERR; /* of socket library (e.g on Win32 call WSAStartup), else gethostbyname fails */ - - if (get_ipaddr(cptr, &ipaddr, NULL) != SCPE_OK) { /* try to parse hostname as dotted decimal nnn.nnn.nnn.nnn */ - if ((he = gethostbyname(cptr)) == NULL) /* if not decimal, look up name through DNS */ - return SCPE_OPENERR; - - if ((ipaddr = * (unsigned long *) he->h_addr_list[0]) == INADDR_NONE) - return SCPE_OPENERR; - - ipaddr = ntohl(ipaddr); /* convert to host byte order; gethostbyname() gives us network order */ - } - - if ((sca_sock = sim_connect_sock(ipaddr, sca_port)) == INVALID_SOCKET) + if ((sca_sock = sim_connect_sock(sca_port, NULL, NULL)) == INVALID_SOCKET) return SCPE_OPENERR; /* sim_connect_sock() sets socket to nonblocking before initiating the connect, so * the connect is pending when it returns. For outgoing connections, the attach command should wait - * until the connection succeeds or fails. We use "accept" to wait and find out which way it goes... + * until the connection succeeds or fails. We use "sim_check_conn" to wait and find out which way it goes... */ - FD_ZERO(&wr_set); /* we are only interested in info for sca_sock */ - FD_ZERO(&err_set); - FD_SET(sca_sock, &wr_set); - FD_SET(sca_sock, &err_set); + while (0 == sim_check_conn(sca_sock, 0))/* wait for connection to complete or fail */ + sim_os_ms_sleep(1000); - select(3, NULL, &wr_set, &err_set, NULL); /* wait for connection to complete or fail */ - - if (FD_ISSET(sca_sock, &wr_set)) { /* sca_sock appears in "writable" set -- connect completed */ - sprintf(name, "%s:%d", cptr, sca_port); + if (1 == sim_check_conn(sca_sock, 0)) { /* sca_sock appears in "writable" set -- connect completed */ + sprintf(name, "%s%s%s:%s", strchr(host, ':') ? "[" : "", host, strchr(host, ':') ? "]" : "", port); sca_unit.filename = mstring(name); SETBIT(sca_dsw, SCA_DSW_READY); } - else if (FD_ISSET(sca_sock, &err_set)) { /* sca_sock appears in "error" set -- connect failed */ - sim_close_sock(sca_sock, TRUE); - sca_sock = INVALID_SOCKET; - return SCPE_OPENERR; - } - else { /* if we get here my assumption about how select works is wrong */ - printf("SCA_SOCK NOT FOUND IN WR_SET -OR- ERR_SET, CODING IN IBM1130_SCA IS WRONG\n"); + else { /* sca_sock appears in "error" set -- connect failed */ sim_close_sock(sca_sock, TRUE); sca_sock = INVALID_SOCKET; return SCPE_OPENERR; @@ -610,22 +583,17 @@ static t_stat sca_detach (UNIT *uptr) static void sca_check_connect (void) { - uint32 ipaddr; - char name[100]; + char *connectaddress; - if ((sca_sock = sim_accept_conn(sca_lsock, &ipaddr)) == INVALID_SOCKET) + if ((sca_sock = sim_accept_conn(sca_lsock, &connectaddress)) == INVALID_SOCKET) return; - ipaddr = htonl(ipaddr); /* convert to network order so we can print it */ - - sprintf(name, "%d.%d.%d.%d", ipaddr & 0xFF, (ipaddr >> 8) & 0xFF, (ipaddr >> 16) & 0xFF, (ipaddr >> 24) & 0xFF); - - printf("(SCA connection from %s)\n", name); + printf("(SCA connection from %s)\n", connectaddress); if (sca_unit.filename != NULL) free(sca_unit.filename); - sca_unit.filename = mstring(name); + sca_unit.filename = connectaddress; SETBIT(sca_dsw, SCA_DSW_READY); /* indicate active connection */ diff --git a/Interdata/id16_cpu.c b/Interdata/id16_cpu.c index f3ec00ad..2a5605c2 100644 --- a/Interdata/id16_cpu.c +++ b/Interdata/id16_cpu.c @@ -604,7 +604,7 @@ while (reason == 0) { /* loop until halted */ int32 sr, st; if (sim_interval <= 0) { /* check clock queue */ - if (reason = sim_process_event ()) + if ((reason = sim_process_event ())) break; int_eval (); } diff --git a/Interdata/id32_cpu.c b/Interdata/id32_cpu.c index 7af43c61..6b874df3 100644 --- a/Interdata/id32_cpu.c +++ b/Interdata/id32_cpu.c @@ -664,7 +664,7 @@ while (reason == 0) { /* loop until halted */ int32 sr, st; if (sim_interval <= 0) { /* check clock queue */ - if (reason = sim_process_event ()) + if ((reason = sim_process_event ())) break; int_eval (); } diff --git a/Interdata/id_dp.c b/Interdata/id_dp.c index a62bf33f..cf3f82c2 100644 --- a/Interdata/id_dp.c +++ b/Interdata/id_dp.c @@ -419,7 +419,7 @@ switch (dp_cmd & 0x7) { /* case on func */ if (sch_actv (dp_dib.sch, dp_dib.dno)) { /* sch transfer? */ if (dp_dter (uptr, dp_1st)) /* check xfr err */ return SCPE_OK; - if (r = dp_rds (uptr)) /* read sec, err? */ + if ((r = dp_rds (uptr))) /* read sec, err? */ return r; dp_1st = 0; t = sch_wrmem (dp_dib.sch, dpxb, DP_NUMBY); /* write to memory */ @@ -438,7 +438,7 @@ switch (dp_cmd & 0x7) { /* case on func */ return SCPE_OK; dp_bptr = sch_rdmem (dp_dib.sch, dpxb, DP_NUMBY); /* read from mem */ dp_db = dpxb[dp_bptr - 1]; /* last byte */ - if (r = dp_wds (uptr)) /* write sec, err? */ + if ((r = dp_wds (uptr))) /* write sec, err? */ return r; dp_1st = 0; if (sch_actv (dp_dib.sch, dp_dib.dno)) { /* more to do? */ diff --git a/Interdata/id_idc.c b/Interdata/id_idc.c index 38854d1c..f888ba6a 100644 --- a/Interdata/id_idc.c +++ b/Interdata/id_idc.c @@ -96,7 +96,7 @@ /* Drive status, ^ = dynamic, * = in unit status */ #define STD_WRP 0x80 /* ^write prot */ -/* 0x40 /* unused */ +/* 0x40 *//* unused */ #define STD_ACH 0x20 /* alt chan busy NI */ #define STD_UNS 0x10 /* *unsafe */ #define STD_NRDY 0x08 /* ^not ready */ @@ -576,7 +576,7 @@ switch (uptr->FNC & CMC_MASK) { /* case on func */ if (sch_actv (idc_dib.sch, idc_dib.dno)) { /* sch transfer? */ if (idc_dter (uptr, idc_1st)) /* dte? done */ return SCPE_OK; - if (r = idc_rds (uptr)) /* read sec, err? */ + if ((r = idc_rds (uptr))) /* read sec, err? */ return r; idc_1st = 0; t = sch_wrmem (idc_dib.sch, idcxb, IDC_NUMBY); /* write mem */ @@ -595,7 +595,7 @@ switch (uptr->FNC & CMC_MASK) { /* case on func */ return SCPE_OK; idc_bptr = sch_rdmem (idc_dib.sch, idcxb, IDC_NUMBY); /* read mem */ idc_db = idcxb[idc_bptr - 1]; /* last byte */ - if (r = idc_wds (uptr)) /* write sec, err? */ + if ((r = idc_wds (uptr))) /* write sec, err? */ return r; idc_1st = 0; if (sch_actv (idc_dib.sch, idc_dib.dno)) { /* more to do? */ diff --git a/Interdata/id_io.c b/Interdata/id_io.c index 86228eda..4ba20a23 100644 --- a/Interdata/id_io.c +++ b/Interdata/id_io.c @@ -358,7 +358,7 @@ if ((r != SCPE_OK) || (newmax == sch_max)) /* err or no chg? */ if (newmax == 0) /* must be > 0 */ return SCPE_ARG; if (newmax < sch_max) { /* reducing? */ - for (i = 0; dptr = sim_devices[i]; i++) { /* loop thru dev */ + for (i = 0; (dptr = sim_devices[i]); i++) { /* loop thru dev */ dibp = (DIB *) dptr->ctxt; /* get DIB */ if (dibp && (dibp->sch >= (int32) newmax)) { /* dev using chan? */ printf ("Device %02X uses channel %d\n", @@ -439,7 +439,7 @@ int32 i, j, t; uint32 r; for (i = t = 0; i < INTSZ; i++) { /* loop thru array */ - if (r = int_req[i] & int_enb[i]) { /* find nz int wd */ + if ((r = int_req[i] & int_enb[i])) { /* find nz int wd */ for (j = 0; j < 32; t++, j++) { if (r & (1u << j)) { int_req[i] = int_req[i] & ~(1u << j); /* clr request */ @@ -630,7 +630,7 @@ for (i = 0; i < (DEVNO / 32); i++) /* Test each device for conflict; add to map; init tables */ -for (i = 0; dptr = sim_devices[i]; i++) { /* loop thru devices */ +for (i = 0; (dptr = sim_devices[i]); i++) { /* loop thru devices */ dibp = (DIB *) dptr->ctxt; /* get DIB */ if ((dibp == NULL) || (dptr->flags & DEV_DIS)) /* exist, enabled? */ continue; diff --git a/Interdata/id_mt.c b/Interdata/id_mt.c index fce949fa..f71a5f18 100644 --- a/Interdata/id_mt.c +++ b/Interdata/id_mt.c @@ -368,13 +368,13 @@ switch (uptr->UCMD) { /* case on function */ } if (mt_bptr) { /* any chars? */ - if (st = sim_tape_wrrecf (uptr, mtxb, mt_bptr)) /* write, err? */ + if ((st = sim_tape_wrrecf (uptr, mtxb, mt_bptr)))/* write, err? */ r = mt_map_err (uptr, st); /* map error */ } break; /* record done */ case MTC_WEOF: /* write eof */ - if (st = sim_tape_wrtmk (uptr)) /* write tmk, err? */ + if ((st = sim_tape_wrtmk (uptr))) /* write tmk, err? */ r = mt_map_err (uptr, st); /* map error */ mt_sta = mt_sta | STA_EOF; /* set eof */ if (mt_arm[u]) /* set intr */ @@ -402,7 +402,7 @@ switch (uptr->UCMD) { /* case on function */ break; case MTC_SPCR: /* backspace */ - if (st = sim_tape_sprecr (uptr, &tbc)) /* skip rec rev, err? */ + if ((st = sim_tape_sprecr (uptr, &tbc))) /* skip rec rev, err? */ r = mt_map_err (uptr, st); /* map error */ break; } /* end case */ diff --git a/Interdata/id_pas.c b/Interdata/id_pas.c index dfc27ccf..3e2d105a 100644 --- a/Interdata/id_pas.c +++ b/Interdata/id_pas.c @@ -334,7 +334,7 @@ if (ln >= 0) { /* got one? */ tmxr_poll_rx (&pas_desc); /* poll for input */ for (ln = 0; ln < PAS_ENAB; ln++) { /* loop thru lines */ if (pas_ldsc[ln].conn) { /* connected? */ - if (c = tmxr_getc_ln (&pas_ldsc[ln])) { /* any char? */ + if ((c = tmxr_getc_ln (&pas_ldsc[ln]))) { /* any char? */ pas_sta[ln] = pas_sta[ln] & ~(STA_FR | STA_PF); if (pas_rchp[ln]) pas_sta[ln] = pas_sta[ln] | STA_OVR; diff --git a/LGP/lgp_cpu.c b/LGP/lgp_cpu.c index 6b969306..27f2746c 100644 --- a/LGP/lgp_cpu.c +++ b/LGP/lgp_cpu.c @@ -288,7 +288,7 @@ if (lgp21_sov) { /* stop sense pending? * do { if (sim_interval <= 0) { /* check clock queue */ - if (r = sim_process_event ()) + if ((r = sim_process_event ())) break; } @@ -308,7 +308,7 @@ do { PC = (PC + 1) & AMASK; /* increment PC */ sim_interval = sim_interval - 1; - if (r = cpu_one_inst (oPC, IR)) { /* one instr; error? */ + if ((r = cpu_one_inst (oPC, IR))) { /* one instr; error? */ if (r == STOP_STALL) { /* stall? */ PC = oPC; /* back up PC */ delay = r = 0; /* no delay */ @@ -744,7 +744,7 @@ if (cptr) { else inst = IR; while ((r = cpu_one_inst (PC, inst)) == STOP_STALL) { sim_interval = 0; - if (r = sim_process_event ()) + if ((r = sim_process_event ())) return r; } return r; diff --git a/LGP/lgp_stddev.c b/LGP/lgp_stddev.c index 2dba6cc1..f86ac096 100644 --- a/LGP/lgp_stddev.c +++ b/LGP/lgp_stddev.c @@ -394,7 +394,7 @@ t_stat ttr_svc (UNIT *uptr) { t_stat r; -if (r = read_reader (uptr, ttr_stopioe, (int32 *) &tti_buf)) +if ((r = read_reader (uptr, ttr_stopioe, (int32 *) &tti_buf))) return r; if (!(uptr->flags & UNIT_NOCS) && /* cstop enable? */ (tti_buf == FLEX_CSTOP)) /* cond stop? */ @@ -415,7 +415,7 @@ t_stat ptr_svc (UNIT *uptr) { t_stat r; -if (r = read_reader (uptr, ptr_stopioe, &uptr->buf)) +if ((r = read_reader (uptr, ptr_stopioe, &uptr->buf))) return r; if (uptr->buf == FLEX_CSTOP) /* cond stop? */ inp_done = 1; @@ -548,7 +548,7 @@ else { ch = '\b'; else ch = flex_to_ascii[flex | (tto_uc << 6)]; /* cvt flex to ascii */ if (ch > 0) { /* legit? */ - if (r = sim_putchar_s (ch)) /* write char */ + if ((r = sim_putchar_s (ch))) /* write char */ return r; tto_unit[0].pos = tto_unit[0].pos + 1; if (flex == FLEX_CR) { /* cr? */ diff --git a/LGP/lgp_sys.c b/LGP/lgp_sys.c index f445e202..083a3025 100644 --- a/LGP/lgp_sys.c +++ b/LGP/lgp_sys.c @@ -363,7 +363,7 @@ if ((sw & SWMASK ('L')) || /* LGP hex? */ return SCPE_OK; if (islower (c)) c = toupper (c); - if (tptr = strchr (hex_decode, c)) + if ((tptr = strchr (hex_decode, c))) val[0] = (val[0] << 4) | (tptr - hex_decode); else return SCPE_ARG; } @@ -388,7 +388,7 @@ else sgn = 0; cptr = get_glyph (cptr, gbuf, 0); /* get opcode */ if (gbuf[1] != 0) return SCPE_ARG; -if (tptr = strchr (opcode, gbuf[0])) +if ((tptr = strchr (opcode, gbuf[0]))) val[0] = ((tptr - opcode) << I_V_OP) | sgn; /* merge opcode */ else return SCPE_ARG; cptr = get_glyph (cptr, gbuf, 0); /* get address */ diff --git a/NOVA/eclipse_cpu.c b/NOVA/eclipse_cpu.c index 2e9efc42..c855cc55 100644 --- a/NOVA/eclipse_cpu.c +++ b/NOVA/eclipse_cpu.c @@ -744,7 +744,7 @@ if (MapInit == 0) { while (reason == 0) { /* loop until halted */ if (sim_interval <= 0) { /* check clock queue */ - if (reason = sim_process_event ()) + if ((reason = sim_process_event ())) break; } diff --git a/NOVA/nova_dkp.c b/NOVA/nova_dkp.c index a89edf6e..f5126f28 100644 --- a/NOVA/nova_dkp.c +++ b/NOVA/nova_dkp.c @@ -25,6 +25,7 @@ dkp moving head disk + 27-Apr-12 RMS Changed ??? string digraphs to ?, per C rules 04-Jul-04 BKR device name changed to DG's DKP from DEC's DP, DEV_SET/CLR/INTR macro use started, fixed 'P' pulse code and secret quirks, @@ -706,7 +707,7 @@ if ( DKP_TRACE(1) ) "write" : ((uptr->FUNC == FCCY_SEEK) ? "seek" - : "" + : "" ) ) ), @@ -871,7 +872,7 @@ do { "read" : ((uptr->FUNC == FCCY_WRITE) ? "write" - : "") + : "") ), (unsigned) (uptr->CYL), (unsigned) (GET_SURF(dkp_ussc, dtype)), @@ -908,7 +909,7 @@ do { if (uptr->FUNC == FCCY_READ) { /* read? */ awc = fxread (tbuf, sizeof(uint16), DKP_NUMWD, uptr->fileref); for ( ; awc < DKP_NUMWD; awc++) tbuf[awc] = 0; - if (err = ferror (uptr->fileref)) + if ((err = ferror (uptr->fileref))) break; for (dx = 0; dx < DKP_NUMWD; dx++) { /* loop thru buffer */ pa = MapAddr (dkp_map, (dkp_ma & AMASK)); @@ -924,7 +925,7 @@ do { dkp_ma = (dkp_ma + 1) & AMASK; } fxwrite (tbuf, sizeof(int16), DKP_NUMWD, uptr->fileref); - if (err = ferror (uptr->fileref)) + if ((err = ferror (uptr->fileref))) break; } diff --git a/NOVA/nova_mta.c b/NOVA/nova_mta.c index 787c37ab..25a9ec1e 100644 --- a/NOVA/nova_mta.c +++ b/NOVA/nova_mta.c @@ -412,7 +412,7 @@ else switch (c) { /* case on command */ mtxb[p++] = M[pa] & 0377; mta_ma = (mta_ma + 1) & AMASK; } - if (st = sim_tape_wrrecf (uptr, mtxb, tbc)) { /* write rec, err? */ + if ((st = sim_tape_wrrecf (uptr, mtxb, tbc))) { /* write rec, err? */ r = mta_map_err (uptr, st); /* map error */ mta_ma = (mta_ma - wc) & AMASK; /* restore wc */ } @@ -421,7 +421,7 @@ else switch (c) { /* case on command */ break; case CU_WREOF: /* write eof */ - if (st = sim_tape_wrtmk (uptr)) /* write tmk, err? */ + if ((st = sim_tape_wrtmk (uptr))) /* write tmk, err? */ r = mta_map_err (uptr, st); /* map error */ else mta_upddsta (uptr, uptr->USTAT | STA_EOF | STA_RDY); break; @@ -435,7 +435,7 @@ else switch (c) { /* case on command */ case CU_SPACEF: /* space forward */ do { mta_wc = (mta_wc + 1) & DMASK; /* incr wc */ - if (st = sim_tape_sprecf (uptr, &tbc)) { /* space rec fwd, err? */ + if ((st = sim_tape_sprecf (uptr, &tbc))) { /* space rec fwd, err? */ r = mta_map_err (uptr, st); /* map error */ break; } @@ -447,7 +447,7 @@ else switch (c) { /* case on command */ case CU_SPACER: /* space reverse */ do { mta_wc = (mta_wc + 1) & DMASK; /* incr wc */ - if (st = sim_tape_sprecr (uptr, &tbc)) { /* space rec rev, err? */ + if ((st = sim_tape_sprecr (uptr, &tbc))) { /* space rec rev, err? */ r = mta_map_err (uptr, st); /* map error */ break; } @@ -493,10 +493,10 @@ if ((uptr->flags & UNIT_ATT) == 0) /* offline? */ change = (uptr->USTAT ^ newsta) & STA_MON; /* changes? */ uptr->USTAT = newsta & STA_DYN; /* update status */ if (change) { -/* if (mta_ep) { /* if polling */ -/* u = uptr - mta_dev.units; /* unit num */ -/* mta_sta = (mta_sta & ~STA_UNIT) | (u << STA_V_UNIT); -/* set polling interupt... +/* if (mta_ep) { *//* if polling */ +/* u = uptr - mta_dev.units; *//* unit num */ +/* mta_sta = (mta_sta & ~STA_UNIT) | (u << STA_V_UNIT); */ +/* set polling interupt... */ /* } */ mta_sta = mta_sta | STA_CHG; /* flag change */ } diff --git a/NOVA/nova_tt1.c b/NOVA/nova_tt1.c index 0b495651..cffad5e9 100644 --- a/NOVA/nova_tt1.c +++ b/NOVA/nova_tt1.c @@ -184,7 +184,7 @@ int32 temp, newln; if (tt1_ldsc.conn) { /* connected? */ tmxr_poll_rx (&tt_desc); /* poll for input */ - if (temp = tmxr_getc_ln (&tt1_ldsc)) { /* get char */ + if ((temp = tmxr_getc_ln (&tt1_ldsc))) { /* get char */ uptr->buf = temp & 0177; if ((uptr->flags & UNIT_DASHER) && (uptr->buf == '\r')) diff --git a/PDP1/pdp1_cpu.c b/PDP1/pdp1_cpu.c index 7be63f73..d52a6a31 100644 --- a/PDP1/pdp1_cpu.c +++ b/PDP1/pdp1_cpu.c @@ -546,7 +546,7 @@ reason = 0; while (reason == 0) { /* loop until halted */ if (sim_interval <= 0) { /* check clock queue */ - if (reason = sim_process_event ()) + if ((reason = sim_process_event ())) break; sbs_lvl = sbs_eval (); /* eval sbs system */ } @@ -610,25 +610,25 @@ while (reason == 0) { /* loop until halted */ /* Logical, load, store instructions */ case 001: /* AND */ - if (reason = Ea (IR)) /* MA <- eff addr */ + if ((reason = Ea (IR))) /* MA <- eff addr */ break; - if (reason = Read ()) /* MB <- data */ + if ((reason = Read ())) /* MB <- data */ break; AC = AC & MB; break; case 002: /* IOR */ - if (reason = Ea (IR)) /* MA <- eff addr */ + if ((reason = Ea (IR))) /* MA <- eff addr */ break; - if (reason = Read ()) /* MB <- data */ + if ((reason = Read ())) /* MB <- data */ break; AC = AC | MB; break; case 003: /* XOR */ - if (reason = Ea (IR)) /* MA <- eff addr */ + if ((reason = Ea (IR))) /* MA <- eff addr */ break; - if (reason = Read ()) /* MB <- data */ + if ((reason = Read ())) /* MB <- data */ break; AC = AC ^ MB; break; @@ -638,9 +638,9 @@ while (reason == 0) { /* loop until halted */ reason = STOP_XCT; break; } - if (reason = Ea (IR)) /* MA <- eff addr */ + if ((reason = Ea (IR))) /* MA <- eff addr */ break; - if (reason = Read ()) /* MB <- data */ + if ((reason = Read ())) /* MB <- data */ break; xct_count = xct_count + 1; /* count XCT's */ IR = MB; /* get instruction */ @@ -648,9 +648,9 @@ while (reason == 0) { /* loop until halted */ case 005: /* LCH */ if (cpu_unit.flags & UNIT_1D) { /* PDP-1D? */ - if (reason = Ea_ch (IR, &byno)) /* MA <- eff addr */ + if ((reason = Ea_ch (IR, &byno))) /* MA <- eff addr */ break; - if (reason = Read ()) /* MB <- data */ + if ((reason = Read ())) /* MB <- data */ break; AC = (MB << byt_shf[byno]) & 0770000; /* extract byte */ } @@ -659,9 +659,9 @@ while (reason == 0) { /* loop until halted */ case 006: /* DCH */ if (cpu_unit.flags & UNIT_1D) { /* PDP-1D? */ - if (reason = Ea_ch (IR, &byno)) /* MA <- eff addr */ + if ((reason = Ea_ch (IR, &byno))) /* MA <- eff addr */ break; - if (reason = Read ()) /* MB <- data */ + if ((reason = Read ())) /* MB <- data */ break; MB = (MB & ~(0770000 >> byt_shf[byno])) | /* insert byte */ ((AC & 0770000) >> byt_shf[byno]); @@ -683,55 +683,55 @@ while (reason == 0) { /* loop until halted */ break; case 010: /* LAC */ - if (reason = Ea (IR)) /* MA <- eff addr */ + if ((reason = Ea (IR))) /* MA <- eff addr */ break; - if (reason = Read ()) /* MB <- data */ + if ((reason = Read ())) /* MB <- data */ break; AC = MB; break; case 011: /* LIO */ - if (reason = Ea (IR)) /* MA <- eff addr */ + if ((reason = Ea (IR))) /* MA <- eff addr */ break; - if (reason = Read ()) /* MB <- data */ + if ((reason = Read ())) /* MB <- data */ break; IO = MB; break; case 012: /* DAC */ - if (reason = Ea (IR)) /* MA <- eff addr */ + if ((reason = Ea (IR))) /* MA <- eff addr */ break; MB = AC; reason = Write (); break; case 013: /* DAP */ - if (reason = Ea (IR)) /* MA <- eff addr */ + if ((reason = Ea (IR))) /* MA <- eff addr */ break; - if (reason = Read ()) /* MB <- data */ + if ((reason = Read ())) /* MB <- data */ break; MB = (AC & DAMASK) | (MB & ~DAMASK); reason = Write (); break; case 014: /* DIP */ - if (reason = Ea (IR)) /* MA <- eff addr */ + if ((reason = Ea (IR))) /* MA <- eff addr */ break; - if (reason = Read ()) /* MB <- data */ + if ((reason = Read ())) /* MB <- data */ break; MB = (AC & ~DAMASK) | (MB & DAMASK); reason = Write (); break; case 015: /* DIO */ - if (reason = Ea (IR)) /* MA <- eff addr */ + if ((reason = Ea (IR))) /* MA <- eff addr */ break; MB = IO; reason = Write (); break; case 016: /* DZM */ - if (reason = Ea (IR)) /* MA <- eff addr */ + if ((reason = Ea (IR))) /* MA <- eff addr */ break; MB = 0; reason = Write (); @@ -755,9 +755,9 @@ while (reason == 0) { /* loop until halted */ case 017: /* TAD */ if (cpu_unit.flags & UNIT_1D) { /* PDP-1D? */ - if (reason = Ea (IR)) /* MA <- eff addr */ + if ((reason = Ea (IR))) /* MA <- eff addr */ break; - if (reason = Read ()) /* MB <- data */ + if ((reason = Read ())) /* MB <- data */ break; AC = AC + MB + ((PF & PF_L)? 1: 0); /* AC + opnd + L */ if (AC > DMASK) /* carry? set L */ @@ -769,9 +769,9 @@ while (reason == 0) { /* loop until halted */ break; case 020: /* ADD */ - if (reason = Ea (IR)) /* MA <- eff addr */ + if ((reason = Ea (IR))) /* MA <- eff addr */ break; - if (reason = Read ()) /* MB <- data */ + if ((reason = Read ())) /* MB <- data */ break; t = AC; AC = AC + MB; @@ -784,9 +784,9 @@ while (reason == 0) { /* loop until halted */ break; case 021: /* SUB */ - if (reason = Ea (IR)) /* MA <- eff addr */ + if ((reason = Ea (IR))) /* MA <- eff addr */ break; - if (reason = Read ()) /* MB <- data */ + if ((reason = Read ())) /* MB <- data */ break; t = AC ^ DMASK; /* complement AC */ AC = t + MB; /* -AC + MB */ @@ -798,9 +798,9 @@ while (reason == 0) { /* loop until halted */ break; case 022: /* IDX */ - if (reason = Ea (IR)) /* MA <- eff addr */ + if ((reason = Ea (IR))) /* MA <- eff addr */ break; - if (reason = Read ()) /* MB <- data */ + if ((reason = Read ())) /* MB <- data */ break; AC = MB + 1; if (AC >= DMASK) @@ -810,9 +810,9 @@ while (reason == 0) { /* loop until halted */ break; case 023: /* ISP */ - if (reason = Ea (IR)) /* MA <- eff addr */ + if ((reason = Ea (IR))) /* MA <- eff addr */ break; - if (reason = Read ()) /* MB <- data */ + if ((reason = Read ())) /* MB <- data */ break; AC = MB + 1; if (AC >= DMASK) @@ -824,18 +824,18 @@ while (reason == 0) { /* loop until halted */ break; case 024: /* SAD */ - if (reason = Ea (IR)) /* MA <- eff addr */ + if ((reason = Ea (IR))) /* MA <- eff addr */ break; - if (reason = Read ()) /* MB <- data */ + if ((reason = Read ())) /* MB <- data */ break; if (AC != MB) PC = INCR_ADDR (PC); break; case 025: /* SAS */ - if (reason = Ea (IR)) /* MA <- eff addr */ + if ((reason = Ea (IR))) /* MA <- eff addr */ break; - if (reason = Read ()) /* MB <- data */ + if ((reason = Read ())) /* MB <- data */ break; if (AC == MB) PC = INCR_ADDR (PC); @@ -863,7 +863,7 @@ while (reason == 0) { /* loop until halted */ hst[hst_p].ea = PC; } else { /* normal JMP */ - if (reason = Ea (IR)) /* MA <- eff addr */ + if ((reason = Ea (IR))) /* MA <- eff addr */ break; PCQ_ENTRY; PC = MA; @@ -871,7 +871,7 @@ while (reason == 0) { /* loop until halted */ break; case 031: /* JSP */ - if (reason = Ea (IR)) /* MA <- eff addr */ + if ((reason = Ea (IR))) /* MA <- eff addr */ break; AC = EPC_WORD; PCQ_ENTRY; @@ -889,9 +889,9 @@ while (reason == 0) { /* loop until halted */ */ case 026: /* MUL */ - if (reason = Ea (IR)) /* MA <- eff addr */ + if ((reason = Ea (IR))) /* MA <- eff addr */ break; - if (reason = Read ()) /* MB <- data */ + if ((reason = Read ())) /* MB <- data */ break; if (cpu_unit.flags & UNIT_MDV) { /* hardware? */ sign = AC ^ MB; /* result sign */ @@ -919,9 +919,9 @@ while (reason == 0) { /* loop until halted */ break; case 027: /* DIV */ - if (reason = Ea (IR)) /* MA <- eff addr */ + if ((reason = Ea (IR))) /* MA <- eff addr */ break; - if (reason = Read ()) /* MB <- data */ + if ((reason = Read ())) /* MB <- data */ break; if (cpu_unit.flags & UNIT_MDV) { /* hardware */ sign = AC ^ MB; /* result sign */ @@ -1362,13 +1362,13 @@ t_stat r; MA = (PC & EPCMASK) | (IR & DAMASK); /* direct address */ if (IR & IA) { /* indirect addr? */ if (extm) { /* extend? */ - if (r = Read ()) /* read; err? */ + if ((r = Read ())) /* read; err? */ return r; MA = MB & AMASK; /* one level */ } else { /* multi-level */ for (i = 0; i < ind_max; i++) { /* count indirects */ - if (r = Read ()) /* get ind word */ + if ((r = Read ())) /* get ind word */ return r; MA = (PC & EPCMASK) | (MB & DAMASK); if ((MB & IA) == 0) @@ -1392,12 +1392,12 @@ t_stat r; MA = (PC & EPCMASK) | (IR & DAMASK); /* direct address */ if (extm) { /* extend? */ - if (r = Read ()) /* read; err? */ + if ((r = Read ())) /* read; err? */ return r; } else { /* multi-level */ for (i = 0; i < ind_max; i++) { /* count indirects */ - if (r = Read ()) /* get ind word */ + if ((r = Read ())) /* get ind word */ return r; if ((MB & IA) == 0) break; diff --git a/PDP1/pdp1_dcs.c b/PDP1/pdp1_dcs.c index dd54ce18..93c9eefc 100644 --- a/PDP1/pdp1_dcs.c +++ b/PDP1/pdp1_dcs.c @@ -251,7 +251,7 @@ if (ln >= 0) { /* got one? */ tmxr_poll_rx (&dcs_desc); /* poll for input */ for (ln = 0; ln < DCS_NUMLIN; ln++) { /* loop thru lines */ if (dcs_ldsc[ln].conn) { /* connected? */ - if (c = tmxr_getc_ln (&dcs_ldsc[ln])) { /* get char */ + if ((c = tmxr_getc_ln (&dcs_ldsc[ln]))) { /* get char */ if (c & SCPE_BREAK) /* break? */ c = 0; else c = sim_tt_inpcvt (c, TT_GET_MODE (dcsl_unit[ln].flags)|TTUF_KSR); diff --git a/PDP10/pdp10_cpu.c b/PDP10/pdp10_cpu.c index d5c9fc10..37cf218b 100644 --- a/PDP10/pdp10_cpu.c +++ b/PDP10/pdp10_cpu.c @@ -705,7 +705,7 @@ pager_tc = FALSE; /* not in trap cycle */ pflgs = 0; /* not in PXCT */ xct_cnt = 0; /* count XCT's */ if (sim_interval <= 0) { /* check clock queue */ - if (i = sim_process_event ()) /* error? stop sim */ + if ((i = sim_process_event ())) /* error? stop sim */ ABORT (i); pi_eval (); /* eval pi system */ } @@ -719,7 +719,7 @@ if (sim_interval <= 0) { /* check clock queue */ if (qintr) { int32 vec, uba; pager_pi = TRUE; /* flag in pi seq */ - if (vec = pi_ub_vec (qintr, &uba)) { /* Unibus interrupt? */ + if ((vec = pi_ub_vec (qintr, &uba))) { /* Unibus interrupt? */ mb = ReadP (epta + EPT_UBIT + uba); /* get dispatch table */ if (mb == 0) /* invalid? stop */ ABORT (STOP_ZERINT); @@ -865,8 +865,8 @@ case 0037: Write (040, UUOWORD, MM_CUR); /* store op, ac, ea */ /* Floating point, bytes, multiple precision (0100 - 0177) */ -/* case 0100: MUUO /* UJEN */ -/* case 0101: MUUO /* unassigned */ +/* case 0100: MUUO *//* UJEN */ +/* case 0101: MUUO *//* unassigned */ case 0102: if (Q_ITS && !TSTF (F_USR)) { /* GFAD (KL), XCTRI (ITS) */ inst = Read (ea, MM_OPND); pflgs = pflgs | ac; @@ -879,10 +879,10 @@ case 0103: if (Q_ITS && !TSTF (F_USR)) { /* GFSB (KL), XCTR (ITS) goto XCT; } goto MUUO; -/* case 0104: MUUO /* JSYS (T20) */ +/* case 0104: MUUO *//* JSYS (T20) */ case 0105: AC(ac) = adjsp (AC(ac), ea); break; /* ADJSP */ -/* case 0106: MUUO /* GFMP (KL)*/ -/* case 0107: MUUO /* GFDV (KL) */ +/* case 0106: MUUO *//* GFMP (KL)*/ +/* case 0107: MUUO *//* GFDV (KL) */ case 0110: RD2; dfad (ac, rs, 0); break; /* DFAD */ case 0111: RD2; dfad (ac, rs, 1); break; /* DFSB */ case 0112: RD2; dfmp (ac, rs); break; /* DFMP */ @@ -909,8 +909,8 @@ case 0124: G2AC; WR2; break; /* DMOVEM */ case 0125: G2AC; DMOVN (rs); WR2; DMOVNF; break; /* DMOVNM */ case 0126: RD; fix (ac, mb, 1); break; /* FIXR */ case 0127: RD; AC(ac) = fltr (mb); break; /* FLTR */ -/* case 0130: MUUO /* UFA */ -/* case 0131: MUUO /* DFN */ +/* case 0130: MUUO *//* UFA */ +/* case 0131: MUUO *//* DFN */ case 0132: AC(ac) = fsc (AC(ac), ea); break; /* FSC */ case 0133: if (!ac) /* IBP */ ibp (ea, pflgs); @@ -920,7 +920,7 @@ case 0135: LDB; break; /* LDB */ case 0136: CIBP; DPB; CLRF (F_FPD); break; /* IDBP */ case 0137: DPB; break; /* DPB */ case 0140: RD; AC(ac) = FAD (mb); break; /* FAD */ -/* case 0141: MUUO /* FADL */ +/* case 0141: MUUO *//* FADL */ case 0142: RM; mb = FAD (mb); WR; break; /* FADM */ case 0143: RM; AC(ac) = FAD (mb); WRAC; break; /* FADB */ case 0144: RD; AC(ac) = FADR (mb); break; /* FADR */ @@ -928,7 +928,7 @@ case 0145: AC(ac) = FADR (IMS); break; /* FADRI */ case 0146: RM; mb = FADR (mb); WR; break; /* FADRM */ case 0147: RM; AC(ac) = FADR (mb); WRAC; break; /* FADRB */ case 0150: RD; AC(ac) = FSB (mb); break; /* FSB */ -/* case 0151: MUUO /* FSBL */ +/* case 0151: MUUO *//* FSBL */ case 0152: RM; mb = FSB (mb); WR; break; /* FSBM */ case 0153: RM; AC(ac) = FSB (mb); WRAC; break; /* FSBB */ case 0154: RD; AC(ac) = FSBR (mb); break; /* FSBR */ @@ -936,7 +936,7 @@ case 0155: AC(ac) = FSBR (IMS); break; /* FSBRI */ case 0156: RM; mb = FSBR (mb); WR; break; /* FSBRM */ case 0157: RM; AC(ac) = FSBR (mb); WRAC; break; /* FSBRB */ case 0160: RD; AC(ac) = FMP (mb); break; /* FMP */ -/* case 0161: MUUO /* FMPL */ +/* case 0161: MUUO *//* FMPL */ case 0162: RM; mb = FMP (mb); WR; break; /* FMPM */ case 0163: RM; AC(ac) = FMP (mb); WRAC; break; /* FMPB */ case 0164: RD; AC(ac) = FMPR (mb); break; /* FMPR */ @@ -944,7 +944,7 @@ case 0165: AC(ac) = FMPR (IMS); break; /* FMPRI */ case 0166: RM; mb = FMPR (mb); WR; break; /* FMPRM */ case 0167: RM; AC(ac) = FMPR (mb); WRAC; break; /* FMPRB */ case 0170: RD; if (FDV (mb)) S1AC; break; /* FDV */ -/* case 0171: MUUO /* FDVL */ +/* case 0171: MUUO *//* FDVL */ case 0172: RM; if (FDV (mb)) WR1; break; /* FDVM */ case 0173: RM; if (FDV (mb)) { S1AC; WRAC; } break; /* FDVB */ case 0174: RD; if (FDVR (mb)) S1AC; break; /* FDVR */ @@ -1008,7 +1008,7 @@ case 0250: RM; WRAC; AC(ac) = mb; break; /* EXCH */ case 0251: blt (ac, ea, pflgs); break; /* BLT */ case 0252: AOBAC; if (TGE (AC(ac))) JUMP (ea); break; /* AOBJP */ case 0253: AOBAC; if (TL (AC(ac))) JUMP (ea); break; /* AOBJN */ -/* case 0254: /* shown later /* JRST */ +/* case 0254: *//* shown later *//* JRST */ case 0255: if (flags & (ac << 14)) { /* JFCL */ JUMP (ea); CLRF (ac << 14); @@ -2019,7 +2019,7 @@ int32 test_int (void) int32 t; if (sim_interval <= 0) { /* check queue */ - if (t = sim_process_event ()) /* IO event? */ + if ((t = sim_process_event ())) /* IO event? */ return t; if (pi_eval ()) /* interrupt? */ return (INTERRUPT); diff --git a/PDP10/pdp10_defs.h b/PDP10/pdp10_defs.h index a6eea9cb..d076dbd9 100644 --- a/PDP10/pdp10_defs.h +++ b/PDP10/pdp10_defs.h @@ -587,9 +587,9 @@ typedef t_int64 d10; /* PDP-10 data (36b) */ /* Unibus I/O constants */ #define READ 0 /* PDP11 compatible */ -/* #define READC 1 /* console read */ +/* #define READC 1 *//* console read */ #define WRITE 2 -/* #define WRITEC 3 /* console write */ +/* #define WRITEC 3 *//* console write */ #define WRITEB 4 #define IO_V_UBA 18 /* UBA in I/O addr */ #define IO_N_UBA 16 /* max num of UBA's */ diff --git a/PDP10/pdp10_ksio.c b/PDP10/pdp10_ksio.c index b37e8039..e71f773c 100644 --- a/PDP10/pdp10_ksio.c +++ b/PDP10/pdp10_ksio.c @@ -401,7 +401,7 @@ uint32 pa = (uint32) ea; int32 i, n, val; DIB *dibp; -for (i = 0; dibp = dib_tab[i]; i++ ) { +for (i = 0; (dibp = dib_tab[i]); i++ ) { if ((pa >= dibp->ba) && (pa < (dibp->ba + dibp->lnt))) { dibp->rd (&val, pa, READ); @@ -418,7 +418,7 @@ uint32 pa = (uint32) ea; int32 i, n; DIB *dibp; -for (i = 0; dibp = dib_tab[i]; i++ ) { +for (i = 0; (dibp = dib_tab[i]); i++ ) { if ((pa >= dibp->ba) && (pa < (dibp->ba + dibp->lnt))) { dibp->wr ((int32) val, pa, mode); diff --git a/PDP10/pdp10_lp20.c b/PDP10/pdp10_lp20.c index 64f2ccba..fec1cda6 100644 --- a/PDP10/pdp10_lp20.c +++ b/PDP10/pdp10_lp20.c @@ -58,10 +58,10 @@ #define TX_DMASK 07777 #define TX_V_FL 8 /* flags */ #define TX_M_FL 017 -/* define TX_INTR 04000 /* interrupt */ +/* define TX_INTR 04000 *//* interrupt */ #define TX_DELH 02000 /* delimiter */ -/* define TX_XLAT 01000 /* translate */ -/* define TX_DVFU 00400 /* DAVFU */ +/* define TX_XLAT 01000 *//* translate */ +/* define TX_DVFU 00400 *//* DAVFU */ #define TX_SLEW 00020 /* chan vs slew */ #define TX_VMASK 00017 /* spacing mask */ #define TX_CHR 0 /* states: pr char */ @@ -563,7 +563,7 @@ lp20_unit.pos = ftell (lp20_unit.fileref); /* print 'n' newlines */ if (dvuadv) /* update DAVFU ptr */ dvptr = (dvptr + cnt) % dvlnt; if (davfu[dvptr] & (1 << DV_TOF)) { /* at top of form? */ - if (lppagc = (lppagc - 1) & PAGC_MASK) { /* decr page cntr */ + if ((lppagc = (lppagc - 1) & PAGC_MASK)) { /* decr page cntr */ lpcsa = lpcsa & ~CSA_PZRO; /* update status */ return TRUE; } @@ -592,7 +592,7 @@ for (i = 0; i < dvlnt; i++) { /* search DAVFU */ lp20_adv (1, FALSE); fputc ('\f', lp20_unit.fileref); /* print form feed */ lp20_unit.pos = ftell (lp20_unit.fileref); - if (lppagc = (lppagc - 1) & PAGC_MASK) { /* decr page cntr */ + if ((lppagc = (lppagc - 1) & PAGC_MASK)) { /* decr page cntr */ lpcsa = lpcsa & ~CSA_PZRO; /* update status */ return TRUE; } diff --git a/PDP10/pdp10_mdfp.c b/PDP10/pdp10_mdfp.c index 2aab8688..bf986e9d 100644 --- a/PDP10/pdp10_mdfp.c +++ b/PDP10/pdp10_mdfp.c @@ -493,7 +493,7 @@ if (a.fhi >= 2 * b.fhi) { /* will divide work? */ SETF (F_AOV | F_DCK | F_FOV | F_T1); return FALSE; } -if (savhi = a.fhi) { /* dvd = 0? quo = 0 */ +if ((savhi = a.fhi)) { /* dvd = 0? quo = 0 */ a.sign = a.sign ^ b.sign; /* result sign */ a.exp = a.exp - b.exp + FP_BIAS + 1; /* result exponent */ a.fhi = a.fhi / (b.fhi >> (FP_N_FHI + 1)); /* do divide */ diff --git a/PDP10/pdp10_rp.c b/PDP10/pdp10_rp.c index ad55f313..a5997728 100644 --- a/PDP10/pdp10_rp.c +++ b/PDP10/pdp10_rp.c @@ -951,7 +951,7 @@ switch (uptr->FUNC) { /* case on function */ if ((rpcs2 & CS2_UAI) == 0) ba = ba + 4; } - if (fc10 = twc10 & (RP_NUMWD - 1)) { /* fill? */ + if ((fc10 = twc10 & (RP_NUMWD - 1))) { /* fill? */ fc10 = RP_NUMWD - fc10; for (i = 0; i < fc10; i++) dbuf[twc10 + i] = 0; diff --git a/PDP10/pdp10_sys.c b/PDP10/pdp10_sys.c index 061f0e40..24ec2d48 100644 --- a/PDP10/pdp10_sys.c +++ b/PDP10/pdp10_sys.c @@ -118,7 +118,7 @@ const char *sim_stop_messages[] = { #define EXE_DIR 01776 /* EXE directory */ #define EXE_VEC 01775 /* EXE entry vec */ #define EXE_PDV 01774 /* EXE ignored */ -#define EXE_END 01777 /* EXE end +#define EXE_END 01777 /* EXE end */ /* RIM10 loader diff --git a/PDP10/pdp10_tu.c b/PDP10/pdp10_tu.c index 0e73ec13..6be277b8 100644 --- a/PDP10/pdp10_tu.c +++ b/PDP10/pdp10_tu.c @@ -833,7 +833,7 @@ switch (fnc) { /* case on function */ case FNC_SPACEF: /* space forward */ do { tufc = (tufc + 1) & 0177777; /* incr fc */ - if (st = sim_tape_sprecf (uptr, &tbc)) { /* space rec fwd, err? */ + if ((st = sim_tape_sprecf (uptr, &tbc))) { /* space rec fwd, err? */ r = tu_map_err (uptr, st, 0); /* map error */ break; } @@ -847,7 +847,7 @@ switch (fnc) { /* case on function */ case FNC_SPACER: /* space reverse */ do { tufc = (tufc + 1) & 0177777; /* incr wc */ - if (st = sim_tape_sprecr (uptr, &tbc)) { /* space rec rev, err? */ + if ((st = sim_tape_sprecr (uptr, &tbc))) { /* space rec rev, err? */ r = tu_map_err (uptr, st, 0); /* map error */ break; } @@ -859,7 +859,7 @@ switch (fnc) { /* case on function */ break; case FNC_WREOF: /* write end of file */ - if (st = sim_tape_wrtmk (uptr)) /* write tmk, err? */ + if ((st = sim_tape_wrtmk (uptr))) /* write tmk, err? */ r = tu_map_err (uptr, st, 0); /* map error */ tufs = tufs | FS_ATA; break; @@ -889,7 +889,7 @@ switch (fnc) { /* case on function */ if ((uptr->UDENS == TC_1600) && sim_tape_bot (uptr)) tufs = tufs | FS_ID; /* PE BOT? ID burst */ TXFR (ba, wc, 0); /* validate transfer */ - if (st = sim_tape_rdrecf (uptr, xbuf, &tbc, MT_MAXFR)) { /* read fwd */ + if ((st = sim_tape_rdrecf (uptr, xbuf, &tbc, MT_MAXFR))) {/* read fwd */ if (st == MTSE_TMK) /* TMK also sets FCE */ set_tuer (ER_FCE); r = tu_map_err (uptr, st, 1); /* map error */ @@ -936,7 +936,7 @@ switch (fnc) { /* case on function */ } /* end for */ if (j < fc) /* short record? */ fc = j; - if (st = sim_tape_wrrecf (uptr, xbuf, fc)) /* write rec, err? */ + if ((st = sim_tape_wrrecf (uptr, xbuf, fc))) /* write rec, err? */ r = tu_map_err (uptr, st, 1); /* map error */ else { tufc = (tufc + fc) & 0177777; @@ -951,7 +951,7 @@ switch (fnc) { /* case on function */ case FNC_WCHKR: /* wcheck = read */ tufc = 0; /* clear frame count */ TXFR (ba, wc, 1); /* validate xfer rev */ - if (st = sim_tape_rdrecr (uptr, xbuf + 4, &tbc, MT_MAXFR)) { /* read rev */ + if ((st = sim_tape_rdrecr (uptr, xbuf + 4, &tbc, MT_MAXFR))) {/* read rev */ if (st == MTSE_TMK) /* TMK also sets FCE */ set_tuer (ER_FCE); r = tu_map_err (uptr, st, 1); /* map error */ diff --git a/PDP11/pdp11_cis.c b/PDP11/pdp11_cis.c index 24dd0168..9f78f1bd 100644 --- a/PDP11/pdp11_cis.c +++ b/PDP11/pdp11_cis.c @@ -1134,7 +1134,7 @@ switch (op) { /* case on opcode */ result = (A2ADR << 16) | A2LNT; /* op in VAX format */ CVTLx: dst = Dstr0; /* clear result */ - if (dst.sign = GET_SIGN_L (result)) + if ((dst.sign = GET_SIGN_L (result))) result = (~result + 1) & 0xFFFFFFFF; for (i = 1; (i < (DSTRLNT * 8)) && result; i++) { digit = result % 10; @@ -1267,7 +1267,7 @@ for (i = 0; i < DSTRLNT; i++) { /* loop thru value */ mask = 0xFFFFFFFF; if (dst->val[i] & mask) /* test for ovflo */ V = 1; - if (dst->val[i] = dst->val[i] & ~mask) /* test nz */ + if ((dst->val[i] = dst->val[i] & ~mask)) /* test nz */ Z = 0; } dst->sign = dst->sign & ~unsignedtab[type] & ~(Z & ~V); @@ -1523,7 +1523,7 @@ uint32 NibbleRshift (DSTR *dsrc, int32 sc, uint32 cin) { int32 i, s, nc; -if (s = sc * 4) { +if ((s = sc * 4)) { for (i = DSTRMAX; i >= 0; i--) { nc = (dsrc->val[i] << (32 - s)) & 0xFFFFFFFF; dsrc->val[i] = ((dsrc->val[i] >> s) | @@ -1548,7 +1548,7 @@ int32 i, s; uint32 nc, cin; cin = 0; -if (s = sc * 4) { +if ((s = sc * 4)) { for (i = 0; i < DSTRLNT; i++) { nc = dsrc->val[i] >> (32 - s); dsrc->val[i] = ((dsrc->val[i] << s) | cin) & 0xFFFFFFFF; diff --git a/PDP11/pdp11_cpu.c b/PDP11/pdp11_cpu.c index 0ee91143..7f8eac70 100644 --- a/PDP11/pdp11_cpu.c +++ b/PDP11/pdp11_cpu.c @@ -25,6 +25,7 @@ cpu PDP-11 CPU + 29-Apr-12 RMS Fixed compiler warning (Mark Pizzolato) 19-Mar-12 RMS Fixed declaration of sim_switches (Mark Pizzolato) 29-Dec-08 RMS Fixed failure to clear cpu_bme on RESET (Walter Mueller) 22-Apr-08 RMS Fixed MMR0 treatment in RESET (Walter Mueller) @@ -731,7 +732,7 @@ while (reason == 0) { if (trap_req) { /* check traps, ints */ trapea = 0; /* assume srch fails */ - if (t = trap_req & TRAP_ALL) { /* if a trap */ + if ((t = trap_req & TRAP_ALL)) { /* if a trap */ for (trapnum = 0; trapnum < TRAP_V_MAX; trapnum++) { if ((t >> trapnum) & 1) { /* trap set? */ trapea = trap_vec[trapnum]; /* get vec, clr */ @@ -1292,7 +1293,7 @@ while (reason == 0) { break; case 070: /* CSM */ - if (CPUT (HAS_CSM) && (MMR3 & MMR3_CSM) || (cm != MD_KER)) { + if ((CPUT (HAS_CSM) && (MMR3 & MMR3_CSM)) || (cm != MD_KER)) { dst = dstreg? R[dstspec]: ReadW (GeteaW (dstspec)); PSW = get_PSW () & ~PSW_CC; /* PSW, cc = 0 */ STACKFILE[cm] = SP; diff --git a/PDP11/pdp11_cpumod.c b/PDP11/pdp11_cpumod.c index 80a52dc4..faf5a2b2 100644 --- a/PDP11/pdp11_cpumod.c +++ b/PDP11/pdp11_cpumod.c @@ -1075,7 +1075,7 @@ t_stat r; for (i = 0; cnf_tab[i].dib != NULL; i++) { /* loop thru config tab */ if (((cnf_tab[i].cpum == 0) || (cpu_type & cnf_tab[i].cpum)) && ((cnf_tab[i].optm == 0) || (cpu_opt & cnf_tab[i].optm))) { - if (r = build_ubus_tab (&cpu_dev, cnf_tab[i].dib)) /* add to dispatch tab */ + if ((r = build_ubus_tab (&cpu_dev, cnf_tab[i].dib)))/* add to dispatch tab */ return r; } } diff --git a/PDP11/pdp11_dl.c b/PDP11/pdp11_dl.c index 2caf6832..ec8cc9ab 100644 --- a/PDP11/pdp11_dl.c +++ b/PDP11/pdp11_dl.c @@ -346,7 +346,7 @@ if (ln >= 0) { /* got one? rcv enb */ tmxr_poll_rx (&dlx_desc); /* poll for input */ for (ln = 0; ln < DLX_LINES; ln++) { /* loop thru lines */ if (dlx_ldsc[ln].conn) { /* connected? */ - if (temp = tmxr_getc_ln (&dlx_ldsc[ln])) { /* get char */ + if ((temp = tmxr_getc_ln (&dlx_ldsc[ln]))) { /* get char */ if (temp & SCPE_BREAK) /* break? */ c = DLIBUF_ERR|DLIBUF_RBRK; else c = sim_tt_inpcvt (temp, TT_GET_MODE (dlo_unit[ln].flags)); diff --git a/PDP11/pdp11_dmc.c b/PDP11/pdp11_dmc.c new file mode 100644 index 00000000..7e420b83 --- /dev/null +++ b/PDP11/pdp11_dmc.c @@ -0,0 +1,2273 @@ +/* pdp11_dmc.c: DMC11 Emulation + ------------------------------------------------------------------------------ + + Copyright (c) 2011, Robert M. A. Jarratt + + 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 + THE AUTHOR 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 the author shall not be + used in advertising or otherwise to promote the sale, use or other dealings + in this Software without prior written authorization from the author. + + ------------------------------------------------------------------------------ + + +I/O is done through sockets so that the remote system can be on the same host machine. The device starts polling for +incoming connections when it receives its first read buffer. The device opens the connection for writing when it receives +the first write buffer. + +Transmit and receive buffers are added to their respective queues and the polling method in dmc_svc() checks for input +and sends any output. + +On the wire the format is a 2-byte block length followed by that number of bytes. Some of the diagnostics expect to receive +the same number of bytes in a buffer as were sent by the other end. Using sockets without a block length can cause the +buffers to coalesce and then the buffer lengths in the diagnostics fail. The block length is always sent in network byte +order. + +Tested with two diagnostics. To run the diagnostics set the default directory to SYS$MAINTENANCE, run ESSAA and then +configure it for the DMC-11 with the following commands: + +The above commands can be put into a COM file in SYS$MAINTENANCE (works on VMS 3.0 but not 4.6, not sure why). + +ATT DW780 SBI DW0 3 4 +ATT DMC11 DW0 XMA0 760070 300 5 +SELECT XMA0 +(if putting these into a COM file to be executed by ESSAA add a "DS> " prefix) + + +The first is EVDCA which takes no parameters. Invoke it with the command R EVDCA. This diagnostic uses the DMC-11 loopback +functionality and the transmit port is not used when LU LOOP is enabled. Seems to work only under later versions of VMS +such as 4.6, does not work on 3.0. + +The second is EVDMC, invoke this with the command R EVDMC. For this I used the following commands inside the diagnostic: + +RUN MODE=TRAN on one machine +RUN MODE=REC on the other (unless the one instance is configured with the ports looping back). + +You can add /PASS=n to the above commands to get the diagnostic to send and receive more buffers. + +The other test was to configure DECnet on VMS 4.6 and do SET HOST. +*/ + +// TODO: Copyright notices +// TODO: Compile on other platforms +// TODO: Avoid need for manifests and newest runtime, compile with 2003 +// TODO: Investigate line number and set parameters at the unit level (?) +// TODO: Multipoint. In this case perhaps don't need transmit port, allow all lines to connect to port on control node. +// TODO: Show active connections like DZ does, for multipoint. +// TODO: Test MOP. +// TODO: Implement actual DDCMP protocol and run over UDP. +// TODO: Allow NCP SHOW COUNTERS to work (think this is the base address thing) + +#include +#include + +#include "pdp11_dmc.h" + +#define POLL 1000 +#define TRACE_BYTES_PER_LINE 16 + +struct csrs { + uint16 sel0; + uint16 sel2; + uint16 sel4; + uint16 sel6; +}; + +typedef struct csrs CSRS; + +typedef enum +{ + Initialised, /* after MASTER CLEAR */ + Running /* after any transmit or receive buffer has been supplied */ +} ControllerState; + +typedef enum +{ + Idle, + InputTransfer, + OutputTransfer +} TransferState; + +typedef enum +{ + Available, /* when empty or partially filled on read */ + ContainsData, + TransferInProgress +} BufferState; + +typedef struct +{ + int isPrimary; + SOCKET socket; // socket used bidirectionally + int receive_readable; + char *receive_port; + int transmit_writeable; + char transmit_host[80]; + int transmit_is_loopback; /* if true the transmit socket is the loopback to the receive */ + int speed; /* bits per second in each direction, 0 for no limit */ + int last_second; + int bytes_sent_in_last_second; + int bytes_received_in_last_second; + time_t last_connect_attempt; +} LINE; + +/* A partially filled buffer (during a read from the socket) will have block_len_bytes_read = 1 or actual_bytes_transferred < actual_block_len */ +typedef struct buffer +{ + uint32 address; /* unibus address of the buffer */ + uint16 count; /* size of the buffer passed to the device by the driver */ + uint16 actual_block_len; /* actual length of the received block */ + uint8 *transfer_buffer; /* the buffer into which data is received or from which it is transmitted*/ + int block_len_bytes_read; /* the number of bytes read so far for the block length */ + int actual_bytes_transferred; /* the number of bytes from the actual block that have been read or written so far*/ + struct buffer *next; /* next buffer in the queue */ + BufferState state; /* state of this buffer */ + int is_loopback; /* loopback was requested when this buffer was queued */ +} BUFFER; + +typedef struct +{ + char * name; + BUFFER queue[BUFFER_QUEUE_SIZE]; + int head; + int tail; + int count; + struct dmc_controller *controller; /* back pointer to the containing controller */ +} BUFFER_QUEUE; + +typedef struct +{ + int started; + clock_t start_time; + clock_t cumulative_time; +} TIMER; + +typedef struct +{ + TIMER between_polls_timer; + TIMER poll_timer; + uint32 poll_count; + +} UNIT_STATS; + +typedef enum +{ + DMC, + DMR, + DMP +} DEVTYPE; + +struct dmc_controller { + CSRS *csrs; + DEVICE *device; + ControllerState state; + TransferState transfer_state; /* current transfer state (type of transfer) */ + int transfer_type; + int transfer_in_io; // remembers IN I/O setting at start of input transfer as host changes it during transfer! + LINE *line; + BUFFER_QUEUE *receive_queue; + BUFFER_QUEUE *transmit_queue; + SOCKET master_socket; + int32 svc_poll_interval; + int32 connect_poll_interval; + DEVTYPE dev_type; + uint32 rxi; + uint32 txi; + uint32 buffers_received_from_net; + uint32 buffers_transmitted_to_net; + uint32 receive_buffer_output_transfers_completed; + uint32 transmit_buffer_output_transfers_completed; + uint32 receive_buffer_input_transfers_completed; + uint32 transmit_buffer_input_transfers_completed; +}; + +typedef struct dmc_controller CTLR; + +t_stat dmc_rd(int32* data, int32 PA, int32 access); +t_stat dmc_wr(int32 data, int32 PA, int32 access); +t_stat dmc_svc(UNIT * uptr); +t_stat dmc_reset (DEVICE * dptr); +t_stat dmc_attach (UNIT * uptr, char * cptr); +t_stat dmc_detach (UNIT * uptr); +int32 dmc_rxint (void); +int32 dmc_txint (void); +t_stat dmc_settransmit (UNIT* uptr, int32 val, char* cptr, void* desc); +t_stat dmc_showtransmit (FILE* st, UNIT* uptr, int32 val, void* desc); +t_stat dmc_setspeed (UNIT* uptr, int32 val, char* cptr, void* desc); +t_stat dmc_showspeed (FILE* st, UNIT* uptr, int32 val, void* desc); +t_stat dmc_settype (UNIT* uptr, int32 val, char* cptr, void* desc); +t_stat dmc_showtype (FILE* st, UNIT* uptr, int32 val, void* desc); +t_stat dmc_setstats (UNIT* uptr, int32 val, char* cptr, void* desc); +t_stat dmc_showstats (FILE* st, UNIT* uptr, int32 val, void* desc); +t_stat dmc_setpoll (UNIT* uptr, int32 val, char* cptr, void* desc); +t_stat dmc_showpoll (FILE* st, UNIT* uptr, int32 val, void* desc); +t_stat dmc_setconnectpoll (UNIT* uptr, int32 val, char* cptr, void* desc); +t_stat dmc_showconnectpoll (FILE* st, UNIT* uptr, int32 val, void* desc); +t_stat dmc_setlinemode (UNIT* uptr, int32 val, char* cptr, void* desc); +t_stat dmc_showlinemode (FILE* st, UNIT* uptr, int32 val, void* desc); +int dmc_is_dmc(CTLR *controller); +int dmc_is_rqi_set(CTLR *controller); +int dmc_is_rdyi_set(CTLR *controller); +int dmc_is_iei_set(CTLR *controller); +int dmc_is_ieo_set(CTLR *controller); +void dmc_process_command(CTLR *controller); +int dmc_buffer_fill_receive_buffers(CTLR *controller); +void dmc_start_transfer_receive_buffer(CTLR *controller); +int dmc_buffer_send_transmit_buffers(CTLR *controller); +void dmc_buffer_queue_init(CTLR *controller, BUFFER_QUEUE *q, char *name); +BUFFER *dmc_buffer_queue_head(BUFFER_QUEUE *q); +int dmc_buffer_queue_full(BUFFER_QUEUE *q); +void dmc_buffer_queue_get_stats(BUFFER_QUEUE *q, int *available, int *contains_data, int *transfer_in_progress); +void dmc_start_transfer_transmit_buffer(CTLR *controller); +void dmc_error_and_close_receive(CTLR *controller, char *format); +void dmc_close_receive(CTLR *controller, char *reason); +void dmc_close_transmit(CTLR *controller, char *reason); +int dmc_get_socket(CTLR *controller, int forRead); +int dmc_get_receive_socket(CTLR *controller, int forRead); +int dmc_get_transmit_socket(CTLR *controller, int is_loopback, int forRead); +void dmc_line_update_speed_stats(LINE *line); +UNIT_STATS *dmc_get_unit_stats(UNIT *uptr); +void dmc_set_unit_stats(UNIT *uptr, UNIT_STATS *stats); + +DEBTAB dmc_debug[] = { + {"TRACE", DBG_TRC}, + {"WARN", DBG_WRN}, + {"REG", DBG_REG}, + {"INFO", DBG_INF}, + {"DATA", DBG_DAT}, + {"DATASUM",DBG_DTS}, + {"SOCKET", DBG_SOK}, + {"CONNECT", DBG_CON}, + {0} +}; + +UNIT dmc_unit[] = { + { UDATA (&dmc_svc, UNIT_IDLE|UNIT_ATTABLE|UNIT_DISABLE, 0) }, + { UDATA (&dmc_svc, UNIT_IDLE|UNIT_ATTABLE|UNIT_DISABLE, 0) }, + { UDATA (&dmc_svc, UNIT_IDLE|UNIT_ATTABLE|UNIT_DISABLE, 0) }, + { UDATA (&dmc_svc, UNIT_IDLE|UNIT_ATTABLE|UNIT_DISABLE, 0) } +}; + +UNIT dmp_unit[] = { + { UDATA (&dmc_svc, UNIT_IDLE|UNIT_ATTABLE|UNIT_DISABLE, 0) } +}; + +CSRS dmc_csrs[DMC_NUMDEVICE]; + +CSRS dmp_csrs[DMP_NUMDEVICE]; + +REG dmca_reg[] = { + { HRDATA (SEL0, dmc_csrs[0].sel0, 16) }, + { HRDATA (SEL2, dmc_csrs[0].sel2, 16) }, + { HRDATA (SEL4, dmc_csrs[0].sel4, 16) }, + { HRDATA (SEL6, dmc_csrs[0].sel6, 16) }, + { GRDATA (BSEL0, dmc_csrs[0].sel0, DEV_RDX, 8, 0) }, + { GRDATA (BSEL1, dmc_csrs[0].sel0, DEV_RDX, 8, 8) }, + { GRDATA (BSEL2, dmc_csrs[0].sel2, DEV_RDX, 8, 0) }, + { GRDATA (BSEL3, dmc_csrs[0].sel2, DEV_RDX, 8, 8) }, + { GRDATA (BSEL4, dmc_csrs[0].sel4, DEV_RDX, 8, 0) }, + { GRDATA (BSEL5, dmc_csrs[0].sel4, DEV_RDX, 8, 8) }, + { GRDATA (BSEL6, dmc_csrs[0].sel6, DEV_RDX, 8, 0) }, + { GRDATA (BSEL7, dmc_csrs[0].sel6, DEV_RDX, 8, 8) }, + { NULL } }; + +REG dmcb_reg[] = { + { HRDATA (SEL0, dmc_csrs[1].sel0, 16) }, + { HRDATA (SEL2, dmc_csrs[1].sel2, 16) }, + { HRDATA (SEL4, dmc_csrs[1].sel4, 16) }, + { HRDATA (SEL6, dmc_csrs[1].sel6, 16) }, + { GRDATA (BSEL0, dmc_csrs[1].sel0, DEV_RDX, 8, 0) }, + { GRDATA (BSEL1, dmc_csrs[1].sel0, DEV_RDX, 8, 8) }, + { GRDATA (BSEL2, dmc_csrs[1].sel2, DEV_RDX, 8, 0) }, + { GRDATA (BSEL3, dmc_csrs[1].sel2, DEV_RDX, 8, 8) }, + { GRDATA (BSEL4, dmc_csrs[1].sel4, DEV_RDX, 8, 0) }, + { GRDATA (BSEL5, dmc_csrs[1].sel4, DEV_RDX, 8, 8) }, + { GRDATA (BSEL6, dmc_csrs[1].sel6, DEV_RDX, 8, 0) }, + { GRDATA (BSEL7, dmc_csrs[1].sel6, DEV_RDX, 8, 8) }, + { NULL } }; + +REG dmcc_reg[] = { + { HRDATA (SEL0, dmc_csrs[2].sel0, 16) }, + { HRDATA (SEL2, dmc_csrs[2].sel2, 16) }, + { HRDATA (SEL4, dmc_csrs[2].sel4, 16) }, + { HRDATA (SEL6, dmc_csrs[2].sel6, 16) }, + { GRDATA (BSEL0, dmc_csrs[2].sel0, DEV_RDX, 8, 0) }, + { GRDATA (BSEL1, dmc_csrs[2].sel0, DEV_RDX, 8, 8) }, + { GRDATA (BSEL2, dmc_csrs[2].sel2, DEV_RDX, 8, 0) }, + { GRDATA (BSEL3, dmc_csrs[2].sel2, DEV_RDX, 8, 8) }, + { GRDATA (BSEL4, dmc_csrs[2].sel4, DEV_RDX, 8, 0) }, + { GRDATA (BSEL5, dmc_csrs[2].sel4, DEV_RDX, 8, 8) }, + { GRDATA (BSEL6, dmc_csrs[2].sel6, DEV_RDX, 8, 0) }, + { GRDATA (BSEL7, dmc_csrs[2].sel6, DEV_RDX, 8, 8) }, + { NULL } }; + +REG dmcd_reg[] = { + { HRDATA (SEL0, dmc_csrs[3].sel0, 16) }, + { HRDATA (SEL2, dmc_csrs[3].sel2, 16) }, + { HRDATA (SEL4, dmc_csrs[3].sel4, 16) }, + { HRDATA (SEL6, dmc_csrs[3].sel6, 16) }, + { GRDATA (BSEL0, dmc_csrs[3].sel0, DEV_RDX, 8, 0) }, + { GRDATA (BSEL1, dmc_csrs[3].sel0, DEV_RDX, 8, 8) }, + { GRDATA (BSEL2, dmc_csrs[3].sel2, DEV_RDX, 8, 0) }, + { GRDATA (BSEL3, dmc_csrs[3].sel2, DEV_RDX, 8, 8) }, + { GRDATA (BSEL4, dmc_csrs[3].sel4, DEV_RDX, 8, 0) }, + { GRDATA (BSEL5, dmc_csrs[3].sel4, DEV_RDX, 8, 8) }, + { GRDATA (BSEL6, dmc_csrs[3].sel6, DEV_RDX, 8, 0) }, + { GRDATA (BSEL7, dmc_csrs[3].sel6, DEV_RDX, 8, 8) }, + { NULL } }; + +REG dmp_reg[] = { + { HRDATA (SEL0, dmc_csrs[3].sel0, 16) }, + { HRDATA (SEL2, dmc_csrs[3].sel2, 16) }, + { HRDATA (SEL4, dmc_csrs[3].sel4, 16) }, + { HRDATA (SEL6, dmc_csrs[3].sel6, 16) }, + { GRDATA (BSEL0, dmc_csrs[3].sel0, DEV_RDX, 8, 0) }, + { GRDATA (BSEL1, dmc_csrs[3].sel0, DEV_RDX, 8, 8) }, + { GRDATA (BSEL2, dmc_csrs[3].sel2, DEV_RDX, 8, 0) }, + { GRDATA (BSEL3, dmc_csrs[3].sel2, DEV_RDX, 8, 8) }, + { GRDATA (BSEL4, dmc_csrs[3].sel4, DEV_RDX, 8, 0) }, + { GRDATA (BSEL5, dmc_csrs[3].sel4, DEV_RDX, 8, 8) }, + { GRDATA (BSEL6, dmc_csrs[3].sel6, DEV_RDX, 8, 0) }, + { GRDATA (BSEL7, dmc_csrs[3].sel6, DEV_RDX, 8, 8) }, + { NULL } }; + +MTAB dmc_mod[] = { + { MTAB_XTD | MTAB_VDV, 0, "TRANSMIT", "TRANSMIT=address:port" ,&dmc_settransmit, &dmc_showtransmit, NULL }, + { MTAB_XTD | MTAB_VDV, 0, "SPEED", "SPEED" ,&dmc_setspeed, &dmc_showspeed, NULL }, + { MTAB_XTD | MTAB_VDV, 0, "TYPE", "TYPE" ,&dmc_settype, &dmc_showtype, NULL }, + { MTAB_XTD | MTAB_VDV, 0, "LINEMODE", "LINEMODE" ,&dmc_setlinemode, &dmc_showlinemode, NULL }, + { MTAB_XTD | MTAB_VDV | MTAB_NMO, 0, "STATS", "STATS" ,&dmc_setstats, &dmc_showstats, NULL }, + { MTAB_XTD | MTAB_VDV, 0, "POLL", "POLL" ,&dmc_setpoll, &dmc_showpoll, NULL }, + { MTAB_XTD | MTAB_VDV, 0, "CONNECTPOLL", "CONNECTPOLL" ,&dmc_setconnectpoll, &dmc_showconnectpoll, NULL }, + { MTAB_XTD | MTAB_VDV, 006, "ADDRESS", "ADDRESS", &set_addr, &show_addr, NULL }, + { MTAB_XTD |MTAB_VDV, 0, "VECTOR", "VECTOR", &set_vec, &show_vec, NULL }, + { 0 }, +}; + +DIB dmc_dib[] = +{ + { IOBA_DMC, IOLN_DMC, &dmc_rd, &dmc_wr, 2, IVCL (DMCRX), VEC_DMCRX, {&dmc_rxint, &dmc_txint} }, + { IOBA_DMC, IOLN_DMC, &dmc_rd, &dmc_wr, 2, IVCL (DMCRX), VEC_DMCRX, {&dmc_rxint, &dmc_txint} }, + { IOBA_DMC, IOLN_DMC, &dmc_rd, &dmc_wr, 2, IVCL (DMCRX), VEC_DMCRX, {&dmc_rxint, &dmc_txint} }, + { IOBA_DMC, IOLN_DMC, &dmc_rd, &dmc_wr, 2, IVCL (DMCRX), VEC_DMCRX, {&dmc_rxint, &dmc_txint} } +}; + +DIB dmp_dib[] = +{ + { IOBA_DMC, IOLN_DMC, &dmc_rd, &dmc_wr, 2, IVCL (DMCRX), VEC_DMCRX, {&dmc_rxint, &dmc_txint} } +}; + +DEVICE dmc_dev[] = +{ + { "DMA", &dmc_unit[0], dmca_reg, dmc_mod, DMC_UNITSPERDEVICE, DMC_RDX, 8, 1, DMC_RDX, 8, + NULL,NULL,&dmc_reset,NULL,&dmc_attach,&dmc_detach, + &dmc_dib[0], DEV_FLTA | DEV_DISABLE | DEV_DIS | DEV_UBUS | DEV_NET | DEV_DEBUG, 0, dmc_debug }, + { "DMB", &dmc_unit[1], dmcb_reg, dmc_mod, DMC_UNITSPERDEVICE, DMC_RDX, 8, 1, DMC_RDX, 8, + NULL,NULL,&dmc_reset,NULL,&dmc_attach,&dmc_detach, + &dmc_dib[1], DEV_FLTA | DEV_DISABLE | DEV_DIS | DEV_UBUS | DEV_NET | DEV_DEBUG, 0, dmc_debug }, + { "DMC", &dmc_unit[2], dmcc_reg, dmc_mod, DMC_UNITSPERDEVICE, DMC_RDX, 8, 1, DMC_RDX, 8, + NULL,NULL,&dmc_reset,NULL,&dmc_attach,&dmc_detach, + &dmc_dib[2], DEV_FLTA | DEV_DISABLE | DEV_DIS | DEV_UBUS | DEV_NET | DEV_DEBUG, 0, dmc_debug }, + { "DMD", &dmc_unit[3], dmcd_reg, dmc_mod, DMC_UNITSPERDEVICE, DMC_RDX, 8, 1, DMC_RDX, 8, + NULL,NULL,&dmc_reset,NULL,&dmc_attach,&dmc_detach, + &dmc_dib[3], DEV_FLTA | DEV_DISABLE | DEV_DIS | DEV_UBUS | DEV_NET | DEV_DEBUG, 0, dmc_debug } +}; + +DEVICE dmp_dev[] = +{ + { "DMP", &dmp_unit[0], dmp_reg, dmc_mod, DMP_UNITSPERDEVICE, DMC_RDX, 8, 1, DMC_RDX, 8, + NULL,NULL,&dmc_reset,NULL,&dmc_attach,&dmc_detach, + &dmp_dib[0], DEV_FLTA | DEV_DISABLE | DEV_DIS | DEV_UBUS | DEV_NET | DEV_DEBUG, 0, dmc_debug } +}; + +LINE dmc_line[DMC_NUMDEVICE]; + +BUFFER_QUEUE dmc_receive_queues[DMC_NUMDEVICE]; +BUFFER_QUEUE dmc_transmit_queues[DMC_NUMDEVICE]; + +LINE dmp_line[DMP_NUMDEVICE]; + +BUFFER_QUEUE dmp_receive_queues[DMP_NUMDEVICE]; +BUFFER_QUEUE dmp_transmit_queues[DMP_NUMDEVICE]; + +CTLR dmc_ctrls[] = +{ + { &dmc_csrs[0], &dmc_dev[0], Initialised, Idle, 0, 0, &dmc_line[0], &dmc_receive_queues[0], &dmc_transmit_queues[0], INVALID_SOCKET, -1, 30, DMC }, + { &dmc_csrs[1], &dmc_dev[1], Initialised, Idle, 0, 0, &dmc_line[1], &dmc_receive_queues[1], &dmc_transmit_queues[1], INVALID_SOCKET, -1, 30, DMC }, + { &dmc_csrs[2], &dmc_dev[2], Initialised, Idle, 0, 0, &dmc_line[2], &dmc_receive_queues[2], &dmc_transmit_queues[2], INVALID_SOCKET, -1, 30, DMC }, + { &dmc_csrs[3], &dmc_dev[3], Initialised, Idle, 0, 0, &dmc_line[3], &dmc_receive_queues[3], &dmc_transmit_queues[3], INVALID_SOCKET, -1, 30, DMC }, + { &dmp_csrs[0], &dmp_dev[0], Initialised, Idle, 0, 0, &dmp_line[0], &dmp_receive_queues[0], &dmp_transmit_queues[0], INVALID_SOCKET, -1, 30, DMP } +}; + +UNIT_STATS *dmc_get_unit_stats(UNIT *uptr) +{ + UNIT_STATS *ans = NULL; +#ifdef USE_ADDR64 + ans = (UNIT_STATS *)(((t_uint64)uptr->u3 << 32) | uptr->u4); +#else + ans = (UNIT_STATS *)(uptr->u3); +#endif + return ans; +} + +void dmc_set_unit_stats(UNIT *uptr, UNIT_STATS *stats) +{ +#ifdef USE_ADDR64 + uptr->u3 = (int32)((t_uint64)stats >> 32); + uptr->u4 = (int32)((t_uint64)stats & 0xFFFFFFFF); +#else + uptr->u3 = (int32)stats; +#endif +} + +void dmc_reset_unit_stats(UNIT_STATS *s) +{ + s->between_polls_timer.started = FALSE; + s->poll_timer.started = FALSE; + s->poll_count = 0; +} + +int dmc_timer_started(TIMER *t) +{ + return t->started; +} + +void dmc_timer_start(TIMER *t) +{ + t->start_time = clock(); + t->cumulative_time = 0; + t->started = TRUE; +} + +void dmc_timer_stop(TIMER *t) +{ + clock_t end_time = clock(); + t->cumulative_time += end_time - t->start_time; +} + +void dmc_timer_resume(TIMER *t) +{ + t->start_time = clock(); +} + +double dmc_timer_cumulative_seconds(TIMER *t) +{ + return (double)t->cumulative_time/CLOCKS_PER_SEC; +} + +int dmc_is_dmc(CTLR *controller) +{ + return controller->dev_type != DMP; +} + +CTLR *dmc_get_controller_from_unit(UNIT *unit) +{ + int i; + CTLR *ans = NULL; + for (i = 0; i < DMC_NUMDEVICE + DMP_NUMDEVICE; i++) + { + if (dmc_ctrls[i].device->units == unit) + { + ans = &dmc_ctrls[i]; + break; + } + } + + return ans; +} + +CTLR* dmc_get_controller_from_address(uint32 address) +{ + int i; + for (i=0; ictxt; + if ((address >= dib->ba) && (address < (dib->ba + dib->lnt))) + return &dmc_ctrls[i]; + } + /* not found */ + return 0; +} + +CTLR *dmc_get_controller_from_device(DEVICE *device) +{ + int i; + CTLR *ans = NULL; + for (i = 0; i < DMC_NUMDEVICE + DMP_NUMDEVICE; i++) + { + if (dmc_ctrls[i].device == device) + { + ans = &dmc_ctrls[i]; + break; + } + } + + return ans; +} + +t_stat dmc_showtransmit (FILE* st, UNIT* uptr, int32 val, void* desc) +{ + CTLR *controller = dmc_get_controller_from_unit(uptr); + fprintf(st, "TRANSMIT=%s", controller->line->transmit_host); + return SCPE_OK; +} + +t_stat dmc_settransmit (UNIT* uptr, int32 val, char* cptr, void* desc) +{ + t_stat status = SCPE_OK; + char host[CBUFSIZE], port[CBUFSIZE]; + CTLR *controller = dmc_get_controller_from_unit(uptr); + + if (!cptr) return SCPE_IERR; + if (uptr->flags & UNIT_ATT) return SCPE_ALATT; + status = sim_parse_addr (cptr, host, sizeof(host), NULL, port, sizeof(port), NULL); + if (status != SCPE_OK) + return status; + if (host[0] == '\0') + return SCPE_ARG; + strncpy(controller->line->transmit_host, cptr, sizeof(controller->line->transmit_host)-1); + + return status; +} + +t_stat dmc_showspeed (FILE* st, UNIT* uptr, int32 val, void* desc) +{ + CTLR *controller = dmc_get_controller_from_unit(uptr); + fprintf(st, "SPEED=%d", controller->line->speed); + return SCPE_OK; +} + +t_stat dmc_setspeed (UNIT* uptr, int32 val, char* cptr, void* desc) +{ + t_stat status = SCPE_OK; + CTLR *controller = dmc_get_controller_from_unit(uptr); + + if (!cptr) return SCPE_IERR; + if (uptr->flags & UNIT_ATT) return SCPE_ALATT; + if (sscanf(cptr, "%d", &controller->line->speed) != 1) + { + status = SCPE_ARG; + } + + return status; +} + +t_stat dmc_showtype (FILE* st, UNIT* uptr, int32 val, void* desc) +{ + CTLR *controller = dmc_get_controller_from_unit(uptr); + switch (controller->dev_type) + { + case DMC: + { + fprintf(st, "TYPE=DMC"); + break; + } + case DMR: + { + fprintf(st, "TYPE=DMR"); + break; + } + case DMP: + { + fprintf(st, "TYPE=DMP"); + break; + } + default: + { + fprintf(st, "TYPE=???"); + break; + } + } + return SCPE_OK; +} + +t_stat dmc_settype (UNIT* uptr, int32 val, char* cptr, void* desc) +{ + char buf[80]; + t_stat status = SCPE_OK; + CTLR *controller = dmc_get_controller_from_unit(uptr); + + if (!cptr) return SCPE_IERR; + if (uptr->flags & UNIT_ATT) return SCPE_ALATT; + if (sscanf(cptr, "%s", buf) != 1) + { + status = SCPE_ARG; + } + else + { + if (strcmp(buf,"DMC")==0) + { + controller->dev_type = DMC; + } + else if (strcmp(buf,"DMR")==0) + { + controller->dev_type = DMR; + } + else if (strcmp(buf,"DMP")==0) + { + controller->dev_type = DMP; + } + else + { + status = SCPE_ARG; + } + } + + return status; +} + +t_stat dmc_showstats (FILE* st, UNIT* uptr, int32 val, void* desc) +{ + CTLR *controller = dmc_get_controller_from_unit(uptr); + TIMER *poll_timer = &dmc_get_unit_stats(uptr)->poll_timer; + TIMER *between_polls_timer = &dmc_get_unit_stats(uptr)->between_polls_timer; + uint32 poll_count = dmc_get_unit_stats(uptr)->poll_count; + + if (dmc_timer_started(between_polls_timer) && poll_count > 0) + { + fprintf(st, "Average time between polls=%f (sec)\n", dmc_timer_cumulative_seconds(between_polls_timer)/poll_count); + } + else + { + fprintf(st, "Average time between polls=n/a\n"); + } + + if (dmc_timer_started(poll_timer) && poll_count > 0) + { + fprintf(st, "Average time within poll=%f (sec)\n", dmc_timer_cumulative_seconds(poll_timer)/poll_count); + } + else + { + fprintf(st, "Average time within poll=n/a\n"); + } + + fprintf(st, "Buffers received from the network=%d\n", controller->buffers_received_from_net); + fprintf(st, "Buffers sent to the network=%d\n", controller->buffers_transmitted_to_net); + fprintf(st, "Output transfers completed for receive buffers=%d\n", controller->receive_buffer_output_transfers_completed); + fprintf(st, "Output transfers completed for transmit buffers=%d\n", controller->transmit_buffer_output_transfers_completed); + fprintf(st, "Input transfers completed for receive buffers=%d\n", controller->receive_buffer_input_transfers_completed); + fprintf(st, "Input transfers completed for transmit buffers=%d\n", controller->transmit_buffer_input_transfers_completed); + + return SCPE_OK; +} + +t_stat dmc_setstats (UNIT* uptr, int32 val, char* cptr, void* desc) +{ + t_stat status = SCPE_OK; + CTLR *controller = dmc_get_controller_from_unit(uptr); + + dmc_reset_unit_stats(dmc_get_unit_stats(uptr)); + + controller->receive_buffer_output_transfers_completed = 0; + controller->transmit_buffer_output_transfers_completed = 0; + controller->receive_buffer_input_transfers_completed = 0; + controller->transmit_buffer_input_transfers_completed = 0; + + printf("Statistics reset\n" ); + + return status; +} + +t_stat dmc_showpoll (FILE* st, UNIT* uptr, int32 val, void* desc) +{ + CTLR *controller = dmc_get_controller_from_unit(uptr); + fprintf(st, "POLL=%d", controller->svc_poll_interval); + return SCPE_OK; +} + +t_stat dmc_setpoll (UNIT* uptr, int32 val, char* cptr, void* desc) +{ + t_stat status = SCPE_OK; + CTLR *controller = dmc_get_controller_from_unit(uptr); + + if (!cptr) return SCPE_IERR; + if (sscanf(cptr, "%d", &controller->svc_poll_interval) != 1) + { + status = SCPE_ARG; + } + + return status; +} + +t_stat dmc_showconnectpoll (FILE* st, UNIT* uptr, int32 val, void* desc) +{ + CTLR *controller = dmc_get_controller_from_unit(uptr); + fprintf(st, "CONNECTPOLL=%d", controller->connect_poll_interval); + return SCPE_OK; +} + +t_stat dmc_setconnectpoll (UNIT* uptr, int32 val, char* cptr, void* desc) +{ + t_stat status = SCPE_OK; + CTLR *controller = dmc_get_controller_from_unit(uptr); + + if (!cptr) return SCPE_IERR; + if (sscanf(cptr, "%d", &controller->connect_poll_interval) != 1) + { + status = SCPE_ARG; + } + + return status; +} + +t_stat dmc_showlinemode (FILE* st, UNIT* uptr, int32 val, void* desc) +{ + CTLR *controller = dmc_get_controller_from_unit(uptr); + fprintf(st, "LINEMODE=%s", controller->line->isPrimary? "PRIMARY" : "SECONDARY"); + return SCPE_OK; +} + +t_stat dmc_setlinemode (UNIT* uptr, int32 val, char* cptr, void* desc) +{ + t_stat status = SCPE_OK; + CTLR *controller = dmc_get_controller_from_unit(uptr); + + if (!cptr) return SCPE_IERR; + if (uptr->flags & UNIT_ATT) return SCPE_ALATT; + + if (strcmp(cptr, "PRIMARY") == 0) + { + controller->line->isPrimary = 1; + } + else if (strcmp(cptr, "SECONDARY") == 0) + { + controller->line->isPrimary = 0; + } + else + { + status = SCPE_ARG; + } + + return status; +} + +void dmc_setrxint(CTLR *controller) +{ + controller->rxi = 1; + SET_INT(DMCRX); +} + +void dmc_clrrxint(CTLR *controller) +{ + controller->rxi = 0; + CLR_INT(DMCRX); +} + +void dmc_settxint(CTLR *controller) +{ + controller->txi = 1; + SET_INT(DMCTX); +} + +void dmc_clrtxint(CTLR *controller) +{ + controller->txi = 0; + CLR_INT(DMCTX); +} + +int dmc_getsel(int addr) +{ + return (addr >> 1) & 03; +} + +uint16 dmc_bitfld(int data, int start_bit, int length) +{ + uint16 ans = data >> start_bit; + uint32 mask = (1 << (length))-1; + ans &= mask; + return ans; +} + +void dmc_dumpregsel0(CTLR *controller, int trace_level, char * prefix, uint16 data) +{ + char *type_str = ""; + uint16 type = dmc_bitfld(data, SEL0_TYPEI_BIT, 2); + + if (dmc_is_dmc(controller)) + { + if (dmc_is_rqi_set(controller)) + { + if (type==TYPE_BACCI) + type_str = "BA/CC I"; + else if (type==TYPE_CNTLI) + type_str = "CNTL I"; + else if (type==TYPE_BASEI) + type_str = "BASE I"; + else + type_str = "?????"; + } + + sim_debug( + trace_level, + controller->device, + "%s SEL0 (0x%04x) %s%s%s%s%s%s%s%s\n", + prefix, + data, + dmc_bitfld(data, SEL0_RUN_BIT, 1) ? "RUN " : "", + dmc_bitfld(data, SEL0_MCLR_BIT, 1) ? "MCLR " : "", + dmc_bitfld(data, SEL0_LU_LOOP_BIT, 1) ? "LU LOOP " : "", + dmc_bitfld(data, SEL0_RDI_BIT, 1) ? "RDI " : "", + dmc_bitfld(data, SEL0_DMC_IEI_BIT, 1) ? "IEI " : "", + dmc_bitfld(data, SEL0_DMC_RQI_BIT, 1) ? "RQI " : "", + dmc_bitfld(data, SEL0_IN_IO_BIT, 1) ? "IN I/O " : "", + type_str + ); + } + else + { + sim_debug( + trace_level, + controller->device, + "%s SEL0 (0x%04x) %s%s%s%s%s%s\n", + prefix, + data, + dmc_bitfld(data, SEL0_RUN_BIT, 1) ? "RUN " : "", + dmc_bitfld(data, SEL0_MCLR_BIT, 1) ? "MCLR " : "", + dmc_bitfld(data, SEL0_LU_LOOP_BIT, 1) ? "LU LOOP " : "", + dmc_bitfld(data, SEL0_DMP_RQI_BIT, 1) ? "RQI " : "", + dmc_bitfld(data, SEL0_DMP_IEO_BIT, 1) ? "IEO " : "", + dmc_bitfld(data, SEL0_DMP_IEI_BIT, 1) ? "IEI " : "" + ); + } +} + +void dmc_dumpregsel2(CTLR *controller, int trace_level, char *prefix, uint16 data) +{ + char *type_str = ""; + uint16 type = dmc_bitfld(data, SEL2_TYPEO_BIT, 2); + + if (type==TYPE_BACCO) + type_str = "BA/CC O"; + else if (type==TYPE_CNTLO) + type_str = "CNTL O"; + else + type_str = "?????"; + + sim_debug( + trace_level, + controller->device, + "%s SEL2 (0x%04x) PRIO=%d LINE=%d %s%s%s%s\n", + prefix, + data, + dmc_bitfld(data, SEL2_PRIO_BIT, SEL2_PRIO_BIT_LENGTH), + dmc_bitfld(data, SEL2_LINE_BIT, SEL2_LINE_BIT_LENGTH), + dmc_bitfld(data, SEL2_RDO_BIT, 1) ? "RDO " : "", + dmc_bitfld(data, SEL2_IEO_BIT, 1) ? "IEO " : "", + dmc_bitfld(data, SEL2_OUT_IO_BIT, 1) ? "OUT I/O " : "", + type_str + ); +} + +void dmc_dumpregsel4(CTLR *controller, int trace_level, char *prefix, uint16 data) +{ + sim_debug(trace_level, controller->device, "%s SEL4 (0x%04x)\n", prefix, data); +} + +void dmc_dumpregsel6(CTLR *controller, int trace_level, char *prefix, uint16 data) +{ + sim_debug( + trace_level, + controller->device, + "%s SEL6 (0x%04x) %s\n", + prefix, + data, + dmc_bitfld(data, SEL6_LOST_DATA_BIT, 1) ? "LOST_DATA " : ""); +} + +uint16 dmc_getreg(CTLR *controller, int reg, int ext) +{ + uint16 ans = 0; + switch (dmc_getsel(reg)) + { + case 00: + ans = controller->csrs->sel0; + if (ext) dmc_dumpregsel0(controller, DBG_REG, "Getting", ans); + break; + case 01: + ans = controller->csrs->sel2; + if (ext) dmc_dumpregsel2(controller, DBG_REG, "Getting", ans); + break; + case 02: + ans = controller->csrs->sel4; + if (ext) dmc_dumpregsel4(controller, DBG_REG, "Getting", ans); + break; + case 03: + ans = controller->csrs->sel6; + if (ext) dmc_dumpregsel6(controller, DBG_REG, "Getting", ans); + break; + default: + { + sim_debug(DBG_WRN, controller->device, "dmc_getreg(). Invalid register %d", reg); + } + } + + return ans; +} + +void dmc_setreg(CTLR *controller, int reg, uint16 data, int ext) +{ + char *trace = (ext) ? "Writing" : "Setting"; + switch (dmc_getsel(reg)) + { + case 00: + dmc_dumpregsel0(controller, DBG_REG, trace, data); + controller->csrs->sel0 = data; + break; + case 01: + dmc_dumpregsel2(controller, DBG_REG, trace, data); + controller->csrs->sel2 = data; + break; + case 02: + dmc_dumpregsel4(controller, DBG_REG, trace, data); + controller->csrs->sel4 = data; + break; + case 03: + dmc_dumpregsel6(controller, DBG_REG, trace, data); + controller->csrs->sel6 = data; + break; + default: + { + sim_debug(DBG_WRN, controller->device, "dmc_setreg(). Invalid register %d", reg); + } + } +} + +int dmc_is_master_clear_set(CTLR *controller) +{ + return controller->csrs->sel0 & MASTER_CLEAR_MASK; +} + +int dmc_is_lu_loop_set(CTLR *controller) +{ + return controller->csrs->sel0 & LU_LOOP_MASK; +} + +int dmc_is_rqi_set(CTLR *controller) +{ + int ans = 0; + if (dmc_is_dmc(controller)) + { + ans = controller->csrs->sel0 & DMC_RQI_MASK; + } + else + { + ans = controller->csrs->sel0 & DMP_RQI_MASK; + } + return ans; +} + +int dmc_is_rdyi_set(CTLR *controller) +{ + int ans = 0; + if (dmc_is_dmc(controller)) + { + ans = controller->csrs->sel0 & DMC_RDYI_MASK; + } + else + { + ans = controller->csrs->sel2 & DMP_RDYI_MASK; + } + return ans; +} + +int dmc_is_iei_set(CTLR *controller) +{ + int ans = 0; + if (dmc_is_dmc(controller)) + { + ans = controller->csrs->sel0 & DMC_IEI_MASK; + } + else + { + ans = controller->csrs->sel0 & DMP_IEI_MASK; + } + + return ans; +} +int dmc_is_ieo_set(CTLR *controller) +{ + int ans = 0; + if (dmc_is_dmc(controller)) + { + ans = controller->csrs->sel2 & DMC_IEO_MASK; + } + else + { + ans = controller->csrs->sel0 & DMP_IEO_MASK; + } + + return ans; +} +int dmc_is_in_io_set(CTLR *controller) +{ + int ans = 0; + if (dmc_is_dmc(controller)) + { + ans = controller->csrs->sel0 & DMC_IN_IO_MASK; + } + else + { + ans = !controller->csrs->sel2 & DMP_IN_IO_MASK; + } + + return ans; +} +int dmc_is_out_io_set(CTLR *controller) +{ + int ans = controller->csrs->sel2 & OUT_IO_MASK; + return ans; +} + +int dmc_is_rdyo_set(CTLR *controller) +{ + return controller->csrs->sel2 & DMC_RDYO_MASK; +} + +void dmc_set_rdyi(CTLR *controller) +{ + if (dmc_is_dmc(controller)) + { + dmc_setreg(controller, 0, controller->csrs->sel0 | DMC_RDYI_MASK, 0); + } + else + { + dmc_setreg(controller, 2, controller->csrs->sel2 | DMP_RDYI_MASK, 0); + } + + if (dmc_is_iei_set(controller)) + { + dmc_setrxint(controller); + } +} + +void dmc_clear_rdyi(CTLR *controller) +{ + if (dmc_is_dmc(controller)) + { + dmc_setreg(controller, 0, controller->csrs->sel0 & ~DMC_RDYI_MASK, 0); + } + else + { + dmc_setreg(controller, 2, controller->csrs->sel2 & ~DMP_RDYI_MASK, 0); + } +} + +void dmc_set_rdyo(CTLR *controller) +{ + dmc_setreg(controller, 2, controller->csrs->sel2 | DMC_RDYO_MASK, 0); + + if (dmc_is_ieo_set(controller)) + { + dmc_settxint(controller); + } +} + +void dmc_set_lost_data(CTLR *controller) +{ + dmc_setreg(controller, 6, controller->csrs->sel6 | LOST_DATA_MASK, 0); +} + +void dmc_clear_master_clear(CTLR *controller) +{ + dmc_setreg(controller, 0, controller->csrs->sel0 & ~MASTER_CLEAR_MASK, 0); +} + +void dmc_set_run(CTLR *controller) +{ + dmc_setreg(controller, 0, controller->csrs->sel0 | RUN_MASK, 0); +} + +int dmc_get_input_transfer_type(CTLR *controller) +{ + int ans = 0; + + if (dmc_is_dmc(controller)) + { + ans = controller->csrs->sel0 & DMC_TYPE_INPUT_MASK; + } + else + { + ans = controller->csrs->sel2 & DMP_TYPE_INPUT_MASK; + } + + return ans; +} +int dmc_get_output_transfer_type(CTLR *controller) +{ + return controller->csrs->sel2 & TYPE_OUTPUT_MASK; +} +void dmc_set_type_output(CTLR *controller, int type) +{ + dmc_setreg(controller, 2, controller->csrs->sel2 | (type & TYPE_OUTPUT_MASK), 0); +} + +void dmc_set_out_io(CTLR *controller) +{ + dmc_setreg(controller, 2, controller->csrs->sel2 | OUT_IO_MASK, 0); +} + +void dmc_clear_out_io(CTLR *controller) +{ + dmc_setreg(controller, 2, controller->csrs->sel2 & ~OUT_IO_MASK, 0); +} + +void dmc_process_master_clear(CTLR *controller) +{ + sim_debug(DBG_INF, controller->device, "Master clear\n"); + dmc_clear_master_clear(controller); + controller->state = Initialised; + dmc_setreg(controller, 0, 0, 0); + if (controller->dev_type == DMR) + { + /* DMR-11 indicates microdiagnostics complete when this is set */ + dmc_setreg(controller, 2, 0x8000, 0); + } + else + { + /* preserve contents of BSEL3 if DMC-11 */ + dmc_setreg(controller, 2, controller->csrs->sel2 & 0xFF00, 0); + } + if (controller->dev_type == DMP) + { + dmc_setreg(controller, 4, 077, 0); + } + else + { + dmc_setreg(controller, 4, 0, 0); + } + + if (controller->dev_type == DMP) + { + dmc_setreg(controller, 6, 0305, 0); + } + else + { + dmc_setreg(controller, 6, 0, 0); + } + dmc_buffer_queue_init(controller, controller->receive_queue, "receive"); + dmc_buffer_queue_init(controller, controller->transmit_queue, "transmit"); + //dmc_close_receive(controller, "master clear"); + //dmc_close_transmit(controller, "master clear"); + + controller->transfer_state = Idle; + dmc_set_run(controller); + + sim_cancel (controller->device->units); /* stop poll */ + sim_activate_abs(controller->device->units, clk_cosched (controller->svc_poll_interval)); +} + +void dmc_start_input_transfer(CTLR *controller) +{ + int ok = 1; + int type = dmc_get_input_transfer_type(controller); + + /* if this is a BA/CC I then check that the relevant queue has room first */ + if (type == TYPE_BACCI) + { + ok = (dmc_is_in_io_set(controller) && !dmc_buffer_queue_full(controller->receive_queue)) + || + (!dmc_is_in_io_set(controller) && !dmc_buffer_queue_full(controller->transmit_queue)); + } + + if (ok) + { + sim_debug(DBG_INF, controller->device, "Starting input transfer\n"); + controller->transfer_state = InputTransfer; + controller->transfer_type = type; + controller->transfer_in_io = dmc_is_in_io_set(controller); + dmc_set_rdyi(controller); + } + else + { + sim_debug(DBG_WRN, controller->device, "Input transfer request not granted as queue is full\n"); + } +} + +void dmc_start_data_output_transfer(CTLR *controller, uint32 addr, int16 count, int is_receive) +{ + if (is_receive) + { + sim_debug(DBG_INF, controller->device, "Starting data output transfer for receive, address=0x%08x, count=%d\n", addr, count); + dmc_set_out_io(controller); + } + else + { + sim_debug(DBG_INF, controller->device, "Starting data output transfer for transmit, address=0x%08x, count=%d\n", addr, count); + dmc_clear_out_io(controller); + } + + dmc_setreg(controller, 4, addr & 0xFFFF, 0); + dmc_setreg(controller, 6, (((addr & 0x30000)) >> 2) | count, 0); + controller->transfer_state = OutputTransfer; + dmc_set_type_output(controller, TYPE_BACCO); + dmc_set_rdyo(controller); +} + +void dmc_start_control_output_transfer(CTLR *controller) +{ + sim_debug(DBG_INF, controller->device, "Starting control output transfer\n"); + controller->transfer_state = OutputTransfer; + dmc_set_type_output(controller, TYPE_CNTLO); + dmc_set_rdyo(controller); +} + +t_stat dmc_svc(UNIT* uptr) +{ + CTLR *controller; + + TIMER *poll_timer = &dmc_get_unit_stats(uptr)->poll_timer; + TIMER *between_polls_timer = &dmc_get_unit_stats(uptr)->between_polls_timer; + + if (dmc_timer_started(between_polls_timer)) + { + dmc_timer_stop(between_polls_timer); + } + + if (dmc_timer_started(poll_timer)) + { + dmc_timer_resume(poll_timer); + } + else + { + dmc_timer_start(poll_timer); + } + + controller = dmc_get_controller_from_unit(uptr); + + dmc_line_update_speed_stats(controller->line); + + if (dmc_buffer_fill_receive_buffers(controller)) + { +// poll = 200; /* if we received data then lets poll quicker as there seems to be some activity */ + } + if (controller->transfer_state == Idle) dmc_start_transfer_receive_buffer(controller); + + if (dmc_buffer_send_transmit_buffers(controller)) + { +// poll = 200; /* if we transmitted data then lets poll quicker as there seems to be some activity */ + } + if (controller->transfer_state == Idle) dmc_start_transfer_transmit_buffer(controller); + + /* resubmit service timer */ + sim_activate(controller->device->units, controller->svc_poll_interval); + + dmc_timer_stop(poll_timer); + if (dmc_timer_started(between_polls_timer)) + { + dmc_timer_resume(between_polls_timer); + } + else + { + dmc_timer_start(between_polls_timer); + } + dmc_get_unit_stats(uptr)->poll_count++; + + return SCPE_OK; +} + +void dmc_line_update_speed_stats(LINE *line) +{ + clock_t current = clock(); + int current_second = current / CLOCKS_PER_SEC; + if (current_second != line->last_second) + { + line->bytes_received_in_last_second = 0; + line->bytes_sent_in_last_second = 0; + line->last_second = current_second; + } +} + +/* given the number of bytes sent/received in the last second, the number of bytes to send or receive and the line speed, calculate how many bytes can be sent/received now */ +int dmc_line_speed_calculate_byte_length(int bytes_in_last_second, int num_bytes, int speed) +{ + int ans; + + if (speed == 0) + { + ans = num_bytes; + } + else + { + int clocks_this_second = clock() % CLOCKS_PER_SEC; + int allowable_bytes_to_date = ((speed/8) * clocks_this_second)/CLOCKS_PER_SEC; + int allowed_bytes = allowable_bytes_to_date - bytes_in_last_second; + if (allowed_bytes < 0) + { + allowed_bytes = 0; + } + + if (num_bytes > allowed_bytes) + { + ans = allowed_bytes; + } + else + { + ans = num_bytes; + } +//sim_debug(DBG_WRN, dmc_ctrls[0].device, "Bytes in last second %4d, clocks this sec %3d allowable bytes %4d, requested %4d allowed %4d\n", bytes_in_last_second, clocks_this_second, allowable_bytes_to_date, num_bytes, ans); + } + + return ans; +} + +void dmc_buffer_trace_line(int tracelevel, CTLR *controller, uint8 *buf, int length, char *prefix) +{ + char hex[TRACE_BYTES_PER_LINE*3+1]; + char ascii[TRACE_BYTES_PER_LINE+1]; + //char ts[9]; + //time_t t; + int i; + hex[0] = 0; + ascii[TRACE_BYTES_PER_LINE] = 0; + + //t = time(NULL); + //strftime(ts, 9, "%H:%M:%S", localtime(&t)); + for (i = 0; i=length) + { + strcat(hex, " "); + ascii[i] = ' '; + } + else + { + char hexByte[4]; + sprintf(hexByte, "%02X ", buf[i]); + strcat(hex, hexByte); + if (isprint(buf[i])) + { + ascii[i] = (char)buf[i]; + } + else + { + ascii[i] = '.'; + } + } + } + + sim_debug(tracelevel, controller->device, "%s %s %s\n", prefix, hex, ascii); +} + +void dmc_buffer_trace(CTLR *controller, uint8 *buf, int length, char *prefix) +{ + int i; + if (length >= 0 && controller->device->dctrl & DBG_DAT) + { + for(i = 0; i < length / TRACE_BYTES_PER_LINE; i++) + { + dmc_buffer_trace_line(DBG_DAT, controller, buf + i*TRACE_BYTES_PER_LINE, TRACE_BYTES_PER_LINE, prefix); + } + + if (length %TRACE_BYTES_PER_LINE > 0) + { + dmc_buffer_trace_line(DBG_DAT, controller, buf + length/TRACE_BYTES_PER_LINE, length % TRACE_BYTES_PER_LINE, prefix); + } + } + else if (length >= 0 && controller->device->dctrl & DBG_DTS) + { + char prefix2[80]; + sprintf(prefix2, "%s (len=%d)", prefix, length); + dmc_buffer_trace_line(DBG_DTS, controller, buf, (length > TRACE_BYTES_PER_LINE)? TRACE_BYTES_PER_LINE : length, prefix2); + } +} + +void dmc_buffer_queue_init(CTLR *controller, BUFFER_QUEUE *q, char *name) +{ + q->name = name; + q->head = 0; + q->tail = 0; + q->count = 0; + q->controller = controller; +} + +int dmc_buffer_queue_full(BUFFER_QUEUE *q) +{ + return q->count > BUFFER_QUEUE_SIZE; +} + +void dmc_buffer_queue_add(BUFFER_QUEUE *q, uint32 address, uint16 count) +{ + if (!dmc_buffer_queue_full(q)) + { + int new_buffer = 0; + if (q->count > 0) + { + int last_buffer = q->tail; + new_buffer = (q->tail +1) % BUFFER_QUEUE_SIZE; + + /* Link last buffer to the new buffer */ + q->queue[last_buffer].next = &q->queue[new_buffer]; + } + else + { + q->head = 0; + new_buffer = 0; + } + + q->tail = new_buffer; + q->queue[new_buffer].address = address; + q->queue[new_buffer].count = count; + q->queue[new_buffer].actual_block_len = 0; + q->queue[new_buffer].transfer_buffer = NULL; + q->queue[new_buffer].block_len_bytes_read = 0; + q->queue[new_buffer].actual_bytes_transferred = 0; + q->queue[new_buffer].next = NULL; + q->queue[new_buffer].state = Available; + q->queue[new_buffer].is_loopback = dmc_is_lu_loop_set(q->controller); + q->count++; + sim_debug(DBG_INF, q->controller->device, "Queued %s buffer address=0x%08x count=%d\n", q->name, address, count); + } + else + { + sim_debug(DBG_WRN, q->controller->device, "Failed to queue %s buffer, queue full\n", q->name); + // TODO: Report error here. + } +} + +void dmc_buffer_queue_release_head(BUFFER_QUEUE *q) +{ + if (q->count > 0) + { + q->head = (q->head + 1) % BUFFER_QUEUE_SIZE; + q->count--; + } + else + { + sim_debug(DBG_INF, q->controller->device, "Failed to release %s buffer, queue already empty\n", q->name); + } +} + +BUFFER *dmc_buffer_queue_head(BUFFER_QUEUE *q) +{ + BUFFER *ans = NULL; + if (q->count >0) + { + ans = &q->queue[q->head]; + } + + return ans; +} + +BUFFER *dmc_buffer_queue_find_first_available(BUFFER_QUEUE *q) +{ + BUFFER *ans = dmc_buffer_queue_head(q); + while (ans != NULL) + { + if (ans->state == Available) + { + break; + } + + ans = ans->next; + } + + return ans; +} + +BUFFER *dmc_buffer_queue_find_first_contains_data(BUFFER_QUEUE *q) +{ + BUFFER *ans = dmc_buffer_queue_head(q); + while (ans != NULL) + { + if (ans->state == ContainsData) + { + break; + } + + ans = ans->next; + } + + return ans; +} + +void dmc_buffer_queue_get_stats(BUFFER_QUEUE *q, int *available, int *contains_data, int *transfer_in_progress) +{ + BUFFER *buf = dmc_buffer_queue_head(q); + *available = 0; + *contains_data = 0; + *transfer_in_progress = 0; + + while (buf != NULL) + { + switch (buf->state) + { + case Available: + { + (*available)++; + break; + } + + case ContainsData: + { + (*contains_data)++; + break; + } + + case TransferInProgress: + { + (*transfer_in_progress)++; + break; + } + } + + buf = buf->next; + } +} + +t_stat dmc_open_master_socket(CTLR *controller, char *port) +{ + t_stat ans; + ans = SCPE_OK; + if (controller->master_socket == INVALID_SOCKET) + { + controller->master_socket = sim_master_sock(port, &ans); + if (controller->master_socket == INVALID_SOCKET) + { + sim_debug(DBG_WRN, controller->device, "Failed to open master socket\n"); + ans = SCPE_OPENERR; + } + else + { + printf ("DMC-11 %s listening on port %s (socket %d)\n", controller->device->name, port, controller->master_socket); + } + } + + return ans; +} + +t_stat dmc_close_master_socket(CTLR *controller) +{ + sim_close_sock (controller->master_socket, TRUE); + controller->master_socket = INVALID_SOCKET; + return SCPE_OK; +} + +// Gets the bidirectional socket and handles arbitration of determining which socket to use. +int dmc_get_socket(CTLR *controller, int forRead) +{ + static int lastans = 0; + int ans = 0; + if (controller->line->isPrimary) + { + ans = dmc_get_transmit_socket(controller, 0, forRead); // TODO: After change to single socket, loopback may not work. + } + else + { + ans = dmc_get_receive_socket(controller, forRead); // TODO: After change to single socket, loopback may not work. + } + + if (lastans != ans) + { +sim_debug(DBG_SOK, controller->device, "Get Socket forread=%d, changed to %d\n", forRead, ans); + } + lastans = ans; + + return ans; +} + +int dmc_get_receive_socket(CTLR *controller, int forRead) +{ + int ans = 0; + if (controller->line->socket == INVALID_SOCKET) + { + char *ipaddr; + //sim_debug(DBG_SOK, controller->device, "Trying to open receive socket\n"); + controller->line->socket = sim_accept_conn (controller->master_socket, &ipaddr); /* poll connect */ + if (controller->line->socket != INVALID_SOCKET) + { + if (strcmp(ipaddr, controller->line->transmit_host)) + { + sim_debug(DBG_WRN, controller->device, "Received connection from unexpected source IP %s. Closing the connection.\n", ipaddr); + dmc_close_receive(controller, "Unathorized connection"); + } + else + { + sim_debug(DBG_SOK, controller->device, "Opened receive socket %d\n", controller->line->socket); + controller->line->receive_readable = FALSE; + } + free(ipaddr); + } + } + + if (controller->line->socket != INVALID_SOCKET) + { + int readable = sim_check_conn(controller->line->socket, forRead); + if (readable == 0) /* Still opening */ + { + // Socket is still being opened, or is open but there is no data ready to be read. + ans = 0; + } + else if (readable == -1) /* Failed to open */ + { + dmc_close_receive(controller, "failed to connect"); + ans = 0; + } + else /* connected */ + { + if (!controller->line->receive_readable) + { + sim_debug(DBG_CON, controller->device, "Receive socket is now readable\n"); + } + controller->line->receive_readable = TRUE; + ans = 1; + } + } + + return ans; +} + +int dmc_get_transmit_socket(CTLR *controller, int is_loopback, int forRead) +{ + int ans = 0; + /* close transmit socket if there is a change in the loopback setting */ + if (is_loopback ^ controller->line->transmit_is_loopback) + { + dmc_close_transmit(controller, "loopback change"); + } + + if (controller->line->socket == INVALID_SOCKET && (time(NULL) - controller->line->last_connect_attempt) > controller->connect_poll_interval) + { + char hostport[CBUFSIZE]; + + controller->line->transmit_is_loopback = is_loopback; + + controller->line->last_connect_attempt = time(NULL); + if (is_loopback) + sprintf(hostport, "localhost:%s", controller->line->receive_port); + else + sprintf(hostport, "%s", controller->line->transmit_host); + sim_debug(DBG_SOK, controller->device, "Trying to open transmit socket to address:port %s\n", hostport); + controller->line->socket = sim_connect_sock(hostport, NULL, NULL); + if (controller->line->socket != INVALID_SOCKET) + { + sim_debug(DBG_SOK, controller->device, "Opened transmit socket to port %d, socket %d\n", hostport, controller->line->socket); + controller->line->transmit_writeable = FALSE; + } + } + + if (controller->line->socket != INVALID_SOCKET) + { + int writeable = sim_check_conn(controller->line->socket, forRead); + if (writeable == 0) /* Still opening */ + { + //sim_debug(DBG_SOK, controller->device, "Waiting for transmit socket to become writeable\n"); + ans = 0; + } + else if (writeable == -1) /* Failed to open */ + { + dmc_close_transmit(controller, "failed to connect"); + ans = 0; + } + else /* connected */ + { + if (!controller->line->transmit_writeable) + { + sim_debug(DBG_CON, controller->device, "Transmit socket is now writeable\n"); + } + controller->line->transmit_writeable = TRUE; + ans = 1; + } + } + + return ans; +} + +void dmc_close_receive(CTLR *controller, char *reason) +{ + sim_debug(DBG_SOK, controller->device, "Closing receive socket on port %d, socket %d, reason: %s\n", controller->line->receive_port, controller->line->socket, reason); + sim_close_sock(controller->line->socket, FALSE); + controller->line->socket = INVALID_SOCKET; + + if (controller->line->receive_readable) + { + sim_debug(DBG_CON, controller->device, "Readable receive socket closed, reason: %s\n", reason); + } + controller->line->receive_readable = FALSE; +} + +void dmc_error_and_close_receive(CTLR *controller, char *format) +{ + int err = WSAGetLastError(); + char errmsg[80]; + sprintf(errmsg, format, err); + if (controller->line->isPrimary) + { + dmc_close_transmit(controller, errmsg); + } + else + { + dmc_close_receive(controller, errmsg); + } +} + +void dmc_close_transmit(CTLR *controller, char *reason) +{ + sim_debug(DBG_SOK, controller->device, "Closing transmit socket to port %s, socket %d, reason: %s\n", controller->line->transmit_host, controller->line->socket, reason); + sim_close_sock(controller->line->socket, FALSE); + controller->line->socket = INVALID_SOCKET; + + if (controller->line->transmit_writeable) + { + sim_debug(DBG_CON, controller->device, "Writeable transmit socket closed, reason: %s\n", reason); + } + controller->line->transmit_writeable = FALSE; +} + +/* returns true if some data was received */ +int dmc_buffer_fill_receive_buffers(CTLR *controller) +{ + int ans = FALSE; + int socket; + if (controller->state == Initialised) + { + /* accept any inbound connection but just throw away any data */ + if (dmc_get_socket(controller, TRUE)) + { + char buffer[1000]; + int bytes_read = 0; + socket = controller->line->socket; + bytes_read = sim_read_sock(socket, buffer, sizeof(buffer)); + if (bytes_read < 0) + { +printf("Socket error was when trying to fill receive buffers when controller initialised.\n"); + //dmc_error_and_close_receive(controller, "read error, code=%d"); + } + else if (bytes_read > 0) + { + sim_debug(DBG_SOK, controller->device, "Discarding received data while controller is not running\n"); + } + } + } + else + { + BUFFER *buffer = dmc_buffer_queue_find_first_available(controller->receive_queue); + while (buffer != NULL && buffer->state == Available) + { + if (dmc_get_socket(controller, TRUE)) + { + int bytes_read = 0; + int lost_data = 0; + + socket = controller->line->socket; + /* read block length and allocate buffer */ + if (buffer->block_len_bytes_read < sizeof(buffer->actual_block_len)) + { + char *start_addr = ((char *)&buffer->actual_block_len) + buffer->block_len_bytes_read; + bytes_read = sim_read_sock(socket, start_addr, sizeof(buffer->actual_block_len) - buffer->block_len_bytes_read); + if (bytes_read >= 0) + { + buffer->block_len_bytes_read += bytes_read; + if (buffer->block_len_bytes_read == sizeof(buffer->actual_block_len)) + { + buffer->actual_block_len = ntohs(buffer->actual_block_len); + if (buffer->actual_block_len > buffer->count) + { + sim_debug(DBG_WRN, controller->device, "LOST DATA, buffer available has %d bytes, but the block is %d bytes\n", buffer->count, buffer->actual_block_len); + dmc_setreg(controller, 4, 0, 0); + dmc_setreg(controller, 6, 0, 0); + dmc_set_lost_data(controller); + dmc_start_control_output_transfer(controller); + lost_data = 1; + } + + if (buffer->actual_block_len > 0) + { + buffer->transfer_buffer = (uint8 *)malloc(buffer->actual_block_len); /* read full buffer regardless, so bad buffer is flushed */ + } + } + } + else + { +//printf("Socket error was when trying to read the header.\n"); + } + } + else + { + lost_data = buffer->actual_block_len > buffer->count; /* need to preserve this variable if need more than one attempt to read the buffer */ + } + + /* read the actual block */ + if (buffer->block_len_bytes_read == sizeof(buffer->actual_block_len)) + { + bytes_read = 0; + if (buffer->actual_block_len > 0) + { + int bytes_to_read = dmc_line_speed_calculate_byte_length(controller->line->bytes_received_in_last_second, buffer->actual_block_len - buffer->actual_bytes_transferred, controller->line->speed); + if (bytes_to_read > 0) + { + bytes_read = sim_read_sock(controller->line->socket, buffer->transfer_buffer + buffer->actual_bytes_transferred, bytes_to_read); + } + } + + if (bytes_read >= 0) + { + buffer->actual_bytes_transferred += bytes_read; + controller->line->bytes_received_in_last_second += bytes_read; + + if (buffer->actual_bytes_transferred >= buffer->actual_block_len) + { + dmc_buffer_trace(controller, buffer->transfer_buffer, buffer->actual_bytes_transferred, "REC "); + controller->buffers_received_from_net++; + buffer->state = ContainsData; + if (!lost_data) + { + Map_WriteB(buffer->address, buffer->actual_bytes_transferred, buffer->transfer_buffer); + } + else + { + buffer->actual_block_len = 0; /* so an empty buffer is returned to the driver */ + } + + if (buffer->actual_block_len > 0) + { + free(buffer->transfer_buffer); + buffer->transfer_buffer = NULL; + } + + ans = TRUE; + } + } + else + { +printf("Socket error was when trying to fill receive buffers when trying to read the body.\n"); + } + } + + /* Only close the socket if there was an error or no more data */ + if (bytes_read < 0) + { + dmc_error_and_close_receive(controller, "read error, code=%d"); + break; + } + + /* if buffer is incomplete do not try to read any more buffers and continue filling this one later */ + if (buffer->state == Available) + { + break; /* leave buffer available and continue filling it later */ + } + } + else + { + break; + } + + buffer = buffer ->next; + } + } + + return ans; +} + +/* returns true if some data was actually sent */ +int dmc_buffer_send_transmit_buffers(CTLR *controller) +{ + int ans = FALSE; + int socket; + /* when transmit buffer is queued it is marked as available, not as ContainsData */ + BUFFER *buffer = dmc_buffer_queue_find_first_available(controller->transmit_queue); + while (buffer != NULL) + { + if (dmc_get_socket(controller, FALSE)) // TODO: , buffer->is_loopback); + { + int bytes = 0; + uint16 block_len; + int total_buffer_len = (buffer->count > 0) ? buffer->count + sizeof(block_len) : 0; + + socket = controller->line->socket; + /* only send the buffer if it actually has some data, sometimes get zero length buffers - don't send these */ + if (total_buffer_len > 0) + { + if (buffer->actual_bytes_transferred <= 0) + { + /* construct buffer and include block length bytes */ + buffer->transfer_buffer = (uint8 *)malloc(total_buffer_len); + block_len = htons(buffer->count); + memcpy(buffer->transfer_buffer, (char *)&block_len, sizeof(block_len)); + Map_ReadB(buffer->address, buffer->count, buffer->transfer_buffer + sizeof(block_len)); + } + + bytes = sim_write_sock (controller->line->socket, buffer->transfer_buffer + buffer->actual_bytes_transferred, buffer->count + sizeof(block_len) - buffer->actual_bytes_transferred); + if (bytes >= 0) + { + buffer->actual_bytes_transferred += bytes; + } + + if (buffer->actual_bytes_transferred >= total_buffer_len || bytes < 0) + { + dmc_buffer_trace(controller, buffer->transfer_buffer+sizeof(block_len), buffer->count, "TRAN"); + free(buffer->transfer_buffer); + } + } + + if (buffer->actual_bytes_transferred >= total_buffer_len) + { + controller->buffers_transmitted_to_net++; + buffer->state = ContainsData; // so won't try to transmit again + ans = TRUE; + } + else if (bytes < 0) + { + int err = WSAGetLastError (); + char errmsg[80]; + sprintf(errmsg, "write failure, code=%d", err); + + dmc_close_transmit(controller, errmsg); + break; + } + else + { + break; /* poll again later to send more bytes */ + } + + } + else + { + break; + } + + buffer = buffer ->next; + } + + return ans; +} + +void dmc_start_transfer_receive_buffer(CTLR *controller) +{ + BUFFER *head = dmc_buffer_queue_head(controller->receive_queue); + if (head != NULL) + { + if (head->state == ContainsData) + { + head->state = TransferInProgress; + dmc_start_data_output_transfer(controller, head->address, head->actual_block_len, TRUE); + } + } +} + +void dmc_start_transfer_transmit_buffer(CTLR *controller) +{ + BUFFER *head = dmc_buffer_queue_head(controller->transmit_queue); + if (head != NULL) + { + if (head->state == ContainsData) + { + head->state = TransferInProgress; + dmc_start_data_output_transfer(controller, head->address, head->count, FALSE); + } + } +} + +void dmc_check_for_output_transfer_completion(CTLR *controller) +{ + if (!dmc_is_rdyo_set(controller)) + { + sim_debug(DBG_INF, controller->device, "Output transfer completed\n"); + controller->transfer_state = Idle; + if (dmc_get_output_transfer_type(controller) == TYPE_BACCO) + { + if (dmc_is_out_io_set(controller)) + { + dmc_buffer_queue_release_head(controller->receive_queue); + controller->receive_buffer_output_transfers_completed++; + } + else + { + dmc_buffer_queue_release_head(controller->transmit_queue); + controller->transmit_buffer_output_transfers_completed++; + } + } + dmc_process_command(controller); // check for any input transfers + } +} + +void dmc_process_input_transfer_completion(CTLR *controller) +{ + if (dmc_is_dmc(controller)) + { + if (!dmc_is_rqi_set(controller)) + { + uint16 sel4 = controller->csrs->sel4; + uint16 sel6 = controller->csrs->sel6; + dmc_clear_rdyi(controller); + //dmc_clrrxint(); + if (controller->transfer_type == TYPE_BASEI) + { + //int i; + uint32 baseaddr = sel6 >> 14 | sel4; + uint16 count = sel6 & 0x3FFF; + sim_debug(DBG_INF, controller->device, "Completing Base In input transfer, base address=0x%08x count=%d\n", baseaddr, count); + //for (i = 0; i < count; i++) + //{ + // uint8 t = ((uint8)i + 1)*2; + // Map_WriteB(baseaddr + i, 1, &t); + //} + } + else if (controller->transfer_type == TYPE_BACCI) + { + uint32 addr = sel6 >> 14 | sel4; + uint16 count = sel6 & 0x3FFF; + if (controller->transfer_in_io != dmc_is_in_io_set(controller)) + { + sim_debug(DBG_TRC, controller->device, "IN IO MISMATCH\n"); + } + + controller->transfer_in_io = dmc_is_in_io_set(controller); // using evdmc the flag is set when the transfer completes - not when it starts, evdca seems to set in only at the start of the transfer - clearing it when it completes + controller->state = Running; + if (controller->transfer_in_io) + { + dmc_buffer_queue_add(controller->receive_queue, addr, count); + dmc_buffer_fill_receive_buffers(controller); + controller->receive_buffer_input_transfers_completed++; + } + else + { + dmc_buffer_queue_add(controller->transmit_queue, addr, count); + dmc_buffer_send_transmit_buffers(controller); + controller->transmit_buffer_input_transfers_completed++; + } + } + + controller->transfer_state = Idle; + } + } + else + { + if (!dmc_is_rdyi_set(controller)) + { + uint16 sel4 = controller->csrs->sel4; + uint16 sel6 = controller->csrs->sel6; + //dmc_clrrxint(); + if (controller->transfer_type == TYPE_DMP_MODE) + { + uint16 mode = sel6 & DMP_TYPE_INPUT_MASK; + char * duplex = (mode & 1) ? "Full-Duplex" : "Half-Duplex"; + char * config; + if (mode & 4) + { + config = "Point-to-point"; + } + else + { + config = (mode & 2) ? "Tributary station" : "Control Station"; + } + + sim_debug(DBG_INF, controller->device, "Completing Mode input transfer, %s %s\n", duplex, config); + } + else if (controller->transfer_type == TYPE_DMP_CONTROL) + { + sim_debug(DBG_WRN, controller->device, "Control command (not processed yet)\n"); + } + else if (controller->transfer_type == TYPE_DMP_RECEIVE) + { + sim_debug(DBG_WRN, controller->device, "Receive Buffer command (not processed yet)\n"); + } + else if (controller->transfer_type == TYPE_DMP_TRANSMIT) + { + sim_debug(DBG_WRN, controller->device, "Transmit Buffer command (not processed yet)\n"); + } + else + { + sim_debug(DBG_WRN, controller->device, "Unrecognised command code %hu\n", controller->transfer_type); + } + + controller->transfer_state = Idle; + } + } +} + +void dmc_process_command(CTLR *controller) +{ + if (dmc_is_master_clear_set(controller)) + { + dmc_process_master_clear(controller); + } + else + { + if (controller->transfer_state == InputTransfer) + { + dmc_process_input_transfer_completion(controller); + } + else if (controller->transfer_state == OutputTransfer) + { + dmc_check_for_output_transfer_completion(controller); + } + else if (dmc_is_rqi_set(controller)) + { + dmc_start_input_transfer(controller); + } + } +} + +t_stat dmc_rd(int32 *data, int32 PA, int32 access) +{ + CTLR *controller = dmc_get_controller_from_address(PA); + int reg = PA & 07; + sim_debug(DBG_TRC, controller->device, "dmc_rd(), addr=0x%x access=%d\n", PA, access); + *data = dmc_getreg(controller, PA, 1); + + return SCPE_OK; +} + +t_stat dmc_wr(int32 data, int32 PA, int32 access) +{ + CTLR *controller = dmc_get_controller_from_address(PA); + int reg = PA & 07; + uint16 oldValue = dmc_getreg(controller, PA, 0); + if (access == WRITE) + { + sim_debug(DBG_TRC, controller->device, "dmc_wr(), addr=0x%08x, SEL%d, data=0x%04x\n", PA, reg, data); + } + else + { + sim_debug(DBG_TRC, controller->device, "dmc_wr(), addr=0x%08x, BSEL%d, data=%04x\n", PA, reg, data); + } + + if (access == WRITE) + { + if (PA & 1) + sim_debug(DBG_WRN, controller->device, "dmc_wr(), Unexpected non-16-bit write access to SEL%d\n", reg); + dmc_setreg(controller, PA, data, 1); + } + else + { + uint16 mask; + if (PA & 1) + { + mask = 0xFF00; + data = data << 8; + } + else + { + mask = 0x00FF; + } + + dmc_setreg(controller, PA, (oldValue & ~mask) | (data & mask), 1); + } + + if (dmc_getsel(reg) == 0 || dmc_getsel(reg) == 1) + { + dmc_process_command(controller); + } + + return SCPE_OK; +} + +int32 dmc_rxint (void) +{ + int i; + int32 ans = 0; /* no interrupt request active */ + for (i=0; irxi != 0) + { + DIB *dib = (DIB *)controller->device->ctxt; + ans = dib->vec; + dmc_clrrxint(controller); + break; + } + } + + return ans; + } + +int32 dmc_txint (void) +{ + int i; + int32 ans = 0; /* no interrupt request active */ + for (i=0; itxi != 0) + { + DIB *dib = (DIB *)controller->device->ctxt; + ans = dib->vec + 4; + dmc_clrtxint(controller); + break; + } + } + + return ans; + + //int32 ans = 0; /* no interrupt request active */ + //if (controller->txi != 0) + //{ + // DIB *dib = (DIB *)controller->device->ctxt; + // ans = dib->vec + 4; + // dmc_clrtxint(); + //} + + //return ans; +} + +t_stat dmc_reset (DEVICE *dptr) +{ + t_stat ans = SCPE_OK; + //int32 ndev; + CTLR *controller = dmc_get_controller_from_device(dptr); + + sim_debug(DBG_TRC, dptr, "dmc_reset()\n"); + + if (dmc_get_unit_stats(dptr->units) == NULL) + { + dmc_set_unit_stats(dptr->units, (UNIT_STATS *)malloc(sizeof(UNIT_STATS))); + dmc_reset_unit_stats(dmc_get_unit_stats(dptr->units)); + } + + dmc_clrrxint(controller); + dmc_clrtxint(controller); + sim_cancel (controller->device->units); /* stop poll */ + if (controller->svc_poll_interval == -1) controller->svc_poll_interval = POLL; + + if (!(dptr->flags & DEV_DIS)) + { + ans = auto_config (dptr->name, DMC_UNITSPERDEVICE); + } + return ans; +} + +t_stat dmc_attach (UNIT *uptr, char *cptr) +{ + CTLR *controller = dmc_get_controller_from_unit(uptr); + t_stat ans = SCPE_OK; + + ans = dmc_open_master_socket(controller, cptr); + if (ans == SCPE_OK) + { + controller->line->socket = INVALID_SOCKET; + uptr->flags = uptr->flags | UNIT_ATT; /* set unit attached flag */ + uptr->filename = (char *)malloc(strlen(cptr)+1); + strcpy(uptr->filename, cptr); + controller->line->receive_port = uptr->filename; + } + + return ans; +} + +t_stat dmc_detach (UNIT *uptr) +{ + CTLR *controller = dmc_get_controller_from_unit(uptr); + dmc_close_master_socket(controller); + uptr->flags = uptr->flags & ~UNIT_ATT; /* clear unit attached flag */ + free(uptr->filename); + uptr->filename = NULL; + + return SCPE_OK; +} + diff --git a/PDP11/pdp11_dmc.h b/PDP11/pdp11_dmc.h new file mode 100644 index 00000000..3984960c --- /dev/null +++ b/PDP11/pdp11_dmc.h @@ -0,0 +1,132 @@ +/* pdp11_dmc.h: DMC11 Emulation + ------------------------------------------------------------------------------ + + Copyright (c) 2011, Robert M. A. Jarratt + + 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 + THE AUTHOR 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 the author shall not be + used in advertising or otherwise to promote the sale, use or other dealings + in this Software without prior written authorization from the author. + + ------------------------------------------------------------------------------*/ + +// Notes +// Base address needs to be 760060 according to DMC11 manual, but SYSGEN seems to think CSR is 0760100. However if I use +// 0760100 I get a conflict with the DZ because the first 13 bits are still 00100. If I use 760060 VMS sees the XM device, but +// if I remove the DZ to prevent the conflict VMS does not see an XM device, but I do get lots of reads and writes, possibly +// because it thinks it is a different device. What worries me more though is that there seems to be overlap in the 13-bit base +// addresses of the DZ and DMC. + + +#ifndef _PDP11_DMC_H +#define _PDP11_DMC_H + +#if defined (VM_VAX) /* VAX version */ +#include "vax_defs.h" +extern int32 int_req[IPL_HLVL]; +#else /* PDP-11 version */ +#include "pdp11_defs.h" +extern int32 int_req[IPL_HLVL]; +#endif + +#include "sim_sock.h" + +#define DMC_NUMDEVICE 4 /* # DMC-11 devices */ +#define DMC_UNITSPERDEVICE 1 /* # units per DMC-11 */ + +#define DMP_NUMDEVICE 1 /* # DMP-11 devices */ +#define DMP_UNITSPERDEVICE 1 /* # units per DMP-11 */ + +#define DMC_RDX 8 + +/* debugging bitmaps */ +#define DBG_TRC 0x0001 /* trace routine calls */ +#define DBG_REG 0x0002 /* trace read/write registers */ +#define DBG_WRN 0x0004 /* display warnings */ +#define DBG_INF 0x0008 /* display informational messages (high level trace) */ +#define DBG_DAT 0x0010 /* display data buffer contents */ +#define DBG_DTS 0x0020 /* display data summary */ +#define DBG_SOK 0x0040 /* display socket open/close */ +#define DBG_CON 0x0080 /* display socket connection establishment */ + +#define TYPE_BACCI 0 +#define TYPE_CNTLI 1 +#define TYPE_BASEI 03 +#define TYPE_BACCO 0 +#define TYPE_CNTLO 1 + +#define TYPE_DMP_MODE 2 +#define TYPE_DMP_CONTROL 1 +#define TYPE_DMP_RECEIVE 0 +#define TYPE_DMP_TRANSMIT 4 + + +/* SEL0 */ +#define DMC_TYPE_INPUT_MASK 0x0003 +#define DMC_IN_IO_MASK 0x0004 +#define DMP_IEO_MASK 0x0010 +#define DMC_RQI_MASK 0x0020 +#define DMP_RQI_MASK 0x0080 +#define DMC_RDYI_MASK 0x0080 +#define DMC_IEI_MASK 0x0040 +#define DMP_IEI_MASK 0x0001 +#define LU_LOOP_MASK 0x0800 +#define MASTER_CLEAR_MASK 0x4000 +#define RUN_MASK 0x8000 + +/* SEL2 */ +#define DMP_IN_IO_MASK 0x0004 +#define DMP_TYPE_INPUT_MASK 0x0007 +#define TYPE_OUTPUT_MASK 0x0003 +#define OUT_IO_MASK 0x0004 +#define DMC_RDYO_MASK 0x0080 +#define DMC_IEO_MASK 0x0040 +#define DMP_RDYI_MASK 0x0010 + +/* BSEL6 */ +#define LOST_DATA_MASK 0x0010 +#define DISCONNECT_MASK 0x0040 + +#define SEL0_RUN_BIT 15 +#define SEL0_MCLR_BIT 14 +#define SEL0_LU_LOOP_BIT 11 +#define SEL0_RDI_BIT 7 +#define SEL0_DMC_IEI_BIT 6 +#define SEL0_DMP_IEI_BIT 0 +#define SEL0_DMP_IEO_BIT 4 +#define SEL0_DMC_RQI_BIT 5 +#define SEL0_DMP_RQI_BIT 7 +#define SEL0_IN_IO_BIT 2 +#define SEL0_TYPEI_BIT 0 + +#define SEL2_TYPEO_BIT 0 +#define SEL2_RDO_BIT 7 +#define SEL2_IEO_BIT 6 +#define SEL2_OUT_IO_BIT 2 +#define SEL2_LINE_BIT 8 +#define SEL2_LINE_BIT_LENGTH 6 +#define SEL2_PRIO_BIT 14 +#define SEL2_PRIO_BIT_LENGTH 2 + +#define SEL6_LOST_DATA_BIT 4 +#define SEL6_DISCONNECT_BIT 6 + +#define BUFFER_QUEUE_SIZE 7 + +#endif /* _VAX_DMC_H */ diff --git a/PDP11/pdp11_fp.c b/PDP11/pdp11_fp.c index 2d1db393..fe7c9660 100644 --- a/PDP11/pdp11_fp.c +++ b/PDP11/pdp11_fp.c @@ -438,7 +438,7 @@ switch ((IR >> 8) & 017) { /* decode IR<11:8> */ else fac.l = ReadI (GeteaFP (dstspec, leni), dstspec, leni); fac.h = 0; if (fac.l) { - if (sign = GET_SIGN_L (fac.l)) + if ((sign = GET_SIGN_L (fac.l))) fac.l = (fac.l ^ 0xFFFFFFFF) + 1; for (i = 0; GET_SIGN_L (fac.l) == 0; i++) fac.l = fac.l << 1; diff --git a/PDP11/pdp11_hk.c b/PDP11/pdp11_hk.c index 72aa9cfd..7d949d07 100644 --- a/PDP11/pdp11_hk.c +++ b/PDP11/pdp11_hk.c @@ -887,7 +887,7 @@ switch (fnc) { /* case on function */ err = fseek (uptr->fileref, da * sizeof (int16), SEEK_SET); if (uptr->FNC == FNC_WRITE) { /* write? */ if (hkcs2 & CS2_UAI) { /* no addr inc? */ - if (t = Map_ReadW (ba, 2, &comp)) { /* get 1st wd */ + if ((t = Map_ReadW (ba, 2, &comp))) { /* get 1st wd */ wc = 0; /* NXM, no xfr */ hkcs2 = hkcs2 | CS2_NEM; /* set nxm err */ } @@ -895,7 +895,7 @@ switch (fnc) { /* case on function */ hkxb[i] = comp; } else { /* normal */ - if (t = Map_ReadW (ba, wc << 1, hkxb)) { /* get buf */ + if ((t = Map_ReadW (ba, wc << 1, hkxb))) {/* get buf */ wc = wc - (t >> 1); /* NXM, adj wc */ hkcs2 = hkcs2 | CS2_NEM; /* set nxm err */ } @@ -915,13 +915,13 @@ switch (fnc) { /* case on function */ for ( ; i < wc; i++) /* fill buf */ hkxb[i] = 0; if (hkcs2 & CS2_UAI) { /* no addr inc? */ - if (t = Map_WriteW (ba, 2, &hkxb[wc - 1])) { + if ((t = Map_WriteW (ba, 2, &hkxb[wc - 1]))) { wc = 0; /* NXM, no xfr */ hkcs2 = hkcs2 | CS2_NEM; /* set nxm err */ } } else { /* normal */ - if (t = Map_WriteW (ba, wc << 1, hkxb)) { /* put buf */ + if ((t = Map_WriteW (ba, wc << 1, hkxb))) {/* put buf */ wc = wc - (t >> 1); /* NXM, adj wc */ hkcs2 = hkcs2 | CS2_NEM; /* set nxm err */ } diff --git a/PDP11/pdp11_io.c b/PDP11/pdp11_io.c index e5909413..9df2b78f 100644 --- a/PDP11/pdp11_io.c +++ b/PDP11/pdp11_io.c @@ -23,6 +23,7 @@ used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from Robert M Supnik. + 27-Mar-12 RMS Fixed order of int_internal (Jordi Guillaumes i Pons) 19-Mar-12 RMS Fixed declaration of cpu_opt (Mark Pizzolato) 12-Dec-11 RMS Fixed Qbus interrupts to treat all IO devices as BR4 19-Nov-08 RMS Moved I/O support routines to I/O library @@ -83,8 +84,8 @@ static const int32 pirq_bit[7] = { }; static const int32 int_internal[IPL_HLVL] = { - INT_INTERNAL7, INT_INTERNAL6, INT_INTERNAL5, INT_INTERNAL4, - INT_INTERNAL3, INT_INTERNAL2, INT_INTERNAL1, 0 + 0, INT_INTERNAL1, INT_INTERNAL2, INT_INTERNAL3, + INT_INTERNAL4, INT_INTERNAL5, INT_INTERNAL6, INT_INTERNAL7 }; /* I/O page lookup and linkage routines @@ -372,17 +373,17 @@ init_ubus_tab (); /* init Unibus tables */ init_mbus_tab (); /* init Massbus tables */ for (i = 0; i < 7; i++) /* seed PIRQ intr */ int_vec[i + 1][pirq_bit[i]] = VEC_PIRQ; -if (r = cpu_build_dib ()) /* build CPU entries */ +if ((r = cpu_build_dib ())) /* build CPU entries */ return r; for (i = 0; (dptr = sim_devices[i]) != NULL; i++) { /* loop thru dev */ dibp = (DIB *) dptr->ctxt; /* get DIB */ if (dibp && !(dptr->flags & DEV_DIS)) { /* defined, enabled? */ if (dptr->flags & DEV_MBUS) { /* Massbus? */ - if (r = build_mbus_tab (dptr, dibp)) /* add to Mbus tab */ + if ((r = build_mbus_tab (dptr, dibp))) /* add to Mbus tab */ return r; } else { /* no, Unibus */ - if (r = build_ubus_tab (dptr, dibp)) /* add to Unibus tab */ + if ((r = build_ubus_tab (dptr, dibp))) /* add to Unibus tab */ return r; } } /* end if enabled */ diff --git a/PDP11/pdp11_ke.c b/PDP11/pdp11_ke.c index 711c1c30..c82ddeef 100644 --- a/PDP11/pdp11_ke.c +++ b/PDP11/pdp11_ke.c @@ -252,7 +252,7 @@ switch (PA & 017) { /* decode PA<3:0> */ data = data & 077; /* 6b shift count */ if (data != 0) { t32 = (ke_AC << 16) | ke_MQ; /* 32b operand */ - if (sign = GET_SIGN_W (ke_AC)) /* sext operand */ + if ((sign = GET_SIGN_W (ke_AC))) /* sext operand */ t32 = t32 | ~017777777777; if (data < 32) { /* [1,31] - left */ sout = (t32 >> (32 - data)) | (-sign << data); @@ -282,7 +282,7 @@ switch (PA & 017) { /* decode PA<3:0> */ data = data & 077; /* 6b shift count */ if (data != 0) { t32 = (ke_AC << 16) | ke_MQ; /* 32b operand */ - if (sign = GET_SIGN_W (ke_AC)) /* sext operand */ + if ((sign = GET_SIGN_W (ke_AC))) /* sext operand */ t32 = t32 | ~017777777777; if (data < 32) { /* [1,31] - left */ sout = (t32 >> (31 - data)) | (-sign << data); diff --git a/PDP11/pdp11_mscp.h b/PDP11/pdp11_mscp.h index 9dd07c90..b000df7d 100644 --- a/PDP11/pdp11_mscp.h +++ b/PDP11/pdp11_mscp.h @@ -211,7 +211,7 @@ #define CMD_REFL 2 /* ref # */ #define CMD_REFH 3 #define CMD_UN 4 /* unit # */ -/* 5 /* reserved */ +/* 5 *//* reserved */ #define CMD_OPC 6 /* opcode */ #define CMD_MOD 7 /* modifier */ @@ -256,14 +256,14 @@ /* Flush - 10 W status (8 undefined) */ #define FLU_LNT 32 -/* 8 - 15 /* reserved */ +/* 8 - 15 *//* reserved */ #define FLU_POSL 16 /* position */ #define FLU_POSH 17 /* Write tape mark - 10W status (8 undefined) */ #define WTM_LNT 32 -/* 8 - 15 /* reserved */ +/* 8 - 15 *//* reserved */ #define WTM_POSL 16 /* position */ #define WTM_POSH 17 @@ -399,8 +399,8 @@ #define RW_BAH 11 #define RW_MAPL 12 /* map table */ #define RW_MAPH 13 -/* 14 /* reserved */ -/* 15 /* reserved */ +/* 14 *//* reserved */ +/* 15 *//* reserved */ /* Disk specific parameters */ diff --git a/PDP11/pdp11_rk.c b/PDP11/pdp11_rk.c index 5e37d54d..d870ca8f 100644 --- a/PDP11/pdp11_rk.c +++ b/PDP11/pdp11_rk.c @@ -545,13 +545,13 @@ if (wc && (err == 0)) { /* seek ok? */ rkxb[i] = 0; } if (rkcs & RKCS_INH) { /* incr inhibit? */ - if (t = Map_WriteW (ma, 2, &rkxb[wc - 1])) { /* store last */ + if ((t = Map_WriteW (ma, 2, &rkxb[wc - 1]))) {/* store last */ rker = rker | RKER_NXM; /* NXM? set flag */ wc = 0; /* no transfer */ } } else { /* normal store */ - if (t = Map_WriteW (ma, wc << 1, rkxb)) { /* store buf */ + if ((t = Map_WriteW (ma, wc << 1, rkxb))) { /* store buf */ rker = rker | RKER_NXM; /* NXM? set flag */ wc = wc - t; /* adj wd cnt */ } @@ -560,7 +560,7 @@ if (wc && (err == 0)) { /* seek ok? */ case RKCS_WRITE: /* write */ if (rkcs & RKCS_INH) { /* incr inhibit? */ - if (t = Map_ReadW (ma, 2, &comp)) { /* get 1st word */ + if ((t = Map_ReadW (ma, 2, &comp))) { /* get 1st word */ rker = rker | RKER_NXM; /* NXM? set flag */ wc = 0; /* no transfer */ } @@ -568,7 +568,7 @@ if (wc && (err == 0)) { /* seek ok? */ rkxb[i] = comp; } else { /* normal fetch */ - if (t = Map_ReadW (ma, wc << 1, rkxb)) { /* get buf */ + if ((t = Map_ReadW (ma, wc << 1, rkxb))) { /* get buf */ rker = rker | RKER_NXM; /* NXM? set flg */ wc = wc - t; /* adj wd cnt */ } @@ -584,7 +584,7 @@ if (wc && (err == 0)) { /* seek ok? */ case RKCS_WCHK: /* write check */ i = fxread (rkxb, sizeof (int16), wc, uptr->fileref); - if (err = ferror (uptr->fileref)) { /* read error? */ + if ((err = ferror (uptr->fileref))) { /* read error? */ wc = 0; /* no transfer */ break; } diff --git a/PDP11/pdp11_rq.c b/PDP11/pdp11_rq.c index d1201983..e96c667b 100644 --- a/PDP11/pdp11_rq.c +++ b/PDP11/pdp11_rq.c @@ -894,7 +894,7 @@ UNIT rqb_unit[] = { (RD54_DTYPE << UNIT_V_DTYPE), RQ_SIZE (RD54)) }, { UDATA (&rq_svc, UNIT_FIX+UNIT_ATTABLE+UNIT_DISABLE+UNIT_ROABLE+ (RD54_DTYPE << UNIT_V_DTYPE), RQ_SIZE (RD54)) }, - { UDATA (&rq_tmrsvc, UNIT_DIS, 0) }, + { UDATA (&rq_tmrsvc, UNIT_IDLE|UNIT_DIS, 0) }, { UDATA (&rq_quesvc, UNIT_DIS, 0) } }; @@ -966,7 +966,7 @@ UNIT rqc_unit[] = { (RD54_DTYPE << UNIT_V_DTYPE), RQ_SIZE (RD54)) }, { UDATA (&rq_svc, UNIT_FIX+UNIT_ATTABLE+UNIT_DISABLE+UNIT_ROABLE+ (RD54_DTYPE << UNIT_V_DTYPE), RQ_SIZE (RD54)) }, - { UDATA (&rq_tmrsvc, UNIT_DIS, 0) }, + { UDATA (&rq_tmrsvc, UNIT_IDLE|UNIT_DIS, 0) }, { UDATA (&rq_quesvc, UNIT_DIS, 0) } }; @@ -1038,7 +1038,7 @@ UNIT rqd_unit[] = { (RD54_DTYPE << UNIT_V_DTYPE), RQ_SIZE (RD54)) }, { UDATA (&rq_svc, UNIT_FIX+UNIT_ATTABLE+UNIT_DISABLE+UNIT_ROABLE+ (RD54_DTYPE << UNIT_V_DTYPE), RQ_SIZE (RD54)) }, - { UDATA (&rq_tmrsvc, UNIT_DIS, 0) }, + { UDATA (&rq_tmrsvc, UNIT_IDLE|UNIT_DIS, 0) }, { UDATA (&rq_quesvc, UNIT_DIS, 0) } }; @@ -1442,7 +1442,7 @@ DEVICE *dptr = rq_devmap[cp->cnum]; sim_debug (DBG_TRC, rq_devmap[cp->cnum], "rq_abo\n"); tpkt = 0; /* set no mtch */ -if (uptr = rq_getucb (cp, lu)) { /* get unit */ +if ((uptr = rq_getucb (cp, lu))) { /* get unit */ if (uptr->cpkt && /* curr pkt? */ (GETP32 (uptr->cpkt, CMD_REFL) == ref)) { /* match ref? */ tpkt = uptr->cpkt; /* save match */ @@ -1455,8 +1455,8 @@ if (uptr = rq_getucb (cp, lu)) { /* get unit */ tpkt = uptr->pktq; /* save match */ uptr->pktq = cp->pak[tpkt].link; /* unlink */ } - else if (prv = uptr->pktq) { /* srch pkt q */ - while (tpkt = cp->pak[prv].link) { /* walk list */ + else if ((prv = uptr->pktq)) { /* srch pkt q */ + while ((tpkt = cp->pak[prv].link)) { /* walk list */ if (GETP32 (tpkt, RSP_REFL) == ref) { /* match? unlink */ cp->pak[prv].link = cp->pak[tpkt].link; break; @@ -1486,7 +1486,7 @@ UNIT *uptr; sim_debug (DBG_TRC, rq_devmap[cp->cnum], "rq_avl\n"); -if (uptr = rq_getucb (cp, lu)) { /* unit exist? */ +if ((uptr = rq_getucb (cp, lu))) { /* unit exist? */ if (q && uptr->cpkt) { /* need to queue? */ rq_enqt (cp, &uptr->pktq, pkt); /* do later */ return OK; @@ -1546,7 +1546,7 @@ if (cp->pak[pkt].d[CMD_MOD] & MD_NXU) { /* next unit? */ cp->pak[pkt].d[RSP_UN] = lu; } } -if (uptr = rq_getucb (cp, lu)) { /* unit exist? */ +if ((uptr = rq_getucb (cp, lu))) { /* unit exist? */ if ((uptr->flags & UNIT_ATT) == 0) /* not attached? */ sts = ST_OFL | SB_OFL_NV; /* offl no vol */ else if (uptr->flags & UNIT_ONL) /* online */ @@ -1583,7 +1583,7 @@ UNIT *uptr; sim_debug (DBG_TRC, rq_devmap[cp->cnum], "rq_onl\n"); -if (uptr = rq_getucb (cp, lu)) { /* unit exist? */ +if ((uptr = rq_getucb (cp, lu))) { /* unit exist? */ if (q && uptr->cpkt) { /* need to queue? */ rq_enqt (cp, &uptr->pktq, pkt); /* do later */ return OK; @@ -1626,7 +1626,7 @@ else { cmd = GETP (pkt, CMD_OPC, OPC); /* get opcode */ cp->cflgs = (cp->cflgs & CF_RPL) | /* hack ctrl flgs */ cp->pak[pkt].d[SCC_CFL]; - if (cp->htmo = cp->pak[pkt].d[SCC_TMO]) /* set timeout */ + if ((cp->htmo = cp->pak[pkt].d[SCC_TMO])) /* set timeout */ cp->htmo = cp->htmo + 2; /* if nz, round up */ cp->pak[pkt].d[SCC_CFL] = cp->cflgs; /* return flags */ cp->pak[pkt].d[SCC_TMO] = RQ_DCTMO; /* ctrl timeout */ @@ -1655,7 +1655,7 @@ UNIT *uptr; sim_debug (DBG_TRC, rq_devmap[cp->cnum], "rq_suc\n"); -if (uptr = rq_getucb (cp, lu)) { /* unit exist? */ +if ((uptr = rq_getucb (cp, lu))) { /* unit exist? */ if (q && uptr->cpkt) { /* need to queue? */ rq_enqt (cp, &uptr->pktq, pkt); /* do later */ return OK; @@ -1686,7 +1686,7 @@ UNIT *uptr; sim_debug (DBG_TRC, rq_devmap[cp->cnum], "rq_fmt\n"); -if (uptr = rq_getucb (cp, lu)) { /* unit exist? */ +if ((uptr = rq_getucb (cp, lu))) { /* unit exist? */ if (q && uptr->cpkt) { /* need to queue? */ rq_enqt (cp, &uptr->pktq, pkt); /* do later */ return OK; @@ -1722,7 +1722,7 @@ UNIT *uptr; sim_debug (DBG_TRC, rq_devmap[cp->cnum], "rq_rw(lu=%d, pkt=%d, queue=%s)\n", lu, pkt, q?"yes" : "no"); -if (uptr = rq_getucb (cp, lu)) { /* unit exist? */ +if ((uptr = rq_getucb (cp, lu))) { /* unit exist? */ if (q && uptr->cpkt) { /* need to queue? */ sim_debug (DBG_TRC, rq_devmap[cp->cnum], "rq_rw - queued\n"); rq_enqt (cp, &uptr->pktq, pkt); /* do later */ @@ -1769,7 +1769,7 @@ if (bc & 1) /* odd byte cnt? */ return (ST_HST | SB_HST_OC); if (bc & 0xF0000000) /* 'reasonable' bc? */ return (ST_CMD | I_BCNT); -/* if (lbn & 0xF0000000) return (ST_CMD | I_LBN); /* 'reasonable' lbn? */ +/* if (lbn & 0xF0000000) return (ST_CMD | I_LBN); *//* 'reasonable' lbn? */ if (lbn >= maxlbn) { /* accessing RCT? */ if (lbn >= (maxlbn + drv_tab[dtyp].rcts)) /* beyond copy 1? */ return (ST_CMD | I_LBN); /* lbn err */ @@ -1854,7 +1854,7 @@ if (!uptr->io_complete) { /* Top End (I/O Initiation) Processing */ else if (cmd == OP_WR) { /* write? */ t = Map_ReadW (ba, tbc, uptr->rqxb); /* fetch buffer */ - if (abc = tbc - t) { /* any xfer? */ + if ((abc = tbc - t)) { /* any xfer? */ wwc = ((abc + (RQ_NUMBY - 1)) & ~(RQ_NUMBY - 1)) >> 1; for (i = (abc >> 1); i < wwc; i++) ((uint16 *)(uptr->rqxb))[i] = 0; @@ -1889,7 +1889,7 @@ else { /* Bottom End (After I/O processing) */ else { sim_disk_data_trace(uptr, uptr->rqxb, bl, tbc, "sim_disk_rdsect", DBG_DAT & rq_devmap[cp->cnum]->dctrl, DBG_REQ); if ((cmd == OP_RD) && !err) { /* read? */ - if (t = Map_WriteW (ba, tbc, uptr->rqxb)) { /* store, nxm? */ + if ((t = Map_WriteW (ba, tbc, uptr->rqxb))) {/* store, nxm? */ PUTP32 (pkt, RW_WBCL, bc - (tbc - t)); /* adj bc */ PUTP32 (pkt, RW_WBAL, ba + (tbc - t)); /* adj ba */ if (rq_hbe (cp, uptr)) /* post err log */ @@ -2746,11 +2746,11 @@ if ((uptr->flags & UNIT_ONL) == 0) { if (uptr->cpkt) { fprintf (st, "Unit %d current ", u); rq_show_pkt (st, cp, uptr->cpkt); - if (pkt = uptr->pktq) { + if ((pkt = uptr->pktq)) { do { fprintf (st, "Unit %d queued ", u); rq_show_pkt (st, cp, pkt); - } while (pkt = cp->pak[pkt].link); + } while ((pkt = cp->pak[pkt].link)); } } else fprintf (st, "Unit %d queues are empty\n", u); @@ -2777,7 +2777,7 @@ if (val & RQ_SH_RI) { rq_show_ring (st, &cp->rq); } if (val & RQ_SH_FR) { - if (pkt = cp->freq) { + if ((pkt = cp->freq)) { for (i = 0; pkt != 0; i++, pkt = cp->pak[pkt].link) { if (i == 0) fprintf (st, "Free queue = %d", pkt); @@ -2790,11 +2790,11 @@ if (val & RQ_SH_FR) { else fprintf (st, "Free queue is empty\n"); } if (val & RQ_SH_RS) { - if (pkt = cp->rspq) { + if ((pkt = cp->rspq)) { do { fprintf (st, "Response "); rq_show_pkt (st, cp, pkt); - } while (pkt = cp->pak[pkt].link); + } while ((pkt = cp->pak[pkt].link)); } else fprintf (st, "Response queue is empty\n"); } diff --git a/PDP11/pdp11_sys.c b/PDP11/pdp11_sys.c index 16ca83b4..b0b358cf 100644 --- a/PDP11/pdp11_sys.c +++ b/PDP11/pdp11_sys.c @@ -1,6 +1,6 @@ /* pdp11_sys.c: PDP-11 simulator interface - Copyright (c) 1993-2008, Robert M Supnik + Copyright (c) 1993-2012, Robert M Supnik Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), @@ -23,6 +23,7 @@ used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from Robert M Supnik. + 29-Apr-12 RMS Fixed compiler warning (Mark Pizzolato) 19-Nov-08 RMS Moved I/O support routines to I/O library 15-May-08 RMS Added KE11-A, DC11 support Renamed DL11 @@ -992,7 +993,7 @@ switch (j) { /* case on class */ disp = (disp - addr) & 0177777; else return SCPE_ARG; } - if ((disp & 1) || (disp > 0400) && (disp < 0177402)) + if ((disp & 1) || ((disp > 0400) && (disp < 0177402))) return SCPE_ARG; val[0] = val[0] | (((disp - 2) >> 1) & 0377); break; diff --git a/PDP11/pdp11_ta.c b/PDP11/pdp11_ta.c index 822a2a30..f777eff9 100644 --- a/PDP11/pdp11_ta.c +++ b/PDP11/pdp11_ta.c @@ -397,13 +397,13 @@ switch (uptr->FNC) { /* case on function */ case TACS_WRITE|TACS_3RD: /* write CRC */ if (ta_bptr) { /* anything to write? */ - if (st = sim_tape_wrrecf (uptr, ta_xb, ta_bptr)) /* write, err? */ + if ((st = sim_tape_wrrecf (uptr, ta_xb, ta_bptr)))/* write, err? */ r = ta_map_err (uptr, st); /* map error */ } break; /* op done */ case TACS_WFG: /* write file gap */ - if (st = sim_tape_wrtmk (uptr)) /* write tmk, err? */ + if ((st = sim_tape_wrtmk (uptr))) /* write tmk, err? */ r = ta_map_err (uptr, st); /* map error */ break; @@ -413,7 +413,7 @@ switch (uptr->FNC) { /* case on function */ break; case TACS_SRB: /* space rev blk */ - if (st = sim_tape_sprecr (uptr, &tbc)) /* space rev, err? */ + if ((st = sim_tape_sprecr (uptr, &tbc))) /* space rev, err? */ r = ta_map_err (uptr, st); /* map error */ break; @@ -425,7 +425,7 @@ switch (uptr->FNC) { /* case on function */ break; case TACS_SFB: /* space fwd blk */ - if (st = sim_tape_sprecf (uptr, &tbc)) /* space rev, err? */ + if ((st = sim_tape_sprecf (uptr, &tbc))) /* space rev, err? */ r = ta_map_err (uptr, st); /* map error */ ta_cs |= TACS_CRC; /* CRC sets, no err */ break; diff --git a/PDP11/pdp11_tc.c b/PDP11/pdp11_tc.c index f1451776..1af3df29 100644 --- a/PDP11/pdp11_tc.c +++ b/PDP11/pdp11_tc.c @@ -992,7 +992,7 @@ switch (fnc) { /* at speed, check fnc * if (ba >= uptr->hwmark) uptr->hwmark = ba + 1; } -/* else /* ignore hdr */ +/* else *//* ignore hdr */ sim_activate (uptr, DT_WSIZE * dt_ltime); DT_SETDONE; /* set done */ break; diff --git a/PDP11/pdp11_tm.c b/PDP11/pdp11_tm.c index ee4f2ba6..e8430b17 100644 --- a/PDP11/pdp11_tm.c +++ b/PDP11/pdp11_tm.c @@ -377,7 +377,7 @@ if (f == MTC_UNLOAD) { /* unload? */ } else if (f == MTC_REWIND) /* rewind */ uptr->USTAT = uptr->USTAT | STA_REW; /* rewinding */ -/* else /* uncomment this else if rewind/unload don't set done */ +/* else *//* uncomment this else if rewind/unload don't set done */ tm_cmd = tm_cmd & ~MTC_DONE; /* clear done */ CLR_INT (TM); /* clear int */ sim_activate (uptr, tm_time); /* start io */ @@ -439,7 +439,7 @@ switch (f) { /* case on function */ tm_sta = tm_sta | STA_RLE; if (tbc < cbc) /* use smaller */ cbc = tbc; - if (t = Map_WriteB (xma, cbc, tmxb)) { /* copy buf to mem */ + if ((t = Map_WriteB (xma, cbc, tmxb))) { /* copy buf to mem */ tm_sta = tm_sta | STA_NXM; /* NXM, set err */ cbc = cbc - t; /* adj byte cnt */ } @@ -449,13 +449,13 @@ switch (f) { /* case on function */ case MTC_WRITE: /* write */ case MTC_WREXT: /* write ext gap */ - if (t = Map_ReadB (xma, cbc, tmxb)) { /* copy mem to buf */ + if ((t = Map_ReadB (xma, cbc, tmxb))) { /* copy mem to buf */ tm_sta = tm_sta | STA_NXM; /* NXM, set err */ cbc = cbc - t; /* adj byte cnt */ if (cbc == 0) /* no xfr? done */ break; } - if (st = sim_tape_wrrecf (uptr, tmxb, cbc)) /* write rec, err? */ + if ((st = sim_tape_wrrecf (uptr, tmxb, cbc))) /* write rec, err? */ r = tm_map_err (uptr, st); /* map error */ else { xma = (xma + cbc) & 0777777; /* inc bus addr */ @@ -464,14 +464,14 @@ switch (f) { /* case on function */ break; case MTC_WREOF: /* write eof */ - if (st = sim_tape_wrtmk (uptr)) /* write tmk, err? */ + if ((st = sim_tape_wrtmk (uptr))) /* write tmk, err? */ r = tm_map_err (uptr, st); /* map error */ break; case MTC_SPACEF: /* space forward */ do { tm_bc = (tm_bc + 1) & 0177777; /* incr wc */ - if (st = sim_tape_sprecf (uptr, &tbc)) { /* spc rec fwd, err? */ + if ((st = sim_tape_sprecf (uptr, &tbc))) { /* spc rec fwd, err? */ r = tm_map_err (uptr, st); /* map error */ break; } @@ -481,7 +481,7 @@ switch (f) { /* case on function */ case MTC_SPACER: /* space reverse */ do { tm_bc = (tm_bc + 1) & 0177777; /* incr wc */ - if (st = sim_tape_sprecr (uptr, &tbc)) { /* spc rec rev, err? */ + if ((st = sim_tape_sprecr (uptr, &tbc))) { /* spc rec rev, err? */ r = tm_map_err (uptr, st); /* map error */ break; } diff --git a/PDP11/pdp11_tq.c b/PDP11/pdp11_tq.c index cd67ba9f..95d76ba2 100644 --- a/PDP11/pdp11_tq.c +++ b/PDP11/pdp11_tq.c @@ -828,13 +828,13 @@ else if (mdf & ~tq_cmf[cmd]) { /* invalid mod? */ sts = ST_CMD | I_MODF; /* ill mods */ } else { /* valid cmd */ - if (uptr = tq_getucb (lu)) { /* valid unit? */ + if ((uptr = tq_getucb (lu))) { /* valid unit? */ if (q && (tq_cmf[cmd] & CMF_SEQ) && /* queueing, seq, */ (uptr->cpkt || uptr->pktq)) { /* and active? */ tq_enqt (&uptr->pktq, pkt); /* do later */ return OK; } -/* if (tq_cmf[cmd] & MD_CDL) /* clr cch lost? */ +/* if (tq_cmf[cmd] & MD_CDL) *//* clr cch lost? */ /* uptr->flags = uptr->flags & ~UNIT_CDL; */ if ((mdf & MD_CSE) && (uptr->flags & UNIT_SXC)) /* clr ser exc? */ uptr->flags = uptr->flags & ~UNIT_SXC; @@ -909,7 +909,7 @@ UNIT *uptr; sim_debug(DBG_TRC, &tq_dev, "tq_abo\n"); tpkt = 0; /* set no mtch */ -if (uptr = tq_getucb (lu)) { /* get unit */ +if ((uptr = tq_getucb (lu))) { /* get unit */ if (uptr->cpkt && /* curr pkt? */ (GETP32 (uptr->cpkt, CMD_REFL) == ref)) { /* match ref? */ tpkt = uptr->cpkt; /* save match */ @@ -922,8 +922,8 @@ if (uptr = tq_getucb (lu)) { /* get unit */ tpkt = uptr->pktq; /* save match */ uptr->pktq = tq_pkt[tpkt].link; /* unlink */ } - else if (prv = uptr->pktq) { /* srch pkt q */ - while (tpkt = tq_pkt[prv].link) { /* walk list */ + else if ((prv = uptr->pktq)) { /* srch pkt q */ + while ((tpkt = tq_pkt[prv].link)) { /* walk list */ if (GETP32 (tpkt, RSP_REFL) == ref) { /* match ref? */ tq_pkt[prv].link = tq_pkt[tpkt].link; /* unlink */ break; @@ -953,7 +953,7 @@ UNIT *uptr; sim_debug(DBG_TRC, &tq_dev, "tq_avl\n"); -if (uptr = tq_getucb (lu)) { /* unit exist? */ +if ((uptr = tq_getucb (lu))) { /* unit exist? */ if (uptr->flags & UNIT_SXC) /* ser exc pending? */ sts = ST_SXC; else { @@ -1012,7 +1012,7 @@ if (tq_pkt[pkt].d[CMD_MOD] & MD_NXU) { /* next unit? */ tq_pkt[pkt].d[RSP_UN] = lu; } } -if (uptr = tq_getucb (lu)) { /* unit exist? */ +if ((uptr = tq_getucb (lu))) { /* unit exist? */ if ((uptr->flags & UNIT_ATT) == 0) /* not attached? */ sts = ST_OFL | SB_OFL_NV; /* offl no vol */ else if (uptr->flags & UNIT_ONL) /* online */ @@ -1039,7 +1039,7 @@ UNIT *uptr; sim_debug(DBG_TRC, &tq_dev, "tq_onl\n"); -if (uptr = tq_getucb (lu)) { /* unit exist? */ +if ((uptr = tq_getucb (lu))) { /* unit exist? */ if ((uptr->flags & UNIT_ATT) == 0) /* not attached? */ sts = ST_OFL | SB_OFL_NV; /* offl no vol */ else if (uptr->flags & UNIT_ONL) /* already online? */ @@ -1070,7 +1070,7 @@ if (tq_pkt[pkt].d[SCC_MSV]) /* MSCP ver = 0? */ else { tq_cflgs = (tq_cflgs & CF_RPL) | /* hack ctrl flgs */ tq_pkt[pkt].d[SCC_CFL]; - if (tq_htmo = tq_pkt[pkt].d[SCC_TMO]) /* set timeout */ + if ((tq_htmo = tq_pkt[pkt].d[SCC_TMO])) /* set timeout */ tq_htmo = tq_htmo + 2; /* if nz, round up */ tq_pkt[pkt].d[SCC_CFL] = tq_cflgs; /* return flags */ tq_pkt[pkt].d[SCC_TMO] = TQ_DCTMO; /* ctrl timeout */ @@ -1096,7 +1096,7 @@ UNIT *uptr; sim_debug(DBG_TRC, &tq_dev, "tq_suc\n"); -if (uptr = tq_getucb (lu)) { /* unit exist? */ +if ((uptr = tq_getucb (lu))) { /* unit exist? */ if ((uptr->flags & UNIT_ATT) == 0) /* not attached? */ sts = ST_OFL | SB_OFL_NV; /* offl no vol */ else { @@ -1120,7 +1120,7 @@ UNIT *uptr; sim_debug(DBG_TRC, &tq_dev, "tq_flu\n"); -if (uptr = tq_getucb (lu)) /* unit exist? */ +if ((uptr = tq_getucb (lu))) /* unit exist? */ sts = tq_mot_valid (uptr, OP_FLU); /* validate req */ else sts = ST_OFL; /* offline */ tq_putr (pkt, OP_FLU | OP_END, tq_efl (uptr), sts, FLU_LNT, UQ_TYP_SEQ); @@ -1138,7 +1138,7 @@ UNIT *uptr; sim_debug(DBG_TRC, &tq_dev, "tq_erase\n"); -if (uptr = tq_getucb (lu)) { /* unit exist? */ +if ((uptr = tq_getucb (lu))) { /* unit exist? */ sts = tq_mot_valid (uptr, cmd); /* validity checks */ if (sts == ST_SUC) { /* ok? */ uptr->cpkt = pkt; /* op in progress */ @@ -1162,7 +1162,7 @@ UNIT *uptr; sim_debug(DBG_TRC, &tq_dev, "tq_wtm\n"); -if (uptr = tq_getucb (lu)) { /* unit exist? */ +if ((uptr = tq_getucb (lu))) { /* unit exist? */ objp = uptr->objp; /* position op */ sts = tq_mot_valid (uptr, OP_WTM); /* validity checks */ if (sts == ST_SUC) { /* ok? */ @@ -1188,7 +1188,7 @@ UNIT *uptr; sim_debug(DBG_TRC, &tq_dev, "tq_pos\n"); -if (uptr = tq_getucb (lu)) { /* unit exist? */ +if ((uptr = tq_getucb (lu))) { /* unit exist? */ objp = uptr->objp; /* position op */ sts = tq_mot_valid (uptr, OP_POS); /* validity checks */ if (sts == ST_SUC) { /* ok? */ @@ -1224,7 +1224,7 @@ UNIT *uptr; sim_debug(DBG_TRC, &tq_dev, "tq_rw\n"); -if (uptr = tq_getucb (lu)) { /* unit exist? */ +if ((uptr = tq_getucb (lu))) { /* unit exist? */ objp = uptr->objp; /* position op */ sts = tq_mot_valid (uptr, cmd); /* validity checks */ if (sts == ST_SUC) { /* ok? */ @@ -1363,7 +1363,7 @@ switch (cmd) { /* case on command */ } else wbc = res->tbc; if (cmd == OP_RD) { /* read? */ - if (t = Map_WriteB (ba, wbc, res->tqxb)) { /* store, nxm? */ + if ((t = Map_WriteB (ba, wbc, res->tqxb))) {/* store, nxm? */ PUTP32 (pkt, RW_BCL, wbc - t); /* adj bc */ if (tq_hbe (uptr, ba + wbc - t)) /* post err log */ tq_mot_end (uptr, EF_LOG, ST_HST | SB_HST_NXM, res->tbc); @@ -1402,7 +1402,7 @@ switch (cmd) { /* case on command */ case OP_WR: /* write */ if (!io_complete) { /* Top half processing */ - if (t = Map_ReadB (ba, bc, res->tqxb)) { /* fetch buf, nxm? */ + if ((t = Map_ReadB (ba, bc, res->tqxb))) { /* fetch buf, nxm? */ PUTP32 (pkt, RW_BCL, 0); /* no bytes xfer'd */ if (tq_hbe (uptr, ba + bc - t)) /* post err log */ tq_mot_end (uptr, EF_LOG, ST_HST | SB_HST_NXM, bc); @@ -2291,11 +2291,11 @@ if ((uptr->flags & UNIT_ONL) == 0) { if (uptr->cpkt) { fprintf (st, "Unit %d current ", u); tq_show_pkt (st, uptr->cpkt); - if (pkt = uptr->pktq) { + if ((pkt = uptr->pktq)) { do { fprintf (st, "Unit %d queued ", u); tq_show_pkt (st, pkt); - } while (pkt = tq_pkt[pkt].link); + } while ((pkt = tq_pkt[pkt].link)); } } else fprintf (st, "Unit %d queues are empty\n", u); @@ -2320,7 +2320,7 @@ if (val & TQ_SH_RI) { tq_show_ring (st, &tq_rq); } if (val & TQ_SH_FR) { - if (pkt = tq_freq) { + if ((pkt = tq_freq)) { for (i = 0; pkt != 0; i++, pkt = tq_pkt[pkt].link) { if (i == 0) fprintf (st, "Free queue = %d", pkt); @@ -2333,11 +2333,11 @@ if (val & TQ_SH_FR) { else fprintf (st, "Free queue is empty\n"); } if (val & TQ_SH_RS) { - if (pkt = tq_rspq) { + if ((pkt = tq_rspq)) { do { fprintf (st, "Response "); tq_show_pkt (st, pkt); - } while (pkt = tq_pkt[pkt].link); + } while ((pkt = tq_pkt[pkt].link)); } else fprintf (st, "Response queue is empty\n"); } diff --git a/PDP11/pdp11_ts.c b/PDP11/pdp11_ts.c index 11ab6f11..5966a062 100644 --- a/PDP11/pdp11_ts.c +++ b/PDP11/pdp11_ts.c @@ -490,7 +490,7 @@ do { fc = (fc - 1) & DMASK; /* decr wc */ if (upd) msgrfc = fc; - if (st = sim_tape_sprecf (uptr, &tbc)) /* space rec fwd, err? */ + if ((st = sim_tape_sprecf (uptr, &tbc))) /* space rec fwd, err? */ return ts_map_status (st); /* map status */ msgxs0 = msgxs0 | XS0_MOT; /* tape has moved */ } while (fc != 0); @@ -533,7 +533,7 @@ do { fc = (fc - 1) & DMASK; /* decr wc */ if (upd) msgrfc = fc; - if (st = sim_tape_sprecr (uptr, &tbc)) /* space rec rev, err? */ + if ((st = sim_tape_sprecr (uptr, &tbc))) /* space rec rev, err? */ return ts_map_status (st); /* map status */ msgxs0 = msgxs0 | XS0_MOT; /* tape has moved */ } while (fc != 0); @@ -666,7 +666,7 @@ else { return TC5; } } -if (st = sim_tape_wrrecf (uptr, tsxb, fc)) /* write rec, err? */ +if ((st = sim_tape_wrrecf (uptr, tsxb, fc))) /* write rec, err? */ return ts_map_status (st); /* return status */ msgxs0 = msgxs0 | XS0_MOT; /* tape has moved */ msgrfc = 0; @@ -679,7 +679,7 @@ int32 ts_wtmk (UNIT *uptr) { t_stat st; -if (st = sim_tape_wrtmk (uptr)) /* write tmk, err? */ +if ((st = sim_tape_wrtmk (uptr))) /* write tmk, err? */ return ts_map_status (st); /* return status */ msgxs0 = msgxs0 | XS0_MOT; /* tape has moved */ if (sim_tape_eot (&ts_unit)) /* EOT on write? */ diff --git a/PDP11/pdp11_tu.c b/PDP11/pdp11_tu.c index 9175b996..d0ced0a9 100644 --- a/PDP11/pdp11_tu.c +++ b/PDP11/pdp11_tu.c @@ -647,7 +647,7 @@ switch (fnc) { /* case on function */ case FNC_SPACEF: /* space forward */ do { tufc = (tufc + 1) & 0177777; /* incr fc */ - if (st = sim_tape_sprecf (uptr, &tbc)) { /* space rec fwd, err? */ + if ((st = sim_tape_sprecf (uptr, &tbc))) { /* space rec fwd, err? */ r = tu_map_err (drv, st, 0); /* map error */ break; } @@ -660,7 +660,7 @@ switch (fnc) { /* case on function */ case FNC_SPACER: /* space reverse */ do { tufc = (tufc + 1) & 0177777; /* incr wc */ - if (st = sim_tape_sprecr (uptr, &tbc)) { /* space rec rev, err? */ + if ((st = sim_tape_sprecr (uptr, &tbc))) { /* space rec rev, err? */ r = tu_map_err (drv, st, 0); /* map error */ break; } @@ -671,7 +671,7 @@ switch (fnc) { /* case on function */ break; case FNC_WREOF: /* write end of file */ - if (st = sim_tape_wrtmk (uptr)) /* write tmk, err? */ + if ((st = sim_tape_wrtmk (uptr))) /* write tmk, err? */ r = tu_map_err (drv, st, 0); /* map error */ break; @@ -687,7 +687,7 @@ switch (fnc) { /* case on function */ tufc = 0; /* clear frame count */ if ((uptr->UDENS == TC_1600) && sim_tape_bot (uptr)) tufs = tufs | FS_ID; /* PE BOT? ID burst */ - if (st = sim_tape_rdrecf (uptr, xbuf, &tbc, MT_MAXFR)) { /* read fwd */ + if ((st = sim_tape_rdrecf (uptr, xbuf, &tbc, MT_MAXFR))) {/* read fwd */ if (st == MTSE_TMK) /* tmk also sets FCE */ tu_set_er (ER_FCE); r = tu_map_err (drv, st, 1); /* map error */ @@ -739,7 +739,7 @@ switch (fnc) { /* case on function */ } tbc = xbc; } - if (st = sim_tape_wrrecf (uptr, xbuf, tbc)) /* write rec, err? */ + if ((st = sim_tape_wrrecf (uptr, xbuf, tbc))) /* write rec, err? */ r = tu_map_err (drv, st, 1); /* map error */ else { tufc = (tufc + tbc) & 0177777; @@ -751,7 +751,7 @@ switch (fnc) { /* case on function */ case FNC_READR: /* read reverse */ case FNC_WCHKR: /* wcheck = read */ tufc = 0; /* clear frame count */ - if (st = sim_tape_rdrecr (uptr, xbuf + 4, &tbc, MT_MAXFR)) { /* read rev */ + if ((st = sim_tape_rdrecr (uptr, xbuf + 4, &tbc, MT_MAXFR))) {/* read rev */ if (st == MTSE_TMK) /* tmk also sets FCE */ tu_set_er (ER_FCE); r = tu_map_err (drv, st, 1); /* map error */ diff --git a/PDP11/pdp11_xq.c b/PDP11/pdp11_xq.c index 9bb366db..4937fe4d 100644 --- a/PDP11/pdp11_xq.c +++ b/PDP11/pdp11_xq.c @@ -702,7 +702,7 @@ t_stat xq_show_filters (FILE* st, UNIT* uptr, int32 val, void* desc) fprintf(st, "Filters:\n"); for (i=0; ivar->setup.macs[i], buffer); - fprintf(st, " [%2d]: %s\n", i, buffer); + fprintf(st, " [%2d]: %s\n", (int)i, buffer); } if (xq->var->setup.multicast) fprintf(st, "All Multicast Receive Mode\n"); @@ -1187,7 +1187,7 @@ t_stat xq_process_setup(CTLR* xq) xq->var->setup.multicast = (0 != (len & XQ_SETUP_MC)); xq->var->setup.promiscuous = (0 != (len & XQ_SETUP_PM)); - if (led = (len & XQ_SETUP_LD) >> 2) { + if ((led = (len & XQ_SETUP_LD) >> 2)) { switch (led) { case 1: xq->var->setup.l1 = 0; break; case 2: xq->var->setup.l2 = 0; break; @@ -2073,6 +2073,9 @@ t_stat xq_process_bootrom (CTLR* xq) /* set to next bdl (implicit chain) */ xq->var->rbdl_ba += 12; break; + + default: + break; } /* switch */ /* --------------------------- Done, finish up -----------------------------*/ diff --git a/PDP11/pdp11_xu.c b/PDP11/pdp11_xu.c index bf43cd84..8ef1cd7b 100644 --- a/PDP11/pdp11_xu.c +++ b/PDP11/pdp11_xu.c @@ -1041,7 +1041,7 @@ void xu_process_receive(CTLR* xu) sim_debug(DBG_TRC, xu->dev, "xu_process_receive(), buffers: %d\n", xu->var->rrlen); -/* xu_dump_rxring(xu); /* debug receive ring */ +/* xu_dump_rxring(xu); *//* debug receive ring */ /* process only when in the running state, and host buffers are available */ if ((state != STATE_RUNNING) || no_buffers) @@ -1213,7 +1213,7 @@ void xu_process_transmit(CTLR* xu) t_stat rstatus, wstatus; sim_debug(DBG_TRC, xu->dev, "xu_process_transmit()\n"); -/* xu_dump_txring(xu); /* debug receive ring */ +/* xu_dump_txring(xu); *//* debug receive ring */ for (;;) { diff --git a/PDP18B/pdp18b_cpu.c b/PDP18B/pdp18b_cpu.c index d9473ac3..7bf7ab28 100644 --- a/PDP18B/pdp18b_cpu.c +++ b/PDP18B/pdp18b_cpu.c @@ -604,7 +604,7 @@ while (reason == 0) { /* loop until halted */ int32 link_init, fill; if (sim_interval <= 0) { /* check clock queue */ - if (reason = sim_process_event ()) + if ((reason = sim_process_event ())) break; api_int = api_eval (&int_pend); /* eval API */ } diff --git a/PDP18B/pdp18b_dt.c b/PDP18B/pdp18b_dt.c index 9b422fec..6b78f81b 100644 --- a/PDP18B/pdp18b_dt.c +++ b/PDP18B/pdp18b_dt.c @@ -1147,7 +1147,7 @@ switch (fnc) { /* at speed, check fnc * if (ba >= uptr->hwmark) uptr->hwmark = ba + 1; } -/* /* ignore hdr */ + /* ignore hdr */ sim_activate (uptr, DT_WSIZE * dt_ltime); if (M[DT_WC] == 0) dt_substate = DTO_WCO; diff --git a/PDP18B/pdp18b_fpp.c b/PDP18B/pdp18b_fpp.c index d1a098a6..0f2f8a04 100644 --- a/PDP18B/pdp18b_fpp.c +++ b/PDP18B/pdp18b_fpp.c @@ -253,7 +253,7 @@ switch (fop) { /* case on subop */ break; case FOP_SUB: /* subtract */ - if (sta = fp15_opnd (fir, ar, &fmb)) /* fetch op to FMB */ + if ((sta = fp15_opnd (fir, ar, &fmb))) /* fetch op to FMB */ break; if (fir & FI_FP) /* fp? */ sta = fp15_fadd (fir, &fma, &fmb, 1); /* yes, fp sub */ @@ -262,7 +262,7 @@ switch (fop) { /* case on subop */ case FOP_RSUB: /* reverse sub */ fmb = fma; /* FMB <- FMA */ - if (sta = fp15_opnd (fir, ar, &fma)) /* fetch op to FMA */ + if ((sta = fp15_opnd (fir, ar, &fma))) /* fetch op to FMA */ break; if (fir & FI_FP) /* fp? */ sta = fp15_fadd (fir, &fma, &fmb, 1); /* yes, fp sub */ @@ -270,7 +270,7 @@ switch (fop) { /* case on subop */ break; case FOP_MUL: /* multiply */ - if (sta = fp15_opnd (fir, ar, &fmb)) /* fetch op to FMB */ + if ((sta = fp15_opnd (fir, ar, &fmb))) /* fetch op to FMB */ break; if (fir & FI_FP) /* fp? */ sta = fp15_fmul (fir, &fma, &fmb); /* yes, fp mul */ @@ -278,9 +278,9 @@ switch (fop) { /* case on subop */ break; case FOP_DIV: /* divide */ - if (sta = fp15_opnd (fir, ar, &fmb)) /* fetch op to FMB */ + if ((sta = fp15_opnd (fir, ar, &fmb))) /* fetch op to FMB */ break; - if (sta = fp15_opnd (fir, ar, &fmb)) break; /* fetch op to FMB */ + if ((sta = fp15_opnd (fir, ar, &fmb)))break; /* fetch op to FMB */ if (fir & FI_FP) /* fp? */ sta = fp15_fdiv (fir, &fma, &fmb); /* yes, fp div */ else sta = fp15_idiv (fir, &fma, &fmb); /* no, int div */ @@ -288,7 +288,7 @@ switch (fop) { /* case on subop */ case FOP_RDIV: /* reverse divide */ fmb = fma; /* FMB <- FMA */ - if (sta = fp15_opnd (fir, ar, &fma)) /* fetch op to FMA */ + if ((sta = fp15_opnd (fir, ar, &fma))) /* fetch op to FMA */ break; if (fir & FI_FP) /* fp? */ sta = fp15_fdiv (fir, &fma, &fmb); /* yes, fp div */ @@ -296,7 +296,7 @@ switch (fop) { /* case on subop */ break; case FOP_LD: /* load */ - if (sta = fp15_opnd (fir, ar, &fma)) /* fetch op to FMA */ + if ((sta = fp15_opnd (fir, ar, &fma))) /* fetch op to FMA */ break; fp15_asign (fir, &fma); /* modify A sign */ if (fir & FI_FP) /* fp? */ @@ -309,7 +309,7 @@ switch (fop) { /* case on subop */ break; case FOP_FLT: /* float */ - if (sta = fp15_opnd (fir, ar, &fma)) /* fetch op to FMA */ + if ((sta = fp15_opnd (fir, ar, &fma))) /* fetch op to FMA */ break; fma.exp = 35; fp15_asign (fir, &fma); /* adjust A sign */ @@ -317,13 +317,13 @@ switch (fop) { /* case on subop */ break; case FOP_FIX: /* fix */ - if (sta = fp15_opnd (fir, ar, &fma)) /* fetch op to FMA */ + if ((sta = fp15_opnd (fir, ar, &fma))) /* fetch op to FMA */ break; sta = fp15_fix (fir, &fma); /* fix */ break; case FOP_LFMQ: /* load FMQ */ - if (sta = fp15_opnd (fir, ar, &fma)) /* fetch op to FMA */ + if ((sta = fp15_opnd (fir, ar, &fma))) /* fetch op to FMA */ break; dp_swap (&fma, &fmq); /* swap FMA, FMQ */ fp15_asign (fir, &fma); /* adjust A sign */ @@ -337,7 +337,7 @@ switch (fop) { /* case on subop */ sta = Write (ar, dat, WR); } else { /* no, load */ - if (sta = Read (ar, &dat, RD)) + if ((sta = Read (ar, &dat, RD))) break; fguard = (dat >> JEA_V_GUARD) & 1; jea = dat & JEA_EAMASK; @@ -345,7 +345,7 @@ switch (fop) { /* case on subop */ break; case FOP_ADD: /* add */ - if (sta = fp15_opnd (fir, ar, &fmb)) /* fetch op to FMB */ + if ((sta = fp15_opnd (fir, ar, &fmb))) /* fetch op to FMB */ break; if (fir & FI_FP) /* fp? */ sta = fp15_fadd (fir, &fma, &fmb, 0); /* yes, fp add */ @@ -429,7 +429,7 @@ t_stat sta; fguard = 0; /* clear guard */ if (ir & FI_FP) { /* fp? */ - if (sta = fp15_norm (ir, a, NULL, 0)) /* normalize */ + if ((sta = fp15_norm (ir, a, NULL, 0))) /* normalize */ return sta; if (ir & FI_DP) { /* dp? */ wd[0] = a->exp & DMASK; /* exponent */ diff --git a/PDP18B/pdp18b_mt.c b/PDP18B/pdp18b_mt.c index 22d190cf..db4d598f 100644 --- a/PDP18B/pdp18b_mt.c +++ b/PDP18B/pdp18b_mt.c @@ -353,7 +353,7 @@ switch (f) { /* case on function */ mtxb[p++] = M[xma] & 0377; } } /* end for */ - if (st = sim_tape_wrrecf (uptr, mtxb, tbc)) /* write rec, err? */ + if ((st = sim_tape_wrrecf (uptr, mtxb, tbc))) /* write rec, err? */ r = mt_map_err (uptr, st); /* map error */ else { M[MT_CA] = (M[MT_CA] + wc) & DMASK; /* advance mem addr */ @@ -363,7 +363,7 @@ switch (f) { /* case on function */ break; case FN_WREOF: - if (st = sim_tape_wrtmk (uptr)) /* write tmk, err? */ + if ((st = sim_tape_wrtmk (uptr))) /* write tmk, err? */ r = mt_map_err (uptr, st); /* map error */ else uptr->USTAT = STA_EOF; mt_cu = mt_cu & ~CU_ERASE; /* clear erase flag */ @@ -372,7 +372,7 @@ switch (f) { /* case on function */ case FN_SPACEF: /* space forward */ do { M[MT_WC] = (M[MT_WC] + 1) & DMASK; /* inc WC */ - if (st = sim_tape_sprecf (uptr, &tbc)) { /* space rec fwd, err? */ + if ((st = sim_tape_sprecf (uptr, &tbc))) { /* space rec fwd, err? */ r = mt_map_err (uptr, st); /* map error */ break; } @@ -382,7 +382,7 @@ switch (f) { /* case on function */ case FN_SPACER: /* space reverse */ do { M[MT_WC] = (M[MT_WC] + 1) & DMASK; /* inc WC */ - if (st = sim_tape_sprecr (uptr, &tbc)) { /* space rec rev, err? */ + if ((st = sim_tape_sprecr (uptr, &tbc))) { /* space rec rev, err? */ r = mt_map_err (uptr, st); /* map error */ break; } diff --git a/PDP18B/pdp18b_stddev.c b/PDP18B/pdp18b_stddev.c index 966b6dd1..78cfeba3 100644 --- a/PDP18B/pdp18b_stddev.c +++ b/PDP18B/pdp18b_stddev.c @@ -594,7 +594,7 @@ if ((temp = getc (ptr_unit.fileref)) == EOF) { /* end of file? */ if (ptr_state == 0) { /* ASCII */ if (ptr_unit.flags & UNIT_RASCII) { /* want parity? */ ptr_unit.buf = temp = temp & 0177; /* parity off */ - while (temp = temp & (temp - 1)) + while ((temp = temp & (temp - 1))) ptr_unit.buf = ptr_unit.buf ^ 0200; /* count bits */ ptr_unit.buf = ptr_unit.buf ^ 0200; /* set even parity */ } diff --git a/PDP18B/pdp18b_sys.c b/PDP18B/pdp18b_sys.c index 97adc3cf..86bedcf5 100644 --- a/PDP18B/pdp18b_sys.c +++ b/PDP18B/pdp18b_sys.c @@ -1009,7 +1009,7 @@ for (i = 0; opc_val[i] >= 0; i++) { /* loop thru ops */ break; case I_V_OPR: /* operate */ - if (sp = (inst & 03730)) + if ((sp = (inst & 03730))) fprintf (of, "%s", opcode[i]); fprint_opr (of, inst & 014047, I_V_OPR, sp); break; diff --git a/PDP18B/pdp18b_tt1.c b/PDP18B/pdp18b_tt1.c index fdc5ac22..d29bde0e 100644 --- a/PDP18B/pdp18b_tt1.c +++ b/PDP18B/pdp18b_tt1.c @@ -222,7 +222,7 @@ if (ln >= 0) /* got one? rcv enab */ tmxr_poll_rx (&ttx_desc); /* poll for input */ for (ln = 0; ln < TTX_MAXL; ln++) { /* loop thru lines */ if (ttx_ldsc[ln].conn) { /* connected? */ - if (temp = tmxr_getc_ln (&ttx_ldsc[ln])) { /* get char */ + if ((temp = tmxr_getc_ln (&ttx_ldsc[ln]))) { /* get char */ if (temp & SCPE_BREAK) /* break? */ c = 0; else c = sim_tt_inpcvt (temp, TT_GET_MODE (ttox_unit[ln].flags) | TTUF_KSR); diff --git a/PDP8/pdp8_cpu.c b/PDP8/pdp8_cpu.c index c327c41a..98ad5846 100644 --- a/PDP8/pdp8_cpu.c +++ b/PDP8/pdp8_cpu.c @@ -344,7 +344,7 @@ reason = 0; while (reason == 0) { /* loop until halted */ if (sim_interval <= 0) { /* check clock queue */ - if (reason = sim_process_event ()) + if ((reason = sim_process_event ())) break; } diff --git a/PDP8/pdp8_ct.c b/PDP8/pdp8_ct.c index 9f5f1e27..31ac1e75 100644 --- a/PDP8/pdp8_ct.c +++ b/PDP8/pdp8_ct.c @@ -270,7 +270,7 @@ switch (IR & 07) { /* decode IR<9:11> */ case 6: /* KGOA */ ct_df = 0; /* clear data flag */ - if (uptr = ct_busy ()) /* op in progress? */ + if ((uptr = ct_busy ())) /* op in progress? */ AC = ct_go_cont (uptr, AC); /* yes */ else AC = ct_go_start (AC); /* no, start */ ct_updsta (NULL); @@ -433,7 +433,7 @@ switch (uptr->FNC) { /* case on function */ case SRA_CRC: /* CRC */ if (ct_write) { /* write? */ - if (st = sim_tape_wrrecf (uptr, ct_xb, ct_bptr)) /* write, err? */ + if ((st = sim_tape_wrrecf (uptr, ct_xb, ct_bptr)))/* write, err? */ r = ct_map_err (uptr, st); /* map error */ break; /* write done */ } @@ -452,7 +452,7 @@ switch (uptr->FNC) { /* case on function */ break; /* read done */ case SRA_WFG: /* write file gap */ - if (st = sim_tape_wrtmk (uptr)) /* write tmk, err? */ + if ((st = sim_tape_wrtmk (uptr))) /* write tmk, err? */ r = ct_map_err (uptr, st); /* map error */ break; @@ -462,7 +462,7 @@ switch (uptr->FNC) { /* case on function */ break; case SRA_SRB: /* space rev blk */ - if (st = sim_tape_sprecr (uptr, &tbc)) /* space rev, err? */ + if ((st = sim_tape_sprecr (uptr, &tbc))) /* space rev, err? */ r = ct_map_err (uptr, st); /* map error */ break; diff --git a/PDP8/pdp8_dt.c b/PDP8/pdp8_dt.c index 8c452eae..2b0ffe9b 100644 --- a/PDP8/pdp8_dt.c +++ b/PDP8/pdp8_dt.c @@ -964,7 +964,7 @@ switch (fnc) { /* at speed, check fnc * if (ba >= uptr->hwmark) uptr->hwmark = ba + 1; } -/* /* ignore hdr */ + /* ignore hdr */ sim_activate (uptr, DT_WSIZE * dt_ltime); if (M[DT_WC] == 0) dt_substate = DTO_WCO; diff --git a/PDP8/pdp8_mt.c b/PDP8/pdp8_mt.c index 914c8619..844f414c 100644 --- a/PDP8/pdp8_mt.c +++ b/PDP8/pdp8_mt.c @@ -120,7 +120,7 @@ #define STA_CPE (00002 << 12) /* compare error */ #define STA_ILL (00001 << 12) /* illegal */ #define STA_9TK 00040 /* 9 track */ -/* #define STA_BAD 00020 /* bad tape?? */ +/* #define STA_BAD 00020 *//* bad tape?? */ #define STA_INC 00010 /* increment error */ #define STA_LAT 00004 /* lateral par error */ #define STA_CRC 00002 /* CRC error */ @@ -453,7 +453,7 @@ switch (f) { /* case on function */ mtxb[p++] = M[xma] & 077; } } - if (st = sim_tape_wrrecf (uptr, mtxb, tbc)) { /* write rec, err? */ + if ((st = sim_tape_wrrecf (uptr, mtxb, tbc))) { /* write rec, err? */ r = mt_map_err (uptr, st); /* map error */ xma = GET_EMA (mt_cu) + mt_ca; /* restore xma */ } @@ -461,14 +461,14 @@ switch (f) { /* case on function */ break; case FN_WREOF: - if (st = sim_tape_wrtmk (uptr)) /* write tmk, err? */ + if ((st = sim_tape_wrtmk (uptr))) /* write tmk, err? */ r = mt_map_err (uptr, st); /* map error */ break; case FN_SPACEF: /* space forward */ do { mt_wc = (mt_wc + 1) & 07777; /* incr wc */ - if (st = sim_tape_sprecf (uptr, &tbc)) { /* space rec fwd, err? */ + if ((st = sim_tape_sprecf (uptr, &tbc))) { /* space rec fwd, err? */ r = mt_map_err (uptr, st); /* map error */ break; /* stop */ } @@ -478,7 +478,7 @@ switch (f) { /* case on function */ case FN_SPACER: /* space reverse */ do { mt_wc = (mt_wc + 1) & 07777; /* incr wc */ - if (st = sim_tape_sprecr (uptr, &tbc)) { /* space rec rev, err? */ + if ((st = sim_tape_sprecr (uptr, &tbc))) { /* space rec rev, err? */ r = mt_map_err (uptr, st); /* map error */ break; /* stop */ } diff --git a/PDP8/pdp8_ttx.c b/PDP8/pdp8_ttx.c index 0956178c..5c335a48 100644 --- a/PDP8/pdp8_ttx.c +++ b/PDP8/pdp8_ttx.c @@ -233,7 +233,7 @@ if (ln >= 0) /* got one? rcv enb*/ tmxr_poll_rx (&ttx_desc); /* poll for input */ for (ln = 0; ln < TTX_LINES; ln++) { /* loop thru lines */ if (ttx_ldsc[ln].conn) { /* connected? */ - if (temp = tmxr_getc_ln (&ttx_ldsc[ln])) { /* get char */ + if ((temp = tmxr_getc_ln (&ttx_ldsc[ln]))) { /* get char */ if (temp & SCPE_BREAK) /* break? */ c = 0; else c = sim_tt_inpcvt (temp, TT_GET_MODE (ttox_unit[ln].flags)); diff --git a/S3/s3_cd.c b/S3/s3_cd.c index 7ec0e2ab..d63d783f 100644 --- a/S3/s3_cd.c +++ b/S3/s3_cd.c @@ -280,7 +280,7 @@ t_stat r; if (sim_is_active (&cdr_unit)) { /* busy? */ sim_cancel (&cdr_unit); /* cancel */ - if (r = cdr_svc (&cdr_unit)) return r; /* process */ + if ((r = cdr_svc (&cdr_unit))) return r; /* process */ } if (((cdp_unit.flags & UNIT_ATT) != 0 || diff --git a/S3/s3_cpu.c b/S3/s3_cpu.c index b4696484..e3f06482 100644 --- a/S3/s3_cpu.c +++ b/S3/s3_cpu.c @@ -527,7 +527,7 @@ reason = 0; while (reason == 0) { /* loop until halted */ if (sim_interval <= 0) { /* check clock queue */ - if (reason = sim_process_event ()) break; + if ((reason = sim_process_event ())) break; } if (int_req) { /* interrupt? */ diff --git a/S3/s3_disk.c b/S3/s3_disk.c index d3588cfd..f0a2ed20 100644 --- a/S3/s3_disk.c +++ b/S3/s3_disk.c @@ -298,7 +298,7 @@ int32 dsk (int32 disk, int32 op, int32 m, int32 n, int32 data) addr++; } - if ((sect == 55) ) { /* HJS MODS */ + if (sect == 55) { /* HJS MODS */ S = sect; N = nsects - i - 2; if (N > -1) diskerr[disk] |= 0x0020; /* end of cyl. */ @@ -349,7 +349,7 @@ int32 dsk (int32 disk, int32 op, int32 m, int32 n, int32 data) diskerr[disk] |= 0x0800; break; } - if ((sect == 55) ) { /* HJS MODS */ + if (sect == 55) { /* HJS MODS */ S = sect; N = nsects - i - 2; if (N > -1) diskerr[disk] |= 0x0020; /* end of cyl. */ @@ -392,7 +392,7 @@ int32 dsk (int32 disk, int32 op, int32 m, int32 n, int32 data) diskerr[disk] |= 0x0400; break; } - if ((sect == 55) ) { /* HJS MODS */ + if (sect == 55) { /* HJS MODS */ S = sect; N = nsects - i - 2; if (N > -1) diskerr[disk] |= 0x0020; /* end of cyl. */ @@ -434,7 +434,7 @@ int32 dsk (int32 disk, int32 op, int32 m, int32 n, int32 data) diskerr[disk] |= 0x0400; break; } - if ((sect == 55) ) { + if (sect == 55) { S = sect; N = nsects - i - 2; if (N > 0) diskerr[disk] |= 0x0020; @@ -486,7 +486,7 @@ int32 dsk (int32 disk, int32 op, int32 m, int32 n, int32 data) found[disk] = 1; if (res == data) break; - if ((sect == 55) ) { /* HJS MODS */ + if (sect == 55) { /* HJS MODS */ S = sect; N = nsects - i - 2; if (N > -1) diskerr[disk] |= 0x0020; /* end of cyl. */ diff --git a/SDS/sds_cpu.c b/SDS/sds_cpu.c index a8f87db7..f045b6e7 100644 --- a/SDS/sds_cpu.c +++ b/SDS/sds_cpu.c @@ -385,14 +385,14 @@ while (reason == 0) { /* loop until halted */ } if (sim_interval <= 0) { /* event queue? */ - if (reason = sim_process_event ()) /* process */ + if ((reason = sim_process_event ())) /* process */ break; int_reqhi = api_findreq (); /* recalc int req */ chan_req = chan_testact (); /* recalc chan act */ } if (chan_req) { /* channel request? */ - if (reason = chan_process ()) /* process */ + if ((reason = chan_process ())) /* process */ break; int_reqhi = api_findreq (); /* recalc int req */ chan_req = chan_testact (); /* recalc chan act */ @@ -506,7 +506,7 @@ if (inst & I_POP) { /* POP? */ } else { /* normal POP */ dat = (OV << 23) | dat; /* ov in <0> */ - if (r = Write (0, dat)) + if ((r = Write (0, dat))) return r; } } @@ -525,49 +525,49 @@ switch (op) { /* case on opcode */ /* Loads and stores */ case LDA: - if (r = Ea (inst, &va)) /* decode eff addr */ + if ((r = Ea (inst, &va))) /* decode eff addr */ return r; - if (r = Read (va, &A)) /* get operand */ + if ((r = Read (va, &A))) /* get operand */ return r; break; case LDB: - if (r = Ea (inst, &va)) /* decode eff addr */ + if ((r = Ea (inst, &va))) /* decode eff addr */ return r; - if (r = Read (va, &B)) /* get operand */ + if ((r = Read (va, &B))) /* get operand */ return r; break; case LDX: - if (r = Ea (inst, &va)) /* decode eff addr */ + if ((r = Ea (inst, &va))) /* decode eff addr */ return r; - if (r = Read (va, &X)) /* get operand */ + if ((r = Read (va, &X))) /* get operand */ return r; break; case STA: - if (r = Ea (inst, &va)) /* decode eff addr */ + if ((r = Ea (inst, &va))) /* decode eff addr */ return r; - if (r = Write (va, A)) /* write operand */ + if ((r = Write (va, A))) /* write operand */ return r; break; case STB: - if (r = Ea (inst, &va)) /* decode eff addr */ + if ((r = Ea (inst, &va))) /* decode eff addr */ return r; - if (r = Write (va, B)) /* write operand */ + if ((r = Write (va, B))) /* write operand */ return r; break; case STX: - if (r = Ea (inst, &va)) /* decode eff addr */ + if ((r = Ea (inst, &va))) /* decode eff addr */ return r; - if (r = Write (va, X)) /* write operand */ + if ((r = Write (va, X))) /* write operand */ return r; break; case EAX: - if (r = Ea (inst, &va)) /* decode eff addr */ + if ((r = Ea (inst, &va))) /* decode eff addr */ return r; if (nml_mode || usr_mode) /* normal or user? */ X = (X & ~VA_MASK) | (va & VA_MASK); /* only 14b */ @@ -575,11 +575,11 @@ switch (op) { /* case on opcode */ break; case XMA: - if (r = Ea (inst, &va)) /* decode eff addr */ + if ((r = Ea (inst, &va))) /* decode eff addr */ return r; - if (r = Read (va, &dat)) /* get operand */ + if ((r = Read (va, &dat))) /* get operand */ return r; - if (r = Write (va, A)) /* write A */ + if ((r = Write (va, A))) /* write A */ return r; A = dat; /* load A */ break; @@ -587,95 +587,95 @@ switch (op) { /* case on opcode */ /* Arithmetic and logical */ case ADD: - if (r = Ea (inst, &va)) /* decode eff addr */ + if ((r = Ea (inst, &va))) /* decode eff addr */ return r; - if (r = Read (va, &dat)) /* get operand */ + if ((r = Read (va, &dat))) /* get operand */ return r; A = Add24 (A, dat, 0); /* add */ break; case ADC: - if (r = Ea (inst, &va)) /* decode eff addr */ + if ((r = Ea (inst, &va))) /* decode eff addr */ return r; - if (r = Read (va, &dat)) /* get operand */ + if ((r = Read (va, &dat))) /* get operand */ return r; OV = 0; /* clear overflow */ A = Add24 (A, dat, X >> 23); /* add with carry */ break; case SUB: - if (r = Ea (inst, &va)) /* decode eff addr */ + if ((r = Ea (inst, &va))) /* decode eff addr */ return r; - if (r = Read (va, &dat)) /* get operand */ + if ((r = Read (va, &dat))) /* get operand */ return r; A = Add24 (A, dat ^ DMASK, 1); /* subtract */ break; case SUC: - if (r = Ea (inst, &va)) /* decode eff addr */ + if ((r = Ea (inst, &va))) /* decode eff addr */ return r; - if (r = Read (va, &dat)) /* get operand */ + if ((r = Read (va, &dat))) /* get operand */ return r; OV = 0; /* clear overflow */ A = Add24 (A, dat ^ DMASK, X >> 23); /* sub with carry */ break; case ADM: - if (r = Ea (inst, &va)) /* decode eff addr */ + if ((r = Ea (inst, &va))) /* decode eff addr */ return r; - if (r = Read (va, &dat)) /* get operand */ + if ((r = Read (va, &dat))) /* get operand */ return r; dat = AddM24 (dat, A); /* mem + A */ - if (r = Write (va, dat)) /* rewrite */ + if ((r = Write (va, dat))) /* rewrite */ return r; break; case MIN: - if (r = Ea (inst, &va)) /* decode eff addr */ + if ((r = Ea (inst, &va))) /* decode eff addr */ return r; - if (r = Read (va, &dat)) /* get operand */ + if ((r = Read (va, &dat))) /* get operand */ return r; dat = AddM24 (dat, 1); /* mem + 1 */ - if (r = Write (va, dat)) /* rewrite */ + if ((r = Write (va, dat))) /* rewrite */ return r; break; case MUL: - if (r = Ea (inst, &va)) /* decode eff addr */ + if ((r = Ea (inst, &va))) /* decode eff addr */ return r; - if (r = Read (va, &dat)) /* get operand */ + if ((r = Read (va, &dat))) /* get operand */ return r; Mul48 (A, dat); /* multiply */ break; case DIV: - if (r = Ea (inst, &va)) /* decode eff addr */ + if ((r = Ea (inst, &va))) /* decode eff addr */ return r; - if (r = Read (va, &dat)) /* get operand */ + if ((r = Read (va, &dat))) /* get operand */ return r; Div48 (A, B, dat); /* divide */ break; case ETR: - if (r = Ea (inst, &va)) /* decode eff addr */ + if ((r = Ea (inst, &va))) /* decode eff addr */ return r; - if (r = Read (va, &dat)) /* get operand */ + if ((r = Read (va, &dat))) /* get operand */ return r; A = A & dat; /* and */ break; case MRG: - if (r = Ea (inst, &va)) /* decode eff addr */ + if ((r = Ea (inst, &va))) /* decode eff addr */ return r; - if (r = Read (va, &dat)) /* get operand */ + if ((r = Read (va, &dat))) /* get operand */ return r; A = A | dat; /* or */ break; case EOR: - if (r = Ea (inst, &va)) /* decode eff addr */ + if ((r = Ea (inst, &va))) /* decode eff addr */ return r; - if (r = Read (va, &dat)) /* get operand */ + if ((r = Read (va, &dat))) /* get operand */ return r; A = A ^ dat; /* xor */ break; @@ -683,75 +683,75 @@ switch (op) { /* case on opcode */ /* Skips */ case SKE: - if (r = Ea (inst, &va)) /* decode eff addr */ + if ((r = Ea (inst, &va))) /* decode eff addr */ return r; - if (r = Read (va, &dat)) /* get operand */ + if ((r = Read (va, &dat))) /* get operand */ return r; if (A == dat) /* if A = op, skip */ P = (P + 1) & VA_MASK; break; case SKG: - if (r = Ea (inst, &va)) /* decode eff addr */ + if ((r = Ea (inst, &va))) /* decode eff addr */ return r; - if (r = Read (va, &dat)) /* get operand */ + if ((r = Read (va, &dat))) /* get operand */ return r; if (SXT (A) > SXT (dat)) /* if A > op, skip */ P = (P + 1) & VA_MASK; break; case SKM: - if (r = Ea (inst, &va)) /* decode eff addr */ + if ((r = Ea (inst, &va))) /* decode eff addr */ return r; - if (r = Read (va, &dat)) /* get operand */ + if ((r = Read (va, &dat))) /* get operand */ return r; if (((A ^ dat) & B) == 0) /* if A = op masked */ P = (P + 1) & VA_MASK; break; case SKA: - if (r = Ea (inst, &va)) /* decode eff addr */ + if ((r = Ea (inst, &va))) /* decode eff addr */ return r; - if (r = Read (va, &dat)) /* get operand */ + if ((r = Read (va, &dat))) /* get operand */ return r; if ((A & dat) == 0) /* if !(A & op), skip */ P = (P + 1) & VA_MASK; break; case SKB: - if (r = Ea (inst, &va)) /* decode eff addr */ + if ((r = Ea (inst, &va))) /* decode eff addr */ return r; - if (r = Read (va, &dat)) /* get operand */ + if ((r = Read (va, &dat))) /* get operand */ return r; if ((B & dat) == 0) /* if !(B & op), skip */ P = (P + 1) & VA_MASK; break; case SKN: - if (r = Ea (inst, &va)) /* decode eff addr */ + if ((r = Ea (inst, &va))) /* decode eff addr */ return r; - if (r = Read (va, &dat)) /* get operand */ + if ((r = Read (va, &dat))) /* get operand */ return r; if (dat & SIGN) /* if op < 0, skip */ P = (P + 1) & VA_MASK; break; case SKR: - if (r = Ea (inst, &va)) /* decode eff addr */ + if ((r = Ea (inst, &va))) /* decode eff addr */ return r; - if (r = Read (va, &dat)) /* get operand */ + if ((r = Read (va, &dat))) /* get operand */ return r; dat = AddM24 (dat, DMASK); /* decr operand */ - if (r = Write (va, dat)) /* rewrite */ + if ((r = Write (va, dat))) /* rewrite */ return r; if (dat & SIGN) /* if op < 0, skip */ P = (P + 1) & VA_MASK; break; case SKD: - if (r = Ea (inst, &va)) /* decode eff addr */ + if ((r = Ea (inst, &va))) /* decode eff addr */ return r; - if (r = Read (va, &dat)) /* get operand */ + if ((r = Read (va, &dat))) /* get operand */ return r; if (SXT_EXP (B) < SXT_EXP (dat)) { /* B < dat? */ X = (dat - B) & DMASK; /* X = dat - B */ @@ -774,29 +774,29 @@ switch (op) { /* case on opcode */ exu_cnt = exu_cnt + 1; /* count chained EXU */ if (exu_cnt > exu_lim) /* too many? */ return STOP_EXULIM; - if (r = Ea (inst, &va)) /* decode eff addr */ + if ((r = Ea (inst, &va))) /* decode eff addr */ return r; - if (r = Read (va, &dat)) /* get operand */ + if ((r = Read (va, &dat))) /* get operand */ return r; inst = dat; goto EXU_LOOP; case BRU: if (nml_mode && (inst & I_IND)) api_dismiss (); /* normal BRU*, dism */ - if (r = Ea (inst, &va)) /* decode eff addr */ + if ((r = Ea (inst, &va))) /* decode eff addr */ return r; - if (r = Read (va, &dat)) /* get operand */ + if ((r = Read (va, &dat))) /* get operand */ return r; PCQ_ENTRY; P = va & VA_MASK; /* branch */ break; case BRX: - if (r = Ea (inst, &va)) /* decode eff addr */ + if ((r = Ea (inst, &va))) /* decode eff addr */ return r; X = (X + 1) & DMASK; /* incr X */ if (X & I_IND) { /* bit 9 set? */ - if (r = Read (va, &dat)) /* test dest access */ + if ((r = Read (va, &dat))) /* test dest access */ return r; PCQ_ENTRY; P = va & VA_MASK; /* branch */ @@ -804,22 +804,22 @@ switch (op) { /* case on opcode */ break; case BRM: - if (r = Ea (inst, &va)) /* decode eff addr */ + if ((r = Ea (inst, &va))) /* decode eff addr */ return r; dat = (EM3 << 18) | (EM2 << 15) | pc; /* form return word */ if (!nml_mode && !usr_mode) /* monitor mode? */ dat = dat | (mode << 23) | (OV << 21); else dat = dat | (OV << 23); /* normal or user */ - if (r = Write (va, dat)) /* write ret word */ + if ((r = Write (va, dat))) /* write ret word */ return r; PCQ_ENTRY; P = (va + 1) & VA_MASK; /* branch */ break; case BRR: - if (r = Ea (inst, &va)) /* decode eff addr */ + if ((r = Ea (inst, &va))) /* decode eff addr */ return r; - if (r = Read (va, &dat)) /* get operand */ + if ((r = Read (va, &dat))) /* get operand */ return r; PCQ_ENTRY; P = (dat + 1) & VA_MASK; /* branch */ @@ -837,9 +837,9 @@ switch (op) { /* case on opcode */ case BRI: if (!nml_mode && usr_mode) /* priv inst */ return MM_PRVINS; - if (r = Ea (inst, &va)) /* decode eff addr */ + if ((r = Ea (inst, &va))) /* decode eff addr */ return r; - if (r = Read (va, &dat)) /* get operand */ + if ((r = Read (va, &dat))) /* get operand */ return r; api_dismiss (); /* dismiss hi api */ PCQ_ENTRY; @@ -909,7 +909,7 @@ switch (op) { /* case on opcode */ /* Shifts */ case RSH: - if (r = EaSh (inst, &va)) /* decode eff addr */ + if ((r = EaSh (inst, &va))) /* decode eff addr */ return r; shf_op = I_GETSHFOP (va); /* get eff op */ sc = va & I_SHFMSK; /* get eff count */ @@ -934,7 +934,7 @@ switch (op) { /* case on opcode */ break; case LSH: - if (r = EaSh (inst, &va)) /* decode eff addr */ + if ((r = EaSh (inst, &va))) /* decode eff addr */ return r; shf_op = I_GETSHFOP (va); /* get eff op */ sc = va & I_SHFMSK; /* get eff count */ @@ -989,11 +989,11 @@ switch (op) { /* case on opcode */ case MIW: case MIY: if (!nml_mode && usr_mode) /* priv inst */ return MM_PRVINS; - if (r = Ea (inst, &va)) /* decode eff addr */ + if ((r = Ea (inst, &va))) /* decode eff addr */ return r; - if (r = Read (va, &dat)) /* get operand */ + if ((r = Read (va, &dat))) /* get operand */ return r; - if (r = op_miwy (inst, dat)) /* process inst */ + if ((r = op_miwy (inst, dat))) /* process inst */ return r; int_reqhi = api_findreq (); /* recalc int req */ chan_req = chan_testact (); /* recalc chan act */ @@ -1002,11 +1002,11 @@ switch (op) { /* case on opcode */ case WIM: case YIM: if (!nml_mode && usr_mode) /* priv inst */ return MM_PRVINS; - if (r = Ea (inst, &va)) /* decode eff addr */ + if ((r = Ea (inst, &va))) /* decode eff addr */ return r; - if (r = op_wyim (inst, &dat)) /* process inst */ + if ((r = op_wyim (inst, &dat))) /* process inst */ return r; - if (r = Write (va, dat)) + if ((r = Write (va, dat))) return r; /* write result */ int_reqhi = api_findreq (); /* recalc int req */ chan_req = chan_testact (); /* recalc chan act */ @@ -1015,7 +1015,7 @@ switch (op) { /* case on opcode */ case EOM: case EOD: if (!nml_mode && usr_mode) /* priv inst */ return MM_PRVINS; - if (r = op_eomd (inst)) /* process inst */ + if ((r = op_eomd (inst))) /* process inst */ return r; int_reqhi = api_findreq (); /* recalc int req */ chan_req = chan_testact (); /* recalc chan act */ @@ -1025,11 +1025,11 @@ switch (op) { /* case on opcode */ case POT: if (!nml_mode && usr_mode) /* priv inst */ return MM_PRVINS; - if (r = Ea (inst, &va)) /* decode eff addr */ + if ((r = Ea (inst, &va))) /* decode eff addr */ return r; - if (r = Read (va, &dat)) /* get operand */ + if ((r = Read (va, &dat))) /* get operand */ return r; - if (r = op_pot (dat)) /* process inst */ + if ((r = op_pot (dat))) /* process inst */ return r; int_reqhi = api_findreq (); /* recalc int req */ chan_req = chan_testact (); /* recalc chan act */ @@ -1038,11 +1038,11 @@ switch (op) { /* case on opcode */ case PIN: if (!nml_mode && usr_mode) /* priv inst */ return MM_PRVINS; - if (r = Ea (inst, &va)) /* decode eff addr */ + if ((r = Ea (inst, &va))) /* decode eff addr */ return r; - if (r = op_pin (&dat)) /* process inst */ + if ((r = op_pin (&dat))) /* process inst */ return r; - if (r = Write (va, dat)) /* write result */ + if ((r = Write (va, dat))) /* write result */ return r; int_reqhi = api_findreq (); /* recalc int req */ chan_req = chan_testact (); /* recalc chan act */ @@ -1051,7 +1051,7 @@ switch (op) { /* case on opcode */ case SKS: if (!nml_mode && usr_mode) /* priv inst */ return MM_PRVINS; - if (r = op_sks (inst, &dat)) /* process inst */ + if ((r = op_sks (inst, &dat))) /* process inst */ return r; if (dat) P = (P + 1) & VA_MASK; @@ -1085,7 +1085,7 @@ for (i = 0; i < ind_lim; i++) { /* count indirects */ hst[hst_p].ea = *addr; return SCPE_OK; } - if (r = Read (va, &wd)) /* read ind; fails? */ + if ((r = Read (va, &wd))) /* read ind; fails? */ return r; va = (va & VA_USR) | (wd & XVA_MASK); } @@ -1112,7 +1112,7 @@ for (i = 0; i < ind_lim; i++) { /* count indirects */ } if (wd & I_IDX) va = (va & VA_USR) | ((va + X) & VA_MASK); - if (r = Read (va, &wd)) /* read ind; fails? */ + if ((r = Read (va, &wd))) /* read ind; fails? */ return r; va = (va & VA_USR) | (wd & XVA_MASK); } @@ -1569,12 +1569,12 @@ if (op == MIN) /* incr */ else if (op == SKR) /* decr */ val = DMASK; else return STOP_RTCINS; /* can't do it */ -if (r = Ea (inst, &va)) /* decode eff addr */ +if ((r = Ea (inst, &va))) /* decode eff addr */ return r; -if (r = Read (va, &dat)) /* get operand */ +if ((r = Read (va, &dat))) /* get operand */ return r; dat = AddM24 (dat, val); /* mem +/- 1 */ -if (r = Write (va, dat)) /* rewrite */ +if ((r = Write (va, dat))) /* rewrite */ return r; if (dat == 0) /* set clk sync int */ int_req = int_req | INT_RTCS; diff --git a/SDS/sds_dsk.c b/SDS/sds_dsk.c index cf9d41ea..22d0a7a3 100644 --- a/SDS/sds_dsk.c +++ b/SDS/sds_dsk.c @@ -204,7 +204,7 @@ switch (fnc) { /* case on function */ case IO_READ: xfr_req = xfr_req & ~XFR_DSK; /* clr xfr req */ if (dsk_bptr >= dsk_blnt) { /* no more data? */ - if (r = dsk_read_buf (inst)) /* read sector */ + if ((r = dsk_read_buf (inst))) /* read sector */ return r; } dsk_wptr = dsk_bptr >> 2; /* word pointer */ @@ -219,7 +219,7 @@ switch (fnc) { /* case on function */ case IO_WRITE: xfr_req = xfr_req & ~XFR_DSK; /* clr xfr req */ if (dsk_bptr >= (DSK_NUMWD * 4)) { /* full? */ - if (r = dsk_write_buf (inst)) /* write sector */ + if ((r = dsk_write_buf (inst))) /* write sector */ return r; } dsk_wptr = dsk_bptr >> 2; /* word pointer */ diff --git a/SDS/sds_io.c b/SDS/sds_io.c index 4e4dd22b..bd0b01f4 100644 --- a/SDS/sds_io.c +++ b/SDS/sds_io.c @@ -336,7 +336,7 @@ switch (mod) { chan_mode[ch] = chan_uar[ch] = 0; if (ch >= CHAN_E) chan_mode[ch] = CHM_CE; - if (r = dev_dsp[dev][ch] (IO_CONN, inst, NULL)) /* connect */ + if ((r = dev_dsp[dev][ch] (IO_CONN, inst, NULL)))/* connect */ return r; if ((inst & I_IND) || (ch >= CHAN_C)) { /* C-H? alert ilc */ alert = POT_ILCY + ch; @@ -958,7 +958,7 @@ for (i = 0; i < NUM_CHAN; i++) { /* Test each device for conflict; add to map; init tables */ -for (i = 0; dptr = sim_devices[i]; i++) { /* loop thru devices */ +for (i = 0; (dptr = sim_devices[i]); i++) { /* loop thru devices */ dibp = (DIB *) dptr->ctxt; /* get DIB */ if ((dibp == NULL) || (dptr->flags & DEV_DIS)) /* exist, enabled? */ continue; diff --git a/SDS/sds_lp.c b/SDS/sds_lp.c index 0de82e70..cbef5249 100644 --- a/SDS/sds_lp.c +++ b/SDS/sds_lp.c @@ -177,7 +177,7 @@ switch (fnc) { /* case function */ t = I_GETSKCND (inst); /* sks cond */ if (((t == 020) && (!CHP (7, lpt_cct[lpt_ccp]))) || /* 14062: !ch 7 */ ((t == 010) && (lpt_unit.flags & UNIT_ATT)) || /* 12062: !online */ - (t == 004) && !lpt_err) /* 11062: !err */ + ((t == 004) && !lpt_err)) /* 11062: !err */ *dat = 1; break; diff --git a/SDS/sds_mt.c b/SDS/sds_mt.c index 163d7d23..3e398ac5 100644 --- a/SDS/sds_mt.c +++ b/SDS/sds_mt.c @@ -235,14 +235,14 @@ switch (fnc) { /* case function */ case IO_DISC: /* disconnect */ sim_cancel (uptr); /* no more xfr's */ if (inst & DEV_OUT) { /* write? */ - if (r = mt_wrend (inst)) /* end record */ + if ((r = mt_wrend (inst))) /* end record */ return r; } break; case IO_WREOR: /* write eor */ chan_set_flag (mt_dib.chan, CHF_EOR); /* set eor flg */ - if (r = mt_wrend (inst)) /* end record */ + if ((r = mt_wrend (inst))) /* end record */ return r; mt_gap = 1; /* in gap */ sim_activate (uptr, mt_gtime); /* start timer */ diff --git a/SDS/sds_mux.c b/SDS/sds_mux.c index ef6203fd..8cc7023a 100644 --- a/SDS/sds_mux.c +++ b/SDS/sds_mux.c @@ -363,7 +363,7 @@ if (ln >= 0) { /* got one? */ tmxr_poll_rx (&mux_desc); /* poll for input */ for (ln = 0; ln < MUX_NUMLIN; ln++) { /* loop thru lines */ if (mux_ldsc[ln].conn) { /* connected? */ - if (c = tmxr_getc_ln (&mux_ldsc[ln])) { /* get char */ + if ((c = tmxr_getc_ln (&mux_ldsc[ln]))) { /* get char */ if (mux_sta[ln] & MUX_SCHP) /* already got one? */ mux_sta[ln] = mux_sta[ln] | MUX_SOVR; /* overrun */ else mux_sta[ln] = mux_sta[ln] | MUX_SCHP; /* char pending */ diff --git a/SDS/sds_stddev.c b/SDS/sds_stddev.c index 7899228b..13877418 100644 --- a/SDS/sds_stddev.c +++ b/SDS/sds_stddev.c @@ -395,7 +395,7 @@ t_stat r = SCPE_OK; if (ptp_ldr) { /* need leader? */ for (i = 0; i < 12; i++) { /* punch leader */ - if (r = ptp_out (0)) + if ((r = ptp_out (0))) break; } } diff --git a/VAX/vax780_defs.h b/VAX/vax780_defs.h index 9e170172..f47b8656 100644 --- a/VAX/vax780_defs.h +++ b/VAX/vax780_defs.h @@ -313,6 +313,8 @@ typedef struct { #define IOLN_PTR 004 #define IOBA_PTP (IOPAGEBASE + 017554) /* PC11 punch */ #define IOLN_PTP 004 +#define IOBA_DMC (IOPAGEBASE + 0760060) +#define IOLN_DMC 010 /* Interrupt assignments; within each level, priority is right to left */ @@ -325,6 +327,8 @@ typedef struct { #define INT_V_TS 6 #define INT_V_RY 7 #define INT_V_XU 8 +#define INT_V_DMCRX 9 +#define INT_V_DMCTX 10 #define INT_V_LPT 0 /* BR4 */ #define INT_V_PTR 1 @@ -348,6 +352,8 @@ typedef struct { #define INT_PTR (1u << INT_V_PTR) #define INT_PTP (1u << INT_V_PTP) #define INT_CR (1u << INT_V_CR) +#define INT_DMCRX (1u << INT_V_DMCRX) +#define INT_DMCTX (1u << INT_V_DMCTX) #define IPL_DZRX (0x15 - IPL_HMIN) #define IPL_DZTX (0x15 - IPL_HMIN) @@ -364,6 +370,8 @@ typedef struct { #define IPL_CR (0x14 - IPL_HMIN) #define IPL_VHRX (0x14 - IPL_HMIN) #define IPL_VHTX (0x14 - IPL_HMIN) +#define IPL_DMCRX (0x15 - IPL_HMIN) +#define IPL_DMCTX (0x15 - IPL_HMIN) /* Device vectors */ @@ -386,6 +394,8 @@ typedef struct { #define VEC_DZTX 0304 #define VEC_VHRX 0310 #define VEC_VHTX 0314 +#define VEC_DMCRX 0310 +#define VEC_DMCTX 0314 /* Interrupt macros */ diff --git a/VAX/vax780_sbi.c b/VAX/vax780_sbi.c index 430aa807..54ac86aa 100644 --- a/VAX/vax780_sbi.c +++ b/VAX/vax780_sbi.c @@ -224,7 +224,7 @@ CTAB vax780_cmd[] = { Instead, the interrupt handler for a given UBA IPL reads a vector register that contains the Unibus vector for that IPL. - +*/ /* Find highest priority vectorable interrupt */ int32 eval_int (void) @@ -646,7 +646,7 @@ DIB *dibp; t_stat r; regptr = get_glyph (ptr, gbuf, 0); /* get glyph */ -if (slptr = strchr (gbuf, '/')) { /* found slash? */ +if ((slptr = strchr (gbuf, '/'))) { /* found slash? */ regptr = strchr (ptr, '/'); /* locate orig */ *slptr = 0; /* zero in string */ } @@ -702,7 +702,7 @@ if (r != SCPE_OK) { #ifndef DONT_USE_INTERNAL_ROM FILE *f; - if (f = sim_fopen ("vmb.exe", "wb")) { + if ((f = sim_fopen ("vmb.exe", "wb"))) { printf ("Saving boot code to vmb.exe\n"); if (sim_log) fprintf (sim_log, "Saving boot code to vmb.exe\n"); @@ -810,15 +810,15 @@ for (i = 0; (dptr = sim_devices[i]) != NULL; i++) { /* loop thru dev */ dibp = (DIB *) dptr->ctxt; /* get DIB */ if (dibp && !(dptr->flags & DEV_DIS)) { /* defined, enabled? */ if (dptr->flags & DEV_NEXUS) { /* Nexus? */ - if (r = build_nexus_tab (dptr, dibp)) /* add to dispatch table */ + if ((r = build_nexus_tab (dptr, dibp))) /* add to dispatch table */ return r; } else if (dptr->flags & DEV_MBUS) { /* Massbus? */ - if (r = build_mbus_tab (dptr, dibp)) + if ((r = build_mbus_tab (dptr, dibp))) return r; } else { /* no, Unibus device */ - if (r = build_ubus_tab (dptr, dibp)) /* add to dispatch tab */ + if ((r = build_ubus_tab (dptr, dibp))) /* add to dispatch tab */ return r; } /* end else */ } /* end if enabled */ diff --git a/VAX/vax780_syslist.c b/VAX/vax780_syslist.c index 9025f616..8d179231 100644 --- a/VAX/vax780_syslist.c +++ b/VAX/vax780_syslist.c @@ -54,6 +54,8 @@ extern DEVICE tu_dev; extern DEVICE dz_dev; extern DEVICE vh_dev; extern DEVICE xu_dev, xub_dev; +extern DEVICE dmc_dev[]; +extern DEVICE dmp_dev[]; extern int32 sim_switches; extern UNIT cpu_unit; @@ -91,6 +93,11 @@ DEVICE *sim_devices[] = { &tq_dev, &xu_dev, &xub_dev, + &dmc_dev[0], + &dmc_dev[1], + &dmc_dev[2], + &dmc_dev[3], + &dmp_dev[0], NULL }; diff --git a/VAX/vax_cis.c b/VAX/vax_cis.c index e75a53b8..3eec163e 100644 --- a/VAX/vax_cis.c +++ b/VAX/vax_cis.c @@ -331,7 +331,7 @@ switch (opc) { /* case on opcode */ R[3] = (R[3] + 1) & LMASK; /* next string char */ if (i >= sim_interval) { /* done with interval? */ sim_interval = 0; - if (r = sim_process_event ()) { /* presumably WRU */ + if ((r = sim_process_event ())) { /* presumably WRU */ PC = fault_PC; /* backup up PC */ ABORT (r); /* abort flushes IB */ } @@ -1225,8 +1225,8 @@ for (i = 0; i <= end; i++) { /* loop thru string */ } if ((i == end) && ((lnt & 1) == 0)) c = c & 0xF; -/* if (((c & 0xF0) > 0x90) || /* check hi digit */ -/* ((c & 0x0F) > 0x09)) /* check lo digit */ +/* if (((c & 0xF0) > 0x90) || *//* check hi digit */ +/* ((c & 0x0F) > 0x09)) *//* check lo digit */ /* RSVD_OPND_FAULT; */ src->val[i / 4] = src->val[i / 4] | (c << ((i % 4) * 8)); } /* end for */ @@ -1550,7 +1550,7 @@ uint32 NibbleRshift (DSTR *dsrc, int32 sc, uint32 cin) { int32 i, s, nc; -if (s = sc * 4) { +if ((s = sc * 4)) { for (i = DSTRMAX; i >= 0; i--) { nc = (dsrc->val[i] << (32 - s)) & LMASK; dsrc->val[i] = ((dsrc->val[i] >> s) | @@ -1574,7 +1574,7 @@ uint32 NibbleLshift (DSTR *dsrc, int32 sc, uint32 cin) { int32 i, s, nc; -if (s = sc * 4) { +if ((s = sc * 4)) { for (i = 0; i < DSTRLNT; i++) { nc = dsrc->val[i] >> (32 - s); dsrc->val[i] = ((dsrc->val[i] << s) | diff --git a/VAX/vax_cmode.c b/VAX/vax_cmode.c index 24c7f8ac..dbf6d4cf 100644 --- a/VAX/vax_cmode.c +++ b/VAX/vax_cmode.c @@ -621,7 +621,7 @@ switch ((IR >> 12) & 017) { /* decode IR<15:12> */ else src2 = RdMemW (GeteaW (dstspec)); src2 = src2 & 077; src = RdRegW (srcspec); /* get src */ - if (sign = ((src & WSIGN)? 1: 0)) + if ((sign = ((src & WSIGN)? 1: 0))) src = src | ~WMASK; if (src2 == 0) { /* [0] */ dst = src; /* result */ diff --git a/VAX/vax_cpu.c b/VAX/vax_cpu.c index 7614cd00..b751e352 100644 --- a/VAX/vax_cpu.c +++ b/VAX/vax_cpu.c @@ -640,7 +640,7 @@ for ( ;; ) { */ if (trpirq) { /* trap or interrupt? */ - if (temp = GET_TRAP (trpirq)) { /* trap? */ + if ((temp = GET_TRAP (trpirq))) { /* trap? */ cc = intexc (SCB_ARITH, cc, 0, IE_EXC); /* take, clear trap */ GET_CUR; /* set cur mode */ in_ie = 1; @@ -648,7 +648,7 @@ for ( ;; ) { SP = SP - 4; in_ie = 0; } - else if (temp = GET_IRQL (trpirq)) { /* interrupt? */ + else if ((temp = GET_IRQL (trpirq))) { /* interrupt? */ int32 vec; if (temp == IPL_HLTPIN) { /* console halt? */ hlt_pin = 0; /* clear intr */ diff --git a/VAX/vax_defs.h b/VAX/vax_defs.h index 5592a066..27f05cb7 100644 --- a/VAX/vax_defs.h +++ b/VAX/vax_defs.h @@ -473,7 +473,7 @@ #define PR_PACV 2 /* pte ACV (780) */ #define PR_PLNV 3 /* pte len viol */ #define PR_TNV 4 /* TNV */ -/* #define PR_TB 5 /* impossible */ +/* #define PR_TB 5 *//* impossible */ #define PR_PTNV 6 /* pte TNV */ #define PR_OK 7 /* ok */ #define MM_PARAM(w,p) (((w)? 4: 0) | ((p) & 3)) /* fault param */ diff --git a/VAX/vax_io.c b/VAX/vax_io.c index 8d6baab0..95b46073 100644 --- a/VAX/vax_io.c +++ b/VAX/vax_io.c @@ -792,7 +792,7 @@ init_ubus_tab (); /* init bus tables */ for (i = 0; (dptr = sim_devices[i]) != NULL; i++) { /* loop thru dev */ dibp = (DIB *) dptr->ctxt; /* get DIB */ if (dibp && !(dptr->flags & DEV_DIS)) { /* defined, enabled? */ - if (r = build_ubus_tab (dptr, dibp)) /* add to bus tab */ + if ((r = build_ubus_tab (dptr, dibp))) /* add to bus tab */ return r; } /* end if enabled */ } /* end for */ diff --git a/VAX/vax_octa.c b/VAX/vax_octa.c index efb1a99c..c46b2718 100644 --- a/VAX/vax_octa.c +++ b/VAX/vax_octa.c @@ -187,7 +187,7 @@ switch (opc) { break; case MOVH: - if (r = op_tsth (opnd[0])) { /* test for 0 */ + if ((r = op_tsth (opnd[0]))) { /* test for 0 */ h_write_o (spec, va, opnd, acc); /* nz, write result */ CC_IIZP_FP (r); /* set cc's */ } @@ -198,7 +198,7 @@ switch (opc) { break; case MNEGH: - if (r = op_tsth (opnd[0])) { /* test for 0 */ + if ((r = op_tsth (opnd[0]))) { /* test for 0 */ opnd[0] = opnd[0] ^ FPSIGN; /* nz, invert sign */ h_write_o (spec, va, opnd, acc); /* write result */ CC_IIZZ_FP (opnd[0]); /* set cc's */ diff --git a/VAX/vax_sys.c b/VAX/vax_sys.c index f33b2edd..0cf2f482 100644 --- a/VAX/vax_sys.c +++ b/VAX/vax_sys.c @@ -1173,7 +1173,7 @@ const char *force[] = { "S^", "I^", "B^", "W^", "L^", NULL }; *r = SCPE_OK; /* assume ok */ M1C ('@', SP_IND); /* look for @ */ -if (tptr = parse_rnum (cptr, &rn)) { /* look for Rn */ +if ((tptr = parse_rnum (cptr, &rn))) { /* look for Rn */ if (*cptr == '[') { /* look for [Rx] */ cptr = parse_rnum (++cptr, &index); if ((cptr == NULL) || (*cptr++ != ']')) diff --git a/VAX/vax_syscm.c b/VAX/vax_syscm.c index 40cec63b..46225523 100644 --- a/VAX/vax_syscm.c +++ b/VAX/vax_syscm.c @@ -1,6 +1,6 @@ /* vax_syscm.c: PDP-11 compatibility mode symbolic decode and parse - Copyright (c) 1993-2010, Robert M Supnik + Copyright (c) 1993-2012, Robert M Supnik Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), @@ -23,6 +23,7 @@ used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from Robert M Supnik. + 29-Apr-12 RMS Fixed compiler warning (Mark Pizzolato) 22-May-10 RMS Fixed t_addr printouts for 64b big-endian systems (Mark Pizzolato) 12-Nov-06 RMS Fixed operand order in EIS instructions (W.F.J. Mueller) @@ -610,7 +611,7 @@ switch (j) { /* case on class */ return SCPE_ARG; if ((pflag & A_REL) == 0) disp = (disp - ad32) & 0177777; - if ((disp & 1) || (disp > 0400) && (disp < 0177402)) + if ((disp & 1) || ((disp > 0400) && (disp < 0177402))) return SCPE_ARG; val[0] = val[0] | (((disp - 2) >> 1) & 0377); break; diff --git a/VAX/vax_sysdev.c b/VAX/vax_sysdev.c index 885e64b8..03c62937 100644 --- a/VAX/vax_sysdev.c +++ b/VAX/vax_sysdev.c @@ -481,16 +481,17 @@ return ((val << 24) & 0xff000000) | (( val << 8) & 0xff0000) | ((val >> 8) & 0xff00) | ((val >> 24) & 0xff); } +volatile int32 rom_loopval = 0; + int32 rom_read_delay (int32 val) { uint32 i, l = rom_delay; -int32 loopval = 0; if (rom_unit.flags & UNIT_NODELAY) return val; /* Calibrate the loop delay factor when first used. - Do this 4 times to and use the largest value computed. */ + Do this 4 times and use the largest value computed. */ if (rom_delay == 0) { uint32 ts, te, c = 10000, samples = 0; @@ -503,15 +504,15 @@ if (rom_delay == 0) { away by a good compiler. loopval always is zero. To avoid smart compilers, the loopval variable is referenced in the function arguments so that the function expression is not loop invariant. It also must be referenced - by subsequent code or to avoid the whole computation being eliminated. */ + by subsequent code to avoid the whole computation being eliminated. */ for (i = 0; i < c; i++) - loopval |= (loopval + ts) ^ rom_swapb (rom_swapb (loopval + ts)); + rom_loopval |= (rom_loopval + ts) ^ rom_swapb (rom_swapb (rom_loopval + ts)); te = sim_os_msec (); if ((te - ts) < 50) /* sample big enough? */ continue; - if (rom_delay < (loopval + (c / (te - ts) / 1000) + 1)) - rom_delay = loopval + (c / (te - ts) / 1000) + 1; + if (rom_delay < (rom_loopval + (c / (te - ts) / 1000) + 1)) + rom_delay = rom_loopval + (c / (te - ts) / 1000) + 1; if (++samples >= 4) break; c = c / 2; @@ -521,8 +522,8 @@ if (rom_delay == 0) { } for (i = 0; i < l; i++) - loopval |= (loopval + val) ^ rom_swapb (rom_swapb (loopval + val)); -return val + loopval; + rom_loopval |= (rom_loopval + val) ^ rom_swapb (rom_swapb (rom_loopval + val)); +return val + rom_loopval; } int32 rom_rd (int32 pa) @@ -1563,7 +1564,7 @@ if (*rom == 0) { /* no boot? */ #ifndef DONT_USE_INTERNAL_ROM FILE *f; - if (f = sim_fopen ("ka655x.bin", "wb")) { + if ((f = sim_fopen ("ka655x.bin", "wb"))) { printf ("Saving boot code to ka655x.bin\n"); if (sim_log) fprintf (sim_log, "Saving boot code to ka655x.bin\n"); diff --git a/VAX/vaxmod_defs.h b/VAX/vaxmod_defs.h index 85e9459d..2f235481 100644 --- a/VAX/vaxmod_defs.h +++ b/VAX/vaxmod_defs.h @@ -178,7 +178,7 @@ /* CMCTL registers */ -/* #define CMCTLSIZE (18 << 2) /* 18 registers */ +/* #define CMCTLSIZE (18 << 2) *//* 18 registers */ #define CMCTLSIZE (19 << 2) /* KA655X extra reg */ #define CMCTLBASE (REGBASE + 0x100) /* CMCTL addr base */ diff --git a/Visual Studio Projects/0ReadMe_Projects.txt b/Visual Studio Projects/0ReadMe_Projects.txt index 8b90b547..4640df79 100644 --- a/Visual Studio Projects/0ReadMe_Projects.txt +++ b/Visual Studio Projects/0ReadMe_Projects.txt @@ -21,7 +21,7 @@ For Example, the directory structure should look like: The contents of the windows-build directory can be downloaded from: - https://github.com/downloads/markpizz/simh/windows-build.zip + https://github.com/downloads/simh/simh/windows-build.zip Network devices are capable of using pthreads to enhance their performance. diff --git a/Visual Studio Projects/PDP11.vcproj b/Visual Studio Projects/PDP11.vcproj index ae07e30c..811accda 100644 --- a/Visual Studio Projects/PDP11.vcproj +++ b/Visual Studio Projects/PDP11.vcproj @@ -400,10 +400,6 @@ Name="Header Files" Filter="h;hpp;hxx;hm;inl;inc" > - - diff --git a/Visual Studio Projects/VAX.vcproj b/Visual Studio Projects/VAX.vcproj index 9470b3a8..71ea3fd3 100644 --- a/Visual Studio Projects/VAX.vcproj +++ b/Visual Studio Projects/VAX.vcproj @@ -365,10 +365,6 @@ Name="Header Files" Filter="h;hpp;hxx;hm;inl;inc" > - - diff --git a/Visual Studio Projects/VAX780.vcproj b/Visual Studio Projects/VAX780.vcproj index 2330cab2..b45a8216 100644 --- a/Visual Studio Projects/VAX780.vcproj +++ b/Visual Studio Projects/VAX780.vcproj @@ -205,6 +205,10 @@ RelativePath="..\PDP11\pdp11_cr.c" > + + @@ -392,7 +396,7 @@ Filter="h;hpp;hxx;hm;inl;inc" > &1 | grep 'gcc version' | awk '{ print $$3 }') + ifeq (,$(shell $(GCC) -v /dev/null 2>&1 | grep 'clang version')) + GCC_VERSION = $(shell $(GCC) -v /dev/null 2>&1 | grep 'gcc version' | awk '{ print $$3 }') + COMPILER_NAME = GCC Version: $(GCC_VERSION) + else + COMPILER_NAME = $(shell $(GCC) -v /dev/null 2>&1 | grep 'clang version' | awk '{ print $$1 " " $$2 " " $$3 }') + CLANG_VERSION = $(word 3,$(COMPILER_NAME)) + ifeq (,$(findstring .,$(CLANG_VERSION))) + COMPILER_NAME = $(shell $(GCC) -v /dev/null 2>&1 | grep 'clang version' | awk '{ print $$1 " " $$2 " " $$3 " " $$4 }') + CLANG_VERSION = $(word 4,$(COMPILER_NAME)) + endif + endif LTO_EXCLUDE_VERSIONS = PCAPLIB = pcap ifeq (agcc,$(findstring agcc,$(GCC))) # Android target build? @@ -85,8 +99,10 @@ ifeq ($(WIN32),) #*nix Environments (&& cygwin) OSNAME = OSX LIBEXT = dylib # OSX's XCode gcc doesn't support LTO, but gcc built to explicitly enable it will work - ifeq (,$(shell $(GCC) -v /dev/null 2>&1 | grep '\-\-enable-lto')) - LTO_EXCLUDE_VERSIONS += $(GCC_VERSION) + ifneq (,$(GCC_VERSION)) + ifeq (,$(shell $(GCC) -v /dev/null 2>&1 | grep '\-\-enable-lto')) + LTO_EXCLUDE_VERSIONS += $(GCC_VERSION) + endif endif else ifeq (Linux,$(OSTYPE)) @@ -253,7 +269,7 @@ ifeq ($(WIN32),) #*nix Environments (&& cygwin) NETWORK_OPT = $(NETWORK_CCDEFS) endif ifneq (binexists,$(shell if $(TEST) -e BIN; then echo binexists; fi)) - MKDIRBIN = if $(TEST) ! -e BIN; then mkdir BIN; fi + MKDIRBIN = mkdir -p BIN endif else #Win32 Environments (via MinGW32) @@ -304,7 +320,15 @@ ifneq ($(DEBUG),) CFLAGS_O = -O0 BUILD_FEATURES = - debugging support else - CFLAGS_O = -O2 + ifneq (clang,$(findstring clang,$(COMPILER_NAME))) + CFLAGS_O = -O2 + else + ifeq (Darwin,$(OSTYPE)) + CFLAGS_O += -O4 -fno-strict-overflow -flto -fwhole-program + else + CFLAGS_O := -O2 -fno-strict-overflow + endif + endif LDFLAGS_O = GCC_MAJOR_VERSION = $(firstword $(subst ., ,$(GCC_VERSION))) ifneq (3,$(GCC_MAJOR_VERSION)) @@ -351,7 +375,7 @@ ifneq (3,$(GCC_MAJOR_VERSION)) endif endif ifneq (clean,$(MAKECMDGOALS)) - BUILD_FEATURES := $(BUILD_FEATURES). GCC Version: $(GCC_VERSION) + BUILD_FEATURES := $(BUILD_FEATURES). $(COMPILER_NAME) $(info ***) $(info *** $(BUILD_SINGLE)Simulator$(BUILD_MULTIPLE) being built with:) $(info *** $(BUILD_FEATURES).) @@ -456,7 +480,7 @@ VAX780 = ${VAXD}/vax_cpu.c ${VAXD}/vax_cpu1.c ${VAXD}/vax_fpa.c \ ${PDP11D}/pdp11_dz.c ${PDP11D}/pdp11_lp.c ${PDP11D}/pdp11_tq.c \ ${PDP11D}/pdp11_xu.c ${PDP11D}/pdp11_ry.c ${PDP11D}/pdp11_cr.c \ ${PDP11D}/pdp11_rp.c ${PDP11D}/pdp11_tu.c ${PDP11D}/pdp11_hk.c \ - ${PDP11D}/pdp11_vh.c ${PDP11D}/pdp11_io_lib.c + ${PDP11D}/pdp11_vh.c ${PDP11D}/pdp11_dmc.c \${PDP11D}/pdp11_io_lib.c VAX780_OPT = -DVM_VAX -DVAX_780 -DUSE_INT64 -DUSE_ADDR64 -I VAX -I ${PDP11D} ${NETWORK_OPT} @@ -815,3 +839,4 @@ swtp6800mp-a2 : ${BIN}swtp6800mp-a2${EXE} ${BIN}swtp6800mp-a2${EXE} : ${SWTP6800MP-A2} ${SIM} ${MKDIRBIN} ${CC} ${SWTP6800MP-A2} ${SIM} ${SWTP6800_OPT} $(CC_OUTSPEC) ${LDFLAGS} + diff --git a/scp.c b/scp.c index 110cec00..84da28a2 100644 --- a/scp.c +++ b/scp.c @@ -72,9 +72,9 @@ Fixed bug in restoration with changed memory size 08-Mar-07 JDB Fixed breakpoint actions in DO command file processing 30-Jan-07 RMS Fixed bugs in get_ipaddr - 30-Aug-06 JDB detach_unit returns SCPE_UNATT if not attached 17-Oct-06 RMS Added idle support 04-Oct-06 JDB DO cmd failure now echoes cmd unless -q + 30-Aug-06 JDB detach_unit returns SCPE_UNATT if not attached 14-Jul-06 RMS Added sim_activate_abs 02-Jun-06 JDB Fixed do_cmd to exit nested files on assertion failure Added -E switch to do_cmd to exit on any error @@ -218,6 +218,7 @@ #include "sim_rev.h" #include "sim_ether.h" #include "sim_serial.h" +#include "sim_sock.h" #include #include #include @@ -752,7 +753,7 @@ int setenv(const char *envname, const char *envval, int overwrite) int main (int argc, char *argv[]) { -char cbuf[CBUFSIZE], gbuf[CBUFSIZE], *cptr; +char cbuf[CBUFSIZE], gbuf[CBUFSIZE], *cptr, *cptr2; char nbuf[PATH_MAX + 7]; int32 i, sw; t_bool lookswitch; @@ -788,7 +789,9 @@ for (i = 1; i < argc; i++) { /* loop thru args */ } } /* end for */ sim_quiet = sim_switches & SWMASK ('Q'); /* -q means quiet */ +sim_on_inherit = sim_switches & SWMASK ('O'); /* -o means inherit on state */ +sim_init_sock (); /* init socket capabilities */ AIO_INIT; /* init Asynch I/O */ if (sim_vm_init != NULL) /* call once only */ (*sim_vm_init)(); @@ -832,10 +835,14 @@ if (sim_dflt_dev == NULL) /* if no default */ sim_dflt_dev = sim_devices[0]; cptr = getenv("HOME"); -if (cptr == NULL) +if (cptr == NULL) { cptr = getenv("HOMEPATH"); + cptr2 = getenv("HOMEDRIVE"); + } +else + cptr2 = NULL; if (cptr && sizeof (nbuf) > strlen (cptr) + strlen ("/simh.ini") + 1) { - sprintf(nbuf, "%s%ssimh.ini", cptr, strchr (cptr, '/') ? "/" : "\\"); + sprintf(nbuf, "\"%s%s%ssimh.ini\"", cptr2 ? cptr2 : "", cptr, strchr (cptr, '/') ? "/" : "\\"); stat = do_cmd (-1, nbuf) & ~SCPE_NOMESSAGE; /* simh.ini proc cmd file */ } if (stat == SCPE_OPENERR) @@ -846,7 +853,7 @@ else if (*argv[0]) { /* sim name arg? */ char *np; /* "path.ini" */ nbuf[0] = '"'; /* starting " */ strncpy (nbuf + 1, argv[0], PATH_MAX + 1); /* copy sim name */ - if (np = match_ext (nbuf, "EXE")) /* remove .exe */ + if ((np = match_ext (nbuf, "EXE"))) /* remove .exe */ *np = 0; strcat (nbuf, ".ini\""); /* add .ini" */ stat = do_cmd (-1, nbuf); /* proc cmd file */ @@ -855,7 +862,7 @@ else if (*argv[0]) { /* sim name arg? */ stat = SCPE_BARE_STATUS(stat); /* remove possible flag */ while (stat != SCPE_EXIT) { /* in case exit */ - if (cptr = sim_brk_getact (cbuf, CBUFSIZE)) /* pending action? */ + if ((cptr = sim_brk_getact (cbuf, CBUFSIZE))) /* pending action? */ printf ("sim> %s\n", cptr); /* echo */ else if (sim_vm_read != NULL) { /* sim routine? */ printf ("sim> "); /* prompt */ @@ -872,7 +879,7 @@ while (stat != SCPE_EXIT) { /* in case exit */ fprintf (sim_log, "sim> %s\n", cptr); cptr = get_glyph (cptr, gbuf, 0); /* get command glyph */ sim_switches = 0; /* init switches */ - if (cmdp = find_cmd (gbuf)) /* lookup command */ + if ((cmdp = find_cmd (gbuf))) /* lookup command */ stat = cmdp->action (cmdp->arg, cptr); /* if found, exec */ else stat = SCPE_UNK; stat_nomessage = stat & SCPE_NOMESSAGE; /* extract possible message supression flag */ @@ -880,7 +887,7 @@ while (stat != SCPE_EXIT) { /* in case exit */ stat = SCPE_BARE_STATUS(stat); /* remove possible flag */ sim_last_cmd_stat = stat; /* save command error status */ if ((stat >= SCPE_BASE) && (!stat_nomessage)) { /* error? */ - if (cmdp->message) /* special message handler? */ + if (cmdp && cmdp->message) /* special message handler? */ cmdp->message (NULL, stat); else { printf ("%s\n", sim_error_text (stat)); @@ -898,6 +905,7 @@ sim_set_logoff (0, NULL); /* close log */ sim_set_notelnet (0, NULL); /* close Telnet */ sim_ttclose (); /* close console */ AIO_CLEANUP; /* Asynch I/O */ +sim_cleanup_sock (); /* cleanup sockets */ return 0; } @@ -948,7 +956,7 @@ if (*cptr) { cptr = get_glyph (cptr, gbuf, 0); if (*cptr) return SCPE_2MARG; - if (cmdp = find_cmd (gbuf)) { + if ((cmdp = find_cmd (gbuf))) { fputs (cmdp->help, stdout); if (sim_log) fputs (cmdp->help, sim_log); @@ -1152,7 +1160,7 @@ do { sim_switches = 0; /* init switches */ sim_gotofile = fpin; sim_do_echo = echo; - if (cmdp = find_cmd (gbuf)) { /* lookup command */ + if ((cmdp = find_cmd (gbuf))) { /* lookup command */ if (cmdp->action == &return_cmd) /* RETURN command? */ break; /* done! */ if (cmdp->action == &do_cmd) { /* DO command? */ @@ -1195,18 +1203,18 @@ do { (stat != SCPE_STEP)) { if (!echo && !sim_quiet && /* report if not echoing */ !stat_nomessage && /* and not suppressing messages */ - !cmdp->message) { /* and not handling them specially */ + !(cmdp && cmdp->message)) { /* and not handling them specially */ printf("%s> %s\n", do_position(), ocptr); if (sim_log) fprintf (sim_log, "%s> %s\n", do_position(), ocptr); } } - if ((flag <= 0) && /* report error if in cmdline/init file */ - (stat >= SCPE_BASE) && !stat_nomessage) { - if (cmdp->message) { /* special message handler */ + if ((stat >= SCPE_BASE) && !stat_nomessage) { /* report error if not suppressed */ + if (cmdp && cmdp->message) { /* special message handler */ cmdp->message ((!echo && !sim_quiet) ? ocptr : NULL, stat); } else { + printf ("%s\n", sim_error_text (stat)); if (sim_log) fprintf (sim_log, "%s\n", sim_error_text (stat)); @@ -1802,18 +1810,18 @@ if (*cptr == 0) /* must be more */ return SCPE_2FARG; cptr = get_glyph (cptr, gbuf, 0); /* get glob/dev/unit */ -if (dptr = find_dev (gbuf)) { /* device match? */ +if ((dptr = find_dev (gbuf))) { /* device match? */ uptr = dptr->units; /* first unit */ ctbr = set_dev_tab; /* global table */ lvl = MTAB_VDV; /* device match */ } -else if (dptr = find_unit (gbuf, &uptr)) { /* unit match? */ +else if ((dptr = find_unit (gbuf, &uptr))) { /* unit match? */ if (uptr == NULL) /* invalid unit */ return SCPE_NXUN; ctbr = set_unit_tab; /* global table */ lvl = MTAB_VUN; /* unit match */ } -else if (gcmdp = find_ctab (set_glob_tab, gbuf)) /* global? */ +else if ((gcmdp = find_ctab (set_glob_tab, gbuf))) /* global? */ return gcmdp->action (gcmdp->arg, cptr); /* do the rest */ else return SCPE_NXDEV; /* no match */ if (*cptr == 0) /* must be more */ @@ -1821,7 +1829,7 @@ if (*cptr == 0) /* must be more */ while (*cptr != 0) { /* do all mods */ cptr = get_glyph (svptr = cptr, gbuf, ','); /* get modifier */ - if (cvptr = strchr (gbuf, '=')) /* = value? */ + if ((cvptr = strchr (gbuf, '='))) /* = value? */ *cvptr++ = 0; for (mptr = dptr->modifiers; mptr && (mptr->mask != 0); mptr++) { if ((mptr->mstring) && /* match string */ @@ -1834,7 +1842,7 @@ while (*cptr != 0) { /* do all mods */ if (mptr->valid) { /* validation rtn? */ if (cvptr && (mptr->mask & MTAB_NC)) { get_glyph_nc (svptr, gbuf, ','); - if (cvptr = strchr (gbuf, '=')) + if ((cvptr = strchr (gbuf, '='))) *cvptr++ = 0; } r = mptr->valid (uptr, mptr->match, cvptr, mptr->desc); @@ -1867,7 +1875,7 @@ while (*cptr != 0) { /* do all mods */ } /* end if match */ } /* end for */ if (!mptr || (mptr->mask == 0)) { /* no match? */ - if (glbr = find_c1tab (ctbr, gbuf)) { /* global match? */ + if ((glbr = find_c1tab (ctbr, gbuf))) { /* global match? */ r = glbr->action (dptr, uptr, glbr->arg, cvptr); /* do global */ if (r != SCPE_OK) return r; @@ -2064,15 +2072,15 @@ GET_SWITCHES (cptr); /* get switches */ if (*cptr == 0) /* must be more */ return SCPE_2FARG; cptr = get_glyph (cptr, gbuf, 0); /* get next glyph */ -if (shptr = find_shtab (show_glob_tab, gbuf)) /* global? */ +if ((shptr = find_shtab (show_glob_tab, gbuf))) /* global? */ return shptr->action (ofile, NULL, NULL, shptr->arg, cptr); -if (dptr = find_dev (gbuf)) { /* device match? */ +if ((dptr = find_dev (gbuf))) { /* device match? */ uptr = dptr->units; /* first unit */ shtb = show_dev_tab; /* global table */ lvl = MTAB_VDV; /* device match */ } -else if (dptr = find_unit (gbuf, &uptr)) { /* unit match? */ +else if ((dptr = find_unit (gbuf, &uptr))) { /* unit match? */ if (uptr == NULL) /* invalid unit */ return SCPE_NXUN; if (uptr->flags & UNIT_DIS) /* disabled? */ @@ -2092,7 +2100,7 @@ if (dptr->modifiers == NULL) /* any modifiers? */ while (*cptr != 0) { /* do all mods */ cptr = get_glyph (cptr, gbuf, ','); /* get modifier */ - if (cvptr = strchr (gbuf, '=')) /* = value? */ + if ((cvptr = strchr (gbuf, '='))) /* = value? */ *cvptr++ = 0; for (mptr = dptr->modifiers; mptr->mask != 0; mptr++) { if (((mptr->mask & MTAB_XTD)? /* right level? */ @@ -2111,7 +2119,7 @@ while (*cptr != 0) { /* do all mods */ } /* end if */ } /* end for */ if (mptr->mask == 0) { /* no match? */ - if (shptr = find_shtab (shtb, gbuf)) /* global match? */ + if ((shptr = find_shtab (shtb, gbuf))) /* global match? */ shptr->action (ofile, dptr, uptr, shptr->arg, cptr); else return SCPE_ARG; } /* end if */ @@ -2562,7 +2570,7 @@ if (sim_brk_types == 0) return SCPE_NOFNC; if ((dptr == NULL) || (uptr == NULL)) return SCPE_IERR; -if (aptr = strchr (cptr, ';')) { /* ;action? */ +if ((aptr = strchr (cptr, ';'))) { /* ;action? */ if (flg != SSH_ST) /* only on SET */ return SCPE_ARG; *aptr++ = 0; /* separate strings */ @@ -3120,8 +3128,10 @@ for (i = 0; (dptr = sim_devices[i]) != NULL; i++) { /* loop thru devices */ for (l = 0; (l < SRBSIZ) && (k < high); l++, k = k + (dptr->aincr)) { /* check for 0 block */ r = dptr->examine (&val, k, uptr, SIM_SW_REST); - if (r != SCPE_OK) + if (r != SCPE_OK) { + free (mbuf); return r; + } if (val) zeroflg = FALSE; SZ_STORE (sz, val, mbuf, l); } /* end for l */ @@ -3362,19 +3372,26 @@ for ( ;; ) { /* device loop */ if ((mbuf = calloc (SRBSIZ, sz)) == NULL) return SCPE_MEM; for (k = 0; k < high; ) { /* loop thru mem */ - READ_I (blkcnt); /* block count */ + if (sim_fread (&blkcnt, sizeof (blkcnt), 1, rfile) == 0) {/* block count */ + free (mbuf); + return SCPE_IOERR; + } if (blkcnt < 0) /* compressed? */ limit = -blkcnt; else limit = (int32)sim_fread (mbuf, sz, blkcnt, rfile); - if (limit <= 0) /* invalid or err? */ + if (limit <= 0) { /* invalid or err? */ + free (mbuf); return SCPE_IOERR; + } for (j = 0; j < limit; j++, k = k + (dptr->aincr)) { if (blkcnt < 0) /* compressed? */ val = 0; else SZ_LOAD (sz, val, mbuf, j); /* saved value */ r = dptr->deposit (val, k, uptr, SIM_SW_REST); - if (r != SCPE_OK) + if (r != SCPE_OK) { + free (mbuf); return r; + } } /* end for j */ } /* end for k */ free (mbuf); /* dealloc buffer */ @@ -3616,7 +3633,7 @@ if (unechoed_cmdline) { printf("%s> %s\n", do_position(), unechoed_cmdline); if (sim_log) fprintf (sim_log, "%s> %s\n", do_position(), unechoed_cmdline); - } + } fprint_stopped (stdout, r); /* print msg */ if (sim_log) /* log if enabled */ fprint_stopped (sim_log, r); @@ -3990,7 +4007,7 @@ if (rptr->flags & REG_RO) if (flag & EX_I) { cptr = read_line (gbuf, CBUFSIZE, stdin); if (sim_log) - fprintf (sim_log, (cptr? "%s\n": "\n"), cptr); + fprintf (sim_log, "%s\n", cptr? cptr: ""); if (cptr == NULL) /* force exit */ return 1; if (*cptr == 0) /* success */ @@ -4208,7 +4225,7 @@ if (dptr == NULL) if (flag & EX_I) { cptr = read_line (gbuf, CBUFSIZE, stdin); if (sim_log) - fprintf (sim_log, (cptr? "%s\n": "\n"), cptr); + fprintf (sim_log, "%s\n", cptr? cptr: ""); if (cptr == NULL) /* force exit */ return 1; if (*cptr == 0) /* success */ @@ -4569,69 +4586,6 @@ if (term && (*tptr++ != term)) return tptr; } -/* get_ipaddr IP address:port - - Inputs: - cptr = pointer to input string - Outputs: - ipa = pointer to IP address (may be NULL), 0 = none - ipp = pointer to IP port (may be NULL), 0 = none - result = status -*/ - -t_stat get_ipaddr (char *cptr, uint32 *ipa, uint32 *ipp) -{ -char gbuf[CBUFSIZE]; -char *addrp, *portp, *octetp; -uint32 i, addr, port, octet; -t_stat r; - -if ((cptr == NULL) || (*cptr == 0)) - return SCPE_ARG; -strncpy (gbuf, cptr, CBUFSIZE); -addrp = gbuf; /* default addr */ -if (portp = strchr (gbuf, ':')) /* x:y? split */ - *portp++ = 0; -else if (strchr (gbuf, '.')) /* x.y...? */ - portp = NULL; -else { - portp = gbuf; /* port only */ - addrp = NULL; /* no addr */ - } -if (portp) { /* port string? */ - if (ipp == NULL) /* not wanted? */ - return SCPE_ARG; - port = (int32) get_uint (portp, 10, 65535, &r); - if ((r != SCPE_OK) || (port == 0)) - return SCPE_ARG; - } -else port = 0; -if (addrp) { /* addr string? */ - if (ipa == NULL) /* not wanted? */ - return SCPE_ARG; - for (i = addr = 0; i < 4; i++) { /* four octets */ - octetp = strchr (addrp, '.'); /* find octet end */ - if (octetp != NULL) /* split string */ - *octetp++ = 0; - else if (i < 3) /* except last */ - return SCPE_ARG; - octet = (int32) get_uint (addrp, 10, 255, &r); - if (r != SCPE_OK) - return SCPE_ARG; - addr = (addr << 8) | octet; - addrp = octetp; - } - if (((addr & 0377) == 0) || ((addr & 0377) == 255)) - return SCPE_ARG; - } -else addr = 0; -if (ipp) /* return req values */ - *ipp = port; -if (ipa) - *ipa = addr; -return SCPE_OK; -} - /* Find_device find device matching input string Inputs: @@ -4677,7 +4631,7 @@ DEVICE *dptr; sim_unit_ref = ref_unit; /* assume unit reference */ if (uptr == NULL) /* arg error? */ return NULL; -if (dptr = find_dev (cptr)) { /* exact match? */ +if ((dptr = find_dev (cptr))) { /* exact match? */ if (qdisable (dptr)) /* disabled? */ return NULL; sim_unit_ref = ref_dev; /* flag device reference */ @@ -4758,7 +4712,7 @@ REG *rptr, *srptr = NULL; for (i = 0; (dptr = sim_devices[i]) != 0; i++) { /* all dev */ if (dptr->flags & DEV_DIS) /* skip disabled */ continue; - if (rptr = find_reg (cptr, optr, dptr)) { /* found? */ + if ((rptr = find_reg (cptr, optr, dptr))) { /* found? */ if (srptr) /* ambig? err */ return NULL; srptr = rptr; /* save reg */ @@ -4976,15 +4930,15 @@ const char logstr[] = "|&^", cmpstr[] = "=!><"; logval = cmpval = 0; if (*cptr == 0) /* check for clause */ return NULL; -for (logop = cmpop = -1; c = *cptr++; ) { /* loop thru clauses */ - if (sptr = strchr (logstr, c)) { /* check for mask */ +for (logop = cmpop = -1; (c = *cptr++); ) { /* loop thru clauses */ + if ((sptr = strchr (logstr, c))) { /* check for mask */ logop = (int32)(sptr - logstr); logval = strtotv (cptr, &tptr, radix); if (cptr == tptr) return NULL; cptr = tptr; } - else if (sptr = strchr (cmpstr, c)) { /* check for boolop */ + else if ((sptr = strchr (cmpstr, c))) { /* check for boolop */ cmpop = (int32)(sptr - cmpstr); if (*cptr == '=') { cmpop = cmpop + strlen (cmpstr); @@ -5676,7 +5630,7 @@ while (isspace (*sim_brk_act[sim_do_depth])) /* skip spaces */ sim_brk_act[sim_do_depth]++; if (*sim_brk_act[sim_do_depth] == 0) /* now empty? */ return (sim_brk_act[sim_do_depth] = NULL); -if (ep = strchr (sim_brk_act[sim_do_depth], ';')) { /* cmd delimiter? */ +if ((ep = strchr (sim_brk_act[sim_do_depth], ';'))) { /* cmd delimiter? */ lnt = ep - sim_brk_act[sim_do_depth]; /* cmd length */ memcpy (buf, sim_brk_act[sim_do_depth], lnt + 1); /* copy with ; */ buf[lnt] = 0; /* erase ; */ diff --git a/scp.h b/scp.h index 98f6bc8b..38ce92fb 100644 --- a/scp.h +++ b/scp.h @@ -111,7 +111,6 @@ char *get_glyph_nc (char *iptr, char *optr, char mchar); t_value get_uint (char *cptr, uint32 radix, t_value max, t_stat *status); char *get_range (DEVICE *dptr, char *cptr, t_addr *lo, t_addr *hi, uint32 rdx, t_addr max, char term); -t_stat get_ipaddr (char *cptr, uint32 *ipa, uint32 *ipp); t_value strtotv (char *cptr, char **endptr, uint32 radix); t_stat fprint_val (FILE *stream, t_value val, uint32 rdx, uint32 wid, uint32 fmt); CTAB *find_cmd (char *gbuf); diff --git a/sim_BuildROMs.c b/sim_BuildROMs.c index 8a3e6982..bb7637b1 100644 --- a/sim_BuildROMs.c +++ b/sim_BuildROMs.c @@ -23,26 +23,30 @@ used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from Robert M Supnik. - - +*/ +#include +#include +#include +/* This program builds C include files which can be used to contain the contents of ROM or other boot code needed by simulators. Current Internal ROM files being built: - ROM/Boot File: Include File: - ======================================= - VAX/ka655x.bin VAX/vax_ka655x_bin.h - VAX/vmb.exe VAX/vax780_vmb_exe.h - - + ROM/Boot File: Include File: Size: Checksum: + ======================================================================================= */ +struct ROM_File_Descriptor { + char *BinaryName; char *IncludeFileName; size_t expected_size; unsigned int checksum; char *ArrayName;} ROMs[] = { + {"VAX/ka655x.bin", "VAX/vax_ka655x_bin.h", 131072, 0xFF7673B6, "vax_ka655x_bin"}, + {"VAX/vmb.exe", "VAX/vax780_vmb_exe.h", 44544, 0xFFC014CC, "vax780_vmb_exe"}, + }; -#include -#include -#include -#include + +#include #include +#include #include #if defined(_WIN32) @@ -53,6 +57,114 @@ #include #endif +int sim_read_ROM_include(const char *include_filename, + int *psize, + unsigned char **pROMData, + unsigned int *pchecksum, + char **prom_array_name) +{ +FILE *iFile; +char line[256]; +size_t i; +size_t bytes_written = 0; +size_t allocated_size = 0; + +*psize = 0; +*pchecksum = 0; +*pROMData = NULL; +*prom_array_name = NULL; +if (NULL == (iFile = fopen (include_filename, "r"))) + return -1; + +memset (line, 0, sizeof (line)); + +while (fgets (line, sizeof(line)-1, iFile)) { + unsigned int byte; + char *c; + + switch (line[0]) { + case '#': + case ' ': + case '/': + case '*': + case '\n': + break; + case 'u': /* unsigned char {array_name}[] */ + *prom_array_name = calloc(512, sizeof(char)); + if (1 == sscanf (line, "unsigned char %s[]", *prom_array_name)) { + c = strchr (*prom_array_name, '['); + if (c) + *c = '\0'; + } + break; + case '0': /* line containing byte data */ + c = line; + while (1 == sscanf (c, "0x%2Xd,", &byte)) { + if (bytes_written >= allocated_size) { + allocated_size += 2048; + *pROMData = realloc(*pROMData, allocated_size); + } + *(*pROMData + bytes_written++) = byte; + c += 5; + } + break; + } + if (strchr (line, '}')) + break; + } +fclose (iFile); +for (i=0; i= statb.st_size) - Difference = 1; - else - IncludeData[bytes_written++] = byte; - c += 5; - } - if ((strchr (line,'}')) || Difference) - break; - } - fclose (iFile); - if (!Difference) - Difference = memcmp (IncludeData, ROMData, statb.st_size); - free (IncludeData); - if (!Difference) { +if (0 == sim_read_ROM_include(include_filename, + &include_bytes, + &include_ROMData, + &include_checksum, + &include_array_name)) { + c = ((include_checksum == expected_checksum) && + (include_bytes == expected_size) && + (0 == strcmp (include_array_name, rom_array_name)) && + (0 == memcmp (include_ROMData, ROMData, include_bytes))); + free(include_ROMData); + free(include_array_name); + if (c) { free (ROMData); return 0; } @@ -153,6 +267,7 @@ fprintf (iFile, "/*\n"); fprintf (iFile, " %s produced at %s", include_filename, ctime(&now)); fprintf (iFile, " from %s which was last modified at %s", rom_filename, ctime(&statb.st_mtime)); fprintf (iFile, " file size: %d (0x%X) - checksum: 0x%08X\n", (int)statb.st_size, (int)statb.st_size, checksum); +fprintf (iFile, " This file is a generated file and should NOT be edited or changed by hand.\n"); fprintf (iFile, "*/\n"); fprintf (iFile, "unsigned char %s[] = {", rom_array_name); for (bytes_written=0;bytes_written 2)) + status = sim_make_ROMs_entry (argv[2]); +else { + for (i=0; iaction (ctptr->arg, cvptr); /* do the rest */ if (r != SCPE_OK) return r; @@ -236,7 +236,7 @@ if (*cptr == 0) { /* show all */ } while (*cptr != 0) { cptr = get_glyph (cptr, gbuf, ','); /* get modifier */ - if (shptr = find_shtab (show_con_tab, gbuf)) + if ((shptr = find_shtab (show_con_tab, gbuf))) shptr->action (st, dptr, uptr, shptr->arg, cptr); else return SCPE_NOPARAM; } @@ -425,21 +425,23 @@ if ((cptr == NULL) || (*cptr == 0)) return SCPE_2FARG; while (*cptr != 0) { /* do all mods */ cptr = get_glyph_nc (cptr, gbuf, ','); /* get modifier */ - if (cvptr = strchr (gbuf, '=')) /* = value? */ + if ((cvptr = strchr (gbuf, '='))) /* = value? */ *cvptr++ = 0; get_glyph (gbuf, gbuf, 0); /* modifier to UC */ - if (isdigit (*gbuf)) { - if (sim_con_tmxr.master) /* already open? */ - sim_set_notelnet (0, NULL); /* close first */ - return tmxr_open_master (&sim_con_tmxr, gbuf); /* open master socket */ + if ((ctptr = find_ctab (set_con_telnet_tab, gbuf))) { /* match? */ + r = ctptr->action (ctptr->arg, cvptr); /* do the rest */ + if (r != SCPE_OK) + return r; } - else - if (ctptr = find_ctab (set_con_telnet_tab, gbuf)) { /* match? */ - r = ctptr->action (ctptr->arg, cvptr); /* do the rest */ - if (r != SCPE_OK) - return r; + else { + r = sim_parse_addr (gbuf, NULL, 0, NULL, NULL, 0, NULL); + if (r == SCPE_OK) { + if (sim_con_tmxr.master) /* already open? */ + sim_set_notelnet (0, NULL); /* close first */ + return tmxr_open_master (&sim_con_tmxr, gbuf); /* open master socket */ } - else return SCPE_NOPARAM; + return SCPE_NOPARAM; + } } return SCPE_OK; } @@ -465,9 +467,9 @@ if (sim_con_tmxr.master == 0) fprintf (st, "Connected to console window\n"); else { if (sim_con_ldsc.conn == 0) - fprintf (st, "Listening on port %d\n", sim_con_tmxr.port); + fprintf (st, "Listening on port %s\n", sim_con_tmxr.port); else { - fprintf (st, "Listening on port %d, connected to socket %d\n", + fprintf (st, "Listening on port %s, connected to socket %d\n", sim_con_tmxr.port, sim_con_ldsc.conn); tmxr_fconns (st, &sim_con_ldsc, -1); } @@ -696,7 +698,7 @@ if (sim_con_ldsc.conn == 0) { /* no Telnet conn? */ return SCPE_OK; /* unconnected and buffered - nothing to receive */ } tmxr_poll_rx (&sim_con_tmxr); /* poll for input */ -if (c = tmxr_getc_ln (&sim_con_ldsc)) /* any char? */ +if ((c = tmxr_getc_ln (&sim_con_ldsc))) /* any char? */ return (c & (SCPE_BREAK | 0377)) | SCPE_KFLAG; return SCPE_OK; } diff --git a/sim_defs.h b/sim_defs.h index 4c4d1f5c..3d32500e 100644 --- a/sim_defs.h +++ b/sim_defs.h @@ -515,7 +515,7 @@ struct sim_fileref { /* The following macros define structure contents */ -#define UDATA(act,fl,cap) NULL,act,NULL,NULL,NULL,0,0,(fl),(cap),0,0 +#define UDATA(act,fl,cap) NULL,act,NULL,NULL,NULL,0,0,(fl),(cap),0,NULL,0,0 #if defined (__STDC__) || defined (_WIN32) #define ORDATA(nm,loc,wd) #nm, &(loc), 8, (wd), 0, 1 diff --git a/sim_disk.c b/sim_disk.c index 01613e53..8397c15b 100644 --- a/sim_disk.c +++ b/sim_disk.c @@ -108,6 +108,7 @@ struct disk_context { pthread_t io_thread; /* I/O Thread Id */ pthread_mutex_t io_lock; pthread_cond_t io_cond; + pthread_cond_t startup_cond; int io_dop; uint8 *buf; t_seccnt *rsects; @@ -176,6 +177,7 @@ pthread_setschedparam (pthread_self(), sched_policy, &sched_priority); sim_debug (ctx->dbit, ctx->dptr, "_disk_io(unit=%d) starting\n", uptr-ctx->dptr->units); pthread_mutex_lock (&ctx->io_lock); +pthread_cond_signal (&ctx->startup_cond); /* Signal we're ready to go */ while (ctx->asynch_io) { pthread_cond_wait (&ctx->io_cond, &ctx->io_lock); if (ctx->io_dop == DOP_DONE) @@ -423,10 +425,15 @@ ctx->asynch_io_latency = latency; if (ctx->asynch_io) { pthread_mutex_init (&ctx->io_lock, NULL); pthread_cond_init (&ctx->io_cond, NULL); + pthread_cond_init (&ctx->startup_cond, NULL); pthread_attr_init(&attr); pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM); + pthread_mutex_lock (&ctx->io_lock); pthread_create (&ctx->io_thread, &attr, _disk_io, (void *)uptr); pthread_attr_destroy(&attr); + pthread_cond_wait (&ctx->startup_cond, &ctx->io_lock); /* Wait for thread to stabilize */ + pthread_mutex_unlock (&ctx->io_lock); + pthread_cond_destroy (&ctx->startup_cond); uptr->a_check_completion = _disk_completion_dispatch; } #endif @@ -2550,13 +2557,13 @@ static FILE *sim_vhd_disk_open (const char *szVHDPath, const char *DesiredAccess if (!hVHD) return (FILE *)hVHD; - if (Status = GetVHDFooter (szVHDPath, - &hVHD->Footer, - &hVHD->Dynamic, - &hVHD->BAT, - NULL, - hVHD->ParentVHDPath, - sizeof (hVHD->ParentVHDPath))) + if (0 != (Status = GetVHDFooter (szVHDPath, + &hVHD->Footer, + &hVHD->Dynamic, + &hVHD->BAT, + NULL, + hVHD->ParentVHDPath, + sizeof (hVHD->ParentVHDPath)))) goto Cleanup_Return; if (NtoHl (hVHD->Footer.DiskType) == VHD_DT_Differencing) { hVHD->Parent = (VHDHANDLE)sim_vhd_disk_open (hVHD->ParentVHDPath, "rb"); @@ -2702,7 +2709,7 @@ if (SizeInBytes > ((uint64)(1024*1024*1024))*2040) { Status = EFBIG; goto Cleanup_Return; } -if (File = sim_fopen (szVHDPath, "rb")) { +if (NULL != (File = sim_fopen (szVHDPath, "rb"))) { fclose (File); File = NULL; Status = EEXIST; @@ -2877,13 +2884,13 @@ char *FullVHDPath = NULL; size_t i, RelativeMatch, UpDirectories, LocatorsWritten = 0; int64 LocatorPosition; -if (Status = GetVHDFooter (szParentVHDPath, - &ParentFooter, - &ParentDynamic, - NULL, - &ParentTimeStamp, - NULL, - 0)) +if (0 != (Status = GetVHDFooter (szParentVHDPath, + &ParentFooter, + &ParentDynamic, + NULL, + &ParentTimeStamp, + NULL, + 0))) goto Cleanup_Return; hVHD = CreateVirtualDisk (szVHDPath, (uint32)(NtoHll(ParentFooter.CurrentSize)/BytesPerSector), @@ -2895,11 +2902,11 @@ if (!hVHD) { } LocatorPosition = NtoHll (hVHD->Dynamic.TableOffset)+BytesPerSector*((NtoHl (hVHD->Dynamic.MaxTableEntries)*sizeof(*hVHD->BAT)+BytesPerSector-1)/BytesPerSector); hVHD->Dynamic.Checksum = 0; -RelativeParentVHDPath = calloc (1, BytesPerSector+1); -FullParentVHDPath = calloc (1, BytesPerSector+1); -RelativeParentVHDPathBuffer = calloc (1, BytesPerSector); -FullParentVHDPathBuffer = calloc (1, BytesPerSector); -FullVHDPath = calloc (1, BytesPerSector+1); +RelativeParentVHDPath = calloc (1, BytesPerSector+2); +FullParentVHDPath = calloc (1, BytesPerSector+2); +RelativeParentVHDPathBuffer = calloc (1, BytesPerSector+2); +FullParentVHDPathBuffer = calloc (1, BytesPerSector+2); +FullVHDPath = calloc (1, BytesPerSector+2); ExpandToFullPath (szParentVHDPath, FullParentVHDPath, BytesPerSector); for (i=0; i < strlen (FullParentVHDPath); i++) hVHD->Dynamic.ParentUnicodeName[i*2+1] = FullParentVHDPath[i]; @@ -3233,8 +3240,13 @@ while (sects) { } SectorsInWrite = 1; if (hVHD->BAT[BlockNumber] == VHD_BAT_FREE_ENTRY) { - void *BitMap = NULL; + uint8 *BitMap = NULL; + uint32 BitMapBufferSize = VHD_DATA_BLOCK_ALIGNMENT; + uint8 *BitMapBuffer = NULL; void *BlockData = NULL; + uint8 *BATUpdateBufferAddress; + uint32 BATUpdateBufferSize; + uint64 BATUpdateStorageAddress; if (!hVHD->Parent && BufferIsZeros(buf, SectorSize)) goto IO_Done; @@ -3242,28 +3254,51 @@ while (sects) { BlockOffset = sim_fsize_ex (hVHD->File); if (((int64)BlockOffset) == -1) return SCPE_IOERR; - BitMap = malloc(BitMapSectors*SectorSize); + if (BitMapSectors*SectorSize > BitMapBufferSize) + BitMapBufferSize = BitMapSectors*SectorSize; + BitMapBuffer = calloc(1, BitMapBufferSize + SectorSize*SectorsPerBlock); + if (BitMapBufferSize > BitMapSectors*SectorSize) + BitMap = BitMapBuffer + BitMapBufferSize-BitMapBytes; + else + BitMap = BitMapBuffer; memset(BitMap, 0xFF, BitMapBytes); BlockOffset -= sizeof(hVHD->Footer); - /* align the data portion of the block to the desired alignment */ - /* compute the address of the data portion of the block */ - BlockOffset += BitMapSectors*SectorSize; - /* round up this address to the desired alignment */ - BlockOffset += VHD_DATA_BLOCK_ALIGNMENT-1; - BlockOffset &= ~(VHD_DATA_BLOCK_ALIGNMENT-1); - /* the actual block address is the beginning of the block bitmap */ + if (0 == (BlockOffset & ~(VHD_DATA_BLOCK_ALIGNMENT-1))) + { // Already aligned, so use padded BitMapBuffer + if (WriteFilePosition(hVHD->File, + BitMapBuffer, + BitMapBufferSize + SectorSize*SectorsPerBlock, + NULL, + BlockOffset)) { + free (BitMapBuffer); + return SCPE_IOERR; + } + BlockOffset += BitMapBufferSize; + } + else + { + // align the data portion of the block to the desired alignment + // compute the address of the data portion of the block + BlockOffset += BitMapSectors*SectorSize; + // round up this address to the desired alignment + BlockOffset += VHD_DATA_BLOCK_ALIGNMENT-1; + BlockOffset &= ~(VHD_DATA_BLOCK_ALIGNMENT-1); + BlockOffset -= BitMapSectors*SectorSize; + if (WriteFilePosition(hVHD->File, + BitMap, + SectorSize * (BitMapSectors + SectorsPerBlock), + NULL, + BlockOffset)) { + free (BitMapBuffer); + return SCPE_IOERR; + } + BlockOffset += BitMapSectors*SectorSize; + } + free(BitMapBuffer); + BitMapBuffer = BitMap = NULL; + /* the BAT block address is the beginning of the block bitmap */ BlockOffset -= BitMapSectors*SectorSize; hVHD->BAT[BlockNumber] = NtoHl((uint32)(BlockOffset/SectorSize)); - if (WriteFilePosition(hVHD->File, - BitMap, - BitMapSectors*SectorSize, - NULL, - BlockOffset)) { - free (BitMap); - return SCPE_IOERR; - } - free(BitMap); - BitMap = NULL; BlockOffset += SectorSize * (SectorsPerBlock + BitMapSectors); if (WriteFilePosition(hVHD->File, &hVHD->Footer, @@ -3271,11 +3306,17 @@ while (sects) { NULL, BlockOffset)) goto Fatal_IO_Error; + BATUpdateBufferAddress = ((uint8 *)hVHD->BAT) + + (((((size_t)&hVHD->BAT[BlockNumber]) - ((size_t)hVHD->BAT) + VHD_DATA_BLOCK_ALIGNMENT - 1)/VHD_DATA_BLOCK_ALIGNMENT)*VHD_DATA_BLOCK_ALIGNMENT); + BATUpdateBufferSize = SectorSize*((sizeof(*hVHD->BAT)*NtoHl(hVHD->Dynamic.MaxTableEntries)+511)/512); + if (BATUpdateBufferSize > VHD_DATA_BLOCK_ALIGNMENT) + BATUpdateBufferSize = VHD_DATA_BLOCK_ALIGNMENT; + BATUpdateStorageAddress = NtoHll(hVHD->Dynamic.TableOffset) + BATUpdateBufferAddress - ((uint8 *)hVHD->BAT); if (WriteFilePosition(hVHD->File, - hVHD->BAT, - SectorSize*((sizeof(*hVHD->BAT)*NtoHl(hVHD->Dynamic.MaxTableEntries)+511)/512), + BATUpdateBufferAddress, + BATUpdateBufferSize, NULL, - NtoHll(hVHD->Dynamic.TableOffset))) + BATUpdateStorageAddress)) goto Fatal_IO_Error; if (hVHD->Parent) { /* Need to populate data block contents from parent VHD */ diff --git a/sim_ether.c b/sim_ether.c index 8318f129..8e43bbc5 100644 --- a/sim_ether.c +++ b/sim_ether.c @@ -664,7 +664,7 @@ void eth_zero(ETH_DEV* dev) } static ETH_DEV **eth_open_devices = NULL; -static eth_open_device_count = 0; +static int eth_open_device_count = 0; static void _eth_add_to_open_list (ETH_DEV* dev) { @@ -717,10 +717,23 @@ t_stat eth_show (FILE* st, UNIT* uptr, int32 val, void* desc) fprintf(st, " %-7s%s\n", eth_open_devices[i]->dptr->name, eth_open_devices[i]->dptr->units[0].filename); } } + if (eth_open_device_count) { + int i; + char desc[ETH_DEV_DESC_MAX], *d; + + fprintf(st,"Open ETH Devices:\n"); + for (i=0; iname, desc); + if (d) + fprintf(st, " %-7s%s (%s)\n", eth_open_devices[i]->dptr->name, eth_open_devices[i]->name, d); + else + fprintf(st, " %-7s%s\n", eth_open_devices[i]->dptr->name, eth_open_devices[i]->name); + } + } return SCPE_OK; } -t_stat eth_show_devices (FILE* st, DEVICE *dptr, UNIT* uptr, int32 val, void* desc) +t_stat eth_show_devices (FILE* st, DEVICE *dptr, UNIT* uptr, int32 val, char* desc) { return eth_show (st, uptr, val, desc); } @@ -942,7 +955,7 @@ static char* (*p_pcap_lib_version) (void); /* load function pointer from DLL */ typedef int (*_func)(); -void load_function(char* function, _func* func_ptr) { +static void load_function(char* function, _func* func_ptr) { #ifdef _WIN32 *func_ptr = (_func)GetProcAddress(hLib, function); #else @@ -1394,7 +1407,7 @@ static void eth_get_nic_hw_addr(ETH_DEV* dev, char *devname) for (i=0; patterns[i] && (0 == dev->have_host_nic_phy_addr); ++i) { snprintf(command, sizeof(command)-1, "ifconfig %s | %s >NIC.hwaddr", devname, patterns[i]); system(command); - if (f = fopen("NIC.hwaddr", "r")) { + if (NULL != (f = fopen("NIC.hwaddr", "r"))) { while (0 == dev->have_host_nic_phy_addr) { if (fgets(command, sizeof(command)-1, f)) { char *p1, *p2; @@ -1580,7 +1593,7 @@ sim_debug(dev->dbit, dev->dptr, "Writer Thread Starting\n"); pthread_mutex_lock (&dev->writer_lock); while (dev->handle) { pthread_cond_wait (&dev->writer_cond, &dev->writer_lock); - while (request = dev->write_requests) { + while (NULL != (request = dev->write_requests)) { /* Pull buffer off request list */ dev->write_requests = request->next; pthread_mutex_unlock (&dev->writer_lock); @@ -1889,11 +1902,11 @@ pthread_mutex_destroy (&dev->writer_lock); pthread_cond_destroy (&dev->writer_cond); if (1) { struct write_request *buffer; - while (buffer = dev->write_buffers) { + while (NULL != (buffer = dev->write_buffers)) { dev->write_buffers = buffer->next; free(buffer); } - while (buffer = dev->write_requests) { + while (NULL != (buffer = dev->write_requests)) { dev->write_requests = buffer->next; free(buffer); } @@ -2146,10 +2159,10 @@ if (!dev) return SCPE_UNATT; /* Get a buffer */ pthread_mutex_lock (&dev->writer_lock); -if (request = dev->write_buffers) +if (NULL != (request = dev->write_buffers)) dev->write_buffers = request->next; pthread_mutex_unlock (&dev->writer_lock); -if (!request) +if (NULL == request) request = malloc(sizeof(*request)); /* Copy buffer contents */ @@ -3159,6 +3172,7 @@ pcap_if_t* dev; char errbuf[PCAP_ERRBUF_SIZE]; memset(list, 0, max*sizeof(*list)); +errbuf[0] = '\0'; /* retrieve the device list */ if (pcap_findalldevs(&alldevs, errbuf) == -1) { char* msg = "Eth: error in pcap_findalldevs: %s\r\n"; @@ -3184,6 +3198,13 @@ else { /* Add any host specific devices and/or validate those already found */ 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); + } + /* return device count */ return i; } diff --git a/sim_ether.h b/sim_ether.h index f26e2e39..7706ffef 100644 --- a/sim_ether.h +++ b/sim_ether.h @@ -291,7 +291,7 @@ void eth_packet_trace_ex (ETH_DEV* dev, const uint8 *msg, int len, char* txt, in t_stat eth_show (FILE* st, UNIT* uptr, /* show ethernet devices */ int32 val, void* desc); t_stat eth_show_devices (FILE* st, DEVICE *dptr, /* show ethernet devices */ - UNIT* uptr, int32 val, void* desc); + UNIT* uptr, int32 val, char* desc); void eth_show_dev (FILE*st, ETH_DEV* dev); /* show ethernet device state */ void eth_mac_fmt (ETH_MAC* add, char* buffer); /* format ethernet mac address */ diff --git a/sim_rev.h b/sim_rev.h index 93b173ca..91c549b4 100644 --- a/sim_rev.h +++ b/sim_rev.h @@ -27,12 +27,22 @@ #ifndef _SIM_REV_H_ #define _SIM_REV_H_ 0 -#define SIM_MAJOR 3 -#define SIM_MINOR 9 +#define SIM_MAJOR 4 +#define SIM_MINOR 0 #define SIM_PATCH 0 #define SIM_DELTA 0 -/* V3.9 revision history +/* + The comment section below reflects the manual editing process which was in place + prior to the use of the git source control system on at https://gihub.com/simh/simh + + Details about all future fixes will be visible in the source control system's + history. + +*/ + +/* + V3.9 revision history patch date module(s) and fix(es) @@ -191,6 +201,9 @@ patch date module(s) and fix(es) - fixed backspace over tapemark not to set EOR (Van Snyder) - added no rewind option (Van Snyder) + i1401_sys.c: + - fixed misuse of & instead of && in decode (Peter Schorn) + pdp1_cpu.c: - fixed misuse of & instead of && in Ea_ch (Michael Bloom) @@ -204,7 +217,8 @@ patch date module(s) and fix(es) - fixed priority of PIRQ vs IO; added INT_INTERNALn pdp11_io.c: - - fixed Qbus interrupts to treat all IO devices as BR4 + - fixed Qbus interrupts to treat all IO devices (except clock) as BR4 + - fixed order of int_internal (Jordi Guillaumes i Pons) ppd11_rf.c - fixed bug in updating mem addr extension (Peter Schorn) @@ -319,7 +333,7 @@ patch date module(s) and fix(es) - fixed bug in scan function decode (Peter Schorn) vax_cpu.c: - - revised idle design Mark Pizzolato) + - revised idle design (Mark Pizzolato) - fixed bug in SET CPU IDLE - fixed failure to clear PSL in BPT, XFC @@ -356,7 +370,7 @@ patch date module(s) and fix(es) - moved all Qbus devices to BR4; deleted RP definitions -/* V3.8 revision history + V3.8 revision history 1 08-Feb-09 scp.c: - revised RESTORE unit logic for consistency @@ -709,7 +723,7 @@ patch date module(s) and fix(es) - fixed declarations (Mark Pizzolato) -/* V3.7 revision history + V3.7 revision history 3 02-Sep-07 scp.c: - fixed bug in SET THROTTLE command @@ -981,7 +995,7 @@ patch date module(s) and fix(es) - fixed operand order in EIS instructions (W.F.J. Mueller) -/* V3.6 revision history + V3.6 revision history 1 25-Jul-06 sim_console.c: - implemented SET/SHOW PCHAR @@ -1155,7 +1169,7 @@ patch date module(s) and fix(es) - fixed bug in reported VA on faulting cross-page write -/* V3.5 revision history + V3.5 revision history patch date module(s) and fix(es) @@ -1291,7 +1305,7 @@ patch date module(s) and fix(es) vax_io.c: revised autoconfiguration algorithm and interface -/* V3.4 revision history + V3.4 revision history 0 01-May-04 scp.c: - fixed ASSERT code @@ -1329,7 +1343,7 @@ patch date module(s) and fix(es) pdp11_tu.c: fixed error reporting -/* V3.3 revision history + V3.3 revision history 2 08-Mar-05 scp.c: added ASSERT command (Dave Bryan) @@ -1581,7 +1595,7 @@ patch date module(s) and fix(es) - split from vax_sys.c - removed PTR, PTP -/* V3.2 revision history + V3.2 revision history 3 03-Sep-04 scp.c: - added ECHO command (Dave Bryan) @@ -1780,7 +1794,7 @@ patch date module(s) and fix(es) - added PC read fault in EXTxV - fixed PC write fault in INSV -/* V3.1 revision history + V3.1 revision history 0 29-Dec-03 sim_defs.h, scp.c: added output stall status @@ -1893,7 +1907,7 @@ patch date module(s) and fix(es) - revised instruction decoding - added instruction history -/* V3.0 revision history + V3.0 revision history 2 15-Sep-03 scp.c: - fixed end-of-file problem in dep, idep @@ -2059,7 +2073,7 @@ patch date module(s) and fix(es) gri_cpu.c: fixed bug in SC queue pointer management -/* V2.10 revision history + V2.10 revision history 4 03-Mar-03 scp.c - added .ini startup file capability @@ -2357,7 +2371,7 @@ patch date module(s) and fix(es) IBM 1620: first release -/* V2.9 revision history + V2.9 revision history 11 20-Jul-02 i1401_mt.c: on read, end of record stores group mark without word mark (Van Snyder) diff --git a/sim_serial.c b/sim_serial.c index 2b493195..1a57c0bc 100644 --- a/sim_serial.c +++ b/sim_serial.c @@ -145,7 +145,7 @@ static struct open_serial_device { char name[SER_DEV_NAME_MAX]; char desc[SER_DEV_DESC_MAX]; } *serial_open_devices = NULL; -static serial_open_device_count = 0; +static int serial_open_device_count = 0; static void _serial_add_to_open_list (SERHANDLE port, TMLN *line, const char *name, const char *desc) { @@ -318,7 +318,7 @@ for (i=0; i +extern FILE *sim_log; + +#if defined(AF_INET6) && defined(_WIN32) +#include +#endif + +#ifndef WSAAPI +#define WSAAPI +#endif + +#if defined(SHUT_RDWR) && !defined(SD_BOTH) +#define SD_BOTH SHUT_RDWR +#endif + +#ifndef NI_MAXHOST +#define NI_MAXHOST 1025 +#endif + /* OS dependent routines sim_master_sock create master socket @@ -54,23 +73,118 @@ sim_msg_sock send message to socket */ -int32 sim_sock_cnt = 0; +/* OS independent routines + + sim_parse_addr parse a hostname/ipaddress from port and apply defaults +*/ + +/* sim_parse_addr host:port + + Presumption is that the input, if it doesn't contain a ':' character is a port specifier. + If the host field contains one or more colon characters (i.e. it is an IPv6 address), + the IPv6 address MUST be enclosed in square bracket characters (i.e. Domain Literal format) + + Inputs: + cptr = pointer to input string + default_host + = optional pointer to default host if none specified + host_len = length of host buffer + default_port + = optional pointer to default host if none specified + port_len = length of port buffer + Outputs: + host = pointer to buffer for IP address (may be NULL), 0 = none + port = pointer to buffer for IP port (may be NULL), 0 = none + result = status +*/ + +t_stat sim_parse_addr (const char *cptr, char *host, size_t host_len, const char *default_host, char *port, size_t port_len, const char *default_port) +{ +char gbuf[CBUFSIZE]; +char *hostp, *portp; +char *endc; +unsigned long portval; + +if ((cptr == NULL) || (*cptr == 0)) + return SCPE_ARG; +if ((host != NULL) && (host_len != 0)) + memset (host, 0, host_len); +if ((port != NULL) && (port_len != 0)) + memset (port, 0, port_len); +strncpy (gbuf, cptr, CBUFSIZE); +hostp = gbuf; /* default addr */ +portp = NULL; +if ((portp = strrchr (gbuf, ':')) && /* x:y? split */ + (NULL == strchr (portp, ']'))) { + *portp++ = 0; + if (*portp == '\0') + portp = (char *)default_port; + } +else + if (default_port) + portp = (char *)default_port; + else { + portp = gbuf; + hostp = NULL; + } +if (portp != NULL) { + portval = strtoul(portp, &endc, 10); + if ((*endc == '\0') && ((portval == 0) || (portval > 65535))) + return SCPE_ARG; /* value too big */ + if (*endc != '\0') { + struct servent *se = getservbyname(portp, "tcp"); + + if (se == NULL) + return SCPE_ARG; /* invalid service name */ + } + } +if (port) /* port wanted? */ + if (portp != NULL) { + if (strlen(portp) >= port_len) + return SCPE_ARG; /* no room */ + else + strcpy (port, portp); + } +if (hostp != NULL) { + if (']' == hostp[strlen(hostp)-1]) { + if ('[' != hostp[0]) + return SCPE_ARG; /* invalid domain literal */ + strcpy(hostp, hostp+1); /* remove brackets from domain literal host */ + hostp[strlen(hostp)-1] = '\0'; + } + } +if (host) /* host wanted? */ + if (hostp != NULL) + if (strlen(hostp) >= host_len) + return SCPE_ARG; /* no room */ + else + strcpy (host, hostp); +return SCPE_OK; +} /* First, all the non-implemented versions */ #if defined (__OS2__) && !defined (__EMX__) -SOCKET sim_master_sock (int32 port) +void sim_init_sock (void) +{ +} + +void sim_cleanup_sock (void) +{ +} + +SOCKET sim_master_sock (const char *hostport, t_stat *parse_status) { return INVALID_SOCKET; } -SOCKET sim_connect_sock (int32 ip, int32 port) +SOCKET sim_connect_sock (const char *hostport, const char *default_host, const char *default_port) { return INVALID_SOCKET; } -SOCKET sim_accept_conn (SOCKET master, uint32 *ipaddr) +SOCKET sim_accept_conn (SOCKET master, char **connectaddr); { return INVALID_SOCKET; } @@ -90,11 +204,6 @@ void sim_close_sock (SOCKET sock, t_bool master) return; } -int32 sim_setnonblock (SOCKET sock) -{ -return SOCKET_ERROR; -} - #else /* endif unimpl */ /* UNIX, Win32, Macintosh, VMS, OS2 (Berkeley socket) routines */ @@ -108,30 +217,383 @@ sim_close_sock (s, flg); return INVALID_SOCKET; } -SOCKET sim_create_sock (void) +static void (WSAAPI *p_freeaddrinfo) (struct addrinfo *ai); + +static int (WSAAPI *p_getaddrinfo) (const char *hostname, + const char *service, + const struct addrinfo *hints, + struct addrinfo **res); + +static int (WSAAPI *p_getnameinfo) (const struct sockaddr *sa, socklen_t salen, + char *host, size_t hostlen, + char *serv, size_t servlen, + int flags); + + +static void WSAAPI s_freeaddrinfo (struct addrinfo *ai) { -SOCKET newsock; -int32 err; +struct addrinfo *a, *an; -#if defined (_WIN32) -WORD wVersionRequested; -WSADATA wsaData; -wVersionRequested = MAKEWORD (1, 1); +for (a=ai; a != NULL; a=an) { + an = a->ai_next; + free (a->ai_canonname); + free (a->ai_addr); + free (a); + } +} -if (sim_sock_cnt == 0) { - err = WSAStartup (wVersionRequested, &wsaData); /* start Winsock */ - if (err != 0) { - printf ("Winsock: startup error %d\n", err); - return INVALID_SOCKET; +static int WSAAPI s_getaddrinfo (const char *hostname, + const char *service, + const struct addrinfo *hints, + struct addrinfo **res) +{ +struct hostent *he; +struct servent *se; +struct sockaddr_in *sin; +struct addrinfo *result = NULL; +struct addrinfo *ai, *lai; +struct addrinfo dhints; +struct in_addr ipaddr; +struct in_addr *fixed[2]; +struct in_addr **ips; +struct in_addr **ip; +const char *cname = NULL; +int port = 0; + +// Validate parameters +if ((hostname == NULL) && (service == NULL)) + return EAI_NONAME; + +if (hints) { + if ((hints->ai_family != PF_INET) && (hints->ai_family != PF_UNSPEC)) + return EAI_FAMILY; + switch (hints->ai_socktype) + { + default: + return EAI_SOCKTYPE; + case SOCK_DGRAM: + case SOCK_STREAM: + case 0: + break; } } -sim_sock_cnt = sim_sock_cnt + 1; +else { + hints = &dhints; + memset(&dhints, 0, sizeof(dhints)); + dhints.ai_family = PF_UNSPEC; + } +if (service) { + char *c; + + port = strtoul(service, &c, 10); + if ((port == 0) && (*c != '\0') && (hints->ai_flags & AI_NUMERICSERV)) + return EAI_NONAME; + if ((port == 0) || (*c != '\0')) { + switch (hints->ai_socktype) + { + case SOCK_DGRAM: + se = getservbyname(service, "udp"); + break; + case SOCK_STREAM: + case 0: + se = getservbyname(service, "tcp"); + break; + } + if (NULL == se) + return EAI_SERVICE; + port = se->s_port; + } + } + +if (hostname) { + if ((0xffffffff != (ipaddr.s_addr = inet_addr(hostname))) || + (0 == strcmp("255.255.255.255", hostname))) { + fixed[0] = &ipaddr; + fixed[1] = NULL; + } + else { + if ((0xffffffff != (ipaddr.s_addr = inet_addr(hostname))) || + (0 == strcmp("255.255.255.255", hostname))) { + fixed[0] = &ipaddr; + fixed[1] = NULL; + if ((hints->ai_flags & AI_CANONNAME) && !(hints->ai_flags & AI_NUMERICHOST)) { + he = gethostbyaddr((char *)&ipaddr, 4, AF_INET); + if (NULL != he) + cname = he->h_name; + else + cname = hostname; + } + ips = fixed; + } + else { + if (hints->ai_flags & AI_NUMERICHOST) + return EAI_NONAME; + he = gethostbyname(hostname); + if (he) { + ips = (struct in_addr **)he->h_addr_list; + if (hints->ai_flags & AI_CANONNAME) + cname = he->h_name; + } + else { + switch (h_errno) + { + case HOST_NOT_FOUND: + case NO_DATA: + return EAI_NONAME; + case TRY_AGAIN: + return EAI_AGAIN; + default: + return EAI_FAIL; + } + } + } + } + } +else { + if (hints->ai_flags & AI_PASSIVE) + ipaddr.s_addr = htonl(INADDR_ANY); + else + ipaddr.s_addr = htonl(INADDR_LOOPBACK); + fixed[0] = &ipaddr; + fixed[1] = NULL; + ips = fixed; + } +for (ip=ips; *ip != NULL; ++ip) { + ai = calloc(1, sizeof(*ai)); + if (NULL == ai) { + s_freeaddrinfo(result); + return EAI_MEMORY; + } + ai->ai_family = PF_INET; + ai->ai_socktype = hints->ai_socktype; + ai->ai_protocol = hints->ai_protocol; + ai->ai_addr = NULL; + ai->ai_addrlen = sizeof(struct sockaddr_in); + ai->ai_canonname = NULL; + ai->ai_next = NULL; + ai->ai_addr = calloc(1, sizeof(struct sockaddr_in)); + if (NULL == ai->ai_addr) { + free(ai); + s_freeaddrinfo(result); + return EAI_MEMORY; + } + sin = (struct sockaddr_in *)ai->ai_addr; + sin->sin_family = PF_INET; + sin->sin_port = port; + memcpy(&sin->sin_addr, *ip, sizeof(sin->sin_addr)); + if (NULL == result) + result = ai; + else + lai->ai_next = ai; + lai = ai; + } +if (cname) { + result->ai_canonname = calloc(1, strlen(cname)+1); + if (NULL == result->ai_canonname) { + s_freeaddrinfo(result); + return EAI_MEMORY; + } + strcpy(result->ai_canonname, cname); + } +*res = result; +return 0; +} + +#ifndef EAI_OVERFLOW +#define EAI_OVERFLOW WSAENAMETOOLONG +#endif + +static int WSAAPI s_getnameinfo (const struct sockaddr *sa, socklen_t salen, + char *host, size_t hostlen, + char *serv, size_t servlen, + int flags) +{ +struct hostent *he; +struct servent *se = NULL; +struct sockaddr_in *sin = (struct sockaddr_in *)sa; + +if (sin->sin_family != PF_INET) + return EAI_FAMILY; +if ((NULL == host) && (NULL == serv)) + return EAI_NONAME; +if ((serv) && (servlen > 0)) { + if (flags & NI_NUMERICSERV) + se = NULL; + else + if (flags & NI_DGRAM) + se = getservbyport(sin->sin_port, "udp"); + else + se = getservbyport(sin->sin_port, "tcp"); + if (se) { + if (servlen <= strlen(se->s_name)) + return EAI_OVERFLOW; + strcpy(serv, se->s_name); + } + else { + char buf[16]; + + sprintf(buf, "%d", ntohs(sin->sin_port)); + if (servlen <= strlen(buf)) + return EAI_OVERFLOW; + strcpy(serv, buf); + } + } +if ((host) && (hostlen > 0)) { + if (flags & NI_NUMERICHOST) + he = NULL; + else + he = gethostbyaddr((char *)&sin->sin_addr, 4, AF_INET); + if (he) { + if (hostlen < strlen(he->h_name)+1) + return EAI_OVERFLOW; + strcpy(host, he->h_name); + } + else { + if (flags & NI_NAMEREQD) + return EAI_NONAME; + if (hostlen < strlen(inet_ntoa(sin->sin_addr))+1) + return EAI_OVERFLOW; + strcpy(host, inet_ntoa(sin->sin_addr)); + } + } +return 0; +} + +#if defined(_WIN32) || defined(__CYGWIN__) + +/* Dynamic DLL load variables */ +static HINSTANCE hLib = 0; /* handle to DLL */ +static int lib_loaded = 0; /* 0=not loaded, 1=loaded, 2=library load failed, 3=Func load failed */ +static char* lib_name = "Ws2_32.dll"; + +/* load function pointer from DLL */ +typedef int (*_func)(); + +static void load_function(char* function, _func* func_ptr) { + *func_ptr = (_func)GetProcAddress(hLib, function); + if (*func_ptr == 0) { + char* msg = "Sockets: Failed to find function '%s' in %s\r\n"; + + printf (msg, function, lib_name); + if (sim_log) fprintf (sim_log, msg, function, lib_name); + lib_loaded = 3; + } +} + +/* load Ws2_32.dll as required */ +int load_ws2(void) { + switch(lib_loaded) { + case 0: /* not loaded */ + /* attempt to load DLL */ +#ifdef _WIN32 + hLib = LoadLibraryA(lib_name); +#else + hLib = dlopen(lib_name, RTLD_NOW); +#endif + if (hLib == 0) { + /* failed to load DLL */ + char* msg = "Sockets: Failed to load %s\r\n"; + + printf (msg, lib_name); + if (sim_log) + fprintf (sim_log, msg, lib_name); + lib_loaded = 2; + break; + } else { + /* library loaded OK */ + lib_loaded = 1; + } + + /* load required functions; sets dll_load=3 on error */ + load_function("getaddrinfo", (_func *) &p_getaddrinfo); + load_function("getnameinfo", (_func *) &p_getnameinfo); + load_function("freeaddrinfo", (_func *) &p_freeaddrinfo); + + if (lib_loaded != 1) { + /* unsuccessful load, connect stubs */ + p_getaddrinfo = s_getaddrinfo; + p_getnameinfo = s_getnameinfo; + p_freeaddrinfo = s_freeaddrinfo; + } + break; + default: /* loaded or failed */ + break; + } + return (lib_loaded == 1) ? 1 : 0; +} +#endif + +void sim_init_sock (void) +{ +#if defined (_WIN32) +int err; +WORD wVersionRequested; +WSADATA wsaData; +wVersionRequested = MAKEWORD (2, 2); + + +err = WSAStartup (wVersionRequested, &wsaData); /* start Winsock */ +if (err != 0) + printf ("Winsock: startup error %d\n", err); +#if defined(AF_INET6) +load_ws2 (); +#endif /* endif AF_INET6 */ #endif /* endif Win32 */ #if defined (SIGPIPE) signal (SIGPIPE, SIG_IGN); /* no pipe signals */ #endif +} -newsock = socket (AF_INET, SOCK_STREAM, 0); /* create socket */ +void sim_cleanup_sock (void) +{ +#if defined (_WIN32) +WSACleanup (); +#endif +} + +#if defined (_WIN32) /* Windows */ +static int32 sim_setnonblock (SOCKET sock) +{ +unsigned long non_block = 1; + +return ioctlsocket (sock, FIONBIO, &non_block); /* set nonblocking */ +} + +#elif defined (VMS) /* VMS */ +static int32 sim_setnonblock (SOCKET sock) +{ +int non_block = 1; + +return ioctl (sock, FIONBIO, &non_block); /* set nonblocking */ +} + +#else /* Mac, Unix, OS/2 */ +static int32 sim_setnonblock (SOCKET sock) +{ +int32 fl, sta; + +fl = fcntl (sock, F_GETFL,0); /* get flags */ +if (fl == -1) + return SOCKET_ERROR; +sta = fcntl (sock, F_SETFL, fl | O_NONBLOCK); /* set nonblock */ +if (sta == -1) + return SOCKET_ERROR; +#if !defined (macintosh) && !defined (__EMX__) /* Unix only */ +sta = fcntl (sock, F_SETOWN, getpid()); /* set ownership */ +if (sta == -1) + return SOCKET_ERROR; +#endif +return 0; +} + +#endif /* endif !Win32 && !VMS */ + +static SOCKET sim_create_sock (int af) +{ +SOCKET newsock; +int32 err; + +newsock = socket (af, SOCK_STREAM, 0); /* create socket */ if (newsock == INVALID_SOCKET) { /* socket error? */ err = WSAGetLastError (); printf ("Sockets: socket error %d\n", err); @@ -140,21 +602,49 @@ if (newsock == INVALID_SOCKET) { /* socket error? */ return newsock; } -SOCKET sim_master_sock (int32 port) -{ -SOCKET newsock; -struct sockaddr_in name; -int32 sta; +/* + Some platforms and/or network stacks have varying support for listening on + an IPv6 socket and receiving connections from both IPv4 and IPv6 client + connections. This is known as IPv4-Mapped. Some platforms claim such + support (i.e. some Windows versions), but it doesn't work in all cases. +*/ -newsock = sim_create_sock (); /* create socket */ -if (newsock == INVALID_SOCKET) /* socket error? */ +SOCKET sim_master_sock (const char *hostport, t_stat *parse_status) +{ +SOCKET newsock = INVALID_SOCKET; +int32 sta; +char host[CBUFSIZE], port[CBUFSIZE]; +t_stat r; +struct addrinfo hints; +struct addrinfo *result = NULL; + +r = sim_parse_addr (hostport, host, sizeof(host), NULL, port, sizeof(port), NULL); +if (parse_status) + *parse_status = r; +if (r != SCPE_OK) return newsock; -name.sin_family = AF_INET; /* name socket */ -name.sin_port = htons ((unsigned short) port); /* insert port */ -name.sin_addr.s_addr = htonl (INADDR_ANY); /* insert addr */ - -sta = bind (newsock, (struct sockaddr *) &name, sizeof (name)); +memset(&hints, 0, sizeof(hints)); +hints.ai_flags = AI_PASSIVE; +hints.ai_family = AF_UNSPEC; +hints.ai_protocol = IPPROTO_TCP; +hints.ai_socktype = SOCK_STREAM; +if (p_getaddrinfo(host[0] ? host : NULL, port[0] ? port : NULL, &hints, &result)) { + if (parse_status) + *parse_status = SCPE_ARG; + return newsock; + } +newsock = sim_create_sock (result->ai_family); /* create socket */ +if (newsock == INVALID_SOCKET) { /* socket error? */ + p_freeaddrinfo(result); + return newsock; + } +if (result->ai_family == AF_INET6) { + int off = FALSE; + sta = setsockopt (newsock, IPPROTO_IPV6, IPV6_V6ONLY, (char *)&off, sizeof(off)); + } +sta = bind (newsock, result->ai_addr, result->ai_addrlen); +p_freeaddrinfo(result); if (sta == SOCKET_ERROR) /* bind error? */ return sim_err_sock (newsock, "bind", 1); sta = sim_setnonblock (newsock); /* set nonblocking */ @@ -166,24 +656,38 @@ if (sta == SOCKET_ERROR) /* listen error? */ return newsock; /* got it! */ } -SOCKET sim_connect_sock (int32 ip, int32 port) +SOCKET sim_connect_sock (const char *hostport, const char *default_host, const char *default_port) { -SOCKET newsock; -struct sockaddr_in name; +SOCKET newsock = INVALID_SOCKET; int32 sta; +char host[CBUFSIZE], port[CBUFSIZE]; +t_stat r; +struct addrinfo hints; +struct addrinfo *result = NULL; -newsock = sim_create_sock (); /* create socket */ -if (newsock == INVALID_SOCKET) /* socket error? */ +r = sim_parse_addr (hostport, host, sizeof(host), default_host, port, sizeof(port), default_port); +if (r != SCPE_OK) return newsock; -name.sin_family = AF_INET; /* name socket */ -name.sin_port = htons ((unsigned short) port); /* insert port */ -name.sin_addr.s_addr = htonl (ip); /* insert addr */ +memset(&hints, 0, sizeof(hints)); +hints.ai_family = AF_UNSPEC; +hints.ai_protocol = IPPROTO_TCP; +hints.ai_socktype = SOCK_STREAM; +if (p_getaddrinfo(host[0] ? host : NULL, port[0] ? port : NULL, &hints, &result)) + return newsock; +newsock = sim_create_sock (result->ai_family); /* create socket */ +if (newsock == INVALID_SOCKET) { /* socket error? */ + p_freeaddrinfo (result); + return newsock; + } sta = sim_setnonblock (newsock); /* set nonblocking */ -if (sta == SOCKET_ERROR) /* fcntl error? */ +if (sta == SOCKET_ERROR) { /* fcntl error? */ + p_freeaddrinfo (result); return sim_err_sock (newsock, "fcntl", 1); -sta = connect (newsock, (struct sockaddr *) &name, sizeof (name)); + } +sta = connect (newsock, result->ai_addr, result->ai_addrlen); +p_freeaddrinfo (result); if ((sta == SOCKET_ERROR) && (WSAGetLastError () != WSAEWOULDBLOCK) && (WSAGetLastError () != WSAEINPROGRESS)) @@ -192,7 +696,7 @@ if ((sta == SOCKET_ERROR) && return newsock; /* got it! */ } -SOCKET sim_accept_conn (SOCKET master, uint32 *ipaddr) +SOCKET sim_accept_conn (SOCKET master, char **connectaddr) { int32 sta, err; #if defined (macintosh) || defined (__linux) || \ @@ -206,11 +710,12 @@ int size; size_t size; #endif SOCKET newsock; -struct sockaddr_in clientname; +struct sockaddr_storage clientname; if (master == 0) /* not attached? */ return INVALID_SOCKET; size = sizeof (clientname); +memset (&clientname, 0, sizeof(clientname)); newsock = accept (master, (struct sockaddr *) &clientname, &size); if (newsock == INVALID_SOCKET) { /* error? */ err = WSAGetLastError (); @@ -218,8 +723,14 @@ if (newsock == INVALID_SOCKET) { /* error? */ printf ("Sockets: accept error %d\n", err); return INVALID_SOCKET; } -if (ipaddr != NULL) - *ipaddr = ntohl (clientname.sin_addr.s_addr); +if (connectaddr != NULL) { + *connectaddr = calloc(1, NI_MAXHOST+1); +#ifdef AF_INET6 + p_getnameinfo((struct sockaddr *)&clientname, size, *connectaddr, NI_MAXHOST, NULL, 0, NI_NUMERICHOST); +#else + strcpy(*connectaddr, inet_ntoa(((struct sockaddr_in *)&connectaddr)->s_addr)); +#endif + } sta = sim_setnonblock (newsock); /* set nonblocking */ if (sta == SOCKET_ERROR) /* fcntl error? */ @@ -273,56 +784,8 @@ return send (sock, msg, nbytes, 0); void sim_close_sock (SOCKET sock, t_bool master) { -#if defined (_WIN32) +shutdown(sock, SD_BOTH); closesocket (sock); -if (master) { - sim_sock_cnt = sim_sock_cnt - 1; - if (sim_sock_cnt <= 0) { - WSACleanup (); - sim_sock_cnt = 0; - } - } -#else -close (sock); -#endif -return; } -#if defined (_WIN32) /* Windows */ -int32 sim_setnonblock (SOCKET sock) -{ -unsigned long non_block = 1; - -return ioctlsocket (sock, FIONBIO, &non_block); /* set nonblocking */ -} - -#elif defined (VMS) /* VMS */ -int32 sim_setnonblock (SOCKET sock) -{ -int non_block = 1; - -return ioctl (sock, FIONBIO, &non_block); /* set nonblocking */ -} - -#else /* Mac, Unix, OS/2 */ -int32 sim_setnonblock (SOCKET sock) -{ -int32 fl, sta; - -fl = fcntl (sock, F_GETFL,0); /* get flags */ -if (fl == -1) - return SOCKET_ERROR; -sta = fcntl (sock, F_SETFL, fl | O_NONBLOCK); /* set nonblock */ -if (sta == -1) - return SOCKET_ERROR; -#if !defined (macintosh) && !defined (__EMX__) /* Unix only */ -sta = fcntl (sock, F_SETOWN, getpid()); /* set ownership */ -if (sta == -1) - return SOCKET_ERROR; -#endif -return 0; -} - -#endif /* endif !Win32 && !VMS */ - #endif /* end else !implemented */ diff --git a/sim_sock.h b/sim_sock.h index d8531cbe..250ac3c8 100644 --- a/sim_sock.h +++ b/sim_sock.h @@ -23,6 +23,7 @@ used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from Robert M Supnik. + 25-Sep-12 MP Reworked for RFC3493 interfaces supporting IPv6 and IPv4 04-Jun-08 RMS Addes sim_create_sock, for IBM 1130 14-Apr-05 RMS Added WSAEINPROGRESS (from Tim Riker) 20-Aug-04 HV Added missing definition for OS/2 (from Holger Veit) @@ -49,16 +50,18 @@ #elif !defined (__OS2__) || defined (__EMX__) /* VMS, Mac, Unix, OS/2 EMX */ #define WSAGetLastError() errno /* Windows macros */ +#define closesocket close #define SOCKET int32 #define WSAEWOULDBLOCK EWOULDBLOCK #define WSAEINPROGRESS EINPROGRESS -#define INVALID_SOCKET -1 +#define INVALID_SOCKET ((SOCKET)-1) #define SOCKET_ERROR -1 #include /* for fcntl, getpid */ #include /* for sockets */ #include #include #include /* for sockaddr_in */ +#include /* for inet_addr and inet_ntoa */ #include #include /* for EMX */ #endif @@ -75,14 +78,15 @@ #endif #endif -SOCKET sim_master_sock (int32 port); -SOCKET sim_connect_sock (int32 ip, int32 port); -SOCKET sim_create_sock (void); -SOCKET sim_accept_conn (SOCKET master, uint32 *ipaddr); +t_stat sim_parse_addr (const char *cptr, char *host, size_t hostlen, const char *default_host, char *port, size_t port_len, const char *default_port); +SOCKET sim_master_sock (const char *hostport, t_stat *parse_status); +SOCKET sim_connect_sock (const char *hostport, const char *default_host, const char *default_port); +SOCKET sim_accept_conn (SOCKET master, char **connectaddr); int32 sim_check_conn (SOCKET sock, t_bool rd); int32 sim_read_sock (SOCKET sock, char *buf, int32 nbytes); int32 sim_write_sock (SOCKET sock, char *msg, int32 nbytes); void sim_close_sock (SOCKET sock, t_bool master); -int32 sim_setnonblock (SOCKET sock); +void sim_init_sock (void); +void sim_cleanup_sock (void); #endif diff --git a/sim_tape.c b/sim_tape.c index c6cbe410..91cf3032 100644 --- a/sim_tape.c +++ b/sim_tape.c @@ -125,6 +125,7 @@ struct tape_context { pthread_t io_thread; /* I/O Thread Id */ pthread_mutex_t io_lock; pthread_cond_t io_cond; + pthread_cond_t startup_cond; int io_top; uint8 *buf; uint32 *bc; @@ -211,6 +212,7 @@ struct tape_context *ctx = (struct tape_context *)uptr->tape_ctx; sim_debug (ctx->dbit, ctx->dptr, "_tape_io(unit=%d) starting\n", uptr-ctx->dptr->units); pthread_mutex_lock (&ctx->io_lock); + pthread_cond_signal (&ctx->startup_cond); /* Signal we're ready to go */ while (1) { pthread_cond_wait (&ctx->io_cond, &ctx->io_lock); if (ctx->io_top == TOP_DONE) @@ -331,10 +333,15 @@ ctx->asynch_io_latency = latency; if (ctx->asynch_io) { pthread_mutex_init (&ctx->io_lock, NULL); pthread_cond_init (&ctx->io_cond, NULL); + pthread_cond_init (&ctx->startup_cond, NULL); pthread_attr_init(&attr); pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM); + pthread_mutex_lock (&ctx->io_lock); pthread_create (&ctx->io_thread, &attr, _tape_io, (void *)uptr); pthread_attr_destroy(&attr); + pthread_cond_wait (&ctx->startup_cond, &ctx->io_lock); /* Wait for thread to stabilize */ + pthread_mutex_unlock (&ctx->io_lock); + pthread_cond_destroy (&ctx->startup_cond); } uptr->a_check_completion = _tape_completion_dispatch; #endif @@ -761,7 +768,7 @@ t_stat st; sim_debug (ctx->dbit, ctx->dptr, "sim_tape_rdrecf(unit=%d, buf=%p, max=%d)\n", uptr-ctx->dptr->units, buf, max); opos = uptr->pos; /* old position */ -if (st = sim_tape_rdlntf (uptr, &tbc)) /* read rec lnt */ +if (MTSE_OK != (st = sim_tape_rdlntf (uptr, &tbc))) /* read rec lnt */ return st; *bc = rbc = MTR_L (tbc); /* strip error flag */ if (rbc > max) { /* rec out of range? */ @@ -823,7 +830,7 @@ t_stat st; sim_debug (ctx->dbit, ctx->dptr, "sim_tape_rdrecr(unit=%d, buf=%p, max=%d)\n", uptr-ctx->dptr->units, buf, max); -if (st = sim_tape_rdlntr (uptr, &tbc)) /* read rec lnt */ +if (MTSE_OK != (st = sim_tape_rdlntr (uptr, &tbc))) /* read rec lnt */ return st; *bc = rbc = MTR_L (tbc); /* strip error flag */ if (rbc > max) /* rec out of range? */ diff --git a/sim_tmxr.c b/sim_tmxr.c index 0bb1b746..62383622 100644 --- a/sim_tmxr.c +++ b/sim_tmxr.c @@ -634,7 +634,8 @@ SOCKET newsock; TMLN *lp; int32 *op; int32 i, j; -uint32 ipaddr, current_time; +uint32 current_time; +char *address; t_bool deferrals; static char mantra[] = { TN_IAC, TN_WILL, TN_LINE, @@ -674,7 +675,7 @@ if (mp->pending) { /* is there a pending se /* Check for a pending Telnet connection */ -newsock = sim_accept_conn (mp->master, &ipaddr); /* poll connect */ +newsock = sim_accept_conn (mp->master, &address); /* poll connect */ if (newsock != INVALID_SOCKET) { /* got a live one? */ op = mp->lnorder; /* get line connection order list pointer */ @@ -699,7 +700,7 @@ if (newsock != INVALID_SOCKET) { /* got a live one? */ lp = mp->ldsc + i; /* get line desc */ tmxr_init_line (lp); /* init line */ lp->conn = newsock; /* record connection */ - lp->ipad = ipaddr; /* ip address */ + lp->ipad = address; /* ip address */ sim_write_sock (newsock, mantra, sizeof(mantra)); tmxr_debug (TMXR_DBG_XMT, lp, "Sending", mantra, sizeof(mantra)); tmxr_report_connection (mp, lp, i); @@ -1092,13 +1093,15 @@ return (lp->txbpi - lp->txbpr + ((lp->txbpi < lp->txbpr)? lp->txbsz: 0)); t_stat tmxr_open_master (TMXR *mp, char *cptr) { -int32 i, port; +int32 i; SOCKET sock; TMLN *lp; t_stat r; if (!isdigit(*cptr)) { char gbuf[CBUFSIZE]; + char *init_cptr = cptr; + cptr = get_glyph (cptr, gbuf, '='); if (0 == MATCH_CMD (gbuf, "LOG")) { if ((NULL == cptr) || ('\0' == *cptr)) @@ -1170,18 +1173,20 @@ if (!isdigit(*cptr)) { } return SCPE_OK; } - return SCPE_ARG; + if (SCPE_OK != sim_parse_addr (gbuf, NULL, 0, NULL, NULL, 0, NULL)) + return SCPE_ARG; + cptr = init_cptr; } -port = (int32) get_uint (cptr, 10, 65535, &r); /* get port */ -if ((r != SCPE_OK) || (port == 0)) - return SCPE_ARG; -sock = sim_master_sock (port); /* make master socket */ +sock = sim_master_sock (cptr, &r); /* make master socket */ +if (r != SCPE_OK) + return r; if (sock == INVALID_SOCKET) /* open error */ return SCPE_OPENERR; -printf ("Listening on port %d (socket %d)\n", port, sock); +printf ("Listening on port %s (socket %d)\n", cptr, sock); if (sim_log) - fprintf (sim_log, "Listening on port %d (socket %d)\n", port, sock); -mp->port = port; /* save port */ + fprintf (sim_log, "Listening on port %s (socket %d)\n", cptr, sock); +mp->port = calloc(1, 1+strlen(cptr)); /* save port */ +strcpy(mp->port, cptr); mp->master = sock; /* save master socket */ for (i = 0; i < mp->lines; i++) { /* initialize lines */ lp = mp->ldsc + i; @@ -1201,7 +1206,7 @@ t_stat tmxr_attach (TMXR *mp, UNIT *uptr, char *cptr) { char* tptr; t_stat r; -char pmsg[20], bmsg[32] = "", lmsg[64+PATH_MAX] = ""; +char pmsg[256], bmsg[32] = "", lmsg[64+PATH_MAX] = ""; tptr = (char *) malloc (strlen (cptr) + /* get string buf */ sizeof(pmsg) + @@ -1213,7 +1218,7 @@ if (r != SCPE_OK) { /* error? */ free (tptr); /* release buf */ return r; } -sprintf (pmsg, "%d", mp->port); /* copy port */ +sprintf (pmsg, "%s", mp->port); /* copy port */ if (mp->buffered) sprintf (bmsg, ", buffered=%d", mp->buffered); /* buffer info */ if (mp->logfiletmpl[0]) @@ -1618,18 +1623,14 @@ if (ln >= 0) fprintf (st, "line %d: ", ln); if (lp->conn) { - int32 o1, o2, o3, o4, hr, mn, sc; + int32 hr, mn, sc; uint32 ctime; if (lp->serport) /* serial connection? */ fprintf (st, "Serial port %s", lp->sername); /* print port name */ else { /* socket connection */ - o1 = (lp->ipad >> 24) & 0xFF; - o2 = (lp->ipad >> 16) & 0xFF; - o3 = (lp->ipad >> 8) & 0xFF; - o4 = (lp->ipad) & 0xFF; - fprintf (st, "IP address %d.%d.%d.%d", o1, o2, o3, o4); + fprintf (st, "IP address %s", lp->ipad); } ctime = (sim_os_msec () - lp->cnms) / 1000; diff --git a/sim_tmxr.h b/sim_tmxr.h index 63c55af9..38ade11c 100644 --- a/sim_tmxr.h +++ b/sim_tmxr.h @@ -44,11 +44,12 @@ added tmxr_rqln, tmxr_tqln */ +#include "sim_serial.h" /* We need serial I/O (SERHANDLE) */ + #ifndef _SIM_TMXR_H_ #define _SIM_TMXR_H_ 0 #include "sim_sock.h" /* We need sockets */ -#include "sim_serial.h" /* We need serial I/O (SERHANDLE) */ #define TMXR_V_VALID 15 #define TMXR_VALID (1 << TMXR_V_VALID) @@ -63,7 +64,7 @@ typedef struct tmxr TMXR; struct tmln { SOCKET conn; /* line conn */ - uint32 ipad; /* IP address */ + char *ipad; /* IP address */ uint32 cnms; /* conn time */ int32 tsta; /* Telnet state */ int32 rcve; /* rcv enable */ @@ -91,7 +92,7 @@ struct tmln { struct tmxr { int32 lines; /* # lines */ - int32 port; /* listening port */ + char *port; /* listening port */ SOCKET master; /* master socket */ TMLN *ldsc; /* line descriptors */ int32 *lnorder; /* line connection order */ diff --git a/swtp6800/common/dc-4.c b/swtp6800/common/dc-4.c index 80cfd54d..b4aff57d 100644 --- a/swtp6800/common/dc-4.c +++ b/swtp6800/common/dc-4.c @@ -551,18 +551,18 @@ int32 fdcdata(int32 io, int32 data) } return 0; } else { /* read byte from fdc */ - if (dsk_unit[cur_dsk].pos < SECSIZ) { /* copy bytes from buffer */ - if (dsk_dev.dctrl & DEBUG_read) - printf("\nfdcdata: Reading byte %d u3=%02X", dsk_unit[cur_dsk].pos, dsk_unit[cur_dsk].u3); - val = *((uint8 *)(dsk_unit[cur_dsk].filebuf) + dsk_unit[cur_dsk].pos) & 0xFF; - dsk_unit[cur_dsk].pos++; /* step counter */ - if (dsk_unit[cur_dsk].pos == SECSIZ) { /* done? */ - dsk_unit[cur_dsk].u3 &= ~(BUSY | DRQ); /* clear flags */ - if (dsk_dev.dctrl & DEBUG_write) - printf("\nfdcdata: Sector read complete"); - } - return val; - } else + if (dsk_unit[cur_dsk].pos < SECSIZ) { /* copy bytes from buffer */ + if (dsk_dev.dctrl & DEBUG_read) + printf("\nfdcdata: Reading byte %d u3=%02X", dsk_unit[cur_dsk].pos, dsk_unit[cur_dsk].u3); + val = *((uint8 *)(dsk_unit[cur_dsk].filebuf) + dsk_unit[cur_dsk].pos) & 0xFF; + dsk_unit[cur_dsk].pos++; /* step counter */ + if (dsk_unit[cur_dsk].pos == SECSIZ) { /* done? */ + dsk_unit[cur_dsk].u3 &= ~(BUSY | DRQ); /* clear flags */ + if (dsk_dev.dctrl & DEBUG_write) + printf("\nfdcdata: Sector read complete"); + } + return val; + } else return 0; } } diff --git a/swtp6800/common/m6800.c b/swtp6800/common/m6800.c index c7f8bf02..c78a5bbb 100644 --- a/swtp6800/common/m6800.c +++ b/swtp6800/common/m6800.c @@ -316,7 +316,7 @@ int32 sim_instr (void) while (reason == 0) { /* loop until halted */ // dump_regs1(); if (sim_interval <= 0) /* check clock queue */ - if (reason = sim_process_event ()) + if ((reason = sim_process_event ())) break; if (mem_fault) { /* memory fault? */ mem_fault = 0; /* reset fault flag */ diff --git a/swtp6800/common/mp-s.c b/swtp6800/common/mp-s.c index 6c9c12a3..13ba3b12 100644 --- a/swtp6800/common/mp-s.c +++ b/swtp6800/common/mp-s.c @@ -1,4 +1,4 @@ -/* mp-s.c: SWTP MP-S serial I/O card emulator +/* mp-s.c: SWTP MP-S serial I/O card simulator Copyright (c) 2005-2011, William Beech @@ -188,6 +188,7 @@ int32 sio_reset (DEVICE *dptr) { sio_unit.buf = 0; // Data buffer sio_unit.u3 = 0x02; // Status buffer + sio_unit.wait = 10000; sim_activate (&sio_unit, sio_unit.wait); // activate unit return SCPE_OK; } @@ -198,8 +199,8 @@ int32 ptr_reset (DEVICE *dptr) { ptr_unit.buf = 0; ptr_unit.u3 = 0x02; - sim_activate (&ptr_unit, ptr_unit.wait); // activate unit -// sim_cancel (&ptr_unit); // deactivate unit +// sim_activate (&ptr_unit, ptr_unit.wait); // activate unit + sim_cancel (&ptr_unit); // deactivate unit return SCPE_OK; } @@ -209,8 +210,8 @@ int32 ptp_reset (DEVICE *dptr) { ptp_unit.buf = 0; ptp_unit.u3 = 0x02; - sim_activate (&ptp_unit, ptp_unit.wait); // activate unit -// sim_cancel (&ptp_unit); // deactivate unit +// sim_activate (&ptp_unit, ptp_unit.wait); // activate unit + sim_cancel (&ptp_unit); // deactivate unit return SCPE_OK; } diff --git a/swtp6800/swtp6800/swtp_defs.h b/swtp6800/swtp6800/swtp_defs.h index 6b286405..2466a5c0 100644 --- a/swtp6800/swtp6800/swtp_defs.h +++ b/swtp6800/swtp6800/swtp_defs.h @@ -25,7 +25,7 @@ Copyright (c) 2005-2012, William Beech */ #include -#include "sim_defs.h" // simulator defs +#include "sim_defs.h" // simulator defs /* Memory */