Tue, 28 Dec 2010 19:55:13 +0000
add LOG macro and convert WD279x printfs to LOG() calls
src/utils.h | file | annotate | diff | revisions | |
src/wd279x.c | file | annotate | diff | revisions |
1.1 diff -r 5bbe76e71698 -r 22452603e214 src/utils.h 1.2 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.3 +++ b/src/utils.h Tue Dec 28 19:55:13 2010 +0000 1.4 @@ -0,0 +1,14 @@ 1.5 +#ifndef _H_UTILS 1.6 +#define _H_UTILS 1.7 + 1.8 +#ifndef NDEBUG 1.9 +/// Log a message to stderr 1.10 +# define LOG(x, ...) do { fprintf(stderr, "%s:%d:%s(): " x "\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, ##__VA_ARGS__); } while (0) 1.11 +/// Log a message to stderr if 'cond' is true 1.12 +# define LOG_IF(cond, x, ...) do { if (cond) fprintf(stderr, "%s:%d:%s(): " x "\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, ##__VA_ARGS__); } while (0) 1.13 +#else 1.14 +#define LOG(x, ...) 1.15 +#define LOG_IF(cond, x, ...) 1.16 +#endif 1.17 + 1.18 +#endif // _H_UTILS
2.1 diff -r 5bbe76e71698 -r 22452603e214 src/wd279x.c 2.2 --- a/src/wd279x.c Tue Dec 28 19:23:57 2010 +0000 2.3 +++ b/src/wd279x.c Tue Dec 28 19:55:13 2010 +0000 2.4 @@ -4,6 +4,9 @@ 2.5 #include "musashi/m68k.h" 2.6 #include "wd279x.h" 2.7 2.8 +#define NDEBUG 2.9 +#include "utils.h" 2.10 + 2.11 /// WD2797 command constants 2.12 enum { 2.13 CMD_MASK = 0xF0, ///< Bit mask to detect command bits 2.14 @@ -172,7 +175,7 @@ 2.15 if (ctx->cmd_has_drq) { 2.16 temp = ctx->status & ~0x03; 2.17 temp |= (ctx->data_pos < ctx->data_len) ? 0x02 : 0x00; 2.18 - printf("\tWDFDC rd sr, has drq, pos=%lu len=%lu, sr=0x%02X\n", ctx->data_pos, ctx->data_len, temp); 2.19 + LOG("\tWDFDC rd sr, has drq, pos=%lu len=%lu, sr=0x%02X", ctx->data_pos, ctx->data_len, temp); 2.20 } else { 2.21 temp = ctx->status & ~0x01; 2.22 } 2.23 @@ -382,12 +385,12 @@ 2.24 case CMD_READ_SECTOR: 2.25 case CMD_READ_SECTOR_MULTI: 2.26 ctx->head = (val & 0x02) ? 1 : 0; 2.27 - printf("WD279X: READ SECTOR cmd=%02X chs=%d:%d:%d\n", cmd, ctx->track, ctx->head, ctx->sector); 2.28 + LOG("WD279X: READ SECTOR cmd=%02X chs=%d:%d:%d", cmd, ctx->track, ctx->head, ctx->sector); 2.29 // Read Sector or Read Sector Multiple 2.30 2.31 // Check to see if the cyl, hd and sec are valid 2.32 if ((ctx->track > (ctx->geom_tracks-1)) || (ctx->head > (ctx->geom_heads-1)) || (ctx->sector > ctx->geom_spt) || (ctx->sector == 0)) { 2.33 - fprintf(stderr, "*** WD2797 ALERT: CHS parameter limit exceeded! CHS=%d:%d:%d, maxCHS=%d:%d:%d\n", 2.34 + LOG("*** WD2797 ALERT: CHS parameter limit exceeded! CHS=%d:%d:%d, maxCHS=%d:%d:%d", 2.35 ctx->track, ctx->head, ctx->sector, 2.36 ctx->geom_tracks-1, ctx->geom_heads-1, ctx->geom_spt); 2.37 // CHS parameters exceed limits 2.38 @@ -414,13 +417,13 @@ 2.39 lba = (((ctx->track * ctx->geom_heads * ctx->geom_spt) + (ctx->head * ctx->geom_spt) + ctx->sector) + i) - 1; 2.40 // convert LBA to byte address 2.41 lba *= ctx->geom_secsz; 2.42 - printf("\tREAD lba = %lu\n", lba); 2.43 + LOG("\tREAD lba = %lu", lba); 2.44 2.45 // Read the sector from the file 2.46 fseek(ctx->disc_image, lba, SEEK_SET); 2.47 + // TODO: check fread return value! if < secsz, BAIL! (call it a crc error or secnotfound maybe? also log to stderr) 2.48 ctx->data_len += fread(&ctx->data[ctx->data_len], 1, ctx->geom_secsz, ctx->disc_image); 2.49 - printf("\tREAD len=%lu, pos=%lu, ssz=%d\n", ctx->data_len, ctx->data_pos, ctx->geom_secsz); 2.50 - // TODO: check fread return value! if < secsz, BAIL! (call it a crc error or secnotfound maybe? also log to stderr) 2.51 + LOG("\tREAD len=%lu, pos=%lu, ssz=%d", ctx->data_len, ctx->data_pos, ctx->geom_secsz); 2.52 } 2.53 2.54 ctx->status = 0;