Documentation

Introduction

Bscript is a programming language that compiles to binary. It is designed to be easy to learn and use, and to be a good first language for beginners. It is also designed to be a good language for teaching computer science concepts, such as how computers work, how programming languages work, and how to write compilers.

Why Bscript?

Bscript it supports variables, no more writing registry adresses manually like in Bssembly. There are also quality of life improvements to locations and jumping.

Specs

Regestries: 256
RAM: 4096 Bytes (Adjustable)
ROM: Infinite
Screen: 256x256 = 65536 Pixels
Colors: 24 bits

Datatypes

Variables

var foo = 34
var bar = 35
var foobar = 0
foobar = foo + bar
out(foobar); -> 69

Functions

var foo = 0
inc(foo)
out(foo); -> 1

Jumping and locations

var index = 0
loc:start
inc(index)
lth(index, 10, to:start)
out(index); -> 10

RAM manipulation

var foo = 0
put16(foo, 100u16)
inc(foo)
ret16(100u16, foo)
out(foo); -> 0

16bit locations

Two 8bit registers represented by a single variable.

var foo:u16 = 256u16
var bar:u16 = 1024
var baz = 0
put16(69, foo)
ret16(256u16, baz)
out(baz); -> 69
out16(bar); -> 1024

Playing sound

Use 5 different waves to make noises.

snd(0, 1, 2, 10);square
snd(1, 1, 2, 10);sawtooth
snd(2, 1, 2, 10);triangle
snd(3, 1, 2, 10);noise
snd(4, 1, 2, 10);sine

Overclock

Overclock runs instructions in a while loop until it reaches a syn and renders a frame. If it reaches the max steps of 20000, it will exit the loop and render a potentially incomplete frame and then continue where it left off. This is to prevent the browser tab from freezing in an infinite while loop.

Conditionals

Conditionals work differently for 8-bit and 16-bit instructions. The 8-bit ones are all conditional jumps, while the 16-bit ones write their result as a boolean value.

lth(0, 1, to:start); jumps to loc:start if a is less than b
lth16(4, 2, flag); stores the boolean result of if a is less than b in the flag variable
eql(flag, 1, to:start); then if you need to jump just compare the flag with 1

Memory

The compiled binary lives in RAM starting at address 0, so runtime data must go above the binary size, which isn't known until you compile. Keep data in RAM above ~1KB (or packing it at the top near 4095) to avoid overwriting the code.

Instructions

Instructions are the building blocks of Bscript and Bssembly. They are the commands that the computer executes. There are 59 instructions, each with a unique number. The instructions are listed below.