while im trying to get better at lua coding, i made a 1k ram with 1024 write/readable addresses
Code:
GateActions["ram1k"] = {
group = "Memory",
name = "RAM(1kb)",
inputs = { "Clk", "AddrRead", "AddrWrite", "Data", "Reset" },
output = function(gate, Clk, AddrRead, AddrWrite, Data, Reset )
if (Reset > 0) then
gate.LatchStore = {}
end
AddrRead = math.floor(tonumber(AddrRead))
AddrWrite = math.floor(tonumber(AddrWrite))
if (Clk > 0) then
if (AddrWrite < 1024) then
gate.LatchStore[AddrWrite] = Data
end
end
return gate.LatchStore[AddrRead] or 0
end,
reset = function(gate)
gate.LatchStore = {}
end,
label = function(Out, Clk, AddrRead, AddrWrite, Data, Reset )
return "WriteAddr:"..AddrWrite.." Data:"..Data.." Clock:"..Clk.." Reset:"..Reset..
"\nReadAddr:"..AddrRead.." = "..Out
end,
ReadCell = function(dummy,gate,Address)
if (Address < 0) || (Address > 1024) then
return 0
else
return gate.LatchStore[Address] or 0
end
end,
WriteCell = function(dummy,gate,Address,value)
if (Address < 0) || (Address > 1024) then
return false
else
gate.LatchStore[Address] = value
return true
end
end
}
and i also added a wire able Reset to the increment/decrement counter
Code:
GateActions["increment/decrement"] = {
group = "Arithmetic",
name = "Increment/Decrement",
inputs = { "A", "Increment", "Decrement", "Reset" },
output = function(gate, A, Increment, Decrement, Reset)
local increment = ( Increment > 0 )
local decrement = ( Decrement > 0 )
local reset = ( Reset > 0 )
if ( gate.PrevValue ~= increment ) then
gate.PrevValue = increment
if ( increment ) then
gate.Memory = (gate.Memory or 0) + A
end
end
if ( gate.PrevValue ~= decrement ) then
gate.PrevValue = decrement
if ( decrement ) then
gate.Memory = (gate.Memory or 0) - A
end
end
if ( reset ) then
gate.Memory = 0
end
return gate.Memory
end,
label = function(Out, A)
return "(" .. A .. " +/- LastNum) = " .. Out
end
}
add to the svn if possible please