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. Regarding the value DAT_0000046c (the memory at address 0x46c), according to information I found this value is in the BIOS data area and stores the number of "ticks" since midnight (resetting to 0 again at the next midnight). Ticks happen at a rate of 18.2 times per second.

    FUN_0007e066 PUSH EBP MOV EBP,ESP PUSH EBX PUSH ECX PUSH EDX PUSH ESI PUSH EDI SUB ESP,0x0 CALL FUN_0007f671 MOV EAX,[DAT_00195b00] MOV [DAT_001a59d0],EAX MOV EAX,[DAT_00195b00] MOV [DAT_001a59c8],EAX LEA ESP=>local_18,[EBP + -0x14] POP EDI POP ESI POP EDX POP ECX POP EBX POP EBP RET

    FUN_0007f671 PUSH EBP MOV EBP,ESP PUSH EBX PUSH ECX PUSH EDX PUSH ESI PUSH EDI SUB ESP,0x4 CALL FUN_000ce8b2 MOV [DAT_001a59cc],EAX MOV dword ptr [EBP + local_1c],DAT_0000046c MOV EAX,dword ptr [EBP + local_1c] MOV EAX=>DAT_0000046c,dword ptr [EAX] MOV [DAT_001a59dc],EAX LEA ESP=>local_18,[EBP + -0x14] POP EDI POP ESI POP EDX POP ECX POP EBX POP EBP RET

    FUN_0007f6a4 PUSH EBP MOV EBP,ESP PUSH EBX PUSH ECX PUSH EDX PUSH ESI PUSH EDI SUB ESP,0xc MOV EAX,[DAT_001a59cc] MOV [DAT_001a59e0],EAX MOV EAX,[DAT_001a59dc] MOV [DAT_001a59e4],EAX CALL FUN_000ce8b2 MOV [DAT_001a59cc],EAX MOV dword ptr [EBP + local_1c],DAT_0000046c MOV EAX,dword ptr [EBP + local_1c] MOV EAX=>DAT_0000046c,dword ptr [EAX] MOV [DAT_001a59dc],EAX MOV EAX,[DAT_001a59dc] CMP EAX,dword ptr [DAT_001a59e4] JNZ LAB_0007f6fe MOV EAX,[DAT_001a59e0] SUB EAX,dword ptr [DAT_001a59cc] MOV dword ptr [EBP + local_24],EAX JMP LAB_0007f726 LAB_0007f6fe MOV EAX,[DAT_001a59dc] SUB EAX,dword ptr [DAT_001a59e4] DEC EAX IMUL EDX,EAX,0xffff MOV EAX,0xffff SUB EAX,dword ptr [DAT_001a59cc] ADD EAX,dword ptr [DAT_001a59e0] ADD EAX,EDX MOV dword ptr [EBP + local_24],EAX LAB_0007f726 CMP dword ptr [EBP + local_24],0x2710 JNC LAB_0007f745 MOV EAX,0xffff SUB EAX,dword ptr [DAT_001a59cc] MOV EDX,dword ptr [DAT_001a59e0] ADD EDX,EAX MOV dword ptr [EBP + local_24],EDX LAB_0007f745 IMUL EAX,dword ptr [EBP + local_24],0x3e8 MOV EBX,DAT_001234dc XOR EDX,EDX DIV EBX SHR EAX,0x1 MOV EBX,EAX MOV EAX,[DAT_001a59d8] SHL EAX,0x2 MOV dword ptr [EAX + DAT_001a5408],EBX MOV EAX,[DAT_001a59d8] SHL EAX,0x2 CMP dword ptr [EAX + DAT_001a5408],0x64 JBE LAB_0007f78a MOV EAX,[DAT_001a59d8] SHL EAX,0x2 MOV dword ptr [EAX + DAT_001a5408],0x64 LAB_0007f78a MOV EAX,[DAT_001a59d8] INC EAX AND EAX,0x7 MOV [DAT_001a59d8],EAX MOV dword ptr [EBP + local_20],0x0 LAB_0007f79f CMP dword ptr [EBP + local_20],0x8 JL LAB_0007f7af JMP LAB_0007f7c3 LAB_0007f7a7 MOV EAX,dword ptr [EBP + local_20] INC dword ptr [EBP + local_20] JMP LAB_0007f79f LAB_0007f7af MOV EAX,dword ptr [EBP + local_20] SHL EAX,0x2 MOV EAX,dword ptr [EAX + DAT_001a5408] ADD dword ptr [DAT_00195ab0],EAX JMP LAB_0007f7a7 LAB_0007f7c3 SAR dword ptr [DAT_00195ab0],0x3 CMP dword ptr [DAT_00195ab0],0x1f4 JLE LAB_0007f7e0 MOV dword ptr [DAT_00195ab0],0x1f4 LAB_0007f7e0 LEA ESP=>local_18,[EBP + -0x14] POP EDI POP ESI POP EDX POP ECX POP EBX POP EBP RET

    FUN_000ce8b2 MOV AL,0xb0 OUT 0x43,AL IN AL,0x40 MOV AH,AL IN AL,0x40 XCHG AL,AH AND EAX,0xffff RET

  2. Assistant

    Let me analyze the code and then provide the explanations and suggestions for each function:

    1. FUN_0007e066:

    This function performs the following steps:

    • Call FUN_0007f671
    • Copies the value from DAT_00195b00 to DAT_001a59d0 and DAT_001a59c8

    Suggested name: Init_Game_Timer

    C language function signature:

    void Init_Game_Timer();
    
    1. FUN_0007f671:

    This function performs the following steps:

    • Call FUN_000ce8b2 and store the result in DAT_001a59cc
    • Copy the tick count (from DAT_0000046c) to DAT_001a59dc

    Suggested name: Update_Timer_Values

    C language function signature:

    void Update_Timer_Values();
    
    1. FUN_0007f6a4:

    This function seems to measure time and calculate some values based on that, then update DAT_00195ab0 with a new value.

    Suggested name: Calculate_Time_and_Update

    C language function signature:

    int Calculate_Time_and_Update();
    
    1. FUN_000ce8b2:

    This function reads the current count from the system PIT (Programmable Interval Timer). It returns the low byte of the count followed by the high byte of the count.

    Suggested name: Get_PIT_Count

    C language function signature:

    unsigned short Get_PIT_Count();
    

    Global values in the code:

    • DAT_00195b00 : Initial value of a game timer variable
    • DAT_00195ab0 : Timer variable used in calculations
    • DAT_0000046c : Number of ticks since midnight (resets to 0 again at the next midnight)
    • DAT_001a59cc : Last PIT Count
    • DAT_001a59dc : Last tick count
    • DAT_001a59d0 : Initialized game timer value
    • DAT_001a59c8 : Initialized game timer value
    • DAT_001a59d8 : Index for updating time-related values in the game
    • DAT_001a5408 : Array to store calculated values based on time
    • DAT_0000046c : Number of ticks since midnight

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