;****; Reassembler V1.5 1992 ;**********************

;****; Definitionen ;****************************************

_LVOAllocMem	EQU	-$C6
_LVOForbid	EQU	-$84
_LVOFindPort	EQU	-$186
_LVOPermit	EQU	-$8A
_LVOFreeMem	EQU	-$D2
_LVOPutMsg	EQU	-$16E
_LVOWaitPort	EQU	-$180
_LVOGetMsg	EQU	-$174
_LVOCreateMsgPort	EQU	-$29A
_LVODeleteMsgPort	EQU	-$2A0
MEMF_CLEAR	EQU	$10000
MEMF_PUBLIC	EQU	1
RETURN_OK	EQU	0

		Include	"Dh0:Includes/AmiExpress/Amix.i"

;****; Programm ;********************************************
;*
;*	SDropOff.x - by PotNoodle/Anthrox. Reassembled by Adkins/Rascals
;*
		SECTION "  0",CODE

Start		BRA.B	ProgBeg

	DC.B	"$VER:",160,"Super-DropOffv1.01",160,"(9-August-1994)",10,0

Over01		Dc.b	"AEDoorPort"
Over01L		Equ	*-Over01
Over02		Dc.b	"xx",0
		Even
Over02L		Equ	*-Over02
LENOVER		Equ	*-Over01
		Even

ProgBeg		CMPI.L	#1,D0			; No commandline?
		BLE.W	Fin_1			; Yes=Finish Program
		CMPI.B	#"0",(A0)		; -.
		BLT.W	Fin_1			;  |_ Exit if node number is
		CMPI.B	#"9",(A0)		;  |  invalid... (not 0-9)
		BGT.W	Fin_1			; -'
		MOVE.B	(A0),-(SP)		; Preserve Node Number (1st letter)
		CMPI.B	#"0",1(A0)		; -.
		BLT.B	NotMany			;  |_ If 2nd half of node number
		CMPI.B	#"9",1(A0)		;  |  invalid then just one node...
		BGT.B	NotMany			; -'
		MOVE.B	1(A0),-(SP)		; Preserve Node Number (2nd letter)
		BRA.B	MaSet_1			; 
NotMany		MOVE.B	#0,-(SP)		; 2nd Node Number Invalid = Null It.
;===========================================================================;
; For residence, allocate memory for anything that'll change, and null it   ;
;===========================================================================;
MaSet_1		MOVE.L	#LENVARS,D0		; -.  Allocate
	MOVE.L	#MEMF_CLEAR|MEMF_PUBLIC,D1	;  |_ Memory for
		MOVEA.L	4.W,A6			;  |  Variables, Overlays,
		JSR	_LVOAllocMem(A6)	; -'  and MsgStructure.
		MOVEA.L	D0,A5			; Put vars address into A5
		TST.L	D0			; 
		BEQ.B	MaSet_1			; Aloc Failed=Try again.
; Can't Tell /X there's no memory, so keep on trying. No dos.lib=No Delay()
		LEA	NULLEND(A5),A0		; -.
		LEA	Over01(PC),A1		;  |  Copy Overlay
		MOVEQ	#LENOVER-1,D7		;  |- Backings onto
OverPrL		MOVE.B	(A1)+,(A0)+		;  |  Overlay Space
		DBRA	D7,OverPrL		; -'
;===========================================================================;
		MOVE.B	(SP)+,AmiPort.Node+1(A5); 2nd Letter of Node-Number (or Null)
		MOVE.B	(SP)+,AmiPort.Node(A5)	; 1st Letter of Node-Number
		MOVE.L	SP,StarStk(A5)		; Store Stack Pointer
;===========================================================================;
; Now we link up with AmiExpress
;===========================================================================;
		LEA	AmiPort.Name(A5),A1	; -._ Find The /X Port
		JSR	_LVOForbid(A6)		; Disable MultiTasking.
		JSR	_LVOFindPort(A6)	; -'  Address -> d0
		JSR	_LVOPermit(A6)		; Allow MultiTasking.
		TST.L	D0			; -._ If it doesn't exist,
		BEQ.B	Fin_2			; -'  end the program.
		MOVE.L	D0,AmiPort(A5)		; Store The Port Address
		JSR	_LVOCreateMsgPort(A6)	; -.
		MOVE.L	D0,OurPort(A5)		;  |- Create OurMsgPort
		BEQ.B	Fin_2			; -'
		MOVE.B	#5,8+MsgStru(A5)	; -.  Put info into
		MOVE.W	#248,18+MsgStru(A5)	;  |- MessageStructure (?)
		MOVE.L	OurPort(A5),14+MsgStru(A5)	; -'
		MOVE.L	#JH_REGISTER,JHM_Command(A5)	; -._ Register Our Door
		BSR.B	Send_Ami_Message	; -'  With AmiExpress!!
		MOVE.L	#BB_DROPDTR,JHM_Command(A5)	; -._ DropDtr
		BSR.B	Send_Ami_Message	; -'  With AmiExpress!!
*= SHUTDOWN =****************************************************************
* Close Everything Down, Return Memory Etc to System and End Program        *
*****************************************************************************
		MOVE.L	#JH_SHUTDOWN,JHM_Command(A5)	; -._ Shut-down Links
		BSR.B	Send_Ami_Message	; -'  With AmiExpress!!
		MOVEA.L	OurPort(A5),A0		; -.
		MOVEA.L	4.W,A6			;  |- Kill Our MsgPort
		JSR	_LVODeleteMsgPort(A6)	; -'
Fin_2		MOVEA.L	StarStk(A5),SP		; Ignore all Branches
		MOVE.L	#LENVARS,D0		; -.
		MOVEA.L	A5,A1			;  |- Unallocate Variables/Overlays
		JSR	_LVOFreeMem(A6)		; -'
Fin_1		MOVEQ	#RETURN_OK,D0		; No Error return code to dos
		RTS				; End Program
*****************************************************************************
* Door Routines for interfacing with AmiExpress BBS                         *
*****************************************************************************
*= SEND AMI MSG =************************************************************
* MsgStru(a5) = /X Message structure setup with details of command to do.   *
* a6 = ExecBase                                                             *
* Assume that all regs destroyed                                            *
*****************************************************************************
Send_Ami_Message
		LEA	MsgStru(A5),A1		; -.
		MOVEA.L	AmiPort(A5),A0		;  |_ Send Message to /X Port
		MOVEA.L	4.W,A6			;  |  From out Message Structure
		JSR	_LVOPutMsg(A6)		; -'
		MOVEA.L	OurPort(A5),A0		; -._ Wait for a Message to
		JSR	_LVOWaitPort(A6)	; -'  our Port (From /X Port)
		MOVEA.L	OurPort(A5),A0		; -._ Read the message sent to
		JMP	_LVOGetMsg(A6)		; -'  our port (From /X Port)
	RSReset
;= ADDRESS-POINTERS ========================================================;
StarStk		Rs.l	1		; Original Stack Pointer
OurPort		Rs.l	1		; Our Message Port
AmiPort		Rs.l	1		; /X  Message Port
;===========================================================================;
; Message Structure. Total length = 248                                     ;
;===========================================================================;
MsgStru		Rs.b	248		; Start of Message Structure
JH_String	Equ	MsgStru+020	; [200] Null-term Text for sending /X
JH_Data		Equ	MsgStru+220	; [L] Data sent/recived to/from Ami
JH_Command	Equ	MsgStru+224	; [L] Command Send to Ami
JH_NodeID	Equ	MsgStru+228	; [L] Unknown! (  When in Rome...  )
JH_LineNum	Equ	MsgStru+232	; [L] Unknown! (do as the Romans do)
;===========================================================================;
NULLEND		Equ	__RS		;------- Overlays Start Here -------;
;===========================================================================;
AmiPort.Name	Rs.b	Over01L		; "AEDoorPort"
AmiPort.Node	Rs.b	Over02L		; "xx",0
;===========================================================================;
LENVARS		Equ	__RS		;---- End of variables/overlays ----;
;===========================================================================;
	END
