Skip to content

Commit 77e4960

Browse files
committed
Compile with ANSI options and fix compiler warnings
Don't use C++ comments Fix unsigned/signed integer comparisons Enable all and extra warnings void out all unused arguments remove unnecessary arguments from functions where they won't be needed other small fixes
1 parent cff63fd commit 77e4960

File tree

7 files changed

+55
-50
lines changed

7 files changed

+55
-50
lines changed

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
# which will noticably slow down emulation
88

99
CC = gcc
10-
CFLAGS = -g -pipe -Wall -DPOSIX_TTY -DLITTLE_ENDIAN -DMEM_BREAK
10+
CFLAGS = -g -pipe -Wall -Wextra -pedantic -ansi \
11+
-D_POSIX_C_SOURCE=200809L -DPOSIX_TTY \
12+
-DLITTLE_ENDIAN -DMEM_BREAK
1113
LDFLAGS =
1214

1315
FILES = README.md Makefile A-Hdrive B-Hdrive cpmws.png \

bdos.c

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ static void storefp(z80info *z80, FILE *fp, unsigned where) {
171171
stfps[ind].name[11] = '\0';
172172
}
173173

174-
// Lookup an FCB to find the host file.
174+
/* Lookup an FCB to find the host file. */
175175

176176
static FILE *lookfp(z80info *z80, unsigned where) {
177177
int i;
@@ -189,7 +189,7 @@ static FILE *lookfp(z80info *z80, unsigned where) {
189189
return NULL;
190190
}
191191

192-
// Report an error finding an FCB.
192+
/* Report an error finding an FCB. */
193193

194194
static void fcberr(z80info *z80, unsigned where) {
195195
int i;
@@ -204,7 +204,7 @@ static void fcberr(z80info *z80, unsigned where) {
204204
exit(1);
205205
}
206206

207-
// Get the host file for an FCB when it should be open.
207+
/* Get the host file for an FCB when it should be open. */
208208

209209
static FILE *getfp(z80info *z80, unsigned where) {
210210
FILE *fp;
@@ -330,20 +330,20 @@ char *bdos_decode(int n)
330330
int bdos_fcb(int n)
331331
{
332332
switch (n) {
333-
case 15: return 1; // "open file";
334-
case 16: return 1; // "close file";
335-
case 17: return 1; // "search for first";
336-
case 18: return 1; // "search for next";
337-
case 19: return 1; // "delete file (no wildcards yet)";
338-
case 20: return 1; // "read sequential";
339-
case 21: return 1; // "write sequential";
340-
case 22: return 1; // "make file";
341-
case 23: return 1; // "rename file";
342-
case 30: return 1; // set attribute
343-
case 33: return 1; // "read random record";
344-
case 34: return 1; // "write random record";
345-
case 35: return 1; // "compute file size";
346-
case 36: return 1; // "set random record";
333+
case 15: return 1; /* "open file"; */
334+
case 16: return 1; /* "close file"; */
335+
case 17: return 1; /* "search for first"; */
336+
case 18: return 1; /* "search for next"; */
337+
case 19: return 1; /* "delete file (no wildcards yet)"; */
338+
case 20: return 1; /* "read sequential"; */
339+
case 21: return 1; /* "write sequential"; */
340+
case 22: return 1; /* "make file"; */
341+
case 23: return 1; /* "rename file"; */
342+
case 30: return 1; /* set attribute */
343+
case 33: return 1; /* "read random record"; */
344+
case 34: return 1; /* "write random record"; */
345+
case 35: return 1; /* "compute file size"; */
346+
case 36: return 1; /* "set random record"; */
347347
default: return 0;
348348
}
349349
}
@@ -467,7 +467,7 @@ void check_BDOS_hook(z80info *z80) {
467467
B = H; A = L;
468468
F = 0;
469469
break;
470-
}
470+
} /* FALLTHRU */
471471
case 0xfd: HL = kget(0);
472472
B = H; A = L;
473473
F = 0;
@@ -616,7 +616,7 @@ void check_BDOS_hook(z80info *z80) {
616616
break;
617617
case 16: /* close file */
618618
{
619-
size_t host_size, host_exts;
619+
long host_size, host_exts;
620620
fp = getfp(z80, DE);
621621
fseek(fp, 0, SEEK_END);
622622
host_size = ftell(fp);

bios.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ closeall(z80info *z80)
115115
void
116116
warmboot(z80info *z80)
117117
{
118-
int i;
118+
unsigned int i;
119119

120120
closeall(z80);
121121

@@ -344,12 +344,14 @@ list(z80info *z80)
344344
static void
345345
punch(z80info *z80)
346346
{
347+
(void)z80;
347348
}
348349

349350
/* return reader char in A, ^Z is EOF */
350351
static void
351352
reader(z80info *z80)
352353
{
354+
(void)z80;
353355
A = CNTL('Z');
354356
}
355357

@@ -886,6 +888,7 @@ closeunix(z80info *z80)
886888
void
887889
finish(z80info *z80)
888890
{
891+
(void)z80;
889892
resetterm();
890893
exit(0);
891894
}
@@ -930,7 +933,7 @@ dotime(z80info *z80)
930933
}
931934

932935
void
933-
bios(z80info *z80, int fn)
936+
bios(z80info *z80, unsigned int fn)
934937
{
935938
static void (*bioscall[])(z80info *z80) =
936939
{
@@ -960,7 +963,7 @@ bios(z80info *z80, int fn)
960963
dotime /* 23 */
961964
};
962965

963-
if (fn < 0 || fn >= sizeof bioscall / sizeof *bioscall)
966+
if (fn >= sizeof bioscall / sizeof *bioscall)
964967
{
965968
fprintf(stderr, "Illegal BIOS call %d\r\n", fn);
966969
return;

cpmtool.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -584,26 +584,26 @@ int write_file(char *name, unsigned char *buf, long sects)
584584
int al[16]; /* Allocation map for current extent */
585585

586586

587-
// Compute number of blocks needed for file
587+
/* Compute number of blocks needed for file */
588588
blks = (sects + SECTORS_PER_BLOCK - 1) / SECTORS_PER_BLOCK;
589589

590-
// Compute number of extents needed for file
590+
/* Compute number of extents needed for file */
591591
extents = ((blks * SECTORS_PER_BLOCK) + SECTORS_PER_EXTENT - 1) / SECTORS_PER_EXTENT;
592-
// Force at least one extent for case of empty file
592+
/* Force at least one extent for case of empty file */
593593
if (!extents)
594594
extents = 1;
595595

596-
// Allocate space for file
596+
/* Allocate space for file */
597597
blk_list = (int *)malloc(sizeof(int) * blks);
598598
if (alloc_space(blk_list, blks))
599599
return -1;
600600

601-
// Allocate extents for file
601+
/* Allocate extents for file */
602602
extent_list = (int *)malloc(sizeof(int) * extents);
603603
if (alloc_extents(extent_list, extents))
604604
return -1;
605605

606-
// Write file
606+
/* Write file */
607607
for (z = 0; z != 16; ++z)
608608
al[z] = 0;
609609
blkno = 0;
@@ -663,12 +663,12 @@ int put_file(char *local_name, char *atari_name)
663663
return -1;
664664
}
665665
rewind(f);
666-
// Round up to a multiple of (SECTOR_SIZE)
666+
/* Round up to a multiple of (SECTOR_SIZE) */
667667
up = size + (SECTOR_SIZE) - 1;
668668
up -= up % (SECTOR_SIZE);
669669

670670
buf = (unsigned char *)malloc(up);
671-
if (size != fread(buf, 1, size, f)) {
671+
if (fread(buf, 1, size, f) != (size_t)size) {
672672
printf("Couldn't read file '%s'\n", local_name);
673673
fclose(f);
674674
free(buf);
@@ -837,12 +837,12 @@ void atari_dir(int all, int full, int single)
837837

838838
int mkfs()
839839
{
840-
char buf[SECTOR_SIZE];
841-
int x;
840+
unsigned char buf[SECTOR_SIZE];
841+
int tracks, x, n;
842842
for (x = 0; x != SECTOR_SIZE; ++x)
843843
buf[x] = 0xe5;
844-
int tracks = dpb->off + (((dpb->dsm + 1) << dpb->bsh) + dpb->spt - 1) / dpb->spt;
845-
int n = tracks * dpb->spt;
844+
tracks = dpb->off + (((dpb->dsm + 1) << dpb->bsh) + dpb->spt - 1) / dpb->spt;
845+
n = tracks * dpb->spt;
846846
printf("%d tracks\n", tracks);
847847
printf("%d sectors\n", n);
848848
for (x = 0; x != n; ++x)

defs.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ typedef unsigned long longword;
127127
typedef struct z80info
128128
{
129129
boolean event;
130-
// byte regaf[2], regbc[2], regde[2], reghl[2];
130+
/* byte regaf[2], regbc[2], regde[2], reghl[2]; */
131131
word regaf, regbc, regde, reghl;
132132
word regaf2, regbc2, regde2, reghl2;
133133
word regsp, regpc, regix, regiy;
@@ -275,13 +275,13 @@ extern void undefinstr(z80info *z80, byte instr);
275275
extern boolean loadfile(z80info *z80, const char *fname);
276276

277277
/* bios.c */
278-
extern void bios(z80info *z80, int fn);
278+
extern void bios(z80info *z80, unsigned int fn);
279279
extern void sysreset(z80info *z80);
280280
extern void warmboot(z80info *z80);
281281
extern void finish(z80info *z80);
282282

283283
/* disassem.c */
284-
extern int disassemlen(z80info *z80);
284+
extern int disassemlen(void);
285285
extern int disassem(z80info *z80, word start, FILE *fp);
286286

287287
/* bdos */

disassem.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ put_qq_reg(int reg_num)
281281
}
282282

283283
int
284-
disassemlen(z80info *z80)
284+
disassemlen(void)
285285
{
286286
return str_length;
287287
}

main.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ initterm(void)
116116
rawterm.c_cc[VERASE] = -1;
117117
rawterm.c_cc[VKILL] = -1;
118118

119-
// tcsetattr(fileno(stdin), TCSADRAIN, &rawterm);
119+
/* tcsetattr(fileno(stdin), TCSADRAIN, &rawterm); */
120120

121121
#if 0
122122
/* rawterm.c_lflag &= ~(ISIG | ICANON | ECHO); */
@@ -148,7 +148,7 @@ initterm(void)
148148
static void
149149
command(z80info *z80)
150150
{
151-
int i, j, t, e;
151+
unsigned int i, j, t, e;
152152
char str[256], *s;
153153
FILE *fp;
154154
static word pe = 0;
@@ -307,7 +307,7 @@ command(z80info *z80)
307307

308308
sscanf(str, "%x", &t);
309309

310-
if (t < 0 || t >= sizeof z80->mem)
310+
if (t >= sizeof z80->mem)
311311
{
312312
printf("Cannot set breakpoint at addr 0x%X\n", t);
313313
break;
@@ -341,7 +341,7 @@ command(z80info *z80)
341341

342342
sscanf(str, "%x", &t);
343343

344-
if (t < 0 || t >= sizeof z80->mem)
344+
if (t >= sizeof z80->mem)
345345
{
346346
printf(" Cannot clear breakpoint at addr 0x%X\n", t);
347347
break;
@@ -370,7 +370,7 @@ command(z80info *z80)
370370
printf(" %.4X: ", pe);
371371
j = pe;
372372
pe += disassem(z80, pe, stdout);
373-
t = disassemlen(z80);
373+
t = disassemlen();
374374

375375
while (t++ < 15)
376376
putchar(' ');
@@ -734,7 +734,7 @@ loadfile(z80info *z80, const char *fname)
734734
boolean
735735
input(z80info *z80, byte haddr, byte laddr, byte *val)
736736
{
737-
int data;
737+
unsigned int data;
738738

739739
/* just uses the lower 8-bits of the I/O address for now... */
740740
switch (laddr)
@@ -777,14 +777,14 @@ input(z80info *z80, byte haddr, byte laddr, byte *val)
777777
#else /* TCGETA */
778778
fflush(stdout);
779779
data = kget(0);
780-
// data = getchar();
780+
/* data = getchar(); */
781781

782-
while ((data < 0 && errno == EINTR) ||
782+
while ((data > 0x7f && errno == EINTR) ||
783783
data == INTR_CHAR)
784784
{
785785
command(z80);
786786
data = kget(0);
787-
// data = getchar();
787+
/* data = getchar(); */
788788
}
789789
#endif
790790
}
@@ -855,7 +855,7 @@ output(z80info *z80, byte haddr, byte laddr, byte data)
855855
}
856856
} else if (laddr == 0) {
857857
/* output a character to the screen */
858-
// putchar(data);
858+
/* putchar(data); */
859859
vt52(data);
860860

861861
if (logfile != NULL)
@@ -1028,7 +1028,7 @@ main(int argc, const char *argv[])
10281028

10291029
cmd[0] = 0;
10301030

1031-
for (x = 1; argv[x]; ++x) {
1031+
for (x = 1; x < argc; ++x) {
10321032
if (argv[x][0] == '-' && argv[x][1] == '-') {
10331033
if (!strcmp(argv[x], "--help")) {
10341034
help = 1;

0 commit comments

Comments
 (0)