<?phpnamespace App\Alis;// Port of alis/src/opernames.c (MIT, Olivier Huguenot, Vadim Kindl).// alis.sd6 / alis.sd7 are int addresses of C strings in Alis::$mem; alis.acc is a host-endian s32 stack.// ============================================================================// Additions// ============================================================================function pop_sd6(): void{ $src = Alis::$acc; mem_strcpy(Alis::$sd6, $src); $len = mem_strlen($src) + 1; if (Alis::$platform->version >= 60) { $src += $len; Alis::$acc = $src; return; } if ($len % 2 == 1) { $src++; } $src += $len; Alis::$acc = $src;}function pop_sd7(): void{ $src = Alis::$acc; mem_strcpy(Alis::$sd7, $src); $len = mem_strlen($src) + 1; if (Alis::$platform->version >= 60) { $src += $len; Alis::$acc = $src; return; } if ($len % 2 == 1) { $src++; } $src += $len; Alis::$acc = $src;}function push_sd6(): void{ $tgt = Alis::$acc; $len = mem_strlen(Alis::$sd6) + 1; if (Alis::$platform->version >= 60) { $tgt -= $len; mem_strcpy($tgt, Alis::$sd6); Alis::$acc = $tgt; return; } if ($len % 2 == 1) { Alis::$mem[--$tgt] = "\0"; } $tgt -= $len; mem_strcpy($tgt, Alis::$sd6); Alis::$acc = $tgt;}function push_sd7(): void{ $tgt = Alis::$acc; $len = mem_strlen(Alis::$sd7) + 1; if (Alis::$platform->version >= 60) { $tgt -= $len; mem_strcpy($tgt, Alis::$sd7); Alis::$acc = $tgt; return; } if ($len % 2 == 1) { Alis::$mem[--$tgt] = "\0"; } $tgt -= $len; mem_strcpy($tgt, Alis::$sd7); Alis::$acc = $tgt;}// =============================================================================// Oper (Operation) routines// =============================================================================// Opername no. 01 opcode 0x00 oimmbfunction oimmb(): void{ // reads a byte, extends into r7 Alis::$varD7 = s8(script_read8());}// Opername no. 02 opcode 0x02 oimmwfunction oimmw(): void{ // reads a word into r7 Alis::$varD7 = s16(script_read16());}// Opername opcode 0x3c oimmlfunction oimml(): void{ // reads a long into r7 Alis::$varD7 = script_read32();}// Opername no. 03 opcode 0x04 oimmpfunction oimmp(): void{ if (Alis::$platform->version == 10) { script_read16(); Alis::$varD7 = script_read16(); return; } // reads null-terminated data into bssChunk3 script_read_until_zero(Alis::$sd7);}// Opername no. 04 opcode 0x06 olocbfunction olocb(): void{ // read word offset, copy extended byte from ram[offset] into r7 $offset = s16(script_read16()); Alis::$varD7 = s8(xread8(Alis::$script->vram_org + $offset));}// Opername no. 05 opcode 0x08 olocwfunction olocw(): void{ // read word offset, copy word from ram[offset] into r7 $offset = s16(script_read16()); Alis::$varD7 = xread16(Alis::$script->vram_org + $offset);}// Opername no. 06 opcode 0x0a olocpfunction olocp(): void{ $offset = s16(script_read16()); if (Alis::$platform->version == 10) { Alis::$varD7 = xread16(Alis::$script->vram_org + $offset + 2); return; } mem_strcpy(Alis::$sd7, get_vram($offset));}// Opername no. 07 opcode 0x0c oloctpfunction oloctp(): void{ if (Alis::$platform->version == 10) { return; } $addr = tabstring(Alis::$script->vram_org + script_read16()); mem_strcpy(Alis::$sd7, $addr);}// Opername opcode 0x3e oloctofunction olocto(): void{ $cell = tabstring(Alis::$script->vram_org + script_read16()); Alis::$varD7 = $cell; Alis::$v6tabcell = $cell;}// Opername opcode 0xaa ogettext: see opernames_v6.php// Opername no. 08 opcode 0x0e oloctcfunction oloctc(): void{ $addr = tabchar(Alis::$script->vram_org + script_read16()); Alis::$varD7 = s8(xread8($addr));}// Opername no. 09 opcode 0x10 oloctifunction olocti(): void{ $addr = tabint(Alis::$script->vram_org + script_read16()); Alis::$varD7 = xread16($addr);}// Opername no. 10 opcode 0x12 odirb// reads a byte offset from script,// then reads an extended byte from vram[offset] into r7function odirb(): void{ $offset = script_read8(); Alis::$varD7 = s8(xread8(Alis::$script->vram_org + $offset));}// Opername no. 11 opcode 0x14 odirw// reads a byte offset from script,// then reads a word from vram[offset] into r7function odirw(): void{ $offset = script_read8(); Alis::$varD7 = xread16(Alis::$script->vram_org + $offset);}// Opername no. 12 opcode 0x16 odirp// reads a byte offset from script,// then reads a null-terminated data stream from vram[offset] into bssChunk3function odirp(): void{ $offset = script_read8(); if (Alis::$platform->version == 10) { Alis::$varD7 = xread16(Alis::$script->vram_org + $offset + 2); return; } mem_strcpy(Alis::$sd7, get_vram($offset));}// Opername no. 13 opcode 0x18 odirtpfunction odirtp(): void{ if (Alis::$platform->version == 10) { return; } $addr = tabstring(Alis::$script->vram_org + script_read8()); mem_strcpy(Alis::$sd7, $addr);}// Opername no. 14 opcode 0x1a odirtcfunction odirtc(): void{ $addr = tabchar(Alis::$script->vram_org + script_read8()); Alis::$varD7 = s8(xread8($addr));}// Opername no. 15 opcode 0x1c odirtifunction odirti(): void{ $addr = tabint(Alis::$script->vram_org + script_read8()); Alis::$varD7 = xread16($addr);}// Opername no. 16 opcode 0x1e omainbfunction omainb(): void{ $offset = s16(script_read16()); Alis::$varD7 = s8(xread8(Alis::$basemain + $offset));}// Opername no. 17 opcode 0x20 omainwfunction omainw(): void{ $offset = s16(script_read16()); Alis::$varD7 = xread16(Alis::$basemain + $offset);}// Opername no. 18 opcode 0x22 omainpfunction omainp(): void{ $offset = s16(script_read16()); if (Alis::$platform->version == 10) { Alis::$varD7 = xread16(Alis::$basemain + $offset + 2); return; } mem_strcpy(Alis::$sd7, Alis::$basemain + $offset);}// Opername no. 19 opcode 0x24 omaintpfunction omaintp(): void{ if (Alis::$platform->version == 10) { return; } $addr = tabstring(Alis::$basemain + script_read16()); mem_strcpy(Alis::$sd7, $addr);}// Opername no. 20 opcode 0x26 omaintcfunction omaintc(): void{ $addr = tabchar(Alis::$basemain + script_read16()); Alis::$varD7 = s8(xread8($addr));}// Opername no. 21 opcode 0x28 omaintifunction omainti(): void{ $addr = tabint(Alis::$basemain + script_read16()); Alis::$varD7 = xread16($addr);}// Opername no. 22 opcode 0x2a ohimbfunction ohimb(): void{ $entry = xread16(Alis::$script->vram_org + s16(script_read16())) & 0xffff; $vram_addr = xread32(Alis::$atent + $entry); if (Alis::$platform->version >= 60) { $offset = script_read16() & 0xffff; if ($vram_addr <= 0) { return; } Alis::$varD7 = s8(xread8($vram_addr + $offset)); return; } $offset = s16(script_read16()); // The v3 DOS VM (0x9edc) leaves D7 unchanged when the other entity is dead or not started (vram <= 0). if (Alis::$platform->kind == C::EPlatformPC && Alis::$platform->version >= 30 && $vram_addr <= 0) { return; } Alis::$varD7 = s8(xread8($vram_addr + $offset));}// Opername no. 23 opcode 0x2c ohimwfunction ohimw(): void{ $entry = xread16(Alis::$script->vram_org + s16(script_read16())) & 0xffff; $vram_addr = xread32(Alis::$atent + $entry); if (Alis::$platform->version >= 60) { $offset = script_read16() & 0xffff; if ($vram_addr <= 0) { return; } Alis::$varD7 = xread16($vram_addr + $offset); return; } $offset = s16(script_read16()); // The v3 DOS VM (0x9f08) leaves D7 unchanged when the other entity is dead or not started (vram <= 0). if (Alis::$platform->kind == C::EPlatformPC && Alis::$platform->version >= 30 && $vram_addr <= 0) { return; } Alis::$varD7 = xread16($vram_addr + $offset);}// Opername no. 24 opcode 0x2e ohimpfunction ohimp(): void{ $entry = xread16(Alis::$script->vram_org + s16(script_read16())) & 0xffff; $vram_addr = xread32(Alis::$atent + $entry); $offset = s16(script_read16()); if (Alis::$platform->version == 10) { Alis::$varD7 = xread16($vram_addr + $offset + 2); return; } mem_strcpy(Alis::$sd7, $vram_addr + $offset);}// Opername no. 25 opcode 0x30 ohimtpfunction ohimtp(): void{ // MISSING in the C}// Opername no. 26 opcode 0x32 ohimtcfunction ohimtc(): void{ if (Alis::$platform->version == 10) { $offset = s16(script_read16()); $vram = xread32(Alis::$atent + xread16(Alis::$script->vram_org + s16(script_read16()))); Alis::$varD7 = s8(xread8(tabchar($vram + $offset))); return; } // MISSING in the C}// Opername no. 27 opcode 0x34 ohimtifunction ohimti(): void{ if (Alis::$platform->version == 10) { $offset = s16(script_read16()); $vram = xread32(Alis::$atent + xread16(Alis::$script->vram_org + s16(script_read16()))); Alis::$varD7 = xread16(tabint($vram + $offset)); return; } // MISSING in the C}// Opername no. 28 opcode 0x36 opile// pop from accumulator into r6function opile(): void{ // save r6 into r7 Alis::$varD7 = Alis::$varD6; Alis::$varD6 = hread32(Alis::$acc); Alis::$acc += 4;}// Opername no. 29 opcode 0x38 oeval// start eval loop, will stop after ofin() is calledfunction oeval(): void{ Alis::$oeval_loop = 1; while (Alis::$oeval_loop) { readexec_opername(); }}// Opername no. 30 opcode 0x3a ofin// stop eval loopfunction ofin(): void{ if (Alis::$oeval_loop) { Alis::$oeval_loop = 0; return; } if (Alis::$platform->version >= 60 && Alis::$ofin_active) { Alis::$ofin_active = 0; throw new OfinJump(); // C: longjmp(alis.ofin_jmp, 1), caught by readexec_opcode_v6 } Alis::$oeval_loop = 0;}// Opername no. 33 opcode 0x40 opushacc// push value from r7 register to accumulatorfunction opushacc(): void{ Alis::$acc -= 4; hwrite32(Alis::$acc, Alis::$varD7);}// Opername no. 34 opcode 0x42 oand// r7 = variable AND r7function oand(): void{ Alis::$varD6 = Alis::$varD7; readexec_opername(); Alis::$varD7 &= Alis::$varD6;}// Opername no. 35 opcode 0x44 oor// r7 = variable OR r7function oor(): void{ Alis::$varD6 = Alis::$varD7; readexec_opername(); Alis::$varD7 |= Alis::$varD6;}// Opername no. 36 opcode 0x46 oxor// r7 = variable XOR r7function oxor(): void{ readexec_opername_saveD7(); Alis::$varD7 ^= Alis::$varD6;}// Opername no. 37 opcode 0x48 oeqv// r7 = variable EQV r7function oeqv(): void{ readexec_opername_saveD7(); Alis::$varD7 ^= Alis::$varD6; Alis::$varD7 = ~Alis::$varD7;}// Opername no. 38 opcode 0x4a oegal// r6 == r7function oegal(): void{ readexec_opername_saveD7(); Alis::$varD7 = (Alis::$varD6 == Alis::$varD7) ? -1 : 0;}// Opername no. 39 opcode 0x4c odiff// r6 != r7function odiff(): void{ readexec_opername_saveD7(); Alis::$varD7 = (Alis::$varD6 != Alis::$varD7) ? -1 : 0;}// Opername no. 40 opcode 0x4e oinfeg// r6 <= r7function oinfeg(): void{ readexec_opername_saveD7(); Alis::$varD7 = (Alis::$varD6 <= Alis::$varD7) ? -1 : 0;}// Opername no. 41 opcode 0x50 osupeg// r6 >= r7function osupeg(): void{ readexec_opername_saveD7(); Alis::$varD7 = (Alis::$varD6 >= Alis::$varD7) ? -1 : 0;}// Opername no. 42 opcode 0x52 oinf// r6 < r7function oinf(): void{ readexec_opername_saveD7(); Alis::$varD7 = (Alis::$varD6 < Alis::$varD7) ? -1 : 0;}// Opername no. 43 opcode 0x54 osup// r6 > r7function osup(): void{ readexec_opername_saveD7(); Alis::$varD7 = (Alis::$varD6 > Alis::$varD7) ? -1 : 0;}// Opername no. 44 opcode 0x56 oadd// r7 += variablefunction oadd(): void{ readexec_opername_saveD7(); Alis::$varD7 = s32(Alis::$varD7 + Alis::$varD6);}// Opername no. 45 opcode 0x58 osub// r7 -= variablefunction osub(): void{ readexec_opername_saveD7(); Alis::$varD6 = s32(Alis::$varD6 - Alis::$varD7); Alis::$varD7 = Alis::$varD6;}// Opername no. 46 opcode 0x5a omod// r7 %= variablefunction omod(): void{ readexec_opername_saveD7(); if (Alis::$platform->version >= 60 && Alis::$varD7 == 0) { Alis::$varD7 = 1; } // PORT: a zero divisor traps in the C (pre-v6 games): cmod() returns 0 instead of crashing. Alis::$varD6 = s32(cmod(Alis::$varD6, Alis::$varD7)); Alis::$varD7 = Alis::$varD6;}// Opername no. 47 opcode 0x5c odiv// r7 /= variablefunction odiv(): void{ readexec_opername_saveD7(); // The DOS VM (0xa31f) replaces a zero divisor by 1: x / 0 = x. if (Alis::$varD7 == 0) { Alis::$varD7 = 1; } // PORT: cdiv() returns 0 instead of crashing. Alis::$varD6 = s32(cdiv(Alis::$varD6, Alis::$varD7)); Alis::$varD7 = Alis::$varD6;}// Opername no. 48 opcode 0x5e omul// r7 *= variablefunction omul(): void{ readexec_opername_saveD7(); Alis::$varD7 = mul32(Alis::$varD7, Alis::$varD6);}// Opername no. 49 opcode 0x60 onegfunction oneg(): void{ Alis::$varD7 = s32(-Alis::$varD7);}// Opername no. 50 opcode 0x62 oabsfunction oabs(): void{ if (Alis::$varD7 < 0) { Alis::$varD7 = s32(-Alis::$varD7); }}// Opername no. 51 opcode 0x64 orndfunction ornd(): void{ $result = Alis::$random_number; $result = Alis::$random_number = (mul32($result, 0x7ab7) - 0x77f) & 0xffff; $result = mul32(Alis::$varD7 & 0xffff, $result); Alis::$varD7 = shl32($result, 16) | shr32($result, 16);}// Opername no. 52 opcode 0x66 osgnfunction osgn(): void{ if (Alis::$varD7 > 0) { Alis::$varD7 = 1; } elseif (Alis::$varD7 < 0) { Alis::$varD7 = -1; }}// Opername no. 53 opcode 0x68 onotfunction onot(): void{ Alis::$varD7 = ~Alis::$varD7;}// Opername no. 54 opcode 0x6a oinkeyfunction oinkey(): void{ if (Alis::$automode) { Alis::$varD7 = Alis::$prevkey; } else { Alis::$prevkey = s16(io_inkey()); Alis::$varD7 = Alis::$prevkey; }}// Opername no. 55 opcode 0x6c okeyon// [N/I]: Robinson's Requiem (IBM PC)function okeyon(): void{}// Opername no. 56 opcode 0x6e ojoyfunction ojoy(): void{ if (Alis::$automode == 0) { Alis::$varD7 = Alis::$platform->version == 10 ? io_joy_raw() : io_joy(Alis::$varD7 & 0xff); }}// Opername no. 57 opcode 0x70 oprndfunction oprnd(): void{ $result = hread32(Alis::$acc); Alis::$acc += 4; $result = (shl32($result, 10) | shr32($result, 6)) & 0xffff; $result = (mul32($result, 0x7ab7) - 0x77f) & 0xffff; $result = mul32(Alis::$varD7 & 0xffff, $result); Alis::$varD7 = shl32($result, 16) | shr32($result, 16);}// Opername no. 58 opcode 0x72 oscanfunction oscan(): void{ $vram_org = Alis::$script->vram_org; $new_val = get_0x1e_scan_clr($vram_org); if ($new_val == get_0x1c_scan_clr($vram_org)) { Alis::$varD7 = -1; return; } $limit = Alis::$platform->version >= 30 ? -0x3f : -0x35; $result = xread16($vram_org + $new_val); $new_val = s16($new_val + 2); if ($limit < $new_val) { $new_val = s16($new_val - xread16(get_0x14_script_org_offset($vram_org) + 0x16)); } set_0x1e_scan_clr($vram_org, $new_val); if ($new_val == get_0x1c_scan_clr($vram_org)) { set_0x24_scan_inter($vram_org, get_0x24_scan_inter($vram_org) & 0x7f); } Alis::$varD7 = $result;}// Opername no. 59 opcode 0x74 oshiftkeyfunction oshiftkey(): void{ // TODO: if automode is active use value stored in D1 Alis::$varD7 = Alis::$automode ? 0 : io_shiftkey();}// Free space for saves, in KB, capped at 32 MB as the original (GEMDOS Dfree). Saves go to// the data folder, so measure its drive whatever letter the script asks for.function io_dfree(): int{ return s16(udiv32(sys_free_bytes(Alis::$platform->path, 32000000), 1000));}// Opername no. 60 opcode 0x76 ofreefunction ofree(): void{ if (Alis::$platform->version <= 20) { if (Alis::$varD7 == 0) { Alis::$varD7 = udiv32(s32(Alis::$finmem - Alis::$finprog), 1000); } elseif (Alis::$varD7 == 1) { Alis::$varD7 = cdiv(s32(Img::$debsprit - Alis::$finent), 1000); } elseif (Alis::$varD7 == 2) { Alis::$varD7 = Alis::$maxprog - Alis::$nbprog; } elseif (Alis::$varD7 == 3) { Alis::$varD7 = s32(Alis::$maxent - Alis::$nbent); } elseif (Alis::$varD7 == 4) { Alis::$varD7 = 0; for ($spritidx = s16(Img::$libsprit); $spritidx != 0; $spritidx = s16(sprite_var($spritidx)->to_next)) { Alis::$varD7++; } } elseif ((Alis::$varD7 == 0x61) || (Alis::$varD7 == 0x41)) { Alis::$varD7 = io_dfree(); } elseif ((Alis::$varD7 == 0x62) || (Alis::$varD7 == 0x42)) { Alis::$varD7 = io_dfree(); } elseif ((Alis::$varD7 != 99) && (Alis::$varD7 != 0x43)) { Alis::$varD7 = -1; } else { Alis::$varD7 = io_dfree(); } } else { if (Alis::$platform->uid == C::EGameDeus && (Alis::$varD7 == 0 || Alis::$varD7 == 1)) { Alis::$varD7 = udiv32(s32(Alis::$finmem - Alis::$finprog + v6_enttop() - Alis::$finent), 1000); } elseif (Alis::$varD7 == 0) { Alis::$varD7 = udiv32(s32(Alis::$finmem - Alis::$finprog), 1000); } elseif (Alis::$varD7 == 1) { Alis::$varD7 = cdiv(s32(Img::$debsprit - Alis::$finent), 1000); } elseif (Alis::$varD7 == 2) { Alis::$varD7 = Alis::$maxprog - Alis::$nbprog; } elseif (Alis::$varD7 == 3) { Alis::$varD7 = s32(Alis::$maxent - Alis::$nbent); } elseif (Alis::$varD7 == 4) { Alis::$varD7 = 0; for ($spritidx = s16(Img::$libsprit); $spritidx != 0; $spritidx = s16(sprite_var($spritidx)->to_next)) { Alis::$varD7++; } } elseif (0x40 < Alis::$varD7) { if (Alis::$varD7 < 0x49) { Alis::$varD7 = io_dfree(); } if ((0x60 < Alis::$varD7) && (Alis::$varD7 < 0x69)) { Alis::$varD7 = io_dfree(); } } else { Alis::$varD7 = -1; } }}// Opername no. 61 opcode 0x78 omodelfunction omodel(): void{ if (Alis::$platform->version >= 60) { Alis::$varD7 = 0; return; } Alis::$varD7 = sys_get_model();}// Opername no. 62 opcode 0x7a ogetkey// PORT: io_getkey() busy-waits for a key in the C; the host layer's io_getkey() (sys.php) is non-blocking:// it calls vm_yield_retry() (this opcode restarts at the next frame) until a key is available.function ogetkey(): void{ Alis::$varD7 = io_getkey();}// Opername no. 63 opcode 0x7c oleftfunction oleft(): void{ pop_sd7(); Alis::$mem[Alis::$sd7 + (Alis::$varD7 & 0xff)] = "\0";}// Opername no. 64 opcode 0x7e orightfunction oright(): void{ // DOS v3 (0xa421): pop the string, keep its last dx characters (src clamped to the start) pop_sd7(); $s = Alis::$sd7; $src = $s + mem_strlen($s) - s16(Alis::$varD7); if ($src <= $s) { $src = $s; } do { $c = Alis::$mem[$src++]; Alis::$mem[$s++] = $c; } while ($c !== "\0");}// Opername no. 65 opcode 0x80 omidfunction omid(): void{ $src = Alis::$sd7 + hread32(Alis::$acc); Alis::$acc += 4; pop_sd7(); $tgt = Alis::$sd7; Alis::$varD7 = s32(Alis::$varD7 - 1); for (; Alis::$varD7 > -1; Alis::$varD7--, $src++, $tgt++) { Alis::$mem[$tgt] = Alis::$mem[$src]; if (Alis::$mem[$tgt] === "\0") { break; } } if (Alis::$varD7 < 0) { Alis::$mem[$tgt] = "\0"; }}// Opername no. 66 opcode 0x82 olenfunction olen(): void{ Alis::$varD7 = mem_strlen(Alis::$sd7);}// Opername no. 67 opcode 0x84 oascfunction oasc(): void{ if (Alis::$platform->version >= 60) { Alis::$varD7 = xread8(Alis::$sd7); return; } // C char is signed Alis::$varD7 = s8(xread8(Alis::$sd7));}// Opername no. 68 opcode 0x86 ostrfunction ostr(): void{ valtostr(Alis::$sd7, s16(Alis::$varD7));}// Opername no. 69 opcode 0x88 osaddfunction osadd(): void{ readexec_opername_swap(); mem_putstr(Alis::$sd6, mem_str(Alis::$sd6) . mem_str(Alis::$sd7)); $tmp = Alis::$sd6; Alis::$sd6 = Alis::$sd7; Alis::$sd7 = $tmp;}// Opername no. 70 opcode 0x8a osequalfunction osequal(): void{ readexec_opername_swap(); Alis::$varD7 = strncmp(mem_str(Alis::$sd6), mem_str(Alis::$sd7), mem_strlen(Alis::$sd6)) ? 0 : -1;}// Opername no. 71 opcode 0x8c osdifffunction osdiff(): void{ readexec_opername_swap(); Alis::$varD7 = strncmp(mem_str(Alis::$sd6), mem_str(Alis::$sd7), mem_strlen(Alis::$sd6)) ? -1 : 0;}// Opername no. 72 opcode 0x8e osinfegfunction osinfeg(): void{ readexec_opername_swap(); Alis::$varD7 = strncmp(mem_str(Alis::$sd6), mem_str(Alis::$sd7), mem_strlen(Alis::$sd6)) <= 0 ? -1 : 0;}// Opername no. 73 opcode 0x90 ossupegfunction ossupeg(): void{ readexec_opername_swap(); Alis::$varD7 = strncmp(mem_str(Alis::$sd6), mem_str(Alis::$sd7), mem_strlen(Alis::$sd6)) >= 0 ? -1 : 0;}// Opername no. 74 opcode 0x92 osinffunction osinf(): void{ readexec_opername_swap(); Alis::$varD7 = strncmp(mem_str(Alis::$sd6), mem_str(Alis::$sd7), mem_strlen(Alis::$sd6)) < 0 ? -1 : 0;}// Opername no. 75 opcode 0x94 ossupfunction ossup(): void{ readexec_opername_swap(); Alis::$varD7 = strncmp(mem_str(Alis::$sd6), mem_str(Alis::$sd7), mem_strlen(Alis::$sd6)) > 0 ? -1 : 0;}// Opername no. 76 opcode 0x96 ospushaccfunction ospushacc(): void{ push_sd7();}// Opername no. 77 opcode 0x98 ospilefunction ospile(): void{ $tmp = Alis::$sd6; Alis::$sd6 = Alis::$sd7; Alis::$sd7 = $tmp; pop_sd6();}// Opername no. 78 opcode 0x9a ovalfunction oval(): void{ // compute int value of the sd7 string (decimal, or hexadecimal after '$') -> d7 $result = 0; $flip = 0; if (xread8(Alis::$sd7) != 0) { $string = Alis::$sd7; $flip = (int) (xread8(Alis::$sd7) == 0x2d); if ($flip) { $string++; } $c1 = 0; $c2 = 0; if (s8(xread8($string)) == 0x24) { while (true) { $string++; $c2 = s8(xread8($string)); if ($c2 == 0 || ($c2 - 0x30) < 0) { break; } if ($c2 < 0x3a) { $c1 = s8($c2 - 0x30); } else { $c2 = s8($c2 & 0xdf); if ($c2 + 0xbf < 0 || 0x46 < $c2) { break; } $c1 = s8($c2 - 0x37); } $result = s16($result * 0x10 + $c1); } } else { while (true) { $c2 = s8(xread8($string)); if (($c2 == 0 || ($c2 - 0x30) < 0) || 0x39 < $c2) { break; } $result = s16($result * 10 + ($c2 - 0x30)); $string++; } } } Alis::$varD7 = $flip ? -$result : $result;}// Opername no. 79 opcode 0x9c oexistffunction oexistf(): void{ $path = Alis::$platform->path; $namepos = strlen($path); $path .= mem_str(Alis::$sd7); $name = substr($path, $namepos); $dotpos = strrpos($name, '.'); if ($dotpos !== false) { $ext = substr($name, $dotpos + 1); if (strcasecmp($ext, 'fic') && strcasecmp($ext, 'cst') && strcasecmp($ext, 'dat') && !sys_fexists($path)) { $path = substr($path, 0, $namepos + $dotpos + 1) . Alis::$platform->ext; } } // an empty name would test the data folder itself Alis::$varD7 = ($name !== '' && sys_fexists($path)) ? -1 : 0;}// Opername no. 80 opcode 0x9e ochrfunction ochr(): void{ Alis::$mem[Alis::$sd7] = chr(Alis::$varD7 & 0xff); Alis::$mem[Alis::$sd7 + 1] = "\0";}// Opername no. 81 opcode 0xa0 ochangefunction ochange(): void{ if (Alis::$platform->kind != C::EPlatformPC) { // TODO: change le drive courant ?? (stubbed in the C) Alis::$varD7 = 0; return; } // DOS VM: emulates an install on the hard disk C: whose current drive never changes // ('?' answers 'C', so `change('?') < 67` is false and the scripts skip the floppy path). $c = Alis::$varD7 & 0xffff; if ($c === 0x3f) { Alis::$varD7 = 0x43; return; } if ($c >= 0x61) { $n = $c - 0x61; } elseif ($c >= 0x41) { $n = $c - 0x41; } else { Alis::$varD7 = 0; return; } // A:/B: fail (no disk, the original returns -1 -> 0); C: and above answer their letter. Alis::$varD7 = ($n >= 2) ? (0x41 + $n) & 0xff : 0;}// Opername no. 82 opcode 0xa2 ocountryfunction ocountry(): void{ Alis::$varD7 = Alis::$pays;}// Opername no. 83 opcode 0xa4 omipfunction oips(): void{ Alis::$varD7 = s16(Alis::$v6ips + 1);}function omip(): void{ Alis::$varD7 = Alis::$platform->version >= 60 ? 0x93 : 0x64;}// Opername no. 84 opcode 0xa6 ojoykeyfunction ojoykey(): void{ if (Alis::$platform->version >= 60) { Alis::$varD7 = 0; return; } if (Alis::$automode == 0) { Alis::$varD7 = io_joykey(Alis::$varD7 & 0xff); }}// Opername no. 85 opcode 0xa8 oconfigfunction oconfig(): void{ Alis::$varD7 = Alis::$theconfig; if (Alis::$platform->version >= 60) { // Deus reads a hardware config word via oconfig and extracts video/capability bits // DOS's runtime value is 0x44 for the SVGA setup, so those bits are non-zero // 0 here takes the VGA/low branch // Override to the verified DOS value until theconfig is derived from OPTION.DAT/START.STP. Alis::$varD7 = 0x0044; }}// Opername no. 31 opcode 0x3c pnul// Opername no. 32 opcode 0x3e pnul// Calls stub pnul// =============================================================================// Oper (Operation) routines pointer table (85 values), indexed by the opcode byte// (odd slots are NULL in the C).// =============================================================================function table_opernames(): array{ $t = [ oimmb(...), null, oimmw(...), null, oimmp(...), null, olocb(...), null, olocw(...), null, olocp(...), null, oloctp(...), null, oloctc(...), null, olocti(...), null, odirb(...), null, odirw(...), null, odirp(...), null, odirtp(...), null, odirtc(...), null, odirti(...), null, omainb(...), null, omainw(...), null, omainp(...), null, omaintp(...), null, omaintc(...), null, omainti(...), null, ohimb(...), null, ohimw(...), null, ohimp(...), null, ohimtp(...), null, ohimtc(...), null, ohimti(...), null, opile(...), null, oeval(...), null, ofin(...), null, oimml(...), null, olocto(...), null, opushacc(...), null, oand(...), null, oor(...), null, oxor(...), null, oeqv(...), null, oegal(...), null, odiff(...), null, oinfeg(...), null, osupeg(...), null, oinf(...), null, osup(...), null, oadd(...), null, osub(...), null, omod(...), null, odiv(...), null, omul(...), null, oneg(...), null, oabs(...), null, ornd(...), null, osgn(...), null, onot(...), null, oinkey(...), null, okeyon(...), null, ojoy(...), null, oprnd(...), null, oscan(...), null, oshiftkey(...), null, ofree(...), null, omodel(...), null, ogetkey(...), null, oleft(...), null, oright(...), null, omid(...), null, olen(...), null, oasc(...), null, ostr(...), null, osadd(...), null, osequal(...), null, osdiff(...), null, osinfeg(...), null, ossupeg(...), null, osinf(...), null, ossup(...), null, ospushacc(...), null, ospile(...), null, oval(...), null, oexistf(...), null, ochr(...), null, ochange(...), null, ocountry(...), null, omip(...), null, ojoykey(...), null, oconfig(...), null, ogettext(...), null, oips(...), null, ]; $names = [ 'oimmb', 'oimmw', 'oimmp', 'olocb', 'olocw', 'olocp', 'oloctp', 'oloctc', 'olocti', 'odirb', 'odirw', 'odirp', 'odirtp', 'odirtc', 'odirti', 'omainb', 'omainw', 'omainp', 'omaintp', 'omaintc', 'omainti', 'ohimb', 'ohimw', 'ohimp', 'ohimtp', 'ohimtc', 'ohimti', 'opile', 'oeval', 'ofin', 'oimml', 'olocto', 'opushacc', 'oand', 'oor', 'oxor', 'oeqv', 'oegal', 'odiff', 'oinfeg', 'osupeg', 'oinf', 'osup', 'oadd', 'osub', 'omod', 'odiv', 'omul', 'oneg', 'oabs', 'ornd', 'osgn', 'onot', 'oinkey', 'okeyon', 'ojoy', 'oprnd', 'oscan', 'oshiftkey', 'ofree', 'omodel', 'ogetkey', 'oleft', 'oright', 'omid', 'olen', 'oasc', 'ostr', 'osadd', 'osequal', 'osdiff', 'osinfeg', 'ossupeg', 'osinf', 'ossup', 'ospushacc', 'ospile', 'oval', 'oexistf', 'ochr', 'ochange', 'ocountry', 'omip', 'ojoykey', 'oconfig', 'ogettext', 'oips', ]; $n = []; foreach ($names as $i => $name) { $n[$i * 2] = $name; $n[$i * 2 + 1] = ''; } Tables::$names['opernames'] = $n; return $t;}// v6 selects its own table: the base one with the opernames_v6_ov entries (opernames_v6.php) applied.// PORT: the C caches the first result in a static; cached per v6-ness here so that the player can// switch from a pre-v6 game to a v6 one in the same PHP process.function alis_tab_opernames(): array{ static $live = []; $v6 = Alis::$platform->version >= 60 ? 1 : 0; if (!isset($live[$v6])) { $t = table_opernames(); if ($v6) { foreach (table_opernames_v6_ov() as $code => [$f, $name]) { $t[$code & 0xff] = $f; Tables::$names['opernames'][$code & 0xff] = $name; } } $live[$v6] = $t; } return $live[$v6];}