Improved commands reference

This commit is contained in:
Mattias Hansson 2026-04-16 07:02:59 +02:00
parent aa59cf8008
commit 5e71adff2b

View file

@ -1,5 +1,47 @@
# Compiler Commands Reference # Compiler Commands Reference
## Index
- [ADD](#add) - Adds two values
- [AND](#and) - Bitwise AND operation
- [BREAK](#break) - Exits current loop
- [BYTE](#byte) - Declares 8-bit variable or constant
- [CALL](#call) - Calls function with parameters
- [CASE](#case) - Case branch in SWITCH statement
- [DEC](#dec) - Decrements variable or memory location
- [DEFAULT](#default) - Default branch in SWITCH statement
- [ELSE](#else) - Alternative branch in IF statement
- [ENDIF](#endif) - Terminates IF block
- [ENDSWITCH](#endswitch) - Terminates SWITCH block
- [FEND](#fend) - Ends function definition
- [FOR](#for) - Loop with automatic counter increment
- [FUNC](#func) - Defines function with parameters
- [GOSUB](#gosub) - Calls subroutine with register passing
- [GOTO](#goto) - Unconditional jump to label
- [IF](#if) - Conditional execution
- [INC](#inc) - Increments variable or memory location
- [LABEL](#label) - Creates named assembly label
- [LET](#let) - Assigns value to variable
- [NEXT](#next) - Terminates FOR loop
- [OR](#or) - Bitwise OR operation
- [ORIGIN](#origin) - Sets assembly origin address
- [PEEK](#peek) - Reads byte from memory
- [PEEKW](#peekw) - Reads word from memory
- [POINTER](#pointer) - Sets pointer to address
- [POKE](#poke) - Writes byte to memory
- [POKEW](#pokew) - Writes word to memory
- [SUBEND](#subend) - Returns from subroutine
- [SHIFTL](#shiftl) - Logical shift left
- [SHIFTR](#shiftr) - Logical shift right
- [SUBTR](#subtr) - Subtracts values
- [SWITCH](#switch) - Multi-way branching
- [WEND](#wend) - Terminates WHILE loop
- [WHILE](#while) - Loop while condition true
- [WORD](#word) - Declares 16-bit variable or constant
- [XOR](#xor) - Bitwise XOR operation
---
## ADD ## ADD
Adds two values and stores result in destination. Adds two values and stores result in destination.
@ -46,13 +88,18 @@ BREAK
``` ```
**Examples:** **Examples:**
``` ```
// BREAK in FOR loop
FOR i = 0 TO 100 FOR i = 0 TO 100
IF i = 50 IF i = 50
BREAK BREAK
ENDIF ENDIF
NEXT NEXT
```
```
// BREAK in WHILE loop
WHILE counter < 1000 WHILE counter < 1000
counter++ counter++
IF error IF error
@ -117,10 +164,7 @@ process("hello",42,myvar)
Defines a case branch within SWITCH statement. Defines a case branch within SWITCH statement.
**Syntax:** See [SWITCH](#switch) for syntax and examples.
```
See SWITCH
```
--- ---
@ -136,11 +180,21 @@ DECREMENT <target>
``` ```
**Examples:** **Examples:**
``` ```
// Modern: decrement variables
counter-- counter--
lives-- lives--
index-- index--
```
```
// Alternative: decrement memory location
DEC $D020 DEC $D020
```
```
// Legacy: DECREMENT form
DECREMENT screenColor DECREMENT screenColor
``` ```
@ -150,10 +204,7 @@ DECREMENT screenColor
Defines the default branch in SWITCH statement. Defines the default branch in SWITCH statement.
**Syntax:** See [SWITCH](#switch) for syntax and examples.
```
See SWITCH
```
--- ---
@ -161,10 +212,7 @@ See SWITCH
Alternative branch in IF statement. Alternative branch in IF statement.
**Syntax:** See [IF](#if) for syntax and examples.
```
See IF
```
--- ---
@ -172,10 +220,7 @@ See IF
Terminates IF block. Terminates IF block.
**Syntax:** See [IF](#if) for syntax and examples.
```
See IF
```
--- ---
@ -183,10 +228,7 @@ See IF
Terminates SWITCH block. Terminates SWITCH block.
**Syntax:** See [SWITCH](#switch) for syntax and examples.
```
See SWITCH
```
--- ---
@ -194,10 +236,7 @@ See SWITCH
Ends a function definition. Ends a function definition.
**Syntax:** See [FUNC](#func) for syntax and examples.
```
See FUNC
```
--- ---
@ -211,11 +250,16 @@ FOR <iterator> = <start_value> TO <end_value>
``` ```
**Examples:** **Examples:**
``` ```
// FOR loop with literal values
FOR i = 0 TO 10 FOR i = 0 TO 10
screen = i screen = i
NEXT NEXT
```
```
// FOR loop with variables
FOR counter = start TO finish FOR counter = start TO finish
process(counter) process(counter)
NEXT NEXT
@ -247,28 +291,37 @@ FUNC name ( in:x out:y io:z ) # direction with pre-declared (legacy)
``` ```
**Examples:** **Examples:**
``` ```
// Modern: self-contained function with local parameters // Modern: self-contained function with local parameters
FUNC add({BYTE a} {BYTE b} out:{BYTE result}) FUNC add({BYTE a} {BYTE b} out:{BYTE result})
result = a + b result = a + b
FEND FEND
```
```
// Modern: with direction modifiers // Modern: with direction modifiers
FUNC process(in:{BYTE input} out:{BYTE output}) FUNC process(in:{BYTE input} out:{BYTE output})
output = input + 1 output = input + 1
FEND FEND
```
```
// Modern: io parameter (read-write) // Modern: io parameter (read-write)
FUNC increment(io:{BYTE counter}) FUNC increment(io:{BYTE counter})
counter = counter + 1 counter = counter + 1
FEND FEND
```
```
// Modern: absolute address parameter // Modern: absolute address parameter
FUNC read_byte({BYTE data @ $fa}) FUNC read_byte({BYTE data @ $fa})
BYTE temp BYTE temp
temp = data // Reads from $fa temp = data // Reads from $fa
FEND FEND
```
```
// Legacy: uses global variables directly // Legacy: uses global variables directly
BYTE x BYTE x
BYTE y BYTE y
@ -336,17 +389,25 @@ IF <param1> [<operator> <param2>]
Operators: `=` `==` `<>` `!=` `>` `<` `>=` `<=` Operators: `=` `==` `<>` `!=` `>` `<` `>=` `<=`
**Examples:** **Examples:**
``` ```
// Simple IF statement
IF count == 10 IF count == 10
result = 1 result = 1
ENDIF ENDIF
```
```
// IF with ELSE branch
IF value > threshold IF value > threshold
process(value) process(value)
ELSE ELSE
skip(value) skip(value)
ENDIF ENDIF
```
```
// IF-ELSE with actions
IF x < 100 IF x < 100
x++ x++
ELSE ELSE
@ -368,11 +429,21 @@ INCREMENT <target>
``` ```
**Examples:** **Examples:**
``` ```
// Modern: increment variables
counter++ counter++
index++ index++
frameCount++ frameCount++
```
```
// Alternative: increment memory location
INC $D020 INC $D020
```
```
// Legacy: INCREMENT form
INCREMENT screenColor INCREMENT screenColor
``` ```
@ -421,10 +492,7 @@ value = 100+50
Loop terminator for FOR. Loop terminator for FOR.
**Syntax:** See [FOR](#for) for syntax and examples.
```
See FOR
```
--- ---
@ -499,19 +567,27 @@ For operating with offsets the address parameter must be an absolute WORD variab
``` ```
**Examples:** **Examples:**
``` ```
// Read from absolute address
reset_addr = PEEKW $FFFE reset_addr = PEEKW $FFFE
```
```
// Read with offset (requires WORD variable in zero page)
WORD buffer @ $fd WORD buffer @ $fd
offset_val = PEEKW buff_ptr[10] offset_val = PEEKW buffer[10]
```
```
// Read through pointer
WORD pointer WORD pointer
val = PEEKW pointer val = PEEKW pointer
``` ```
--- ---
## POINT ## POINTER
Sets pointer variable to address of target. Sets pointer variable to address of target.
@ -586,11 +662,16 @@ EXIT
``` ```
**Examples:** **Examples:**
``` ```
// Simple subroutine with SUBEND
LABEL subroutine LABEL subroutine
counter = counter + 1 counter = counter + 1
SUBEND SUBEND
```
```
// Subroutine with early EXIT
LABEL checkValue LABEL checkValue
IF value = 0 IF value = 0
EXIT EXIT
@ -625,10 +706,20 @@ SHIFTL <source> << <amount> -> <dest>
- WORD→BYTE conversion truncates low byte only - WORD→BYTE conversion truncates low byte only
**Examples:** **Examples:**
``` ```
// Modern: assignment form
result = value << 3 result = value << 3
```
```
// Alternative: arrow form
SHIFTL flags << 2 -> masked
```
```
// Legacy: verbose form
SHIFTL mask BY bits GIVING shifted SHIFTL mask BY bits GIVING shifted
SHIFTR flags >> 2 -> masked
``` ```
--- ---
@ -657,12 +748,22 @@ SHIFTR <source> >> <amount> -> <dest>
- WORD→BYTE conversion truncates low byte only - WORD→BYTE conversion truncates low byte only
**Examples:** **Examples:**
``` ```
// Modern: assignment form
mask = flags >> 2 mask = flags >> 2
SHIFTR value BY shift GIVING result ```
```
// Alternative: arrow form
SHIFTR data >> 4 -> nibble SHIFTR data >> 4 -> nibble
``` ```
```
// Legacy: verbose form
SHIFTR value BY shift GIVING result
```
--- ---
## SUBTR ## SUBTR
@ -712,6 +813,7 @@ ENDSWITCH
- Nested SWITCH statements are supported - Nested SWITCH statements are supported
**Examples:** **Examples:**
``` ```
// Basic switch with default // Basic switch with default
SWITCH status SWITCH status
@ -722,7 +824,9 @@ SWITCH status
DEFAULT DEFAULT
result = 0 result = 0
ENDSWITCH ENDSWITCH
```
```
// Switch with constants // Switch with constants
BYTE CONST MAX = 100 BYTE CONST MAX = 100
SWITCH value SWITCH value
@ -731,7 +835,9 @@ SWITCH value
CASE 50 CASE 50
halfway = 1 halfway = 1
ENDSWITCH ENDSWITCH
```
```
// WORD switch // WORD switch
WORD big_val WORD big_val
SWITCH big_val SWITCH big_val
@ -742,7 +848,9 @@ SWITCH big_val
DEFAULT DEFAULT
mode = 0 mode = 0
ENDSWITCH ENDSWITCH
```
```
// Nested switch // Nested switch
SWITCH outer SWITCH outer
CASE 1 CASE 1
@ -757,7 +865,9 @@ SWITCH outer
DEFAULT DEFAULT
result = 0 result = 0
ENDSWITCH ENDSWITCH
```
```
// Using variables in CASE // Using variables in CASE
BYTE threshold1 BYTE threshold1
BYTE threshold2 BYTE threshold2
@ -779,10 +889,7 @@ ENDSWITCH
Terminates WHILE loop. Terminates WHILE loop.
**Syntax:** See [WHILE](#while) for syntax and examples.
```
See WHILE
```
--- ---
@ -800,17 +907,25 @@ WHILE <param1> [<operator> <param2>]
Operators: `=` `==` `<>` `!=` `>` `<` `>=` `<=` Operators: `=` `==` `<>` `!=` `>` `<` `>=` `<=`
**Examples:** **Examples:**
``` ```
// WHILE with numeric comparison
WHILE counter < 100 WHILE counter < 100
counter++ counter++
result = result + counter result = result + counter
WEND WEND
```
```
// WHILE with boolean condition
WHILE running WHILE running
processFrame processFrame
checkInput checkInput
WEND WEND
```
```
// WHILE with inequality
WHILE x != y WHILE x != y
x++ x++
WEND WEND