Skip to content
TheChatArchiveThe Chat Archive
gpt-4-0314· OpenAIAi2 WildChat-4.8M (AI2)

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.

    FUN_00160900 PUSH ESI DEC EAX CMP byte ptr [EAX + DAT_00160000],offset DAT_0015ffff JZ LAB_00160963 MOV byte ptr [EAX + DAT_00160000],offset DAT_0015ffff PUSH EAX PUSH EBX PUSH ECX PUSH EDX MOV EBX,EAX MOV EAX,dword ptr [EAX0x4 + DAT_00160014] PUSH EAX CALL _dos_getvect MOV word ptr [EBX0x2 + DAT_00160038],DX MOV dword ptr [EBX0x4 + DAT_00160028],EAX POP EAX MOV EBX,dword ptr [EBX0x4 + PTR_FUN_00160040] PUSH EBX MOV CX,CS CALL set_interrupt_handler POP EAX MOV EDX,0x400 CALL lock_memory_region MOV EAX,DAT_00160000 MOV EDX,0x880 CALL lock_memory_region POP EDX POP ECX POP EBX POP EAX LAB_00160963 INC EAX CALL FUN_00160a18 CLI LEA ESI,[EAX*0x4 + 0xfffffffc] MOV EAX,EDX MOV EDX,dword ptr [ESI + 0x160004] ADD EDX,0x3 OR AL,0x80 OUT DX,AL PUSH EAX PUSH EDX MOV EDX,dword ptr [ESI + 0x160004] MOV EAX,EBX OUT DX,AX POP EDX POP EAX AND AL,0x7f OUT DX,AL MOV EDX,dword ptr [ESI + 0x160004] ADD EDX,0x4 MOV AL,0x8 OUT DX,AL MOV EDX,dword ptr [ESI + 0x160004] ADD EDX,0x1 MOV AL,0x1 OUT DX,AL SUB EDX,0x1 IN AL,DX SHR ESI,0x2 IN AL,0x21 AND AL,byte ptr [ESI + DAT_00160024] OUT 0x21,AL STI MOV AL,0x20 OUT 0x20,AL POP ESI RET

    Data at DAT_00160014: 0c 00 00 00 0b 00 00 00 0c 00 00 00 0b 00 00 00

    Data at PTR_FUN_00160040 is the addresses for four functions: FUN_00160ae0 FUN_00160b60 FUN_00160be0 FUN_00160c60

    Data at DAT_00160024 is: ef f7 ef f7

    FUN_00160ae0 PUSH EAX PUSH EDX PUSH DS MOV AX,0x0 MOV DS,AX MOV EDX,0x3f8 ADD EDX,0x2 IN AL,DX TEST AL,0x1 JNZ LAB_00160b3a TEST AL,0x6 JZ LAB_00160b30 TEST AL,0x4 JZ LAB_00160b3a MOV EDX,0x3f8 ADD EDX,0x5 IN AL,DX SUB EDX,0x5 IN AL,DX MOV EDX,DAT_00160050 ADD EDX,dword ptr [DAT_00160860] INC dword ptr [DAT_00160860] MOV byte ptr [EDX],AL AND dword ptr [DAT_00160860],0x1ff INC dword ptr [DAT_00160870] JMP LAB_00160b3a LAB_00160b30 MOV EDX,0x3f8 IN AL,DX ADD EDX,0x5 IN AL,DX LAB_00160b3a MOV AL,0x20 OUT 0x20,AL POP DS POP EDX POP EAX IRET

    FUN_00160b60 PUSH EAX PUSH EDX PUSH DS MOV AX,0x0 MOV DS,AX MOV EDX,0x2f8 ADD EDX,0x2 IN AL,DX TEST AL,0x1 JNZ LAB_00160bba TEST AL,0x6 JZ LAB_00160bb0 TEST AL,0x4 JZ LAB_00160bba MOV EDX,0x2f8 ADD EDX,0x5 IN AL,DX SUB EDX,0x5 IN AL,DX MOV EDX,DAT_00160250 ADD EDX,dword ptr [DAT_00160864] MOV byte ptr [EDX],AL INC dword ptr [DAT_00160864] AND dword ptr [DAT_00160864],0x1ff INC dword ptr [DAT_00160874] JMP LAB_00160bba LAB_00160bb0 MOV EDX,0x2f8 IN AL,DX ADD EDX,0x5 IN AL,DX LAB_00160bba MOV AL,0x20 OUT 0x20,AL POP DS POP EDX POP EAX IRET

    FUN_00160be0 PUSH EAX PUSH EDX PUSH DS MOV AX,0x0 MOV DS,AX MOV EDX,0x3e8 ADD EDX,0x2 IN AL,DX TEST AL,0x1 JNZ LAB_00160c3a TEST AL,0x6 JZ LAB_00160c30 TEST AL,0x4 JZ LAB_00160c3a MOV EDX,0x3e8 ADD EDX,0x5 IN AL,DX SUB EDX,0x5 IN AL,DX MOV EDX,DAT_00160450 ADD EDX,dword ptr [DAT_00160868] MOV byte ptr [EDX],AL INC dword ptr [DAT_00160868] AND dword ptr [DAT_00160868],0x1ff INC dword ptr [DAT_00160878] JMP LAB_00160c3a LAB_00160c30 MOV EDX,0x3e8 IN AL,DX ADD EDX,0x5 IN AL,DX LAB_00160c3a MOV AL,0x20 OUT 0x20,AL POP DS POP EDX POP EAX IRET

    FUN_00160c60 PUSH EAX PUSH EDX PUSH DS MOV AX,0x0 MOV DS,AX MOV EDX,0x2e8 ADD EDX,0x2 IN AL,DX TEST AL,0x1 JNZ LAB_00160cba TEST AL,0x6 JZ LAB_00160cb0 TEST AL,0x4 JZ LAB_00160cba MOV EDX,0x2e8 ADD EDX,0x5 IN AL,DX SUB EDX,0x5 IN AL,DX MOV EDX,DAT_00160650 ADD EDX,dword ptr [DAT_0016086c] MOV byte ptr [EDX],AL INC dword ptr [DAT_0016086c] AND dword ptr [DAT_0016086c],0x1ff INC dword ptr [DAT_0016087c] JMP LAB_00160cba LAB_00160cb0 MOV EDX,0x2e8 IN AL,DX ADD EDX,0x5 IN AL,DX LAB_00160cba MOV AL,0x20 OUT 0x20,AL POP DS POP EDX POP EAX IRET

    FUN_00161000 PUSHAD MOV [DAT_00153400],EAX MOV EDX,0x3 MOV EBX,0x6 CALL FUN_00160900 CALL FUN_00161094 JC LAB_00161072 MOV ECX,0x10 LAB_00161021 MOV EAX,DAT_00160f08 CALL FUN_00161224 CALL FUN_00161250 JNC LAB_00161036 LOOP LAB_00161021 JMP LAB_00161072 LAB_00161036 MOV dword ptr [DAT_00160f18],0x1 CALL FUN_001610d4 JC LAB_00161072 CALL FUN_00161114 CMP EAX,0x3eb JC LAB_00161059 NEG dword ptr [DAT_00160f18] LAB_00161059 CALL FUN_001610b4 MOV EAX,[DAT_00153400] CALL FUN_00160a18 CALL FUN_001610c4 POPAD XOR EAX,EAX CLC RET LAB_00161072 MOV EAX,[DAT_00153400] CALL FUN_001609c0 POPAD MOV EAX,0x1 STC RET

    Data at DAT_00160f08: 21 4d 32 2c 43 2c 42 0d ff

  2. Assistant

    The provided code appears to deal with the initialization, configuration, and handling of UART (Universal Asynchronous Receiver/Transmitter) serial communication in the context of an MS-DOS computer game.

    Here is the proposed function signatures for the given code:

    // function FUN_00160900
    int init_uart(uint8_t port, uint32_t divisor);
    
    // function FUN_00160ae0, FUN_00160b60, FUN_00160be0, FUN_00160c60
    void interrupt_handler();
    
    // function FUN_00161000
    int configure_uart(uint8_t port);
    

    Global variable names:

    DAT_00160000 : g_uart_base_addr
    DAT_00160014 : g_uart_divisor_table
    PTR_FUN_00160040 : g_interrupt_handler_table
    DAT_00160024 : g_uart_restore_mask
    DAT_00160f08 : g_uart_init_sequence
    

    Function descriptions:

    init_uart(uint8_t port, uint32_t divisor) (FUN_00160900):

    • Initializes the UART port specified by the port parameter, and sets the baud rate divisor specified by the divisor parameter.
    • Saves the current interrupt vector for the specified port and sets the interrupt handler from the handler table.
    • Locks the specified memory regions (EMS or XMS regions) for the game.
    • Returns 0 if successful, else returns 1.

    interrupt_handler() (FUN_00160ae0, FUN_00160b60, FUN_00160be0, FUN_00160c60):

    • These functions act as interrupt handlers for each of the four serial UART ports (0x3F8, 0x2F8, 0x3E8, and 0x2E8).
    • The handlers read the incoming data and store it in a ring buffer.
    • In case of a line status error, the data is read but not stored in the buffer.

    configure_uart(uint8_t port) (FUN_00161000):

    • Configures the specified UART port by setting its properties, such as baud rate, data length, parity, and flow control.
    • Calls init_uart for initialization and then sends specific commands to the UART to configure it.
    • Returns 0 if successful, else returns 1.

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