Skip to content

Commit

Permalink
Z80: added simple modelling of charge sharing to deal with so Z80 flo…
Browse files Browse the repository at this point in the history
…ating node issues
  • Loading branch information
hoglet67 committed Oct 8, 2018
1 parent 9370a4f commit 22a6aae
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
36 changes: 35 additions & 1 deletion netlist_sim.c
Expand Up @@ -61,6 +61,7 @@ typedef struct {
} list_t;

typedef struct {
BOOL chargeSharing;
nodenum_t nodes;
nodenum_t transistors;
nodenum_t vss;
Expand Down Expand Up @@ -380,6 +381,32 @@ getGroupValue(state_t *state)
}
}

static inline BOOL
getGroupValueChargeSharing(state_t *state)
{
switch (state->group_contains_value) {
case contains_vcc:
case contains_pullup:
return YES;
case contains_vss:
case contains_pulldown:
return NO;
default:
break;
}
BOOL max_state = NO;
int max_connections = 0;
for (int i = 0; i < group_count(state); i++) {
nodenum_t nn = group_get(state, i);
int connections = state->nodes_gatecount[nn] + state->nodes_c1c2count[nn];
if (connections > max_connections) {
max_connections = connections;
max_state = get_nodes_value(state, nn);
}
}
return max_state;
}

static inline void
recalcNode(state_t *state, nodenum_t node)
{
Expand All @@ -390,7 +417,7 @@ recalcNode(state_t *state, nodenum_t node)
addAllNodesToGroup(state, node);

/* get the state of the group */
BOOL newv = getGroupValue(state);
BOOL newv = state->chargeSharing ? getGroupValueChargeSharing(state) : getGroupValue(state);

/*
* - set all nodes to the group state
Expand Down Expand Up @@ -457,6 +484,12 @@ recalcNodeList(state_t *state)
*
************************************************************/

void
modelChargeSharing(state_t *state, BOOL enabled)
{
state->chargeSharing = enabled;
}

static inline void
add_nodes_dependant(state_t *state, nodenum_t a, nodenum_t b)
{
Expand All @@ -482,6 +515,7 @@ setupNodesAndTransistors(netlist_transdefs *transdefs, BOOL *node_is_pullup, nod
{
/* allocate state */
state_t *state = malloc(sizeof(state_t));
state->chargeSharing = NO;
state->nodes = nodes;
state->transistors = transistors;
state->vss = vss;
Expand Down
2 changes: 2 additions & 0 deletions netlist_sim.h
Expand Up @@ -10,3 +10,5 @@ void writeNodes(state_t *state, int count, nodenum_t *nodelist, int v);

void recalcNodeList(state_t *state);
void stabilizeChip(state_t *state);

void modelChargeSharing(state_t *state, BOOL enabled);
2 changes: 2 additions & 0 deletions perfectz80.c
Expand Up @@ -417,6 +417,8 @@ initAndResetChip(int argc, char *argv[])
vss,
vcc);

modelChargeSharing(state, YES);

setNode(state, _reset, 0);
setNode(state, clk, 1);
setNode(state, _busrq, 1);
Expand Down

0 comments on commit 22a6aae

Please sign in to comment.