Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom RAM/ROM Sizes #57

Merged
merged 4 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lua/entities/gmod_wire_cpu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,12 @@ local memoryModels = {
["flat"] = { 0, 0 },
}

function ENT:SetMemoryModel(model)
function ENT:SetMemoryModel(model,cram,crom)
if model == "custom" then
self.VM.RAMSize = math.floor(math.Clamp((tonumber(cram) or 512),0,1024))*128 -- 65536
self.VM.ROMSize = math.floor(math.Clamp((tonumber(crom) or 512),0,1024))*128 -- 65536
return
end
self.VM.RAMSize = memoryModels[model][1] or 65536
self.VM.ROMSize = memoryModels[model][2] or 65536
end
Expand Down
47 changes: 43 additions & 4 deletions lua/wire/stools/cpu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
model = "models/cheeze/wires/cpu.mdl",
filename = "",
memorymodel = "64krom",
extensions = ""
extensions = "",
customram = 0,
customrom = 0
}

if CLIENT then
Expand All @@ -46,7 +48,7 @@
if player:KeyDown(IN_SPEED) then
if (trace.Entity:IsValid()) and
(trace.Entity:GetClass() == "gmod_wire_cpu") then
trace.Entity:SetMemoryModel(self:GetClientInfo("memorymodel"))
trace.Entity:SetMemoryModel(self:GetClientInfo("memorymodel"),self:GetClientInfo("customram"),self:GetClientInfo("customrom"))
trace.Entity:FlashData({})
net.Start("CPULib.InvalidateDebugger") net.WriteUInt(0,2) net.Send(player)
end
Expand Down Expand Up @@ -75,8 +77,8 @@
net.Start("CPULib.InvalidateDebugger") net.WriteUInt(0,2) net.Send(player)
end
function TOOL:MakeEnt(ply, model, Ang, trace)
local ent = WireLib.MakeWireEnt(ply, {Class = self.WireClass, Pos=trace.HitPos, Angle=Ang, Model=model})

Check warning on line 80 in lua/wire/stools/cpu.lua

View workflow job for this annotation

GitHub Actions / lint

"Whitespace style"

Style: Please put some whitespace before the operator

Check warning on line 80 in lua/wire/stools/cpu.lua

View workflow job for this annotation

GitHub Actions / lint

"Whitespace style"

Style: Please put some whitespace before the operator

Check warning on line 80 in lua/wire/stools/cpu.lua

View workflow job for this annotation

GitHub Actions / lint

"Whitespace style"

Style: Please put some whitespace before the operator
ent:SetMemoryModel(self:GetClientInfo("memorymodel"))
ent:SetMemoryModel(self:GetClientInfo("memorymodel"),self:GetClientInfo("customram"),self:GetClientInfo("customrom"))
ent:SetExtensionLoadOrder(self:GetClientInfo("extensions"))
self:LeftClick_Update(trace)
return ent
Expand Down Expand Up @@ -138,7 +140,7 @@


----------------------------------------------------------------------------
local currentDirectory

Check warning on line 143 in lua/wire/stools/cpu.lua

View workflow job for this annotation

GitHub Actions / lint

"Unused variable"

Unused variable: currentDirectory
local FileBrowser = vgui.Create("wire_expression2_browser" , panel)
panel:AddPanel(FileBrowser)
FileBrowser:Setup("cpuchip")
Expand Down Expand Up @@ -176,12 +178,12 @@


----------------------------------------------------------------------------
local modelPanel = WireDermaExts.ModelSelect(panel, "wire_cpu_model", list.Get("Wire_gate_Models"), 2)

Check warning on line 181 in lua/wire/stools/cpu.lua

View workflow job for this annotation

GitHub Actions / lint

"Unused variable"

Unused variable: modelPanel
panel:AddControl("Label", {Text = ""})


----------------------------------------------------------------------------
panel:AddControl("ComboBox", {
local memPanel = panel:AddControl("ComboBox", {
Label = "Memory model",
Options = {
["128 bytes ROM only"] = {wire_cpu_memorymodel = "128rom"},
Expand All @@ -194,10 +196,47 @@
["8KB RAM only"] = {wire_cpu_memorymodel = "8k"},
["128KB RAM/ROM"] = {wire_cpu_memorymodel = "128krom"},
["No internal RAM/ROM"] = {wire_cpu_memorymodel = "flat"},
["Custom RAM/ROM"] = {wire_cpu_memorymodel = "custom"},
}
})
panel:AddControl("Label", {Text = "Sets the processor memory model (determines interaction with the external devices)"})
local customMemPanel = {
panel:AddControl("Label", {Text = "Custom memory size for RAM and ROM is in pages(128 bytes)"}),
panel:AddControl("Slider", {Label = "RAM size", Command = "wire_cpu_customram", Min = 0, Max = 1024}),
panel:AddControl("Slider", {Label = "ROM size", Command = "wire_cpu_customrom", Min = 0, Max = 1024}),
}
local function formatPageSizeString(pages)
if pages >= 8 then
return string.format("KB %g",pages/8) -- padding with spaces won't help because the font isn't monospaced

Check warning on line 210 in lua/wire/stools/cpu.lua

View workflow job for this annotation

GitHub Actions / lint

"Whitespace style"

Style: Please put some whitespace before the operator
else
return string.format(" B %g",pages*128)

Check warning on line 212 in lua/wire/stools/cpu.lua

View workflow job for this annotation

GitHub Actions / lint

"Whitespace style"

Style: Please put some whitespace before the operator
end
end
customMemPanel[2].OnValueChanged = function(self,pages)
self:SetText("RAM size "..formatPageSizeString(pages))

Check warning on line 216 in lua/wire/stools/cpu.lua

View workflow job for this annotation

GitHub Actions / lint

"Whitespace style"

Style: Please put some whitespace before the operator
end
customMemPanel[3].OnValueChanged = function(self,pages)
self:SetText("ROM size "..formatPageSizeString(pages))

Check warning on line 219 in lua/wire/stools/cpu.lua

View workflow job for this annotation

GitHub Actions / lint

"Whitespace style"

Style: Please put some whitespace before the operator
end

local memoryModel = GetConVar("wire_cpu_memorymodel")
function memPanel:OnSelect(index, value, data)
if data.wire_cpu_memorymodel == "custom" then
for _,i in ipairs(customMemPanel) do
i:Show()
end
else
for _,i in ipairs(customMemPanel) do
i:Hide()
end
end
-- Overriding this turns off the automatic convar write, so we have to do it ourselves.
memoryModel:SetString(data.wire_cpu_memorymodel)
-- Rebuild the layout to prevent an unsightly gap
panel:InvalidateLayout()
panel:InvalidateChildren(true)
end
memPanel:OnSelect(0,0,{wire_cpu_memorymodel = memoryModel:GetString()}) -- Simulate one on-select to correct the show/hide status
local enabledExtensionOrder = {}
local enabledExtensionLookup = {}
local extensionConvar = GetConVar("wire_cpu_extensions")
Expand Down Expand Up @@ -274,7 +313,7 @@
fontData.size = 26
surface.CreateFont( "ZCPUToolScreenFontSmall", fontData )

local function outc(text,y,color) draw.DrawText(text or "","ZCPUToolScreenFont",2,32*y,color,0) end

Check warning on line 316 in lua/wire/stools/cpu.lua

View workflow job for this annotation

GitHub Actions / lint

"Whitespace style"

Style: Please put some whitespace before the operator
local prevStateTime = RealTime()
local prevState = nil
local consoleHistory = { "", "", "", "", "", "" }
Expand Down
Loading