home *** CD-ROM | disk | FTP | other *** search
- .286
-
- Code SEGMENT para PUBLIC 'CODE'
-
- Assume CS:Code, DS:Code
- ORG 100h
-
- ;====================================================================
- cr equ 10
- lf equ 13
-
- ;====================================================================
- Start:
- Call Header ;logo
- Call CmdLine
- cmp al,-1
- je _usage
- Call OpenRFile ;open readfile
- cmp al,-1
- je _norfile
- Call OpenWFile ;open writefile
- cmp al,-1
- je _nowfile
- Call HeadOn ;write header
- _closewfile: Call CloseWFile ;close writefile
- jmp _closerfile
- _nowfile: Call NoFile
- _closerfile: Call CloseRFile ;close readfile
- jmp _ende
- _norfile: Call NoFile
- jmp _ende
- _usage: Call Usage ;display usage
- _ende: Call Footer ;display ---------------------
- mov ax,4c00h
- int 21h
-
- ;====================================================================
- HeadOn PROC near
- pusha
- mov cx,32 ;bytes
- mov ah,40h ;write to file
- mov bx,WFileHandle ;handle of file
- lea dx,exe_header ;data: where at
- int 21h
- jc headon_fail
-
- headon_lop:
- mov ah,3fh ;read
- mov bx,RFileHandle ;handle
- mov cx,63000 ;bytes
- lea dx,loadword ;where at
- int 21h
- or ax,ax ;0 bytes ? !!!!
- jz headon_end ; !!!!
- add filesize,ax
- mov cx,ax ;bytes
- mov ah,40h ;write
- mov bx,WFileHandle ;handle
- lea dx,loadword ;where at
- int 21h
- jc headon_fail
- jmp headon_lop
- headon_end:
- add filesize,32
- xor cx,cx
- mov dx,2 ;where at (cx:dx)
- mov ax,4200h ;move filepointer to (from files begin)
- mov bx,WFileHandle ;handle
- int 21h
- mov ax,filesize
- and ax,511
- mov loadword,ax ;length mod 512
- mov ax,filesize
- mov cl,9
- shr ax,cl ;div 512
- inc ax
- mov [loadword+2],ax ;pages
- mov cx,4 ;bytes
- mov ah,40h ;write
- mov bx,WFileHandle ;handle
- lea dx,loadword ;where at
- int 21h
- lea dx,headon_
- Call Print
- popa
- ret
- headon_fail:
- lea dx,headon_fail_
- Call Print
- CALL FileName
- popa
- mov al,-1
- ret
- headon_ db 'CREATED EXE-FILE',cr,lf,'$'
- headon_fail_ db 'CANNOT WRITE TO $'
- exe_header db 'MZ' ;offset 00 (EXE-signature)
- dw 0,0 ;bytes on last page, pages
- dw 0 ;relocations
- dw 2 ;size of header in paragraphs
- dw 1000h,-1 ;minimum, maximum memory
- dw 0fff0h,0fffeh ;ss,sp values (ss=PSP)
- dw 0 ;checksum
- dw 100h,0fff0h ;ip,cs values (cs=PSP)
- dw 1ch ;offset to reloc table
- dw 0,0,0 ;overlay number, 0,0 (fill-ups)
- HeadOn ENDP
-
- ;====================================================================
- CloseRFile PROC near
- pusha
- mov bx,RFileHandle
- mov ah,3eh
- int 21h
- popa
- ret
- CloseRFile ENDP
-
- ;====================================================================
- CloseWFile PROC near
- pusha
- mov bx,WFileHandle
- mov ah,3eh
- int 21h
- popa
- ret
- CloseWFile ENDP
-
- ;====================================================================
- NoFile PROC near
- pusha
- lea dx,nofile_
- Call Print
- Call FileName
- popa
- ret
- nofile_ db 'CANNOT OPEN FILE $'
- NoFile ENDP
-
- ;====================================================================
- OpenRFile PROC near
- pusha
- mov dx,82h ;asciiz = cmdline
- mov ax,3d00h ;open it for read
- int 21h
- jc openrfile_fail
- mov RFileHandle,ax
- lea dx,openrfile_
- Call Print
- Call FileName
- popa
- ret
- openrfile_fail:
- popa
- mov al,-1
- ret
- openrfile_ db 'OPENED FILE $'
- OpenRFile ENDP
-
- ;====================================================================
- OpenWFile PROC near
- pusha
- xor ah,ah
- mov al,ds:80h
- mov di,ax
- mov ds:[di+80h-2],'XE'
- mov byte ptr ds:[di+80h],'E'
- mov dx,82h ;asciiz = cmdline
- mov ah,3ch ;open it for write
- mov cx,0 ;attribute
- int 21h
- cmp ax,0
- je openwfile_fail
- mov WFileHandle,ax
- lea dx,openwfile_
- Call Print
- Call FileName
- popa
- ret
- openwfile_fail:
- popa
- mov al,-1
- ret
- openwfile_ db 'OPENED FILE $'
- OpenWFile ENDP
-
- ;====================================================================
- CmdLine PROC near
- pusha
- xor ah,ah
- mov al,ds:80h
- cmp ax,6 ;less than 5 chars (cmd-LINE) incl. ret?
- jl cmdline_fail
- mov di,ax
- mov word ptr ds:[di+81h],'$'*256
- popa
- ret
- cmdline_fail:
- popa
- mov al,-1
- ret
- CmdLine ENDP
-
- ;====================================================================
- Header PROC near
- pusha
- lea dx,header_
- Call Print
- popa
- ret
- header_ db cr,lf
- db '∙∙--==--∙∙ COM2EXE ∙∙--==--∙∙ by HENDR¡X of OBSESSION',cr,lf,'$'
- Header ENDP
-
- ;====================================================================
- Footer PROC near
- pusha
- lea dx,footer_
- Call Print
- popa
- ret
- footer_ db '--==**==-- COM2EXE --==**==--',cr,lf,'$'
- Footer ENDP
-
- ;====================================================================
- Usage PROC near
- pusha
- lea dx,usage_
- Call Print
- popa
- ret
- usage_ db 'USAGE: C2E PROGRAM.COM',cr,lf,'$'
- Usage ENDP
-
- ;====================================================================
- Print PROC near
- mov ah,09h
- int 21h
- ret
- Print ENDP
-
- ;====================================================================
- Return PROC near
- pusha
- lea dx,return_
- Call Print
- popa
- ret
- return_ db cr,lf,'$'
- Return ENDP
-
- ;====================================================================
- FileName PROC near
- pusha
- mov dx,82h
- Call Print
- Call Return
- popa
- ret
- FileName ENDP
-
- ;====================================================================
- filesize dw 0
- RFileHandle dw ?
- WFileHandle dw ?
- loadword dw ?
-
- ;====================================================================
- Code ENDS
- END Start
-