TITLE 'COMID - AN ATTEMPT TO IDENTIFY COM FILES' ; ; NOTICE: ; Inspired by a question by Bill Duerr on the SYSOP system, ; I have written this program. Its sole purpose is to take ; a stab at the identity of a .COM file (or .OBJ if used on ; a remote system) and say it may be an MSDOS or a CP/M ; command file. ; There is sufficient room for improvement. This is only a ; first attempt and anyone please feel free to add their ; (useful, please!!!) ideas. ; This program was written by Sigi Kluger (also known as ; ESKAY Software) and is fully released into the Public ; Domain with no strings attached and no restrictions. ; .request syslib ; Rick Conn's SYSLIB version 3.x is required for reassembly. ; Externals are declared on the fly, M80-convention. ; .z80 ; Z80 mnemonics used, but only 8080 subset. ; cr equ 0dh lf equ 0ah ; dfcb equ 5ch dbuf equ 80h ; cseg ; start: ld hl,0 ; save stack pointer add hl,sp ld (stksav),hl ld sp,stack ; set up local stack call print## cr,lf,lf 'COMID ver 1.00 by ESKAY - COM file identifier',cr,lf,lf,0 ld a,(dfcb+1) ; see if argument typed cp ' ' jp nz,gotarg ; yes, got some argument call print## ; else complain and give up trying 'USAGE:',cr,lf ' A>comid pip.com',cr,lf ' B>comid a:test.obj',cr,lf ' A>comid stat (.COM may be omitted)',cr,lf,lf,0 jp quit ; back to O/S ; ; got an argument, now see if COM or whatever ; gotarg: ld hl,dfcb+9 ; point to filetype ld a,(hl) ; get first byte cp ' ' ; empty? jp z,mkecom ; yes, make .COM cp 'C' ; now check for COM or OBJ jp z,ck2 cp 'O' jp nz,ncom ; error - not COM, OBJ or blank ck2: inc hl ld a,(hl) cp 'O' jp z,ck3 cp 'B' jp nz,ncom ; error - not COM, OBJ or blank ck3: inc hl ld a,(hl) cp 'M' jp z,isco ; ok, is COM cp 'J' jp z,isco ; ok, is OBJ ncom: call print## 'ERROR: Argument must be .COM or .OBJ (no type = COM)',cr,lf,lf,0 quit: ld hl,(stksav) ; get entry stack ld sp,hl ret ; back to caller (usually CCP) ; mkecom: ld (hl),'C' ; make .COM inc hl ld (hl),'O' inc hl ld (hl),'M' isco: ld de,dfcb ; point to fcb call f$open## ; attempt to open file jp z,isopn ; gotcha! call print## 'ERROR: specified file cannot be found',cr,lf,lf,0 jp quit ; isopn: call f$read## ; attempt to read first block jp z,isrd ; ok read call print## 'ERROR: file appears empty',cr,lf,lf,0 jp quit ; isrd: ld a,(dbuf) ; now get file's first byte cp 0C3H ; most likely it's a JMP jp z,iscpm cp 31H ; maybe a LD SP,... jp z,iscpm cp 18H ; or maybe a JR jp z,iscpm cp 21H ; a LD HL,... maybe? jp z,iscpm cp 2AH ; BDS C always does a LD HL,(6)... jp z,iscpm cp 1 ; LD BC,...??? jp z,iscpm cp 0CDH ; some start with a CALL!!! jp z,iscpm ; ; here is room for improvement... ; (add YOUR favorite 8080 code a program is most likely to start with) ; ; we assume that whatever is not already identified must be an 8086 ; instruction and proclaim this to be a mushdos file. ; call print## 'This file seems to be an MS-DOS COM file.',cr,lf,lf,0 jp quit ; iscpm: call print## 'This file is almost certainly a CP/M-80 COM file.',cr,lf,lf,0 jp quit ; dseg ; stksav: dw 0 ; entry stack save ds 40 ; 20-level stack should be enuf stack equ $ end