' . htmlspecialchars($m[1]) . ''; return "\x01" . (count($codes) - 1) . "\x02"; }, $s); $s = htmlspecialchars($s, ENT_NOQUOTES); $s = preg_replace('/\*\*(.+?)\*\*/', '$1', $s); $s = preg_replace('/(?$1', $s); $s = preg_replace_callback('/\[([^\]]+)\]\(([^)]+)\)/', static fn ($m) => '' . $m[1] . '', $s); return preg_replace_callback("/\x01(\d+)\x02/", static fn ($m) => $codes[(int) $m[1]], $s); }; for ($i = 0; $i < $n;) { $line = $lines[$i]; if (trim($line) === '') { $i++; continue; } if (str_starts_with($line, '```')) { $code = []; for ($i++; $i < $n && !str_starts_with($lines[$i], '```'); $i++) { $code[] = $lines[$i]; } $i++; $out .= '
' . htmlspecialchars(implode("\n", $code)) . "
\n"; continue; } if (preg_match('/^(#{1,4})\s+(.*)$/', $line, $m)) { $level = strlen($m[1]); $id = trim(preg_replace('/[^a-z0-9]+/', '-', strtolower(iconv('UTF-8', 'ASCII//TRANSLIT', strip_tags($m[2])) ?: 'x')), '-'); $out .= "" . $inline($m[2]) . "\n"; $i++; continue; } if (str_starts_with($line, '|')) { $rows = []; for (; $i < $n && str_starts_with($lines[$i], '|'); $i++) { $rows[] = $lines[$i]; } $cells = static fn (string $r) => array_map('trim', explode('|', trim(preg_replace('/\\\\\|/', "\x03", $r), '|'))); $out .= "
\n"; foreach ($cells($rows[0]) as $c) { $out .= ''; } $out .= "\n\n"; foreach (array_slice($rows, 2) as $r) { $out .= ''; foreach ($cells($r) as $c) { $out .= ''; } $out .= "\n"; } $out .= "
' . str_replace("\x03", '|', $inline($c)) . '
' . str_replace("\x03", '|', $inline($c)) . '
\n"; continue; } if (preg_match('/^\s*[-*]\s+/', $line)) { $out .= "\n"; continue; } $para = []; for (; $i < $n && trim($lines[$i]) !== '' && !preg_match('/^(#|\||```|\s*[-*]\s)/', $lines[$i]); $i++) { $para[] = trim($lines[$i]); } $out .= '

' . $inline(implode(' ', $para)) . "

\n"; } return $out; } function page(string $lang, string $title, string $description, string $path, string $body, string $up, array $alternates, string $nav): string { $alt = ''; foreach ($alternates as $l => $p) { $alt .= "\n"; } $t = htmlspecialchars($title); $d = htmlspecialchars($description); $locale = $lang === 'fr' ? 'fr_FR' : 'en_US'; $play = $lang === 'fr' ? '▶ Jouer' : '▶ Play'; return << $t $alt
$body

$play

HTML; } $links = ['language.md' => '../langage/', 'editor.md' => '../editeur/', 'vm.md' => '../vm/']; $navFr = 'AccueilLe langage ALISL\'éditeurLa machine (doc technique)English'; $navEn = 'HomeThe ALIS languageFrançais'; $language = (string) file_get_contents("$root/docs/language.md"); $editor = (string) file_get_contents("$root/docs/editor.md"); @mkdir("$root/site/langage", 0777, true); @mkdir("$root/site/editeur", 0777, true); @mkdir("$root/site/en/language", 0777, true); file_put_contents("$root/site/langage/index.html", page('fr', 'Le langage de script ALIS – les scripts des jeux Silmarils décompilés', 'Le langage source des scripts ALIS (Robinson\'s Requiem, Ishar, Transarctica) : variables, expressions, instructions, et la table de toutes les instructions de la machine.', 'langage/', md($language, $links), '../', ['fr' => 'langage/', 'en' => 'en/language/', 'x-default' => 'langage/'], $navFr)); file_put_contents("$root/site/editeur/index.html", page('fr', 'L\'éditeur ALIS – modifier les scripts de Robinson\'s Requiem dans le navigateur', 'L\'éditeur de scripts ALIS du moteur Silmarils en PHP : coloration, recherche, compilation, et le jeu relancé avec ta version.', 'editeur/', md($editor, $links) . '

L\'éditeur ALIS ouvert sur le script flags de Robinson\'s Requiem, une erreur de compilation surlignée

', '../', ['fr' => 'editeur/', 'x-default' => 'editeur/'], $navFr)); @mkdir("$root/site/vm", 0777, true); file_put_contents("$root/site/vm/index.html", page('fr', 'La machine virtuelle ALIS – documentation technique de chaque instruction', 'Chaque instruction, élément d\'expression et cible de rangement de la machine ALIS de Silmarils, tels que l\'exécutable DOS de Robinson\'s Requiem les exécute : opérandes, effet, utilisations.', 'vm/', md((string) file_get_contents("$root/docs/vm.md"), $links), '../', ['fr' => 'vm/', 'x-default' => 'vm/'], $navFr)); // English: an overview, then the reference tables of the French document (they are code) $reference = substr($language, (int) strpos($language, "## Référence")); $reference = str_replace(['## Référence', '### Échappements', '### Éléments d\'expression'], ['## Reference', '### Escapes', '### Expression items'], $reference); $en = <<<'MD' # The ALIS scripting language Silmarils' games (Robinson's Requiem, Ishar, Transarctica, Targhan…) are **programs for a virtual machine**, ALIS: each `.io` file of a game is a compiled script (byte code, the variables it reserves, its pictures, sounds and 3D models). This port of the machine to PHP comes with a **decompiler and a compiler**: every script becomes a text in the ALIS source language, and the engine compiles that text back when it loads the script. Silmarils' own sources were never published, so the syntax is a reconstruction: the names of the instructions and expression items are the machine's own (`cput`, `cscmov`, `oimmb`, `oadd`…), and the structures follow the habits of the original compiler, read from the byte code (one pass, left-to-right expressions, the same code for every `if … else` and `while`). The 109 scripts of Robinson's Requiem (46,886 lines) compile back **byte for byte**, and the game started from the sources shows exactly the same pictures as the original. ``` L0049: putnat 108, 0, 137, 5 + vb[0x52], 1 if vw[0x54] { call L010d } table inkey(), -187 goto L00b0 goto L00bf end ``` - variables are named by their address: `vb[0x52]` (a byte of the entity), `vw[...]` (a word), `vs[...]` (a string), `mw[...]` (the main script's), `hw[e, ...]` (another entity's), tables `tb[...](i)`; - expressions are evaluated from left to right: `[ ]` groups, `$+`, `$==`… work on strings; - the engine offers three editions of the game: the original scripts, **ALIS sources** (compiled from the text) and **HD** (the same, with sharp pixels scaled by the GPU, the texts redrawn with a real font and the 3D rendered at twice the resolution); - the **90s form**: the same scripts as a developer of the time could have written them, French words, named and declared variables (`local octet vague @ $52`), `si … alors … sinon … finsi`, `tantque … faire … fintantque`, `:=` to store, `=` / `<>` to compare, `$52` numbers; translated word for word both ways, byte-identical; - **ALIS BASIC**: the scripts as Silmarils' developers most likely wrote them on the Atari ST. The machine's original instruction names are BASIC words (`locate`, `tab`, `dim`, `plot`, `box`, `ink`…), those of GFA BASIC, the language of the ST in France: so `PUTNAT`, `TOPALET` in capitals, `IF … ELSE … ENDIF`, `WHILE … WEND`, `GOSUB`, `SELECT … CASE`, `ADD x, n`, `&H52`, `'` comments, typed variables (`vague|` a byte, `x&` a word, `name$` a string) declared with `LOCAL` / `GLOBAL`; translated word for word both ways, byte-identical; - the **ALIS editor** (home screen: ` - ALIS EDITOR`) edits a script with colours and search, compiles it (a mistake shows its line), keeps your version in your files and starts the game with it (`F5`). The full guide is in French: [le langage ALIS](../../langage/), [l'éditeur](../../editeur/). Below: every instruction of the machine and its operands. MD; file_put_contents("$root/site/en/language/index.html", page('en', 'The ALIS scripting language – Silmarils\' game scripts decompiled', 'The source language of ALIS scripts (Robinson\'s Requiem, Ishar, Transarctica): variables, expressions, and the table of every instruction of the machine.', 'en/language/', md($en . $reference, ['../../langage/' => '../../langage/']), '../../', ['fr' => 'langage/', 'en' => 'en/language/', 'x-default' => 'langage/'], $navEn)); echo "site/langage/, site/editeur/, site/vm/, site/en/language/\n";