-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
DerelictDrone
committed
Nov 15, 2023
1 parent
61c5fc2
commit 24e0f0a
Showing
8 changed files
with
448 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
CPUTest = {} | ||
|
||
function CPUTest:RunTest(VM,TestSuite) | ||
CPUTest.VM = VM | ||
CPUTest.TestSuite = TestSuite | ||
TestSuite.Compile("x: INC R0 JMP x",nil,CPUTest.RunCPU,CPUTest.CompileError) | ||
end | ||
|
||
function CPUTest.RunCPU() | ||
CPUTest.TestSuite.FlashData(CPUTest.VM,CPUTest.TestSuite.GetCompileBuffer()) -- upload compiled to virtual cpu | ||
CPUTest.VM.Clk = 1 | ||
for i=0,4096 do | ||
CPUTest.VM:RunStep() | ||
end | ||
-- False = no error, True = error | ||
if CPUTest.VM.R0 == 4096 then | ||
CPUTest.TestSuite.FinishTest(false) | ||
else | ||
print("R0 is not 4096! R0 is "..tostring(CPUTest.VM.R0)) | ||
CPUTest.TestSuite.FinishTest(true) | ||
end | ||
end | ||
|
||
function CPUTest.CompileError() | ||
print('hit a compile time error') | ||
CPUTest.TestSuite.FinishTest(true) | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
CPUTest = {} | ||
|
||
function CPUTest:RunTest(VM,TestSuite) | ||
CPUTest.VM = VM | ||
CPUTest.TestSuite = TestSuite | ||
TestSuite.Compile("MOV R0,",nil,CPUTest.RunCPU,CPUTest.CompileError) | ||
end | ||
|
||
function CPUTest.RunCPU() | ||
print('Compiler did not error when it should have!') | ||
CPUTest.TestSuite.FinishTest(true) | ||
end | ||
|
||
function CPUTest.CompileError() | ||
CPUTest.TestSuite.FinishTest(false) | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
CPUTest = {} | ||
|
||
function CPUTest:RunTest(VM,TestSuite) | ||
CPUTest.VM = VM | ||
CPUTest.TestSuite = TestSuite | ||
TestSuite.Compile("x: INC R0 JMP x",nil,CPUTest.RunCPU,CPUTest.CompileError) | ||
end | ||
|
||
function CPUTest.RunCPU() | ||
CPUTest.TestSuite.FlashData(CPUTest.VM,CPUTest.TestSuite.GetCompileBuffer()) -- upload compiled to virtual cpu | ||
CPUTest.VM.Clk = 1 | ||
for i=0,4096 do | ||
CPUTest.VM:RunStep() | ||
end | ||
-- False = no error, True = error | ||
if CPUTest.VM.R0 == 4095 then | ||
CPUTest.TestSuite.FinishTest(false) | ||
else | ||
print("R0 is not 4095! R0 is "..tostring(CPUTest.VM.R0)) | ||
CPUTest.TestSuite.FinishTest(true) | ||
end | ||
end | ||
|
||
function CPUTest.CompileError() | ||
print('hit a compile time error') | ||
CPUTest.TestSuite.FinishTest(true) | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
CPUTest = {} | ||
|
||
function CPUTest:RunTest(VM,TestSuite) | ||
CPUTest.VM = VM | ||
CPUTest.TestSuite = TestSuite | ||
TestSuite.Compile("MOV PORT0,1 MOV R0,PORT0",nil,CPUTest.RunCPU,CPUTest.CompileError) | ||
end | ||
|
||
function CPUTest.RunCPU() | ||
CPUTest.TestSuite.FlashData(CPUTest.VM,CPUTest.TestSuite.GetCompileBuffer()) -- upload compiled to virtual cpu | ||
local IOBus = CPUTest.TestSuite.CreateVirtualIOBus(4) -- get external IO device of size 4 | ||
CPUTest.TestSuite.Initialize(CPUTest.VM,nil,IOBus) -- reinitialize the CPU with the IOBus | ||
IOBus.InPorts[0] = 24 | ||
CPUTest.VM.Clk = 1 | ||
for i=0,16 do | ||
CPUTest.VM:RunStep() | ||
end | ||
|
||
-- False = no error, True = error | ||
if IOBus:ReadCell(0) == 24 then | ||
if IOBus.OutPorts[0] == 1 then | ||
if CPUTest.VM.R0 == 24 then | ||
CPUTest.TestSuite.FinishTest(false) | ||
else | ||
print("CPU failed to read input port! R0 = "..CPUTest.VM.R0) | ||
CPUTest.TestSuite.FinishTest(true) | ||
end | ||
else | ||
print("CPU failed to write to output port! Port0 = "..IOBus.OutPorts[0]) | ||
end | ||
else | ||
print("CPU wrote to input ports! "..tostring(IOBus:ReadCell(0))) | ||
CPUTest.TestSuite.FinishTest(true) | ||
end | ||
end | ||
|
||
function CPUTest.CompileError() | ||
print('hit a compile time error') | ||
CPUTest.TestSuite.FinishTest(true) | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
CPUTest = {} | ||
|
||
function CPUTest:RunTest(VM,TestSuite) | ||
CPUTest.VM = VM | ||
CPUTest.TestSuite = TestSuite | ||
TestSuite.Compile("CPUGET R0,43 MOV [R0],1 MOV R1,[R0]",nil,CPUTest.RunCPU,CPUTest.CompileError) | ||
end | ||
|
||
function CPUTest.RunCPU() | ||
CPUTest.TestSuite.FlashData(CPUTest.VM,CPUTest.TestSuite.GetCompileBuffer()) -- upload compiled to virtual cpu | ||
local bus = CPUTest.TestSuite.CreateVirtualMemBus(4) -- get external ram device of size 4 | ||
CPUTest.TestSuite.Initialize(CPUTest.VM,bus,nil) -- reinitialize the CPU with the membus | ||
CPUTest.VM.Clk = 1 | ||
for i=0,16 do | ||
CPUTest.VM:RunStep() | ||
end | ||
|
||
-- False = no error, True = error | ||
if bus:ReadCell(0) == 1 then | ||
if CPUTest.VM.R1 == 1 then | ||
CPUTest.TestSuite.FinishTest(false) | ||
else | ||
print('CPU failed to read the bus! R1 was '..tostring(CPUTest.VM.R1)) | ||
CPUTest.TestSuite.FinishTest(true) | ||
end | ||
else | ||
print("CPU failed to write to bus! "..tostring(bus:ReadCell(0))) | ||
CPUTest.TestSuite.FinishTest(true) | ||
end | ||
end | ||
|
||
function CPUTest.CompileError() | ||
print('hit a compile time error') | ||
CPUTest.TestSuite.FinishTest(true) | ||
end | ||
|
Oops, something went wrong.