home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / CPROG / TASMSWAN.ZIP / KOPY.ASM < prev    next >
Assembly Source File  |  1989-07-17  |  3KB  |  175 lines

  1. %TITLE  "Copy Input to Output"
  2.  
  3.     IDEAL
  4.     DOSSEG
  5.     MODEL    small
  6.     STACK    256
  7.  
  8. ;----- Equates
  9. cr    EQU    13
  10. lf    EQU    10
  11.  
  12.     DATASEG
  13.  
  14. exitCode    db    0
  15. inFile        dw    0
  16. outFile        dw    0
  17. oneByte        db    0
  18. prompt        db    cr,lf,'Erase this file? (y/n) ', 0
  19. diskFull    db    cr,lf,'*** ERROR: disk is FULL', 0
  20.  
  21. notes    db    cr,lf,' KOPY copies all bytes from one file to a new file'
  22.     db    cr,lf,'as a demonstration of file read/write methods'
  23.     db    cr,lf,'in assembly language.  The program can be modified'
  24.     db    cr,lf,'to process data on its way to the output file,'
  25.     db    cr,lf,'although this version makes no changes to the'
  26.     db    cr,lf,'information in the input file.  Use the program by'
  27.     db    cr,lf,'supplying two file names: the first name is the'
  28.     db    cr,lf,'file you want to read; the second is the new file'
  29.     db    cr,lf,'that you want KOPY to create:',cr,lf
  30.     db    cr,lf,'    KOPY <input file> <output file>',cr,lf, 0
  31.  
  32.     CODESEG
  33.  
  34. ;---------- from STRIO.obj
  35.     EXTRN    StrWrite:proc, NewLine:proc
  36.  
  37. ;---------- from DISKERR.obj
  38.     EXTRN    DiskErr:proc
  39.  
  40. ;---------- from PARAMS.obj
  41.     EXTRN    GetParams:proc, ParamCount:proc, GetOneParam:proc
  42.  
  43. Start:
  44.     mov    ax,@data
  45.     mov    es,ax
  46.     call    GetParams
  47.     call    ParamCount
  48.     cmp    dx,2
  49.     je    @@10
  50.     mov    di, offset notes
  51.     call    StrWrite
  52.     jmp    Exit
  53. @@10:
  54.     xor    cx,cx
  55.     call    GetOneParam
  56.     mov    dx,di
  57.     xor    al,al
  58.     mov    ah,3Dh
  59.     int    21h
  60.     jnc    @@20
  61.     jmp    Errors
  62. @@20:
  63.     mov    [inFile],ax
  64.     mov    cx,1
  65.     call    GetOneParam
  66.     mov    dx,di
  67.     call    FileExists
  68.     jc    @@30
  69.     call    StrWrite
  70.     call    Confirm
  71.     je    @@30
  72.     jmp    Exit
  73. @@30:
  74.     mov    cx,1
  75.     call    GetOneParam
  76.     mov    dx,di
  77.     xor    cx,cx
  78.     mov    ah,3Ch
  79.     int    21h
  80.     jnc    @@40
  81.     jmp    Errors
  82. @@40:
  83.     mov    [OutFile],ax
  84. @@50:
  85.     mov    ah,3Fh
  86.     mov    bx,[inFile]
  87.     mov    cx,1
  88.     mov    dx, offset oneByte
  89.     int     21h
  90.     jnc    @@60
  91.     jmp    Errors
  92. @@60:
  93.     or    ax,ax
  94.     jz    @@80
  95.     mov    ah,40h
  96.     mov    bx,[outFile]
  97.     mov    cx,1
  98.     mov    dx, offset oneByte
  99.     int    21h
  100.     jnc    @@70
  101.     jmp    Errors
  102. @@70:
  103.     or    ax,ax
  104.     jnz    @@50
  105.  
  106.     mov    di, offset diskFull
  107.     call    StrWrite
  108. @@80:
  109.     mov    bx,[inFile]
  110.     mov    ah,3Eh
  111.     int    21h
  112.     mov    bx,[outFile]
  113.     mov    ah,3Eh
  114.     int    21h
  115.     jnc    Exit
  116.     jmp    Errors
  117. Exit:
  118.     mov    ah,04Ch
  119.     mov    al,[exitCode]
  120.     int    21h
  121. Errors:
  122.     mov    [exitCode],al
  123.     call    DiskErr
  124.     jmp    Exit
  125. %NEWPAGE
  126. ;------------------------------------------------------------------------
  127. ; FileExists - tests whether a file already exists
  128. ;------------------------------------------------------------------------
  129. ;    Input:  ds:dx = address of ASCIIZ file name
  130. ;    Output: cf = 0 : (jnc) file of this name exits
  131. ;        cf = 1 : (jc)  file of this name does not exist
  132. ;       Registers:
  133. ;------------------------------------------------------------------------
  134. PROC    FileExists
  135.     xor    al,al
  136.     mov    ah,3Dh
  137.     int    21h
  138.     jc    @@99
  139.     mov    bx,ax
  140.     mov    ah,3Eh
  141.     int    21h
  142.     clc
  143. @@99:
  144.     ret
  145. ENDP    FileExists
  146. %NEWPAGE
  147. ;------------------------------------------------------------------------
  148. ; Confirm -  get YES/NO answer from user
  149. ;------------------------------------------------------------------------
  150. ;    Input:  none
  151. ;    Output: zf = 0 : (jnz) user typed N or n
  152. ;        zf = 1 : (jz)  user typed Y or y
  153. ;       Registers:
  154. ;------------------------------------------------------------------------
  155. PROC    Confirm
  156.     mov    di, offset Prompt
  157.     call    StrWrite
  158.     mov    ah,1
  159.     int    21h
  160.     cmp    al,'Y'
  161.     je    @@99
  162.     cmp    al,'y'
  163.     je    @@99
  164.     cmp    al,'N'
  165.     je    @@20
  166.     cmp    al,'n'
  167.     jne    Confirm
  168. @@20:
  169.     cmp    al,'@'
  170. @@99:
  171.     ret
  172. ENDP    Confirm
  173.  
  174.     END    Start
  175.