mirror of
https://github.com/mauiaaron/apple2.git
synced 2025-01-27 08:31:03 +00:00
Adds a VM tracing facility and functionality test
This commit is contained in:
parent
89fc5f6599
commit
101e507add
@ -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 -DDISK_TRACING=1 -Isrc/test
|
||||
A2_TEST_CFLAGS = -DTESTING=1 -DCPU_TRACING=1 -DDISK_TRACING=1 -DVM_TRACING=1 -Isrc/test
|
||||
|
||||
TESTS = testcpu testdisplay testvm
|
||||
check_PROGRAMS = testcpu testdisplay testvm
|
||||
|
@ -1942,6 +1942,11 @@ void MB_InitializeIO(LPBYTE unused_pCxRomPeripheral, UINT uSlot4, UINT uSlot5)
|
||||
// Phasor : Slot 4
|
||||
// <other> : Slot 4 & 5
|
||||
|
||||
#ifdef APPLE2IX
|
||||
extern void MB_Read();
|
||||
extern void MB_Write();
|
||||
extern void PhasorIO();
|
||||
#endif
|
||||
if (g_Slot4 != CT_MockingboardC && g_Slot4 != CT_Phasor)
|
||||
{
|
||||
MB_SetSoundcardType(CT_Empty);
|
||||
|
@ -14,6 +14,13 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#if CPU_TRACING
|
||||
# if VM_TRACING
|
||||
# define RESET_VM_TRACING 1
|
||||
# endif
|
||||
# undef VM_TRACING
|
||||
#endif
|
||||
|
||||
#include "common.h"
|
||||
|
||||
uint16_t cpu65_pc;
|
||||
@ -822,5 +829,10 @@ GLUE_C_WRITE(cpu65_trace_epilogue)
|
||||
fflush(cpu_trace_fp);
|
||||
}
|
||||
|
||||
# if RESET_VM_TRACING
|
||||
# define VM_TRACING 1
|
||||
# endif
|
||||
# undef RESET_VM_TRACING
|
||||
|
||||
#endif // CPU_TRACING
|
||||
|
||||
|
35
src/glue.h
35
src/glue.h
@ -21,13 +21,40 @@
|
||||
#define GLUE_BANK_WRITE(func,pointer)
|
||||
#define GLUE_BANK_MAYBEWRITE(func,pointer)
|
||||
|
||||
#if VM_TRACING
|
||||
|
||||
#define GLUE_C_WRITE(func) \
|
||||
extern void func(); \
|
||||
void c_##func(uint16_t ea, uint8_t b) /* you complete definition */
|
||||
void c__##func(uint16_t ea, uint8_t b); \
|
||||
void c_##func(uint16_t ea, uint8_t b) { \
|
||||
extern FILE *test_vm_fp; \
|
||||
if (test_vm_fp && ((ea >= 0xC000) && (ea < 0xD000)) ) { \
|
||||
fprintf(test_vm_fp, "%04X w:%02X %s (%s:%d)\n", ea, b, __FUNCTION__, __FILE__, __LINE__); \
|
||||
} \
|
||||
c__##func(ea, b); \
|
||||
} \
|
||||
void c__##func(uint16_t ea, uint8_t b)
|
||||
|
||||
#define GLUE_C_READ(func) \
|
||||
extern void func(); \
|
||||
uint8_t c_##func(uint16_t ea) /* you complete definition */
|
||||
uint8_t c__##func(uint16_t ea); \
|
||||
uint8_t c_##func(uint16_t ea) { \
|
||||
uint8_t b = c__##func(ea); \
|
||||
extern FILE *test_vm_fp; \
|
||||
if (test_vm_fp && ((ea >= 0xC000) && (ea < 0xD000)) ) { \
|
||||
fprintf(test_vm_fp, "%04X r:%02X %s (%s:%d)\n", ea, b, __FUNCTION__, __FILE__, __LINE__); \
|
||||
} \
|
||||
return b; \
|
||||
} \
|
||||
uint8_t c__##func(uint16_t ea)
|
||||
|
||||
#else
|
||||
|
||||
#define GLUE_C_WRITE(func) \
|
||||
void c_##func(uint16_t ea, uint8_t b)
|
||||
|
||||
#define GLUE_C_READ(func) \
|
||||
uint8_t c_##func(uint16_t ea)
|
||||
|
||||
#endif
|
||||
|
||||
#define GLUE_C_READ_ALTZP(func, ...) GLUE_C_READ(func)
|
||||
|
||||
|
13
src/misc.h
13
src/misc.h
@ -121,14 +121,15 @@ void c_initialize_vm();
|
||||
uint8_t c_read_random(uint16_t ea);
|
||||
void reinitialize();
|
||||
|
||||
/* virtual memory compacter */
|
||||
|
||||
void pre_compact(void);
|
||||
void compact(void);
|
||||
|
||||
/* vm hooks */
|
||||
|
||||
void ram_nop(),
|
||||
#if VM_TRACING
|
||||
void vm_begin_trace(const char *vm_file);
|
||||
void vm_end_trace(void);
|
||||
void vm_toggle_trace(const char *vm_file);
|
||||
#endif
|
||||
|
||||
void ram_nop(),
|
||||
|
||||
write_unmapped_softswitch(),
|
||||
|
||||
|
@ -106,7 +106,7 @@ TEST test_boot_disk_bytes() {
|
||||
TEST test_boot_disk_cputrace() {
|
||||
char *homedir = getenv("HOME");
|
||||
char *output = NULL;
|
||||
asprintf(&output, "%s/a2_cputrace.raw", homedir);
|
||||
asprintf(&output, "%s/a2_cputrace.txt", homedir);
|
||||
if (output) {
|
||||
unlink(output);
|
||||
cpu65_trace_begin(output);
|
||||
@ -144,6 +144,45 @@ TEST test_boot_disk_cputrace() {
|
||||
PASS();
|
||||
}
|
||||
|
||||
#define EXPECTED_VM_TRACE_FILE_SIZE 3688453
|
||||
#define EXPECTED_VM_TRACE_SHA "9946B0C5288228535A37475CDAB5C9E685EEDDE9"
|
||||
TEST test_boot_disk_vmtrace() {
|
||||
char *homedir = getenv("HOME");
|
||||
char *disk = NULL;
|
||||
asprintf(&disk, "%s/a2_vmtrace.txt", homedir);
|
||||
if (disk) {
|
||||
unlink(disk);
|
||||
vm_begin_trace(disk);
|
||||
}
|
||||
|
||||
BOOT_TO_DOS();
|
||||
|
||||
vm_end_trace();
|
||||
c_eject_6(0);
|
||||
|
||||
do {
|
||||
uint8_t md[SHA_DIGEST_LENGTH];
|
||||
char mdstr[(SHA_DIGEST_LENGTH*2)+1];
|
||||
|
||||
FILE *fp = fopen(disk, "r");
|
||||
char *buf = malloc(EXPECTED_VM_TRACE_FILE_SIZE);
|
||||
if (fread(buf, 1, EXPECTED_VM_TRACE_FILE_SIZE, fp) != EXPECTED_VM_TRACE_FILE_SIZE) {
|
||||
ASSERT(false);
|
||||
}
|
||||
fclose(fp); fp = NULL;
|
||||
SHA1(buf, EXPECTED_VM_TRACE_FILE_SIZE, md);
|
||||
FREE(buf);
|
||||
|
||||
sha1_to_str(md, mdstr);
|
||||
ASSERT(strcmp(mdstr, EXPECTED_VM_TRACE_SHA) == 0);
|
||||
} while(0);
|
||||
|
||||
unlink(disk);
|
||||
FREE(disk);
|
||||
|
||||
PASS();
|
||||
}
|
||||
|
||||
TEST test_boot_disk() {
|
||||
BOOT_TO_DOS();
|
||||
PASS();
|
||||
@ -3418,6 +3457,7 @@ static void *test_thread(void *dummyptr) {
|
||||
|
||||
RUN_TESTp(test_boot_disk_bytes);
|
||||
RUN_TESTp(test_boot_disk_cputrace);
|
||||
RUN_TESTp(test_boot_disk_vmtrace);
|
||||
RUN_TESTp(test_boot_disk);
|
||||
|
||||
RUN_TESTp(test_inithello_dsk);
|
||||
|
32
src/vm.c
32
src/vm.c
@ -113,6 +113,10 @@
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#if VM_TRACING
|
||||
FILE *test_vm_fp = NULL;
|
||||
#endif
|
||||
|
||||
GLUE_C_READ(ram_nop)
|
||||
{
|
||||
return 0x0;
|
||||
@ -1038,3 +1042,31 @@ void debug_print_softwitches(void) {
|
||||
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
#if VM_TRACING
|
||||
void vm_begin_trace(const char *vm_file) {
|
||||
if (vm_file) {
|
||||
if (test_vm_fp) {
|
||||
vm_end_trace();
|
||||
}
|
||||
test_vm_fp = fopen(vm_file, "w");
|
||||
}
|
||||
}
|
||||
|
||||
void vm_end_trace(void) {
|
||||
if (test_vm_fp) {
|
||||
fflush(test_vm_fp);
|
||||
fclose(test_vm_fp);
|
||||
test_vm_fp = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void vm_toggle_trace(const char *vm_file) {
|
||||
if (test_vm_fp) {
|
||||
vm_end_trace();
|
||||
} else {
|
||||
vm_begin_trace(vm_file);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user