FR
games/alis / src / Alis / Compiled / Templates / Ops01.php · commit 9c722cf
<?phpnamespace App\Alis\Compiled\Templates;use App\Alis\Compiled\Context;use App\Alis\Compiled\Templates;/** * Opcodes 0x22-0x36 (fn/opcodes_a.php, opcodes_b.php): printing, cursor, random, loop, start, leave, protect, sleep, * clock. Left to the VM: cmul / cdiv (empty in the VM, no operand: trivial anyway), cdim, cswitch1 / cswitch2 * (specials of the decoder). */final class Ops01{    public static function register(): void    {        $o = &Templates::$op;        $e = static fn (array $i, int $n): array => $i['ops'][$n][1];        $o['cvprint'] = static fn (array $i, Context $c): string => 'Alis::$charmode = 0;' . "\n"            . $c->opernameSaveD7($e($i, 0)) . "\n" . '\App\Alis\putval(\App\Alis\s16(Alis::$varD7));';        $o['csprinti'] = static function (array $i, Context $c): string {            $s = 'Alis::$charmode = 0;';            foreach (str_split($i['ops'][0][1]) as $ch) {                $s .= ' \App\Alis\put_char(' . ord($ch) . ');';            }            return $s;        };        $o['csprinta'] = static fn (array $i, Context $c): string => 'if (Alis::$platform->version != 10) {' . "\n"            . 'Alis::$charmode = 0;' . "\n" . $c->opernameSaveD7($e($i, 0)) . "\n" . '\App\Alis\put_string();' . "\n" . '}';        $o['clocate'] = static fn (array $i, Context $c): string => 'Alis::$charmode = 0;' . "\n"            . $c->opernameSaveD7($e($i, 0)) . "\n" . $c->opernameSaveD6($e($i, 1)) . "\n"            . 'Alis::$xlocate = Alis::$varD7 & 0xff; Alis::$ylocate = Alis::$varD6 & 0xff;';        $o['ctab'] = static fn (array $i, Context $c): string => 'Alis::$charmode = 0;' . "\n"            . $c->opernameSaveD7($e($i, 0)) . "\n" . 'Alis::$xlocate = Alis::$varD7 & 0xff;';        $o['crandom'] = static fn (array $i, Context $c): string => 'if (\App\Alis\is_rrq_dos_v3()) {' . "\n"            . $c->opernameSaveD7($e($i, 0)) . "\n" . 'Alis::$random_number = Alis::$varD7 & 0xffff;' . "\n"            . '} else {' . "\n" . $c->opername($e($i, 0)) . "\n"            . 'Alis::$random_number = Alis::$varD7 & 0xffff;' . "\n"            . 'if (Alis::$random_number == 0) { Alis::$random_number = \App\Alis\sys_random() & 0xffff; }' . "\n" . '}';        // loop: the jump operand is read first, then the add target (its value of the zero flag decides)        foreach ([8, 16, 24] as $bits) {            $o["cloop$bits"] = static function (array $i, Context $c): string {                $t = $i['ops'][0][2];                return 'Alis::$varD7 = -1;' . "\n" . $c->addnameSwap($i['ops'][1][1]) . "\n"                    . 'if (!(Alis::$sr[\'zero\'] ?? 0)) { ' . Context::go($t) . ' }';            };        }        // start: cstart() reads nothing from the stream, only $s->pc (already after the operand)        foreach ([8, 16, 24] as $bits) {            $o["cstart$bits"] = static fn (array $i, Context $c): string => sprintf(                '\App\Alis\cstart(%d);', $i['ops'][0][2] - $i['end']);        }        $o['cleave'] = static fn (array $i, Context $c): string => '\App\Alis\cleave();';        $o['cprotect'] = static fn (array $i, Context $c): string => $c->opername($e($i, 0)) . "\n"            . 'Alis::$vprotect = \App\Alis\s8(Alis::$varD7);';        $o['casleep'] = static fn (array $i, Context $c): string => $c->opername($e($i, 0)) . "\n"            . 'if (-1 < Alis::$varD7) { $v = \App\Alis\xread32(Alis::$atent + Alis::$varD7); if ($v) { \App\Alis\set_0x04_cstart_csleep($v, 0); } }';        $o['cclock'] = static fn (array $i, Context $c): string => $c->opername($e($i, 0)) . "\n"            . '\App\Alis\set_0x3a_wait_cycles($s->vram_org, Alis::$varD7);' . "\n"            . '\App\Alis\set_0x3e_wait_time($s->vram_org, \App\Alis\s32(Alis::$varD7 + Alis::$timeclock));';    }}