Tue, 21 May 2013 22:48:32 +0100
Code clean up
* Tighten optimisation and warning options to find more potential issues
* Remove unused variable in keyboard code
* Display error message if ROMs fail to load
* Fix format string bugs in WD2010
Makefile | file | annotate | diff | revisions | |
src/keyboard.c | file | annotate | diff | revisions | |
src/state.c | file | annotate | diff | revisions | |
src/wd2010.c | file | annotate | diff | revisions |
1.1 --- a/Makefile Fri Apr 12 16:26:25 2013 +0100 1.2 +++ b/Makefile Tue May 21 22:48:32 2013 +0100 1.3 @@ -167,8 +167,8 @@ 1.4 MAKE = make 1.5 CC = gcc 1.6 CXX = g++ 1.7 -CFLAGS = -Wall -pedantic -std=gnu99 $(EXT_CFLAGS) -DWD2010_SEEK_DELAY=1 -DSHOW_LEDS -DDEBUG_MAP 1.8 -CXXFLAGS= -Wall -pedantic -std=gnu++0x $(EXT_CXXFLAGS) 1.9 +CFLAGS = -O -Wall -Wextra -Wno-unused-parameter -pedantic -std=gnu99 $(EXT_CFLAGS) -DWD2010_SEEK_DELAY=1 1.10 +CXXFLAGS= -O -Wall -Wextra -Wno-unused-parameter -pedantic -std=gnu++0x $(EXT_CXXFLAGS) 1.11 LDFLAGS = $(EXT_LDFLAGS) 1.12 RM = rm 1.13 STRIP = strip
2.1 --- a/src/keyboard.c Fri Apr 12 16:26:25 2013 +0100 2.2 +++ b/src/keyboard.c Tue May 21 22:48:32 2013 +0100 2.3 @@ -218,7 +218,6 @@ 2.4 2.5 // if buffer empty, do a keyboard scan 2.6 if (ks->buflen == 0) { 2.7 - size_t last_writep; 2.8 // Keyboard Data Begins Here (BEGKBD) 2.9 //ks->buffer[ks->writep] = KEY_BEGIN_KEYBOARD; 2.10 //ks->writep = (ks->writep + 1) % KEYBOARD_BUFFER_SIZE; 2.11 @@ -228,7 +227,6 @@ 2.12 if (ks->keystate[i]) { 2.13 LOG_IF(kbc_debug, "KBC KEY DOWN: %d\n", i); 2.14 ks->buffer[ks->writep] = i; 2.15 - last_writep = ks->writep; 2.16 ks->writep = (ks->writep + 1) % KEYBOARD_BUFFER_SIZE; 2.17 if (ks->buflen < KEYBOARD_BUFFER_SIZE) ks->buflen++; 2.18 nkeys++;
3.1 --- a/src/state.c Fri Apr 12 16:26:25 2013 +0100 3.2 +++ b/src/state.c Tue May 21 22:48:32 2013 +0100 3.3 @@ -76,8 +76,14 @@ 3.4 uint8_t *romdat1, *romdat2; 3.5 romdat1 = malloc(romlen); 3.6 romdat2 = malloc(romlen2); 3.7 - fread(romdat1, 1, romlen, r15c); 3.8 - fread(romdat2, 1, romlen2, r14c); 3.9 + if (fread(romdat1, 1, romlen, r15c) != romlen) { 3.10 + fprintf(stderr, "[state] Error reading ROM 15C.\n"); 3.11 + return -3; 3.12 + } 3.13 + if (fread(romdat2, 1, romlen2, r14c) != romlen) { 3.14 + fprintf(stderr, "[state] Error reading ROM 14C.\n"); 3.15 + return -3; 3.16 + } 3.17 3.18 // convert the ROM data 3.19 for (size_t i=0; i<(romlen + romlen2); i+=2) {
4.1 --- a/src/wd2010.c Fri Apr 12 16:26:25 2013 +0100 4.2 +++ b/src/wd2010.c Tue May 21 22:48:32 2013 +0100 4.3 @@ -239,7 +239,7 @@ 4.4 if (ctx->cmd_has_drq) { 4.5 temp = ctx->status & ~(SR_BUSY & SR_DRQ); 4.6 temp |= (ctx->data_pos < ctx->data_len) ? SR_DRQ : 0; 4.7 - LOG("\tWDFDC rd sr, has drq, pos=%lu len=%lu, sr=0x%02X", ctx->data_pos, ctx->data_len, temp); 4.8 + LOG("\tWD2010 rd sr, has drq, pos=%zu len=%zu, sr=0x%02X", ctx->data_pos, ctx->data_len, temp); 4.9 } else { 4.10 temp = ctx->status & ~0x80; 4.11 } 4.12 @@ -389,13 +389,13 @@ 4.13 lba = (((ctx->track * ctx->geom_heads * ctx->geom_spt) + (ctx->head * ctx->geom_spt) + ctx->sector) + i); 4.14 // convert LBA to byte address 4.15 lba *= ctx->geom_secsz; 4.16 - LOG("\tREAD lba = %lu", lba); 4.17 + LOG("\tREAD lba = %zu", lba); 4.18 4.19 // Read the sector from the file 4.20 fseek(ctx->disc_image, lba, SEEK_SET); 4.21 // TODO: check fread return value! if < secsz, BAIL! (call it a crc error or secnotfound maybe? also log to stderr) 4.22 ctx->data_len += fread(&ctx->data[ctx->data_len], 1, ctx->geom_secsz, ctx->disc_image); 4.23 - LOG("\tREAD len=%lu, pos=%lu, ssz=%d", ctx->data_len, ctx->data_pos, ctx->geom_secsz); 4.24 + LOG("\tREAD len=%zu, pos=%zu, ssz=%d", ctx->data_len, ctx->data_pos, ctx->geom_secsz); 4.25 } 4.26 4.27 ctx->status = 0;