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 (variables beginning with "DAT").
The values for the global values at the start of program execution (not necessarily at the time FUN_0012b136 is called) are as follows: DAT_0012ac04 = A0h DAT_0012af36 = 13Fh DAT_0012af3a = C7h DAT_0012ac06 = 64h All others = 0h
Note that DAT_0000046c refers to the four bytes of memory at 0x46C. These bytes stored as two 2-byte words provide the master clock count.
FUN_0012b136 PUSHAD CALL FUN_0012b196 MOV AX,[DAT_0012ac04] CMP AX,word ptr [DAT_0012af34] JGE LAB_0012b153 MOV AX,[DAT_0012af34] JMP LAB_0012b162 LAB_0012b153 CMP AX,word ptr [DAT_0012af36] JLE LAB_0012b162 MOV AX,[DAT_0012af36] LAB_0012b162 MOV [DAT_0012ac04],AX MOV AX,[DAT_0012ac06] CMP AX,word ptr [DAT_0012af38] JGE LAB_0012b17f MOV AX,[DAT_0012af38] JMP LAB_0012b18e LAB_0012b17f CMP AX,word ptr [DAT_0012af3a] JLE LAB_0012b18e MOV AX,[DAT_0012af3a] LAB_0012b18e MOV [DAT_0012ac06],AX POPAD RET
FUN_0012b196 PUSH DS POP FS MOV AL,[DAT_0012ac00] MOV [DAT_0012ac01],AL MOV EAX,0x3 INT 0x33 MOV byte ptr [DAT_0012ac00],BL MOV word ptr [DAT_0012ac04],CX MOV word ptr [DAT_0012ac06],DX MOV word ptr [DAT_0012ac02],0x0 MOV EDX,0x46c MOV EDX=>DAT_0000046c,dword ptr [EDX] MOV AL,[DAT_0012ac00] MOV AH,byte ptr [DAT_0012ac01] AND AX,0x101 CMP AX,0x1 JNZ LAB_0012b250 NOP NOP NOP NOP MOV EAX,EDX SUB EAX,dword ptr [DAT_0012af24] OR EAX,EAX JNS LAB_0012b1f5 NEG EAX LAB_0012b1f5 CMP EAX,0x8 JGE LAB_0012b232 MOV AX,[DAT_0012af28] SUB AX,word ptr [DAT_0012ac04] JNS LAB_0012b20c NEG AX LAB_0012b20c CMP AX,0x4 JGE LAB_0012b232 MOV AX,[DAT_0012af2a] SUB AX,word ptr [DAT_0012ac06] JNS LAB_0012b224 NEG AX LAB_0012b224 CMP AX,0x4 JGE LAB_0012b232 word ptr [DAT_0012ac02],0x1 LAB_0012b232 MOV dword ptr [DAT_0012af24],EDX MOV AX,[DAT_0012ac04] MOV [DAT_0012af28],AX MOV AX,[DAT_0012ac06] MOV [DAT_0012af2a],AX LAB_0012b250 MOV AL,[DAT_0012ac00] MOV AH,byte ptr [DAT_0012ac01] AND AX,0x202 CMP AX,0x2 JNZ LAB_0012b2d2 NOP NOP NOP NOP MOV EAX,EDX SUB EAX,dword ptr [DAT_0012af2c] OR EAX,EAX JNS LAB_0012b277 NEG EAX LAB_0012b277 CMP EAX,0x8 JGE LAB_0012b2b4 MOV AX,[DAT_0012af30] SUB AX,word ptr [DAT_0012ac04] JNS LAB_0012b28e NEG AX LAB_0012b28e CMP AX,0x4 JGE LAB_0012b2b4 MOV AX,[DAT_0012af32] SUB AX,word ptr [DAT_0012ac06] JNS LAB_0012b2a6 NEG AX LAB_0012b2a6 CMP AX,0x4 JGE LAB_0012b2b4 OR word ptr [DAT_0012ac02],0x2 LAB_0012b2b4 MOV dword ptr [DAT_0012af2c],EDX MOV AX,[DAT_0012ac04] MOV [DAT_0012af30],AX MOV AX,[DAT_0012ac06] MOV [DAT_0012af32],AX LAB_0012b2d2 RET
- Assistant
FUN_0012b136seems to be a function that first callsFUN_0012b196to update some global values related to mouse input, then clamps the mouse coordinates to a specific range.I would suggest the following C-language function signature for it:
void update_mouse_coordinates_and_clamp(void);FUN_0012b196is a function that retrieves the mouse input and stores them in global variables, as well as updates some other global values potentially related to the state of the mouse buttons.I would suggest the following C-language function signature for it:
void update_mouse_input(void); - User
How about this function:
FUN_0005a661 PUSH EBP MOV EBP,ESP PUSH ESI PUSH EDI SUB ESP,0x10 MOV dword ptr [EBP + local_1c],EAX MOV dword ptr [EBP + local_18],EDX MOV dword ptr [EBP + local_14],EBX MOV dword ptr [EBP + local_10],ECX MOV EAX,dword ptr [EBP + local_1c] MOV [DAT_0012af34],AX MOV EAX,dword ptr [EBP + local_14] MOV [DAT_0012af36],AX MOV EAX,dword ptr [EBP + local_18] MOV [DAT_0012af38],AX MOV EAX,dword ptr [EBP + local_10] MOV [DAT_0012af3a] LEA ESP=>local_c,[EBP + -0x8] POP EDI POP ESI POP EBP RET
- Assistant
FUN_0005a661seems to be a function that takes four input arguments and sets the values of the global values related to the clamping ranges of the mouse coordinates (min_x_clamp,max_x_clamp,min_y_clamp, andmax_y_clamp) using these arguments.I would suggest the following C-language function signature for it:
void set_mouse_clamp_ranges(uint16_t min_x, uint16_t max_x, uint16_t min_y, uint16_t max_y);For the stack values (local_*), based on their usage, I would suggest the following names (with their corresponding offsets in ebp):
local_1c (-0x1C):min_xlocal_18 (-0x18):max_xlocal_14 (-0x14):min_ylocal_10 (-0x10):max_y
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.