EN
games/alis / src / Alis / Compiled / Templates / Ops03.php · commit 9c722cf
<?phpnamespace App\Alis\Compiled\Templates;use App\Alis\Compiled\Context;use App\Alis\Compiled\Templates;/** * Opcodes 0x4c..0x60 (fn/opcodes_a.php): cset, cmov, copensc, cclosesc, cerasall, cforme, cdelforme, csuccent, cpredent, * crstent. The near / view / tst families stay with the VM (their helpers read the stream after the instruction). * Version 6 scripts are left to the VM by the compiler. */final class Ops03{    public static function register(): void    {        $wc = static function (Context $c, array $i, string $fn32): string {            $k = '\App\Alis\OpcodesConst::';            $out = '';            foreach (['\App\Alis\C::ALIS_SCR_WCX', $k . 'ALIS_SCR_WCY()', $k . 'ALIS_SCR_WCZ()'] as $n => $off) {                $out .= $c->opername($i['ops'][$n][1]) . "\n"                    . sprintf('\App\Alis\%s16($s->vram_org + %s, Alis::$varD7);', $fn32, $off) . "\n";            }            return $out;        };        Templates::$op['cset'] = static fn (array $i, Context $c): string => $wc($c, $i, 'xwrite');        Templates::$op['cmov'] = static fn (array $i, Context $c): string => $wc($c, $i, 'xadd');        Templates::$op['copensc'] = static function (array $i): string {            $id = $i['ops'][0][1] & 0xffff;            return sprintf('$t = %d;', $id) . "\n"                . 'Alis::$mem[Alis::$basemain + $t] = chr((ord(Alis::$mem[Alis::$basemain + $t]) & 0xbf) | 0x80);' . "\n"                . '\App\Alis\scbreak($t);' . "\n"                . '\App\Alis\scadd($t);' . "\n"                . 'if (Alis::$platform->version >= 31 && (\App\Alis\xread8(Alis::$basemain + 1 + $t) & 2) != 0) { \App\Alis\openland($t); }';        };        Templates::$op['cclosesc'] = static function (array $i): string {            $id = $i['ops'][0][1] & 0xffff;            return sprintf('$t = %d;', $id) . "\n"                . 'Alis::$mem[Alis::$basemain + $t] = chr(ord(Alis::$mem[Alis::$basemain + $t]) | 0x40);';        };        Templates::$op['cerasall'] = static fn (array $i): string =>            '$t = 0; $cur = \App\Alis\get_0x18_unknown($s->vram_org);' . "\n"            . 'while ($cur) { \App\Alis\killelem($cur, $t); }' . "\n"            . 'Alis::$ferase = 0;';        Templates::$op['cforme'] = static fn (array $i, Context $c): string => $c->opername($i['ops'][0][1]) . "\n"            . '\App\Alis\set_0x1a_cforme($s->vram_org, Alis::$varD7);';        Templates::$op['cdelforme'] = static fn (array $i): string => '\App\Alis\set_0x1a_cforme($s->vram_org, -1);';        $tail = static fn (Context $c, array $i, int $n): string =>            '[Alis::$sd7, Alis::$oldsd7] = [Alis::$oldsd7, Alis::$sd7];' . "\n" . $c->storename($i['ops'][$n][1]);        Templates::$op['csuccent'] = static fn (array $i, Context $c): string =>            'Alis::$varD7 = Alis::$tablent[Alis::$ptrent];' . "\n"            . 'if (-1 < Alis::$tablent[Alis::$ptrent]) { Alis::$ptrent++; }' . "\n" . $tail($c, $i, 0);        Templates::$op['crstent'] = static fn (array $i, Context $c): string =>            'Alis::$ptrent = 0;' . "\n"            . 'Alis::$varD7 = Alis::$tablent[Alis::$ptrent];' . "\n"            . 'if (-1 < Alis::$tablent[Alis::$ptrent]) { Alis::$ptrent++; }' . "\n" . $tail($c, $i, 0);        Templates::$op['cpredent'] = static fn (array $i, Context $c): string =>            'if (Alis::$ptrent != 0) { Alis::$ptrent--; Alis::$varD7 = Alis::$tablent[Alis::$ptrent]; } else { Alis::$varD7 = -1; }' . "\n"            . $tail($c, $i, 0);    }}