Thursday, September 13, 2018

Gen 2 update: stacks n keyboards.

SBTCVM's CPU makes some progress, as the cpu is now equipped with a whopping 2 stacks. 

Along with the cpu, SBTCVM Gen 2-9 is now capable of interactive programs, thanks to a new TTY Input device, that allows for a basic serial text interface.
Aside from the usual assembly enhancements, SSTNPL has gotten its share of changes too:

  •  you can now create variables based on character code values.
  •  you can read from the tty input buffer into a variable for easy parsing of keystrokes.
  • return is now stackable.
  • separate subroutine gotos are required to use return.
  • conditional returns are now available.

Monday, August 13, 2018


SBTCVM for the longest time, only had one programming language: SBTCVM Assembly. However, with Gen 2, that's going to change. In fact, it already has.
Presenting SSTNPL:

SBTCVM Simplified Ternary Numeric Programming Language.

Overall SSTNPL isn't ultra-high-level. For example: it supports in-line assembler and its loop and branching capacity is provided by several goto instructions. 

Yea i know, the 'dreaded' goto. But SSTNPL isn't meant to be super abstracted. Its mainly meant as a lower-level language, that abstracts much of the VM's more detailed behaviors, while letting people experiment with them if they wish, and aren't ready to tackle the assembler head-on. It can also be handy for quick math algorithms.

  • built upon a named-integer variable system
  • both static, and equals, greater, and less than gotos. (goto, if, ifmore, ifless)
  • addresses and memory are handled automatically, using the assembler's builtin variable system.
  • simple, easy to follow, syntax.
  • quick formatting commands like 'space' and 'newline' paired with the new print, and dumpd/dumpt integer dump commands, make outputting algorithm results a breeze. 
For more information, check out the included example *.stnp programs and the shiny new compiler, in SBTCVM gen2-9's repository:

Thursday, July 26, 2018

Gen 2 update: 3 new additions to the assembler.

The assembler has grown a bit. Specifically, it has a header variable system, the new nsp framework, as well as the new xas framework. So... Whats all that mean?

Header Variables.

source files traditionally had no say in how they were assembled in the past, thats where header variables come in. What they do does vary, however:
assembler mode

head-mode=trom, head-mode=vars

head-mode refers to the mode of the assembler. currently there are two possible values:
  • trom: normal assembly (this mode will be chosen if head-mode is omitted.)
  • vars: don't assemble a trom, but do handle nsp if enabled. (nsp is explained later in this post.)

Rom Name

head-rname=<rom name>
: override the trom output name. (excluding extension)

SBTCVM Assembly Namespace (.nsp) files:

.nsp files allow you to use the namespace variables from one assembler source file (.tasm file) in another. here are the needed header variables to use them.

head-nspout=1: enables .nsp output for that source file. (excludes variables from other nsp files, as well as any builtin variables.

head-nspname=<nsp name>: override the nsp output name. (excluding extension)

head-nspin=<nsp name>
: Import an nsp into an assembler file's namespace. you can use this namespace variable multiple times to import multiple .nsp files.

If all this .nsp nonsense sounds complicated, rest assured that one of its main purposes is to make some things easier.

SBTCVM Assembly Script (XAS)

XAS is an assembly automation script system, that makes multi-source-file projects easy to assemble.

Its main purpose isn't so very useful yet, but once Gen 2 gets a bit further along, its going to come in very handy.

Currently it has 4 commands:

  • asm: takes name of tasm source file as argument. same as [source file]
  • print: print argument to standard output.
  • xas: run a xas script from within another xas script. takes script name as argument.
  • exit: exit. takes no arguments
to run a XAS script, just pass it as an argument to the assembler just like you would a .tasm file.

SBTCVM Gen 2-9 repository:

Tuesday, July 3, 2018

tutorials: balanced ternary basics

If you happened across SBTCVM and/or Balanced Ternary someplace, and you are wondering what the heck a trit or tryte is, you are at the right place.

Lets start with the very basics:

balanced ternary, like regular ternary (base 3), has 3 digits.

Several notations exist for balanced ternary. the one you use often is best chosen for the circumstance. For example: +0- is supported by all versions of SBTCVM, while p0n is only supported by the newer SBTCVM Gen 2-9 VM, thats still in development. 
Here is the number '8' in a few forms of balanced ternary notation:

  • Positive: (+,p) your familiar positive digit.
  • Ground: (0) ground, or zero, is in the middle. but that's not even the most confusing bit.
  • Negative: (-,n) this is the curve ball, and why 2 in balanced ternary is '+-'

still dont get it? lets count from -4 to +4

-- (nn) -4
-0 (n0) -3
-+ (np) -2
0- (0n) -1
00 (00)  0
0+ (0p)  1
+- (pn)  2
+0 (p0)  3
++ (pp)  4

here are some key terms:
  • trit: a balanced ternary digit
  • tryte: 6 balanced ternary digits
 Special note: 1093 is based on the MPI of 7 trits.
  • KiloTryte (KT): 1093 trytes.
  • Kilotrit (Kt): 1093 trits.
 Helpful equations. (SBTCVM's libbaltcalc has functions for these)
  • MPI: Max positive integer: maximum positive value a length of trits can represent. ((3^n)-1)/2=MPI where n=length of trits
  • MNI: Max negative integer: lowest value a length of trits can represent. is the opposite of MPI. 
  • MCV: Max combinations value: number of combinations in a length of trits. 3^n=MCV where n=length of trits
why is MPI, MNI, and MCV, relevant now?

 Well. thats a good question! this brings me to another point:

Balanced ternary, like other balanced base numbers, have many subtle differences form bases like binary and decimal. for example: lets compare 8 trits & 8 bits
    8 trits | 8 bits
MPI: 3280   | 255
MCV: 6561   | 256

Aside from balanced ternary knocking binary out of the park numerically, notice how with binary, the MPI and MCV equivalents are only 1 off, while in balanced ternary its 3281 off. why is this? 

ok but why are MPI and MCV so different?

well. balanced ternary, like other balanced base numbers, is inherently signed. lets look at the combinations of 1 trit:

- (n) accounts for one MPI
0 (0) zero accounts for 1
+ (p) accounts for one MPI

this can be summed up into this formula:

n=length of trits

and then:



Friday, June 29, 2018

Gen 2 update: a look at the new assembler.

SBTCVM's assembler has been with it for a long time. Since the prototype era actually. Gen 2's ground-up rebuild of the VM also brings a similar treatment to good old SBTCVM tasm.

Syntax checks:

no less than 2 syntax check passes and 1 validation pass before writing to a trom file, along with a new trom format, ensure problems with corrupt roms are unheard of in Gen 2. saving coders time and energy.

simple numeric data tweaks:
first, decimal support has been added:


second, ternary support has been overhauled:

two representations are supported:

Also, ternary values can be any arbitrary length from 1 to 9 trits.

Unified namespace:

the goto reference label, iobus address macro, and other namespaces accessed via '>' have been merged into a singular namespace, with custom variable support:

the v> prefix keyword supports all the numeric representations supported by most keywords:
They can even point to namespace entries to duplicate their value.

normal keywords can do this too:

dual data ahoy: 

Gen 2's new dual-packing concepts and the mirrored data/instruction size have been complimented by a new raw instruction:

They, of course, can be mixed numeric syntaxes.

This rock solid, modular, base of features will prove to be very useful in the coming months, as the Gen 2 instruction set and CPU development enter full swing.

Saturday, May 19, 2018

Gen 1: a retrospective

SBTCVM. Its hard to believe that mark 2 was first committed to GitHub over a year ago, but its true. In fact, SBTCVM has been in development for over 2 years. So, in light of Gen 1's codebase being retired, lets take a look at its history.

Just a quick look at Wikipedia.
The origin of mark 2 actually traces back to me going to look up something on Wikipedia, and getting lost in the maze of related articles until i stumbled across "balanced ternary".

calculations operational, sir.
On June 3rd 2016, A curious little python program poped up on github.
Its name, was BalTCalc of course. and as you might guess, its a calculator, that works in balanced ternary. This calculator needed some backend code, so i wrote libbaltcalc to go along with it. Little did i know, that one library would lead me to starting a certain project.

Demo ahoy!
September 24th 2016. I had been coding away at a rather alien project for myself, a virtual computer of sorts. TDA was just as its acronym suggests, Ternary, and a Demonstration of a computer Architecture. The code was buggy, slow, and didn't even have memory writes. but It did one thing: Show that i actually could simulate a balanced ternary computer in python, and prove libbaltcalc was indeed capable of such. Its worth noting, that what is now SBTCVM's assembler was begun partway through TDA's development because of me growing sick and tired of base 3 machine code programming.

x6 729 word (6trit) memory banks (roughly 4KT)
x1 729 word IObus
4trit instruction set

SBTCVM is born
March 9th, 2017. SBTCVM Mark 1.1 didn't change too much of TDA's code, but it did have some important improvements, most notably address calculation in SBTCVM's assembler. Mark 1.1 was also a stepping stone for a much more capable VM.

March 17, 2017. SBTCVM Mark 2 makes its presence known.
with a whopping 162 KT of combined memory. (108KT of unbroken trytes) Mark 2 is vastly superior to the Mark 1.x machines, and a worthy holder of Gen 1's final form. It introduced features that made SBTCVM vastly more useful in studying balanced ternary computing.

For one, it was the first to include a graphical calculator, the first to include framebuffered graphics, and even the first to reproduce digital sampled audio. Mark 2's set of utilities did balloon out of control in hindsight, but now we know better what tools are actually needed. and what aren't. the calculator is always handy for a quick bit of calculation after all. and yes i still have 19,683 stuck in my head. :)

162 KT of combined memory. (108KT of unbroken trytes)
27 KT of memory per bank (18KT of unbroken trytes per bank)
6 memory banks
1-trit mono and 3-trit RGB framebuffer graphics at 114x81 and 54x38
2 text modes
1-trit digital samples at 2 and 4 KHZ
3 voice square wave sound chip
hardware-thread-based multitasking
various conversion tools relating to the internal data formats.

In conclusion: 
I hope you enjoyed that short look back on SBTCVM's first generation codebase, as the SBTCVM project moves on to bigger and better things. 

SBTCVM Gen 2: on the road to alpha.

End of an era:
SBTCVM Mark 2 has been been in development for a while, and while Mark 2 has served the project well, and has taught the dev team some important things, its come to the point where Mark 2 has become too complex under the hood to make the jump to python 3 reasonably, and continue development in a orderly fashion.

Its with this, that I announce the official end-of-development for SBTCVM Mark 2, and its underlying "gen 1" codebase. Its replacement is currently being developed.

The future:
SBTCVM Generation 2 is slated to drasticly change not only how the VM works under the hood, and how its CPU works, but also how its used. With advanced features like SBTVDI, a virtual disk system and psudo-filesystem implementation that will work in tandem with a new subproject: SBTCVM DOS.

Some other features being explored are more advanced sound (like the digital sample system that was added to Mark 2 at the last minute), more interactive vm programs, and less cluttered, streamlined user interfaces. Thanks to the new modular codebase, plans exist for terminal-only, pygame, and a TK version when time allows. with the terminal version slated to be a subset of the more fleshed out TK and pygame versions.

Gen 2 is currently VERY early in development, so again, its hard to say what the exact details will be, or when it will be announced. That said, a "gen 2" status page can now be found on the blog (see the link bar above), and blog updates will be posted on major developments.

Wednesday, February 14, 2018

Documentation: new and improved helpview.

Helpview. v2.0.3's fast and easy help system just got a bit more helpful with a new search feature & glossary.

The search feature is accessed by entering keywords (separated by spaces) into the search box in the hud, then clicking the "search" button.

Helpview will search its pages and present a list of matching pages, and the number of matches on each.

But what about the glossary? well, you can read through it like a normal page, but you will probably find the integrated glossary results included in the search feature to be much more helpful.

Utilities - New Development aids: GUIasm & memory map views


For the longest time, the only way to run the assembler was by typing in a string of commands into a terminal.

Now when you open tasm files in fileview2 and fileman in run mode, GUIasm will open up and easily allow for repeat assembling with a mouse click, an automatically opening a log of assembler output upon errors. It can also be run from codeview as well.

Codeview enhancement: memory view.

When Opening troms and .dmp memory and iobus dumps in codeview, users will see a handy new memory view.

This view can be scrolled independently from the main view with w & s (or e & d for faster scrolling), or by scrolling over it with the mouse wheel. It even highlights faulty trits in red for easily knowing when somethings not quite right.

Sunday, October 15, 2017

SBTGA: SBTCVM's graphics adapter.

It happened.

SBTGA mode G0, 114x81 @ 3-trit RGB, (27 colors)
SBTCVM, for the longest time, has had no framebuffered displays. and while the 9x9 and 27x27 plotters have proved functional, the time has come.

SBTGA currently has a standby mode (default), and Graphics Mode 0 (G0, shown). While its indeed colorful, SBTGA has more features planned: such as formatted text modes, and a new, high-resolution plotter mode to replace the old 9x9 and 27x27 plotters that have proven quite useful.

Under the hood, SBTGA is SBTCVM's first complex IObus device, (unless you consider a basic psudo-random number generator or scratch memory, complex)
it works via a pointer address that points to a portion of Memory Bank A (the first memory bank), that tells SBTGA where its DMA-based framebuffer is. 

Naturally this lets programs have precomputed framebuffer memory ranges.In fact, this is the first job of the new utility (GAT meaning Graphics Adapter Toolkit): To convert 114x81 binary images, to SBTGA Mode G0 framebuffer maps.

And while for the moment, SBTGA lacks even sprites, Its a definite start to a new chapter in SBTCVM's development.

The SBTCVM Desktop

SBTCVM's central launcher and its recently added "mini tools" are now much more:

Presenting a new and upcoming part of the SBTCVM suite: The SBTCVM desktop.

Featuring a multi-windowing enviornment, with resizable windows, additional applications as plugins, and powerful builtin utilities, along with integration with SBTCVM's powerful backend. Best part is, like the rest of the SBTCVM suite, its OS-agnostic, and very portable, and powered by python and pygame.

Builtin applications (often called SDAs, or SBTCVM Desktop Applications, for short) include:
  • Shell, a shell interface used to create a veriety of CLI interfaces, such as a System Shell (center) and a math shell (right)
  • taskman, manages the various tasks that are running. (top left)
  • fileman (not shown) a compact variant of the larger fileview.
  • and more on the way.
The Plugin system also provides some applications as SDAPs (SBTCVM Desktop Application Plugin)
  • The Math shell mentioned before is implemented as an SDAP, it features the same math functions as the command shell.
  • Scribble started as a mouse coordinate test and grew into a simplistic paint program (keyword: simplistic).
  • the scrolling credits shown is a port of the same code used in the credits window accessible via the VM's file menu.
  • as with the builtin SDAs, more SDAPs are in the works.
As mentioned in the recent, "new system of things" post, Themes are supported, and several are provided, along with various backgrounds.

Thursday, September 14, 2017

new system of things - how v2.0.3 is shaping up...

The VM

First and foremost, The VM has been redesigned, like the rest of v2.0.3, it features standardized UI elements, with support for themes...

notable enhancements are the new, mouse-ready menus at the top, and the enhanced post-VMSYSHALT mode, that tries to be more helpful than waiting for the user to press enter...

Launcher & the new mini-tools.

SBTCVM v2.0.3's launcher is a far cry from v2.0.2's it features a multi-window environment of smaller tools,
such as Scribble: a sketch tool that started as a test for mouse coordinates, and even SBTCVM's scrolling credits.

Like Several of v2.0.3's utilities, launcher has also been redesigned around a resizable UI, meaning you can resize the window as you wish. Other utilities with this feature include, helpview, imageview, & codeview/textview.

SBTCVM now has support for themes, and in select utilities, different backgrounds changeable on-the-fly.

SBTCVM's new dark theme, for those who prefer darker UIs...


SBTCVM now has a unified help system. called helpview, this nifty program offers quite a bit of it.


The new Fileview program is far more useful than its v2.0.2 predecessor, featuring a redesigned UI, right-click menus, and even single, and dual pane view modes.

In Conclusion.

SBTCVM's other utilities, including the new calculator, all have been enhanced to match the new UI style, complete with drop-down menus, and theme support.

The release schedule for v2.0.3 is "when its done", but you are quite welcome to try out the latest code over on GitHub.  That aside, v2.0.3 already makes huge leaps in unifying SBTCVM's suite of utilities, as well as vastly improving the User interface side of things...

Stay tuned for more updates on SBTCVM v2.0.3!

Sunday, August 27, 2017

Utilities - calc


SBTCVM does have a command shell with mathematics functions, and a powerful integer mathematics backend, but for the longest time it hasn't included a graphical calculator. until now.

Presenting SBTCVM's newest utility:

It provides common operations like invert, mpi, mcv, the usual arithmetic operations like add, and some copy and swap operations, including the ability to either manually, or automatically copy the result to either or even both inputs.  It even features simultaneous decimal, and balanced ternary representation, with ability to enter and edit inputs in either form, with conversions handled automatically.