1
0
mirror of https://github.com/mist64/perfect6502.git synced 2024-06-08 12:29:28 +00:00

breaking transistors

This commit is contained in:
Michael Steil 2010-09-28 17:22:57 +00:00
parent a0034447c1
commit e292c84c3a
2 changed files with 96 additions and 21 deletions

View File

@ -20,9 +20,10 @@
THE SOFTWARE.
*/
int verbose = 0;
int verbose = 1;
//#define TEST
//#define BROKEN_TRANSISTORS
/************************************************************
*
@ -461,6 +462,10 @@ floatnode(nodenum_t nn)
set_nodes_state_floating(nn, 1);
}
#ifdef BROKEN_TRANSISTORS
transnum_t broken_transistor = (transnum_t)-1;
#endif
void
toggleTransistor(transnum_t tn)
{
@ -471,6 +476,13 @@ toggleTransistor(transnum_t tn)
BOOL on = !get_transistors_on(tn);
#endif
#ifdef BROKEN_TRANSISTORS
if (tn == broken_transistor) {
if (!on)
return;
}
#endif
set_transistors_on(tn, on);
/* if the transistor is off, both nodes are floating */
@ -926,6 +938,8 @@ step()
*
************************************************************/
count_t transistors;
void
setupNodesAndTransistors()
{
@ -944,6 +958,7 @@ setupNodesAndTransistors()
nodenum_t c2 = transdefs[i].c2;
/* skip duplicate transistors */
BOOL found = NO;
#ifndef BROKEN_TRANSISTORS
for (count_t k = 0; k < i; k++) {
if (transdefs[k].gate == gate &&
transdefs[k].c1 == c1 &&
@ -952,6 +967,7 @@ setupNodesAndTransistors()
break;
}
}
#endif
if (!found) {
transistors_gate[j] = gate;
transistors_c1[j] = c1;
@ -959,7 +975,7 @@ setupNodesAndTransistors()
j++;
}
}
count_t transistors = j;
transistors = j;
if (verbose)
printf("unique transistors: %d\n", transistors);
@ -1004,7 +1020,7 @@ initChip()
/* hold RESET for 8 cycles */
for (int i = 0; i < 16; i++)
step_quiet();
step();
/* release RESET */
setHigh(res);
@ -1023,24 +1039,7 @@ initChip()
*
************************************************************/
#ifndef TEST
int
main()
{
/* set up data structures for efficient emulation */
setupNodesAndTransistors();
/* set up memory for user program */
init_monitor();
/* set initial state of nodes, transistors, inputs; RESET chip */
initChip();
/* emulate the 6502! */
for (;;) {
step();
if (verbose)
chipStatus();
};
}
#else
#ifdef TEST
#define BRK_LENGTH 2 /* BRK pushes PC + 2 onto the stack */
@ -1590,4 +1589,75 @@ main()
}
}
}
#elif defined(BROKEN_TRANSISTORS)
#define MAX_CYCLES 33000
BOOL log_rw[MAX_CYCLES];
uint16_t log_ab[MAX_CYCLES];
uint8_t log_db[MAX_CYCLES];
int
main()
{
setupNodesAndTransistors();
for (int run = -1; run < transistors; run ++) {
#if 0
/* skip a few runs! */
if (run == 0)
run = 180;
#endif
if (run != -1) {
printf("testing transistor %d: ", run);
broken_transistor = run;
}
bzero(memory, 65536);
init_monitor();
initChip();
BOOL fail = NO;
for (int c = 0; c < MAX_CYCLES; c++) {
step();
if (run == -1) {
log_rw[c] = isNodeHigh(rw);
log_ab[c] = readAddressBus();
log_db[c] = readDataBus();
} else {
if (log_rw[c] != isNodeHigh(rw)) {
printf("FAIL, RW %d instead of %d @ %d\n", isNodeHigh(rw), log_rw[c], c);
fail = YES;
break;
}
if (log_ab[c] != readAddressBus()) {
printf("FAIL, AB 0x%04x instead of 0x%04x @ %d\n", readAddressBus(), log_ab[c], c);
fail = YES;
break;
}
if (log_db[c] != readDataBus()) {
printf("FAIL, DB 0x%02x instead of 0x%02x @ %d\n", readDataBus(), log_db[c], c);
fail = YES;
break;
}
}
}
if (run != -1 && !fail)
printf("PASS\n");
}
}
#else
int
main()
{
/* set up data structures for efficient emulation */
setupNodesAndTransistors();
/* set up memory for user program */
init_monitor();
/* set initial state of nodes, transistors, inputs; RESET chip */
initChip();
/* emulate the 6502! */
for (;;) {
step();
if (verbose)
chipStatus();
};
}
#endif

View File

@ -399,6 +399,7 @@ CHRIN() {
/* CHROUT */
static void
CHROUT() {
return;
//exit(1);
#if 0
int a = *(unsigned short*)(&RAM[0x0100+S+1]) + 1;
@ -913,7 +914,11 @@ kernal_dispatch() {
case MAGIC_CONTINUATION: /*printf("--CONTINUATION--\n");*/ return 0;
#if 0
default: printf("unknown PC=$%04X S=$%02X\n", PC, S); exit(1);
#else
default: return 1;
#endif
}
return 1;
}