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

Instructions for setting the cpu error or clearing it in programs #13

Merged
merged 5 commits into from
Nov 14, 2023
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
2 changes: 2 additions & 0 deletions lua/wire/cpulib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,8 @@ CPU(137, "EXTRETP", 1, 10.00, R0, "PTBL", "", "Set PTBL,
CPU(140, "EXTRETA", 0, 11.00, R0, "", "", "Return from an external interrupt and restore R0-R31 registers")
CPU(141, "EXTRETPA", 1, 11.00, R0, "PTBL", "", "Set PTBL, then return from an external interrupt with restoring R0-R31 registers")
---- Dec 15 -- UNDEFINED ------------------------------------------------------------------------------------------------------------------------
CPU(150, "STERR", 2, 3.00, R0, "X", "Y", "Output an external error where X is error number and Y is error parameter")
CPU(151, "CLERR", 0, 1.00, R0, "", "", "Clear the external error output")
---- Dec 16 -- UNDEFINED ------------------------------------------------------------------------------------------------------------------------
---- Dec 17 -- UNDEFINED ------------------------------------------------------------------------------------------------------------------------
---- Dec 18 -- UNDEFINED ------------------------------------------------------------------------------------------------------------------------
Expand Down
7 changes: 4 additions & 3 deletions lua/wire/zvm/zvm_features.lua
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,9 @@ function ZVM:ExternalInterrupt(interruptNo)
end



function ZVM:MakeErrorCode(code,param)
return code+(param * (10^math.floor(-math.log10(math.abs(param)+1e-12)-1)))
end

--------------------------------------------------------------------------------
function ZVM:Interrupt(interruptNo,interruptParameter,isExternal,cascadeInterrupt)
Expand All @@ -660,8 +662,7 @@ function ZVM:Interrupt(interruptNo,interruptParameter,isExternal,cascadeInterrup
self.LADD = interruptParameter or self.XEIP

-- Output an error externally
local fractionalParameter = self.LADD * (10^math.floor(-math.log10(math.abs(self.LADD)+1e-12)-1))
self:SignalError(fractionalParameter+interruptNo)
self:SignalError(self:MakeErrorCode(interruptNo,self.LADD))

-- Check if interrupts handling is enabled
if self.IF == 1 then
Expand Down
8 changes: 8 additions & 0 deletions lua/wire/zvm/zvm_opcodes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1221,6 +1221,14 @@ ZVM.OpcodeTable[141] = function(self) --EXTRETPA
end


ZVM.OpcodeTable[150] = function(self) -- STERR
self:Dyn_Emit("VM:SignalError(VM:MakeErrorCode($1,$2))")
end

ZVM.OpcodeTable[151] = function(self) -- CLERR
self:Dyn_Emit("VM:SignalError(0)")
end

--------------------------------------------------------------------------------
ZVM.OpcodeTable[250] = function(self) --VADD
self:Dyn_Emit("if VM.VMODE == 2 then")
Expand Down
Loading