****************************************************************************
*  DevStat				by	Fabrice LIENHARDT 	   *
*  written in October 1989			7, rue de Leicester 	   *
*						67000 Strasbourg (France)  *
*									   *
*  Written 100 % in assembler with Hisoft's Devpac Assembler V2.12	   *
****************************************************************************

	opt d+				:Option debugging 

	incdir ":include/"
	include exec/exec_lib.i
	include libraries/dos_lib.i
	include libraries/dos.i
	include libraries/filehandler.i
	include libraries/dosextens.i

	move.l	#dosname,a1
	moveq #0,d0
	CALLEXEC OpenLibrary		:Open DOSlibrary
	tst.l d0
	beq devquitfast
	move.l d0,_DOSBase		:save DOSBase

	CALLDOS Output
	move.l d0,devwindhd		:windowhandle

	move.l _DOSBase,a0		:Search pointer of DeviceNodes------
	move.l dl_Root(a0),a1		:search dl_Root	
	move.l rn_Info(a1),d0		:search rn_Info (BPTR)
	asl.l #2,d0			:(convert BPTR in APTR)
	move.l d0,a0			:
	move.l di_DevInfo(a0),d0	:search di_DevInfo (BPTR)
	asl.l #2,d0			:
	move.l d0,devsavea5		:save pointer of Devicenodes
	move.l d0,a5			:Result = a5

* List of all DLT_DEVICE ---------------------------------------------------

	move.l devwindhd,d1
	move.l #devclrscr,d2
	move.l #1,d3
	CALLDOS Write			:clear screen

	move.l #0,a3			:counter of line=0 (to stop screen
					*scrolling)
	move.l #devintrotxt,a0		
	bsr devafftxt			:print "Printdevs by F.Lienhardt ..."
	bsr devlfcr
	bsr devlfcr			: 2 * line feed, carriage return

	move.l #devdevt1,a0
	bsr devafftxt			:print "List of all hardware devices"

  	move.l #devdevtext,d6		:prepare text (Name, Type, Unit...) 

devDLT_DEVICE:
	cmp.l #DLT_DEVICE,dn_Type(a5)	:is it a harware device?
	bne devdevcont	

	bsr devlfcr			:if yes, line feed

	bsr devdevtxt			:print "Name :"
	move.l dn_Name(a5),d0
	asl.l #2,d0
	move.l d0,a0
	bsr devafftxt			:and print the name of device

	bsr devdevtxt
	move.l dn_Type(a5),d0		:print the type
	bsr devaffnum

	move.l a5,a4			:save the pointer for Next DeviceNode

	move.l dn_Startup(a5),d0	:is there a startup pointer
	cmp.l #10000,d0			:to go to FileSysStartupMsg ?
	bcs devdevcont 
	asl.l #2,d0			:if yes, put the pointer in a5
	move.l d0,a5
	
	bsr devdevtxt			:and print all other parameters
	move.l fssm_Unit(a5),d0		:fssm_Unit
	bsr devaffnum

	bsr devdevtxt
	move.l fssm_Device(a5),d0	:fssm_Device
	asl.l #2,d0
	move.l d0,a0
	bsr devafftxt

	bsr devdevtxt
	move.l fssm_Flags(a5),d0	:fssm_Flags
	bsr devaffnum

	move.l fssm_Environ(a5),d0
	asl.l #2,d0
	move.l d0,a5			:search pointer of Environ parameters

	moveq #13,d5
devbcle:
	bsr devdevtxt
	move.l (a5)+,d0
	bsr devaffnum			:and print all his values
	subq #1,d5
	bne devbcle			:(13 values in DosEnvec)
	bsr devlfcr

	move.l a4,a5			:Get the pointer of DeviceNode

devdevcont:
	move.l dn_Next(a5),d7		:Search the next pointer
	tst.l d7
	beq devDLT_VOLUME		:if no more, then list all dev.names
	asl.l #2,d7
	move.l d7,a5
	move.l #devdevtext,d6
	bra devDLT_DEVICE		:else print the other devices
	
* List of all DLT_VOLUME ---------------------------------------------------

devDLT_VOLUME:
	bsr devlfcr
	bsr devlfcr			:line feed, carriage return

	move.l #devvol1,a0
	bsr devafftxt			:print "List of all device names"

	move.l devsavea5,a5		:Get the original DeviceNode pointer

	move.l #devdevtext,d6		:and prepare text "Name, type..."

devDLT_VOLUME2:
	cmp.l #DLT_VOLUME,dn_Type(a5)	:is it a device name?
	bne devvolcont

	bsr devlfcr			:if yes, line feed

	bsr devdevtxt			:print "Name"
	move.l dn_Name(a5),d0
	asl.l #2,d0
	move.l d0,a0
	bsr devafftxt			:the name

	bsr devdevtxt
	move.l dn_Type(a5),d0		:and the type
	bsr devaffnum

devvolcont:
	move.l dn_Next(a5),d7		:Search the next pointer
	tst.l d7
	beq devDLT_DIRECTORY		:if no more, search all logical dev.
	asl.l #2,d7
	move.l d7,a5
	move.l #devdevtext,d6
	bra devDLT_VOLUME2		:else print all other names

* List of all DLT_DIRECTORY ------------------------------------------------

devDLT_DIRECTORY:
	bsr devlfcr
	bsr devlfcr			:line feed

	move.l #devdir1,a0
	bsr devafftxt			:print "List of all logical devices"

	move.l devsavea5,a5		:Get the original pointer

	move.l #devdevtext,d6		:prepare the text (Name, type...)

devDLT_DIRECTORY2:
	cmp.l #DLT_DIRECTORY,dn_Type(a5)	:is it a logical device?
	bne devdircont

	bsr devlfcr			:if yes, line feed

	bsr devdevtxt			:print "Name  :"
	move.l dn_Name(a5),d0
	asl.l #2,d0
	move.l d0,a0
	bsr devafftxt			:the name

	bsr devdevtxt
	move.l dn_Type(a5),d0		:and the type
	bsr devaffnum

devdircont:
	move.l dn_Next(a5),d7		:search the next device
	tst.l d7
	beq devquit			:no more? then quit
	asl.l #2,d7
	move.l d7,a5
	move.l #devdevtext,d6
	bra devDLT_DIRECTORY2		:if not print all other devices

devquit:
	bsr devlfcr
	bsr devlfcr			:line feed

	move.l _DOSBase,a1
	CALLEXEC CloseLibrary		:Close the DOS Library
devquitfast:
	rts				:The End

*** Routines ---------------------------------------------------------

devdevtxt:
	bsr devlfcr			:line feed, carriage return
	move.l d6,a0
	bsr devafftxt			:print text before values
	add.l #21,d6			:and prepare next text
	rts

devlfcr:
	move.l devwindhd,d1		:Routine to make a line feed and
	move.l #devlr,d2		:a carriage return, stop the screen 
	move.l #2,d3			:scrolling and wait of mouse click
	CALLDOS Write
	addq #1,a3
	cmp.l #22,a3			:are there 22 lines printed ?
	bne devnomouse			:if not, return 
	move.l #0,a3
	move.l devwindhd,d1
	move.l #devmouse,d2
	move.l #38,d3
	CALLDOS Write			:else write"<<< Click Mouse..."
devwaitclick:
	and.b #64,$bfe001
	bne devwaitclick		:and wait mouse click
	move.l devwindhd,d1
	move.l #devcr,d2
	move.l #1,d3
	CALLDOS Write
	move.l devwindhd,d1
	move.l #devdelete,d2
	move.l #50,d3
	CALLDOS Write			:delete the line
	move.l devwindhd,d1
	move.l #devcr,d2
	move.l #1,d3
	CALLDOS Write
devnomouse:
	rts				:and return to the programm

devafftxt:
	move.l devwindhd,d1		:Routine to write text on screen	
	move.b (a0)+,d3
	move.l a0,d2			:adress of text with pointer = a0
	CALLDOS Write	
	rts

devaffnum:
	move.l #10000,d1		:convert numbers in ASCII
	move.l #devnumber,a1		:input = d0
	bsr devcalc			:max = 100 000 decimal
	move.l #1000,d1
	bsr devcalc			:and print the number
	move.l #100,d1
	bsr devcalc
	move.l #10,d1
	bsr devcalc
	add.b #$30,d0
	move.b d0,(a1)+
	move.l devwindhd,d1
	move.l #devnumber,d2
	move.l #6,d3
	CALLDOS Write			:write the result
	rts
devcalc:
	divu d1,d0
	cmp.b #0,d0
	beq devcalczero			:result = 0? 
	add.b #$30,d0			:if not, convert it in ASCII
	bra devcalc2
devcalczero:
	move.b #32,d0			:else write nothing (space)
devcalc2:
	move.b d0,(a1)+
	move.w #0,d0
	swap d0
	rts

*** Variables --------------------------------------------------------

_DOSBase	dc.l 0
dosname		DOSNAME			:'dos.library'
		even

devcr		dc.w $0d00		:carriage return
devlr		dc.w $0a0d		:line feed, carriage return
devclrscr	dc.w $0c00

devmouse	dc.b "<<< Click mouse button to continue >>>"
		even
devdelete	dc.b "                                                  "
		even
devwindhd	dc.l 0			:windowhandle

devnumber	ds.b 6			:number in ASCII
devsavea5	dc.l 0

devdevtext	dc.b 20," Name             : "
		dc.b 20," Type             : "
		dc.b 20," Unit             : "
		dc.b 20," Device           : "
		dc.b 20," Flags            : "
		dc.b 20," TableSize        : "
		dc.b 20," SizeBlock        : "
		dc.b 20," SecOrg           : "
		dc.b 20," Surfaces         : "
		dc.b 20," SectorPerBlock   : "
		dc.b 20," SectorPerTrack   : "
		dc.b 20," Reserved         : "
		dc.b 20," PreAlloc         : "
		dc.b 20," Interleave       : "
		dc.b 20," LowCyl           : "
		dc.b 20," HighCyl          : "
		dc.b 20," NumBuffers       : "
		dc.b 20," BufMemType       : "
		even
devdevt1	dc.b 28,"List of all hardware devices"
		even
devintrotxt	dc.b 38,"DevStat by F.Lienhardt    October 1989"
		even
devvol1		dc.b 24,"List of all volume names"
		even
devdir1		dc.b 27,"List of all logical devices"
		even

