Ultimate Basic v1.6.6 – Release Notes ====================================== 2026-10-18 – Unreleased (after 1.6.6) ------------------------------------------------------------------ New - option strings n [, m]: a computed string variable holds up to n characters (1-255, default 80), a string-array element up to m (default 31). Each variable keeps its own buffer. - Compile-time warnings: a byte variable that gets a constant it cannot hold (b = 300, b = a + 1000) is reported with its line. Warnings never stop the build. - With --basic-print, STR$ gives the C64 BASIC text for every number (" 7", "-42", " 3.5"); without it a byte keeps "007". - Struct types: field defaults (var hp: word = 100 - the array's contents at program start), nested struct fields (e[i].pos.x), fixed-length string fields (var name: string * 20), struct parameters (sub heal(p AS TEntity) ... heal(e[i])), and the QBasic form TYPE ... name AS type ... END TYPE. A struct element can be at most 256 bytes (a compile error says so). Changed - In a SUB / FUNCTION closed by END SUB / END FUNCTION, END alone on its line ends the program, as in QBasic (also inside IF ... END IF). Blocks in such routines are closed QBasic-style. Fixed - / with a WORD, INTEGER or negative divisor used only the low byte of the divisor: -700 / -7 gave 0, 50000 / (v + 0) was wrong. It is a 16-bit division now, truncated toward zero. - END and BYE inside a sub or function returned to the caller instead of ending the program. - A variable index into a struct array was multiplied in 8 bits, so elements beyond byte offset 255 were read and written wrongly. - Word struct fields were cut to 8 bits inside expressions, and word + x / word - x dropped the high byte of a 16-bit x (a word array element, a word function). 2026-10-17 – Release 1.6.6: PRINT USING, string order, floats ------------------------------------------------------------------ New - PRINT USING "format"; values (QBasic subset): numeric fields with # digits, . point, , thousands separators, a leading + (always a sign) and a trailing - (sign after the number); a number that does not fit is printed with a % in front. String fields & (whole string), ! (first character) and \ \ (as wide as the field); _ prints the next character as it is. Values cycle through the fields; a trailing ; or , keeps the cursor on the line. The format must be a string literal. - Strings can be ordered: < > <= >= compare in PETSCII order, a shorter string first when it starts the other ("AB" < "ABC"). - RND as a floating-point number: in a statement that computes in floating point, rnd / rnd() is 0 <= x < 1 (d = rnd, x = rnd() * 6). rnd(n) and integer statements keep the 0-255 / 0..n-1 generator. - MOD with a SINGLE / DOUBLE operand works in floating point, like VB / C fmod: 7.5 mod 2 = 1.5, -7.5 mod 2 = -1.5; x mod 0 = x. - Floating point in IRQ / NMI handlers: a handler sub (irq, nmi, cia_timer) that uses SINGLE / DOUBLE saves and restores the runtime state, so it no longer disturbs the main program. Handlers without floating point cost nothing extra. - --basic-print (or a line "option basic print" in the program): C64 BASIC PRINT spacing - numbers print with a leading space (or their minus sign) and a trailing space (print 5 gives " 5 "), a , between items moves to the next 10-column zone, a trailing , keeps the line. Without it the output is unchanged. Changed - Programs carry only the floating-point routines they use: a small program with + * and PRINT went from 4603 to 2293 bytes, examples/float_demo.ub from 6319 to 5660. - MOD with a WORD or INTEGER operand is a real 16-bit remainder with the sign of the dividend, like QBasic: -7 mod 3 = -1, 7 mod -3 = 1, (w + 5) mod 7 is no longer cut to 8 bits. - SHR of an INTEGER is an arithmetic shift: -8 shr 1 = -4. WORD and byte SHR stay logical. Fixed - A literal from 32768 to 65535 in a floating-point statement was read as a negative 16-bit pattern: d = 40000 gave -25536. It keeps its value now; integer statements are unchanged. 2026-10-17 – Release 1.6.5: 16-bit address expressions ------------------------------------------------------------------ Fixed - An address made of a 16-bit constant plus a byte variable was computed in 8 bits: peek($07F8 + k) read $00F8 + k, and poke $07F8 + k, v wrote into zero page. Addresses are now 16-bit in peek, poke, peek16, poke16, fill, memcopy, drawmem, save and reu (also the fill / memcopy length, e.g. 40 * rows). constant + byte compiles to LDA / STA $07F8,Y. - poke ptr + i, v with a word pointer adds in 16 bits. - peek(k) with a byte variable returned k itself; it now reads memory at $00kk. - poke16 addr, base + k wrote only the low byte of the value. 2026-10-09 – Release 1.6.4: floating point, variables in RAM, 12 KB arrays ------------------------------------------------------------------ New - SINGLE / DOUBLE are real floating-point numbers: 5 bytes, the C64 BASIC format (about 9 digits, +-2.9E-39 .. 1.7E+38). Operators + - * / and ^ (power), functions SQR SIN COS TAN ATN EXP LOG INT FIX CINT ABS SGN CSNG CDBL VAL, literals 1E6 / 2.5e-3 / .5 / 70000, comparisons, FOR with a floating-point counter and STEP, arrays (5 bytes per element), AS DOUBLE parameters and functions, PRINT / STR$ / string + in C64 BASIC format (.5, 1E+10), INPUT and READ. Assigning to BYTE / INTEGER / WORD rounds; FLOAT stays Q8.8. The runtime (about 4.4 KB) is generated by the compiler and only added when a program uses floating point; it does not call the BASIC ROM. See examples/float_demo.ub. Not for IRQ handlers. - Variables in RAM: when the variables do not fit into zero page ($02-$4F) the program is compiled again with the least-used variables in RAM (copied to zero page around the statements that use them). The memory map shows them as RAM:$xxxx. - 12 KB of arrays: when arrays need more than 4 KB they are placed at $A000-$CFFF; the BASIC ROM is banked out at program start and back in at every exit (end, bye, chain, end of program). - %01010101 binary literals. Changed - A leading minus binds to its operand: -5 - 3 is -8 (it was -(5 - 3) = -2). - 7 / 2 and 300 * 300 are no longer folded at parse time, so a DOUBLE gets 3.5 / 90000; integer contexts give the same result as before. Fixed - print 2.5 printed 640 (the raw Q8.8 value); now 2.50. - arrays declared inside subs or blocks all got address $C000 and overlapped. 2026-10-08 – Release 1.6.3: QBasic-style DIM, arrays, FUNCTION / SUB ------------------------------------------------------------------ New - dim name as type [= value] [, name as type ...]: BASIC-style typed declaration, same as var name: type. Types: byte/int (8-bit), integer/word (16-bit), single/double/float (Q8.8), string. Numbers start at 0, strings at "". dim a, b as integer types both. See examples/dim_demo.ub. - QBasic-style FUNCTION name(p AS type) AS type ... END FUNCTION and SUB name(p AS type) ... END SUB. Return a value by assigning to the function name; EXIT FUNCTION / EXIT SUB return early. END IF and END SELECT are accepted too. function = fn. - Subs can be called without parentheses: Koszont "Zsolt". - PRINT a; b; c joins items with ';' (trailing ';' = no newline). - Accented letters in strings print as the base letter (ü -> u). See examples/qbasic_demo.ub. - dim name(u1, u2, ...) as type: arrays for every type (byte, integer, single/double, string), any number of dimensions, bounds = highest index (dim t(2, 3) = 3 x 4). Index with t(i, j) or t[i, j]. - QBasic control flow: IF x = 3 and <> in conditions, single-line IF ... THEN ... ELSE ..., ELSEIF, DO [WHILE|UNTIL c] ... LOOP [WHILE| UNTIL c], WHILE ... WEND, SELECT CASE (a, b / lo TO hi / IS > n / CASE ELSE), EXIT DO / EXIT FOR / EXIT WHILE, END ends the program, ' comments. - Runtime strings: s = a + b (+ numbers), value copies (t = s), LEFT$ / RIGHT$ / MID$, LEN of any string expression, string = / <>, 16-bit STR$ (no leading zeros) and VAL. 80-char buffer per variable, 31-char slot per string-array element. - INTEGER is signed 16-bit (-32768..32767): print, compare, divide, ABS, FOR through zero, unary minus anywhere. WORD stays unsigned. - INPUT into INTEGER / WORD (16-bit), DOUBLE ("12.5"), array elements; INPUT "prompt"; x. - DOUBLE / DOUBLE is exact (the divisor's fraction was ignored). - Recursive subs / functions are a compile error (they compiled and returned wrong values: parameters live in fixed zero-page slots). - ROADMAP.md: deferred work (ROM floating point, variables in RAM, more array space). Fixed - for loops with a 16-bit counter wrapped at 256 (for x = 0 to 319 ran 64 times; wide_x_demo never drew past x = 255). - arrays over 256 bytes with a variable index wrote the wrong element. - print of a 16-bit function result printed only the low byte. - word x word multiplied by the right operand's low byte only (300 * 300 gave 13200); now a full 16x16 multiply (low 16 bits). - map_view unit test: u16 overflow in debug builds. - print of a word-array element printed 0; word-array elements in 16-bit arithmetic (w = t[i] + 5) used only the low byte. - word / float sub and fn parameters received only the low byte. - a string literal passed to a string parameter arrived as garbage. - s = "TEXT" and s = t on a string variable repoint the string; the assignment used to write one garbage byte into the pointer. 2026-10-04 – Release 1.6.2: tracker instruments ------------------------------------------------------------------ New (tune ... end) - imod id, vibdelay, vibspeed, vibdepth, pwmspeed, pwmmin, pwmmax: instrument vibrato (triangle LFO after a delay, depth scaled to the note's semitone) and pulse width modulation between min and max. - ifilt id, cutend, sweep, pingpong: filter cutoff sweep from the inst cutoff toward cutend, sweep per frame, optionally back and forth. - igate id, gatetimer, hardrestart, firstwave: gate released gatetimer frames before the next note, hard restart also zeroes ADSR, firstwave is written on a note's first frame ($09 = test + gate). - itab id, speed, loop, "WW +n" / ".. -n" / "WW =n": wave / arpeggio table (up to 32 steps), one step every speed frames, loop step or 255. - inst ctrl may carry ring modulation ($04) / sync ($02); modevol bit 7 = voice 3 off. Changed - The player now works every frame (tables, vibrato, PWM, gate timer, filter sweep). Filter routing is per voice: the voice that starts a filter-routed instrument owns cutoff / resonance / mode, $D417 routes every voice whose instrument is filter-routed. A tune blob is about 2.5 KB of player code plus its data. - Same algorithm as the Visual Assembler SID editor's player; the new tests/tune_player.rs compares the SID registers frame by frame with a trace of the editor's engine. 2026-10-03 – Release 1.6.1: smooth scrolling maps ------------------------------------------------------------------ New - map view px, py: shows the loaded map at a pixel position, once per frame (instead of wait raster). XSCROLL / YSCROLL with 38 columns / 24 rows, two screen buffers ($0400 / $3C00) swapped at char steps, the next char cell built two frames ahead, color RAM copied in two halves behind / ahead of the raster beam: smooth and tear-free in every direction. Sprite pointers are copied to both buffers. - map load reads a VisualAssembler Level Editor project (.bin) and composes its screens into one map (max 6x10 screens, 255x255 cells). - map load "file", addr: the map data goes to a fixed address (like incbin "file", addr) instead of inline in the code. - Compile errors: map view without map load, maps smaller than 40x25, program code reaching into $3C00-$3FFF. - Example: examples/level_scroll_demo.ub. Fixes - A byte product or shift assigned to a word variable inside a sum was truncated to 8 bits (py = cy * 8 + fy gave 67 instead of 323 for cy = 40, fy = 3); it is now computed in 16 bits, like a lone product. w = b shl n keeps 16 bits too. - A constant multiplier above 255 was cut to 8 bits (cy * 300); the 16-bit operand now always takes the multiplicand side. 2026-10-03 – Release 1.6.0: optimised 6502 code generation ------------------------------------------------------------------ Performance - Conditions (if / while / until / select) compile to CMP + branch instead of materialising a 0/1 value and testing it again (`if x == 10`: 24 -> 9 bytes). `x > n` becomes `x >= n+1`; and / or of comparisons short-circuit when the right side is side-effect free; while loops are rotated (test at the bottom); select compares the variable in place. - Constants and byte variables are used directly as operands (ADC #n, CMP zp) instead of being staged in scratch zero page; poke to a constant or word address stores directly; identity operations vanish. - `*` by a constant: shifts / shift-add (x * 8 -> 3x ASL); otherwise a shift-add loop of at most 8 rounds (the old repeated-addition loop needed ~16 cycles per unit of the multiplier). - `/` and `mod` by a power of two: LSR / AND #(n-1); otherwise an 8-round shift-subtract loop (the old loop ran once per unit of the quotient). - x = x +/- 1|2 -> INC / DEC (word: 16-bit INC / DEC for +/-1). - Arrays with a variable index use base,Y addressing instead of a zero-page pointer. - for loops are rotated (no JMP per iteration); constant limits / steps are immediates and use no zero page. - A-register reuse: the leading LDA of a statement is skipped when it reloads the value the previous statement just stored. Fixes - Division by zero used to hang: now x / 0 = 255 and x mod 0 = x. - `for i = 0 to 255` looped forever; the step now detects the 8-bit wrap-around in both directions, so the loop runs 256 times and stops. Tests - Full 6502 emulator for tests (tests/common/cpu6502.rs), semantic tests that run compiled programs (tests/codegen_semantics.rs), code-shape / cycle tests (tests/codegen_opt.rs) and an ignored differential fuzzer against a reference compiler (tests/differential_fuzz.rs). 2026-09-26 – chain: load and start another program ------------------------------------------------------------------ New language elements - Added `chain "FILE" [, device]`: loads another program to its own load address (normally $0801, right over the running program) and RUNs it, as if LOAD"FILE",8,1 and RUN had been typed. For boot / title programs. A 46-byte position-independent loader and the file name (1-16 characters) are copied to the cassette buffer $033C. Before the load the I/O is reset (VIC IRQs off, SID volume 0, IOINIT, RESTOR, $01 = $37); after it the end-of-program pointer $2D/$2E is set, BASIC is re-initialised ($E453, $E3BF - a self-extracting cruncher such as Exomizer sfx may have used BASIC's zero page) and the program is RUN ($A659, $A7AE). Without a device the drive the program came from ($BA) is used, else drive 8. If the file cannot be loaded, the program continues with the statement after `chain`. Fixes - `load`: the secondary address was swapped. `load "FILE"` used secondary 0 with X/Y = 0 and loaded the file to $0000; `load "FILE", addr` used secondary 1 and ignored `addr`. Now `load "FILE"` loads to the file's own address (secondary 1) and `load "FILE", addr` to `addr` (secondary 0). - `--d64`: directory entries were written 30 bytes apart instead of 32, so every file after the first had a broken entry (e.g. `--add data.prg` showed up as a garbled name and could not be loaded). Also fixed: disk ID and DOS type were at the wrong BAM offsets; file data only used tracks 1-17 (a larger disk crashed the build instead of reporting it); sectors are now allocated like the 1541 DOS does (tracks 17->1, then 19->35, interleave 10). A full disk is reported as "D64 error: disk full ...". New tests: tests/d64_tests.rs reads the image back (BAM, directory, sector chains) and compares every file. 2026-09-25 – Initialised arrays ------------------------------------------------------------------ New language elements - Added `data : v, v, ...`: fills a declared `array` / `array_word` with constant values. Further lines continue where the previous one stopped; word arrays take 16-bit values (stored lo, hi). The values are stored after the code and copied into the array once at program start (right after the arrays are zeroed), so the table is writable and indexed like any other array (`sinus[i]`). These lines do not affect `read`. An undeclared name or more values than the array holds is a compile-time error. This is what the Visual Assembler Curve Editor's "Export to UltimateBasic" and "Export UltimateBasic demo" generate. 2026-09-21 – Tracker tunes and an inline-assembler fix ------------------------------------------------------------------ New language elements - Added `tune ... end`: describe a 3-voice SID tracker tune (instruments, order list, per-voice pattern rows such as "C-4 01 V24") directly in the source. The compiler builds a self-contained, zero-page-free player at compile time and defines `sid_init` / `sid_play`, so `music play|stop| pause|resume` work exactly as with `load sid`. Vibrato, slide, note cut and speed change are supported. `tune at $addr` moves the blob (default $8000). This is what the Visual Assembler SID editor's "Export to UltimateBasic" now generates. Fixes - Inline `asm { }`: `label,X`, `label,Y` and `JMP (label)` were assembled as plain absolute instructions (the index/indirect mode was dropped), so table lookups such as `LDA table,X` read the wrong byte. The addressing mode is now kept. - `music play`: the CIA1 IRQ wrapper acknowledged the timer by WRITING $01 to $DC0D, which clears the interrupt mask, so the music IRQ stopped after the first tick. It now acknowledges by reading $DC0D. 2026-09-21 – Custom charsets, code layout and non-blocking sound ------------------------------------------------------------------ New language elements - Added `charset on` / `charset off`. `charset addr` (default $3800) used to only set the destination of `chardef`; `charset on` now points the VIC-II at that RAM set (read-modify-write of $D018 bits 1-3, the screen-matrix bits are kept) and `charset off` restores the ROM set ($1000, or $1800 after `lowercase`). The base must be a multiple of $800 inside VIC bank 0. - Added a build-time check that generated code does not overlap the charset: `charset on` claims the 2 KB set and every `chardef` its 8 bytes; a program that reaches into them stops with "the program code (...) overlaps the charset area ...". Data in an `org` gap is not counted. - Added `org addr`. Placed between sub/fn definitions it continues the subroutine code at `addr` and zero-fills the gap, which stays free for data (fonts, sprites, tables). Subs never fall through, so this is safe; `org` below the current code end is an error. - Extended `incbin` with `incbin "file", addr, skip [, len]`: skip a header (e.g. a .prg load address) and/or take only a slice. `incbin ..., addr` can now be written into an `org` gap. - Added `sfx channel, freq, frames [, wave]`: a non-blocking SID note. It sets attack 0 / sustain 0 / release 0 and picks the decay from `frames` (1 frame = 20 ms) at compile time, re-triggers the voice and returns at once. `wave` is 16 (triangle), 32 (saw, default), 64 (pulse) or 128 (noise). Unlike `sound` it is safe inside a game loop. Fixes - `sound` waited on raster line 0, which $D012 (low 8 bits) shows twice per frame (lines 0 and 256), so notes were half as long as requested; two of its branches were also patched over their opcode, crashing the program for any non-zero duration. It now waits on raster line 200 like `delay`. - `word` assignments computed products in 8 bits: `w += 300 * level`, `w = w + 100 * level` and `w = 100 * level + 900` now keep all 16 bits. - `print a / 10` (and other arithmetic on a `float`) printed the raw Q8.8 value as an integer; it now prints `N.DD`. - Arrays are zeroed once at program start (RAM contents at power-up are random; `array(N)` previously started with whatever was there). - Running out of permanent zero page ($02-$4F) is now a compile-time error ("out of zero page"). Before, variables and `for` limit/step bytes silently spilled into the scratch area and broke loops. Sequential `for` loops now release their two limit/step bytes when the loop ends (if the body declared no variables), so many loops no longer exhaust it. - Manual corrections: `%` binary literals were documented but never supported by the lexer (use $hex or decimal); the `charset` example used the $D018 value of another address ($1E selects $3800, $1A selects $2800). - Tests: a missing `ROL zp` opcode in the test CPU was added, and the koala tests no longer race on a shared temp file. Ultimate Basic v1.5.6 – Release Notes ====================================== 2026-09-06 – Hires draw color + multicolor shapes -------------------------------------------------- - Added `color pen c`: sets a persistent hires drawing color (0-15). The plot/line/rect/circle/paint helpers stamp it into the video-matrix foreground nibble of every cell they touch; the background nibble is preserved. Default is white (1), so programs that never call `color pen` render exactly as before. Emitted only when `color pen` is used, so the plot helper is unchanged for existing programs. - Added multicolor shape commands `mline`, `mrect`, and `mcircle` (joining `mplot`). The trailing `color` argument is the 2-bit source (0-3); the actual colors come from the cell palette (screen / color RAM), exactly as for `mplot`. They reuse the hires Bresenham/midpoint routines via a shared draw-target switch, plotting each pixel through the mplot helper. `mline` and `mrect` require x in 0-159; `mcircle` clips off-screen points. Ultimate Basic v1.5.5 – Release Notes ====================================== 2026-08-26 – Magic Desk CRT export -------------------------------------------------- - Added `.crt` output support: when the output filename ends in `.crt`, the compiler now writes a Commodore 64 cartridge image instead of a raw PRG. - The cartridge uses the same banked Magic Desk type-19 layout as VisualAssembler: 64-byte header, bank 0 boot loader, and the compiled PRG payload copied into RAM on startup. - Existing `.prg` and `.d64` output paths are unchanged. - Added integration tests covering the CRT header, bank layout, payload copy, and boot stub. 2026-08-18 – Struct types (`type ... endtype`) -------------------------------------------------- - New user-defined struct types with `type NAME ... endtype` blocks. Fields are declared inside as `var name: int`, `var name: word`, or `var name: float`. Element size is the sum of field widths (no padding). type TEntity var x: int var y: int var hp: word # 1 + 1 + 2 = 4 bytes per element endtype - Array-of-struct declarations look like regular arrays: var enemies: TEntity = array(N) ; allocates N * elem_size bytes at $C000+ - Field access on both sides of assignment: enemies[0].x = 5 ; constant idx → STA absolute enemies[i].hp = enemies[i].hp + 1 ; variable idx → shift-add mul + (ptr),Y - Constant-index writes/reads fold to bare LDA/STA absolute. Variable-index access emits a small shift-and-add multiplier for idx * elem_size (uses ASL A chains for power-of-two sizes, or a shift-add sequence for arbitrary sizes via two scratch zero-page bytes), then indexed (ptr),Y access. - Word and float fields write both bytes (little-endian): STA addr / STA addr+1 for constant idx, STA (ptr),Y ; INY ; STA (ptr),Y for variable idx. - Float fields use Q8.8 fixed-point format (hi byte = integer, lo byte = fraction × 256). Reading a float field into a `float` variable works via gen_word_assign; printing a float struct field uses print_fixed ("N.DD"). - The parser resolves `arr[i].field` into Stmt::StructSet and Expr::StructGet nodes that carry (field_offset, field_kind, elem_size) — codegen is self-contained and needs no type table lookup. - Not yet implemented in this release: struct-typed sub/fn parameters, default field values (parsed for compatibility with the proposal but not initialized at allocation time), nested struct fields, multi-dimensional struct arrays, string fields. Errors reported: struct-typed var without array(N) initializer, and unknown-field access. - Added `examples/type_demo.ub` and CPU-run integration tests for constant and variable index, int, word, and float field kinds, and the unknown-field error. 2026-08-18 – Count-down for-loop fix -------------------------------------------------- - `for` / `loop` with a negative constant `step` (e.g. `for i = 20 to 0 step -2`) used to compile but never enter the body, and — for values that wrap past 0 — loop forever. The exit test was unsigned-only, so counting down from 20 to 0 kept re-entering after the 254 (= -2 mod 256) wrap-around. - The compiler now inspects the sign of a constant `step` at code generation: * positive step or default +1 → BCC/BEQ to body, unchanged (exit when var > to) * negative constant step → BCS to body (exit when var < to), plus a post-increment `BCS loop_top ; JMP exit` that catches the ADC underflow (carry clear) when var wraps below 0. This is what keeps `for i = N to 0 step -k` finite. - A default-step `for`/`loop` where `from > to` (e.g. `loop i = 10 to 1`, no `step`) used to silently skip the body — 0 iterations, no diagnostic. It is now a compile-time error: "for-loop: from (10) > to (1) with default step +1 loops 0 times — use 'step -1' to count down" - Non-constant `step` (variable or expression) is still treated as positive at compile time. Use a `while` loop when you need count-down with a runtime step. - Added `examples/countdown_demo.ub` (working forms) and `examples/countdown_errors_demo.ub` (the compile-time error form). - Added integration tests: a codegen check that count-down loops emit `BCS` for the body branch, a check that count-up loops still emit `BCC` + `BEQ`, `should_panic` coverage of the from>to default-step error, and CPU-run tests that execute the loop and verify it terminates with the expected iteration count. 2026-08-18 – --explicit CLI flag -------------------------------------------------- - Added the `--explicit` build flag: ub build myprog.ub --explicit With the flag, every `var`, `sub`-parameter, and `fn`-parameter declaration must carry a `:type` annotation. Untyped declarations become compile-time errors: line 12: 'explicit' mode: 'var loose' has no type — use 'var loose: int|word|float|string' line 14: 'explicit' mode: parameter 'a' has no type — use 'a: int|word|float|string' - Array declarations (`array(N)`, `array_word(N)`) and `const NAME = value` are unaffected — their type is fixed by the declaration form. - The flag is CLI-only; no source-level directive keyword. Existing programs compile unchanged without the flag. Add it to a Makefile / build script to enforce typed style project-wide. - Added `examples/explicit_demo.ub` (annotated code that builds under the flag) and `examples/explicit_errors_demo.ub` (loose code that builds without the flag but reports errors with it). - Added integration tests covering the typed-ok case, untyped var / sub-param / fn-param errors, and the without-flag regression. Ultimate Basic v1.5.3 – Release Notes ====================================== 2026-08-18 – Multi-dimensional arrays -------------------------------------------------- - Arrays can now be declared with more than one dimension using a comma-separated dimension list, for both byte and word arrays: var grid = array(8, 8) # 8x8 = 64 bytes var wm = array_word(4, 4) # 4x4 word elements = 32 bytes - Elements are indexed with a comma-separated subscript list and stored row-major; the flat offset is base + i0*(d1*..) + i1*(d2*..) + ... : grid[row, col] = 42 var v = grid[row, col] - Any number of dimensions is supported. Dimensions must be compile-time constants (integer literals or `const` values). - When every subscript is a constant the address is folded at compile time to a single absolute store/load; a variable subscript emits the row*stride + col computation followed by an indexed (ptr),Y access. - A single subscript into a multi-dimensional array is still allowed and is treated as a flat/linear index (e.g. grid[10]). - Indexing with a subscript count that is neither 1 nor the declared rank is reported as a compile-time error. - Implemented entirely in the parser (multi-index folds to one flat index expression), so code generation is unchanged. - Added examples/array2d_demo.ub and integration tests covering constant and variable indices, row-major layout, word-element stride, linear access, const-derived dimensions, and the wrong-rank error. 2026-08-18 – PETSCII bracket encoding fix -------------------------------------------------- - Fixed string encoding of the '[' , ']' and '^' characters, which previously fell through to the unknown-character placeholder and printed as '?'. - They now emit their correct C64 codes ($5B, $5D, $5E). These code points are identical in the uppercase/graphics and lowercase charsets, so the fix is correct in both `uppercase` and `lowercase` modes. - Added a regression test for bracket encoding in both charset modes. Ultimate Basic v1.5.2 – Release Notes ====================================== 2026-08-15 – Readable assembly codegen listings -------------------------------------------------- - Added the `--asm` build option: ub build demo.ub --asm A successful build writes `demo.asm` next to the selected `.prg` output. - The listing is generated from compiler metadata rather than being only a bare disassembly of the completed PRG. - UB statement boundaries are retained as comments alongside their emitted code. - Zero-page variables, arrays, subroutines, BASIC labels, relative branches, and in-program JMP/JSR targets receive readable symbols or generated labels. - Each instruction includes its final C64 address and exact machine-code bytes. - Compiler-generated helpers are included in final memory order, while unknown opcodes are preserved as `.byte` directives. - Helper entry points now use descriptive `ub_helper_*` labels. - Known data regions (DATA, maps, sprite/character definitions, lookup tables, incbins, SID and Koala payloads) are emitted as named `.byte` blocks instead of being disassembled as instructions; long zero gaps use `.fill`. - Output uses reassemblable KickAssembler syntax, including `.label` constants and a valid `* = origin` program counter directive. - Added automated listing tests and full README.md, MANUAL.md, CLI-help, and developer-guide documentation. Ultimate Basic v1.5.1 – Release Notes ====================================== 2026-08-15 – Koala Painter image import -------------------------------------------------- - Added compile-time loading of standard and raw Koala Painter images: koala load "picture.kla" koala show koala hide - Added file, memory-layout, and SID-conflict diagnostics plus emulation-backed tests and full manual documentation. 2026-08-15 – Character tile maps -------------------------------------------------- - Added compile-time loading and validation of self-describing `.ubmap` files: map load "level.ubmap" VisualAssembler `me-map` `.bin` exports are also accepted directly, without an `.ubmap` conversion step. - Added 40x25 viewport rendering from arbitrary map origins: map draw map_x, map_y Character codes go to $0400 and optional per-cell colors go to $D800. - Added writable runtime access with `map_tile()`, `map_color()`, `map set`, and `map color`, allowing game logic and destructible maps without reloading data. - Added normal and multicolor character-map modes. Multicolor maps configure $D016 MCM and the three shared colors in $D021-$D023. - Documented the byte-exact UBMP v1 format, flags, row-major arrays, viewport constraints, and charset relationship in MANUAL.md and CLAUDE.md. - Added emulation-backed tests for normal/multicolor setup, screen and color-RAM rendering, tile/color mutation and queries, and invalid-file diagnostics. 2026-08-12 – Debug symbol exports -------------------------------------------------- - Added side-effect-free software bounding-box collision detection: var hit = box_hit(l1, t1, r1, b1, l2, t2, r2, b2) It returns 1 for overlapping or edge-touching inclusive AABBs and 0 otherwise, without reading or clearing the VIC-II $D01E/$D01F collision registers. - Extended `sprite_frame` with an optional animation frame expression: sprite_frame id, base_addr, frame Consecutive frames occupy 64-byte slots; the original two-argument syntax is unchanged and remains backward compatible. - Added emulation-backed integration tests for overlap, separation, touching edges, and runtime animation-frame pointer selection. - Added the `--debug` build option: ub build demo.ub --debug A successful build now writes three debugger files next to the `.prg`, using the output file's stem. - Added KickAssembler-compatible `.sym` export. It can be imported by assembler source and contains resolved symbols in `.label name = $address` form. - Added C64Debugger/RetroDebugger `.dbg` export in KickAssembler debug-dump XML format. It contains the UltimateBasic program segment, source filename, and resolved address labels. - Added VICE `.vs` monitor-command export. It contains `al C:address .label` commands and can be loaded with VICE's `-moncommands` option or `ll` command. - Debug exports include `program_start`, `program_end`, zero-page variables, arrays, subroutines, and BASIC labels. - BASIC labels are now retained with their final machine-code addresses in the compiler memory map, making them available to all debug exporters. - Symbol names are sanitized for debugger compatibility, and source paths are XML-escaped in `.dbg` output. - Added unit coverage for all three symbol syntaxes and documented the new CLI option and file formats in README.md, MANUAL.md, and CLAUDE.md. - Current limitation: `.dbg` provides segments and address symbols, but does not yet contain instruction-to-source-line mappings for source-level stepping. Ultimate Basic v1.5.0 – Release Notes ====================================== 2026-06-25 – Double buffering + full-width X -------------------------------------------------- - **Double-buffered hires bitmap** for flicker-free animation: graphics on double # two complete bitmaps; drawing goes to the hidden one gcls # clears the hidden back buffer ... draw a frame ... # plot/line/circle/rect/paint all hit the back buffer flip # show the drawn buffer, draw into the other one Buffer A = bitmap $2000 / matrix $0400 (VIC bank 0); buffer B = bitmap $6000 / matrix $4400 (VIC bank 1). Only $DD00 selects which is shown ($D018 stays $18 for both). `flip` waits for the lower border (raster >= 251) before switching the VIC bank, so the swap is tear-free, then redirects drawing to the now-hidden buffer. - All pixel commands and `gcls` now write through a runtime "draw base" (two zero-page bytes: bitmap hi + matrix hi), initialised to the single-buffer layout ($2000/$0400) at program start. Single-buffer programs are byte-for-byte unaffected in behaviour; `flip` simply repoints the base at the hidden buffer. - Requirements: hires only (not multicolor); the back buffer uses $4000-$7FFF, so program code must stay below $4400; not combinable with sprites across a flip. On a stock 1 MHz C64 the per-frame full gcls limits frame rate — raise `speed` on the Commodore 64 Ultimate for smooth high-rate animation. - **Full 320-pixel X coordinate range** for plot/line/circle/rect: X values above 255 are handled automatically (9th X bit added in the pixel helper), so drawing reaches the right edge of the screen. Use a `word` variable for X when it can exceed 255. - **rect / rect erase / rect xor** — rectangle outline (4 edges) in hires bitmap mode. - Fix: assigning an 8-bit expression to an existing `word` variable (e.g. `w = cos(a)` after `w = w * 70`) now clears the high byte. Previously a stale high byte survived and corrupted later 16-bit arithmetic. - New examples: examples/cube_demo.ub – tumbling 3D wireframe cube, double-buffered examples/wide_x_demo.ub – verifies plot/line/circle/rect past X=255 examples/reu_bitmap_demo.ub – full-width (0-319) random lines/circles + REU Ultimate Basic v1.4.4 – Release Notes ====================================== 2026-06-14 – Strict variables + mouse support -------------------------------------------------- - **BREAKING**: Strict variable checking — all variables must be declared with `var` before use. The parser now pre-scans all tokens (including included files) to collect `var` declarations, then reports an error for any undeclared variable reference in expressions, assignments, for/loop counters, inc/dec, input, and read statements. var x = 0 # REQUIRED before for-loop for x = 1 to 10 print x next print kukk # ERROR: variable 'kukk' is not declared Sub/fn parameters are automatically added to the declared set so they can be used inside the body. irq/nmi/cia_timer handler names are exempt (they reference subroutines, not variables). - 1351 proportional mouse support via mouse_x(), mouse_y(), mouse_btn() Built-in mouse_read_helper assembly subroutine handles: CIA1 $DC00 capacitor charging, LDX#$67 delay, SID POT X/Y read, signed 7-bit delta computation, Y-axis EOR#$FF inversion, accumulated position tracking, and dual-sample per frame. - mouse_btn() reads $DC01 (control port 1) — bit0=left, bit1=right. - mouse_x() returns accum_x via JSR to helper; mouse_y() reads accum_y directly (avoids double-update per frame). - Word var assignment (sx: word = mouse_x()) sets both lo/hi bytes for proper $D010 MSB handling by the sprite command. - 9-bit X carry/borrow via accum_x_hi (INC/DEC on overflow). - Demo: examples/mouse_demo.ub — 1351 mouse pointer sprite with button feedback (left=red border, right=blue background). - Fixed: KERNAL IRQ touches $DC00 during keyboard scan → corrupts POT; demo disables CIA1 interrupts (poke $DC0D, $7F + asm { SEI }). - Fixed: helper RTS must return LDA accum_x (not leftover raw_y). - Fixed: mouse helper ZP zeroed before game loop (fill $02, 7, 0). - Fixed: helper init uses same charge_delay as do_delta for consistent POT readings (no initial delta jump). - Fixed: prev_raw only updated when delta != 0 (matches original). Ultimate Basic v1.4.3 – Release Notes ====================================== Recent development notes (2026-06-12) -------------------------------------------------- 2026-06-12 - Added `fn` keyword — functions with return values. fn square(x) → 8-bit return (result in A register) return x * x end fn get_ptr(): word → 16-bit return (result in fn_ret_zp pair) return $C000 end var s = square(9) # fn call as expression var ptr: word = get_ptr() # word return - Typed subroutine parameters are now preserved end-to-end: sub init_message(src:string) var c = src[i] # string indexing → LDA (ptr),Y end The parser, AST, and codegen all propagate string, int, word, float annotations on sub/fn parameters. - Unused variable reporting: the build output now lists variables that are declared but never read (tracked via mark_used across all variable read paths — eval_expr, print, inc/dec, array get/set, string params). - New example: examples/function_demo.ub — demonstrates fn with multiple return paths, word params, and expression-context calls. Ultimate Basic v1.4.2 – Release Notes ====================================== Recent development notes (2026-05-30 / 2026-05-31) -------------------------------------------------- 2026-05-31 - Added parallax starfield example programs: examples/parallax.ub examples/parallax_demo.ub examples/text_scroll_demo.ub - Added smooth text-scroller demo using hardware horizontal fine scroll. - Added new scroll helpers for pixel-scrolling examples: scroll x n narrow (set x fine-scroll and force 38-column mode) scroll x n wide (set x fine-scroll and restore 40-column mode) scroll row R left (shift one screen RAM row left by one character) - Reworked text-scroll example to use UltimateBasic commands instead of inline asm for 38/40-column mode and row shifting. - Clarified documentation: semicolon is not a BASIC comment marker; it is an asm-source comment marker inside asm { } blocks. BASIC comments are # and rem. - Added focused tests for scroll x narrow/wide, scroll row left, and semicolon handling. 2026-05-30 - Added graphics on block: 80x50 chunky block-pixel mode using a custom 4-pixel charset at $2800, with no bitmap RAM required. - Added plot4 x, y and plot4 erase x, y for setting and clearing block pixels. - Added circle4 x, y, r for midpoint circle outlines in 80x50 block-pixel mode. - Fixed gcls in block mode so it clears all screen/color RAM pages correctly; the old descending DEX/BPL loop failed for counts >= 128. - Added lowercase and uppercase commands for switching C64 charset mode via CHROUT. - Updated TENPRINT example to demonstrate lowercase charset mode. - Removed temporary test/demo files from tmp/. New language features --------------------- Variables & types - float type (Q8.8 fixed-point): var f: float = 3.5 / int(f) / print f ("N.DD") - array_word(N): 16-bit word arrays at $C000+ - Compound assignments: and= or= xor= shl= shr= - Full 16-bit arithmetic on word vars: * / mod shl shr and or xor - inc/dec carry-aware for word variables Control flow - for/next with optional step and continue - repeat/until (do-while) - select/case/else - gosub label / return - continue / break in all loop types Print & formatting - spc(n), tab(n) in print - print at col, row, ... (no trailing newline) - hex(n), bin(n), dec(n, width) - numstr var, addr (8-bit int → 3-digit decimal string) Math & string functions - sin(angle), cos(angle) (0–255 lookup table) - rnd(n) (rnd() mod n) - min, max, abs, sgn - val(s) (decimal string → 8-bit int) - s[i] (string character by index) Screen & display - screen col, row, char [, color] (direct screen/color RAM write) - display on / display off (VIC DEN bit, independent of mode) - scroll x n / scroll y n (hardware fine-scroll registers) - scroll x n narrow / scroll x n wide (fine scroll + 38/40-column mode control) - scroll row R left (single screen-row character shift for smooth scrollers) - lowercase / uppercase (switch C64 charset mode) - cursor col, row Bitmap graphics - graphics on multi (multicolor bitmap 160×200, 4 colours/cell) - mplot x, y, color (multicolor pixel; requires graphics on multi) - plot erase, plot xor, line, paint Block graphics (80×50) - graphics on block (chunky 80×50 mode; custom 4-pixel charset @ $2800; no bitmap RAM) - plot4 x, y / plot4 erase x, y (set/clear a block pixel, x: 0-79, y: 0-49) - circle4 x, y, r (draw clipped midpoint circle outlines in block-pixel coordinates) - gcls clears screen RAM $0400-$07FF + color RAM $D800-$DBFF in block mode - Fix: gcls block-mode no longer leaves the bottom ~6 rows uncleared (the old descending LDX #231/DEX/BPL loop ran only once for counts ≥128; replaced with forward INX/BNE page loops) Sprites & charset - sprite_frame id, addr (update data pointer at runtime) - sprdef id...end (inline 63-byte shape + auto pointer; binary literals) - sprite multicolor / expand x/y / priority - charset base / chardef id...end (custom character definitions) SID & music - sid volume N / sid stop - load sid "file.sid" [, addr] (compile-time embed; defines sid_init/sid_play) - music play [N] (CIA1 timer A 50 Hz IRQ + wrapper; auto-installs handler) - music stop / pause / resume Interrupts & timing - nmi handler / nmi_exit - cia_timer period, handler - irq_exit (JMP $EA81) - delay N (N PAL frames) - wait raster N Error handling - onerr goto label (KERNAL I/O error vector $0300/$0301; forward refs OK) Memory & I/O - peek16 / poke16 (16-bit little-endian) - fill, memcopy, drawmem - reu stash / fetch / swap + reu_present() - load / save / open / close / print# / input - data / read Ultimate 64 - speed N / speed max / speed off - badlines on / off - turbo() CLI --- - Binary renamed from ultimate-basic to ub - --d64 [file] produce .d64 disk image - --add add extra files to .d64 (repeatable) - -v / --verbose zero-page layout + hex dump