๐ป What is Hobby BASIC?
Hobby BASIC is a modern, structured BASIC interpreter for the classic Windows console (CMD.EXE), combining retro simplicity with ANSI graphics, UDP networking, and direct Win32 API access โ packed into a tiny ~78 KB executable written in 32-bit x86 assembly (FASM).
Key Features:
- Structured BASIC syntax with console & graphics commands
- Full keyboard & mouse input inside the Windows console
- High-compatibility ANSI X3.64/ECMA-48 terminal emulation
- Built-in array undo stacks (.PUSH / .POP), circular stack, and user-defined TYPEs
- UDP peer-to-peer networking & remote script execution over HTTP
- FPU string math & direct Win32 API / GDI calls via SYSCALL
- Standalone executable builder (-bind .BAS into .EXE)
- Maintained for 10+ years โ runs cleanly on Windows 7โ11
- Developed in 32-bit x86 Assembly language
๐ฏ 50,000+ lines of games, demos, and examples
๐ Evolving since 2015 โ tiny ~78 KB x86 assembly core
๐จ ANSI Art Studio v0.9.7 โ ANSI drawing tool built in Hobby BASIC
๐ Super Tiny BASIC v1.24 โ '80s BASIC interpreter (~900 lines, full source)
My goal has always been to create a simple, user-friendly language designed for game development within the Windows consoleโand I believe it's progressing quite well!
๐ฅ Watch the full video tour on YouTube to see Hobby BASIC in action.
๐ฆ Full Feature Overview
๐ Click to expand โ Hobby BASIC โ Full Feature Overview โผ
๐ค Language & Core
- Classic BASIC-style syntax with clean, retro-oriented structure
- Case-sensitive variables with dynamic name construction support (//)
- Labels (#) and anonymous labels (@@#, @b/@f directional jumps)
- Preprocessor directives (%INCLUDE, FIX)
- Extended operator set (arithmetic, logical, bitwise, compound, ++/--)
- Built-in constants (TRUE/FALSE, EOL$) and ENUM declarations
- Variable utilities (SET for bulk assignment, SWAP for value exchange)
๐ฎ Control Flow
- IF / THEN / ELSE conditional branching
- SELECT / CASE / ENDSEL multi-branch selection
- FOR / TO / STEP / NEXT counted loops
- WHILE / ENDW and DO / UNTIL conditional loops
- TIMES fixed-iteration loop, BREAK (exit), PASS (no-op)
- GOTO, GOSUB, RETURN for direct flow control
๐ Data Types
- 32-bit signed integers (primary numeric type)
- Mutable strings ($ suffix) with direct indexed character access
- String concatenation (+) and dynamic variable name binding (//)
- STATIC numeric variables with persistent state across calls
๐ Arrays
- 1D and 2D arrays (zero-based, type-homogeneous)
- Dynamic initialization and resizing
- Built-in array operations (SORT, SUM, MIN/MAX, MATCH, etc.)
- File and directory handling via string array methods
๐ฆ User Types
- TYPE structures with named integer/string members
- Compact and block-based declaration syntax
- Arrays of structures with optional default initialization
โ๏ธ Subroutines & Functions
- SUB / ENDS with recursion support
- DEF single-expression functions
- Pass-by-value and BYREF parameter passing
- RETS for returning integer or string values
- LOCAL scope variables (scalars, arrays, TYPE instances)
๐ Built-in Functions
- Math & conversion (ABS, POW, VAL, STR, HEX, BIN, etc.)
- String processing (LEN, TRIM, MID, REPLACE, INSERT, etc.)
- File/system access (FILE, PATH, SIZE, GETLINE)
- Search & parsing (FIND, MATCH, SPLIT, EXTRACT)
- Networking (GETURL), timing (TIMER), random (RND)
๐งฎ Floating Point (FPU)
- Optional floating-point via string-based FPU operations
- Arithmetic, trigonometric, rounding, and comparison functions
- Configurable precision via system register V3
๐ฅ๏ธ Console & Graphics
- Full console control (cursor, colors, fonts, window state)
- ANSI rendering, import, and export support
- Advanced screen buffer operations (GRAB, PAINT, MOVE, SWAP, etc.)
- Clipboard access (COPY / PASTE)
- Screen snapshots and state stack (SNAP, STORE/RESTORE)
- Block memory operations (BSAVE, BLOAD)
๐ฑ๏ธ Input
- INPUT (prompt-based input)
- INKEY (key codes, modifiers, non-blocking input)
- MOUSE (position, buttons, pixel-level data)
๐ File & System
- File I/O (LOAD, SAVE, CAT for append)
- File system operations via FILE() (create, delete, rename, query)
- Directory listing via array$[].FILE
- Shell execution with output capture (EXEC)
- Remote script execution over HTTP (EXEC run URL)
๐ Networking
- UDP networking (OPEN, SEND, QUEUE, CLOSE)
- FIFO-based message queue handling
๐ System Integration
- Direct Win32 API access via SYSCALL (DLL calls, wide versions)
- BYREF array passing for structured data interop
- System/environment access via PATH() and PEEK()
๐ต Multimedia
- Sound playback (WAV, MP3)
๐ Debug & Tools
- DEBUG window for real-time inspection and logging
- WAIT (timing control), PRINT (alias ?)
- Compact interpreter design
๐ Deployment
- Standalone executable generation (bind .BAS into .EXE)
- No external runtime or dependencies required
โน๏ธ Runtime & System Info
- System registers V0โV3 for return values and runtime state
- PEEK() for internal metrics (memory, timers, UDP state, etc.)
- PATH() for environment info and system dialogs
๐ช Compatibility
- Runs on Windows 7 / 8 / 10 / 11
- Designed for the classic Win32 console / CMD.EXE
- Compact, self-contained interpreter written in FASM
- Stable and maintained over long-term use
โจ Extras
- ANSI Art Studio - ANSI drawing tool written in Hobby BASIC
- Super Tiny BASIC included with full source code
- Free for personal use, learning, and experimentation
- Binary-only interpreter distribution
- Commercial use or redistribution requires permission
โ Conditionals in Hobby BASIC
1. IF...THEN...ELSE Statement
The IF...THEN...ELSE structure is used to control program flow based on conditions.
Example 1: Simple IF Statement
IF SCORE >= 50
PRINT "You passed!"
ENDIF
Example 2: IF...ELSEIF...ELSE
IF (GRADE$ = "A" AND ATTENDANCE >= 90) OR AGE > 18
PRINT "Great job!"
ELSEIF (GRADE$ = "B" OR AGE <= 18) AND ATTENDANCE >= 50
PRINT "Good effort!"
ELSE
PRINT "Keep improving!"
ENDIF
Example 3: Nested IF Statements
IF AGE >= 18
IF COUNTRY$ = "USA" THEN PRINT "You can vote."
ELSE
PRINT "You are too young to vote."
ENDIF
Example 4: Single-line IF with THEN
IF BALANCE < 0 THEN PRINT "Your account is overdrawn!" ELSE PRINT "Balance OK."
Example 5: IF without ELSE
IF LOGIN$ = "admin"
PRINT "Access granted."
ENDIF
2. IIF Function
The IIF function evaluates a condition and returns one of two values.
Example 6: Basic IIF Usage
STATUS$ = IIF(SCORE >= 60, "Pass", "Fail")
Example 7: Numeric IIF Example
DISCOUNT = IIF(QUANTITY > 10, 1, 0)
Example 8: String Assignment with IIF
COUNTRY$ = IIF(COUNTRY$ = "", "Unknown", COUNTRY$)
3. SELECT...CASE...ENDSEL Statement
The SELECT...CASE structure simplifies multiple condition checks.
Example 9: Simple SELECT...CASE
INPUT "Enter day of week (1-7): ", DAY
SELECT CASE DAY
CASE IS 1 :
PRINT "Monday"
BREAK
CASE IS 2 :
PRINT "Tuesday"
BREAK
CASE IS 3 :
PRINT "Wednesday"
BREAK
CASE IS 4 :
PRINT "Thursday"
BREAK
CASE IS 5 :
PRINT "Friday"
BREAK
CASE IS 6,7 :
PRINT "Weekend"
BREAK
CASE IS :
PRINT "Invalid day"
ENDSEL
Example 10: SELECT...CASE without parameter
SELECT CASE
CASE TEMP > 30 :
PRINT "Hot"
BREAK
CASE TEMP >= 20 AND TEMP <= 30 :
PRINT "Warm"
BREAK
CASE TEMP < 20 :
PRINT "Cold"
BREAK
ENDSEL
โ Loops and Control Statements
1. FOR...NEXT Loop
The FOR...NEXT loop in Hobby BASIC is used to repeat a block of code for a specific number of times.
Example 1: Basic FOR Loop with PASS
FOR I = 1 TO 5
IF I = 3 THEN PASS
PRINT I
NEXT I
Expected Output: 1 2 4 5
2. DO...UNTIL Loop
The DO...UNTIL loop executes a block of code repeatedly until a condition is met.
Example 2: DO Loop with PASS
I = 0
DO
I = I + 1
IF I = 2 THEN PASS
PRINT I
UNTIL I = 4
Expected Output: 1 3 4
3. WHILE...ENDW Loop
The WHILE...ENDW loop repeats a block of code as long as the condition is true.
โ๏ธ Note: Hobby BASIC uses ENDW instead of WEND.
Example 3: WHILE Loop
I = 1
WHILE I <= 5
PRINT I
I = I + 1
ENDW
Expected Output: 1 2 3 4 5
4. PASS Statement
The PASS statement is used to skip the current iteration of a loop. It is similar to the continue statement in C.
Example 4: Simple PASS Usage
FOR I = 1 TO 3
PASS
PRINT I
NEXT I
Expected Output: (Nothing printed)
5. BREAK Statement
The BREAK statement is used to exit a loop prematurely when a certain condition is met.
Example 5: Simple BREAK Usage
FOR I = 1 TO 9
IF I = 5 THEN BREAK
PRINT I
NEXT
Expected Output: 1 2 3 4
6. Nested Loops with BREAK and PASS
You can also use BREAK and PASS inside nested loops to control the flow.
Example 6: Nested Loops with PASS
FOR I = 1 TO 3
FOR J = 1 TO 3
IF J = 2 THEN PASS
PRINT "I=", I, " J=", J
NEXT J
NEXT I
Expected Output: I=1 J=1 I=1 J=3 I=2 J=1 I=2 J=3 I=3 J=1 I=3 J=3
7. Complex Example: Search for Prime Numbers
In this example, we will search for prime numbers up to a limit using BREAK and PASS.
Example 7: Search for Prime Numbers
LIMIT = 20
PRINT "Prime numbers up to ", LIMIT
PRINT 2, " ";
FOR NUM = 3 TO LIMIT STEP 2
ISPRIME = 1
I = 3
WHILE I * I <= NUM
IF NUM % I = 0
ISPRIME = 0
BREAK
ENDIF
I = I + 2
ENDW
IF ISPRIME THEN PRINT NUM, " ";
NEXT
Expected Output: 2 3 5 7 11 13 17 19
โ Functions in Hobby BASIC
1. Validated User Input (1โ100)
This function prompts for numeric input and checks for valid range and characters.
Example: getValidatedNumber Function
sub getValidatedNumber()
while 1
! prompt for input
INPUT "Please enter a number (from 1 to 100):", num$
! remove whitespace
num$ = TRIM(num$)
! check if input is empty
if not LEN(num$)
pass
! check for invalid characters (only digits allowed)
elseif not INSET(num$, "0123456789")
PRINT "Invalid characters in string, please try again."
! convert to number and check range
else
num = VAL(num$)
if num < 1 or num > 100
PRINT "Invalid value, please try again."
else
rets num ! return valid number
endif
endif
endw
ends
! call the function and display the result
number = getValidatedNumber()
PRINT "You entered:", number
โ๏ธ Note: The INPUT command needs an active screen buffer to work.
view 11
screen 80, 30, 3000
2. Searching for a Value in an Array
This function searches for a target value in an array and returns its index if found.
Example: searchArray Function
sub searchArray(arr[], target)
! search for the target value in the array
arr[].FIND target
rets V0 ! return the position (1-based, 0 if not found)
ends
! create an array with 50 random numbers (1โ50)
dim numbers[50].RND 50
searchValue = 10
! call the function and store the result
index = searchArray(numbers[], searchValue)
! check if the value was found
if index <> 0
PRINT "Value ", searchValue, " found at position ", index - 1
else
PRINT "Value ", searchValue, " not found in the array"
endif
3. Loading File Content into an Array
This function loads lines of text from a file into an array.
Example: loadFileIntoArray Function
sub loadFileIntoArray(filePath$, lines$[])
! check if file exists (SIZE returns -1 if not found)
if SIZE(filePath$) = -1 then rets -1
! load file contents into string array
lines$[].FILE filePath$
rets V0 ! return number of lines loaded
ends
! create a string array with 100 empty slots
dim fileBuffer$[100].ZERO
! load the file into the array and get the line count
lineCount = loadFileIntoArray(PATH("LICENSE-NOTES.TXT"), byref fileBuffer$[])
! check for file not found error
if lineCount = -1
PRINT "Error: File not found"
end
endif
! print each line of the loaded file
for i = 0 to lineCount - 1
PRINT fileBuffer$[i]
next
4. Swapping Two Values
This function swaps two values using a temporary variable.
Example: swapValues Function
sub swapValues(x, y)
! store the value of x in a temporary variable
local temp = x
! swap the values
x = y
y = temp
ends
firstValue = 5
secondValue = 10
! swap the two values using byref parameters
swapValues(byref firstValue, byref secondValue)
! print the swapped values
PRINT "After swapping: ", firstValue, " and ", secondValue
5. Checking if a String is a Palindrome
This function checks if a string is a palindrome (reads the same forwards and backwards).
Example: checkPalindrome Function
sub checkPalindrome(inputString$)
! declare local variables
local reversedString$
local cleanedInput$
! remove spaces from the input
cleanedInput$ = REPLACE(inputString$, " ", "")
! reverse the cleaned string
reversedString$ = REVERSE(cleanedInput$)
! compare the reversed and original (case-insensitive)
if UCASE(reversedString$) = UCASE(cleanedInput$)
rets "The string is a palindrome!"
else
rets "The string is not a palindrome!"
endif
ends
! call the function and display the result
result$ = checkPalindrome("Rotator")
PRINT result$
โ The Stack in Hobby BASIC
In Hobby BASIC, the stack operates in a LIFO (Last In, First Out) manner and consists of 262,140 double words. You can manipulate it using the basic PUSH and POP commands or directly through the stack[] array.
โ๏ธ Note: The stack[] array and the internal stack are the same. Any operation on stack[] directly affects the stack. However, commands like FILL, SHUFFLE, SORT, etc., do not update the internal stack pointer, so use them with care.
Example: Basic PUSH and POP
push 100
push 'A'
pop x
This sends 100 and the ASCII of 'A' to the stack, and retrieves 'A' into x.
Example: Multiple PUSH and Top Check
push 1, 2, 3, 'A'
top = PEEK(10) ! Get top of the stack
print CHR(stack[top - 1]) ! Prints 'A'
pop 4 ! pop 4 times
Sorting the Stack
x = 0
dim stack[10] ! reinitialize stack with 10 elements
times 10 push x++ ! pushes 0..9 onto the stack
stack[].SORTD ! now stack[] = [9, 8, โฆ, 0]
for i = 0 to 9
print stack[i]
next
Expected Output: 9 8 7 6 5 4 3 2 1 0 (Descending order)
Value Replacement
dim stack[5]
push 10, 20, 30, 20, 40
stack[].REPLACE 20, 99
times 5 pop x : print x
Expected Output: 40 99 30 99 10
Extra: Stack SHUFFLE
dim stack[5]
push 1, 2, 3, 4, 5
stack[].SHUFFLE
times 5 pop x : print x
โ๏ธ Note: SHUFFLE randomly shuffles stack values. The result will vary.
Handling the Circular Stack
The Hobby BASIC stack is circular. When it becomes full, new values start replacing older ones from the beginning of the array.
Example: Circular Stack Behavior
dim stack[5]
push 1, 2, 3, 4, 5
push 6, 7
top = PEEK(10)
arr_size = 5
for i = 0 to arr_size - 1
print stack[i]
next
Expected Output: 6 7 3 4 5
Reading Top to Bottom with Wrap-around
for i = 1 to 5
idx = (top - i + arr_size) mod arr_size
print stack[idx]
next
Expected Output: 7 6 5 4 3
Alternative: Simple POP
times 5 pop x : print x
Expected Output: 7 6 5 4 3
The stack in Hobby BASIC is a powerful tool. Its circular nature makes it highly efficient not only for simple PUSH and POP operations but also for advanced manipulations like sorting, shuffling, and value replacements using the stack[] array.
๐จ ANSI Art Studio โ Drawing Tool Guide
Introduction
ANSI Art Studio (STUDIO.BAS, formerly DRAW) is the ANSI graphics editor of the Hobby BASIC collection, written entirely in Hobby BASIC. It can create, load, edit and save ANSI images (.ANS), keep many images in memory at the same time (frames), and export a drawing as a ready-to-run .BAS loader script. All the ANSI graphics in the Hobby BASIC games were created with it.
On this page: Quick start ยท The screen ยท Drawing and selecting ยท Colors and schemes ยท Frames and multiple images ยท Shortcuts ยท Export to BASIC ยท Tips and limits
Requirements: Hobby BASIC on Windows 7/8/10/11 with Use Legacy Console enabled (how to enable it). Start the tool with HB.EXE EXAMPLES\STUDIO.BAS. To open an image directly, add its path: HB.EXE EXAMPLES\STUDIO.BAS MYIMAGE.ANS (paths with spaces are not supported).
๐ Quick start
When the program starts, press a key to choose the canvas:
- 1 โ Pixel font 8x12 (default), canvas 80x50 cells.
- 2 โ Pixel font 8x8, canvas 80x75 cells.
- 3 โ Load an RGB color scheme before you start (the same as the Insert key inside the editor).
โ ๏ธ Note: Options 1 and 2 define the font and canvas size used during your drawing session. Make sure to choose the correct mode when loading an image you previously created, to match its original dimensions.
- Click a character in the right panel.
- Click the FG or BG label (the active one is marked with
>) and pick one of the 16 colors in the left panel. - Click or drag on the canvas to draw.
- Press F3 to save the image as an
.ANSfile. Its color scheme is saved automatically.
๐ฅ๏ธ The screen
- Left panel: the main menu (NEW, LOAD, SAVE, UNDO, CLEAR, INVERT, ROTATE, REPAINT, RESIZE, REPLACE, ABOUT), the pointer coordinates, the FG / BG selectors and the 16-color picker.
- Canvas: the drawing area, 80x50 or 80x75 cells.
- Right panel: the character palette, with the current FG and BG colors shown above it.
- Title bar: the file name, the current frame, the coordinates under the pointer and an
[UNSAVED]flag when the drawing has unsaved changes. When you hover a menu item, its description appears there.
๐ฑ๏ธ Drawing and selecting
| Action | Result |
|---|---|
| Left-click (right panel) | Select the character to draw with. |
| Left-click (canvas) | Draw one cell with the selected character and colors. |
| Left-click + drag (canvas) | Draw a filled rectangle from the click point to the pointer. |
| Space (hold) + move the mouse | Freehand drawing: paints cell by cell with the selected character and colors. |
| Right-click + drag (canvas) | Select an area. |
| Left-click + drag (selected area) | Move the selection. |
| Left-click (selected area) | Delete the selected area. |
| Right-click (selected area) | Deselect. |
| Double-click (while an area is selected) | Paste a copy of the selected area at the pointer. The copy also works across frames. |
| Right-click (color picker) | Open the RGB color dialog. |
| Right-click (FG / BG labels) | Swap the foreground and background colors. If an area is selected, the swap is applied to it automatically. |
Working with a selected area
These commands work on the selected area and do nothing when there is no selection:
| Key | Menu item | What it does |
|---|---|---|
| F5 or Delete | CLEAR | Clear the selected area. |
| F6 | INVERT | Invert the selected area. |
| F7 | ROTATE | Rotate the selected area. |
| F8 | REPAINT | Repaint the selected area (change BG color to FG color). |
| F9 | RESIZE | Double the size of the selected area. It must still fit inside the canvas. |
| F10 | REPLACE | Replace characters. Enter two values separated by a comma: ASCII codes (65,66) or characters in quotes ('A','B'). The first character is replaced by the second. |
F12 inserts text at the pointer position, using the current FG and BG colors.
๐จ Colors and schemes
The attributes picker
Click the BG or FG label to choose which color you are changing (the active one is marked with >), then click one of the 16 colors. Right-click the labels to swap foreground and background.
โ๏ธ Note: This method overrides color number 8 (GRAY) as it is used for temporary storage.
The color dialog and the dropper
- Right-click any color in the picker to open the RGB dialog. Changes affect the whole console window instantly. Cancel leaves the color unchanged.
- Hold D and move the mouse over any pixel on your screen (even outside the window): the active color (FG or BG) takes the RGB value under the pointer.
Color schemes
The 16 console colors are shared by everything on the screen. That is why every image has its own color scheme:
- When you save an image (.ANS), the scheme is stored automatically in
DATA\TEMP\SCHEMESas a text file with the same name (for exampleMYIMAGE_SCHEME.TXT). - When you open an image, ANSI Art Studio looks for its scheme and loads it automatically. If there is none, the current colors are kept.
- To load a different scheme by hand, use option 3 at startup or press Insert at any time.
A scheme file has 16 lines, one per color (0โ15). Each line is 0x followed by six hex digits in BBGGRR order, the same format used by the RGB command.
๐ก Tip: Because the palette is shared, opening an image with a different scheme changes the colors of the other frames on screen too. If you work with several images that use different schemes, set AUTO_LOAD_SCHEME = 0 near the top of STUDIO.BAS and load schemes by hand with Insert.
๐๏ธ Frames and multiple images
ANSI Art Studio keeps many frames in memory at the same time. Use โ and โ to move between them; the current frame is shown in the title bar.
- LOAD (F2) places the image in the current frame. A multi-frame image fills the following frames, starting from the current one. All other frames keep their content.
- SAVE (F3) saves only the current frame.
- NEW (F1) clears all frames (it asks first if there are unsaved changes).
- UNDO (Ctrl+Z or F4) undoes the last action, even if it was made in another frame.
Example: load one image in frame 0, press โ and load another image in frame 1, press โ again and load an image with 10 frames. All of them stay in memory together, and you can copy parts between them with the selection tools (double-click pastes across frames).
โจ๏ธ Shortcuts
| Key | Action |
|---|---|
| F1 | Start a new drawing. |
| F2 | Open a drawing (.ANS file) into the current frame. |
| F3 | Save the current frame (.ANS file). |
| F4 / Ctrl+Z | Undo the last action. |
| F5 โ F10 | Clear, invert, rotate, repaint, resize and replace in the selected area (see above). |
| F11 | Export the current drawing as a .BAS loader script. |
| F12 | Insert text at the pointer position. |
| โ / โ | Previous / next frame. |
| Delete | Clear the selected area. |
| Insert | Load a color scheme (from DATA\TEMP\SCHEMES). |
| Space (hold) | Freehand drawing with the mouse. |
| D (hold) | Color dropper. |
| Q | Quit (the program asks for confirmation, and warns you about unsaved changes). |
๐ค Export to BASIC
Save your image first, then press F11. ANSI Art Studio creates a small loader script in the DATA\TEMP folder, with the same name as the image and the .BAS extension, and offers to run it. The script contains the console setup, the 16-color palette and the ANSI command that loads the image:
view 11
screen 80,50, 0
cursor 0
color 0, 0
cls
rgb 0, 0x000000
rgb 1, 0x800000
! ... the other 14 colors ...
! Change this path if you move the .ANS file
ansi_file$ = "C:\DATA\MEDIA\ANSI\MYIMAGE.ANS"
ansi ansi_file$
inkey
view 1
color 0, 7 : cls
end
The path of the .ANS file is kept in a single variable, so it is easy to adjust when you move the image. To load images inside your own programs, see Creating Snapshots.
๐ก Tips and limits
- The title bar shows
[UNSAVED]while there are unsaved changes. NEW, LOAD and quitting ask before discarding work (LOAD only replaces the current frame). - Undo remembers up to 700 actions. NEW and LOAD clear the undo history.
- Frames are numbered from 0 up to 699.
- A single file can hold about 40 frames at 80x50 or 26 frames at 80x75. If a file is longer than the load buffer, the program warns you that some frames were cut off.
- The keyboard is ignored while another window has the focus, so typing elsewhere does not trigger actions in the editor.
- Scheme files live in
DATA\TEMP\SCHEMES; exported scripts are written toDATA\TEMP. - If the colors or characters look wrong, check that Use Legacy Console is enabled (instructions) and that the canvas mode (8x12 or 8x8) matches the image.
โ Creating Snapshots
Introduction
ANSI images (.ANS) can be loaded into any Hobby BASIC program with the ANSI command, and parts of the screen can be saved as compact snapshots (.HB) with SNAP. Images are created with ANSI Art Studio, whose canvas is 80x50 cells (8x12 font) or 80x75 cells (8x8 font).
Loading an ANSI Image
For example, if we save an image named TEST.ANS in the DATA\MEDIA\ANSI\ folder, we can load it as follows:
! COLS = 80
! ROWS = 50
screen 80, 50, 0
cls
ansi PATH("DATA\MEDIA\ANSI\TEST.ANS")
inkey
The critical setting here is COLS, which must match the width of the image (80 columns for images made with ANSI Art Studio). ROWS only needs to be large enough to hold the whole image.
Saving a Portion of an Image
The following code creates a new ANSI image, TEST1.ANS, with a size of 40x25 from the original TEST.ANS file.
screen 80, 50, 0
cls
ansi PATH("DATA\MEDIA\ANSI\TEST.ANS")
ansi 0, 0, 40, 25, PATH("DATA\MEDIA\ANSI\TEST1.ANS")
inkey
Loading the Cropped Image
To load TEST1.ANS, the console window must match the image size:
screen 40, 25, 0
cls
ansi PATH("DATA\MEDIA\ANSI\TEST1.ANS")
inkey
โน๏ธ Using SNAP for More Flexibility
SNAP loads a snapshot file at position x, y, or saves a rectangular area of the screen to a file. Snapshot files require the .HB extension. SNAP allows us to load an image of any size into a console window of any dimensions (as long as it fits inside the window).
โ๏ธ Note: Since version 2.4.5, the SNAP command automatically includes the console's 16-color palette. This means:
- No separate RGB commands are needed after loading
- Perfect color reproduction every time
- Backward compatible with older .HB files
Creating and Loading a Snapshot
To load TEST.ANS and create a snapshot named TEST.HB with a size of 40x25, use the following code:
screen 80, 50, 0
cls
ansi PATH("DATA\MEDIA\ANSI\TEST.ANS")
snap 0, 0, 40, 25, PATH("DATA\SNAP\TEST.HB")
inkey
๐จ Fixing the Colors with a Color Scheme
If you run the code above, the colors will probably be wrong. An .ANS file stores only which of the 16 colors each cell uses, not what those colors look like, so the image is displayed with the console's current palette. A snapshot saves the palette that is active at that moment, so it would keep the wrong colors too.
ANSI Art Studio saves the palette of every image separately, in DATA\TEMP\SCHEMES, as <IMAGE NAME>_SCHEME.TXT (for TEST.ANS the file is TEST_SCHEME.TXT). It has 16 lines, one per color, in 0xBBGGRR format. These are the first lines (shortened here):
0x000000
0x800000
0x008000
... 13 more lines ...
To fix the colors, read the scheme and apply it with RGB before saving the snapshot:
! Load an ANSI image and save it as a snapshot with the correct colors
screen 80, 50, 0
cls
ansi_file$ = PATH("DATA\MEDIA\ANSI\TEST.ANS")
scheme_file$ = PATH("DATA\TEMP\SCHEMES\TEST_SCHEME.TXT")
snap_file$ = PATH("DATA\SNAP\TEST.HB")
! Stop early if the scheme file does not exist
if SIZE(scheme_file$) = -1
print "Scheme file not found:"
print scheme_file$
inkey
end
endif
! Apply the saved palette: one line per color, 16 colors (0 - 15)
for i = 0 to 15
color_hex$ = GETLINE(i + 1, scheme_file$)
rgb i, VAL(color_hex$)
next
! Load the image: it is now displayed with its real colors
ansi ansi_file$
! The snapshot stores the active palette, so it keeps the correct colors
snap 0, 0, 40, 25, snap_file$
inkey
๐ก Tip: Since version 2.4.5 a snapshot contains its own 16-color palette, so the .HB file shows the correct colors every time you load it, with no RGB commands. The same loop works at the start of a program that loads .ANS files directly.
Now, we can load this snapshot at any position within the console window:
screen 80, 50, 0
cls
snap 10, 10, PATH("DATA\SNAP\TEST.HB")
inkey
๐ SNAP 2D tile engine tutorial (FASM forum)
โ Hobby BASIC - Try These
๐ Built-in Functions Overview
Useful one-liners and built-in functions:
print ABS(-10) ! 10
print RND()%100 ! random number 0-99
print STR(25) + " years" ! "25 years"
print FORMAT(1, 23456) ! "22,9 KB"
print PAD("42", '0', 5) ! "00042"
print EXTRACT("abc123!@#", 0) ! "123"
๐ Use PAUSE or INKEY to prevent the window from closing.
๐งต Strings in Hobby BASIC
String manipulation with built-ins:
a$ = "Hello World"
print LEFT(a$, 5) ! "Hello"
print RIGHT(a$, 5) ! "World"
print REVERSE(a$) ! "dlroW olleH"
a$(0) = 'h' ! Change first char (0-based)
๐งฎ Arrays (1D & 2D)
Working with arrays and array functions:
dim nums[5] = 5, 3, 1, 4, 2
nums[].SORTA
nums[].PRINT 3
nums[].REPLACE 3, 99
nums[].PRINT 3
! 2D example:
dim matrix[2, 2] = 1, 2, 3, 4
print matrix[0, 0], matrix[1, 1] ! prints 1 4
Example: Load file into string array and display lines.
dim lines$[100].FILE PATH("LICENSE-NOTES.TXT")
lineCount = V0
for idx = 0 to lineCount - 1
print lines$[idx]
next
๐จ Console Drawing & Screen Tools
Manipulate screen output using built-in commands:
cls
color 1, 14
print "Yellow on Blue!"
paint 0, 0, 80, 25, 'A', 1
invert 10, 10, 15, 5
redraw 10, 10, 15, 5, 'A', '-'
You can redefine any of the 16 default console colors using the RGB command:
rgb 1, 0x00A5FF ! Set color #1 to orange
color 0, 1
print "Now using custom orange text!"
You can also use the alternate format with separate RGB components:
rgb 1, 255, 165, 0 ! equivalent to rgb 1, 0x00A5FF (note: color is in 0xBBGGRR format)
This allows for personalized color schemes inside your apps or tools built with Hobby BASIC.
๐ File & Snapshot Utilities
Working with files and snapshots:
! Load text from file into array
dim lines$[]
lines$[].FILE PATH("LICENSE-NOTES.TXT")
for i = 0 to SIZE(lines$[]) - 1
print lines$[i]
next
! Save a portion of screen
snap 0, 0, 40, 15, PATH("DATA\SNAP\TEST.HB")
! Load the snapshot
snap 10, 10, PATH("DATA\SNAP\TEST.HB")
๐ Mini Lab: Digital Clock
Create a simple digital clock:
while 1
print at 0, 0, LEFT(PATH(10), 8) ! system time
wait 1000
endw
๐บ๏ธ Mini Lab: Three Points with TYPE
TYPE is a user-defined structure that can hold variables or strings (classic syntax):
! Define a Coord structure for 3 points
type Coord (x, y) 3
! Assign coordinates to each point
Coord:[0].x = 10 : Coord:[0].y = 5 ! Point 0 at (10,5)
Coord:[1].x = 20 : Coord:[1].y = 15 ! Point 1 at (20,15)
Coord:[2].x = 30 : Coord:[2].y = 25 ! Point 2 at (30,25)
! Loop through and print each point
for i = 0 to 2
print "Point ", i, ": (", Coord:[i].x, ", ", Coord:[i].y, ")"
next
โจ Block syntax with ENDT (available from version 2.5.4+):
! Define a Player structure with default values
type Player
Name$ = "Unknown"
Score = 0
Level = 1
Class$ = "Novice"
endt 3
! Initialize first player
Player:[0].Name$ = "Aragorn"
Player:[0].Class$ = "Ranger"
Player:[0].Score = 1500
Player:[0].Level++
! Display all players
for i = 0 to SIZE(Player:[])-1
print Player:[i].Name$; Player:[i].Class$; Player:[i].Score; "Lv.", Player:[i].Level
next
Both syntaxes work, but the block style offers better readability for complex structures.
โจ๏ธ Keyboard Input
Wait for a key press and display the key code:
LOOP#
inkey
! V0 = Keycode
! V1 = SHIFT, ALT, CTRL, etc.
! V2 = F1..F12, INS, DEL, HOME, Arrows Keys
print "Key:", V0, " Mod:", V1, " Extra:", V2
if V0 = 13 then print "Enter was pressed"
if V0 = 27 then end ! Exit with Esc
goto LOOP
๐ฑ๏ธ Mouse Tracking
Track mouse position and button state:
while 1
mouse
! V0 = mouse x
! V1 = mouse y
! V2 = button: 1 left, 2 right, 4 double-click
print "X:", V0, " Y:", V1, " Btn:", V2
if V2 = 2 then print "Right click!"
if V2 = 1 then break ! Left click to exit
wait 1
endw
โ๏ธ Note: Mouse input requires no screen buffer.
view 11
screen 80, 30, 0
โ Hobby BASIC - Advanced
๐งพ Version notes
- 2.4.5 โ
SNAPfiles include the 16-color palette - 2.5.4 โ block
TYPE ... ENDTsyntax - 2.5.5 โ registry module; subroutines can return strings directly
โ๏ธ FIX and TIMES
FIX replaces code before execution, letting you use alternative keywords or rename commands.
TIMES is like a compact loop. It runs a single-line command multiple times using V3 as the counter.
wait100ms fix wait 100
display fix print
times 50 display V3 : wait100ms
With the above fix, you can write display instead of print, or even use your native language!
๐ Full Wide & Greek-native support with fix command
Hobby BASIC is fully Wide-native, supporting Greek identifiers and keywords. To use Greek keywords in your code,
first declare them with the fix command, linking the Greek word to the corresponding English command.
For example:
! After these mappings, you can write your program using Greek commands directly
ฮ ฮกฮฮฮฮฮ fix VIEW
ฮฮฮฮฮ fix SCREEN
ฮงฮกฮฉฮฮ fix COLOR
ฮฃฮฮฮฃฮฮฮ fix CLS
ฮคฮฅฮ ฮฉฮฃฮ fix PRINT
ฮ ฮฮฅฮฃฮ fix PAUSE
ฮฮกฮงฮ#
ฮ ฮกฮฮฮฮฮ 11
ฮฮฮฮฮ 80, 30, 1000
ฮฃฮฮฮฃฮฮฮ
ฮงฮกฮฉฮฮ 0, 7
ฮคฮฅฮ ฮฉฮฃฮ "ฮฅฯฮฟฯฯฮทฯฮฏฮถฯ ฮฮปฮปฮทฮฝฮนฮบฮฌ"
ฮ ฮฮฅฮฃฮ
All source code, tokens, labels, and strings are handled as Wide, enabling case-sensitive Greek and Latin text everywhere.
โ๏ธ Note: To display Greek characters correctly, Hobby BASIC requires a raster font that supports Wide glyphs.
๐ ๏ธ DEBUG() Window Examples
Use the DEBUG window to visualize variable contents in real time:
dim values[5] = 10, 20, 30, 40, 50
for i = 0 to 4
DEBUG(i, values[i]) ! show key-value pairs in debugger
next
Viewing output of an external command.
exec "tasklist", list$
debug(list$)
This will show the list of running processes from the Windows tasklist command directly inside the DEBUG window.
๐๏ธ Registry Module
Hobby BASIC 2.5.5 includes a registry module (REGISTRY.BAS) for reading and writing Windows registry values.
%include "EXAMPLES\MODULES\REGISTRY.BAS"
! Returns the processor name (e.g., "Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz")
sub GetProcessorName()
rets RegReadString(HKEY_LOCAL_MACHINE, "HARDWARE\DESCRIPTION\System\CentralProcessor\0", "ProcessorNameString")
ends
DEBUG("Processor Name :" , GetProcessorName())
pause
end
Sample DEBUG Output:
Processor Name: Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz
๐ก Note: The actual output depends on your processor.
What's happening here?
RegReadStringreads the processor name from the registry- The subroutine
GetProcessorName()returns a string directly DEBUGreceives and displays the string without any intermediate variable- This works because v2.5.5 subroutines can return strings directly, not just integers
๐ See also: A high-score table stored entirely in the registry (FASM forum).
๐ Run Remote Scripts Anywhere
One of Hobby BASICโs unique features is the ability to run remote .BAS scripts
directly from the command line, without needing to download them manually. Try the following in the command line and see what it does.
HB.EXE https://files.catbox.moe/ia9qt7.BAS
Alternatively, you can run remote scripts dynamically from within another .BAS program:
exec "run https://files.catbox.moe/ia9qt7.BAS"
This command fetches the .BAS file from the specified URL, loads it into memory, and executes it in the console.
โ ๏ธ Security Warning: Scripts from remote URLs run with full privileges. Only run code from trusted and verified sources.
๐งฎ Floating-Point Functions
Hobby BASIC supports optional floating-point math through external functions. All arguments and results are passed as strings, making it easy to use floats without affecting the integer core.
print FADD("3.14", "2.0") ! "5.14"
print FSUB("10", "2.5") ! "7.50"
print FMUL("3.0", "2.0") ! "6.00"
print FDIV("1.0", "0.0") ! "0.00"
! Using variables, strings, arrays, types
x$ = "3.14" : y = 2
dim a$[] = "1.5", "2.5"
type T (x$ = "3.5", y$ = "2.5")
print FADD(x$, y) ! "5.14"
print FADD(a$[0], a$[1]) ! "4.00"
print FMUL(T:[0].x$, T:[0].y$) ! "8.75"
โญ Drawing a circle in console using FPU string math and TIMES command.
โถ View source code
! ----------------------------------------------------------------------------------------
! TIMES WITH FPU STRINGS
! Drawing a circle in console using FPU string math and TIMES command
! Note: the backslash (\) is the line-continuation character; here it builds a multi-line TIMES block
! ----------------------------------------------------------------------------------------
! Initialize display (font size 8x8)
title "FPU CIRCLE"
view 7
screen 40, 25, 0
cursor 0
color 0, 15
cls
times 360 \
! Calculate circle coordinates (360 degrees in radians)
a$ = FDIV(FMUL(V3,"6.28318"),"360.0") : \
x = VAL(FROUND(FADD("20.0",FMUL(FSIN(a$),"9.0")),"NEAREST")) : \
y = VAL(FROUND(FADD("12.0",FMUL(FCOS(a$),"9.0")),"NEAREST")) : \
if x >= 0 and x < 40 and y >= 0 and y < 25 then at x, y, "โ"
! Clean exit
inkey
color 0, 7 : cls
view 11
end
๐ Why strings?
Floating-point functions operate on string arguments to maintain compatibility with Hobby's integer-based architecture. This makes conversions explicit and avoids hidden side effects. It also keeps the system small, portable, and easy to debug. See the Hobby BASIC manual for more details about the floating-point set and how to use it effectively in your programs.
โ๏ธ Win32 Power with syscall
With Hobby BASIC you can call Windows API functions, unlocking features beyond standard BASIC โfrom message boxes to launching programs, querying system info, or even experimenting with simple GDI graphics in the console.
syscall "user32.dll", "MessageBoxW", 0, "Hello from BASIC!", "Title", 0
APIs can also return values. For example, get system uptime in milliseconds:
syscall "kernel32.dll", "GetTickCount"
print "Milliseconds since boot: ", V0
Or play a simple system beep using kernel32.dll:
syscall "kernel32.dll", "Beep", 750, 300
Structures made of DWORD fields are supported by using arrays with
byref, letting you call functions such as GetWindowRect to retrieve window dimensions.
โ ๏ธ Warning: Native API calls run with full privileges. Incorrect use may cause crashes. Use only documented functions and safe values!
๐ See the Hobby BASIC Manual for details and the EXAMPLES\API folder for samples.
๐ ๏ธ Super Tiny BASIC โ Built with Hobby BASIC
Super Tiny BASIC is a ~900-line '80s-style BASIC interpreter written entirely in Hobby BASIC โ a fun proof of what the language can do.
It supports single-letter variables (AโZ), single-line IF statements, structured loops (FOR/NEXT, WHILE/WEND (Hobby BASIC itself uses ENDW)), classic I/O (PRINT, INPUT), subroutines (GOSUB/RETURN), and essential console commands.
๐ It can be enjoyed as:
- ๐ฎ A toy environment for newcomers to play and learn programming basics.
- ๐ผ A retro playground for experienced BASIC programmers.
- ๐งฉ A compact codebase open to modifications, enhancements, experiments, and pure programming fun.
โจ Features
- ๐ฌ
REMcomments - ๐ข Numeric expressions and logical operators
- ๐ฒ Built-in functions:
RND(),CHR() - ๐จ Console control:
LOCATE,COLOR,CLS,WAIT,INKEY - ๐พ File operations:
LOAD,SAVE - โ ๏ธ Limitations: numeric variables only (AโZ), max 1,000 lines, runs inside the Hobby BASIC Interpreter.
๐ Example
10 FOR I = 1 TO 5
20 PRINT "Hello, World!"
30 NEXT I
๐ Type in lowercase โ the interpreter converts keywords and variables automatically.
๐ The program, TEST.BAS, showcases all the features of Super Tiny BASIC.
๐ฎ Demo Game
A full Hobby BASIC demo running inside the Windows 10 console.
โถ View source code
! ----------------------------------------------------------------------------------------
! DEMO.BAS
! Hobby BASIC Interpreter
! Example program from the Hobby BASIC collection.
!
! ----------------------------------------------------------------------------------------
! DEMO DESCRIPTION
! ----------------------------------------------------------------------------------------
!
! 2D Platformer Demo with physics and multi-level progression.
! Jump, climb ladders, and navigate through 4 challenging levels.
! Features smooth character animation, collision detection, and gravity physics.
!
! Controls:
! - Arrow Keys: Move left/right and climb ladders
! - Space: Jump
! - ESC: Exit game
!
! ----------------------------------------------------------------------------------------
! COMPATIBILITY NOTE
! ----------------------------------------------------------------------------------------
!
! For Windows 10/11:
! Enable "Use Legacy Console" in Properties for proper display
! (Right-click title bar โ Properties โ Options tab)
!
! ----------------------------------------------------------------------------------------
! ----------------------------------------------------------------------------------------
! SYSTEM CONSTANTS AND INITIALIZATION
! ----------------------------------------------------------------------------------------
FILE_OR_FOLDER_EXISTS = 3
MB_ICONERROR = 0x10
! System compatibility check
if VAL(PATH(6)) < 6
alert MB_ICONERROR, PATH(3), "Demo Requires Windows 7 or later" : end
endif
! Load graphics tileset
path_gfx$ = PATH("DATA\SNAP\TILESET.HB")
if FILE(path_gfx$, FILE_OR_FOLDER_EXISTS) = 0
alert MB_ICONERROR, "Tileset not found", path_gfx$ : end
endif
! Sound initialization
JUMP_SND = 700
sound PATH("DATA\MEDIA\SFX\WAV\SFX1.WAV"), JUMP_SND
! Virtual key codes for input handling
enum VK_LEFT=37, VK_UP, VK_RIGHT, VK_DOWN
VK_ESC = 27
VK_SPACE = 32
! ----------------------------------------------------------------------------------------
! GAME CONSTANTS
! ----------------------------------------------------------------------------------------
FRAME_RIGHT = 7 ! Character sprite facing right
FRAME_LEFT = 17 ! Character sprite facing left (mirrored)
FRAME_CLIMB = 8 ! Character climbing sprite
TILE_SIZE = 8 ! Size of each tile in cells
JUMP_OFFSET = 12 ! Maximum jump height in cells
GAME_INTERVAL = 20 ! Frame time in milliseconds
level = 1 ! Current level (1-4)
! ----------------------------------------------------------------------------------------
! COLOR PALETTE (16-color palette for the game)
! ----------------------------------------------------------------------------------------
dim rgb_color[] = \
0x000000, 0x584751, 0x49AB52, 0x3A4994, 0x3E628E, 0x43266B, 0x3381C1, 0xB8A7B0, \
0xA48E9A, 0xDE8833, 0x52B55A, 0x33A8F3, 0x304C6E, 0xACA2FF, 0x4892CE, 0xC9BBC2
! ----------------------------------------------------------------------------------------
! LEVEL DESIGNS
! Tile IDs:
! 0 = Empty/background
! 1 = Solid ground
! 2 = Platform blocks
! 3 = Special block 1
! 4 = Ladder
! 5 = Ladder top
! 6 = Special block 2
! 9 = Level exit/goal
! ----------------------------------------------------------------------------------------
dim map1[11,7] = \
2,2,2,2,2,2,2,2,2,2,2, \
2,2,2,2,2,2,2,2,2,2,2, \
2,2,2,2,2,2,2,2,2,2,2, \
2,2,2,2,2,2,2,2,2,2,2, \
1,1,1,1,1,2,2,2,2,2,9, \
0,0,0,0,0,1,1,1,1,1,1, \
0,0,0,0,0,0,0,0,0,0,0
dim map2[11,7] = \
2,2,2,2,2,2,2,2,2,2,2, \
2,2,2,2,2,2,2,2,2,2,2, \
2,2,2,2,2,2,2,2,2,2,9, \
2,2,2,2,2,2,2,5,1,1,1, \
2,2,2,2,2,2,2,4,0,0,0, \
1,1,1,1,1,1,1,1,0,0,0, \
0,0,0,0,0,0,0,0,0,0,0
dim map3[11,7] = \
2,2,2,2,2,2,2,2,2,2,2, \
2,2,2,2,2,2,2,2,2,2,2, \
2,2,2,2,2,2,2,2,2,2,2, \
1,1,1,1,5,2,2,2,2,2,2, \
0,0,0,0,4,2,2,6,2,2,9, \
0,0,0,0,4,2,1,1,1,1,1, \
0,0,0,0,1,1,0,0,0,0,0
dim map4[11,7] = \
2,2,2,2,2,2,2,2,2,2,2, \
2,2,2,2,2,2,2,2,2,2,2, \
2,2,2,2,2,2,2,2,2,2,2, \
2,2,2,2,2,2,2,2,2,2,9, \
1,1,1,1,5,2,2,3,2,2,1, \
0,0,0,0,4,2,2,2,2,2,0, \
0,0,0,0,1,1,1,1,1,1,0
! Player starting positions for each level (tile coordinates: x, y)
dim hero_start_positions$[] = "00","03","04","02","03"
! ----------------------------------------------------------------------------------------
! DISPLAY INITIALIZATION
! ----------------------------------------------------------------------------------------
title "๐ฎ 2D Platformer Demo โข Use โ โ โ, Space to jump"
view 0, 7 ! Hide window, 8x8 pixel font
screen 80, 75, 0 ! Set console size
cursor 0 ! Hide cursor
color 0, 0 ! Black text on black background
cls ! Clear screen
! Load tileset graphics
snap 0, 0, path_gfx$
! Copy individual tiles from tileset to graphic slots
for i = 0 to 7
bsave i * 8, 0, TILE_SIZE, TILE_SIZE, i
next
! Special tiles (mirrored left-facing sprite and climbing)
flip 56,0,TILE_SIZE,TILE_SIZE,0 ! Create mirrored sprite
bsave 56,0,TILE_SIZE,TILE_SIZE,17 ! Store as left-facing frame
bsave 64,0,TILE_SIZE,TILE_SIZE,8 ! Climbing frame
bsave 72,0,TILE_SIZE,TILE_SIZE,9 ! Special tile
! Apply color palette to all 16 colors
for i = 0 to 15
rgb i, rgb_color[i]
next
! ----------------------------------------------------------------------------------------
! GAME SUBROUTINES
! ----------------------------------------------------------------------------------------
! ----------------------------------------------------------------------------
! Update character position and sprite
! Parameters: x, y = character coordinates, frame = sprite frame to display
! ----------------------------------------------------------------------------
sub update_character(x, y, frame)
bloads x, y, frame
ends
! ----------------------------------------------------------------------------
! Check if character is on a ladder at given position
! Returns: 1 if on ladder, 0 otherwise
! ----------------------------------------------------------------------------
sub is_on_ladder(x, y)
for local i = 1 to TILE_SIZE - 1
cinfo x + i, y - 1
if V1 = 4 then rets 1 ! Color 4 = ladder
next
rets 0
ends
! ----------------------------------------------------------------------------
! Check if character should fall (no ground below)
! Returns: 1 if falling, 0 if on solid ground
! ----------------------------------------------------------------------------
sub check_falling()
for local i = 1 to TILE_SIZE - 1
cinfo x + i, y + TILE_SIZE
if MATCH(V1,1,7,8,10,12,15) then jumping = 0 : rets 0
next
rets 1
ends
! ----------------------------------------------------------------------------
! Check if character can move in horizontal direction
! Parameters: dx = direction (-1 for left, TILE_SIZE for right)
! Returns: 1 if movement allowed, 0 if blocked
! ----------------------------------------------------------------------------
sub can_move_horizontal(dx)
for local i = 0 to TILE_SIZE - 1
cinfo x + dx, y + i
if MATCH(V1,1,7,8,10,12,15) then rets 0
next
rets 1
ends
! ----------------------------------------------------------------------------
! Render the current level map to the screen
! ----------------------------------------------------------------------------
sub render_level_map()
for local y = 0 to map_height-1
for local x = 0 to map_width-1
bloads x * TILE_SIZE, y * TILE_SIZE, map[x, y]
next
next
ends
! ----------------------------------------------------------------------------------------
! LEVEL SETUP AND INITIALIZATION
! ----------------------------------------------------------------------------------------
start#
view 0 ! Hide console window
! Level cycling (1-4)
if level > 4 then level = 1
! Get current map dimensions
map//level[].SIZE
map_width = V1
map_height = V2
! Create and copy level map
dim map[map_width, map_height]
map[].COPY map//level[]
! Calculate screen dimensions
COLS = map_width * TILE_SIZE
ROWS = map_height * TILE_SIZE
! Create background buffer
dim stage[COLS, ROWS]
! Set up graphics area
screen COLS, ROWS, 0
color 9, 9
paint TILE_SIZE, TILE_SIZE, COLS, ROWS, -1, -1
! Render level and capture to buffer
dir = 1 ! Start facing right
render_level_map()
grab 0, 0, COLS, ROWS, stage[], 0
! Initialize timing for frame rate control
lastGameTime = PEEK(0) & 0x7FFFFFFF
! Set player starting position
hero_start$ = hero_start_positions$[level]
tile_x = VAL(LEFT(hero_start$, 1))
tile_y = VAL(RIGHT(hero_start$, 1))
x = tile_x * TILE_SIZE
y = tile_y * TILE_SIZE
! Display character at starting position
update_character(x, y, FRAME_RIGHT)
view 1 ! Show console window
! ----------------------------------------------------------------------------------------
! MAIN GAME LOOP
! ----------------------------------------------------------------------------------------
main#
! Frame rate control
currentTime = PEEK(0) & 0x7FFFFFFF
if currentTime - lastGameTime < GAME_INTERVAL
wait 1 ! Reduce CPU usage while waiting
goto main
endif
! ------------------------------------------------------------------------
! JUMPING AND GRAVITY SYSTEM
! ------------------------------------------------------------------------
if jumping
! Character is currently jumping upward
if y = JUMP_HEIGHT
jumping = 0 ! Reached jump peak
vy = 1 ! Start falling
endif
else
! Check if character should fall
vy = check_falling()
if vy = 0 then onGround = 1 else onGround = 0
endif
! Jump initiation (space bar while on ground or ladder)
if KEY(VK_SPACE) and (onGround or is_on_ladder(x, y))
sound JUMP_SND ! Play jump sound
jumping = 1
onGround = 0
JUMP_HEIGHT = y - JUMP_OFFSET ! Calculate jump peak
vy = -1 ! Start moving upward
endif
! ------------------------------------------------------------------------
! LADDER CLIMBING
! ------------------------------------------------------------------------
if KEY(VK_UP) and is_on_ladder(x, y)
! Continuous climbing while up key is pressed
while 1
if KEY(VK_UP)
grab x, y, TILE_SIZE, TILE_SIZE, stage[], x, y
y-- ! Move up one cell
update_character(x, y, FRAME_CLIMB)
wait 20 ! Climbing speed
elseif KEY(VK_DOWN) or not is_on_ladder(x, y + TILE_SIZE - 1)
break ! Stop climbing
endif
endw
endif
! ------------------------------------------------------------------------
! HORIZONTAL MOVEMENT
! ------------------------------------------------------------------------
if KEY(VK_LEFT) and can_move_horizontal(-1) and x > 0
dir = -1 ! Facing left
vx = -1 ! Moving left
elseif KEY(VK_RIGHT) and can_move_horizontal(TILE_SIZE)
! Check if reached level exit (right edge)
if x > COLS - 10
level++ ! Advance to next level
goto start
endif
dir = 1 ! Facing right
vx = 1 ! Moving right
else
vx = 0 ! No horizontal movement
endif
! ------------------------------------------------------------------------
! UPDATE CHARACTER POSITION AND DISPLAY
! ------------------------------------------------------------------------
if vx or vy or jumping
! Restore background at old position
grab x, y, TILE_SIZE, TILE_SIZE, stage[], x, y
! Update character coordinates
x += vx
y += vy
! Draw character with correct facing direction
if dir = -1
update_character(x, y, FRAME_LEFT)
else
update_character(x, y, FRAME_RIGHT)
endif
endif
! Update timing for next frame
lastGameTime = currentTime
! Continue unless ESC key is pressed
if not KEY(VK_ESC) then goto main
! ----------------------------------------------------------------------------------------
! CLEAN EXIT
! ----------------------------------------------------------------------------------------
color 0,7 : cls ! Clear with black on white
view 11 ! 8x12 pixel font
end
๐จ P2P Drawing
Collaborative real-time drawing using UDP peer-to-peer networking running inside the Windows 10 console.
โถ View source code
! ----------------------------------------------------------------------------------------
! P2PDRAW.BAS
! Hobby BASIC Interpreter
! Example program from the Hobby BASIC collection
!
! ----------------------------------------------------------------------------------------
! APPLICATION DESCRIPTION
! ----------------------------------------------------------------------------------------
!
! Peer-to-peer collaborative drawing application using UDP sockets.
! Draw together with remote users in real-time - left click to paint,
! right click to erase. Press SPACE to clear both screens simultaneously.
!
! Controls:
! - Left Click: Draw/paint cell
! - Right Click: Clear/erase cell
! - SPACE: Clear both screens (synchronized)
! - ESC: Exit application
!
! ----------------------------------------------------------------------------------------
! NETWORK FEATURES
! ----------------------------------------------------------------------------------------
!
! - Real-time drawing synchronization
! - Peer-to-peer UDP communication
! - Coordinate and color encoding
! - Synchronized screen clearing with feedback
! - Local network or localhost operation
!
! ----------------------------------------------------------------------------------------
! --- Constants ---
VK_ESC = 27
VK_SPACE = 32
CMD_CLEAR$ = "P2PDRAW_CLEAR_SCREEN"
! --- Port configuration ---
enum PORT1=50002, PORT2
REMOTE_IP$ = "localhost"
LOCAL_PORT = PORT1
REMOTE_PORT = PORT2
! --- Open UDP socket ---
if OPEN(LOCAL_PORT) = -1
print "Socket error ", STR(V0) : pause : end
endif
! --- Mouse initialization ---
mouse() fix mouse : x = V0 : y = V1 : btn = V2
px = -1
py = -1
dim a$[10000]
! --- Screen setup ---
title "P2P Drawing - " + PATH(8) + " - SPACE to clear both"
view 11
screen 80, 30, 0
cursor 0
color 0, 0
cls
gosub RedrawControls
! --- Main loop ---
do
! --- SPACE: Synchronized clear ---
if KEY(VK_SPACE)
cls
gosub RedrawControls
pen 13
at 32, 12, "CLEARING..."
wait 250
SEND(REMOTE_IP$, REMOTE_PORT, CMD_CLEAR$)
at 32, 12, "SCREEN CLEARED!"
wait 250
at 32, 12, " "
pen 15
wait 250
endif
! --- Mouse drawing ---
n = 0
mouse()
if (btn = 1 or btn = 2)
c = IIF(btn = 2, 32, 0x2588)
pen 13 : at 0, 0, "DRAWING..."
do
mouse()
if (x <> px or y <> py)
pen 15
at x, y, CHR(c)
a$[n] = STR((((x << 7) | y) << 15) | c)
n++
px = x
py = y
endif
until btn = -1
at 0, 0, " "
! --- Send with progress feedback ---
if n > 0
pen 14
at 0, 0, "SENDING"
for i = 0 to n-1
SEND(REMOTE_IP$, REMOTE_PORT, a$[i])
pen 14
at 8, 0, STR(i+1) + "/" + STR(n)
wait 1
next
at 0, 0, " "
at 8, 0, " "
wait 10
endif
endif
! --- Handle incoming messages ---
while LEN(QUEUE(1))
msg$ = QUEUE(0)
if msg$ = CMD_CLEAR$
cls
gosub RedrawControls
pen 13
at 32, 12, "SCREEN CLEARED!"
wait 250
at 32, 12, " "
pen 15
else
n = VAL(msg$)
x = BITS(n, 28, 7)
y = BITS(n, 21, 7)
c = BITS(n, 14, 15)
pen 9
at x, y, CHR(c)
endif
endw
wait 1
until KEY(VK_ESC)
CLOSE()
end
RedrawControls#
locate 6, 28
pen 11 : print "LEFT=Draw ";
pen 12 : print "RIGHT=Erase ";
pen 10 : print "SPACE=Clear Both ";
pen 14 : print "ESC=Exit"
pen 15
return
๐ Network Diagnostics
UDP and internet testing with visual DEBUG() output.
โถ View source code
! ----------------------------------------------------------------------------------------
! NETWORK.BAS
! Hobby BASIC Interpreter
! Example program from the Hobby BASIC collection
!
! ----------------------------------------------------------------------------------------
! PROGRAM DESCRIPTION
! ----------------------------------------------------------------------------------------
!
! Complete network testing with DEBUG() window
!
! Features:
! - UDP socket connectivity testing
! - Internet access verification with public IP lookup
! - Visual feedback with emoji and color coding
! - System information display
! - Real-time status reporting in DEBUG() window
!
! ----------------------------------------------------------------------------------------
DEBUG("CLEAR")
DEBUG("๐ NETWORK DIAGNOSTICS")
DEBUG("โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ")
DEBUG("๐ Session started: ", PATH(10))
DEBUG("๐ป Hostname: ", PATH(7))
DEBUG("๐ก Local IP: ", PATH(8))
DEBUG("๐ CONNECTIVITY TESTS")
DEBUG("โโโโโโโโโโโโโโโโโโโโ")
socket_test = OPEN(0)
if socket_test <> -1
DEBUG(" UDP Socket: โ
Open")
CLOSE()
else
DEBUG(" UDP Socket: โ Failed")
endif
public_ip$ = GETURL("https://api.ipify.org")
if LEN(public_ip$) > 0
DEBUG(" Internet: โ
Connected")
DEBUG(" Public IP: ", public_ip$)
else
DEBUG(" Internet: โ No connection")
endif
DEBUG("๐ SYSTEM INFO")
DEBUG("โโโโโโโโโโโโโโโโโโโโ")
DEBUG(" OS: Windows ", PATH(6))
DEBUG(" Hobby BASIC: ", PATH(5))
DEBUG("โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ")
if socket_test <> -1 and LEN(public_ip$) > 0
DEBUG("โ
STATUS: FULLY OPERATIONAL")
else
DEBUG("โ ๏ธ CHECK NETWORK SETTINGS")
endif
cls
print "Check DEBUG() window for network diagnostics"
inkey
end
๐ About Hobby BASIC
Hobby BASIC is a lightweight yet surprisingly powerful BASIC interpreter for the Windows console, written entirely in x86 Assembly language.
It enables the creation of games with ANSI graphics in the console, which is quite unusual.
What began in 2015 as a personal fun project continues to evolve to this day.
This quick guide offers just a small glimpse of what Hobby BASIC can do.
๐ To download it and learn more, visit the Hobby BASIC topic on the Flat Assembler forum.
๐ Get the file directly right here -- Unzip the HB folder and you're ready to go.
๐ Watch a full video tour on YouTube to see Hobby BASIC in action.
Chrome may say: โThis file is dangerous, so Chrome has blocked it.โ
๐ Press CTRL + J and choose to Keep the file.
Windows Defender might also block it โ you can:
- Temporarily disable real-time protection
- Add an exception after installing
Hobby BASIC started on Windows XP, continued on 7, and is now focused on Windows 10 and 11.
Some examples still work on older systems!
๐ Enable Legacy Console Mode
To ensure full compatibility with ANSI graphics and console behavior:
- Windows 10: Right-click the console title bar โ Properties โ Check "Use legacy console" โ Restart the console
-
Windows 11 (24H2 and newer):
- Go to Settings > System > Optional Features
- Click Add a feature and search for "Legacy Console"
- Install it, then go to Settings > Privacy & Security > For Developers โ Change terminal to Windows Console Host
- Now open the console and enable "Use legacy console" as before
Donโt let system warnings discourage you. Experiment. Learn. Thatโs the spirit of hobby programming!
๐ Conclusion
This guide covers the fundamental concepts of Hobby BASIC, from conditions and loops to functions and drawing tools. With this knowledge, you can start creating your own programs.