This is a C# wrapper for the SAL-8 C99 implementation, an interpreted 8-bit simple assembly-like language.
For more details, see the SAL-8 repository.
The wrapper is already documented (see the source file). Here's an example showcasing most of the wrapper functionality:
using SAL8;
...
static void Main(string[] args) {
try
{
string src = File.ReadAllText("script.sal8");
Compiler compiler = new Compiler();
Cluster cl = compiler.Compile(src);
VM vm = new VM();
vm.Load(cl);
vm.Run(); // Runs all instructions. You can also run a limited number of them like this:
/* while(!vm.Finished())
* vm.Run(1); // One at a time. You can do anything between the runs.
*
* // To get the index of the first instruction that will be executed next time you call Run(),
* // use the vm.GetCurrentInstructionIndex() function. You can combine this with Run(1) to create
* // a simple step-by-step debugging feature for your game/project.
*/
// Outputs the values of all registers.
for(byte i = 0; i < vm.GetRegisterCount(); ++i)
Console.WriteLine("R" + i + " " + vm.GetRegisterValue(i));
// Outputs the value of the CMP register.
Console.WriteLine("\nCMP " + vm.GetCmpRegisterValue() + "\n");
// Outputs the whole stack.
for(byte i = (byte)(vm.GetStackCapacity() - 1); ; --i)
{
Console.WriteLine("S" + i + " " + vm.GetStackValue(i));
if(i == 0)
break;
}
// Important: after you're done using the Cluster object, destroy it.
cl.Destroy();
}
catch(CompileTimeException)
{
// Compile time error
}
catch(RuntimeException)
{
// Runtime error
}
catch(Exception ex)
{
// Something else
}
}
...
This project was created by The Exom Developers. It is licensed under the MIT license.