Skip to content

coolDudeRude/stackvm-xonotic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Stack Based Virtual Machine

Building

Requires GNU m4

To build the script, simply run make in the project directory:

git clone https://github.com/coolDudeRude/stackvm-xonotic
cd stackvm-xonotic && make

Examples

Some sample programs are included in the examples folder. These use DPI (Dynamic Programming Interface). This allows users to write programs in game. However it can be very slow. There is also an assembler for the virtual machine (See: vasm)

About programs in examples folder

  • mainloader.cfg: Sits at the top of the program, loads the main function.
  • math.cfg: Primitive math library containing basic functions.
  • main.cfg: Example program that tests math.cfg functionality.

Running the example program

First copy the examples folder and stackvm.cfg script to your userdir. Then run these command in Xonotic's console:

// This should load the vm and the example program
exec stackvm.cfg
exec examples/main.cfg

To start program execution run:

vm.run

Debugging

There is no proper debugging interface yet, but you can combine vm.step with the aliases defined below to debug your scripts.

Use vm.step to step through each instruction and use peek and poke aliases to retrieve and change values of local and global variables.

// Retrieve local and global variable value
alias peek_l "load_l \"${1 !}\"; dot"
alias peek_g "load_g \"${1 !}\"; dot"

// Set local and global variable value
alias poke_l "push \"${2 !}\"; store_l \"${1 !}\"; echo \"${1} <- ${2}\""
alias poke_g "push \"${2 !}\"; store_g \"${1 !}\"; echo \"${1} <- ${2}\""

Suggested Reads

About

Stack based virtual machine implemented using Xonotic's RPN command and console tricks.

Resources

License

Stars

Watchers

Forks

Contributors