/* test_cpu -- tests the CP-1610 code in a quick and dirty fashion. */ /* WARNING: THIS CODE IS SUCH A DIRTY HACK, I'M ALMOST EMBARASSED TO SHOW IT */ #include "config.h" #include #include #include #include "cp_1610.h" cpu_t cpu_struct, *cpu = &cpu_struct; #ifdef _TMS320C6X #define MICROCYCLES (2000000) #else #define MICROCYCLES (200000000) #endif #define RATE (894886.0) cpu_word_t exec[4096]; cpu_word_t grom[2048]; cpu_word_t game[16384]; cpu_word_t ay8910[16] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, }; int main(int argc, char * argv[]) { FILE * f; int addr = 0, c0, c1, c2; int t1, t2, g; #ifdef _TMS320C6X argc=1; #endif cpu_init(cpu); /* Read in big-endian memory image at location 0, and jump to it. */ f = fopen("exec.bin", "r"); fread(exec, 2, 4096, f); fclose(f); f = fopen("grom.bin", "r"); fread(grom, 2, 2048, f); fclose(f); f = fopen("game.bin", "r"); g=fread(game, 2, 16384, f); fclose(f); #ifdef _LITTLE_ENDIAN for (addr = 0; addr < 2048; addr++) { exec[addr] = (0xFF & (exec[addr] >> 8)) | (0xFF00 & (exec[addr] << 8)); grom[addr] = (0xFF & (grom[addr] >> 8)) | (0xFF00 & (grom[addr] << 8)); game[addr] = (0xFF & (game[addr] >> 8)) | (0xFF00 & (game[addr] << 8)); } for (; addr < 4096; addr++) { exec[addr] = (0xFF & (exec[addr] >> 8)) | (0xFF00 & (exec[addr] << 8)); game[addr] = (0xFF & (game[addr] >> 8)) | (0xFF00 & (game[addr] << 8)); } for (; addr < g; addr++) { game[addr] = (0xFF & (game[addr] >> 8)) | (0xFF00 & (game[addr] << 8)); } #endif cpu_add_ram(cpu, 16, 0x0000, 0x0100, 1); /* stic? */ cpu_add_ram(cpu, 8, 0x0100, 0x00F0, 1); /* 8-bit scratchpad */ cpu_add_ram(cpu, 16, 0x0200, 0x0160, 1); /* 16-bit system mem */ cpu_add_ram(cpu, 8, 0x3800, 0x0200, 1); /* 8-bit GRAM */ cpu_add_rom(cpu, 7, 0x01F0, 0x0010, 1, ay8910); /* HACK */ cpu_add_rom(cpu, 8, 0x3000, 0x0800, 1, grom); cpu_add_rom(cpu, 10, 0x1000, 0x1000, 1, exec); cpu_add_rom(cpu, 10, 0x5000, g, 1, game); cpu->r[7] = 0x1000; /* Reset vector. */ cpu->int_vec = 0x1004; /* Interrupt vector. I think this is right. */ if (argc < 2) { t1 = clock(); c0 = MICROCYCLES; c1 = RATE / 60; while (c0 >= RATE / 60) { c1 = cpu_run(cpu, c1); c0 -= c1; cpu->irq = 1; c1 = RATE / 60; } c1 = cpu_run(cpu, c0); t2 = clock(); } else { c0 = atoi(argv[1]); if (argc > 2) c1 = atoi(argv[2]); else c1 = 0; printf("%65s R0 R1 R2 R3 R4 R5 R6 R7 SZOCDIiq\n"," "); c2 = RATE / 60; t1 = clock(); while (c0-->0) { char dasmbuf[256]; int ws; void dasm1600(char *outbuf, int addr, int dbd, int w1, int w2, int w3); if (c2--<0) { c2 = RATE/60; cpu->irq = 1; } if (c1--<=0) { dasm1600(dasmbuf, cpu->r[7], cpu->D, CPU_RD(cpu,&ws,cpu->r[7] ), CPU_RD(cpu,&ws,cpu->r[7]+1), CPU_RD(cpu,&ws,cpu->r[7]+2)); printf("%-65s%.4x %.4x %.4x %.4x %.4x %.4x %.4x %.4x " "%c%c%c%c%c%c%c%c %lu\n", dasmbuf, cpu->r[0], cpu->r[1], cpu->r[2], cpu->r[3], cpu->r[4], cpu->r[5], cpu->r[6], cpu->r[7], cpu->S ? 'S' : '-', cpu->Z ? 'Z' : '-', cpu->O ? 'O' : '-', cpu->C ? 'C' : '-', cpu->D ? 'D' : '-', cpu->I ? 'I' : '-', cpu->intr ? 'i' : '-', cpu->irq ? 'q' : '-', (unsigned long)cpu->tot_cycle ); } cpu_run(cpu, 1); } t2 = clock(); } #ifdef _TMS320C6X printf("%10d clocks\n%10lu instructions\n%10lu microcycles\n", t2-t1,cpu->tot_instr,cpu->tot_cycle); printf("Effective clock rate: %10.0f Hz\n", ((double)cpu->tot_cycle * (double)200000000.) / ((double)(t2-t1))); printf("Instructions per sec: %10.0f\n", ((double)cpu->tot_instr * (double)200000000.) / ((double)(t2-t1))); #else printf("%10d clocks\n%10llu instructions\n%10llu microcycles\n", t2-t1,cpu->tot_instr,cpu->tot_cycle); printf("Effective clock rate: %10.0f Hz\n", ((double)cpu->tot_cycle * (double)CLOCKS_PER_SEC) / ((double)(t2-t1))); printf("Instructions per sec: %10.0f instr/sec\n", ((double)cpu->tot_instr * (double)CLOCKS_PER_SEC) / ((double)(t2-t1))); #endif /* Dump memory to file */ #ifndef _TMS320C6X f = fopen("out","w"); for (addr = 0; addr < 0x10000; addr++) { int ws; c1 = CPU_RD(cpu,&ws,addr); c0 = (c1 >> 8) & 0xFF; c1 &= 0xFF; fputc(c0, f); fputc(c1, f); } fclose(f); #endif #ifdef DEBUG_DECODE_CACHE for (addr = 0; addr < 0x10000; addr++) { if ((addr & 0xf) == 0) printf("%.4x: ", addr); printf("%2x%c",cpu->decoded[addr],(addr&0xf)==0xf?'\n':' '); } #endif printf("Total cacheable : %10d instructions\n", cpu->tot_cache); printf("Total non-cacheable : %10d instructions\n", cpu->tot_noncache); return 0; } /* * ============================================================================ * Copyright (c) 1998, Joseph Zbiciak. * ============================================================================ */