@@ -45,7 +45,7 @@ if CLIENT or TESTING then
4545
4646 ---- --------------------------------------------------------------------------
4747 -- Request compiling specific sourcecode
48- function CPULib .Compile (source ,fileName ,successCallback ,errorCallback ,targetPlatform )
48+ function CPULib .Compile (source ,fileName ,successCallback ,errorCallback ,targetPlatform , sourceDirectory )
4949 -- Stop any compile/upload process that is running right now
5050 timer .Remove (" cpulib_compile" )
5151 timer .Remove (" cpulib_upload" )
@@ -72,6 +72,7 @@ if CLIENT or TESTING then
7272
7373 -- Start compiling the sourcecode
7474 HCOMP .Settings .CurrentPlatform = targetPlatform or " CPU"
75+ HCOMP .Location = sourceDirectory or HCOMP .Settings .CurrentPlatform .. " chip"
7576 print (" === HL-ZASM High Level Assembly Compiler Output ==" )
7677
7778 -- Initialize callbacks
@@ -88,10 +89,11 @@ if CLIENT or TESTING then
8889 function CPULib .SelectTab (editor ,fileName ,dontForceChange )
8990 if not editor then return end
9091 local editorType = string.lower (editor .EditorType )
91- local fullFileName = editorType .. " chip\\ " .. fileName
92-
93- if string.sub (fileName ,1 ,7 ) == editorType .. " chip" then
92+ local fullFileName
93+ if string.match (fileName ," ^" .. editor .Location ) then
9494 fullFileName = fileName
95+ else
96+ fullFileName = editor .Location .. " /" .. fileName
9597 end
9698
9799 local currentTab = editor :GetActiveTabIndex ()
@@ -143,7 +145,7 @@ if CLIENT or TESTING then
143145 end
144146
145147 editor .C .Val :Update ({{message = issue , line = line , char = char }}, nil , issue , Color (128 , 20 , 50 ))
146- end ,editor .EditorType )
148+ end ,editor .EditorType , editor . Location )
147149 end
148150
149151 ---- --------------------------------------------------------------------------
@@ -372,8 +374,12 @@ if CLIENT or TESTING then
372374 if ZCPU_Editor then
373375 -- Highlight current position
374376 local currentPosition = CPULib .Debugger .PositionByPointer [CPULib .Debugger .Variables [CPULib .Debugger .PreferredTracker or " IP" ]]
375-
376377 if currentPosition then
378+ -- Check if currentposition is even in the correct editor first, when switching editors CPULib's debugging info switches
379+ -- to the file in the new editor.
380+ if not currentPosition .File :sub (1 ,9 ):match (" cpuchip/" ) then
381+ return
382+ end
377383 -- Clear all highlighted lines
378384 for tab = 1 ,ZCPU_Editor :GetNumTabs () do
379385 ZCPU_Editor :GetEditor (tab ):ClearHighlightedLines ()
@@ -824,6 +830,128 @@ end
824830--
825831-- INT: 48-bit signed integer
826832
833+ if CLIENT then
834+ timer .Simple (1 ,function ()
835+ if E2Helper .Modes then
836+ -- If the version of wiremod is too old for E2Helper modules we should be fine since it's probably
837+ -- the one with the hardcoded ZCPU support, we just miss out on seeing extension stuff.
838+ E2Helper .Modes .ZASM = nil -- Erase existing mode
839+ CPULib .E2HelperMode = E2Helper :RegisterMode (" ZASM" )
840+ local helperModule = CPULib .E2HelperMode
841+
842+ local helperDesc = helperModule .Descriptions
843+ local helperInst = helperModule .Items
844+ helperModule .ModeSetup = function (panel )
845+ panel .FunctionColumn :SetName (" Instruction" )
846+ panel .FunctionColumn :SetWidth (126 )
847+ panel .FromColumn :SetName (" From" ) -- This can be the extension name now
848+ panel .FromColumn :SetWidth (80 )
849+ panel .TakesColumn :SetName (" Takes" )
850+ panel .TakesColumn :SetWidth (60 )
851+ panel .ReturnsColumn :SetName (" Platform" )
852+ panel .ReturnsColumn :SetWidth (60 )
853+ panel .CostColumn :SetName (" Opcode" )
854+ panel .CostColumn :SetWidth (40 )
855+ end
856+ -- Divran's instruction generator from the original e2helper implementation.
857+ local function AddCPUDesc (FuncName , Args , Desc , Platform , Type )
858+ table.insert (helperInst , { [1 ] = FuncName , [2 ] = " ZASM" , [3 ] = Args , [4 ] = Platform , [5 ] = Type })
859+ helperDesc [FuncName ] = Desc
860+ end
861+
862+ -- Add help on all opcodes
863+ for _ , instruction in ipairs (CPULib .InstructionTable ) do
864+ if (instruction .Mnemonic ~= " RESERVED" ) and
865+ (not instruction .Obsolete ) then
866+ local instructionArgs = instruction .Operand1
867+ if instruction .Operand2 ~= " " then
868+ instructionArgs = instructionArgs .. " , " .. instruction .Operand2
869+ end
870+
871+ AddCPUDesc (instruction .Mnemonic ,
872+ instructionArgs ,
873+ instruction .Reference ,
874+ instruction .Set ,
875+ instruction .Opcode )
876+ end
877+ end
878+ -- Create and destroy hooks for extended instruction support.
879+ local function helperCreateInstructionHook (indexes )
880+ for _ ,k in ipairs (indexes ) do
881+ local instr = CPULib .InstructionTable [k ]
882+ local instructionArgs = instr .Operand1
883+ if instr .Operand2 ~= " " then
884+ instructionArgs = instructionArgs .. " , " .. instr .Operand2
885+ end
886+ table.insert (helperInst ,{
887+ [1 ] = instr .Mnemonic ,
888+ [2 ] = instr .Extension ,
889+ [3 ] = instructionArgs ,
890+ [4 ] = instr .Set ,
891+ [5 ] = instr .Opcode
892+ })
893+ helperDesc [instr .Mnemonic ] = instr .Reference
894+ end
895+ end
896+ local function helperDestroyInstructionHook (indexes )
897+ for _ ,k in ipairs (indexes ) do
898+ helperDesc [helperInst [k ][1 ]] = nil
899+ helperInst [k ] = nil
900+ end
901+ end
902+ table.insert (CPULib .CreateInstructionHooks ,helperCreateInstructionHook )
903+ table.insert (CPULib .RemoveInstructionHooks ,helperDestroyInstructionHook )
904+ end
905+ end )
906+ end
907+
908+ function CPULib .SetupEditor (editor ,title ,location ,name )
909+ -- Modes support removes the original handling for the debug buttons, which are added back here.
910+ -- These were also moved a bit to make them not overlap the sound browser on the spu
911+ if E2Helper .Modes then
912+ -- Add "step forward" button
913+ local DebugForward = editor :addComponent (vgui .Create (" Button" , editor ), - 366 , 31 , - 286 , 20 )
914+ DebugForward :SetText (" Step Forward" )
915+ DebugForward .Font = " E2SmallFont"
916+ DebugForward .DoClick = function ()
917+ local currentPosition = CPULib .Debugger .PositionByPointer [CPULib .Debugger .Variables .IP ]
918+ if currentPosition then
919+ local linePointers = CPULib .Debugger .PointersByLine [currentPosition .Line .. " :" .. currentPosition .File ]
920+ if linePointers then -- Run till end of line
921+ RunConsoleCommand (" wire_cpulib_debugstep" , linePointers [2 ])
922+ else -- Run just once
923+ RunConsoleCommand (" wire_cpulib_debugstep" )
924+ end
925+ else -- Run just once
926+ RunConsoleCommand (" wire_cpulib_debugstep" )
927+ end
928+ -- Reset interrupt text
929+ CPULib .InterruptText = nil
930+ end
931+ editor .C .DebugForward = DebugForward
932+
933+ -- Add "reset" button
934+ local DebugReset = editor :addComponent (vgui .Create (" Button" , editor ), - 406 , 31 , - 366 , 20 )
935+ DebugReset :SetText (" Reset" )
936+ DebugReset .DoClick = function ()
937+ RunConsoleCommand (" wire_cpulib_debugreset" )
938+ -- Reset interrupt text
939+ CPULib .InterruptText = nil
940+ end
941+ editor .C .DebugReset = DebugReset
942+
943+ -- Add "run" button
944+ local DebugRun = editor :addComponent (vgui .Create (" Button" , editor ), - 441 , 31 , - 406 , 20 )
945+ DebugRun :SetText (" Run" )
946+ DebugRun .DoClick = function () RunConsoleCommand (" wire_cpulib_debugrun" ) end
947+ editor .C .DebugRun = DebugRun
948+ editor :Setup (title ,location ," Z" .. name )
949+ else
950+ editor :Setup (title ,location ,name )
951+ -- ZCPU will be fine without the new version, because the old version is hardcoded to support us.
952+ end
953+ end
954+
827955CPULib .InstructionTable = {}
828956local W1 ,R0 ,OB ,UB ,CB ,TR ,OL ,BL ,PR = 1 ,2 ,4 ,8 ,16 ,32 ,64 ,128 ,256
829957
@@ -849,6 +977,7 @@ local function Entry(Set,Opc,Mnemonic,Ops,Version,Flags,Op1,Op2,Reference)
849977 BlockPrefix = Bit (Flags ,BL ),
850978 PrivilegedRequester = Bit (Flags ,PR )
851979 })
980+
852981end
853982local function CPU (...) Entry (" CPU" ,... ) end
854983local function GPU (...) Entry (" GPU" ,... ) end
@@ -921,7 +1050,8 @@ function CPULib:RegisterExtension(name, extension)
9211050 OpFunc = opfunc ,
9221051 Flags = flags ,
9231052 Op1Name = " " ,
924- Op2Name = " "
1053+ Op2Name = " " ,
1054+ Description = docs .Description
9251055 }
9261056 if not docs then
9271057 instruction .Description = " Instruction " .. name .. " created by extension " .. self .Name
@@ -1002,7 +1132,10 @@ function CPULib:RebuildExtendedInstructions()
10021132 for _ ,extension in ipairs (platform ) do
10031133 for _ ,i in ipairs (self .Extensions [platname ][extension ].Instructions ) do
10041134 Entry (platname ,curOpcode ,i .Name ,i .Operands ,i .Version ,self :ParseFlagArray (i .Flags ),i .Op1Name ,i .Op2Name ,i .Description )
1005- table.insert (self .ExtendedInstructions ,# CPULib .InstructionTable )
1135+ -- Store extension name on the instruction
1136+ local lastIndex = # CPULib .InstructionTable
1137+ CPULib .InstructionTable [lastIndex ].Extension = extension
1138+ table.insert (self .ExtendedInstructions ,lastIndex )
10061139 curOpcode = curOpcode - 1
10071140 end
10081141 end
0 commit comments