home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / cpm / filutl / comid1.lbr / COMID.MQC / COMID.MAC
Text File  |  1985-11-30  |  3KB  |  133 lines

  1.     TITLE    'COMID - AN ATTEMPT TO IDENTIFY COM FILES'
  2. ;
  3. ; NOTICE:
  4. ;    Inspired by a question by Bill Duerr on the SYSOP system,
  5. ;    I have written this program. Its sole purpose is to take
  6. ;    a stab at the identity of a .COM file (or .OBJ if used on
  7. ;    a remote system) and say it may be an MSDOS or a CP/M
  8. ;    command file.
  9. ;    There is sufficient room for improvement. This is only a
  10. ;    first attempt and anyone please feel free to add their
  11. ;    (useful, please!!!) ideas.
  12. ;    This program was written by Sigi Kluger (also known as
  13. ;    ESKAY Software) and is fully released into the Public
  14. ;    Domain with no strings attached and no restrictions.
  15. ;
  16. .request syslib
  17. ; Rick Conn's SYSLIB version 3.x is required for reassembly.
  18. ; Externals are declared on the fly, M80-convention.
  19. ;
  20. .z80
  21. ; Z80 mnemonics used, but only 8080 subset.
  22. ;
  23. cr    equ    0dh
  24. lf    equ    0ah
  25. ;
  26. dfcb    equ    5ch
  27. dbuf    equ    80h
  28. ;
  29.     cseg
  30. ;
  31. start:    ld    hl,0        ; save stack pointer
  32.     add    hl,sp
  33.     ld    (stksav),hl
  34.     ld    sp,stack    ; set up local stack
  35.     call    print##
  36.     cr,lf,lf
  37.     'COMID ver 1.00 by ESKAY - COM file identifier',cr,lf,lf,0
  38.     ld    a,(dfcb+1)    ; see if argument typed
  39.     cp    ' '
  40.     jp    nz,gotarg    ; yes, got some argument
  41.     call    print##        ;   else complain and give up trying
  42.     'USAGE:',cr,lf
  43.     '  A>comid pip.com',cr,lf
  44.     '  B>comid a:test.obj',cr,lf
  45.     '  A>comid stat       (.COM may be omitted)',cr,lf,lf,0
  46.     jp    quit        ; back to O/S
  47. ;
  48. ; got an argument, now see if COM or whatever
  49. ;
  50. gotarg:    ld    hl,dfcb+9    ; point to filetype
  51.     ld    a,(hl)        ; get first byte
  52.     cp    ' '        ; empty?
  53.     jp    z,mkecom    ;   yes, make .COM
  54.     cp    'C'        ; now check for COM or OBJ
  55.     jp    z,ck2
  56.     cp    'O'
  57.     jp    nz,ncom        ; error - not COM, OBJ or blank
  58. ck2:    inc    hl
  59.     ld    a,(hl)
  60.     cp    'O'
  61.     jp    z,ck3
  62.     cp    'B'
  63.     jp    nz,ncom        ; error - not COM, OBJ or blank
  64. ck3:    inc    hl
  65.     ld    a,(hl)
  66.     cp    'M'
  67.     jp    z,isco        ; ok, is COM
  68.     cp    'J'
  69.     jp    z,isco        ; ok, is OBJ
  70. ncom:    call    print##
  71.     'ERROR: Argument must be .COM or .OBJ (no type = COM)',cr,lf,lf,0
  72. quit:    ld    hl,(stksav)    ; get entry stack
  73.     ld    sp,hl
  74.     ret            ; back to caller (usually CCP)
  75. ;
  76. mkecom:    ld    (hl),'C'    ; make .COM
  77.     inc    hl
  78.     ld    (hl),'O'
  79.     inc    hl
  80.     ld    (hl),'M'
  81. isco:    ld    de,dfcb        ; point to fcb
  82.     call    f$open##    ; attempt to open file
  83.     jp    z,isopn        ; gotcha!
  84.     call    print##
  85.     'ERROR: specified file cannot be found',cr,lf,lf,0
  86.     jp    quit
  87. ;
  88. isopn:    call    f$read##    ; attempt to read first block
  89.     jp    z,isrd        ; ok read
  90.     call    print##
  91.     'ERROR: file appears empty',cr,lf,lf,0
  92.     jp    quit
  93. ;
  94. isrd:    ld    a,(dbuf)    ; now get file's first byte
  95.     cp    0C3H        ; most likely it's a JMP
  96.     jp    z,iscpm
  97.     cp    31H        ; maybe a LD SP,...
  98.     jp    z,iscpm
  99.     cp    18H        ; or maybe a JR
  100.     jp    z,iscpm
  101.     cp    21H        ; a LD HL,... maybe?
  102.     jp    z,iscpm
  103.     cp    2AH        ; BDS C always does a LD HL,(6)...
  104.     jp    z,iscpm
  105.     cp    1        ; LD BC,...???
  106.     jp    z,iscpm
  107.     cp    0CDH        ; some start with a CALL!!!
  108.     jp    z,iscpm
  109. ;
  110. ; here is room for improvement...
  111. ; (add YOUR favorite 8080 code a program is most likely to start with)
  112. ;
  113. ; we assume that whatever is not already identified must be an 8086
  114. ; instruction and proclaim this to be a mushdos file.
  115. ;
  116.     call    print##
  117.     'This file seems to be an MS-DOS COM file.',cr,lf,lf,0
  118.     jp    quit
  119. ;
  120. iscpm:    call    print##
  121.     'This file is almost certainly a CP/M-80 COM file.',cr,lf,lf,0
  122.     jp    quit
  123. ;
  124.     dseg
  125. ;
  126. stksav:    dw    0        ; entry stack save
  127.     ds    40        ; 20-level stack should be enuf
  128. stack    equ    $
  129.     end
  130. d##    ; attempt to read first block
  131.     jp    z,isrd        ; ok read
  132.     call    print##
  133.     'ERROR: file appears empty',cr,lf,lf,