EkBass commited on
Commit
c18531e
·
verified ·
1 Parent(s): ea33f99

Upload BazzBasic-AI-guide-19032026.md

Browse files
Files changed (1) hide show
  1. BazzBasic-AI-guide-19032026.md +759 -0
BazzBasic-AI-guide-19032026.md ADDED
@@ -0,0 +1,759 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ > METADATA:
2
+ > Name: BazzBasic
3
+
4
+ > Description: BazzBasic BASIC interpreter language reference. Use when writing, debugging, or explaining BazzBasic code (.bas files). Triggers on BazzBasic syntax, BASIC programming with $ and # suffixes, SDL2 graphics in BASIC, or references to BazzBasic interpreter features
5
+
6
+ > About: BazzBasic is built around one simple idea: starting programming should feel nice and even fun. Ease of learning, comfort of exploration and small but important moments of success. Just like the classic BASICs of decades past, but with a fresh and modern feel.
7
+
8
+ > Purpose: This guide has been provided with the idea that it would be easy and efficient for a modern AI to use this guide and through this either guide a new programmer to the secrets of BazzBasic or, if necessary, generate code himself.
9
+
10
+ > Version: This guide is written for BazzBasic version 1.0 and is updated 19.03.2026 09:51 Finnish time.
11
+
12
+ ---
13
+
14
+ # BazzBasic Language Reference
15
+
16
+ BazzBasic is a BASIC interpreter for .NET 10 with SDL2 graphics and SDL2_mixer sound support. It is not a clone of any previous BASIC — it aims to be easy, fun, and modern. Released under MIT license.
17
+
18
+ **Version:** 1.0 (Released February 22, 2026)
19
+ **Author:** Kristian Virtanen (krisu.virtanen@gmail.com)
20
+ **Platform:** Windows (x64 primary); Linux/macOS possible with effort
21
+ **Dependencies:** SDL2.dll, SDL2_mixer (bundled).
22
+ **Github:** https://github.com/EkBass/BazzBasic
23
+ **Homepage:** https://ekbass.github.io/BazzBasic/
24
+ **Manual:** "https://ekbass.github.io/BazzBasic/manual/#/"
25
+ **Examples:** "https://github.com/EkBass/BazzBasic/tree/main/Examples"
26
+ **Github_repo:** "https://github.com/EkBass/BazzBasic"
27
+ **Github_discussions:** "https://github.com/EkBass/BazzBasic/discussions"
28
+ **Discord_channel:** "https://discord.com/channels/682603735515529216/1464283741919907932"
29
+ **Thinbasic subforum:** "https://www.thinbasic.com/community/forumdisplay.php?401-BazzBasic"
30
+
31
+ ## Few examples:
32
+ **raycaster_3d:** https://raw.githubusercontent.com/EkBass/BazzBasic/refs/heads/main/Examples/raycaster_3d_optimized.bas
33
+ **voxel_terrain:** https://raw.githubusercontent.com/EkBass/BazzBasic/refs/heads/main/Examples/voxel_terrain.bas
34
+ **sprite load:** https://github.com/EkBass/BazzBasic/blob/main/Examples/countdown_demo.bas
35
+ **Eliza:** https://github.com/EkBass/BazzBasic/blob/main/Examples/Eliza.bas
36
+
37
+ ## CLI Usage
38
+
39
+ | Command | Action |
40
+ |---------|--------|
41
+ | `bazzbasic.exe` | Launch IDE |
42
+ | `bazzbasic.exe file.bas` | Run program |
43
+ | `bazzbasic.exe -exe file.bas` | Create standalone .exe |
44
+ | `bazzbasic.exe -lib file.bas` | Create tokenized library (.bb) |
45
+
46
+ IDE shortcuts: F5 run, Ctrl+N/O/S new/open/save, Ctrl+Shift+S save as, Ctrl+W close tab, Ctrl+F find, Ctrl+H replace.
47
+
48
+ ### External syntax colors.
49
+ BazzBasic IDE is developed just so double-clicking *bazzbasic.exe* would bring something in the screen of a newbie. A person can use it, but it stands no chance for more advanced editors.
50
+
51
+ There are syntax color files for *Notepad++*, *Geany* and *Visual Studio Code* available at https://github.com/EkBass/BazzBasic/tree/main/extras
52
+
53
+ ---
54
+
55
+ ## Syntax Fundamentals
56
+
57
+ ### Variables and Constants
58
+ Forget traditional BASIC types. Suffixes in BazzBasic define mutability, not data type.
59
+
60
+ Variables and arrays in BazzBasic are typeless: hold numbers or strings interchangeably
61
+
62
+ - $ = Mutable Variable
63
+ - # = Immutable Constant
64
+
65
+
66
+ ```basic
67
+ LET a$ ' Declare without value
68
+ LET name$ = "Alice" ' Variable, string (mutable, $ suffix)
69
+ LET age$ = 19 ' Variable, integer (mutable, $ suffix)
70
+ LET price$ = 1.99 ' Variable, decimal (mutable, $ suffix)
71
+ LET PI# = 3.14159 ' Constant (immutable, # suffix)
72
+ LET x$, y$, z$ = 10 ' Multiple declaration
73
+ ```
74
+ - All variables require `$` suffix, constants require `#`
75
+ - Typeless: hold numbers or strings interchangeably
76
+ - Must declare with `LET` before use (except FOR/INPUT which auto-declare)
77
+ - Assignment after declaration: `x$ = x$ + 1` (no LET needed)
78
+ - **Case-insensitive**: `PRINT`, `print`, `Print` all work
79
+ - Naming: letters, numbers, underscores; cannot start with number
80
+
81
+ ### Comparison Behavior
82
+ `"123" = 123` is TRUE (cross-type comparison), but slower — keep types consistent.
83
+
84
+ ### Scope
85
+ - Main code shares one scope (even inside IF blocks)
86
+ - `DEF FN` functions have completely isolated scope
87
+ - Only global constants (`#`) are accessible inside functions
88
+
89
+ ### Multiple Statements Per Line
90
+ ```basic
91
+ COLOR 14, 0 : CLS : PRINT "Hello"
92
+ ```
93
+
94
+ ### Comments
95
+ ```basic
96
+ REM This is a comment
97
+ ' This is also a comment
98
+ PRINT "Hello" ' Inline comment
99
+ ```
100
+
101
+ ### Escape Sequences in Strings
102
+ | Sequence | Result |
103
+ |----------|--------|
104
+ | `\"` | Quote |
105
+ | `\n` | Newline |
106
+ | `\t` | Tab |
107
+ | `\\` | Backslash |
108
+
109
+ ---
110
+
111
+ ## Arrays
112
+ ```basic
113
+ DIM scores$ ' Declare (must use DIM)
114
+ DIM a$, b$, c$ ' Multiple declaration
115
+ scores$(0) = 95 ' Numeric index (0-based)
116
+ scores$("name") = "Alice" ' String key (associative)
117
+ matrix$(0, 1) = "A2" ' Multi-dimensional
118
+ data$(1, "header") = "Name" ' Mixed indexing
119
+ ```
120
+ - Array names must end with `$`
121
+ - Fully dynamic: numeric, string, multi-dimensional, mixed indexing
122
+ - Arrays **cannot** be passed directly to functions — pass values of individual elements
123
+ - Accessing uninitialized elements is an error — check with `HASKEY` first
124
+
125
+ ### Array Functions
126
+ | Function | Description |
127
+ |----------|-------------|
128
+ | `LEN(arr$())` | Element count (note: empty parens) |
129
+ | `HASKEY(arr$(key))` | 1 if exists, 0 if not |
130
+ | `DELKEY arr$(key)` | Remove element |
131
+ | `DELARRAY arr$` | Remove entire array (can re-DIM after) |
132
+
133
+ ---
134
+
135
+ ## Operators
136
+
137
+ ### Arithmetic
138
+ `+` (add/concatenate), `-`, `*`, `/` (returns float)
139
+
140
+ ### Comparison
141
+ `=` or `==`, `<>` or `!=`, `<`, `>`, `<=`, `>=`
142
+
143
+ ### Logical
144
+ `AND`, `OR`, `NOT`
145
+
146
+ ### Precedence (high to low)
147
+ `()` → `NOT` → `*`, `/` → `+`, `-` → comparisons → `AND` → `OR`
148
+
149
+ ---
150
+
151
+ ## User-Defined Functions
152
+ ```basic
153
+ DEF FN add$(a$, b$)
154
+ RETURN a$ + b$
155
+ END DEF
156
+ PRINT FN add$(3, 4) ' Call with FN prefix
157
+ ```
158
+ - Function name **must** end with `$`, called with `FN` prefix
159
+ - **Must be defined before called** (top of file or via INCLUDE)
160
+ - Parameters passed **by value**
161
+ - Completely isolated scope: no access to global variables, only global constants (`#`)
162
+ - Labels inside functions are local — GOTO/GOSUB **cannot** jump outside (error)
163
+ - Supports recursion
164
+ - Tip: put functions in separate files, `INCLUDE` at program start
165
+
166
+ ---
167
+
168
+ ## Control Flow
169
+
170
+ ### IF Statements
171
+ ```basic
172
+ ' Block IF (END IF and ENDIF both work)
173
+ IF x$ > 10 THEN
174
+ PRINT "big"
175
+ ELSEIF x$ > 5 THEN
176
+ PRINT "medium"
177
+ ELSE
178
+ PRINT "small"
179
+ ENDIF
180
+
181
+ ' One-line IF (GOTO/GOSUB only)
182
+ IF lives$ = 0 THEN GOTO [game_over]
183
+ IF key$ = KEY_ESC# THEN GOTO [menu] ELSE GOTO [continue]
184
+ IF ready$ = 1 THEN GOSUB [start_game]
185
+ ```
186
+
187
+ ### FOR Loops
188
+ ```basic
189
+ FOR i$ = 1 TO 10 STEP 2 ' Auto-declares variable, STEP optional
190
+ PRINT i$
191
+ NEXT
192
+
193
+ FOR i$ = 10 TO 1 STEP -1 ' Count down
194
+ PRINT i$
195
+ NEXT
196
+ ```
197
+
198
+ ### WHILE Loops
199
+ ```basic
200
+ WHILE x$ < 100
201
+ x$ = x$ * 2
202
+ WEND
203
+ ```
204
+
205
+ ### Labels, GOTO, GOSUB
206
+ ```basic
207
+ [start]
208
+ GOSUB [subroutine]
209
+ GOTO [start]
210
+ END
211
+
212
+ [subroutine]
213
+ PRINT "Hello"
214
+ RETURN
215
+ ```
216
+
217
+ ### Dynamic Jumps (Labels as Variables)
218
+ ```basic
219
+ LET target$ = "[menu]"
220
+ GOTO target$ ' Variable holds label string
221
+ LET dest# = "[jump]"
222
+ GOSUB dest# ' Constants work too
223
+ ```
224
+
225
+ If you want to make a dynamic jump, use the "[" and "]" characters to indicate to BazzBasic that it is specifically a label.
226
+
227
+ ```basic
228
+ LET target$ = "[menu]" ' Correct way
229
+ LET target$ = "menu" ' Incorrect way
230
+ ```
231
+
232
+ ### Other
233
+ | Command | Description |
234
+ |---------|-------------|
235
+ | `SLEEP ms` | Pause execution |
236
+ | `END` | Terminate program |
237
+
238
+ ---
239
+
240
+ ## I/O Commands
241
+
242
+ | Command | Description |
243
+ |---------|-------------|
244
+ | `PRINT expr; expr` | Output (`;` = no space, `,` = tab) |
245
+ | `PRINT "text";` | Trailing `;` suppresses newline |
246
+ | `INPUT "prompt", var$` | Read input (splits on whitespace/comma) |
247
+ | `INPUT "prompt", a$, b$` | Read multiple values |
248
+ | `INPUT var$` | Default prompt `"? "` |
249
+ | `LINE INPUT "prompt", var$` | Read entire line including spaces |
250
+ | `CLS` | Clear screen |
251
+ | `LOCATE row, col` | Move cursor (1-based) |
252
+ | `COLOR fg, bg` | Set colors (0-15 palette) |
253
+ | `GETCONSOLE(row, col, type)` | Console read: 0=char(ASCII), 1=fg, 2=bg |
254
+ | `INKEY` | Non-blocking key check (0 if none, >256 for special keys) |
255
+ | `KEYDOWN(key#)` | Returns TRUE if specified key is currently held down |
256
+
257
+ ### INPUT vs LINE INPUT
258
+ | Feature | INPUT | LINE INPUT |
259
+ |---------|-------|------------|
260
+ | Reads spaces | No (splits) | Yes |
261
+ | Multiple variables | Yes | No |
262
+ | Default prompt | `"? "` | None |
263
+
264
+ ### INKEY vs KEYDOWN
265
+ | Feature | INKEY | KEYDOWN |
266
+ |---------|-------|---------|
267
+ | Returns | Key value or 0 | TRUE/FALSE |
268
+ | Key held | Reports once | Reports while held |
269
+ | Use case | Menu navigation | Game movement, held keys |
270
+
271
+ ```basic
272
+ ' KEYDOWN example — smooth movement
273
+ IF KEYDOWN(KEY_LEFT#) THEN x$ = x$ - 5
274
+ IF KEYDOWN(KEY_RIGHT#) THEN x$ = x$ + 5
275
+ ```
276
+
277
+ ---
278
+
279
+ ## Math Functions
280
+
281
+ | Function | Description |
282
+ |----------|-------------|
283
+ | `ABS(n)` | Absolute value |
284
+ | `ATAN(n)` | Returns the arc tangent of n |
285
+ | `BETWEEN(n, min, max)` | TRUE if n is in range |
286
+ | `CEIL(n)` | Rounds up |
287
+ | `CINT(n)` | Convert to integer (rounds) |
288
+ | `COS(n)` | Returns the cosine of an angle |
289
+ | `CLAMP(n, min, max)` | Constrain value to range |
290
+ | `DEG(radians)` | Radians to degrees |
291
+ | `DISTANCE(x1,y1,x2,y2)` | 2D Euclidean distance |
292
+ | `DISTANCE(x1,y1,z1,x2,y2,z2)` | 3D Euclidean distance |
293
+ | `EXP(n)` | Exponential (e^n) |
294
+ | `FLOOR(n)` | Rounds down |
295
+ | `INT(n)` | Truncate toward zero |
296
+ | `LERP(start, end, t)` | Linear interpolation (t = 0.0-1.0) |
297
+ | `LOG(n)` | Natural log |
298
+ | `MAX(a, b)` | Returns higher from a & b |
299
+ | `MIN(a, b)` | Returns smaller from a & b |
300
+ | `MOD(a, b)` | Remainder |
301
+ | `POW(base, exp)` | Power |
302
+ | `RAD(degrees)` | Degrees to radians |
303
+ | `RND(n)` | Random 0 to n-1 |
304
+ | `ROUND(n)` | Standard rounding |
305
+ | `SGN(n)` | Sign (-1, 0, 1) |
306
+ | `SIN(n)` | Returns the sine of n |
307
+ | `SQR(n)` | Square root |
308
+ | `TAN(n)` | Returns the tangent of n |
309
+
310
+
311
+ ### Math Constants
312
+ | Constant | Value | Notes |
313
+ |----------|-------|-------|
314
+ | `PI` | 3.14159265358979 | 180° |
315
+ | `HPI` | 1.5707963267929895 | 90° (PI/2) |
316
+ | `QPI` | 0.7853981633974483 | 45° (PI/4) |
317
+ | `TAU` | 6.283185307179586 | 360° (PI*2) |
318
+ | `EULER` | 2.718281828459045 | e |
319
+
320
+ All are raw-coded values — no math at runtime, maximum performance.
321
+
322
+ ### Fast Trigonometry (Lookup Tables)
323
+ For graphics-intensive applications — ~20x faster than SIN/COS, 1-degree precision.
324
+
325
+ ```basic
326
+ FastTrig(TRUE) ' Enable lookup tables (~5.6 KB)
327
+
328
+ LET x$ = FastCos(45) ' Degrees, auto-normalized to 0-359
329
+ LET y$ = FastSin(90)
330
+ LET r$ = FastRad(180) ' Degrees to radians (doesn't need FastTrig)
331
+
332
+ FastTrig(FALSE) ' Free memory when done
333
+ ```
334
+
335
+ **Use FastTrig when:** raycasting, rotating sprites, particle systems, any loop calling trig hundreds of times per frame.
336
+ **Use regular SIN/COS when:** high precision needed, one-time calculations.
337
+
338
+ ---
339
+
340
+ ## String Functions
341
+
342
+ | Function | Description |
343
+ |----------|-------------|
344
+ | `ASC(s$)` | Character to ASCII code |
345
+ | `CHR(n)` | ASCII code to character |
346
+ | `INSTR(s$, search$)` | Find substring position (0 = not found) |
347
+ | `INSTR(start$, s$, search$)` | Find substring starting from position start$ (0 = not found) |
348
+ | `INVERT(s$)` | Inverts a string |
349
+ | `LCASE(s$)` | Converts to lowercase |
350
+ | `LEFT(s$, n)` | First n characters |
351
+ | `LEN(s$)` | String length |
352
+ | `LTRIM(s$)` | Left trim |
353
+ | `MID(s$, start, len)` | Substring (1-based) len optional |
354
+ | `REPEAT(s$, n)` | Repeat s$ for n times |
355
+ | `REPLACE(s$, old$, new$)` | Replace all occurrences |
356
+ | `RIGHT(s$, n)` | Last n characters |
357
+ | `RTRIM(s$)` | Right trim |
358
+ | `SPLIT(s$, delim$, arr$)` | Split into array |
359
+ | `SRAND(n)` | Returns random string length of n from allowed chars (letters, numbers and "_") |
360
+ | `STR(n)` | Number to string |
361
+ | `TRIM(s$)` | Remove leading/trailing spaces |
362
+ | `UCASE(s$)` | Converts to uppercase |
363
+ | `VAL(s$)` | String to number |
364
+
365
+ ---
366
+
367
+ ## File I/O
368
+
369
+ ```basic
370
+ ' Simple text file
371
+ FileWrite "save.txt", data$
372
+ LET data$ = FileRead("save.txt")
373
+
374
+ ' Array read/write (key=value format)
375
+ DIM a$
376
+ a$("name") = "player1"
377
+ a$("score") = 9999
378
+ FileWrite "scores.txt", a$
379
+
380
+ DIM b$
381
+ LET b$ = FileRead("scores.txt")
382
+ PRINT b$("name") ' Output: player1
383
+ ```
384
+
385
+ **Array file format:**
386
+ ```
387
+ name=player1
388
+ score=9999
389
+ multi,dim,key=value
390
+ ```
391
+
392
+ | Function/Command | Description |
393
+ |---------|-------------|
394
+ | `FileRead(path)` | Read file; returns string or populates array |
395
+ | `FileWrite path, data` | Write string or array to file |
396
+ | `FileExists(path)` | Returns 1 if file exists, 0 if not |
397
+ | `FileDelete path` | Delete a file |
398
+ | `FileList(path$, arr$)` | List files in directory into array |
399
+
400
+ ---
401
+
402
+ ## Network (HTTP)
403
+
404
+ ```basic
405
+ DIM response$
406
+ LET response$ = HTTPGET("https://api.example.com/data")
407
+ PRINT response$
408
+
409
+ DIM result$
410
+ LET result$ = HTTPPOST("https://api.example.com/post", "{""key"":""value""}")
411
+ PRINT result$
412
+ ```
413
+
414
+ - Returns response body as string
415
+ - Supports HTTPS
416
+ - Use `""` inside strings to escape quotes in JSON bodies
417
+ - Timeout handled gracefully — returns error message string on failure
418
+
419
+ ---
420
+
421
+ ## Sound (SDL2_mixer)
422
+
423
+ ```basic
424
+ DIM bgm$
425
+ LET bgm$ = LOADSOUND("music.wav")
426
+ LET sfx$ = LOADSOUND("jump.wav")
427
+
428
+ SOUNDREPEAT(bgm$) ' Loop continuously
429
+ SOUNDONCE(sfx$) ' Play once
430
+ SOUNDSTOP(bgm$) ' Stop specific sound
431
+ SOUNDSTOPALL ' Stop all sounds
432
+ ```
433
+
434
+ | Command | Description |
435
+ |---------|-------------|
436
+ | `LOADSOUND(path)` | Load sound file, returns ID |
437
+ | `SOUNDONCE(id$)` | Play once |
438
+ | `SOUNDREPEAT(id$)` | Loop continuously |
439
+ | `SOUNDSTOP(id$)` | Stop specific sound |
440
+ | `SOUNDSTOPALL` | Stop all sounds |
441
+
442
+ - Formats: WAV (recommended), MP3, others via SDL2_mixer
443
+ - Thread-safe, multiple simultaneous sounds supported
444
+ - Load sounds once at startup for performance
445
+
446
+ ---
447
+
448
+ ## Graphics (SDL2)
449
+
450
+ ### Screen Setup
451
+ ```basic
452
+ SCREEN 12 ' 640x480 VGA mode
453
+ SCREEN 0, 800, 600, "Title" ' Custom size with title
454
+ ```
455
+ Modes: 0=640x400, 1=320x200, 2=640x350, 7=320x200, 9=640x350, 12=640x480, 13=320x200
456
+
457
+ ### Fullscreen
458
+ ```basic
459
+ FULLSCREEN TRUE ' Borderless fullscreen
460
+ FULLSCREEN FALSE ' Windowed mode
461
+ ```
462
+ Call after `SCREEN`.
463
+
464
+ ### VSync
465
+ ```basic
466
+ VSYNC(TRUE) ' Enable (default) — caps to monitor refresh
467
+ VSYNC(FALSE) ' Disable — unlimited FPS, may tear
468
+ ```
469
+
470
+ ### Double Buffering (Required for Animation)
471
+ ```basic
472
+ SCREENLOCK ON ' Start buffering
473
+ ' ... draw commands ...
474
+ SCREENLOCK OFF ' Display frame
475
+ SLEEP 16 ' ~60 FPS
476
+ ```
477
+ `SCREENLOCK` without argument = `SCREENLOCK ON`. Do math/logic outside SCREENLOCK block.
478
+
479
+ ### Drawing Primitives
480
+ | Command | Description |
481
+ |---------|-------------|
482
+ | `PSET (x, y), color` | Draw pixel |
483
+ | `POINT(x, y)` | Read pixel color (returns RGB integer) |
484
+ | `LINE (x1,y1)-(x2,y2), color` | Draw line |
485
+ | `LINE (x1,y1)-(x2,y2), color, B` | Box outline |
486
+ | `LINE (x1,y1)-(x2,y2), color, BF` | Filled box (faster than CLS) |
487
+ | `CIRCLE (cx, cy), r, color` | Circle outline |
488
+ | `CIRCLE (cx, cy), r, color, 1` | Filled circle |
489
+ | `PAINT (x, y), fill, border` | Flood fill |
490
+ | `RGB(r, g, b)` | Create color (0-255 each) |
491
+
492
+ ### Shape/Sprite System
493
+ ```basic
494
+ DIM sprite$
495
+ sprite$ = LOADSHAPE("RECTANGLE", 50, 50, RGB(255,0,0)) ' Types: RECTANGLE, CIRCLE, TRIANGLE
496
+ sprite$ = LOADIMAGE("player.png") ' PNG (with alpha) or BMP
497
+
498
+ MOVESHAPE sprite$, x, y ' Position (top-left point)
499
+ ROTATESHAPE sprite$, angle ' Absolute degrees
500
+ SCALESHAPE sprite$, 1.5 ' 1.0 = original
501
+ SHOWSHAPE sprite$
502
+ HIDESHAPE sprite$
503
+ DRAWSHAPE sprite$ ' Render
504
+ REMOVESHAPE sprite$ ' Free memory
505
+ ```
506
+ - PNG recommended (full alpha transparency 0-255), BMP for legacy
507
+ - Images positioned by their **top-left point**
508
+ - Rotation is absolute, not cumulative
509
+ - Always REMOVESHAPE when done to free memory
510
+
511
+ ### Sprite Sheets (LOADSHEET)
512
+ ```basic
513
+ DIM sprites$
514
+ LOADSHEET sprites$, spriteW, spriteH, "sheet.png"
515
+
516
+ ' Access sprites by 1-based index
517
+ MOVESHAPE sprites$(index$), x#, y#
518
+ DRAWSHAPE sprites$(index$)
519
+ ```
520
+ - Sprites indexed left-to-right, top-to-bottom starting at 1
521
+ - All sprites must be same size (spriteW x spriteH)
522
+
523
+ ### Mouse Input (Graphics Mode Only)
524
+ | Function | Description |
525
+ |----------|-------------|
526
+ | `MOUSEX` / `MOUSEY` | Cursor position |
527
+ | `MOUSEB` | Button state (bitmask, use `AND`) |
528
+
529
+ Button constants: `MOUSE_LEFT#`=1, `MOUSE_RIGHT#`=2, `MOUSE_MIDDLE#`=4
530
+
531
+ ### Color Palette (0-15)
532
+ | 0 Black | 4 Red | 8 Dark Gray | 12 Light Red |
533
+ |---------|-------|-------------|--------------|
534
+ | 1 Blue | 5 Magenta | 9 Light Blue | 13 Light Magenta |
535
+ | 2 Green | 6 Brown | 10 Light Green | 14 Yellow |
536
+ | 3 Cyan | 7 Light Gray | 11 Light Cyan | 15 White |
537
+
538
+ ### Performance Tips
539
+ 1. Use `SCREENLOCK ON/OFF` for all animation
540
+ 2. `LINE...BF` is faster than `CLS` for clearing
541
+ 3. Store `RGB()` values in constants
542
+ 4. REMOVESHAPE unused shapes
543
+ 5. SLEEP 16 for ~60 FPS
544
+ 6. Do math/logic outside SCREENLOCK block
545
+
546
+ ---
547
+
548
+ ## Built-in Constants
549
+
550
+ ### Arrow Keys
551
+ | | | |
552
+ |---|---|---|
553
+ | `KEY_UP#` | `KEY_DOWN#` | `KEY_LEFT#` |
554
+ | `KEY_RIGHT#` | | |
555
+
556
+ ### Special Keys
557
+ | | | |
558
+ |---|---|---|
559
+ | `KEY_ESC#` | `KEY_TAB#` | `KEY_BACKSPACE#` |
560
+ | `KEY_ENTER#` | `KEY_SPACE#` | `KEY_INSERT#` |
561
+ | `KEY_DELETE#` | `KEY_HOME#` | `KEY_END#` |
562
+ | `KEY_PGUP#` | `KEY_PGDN#` | |
563
+
564
+ ### Modifier Keys
565
+ | | | |
566
+ |---|---|---|
567
+ | `KEY_LSHIFT#` | `KEY_RSHIFT#` | `KEY_LCTRL#` |
568
+ | `KEY_RCTRL#` | `KEY_LALT#` | `KEY_RALT#` |
569
+ | `KEY_LWIN#` | `KEY_RWIN#` | |
570
+
571
+ ### Function Keys
572
+ | | | |
573
+ |---|---|---|
574
+ | `KEY_F1#` | `KEY_F2#` | `KEY_F3#` |
575
+ | `KEY_F4#` | `KEY_F5#` | `KEY_F6#` |
576
+ | `KEY_F7#` | `KEY_F8#` | `KEY_F9#` |
577
+ | `KEY_F10#` | `KEY_F11#` | `KEY_F12#` |
578
+
579
+ ### Numpad Keys
580
+ | | | |
581
+ |---|---|---|
582
+ | `KEY_NUMPAD0#` | `KEY_NUMPAD1#` | `KEY_NUMPAD2#` |
583
+ | `KEY_NUMPAD3#` | `KEY_NUMPAD4#` | `KEY_NUMPAD5#` |
584
+ | `KEY_NUMPAD6#` | `KEY_NUMPAD7#` | `KEY_NUMPAD8#` |
585
+ | `KEY_NUMPAD9#` | | |
586
+
587
+ ### Punctuation Keys
588
+ | | | |
589
+ |---|---|---|
590
+ | `KEY_COMMA#` | `KEY_DOT#` | `KEY_MINUS#` |
591
+ | `KEY_EQUALS#` | `KEY_SLASH#` | `KEY_BACKSLASH#` |
592
+ | `KEY_SEP#` | `KEY_GRAVE#` | `KEY_LBRACKET#` |
593
+ | `KEY_RBRACKET#` | | |
594
+
595
+ ### Alphabet Keys
596
+ | | | |
597
+ |---|---|---|
598
+ | `KEY_A#` | `KEY_B#` | `KEY_C#` |
599
+ | `KEY_D#` | `KEY_E#` | `KEY_F#` |
600
+ | `KEY_G#` | `KEY_H#` | `KEY_I#` |
601
+ | `KEY_J#` | `KEY_K#` | `KEY_L#` |
602
+ | `KEY_M#` | `KEY_N#` | `KEY_O#` |
603
+ | `KEY_P#` | `KEY_Q#` | `KEY_R#` |
604
+ | `KEY_S#` | `KEY_T#` | `KEY_U#` |
605
+ | `KEY_V#` | `KEY_W#` | `KEY_X#` |
606
+ | `KEY_Y#` | `KEY_Z#` | |
607
+
608
+ ### Number Keys
609
+ | | | |
610
+ |---|---|---|
611
+ | `KEY_0#` | `KEY_1#` | `KEY_2#` |
612
+ | `KEY_3#` | `KEY_4#` | `KEY_5#` |
613
+ | `KEY_6#` | `KEY_7#` | `KEY_8#` |
614
+ | `KEY_9#` | | |
615
+
616
+ ### Mouse
617
+ ```basic
618
+ MOUSE_LEFT# = 1, MOUSE_RIGHT# = 2, MOUSE_MIDDLE# = 4
619
+ ```
620
+
621
+ ### Logical
622
+ `TRUE` = 1, `FALSE` = 0
623
+
624
+ ---
625
+
626
+ ## Source Control
627
+
628
+ ### INCLUDE
629
+ ```basic
630
+ INCLUDE "other_file.bas" ' Insert source at this point
631
+ INCLUDE "MathLib.bb" ' Include compiled library
632
+ ```
633
+
634
+ ### Libraries (.bb files)
635
+ ```basic
636
+ ' MathLib.bas — can ONLY contain DEF FN functions
637
+ DEF FN add$(x$, y$)
638
+ RETURN x$ + y$
639
+ END DEF
640
+ ```
641
+ Compile: `bazzbasic.exe -lib MathLib.bas` → `MathLib.bb`
642
+
643
+ ```basic
644
+ INCLUDE "MathLib.bb"
645
+ PRINT FN MATHLIB_add$(5, 3) ' Auto-prefix: FILENAME_ + functionName
646
+ ```
647
+ - Libraries can only contain `DEF FN` functions
648
+ - Library functions can access main program constants (`#`)
649
+ - Version-locked: .bb may not work across BazzBasic versions
650
+
651
+ ---
652
+
653
+ ## Common Patterns
654
+
655
+ ### Game Loop
656
+ ```basic
657
+ SCREEN 12
658
+ LET running$ = TRUE
659
+
660
+ WHILE running$
661
+ LET key$ = INKEY
662
+ IF key$ = KEY_ESC# THEN running$ = FALSE
663
+
664
+ ' Math and logic here
665
+
666
+ SCREENLOCK ON
667
+ LINE (0,0)-(640,480), 0, BF ' Fast clear
668
+ ' Draw game state
669
+ SCREENLOCK OFF
670
+ SLEEP 16
671
+ WEND
672
+ END
673
+ ```
674
+
675
+ ### HTTP + Data
676
+ ```basic
677
+ DIM response$
678
+ LET response$ = HTTPGET("https://api.example.com/scores")
679
+ PRINT response$
680
+
681
+ DIM payload$
682
+ LET payload$ = HTTPPOST("https://api.example.com/submit", "{""score"":9999}")
683
+ PRINT payload$
684
+ ```
685
+
686
+ ### Save/Load with Arrays
687
+ ```basic
688
+ DIM save$
689
+ save$("level") = 3
690
+ save$("hp") = 80
691
+ FileWrite "save.txt", save$
692
+
693
+ DIM load$
694
+ LET load$ = FileRead("save.txt")
695
+ PRINT load$("level") ' Output: 3
696
+ ```
697
+
698
+ ### Sound with Graphics
699
+ ```basic
700
+ SCREEN 12
701
+ LET bgm$ = LOADSOUND("music.wav")
702
+ LET sfx$ = LOADSOUND("jump.wav")
703
+ SOUNDREPEAT(bgm$)
704
+
705
+ WHILE INKEY <> KEY_ESC#
706
+ IF INKEY = KEY_SPACE# THEN SOUNDONCE(sfx$)
707
+ SLEEP 16
708
+ WEND
709
+ SOUNDSTOPALL
710
+ END
711
+ ```
712
+
713
+ ---
714
+
715
+ ## Code Style Conventions
716
+
717
+ **Variables** — `camelCase$`
718
+ ```basic
719
+ LET playerName$ = "Hero"
720
+ LET score$ = 0
721
+ ```
722
+
723
+ **Constants** — `UPPER_SNAKE_CASE#`
724
+ ```basic
725
+ LET MAX_HEALTH# = 100
726
+ LET SCREEN_W# = 640
727
+ ```
728
+
729
+ **Arrays** — `camelCase$` (like variables, declared with DIM)
730
+ ```basic
731
+ DIM scores$
732
+ DIM playerData$
733
+ ```
734
+
735
+ **User-defined functions** — `PascalCase$`
736
+ ```basic
737
+ DEF FN CalculateDamage$(attack$, defence$)
738
+ DEF FN IsColliding$(x$, y$)
739
+ ```
740
+
741
+ **Labels** — descriptive names, `[sub:]` prefix recommended for subroutines
742
+ ```basic
743
+ [sub:DrawPlayer] ' Subroutine
744
+ [gameLoop] ' Jump target
745
+ ```
746
+
747
+ ### Program Structure
748
+ 1. Constants first
749
+ 2. User-defined functions (or INCLUDE them)
750
+ 3. Main program loop
751
+ 4. Subroutines (labels) last
752
+
753
+ ### Subroutine Indentation
754
+ ```basic
755
+ [sub:DrawPlayer]
756
+ MOVESHAPE player$, x$, y$
757
+ DRAWSHAPE player$
758
+ RETURN
759
+ ```