;
;                            Tempest Door-Source Demo
;
; Written for /T\empest BBS v3.15 or higher Versions. Started: 07-19-94
;
; COPYRIGHT NOTE                                                        
; ŻŻŻŻŻŻŻŻŻŻŻŻŻŻ                                                        
; This program is copyrighted İ 1994 by Amtrac.            
; All rights reserved.                                                  
;                                                                      
; This Source is FREEWARE.  This program may be freely distributed as long as
;   - the executable and documentation remain unchanged and are included in 
;     the distribution (NOT COMPLETED NOW).
;                                                                      
;                                                                      
; DISCLAIMER                                                            
; ŻŻŻŻŻŻŻŻŻŻ                                                            
; No warranties of any kind are made as to the functionality of this    
; program. You are using it ENTIRE at your own risk.                    
;                                                                      
;                                                                      
; SYSTEM REQUIREMENTS                                                   
; ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ                                                   
; To run it you'll need OS2.0 or higher and Tempest BBS-Software 3.15 or higher.
;                                                                       
;                                                                       
; QUICK OVERVIEW
; ŻŻŻŻŻŻŻŻŻŻŻŻŻŻ                                                   
; 
; Don't be confused, but this source looks a little bit different!
; This is an very exactly version... hope you will understand it.
;
; If you have any suggestions, bugreports, hints & tips for this or other tools       
; coming from AMTRAC and CASA NOVA, feel free to contact us at SKYLINE BBS or
; DAWN of ETERNITY and we will change it to your needs.



TempMsgLength	EQU	72




Start

	move.b	#0,-1(a0,d0)		;Grab Node#
	lea	_TempPort(pc),a1
.copy0	move.b	(a0)+,(a1)+
	bne.s	.copy0
	subq.l	#1,a1
	lea	_TempPortName(pc),a0
.copy1	move.b	(a0)+,(a1)+
	bne.s	.copy1

	bsr	_DoorStart
	tst.l	d0
	beq	_Quit

_GetCLSString

	lea	_Command(pc),a0
	move.l	#33,(a0)		;CMD->GetString
	lea	_DOOR_VALUE1(pc),a0
	move.l	#110,(a0)		;Get Code for CLS
	bsr	_DOORIO

; In _DOOR_TEXT1 we will find the sequence - just give it to...

	lea	_Command(pc),a0
	move.l	#1,(a0)			;CMD->PrintLine
	bsr	_DOORIO


	lea	_Command(pc),a0
	move.l	#1,(a0)
	lea	_Text(pc),a0
	lea	_DOOR_TEXT1(pc),a1
.copy	move.b	(a0)+,(a1)+
	bne.s	.copy

	bsr	_DOORIO

	lea	_Command(pc),a0
	move.l	#21,(a0)		;CMD->InputString (ANSI-Bar)
	lea	_DOOR_VALUE1(pc),a0
	move.l	#29,(a0)		;Maximal 29 Chars
	lea	_DOOR_TEXT1(pc),a1
	move.l	#0,(a1)

	bsr	_DOORIO			;Query you will find in DOOR_TEXT1

	lea	_EXIT_FLAG(pc),a0	;Just testing if the
	tst.l	(a0)			;User ist still online...
	bne	_DOOR_Quit

PrintLine

	lea	_Hello(pc),a0
	lea	_DataStream(pc),a1
	lea	_DOOR_TEXT1(pc),a2
	move.l	a2,(a1)
	lea	_CopyChar(pc),a2
	lea	_Output(pc),a3

	move.l	4.w,a6
	jsr	-522(a6)		;RawDoFmt

	lea	_Output(pc),a0
	lea	_DOOR_TEXT1(pc),a1
.copy	move.b	(a0)+,(a1)+
	bne.s	.copy

	lea	_Command(pc),a0
	move.l	#1,(a0)			;CMD->PrintLine

	bsr	_DOORIO

_DOOR_Quit

	bsr	_CloseStuff

_Quit
	rts




;***** Tempest-Door Connection *****



; DoorStart ********************************

; A1 = CPTR TempestPortName



_DoorStart:
	move.l	a6,-(sp)
	lea	_EXIT_FLAG(pc),a0
	move.l	#0,(a0)

	lea	_TempPort(pc),a1

	move.l	4.w,a6
	jsr	-390(a6)	;FindPort
	tst.l	d0
	bne.s	.TempPortOk
	moveq	#0,d0
.Done
	move.l	(sp)+,a6
	rts

.TempPortOk
	jsr	-666(a6)	;CreateMsgPort
	lea	_MyPort(pc),a1
	move.l	d0,(a1)
	bne.s	.MyPortOk
	moveq	#0,d0
	bra.s	.Done
.MyPortOk
	lea	_DOOR_TEXT1(pc),a1
	move.l	#0,(a1)
	lea	_DOOR_TEXT2(pc),a1
	move.l	#0,(a1)
	lea	_DOOR_TEXT3(pc),a1
	move.l	#0,(a1)

	bsr.s	_DOORIO

	moveq	#1,d0
	bra.s	.Done





_DOORIO:
	movem.l	a5/a6,-(sp)
	lea	_TempestMsg(pc),a5	;Basis Adress Tempest-Msg
	tst.l	52(a5)			;msg.carrier
	beq.s	.Online
	moveq	#0,d0
.Done
	movem.l	(sp)+,a5/a6
	rts
.Online
	lea	_EXIT_FLAG(pc),a0
	move.l	#0,(a0)
	lea	_TempPort(pc),a1
	move.l	4.w,a6
	jsr	-390(a6)		;FindPort
	tst.l	d0
	beq	.Exit
	move.l	d0,a0
	move.l	#0,52(a5)		;Clear msg.carrier
	move.b	#5,8(a5)		;NT_MESSAGE->LN_TYPE
	move.w	#TempMsgLength,18(a5)	;MN_LENGTH
	move.l	_MyPort(pc),14(a5)	;MN_REPLYPORT

	move.l	_Command(pc),20(a5)	;msg.command
	lea	_DOOR_TEXT1(pc),a1
	move.l	a1,24(a5)		;msg.text1
	lea	_DOOR_TEXT2(pc),a1
	move.l	a1,28(a5)		;msg.text2
	lea	_DOOR_TEXT3(pc),a1
	move.l	a1,32(a5)		;msg.text3
	move.l	_DOOR_VALUE1(pc),36(a5)	;msg.value1
	move.l	_DOOR_VALUE2(pc),40(a5)	;msg.value2
	move.l	_LONG_VALUE(pc),44(a5)	;msg.longvalue

	move.l	a5,a1
	move.l	4.w,a6
	jsr	-366(a6)		;PutMsg
	move.l	_MyPort(pc),a0
	jsr	-384(a6)		;WaitPort
	move.l	_MyPort(pc),a0
	jsr	-372(a6)		;GetMsg
	tst.l	52(a5)			;check msg.carrier
	beq.s	.Present
.Exit
	lea	_EXIT_FLAG(pc),a0
	move.l	#1,(a0)
.Present
	moveq	#1,d0
	bra	.Done




_CloseStuff:

	move.l	a6,-(sp)
	lea	_Command(pc),a0
	move.l	#999,(a0)
	lea	_DOOR_TEXT1(pc),a0
	move.l	#0,(a0)

	bsr	_DOORIO
.GetMsg
	move.l	_MyPort(pc),a0
	move.l	4.w,a6
	jsr	-372(a6)	;GetMsg
	tst.l	d0
	beq	.MsgDone
	move.l	d0,a1
	jsr	-378(a6)	;ReplyMsg
	bra.s	.GetMsg		;so long as all MSGs are answered
.MsgDone
        lea     _MyPort(pc),a0
        tst.l   (a0)
        beq.s   .Done
        move.l  _MyPort(pc),a0
        jsr     -672(a6)        ;DeleteMsgPort
.Done
	move.l	(sp)+,a6
	rts


; *** DATAS ***


_CopyChar	move.b	d0,(a3)+
		rts


; For better understaending this structure was written completly.
; All other things (Commands and Parameter) you will find in the 
; DOOR-Document for Tempest-Doors.

_TempestMsg	ds.b 20			;ExecMessage
_Command	dc.l 0			;LONG COMMAND
		dc.l 0			;LONG _DOOR_TEXT1
		dc.l 0			;LONG _DOOR_TEXT2
		dc.l 0			;LONG _DOOR_TEXT3
		dc.l 0			;LONG _DOOR_VALUE1
		dc.l 0			;LONG _DOOR_VALUE2
		dc.l 0			;LONG _LONG_VALUE
		dc.l 0			;(LONGBITS Flags)
		dc.l 0			;LONG CARRIER
		dc.l 0			;APTR User
		dc.l 0			;APTR SystemData
		dc.l 0			;APTR NodeData
		dc.l 0			;APTR Today

_EXIT_FLAG	dc.l	0

_MyPort		dc.l	0

_DataStream	dc.l	0

_DOOR_TEXT1	ds.b	255
_DOOR_TEXT2	ds.b	255
_DOOR_TEXT3	ds.b	255

_Output		ds.b	80

	EVEN

_DOOR_VALUE1	dc.l	0
_DOOR_VALUE2	dc.l	0
_LONG_VALUE	dc.l	0

_Text		dc.b	13,10,"Enter your name: ",0
_Hello		dc.b	13,10,"Hi, ",27,"[33m%s",27,"[0m!!! Nice day, bye...",13,10,0

_BBSNode	ds.b	6
_TempPort	ds.b	40
_TempPortName	dc.b	":TEMPEST_DOOR",0

	END
