FR
games/alis / tools / site / docs.php · commit 9c722cf
<?php// The game's site gets the documentation of the ALIS language and editor (docs/language.md, docs/editor.md) as// pages: site/langage/ and site/editeur/ (French, the documents' language), site/en/language/ (English: an// overview and the same reference tables). Re-run it when a document changes://   bin/jumphp php games/alis tools/site/docs.php$root = dirname(__DIR__, 2);/** A small Markdown: headings, paragraphs, lists, tables, code blocks, `code`, **bold**, *em*, [links](...). */function md(string $text, array $links = []): string{    $out = '';    $lines = explode("\n", str_replace("\r", '', $text));    $n = count($lines);    $inline = static function (string $s) use ($links): string {        $codes = [];        $s = preg_replace_callback('/`([^`]+)`/', static function ($m) use (&$codes) {            $codes[] = '<code>' . htmlspecialchars($m[1]) . '</code>';            return "\x01" . (count($codes) - 1) . "\x02";        }, $s);        $s = htmlspecialchars($s, ENT_NOQUOTES);        $s = preg_replace('/\*\*(.+?)\*\*/', '<strong>$1</strong>', $s);        $s = preg_replace('/(?<![\w*])\*([^*\s][^*]*?)\*(?![\w*])/', '<em>$1</em>', $s);        $s = preg_replace_callback('/\[([^\]]+)\]\(([^)]+)\)/', static fn ($m) => '<a href="' . htmlspecialchars($links[$m[2]] ?? $m[2]) . '">' . $m[1] . '</a>', $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 .= '<pre><code>' . htmlspecialchars(implode("\n", $code)) . "</code></pre>\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 .= "<h$level id=\"$id\">" . $inline($m[2]) . "</h$level>\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 .= "<div class=\"table\"><table>\n<thead><tr>";            foreach ($cells($rows[0]) as $c) {                $out .= '<th>' . str_replace("\x03", '|', $inline($c)) . '</th>';            }            $out .= "</tr></thead>\n<tbody>\n";            foreach (array_slice($rows, 2) as $r) {                $out .= '<tr>';                foreach ($cells($r) as $c) {                    $out .= '<td>' . str_replace("\x03", '|', $inline($c)) . '</td>';                }                $out .= "</tr>\n";            }            $out .= "</tbody></table></div>\n";            continue;        }        if (preg_match('/^\s*[-*]\s+/', $line)) {            $out .= "<ul>\n";            while ($i < $n && preg_match('/^\s*[-*]\s+(.*)$/', $lines[$i], $m)) {                $item = $m[1];                for ($i++; $i < $n && preg_match('/^\s{2,}\S/', $lines[$i]) && !preg_match('/^\s*[-*]\s+/', $lines[$i]); $i++) {                    $item .= ' ' . trim($lines[$i]);                }                $out .= '<li>' . $inline($item) . "</li>\n";            }            $out .= "</ul>\n";            continue;        }        $para = [];        for (; $i < $n && trim($lines[$i]) !== '' && !preg_match('/^(#|\||```|\s*[-*]\s)/', $lines[$i]); $i++) {            $para[] = trim($lines[$i]);        }        $out .= '<p>' . $inline(implode(' ', $para)) . "</p>\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 .= "<link rel=\"alternate\" hreflang=\"$l\" href=\"https://{{DOMAIN}}/$p\">\n";    }    $t = htmlspecialchars($title);    $d = htmlspecialchars($description);    $locale = $lang === 'fr' ? 'fr_FR' : 'en_US';    $play = $lang === 'fr' ? '▶ Jouer' : '▶ Play';    return <<<HTML        <!doctype html>        <html lang="$lang">        <head>        <meta charset="utf-8">        <meta name="viewport" content="width=device-width, initial-scale=1">        <title>$t</title>        <meta name="description" content="$d">        <link rel="canonical" href="https://{{DOMAIN}}/$path">        $alt<link rel="icon" href="{$up}images/favicon.png">        <meta property="og:type" content="article">        <meta property="og:title" content="$t">        <meta property="og:description" content="$d">        <meta property="og:image" content="https://{{DOMAIN}}/images/og.png">        <meta property="og:url" content="https://{{DOMAIN}}/$path">        <meta property="og:locale" content="$locale">        <meta name="twitter:card" content="summary_large_image">        <style>        :root{--bg:#120f0a;--panel:#2a2216;--gold:#d8b25a;--text:#efe6d2;--muted:#b9a985}        *{box-sizing:border-box}body{margin:0;background:var(--bg);color:var(--text);font:17px/1.6 Georgia,serif}        .wrap{max-width:980px;margin:0 auto;padding:0 16px}        nav{display:flex;flex-wrap:wrap;justify-content:flex-end;gap:12px;padding:10px 0;font-size:14px}nav a{color:var(--muted)}        h1{font-size:clamp(26px,5vw,40px);color:var(--gold);margin:.4em 0}        h2{color:var(--gold);border-bottom:1px solid #4a3c22;padding-bottom:.2em;margin-top:2em}        h3{color:var(--gold)}        a{color:var(--gold)}        p,li,td{overflow-wrap:anywhere}td code,td:last-child{white-space:nowrap;overflow-wrap:normal}        code{font:14px/1.4 ui-monospace,Menlo,Consolas,monospace;background:var(--panel);padding:0 4px;border-radius:3px;overflow-wrap:anywhere}        pre{background:#1c1710;border:1px solid #4a3c22;border-radius:4px;padding:12px;overflow-x:auto}        pre code{background:none;padding:0}        .table{overflow-x:auto}table{border-collapse:collapse;font-size:15px;margin:10px 0}        th,td{border:1px solid #4a3c22;padding:4px 8px;text-align:left;vertical-align:top}th{background:var(--panel)}        .play{display:inline-block;margin:18px 0;padding:10px 26px;background:var(--gold);color:#1a1307;font-weight:bold;border-radius:6px;text-decoration:none}        footer{color:var(--muted);font-size:14px;padding:30px 0;text-align:center}        img{max-width:100%;height:auto;border:2px solid #4a3c22;border-radius:4px}        </style>        </head>        <body>        <div class="wrap">        <nav>$nav</nav>        $body        <p><a class="play" href="{$up}play/">$play</a></p>        </div>        <footer>ALIS en PHP — <a href="https://jumphp.net">JumPHP</a></footer>        </body>        </html>        HTML;}$links = ['language.md' => '../langage/', 'editor.md' => '../editeur/', 'vm.md' => '../vm/'];$navFr = '<a href="../">Accueil</a><a href="../langage/">Le langage ALIS</a><a href="../editeur/">L\'éditeur</a><a href="../vm/">La machine (doc technique)</a><a href="../en/language/">English</a>';$navEn = '<a href="../">Home</a><a href="../language/">The ALIS language</a><a href="../../langage/">Français</a>';$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) . '<p><img src="../images/editor.png" alt="L\'éditeur ALIS ouvert sur le script flags de Robinson\'s Requiem, une erreur de compilation surlignée" width="640" height="480" loading="lazy"></p>',    '../', ['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 languageSilmarils' 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 3Dmodels). This port of the machine to PHP comes with a **decompiler and a compiler**: every script becomes a textin 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 instructionsand expression items are the machine's own (`cput`, `cscmov`, `oimmb`, `oadd`…), and the structures follow thehabits of the original compiler, read from the byte code (one pass, left-to-right expressions, the same code forevery `if … else` and `while`). The 109 scripts of Robinson's Requiem (46,886 lines) compile back **byte forbyte**, 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: `<GAME> - 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: everyinstruction 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";