EN
games/alis / src / Alis / Compiled / Templates / Adds.php · commit 9c722cf
<?phpnamespace App\Alis\Compiled\Templates;use App\Alis\Compiled\Context;use App\Alis\Compiled\Templates;/** * The add targets (Grammar ADDS), from fn/addnames.php (base table: the compiler leaves version 6 to the VM). * Left to the VM: ahimb / ahimp / ahimtc / ahimti (their operands are not in the grammar), aeval (recursion on the * stream), ofin. */final class Adds{    public static function register(): void    {        $a = &Templates::$add;        $rd = '\App\Alis\xread8';        // pnul        $stop = static fn (array $e): string => 'Alis::$state = \App\Alis\C::eAlisStateStopped;';        $a[0x00] = $a[0x02] = $a[0x04] = $stop;        // alocb / alocw: local variable, flags        $a[0x06] = static fn (array $e): string => sprintf(            '\App\Alis\xadd8($s->vram_org + %1$d, Alis::$varD7 & 0xff); Alis::$sr[\'zero\'] = (int) (\App\Alis\xread8($s->vram_org + %1$d) == 0);', $e['a']);        $a[0x08] = static fn (array $e): string => sprintf(            '\App\Alis\xadd16($s->vram_org + %1$d, Alis::$varD7); Alis::$sr[\'zero\'] = (int) (\App\Alis\xread16($s->vram_org + %1$d) == 0);', $e['a']);        // alocp / adirp / amainp: string append        $a[0x0a] = static fn (array $e): string => sprintf(            '$d = $s->vram_org + %d; \App\Alis\mem_putstr($d, \App\Alis\mem_str($d) . \App\Alis\mem_str(Alis::$oldsd7));', $e['a']);        $a[0x16] = static fn (array $e): string => sprintf(            '$d = $s->vram_org + %d; \App\Alis\mem_putstr($d, \App\Alis\mem_str($d) . \App\Alis\mem_str(Alis::$oldsd7));', $e['a']);        $a[0x22] = static fn (array $e): string => sprintf(            '$d = Alis::$basemain + %d; \App\Alis\mem_putstr($d, \App\Alis\mem_str($d) . \App\Alis\mem_str(Alis::$oldsd7));', $e['a']);        // tab strings        $tp = static fn (string $base, int $off): string => sprintf(            '$d = \App\Alis\tabstring(%s + %d); \App\Alis\mem_putstr($d, \App\Alis\mem_str($d) . \App\Alis\mem_str(Alis::$oldsd7));', $base, $off);        $a[0x0c] = static fn (array $e): string => $tp('$s->vram_org', $e['a'] & 0xffff);        $a[0x18] = static fn (array $e): string => $tp('$s->vram_org', $e['a']);        $a[0x24] = static fn (array $e): string => $tp('Alis::$basemain', $e['a']);        // tab chars / ints: the value comes from the stack        $tc = static fn (string $fn, string $base, int $off, string $add): string => sprintf(            '$d = \App\Alis\%s(%s + %d); Alis::$varD7 = \App\Alis\hread32(Alis::$acc); Alis::$acc += 4; %s', $fn, $base, $off, $add);        $a[0x0e] = static fn (array $e): string => $tc('tabchar', '$s->vram_org', $e['a'] & 0xffff, '\App\Alis\xadd8($d, \App\Alis\s8(Alis::$varD7));');        $a[0x10] = static fn (array $e): string => $tc('tabint', '$s->vram_org', $e['a'] & 0xffff, '\App\Alis\xadd16($d, Alis::$varD7);');        $a[0x1a] = static fn (array $e): string => $tc('tabchar', '$s->vram_org', $e['a'], '\App\Alis\xadd8($d, \App\Alis\s8(Alis::$varD7));');        $a[0x1c] = static fn (array $e): string => $tc('tabint', '$s->vram_org', $e['a'], '\App\Alis\xadd16($d, Alis::$varD7);');        $a[0x26] = static fn (array $e): string => $tc('tabchar', 'Alis::$basemain', $e['a'] & 0xffff, '\App\Alis\xadd8($d, Alis::$varD7 & 0xff);');        $a[0x28] = static fn (array $e): string => $tc('tabint', 'Alis::$basemain', $e['a'] & 0xffff, '\App\Alis\xadd16($d, Alis::$varD7);');        // direct (one byte offset)        $a[0x12] = static fn (array $e): string => sprintf(            '\App\Alis\xadd8($s->vram_org + %1$d, Alis::$varD7 & 0xff); Alis::$sr[\'zero\'] = (int) (\App\Alis\xread8($s->vram_org + %1$d) == 0);', $e['a']);        $a[0x14] = static fn (array $e): string => sprintf(            '\App\Alis\xadd16($s->vram_org + %1$d, Alis::$varD7); Alis::$sr[\'zero\'] = (int) (\App\Alis\xread16($s->vram_org + %1$d) == 0);', $e['a']);        // main script        $a[0x1e] = static fn (array $e): string => sprintf('\App\Alis\xadd8(Alis::$basemain + %d, Alis::$varD7 & 0xff);', $e['a']);        $a[0x20] = static fn (array $e): string => sprintf('\App\Alis\xadd16(Alis::$basemain + %d, \App\Alis\s16(Alis::$varD7));', $e['a']);        // him: another entity's variables        $a[0x2c] = static fn (array $e): string => sprintf(            'if (Alis::$platform->kind == \App\Alis\C::EPlatformPC && Alis::$platform->version >= 30) {'            . ' $ent = \App\Alis\xread16($s->vram_org + %1$d); $vr = \App\Alis\xread32(Alis::$atent + $ent);'            . ' if ($vr > 0) { \App\Alis\xadd16($vr + %2$d, Alis::$varD7); }'            . ' } else {'            . ' $ent = \App\Alis\xread16($s->vram_org + %3$d); $d = \App\Alis\s32(\App\Alis\xread32(Alis::$atent + $ent) + %4$d);'            . ' \App\Alis\xadd16($d, Alis::$varD7); }',            $e['a'][0], $e['a'][1], $e['a'][0] & 0xffff, $e['a'][1] & 0xffff);        $a[0x30] = static fn (array $e): string => sprintf(            '$d = \App\Alis\xread32(Alis::$atent + \App\Alis\xread16($s->vram_org + %2$d)); $d = \App\Alis\tabstring($d + %1$d);'            . ' \App\Alis\mem_putstr($d, \App\Alis\mem_str($d) . \App\Alis\mem_str(Alis::$oldsd7));',            $e['a'][0], $e['a'][1]);        // aeval        $a[0x38] = static fn (array $e, Context $c): string => Stores::evalTarget($e, $c, true);        // spile        $a[0x36] = static fn (array $e): string => 'Alis::$acc -= 4; \App\Alis\hwrite32(Alis::$acc, Alis::$varD7);';        unset($rd);    }}