Skip to content

Commit

Permalink
ALL: Massive 'const' cleanup
Browse files Browse the repository at this point in the history
These changes facilitate more robust parameter type checking and helps
to identify unexpected coding errors.

Most simulators can now also be compiled with a C++ compiler without
warnings.

Additionally, these changes have also been configured to facilitate easier
backporting of simulator and device simulation modules to run under the
simh v3.9+ SCP framework.
  • Loading branch information
markpizz committed May 15, 2016
1 parent 60a8a2d commit 5531ccb
Show file tree
Hide file tree
Showing 444 changed files with 4,123 additions and 3,802 deletions.
4 changes: 2 additions & 2 deletions ALTAIR/altair_cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ int32 PCX; /* External view of PC *
t_stat cpu_ex (t_value *vptr, t_addr addr, UNIT *uptr, int32 sw);
t_stat cpu_dep (t_value val, t_addr addr, UNIT *uptr, int32 sw);
t_stat cpu_reset (DEVICE *dptr);
t_stat cpu_set_size (UNIT *uptr, int32 val, char *cptr, void *desc);
t_stat cpu_set_size (UNIT *uptr, int32 val, CONST char *cptr, void *desc);
void setarith(int32 reg);
void setlogical(int32 reg);
void setinc(int32 reg);
Expand Down Expand Up @@ -1163,7 +1163,7 @@ t_stat cpu_dep (t_value val, t_addr addr, UNIT *uptr, int32 sw)
return SCPE_OK;
}

t_stat cpu_set_size (UNIT *uptr, int32 val, char *cptr, void *desc)
t_stat cpu_set_size (UNIT *uptr, int32 val, CONST char *cptr, void *desc)
{
int32 mc = 0;
uint32 i;
Expand Down
4 changes: 2 additions & 2 deletions ALTAIR/altair_sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ int32 oplen[256] = {
load starts at the current value of the PC.
*/

t_stat sim_load (FILE *fileref, char *cptr, char *fnam, int flag)
t_stat sim_load (FILE *fileref, CONST char *cptr, CONST char *fnam, int flag)
{
int32 i, addr = 0, cnt = 0;

Expand Down Expand Up @@ -234,7 +234,7 @@ return -(oplen[inst] - 1);
status = error status
*/

t_stat parse_sym (char *cptr, t_addr addr, UNIT *uptr, t_value *val, int32 sw)
t_stat parse_sym (CONST char *cptr, t_addr addr, UNIT *uptr, t_value *val, int32 sw)
{
int32 cflag, i = 0, j, r;
char gbuf[CBUFSIZE];
Expand Down
83 changes: 41 additions & 42 deletions AltairZ80/altairz80_cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,24 +154,24 @@ extern t_stat sim_instr_8086(void);
extern void cpu8086reset(void);

/* function prototypes */
static t_stat cpu_set_switcher (UNIT *uptr, int32 value, char *cptr, void *desc);
static t_stat cpu_reset_switcher(UNIT *uptr, int32 value, char *cptr, void *desc);
static t_stat cpu_show_switcher (FILE *st, UNIT *uptr, int32 val, void *desc);
static int32 switchcpu_io (const int32 port, const int32 io, const int32 data);

static t_stat cpu_set_altairrom (UNIT *uptr, int32 value, char *cptr, void *desc);
static t_stat cpu_set_noaltairrom (UNIT *uptr, int32 value, char *cptr, void *desc);
static t_stat cpu_set_nommu (UNIT *uptr, int32 value, char *cptr, void *desc);
static t_stat cpu_set_banked (UNIT *uptr, int32 value, char *cptr, void *desc);
static t_stat cpu_set_nonbanked (UNIT *uptr, int32 value, char *cptr, void *desc);
static t_stat cpu_set_ramtype (UNIT *uptr, int32 value, char *cptr, void *desc);
static t_stat cpu_set_chiptype (UNIT *uptr, int32 value, char *cptr, void *desc);
static t_stat cpu_set_size (UNIT *uptr, int32 value, char *cptr, void *desc);
static t_stat cpu_set_memory (UNIT *uptr, int32 value, char *cptr, void *desc);
static t_stat cpu_clear_command (UNIT *uptr, int32 value, char *cptr, void *desc);
static t_stat cpu_set_switcher (UNIT *uptr, int32 value, CONST char *cptr, void *desc);
static t_stat cpu_reset_switcher(UNIT *uptr, int32 value, CONST char *cptr, void *desc);
static t_stat cpu_show_switcher (FILE *st, UNIT *uptr, int32 val, CONST void *desc);
static int32 switchcpu_io (const int32 port, const int32 io, CONST int32 data);

static t_stat cpu_set_altairrom (UNIT *uptr, int32 value, CONST char *cptr, void *desc);
static t_stat cpu_set_noaltairrom (UNIT *uptr, int32 value, CONST char *cptr, void *desc);
static t_stat cpu_set_nommu (UNIT *uptr, int32 value, CONST char *cptr, void *desc);
static t_stat cpu_set_banked (UNIT *uptr, int32 value, CONST char *cptr, void *desc);
static t_stat cpu_set_nonbanked (UNIT *uptr, int32 value, CONST char *cptr, void *desc);
static t_stat cpu_set_ramtype (UNIT *uptr, int32 value, CONST char *cptr, void *desc);
static t_stat cpu_set_chiptype (UNIT *uptr, int32 value, CONST char *cptr, void *desc);
static t_stat cpu_set_size (UNIT *uptr, int32 value, CONST char *cptr, void *desc);
static t_stat cpu_set_memory (UNIT *uptr, int32 value, CONST char *cptr, void *desc);
static t_stat cpu_clear_command (UNIT *uptr, int32 value, CONST char *cptr, void *desc);
static void cpu_clear(void);
static t_stat cpu_show (FILE *st, UNIT *uptr, int32 val, void *desc);
static t_stat chip_show (FILE *st, UNIT *uptr, int32 val, void *desc);
static t_stat cpu_show (FILE *st, UNIT *uptr, int32 val, CONST void *desc);
static t_stat chip_show (FILE *st, UNIT *uptr, int32 val, CONST void *desc);
static t_stat cpu_ex(t_value *vptr, t_addr addr, UNIT *uptr, int32 sw);
static t_stat cpu_dep(t_value val, t_addr addr, UNIT *uptr, int32 sw);
static t_stat cpu_reset(DEVICE *dptr);
Expand Down Expand Up @@ -2075,7 +2075,6 @@ static t_stat sim_instr_mmu (void) {
extern int32 timerInterruptHandler;
extern int32 keyboardInterrupt;
extern uint32 keyboardInterruptHandler;
extern const t_bool rtc_avail;
int32 reason = SCPE_OK;
register uint32 specialProcessing;
register uint32 AF;
Expand Down Expand Up @@ -6738,9 +6737,9 @@ const static CPUFLAG *cpuflags[NUM_CHIP_TYPE] = { cpuflags8080, cpuflagsZ80,
cpuflags8086, cpuflagsM68K, };

/* needs to be set for each ramtype <= MAX_RAM_TYPE */
static char *ramTypeToString[] = { "AZ80", "HRAM", "VRAM", "CRAM" };
static const char *ramTypeToString[] = { "AZ80", "HRAM", "VRAM", "CRAM" };

static t_stat chip_show(FILE *st, UNIT *uptr, int32 val, void *desc) {
static t_stat chip_show(FILE *st, UNIT *uptr, int32 val, CONST void *desc) {
fprintf(st, cpu_unit.flags & UNIT_CPU_OPSTOP ? "ITRAP, " : "NOITRAP, ");
if (chiptype < NUM_CHIP_TYPE)
fprintf(st, "%s", cpu_mod[chiptype].mstring);
Expand All @@ -6750,7 +6749,7 @@ static t_stat chip_show(FILE *st, UNIT *uptr, int32 val, void *desc) {
return SCPE_OK;
}

static t_stat cpu_show(FILE *st, UNIT *uptr, int32 val, void *desc) {
static t_stat cpu_show(FILE *st, UNIT *uptr, int32 val, CONST void *desc) {
uint32 i, maxBanks, first = TRUE;
MDEV m;
maxBanks = ((cpu_unit.flags & UNIT_CPU_BANKED) ||
Expand Down Expand Up @@ -6815,23 +6814,23 @@ static void cpu_clear(void) {
clockHasChanged = FALSE;
}

static t_stat cpu_clear_command(UNIT *uptr, int32 value, char *cptr, void *desc) {
static t_stat cpu_clear_command(UNIT *uptr, int32 value, CONST char *cptr, void *desc) {
cpu_clear();
return SCPE_OK;
}

static t_stat cpu_set_altairrom(UNIT *uptr, int32 value, char *cptr, void *desc) {
static t_stat cpu_set_altairrom(UNIT *uptr, int32 value, CONST char *cptr, void *desc) {
install_ALTAIRbootROM();
return SCPE_OK;
}

static t_stat cpu_set_noaltairrom(UNIT *uptr, int32 value, char *cptr, void *desc) {
static t_stat cpu_set_noaltairrom(UNIT *uptr, int32 value, CONST char *cptr, void *desc) {
mmu_table[ALTAIR_ROM_LOW >> LOG2PAGESIZE] = MEMORYSIZE < MAXBANKSIZE ?
EMPTY_PAGE : RAM_PAGE;
return SCPE_OK;
}

static t_stat cpu_set_nommu(UNIT *uptr, int32 value, char *cptr, void *desc) {
static t_stat cpu_set_nommu(UNIT *uptr, int32 value, CONST char *cptr, void *desc) {
if (chiptype == CHIP_TYPE_8086) {
sim_printf("Cannot switch off MMU for 8086 CPU.\n");
return SCPE_ARG;
Expand All @@ -6849,7 +6848,7 @@ static t_stat cpu_set_nommu(UNIT *uptr, int32 value, char *cptr, void *desc) {
return SCPE_OK;
}

static t_stat cpu_set_banked(UNIT *uptr, int32 value, char *cptr, void *desc) {
static t_stat cpu_set_banked(UNIT *uptr, int32 value, CONST char *cptr, void *desc) {
if ((chiptype == CHIP_TYPE_8080) || (chiptype == CHIP_TYPE_Z80)) {
if (MEMORYSIZE <= MAXBANKSIZE)
previousCapacity = MEMORYSIZE;
Expand All @@ -6864,7 +6863,7 @@ static t_stat cpu_set_banked(UNIT *uptr, int32 value, char *cptr, void *desc) {
return SCPE_OK;
}

static t_stat cpu_set_nonbanked(UNIT *uptr, int32 value, char *cptr, void *desc) {
static t_stat cpu_set_nonbanked(UNIT *uptr, int32 value, CONST char *cptr, void *desc) {
if ((chiptype == CHIP_TYPE_8080) || (chiptype == CHIP_TYPE_Z80)) {
MEMORYSIZE = previousCapacity;
cpu_dev.awidth = MAXBANKSIZELOG2;
Expand Down Expand Up @@ -6965,10 +6964,10 @@ static void cpu_set_chiptype_short(const int32 value) {
return; /* nothing to do */
if (((chiptype == CHIP_TYPE_8080) && (value == CHIP_TYPE_Z80)) ||
((chiptype == CHIP_TYPE_Z80) && (value == CHIP_TYPE_8080))) {
chiptype = value;
chiptype = (ChipType)value;
return;
}
chiptype = value;
chiptype = (ChipType)value;
switch (chiptype) {
case CHIP_TYPE_8080:
case CHIP_TYPE_Z80:
Expand Down Expand Up @@ -6998,13 +6997,13 @@ static void cpu_set_chiptype_short(const int32 value) {
}
}

static t_stat cpu_set_chiptype(UNIT *uptr, int32 value, char *cptr, void *desc) {
static t_stat cpu_set_chiptype(UNIT *uptr, int32 value, CONST char *cptr, void *desc) {
cpu_set_chiptype_short(value);
cpu_clear();
return SCPE_OK;
}

static int32 switchcpu_io(const int32 port, const int32 io, const int32 data) {
static int32 switchcpu_io(const int32 port, const int32 io, CONST int32 data) {
int32 new_chiptype = 0;
if (io == 0) { /* Read, switch CPU */
switch(chiptype) {
Expand Down Expand Up @@ -7036,15 +7035,15 @@ static int32 switchcpu_io(const int32 port, const int32 io, const int32 data) {
return 0;
}

static t_stat cpu_show_switcher(FILE *st, UNIT *uptr, int32 val, void *desc) {
static t_stat cpu_show_switcher(FILE *st, UNIT *uptr, int32 val, CONST void *desc) {
if ((cpu_unit.flags & UNIT_CPU_SWITCHER) && (switcherPort >= 0))
fprintf(st, "SWITCHER=0x%02x", switcherPort);
else
fprintf(st, "NOSWITCHER");
return SCPE_OK;
}

static t_stat cpu_set_switcher(UNIT *uptr, int32 value, char *cptr, void *desc) {
static t_stat cpu_set_switcher(UNIT *uptr, int32 value, CONST char *cptr, void *desc) {
struct idev safe;
switcherPort &= 0xff;
safe = dev_table[switcherPort];
Expand All @@ -7056,15 +7055,15 @@ static t_stat cpu_set_switcher(UNIT *uptr, int32 value, char *cptr, void *desc)
return SCPE_OK;
}

static t_stat cpu_reset_switcher(UNIT *uptr, int32 value, char *cptr, void *desc) {
static t_stat cpu_reset_switcher(UNIT *uptr, int32 value, CONST char *cptr, void *desc) {
if (sim_map_resource(switcherPort, 1, RESOURCE_TYPE_IO, oldSwitcherDevice.routine, FALSE)) {
sim_printf("%s: error mapping I/O resource at 0x%04x\n", __FUNCTION__, switcherPort);
return SCPE_ARG;
}
return SCPE_OK;
}

static t_stat cpu_set_ramtype(UNIT *uptr, int32 value, char *cptr, void *desc) {
static t_stat cpu_set_ramtype(UNIT *uptr, int32 value, CONST char *cptr, void *desc) {

if (value == ramtype) {
if (cpu_unit.flags & UNIT_CPU_VERBOSE)
Expand Down Expand Up @@ -7149,11 +7148,11 @@ static t_stat set_size(uint32 size) {
return SCPE_OK;
}

static t_stat cpu_set_size(UNIT *uptr, int32 value, char *cptr, void *desc) {
static t_stat cpu_set_size(UNIT *uptr, int32 value, CONST char *cptr, void *desc) {
return set_size(value);
}

static t_stat cpu_set_memory(UNIT *uptr, int32 value, char *cptr, void *desc) {
static t_stat cpu_set_memory(UNIT *uptr, int32 value, CONST char *cptr, void *desc) {
uint32 size, result, i;
if (cptr == NULL)
return SCPE_ARG;
Expand All @@ -7175,7 +7174,7 @@ void altairz80_init(void) {
/* altairz80_print_tables(); */
}

void (*sim_vm_init) (void) = &altairz80_init;
WEAK void (*sim_vm_init) (void) = &altairz80_init;

/* This is the binary loader. The input file is considered to be a string of
literal bytes with no special format. The load starts at the current value
Expand All @@ -7186,12 +7185,12 @@ void (*sim_vm_init) (void) = &altairz80_init;

#define PLURAL(x) (x), (x) == 1 ? "" : "s"

static t_stat sim_load_m68k(FILE *fileref, char *cptr, char *fnam, int flag) {
static t_stat sim_load_m68k(FILE *fileref, CONST char *cptr, CONST char *fnam, int flag) {
char gbuf[CBUFSIZE];
int32 i;
t_addr j, lo, hi;
uint32 addr, org, cnt = 0;
const char* result;
CONST char* result;
if (flag ) {
result = get_range(NULL, cptr, &lo, &hi, 16, M68K_MAX_RAM, 0);
if (result == NULL)
Expand Down Expand Up @@ -7221,11 +7220,11 @@ static t_stat sim_load_m68k(FILE *fileref, char *cptr, char *fnam, int flag) {
return SCPE_OK;
}

t_stat sim_load(FILE *fileref, char *cptr, char *fnam, int flag) {
t_stat sim_load(FILE *fileref, CONST char *cptr, CONST char *fnam, int flag) {
int32 i;
uint32 addr, cnt = 0, org, pagesModified = 0, makeROM = FALSE;
t_addr j, lo, hi;
const char *result;
CONST char *result;
MDEV m;
char gbuf[CBUFSIZE];
if (chiptype == CHIP_TYPE_M68K)
Expand Down
1 change: 0 additions & 1 deletion AltairZ80/altairz80_cpu_nommu.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ extern int32 DE1_S; /* alternate DE register */
extern int32 HL1_S; /* alternate HL register */
extern int32 IFF_S; /* Interrupt Flip Flop */
extern int32 IR_S; /* Interrupt (upper) / Refresh (lower) register */
extern int32 chiptype;

#if !UNIX_PLATFORM
extern void pollForCPUStop(void);
Expand Down
2 changes: 2 additions & 0 deletions AltairZ80/altairz80_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,6 @@ typedef struct {
uint32 io_size; /* I/O Address Space requirement */
} PNP_INFO;

extern ChipType chiptype;

#endif
7 changes: 3 additions & 4 deletions AltairZ80/altairz80_dsk.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,7 @@ int32 dsk11(const int32 port, const int32 io, const int32 data);
int32 dsk12(const int32 port, const int32 io, const int32 data);
static t_stat dsk_boot(int32 unitno, DEVICE *dptr);
static t_stat dsk_reset(DEVICE *dptr);
static t_stat dsk_attach(UNIT *uptr, char *cptr);
static const char* dsk_description(DEVICE *dptr);
static t_stat dsk_attach(UNIT *uptr, CONST char *cptr);

extern UNIT cpu_unit;
extern uint32 PCX;
Expand Down Expand Up @@ -369,7 +368,7 @@ DEVICE dsk_dev = {
dsk_dt, NULL, NULL, NULL, NULL, NULL, &dsk_description
};

static char* selectInOut(const int32 io) {
static const char* selectInOut(const int32 io) {
return io == 0 ? "IN" : "OUT";
}

Expand Down Expand Up @@ -399,7 +398,7 @@ static t_stat dsk_reset(DEVICE *dptr) {
}
/* dsk_attach - determine type of drive attached based on disk image size */

static t_stat dsk_attach(UNIT *uptr, char *cptr) {
static t_stat dsk_attach(UNIT *uptr, CONST char *cptr) {
int32 thisUnitIndex;
int32 imageSize;
const t_stat r = attach_unit(uptr, cptr); /* attach unit */
Expand Down
25 changes: 12 additions & 13 deletions AltairZ80/altairz80_hdsk.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@
#define VERBOSE_MSG (1 << 2)

/* The following routines are based on work from Howard M. Harte */
static t_stat set_geom(UNIT *uptr, int32 val, char *cptr, void *desc);
static t_stat show_geom(FILE *st, UNIT *uptr, int32 val, void *desc);
static t_stat set_format(UNIT *uptr, int32 val, char *cptr, void *desc);
static t_stat show_format(FILE *st, UNIT *uptr, int32 val, void *desc);
static t_stat set_geom(UNIT *uptr, int32 val, CONST char *cptr, void *desc);
static t_stat show_geom(FILE *st, UNIT *uptr, int32 val, CONST void *desc);
static t_stat set_format(UNIT *uptr, int32 val, CONST char *cptr, void *desc);
static t_stat show_format(FILE *st, UNIT *uptr, int32 val, CONST void *desc);

static t_stat hdsk_reset(DEVICE *dptr);
static t_stat hdsk_attach(UNIT *uptr, char *cptr);
static t_stat hdsk_attach(UNIT *uptr, CONST char *cptr);
static t_stat hdsk_detach(UNIT *uptr);
static uint32 is_imd(const UNIT *uptr);
static void assignFormat(UNIT *uptr);
Expand Down Expand Up @@ -71,15 +71,14 @@ static void verifyDiskInfo(const DISK_INFO *info, const char unitChar);

extern uint32 PCX;
extern UNIT cpu_unit;
extern ChipType chiptype;

extern void install_ALTAIRbootROM(void);
extern void PutBYTEWrapper(const uint32 Addr, const uint32 Value);
extern uint8 GetBYTEWrapper(const uint32 Addr);
extern t_stat install_bootrom(const int32 bootrom[], const int32 size, const int32 addr, const int32 makeROM);
extern int32 bootrom_dsk[];
extern t_stat set_iobase(UNIT *uptr, int32 val, char *cptr, void *desc);
extern t_stat show_iobase(FILE *st, UNIT *uptr, int32 val, void *desc);
extern t_stat set_iobase(UNIT *uptr, int32 val, CONST char *cptr, void *desc);
extern t_stat show_iobase(FILE *st, UNIT *uptr, int32 val, CONST void *desc);
extern uint32 sim_map_resource(uint32 baseaddr, uint32 size, uint32 resource_type,
int32 (*routine)(const int32, const int32, const int32), uint8 unmap);
extern int32 find_unit_index(UNIT *uptr);
Expand Down Expand Up @@ -430,7 +429,7 @@ static void verifyDiskInfo(const DISK_INFO *info, const char unitChar) {
}

/* Attach routine */
static t_stat hdsk_attach(UNIT *uptr, char *cptr) {
static t_stat hdsk_attach(UNIT *uptr, CONST char *cptr) {
int32 thisUnitIndex;
char unitChar;
const t_stat r = attach_unit(uptr, cptr); /* attach unit */
Expand Down Expand Up @@ -541,7 +540,7 @@ static t_stat hdsk_detach(UNIT *uptr) {
}

/* Set disk geometry routine */
static t_stat set_geom(UNIT *uptr, int32 val, char *cptr, void *desc) {
static t_stat set_geom(UNIT *uptr, int32 val, CONST char *cptr, void *desc) {
uint32 numberOfTracks, numberOfSectors, sectorSize;
int result, n;

Expand All @@ -567,7 +566,7 @@ static t_stat set_geom(UNIT *uptr, int32 val, char *cptr, void *desc) {
}

/* Show disk geometry routine */
static t_stat show_geom(FILE *st, UNIT *uptr, int32 val, void *desc) {
static t_stat show_geom(FILE *st, UNIT *uptr, int32 val, CONST void *desc) {
if (uptr == NULL)
return SCPE_IERR;
fprintf(st, "T:%d/N:%d/S:%d", uptr -> HDSK_NUMBER_OF_TRACKS,
Expand All @@ -578,7 +577,7 @@ static t_stat show_geom(FILE *st, UNIT *uptr, int32 val, void *desc) {
#define QUOTE1(text) #text
#define QUOTE2(text) QUOTE1(text)
/* Set disk format routine */
static t_stat set_format(UNIT *uptr, int32 val, char *cptr, void *desc) {
static t_stat set_format(UNIT *uptr, int32 val, CONST char *cptr, void *desc) {
char fmtname[DPB_NAME_LENGTH + 1];
int32 i;

Expand Down Expand Up @@ -611,7 +610,7 @@ static t_stat set_format(UNIT *uptr, int32 val, char *cptr, void *desc) {
}

/* Show disk format routine */
static t_stat show_format(FILE *st, UNIT *uptr, int32 val, void *desc) {
static t_stat show_format(FILE *st, UNIT *uptr, int32 val, CONST void *desc) {
if (uptr == NULL)
return SCPE_IERR;
fprintf(st, "%s", dpb[uptr -> HDSK_FORMAT_TYPE].name);
Expand Down
Loading

0 comments on commit 5531ccb

Please sign in to comment.