mirror of
https://github.com/mist64/perfect6502.git
synced 2025-08-09 15:24:59 +00:00
list cleanup WIP
This commit is contained in:
119
perfect6502.c
119
perfect6502.c
@@ -58,15 +58,6 @@ int cycle;
|
|||||||
|
|
||||||
uint8_t memory[65536]; /* XXX must be hooked up with RAM[] in runtime.c */
|
uint8_t memory[65536]; /* XXX must be hooked up with RAM[] in runtime.c */
|
||||||
|
|
||||||
/* list of nodes that need to be recalculated */
|
|
||||||
typedef struct {
|
|
||||||
nodenum_t *list;
|
|
||||||
count_t count;
|
|
||||||
int *bitmap;
|
|
||||||
} list_t;
|
|
||||||
|
|
||||||
list_t recalc;
|
|
||||||
|
|
||||||
/************************************************************
|
/************************************************************
|
||||||
*
|
*
|
||||||
* Helpers for Data Structures
|
* Helpers for Data Structures
|
||||||
@@ -88,12 +79,70 @@ get_transistors_on(transnum_t t)
|
|||||||
return (transistors_on[t>>5] >> (t & 31)) & 1;
|
return (transistors_on[t>>5] >> (t & 31)) & 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL
|
/************************************************************
|
||||||
recalcListContains(nodenum_t el)
|
*
|
||||||
|
* Data Structures and Algorithms for Lists
|
||||||
|
*
|
||||||
|
************************************************************/
|
||||||
|
|
||||||
|
/* list of nodes that need to be recalculated */
|
||||||
|
typedef struct {
|
||||||
|
nodenum_t *list;
|
||||||
|
count_t count;
|
||||||
|
int *bitmap;
|
||||||
|
} list_t;
|
||||||
|
|
||||||
|
nodenum_t list[NODES];
|
||||||
|
|
||||||
|
/* storage for secondary list and two sets of bitmaps */
|
||||||
|
nodenum_t list1[NODES];
|
||||||
|
int bitmap1[NODES/sizeof(int)+1];
|
||||||
|
int bitmap2[NODES/sizeof(int)+1];
|
||||||
|
|
||||||
|
/* the nodes we are working with */
|
||||||
|
list_t current = {
|
||||||
|
.list = list,
|
||||||
|
.bitmap = bitmap2
|
||||||
|
};
|
||||||
|
|
||||||
|
/* the nodes we are collecting for the next run */
|
||||||
|
list_t recalc = {
|
||||||
|
.list = list1,
|
||||||
|
.bitmap = bitmap1
|
||||||
|
};
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
recalclist_init()
|
||||||
|
{
|
||||||
|
bzero(recalc.bitmap, sizeof(*recalc.bitmap)*NODES/sizeof(int));
|
||||||
|
recalc.count = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
recalclist_add(nodenum_t i)
|
||||||
|
{
|
||||||
|
recalc.list[recalc.count++] = i;
|
||||||
|
recalc.bitmap[i>>5] |= 1 << (i & 31);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline BOOL
|
||||||
|
recalclist_contains(nodenum_t el)
|
||||||
{
|
{
|
||||||
return (recalc.bitmap[el>>5] >> (el & 31)) & 1;
|
return (recalc.bitmap[el>>5] >> (el & 31)) & 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
count_t
|
||||||
|
currentlist_count()
|
||||||
|
{
|
||||||
|
return current.count;
|
||||||
|
}
|
||||||
|
|
||||||
|
nodenum_t
|
||||||
|
currentlist_get(count_t i)
|
||||||
|
{
|
||||||
|
return current.list[i];
|
||||||
|
}
|
||||||
|
|
||||||
/************************************************************
|
/************************************************************
|
||||||
*
|
*
|
||||||
* Data Structures and Algorithms for Groups of Nodes
|
* Data Structures and Algorithms for Groups of Nodes
|
||||||
@@ -217,12 +266,11 @@ addRecalcNode(nodenum_t nn)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
/* we already know about this node */
|
/* we already know about this node */
|
||||||
if (recalcListContains(nn))
|
if (recalclist_contains(nn))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* add node to list */
|
/* add node to list */
|
||||||
recalc.list[recalc.count++] = nn;
|
recalclist_add(nn);
|
||||||
recalc.bitmap[nn>>5] |= 1 << (nn & 31);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -301,30 +349,13 @@ recalcNode(nodenum_t node)
|
|||||||
* at least be able to hold NODES elements!
|
* at least be able to hold NODES elements!
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
recalcNodeList(nodenum_t *list, count_t count)
|
recalcNodeList()
|
||||||
{
|
{
|
||||||
/* storage for secondary list and two sets of bitmaps */
|
|
||||||
nodenum_t list1[NODES];
|
|
||||||
int bitmap1[NODES/sizeof(int)+1];
|
|
||||||
int bitmap2[NODES/sizeof(int)+1];
|
|
||||||
|
|
||||||
/* the nodes we are working with */
|
|
||||||
list_t current;
|
|
||||||
current.list = list;
|
|
||||||
current.count = count;
|
|
||||||
current.bitmap = bitmap2;
|
|
||||||
|
|
||||||
/* the nodes we are collecting for the next run */
|
|
||||||
recalc.list = list1;
|
|
||||||
recalc.bitmap = bitmap1;
|
|
||||||
|
|
||||||
for (int j = 0; j < 100; j++) { // loop limiter
|
for (int j = 0; j < 100; j++) { // loop limiter
|
||||||
if (!current.count)
|
if (!current.count)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* clear secondary list */
|
recalclist_init();
|
||||||
bzero(recalc.bitmap, sizeof(*recalc.bitmap)*NODES/sizeof(int));
|
|
||||||
recalc.count = 0;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* for all nodes, follow their paths through
|
* for all nodes, follow their paths through
|
||||||
@@ -333,8 +364,8 @@ recalcNodeList(nodenum_t *list, count_t count)
|
|||||||
* all transistors controlled by this path, collecting
|
* all transistors controlled by this path, collecting
|
||||||
* all nodes that changed because of it for the next run
|
* all nodes that changed because of it for the next run
|
||||||
*/
|
*/
|
||||||
for (count_t i = 0; i < current.count; i++)
|
for (count_t i = 0; i < currentlist_count(); i++)
|
||||||
recalcNode(current.list[i]);
|
recalcNode(currentlist_get(i));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* make the secondary list our primary list, use
|
* make the secondary list our primary list, use
|
||||||
@@ -350,10 +381,10 @@ recalcNodeList(nodenum_t *list, count_t count)
|
|||||||
void
|
void
|
||||||
recalcAllNodes()
|
recalcAllNodes()
|
||||||
{
|
{
|
||||||
nodenum_t list[NODES];
|
|
||||||
for (count_t i = 0; i < NODES; i++)
|
for (count_t i = 0; i < NODES; i++)
|
||||||
list[i] = i;
|
current.list[i] = i;
|
||||||
recalcNodeList(list, NODES);
|
current.count = NODES;
|
||||||
|
recalcNodeList();
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
@@ -361,9 +392,9 @@ setNode(nodenum_t nn, BOOL state)
|
|||||||
{
|
{
|
||||||
nodes_pullup[nn] = state;
|
nodes_pullup[nn] = state;
|
||||||
nodes_pulldown[nn] = !state;
|
nodes_pulldown[nn] = !state;
|
||||||
nodenum_t list[NODES];
|
current.list[0] = nn;
|
||||||
list[0] = nn;
|
current.count = 1;
|
||||||
recalcNodeList(list, 1);
|
recalcNodeList();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -398,9 +429,9 @@ writeDataBus(uint8_t x)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* recalc all nodes connected starting from the data bus */
|
/* recalc all nodes connected starting from the data bus */
|
||||||
nodenum_t list[NODES];
|
bcopy(dbnodes, current.list, sizeof(dbnodes));
|
||||||
bcopy(dbnodes, list, sizeof(dbnodes));
|
current.count = 8;
|
||||||
recalcNodeList(list, 8);
|
recalcNodeList();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t mRead(uint16_t a)
|
uint8_t mRead(uint16_t a)
|
||||||
|
Reference in New Issue
Block a user