diff --git a/Makefile.am b/Makefile.am index e2df2f08..aaf6b24e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -92,7 +92,7 @@ src/x86/glue.S: src/disk.c src/misc.c src/display.c src/vm.c src/cpu-supp.c @AUD LOG_DRIVER = testcpu ## hack TODO/FIXME ... should be wrapper shell script accepting standard GNU testing API args ... A2_TEST_SOURCES = $(apple2ix_SOURCES) src/test/testcommon.c -A2_TEST_CFLAGS = -DTESTING=1 -DCPU_TRACING=1 -Isrc/test +A2_TEST_CFLAGS = -DTESTING=1 -DCPU_TRACING=1 -DDISK_TRACING=1 -Isrc/test TESTS = testcpu testdisplay testvm check_PROGRAMS = testcpu testdisplay testvm diff --git a/src/disk.c b/src/disk.c index 158cd38b..631730f6 100644 --- a/src/disk.c +++ b/src/disk.c @@ -21,7 +21,7 @@ #define NIB_SIZE 232960 #define DSK_SIZE 143360 -#ifdef TESTING +#if DISK_TRACING static FILE *test_read_fp = NULL; static FILE *test_write_fp = NULL; #endif @@ -114,7 +114,7 @@ void c_init_6(void) { #endif } -#ifdef TESTING +#if DISK_TRACING void c_begin_disk_trace_6(const char *read_file, const char *write_file) { if (read_file) { test_read_fp = fopen(read_file, "w"); @@ -136,6 +136,14 @@ void c_end_disk_trace_6(void) { test_write_fp = NULL; } } + +void c_toggle_disk_trace_6(const char *read_file, const char *write_file) { + if (test_read_fp) { + c_end_disk_trace_6(); + } else { + c_begin_disk_trace_6(read_file, write_file); + } +} #endif /* ------------------------------------------------------------------------- @@ -260,9 +268,9 @@ unsigned char c_read_nibblized_6_6(void) { fseek(disk6.disk[disk6.drive].fp, -2 * PHASE_BYTES, SEEK_CUR); } -#ifdef TESTING +#if DISK_TRACING if (test_read_fp) { - fputc(ch, test_read_fp); + fprintf(test_read_fp, "%02X", ch); fflush(test_read_fp); } #endif @@ -367,6 +375,11 @@ unsigned char c_read_normal_6(void) { /* Set file position variable */ disk6.disk[disk6.drive].file_pos = 256 * 16 * (disk6.disk[disk6.drive].phase >> 1) + 256 * skew_table_6[ disk6.disk[disk6.drive].sector ]; +#if DISK_TRACING + if (test_read_fp) { + fprintf(test_read_fp, "\nTRK:%02X SECTOR:%02X SKEW:%02X (FILE_POS:%d)\n", disk6.disk[disk6.drive].phase, disk6.disk[disk6.drive].sector, skew_table_6[ disk6.disk[disk6.drive].sector ], disk6.disk[disk6.drive].file_pos); + } +#endif /* File large enough? */ if (disk6.disk[disk6.drive].file_pos + 255 > disk6.disk[disk6.drive].file_size) { @@ -427,9 +440,9 @@ unsigned char c_read_normal_6(void) { disk6.disk[disk6.drive].run_byte = 0; } -#ifdef TESTING +#if DISK_TRACING if (test_read_fp) { - fputc(value, test_read_fp); + fprintf(test_read_fp, "%02X", value); fflush(test_read_fp); } #endif @@ -451,9 +464,9 @@ void c_write_nibblized_6_6(void) { fputc(disk6.disk_byte, disk6.disk[disk6.drive].fp); -#ifdef TESTING +#if DISK_TRACING if (test_write_fp) { - fputc(disk6.disk_byte, test_write_fp); + fprintf(test_read_fp, "%02X", disk6.disk_byte); fflush(test_write_fp); } #endif @@ -565,9 +578,12 @@ void c_write_normal_6(void) { /* Write sector */ fwrite(disk6.disk_data, 1, 256, disk6.disk[disk6.drive].fp); -#ifdef TESTING +#if DISK_TRACING if (test_write_fp) { - fwrite(disk6.disk_data, 1, 256, test_write_fp); + fprintf(test_write_fp, "\nTRK:%02X SECTOR:%02X SKEW:%02X (FILE_POS:%d)\n", disk6.disk[disk6.drive].phase, disk6.disk[disk6.drive].sector, skew_table_6[ disk6.disk[disk6.drive].sector ], disk6.disk[disk6.drive].file_pos); + for (unsigned int i=0; i<256; i++) { + fprintf(test_write_fp, "%02X", disk6.disk_data[i]); + } fflush(test_write_fp); } #endif diff --git a/src/disk.h b/src/disk.h index 2acbfbc5..6a4ad08e 100644 --- a/src/disk.h +++ b/src/disk.h @@ -64,7 +64,8 @@ disk_write_latch(void), disk_read_prepare_in(void), disk_read_prepare_out(void); -#ifdef TESTING +#if DISK_TRACING +void c_toggle_disk_trace_6(const char *read_file, const char *write_file); void c_begin_disk_trace_6(const char *read_file, const char *write_file); void c_end_disk_trace_6(void); #endif diff --git a/src/meta/debug.l b/src/meta/debug.l index 8b2ed8cf..c3c2e46e 100644 --- a/src/meta/debug.l +++ b/src/meta/debug.l @@ -861,6 +861,17 @@ ADDRS [0-9a-fA-F]+ #endif } +{BOS}diskt?r?a?c?e?{EOS} { +#if DISK_TRACING + char *buf = NULL; + asprintf(&buf, "%s/%s", getenv("HOME"), "disktrace.txt"); + c_toggle_disk_trace_6(buf, NULL); + free(buf); +#else + LOG("CPU tracing not enabled..."); +#endif +} + {BOS}la?n?g?{EOS} { /* display language card settings */ show_lc_info(); diff --git a/src/test/testvm.c b/src/test/testvm.c index 38548a85..c1525245 100644 --- a/src/test/testvm.c +++ b/src/test/testvm.c @@ -60,12 +60,12 @@ static void sha1_to_str(const uint8_t * const md, char *buf) { // ---------------------------------------------------------------------------- // VM TESTS ... -#define EXPECTED_DISK_TRACE_FILE_SIZE 60961 -#define EXPECTED_DISK_TRACE_SHA "D21CC686571ADE868A909B5A7044A973DE70DFFB" +#define EXPECTED_DISK_TRACE_FILE_SIZE 128794 +#define EXPECTED_DISK_TRACE_SHA "7CEBB3690E66605E558D98D9041C29AE10C92D42" TEST test_boot_disk_bytes() { char *homedir = getenv("HOME"); char *disk = NULL; - asprintf(&disk, "%s/a2_read_disk_test.raw", homedir); + asprintf(&disk, "%s/a2_read_disk_test.txt", homedir); if (disk) { unlink(disk); c_begin_disk_trace_6(disk, NULL);