<?phpnamespace App\Alis;// Port of alis/src/addnames.c (MIT, Olivier Huguenot, Vadim Kindl).// ============================================================================// Add routines// ============================================================================// Addname no. 01 opcode 0x00 pnul// Addname no. 02 opcode 0x02 pnul// Addname no. 03 opcode 0x04 pnul// Calls stub pnul// Addname no. 04 opcode 0x06 alocbfunction alocb(): void{ $offset = s16(script_read16()); xadd8(Alis::$script->vram_org + $offset, Alis::$varD7 & 0xff); Alis::$sr['zero'] = (int) (xread8(Alis::$script->vram_org + $offset) == 0);}// Addname no. 05 opcode 0x08 alocwfunction alocw(): void{ $offset = s16(script_read16()); xadd16(Alis::$script->vram_org + $offset, Alis::$varD7); Alis::$sr['zero'] = (int) (xread16(Alis::$script->vram_org + $offset) == 0);}// Addname no. 06 opcode 0x0a alocpfunction alocp(): void{ $offset = s16(script_read16()); $dst = get_vram($offset); mem_putstr($dst, mem_str($dst) . mem_str(Alis::$oldsd7));}// Addname no. 07 opcode 0x0c aloctpfunction aloctp(): void{ $addr = tabstring(Alis::$script->vram_org + script_read16()); mem_putstr($addr, mem_str($addr) . mem_str(Alis::$oldsd7));}// Addname no. 08 opcode 0x0e aloctcfunction aloctc(): void{ $addr = tabchar(Alis::$script->vram_org + script_read16()); Alis::$varD7 = hread32(Alis::$acc); Alis::$acc += 4; xadd8($addr, s8(Alis::$varD7));}// Addname no. 09 opcode 0x10 aloctifunction alocti(): void{ $addr = tabint(Alis::$script->vram_org + script_read16()); Alis::$varD7 = hread32(Alis::$acc); Alis::$acc += 4; xadd16($addr, Alis::$varD7);}// Addname no. 10 opcode 0x12 adirbfunction adirb(): void{ $offset = script_read8(); xadd8(Alis::$script->vram_org + $offset, Alis::$varD7 & 0xff); Alis::$sr['zero'] = (int) (xread8(Alis::$script->vram_org + $offset) == 0);}// Addname no. 11 opcode 0x14 adirwfunction adirw(): void{ $offset = script_read8(); xadd16(Alis::$script->vram_org + $offset, Alis::$varD7); Alis::$sr['zero'] = (int) (xread16(Alis::$script->vram_org + $offset) == 0);}// adirl was between adirw and adirp. Robinson's Requiem/Ishar 3 have a stub// Addname no. 12 opcode 0x16 adirpfunction adirp(): void{ $offset = script_read8(); $dst = get_vram($offset); mem_putstr($dst, mem_str($dst) . mem_str(Alis::$oldsd7));}// Addname no. 13 opcode 0x18 adirtpfunction adirtp(): void{ $addr = tabstring(Alis::$script->vram_org + script_read8()); mem_putstr($addr, mem_str($addr) . mem_str(Alis::$oldsd7));}// Addname no. 14 opcode 0x1a adirtcfunction adirtc(): void{ $addr = tabchar(Alis::$script->vram_org + script_read8()); Alis::$varD7 = hread32(Alis::$acc); Alis::$acc += 4; xadd8($addr, s8(Alis::$varD7));}// Addname no. 15 opcode 0x1c adirtifunction adirti(): void{ $addr = tabint(Alis::$script->vram_org + script_read8()); Alis::$varD7 = hread32(Alis::$acc); Alis::$acc += 4; xadd16($addr, Alis::$varD7);}// Addname no. 16 opcode 0x1e amainbfunction amainb(): void{ $offset = s16(script_read16()); xadd8(Alis::$basemain + $offset, Alis::$varD7 & 0xff);}// Addname no. 17 opcode 0x20 amainwfunction amainw(): void{ $offset = s16(script_read16()); xadd16(Alis::$basemain + $offset, s16(Alis::$varD7));}// Addname no. 18 opcode 0x22 amainpfunction amainp(): void{ $offset = s16(script_read16()); $dst = Alis::$basemain + $offset; mem_putstr($dst, mem_str($dst) . mem_str(Alis::$oldsd7));}// Addname no. 19 opcode 0x24 amaintpfunction amaintp(): void{ $addr = tabstring(Alis::$basemain + s16(script_read16())); mem_putstr($addr, mem_str($addr) . mem_str(Alis::$oldsd7));}// Addname no. 20 opcode 0x26 amaintcfunction amaintc(): void{ $addr = tabchar(Alis::$basemain + script_read16()); Alis::$varD7 = hread32(Alis::$acc); Alis::$acc += 4; xadd8($addr, Alis::$varD7 & 0xff);}// Addname no. 21 opcode 0x28 amaintifunction amainti(): void{ $addr = tabint(Alis::$basemain + script_read16()); Alis::$varD7 = hread32(Alis::$acc); Alis::$acc += 4; xadd16($addr, Alis::$varD7);}// Addname no. 22 opcode 0x2a ahimbfunction ahimb(): void{ if (Alis::$platform->version == 10) { $offset = xread16(Alis::$script->vram_org + script_read16()); $addr = s32(xread32(Alis::$atent + $offset) + script_read16()); xwrite8($addr, xread8($addr) + (Alis::$varD7 & 0xff)); return; } // MISSING in the C}// Addname no. 23 opcode 0x2c ahimwfunction ahimw(): void{ if (Alis::$platform->kind == C::EPlatformPC && Alis::$platform->version >= 30) { // The v3 DOS VM (0xabad): both offsets are signed, and nothing is added // to a dead or not started entity (vram <= 0); the second offset is always read. $ent = xread16(Alis::$script->vram_org + s16(script_read16())); $vram = xread32(Alis::$atent + $ent); $offset2 = s16(script_read16()); if ($vram > 0) { xadd16($vram + $offset2, Alis::$varD7); } return; } $offset = xread16(Alis::$script->vram_org + script_read16()); $offset2 = s32(xread32(Alis::$atent + $offset) + script_read16()); xadd16($offset2, Alis::$varD7);}// Addname no. 24 opcode 0x2e ahimpfunction ahimp(): void{ // MISSING in the C}// Addname no. 25 opcode 0x30 ahimtpfunction ahimtp(): void{ $offset1 = s16(script_read16()); $offset2 = s16(script_read16()); $addr = xread32(Alis::$atent + xread16(Alis::$script->vram_org + $offset2)); $addr = tabstring($addr + $offset1); mem_putstr($addr, mem_str($addr) . mem_str(Alis::$oldsd7));}// Addname no. 26 opcode 0x32 ahimtcfunction ahimtc(): void{ // MISSING in the C}// Addname no. 27 opcode 0x34 ahimtifunction ahimti(): void{ // MISSING in the C}// Addname no. 28 opcode 0x36 spile// Calls store->spile// Addname no. 29 opcode 0x38 aevalfunction aeval(): void{ if (Alis::$platform->version >= 60) { Alis::$acc = Alis::$acc_org; } Alis::$acc -= 4; hwrite32(Alis::$acc, Alis::$varD7); oeval(); readexec_addname();}// Addname no. 30 opcode 0x3a ofin// Storename no. 30 opcode 0x3a ofin// Calls oper->ofin// ============================================================================// Add routines pointer table, indexed by the opcode byte (odd slots are NULL in the C)// ============================================================================function table_addnames(): array{ $t = [ pnul(...), null, pnul(...), null, pnul(...), null, alocb(...), null, alocw(...), null, alocp(...), null, aloctp(...), null, aloctc(...), null, alocti(...), null, adirb(...), null, adirw(...), null, adirp(...), null, adirtp(...), null, adirtc(...), null, adirti(...), null, amainb(...), null, amainw(...), null, amainp(...), null, amaintp(...), null, amaintc(...), null, amainti(...), null, ahimb(...), null, ahimw(...), null, ahimp(...), null, ahimtp(...), null, ahimtc(...), null, ahimti(...), null, spile(...), null, aeval(...), null, ofin(...), null, ]; $names = [ 'pnul', 'pnul', 'pnul', 'alocb', 'alocw', 'alocp', 'aloctp', 'aloctc', 'alocti', 'adirb', 'adirw', 'adirp', 'adirtp', 'adirtc', 'adirti', 'amainb', 'amainw', 'amainp', 'amaintp', 'amaintc', 'amainti', 'ahimb', 'ahimw', 'ahimp', 'ahimtp', 'ahimtc', 'ahimti', 'spile', 'aeval', 'ofin', ]; $n = []; foreach ($names as $i => $name) { $n[$i * 2] = $name; $n[$i * 2 + 1] = ''; } Tables::$names['addnames'] = $n; return $t;}// v6 selects its own table: the base one with the addnames_v6_ov entries (addnames_v6.php) applied.// PORT: the C caches the first result in a static; cached per v6-ness here (game switch in one process).function alis_tab_addnames(): array{ static $live = []; $v6 = Alis::$platform->version >= 60 ? 1 : 0; if (!isset($live[$v6])) { $t = table_addnames(); if ($v6) { foreach (table_addnames_v6_ov() as $code => [$f, $name]) { $t[$code & 0xff] = $f; Tables::$names['addnames'][$code & 0xff] = $name; } } $live[$v6] = $t; } return $live[$v6];}