1
0
mirror of https://github.com/mist64/perfect6502.git synced 2024-06-03 09:29:32 +00:00

emulator / tester work

This commit is contained in:
Michael Steil 2010-09-30 02:39:11 +00:00
parent 5b43898aae
commit f101c89980
2 changed files with 43 additions and 27 deletions

View File

@ -1,4 +1,4 @@
OBJS=runtime.o plugin.o perfect6502.o console.o OBJS=runtime.o plugin.o perfect6502.o console.o emu.o
CFLAGS=-Wall -O3 CFLAGS=-Wall -O3
CC=clang CC=clang

View File

@ -20,7 +20,7 @@
THE SOFTWARE. THE SOFTWARE.
*/ */
int verbose = 1; int verbose = 0;
//#define TEST //#define TEST
//#define BROKEN_TRANSISTORS //#define BROKEN_TRANSISTORS
@ -1001,7 +1001,7 @@ setupNodesAndTransistors()
} }
void void
initChip() resetChip()
{ {
/* all nodes are floating */ /* all nodes are floating */
for (nodenum_t nn = 0; nn < NODES; nn++) { for (nodenum_t nn = 0; nn < NODES; nn++) {
@ -1165,7 +1165,7 @@ main()
* find out length of instruction in bytes * find out length of instruction in bytes
**************************************************/ **************************************************/
setup_memory(opcode); setup_memory(opcode);
initChip(); resetChip();
int i; int i;
for (i = 0; i < MAX_CYCLES; i++) { for (i = 0; i < MAX_CYCLES; i++) {
step(); step();
@ -1184,7 +1184,7 @@ main()
* find out length of instruction in cycles * find out length of instruction in cycles
**************************************************/ **************************************************/
setup_memory(opcode); setup_memory(opcode);
initChip(); resetChip();
for (i = 0; i < MAX_CYCLES; i++) { for (i = 0; i < MAX_CYCLES; i++) {
step(); step();
if ((readNOTIR() ^ 0xFF) == 0x00) if ((readNOTIR() ^ 0xFF) == 0x00)
@ -1202,7 +1202,7 @@ main()
memory[MAGIC_8 + X_OFFSET + 1] = MAGIC_IZX >> 8; memory[MAGIC_8 + X_OFFSET + 1] = MAGIC_IZX >> 8;
memory[MAGIC_8 + 0] = MAGIC_IZY & 0xFF; memory[MAGIC_8 + 0] = MAGIC_IZY & 0xFF;
memory[MAGIC_8 + 1] = MAGIC_IZY >> 8; memory[MAGIC_8 + 1] = MAGIC_IZY >> 8;
initChip(); resetChip();
if (data[opcode].length == 2) { if (data[opcode].length == 2) {
memory[INSTRUCTION_ADDR + 1] = MAGIC_8; memory[INSTRUCTION_ADDR + 1] = MAGIC_8;
} else if (data[opcode].length == 3) { } else if (data[opcode].length == 3) {
@ -1336,7 +1336,7 @@ main()
memory[MAGIC_16] = MAGIC_DATA8; memory[MAGIC_16] = MAGIC_DATA8;
break; break;
} }
initChip(); resetChip();
writes = 0; writes = 0;
reads = 0; reads = 0;
for (i = 0; i < data[opcode].cycles * 2 + 2; i++) { for (i = 0; i < data[opcode].cycles * 2 + 2; i++) {
@ -1487,7 +1487,7 @@ main()
memory[MAGIC_16] = MAGIC_DATA8; memory[MAGIC_16] = MAGIC_DATA8;
break; break;
} }
initChip(); resetChip();
for (i = 0; i < data[opcode].cycles * 2 + 2; i++) { for (i = 0; i < data[opcode].cycles * 2 + 2; i++) {
step(); step();
}; };
@ -1621,7 +1621,7 @@ main()
bzero(memory, 65536); bzero(memory, 65536);
init_monitor(); init_monitor();
initChip(); resetChip();
BOOL fail = NO; BOOL fail = NO;
for (int c = 0; c < MAX_CYCLES; c++) { for (int c = 0; c < MAX_CYCLES; c++) {
step(); step();
@ -1744,26 +1744,24 @@ enum {
STATE_FIRST_FETCH STATE_FIRST_FETCH
}; };
int void
main() setup_perfect()
{ {
setupNodesAndTransistors(); setupNodesAndTransistors();
verbose = 0; verbose = 0;
}
// printf("$%02X: ", opcode);
/************************************************** extern void setup_emu(void);
* find out length of instruction in bytes
**************************************************/ uint16_t instr_ab[10];
setup_memory(1, 0xEA, 0x00, 0x00, 0, 0, 0, 0, 0); uint8_t instr_db[10];
// setup_memory(2, 0xA9, 0x00, 0x00, 0, 0, 0, 0, 0); BOOL instr_rw[10];
// setup_memory(3, 0xFE, 0x00, 0x10, 0, 0, 0, 0, 0);
initChip(); int
perfect_measure_instruction()
{
int state = STATE_BEFORE_INSTRUCTION; int state = STATE_BEFORE_INSTRUCTION;
uint16_t instr_ab[10];
uint8_t instr_db[10];
BOOL instr_rw[10];
int c = 0; int c = 0;
for (int i = 0; i < MAX_CYCLES; i++) { for (int i = 0; i < MAX_CYCLES; i++) {
uint16_t ab; uint16_t ab;
@ -1794,15 +1792,33 @@ main()
} }
}; };
int instr_cycles = c - 1; return c - 1;
for (c = 0; c < instr_cycles; c++ ) { }
printf("%d T%d ", state, c);
int
main()
{
setup_perfect();
// setup_memory(1, 0xEA, 0x00, 0x00, 0, 0, 0, 0, 0);
// setup_memory(2, 0xA9, 0x00, 0x00, 0, 0, 0, 0, 0);
// setup_memory(2, 0xAD, 0x00, 0x10, 0, 0, 0, 0, 0);
setup_memory(3, 0xFE, 0x00, 0x10, 0, 0, 0, 0, 0);
// setup_memory(3, 0x9D, 0xFF, 0x10, 0, 2, 0, 0, 0);
resetChip();
int instr_cycles = perfect_measure_instruction();
for (int c = 0; c < instr_cycles; c++ ) {
printf("T%d ", c+1);
if (instr_rw[c]) if (instr_rw[c])
printf("R $%04X\n", instr_ab[c]); printf("R $%04X\n", instr_ab[c]);
else else
printf("W $%04X = $%02X\n", instr_ab[c], instr_db[c]); printf("W $%04X = $%02X\n", instr_ab[c], instr_db[c]);
} }
setup_emu();
} }
#else #else
int int
@ -1813,7 +1829,7 @@ main()
/* set up memory for user program */ /* set up memory for user program */
init_monitor(); init_monitor();
/* set initial state of nodes, transistors, inputs; RESET chip */ /* set initial state of nodes, transistors, inputs; RESET chip */
initChip(); resetChip();
/* emulate the 6502! */ /* emulate the 6502! */
for (;;) { for (;;) {
step(); step();