diff --git a/lua/entities/gmod_wire_cpu.lua b/lua/entities/gmod_wire_cpu.lua index 853d1fa..b9b0b26 100644 --- a/lua/entities/gmod_wire_cpu.lua +++ b/lua/entities/gmod_wire_cpu.lua @@ -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 + return + end self.VM.RAMSize = memoryModels[model][1] or 65536 self.VM.ROMSize = memoryModels[model][2] or 65536 end diff --git a/lua/wire/stools/cpu.lua b/lua/wire/stools/cpu.lua index 2d0aa7e..118c89f 100644 --- a/lua/wire/stools/cpu.lua +++ b/lua/wire/stools/cpu.lua @@ -19,7 +19,9 @@ TOOL.ClientConVar = { model = "models/cheeze/wires/cpu.mdl", filename = "", memorymodel = "64krom", - extensions = "" + extensions = "", + customram = 0, + customrom = 0 } if CLIENT then @@ -46,7 +48,7 @@ if SERVER then 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 @@ -76,7 +78,7 @@ if SERVER then end function TOOL:MakeEnt(ply, model, Ang, trace) local ent = WireLib.MakeWireEnt(ply, {Class = self.WireClass, Pos=trace.HitPos, Angle=Ang, Model=model}) - 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 @@ -181,7 +183,7 @@ if CLIENT then ---------------------------------------------------------------------------- - panel:AddControl("ComboBox", { + local memPanel = panel:AddControl("ComboBox", { Label = "Memory model", Options = { ["128 bytes ROM only"] = {wire_cpu_memorymodel = "128rom"}, @@ -194,9 +196,29 @@ if CLIENT then ["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 = {}