home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_GEN / PMODE24.ZIP / EXAMPLES.ZIP / EX_PM5.ASM < prev    next >
Assembly Source File  |  1994-02-05  |  5KB  |  136 lines

  1. ; This program uses FILE and ARGC to copy one file to another.
  2.  
  3.         .386p
  4. code32  segment para public use32
  5.         assume cs:code32, ds:code32
  6.  
  7. include pmode.inc
  8. include file.inc
  9. include argc.inc
  10.  
  11. public  _main
  12.  
  13. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  14. ; DATA
  15. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  16.  
  17. input_fnm       db      80h dup(?)
  18. output_fnm      db      80h dup(?)
  19.  
  20. msg0            db      'SYNTAX: EX_PM5 <input filename> <output filename>$'
  21. msg1            db      'Not enough low memory to allocate low file buffer.$'
  22. msg2            db      'Could not open input file.$'
  23. msg3            db      'Not enough memory to load input file.$'
  24. msg4            db      'Error reading from input file.$'
  25. msg5            db      'Output file already exists, will not overwrite.$'
  26. msg6            db      'Could not create output file.$'
  27. msg7            db      'Error writing to output file.$'
  28. msg8            db      'File copied successfully.$'
  29.  
  30. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  31. ; CODE
  32. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  33.  
  34. ;═════════════════════════════════════════════════════════════════════════════
  35. _main:
  36.         sti
  37.  
  38.         mov al,1                        ; get 2nd string on command line if
  39.         mov edx,offset output_fnm       ;  present
  40.         call _cchekstr
  41.         jc done0
  42.         xor al,al                       ; 2nd string present, so the first is
  43.         mov edx,offset input_fnm        ;  definately there
  44.         call _cchekstr
  45.  
  46.         movzx eax,_filebuflen           ; allocate low memory for file buffer
  47.         call _getlomem                  ;  it will only be used if high memory
  48.         jc done1                        ;  is needed to load in the full input
  49.         mov _filebufloc,eax             ;  file
  50.  
  51.         mov edx,offset input_fnm        ; try to open input file
  52.         call _openfile
  53.         jc done2
  54.  
  55.         call _filesize                  ; opened, get its size
  56.  
  57.         mov ebp,eax                     ; preserve size for later use
  58.         call _getmem                    ; allocate that much mem, low or high
  59.         jc done3
  60.  
  61.         mov edi,eax                     ; preserve ptr for later use
  62.         mov edx,eax                     ; read in whole file
  63.         mov ecx,ebp
  64.         call _readfile
  65.         jc done4
  66.  
  67.         call _closefile                 ; close input file
  68.  
  69.         mov edx,offset output_fnm       ; try to open output file, if it opens
  70.         call _openfile                  ;  then its already present and we
  71.         jnc done5                       ;  will not overwrite it
  72.  
  73.         call _createfile                ; does not exist, create it
  74.         jc done6
  75.  
  76.         mov edx,edi                     ; write data from input file to output
  77.         mov ecx,ebp
  78.         call _writefile
  79.         jc done7
  80.  
  81.         call _closefile                 ; close output file
  82.  
  83.         mov edx,offset msg8
  84.         jmp done
  85.  
  86. ;─────────────────────────────────────────────────────────────────────────────
  87. done0:
  88.         mov edx,offset msg0
  89.         jmp short done
  90. ;─────────────────────────────────────────────────────────────────────────────
  91. done1:
  92.         mov edx,offset msg1
  93.         jmp short done
  94. ;─────────────────────────────────────────────────────────────────────────────
  95. done2:
  96.         mov edx,offset msg2
  97.         jmp short done
  98. ;─────────────────────────────────────────────────────────────────────────────
  99. done3:
  100.         mov edx,offset msg3
  101.         jmp short done
  102. ;─────────────────────────────────────────────────────────────────────────────
  103. done4:
  104.         call _closefile
  105.         mov edx,offset msg4
  106.         jmp short done
  107. ;─────────────────────────────────────────────────────────────────────────────
  108. done5:
  109.         call _closefile
  110.         mov edx,offset msg5
  111.         jmp short done
  112. ;─────────────────────────────────────────────────────────────────────────────
  113. done6:
  114.         mov edx,offset msg4
  115.         jmp short done
  116. ;─────────────────────────────────────────────────────────────────────────────
  117. done7:
  118.         call _closefile
  119.         mov edx,offset msg5
  120. ;-----------------------------------------------------------------------------
  121. done:
  122.         add edx,_code32a                ; put message with INT 21h AH=9
  123.         shld eax,edx,28
  124.         and edx,0fh
  125.         mov v86r_ds,ax
  126.         mov v86r_dx,dx
  127.         mov v86r_ah,9
  128.         mov al,21h
  129.         int 33h
  130.  
  131.         jmp _exit
  132.  
  133. code32  ends
  134.         end
  135.  
  136.