AltairZ80: Replaced assert() with ASSURE() for error checking at run time

This commit is contained in:
Peter Schorn 2018-08-11 09:48:55 +02:00
parent f659574e11
commit 1b7d77e03b
5 changed files with 15 additions and 20 deletions

View file

@ -28,7 +28,6 @@
*/ */
#include "m68k.h" #include "m68k.h"
#include "assert.h"
#include <ctype.h> #include <ctype.h>
#define SWITCHCPU_DEFAULT 0xfd #define SWITCHCPU_DEFAULT 0xfd

View file

@ -131,7 +131,6 @@
*/ */
#include "altairz80_defs.h" #include "altairz80_defs.h"
#include <assert.h>
/* Debug flags */ /* Debug flags */
#define IN_MSG (1 << 0) #define IN_MSG (1 << 0)
@ -406,9 +405,9 @@ static t_stat dsk_attach(UNIT *uptr, CONST char *cptr) {
if (r != SCPE_OK) /* error? */ if (r != SCPE_OK) /* error? */
return r; return r;
assert(uptr != NULL); ASSURE(uptr != NULL);
thisUnitIndex = find_unit_index(uptr); thisUnitIndex = find_unit_index(uptr);
assert((0 <= thisUnitIndex) && (thisUnitIndex < NUM_OF_DSK)); ASSURE((0 <= thisUnitIndex) && (thisUnitIndex < NUM_OF_DSK));
/* If the file size is close to the mini-disk image size, set the number of /* If the file size is close to the mini-disk image size, set the number of
tracks to 16, otherwise, 32 sectors per track. */ tracks to 16, otherwise, 32 sectors per track. */
@ -423,7 +422,7 @@ static t_stat dsk_attach(UNIT *uptr, CONST char *cptr) {
void install_ALTAIRbootROM(void) { void install_ALTAIRbootROM(void) {
const t_bool result = (install_bootrom(bootrom_dsk, BOOTROM_SIZE_DSK, ALTAIR_ROM_LOW, TRUE) == const t_bool result = (install_bootrom(bootrom_dsk, BOOTROM_SIZE_DSK, ALTAIR_ROM_LOW, TRUE) ==
SCPE_OK); SCPE_OK);
assert(result); ASSURE(result);
} }
/* The boot routine modifies the boot ROM in such a way that subsequently /* The boot routine modifies the boot ROM in such a way that subsequently
@ -434,7 +433,7 @@ static t_stat dsk_boot(int32 unitno, DEVICE *dptr) {
if (sectors_per_track[unitno] == MINI_DISK_SECT) { if (sectors_per_track[unitno] == MINI_DISK_SECT) {
const t_bool result = (install_bootrom(alt_bootrom_dsk, BOOTROM_SIZE_DSK, const t_bool result = (install_bootrom(alt_bootrom_dsk, BOOTROM_SIZE_DSK,
ALTAIR_ROM_LOW, TRUE) == SCPE_OK); ALTAIR_ROM_LOW, TRUE) == SCPE_OK);
assert(result); ASSURE(result);
} else { } else {
/* check whether we are really modifying an LD A,<> instruction */ /* check whether we are really modifying an LD A,<> instruction */
if ((bootrom_dsk[UNIT_NO_OFFSET_1 - 1] == LDA_INSTRUCTION) && if ((bootrom_dsk[UNIT_NO_OFFSET_1 - 1] == LDA_INSTRUCTION) &&

View file

@ -27,7 +27,6 @@
*/ */
#include "m68k.h" #include "m68k.h"
#include <assert.h>
#include "sim_imd.h" #include "sim_imd.h"
/* Debug flags */ /* Debug flags */
@ -433,10 +432,10 @@ static t_stat hdsk_attach(UNIT *uptr, CONST char *cptr) {
if (r != SCPE_OK) /* error? */ if (r != SCPE_OK) /* error? */
return r; return r;
assert(uptr != NULL); ASSURE(uptr != NULL);
thisUnitIndex = find_unit_index(uptr); thisUnitIndex = find_unit_index(uptr);
unitChar = '0' + thisUnitIndex; unitChar = '0' + thisUnitIndex;
assert((0 <= thisUnitIndex) && (thisUnitIndex < HDSK_NUMBER)); ASSURE((0 <= thisUnitIndex) && (thisUnitIndex < HDSK_NUMBER));
if (is_imd(uptr)) { if (is_imd(uptr)) {
if ((sim_fsize(uptr -> fileref) == 0) && if ((sim_fsize(uptr -> fileref) == 0) &&
@ -476,7 +475,7 @@ static t_stat hdsk_attach(UNIT *uptr, CONST char *cptr) {
if (uptr -> capac == 0) if (uptr -> capac == 0)
uptr -> capac = HDSK_CAPACITY; uptr -> capac = HDSK_CAPACITY;
} /* post condition: uptr -> capac > 0 */ } /* post condition: uptr -> capac > 0 */
assert(uptr -> capac); ASSURE(uptr -> capac);
/* Step 2: Determine format based on disk capacity */ /* Step 2: Determine format based on disk capacity */
assignFormat(uptr); assignFormat(uptr);
@ -502,12 +501,12 @@ static t_stat hdsk_attach(UNIT *uptr, CONST char *cptr) {
uptr -> HDSK_SECTORS_PER_TRACK = dpb[uptr -> HDSK_FORMAT_TYPE].spt >> dpb[uptr -> HDSK_FORMAT_TYPE].psh; uptr -> HDSK_SECTORS_PER_TRACK = dpb[uptr -> HDSK_FORMAT_TYPE].spt >> dpb[uptr -> HDSK_FORMAT_TYPE].psh;
uptr -> HDSK_SECTOR_SIZE = (128 << dpb[uptr -> HDSK_FORMAT_TYPE].psh); uptr -> HDSK_SECTOR_SIZE = (128 << dpb[uptr -> HDSK_FORMAT_TYPE].psh);
} }
assert((uptr -> HDSK_SECTORS_PER_TRACK) && (uptr -> HDSK_SECTOR_SIZE) && (uptr -> HDSK_FORMAT_TYPE >= 0)); ASSURE((uptr -> HDSK_SECTORS_PER_TRACK) && (uptr -> HDSK_SECTOR_SIZE) && (uptr -> HDSK_FORMAT_TYPE >= 0));
/* Step 4: Number of tracks is smallest number to accomodate capacity */ /* Step 4: Number of tracks is smallest number to accomodate capacity */
uptr -> HDSK_NUMBER_OF_TRACKS = (uptr -> capac + uptr -> HDSK_SECTORS_PER_TRACK * uptr -> HDSK_NUMBER_OF_TRACKS = (uptr -> capac + uptr -> HDSK_SECTORS_PER_TRACK *
uptr -> HDSK_SECTOR_SIZE - 1) / (uptr -> HDSK_SECTORS_PER_TRACK * uptr -> HDSK_SECTOR_SIZE); uptr -> HDSK_SECTOR_SIZE - 1) / (uptr -> HDSK_SECTORS_PER_TRACK * uptr -> HDSK_SECTOR_SIZE);
assert( ( (t_addr) ((uptr -> HDSK_NUMBER_OF_TRACKS - 1) * uptr -> HDSK_SECTORS_PER_TRACK * ASSURE( ( (t_addr) ((uptr -> HDSK_NUMBER_OF_TRACKS - 1) * uptr -> HDSK_SECTORS_PER_TRACK *
uptr -> HDSK_SECTOR_SIZE) < uptr -> capac) && uptr -> HDSK_SECTOR_SIZE) < uptr -> capac) &&
(uptr -> capac <= (t_addr) (uptr -> HDSK_NUMBER_OF_TRACKS * (uptr -> capac <= (t_addr) (uptr -> HDSK_NUMBER_OF_TRACKS *
uptr -> HDSK_SECTORS_PER_TRACK * uptr -> HDSK_SECTOR_SIZE) ) ); uptr -> HDSK_SECTORS_PER_TRACK * uptr -> HDSK_SECTOR_SIZE) ) );
@ -524,7 +523,7 @@ static t_stat hdsk_detach(UNIT *uptr) {
unitIndex = find_unit_index(uptr); unitIndex = find_unit_index(uptr);
if (unitIndex == -1) if (unitIndex == -1)
return SCPE_IERR; return SCPE_IERR;
assert((0 <= unitIndex) && (unitIndex < HDSK_NUMBER)); ASSURE((0 <= unitIndex) && (unitIndex < HDSK_NUMBER));
result = diskClose(&hdsk_imd[unitIndex]); result = diskClose(&hdsk_imd[unitIndex]);
if (result != SCPE_OK) { if (result != SCPE_OK) {
return result; return result;
@ -672,7 +671,7 @@ static t_stat hdsk_boot(int32 unitno, DEVICE *dptr) {
} }
installSuccessful = (install_bootrom(bootrom_hdsk, BOOTROM_SIZE_HDSK, HDSK_BOOT_ADDRESS, installSuccessful = (install_bootrom(bootrom_hdsk, BOOTROM_SIZE_HDSK, HDSK_BOOT_ADDRESS,
FALSE) == SCPE_OK); FALSE) == SCPE_OK);
assert(installSuccessful); ASSURE(installSuccessful);
*((int32 *) sim_PC -> loc) = HDSK_BOOT_ADDRESS; *((int32 *) sim_PC -> loc) = HDSK_BOOT_ADDRESS;
return SCPE_OK; return SCPE_OK;
} }
@ -785,7 +784,7 @@ static int32 doSeek(void) {
int32 hostSector; int32 hostSector;
int32 sectorSize; int32 sectorSize;
UNIT *uptr = &hdsk_dev.units[selectedDisk]; UNIT *uptr = &hdsk_dev.units[selectedDisk];
assert(uptr != NULL); ASSURE(uptr != NULL);
hostSector = ((dpb[uptr -> HDSK_FORMAT_TYPE].skew == NULL) ? hostSector = ((dpb[uptr -> HDSK_FORMAT_TYPE].skew == NULL) ?
selectedSector : dpb[uptr -> HDSK_FORMAT_TYPE].skew[selectedSector]); selectedSector : dpb[uptr -> HDSK_FORMAT_TYPE].skew[selectedSector]);
sectorSize = ((dpb[uptr -> HDSK_FORMAT_TYPE].physicalSectorSize == 0) ? sectorSize = ((dpb[uptr -> HDSK_FORMAT_TYPE].physicalSectorSize == 0) ?

View file

@ -45,7 +45,6 @@
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
*/ */
#include "altairz80_defs.h" #include "altairz80_defs.h"
#include <assert.h>
/** Typedefs & Defines **************************************/ /** Typedefs & Defines **************************************/
#define HDSK_SECTOR_SIZE 256 /* size of sector */ #define HDSK_SECTOR_SIZE 256 /* size of sector */
@ -248,7 +247,7 @@ static int32 bootrom_mhdsk[BOOTROM_SIZE_MHDSK] = {
static t_stat mhdsk_boot(int32 unitno, DEVICE *dptr) { static t_stat mhdsk_boot(int32 unitno, DEVICE *dptr) {
const t_bool installSuccessful = (install_bootrom(bootrom_mhdsk, BOOTROM_SIZE_MHDSK, const t_bool installSuccessful = (install_bootrom(bootrom_mhdsk, BOOTROM_SIZE_MHDSK,
MHDSK_BOOT_ADDRESS, FALSE) == SCPE_OK); MHDSK_BOOT_ADDRESS, FALSE) == SCPE_OK);
assert(installSuccessful); ASSURE(installSuccessful);
*((int32 *) sim_PC -> loc) = MHDSK_BOOT_ADDRESS; *((int32 *) sim_PC -> loc) = MHDSK_BOOT_ADDRESS;
return SCPE_OK; return SCPE_OK;
} }

View file

@ -55,7 +55,6 @@
#include "sim_sock.h" #include "sim_sock.h"
#include "sim_tmxr.h" #include "sim_tmxr.h"
#include <time.h> #include <time.h>
#include <assert.h>
uint8 *URLContents(const char *URL, uint32 *length); uint8 *URLContents(const char *URL, uint32 *length);
#ifndef URL_READER_SUPPORT #ifndef URL_READER_SUPPORT
@ -750,7 +749,7 @@ static void voidSleep(void) {
static int32 sio0sCore(const int32 port, const int32 io, const int32 data) { static int32 sio0sCore(const int32 port, const int32 io, const int32 data) {
int32 ch, result; int32 ch, result;
const SIO_PORT_INFO spi = lookupPortInfo(port, &ch); const SIO_PORT_INFO spi = lookupPortInfo(port, &ch);
assert(spi.port == port); ASSURE(spi.port == port);
pollConnection(); pollConnection();
if (io == 0) { /* IN */ if (io == 0) { /* IN */
if (sio_unit.u4) { /* attached to a file? */ if (sio_unit.u4) { /* attached to a file? */
@ -820,7 +819,7 @@ int32 sio0s(const int32 port, const int32 io, const int32 data) {
static int32 sio0dCore(const int32 port, const int32 io, const int32 data) { static int32 sio0dCore(const int32 port, const int32 io, const int32 data) {
int32 ch; int32 ch;
const SIO_PORT_INFO spi = lookupPortInfo(port, &ch); const SIO_PORT_INFO spi = lookupPortInfo(port, &ch);
assert(spi.port == port); ASSURE(spi.port == port);
pollConnection(); pollConnection();
if (io == 0) { /* IN */ if (io == 0) { /* IN */
if ((sio_unit.flags & UNIT_ATT) && (!sio_unit.u4)) if ((sio_unit.flags & UNIT_ATT) && (!sio_unit.u4))