home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / enterprs / cpm / utils / a / batch.lbr / IFNOT.AQM / IFNOT.ASM
Encoding:
Assembly Source File  |  1993-03-31  |  3.5 KB  |  136 lines

  1. ;
  2. ; IFNOT.ASM    Version 1.0    May 25, 1987
  3. ;
  4. ; Note:  This program requires CP/M Plus (CP/M 3.0) and a Z80 CPU.
  5. ;
  6. ; USAGE:    IFNOT {d:}<fn.ft>
  7. ;
  8. ; If a drive specification is not given, the default drive is
  9. ; assumed.  If a filename is not given, "No Filename Specified"
  10. ; will be reported and a "failure" code will be sent to the BDOS.
  11. ; If the file is found and it is not zero length, "File Found"
  12. ; will be reported and a "failure" code will be sent to the BDOS.
  13. ; If the specified file is not found on the drive, or if the file
  14. ; is a zero length file, the situation will be reported and no
  15. ; return code will be sent to the BDOS.
  16. ;
  17. ; In a SUBMIT (.SUB) file or in a multiple command line a command
  18. ; that has a colon as the first character is ignored if the
  19. ; previous command returns a "failure"code; otherwise it is
  20. ; executed normally.  Thus, if IFNOT finds the file on the specified
  21. ; drive, the following conditional command WILL NOT be executed.
  22. ; Remember:
  23. ;*    ifnot filename [exists]!:command [will not be executed]
  24. ;
  25. ;    Gene Pizzetta            CompuServe:  72060,505
  26. ;    481 Revere Street        QuantumLink:  GeneP
  27. ;    Revere, MA  02151        FOG #29:  (617) 288-4667
  28. ;    Voice: (617) 284-0891
  29. ;
  30. ; Assemble with MAC and load with HEXCOM.  Z80.LIB required.
  31. ; Note:  The line above marked with an * will generate an error
  32. ; message, but it causes no harm.
  33. ;
  34. Bdos    equ    05h        ; BDOS entry
  35. WBoot    equ    00h        ; warm boot
  36. TPA    equ    0100h        ; program load address
  37. Fail    equ    0FF00h        ; program failure code
  38. ;
  39. ; file control block
  40. ;
  41. Fcb    equ    05Ch        ; default file control block
  42. FcbDr    equ    Fcb        ; drive
  43. FcbName    equ    Fcb+1        ; filename
  44. FcbType    equ    Fcb+9        ; filetype
  45. FcbEx    equ    Fcb+12        ; extent
  46. FcbRc    equ    Fcb+15        ; record count
  47. FcbCr    equ    Fcb+32        ; current record
  48. FcbR0    equ    Fcb+33        ; random record, LSB
  49. FcbR1    equ    Fcb+34        ; random record, middle byte
  50. FcbR2    equ    Fcb+35        ; random record, MSB
  51. ;
  52. ; BDOS service functions
  53. ;
  54. PrtStr    equ    9
  55. GetStr    equ    10
  56. FOpen    equ    15
  57. FClose    equ    16
  58. FRead    equ    20
  59. SetDma    equ    26
  60. FSize    equ    35
  61. FMulti    equ    44
  62. BdosRet    equ    108
  63. FParse    equ    152
  64. ;
  65. LF    equ    0Ah        ; linefeed
  66. CR    equ    0Dh        ; carriage return
  67. ;
  68.     MACLIB    Z80
  69. ;
  70.     org    TPA
  71.     jmp    MAIN
  72. ;
  73. Msg1:    db    'IFNOT  1.0 -- $'
  74. Msg2:    db    'No Filename Specified -- $'
  75. Msg3:    db    'Ignore Conditional$'
  76. Msg4:    db    'Execute Conditional$'
  77. Msg5:    db    'Zero Length File -- $'
  78. Msg6:    db    'File Not Found -- $'
  79. Msg7:    db    'File Found -- $'
  80. ;
  81. MAIN:    lxi    d,Msg1        ; print sign-on
  82.     mvi    c,PrtStr
  83.     call    Bdos
  84.     lda    FcbName        ; check for filename
  85.     cpi    'A'
  86.     jrnc    ISFILE        ; (filename found)
  87.     lxi    d,Msg2        ; print 'no file'
  88.     mvi    c,PrtStr
  89.     call    Bdos
  90.     jr    ABORT        ; ..and abort
  91. ;
  92. ISFILE:    lxi    d,Fcb        ; point to FCB
  93.     mvi    c,FSize        ; get file size
  94.     call    Bdos
  95.     inr    a        ; does the file exist?
  96.     jrz    NOFILE
  97.     lda    FcbR0        ; check LSB
  98.     cpi    0        ; greater than zero?
  99.     jrnz    FOUND        ; (yes, a failure)
  100.     lda    FcbR1        ; check middle byte
  101.     cpi    0
  102.     jrnz    FOUND
  103.     lda    FcbR2        ; check MSB
  104.     cpi    0
  105.     jrnz    FOUND
  106.     lxi    d,Msg5        ; it must be a null file
  107.     mvi    c,PrtStr    ; ..so print message
  108.     call    Bdos
  109.     jr    SUCC        ; ..and report success
  110. ;
  111. NOFILE:    lxi    d,Msg6        ; print 'not found'
  112.     mvi    c,PrtStr
  113.     call    Bdos
  114.     jr    SUCC        ; ..and report success
  115. ;
  116. FOUND:    lxi    d,Msg7        ; print 'file found'
  117.     mvi    c,PrtStr
  118.     call    BDOS
  119.     jr    ABORT        ; ..and abort
  120. ;
  121. ABORT:    lxi    d,Fail        ; send 'failure' code
  122.     mvi    c,BdosRet
  123.     call    Bdos
  124.     lxi    d,Msg3        ; ..and print failure message
  125.     mvi    c,PrtStr
  126.     call    Bdos
  127.     jr    EXIT
  128. ;
  129. SUCC:    lxi    d,Msg4        ; print success message
  130.     mvi    c,PrtStr
  131.     call    Bdos
  132. ;
  133. EXIT:    jmp    WBoot        ; warm boot
  134. ;
  135.     end
  136.