commit b0b062a2b052f6350facee24779de71408729ee8 Author: kaylee Date: Fri Dec 15 19:43:36 2023 +0000 initial spaghetti code diff --git a/WORKING_SETUP.json b/WORKING_SETUP.json new file mode 100755 index 0000000..d8899f2 --- /dev/null +++ b/WORKING_SETUP.json @@ -0,0 +1 @@ +{"nand":{"image":"img/gates/nand.png","inputs":2,"pins":[0,0,0],"subComponents":[],"wires":[]},"not":{"image":"img/gates/not.png","inputs":1,"pins":[0,0],"subComponents":["nand"],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0}},{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":1}},{"source":{"component":1,"pin":2},"destination":{"component":0,"pin":1}}]},"and":{"image":"img/gates/and.png","inputs":2,"pins":[0,0,0],"subComponents":["nand","nand"],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0}},{"source":{"component":0,"pin":1},"destination":{"component":1,"pin":1}},{"source":{"component":1,"pin":2},"destination":{"component":2,"pin":0}},{"source":{"component":1,"pin":2},"destination":{"component":2,"pin":1}},{"source":{"component":2,"pin":2},"destination":{"component":0,"pin":2}}]},"or":{"image":"img/gates/or.png","inputs":2,"pins":[0,0,0],"subComponents":["nand","nand","nand"],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0}},{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":1}},{"source":{"component":0,"pin":1},"destination":{"component":2,"pin":0}},{"source":{"component":0,"pin":1},"destination":{"component":2,"pin":1}},{"source":{"component":1,"pin":2},"destination":{"component":3,"pin":0}},{"source":{"component":2,"pin":2},"destination":{"component":3,"pin":1}},{"source":{"component":3,"pin":2},"destination":{"component":0,"pin":2}}]},"xor":{"image":"img/gates/xor.png","inputs":2,"pins":[0,0,0],"subComponents":["nand","nand","nand","nand"],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0}},{"source":{"component":0,"pin":1},"destination":{"component":1,"pin":1}},{"source":{"component":0,"pin":0},"destination":{"component":2,"pin":0}},{"source":{"component":1,"pin":2},"destination":{"component":2,"pin":1}},{"source":{"component":1,"pin":2},"destination":{"component":3,"pin":0}},{"source":{"component":0,"pin":1},"destination":{"component":3,"pin":1}},{"source":{"component":2,"pin":2},"destination":{"component":4,"pin":0}},{"source":{"component":3,"pin":2},"destination":{"component":4,"pin":1}},{"source":{"component":4,"pin":2},"destination":{"component":0,"pin":2}}]},"nor":{"inputs":2,"image":"img/gates/nor.png","pins":[0,0,0],"subComponents":["or","not"],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0}},{"source":{"component":0,"pin":1},"destination":{"component":1,"pin":1}},{"source":{"component":1,"pin":2},"destination":{"component":2,"pin":0}},{"source":{"component":2,"pin":1},"destination":{"component":0,"pin":2}}]},"xnor":{"inputs":2,"image":"img/gates/xnor.png","pins":[0,0,0],"subComponents":["xor","not"],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0}},{"source":{"component":0,"pin":1},"destination":{"component":1,"pin":1}},{"source":{"component":1,"pin":2},"destination":{"component":2,"pin":0}},{"source":{"component":2,"pin":1},"destination":{"component":0,"pin":2}}]},"half adder":{"type":"half adder","groups":[[0],[1],[2],[3]],"inputs":2,"tooltips":["A","B","sum","carry"],"pins":[0,0,0,0],"subComponents":["and","xor"],"positions":[{"x":336,"y":269},{"x":556,"y":482}],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0},"wireId":0},{"source":{"component":0,"pin":1},"destination":{"component":1,"pin":1},"wireId":1},{"source":{"component":2,"pin":2},"destination":{"component":0,"pin":2},"wireId":4},{"source":{"component":1,"pin":2},"destination":{"component":0,"pin":3},"wireId":5},{"source":{"component":0,"pin":0},"destination":{"component":2,"pin":0},"wireId":6},{"source":{"component":0,"pin":1},"destination":{"component":2,"pin":1},"wireId":7}]},"full adder":{"type":"full adder","groups":[[0],[1],[2],[3],[4]],"inputs":3,"tooltips":["A","B","carry in","sum","carry out"],"pins":[0,0,0,0,0],"subComponents":["half adder","half adder","or"],"positions":[{"x":337,"y":330},{"x":804,"y":440},{"x":1159,"y":673}],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0},"wireId":0},{"source":{"component":0,"pin":1},"destination":{"component":1,"pin":1},"wireId":1},{"source":{"component":0,"pin":2},"destination":{"component":2,"pin":1},"wireId":4},{"source":{"component":1,"pin":2},"destination":{"component":2,"pin":0},"wireId":5},{"source":{"component":2,"pin":2},"destination":{"component":0,"pin":3},"wireId":6},{"source":{"component":3,"pin":2},"destination":{"component":0,"pin":4},"wireId":7},{"source":{"component":2,"pin":3},"destination":{"component":3,"pin":0},"wireId":9},{"source":{"component":1,"pin":3},"destination":{"component":3,"pin":1},"wireId":10}]},"8 bit ripple carry adder":{"type":"8 bit ripple carry adder","groups":[[0,1,2,3,4,5,6,7],[8,9,10,11,12,13,14,15],[16],[17,18,19,20,21,22,23,24],[25]],"inputs":17,"tooltips":["A","A","A","A","A","A","A","A","B","B","B","B","B","B","B","B","carry in","sum","sum","sum","sum","sum","sum","sum","sum","carry out"],"pins":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"subComponents":["full adder","full adder","full adder","full adder","full adder","full adder","full adder","full adder"],"positions":[{"x":383,"y":351},{"x":352,"y":281},{"x":329,"y":222},{"x":311,"y":155},{"x":476,"y":584},{"x":430,"y":502},{"x":428,"y":423},{"x":301,"y":100}],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":8,"pin":0},"wireId":0},{"source":{"component":0,"pin":8},"destination":{"component":8,"pin":1},"wireId":1},{"source":{"component":0,"pin":1},"destination":{"component":4,"pin":0},"wireId":2},{"source":{"component":0,"pin":9},"destination":{"component":4,"pin":1},"wireId":3},{"source":{"component":0,"pin":2},"destination":{"component":3,"pin":0},"wireId":4},{"source":{"component":0,"pin":10},"destination":{"component":3,"pin":1},"wireId":5},{"source":{"component":0,"pin":3},"destination":{"component":2,"pin":0},"wireId":6},{"source":{"component":0,"pin":11},"destination":{"component":2,"pin":1},"wireId":7},{"source":{"component":0,"pin":4},"destination":{"component":1,"pin":0},"wireId":8},{"source":{"component":0,"pin":12},"destination":{"component":1,"pin":1},"wireId":9},{"source":{"component":0,"pin":5},"destination":{"component":7,"pin":0},"wireId":10},{"source":{"component":0,"pin":13},"destination":{"component":7,"pin":1},"wireId":11},{"source":{"component":0,"pin":14},"destination":{"component":6,"pin":1},"wireId":12},{"source":{"component":0,"pin":6},"destination":{"component":6,"pin":0},"wireId":13},{"source":{"component":0,"pin":7},"destination":{"component":5,"pin":0},"wireId":14},{"source":{"component":0,"pin":15},"destination":{"component":5,"pin":1},"wireId":15},{"source":{"component":5,"pin":4},"destination":{"component":0,"pin":25},"wireId":16},{"source":{"component":5,"pin":3},"destination":{"component":0,"pin":24},"wireId":17},{"source":{"component":6,"pin":3},"destination":{"component":0,"pin":23},"wireId":18},{"source":{"component":7,"pin":3},"destination":{"component":0,"pin":22},"wireId":19},{"source":{"component":1,"pin":3},"destination":{"component":0,"pin":21},"wireId":20},{"source":{"component":2,"pin":3},"destination":{"component":0,"pin":20},"wireId":21},{"source":{"component":3,"pin":3},"destination":{"component":0,"pin":19},"wireId":22},{"source":{"component":4,"pin":3},"destination":{"component":0,"pin":18},"wireId":23},{"source":{"component":8,"pin":3},"destination":{"component":0,"pin":17},"wireId":24},{"source":{"component":8,"pin":4},"destination":{"component":4,"pin":2},"wireId":25},{"source":{"component":4,"pin":4},"destination":{"component":3,"pin":2},"wireId":26},{"source":{"component":3,"pin":4},"destination":{"component":2,"pin":2},"wireId":27},{"source":{"component":2,"pin":4},"destination":{"component":1,"pin":2},"wireId":28},{"source":{"component":1,"pin":4},"destination":{"component":7,"pin":2},"wireId":29},{"source":{"component":7,"pin":4},"destination":{"component":6,"pin":2},"wireId":30},{"source":{"component":6,"pin":4},"destination":{"component":5,"pin":2},"wireId":31},{"source":{"component":0,"pin":16},"destination":{"component":8,"pin":2},"wireId":32}]},"2-1 mux":{"type":"2-1 mux","groups":[[2]],"inputs":3,"tooltips":["A","B","select","output"],"pins":[0,0,0,0],"subComponents":["not","and","and","or"],"positions":[{"x":272,"y":210},{"x":429,"y":281},{"x":445,"y":66},{"x":611,"y":173}],"wires":[{"source":{"component":0,"pin":2},"destination":{"component":1,"pin":0},"wireId":8},{"source":{"component":0,"pin":1},"destination":{"component":2,"pin":0},"wireId":9},{"source":{"component":0,"pin":2},"destination":{"component":2,"pin":1},"wireId":10},{"source":{"component":1,"pin":1},"destination":{"component":3,"pin":1},"wireId":11},{"source":{"component":0,"pin":0},"destination":{"component":3,"pin":0},"wireId":12},{"source":{"component":3,"pin":2},"destination":{"component":4,"pin":0},"wireId":13},{"source":{"component":2,"pin":2},"destination":{"component":4,"pin":1},"wireId":14},{"source":{"component":4,"pin":2},"destination":{"component":0,"pin":3},"wireId":15}]},"16:8 mux":{"type":"16:8 mux","groups":[[0,1,2,3,4,5,6,7],[8,9,10,11,12,13,14,15],[16],[17,18,19,20,21,22,23,24]],"inputs":17,"tooltips":["A","A","A","A","A","A","A","A","B","B","B","B","B","B","B","B","select","output","output","output","output","output","output","output","output"],"pins":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"subComponents":["2-1 mux","2-1 mux","2-1 mux","2-1 mux","2-1 mux","2-1 mux","2-1 mux","2-1 mux"],"positions":[{"x":428,"y":140},{"x":487,"y":225},{"x":549,"y":295},{"x":603,"y":349},{"x":661,"y":427},{"x":690,"y":504},{"x":763,"y":588},{"x":775,"y":659}],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0},"wireId":0},{"source":{"component":0,"pin":8},"destination":{"component":1,"pin":1},"wireId":1},{"source":{"component":0,"pin":9},"destination":{"component":2,"pin":1},"wireId":2},{"source":{"component":0,"pin":1},"destination":{"component":2,"pin":0},"wireId":3},{"source":{"component":0,"pin":2},"destination":{"component":3,"pin":0},"wireId":4},{"source":{"component":0,"pin":10},"destination":{"component":3,"pin":1},"wireId":5},{"source":{"component":0,"pin":3},"destination":{"component":4,"pin":0},"wireId":6},{"source":{"component":0,"pin":11},"destination":{"component":4,"pin":1},"wireId":7},{"source":{"component":0,"pin":4},"destination":{"component":5,"pin":0},"wireId":8},{"source":{"component":0,"pin":12},"destination":{"component":5,"pin":1},"wireId":9},{"source":{"component":0,"pin":5},"destination":{"component":6,"pin":0},"wireId":10},{"source":{"component":0,"pin":13},"destination":{"component":6,"pin":1},"wireId":11},{"source":{"component":0,"pin":6},"destination":{"component":7,"pin":0},"wireId":12},{"source":{"component":0,"pin":14},"destination":{"component":7,"pin":1},"wireId":13},{"source":{"component":0,"pin":7},"destination":{"component":8,"pin":0},"wireId":14},{"source":{"component":0,"pin":15},"destination":{"component":8,"pin":1},"wireId":15},{"source":{"component":0,"pin":16},"destination":{"component":8,"pin":2},"wireId":16},{"source":{"component":0,"pin":16},"destination":{"component":7,"pin":2},"wireId":17},{"source":{"component":0,"pin":16},"destination":{"component":6,"pin":2},"wireId":18},{"source":{"component":0,"pin":16},"destination":{"component":5,"pin":2},"wireId":19},{"source":{"component":0,"pin":16},"destination":{"component":4,"pin":2},"wireId":20},{"source":{"component":0,"pin":16},"destination":{"component":3,"pin":2},"wireId":21},{"source":{"component":0,"pin":16},"destination":{"component":2,"pin":2},"wireId":22},{"source":{"component":0,"pin":16},"destination":{"component":1,"pin":2},"wireId":23},{"source":{"component":1,"pin":3},"destination":{"component":0,"pin":17},"wireId":24},{"source":{"component":2,"pin":3},"destination":{"component":0,"pin":18},"wireId":25},{"source":{"component":3,"pin":3},"destination":{"component":0,"pin":19},"wireId":26},{"source":{"component":4,"pin":3},"destination":{"component":0,"pin":20},"wireId":27},{"source":{"component":5,"pin":3},"destination":{"component":0,"pin":21},"wireId":28},{"source":{"component":6,"pin":3},"destination":{"component":0,"pin":22},"wireId":29},{"source":{"component":7,"pin":3},"destination":{"component":0,"pin":23},"wireId":30},{"source":{"component":8,"pin":3},"destination":{"component":0,"pin":24},"wireId":31}]},"8-bit not":{"type":"8-bit not","groups":[[0,1,2,3,4,5,6,7],[8,9,10,11,12,13,14,15]],"inputs":8,"tooltips":["input","input","input","input","input","input","input","input","output","output","output","output","output","output","output","output"],"pins":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"subComponents":["not","not","not","not","not","not","not","not"],"positions":[{"x":113,"y":635},{"x":134,"y":545},{"x":175,"y":464},{"x":230,"y":363},{"x":175,"y":137},{"x":169,"y":47},{"x":395,"y":411},{"x":381,"y":192}],"wires":[{"source":{"component":0,"pin":7},"destination":{"component":1,"pin":0},"wireId":0},{"source":{"component":0,"pin":6},"destination":{"component":2,"pin":0},"wireId":1},{"source":{"component":0,"pin":5},"destination":{"component":3,"pin":0},"wireId":2},{"source":{"component":0,"pin":4},"destination":{"component":7,"pin":0},"wireId":3},{"source":{"component":0,"pin":3},"destination":{"component":4,"pin":0},"wireId":4},{"source":{"component":0,"pin":2},"destination":{"component":8,"pin":0},"wireId":5},{"source":{"component":0,"pin":1},"destination":{"component":5,"pin":0},"wireId":6},{"source":{"component":0,"pin":0},"destination":{"component":6,"pin":0},"wireId":7},{"source":{"component":6,"pin":1},"destination":{"component":0,"pin":8},"wireId":8},{"source":{"component":5,"pin":1},"destination":{"component":0,"pin":9},"wireId":9},{"source":{"component":8,"pin":1},"destination":{"component":0,"pin":10},"wireId":10},{"source":{"component":4,"pin":1},"destination":{"component":0,"pin":11},"wireId":11},{"source":{"component":7,"pin":1},"destination":{"component":0,"pin":12},"wireId":12},{"source":{"component":3,"pin":1},"destination":{"component":0,"pin":13},"wireId":13},{"source":{"component":2,"pin":1},"destination":{"component":0,"pin":14},"wireId":14},{"source":{"component":1,"pin":1},"destination":{"component":0,"pin":15},"wireId":15}]},"8-bit subtractor":{"type":"8-bit subtractor","groups":[[0,1,2,3,4,5,6,7],[8,9,10,11,12,13,14,15],[16],[17,18,19,20,21,22,23,24],[25]],"inputs":17,"tooltips":["A","A","A","A","A","A","A","A","B","B","B","B","B","B","B","B","borrow in","difference","difference","difference","difference","difference","difference","difference","difference","borrow out"],"pins":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"subComponents":["8 bit ripple carry adder","not","8-bit not","not"],"positions":[{"x":736,"y":333},{"x":251,"y":723},{"x":250,"y":583},{"x":1308,"y":676}],"wires":[{"source":{"component":0,"pin":16},"destination":{"component":2,"pin":0},"wireId":0},{"source":{"component":3,"pin":15},"destination":{"component":1,"pin":15},"wireId":2},{"source":{"component":3,"pin":14},"destination":{"component":1,"pin":14},"wireId":3},{"source":{"component":3,"pin":13},"destination":{"component":1,"pin":13},"wireId":4},{"source":{"component":3,"pin":12},"destination":{"component":1,"pin":12},"wireId":5},{"source":{"component":3,"pin":11},"destination":{"component":1,"pin":11},"wireId":6},{"source":{"component":3,"pin":10},"destination":{"component":1,"pin":10},"wireId":7},{"source":{"component":3,"pin":9},"destination":{"component":1,"pin":9},"wireId":8},{"source":{"component":3,"pin":8},"destination":{"component":1,"pin":8},"wireId":9},{"source":{"component":0,"pin":8},"destination":{"component":3,"pin":0},"wireId":10},{"source":{"component":0,"pin":9},"destination":{"component":3,"pin":1},"wireId":11},{"source":{"component":0,"pin":10},"destination":{"component":3,"pin":2},"wireId":12},{"source":{"component":0,"pin":11},"destination":{"component":3,"pin":3},"wireId":13},{"source":{"component":0,"pin":12},"destination":{"component":3,"pin":4},"wireId":14},{"source":{"component":0,"pin":13},"destination":{"component":3,"pin":5},"wireId":15},{"source":{"component":0,"pin":14},"destination":{"component":3,"pin":6},"wireId":16},{"source":{"component":0,"pin":15},"destination":{"component":3,"pin":7},"wireId":17},{"source":{"component":2,"pin":1},"destination":{"component":1,"pin":16},"wireId":18},{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0},"wireId":19},{"source":{"component":0,"pin":1},"destination":{"component":1,"pin":1},"wireId":20},{"source":{"component":0,"pin":2},"destination":{"component":1,"pin":2},"wireId":21},{"source":{"component":0,"pin":3},"destination":{"component":1,"pin":3},"wireId":22},{"source":{"component":0,"pin":4},"destination":{"component":1,"pin":4},"wireId":23},{"source":{"component":0,"pin":5},"destination":{"component":1,"pin":5},"wireId":24},{"source":{"component":0,"pin":6},"destination":{"component":1,"pin":6},"wireId":25},{"source":{"component":0,"pin":7},"destination":{"component":1,"pin":7},"wireId":26},{"source":{"component":1,"pin":17},"destination":{"component":0,"pin":17},"wireId":27},{"source":{"component":1,"pin":18},"destination":{"component":0,"pin":18},"wireId":28},{"source":{"component":1,"pin":19},"destination":{"component":0,"pin":19},"wireId":29},{"source":{"component":1,"pin":20},"destination":{"component":0,"pin":20},"wireId":30},{"source":{"component":1,"pin":21},"destination":{"component":0,"pin":21},"wireId":31},{"source":{"component":1,"pin":22},"destination":{"component":0,"pin":22},"wireId":32},{"source":{"component":1,"pin":23},"destination":{"component":0,"pin":23},"wireId":33},{"source":{"component":1,"pin":24},"destination":{"component":0,"pin":24},"wireId":34},{"source":{"component":1,"pin":25},"destination":{"component":4,"pin":0},"wireId":35},{"source":{"component":4,"pin":1},"destination":{"component":0,"pin":25},"wireId":36}]},"add/subtract unit":{"type":"add/subtract unit","groups":[[0,1,2,3,4,5,6,7],[8,9,10,11,12,13,14,15],[16],[18,19,20,21,22,23,24,25],[26]],"inputs":18,"tooltips":["A","A","A","A","A","A","A","A","B","B","B","B","B","B","B","B","carry/borrow in","operation select","result","result","result","result","result","result","result","result","carry/borrow out"],"pins":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"subComponents":["8-bit subtractor","8 bit ripple carry adder","16:8 mux","2-1 mux"],"positions":[{"x":795,"y":579},{"x":881,"y":165},{"x":1401,"y":247},{"x":1560,"y":700}],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":2,"pin":0},"wireId":0},{"source":{"component":0,"pin":1},"destination":{"component":2,"pin":1},"wireId":1},{"source":{"component":0,"pin":3},"destination":{"component":2,"pin":3},"wireId":3},{"source":{"component":0,"pin":4},"destination":{"component":2,"pin":4},"wireId":4},{"source":{"component":0,"pin":5},"destination":{"component":2,"pin":5},"wireId":5},{"source":{"component":0,"pin":6},"destination":{"component":2,"pin":6},"wireId":6},{"source":{"component":0,"pin":7},"destination":{"component":2,"pin":7},"wireId":7},{"source":{"component":0,"pin":2},"destination":{"component":2,"pin":2},"wireId":8},{"source":{"component":0,"pin":8},"destination":{"component":2,"pin":8},"wireId":9},{"source":{"component":0,"pin":9},"destination":{"component":2,"pin":9},"wireId":10},{"source":{"component":0,"pin":10},"destination":{"component":2,"pin":10},"wireId":11},{"source":{"component":0,"pin":11},"destination":{"component":2,"pin":11},"wireId":12},{"source":{"component":0,"pin":12},"destination":{"component":2,"pin":12},"wireId":13},{"source":{"component":0,"pin":13},"destination":{"component":2,"pin":13},"wireId":14},{"source":{"component":0,"pin":14},"destination":{"component":2,"pin":14},"wireId":15},{"source":{"component":0,"pin":15},"destination":{"component":2,"pin":15},"wireId":16},{"source":{"component":0,"pin":16},"destination":{"component":2,"pin":16},"wireId":17},{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0},"wireId":18},{"source":{"component":0,"pin":1},"destination":{"component":1,"pin":1},"wireId":19},{"source":{"component":0,"pin":2},"destination":{"component":1,"pin":2},"wireId":20},{"source":{"component":0,"pin":3},"destination":{"component":1,"pin":3},"wireId":21},{"source":{"component":0,"pin":4},"destination":{"component":1,"pin":4},"wireId":22},{"source":{"component":0,"pin":5},"destination":{"component":1,"pin":5},"wireId":23},{"source":{"component":0,"pin":6},"destination":{"component":1,"pin":6},"wireId":24},{"source":{"component":0,"pin":7},"destination":{"component":1,"pin":7},"wireId":25},{"source":{"component":0,"pin":8},"destination":{"component":1,"pin":8},"wireId":26},{"source":{"component":0,"pin":9},"destination":{"component":1,"pin":9},"wireId":27},{"source":{"component":0,"pin":10},"destination":{"component":1,"pin":10},"wireId":28},{"source":{"component":0,"pin":11},"destination":{"component":1,"pin":11},"wireId":29},{"source":{"component":0,"pin":12},"destination":{"component":1,"pin":12},"wireId":30},{"source":{"component":0,"pin":13},"destination":{"component":1,"pin":13},"wireId":31},{"source":{"component":0,"pin":14},"destination":{"component":1,"pin":14},"wireId":32},{"source":{"component":0,"pin":15},"destination":{"component":1,"pin":15},"wireId":33},{"source":{"component":0,"pin":16},"destination":{"component":1,"pin":16},"wireId":34},{"source":{"component":2,"pin":17},"destination":{"component":3,"pin":0},"wireId":35},{"source":{"component":2,"pin":18},"destination":{"component":3,"pin":1},"wireId":36},{"source":{"component":2,"pin":19},"destination":{"component":3,"pin":2},"wireId":37},{"source":{"component":2,"pin":20},"destination":{"component":3,"pin":3},"wireId":38},{"source":{"component":2,"pin":21},"destination":{"component":3,"pin":4},"wireId":39},{"source":{"component":2,"pin":22},"destination":{"component":3,"pin":5},"wireId":40},{"source":{"component":2,"pin":23},"destination":{"component":3,"pin":6},"wireId":41},{"source":{"component":2,"pin":24},"destination":{"component":3,"pin":7},"wireId":42},{"source":{"component":1,"pin":17},"destination":{"component":3,"pin":8},"wireId":44},{"source":{"component":1,"pin":18},"destination":{"component":3,"pin":9},"wireId":45},{"source":{"component":1,"pin":19},"destination":{"component":3,"pin":10},"wireId":46},{"source":{"component":1,"pin":20},"destination":{"component":3,"pin":11},"wireId":47},{"source":{"component":1,"pin":21},"destination":{"component":3,"pin":12},"wireId":48},{"source":{"component":1,"pin":22},"destination":{"component":3,"pin":13},"wireId":49},{"source":{"component":1,"pin":23},"destination":{"component":3,"pin":14},"wireId":50},{"source":{"component":1,"pin":24},"destination":{"component":3,"pin":15},"wireId":51},{"source":{"component":4,"pin":3},"destination":{"component":0,"pin":26},"wireId":52},{"source":{"component":1,"pin":25},"destination":{"component":4,"pin":1},"wireId":53},{"source":{"component":2,"pin":25},"destination":{"component":4,"pin":0},"wireId":54},{"source":{"component":0,"pin":17},"destination":{"component":4,"pin":2},"wireId":56},{"source":{"component":0,"pin":17},"destination":{"component":3,"pin":16},"wireId":57},{"source":{"component":3,"pin":17},"destination":{"component":0,"pin":18},"wireId":58},{"source":{"component":3,"pin":18},"destination":{"component":0,"pin":19},"wireId":59},{"source":{"component":3,"pin":19},"destination":{"component":0,"pin":20},"wireId":60},{"source":{"component":3,"pin":20},"destination":{"component":0,"pin":21},"wireId":61},{"source":{"component":3,"pin":21},"destination":{"component":0,"pin":22},"wireId":62},{"source":{"component":3,"pin":22},"destination":{"component":0,"pin":23},"wireId":63},{"source":{"component":3,"pin":23},"destination":{"component":0,"pin":24},"wireId":64},{"source":{"component":3,"pin":24},"destination":{"component":0,"pin":25},"wireId":65}]},"8-bit nand":{"type":"8-bit nand","groups":[[0,1,2,3,4,5,6,7],[8,9,10,11,12,13,14,15],[16,17,18,19,20,21,22,23]],"inputs":16,"tooltips":["A","A","A","A","A","A","A","A","B","B","B","B","B","B","B","B","output","output","output","output","output","output","output","output"],"pins":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"subComponents":["8-bit not","and","and","and","and","and","and","and","and"],"positions":[{"x":1390,"y":364},{"x":840,"y":712},{"x":419,"y":313},{"x":388,"y":193},{"x":564,"y":630},{"x":511,"y":515},{"x":476,"y":431},{"x":712,"y":802},{"x":1077,"y":782}],"wires":[{"source":{"component":1,"pin":8},"destination":{"component":0,"pin":16},"wireId":0},{"source":{"component":1,"pin":9},"destination":{"component":0,"pin":17},"wireId":1},{"source":{"component":1,"pin":10},"destination":{"component":0,"pin":18},"wireId":2},{"source":{"component":1,"pin":11},"destination":{"component":0,"pin":19},"wireId":3},{"source":{"component":1,"pin":12},"destination":{"component":0,"pin":20},"wireId":4},{"source":{"component":1,"pin":13},"destination":{"component":0,"pin":21},"wireId":5},{"source":{"component":1,"pin":14},"destination":{"component":0,"pin":22},"wireId":6},{"source":{"component":1,"pin":15},"destination":{"component":0,"pin":23},"wireId":7},{"source":{"component":0,"pin":0},"destination":{"component":4,"pin":0},"wireId":13},{"source":{"component":0,"pin":8},"destination":{"component":4,"pin":1},"wireId":14},{"source":{"component":0,"pin":1},"destination":{"component":3,"pin":0},"wireId":15},{"source":{"component":0,"pin":9},"destination":{"component":3,"pin":1},"wireId":16},{"source":{"component":0,"pin":2},"destination":{"component":7,"pin":0},"wireId":17},{"source":{"component":0,"pin":10},"destination":{"component":7,"pin":1},"wireId":18},{"source":{"component":4,"pin":2},"destination":{"component":1,"pin":0},"wireId":19},{"source":{"component":3,"pin":2},"destination":{"component":1,"pin":1},"wireId":20},{"source":{"component":7,"pin":2},"destination":{"component":1,"pin":2},"wireId":21},{"source":{"component":0,"pin":11},"destination":{"component":6,"pin":1},"wireId":22},{"source":{"component":0,"pin":3},"destination":{"component":6,"pin":0},"wireId":23},{"source":{"component":6,"pin":2},"destination":{"component":1,"pin":3},"wireId":24},{"source":{"component":5,"pin":2},"destination":{"component":1,"pin":4},"wireId":25},{"source":{"component":0,"pin":4},"destination":{"component":5,"pin":0},"wireId":26},{"source":{"component":0,"pin":12},"destination":{"component":5,"pin":1},"wireId":27},{"source":{"component":0,"pin":5},"destination":{"component":2,"pin":0},"wireId":28},{"source":{"component":0,"pin":13},"destination":{"component":2,"pin":1},"wireId":29},{"source":{"component":2,"pin":2},"destination":{"component":1,"pin":5},"wireId":30},{"source":{"component":0,"pin":6},"destination":{"component":8,"pin":0},"wireId":31},{"source":{"component":0,"pin":14},"destination":{"component":8,"pin":1},"wireId":32},{"source":{"component":8,"pin":2},"destination":{"component":1,"pin":6},"wireId":33},{"source":{"component":0,"pin":15},"destination":{"component":9,"pin":1},"wireId":34},{"source":{"component":0,"pin":7},"destination":{"component":9,"pin":0},"wireId":35},{"source":{"component":9,"pin":2},"destination":{"component":1,"pin":7},"wireId":36}]},"8-bit xor":{"type":"8-bit xor","groups":[[0,1,2,3,4,5,6,7],[8,9,10,11,12,13,14,15],[16,17,18,19,20,21,22,23]],"inputs":16,"tooltips":["A","A","A","A","A","A","A","A","B","B","B","B","B","B","B","B","output","output","output","output","output","output","output","output"],"pins":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"subComponents":["xor","xor","xor","xor","xor","xor","xor","xor"],"positions":[{"x":470,"y":747},{"x":488,"y":524},{"x":490,"y":626},{"x":490,"y":432},{"x":489,"y":336},{"x":491,"y":217},{"x":484,"y":122},{"x":474,"y":19}],"wires":[{"source":{"component":0,"pin":15},"destination":{"component":1,"pin":1},"wireId":0},{"source":{"component":0,"pin":7},"destination":{"component":1,"pin":0},"wireId":2},{"source":{"component":0,"pin":14},"destination":{"component":3,"pin":1},"wireId":3},{"source":{"component":0,"pin":6},"destination":{"component":3,"pin":0},"wireId":4},{"source":{"component":0,"pin":5},"destination":{"component":2,"pin":0},"wireId":5},{"source":{"component":0,"pin":13},"destination":{"component":2,"pin":1},"wireId":6},{"source":{"component":0,"pin":4},"destination":{"component":4,"pin":0},"wireId":7},{"source":{"component":0,"pin":12},"destination":{"component":4,"pin":1},"wireId":8},{"source":{"component":0,"pin":3},"destination":{"component":5,"pin":0},"wireId":9},{"source":{"component":0,"pin":11},"destination":{"component":5,"pin":1},"wireId":10},{"source":{"component":0,"pin":10},"destination":{"component":6,"pin":1},"wireId":11},{"source":{"component":0,"pin":2},"destination":{"component":6,"pin":0},"wireId":12},{"source":{"component":0,"pin":0},"destination":{"component":8,"pin":0},"wireId":13},{"source":{"component":0,"pin":8},"destination":{"component":8,"pin":1},"wireId":14},{"source":{"component":0,"pin":1},"destination":{"component":7,"pin":0},"wireId":15},{"source":{"component":0,"pin":9},"destination":{"component":7,"pin":1},"wireId":16},{"source":{"component":8,"pin":2},"destination":{"component":0,"pin":16},"wireId":17},{"source":{"component":7,"pin":2},"destination":{"component":0,"pin":17},"wireId":18},{"source":{"component":6,"pin":2},"destination":{"component":0,"pin":18},"wireId":19},{"source":{"component":5,"pin":2},"destination":{"component":0,"pin":19},"wireId":20},{"source":{"component":4,"pin":2},"destination":{"component":0,"pin":20},"wireId":21},{"source":{"component":2,"pin":2},"destination":{"component":0,"pin":21},"wireId":22},{"source":{"component":3,"pin":2},"destination":{"component":0,"pin":22},"wireId":23},{"source":{"component":1,"pin":2},"destination":{"component":0,"pin":23},"wireId":24}]},"left shift":{"type":"left shift","groups":[[0,1,2,3,4,5,6,7],[8,9,10,11,12,13,14,15]],"inputs":8,"tooltips":["input","input","input","input","input","input","input","input","output","output","output","output","output","output","output","output","overflow"],"pins":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"subComponents":[],"positions":[],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":0,"pin":9},"wireId":0},{"source":{"component":0,"pin":1},"destination":{"component":0,"pin":10},"wireId":1},{"source":{"component":0,"pin":2},"destination":{"component":0,"pin":11},"wireId":2},{"source":{"component":0,"pin":3},"destination":{"component":0,"pin":12},"wireId":3},{"source":{"component":0,"pin":4},"destination":{"component":0,"pin":13},"wireId":4},{"source":{"component":0,"pin":5},"destination":{"component":0,"pin":14},"wireId":5},{"source":{"component":0,"pin":6},"destination":{"component":0,"pin":15},"wireId":6},{"source":{"component":0,"pin":7},"destination":{"component":0,"pin":16},"wireId":7}]},"right shift":{"type":"right shift","groups":[[0,1,2,3,4,5,6,7],[9,10,11,12,13,14,15,16]],"inputs":8,"tooltips":["input","input","input","input","input","input","input","input","underflow","output","output","output","output","output","output","output","output"],"pins":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"subComponents":[],"positions":[],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":0,"pin":8},"wireId":0},{"source":{"component":0,"pin":1},"destination":{"component":0,"pin":9},"wireId":1},{"source":{"component":0,"pin":2},"destination":{"component":0,"pin":10},"wireId":2},{"source":{"component":0,"pin":3},"destination":{"component":0,"pin":11},"wireId":3},{"source":{"component":0,"pin":4},"destination":{"component":0,"pin":12},"wireId":4},{"source":{"component":0,"pin":5},"destination":{"component":0,"pin":13},"wireId":5},{"source":{"component":0,"pin":6},"destination":{"component":0,"pin":14},"wireId":6},{"source":{"component":0,"pin":7},"destination":{"component":0,"pin":15},"wireId":7}]},"1:2 demux":{"type":"1:2 demux","groups":[[1]],"inputs":2,"tooltips":["input","select","output A","output B"],"pins":[0,0,0,0],"subComponents":["and","not","and"],"positions":[{"x":1363,"y":603},{"x":1227,"y":400},{"x":1333,"y":278}],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0},"wireId":0},{"source":{"component":0,"pin":1},"destination":{"component":1,"pin":1},"wireId":1},{"source":{"component":1,"pin":2},"destination":{"component":0,"pin":3},"wireId":2},{"source":{"component":0,"pin":1},"destination":{"component":2,"pin":0},"wireId":3},{"source":{"component":2,"pin":1},"destination":{"component":3,"pin":1},"wireId":4},{"source":{"component":0,"pin":0},"destination":{"component":3,"pin":0},"wireId":5},{"source":{"component":3,"pin":2},"destination":{"component":0,"pin":2},"wireId":6}]},"1:8 demux":{"type":"1:8 demux","groups":[[1,2,3]],"inputs":4,"tooltips":["input","select","select","select","output A","output B","output C","output D","output E","output F","output G","output H"],"pins":[0,0,0,0,0,0,0,0,0,0,0,0],"subComponents":["or","or","1:2 demux","1:2 demux","1:2 demux","or","1:2 demux","1:2 demux","or","1:2 demux","1:2 demux"],"positions":[{"x":123,"y":576},{"x":294,"y":377},{"x":488,"y":221},{"x":730,"y":341},{"x":957,"y":422},{"x":710,"y":504},{"x":1203,"y":499},{"x":1458,"y":591},{"x":641,"y":678},{"x":1639,"y":698},{"x":1850,"y":834}],"wires":[{"source":{"component":0,"pin":2},"destination":{"component":1,"pin":0},"wireId":0},{"source":{"component":0,"pin":3},"destination":{"component":1,"pin":1},"wireId":1},{"source":{"component":0,"pin":1},"destination":{"component":2,"pin":0},"wireId":2},{"source":{"component":1,"pin":2},"destination":{"component":2,"pin":1},"wireId":3},{"source":{"component":2,"pin":2},"destination":{"component":3,"pin":1},"wireId":4},{"source":{"component":0,"pin":0},"destination":{"component":3,"pin":0},"wireId":5},{"source":{"component":3,"pin":3},"destination":{"component":4,"pin":0},"wireId":6},{"source":{"component":3,"pin":2},"destination":{"component":0,"pin":4},"wireId":7},{"source":{"component":1,"pin":2},"destination":{"component":4,"pin":1},"wireId":8},{"source":{"component":4,"pin":2},"destination":{"component":0,"pin":5},"wireId":9},{"source":{"component":5,"pin":2},"destination":{"component":0,"pin":6},"wireId":10},{"source":{"component":4,"pin":3},"destination":{"component":5,"pin":0},"wireId":11},{"source":{"component":0,"pin":1},"destination":{"component":6,"pin":0},"wireId":15},{"source":{"component":0,"pin":3},"destination":{"component":6,"pin":1},"wireId":16},{"source":{"component":6,"pin":2},"destination":{"component":5,"pin":1},"wireId":17},{"source":{"component":5,"pin":3},"destination":{"component":7,"pin":0},"wireId":18},{"source":{"component":0,"pin":3},"destination":{"component":7,"pin":1},"wireId":19},{"source":{"component":7,"pin":2},"destination":{"component":0,"pin":7},"wireId":20},{"source":{"component":7,"pin":3},"destination":{"component":8,"pin":0},"wireId":21},{"source":{"component":0,"pin":1},"destination":{"component":9,"pin":0},"wireId":22},{"source":{"component":0,"pin":2},"destination":{"component":9,"pin":1},"wireId":23},{"source":{"component":9,"pin":2},"destination":{"component":8,"pin":1},"wireId":24},{"source":{"component":8,"pin":2},"destination":{"component":0,"pin":8},"wireId":25},{"source":{"component":8,"pin":3},"destination":{"component":10,"pin":0},"wireId":26},{"source":{"component":10,"pin":2},"destination":{"component":0,"pin":9},"wireId":27},{"source":{"component":0,"pin":2},"destination":{"component":10,"pin":1},"wireId":28},{"source":{"component":10,"pin":3},"destination":{"component":11,"pin":0},"wireId":29},{"source":{"component":0,"pin":1},"destination":{"component":11,"pin":1},"wireId":30},{"source":{"component":11,"pin":3},"destination":{"component":0,"pin":11},"wireId":31},{"source":{"component":11,"pin":2},"destination":{"component":0,"pin":10},"wireId":32}]},"8:1 or":{"type":"8:1 or","groups":[[0,1,2,3,4,5,6,7],[8,9,10,11,12,13,14,15]],"inputs":16,"tooltips":["A","A","A","A","A","A","A","A","B","B","B","B","B","B","B","B","output"],"pins":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"subComponents":["or","or","or","or","or","or","or","or","or","or","or","or","or","or","or"],"positions":[{"x":797,"y":125},{"x":755,"y":224},{"x":750,"y":364},{"x":704,"y":485},{"x":649,"y":643},{"x":612,"y":758},{"x":594,"y":861},{"x":534,"y":950},{"x":978,"y":166},{"x":1005,"y":432},{"x":933,"y":640},{"x":922,"y":830},{"x":1372,"y":274},{"x":1252,"y":726},{"x":1594,"y":428}],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0},"wireId":0},{"source":{"component":0,"pin":8},"destination":{"component":1,"pin":1},"wireId":1},{"source":{"component":0,"pin":1},"destination":{"component":2,"pin":0},"wireId":2},{"source":{"component":0,"pin":9},"destination":{"component":2,"pin":1},"wireId":3},{"source":{"component":0,"pin":2},"destination":{"component":3,"pin":0},"wireId":4},{"source":{"component":0,"pin":10},"destination":{"component":3,"pin":1},"wireId":5},{"source":{"component":0,"pin":3},"destination":{"component":4,"pin":0},"wireId":6},{"source":{"component":0,"pin":11},"destination":{"component":4,"pin":1},"wireId":7},{"source":{"component":0,"pin":4},"destination":{"component":5,"pin":0},"wireId":8},{"source":{"component":0,"pin":12},"destination":{"component":5,"pin":1},"wireId":9},{"source":{"component":0,"pin":5},"destination":{"component":6,"pin":0},"wireId":10},{"source":{"component":0,"pin":13},"destination":{"component":6,"pin":1},"wireId":11},{"source":{"component":0,"pin":6},"destination":{"component":7,"pin":0},"wireId":12},{"source":{"component":0,"pin":14},"destination":{"component":7,"pin":1},"wireId":13},{"source":{"component":0,"pin":7},"destination":{"component":8,"pin":0},"wireId":14},{"source":{"component":0,"pin":15},"destination":{"component":8,"pin":1},"wireId":15},{"source":{"component":1,"pin":2},"destination":{"component":9,"pin":0},"wireId":16},{"source":{"component":2,"pin":2},"destination":{"component":9,"pin":1},"wireId":17},{"source":{"component":3,"pin":2},"destination":{"component":10,"pin":0},"wireId":18},{"source":{"component":4,"pin":2},"destination":{"component":10,"pin":1},"wireId":19},{"source":{"component":5,"pin":2},"destination":{"component":11,"pin":0},"wireId":20},{"source":{"component":6,"pin":2},"destination":{"component":11,"pin":1},"wireId":21},{"source":{"component":7,"pin":2},"destination":{"component":12,"pin":0},"wireId":22},{"source":{"component":8,"pin":2},"destination":{"component":12,"pin":1},"wireId":23},{"source":{"component":9,"pin":2},"destination":{"component":13,"pin":0},"wireId":24},{"source":{"component":10,"pin":2},"destination":{"component":13,"pin":1},"wireId":25},{"source":{"component":11,"pin":2},"destination":{"component":14,"pin":0},"wireId":26},{"source":{"component":12,"pin":2},"destination":{"component":14,"pin":1},"wireId":27},{"source":{"component":13,"pin":2},"destination":{"component":15,"pin":0},"wireId":28},{"source":{"component":14,"pin":2},"destination":{"component":15,"pin":1},"wireId":29},{"source":{"component":15,"pin":2},"destination":{"component":0,"pin":16},"wireId":30}]},"shift one":{"type":"shift one","groups":[[0,1,2,3,4,5,6,7],[9,10,11,12,13,14,15,16]],"inputs":9,"tooltips":["input","input","input","input","input","input","input","input","left/right?","output","output","output","output","output","output","output","output"],"pins":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"subComponents":["not","and","and","and","or","or","or","or","or","or","and","and","and","and","and","and","and","and","and","and","and"],"positions":[{"x":161,"y":924},{"x":1299,"y":-1},{"x":1297,"y":134},{"x":1295,"y":201},{"x":1682,"y":182},{"x":1580,"y":303},{"x":1582,"y":482},{"x":1583,"y":663},{"x":1564,"y":756},{"x":1574,"y":909},{"x":1300,"y":320},{"x":1299,"y":386},{"x":1303,"y":479},{"x":1302,"y":542},{"x":1309,"y":636},{"x":1310,"y":701},{"x":1309,"y":814},{"x":1314,"y":877},{"x":1317,"y":980},{"x":1320,"y":1048},{"x":1081,"y":963}],"wires":[{"source":{"component":0,"pin":8},"destination":{"component":1,"pin":0},"wireId":0},{"source":{"component":5,"pin":2},"destination":{"component":0,"pin":10},"wireId":6},{"source":{"component":6,"pin":2},"destination":{"component":0,"pin":11},"wireId":11},{"source":{"component":7,"pin":2},"destination":{"component":0,"pin":12},"wireId":12},{"source":{"component":8,"pin":2},"destination":{"component":0,"pin":13},"wireId":15},{"source":{"component":9,"pin":2},"destination":{"component":0,"pin":14},"wireId":18},{"source":{"component":10,"pin":2},"destination":{"component":0,"pin":15},"wireId":21},{"source":{"component":0,"pin":0},"destination":{"component":2,"pin":0},"wireId":25},{"source":{"component":0,"pin":8},"destination":{"component":2,"pin":1},"wireId":27},{"source":{"component":2,"pin":2},"destination":{"component":5,"pin":0},"wireId":28},{"source":{"component":3,"pin":2},"destination":{"component":0,"pin":9},"wireId":29},{"source":{"component":0,"pin":1},"destination":{"component":3,"pin":1},"wireId":30},{"source":{"component":0,"pin":1},"destination":{"component":4,"pin":0},"wireId":31},{"source":{"component":1,"pin":1},"destination":{"component":3,"pin":0},"wireId":32},{"source":{"component":0,"pin":8},"destination":{"component":4,"pin":1},"wireId":33},{"source":{"component":0,"pin":2},"destination":{"component":11,"pin":1},"wireId":34},{"source":{"component":0,"pin":2},"destination":{"component":12,"pin":0},"wireId":35},{"source":{"component":1,"pin":1},"destination":{"component":11,"pin":0},"wireId":36},{"source":{"component":0,"pin":8},"destination":{"component":12,"pin":1},"wireId":37},{"source":{"component":4,"pin":2},"destination":{"component":6,"pin":0},"wireId":38},{"source":{"component":11,"pin":2},"destination":{"component":5,"pin":1},"wireId":39},{"source":{"component":12,"pin":2},"destination":{"component":7,"pin":0},"wireId":40},{"source":{"component":13,"pin":2},"destination":{"component":6,"pin":1},"wireId":41},{"source":{"component":14,"pin":2},"destination":{"component":8,"pin":0},"wireId":42},{"source":{"component":1,"pin":1},"destination":{"component":13,"pin":0},"wireId":43},{"source":{"component":0,"pin":8},"destination":{"component":14,"pin":1},"wireId":44},{"source":{"component":0,"pin":3},"destination":{"component":13,"pin":1},"wireId":45},{"source":{"component":0,"pin":3},"destination":{"component":14,"pin":0},"wireId":46},{"source":{"component":1,"pin":1},"destination":{"component":15,"pin":0},"wireId":47},{"source":{"component":0,"pin":8},"destination":{"component":16,"pin":1},"wireId":48},{"source":{"component":0,"pin":4},"destination":{"component":15,"pin":1},"wireId":49},{"source":{"component":0,"pin":4},"destination":{"component":16,"pin":0},"wireId":50},{"source":{"component":15,"pin":2},"destination":{"component":7,"pin":1},"wireId":51},{"source":{"component":16,"pin":2},"destination":{"component":9,"pin":0},"wireId":52},{"source":{"component":17,"pin":2},"destination":{"component":8,"pin":1},"wireId":53},{"source":{"component":18,"pin":2},"destination":{"component":10,"pin":0},"wireId":54},{"source":{"component":1,"pin":1},"destination":{"component":17,"pin":0},"wireId":55},{"source":{"component":0,"pin":8},"destination":{"component":18,"pin":1},"wireId":56},{"source":{"component":0,"pin":5},"destination":{"component":18,"pin":0},"wireId":57},{"source":{"component":0,"pin":5},"destination":{"component":17,"pin":1},"wireId":58},{"source":{"component":19,"pin":2},"destination":{"component":9,"pin":1},"wireId":59},{"source":{"component":20,"pin":2},"destination":{"component":0,"pin":16},"wireId":60},{"source":{"component":0,"pin":6},"destination":{"component":19,"pin":1},"wireId":61},{"source":{"component":0,"pin":6},"destination":{"component":20,"pin":0},"wireId":62},{"source":{"component":1,"pin":1},"destination":{"component":19,"pin":0},"wireId":63},{"source":{"component":0,"pin":8},"destination":{"component":20,"pin":1},"wireId":64},{"source":{"component":21,"pin":2},"destination":{"component":10,"pin":1},"wireId":65},{"source":{"component":0,"pin":7},"destination":{"component":21,"pin":0},"wireId":66},{"source":{"component":1,"pin":1},"destination":{"component":21,"pin":1},"wireId":67}]},"shift unit":{"type":"shift unit","groups":[[0,1,2,3,4,5,6,7],[8,9,10],[12,13,14,15,16,17,18,19]],"inputs":12,"tooltips":["input","input","input","input","input","input","input","input","shift by","shift by","shift by","left/right?","output","output","output","output","output","output","output","output"],"pins":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"subComponents":["shift one","shift one","shift one","shift one","shift one","shift one","shift one","16:8 mux","16:8 mux","16:8 mux","or","or","or","16:8 mux","and","or","or","16:8 mux","16:8 mux","and","16:8 mux","and","and","not"],"positions":[{"x":181,"y":217},{"x":473,"y":36},{"x":1655,"y":329},{"x":1003,"y":501},{"x":1181,"y":148},{"x":894,"y":129},{"x":772,"y":281},{"x":1925,"y":341},{"x":420,"y":191},{"x":604,"y":186},{"x":106,"y":707},{"x":179,"y":816},{"x":295,"y":736},{"x":912,"y":227},{"x":636,"y":729},{"x":853,"y":668},{"x":586,"y":555},{"x":1082,"y":304},{"x":1198,"y":368},{"x":946,"y":812},{"x":1412,"y":525},{"x":1177,"y":845},{"x":1558,"y":820},{"x":50,"y":1002}],"wires":[{"source":{"component":8,"pin":17},"destination":{"component":0,"pin":12},"wireId":0},{"source":{"component":8,"pin":18},"destination":{"component":0,"pin":13},"wireId":1},{"source":{"component":8,"pin":19},"destination":{"component":0,"pin":14},"wireId":2},{"source":{"component":8,"pin":20},"destination":{"component":0,"pin":15},"wireId":3},{"source":{"component":8,"pin":21},"destination":{"component":0,"pin":16},"wireId":4},{"source":{"component":8,"pin":22},"destination":{"component":0,"pin":17},"wireId":5},{"source":{"component":8,"pin":23},"destination":{"component":0,"pin":18},"wireId":6},{"source":{"component":8,"pin":24},"destination":{"component":0,"pin":19},"wireId":7},{"source":{"component":0,"pin":0},"destination":{"component":9,"pin":0},"wireId":8},{"source":{"component":0,"pin":1},"destination":{"component":9,"pin":1},"wireId":9},{"source":{"component":0,"pin":2},"destination":{"component":9,"pin":2},"wireId":10},{"source":{"component":0,"pin":3},"destination":{"component":9,"pin":3},"wireId":11},{"source":{"component":0,"pin":4},"destination":{"component":9,"pin":4},"wireId":12},{"source":{"component":0,"pin":5},"destination":{"component":9,"pin":5},"wireId":13},{"source":{"component":0,"pin":6},"destination":{"component":9,"pin":6},"wireId":14},{"source":{"component":0,"pin":7},"destination":{"component":9,"pin":7},"wireId":15},{"source":{"component":1,"pin":9},"destination":{"component":9,"pin":8},"wireId":16},{"source":{"component":1,"pin":10},"destination":{"component":9,"pin":9},"wireId":17},{"source":{"component":1,"pin":11},"destination":{"component":9,"pin":10},"wireId":18},{"source":{"component":1,"pin":12},"destination":{"component":9,"pin":11},"wireId":19},{"source":{"component":1,"pin":13},"destination":{"component":9,"pin":12},"wireId":20},{"source":{"component":1,"pin":14},"destination":{"component":9,"pin":13},"wireId":21},{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0},"wireId":24},{"source":{"component":0,"pin":1},"destination":{"component":1,"pin":1},"wireId":25},{"source":{"component":0,"pin":2},"destination":{"component":1,"pin":2},"wireId":26},{"source":{"component":0,"pin":3},"destination":{"component":1,"pin":3},"wireId":27},{"source":{"component":0,"pin":4},"destination":{"component":1,"pin":4},"wireId":28},{"source":{"component":0,"pin":5},"destination":{"component":1,"pin":5},"wireId":29},{"source":{"component":0,"pin":6},"destination":{"component":1,"pin":6},"wireId":30},{"source":{"component":0,"pin":7},"destination":{"component":1,"pin":7},"wireId":31},{"source":{"component":1,"pin":15},"destination":{"component":9,"pin":14},"wireId":33},{"source":{"component":1,"pin":16},"destination":{"component":9,"pin":15},"wireId":34},{"source":{"component":9,"pin":17},"destination":{"component":2,"pin":0},"wireId":36},{"source":{"component":9,"pin":18},"destination":{"component":2,"pin":1},"wireId":37},{"source":{"component":9,"pin":19},"destination":{"component":2,"pin":2},"wireId":38},{"source":{"component":9,"pin":20},"destination":{"component":2,"pin":3},"wireId":39},{"source":{"component":9,"pin":21},"destination":{"component":2,"pin":4},"wireId":40},{"source":{"component":9,"pin":22},"destination":{"component":2,"pin":5},"wireId":41},{"source":{"component":9,"pin":23},"destination":{"component":2,"pin":6},"wireId":42},{"source":{"component":9,"pin":24},"destination":{"component":2,"pin":7},"wireId":43},{"source":{"component":9,"pin":17},"destination":{"component":10,"pin":0},"wireId":45},{"source":{"component":9,"pin":18},"destination":{"component":10,"pin":1},"wireId":46},{"source":{"component":9,"pin":19},"destination":{"component":10,"pin":2},"wireId":47},{"source":{"component":9,"pin":20},"destination":{"component":10,"pin":3},"wireId":48},{"source":{"component":9,"pin":21},"destination":{"component":10,"pin":4},"wireId":49},{"source":{"component":9,"pin":22},"destination":{"component":10,"pin":5},"wireId":50},{"source":{"component":9,"pin":23},"destination":{"component":10,"pin":6},"wireId":51},{"source":{"component":9,"pin":24},"destination":{"component":10,"pin":7},"wireId":52},{"source":{"component":2,"pin":9},"destination":{"component":10,"pin":8},"wireId":53},{"source":{"component":2,"pin":10},"destination":{"component":10,"pin":9},"wireId":54},{"source":{"component":2,"pin":11},"destination":{"component":10,"pin":10},"wireId":55},{"source":{"component":2,"pin":12},"destination":{"component":10,"pin":11},"wireId":56},{"source":{"component":2,"pin":13},"destination":{"component":10,"pin":12},"wireId":57},{"source":{"component":2,"pin":14},"destination":{"component":10,"pin":13},"wireId":58},{"source":{"component":2,"pin":15},"destination":{"component":10,"pin":14},"wireId":59},{"source":{"component":2,"pin":16},"destination":{"component":10,"pin":15},"wireId":60},{"source":{"component":0,"pin":8},"destination":{"component":11,"pin":0},"wireId":62},{"source":{"component":0,"pin":9},"destination":{"component":11,"pin":1},"wireId":63},{"source":{"component":0,"pin":9},"destination":{"component":12,"pin":0},"wireId":64},{"source":{"component":0,"pin":10},"destination":{"component":12,"pin":1},"wireId":65},{"source":{"component":11,"pin":2},"destination":{"component":13,"pin":0},"wireId":66},{"source":{"component":12,"pin":2},"destination":{"component":13,"pin":1},"wireId":67},{"source":{"component":13,"pin":2},"destination":{"component":9,"pin":16},"wireId":68},{"source":{"component":10,"pin":17},"destination":{"component":7,"pin":0},"wireId":69},{"source":{"component":10,"pin":18},"destination":{"component":7,"pin":1},"wireId":70},{"source":{"component":10,"pin":19},"destination":{"component":7,"pin":2},"wireId":71},{"source":{"component":10,"pin":20},"destination":{"component":7,"pin":3},"wireId":72},{"source":{"component":10,"pin":21},"destination":{"component":7,"pin":4},"wireId":77},{"source":{"component":10,"pin":22},"destination":{"component":7,"pin":5},"wireId":78},{"source":{"component":10,"pin":23},"destination":{"component":7,"pin":6},"wireId":79},{"source":{"component":10,"pin":24},"destination":{"component":7,"pin":7},"wireId":80},{"source":{"component":10,"pin":17},"destination":{"component":14,"pin":0},"wireId":82},{"source":{"component":10,"pin":18},"destination":{"component":14,"pin":1},"wireId":83},{"source":{"component":10,"pin":19},"destination":{"component":14,"pin":2},"wireId":84},{"source":{"component":10,"pin":20},"destination":{"component":14,"pin":3},"wireId":85},{"source":{"component":10,"pin":21},"destination":{"component":14,"pin":4},"wireId":86},{"source":{"component":10,"pin":22},"destination":{"component":14,"pin":5},"wireId":87},{"source":{"component":10,"pin":23},"destination":{"component":14,"pin":6},"wireId":88},{"source":{"component":10,"pin":24},"destination":{"component":14,"pin":7},"wireId":89},{"source":{"component":7,"pin":9},"destination":{"component":14,"pin":8},"wireId":90},{"source":{"component":7,"pin":10},"destination":{"component":14,"pin":9},"wireId":91},{"source":{"component":7,"pin":11},"destination":{"component":14,"pin":10},"wireId":92},{"source":{"component":7,"pin":12},"destination":{"component":14,"pin":11},"wireId":93},{"source":{"component":7,"pin":13},"destination":{"component":14,"pin":12},"wireId":94},{"source":{"component":7,"pin":14},"destination":{"component":14,"pin":13},"wireId":95},{"source":{"component":7,"pin":15},"destination":{"component":14,"pin":14},"wireId":96},{"source":{"component":7,"pin":16},"destination":{"component":14,"pin":15},"wireId":97},{"source":{"component":0,"pin":8},"destination":{"component":15,"pin":0},"wireId":99},{"source":{"component":0,"pin":9},"destination":{"component":15,"pin":1},"wireId":100},{"source":{"component":15,"pin":2},"destination":{"component":16,"pin":0},"wireId":102},{"source":{"component":0,"pin":10},"destination":{"component":16,"pin":1},"wireId":103},{"source":{"component":16,"pin":2},"destination":{"component":14,"pin":16},"wireId":104},{"source":{"component":0,"pin":9},"destination":{"component":17,"pin":0},"wireId":105},{"source":{"component":0,"pin":10},"destination":{"component":17,"pin":1},"wireId":106},{"source":{"component":17,"pin":2},"destination":{"component":10,"pin":16},"wireId":107},{"source":{"component":14,"pin":17},"destination":{"component":6,"pin":0},"wireId":108},{"source":{"component":14,"pin":18},"destination":{"component":6,"pin":1},"wireId":109},{"source":{"component":14,"pin":19},"destination":{"component":6,"pin":2},"wireId":110},{"source":{"component":14,"pin":20},"destination":{"component":6,"pin":3},"wireId":111},{"source":{"component":14,"pin":21},"destination":{"component":6,"pin":4},"wireId":112},{"source":{"component":14,"pin":22},"destination":{"component":6,"pin":5},"wireId":113},{"source":{"component":14,"pin":23},"destination":{"component":6,"pin":6},"wireId":114},{"source":{"component":14,"pin":24},"destination":{"component":6,"pin":7},"wireId":115},{"source":{"component":14,"pin":18},"destination":{"component":18,"pin":1},"wireId":118},{"source":{"component":14,"pin":18},"destination":{"component":18,"pin":0},"wireId":127},{"source":{"component":14,"pin":19},"destination":{"component":18,"pin":2},"wireId":128},{"source":{"component":14,"pin":20},"destination":{"component":18,"pin":3},"wireId":129},{"source":{"component":14,"pin":21},"destination":{"component":18,"pin":4},"wireId":130},{"source":{"component":14,"pin":22},"destination":{"component":18,"pin":5},"wireId":131},{"source":{"component":14,"pin":23},"destination":{"component":18,"pin":6},"wireId":132},{"source":{"component":14,"pin":24},"destination":{"component":18,"pin":7},"wireId":133},{"source":{"component":6,"pin":9},"destination":{"component":18,"pin":8},"wireId":134},{"source":{"component":6,"pin":10},"destination":{"component":18,"pin":9},"wireId":135},{"source":{"component":6,"pin":11},"destination":{"component":18,"pin":10},"wireId":136},{"source":{"component":6,"pin":12},"destination":{"component":18,"pin":11},"wireId":137},{"source":{"component":6,"pin":13},"destination":{"component":18,"pin":12},"wireId":140},{"source":{"component":6,"pin":14},"destination":{"component":18,"pin":13},"wireId":141},{"source":{"component":6,"pin":15},"destination":{"component":18,"pin":14},"wireId":142},{"source":{"component":6,"pin":16},"destination":{"component":18,"pin":15},"wireId":143},{"source":{"component":0,"pin":10},"destination":{"component":18,"pin":16},"wireId":144},{"source":{"component":18,"pin":17},"destination":{"component":4,"pin":0},"wireId":145},{"source":{"component":18,"pin":18},"destination":{"component":4,"pin":1},"wireId":146},{"source":{"component":18,"pin":19},"destination":{"component":4,"pin":2},"wireId":147},{"source":{"component":18,"pin":20},"destination":{"component":4,"pin":3},"wireId":148},{"source":{"component":18,"pin":21},"destination":{"component":4,"pin":4},"wireId":149},{"source":{"component":18,"pin":22},"destination":{"component":4,"pin":5},"wireId":150},{"source":{"component":18,"pin":23},"destination":{"component":4,"pin":6},"wireId":151},{"source":{"component":18,"pin":24},"destination":{"component":4,"pin":7},"wireId":152},{"source":{"component":4,"pin":16},"destination":{"component":19,"pin":15},"wireId":155},{"source":{"component":4,"pin":15},"destination":{"component":19,"pin":14},"wireId":156},{"source":{"component":4,"pin":14},"destination":{"component":19,"pin":13},"wireId":157},{"source":{"component":4,"pin":13},"destination":{"component":19,"pin":12},"wireId":158},{"source":{"component":4,"pin":12},"destination":{"component":19,"pin":11},"wireId":159},{"source":{"component":4,"pin":11},"destination":{"component":19,"pin":10},"wireId":160},{"source":{"component":4,"pin":10},"destination":{"component":19,"pin":9},"wireId":161},{"source":{"component":4,"pin":9},"destination":{"component":19,"pin":8},"wireId":162},{"source":{"component":18,"pin":17},"destination":{"component":19,"pin":0},"wireId":163},{"source":{"component":18,"pin":18},"destination":{"component":19,"pin":1},"wireId":164},{"source":{"component":18,"pin":19},"destination":{"component":19,"pin":2},"wireId":165},{"source":{"component":18,"pin":20},"destination":{"component":19,"pin":3},"wireId":166},{"source":{"component":18,"pin":21},"destination":{"component":19,"pin":4},"wireId":167},{"source":{"component":18,"pin":22},"destination":{"component":19,"pin":5},"wireId":168},{"source":{"component":18,"pin":23},"destination":{"component":19,"pin":6},"wireId":169},{"source":{"component":18,"pin":24},"destination":{"component":19,"pin":7},"wireId":170},{"source":{"component":0,"pin":10},"destination":{"component":20,"pin":1},"wireId":171},{"source":{"component":11,"pin":2},"destination":{"component":20,"pin":0},"wireId":172},{"source":{"component":20,"pin":2},"destination":{"component":19,"pin":16},"wireId":173},{"source":{"component":19,"pin":17},"destination":{"component":5,"pin":0},"wireId":174},{"source":{"component":19,"pin":18},"destination":{"component":5,"pin":1},"wireId":175},{"source":{"component":19,"pin":19},"destination":{"component":5,"pin":2},"wireId":176},{"source":{"component":19,"pin":20},"destination":{"component":5,"pin":3},"wireId":177},{"source":{"component":19,"pin":21},"destination":{"component":5,"pin":4},"wireId":178},{"source":{"component":19,"pin":22},"destination":{"component":5,"pin":5},"wireId":179},{"source":{"component":19,"pin":23},"destination":{"component":5,"pin":6},"wireId":180},{"source":{"component":19,"pin":24},"destination":{"component":5,"pin":7},"wireId":181},{"source":{"component":19,"pin":17},"destination":{"component":21,"pin":0},"wireId":183},{"source":{"component":19,"pin":18},"destination":{"component":21,"pin":1},"wireId":184},{"source":{"component":19,"pin":19},"destination":{"component":21,"pin":2},"wireId":185},{"source":{"component":19,"pin":20},"destination":{"component":21,"pin":3},"wireId":186},{"source":{"component":19,"pin":21},"destination":{"component":21,"pin":4},"wireId":187},{"source":{"component":19,"pin":22},"destination":{"component":21,"pin":5},"wireId":188},{"source":{"component":19,"pin":23},"destination":{"component":21,"pin":6},"wireId":189},{"source":{"component":19,"pin":24},"destination":{"component":21,"pin":7},"wireId":190},{"source":{"component":5,"pin":9},"destination":{"component":21,"pin":8},"wireId":191},{"source":{"component":5,"pin":10},"destination":{"component":21,"pin":9},"wireId":192},{"source":{"component":5,"pin":11},"destination":{"component":21,"pin":10},"wireId":193},{"source":{"component":5,"pin":12},"destination":{"component":21,"pin":11},"wireId":194},{"source":{"component":5,"pin":13},"destination":{"component":21,"pin":12},"wireId":195},{"source":{"component":5,"pin":14},"destination":{"component":21,"pin":13},"wireId":196},{"source":{"component":5,"pin":15},"destination":{"component":21,"pin":14},"wireId":197},{"source":{"component":5,"pin":16},"destination":{"component":21,"pin":15},"wireId":198},{"source":{"component":0,"pin":10},"destination":{"component":22,"pin":1},"wireId":199},{"source":{"component":0,"pin":9},"destination":{"component":22,"pin":0},"wireId":200},{"source":{"component":22,"pin":2},"destination":{"component":21,"pin":16},"wireId":201},{"source":{"component":21,"pin":17},"destination":{"component":3,"pin":0},"wireId":202},{"source":{"component":21,"pin":18},"destination":{"component":3,"pin":1},"wireId":203},{"source":{"component":21,"pin":19},"destination":{"component":3,"pin":2},"wireId":204},{"source":{"component":21,"pin":20},"destination":{"component":3,"pin":3},"wireId":205},{"source":{"component":21,"pin":21},"destination":{"component":3,"pin":4},"wireId":206},{"source":{"component":21,"pin":22},"destination":{"component":3,"pin":5},"wireId":207},{"source":{"component":21,"pin":23},"destination":{"component":3,"pin":6},"wireId":208},{"source":{"component":21,"pin":24},"destination":{"component":3,"pin":7},"wireId":209},{"source":{"component":21,"pin":17},"destination":{"component":8,"pin":0},"wireId":211},{"source":{"component":21,"pin":18},"destination":{"component":8,"pin":1},"wireId":212},{"source":{"component":21,"pin":19},"destination":{"component":8,"pin":2},"wireId":213},{"source":{"component":21,"pin":20},"destination":{"component":8,"pin":3},"wireId":214},{"source":{"component":21,"pin":21},"destination":{"component":8,"pin":4},"wireId":215},{"source":{"component":21,"pin":22},"destination":{"component":8,"pin":5},"wireId":216},{"source":{"component":21,"pin":23},"destination":{"component":8,"pin":6},"wireId":217},{"source":{"component":21,"pin":24},"destination":{"component":8,"pin":7},"wireId":218},{"source":{"component":3,"pin":12},"destination":{"component":8,"pin":11},"wireId":222},{"source":{"component":3,"pin":13},"destination":{"component":8,"pin":12},"wireId":223},{"source":{"component":3,"pin":14},"destination":{"component":8,"pin":13},"wireId":224},{"source":{"component":3,"pin":15},"destination":{"component":8,"pin":14},"wireId":225},{"source":{"component":3,"pin":9},"destination":{"component":8,"pin":8},"wireId":226},{"source":{"component":3,"pin":10},"destination":{"component":8,"pin":9},"wireId":227},{"source":{"component":3,"pin":11},"destination":{"component":8,"pin":10},"wireId":228},{"source":{"component":3,"pin":16},"destination":{"component":8,"pin":15},"wireId":229},{"source":{"component":15,"pin":2},"destination":{"component":23,"pin":0},"wireId":230},{"source":{"component":0,"pin":10},"destination":{"component":23,"pin":1},"wireId":231},{"source":{"component":23,"pin":2},"destination":{"component":8,"pin":16},"wireId":232},{"source":{"component":0,"pin":11},"destination":{"component":24,"pin":0},"wireId":233},{"source":{"component":24,"pin":1},"destination":{"component":1,"pin":8},"wireId":234},{"source":{"component":24,"pin":1},"destination":{"component":2,"pin":8},"wireId":235},{"source":{"component":24,"pin":1},"destination":{"component":7,"pin":8},"wireId":236},{"source":{"component":24,"pin":1},"destination":{"component":6,"pin":8},"wireId":237},{"source":{"component":24,"pin":1},"destination":{"component":5,"pin":8},"wireId":238},{"source":{"component":24,"pin":1},"destination":{"component":4,"pin":8},"wireId":239},{"source":{"component":24,"pin":1},"destination":{"component":3,"pin":8},"wireId":240}]},"nand/xor":{"type":"nand/xor","groups":[],"inputs":3,"tooltips":["A","B","nand/xor?","output"],"pins":[0,0,0,0],"subComponents":["nand","xor","2-1 mux"],"positions":[{"x":490,"y":253},{"x":668,"y":441},{"x":1098,"y":387}],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0},"wireId":0},{"source":{"component":0,"pin":1},"destination":{"component":1,"pin":1},"wireId":1},{"source":{"component":0,"pin":0},"destination":{"component":2,"pin":0},"wireId":2},{"source":{"component":0,"pin":1},"destination":{"component":2,"pin":1},"wireId":3},{"source":{"component":1,"pin":2},"destination":{"component":3,"pin":0},"wireId":4},{"source":{"component":2,"pin":2},"destination":{"component":3,"pin":1},"wireId":5},{"source":{"component":0,"pin":2},"destination":{"component":3,"pin":2},"wireId":6},{"source":{"component":3,"pin":3},"destination":{"component":0,"pin":3},"wireId":7}]},"8-bit nand/xor":{"type":"8-bit nand/xor","groups":[[0,1,2,3,4,5,6,7],[8,9,10,11,12,13,14,15],[17,18,19,20,21,22,23,24]],"inputs":17,"tooltips":["A","A","A","A","A","A","A","A","B","B","B","B","B","B","B","B","nand/xor?","output","output","output","output","output","output","output","output"],"pins":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"subComponents":["nand/xor","nand/xor","nand/xor","nand/xor","nand/xor","nand/xor","nand/xor","nand/xor"],"positions":[{"x":488,"y":697},{"x":488,"y":579},{"x":485,"y":492},{"x":491,"y":400},{"x":491,"y":318},{"x":489,"y":241},{"x":485,"y":168},{"x":502,"y":807}],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":7,"pin":0},"wireId":0},{"source":{"component":0,"pin":8},"destination":{"component":7,"pin":1},"wireId":1},{"source":{"component":0,"pin":1},"destination":{"component":6,"pin":0},"wireId":2},{"source":{"component":0,"pin":9},"destination":{"component":6,"pin":1},"wireId":3},{"source":{"component":0,"pin":2},"destination":{"component":5,"pin":0},"wireId":4},{"source":{"component":0,"pin":10},"destination":{"component":5,"pin":1},"wireId":5},{"source":{"component":0,"pin":3},"destination":{"component":4,"pin":0},"wireId":6},{"source":{"component":0,"pin":11},"destination":{"component":4,"pin":1},"wireId":7},{"source":{"component":0,"pin":12},"destination":{"component":3,"pin":1},"wireId":8},{"source":{"component":0,"pin":4},"destination":{"component":3,"pin":0},"wireId":9},{"source":{"component":0,"pin":5},"destination":{"component":2,"pin":0},"wireId":10},{"source":{"component":0,"pin":13},"destination":{"component":2,"pin":1},"wireId":11},{"source":{"component":0,"pin":6},"destination":{"component":1,"pin":0},"wireId":12},{"source":{"component":0,"pin":7},"destination":{"component":8,"pin":0},"wireId":13},{"source":{"component":0,"pin":15},"destination":{"component":8,"pin":1},"wireId":14},{"source":{"component":0,"pin":14},"destination":{"component":1,"pin":1},"wireId":15},{"source":{"component":0,"pin":16},"destination":{"component":8,"pin":2},"wireId":16},{"source":{"component":0,"pin":16},"destination":{"component":1,"pin":2},"wireId":17},{"source":{"component":0,"pin":16},"destination":{"component":2,"pin":2},"wireId":18},{"source":{"component":0,"pin":16},"destination":{"component":3,"pin":2},"wireId":19},{"source":{"component":0,"pin":16},"destination":{"component":4,"pin":2},"wireId":20},{"source":{"component":0,"pin":16},"destination":{"component":5,"pin":2},"wireId":21},{"source":{"component":0,"pin":16},"destination":{"component":6,"pin":2},"wireId":22},{"source":{"component":0,"pin":16},"destination":{"component":7,"pin":2},"wireId":23},{"source":{"component":7,"pin":3},"destination":{"component":0,"pin":17},"wireId":24},{"source":{"component":6,"pin":3},"destination":{"component":0,"pin":18},"wireId":25},{"source":{"component":5,"pin":3},"destination":{"component":0,"pin":19},"wireId":26},{"source":{"component":4,"pin":3},"destination":{"component":0,"pin":20},"wireId":27},{"source":{"component":3,"pin":3},"destination":{"component":0,"pin":21},"wireId":28},{"source":{"component":2,"pin":3},"destination":{"component":0,"pin":22},"wireId":29},{"source":{"component":1,"pin":3},"destination":{"component":0,"pin":23},"wireId":30},{"source":{"component":8,"pin":3},"destination":{"component":0,"pin":24},"wireId":31}]},"logic unit":{"type":"logic unit","groups":[[0,1,2,3,4,5,6,7],[8,9,10,11,12,13,14,15],[18,19,20,21,22,23,24,25]],"inputs":18,"tooltips":["A","A","A","A","A","A","A","A","B","B","B","B","B","B","B","B","operation select - nand/xor or shift","operation select - nand/left or xor/right","result","result","result","result","result","result","result","result"],"pins":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"subComponents":["8-bit nand/xor","shift unit","16:8 mux"],"positions":[{"x":1130,"y":98},{"x":1007,"y":751},{"x":1665,"y":293}],"wires":[{"source":{"component":0,"pin":17},"destination":{"component":1,"pin":16},"wireId":0},{"source":{"component":0,"pin":17},"destination":{"component":2,"pin":11},"wireId":1},{"source":{"component":0,"pin":0},"destination":{"component":2,"pin":0},"wireId":2},{"source":{"component":0,"pin":1},"destination":{"component":2,"pin":1},"wireId":3},{"source":{"component":0,"pin":2},"destination":{"component":2,"pin":2},"wireId":4},{"source":{"component":0,"pin":3},"destination":{"component":2,"pin":3},"wireId":5},{"source":{"component":0,"pin":4},"destination":{"component":2,"pin":4},"wireId":6},{"source":{"component":0,"pin":5},"destination":{"component":2,"pin":5},"wireId":7},{"source":{"component":0,"pin":6},"destination":{"component":2,"pin":6},"wireId":8},{"source":{"component":0,"pin":7},"destination":{"component":2,"pin":7},"wireId":9},{"source":{"component":0,"pin":8},"destination":{"component":2,"pin":8},"wireId":10},{"source":{"component":0,"pin":9},"destination":{"component":2,"pin":9},"wireId":11},{"source":{"component":0,"pin":10},"destination":{"component":2,"pin":10},"wireId":12},{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0},"wireId":13},{"source":{"component":0,"pin":1},"destination":{"component":1,"pin":1},"wireId":14},{"source":{"component":0,"pin":2},"destination":{"component":1,"pin":2},"wireId":15},{"source":{"component":0,"pin":3},"destination":{"component":1,"pin":3},"wireId":16},{"source":{"component":0,"pin":4},"destination":{"component":1,"pin":4},"wireId":17},{"source":{"component":0,"pin":5},"destination":{"component":1,"pin":5},"wireId":18},{"source":{"component":0,"pin":6},"destination":{"component":1,"pin":6},"wireId":19},{"source":{"component":0,"pin":7},"destination":{"component":1,"pin":7},"wireId":20},{"source":{"component":0,"pin":8},"destination":{"component":1,"pin":8},"wireId":23},{"source":{"component":0,"pin":9},"destination":{"component":1,"pin":9},"wireId":24},{"source":{"component":0,"pin":10},"destination":{"component":1,"pin":10},"wireId":25},{"source":{"component":0,"pin":11},"destination":{"component":1,"pin":11},"wireId":26},{"source":{"component":0,"pin":12},"destination":{"component":1,"pin":12},"wireId":27},{"source":{"component":0,"pin":13},"destination":{"component":1,"pin":13},"wireId":28},{"source":{"component":0,"pin":14},"destination":{"component":1,"pin":14},"wireId":29},{"source":{"component":0,"pin":15},"destination":{"component":1,"pin":15},"wireId":30},{"source":{"component":1,"pin":17},"destination":{"component":3,"pin":0},"wireId":31},{"source":{"component":1,"pin":18},"destination":{"component":3,"pin":1},"wireId":32},{"source":{"component":1,"pin":19},"destination":{"component":3,"pin":2},"wireId":33},{"source":{"component":1,"pin":20},"destination":{"component":3,"pin":3},"wireId":34},{"source":{"component":1,"pin":21},"destination":{"component":3,"pin":4},"wireId":35},{"source":{"component":1,"pin":22},"destination":{"component":3,"pin":5},"wireId":36},{"source":{"component":1,"pin":23},"destination":{"component":3,"pin":6},"wireId":37},{"source":{"component":1,"pin":24},"destination":{"component":3,"pin":7},"wireId":38},{"source":{"component":2,"pin":12},"destination":{"component":3,"pin":8},"wireId":39},{"source":{"component":2,"pin":13},"destination":{"component":3,"pin":9},"wireId":40},{"source":{"component":2,"pin":14},"destination":{"component":3,"pin":10},"wireId":41},{"source":{"component":2,"pin":15},"destination":{"component":3,"pin":11},"wireId":42},{"source":{"component":2,"pin":16},"destination":{"component":3,"pin":12},"wireId":43},{"source":{"component":2,"pin":17},"destination":{"component":3,"pin":13},"wireId":44},{"source":{"component":2,"pin":18},"destination":{"component":3,"pin":14},"wireId":45},{"source":{"component":2,"pin":19},"destination":{"component":3,"pin":15},"wireId":46},{"source":{"component":0,"pin":16},"destination":{"component":3,"pin":16},"wireId":47},{"source":{"component":3,"pin":17},"destination":{"component":0,"pin":18},"wireId":48},{"source":{"component":3,"pin":18},"destination":{"component":0,"pin":19},"wireId":49},{"source":{"component":3,"pin":19},"destination":{"component":0,"pin":20},"wireId":50},{"source":{"component":3,"pin":20},"destination":{"component":0,"pin":21},"wireId":51},{"source":{"component":3,"pin":21},"destination":{"component":0,"pin":22},"wireId":52},{"source":{"component":3,"pin":22},"destination":{"component":0,"pin":23},"wireId":53},{"source":{"component":3,"pin":23},"destination":{"component":0,"pin":24},"wireId":54},{"source":{"component":3,"pin":24},"destination":{"component":0,"pin":25},"wireId":55}]},"ALU":{"type":"ALU","groups":[[0,1,2,3,4,5,6,7],[8,9,10,11,12,13,14,15],[16,17,18,19],[20],[21,22,23,24,25,26,27,28],[29,30,31,32]],"inputs":21,"tooltips":["operand 0","operand 0","operand 0","operand 0","operand 0","operand 0","operand 0","operand 0","operand 1","operand 1","operand 1","operand 1","operand 1","operand 1","operand 1","operand 1","opcode","opcode","opcode","opcode","carry/borrow in","result","result","result","result","result","result","result","result","overflow flag","negative flag","carry/borrow flag","zero flag"],"pins":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"subComponents":["logic unit","add/subtract unit","16:8 mux","16:8 mux","and","and","8-bit not","and","and","and","and","and","and","and","not","not","and","and","not","xor","xnor","and","and","or","and","and","and","not","not"],"positions":[{"x":811,"y":374},{"x":759,"y":42},{"x":1570,"y":705},{"x":1236,"y":162},{"x":82,"y":1105},{"x":2114,"y":1161},{"x":1850,"y":1060},{"x":2118,"y":1096},{"x":2121,"y":1031},{"x":2120,"y":983},{"x":2268,"y":1136},{"x":2276,"y":1029},{"x":2398,"y":1080},{"x":1267,"y":1040},{"x":1061,"y":1105},{"x":1001,"y":1044},{"x":1471,"y":987},{"x":1615,"y":571},{"x":946,"y":763},{"x":125,"y":337},{"x":1197,"y":528},{"x":1517,"y":443},{"x":1759,"y":456},{"x":2102,"y":838},{"x":1620,"y":284},{"x":1756,"y":236},{"x":1549,"y":152},{"x":1359,"y":466},{"x":663,"y":314}],"wires":[{"source":{"component":3,"pin":17},"destination":{"component":0,"pin":21},"wireId":0},{"source":{"component":3,"pin":18},"destination":{"component":0,"pin":22},"wireId":1},{"source":{"component":3,"pin":19},"destination":{"component":0,"pin":23},"wireId":2},{"source":{"component":3,"pin":20},"destination":{"component":0,"pin":24},"wireId":3},{"source":{"component":3,"pin":21},"destination":{"component":0,"pin":25},"wireId":4},{"source":{"component":3,"pin":22},"destination":{"component":0,"pin":26},"wireId":5},{"source":{"component":3,"pin":23},"destination":{"component":0,"pin":27},"wireId":6},{"source":{"component":3,"pin":24},"destination":{"component":0,"pin":28},"wireId":7},{"source":{"component":4,"pin":17},"destination":{"component":3,"pin":0},"wireId":8},{"source":{"component":4,"pin":18},"destination":{"component":3,"pin":1},"wireId":9},{"source":{"component":4,"pin":19},"destination":{"component":3,"pin":2},"wireId":10},{"source":{"component":4,"pin":20},"destination":{"component":3,"pin":3},"wireId":11},{"source":{"component":4,"pin":21},"destination":{"component":3,"pin":4},"wireId":12},{"source":{"component":4,"pin":22},"destination":{"component":3,"pin":5},"wireId":13},{"source":{"component":4,"pin":23},"destination":{"component":3,"pin":6},"wireId":14},{"source":{"component":4,"pin":24},"destination":{"component":3,"pin":7},"wireId":15},{"source":{"component":0,"pin":8},"destination":{"component":3,"pin":8},"wireId":17},{"source":{"component":0,"pin":9},"destination":{"component":3,"pin":9},"wireId":18},{"source":{"component":0,"pin":10},"destination":{"component":3,"pin":10},"wireId":19},{"source":{"component":0,"pin":11},"destination":{"component":3,"pin":11},"wireId":20},{"source":{"component":0,"pin":12},"destination":{"component":3,"pin":12},"wireId":21},{"source":{"component":0,"pin":13},"destination":{"component":3,"pin":13},"wireId":22},{"source":{"component":0,"pin":14},"destination":{"component":3,"pin":14},"wireId":23},{"source":{"component":0,"pin":15},"destination":{"component":3,"pin":15},"wireId":24},{"source":{"component":0,"pin":19},"destination":{"component":3,"pin":16},"wireId":25},{"source":{"component":0,"pin":0},"destination":{"component":2,"pin":0},"wireId":28},{"source":{"component":0,"pin":1},"destination":{"component":2,"pin":1},"wireId":29},{"source":{"component":0,"pin":2},"destination":{"component":2,"pin":2},"wireId":30},{"source":{"component":0,"pin":3},"destination":{"component":2,"pin":3},"wireId":31},{"source":{"component":0,"pin":4},"destination":{"component":2,"pin":4},"wireId":32},{"source":{"component":0,"pin":5},"destination":{"component":2,"pin":5},"wireId":33},{"source":{"component":0,"pin":6},"destination":{"component":2,"pin":6},"wireId":34},{"source":{"component":0,"pin":7},"destination":{"component":2,"pin":7},"wireId":35},{"source":{"component":0,"pin":8},"destination":{"component":2,"pin":8},"wireId":36},{"source":{"component":0,"pin":9},"destination":{"component":2,"pin":9},"wireId":37},{"source":{"component":0,"pin":10},"destination":{"component":2,"pin":10},"wireId":38},{"source":{"component":0,"pin":11},"destination":{"component":2,"pin":11},"wireId":39},{"source":{"component":0,"pin":12},"destination":{"component":2,"pin":12},"wireId":40},{"source":{"component":0,"pin":13},"destination":{"component":2,"pin":13},"wireId":41},{"source":{"component":0,"pin":14},"destination":{"component":2,"pin":14},"wireId":42},{"source":{"component":0,"pin":15},"destination":{"component":2,"pin":15},"wireId":43},{"source":{"component":0,"pin":16},"destination":{"component":2,"pin":17},"wireId":44},{"source":{"component":0,"pin":17},"destination":{"component":5,"pin":0},"wireId":45},{"source":{"component":0,"pin":20},"destination":{"component":5,"pin":1},"wireId":46},{"source":{"component":5,"pin":2},"destination":{"component":2,"pin":16},"wireId":47},{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0},"wireId":48},{"source":{"component":0,"pin":1},"destination":{"component":1,"pin":1},"wireId":49},{"source":{"component":0,"pin":2},"destination":{"component":1,"pin":2},"wireId":50},{"source":{"component":0,"pin":3},"destination":{"component":1,"pin":3},"wireId":51},{"source":{"component":0,"pin":4},"destination":{"component":1,"pin":4},"wireId":52},{"source":{"component":0,"pin":5},"destination":{"component":1,"pin":5},"wireId":53},{"source":{"component":0,"pin":6},"destination":{"component":1,"pin":6},"wireId":54},{"source":{"component":0,"pin":7},"destination":{"component":1,"pin":7},"wireId":55},{"source":{"component":0,"pin":8},"destination":{"component":1,"pin":8},"wireId":56},{"source":{"component":0,"pin":9},"destination":{"component":1,"pin":9},"wireId":57},{"source":{"component":0,"pin":10},"destination":{"component":1,"pin":10},"wireId":58},{"source":{"component":0,"pin":11},"destination":{"component":1,"pin":11},"wireId":59},{"source":{"component":0,"pin":12},"destination":{"component":1,"pin":12},"wireId":60},{"source":{"component":0,"pin":13},"destination":{"component":1,"pin":13},"wireId":61},{"source":{"component":0,"pin":14},"destination":{"component":1,"pin":14},"wireId":62},{"source":{"component":0,"pin":15},"destination":{"component":1,"pin":15},"wireId":63},{"source":{"component":2,"pin":21},"destination":{"component":4,"pin":3},"wireId":67},{"source":{"component":2,"pin":22},"destination":{"component":4,"pin":4},"wireId":68},{"source":{"component":2,"pin":23},"destination":{"component":4,"pin":5},"wireId":69},{"source":{"component":2,"pin":24},"destination":{"component":4,"pin":6},"wireId":70},{"source":{"component":2,"pin":25},"destination":{"component":4,"pin":7},"wireId":71},{"source":{"component":2,"pin":18},"destination":{"component":4,"pin":0},"wireId":74},{"source":{"component":2,"pin":19},"destination":{"component":4,"pin":1},"wireId":75},{"source":{"component":2,"pin":20},"destination":{"component":4,"pin":2},"wireId":76},{"source":{"component":1,"pin":18},"destination":{"component":4,"pin":8},"wireId":82},{"source":{"component":1,"pin":19},"destination":{"component":4,"pin":9},"wireId":83},{"source":{"component":1,"pin":20},"destination":{"component":4,"pin":10},"wireId":84},{"source":{"component":1,"pin":21},"destination":{"component":4,"pin":11},"wireId":85},{"source":{"component":1,"pin":22},"destination":{"component":4,"pin":12},"wireId":86},{"source":{"component":1,"pin":23},"destination":{"component":4,"pin":13},"wireId":87},{"source":{"component":1,"pin":24},"destination":{"component":4,"pin":14},"wireId":88},{"source":{"component":1,"pin":25},"destination":{"component":4,"pin":15},"wireId":89},{"source":{"component":0,"pin":18},"destination":{"component":4,"pin":16},"wireId":90},{"source":{"component":0,"pin":16},"destination":{"component":1,"pin":17},"wireId":92},{"source":{"component":0,"pin":17},"destination":{"component":1,"pin":16},"wireId":93},{"source":{"component":3,"pin":17},"destination":{"component":7,"pin":0},"wireId":94},{"source":{"component":3,"pin":18},"destination":{"component":7,"pin":1},"wireId":95},{"source":{"component":3,"pin":19},"destination":{"component":7,"pin":2},"wireId":96},{"source":{"component":3,"pin":20},"destination":{"component":7,"pin":3},"wireId":97},{"source":{"component":3,"pin":21},"destination":{"component":7,"pin":4},"wireId":98},{"source":{"component":3,"pin":22},"destination":{"component":7,"pin":5},"wireId":99},{"source":{"component":3,"pin":23},"destination":{"component":7,"pin":6},"wireId":100},{"source":{"component":3,"pin":24},"destination":{"component":7,"pin":7},"wireId":101},{"source":{"component":7,"pin":15},"destination":{"component":6,"pin":1},"wireId":104},{"source":{"component":7,"pin":14},"destination":{"component":6,"pin":0},"wireId":105},{"source":{"component":7,"pin":13},"destination":{"component":8,"pin":1},"wireId":106},{"source":{"component":7,"pin":12},"destination":{"component":8,"pin":0},"wireId":107},{"source":{"component":7,"pin":11},"destination":{"component":9,"pin":1},"wireId":108},{"source":{"component":7,"pin":10},"destination":{"component":9,"pin":0},"wireId":109},{"source":{"component":7,"pin":9},"destination":{"component":10,"pin":1},"wireId":110},{"source":{"component":7,"pin":8},"destination":{"component":10,"pin":0},"wireId":111},{"source":{"component":8,"pin":2},"destination":{"component":11,"pin":0},"wireId":112},{"source":{"component":6,"pin":2},"destination":{"component":11,"pin":1},"wireId":113},{"source":{"component":10,"pin":2},"destination":{"component":12,"pin":0},"wireId":114},{"source":{"component":9,"pin":2},"destination":{"component":12,"pin":1},"wireId":115},{"source":{"component":12,"pin":2},"destination":{"component":13,"pin":0},"wireId":116},{"source":{"component":11,"pin":2},"destination":{"component":13,"pin":1},"wireId":117},{"source":{"component":13,"pin":2},"destination":{"component":0,"pin":32},"wireId":118},{"source":{"component":3,"pin":24},"destination":{"component":0,"pin":30},"wireId":119},{"source":{"component":0,"pin":19},"destination":{"component":15,"pin":0},"wireId":120},{"source":{"component":15,"pin":1},"destination":{"component":14,"pin":1},"wireId":121},{"source":{"component":0,"pin":18},"destination":{"component":16,"pin":0},"wireId":122},{"source":{"component":16,"pin":1},"destination":{"component":14,"pin":0},"wireId":123},{"source":{"component":17,"pin":2},"destination":{"component":0,"pin":31},"wireId":124},{"source":{"component":14,"pin":2},"destination":{"component":17,"pin":1},"wireId":125},{"source":{"component":2,"pin":26},"destination":{"component":17,"pin":0},"wireId":126},{"source":{"component":16,"pin":1},"destination":{"component":18,"pin":1},"wireId":127},{"source":{"component":0,"pin":16},"destination":{"component":19,"pin":0},"wireId":129},{"source":{"component":19,"pin":1},"destination":{"component":18,"pin":0},"wireId":130},{"source":{"component":0,"pin":7},"destination":{"component":20,"pin":0},"wireId":133},{"source":{"component":0,"pin":15},"destination":{"component":20,"pin":1},"wireId":134},{"source":{"component":0,"pin":15},"destination":{"component":21,"pin":1},"wireId":135},{"source":{"component":2,"pin":25},"destination":{"component":21,"pin":0},"wireId":136},{"source":{"component":22,"pin":2},"destination":{"component":23,"pin":0},"wireId":139},{"source":{"component":18,"pin":2},"destination":{"component":23,"pin":1},"wireId":140},{"source":{"component":24,"pin":2},"destination":{"component":0,"pin":29},"wireId":141},{"source":{"component":23,"pin":2},"destination":{"component":24,"pin":1},"wireId":142},{"source":{"component":16,"pin":1},"destination":{"component":25,"pin":1},"wireId":143},{"source":{"component":0,"pin":16},"destination":{"component":25,"pin":0},"wireId":144},{"source":{"component":25,"pin":2},"destination":{"component":26,"pin":1},"wireId":145},{"source":{"component":26,"pin":2},"destination":{"component":24,"pin":0},"wireId":146},{"source":{"component":20,"pin":2},"destination":{"component":27,"pin":1},"wireId":147},{"source":{"component":21,"pin":2},"destination":{"component":27,"pin":0},"wireId":148},{"source":{"component":21,"pin":2},"destination":{"component":28,"pin":0},"wireId":149},{"source":{"component":28,"pin":1},"destination":{"component":22,"pin":1},"wireId":150},{"source":{"component":20,"pin":2},"destination":{"component":29,"pin":0},"wireId":151},{"source":{"component":29,"pin":1},"destination":{"component":22,"pin":0},"wireId":152},{"source":{"component":27,"pin":2},"destination":{"component":26,"pin":0},"wireId":153}]}} diff --git a/build/.DS_Store b/build/.DS_Store new file mode 100755 index 0000000..940e942 Binary files /dev/null and b/build/.DS_Store differ diff --git a/build/._.DS_Store b/build/._.DS_Store new file mode 100755 index 0000000..2fa28b3 Binary files /dev/null and b/build/._.DS_Store differ diff --git a/build/alu/full/index.html b/build/alu/full/index.html new file mode 100755 index 0000000..f6bbd5b --- /dev/null +++ b/build/alu/full/index.html @@ -0,0 +1,66 @@ + + + + + + + Build an ALU + + + + +

Time to put it all together

+

Now we've built the constituent parts, it's now time to put everything together into our ALU chip.

+

The ALU has two outputs: the 8-bit result of the operation that was performed, and a 4-bit "flags" value which contains information about the calculation.

+ flags +

You should set the flags according to the following logic:

+
+ + + + + + + + +
FlagLogic
Overflow1 if the addition of two numbers with the same sign bit produces a result with a different sign, or if the subtraction of two numbers with different signs produces a result with the same sign as the number being subtracted.
0 otherwise.
Carry / Borrow1 if an addition or subtraction operation results in a carry / borrow.
0 otherwise.
Negative flag1 if the sign bit (most significant bit) of the result is 1.
0 otherwise.
Zero flag1 if every bit of the result is 0.
0 otherwise.
+
+

The ALU has three inputs: the first and second 8-bit operands, and a 4-bit "opcode" which selects the operation to be performed.
This processor's ALU will use the following opcodes:

+
+ + + + + + + + + + + + + + +
OpcodeOperationExplaiation
0000add Adds the second operand to the first, setting the carry in to 0.
0001subtract (sub)Subtracts the second operand from the first, setting the carry in to 0.
0010add with carry
(adc)
Adds the second operand to the first, setting the carry in to the value of the carry flag.
0011subtract with borrow
(subb)
Subtracts the second operand from the first, setting the carry in to the value of the carry flag.
0100nandEach bit of the output is the result of NANDing together the respective bits of each operand.
0101xorEach bit of the output is the result of XORing together the respective bits of each operand.
0110shift left
(sll)
Each bit of operand 1 is shifted to the left by the number of places specified by operand 2.
0111shift right
(srl)
Each bit of operand 1 is shifted to the right by the number of places specified by operand 2.
1XXXmove
(mov)
Operand 2 is passed straight through to the result. No operation is performed.
+
+

This is the most complicated part of the process, and it's OK if you don't quite understand everything yet. You can use the green links to get more information about certain words, and now might be a good time to ask your tutor for help if you are truly stuck.

+ +

Start building

+ +

+ Once you are finished, you can return to the CPU. +

+ + diff --git a/build/alu/index.html b/build/alu/index.html new file mode 100755 index 0000000..3d8ab70 --- /dev/null +++ b/build/alu/index.html @@ -0,0 +1,42 @@ + + + + Build an ALU + + + + +

Build an ALU!

+

The ALU is the chip that's responsible for performing all the calculations this processor can do. It's far too complex to build all in one go, however, so we have to break it down into component parts.

+

+ Below is a list of all the parts that we need to make. They have to be done in order, because each one builds on the one before! Make sure you have a multiplexer built first, because we will need this! +

+

Addition

+
    +
  1. half adder
  2. +
  3. full adder
  4. +
  5. 8-bit ripple carry adder
  6. +
+

Subtraction

+
    +
  1. 8-bit inverter
  2. +
  3. subtract unit
  4. +
  5. add / subtract unit
  6. +
+

Logic

+
    +
  1. nand/xor gate
  2. +
  3. 8-bit nand/xor unit
  4. +
  5. left/right shift bit
  6. +
  7. shift n bits unit
  8. +
  9. logic unit
  10. +
+

Final boss

+
    +
  1. full ALU
  2. +
+

+ Once you are finished, you can return to the CPU. +

+ + diff --git a/build/css/._ibm.woff b/build/css/._ibm.woff new file mode 100755 index 0000000..b54e590 Binary files /dev/null and b/build/css/._ibm.woff differ diff --git a/build/css/ibm.woff b/build/css/ibm.woff new file mode 100755 index 0000000..1f1508d Binary files /dev/null and b/build/css/ibm.woff differ diff --git a/build/css/style.css b/build/css/style.css new file mode 100755 index 0000000..4512be2 --- /dev/null +++ b/build/css/style.css @@ -0,0 +1,104 @@ +html { + background-color: #3A0000; + display: flex; + justify-content: center; +} +body { + margin-top: 15px; + line-height: 1; + padding: 30px; + font-family: sans-serif; + background-color: white; + box-shadow: rgb(142 47 47) 15px 15px; + margin-bottom:20px; +} +* { + margin-top: 5px; + margin-bottom: 5px; + font-family: "IBM VGA"; + } +a { + border-bottom: 1px; + --fgcolor: blue; + color: var(--fgcolor); +} +img { + display: block; + margin: 0 auto; + max-width: 600px; +} +a:hover { + background-color: var(--fgcolor); + color: white; +} +a[href*="//"] { + border-bottom: 1px double; + --fgcolor: green; + target-name: new; + target-new: tab; +} +h1,ul,ol { + margin-top: 13px; + margin-bottom: 13px; +} +ol[data-bin="1"]{ + list-style: none; + padding-left:0; + margin-left: 0; + padding-right:0; + margin-right: 0; +} +ol[data-bin="1"] li { + padding-left: 1rem; + text-indent: -0.7rem; +} +li:before { + font-weight: bolder; + color: red; + content: attr(data-before); + padding-right:10px; +} +p { + margin-bottom: 15px; +} + +table{ + margin: 25px; + width: 50%; + min-width: 500px; + border-collapse: collapse; + +} +thead tr { + background-color: black; + color: white; + border-bottom: 1px solid; +} +td { + padding: 5px; +} +tbody tr:not(:last-child){ + border-bottom: 1px solid; +} +tbody td:not(:first-child) { + border-left: 1px solid; +} +table.c1c td:first-child { + text-align: center; +} +table.c1c tbody td:first-child { + color: red; +} +@media screen and (max-width:600px) { + body { width: 100%; } + img { width: 100%; } +} +@media screen and (min-width:600px) { + body { width: 40%; min-width:600px; max-width:960px; } +} +@font-face { + font-family: 'IBM VGA'; + src: url('../css/ibm.woff'); + font-weight: normal; + font-style: normal; +} diff --git a/build/editor/.DS_Store b/build/editor/.DS_Store new file mode 100755 index 0000000..5bb0a97 Binary files /dev/null and b/build/editor/.DS_Store differ diff --git a/build/editor/._.DS_Store b/build/editor/._.DS_Store new file mode 100755 index 0000000..e0eba57 Binary files /dev/null and b/build/editor/._.DS_Store differ diff --git a/build/editor/css/style.css b/build/editor/css/style.css new file mode 100755 index 0000000..33e0a8b --- /dev/null +++ b/build/editor/css/style.css @@ -0,0 +1,15 @@ +html, body { + width:100%; + height: 100%; + margin: 0; + overflow: hidden; +} +body { + display: flex; + align-items: center; + justify-content: center; + background-color:black; +} +canvas { + background-color:#36393E; +} diff --git a/build/editor/img/.DS_Store b/build/editor/img/.DS_Store new file mode 100755 index 0000000..72faf3a Binary files /dev/null and b/build/editor/img/.DS_Store differ diff --git a/build/editor/img/._.DS_Store b/build/editor/img/._.DS_Store new file mode 100755 index 0000000..c1b6d2b Binary files /dev/null and b/build/editor/img/._.DS_Store differ diff --git a/build/editor/img/gates copy/and.png b/build/editor/img/gates copy/and.png new file mode 100755 index 0000000..96e6a00 Binary files /dev/null and b/build/editor/img/gates copy/and.png differ diff --git a/build/editor/img/gates copy/nand.png b/build/editor/img/gates copy/nand.png new file mode 100755 index 0000000..fb6eec7 Binary files /dev/null and b/build/editor/img/gates copy/nand.png differ diff --git a/build/editor/img/gates copy/nor.png b/build/editor/img/gates copy/nor.png new file mode 100755 index 0000000..a739ef4 Binary files /dev/null and b/build/editor/img/gates copy/nor.png differ diff --git a/build/editor/img/gates copy/not.png b/build/editor/img/gates copy/not.png new file mode 100755 index 0000000..3779ce4 Binary files /dev/null and b/build/editor/img/gates copy/not.png differ diff --git a/build/editor/img/gates copy/or.png b/build/editor/img/gates copy/or.png new file mode 100755 index 0000000..3bcadfd Binary files /dev/null and b/build/editor/img/gates copy/or.png differ diff --git a/build/editor/img/gates copy/xnor.png b/build/editor/img/gates copy/xnor.png new file mode 100755 index 0000000..ab8cfe5 Binary files /dev/null and b/build/editor/img/gates copy/xnor.png differ diff --git a/build/editor/img/gates copy/xor.png b/build/editor/img/gates copy/xor.png new file mode 100755 index 0000000..531dd70 Binary files /dev/null and b/build/editor/img/gates copy/xor.png differ diff --git a/build/editor/img/gates/._and.png b/build/editor/img/gates/._and.png new file mode 100755 index 0000000..08a775d Binary files /dev/null and b/build/editor/img/gates/._and.png differ diff --git a/build/editor/img/gates/._nand.png b/build/editor/img/gates/._nand.png new file mode 100755 index 0000000..fb1c285 Binary files /dev/null and b/build/editor/img/gates/._nand.png differ diff --git a/build/editor/img/gates/._nor.png b/build/editor/img/gates/._nor.png new file mode 100755 index 0000000..f44c992 Binary files /dev/null and b/build/editor/img/gates/._nor.png differ diff --git a/build/editor/img/gates/._not.png b/build/editor/img/gates/._not.png new file mode 100755 index 0000000..c38b159 Binary files /dev/null and b/build/editor/img/gates/._not.png differ diff --git a/build/editor/img/gates/._or.png b/build/editor/img/gates/._or.png new file mode 100755 index 0000000..534b34a Binary files /dev/null and b/build/editor/img/gates/._or.png differ diff --git a/build/editor/img/gates/._xnor.png b/build/editor/img/gates/._xnor.png new file mode 100755 index 0000000..b556ca4 Binary files /dev/null and b/build/editor/img/gates/._xnor.png differ diff --git a/build/editor/img/gates/._xor.png b/build/editor/img/gates/._xor.png new file mode 100755 index 0000000..83f6eb4 Binary files /dev/null and b/build/editor/img/gates/._xor.png differ diff --git a/build/editor/img/gates/and.png b/build/editor/img/gates/and.png new file mode 100755 index 0000000..ca5be7b Binary files /dev/null and b/build/editor/img/gates/and.png differ diff --git a/build/editor/img/gates/nand.png b/build/editor/img/gates/nand.png new file mode 100755 index 0000000..25a29c7 Binary files /dev/null and b/build/editor/img/gates/nand.png differ diff --git a/build/editor/img/gates/nor.png b/build/editor/img/gates/nor.png new file mode 100755 index 0000000..9f8ecdc Binary files /dev/null and b/build/editor/img/gates/nor.png differ diff --git a/build/editor/img/gates/not.png b/build/editor/img/gates/not.png new file mode 100755 index 0000000..6a8a82e Binary files /dev/null and b/build/editor/img/gates/not.png differ diff --git a/build/editor/img/gates/or.png b/build/editor/img/gates/or.png new file mode 100755 index 0000000..d34225e Binary files /dev/null and b/build/editor/img/gates/or.png differ diff --git a/build/editor/img/gates/xnor.png b/build/editor/img/gates/xnor.png new file mode 100755 index 0000000..72cac5e Binary files /dev/null and b/build/editor/img/gates/xnor.png differ diff --git a/build/editor/img/gates/xor.png b/build/editor/img/gates/xor.png new file mode 100755 index 0000000..59d2bc8 Binary files /dev/null and b/build/editor/img/gates/xor.png differ diff --git a/build/editor/index.php b/build/editor/index.php new file mode 100755 index 0000000..f8c742e --- /dev/null +++ b/build/editor/index.php @@ -0,0 +1,22 @@ + + + Component editior +\n"); + } + if(!isset($_GET['edit'])) { echo("\n"); } +?> + + + + + + + + + + + + + diff --git a/build/editor/js/bk/chips.js b/build/editor/js/bk/chips.js new file mode 100755 index 0000000..96cd480 --- /dev/null +++ b/build/editor/js/bk/chips.js @@ -0,0 +1,187 @@ +chips = { + "nand": { + image: "img/gates/nand.png", + inputs: 2, + pins : [0,0,0], + subComponents : [], + wires : [] + }, + "not": { + image: "img/gates/not.png", + inputs: 1, + pins: [0,0], + subComponents: ["nand"], + wires: [ + { + source: { component: 0, pin: 0 }, + destination: { component: 1, pin: 0 } + }, + { + source: { component: 0, pin: 0 }, + destination: { component: 1, pin: 1 } + }, + { + source: { component: 1, pin: 2 }, + destination: { component: 0, pin: 1 } + } + ] + }, + "and": { + image: "img/gates/and.png", + inputs: 2, + pins : [0,0,0], + subComponents : ["nand", "nand"], + wires : [ + { + source: { component: 0, pin: 0 }, + destination: { component: 1, pin: 0 }, + }, + { + source: { component: 0, pin: 1 }, + destination: { component: 1, pin: 1 } + }, + { + source: { component: 1, pin: 2 }, + destination: { component: 2, pin: 0 } + }, + { + source: { component: 1, pin: 2 }, + destination: { component: 2, pin: 1 } + }, + { + source: { component: 2, pin: 2 }, + destination: { component: 0, pin: 2 } + } + ] + }, + "or": { + image: "img/gates/or.png", + inputs: 2, + pins: [0,0,0], + subComponents : ["nand","nand","nand"], + wires : [ + { + source: { component: 0, pin: 0 }, + destination: { component: 1, pin: 0 }, + }, + { + source: { component: 0, pin: 0 }, + destination: { component: 1, pin: 1 } + }, + { + source: { component: 0, pin: 1 }, + destination: { component: 2, pin: 0 } + }, + { + source: { component: 0, pin: 1 }, + destination: { component: 2, pin: 1 } + }, + { + source: { component: 1, pin: 2 }, + destination: { component: 3, pin: 0 } + }, + { + source: { component: 2, pin: 2 }, + destination: { component: 3, pin: 1 } + }, + { + source: { component: 3, pin: 2 }, + destination: { component: 0, pin: 2 } + } + ] + }, + "xor": { + image: "img/gates/xor.png", + inputs:2, + pins: [0,0,0], + subComponents: ["nand","nand","nand", "nand"], + wires : [ + { + source: { component: 0, pin: 0 }, + destination: { component: 1, pin: 0 } + }, + { + source: { component: 0, pin: 1 }, + destination: { component: 1, pin: 1 } + }, + { + source: { component: 0, pin: 0 }, + destination: { component: 2, pin: 0 } + }, + { + source: { component: 1, pin: 2 }, + destination: { component: 2, pin: 1 } + }, + { + source: { component: 1, pin: 2 }, + destination: { component: 3, pin: 0 } + }, + { + source: { component: 0, pin: 1 }, + destination: { component: 3, pin: 1 } + }, + { + source: { component: 2, pin: 2 }, + destination: { component: 4, pin: 0 } + }, + { + source: { component: 3, pin: 2 }, + destination: { component: 4, pin: 1 } + }, + { + source: { component: 4, pin: 2 }, + destination: { component: 0, pin: 2 } + } + + ] + }, + "nor": { + inputs:2, + image: "img/gates/nor.png", + pins: [0,0,0], + subComponents: ["or","not"], + wires: [ + { + source: { component: 0, pin: 0 }, + destination: { component: 1, pin: 0 } + }, + { + source: { component: 0, pin: 1 }, + destination: { component: 1, pin: 1 } + }, + { + source: { component: 1, pin: 2 }, + destination: { component: 2, pin: 0 }, + }, + { + source: { component: 2, pin: 1 }, + destination: { component: 0, pin: 2 } + } + ] + }, + "xnor": { + image: "img/gates/nor.png", + pins: [0,0,0], + subComponents: ["xor","not"], + wires: [ + { + source: { component: 0, pin: 0 }, + destination: { component: 1, pin: 0 } + }, + { + source: { component: 0, pin: 1 }, + destination: { component: 1, pin: 1 } + }, + { + source: { component: 1, pin: 2 }, + destination: { component: 2, pin: 0 }, + }, + { + source: { component: 2, pin: 1 }, + destination: { component: 0, pin: 2 } + } + ] + } + + +} diff --git a/build/editor/js/bk/components.js b/build/editor/js/bk/components.js new file mode 100755 index 0000000..58fdd77 --- /dev/null +++ b/build/editor/js/bk/components.js @@ -0,0 +1,205 @@ +class Component { + type; + image; + inputs=0; + pins = []; + subComponents = [this]; + zIndex = []; + wires = []; + position = { x: 0, y: 0 }; + constructor(name){ + this.type = name; + if (!(name in chips)) { + return; + } + var chip = JSON.parse(JSON.stringify(chips[name])); + this.image = chip.image; + this.pins = chip.pins; + this.wires = chip.wires; + this.inputs = chip.inputs; + chip.subComponents.forEach((sc,i)=>{ + this.subComponents.push(new Component(sc)); + this.zIndex.push(this.subComponents[i]); + }); + this.process(); + } + process(){ + if (this.type=="nand"){ + this.pins[2] = (this.pins[0] && this.pins[1])?0:1; + } else { + this.subComponents.forEach(s=>{if(s != this) {s.process()}}); + this.wires.forEach(w=>{ + this.subComponents[w.destination.component].pins[w.destination.pin] = this.subComponents[w.source.component].pins[w.source.pin] + }); + } + return this.pins; + } + addComponent(name){ + var nc = new Component(name); + this.subComponents.push(nc); + this.zIndex.unshift(nc); + } + removeComponent(index){ + this.zIndex = this.zIndex.filter(zEntry=> this.getProperIndex(zEntry) !== index); + this.wires.forEach(w=>{ + if(w.source.component == index) + this.subComponents[w.destination.component].pins[w.destination.pin] = 0; + }); + this.wires = this.wires.filter(w=>w.source.component != index && w.destination.component != index).map(w => { if(w.destination.component>index){w.destination.component-=1};if(w.source.component>index){w.source.component-=1}; return w }); + + this.subComponents.splice(index,1); + console.log("hi"); + console.log(this.subComponents); + + } + sendToFront(index){ + this.zIndex=this.zIndex.filter(zEntry=>this.getProperIndex(zEntry)!==index); + this.zIndex.push(this.subComponents[index]); + } + getProperIndex(zEntry){ + return this.subComponents.indexOf(zEntry); + } + connect(source,destination,wid){ + var sourceIsInput,destinationIsOutput; + sourceIsInput=destinationIsOutput=0; + if (source.pin < this.subComponents[source.component].inputs) + sourceIsInput = true; + if (destination.pin >= this.subComponents[destination.component].inputs) + destinationIsOutput = true; + source = {component:source.component, pin:source.pin}; + destination={component:destination.component,pin:destination.pin}; + if(source.component == 0){ // if the source is the chip itself + if(destination.component == 0){ // should be direct connection between input and output pins + if(!(sourceIsInput&&destinationIsOutput)){ // if not, + if((!sourceIsInput&&!destinationIsOutput)){ // is it backwards? + var tmp=source; + source=destination; + destination=tmp; + } else { // no, so it's wrong + console.log("1"); + return false; + } + } else { + // connection between chip and component - both should be inputs or both should be outputs + if(!((sourceIsInput&&!destinationIsOutput)||(!sourceIsInput && destinationIsOutput))){ + // if not, we know something must be wrong. there is no reason ever for an output pin on a component to go to an input pin or vice versa. + console.log("2"); + return false; + } else if(!sourceIsInput&&!destinationIsOutput) { + + } + } + } + } else { + if(destination.component == 0){ + //connection between component and chip! both inputs or both outputs + if(!((sourceIsInput&&!destinationIsOutput)||(!sourceIsInput && destinationIsOutput))){ + console.log("3"); + return false; + } + } else { // connection between two components. source must be an output and destination must be input. cannot be same type. + //if same type + + if(!((sourceIsInput&&destinationIsOutput)||(!sourceIsInput&&!destinationIsOutput))){ + console.log("4"); + return false; + } + if(sourceIsInput&&destinationIsOutput){ // if that happened its mixed up + var tmp = source; + tmp=destination; + destination=tmp; + } + } + + } + /* + var sourceShouldBeInput,destinationShouldBeOutput,sourceIsInput, destinationIsOutput; + sourceShouldBeInput = destinationShouldBeOutput = sourceIsInput = destinationIsOutput = false; + if (source.pin < this.subComponents[source.component].inputs) + sourceIsInput = true; + if (destination.pin >= this.subComponents[destination.component].inputs) + destinationIsOutput = true; + if(source.component==0) + sourceShouldBeInput=true; + if(destination.component==0) + destinationShouldBeOutput=true; + + if(sourceIsInput&&!sourceShouldBeInput){ + if(destinationIsOutput&&!destinationShouldBeOutput){ + var tmp = source; + source = destination; + destination = tmp; + } else { + if( + console.log("no bc source is input xor destination is output"); + console.log({sourceIsInput,sourceShouldBeInput,destinationIsOutput,destinationShouldBeOutput}); + return false; + } + } else if(destinationIsOutput&&!destinationShouldBeOutput) { + console.log("no bc destination is output"); + console.log({sourceIsInput,sourceShouldBeInput,destinationIsOutput,destinationShouldBeOutput}); + return false; + } + if(!sourceIsInput&&sourceShouldBeInput){ + if(!destinationIsOutput&&destinationShouldBeOutput){ + var tmp=source; + source=destination; + destination=tmp; + } else { + console.log({sourceIsInput,sourceShouldBeInput,destinationIsOutput,destinationShouldBeOutput}); + console.log("no bc source is output xor destination is input"); + return false; + } + } else if(!destinationIsOutput&&destinationShouldBeOutput) { + console.log("no bc destination is input"); + console.log({sourceIsInput,sourceShouldBeInput,destinationIsOutput,destinationShouldBeOutput}); + return false; + } + console.log({sourceIsInput,sourceShouldBeInput,destinationIsOutput,destinationShouldBeOutput}); + /* + if (sourceIsInput && destinationIsOutput) { + if (source.component==0||destination.component==0) + return false; + var tmp = source; + source=destination; + destination = tmp; + } else if (sourceIsInput || destinationIsOutput) { + if (!((sourceIsInput && source.component==0)||(destinationIsOutput && destination.component==0))) + return false; + } else { + if(source.component==0||destination.component==0){ + var tmp=source; + source=destination; + destination=tmp; + } + } + */ + this.wires = this.wires.filter(w=>JSON.stringify(w.destination)!=JSON.stringify(destination)); + this.wires.push({ source: source, destination: destination, wireId:wid }); + return true; + + } + disconnect(source,destination){ + this.wires = this.wires.filter(w=>JSON.stringify(w)!=JSON.stringify({source:source,destination:destination})); + } + addPin(isInput){ + if(isInput){ + this.inputs++; + this.pins.unshift(0); + this.wires.forEach(w=>{ if(w.source.component==0){w.source.pin+=1} }); + } else { + this.pins.push(0); + } + } + removePin(i){; + this.wires = this.wires.filter(w=>!((w.source.component==0 && w.source.pin == pin)||(w.destination.component==0 && w.destination.pin == pin))); + if(i{ if(w.source.component==0){w.source.pin-=1}}); + } else { + this.pins.pop(); + } + } +} + + diff --git a/build/editor/js/bk/index.js b/build/editor/js/bk/index.js new file mode 100755 index 0000000..d03a4e9 --- /dev/null +++ b/build/editor/js/bk/index.js @@ -0,0 +1,229 @@ +var canvas, ctx +var selectedItem +var mouseisdown +var chip = new Component("main"); +var pinImages = []; +var wireVisuals = []; +var wireBeingDrawn = []; +images = {}; +var x; +document.addEventListener("DOMContentLoaded", function(event){ + canvas = document.getElementById('logicsim'); + canvas.addEventListener("mousedown",selectItem); + canvas.addEventListener("mouseup", function(){mouseisdown=false}); + canvas.addEventListener("mousemove",mousemove); + document.addEventListener("keydown",checkKey); + ctx = canvas.getContext('2d'); + preloadAssets(); + requestAnimationFrame(drawCanvas); + x=setInterval(function(){chip.process()},1); +}); +function getMousePos(c,e){ + var rect = c.getBoundingClientRect(); + return { + x: e.clientX - rect.left, + y: e.clientY - rect.top + } +} +function checkKey(e){ + e=e||window.event; + if(e.keyCode==27){ + selectedPin={component:-1,pin:-1}; + wireBeingDrawn=[]; + } +} +function isInside(c,point){ + return ( point.x > c.position.x && point.x < c.position.x + images[c.type].width) && + ( point.y > c.position.y && point.y < c.position.y + images[c.type].height); +} +function isInsidePin(p,point){ + return Math.sqrt(Math.pow((p.position.x-point.x),2)+Math.pow((p.position.y-point.y),2)) < p.radius; +} +var clickpos; +var nWireAttempts=0; +var selectedPin = {component:-1,pin:-1}; +var hoveredPin = {component:-1,pin:-1,type:-1}; +function selectItem(e){ + pos = getMousePos(canvas, e) + if(hoveredPin.component>=0){ + if(hoveredPin.type==1){ + chip.pins[hoveredPin.pin]=1-chip.pins[hoveredPin.pin]; + } else { + if(wireBeingDrawn.length>0){ + if(chip.connect(selectedPin, hoveredPin, nWireAttempts)){ + wireBeingDrawn[wireBeingDrawn.length-1]={component:hoveredPin.component,pin:hoveredPin.pin}; + wireVisuals.push({wireId:nWireAttempts,path:wireBeingDrawn.slice()}); + wireBeingDrawn=[]; + selectedPin={component:-1,pin:-1}; + nWireAttempts+=1; + } else { + console.log("noooo"); + } + } else { + wireBeingDrawn.push({component:hoveredPin.component,pin:hoveredPin.pin}); + wireBeingDrawn.push({x:pos.x,y:pos.y}); + selectedPin = {component:hoveredPin.component,pin:hoveredPin.pin}; + } + } + } else { + if(wireBeingDrawn.length>0){ + wireBeingDrawn[wireBeingDrawn.length-1]={x:pos.x,y:pos.y}; + wireBeingDrawn.push({x:pos.x,y:pos.y})//slice()); + } + } + chip.zIndex.forEach(function(c,i){ + if (isInside(c, pos) && ctx.getImageData(pos.x,pos.y,1,1).data[3]) { + mouseisdown = true; + clickpos = pos; + chip.sendToFront(chip.getProperIndex(c)); + // DELETE THIS LATER // + return; + } + + }); +} +var pos; +function mousemove(e){ + pos = getMousePos(canvas,e); + if(wireBeingDrawn.length>0){ + wireBeingDrawn[wireBeingDrawn.length-1]={x:pos.x,y:pos.y}; + } + if(mouseisdown){ + last = chip.zIndex.length-1; + chip.zIndex[last].position.x -= (clickpos.x - pos.x); + chip.zIndex[last].position.y -= (clickpos.y - pos.y); + clickpos = pos; + } + if(!pinImages.some(pi=>{ + if(isInsidePin(pi,pos)){ + hoveredPin = {component:pi.component,pin:pi.pin,type:pi.type} + return true; + } + })){ + hoveredPin={component:-1,pin:-1}; + } +} +function preloadAssets(){ + Object.entries(chips).forEach(function(c){ + if (!(c[1].image in images)){ + images[c[0]] = new Image(); + images[c[0]].src = c[1].image; + } + }); +} +function makeArr(startValue, stopValue, cardinality) { + var arr = []; + var step = (stopValue - startValue) / (cardinality - 1); + for (var i = 0; i < cardinality; i++) { + arr.push(startValue + (step * i)); + } + return arr; +} +function drawCircle(x,y,radius,colour){ + ctx.beginPath(); + ctx.arc(Math.floor(x),Math.floor(y),radius,0,2*Math.PI,false); + ctx.fillStyle=colour; + ctx.fill(); +} +function drawLine(origin,destination,width,colour){ + ctx.beginPath(); + ctx.moveTo(origin.x,origin.y); + ctx.lineTo(destination.x,destination.y); + ctx.strokeStyle=colour; + ctx.lineWidth=width; + ctx.stroke(); +} +function drawCanvas() { + pI = []; + ctx.clearRect(0, 0, canvas.width, canvas.height); + ctx.canvas.width = 600; + ctx.canvas.height = 600; + ctx.fillStyle="lightgray"; + ctx.fillRect(0,0,20,canvas.height); + //components.slice().reverse().forEach(function(c){ + for(var i=0;ip.component==wireBeingDrawn[0].component && p.pin==wireBeingDrawn[0].pin && p.type==0).position; + else + p1=wireBeingDrawn[i]; + //if(i==wireBeingDrawn.length-2) + // p2=pinImages.find(p=>p.component==wireBeingDrawn[i+1].component&&p.pin==wireBeingDrawn[i+1].pin&&p.type==0).position; + //else + p2=wireBeingDrawn[i+1] + drawLine(p1,p2,3,["black","red"][chip.subComponents[wireBeingDrawn[0].component].pins[wireBeingDrawn[0].pin]]); + } + wireVisuals=wireVisuals.filter(wv=> {return chip.wires.findIndex(w=>w.wireId==wv.wireId)>=0}); + wireVisuals.forEach(wv=>{ + for(var i=0;ip.component==wv.path[0].component && p.pin==wv.path[0].pin && p.type==0).position; + else + p1=wv.path[i]; + if(i==wv.path.length-2) + p2=pinImages.find(p=>p.component==wv.path[i+1].component&&p.pin==wv.path[i+1].pin&&p.type==0).position; + else + p2=wv.path[i+1]; + drawLine(p1,p2,3,["black","red"][chip.subComponents[wv.path[0].component].pins[wv.path[0].pin]]); + } + }); + chip.pins.forEach((p,i)=>{ + if(i{ + img = images[c.type]; + ctx.drawImage(img,c.position.x,c.position.y); + c.pins.forEach((p,i)=>{ + //trueCenterY = (c.position.y+(c.position.y + c.height))/2 + centerX = c.position.x+img.width+5; + otherpins = c.pins.length - c.inputs; + pindex = i - c.inputs; + if(i{ + if (c!==this){ + niceStructure.subComponents.push(c.type); + niceStructure.positions.push(c.position); + } + }); + return JSON.stringify(niceStructure); + + } + constructor(name,direct=false,djson=""){ + this.type = name; + if (!(name in chips) && !direct) { + return; + } + var chip; + if(!direct){ + chip = JSON.parse(JSON.stringify(chips[name])); + } else { + chip = JSON.parse(djson); + } + this.image = chip.image; + this.groups = [1,2,3]//chip.groups || []; + this.pins = chip.pins; + this.wires = chip.wires; + this.inputs = chip.inputs; + this.tooltips = chip.tooltips; + chip.subComponents.forEach((sc,i)=>{ + this.subComponents.push(new Component(sc)); + this.zIndex.push(this.subComponents[i+1]); + if(chip.type=="main"){ + this.subComponents[i+1].position = chip.positions[i]; + } + + }); + this.process(); + } + process(){ + //var startTime = performance.now() + if (this.type=="nand"){ + this.pins[2] = (this.pins[0] && this.pins[1])?0:1; + } else { + this.subComponents.forEach(s=>{if(s != this) {s.process()}}); + this.wires.forEach(w=>{ + this.subComponents[w.destination.component].pins[w.destination.pin] = this.subComponents[w.source.component].pins[w.source.pin] + }); + } + //var endTime = performance.now() + //if(this.type=="main") + // console.log(`Updating ${this.type} took ${endTime - startTime} milliseconds`) + return this.pins; + } + addComponent(name){ + var nc = new Component(name); + this.subComponents.push(nc); + this.zIndex.unshift(nc); + } + removeComponent(index){ + this.zIndex = this.zIndex.filter(zEntry=> this.getProperIndex(zEntry) !== index); + this.wires.forEach(w=>{ + if(w.source.component == index) + this.subComponents[w.destination.component].pins[w.destination.pin] = 0; + }); + this.wires = this.wires.filter(w=>w.source.component != index && w.destination.component != index).map(w => { if(w.destination.component>index){w.destination.component-=1};if(w.source.component>index){w.source.component-=1}; return w }); + + this.subComponents.splice(index,1); + console.log("hi"); + console.log(this.subComponents); + + } + sendToFront(index){ + this.zIndex=this.zIndex.filter(zEntry=>this.getProperIndex(zEntry)!==index); + this.zIndex.push(this.subComponents[index]); + } + getProperIndex(zEntry){ + return this.subComponents.indexOf(zEntry); + } + connect(source,destination,wid){ + var sourceIsInput,destinationIsOutput; + sourceIsInput=destinationIsOutput=0; + if (source.pin < this.subComponents[source.component].inputs) + sourceIsInput = true; + if (destination.pin >= this.subComponents[destination.component].inputs) + destinationIsOutput = true; + source = {component:source.component, pin:source.pin}; + destination={component:destination.component,pin:destination.pin}; + if(sourceIsInput){ + if(source.component == 0){ + if((destinationIsOutput&&destination.component!=0)||(!destinationIsOutput && destination.component==0)){ + console.log(1); + return false; + } + } else { + if(destinationIsOutput && destination.component==0){ + console.log({n:2,c:source.component}); + return false; + } else if (destinationIsOutput||destination.component==0){ + console.log("swap"); + var tmp = source; + source=destination; + destination = tmp; + } else if(!destinationIsOutput&&destination.component==0) { + } else { + console.log(3); + return false; + } + } + } else { + if(source.component==0){ + if((destinationIsOutput&&destination.component!=0)||(!destinationIsOutput&&destination.component==0)){ + console.log("swap"); + var tmp=source; + source=destination; + destination=tmp; + } else { + console.log(4); + return false; + } + + } else { + if(destinationIsOutput&&destination.component!=0){ + console.log(5); + return false; + /* + } else if (!destinationIsOutput){ + console.log("swap"); + var tmp=source; + source=destination; + destination=tmp; +*/ + } else if(destination.component==0&&!destinationIsOutput){ + console.log(6); + return false; + } + } + } + this.wires = this.wires.filter(w=>JSON.stringify(w.destination)!=JSON.stringify(destination)); + this.wires.push({ source: source, destination: destination, wireId:wid }); + return true; + + } + disconnect(source,destination){ + this.wires = this.wires.filter(w=>JSON.stringify(w)!=JSON.stringify({source:source,destination:destination})); + } + addPin(isInput){ + if(isInput){ + this.inputs++; + this.pins.unshift(0); + this.wires.forEach(w=>{ if(w.destination.component==0){w.destination.pin+=1} }); + } else { + this.pins.push(0); + } + } + removePin(i){; + this.wires = this.wires.filter(w=>!((w.source.component==0 && w.source.pin == pin)||(w.destination.component==0 && w.destination.pin == pin))); + if(i{ if(w.source.component==0){w.source.pin-=1}}); + } else { + this.pins.pop(); + } + } +} + + diff --git a/build/editor/js/index.js b/build/editor/js/index.js new file mode 100755 index 0000000..97241fa --- /dev/null +++ b/build/editor/js/index.js @@ -0,0 +1,425 @@ +var canvas, ctx +var selectedItem +var mouseisdown +var chip = new Component("main"); +var pinImages = []; +var wireVisuals = []; +var wireBeingDrawn = []; +images = {}; +var chipoffset=0; +var numUpdates = 0; +var x; +document.addEventListener("DOMContentLoaded", function(event){ + canvas = document.getElementById('logicsim'); + canvas.addEventListener("mousedown",selectItem); + canvas.addEventListener("mouseup", function(){mouseisdown=false}); + canvas.addEventListener("mousemove",mousemove); + document.addEventListener("keydown",checkKey); + document.addEventListener("keyup",function(e){shifted=e.shiftKey}); + ctx = canvas.getContext('2d'); + preloadAssets(); + requestAnimationFrame(drawCanvas); + //x=setInterval(function(){var st = performance.now(); chip.process(console.log(performance.now()-st))},1.1); + y=0 + x=setInterval(function(){chip.process();numUpdates+=1},0.3); + storedChips = localStorage.getItem('chips'); + if(storedChips) chips = JSON.parse(storedChips); +}); +function getMousePos(c,e){ + var rect = c.getBoundingClientRect(); + return { + x: e.clientX - rect.left, + y: e.clientY - rect.top + } +} +function checkKey(e){ + e=e||window.event; + if(e.keyCode==27){ + selectedPin={component:-1,pin:-1}; + wireBeingDrawn=[]; + } else if(e.key=="n"){ + var name = prompt('name new chip or cancel'); + if (name.length){ + chips[name]=JSON.parse(chip.getJSONandName(name)); + localStorage.setItem('chips',JSON.stringify(chips)); + chip = new Component(); + close(); + } + } else if(e.keyCode==8 || e.keyCode==46){if(selectedItem>=0){chip.removeComponent(selectedItem); + wireVisuals.forEach(wv=>{ + wv.path.forEach(p=>{if(p.component>selectedItem){p.component-=1}}); + });}} else if (e.keyCode==37) { + chipoffset+=10; + } else if (e.keyCode==39) { chipoffset-=10}; + shifted=e.shiftKey; +} +function isInside(c,point){ + return ( point.x > c.position.x && point.x < c.position.x + images[c.type].width) && + ( point.y > c.position.y && point.y < c.position.y + images[c.type].height); +} +function isInsidePin(p,point){ + return Math.sqrt(Math.pow((p.position.x-point.x),2)+Math.pow((p.position.y-point.y),2)) < p.radius; +} +var clickpos; +var shifted = 0; +var nWireAttempts=0; +var selectedPin = {component:-1,pin:-1}; +var hoveredPin = {component:-1,pin:-1,type:-1}; +function selectItem(e){ + pos = getMousePos(canvas, e) + + if(pos.y>canvas.height-60){ + chipMenu.forEach(cm=>{ + if((pos.x>cm.topLeft.x && pos.x < (cm.topLeft.x+cm.width))&&(pos.y>cm.topLeft.y&&pos.y<(cm.topLeft.y+40))){ + console.log(cm.type); + chip.addComponent(cm.type); + //.position = {x:pos.x,y:pos.y} + + } else { + } + }); + return; + } + + if(hoveredPin.component>=0){ + if(hoveredPin.type==1){ + if(hoveredPin.pin0){ + if(chip.connect(selectedPin, hoveredPin, nWireAttempts)){ + wireBeingDrawn[wireBeingDrawn.length-1]={component:hoveredPin.component,pin:hoveredPin.pin,shift:shifted,offset:wireBeingDrawn[1].offset}; + wireVisuals.push({wireId:nWireAttempts,path:wireBeingDrawn.slice()}); + wireBeingDrawn=[]; + selectedPin={component:-1,pin:-1}; + nWireAttempts+=1; + } else { + console.log("noooo"); + } + } else { + inp = chip.subComponents[hoveredPin.component].inputs; + defaultOffset = 10; + if(hoveredPin.component == 0 && hoveredPin.pin < inp){ + o = 7*hoveredPin.pin; + rev = 1 + } else if(hoveredPin.component == 0) { + o = 7*(hoveredPin.pin-inp); + rev = -1 + } else if (hoveredPin.component>0 && hoveredPin.pin < inp) { + o = 7*hoveredPin.pin; + rev = -1 + } else { + o = 7*(hoveredPin.pin-inp) + rev = 1 + } + wireBeingDrawn.push({component:hoveredPin.component,pin:hoveredPin.pin,shift:shifted,rev:rev}); + wireBeingDrawn.push({x:pos.x,y:pos.y,shift:shifted,offset:o}); + selectedPin = {component:hoveredPin.component,pin:hoveredPin.pin}; + } + } + } else if(pos.x<20){ + if(typeof editDisabled == 'undefined') + chip.addPin(1); + + //wireVisuals.forEach(wv=>{if(wv.path[0].component==0){wv.path[wv.path.length-1].pin+=1;}}); + return true; + } else if(pos.x>canvas.width-20){ + if(typeof editDisabled == 'undefined') + chip.addPin(); + return true; + } else { + if(wireBeingDrawn.length>0){ + wireBeingDrawn[wireBeingDrawn.length-1]={x:pos.x,y:pos.y,shift:shifted,offset:wireBeingDrawn[1].offset}; + wireBeingDrawn.push({x:pos.x,y:pos.y,shift:shifted,offset:wireBeingDrawn[1].offset})//slice()); + } + } + selectedItem=-1; + chip.zIndex.forEach(function(c,i){ + if (isInside(c, pos) && ctx.getImageData(pos.x,pos.y,1,1).data[3]) { + mouseisdown = true; + clickpos = pos; + chip.sendToFront(chip.getProperIndex(c)); + selectedItem = chip.getProperIndex(c); + console.log(selectedItem); + // DELETE THIS LATER // + return; + } + + }); +} +var pos; +function mousemove(e){ + pos = getMousePos(canvas,e); + if(wireBeingDrawn.length>0){ + o = wireBeingDrawn[wireBeingDrawn.length-1].offset; + wireBeingDrawn[wireBeingDrawn.length-1]={x:pos.x,y:pos.y,shift:shifted,offset:o}; + } + if(mouseisdown){ + last = chip.zIndex.length-1; + chip.zIndex[last].position.x -= (clickpos.x - pos.x); + chip.zIndex[last].position.y -= (clickpos.y - pos.y); + clickpos = pos; + } + if(!pinImages.some(pi=>{ + if(isInsidePin(pi,pos)){ + hoveredPin = {component:pi.component,pin:pi.pin,type:pi.type} + return true; + } + })){ + hoveredPin={component:-1,pin:-1}; + } +} +function preloadAssets(){ + Object.entries(chips).forEach(function(c){ + if (!(c[1].image in images)){ + images[c[0]] = new Image(); + images[c[0]].src = c[1].image; + } + }); + if(typeof loadChip == 'function'){ + loadChip(); + } +} +function makeArr(startValue, stopValue, cardinality) { + var arr = []; + var step = (stopValue - startValue) / (cardinality - 1); + for (var i = 0; i < cardinality; i++) { + arr.push(startValue + (step * i)); + } + return arr; +} +function drawCircle(x,y,radius,colour){ + ctx.beginPath(); + ctx.arc(Math.floor(x),Math.floor(y),radius,0,2*Math.PI,false); + ctx.fillStyle=colour; + ctx.fill(); +} +function drawLine(origin,destination,width,colour,taxi,offset,rev){ + if(!taxi||destination.shift){ + ctx.beginPath(); + ctx.moveTo(origin.x,origin.y); + ctx.lineTo(destination.x,destination.y); + ctx.strokeStyle=colour; + ctx.lineWidth=width; + ctx.stroke(); + } else { + ctx.beginPath(); + ctx.moveTo(origin.x,origin.y); + if(destination.y>origin.y){ + offset = offset*-rev; + } else { + offset = offset * rev; + } + multip = 0.4; + if(rev<0) { + multip = 1-multip; + } + ctx.lineTo(origin.x+(destination.x-origin.x)*multip+offset,origin.y); + ctx.lineTo(origin.x+(destination.x-origin.x)*multip+offset,destination.y); + ctx.lineTo(destination.x,destination.y); + ctx.strokeStyle=colour; + ctx.lineWidth=width; + ctx.stroke(); + } +} +chipMenu = []; +tt = null; +class Tooltip { + constructor(x,y,message,persist=false){ + this.x=x; + this.y=y; + this.message=message; + this.persist=persist; + } + draw(offset){ + //ctx.fillStyle='pink'; + //ctx.fillRect(0,0,canvas.width,canvas.height); + //return; + ctx.fillStyle="rgba(0,0,0,0.65)"; + ctx.font="20px vcr_osd_monoregular"; + ctx.textBaseline="bottom"; + ctx.textAlign="left"; + var width=ctx.measureText(this.message).width+6; + offset=0 + ctx.fillRect(this.x{ + ctx.font = "20px vcr_osd_monoregular" + ctx.fillStyle="#1A3060"; + width=ctx.measureText(chip[0]).width+8; + ctx.fillRect(curX+chipoffset,canvas.height-50,width,40); + ctx.fillStyle="white"; + ctx.fillText(chip[0],curX+chipoffset+4,canvas.height-25); + cm.push({type:chip[0],topLeft:{x: curX+chipoffset, y: canvas.height-50},width:width}); + curX+=width+5; + }); + chipMenu=cm; + + //components.slice().reverse().forEach(function(c){ + for(var i=0;ip.component==wireBeingDrawn[0].component && p.pin==wireBeingDrawn[0].pin && p.type==0).position; + else + p1=wireBeingDrawn[i]; + //if(i==wireBeingDrawn.length-2) + // p2=pinImages.find(p=>p.component==wireBeingDrawn[i+1].component&&p.pin==wireBeingDrawn[i+1].pin&&p.type==0).position; + //else + p2=wireBeingDrawn[i+1] + o=0.5; + if(wireBeingDrawn[i+1].offset != undefined){ + o=wireBeingDrawn[i+1].offset; + } + drawLine(p1,p2,3,["lightgray","red"][chip.subComponents[wireBeingDrawn[0].component].pins[wireBeingDrawn[0].pin]],true,o,wireBeingDrawn[0].rev); + } + wireVisuals=wireVisuals.filter(wv=> {return chip.wires.findIndex(w=>w.wireId==wv.wireId)>=0}); + wireVisuals.forEach(wv=>{ + for(var i=0;ip.component==wv.path[0].component && p.pin==wv.path[0].pin && p.type==0).position; + else + p1=wv.path[i]; + if(i==wv.path.length-2) + p2=pinImages.find(p=>p.component==wv.path[i+1].component&&p.pin==wv.path[i+1].pin&&p.type==0).position; + else + p2=wv.path[i+1]; + drawLine(p1,p2,3,["lightgray","red"][chip.subComponents[wv.path[0].component].pins[wv.path[0].pin]],true,wv.path[1].offset,wv.path[0].rev); + } + }); + currentGroup=-1; + groupn=1; + chip.pins.forEach((p,i)=>{ + if(i{ + if(group.includes(i)) newGroup = n; + }); + if(newGroup>-1 && newGroup==currentGroup) { + centerY -=20*groupn; + groupn++; + } else {groupn=1}; + pI.push({component:0,pin:i,position:{x:centerX,y:centerY},radius:7,type:1}); + secondaryX=(i-1){ + ctx.fillStyle="white"; + old=[ctx.textAlign, ctx.textBaseline]; + ctx.textAlign="center"; + ctx.textBaseline="middle"; + ctx.font='11px monospace' + if(!chip.no) + ctx.fillText(Math.pow(2,groupn-1), centerX, centerY); + else if(!chip.no.includes(i)) ctx.fillText(Math.pow(2,groupn-1), centerX, centerY); + ctx.textAlign=old[0]; + ctx.textBaseline=old[1]; + } + currentGroup=newGroup; + }) + chip.zIndex.forEach(c=>{ + img = images[c.type]; + if(img!==undefined&&img.dummy!=1) + ctx.drawImage(img,c.position.x,c.position.y); + else { + ctx.font = "20px vcr_osd_monoregular" + ctx.fillStyle="#1A3060"; + h = parseInt(md5(c.type).substring(1,10),16); + poss_colors = ["white","red","lightblue","pink","yellow","lightgreen","orange","violet"]; + ctx.fillStyle = poss_colors[h%poss_colors.length]; + width = ctx.measureText(c.type).width + 30; + if (c.inputs>c.pins.length/2){ + height = c.inputs * 15 + } else { + height = (c.pins.length-c.inputs)*15; + } + ctx.fillRect(c.position.x,c.position.y,width,height); + ctx.fillStyle="black"; + ctx.fillText(c.type,c.position.x+15,c.position.y+(height/2)+4); + img = {width,height,dummy:1}; + images[c.type]=img; + } + + c.pins.forEach((p,i)=>{ + //trueCenterY = (c.position.y+(c.position.y + c.height))/2 + centerX = c.position.x+img.width+5; + otherpins = c.pins.length - c.inputs; + pindex = i - c.inputs; + if(i=0){ + try{ + drawTooltip(chip.subComponents[hoveredPin.component].tooltips[hoveredPin.pin]); + } catch(ex){console.log(ex)} + } else { + } + if(tt) tt.draw(); + + requestAnimationFrame(drawCanvas); +} diff --git a/build/editor/js/items/CPU_ALU.js b/build/editor/js/items/CPU_ALU.js new file mode 100755 index 0000000..6fa6a50 --- /dev/null +++ b/build/editor/js/items/CPU_ALU.js @@ -0,0 +1,10 @@ +function loadChip(){ + setTimeout(function(){ + chip = new Component("main", true, '{"type":"main","groups":[[0,1,2,3,4,5,6,7],[8,9,10,11,12,13,14,15],[16,17,18,19],[20],[21,22,23,24,25,26,27,28],[29,30,31,32]],"inputs":21,"tooltips":["operand 0","operand 0","operand 0","operand 0","operand 0","operand 0","operand 0","operand 0","operand 1","operand 1","operand 1","operand 1","operand 1","operand 1","operand 1","operand 1","opcode","opcode","opcode","opcode","carry/borrow in","result","result","result","result","result","result","result","result","overflow flag","negative flag","carry/borrow flag","zero flag"],"pins":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"subComponents":["ALU"],"positions":[{"x":467,"y":673}],"wires":[{"source":{"component":1,"pin":32},"destination":{"component":0,"pin":32},"wireId":0},{"source":{"component":1,"pin":31},"destination":{"component":0,"pin":31},"wireId":1},{"source":{"component":1,"pin":30},"destination":{"component":0,"pin":30},"wireId":2},{"source":{"component":1,"pin":29},"destination":{"component":0,"pin":29},"wireId":3},{"source":{"component":1,"pin":28},"destination":{"component":0,"pin":28},"wireId":4},{"source":{"component":1,"pin":27},"destination":{"component":0,"pin":27},"wireId":5},{"source":{"component":1,"pin":26},"destination":{"component":0,"pin":26},"wireId":6},{"source":{"component":1,"pin":25},"destination":{"component":0,"pin":25},"wireId":7},{"source":{"component":1,"pin":24},"destination":{"component":0,"pin":24},"wireId":8},{"source":{"component":1,"pin":23},"destination":{"component":0,"pin":23},"wireId":9},{"source":{"component":1,"pin":22},"destination":{"component":0,"pin":22},"wireId":10},{"source":{"component":1,"pin":21},"destination":{"component":0,"pin":21},"wireId":11},{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0},"wireId":12},{"source":{"component":0,"pin":1},"destination":{"component":1,"pin":1},"wireId":13},{"source":{"component":0,"pin":2},"destination":{"component":1,"pin":2},"wireId":15},{"source":{"component":0,"pin":3},"destination":{"component":1,"pin":3},"wireId":16},{"source":{"component":0,"pin":4},"destination":{"component":1,"pin":4},"wireId":17},{"source":{"component":0,"pin":5},"destination":{"component":1,"pin":5},"wireId":18},{"source":{"component":0,"pin":6},"destination":{"component":1,"pin":6},"wireId":19},{"source":{"component":0,"pin":7},"destination":{"component":1,"pin":7},"wireId":20},{"source":{"component":0,"pin":8},"destination":{"component":1,"pin":8},"wireId":21},{"source":{"component":0,"pin":9},"destination":{"component":1,"pin":9},"wireId":22},{"source":{"component":0,"pin":10},"destination":{"component":1,"pin":10},"wireId":23},{"source":{"component":0,"pin":11},"destination":{"component":1,"pin":11},"wireId":24},{"source":{"component":0,"pin":12},"destination":{"component":1,"pin":12},"wireId":25},{"source":{"component":0,"pin":13},"destination":{"component":1,"pin":13},"wireId":26},{"source":{"component":0,"pin":14},"destination":{"component":1,"pin":14},"wireId":27},{"source":{"component":0,"pin":15},"destination":{"component":1,"pin":15},"wireId":28},{"source":{"component":0,"pin":16},"destination":{"component":1,"pin":16},"wireId":29},{"source":{"component":0,"pin":17},"destination":{"component":1,"pin":17},"wireId":30},{"source":{"component":0,"pin":18},"destination":{"component":1,"pin":18},"wireId":31},{"source":{"component":0,"pin":19},"destination":{"component":1,"pin":19},"wireId":32},{"source":{"component":0,"pin":20},"destination":{"component":1,"pin":20},"wireId":33}]}'); + chip.groups = [] + chip.tooltips = ["A","B","nand/xor?","output"]; + },1000) + setTimeout(function(){ + wireVisuals = JSON.parse('[{"wireId":0,"path":[{"component":1,"pin":32,"shift":false,"rev":1},{"component":0,"pin":32,"shift":false,"offset":77}]},{"wireId":1,"path":[{"component":1,"pin":31,"shift":false,"rev":1},{"component":0,"pin":31,"shift":false,"offset":70}]},{"wireId":2,"path":[{"component":1,"pin":30,"shift":false,"rev":1},{"component":0,"pin":30,"shift":false,"offset":63}]},{"wireId":3,"path":[{"component":1,"pin":29,"shift":false,"rev":1},{"component":0,"pin":29,"shift":false,"offset":56}]},{"wireId":4,"path":[{"component":1,"pin":28,"shift":false,"rev":1},{"component":0,"pin":28,"shift":false,"offset":49}]},{"wireId":5,"path":[{"component":1,"pin":27,"shift":false,"rev":1},{"component":0,"pin":27,"shift":false,"offset":42}]},{"wireId":6,"path":[{"component":1,"pin":26,"shift":false,"rev":1},{"component":0,"pin":26,"shift":false,"offset":35}]},{"wireId":7,"path":[{"component":1,"pin":25,"shift":false,"rev":1},{"component":0,"pin":25,"shift":false,"offset":28}]},{"wireId":8,"path":[{"component":1,"pin":24,"shift":false,"rev":1},{"component":0,"pin":24,"shift":false,"offset":21}]},{"wireId":9,"path":[{"component":1,"pin":23,"shift":false,"rev":1},{"component":0,"pin":23,"shift":false,"offset":14}]},{"wireId":10,"path":[{"component":1,"pin":22,"shift":false,"rev":1},{"component":0,"pin":22,"shift":false,"offset":7}]},{"wireId":11,"path":[{"component":1,"pin":21,"shift":false,"rev":1},{"component":0,"pin":21,"shift":false,"offset":0}]},{"wireId":12,"path":[{"component":0,"pin":0,"shift":false,"rev":1},{"component":1,"pin":0,"shift":false,"offset":0}]},{"wireId":13,"path":[{"component":0,"pin":1,"shift":false,"rev":1},{"component":1,"pin":1,"shift":false,"offset":7}]},{"wireId":15,"path":[{"component":0,"pin":2,"shift":false,"rev":1},{"component":1,"pin":2,"shift":false,"offset":14}]},{"wireId":16,"path":[{"component":0,"pin":3,"shift":false,"rev":1},{"component":1,"pin":3,"shift":false,"offset":21}]},{"wireId":17,"path":[{"component":0,"pin":4,"shift":false,"rev":1},{"component":1,"pin":4,"shift":false,"offset":28}]},{"wireId":18,"path":[{"component":0,"pin":5,"shift":false,"rev":1},{"component":1,"pin":5,"shift":false,"offset":35}]},{"wireId":19,"path":[{"component":0,"pin":6,"shift":false,"rev":1},{"component":1,"pin":6,"shift":false,"offset":42}]},{"wireId":20,"path":[{"component":0,"pin":7,"shift":false,"rev":1},{"component":1,"pin":7,"shift":false,"offset":49}]},{"wireId":21,"path":[{"component":0,"pin":8,"shift":false,"rev":1},{"component":1,"pin":8,"shift":false,"offset":56}]},{"wireId":22,"path":[{"component":0,"pin":9,"shift":false,"rev":1},{"component":1,"pin":9,"shift":false,"offset":63}]},{"wireId":23,"path":[{"component":0,"pin":10,"shift":false,"rev":1},{"component":1,"pin":10,"shift":false,"offset":70}]},{"wireId":24,"path":[{"component":0,"pin":11,"shift":false,"rev":1},{"component":1,"pin":11,"shift":false,"offset":77}]},{"wireId":25,"path":[{"component":0,"pin":12,"shift":false,"rev":1},{"component":1,"pin":12,"shift":false,"offset":84}]},{"wireId":26,"path":[{"component":0,"pin":13,"shift":false,"rev":1},{"component":1,"pin":13,"shift":false,"offset":91}]},{"wireId":27,"path":[{"component":0,"pin":14,"shift":false,"rev":1},{"component":1,"pin":14,"shift":false,"offset":98}]},{"wireId":28,"path":[{"component":0,"pin":15,"shift":false,"rev":1},{"component":1,"pin":15,"shift":false,"offset":105}]},{"wireId":29,"path":[{"component":0,"pin":16,"shift":false,"rev":1},{"component":1,"pin":16,"shift":false,"offset":112}]},{"wireId":30,"path":[{"component":0,"pin":17,"shift":false,"rev":1},{"component":1,"pin":17,"shift":false,"offset":119}]},{"wireId":31,"path":[{"component":0,"pin":18,"shift":false,"rev":1},{"component":1,"pin":18,"shift":false,"offset":126}]},{"wireId":32,"path":[{"component":0,"pin":19,"shift":false,"rev":1},{"component":1,"pin":19,"shift":false,"offset":133}]},{"wireId":33,"path":[{"component":0,"pin":20,"shift":false,"rev":1},{"component":1,"pin":20,"shift":false,"offset":140}]}]'); + },2000); +} diff --git a/build/editor/js/items/CPU_MUX.js b/build/editor/js/items/CPU_MUX.js new file mode 100755 index 0000000..e3af947 --- /dev/null +++ b/build/editor/js/items/CPU_MUX.js @@ -0,0 +1,10 @@ +function loadChip(){ + setTimeout(function(){ + chip = new Component("main", true, '{"type":"main","groups":[[0,1,2,3,4,5,6,7],[8,9,10,11,12,13,14,15],[16],[17,18,19,20,21,22,23,24]],"inputs":17,"tooltips":["A","A","A","A","A","A","A","A","B","B","B","B","B","B","B","B","select","output","output","output","output","output","output","output","output"],"pins":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"subComponents":["16:8 mux"],"positions":[{"x":690,"y":308}],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0},"wireId":0},{"source":{"component":0,"pin":1},"destination":{"component":1,"pin":1},"wireId":1},{"source":{"component":0,"pin":2},"destination":{"component":1,"pin":2},"wireId":2},{"source":{"component":0,"pin":3},"destination":{"component":1,"pin":3},"wireId":3},{"source":{"component":0,"pin":4},"destination":{"component":1,"pin":4},"wireId":4},{"source":{"component":0,"pin":5},"destination":{"component":1,"pin":5},"wireId":5},{"source":{"component":0,"pin":6},"destination":{"component":1,"pin":6},"wireId":6},{"source":{"component":0,"pin":7},"destination":{"component":1,"pin":7},"wireId":7},{"source":{"component":0,"pin":8},"destination":{"component":1,"pin":8},"wireId":8},{"source":{"component":0,"pin":9},"destination":{"component":1,"pin":9},"wireId":9},{"source":{"component":0,"pin":10},"destination":{"component":1,"pin":10},"wireId":10},{"source":{"component":0,"pin":11},"destination":{"component":1,"pin":11},"wireId":11},{"source":{"component":0,"pin":12},"destination":{"component":1,"pin":12},"wireId":12},{"source":{"component":0,"pin":13},"destination":{"component":1,"pin":13},"wireId":13},{"source":{"component":0,"pin":14},"destination":{"component":1,"pin":14},"wireId":14},{"source":{"component":0,"pin":15},"destination":{"component":1,"pin":15},"wireId":15},{"source":{"component":0,"pin":16},"destination":{"component":1,"pin":16},"wireId":16},{"source":{"component":1,"pin":17},"destination":{"component":0,"pin":17},"wireId":17},{"source":{"component":1,"pin":18},"destination":{"component":0,"pin":18},"wireId":18},{"source":{"component":1,"pin":19},"destination":{"component":0,"pin":19},"wireId":19},{"source":{"component":1,"pin":20},"destination":{"component":0,"pin":20},"wireId":20},{"source":{"component":1,"pin":21},"destination":{"component":0,"pin":21},"wireId":21},{"source":{"component":1,"pin":22},"destination":{"component":0,"pin":22},"wireId":22},{"source":{"component":1,"pin":23},"destination":{"component":0,"pin":23},"wireId":23},{"source":{"component":1,"pin":24},"destination":{"component":0,"pin":24},"wireId":24}]}'); + chip.groups = [] + chip.tooltips = ["A","B","nand/xor?","output"]; + },1000) + setTimeout(function(){ + wireVisuals = JSON.parse('[{"wireId":0,"path":[{"component":0,"pin":0,"shift":false,"rev":1},{"component":1,"pin":0,"shift":false,"offset":0}]},{"wireId":1,"path":[{"component":0,"pin":1,"shift":false,"rev":1},{"component":1,"pin":1,"shift":false,"offset":7}]},{"wireId":2,"path":[{"component":0,"pin":2,"shift":false,"rev":1},{"component":1,"pin":2,"shift":false,"offset":14}]},{"wireId":3,"path":[{"component":0,"pin":3,"shift":false,"rev":1},{"component":1,"pin":3,"shift":false,"offset":21}]},{"wireId":4,"path":[{"component":0,"pin":4,"shift":false,"rev":1},{"component":1,"pin":4,"shift":false,"offset":28}]},{"wireId":5,"path":[{"component":0,"pin":5,"shift":false,"rev":1},{"component":1,"pin":5,"shift":false,"offset":35}]},{"wireId":6,"path":[{"component":0,"pin":6,"shift":false,"rev":1},{"component":1,"pin":6,"shift":false,"offset":42}]},{"wireId":7,"path":[{"component":0,"pin":7,"shift":false,"rev":1},{"component":1,"pin":7,"shift":false,"offset":49}]},{"wireId":8,"path":[{"component":0,"pin":8,"shift":false,"rev":1},{"component":1,"pin":8,"shift":false,"offset":56}]},{"wireId":9,"path":[{"component":0,"pin":9,"shift":false,"rev":1},{"component":1,"pin":9,"shift":false,"offset":63}]},{"wireId":10,"path":[{"component":0,"pin":10,"shift":false,"rev":1},{"component":1,"pin":10,"shift":false,"offset":70}]},{"wireId":11,"path":[{"component":0,"pin":11,"shift":false,"rev":1},{"component":1,"pin":11,"shift":false,"offset":77}]},{"wireId":12,"path":[{"component":0,"pin":12,"shift":false,"rev":1},{"component":1,"pin":12,"shift":false,"offset":84}]},{"wireId":13,"path":[{"component":0,"pin":13,"shift":false,"rev":1},{"component":1,"pin":13,"shift":false,"offset":91}]},{"wireId":14,"path":[{"component":0,"pin":14,"shift":false,"rev":1},{"component":1,"pin":14,"shift":false,"offset":98}]},{"wireId":15,"path":[{"component":0,"pin":15,"shift":false,"rev":1},{"component":1,"pin":15,"shift":false,"offset":105}]},{"wireId":16,"path":[{"component":0,"pin":16,"shift":false,"rev":1},{"component":1,"pin":16,"shift":false,"offset":112}]},{"wireId":17,"path":[{"component":1,"pin":17,"shift":true,"rev":1},{"component":0,"pin":17,"shift":true,"offset":0}]},{"wireId":18,"path":[{"component":1,"pin":18,"shift":true,"rev":1},{"component":0,"pin":18,"shift":true,"offset":7}]},{"wireId":19,"path":[{"component":1,"pin":19,"shift":false,"rev":1},{"component":0,"pin":19,"shift":false,"offset":14}]},{"wireId":20,"path":[{"component":1,"pin":20,"shift":false,"rev":1},{"component":0,"pin":20,"shift":false,"offset":21}]},{"wireId":21,"path":[{"component":1,"pin":21,"shift":false,"rev":1},{"component":0,"pin":21,"shift":false,"offset":28}]},{"wireId":22,"path":[{"component":1,"pin":22,"shift":false,"rev":1},{"component":0,"pin":22,"shift":false,"offset":35}]},{"wireId":23,"path":[{"component":1,"pin":23,"shift":false,"rev":1},{"component":0,"pin":23,"shift":false,"offset":42}]},{"wireId":24,"path":[{"component":1,"pin":24,"shift":false,"rev":1},{"component":0,"pin":24,"shift":false,"offset":49}]}]'); + },2000); +} diff --git a/build/editor/js/items/alu.js b/build/editor/js/items/alu.js new file mode 100755 index 0000000..1eafa86 --- /dev/null +++ b/build/editor/js/items/alu.js @@ -0,0 +1,6 @@ +function loadChip(){ + chip=new Component('main',true,'{"type":"main","inputs":21,"tooltips":[],"pins":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"subComponents":[],"positions":[],"wires":[]}'); + chip.groups = [[0,1,2,3,4,5,6,7],[8,9,10,11,12,13,14,15],[16,17,18,19],[20],[21,22,23,24,25,26,27,28],[29,30,31,32]]; + chip.no=[29,30,31,32]; + chip.tooltips = ["operand 0","operand 0","operand 0","operand 0","operand 0","operand 0","operand 0","operand 0","operand 1","operand 1","operand 1","operand 1","operand 1","operand 1","operand 1","operand 1","opcode","opcode","opcode","opcode","carry/borrow in","result","result","result","result","result","result","result","result","overflow flag","negative flag","carry/borrow flag","zero flag"]; +} diff --git a/build/editor/js/items/alu1.js b/build/editor/js/items/alu1.js new file mode 100755 index 0000000..a33c6f0 --- /dev/null +++ b/build/editor/js/items/alu1.js @@ -0,0 +1,5 @@ +function loadChip(){ + chip=new Component('main',true,'{"type":"main","inputs":2,"tooltips":[],"pins":[0,0,0,0],"subComponents":[],"positions":[],"wires":[]}'); + chip.groups = [[0],[1],[2],[3]] + chip.tooltips = ["A","B","sum", "carry"] +} diff --git a/build/editor/js/items/alu10.js b/build/editor/js/items/alu10.js new file mode 100755 index 0000000..04274f8 --- /dev/null +++ b/build/editor/js/items/alu10.js @@ -0,0 +1,5 @@ +function loadChip(){ + chip=new Component('main',true,'{"type":"main","inputs":12,"tooltips":[],"pins":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"subComponents":[],"positions":[],"wires":[]}'); + chip.groups = [[0,1,2,3,4,5,6,7],[8,9,10],[12,13,14,15,16,17,18,19]]; + chip.tooltips = ["input","input","input","input","input","input","input","input","shift by","shift by","shift by","left/right?","output","output","output","output","output","output","output","output"]; +} diff --git a/build/editor/js/items/alu11.js b/build/editor/js/items/alu11.js new file mode 100755 index 0000000..bfd8781 --- /dev/null +++ b/build/editor/js/items/alu11.js @@ -0,0 +1,5 @@ +function loadChip(){ + chip=new Component('main',true,'{"type":"main","inputs":18,"tooltips":[],"pins":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"subComponents":[],"positions":[],"wires":[]}'); + chip.groups = [[0,1,2,3,4,5,6,7],[8,9,10,11,12,13,14,15],[18,19,20,21,22,23,24,25]]; + chip.tooltips = ["A","A","A","A","A","A","A","A","B","B","B","B","B","B","B","B","operation select - nand/xor or shift", "operation select - nand/left or xor/right","result","result","result","result","result","result","result","result"]; +} diff --git a/build/editor/js/items/alu2.js b/build/editor/js/items/alu2.js new file mode 100755 index 0000000..89887dc --- /dev/null +++ b/build/editor/js/items/alu2.js @@ -0,0 +1,5 @@ +function loadChip(){ + chip=new Component('main',true,'{"type":"main","inputs":3,"tooltips":[],"pins":[0,0,0,0,0],"subComponents":[],"positions":[],"wires":[]}'); + chip.groups = [[0],[1],[2],[3],[4]]; + chip.tooltips = ["A","B","carry in", "sum", "carry out"]; +} diff --git a/build/editor/js/items/alu3.js b/build/editor/js/items/alu3.js new file mode 100755 index 0000000..f7451b1 --- /dev/null +++ b/build/editor/js/items/alu3.js @@ -0,0 +1,5 @@ +function loadChip(){ + chip=new Component('main',true,'{"type":"main","inputs":17,"tooltips":[],"pins":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"subComponents":[],"positions":[],"wires":[]}'); + chip.groups = [[0,1,2,3,4,5,6,7],[8,9,10,11,12,13,14,15],[16],[17,18,19,20,21,22,23,24],[25]]; + chip.tooltips = ["A","A","A","A","A","A","A","A","B","B","B","B","B","B","B","B","carry in","sum","sum","sum","sum","sum","sum","sum","sum","carry out"]; +} diff --git a/build/editor/js/items/alu4.js b/build/editor/js/items/alu4.js new file mode 100755 index 0000000..84c02e9 --- /dev/null +++ b/build/editor/js/items/alu4.js @@ -0,0 +1,5 @@ +function loadChip(){ + chip=new Component('main',true,'{"type":"main","inputs":8,"tooltips":[],"pins":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"subComponents":[],"positions":[],"wires":[]}'); + chip.groups = [[0,1,2,3,4,5,6,7],[8,9,10,11,12,13,14,15]]; + chip.tooltips = ["input","input","input","input","input","input","input","input","output","output","output","output","output","output","output","output"]; +} diff --git a/build/editor/js/items/alu5.js b/build/editor/js/items/alu5.js new file mode 100755 index 0000000..a1f9743 --- /dev/null +++ b/build/editor/js/items/alu5.js @@ -0,0 +1,5 @@ +function loadChip(){ + chip=new Component('main',true,'{"type":"main","inputs":17,"tooltips":[],"pins":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"subComponents":[],"positions":[],"wires":[]}'); + chip.groups = [[0,1,2,3,4,5,6,7],[8,9,10,11,12,13,14,15],[16],[17,18,19,20,21,22,23,24],[25]]; + chip.tooltips = ["A","A","A","A","A","A","A","A","B","B","B","B","B","B","B","B","borrow in","difference","difference","difference","difference","difference","difference","difference","difference","borrow out"]; +} diff --git a/build/editor/js/items/alu6.js b/build/editor/js/items/alu6.js new file mode 100755 index 0000000..5658827 --- /dev/null +++ b/build/editor/js/items/alu6.js @@ -0,0 +1,5 @@ +function loadChip(){ + chip=new Component('main',true,'{"type":"main","inputs":18,"tooltips":[],"pins":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"subComponents":[],"positions":[],"wires":[]}'); + chip.groups = [[0,1,2,3,4,5,6,7],[8,9,10,11,12,13,14,15],[16],[18,19,20,21,22,23,24,25],[26]]; + chip.tooltips = ["A","A","A","A","A","A","A","A","B","B","B","B","B","B","B","B","carry/borrow in","operation select","result","result","result","result","result","result","result","result","carry/borrow out"]; +} diff --git a/build/editor/js/items/alu7.js b/build/editor/js/items/alu7.js new file mode 100755 index 0000000..94d7c3e --- /dev/null +++ b/build/editor/js/items/alu7.js @@ -0,0 +1,5 @@ +function loadChip(){ + chip=new Component('main',true,'{"type":"main","inputs":3,"tooltips":[],"pins":[0,0,0,0],"subComponents":[],"positions":[],"wires":[]}'); + chip.groups = []; + chip.tooltips = ["A","B","nand/xor?","output"]; +} diff --git a/build/editor/js/items/alu8.5.js b/build/editor/js/items/alu8.5.js new file mode 100755 index 0000000..a9080fd --- /dev/null +++ b/build/editor/js/items/alu8.5.js @@ -0,0 +1,5 @@ +function loadChip(){ + chip=new Component('main',true,'{"type":"main","inputs":16,"tooltips":[],"pins":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"subComponents":[],"positions":[],"wires":[]}'); + chip.groups = [[0,1,2,3,4,5,6,7],[8,9,10,11,12,13,14,15]]; + chip.tooltips = ["A","A","A","A","A","A","A","A","B","B","B","B","B","B","B","B","output"]; +} diff --git a/build/editor/js/items/alu8.js b/build/editor/js/items/alu8.js new file mode 100755 index 0000000..cb4c9d8 --- /dev/null +++ b/build/editor/js/items/alu8.js @@ -0,0 +1,5 @@ +function loadChip(){ + chip=new Component('main',true,'{"type":"main","inputs":17,"tooltips":[],"pins":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"subComponents":[],"positions":[],"wires":[]}'); + chip.groups = [[0,1,2,3,4,5,6,7],[8,9,10,11,12,13,14,15],[17,18,19,20,21,22,23,24]]; + chip.tooltips = ["A","A","A","A","A","A","A","A","B","B","B","B","B","B","B","B","nand/nor?","output","output","output","output","output","output","output","output"]; +} diff --git a/build/editor/js/items/alu9.js b/build/editor/js/items/alu9.js new file mode 100755 index 0000000..1cd809f --- /dev/null +++ b/build/editor/js/items/alu9.js @@ -0,0 +1,5 @@ +function loadChip(){ + chip=new Component('main',true,'{"type":"main","inputs":9,"tooltips":[],"pins":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"subComponents":[],"positions":[],"wires":[]}'); + chip.groups = [[0,1,2,3,4,5,6,7],[9,10,11,12,13,14,15,16]]; + chip.tooltips = ["input","input","input","input","input","input","input","input","left/right?","output","output","output","output","output","output","output","output"]; +} diff --git a/build/editor/js/items/md5.js b/build/editor/js/items/md5.js new file mode 100755 index 0000000..e69de29 diff --git a/build/editor/js/items/mux1.js b/build/editor/js/items/mux1.js new file mode 100755 index 0000000..2afda38 --- /dev/null +++ b/build/editor/js/items/mux1.js @@ -0,0 +1,5 @@ +function loadChip(){ + chip=new Component('main',true,'{"type":"main","inputs":3,"tooltips":[],"pins":[0,0,0,0],"subComponents":[],"positions":[],"wires":[]}'); + chip.groups = [[2]] + chip.tooltips = ["A","B","select", "output"] +} diff --git a/build/editor/js/items/mux2.js b/build/editor/js/items/mux2.js new file mode 100755 index 0000000..2ee8b01 --- /dev/null +++ b/build/editor/js/items/mux2.js @@ -0,0 +1,5 @@ +function loadChip(){ + chip=new Component('main',true,'{"type":"main","inputs":17,"tooltips":[],"pins":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"subComponents":[],"positions":[],"wires":[]}'); + chip.groups = [[0,1,2,3,4,5,6,7],[8,9,10,11,12,13,14,15], [16], [17,18,19,20,21,22,23,24]] + chip.tooltips = ["A","A","A","A","A","A","A","A","B","B","B","B","B","B","B","B","select","output","output","output","output","output","output","output", "output"] +} diff --git a/build/editor/js/items/mux3.js b/build/editor/js/items/mux3.js new file mode 100755 index 0000000..5e7e7f5 --- /dev/null +++ b/build/editor/js/items/mux3.js @@ -0,0 +1,5 @@ +function loadChip(){ + chip=new Component('main',true,'{"type":"main","inputs":2,"tooltips":[],"pins":[0,0,0,0],"subComponents":[],"positions":[],"wires":[]}'); + chip.groups = [[1]] + chip.tooltips = ["input","select","output A", "output B"] +} diff --git a/build/editor/js/items/mux4.js b/build/editor/js/items/mux4.js new file mode 100755 index 0000000..65c881d --- /dev/null +++ b/build/editor/js/items/mux4.js @@ -0,0 +1,5 @@ +function loadChip(){ + chip=new Component('main',true,'{"type":"main","inputs":4,"tooltips":[],"pins":[0,0,0,0,0,0,0,0,0,0,0,0],"subComponents":[],"positions":[],"wires":[]}'); + chip.groups = [[1,2,3]] + chip.tooltips = ["input","select","select","select","output A", "output B", "output C", "output D", "output E", "output F", "output G", "output H"] +} diff --git a/build/editor/js/layouts/21mux.js b/build/editor/js/layouts/21mux.js new file mode 100755 index 0000000..42e7401 --- /dev/null +++ b/build/editor/js/layouts/21mux.js @@ -0,0 +1,6 @@ +function loadChip(){ + chip = new Component("main",true,'{"type":"main","inputs":3,"pins":[0,0,0,0],"subComponents":["and","not","or","and"],"positions":[{"x":255,"y":136},{"x":126,"y":364},{"x":536,"y":179},{"x":291,"y":240}],"wires":[{"source":{"component":0,"pin":2},"destination":{"component":2,"pin":0},"wireId":0},{"source":{"component":2,"pin":1},"destination":{"component":1,"pin":1},"wireId":1},{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0},"wireId":2},{"source":{"component":1,"pin":2},"destination":{"component":3,"pin":0},"wireId":3},{"source":{"component":0,"pin":1},"destination":{"component":4,"pin":0},"wireId":4},{"source":{"component":0,"pin":2},"destination":{"component":4,"pin":1},"wireId":5},{"source":{"component":4,"pin":2},"destination":{"component":3,"pin":1},"wireId":6},{"source":{"component":3,"pin":2},"destination":{"component":0,"pin":3},"wireId":7}]}'); +setTimeout(function(){ wireVisuals = JSON.parse( + '[{"wireId":0,"path":[{"component":0,"pin":2,"shift":0,"rev":1},{"component":2,"pin":0,"shift":0,"offset":14}]},{"wireId":1,"path":[{"component":2,"pin":1,"shift":0,"rev":1},{"component":1,"pin":1,"shift":0,"offset":0}]},{"wireId":2,"path":[{"component":0,"pin":0,"shift":0,"rev":1},{"component":1,"pin":0,"shift":0,"offset":0}]},{"wireId":3,"path":[{"component":1,"pin":2,"shift":0,"rev":1},{"component":3,"pin":0,"shift":0,"offset":0}]},{"wireId":4,"path":[{"component":0,"pin":1,"shift":0,"rev":1},{"component":4,"pin":0,"shift":0,"offset":7}]},{"wireId":5,"path":[{"component":0,"pin":2,"shift":0,"rev":1},{"component":4,"pin":1,"shift":0,"offset":14}]},{"wireId":6,"path":[{"component":4,"pin":2,"shift":0,"rev":1},{"component":3,"pin":1,"shift":0,"offset":0}]},{"wireId":7,"path":[{"component":3,"pin":2,"shift":0,"rev":1},{"component":0,"pin":3,"shift":0,"offset":0}]}]'); +},50); +} diff --git a/build/editor/js/layouts/84mux.js b/build/editor/js/layouts/84mux.js new file mode 100755 index 0000000..0ab5d64 --- /dev/null +++ b/build/editor/js/layouts/84mux.js @@ -0,0 +1,7 @@ +function loadChip(){ + chips=JSON.parse('{"nand":{"image":"img/gates/nand.png","inputs":2,"pins":[0,0,0],"subComponents":[],"wires":[]},"not":{"image":"img/gates/not.png","inputs":1,"pins":[0,0],"subComponents":["nand"],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0}},{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":1}},{"source":{"component":1,"pin":2},"destination":{"component":0,"pin":1}}]},"and":{"image":"img/gates/and.png","inputs":2,"pins":[0,0,0],"subComponents":["nand","nand"],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0}},{"source":{"component":0,"pin":1},"destination":{"component":1,"pin":1}},{"source":{"component":1,"pin":2},"destination":{"component":2,"pin":0}},{"source":{"component":1,"pin":2},"destination":{"component":2,"pin":1}},{"source":{"component":2,"pin":2},"destination":{"component":0,"pin":2}}]},"or":{"image":"img/gates/or.png","inputs":2,"pins":[0,0,0],"subComponents":["nand","nand","nand"],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0}},{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":1}},{"source":{"component":0,"pin":1},"destination":{"component":2,"pin":0}},{"source":{"component":0,"pin":1},"destination":{"component":2,"pin":1}},{"source":{"component":1,"pin":2},"destination":{"component":3,"pin":0}},{"source":{"component":2,"pin":2},"destination":{"component":3,"pin":1}},{"source":{"component":3,"pin":2},"destination":{"component":0,"pin":2}}]},"xor":{"image":"img/gates/xor.png","inputs":2,"pins":[0,0,0],"subComponents":["nand","nand","nand","nand"],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0}},{"source":{"component":0,"pin":1},"destination":{"component":1,"pin":1}},{"source":{"component":0,"pin":0},"destination":{"component":2,"pin":0}},{"source":{"component":1,"pin":2},"destination":{"component":2,"pin":1}},{"source":{"component":1,"pin":2},"destination":{"component":3,"pin":0}},{"source":{"component":0,"pin":1},"destination":{"component":3,"pin":1}},{"source":{"component":2,"pin":2},"destination":{"component":4,"pin":0}},{"source":{"component":3,"pin":2},"destination":{"component":4,"pin":1}},{"source":{"component":4,"pin":2},"destination":{"component":0,"pin":2}}]},"nor":{"inputs":2,"image":"img/gates/nor.png","pins":[0,0,0],"subComponents":["or","not"],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0}},{"source":{"component":0,"pin":1},"destination":{"component":1,"pin":1}},{"source":{"component":1,"pin":2},"destination":{"component":2,"pin":0}},{"source":{"component":2,"pin":1},"destination":{"component":0,"pin":2}}]},"xnor":{"inputs":2,"image":"img/gates/xnor.png","pins":[0,0,0],"subComponents":["xor","not"],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0}},{"source":{"component":0,"pin":1},"destination":{"component":1,"pin":1}},{"source":{"component":1,"pin":2},"destination":{"component":2,"pin":0}},{"source":{"component":2,"pin":1},"destination":{"component":0,"pin":2}}]},"2-1 mux":{"type":"2-1 mux","inputs":3,"pins":[0,0,0,0],"subComponents":["and","not","or","and"],"positions":[{"x":255,"y":136},{"x":126,"y":364},{"x":536,"y":179},{"x":291,"y":240}],"wires":[{"source":{"component":0,"pin":2},"destination":{"component":2,"pin":0},"wireId":0},{"source":{"component":2,"pin":1},"destination":{"component":1,"pin":1},"wireId":1},{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0},"wireId":2},{"source":{"component":1,"pin":2},"destination":{"component":3,"pin":0},"wireId":3},{"source":{"component":0,"pin":1},"destination":{"component":4,"pin":0},"wireId":4},{"source":{"component":0,"pin":2},"destination":{"component":4,"pin":1},"wireId":5},{"source":{"component":4,"pin":2},"destination":{"component":3,"pin":1},"wireId":6},{"source":{"component":3,"pin":2},"destination":{"component":0,"pin":3},"wireId":7}]}}'); + chip = new Component("main",true,'{"type":"main","inputs":9,"pins":[0,0,0,0,0,0,0,0,0,0,0,0,0],"subComponents":["2-1 mux","2-1 mux","2-1 mux","2-1 mux"],"positions":[{"x":259,"y":17},{"x":438,"y":112},{"x":590,"y":194},{"x":610,"y":296}],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0},"wireId":0},{"source":{"component":0,"pin":8},"destination":{"component":1,"pin":2},"wireId":2},{"source":{"component":0,"pin":4},"destination":{"component":1,"pin":1},"wireId":3},{"source":{"component":0,"pin":1},"destination":{"component":2,"pin":0},"wireId":4},{"source":{"component":0,"pin":5},"destination":{"component":2,"pin":1},"wireId":5},{"source":{"component":1,"pin":3},"destination":{"component":0,"pin":9},"wireId":6},{"source":{"component":2,"pin":3},"destination":{"component":0,"pin":10},"wireId":7},{"source":{"component":3,"pin":3},"destination":{"component":0,"pin":11},"wireId":8},{"source":{"component":0,"pin":8},"destination":{"component":2,"pin":2},"wireId":9},{"source":{"component":0,"pin":2},"destination":{"component":3,"pin":0},"wireId":10},{"source":{"component":0,"pin":6},"destination":{"component":3,"pin":1},"wireId":11},{"source":{"component":0,"pin":8},"destination":{"component":3,"pin":2},"wireId":12},{"source":{"component":0,"pin":3},"destination":{"component":4,"pin":0},"wireId":13},{"source":{"component":0,"pin":7},"destination":{"component":4,"pin":1},"wireId":14},{"source":{"component":0,"pin":8},"destination":{"component":4,"pin":2},"wireId":15},{"source":{"component":4,"pin":3},"destination":{"component":0,"pin":12},"wireId":16}]}'); +setTimeout(function(){ wireVisuals = JSON.parse( + '[{"wireId":0,"path":[{"component":0,"pin":0,"shift":false,"rev":1},{"component":1,"pin":0,"shift":false,"offset":0}]},{"wireId":2,"path":[{"component":1,"pin":2,"shift":false,"rev":-1},{"component":0,"pin":8,"shift":false,"offset":14}]},{"wireId":3,"path":[{"component":0,"pin":4,"shift":false,"rev":1},{"component":1,"pin":1,"shift":false,"offset":28}]},{"wireId":4,"path":[{"component":0,"pin":1,"shift":false,"rev":1},{"component":2,"pin":0,"shift":false,"offset":7}]},{"wireId":5,"path":[{"component":0,"pin":5,"shift":false,"rev":1},{"component":2,"pin":1,"shift":false,"offset":35}]},{"wireId":6,"path":[{"component":1,"pin":3,"shift":false,"rev":1},{"component":0,"pin":9,"shift":false,"offset":0}]},{"wireId":7,"path":[{"component":2,"pin":3,"shift":false,"rev":1},{"component":0,"pin":10,"shift":false,"offset":0}]},{"wireId":8,"path":[{"component":3,"pin":3,"shift":false,"rev":1},{"component":0,"pin":11,"shift":false,"offset":0}]},{"wireId":9,"path":[{"component":2,"pin":2,"shift":false,"rev":-1},{"component":0,"pin":8,"shift":false,"offset":14}]},{"wireId":10,"path":[{"component":3,"pin":0,"shift":false,"rev":-1},{"component":0,"pin":2,"shift":false,"offset":0}]},{"wireId":11,"path":[{"component":0,"pin":6,"shift":false,"rev":1},{"component":3,"pin":1,"shift":false,"offset":42}]},{"wireId":12,"path":[{"component":3,"pin":2,"shift":false,"rev":-1},{"component":0,"pin":8,"shift":false,"offset":14}]},{"wireId":13,"path":[{"component":0,"pin":3,"shift":false,"rev":1},{"component":4,"pin":0,"shift":false,"offset":21}]},{"wireId":14,"path":[{"component":0,"pin":7,"shift":false,"rev":1},{"component":4,"pin":1,"shift":false,"offset":49}]},{"wireId":15,"path":[{"component":4,"pin":2,"shift":false,"rev":-1},{"component":0,"pin":8,"shift":false,"offset":14}]},{"wireId":16,"path":[{"component":4,"pin":3,"shift":false,"rev":1},{"component":0,"pin":12,"shift":false,"offset":0}]}]'); +},50); +} diff --git a/build/editor/js/layouts/addsub.js b/build/editor/js/layouts/addsub.js new file mode 100755 index 0000000..6763354 --- /dev/null +++ b/build/editor/js/layouts/addsub.js @@ -0,0 +1,7 @@ +function loadChip(){ + chips = JSON.parse('{"nand":{"image":"img/gates/nand.png","inputs":2,"pins":[0,0,0],"subComponents":[],"wires":[]},"not":{"image":"img/gates/not.png","inputs":1,"pins":[0,0],"subComponents":["nand"],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0}},{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":1}},{"source":{"component":1,"pin":2},"destination":{"component":0,"pin":1}}]},"and":{"image":"img/gates/and.png","inputs":2,"pins":[0,0,0],"subComponents":["nand","nand"],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0}},{"source":{"component":0,"pin":1},"destination":{"component":1,"pin":1}},{"source":{"component":1,"pin":2},"destination":{"component":2,"pin":0}},{"source":{"component":1,"pin":2},"destination":{"component":2,"pin":1}},{"source":{"component":2,"pin":2},"destination":{"component":0,"pin":2}}]},"or":{"image":"img/gates/or.png","inputs":2,"pins":[0,0,0],"subComponents":["nand","nand","nand"],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0}},{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":1}},{"source":{"component":0,"pin":1},"destination":{"component":2,"pin":0}},{"source":{"component":0,"pin":1},"destination":{"component":2,"pin":1}},{"source":{"component":1,"pin":2},"destination":{"component":3,"pin":0}},{"source":{"component":2,"pin":2},"destination":{"component":3,"pin":1}},{"source":{"component":3,"pin":2},"destination":{"component":0,"pin":2}}]},"xor":{"image":"img/gates/xor.png","inputs":2,"pins":[0,0,0],"subComponents":["nand","nand","nand","nand"],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0}},{"source":{"component":0,"pin":1},"destination":{"component":1,"pin":1}},{"source":{"component":0,"pin":0},"destination":{"component":2,"pin":0}},{"source":{"component":1,"pin":2},"destination":{"component":2,"pin":1}},{"source":{"component":1,"pin":2},"destination":{"component":3,"pin":0}},{"source":{"component":0,"pin":1},"destination":{"component":3,"pin":1}},{"source":{"component":2,"pin":2},"destination":{"component":4,"pin":0}},{"source":{"component":3,"pin":2},"destination":{"component":4,"pin":1}},{"source":{"component":4,"pin":2},"destination":{"component":0,"pin":2}}]},"nor":{"inputs":2,"image":"img/gates/nor.png","pins":[0,0,0],"subComponents":["or","not"],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0}},{"source":{"component":0,"pin":1},"destination":{"component":1,"pin":1}},{"source":{"component":1,"pin":2},"destination":{"component":2,"pin":0}},{"source":{"component":2,"pin":1},"destination":{"component":0,"pin":2}}]},"xnor":{"inputs":2,"image":"img/gates/xnor.png","pins":[0,0,0],"subComponents":["xor","not"],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0}},{"source":{"component":0,"pin":1},"destination":{"component":1,"pin":1}},{"source":{"component":1,"pin":2},"destination":{"component":2,"pin":0}},{"source":{"component":2,"pin":1},"destination":{"component":0,"pin":2}}]},"half adder":{"type":"half adder","inputs":2,"pins":[0,0,0,0],"subComponents":["and","xor"],"positions":[{"x":413,"y":299},{"x":293,"y":132}],"wires":[{"source":{"component":0,"pin":1},"destination":{"component":1,"pin":1},"wireId":0},{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0},"wireId":1},{"source":{"component":1,"pin":2},"destination":{"component":0,"pin":3},"wireId":2},{"source":{"component":0,"pin":1},"destination":{"component":2,"pin":1},"wireId":3},{"source":{"component":0,"pin":0},"destination":{"component":2,"pin":0},"wireId":4},{"source":{"component":2,"pin":2},"destination":{"component":0,"pin":2},"wireId":5}]},"full adder":{"type":"full adder","inputs":3,"pins":[0,0,0,0,0],"subComponents":["half adder","half adder","or"],"positions":[{"x":110,"y":127},{"x":403,"y":212},{"x":827,"y":287}],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0},"wireId":6},{"source":{"component":0,"pin":1},"destination":{"component":1,"pin":1},"wireId":7},{"source":{"component":1,"pin":2},"destination":{"component":2,"pin":0},"wireId":8},{"source":{"component":0,"pin":2},"destination":{"component":2,"pin":1},"wireId":9},{"source":{"component":2,"pin":2},"destination":{"component":0,"pin":3},"wireId":10},{"source":{"component":1,"pin":3},"destination":{"component":3,"pin":1},"wireId":12},{"source":{"component":2,"pin":3},"destination":{"component":3,"pin":0},"wireId":13},{"source":{"component":3,"pin":2},"destination":{"component":0,"pin":4},"wireId":14}]},"ripple carry adder":{"type":"ripple carry adder","inputs":9,"pins":[0,0,0,0,0,0,0,0,0,0,0,0,0,0],"subComponents":["full adder","full adder","full adder","full adder"],"positions":[{"x":157,"y":30},{"x":364,"y":150},{"x":546,"y":224},{"x":734,"y":300}],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0},"wireId":11},{"source":{"component":0,"pin":4},"destination":{"component":1,"pin":1},"wireId":12},{"source":{"component":0,"pin":8},"destination":{"component":1,"pin":2},"wireId":13},{"source":{"component":0,"pin":1},"destination":{"component":2,"pin":0},"wireId":18},{"source":{"component":1,"pin":4},"destination":{"component":2,"pin":2},"wireId":20},{"source":{"component":0,"pin":5},"destination":{"component":2,"pin":1},"wireId":21},{"source":{"component":1,"pin":3},"destination":{"component":0,"pin":9},"wireId":22},{"source":{"component":2,"pin":3},"destination":{"component":0,"pin":10},"wireId":25},{"source":{"component":2,"pin":4},"destination":{"component":3,"pin":2},"wireId":26},{"source":{"component":0,"pin":2},"destination":{"component":3,"pin":0},"wireId":27},{"source":{"component":0,"pin":6},"destination":{"component":3,"pin":1},"wireId":28},{"source":{"component":3,"pin":3},"destination":{"component":0,"pin":11},"wireId":29},{"source":{"component":3,"pin":4},"destination":{"component":4,"pin":2},"wireId":30},{"source":{"component":0,"pin":7},"destination":{"component":4,"pin":1},"wireId":31},{"source":{"component":0,"pin":3},"destination":{"component":4,"pin":0},"wireId":32},{"source":{"component":4,"pin":3},"destination":{"component":0,"pin":12},"wireId":33},{"source":{"component":4,"pin":4},"destination":{"component":0,"pin":13},"wireId":34}]},"subtractor":{"type":"subtractor","inputs":8,"pins":[0,0,0,0,0,0,0,0,0,0,0,0,0],"subComponents":["ripple carry adder","not","not","not","not","not","not"],"positions":[{"x":405,"y":151},{"x":288,"y":357},{"x":858,"y":341},{"x":147,"y":347},{"x":164,"y":273},{"x":137,"y":201},{"x":135,"y":135}],"wires":[{"source":{"component":2,"pin":1},"destination":{"component":1,"pin":8},"wireId":0},{"source":{"component":3,"pin":1},"destination":{"component":0,"pin":12},"wireId":1},{"source":{"component":1,"pin":13},"destination":{"component":3,"pin":0},"wireId":2},{"source":{"component":1,"pin":9},"destination":{"component":0,"pin":8},"wireId":3},{"source":{"component":1,"pin":10},"destination":{"component":0,"pin":9},"wireId":4},{"source":{"component":1,"pin":11},"destination":{"component":0,"pin":10},"wireId":5},{"source":{"component":1,"pin":12},"destination":{"component":0,"pin":11},"wireId":6},{"source":{"component":0,"pin":7},"destination":{"component":4,"pin":0},"wireId":0},{"source":{"component":4,"pin":1},"destination":{"component":1,"pin":7},"wireId":1},{"source":{"component":0,"pin":6},"destination":{"component":5,"pin":0},"wireId":2},{"source":{"component":5,"pin":1},"destination":{"component":1,"pin":6},"wireId":3},{"source":{"component":6,"pin":1},"destination":{"component":1,"pin":5},"wireId":4},{"source":{"component":0,"pin":5},"destination":{"component":6,"pin":0},"wireId":5},{"source":{"component":0,"pin":4},"destination":{"component":7,"pin":0},"wireId":6},{"source":{"component":7,"pin":1},"destination":{"component":1,"pin":4},"wireId":7},{"source":{"component":0,"pin":3},"destination":{"component":1,"pin":3},"wireId":8},{"source":{"component":0,"pin":2},"destination":{"component":1,"pin":2},"wireId":9},{"source":{"component":0,"pin":1},"destination":{"component":1,"pin":1},"wireId":10},{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0},"wireId":11}]},"2-1 mux":{"type":"2-1 mux","inputs":3,"pins":[0,0,0,0],"subComponents":["not","and","or","and"],"positions":[{"x":161,"y":182},{"x":317,"y":128},{"x":527,"y":198},{"x":263,"y":289}],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":2,"pin":0},"wireId":17},{"source":{"component":0,"pin":2},"destination":{"component":1,"pin":0},"wireId":18},{"source":{"component":1,"pin":1},"destination":{"component":2,"pin":1},"wireId":19},{"source":{"component":2,"pin":2},"destination":{"component":3,"pin":0},"wireId":20},{"source":{"component":0,"pin":1},"destination":{"component":4,"pin":0},"wireId":21},{"source":{"component":0,"pin":2},"destination":{"component":4,"pin":1},"wireId":22},{"source":{"component":4,"pin":2},"destination":{"component":3,"pin":1},"wireId":23},{"source":{"component":3,"pin":2},"destination":{"component":0,"pin":3},"wireId":24}]},"8-4 mux":{"type":"8-4 mux","inputs":9,"pins":[0,0,0,0,0,0,0,0,0,0,0,0,0],"subComponents":["2-1 mux","2-1 mux","2-1 mux","2-1 mux"],"positions":[{"x":279,"y":91},{"x":326,"y":171},{"x":361,"y":249},{"x":497,"y":320}],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0},"wireId":25},{"source":{"component":0,"pin":4},"destination":{"component":1,"pin":1},"wireId":26},{"source":{"component":0,"pin":8},"destination":{"component":1,"pin":2},"wireId":27},{"source":{"component":0,"pin":1},"destination":{"component":2,"pin":0},"wireId":28},{"source":{"component":0,"pin":5},"destination":{"component":2,"pin":1},"wireId":29},{"source":{"component":0,"pin":8},"destination":{"component":2,"pin":2},"wireId":30},{"source":{"component":0,"pin":8},"destination":{"component":3,"pin":2},"wireId":31},{"source":{"component":0,"pin":2},"destination":{"component":3,"pin":0},"wireId":32},{"source":{"component":0,"pin":6},"destination":{"component":3,"pin":1},"wireId":33},{"source":{"component":0,"pin":8},"destination":{"component":4,"pin":2},"wireId":34},{"source":{"component":0,"pin":7},"destination":{"component":4,"pin":1},"wireId":35},{"source":{"component":0,"pin":3},"destination":{"component":4,"pin":0},"wireId":36},{"source":{"component":1,"pin":3},"destination":{"component":0,"pin":9},"wireId":37},{"source":{"component":2,"pin":3},"destination":{"component":0,"pin":10},"wireId":38},{"source":{"component":3,"pin":3},"destination":{"component":0,"pin":11},"wireId":39},{"source":{"component":4,"pin":3},"destination":{"component":0,"pin":12},"wireId":40}]}}'); + chip = new Component("main",true,'{"type":"main","inputs":9,"pins":[0,0,0,0,0,0,0,0,0,0,0,0,0,0],"subComponents":["2-1 mux","subtractor","ripple carry adder","8-4 mux"],"positions":[{"x":642,"y":373},{"x":250,"y":239},{"x":221,"y":57},{"x":672,"y":131}],"wires":[{"source":{"component":1,"pin":3},"destination":{"component":0,"pin":13},"wireId":4},{"source":{"component":0,"pin":0},"destination":{"component":3,"pin":0},"wireId":5},{"source":{"component":0,"pin":1},"destination":{"component":3,"pin":1},"wireId":6},{"source":{"component":0,"pin":2},"destination":{"component":3,"pin":2},"wireId":7},{"source":{"component":0,"pin":3},"destination":{"component":3,"pin":3},"wireId":8},{"source":{"component":0,"pin":4},"destination":{"component":3,"pin":4},"wireId":9},{"source":{"component":0,"pin":5},"destination":{"component":3,"pin":5},"wireId":10},{"source":{"component":0,"pin":6},"destination":{"component":3,"pin":6},"wireId":11},{"source":{"component":0,"pin":7},"destination":{"component":3,"pin":7},"wireId":12},{"source":{"component":0,"pin":8},"destination":{"component":1,"pin":2},"wireId":14},{"source":{"component":4,"pin":9},"destination":{"component":0,"pin":9},"wireId":20},{"source":{"component":4,"pin":10},"destination":{"component":0,"pin":10},"wireId":21},{"source":{"component":4,"pin":11},"destination":{"component":0,"pin":11},"wireId":22},{"source":{"component":4,"pin":12},"destination":{"component":0,"pin":12},"wireId":23},{"source":{"component":0,"pin":8},"destination":{"component":4,"pin":8},"wireId":24},{"source":{"component":3,"pin":9},"destination":{"component":4,"pin":0},"wireId":25},{"source":{"component":3,"pin":10},"destination":{"component":4,"pin":1},"wireId":26},{"source":{"component":3,"pin":11},"destination":{"component":4,"pin":2},"wireId":27},{"source":{"component":3,"pin":12},"destination":{"component":4,"pin":3},"wireId":28},{"source":{"component":3,"pin":13},"destination":{"component":1,"pin":0},"wireId":29}]}'); +setTimeout(function(){ wireVisuals = JSON.parse( +'[{"wireId":4,"path":[{"component":1,"pin":3,"shift":false,"rev":1},{"component":0,"pin":13,"shift":false,"offset":0}]},{"wireId":5,"path":[{"component":0,"pin":0,"shift":false,"rev":1},{"component":3,"pin":0,"shift":false,"offset":0}]},{"wireId":6,"path":[{"component":0,"pin":1,"shift":false,"rev":1},{"component":3,"pin":1,"shift":false,"offset":7}]},{"wireId":7,"path":[{"component":0,"pin":2,"shift":false,"rev":1},{"component":3,"pin":2,"shift":false,"offset":14}]},{"wireId":8,"path":[{"component":0,"pin":3,"shift":false,"rev":1},{"component":3,"pin":3,"shift":false,"offset":21}]},{"wireId":9,"path":[{"component":0,"pin":4,"shift":false,"rev":1},{"component":3,"pin":4,"shift":false,"offset":28}]},{"wireId":10,"path":[{"component":0,"pin":5,"shift":false,"rev":1},{"component":3,"pin":5,"shift":false,"offset":35}]},{"wireId":11,"path":[{"component":0,"pin":6,"shift":false,"rev":1},{"component":3,"pin":6,"shift":false,"offset":42}]},{"wireId":12,"path":[{"component":0,"pin":7,"shift":false,"rev":1},{"component":3,"pin":7,"shift":false,"offset":49}]},{"wireId":14,"path":[{"component":0,"pin":8,"shift":false,"rev":1},{"x":354.085227265954,"y":393.81534092128277,"shift":false,"offset":56},{"component":1,"pin":2,"shift":false,"offset":56}]},{"wireId":20,"path":[{"component":4,"pin":9,"shift":false,"rev":1},{"component":0,"pin":9,"shift":false,"offset":0}]},{"wireId":21,"path":[{"component":4,"pin":10,"shift":false,"rev":1},{"component":0,"pin":10,"shift":false,"offset":7}]},{"wireId":22,"path":[{"component":4,"pin":11,"shift":false,"rev":1},{"component":0,"pin":11,"shift":false,"offset":14}]},{"wireId":23,"path":[{"component":4,"pin":12,"shift":false,"rev":1},{"component":0,"pin":12,"shift":false,"offset":21}]},{"wireId":24,"path":[{"component":4,"pin":8,"shift":false,"rev":-1},{"x":310.085227265954,"y":393.81534092128277,"shift":false,"offset":56},{"component":0,"pin":8,"shift":false,"offset":56}]},{"wireId":25,"path":[{"component":3,"pin":9,"shift":false,"rev":1},{"component":4,"pin":0,"shift":false,"offset":0}]},{"wireId":26,"path":[{"component":3,"pin":10,"shift":false,"rev":1},{"component":4,"pin":1,"shift":false,"offset":7}]},{"wireId":27,"path":[{"component":3,"pin":11,"shift":false,"rev":1},{"component":4,"pin":2,"shift":false,"offset":14}]},{"wireId":28,"path":[{"component":3,"pin":12,"shift":false,"rev":1},{"component":4,"pin":3,"shift":false,"offset":21}]},{"wireId":29,"path":[{"component":3,"pin":13,"shift":false,"rev":1},{"component":1,"pin":0,"shift":false,"offset":28}]}]'); +},50); +} diff --git a/build/editor/js/layouts/alu.js b/build/editor/js/layouts/alu.js new file mode 100755 index 0000000..debb27b --- /dev/null +++ b/build/editor/js/layouts/alu.js @@ -0,0 +1,7 @@ +function loadChip(){ + chips = JSON.parse('{"nand":{"image":"img/gates/nand.png","inputs":2,"pins":[0,0,0],"subComponents":[],"wires":[]},"not":{"image":"img/gates/not.png","inputs":1,"pins":[0,0],"subComponents":["nand"],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0}},{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":1}},{"source":{"component":1,"pin":2},"destination":{"component":0,"pin":1}}]},"and":{"image":"img/gates/and.png","inputs":2,"pins":[0,0,0],"subComponents":["nand","nand"],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0}},{"source":{"component":0,"pin":1},"destination":{"component":1,"pin":1}},{"source":{"component":1,"pin":2},"destination":{"component":2,"pin":0}},{"source":{"component":1,"pin":2},"destination":{"component":2,"pin":1}},{"source":{"component":2,"pin":2},"destination":{"component":0,"pin":2}}]},"or":{"image":"img/gates/or.png","inputs":2,"pins":[0,0,0],"subComponents":["nand","nand","nand"],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0}},{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":1}},{"source":{"component":0,"pin":1},"destination":{"component":2,"pin":0}},{"source":{"component":0,"pin":1},"destination":{"component":2,"pin":1}},{"source":{"component":1,"pin":2},"destination":{"component":3,"pin":0}},{"source":{"component":2,"pin":2},"destination":{"component":3,"pin":1}},{"source":{"component":3,"pin":2},"destination":{"component":0,"pin":2}}]},"xor":{"image":"img/gates/xor.png","inputs":2,"pins":[0,0,0],"subComponents":["nand","nand","nand","nand"],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0}},{"source":{"component":0,"pin":1},"destination":{"component":1,"pin":1}},{"source":{"component":0,"pin":0},"destination":{"component":2,"pin":0}},{"source":{"component":1,"pin":2},"destination":{"component":2,"pin":1}},{"source":{"component":1,"pin":2},"destination":{"component":3,"pin":0}},{"source":{"component":0,"pin":1},"destination":{"component":3,"pin":1}},{"source":{"component":2,"pin":2},"destination":{"component":4,"pin":0}},{"source":{"component":3,"pin":2},"destination":{"component":4,"pin":1}},{"source":{"component":4,"pin":2},"destination":{"component":0,"pin":2}}]},"nor":{"inputs":2,"image":"img/gates/nor.png","pins":[0,0,0],"subComponents":["or","not"],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0}},{"source":{"component":0,"pin":1},"destination":{"component":1,"pin":1}},{"source":{"component":1,"pin":2},"destination":{"component":2,"pin":0}},{"source":{"component":2,"pin":1},"destination":{"component":0,"pin":2}}]},"xnor":{"inputs":2,"image":"img/gates/xnor.png","pins":[0,0,0],"subComponents":["xor","not"],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0}},{"source":{"component":0,"pin":1},"destination":{"component":1,"pin":1}},{"source":{"component":1,"pin":2},"destination":{"component":2,"pin":0}},{"source":{"component":2,"pin":1},"destination":{"component":0,"pin":2}}]},"half adder":{"type":"half adder","inputs":2,"pins":[0,0,0,0],"subComponents":["and","xor"],"positions":[{"x":413,"y":299},{"x":293,"y":132}],"wires":[{"source":{"component":0,"pin":1},"destination":{"component":1,"pin":1},"wireId":0},{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0},"wireId":1},{"source":{"component":1,"pin":2},"destination":{"component":0,"pin":3},"wireId":2},{"source":{"component":0,"pin":1},"destination":{"component":2,"pin":1},"wireId":3},{"source":{"component":0,"pin":0},"destination":{"component":2,"pin":0},"wireId":4},{"source":{"component":2,"pin":2},"destination":{"component":0,"pin":2},"wireId":5}]},"full adder":{"type":"full adder","inputs":3,"pins":[0,0,0,0,0],"subComponents":["half adder","half adder","or"],"positions":[{"x":110,"y":127},{"x":403,"y":212},{"x":827,"y":287}],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0},"wireId":6},{"source":{"component":0,"pin":1},"destination":{"component":1,"pin":1},"wireId":7},{"source":{"component":1,"pin":2},"destination":{"component":2,"pin":0},"wireId":8},{"source":{"component":0,"pin":2},"destination":{"component":2,"pin":1},"wireId":9},{"source":{"component":2,"pin":2},"destination":{"component":0,"pin":3},"wireId":10},{"source":{"component":1,"pin":3},"destination":{"component":3,"pin":1},"wireId":12},{"source":{"component":2,"pin":3},"destination":{"component":3,"pin":0},"wireId":13},{"source":{"component":3,"pin":2},"destination":{"component":0,"pin":4},"wireId":14}]},"ripple carry adder":{"type":"ripple carry adder","inputs":9,"pins":[0,0,0,0,0,0,0,0,0,0,0,0,0,0],"subComponents":["full adder","full adder","full adder","full adder"],"positions":[{"x":157,"y":30},{"x":364,"y":150},{"x":546,"y":224},{"x":734,"y":300}],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0},"wireId":11},{"source":{"component":0,"pin":4},"destination":{"component":1,"pin":1},"wireId":12},{"source":{"component":0,"pin":8},"destination":{"component":1,"pin":2},"wireId":13},{"source":{"component":0,"pin":1},"destination":{"component":2,"pin":0},"wireId":18},{"source":{"component":1,"pin":4},"destination":{"component":2,"pin":2},"wireId":20},{"source":{"component":0,"pin":5},"destination":{"component":2,"pin":1},"wireId":21},{"source":{"component":1,"pin":3},"destination":{"component":0,"pin":9},"wireId":22},{"source":{"component":2,"pin":3},"destination":{"component":0,"pin":10},"wireId":25},{"source":{"component":2,"pin":4},"destination":{"component":3,"pin":2},"wireId":26},{"source":{"component":0,"pin":2},"destination":{"component":3,"pin":0},"wireId":27},{"source":{"component":0,"pin":6},"destination":{"component":3,"pin":1},"wireId":28},{"source":{"component":3,"pin":3},"destination":{"component":0,"pin":11},"wireId":29},{"source":{"component":3,"pin":4},"destination":{"component":4,"pin":2},"wireId":30},{"source":{"component":0,"pin":7},"destination":{"component":4,"pin":1},"wireId":31},{"source":{"component":0,"pin":3},"destination":{"component":4,"pin":0},"wireId":32},{"source":{"component":4,"pin":3},"destination":{"component":0,"pin":12},"wireId":33},{"source":{"component":4,"pin":4},"destination":{"component":0,"pin":13},"wireId":34}]},"subtractor":{"type":"subtractor","inputs":8,"pins":[0,0,0,0,0,0,0,0,0,0,0,0,0],"subComponents":["ripple carry adder","not","not","not","not","not","not"],"positions":[{"x":405,"y":151},{"x":288,"y":357},{"x":858,"y":341},{"x":147,"y":347},{"x":164,"y":273},{"x":137,"y":201},{"x":135,"y":135}],"wires":[{"source":{"component":2,"pin":1},"destination":{"component":1,"pin":8},"wireId":0},{"source":{"component":3,"pin":1},"destination":{"component":0,"pin":12},"wireId":1},{"source":{"component":1,"pin":13},"destination":{"component":3,"pin":0},"wireId":2},{"source":{"component":1,"pin":9},"destination":{"component":0,"pin":8},"wireId":3},{"source":{"component":1,"pin":10},"destination":{"component":0,"pin":9},"wireId":4},{"source":{"component":1,"pin":11},"destination":{"component":0,"pin":10},"wireId":5},{"source":{"component":1,"pin":12},"destination":{"component":0,"pin":11},"wireId":6},{"source":{"component":0,"pin":7},"destination":{"component":4,"pin":0},"wireId":0},{"source":{"component":4,"pin":1},"destination":{"component":1,"pin":7},"wireId":1},{"source":{"component":0,"pin":6},"destination":{"component":5,"pin":0},"wireId":2},{"source":{"component":5,"pin":1},"destination":{"component":1,"pin":6},"wireId":3},{"source":{"component":6,"pin":1},"destination":{"component":1,"pin":5},"wireId":4},{"source":{"component":0,"pin":5},"destination":{"component":6,"pin":0},"wireId":5},{"source":{"component":0,"pin":4},"destination":{"component":7,"pin":0},"wireId":6},{"source":{"component":7,"pin":1},"destination":{"component":1,"pin":4},"wireId":7},{"source":{"component":0,"pin":3},"destination":{"component":1,"pin":3},"wireId":8},{"source":{"component":0,"pin":2},"destination":{"component":1,"pin":2},"wireId":9},{"source":{"component":0,"pin":1},"destination":{"component":1,"pin":1},"wireId":10},{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0},"wireId":11}]},"2-1 mux":{"type":"2-1 mux","inputs":3,"pins":[0,0,0,0],"subComponents":["not","and","or","and"],"positions":[{"x":161,"y":182},{"x":317,"y":128},{"x":527,"y":198},{"x":263,"y":289}],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":2,"pin":0},"wireId":17},{"source":{"component":0,"pin":2},"destination":{"component":1,"pin":0},"wireId":18},{"source":{"component":1,"pin":1},"destination":{"component":2,"pin":1},"wireId":19},{"source":{"component":2,"pin":2},"destination":{"component":3,"pin":0},"wireId":20},{"source":{"component":0,"pin":1},"destination":{"component":4,"pin":0},"wireId":21},{"source":{"component":0,"pin":2},"destination":{"component":4,"pin":1},"wireId":22},{"source":{"component":4,"pin":2},"destination":{"component":3,"pin":1},"wireId":23},{"source":{"component":3,"pin":2},"destination":{"component":0,"pin":3},"wireId":24}]},"8-4 mux":{"type":"8-4 mux","inputs":9,"pins":[0,0,0,0,0,0,0,0,0,0,0,0,0],"subComponents":["2-1 mux","2-1 mux","2-1 mux","2-1 mux"],"positions":[{"x":279,"y":91},{"x":326,"y":171},{"x":361,"y":249},{"x":497,"y":320}],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0},"wireId":25},{"source":{"component":0,"pin":4},"destination":{"component":1,"pin":1},"wireId":26},{"source":{"component":0,"pin":8},"destination":{"component":1,"pin":2},"wireId":27},{"source":{"component":0,"pin":1},"destination":{"component":2,"pin":0},"wireId":28},{"source":{"component":0,"pin":5},"destination":{"component":2,"pin":1},"wireId":29},{"source":{"component":0,"pin":8},"destination":{"component":2,"pin":2},"wireId":30},{"source":{"component":0,"pin":8},"destination":{"component":3,"pin":2},"wireId":31},{"source":{"component":0,"pin":2},"destination":{"component":3,"pin":0},"wireId":32},{"source":{"component":0,"pin":6},"destination":{"component":3,"pin":1},"wireId":33},{"source":{"component":0,"pin":8},"destination":{"component":4,"pin":2},"wireId":34},{"source":{"component":0,"pin":7},"destination":{"component":4,"pin":1},"wireId":35},{"source":{"component":0,"pin":3},"destination":{"component":4,"pin":0},"wireId":36},{"source":{"component":1,"pin":3},"destination":{"component":0,"pin":9},"wireId":37},{"source":{"component":2,"pin":3},"destination":{"component":0,"pin":10},"wireId":38},{"source":{"component":3,"pin":3},"destination":{"component":0,"pin":11},"wireId":39},{"source":{"component":4,"pin":3},"destination":{"component":0,"pin":12},"wireId":40}]},"add/sub unit":{"type":"add/sub unit","inputs":9,"pins":[0,0,0,0,0,0,0,0,0,0,0,0,0,0],"subComponents":["2-1 mux","subtractor","ripple carry adder","8-4 mux"],"positions":[{"x":642,"y":373},{"x":250,"y":239},{"x":221,"y":57},{"x":672,"y":131}],"wires":[{"source":{"component":1,"pin":3},"destination":{"component":0,"pin":13},"wireId":4},{"source":{"component":0,"pin":0},"destination":{"component":3,"pin":0},"wireId":5},{"source":{"component":0,"pin":1},"destination":{"component":3,"pin":1},"wireId":6},{"source":{"component":0,"pin":2},"destination":{"component":3,"pin":2},"wireId":7},{"source":{"component":0,"pin":3},"destination":{"component":3,"pin":3},"wireId":8},{"source":{"component":0,"pin":4},"destination":{"component":3,"pin":4},"wireId":9},{"source":{"component":0,"pin":5},"destination":{"component":3,"pin":5},"wireId":10},{"source":{"component":0,"pin":6},"destination":{"component":3,"pin":6},"wireId":11},{"source":{"component":0,"pin":7},"destination":{"component":3,"pin":7},"wireId":12},{"source":{"component":0,"pin":8},"destination":{"component":1,"pin":2},"wireId":14},{"source":{"component":4,"pin":9},"destination":{"component":0,"pin":9},"wireId":20},{"source":{"component":4,"pin":10},"destination":{"component":0,"pin":10},"wireId":21},{"source":{"component":4,"pin":11},"destination":{"component":0,"pin":11},"wireId":22},{"source":{"component":4,"pin":12},"destination":{"component":0,"pin":12},"wireId":23},{"source":{"component":0,"pin":8},"destination":{"component":4,"pin":8},"wireId":24},{"source":{"component":3,"pin":9},"destination":{"component":4,"pin":0},"wireId":25},{"source":{"component":3,"pin":10},"destination":{"component":4,"pin":1},"wireId":26},{"source":{"component":3,"pin":11},"destination":{"component":4,"pin":2},"wireId":27},{"source":{"component":3,"pin":12},"destination":{"component":4,"pin":3},"wireId":28},{"source":{"component":3,"pin":13},"destination":{"component":1,"pin":0},"wireId":29},{"source":{"component":0,"pin":0},"destination":{"component":2,"pin":0},"wireId":0},{"source":{"component":0,"pin":1},"destination":{"component":2,"pin":1},"wireId":1},{"source":{"component":0,"pin":2},"destination":{"component":2,"pin":2},"wireId":2},{"source":{"component":0,"pin":3},"destination":{"component":2,"pin":3},"wireId":3},{"source":{"component":0,"pin":4},"destination":{"component":2,"pin":4},"wireId":4},{"source":{"component":0,"pin":5},"destination":{"component":2,"pin":5},"wireId":5},{"source":{"component":0,"pin":6},"destination":{"component":2,"pin":6},"wireId":6},{"source":{"component":0,"pin":7},"destination":{"component":2,"pin":7},"wireId":7},{"source":{"component":2,"pin":8},"destination":{"component":4,"pin":4},"wireId":8},{"source":{"component":2,"pin":9},"destination":{"component":4,"pin":5},"wireId":9},{"source":{"component":2,"pin":10},"destination":{"component":4,"pin":6},"wireId":10},{"source":{"component":2,"pin":11},"destination":{"component":4,"pin":7},"wireId":11},{"source":{"component":2,"pin":12},"destination":{"component":1,"pin":1},"wireId":12}]},"bitwise and":{"type":"bitwise and","inputs":8,"pins":[0,0,0,0,0,0,0,0,0,0,0,0],"subComponents":["and","and","and","and"],"positions":[{"x":315,"y":190},{"x":380,"y":311},{"x":477,"y":424},{"x":324,"y":86}],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":4,"pin":0},"wireId":13},{"source":{"component":0,"pin":4},"destination":{"component":4,"pin":1},"wireId":14},{"source":{"component":0,"pin":1},"destination":{"component":1,"pin":0},"wireId":15},{"source":{"component":0,"pin":5},"destination":{"component":1,"pin":1},"wireId":16},{"source":{"component":0,"pin":2},"destination":{"component":2,"pin":0},"wireId":17},{"source":{"component":0,"pin":6},"destination":{"component":2,"pin":1},"wireId":18},{"source":{"component":0,"pin":3},"destination":{"component":3,"pin":0},"wireId":19},{"source":{"component":0,"pin":7},"destination":{"component":3,"pin":1},"wireId":20},{"source":{"component":4,"pin":2},"destination":{"component":0,"pin":8},"wireId":21},{"source":{"component":1,"pin":2},"destination":{"component":0,"pin":9},"wireId":22},{"source":{"component":2,"pin":2},"destination":{"component":0,"pin":10},"wireId":23},{"source":{"component":3,"pin":2},"destination":{"component":0,"pin":11},"wireId":24}]},"bitwise xor":{"type":"bitwise xor","inputs":8,"pins":[0,0,0,0,0,0,0,0,0,0,0,0],"subComponents":["xor","xor","xor","xor"],"positions":[{"x":527,"y":220},{"x":680,"y":355},{"x":576,"y":89},{"x":670,"y":520}],"wires":[{"source":{"component":3,"pin":2},"destination":{"component":0,"pin":8},"wireId":25},{"source":{"component":1,"pin":2},"destination":{"component":0,"pin":9},"wireId":26},{"source":{"component":2,"pin":2},"destination":{"component":0,"pin":10},"wireId":27},{"source":{"component":4,"pin":2},"destination":{"component":0,"pin":11},"wireId":28},{"source":{"component":0,"pin":6},"destination":{"component":2,"pin":1},"wireId":29},{"source":{"component":0,"pin":2},"destination":{"component":2,"pin":0},"wireId":30},{"source":{"component":0,"pin":3},"destination":{"component":4,"pin":0},"wireId":31},{"source":{"component":0,"pin":7},"destination":{"component":4,"pin":1},"wireId":32},{"source":{"component":0,"pin":5},"destination":{"component":1,"pin":1},"wireId":33},{"source":{"component":0,"pin":1},"destination":{"component":1,"pin":0},"wireId":34},{"source":{"component":0,"pin":4},"destination":{"component":3,"pin":1},"wireId":35},{"source":{"component":0,"pin":0},"destination":{"component":3,"pin":0},"wireId":36}]}}'); + chip = new Component("main",true,'{"type":"main","inputs":10,"pins":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"subComponents":["add/sub unit","bitwise and","bitwise xor","8-4 mux","not","and","and","and","not","not","not","8-4 mux","2-1 mux"],"positions":[{"x":187,"y":62},{"x":190,"y":234},{"x":195,"y":380},{"x":559,"y":62},{"x":717,"y":543},{"x":1017,"y":508},{"x":829,"y":415},{"x":829,"y":524},{"x":717,"y":475},{"x":716,"y":416},{"x":716,"y":349},{"x":411,"y":293},{"x":1221,"y":426}],"wires":[{"source":{"component":4,"pin":9},"destination":{"component":0,"pin":10},"wireId":37},{"source":{"component":4,"pin":10},"destination":{"component":0,"pin":11},"wireId":38},{"source":{"component":4,"pin":11},"destination":{"component":0,"pin":12},"wireId":39},{"source":{"component":4,"pin":12},"destination":{"component":0,"pin":13},"wireId":40},{"source":{"component":6,"pin":2},"destination":{"component":0,"pin":15},"wireId":41},{"source":{"component":7,"pin":2},"destination":{"component":6,"pin":0},"wireId":42},{"source":{"component":8,"pin":2},"destination":{"component":6,"pin":1},"wireId":43},{"source":{"component":5,"pin":1},"destination":{"component":8,"pin":1},"wireId":44},{"source":{"component":9,"pin":1},"destination":{"component":8,"pin":0},"wireId":45},{"source":{"component":10,"pin":1},"destination":{"component":7,"pin":1},"wireId":46},{"source":{"component":11,"pin":1},"destination":{"component":7,"pin":0},"wireId":47},{"source":{"component":2,"pin":8},"destination":{"component":12,"pin":0},"wireId":49},{"source":{"component":2,"pin":9},"destination":{"component":12,"pin":1},"wireId":50},{"source":{"component":2,"pin":10},"destination":{"component":12,"pin":2},"wireId":51},{"source":{"component":2,"pin":11},"destination":{"component":12,"pin":3},"wireId":52},{"source":{"component":0,"pin":8},"destination":{"component":1,"pin":8},"wireId":53},{"source":{"component":0,"pin":8},"destination":{"component":12,"pin":8},"wireId":54},{"source":{"component":13,"pin":3},"destination":{"component":0,"pin":14},"wireId":55},{"source":{"component":0,"pin":9},"destination":{"component":13,"pin":2},"wireId":56}]}'); +setTimeout(function(){ wireVisuals = JSON.parse( +'[{"wireId":37,"path":[{"component":4,"pin":9,"shift":false,"rev":1},{"component":0,"pin":10,"shift":false,"offset":0}]},{"wireId":38,"path":[{"component":4,"pin":10,"shift":false,"rev":1},{"component":0,"pin":11,"shift":false,"offset":7}]},{"wireId":39,"path":[{"component":4,"pin":11,"shift":false,"rev":1},{"component":0,"pin":12,"shift":false,"offset":14}]},{"wireId":40,"path":[{"component":4,"pin":12,"shift":false,"rev":1},{"component":0,"pin":13,"shift":false,"offset":21}]},{"wireId":41,"path":[{"component":6,"pin":2,"shift":false,"rev":1},{"component":0,"pin":15,"shift":false,"offset":0}]},{"wireId":42,"path":[{"component":7,"pin":2,"shift":false,"rev":1},{"component":6,"pin":0,"shift":false,"offset":0}]},{"wireId":43,"path":[{"component":8,"pin":2,"shift":false,"rev":1},{"component":6,"pin":1,"shift":false,"offset":0}]},{"wireId":44,"path":[{"component":5,"pin":1,"shift":false,"rev":1},{"component":8,"pin":1,"shift":false,"offset":0}]},{"wireId":45,"path":[{"component":9,"pin":1,"shift":false,"rev":1},{"component":8,"pin":0,"shift":false,"offset":0}]},{"wireId":46,"path":[{"component":10,"pin":1,"shift":false,"rev":1},{"component":7,"pin":1,"shift":false,"offset":0}]},{"wireId":47,"path":[{"component":11,"pin":1,"shift":false,"rev":1},{"component":7,"pin":0,"shift":false,"offset":0}]},{"wireId":49,"path":[{"component":12,"pin":0,"shift":false,"rev":-1},{"component":2,"pin":8,"shift":false,"offset":0}]},{"wireId":50,"path":[{"component":12,"pin":1,"shift":false,"rev":-1},{"component":2,"pin":9,"shift":false,"offset":7}]},{"wireId":51,"path":[{"component":12,"pin":2,"shift":false,"rev":-1},{"component":2,"pin":10,"shift":false,"offset":14}]},{"wireId":52,"path":[{"component":12,"pin":3,"shift":false,"rev":-1},{"component":2,"pin":11,"shift":false,"offset":21}]},{"wireId":53,"path":[{"component":0,"pin":8,"shift":false,"rev":1},{"component":1,"pin":8,"shift":false,"offset":56}]},{"wireId":54,"path":[{"component":0,"pin":8,"shift":false,"rev":1},{"x":272.914772734046,"y":528.170454531908,"shift":false,"offset":56},{"component":12,"pin":8,"shift":false,"offset":56}]},{"wireId":55,"path":[{"component":13,"pin":3,"shift":false,"rev":1},{"component":0,"pin":14,"shift":false,"offset":0}]},{"wireId":56,"path":[{"component":0,"pin":9,"shift":false,"rev":1},{"x":512.914772734046,"y":560.170454531908,"shift":false,"offset":63},{"x":742.914772734046,"y":336.17045453190804,"shift":false,"offset":63},{"x":835.914772734046,"y":336.17045453190804,"shift":false,"offset":63},{"x":1036.914772734046,"y":394.17045453190804,"shift":false,"offset":63},{"component":13,"pin":2,"shift":false,"offset":63}]}]'); +},50); +} diff --git a/build/editor/js/layouts/and.js b/build/editor/js/layouts/and.js new file mode 100755 index 0000000..c7494a7 --- /dev/null +++ b/build/editor/js/layouts/and.js @@ -0,0 +1,6 @@ +function loadChip(){ + chip = new Component("main",true,'{"type":"main","inputs":2,"pins":[0,0,0],"subComponents":["and"],"positions":[{"x":300,"y":178}],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0},"wireId":0},{"source":{"component":0,"pin":1},"destination":{"component":1,"pin":1},"wireId":1},{"source":{"component":1,"pin":2},"destination":{"component":0,"pin":2},"wireId":2}]}'); +setTimeout(function(){ wireVisuals = JSON.parse( + '[{"wireId":0,"path":[{"component":1,"pin":0,"shift":false,"rev":-1},{"component":0,"pin":0,"shift":false,"offset":0}]},{"wireId":1,"path":[{"component":0,"pin":1,"shift":false,"rev":1},{"component":1,"pin":1,"shift":false,"offset":7}]},{"wireId":2,"path":[{"component":1,"pin":2,"shift":false,"rev":1},{"component":0,"pin":2,"shift":false,"offset":0}]}]'); +},50); +} diff --git a/build/editor/js/layouts/challenge1.js b/build/editor/js/layouts/challenge1.js new file mode 100755 index 0000000..43f28e0 --- /dev/null +++ b/build/editor/js/layouts/challenge1.js @@ -0,0 +1,6 @@ +function loadChip(){ + chip = new Component("main",true,'{"type":"main","inputs":6,"pins":[0,0,0,0,0,0,0,0,0,0,0],"subComponents":["not","and","xor","and","not","or","not"],"positions":[{"x":124,"y":232},{"x":272,"y":291},{"x":276,"y":163},{"x":689,"y":126},{"x":458,"y":354},{"x":405,"y":22},{"x":878,"y":82}],"wires":[{"source":{"component":0,"pin":2},"destination":{"component":1,"pin":0},"wireId":1},{"source":{"component":1,"pin":1},"destination":{"component":2,"pin":0},"wireId":7},{"source":{"component":2,"pin":2},"destination":{"component":0,"pin":10},"wireId":8},{"source":{"component":0,"pin":4},"destination":{"component":2,"pin":1},"wireId":9},{"source":{"component":1,"pin":1},"destination":{"component":3,"pin":1},"wireId":10},{"source":{"component":0,"pin":1},"destination":{"component":3,"pin":0},"wireId":11},{"source":{"component":3,"pin":2},"destination":{"component":0,"pin":9},"wireId":12},{"source":{"component":0,"pin":0},"destination":{"component":4,"pin":0},"wireId":13},{"source":{"component":0,"pin":5},"destination":{"component":5,"pin":0},"wireId":14},{"source":{"component":5,"pin":1},"destination":{"component":4,"pin":1},"wireId":15},{"source":{"component":4,"pin":2},"destination":{"component":0,"pin":8},"wireId":16},{"source":{"component":0,"pin":5},"destination":{"component":6,"pin":1},"wireId":17},{"source":{"component":0,"pin":3},"destination":{"component":6,"pin":0},"wireId":18},{"source":{"component":6,"pin":2},"destination":{"component":0,"pin":6},"wireId":19},{"source":{"component":4,"pin":2},"destination":{"component":7,"pin":0},"wireId":20},{"source":{"component":7,"pin":1},"destination":{"component":0,"pin":7},"wireId":21}]}'); +setTimeout(function(){ wireVisuals = JSON.parse( + '[{"wireId":1,"path":[{"component":0,"pin":2,"shift":false,"rev":1},{"component":1,"pin":0,"shift":false,"offset":14}]},{"wireId":7,"path":[{"component":1,"pin":1,"shift":false,"rev":1},{"component":2,"pin":0,"shift":false,"offset":0}]},{"wireId":8,"path":[{"component":2,"pin":2,"shift":false,"rev":1},{"component":0,"pin":10,"shift":false,"offset":0}]},{"wireId":9,"path":[{"component":0,"pin":4,"shift":false,"rev":1},{"component":2,"pin":1,"shift":false,"offset":28}]},{"wireId":10,"path":[{"component":1,"pin":1,"shift":false,"rev":1},{"component":3,"pin":1,"shift":false,"offset":0}]},{"wireId":11,"path":[{"component":0,"pin":1,"shift":false,"rev":1},{"component":3,"pin":0,"shift":false,"offset":7}]},{"wireId":12,"path":[{"component":3,"pin":2,"shift":false,"rev":1},{"component":0,"pin":9,"shift":false,"offset":0}]},{"wireId":13,"path":[{"component":0,"pin":0,"shift":false,"rev":1},{"component":4,"pin":0,"shift":false,"offset":0}]},{"wireId":14,"path":[{"component":0,"pin":5,"shift":false,"rev":1},{"component":5,"pin":0,"shift":false,"offset":35}]},{"wireId":15,"path":[{"component":5,"pin":1,"shift":false,"rev":1},{"component":4,"pin":1,"shift":false,"offset":0}]},{"wireId":16,"path":[{"component":4,"pin":2,"shift":false,"rev":1},{"component":0,"pin":8,"shift":false,"offset":0}]},{"wireId":17,"path":[{"component":0,"pin":5,"shift":false,"rev":1},{"component":6,"pin":1,"shift":false,"offset":35}]},{"wireId":18,"path":[{"component":0,"pin":3,"shift":false,"rev":1},{"component":6,"pin":0,"shift":false,"offset":21}]},{"wireId":19,"path":[{"component":6,"pin":2,"shift":false,"rev":1},{"component":0,"pin":6,"shift":false,"offset":0}]},{"wireId":20,"path":[{"component":4,"pin":2,"shift":false,"rev":1},{"component":7,"pin":0,"shift":false,"offset":0}]},{"wireId":21,"path":[{"component":7,"pin":1,"shift":false,"rev":1},{"component":0,"pin":7,"shift":false,"offset":0}]}]'); +},50); +} diff --git a/build/editor/js/layouts/fourpin.js b/build/editor/js/layouts/fourpin.js new file mode 100755 index 0000000..08c5d35 --- /dev/null +++ b/build/editor/js/layouts/fourpin.js @@ -0,0 +1,6 @@ +function loadChip(){ + chip = new Component("main",true,'{"type":"main","inputs":2,"pins":[0,0,0,0],"subComponents":[],"positions":[],"wires":[]}'); +setTimeout(function(){ wireVisuals = JSON.parse( + '[]'); +},50); +} diff --git a/build/editor/js/layouts/fulladder.js b/build/editor/js/layouts/fulladder.js new file mode 100755 index 0000000..7aa9f26 --- /dev/null +++ b/build/editor/js/layouts/fulladder.js @@ -0,0 +1,8 @@ +function loadChip(){ + chips = JSON.parse('{"nand":{"image":"img/gates/nand.png","inputs":2,"pins":[0,0,0],"subComponents":[],"wires":[]},"not":{"image":"img/gates/not.png","inputs":1,"pins":[0,0],"subComponents":["nand"],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0}},{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":1}},{"source":{"component":1,"pin":2},"destination":{"component":0,"pin":1}}]},"and":{"image":"img/gates/and.png","inputs":2,"pins":[0,0,0],"subComponents":["nand","nand"],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0}},{"source":{"component":0,"pin":1},"destination":{"component":1,"pin":1}},{"source":{"component":1,"pin":2},"destination":{"component":2,"pin":0}},{"source":{"component":1,"pin":2},"destination":{"component":2,"pin":1}},{"source":{"component":2,"pin":2},"destination":{"component":0,"pin":2}}]},"or":{"image":"img/gates/or.png","inputs":2,"pins":[0,0,0],"subComponents":["nand","nand","nand"],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0}},{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":1}},{"source":{"component":0,"pin":1},"destination":{"component":2,"pin":0}},{"source":{"component":0,"pin":1},"destination":{"component":2,"pin":1}},{"source":{"component":1,"pin":2},"destination":{"component":3,"pin":0}},{"source":{"component":2,"pin":2},"destination":{"component":3,"pin":1}},{"source":{"component":3,"pin":2},"destination":{"component":0,"pin":2}}]},"xor":{"image":"img/gates/xor.png","inputs":2,"pins":[0,0,0],"subComponents":["nand","nand","nand","nand"],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0}},{"source":{"component":0,"pin":1},"destination":{"component":1,"pin":1}},{"source":{"component":0,"pin":0},"destination":{"component":2,"pin":0}},{"source":{"component":1,"pin":2},"destination":{"component":2,"pin":1}},{"source":{"component":1,"pin":2},"destination":{"component":3,"pin":0}},{"source":{"component":0,"pin":1},"destination":{"component":3,"pin":1}},{"source":{"component":2,"pin":2},"destination":{"component":4,"pin":0}},{"source":{"component":3,"pin":2},"destination":{"component":4,"pin":1}},{"source":{"component":4,"pin":2},"destination":{"component":0,"pin":2}}]},"nor":{"inputs":2,"image":"img/gates/nor.png","pins":[0,0,0],"subComponents":["or","not"],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0}},{"source":{"component":0,"pin":1},"destination":{"component":1,"pin":1}},{"source":{"component":1,"pin":2},"destination":{"component":2,"pin":0}},{"source":{"component":2,"pin":1},"destination":{"component":0,"pin":2}}]},"xnor":{"inputs":2,"image":"img/gates/xnor.png","pins":[0,0,0],"subComponents":["xor","not"],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0}},{"source":{"component":0,"pin":1},"destination":{"component":1,"pin":1}},{"source":{"component":1,"pin":2},"destination":{"component":2,"pin":0}},{"source":{"component":2,"pin":1},"destination":{"component":0,"pin":2}}]},"half adder":{"type":"half adder","inputs":2,"pins":[0,0,0,0],"subComponents":["and","xor"],"positions":[{"x":413,"y":299},{"x":293,"y":132}],"wires":[{"source":{"component":0,"pin":1},"destination":{"component":1,"pin":1},"wireId":0},{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0},"wireId":1},{"source":{"component":1,"pin":2},"destination":{"component":0,"pin":3},"wireId":2},{"source":{"component":0,"pin":1},"destination":{"component":2,"pin":1},"wireId":3},{"source":{"component":0,"pin":0},"destination":{"component":2,"pin":0},"wireId":4},{"source":{"component":2,"pin":2},"destination":{"component":0,"pin":2},"wireId":5}]}}'); + + chip = new Component("main",true,'{"type":"main","inputs":3,"pins":[0,0,0,0,0],"subComponents":["half adder","half adder","or"],"positions":[{"x":110,"y":127},{"x":403,"y":212},{"x":827,"y":287}],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0},"wireId":6},{"source":{"component":0,"pin":1},"destination":{"component":1,"pin":1},"wireId":7},{"source":{"component":1,"pin":2},"destination":{"component":2,"pin":0},"wireId":8},{"source":{"component":0,"pin":2},"destination":{"component":2,"pin":1},"wireId":9},{"source":{"component":2,"pin":2},"destination":{"component":0,"pin":3},"wireId":10},{"source":{"component":1,"pin":3},"destination":{"component":3,"pin":1},"wireId":12},{"source":{"component":2,"pin":3},"destination":{"component":3,"pin":0},"wireId":13},{"source":{"component":3,"pin":2},"destination":{"component":0,"pin":4},"wireId":14}]}'); +setTimeout(function(){ wireVisuals = JSON.parse( + '[{"wireId":6,"path":[{"component":0,"pin":0,"shift":false,"rev":1},{"component":1,"pin":0,"shift":false,"offset":0}]},{"wireId":7,"path":[{"component":0,"pin":1,"shift":false,"rev":1},{"component":1,"pin":1,"shift":false,"offset":7}]},{"wireId":8,"path":[{"component":1,"pin":2,"shift":false,"rev":1},{"component":2,"pin":0,"shift":false,"offset":0}]},{"wireId":9,"path":[{"component":0,"pin":2,"shift":false,"rev":1},{"component":2,"pin":1,"shift":false,"offset":14}]},{"wireId":10,"path":[{"component":2,"pin":2,"shift":false,"rev":1},{"component":0,"pin":3,"shift":false,"offset":0}]},{"wireId":12,"path":[{"component":1,"pin":3,"shift":false,"rev":1},{"x":468.085227265954,"y":342.81534092128277,"shift":false,"offset":7},{"component":3,"pin":1,"shift":false,"offset":7}]},{"wireId":13,"path":[{"component":3,"pin":0,"shift":false,"rev":-1},{"component":2,"pin":3,"shift":false,"offset":0}]},{"wireId":14,"path":[{"component":3,"pin":2,"shift":false,"rev":1},{"component":0,"pin":4,"shift":false,"offset":0}]}]' ); +},50); +} diff --git a/build/editor/js/layouts/not.js b/build/editor/js/layouts/not.js new file mode 100755 index 0000000..75de906 --- /dev/null +++ b/build/editor/js/layouts/not.js @@ -0,0 +1,6 @@ +function loadChip(){ + chip = new Component("main",true,'{"type":"main","inputs":1,"pins":[0,0],"subComponents":["not"],"positions":[{"x":300,"y":178}],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0},"wireId":0},{"source":{"component":1,"pin":1},"destination":{"component":0,"pin":1},"wireId":1}]}'); +setTimeout(function(){ wireVisuals = JSON.parse( + '[{"wireId":0,"path":[{"component":1,"pin":0,"shift":false,"rev":-1},{"component":0,"pin":0,"shift":false,"offset":0}]},{"wireId":1,"path":[{"component":1,"pin":1,"shift":false,"rev":1},{"component":0,"pin":1,"shift":false,"offset":0}]}]'); +},50); +} diff --git a/build/editor/js/layouts/or.js b/build/editor/js/layouts/or.js new file mode 100755 index 0000000..0b32f45 --- /dev/null +++ b/build/editor/js/layouts/or.js @@ -0,0 +1,6 @@ +function loadChip(){ + chip = new Component("main",true,'{"type":"main","inputs":2,"pins":[0,0,0],"subComponents":["or"],"positions":[{"x":300,"y":178}],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0},"wireId":0},{"source":{"component":0,"pin":1},"destination":{"component":1,"pin":1},"wireId":1},{"source":{"component":1,"pin":2},"destination":{"component":0,"pin":2},"wireId":2}]}'); +setTimeout(function(){ wireVisuals = JSON.parse( + '[{"wireId":0,"path":[{"component":1,"pin":0,"shift":false,"rev":-1},{"component":0,"pin":0,"shift":false,"offset":0}]},{"wireId":1,"path":[{"component":0,"pin":1,"shift":false,"rev":1},{"component":1,"pin":1,"shift":false,"offset":7}]},{"wireId":2,"path":[{"component":1,"pin":2,"shift":false,"rev":1},{"component":0,"pin":2,"shift":false,"offset":0}]}]'); +},50); +} diff --git a/build/editor/js/layouts/rca.js b/build/editor/js/layouts/rca.js new file mode 100755 index 0000000..8f8f821 --- /dev/null +++ b/build/editor/js/layouts/rca.js @@ -0,0 +1,7 @@ +function loadChip(){ + chips = JSON.parse('{"nand":{"image":"img/gates/nand.png","inputs":2,"pins":[0,0,0],"subComponents":[],"wires":[]},"not":{"image":"img/gates/not.png","inputs":1,"pins":[0,0],"subComponents":["nand"],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0}},{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":1}},{"source":{"component":1,"pin":2},"destination":{"component":0,"pin":1}}]},"and":{"image":"img/gates/and.png","inputs":2,"pins":[0,0,0],"subComponents":["nand","nand"],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0}},{"source":{"component":0,"pin":1},"destination":{"component":1,"pin":1}},{"source":{"component":1,"pin":2},"destination":{"component":2,"pin":0}},{"source":{"component":1,"pin":2},"destination":{"component":2,"pin":1}},{"source":{"component":2,"pin":2},"destination":{"component":0,"pin":2}}]},"or":{"image":"img/gates/or.png","inputs":2,"pins":[0,0,0],"subComponents":["nand","nand","nand"],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0}},{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":1}},{"source":{"component":0,"pin":1},"destination":{"component":2,"pin":0}},{"source":{"component":0,"pin":1},"destination":{"component":2,"pin":1}},{"source":{"component":1,"pin":2},"destination":{"component":3,"pin":0}},{"source":{"component":2,"pin":2},"destination":{"component":3,"pin":1}},{"source":{"component":3,"pin":2},"destination":{"component":0,"pin":2}}]},"xor":{"image":"img/gates/xor.png","inputs":2,"pins":[0,0,0],"subComponents":["nand","nand","nand","nand"],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0}},{"source":{"component":0,"pin":1},"destination":{"component":1,"pin":1}},{"source":{"component":0,"pin":0},"destination":{"component":2,"pin":0}},{"source":{"component":1,"pin":2},"destination":{"component":2,"pin":1}},{"source":{"component":1,"pin":2},"destination":{"component":3,"pin":0}},{"source":{"component":0,"pin":1},"destination":{"component":3,"pin":1}},{"source":{"component":2,"pin":2},"destination":{"component":4,"pin":0}},{"source":{"component":3,"pin":2},"destination":{"component":4,"pin":1}},{"source":{"component":4,"pin":2},"destination":{"component":0,"pin":2}}]},"nor":{"inputs":2,"image":"img/gates/nor.png","pins":[0,0,0],"subComponents":["or","not"],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0}},{"source":{"component":0,"pin":1},"destination":{"component":1,"pin":1}},{"source":{"component":1,"pin":2},"destination":{"component":2,"pin":0}},{"source":{"component":2,"pin":1},"destination":{"component":0,"pin":2}}]},"xnor":{"inputs":2,"image":"img/gates/xnor.png","pins":[0,0,0],"subComponents":["xor","not"],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0}},{"source":{"component":0,"pin":1},"destination":{"component":1,"pin":1}},{"source":{"component":1,"pin":2},"destination":{"component":2,"pin":0}},{"source":{"component":2,"pin":1},"destination":{"component":0,"pin":2}}]},"half adder":{"type":"half adder","inputs":2,"pins":[0,0,0,0],"subComponents":["and","xor"],"positions":[{"x":413,"y":299},{"x":293,"y":132}],"wires":[{"source":{"component":0,"pin":1},"destination":{"component":1,"pin":1},"wireId":0},{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0},"wireId":1},{"source":{"component":1,"pin":2},"destination":{"component":0,"pin":3},"wireId":2},{"source":{"component":0,"pin":1},"destination":{"component":2,"pin":1},"wireId":3},{"source":{"component":0,"pin":0},"destination":{"component":2,"pin":0},"wireId":4},{"source":{"component":2,"pin":2},"destination":{"component":0,"pin":2},"wireId":5}]},"full adder":{"type":"full adder","inputs":3,"pins":[0,0,0,0,0],"subComponents":["half adder","half adder","or"],"positions":[{"x":110,"y":127},{"x":403,"y":212},{"x":827,"y":287}],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0},"wireId":6},{"source":{"component":0,"pin":1},"destination":{"component":1,"pin":1},"wireId":7},{"source":{"component":1,"pin":2},"destination":{"component":2,"pin":0},"wireId":8},{"source":{"component":0,"pin":2},"destination":{"component":2,"pin":1},"wireId":9},{"source":{"component":2,"pin":2},"destination":{"component":0,"pin":3},"wireId":10},{"source":{"component":1,"pin":3},"destination":{"component":3,"pin":1},"wireId":12},{"source":{"component":2,"pin":3},"destination":{"component":3,"pin":0},"wireId":13},{"source":{"component":3,"pin":2},"destination":{"component":0,"pin":4},"wireId":14}]}}'); + chip = new Component("main",true,'{"type":"main","inputs":9,"pins":[0,0,0,0,0,0,0,0,0,0,0,0,0,0],"subComponents":["full adder","full adder","full adder","full adder"],"positions":[{"x":157,"y":30},{"x":364,"y":150},{"x":546,"y":224},{"x":734,"y":300}],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0},"wireId":11},{"source":{"component":0,"pin":4},"destination":{"component":1,"pin":1},"wireId":12},{"source":{"component":0,"pin":8},"destination":{"component":1,"pin":2},"wireId":13},{"source":{"component":0,"pin":1},"destination":{"component":2,"pin":0},"wireId":18},{"source":{"component":1,"pin":4},"destination":{"component":2,"pin":2},"wireId":20},{"source":{"component":0,"pin":5},"destination":{"component":2,"pin":1},"wireId":21},{"source":{"component":1,"pin":3},"destination":{"component":0,"pin":9},"wireId":22},{"source":{"component":2,"pin":3},"destination":{"component":0,"pin":10},"wireId":25},{"source":{"component":2,"pin":4},"destination":{"component":3,"pin":2},"wireId":26},{"source":{"component":0,"pin":2},"destination":{"component":3,"pin":0},"wireId":27},{"source":{"component":0,"pin":6},"destination":{"component":3,"pin":1},"wireId":28},{"source":{"component":3,"pin":3},"destination":{"component":0,"pin":11},"wireId":29},{"source":{"component":3,"pin":4},"destination":{"component":4,"pin":2},"wireId":30},{"source":{"component":0,"pin":7},"destination":{"component":4,"pin":1},"wireId":31},{"source":{"component":0,"pin":3},"destination":{"component":4,"pin":0},"wireId":32},{"source":{"component":4,"pin":3},"destination":{"component":0,"pin":12},"wireId":33},{"source":{"component":4,"pin":4},"destination":{"component":0,"pin":13},"wireId":34}]}'); +setTimeout(function(){ wireVisuals = JSON.parse( + '[{"wireId":11,"path":[{"component":0,"pin":0,"shift":false,"rev":1},{"component":1,"pin":0,"shift":false,"offset":0}]},{"wireId":12,"path":[{"component":0,"pin":4,"shift":false,"rev":1},{"component":1,"pin":1,"shift":false,"offset":28}]},{"wireId":13,"path":[{"component":0,"pin":8,"shift":false,"rev":1},{"component":1,"pin":2,"shift":false,"offset":56}]},{"wireId":18,"path":[{"component":2,"pin":0,"shift":false,"rev":-1},{"component":0,"pin":1,"shift":false,"offset":0}]},{"wireId":20,"path":[{"component":1,"pin":4,"shift":false,"rev":1},{"component":2,"pin":2,"shift":false,"offset":7}]},{"wireId":21,"path":[{"component":2,"pin":1,"shift":false,"rev":-1},{"component":0,"pin":5,"shift":false,"offset":7}]},{"wireId":22,"path":[{"component":1,"pin":3,"shift":false,"rev":1},{"component":0,"pin":9,"shift":false,"offset":0}]},{"wireId":25,"path":[{"component":2,"pin":3,"shift":false,"rev":1},{"component":0,"pin":10,"shift":false,"offset":0}]},{"wireId":26,"path":[{"component":2,"pin":4,"shift":false,"rev":1},{"component":3,"pin":2,"shift":false,"offset":7}]},{"wireId":27,"path":[{"component":0,"pin":2,"shift":false,"rev":1},{"component":3,"pin":0,"shift":false,"offset":14}]},{"wireId":28,"path":[{"component":0,"pin":6,"shift":false,"rev":1},{"component":3,"pin":1,"shift":false,"offset":42}]},{"wireId":29,"path":[{"component":3,"pin":3,"shift":false,"rev":1},{"component":0,"pin":11,"shift":false,"offset":0}]},{"wireId":30,"path":[{"component":3,"pin":4,"shift":false,"rev":1},{"component":4,"pin":2,"shift":false,"offset":7}]},{"wireId":31,"path":[{"component":0,"pin":7,"shift":false,"rev":1},{"component":4,"pin":1,"shift":false,"offset":49}]},{"wireId":32,"path":[{"component":0,"pin":3,"shift":false,"rev":1},{"component":4,"pin":0,"shift":false,"offset":21}]},{"wireId":33,"path":[{"component":4,"pin":3,"shift":false,"rev":1},{"component":0,"pin":12,"shift":false,"offset":0}]},{"wireId":34,"path":[{"component":4,"pin":4,"shift":false,"rev":1},{"component":0,"pin":13,"shift":false,"offset":7}]}]'); +},50); +} diff --git a/build/editor/js/layouts/sub.js b/build/editor/js/layouts/sub.js new file mode 100755 index 0000000..f3fa85f --- /dev/null +++ b/build/editor/js/layouts/sub.js @@ -0,0 +1,7 @@ +function loadChip(){ + chips = JSON.parse('{"nand":{"image":"img/gates/nand.png","inputs":2,"pins":[0,0,0],"subComponents":[],"wires":[]},"not":{"image":"img/gates/not.png","inputs":1,"pins":[0,0],"subComponents":["nand"],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0}},{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":1}},{"source":{"component":1,"pin":2},"destination":{"component":0,"pin":1}}]},"and":{"image":"img/gates/and.png","inputs":2,"pins":[0,0,0],"subComponents":["nand","nand"],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0}},{"source":{"component":0,"pin":1},"destination":{"component":1,"pin":1}},{"source":{"component":1,"pin":2},"destination":{"component":2,"pin":0}},{"source":{"component":1,"pin":2},"destination":{"component":2,"pin":1}},{"source":{"component":2,"pin":2},"destination":{"component":0,"pin":2}}]},"or":{"image":"img/gates/or.png","inputs":2,"pins":[0,0,0],"subComponents":["nand","nand","nand"],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0}},{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":1}},{"source":{"component":0,"pin":1},"destination":{"component":2,"pin":0}},{"source":{"component":0,"pin":1},"destination":{"component":2,"pin":1}},{"source":{"component":1,"pin":2},"destination":{"component":3,"pin":0}},{"source":{"component":2,"pin":2},"destination":{"component":3,"pin":1}},{"source":{"component":3,"pin":2},"destination":{"component":0,"pin":2}}]},"xor":{"image":"img/gates/xor.png","inputs":2,"pins":[0,0,0],"subComponents":["nand","nand","nand","nand"],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0}},{"source":{"component":0,"pin":1},"destination":{"component":1,"pin":1}},{"source":{"component":0,"pin":0},"destination":{"component":2,"pin":0}},{"source":{"component":1,"pin":2},"destination":{"component":2,"pin":1}},{"source":{"component":1,"pin":2},"destination":{"component":3,"pin":0}},{"source":{"component":0,"pin":1},"destination":{"component":3,"pin":1}},{"source":{"component":2,"pin":2},"destination":{"component":4,"pin":0}},{"source":{"component":3,"pin":2},"destination":{"component":4,"pin":1}},{"source":{"component":4,"pin":2},"destination":{"component":0,"pin":2}}]},"nor":{"inputs":2,"image":"img/gates/nor.png","pins":[0,0,0],"subComponents":["or","not"],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0}},{"source":{"component":0,"pin":1},"destination":{"component":1,"pin":1}},{"source":{"component":1,"pin":2},"destination":{"component":2,"pin":0}},{"source":{"component":2,"pin":1},"destination":{"component":0,"pin":2}}]},"xnor":{"inputs":2,"image":"img/gates/xnor.png","pins":[0,0,0],"subComponents":["xor","not"],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0}},{"source":{"component":0,"pin":1},"destination":{"component":1,"pin":1}},{"source":{"component":1,"pin":2},"destination":{"component":2,"pin":0}},{"source":{"component":2,"pin":1},"destination":{"component":0,"pin":2}}]},"half adder":{"type":"half adder","inputs":2,"pins":[0,0,0,0],"subComponents":["and","xor"],"positions":[{"x":413,"y":299},{"x":293,"y":132}],"wires":[{"source":{"component":0,"pin":1},"destination":{"component":1,"pin":1},"wireId":0},{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0},"wireId":1},{"source":{"component":1,"pin":2},"destination":{"component":0,"pin":3},"wireId":2},{"source":{"component":0,"pin":1},"destination":{"component":2,"pin":1},"wireId":3},{"source":{"component":0,"pin":0},"destination":{"component":2,"pin":0},"wireId":4},{"source":{"component":2,"pin":2},"destination":{"component":0,"pin":2},"wireId":5}]},"full adder":{"type":"full adder","inputs":3,"pins":[0,0,0,0,0],"subComponents":["half adder","half adder","or"],"positions":[{"x":110,"y":127},{"x":403,"y":212},{"x":827,"y":287}],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0},"wireId":6},{"source":{"component":0,"pin":1},"destination":{"component":1,"pin":1},"wireId":7},{"source":{"component":1,"pin":2},"destination":{"component":2,"pin":0},"wireId":8},{"source":{"component":0,"pin":2},"destination":{"component":2,"pin":1},"wireId":9},{"source":{"component":2,"pin":2},"destination":{"component":0,"pin":3},"wireId":10},{"source":{"component":1,"pin":3},"destination":{"component":3,"pin":1},"wireId":12},{"source":{"component":2,"pin":3},"destination":{"component":3,"pin":0},"wireId":13},{"source":{"component":3,"pin":2},"destination":{"component":0,"pin":4},"wireId":14}]},"ripple carry adder":{"type":"ripple carry adder","inputs":9,"pins":[0,0,0,0,0,0,0,0,0,0,0,0,0,0],"subComponents":["full adder","full adder","full adder","full adder"],"positions":[{"x":157,"y":30},{"x":364,"y":150},{"x":546,"y":224},{"x":734,"y":300}],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0},"wireId":11},{"source":{"component":0,"pin":4},"destination":{"component":1,"pin":1},"wireId":12},{"source":{"component":0,"pin":8},"destination":{"component":1,"pin":2},"wireId":13},{"source":{"component":0,"pin":1},"destination":{"component":2,"pin":0},"wireId":18},{"source":{"component":1,"pin":4},"destination":{"component":2,"pin":2},"wireId":20},{"source":{"component":0,"pin":5},"destination":{"component":2,"pin":1},"wireId":21},{"source":{"component":1,"pin":3},"destination":{"component":0,"pin":9},"wireId":22},{"source":{"component":2,"pin":3},"destination":{"component":0,"pin":10},"wireId":25},{"source":{"component":2,"pin":4},"destination":{"component":3,"pin":2},"wireId":26},{"source":{"component":0,"pin":2},"destination":{"component":3,"pin":0},"wireId":27},{"source":{"component":0,"pin":6},"destination":{"component":3,"pin":1},"wireId":28},{"source":{"component":3,"pin":3},"destination":{"component":0,"pin":11},"wireId":29},{"source":{"component":3,"pin":4},"destination":{"component":4,"pin":2},"wireId":30},{"source":{"component":0,"pin":7},"destination":{"component":4,"pin":1},"wireId":31},{"source":{"component":0,"pin":3},"destination":{"component":4,"pin":0},"wireId":32},{"source":{"component":4,"pin":3},"destination":{"component":0,"pin":12},"wireId":33},{"source":{"component":4,"pin":4},"destination":{"component":0,"pin":13},"wireId":34}]}}'); + chip = new Component("main",true,'{"type":"main","inputs":8,"pins":[0,0,0,0,0,0,0,0,0,0,0,0,0],"subComponents":["ripple carry adder","not","not"],"positions":[{"x":405,"y":151},{"x":288,"y":357},{"x":858,"y":341}],"wires":[{"source":{"component":2,"pin":1},"destination":{"component":1,"pin":8},"wireId":0},{"source":{"component":3,"pin":1},"destination":{"component":0,"pin":12},"wireId":1},{"source":{"component":1,"pin":13},"destination":{"component":3,"pin":0},"wireId":2},{"source":{"component":1,"pin":9},"destination":{"component":0,"pin":8},"wireId":3},{"source":{"component":1,"pin":10},"destination":{"component":0,"pin":9},"wireId":4},{"source":{"component":1,"pin":11},"destination":{"component":0,"pin":10},"wireId":5},{"source":{"component":1,"pin":12},"destination":{"component":0,"pin":11},"wireId":6}]}'); +setTimeout(function(){ wireVisuals = JSON.parse( +'[{"wireId":0,"path":[{"component":2,"pin":1,"shift":0,"rev":1},{"component":1,"pin":8,"shift":0,"offset":0}]},{"wireId":1,"path":[{"component":3,"pin":1,"shift":0,"rev":1},{"component":0,"pin":12,"shift":0,"offset":0}]},{"wireId":2,"path":[{"component":3,"pin":0,"shift":0,"rev":-1},{"component":1,"pin":13,"shift":0,"offset":0}]},{"wireId":3,"path":[{"component":1,"pin":9,"shift":0,"rev":1},{"x":1007.085227265954,"y":68.81534092128277,"shift":0,"offset":0},{"component":0,"pin":8,"shift":0,"offset":0}]},{"wireId":4,"path":[{"component":1,"pin":10,"shift":0,"rev":1},{"component":0,"pin":9,"shift":0,"offset":7}]},{"wireId":5,"path":[{"component":1,"pin":11,"shift":0,"rev":1},{"component":0,"pin":10,"shift":0,"offset":14}]},{"wireId":6,"path":[{"component":1,"pin":12,"shift":0,"rev":1},{"component":0,"pin":11,"shift":0,"offset":21}]}]'); +},50); +} diff --git a/build/editor/js/layouts/xor.js b/build/editor/js/layouts/xor.js new file mode 100755 index 0000000..ba4fe44 --- /dev/null +++ b/build/editor/js/layouts/xor.js @@ -0,0 +1,6 @@ +function loadChip(){ + chip = new Component("main",true,'{"type":"main","inputs":2,"pins":[0,0,0],"subComponents":["xor"],"positions":[{"x":300,"y":178}],"wires":[{"source":{"component":0,"pin":0},"destination":{"component":1,"pin":0},"wireId":0},{"source":{"component":0,"pin":1},"destination":{"component":1,"pin":1},"wireId":1},{"source":{"component":1,"pin":2},"destination":{"component":0,"pin":2},"wireId":2}]}'); +setTimeout(function(){ wireVisuals = JSON.parse( + '[{"wireId":0,"path":[{"component":1,"pin":0,"shift":false,"rev":-1},{"component":0,"pin":0,"shift":false,"offset":0}]},{"wireId":1,"path":[{"component":0,"pin":1,"shift":false,"rev":1},{"component":1,"pin":1,"shift":false,"offset":7}]},{"wireId":2,"path":[{"component":1,"pin":2,"shift":false,"rev":1},{"component":0,"pin":2,"shift":false,"offset":0}]}]'); +},50); +} diff --git a/build/editor/js/md5.js b/build/editor/js/md5.js new file mode 100755 index 0000000..2cca30f --- /dev/null +++ b/build/editor/js/md5.js @@ -0,0 +1,171 @@ +function md5 ( str ) { + + var RotateLeft = function(lValue, iShiftBits) { + return (lValue<>>(32-iShiftBits)); + }; + + var AddUnsigned = function(lX,lY) { + var lX4,lY4,lX8,lY8,lResult; + lX8 = (lX & 0x80000000); + lY8 = (lY & 0x80000000); + lX4 = (lX & 0x40000000); + lY4 = (lY & 0x40000000); + lResult = (lX & 0x3FFFFFFF)+(lY & 0x3FFFFFFF); + if (lX4 & lY4) { + return (lResult ^ 0x80000000 ^ lX8 ^ lY8); + } + if (lX4 | lY4) { + if (lResult & 0x40000000) { + return (lResult ^ 0xC0000000 ^ lX8 ^ lY8); + } else { + return (lResult ^ 0x40000000 ^ lX8 ^ lY8); + } + } else { + return (lResult ^ lX8 ^ lY8); + } + }; + + var F = function(x,y,z) { return (x & y) | ((~x) & z); }; + var G = function(x,y,z) { return (x & z) | (y & (~z)); }; + var H = function(x,y,z) { return (x ^ y ^ z); }; + var I = function(x,y,z) { return (y ^ (x | (~z))); }; + + var FF = function(a,b,c,d,x,s,ac) { + a = AddUnsigned(a, AddUnsigned(AddUnsigned(F(b, c, d), x), ac)); + return AddUnsigned(RotateLeft(a, s), b); + }; + + var GG = function(a,b,c,d,x,s,ac) { + a = AddUnsigned(a, AddUnsigned(AddUnsigned(G(b, c, d), x), ac)); + return AddUnsigned(RotateLeft(a, s), b); + }; + + var HH = function(a,b,c,d,x,s,ac) { + a = AddUnsigned(a, AddUnsigned(AddUnsigned(H(b, c, d), x), ac)); + return AddUnsigned(RotateLeft(a, s), b); + }; + + var II = function(a,b,c,d,x,s,ac) { + a = AddUnsigned(a, AddUnsigned(AddUnsigned(I(b, c, d), x), ac)); + return AddUnsigned(RotateLeft(a, s), b); + }; + + var ConvertToWordArray = function(str) { + var lWordCount; + var lMessageLength = str.length; + var lNumberOfWords_temp1=lMessageLength + 8; + var lNumberOfWords_temp2=(lNumberOfWords_temp1-(lNumberOfWords_temp1 % 64))/64; + var lNumberOfWords = (lNumberOfWords_temp2+1)*16; + var lWordArray=Array(lNumberOfWords-1); + var lBytePosition = 0; + var lByteCount = 0; + while ( lByteCount < lMessageLength ) { + lWordCount = (lByteCount-(lByteCount % 4))/4; + lBytePosition = (lByteCount % 4)*8; + lWordArray[lWordCount] = (lWordArray[lWordCount] | (str.charCodeAt(lByteCount)<>>29; + return lWordArray; + }; + + var WordToHex = function(lValue) { + var WordToHexValue="",WordToHexValue_temp="",lByte,lCount; + for (lCount = 0;lCount<=3;lCount++) { + lByte = (lValue>>>(lCount*8)) & 255; + WordToHexValue_temp = "0" + lByte.toString(16); + WordToHexValue = WordToHexValue + WordToHexValue_temp.substr(WordToHexValue_temp.length-2,2); + } + return WordToHexValue; + }; + + var x=Array(); + var k,AA,BB,CC,DD,a,b,c,d; + var S11=7, S12=12, S13=17, S14=22; + var S21=5, S22=9 , S23=14, S24=20; + var S31=4, S32=11, S33=16, S34=23; + var S41=6, S42=10, S43=15, S44=21; + + x = ConvertToWordArray(str); + a = 0x67452301; b = 0xEFCDAB89; c = 0x98BADCFE; d = 0x10325476; + + for (k=0;k +printf("hello world"); diff --git a/build/img/._flags_diagram.png b/build/img/._flags_diagram.png new file mode 100755 index 0000000..0cf051a Binary files /dev/null and b/build/img/._flags_diagram.png differ diff --git a/build/img/._flags_diagram.psd b/build/img/._flags_diagram.psd new file mode 100755 index 0000000..e7e5dbc Binary files /dev/null and b/build/img/._flags_diagram.psd differ diff --git a/build/img/flags_diagram.png b/build/img/flags_diagram.png new file mode 100755 index 0000000..ffe3780 Binary files /dev/null and b/build/img/flags_diagram.png differ diff --git a/build/img/flags_diagram.psd b/build/img/flags_diagram.psd new file mode 100755 index 0000000..7e70a0e Binary files /dev/null and b/build/img/flags_diagram.psd differ diff --git a/build/js/page.js b/build/js/page.js new file mode 100755 index 0000000..f6f77aa --- /dev/null +++ b/build/js/page.js @@ -0,0 +1,20 @@ +window.addEventListener('load',e=>{ + for(var c = document.getElementsByTagName("a"), a = 0;a < c.length;a++) { + var b = c[a]; + ((b.getAttribute("href") && b.hostname !== location.hostname) || (b.getAttribute("data-newtab")==true)) && (b.target = "_blank") + } + for(var c=document.getElementsByTagName("ol"), a=0; a{ + if(!child.getAttribute("data-before")) + child.setAttribute("data-before", pad(i.toString(2), Math.log2(b.children.length))); + }); + } + } +}); +function pad(num, size) { + var s = "000000000" + num; + return s.substr(s.length-size); +} + diff --git a/build/multiplexer/index.html b/build/multiplexer/index.html new file mode 100755 index 0000000..e9c0e76 --- /dev/null +++ b/build/multiplexer/index.html @@ -0,0 +1,28 @@ + + + + Build a multiplexer + + + + +

Build a multiplexer!

+

+ The multiplexer chip used in this CPU is a 16:8 mux - this means it can select between two 8-bit inputs.

+ Don't worry, this is an extremely simple chip to construct. To start with, you must build from logic gates a 2:1 mux which can switch between two individual bits. Then you can use 8 of these 2:1 muxes to build this chip. +

+ +

Start building

+
    +
  1. construct 2:1 mux
  2. +
  3. assemble 16:8 mux
  4. + +
+

+ Once you are finished, you can return to the CPU. +

+ + diff --git a/build/registers/index.html b/build/registers/index.html new file mode 100755 index 0000000..080f3a5 --- /dev/null +++ b/build/registers/index.html @@ -0,0 +1,23 @@ + + + + Build a multiplexer + + + +

Build a multiplexer!

+

+ The multiplexer chip used in this CPU is a 16:8 mux - this means it can select between two 8-bit inputs. +
+ Don't worry, this is an extremely simple chip to construct. To start with, you must build from logic gates a 2:1 mux which can switch between two individual bits. Then you can use 8 of these 2:1 muxes to build this chip. +

+

Start building

+
    +
  1. construct 2:1 mux
  2. +
  3. assemble 16:8 mux
  4. +
+

+ Once you are finished, you can return to the CPU. +

+ + diff --git a/cheat/index.html b/cheat/index.html new file mode 100755 index 0000000..04d0974 --- /dev/null +++ b/cheat/index.html @@ -0,0 +1,3 @@ + diff --git a/css/generator_config.txt b/css/generator_config.txt new file mode 100755 index 0000000..81e64f6 --- /dev/null +++ b/css/generator_config.txt @@ -0,0 +1,5 @@ +# Font Squirrel Font-face Generator Configuration File +# Upload this file to the generator to recreate the settings +# you used to create these fonts. + +{"mode":"optimal","formats":["woff","woff2"],"tt_instructor":"default","fix_gasp":"xy","fix_vertical_metrics":"Y","metrics_ascent":"","metrics_descent":"","metrics_linegap":"","add_spaces":"Y","add_hyphens":"Y","fallback":"none","fallback_custom":"100","options_subset":"basic","subset_custom":"","subset_custom_range":"","subset_ot_features_list":"","css_stylesheet":"stylesheet.css","filename_suffix":"-webfont","emsquare":"2048","spacing_adjustment":"0"} \ No newline at end of file diff --git a/css/specimen_files/grid_12-825-55-15.css b/css/specimen_files/grid_12-825-55-15.css new file mode 100755 index 0000000..3d6aef7 --- /dev/null +++ b/css/specimen_files/grid_12-825-55-15.css @@ -0,0 +1,129 @@ +/*Notes about grid: +Columns: 12 +Grid Width: 825px +Column Width: 55px +Gutter Width: 15px +-------------------------------*/ + + + +.section {margin-bottom: 18px; +} +.section:after {content: ".";display: block;height: 0;clear: both;visibility: hidden;} +.section {*zoom: 1;} + +.section .firstcolumn, +.section .firstcol {margin-left: 0;} + + +/* Border on left hand side of a column. */ +.border { + padding-left: 7px; + margin-left: 7px; + border-left: 1px solid #eee; +} + +/* Border with more whitespace, spans one column. */ +.colborder { + padding-left: 42px; + margin-left: 42px; + border-left: 1px solid #eee; +} + + + +/* The Grid Classes */ +.grid1, .grid1_2cols, .grid1_3cols, .grid1_4cols, .grid2, .grid2_3cols, .grid2_4cols, .grid3, .grid3_2cols, .grid3_4cols, .grid4, .grid4_3cols, .grid5, .grid5_2cols, .grid5_3cols, .grid5_4cols, .grid6, .grid6_4cols, .grid7, .grid7_2cols, .grid7_3cols, .grid7_4cols, .grid8, .grid8_3cols, .grid9, .grid9_2cols, .grid9_4cols, .grid10, .grid10_3cols, .grid10_4cols, .grid11, .grid11_2cols, .grid11_3cols, .grid11_4cols, .grid12 +{margin-left: 15px;float: left;display: inline; overflow: hidden;} + + +.width1, .grid1, .span-1 {width: 55px;} +.width1_2cols,.grid1_2cols {width: 20px;} +.width1_3cols,.grid1_3cols {width: 8px;} +.width1_4cols,.grid1_4cols {width: 2px;} +.input_width1 {width: 49px;} + +.width2, .grid2, .span-2 {width: 125px;} +.width2_3cols,.grid2_3cols {width: 31px;} +.width2_4cols,.grid2_4cols {width: 20px;} +.input_width2 {width: 119px;} + +.width3, .grid3, .span-3 {width: 195px;} +.width3_2cols,.grid3_2cols {width: 90px;} +.width3_4cols,.grid3_4cols {width: 37px;} +.input_width3 {width: 189px;} + +.width4, .grid4, .span-4 {width: 265px;} +.width4_3cols,.grid4_3cols {width: 78px;} +.input_width4 {width: 259px;} + +.width5, .grid5, .span-5 {width: 335px;} +.width5_2cols,.grid5_2cols {width: 160px;} +.width5_3cols,.grid5_3cols {width: 101px;} +.width5_4cols,.grid5_4cols {width: 72px;} +.input_width5 {width: 329px;} + +.width6, .grid6, .span-6 {width: 405px;} +.width6_4cols,.grid6_4cols {width: 90px;} +.input_width6 {width: 399px;} + +.width7, .grid7, .span-7 {width: 475px;} +.width7_2cols,.grid7_2cols {width: 230px;} +.width7_3cols,.grid7_3cols {width: 148px;} +.width7_4cols,.grid7_4cols {width: 107px;} +.input_width7 {width: 469px;} + +.width8, .grid8, .span-8 {width: 545px;} +.width8_3cols,.grid8_3cols {width: 171px;} +.input_width8 {width: 539px;} + +.width9, .grid9, .span-9 {width: 615px;} +.width9_2cols,.grid9_2cols {width: 300px;} +.width9_4cols,.grid9_4cols {width: 142px;} +.input_width9 {width: 609px;} + +.width10, .grid10, .span-10 {width: 685px;} +.width10_3cols,.grid10_3cols {width: 218px;} +.width10_4cols,.grid10_4cols {width: 160px;} +.input_width10 {width: 679px;} + +.width11, .grid11, .span-11 {width: 755px;} +.width11_2cols,.grid11_2cols {width: 370px;} +.width11_3cols,.grid11_3cols {width: 241px;} +.width11_4cols,.grid11_4cols {width: 177px;} +.input_width11 {width: 749px;} + +.width12, .grid12, .span-12 {width: 825px;} +.input_width12 {width: 819px;} + +/* Subdivided grid spaces */ +.emptycols_left1, .prepend-1 {padding-left: 70px;} +.emptycols_right1, .append-1 {padding-right: 70px;} +.emptycols_left2, .prepend-2 {padding-left: 140px;} +.emptycols_right2, .append-2 {padding-right: 140px;} +.emptycols_left3, .prepend-3 {padding-left: 210px;} +.emptycols_right3, .append-3 {padding-right: 210px;} +.emptycols_left4, .prepend-4 {padding-left: 280px;} +.emptycols_right4, .append-4 {padding-right: 280px;} +.emptycols_left5, .prepend-5 {padding-left: 350px;} +.emptycols_right5, .append-5 {padding-right: 350px;} +.emptycols_left6, .prepend-6 {padding-left: 420px;} +.emptycols_right6, .append-6 {padding-right: 420px;} +.emptycols_left7, .prepend-7 {padding-left: 490px;} +.emptycols_right7, .append-7 {padding-right: 490px;} +.emptycols_left8, .prepend-8 {padding-left: 560px;} +.emptycols_right8, .append-8 {padding-right: 560px;} +.emptycols_left9, .prepend-9 {padding-left: 630px;} +.emptycols_right9, .append-9 {padding-right: 630px;} +.emptycols_left10, .prepend-10 {padding-left: 700px;} +.emptycols_right10, .append-10 {padding-right: 700px;} +.emptycols_left11, .prepend-11 {padding-left: 770px;} +.emptycols_right11, .append-11 {padding-right: 770px;} +.pull-1 {margin-left: -70px;} +.push-1 {margin-right: -70px;margin-left: 18px;float: right;} +.pull-2 {margin-left: -140px;} +.push-2 {margin-right: -140px;margin-left: 18px;float: right;} +.pull-3 {margin-left: -210px;} +.push-3 {margin-right: -210px;margin-left: 18px;float: right;} +.pull-4 {margin-left: -280px;} +.push-4 {margin-right: -280px;margin-left: 18px;float: right;} \ No newline at end of file diff --git a/css/specimen_files/specimen_stylesheet.css b/css/specimen_files/specimen_stylesheet.css new file mode 100755 index 0000000..aecc43c --- /dev/null +++ b/css/specimen_files/specimen_stylesheet.css @@ -0,0 +1,396 @@ +@import url('grid_12-825-55-15.css'); + +/* + CSS Reset by Eric Meyer - Released under Public Domain + http://meyerweb.com/eric/tools/css/reset/ +*/ +html, body, div, span, applet, object, iframe, +h1, h2, h3, h4, h5, h6, p, blockquote, pre, +a, abbr, acronym, address, big, cite, code, +del, dfn, em, font, img, ins, kbd, q, s, samp, +small, strike, strong, sub, sup, tt, var, +b, u, i, center, dl, dt, dd, ol, ul, li, +fieldset, form, label, legend, table, +caption, tbody, tfoot, thead, tr, th, td + {margin: 0;padding: 0;border: 0;outline: 0; + font-size: 100%;vertical-align: baseline; + background: transparent;} +body {line-height: 1;} +ol, ul {list-style: none;} +blockquote, q {quotes: none;} +blockquote:before, blockquote:after, +q:before, q:after {content: ''; content: none;} +:focus {outline: 0;} +ins {text-decoration: none;} +del {text-decoration: line-through;} +table {border-collapse: collapse;border-spacing: 0;} + + + + +body { + color: #000; + background-color: #dcdcdc; +} + +a { + text-decoration: none; + color: #1883ba; +} + +h1{ + font-size: 32px; + font-weight: normal; + font-style: normal; + margin-bottom: 18px; +} + +h2{ + font-size: 18px; +} + +#container { + width: 865px; + margin: 0px auto; +} + + +#header { + padding: 20px; + font-size: 36px; + background-color: #000; + color: #fff; +} + +#header span { + color: #666; +} +#main_content { + background-color: #fff; + padding: 60px 20px 20px; +} + + +#footer p { + margin: 0; + padding-top: 10px; + padding-bottom: 50px; + color: #333; + font: 10px Arial, sans-serif; +} + +.tabs { + width: 100%; + height: 31px; + background-color: #444; +} +.tabs li { + float: left; + margin: 0; + overflow: hidden; + background-color: #444; +} +.tabs li a { + display: block; + color: #fff; + text-decoration: none; + font: bold 11px/11px 'Arial'; + text-transform: uppercase; + padding: 10px 15px; + border-right: 1px solid #fff; +} + +.tabs li a:hover { + background-color: #00b3ff; + +} + +.tabs li.active a { + color: #000; + background-color: #fff; +} + + + +div.huge { + + font-size: 300px; + line-height: 1em; + padding: 0; + letter-spacing: -.02em; + overflow: hidden; +} +div.glyph_range { + font-size: 72px; + line-height: 1.1em; +} + +.size10{ font-size: 10px; } +.size11{ font-size: 11px; } +.size12{ font-size: 12px; } +.size13{ font-size: 13px; } +.size14{ font-size: 14px; } +.size16{ font-size: 16px; } +.size18{ font-size: 18px; } +.size20{ font-size: 20px; } +.size24{ font-size: 24px; } +.size30{ font-size: 30px; } +.size36{ font-size: 36px; } +.size48{ font-size: 48px; } +.size60{ font-size: 60px; } +.size72{ font-size: 72px; } +.size90{ font-size: 90px; } + + +.psample_row1 { height: 120px;} +.psample_row1 { height: 120px;} +.psample_row2 { height: 160px;} +.psample_row3 { height: 160px;} +.psample_row4 { height: 160px;} + +.psample { + overflow: hidden; + position: relative; +} +.psample p { + line-height: 1.3em; + display: block; + overflow: hidden; + margin: 0; +} + +.psample span { + margin-right: .5em; +} + +.white_blend { + width: 100%; + height: 61px; + background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAVkAAAA9CAYAAAAH4BojAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAO1JREFUeNrs3TsKgFAMRUE/eer+NxztxMYuEWQG3ECKwwUF58ycAKixOAGAyAKILAAiCyCyACILgMgCiCyAyAIgsgAiCyCyAIgsgMgCiCwAIgsgsgAiC4DIAogsACIL0CWuZ3UGgLrIhjMA1EV2OAOAJQtgyQLwjOzmDAAiCyCyAIgsQFtkd2cAEFkAkQVAZAHaIns4A4AlC2DJAiCyACILILIAiCzAV5H1dQGAJQsgsgCILIDIAvwisl58AViyAJYsACILILIAIgvAe2T9EhxAZAFEFgCRBeiL7HAGgLrIhjMAWLIAliwAt1OAAQDwygTBulLIlQAAAABJRU5ErkJggg==); + position: absolute; + bottom: 0; +} +.black_blend { + width: 100%; + height: 61px; + background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAVkAAAA9CAYAAAAH4BojAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAPJJREFUeNrs3TEKhTAQRVGjibr/9QoxhY2N3Ywo50A28IrLwP9g6b1PAMSYTQAgsgAiC4DIAogsgMgCILIAIgsgsgCILIDIAogsACILILIAIguAyAKILIDIAiCyACILgMgCZCnjLWYAiFGvB0BQZJsZAFyyAC5ZAO6RXc0AILIAIguAyAKkRXYzA4DIAogsACILkBbZ3QwALlkAlywAIgsgsgAiC4DIArwVWf8uAHDJAogsACILILIAv4isH74AXLIALlkARBZAZAFEFoDnyPokOIDIAogsACILkBfZZgaAuMhWMwC4ZAE+p4x3mAEgxinAAJ+XBbPWGkwAAAAAAElFTkSuQmCC); + position: absolute; + bottom: 0; +} +.fullreverse { + background: #000 !important; + color: #fff !important; + margin-left: -20px; + padding-left: 20px; + margin-right: -20px; + padding-right: 20px; + padding: 20px; + margin-bottom:0; +} + + +.sample_table td { + padding-top: 3px; + padding-bottom:5px; + padding-left: 5px; + vertical-align: middle; + line-height: 1.2em; +} + +.sample_table td:first-child { + background-color: #eee; + text-align: right; + padding-right: 5px; + padding-left: 0; + padding: 5px; + font: 11px/12px "Courier New", Courier, mono; +} + +code { + white-space: pre; + background-color: #eee; + display: block; + padding: 10px; + margin-bottom: 18px; + overflow: auto; +} + + +.bottom,.last {margin-bottom:0 !important; padding-bottom:0 !important;} + +.box { + padding: 18px; + margin-bottom: 18px; + background: #eee; +} + +.reverse,.reversed { background: #000 !important;color: #fff !important; border: none !important;} + +#bodycomparison { + position: relative; + overflow: hidden; + font-size: 72px; + height: 90px; + white-space: nowrap; +} + +#bodycomparison div{ + font-size: 72px; + line-height: 90px; + display: inline; + margin: 0 15px 0 0; + padding: 0; +} + +#bodycomparison div span{ + font: 10px Arial; + position: absolute; + left: 0; +} +#xheight { + float: none; + position: absolute; + color: #d9f3ff; + font-size: 72px; + line-height: 90px; +} + +.fontbody { + position: relative; +} +.arialbody{ + font-family: Arial; + position: relative; +} +.verdanabody{ + font-family: Verdana; + position: relative; +} +.georgiabody{ + font-family: Georgia; + position: relative; +} + +/* @group Layout page + */ + +#layout h1 { + font-size: 36px; + line-height: 42px; + font-weight: normal; + font-style: normal; +} + +#layout h2 { + font-size: 24px; + line-height: 23px; + font-weight: normal; + font-style: normal; +} + +#layout h3 { + font-size: 22px; + line-height: 1.4em; + margin-top: 1em; + font-weight: normal; + font-style: normal; +} + + +#layout p.byline { + font-size: 12px; + margin-top: 18px; + line-height: 12px; + margin-bottom: 0; +} +#layout p { + font-size: 14px; + line-height: 21px; + margin-bottom: .5em; +} + +#layout p.large{ + font-size: 18px; + line-height: 26px; +} + +#layout .sidebar p{ + font-size: 12px; + line-height: 1.4em; +} + +#layout p.caption { + font-size: 10px; + margin-top: -16px; + margin-bottom: 18px; +} + +/* @end */ + +/* @group Glyphs */ + +#glyph_chart div{ + background-color: #d9f3ff; + color: black; + float: left; + font-size: 36px; + height: 1.2em; + line-height: 1.2em; + margin-bottom: 1px; + margin-right: 1px; + text-align: center; + width: 1.2em; + position: relative; + padding: .6em .2em .2em; +} + +#glyph_chart div p { + position: absolute; + left: 0; + top: 0; + display: block; + text-align: center; + font: bold 9px Arial, sans-serif; + background-color: #3a768f; + width: 100%; + color: #fff; + padding: 2px 0; +} + + +#glyphs h1 { + font-family: Arial, sans-serif; +} +/* @end */ + +/* @group Installing */ + +#installing { + font: 13px Arial, sans-serif; +} + +#installing p, +#glyphs p{ + line-height: 1.2em; + margin-bottom: 18px; + font: 13px Arial, sans-serif; +} + + + +#installing h3{ + font-size: 15px; + margin-top: 18px; +} + +/* @end */ + +#rendering h1 { + font-family: Arial, sans-serif; +} +.render_table td { + font: 11px "Courier New", Courier, mono; + vertical-align: middle; +} + + diff --git a/css/style.css b/css/style.css new file mode 100755 index 0000000..a81b3b9 --- /dev/null +++ b/css/style.css @@ -0,0 +1,87 @@ +* { + margin:0; +} +body,html{ + color:#5be55b; + background-color:#191a1d; + width:100vw; + height:100vh; + display: flex; + flex-direction:column; + flex-wrap:wrap; + align-content:flex-start; + font-family:vcr_osd_monoregular; +} +canvas { + width:75vw; + height:100vh; + background-color:#36393E; +} +.center_holder{ + margin-left:-10px; + margin-right:-10px; + width:100%; + display:flex; + justify-content:center; +} +.right_holder{ + width:100%; + display: flex; + justify-content:right; +} +#compile{ + margin-top:5px; + margin-right:25px; +} +#program{ + width:90%; + height:20vh; +} +#sidebar{ + padding-left:10px; + padding-top:10px; + padding-right:10px; + padding-bottom:10px; + width:25vw; + height:100vh; +} +#memory{ + margin-top:5px; + /*font-size:13px; + line-height:15px; + */ + font-size: 0.65vw; + line-height:0.7vw; + color:#AAA; +} +#memory .written { + color: #FFF; +} +#memory tr td { + border-left: 1px solid #AAA; + border-bottom: 1px solid #AAA; +} +.label { + color: #5be55b; + border-left: none !important; +} +textarea::before{ + background-color:grey; + display:block; + content:''; + position:absolute; + height:20vh; + width:90%; +} +textarea { + color: white; + background-color: grey; + background: url(http://i.imgur.com/2cOaJ.png); + background-attachment: local; + background-repeat: no-repeat; + padding-left: 35px; + padding-top: 10px; + font-size:13px; + line-height:16px; + border-color:#ccc; +} diff --git a/css/stylesheet.css b/css/stylesheet.css new file mode 100755 index 0000000..0bc97b1 --- /dev/null +++ b/css/stylesheet.css @@ -0,0 +1,12 @@ +/*! Generated by Font Squirrel (https://www.fontsquirrel.com) on February 20, 2022 */ + + + +@font-face { + font-family: 'vcr_osd_monoregular'; + src: url('vcr_osd_mono_1.001-webfont.woff2') format('woff2'), + url('vcr_osd_mono_1.001-webfont.woff') format('woff'); + font-weight: normal; + font-style: normal; + +} diff --git a/css/vcr_osd_mono_1.001-demo.html b/css/vcr_osd_mono_1.001-demo.html new file mode 100755 index 0000000..e3ee752 --- /dev/null +++ b/css/vcr_osd_mono_1.001-demo.html @@ -0,0 +1,602 @@ + + + + + + + + + + + + + VCR OSD Mono Regular Specimen + + + + + + +
+ + + +
+ + +
+ +
+
+
AaBb
+
+
+ +
+
A​B​C​D​E​F​G​H​I​J​K​L​M​N​O​P​Q​R​S​T​U​V​W​X​Y​Z​a​b​c​d​e​f​g​h​i​j​k​l​m​n​o​p​q​r​s​t​u​v​w​x​y​z​1​2​3​4​5​6​7​8​9​0​&​.​,​?​!​@​(​)​#​$​%​*​+​-​=​:​;
+
+
+
+ + + + + + + + + + + + + + + + +
10abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
11abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
12abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
13abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
14abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
16abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
18abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
20abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
24abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
30abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
36abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
48abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
60abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
72abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
90abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
+ +
+ +
+ + + +
+ + +
+
◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼body
body
body
body
+
+ bodyVCR OSD Mono Regular +
+
+ bodyArial +
+
+ bodyVerdana +
+
+ bodyGeorgia +
+ + + +
+ + +
+ +
+

10.Aenean lacinia bibendum nulla sed consectetur. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Nullam id dolor id nibh ultricies vehicula ut id elit. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nulla vitae elit libero, a pharetra augue.

+ +
+
+

11.Aenean lacinia bibendum nulla sed consectetur. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Nullam id dolor id nibh ultricies vehicula ut id elit. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nulla vitae elit libero, a pharetra augue.

+ +
+
+

12.Aenean lacinia bibendum nulla sed consectetur. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Nullam id dolor id nibh ultricies vehicula ut id elit. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nulla vitae elit libero, a pharetra augue.

+ +
+
+

13.Aenean lacinia bibendum nulla sed consectetur. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Nullam id dolor id nibh ultricies vehicula ut id elit. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nulla vitae elit libero, a pharetra augue.

+ +
+
+ +
+
+
+

14.Aenean lacinia bibendum nulla sed consectetur. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Nullam id dolor id nibh ultricies vehicula ut id elit. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nulla vitae elit libero, a pharetra augue.

+ +
+
+

16.Aenean lacinia bibendum nulla sed consectetur. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Nullam id dolor id nibh ultricies vehicula ut id elit. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nulla vitae elit libero, a pharetra augue.

+ +
+
+

18.Aenean lacinia bibendum nulla sed consectetur. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Nullam id dolor id nibh ultricies vehicula ut id elit. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nulla vitae elit libero, a pharetra augue.

+ +
+ +
+ +
+ +
+
+

20.Aenean lacinia bibendum nulla sed consectetur. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Nullam id dolor id nibh ultricies vehicula ut id elit. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nulla vitae elit libero, a pharetra augue.

+
+
+

24.Aenean lacinia bibendum nulla sed consectetur. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Nullam id dolor id nibh ultricies vehicula ut id elit. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nulla vitae elit libero, a pharetra augue.

+
+ +
+ +
+ +
+
+

30.Aenean lacinia bibendum nulla sed consectetur. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Nullam id dolor id nibh ultricies vehicula ut id elit. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nulla vitae elit libero, a pharetra augue.

+
+
+ +
+ + + +
+
+

10.Aenean lacinia bibendum nulla sed consectetur. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Nullam id dolor id nibh ultricies vehicula ut id elit. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nulla vitae elit libero, a pharetra augue.

+ +
+
+

11.Aenean lacinia bibendum nulla sed consectetur. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Nullam id dolor id nibh ultricies vehicula ut id elit. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nulla vitae elit libero, a pharetra augue.

+ +
+
+

12.Aenean lacinia bibendum nulla sed consectetur. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Nullam id dolor id nibh ultricies vehicula ut id elit. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nulla vitae elit libero, a pharetra augue.

+ +
+
+

13.Aenean lacinia bibendum nulla sed consectetur. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Nullam id dolor id nibh ultricies vehicula ut id elit. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nulla vitae elit libero, a pharetra augue.

+ +
+
+ +
+ +
+
+

14.Aenean lacinia bibendum nulla sed consectetur. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Nullam id dolor id nibh ultricies vehicula ut id elit. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nulla vitae elit libero, a pharetra augue.

+ +
+
+

16.Aenean lacinia bibendum nulla sed consectetur. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Nullam id dolor id nibh ultricies vehicula ut id elit. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nulla vitae elit libero, a pharetra augue.

+ +
+
+

18.Aenean lacinia bibendum nulla sed consectetur. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Nullam id dolor id nibh ultricies vehicula ut id elit. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nulla vitae elit libero, a pharetra augue.

+ +
+
+ +
+ +
+
+

20.Aenean lacinia bibendum nulla sed consectetur. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Nullam id dolor id nibh ultricies vehicula ut id elit. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nulla vitae elit libero, a pharetra augue.

+
+
+

24.Aenean lacinia bibendum nulla sed consectetur. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Nullam id dolor id nibh ultricies vehicula ut id elit. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nulla vitae elit libero, a pharetra augue.

+
+ +
+ +
+ +
+
+

30.Aenean lacinia bibendum nulla sed consectetur. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Nullam id dolor id nibh ultricies vehicula ut id elit. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nulla vitae elit libero, a pharetra augue.

+
+
+ +
+ + + + +
+ +
+ +
+ +
+

Lorem Ipsum Dolor

+

Etiam porta sem malesuada magna mollis euismod

+ + +
+
+
+
+

Donec sed odio dui. Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.

+ + +

Pellentesque ornare sem

+ +

Maecenas sed diam eget risus varius blandit sit amet non magna. Maecenas faucibus mollis interdum. Donec ullamcorper nulla non metus auctor fringilla. Nullam id dolor id nibh ultricies vehicula ut id elit. Nullam id dolor id nibh ultricies vehicula ut id elit.

+ +

Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.

+ +

Nulla vitae elit libero, a pharetra augue. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Aenean lacinia bibendum nulla sed consectetur.

+ +

Nullam quis risus eget urna mollis ornare vel eu leo. Nullam quis risus eget urna mollis ornare vel eu leo. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec ullamcorper nulla non metus auctor fringilla.

+ +

Cras mattis consectetur

+ +

Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Aenean lacinia bibendum nulla sed consectetur. Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Cras mattis consectetur purus sit amet fermentum.

+ +

Nullam id dolor id nibh ultricies vehicula ut id elit. Nullam quis risus eget urna mollis ornare vel eu leo. Cras mattis consectetur purus sit amet fermentum.

+
+ + +
+ +
+ + + + + + +
+
+
+ +

Language Support

+

The subset of VCR OSD Mono Regular in this kit supports the following languages:
+ + Albanian, Basque, Breton, Chamorro, Danish, English, Faroese, Finnish, Frisian, Galician, German, Icelandic, Italian, Malagasy, Norwegian, Portuguese, Spanish, Alsatian, Aragonese, Arapaho, Arrernte, Asturian, Aymara, Bislama, Cebuano, Corsican, Fijian, French_creole, Genoese, Gilbertese, Greenlandic, Haitian_creole, Hiligaynon, Hmong, Hopi, Ibanag, Iloko_ilokano, Indonesian, Interglossa_glosa, Interlingua, Irish_gaelic, Jerriais, Lojban, Lombard, Luxembourgeois, Manx, Mohawk, Norfolk_pitcairnese, Occitan, Oromo, Pangasinan, Papiamento, Piedmontese, Potawatomi, Rhaeto-romance, Romansh, Rotokas, Sami_lule, Sardinian, Scots_gaelic, Seychelles_creole, Shona, Sicilian, Somali, Southern_ndebele, Swahili, Swati_swazi, Tagalog_filipino_pilipino, Tetum, Tok_pisin, Uyghur_latinized, Volapuk, Walloon, Warlpiri, Xhosa, Yapese, Zulu, Latinbasic, Ubasic, Demo

+

Glyph Chart

+

The subset of VCR OSD Mono Regular in this kit includes all the glyphs listed below. Unicode entities are included above each glyph to help you insert individual characters into your layout.

+
+ +

&#29;


+

&#13;

+

&#29;


+

&#32;

+

&#33;

!
+

&#34;

"
+

&#35;

#
+

&#36;

$
+

&#37;

%
+

&#38;

&
+

&#39;

'
+

&#40;

(
+

&#41;

)
+

&#42;

*
+

&#43;

+
+

&#44;

,
+

&#45;

-
+

&#46;

.
+

&#47;

/
+

&#48;

0
+

&#49;

1
+

&#50;

2
+

&#51;

3
+

&#52;

4
+

&#53;

5
+

&#54;

6
+

&#55;

7
+

&#56;

8
+

&#57;

9
+

&#58;

:
+

&#59;

;
+

&#60;

<
+

&#61;

=
+

&#62;

>
+

&#63;

?
+

&#64;

@
+

&#65;

A
+

&#66;

B
+

&#67;

C
+

&#68;

D
+

&#69;

E
+

&#70;

F
+

&#71;

G
+

&#72;

H
+

&#73;

I
+

&#74;

J
+

&#75;

K
+

&#76;

L
+

&#77;

M
+

&#78;

N
+

&#79;

O
+

&#80;

P
+

&#81;

Q
+

&#82;

R
+

&#83;

S
+

&#84;

T
+

&#85;

U
+

&#86;

V
+

&#87;

W
+

&#88;

X
+

&#89;

Y
+

&#90;

Z
+

&#91;

[
+

&#92;

\
+

&#93;

]
+

&#94;

^
+

&#95;

_
+

&#96;

`
+

&#97;

a
+

&#98;

b
+

&#99;

c
+

&#100;

d
+

&#101;

e
+

&#102;

f
+

&#103;

g
+

&#104;

h
+

&#105;

i
+

&#106;

j
+

&#107;

k
+

&#108;

l
+

&#109;

m
+

&#110;

n
+

&#111;

o
+

&#112;

p
+

&#113;

q
+

&#114;

r
+

&#115;

s
+

&#116;

t
+

&#117;

u
+

&#118;

v
+

&#119;

w
+

&#120;

x
+

&#121;

y
+

&#122;

z
+

&#123;

{
+

&#124;

|
+

&#125;

}
+

&#126;

~
+

&#160;

 
+

&#161;

¡
+

&#162;

¢
+

&#163;

£
+

&#165;

¥
+

&#166;

¦
+

&#168;

¨
+

&#169;

©
+

&#170;

ª
+

&#171;

«
+

&#173;

­
+

&#174;

®
+

&#176;

°
+

&#178;

²
+

&#179;

³
+

&#180;

´
+

&#185;

¹
+

&#186;

º
+

&#187;

»
+

&#188;

¼
+

&#189;

½
+

&#190;

¾
+

&#191;

¿
+

&#192;

À
+

&#193;

Á
+

&#194;

Â
+

&#195;

Ã
+

&#196;

Ä
+

&#197;

Å
+

&#198;

Æ
+

&#199;

Ç
+

&#200;

È
+

&#201;

É
+

&#202;

Ê
+

&#203;

Ë
+

&#204;

Ì
+

&#205;

Í
+

&#206;

Î
+

&#207;

Ï
+

&#208;

Ð
+

&#209;

Ñ
+

&#210;

Ò
+

&#211;

Ó
+

&#212;

Ô
+

&#213;

Õ
+

&#214;

Ö
+

&#216;

Ø
+

&#217;

Ù
+

&#218;

Ú
+

&#219;

Û
+

&#220;

Ü
+

&#221;

Ý
+

&#222;

Þ
+

&#223;

ß
+

&#224;

à
+

&#225;

á
+

&#226;

â
+

&#227;

ã
+

&#228;

ä
+

&#229;

å
+

&#230;

æ
+

&#231;

ç
+

&#232;

è
+

&#233;

é
+

&#234;

ê
+

&#235;

ë
+

&#236;

ì
+

&#237;

í
+

&#238;

î
+

&#239;

ï
+

&#240;

ð
+

&#241;

ñ
+

&#242;

ò
+

&#243;

ó
+

&#244;

ô
+

&#245;

õ
+

&#246;

ö
+

&#248;

ø
+

&#249;

ù
+

&#250;

ú
+

&#251;

û
+

&#252;

ü
+

&#253;

ý
+

&#254;

þ
+

&#255;

ÿ
+

&#8192;

 
+

&#8193;

+

&#8194;

+

&#8195;

+

&#8196;

+

&#8197;

+

&#8198;

+

&#8199;

+

&#8200;

+

&#8201;

+

&#8202;

+

&#8208;

+

&#8209;

+

&#8210;

+

&#8211;

+

&#8212;

+

&#8216;

+

&#8217;

+

&#8220;

+

&#8221;

+

&#8226;

+

&#8230;

+

&#8239;

+

&#8249;

+

&#8250;

+

&#8287;

+

&#8364;

+

&#8482;

+

&#9724;

+
+
+ + +
+
+ + +
+ +
+ +
+
+
+

Installing Webfonts

+ +

Webfonts are supported by all major browser platforms but not all in the same way. There are currently four different font formats that must be included in order to target all browsers. This includes TTF, WOFF, EOT and SVG.

+ +

1. Upload your webfonts

+

You must upload your webfont kit to your website. They should be in or near the same directory as your CSS files.

+ +

2. Include the webfont stylesheet

+

A special CSS @font-face declaration helps the various browsers select the appropriate font it needs without causing you a bunch of headaches. Learn more about this syntax by reading the Fontspring blog post about it. The code for it is as follows:

+ + + +@font-face{ + font-family: 'MyWebFont'; + src: url('WebFont.eot'); + src: url('WebFont.eot?#iefix') format('embedded-opentype'), + url('WebFont.woff') format('woff'), + url('WebFont.ttf') format('truetype'), + url('WebFont.svg#webfont') format('svg'); +} + + +

We've already gone ahead and generated the code for you. All you have to do is link to the stylesheet in your HTML, like this:

+ <link rel="stylesheet" href="stylesheet.css" type="text/css" charset="utf-8" /> + +

3. Modify your own stylesheet

+

To take advantage of your new fonts, you must tell your stylesheet to use them. Look at the original @font-face declaration above and find the property called "font-family." The name linked there will be what you use to reference the font. Prepend that webfont name to the font stack in the "font-family" property, inside the selector you want to change. For example:

+p { font-family: 'WebFont', Arial, sans-serif; } + +

4. Test

+

Getting webfonts to work cross-browser can be tricky. Use the information in the sidebar to help you if you find that fonts aren't loading in a particular browser.

+
+ + +
+ +
+ +
+ +
+ + \ No newline at end of file diff --git a/css/vcr_osd_mono_1.001-webfont.woff b/css/vcr_osd_mono_1.001-webfont.woff new file mode 100755 index 0000000..5b551c3 Binary files /dev/null and b/css/vcr_osd_mono_1.001-webfont.woff differ diff --git a/css/vcr_osd_mono_1.001-webfont.woff2 b/css/vcr_osd_mono_1.001-webfont.woff2 new file mode 100755 index 0000000..9e8d3ac Binary files /dev/null and b/css/vcr_osd_mono_1.001-webfont.woff2 differ diff --git a/css/webfontkit-20220220-160412.zip b/css/webfontkit-20220220-160412.zip new file mode 100755 index 0000000..806fcd0 Binary files /dev/null and b/css/webfontkit-20220220-160412.zip differ diff --git a/img/pencil.png b/img/pencil.png new file mode 100755 index 0000000..5de29ce Binary files /dev/null and b/img/pencil.png differ diff --git a/img/question.png b/img/question.png new file mode 100755 index 0000000..364e043 Binary files /dev/null and b/img/question.png differ diff --git a/index.html b/index.html new file mode 100755 index 0000000..ad396b4 --- /dev/null +++ b/index.html @@ -0,0 +1,97 @@ + + + + + + CPU sim + + + + + + + + + + + + + + + diff --git a/js/assembler copy.js b/js/assembler copy.js new file mode 100755 index 0000000..d0facf3 --- /dev/null +++ b/js/assembler copy.js @@ -0,0 +1,294 @@ +Array.prototype.findIndexes=function(where) { + return this.reduce((a, e, i) => (where(e, i) ? a.concat(i) : a), []); +} +class assembler { + labels = []; + labelAddresses = []; + address = 0; + curLine = 0; + + offset = 0; // account for any instructions the assembler needs to add + upper8(address){ + return address>>8; + } + lower8(address){ + return address&0x00FF; + } + intByte(n){ + n=n.replace("#",""); + var invert = false; + if(n[0]=="~") { invert=true; n=n.slice(1)}; + var b = 0; + if(n.match(/^0b/)){ + b = parseInt(n.slice(2),2); + } else { + b = parseInt(n); + } + if(isNaN(b)) { + throw 'Invalid number'; + } else if(b>255 || b <-128){ + throw 'Number will not fit in a byte!'; + } + if(b<0){ + // apply 2's complement to negative value + var r= ~Math.abs(b)+1; + } else { + var r= b; + }; + return invert ? ((~r>>>0)&0xFF) : r; + } + encodeInstruction(line){ + var bytes = [0,0]; + var instruction = instructions.opcodes.find(oc=>oc.mnemonic==line[0].toLowerCase()); + if(instruction.mnemonic=="bflag"||instruction.mnemonic=="bnoflag") { + var flag = instructions.flags.indexOf(line[1]); + if(flag>=0){ + // evil stupid dumb + line[1] = line[1].replace(instructions.flags[flag],instructions.registers[flag]); + + } else throw 'Invalid flag.'; + } + if(!instruction) throw 'Unknown opcode'; + var patterns = instructions.arg_patterns[instruction.patterns]; + var mode = -1; + if(patterns[0].pattern.length!=line.length-1){ + throw 'Wrong number of operands'; + } else if(patterns.length==1){ + mode = patterns[0].mode; + } else { + patterns.forEach(pattern=>{ + var fit=0; + for(var i=0;i{ + var l; + var mnemonic = instruction[0].toLowerCase(); + this.curLine = i; + var offset=0; + // dealing with pseudo instructions + if(mnemonic==".data"){ + return; + /* + } else if(mnemonic=="hlt"){ // halt: jump to same instruction + if(this.upper8(instAddr)!=instPage){ + instPage=this.upper8(instAddr); + bytecode=bytecode.concat(this.encodeInstruction(["mov","ibank","#"+instPage])); + offset=2; + } + bytecode = bytecode.concat(this.encodeInstruction(["jmp","#"+this.lower8(instAddr+offset)])); + } else if(mnemonic=="nop"){ // nop: jump to next instruction + if(this.upper8(instAddr+2)!=instPage){ + offset=2; + instPage=this.upper8(instAddr); + bytecode=bytecode.concat(this.encodeInstruction(["mov","ibank","#"+instPage])); + } + bytecode = bytecode.concat(this.encodeInstruction(["jmp","#"+this.lower8(instAddr+2+offset)])); + */ + // now process labels + } else if(mnemonic=="jsr"||mnemonic=="jmp"){ + instruction[1] = instruction[1].replace("SKIP",'#'+(instAddr+4+offset)); + l = this.labelAddresses.find(la=>instruction[1].includes(la.label)); + + if(l){ // we must replace + instruction[1] = instruction[1].replace(l.label, "#"+this.lower8(l.address)); + if(this.upper8(l.address)!=instPage){ + instPage=this.upper8(l.address); + bytecode=bytecode.concat(this.encodeInstruction(["mov","ip","#"+instPage])); + offset=2; + } + } + console.log(instruction); + bytecode=bytecode.concat(this.encodeInstruction(instruction)); + } else if(mnemonic=="stb"||mnemonic=="ldb"||mnemonic=="mov"||mnemonic=="bflag"||mnemonic=="bnoflag"){ + // QUICK AND DIRTY: WILL BREAK UNDER CERTAIN CONDITIONS + instruction[2] = instruction[2].replace("SKIP",'#'+(instAddr+4+offset)); + l = this.labelAddresses.find(la=>instruction[2].includes(la.label)); + if(l){ // we must replace + instruction[2] = instruction[2].replace(l.label, "#"+this.lower8(l.address)); + if(this.upper8(l.address)!=dataPage){ + dataPage=this.upper8(l.address); + bytecode=bytecode.concat(this.encodeInstruction(["mov","dp","#"+dataPage])); + offset=2; + } + } + bytecode=bytecode.concat(this.encodeInstruction(instruction)); + } else bytecode=bytecode.concat(this.encodeInstruction(instruction)); + console.log({i:i, l:this.labels}); + l = this.labels.findIndex(la=>la.line==i); + if(l>-1){ + this.labelAddresses.push({label: this.labels[l].label, address: instAddr}); + } + instAddr += 2 + offset; + }); + return bytecode; + } + assemble(code) { + // try + var tokens = this.tokenize(code).filter(line=>line.length>0 &&line[0]!=''); + console.log(tokens); + var withPseudo = this.processAndOr(tokens); + var delabeled = this.processLabels(withPseudo); + var data = this.processData(delabeled); + var bytecode = this.processInstructions(delabeled); + var pad = data.bytes.length>0?Array(data.start - bytecode.length).fill(0):[]; + console.log({tokens,withPseudo,delabeled,data,bytecode}) + + return bytecode.concat(pad).concat(data.bytes); + // catch + } + processAndOr(tokenLines) { + var processed=[]; + tokenLines.forEach(line=>{ + if(line.length<2){ + processed.push(line) + } + else if(line[0].toLowerCase()=="and") { + line[0] = "nand"; + processed.push(line); // NAND a, b + processed.push(['nand',line[1],line[1]]); // NAND a, a + } else if(line[1].toLowerCase()=="and") { + line[1] = "nand"; + processed.push(line); // ibid + processed.push(['nand',line[2],line[2]]); + } else if(line[0].toLowerCase()=="or") { + processed.push(['nand',line[1],line[1]]); // NAND a, a + if(line[2].toLowerCase().match(instructions.match.reg)){ + processed.push(['nand',line[2],line[2]]); // NAND b, b + processed.push(['nand',line[1],line[2]]); // NAND a, b + processed.push(['nand',line[2],line[2]]); // NAND b, b + } else if(line[2].toLowerCase().match(instructions.match.imm8)) { + //int imm8 = intByte(this.intByte(line[2]); // NAND b, b + processed.push(['nand',line[1],"~"+line[2]]);//line[2]]); // NAND a, b + } else if(line[2].toLowerCase().match(instructions.match.label)) { + processed.push(['nand',line[1],"~"+line[2]]);// NAND a, ~b + } else throw("error converting and"); + } else if(line[1].toLowerCase()=="or"){ + processed.push(['nand',line[2],line[2]]); // NAND a, a + if(line[3].toLowerCase().match(/(ip|dp|sp|r[0-3])/)){ + processed.push(['nand',line[3],line[3]]); // NAND b, b + processed.push(['nand',line[2],line[3]]); // NAND a, b + processed.push(['nand',line[3],line[3]]); // NAND b, b + } else if(line[3].toLowerCase().match(instructions.match.imm8)) { + imm8 = ~this.intByte(line[3]); // NAND b, b + processed.push(['nand',line[2],line[3]]); // NAND a, b + } else if(line[3].toLowerCase().match(instructions.match.label)) { + processed.push(['nand',line[2],"~"+line[3]]);// NAND a, ~b + } else throw("error converting and"); + + } else { + processed.push(line); + } + }); + return processed; + } + processLabels(tokenLines) { + var processed = []; + // first pass: extract labels + for(var i=0;i 1 && curLine[1]!=''){ + // first token was label; next token will be opcode or data + processed.push(curLine.slice(1)); + } + this.labels.push({ label: curLine[0].split(/:.*/)[0], line: lineNum }); + //processed.push(curLine.slice(1)); + } else processed.push(curLine); + } + return processed; + } + processData(tokenLines) { + // we want to find out where the end of the instructions will be + // however, we don't know how many the assembler will insert to deal with pages + // i can't be bothered doing this properly so let's just add an extra two bytes + // for every instruction that accesses memory + // get number of instructions that deal with memory + var dataInstructions = tokenLines.findIndexes(line=>line[0].toLowerCase().match('^.data$')); + var numMem = tokenLines.filter(line => line[0].toLowerCase().match(/(ldb|stb|jsr|jmp|bflag|bnoflag)/)).length; + var start = ( (tokenLines.length - dataInstructions.length) + numMem )* 2; + var curAddr = 0; + var bytes = []; + dataInstructions.forEach(i=>{ + this.curLine = i; + var thisLabel = this.labels.find(l => l.line== i); + if(thisLabel){ + this.labelAddresses.push({ label: thisLabel.label, address: curAddr+start }); + } + tokenLines[i].slice(1).forEach(token=>{ + // if string + if(token.match(/^".*"$/)) { + token.slice(1).slice(0,-1).replace(/[^\x00-\x7F]/g, "").split('').forEach(character=>{ + bytes.push(character.charCodeAt(0)); + curAddr += 1; + }); + } else { + bytes.push(this.intByte(token)); + curAddr += 1; + } + }); + + }) + + return { start, bytes }; + + } + tokenize(code) { + var tokenLines = []; + // split code into lines - strings enclosed in quotes can span multiple lines + // nb this breaks for escaped quotes but who cares + var lines = code.split(/(?<=^[^\"]*(?:\"[^\"]*\"[^\"]*)*)\r?\n(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/); + lines.forEach(line=>{ + // split on wgutespace or comma, unless quoted + var tokens = line.split(/(?<=^[^\"]*(?:\"[^\"]*\"[^\"]*)*)[ ,]+(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/); + // remove comments preceded by ; + var hitSemicolon=false + var tokenLine=[]; + tokens.forEach(token=>{ + //console.log(token); + if(token[0]==";"||hitSemicolon){ + hitSemicolon=true; + } else { + tokenLine.push(token); + //console.log(tokenLine); + } + }) + tokenLines.push(tokenLine); + }) + return tokenLines; + } +} diff --git a/js/assembler.js b/js/assembler.js new file mode 100755 index 0000000..d0facf3 --- /dev/null +++ b/js/assembler.js @@ -0,0 +1,294 @@ +Array.prototype.findIndexes=function(where) { + return this.reduce((a, e, i) => (where(e, i) ? a.concat(i) : a), []); +} +class assembler { + labels = []; + labelAddresses = []; + address = 0; + curLine = 0; + + offset = 0; // account for any instructions the assembler needs to add + upper8(address){ + return address>>8; + } + lower8(address){ + return address&0x00FF; + } + intByte(n){ + n=n.replace("#",""); + var invert = false; + if(n[0]=="~") { invert=true; n=n.slice(1)}; + var b = 0; + if(n.match(/^0b/)){ + b = parseInt(n.slice(2),2); + } else { + b = parseInt(n); + } + if(isNaN(b)) { + throw 'Invalid number'; + } else if(b>255 || b <-128){ + throw 'Number will not fit in a byte!'; + } + if(b<0){ + // apply 2's complement to negative value + var r= ~Math.abs(b)+1; + } else { + var r= b; + }; + return invert ? ((~r>>>0)&0xFF) : r; + } + encodeInstruction(line){ + var bytes = [0,0]; + var instruction = instructions.opcodes.find(oc=>oc.mnemonic==line[0].toLowerCase()); + if(instruction.mnemonic=="bflag"||instruction.mnemonic=="bnoflag") { + var flag = instructions.flags.indexOf(line[1]); + if(flag>=0){ + // evil stupid dumb + line[1] = line[1].replace(instructions.flags[flag],instructions.registers[flag]); + + } else throw 'Invalid flag.'; + } + if(!instruction) throw 'Unknown opcode'; + var patterns = instructions.arg_patterns[instruction.patterns]; + var mode = -1; + if(patterns[0].pattern.length!=line.length-1){ + throw 'Wrong number of operands'; + } else if(patterns.length==1){ + mode = patterns[0].mode; + } else { + patterns.forEach(pattern=>{ + var fit=0; + for(var i=0;i{ + var l; + var mnemonic = instruction[0].toLowerCase(); + this.curLine = i; + var offset=0; + // dealing with pseudo instructions + if(mnemonic==".data"){ + return; + /* + } else if(mnemonic=="hlt"){ // halt: jump to same instruction + if(this.upper8(instAddr)!=instPage){ + instPage=this.upper8(instAddr); + bytecode=bytecode.concat(this.encodeInstruction(["mov","ibank","#"+instPage])); + offset=2; + } + bytecode = bytecode.concat(this.encodeInstruction(["jmp","#"+this.lower8(instAddr+offset)])); + } else if(mnemonic=="nop"){ // nop: jump to next instruction + if(this.upper8(instAddr+2)!=instPage){ + offset=2; + instPage=this.upper8(instAddr); + bytecode=bytecode.concat(this.encodeInstruction(["mov","ibank","#"+instPage])); + } + bytecode = bytecode.concat(this.encodeInstruction(["jmp","#"+this.lower8(instAddr+2+offset)])); + */ + // now process labels + } else if(mnemonic=="jsr"||mnemonic=="jmp"){ + instruction[1] = instruction[1].replace("SKIP",'#'+(instAddr+4+offset)); + l = this.labelAddresses.find(la=>instruction[1].includes(la.label)); + + if(l){ // we must replace + instruction[1] = instruction[1].replace(l.label, "#"+this.lower8(l.address)); + if(this.upper8(l.address)!=instPage){ + instPage=this.upper8(l.address); + bytecode=bytecode.concat(this.encodeInstruction(["mov","ip","#"+instPage])); + offset=2; + } + } + console.log(instruction); + bytecode=bytecode.concat(this.encodeInstruction(instruction)); + } else if(mnemonic=="stb"||mnemonic=="ldb"||mnemonic=="mov"||mnemonic=="bflag"||mnemonic=="bnoflag"){ + // QUICK AND DIRTY: WILL BREAK UNDER CERTAIN CONDITIONS + instruction[2] = instruction[2].replace("SKIP",'#'+(instAddr+4+offset)); + l = this.labelAddresses.find(la=>instruction[2].includes(la.label)); + if(l){ // we must replace + instruction[2] = instruction[2].replace(l.label, "#"+this.lower8(l.address)); + if(this.upper8(l.address)!=dataPage){ + dataPage=this.upper8(l.address); + bytecode=bytecode.concat(this.encodeInstruction(["mov","dp","#"+dataPage])); + offset=2; + } + } + bytecode=bytecode.concat(this.encodeInstruction(instruction)); + } else bytecode=bytecode.concat(this.encodeInstruction(instruction)); + console.log({i:i, l:this.labels}); + l = this.labels.findIndex(la=>la.line==i); + if(l>-1){ + this.labelAddresses.push({label: this.labels[l].label, address: instAddr}); + } + instAddr += 2 + offset; + }); + return bytecode; + } + assemble(code) { + // try + var tokens = this.tokenize(code).filter(line=>line.length>0 &&line[0]!=''); + console.log(tokens); + var withPseudo = this.processAndOr(tokens); + var delabeled = this.processLabels(withPseudo); + var data = this.processData(delabeled); + var bytecode = this.processInstructions(delabeled); + var pad = data.bytes.length>0?Array(data.start - bytecode.length).fill(0):[]; + console.log({tokens,withPseudo,delabeled,data,bytecode}) + + return bytecode.concat(pad).concat(data.bytes); + // catch + } + processAndOr(tokenLines) { + var processed=[]; + tokenLines.forEach(line=>{ + if(line.length<2){ + processed.push(line) + } + else if(line[0].toLowerCase()=="and") { + line[0] = "nand"; + processed.push(line); // NAND a, b + processed.push(['nand',line[1],line[1]]); // NAND a, a + } else if(line[1].toLowerCase()=="and") { + line[1] = "nand"; + processed.push(line); // ibid + processed.push(['nand',line[2],line[2]]); + } else if(line[0].toLowerCase()=="or") { + processed.push(['nand',line[1],line[1]]); // NAND a, a + if(line[2].toLowerCase().match(instructions.match.reg)){ + processed.push(['nand',line[2],line[2]]); // NAND b, b + processed.push(['nand',line[1],line[2]]); // NAND a, b + processed.push(['nand',line[2],line[2]]); // NAND b, b + } else if(line[2].toLowerCase().match(instructions.match.imm8)) { + //int imm8 = intByte(this.intByte(line[2]); // NAND b, b + processed.push(['nand',line[1],"~"+line[2]]);//line[2]]); // NAND a, b + } else if(line[2].toLowerCase().match(instructions.match.label)) { + processed.push(['nand',line[1],"~"+line[2]]);// NAND a, ~b + } else throw("error converting and"); + } else if(line[1].toLowerCase()=="or"){ + processed.push(['nand',line[2],line[2]]); // NAND a, a + if(line[3].toLowerCase().match(/(ip|dp|sp|r[0-3])/)){ + processed.push(['nand',line[3],line[3]]); // NAND b, b + processed.push(['nand',line[2],line[3]]); // NAND a, b + processed.push(['nand',line[3],line[3]]); // NAND b, b + } else if(line[3].toLowerCase().match(instructions.match.imm8)) { + imm8 = ~this.intByte(line[3]); // NAND b, b + processed.push(['nand',line[2],line[3]]); // NAND a, b + } else if(line[3].toLowerCase().match(instructions.match.label)) { + processed.push(['nand',line[2],"~"+line[3]]);// NAND a, ~b + } else throw("error converting and"); + + } else { + processed.push(line); + } + }); + return processed; + } + processLabels(tokenLines) { + var processed = []; + // first pass: extract labels + for(var i=0;i 1 && curLine[1]!=''){ + // first token was label; next token will be opcode or data + processed.push(curLine.slice(1)); + } + this.labels.push({ label: curLine[0].split(/:.*/)[0], line: lineNum }); + //processed.push(curLine.slice(1)); + } else processed.push(curLine); + } + return processed; + } + processData(tokenLines) { + // we want to find out where the end of the instructions will be + // however, we don't know how many the assembler will insert to deal with pages + // i can't be bothered doing this properly so let's just add an extra two bytes + // for every instruction that accesses memory + // get number of instructions that deal with memory + var dataInstructions = tokenLines.findIndexes(line=>line[0].toLowerCase().match('^.data$')); + var numMem = tokenLines.filter(line => line[0].toLowerCase().match(/(ldb|stb|jsr|jmp|bflag|bnoflag)/)).length; + var start = ( (tokenLines.length - dataInstructions.length) + numMem )* 2; + var curAddr = 0; + var bytes = []; + dataInstructions.forEach(i=>{ + this.curLine = i; + var thisLabel = this.labels.find(l => l.line== i); + if(thisLabel){ + this.labelAddresses.push({ label: thisLabel.label, address: curAddr+start }); + } + tokenLines[i].slice(1).forEach(token=>{ + // if string + if(token.match(/^".*"$/)) { + token.slice(1).slice(0,-1).replace(/[^\x00-\x7F]/g, "").split('').forEach(character=>{ + bytes.push(character.charCodeAt(0)); + curAddr += 1; + }); + } else { + bytes.push(this.intByte(token)); + curAddr += 1; + } + }); + + }) + + return { start, bytes }; + + } + tokenize(code) { + var tokenLines = []; + // split code into lines - strings enclosed in quotes can span multiple lines + // nb this breaks for escaped quotes but who cares + var lines = code.split(/(?<=^[^\"]*(?:\"[^\"]*\"[^\"]*)*)\r?\n(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/); + lines.forEach(line=>{ + // split on wgutespace or comma, unless quoted + var tokens = line.split(/(?<=^[^\"]*(?:\"[^\"]*\"[^\"]*)*)[ ,]+(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/); + // remove comments preceded by ; + var hitSemicolon=false + var tokenLine=[]; + tokens.forEach(token=>{ + //console.log(token); + if(token[0]==";"||hitSemicolon){ + hitSemicolon=true; + } else { + tokenLine.push(token); + //console.log(tokenLine); + } + }) + tokenLines.push(tokenLine); + }) + return tokenLines; + } +} diff --git a/js/index.js b/js/index.js new file mode 100755 index 0000000..9295aa5 --- /dev/null +++ b/js/index.js @@ -0,0 +1,1129 @@ +var registers=[]; +var blocks=[]; +var wires=[]; +var tooltips=[]; +var embedded = {}; +var images={}; +const BORDER_THICKNESS=5.5; +var canvas, ctx; +var outputBuf = [] +var clockTimer; +var opcodes = ['add','sub','adc','subb','nand','xor','sll','srl','mov','ldb','stb', 'nop','bflag','bnoflag', 'jmp', 'hlt']; +var rs = ['io','stackptr','datapg','instpg','gp0','gp1','gp2','gp3']; +var flags = ['zero','carry','negative','overflow','input']; +var memory=new Array(65536).fill(0); +var memPage = 0; +var dataPage = 0; +function getNumber(pins,reverse=true){ + var val = 0; + for(var i=0;i>12; + var addressMode = (machineCode & 0b0000100000000000) >>11; + var r1 = (machineCode & 0b0000011100000000)>>8; + var r2 = (machineCode & 0b0000000011100000)>>5; + var imm8 = machineCode & 0b0000000011111111; + if(opcode==15){ + return(opcodes[opcode]); + } else if(opcode<11) { + return(`${opcodes[opcode]} ${specific?rs[r1]:'reg'}, ${specific?((addressMode?imm8:rs[r2])):addressMode?'imm8':'reg'}`); + } else if (opcode==11){ + return(`${opcodes[opcode]}`); + } else if(opcode==12) { + return(`${opcodes[opcode]} ${specific?flags[r1 & 0b00000111]:'flag'}, ${specific?((addressMode?imm8:rs[r2])):addressMode?'imm8':'reg'}`); + } else { + return(`${opcodes[opcode]} ${specific?((addressMode?imm8:rs[r2])):(addressMode?'imm8':'reg')}`); + } + +} +document.addEventListener("DOMContentLoaded", function(event){ + event; + canvas = document.getElementById("sim"); + ctx = canvas.getContext('2d'); + setup(); + setTimeout(function(){ + embedded['alu'] = document.getElementById('ALUframe').contentWindow.chip; + embedded['mux1'] = document.getElementById('MUX1frame').contentWindow.chip; + embedded['mux2'] = document.getElementById('MUX2frame').contentWindow.chip; + },2000); +}); +function w(width){ + return ((width*canvas.width)/1440); +} +function h(height){ + return ((height*canvas.height)/976); +} +function drawBorder(thing,thickness,color="black"){ + ctx.fillStyle=color; + ctx.fillRect(thing.x-thickness,thing.y-thickness,thing.width+thickness*2,thing.height+thickness*2); +} + +class Block { + constructor(name, x, y, width, height,points=[],editable=true){ + this.name=name; + this.url=""; + this.x=w(x); + this.y=h(y); + this.width=w(width); + this.height=h(height); + this.editable=editable; + this.points=points; + if(this.editable) + this.done=false; + else + this.done=true; + } + update(){ + } + reset(){ + } + makePointArray(){ + this.points=[] + for(const[key,value] of Object.entries(this.pins)){ + key; + //this.points=this.points.concat(value); + value.forEach((pin,i)=>{ pin.number=i; this.points.push(pin) }); + } + + } + drawOverlay(){ + if(!(this.done||this.attempted)){ + ctx.fillStyle="rgba(255,255,255,0.6)"; + ctx.fillRect(this.x,this.y+BORDER_THICKNESS+35,this.width,this.height-BORDER_THICKNESS-35); + ctx.fillStyle="#FFA500" + if(this.wrong) + ctx.fillStyle="#dd3333"; + ctx.fillRect(this.x+this.width/2-35,this.y+this.height/2-35+17,70,70); + ctx.drawImage(images[this.editable?'pencil':'question'],this.x+this.width/2-30,this.y+this.height/2-30+17,60,60); + } else + if(this.editable) + ctx.drawImage(images[this.editable?'pencil':'question'],this.x+this.width-w(37),this.y+this.height-h(30)-h(3),w(30),h(30)); + } + draw(color='white',textcolor='white'){ + ctx.fillStyle=color; + ctx.fillRect(this.x, this.y, this.width, this.height); + ctx.fillStyle="#444"; + ctx.fillRect(this.x,this.y,this.width,BORDER_THICKNESS); + ctx.fillRect(this.x-BORDER_THICKNESS,this.y,BORDER_THICKNESS,this.height+BORDER_THICKNESS); + ctx.fillRect(this.x+this.width,this.y,BORDER_THICKNESS,this.height+BORDER_THICKNESS); + ctx.fillRect(this.x,this.y+this.height,this.width,BORDER_THICKNESS); + if(this.done) + ctx.fillStyle="#43c143"; + else if(!this.attempted) + ctx.fillStyle="#ffa500"; + else + ctx.fillStyle="#dd3333"; + if(this.wrong){ + ctx.fillStyle="#dd3333"; + } + ctx.fillRect(this.x,this.y+BORDER_THICKNESS,this.width,35); + ctx.fillStyle=textcolor; + ctx.font=170*0.15+"px vcr_osd_monoregular"; + ctx.textBaseline = "top"; + ctx.textAlign='left'; + ctx.fillText(this.name,this.x+w(7), this.y+h(13)); + + + this.points.forEach(p=>p.draw()); + } + checkMouse(pos){ + // check if mouse is over icon + if(!this.attempted&&this.editable){ + return pos.x>=this.x+this.width/2-35 && pos.y>=this.y+this.height/2-35 && pos.x<=this.x+this.width/2-35+70 && pos.y<=this.y+this.height/2-35+70; + } else + return pos.x>=this.x+this.width-w(37) && pos.x<=this.x+this.width-w(7) && pos.y>=this.y+this.height-h(33) && pos.y<=this.y+this.height-h(3) && JSON.stringify(Array.from(ctx.getImageData(pos.x,pos.y,1,1).data.slice(0,3)))!="[255,255,255]"; + } +} +class Decoder extends Block { + update(){ + this.setInstruction(humanInstruction(registers[0].value,false),(registers[0].value>>12)); + for(var i=0;i<16;i++){ + if(i<4){ + this.pins.toALU[i].write(this.pins.instruction[i].read()); + } + } + // read from first register only if it's an ALU operation + // write to the first register unless we're in a store or branch instruction + this.pins.registerReadEnable[0].write(this.opcode<8); + this.pins.registerWriteEnable[0].write(this.opcode<10); + // imm8 + this.pins.toMux[0].write(this.pins.instruction[4].read() && this.opcode!=11 &&this.opcode!=15);//(this.mode==1 && this.opcode!=11 && this.opcode!=15)); + + // mem load + this.pins.toMux[1].write(this.opcode==9); + this.pins.memDataReadEnable[0].write(this.opcode==9); + this.pins.memDataWriteEnable[0].write(this.opcode==10); + // + this.pins.memAddrWriteEnable[0].write(this.opcode==9||this.opcode==10); + // jumps + if(this.opcode==14) + this.pins.pcWriteEnable[0].write(1); + else if(this.opcode!=12&&this.opcode!=13) + this.pins.pcWriteEnable[0].write(0); + else + this.pins.pcWriteEnable[0].write(branchyes?1:0); + } + setInstruction(instruction,opcode,mode){ + this.instruction = instruction; + this.opcode=opcode; + this.mode=mode; + } + constructor(x,y,width,height,points=[],editable=true){ + super("decoder",x,y,width,height,points,editable); + this.mode=0; + this.pins = { + instruction: [ + ], + toALU: [ + + ], + toMux: [ + new Pin(this.x+this.width,this.y+this.height-50,6,false,"right"), + new Pin(this.x+this.width,this.y+this.height-50+17,6,false,"right") + ], + registerWriteEnable: [ + new Pin(this.x+this.width,this.y+this.height-140,6,false,"right") + ], + registerReadEnable: [ + new Pin(this.x+this.width,this.y+this.height-157,6,false,"right") + ], + memAddrWriteEnable: [ + new Pin(this.x+190,this.y+this.height), + ], + memAddrReadEnable: [ + new Pin(this.x+207,this.y+this.height) + ], + pcWriteEnable: [ + new Pin(this.x+227+17,this.y+this.height) + ], + pcReadEnable: [ + new Pin(this.x+227+34,this.y+this.height) + ], + memDataWriteEnable:[ + new Pin(this.x+282+17,this.y+this.height) + ], + memDataReadEnable:[ + new Pin(this.x+282+34,this.y+this.height) + ], + + + + + } + for(var i=0;i<5;i++){ + this.pins.instruction.push(new Pin(this.x+17+17*i, this.y)); + if(i<4) + this.pins.toALU.push(new Pin((this.x+17+17*i+(i<4?0:34)), this.y+this.height)); + } + this.makePointArray(); + this.instruction="add reg,reg"; + this.opcode=0; + } + draw(){ + super.draw(); + ctx.fillStyle="black"; + ctx.font=250*0.07+"px vcr_osd_monoregular"; + ctx.textBaseline = "top"; + ctx.textAlign='center'; + ctx.fillText("opcode: "+Register.getBits(this.opcode,4)+" / "+Register.getHex(this.opcode,1)+"",this.x+this.width/2-w(4), this.y+h(55)); + var am=this.pins["instruction"][4].read(); + this.mode=am; + ctx.fillText("mode: "+(am?1:0)+" / "+(this.opcode==15?'special':(((am==0||this.opcode==11)?"register":"immediate"))),this.x+this.width/2-w(4), this.y+h(75)); + + ctx.font=240*0.15+"px vcr_osd_monoregular"; + ctx.fillText(this.instruction,this.x+this.width/2-w(4), this.y+h(100)); + } + + +} +class Mux extends Block { + setChannel(c){ + this.channel=c; + } + update(){ + if(this.second){ + if(!embedded.mux2 || !embedded.mux2.pins) return; + embedded.mux2.pins[16] = this.pins.selector[0].read(); + for(var i=0;i<8;i++){ + embedded.mux2.pins[i] = this.pins.channel0[i].read(); + embedded.mux2.pins[8+i] = this.pins.channel1[7-i].read(); + this.pins.output[7-i].write(embedded.mux2.pins[24-i]); + + }}else{ + if(!embedded.mux1 || !embedded.mux1.pins) return; + embedded.mux1.pins[16] = this.pins.selector[0].read(false); + for(var i=0;i<8;i++){ + embedded.mux1.pins[i] = this.pins.channel0[7-i].read(); + embedded.mux1.pins[8+i] = this.pins.channel1[i].read(); + this.pins.output[7-i].write(embedded.mux1.pins[24-i]); + + }} + + + + this.setChannel(this.pins.selector[0].read()==true?1:0); + } + constructor(x,y,width,height,second=false,de=false,points=[],editable=true){ + super((de?"de":"")+"multiplexer",x,y,width,height,points,editable); + this.de=de; + this.second=second; + this.channel=0; + if(second) + var theselector=new Pin(this.x+this.width-17, this.y); + else + var theselector=new Pin(this.x-BORDER_THICKNESS,blocks[0].pins.toMux[0].y,6,"","right") + if(!this.de){ + this.pins={ + selector: [ + theselector + ], + channel0:[ + ], + channel1: [ + ], + output:[ + ] + } + for(var i=0;i<8;i++){ + if(second){ + this.pins.channel1.push(new Pin(this.x+62+17*i,this.y+BORDER_THICKNESS+this.height,6,"","up")); + this.pins.output.push(new Pin(this.x+this.width,this.y+17+17*i,6,"","right")); + this.pins.channel0.push(new Pin(this.x-BORDER_THICKNESS,this.y+17+17*i,6,"","right")); + } else { + this.pins.channel1.push(new Pin(this.x+17+17*i,this.y)); + this.pins.channel0.push(new Pin(this.x+BORDER_THICKNESS+this.width,this.y+17+17*i,6,"","left")); + this.pins.output.push(new Pin(this.x+17+17*i,this.y+this.height)); + } + } + } else { + this.pins={ + selector: [ + new Pin(this.x-BORDER_THICKNESS,this.y+15,6,"","right"), + new Pin(this.x-BORDER_THICKNESS,this.y+30,6,"","right") + ], + input:[ + ], + channel0:[ + ], + channel1:[ + ], + channel2:[ + ] + } + for(var i=0;i<8;i++){ + this.pins.input.push(new Pin(this.x-BORDER_THICKNESS,this.y+67+17*i,6,"","right")); + this.pins.channel0.push(new Pin(this.x+this.width,this.y+17+17*i,6,"","right")); + this.pins.channel1.push(new Pin(this.x+17+17*i,this.y+this.height)); + this.pins.channel2.push(new Pin(this.x+220+17*i,this.y+this.height)); + } + } + this.makePointArray(); + } + draw(){ + super.draw(); + ctx.fillStyle="black"; + ctx.font="25px vcr_osd_monoregular"; + ctx.baseline="middle"; + ctx.textAlign="center"; + ctx.fillText(" channel: "+this.channel,this.x+this.width/2,this.y+this.height/2); + } +} +class ALU extends Block { + update(){ + if(!embedded.alu) return; + for(var i=0;i<8;i++){ + if(i<4){ + embedded.alu.pins[19-i] = this.pins.opcode[i].read(); + this.pins.flags[i].write(embedded.alu.pins[29+i]); + } + embedded.alu.pins[i] = this.pins.operand1[i].read(); + embedded.alu.pins[i+8] = this.pins.operand2[i].read(); + this.pins.result[i].write(embedded.alu.pins[21+i]); + } + this.values[3].set(getNumber(this.pins.flags)); + this.values[1].set(getNumber(this.pins.operand1,false)); + this.values[0].set(getNumber(this.pins.operand2,false)); + this.values[2].set(getNumber(this.pins.result,false)); + var opcode=getNumber(this.pins.opcode); + if(opcode==6){ + this.correctAnswer = this.values[1].value << this.values[0].value; + } else { + this.correctAnswer = -1; + } + if(opcode>=8){ + this.operation = "move"; + } else { + this.operation = opcodes[opcode]; + } + + } + constructor(x,y,width,height,points=[],editable=true){ + points; + super("ALU",x,y,width,height,wires,editable); + this.wrong=false; + this.operation="add"; + this.values=[new Register("operand 1",8,0,this.x+w(20),this.y+h(80),50,"above",true,"black"), + new Register("operand 0",8,0,this.x+w(20),this.y+h(175),50,"above",true,"black"), + new Register("result",8,0,this.x+w(20),this.y+h(340),50,"above",true,"black"), + new Register("O N C Z flags",4,1,this.x+w(20),this.y+h(410),32,"above",false,"black")]; + //new Register("O . N . C . Z",4,0,this.x+w(125),this.y+h(360),30,"above",false,"black")]; + this.pins={ opcode: []/*,setFlags:[]*/, operand1:[], operand2:[],flags:[],result:[] } + for(var i=0;i<4;i++){ + this.pins.opcode.push(new Pin(this.x+17+17*i,this.y)); + this.pins.flags.push(new Pin(this.x+17+17*i,this.y+this.height)); + } + this.pins.flags[3].write(1); + for(var i=0;i<8;i++){ + this.pins.operand2.push(new Pin(this.x+this.width+BORDER_THICKNESS, this.y+17+17*i,6,"","left")); + this.pins.operand1.push(new Pin(this.x+this.width+BORDER_THICKNESS, this.y+167+17*i,6,"","left")); + this.pins.result.push(new Pin(this.x+this.width, this.y+317+17*i,6,"","right")); + } + + //this.pins.setFlags.push(new Pin(this.x+17*5+34,this.y)); + //this.pins.setFlags[0].write(1); + + this.makePointArray(); + + } + draw(){ + super.draw(); + ctx.fillStyle="black"; + ctx.textAlign="center"; + ctx.textBaseline="middle"; + ctx.font="25px vcr_osd_monoregular"; + ctx.fillText("operation: "+this.operation,this.x+this.width/2, this.y+260); + ctx.font="15px vcr_osd_monoregular"; + //ctx.fillText("set flags: "+(this.pins.setFlags[0].read()==1?"yes":"no"),this.x+this.width/2, this.y+280); + ctx.fillRect(this.x+20,this.y+300,this.width-40,2); + this.values.forEach(v=>v.draw(0)); + } +} +class RegisterFile extends Block { + fileRegisters = []; + selected(){ + return{r1:this.fileRegisters[7-getNumber(this.pins.address1,false)], r2:this.fileRegisters[7-getNumber(this.pins.address2,false)]}; + } + update(){ + for(var i=0;i<8;i++){ + if(this.pins.read1Enable[0].read()) + this.pins.data1[7-i].write(this.selected().r1.binary[i]); + this.pins.data2[7-i].write(this.selected().r2.binary[i]); + } + } + realUpdate(){ + if(!!this.pins.write1Enable[0].read()) { + this.selected().r1.set(getNumber(this.pins.writeback,false),true); + } + } + constructor(x,y,fileRegisters=[],pins=[],editable=true){ + pins,editable; + super("registers",x,y,0,fileRegisters.length*h(85)+h(45),wires,false); + fileRegisters.forEach((r,i)=>{ + if(!r.bits){ + r.bits=8 + } + this.fileRegisters.push(new Register(r.name,r.bits,0,x+w(20),y+i*h(85)+h(65),40,"above",true,"black")); + }); + this.width=this.fileRegisters[0].width+w(80); + this.pins={ + clock:[ new Pin(this.x-BORDER_THICKNESS,this.y+17,6,"","right") ], + read1Enable: [ new Pin(this.x-BORDER_THICKNESS,this.y+17+35,6,"","right") ], + write1Enable: [new Pin(this.x-BORDER_THICKNESS,this.y+34+35,6,"","right") ], + address1: [ ], + address2: [ ], + data2:[ ], + data1:[ ], + writeback:[] + }; + for(var i=0;i<3;i++){ + this.pins.address2.push(new Pin(this.x-BORDER_THICKNESS,this.y+55+35+17+17*i,6,"","right")); + this.pins.address1.push(new Pin(this.x-BORDER_THICKNESS,this.y+125+35+17+17*i,6,"","right")); + } + for(var i=0;i<8;i++){ + this.pins.data2.push(new Pin(this.x,this.y+205+35+17+17*i,6,"","left")); + this.pins.data1.push(new Pin(this.x,this.y+365+35+17+17*i,6,"","left")); + this.pins.writeback.push(new Pin(this.x-BORDER_THICKNESS,this.y+530+35+17+17*i,6,"","right")); + } + super.makePointArray(); + } + draw(){ + super.draw(); + this.fileRegisters.forEach(r=>r.draw(1)); + } +} +class Clock extends Block { + reset(){ + this.state=0; + this.cycles=0; + } + update(){ + this.pins.clk[0].write(this.state); + } + constructor(x,y,width,height){ + super("clock",x,y,width,height,[],false); + this.pins={clk:[new Pin(this.x+this.width,this.y+17,6,"","right")]}; + super.makePointArray(); + this.cycles=0; + this.state=0; + } + pulse(t,w=false){ + this.state = 1; + if(!w) + this.cycles+=1; + setTimeout(function(){this.state=0}.bind(this),t/10); + } + draw(){ + super.draw(); + ctx.fillStyle="black"; + ctx.textAlign="center"; + ctx.textBaseline="middle"; + ctx.fillText(this.cycles,this.x+this.width/2,this.y+this.height/2+20); + } +} + +class Register { + pins=[]; + update(fuck=false){ + /*if(this.name=="memory address register" && fuck) return; + if(this.name=="m. data reg." && fuck) return;*/ + if(this.name=="flags"){ + this.set(getNumber(this.pins)); + if(document.getElementById("input").value.length>0) + this.value=this.value|0b10000; + else { + this.value=this.value & 0b01111; + } + this.set(this.value); + } + else if('writeEnable' in this) { + if(!!this.writeEnable.read()){ + this.set(getNumber(this.pins)); + } + } + if(this.name=="m. data reg."){ + var mAddr = registers[2].value; + if(this.writeEnable.read()){ + memory[mAddr] = this.value; + } + if(this.readEnable.read()||initialRun){ + initialRun=false; + this.set(memory[mAddr]); + } + } + } + static getBits(n,digits=8){ + if(n<0||n>=Math.pow(2,digits)||n%1!==0) { + //console.error(n+" is fucked, yo"); + } + return ("0000000000000000"+n.toString(2)).substr(-digits); + } + static getHex(n, digits=2){ + return "0x"+("0000"+n.toString(16).toUpperCase()).substr(-digits); + } + constructor(name, bits, value,x,y,scale,position="above",showValue=true,textColor="white",pins=false,numPins=8){ + this.name=name; + this.bits=bits; + this.x=w(x); + this.y=h(y); + this.width=w(scale * this.bits)*0.75; + this.height=h(scale); + this.above=position=="above"; + this.showValue=showValue; + this.textColor=textColor; + if(pins) + for(var i=bits-Math.min(bits,numPins);i{ pin.write(this.binary[i]) }); + + } + draw(border=0){ + if(this.name=="flags"){ + this.value=actualflags; + if(document.getElementById("input").value.length>0) + this.value=this.value|0b10000; + else { + this.value=this.value & 0b01111; + } + this.set(this.value); + } + + drawBorder(this,border); + ctx.fillStyle='white'; + ctx.fillRect(this.x,this.y,this.width,this.height); + var section_width = this.width/this.bits; + // draw text and separators + // labels + ctx.fillStyle = this.textColor; + ctx.font=this.height*0.4+"px vcr_osd_monoregular"; + var textY; + if(this.above){ + ctx.textBaseline = "bottom"; + textY = this.y-this.height*0.05; + } else { + ctx.textBaseline = "top"; + textY = this.y + this.height + this.height * 0.05; + ctx.fillStyle="rgba(24,27,32,0.5)"; + ctx.fillRect(this.x,this.y+this.height,this.width,21); + ctx.fillStyle="white"; + } + ctx.textAlign = "left"; + ctx.fillText(this.name,this.x,textY) + ctx.textAlign = "right"; + if(this.name=="instruction register"){ + ctx.fillText(humanInstruction(this.value),this.x+this.width,textY); + } else + this.showValue ? ctx.fillText(this.value+" | "+Register.getHex(this.value,(this.bits/4)),this.x+this.width,textY) : null; + + for(var i=0;i0) { + ctx.fillRect(this.x+section_width*i,this.y,2,this.height); + } + } + this.pins.forEach(pin=>pin.draw()); + if(this.readEnable){ + ctx.fillStyle="black"; + ctx.fillRect(this.x-6,this.y,6,this.height); + this.readEnable.draw(); + this.writeEnable.draw(); + } + } +} +var actualflags=0; +function pointInCircle(x, y, cx, cy, radius) { + var distancesquared = (x - cx) * (x - cx) + (y - cy) * (y - cy); + return distancesquared <= radius * radius; +} +class Pin { + constructor(x,y,radius=6,label=false,direction="down"){ + this.x=x; + this.y=y; + this.radius=radius; + this.state=0; + this.label=label; + this.direction=direction; + } + read(){ + return this.state; + } + write(state){ + this.state=state==true?1:0; + } + checkMouse(pos){ + return pointInCircle(pos.x,pos.y,this.x,this.y,this.radius); + } + draw(){ + ctx.fillStyle=this.read()==1?"red":"lightgray"; + ctx.beginPath(); + if(this.direction=="down"){ + ctx.arc(this.x,this.y,this.radius, 0*Math.PI,1*Math.PI,false); + } else if(this.direction=="right"){ + ctx.arc(this.x,this.y,this.radius,1.5*Math.PI,0.5*Math.PI,false); + } else if(this.direction=="left") { + ctx.arc(this.x,this.y,this.radius,0.5*Math.PI,1.5*Math.PI,false); + } else if (this.direction=="up") { + ctx.arc(this.x,this.y,this.radius, -1*Math.PI,0*Math.PI,false); + + } + ctx.fill(); + } +} + +class Wire { + update(){ + var state=!!this.input.read(); + if(this.killme>-1){ + if(registers[4].readEnable.read()){ + state = parseInt(registers[4].binary[7-this.killme]); + this.input.write(state); + } + } + this.state=state; + var hovered = this.input.hovered =1 || this.output.hovered == 1; + if(!this.behind) + this.color=state?"#F00":"#AAA"; + else if(this.behind==1) + this.color=state?"#A00":"#777"; + else + this.color=state?"#800":"#555"; + this.output.write(state); + } + draw(){ + ctx.beginPath(); + ctx.moveTo(this.input.x,this.input.y); + var n = this.output.number; + n = n - this.reindex; + var fuckyou = (this.output.number==0 && this.input.direction=="down")?2:0; + if (this.fuckoffanddie){ + ctx.lineTo(435,this.input.y); + ctx.lineTo(435,650); + ctx.lineTo(760,650); + ctx.lineTo(760,570); + ctx.lineTo(this.output.x,570); + } else { + if(!this.horizontal){ + if(!this.reverse){ + ctx.lineTo(this.input.x,this.input.y+fuckyou+Math.max((this.output.y-this.input.y)*0.45+n*7,0)); + ctx.lineTo(this.output.x,this.input.y+fuckyou+Math.max((this.output.y-this.input.y)*0.45+n*7,0.0)); + } else { + /* + ctx.lineTo(this.input.x,this.input.y-15+((this.output.y-this.input.y)*(1-(0.15*n)))); + ctx.lineTo(this.output.x,this.input.y-15+((this.output.y-this.input.y)*(1-(0.15*n)))); + */ + ctx.lineTo(this.input.x,this.input.y+fuckyou+Math.max((this.output.y-this.input.y)*0.56-n*6,0)); + ctx.lineTo(this.output.x,this.input.y+fuckyou+Math.max((this.output.y-this.input.y)*0.56-n*6,0.0)); + } + } else { + if(!this.reverse){ + //ctx.lineTo(this.input.x+fuckyou+Math.max((this.output.x-this.input.x)*0.45+n*7,0),this.input.y); + //ctx.lineTo(this.input.x+fuckyou+Math.max((this.output.x-this.input.x)*0.45+n*7,0.0),this.output.y); + if(!this.zigzag){ + ctx.lineTo(this.input.x-this.flip*(Math.abs(this.output.x-this.input.x)*0.45+n*7),this.input.y); + ctx.lineTo(this.input.x-this.flip*(Math.abs(this.output.x-this.input.x)*0.45+n*7),this.output.y); + } else{ + if(this.kms) + ctx.lineTo(this.input.x,this.output.y) + else + ctx.lineTo(this.output.x,this.input.y) + } + } else { + if(!this.zigzag){ + ctx.lineTo(this.input.x-this.flip*(Math.abs(this.output.x-this.input.x)*0.45-n*7),this.input.y); + ctx.lineTo(this.input.x-this.flip*(Math.abs(this.output.x-this.input.x)*0.45-n*7),this.output.y); + } else{ + ctx.lineTo(this.input.x,this.output.y) + } + /* + ctx.lineTo(this.input.x,this.input.y-15+((this.output.y-this.input.y)*(1-(0.15*n)))); + ctx.lineTo(this.output.x,this.input.y-15+((this.output.y-this.input.y)*(1-(0.15*n)))); + */ + + } + + }} + ctx.lineTo(this.output.x, this.output.y); + var redcolor,graycolor; + if(this.behind==0){ + redcolor="#F0F" + graycolor="#99F" + } else if(this.behind==1) { + redcolor="#A0A" + graycolor="#55F" + } else { + redcolor = "#808" + graycolor="#22F" + } + ctx.strokeStyle=this.hovered?(this.state?redcolor:graycolor):this.color + // cursed ctx.strokeStyle=this.color.substr(0,3)+(this.hovered?"F"/*(Math.min(parseInt(this.color[1],16)+3,15)).toString(16)*/:this.color[3]); + ctx.lineWidth=this.hovered?6:4; + ctx.stroke(); + } + constructor(input, output, label,behind=false, reverse=false,reindex=0,horizontal=false,flip=false,zigzag=false,kms=false,fuckoffanddie=false,killme=-1 ){ + this.input=input; + this.fuckoffanddie=fuckoffanddie; + this.output=output; + this.label=label; + this.reverse=reverse; + this.reindex=reindex; + this.behind=behind; + this.horizontal=horizontal; + this.flip=flip?-1:1; + this.zigzag=zigzag; + this.kms=kms; + this.killme=killme; + } +} +class Tooltip { + constructor(x,y,message,persist=false){ + this.x=x; + this.y=y; + this.message=message; + this.persist=persist; + } + draw(offset){ + ctx.fillStyle="rgba(0,0,0,0.65)"; + ctx.font="20px vcr_osd_monoregular"; + ctx.textBaseline="bottom"; + ctx.textAlign="left"; + var width=ctx.measureText(this.message).width+6; + ctx.fillRect(this.x<720?this.x:this.x-width,this.y-25-(26*offset),width,25); + ctx.fillStyle="white"; + ctx.fillText(this.message,this.x<720?(this.x+3):(this.x-width+3),this.y-(26*offset)); + } +} +function wireUp(){ + // clock + wires.push(new Wire(blocks[4].pins.clk[0],blocks[3].pins.clock[0],"clock")); + // instruction to decoder + //decoder to ALU + for(var i=0;i<5;i++){ + wires.push(new Wire(registers[0].pins[i],blocks[0].pins["instruction"][i],i<4?("opcode bit "+(3-i)):"addressing mode",false,false,2)); + if(i<4) + wires.push(new Wire(blocks[0].pins.toALU[i],blocks[2].points[i],i<4?"ALU opcode bit ":"set flags?")); + } + for(var i=0;i<8;i++){ + ///m data reg to mux + wires.push(new Wire(blocks[5].pins.channel1[7-i],registers[4].pins[7-i],"MDR (mux ch. 1), bit "+i,false,true,3,false,false,false,false,false,i)); + //wires.push(new Wire(blocks[5].pins.channel1[7-i],registers[4].pins[7-i],"memory data register, bit "+(7-i),false,true,5,false,false,false)); + + } + // ALU to flags + var flagtext=["overflow flag","negative flag","carry flag","zero flag"] + for(var i=0;i<4;i++){ + wires.push(new Wire(blocks[2].pins.flags[i],registers[1].pins[i+1],flagtext[i],false,true,2)); + } + //// INPUT OUTPUT STOPS BEHIND REVERSE REINDEX HORIZONTAL FLIP + // decoder to mux control + wires.push(new Wire(blocks[0].pins.toMux[0],blocks[1].pins.selector[0],"mux 0 selector")); + // instruction to multiplexer + for(var i=0;i<8;i++){ + // reg to mux and alu + wires.push(new Wire(blocks[3].pins.data1[i],blocks[2].pins.operand1[i],"first register data (operand 0), bit "+i,false,true,30,true)); + wires.push(new Wire(blocks[3].pins.data2[i],blocks[1].pins.channel0[i],"second register data (mux ch. 0), bit "+i,false,false,0,true)); + //mux to alu + wires.push(new Wire(blocks[1].pins.output[i],blocks[2].pins.operand2[7-i],/*"mux output, bit "+i*/"mux output (operand 1), bit "+[7-i],false,true,0,true,true,true)); + //alu to writeback + //wires.push(new Wire(blocks[2].pins.result[i],blocks[3].pins.writeback[i],"ALU result, bit "+i,false,false,-29,true,true)); + + wires.push(new Wire(blocks[5].pins.output[i],blocks[3].pins.writeback[i],"mux output (reg writeback), bit "+i,false,false,-29,true,true)); + wires.push(new Wire(blocks[2].pins.result[i],blocks[5].pins.channel0[i],"mux ch. 0 (ALU result), bit "+i,false,false,-29,true,true)); + + //alu to mar + wires.unshift(new Wire(blocks[2].pins.result[i],registers[2].pins[7-i],"MAR (ALU result), bit "+i,true,false,0,true,true,true)); + wires.unshift(new Wire(blocks[2].pins.result[i],registers[4].pins[7-i],"MDR (ALU result), bit "+i,true,false,0,true,true,true)); + + wires.unshift(new Wire(blocks[2].pins.result[i],registers[3].pins[7-i],"PC (ALU result), bit "+i,3,false,0,true,true,true)); + //inst to mux + wires.push(new Wire(registers[0].pins[15-i],blocks[1].pins.channel1[7-i],"immediate data (mux ch. 1), bit "+i,false,(7-i)<3,(7-i)<3?-2:8)); + } + // decoder to mux2 + wires.unshift(new Wire(blocks[0].pins.toMux[1],blocks[5].pins.selector[0],"mux 1 selector",true,false,0,false,false,true,true,true)); + + // decoder to reg rwenable + wires.unshift(new Wire(blocks[0].pins.registerReadEnable[0],blocks[3].pins.read1Enable[0],"first register read enable",true,false,-34,true,true)); + wires.unshift(new Wire(blocks[0].pins.registerWriteEnable[0],blocks[3].pins.write1Enable[0],"first register write enable",true,false,-35,true,true)); + // decoder to mar rwenable + wires.unshift(new Wire(blocks[0].pins.memAddrReadEnable[0],registers[2].readEnable,"MAR read enable",3, false,0,true,true,true,true)); + wires.unshift(new Wire(blocks[0].pins.memAddrWriteEnable[0],registers[2].writeEnable,"MAR write enable",3, false,0,true,true,true,true)); + //pc rwenable + wires.unshift(new Wire(blocks[0].pins.pcReadEnable[0],registers[3].readEnable,"PC read enable",3, false,0,true,true,true,true)); + wires.unshift(new Wire(blocks[0].pins.pcWriteEnable[0],registers[3].writeEnable,"PC write enable",3, false,0,true,true,true,true)); + // m d r rwenable + wires.unshift(new Wire(blocks[0].pins.memDataReadEnable[0],registers[4].readEnable,"MDR read enable",3, false,0,true,true,true,true)); + wires.unshift(new Wire(blocks[0].pins.memDataWriteEnable[0],registers[4].writeEnable,"MDR write enable",3, false,0,true,true,true,true)); + // instruction to register address + for(var i=0;i<3;i++){ + wires.unshift(new Wire(registers[0].pins[7-i],blocks[3].pins.address1[i],"first register address, bit "+i,3,false,3,true,true,true,true)); + wires.unshift(new Wire(registers[0].pins[10-i],blocks[3].pins.address2[i],"second register address, bit "+i,3,false,3,true,true,true,true)); + } + +} +url=""; +function setup(){ + images["pencil"]=new Image(); + images["pencil"].src='img/pencil.png'; + images["question"]=new Image(); + images["question"].src='img/question.png'; + + ctx.canvas.width = 1440//window.innerWidth*0.75; + ctx.canvas.height = 976 //window.innerHeight; + registers.push(new Register("instruction register",16, 0, w(13), h(36), 60,"above",true,"white","below",16)); + registers.push(new Register("flags",5,0,w(13),h(885),45,"below",false,"white","above")); + registers.push(new Register("memory address register", 16, 0, w(250), h(885), 45, "below",true,"white","above")) + registers.push(new Register("program counter", 16, 0, w(880), h(885), 45, "below",true,"white","above")) + registers.push(new Register("m. data reg.",8,0,880+(registers[registers.length-1].width/2),803,45,"below",true,"white","above")); + + //goddammit + for(var i=2;i{ + var rect = canvas.getBoundingClientRect(); + tooltips = tooltips.filter(t=>t.persist==true); + scaleX=canvas.width/rect.width; + scaleY=canvas.height/rect.height; + isOverOne=false; + this.wires.forEach(wire=>{ + wire.hovered=false; + var pos = {x:(e.clientX-rect.left)*scaleX, y:(e.clientY-rect.top)*scaleY}; + if(wire.input.checkMouse(pos)||wire.output.checkMouse(pos)){ + wire.hovered=true; + tooltips.push(new Tooltip(pos.x,pos.y,wire.label)); + isOverOne=2; + } + }); + blocks.forEach(block=>{ if(block.checkMouse({x:(e.clientX-rect.left)*scaleX, y:(e.clientY-rect.top)*scaleY})){isOverOne=true;url=block.url;} }); + if(isOverOne==1){ + canvas.style.cursor="pointer"; + } else if(isOverOne==2){ + canvas.style.cursor="help"; + } else { + canvas.style.cursor="default"; + url=""; + } + }); + document.addEventListener('click',e=>{ + if(url){ + window.location.href=url; + console.log("no"); + } else { + console.log("no"); + } + }); + requestAnimationFrame(drawCanvas); +} +var wait=false; +function clockTick(t=1000,oneTime=false){ + blocks[4].pulse(1000,wait); + if(wait){ + registers[2].update(); + registers[4].update(); + wait=false; + } else { + if(blocks[2].correctAnswer>-1){ + if(blocks[2].correctAnswer!=blocks[2].values[2].value){ + tick=false; + blocks[2].done = false; + blocks[2].editable = true; + blocks[2].wrong = true; + return; + } + } + if(!tick && !oneTime) return; + registers.forEach(r=>r.update(true)); + actualflags=getNumber(blocks[2].pins.flags); + if(blocks[4].cycles>1) + blocks[3].realUpdate(); + drawMemory(); + nextInstruction(); + } + if(tick){ + setTimeout(clockTick,t,t); + } +} +var tick=false; +const zeroPad = (num, places) => String(num).padStart(places, '0') +var memPage=0; +function nextMemPage(){ + memPage++; + if(memPage>255) memPage=0; + document.getElementById('label_mempage').innerHTML=zeroPad(memPage,3); + drawMemory(); +} +function prevMemPage(){ + memPage--; + if(memPage<0) memPage=255; + document.getElementById('label_mempage').innerHTML=zeroPad(memPage,3); + drawMemory(); +} +function drawMemory(){ + var memTable = document.getElementById('memory').children[0]; + for(var i=1;i<=16;i++){ + var row = memTable.children[i]; + for(var j=1;j<=16;j++){ + var cell = row.children[j]; + var address = ((memPage)<<8)+(i-1)*16+(j-1); + var val = memory[address]; + cell.innerHTML = zeroPad(val,3); + if(val>0) cell.classList.add('nonzero'); else cell.classList.remove('nonzero'); + } + } +} +initialRun=false; +function compile(){ + resetAll(); + try { + ass = new assembler(); + var bytecode = ass.assemble(document.getElementById('program').value); + console.log(ass.labelAddresses); + for(var i=0;ir.update()); +} +var branchyes = false; +var prevInstruction=-1; +function nextInstruction(){ + var pc = registers[3]; + if(!nosetpc){ + if(prevInstruction!=-1) { + pc.set(pc.value+2,false); + } + } else nosetpc=false; + var flag_reg = registers[1]; + var ir = registers[0]; + var mar = registers[2]; + var mdr = registers[4]; + ir.set((memory[pc.value]<<8)+memory[pc.value+1]); + var instruction = ir.value; + var opcode = instruction >> 12; + if(opcode==15){ + tick=false; + runLabel.innerHTML='Run (finished)'; + } + if(opcode==0b1011) return; + prevInstruction=instruction; + // glue code + wait=opcode==0b1001; + var mode = (instruction>>11)&0b00001; + var f = (registers[0].value >> 8)&0b00000111; + //input + var r2 = (instruction & 0x00FF)>>5; + if((opcode!=11 && opcode<=12)&&r2==0&&mode==0){ + var inp = document.getElementById('input'); + if(inp.value.length>0){ + var setTo; + if(document.getElementById('ascii').checked){ + setTo = inp.value[0]; + setTo = setTo.charCodeAt(0); + inp.value = inp.value.substr(1); + } else { + setTo = parseInt(inp.value.split(" ")[0]); + if(inp.value.indexOf(" ")==-1) inp.value=""; else + inp.value = inp.value.substring(inp.value.indexOf(" ")+1); + } + blocks[3].fileRegisters[7].set(setTo,false); + flag_reg.set(flag_reg.value+(1<<4)); + } else { + blocks[3].fileRegisters[7].set(0,false); + } + } + // memory stores + if(opcode==10){ + registers[4].set(blocks[3].fileRegisters[7-f].value); + } + // conditional branching + if(opcode==12||opcode==13){ + if((actualflags+(registers[1].binary[0]=='1'?16:0)) & (1 << f)){ + branchyes=(opcode==12); + nosetpc=(opcode==12); + } else { + branchyes=(opcode==13); + nosetpc=(opcode==13); + } + } + var mode = (ir.value & 0b0000100000000000)>>11; + if(opcode==0b1110) { //jmp: don't increment pc + nosetpc=true; + } + /* + if(opcode==1111 && mode==0){ // setipg + ir.set((171<<8)+((pc.value+4)>>8)); + } + */ + +} +var nosetpc=false; +function resetAll(){ + initialRun=true; + prevInstruction=-1; + branchyes=false; + nosetpc=false; + document.getElementById("output").value=""; + outputBuf = []; + memory = new Array(65536).fill(0); + blocks.forEach(b=>b.reset()); + registers.forEach(r=>r.set(0,false)); + blocks[3].fileRegisters.forEach(r=>r.set(0,false)); +} +function drawCanvas(){ + ctx.clearRect(0, 0, canvas.width, canvas.height); + if(window.debugall) {;} else { + wires.forEach(w=>w.update()); + blocks.forEach(b=>b.update()); + for(var i=0;i<8;i++){ + registers[4].pins[i].write(registers[4].binary[i]); + } + } + wires.forEach(w=>w.draw()); + blocks.forEach(b=>b.draw()); + registers.forEach(r=>r.draw(1)); + blocks.forEach(b=>b.drawOverlay()); + const flags = new Set(); + tooltips.filter(tt=>{if(flags.has(tt.message)){return false};flags.add(tt.message);return true;}).forEach((t,i)=>t.draw(i)); + requestAnimationFrame(drawCanvas); + +}; +function displayOutput(){ + outputBox = document.getElementById("output"); + outputBox.value = "" + outputBuf.forEach(value=>{ + if(document.getElementById('ascii').checked) + outputBox.value += String.fromCharCode(value); + else + document.getElementById("output").value += value + " "; + }) + +} \ No newline at end of file diff --git a/js/index_mod.js b/js/index_mod.js new file mode 100644 index 0000000..890083f --- /dev/null +++ b/js/index_mod.js @@ -0,0 +1,1129 @@ +var registers=[]; +var blocks=[]; +var wires=[]; +var tooltips=[]; +var embedded = {}; +var images={}; +const BORDER_THICKNESS=5.5; +var canvas, ctx; +var outputBuf = [] +var clockTimer; +var opcodes = ['add','sub','adc','subb','nand','xor','sll','srl','mov','ldb','stb', 'nop','bflag','bnoflag', 'jmp', 'hlt']; +var rs = ['io','stackptr','datapg','instpg','gp0','gp1','gp2','gp3']; +var flags = ['zero','carry','negative','overflow','input']; +var memory=new Array(65536).fill(0); +var memPage = 0; +var dataPage = 0; +function getNumber(pins,reverse=true){ + var val = 0; + for(var i=0;i>12; + var addressMode = (machineCode & 0b0000100000000000) >>11; + var r1 = (machineCode & 0b0000011100000000)>>8; + var r2 = (machineCode & 0b0000000011100000)>>5; + var imm8 = machineCode & 0b0000000011111111; + if(opcode==15){ + return(opcodes[opcode]); + } else if(opcode<11) { + return(`${opcodes[opcode]} ${specific?rs[r1]:'reg'}, ${specific?((addressMode?imm8:rs[r2])):addressMode?'imm8':'reg'}`); + } else if (opcode==11){ + return(`${opcodes[opcode]}`); + } else if(opcode==12) { + return(`${opcodes[opcode]} ${specific?flags[r1 & 0b00000111]:'flag'}, ${specific?((addressMode?imm8:rs[r2])):addressMode?'imm8':'reg'}`); + } else { + return(`${opcodes[opcode]} ${specific?((addressMode?imm8:rs[r2])):(addressMode?'imm8':'reg')}`); + } + +} +document.addEventListener("DOMContentLoaded", function(event){ + event; + canvas = document.getElementById("sim"); + ctx = canvas.getContext('2d'); + setup(); + setTimeout(function(){ + embedded['alu'] = document.getElementById('ALUframe').contentWindow.chip; + embedded['mux1'] = document.getElementById('MUX1frame').contentWindow.chip; + embedded['mux2'] = document.getElementById('MUX2frame').contentWindow.chip; + },2000); +}); +function w(width){ + return ((width*canvas.width)/1440); +} +function h(height){ + return ((height*canvas.height)/976); +} +function drawBorder(thing,thickness,color="black"){ + ctx.fillStyle=color; + ctx.fillRect(thing.x-thickness,thing.y-thickness,thing.width+thickness*2,thing.height+thickness*2); +} + +class Block { + constructor(name, x, y, width, height,points=[],editable=true){ + this.name=name; + this.url=""; + this.x=w(x); + this.y=h(y); + this.width=w(width); + this.height=h(height); + this.editable=editable; + this.points=points; + if(this.editable) + this.done=false; + else + this.done=true; + } + update(){ + } + reset(){ + } + makePointArray(){ + this.points=[] + for(const[key,value] of Object.entries(this.pins)){ + key; + //this.points=this.points.concat(value); + value.forEach((pin,i)=>{ pin.number=i; this.points.push(pin) }); + } + + } + drawOverlay(){ + if(!(this.done||this.attempted)){ + ctx.fillStyle="rgba(255,255,255,0.6)"; + ctx.fillRect(this.x,this.y+BORDER_THICKNESS+35,this.width,this.height-BORDER_THICKNESS-35); + ctx.fillStyle="#FFA500" + if(this.wrong) + ctx.fillStyle="#dd3333"; + ctx.fillRect(this.x+this.width/2-35,this.y+this.height/2-35+17,70,70); + ctx.drawImage(images[this.editable?'pencil':'question'],this.x+this.width/2-30,this.y+this.height/2-30+17,60,60); + } else + if(this.editable) + ctx.drawImage(images[this.editable?'pencil':'question'],this.x+this.width-w(37),this.y+this.height-h(30)-h(3),w(30),h(30)); + } + draw(color='white',textcolor='white'){ + ctx.fillStyle=color; + ctx.fillRect(this.x, this.y, this.width, this.height); + ctx.fillStyle="#444"; + ctx.fillRect(this.x,this.y,this.width,BORDER_THICKNESS); + ctx.fillRect(this.x-BORDER_THICKNESS,this.y,BORDER_THICKNESS,this.height+BORDER_THICKNESS); + ctx.fillRect(this.x+this.width,this.y,BORDER_THICKNESS,this.height+BORDER_THICKNESS); + ctx.fillRect(this.x,this.y+this.height,this.width,BORDER_THICKNESS); + if(this.done) + ctx.fillStyle="#43c143"; + else if(!this.attempted) + ctx.fillStyle="#ffa500"; + else + ctx.fillStyle="#dd3333"; + if(this.wrong){ + ctx.fillStyle="#dd3333"; + } + ctx.fillRect(this.x,this.y+BORDER_THICKNESS,this.width,35); + ctx.fillStyle=textcolor; + ctx.font=170*0.15+"px vcr_osd_monoregular"; + ctx.textBaseline = "top"; + ctx.textAlign='left'; + ctx.fillText(this.name,this.x+w(7), this.y+h(13)); + + + this.points.forEach(p=>p.draw()); + } + checkMouse(pos){ + // check if mouse is over icon + if(!this.attempted&&this.editable){ + return pos.x>=this.x+this.width/2-35 && pos.y>=this.y+this.height/2-35 && pos.x<=this.x+this.width/2-35+70 && pos.y<=this.y+this.height/2-35+70; + } else + return pos.x>=this.x+this.width-w(37) && pos.x<=this.x+this.width-w(7) && pos.y>=this.y+this.height-h(33) && pos.y<=this.y+this.height-h(3) && JSON.stringify(Array.from(ctx.getImageData(pos.x,pos.y,1,1).data.slice(0,3)))!="[255,255,255]"; + } +} +class Decoder extends Block { + update(){ + this.setInstruction(humanInstruction(registers[0].value,false),(registers[0].value>>12)); + for(var i=0;i<16;i++){ + if(i<4){ + this.pins.toALU[i].write(this.pins.instruction[i].read()); + } + } + // read from first register only if it's an ALU operation + // write to the first register unless we're in a store or branch instruction + this.pins.registerReadEnable[0].write(this.opcode<8); + this.pins.registerWriteEnable[0].write(this.opcode<10); + // imm8 + this.pins.toMux[0].write(this.pins.instruction[4].read() && this.opcode!=11 &&this.opcode!=15);//(this.mode==1 && this.opcode!=11 && this.opcode!=15)); + + // mem load + this.pins.toMux[1].write(this.opcode==9); + this.pins.memDataReadEnable[0].write(this.opcode==9); + this.pins.memDataWriteEnable[0].write(this.opcode==10); + // + this.pins.memAddrWriteEnable[0].write(this.opcode==9||this.opcode==10); + // jumps + if(this.opcode==14) + this.pins.pcWriteEnable[0].write(1); + else if(this.opcode!=12&&this.opcode!=13) + this.pins.pcWriteEnable[0].write(0); + else + this.pins.pcWriteEnable[0].write(branchyes?1:0); + } + setInstruction(instruction,opcode,mode){ + this.instruction = instruction; + this.opcode=opcode; + this.mode=mode; + } + constructor(x,y,width,height,points=[],editable=true){ + super("decoder",x,y,width,height,points,editable); + this.mode=0; + this.pins = { + instruction: [ + ], + toALU: [ + + ], + toMux: [ + new Pin(this.x+this.width,this.y+this.height-50,6,false,"right"), + new Pin(this.x+this.width,this.y+this.height-50+17,6,false,"right") + ], + registerWriteEnable: [ + new Pin(this.x+this.width,this.y+this.height-140,6,false,"right") + ], + registerReadEnable: [ + new Pin(this.x+this.width,this.y+this.height-157,6,false,"right") + ], + memAddrWriteEnable: [ + new Pin(this.x+190,this.y+this.height), + ], + memAddrReadEnable: [ + new Pin(this.x+207,this.y+this.height) + ], + pcWriteEnable: [ + new Pin(this.x+227+17,this.y+this.height) + ], + pcReadEnable: [ + new Pin(this.x+227+34,this.y+this.height) + ], + memDataWriteEnable:[ + new Pin(this.x+282+17,this.y+this.height) + ], + memDataReadEnable:[ + new Pin(this.x+282+34,this.y+this.height) + ], + + + + + } + for(var i=0;i<5;i++){ + this.pins.instruction.push(new Pin(this.x+17+17*i, this.y)); + if(i<4) + this.pins.toALU.push(new Pin((this.x+17+17*i+(i<4?0:34)), this.y+this.height)); + } + this.makePointArray(); + this.instruction="add reg,reg"; + this.opcode=0; + } + draw(){ + super.draw(); + ctx.fillStyle="black"; + ctx.font=250*0.07+"px vcr_osd_monoregular"; + ctx.textBaseline = "top"; + ctx.textAlign='center'; + ctx.fillText("opcode: "+Register.getBits(this.opcode,4)+" / "+Register.getHex(this.opcode,1)+"",this.x+this.width/2-w(4), this.y+h(55)); + var am=this.pins["instruction"][4].read(); + this.mode=am; + ctx.fillText("mode: "+(am?1:0)+" / "+(this.opcode==15?'special':(((am==0||this.opcode==11)?"register":"immediate"))),this.x+this.width/2-w(4), this.y+h(75)); + + ctx.font=240*0.15+"px vcr_osd_monoregular"; + ctx.fillText(this.instruction,this.x+this.width/2-w(4), this.y+h(100)); + } + + +} +class Mux extends Block { + setChannel(c){ + this.channel=c; + } + update(){ + if(this.second){ + if(!embedded.mux2 || !embedded.mux2.pins) return; + embedded.mux2.pins[16] = this.pins.selector[0].read(); + for(var i=0;i<8;i++){ + embedded.mux2.pins[i] = this.pins.channel0[i].read(); + embedded.mux2.pins[8+i] = this.pins.channel1[7-i].read(); + this.pins.output[7-i].write(embedded.mux2.pins[24-i]); + + }}else{ + if(!embedded.mux1 || !embedded.mux1.pins) return; + embedded.mux1.pins[16] = this.pins.selector[0].read(false); + for(var i=0;i<8;i++){ + embedded.mux1.pins[i] = this.pins.channel0[7-i].read(); + embedded.mux1.pins[8+i] = this.pins.channel1[i].read(); + this.pins.output[7-i].write(embedded.mux1.pins[24-i]); + + }} + + + + this.setChannel(this.pins.selector[0].read()==true?1:0); + } + constructor(x,y,width,height,second=false,de=false,points=[],editable=true){ + super((de?"de":"")+"multiplexer",x,y,width,height,points,editable); + this.de=de; + this.second=second; + this.channel=0; + if(second) + var theselector=new Pin(this.x+this.width-17, this.y); + else + var theselector=new Pin(this.x-BORDER_THICKNESS,blocks[0].pins.toMux[0].y,6,"","right") + if(!this.de){ + this.pins={ + selector: [ + theselector + ], + channel0:[ + ], + channel1: [ + ], + output:[ + ] + } + for(var i=0;i<8;i++){ + if(second){ + this.pins.channel1.push(new Pin(this.x+62+17*i,this.y+BORDER_THICKNESS+this.height,6,"","up")); + this.pins.output.push(new Pin(this.x+this.width,this.y+17+17*i,6,"","right")); + this.pins.channel0.push(new Pin(this.x-BORDER_THICKNESS,this.y+17+17*i,6,"","right")); + } else { + this.pins.channel1.push(new Pin(this.x+17+17*i,this.y)); + this.pins.channel0.push(new Pin(this.x+BORDER_THICKNESS+this.width,this.y+17+17*i,6,"","left")); + this.pins.output.push(new Pin(this.x+17+17*i,this.y+this.height)); + } + } + } else { + this.pins={ + selector: [ + new Pin(this.x-BORDER_THICKNESS,this.y+15,6,"","right"), + new Pin(this.x-BORDER_THICKNESS,this.y+30,6,"","right") + ], + input:[ + ], + channel0:[ + ], + channel1:[ + ], + channel2:[ + ] + } + for(var i=0;i<8;i++){ + this.pins.input.push(new Pin(this.x-BORDER_THICKNESS,this.y+67+17*i,6,"","right")); + this.pins.channel0.push(new Pin(this.x+this.width,this.y+17+17*i,6,"","right")); + this.pins.channel1.push(new Pin(this.x+17+17*i,this.y+this.height)); + this.pins.channel2.push(new Pin(this.x+220+17*i,this.y+this.height)); + } + } + this.makePointArray(); + } + draw(){ + super.draw(); + ctx.fillStyle="black"; + ctx.font="25px vcr_osd_monoregular"; + ctx.baseline="middle"; + ctx.textAlign="center"; + ctx.fillText(" channel: "+this.channel,this.x+this.width/2,this.y+this.height/2); + } +} +class ALU extends Block { + update(){ + if(!embedded.alu) return; + for(var i=0;i<8;i++){ + if(i<4){ + embedded.alu.pins[19-i] = this.pins.opcode[i].read(); + this.pins.flags[i].write(embedded.alu.pins[29+i]); + } + embedded.alu.pins[i] = this.pins.operand1[i].read(); + embedded.alu.pins[i+8] = this.pins.operand2[i].read(); + this.pins.result[i].write(embedded.alu.pins[21+i]); + } + this.values[3].set(getNumber(this.pins.flags)); + this.values[1].set(getNumber(this.pins.operand1,false)); + this.values[0].set(getNumber(this.pins.operand2,false)); + this.values[2].set(getNumber(this.pins.result,false)); + var opcode=getNumber(this.pins.opcode); + if(opcode==6){ + this.correctAnswer = this.values[1].value << this.values[0].value; + } else { + this.correctAnswer = -1; + } + if(opcode>=8){ + this.operation = "move"; + } else { + this.operation = opcodes[opcode]; + } + + } + constructor(x,y,width,height,points=[],editable=true){ + points; + super("ALU",x,y,width,height,wires,editable); + this.wrong=false; + this.operation="add"; + this.values=[new Register("operand 1",8,0,this.x+w(20),this.y+h(80),50,"above",true,"black"), + new Register("operand 0",8,0,this.x+w(20),this.y+h(175),50,"above",true,"black"), + new Register("result",8,0,this.x+w(20),this.y+h(340),50,"above",true,"black"), + new Register("O N C Z flags",4,1,this.x+w(20),this.y+h(410),32,"above",false,"black")]; + //new Register("O . N . C . Z",4,0,this.x+w(125),this.y+h(360),30,"above",false,"black")]; + this.pins={ opcode: []/*,setFlags:[]*/, operand1:[], operand2:[],flags:[],result:[] } + for(var i=0;i<4;i++){ + this.pins.opcode.push(new Pin(this.x+17+17*i,this.y)); + this.pins.flags.push(new Pin(this.x+17+17*i,this.y+this.height)); + } + this.pins.flags[3].write(1); + for(var i=0;i<8;i++){ + this.pins.operand2.push(new Pin(this.x+this.width+BORDER_THICKNESS, this.y+17+17*i,6,"","left")); + this.pins.operand1.push(new Pin(this.x+this.width+BORDER_THICKNESS, this.y+167+17*i,6,"","left")); + this.pins.result.push(new Pin(this.x+this.width, this.y+317+17*i,6,"","right")); + } + + //this.pins.setFlags.push(new Pin(this.x+17*5+34,this.y)); + //this.pins.setFlags[0].write(1); + + this.makePointArray(); + + } + draw(){ + super.draw(); + ctx.fillStyle="black"; + ctx.textAlign="center"; + ctx.textBaseline="middle"; + ctx.font="25px vcr_osd_monoregular"; + ctx.fillText("operation: "+this.operation,this.x+this.width/2, this.y+260); + ctx.font="15px vcr_osd_monoregular"; + //ctx.fillText("set flags: "+(this.pins.setFlags[0].read()==1?"yes":"no"),this.x+this.width/2, this.y+280); + ctx.fillRect(this.x+20,this.y+300,this.width-40,2); + this.values.forEach(v=>v.draw(0)); + } +} +class RegisterFile extends Block { + fileRegisters = []; + selected(){ + return{r1:this.fileRegisters[7-getNumber(this.pins.address1,false)], r2:this.fileRegisters[7-getNumber(this.pins.address2,false)]}; + } + update(){ + for(var i=0;i<8;i++){ + if(this.pins.read1Enable[0].read()) + this.pins.data1[7-i].write(this.selected().r1.binary[i]); + this.pins.data2[7-i].write(this.selected().r2.binary[i]); + } + } + realUpdate(){ + if(!!this.pins.write1Enable[0].read()) { + this.selected().r1.set(getNumber(this.pins.writeback,false),true); + } + } + constructor(x,y,fileRegisters=[],pins=[],editable=true){ + pins,editable; + super("registers",x,y,0,fileRegisters.length*h(85)+h(45),wires,false); + fileRegisters.forEach((r,i)=>{ + if(!r.bits){ + r.bits=8 + } + this.fileRegisters.push(new Register(r.name,r.bits,0,x+w(20),y+i*h(85)+h(65),40,"above",true,"black")); + }); + this.width=this.fileRegisters[0].width+w(80); + this.pins={ + clock:[ new Pin(this.x-BORDER_THICKNESS,this.y+17,6,"","right") ], + read1Enable: [ new Pin(this.x-BORDER_THICKNESS,this.y+17+35,6,"","right") ], + write1Enable: [new Pin(this.x-BORDER_THICKNESS,this.y+34+35,6,"","right") ], + address1: [ ], + address2: [ ], + data2:[ ], + data1:[ ], + writeback:[] + }; + for(var i=0;i<3;i++){ + this.pins.address2.push(new Pin(this.x-BORDER_THICKNESS,this.y+55+35+17+17*i,6,"","right")); + this.pins.address1.push(new Pin(this.x-BORDER_THICKNESS,this.y+125+35+17+17*i,6,"","right")); + } + for(var i=0;i<8;i++){ + this.pins.data2.push(new Pin(this.x,this.y+205+35+17+17*i,6,"","left")); + this.pins.data1.push(new Pin(this.x,this.y+365+35+17+17*i,6,"","left")); + this.pins.writeback.push(new Pin(this.x-BORDER_THICKNESS,this.y+530+35+17+17*i,6,"","right")); + } + super.makePointArray(); + } + draw(){ + super.draw(); + this.fileRegisters.forEach(r=>r.draw(1)); + } +} +class Clock extends Block { + reset(){ + this.state=0; + this.cycles=0; + } + update(){ + this.pins.clk[0].write(this.state); + } + constructor(x,y,width,height){ + super("clock",x,y,width,height,[],false); + this.pins={clk:[new Pin(this.x+this.width,this.y+17,6,"","right")]}; + super.makePointArray(); + this.cycles=0; + this.state=0; + } + pulse(t,w=false){ + this.state = 1; + if(!w) + this.cycles+=1; + setTimeout(function(){this.state=0}.bind(this),t/10); + } + draw(){ + super.draw(); + ctx.fillStyle="black"; + ctx.textAlign="center"; + ctx.textBaseline="middle"; + ctx.fillText(this.cycles,this.x+this.width/2,this.y+this.height/2+20); + } +} + +class Register { + pins=[]; + update(fuck=false){ + /*if(this.name=="memory address register" && fuck) return; + if(this.name=="m. data reg." && fuck) return;*/ + if(this.name=="flags"){ + this.set(getNumber(this.pins)); + if(document.getElementById("input").value.length>0) + this.value=this.value|0b10000; + else { + this.value=this.value & 0b01111; + } + this.set(this.value); + } + else if('writeEnable' in this) { + if(!!this.writeEnable.read()){ + this.set(getNumber(this.pins)); + } + } + if(this.name=="m. data reg."){ + var mAddr = registers[2].value; + if(this.writeEnable.read()){ + memory[mAddr] = this.value; + } + if(this.readEnable.read()||initialRun){ + initialRun=false; + this.set(memory[mAddr]); + } + } + } + static getBits(n,digits=8){ + if(n<0||n>=Math.pow(2,digits)||n%1!==0) { + //console.error(n+" is fucked, yo"); + } + return ("0000000000000000"+n.toString(2)).substr(-digits); + } + static getHex(n, digits=2){ + return "0x"+("0000"+n.toString(16).toUpperCase()).substr(-digits); + } + constructor(name, bits, value,x,y,scale,position="above",showValue=true,textColor="white",pins=false,numPins=8){ + this.name=name; + this.bits=bits; + this.x=w(x); + this.y=h(y); + this.width=w(scale * this.bits)*0.75; + this.height=h(scale); + this.above=position=="above"; + this.showValue=showValue; + this.textColor=textColor; + if(pins) + for(var i=bits-Math.min(bits,numPins);i{ pin.write(this.binary[i]) }); + + } + draw(border=0){ + if(this.name=="flags"){ + this.value=actualflags; + if(document.getElementById("input").value.length>0) + this.value=this.value|0b10000; + else { + this.value=this.value & 0b01111; + } + this.set(this.value); + } + + drawBorder(this,border); + ctx.fillStyle='white'; + ctx.fillRect(this.x,this.y,this.width,this.height); + var section_width = this.width/this.bits; + // draw text and separators + // labels + ctx.fillStyle = this.textColor; + ctx.font=this.height*0.4+"px vcr_osd_monoregular"; + var textY; + if(this.above){ + ctx.textBaseline = "bottom"; + textY = this.y-this.height*0.05; + } else { + ctx.textBaseline = "top"; + textY = this.y + this.height + this.height * 0.05; + ctx.fillStyle="rgba(24,27,32,0.5)"; + ctx.fillRect(this.x,this.y+this.height,this.width,21); + ctx.fillStyle="white"; + } + ctx.textAlign = "left"; + ctx.fillText(this.name,this.x,textY) + ctx.textAlign = "right"; + if(this.name=="instruction register"){ + ctx.fillText(humanInstruction(this.value),this.x+this.width,textY); + } else + this.showValue ? ctx.fillText(this.value+" | "+Register.getHex(this.value,(this.bits/4)),this.x+this.width,textY) : null; + + for(var i=0;i0) { + ctx.fillRect(this.x+section_width*i,this.y,2,this.height); + } + } + this.pins.forEach(pin=>pin.draw()); + if(this.readEnable){ + ctx.fillStyle="black"; + ctx.fillRect(this.x-6,this.y,6,this.height); + this.readEnable.draw(); + this.writeEnable.draw(); + } + } +} +var actualflags=0; +function pointInCircle(x, y, cx, cy, radius) { + var distancesquared = (x - cx) * (x - cx) + (y - cy) * (y - cy); + return distancesquared <= radius * radius; +} +class Pin { + constructor(x,y,radius=6,label=false,direction="down"){ + this.x=x; + this.y=y; + this.radius=radius; + this.state=0; + this.label=label; + this.direction=direction; + } + read(){ + return this.state; + } + write(state){ + this.state=state==true?1:0; + } + checkMouse(pos){ + return pointInCircle(pos.x,pos.y,this.x,this.y,this.radius); + } + draw(){ + ctx.fillStyle=this.read()==1?"red":"lightgray"; + ctx.beginPath(); + if(this.direction=="down"){ + ctx.arc(this.x,this.y,this.radius, 0*Math.PI,1*Math.PI,false); + } else if(this.direction=="right"){ + ctx.arc(this.x,this.y,this.radius,1.5*Math.PI,0.5*Math.PI,false); + } else if(this.direction=="left") { + ctx.arc(this.x,this.y,this.radius,0.5*Math.PI,1.5*Math.PI,false); + } else if (this.direction=="up") { + ctx.arc(this.x,this.y,this.radius, -1*Math.PI,0*Math.PI,false); + + } + ctx.fill(); + } +} + +class Wire { + update(){ + var state=!!this.input.read(); + if(this.killme>-1){ + if(registers[4].readEnable.read()){ + state = parseInt(registers[4].binary[7-this.killme]); + this.input.write(state); + } + } + this.state=state; + var hovered = this.input.hovered =1 || this.output.hovered == 1; + if(!this.behind) + this.color=state?"#F00":"#AAA"; + else if(this.behind==1) + this.color=state?"#A00":"#777"; + else + this.color=state?"#800":"#555"; + this.output.write(state); + } + draw(){ + ctx.beginPath(); + ctx.moveTo(this.input.x,this.input.y); + var n = this.output.number; + n = n - this.reindex; + var fuckyou = (this.output.number==0 && this.input.direction=="down")?2:0; + if (this.fuckoffanddie){ + ctx.lineTo(435,this.input.y); + ctx.lineTo(435,650); + ctx.lineTo(760,650); + ctx.lineTo(760,570); + ctx.lineTo(this.output.x,570); + } else { + if(!this.horizontal){ + if(!this.reverse){ + ctx.lineTo(this.input.x,this.input.y+fuckyou+Math.max((this.output.y-this.input.y)*0.45+n*7,0)); + ctx.lineTo(this.output.x,this.input.y+fuckyou+Math.max((this.output.y-this.input.y)*0.45+n*7,0.0)); + } else { + /* + ctx.lineTo(this.input.x,this.input.y-15+((this.output.y-this.input.y)*(1-(0.15*n)))); + ctx.lineTo(this.output.x,this.input.y-15+((this.output.y-this.input.y)*(1-(0.15*n)))); + */ + ctx.lineTo(this.input.x,this.input.y+fuckyou+Math.max((this.output.y-this.input.y)*0.56-n*6,0)); + ctx.lineTo(this.output.x,this.input.y+fuckyou+Math.max((this.output.y-this.input.y)*0.56-n*6,0.0)); + } + } else { + if(!this.reverse){ + //ctx.lineTo(this.input.x+fuckyou+Math.max((this.output.x-this.input.x)*0.45+n*7,0),this.input.y); + //ctx.lineTo(this.input.x+fuckyou+Math.max((this.output.x-this.input.x)*0.45+n*7,0.0),this.output.y); + if(!this.zigzag){ + ctx.lineTo(this.input.x-this.flip*(Math.abs(this.output.x-this.input.x)*0.45+n*7),this.input.y); + ctx.lineTo(this.input.x-this.flip*(Math.abs(this.output.x-this.input.x)*0.45+n*7),this.output.y); + } else{ + if(this.kms) + ctx.lineTo(this.input.x,this.output.y) + else + ctx.lineTo(this.output.x,this.input.y) + } + } else { + if(!this.zigzag){ + ctx.lineTo(this.input.x-this.flip*(Math.abs(this.output.x-this.input.x)*0.45-n*7),this.input.y); + ctx.lineTo(this.input.x-this.flip*(Math.abs(this.output.x-this.input.x)*0.45-n*7),this.output.y); + } else{ + ctx.lineTo(this.input.x,this.output.y) + } + /* + ctx.lineTo(this.input.x,this.input.y-15+((this.output.y-this.input.y)*(1-(0.15*n)))); + ctx.lineTo(this.output.x,this.input.y-15+((this.output.y-this.input.y)*(1-(0.15*n)))); + */ + + } + + }} + ctx.lineTo(this.output.x, this.output.y); + var redcolor,graycolor; + if(this.behind==0){ + redcolor="#F0F" + graycolor="#99F" + } else if(this.behind==1) { + redcolor="#A0A" + graycolor="#55F" + } else { + redcolor = "#808" + graycolor="#22F" + } + ctx.strokeStyle=this.hovered?(this.state?redcolor:graycolor):this.color + // cursed ctx.strokeStyle=this.color.substr(0,3)+(this.hovered?"F"/*(Math.min(parseInt(this.color[1],16)+3,15)).toString(16)*/:this.color[3]); + ctx.lineWidth=this.hovered?6:4; + ctx.stroke(); + } + constructor(input, output, label,behind=false, reverse=false,reindex=0,horizontal=false,flip=false,zigzag=false,kms=false,fuckoffanddie=false,killme=-1 ){ + this.input=input; + this.fuckoffanddie=fuckoffanddie; + this.output=output; + this.label=label; + this.reverse=reverse; + this.reindex=reindex; + this.behind=behind; + this.horizontal=horizontal; + this.flip=flip?-1:1; + this.zigzag=zigzag; + this.kms=kms; + this.killme=killme; + } +} +class Tooltip { + constructor(x,y,message,persist=false){ + this.x=x; + this.y=y; + this.message=message; + this.persist=persist; + } + draw(offset){ + ctx.fillStyle="rgba(0,0,0,0.65)"; + ctx.font="20px vcr_osd_monoregular"; + ctx.textBaseline="bottom"; + ctx.textAlign="left"; + var width=ctx.measureText(this.message).width+6; + ctx.fillRect(this.x<720?this.x:this.x-width,this.y-25-(26*offset),width,25); + ctx.fillStyle="white"; + ctx.fillText(this.message,this.x<720?(this.x+3):(this.x-width+3),this.y-(26*offset)); + } +} +function wireUp(){ + // clock + wires.push(new Wire(blocks[4].pins.clk[0],blocks[3].pins.clock[0],"clock")); + // instruction to decoder + //decoder to ALU + for(var i=0;i<5;i++){ + wires.push(new Wire(registers[0].pins[i],blocks[0].pins["instruction"][i],i<4?("opcode bit "+(3-i)):"addressing mode",false,false,2)); + if(i<4) + wires.push(new Wire(blocks[0].pins.toALU[i],blocks[2].points[i],i<4?"ALU opcode bit ":"set flags?")); + } + for(var i=0;i<8;i++){ + ///m data reg to mux + wires.push(new Wire(blocks[5].pins.channel1[7-i],registers[4].pins[7-i],"MDR (mux ch. 1), bit "+i,false,true,3,false,false,false,false,false,i)); + //wires.push(new Wire(blocks[5].pins.channel1[7-i],registers[4].pins[7-i],"memory data register, bit "+(7-i),false,true,5,false,false,false)); + + } + // ALU to flags + var flagtext=["overflow flag","negative flag","carry flag","zero flag"] + for(var i=0;i<4;i++){ + wires.push(new Wire(blocks[2].pins.flags[i],registers[1].pins[i+1],flagtext[i],false,true,2)); + } + //// INPUT OUTPUT STOPS BEHIND REVERSE REINDEX HORIZONTAL FLIP + // decoder to mux control + wires.push(new Wire(blocks[0].pins.toMux[0],blocks[1].pins.selector[0],"mux 0 selector")); + // instruction to multiplexer + for(var i=0;i<8;i++){ + // reg to mux and alu + wires.push(new Wire(blocks[3].pins.data1[i],blocks[2].pins.operand1[i],"first register data (operand 0), bit "+i,false,true,30,true)); + wires.push(new Wire(blocks[3].pins.data2[i],blocks[1].pins.channel0[i],"second register data (mux ch. 0), bit "+i,false,false,0,true)); + //mux to alu + wires.push(new Wire(blocks[1].pins.output[i],blocks[2].pins.operand2[7-i],/*"mux output, bit "+i*/"mux output (operand 1), bit "+[7-i],false,true,0,true,true,true)); + //alu to writeback + //wires.push(new Wire(blocks[2].pins.result[i],blocks[3].pins.writeback[i],"ALU result, bit "+i,false,false,-29,true,true)); + + wires.push(new Wire(blocks[5].pins.output[i],blocks[3].pins.writeback[i],"mux output (reg writeback), bit "+i,false,false,-29,true,true)); + wires.push(new Wire(blocks[2].pins.result[i],blocks[5].pins.channel0[i],"mux ch. 0 (ALU result), bit "+i,false,false,-29,true,true)); + + //alu to mar + wires.unshift(new Wire(blocks[2].pins.result[i],registers[2].pins[7-i],"MAR (ALU result), bit "+i,true,false,0,true,true,true)); + wires.unshift(new Wire(blocks[2].pins.result[i],registers[4].pins[7-i],"MDR (ALU result), bit "+i,true,false,0,true,true,true)); + + wires.unshift(new Wire(blocks[2].pins.result[i],registers[3].pins[7-i],"PC (ALU result), bit "+i,3,false,0,true,true,true)); + //inst to mux + wires.push(new Wire(registers[0].pins[15-i],blocks[1].pins.channel1[7-i],"immediate data (mux ch. 1), bit "+i,false,(7-i)<3,(7-i)<3?-2:8)); + } + // decoder to mux2 + wires.unshift(new Wire(blocks[0].pins.toMux[1],blocks[5].pins.selector[0],"mux 1 selector",true,false,0,false,false,true,true,true)); + + // decoder to reg rwenable + wires.unshift(new Wire(blocks[0].pins.registerReadEnable[0],blocks[3].pins.read1Enable[0],"first register read enable",true,false,-34,true,true)); + wires.unshift(new Wire(blocks[0].pins.registerWriteEnable[0],blocks[3].pins.write1Enable[0],"first register write enable",true,false,-35,true,true)); + // decoder to mar rwenable + wires.unshift(new Wire(blocks[0].pins.memAddrReadEnable[0],registers[2].readEnable,"MAR read enable",3, false,0,true,true,true,true)); + wires.unshift(new Wire(blocks[0].pins.memAddrWriteEnable[0],registers[2].writeEnable,"MAR write enable",3, false,0,true,true,true,true)); + //pc rwenable + wires.unshift(new Wire(blocks[0].pins.pcReadEnable[0],registers[3].readEnable,"PC read enable",3, false,0,true,true,true,true)); + wires.unshift(new Wire(blocks[0].pins.pcWriteEnable[0],registers[3].writeEnable,"PC write enable",3, false,0,true,true,true,true)); + // m d r rwenable + wires.unshift(new Wire(blocks[0].pins.memDataReadEnable[0],registers[4].readEnable,"MDR read enable",3, false,0,true,true,true,true)); + wires.unshift(new Wire(blocks[0].pins.memDataWriteEnable[0],registers[4].writeEnable,"MDR write enable",3, false,0,true,true,true,true)); + // instruction to register address + for(var i=0;i<3;i++){ + wires.unshift(new Wire(registers[0].pins[7-i],blocks[3].pins.address1[i],"first register address, bit "+i,3,false,3,true,true,true,true)); + wires.unshift(new Wire(registers[0].pins[10-i],blocks[3].pins.address2[i],"second register address, bit "+i,3,false,3,true,true,true,true)); + } + +} +url=""; +function setup(){ + images["pencil"]=new Image(); + images["pencil"].src='img/pencil.png'; + images["question"]=new Image(); + images["question"].src='img/question.png'; + + ctx.canvas.width = 1440//window.innerWidth*0.75; + ctx.canvas.height = 976 //window.innerHeight; + registers.push(new Register("instruction register",16, 0, w(13), h(36), 60,"above",true,"white","below",16)); + registers.push(new Register("flags",5,0,w(13),h(885),45,"below",false,"white","above")); + registers.push(new Register("memory address register", 16, 0, w(250), h(885), 45, "below",true,"white","above")) + registers.push(new Register("program counter", 16, 0, w(880), h(885), 45, "below",true,"white","above")) + registers.push(new Register("m. data reg.",8,0,880+(registers[registers.length-1].width/2),803,45,"below",true,"white","above")); + + //goddammit + for(var i=2;i{ + var rect = canvas.getBoundingClientRect(); + tooltips = tooltips.filter(t=>t.persist==true); + scaleX=canvas.width/rect.width; + scaleY=canvas.height/rect.height; + isOverOne=false; + this.wires.forEach(wire=>{ + wire.hovered=false; + var pos = {x:(e.clientX-rect.left)*scaleX, y:(e.clientY-rect.top)*scaleY}; + if(wire.input.checkMouse(pos)||wire.output.checkMouse(pos)){ + wire.hovered=true; + tooltips.push(new Tooltip(pos.x,pos.y,wire.label)); + isOverOne=2; + } + }); + blocks.forEach(block=>{ if(block.checkMouse({x:(e.clientX-rect.left)*scaleX, y:(e.clientY-rect.top)*scaleY})){isOverOne=true;url=block.url;} }); + if(isOverOne==1){ + canvas.style.cursor="pointer"; + } else if(isOverOne==2){ + canvas.style.cursor="help"; + } else { + canvas.style.cursor="default"; + url=""; + } + }); + document.addEventListener('click',e=>{ + if(url){ + window.location.href=url; + console.log("no"); + } else { + console.log("no"); + } + }); + requestAnimationFrame(drawCanvas); +} +var wait=false; +function clockTick(t=1000,oneTime=false){ + blocks[4].pulse(1000,wait); + if(wait){ + registers[2].update(); + registers[4].update(); + wait=false; + } else { + if(blocks[2].correctAnswer>-1){ + if(blocks[2].correctAnswer!=blocks[2].values[2].value){ + tick=false; + blocks[2].done = false; + blocks[2].editable = true; + blocks[2].wrong = true; + return; + } + } + if(!tick && !oneTime) return; + registers.forEach(r=>r.update(true)); + actualflags=getNumber(blocks[2].pins.flags); + if(blocks[4].cycles>1) + blocks[3].realUpdate(); + drawMemory(); + nextInstruction(); + } + if(tick){ + setTimeout(clockTick,t,t); + } +} +var tick=false; +const zeroPad = (num, places) => String(num).padStart(places, '0') +var memPage=0; +function nextMemPage(){ + memPage++; + if(memPage>255) memPage=0; + document.getElementById('label_mempage').innerHTML=zeroPad(memPage,3); + drawMemory(); +} +function prevMemPage(){ + memPage--; + if(memPage<0) memPage=255; + document.getElementById('label_mempage').innerHTML=zeroPad(memPage,3); + drawMemory(); +} +function drawMemory(){ + var memTable = document.getElementById('memory').children[0]; + for(var i=1;i<=16;i++){ + var row = memTable.children[i]; + for(var j=1;j<=16;j++){ + var cell = row.children[j]; + var address = ((memPage)<<8)+(i-1)*16+(j-1); + var val = memory[address]; + cell.innerHTML = zeroPad(val,3); + if(val>0) cell.classList.add('nonzero'); else cell.classList.remove('nonzero'); + } + } +} +initialRun=false; +function compile(){ + resetAll(); + try { + ass = new assembler(); + var bytecode = ass.assemble(document.getElementById('program').value); + console.log(ass.labelAddresses); + for(var i=0;ir.update()); +} +var branchyes = false; +var prevInstruction=-1; +function nextInstruction(){ + var pc = registers[3]; + if(!nosetpc){ + if(prevInstruction!=-1) { + pc.set(pc.value+2,false); + } + } else nosetpc=false; + var flag_reg = registers[1]; + var ir = registers[0]; + var mar = registers[2]; + var mdr = registers[4]; + ir.set((memory[pc.value]<<8)+memory[pc.value+1]); + var instruction = ir.value; + var opcode = instruction >> 12; + if(opcode==15){ + tick=false; + runLabel.innerHTML='Run (finished)'; + } + if(opcode==0b1011) return; + prevInstruction=instruction; + // glue code + wait=opcode==0b1001; + var mode = (instruction>>11)&0b00001; + var f = (registers[0].value >> 8)&0b00000111; + //input + var r2 = (instruction & 0x00FF)>>5; + if((opcode!=11 && opcode<=12)&&r2==0&&mode==0){ + var inp = document.getElementById('input'); + if(inp.value.length>0){ + var setTo; + if(document.getElementById('ascii').checked){ + setTo = inp.value[0]; + setTo = setTo.charCodeAt(0); + inp.value = inp.value.substr(1); + } else { + setTo = parseInt(inp.value.split(" ")[0]); + if(inp.value.indexOf(" ")==-1) inp.value=""; else + inp.value = inp.value.substring(inp.value.indexOf(" ")+1); + } + blocks[3].fileRegisters[7].set(setTo,false); + flag_reg.set(flag_reg.value+(1<<4)); + } else { + blocks[3].fileRegisters[7].set(0,false); + } + } + // memory stores + if(opcode==10){ + registers[4].set(blocks[3].fileRegisters[7-f].value); + } + // conditional branching + if(opcode==12||opcode==13){ + if((actualflags+(registers[1].binary[0]=='1'?16:0)) & (1 << f)){ + branchyes=(opcode==12); + nosetpc=(opcode==12); + } else { + branchyes=(opcode==13); + nosetpc=(opcode==13); + } + } + var mode = (ir.value & 0b0000100000000000)>>11; + if(opcode==0b1110) { //jmp: don't increment pc + nosetpc=true; + } + /* + if(opcode==1111 && mode==0){ // setipg + ir.set((171<<8)+((pc.value+4)>>8)); + } + */ + +} +var nosetpc=false; +function resetAll(){ + initialRun=true; + prevInstruction=-1; + branchyes=false; + nosetpc=false; + document.getElementById("output").value=""; + outputBuf = []; + memory = new Array(65536).fill(0); + blocks.forEach(b=>b.reset()); + registers.forEach(r=>r.set(0,false)); + blocks[3].fileRegisters.forEach(r=>r.set(0,false)); +} +function drawCanvas(){ + ctx.clearRect(0, 0, canvas.width, canvas.height); + if(window.debugall) {;} else { + wires.forEach(w=>w.update()); + blocks.forEach(b=>b.update()); + for(var i=0;i<8;i++){ + registers[4].pins[i].write(registers[4].binary[i]); + } + } + wires.forEach(w=>w.draw()); + blocks.forEach(b=>b.draw()); + registers.forEach(r=>r.draw(1)); + blocks.forEach(b=>b.drawOverlay()); + const flags = new Set(); + tooltips.filter(tt=>{if(flags.has(tt.message)){return false};flags.add(tt.message);return true;}).forEach((t,i)=>t.draw(i)); + requestAnimationFrame(drawCanvas); + +}; +function displayOutput(){ + outputBox = document.getElementById("output"); + outputBox.value = "" + outputBuf.forEach(value=>{ + if(!document.getElementById('ascii').checked) + outputBox.value += String.fromCharCode(b); + else + document.getElementById("output").value += value + " "; + }) + +} \ No newline at end of file diff --git a/js/index_old.js b/js/index_old.js new file mode 100644 index 0000000..efc8287 --- /dev/null +++ b/js/index_old.js @@ -0,0 +1,1112 @@ +var registers=[]; +var blocks=[]; +var wires=[]; +var tooltips=[]; +var embedded = {}; +var images={}; +const BORDER_THICKNESS=5.5; +var canvas, ctx; +var clockTimer; +var opcodes = ['add','sub','adc','subb','nand','xor','sll','srl','mov','ldb','stb', 'nop','bflag','bnoflag', 'jmp', 'hlt']; +var rs = ['io','stackptr','datapg','instpg','gp0','gp1','gp2','gp3']; +var flags = ['zero','carry','negative','overflow','input']; +var memory=new Array(65536).fill(0); +var memPage = 0; +var dataPage = 0; +function getNumber(pins,reverse=true){ + var val = 0; + for(var i=0;i>12; + var addressMode = (machineCode & 0b0000100000000000) >>11; + var r1 = (machineCode & 0b0000011100000000)>>8; + var r2 = (machineCode & 0b0000000011100000)>>5; + var imm8 = machineCode & 0b0000000011111111; + if(opcode==15){ + return(opcodes[opcode]); + } else if(opcode<11) { + return(`${opcodes[opcode]} ${specific?rs[r1]:'reg'}, ${specific?((addressMode?imm8:rs[r2])):addressMode?'imm8':'reg'}`); + } else if (opcode==11){ + return(`${opcodes[opcode]}`); + } else if(opcode==12) { + return(`${opcodes[opcode]} ${specific?flags[r1 & 0b00000111]:'flag'}, ${specific?((addressMode?imm8:rs[r2])):addressMode?'imm8':'reg'}`); + } else { + return(`${opcodes[opcode]} ${specific?((addressMode?imm8:rs[r2])):(addressMode?'imm8':'reg')}`); + } + +} +document.addEventListener("DOMContentLoaded", function(event){ + event; + canvas = document.getElementById("sim"); + ctx = canvas.getContext('2d'); + setup(); + setTimeout(function(){ + embedded['alu'] = document.getElementById('ALUframe').contentWindow.chip; + embedded['mux1'] = document.getElementById('MUX1frame').contentWindow.chip; + embedded['mux2'] = document.getElementById('MUX2frame').contentWindow.chip; + },2000); +}); +function w(width){ + return ((width*canvas.width)/1440); +} +function h(height){ + return ((height*canvas.height)/976); +} +function drawBorder(thing,thickness,color="black"){ + ctx.fillStyle=color; + ctx.fillRect(thing.x-thickness,thing.y-thickness,thing.width+thickness*2,thing.height+thickness*2); +} + +class Block { + constructor(name, x, y, width, height,points=[],editable=true){ + this.name=name; + this.url=""; + this.x=w(x); + this.y=h(y); + this.width=w(width); + this.height=h(height); + this.editable=editable; + this.points=points; + if(this.editable) + this.done=false; + else + this.done=true; + } + update(){ + } + reset(){ + } + makePointArray(){ + this.points=[] + for(const[key,value] of Object.entries(this.pins)){ + key; + //this.points=this.points.concat(value); + value.forEach((pin,i)=>{ pin.number=i; this.points.push(pin) }); + } + + } + drawOverlay(){ + if(!(this.done||this.attempted)){ + ctx.fillStyle="rgba(255,255,255,0.6)"; + ctx.fillRect(this.x,this.y+BORDER_THICKNESS+35,this.width,this.height-BORDER_THICKNESS-35); + ctx.fillStyle="#FFA500" + if(this.wrong) + ctx.fillStyle="#dd3333"; + ctx.fillRect(this.x+this.width/2-35,this.y+this.height/2-35+17,70,70); + ctx.drawImage(images[this.editable?'pencil':'question'],this.x+this.width/2-30,this.y+this.height/2-30+17,60,60); + } else + if(this.editable) + ctx.drawImage(images[this.editable?'pencil':'question'],this.x+this.width-w(37),this.y+this.height-h(30)-h(3),w(30),h(30)); + } + draw(color='white',textcolor='white'){ + ctx.fillStyle=color; + ctx.fillRect(this.x, this.y, this.width, this.height); + ctx.fillStyle="#444"; + ctx.fillRect(this.x,this.y,this.width,BORDER_THICKNESS); + ctx.fillRect(this.x-BORDER_THICKNESS,this.y,BORDER_THICKNESS,this.height+BORDER_THICKNESS); + ctx.fillRect(this.x+this.width,this.y,BORDER_THICKNESS,this.height+BORDER_THICKNESS); + ctx.fillRect(this.x,this.y+this.height,this.width,BORDER_THICKNESS); + if(this.done) + ctx.fillStyle="#43c143"; + else if(!this.attempted) + ctx.fillStyle="#ffa500"; + else + ctx.fillStyle="#dd3333"; + if(this.wrong){ + ctx.fillStyle="#dd3333"; + } + ctx.fillRect(this.x,this.y+BORDER_THICKNESS,this.width,35); + ctx.fillStyle=textcolor; + ctx.font=170*0.15+"px vcr_osd_monoregular"; + ctx.textBaseline = "top"; + ctx.textAlign='left'; + ctx.fillText(this.name,this.x+w(7), this.y+h(13)); + + + this.points.forEach(p=>p.draw()); + } + checkMouse(pos){ + // check if mouse is over icon + if(!this.attempted&&this.editable){ + return pos.x>=this.x+this.width/2-35 && pos.y>=this.y+this.height/2-35 && pos.x<=this.x+this.width/2-35+70 && pos.y<=this.y+this.height/2-35+70; + } else + return pos.x>=this.x+this.width-w(37) && pos.x<=this.x+this.width-w(7) && pos.y>=this.y+this.height-h(33) && pos.y<=this.y+this.height-h(3) && JSON.stringify(Array.from(ctx.getImageData(pos.x,pos.y,1,1).data.slice(0,3)))!="[255,255,255]"; + } +} +class Decoder extends Block { + update(){ + this.setInstruction(humanInstruction(registers[0].value,false),(registers[0].value>>12)); + for(var i=0;i<16;i++){ + if(i<4){ + this.pins.toALU[i].write(this.pins.instruction[i].read()); + } + } + // read from first register only if it's an ALU operation + // write to the first register unless we're in a store or branch instruction + this.pins.registerReadEnable[0].write(this.opcode<8); + this.pins.registerWriteEnable[0].write(this.opcode<10); + // imm8 + this.pins.toMux[0].write(this.pins.instruction[4].read() && this.opcode!=11 &&this.opcode!=15);//(this.mode==1 && this.opcode!=11 && this.opcode!=15)); + + // mem load + this.pins.toMux[1].write(this.opcode==9); + this.pins.memDataReadEnable[0].write(this.opcode==9); + this.pins.memDataWriteEnable[0].write(this.opcode==10); + // + this.pins.memAddrWriteEnable[0].write(this.opcode==9||this.opcode==10); + // jumps + if(this.opcode==14) + this.pins.pcWriteEnable[0].write(1); + else if(this.opcode!=12&&this.opcode!=13) + this.pins.pcWriteEnable[0].write(0); + else + this.pins.pcWriteEnable[0].write(branchyes?1:0); + } + setInstruction(instruction,opcode,mode){ + this.instruction = instruction; + this.opcode=opcode; + this.mode=mode; + } + constructor(x,y,width,height,points=[],editable=true){ + super("decoder",x,y,width,height,points,editable); + this.mode=0; + this.pins = { + instruction: [ + ], + toALU: [ + + ], + toMux: [ + new Pin(this.x+this.width,this.y+this.height-50,6,false,"right"), + new Pin(this.x+this.width,this.y+this.height-50+17,6,false,"right") + ], + registerWriteEnable: [ + new Pin(this.x+this.width,this.y+this.height-140,6,false,"right") + ], + registerReadEnable: [ + new Pin(this.x+this.width,this.y+this.height-157,6,false,"right") + ], + memAddrWriteEnable: [ + new Pin(this.x+190,this.y+this.height), + ], + memAddrReadEnable: [ + new Pin(this.x+207,this.y+this.height) + ], + pcWriteEnable: [ + new Pin(this.x+227+17,this.y+this.height) + ], + pcReadEnable: [ + new Pin(this.x+227+34,this.y+this.height) + ], + memDataWriteEnable:[ + new Pin(this.x+282+17,this.y+this.height) + ], + memDataReadEnable:[ + new Pin(this.x+282+34,this.y+this.height) + ], + + + + + } + for(var i=0;i<5;i++){ + this.pins.instruction.push(new Pin(this.x+17+17*i, this.y)); + if(i<4) + this.pins.toALU.push(new Pin((this.x+17+17*i+(i<4?0:34)), this.y+this.height)); + } + this.makePointArray(); + this.instruction="add reg,reg"; + this.opcode=0; + } + draw(){ + super.draw(); + ctx.fillStyle="black"; + ctx.font=250*0.07+"px vcr_osd_monoregular"; + ctx.textBaseline = "top"; + ctx.textAlign='center'; + ctx.fillText("opcode: "+Register.getBits(this.opcode,4)+" / "+Register.getHex(this.opcode,1)+"",this.x+this.width/2-w(4), this.y+h(55)); + var am=this.pins["instruction"][4].read(); + this.mode=am; + ctx.fillText("mode: "+(am?1:0)+" / "+(this.opcode==15?'special':(((am==0||this.opcode==11)?"register":"immediate"))),this.x+this.width/2-w(4), this.y+h(75)); + + ctx.font=240*0.15+"px vcr_osd_monoregular"; + ctx.fillText(this.instruction,this.x+this.width/2-w(4), this.y+h(100)); + } + + +} +class Mux extends Block { + setChannel(c){ + this.channel=c; + } + update(){ + if(this.second){ + if(!embedded.mux2 || !embedded.mux2.pins) return; + embedded.mux2.pins[16] = this.pins.selector[0].read(); + for(var i=0;i<8;i++){ + embedded.mux2.pins[i] = this.pins.channel0[i].read(); + embedded.mux2.pins[8+i] = this.pins.channel1[7-i].read(); + this.pins.output[7-i].write(embedded.mux2.pins[24-i]); + + }}else{ + if(!embedded.mux1 || !embedded.mux1.pins) return; + embedded.mux1.pins[16] = this.pins.selector[0].read(false); + for(var i=0;i<8;i++){ + embedded.mux1.pins[i] = this.pins.channel0[7-i].read(); + embedded.mux1.pins[8+i] = this.pins.channel1[i].read(); + this.pins.output[7-i].write(embedded.mux1.pins[24-i]); + + }} + + + + this.setChannel(this.pins.selector[0].read()==true?1:0); + } + constructor(x,y,width,height,second=false,de=false,points=[],editable=true){ + super((de?"de":"")+"multiplexer",x,y,width,height,points,editable); + this.de=de; + this.second=second; + this.channel=0; + if(second) + var theselector=new Pin(this.x+this.width-17, this.y); + else + var theselector=new Pin(this.x-BORDER_THICKNESS,blocks[0].pins.toMux[0].y,6,"","right") + if(!this.de){ + this.pins={ + selector: [ + theselector + ], + channel0:[ + ], + channel1: [ + ], + output:[ + ] + } + for(var i=0;i<8;i++){ + if(second){ + this.pins.channel1.push(new Pin(this.x+62+17*i,this.y+BORDER_THICKNESS+this.height,6,"","up")); + this.pins.output.push(new Pin(this.x+this.width,this.y+17+17*i,6,"","right")); + this.pins.channel0.push(new Pin(this.x-BORDER_THICKNESS,this.y+17+17*i,6,"","right")); + } else { + this.pins.channel1.push(new Pin(this.x+17+17*i,this.y)); + this.pins.channel0.push(new Pin(this.x+BORDER_THICKNESS+this.width,this.y+17+17*i,6,"","left")); + this.pins.output.push(new Pin(this.x+17+17*i,this.y+this.height)); + } + } + } else { + this.pins={ + selector: [ + new Pin(this.x-BORDER_THICKNESS,this.y+15,6,"","right"), + new Pin(this.x-BORDER_THICKNESS,this.y+30,6,"","right") + ], + input:[ + ], + channel0:[ + ], + channel1:[ + ], + channel2:[ + ] + } + for(var i=0;i<8;i++){ + this.pins.input.push(new Pin(this.x-BORDER_THICKNESS,this.y+67+17*i,6,"","right")); + this.pins.channel0.push(new Pin(this.x+this.width,this.y+17+17*i,6,"","right")); + this.pins.channel1.push(new Pin(this.x+17+17*i,this.y+this.height)); + this.pins.channel2.push(new Pin(this.x+220+17*i,this.y+this.height)); + } + } + this.makePointArray(); + } + draw(){ + super.draw(); + ctx.fillStyle="black"; + ctx.font="25px vcr_osd_monoregular"; + ctx.baseline="middle"; + ctx.textAlign="center"; + ctx.fillText(" channel: "+this.channel,this.x+this.width/2,this.y+this.height/2); + } +} +class ALU extends Block { + update(){ + if(!embedded.alu) return; + for(var i=0;i<8;i++){ + if(i<4){ + embedded.alu.pins[19-i] = this.pins.opcode[i].read(); + this.pins.flags[i].write(embedded.alu.pins[29+i]); + } + embedded.alu.pins[i] = this.pins.operand1[i].read(); + embedded.alu.pins[i+8] = this.pins.operand2[i].read(); + this.pins.result[i].write(embedded.alu.pins[21+i]); + } + this.values[3].set(getNumber(this.pins.flags)); + this.values[1].set(getNumber(this.pins.operand1,false)); + this.values[0].set(getNumber(this.pins.operand2,false)); + this.values[2].set(getNumber(this.pins.result,false)); + var opcode=getNumber(this.pins.opcode); + if(opcode==6){ + this.correctAnswer = this.values[1].value << this.values[0].value; + } else { + this.correctAnswer = -1; + } + if(opcode>=8){ + this.operation = "move"; + } else { + this.operation = opcodes[opcode]; + } + + } + constructor(x,y,width,height,points=[],editable=true){ + points; + super("ALU",x,y,width,height,wires,editable); + this.wrong=false; + this.operation="add"; + this.values=[new Register("operand 1",8,0,this.x+w(20),this.y+h(80),50,"above",true,"black"), + new Register("operand 0",8,0,this.x+w(20),this.y+h(175),50,"above",true,"black"), + new Register("result",8,0,this.x+w(20),this.y+h(340),50,"above",true,"black"), + new Register("O N C Z flags",4,1,this.x+w(20),this.y+h(410),32,"above",false,"black")]; + //new Register("O . N . C . Z",4,0,this.x+w(125),this.y+h(360),30,"above",false,"black")]; + this.pins={ opcode: []/*,setFlags:[]*/, operand1:[], operand2:[],flags:[],result:[] } + for(var i=0;i<4;i++){ + this.pins.opcode.push(new Pin(this.x+17+17*i,this.y)); + this.pins.flags.push(new Pin(this.x+17+17*i,this.y+this.height)); + } + this.pins.flags[3].write(1); + for(var i=0;i<8;i++){ + this.pins.operand2.push(new Pin(this.x+this.width+BORDER_THICKNESS, this.y+17+17*i,6,"","left")); + this.pins.operand1.push(new Pin(this.x+this.width+BORDER_THICKNESS, this.y+167+17*i,6,"","left")); + this.pins.result.push(new Pin(this.x+this.width, this.y+317+17*i,6,"","right")); + } + + //this.pins.setFlags.push(new Pin(this.x+17*5+34,this.y)); + //this.pins.setFlags[0].write(1); + + this.makePointArray(); + + } + draw(){ + super.draw(); + ctx.fillStyle="black"; + ctx.textAlign="center"; + ctx.textBaseline="middle"; + ctx.font="25px vcr_osd_monoregular"; + ctx.fillText("operation: "+this.operation,this.x+this.width/2, this.y+260); + ctx.font="15px vcr_osd_monoregular"; + //ctx.fillText("set flags: "+(this.pins.setFlags[0].read()==1?"yes":"no"),this.x+this.width/2, this.y+280); + ctx.fillRect(this.x+20,this.y+300,this.width-40,2); + this.values.forEach(v=>v.draw(0)); + } +} +class RegisterFile extends Block { + fileRegisters = []; + selected(){ + return{r1:this.fileRegisters[7-getNumber(this.pins.address1,false)], r2:this.fileRegisters[7-getNumber(this.pins.address2,false)]}; + } + update(){ + for(var i=0;i<8;i++){ + if(this.pins.read1Enable[0].read()) + this.pins.data1[7-i].write(this.selected().r1.binary[i]); + this.pins.data2[7-i].write(this.selected().r2.binary[i]); + } + } + realUpdate(){ + if(!!this.pins.write1Enable[0].read()) { + this.selected().r1.set(getNumber(this.pins.writeback,false),true); + } + } + constructor(x,y,fileRegisters=[],pins=[],editable=true){ + pins,editable; + super("registers",x,y,0,fileRegisters.length*h(85)+h(45),wires,false); + fileRegisters.forEach((r,i)=>{ + if(!r.bits){ + r.bits=8 + } + this.fileRegisters.push(new Register(r.name,r.bits,0,x+w(20),y+i*h(85)+h(65),40,"above",true,"black")); + }); + this.width=this.fileRegisters[0].width+w(80); + this.pins={ + clock:[ new Pin(this.x-BORDER_THICKNESS,this.y+17,6,"","right") ], + read1Enable: [ new Pin(this.x-BORDER_THICKNESS,this.y+17+35,6,"","right") ], + write1Enable: [new Pin(this.x-BORDER_THICKNESS,this.y+34+35,6,"","right") ], + address1: [ ], + address2: [ ], + data2:[ ], + data1:[ ], + writeback:[] + }; + for(var i=0;i<3;i++){ + this.pins.address2.push(new Pin(this.x-BORDER_THICKNESS,this.y+55+35+17+17*i,6,"","right")); + this.pins.address1.push(new Pin(this.x-BORDER_THICKNESS,this.y+125+35+17+17*i,6,"","right")); + } + for(var i=0;i<8;i++){ + this.pins.data2.push(new Pin(this.x,this.y+205+35+17+17*i,6,"","left")); + this.pins.data1.push(new Pin(this.x,this.y+365+35+17+17*i,6,"","left")); + this.pins.writeback.push(new Pin(this.x-BORDER_THICKNESS,this.y+530+35+17+17*i,6,"","right")); + } + super.makePointArray(); + } + draw(){ + super.draw(); + this.fileRegisters.forEach(r=>r.draw(1)); + } +} +class Clock extends Block { + reset(){ + this.state=0; + this.cycles=0; + } + update(){ + this.pins.clk[0].write(this.state); + } + constructor(x,y,width,height){ + super("clock",x,y,width,height,[],false); + this.pins={clk:[new Pin(this.x+this.width,this.y+17,6,"","right")]}; + super.makePointArray(); + this.cycles=0; + this.state=0; + } + pulse(t,w=false){ + this.state = 1; + if(!w) + this.cycles+=1; + setTimeout(function(){this.state=0}.bind(this),t/10); + } + draw(){ + super.draw(); + ctx.fillStyle="black"; + ctx.textAlign="center"; + ctx.textBaseline="middle"; + ctx.fillText(this.cycles,this.x+this.width/2,this.y+this.height/2+20); + } +} + +class Register { + pins=[]; + update(fuck=false){ + /*if(this.name=="memory address register" && fuck) return; + if(this.name=="m. data reg." && fuck) return;*/ + if(this.name=="flags"){ + this.set(getNumber(this.pins)); + if(document.getElementById("input").value.length>0) + this.value=this.value|0b10000; + else { + this.value=this.value & 0b01111; + } + this.set(this.value); + } + else if('writeEnable' in this) { + if(!!this.writeEnable.read()){ + this.set(getNumber(this.pins)); + } + } + if(this.name=="m. data reg."){ + var mAddr = registers[2].value; + if(this.writeEnable.read()){ + memory[mAddr] = this.value; + } + if(this.readEnable.read()||initialRun){ + initialRun=false; + this.set(memory[mAddr]); + } + } + } + static getBits(n,digits=8){ + if(n<0||n>=Math.pow(2,digits)||n%1!==0) { + //console.error(n+" is fucked, yo"); + } + return ("0000000000000000"+n.toString(2)).substr(-digits); + } + static getHex(n, digits=2){ + return "0x"+("0000"+n.toString(16).toUpperCase()).substr(-digits); + } + constructor(name, bits, value,x,y,scale,position="above",showValue=true,textColor="white",pins=false,numPins=8){ + this.name=name; + this.bits=bits; + this.x=w(x); + this.y=h(y); + this.width=w(scale * this.bits)*0.75; + this.height=h(scale); + this.above=position=="above"; + this.showValue=showValue; + this.textColor=textColor; + if(pins) + for(var i=bits-Math.min(bits,numPins);i{ pin.write(this.binary[i]) }); + + } + draw(border=0){ + if(this.name=="flags"){ + this.value=actualflags; + if(document.getElementById("input").value.length>0) + this.value=this.value|0b10000; + else { + this.value=this.value & 0b01111; + } + this.set(this.value); + } + + drawBorder(this,border); + ctx.fillStyle='white'; + ctx.fillRect(this.x,this.y,this.width,this.height); + var section_width = this.width/this.bits; + // draw text and separators + // labels + ctx.fillStyle = this.textColor; + ctx.font=this.height*0.4+"px vcr_osd_monoregular"; + var textY; + if(this.above){ + ctx.textBaseline = "bottom"; + textY = this.y-this.height*0.05; + } else { + ctx.textBaseline = "top"; + textY = this.y + this.height + this.height * 0.05; + ctx.fillStyle="rgba(24,27,32,0.5)"; + ctx.fillRect(this.x,this.y+this.height,this.width,21); + ctx.fillStyle="white"; + } + ctx.textAlign = "left"; + ctx.fillText(this.name,this.x,textY) + ctx.textAlign = "right"; + if(this.name=="instruction register"){ + ctx.fillText(humanInstruction(this.value),this.x+this.width,textY); + } else + this.showValue ? ctx.fillText(this.value+" | "+Register.getHex(this.value,(this.bits/4)),this.x+this.width,textY) : null; + + for(var i=0;i0) { + ctx.fillRect(this.x+section_width*i,this.y,2,this.height); + } + } + this.pins.forEach(pin=>pin.draw()); + if(this.readEnable){ + ctx.fillStyle="black"; + ctx.fillRect(this.x-6,this.y,6,this.height); + this.readEnable.draw(); + this.writeEnable.draw(); + } + } +} +var actualflags=0; +function pointInCircle(x, y, cx, cy, radius) { + var distancesquared = (x - cx) * (x - cx) + (y - cy) * (y - cy); + return distancesquared <= radius * radius; +} +class Pin { + constructor(x,y,radius=6,label=false,direction="down"){ + this.x=x; + this.y=y; + this.radius=radius; + this.state=0; + this.label=label; + this.direction=direction; + } + read(){ + return this.state; + } + write(state){ + this.state=state==true?1:0; + } + checkMouse(pos){ + return pointInCircle(pos.x,pos.y,this.x,this.y,this.radius); + } + draw(){ + ctx.fillStyle=this.read()==1?"red":"lightgray"; + ctx.beginPath(); + if(this.direction=="down"){ + ctx.arc(this.x,this.y,this.radius, 0*Math.PI,1*Math.PI,false); + } else if(this.direction=="right"){ + ctx.arc(this.x,this.y,this.radius,1.5*Math.PI,0.5*Math.PI,false); + } else if(this.direction=="left") { + ctx.arc(this.x,this.y,this.radius,0.5*Math.PI,1.5*Math.PI,false); + } else if (this.direction=="up") { + ctx.arc(this.x,this.y,this.radius, -1*Math.PI,0*Math.PI,false); + + } + ctx.fill(); + } +} + +class Wire { + update(){ + var state=!!this.input.read(); + if(this.killme>-1){ + if(registers[4].readEnable.read()){ + state = parseInt(registers[4].binary[7-this.killme]); + this.input.write(state); + } + } + this.state=state; + var hovered = this.input.hovered =1 || this.output.hovered == 1; + if(!this.behind) + this.color=state?"#F00":"#AAA"; + else if(this.behind==1) + this.color=state?"#A00":"#777"; + else + this.color=state?"#800":"#555"; + this.output.write(state); + } + draw(){ + ctx.beginPath(); + ctx.moveTo(this.input.x,this.input.y); + var n = this.output.number; + n = n - this.reindex; + var fuckyou = (this.output.number==0 && this.input.direction=="down")?2:0; + if (this.fuckoffanddie){ + ctx.lineTo(435,this.input.y); + ctx.lineTo(435,650); + ctx.lineTo(760,650); + ctx.lineTo(760,570); + ctx.lineTo(this.output.x,570); + } else { + if(!this.horizontal){ + if(!this.reverse){ + ctx.lineTo(this.input.x,this.input.y+fuckyou+Math.max((this.output.y-this.input.y)*0.45+n*7,0)); + ctx.lineTo(this.output.x,this.input.y+fuckyou+Math.max((this.output.y-this.input.y)*0.45+n*7,0.0)); + } else { + /* + ctx.lineTo(this.input.x,this.input.y-15+((this.output.y-this.input.y)*(1-(0.15*n)))); + ctx.lineTo(this.output.x,this.input.y-15+((this.output.y-this.input.y)*(1-(0.15*n)))); + */ + ctx.lineTo(this.input.x,this.input.y+fuckyou+Math.max((this.output.y-this.input.y)*0.56-n*6,0)); + ctx.lineTo(this.output.x,this.input.y+fuckyou+Math.max((this.output.y-this.input.y)*0.56-n*6,0.0)); + } + } else { + if(!this.reverse){ + //ctx.lineTo(this.input.x+fuckyou+Math.max((this.output.x-this.input.x)*0.45+n*7,0),this.input.y); + //ctx.lineTo(this.input.x+fuckyou+Math.max((this.output.x-this.input.x)*0.45+n*7,0.0),this.output.y); + if(!this.zigzag){ + ctx.lineTo(this.input.x-this.flip*(Math.abs(this.output.x-this.input.x)*0.45+n*7),this.input.y); + ctx.lineTo(this.input.x-this.flip*(Math.abs(this.output.x-this.input.x)*0.45+n*7),this.output.y); + } else{ + if(this.kms) + ctx.lineTo(this.input.x,this.output.y) + else + ctx.lineTo(this.output.x,this.input.y) + } + } else { + if(!this.zigzag){ + ctx.lineTo(this.input.x-this.flip*(Math.abs(this.output.x-this.input.x)*0.45-n*7),this.input.y); + ctx.lineTo(this.input.x-this.flip*(Math.abs(this.output.x-this.input.x)*0.45-n*7),this.output.y); + } else{ + ctx.lineTo(this.input.x,this.output.y) + } + /* + ctx.lineTo(this.input.x,this.input.y-15+((this.output.y-this.input.y)*(1-(0.15*n)))); + ctx.lineTo(this.output.x,this.input.y-15+((this.output.y-this.input.y)*(1-(0.15*n)))); + */ + + } + + }} + ctx.lineTo(this.output.x, this.output.y); + var redcolor,graycolor; + if(this.behind==0){ + redcolor="#F0F" + graycolor="#99F" + } else if(this.behind==1) { + redcolor="#A0A" + graycolor="#55F" + } else { + redcolor = "#808" + graycolor="#22F" + } + ctx.strokeStyle=this.hovered?(this.state?redcolor:graycolor):this.color + // cursed ctx.strokeStyle=this.color.substr(0,3)+(this.hovered?"F"/*(Math.min(parseInt(this.color[1],16)+3,15)).toString(16)*/:this.color[3]); + ctx.lineWidth=this.hovered?6:4; + ctx.stroke(); + } + constructor(input, output, label,behind=false, reverse=false,reindex=0,horizontal=false,flip=false,zigzag=false,kms=false,fuckoffanddie=false,killme=-1 ){ + this.input=input; + this.fuckoffanddie=fuckoffanddie; + this.output=output; + this.label=label; + this.reverse=reverse; + this.reindex=reindex; + this.behind=behind; + this.horizontal=horizontal; + this.flip=flip?-1:1; + this.zigzag=zigzag; + this.kms=kms; + this.killme=killme; + } +} +class Tooltip { + constructor(x,y,message,persist=false){ + this.x=x; + this.y=y; + this.message=message; + this.persist=persist; + } + draw(offset){ + ctx.fillStyle="rgba(0,0,0,0.65)"; + ctx.font="20px vcr_osd_monoregular"; + ctx.textBaseline="bottom"; + ctx.textAlign="left"; + var width=ctx.measureText(this.message).width+6; + ctx.fillRect(this.x<720?this.x:this.x-width,this.y-25-(26*offset),width,25); + ctx.fillStyle="white"; + ctx.fillText(this.message,this.x<720?(this.x+3):(this.x-width+3),this.y-(26*offset)); + } +} +function wireUp(){ + // clock + wires.push(new Wire(blocks[4].pins.clk[0],blocks[3].pins.clock[0],"clock")); + // instruction to decoder + //decoder to ALU + for(var i=0;i<5;i++){ + wires.push(new Wire(registers[0].pins[i],blocks[0].pins["instruction"][i],i<4?("opcode bit "+(3-i)):"addressing mode",false,false,2)); + if(i<4) + wires.push(new Wire(blocks[0].pins.toALU[i],blocks[2].points[i],i<4?"ALU opcode bit ":"set flags?")); + } + for(var i=0;i<8;i++){ + ///m data reg to mux + wires.push(new Wire(blocks[5].pins.channel1[7-i],registers[4].pins[7-i],"MDR (mux ch. 1), bit "+i,false,true,3,false,false,false,false,false,i)); + //wires.push(new Wire(blocks[5].pins.channel1[7-i],registers[4].pins[7-i],"memory data register, bit "+(7-i),false,true,5,false,false,false)); + + } + // ALU to flags + var flagtext=["overflow flag","negative flag","carry flag","zero flag"] + for(var i=0;i<4;i++){ + wires.push(new Wire(blocks[2].pins.flags[i],registers[1].pins[i+1],flagtext[i],false,true,2)); + } + //// INPUT OUTPUT STOPS BEHIND REVERSE REINDEX HORIZONTAL FLIP + // decoder to mux control + wires.push(new Wire(blocks[0].pins.toMux[0],blocks[1].pins.selector[0],"mux 0 selector")); + // instruction to multiplexer + for(var i=0;i<8;i++){ + // reg to mux and alu + wires.push(new Wire(blocks[3].pins.data1[i],blocks[2].pins.operand1[i],"first register data (operand 0), bit "+i,false,true,30,true)); + wires.push(new Wire(blocks[3].pins.data2[i],blocks[1].pins.channel0[i],"second register data (mux ch. 0), bit "+i,false,false,0,true)); + //mux to alu + wires.push(new Wire(blocks[1].pins.output[i],blocks[2].pins.operand2[7-i],/*"mux output, bit "+i*/"mux output (operand 1), bit "+[7-i],false,true,0,true,true,true)); + //alu to writeback + //wires.push(new Wire(blocks[2].pins.result[i],blocks[3].pins.writeback[i],"ALU result, bit "+i,false,false,-29,true,true)); + + wires.push(new Wire(blocks[5].pins.output[i],blocks[3].pins.writeback[i],"mux output (reg writeback), bit "+i,false,false,-29,true,true)); + wires.push(new Wire(blocks[2].pins.result[i],blocks[5].pins.channel0[i],"mux ch. 0 (ALU result), bit "+i,false,false,-29,true,true)); + + //alu to mar + wires.unshift(new Wire(blocks[2].pins.result[i],registers[2].pins[7-i],"MAR (ALU result), bit "+i,true,false,0,true,true,true)); + wires.unshift(new Wire(blocks[2].pins.result[i],registers[4].pins[7-i],"MDR (ALU result), bit "+i,true,false,0,true,true,true)); + + wires.unshift(new Wire(blocks[2].pins.result[i],registers[3].pins[7-i],"PC (ALU result), bit "+i,3,false,0,true,true,true)); + //inst to mux + wires.push(new Wire(registers[0].pins[15-i],blocks[1].pins.channel1[7-i],"immediate data (mux ch. 1), bit "+i,false,(7-i)<3,(7-i)<3?-2:8)); + } + // decoder to mux2 + wires.unshift(new Wire(blocks[0].pins.toMux[1],blocks[5].pins.selector[0],"mux 1 selector",true,false,0,false,false,true,true,true)); + + // decoder to reg rwenable + wires.unshift(new Wire(blocks[0].pins.registerReadEnable[0],blocks[3].pins.read1Enable[0],"first register read enable",true,false,-34,true,true)); + wires.unshift(new Wire(blocks[0].pins.registerWriteEnable[0],blocks[3].pins.write1Enable[0],"first register write enable",true,false,-35,true,true)); + // decoder to mar rwenable + wires.unshift(new Wire(blocks[0].pins.memAddrReadEnable[0],registers[2].readEnable,"MAR read enable",3, false,0,true,true,true,true)); + wires.unshift(new Wire(blocks[0].pins.memAddrWriteEnable[0],registers[2].writeEnable,"MAR write enable",3, false,0,true,true,true,true)); + //pc rwenable + wires.unshift(new Wire(blocks[0].pins.pcReadEnable[0],registers[3].readEnable,"PC read enable",3, false,0,true,true,true,true)); + wires.unshift(new Wire(blocks[0].pins.pcWriteEnable[0],registers[3].writeEnable,"PC write enable",3, false,0,true,true,true,true)); + // m d r rwenable + wires.unshift(new Wire(blocks[0].pins.memDataReadEnable[0],registers[4].readEnable,"MDR read enable",3, false,0,true,true,true,true)); + wires.unshift(new Wire(blocks[0].pins.memDataWriteEnable[0],registers[4].writeEnable,"MDR write enable",3, false,0,true,true,true,true)); + // instruction to register address + for(var i=0;i<3;i++){ + wires.unshift(new Wire(registers[0].pins[7-i],blocks[3].pins.address1[i],"first register address, bit "+i,3,false,3,true,true,true,true)); + wires.unshift(new Wire(registers[0].pins[10-i],blocks[3].pins.address2[i],"second register address, bit "+i,3,false,3,true,true,true,true)); + } + +} +url=""; +function setup(){ + images["pencil"]=new Image(); + images["pencil"].src='img/pencil.png'; + images["question"]=new Image(); + images["question"].src='img/question.png'; + + ctx.canvas.width = 1440//window.innerWidth*0.75; + ctx.canvas.height = 976 //window.innerHeight; + registers.push(new Register("instruction register",16, 0, w(13), h(36), 60,"above",true,"white","below",16)); + registers.push(new Register("flags",5,0,w(13),h(885),45,"below",false,"white","above")); + registers.push(new Register("memory address register", 16, 0, w(250), h(885), 45, "below",true,"white","above")) + registers.push(new Register("program counter", 16, 0, w(880), h(885), 45, "below",true,"white","above")) + registers.push(new Register("m. data reg.",8,0,880+(registers[registers.length-1].width/2),803,45,"below",true,"white","above")); + + //goddammit + for(var i=2;i{ + var rect = canvas.getBoundingClientRect(); + tooltips = tooltips.filter(t=>t.persist==true); + scaleX=canvas.width/rect.width; + scaleY=canvas.height/rect.height; + isOverOne=false; + this.wires.forEach(wire=>{ + wire.hovered=false; + var pos = {x:(e.clientX-rect.left)*scaleX, y:(e.clientY-rect.top)*scaleY}; + if(wire.input.checkMouse(pos)||wire.output.checkMouse(pos)){ + wire.hovered=true; + tooltips.push(new Tooltip(pos.x,pos.y,wire.label)); + isOverOne=2; + } + }); + blocks.forEach(block=>{ if(block.checkMouse({x:(e.clientX-rect.left)*scaleX, y:(e.clientY-rect.top)*scaleY})){isOverOne=true;url=block.url;} }); + if(isOverOne==1){ + canvas.style.cursor="pointer"; + } else if(isOverOne==2){ + canvas.style.cursor="help"; + } else { + canvas.style.cursor="default"; + url=""; + } + }); + document.addEventListener('click',e=>{ + if(url){ + window.location.href=url; + console.log("no"); + } else { + console.log("no"); + } + }); + requestAnimationFrame(drawCanvas); +} +var wait=false; +function clockTick(t=1000,oneTime=false){ + blocks[4].pulse(1000,wait); + if(wait){ + registers[2].update(); + registers[4].update(); + wait=false; + } else { + if(blocks[2].correctAnswer>-1){ + if(blocks[2].correctAnswer!=blocks[2].values[2].value){ + tick=false; + blocks[2].done = false; + blocks[2].editable = true; + blocks[2].wrong = true; + return; + } + } + if(!tick && !oneTime) return; + registers.forEach(r=>r.update(true)); + actualflags=getNumber(blocks[2].pins.flags); + if(blocks[4].cycles>1) + blocks[3].realUpdate(); + drawMemory(); + nextInstruction(); + } + if(tick){ + setTimeout(clockTick,t,t); + } +} +var tick=false; +const zeroPad = (num, places) => String(num).padStart(places, '0') +var memPage=0; +function nextMemPage(){ + memPage++; + if(memPage>255) memPage=0; + document.getElementById('label_mempage').innerHTML=zeroPad(memPage,3); + drawMemory(); +} +function prevMemPage(){ + memPage--; + if(memPage<0) memPage=255; + document.getElementById('label_mempage').innerHTML=zeroPad(memPage,3); + drawMemory(); +} +function drawMemory(){ + var memTable = document.getElementById('memory').children[0]; + for(var i=1;i<=16;i++){ + var row = memTable.children[i]; + for(var j=1;j<=16;j++){ + var cell = row.children[j]; + var address = ((memPage)<<8)+(i-1)*16+(j-1); + var val = memory[address]; + cell.innerHTML = zeroPad(val,3); + if(val>0) cell.classList.add('nonzero'); else cell.classList.remove('nonzero'); + } + } +} +initialRun=false; +function compile(){ + resetAll(); + try { + ass = new assembler(); + var bytecode = ass.assemble(document.getElementById('program').value); + console.log(ass.labelAddresses); + for(var i=0;ir.update()); +} +var branchyes = false; +var prevInstruction=-1; +function nextInstruction(){ + var pc = registers[3]; + if(!nosetpc){ + if(prevInstruction!=-1) { + pc.set(pc.value+2,false); + } + } else nosetpc=false; + var flag_reg = registers[1]; + var ir = registers[0]; + var mar = registers[2]; + var mdr = registers[4]; + ir.set((memory[pc.value]<<8)+memory[pc.value+1]); + var instruction = ir.value; + var opcode = instruction >> 12; + if(opcode==15){ + tick=false; + runLabel.innerHTML='Run (finished)'; + } + if(opcode==0b1011) return; + prevInstruction=instruction; + // glue code + wait=opcode==0b1001; + var mode = (instruction>>11)&0b00001; + var f = (registers[0].value >> 8)&0b00000111; + //input + var r2 = (instruction & 0x00FF)>>5; + if((opcode!=11 && opcode<=12)&&r2==0&&mode==0){ + var inp = document.getElementById('input'); + if(inp.value.length>0){ + var setTo; + if(document.getElementById('ascii').checked){ + setTo = inp.value[0]; + setTo = setTo.charCodeAt(0); + inp.value = inp.value.substr(1); + } else { + setTo = parseInt(inp.value.split(" ")[0]); + if(inp.value.indexOf(" ")==-1) inp.value=""; else + inp.value = inp.value.substring(inp.value.indexOf(" ")+1); + } + blocks[3].fileRegisters[7].set(setTo,false); + flag_reg.set(flag_reg.value+(1<<4)); + } else { + blocks[3].fileRegisters[7].set(0,false); + } + } + // memory stores + if(opcode==10){ + registers[4].set(blocks[3].fileRegisters[7-f].value); + } + // conditional branching + if(opcode==12||opcode==13){ + if((actualflags+(registers[1].binary[0]=='1'?16:0)) & (1 << f)){ + branchyes=(opcode==12); + nosetpc=(opcode==12); + } else { + branchyes=(opcode==13); + nosetpc=(opcode==13); + } + } + var mode = (ir.value & 0b0000100000000000)>>11; + if(opcode==0b1110) { //jmp: don't increment pc + nosetpc=true; + } + /* + if(opcode==1111 && mode==0){ // setipg + ir.set((171<<8)+((pc.value+4)>>8)); + } + */ + +} +var nosetpc=false; +function resetAll(){ + initialRun=true; + prevInstruction=-1; + branchyes=false; + nosetpc=false; + document.getElementById("output").value=""; + memory = new Array(65536).fill(0); + blocks.forEach(b=>b.reset()); + registers.forEach(r=>r.set(0,false)); + blocks[3].fileRegisters.forEach(r=>r.set(0,false)); +} +function drawCanvas(){ + ctx.clearRect(0, 0, canvas.width, canvas.height); + if(window.debugall) {;} else { + wires.forEach(w=>w.update()); + blocks.forEach(b=>b.update()); + for(var i=0;i<8;i++){ + registers[4].pins[i].write(registers[4].binary[i]); + } + } + wires.forEach(w=>w.draw()); + blocks.forEach(b=>b.draw()); + registers.forEach(r=>r.draw(1)); + blocks.forEach(b=>b.drawOverlay()); + const flags = new Set(); + tooltips.filter(tt=>{if(flags.has(tt.message)){return false};flags.add(tt.message);return true;}).forEach((t,i)=>t.draw(i)); + requestAnimationFrame(drawCanvas); + +}; diff --git a/js/opcodes.js b/js/opcodes.js new file mode 100755 index 0000000..a5ad046 --- /dev/null +++ b/js/opcodes.js @@ -0,0 +1,152 @@ +match= { + reg: "(io|sp|ipage|dpage|stackptr|gp[0-3])", + imm8: "~?#(0b[0-1]{1,8}|(0x)?[0-9]{1,3})", + label: "[A-z][A-z0-9]*", + flags: "(INPUT|OVERFLOW|NEGATIVE|CARRY|ZERO)" + } +instructions = { + match: match, + registers:[ + "io", + "stackptr", + "dpage", + "ipage", + "gp0", + "gp1", + "gp2", + "gp3" + ], + flags:[ + "INPUT", + "OVERFLOW", + "NEGATIVE", + "CARRY", + "ZERO" + ].reverse(), + arg_patterns:[ + [ + { pattern: [ match.reg, match.reg ], mode: 0 }, + { pattern: [ match.reg, match.imm8 ], mode: 1 }, + ], + [ + { pattern: [ match.reg ], mode: 0 } + ], + [ + { pattern: [ match.reg ], mode: 1 } + + ], + [ + { pattern: [ match.flags, match.reg ], mode: 0 }, + { pattern: [ match.flags, match.imm8 ], mode: 1 }, + ], + [ + { pattern: [ match.reg ], mode: 0 }, + { pattern: [ match.imm8 ], mode: 1 }, + ], + [ + { pattern: [ ], mode: 0 } + ], + [ + { pattern: [ ], mode: 1 } + ] + ], + opcodes:[ + { + opcode: 0b0000, + mnemonic:"add", + patterns: 0, + description: "Adds the immediate data, or the contents of the register given as the second operand to the register given as first operand." + }, + { + opcode: 0b0001, + mnemonic:"sub", + patterns: 0, + description: "Subtracts the immediate data, or the contents of the register given as the third operand to the register given as the first operand." + }, + { + opcode:0b0010, + mnemonic: "adc", + patterns: 0, + description: "Adds the two operands plus the carry flag, stores in the first operand register." + }, + { + opcode:0b0011, + mnemonic:"subb", + patterns:0, + description: "Subtracts the second operand plus the carry flag from the first operand." + }, + { + opcode:0b0100, + mnemonic:"nand", + patterns:0, + description:"Performs logical NAND on the two operands; stores in first operand register." + }, + { + opcode:0b0101, + mnemonic: "xor", + patterns:0, + description:"Performs logical XOR on the two operands; stores in first operand register." + }, + { + opcode:0b0110, + mnemonic:"sll", + patterns:0, + description:"Shifts bits in the first operand register left by the amount specified in the second operand." + }, + { + opcode:0b0111, + mnemonic:"srl", + patterns:0, + description:"Shifts bits in the first operand register right by the amount specified in the second operand." + }, + { + opcode:0b1000, + mnemonic:"mov", + patterns:0, + description: "Copies the register or data in the second operand into the first operand register." + }, + { + opcode:0b1001, + mnemonic:"ldb", + patterns:0, + description:"Loads the byte into the first operand register at the address specified in the second operand." + }, + { + opcode:0b1010, + mnemonic:"stb", + patterns:0, + description:"Stores the contents of the first operand register into the address specified in the second operand." + }, + { + opcode:0b1011, + mnemonic:"nop", + patterns:5, + description:"performs no operation." + }, + { + opcode:0b1100, + mnemonic:"bflag", + patterns:0, + description: "Branches to the specified memory address if the specified flag bit is set." + }, + { + opcode:0b1101, + mnemonic:"bnoflag", + patterns:0, + description: "Branches to the specified memory address if the specified flag bit is NOT set." + }, + + { + opcode:0b1110, + mnemonic:"jmp", + patterns:4, + description:"Branches unconditionally to the specified memory address." + }, + { + opcode:0b1111, + mnemonic:"hlt", + patterns:5, + description:"Terminates execution." + } + ] +} diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..e69de29 diff --git a/simulator/asm.html b/simulator/asm.html new file mode 100755 index 0000000..127b167 --- /dev/null +++ b/simulator/asm.html @@ -0,0 +1,5 @@ + + + diff --git a/simulator/assembler.js b/simulator/assembler.js new file mode 100755 index 0000000..5f5c97e --- /dev/null +++ b/simulator/assembler.js @@ -0,0 +1,283 @@ +Array.prototype.findIndexes=function(where) { + return this.reduce((a, e, i) => (where(e, i) ? a.concat(i) : a), []); +} +class assembler { + labels = []; + labelAddresses = []; + address = 0; + curLine = 0; + + offset = 0; // account for any instructions the assembler needs to add + upper8(address){ + return address>>8; + } + lower8(address){ + return address&0x00FF; + } + intByte(n){ + n=n.replace("#",""); + var invert = false; + if(n[0]=="~") { invert=true; n=n.slice(1)}; + var b = 0; + if(n.match(/^0b/)){ + b = parseInt(n.slice(2),2); + } else { + b = parseInt(n); + } + if(isNaN(b)) { + throw 'Invalid number'; + } else if(b>255 || b <-128){ + throw 'Number will not fit in a byte!'; + } + if(b<0){ + // apply 2's complement to negative value + var r= ~Math.abs(b)+1; + } else { + var r= b; + }; + return invert ? ((~r>>>0)&0xFF) : r; + } + encodeInstruction(line){ + var bytes = [0,0]; + var instruction = instructions.opcodes.find(oc=>oc.mnemonic==line[0].toLowerCase()); + if(instruction.mnemonic=="bflag") { + flag = instruction.flags.indexOf(line[1]); + if(flag>=0){ + // evil stupid dumb + line[1] = line[1].replace(instruction.flags[flag],instruction.registers[flag]); + + } else throw 'Invalid flag.'; + } + if(!instruction) throw 'Unknown opcode'; + var patterns = instructions.arg_patterns[instruction.patterns]; + var mode = -1; + if(patterns[0].pattern.length!=line.length-1){ + throw 'Wrong number of operands'; + } else if(patterns.length==1){ + mode = patterns[0].mode; + } else { + patterns.forEach(pattern=>{ + var fit=0; + for(var i=0;i{ + var l; + var mnemonic = instruction[0].toLowerCase(); + this.curLine = i; + var offset=0; + // dealing with pseudo instructions + if(mnemonic==".data"){ + return; + } else if(mnemonic=="hlt"){ // halt: jump to same instruction + if(this.upper8(instAddr)!=instPage){ + instPage=this.upper8(instAddr); + bytecode=bytecode.concat(this.encodeInstruction(["mov","ibank","#"+instPage])); + offset=2; + } + bytecode = bytecode.concat(this.encodeInstruction(["jmp","#"+this.lower8(instAddr+offset)])); + } else if(mnemonic=="nop"){ // nop: jump to next instruction + if(this.upper8(instAddr+2)!=instPage){ + offset=2; + instPage=this.upper8(instAddr); + bytecode=bytecode.concat(this.encodeInstruction(["mov","ibank","#"+instPage])); + } + bytecode = bytecode.concat(this.encodeInstruction(["jmp","#"+this.lower8(instAddr+2+offset)])); + // now process labels + } else if(mnemonic=="jsr"||mnemonic=="jmp"){ + l = this.labelAddresses.find(la=>instruction[1].includes(la.label)); + + if(l){ // we must replace + instruction[1] = instruction[1].replace(l.label, "#"+this.lower8(l.address)); + if(this.upper8(l.address)!=instPage){ + instPage=this.upper8(l.address); + bytecode=bytecode.concat(this.encodeInstruction(["mov","ibank","#"+instPage])); + offset=2; + } + } + bytecode=bytecode.concat(this.encodeInstruction(instruction)); + } else if(mnemonic=="stb"||mnemonic=="ldb"){ + l = this.labelAddresses.find(la=>instruction[2].includes(la.label)); + if(l){ // we must replace + instruction[2] = instruction[2].replace(l.label, "#"+this.lower8(l.address)); + if(this.upper8(l.address)!=dataPage){ + dataPage=this.upper8(l.address); + bytecode=bytecode.concat(this.encodeInstruction(["mov","dbank","#"+dataPage])); + offset=2; + } + } + bytecode=bytecode.concat(this.encodeInstruction(instruction)); + } else bytecode=bytecode.concat(this.encodeInstruction(instruction)); + l = this.labels.findIndex(la=>la.line==i); + if(l>-1){ + this.labelAddresses.push({label: this.labels[i].label, address: instAddr}); + } + instAddr += 2 + offset; + }); + return bytecode; + } + assemble(code) { + // try + var tokens = this.tokenize(code); + var withPseudo = this.processAndOr(tokens); + var delabeled = this.processLabels(withPseudo); + var data = this.processData(delabeled); + var bytecode = this.processInstructions(delabeled); + var pad = data.bytes.length>0?Array(data.start - bytecode.length).fill(0):[]; + console.log({tokens,withPseudo,delabeled,data,bytecode}) + + return bytecode.concat(pad).concat(data.bytes); + // catch + } + processAndOr(tokenLines) { + var processed=[]; + tokenLines.forEach(line=>{ + if(line.length<2){ + processed.push(line) + } + else if(line[0].toLowerCase()=="and") { + line[0] = "nand"; + processed.push(line); // NAND a, b + processed.push(['nand',line[1],line[1]]); // NAND a, a + } else if(line[1].toLowerCase()=="and") { + line[1] = "nand"; + processed.push(line); // ibid + processed.push(['nand',line[2],line[2]]); + } else if(line[0].toLowerCase()=="or") { + processed.push(['nand',line[1],line[1]]); // NAND a, a + if(line[2].toLowerCase().match(instructions.match.reg)){ + processed.push(['nand',line[2],line[2]]); // NAND b, b + processed.push(['nand',line[1],line[2]]); // NAND a, b + processed.push(['nand',line[2],line[2]]); // NAND b, b + } else if(line[2].toLowerCase().match(instructions.match.imm8)) { + //int imm8 = intByte(this.intByte(line[2]); // NAND b, b + processed.push(['nand',line[1],"~"+line[2]]);//line[2]]); // NAND a, b + } else if(line[2].toLowerCase().match(instructions.match.label)) { + processed.push(['nand',line[1],"~"+line[2]]);// NAND a, ~b + } else throw("error converting and"); + } else if(line[1].toLowerCase()=="or"){ + processed.push(['nand',line[2],line[2]]); // NAND a, a + if(line[3].toLowerCase().match(/(ip|dp|sp|r[0-3])/)){ + processed.push(['nand',line[3],line[3]]); // NAND b, b + processed.push(['nand',line[2],line[3]]); // NAND a, b + processed.push(['nand',line[3],line[3]]); // NAND b, b + } else if(line[3].toLowerCase().match(instructions.match.imm8)) { + imm8 = ~this.intByte(line[3]); // NAND b, b + processed.push(['nand',line[2],line[3]]); // NAND a, b + } else if(line[3].toLowerCase().match(instructions.match.label)) { + processed.push(['nand',line[2],"~"+line[3]]);// NAND a, ~b + } else throw("error converting and"); + + } else { + processed.push(line); + } + }); + return processed; + } + processLabels(tokenLines) { + var processed = []; + // first pass: extract labels + for(var i=0;i 1 && curLine[1]!=''){ + // first token was label; next token will be opcode or data + processed.push(curLine.slice(1)); + } + this.labels.push({ label: curLine[0].split(/:.*/)[0], line: lineNum }); + //processed.push(curLine.slice(1)); + } else processed.push(curLine); + } + return processed; + } + processData(tokenLines) { + // we want to find out where the end of the instructions will be + // however, we don't know how many the assembler will insert to deal with pages + // i can't be bothered doing this properly so let's just add an extra two bytes + // for every instruction that accesses memory + // get number of instructions that deal with memory + var dataInstructions = tokenLines.findIndexes(line=>line[0].toLowerCase().match('^.data$')); + var numMem = tokenLines.filter(line => line[0].toLowerCase().match(/(ldb|stb|jsr|jmp|bflag)/)).length; + var start = ( (tokenLines.length - dataInstructions.length) + numMem )* 2; + var curAddr = 0; + var bytes = []; + dataInstructions.forEach(i=>{ + this.curLine = i; + var thisLabel = this.labels.find(l => l.line== i); + if(thisLabel){ + this.labelAddresses.push({ label: thisLabel.label, address: curAddr+start }); + } + tokenLines[i].slice(1).forEach(token=>{ + // if string + if(token.match(/^".*"$/)) { + token.slice(1).slice(0,-1).replace(/[^\x00-\x7F]/g, "").split('').forEach(character=>{ + bytes.push(character.charCodeAt(0)); + curAddr += 1; + }); + } else { + bytes.push(this.intByte(token)); + curAddr += 1; + } + }); + + }) + + return { start, bytes }; + + } + tokenize(code) { + var tokenLines = []; + // split code into lines - strings enclosed in quotes can span multiple lines + // nb this breaks for escaped quotes but who cares + var lines = code.split(/(?<=^[^\"]*(?:\"[^\"]*\"[^\"]*)*)\r?\n(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/); + lines.forEach(line=>{ + // split on wgutespace or comma, unless quoted + var tokens = line.split(/(?<=^[^\"]*(?:\"[^\"]*\"[^\"]*)*)[ ,]+(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/); + // remove comments preceded by ; + var hitSemicolon=false + var tokenLine=[]; + tokens.forEach(token=>{ + //console.log(token); + if(token[0]==";"||hitSemicolon){ + hitSemicolon=true; + } else { + tokenLine.push(token); + //console.log(tokenLine); + } + }) + tokenLines.push(tokenLine); + }) + return tokenLines; + } +} diff --git a/simulator/opcodes.js b/simulator/opcodes.js new file mode 100755 index 0000000..13b76e4 --- /dev/null +++ b/simulator/opcodes.js @@ -0,0 +1,163 @@ +match= { + reg: "(ibank|dbank|sp|r[0-3])", + imm8: "~?#(0b[0-1]{1,8}|(0x)?[0-9]{1,3})", + label: "[A-z][A-z0-9]*", + flags: "(INPUT|OVERFLOW|NEGATIVE|CARRY|ZERO)" + } +instructions = { + match: match, + + registers:[ + "ibank", + "dbank", + "sp", + "r0", + "r1", + "r2", + "r3" + ], + flags:[ + "INPUT", + "OVERFLOW", + "NEGATIVE", + "CARRY", + "ZERO" + ], + arg_patterns:[ + [ + { pattern: [ match.reg, match.reg ], mode: 0 }, + { pattern: [ match.reg, match.imm8 ], mode: 1 }, + ], + [ + { pattern: [ match.reg ], mode: 0 } + ], + [ + { pattern: [ match.reg ], mode: 1 } + + ], + [ + { pattern: [ match.flags, match.reg ], mode: 0 }, + { pattern: [ match.flags, match.imm8 ], mode: 1 }, + ], + [ + { pattern: [ match.reg ], mode: 0 }, + { pattern: [ match.imm8 ], mode: 1 }, + ], + [ + { pattern: [ ], mode: 0 } + ], + [ + { pattern: [ ], mode: 1 } + ] + ], + opcodes:[ + { + opcode: 0b0000, + mnemonic:"add", + patterns: 0, + description: "Adds the immediate data, or the contents of the register given as the second operand to the register given as first operand." + }, + { + opcode: 0b0001, + mnemonic:"sub", + patterns: 0, + description: "Subtracts the immediate data, or the contents of the register given as the third operand to the register given as the first operand." + }, + { + opcode:0b0010, + mnemonic: "adc", + patterns: 0, + description: "Adds the two operands plus the carry flag, stores in the first operand register." + }, + { + opcode:0b0011, + mnemonic:"subb", + patterns:0, + description: "Subtracts the second operand plus the carry flag from the first operand." + }, + { + opcode:0b0100, + mnemonic:"nand", + patterns:0, + description:"Performs logical NAND on the two operands; stores in first operand register." + }, + { + opcode:0b0101, + mnemonic: "xor", + patterns:0, + description:"Performs logical XOR on the two operands; stores in first operand register." + }, + { + opcode:0b0110, + mnemonic:"sll", + patterns:0, + description:"Shifts bits in the first operand register left by the amount specified in the second operand." + }, + { + opcode:0b0111, + mnemonic:"srl", + patterns:0, + description:"Shifts bits in the first operand register right by the amount specified in the second operand." + }, + { + opcode:0b1000, + mnemonic:"mov", + patterns:0, + description: "Copies the register or data in the second operand into the first operand register." + }, + { + opcode:0b1001, + mnemonic:"ldb", + patterns:0, + description:"Loads the byte into the first operand register at the address specified in the second operand." + }, + { + opcode:0b1010, + mnemonic:"stb", + patterns:0, + description:"Stores the contents of the first operand register into the address specified in the second operand." + }, + { + opcode:0b1011, + mnemonic:"push", + patterns:1, + description:"Pushes the contents of the specified register onto the stack." + }, + { + opcode:0b1011, + mnemonic:"pop", + patterns:2, + description:"Pops the first item of the stack into the specified register" + }, + { + opcode:0b1100, + mnemonic:"bflag", + patterns:3, + description: "Branches to the specified memory address if the specified flag bit is set." + }, + { + opcode:0b1101, + mnemonic:"jmp", + patterns:4, + description:"Branches unconditionally to the specified memory address." + }, + { + opcode:0b1110, + "menmonic":"jsr", + patterns:4, + description:"Branches unconditionally to the specified memory address and push the lower 8 bits of (program counter + 2) onto the stack." + }, + { + opcode:0b1111, + mnemonic:"setipg", + patterns:5, + description:"Sets the instruction page register to the upper 8 bits of (program counter + 4)." + }, + { + opcode:0b1111, + mnemonic:"ret", + patterns:6, + description:"Pulls the lower 8 bits of the return address from the stack and jumps to it." + } + ] +} diff --git a/simulator/opcodes.json b/simulator/opcodes.json new file mode 100755 index 0000000..97c7224 --- /dev/null +++ b/simulator/opcodes.json @@ -0,0 +1,134 @@ +{ + "arg_patterns":[ + [ + "(ip|dp|sp|r[0-3]),? (ip|dp|sp|r[0-3])", + "(ip|dp|sp|r[0-3]),? #(0b[0-1]{1,8}|(0x)?[0-9]{1,3})", + "(ip|dp|sp|r[0-3]),? [A-z][A-z0-9]*" + ], + [ + "(ip|dp|sp|r[0-3])" + ], + [ + "#(0b[0-1]{1,3}|(0x)?[0-9]{1,3})", + "(INPUT|OVERFLOW|NEGATIVE|CARRY|ZERO)" + ] + [ + "(ip|dp|sp|r[0-3])", + "#(0b[0-1]{1,8}|(0x)?[0-9]{1,3})", + "[A-z][A-z0-9]*" + ], + [ + "" + ] + ], + "opcodes":[ + { + "opcode": 0b0000, + "mnemonic":"add", + "patterns": 0, + "description": "Adds the immediate data, or the contents of the register given as the second operand to the register given as first operand." + }, + { + "opcode": 0b0001, + "mnemonic":"sub", + "patterns": 0, + "description": "Subtracts the immediate data, or the contents of the register given as the third operand to the register given as the first operand." + }, + { + "opcode":0b0010, + "mnemonic": "adc", + "patterns": 0, + "description": "Adds the two operands plus the carry flag, stores in the first operand register." + }, + { + "opcode":0b0011, + "mnemonic":"subb", + "patterns":0, + "description": "Subtracts the second operand plus the carry flag from the first operand." + }, + { + "opcode":0b0100, + "mnemonic":"nand", + "patterns":0, + "description":"Performs logical NAND on the two operands; stores in first operand register." + }, + { + "opcode":0b0101, + "mnemonic": "xor", + "patterns":0, + "description":"Performs logical XOR on the two operands; stores in first operand register." + }, + { + "opcode":0b0110, + "mnemonic":"sll", + "patterns":0, + "description":"Shifts bits in the first operand register left by the amount specified in the second operand." + }, + { + "opcode":0b0111, + "mnemonic":"srl", + "patterns":0, + "description":"Shifts bits in the first operand register right by the amount specified in the second operand." + }, + { + "opcode":0b1000, + "mnemonic":"mov", + "patterns":0, + "description": "Copies the register or data in the second operand into the first operand register." + }, + { + "opcode":0b1001, + "mnemonic":"ldb", + "patterns":0, + "description":"Loads the byte into the first operand register at the address specified in the second operand." + }, + { + "opcode":0b1010, + "mnemonic":"stb", + "patterns":0, + "description":"Stores the contents of the first operand register into the address specified in the second operand." + }, + { + "opcode":0b1011, + "mnemonic":"push", + "patterns":1, + "description":"Pushes the contents of the specified register onto the stack." + }, + { + "opcode":0b1011, + "mnemonic":"pop", + "patterns":1, + "description":"Pops the first item of the stack into the specified register" + }, + { + "opcode":0b1100, + "mnemonic":"bflag", + "patterns":2, + "description": "Branches to the specified memory address if the specified flag bit is set." + }, + { + "opcode":0b1101, + "mnemonic":"jmp", + "patterns":3, + "description":"Branches unconditionally to the specified memory address." + }, + { + "opcode":0b1110, + "menmonic":"jsr", + "patterns":3, + "description":"Branches unconditionally to the specified memory address and push the lower 8 bits of (program counter + 2) onto the stack." + }, + { + "opcode":0b1111, + "mnemonic":"setipg", + "patterns":4, + "description":"Sets the instruction page register to the upper 8 bits of (program counter + 4)." + }, + { + "opcode":0b1111, + "mnemonic":"ret", + "patterns":4, + "description":"Pulls the lower 8 bits of the return address from the stack and jumps to it." + + +} diff --git a/simulator/sim.js b/simulator/sim.js new file mode 100755 index 0000000..d7d3ce8 --- /dev/null +++ b/simulator/sim.js @@ -0,0 +1,188 @@ +class eduProc { + reset() { + // initialise instruction and data memory + this.memory = new Array(65536).fill(0); + + this.state = 0; // 0=fetch, 1=decode, 2=execute; + // store the registers as private members + this.programCounter = 0x0000; // 16 bits + this.instructionRegister = 0x0000; // 16 bits + this.memoryAddressRegister = 0x0000; // 16 bits + //memoryDataRegister = 0x00; // 8 bits + this.flags = 0x0; // 4 bits + this.flagNames = { input: 4, overflow: 3, negative: 2, carry: 1, zero: 0 } + this.registers = [0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00]; //8 bits + // human friendly names for the four special purpose registers + this.regNames = { instruction_page: 0, data_page: 1, stack_pointer: 2, serial_io: 3 }; + this.stack_page = 0xFF; + } + + freeze() { + // todo + } + + constructor() { + reset(); + } + // handle flags + setFlag(flagName, onoff) { + // get bit position of flag + const bitPosition = this.flagNames[flagName]; + + // ensure we have a boolean + onoff = onoff ? 1 : 0; + // clear the bit in the bitmask, so we can replace it with the provided value + const clearMask = ~(1<=0 ? result % 255 : 255+result+1; // overflow if positive, underflow if negative + // write result and flags + if(operand!=6) { // don't write result of cmp + this.registers[dest] = result; + } + if(opcode==7) { // move instruction: don't affect flags + return; + } + this.setFlag("zero",result==0); + this.setFlag("negative",getBit(result,7)); + if(opcode==2||opcode==3) { // logic instruction: only zero and negative flag are touched + return; + } + this.setFlag("carry", result>255||result<0); + op1_sign = this.getBit(operand_1,7); + op2_sign = this.getBit(operand_2,7); + result_sign = this.getBit(result,7); + this.setFlag("overflow",~(op1_sign^op2_sign) && (op1_sign^result_sign)); // sets flag if two inputs have same sign but output has different + } + + // load a new program into memory and reset the processor + loadProgram(bytecode) { + reset(); + this.memory.splice(0,bytecode.length, ...bytecode); + freeze(); + } + // FETCH STAGE: load instruction from memory and increment PC + fetch(stage=0) { + if (stage=0) + this.instructionRegister = this.memory[this.programCounter]<<8; + else + this.instructionRegister += this.memory[this.programCounter]; + this.programCounter = (this.programCounter+1)%65535; + } + execute() { + instruction = this.instructionRegister; + opcode = instruction>>12; + addressingMode = this.getBit(instruction, 4); // 0 = from reg, 1 = immediate + operand_1 = (instruction>>8)&0x7 // extract operand 1 + operand_2 = instruction&0xFF // extract second byte + if(!addressingMode) { // not immediate data - load from register instead + operand_2 = this.registers[operand_2>>5]; + } + if(opcode<8) { // this means ALU INSTRUCTION + this.ALU(opcode,operand_1,operand_2); + } else { + data_address = this.regNames["data_page"]<<8+operand_2; + branch_address = this.regNames["instruction_page"]<<8+operand_2; + stack_pointer = this.stack_page+this.regNames["stack_pointer"]; + + switch(opcode){ + case 8: // load + this.registers[operand_1] = this.memory[data_address]; + break; + case 9: //store + this.memory[data_address] = this.registers[operand_1]; + break; + case 10: // stack + if(!addressingMode){ // push + this.memory[stack_pointer] = this.registers[operand_1]; + this.regNames["stack_pointer"] -= 1; + if(this.regNames["stack_pointer"]<0) + this.regNames["stack_pointer"]=255; + } else { // pop + this.registers[operand_1]=this.memory[stack_pointer]; + this.regNames["stack_pointer"]=(this.regNames["stack_pointer"]+1)%256 + } + break; + case 11: // beqz + if(this.getFlag("zero")) + this.programCounter = branch_address; + break; + case 12: // bneg + if(this.getFlag("negative")) + this.programCounter = branch_address; + break; + case 13: // binput + if(this.getFlag("input")) + this.programCounter = branch_address; + break; + case 14: + if(this.getFlag("overflow")) + this.programCounter = branch_address; + break; + case 15: + this.programCounter = branch_address; + break; + + + } + } + + } + + cycle(instructionStep=false) { + if(this.state==0||instructionStep) + this.fetch(0); + if(this.state==1||instructionStep) + this.fetch(1); + if(this.state==2||instructionStep) + this.execute(); + this.state = instructionStep ? 0 :(this.state+1)%3; + } + +} diff --git a/uncheat/index.html b/uncheat/index.html new file mode 100755 index 0000000..2ac25d0 --- /dev/null +++ b/uncheat/index.html @@ -0,0 +1 @@ +