32
32
#include <stdlib.h>
33
33
#include <string.h>
34
34
35
+ #include <dispatch/dispatch.h>
36
+
35
37
#include "perfect6502.h"
36
38
37
39
typedef unsigned char uint8_t ;
@@ -181,6 +183,10 @@ nodenum_t transistors_c1[TRANSISTORS];
181
183
nodenum_t transistors_c2 [TRANSISTORS ];
182
184
DECLARE_BITMAP (transistors_on , TRANSISTORS );
183
185
186
+ #ifdef BROKEN_TRANSISTORS
187
+ unsigned int broken_transistor = (unsigned int )-1 ;
188
+ #endif
189
+
184
190
static inline void
185
191
set_transistors_on (transnum_t t , BOOL state )
186
192
{
@@ -215,7 +221,7 @@ list_t listin = {
215
221
.list = list1 ,
216
222
};
217
223
218
- /* the nodes we are collecting for the next run */
224
+ /* the indirect nodes we are collecting for the next run */
219
225
nodenum_t list2 [NODES ];
220
226
list_t listout = {
221
227
.list = list2 ,
@@ -302,28 +308,6 @@ group_count()
302
308
return groupcount ;
303
309
}
304
310
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
-
327
311
/************************************************************
328
312
*
329
313
* Node and Transistor Emulation
@@ -334,7 +318,7 @@ BOOL group_contains_pullup;
334
318
BOOL group_contains_pulldown ;
335
319
BOOL group_contains_hi ;
336
320
337
- void
321
+ static void
338
322
addNodeToGroup (nodenum_t n )
339
323
{
340
324
if (group_contains (n ))
@@ -396,10 +380,6 @@ getGroupValue()
396
380
return group_contains_hi ;
397
381
}
398
382
399
- #ifdef BROKEN_TRANSISTORS
400
- unsigned int broken_transistor = (unsigned int )-1 ;
401
- #endif
402
-
403
383
void
404
384
recalcNode (nodenum_t node )
405
385
{
@@ -433,17 +413,9 @@ printf(" %s node %d -> ", __func__, node);
433
413
transnum_t tn = nodes_gates [nn ][t ];
434
414
set_transistors_on (tn , !get_transistors_on (tn ));
435
415
}
436
- #if 0
437
- for (count_t g = 0 ; g < nodes_dependants [nn ]; g ++ )
438
- listout_add (nodes_dependant [nn ][g ]);
439
- #else
440
416
listout_add (nn );
441
- #endif
442
417
}
443
418
}
444
- #ifdef DEBUG
445
- printf ("(%d)\n" , listout .count );
446
- #endif
447
419
}
448
420
449
421
void
@@ -474,9 +446,20 @@ recalcNodeList(const nodenum_t *source, count_t count)
474
446
*/
475
447
for (count_t i = 0 ; i < listin_count (); i ++ ) {
476
448
nodenum_t n = listin_get (i );
449
+ #ifdef DEBUG
450
+ printf ("libdispatch %d times\n" , nodes_dependants [n ]);
451
+ #endif
452
+ #if 1
477
453
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
478
457
recalcNode (nodes_dependant [n ][g ]);
479
458
}
459
+ #if 1
460
+ #else
461
+ );
462
+ #endif
480
463
}
481
464
/*
482
465
* make the secondary list our primary list, use
@@ -498,32 +481,30 @@ recalcAllNodes()
498
481
499
482
/************************************************************
500
483
*
501
- * Address Bus and Data Bus Interface
484
+ * Node State
502
485
*
503
486
************************************************************/
504
487
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 )
512
490
{
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 );
520
494
}
521
495
522
- uint8_t mRead (uint16_t a )
496
+ static inline BOOL
497
+ isNodeHigh (nodenum_t nn )
523
498
{
524
- return memory [ a ] ;
499
+ return get_nodes_value ( nn ) ;
525
500
}
526
501
502
+ /************************************************************
503
+ *
504
+ * Interfacing and Extracting State
505
+ *
506
+ ************************************************************/
507
+
527
508
#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))
528
509
529
510
uint16_t
@@ -539,26 +520,19 @@ readDataBus()
539
520
}
540
521
541
522
void
542
- mWrite ( uint16_t a , uint8_t d )
523
+ writeDataBus ( uint8_t d )
543
524
{
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 );
545
528
}
546
529
547
- static inline void
548
- handleMemory ()
530
+ BOOL
531
+ readRW ()
549
532
{
550
- if (isNodeHigh (rw ))
551
- writeDataBus (mRead (readAddressBus ()));
552
- else
553
- mWrite (readAddressBus (), readDataBus ());
533
+ return isNodeHigh (rw );
554
534
}
555
535
556
- /************************************************************
557
- *
558
- * Tracing/Debugging
559
- *
560
- ************************************************************/
561
-
562
536
uint8_t
563
537
readA ()
564
538
{
@@ -613,11 +587,11 @@ readPC()
613
587
return (readPCH () << 8 ) | readPCL ();
614
588
}
615
589
616
- BOOL
617
- readRW ()
618
- {
619
- return isNodeHigh ( rw );
620
- }
590
+ /************************************************************
591
+ *
592
+ * Tracing/Debugging
593
+ *
594
+ ************************************************************/
621
595
622
596
unsigned int cycle ;
623
597
@@ -651,6 +625,34 @@ chipStatus()
651
625
printf ("\n" );
652
626
}
653
627
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
+
654
656
/************************************************************
655
657
*
656
658
* Main Clock Loop
0 commit comments