Skip to content
TheChatArchiveThe Chat Archive
gpt-4-0314· openaiHugging Face Suzhen/CodeChat

I will provide you disassembly from a computer game that runs in MS-DOS. The game was…

  1. 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 and explain the data that is used.

    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_0012dc44 PUSH EAX PUSH EBX PUSH ECX PUSH EDX CMP EAX,dword ptr [DAT_00142948] JGE LAB_0012dd17 CMP EDX,dword ptr [DAT_0014294c] JGE LAB_0012dd17 MOV EBP,dword ptr [DAT_0012da44] CMP EDX,dword ptr [DAT_00142944] JGE LAB_0012dc88 SUB EDX,dword ptr [DAT_00142944] NEG EDX SUB EBP,EDX JLE LAB_0012dd17 ADD EDX,EDX ADD ESI,EDX MOV EDX,dword ptr [DAT_00142944] LAB_0012dc88 MOV ECX,EDX ADD ECX,EBP SUB ECX,dword ptr [DAT_0014294c] JLE LAB_0012dc9c SUB EBP,ECX JLE LAB_0012dd17 NOP NOP NOP NOP LAB_0012dc9c MOV byte ptr [LAB_0012dd00+2],0x10 CMP EAX,dword ptr [DAT_00142940] JGE LAB_0012dcc5 SUB EAX,dword ptr [DAT_00142940] NEG EAX SUB EBX,EAX JLE LAB_0012dd17 ADD BL,0x10 MOV byte ptr [LAB_0012dd00+2],BL MOV EAX,[DAT_00142940] LAB_0012dcc5 MOV ECX,EAX ADD ECX,EBX SUB ECX,dword ptr [DAT_00142948] = 0140h JLE LAB_0012dcd5 SUB EBX,ECX JLE LAB_0012dd17 LAB_0012dcd5 MOV EDI,dword ptr [EDX*0x4 + DAT_00142950] ADD EDI,dword ptr [PTR_DAT_00143550] ADD EDI,EAX MOV ECX,dword ptr [DAT_00142930] SUB ECX,EBX MOV dword ptr [LAB_0012dd0e+2],ECX MOV CH,byte ptr [DAT_0012b508] LAB_0012dcf8 MOV AX,word ptr [ESI] MOV CL,BL ADD ESI,0x2 SHL EAX,0x64 ; LAB_0012dd00+2 points to the 0x64 byte in this instruction LAB_0012dd03 ADD EAX,EAX JNC LAB_0012dd09 MOV byte ptr [EDI],CH LAB_0012dd09 INC EDI DEC CL JNZ LAB_0012dd03 ADD EDI,0x3e8 ; LAB_0012dd0e+2 points to the 0x3e8 4-byte value in this instruction DEC EBP JNZ LAB_0012dcf8 LAB_0012dd17 POP EDX POP ECX POP EBX POP EAX 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

    FUN_00149ef8 PUSHAD MOV EAX,[DAT_00147958] TEST EAX,EAX JZ LAB_00149f07 CALL FUN_000a117e LAB_00149f07 POPAD RET

  2. Assistant

    Let's start by examining FUN_0012db50. This function first checks if a global value at the address DAT_0012da54 + EAX*0x4 is not null, and if it is, it jumps to LAB_0012db80, where it calls three other functions, prints an error message and exits. If the value is not null, it copies some values into global variables and returns. Therefore, this function might be trying to set some values based on an index passed in EAX. We can give it the name SetValueBasedOnIndex and the C signature void SetValueBasedOnIndex(uint32_t index).

    void SetValueBasedOnIndex(uint32_t index) {
        if (some_global_array[index]) {
            ...
        } else {
            ...
            exit(0);
        }
    }
    

    FUN_0012dc44 seems to perform some operations on data from global variables, controlled by parameters in EAX and EDX. It's not very clear what it does, but we can call it ProcessData and give it the signature: void ProcessData(uint32_t eax_value, uint32_t edx_value).

    void ProcessData(uint32_t eax_value, uint32_t edx_value) {
        ...
    }
    

    FUN_00142764 checks a global byte value located at DAT_00142306. If this value is non-zero, it resets it to zero, takes more values from global variables, and calls another function. It doesn't take any input parameters, so we can assume it's something like ResetCheckAndPerformAction. The C signature would be void ResetCheckAndPerformAction().

    void ResetCheckAndPerformAction() {
        if (global_flag_00142306) {
            ...
        }
    }
    

    FUN_00143700 seems related to interrupting the video functions on old MS-DOS systems. It calls an interrupt (0x10) if a specific value is set, and some other functions depending on the values of global variables. It might be some kind of UpdateGraphics function, and the C signature would be void UpdateGraphics().

    void UpdateGraphics() {
        ...
    }
    

    Finally, FUN_00149ef8 checks another global value DAT_00147958. If it is non-zero, it calls another function. It doesn't use any input parameters, so we can call it something like PerformActionIfFlagSet and give it the C signature void PerformActionIfFlagSet().

    void PerformActionIfFlagSet() {
        if (global_flag_00147958) {
            ...
        }
    }
    

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.