Showing posts with label lesson. Show all posts
Showing posts with label lesson. Show all posts

Sunday, May 21, 2017

SBTCVM: now with a custom command shell

SBTCVM Command Shell


To run it, just start MK2-CS.py in a terminal.
When it first starts. it waits for libraries to load, prints its version string, then says its ready, prompting the user with a ":".

it has various uses. From working with SBTCVM utilities, to translating a balanced ternary integer to decimal.

naturally, the first thing a new SBTCVM user would be wise to do is type "help". doing this will spit out a few lists of commands like this:

:help
Commands:
run [arguments] : SBTCVM command line launcher. use "run help" for help.
asm [arguments] : SBTCVM assembler. "asm help" for help.
gfx [arguments] : SBTCVM graphics toolkit. use "asm help" for help.
list [type]     : use "list help" for help on the list command.
help            : this text
version         : version info
about           : about info
quit            : quit SBTCVM command shell

math commands:
add    : add two balanced ternary integers (separated by a space)
sub    : subtract two balanced ternary integers (separated by a space)
div    : divide two balanced ternary integers (separated by a space)
mul    : multiply two balanced ternary integers (separated by a space)
btdec  : convert a balanced ternary integer to decimal
decbt  : convert a decimal integer to balanced ternary
invert : invert a balanced ternary integer
mpi    : calculate the Max Positive Integer for a given number of trits
mcv    : calculate the Max Combinations Value for a given number of trits



Interesting eh? those math commands mainly expose the underlying libbaltcalc integer mathematics API as various commands. also some more specialized functions are available. such as the MPI and MCV commands:

:mpi 9
9841

:mcv 9
19683










you might also have noticed the run, asm, and gfx commands. these call MK2-RUN.py, SBTCVM-asm2.py, and MK2-GFX.py respectively. You can use the same exact arguments that those utilities use:
asm -t thisisanexample
would assemble  thisisanexample.tasm and create an apropiate tracelog just like:
./SBTCVM-asm2.py -t thisisanexample

also there is the list command. it can help when trying to see what files of a specific type are available. for example:

:list streg
VMSYSTEM/ROMS/fib.streg
VMSYSTEM/ROMS/gtt.streg
VMSYSTEM/ROMS/flower.streg
VMSYSTEM/ROMS/dazzle.streg
VMSYSTEM/ROMS/colmap3.streg
VMSYSTEM/ROMS/intro.streg


Saturday, May 20, 2017

SBTCVM: Working with SBTCVM assembly

Working with SBTCVM assembly.

Guess That Trit - Game
OK. so SBTCVM is a balanced ternary virtual machine with an
oddball
 
assembly language. How hard is it?

(note: if you want to try the tutorial in this post, make sure you have SBTCVM installed. you can get it here. SBTCVM requires python and pygame as well.)

hello world:
textstart
Hello World
textstop

That wasn't hard was it?
Ok. so the other 99.9% of use cases are not that simple.


The assembler does have these nifty address references.
for example: the goto reference pointer (or "pointer" for short):
null|000000000|foobar
(some commands...)
(this data-based goto is pointed to that "pointer")
gotodata|>foobar
this is a basic loop. Basically whatever "(some commands...)" is, is looped. and it doesn't matter where the pointer is in the resulting ROM, as the assembler automatically calculates that for you.

there are also similar, but predefined, IObus references:
IOread1|>random
IOwrite1|>mem1
This example reads from the random integer port, and writes that random integer to scratch memory point 1 (the scratch memory ranges from mem1 to mem729)

Lets look at how the Fibonacci demo works: