I will provide you disassembly from a computer game that runs in MS-DOS. The game was…
- User
I will provide you disassembly from a computer game that runs in MS-DOS. The game was written in C with a Watcom compiler. Some library function calls are already identified. Explain the functions I give to you and suggest names and C-language function signatures for them, including which parameters map to which registers or stack values. Also suggest names for global values if you have enough context to do so.
FUN_0009960a PUSH EBP MOV EBP,ESP PUSH EBX PUSH ECX PUSH EDX PUSH ESI PUSH EDI SUB ESP,0x28 LEA EAX=>local_24,[EBP + -0x20] CALL FUN_000a3327 MOV byte ptr [EBP + local_38],0x0 MOV word ptr [EBP + local_40],0xff30 LEA ECX=>local_24,[EBP + -0x20] LEA EBX=>local_40,[EBP + -0x3c] LEA EDX=>local_40,[EBP + -0x3c] MOV EAX,0x31 CALL int386x LEA ESP=>local_18,[EBP + -0x14] POP EDI POP ESI POP EDX POP ECX POP EBX POP EBP RET
FUN_00099647 ADD byte ptr [EDX + 0x66],DL POP EDX POP CX MOV BX,AX MOV AX,0x7 INT 0x31 RET
FUN_00099657 ADD EAX,0xff AND EAX,0xffffff00 RET
FUN_00099662 PUSH EBX PUSH ECX PUSH EDX ADD EAX,0xf SHR EAX,0x4 MOV EBX,EAX MOV AX,0x100 INT 0x31 MOV BX,DX MOV AX,0x6 INT 0x31 MOV AX,CX SHL EAX,0x10 MOV AX,DX POP EDX POP ECX POP EBX RET
- Assistant
- FUN_0009960a
This function calls FUN_000a3327 with an input parameter passed by reference, and then calls the DOS interrupt 31h with some values stored in memory. It seems to be related to initializing some system settings, though the exact purpose of these calls is not clear due to missing information.
Suggested name: init_system_settings()
Suggested signature: void init_system_settings(void)
Explanation:
- CALL FUN_000a3327 with a reference to a local variable (likely initializing the value)
- Set up some register values and call interrupt 31h (a DOS function)
- User
- Assistant
Re-examining FUN_000a3327: Based on the description of segread, it seems that the function reads the segment registers into a structure. It takes a pointer to the SREGS structure as its single input parameter.
Suggested name: read_segment_registers()
- User
Sorry, I asked you to re-examine FUN_000a0040 (segread), but I meant to ask you to re-examine FUN_00099490.
- Assistant
Apologies for the confusion earlier. Here is the re-examination of FUN_00099490:
- FUN_00099490
This function sets up and calls the int386x function with an interrupt number of 0x31, using registers and memory operands. It takes a 32-bit input value and calls the int386x function with the DS (Data Segment) register set, as well as the values of the input.
Suggested name: call_int386x_with_input()
Suggested signature: void call_int386x_with_input(uint32_t input_value);
Explanation:
- Stores input EAX value in a local variable
- Calls FUN_000a0040 with 0x27, 0x4, and "int.c" to set up some values
- Sets up registers and memory operands for the int386x call
- Calls int386x with interrupt number 0x31, the prepared registers, and the Data Segment register set
- Keeps the input EAX value intact before calling the interrupt
- User
- Assistant
- FUN_00099689
This function initializes a color palette by calling several sub-functions and using the data provided. It seems to be setting colors and palettes for different elements of the game.
Suggested name: init_color_palette()
Suggested signature: void init_color_palette(void);
Explanation:
- Sets up initial values by calling FUN_000a00af and FUN_000ce66c
- Iterates through nested loops and populates color information using the call to FUN_000a1023 by reading data from address 0x1886a8
- Sets up special colors and palettes by calling FUN_000ce663 multiple times
- Repeats the process for different color palettes
- FUN_000ce663
This function copies a given number of bytes from the source to the destination specified by EDX and EAX registers.
- User
FUN_0012db50 CMP dword ptr [EAX0x4 + DAT_0012da54],0x0 JZ LAB_0012db80 PUSH ESI MOV [DAT_0012da50],EAX MOV ESI,dword ptr [EAX0x4 + DAT_0012da54] MOV dword ptr [DAT_0012da74],ESI MOVZX EAX,word ptr [ESI] MOV [DAT_0012da40],EAX MOVZX EAX,word ptr [ESI + 0x2] MOV [DAT_0012da44],EAX POP ESI RET LAB_0012db80 CALL FUN_00143700 CALL FUN_00142764 CALL FUN_00149ef8 MOV AH,0x9 MOV EDX,s_FONT:_Attempt_to_set_non-existin_0012da0d = "FONT: Attempt to set non-existing font.\n\r$" INT 0x21 MOV AX,0x4c00 INT 0x21 XCHG EBX,EBX PUSH ECX PUSH EBP PUSH ESI PUSH EDI SUB EBX,0x21 LAB_0012dbc5 SHL EBX,0x2 ADD EBX,dword ptr [DAT_0012da74] MOVZX ESI,word ptr [EBX + 0x4] ADD ESI,dword ptr [DAT_0012da74] MOVZX EBX,word ptr [EBX + 0x6] CALL FUN_0012dc44 LAB_0012dbc5 POP EDI POP ESI POP EBP POP ECX RET
FUN_00142764 PUSHAD CMP byte ptr [DAT_00142306],0x0 JZ LAB_0014278c MOV byte ptr [DAT_00142306],0x0 MOV EAX,0x9 MOV EBX,dword ptr [DAT_00142300] MOVZX ECX,word ptr [DAT_00142304] CALL FUN_000a12a6 LAB_0014278c POPAD RET
FUN_00143700 PUSHAD MOV EAX,[DAT_00142923] CALL dword ptr [EAX + DAT_00143565] MOV EAX,[DAT_00143558] TEST EAX,EAX JZ LAB_0014371a CALL FUN_000a117e LAB_0014371a MOV EAX,[DAT_0014291f] TEST EAX,EAX JZ LAB_0014373d CMP EAX,0x100 JC LAB_00143736 CALL FUN_0015fca7 CALL FUN_0015fc93 POPAD RET LAB_00143736 INT 0x10 CALL FUN_0015fc93 LAB_0014373d POPAD RET
- Assistant
- FUN_0012db50
This function appears to be handling fonts and has some error handling for non-existing fonts. It sets font data based on the input value in EAX register and calls other functions to handle fonts.
Suggested name: set_font_data()
Suggested signature: void set_font_data(uint32_t font_index);
Explanation:
- Checks if the font data exists at the given index (EAX*0x4 + DAT_0012da54)
- If it exists, updates the global variables with font information and returns