ES
games/alis / src / Alis / Compiled / Templates / Ops09.php · commit 9c722cf
<?phpnamespace App\Alis\Compiled\Templates;use App\Alis\Compiled\Context;use App\Alis\Compiled\Templates;/** * Instructions 0xca..0xde (fn/opcodes_b.php), version below 60 (the compiler leaves version 6 to the VM). * Left to the VM: cfindcla, cnearcla, cviewcla, cbackstar, cstarring, cengine and cautomode (their operands depend on * the platform at run time). */final class Ops09{    public static function register(): void    {        $n = '\App\Alis\\';        $op = &Templates::$op;        $op['cordspr'] = static fn (array $i, Context $c): string => $c->opername($i['ops'][0][1]) . "\n"            . $n . 'set_0x2b_cordspr($s->vram_org, Alis::$varD7 & 0xff);';        $op['calign'] = static fn (array $i, Context $c): string => $c->opername($i['ops'][0][1]) . "\n"            . '$v = Alis::$varD7 & 0xff;' . "\n"            . '$bit = ($v & 0x10) ? 4 : (($v & 0x8) ? 3 : (($v & 0x4) ? 2 : (($v & 0x2) ? 1 : 0)));' . "\n"            . $n . 'set_0x2c_calign($s->vram_org, $bit);' . "\n"            . $c->opername($i['ops'][1][1]) . "\n"            . $n . 'set_0x2d_calign($s->vram_org, Alis::$varD7);';        $op['cquality'] = static fn (array $i, Context $c): string => $c->opername($i['ops'][0][1]) . "\n"            . 'Alis::$vquality = Alis::$varD7 & 0xffff;';        foreach (['cinstru' => 0, 'cminstru' => 1] as $name => $flag) {            $op[$name] = static function (array $i, Context $c) use ($n, $flag): string {                return 'Alis::$flagmain = ' . $flag . ';' . "\n"                    . $c->opername($i['ops'][0][1]) . "\n" . '$tabidx = ' . $n . 's16(Alis::$varD7);' . "\n"                    . $c->opername($i['ops'][1][1]) . "\n" . '$scridx = ' . $n . 's16(Alis::$varD7);' . "\n"                    . $c->opername($i['ops'][2][1]) . "\n" . '$instidx = ' . $n . 's16(Alis::$varD7);' . "\n"                    . 'if ($scridx < 0) {' . "\n" . '$instidx = 0;' . "\n" . '$addr = 0;' . "\n" . '} else {' . "\n"                    . '$addr = ' . $n . 'adresmus($scridx);' . "\n" . '$type = ' . $n . 'xread8($addr);' . "\n"                    . 'if ($type == 1 || $type == 2 || $type == 5 || $type == 6) {' . "\n"                    . '$addr += 0x10;' . "\n"                    . '\App\Alis\Aud::$tabinst[$tabidx]->address = $addr;' . "\n"                    . '\App\Alis\Aud::$tabinst[$tabidx]->unknown = $instidx;' . "\n"                    . '}' . "\n" . '}' . "\n"                    . 'if ($scridx < 0) {' . "\n"                    . '\App\Alis\Aud::$tabinst[$tabidx]->address = $addr;' . "\n"                    . '\App\Alis\Aud::$tabinst[$tabidx]->unknown = $instidx;' . "\n" . '}';            };        }        $op['chsprite'] = static function (array $i, Context $c) use ($n): string {            // the VM reads 1 + 3 operands whichever the value (the rest of its code has no effect)            return $c->opername($i['ops'][0][1]) . "\n"                . $n . 'set_0x2f_chsprite($s->vram_org, ' . $n . 's8(Alis::$varD7));' . "\n"                . $c->opername($i['ops'][1][1]) . "\n" . $c->opername($i['ops'][2][1]) . "\n" . $c->opername($i['ops'][3][1]);        };        $op['cselpalet'] = static fn (array $i, Context $c): string => $c->opername($i['ops'][0][1]) . "\n"            . 'if (' . $n . 'dos_pal_active()) {' . "\n" . $n . 'dos_cselpalet(Alis::$varD7);' . "\n" . '} else {' . "\n"            . 'Alis::$varD7 &= 0x3;' . "\n" . '\App\Alis\Img::$thepalet = Alis::$varD7;' . "\n" . '\App\Alis\Img::$defpalet = 1;' . "\n" . '}';        $op['clinepalet'] = static fn (array $i, Context $c): string => $c->opername($i['ops'][0][1]) . "\n"            . $c->opernameSaveD6($i['ops'][1][1]) . "\n"            . 'if (Alis::$platform->bpp < 8 && !' . $n . 'dos_pal_active() && !(Alis::$platform->uid == \App\Alis\Opcodes2Const::EGameMetalMutant && Alis::$platform->kind == \App\Alis\C::EPlatformPC)) {' . "\n"            . $n . 'setlinepalet();' . "\n" . '}';        $op['cautobase'] = static fn (array $i, Context $c): string => ';';        $op['ccancel'] = static fn (array $i, Context $c): string => ';';        $op['cautofile'] = static fn (array $i, Context $c): string => $c->opernameSwap($i['ops'][0][1]) . "\n"            . 'if (Alis::$platform->version >= 30) {' . "\n"            . '$t = ' . $n . 'mem_read(Alis::$sd7, 0xc);' . "\n" . '$z = strpos($t, "\0");' . "\n"            . 'Alis::$autoname = $z === false ? $t : substr($t, 0, $z);' . "\n" . '}';        $op['ccancall'] = static fn (array $i, Context $c): string => 'Alis::$ferase = 1;' . "\n"            . '$tmpidx = 0;' . "\n" . '$curidx = ' . $n . 'get_0x18_unknown($s->vram_org);' . "\n"            . 'while ($curidx) {' . "\n" . $n . 'killelem($curidx, $tmpidx);' . "\n" . '}' . "\n" . 'Alis::$ferase = 0;';        $op['ccancen'] = static fn (array $i, Context $c): string => 'Alis::$ferase = 1;' . "\n"            . $c->opernameSaveD7($i['ops'][0][1]) . "\n"            . '\App\Alis\Img::$numelem = ' . $n . 's8(Alis::$varD7);' . "\n"            . '$curidx = 0;' . "\n" . '$previdx = 0;' . "\n"            . 'while (' . $n . 'searchelem($curidx, $previdx)) {' . "\n" . $n . 'killelem($curidx, $previdx);' . "\n" . '}' . "\n"            . 'Alis::$ferase = 0;';        $op['cblast'] = static fn (array $i, Context $c): string => 'Alis::$ferase = 1;' . "\n"            . $c->opernameSaveD7($i['ops'][0][1]) . "\n"            . 'if (Alis::$platform->version >= 30 ? ' . $n . 's16(Alis::$varD7) > 0 : Alis::$varD7 >= 0) {' . "\n"            . $n . 'killent(Alis::$varD7 & 0xffff);' . "\n" . '}';    }}