;$VER: Query.s v1.00 (15-Apr-98)
;Code by Zebedee/A51^CRN
;Just a VERY basic "what is that file type" sort of command!

;I wrote this because I'm pissed off with new file formats being created
;and file ID progs and libs aren't being updated.  Maybe we should have a
;place where new file ID structures are sent to so you can write and get
;a description on how certain files are made?  If anyone wants to send me
;the source to file id utils/libs and the descriptions of any file formats
;you have, I'll glady set a database up.  Write to:

;Ivan Oliver, 39 Beckly Court, Armada Way, Plymouth, Devon, PL1 1LD, ENGLAND

;Pass this source code around and do with it what you will.  I used DevPac
;to write it.

	opt	o+
	section	main,code

ProgStart
	lea	FileNom(pc),a1
.copy	move.b	(a0)+,(a1)+
	bne.b	.copy
	move.w	#0,-(a1)
	move.l	4.w,a6
	lea	Dos_L(pc),a1
	moveq.l	#0,d0
	jsr	-$228(a6)	;OpenLibrary(a1,d0)exec
	move.l	d0,Dos_B
	beq.b	QuitFatal
	move.l	d0,a6
	jsr	-$3c(a6)	;Output()dos
	move.l	d0,Output
	beq.b	ClDos
	lea	FileNom(pc),a1
	cmp.b	#'?',(a1)
	beq	ShowUsage
	cmp.l	#0,(a1)
	beq	ShowTitle
	move.l	a1,d1
	move.l	#$3ed,d2
	jsr	-$1e(a6)	;Open(d1,d2)dos
	move.l	d0,FilePtr
	beq.b	FileNotFound
	move.l	Dos_B(pc),a6
	move.l	FilePtr(pc),d1
	lea	Buffer(pc),a2
	move.l	a2,d2
	moveq.l	#16,d3
	jsr	-$2a(a6)	;Read(d1,d2,d3)dos
ClFile	move.l	Dos_B(pc),a6
	move.l	FilePtr(pc),d1
	jsr	-$24(a6)	;Close(d1)dos
	bsr.b	CheckFileHeader
ClDos	move.l	4.w,a6
	move.l	Dos_B(pc),a1
	jsr	-$19e(a6)	;CloseLibrary(a1)exec
Quit	moveq.l	#0,d0
	rts

QuitFatal
	moveq.l	#20,d0
	rts

FileNotFound
	lea	NoFile(pc),a0
	moveq.l	#22,d3
	bsr.b	PrintText
	bra.b	ClDos

PrintText
	move.l	Dos_B(pc),a6
	move.l	Output(pc),d1
	move.l	a0,d2
	jmp	-$30(a6)	;Write(d1,d2,d3)dos

CheckFileHeader
debug	lea	FileIs(pc),a0
	moveq.l	#8,d3
	bsr.b	PrintText
	lea	Buffer(pc),a0
	lea	Headers(pc),a1
	lea	File_ID(pc),a2
	cmp.b	#'?',(a0)
	beq.b	ShowUsage
	cmp.l	#0,(a0)
	beq.b	ShowTitle
	cmp.l	#'XPKF',(a0)
	beq.b	FileIsXPKF
	cmp.w	#'-l',2(a0)
	beq.b	FileIsLHA
Next	move.l	(a1)+,a3
	cmp.l	(a0),a3
	beq.b	Found
	cmp.l	#0,a3
	beq.b	.eh
	lea	26(a2),a2
	bra.b	Next
.eh	lea	Unknown(pc),a2
Found	move.l	a2,a0
	moveq.l	#26,d3
	bsr.b	PrintText
	rts

FileIsXPKF
	lea	XPKF(pc),a2
	move.l	8(a0),5(a2)
	bra.b	Found

FileIsLHA
	cmp.b	#'h',4(a0)
	bne.b	Next
	lea	LHA(pc),a2
	move.l	2(a0),13(a2)
	bra.b	Found

ShowTitle
	lea	Title(pc),a0
	moveq.l	#58,d3
	bsr	PrintText

ShowUsage
	lea	Usage(pc),a0
	moveq.l	#20,d3
	bsr	PrintText
	bra	ClDos

Version	dc.b	'$VER: Query v1.00 (15-Apr-98)',0
Dos_L	dc.b	'dos.library',0
Dos_B	dc.l	0
Output	dc.l	0
Buffer	dcb.l	4,0
FileNom	dcb.b	255,0
FilePtr	dc.l	0
Title	dc.b	$9b,'0;1;4mQuery v1.00 by Zebedee ©1998 Area 51 & Carnage',$9b,'0m',$a,$a
Usage	dc.b	'Usage: Query <file>',$a
NoFile	dc.b	'ERROR: File not found',$a
FileIs	dc.b	'File is '
Headers	dc.l	$000003f3,$e3100001,"DMS!",$4c5a5800,"MMD0","MMD1","MMD2"
	dc.l	"MMD3","CPLX","SNT!","PM40","PP20","PX20","TRK1","FC-M"
	dc.l	"P40A","MEXX","STP3","PSID","P60A","P61A","CrM!","CrMS"
	dc.l	"SMOD","FC13","FC14","BeEp","FORM",0
File_ID	dc.b	'executable               ',$a
	dc.b	'an icon                  ',$a
	dc.b	'a DMS archive            ',$a
	dc.b	'an LZX archive           ',$a
	dc.b	'a MED module (MMD0)      ',$a
	dc.b	'an OctaMED module (MMD1) ',$a
	dc.b	'an OctaMED module (MMD2) ',$a
	dc.b	'an OctaMED module (MMD3) ',$a
	dc.b	'a TrackerPacker module   ',$a
	dc.b	'a ProRunner 2.0 module   ',$a
	dc.b	'a Promizer 4.0 module    ',$a
	dc.b	'PowerPacker data         ',$a
	dc.b	'PowerPacker enc data     ',$a
	dc.b	'a Module Protector module',$a
	dc.b	'a FC-M Packer module     ',$a
	dc.b	'a The Player 4.xx module ',$a
	dc.b	'a TrackerPacker 1/2 mod  ',$a
	dc.b	'a SoundTracker Pro 3 mod ',$a
	dc.b	'a SID module (C64)       ',$a
	dc.b	'a The Player 6.0 module  ',$a
	dc.b	'a The Player 6.1 module  ',$a
	dc.b	'CrunchMania (CrM!)       ',$a
	dc.b	'CrunchMania (CrMS)       ',$a
	dc.b	'a Future Composer module ',$a
	dc.b	'Future Composer v1.3 mod ',$a
	dc.b	'Future Composer v1.4 mod ',$a
	dc.b	'a JamCracker module      ',$a
	dc.b	'an unknown IFF file      ',$a
XPKF	dc.b	'XPK (????)               ',$a
LHA	dc.b	'LHA archive (????)       ',$a
Unknown	dc.b	'unknown                  ',$a
	end