From 25016018acaf73a47595be3c2ce8ad366c690154 Mon Sep 17 00:00:00 2001 From: Mattias Hansson Date: Mon, 22 Dec 2025 23:48:18 +0200 Subject: [PATCH] Added SWICH/CASE/DEFAULT/ENDSWITCH to docs --- commands.md | 125 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) diff --git a/commands.md b/commands.md index 9f67968..f7e8c9a 100644 --- a/commands.md +++ b/commands.md @@ -107,6 +107,17 @@ process("hello",42,myvar) --- +## CASE + +Defines a case branch within SWITCH statement. + +**Syntax:** +``` +See SWITCH +``` + +--- + ## DEC Decrements a variable or memory location by 1. @@ -129,6 +140,17 @@ DECREMENT screenColor --- +## DEFAULT + +Defines the default branch in SWITCH statement. + +**Syntax:** +``` +See SWITCH +``` + +--- + ## ELSE Alternative branch in IF statement. @@ -151,6 +173,17 @@ See IF --- +## ENDSWITCH + +Terminates SWITCH block. + +**Syntax:** +``` +See SWITCH +``` + +--- + ## FEND Ends a function definition. @@ -561,6 +594,98 @@ remaining = total - used --- +## SWITCH + +Multi-way branching based on variable value comparison. + +Features implicit breaks (automatic jump to ENDSWITCH after each case), supports nesting, and works with BYTE and WORD types. + +**Syntax:** +``` +SWITCH + CASE + [statements] + [CASE + [statements]] + [DEFAULT + [statements]] +ENDSWITCH +``` + +**Notes:** +- Each CASE automatically breaks (jumps to ENDSWITCH) after execution +- CASE values can be literals, constants, or variables +- DEFAULT branch is optional and executes when no CASE matches +- DEFAULT must come after all CASE statements +- Only one DEFAULT per SWITCH +- BYTE variables can only be compared with values 0-255 +- Can use `#PRAGMA _P_USE_LONG_JUMP 1` for large switch statements +- Nested SWITCH statements are supported + +**Examples:** +``` +// Basic switch with default +SWITCH status + CASE 1 + result = 10 + CASE 2 + result = 20 + DEFAULT + result = 0 +ENDSWITCH + +// Switch with constants +BYTE CONST MAX = 100 +SWITCH value + CASE MAX + overflow = 1 + CASE 50 + halfway = 1 +ENDSWITCH + +// WORD switch +WORD big_val +SWITCH big_val + CASE 1000 + mode = 1 + CASE 5000 + mode = 2 + DEFAULT + mode = 0 +ENDSWITCH + +// Nested switch +SWITCH outer + CASE 1 + result = 1 + CASE 2 + SWITCH inner + CASE 10 + result = 20 + CASE 20 + result = 40 + ENDSWITCH + DEFAULT + result = 0 +ENDSWITCH + +// Using variables in CASE +BYTE threshold1 +BYTE threshold2 +LET threshold1 = 50 +LET threshold2 = 100 +SWITCH temperature + CASE threshold1 + fan_speed = 1 + CASE threshold2 + fan_speed = 2 + DEFAULT + fan_speed = 0 +ENDSWITCH +``` + +--- + ## WEND Terminates WHILE loop.