<?phpnamespace App\Alis\Compiled\Templates;use App\Alis\Alis;use App\Alis\Compiled\Context;use App\Alis\Compiled\Templates;use App\Alis\Lang\Decoder;/** * Rare instructions (fn/opcodes_b.php): cshrink, cchartmap, cvinput, cavmov, crunfilm, and the expression element * 0x7a (ogetkey). The ones that read the stream in their own way have a core function the VM's handler calls too * (cshrink_core(), cchartmap_fill(), cchartmap_sub()). */final class Ops13{ /** the store target after a swap of the string accumulators (cstore_continue()) */ private static function storeContinue(Context $c, array $target): string { return '[Alis::$sd7, Alis::$oldsd7] = [Alis::$oldsd7, Alis::$sd7];' . "\n" . $c->storename($target); } public static function register(): void { // ogetkey: io_getkey() yields the frame (vm_yield_retry) until a key comes: the instruction restarts Templates::$oper[0x7a] = static fn (array $e, Context $c): string => 'Alis::$varD7 = \App\Alis\io_getkey();'; Templates::$op['cshrink'] = static fn (array $i, Context $c): string => $c->opername($i['ops'][0][1]) . "\n" . $c->opernameSaveD6($i['ops'][1][1]) . "\n" . '\App\Alis\cshrink_core();'; Templates::$op['cvinput'] = static fn (array $i, Context $c): string => 'Alis::$charmode = 0;' . "\n" . '\App\Alis\getval();' . "\n" . self::storeContinue($c, $i['ops'][0][1]); // cavmov: no operand, the handler tests the version itself Templates::$op['cavmov'] = static fn (array $i, Context $c): string => '\App\Alis\cavmov();'; Templates::$op['crunfilm'] = static function (array $i, Context $c): string { [$e, $s1, $s2] = array_map(static fn ($o) => $o[1], $i['ops']); $out = [$c->opername($e), '\App\Alis\film_check_boot();']; if (Alis::$platform->uid == \App\Alis\C::EGameRobinsonsRequiem3DO) { return implode("\n", [...$out, '\App\Alis\film3do_run(Alis::$varD7);', 'Alis::$varD7 = 0;', self::storeContinue($c, $s1), 'Alis::$varD7 = 0;', self::storeContinue($c, $s2)]); } // runfilm() yields between the film frames and the instruction restarts: batchframes is set once return implode("\n", [...$out, 'if (!\App\Alis\film_run_resuming()) {', ' \App\Alis\FilmVars::$bfilm->batchframes = \App\Alis\s16(Alis::$varD7);', '}', '\App\Alis\runfilm();', 'Alis::$varD7 = \App\Alis\FilmVars::$bfilm->frame;', self::storeContinue($c, $s1), 'Alis::$varD7 = \App\Alis\FilmVars::$bfilm->result;', self::storeContinue($c, $s2)]); }; // cchartmap: v, the sub-command, then (0 / 1) the entity's address or (others) an expression. The sub-command // must be a constant (it decides what the compiler wrote after it); else the VM runs it. Templates::$op['cchartmap'] = static function (array $i, Context $c): ?string { [$v, $cmd, $third] = $i['ops']; $value = Decoder::constant($cmd[1]); if ($value === null) { return null; } $value = ($value & 0xffff) >= 0x8000 ? ($value & 0xffff) - 0x10000 : ($value & 0xffff); $out = [sprintf('$a = %s + %d;', $v[2] ? 'Alis::$basemain' : '$s->vram_org', $v[1]), $c->opername($cmd[1])]; if ($value == 0 || $value == 1) { $out[] = sprintf('\App\Alis\cchartmap_fill($a, %d);', $value == 0 ? 0 : -1); $out[] = sprintf('\App\Alis\xwrite32($a - 0x3ba, %s + %d);', $third[2] ? 'Alis::$basemain' : 'Alis::$script->vram_org', $third[1]); } else { $out[] = $c->opername($third[1]); $out[] = sprintf('\App\Alis\cchartmap_sub($a, %d);', $value); } return implode("\n", $out); }; }}