add ram bricks
This commit is contained in:
parent
5ae87d926c
commit
10462e5a6e
Binary file not shown.
@ -167,6 +167,8 @@ enum GateFuncs {
|
|||||||
GateFunc_Rom12x32,
|
GateFunc_Rom12x32,
|
||||||
GateFunc_Rom12x48,
|
GateFunc_Rom12x48,
|
||||||
GateFunc_Rom12x64,
|
GateFunc_Rom12x64,
|
||||||
|
GateFunc_Ram8x8,
|
||||||
|
GateFunc_Ram8x12,
|
||||||
};
|
};
|
||||||
|
|
||||||
GATEFUNC(Diode) { setport(2, getport(1)); }
|
GATEFUNC(Diode) { setport(2, getport(1)); }
|
||||||
@ -334,6 +336,8 @@ GATEFUNC(Rom12x16) { if(getport(29)) { int a = getword(12, 1); for(int i=0; i<16
|
|||||||
GATEFUNC(Rom12x32) { if(getport(45)) { int a = getword(12, 1); for(int i=0; i<32; i++) { setport(13+i, getdata(a + i*4096)); } } else { clearword(32, 13); } }
|
GATEFUNC(Rom12x32) { if(getport(45)) { int a = getword(12, 1); for(int i=0; i<32; i++) { setport(13+i, getdata(a + i*4096)); } } else { clearword(32, 13); } }
|
||||||
GATEFUNC(Rom12x48) { if(getport(61)) { int a = getword(12, 1); for(int i=0; i<48; i++) { setport(13+i, getdata(a + i*4096)); } } else { clearword(48, 13); } }
|
GATEFUNC(Rom12x48) { if(getport(61)) { int a = getword(12, 1); for(int i=0; i<48; i++) { setport(13+i, getdata(a + i*4096)); } } else { clearword(48, 13); } }
|
||||||
GATEFUNC(Rom12x64) { if(getport(77)) { int a = getword(12, 1); for(int i=0; i<64; i++) { setport(13+i, getdata(a + i*4096)); } } else { clearword(64, 13); } }
|
GATEFUNC(Rom12x64) { if(getport(77)) { int a = getword(12, 1); for(int i=0; i<64; i++) { setport(13+i, getdata(a + i*4096)); } } else { clearword(64, 13); } }
|
||||||
|
GATEFUNC(Ram8x8) { if(getport(25)) { setword(8, 9, getdata(getword(8, 17))); } else { clearword(8, 9); } if(getport(26)) { setdata(getword(8, 17), getword(8, 1)); } }
|
||||||
|
GATEFUNC(Ram8x12) { if(getport(29)) { setword(8, 9, getdata(getword(12, 17))); } else { clearword(8, 9); } if(getport(30)) { setdata(getword(12, 17), getword(8, 1)); } }
|
||||||
|
|
||||||
GateFunc sim_logic_functions[] = {
|
GateFunc sim_logic_functions[] = {
|
||||||
0,
|
0,
|
||||||
@ -502,5 +506,7 @@ GateFunc sim_logic_functions[] = {
|
|||||||
GATEFUNCID(Rom12x32),
|
GATEFUNCID(Rom12x32),
|
||||||
GATEFUNCID(Rom12x48),
|
GATEFUNCID(Rom12x48),
|
||||||
GATEFUNCID(Rom12x64),
|
GATEFUNCID(Rom12x64),
|
||||||
|
GATEFUNCID(Ram8x8),
|
||||||
|
GATEFUNCID(Ram8x12),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -306,6 +306,8 @@ cFuncsByName = {
|
|||||||
["rom 64x64x32"] = 163,
|
["rom 64x64x32"] = 163,
|
||||||
["rom 64x64x48"] = 164,
|
["rom 64x64x48"] = 164,
|
||||||
["rom 64x64x64"] = 165,
|
["rom 64x64x64"] = 165,
|
||||||
|
["ram 256 b"] = 166,
|
||||||
|
["ram 4 kb"] = 167,
|
||||||
}
|
}
|
||||||
|
|
||||||
cDataSizeByName = {
|
cDataSizeByName = {
|
||||||
@ -364,4 +366,6 @@ cDataSizeByName = {
|
|||||||
["rom 64x64x32"] = 131072,
|
["rom 64x64x32"] = 131072,
|
||||||
["rom 64x64x48"] = 196608,
|
["rom 64x64x48"] = 196608,
|
||||||
["rom 64x64x64"] = 262144,
|
["rom 64x64x64"] = 262144,
|
||||||
|
["ram 256 b"] = 256,
|
||||||
|
["ram 4 kb"] = 4096,
|
||||||
}
|
}
|
||||||
|
31849
sim/dump.txt
31849
sim/dump.txt
File diff suppressed because it is too large
Load Diff
@ -67,6 +67,10 @@ local function exportGates(gates)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function log2(n) return math.log(n)/math.log(2) end
|
local function log2(n) return math.log(n)/math.log(2) end
|
||||||
|
local function sizestrFromAddrwS(w) return ({"2 ", "4 ", "8 ", "16 ", "32 ", "64 ", "128 ", "256 ", "512 ", "1 K", "2 K", "4 K", "8 K", "16 K", "32 K", "64 K"})[w] end
|
||||||
|
local function sizestrFromAddrw(w) sizeFromAddrWS(w):gsub(" ", "") end
|
||||||
|
local function bwFromN(n) return ({"B", "W", nil, "DW"})[n/8] or error("invalid size "..n) end
|
||||||
|
|
||||||
local function createEnabler(n) return { name = "Enabler"..n, names = {"Enabler " ..n.." Bit", "Enabler " ..n.." Bit Up", "Enabler " ..n.." Bit Down"}, func = "if(getport("..(n*2+1)..")) { copyword("..n..", 1, "..(n+1).."); } else { clearword("..n..", "..(n+1).."); }" } end
|
local function createEnabler(n) return { name = "Enabler"..n, names = {"Enabler " ..n.." Bit", "Enabler " ..n.." Bit Up", "Enabler " ..n.." Bit Down"}, func = "if(getport("..(n*2+1)..")) { copyword("..n..", 1, "..(n+1).."); } else { clearword("..n..", "..(n+1).."); }" } end
|
||||||
local function createBuffer (n) return { name = "Buffer" ..n, names = {"Buffer " ..n.." Bit", "Buffer " ..n.." Bit Up", "Buffer " ..n.." Bit Down"}, func = "if(getport("..(n*2+1)..")) { copyword("..n..", 1, "..(n+1).."); } else { clearword("..n..", "..(n+1).."); }" } end
|
local function createBuffer (n) return { name = "Buffer" ..n, names = {"Buffer " ..n.." Bit", "Buffer " ..n.." Bit Up", "Buffer " ..n.." Bit Down"}, func = "if(getport("..(n*2+1)..")) { copyword("..n..", 1, "..(n+1).."); } else { clearword("..n..", "..(n+1).."); }" } end
|
||||||
local function createDFF (n) return { name = "DFF" ..n, names = {"D FlipFlop " ..n.." Bit", "D FlipFlop " ..n.." Bit Up", "D FlipFlop " ..n.." Bit Down"}, func = "if(getport("..(n*2+1)..")) { copyword("..n..", 1, "..(n+1).."); }" } end
|
local function createDFF (n) return { name = "DFF" ..n, names = {"D FlipFlop " ..n.." Bit", "D FlipFlop " ..n.." Bit Up", "D FlipFlop " ..n.." Bit Down"}, func = "if(getport("..(n*2+1)..")) { copyword("..n..", 1, "..(n+1).."); }" } end
|
||||||
@ -75,7 +79,16 @@ local function createDemux(n) return { name = "Demux"..n, names = {"Demux "..n..
|
|||||||
local function createRom(x, y, z) local w = log2(x*y); return { name = "Rom"..w.."x"..z, names = {"ROM "..x.."x"..y..(z>1 and ("x"..z) or "")}, size = x*y*z, func="if(getport("..(w+z+1)..")) { int a = getword("..w..", 1); for(int i=0; i<"..z.."; i++) { setport("..(w+1).."+i, getdata(a + i*"..(x*y)..")); } } else { clearword("..z..", "..(w+1).."); }" } end
|
local function createRom(x, y, z) local w = log2(x*y); return { name = "Rom"..w.."x"..z, names = {"ROM "..x.."x"..y..(z>1 and ("x"..z) or "")}, size = x*y*z, func="if(getport("..(w+z+1)..")) { int a = getword("..w..", 1); for(int i=0; i<"..z.."; i++) { setport("..(w+1).."+i, getdata(a + i*"..(x*y)..")); } } else { clearword("..z..", "..(w+1).."); }" } end
|
||||||
local function createAdder(n) return { name = "Adder"..n, names = {"Adder "..n.." Bit"}, func = (n>=32 and "unsigned long long" or "int").." v = getword("..n..", 1) + getword("..n..", "..(n+1)..") + getport("..(n*3+1).."); setword("..n..", "..(n*2+1)..", v); setport("..(n*3+2)..", (v>>"..n..") & 1);" } end
|
local function createAdder(n) return { name = "Adder"..n, names = {"Adder "..n.." Bit"}, func = (n>=32 and "unsigned long long" or "int").." v = getword("..n..", 1) + getword("..n..", "..(n+1)..") + getport("..(n*3+1).."); setword("..n..", "..(n*2+1)..", v); setport("..(n*3+2)..", (v>>"..n..") & 1);" } end
|
||||||
local function createBinary(name, f, inv, n) local ilist = {}; for i = 1, n do table.insert(ilist, "getport("..i..")") end; return { name = name..n, names = {name:upper().." "..n.." Bit"}, func = "setport("..(n+1)..", "..inv.."("..table.concat(ilist, " "..f.." ").."));" } end
|
local function createBinary(name, f, inv, n) local ilist = {}; for i = 1, n do table.insert(ilist, "getport("..i..")") end; return { name = name..n, names = {name:upper().." "..n.." Bit"}, func = "setport("..(n+1)..", "..inv.."("..table.concat(ilist, " "..f.." ").."));" } end
|
||||||
|
local function createRam(n, w) return { name = "Ram"..n.."x"..w, names = {"RAM "..sizestrFromAddrwS(w)..bwFromN(n)}, size = math.pow(2, w), func = "if(getport("..(n*2+w+1)..")) { setword("..n..", "..(n+1)..", getdata(getword("..w..", "..(n*2+1).."))); } else { clearword("..n..", "..(n+1).."); } if(getport("..(n*2+w+2)..")) { setdata(getword("..w..", "..(n*2+1).."), getword("..n..", 1)); }" } end -- in*n out*n addr*w readclk writeclk
|
||||||
|
|
||||||
|
local binaries = {
|
||||||
|
{"And", "&&", ""},
|
||||||
|
{"Or", "||", ""},
|
||||||
|
{"Xor", "^", ""},
|
||||||
|
{"Nand", "&&", "!"},
|
||||||
|
{"Nor", "||", "!"},
|
||||||
|
{"Xnor", "^", "!"},
|
||||||
|
}
|
||||||
local romsizes = { -- copied from brick gen
|
local romsizes = { -- copied from brick gen
|
||||||
-- 1 bit data 4 bit data 8 bit data 16 bit data 32 bit data 48 bit data 64 bit data
|
-- 1 bit data 4 bit data 8 bit data 16 bit data 32 bit data 48 bit data 64 bit data
|
||||||
{ 4, 4 }, { 4, 4, 4}, { 8, 2, 8}, -- 4 bit addr
|
{ 4, 4 }, { 4, 4, 4}, { 8, 2, 8}, -- 4 bit addr
|
||||||
@ -86,13 +99,9 @@ local romsizes = { -- copied from brick gen
|
|||||||
{64, 32, 8}, {64, 32, 16}, {64, 32, 32}, {64, 32, 48}, {64, 32, 64}, -- 11 bit addr
|
{64, 32, 8}, {64, 32, 16}, {64, 32, 32}, {64, 32, 48}, {64, 32, 64}, -- 11 bit addr
|
||||||
{64, 64, 8}, {64, 64, 16}, {64, 64, 32}, {64, 64, 48}, {64, 64, 64}, -- 12 bit addr
|
{64, 64, 8}, {64, 64, 16}, {64, 64, 32}, {64, 64, 48}, {64, 64, 64}, -- 12 bit addr
|
||||||
}
|
}
|
||||||
local binaries = {
|
local ramsizes = {
|
||||||
{"And", "&&", ""},
|
{8, 8},
|
||||||
{"Or", "||", ""},
|
{8, 12},
|
||||||
{"Xor", "^", ""},
|
|
||||||
{"Nand", "&&", "!"},
|
|
||||||
{"Nor", "||", "!"},
|
|
||||||
{"Xnor", "^", "!"},
|
|
||||||
}
|
}
|
||||||
local gates = {
|
local gates = {
|
||||||
{ name = "Diode", names = {"Diode", "Diode Up", "Diode Down"}, func = "setport(2, getport(1));" },
|
{ name = "Diode", names = {"Diode", "Diode Up", "Diode Down"}, func = "setport(2, getport(1));" },
|
||||||
@ -106,5 +115,6 @@ local gates = {
|
|||||||
}
|
}
|
||||||
for _, v in ipairs(binaries) do for i = 2, 8 do table.insert(gates, createBinary(v[1], v[2], v[3], i)) end end
|
for _, v in ipairs(binaries) do for i = 2, 8 do table.insert(gates, createBinary(v[1], v[2], v[3], i)) end end
|
||||||
for i, size in ipairs(romsizes) do table.insert(gates, createRom(size[1], size[2], size[3] or 1)) end
|
for i, size in ipairs(romsizes) do table.insert(gates, createRom(size[1], size[2], size[3] or 1)) end
|
||||||
|
for i, size in ipairs(ramsizes) do table.insert(gates, createRam(size[1], size[2])) end
|
||||||
|
|
||||||
exportGates(gates)
|
exportGates(gates)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user