From d273ca7fbe2fef111a3861cac78bd97ce9321c29 Mon Sep 17 00:00:00 2001 From: radius75 Date: Wed, 14 May 2025 13:34:45 +0200 Subject: [PATCH 01/60] index html abbreviation and more - abbreviation - shifted letter is needed - notation of remaining symbols consistent with cbm prg studio --- html/index.html | 296 +++++++++++++++++++++++++++++++----------------- 1 file changed, 191 insertions(+), 105 deletions(-) diff --git a/html/index.html b/html/index.html index af8efb769..4b2d8b90f 100644 --- a/html/index.html +++ b/html/index.html @@ -186,7 +186,7 @@ // Split into lines, remove blank lines, convert to lowercase, and join back var temp = textarea.split('\n') - .map(line => line.trim().toLowerCase()) + //.map(line => line.trim().toLowerCase()) //Shifted is neded! .filter(line => line.trim().length > 0) .join('\n'); @@ -247,74 +247,75 @@ var basic_error = ""; const TOKENS = [ - ['restore', 140], - ['input#', 132], - ['return', 142], - ['verify', 149], - ['print#', 152], - ['right$', 201], - ['input', 133], - ['gosub', 141], - ['print', 153], - ['close', 160], - ['left$', 200], - ['next', 130], - ['data', 131], - ['read', 135], - ['goto', 137], - ['stop', 144], - ['wait', 146], - ['load', 147], - ['save', 148], - ['poke', 151], - ['cont', 154], - ['list', 155], - ['open', 159], - ['tab(', 163], - ['spc(', 166], - ['then', 167], - ['step', 169], - ['peek', 194], - ['str$', 196], - ['chr$', 199], - ['mid$', 202], - ['end', 128], - ['for', 129], - ['dim', 134], - ['let', 136], - ['run', 138], - ['rem', 143], - ['def', 150], - ['clr', 156], - ['cmd', 157], - ['sys', 158], - ['get', 161], - ['new', 162], - ['not', 168], - ['and', 175], - ['sgn', 180], - ['int', 181], - ['abs', 182], - ['usr', 183], - ['fre', 184], - ['pos', 185], - ['sqr', 186], - ['rnd', 187], - ['log', 188], - ['exp', 189], - ['cos', 190], - ['sin', 191], - ['tan', 192], - ['atn', 193], - ['len', 195], - ['val', 197], - ['asc', 198], - ['if', 139], - ['on', 145], - ['to', 164], - ['fn', 165], - ['or', 176], - ['go', 203], + ['restore', 140], ['reS', 140], ['resT', 140], ['restO', 140], ['restoR', 140], + ['input#', 132], ['iN', 132], ['inP', 132], ['inpU', 132], ['inpuT', 132], + ['return', 142], ['reT', 142], ['retU', 142], ['retuR', 142], + ['verify', 149], ['vE', 149], ['veR', 149], ['verI', 149], ['veriF', 149], + ['print#', 152], ['pR', 152], ['prI', 152], ['priN', 152], ['prinT', 152], + ['right$', 201], ['rI', 201], ['riG', 201], ['rigH', 201], ['righT', 201], + ['input', 133], //No abbreviation + ['gosub', 141], ['goS', 141], ['gosU', 141], + ['print', 153], ['?', 153], + ['close', 160], ['clO', 160], ['cloS', 160], + ['left$', 200], ['leF', 200], ['lefT', 200], + ['next', 130], ['nE', 130], ['neX', 130], + ['data', 131], ['dA', 131], + ['read', 135], ['rE', 135], + ['goto', 137], ['gO', 137], ['goT', 137], + ['stop', 144], ['sT', 144], ['stO', 144], + ['wait', 146], ['wA', 146], ['waI', 146], + ['load', 147], ['lO', 147], ['loA', 147], + ['save', 148], ['sA', 148], ['saV', 148], + ['poke', 151], ['pO', 151], ['poK', 151], + ['cont', 154], ['cO', 154], ['coN', 154], + ['list', 155], ['lI', 155], ['liS', 155], + ['open', 159], ['oP', 159], ['opE', 159], + ['tab(', 163], ['tA', 163], ['taB', 163], + ['spc(', 166], ['sP', 166], ['spC', 166], + ['then', 167], ['tH', 167], ['thE', 167], + ['step', 169], ['stE', 169], + ['peek', 194], ['pE', 194], ['peE', 194], + ['str$', 196], ['stR', 196], + ['chr$', 199], ['cH', 199], ['chR', 199], + ['mid$', 202], ['mI', 202], ['miD', 202], + ['end', 128], ['eN', 128], + ['for', 129], ['fO', 129], + ['dim', 134], ['dI', 134], + ['let', 136], ['lE', 136], + ['run', 138], ['rU', 138], + ['rem', 143], //No abbreviation + ['def', 150], ['dE', 150], + ['clr', 156], ['cL', 156], + ['cmd', 157], ['cM', 157], + ['sys', 158], ['sY', 158], + ['get', 161], ['gE', 161], + ['new', 162], //No abbreviation + ['not', 168], ['nO', 168], + ['and', 175], ['aN', 175], + ['sgn', 180], ['sG', 180], + ['int', 181], //No abbreviation + ['abs', 182], ['aB', 182], + ['usr', 183], ['uS', 183], + ['fre', 184], ['fR', 184], + ['pos', 185], //No abbreviation + ['sqr', 186], ['sQ', 186], + ['rnd', 187], ['rN', 187], + ['log', 188], //No abbreviation + ['exp', 189], ['eX', 189], + ['cos', 190], //No abbreviation + ['sin', 191], ['sI', 191], + ['tan', 192], //No abbreviation + ['atn', 193], ['aT', 193], + ['len', 195], //No abbreviation + ['val', 197], ['vA', 197], + ['asc', 198], ['aS', 198], + ['if', 139], //No abbreviation + ['on', 145], //No abbreviation + ['to', 164], //No abbreviation + ['fn', 165], //No abbreviation + ['or', 176], //No abbreviation + ['go', 203], //No abbreviation + // ['+', 170], ['-', 171], ['*', 172], @@ -327,36 +328,121 @@ const TOKENS_UPPERCASE = TOKENS.map(token => [token[0].toUpperCase(), token[1]]); - const SPECIAL = [ - ['{rvs off}', 0x92], - ['{rvs on}', 0x12], - ['{up}', 0x91], - ['{down}', 0x11], - ['{left}', 0x9d], - ['{rght}', 0x1d], - ['{clr}', 0x93], - ['{clear}', 0x93], - ['{home}', 0x13], - - ['{blk}', 0x90], - ['{wht}', 0x05], - ['{red}', 0x1c], - ['{cyn}', 0x9f], - ['{pur}', 0x9c], - ['{grn}', 0x1e], - ['{blu}', 0x1f], - ['{yel}', 0x9e], - ['{org}', 0x81], - ['{brn}', 0x95], - ['{lred}', 0x96], - ['{dgry}', 0x97], - ['{mgry}', 0x98], - ['{lgrn}', 0x99], - ['{lblu}', 0x9a], - ['{lgry}', 0x9b] - - + ['{black}', 0x90], + ['{white}', 0x05], + ['{red}', 0x1c], + ['{cyan}', 0x9f], + ['{purple}', 0x9c], + ['{green}', 0x1e], + ['{blue}', 0x1f], + ['{yellow}', 0x9e], + ['{orange}', 0x81], + ['{brown}', 0x95], + ['{pink}', 0x96], + ['{dark gray}', 0x97], + ['{gray}', 0x98], + ['{light green}', 0x99], + ['{light blue}', 0x9a], + ['{light gray}', 0x9b], + // + ['{reverse on}', 0x12], + ['{reverse off}', 0x92], + // + ['{clear}', 0x93], + ['{home}', 0x13], + ['{insert}', 0x94], + ['{delete}', 0x14], + // + ['{pound}', 0x5c], + ['{arrow left}', 0x5f], + ['{^}', 0x5e], + ['{pi}', 0xff], + // + ['{up}', 0x91], + ['{down}', 0x11], + ['{left}', 0x9d], + ['{right}', 0x1d], + // commodore key + + ['{cm a}', 0xb0], + ['{cm b}', 0xbf], + ['{cm c}', 0xbc], + ['{cm d}', 0xac], + ['{cm e}', 0xb1], + ['{cm f}', 0xbb], + ['{cm g}', 0xa5], + ['{cm h}', 0xb4], + ['{cm i}', 0xa2], + ['{cm j}', 0xb5], + ['{cm k}', 0xa1], + ['{cm l}', 0xb6], + ['{cm m}', 0xa7], + ['{cm n}', 0xaa], + ['{cm o}', 0xb9], + ['{cm p}', 0xaf], + ['{cm q}', 0xab], + ['{cm r}', 0xb2], + ['{cm s}', 0xae], + ['{cm t}', 0xa3], + ['{cm u}', 0xb8], + ['{cm v}', 0xbe], + ['{cm w}', 0xb3], + ['{cm x}', 0xbd], + ['{cm y}', 0xb7], + ['{cm z}', 0xad], + ['{cm +}', 0xa6], + ['{cm -}', 0xdc], + ['{cm pound}', 0xa8], + ['{cm @}', 0xa4], + ['{cm asterisk}', 0xdf], + ['{cm ^}', 0xff], + ['{cm space}', 0xa0], + // control key + + ['{ct a}', 0x01], + ['{ct b}', 0x02], + ['{ct c}', 0x03], + ['{ct d}', 0x04], + ['{ct e}', 0x05], + ['{ct f}', 0x06], + ['{ct g}', 0x07], + ['{ct h}', 0x08], + ['{ct i}', 0x09], + ['{ct j}', 0x0a], + ['{ct k}', 0x0b], + ['{ct l}', 0x0c], + ['{ct n}', 0x0e], + ['{ct o}', 0x0f], + ['{ct p}', 0x10], + ['{ct q}', 0x11], + ['{ct r}', 0x12], + ['{ct s}', 0x13], + ['{ct t}', 0x14], + ['{ct u}', 0x15], + ['{ct v}', 0x16], + ['{ct w}', 0x17], + ['{ct x}', 0x18], + ['{ct y}', 0x19], + ['{ct z}', 0x1a], + ['{ct [}', 0x1b], + ['{ct ]}', 0x1d], + ['{ct =}', 0x1f], + // shift key + + ['{sh +}', 0xdb], + ['{sh -}', 0xdd], + ['{sh pound}', 0xa9], + ['{sh @}', 0xba], + ['{sh asterisk}', 0xc0], + ['{sh ^}', 0xff], + ['{sh space}', 0xa0], + // function keys + ['{f1}', 0x85], + ['{f2}', 0x89], + ['{f3}', 0x86], + ['{f4}', 0x8a], + ['{f5}', 0x87], + ['{f6}', 0x8b], + ['{f7}', 0x88], + ['{f8}', 0x8c] ]; function asciiToPetscii(o) { @@ -494,13 +580,13 @@ function createTable() { let $table = $('
'); - // Calculate the number of rows needed for 10 columns - let numRows = Math.ceil(SPECIAL.length / 10); + // Calculate the number of rows needed for 16 columns + let numRows = Math.ceil(SPECIAL.length / 16); for (let row = 0; row < numRows; row++) { let $row = $(''); - for (let col = 0; col < 10; col++) { - let cellIndex = row * 10 + col; + for (let col = 0; col < 16; col++) { + let cellIndex = row * 16 + col; if (cellIndex < SPECIAL.length) { let [symbol, code] = SPECIAL[cellIndex]; $row.append(`${symbol}`); @@ -1392,13 +1478,13 @@

Live Monitor

BASIC Tokenizer / Editor

-

Here, you may enter a BASIC program, and upload it directly to your machine.

+

Here, you may enter a BASIC program (type in lower case, abbreviation is allowed), and upload it directly to your machine.

Special characters:

From 043a71d7823b06e137b0a23ad0e1cea0d373710e Mon Sep 17 00:00:00 2001 From: radius75 Date: Fri, 2 Jan 2026 12:27:44 +0100 Subject: [PATCH 02/60] only lines starting with a number are taken into account, comments placed between program lines are ignored during tokenization --- html/index.html | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/html/index.html b/html/index.html index 957aac7d6..ae2ac4793 100644 --- a/html/index.html +++ b/html/index.html @@ -202,14 +202,10 @@ async function parseBASIC() { var textarea = $("#basiceditor").val(); - // Split into lines, remove blank lines, convert to lowercase, and join back - var temp = textarea.split('\n') - //.map(line => line.trim().toLowerCase()) //Shifted is neded! - .filter(line => line.trim().length > 0) - .join('\n'); - - $("#basiceditor").val(temp); - var lines = temp.split('\n'); + // Split into lines, keep only those starting with a digit, and join back + var lines = textarea.split('\n') + .map(line => line.trim()) + .filter(line => /^\d/.test(line)); const tokenized_lines = []; let addr = 2049; @@ -1522,8 +1518,12 @@

BASIC Tokenizer / Editor

From 14f5f44a82f0688facbe71500fa2e5e4bbb51fe5 Mon Sep 17 00:00:00 2001 From: radius75 Date: Sat, 3 Jan 2026 12:42:16 +0100 Subject: [PATCH 03/60] fix upload&run --- html/index.html | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/html/index.html b/html/index.html index ae2ac4793..3622a0619 100644 --- a/html/index.html +++ b/html/index.html @@ -178,20 +178,20 @@ } } - $('#submitBASIC').click(function(event){ + $('#submitBASIC').click(async function(event){ event.preventDefault(); // Prevents the default action of the anchor tag - parseBASIC(); + await parseBASIC(); }); - $('#submitBASICAndRun').click(function (event) { + $('#submitBASICAndRun').click(async function (event) { event.preventDefault(); // Prevents the default action of the anchor tag - parseBASIC(); - runBASIC(); + await parseBASIC(); + await runBASIC(); }); - $('#runBASIC').click(function (event) { + $('#runBASIC').click(async function (event) { event.preventDefault(); // Prevents the default action of the anchor tag - runBASIC(); + await runBASIC(); }); async function runBASIC() { From 70f6b7951a924b9f42bfaa50a6b9d19df46e712c Mon Sep 17 00:00:00 2001 From: radius75 Date: Sat, 3 Jan 2026 12:44:13 +0100 Subject: [PATCH 04/60] The tokenizer will give the program line number where the error occurred. --- html/index.html | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/html/index.html b/html/index.html index 3622a0619..ceb3e89fd 100644 --- a/html/index.html +++ b/html/index.html @@ -210,12 +210,23 @@ const tokenized_lines = []; let addr = 2049; + // Clear error before starting + if (typeof basic_error !== 'undefined') basic_error = ""; + // Process each line for(let x=0; x Date: Sat, 3 Jan 2026 16:38:38 +0100 Subject: [PATCH 05/60] special as external file --- html/index.html | 119 +----------------------------------------------- html/special.js | 116 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+), 117 deletions(-) create mode 100644 html/special.js diff --git a/html/index.html b/html/index.html index ceb3e89fd..fca7971a7 100644 --- a/html/index.html +++ b/html/index.html @@ -7,6 +7,8 @@ + + - + + + + From 54301ef8fd44d0501b3c28d3749f20bebb2f6757 Mon Sep 17 00:00:00 2001 From: radius75 Date: Fri, 9 Jan 2026 09:26:19 +0100 Subject: [PATCH 16/60] Added spellcheck="false", autocorrect="off", and autocapitalize="off" to the BASIC Tokenizer textarea to prevent visual distractions and ensure a proper coding experience. --- html/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/html/index.html b/html/index.html index df794ad4d..3eabd780a 100644 --- a/html/index.html +++ b/html/index.html @@ -1562,7 +1562,7 @@

Live Monitor

BASIC Editor / Tokenizer

Here, you may enter a BASIC program (type in lower case, abbreviation is allowed), and upload it directly to your machine.

- From fbb3f87621a32226723bbf9754e962071bba13df Mon Sep 17 00:00:00 2001 From: radius75 Date: Fri, 9 Jan 2026 09:49:12 +0100 Subject: [PATCH 17/60] Updated welcome screen with comprehensive QUICK TIPS and compatibility notes. Switched // comments to !- within the BASIC template for CBM prg Studio compatibility. Standardized the external configuration file (SPECIAL.js logic/loader) for clarity. --- html/CBMprgStudio.js | 58 +++++++++++++++++++++++++++++++------------- html/SPECIAL.js | 17 ++++++++++++- 2 files changed, 57 insertions(+), 18 deletions(-) diff --git a/html/CBMprgStudio.js b/html/CBMprgStudio.js index af5a022c4..67af46335 100644 --- a/html/CBMprgStudio.js +++ b/html/CBMprgStudio.js @@ -1,48 +1,72 @@ -BASIC_CODE = `// -// short guide to using Basic Tokenizer -// +// Initial welcome message and code template displayed in the Tokenizer editor window +BASIC_CODE = `!- Welcome to Ultimate BASIC Editor / Tokenizer +!- ---------------------------------------------------------- +!- Current Profile: CBM prg Studio Mapping Standard +!- +!- QUICK TIPS: +!- - Use lowercase for BASIC commands (e.g. print, goto). +!- - Special keys use curly braces: {clear}, {red}, {f1}, etc. +!- - Control/Commodore keys: {ct a} / {cm a}. +!- - Shift/Uppercase: Typing UPPERCASE letters in this editor +!- is treated as Shift + Key (produces special symbols or +!- uppercase on C64 depending on its character set mode). +!- - Multi-char shortcut: Use {5 space} or {3 asterisk}. +!- (Note: This is an extra feature. In CBM prg Studio this +!- would be written as {space*5} or {asterisk*3}). +!- +!- COMPATIBILITY NOTE: +!- To follow CBM prg Studio standards, use ' !- ' for +!- comments. +!- +!- CONFIGURATION: +!- Learn how to load custom profiles in 'SPECIAL.js' file. +!- ---------------------------------------------------------- +!- +!- Short guide to using Basic Tokenizer. +!- -// clear screen and set uppercase mode +!- clear screen and set uppercase mode 10 print "{clear}"chr$(142) -// print HELLO WORLD! text +!- print HELLO WORLD! text 11 print "hello world!" -// gosub to delay loop +!- gosub to delay loop 12 gosub 100 -// example of writing using abbreviated commands -// print > ?, gosub > goS +!- example of writing using abbreviated commands +!- print > ?, gosub > goS 13 ? "hello world!" 14 goS 100 -// example of inserting characters using Shift to obtain uppercase letters or special symbols -// set lowercase (business) mode > print chr$(14) +!- example of inserting characters using Shift to obtain uppercase letters or special symbols +!- set lowercase (business) mode > print chr$(14) 15 print chr$(14) 16 print "Hello world!" 17 gosub 100 -// a simplified format of inserting the same character multiple times is allowed -// uppercase mode > print chr$(142) +!- a simplified format of inserting the same character multiple times is allowed +!- uppercase mode > print chr$(142) 18 print chr$(142) 19 print " print {pi}{pi}:";{pi}{pi} 20 print "{7 space}print {2 pi}:";{2 pi} 21 gosub 100 -// special characters from keys: A S Z X in uppercase mode -// with the Shift key +!- special characters from keys: A S Z X in uppercase mode +!- with the Shift key 22 print "AS": print "ZX" -// with the C= key +!- with the C= key 23 print "{cm a}{cm s}": print "{cm z}{cm x}" 24 gosub 100 -// program end +!- program end 99 end -// delay loop +!- delay loop 100 for i = 0 to 2000: next: return `; +// Special Character Mapping (CBM prg Studio Standard) SPECIAL = [ ['{black}', 0x90], ['{white}', 0x05], diff --git a/html/SPECIAL.js b/html/SPECIAL.js index d678e0bcf..5c4f40e31 100644 --- a/html/SPECIAL.js +++ b/html/SPECIAL.js @@ -1,2 +1,17 @@ -// Set the name of the file you want to load +// ========================================================================= +// ULTIMATE BASIC TOKENIZER - PROFILE CONFIGURATION +// ========================================================================= +// INSTRUCTIONS: +// To switch between different BASIC flavors or custom token sets, +// update the 'SCRIPT_TO_LOAD' variable below. +// +// - The filename must be enclosed in quotes (e.g., "filename.js"). +// - Ensure the file exists in the same directory as index.html. +// - If you don't want to load a custom set, leave it empty: "". +// +// EXAMPLES: +// var SCRIPT_TO_LOAD = "CBMprgStudio.js"; // For CBM prg Studio mapping +// var SCRIPT_TO_LOAD = ""; // Use internal default set +// ========================================================================= + var SCRIPT_TO_LOAD = "CBMprgStudio.js"; \ No newline at end of file From 74ff2fc1c4bf4f8674a57dd5fcbdcd809a518a08 Mon Sep 17 00:00:00 2001 From: radius75 Date: Fri, 9 Jan 2026 11:48:58 +0100 Subject: [PATCH 18/60] fix: implement reliable UI initialization and dynamic profile loading - Replaced unreliable setTimeout with script.onload combined with jQuery readiness to eliminate race conditions. - Centralized editor and table initialization into initializeTokenizerUI() to ensure atomic UI updates. - Corrected loading order of jQuery and external assets in to prevent reference errors. - Refactored renderSpecialTable to use .empty().append() for consistent UI refreshes when switching profiles. - Cleaned up redundant script blocks at the end of to maintain a single source of truth for initialization. --- html/index.html | 91 +++++++++++++++++++++++++------------------------ 1 file changed, 47 insertions(+), 44 deletions(-) diff --git a/html/index.html b/html/index.html index 3eabd780a..638e88af1 100644 --- a/html/index.html +++ b/html/index.html @@ -3,31 +3,30 @@ Ultimate II/64 - - - + - + + + + @@ -25,10 +29,8 @@ - - - + - @@ -489,56 +474,67 @@ const TOKENS_UPPERCASE = TOKENS.map(token => [token[0].toUpperCase(), token[1]]); - // Check if SPECIAL exists in the global window object and is ready - if (!window.SPECIAL || window.CBM_SIGNATURE !== "READY") { - // If not found or not ready (file .js failed to load), define base data - window.SPECIAL = [ - ['{rvs off}', 0x92], - ['{rvs on}', 0x12], - ['{up}', 0x91], - ['{down}', 0x11], - ['{left}', 0x9d], - ['{rght}', 0x1d], - ['{clr}', 0x93], - ['{clear}', 0x93], - ['{home}', 0x13], - - ['{blk}', 0x90], - ['{wht}', 0x05], - ['{red}', 0x1c], - ['{cyn}', 0x9f], - ['{pur}', 0x9c], - ['{grn}', 0x1e], - ['{blu}', 0x1f], - ['{yel}', 0x9e], - ['{org}', 0x81], - ['{brn}', 0x95], - ['{lred}', 0x96], - ['{dgry}', 0x97], - ['{mgry}', 0x98], - ['{lgrn}', 0x99], - ['{lblu}', 0x9a], - ['{lgry}', 0x9b], - - // additional entries found in COMPUTES!'s Gazette - ['{rvs}', 0x12], - ['{space}', 0x20], - ['{spaces}', 0x20], - ['{gry1}', 0x97], - ['{gry2}', 0x98], - ['{gry3}', 0x9b], - ['{f1}', 0x85], - ['{f2}', 0x86], - ['{f3}', 0x87], - ['{f4}', 0x88], - ['{f5}', 0x89], - ['{f6}', 0x8a], - ['{f7}', 0x8b], - ['{f8}', 0x8c], - ]; + // Reset textarea to its default HTML value (the error message) on every reload. + // This prevents the browser from restoring previous session text after F5. + const editor = document.getElementById('basiceditor'); + if (editor) { + // Reset to the initial content defined between
@@ -2130,15 +2122,5 @@

BASIC Editor / Tokenizer

- - - - From a4be3695a6b59f2541d09b863eba411974cf8834 Mon Sep 17 00:00:00 2001 From: radius75 Date: Sat, 17 Jan 2026 22:06:25 +0100 Subject: [PATCH 30/60] Update SCRIPT_TO_LOAD instructions with path details and hard reload tip. Unnecessary blank line --- html/Default.js | 1 - html/SPECIAL.js | 12 +++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/html/Default.js b/html/Default.js index f918fd18a..cf486cf7c 100644 --- a/html/Default.js +++ b/html/Default.js @@ -64,7 +64,6 @@ BASIC_CODE = `// Welcome to Ultimate BASIC Editor / Tokenizer // Print 38 dashes {45} between '+' signs // Print 40 zeros {48} // Print 10 asterisks {42} - 80 print "+{38 45}+"; 81 print "{40 48}"; 82 print "{42*10}" diff --git a/html/SPECIAL.js b/html/SPECIAL.js index e47c079eb..f83da1eea 100644 --- a/html/SPECIAL.js +++ b/html/SPECIAL.js @@ -5,13 +5,15 @@ // To switch between different BASIC flavors or custom token sets, // update the 'SCRIPT_TO_LOAD' variable below. // -// - The filename must be enclosed in quotes (e.g., "filename.js"). -// - Ensure the file exists in the same directory as index.html. -// - If you don't want to load a custom set, leave it empty: "". +// - Path: Files are typically located in /Flash/html/ on your device. +// - Filename: Must be enclosed in quotes (e.g., "filename.js"). +// - Custom sets: Enabling a custom set will override defaults. +// - Refresh: After editing this file, perform a Hard Reload (Ctrl+F5) +// in your browser to apply changes. // // EXAMPLES: -// var SCRIPT_TO_LOAD = "CBMprgStudio.js"; // For CBM prg Studio mapping -// var SCRIPT_TO_LOAD = ""; // Use internal default set +// var SCRIPT_TO_LOAD = "Default.js"; // Load default profile +// var SCRIPT_TO_LOAD = "CBMprgStudio.js"; // Load CBM prg Studio mapping // ========================================================================= var SCRIPT_TO_LOAD = "Default.js"; \ No newline at end of file From 832e0fb88f4c9c44dbfc3e0ead06f25be713ff74 Mon Sep 17 00:00:00 2001 From: radius75 Date: Sun, 18 Jan 2026 10:00:19 +0100 Subject: [PATCH 31/60] Refactor initial content loading and clean up index.html - Remove default table and example Basic code from index.html - Implement dynamic loading of default assets from CBMprgStudio.js - Add new default welcome message and sample Basic code - Add instructional descriptions and error handling for failed asset loading --- html/CBMprgStudio.js | 360 +++++++++++++++++++++++++++++++++++++++++++ html/Default.js | 347 ----------------------------------------- html/SPECIAL.js | 3 +- html/index.html | 62 +++----- 4 files changed, 386 insertions(+), 386 deletions(-) create mode 100644 html/CBMprgStudio.js delete mode 100644 html/Default.js diff --git a/html/CBMprgStudio.js b/html/CBMprgStudio.js new file mode 100644 index 000000000..32f9ebac8 --- /dev/null +++ b/html/CBMprgStudio.js @@ -0,0 +1,360 @@ +// Initial welcome message and code template displayed in the Tokenizer editor window +BASIC_CODE = `!- Welcome to Ultimate BASIC Editor / Tokenizer +!- ---------------------------------------------------------- +!- Current Profile: CBM prg Studio Mapping Standard +!- +!- QUICK TIPS: +!- - Use lowercase for BASIC commands (e.g. print, goto). +!- - Special keys use curly braces: {clear}, {red}, {f1}, etc. +!- - Control/Commodore keys: {ct a} / {cm a}. +!- - Shift/Uppercase: Typing UPPERCASE letters in this editor +!- is treated as Shift + Key (produces special symbols or +!- uppercase on C64 depending on its character set mode). +!- - Multi-character shortcuts: You can use {space*5} or {**3}. +!- These are compliant with CBM prg Studio, though +!- alternative formats such as {5 space}, {3 asterisk}, +!- or {3 *} are also acceptable. +!- - C64 BASIC keyword abbreviations are permitted, +!- e.g., goto > gO, print > ?, then > tH. +!- +!- IMPORTANT: +!- For mathematical operators, signs should not be placed +!- inside {}. Example: 10 PRINT"2 {^} 2 ="2^2 +!- +!- COMPATIBILITY NOTE: +!- To follow CBM prg Studio standards, use ' !- ' for +!- comments. +!- +!- CONFIGURATION: +!- Learn how to load custom profiles in 'SPECIAL.js' file. +!- Path: /Flash/html/SPECIAL.js +!- ---------------------------------------------------------- +!- +!- Short guide to using Basic Tokenizer. +!- + +!- clear screen, set uppercase mode and white color +10 print "{clear}{uppercase}{white}"; + +!- print HELLO WORLD! text +20 print "hello world!" + +!- gosub to delay loop +30 gosub 100 + +!- example of writing using abbreviated commands +!- print > ?, gosub > goS +40 ? "hello world!" +41 goS 100 + +!- example of inserting characters using Shift to obtain uppercase letters or special symbols +!- set lowercase (business) mode > print chr$(14) +50 print "{lowercase}Hello world!" +51 gosub 100 + +!- a simplified format of inserting the same character multiple times is allowed +!- uppercase mode > print chr$(142) +60 print "{uppercase}"; +61 print " print {pi}{pi}:";{pi}{pi} +62 print "99999999999999999999" +63 print "{space*6}print {pi*2}:";{pi*2} +64 print "{nine*20}" +65 gosub 100 + +!- special characters from keys: A S Z X in uppercase mode +!- with the Shift key +70 print "AS": print "ZX" +!- with the C= key +71 print "{cm a}{cm s}": print "{cm z}{cm x}" +72 gosub 100 + +!- print 38 '-' characters between '+' signs. +!- print 40 '0' characters +!- print 10 '*' characters +80 print "+{-*38}+"; +81 print "{zero*40}"; +82 print "{**10}" +83 gosub 100 + +!- colour setup +91 print "{ct 1}black","{ct 2}white","{ct 3}red","{ct 4}cyan" +92 print "{black}ctrl+1","{white}ctrl+2","{red}ctrl+3","{cyan}ctrl+4 +93 print "{white}" + +!- program end +99 end + +!- next line and delay loop +100 print:for i = 0 to 2000: next: return +`; + +// Special Character Mapping (CBM prg Studio Standard) +SPECIAL = [ + //Column 1 + ['{0}', 0x00], ['{null}', 0x00], ['{ct @}', 0x00], + ['{1}', 0x01], ['{ct a}', 0x01], + ['{2}', 0x02], ['{ct b}', 0x02], + ['{3}', 0x03], ['{ct c}', 0x03], + ['{4}', 0x04], ['{ct d}', 0x04], + ['{5}', 0x05], ['{white}', 0x05], ['{ct e}', 0x05], ['{ct 2}', 0x05], + ['{6}', 0x06], ['{ct f}', 0x06], + ['{7}', 0x07], ['{ct g}', 0x07], + ['{8}', 0x08], ['{switch off}', 0x08], ['{ct h}', 0x08], + ['{9}', 0x09], ['{switch on}', 0x09],['{ct i}', 0x09], + ['{10}', 0x0a], ['{ct j}', 0x0a], + ['{11}', 0x0b], ['{ct k}', 0x0b], + ['{12}', 0x0c], ['{ct l}', 0x0c], + ['{13}', 0x0d], ['{return}', 0x0d], ['{ct m}', 0x0d], + ['{14}', 0x0e], ['{lowercase}', 0x0e], ['{ct n}', 0x0e], + ['{15}', 0x0f], ['{ct o}', 0x0f], + ['{16}', 0x10], ['{ct p}', 0x10], + ['{17}', 0x11], ['{down}', 0x11], ['{ct q}', 0x11], + ['{18}', 0x12], ['{reverse on}', 0x12], ['{ct r}', 0x12], ['{ct 9}', 0x12], + ['{19}', 0x13], ['{home}', 0x13], ['{ct s}', 0x13], + ['{20}', 0x14], ['{delete}', 0x14], ['{ct t}', 0x14], + ['{21}', 0x15], ['{ct u}', 0x15], + ['{22}', 0x16], ['{ct v}', 0x16], + ['{23}', 0x17], ['{ct w}', 0x17], + ['{24}', 0x18], ['{ct x}', 0x18], + ['{25}', 0x19], ['{ct y}', 0x19], + ['{26}', 0x1a], ['{ct z}', 0x1a], + ['{27}', 0x1b], ['{ct [}', 0x1b], + ['{28}', 0x1c], ['{red}', 0x1c], ['{ct pound}', 0x1c], ['{ct 3}', 0x1c], + ['{29}', 0x1d], ['{right}', 0x1d], ['{ct ]}', 0x1d], + ['{30}', 0x1e], ['{green}', 0x1e], ['{ct ^}', 0x1e], ['{ct 6}', 0x1e], + ['{31}', 0x1f], ['{blue}', 0x1f], ['{ct =}', 0x1f], ['{ct 7}', 0x1f], + //Column 2 + ['{32}', 0x20], ['{space}', 0x20], + ['{33}', 0x21], ['{!}', 0x21], + ['{34}', 0x22], ['{quote}', 0x22], + ['{35}', 0x23], ['{#}', 0x23], + ['{36}', 0x24], ['{$}', 0x24], + ['{37}', 0x25], ['{%}', 0x25], + ['{38}', 0x26], ['{&}', 0x26], + ['{39}', 0x27], ["{'}", 0x27], + ['{40}', 0x28], ['{(}', 0x28], + ['{41}', 0x29], ['{)}', 0x29], + ['{42}', 0x2a], ['{*}', 0x2a], ['{asterisk}', 0x2a], + ['{43}', 0x2b], ['{+}', 0x2b], + ['{44}', 0x2c], ['{,}', 0x2c], + ['{45}', 0x2d], ['{-}', 0x2d], + ['{46}', 0x2e], ['{.}', 0x2e], + ['{47}', 0x2f], ['{/}', 0x2f], + ['{48}', 0x30], ['{zero}', 0x30], + ['{49}', 0x31], ['{one}', 0x31], + ['{50}', 0x32], ['{two}', 0x32], + ['{51}', 0x33], ['{three}', 0x33], + ['{52}', 0x34], ['{four}', 0x34], + ['{53}', 0x35], ['{five}', 0x35], + ['{54}', 0x36], ['{six}', 0x36], + ['{55}', 0x37], ['{seven}', 0x37], + ['{56}', 0x38], ['{eight}', 0x38], + ['{57}', 0x39], ['{nine}', 0x39], + ['{58}', 0x3a], ['{:}', 0x3a], + ['{59}', 0x3b], ['{;}', 0x3b], + ['{60}', 0x3c], ['{<}', 0x3c], + ['{61}', 0x3d], ['{=}', 0x3d], + ['{62}', 0x3e], ['{>}', 0x3e], + ['{63}', 0x3f], ['{?}', 0x3f], + //Column 3 + ['{64}', 0x40], ['{@}', 0x40], + ['{65}', 0x41], ['{a}', 0x41], + ['{66}', 0x42], ['{b}', 0x42], + ['{67}', 0x43], ['{c}', 0x43], + ['{68}', 0x44], ['{d}', 0x44], + ['{69}', 0x45], ['{e}', 0x45], + ['{70}', 0x46], ['{f}', 0x46], + ['{71}', 0x47], ['{g}', 0x47], + ['{72}', 0x48], ['{h}', 0x48], + ['{73}', 0x49], ['{i}', 0x49], + ['{74}', 0x4a], ['{j}', 0x4a], + ['{75}', 0x4b], ['{k}', 0x4b], + ['{76}', 0x4c], ['{l}', 0x4c], + ['{77}', 0x4d], ['{m}', 0x4d], + ['{78}', 0x4e], ['{n}', 0x4e], + ['{79}', 0x4f], ['{o}', 0x4f], + ['{80}', 0x50], ['{p}', 0x50], + ['{81}', 0x51], ['{q}', 0x51], + ['{82}', 0x52], ['{r}', 0x52], + ['{83}', 0x53], ['{s}', 0x53], + ['{84}', 0x54], ['{t}', 0x54], + ['{85}', 0x55], ['{u}', 0x55], + ['{86}', 0x56], ['{v}', 0x56], + ['{87}', 0x57], ['{w}', 0x57], + ['{88}', 0x58], ['{x}', 0x58], + ['{89}', 0x59], ['{y}', 0x59], + ['{90}', 0x5a], ['{z}', 0x5a], + ['{91}', 0x5b], ['{[}', 0x5b], + ['{92}', 0x5c], ['{pound}', 0x5c], + ['{93}', 0x5d], ['{]}', 0x5d], + ['{94}', 0x5e], ['{^}', 0x5e], + ['{95}', 0x5f], ['{arrow left}', 0x5f], + //Column 4 + ['{96}', 0x60], + ['{97}', 0x61], + ['{98}', 0x62], + ['{99}', 0x63], + ['{100}', 0x64], + ['{101}', 0x65], + ['{102}', 0x66], + ['{103}', 0x67], + ['{104}', 0x68], + ['{105}', 0x69], + ['{106}', 0x6a], + ['{107}', 0x6b], + ['{108}', 0x6c], + ['{109}', 0x6d], + ['{110}', 0x6e], + ['{111}', 0x6f], + ['{112}', 0x70], + ['{113}', 0x71], + ['{114}', 0x72], + ['{115}', 0x73], + ['{116}', 0x74], + ['{117}', 0x75], + ['{118}', 0x76], + ['{119}', 0x77], + ['{120}', 0x78], + ['{121}', 0x79], + ['{122}', 0x7a], + ['{123}', 0x7b], + ['{124}', 0x7c], + ['{125}', 0x7d], + ['{126}', 0x7e], + ['{127}', 0x7f], + //Column 5 + ['{128}', 0x80], + ['{129}', 0x81], ['{orange}', 0x81], ['{cm 1}', 0x81], + ['{130}', 0x82], + ['{131}', 0x83], + ['{132}', 0x84], + ['{133}', 0x85], ['{f1}', 0x85], + ['{134}', 0x86], ['{f3}', 0x86], + ['{135}', 0x87], ['{f5}', 0x87], + ['{136}', 0x88], ['{f7}', 0x88], + ['{137}', 0x89], ['{f2}', 0x89], + ['{138}', 0x8a], ['{f4}', 0x8a], + ['{139}', 0x8b], ['{f6}', 0x8b], + ['{140}', 0x8c], ['{f8}', 0x8c], + ['{141}', 0x8d], ['{sh return}', 0x8d], + ['{142}', 0x8e], ['{uppercase}', 0x8e], + ['{143}', 0x8f], + ['{144}', 0x90], ['{black}', 0x90], ['{ct 1}', 0x90], + ['{145}', 0x91], ['{up}', 0x91], + ['{146}', 0x92], ['{reverse off}', 0x92], ['{ct 0}', 0x92], + ['{147}', 0x93], ['{clear}', 0x93], + ['{148}', 0x94], ['{insert}', 0x94], + ['{149}', 0x95], ['{brown}', 0x95], ['{cm 2}', 0x95], + ['{150}', 0x96], ['{pink}', 0x96], ['{cm 3}', 0x96], + ['{151}', 0x97], ['{dark gray}', 0x97], ['{cm 4}', 0x97], + ['{152}', 0x98], ['{gray}', 0x98], ['{cm 5}', 0x98], + ['{153}', 0x99], ['{light green}', 0x99], ['{cm 6}', 0x99], + ['{154}', 0x9a], ['{light blue}', 0x9a], ['{cm 7}', 0x9a], + ['{155}', 0x9b], ['{light gray}', 0x9b], ['{cm 8}', 0x9b], + ['{156}', 0x9c], ['{purple}', 0x9c], ['{ct 5}', 0x9c], + ['{157}', 0x9d], ['{left}', 0x9d], + ['{158}', 0x9e], ['{yellow}', 0x9e], ['{ct 8}', 0x9e], + ['{159}', 0x9f], ['{cyan}', 0x9f], ['{ct 4}', 0x9f], + //Column 6 + ['{160}', 0xa0], ['{sh space}', 0xa0], + ['{161}', 0xa1], ['{cm k}', 0xa1], + ['{162}', 0xa2], ['{cm i}', 0xa2], + ['{163}', 0xa3], ['{cm t}', 0xa3], + ['{164}', 0xa4], ['{cm @}', 0xa4], + ['{165}', 0xa5], ['{cm g}', 0xa5], + ['{166}', 0xa6], ['{cm +}', 0xa6], + ['{167}', 0xa7], ['{cm m}', 0xa7], + ['{168}', 0xa8], ['{cm pound}', 0xa8], + ['{169}', 0xa9], ['{sh pound}', 0xa9], + ['{170}', 0xaa], ['{cm n}', 0xaa], + ['{171}', 0xab], ['{cm q}', 0xab], + ['{172}', 0xac], ['{cm d}', 0xac], + ['{173}', 0xad], ['{cm z}', 0xad], + ['{174}', 0xae], ['{cm s}', 0xae], + ['{175}', 0xaf], ['{cm p}', 0xaf], + ['{176}', 0xb0], ['{cm a}', 0xb0], + ['{177}', 0xb1], ['{cm e}', 0xb1], + ['{178}', 0xb2], ['{cm r}', 0xb2], + ['{179}', 0xb3], ['{cm w}', 0xb3], + ['{180}', 0xb4], ['{cm h}', 0xb4], + ['{181}', 0xb5], ['{cm j}', 0xb5], + ['{182}', 0xb6], ['{cm l}', 0xb6], + ['{183}', 0xb7], ['{cm y}', 0xb7], + ['{184}', 0xb8], ['{cm u}', 0xb8], + ['{185}', 0xb9], ['{cm o}', 0xb9], + ['{186}', 0xba], ['{sh @}', 0xba], + ['{187}', 0xbb], ['{cm f}', 0xbb], + ['{188}', 0xbc], ['{cm c}', 0xbc], + ['{189}', 0xbd], ['{cm x}', 0xbd], + ['{190}', 0xbe], ['{cm v}', 0xbe], + ['{191}', 0xbf], ['{cm b}', 0xbf], + //Column 7 + ['{192}', 0xc0], ['{sh asterisk}', 0xc0], + ['{193}', 0xc1], ['{A}', 0xc1], + ['{194}', 0xc2], ['{B}', 0xc2], + ['{195}', 0xc3], ['{C}', 0xc3], + ['{196}', 0xc4], ['{D}', 0xc4], + ['{197}', 0xc5], ['{E}', 0xc5], + ['{198}', 0xc6], ['{F}', 0xc6], + ['{199}', 0xc7], ['{G}', 0xc7], + ['{200}', 0xc8], ['{H}', 0xc8], + ['{201}', 0xc9], ['{I}', 0xc9], + ['{202}', 0xca], ['{J}', 0xca], + ['{203}', 0xcb], ['{K}', 0xcb], + ['{204}', 0xcc], ['{L}', 0xcc], + ['{205}', 0xcd], ['{M}', 0xcd], + ['{206}', 0xce], ['{N}', 0xce], + ['{207}', 0xcf], ['{O}', 0xcf], + ['{208}', 0xd0], ['{P}', 0xd0], + ['{209}', 0xd1], ['{Q}', 0xd1], + ['{210}', 0xd2], ['{R}', 0xd2], + ['{211}', 0xd3], ['{S}', 0xd3], + ['{212}', 0xd4], ['{T}', 0xd4], + ['{213}', 0xd5], ['{U}', 0xd5], + ['{214}', 0xd6], ['{V}', 0xd6], + ['{215}', 0xd7], ['{W}', 0xd7], + ['{216}', 0xd8], ['{X}', 0xd8], + ['{217}', 0xd9], ['{Y}', 0xd9], + ['{218}', 0xda], ['{Z}', 0xda], + ['{219}', 0xdb], ['{sh +}', 0xdb], + ['{220}', 0xdc], ['{cm -}', 0xdc], + ['{221}', 0xdd], ['{sh -}', 0xdd], + ['{222}', 0xde], + ['{223}', 0xdf], ['{cm asterisk}', 0xdf], + //Column 8 + ['{224}', 0xe0], + ['{225}', 0xe1], + ['{226}', 0xe2], + ['{227}', 0xe3], + ['{228}', 0xe4], + ['{229}', 0xe5], + ['{230}', 0xe6], + ['{231}', 0xe7], + ['{232}', 0xe8], + ['{233}', 0xe9], + ['{234}', 0xea], + ['{235}', 0xeb], + ['{236}', 0xec], + ['{237}', 0xed], + ['{238}', 0xee], + ['{239}', 0xef], + ['{240}', 0xf0], + ['{241}', 0xf1], + ['{242}', 0xf2], + ['{243}', 0xf3], + ['{244}', 0xf4], + ['{245}', 0xf5], + ['{246}', 0xf6], + ['{247}', 0xf7], + ['{248}', 0xf8], + ['{249}', 0xf9], + ['{250}', 0xfa], + ['{251}', 0xfb], + ['{252}', 0xfc], + ['{253}', 0xfd], + ['{254}', 0xfe], + ['{255}', 0xff], ['{pi}', 0xff] +]; + +// DO NOT REMOVE - Verification signature +CBM_SIGNATURE = "READY"; \ No newline at end of file diff --git a/html/Default.js b/html/Default.js deleted file mode 100644 index cf486cf7c..000000000 --- a/html/Default.js +++ /dev/null @@ -1,347 +0,0 @@ -// Initial welcome message and code template displayed in the Tokenizer editor window -BASIC_CODE = `// Welcome to Ultimate BASIC Editor / Tokenizer -// ---------------------------------------------------------- -// Current Profile: Default -// -// QUICK TIPS: -// - Use lowercase for BASIC commands (e.g. print, goto). -// - Shift/Uppercase: Typing UPPERCASE letters in this editor -// is treated as Shift + Key (produces special symbols or -// uppercase on C64 depending on its character set mode). -// - Numeric tokens: You can use any code directly -// using its decimal value: {0} to {255}. -// - Named tokens: {clr}, {red}, {f1}, {up}, {down}, etc. -// - Multi-char shortcut: Use {5 space} or {space*5}, {10 160} or {**3}. -// -// IMPORTANT: -// For mathematical operators, signs should not be placed inside {}. -// Example: 10 print "2 {^} 2 ="; 2^2 -// -// ADVANCED: -// This profile maps all 256 PETSCII bytes. If a named token -// is missing, simply use its number: e.g., {147} for clr. -// -// CONFIGURATION: -// Learn how to load or customize your own profiles in -// the '/Flash/html/SPECIAL.js' file. -// ---------------------------------------------------------- -// -// Short guide to using Basic Tokenizer. - -// Clear screen {clr} and set uppercase mode {142} -10 print "{clr}{142}"; - -// Print hello world! text -20 print "hello world!" - -// Gosub to delay loop -30 gosub 100 - -// Example of writing using abbreviated commands -// print > ?, gosub > goS -40 ? "hello world!" -41 goS 100 - -// Set lowercase mode using code {14} -50 print "{14}Hello world!" -51 gosub 100 - -// Using numeric tokens and multipliers -// Set uppercase mode {142} -60 print "{142}"; -// PI symbol as text {255} and mathematical constant -61 print " print {255}{255}:";{255}{255} -62 print "{6 space}print {255*2}:";{255*2} -63 gosub 100 - -// Special characters using numeric tokens for A S Z X -// Using codes 193, 211, 218, 216 for Shift+Key -70 print "{193}{211}": print "{218}{216}" -// Using codes 176, 174, 173, 189 for C=+Key -71 print "{176}{174}": print "{173}{189}" -72 gosub 100 - -// Print 38 dashes {45} between '+' signs -// Print 40 zeros {48} -// Print 10 asterisks {42} -80 print "+{38 45}+"; -81 print "{40 48}"; -82 print "{42*10}" - -// Program end -90 end - -// Next line and delay loop -100 print:for i = 0 to 2000: next: return -`; - -// Special Character Mapping -SPECIAL = [ - // Column 1 - ['{0}', 0x00], - ['{1}', 0x01], - ['{2}', 0x02], - ['{3}', 0x03], - ['{4}', 0x04], - ['{5}', 0x05], ['{wht}', 0x05], - ['{6}', 0x06], - ['{7}', 0x07], - ['{8}', 0x08], - ['{9}', 0x09], - ['{10}', 0x0a], - ['{11}', 0x0b], - ['{12}', 0x0c], - ['{13}', 0x0d], - ['{14}', 0x0e], - ['{15}', 0x0f], - ['{16}', 0x10], - ['{17}', 0x11], ['{down}', 0x11], - ['{18}', 0x12], ['{rvs on}', 0x12], ['{rvs}', 0x12], - ['{19}', 0x13], ['{home}', 0x13], - ['{20}', 0x14], - ['{21}', 0x15], - ['{22}', 0x16], - ['{23}', 0x17], - ['{24}', 0x18], - ['{25}', 0x19], - ['{26}', 0x1a], - ['{27}', 0x1b], - ['{28}', 0x1c], ['{red}', 0x1c], - ['{29}', 0x1d], ['{rght}', 0x1d], - ['{30}', 0x1e], ['{grn}', 0x1e], - ['{31}', 0x1f], ['{blu}', 0x1f], - // Column 2 - ['{32}', 0x20], ['{space}', 0x20], ['{spaces}', 0x20], - ['{33}', 0x21], - ['{34}', 0x22], - ['{35}', 0x23], - ['{36}', 0x24], - ['{37}', 0x25], - ['{38}', 0x26], - ['{39}', 0x27], - ['{40}', 0x28], - ['{41}', 0x29], - ['{42}', 0x2a], - ['{43}', 0x2b], - ['{44}', 0x2c], - ['{45}', 0x2d], - ['{46}', 0x2e], - ['{47}', 0x2f], - ['{48}', 0x30], - ['{49}', 0x31], - ['{50}', 0x32], - ['{51}', 0x33], - ['{52}', 0x34], - ['{53}', 0x35], - ['{54}', 0x36], - ['{55}', 0x37], - ['{56}', 0x38], - ['{57}', 0x39], - ['{58}', 0x3a], - ['{59}', 0x3b], - ['{60}', 0x3c], - ['{61}', 0x3d], - ['{62}', 0x3e], - ['{63}', 0x3f], - // Column 3 - ['{64}', 0x40], - ['{65}', 0x41], - ['{66}', 0x42], - ['{67}', 0x43], - ['{68}', 0x44], - ['{69}', 0x45], - ['{70}', 0x46], - ['{71}', 0x47], - ['{72}', 0x48], - ['{73}', 0x49], - ['{74}', 0x4a], - ['{75}', 0x4b], - ['{76}', 0x4c], - ['{77}', 0x4d], - ['{78}', 0x4e], - ['{79}', 0x4f], - ['{80}', 0x50], - ['{81}', 0x51], - ['{82}', 0x52], - ['{83}', 0x53], - ['{84}', 0x54], - ['{85}', 0x55], - ['{86}', 0x56], - ['{87}', 0x57], - ['{88}', 0x58], - ['{89}', 0x59], - ['{90}', 0x5a], - ['{91}', 0x5b], - ['{92}', 0x5c], - ['{93}', 0x5d], - ['{94}', 0x5e], - ['{95}', 0x5f], - // Column 4 - ['{96}', 0x60], - ['{97}', 0x61], - ['{98}', 0x62], - ['{99}', 0x63], - ['{100}', 0x64], - ['{101}', 0x65], - ['{102}', 0x66], - ['{103}', 0x67], - ['{104}', 0x68], - ['{105}', 0x69], - ['{106}', 0x6a], - ['{107}', 0x6b], - ['{108}', 0x6c], - ['{109}', 0x6d], - ['{110}', 0x6e], - ['{111}', 0x6f], - ['{112}', 0x70], - ['{113}', 0x71], - ['{114}', 0x72], - ['{115}', 0x73], - ['{116}', 0x74], - ['{117}', 0x75], - ['{118}', 0x76], - ['{119}', 0x77], - ['{120}', 0x78], - ['{121}', 0x79], - ['{122}', 0x7a], - ['{123}', 0x7b], - ['{124}', 0x7c], - ['{125}', 0x7d], - ['{126}', 0x7e], - ['{127}', 0x7f], - // Column 5 - ['{128}', 0x80], - ['{129}', 0x81], ['{org}', 0x81], - ['{130}', 0x82], - ['{131}', 0x83], - ['{132}', 0x84], - ['{133}', 0x85], ['{f1}', 0x85], - ['{134}', 0x86], ['{f3}', 0x86], - ['{135}', 0x87], ['{f5}', 0x87], - ['{136}', 0x88], ['{f7}', 0x88], - ['{137}', 0x89], ['{f2}', 0x89], - ['{138}', 0x8a], ['{f4}', 0x8a], - ['{139}', 0x8b], ['{f6}', 0x8b], - ['{140}', 0x8c], ['{f8}', 0x8c], - ['{141}', 0x8d], - ['{142}', 0x8e], - ['{143}', 0x8f], - ['{144}', 0x90], ['{blk}', 0x90], - ['{145}', 0x91], ['{up}', 0x91], - ['{146}', 0x92], ['{rvs off}', 0x92], - ['{147}', 0x93], ['{clr}', 0x93], ['{clear}', 0x93], - ['{148}', 0x94], - ['{149}', 0x95], ['{brn}', 0x95], - ['{150}', 0x96], ['{lred}', 0x96], - ['{151}', 0x97], ['{dgry}', 0x97], ['{gry1}', 0x97], - ['{152}', 0x98], ['{mgry}', 0x98], ['{gry2}', 0x98], - ['{153}', 0x99], ['{lgrn}', 0x99], - ['{154}', 0x9a], ['{lblu}', 0x9a], - ['{155}', 0x9b], ['{lgry}', 0x9b], ['{gry3}', 0x9b], - ['{156}', 0x9c], ['{pur}', 0x9c], - ['{157}', 0x9d], ['{left}', 0x9d], - ['{158}', 0x9e], ['{yel}', 0x9e], - ['{159}', 0x9f], ['{cyn}', 0x9f], - // Column 6 - ['{160}', 0xa0], - ['{161}', 0xa1], - ['{162}', 0xa2], - ['{163}', 0xa3], - ['{164}', 0xa4], - ['{165}', 0xa5], - ['{166}', 0xa6], - ['{167}', 0xa7], - ['{168}', 0xa8], - ['{169}', 0xa9], - ['{170}', 0xaa], - ['{171}', 0xab], - ['{172}', 0xac], - ['{173}', 0xad], - ['{174}', 0xae], - ['{175}', 0xaf], - ['{176}', 0xb0], - ['{177}', 0xb1], - ['{178}', 0xb2], - ['{179}', 0xb3], - ['{180}', 0xb4], - ['{181}', 0xb5], - ['{182}', 0xb6], - ['{183}', 0xb7], - ['{184}', 0xb8], - ['{185}', 0xb9], - ['{186}', 0xba], - ['{187}', 0xbb], - ['{188}', 0xbc], - ['{189}', 0xbd], - ['{190}', 0xbe], - ['{191}', 0xbf], - // Column 7 - ['{192}', 0xc0], - ['{193}', 0xc1], - ['{194}', 0xc2], - ['{195}', 0xc3], - ['{196}', 0xc4], - ['{197}', 0xc5], - ['{198}', 0xc6], - ['{199}', 0xc7], - ['{200}', 0xc8], - ['{201}', 0xc9], - ['{202}', 0xca], - ['{203}', 0xcb], - ['{204}', 0xcc], - ['{205}', 0xcd], - ['{206}', 0xce], - ['{207}', 0xcf], - ['{208}', 0xd0], - ['{209}', 0xd1], - ['{210}', 0xd2], - ['{211}', 0xd3], - ['{212}', 0xd4], - ['{213}', 0xd5], - ['{214}', 0xd6], - ['{215}', 0xd7], - ['{216}', 0xd8], - ['{217}', 0xd9], - ['{218}', 0xda], - ['{219}', 0xdb], - ['{220}', 0xdc], - ['{221}', 0xdd], - ['{222}', 0xde], - ['{223}', 0xdf], - // Column 8 - ['{224}', 0xe0], - ['{225}', 0xe1], - ['{226}', 0xe2], - ['{227}', 0xe3], - ['{228}', 0xe4], - ['{229}', 0xe5], - ['{230}', 0xe6], - ['{231}', 0xe7], - ['{232}', 0xe8], - ['{233}', 0xe9], - ['{234}', 0xea], - ['{235}', 0xeb], - ['{236}', 0xec], - ['{237}', 0xed], - ['{238}', 0xee], - ['{239}', 0xef], - ['{240}', 0xf0], - ['{241}', 0xf1], - ['{242}', 0xf2], - ['{243}', 0xf3], - ['{244}', 0xf4], - ['{245}', 0xf5], - ['{246}', 0xf6], - ['{247}', 0xf7], - ['{248}', 0xf8], - ['{249}', 0xf9], - ['{250}', 0xfa], - ['{251}', 0xfb], - ['{252}', 0xfc], - ['{253}', 0xfd], - ['{254}', 0xfe], - ['{255}', 0xff] -]; - -// DO NOT REMOVE - Verification signature -CBM_SIGNATURE = "READY"; \ No newline at end of file diff --git a/html/SPECIAL.js b/html/SPECIAL.js index f83da1eea..f25697ae3 100644 --- a/html/SPECIAL.js +++ b/html/SPECIAL.js @@ -12,8 +12,7 @@ // in your browser to apply changes. // // EXAMPLES: -// var SCRIPT_TO_LOAD = "Default.js"; // Load default profile // var SCRIPT_TO_LOAD = "CBMprgStudio.js"; // Load CBM prg Studio mapping // ========================================================================= -var SCRIPT_TO_LOAD = "Default.js"; \ No newline at end of file +var SCRIPT_TO_LOAD = "CBMprgStudio.js"; \ No newline at end of file diff --git a/html/index.html b/html/index.html index 024a9efe9..2391557fe 100644 --- a/html/index.html +++ b/html/index.html @@ -11,11 +11,11 @@ - - + @@ -1948,7 +1948,7 @@

BASIC Editor / Tokenizer

diff --git a/html/SPECIAL.js b/html/special.js similarity index 86% rename from html/SPECIAL.js rename to html/special.js index f25697ae3..1a905d63f 100644 --- a/html/SPECIAL.js +++ b/html/special.js @@ -12,7 +12,7 @@ // in your browser to apply changes. // // EXAMPLES: -// var SCRIPT_TO_LOAD = "CBMprgStudio.js"; // Load CBM prg Studio mapping +// var SCRIPT_TO_LOAD = "cbm_prg_studio.js"; // Load CBM prg Studio mapping // ========================================================================= -var SCRIPT_TO_LOAD = "CBMprgStudio.js"; \ No newline at end of file +var SCRIPT_TO_LOAD = "cbm_prg_studio.js"; \ No newline at end of file From ade99cc08089d9260c2a57bd122427c3eb8b9e85 Mon Sep 17 00:00:00 2001 From: Christian Gleissner Date: Thu, 3 Sep 2026 12:31:47 +0100 Subject: [PATCH 42/60] Set the caret on the textarea, not on the jQuery object A tag clicked in the table was inserted, then setSelectionRange threw and the caret was left at the end of the text instead of after the tag. --- html/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/html/index.html b/html/index.html index 70261bef8..06a34dd40 100644 --- a/html/index.html +++ b/html/index.html @@ -803,7 +803,7 @@ $(window).scrollTop(scrollPos); const newCursorPos = start + token.length; - $editor.setSelectionRange(newCursorPos, newCursorPos); + $editor[0].setSelectionRange(newCursorPos, newCursorPos); } }); } From 5a6377775efdf5654ce84eda0c25f1a9f36eab53 Mon Sep 17 00:00:00 2001 From: Christian Gleissner Date: Thu, 3 Sep 2026 12:31:47 +0100 Subject: [PATCH 43/60] Refuse an upload that cannot produce a valid program With no profile loaded the keyword table is empty and every keyword was uploaded as its plain characters. With no numbered line in the editor the link pointer of the last line was written to a line that is not there, which threw and left the page silent. --- html/index.html | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/html/index.html b/html/index.html index 06a34dd40..3edb28714 100644 --- a/html/index.html +++ b/html/index.html @@ -372,11 +372,28 @@ async function parseBASIC() { var textarea = $("#basiceditor").val(); + // Without a profile there are no keyword or special character tables, and + // every keyword would be uploaded as its plain characters instead. + if (!window.TOKENS || window.TOKENS.length === 0 || + !window.SPECIAL || window.SPECIAL.length === 0) { + showBASICerror("No tokenizer profile is loaded. " + + "Check SCRIPT_TO_LOAD in /Flash/html/special.js."); + return false; + } + // Split into lines, keep only those starting with a digit, and join back var lines = textarea.split('\n') .map(line => line.trim()) .filter(line => /^\d/.test(line)); + // The link pointer of the last line is written after the loop below, which + // has no last line to write to when the editor holds no numbered line. + if (lines.length === 0) { + showBASICerror("There is no BASIC line to upload. " + + "A line has to start with a line number."); + return false; + } + const tokenized_lines = []; let addr = 2049; From ad75c9563a5c06f0b2ac0a5e7bccfe7d0b1362d6 Mon Sep 17 00:00:00 2001 From: Christian Gleissner Date: Thu, 3 Sep 2026 12:31:47 +0100 Subject: [PATCH 44/60] Cover what the BASIC editor uploads Reads the bytes the page posts to machine:writemem for tags, abbreviations, the repetition shorthand and a null-terminated line, and covers the three refusals. Chrome and Firefox. --- run-tests | 6 + tests/e2e/web/tokenizer_test.py | 394 ++++++++++++++++++++++++++++++++ 2 files changed, 400 insertions(+) create mode 100644 tests/e2e/web/tokenizer_test.py diff --git a/run-tests b/run-tests index 52069483c..48036364a 100755 --- a/run-tests +++ b/run-tests @@ -240,6 +240,12 @@ SUITES: Sequence[Suite] = ( # address fails here rather than on somebody's desk. Manual for the same # reason web-theme is. Suite("e2e", "web-index", "tests/e2e/web/index_test.py", "", manual=True), + # Also needs no device: the BASIC editor turns typed text into the bytes of + # a program in C64 memory, and nothing on the page shows those bytes, so a + # keyword uploaded as plain characters or a wrong link pointer is invisible + # until the program is run. It reads the upload the page sends the stub. + # Manual for the same reason web-index is. + Suite("e2e", "web-tokenizer", "tests/e2e/web/tokenizer_test.py", "", manual=True), # Validates tests/e2e/lib/ui_backend.py itself (Telnet, REST/Freeze, # REST/Overlay) before any suite built on it runs, so a broken shared # facade fails here with a clear cause instead of as confusing failures diff --git a/tests/e2e/web/tokenizer_test.py b/tests/e2e/web/tokenizer_test.py new file mode 100644 index 000000000..c0db8311c --- /dev/null +++ b/tests/e2e/web/tokenizer_test.py @@ -0,0 +1,394 @@ +#!/usr/bin/env python3 +# E2E: what the BASIC editor of html/index.html uploads, driven in real browsers. + +"""The tokenizer tab of the device's home page, checked against what it sends. + +The editor turns typed BASIC into the bytes of a program in C64 memory and +posts them to `POST /v1/machine:writemem`. Nothing on the page shows those +bytes, so a keyword that was uploaded as plain characters, a link pointer that +points at the wrong address, or a program that was never sent at all all look +the same in the browser. The checks here read the request instead. + +The keyword and special-character tables live in a profile that `html/special.js` +names and `index.html` loads at run time, so the profile is part of what is +under test: a page whose profile did not load has no tables at all. + +What the checks cover: + +- the profile named by `html/special.js` loads, fills the editor with the sample + program it carries, and renders the clickable special-character table; +- a program using the tag syntax, the `?` and `goS` keyword abbreviations and + the `{space*2}` repetition shorthand reaches the device as the exact bytes of + a BASIC program: link pointer, line number, tokens, and the two zero bytes + that end the program; +- `{null}` ends the line where it appears, and the rest of that line is dropped, + which is what the C64's own interpreter does with a zero byte in a line; +- clicking a character in the table inserts its tag at the caret and leaves the + caret after it, so the next click inserts after the first rather than before; +- an editor holding no numbered line is refused with a message, rather than + ending in the code that writes the link pointer of a line that is not there; +- a page whose profile never loaded refuses to upload, rather than uploading a + program in which every keyword became its plain characters. + +The device is `device_stub.py`, the same stand-in the other web suites use, +handed `html/` so that it serves the pages as well as the REST calls and can be +asked afterwards what it was sent. The typing and the clicks are what a person +would do. + +Host packages: selenium. See tests/requirements.txt. Also needs Chrome or +Firefox installed with their WebDriver on PATH, and a route to the CDN the page +loads jQuery from. Whatever is missing is reported as a skip. +""" + +import argparse +import os +import pathlib +import shutil +import sys +import tempfile +import time + +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) +sys.path.insert(0, os.path.join( + os.path.dirname(os.path.abspath(__file__)), "..", "..", "lib")) + +import browser as browser_lib # noqa: E402 +from device_stub import DeviceStub # noqa: E402 +# The tokenizer is a tab of the page index_test.py drives, reached through the +# same stub and the same proxy, so it is driven by the same class. +from index_test import Page # noqa: E402 +from report import (Failure, check, check_skip, detail, # noqa: E402 + section, suite_fail, suite_ok) + +REPO_ROOT = pathlib.Path(__file__).resolve().parents[3] +PAGES = REPO_ROOT / "html" + +READY_TIMEOUT = 20.0 + +WRITEMEM = "/v1/machine:writemem" + +# Where a BASIC program starts on a C64, and what the page sends as the address. +BASIC_START = 0x0801 + +# A program that exercises what the profile adds: a tag inside a string, the +# `?` and `goS` abbreviations, and the `{space*2}` repetition shorthand. +PROGRAM = '10 print "{clear}hi"\n20 ? "{space*2}a"\n30 goS 100' + +# What that program is in memory. Each line is a link pointer to the next line, +# a line number, its bytes and a zero; two zero bytes end the program. PRINT is +# 153, GOSUB is 141, {clear} is 147, and a lower-case letter reaches PETSCII as +# 0x41 upwards, so "hi" is 72, 73. +PROGRAM_BYTES = bytes([ + 0x0D, 0x08, 10, 0, 153, 32, 34, 147, 72, 73, 34, 0, # 10 print "{clear}hi" + 0x19, 0x08, 20, 0, 153, 32, 34, 32, 32, 65, 34, 0, # 20 ? "{space*2}a" + 0x23, 0x08, 30, 0, 141, 32, 49, 48, 48, 0, # 30 goS 100 + 0, 0, +]) + +# A zero byte ends a line on a C64 whatever follows it, so the 'b"' is dropped. +NULL_PROGRAM = '10 print "a{null}b"' +NULL_PROGRAM_BYTES = bytes([0x0A, 0x08, 10, 0, 153, 32, 34, 65, 0, 0, 0]) + +# A character in the table to click, the line it is clicked into, and where the +# caret sits when it is clicked. +CLICKED_TAG = "{clear}" +INSERT_INTO = '10 print "hi"' +INSERT_AT = 10 + + +def parse_args(): + parser = argparse.ArgumentParser(description=__doc__.split("\n")[0]) + parser.add_argument("--browser", default="all", choices=("all",) + browser_lib.BROWSERS, + help="Which browsers to drive. Default: every one installed.") + parser.add_argument("-t", "--timeout", type=float, default=READY_TIMEOUT, + help="How long a page has to become ready.") + return parser.parse_args() + + +def expect(label, got, want): + if got != want: + raise Failure("%s is %r, expected %r" % (label, got, want)) + + +def wait_for(page, condition): + """Whether `condition` became true in the page within its timeout.""" + from selenium.webdriver.support.ui import WebDriverWait + + def holds(driver): + try: + return bool(driver.execute_script("return %s" % condition)) + except Exception: + return False + + try: + WebDriverWait(page.driver, page.timeout).until(holds) + return True + except Exception: + return False + + +def open_tokenizer(page): + """Show the tokenizer tab, once the profile it needs has loaded.""" + ready = wait_for(page, "window.CBM_SIGNATURE === 'READY'") + page.show_page("showtokenizer") + return ready + + +def type_program(page, text): + """Replace whatever is in the editor with `text`, by typing it.""" + editor = page.element("basiceditor") + editor.clear() + editor.send_keys(text) + + +def uploaded(stub, timeout=5.0): + """The POST that carries the program, or None if none was sent. + + The page writes the variable pointer with a PUT to the same route, so the + method is what tells the program upload from the write that follows it. + """ + deadline = time.time() + timeout + while time.time() < deadline: + posts = [call for call in stub.calls_to(WRITEMEM) if call.method == "POST"] + if posts: + return posts[0] + time.sleep(0.02) + return None + + +def upload(page, text): + """Type a program, press Upload, and return the POST it produced.""" + type_program(page, text) + page.stub.clear() + page.click("submitBASIC") + return uploaded(page.stub) + + +def error_shown(page): + """The message the editor is showing, or "" when the box is hidden.""" + if not page.visible("basicmsg"): + return "" + return page.element("basicmsg").text + + +def check_the_profile_loads(page): + """The page reaches its profile, and takes the editor and the table from it.""" + with check("the profile named in special.js loads and fills the editor"): + if not wait_for(page, "window.CBM_SIGNATURE === 'READY'"): + raise Failure("the profile never reported READY, so the page has no " + "keyword or special character tables at all") + expect("the number of keywords", page.script("window.TOKENS.length > 0"), True) + editor = page.script("document.getElementById('basiceditor').value") + if editor != page.script("window.BASIC_CODE"): + raise Failure("the editor holds %r, which is not the sample program the " + "profile carries" % editor[:60]) + + with check("the special character table is rendered and its tags are clickable"): + count = page.script("document.querySelectorAll('#tableContainer " + ".special-token').length") + if not count: + raise Failure("the table has no tags in it") + tagged = page.script("!!document.querySelector('#tableContainer " + ".special-token[data-token=\"%s\"]')" % CLICKED_TAG) + expect("whether %s is offered" % CLICKED_TAG, tagged, True) + detail("%d tags rendered" % count) + + +def check_a_program_reaches_the_device(page): + """Tags, abbreviations and the repetition shorthand reach memory as bytes.""" + with check("a program using tags and abbreviations is uploaded as C64 bytes"): + call = upload(page, PROGRAM) + if call is None: + raise Failure("no program was sent; the page sent %r" + % page.stub.rest_calls()) + expect("the address", call.query.get("address"), "%04x" % BASIC_START) + if call.body != PROGRAM_BYTES: + raise Failure("the program reached the device as %r, expected %r" + % (list(call.body), list(PROGRAM_BYTES))) + detail("%d bytes, three lines linked from $%04x" % (len(call.body), BASIC_START)) + + +def check_null_ends_the_line(page): + """A zero byte ends the line, and what follows it on that line is dropped.""" + with check("{null} ends the line and the rest of that line is not uploaded"): + call = upload(page, NULL_PROGRAM) + if call is None: + raise Failure("no program was sent; the page sent %r" + % page.stub.rest_calls()) + if call.body != NULL_PROGRAM_BYTES: + raise Failure("the program reached the device as %r, expected %r" + % (list(call.body), list(NULL_PROGRAM_BYTES))) + + +def check_clicking_a_tag_inserts_it(page): + """A tag clicked in the table lands at the caret, which then sits after it.""" + from selenium.webdriver.common.by import By + + # Into the middle of a line rather than into an empty editor: setting the + # value of a textarea leaves the caret at the end of it by itself, so an + # empty editor would report the caret in the right place however the page + # got there. + type_program(page, INSERT_INTO) + page.driver.execute_script( + "const e = document.getElementById('basiceditor');" + "e.focus(); e.setSelectionRange(%d, %d);" % (INSERT_AT, INSERT_AT)) + + with check("clicking %s inserts it at the caret, which then sits after it" + % CLICKED_TAG): + page.driver.find_element( + By.CSS_SELECTOR, + '#tableContainer .special-token[data-token="%s"]' % CLICKED_TAG).click() + expect("the editor", page.script("document.getElementById('basiceditor').value"), + INSERT_INTO[:INSERT_AT] + CLICKED_TAG + INSERT_INTO[INSERT_AT:]) + # The caret is what a second click depends on: left where the insert + # happened to leave it, the next tag lands somewhere else again. + expect("the caret", + page.script("document.getElementById('basiceditor').selectionStart"), + INSERT_AT + len(CLICKED_TAG)) + + +def check_an_editor_without_a_line_number(page): + """Text with no numbered line is refused, and nothing is sent.""" + with check("an editor holding no numbered line is refused with a message"): + type_program(page, "hello") + page.stub.clear() + page.click("submitBASIC") + if uploaded(page.stub, timeout=1.0) is not None: + raise Failure("the page uploaded something for text that holds no " + "BASIC line") + message = error_shown(page) + if not message: + raise Failure("nothing was sent and nothing was said: the page ended in " + "the code that links the last line, which is not there") + detail(message) + + +def check_a_page_without_a_profile(webdriver, browser, timeout, directory): + """A page whose profile did not load refuses to upload anything.""" + pages = pages_without_a_profile(directory) + stub = DeviceStub(pages) + try: + page = Page(webdriver, browser, stub, timeout) + try: + page.open() + if not page.jquery_reached(): + with check("a page with no profile refuses to upload"): + check_skip("this host has no route to the CDN the page loads " + "jQuery from") + return + page.show_page("showtokenizer") + with check("a page whose profile did not load refuses to upload"): + type_program(page, "10 print 1") + stub.clear() + page.click("submitBASIC") + if uploaded(stub, timeout=1.0) is not None: + raise Failure("the page uploaded a program with no keyword table " + "loaded, so every keyword in it became its plain " + "characters") + message = error_shown(page) + if not message: + raise Failure("nothing was sent and nothing was said") + detail(message) + finally: + page.close() + finally: + stub.close() + + +def check_clear_asks_first(page): + """Clear asks before emptying the editor, and No leaves the text alone.""" + type_program(page, "10 print 1") + with check("Clear asks first, and answering No leaves the program alone"): + page.click("clearBASIC") + if not page.visible("customModalOverlay"): + raise Failure("Clear emptied the editor without asking") + page.click("modalNo") + expect("the editor", page.script("document.getElementById('basiceditor').value"), + "10 print 1") + + with check("answering Yes empties the editor"): + page.click("clearBASIC") + page.click("modalYes") + expect("the editor", page.script("document.getElementById('basiceditor').value"), + "") + + +def pages_without_a_profile(directory): + """A copy of html/ whose special.js names no profile to load.""" + target = pathlib.Path(directory) / "html" + if target.exists(): + shutil.rmtree(target) + shutil.copytree(PAGES, target) + special = target / "special.js" + text = special.read_text() + emptied = text.replace('var SCRIPT_TO_LOAD = "cbm_prg_studio.js";', + 'var SCRIPT_TO_LOAD = "";') + if emptied == text: + raise Failure("%s no longer sets SCRIPT_TO_LOAD the way this check empties it, " + "so the page it serves would still load a profile" % special) + special.write_text(emptied) + return target + + +def run_browser(webdriver, browser, timeout, directory): + section(browser) + stub = DeviceStub(PAGES) + try: + page = Page(webdriver, browser, stub, timeout) + try: + page.open() + if not page.jquery_reached(): + with check("index.html reaches the CDN it loads jQuery from"): + check_skip("this host has no route to that CDN, and the page " + "does nothing at all without it") + return + if not open_tokenizer(page): + with check("the profile named in special.js loads"): + raise Failure("the profile never reported READY") + return + check_the_profile_loads(page) + check_a_program_reaches_the_device(page) + check_null_ends_the_line(page) + check_clicking_a_tag_inserts_it(page) + check_an_editor_without_a_line_number(page) + check_clear_asks_first(page) + finally: + page.close() + finally: + stub.close() + check_a_page_without_a_profile(webdriver, browser, timeout, directory) + + +def run(args, directory): + webdriver = browser_lib.require_selenium() + wanted = browser_lib.BROWSERS if args.browser == "all" else (args.browser,) + drove_one = False + for browser in wanted: + here, why = browser_lib.available(webdriver, browser) + if not here: + section(browser) + with check("%s and its WebDriver are installed" % browser): + check_skip(why) + continue + drove_one = True + run_browser(webdriver, browser, args.timeout, directory) + if not drove_one: + raise Failure("no browser this suite can drive is installed") + + +def main(): + args = parse_args() + try: + if not (PAGES / "index.html").exists(): + raise Failure("%s is missing" % PAGES) + with tempfile.TemporaryDirectory(prefix="web-tokenizer-") as directory: + run(args, directory) + except (Failure, browser_lib.Unavailable) as exc: + suite_fail("web_tokenizer", str(exc)) + return 1 + suite_ok("web_tokenizer") + return 0 + + +if __name__ == "__main__": + raise SystemExit(main()) From 6ec81004cc8411ce6d03494c1b6efb665b7209c9 Mon Sep 17 00:00:00 2001 From: radius75 Date: Thu, 3 Sep 2026 21:52:53 +0200 Subject: [PATCH 45/60] Fix tokenizer profile description --- html/special.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/html/special.js b/html/special.js index 1a905d63f..46fe6f530 100644 --- a/html/special.js +++ b/html/special.js @@ -7,12 +7,15 @@ // // - Path: Files are typically located in /Flash/html/ on your device. // - Filename: Must be enclosed in quotes (e.g., "filename.js"). -// - Custom sets: Enabling a custom set will override defaults. +// - Tokenizer tables are loaded from the selected external file. // - Refresh: After editing this file, perform a Hard Reload (Ctrl+F5) // in your browser to apply changes. // // EXAMPLES: // var SCRIPT_TO_LOAD = "cbm_prg_studio.js"; // Load CBM prg Studio mapping +// +// If the selected file cannot be loaded or contains syntax errors, +// the tokenizer will display an error message. // ========================================================================= var SCRIPT_TO_LOAD = "cbm_prg_studio.js"; \ No newline at end of file From d6b20ff7e1eeed811823ae999a8b7e1f3943a81f Mon Sep 17 00:00:00 2001 From: radius75 Date: Sun, 6 Sep 2026 08:46:06 +0200 Subject: [PATCH 46/60] Tokenizer case normalization * Add an optional `NORMALIZE_TO_LOWERCASE` setting to tokenizer profiles. * BASIC source lines are always trimmed before tokenization, removing leading and trailing whitespace. * When `NORMALIZE_TO_LOWERCASE = true`, the trimmed source is converted to lowercase before tokenization. For example, `10 PrInT "Hello"` is tokenized as `10 print "hello"`. * When `NORMALIZE_TO_LOWERCASE = false`, the original character case is preserved. * The `cbm_prg_studio.js` profile uses `NORMALIZE_TO_LOWERCASE = false` because its tokenizer uses case-sensitive abbreviations and character mappings. * The setting affects only the source copy used for tokenization; the text displayed in the editor is not modified. * Custom tokenizer profiles can set the option to `true` when BASIC keywords should be handled case-insensitively. --- html/cbm_prg_studio.js | 30 ++++++++++++++++++++++++++++++ html/index.html | 11 +++++++++-- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/html/cbm_prg_studio.js b/html/cbm_prg_studio.js index 83d4fe0af..72b0a7523 100644 --- a/html/cbm_prg_studio.js +++ b/html/cbm_prg_studio.js @@ -117,6 +117,36 @@ BASIC_CODE = `!- Welcome to Ultimate BASIC Editor / Tokenizer 100 print:for i = 0 to 2000: next: return `; // +// CASE NORMALIZATION: +// +// NORMALIZE_TO_LOWERCASE controls whether the BASIC source is converted +// to lowercase before tokenization: +// +// true - convert the source to lowercase +// false - preserve the original character case +// +// For example, with NORMALIZE_TO_LOWERCASE = true: +// +// 10 PRINT "Hello" +// 20 PrInT "World" +// +// are tokenized as: +// +// 10 print "hello" +// 20 print "world" +// +// The text displayed in the editor is not changed. +// +// Use true for profiles where BASIC keywords should be matched +// case-insensitively and the profile does not rely on case-sensitive +// or shifted C64/PETSCII characters. +// +// Use false when the profile needs to preserve the original character case. +// +// The variable must be defined by every tokenizer profile. +// +NORMALIZE_TO_LOWERCASE = false; +// // Special Character Mapping SPECIAL = [ //Column 1 diff --git a/html/index.html b/html/index.html index 3edb28714..ee59ac8c3 100644 --- a/html/index.html +++ b/html/index.html @@ -381,9 +381,16 @@ return false; } - // Split into lines, keep only those starting with a digit, and join back + // Split into lines and prepare each line for tokenization. + // Leading and trailing whitespace is always removed. + // Optionally normalize the source to lowercase according to the tokenizer profile. var lines = textarea.split('\n') - .map(line => line.trim()) + .map(line => { + line = line.trim(); + if (NORMALIZE_TO_LOWERCASE) + line = line.toLowerCase(); + return line; + }) .filter(line => /^\d/.test(line)); // The link pointer of the last line is written after the loop below, which From 6eccbb2f6c5b9e6f9cf3fa4e367e0194e0618192 Mon Sep 17 00:00:00 2001 From: radius75 Date: Mon, 7 Sep 2026 10:08:01 +0200 Subject: [PATCH 47/60] For full compatibility with CBMprgStudio, BASIC commands can now be entered using uppercase, lowercase, or supported abbreviations. For example: `GOTO`, `goto`, `gO`, `goT`. Non-keyword characters outside quoted strings are normalized to lowercase, including text following `REM` and `DATA`. Compatibility with the previous tokenizer version from master is preserved when full normalization is enabled by setting NORMALIZE_TO_LOWERCASE = true in the profile file. Tests were performed using BASIC programs from the Commodore 64 Games Book 1 collection: https://github.com/TypeInBooks/books/tree/master/commodore/c64/gamesbook1 --- html/cbm_prg_studio.js | 145 +++++++++++++++++++++-------------------- html/index.html | 10 ++- 2 files changed, 80 insertions(+), 75 deletions(-) diff --git a/html/cbm_prg_studio.js b/html/cbm_prg_studio.js index 72b0a7523..7204f5c96 100644 --- a/html/cbm_prg_studio.js +++ b/html/cbm_prg_studio.js @@ -29,7 +29,9 @@ BASIC_CODE = `!- Welcome to Ultimate BASIC Editor / Tokenizer !- Current Profile: CBM prg Studio Mapping Standard Basic !- !- QUICK TIPS: -!- - Use lowercase for BASIC commands (e.g. print, goto). +!- - Use uppercase or lowercase for BASIC commands (e.g. print, PRINT). +!- - C64 BASIC keyword abbreviations are permitted, +!- e.g., goto > gO, print > ?, then > tH. !- - Special keys use curly braces: {clear}, {red}, {f1}, etc. !- - Control/Commodore keys: {ct a} / {cm a}. !- - Shift/Uppercase: Typing UPPERCASE letters in this editor @@ -39,8 +41,6 @@ BASIC_CODE = `!- Welcome to Ultimate BASIC Editor / Tokenizer !- These are compliant with CBM prg Studio, though !- alternative formats such as {5 space}, {3 asterisk}, !- or {3 *} are also acceptable. -!- - C64 BASIC keyword abbreviations are permitted, -!- e.g., goto > gO, print > ?, then > tH. !- !- IMPORTANT: !- For mathematical operators, signs should not be placed @@ -61,7 +61,8 @@ BASIC_CODE = `!- Welcome to Ultimate BASIC Editor / Tokenizer !- clear screen, set uppercase mode and white color 10 print "{clear}{uppercase}{white}"; !- print HELLO WORLD! text -11 print "hello world!" +11 print "hello" +12 PRINT "world!" !- gosub to delay loop 20 gosub 100 @@ -417,74 +418,74 @@ SPECIAL = [ // // BASIC Instructions and Commands Mapping TOKENS = [ - ['restore', 140], ['reS', 140], ['resT', 140], ['restO', 140], ['restoR', 140], - ['input#', 132], ['iN', 132], ['inP', 132], ['inpU', 132], ['inpuT', 132], - ['return', 142], ['reT', 142], ['retU', 142], ['retuR', 142], - ['verify', 149], ['vE', 149], ['veR', 149], ['verI', 149], ['veriF', 149], - ['print#', 152], ['pR', 152], ['prI', 152], ['priN', 152], ['prinT', 152], - ['right$', 201], ['rI', 201], ['riG', 201], ['rigH', 201], ['righT', 201], - ['input', 133], //No abbreviation - ['gosub', 141], ['goS', 141], ['gosU', 141], - ['print', 153], ['?', 153], - ['close', 160], ['clO', 160], ['cloS', 160], - ['left$', 200], ['leF', 200], ['lefT', 200], - ['next', 130], ['nE', 130], ['neX', 130], - ['data', 131], ['dA', 131], - ['read', 135], ['rE', 135], - ['goto', 137], ['gO', 137], ['goT', 137], - ['stop', 144], ['sT', 144], ['stO', 144], - ['wait', 146], ['wA', 146], ['waI', 146], - ['load', 147], ['lO', 147], ['loA', 147], - ['save', 148], ['sA', 148], ['saV', 148], - ['poke', 151], ['pO', 151], ['poK', 151], - ['cont', 154], ['cO', 154], ['coN', 154], - ['list', 155], ['lI', 155], ['liS', 155], - ['open', 159], ['oP', 159], ['opE', 159], - ['tab(', 163], ['tA', 163], ['taB', 163], - ['spc(', 166], ['sP', 166], ['spC', 166], - ['then', 167], ['tH', 167], ['thE', 167], - ['step', 169], ['stE', 169], - ['peek', 194], ['pE', 194], ['peE', 194], - ['str$', 196], ['stR', 196], - ['chr$', 199], ['cH', 199], ['chR', 199], - ['mid$', 202], ['mI', 202], ['miD', 202], - ['end', 128], ['eN', 128], - ['for', 129], ['fO', 129], - ['dim', 134], ['dI', 134], - ['let', 136], ['lE', 136], - ['run', 138], ['rU', 138], - ['rem', 143], //No abbreviation - ['def', 150], ['dE', 150], - ['clr', 156], ['cL', 156], - ['cmd', 157], ['cM', 157], - ['sys', 158], ['sY', 158], - ['get', 161], ['gE', 161], - ['new', 162], //No abbreviation - ['not', 168], ['nO', 168], - ['and', 175], ['aN', 175], - ['sgn', 180], ['sG', 180], - ['int', 181], //No abbreviation - ['abs', 182], ['aB', 182], - ['usr', 183], ['uS', 183], - ['fre', 184], ['fR', 184], - ['pos', 185], //No abbreviation - ['sqr', 186], ['sQ', 186], - ['rnd', 187], ['rN', 187], - ['log', 188], //No abbreviation - ['exp', 189], ['eX', 189], - ['cos', 190], //No abbreviation - ['sin', 191], ['sI', 191], - ['tan', 192], //No abbreviation - ['atn', 193], ['aT', 193], - ['len', 195], //No abbreviation - ['val', 197], ['vA', 197], - ['asc', 198], ['aS', 198], - ['if', 139], //No abbreviation - ['on', 145], //No abbreviation - ['to', 164], //No abbreviation - ['fn', 165], //No abbreviation - ['or', 176], //No abbreviation - ['go', 203], //No abbreviation + ['RESTORE', 140], ['restore', 140], ['reS', 140], ['resT', 140], ['restO', 140], ['restoR', 140], + ['INPUT#', 132], ['input#', 132], ['iN', 132], ['inP', 132], ['inpU', 132], ['inpuT', 132], + ['RETURN', 142], ['return', 142], ['reT', 142], ['retU', 142], ['retuR', 142], + ['VERIFY', 149], ['verify', 149], ['vE', 149], ['veR', 149], ['verI', 149], ['veriF', 149], + ['PRINT#', 152], ['print#', 152], ['pR', 152], ['prI', 152], ['priN', 152], ['prinT', 152], + ['RIGHT$', 201], ['right$', 201], ['rI', 201], ['riG', 201], ['rigH', 201], ['righT', 201], + ['INPUT', 133], ['input', 133], //No abbreviation + ['GOSUB', 141], ['gosub', 141], ['goS', 141], ['gosU', 141], + ['PRINT', 153], ['print', 153], ['?', 153], + ['CLOSE', 160], ['close', 160], ['clO', 160], ['cloS', 160], + ['LEFT$', 200], ['left$', 200], ['leF', 200], ['lefT', 200], + ['NEXT', 130], ['next', 130], ['nE', 130], ['neX', 130], + ['DATA', 131], ['data', 131], ['dA', 131], + ['READ', 135], ['read', 135], ['rE', 135], + ['GOTO', 137], ['goto', 137], ['gO', 137], ['goT', 137], + ['STOP', 144], ['stop', 144], ['sT', 144], ['stO', 144], + ['WAIT', 146], ['wait', 146], ['wA', 146], ['waI', 146], + ['LOAD', 147], ['load', 147], ['lO', 147], ['loA', 147], + ['SAVE', 148], ['save', 148], ['sA', 148], ['saV', 148], + ['POKE', 151], ['poke', 151], ['pO', 151], ['poK', 151], + ['CONT', 154], ['cont', 154], ['cO', 154], ['coN', 154], + ['LIST', 155], ['list', 155], ['lI', 155], ['liS', 155], + ['OPEN', 159], ['open', 159], ['oP', 159], ['opE', 159], + ['TAB(', 163], ['tab(', 163], ['tA', 163], ['taB', 163], + ['SPC(', 166], ['spc(', 166], ['sP', 166], ['spC', 166], + ['THEN', 167], ['then', 167], ['tH', 167], ['thE', 167], + ['STEP', 169], ['step', 169], ['stE', 169], + ['PEEK', 194], ['peek', 194], ['pE', 194], ['peE', 194], + ['STR$', 196], ['str$', 196], ['stR', 196], + ['CHR$', 199], ['chr$', 199], ['cH', 199], ['chR', 199], + ['MID$', 202], ['mid$', 202], ['mI', 202], ['miD', 202], + ['END', 128], ['end', 128], ['eN', 128], + ['FOR', 129], ['for', 129], ['fO', 129], + ['DIM', 134], ['dim', 134], ['dI', 134], + ['LET', 136], ['let', 136], ['lE', 136], + ['RUN', 138], ['run', 138], ['rU', 138], + ['REM', 143], ['rem', 143], //No abbreviation + ['DEF', 150], ['def', 150], ['dE', 150], + ['CLR', 156], ['clr', 156], ['cL', 156], + ['CMD', 157], ['cmd', 157], ['cM', 157], + ['SYS', 158], ['sys', 158], ['sY', 158], + ['GET', 161], ['get', 161], ['gE', 161], + ['NEW', 162], ['new', 162], //No abbreviation + ['NOT', 168], ['not', 168], ['nO', 168], + ['AND', 175], ['and', 175], ['aN', 175], + ['SGN', 180], ['sgn', 180], ['sG', 180], + ['INT', 181], ['int', 181], //No abbreviation + ['ABS', 182], ['abs', 182], ['aB', 182], + ['USR', 183], ['usr', 183], ['uS', 183], + ['FRE', 184], ['fre', 184], ['fR', 184], + ['POS', 185], ['pos', 185], //No abbreviation + ['SQR', 186], ['sqr', 186], ['sQ', 186], + ['RND', 187], ['rnd', 187], ['rN', 187], + ['LOG', 188], ['log', 188], //No abbreviation + ['EXP', 189], ['exp', 189], ['eX', 189], + ['COS', 190], ['cos', 190], //No abbreviation + ['SIN', 191], ['sin', 191], ['sI', 191], + ['TAN', 192], ['tan', 192], //No abbreviation + ['ATN', 193], ['atn', 193], ['aT', 193], + ['LEN', 195], ['len', 195], //No abbreviation + ['VAL', 197], ['val', 197], ['vA', 197], + ['ASC', 198], ['asc', 198], ['aS', 198], + ['IF', 139], ['if', 139], //No abbreviation + ['ON', 145], ['on', 145], //No abbreviation + ['TO', 164], ['to', 164], //No abbreviation + ['FN', 165], ['fn', 165], //No abbreviation + ['OR', 176], ['or', 176], //No abbreviation + ['GO', 203], ['go', 203], //No abbreviation // ['+', 170], ['-', 171], diff --git a/html/index.html b/html/index.html index ee59ac8c3..b4a0e6646 100644 --- a/html/index.html +++ b/html/index.html @@ -575,7 +575,7 @@ // * @param {string} s - The input string fragment. // * @param {boolean} tokenize - Whether to attempt keyword tokenization. // * @returns {[number|null, string]} - Array containing the byte value and the remaining string. - function scan(s, tokenize = true) { + function scan(s, tokenize = true, normalize = true) { s = expandCounts(s); if (tokenize) { @@ -605,7 +605,11 @@ } // Convert standard character to PETSCII and move to next char - return [asciiToPetscii(s.charCodeAt(0)), s.substring(1)]; + let ch = s[0]; + if (normalize) + ch = ch.toLowerCase(); + + return [asciiToPetscii(ch.charCodeAt(0)), s.substring(1)]; } // * Expands character repetition shorthands into individual tokens. @@ -649,7 +653,7 @@ while (remainingString && remainingString.length > 0) { // C64 Logic: Tokenization is disabled inside quotes, REM (comments), or after DATA statements let shouldTokenize = !(inQuotes || inRemark || inData); - let [byte, newString] = scan(remainingString, shouldTokenize); + let [byte, newString] = scan(remainingString, shouldTokenize, !inQuotes); // C64 CRITICAL FIX: If a 0x00 byte is generated, terminate the line immediately. // This ensures compatibility with the C64 Kernal/BASIC interpreter, which From 1dfa9de75c13182bc3e98da39009d072b699184c Mon Sep 17 00:00:00 2001 From: radius75 Date: Mon, 7 Sep 2026 17:56:09 +0200 Subject: [PATCH 48/60] clarify lowercase normalization behavior in comments --- html/cbm_prg_studio.js | 8 ++++++-- html/index.html | 11 +++++++---- html/special.js | 4 +++- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/html/cbm_prg_studio.js b/html/cbm_prg_studio.js index 7204f5c96..537f53279 100644 --- a/html/cbm_prg_studio.js +++ b/html/cbm_prg_studio.js @@ -18,7 +18,11 @@ // mnemonic is mapped to a unique token in the 0x00-0xFF range. // - TOOLTIP: Hex-to-Description object mapping for UI tooltips. // -// 3. READY Signature: +// 3. Configuration Flags: +// - NORMALIZE_TO_LOWERCASE: Boolean flag indicating if the entire source +// code should be normalized to lowercase before processing. +// +// 4. READY Signature: // The final line MUST be: 'window.CBM_SIGNATURE = "READY";'. This signals // the main application that the data load is complete and safe to process. // --------------------------------------------------------------------------- @@ -123,7 +127,7 @@ BASIC_CODE = `!- Welcome to Ultimate BASIC Editor / Tokenizer // NORMALIZE_TO_LOWERCASE controls whether the BASIC source is converted // to lowercase before tokenization: // -// true - convert the source to lowercase +// true - convert the entire source code to lowercase // false - preserve the original character case // // For example, with NORMALIZE_TO_LOWERCASE = true: diff --git a/html/index.html b/html/index.html index b4a0e6646..149597c73 100644 --- a/html/index.html +++ b/html/index.html @@ -571,9 +571,9 @@ } - // * Scans the input string for tokens, special characters, or plain text. // * @param {string} s - The input string fragment. // * @param {boolean} tokenize - Whether to attempt keyword tokenization. + // * @param {boolean} normalize - Whether ordinary characters should be normalized to lowercase. // * @returns {[number|null, string]} - Array containing the byte value and the remaining string. function scan(s, tokenize = true, normalize = true) { s = expandCounts(s); @@ -604,7 +604,8 @@ return [null, null]; } - // Convert standard character to PETSCII and move to next char + // Convert an ordinary character to PETSCII. + // When normalization is enabled, convert it to lowercase first. let ch = s[0]; if (normalize) ch = ch.toLowerCase(); @@ -651,7 +652,9 @@ let inData = false; while (remainingString && remainingString.length > 0) { - // C64 Logic: Tokenization is disabled inside quotes, REM (comments), or after DATA statements + // C64 BASIC parsing: keyword tokenization is disabled inside quoted strings, + // REM comments, and DATA statements, while their contents are processed + // as ordinary characters. let shouldTokenize = !(inQuotes || inRemark || inData); let [byte, newString] = scan(remainingString, shouldTokenize, !inQuotes); @@ -1972,7 +1975,7 @@

Live Monitor

BASIC Editor / Tokenizer

-

Here, you may enter a BASIC program (type in lower case, abbreviation is allowed), and upload it directly to your machine.

+

Here, you may enter a BASIC program according to the syntax supported by the currently loaded tokenizer profile, and upload it directly to your machine.