2023-07-24 06:50:18 -04:00
|
|
|
AddCSLuaFile()
|
2023-07-28 06:05:58 -04:00
|
|
|
DEFINE_BASECLASS("base_wire_entity")
|
2023-07-24 06:50:18 -04:00
|
|
|
ENT.PrintName = "LCPU"
|
|
|
|
ENT.Author = "Lily <3"
|
|
|
|
-- no more, this deeply uses native APIs
|
|
|
|
if CLIENT then return end
|
2023-07-28 06:05:58 -04:00
|
|
|
|
2023-07-29 01:56:19 -04:00
|
|
|
-- Include the devices which require Wiremod here
|
|
|
|
-- (hacky, but /shrug)
|
|
|
|
include("lcpu/devices/wire_interface.lua")
|
|
|
|
|
2023-07-28 06:05:58 -04:00
|
|
|
-- TODO: serverside convars to control execution rate & cycle count
|
2023-07-24 06:50:18 -04:00
|
|
|
function ENT:Initialize()
|
|
|
|
self:PhysicsInit(SOLID_VPHYSICS)
|
|
|
|
self:SetMoveType(MOVETYPE_VPHYSICS)
|
|
|
|
self:SetSolid(SOLID_VPHYSICS)
|
2023-07-28 18:12:27 -04:00
|
|
|
-- CPU callbacks?
|
|
|
|
self.cpu = LCPUNative.CreateCPU(128 * 1024)
|
|
|
|
self.uart = LCPU.Devices.UART(0x10000000)
|
2023-07-29 01:56:19 -04:00
|
|
|
self.wireInterface = LCPU.Devices.WireInterface(0x11310000, self, 8, 8)
|
2023-07-28 18:12:27 -04:00
|
|
|
self.cpu:AttachDevice(self.uart)
|
2023-07-29 01:56:19 -04:00
|
|
|
self.cpu:AttachDevice(self.wireInterface)
|
2023-07-28 06:05:58 -04:00
|
|
|
self:SetOverlayText("hi :)")
|
2023-07-24 06:50:18 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
function ENT:Think()
|
2023-07-28 06:05:58 -04:00
|
|
|
-- Avoid running if the cpu is not powered on
|
2023-07-24 20:17:07 -04:00
|
|
|
if not self.cpu:PoweredOn() then return end
|
2023-08-05 06:46:56 -04:00
|
|
|
|
|
|
|
if LCPU.cycleCount ~= self.cpu.CycleCount then
|
|
|
|
--print(string.format("bumping up cycle count to %d", LCPU.cycleCount));
|
|
|
|
self.cpu.CycleCount = LCPU.cycleCount
|
|
|
|
end
|
|
|
|
|
|
|
|
for i = 1, LCPU.tickCount do
|
|
|
|
self.cpu:Cycle()
|
|
|
|
end
|
|
|
|
|
2023-07-24 06:50:18 -04:00
|
|
|
-- Even though this is gated by tickrate I'm just trying to be nice here
|
|
|
|
self:NextThink(CurTime() + 0.1)
|
2023-07-29 01:56:19 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
function ENT:Reset()
|
|
|
|
self.cpu:Reset()
|
2023-07-28 06:05:58 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
function ENT:PowerOn()
|
|
|
|
self.cpu:PowerOn()
|
|
|
|
self:NextThink(CurTime() + 0.1)
|
2023-07-24 06:50:18 -04:00
|
|
|
end
|