Skip to content

Commit 2d770e9

Browse files
committed
SCP: Enable C99 standard 'bool'
Teach SIMH to make use of the C standard bool type when supported, implemented in the support/sim_bool.h header. - If the compiler claims that __STDC_VERSION__ is C99 and above, or if the Microsoft C compiler version is at least 1800, include stdbool.h, typedef t_bool to bool, set TRUE and FALSE to true and false, respectively. - If not a standard compliant compiler or older Microsoft compiler, typedef t_bool to int, TRUE = 1 and FALSE = 0 (i.e., the old SIMH settings.) CMake: Use target_compiler_feature() to baseline C99 dialect. Make a pass through the SIMH code base for t_bool variable declarations and associated references: - Ensure boolean expressions are boolean expressions, e.g., "(foo & mask) != 0" vs. "foo & mask" to remove any ambiguity. Overkill, perhaps, but explicitly and unambiguously Boolean. - Fix expressions, declarations where t_bool was assumed to be the same as int. - Fix inconsistent function prototypes. 3B2: 3b2_mau.h: Adjust *_SIGN() macros to produce Boolean expressions. AltairZ80: s100_dazzler.c: Change daz_0e, daz_0f and daz_frame's type from t_bool to uint8, remove assumption that t_bool is type-equivalent to int. m68k/m68k.h, m68k/m68kcpu.c: Rename TRUE to NMI_TRUE, FALSE to NMI_FALSE to resolve namespace collision with SIMH TRUE and FALSE. H316: h316_hi.c, h316_mi.c: Ensure assignment result is Boolean. hp2100_defs.h, FLIP_FLOP enum: Alias CLEAR and SET to FALSE and TRUE, respectively, to avoid any compiler ambiguity with respect to Boolean values. hp2100_sys.c: Update assignment to Boolean result. HP3000: hp3000_lp.c: Ensure (device_command ^ J2W10_INSTALLED) evaluates to a Boolean expression. Instantiates a separate boolean variable to preserve comment formatting. I1401: i1401_cpu.c: Initialize clear to FALSE (vice 0), ensure conv_old is assigned a Boolean value in cpu_set_conv() (t_bool is not int32.) i1401_iq.c: Assign use_h from a Boolean expression. i1401_sys.c: Assign use_h from a Boolean expression in dcw() and fprint_sym(). I7094: Fix ch6_req_wr() return type: should be t_bool, not t_stat. Ibm1130: ibm1130_cr.c: Remove extraneous extern declaraction for cgi. ibm1130_defs.h: Change cgi and cgiwritable's extern declaration type to t_bool to be consistent with actual definitions. ibm1130_disk.c: Assign raw_disk_debug from a Boolean expression. ibm1139_gui.c: Update update_gui() prototype to be consistent across the GUI and non-GUI compile paths. ibm1130_sca.c: Assign any_timer_running from a Boolean expression. ibm1130_stddev.c: Remove extraneous extern declaraction for cgi. t_bool for update_gui Interdata: id_idc.c: Fix idc_wds() return type (was t_stat, should be t_bool.) ND100: nd100_sys.c: Update sim_load()'s flag declaration. Should be int, not t_bool (flag is an unused parameter.) PDP10: pdp10_ksio.c: Return type from build_dib_tab should be t_stat, not t_bool. PDP11: pdp11_cr.c: Assign eof_pending to TRUE (vice 1.) pdp11_rq.c: Assign dontchangecapac from Boolean expression. SAGE: m68k_sys.c: Fix sim_load()'s flag parameter type, should be int, not t_bool. VAX: vax_sysdev.c: Initialize ka_hltenab, tmr_inst[] to TRUE, FALSE to be consistent with t_bool. vax_va.c, vax_vc.c, vax4xx_va.c, vax4xx_vc.c: Assign va_input_captured from Boolean expression. vax780_fload.c: Update rtfile_read() return type to t_bool (not t_stat.)
1 parent c20b391 commit 2d770e9

42 files changed

Lines changed: 111 additions & 69 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

3B2/3b2_mau.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,15 +186,15 @@
186186
#define MAU_RC_RZ 3 /* Round toward Zero */
187187
#endif
188188

189-
#define SFP_SIGN(V) (((V) >> 31) & 1)
189+
#define SFP_SIGN(V) ((((V) >> 31) & 1) != 0)
190190
#define SFP_EXP(V) (((V) >> 23) & 0xff)
191191
#define SFP_FRAC(V) ((V) & 0x7fffff)
192192

193-
#define DFP_SIGN(V) (((V) >> 63) & 1)
193+
#define DFP_SIGN(V) ((((V) >> 63) & 1) != 0)
194194
#define DFP_EXP(V) (((V) >> 52) & 0x7ff)
195195
#define DFP_FRAC(V) ((V) & 0xfffffffffffffull)
196196

197-
#define XFP_SIGN(V) (((V)->sign_exp >> 15) & 1)
197+
#define XFP_SIGN(V) ((((V)->sign_exp >> 15) & 1) != 0)
198198
#define XFP_EXP(V) ((V)->sign_exp & 0x7fff)
199199
#define XFP_FRAC(V) ((V)->frac)
200200

AltairZ80/m68k/example/m68kcpu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1047,7 +1047,7 @@ void m68k_set_irq(unsigned int int_level)
10471047
/* A transition from < 7 to 7 always interrupts (NMI) */
10481048
/* Note: Level 7 can also level trigger like a normal IRQ */
10491049
if(old_level != 0x0700 && CPU_INT_LEVEL == 0x0700)
1050-
m68ki_cpu.nmi_pending = TRUE;
1050+
m68ki_cpu.nmi_pending = NMI_TRUE;
10511051
}
10521052

10531053
void m68k_set_virq(unsigned int level, unsigned int active)

AltairZ80/m68k/m68k.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ extern "C" {
3838
#define ARRAY_LENGTH(x) (sizeof(x) / sizeof(x[0]))
3939
#endif
4040

41-
#ifndef FALSE
42-
#define FALSE 0
43-
#define TRUE 1
41+
#ifndef NMI_FALSE
42+
#define NMI_FALSE 0
43+
#define NMI_TRUE 1
4444
#endif
4545

4646
/* ======================================================================== */

AltairZ80/m68k/m68kcpu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1047,7 +1047,7 @@ void m68k_set_irq(unsigned int int_level)
10471047
/* A transition from < 7 to 7 always interrupts (NMI) */
10481048
/* Note: Level 7 can also level trigger like a normal IRQ */
10491049
if(old_level != 0x0700 && CPU_INT_LEVEL == 0x0700)
1050-
m68ki_cpu.nmi_pending = TRUE;
1050+
m68ki_cpu.nmi_pending = NMI_TRUE;
10511051
}
10521052

10531053
void m68k_set_virq(unsigned int level, unsigned int active)

AltairZ80/m68k/m68kcpu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2136,7 +2136,7 @@ static inline void m68ki_check_interrupts(void)
21362136
{
21372137
if(m68ki_cpu.nmi_pending)
21382138
{
2139-
m68ki_cpu.nmi_pending = FALSE;
2139+
m68ki_cpu.nmi_pending = NMI_FALSE;
21402140
m68ki_exception_interrupt(7);
21412141
}
21422142
else if(CPU_INT_LEVEL > FLAG_INT_MASK)

AltairZ80/m68k/softfloat/milieu.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,5 @@ these four paragraphs for those parts of this code that are retained.
3838
/*----------------------------------------------------------------------------
3939
| Symbolic Boolean literals.
4040
*----------------------------------------------------------------------------*/
41-
#define FALSE 0
42-
#define TRUE 1
41+
#define NMI_FALSE 0
42+
#define NMI_TRUE 1

AltairZ80/s100_dazzler.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@
6363
*/
6464
VID_DISPLAY *daz_vptr = NULL;
6565

66-
static t_bool daz_0e = 0x00;
67-
static t_bool daz_0f = 0x80;
66+
static uint8 daz_0e = 0x00;
67+
static uint8 daz_0f = 0x80;
6868
static uint32 daz_addr = 0x0000;
69-
static t_bool daz_frame = 0x3f;
69+
static uint8 daz_frame = 0x3f;
7070
static uint8 daz_res = 32;
7171
static uint16 daz_pages = 1;
7272
static uint16 daz_window_width = 640;

H316/h316_hi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ t_stat hi_attach (UNIT *uptr, CONST char *cptr)
784784
// ATTACH HIn llll:w.x.y.z:rrrr - connect via UDP to a remote simh host
785785
//
786786
t_stat ret; char *pfn; uint16 host = uptr->hline;
787-
t_bool fport = sim_switches & SWMASK('P');
787+
t_bool fport = ((sim_switches & SWMASK('P')) != 0);
788788

789789
// If we're already attached, then detach ...
790790
if ((uptr->flags & UNIT_ATT) != 0) detach_unit(uptr);

H316/h316_mi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ t_stat mi_attach (UNIT *uptr, CONST char *cptr)
694694
// ATTACH MIn llll:w.x.y.z:rrrr - connect via UDP to a remote simh host
695695
//
696696
t_stat ret; char *pfn; uint16 line = uptr->mline;
697-
t_bool fport = sim_switches & SWMASK('P');
697+
t_bool fport = ((sim_switches & SWMASK('P')) != 0);
698698

699699
// If we're already attached, then detach ...
700700
if ((uptr->flags & UNIT_ATT) != 0) detach_unit(uptr);

HP2100/hp2100_defs.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -740,8 +740,8 @@ typedef enum { /* poll synchronization modes */
740740
/* Flip-flops */
741741

742742
typedef enum { /* flip-flop values */
743-
CLEAR = 0, /* the flip-flop is clear */
744-
SET = 1 /* the flip-flop is set */
743+
CLEAR = FALSE, /* the flip-flop is clear */
744+
SET = TRUE /* the flip-flop is set */
745745
} FLIP_FLOP;
746746

747747

0 commit comments

Comments
 (0)