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 1 commit
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 = (tonumber(cram) or 512)*128 -- 65536
self.VM.ROMSize = (tonumber(crom) or 512)*128 -- 65536
DerelictDrone marked this conversation as resolved.
Show resolved Hide resolved
return
end
self.VM.RAMSize = memoryModels[model][1] or 65536
self.VM.ROMSize = memoryModels[model][2] or 65536
end
Expand Down
30 changes: 26 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,9 +196,29 @@
["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 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)
end

local enabledExtensionOrder = {}
local enabledExtensionLookup = {}
Expand Down Expand Up @@ -274,7 +296,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 299 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 All @@ -283,7 +305,7 @@

local function outform(x,y,w,h,title)
surface.SetDrawColor(255, 255, 255, 255)
surface.DrawRect(x*28-3,y*32-3,w*28,h*32)

Check warning on line 308 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 308 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 308 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 308 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

surface.SetDrawColor(0, 0, 0, 255)
surface.DrawRect(x*28+3,y*32+3,w*28,h*32)
Expand Down
Loading