Skip to content

Commit 48e5756

Browse files
committed
cleanup
1 parent 8d948b5 commit 48e5756

File tree

3 files changed

+76
-74
lines changed

3 files changed

+76
-74
lines changed

cbmbasic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ main()
1919
if (clk)
2020
handle_monitor();
2121

22-
// chipStatus();
22+
// chipStatus();
2323
//if (!(cycle % 1000)) printf("%d\n", cycle);
2424
};
2525
}

nodenames.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ a4 = 727,
4747
a7 = 1653,
4848
a6 = 1136,
4949
so = 1672,
50-
sync = 539,
50+
sync_ = 539,
5151
vcc = 657,
5252
clk1out = 1163,
5353
p2 = 1421,

perfect6502.c

Lines changed: 74 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
#include <stdlib.h>
3333
#include <string.h>
3434

35+
#include <dispatch/dispatch.h>
36+
3537
#include "perfect6502.h"
3638

3739
typedef unsigned char uint8_t;
@@ -181,6 +183,10 @@ nodenum_t transistors_c1[TRANSISTORS];
181183
nodenum_t transistors_c2[TRANSISTORS];
182184
DECLARE_BITMAP(transistors_on, TRANSISTORS);
183185

186+
#ifdef BROKEN_TRANSISTORS
187+
unsigned int broken_transistor = (unsigned int)-1;
188+
#endif
189+
184190
static inline void
185191
set_transistors_on(transnum_t t, BOOL state)
186192
{
@@ -215,7 +221,7 @@ list_t listin = {
215221
.list = list1,
216222
};
217223

218-
/* the nodes we are collecting for the next run */
224+
/* the indirect nodes we are collecting for the next run */
219225
nodenum_t list2[NODES];
220226
list_t listout = {
221227
.list = list2,
@@ -302,28 +308,6 @@ group_count()
302308
return groupcount;
303309
}
304310

305-
/************************************************************
306-
*
307-
* Node State
308-
*
309-
************************************************************/
310-
311-
void recalcNodeList(const nodenum_t *source, count_t count);
312-
313-
static inline void
314-
setNode(nodenum_t nn, BOOL state)
315-
{
316-
set_nodes_pullup(nn, state);
317-
set_nodes_pulldown(nn, !state);
318-
recalcNodeList(&nn, 1);
319-
}
320-
321-
static inline BOOL
322-
isNodeHigh(nodenum_t nn)
323-
{
324-
return get_nodes_value(nn);
325-
}
326-
327311
/************************************************************
328312
*
329313
* Node and Transistor Emulation
@@ -334,7 +318,7 @@ BOOL group_contains_pullup;
334318
BOOL group_contains_pulldown;
335319
BOOL group_contains_hi;
336320

337-
void
321+
static void
338322
addNodeToGroup(nodenum_t n)
339323
{
340324
if (group_contains(n))
@@ -396,10 +380,6 @@ getGroupValue()
396380
return group_contains_hi;
397381
}
398382

399-
#ifdef BROKEN_TRANSISTORS
400-
unsigned int broken_transistor = (unsigned int)-1;
401-
#endif
402-
403383
void
404384
recalcNode(nodenum_t node)
405385
{
@@ -433,17 +413,9 @@ printf(" %s node %d -> ", __func__, node);
433413
transnum_t tn = nodes_gates[nn][t];
434414
set_transistors_on(tn, !get_transistors_on(tn));
435415
}
436-
#if 0
437-
for (count_t g = 0; g < nodes_dependants[nn]; g++)
438-
listout_add(nodes_dependant[nn][g]);
439-
#else
440416
listout_add(nn);
441-
#endif
442417
}
443418
}
444-
#ifdef DEBUG
445-
printf("(%d)\n", listout.count);
446-
#endif
447419
}
448420

449421
void
@@ -474,9 +446,20 @@ recalcNodeList(const nodenum_t *source, count_t count)
474446
*/
475447
for (count_t i = 0; i < listin_count(); i++) {
476448
nodenum_t n = listin_get(i);
449+
#ifdef DEBUG
450+
printf("libdispatch %d times\n", nodes_dependants[n]);
451+
#endif
452+
#if 1
477453
for (count_t g = 0; g < nodes_dependants[n]; g++) {
454+
#else
455+
dispatch_apply(nodes_dependants[n], dispatch_get_global_queue(0, 0), ^(size_t g) {
456+
#endif
478457
recalcNode(nodes_dependant[n][g]);
479458
}
459+
#if 1
460+
#else
461+
);
462+
#endif
480463
}
481464
/*
482465
* make the secondary list our primary list, use
@@ -498,32 +481,30 @@ recalcAllNodes()
498481

499482
/************************************************************
500483
*
501-
* Address Bus and Data Bus Interface
484+
* Node State
502485
*
503486
************************************************************/
504487

505-
uint8_t memory[65536];
506-
507-
/* the nodes that make the data bus */
508-
const nodenum_t dbnodes[8] = { db0, db1, db2, db3, db4, db5, db6, db7 };
509-
510-
void
511-
writeDataBus(uint8_t d)
488+
static inline void
489+
setNode(nodenum_t nn, BOOL state)
512490
{
513-
for (int i = 0; i < 8; i++) {
514-
setNode(dbnodes[i], d & 1);
515-
d >>= 1;
516-
}
517-
518-
/* recalc all nodes connected starting from the data bus */
519-
recalcNodeList(dbnodes, 8);
491+
set_nodes_pullup(nn, state);
492+
set_nodes_pulldown(nn, !state);
493+
recalcNodeList(&nn, 1);
520494
}
521495

522-
uint8_t mRead(uint16_t a)
496+
static inline BOOL
497+
isNodeHigh(nodenum_t nn)
523498
{
524-
return memory[a];
499+
return get_nodes_value(nn);
525500
}
526501

502+
/************************************************************
503+
*
504+
* Interfacing and Extracting State
505+
*
506+
************************************************************/
507+
527508
#define read8(n0,n1,n2,n3,n4,n5,n6,n7) ((uint8_t)(isNodeHigh(n0) << 0) | (isNodeHigh(n1) << 1) | (isNodeHigh(n2) << 2) | (isNodeHigh(n3) << 3) | (isNodeHigh(n4) << 4) | (isNodeHigh(n5) << 5) | (isNodeHigh(n6) << 6) | (isNodeHigh(n7) << 7))
528509

529510
uint16_t
@@ -539,26 +520,19 @@ readDataBus()
539520
}
540521

541522
void
542-
mWrite(uint16_t a, uint8_t d)
523+
writeDataBus(uint8_t d)
543524
{
544-
memory[a] = d;
525+
static const nodenum_t dbnodes[8] = { db0, db1, db2, db3, db4, db5, db6, db7 };
526+
for (int i = 0; i < 8; i++, d>>=1)
527+
setNode(dbnodes[i], d & 1);
545528
}
546529

547-
static inline void
548-
handleMemory()
530+
BOOL
531+
readRW()
549532
{
550-
if (isNodeHigh(rw))
551-
writeDataBus(mRead(readAddressBus()));
552-
else
553-
mWrite(readAddressBus(), readDataBus());
533+
return isNodeHigh(rw);
554534
}
555535

556-
/************************************************************
557-
*
558-
* Tracing/Debugging
559-
*
560-
************************************************************/
561-
562536
uint8_t
563537
readA()
564538
{
@@ -613,11 +587,11 @@ readPC()
613587
return (readPCH() << 8) | readPCL();
614588
}
615589

616-
BOOL
617-
readRW()
618-
{
619-
return isNodeHigh(rw);
620-
}
590+
/************************************************************
591+
*
592+
* Tracing/Debugging
593+
*
594+
************************************************************/
621595

622596
unsigned int cycle;
623597

@@ -651,6 +625,34 @@ chipStatus()
651625
printf("\n");
652626
}
653627

628+
/************************************************************
629+
*
630+
* Address Bus and Data Bus Interface
631+
*
632+
************************************************************/
633+
634+
uint8_t memory[65536];
635+
636+
uint8_t mRead(uint16_t a)
637+
{
638+
return memory[a];
639+
}
640+
641+
void
642+
mWrite(uint16_t a, uint8_t d)
643+
{
644+
memory[a] = d;
645+
}
646+
647+
static inline void
648+
handleMemory()
649+
{
650+
if (isNodeHigh(rw))
651+
writeDataBus(mRead(readAddressBus()));
652+
else
653+
mWrite(readAddressBus(), readDataBus());
654+
}
655+
654656
/************************************************************
655657
*
656658
* Main Clock Loop

0 commit comments

Comments
 (0)