*******************************************************************************
* Ami-Express /X3.xx SuperWho			   Copyright İ 1993 2-Cool/LSd!
* ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
* $Release	: 0.1 $
* $Revision	: 1.03 $
* $Date		: 13-Nov-93 $
*
* $Authors	: Written by 2-Cool/LSd!
*		: Developed using the "AEDoor library".
*
* $Purpose	: An Ami-Express replacement for the INTERNAL 'WHO' door
*		: This one assembles to little over 2k!
*******************************************************************************
;-------------- Definition Includes

		incdir	"includes:"
		include	"exec/exec.i"
		include	"exec/exec_lib.i"
		include	"libraries/dos.i"
		include	"libraries/dos_lib.i"
		include	"amix/amix.i"
		include	"amix/aedoor.i"

CALL		macro
		jsr	_LVO\1(a6)
		endm

		section	SuperWho,code		;public memory

Startup:	lea	Startup(pc),a5		;a5=PC-Offsetting Base
		move.b	(a0),d7			;d7=NODE number (from CLIParam)

;-------------- open AEDoor library

		move.l	4.w,a6			;get execbase
		lea	AEName(pc),a1		;ptr to name of library to open
		CALL	OldOpenLibrary		;open the AEDoor Library
		move.l	d0,_AEDBase-Startup(a5)	;save AEDBase for later use
		beq.w	ExitDoor		;if fails to open exitfast...

;-------------- open DOS Library

		move.l	4.w,a6			;ge execbase
		lea	DName(pc),a1		;ptr to name of library to open
		CALL	OldOpenLibrary		;open the DOS Library
		move.l	d0,_DOSBase-Startup(a5)	;save DOSBase for later use
		beq.w	CloseAEDoor		;if fails close all & exit...

;-------------- Create Ami-Door Communication Channel

		move.b	d7,d0			;Get Node Number
		move.l	_AEDBase(pc),a6		;put AEDBase in a6
		CALL	CreateComm		;Create our communications port
		move.l	d0,DIFPtr-Startup(a5)	;save DoorInterface struct ptr
		beq.w	CloseDOS		;if fails close all & exit...

;-------------- Show 'who' text

		lea	Who.txt(pc),a0		;a0=string
		move.l	DIFPtr(pc),a1		;a1=DoorInterface Struct
		moveq	#LF,d1			;d1=MSG_DATA
		CALL	WriteStr		;write string to user

;-------------- Show 'who' text
		lea	Who2.txt(pc),a0
		move.l	DIFPtr(pc),a1
		moveq	#LF,d1
		CALL	WriteStr

;-------------- Show 'who' text
		lea	Who3.txt(pc),a0
		move.l	DIFPtr(pc),a1
		moveq	#LF,d1
		CALL	WriteStr

;-------------- call systems 'node' configurations

		bsr.s	GetNodeInfo

;-------------- Show 'who' end texts

		lea	Done.txt(pc),a0
		move.l	DIFPtr(pc),a1
		moveq	#NOLF,d1
		move.l	_AEDBase(pc),a6
		CALL	WriteStr

		lea	Line.txt(pc),a0
		move.l	DIFPtr(pc),a1
		moveq	#NOLF,d1
		move.l	_AEDBase(pc),a6
		CALL	WriteStr

		lea	Done2.txt(pc),a0
		move.l	DIFPtr(pc),a1
		moveq	#NOLF,d1
		move.l	_AEDBase(pc),a6
		CALL	WriteStr

		lea	Done3.txt(pc),a0
		move.l	DIFPtr(pc),a1
		moveq	#NOLF,d1
		move.l	_AEDBase(pc),a6
		CALL	WriteStr

;-------------- Remove Ami-Door Communiations channel

CloseAEComm:	move.l	DIFPtr(pc),a1
		move.l	_AEDBase(pc),a6
		CALL	DeleteComm

;-------------- close DOS Library

CloseDOS:	move.l	_DOSBase(pc),a1		;get DOS library ptr to close
		move.l	4.w,a6			;get execbase
		CALL	CloseLibrary		;close the DOS library

;-------------- close AELib

CloseAEDoor:	move.l	_AEDBase(pc),a1		;get library AEDBase to close
		move.l	4.w,a6			;get execbase
		CALL	CloseLibrary		;close the AEDoor library
ExitDoor
DDDOne:		rts				;exit program


GetNodeInfo:	move.l	#123,d0			;COMMAND: JH_ACTIVE_NODES
		moveq	#1,d1			;DATA:    
		move.l	DIFPtr(pc),a1
		move.l	_AEDBase(pc),a6
		CALL	SendDataCmd		;get active nodes

		lea	ActiveNodes(pc),a0	;a0=destination
		move.l	DIFPtr(pc),a1		;a1=DIFStruct
		CALL	CopyStr			;get string from struct

		moveq	#-1,d0
		lea	ActiveNodes(pc),a0
getloop:	addq.l	#1,d0
		tst.b	(a0,d0.l)
		beq.s	DDDOne
		cmp.b	#'X',(a0,d0.l)
		bne.s	getloop

		movem.l	d0/a0,-(sp)
		bsr.s	FillASCII

		lea	node.txt(pc),a0
		move.l	DIFPtr(pc),a1
		moveq	#LF,d1
		move.l	_AEDBase(pc),a6
		CALL	WriteStr

		movem.l	(sp)+,d0/a0

		bra.s	getloop


FillASCII:	move.b	d0,(Node.txt-Startup)+5(a5)
		add.b	#'0',(Node.txt-Startup)+5(a5)
		bsr.b	FillFronts
		bsr.w	SortENVStuff

DoActivity:	move.l	d0,d1
		cmp.l	#-1,d0
		bne.s	FillInActivity
		lea	LostCarrier.txt(pc),a0
		bra.s	DoAction

FillInActivity:	lea	Messages.txt(pc),a0
		mulu	#19,d0			;19 chars per message
		add.l	d0,a0

DoAction:	lea	Action.txt(pc),a1
		move.l	(a0)+,(a1)+	;4
		move.l	(a0)+,(a1)+	;8	;copy all 19 chars for
		move.l	(a0)+,(a1)+	;12	;current status action
		move.l	(a0)+,(a1)+	;16
		move.w	(a0)+,(a1)+	;18
		move.b	(a0)+,(a1)+	;19

		lea	NodeSpace(pc),a0
		lea	Handle.txt(pc),a1

		moveq	#0,d0
CopyHandle:	tst.b	(a0)
		beq.s	GetLocation
		cmp.l	#15,d0
		beq.s	GetLocation
		move.b	(a0)+,(a1)+
		addq.l	#1,d0
		bra.s	CopyHandle

GetLocation:	lea	LocationSpace(pc),a0
		lea	Location.txt(pc),a1
		moveq	#0,d0
copyloc:	tst.b	(a0)
		beq.s	locdone
		cmp.l	#25,d0
		beq.s	locdone
		move.b	(a0)+,(a1)+
		addq.l	#1,d0
		bra.s	copyloc
locdone:	rts


FillFronts:	lea	Handle.txt(pc),a1
		move.l	#'    ',d1
		move.l	d1,(a1)+	;4
		move.l	d1,(a1)+	;8
		move.l	d1,(a1)+	;12
		move.w	d1,(a1)+	;14
		move.b	d1,(a1)+	;15

		lea	Location.txt(pc),a1
		move.l	d1,(a1)+	;4
		move.l	d1,(a1)+	;8
		move.l	d1,(a1)+	;12
		move.l	d1,(a1)+	;16
		move.l	d1,(a1)+	;20
		move.l	d1,(a1)+	;24
		move.b	d1,(a1)+	;25

		lea	Action.txt(pc),a1
		move.l	d1,(a1)+	;4
		move.l	d1,(a1)+	;8
		move.l	d1,(a1)+	;12
		move.l	d1,(a1)+	;16
		move.w	d1,(a1)+	;18
		move.b	d1,(a1)+	;19

		lea	NodeSpace(pc),a1
		moveq	#0,d1
		move.l	d1,(a1)+	;4
		move.l	d1,(a1)+	;8
		move.l	d1,(a1)+	;12
		move.w	d1,(a1)+	;14
		move.b	d1,(a1)+	;15

		lea	LocationSpace(pc),a1
		move.l	d1,(a1)+	;4
		move.l	d1,(a1)+	;8
		move.l	d1,(a1)+	;12
		move.l	d1,(a1)+	;16
		move.l	d1,(a1)+	;20
		move.l	d1,(a1)+	;24
		move.b	d1,(a1)+	;25
		rts


SortENVStuff:	move.b	d0,EnvNode-Startup(a5)
		add.b	#'0',EnvNode-Startup(a5)
		move.b	d0,_NodeFile.txt-Startup(a5)
		add.b	#'0',_NodeFile.txt-Startup(a5)
		bsr.s	_GetNodeFile
		cmp.l	#$FFFFFFFF,d1
		beq.s	ErrorENVFile
		bsr.b	GetENVStats
		cmp.l	#$12,d0
		bne.s	EnvFileErr
_ENVFileErrors:
_NodeFileFailed
		moveq	#-1,d1
EnvFileErr:	rts
ErrorENVFile:	moveq	#$12,d0
		rts


_GetNodeFile:	lea	_NodeFilename(pc),a0
		move.l	a0,d1
		move.l	#MODE_OLDFILE,d2
		move.l	_DOSBase(pc),a6
		jsr	_LVOOpen(a6)
		move.l	d0,_FileBase1-Startup(a5)
		beq.b	_NodeFileFailed

		move.l	d0,d1
		lea	NodeSpace(pc),a0
		move.l	a0,d2
		moveq	#18,d3
		jsr	_LVORead(a6)
		tst.l	d0
		bmi.w	CloseNodeFile

		move.l	_FileBase1(pc),d1
		moveq	#40,d2
		moveq	#-1,d3
		jsr	_LVOSeek(a6)
		moveq	#-1,d1
		cmp.l	d1,d0
		beq.s	CloseNodeFile

		move.l	_FileBase1(pc),d1
		lea	LocationSpace(pc),a0
		move.l	a0,d2
		moveq	#$1C,d3
		jsr	_LVORead(a6)
		tst.l	d0
		bmi.s	CloseNodeFile

		move.l	_FileBase1(pc),d1
		jsr	_LVOClose(a6)
		moveq	#0,d1
Stub:		rts


GetENVStats:	lea	EnvStats.txt(pc),a0
		move.l	a0,d1
		move.l	#MODE_OLDFILE,d2
		move.l	_DOSBase(pc),a6
		jsr	_LVOOpen(a6)
		move.l	d0,_FileBase1-Startup(a5)
		beq.w	_ENVFileErrors

		move.l	d0,d1
		moveq	#$24,d2
		moveq	#-1,d3
		jsr	_LVOSeek(a6)
		moveq	#-1,d1
		cmp.l	d1,d0
		beq.b	_CloseENVFile

		move.l	_FileBase1(pc),d1
		lea	_EnvMem(pc),a0
		move.l	a0,d2
		moveq	#2,d3
		jsr	_LVORead(a6)
		tst.l	d0
		bmi.b	_CloseENVFile

		lea	_EnvMem(pc),a0
		bsr.s	LookENVStats

		move.l	d0,-(sp)
		move.l	_FileBase1(pc),d1
		jsr	_LVOClose(a6)
		move.l	(sp)+,d0
_ExitENVLoad:	rts
_CloseENVFile:
CloseNodeFile:	move.l	_FileBase1(pc),d1
		jsr	_LVOClose(a6)
_failed:	moveq	#-1,d1
		rts

LookENVStats:	movem.l	d1-d7/a0-a6,-(sp)
		moveq	#0,d0
		move.l	d0,d1
		move.l	d0,d2

		move.b	(a0)+,d2
		cmp.b	#'+',d2
		beq.s	GotPlus
		cmp.b	#'-',d2
		bne.s	GotMinus
		moveq	#1,d1
		bra.s	GotPlus

GotMinus:	subq.l	#1,a0
GotPlus:	move.b	(a0)+,d2
		beq.s	GotZero
		and.b	#15,d2
		mulu	#10,d0
		add.l	d2,d0
		bra.s	GotPlus

GotZero:	tst.l	d1
		beq.s	DDone
		neg.l	d0
DDone:		movem.l	(sp)+,d1-d7/a0-a6
		rts

_DOSBase:	ds.l	1			;DOS Library base
_AEDBase:	ds.l	1			;AEDoor Library base
DIFPtr		ds.l	1			;DIFStructure base
_EnvMem:	ds.l	1
_FileBase1:	ds.l	1
ActiveNodes:	ds.b	10			;Active nodes storage
NodeSpace:	ds.b	18			;/X Nodes
LocationSpace:	ds.b	28			;"Location"
		even
AEName:		AEDOORNAME
		even
DName:		DOSNAME
		even
EnvStats.txt:	dc.b	'ENV:STATS@'
EnvNode:	dc.b	'%',0

_NodeFilename:	dc.b	'BBS:node'
_NodeFile.txt:	dc.b	'%','.user',0
Zero:		dc.b	0
		even

Who.txt:	dc.b	"                                                                             .",$a
		dc.b	"  .                                                                          :"
		dc.b	0
		even
Who2.txt:	dc.b	"  |             -^- /X sUPER-wHO v1.3 - wRiTTeN bY 2-cOOL/LSd! -^-           |",$a
Line.txt:	dc.b	"--+--------------------------------------------------------------------------+-"
		dc.b	0
		even
Who3.txt:	dc.b	"  |Ĝ··     -^-hAndLE-^-       -^-LoCATIOn/GroUP-^-        -^-AcTion-^-    ··Ĝ|",$a
		dc.b	"  |:     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    :|"
		dc.b	0
		even
Node.txt:	dc.b	'  | [x] | '
Handle.txt:	dc.b	'123456789012345 | '		;Space for 15 bytes
Location.txt:	dc.b	'1234567890123456789012345 |'	;Space for 25 bytes
Action.txt:	dc.b	'1234567890123456789 | |',0,0	;Space for 19 bytes
		even
Done.txt:	dc.b	"  |:    `------------------------------------------------------------------'.|",$a
		dc.b	"  |Ĝ··   -ż- Written exclusively for SkullBuggery - !The BrOtHa-HoOd! -ż- ..:|"
		dc.b	$a,0
		even
Done2.txt:	dc.b	$a,"  |                                                                          |"
		dc.b	0
		even
Done3.txt:	dc.b	$a,"  |                                                                          .",$a
		dc.b	"  :",$a
		dc.b	"  .",$a,0
		even

LostCarrier.txt	dc.b	'- !lOST cARRIER! - ',0
Messages.txt:	dc.b	'nOTHING iNTERESTING'
		dc.b	' DL: xxxxxxxx.xxx! '
		dc.b	' UL: xxxxxxxx.xxx! '
		dc.b	'- uSING A /X dOOR -'
		dc.b	' - rEADING mAIL! - '
		dc.b	'- cHECKING sTATUS -'
		dc.b	'- aCCOUNT eDITING -'
		dc.b	' - zOOMiNG mAIL! - '
		dc.b	'- sCANNING fILES! -'
		DC.B	' vIEWING bULLETINS '
		DC.B	'- vIEWING a fILE  -'
		DC.B	'- tRYING tO lOGON -'
		DC.B	' - lOGGING oFF! -  '
		DC.B	'- sYSOP fUNCTIONS -'
		DC.B	'- rEMOTE sHELL!!! -'
		DC.B	'-   uSING eMACS   -'
		DC.B	'jOINING cONFERENCE '
		DC.B	'cHATTING wITH sYSOP'
		DC.B	'- aWAITING lOGON - ',0
		end
