SmallBASIC syntax groups: 

SmallBASIC’s graphics commands use integers (2D algebra commands use reals).


  • Monochrome 0 = black, 15 = white
  • 2bit (4 colors) 0 = black, 15 = white, 1-6, 8 = dark-gray, 7, 9-14 = light-gray
  • 4bit (16 colors) 16 Standard VGA colors, 16 colors of gray (on PalmOS)
  • 8bit (256 paletted colors) 16 Standard VGA colors. The remaining colors are ignored.
  • 15bit (32K colors), 16bit (64K colors) and 24bit (1.7M colors) Color 0..15 is the standard VGA colors, full 24-bit RGB colors can be passed by using negative number.


Any point can be specified by an array of 2 elements or by 2 parameters

LINE x1, y1, x2, y2
LINE [x1, y1], [x2, y2]

Polylines also work the same way.

DIM poly(10)
poly[0] = [x, y]


The STEP keyword calculates x1, y1 parameters relative to the current
position. This applies to the following commands: RECT, PSET, LINE, CIRCLE, ARC, PAINT.

The current position can be returned using the POINT(0) and POINT(1) functions. It is set
by the x2, y2 parameters from the LINE and RECT commands and x1, y1 parameters from PSET.
The current position can also be updated using the DRAW command.

Note, “STEP” may also be used with the FOR loop statement as the incremented value each time the
loop is repeated.


The x/y factor.


The FILLED keyword fills the result of the command with the drawing color.


REM step demo.bas 2016-02-16 SmallBASIC 0.12.0 [B+=MGA]
' for STEP to work it needs a place to STEP from:
'     PSET, LINE, CIRCLE some graphic x,y pixel location
'PSET is typical start place for turtle like drawings

pset xmax/2,ymax/2 '<==pset is used here to provide STEP a relative place to STEP from
while i*sx<xmax 'once one x,y pixel reference is set you can STEP out to your hearts desire
  color 14,14
  line step sx*i,0
  color 9,9
  line step 0,sy*i
  color 12,12
  line step -1*i*sx,0
  color 11,11
  line step 0,-1*i*sy

I personally would appreciate if you will add more really SHORT & CLEAR example programs, for GRAPHICS, MATH & TRIGONOMETRY.

It's really useful for controlling industrial controllers (coding control panels as I used to do);
But the problem is that I don't have university education, not even high-school education, I didn't even graduate elementary school... what a shame.

So each SHORT example of using those functions, with a bit of elementary explanations, is really useful for me.
Once I spent a whole week reading, only to find out what is SIN and Arcsine... and how to convert radians to degrees...
it was for controlling an Iron cutting machine. it was really frustrating.

Thank you very much MGA for this SHORT & CLEAR example program.

I saw already new example codes, which include elementary explanation, for:
COS - "Trig lesson one."
SIN - "Spiral demo for SIN and COS use"

And it gives me confidence to use these functions later on. (without these examples I'm totally lost in this subject).

Positive feedback goes along way with me, plus shian you are an asset to this forum with your sharing of your experience. I worked on CNC lathes for awhile, some programming including threading. There you create 2d profiles in the round. Milling I never got to setup but I am realizing that the LOGO program sim is just like machining, you move the cutting tool from the last location to the next, setup a home (safe) position to constantly return to in between cutting or drawing jobs...

shian your examples of bit math give me confidence in an area I am clueless and inspired me to add to Language reference what I know. I request to know practical situations when bit math comes in handy, probably in programming. It is my observation if a person does not have knowledge of an area they can't see potential to use it, it supplements the saying, If you have a hammer, all the world looks like a nail.

The answer is in your question...

The Iron cutting machine works the same like a 2D CNC machine. But it's very flexible, since the program knows each moment the exact position of the cutting head. So you can stop, move manually to another position, and later continue to cut from the last position.

So you see, for moving the head in arcs and angles, rotate, scale, zoom, etc, you need good knowledge about trigonometry.
For communicating very fast with the RS-232 port (standard serial port), you should know bit manipulation. since you must encode/decode the data and the checksum of the controller. and you cannot do it slow, it must be fast using bitwise operators, otherwise, you will get time-out.

Later I will think about more handy example, other then communicating with the serial port. thanks.

REM created: 13/03/2016

' MISSION.BAS: Handy and simple bitwise demo for MGA.

' This program will encode our SmallBASIC program, using
' bitwise XOR operator, so nobody can read it when they
' return home.
' It will also decode our SmallBASIC program, using
' bitwise XOR again, so we can continue to work on it
' while everybody's sleeping.
' Note: before you run this program, please create
'       a SmallBASIC program named: "new-idea-1.bas"

Const SMALL_BASIC_FILE = "new-idea-1.bas"
Const FAKE_BACKUP_FILE = "old-stuff-1.bak"

' This is a  mask of 8 bits, because each character
' is made of 8 bits (byte):
Const CHAR_MASK = 0b10011011

' Before everybody's home, let's hide our SmallBASIC program,
' (we will continue to work on it late at night...):
Sub Hide_SB_Program
Open SMALL_BASIC_FILE For Input As #1  ' regular SB file
Open FAKE_BACKUP_FILE For Output As #2 ' encoded SB file
While Not Eof(1) Do
  normal_char = Bgetc(1) ' get 1 character from SB program
  encoded_char = (normal_char Xor CHAR_MASK) ' encode it (hide it)
  Bputc #2; encoded_char ' put 1 encoded character in encoded file
Close #1
Close #2
' OK, now that we kept our program in encoded file,
' let's delete the source code so nobody can read it:

' Now that everybody's sleeping, let's restore our SmallBASIC program,
' so we can continue to work on it:
Sub Show_SB_Program
Open FAKE_BACKUP_FILE For Input As #1  ' encoded SB file
Open SMALL_BASIC_FILE For Output As #2 ' regular SB file
While Not Eof(1) Do
  encoded_char = Bgetc(1) ' get 1 encoded character from encoded file
  normal_char = (encoded_char Xor CHAR_MASK) ' decode it (restore it)
  Bputc #2; normal_char ' put 1 decoded character in SB program

Close #1
Close #2

' Main control panel of MISSION.BAS:
Sub Main_Menu
' MGA don't like standard colors...:
Color Rgb(225, 181, 245), 0
' display the control panel for user:
Input " Choose!! HIDE or SHOW or Cancel? [H or S or C] ", menu_item
' execute the mission:
Select Case Ucase(menu_item)
Case "H" ' hide source
   Print " '" + FAKE_BACKUP_FILE + "' created successfuly. (source deleted no worries)."
   Print " You must create the file '" + SMALL_BASIC_FILE + "' first!"
  Case "S" ' show source
   Print " '" + SMALL_BASIC_FILE + "' restored successfuly. Let's go back to work!"
  Case Else ' cancel
   Print " Mission canceled by user."
  End Select

Main_Menu ' start the program


What if I have a son who knows Basic programming and is a natural born snoop!

He sees the Mission.bas file and immediately can use that and get all my private thoughts.

Couldn't the mask be a variable hooked up to a password that only I know.

I have to therefore code and decode the file with the same password that is converted into a mask.

Also I am thinking,

further pass codes might be in order because my son being a natural born snoop made a smart decision to employ his skills constructively and took a job with the CIA. I am proud he is protecting the country I was born and raised but! at the CIA, it would take him about a second to crack an 8 bit mask with one of their super computers, so I want to give my son more of a challenge.


For CIA son... hmm... you need a Cryptographic hash function. Maybe SHA-3.

Again this is some metaphysical algorithm that can only be described by ancient Egyptian glyphs. sorry...

But for daily encryption it's just fine. you can remember the mask in your head and code it each time you run MISSION.BAS.
You can also change the mask from time to time into different sequence of 0's and 1's.

I remember that a simpler encryption was used by a popular text editor for DOS.
It was good just to give a bit of privacy at work, where many people could read your work.
The point is that most people will not bother to hack a file named "AF13900F.TMP".

P.S. my father spent his entire life in the army. I'm not proud of it. Actually to see him after the war simply erased my childhood forever.

Edit: of course, to use SHA-3 you need to encrypt your BAS file as well, and then put the PC on 10KG of dynamite...

Edit 2: but it's easy to convert a password into 8-bits... an odd character will be 1, and an even character will be 0. and you can XOR and BOR the result few times as well... CRC-32 can do this task quite well, for any length of password.