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

  1. %TITLE  "Filter shell"
  2.  
  3.     IDEAL
  4.     DOSSEG
  5.     MODEL    small
  6.     STACK    256
  7.  
  8. ;----- Equates
  9. InputHandle        EQU    0
  10. OutputHandle        EQU    1
  11. ErrOutHandle        EQU    2
  12. bell            EQU    07
  13. cr            EQU    13
  14. lf            EQU    10
  15. eof            EQU    26
  16.  
  17.  
  18.     DATASEG
  19.  
  20. exitCode    db    0
  21. errMessage    db    bell,cr,lf, '** Filter ERROR: '
  22. lenErrMessage    =    $-errMessage
  23. codeAccess    EQU    5
  24. errAccess    db    'access denied',cr,lf
  25. lenErrAccess    =    $-errAccess
  26. codeNotOpen    EQU    6
  27. errNotOpen    db    'bad handle or file not open', cr,lf
  28. lenErrNotOpen    =    $-errNotOpen
  29. codeDiskFull    EQU    29
  30. errDiskFull    db    'disk full',cr,lf
  31. lenErrDiskFull    =    $-errDiskFull
  32. errGeneral    db    'unknown cause',cr,lf
  33. lenErrGeneral    =    $-errGeneral
  34. onechar    db    ?
  35.  
  36.  
  37.     CODESEG
  38.  
  39. Start:
  40.     mov    ax,@data
  41.     mov    ds,ax
  42.     mov    es,ax
  43.  
  44. Repeat:
  45.     call    ReadChar
  46.     jz    Done
  47.     call    WriteChar
  48.     jnz    Repeat
  49.     mov    [exitCode],codeDiskFull
  50.     jmp    Exit
  51. Done:
  52.     mov    [oneChar],eof
  53.     call    WriteChar
  54. Exit:
  55.     cmp    [exitCode],0
  56.     jz    @@99
  57.     call    DisplayError
  58. @@99:
  59.     mov    ah,04Ch
  60.     mov    al,[exitCode]
  61.     int    21h
  62. %NEWPAGE
  63. ;----------------------------------------------------------------------
  64. ;  ReadChar - reads one character from standard input
  65. ;----------------------------------------------------------------------
  66. ;     Input: none
  67. ;       Output: zf = 0 : al = next input character (0...255)
  68. ;               zf = 1 : no more input available
  69. ;       Registers: ax
  70. ;----------------------------------------------------------------------
  71. PROC    ReadChar
  72.     push    bx
  73.     push    cx
  74.     push    dx
  75.     mov    ah,03Fh
  76.     mov    bx,InputHandle
  77.     mov    cx,1
  78.     mov    dx, offset oneChar
  79.     int    21h
  80.     jnc    @@10
  81.     mov    [exitCode],al
  82.     jmp    Exit
  83. @@10:
  84.     or    ax,ax
  85.     pop    dx
  86.     pop    cx
  87.     pop    bx
  88.     ret
  89. ENDP    ReadChar
  90. %NEWPAGE
  91. ;----------------------------------------------------------------------
  92. ;  WriteChar - writes one character to standard output
  93. ;----------------------------------------------------------------------
  94. ;     Input: [oneChar] = character to write
  95. ;       Output: zf = 0 : character written to standard output file
  96. ;               zf = 1 : output device is FULL (disk output only)
  97. ;       Registers: ax
  98. ;----------------------------------------------------------------------
  99. PROC    WriteChar
  100.     push    bx
  101.     push    cx
  102.     push    dx
  103.     mov    ah,040h
  104.     mov    bx,OutputHandle
  105.     mov    cx,1
  106.     mov    dx, offset oneChar
  107.     int    21h
  108.     jnc    @@10
  109.     mov    [exitCode],al
  110.     jmp    Exit
  111. @@10:
  112.     or    ax,ax
  113.     pop    dx
  114.     pop    cx
  115.     pop    bx
  116.     ret
  117. ENDP    WriteChar
  118. %NEWPAGE
  119. ;----------------------------------------------------------------------
  120. ;  DisplayError - displays error message
  121. ;----------------------------------------------------------------------
  122. ;     Input: [exitCode] = nonZero error code
  123. ;       Output: none: error message sent to standard error-output device
  124. ;       Registers: ax,bx,cx,dx
  125. ;----------------------------------------------------------------------
  126. PROC    DisplayError
  127.     mov    cx,lenErrMessage
  128.     mov    dx, offset errMessage
  129.     call    DisplayString
  130.     cmp    [exitCode],codeAccess
  131.     jne    @@10
  132.     mov    cx,lenErrAccess
  133.     mov    dx, offset errAccess
  134.     jmp    DisplayString
  135. @@10:
  136.     cmp    [exitCode],codeNotOpen
  137.     jne    @@20
  138.     mov    cx,lenErrNotOpen
  139.     mov    dx, offset errNotOpen
  140.     jmp    DisplayString
  141. @@20:
  142.     cmp    [exitCode], codeDiskFull
  143.     jne    @@30
  144.     mov    cx, lenErrDiskFull
  145.     mov    dx,offset errDiskFull
  146.     jmp    DisplayString
  147. @@30:
  148.     mov    cx, lenErrGeneral
  149.     mov    dx, offset errGeneral
  150. DisplayString:
  151.     mov    ah,040h
  152.     mov    bx,ErrOutHandle
  153.     int    21h
  154.     ret
  155. ENDP    DisplayError
  156.  
  157.     END    Start
  158.