Post

HN
Hacker News

Commodore 64 Basic for PostgreSQL

LOAD "PL/CBMBASIC",8,1: Commodore 64 BASIC for PostgreSQL

If you are of a certain age, the words 38911 BASIC BYTES FREE will do something to you that no amount of therapy can undo. You remember the blue screen. You remember typing in three pages of a listing from a magazine, getting ?SYNTAX ERROR IN 2340 , and not knowing which of the three pages contained the typo. You remember that the disk drive was device 8, and that you had time to go make a cup of tea before it would finish loading.

PL/CBMBASIC is a procedural language extension that executes function bodies on Commodore 64 BASIC V2. The actual Microsoft/Commodore interpreter from 1982, by way of Michael Steil's cbmbasic project, which statically recompiled the 6502 ROM into C. That C is compiled into the extension's shared library, so the interpreter lives inside your backend process. Every function call is an in-memory power cycle: zero the 64KB RAM array, reset the CPU registers, and re-enter the ROM at $E394. The whole thing costs about 15 to 20 microseconds, which is roughly a thousand times faster than the original C64 ever managed, and quick enough to call per row over a large table without too much waiting.

Yes, those are line numbers, and they are mandatory. User code starts at line 10, because lines 0 to 9 are reserved: the extension injects your function arguments there as ordinary BASIC assignments before your code runs. A text parameter named who ends up as WHO$ , a smallint named lives becomes a LIVES% , and everything numeric otherwise lands in a 40-bit CBM float.

The validator has opinions, because BASIC V2 had opinions

Anyone who programmed a C64 discovered that you could not have a variable called TOTAL . The tokeniser truncated keywords, including inside identifiers, so TOTAL contained TO . SCORE contained OR . BUDGET contained GET . Only the first two characters of a name were significant, so USERNAME and USERID ... actually those were fine, US$ and US are different variables, but ALPHA and ALPS silently became the same string. And TI and ST were taken by the system.