	title	show IDE drive type
;++
;
; Show IDE drive type.
;
; By John Wilson, wilsonj@alumni.rpi.edu.
;
; 02/02/93	JMBW	Created.
;
;--
	.radix	8
;
pcat=	1	;0 => my homemade 8/16-bit IDE controller
		;1 => standard PC AT IDE controller
;
if pcat ; normal controller
ide=	1F0h	;8-bit IDE register file
idedat=	1F0h	;16-bit data port is register 0
else ; my homemade controller
ide=	3E0h	;normal 8-bit IDE register file
idedat=	7E0h	;16-bit data latches
endif
;
print	macro	text
	local	a,b
	call	wrasc
a	db	b,text
b=	$-a-1
	endm
;
code	segment
	assume	cs:code
	org	100h
	.186			;INSW/OUTSW
start:	cld
	mov	si,80h		;point at command line
	lodsb			;get length
	cbw			;ah=0
	mov	cx,ax		;copy
	mov	dx,ide+6	;drive/head reg
	jcxz	sk2
lp1:	lodsb			;get a byte
	cmp	al,' '		;blank or ctrl?
	jbe	sk1
	cmp	al,'/'		;ignore switches
	je	sk1
	cmp	al,'-'
	je	sk1
	cmp	al,'0'		;0?
	je	sk2
	cmp	al,'1'		;1?
	jne	usage		;no, get usage
	mov	al,260		;constant bits, drive #1, hd #0
	jmp	short sk3	;go display
usage:	print	'SHOWIDE n  (where n is IDE drive #, 0 or 1)'
	call	crlf
	int	20h
sk1:	loop	lp1
sk2:	mov	al,240		;constant bits, drive #0, hd #0
sk3:	out	dx,al
	inc	dx		;command reg
	mov	al,354		;func=identify drive
	out	dx,al
lp2:	; wait until ready
	in	al,dx		;read status
	test	al,10		;DRQ?
	jz	lp2
	mov	dx,idedat	;point at data reg
	mov	di,offset buf
	mov	cx,1000/2	;wc
	rep	insw		;read data
;;; read parms
	mov	ax,word ptr ds:buf ;get config bits
	mov	ds:config,ax
	mov	ax,word ptr ds:buf+2 ;get # of cylinders
	mov	ds:ncyls,ax
	mov	ax,word ptr ds:buf+6 ;get # of heads
	mov	ds:nhds,ax
	mov	ax,word ptr ds:buf+14 ;get # of sectors
	mov	ds:nsecs,ax
	; byte-swap ASCII data
	mov	si,offset buf	;point at data
	mov	di,si		;with both
	mov	cx,1000/2	;wc
lp3:	lodsw			;get a word
	xchg	al,ah		;><
	stosw			;save
	loop	lp3
	; print banner
	print	'SHOWIDE.COM: by John Wilson'
	call	crlf
	call	crlf
	; show drive type
	print	'Drive type:  '
	mov	dx,offset buf+(27d*2) ;point at model
	mov	cx,40d		;length
	mov	bx,1		;STDOUT
	mov	ah,40h		;func=write
	int	21h
	call	crlf		;cr, lf
	; serial number
	print	'Serial no.:  '
	mov	dx,offset buf+24 ;point at it
	mov	cx,20d		;length
	mov	bx,1		;STDOUT
	mov	ah,40h		;func=write
	int	21h
	call	crlf
	; firmware version
	print	'Revision:    '
	mov	dx,offset buf+56 ;point
	mov	cx,8d		;length
	mov	bx,1		;STDOUT
	mov	ah,40h		;func=write
	int	21h
	call	crlf
	; geometry
	print	'Geometry:    Cyl=' ;# cyls
	mov	ax,ds:ncyls
	call	num
	print	' Hd='		;# heads
	mov	ax,ds:nhds
	call	num
	print	' Sec='		;# sectors
	mov	ax,ds:nsecs
	call	num
	call	crlf
	int	20h
;+
;
; Write inline ASCII string to STDOUT.
;
; call wrasc
; db len, 'string'
;
;-
wrasc:	pop	si		;catch return addr
	lodsb			;get length
	cbw			;ah=0
	mov	dx,si		;ptr
	add	si,ax		;(update)
	mov	cx,ax		;ctr
	mov	bx,1		;STDOUT
	mov	ah,40h		;func=write
	int	21h
	jmp	si		;return
;+
;
; Write a decimal number to STDOUT.
;
; ax	number
;
;-
num:	mov	bx,10d		;radix
num1:	xor	dx,dx		;zero-extend
	div	bx		;get next digit
	or	ax,ax		;recurse?
	jz	num2
	push	dx		;yes
	call	num1
	pop	dx
num2:	or	dl,'0'		;cvt rem. to digit
	mov	ah,02h		;func=conout
	int	21h
	ret
;+
;
; Write cr, lf to STDOUT.
;
;-
crlf:	call	wrasc		;yep
	db	2,15,12		;len, cr, lf
	ret
;
config	dw	1 dup(?)	;drive config bits
ncyls	dw	1 dup(?)	;# cylinders
nhds	dw	1 dup(?)	;# surfaces
nsecs	dw	1 dup(?)	;# sectors
;
buf	db	1000 dup(?)	;buffer
;
code	ends
	end	start
