<?phpnamespace App\Alis;// Port of alis/src/escnames.c (MIT, Olivier Huguenot, Vadim Kindl).// Scope: the pre-v6 escape tables (codesc1names: sound/music switches and the FLI film opcodes,// codesc2names, codesc3names). The v40+/v6 escape-1 handlers are in escnames_v6.php.// ============================================================================// Codesc1 routines// ============================================================================// Codesc1name no. 01 opcode 0x00 cnul// Calls stub cnul// Codesc1name no. 02 opcode 0x01 csoundon// Known as consound in c-filefunction csoundon(): void{ Aud::$fsound = 1;}// Codesc1name no. 03 opcode 0x02 csoundoff// Known as coffsound in c-filefunction csoundoff(): void{ Aud::$fsound = 0;}// Codesc1name no. 04 opcode 0x03 cmusicon// Known as conmusic in c-filefunction cmusicon(): void{ Aud::$fmusic = 1;}// Codesc1name no. 05 opcode 0x04 cmusicoff// Known as coffmusic in c-filefunction cmusicoff(): void{ Aud::$fmusic = 0;}// Codesc1name no. 06 opcode 0x05 cdelfilmfunction cdelfilm(): void{ film_check_boot(); if (Alis::$platform->uid == C::EGameRobinsonsRequiem3DO) { return; // a stub on 3DO (crunfilm already closed the stream) } endfilm(); fli_stream_close(); // close the streaming file handle (no-op in whole-file mode) if (FilmVars::$bfilm->delptr !== null) { FilmVars::$data = ''; // free(bfilm.delptr) FilmVars::$src = null; } film_reset(); if (Alis::$platform->version >= 60) { node_free(Alis::$filmnode); Alis::$filmnode = 0; }}// Codesc1name no. 07 opcode 0x06 copenfilm// PORT: the film file goes to FilmVars::$data (not malloc); films over FilmConst::kFilmStreamAbove bytes are// streamed (fli_stream_open), as the C does when the malloc of the whole file fails.function copenfilm(): void{ film_check_boot(); if (Alis::$platform->uid == C::EGameRobinsonsRequiem3DO) { // 3DO only names the stream here; crunfilm plays it. Stores 0. readexec_opername(); readexec_opername_swap(); $name = mem_str(Alis::$sd7); $path = ($name === '' || $name[0] != '/') ? Alis::$platform->path : ''; film3do_open($path . $name); readexec_opername(); readexec_opername(); Alis::$varD7 = 0; cstore_continue(); return; } fli_stream_close(); // stale streaming film (script skipped cdelfilm): don't leak the handle film_reset(); if (Alis::$platform->version >= 60) { node_free(Alis::$filmnode); // close the open film first Alis::$filmnode = 0; } readexec_opername(); FilmVars::$bfilm->id = s16(Alis::$varD7); readexec_opername_swap(); Alis::$fp = null; // The one CD carries both "150." (smaller, Falcon-sized) and "300." (fullscreen) video // variants; this remaps 150 -> 300 to force the fullscreen version. $at = strpos(mem_str(Alis::$sd7), '150.'); if ($at !== false) { film_mem_poke(Alis::$sd7 + $at, '300.', 4); } $path = Alis::$platform->path . mem_str(Alis::$sd7); afopen($path, 1); $addr = null; if (Alis::$fp) { $size = (int) (fstat(Alis::$fp)['size'] ?? 0); if ($size <= FilmConst::kFilmStreamAbove) { film_set_data((string) stream_get_contents(Alis::$fp)); FilmVars::$src = ['file', $path]; $addr = 0; } elseif (fli_stream_open(Alis::$fp, $size)) { // fli_stream_open takes ownership of the file handle. FilmVars::$src = ['file', $path]; $addr = FilmVars::$bfilm->sbuf; Alis::$fp = null; } } if (Alis::$platform->version >= 60 && $addr !== null) { Alis::$filmnode = node_take(0xb); // film buffer } $bf = FilmVars::$bfilm; $bf->addr1 = $addr; $bf->addr2 = $addr; $bf->delptr = $addr; // TODO: not realy sure what next value is used for readexec_opername(); readexec_opername(); $bf->waitclock = s16(Alis::$varD7); // DOS v3: the film window is the current script's screen record (basemain + screen id, 0x8eb3) $bf->basemain = Alis::$basemain + (Alis::$platform->version < 60 ? s16(get_0x16_screen_id(Alis::$script->vram_org)) : 0); inifilm(); Alis::$varD7 = FilmVars::$bfilm->frames; cstore_continue();}// ============================================================================// Codesc1 routines pointer table (pre-v6)// ============================================================================function table_codesc1names(): array{ Tables::$names['codesc1names'] = ['cnul', 'csoundon', 'csoundoff', 'cmusicon', 'cmusicoff', 'cdelfilm', 'copenfilm']; return [ cnul(...), csoundon(...), csoundoff(...), cmusicon(...), cmusicoff(...), cdelfilm(...), copenfilm(...), ];}// ============================================================================// Codesc2 routines pointer table// ============================================================================function table_codesc2names(): array{ Tables::$names['codesc2names'] = ['cnul']; return [ cnul(...), ];}// ============================================================================// Codesc3 routines pointer table// ============================================================================function table_codesc3names(): array{ Tables::$names['codesc3names'] = ['cnul']; return [ cnul(...), ];}// ============================================================================// v6 resident text blocks (.to files). Kept because unloadprog (opcodes.c) calls v6text_free and// the savestate restore (alis.c) calls v6text_reload; before v6 no block is ever loaded// (Alis::$v6texts[i]['node'] stays 0), so both are no-ops there.// Alis::$v6texts[i] = ['node' => u16, 'sz' => u32, 'data' => host offset in Alis::$mem or 0].// ============================================================================// Codesc1name no. 009 opcode 0x08 cloadtext: reads <path><name>.to (name part lowercased).// Returns the host offset of the data (NUL terminated) or 0; $sz receives its size.function text_read(string $name, int &$sz): int{ $path = Alis::$platform->path . strtolower($name . '.to'); // PORT: the C uses a plain fopen(path, "rb"); routed through sys_fopen() (host layer). $fp = sys_fopen($path, 'rb'); if (!$fp) { return 0; } fseek($fp, 0, SEEK_END); $len = ftell($fp); rewind($fp); $data = host_alloc($len + 1); $bytes = $len > 0 ? fread($fp, $len) : ''; if ($bytes === false) { $bytes = ''; } $rd = strlen($bytes); mem_write($data, $bytes); Alis::$mem[$data + $rd] = "\0"; $sz = $rd; fclose($fp); return $data;}// v6 resident text of block n (0 if none)function v6text_get(int $n, int &$sz): int{ for ($i = 0; $n && $i < 8; $i++) { if ((Alis::$v6texts[$i]['node'] ?? 0) == $n) { $sz = Alis::$v6texts[$i]['sz']; return Alis::$v6texts[$i]['data']; } } return 0;}// unloadprog freed text block nfunction v6text_free(int $n): void{ for ($i = 0; $n && $i < 8; $i++) { if ((Alis::$v6texts[$i]['node'] ?? 0) == $n) { host_free(Alis::$v6texts[$i]['data'] ?? 0); Alis::$v6texts[$i] = ['node' => 0, 'sz' => 0, 'data' => 0]; } }}// savestate restore: host buffers are gone, reread them by block namefunction v6text_reload(): void{ for ($i = 0; $i < 8; $i++) { Alis::$v6texts[$i]['data'] = 0; if ((Alis::$v6texts[$i]['node'] ?? 0) == 0) { continue; } $raw = mem_read(Alis::$atent + Alis::$v6texts[$i]['node'] + 6, 8); $nul = strpos($raw, "\0"); $name = $nul === false ? $raw : substr($raw, 0, $nul); $sz = Alis::$v6texts[$i]['sz'] ?? 0; Alis::$v6texts[$i]['data'] = text_read($name, $sz); Alis::$v6texts[$i]['sz'] = $sz; }}// v6text_load and the v6.0+ (v40+) escape-1 handlers (codesc1names_v40, version >= 60): fn/escnames_v6.php.// camovnat, csetvectnat, casetnat, cdefvectnat, cgetglobal, cgetlocal, cobjaim live in opcodes.c.// ============================================================================// Codesc1 routines pointer table, v40+ (v6) version: selected by alis_init for version >= 60 only.// ============================================================================function table_codesc1names_v40(): array{ $names = [ 'cnul', 'csoundon', 'csoundoff', 'cmusicon', 'cmusicoff', 'cdelfilm', 'copenfilm', 'cdeffont', 'cloadtext', 'cafteron', 'cafteroff', 'cbeforon', 'cbeforoff', 'cscfocale', 'csccamera', 'ctexmap', 'cscrender', 'cvideo', 'ctexture', 'cplaycd', 'camovnat', 'csetvectnat', 'conscreen', 'cgetglobal', 'cgetlocal', 'cmatitem', 'cmaskitem', 'cdefitem', 'casetnat', 'cdefvectnat', 'cgetmap', 'cconvmap', 'csetfilm', 'cscmem', 'cmapcell', 'cobjaim', 'cloadpic', 'cputpic', 'cfwriteg', 'cfreadg', 'cobjmat', 'cobjmask', 'cscclut', 'cobjclut', 'copennet', 'cclosenet', 'csendnet', 'cmailnet', 'cplayernet', 'cgamenet', 'csyncnet', 'ctexitem', 'cgetanim', 'canimsize', 'cscmath', 'cintermode', 'csysnet', 'cobjshad', 'csphere', 'cscdark', 'cagetlocal', 'cfollow', 'cplayfilm', 'csoundtime', 'cinfoitem', 'cmorph', 'cscmicro', 'cptrset', 'cdefproc', 'cfreadm', 'cfwritem', 'cmaskent', 'cvram', 'cadresnet', 'cfdir', 'cnul', 'cloadas', 'cfindobjitem', 'cobjid', 'cgetobjid', 'cprelight', 'croomdoor', ]; $t = [ cnul(...), csoundon(...), csoundoff(...), cmusicon(...), cmusicoff(...), cdelfilm(...), copenfilm(...), cdeffont(...), cloadtext(...), cafteron(...), cafteroff(...), cbeforon(...), cbeforoff(...), cscfocale(...), csccamera(...), esc_ctexmap(...), cscrender(...), cvideo(...), ctexture(...), cplaycd(...), camovnat(...), csetvectnat(...), conscreen(...), cgetglobal(...), cgetlocal(...), cmatitem(...), cmaskitem(...), cdefitem(...), casetnat(...), cdefvectnat(...), cgetmap(...), cconvmap(...), csetfilm(...), cscmem(...), cmapcell(...), cobjaim(...), cloadpic(...), cputpic(...), cfwriteg(...), cfreadg(...), cobjmat(...), cobjmask(...), cscclut(...), cobjclut(...), copennet(...), cclosenet(...), csendnet(...), cmailnet(...), cplayernet(...), cgamenet(...), csyncnet(...), ctexitem(...), cgetanim(...), canimsize(...), cscmath(...), cintermode(...), csysnet(...), cobjshad(...), csphere(...), esc_cscdark(...), cagetlocal(...), cfollow(...), cplayfilm(...), csoundtime(...), cinfoitem(...), cmorph(...), cscmicro(...), cptrset(...), cdefproc(...), cfreadm(...), cfwritem(...), cmaskent(...), cvram(...), cadresnet(...), cfdir(...), cnul(...), cloadas(...), cfindobjitem(...), cobjid(...), cgetobjid(...), cprelight(...), croomdoor(...), ]; Tables::$names['codesc1names_v40'] = $names; return $t;}