;=========================================================================== ; INSERT.COM v1.0 by David Boozer 8/30/1994 ;--------------------------------------------------------------------------- ;=========================================================================== OUTPUT_FILE_SIZE EQU 0930h CUSTOM_ADDR EQU 08B1h LOAD_ADDR EQU 033Fh CUSTOM_PTR EQU 8641h ;LOAD_ADDR EQU 0915h ;CUSTOM_PTR EQU 8C15h CODE SEGMENT ASSUME CS:CODE, DS:CODE, ES:CODE, SS:CODE ORG 0100h Start: ; ; Get the filename from the command line ; MOV DI, 80h MOV AL, [DI] ; AL = # bytes in switches MOV CL, AL XOR CH, CH Search: CMP CX, 0 JZ Parse_error DEC CX INC DI MOV AL, [DI] CMP AL, ' ' JZ Search INC CX MOV SI, DI MOV DI, OFFSET Input_file REP MOVSB JMP Open_file Parse_error: MOV DX, OFFSET Parse_msg MOV AH, 9 ; Display string INT 21h INT 20h ; ; Open the file ; Open_file: MOV AX, 3D00h ; Open file for read access MOV DX, OFFSET Input_file INT 21h MOV BX, AX ; Put file handle in BX JC File_error ; ; Get the file size ; MOV AX, 4202h ; Move ptr from end of file XOR CX, CX ; Move file ptr 0 bytes XOR DX, DX INT 21h JC File_error MOV Input_file_size, AX MOV AX, 4200h ; Move ptr from start of file XOR CX, CX ; More file ptr 0 bytes XOR DX, DX INT 21h JC File_error ; ; Read in the file ; MOV AH, 3Fh ; Read file MOV CX, Input_file_size MOV DX, OFFSET Buffer+LOAD_ADDR INT 21h JC File_error ; ; Patch the CUSTOM menu ; MOV DI, (OFFSET Buffer)+CUSTOM_ADDR MOV [DI], CUSTOM_PTR ; ; Close the file ; MOV AH, 3Eh INT 21h ; ; Calculate the new checksum ; MOV DI, (OFFSET Buffer)+35h MOV CX, [DI] ; CX = # data bytes XOR AX, AX XOR DX, DX MOV DI, CX ADD DI, (OFFSET Buffer)+37h Sum_loop: DEC DI MOV DL, [DI] ADD AX, DX LOOP Sum_loop ; ; Modify the file image in memory ; MOV DI, OUTPUT_FILE_SIZE ADD DI, (OFFSET Buffer)-2 MOV [DI], AX ; AX = checksum ; ; Create the file "BACKUP.85B" ; MOV AH, 03Ch ; Create file XOR CX, CX ; Normal file MOV DX, OFFSET Output_file INT 21h JC File_error MOV BX, AX ; BX = File handle ; ; Write the updated file image to disk ; MOV AH, 40h ; Write file MOV CX, OUTPUT_FILE_SIZE MOV DX, OFFSET Buffer INT 21h JC File_error MOV AH, 9 MOV DX, OFFSET Good_msg INT 21h Close_file: MOV AH, 3Eh INT 21h INT 20h File_error: MOV DX, OFFSET File_msg MOV AH, 9 ; Display string INT 21h JMP Close_file Dump_addr DW 0 Input_file DB 80 DUP (0) Output_file DB 'BACKUP.85B', 0 Input_file_size DW 0 File_msg: DB 'File I/O Error.$' Parse_msg DB 'Invalid number of parameters.$' Good_msg: DB 'The backup file BACKUP.85B is being created.' DB 0Dh, 0Ah, 'ML program is stored in video memory.$' Buffer: CODE ENDS END Start