/* CTL3D file probing and Pascal unit initialization from Code3. */ #include "tdkpin_multimedia.h" #include "tdkpin_borland_files.h" #include "tdkpin_borland_records.h" #include "tdkpin_shortstrings.h" #include "tdkpin_strings.h" extern Win16FarPtr g_multimedia_procedures[11]; /* 1028:4750..477b */ extern HINSTANCE16 g_multimedia_module; /* 1028:4781 */ extern uint8_t g_multimedia_initialized; /* 1028:4784 */ enum { DGROUP_CTL3D_DLL = 0x0522, DGROUP_CTL3DV2_DLL = 0x052c, DGROUP_MULTIMEDIA_LIBRARY_PATH = 0x478d, DGROUP_SYSTEM_DIRECTORY = 0x47a4, DGROUP_CTL3D_FULL_SHORT = 0x486d, DGROUP_CTL3DV2_FULL_SHORT = 0x496d, }; /* * 1010:0405 -- existence probe for one Pascal ShortString path. A failed * open is consumed through IOResult and reported false. A successful open is * closed, and any close failure follows the original RuntimeError path. */ bool multimedia_short_file_exists(Win16FarPtr short_name) { uint8_t copied_name[256]; uint8_t length = win16_read_u8(short_name); copied_name[0] = length; for (uint16_t index = 0; index < length; index++) { copied_name[index + 1] = win16_read_u8( win16_far_add_offset(short_name, (uint16_t)(index + 1))); } uint8_t record_bytes[128]; Win16FarPtr copied_name_far = win16_stack_pointer(copied_name); Win16FarPtr record = win16_stack_pointer(record_bytes); borland_assign_file_short(copied_name_far, record); borland_open_generic_file(1, record); if (borland_take_io_result() != 0) { return false; } borland_close_generic_file(record); borland_require_io_success(); return true; } static void construct_system_path( Win16FarPtr destination, Win16FarPtr file_name, Win16FarPtr temporary_directory, Win16FarPtr temporary_file) { borland_c_to_short_string( temporary_directory, win16_dgroup_pointer(DGROUP_SYSTEM_DIRECTORY)); borland_short_concat( temporary_directory, win16_relocated_code_pointer(3, 0x0470)); borland_c_to_short_string(temporary_file, file_name); borland_short_concat(temporary_directory, temporary_file); borland_short_assign_truncated( destination, temporary_directory, 0xff); } /* * 1010:0472 -- initialize all CTL3D unit state and Windows-version policy. * The two 256-byte temporaries are Pascal ShortStrings. The system-directory * paths remain ShortStrings at 486d/496d; only the selected DLL basename at * 478d is converted back to a NUL-terminated C string for LoadLibrary. */ void multimedia_initialize_runtime_unit(void) { g_multimedia_system_directory_length = GetSystemDirectoryFar16( win16_dgroup_pointer(DGROUP_SYSTEM_DIRECTORY), 200); uint8_t directory_short[256]; uint8_t file_short[256]; Win16FarPtr directory = win16_stack_pointer(directory_short); Win16FarPtr file = win16_stack_pointer(file_short); construct_system_path( win16_dgroup_pointer(DGROUP_CTL3D_FULL_SHORT), win16_dgroup_pointer(DGROUP_CTL3D_DLL), directory, file); construct_system_path( win16_dgroup_pointer(DGROUP_CTL3DV2_FULL_SHORT), win16_dgroup_pointer(DGROUP_CTL3DV2_DLL), directory, file); if (g_multimedia_system_directory_length != 0) { borland_c_to_short_string( file, win16_dgroup_pointer(DGROUP_CTL3DV2_DLL)); (void)borland_short_to_c_string( win16_dgroup_pointer(DGROUP_MULTIMEDIA_LIBRARY_PATH), file); if (!multimedia_short_file_exists( win16_dgroup_pointer(DGROUP_CTL3DV2_FULL_SHORT)) && multimedia_short_file_exists( win16_dgroup_pointer(DGROUP_CTL3D_FULL_SHORT))) { borland_c_to_short_string( file, win16_dgroup_pointer(DGROUP_CTL3D_DLL)); (void)borland_short_to_c_string( win16_dgroup_pointer(DGROUP_MULTIMEDIA_LIBRARY_PATH), file); } } for (uint16_t index = 0; index < 11; index++) { g_multimedia_procedures[index] = 0; } g_multimedia_windows_version = (uint16_t)GetVersion16(); uint8_t major = (uint8_t)g_multimedia_windows_version; uint8_t minor = (uint8_t)(g_multimedia_windows_version >> 8); g_multimedia_legacy_windows = major == 3 && minor < 10; g_multimedia_auto_subclassed = 0; g_multimedia_argument_2 = 0; g_multimedia_argument_1 = 1; g_multimedia_module = 0; g_multimedia_pending = 0; g_multimedia_initialized = 0; }