Please examine the following assembly code from a 1980s IBM PC computer game. This game…
Rate quality
Private research annotation
Sign in to add a private research label or note.
- User
Please examine the following assembly code from a 1980s IBM PC computer game. This game uses CGA graphics, PC speaker sound and keyboard input. Can you tell me in detail what these functions appear to be doing, and if possible suggest names for the functions?
FUN_0000_2e48() PUSH BP SUB SP,0x6 MOV BP,SP MOV AX,0x28 PUSH AX PUSH AX PUSH word ptr [0x2968] CALL FUN_0000_5ad6 MOV SP,BP MOV AL,[0x17c] XOR AH,AH SHL AX,0x1 MOV SI,AX MOV AX,0x64 PUSH AX MOV AX,0x50 PUSH AX PUSH word ptr [SI + 0x296a] CALL FUN_0000_5ad6 MOV SP,BP MOV AL,[0x17a] XOR AH,AH CMP AX,0x3 MOV word ptr [BP + 0x0],AX MOV [0x17b],AL JGE LAB_0000_2e8c INC AX MOV [0x17a],AL JMP LAB_0000_2e91 LAB_0000_2e8c MOV byte ptr [0x17a],0x0 LAB_0000_2e91 MOV AL,[0x17b] XOR AH,AH MOV SI,AX MOV AL,byte ptr [SI + 0x176] XOR AH,AH MOV BL,byte ptr [0x17a] XOR BH,BH MOV CL,byte ptr [BX + 0x176] XOR CH,CH PUSH CX PUSH AX PUSH word ptr [0x2968] CALL FUN_0000_50b9 MOV SP,BP MOV AL,[0x17c] XOR AH,AH SHL AX,0x1 MOV SI,AX MOV AL,[0x17b] XOR AH,AH MOV DI,AX MOV AL,byte ptr [DI + 0x176] XOR AH,AH MOV BL,byte ptr [0x17a] XOR BH,BH MOV CL,byte ptr [BX + 0x176] XOR CH,CH PUSH CX PUSH AX PUSH word ptr [SI + 0x296a] CALL FUN_0000_50b9 MOV SP,BP ADD SP,0x6 POP BP RET
FUN_0000_5ad6 PUSH BP MOV BP,SP MOV SI,word ptr [BP + Stack[0x2]] MOV DX,word ptr [BP + Stack[0x4]] MOV BX,word ptr [BP + Stack[0x6]] SUB DX,0xa LODSW SI INC AX TEST AX,0x1 JZ LAB_0000_5aed INC AX LAB_0000_5aed SHR AX,0x1 MOV [0x5ff2],AX LODSW SI INC AX MOV [0x5ff4],AX SHL BX,0x1 MOV AX,DX SHR AX,0x1 MOV BP,AX TEST DX,0x1 JZ LAB_0000_5b06 DEC DX LAB_0000_5b06 MOV CX,word ptr [0x5ff2] MOV DX,word ptr [0x5ff4] PUSH ES MOV AX,DAT_0000_b800 MOV ES,AX LAB_0000_5b14 MOV DI,word ptr [BX + 0x5c46] ADD DI,BP PUSH BP PUSH CX MOVSB.REP ES:DI,SI POP CX POP BP INC BX INC BX DEC DX JNZ LAB_0000_5b14 POP ES POP BP RET
FUN_0000_50b9 PUSH BP SUB SP,0xe MOV BP,SP MOV SI,word ptr [BP + Stack[0x2]] MOV AL,byte ptr [SI] XOR AH,AH INC SI INC SI MOV BL,byte ptr [SI] XOR BH,BH MOV CX,SI MOV word ptr [BP + Stack[0x2]],CX INC CX INC CX MOV word ptr [BP + local_6],BX INC BX MOV word ptr [BP + local_8],AX INC AX INC AX MOV word ptr [BP + local_8],AX MOV word ptr [BP + 0x0],BX MOV word ptr [BP + local_6],BX MOV BX,0x2 CWD IDIV BX MOV word ptr [BP + local_e],AX MOV AX,word ptr [BP + 0x0] MOV BX,word ptr [BP + local_e] IMUL BX MOV word ptr [BP + local_4],0x0 MOV word ptr [BP + local_a],AX MOV word ptr [BP + Stack[0x2]],CX LAB_0000_5101 MOV AX,word ptr [BP + local_4] CMP AX,word ptr [BP + local_a] JGE LAB_0000_5167 MOV byte ptr [BP + local_b],0x0 MOV SI,word ptr [BP + Stack[0x2]] MOV AL,byte ptr [SI] XOR AH,AH MOV byte ptr [BP + local_c],AL AND AX,0xf0 MOV BX,word ptr [BP + Stack[0x4]] AND BX,0xf0 CMP AX,BX JNZ LAB_0000_512e MOV AX,word ptr [BP + Stack[0x6]] AND AX,0xf0 MOV byte ptr [BP + local_b],AL LAB_0000_512e MOV AL,byte ptr [BP + local_c] XOR AH,AH AND AX,0xf MOV BX,word ptr [BP + Stack[0x4]] AND BX,0xf CMP AX,BX JNZ LAB_0000_5151 MOV AX,word ptr [BP + Stack[0x6]] AND AX,0xf MOV BL,byte ptr [BP + local_b] XOR BH,BH OR BX,AX MOV byte ptr [BP + local_b],BL LAB_0000_5151 MOV AL,byte ptr [BP + local_b] XOR AH,AH TEST AX,AX JZ LAB_0000_515f MOV SI,word ptr [BP + Stack[0x2]] MOV byte ptr [SI],AL LAB_0000_515f INC word ptr [BP + Stack[0x2]] INC word ptr [BP + local_4] JMP LAB_0000_5101 LAB_0000_5167 ADD SP,0xe POP BP RET
- Assistant
Based on the examination of the assembly code:
-
FUN_0000_2e48: This function seems to be drawing two sets of pictures (tiles or sprites) on the screen based on the stored data in memory region 0x2968 - 0x296b. It does this in four steps: a. Draw a pair of pictures from data source 0x2968 b. Update variables at addresses 0x17a, 0x17b based on the comparison results c. Use the updated variables to draw another pair of pictures d. Draw a second pair of pictures based on data source 0x296a - 0x296b Suggested name: DrawAndUpdateSprites
-
FUN_0000_5ad6: This function is related to drawing pictures on the CGA screen memory located at 0xB800. It processes a sequence of tiles stored in memory, composed of 8x8 pixels each (14 bytes per tile, each byte made up of 2 4-bit pixel color values). The function reads input parameters (width and height of the tile picture) and a pointer to the tile data. It then calculates the location of each tile on the screen (address calculation) and copies the pixel data from the source to the CGA screen memory. Suggested name: DrawTiles
-
- User
Please continue.
- Assistant
- FUN_0000_2e48 (DrawAndUpdateSprites):
This function appears to be performing the following operations: a. Draws two pictures on screen based on data in memory (located at 0x2968 and 0x296a). To draw the pictures, it calls FUN_0000_5ad6 two times with different parameters.
code - User
Here is additional code from the program. Please explain/name these as well, and if necessary, update or amend your explanation of the previous three functions:
FUN_0000_5d86 PUSH AX PUSH BX PUSH CX PUSH DX PUSH SI PUSH DI PUSH DS PUSH ES PUSH BP MOV AX,0x4ce MOV DS,AX DEC byte ptr [0x6305]=>DAT_0000_afe5 JNZ LAB_0000_5da4 MOV byte ptr [0x6306]=>DAT_0000_afe6,0x1 MOV byte ptr [0x6305]=>DAT_0000_afe5,0x12 LAB_0000_5da4 CMP byte ptr [0x1fd0]=>DAT_0000_6cb0,0x1 JNZ LAB_0000_5db5 CMP byte ptr [0x6303]=>DAT_0000_afe3,0x1 JNZ LAB_0000_5db5 CALL FUN_0000_5dcd LAB_0000_5db5 CMP byte ptr [0x175]=>LAB_0000_4e55,0x1 JNZ LAB_0000_5dc3 MOV BP,SP CALL FUN_0000_2e48 MOV SP,BP LAB_0000_5dc3 POP BP POP ES POP DS POP DI POP SI POP DX POP CX POP BX POP AX IRET
- Assistant
Here's the analysis of the new functions:
-
FUN_0000_5d86: Main Interrupt Handler This function appears to be an interrupt handler, possibly for a timer interrupt based on the code. It saves the state of all registers and does the following tasks:
a. Decrement value [0x6305]. If this value becomes zero, it sets the values at [0x6306] to 0x1 and [0x6305] to 0x12.
b. Check two conditions at memory addresses [0x1fd0] and [0x6303], and if both conditions are true (both values are 0x1), it calls FUN_0000_5dcd.
c. Check another condition at memory address [0x175]. If the value is 0x1, it calls FUN_0000_2e48 (DrawAndUpdateSprites).
After these instructions, it restores the register values and executes the IRET instruction, which returns from the interrupt.
-