= 60: Deus, Robinson's Requiem 3DO, Time Warriors...) part of the second half of opcodes.c // (cwmov .. end): the *_v6 handlers, the v6 helpers and the v6 override opcode table (opcodes_v6_ov). // The v6 branches of the shared handlers stay inline in fn/opcodes_b.php; the big ones are // split out here as _v6branch() (PORT: not a C function, the body of the `version >= 60` block). use App\Alis\OpcodesV6Vars as V6; use App\Alis\OpcodesV6bVars as V6b; // Codopname no. 163 opcode 0xa2 cwmov: body of the `version >= 60` block function cwmov_v6branch(): void { readexec_opername_saveD7(); $px = s32(Alis::$varD7); readexec_opername_saveD7(); $op2 = s32(Alis::$varD7); $scr = s16(xread16(Alis::$script->vram_org - 0x64)); $s = s32(Alis::$basemain + ($scr & 0xffff)); $world = xread32($s + 0x5e); $py = 0; $pz = $op2; $mode = xread8($s + 0x5a); if ($mode != 0) { $pz = s16(-$op2 + s16(xread16($s + 0x64))); if ($mode != 1 && $mode != 6) { $t = $pz; $pz = $py; $py = $t; } } $pye = 0x7fffffff; $pze = 1; if ($mode == 2) { $pye = 1; $pze = 0x7fffffff; } $pxmin = $px; $pxmax = s32($px + 1); $pymin = $py; $pymax = s32($py + $pye); $pzmin = $pz; $pzmax = s32($pz + $pze); $result = 0; V6::$v6mat_n = 0; if ($world != 0) { $sp = xread32($world + 0x38); while ($sp != 0 && $sp != xread32($sp + 0x38)) { $cand = $sp; $sp = xread32($sp + 0x38); if (xread16($cand + 0x28) == 0) { continue; } if (xread8($cand + 0x24) & 0x40) { continue; } if (xread8($cand + 0x25) & 0x4) { continue; } if (v6sp_state($cand) != 0x35) { continue; } if (xread16($cand + 0x2a) == 0) { continue; } $cx = 0; $cy = 0; $cz = 0; for ($p = $cand; $p != 0; $p = v6sp_parent($p)) { $cx = s32($cx + v6sp_depx($p)); $cy = s32($cy + v6sp_depy($p)); $cz = s32($cz + v6sp_depz($p)); } if (xread8($cand + 0x25) & 1) { $cxmax = s32($cx - xread32($cand + 0x40)); $cxmin = s32($cxmax - xread32($cand + 0x4c)); } else { $cxmin = s32($cx + xread32($cand + 0x40)); $cxmax = s32($cxmin + xread32($cand + 0x4c)); } if ($cxmin > $pxmax || $cxmax < $pxmin) { continue; } $czmin = s32($cz + xread32($cand + 0x48)); $czmax = s32($czmin + xread32($cand + 0x54)); if ($czmin > $pzmax || $czmax < $pzmin) { continue; } $cymin = s32($cy + xread32($cand + 0x44)); $cymax = s32($cymin + xread32($cand + 0x50)); if ($cymin > $pymax || $cymax < $pymin) { continue; } if (V6::$v6mat_n < V6::V6MAT_MAX) { V6::$v6mat_ent[V6::$v6mat_n] = xread16($cand + 0x2a) & 0xffff; V6::$v6mat_id[V6::$v6mat_n] = s32((xread16($cand + 0x26) & 0xffff) | shl32(xread16($cand + 0x28) & 0xffff, 16)); V6::$v6mat_n++; } $result = xread16($cand + 0x26) & 0xffff; break; } } Alis::$varD7 = s16($result); cstore_continue(); } // v6 dispatch target for cwtstmov function cwtstmov_v6(): void { Alis::$v6tstdx = Alis::$v6tstdy = Alis::$v6tstdz = 0; Alis::$v6tstflag = 0; readexec_opername_saveD7(); Alis::$v6tstmask = Alis::$varD7 & 0xffff; readexec_opername_saveD7(); Alis::$v6tstarg = s32(Alis::$varD7); v6_tstscan(); crstent(); } // v6 dispatch target for cwftstmov function cwftstmov_v6(): void { Alis::$v6tstdx = Alis::$v6tstdy = Alis::$v6tstdz = 0; Alis::$v6tstflag = 0; readexec_opername_saveD7(); Alis::$v6tstmask = Alis::$varD7 & 0xffff; v6_tst_addr_operand(); v6_tstscan_elem(); crstent(); } // v6 dispatch target for ctstform function ctstform_v6(): void { Alis::$v6tstpolar = 1; v6_tst_from_movevec(); readexec_opername_saveD7(); Alis::$v6tstflag = Alis::$varD7 & 0xff; readexec_opername_saveD7(); Alis::$v6tstmask = Alis::$varD7 & 0xffff; v6_tst_addr_operand(); v6_tstscan_elem(); Alis::$v6tstpolar = 0; crstent(); } // v6 dispatch target for cxput function cxput_v6(): void { v6_put_entry(1, 0, 0, 0); } // v6 dispatch target for cxputat function cxputat_v6(): void { v6_put_entry(1, 0, 0, 1); } // v6 dispatch target for cmput function cmput_v6(): void { v6_put_entry(0, 1, 0, 0); } // v6 dispatch target for cmputat function cmputat_v6(): void { v6_put_entry(0, 1, 0, 1); } // v6 dispatch target for cmxput function cmxput_v6(): void { v6_put_entry(0, 0, 1, 0); } // v6 dispatch target for cmxputat function cmxputat_v6(): void { v6_put_entry(0, 0, 1, 1); } // Codopname no. 179 opcode 0xb2 casleepfar function casleepfar_v6(): void { readexec_opername(); $r2 = mul32(Alis::$varD7, Alis::$varD7); $me = Alis::$script->vram_org; $ent = s16(alis_first_ent()); do { $vram = xread32(Alis::$atent + $ent); if ($vram == 0 || (get_0x24_scan_inter($vram) & 4) != 0) { continue; } $dx = s32(xread32($vram + 0x0c) - xread32($me + 0x0c)); $dy = s32(xread32($vram + 0x10) - xread32($me + 0x10)); $dz = s32(xread32($vram + 0x14) - xread32($me + 0x14)); // u64 d2 = dx*dx + dy*dy + dz*dz; near when (d2 >> 32) == 0 && (u32)d2 < r2. // PORT: d2 < 2^32 needs every |d| < 0x10000, then the sum is exact (int or float < 2^53). $near = false; if ($dx > -0x10000 && $dx < 0x10000 && $dy > -0x10000 && $dy < 0x10000 && $dz > -0x10000 && $dz < 0x10000) { $d2 = $dx * $dx + $dy * $dy + $dz * $dz; $near = $d2 < 65536.0 * 65536.0 && $d2 < u32v($r2); } $fl = xread8(V6_FARSLEEP($vram)); if ($near) { if ($fl & 2) { xwrite8(V6_FARSLEEP($vram), $fl & 0xfd); v6_enqueue(s16(xread16($vram + 0x3a)), -0x7fff); v6_enqueue(s16(xread16($vram + 0x3a)), xread16($me + 0x3a) & 0xffff); } } elseif (!($fl & 2)) { xwrite8(V6_FARSLEEP($vram), $fl | 2); } } while (($ent = xread16(Alis::$atent + 4 + $ent))); } // v6 dispatch target for cfont function cfont_v6(): void { readexec_opername(); $index = s16(Alis::$varD7); if (Alis::$platform->version >= 60) { xwrite8(Alis::$script->vram_org - 0x66, $index & 0xff); } if ($index >= 0 && $index < 64 && !empty(Alis::$v6fonts[$index]['valid'])) { $f = Alis::$v6fonts[$index]; Alis::$foasc = $f['foasc'] & 0xffff; Alis::$fonum = $f['fonum'] & 0xffff; Alis::$fomax = $f['fomax'] & 0xffff; Alis::$folarg = $f['folarg'] & 0xff; Alis::$fohaut = $f['fohaut'] & 0xff; Alis::$fomain = $f['usemain'] & 0xff; } } // Codopname no. 192 opcode 0xbf cnumput: body of the `version >= 60` block function cnumput_v6branch(): void { $v6put = ImageV6Vars::$v6put; Alis::$flagmain = 0; $v6put->angx = 0; $v6put->angy = 0; $v6put->angz = 0; $v6put->invert = 0; $v6put->scale = 0x100; $v6put->rotb1 = 0; $v6put->rotate = 0; $v6put->rotb2 = 0; $p = ['elem' => 0, 'limit' => 0, 'aux' => 0]; getprot_x($p); $v6put->basesprite = $p['elem']; $v6put->limit = $p['limit']; $v6put->numcreated = 0; if ($p['elem'] > 0) { xwrite32($p['elem'] + 0x3c, 0); } readexec_opername_saveD7(); $v6put->depx = s16(Alis::$varD7); readexec_opername_saveD7(); $v6put->depy = s16(Alis::$varD7); readexec_opername_saveD7(); $v6put->depz = s16(Alis::$varD7); readexec_opername_saveD7(); $v6put->textattr = Alis::$varD7 & 0xff; } // v6 dispatch target for cschoriz function cschoriz_v6(): void { $scene = Alis::$platform->version >= 60 ? s16(xread16(Alis::$script->vram_org - 0x64)) : s16(get_0x16_screen_id(Alis::$script->vram_org)); readexec_opername(); $addr = s32(Alis::$basemain + ($scene & 0xffff) + 0x59); $dl = Alis::$varD7 & 0xff; if (Alis::$varD7 & 0x100) { xwrite8($addr, xread8($addr) | $dl); } else { xwrite8($addr, xread8($addr) & (~$dl & 0xff)); } } // v6 dispatch target for creducing function creducing_v6(): void { $p = ['elem' => 0, 'limit' => 0, 'aux' => 0]; getprot_x($p); readexec_opername_saveD7(); $v = s32(Alis::$varD7); $setbits = $v & 0xff; $clrmask = ~(($v >> 16) & 0xff) & 0xff; if ($p['aux'] != -1) { $slot = s32($p['elem'] + $p['aux']); xwrite8($slot + 0x25, (xread8($slot + 0x25) | $setbits) & $clrmask); xwrite8($slot + 0x23, (xread8($slot + 0x23) & 0x8f) | 1); soundatten_v6($slot); return; } $slot = $p['elem']; $count = xread8($slot + 0x33); for ($i = 0; $i < $count; $i++) { if (xread32($slot + 0x8) == Alis::$script->vram_org) { xwrite8($slot + 0x25, (xread8($slot + 0x25) | $setbits) & $clrmask); xwrite8($slot + 0x23, (xread8($slot + 0x23) & 0x8f) | 1); soundatten_v6($slot); } $slot = s32($slot + C::V6_SLOT_STRIDE); } } // v6 dispatch target for calign function calign_v6(): void { $v6put = ImageV6Vars::$v6put; Alis::$flagmain = 0; $v6put->invert = xread8(Alis::$script->vram_org + 0x25); $p = ['elem' => 0, 'limit' => 0, 'aux' => 0]; getprot_x($p); $v6put->limit = $p['limit']; $v6put->basesprite = $p['elem']; $v6put->desc = 0; $v6put->defstate = 0x10; $e = $p['elem']; readexec_opername_saveD7(); xwrite8($e + 0x56, Alis::$varD7 & 0xff); readexec_opername_saveD7(); xwrite16($e + 0x48, Alis::$varD7); readexec_opername_saveD7(); xwrite16($e + 0x4a, Alis::$varD7); readexec_opername_saveD7(); xwrite16($e + 0x4c, Alis::$varD7); readexec_opername_saveD7(); xwrite16($e + 0x4e, Alis::$varD7); readexec_opername_saveD7(); xwrite16($e + 0x40, Alis::$varD7); if (Alis::$varD7 == -1) { xwrite8($e + 0x56, 1); } readexec_opername_saveD7(); $vol = s32(Alis::$varD7); if (!ult($vol, 0x100)) { $vol = 0xff; } xwrite8($e + 0x53, $vol & 0xff); readexec_opername_saveD7(); xwrite16($e + 0x54, 0xff); xwrite8($e + 0x50, 0); xwrite8($e + 0x51, 0x7f); xwrite8($e + 0x52, 0); readexec_opername_saveD7(); $v6put->depx = s32(Alis::$varD7); readexec_opername_saveD7(); $v6put->depy = s32(Alis::$varD7); readexec_opername_saveD7(); $v6put->depz = s32(Alis::$varD7); $v6put->angx = 0; $v6put->angy = 0; $v6put->angz = 0; $v6put->fadddes = 0; if ($p['elem'] > 0) { put_v6($p['elem']); } } // v6 dispatch target for ccancel function ccancel_v6(): void { v6_erase_entry(0); } // v6 dispatch target for ccancall function ccancall_v6(): void { if (Alis::$platform->uid == C::EGameRobinsonsRequiem3DO) { return; } $p1 = ['elem' => 0, 'limit' => 0, 'aux' => 0]; $p2 = ['elem' => 0, 'limit' => 0, 'aux' => 0]; getprot_x($p1); getprot_x($p2); if ($p2['elem'] != 0 && $p1['elem'] > 0) { xwrite32($p1['elem'] + 0x8, $p2['elem']); } } // v6 dispatch target for ccancen function ccancen_v6(): void { $p = ['elem' => 0, 'limit' => 0, 'aux' => 0]; getprot_x($p); if ($p['aux'] != -1) { $tgt = s32($p['elem'] + $p['aux']); readexec_opername_saveD7(); $mvx = s32(Alis::$varD7); readexec_opername_saveD7(); $mvy = s32(Alis::$varD7); readexec_opername_saveD7(); $mvz = s32(Alis::$varD7); xwrite32($tgt + 0x0c, $mvx); xwrite32($tgt + 0x10, $mvy); xwrite32($tgt + 0x14, $mvz); return; } readexec_opername_saveD7(); $x = s32(Alis::$varD7); readexec_opername_saveD7(); $y = s32(Alis::$varD7); readexec_opername_saveD7(); $z = s32(Alis::$varD7); if ($p['elem'] > 0) { $count = xread8($p['elem'] + 0x33); $sp = $p['elem']; for ($i = 0; $i < $count; $i++, $sp = s32($sp + C::V6_SLOT_STRIDE)) { if (v6sp_parent($sp) != Alis::$script->vram_org) { continue; } v6sp_set_depx($sp, $x); v6sp_set_depy($sp, $y); v6sp_set_depz($sp, $z); if (v6sp_state($sp) == 0x30) { xwrite16($sp + 0x48, s16($x)); xwrite16($sp + 0x4a, s16($y)); xwrite16($sp + 0x4c, s16($z)); } v6sp_set_flags($sp, v6sp_flags($sp) | 1); } } } function hibit(int $v): int { $n = -1; $u = s32($v); do { $n++; $u = shr32($u, 1); } while ($u); return $n; } // ARM unrolled 32-bit divide: x/0 yields all ones function udiv_arm(int $num, int $div): int { return $div ? udiv32($num, $div) : -1; } // 3DO OPCODE_CDEFMAP_0xe3 @0001e82c function cdefmap_3do(): void { $vram = Alis::$script->vram_org; $map = read_vaddr(); readexec_opername(); xwrite8($map - 0x400, Alis::$varD7); readexec_opername(); xwrite16($map - 0x3fe, Alis::$varD7); xwrite16($map - 0x3fc, xread16($vram + 0x3a)); readexec_opername(); xwrite16($map - 0x3fa, Alis::$varD7); xwrite16($map - 0x3f8, Alis::$varD7); readexec_opername(); xwrite16($map - 0x3f8, xread16($map - 0x3f8) + Alis::$varD7 - 1); readexec_opername(); xwrite16($map - 0x3f4, Alis::$varD7); readexec_opername(); xwrite16($map - 0x3f2, Alis::$varD7); readexec_opername(); xwrite16($map - 0x3f0, Alis::$varD7); xwrite8($map - 0x3ff, 0); xwrite16($map - 0x3dc, 4); xwrite16($map - 0x3da, 0); xwrite8($map - 0x3d8, 0x7f); // the negative branch never loads r8, which still holds 0x7f from above $num = 0x7f; if (s8(xread8($map - 1)) < 0) { $div = xread32($map - 6); } else { $div = xread16($map - 4) & 0xffff; $num = xread32($map - 8); } xwrite16($map - 0x3c4, $num); xwrite16($map - 0x3ca, udiv_arm($num, $div)); xwrite16($map - 0x3cc, udiv_arm(xread32($map - 0xc), $num)); xwrite16($vram - 0x3b6, 0); xwrite16($map - 0x3c0, hibit(xread16($map - 0x3f4))); xwrite16($map - 0x3be, hibit(xread16($map - 0x3f2))); xwrite16($map - 0x3b8, hibit(xread16($map - 0x3f0))); // the original's "-0x3d8 == 10" screen binding can't fire: -0x3d8 was just set to 0x7f } // v6 dispatch target for ctexmap function ctexmap_v6(): void { Alis::$v6tstpolar = 1; $vram = Alis::$script->vram_org; Alis::$v6tstdx = s16(xread16($vram + 0x26)); Alis::$v6tstdy = s16(xread16($vram + 0x28)); readexec_opername_saveD7(); Alis::$v6walkmode = Alis::$varD7 & 0xff; readexec_opername_saveD7(); Alis::$v6walkc4 = s32(Alis::$varD7); Alis::$v6walkcc = s32(Alis::$varD7); readexec_opername_saveD7(); Alis::$v6walkd0 = s32(Alis::$varD7); readexec_opername_saveD7(); Alis::$v6walkd8 = Alis::$varD7 & 0xff; readexec_opername_saveD7(); Alis::$v6tstmask = Alis::$varD7 & 0xffff; { $p = ['elem' => 0, 'limit' => 0, 'aux' => 0]; getprot_x($p); Alis::$v6walkb8 = $p['elem']; if ($p['elem'] > 0 && xread8($p['elem'] + 0x22) == 0x33) { Alis::$v6walkcc = xread16($p['elem'] + 0x40) & 0xffff; } } V6::$v6wk_cbstep = 1; Alis::$varD7 = v6wk_stepper(); Alis::$v6tstpolar = 0; cstore_continue(); crstent(); } // Codopname no. 234 opcode 0xe9 calloctab function calloctab_v6(int $cell): void { $size = s32(xread32($cell - 8 - xread8($cell - 1) * 4) + 0x800 + 8); $h = io_malloc($size); if ($h == 0) { return; } $blk = xread32($h); mem_set($blk, 0, $size); $pad = s32(((($blk + 8 + 0x7ff) & ~0x7ff) - ($blk + 8))); xwrite32($blk, 8 + $pad); xwrite32($blk + 4, $size); xwrite32($cell, $blk); } function v6_scdark_precalc(int $scr): void { $mode = xread8($scr + 0x94); if ($mode == 1) { $range = xread32($scr + 0x146); $near = s32($range - shr32($range, 2)); xwrite32($scr + 0x16e, $near); xwrite16($scr + 0xae, (xread16($scr + 0x96) & 0xffff) >> 1); $den = s32($range - $near); if ($den == 0) { $den = 1; } xwrite32($scr + 0xaa, intdiv(0x10000, $den)); } else { $range = xread32($scr + 0x146); xwrite32($scr + 0x16e, shr32($range, 2)); xwrite16($scr + 0xae, xread16($scr + 0x96)); xwrite32($scr + 0xaa, 0); } $den = s32(xread32($scr + 0x146) - xread32($scr + 0x16e)); if ($den == 0) { $den = 1; } xwrite32($scr + 0xa6, intdiv(s16(xread16($scr + 0xa0)) << 9, $den)); } // v6 dispatch target for cscdark function cscdark_v6(): void { $scr = s32(Alis::$basemain + (xread16(Alis::$script->vram_org - 0x64) & 0xffff)); readexec_opername_saveD7(); xwrite16($scr + 0x94, Alis::$varD7); readexec_opername_saveD7(); $form = s16(Alis::$varD7); if ($form >= 0) { $form = adresdes(Alis::$varD7); } xwrite32($scr + 0xb0, $form); readexec_opername_saveD7(); xwrite16($scr + 0x96, Alis::$varD7); readexec_opername_saveD7(); xwrite16($scr + 0x98, Alis::$varD7); readexec_opername_saveD7(); xwrite16($scr + 0x9a, Alis::$varD7); readexec_opername_saveD7(); xwrite16($scr + 0x9c, Alis::$varD7); readexec_opername_saveD7(); xwrite16($scr + 0x9e, Alis::$varD7); readexec_opername_saveD7(); xwrite32($scr + 0xa2, s32(Alis::$varD7)); readexec_opername_saveD7(); if (Alis::$platform->uid == C::EGameRobinsonsRequiem3DO) { Alis::$fog3do = Alis::$varD7 & 0xffff; } xwrite16($scr + 0xa0, Alis::$varD7 - s16(xread32($scr + 0xa2))); $cx = s16(xread16($scr + 0x96)); if (xread8($scr + 0x94) == 1) { $cx = shr32($cx, 1); } xwrite32($scr + 0xa2, mul32(xread32($scr + 0xa2), $cx)); xwrite16($scr + 0xa0, s16(mul32(xread16($scr + 0xa0), s16($cx)))); v6_scdark_precalc($scr); readexec_opername_saveD7(); xwrite16($scr + 0xb8, Alis::$varD7); readexec_opername_saveD7(); xwrite16($scr + 0xba, Alis::$varD7); if (Alis::$platform->kind == C::EPlatform3DO || (xread16($scr + 0x94) & 0x200) == 0) { $desc = xread32($scr + 0xb0); $desc = s32($desc + xread32($desc)); if (xread8($desc) == 3) { if (Alis::$platform->kind == C::EPlatform3DO) { node_take(0xb); } v6shad_build3($scr, $desc); } else { xwrite32($scr + 0xb4, $desc); if (Alis::$platform->uid == C::EGameRobinsonsRequiem3DO) { goto done; } $d2 = s32($desc + xread32($desc)); $cx2 = xread16($d2 + 0x12) & 0xffff; xwrite16($scr + 0x96, $cx2); if (s16(xread16($scr + 0x98)) < 0) { $cx2 >>= 1; xwrite16($scr + 0x98, $cx2); } // (C: warns "cscdark v6: non-type-3 land init partially ported") } } done: xwrite8($scr + 0x58, xread8($scr + 0x58) | 0x80); } // v6 dispatch target for caset function caset_v6(): void { $vram = Alis::$script->vram_org; readexec_opername_saveD7(); xwrite16($vram + 0x18, s16(Alis::$varD7 << 8)); readexec_opername_saveD7(); xwrite16($vram + 0x1a, s16(Alis::$varD7 << 8)); readexec_opername_saveD7(); xwrite16($vram + 0x1c, s16(Alis::$varD7 << 8)); xwrite8($vram + 0x45, 1); } // v6 dispatch target for camov function camov_v6(): void { $vram = Alis::$script->vram_org; readexec_opername_saveD7(); xadd16($vram + 0x18, s16(Alis::$varD7 << 8)); readexec_opername_saveD7(); xadd16($vram + 0x1a, s16(Alis::$varD7 << 8)); readexec_opername_saveD7(); xadd16($vram + 0x1c, s16(Alis::$varD7 << 8)); xwrite8($vram + 0x45, 1); } function camovnat(): void { $vram = Alis::$script->vram_org; readexec_opername_saveD7(); xadd16($vram + 0x18, s16(Alis::$varD7)); readexec_opername_saveD7(); xadd16($vram + 0x1a, s16(Alis::$varD7)); readexec_opername_saveD7(); xadd16($vram + 0x1c, s16(Alis::$varD7)); xwrite8($vram + 0x45, 1); } function casetnat(): void { $vram = Alis::$script->vram_org; readexec_opername_saveD7(); xwrite16($vram + 0x18, s16(Alis::$varD7)); readexec_opername_saveD7(); xwrite16($vram + 0x1a, s16(Alis::$varD7)); readexec_opername_saveD7(); xwrite16($vram + 0x1c, s16(Alis::$varD7)); xwrite8($vram + 0x45, 1); } function csetvectnat(): void { $p = ['elem' => 0, 'limit' => 0, 'aux' => 0]; getprot_x($p); if ($p['aux'] != -1) { $slot = s32($p['elem'] + $p['aux']); readexec_opername_saveD7(); xadd16($slot + 0x18, s16(Alis::$varD7)); readexec_opername_saveD7(); xadd16($slot + 0x1a, s16(Alis::$varD7)); readexec_opername_saveD7(); xadd16($slot + 0x1c, s16(Alis::$varD7)); return; } readexec_opername_saveD7(); $ax = s16(Alis::$varD7); readexec_opername_saveD7(); $bx = s16(Alis::$varD7); readexec_opername_saveD7(); $dx = s16(Alis::$varD7); $slot = $p['elem']; $count = xread8($slot + 0x33); for ($i = 0; $i < $count; $i++) { if (xread32($slot + 0x8) == Alis::$script->vram_org) { xadd16($slot + 0x18, $ax); xadd16($slot + 0x1a, $bx); xadd16($slot + 0x1c, $dx); xwrite8($slot + 0x23, xread8($slot + 0x23) | 1); } $slot = s32($slot + C::V6_SLOT_STRIDE); } } function cdefvectnat(): void { $p = ['elem' => 0, 'limit' => 0, 'aux' => 0]; getprot_x($p); if ($p['aux'] != -1) { $slot = s32($p['elem'] + $p['aux']); readexec_opername_saveD7(); xwrite16($slot + 0x18, s16(Alis::$varD7)); readexec_opername_saveD7(); xwrite16($slot + 0x1a, s16(Alis::$varD7)); readexec_opername_saveD7(); xwrite16($slot + 0x1c, s16(Alis::$varD7)); return; } readexec_opername_saveD7(); $ax = s16(Alis::$varD7); readexec_opername_saveD7(); $bx = s16(Alis::$varD7); readexec_opername_saveD7(); $dx = s16(Alis::$varD7); $slot = $p['elem']; $count = xread8($slot + 0x33); for ($i = 0; $i < $count; $i++) { if (xread32($slot + 0x8) == Alis::$script->vram_org) { xwrite16($slot + 0x18, $ax); xwrite16($slot + 0x1a, $bx); xwrite16($slot + 0x1c, $dx); xwrite8($slot + 0x23, xread8($slot + 0x23) | 1); } $slot = s32($slot + C::V6_SLOT_STRIDE); } } // v6 screen camera function v6_defscr(): int { return s32(Alis::$basemain + s16(xread16(Alis::$script->vram_org - 0x64))); } function v6_readxyz(array &$v): void { for ($i = 0; $i < 3; $i++) { readexec_opername(); $v[$i] = s32(Alis::$varD7); } } function v6_scdirty(int $s): void { xwrite8($s + 0x58, xread8($s + 0x58) | 0x80); } // add to camera position (s32 +0xc/+0x10/+0x14) function cscmov_v6(): void { $v = [0, 0, 0]; v6_readxyz($v); $s = v6_defscr(); for ($i = 0; $i < 3; $i++) { if ($v[$i]) { xwrite32($s + 0xc + $i * 4, s32(xread32($s + 0xc + $i * 4) + $v[$i])); v6_scdirty($s); } } } // set camera position function cscset_v6(): void { $v = [0, 0, 0]; v6_readxyz($v); $s = v6_defscr(); for ($i = 0; $i < 3; $i++) { if (xread32($s + 0xc + $i * 4) != $v[$i]) { xwrite32($s + 0xc + $i * 4, $v[$i]); v6_scdirty($s); } } } // add to camera angles function cscamov_v6(): void { $v = [0, 0, 0]; v6_readxyz($v); $s = v6_defscr(); for ($i = 0; $i < 3; $i++) { xwrite16($s + 0x18 + $i * 2, s32(xread16($s + 0x18 + $i * 2) + ($v[$i] << 8))); } v6_scdirty($s); } // set camera angles function cscaset_v6(): void { $v = [0, 0, 0]; v6_readxyz($v); $s = v6_defscr(); for ($i = 0; $i < 3; $i++) { xwrite16($s + 0x18 + $i * 2, $v[$i] << 8); } v6_scdirty($s); } // map reference of the screen function cscmap_v6(): void { readexec_opername(); $owner = s16(xread16(Alis::$script->vram_org + 0x3a)); $off = s16(script_read16()); if ($off == 0) { $owner = 0; $off = s16(script_read16()); } if (s16(xread16(Alis::$script->vram_org - 0x64)) != 0) { $s = v6_defscr(); xwrite16($s + 0xc6, $off); xwrite16($s + 0xc4, $owner); } } // v6 dispatch target for cscfollow function cscfollow_v6(): void { $screen = s32(Alis::$basemain + (xread16(Alis::$script->vram_org - 0x64) & 0xffff)); readexec_opername_saveD7(); $id = s16(Alis::$varD7); readexec_opername_saveD7(); $flw = Alis::$varD7 & 0xffff; readexec_opername_saveD7(); $ox = s32(Alis::$varD7); readexec_opername_saveD7(); $oy = s32(Alis::$varD7); readexec_opername_saveD7(); $oz = s32(Alis::$varD7); readexec_opername_saveD7(); $ax = s16(Alis::$varD7); readexec_opername_saveD7(); $ay = s16(Alis::$varD7); readexec_opername_saveD7(); $az = s16(Alis::$varD7); xwrite16($screen + 0x92, $az); xwrite16($screen + 0x90, $ay); xwrite16($screen + 0x8e, $ax); xwrite32($screen + 0x8a, $oz); xwrite32($screen + 0x86, $oy); xwrite32($screen + 0x82, $ox); xwrite8($screen + 0x80, $flw & 0xff); if (!($flw & 0x100)) { xwrite16($screen + 0x8e, s16(xread16($screen + 0x8e) << 8)); xwrite16($screen + 0x90, s16(xread16($screen + 0x90) << 8)); xwrite16($screen + 0x92, s16(xread16($screen + 0x92) << 8)); } xwrite16($screen + 0x7e, $id); xwrite8($screen + 0x58, xread8($screen + 0x58) | 0x80); } // v6 dispatch target for cwalkmap function cwalkmap_v6(): void { Alis::$v6tstpolar = 1; $vram = Alis::$script->vram_org; Alis::$v6tstdx = s16(xread16($vram + 0x26)); Alis::$v6tstdy = s16(xread16($vram + 0x28)); readexec_opername_saveD7(); Alis::$v6walkmode = Alis::$varD7 & 0xff; readexec_opername_saveD7(); Alis::$v6walkc4 = s32(Alis::$varD7); Alis::$v6walkcc = s32(Alis::$varD7); readexec_opername_saveD7(); Alis::$v6walkd0 = s32(Alis::$varD7); readexec_opername_saveD7(); Alis::$v6walkd8 = Alis::$varD7 & 0xff; readexec_opername_saveD7(); Alis::$v6tstmask = Alis::$varD7 & 0xffff; readexec_opername_saveD7(); Alis::$v6walkb8 = s32(Alis::$varD7); if (Alis::$varD7 != -1) { $desc = adresdes(Alis::$varD7); $fdsc = s32($desc + xread32($desc)); if (xread8($fdsc) == 7) { Alis::$v6walkcc = xread16($fdsc + 0x12) & 0xffff; } } V6::$v6wk_cbstep = 0; Alis::$varD7 = v6wk_stepper(); Alis::$v6tstpolar = 0; cstore_continue(); crstent(); } function v6_mapcell(int $mode): void { $off = s16(script_read16()); $L = Alis::$script->vram_org; if ($off == 0) { $off = s16(script_read16()); $L = Alis::$basemain; } $L = s32($L + $off); if ($mode < 0) { readexec_opername(); $mode = Alis::$varD7; } $d = [0, 0, 0]; for ($i = 0; $i < 3; $i++) { readexec_opername(); $d[$i] = s16(Alis::$varD7); } $vram = Alis::$script->vram_org; $pos = [xread32($vram + 0xc), xread32($vram + 0x10), xread32($vram + 0x14)]; Alis::$varD7 = r3do_cellat($vram, $d[0], $d[1], $d[2], $L, $mode); cstore_continue(); for ($i = 0; $i < 3; $i++) { xwrite32($vram + 0xc + $i * 4, $pos[$i]); } } // v6 dispatch target for cavtstmov function cavtstmov_v6(): void { Alis::$v6tstpolar = 1; v6_tst_from_movevec(); readexec_opername_saveD7(); Alis::$v6tstflag = Alis::$varD7 & 0xff; readexec_opername_saveD7(); Alis::$v6tstmask = Alis::$varD7 & 0xffff; readexec_opername_saveD7(); Alis::$v6tstarg = s32(Alis::$varD7); v6_tstscan(); Alis::$v6tstpolar = 0; crstent(); } function caim_tail(int $dx, int $dy, int $dz): void { $vram = Alis::$script->vram_org; $b1 = $dx; $a1 = $dy; v6wk_atan2($dy, $dx, $b1, $a1); $bearing = s32(-s16($b1)); $b2 = $dz; $a2 = $a1; v6wk_atan2($a1, $dz, $b2, $a2); $dist = $a2; $rx = $b2; $rz = $bearing; if ($dist == 0) { $rz = s16(xread16($vram + 0x1c)); $rx = s16(xread16($vram + 0x18)); } readexec_opername_saveD7(); $rate = shl32(Alis::$varD7, 8); $d = s32($rx - s16(xread16($vram + 0x18))); if ($d <= -0x8000) { $d += 0x10000; } if ($d >= 0x8000) { $d -= 0x10000; } if ($d < 0) { $m = -$d; if ($m >= $rate) { $m = $rate; } $d = -$m; } else { if ($d >= $rate) { $d = $rate; } } $nx = (($d & 0xffff) + (xread16($vram + 0x18) & 0xffff)) & 0xffff; $d = s32($rz - s16(xread16($vram + 0x1c))); if ($d <= -0x8000) { $d += 0x10000; } if ($d >= 0x8000) { $d -= 0x10000; } if ($d < 0) { $m = -$d; if ($m >= $rate) { $m = $rate; } $d = -$m; } else { if ($d >= $rate) { $d = $rate; } } $nz = (($d & 0xffff) + (xread16($vram + 0x1c) & 0xffff)) & 0xffff; Alis::$varD7 = s16($nx) >> 8; cstore_continue(); Alis::$varD7 = s16($nz) >> 8; cstore_continue(); Alis::$varD7 = $dist; cstore_continue(); } // v6 dispatch target for caim function caim_v6(): void { $vram = Alis::$script->vram_org; readexec_opername_saveD7(); $tx = s32(Alis::$varD7); readexec_opername_saveD7(); $ty = s32(Alis::$varD7); readexec_opername_saveD7(); $tz = s32(Alis::$varD7); caim_tail(s32($tx - xread32($vram + 0x0c)), s32($ty - xread32($vram + 0x10)), s32($tz - xread32($vram + 0x14))); } /** C: static u32 prot_elem(const sV6Prot *p) — p is the getprot_x() array */ function prot_elem(array $p): int { return s32($p['elem'] + ($p['aux'] == -1 ? 0 : $p['aux'])); } function v6_xform_point(int $src, int $dst, array &$v): void { $c = new sV6Ctx(); v6tf_build($src, $dst, $c); v6tf_apply($v, $c, $v); } // v6 escape 0x17: getglobal(sel, x, y, z) -> world x, y, z function cgetglobal(): void { $p = ['elem' => 0, 'limit' => 0, 'aux' => 0]; getprot_x($p); $v = [0, 0, 0]; readexec_opername_saveD7(); $v[0] = s32(Alis::$varD7); readexec_opername_saveD7(); $v[1] = s32(Alis::$varD7); readexec_opername_saveD7(); $v[2] = s32(Alis::$varD7); v6_xform_point(prot_elem($p), 0, $v); Alis::$varD7 = $v[0]; cstore_continue(); Alis::$varD7 = $v[1]; cstore_continue(); Alis::$varD7 = $v[2]; cstore_continue(); } // v6 escape 0x18: getlocal(sel, x, y, z, sel2): point of sel in sel2's frame function cgetlocal(): void { $p = ['elem' => 0, 'limit' => 0, 'aux' => 0]; getprot_x($p); $v = [0, 0, 0]; readexec_opername_saveD7(); $v[0] = s32(Alis::$varD7); readexec_opername_saveD7(); $v[1] = s32(Alis::$varD7); readexec_opername_saveD7(); $v[2] = s32(Alis::$varD7); $p2 = ['elem' => 0, 'limit' => 0, 'aux' => 0]; getprot_x($p2); v6_xform_point(prot_elem($p), prot_elem($p2), $v); Alis::$varD7 = $v[0]; cstore_continue(); Alis::$varD7 = $v[1]; cstore_continue(); Alis::$varD7 = $v[2]; cstore_continue(); } // v6 escape 0x23: caim at a target point from an element's world origin function cobjaim(): void { $p = ['elem' => 0, 'limit' => 0, 'aux' => 0]; getprot_x($p); $t = [0, 0, 0]; readexec_opername_saveD7(); $t[0] = s32(Alis::$varD7); readexec_opername_saveD7(); $t[1] = s32(Alis::$varD7); readexec_opername_saveD7(); $t[2] = s32(Alis::$varD7); $g = [0, 0, 0]; v6_xform_point(prot_elem($p), 0, $g); caim_tail(s32($t[0] - $g[0]), s32($t[1] - $g[1]), s32($t[2] - $g[2])); } // 3DO: the first operand is dropped; x/y pick among the land cels function cpointpix_3do(): void { readexec_opername_saveD7(); readexec_opername_saveD7(); $px = s32(Alis::$varD7); readexec_opername_saveD7(); $py = s32(Alis::$varD7); $scr = s32(Alis::$basemain + (xread16(Alis::$script->vram_org - 0x64) & 0xffff)); $w3 = [0, 0, 0]; $aux = 0; $img = 0; $elem = r3do_pick($scr, $px, $py, $w3, $aux, $img); Alis::$varD7 = 0; if (!$elem) { for ($k = 0; $k < 6; $k++) { cstore_continue(); } return; } $dx = s32($w3[0] - xread32($scr + 0x0c)); $dy = s32($w3[1] - xread32($scr + 0x10)); $dz = s32($w3[2] - xread32($scr + 0x14)); $dist = v6x_isqrt(s32(mul32($dx, $dx) + mul32($dy, $dy) + mul32($dz, $dz))); for ($k = 0; $k < 3; $k++) { Alis::$varD7 = $w3[$k]; cstore_continue(); } Alis::$varD7 = s32($dist); cstore_continue(); $tag = s16(xread16($img + 8)); if ($tag == 0) { $tag = s32(shl32(xread16($elem + 0x28) & 0xffff, 16) | (xread16($elem + 0x26) & 0xffff)); } Alis::$varD7 = $tag; cstore_continue(); if ($elem == $scr || xread8($elem + 0x22) == 0x7f) { Alis::$varD7 = ($aux & 0xffff) ? ($aux & 0xffff) : -2; } else { Alis::$varD7 = xread16($elem + 0x2a) & 0xffff; } cstore_continue(); } // v6 dispatch target for cpointpix function cpointpix_v6(): void { if (Alis::$platform->uid == C::EGameRobinsonsRequiem3DO) { cpointpix_3do(); return; } readexec_opername_saveD7(); $px = s32(Alis::$varD7); // pick X readexec_opername_saveD7(); $py = s32(Alis::$varD7); // pick Y readexec_opername_saveD7(); $zmin = s32(Alis::$varD7); // min depth $vram = Alis::$script->vram_org; $scr = s32(Alis::$basemain + (xread16($vram - 0x64) & 0xffff)); $w3 = [0, 0, 0]; $elem = 0; $tg = 0; $dep = 0; $hit = 0; if (Deus3dVars::$v6x3d_heapmoved == 0) { // stale-lists gate $hit = v6x3d_pickwalk($scr, $px, $py, $zmin, $w3, $elem, $tg, $dep); } if ($hit) { $dx = s32($w3[0] - xread32($scr + 0x0c)); // camera delta $dy = s32($w3[1] - xread32($scr + 0x10)); $dz = s32($w3[2] - xread32($scr + 0x14)); $d2 = s32(mul32($dx, $dx) + mul32($dy, $dy) + mul32($dz, $dz)); // wraps (u32 bits) $dist = v6x_isqrt($d2); Alis::$varD7 = $w3[0]; cstore_continue(); // world X Alis::$varD7 = $w3[1]; cstore_continue(); // world Y Alis::$varD7 = $w3[2]; cstore_continue(); // world Z Alis::$varD7 = s32($dist); cstore_continue(); if (($tg & 0xffff) == 0) { $tg = xread32($elem + 0x26); // elem tag } Alis::$varD7 = s32($tg); cstore_continue(); Alis::$varD7 = xread16($elem + 0x2a) & 0xffff; // owner entity id cstore_continue(); } else { Alis::$varD7 = 0; for ($k = 0; $k < 6; $k++) { cstore_continue(); } } } // v6 dispatch target for cscsky function cscsky_v6(): void { if (Alis::$platform->uid == C::EGameRobinsonsRequiem3DO) { // 3DO: mode, sky form, angle (3DO land view draws no sky, fog fill) for ($i = 0; $i < 3; $i++) { readexec_opername(); } return; } $scr = s32(Alis::$basemain + (xread16(Alis::$script->vram_org - 0x64) & 0xffff)); readexec_opername_saveD7(); xwrite16($scr + 0x116, Alis::$varD7 & 0xffff); // sky mode readexec_opername_saveD7(); $form = s16(Alis::$varD7); xwrite16($scr + 0x122, $form & 0xffff); // sky form number xwrite16($scr + 0x124, xread16(Alis::$script->vram_org + 0x3a)); $entry = adresdes($form); xwrite32($scr + 0x118, $entry); readexec_opername_saveD7(); xwrite32($scr + 0x11c, Alis::$varD7); // param dword readexec_opername_saveD7(); $scale = s32(Alis::$varD7); $res = s32($entry + xread32($entry)); xwrite16($scr + 0x120, intdiv(mul32(s16(xread16($res + 0x10)), $scale), 0x1000) & 0xffff); xwrite8($scr + 0x58, xread8($scr + 0x58) | 0x80); // redraw } // v6 dispatch target for czoom function czoom_v6(): void { $p = ['elem' => 0, 'limit' => 0, 'aux' => 0]; getprot_x($p); if ($p['aux'] != -1) { readexec_opername_saveD7(); xwrite16(s32($p['elem'] + $p['aux'] + 0x1e), Alis::$varD7); return; } readexec_opername_saveD7(); $slot = $p['elem']; $count = xread8($slot + 0x33); if (Alis::$platform->uid == C::EGameRobinsonsRequiem3DO) { if ($count == 0) { xwrite16($slot + 0x1e, Alis::$varD7); return; } for (; $count; $count--, $slot = s32($slot + C::V6_SLOT_STRIDE)) { if (xread32($slot + 0x8) == Alis::$script->vram_org) { xwrite16($slot + 0x1e, Alis::$varD7); } } return; } for ($i = 0; $i < $count; $i++) { if (xread32($slot + 0x8) == Alis::$script->vram_org) { xwrite16($slot + 0x1e, Alis::$varD7); } $slot = s32($slot + C::V6_SLOT_STRIDE); } } // v6 dispatch target for cret function cret_v6(): void { if (Alis::$fseq == 0 && s16(Alis::$script->vacc_off) >= s16(Alis::$saversp)) { cstop(); return; } $di = s16(Alis::$script->vacc_off); Alis::$script->pc = s32(Alis::$script->pc_org + xread32(Alis::$script->vram_org + $di)); if ($di == s16(xread16(Alis::$script->vram_org - 0x7c))) { xwrite16(Alis::$script->vram_org - 0x7c, 0); } Alis::$script->vacc_off = s16($di + 4); } // v6 dispatch target for cjmp24 function read_off24_v6(): int { if (Alis::$platform->is_little_endian) { $offset = s16(script_read16()); script_read8(); return $offset; } script_read8(); return s16(script_read16()); } function cjmp24_v6(): void { $offset = read_off24_v6(); Alis::$script->pc += $offset; } // v6 dispatch target for cbz24 function cbz24_v6(): void { $d7 = bztest(); if ($d7 == 0) { Alis::$script->pc += read_off24_v6(); } else { Alis::$script->pc += 3; } } // v6 dispatch target for cbnz24 function cbnz24_v6(): void { $d7 = bztest(); if ($d7 != 0) { Alis::$script->pc += read_off24_v6(); } else { Alis::$script->pc += 3; } } // Codopname cstart (0x5? cstart8/16/24): body of the `version >= 60` block function cstart_v6branch(int $offset): void { $vram = Alis::$script->vram_org; $marker = s16(xread16($vram - 0x7c)); if (Alis::$fseq == 0) { if ($marker == 0) { $marker = s16(Alis::$saversp); xwrite16($vram - 0x7c, $marker); xwrite32($vram - 0x80, s32(get_0x08_script_ret_offset($vram) - Alis::$script->pc_org)); } $slot = s16($marker - 4); Alis::$saversp = $slot & 0xffff; xwrite32($vram + $slot, xread32($vram - 0x80)); set_0x08_script_ret_offset($vram, s32(Alis::$script->pc + $offset)); set_0x04_cstart_csleep($vram, 1); set_0x3e_wait_time($vram, 0); } else { if ($marker == 0) { xwrite32($vram - 0x80, s32(Alis::$script->pc - Alis::$script->pc_org)); $marker = s16(Alis::$script->vacc_off); xwrite16($vram - 0x7c, $marker); } $slot = s16($marker - 4); Alis::$script->vacc_off = $slot; xwrite32($vram + $slot, xread32($vram - 0x80)); Alis::$script->pc += $offset; } } function v6_relocate_vram(int $blockstart, int $shrinkby): void { for ($w = V6::$defworld_list_head; $w != 0; $w = xread32($w + 0xb4)) { $node = $w; for (;;) { $next = xread32($node + 0x38); if (!ult($next, $blockstart)) { xwrite32($node + 0x38, s32($next - $shrinkby)); } $prev = xread32($node + 0x34); if (!ult($prev, $blockstart)) { xwrite32($node + 0x34, s32($prev - $shrinkby)); } $par = xread32($node + 0x8); if (!ult($par, $blockstart)) { xwrite32($node + 0x8, s32($par - $shrinkby)); } if ($node == $next) { break; } $node = $next; } } for ($i = 0; $i < 512; $i++) { // MAX_SCRIPTS $s = Alis::$live_scripts[$i]; if ($s === null || ult($s->vram_org, $blockstart)) { continue; } $node = v6_elemhead($s->vram_org); for (;;) { $next = v6el_next($node); if (!ult($next, $blockstart)) { v6el_set_next($node, s32($next - $shrinkby)); } $prev = v6el_prev($node); if (!ult($prev, $blockstart)) { v6el_set_prev($node, s32($prev - $shrinkby)); } if ($node == $next) { break; } $node = $next; } } } // pointers into (lo, hi) move by delta, fonts in the removed range below lo are dropped function v6_relocate_prog(int $lo, int $hi, int $delta): void { for ($w = V6::$defworld_list_head; $w != 0; $w = xread32($w + 0xb4)) { for ($e = xread32($w + 0x38); $e != xread32($e + 0x38); $e = xread32($e + 0x38)) { if ((xread8($e + 0x24) & 0x40) || v6sp_state($e) == 0x38) { // '8' continue; } $p = xread32($e + 0x50); if ((v6sp_state($e) == 0x30 || v6sp_state($e) == 0x3a) && !ult($p, $lo) && ult($p, $hi)) { // '0' / ':' xwrite32($e + 0x50, s32($p + $delta)); } $p = xread32($e + 0x3c); if (!ult($p, $lo) && ult($p, $hi)) { xwrite32($e + 0x3c, s32($p + $delta)); } } } for ($i = 0; $i < 16; $i++) { $g = Alis::$v6xfonts[$i]['glyphslot'] ?? 0; if (!ult($g, $lo) && ult($g, $hi)) { Alis::$v6xfonts[$i]['glyphslot'] = s32($g + $delta); } elseif ($delta < 0 && !ult($g, s32($lo + $delta)) && ult($g, $lo)) { Alis::$v6xfonts[$i]['glyphslot'] = 0; } } } function v6_dormant(int $ent, int $org, int $end): void { $s = ENTSCR($ent & 0xffff); $vram = $s->vram_org; $fl = xread8(V6_FARSLEEP($vram)); if ($fl & AlisV6Const::V6_DORMANT) { return; } xwrite8(V6_FARSLEEP($vram), $fl | AlisV6Const::V6_DORMANT); for ($e = v6el_next(v6_elemhead($vram)); $e != v6el_next($e); $e = v6el_next($e)) { $sp = $e; for ($i = xread8($e + 0x33); $i != 0; $i--, $sp = s32($sp + C::V6_SLOT_STRIDE)) { $p = xread32($sp + 0x3c); if (!ult($p, $org) && ult($p, $end)) { xwrite8($sp + 0x24, xread8($sp + 0x24) | 0x40); } } } $s->data = null; } function v6_wake(int $ent, ScriptData $prog): void { $s = ENTSCR($ent & 0xffff); $vram = $s->vram_org; $fl = xread8(V6_FARSLEEP($vram)); if (!($fl & AlisV6Const::V6_DORMANT)) { return; } xwrite8(V6_FARSLEEP($vram), $fl & ~AlisV6Const::V6_DORMANT & 0xff); $d = s32($prog->data_org - get_0x14_script_org_offset($vram)); set_0x14_script_org_offset($vram, $prog->data_org); set_0x08_script_ret_offset($vram, s32(get_0x08_script_ret_offset($vram) + $d)); $s->pc = s32($s->pc + $d); $s->pc_org = s32($s->pc_org + $d); $s->data = $prog; $s->name = $prog->name; for ($e = v6el_next(v6_elemhead($vram)); $e != v6el_next($e); $e = v6el_next($e)) { $sp = $e; for ($i = xread8($e + 0x33); $i != 0; $i--, $sp = s32($sp + C::V6_SLOT_STRIDE)) { if (!(xread8($sp + 0x24) & 0x40)) { continue; } if (xread32($sp + 0x3c) != 0) { xwrite32($sp + 0x3c, s32(xread32($sp + 0x3c) + $d)); } if (v6sp_state($sp) == 0x30 || v6sp_state($sp) == 0x3a) { // '0' / ':' xwrite32($sp + 0x50, s32(xread32($sp + 0x50) + $d)); } xwrite8($sp + 0x24, xread8($sp + 0x24) & 0xbf); } } } function v6_wakeall(int $n): void { $n &= 0xffff; $prog = node_prog($n); if ($prog === null || Alis::$platform->kind == C::EPlatform3DO) { return; } for ($e = xread16(Alis::$atent + 4) & 0xffff; $e != 0; $e = xread16(Alis::$atent + $e + 4) & 0xffff) { if (mem_cmp(s32(xread32(Alis::$atent + $e) + 0x3c), Alis::$atent + $n + 6, 8) == 0) { v6_wake($e, $prog); } } } /** C: void v6_unloadprog(const char *name, s32 mode) — name: PHP string (or offset, see node_name_str) */ function v6_unloadprog(int|string $name, int $mode): void { if (($mode & 0x100) && Alis::$platform->kind != C::EPlatform3DO) { for ($n = xread16(Alis::$atent + C::NODE_BLKHEAD + 0xe) & 0xffff; $n != C::NODE_BLKTAIL; $n = xread16(Alis::$atent + $n + 0xe) & 0xffff) { $t = xread8(Alis::$atent + $n + 0x15); if ($t != 2 && $t != 0xc && $t != 0xd) { continue; } $raw = substr(Alis::$mem, Alis::$atent + $n + 6, 8); // char nm[9] = {0}; memcpy(nm, .., 8) if ($raw === "main\0\0\0\0") { continue; } $z = strpos($raw, "\0"); $nm = $z === false ? $raw : substr($raw, 0, $z); v6_unloadprog($nm, $mode & 0xff); if (Alis::$restart_loop) { return; } } return; } $m = $mode & 0xff; $n = node_find($name); if ($n == 0) { return; } if (Alis::$platform->kind != C::EPlatform3DO) { Deus3dVars::$v6x3d_heapmoved = 1; } $prog = node_prog($n); $org = $prog ? $prog->data_org : 0; $end = Alis::$finprog; for ($i = 0; $prog && $i < Alis::$nbprog; $i++) { if (ult($org, ATPROG($i)) && ult(ATPROG($i), $end)) { $end = ATPROG($i); } } for ($e = xread16(Alis::$atent + 4) & 0xffff; $e != 0; $e = xread16(Alis::$atent + $e + 4) & 0xffff) { if (mem_cmp(s32(xread32(Alis::$atent + $e) + 0x3c), Alis::$atent + $n + 6, 8) != 0) { continue; } Alis::$ferase = 0; if ($m == 2) { if ($prog) { v6_dormant($e, $org, $end); } continue; } if ($m != 1) { Alis::$ferase = 1; } killent($e); if (Alis::$restart_loop) { return; } } if ($prog) { // NOTE: interuptable delay to make everything work more like on original platforms sys_sleep_interactive(Alis::$unload_delay, Alis::$unload_delay - 100); shrinkprog($org, s32($end - $org), $prog->header->id); } v6text_free($n); node_free($n); } function v6_growent(int $need): int { $top = v6_enttop(); if (!ult($top, s32(Alis::$finent + $need))) { return 1; } $d = s32(Alis::$finent + $need - $top + 0xffff) & ~0xffff; if (ult(Alis::$finmem, s32(Alis::$finprog + $d))) { $d = s32(Alis::$finent + $need - $top + 0xf) & ~0xf; } if (ult(Alis::$finmem, s32(Alis::$finprog + $d))) { return 0; } $fin = Alis::$finprog; v6_relocate_prog($top, $fin, $d); mem_move(s32($top + $d), $top, s32($fin - $top)); Alis::$finprog = s32(Alis::$finprog + $d); Alis::$debprog = s32(Alis::$debprog + $d); Alis::$specs->max_allocatable_vram = s32(Alis::$specs->max_allocatable_vram + $d); if (Alis::$desmouse && Alis::$desmouse >= $top && Alis::$desmouse < $fin) { Alis::$desmouse += $d; } audio_relocate($top, $top, $d); Deus3dVars::$v6x3d_heapmoved = 1; for ($i = 0; $i < Alis::$nbprog; $i++) { if (!ult(Alis::$loaded_scripts[$i]->data_org, $top)) { Alis::$loaded_scripts[$i]->data_org = s32(Alis::$loaded_scripts[$i]->data_org + $d); ATPROG_SET($i, s32(ATPROG($i) + $d)); } } // dormant entities rebase on wake (v6_wake) for ($e = xread16(Alis::$atent + 4) & 0xffff; $e != 0; $e = xread16(Alis::$atent + $e + 4) & 0xffff) { $sc = ENTSCR($e); $vram = $sc->vram_org; if ((xread8(V6_FARSLEEP($vram)) & AlisV6Const::V6_DORMANT) || ult(get_0x14_script_org_offset($vram), $top)) { continue; } $sc->pc = s32($sc->pc + $d); $sc->pc_org = s32($sc->pc_org + $d); set_0x14_script_org_offset($vram, s32(get_0x14_script_org_offset($vram) + $d)); set_0x08_script_ret_offset($vram, s32(get_0x08_script_ret_offset($vram) + $d)); } return 1; } // ============================================================================ // v6 selects a different TABLE rather than branching inside each handler: only the entries that // differ from opcodes[] are listed (C: static const sAlisOpcode opcodes_v6_ov[]). // ============================================================================ /** C: opcodes_v6_ov[] — code => [callable, C name], in C order. Applied by alis_tab_opcodes(). */ function table_opcodes_v6_ov(): array { return [ 0x0a => [cjmp24_v6(...), 'cjmp24_v6'], // v6: cjmp24 0x11 => [cret_v6(...), 'cret_v6'], // v6: cret 0x14 => [cbz24_v6(...), 'cbz24_v6'], // v6: cbz24 0x17 => [cbnz24_v6(...), 'cbnz24_v6'], // v6: cbnz24 0x33 => [cleave_v6(...), 'cleave_v6'], // v6: cleave 0x38 => [cscmov_v6(...), 'cscmov_v6'], // v6: cscmov 0x39 => [cscset_v6(...), 'cscset_v6'], // v6: cscset 0x43 => [cstopret_v6(...), 'cstopret_v6'], // v6: cstopret 0x44 => [cexit_v6(...), 'cexit_v6'], // v6: cexit 0x4b => [cerasen_v6(...), 'cerasen_v6'], // v6: cerasen 0x51 => [cforme_v6(...), 'cforme_v6'], // v6: cforme 0x52 => [cdelforme_v6(...), 'cdelforme_v6'], // v6: cdelforme 0x53 => [ctstmov_v6(...), 'ctstmov_v6'], // v6: ctstmov 0x54 => [ctstset_v6(...), 'ctstset_v6'], // v6: ctstset 0x55 => [cftstmov_v6(...), 'cftstmov_v6'], // v6: cftstmov 0x56 => [cftstset_v6(...), 'cftstset_v6'], // v6: cftstset 0x61 => [csend_v6(...), 'csend_v6'], // v6: csend 0x66 => [cscanclr_v6(...), 'cscanclr_v6'], // v6: cscanclr 0x74 => [cfreadv_v6(...), 'cfreadv_v6'], // v6: cfreadv 0x81 => [cpicture_v6(...), 'cpicture_v6'], // v6: cpicture 0x89 => [cdefvect_v6(...), 'cdefvect_v6'], // v6: cdefvect 0x8a => [csetvect_v6(...), 'csetvect_v6'], // v6: csetvect 0x8e => [cvtstmov_v6(...), 'cvtstmov_v6'], // v6: cvtstmov 0x8f => [cvftstmov_v6(...), 'cvftstmov_v6'], // v6: cvftstmov 0x93 => [cfindmat_v6(...), 'cfindmat_v6'], // v6: cfindmat 0x98 => [csetvolum_v6(...), 'csetvolum_v6'], // v6: csetvolum 0xa1 => [cdelsound_v6(...), 'cdelsound_v6'], // v6: cdelsound 0xa3 => [cwtstmov_v6(...), 'cwtstmov_v6'], // v6: cwtstmov 0xa4 => [cwftstmov_v6(...), 'cwftstmov_v6'], // v6: cwftstmov 0xa5 => [ctstform_v6(...), 'ctstform_v6'], // v6: ctstform 0xa6 => [cxput_v6(...), 'cxput_v6'], // v6: cxput 0xa7 => [cxputat_v6(...), 'cxputat_v6'], // v6: cxputat 0xa8 => [cmput_v6(...), 'cmput_v6'], // v6: cmput 0xa9 => [cmputat_v6(...), 'cmputat_v6'], // v6: cmputat 0xaa => [cmxput_v6(...), 'cmxput_v6'], // v6: cmxput 0xab => [cmxputat_v6(...), 'cmxputat_v6'], // v6: cmxputat 0xba => [cfont_v6(...), 'cfont_v6'], // v6: cfont 0xc3 => [cschoriz_v6(...), 'cschoriz_v6'], // v6: cschoriz 0xc7 => [creducing_v6(...), 'creducing_v6'], // v6: creducing 0xc8 => [cscmap_v6(...), 'cscmap_v6'], // v6: cscmap 0xc9 => [cscdump_v6(...), 'cscdump_v6'], // v6: cscdump 0xd0 => [calign_v6(...), 'calign_v6'], // v6: calign 0xdb => [ccancel_v6(...), 'ccancel_v6'], // v6: ccancel 0xdc => [ccancall_v6(...), 'ccancall_v6'], // v6: ccancall 0xdd => [ccancen_v6(...), 'ccancen_v6'], // v6: ccancen 0xe8 => [ctexmap_v6(...), 'ctexmap_v6'], // v6: ctexmap 0xef => [cscdark_v6(...), 'cscdark_v6'], // v6: cscdark 0xf0 => [caset_v6(...), 'caset_v6'], // v6: caset 0xf1 => [camov_v6(...), 'camov_v6'], // v6: camov 0xf2 => [cscaset_v6(...), 'cscaset_v6'], // v6: cscaset 0xf3 => [cscamov_v6(...), 'cscamov_v6'], // v6: cscamov 0xf4 => [cscfollow_v6(...), 'cscfollow_v6'], // v6: cscfollow 0xf7 => [cwalkmap_v6(...), 'cwalkmap_v6'], // v6: cwalkmap 0xf9 => [cavtstmov_v6(...), 'cavtstmov_v6'], // v6: cavtstmov 0xfb => [caim_v6(...), 'caim_v6'], // v6: caim 0xfc => [cpointpix_v6(...), 'cpointpix_v6'], // v6: cpointpix 0xfe => [cscsky_v6(...), 'cscsky_v6'], // v6: cscsky 0xff => [czoom_v6(...), 'czoom_v6'], // v6: czoom ]; }