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
- pointer = <>
- byte = []
- data = ()
- location (16 bit) = {}
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.
- EXT - exit
- SET - set <target> [byte]
- CLR - clear <target>
- CPY - copy <source> <target>
- ADD - add <source1> <source2> <target>
- SUB - subtract <source1> <source2> <target>
- MLT - multiply <source1> <source2> <target>
- INC - increment <source/target>
- DEC - decrement <source/target>
- JMP - jump TO:"location name"
- BMP - bitmap [width] [height] (image)
- TEX16 - texture <posx> <posy> <width> <height> {<location>}
- CLB - clear bitmap
- OUT - output <source>
- INP - input <target>
- DLY - delay <time (10x ms)>
- IPT16 - import ROM data {<source>} {<target>} {<length>}
- XPT16 - export RAM data {<source>} {<target>} {<length>}
- PUT16 - put <source> {<location>}
- RET16 - retrieve {<location>} <target>
- LOC - jump point LOC:"location name"
- EQL - equals <source1> <source2> TO:"location name"
- LTH - less than <source1> <source2> TO:"location name"
- GTH - greater than <source1> <source2> TO:"location name"
- RGB - color <red> <green> <blue>
- COL - color <source>
- LFT - line <fromx> <fromy> <tox> <toy>
- PNT - point <posx> <posy>
- BTN - is key down <keycode> <target>
- GPBTN - gamepad button value <gamepad> <buttonnr> <target>
- GPJOY - gamepad joystick axis value <gamepad> <axis> <target>
- RND - random number <min> <max> <target>
- BSL - shift left <source> <target>
- BSR - shift right <source> <target>
- TXT - draw char <posx> <posy> <ascii-char>
- TXT16 - draw string <posx> <posy> {<location>} <length>
- DLT - delta time <target>
- SYN - sync with screen refresh
- PSH - save cursor position <offset>
- POP - load cursor position
- NEQ - not equal <source1> <source2> TO:"location name"
- SIN - sinus <angle> <y>
- COS - cosinus <angle> <x>
- MPOS - mouse position <x> <y>
- MBTN - mouse position <button> <pressed>
- SND - play a sound <wave> <tone> <octave> <duration>*10ms
- SET16 - set <source1> <source2>
- CLR16 - clear {<target>}
- CPY16 - copy {<source>} {<target>}
- INC16 - increment {<source/target>}
- DEC16 - decrement {<source/target>}
- ADD16 - add {<source1>} {<source2>} {<target>}
- SUB16 - subtract {<source1>} {<source2>} {<target>}
- MLT16 - multiply {<source1>} {<source2>} {<target>}
- BSL16 - shift left {<source/target>} {<bits>}
- BSR16 - shift right {<source/target>} {<bits>}
- EQL16 - equals {<source1>} {<source2>} <target>
- NEQ16 - not equals {<source1>} {<source2>} <target>
- LTH16 - less than {<source1>} {<source2>} <target>
- GTH16 - greater than {<source1>} {<source2>} <target>
- INP16 - input {<target>}
- OUT16 - output {<source>}
- PXL - read a pixel value <x> <y> <red> <green> <blue>