JMP JMP00 NAMADD1: DW 0000 ;Address of target filename NAMADD2: DB "OUTPUT1.A00" ;Default output filename ADD2B: DB 00,0D,0A,024 ;For displaying default output filename NAMADD2A:DB 13 DUP 00 ;Output filename buffer HANDLE1: DW 0000 ;Handle of source file HANDLE2: DW 0000 ;Handle of output file MSGSYN: DB "Syntax: STEP1 TARGET.EXT OUTPUT1.EXT",0D,0A DB " Target.Ext is the file to be dumped.",0D,0A DB " Output1.Ext is the dump file.",0D,0A,024 MSGFNF: DB "File not found$" MSGFCE: DB "File creation error.",0D,0A,024 MSGDSO: DB "Defaulting to standard output filename.",0D,0A,024 MSGTMO: DB "Too many output files, terminating program.",0D,0A,024 MSGNOF: DB "New output file will be ",024 MSGCPR: DB "Copyright 1993 Robert Wallingford, P.E.",0D,0A DB " 2338 N. McVicker Avenue",0D,0A DB " Chicago, IL 60639-2216",0D,0A,0A,"$" TITL: DB "OFFSET 0 1 2 3 4 5 6 7 8 9 A B C D E F" DB " TEXT",0D,0A," ",0C9,51 DUP 0CD,0CB,16 DUP 0CD DB 0BB,0D,0A ND: DB " ",0C8,51 DUP 0CD,0CA,16 DUP 0CD,0BC,0D,0A FLAG: DB 00 ;Quit when = 1 LSIZE: DW 0000 ;Low word of size HSIZE: DW 0000 ;High word of size LINEBUF: DB 20 DUP 00 ;16 bytes at a time NUMB: DW 000F ;Line number OFSET: DB 3 DUP 00,030,020,0BA,020,020 BUFONE: DB 16 DUP (00,00,020),020,0BA, ;String line to new file BUFTWO: DB 16 DUP 00,0BA,0D,0A ;Text section SKIPSP: ;Skip spaces in parameter line INC SI ;Next byte CMP B[SI],020 ;Space? JE SKIPSP ;Loop back RET ;Return SUBR01: ;READ PARAMETERS, OPEN, CREATE FILES, FILL BUFFER, CLOSE TARGET MOV DX,MSGCPR ;Copyright message MOV AH,09 ;Print copyright msg INT 021 ;Using DOS MOV SI,0080 ;Parameters MOV DX,MSGSYN ;Syntax message offset CLD ;Forward CALL SKIPSP ;Skip spaces MOV W[NAMADD1],SI ;Target filename address CMP B[SI],0D ;CR? JNE SUB102 ;No filename JMP SUB111 SUB101: CMP B[SI],0D ;CR? JE SUB103 ;No filename SUB102: CMP B[SI],020 ;Space? JE SUB104 ;End of filename INC SI ;Next byte JMP SUB101 ;Loop back SUB103: MOV B[SI],0 ;Make filename ASCIIZ JMP SUB107 ;Continue, no output file named SUB104: MOV B[SI],0 ;Make filename ASCIIZ CALL SKIPSP ;Skip spaces MOV DI,NAMADD2A ;Output filename address MOV CX,0D ;Max. filename length SUB105: CMP B[SI],0D ;CR ? JE SUB106 ;Continue CMP B[SI],020 ;Space ? JE SUB106 ;Continue LODSB ;Get char. from para. string STOSB ;Put it in filename LOOP SUB105 ;Loop back SUB106: MOV DX,NAMADD2A ;ASCII filename address MOV CX,0 ;Normal attributes MOV AX,05B00 ;Create file INT 021 ;Using DOS MOV W[HANDLE2],AX ;Store handle JNC SUB110 SUB107: MOV DX,MSGDSO ;Message address MOV AH,9 ;Ouput message INT 021 ;Using DOS MOV SI,NAMADD2 ;Standard output f.n. address ADD SI,0A ;First ext. index SUB108: INC B[SI] ;Increment index CMP B[SI],03A ;Not bigger than ASCII 9 JE SUB109 MOV DX,NAMADD2 ;ASCII filename address MOV CX,0 ;Normal attributes MOV AX,05B00 ;Create file INT 021 ;Using DOS MOV W[HANDLE2],AX ;Store handle JC SUB108 ;Repeat loop if creation failed MOV DX,MSGNOF ;New output file message address MOV AH,9 ;Display it INT 021 ;Using DOS MOV B[ADD2B],020 ;Make ASCIIZ a space for display MOV DX,NAMADD2 ;Address of default filename MOV AH,9 ;Display it INT 021 ;Using DOS JMP SUB110 ;Continue SUB109: MOV B[SI],02F ;Reinitialize filename index INC B[SI - 1] ;Increment second index CMP B[SI - 1],03A ;Check second index (99 files maximum) JB SUB108 MOV DX,MSGTMO ;Too many output files message JMP SUB111 ;Exit with message SUB110: MOV DX,W[NAMADD1] ;ASCIIZ filename MOV AX,03D00 ;Open file INT 021 ;Using DOS MOV DX,MSGFNF ;Msg offset JNB SUB112 ;Exit with message SUB111: MOV AH,9 ;Display message INT 021 ;Using DOS MOV AX,04C00 ;Exit program INT 021 ;Using DOS SUB112: MOV W[HANDLE1],AX ;Input file handle MOV BX,AX ;Move file handle MOV AX,04202 ;Move pointer to end XOR CX,CX ;Zero offset from end XOR DX,DX ;Zero offset from end INT 021 ;Using DOS ADD DX,DX ;Using half segments MOV W[HSIZE],DX ;Size high word CMP AX,08000 ;Using half segments JNA SUB113 ;Skip if not bigger INC W[HSIZE] ;Using half segments SUB AX,08000 ;Using half segments SUB113: MOV W[LSIZE],AX ;Size low word MOV AX,04200 ;Move pointer to beginning XOR CX,CX ;Zero offset from start XOR DX,DX ;Zero offset from start INT 021 ;Using DOS RET ;Return SUBR02: ;Puts in first two lines MOV AH,040 ;Write buffer to file MOV BX,W[HANDLE2] ;Output file handle MOV DX,TITL ;Source of write MOV CX,145 ;Length of write INT 021 ;Using DOS RET ;Return SUBR03: ;Reads 16 bytes from input file CMP W[LSIZE],0010 ;Check size low word JA SUB302 ;Skip if still OK CMP W[HSIZE],00 ;Check size high word JNE SUB301 ;Skip if not zero MOV B[FLAG],1 ;Set done flag JMP SUB302 ;Skip alternate possibility SUB301: ADD W[LSIZE],08000 ;Adjust low size word DEC W[HSIZE] ;Adjust high size word SUB302: MOV DX,LINEBUF ;16 bytes from original file MOV CX,0010 ;Max. bytes to read CMP B[FLAG],1 ;Check done flag JNE SUB303 ;Skip if not set MOV CX,W[LSIZE] ;Must reset loop counter SUB303: MOV AH,03F ;Read file MOV BX,W[HANDLE1] ;Input file handle INT 021 ;Using DOS SUB W[LSIZE],AX ;Adjust size low word CMP B[FLAG],1 ;Check done flag JNE SUB304 ;Skip if not set PUSH AX ;Save AX in stack MOV DI,LINEBUF ;Set DI ADD DI,AX ;Add true size of last line MOV CX,010 ;Set counter to 16 SUB CX,AX ;Subtract true line size XOR AL,AL ;Zero for rest of last line REP STOSB ;Write the zeros POP AX ;Recover AX from stack SUB304: RET ;Return SUBR04: ;Prepares output line MOV CX,010 ;Set loop counter MOV DI,BUFONE ;Set DI MOV SI,LINEBUF ;Set SI SUB401: LODSB ;Load byte into AL CALL SUBR05 ;Convert it STOSB ;Store first part MOV AL,AH ;Copy second part to AL STOSB ;Store second part INC DI ;Skip preinstalled space LOOP SUB401 ;Repeat loop RET ;Return SUBR05: ;Modify byte MOV AH,AL ;Copy it to AH AND AL,0F0 ;Get left byte AND AH,0F ;Get right byte ROR AL,1 ;Move from MSB to LSB ROR AL,1 ;Move from MSB to LSB ROR AL,1 ;Move from MSB to LSB ROR AL,1 ;Move from MSB to LSB ADD AL,030 ;Make it ASCII ADD AH,030 ;Make it ASCII CMP AL,039 ;Treat A through F JNA SUB501 ;Skip if not required ADD AL,07 ;Adjust for ASCII letter SUB501: CMP AH,039 ;Treat A through F JNA SUB502 ;Skip if not required ADD AH,07 ;Adjust for ASCII letter SUB502: RET ;Return SUBR06: ;Updates line number MOV DI,OFSET ;Set DI INC W[NUMB] ;Increment line number MOV BX,W[NUMB] ;Load it in BX CMP BX,01000 ;Check size JNE SUB601 ;Skip if OK MOV W[NUMB],0 ;Reset it to zero XOR BX,BX ;Also reset BX SUB601: MOV AX,BX ;Copy it to AX AND AX,0F00 ;Get left byte MOV AL,AH ;Copy it to AL ADD AL,030 ;Make it ASCII CMP AL,039 ;Treat A through F JNA SUB602 ;Skip if not required ADD AL,07 ;Adjust for ASCII letter SUB602: STOSB ;Store modified byte MOV AX,BX ;Copy number to AX AND AX,0F0 ;Get center byte ROR AL,1 ;Move from MSB to LSB ROR AL,1 ;Move from MSB to LSB ROR AL,1 ;Move from MSB to LSB ROR AL,1 ;Move from MSB to LSB ADD AL,030 ;Make it ASCII CMP AL,039 ;Treat A through F JNA SUB603 ;Skip if not required ADD AL,07 ;Adjust for ASCII letter SUB603: STOSB ;Store modified byte MOV AX,BX ;Copy number to AX AND AX,0F ;Get right byte ADD AL,030 ;Make it ASCII CMP AL,039 ;Treat A through F JNA SUB604 ;Skip if not required ADD AL,07 ;Adjust for ASCII letter SUB604: STOSB ;Store modified byte RET ;Return SUBR07: ;Prepare text section MOV SI,LINEBUF ;Set SI MOV DI,BUFTWO ;Set DI MOV CX,010 ;Set loop counter SUB701: LODSB ;Load byte in AL CMP AL,00 ;Is it NUL ? JNE SUB702 ;No, next check MOV AL,030 ;Yes, make it "0" JMP SUB704 ;Write it SUB702: CMP AL,024 ;Is it $ JE SUB704 ;Write it CMP AL,020 ;If it is below JAE SUB703 ; 020 then replace MOV AL,02E ; it with 02E JMP SUB704 ;Skip alternate test SUB703: CMP AL,07A ;If it is above JBE SUB704 ; 020 then replace MOV AL,02E ; it with 02E SUB704: STOSB ;Store byte LOOP SUB701 ;Repeat loop RET ;Return SUBR08: ;Puts in a line MOV AH,040 ;Write buffer to file MOV BX,W[HANDLE2] ;Output file handle MOV DX,OFSET ;Source of write MOV CX,04D ;Length of write INT 021 ;Using DOS RET ;Return SUBR09: ;Puts in last line MOV AH,040 ;Write buffer to file MOV BX,W[HANDLE2] ;Output file handle MOV DX,ND ;Source of write MOV CX,77 ;Length of write INT 021 ;Using DOS RET ;Return JMP00: CALL SUBR01 CALL SUBR02 ;Put in first two lines JMP01: CALL SUBR03 ;Reads 16 bytes from input file CALL SUBR04 ;Prepares output line CALL SUBR06 ;Updates line number CALL SUBR07 ;Prepare text section CALL SUBR08 ;Put in a line CMP B[FLAG],0 ;Check done flag JE JMP01 ;Repeat CALL SUBR09 ;Put in last line MOV AH,03E ;Close file MOV BX,W[HANDLE1] ;Input file handle INT 021 ;Using DOS MOV AH,03E ;Close file MOV BX,W[HANDLE2] ;Output file handle INT 021 ;Using DOS MOV AX,04C00 ;Exit program INT 021 ;Exit END