Skip to content

thepanoc95/PassiBASIC

Repository files navigation

PassiBASIC

PassiBASIC is a portable, C64-inspired BASIC dialect with scientific calculator-style functions like TAN(), LOG(), SQR(), SQRT(), SIN(), COS(), and ATN().

Build

From the repository root:

make

This produces the passibasic executable and auto-generates buildinfo.h with a random PASSIBASIC_BUILD_NUMBER string for the BUILD banner. Set BASIC_BE_BUILDVER=... when invoking make if you need to override the displayed build string.

Run

./passibasic

Commands supported in the shell:

  • RUN - execute the stored program
  • LIST - show stored program lines
  • NEW - clear the program
  • LOAD_CORE <module> - load a numbered module from core/ by name, e.g. LOAD_CORE APPLEBUS
  • QUIT / EXIT / BYE - leave the shell
  • C64-style lines, e.g. 10 PRINT 2+2
  • LET A = 5, A = 10
  • INPUT A
  • GOTO 20
  • IF A > 5 THEN 50
  • END

Features

  • Modular interpreter core in src/passibasic.c
  • Host front-end in src/main.c
  • Line-numbered program storage compatible with BASIC-80 and C64 BASIC style
  • Variable names limited to A through Z
  • String variables with $ suffix (e.g., A$, COLOR_RED$)
  • String concatenation with + operator
  • CHR$() function for character codes
  • Arithmetic parser with precedence and relational operators
  • Mathematical functions for scientific calculator behavior
  • Apple Business BASIC-style console commands: HOME, HTAB, VTAB, TAB(n), SPC(n), TEXT, GR, HGR, NORMAL, INVERSE, and FLASH
  • Apple-style byte memory access with POKE address,value and PEEK(address)
  • Simple built-in shape drawing with DRAW(SHAPE(n)); optional positioning is available as DRAW(SHAPE(n)),x,y

Apple Business BASIC-style Features

PassiBASIC includes a small compatibility layer for Apple Business BASIC-inspired programs:

10 HOME
20 HTAB 10
30 VTAB 5
40 PRINT "APPLE-STYLE TEXT"
50 POKE 1000,42
60 PRINT PEEK(1000)
70 DRAW(SHAPE(3))
80 DRAW(SHAPE(4)),20,8

Supported commands and functions:

  • HOME clears the terminal and moves the cursor to the upper-left corner.
  • HTAB n and VTAB n position the terminal cursor column and row.
  • TAB(n) and SPC(n) can be used in PRINT to emit spaces.
  • NORMAL, INVERSE, and FLASH map to ANSI terminal text attributes.
  • TEXT, GR, and HGR switch PassiBASIC's text/graphics mode flag for Apple-style source compatibility.
  • POKE address,value writes an 8-bit value to PassiBASIC's 64K byte memory array.
  • PEEK(address) reads an 8-bit value from that memory array.
  • SHAPE(n) selects one of ten built-in ASCII shapes, and DRAW(SHAPE(n)) renders it. DRAW(SHAPE(n)),x,y moves the cursor before drawing.

Core modules for these extensions live in core/: INIT.BAS sets default text state, GRAPHIN.BAS prepares graphics mode, and APPLEBUS.BAS initializes the Apple-style memory metadata used by demos. Load one with LOAD_CORE APPLEBUS and run it with RUN.

String Variables

PassiBASIC supports string variables:

10 A$ = "HELLO"
20 PRINT A$
30 B$ = CHR$(27) + "[31m"  : REM ANSI escape sequence
40 PRINT B$ + "RED TEXT" + CHR$(27) + "[0m"

String variables can have single-letter names (A$) or multi-character names (COLOR_RED$).

Assembly Program Loading

PassiBASIC supports loading assembly/machine code programs that can register USR functions callable from BASIC:

  • LOAD_BINARY <filename> - Load an assembly binary to register USR functions
  • USR(n)(value) - Call USR function n with the given value

PassiBASIC Binary Header

Assembly programs use the pb_binary_header_t structure defined in src/passibasic_portable.h:

typedef struct {
    uint16_t magic;         // Must be 0xBE42 (PB_BINARY_MAGIC)
    uint16_t version;       // Must be 0x0100 (PB_BINARY_VERSION)
    uint16_t func_count;    // Number of USR functions (max 16)
    uint16_t reserved;      // Must be 0
    void (*entry_point)(void);  // Optional entry point
    void (*func_pointers[16])(void);  // USR function pointers
    // ... callbacks for interacting with BASIC
} pb_binary_header_t;

Example Assembly Programs

  • arch/dos/USR_EXAMPLE.ASM - MS-DOS real-mode example with video mode switching
  • arch/dos/ENTRY.ASM - MS-DOS .COM entry with POKE-based video control
  • arch/avr/USR_EXAMPLE.S - AVR microcontroller example
  • examples/USR_EXAMPLE.c - Native platform C example

MS-DOS Video Mode Switching via POKE

On the MS-DOS port, POKE can change video resolutions to Apple IIc-like modes:

10 POKE 49152, 0  : REM 80x24 text with bigger fonts (default)
20 POKE 49152, 1  : REM Lowres Graphics  40 x 48
30 POKE 49152, 2  : REM Highres Graphics 280 x 192
40 POKE 49152, 3  : REM Double Highres   560 x 192
50 POKE 49152, 4  : REM Standard 80x25 text

USR Function Calling Convention

On native platforms (C), USR functions take a double argument and return a double:

double my_usr_func(double value) {
    return value * 2.0;  // Double the input
}

Then register and call:

LOAD_BINARY USR_EXAMPLE.C
PRINT USR(0)(21)  rem Prints 42.0

Portability

The core interpreter is intentionally separated from the host I/O layer so it can be adapted to smaller systems or calculator-like environments.

About

Familiar BASIC

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors