mirror of
https://github.com/mist64/perfect6502.git
synced 2025-01-29 14:30:04 +00:00
some C
This commit is contained in:
parent
dbd2f0484f
commit
88b9cb9b75
@ -20,7 +20,7 @@
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
var ctrace = true;
|
||||
var ctrace = false;
|
||||
var loglevel = 3;
|
||||
|
||||
function recalcNodeList(list){
|
||||
|
13
js/macros.js
13
js/macros.js
@ -54,6 +54,19 @@ function initChip(){
|
||||
setHigh('rdy'); setLow('so');
|
||||
setHigh('irq'); setHigh('nmi');
|
||||
recalcNodeList(allNodes());
|
||||
|
||||
var string = '';
|
||||
for (var i in nodes) {
|
||||
string += ' '+nodes[i].pullup;
|
||||
}
|
||||
console.log(string);
|
||||
|
||||
string = '';
|
||||
for (var i in transistors) {
|
||||
string += ' '+transistors[i].on;
|
||||
}
|
||||
console.log(string);
|
||||
|
||||
for(var i=0;i<8;i++){setHigh('clk0'), setLow('clk0');}
|
||||
setHigh('res');
|
||||
for(var i=0;i<18;i++){halfStep();}
|
||||
|
209
nodenames.h
Normal file
209
nodenames.h
Normal file
@ -0,0 +1,209 @@
|
||||
/*
|
||||
Copyright (c) 2010 Brian Silverman, Barry Silverman
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions =
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
enum {
|
||||
db1 = 82,
|
||||
db0 = 1005,
|
||||
db3 = 650,
|
||||
db2 = 945,
|
||||
db5 = 175,
|
||||
db4 = 1393,
|
||||
db7 = 1349,
|
||||
db6 = 1591,
|
||||
idl0 = 116,
|
||||
idl1 = 576,
|
||||
idl2 = 1485,
|
||||
idl3 = 1284,
|
||||
idl4 = 1516,
|
||||
idl5 = 498,
|
||||
idl6 = 1537,
|
||||
idl7 = 529,
|
||||
a1 = 1234,
|
||||
ab1 = 451,
|
||||
ab2 = 1340,
|
||||
a2 = 978,
|
||||
s2 = 81,
|
||||
a5 = 858,
|
||||
a4 = 727,
|
||||
a7 = 1653,
|
||||
a6 = 1136,
|
||||
so = 1672,
|
||||
sync = 539,
|
||||
vcc = 657,
|
||||
clk1out = 1163,
|
||||
p2 = 1421,
|
||||
p3 = 439,
|
||||
p0 = 687,
|
||||
p1 = 1444,
|
||||
p6 = 77,
|
||||
p7 = 1370,
|
||||
p4 = 1119,
|
||||
p5 = 0,
|
||||
pcl3 = 1359,
|
||||
pcl2 = 655,
|
||||
pcl1 = 1022,
|
||||
pcl0 = 1139,
|
||||
pcl7 = 1611,
|
||||
pcl6 = 377,
|
||||
pcl5 = 622,
|
||||
pcl4 = 900,
|
||||
clk0 = 1171,
|
||||
s3 = 1532,
|
||||
res = 159,
|
||||
s1 = 183,
|
||||
s0 = 1403,
|
||||
s7 = 1435,
|
||||
s6 = 1212,
|
||||
s5 = 1098,
|
||||
s4 = 1702,
|
||||
nots0 = 418,
|
||||
nots1 = 1064,
|
||||
nots2 = 752,
|
||||
nots3 = 828,
|
||||
nots4 = 1603,
|
||||
nots5 = 601,
|
||||
nots6 = 1029,
|
||||
nots7 = 181,
|
||||
rw = 1156,
|
||||
x2 = 1,
|
||||
x3 = 1648,
|
||||
x0 = 1216,
|
||||
x1 = 98,
|
||||
x6 = 448,
|
||||
x7 = 777,
|
||||
x4 = 85,
|
||||
x5 = 589,
|
||||
rdy = 89,
|
||||
clk2out = 421,
|
||||
nmi = 1297,
|
||||
ab12 = 1237,
|
||||
ab13 = 349,
|
||||
ab10 = 1443,
|
||||
ab11 = 399,
|
||||
ab14 = 672,
|
||||
ab15 = 195,
|
||||
ab0 = 268,
|
||||
a0 = 737,
|
||||
a3 = 162,
|
||||
ab3 = 211,
|
||||
ab4 = 435,
|
||||
ab5 = 736,
|
||||
ab6 = 887,
|
||||
ab7 = 1493,
|
||||
ab8 = 230,
|
||||
ab9 = 148,
|
||||
pch7 = 205,
|
||||
pch6 = 1551,
|
||||
pch5 = 49,
|
||||
pch4 = 948,
|
||||
pch3 = 584,
|
||||
pch2 = 502,
|
||||
pch1 = 292,
|
||||
pch0 = 1670,
|
||||
irq = 103,
|
||||
vss = 558,
|
||||
y1 = 1148,
|
||||
y0 = 64,
|
||||
y3 = 305,
|
||||
y2 = 573,
|
||||
y5 = 615,
|
||||
y4 = 989,
|
||||
y7 = 843,
|
||||
y6 = 115,
|
||||
cclk = 943, // aka cp2
|
||||
clock1 = 156,
|
||||
clock2 = 1536,
|
||||
notir7 = 1320,
|
||||
notir6 = 895, // OK
|
||||
notir5 = 1394, // OK
|
||||
notir4 = 26,
|
||||
notir3 = 1125,
|
||||
notir2 = 1182,
|
||||
notir1 = 702,
|
||||
notir0 = 194,
|
||||
t2 = 971,
|
||||
t3 = 1567,
|
||||
t4 = 690,
|
||||
t5 = 909,
|
||||
cp1 = 710,
|
||||
fetch = 879,
|
||||
clearIR = 1077,
|
||||
D1x1 = 827,
|
||||
notRdy0 = 248,
|
||||
alu0 = 394,
|
||||
alu1 = 697,
|
||||
alu2 = 276,
|
||||
alu3 = 495,
|
||||
alu4 = 1490,
|
||||
alu5 = 893,
|
||||
alu6 = 68,
|
||||
alu7 = 1123,
|
||||
adl0 = 413,
|
||||
adl1 = 1282,
|
||||
adl2 = 1242,
|
||||
adl3 = 684,
|
||||
adl4 = 1437,
|
||||
adl5 = 1630,
|
||||
adl6 = 121,
|
||||
adl7 = 1299,
|
||||
adh0 = 407,
|
||||
adh1 = 52,
|
||||
adh2 = 1651,
|
||||
adh3 = 315,
|
||||
adh4 = 1160,
|
||||
adh5 = 483,
|
||||
adh6 = 13,
|
||||
adh7 = 1539,
|
||||
sb0 = 54,
|
||||
sb1 = 1150,
|
||||
sb2 = 1287,
|
||||
sb3 = 1188,
|
||||
sb4 = 1405,
|
||||
sb5 = 166,
|
||||
sb6 = 1336,
|
||||
sb7 = 1001,
|
||||
idb0 = 1108,
|
||||
idb1 = 991,
|
||||
idb2 = 1473,
|
||||
idb3 = 1302,
|
||||
idb4 = 892,
|
||||
idb5 = 1503,
|
||||
idb6 = 833,
|
||||
idb7 = 493,
|
||||
dor0 = 222,
|
||||
dor1 = 527,
|
||||
dor2 = 1288,
|
||||
dor3 = 823,
|
||||
dor4 = 873,
|
||||
dor5 = 1266,
|
||||
dor6 = 1418,
|
||||
dor7 = 158,
|
||||
pd0 = 758,
|
||||
pd1 = 361,
|
||||
pd2 = 955,
|
||||
pd3 = 894,
|
||||
pd4 = 369,
|
||||
pd5 = 829,
|
||||
pd6 = 1669,
|
||||
pd7 = 1690,
|
||||
h1x1 = 1042 // drive status byte onto databus
|
||||
};
|
344
perfect6502.c
Normal file
344
perfect6502.c
Normal file
@ -0,0 +1,344 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
typedef unsigned char uint8_t;
|
||||
typedef int BOOL;
|
||||
|
||||
#define NO 0
|
||||
#define YES 1
|
||||
|
||||
#include "segdefs.h"
|
||||
#include "transdefs.h"
|
||||
#include "nodenames.h"
|
||||
|
||||
#define ngnd vss
|
||||
#define npwr vcc
|
||||
|
||||
uint8_t code[] = { 0xa9, 0x00, 0x20, 0x10, 0x00, 0x4c, 0x02, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0xe8, 0x88, 0xe6, 0x40, 0x38, 0x69, 0x02, 0x60 };
|
||||
|
||||
enum {
|
||||
STATE_UNDEFINED,
|
||||
STATE_GND,
|
||||
STATE_VCC,
|
||||
STATE_FL,
|
||||
STATE_FH,
|
||||
STATE_PD,
|
||||
STATE_PU
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
BOOL pullup;
|
||||
BOOL pulldown;
|
||||
int state;
|
||||
int gates[50];
|
||||
int c1c2s[50];
|
||||
int gatecount;
|
||||
int c1c2count;
|
||||
} node_t;
|
||||
|
||||
node_t nodes[1725];
|
||||
|
||||
#define EMPTY -1
|
||||
|
||||
struct {
|
||||
int name;
|
||||
BOOL on;
|
||||
int gate;
|
||||
int c1;
|
||||
int c2;
|
||||
} transistors[3510];
|
||||
|
||||
uint8_t memory[65536];
|
||||
int cycle;
|
||||
|
||||
void
|
||||
setupNodes()
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < sizeof(segdefs)/sizeof(*segdefs); i++) {
|
||||
nodes[i].pullup = segdefs[i];
|
||||
nodes[i].state = STATE_FL;
|
||||
nodes[i].gatecount = 0;
|
||||
nodes[i].c1c2count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
setupTransistors()
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < sizeof(transdefs)/sizeof(*transdefs); i++) {
|
||||
int gate = transdefs[i].gate;
|
||||
int c1 = transdefs[i].c1;
|
||||
int c2 = transdefs[i].c2;
|
||||
transistors[i].name = i;
|
||||
transistors[i].on = NO;
|
||||
transistors[i].gate = gate;
|
||||
transistors[i].c1 = c1;
|
||||
transistors[i].c2 = c2;
|
||||
nodes[gate].gates[nodes[gate].gatecount++] = i;
|
||||
nodes[c1].c1c2s[nodes[c1].c1c2count++] = i;
|
||||
nodes[c2].c1c2s[nodes[c2].c1c2count++] = i;
|
||||
}
|
||||
}
|
||||
|
||||
BOOL
|
||||
arrayContains(int *arr, int count, int el)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < count; i++) {
|
||||
if (arr[i] == el)
|
||||
return YES;
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
void addNodeToGroup(int i, int *group, int *groupcount);
|
||||
|
||||
void
|
||||
addNodeTransistor(int node, int t, int *group, int *groupcount)
|
||||
{
|
||||
if (!transistors[t].on)
|
||||
return;
|
||||
int other;
|
||||
if (transistors[t].c1 == node)
|
||||
other = transistors[t].c2;
|
||||
if (transistors[t].c2 == node)
|
||||
other = transistors[t].c1;
|
||||
addNodeToGroup(other, group, groupcount);
|
||||
}
|
||||
|
||||
void
|
||||
addNodeToGroup(int i, int *group, int *groupcount)
|
||||
{
|
||||
if (arrayContains(group, *groupcount, i))
|
||||
return;
|
||||
group[*groupcount++] = i;
|
||||
if (i == ngnd)
|
||||
return;
|
||||
if (i == npwr)
|
||||
return;
|
||||
int t;
|
||||
for (t = 0; t < nodes[i].c1c2count; t++)
|
||||
addNodeTransistor(i, nodes[i].c1c2s[t], group, groupcount);
|
||||
}
|
||||
|
||||
int
|
||||
getNodeValue(int *group, int groupcount)
|
||||
{
|
||||
if (arrayContains(group, groupcount, ngnd))
|
||||
return STATE_GND;
|
||||
if (arrayContains(group, groupcount, npwr))
|
||||
return STATE_VCC;
|
||||
int flstate;
|
||||
int i;
|
||||
for (i = 0; i < groupcount; i++) {
|
||||
int nn = group[i];
|
||||
node_t n = nodes[nn];
|
||||
if (n.pullup)
|
||||
return STATE_PU;
|
||||
if (n.pulldown)
|
||||
return STATE_PD;
|
||||
if ((n.state == STATE_FL) && (flstate == STATE_UNDEFINED))
|
||||
flstate = STATE_FL;
|
||||
if (n.state== STATE_FH)
|
||||
flstate = STATE_FH;
|
||||
}
|
||||
return flstate;
|
||||
}
|
||||
|
||||
void
|
||||
recalcNode(int node, int *recalclist, int *recalccount)
|
||||
{
|
||||
if (node == ngnd)
|
||||
return;
|
||||
if (node == npwr)
|
||||
return;
|
||||
|
||||
int *group = malloc(1000);
|
||||
int groupcount = 0;
|
||||
addNodeToGroup(node, group, &groupcount);
|
||||
|
||||
|
||||
#if 0
|
||||
var newv = getNodeValue(group);
|
||||
if(ctrace) console.log('recalc', node, group);
|
||||
for(var i in group){
|
||||
var n = nodes[group[i]];
|
||||
if(n.state!=newv && ctrace) console.log(group[i], n.state, newv);
|
||||
n.state = newv;
|
||||
for(var t in n.gates) recalcTransistor(n.gates[t], recalclist);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
recalcNodeList(int *list, int count)
|
||||
{
|
||||
int recalclist[1000];
|
||||
int recalccount = 0;
|
||||
int i, j;
|
||||
for (j = 0; j < 100; j++) { // loop limiter
|
||||
if (!count)
|
||||
return;
|
||||
for (i = 0; i < count; i++)
|
||||
recalcNode(list[i], recalclist, &recalccount);
|
||||
for (i = 0; i < recalccount; i++)
|
||||
list[i] = recalclist[i];
|
||||
count = recalccount;
|
||||
recalccount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
recalcListOfOne(int nn)
|
||||
{
|
||||
printf("TODO %s\n", __func__);
|
||||
}
|
||||
|
||||
void
|
||||
recalcAllNodes()
|
||||
{
|
||||
printf("TODO %s\n", __func__);
|
||||
}
|
||||
|
||||
void
|
||||
setLow(int nn)
|
||||
{
|
||||
nodes[nn].pullup = NO;
|
||||
nodes[nn].pulldown = YES;
|
||||
recalcListOfOne(nn);
|
||||
}
|
||||
|
||||
void
|
||||
setHigh(int nn)
|
||||
{
|
||||
nodes[nn].pullup = YES;
|
||||
nodes[nn].pulldown = NO;
|
||||
recalcListOfOne(nn);
|
||||
}
|
||||
|
||||
BOOL
|
||||
isNodeHigh(int node)
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
void
|
||||
handleBusRead()
|
||||
{
|
||||
printf("TODO %s\n", __func__);
|
||||
}
|
||||
|
||||
void
|
||||
handleBusWrite()
|
||||
{
|
||||
printf("TODO %s\n", __func__);
|
||||
}
|
||||
|
||||
void
|
||||
chipStatus()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
halfStep()
|
||||
{
|
||||
if (isNodeHigh(clk0)) {
|
||||
setLow(clk0);
|
||||
handleBusRead();
|
||||
} else {
|
||||
setHigh(clk0);
|
||||
handleBusWrite();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
initChip()
|
||||
{
|
||||
int nn;
|
||||
for (nn = 0; nn < sizeof(nodes)/sizeof(*nodes); nn++)
|
||||
nodes[nn].state = STATE_FL;
|
||||
nodes[ngnd].state = STATE_GND;
|
||||
nodes[npwr].state = STATE_VCC;
|
||||
int tn;
|
||||
for (tn = 0; tn < sizeof(transistors)/sizeof(*transistors); tn++)
|
||||
transistors[tn].on = NO;
|
||||
setLow(res);
|
||||
setLow(clk0);
|
||||
setHigh(rdy);
|
||||
setLow(so);
|
||||
setHigh(irq);
|
||||
setHigh(nmi);
|
||||
recalcAllNodes();
|
||||
|
||||
#if 0
|
||||
var string = '';
|
||||
for (var i in nodes) {
|
||||
string += ' '+nodes[i].pullup;
|
||||
}
|
||||
console.log(string);
|
||||
|
||||
string = '';
|
||||
for (var i in transistors) {
|
||||
string += ' '+transistors[i].on;
|
||||
}
|
||||
console.log(string);
|
||||
#endif
|
||||
|
||||
int i;
|
||||
for (i = 0; i < 8; i++) {
|
||||
setHigh(clk0);
|
||||
setLow(clk0);
|
||||
}
|
||||
setHigh(res);
|
||||
for (i = 0; i < 18; i++)
|
||||
halfStep();
|
||||
cycle = 0;
|
||||
// chipStatus();
|
||||
}
|
||||
|
||||
void
|
||||
step()
|
||||
{
|
||||
printf("%s\n", __func__);
|
||||
halfStep();
|
||||
cycle++;
|
||||
chipStatus();
|
||||
}
|
||||
|
||||
void
|
||||
steps()
|
||||
{
|
||||
for (;;)
|
||||
step();
|
||||
}
|
||||
|
||||
void
|
||||
go(n)
|
||||
{
|
||||
memcpy(memory, code, sizeof(code));
|
||||
code[0xfffc] = 0x00;
|
||||
code[0xfffd] = 0x00;
|
||||
steps();
|
||||
}
|
||||
|
||||
void
|
||||
setup()
|
||||
{
|
||||
setupNodes();
|
||||
setupTransistors();
|
||||
initChip();
|
||||
go();
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
setup();
|
||||
return 0;
|
||||
}
|
3527
transdefs.h
Normal file
3527
transdefs.h
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user