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

ZCPU VM now self-aware like GPU and SPU VMs are #53

Merged
merged 1 commit into from
May 17, 2024
Merged
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
1 change: 1 addition & 0 deletions lua/entities/gmod_wire_cpu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
-- Create virtual machine
self.VM = CPULib.VirtualMachine()
self.VM.SerialNo = CPULib.GenerateSN("CPU")
self.VM.Entity = self
-- Since the device supports (quota)interruptible instructions
-- Memory access can be a lot cheaper.
self.VM.MemoryReadCycles = 2
Expand Down Expand Up @@ -69,7 +70,7 @@
if result then return true
else VM:Interrupt(10,-Address-1) return false
end
else VM:Interrupt(8,Address+1) return false

Check warning on line 73 in lua/entities/gmod_wire_cpu.lua

View workflow job for this annotation

GitHub Actions / lint

"Whitespace style"

Style: Please put some whitespace before the operator
end
else return true
end
Expand All @@ -96,7 +97,7 @@
if isnumber(result) then return result
else VM:Interrupt(10,-Address-1) return
end
else VM:Interrupt(8,Address+1) return

Check warning on line 100 in lua/entities/gmod_wire_cpu.lua

View workflow job for this annotation

GitHub Actions / lint

"Whitespace style"

Style: Please put some whitespace before the operator
end
else return 0
end
Expand Down Expand Up @@ -159,14 +160,14 @@

-- Calculate time-related variables
local CurrentTime = CurTime()
local DeltaTime = math.min(1/30,CurrentTime - (self.PreviousTime or 0))

Check warning on line 163 in lua/entities/gmod_wire_cpu.lua

View workflow job for this annotation

GitHub Actions / lint

"Whitespace style"

Style: Please put some whitespace before the operator
self.PreviousTime = CurrentTime

-- Check if need to run till specific instruction
if self.BreakpointInstructions then
self.VM.TimerDT = DeltaTime
self.VM.CPUIF = self
self.VM:Step(8,function(self)

Check warning on line 170 in lua/entities/gmod_wire_cpu.lua

View workflow job for this annotation

GitHub Actions / lint

"Shadowing"

Variable 'self' shadows existing binding, defined at line 157, column 10
-- self:Emit("VM.IP = "..(self.PrecompileIP or 0))
-- self:Emit("VM.XEIP = "..(self.PrecompileTrueXEIP or 0))

Expand Down Expand Up @@ -195,10 +196,10 @@
self.VM.CPUIF = nil
else
-- How many steps VM must make to keep up with execution
local Cycles = math.max(1,math.floor(self.Frequency*DeltaTime*0.5))

Check warning on line 199 in lua/entities/gmod_wire_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 199 in lua/entities/gmod_wire_cpu.lua

View workflow job for this annotation

GitHub Actions / lint

"Whitespace style"

Style: Please put some whitespace before the operator
self.VM.TimerDT = (DeltaTime/Cycles)

Check warning on line 200 in lua/entities/gmod_wire_cpu.lua

View workflow job for this annotation

GitHub Actions / lint

"Whitespace style"

Style: Please put some whitespace before the operator

while (Cycles > 0) and (self.Clk) and (not self.VMStopped) and (self.VM.Idle == 0) do

Check warning on line 202 in lua/entities/gmod_wire_cpu.lua

View workflow job for this annotation

GitHub Actions / lint

"Unnecessary parentheses"

Unnecessary parentheses
-- Run VM step
self.VM.QuotaSupported = true
local previousTMR = self.VM.TMR
Expand Down Expand Up @@ -242,7 +243,7 @@
end

function ENT:SetCPUName(name)
local overlayStr = ""

Check warning on line 246 in lua/entities/gmod_wire_cpu.lua

View workflow job for this annotation

GitHub Actions / lint

"Unused variable"

Unused variable: overlayStr
local a = math.floor(self.VM.SerialNo / 100000)
local b = math.floor(self.VM.SerialNo % 100000)
if name and (name ~= "") then
Expand Down Expand Up @@ -313,7 +314,7 @@
Wire_TriggerOutput(self, "Error", 0)
elseif iname == "Interrupt" then
if (value >= 32) and (value < 256) then
if (self.Clk and not self.VMStopped) then self.VM:ExternalInterrupt(math.floor(value)) end

Check warning on line 317 in lua/entities/gmod_wire_cpu.lua

View workflow job for this annotation

GitHub Actions / lint

"Double if-statement"

Double if statement. Please combine the condition of this if statement with that of the outer if statement using `and`.
end
end
end
Expand Down
Loading