;ProfiPacket - packet radio terminal program
;Copyright (C) 1999  Alexander Feigl
;
;This program is free software; you can redistribute it and/or modify
;it under the terms of the GNU General Public License as published by
;the Free Software Foundation; either version 2 of the License, or
;(at your option) any later version.
;
;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;GNU General Public License for more details.
;
;You should have received a copy of the GNU General Public License
;along with this program; if not, write to the Free Software
;Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
;
;Author:
;
;Alexander Feigl
;Burachstraße 51
;
;D-88250 Weingarten
;
;EMail : Alexander.Feigl@gmx.de

                CPU M68000
                SNMAOPT Q+,P+,A+,B-,S+,M+,E+
                nolist
AJUMP                   MACRO
                        dc.w $4ef9
                        dc.l \1
                        ENDM
                
                        incdir "sys:include/"
                        include "exec/exec_lib.i"
                        include "/global.i"
                                
_Nil                    moveq #0,d0
                        rts
                        dc.b "ProfServ"
                
                
                        dc.l CHAT_Name
                        dc.l 1
                        dc.l CHAT_Init
                        dc.l 0
                        dc.l 0                  ;Subtype (0=General)
                        
CHAT_Name               dc.b "CHAT",0
                        even
CHAT_Init               movem.l a6/a4/d5-d7,-(sp)
                        move.l a0,a4
                        move.l a1,d7
                        move.l d0,d6
                        move.l a3,a6
                        move.l #CHAT_Functions-CHAT_FunctionsBegin,d0
                        move.l #chat_Size,d1
                        lea CHAT_Functions,a0
                        move.l ppb_Global(a6),a5
                        jsr _QVOCreateServerBase(A6)
                        tst.l d0
                        beq .Cannot_Serve
                        move.l d0,a6
                        move.l a3,a5

                        move.l a3,chat_QSOBase(A6)
                        move.l d7,chat_OldServer(A6)
                        move.l d6,chat_Channel(a6)
                        move.l a4,chat_ThisQSO(a6)
                        clr.l chat_PutTerminal(a6)
                        clr.l chat_CodeIncoming(a6)
                        clr.b chat_ServerLine(a6)
                        clr.l chat_ServerInLine(a6)
                        move.l a6,qso_Server(a4)
                        clr.l qso_SendPrompt(a4)

                        movem.l (sp)+,a6/a4/d5-d7
                        moveq #0,d0
                        rts


.Cannot_Serve           movem.l (sp)+,a6/a4/d5-d7
                        moveq #0,d0
                        bsr Get_Text
                        move.l d0,a0
                        move.l d0,-(sp)
                        movem.l d2-d3,-(sp)
                        moveq #1,d1
                        moveq #0,d2
                        move.l a3,a6
                        jsr _QVOTransmitText(a6)
                        movem.l (sp)+,d2-d3
                        move.l (sp)+,d0
                        jsr _QVOForceTransmit(A6)
                        moveq #-1,d0
                        rts

CHAT_Cleanup            move.l chat_OldServer(a6),d0
                        move.l chat_ThisQSO(a6),a0
                        move.l d0,qso_Server(a0)
                        move.l a6,a1
                        move.l ppb_ExecBase(a5),a6
                        sub.l #CHAT_Functions-CHAT_FunctionsBegin,a1
                        jsr _LVOFreeVec(A6)
                        moveq #0,d0
                        rts

CHAT_ConnectProced      sub.l #sid_Size,a7
                        move.l a7,a0
                        move.l #1,sid_Program(a0)
                        move.l #-1,sid_Version(a0)
                        move.l #-1,sid_Revision(a0)
                        move.l #-1,sid_Subrevision(a0)
                        clr.l sid_SystemType(a0)
                        move.l chat_Channel(a6),d0
                        GOQSO TransmitSID
                        add.l #sid_Size,a7
                        sub.l #16,a7
                        move.l chat_ThisQSO(a6),a0
                        lea qso_Call(a0),a0
                        move.l a7,a1
                        move.b #"C",(a1)+
                        move.b #"H",(a1)+
                        move.b #"A",(a1)+
                        move.b #"T",(a1)+
                        move.b #"_",(a1)+
                        move.b #"C",(a1)+
                        move.b #"_",(a1)+
.Copy_ConnectCall       cmp.b #"-",(a0)
                        beq .Copy_ConnectEnd
                        tst.b (a0)
                        beq .Copy_ConnectEnd
                        move.b (A0)+,(A1)+
                        bra .Copy_ConnectCall
.Copy_ConnectEnd        clr.b (a1)+
                        move.l a7,a0
                        moveq #1,d1
                        move.l chat_Channel(a6),d0
                        GOQSO TransmitMacroFile
                        tst.l d0
                        beq .CText_Dumped
                        move.l a7,a1
                        move.b #"C",(a1)+
                        move.b #"H",(a1)+
                        move.b #"A",(a1)+
                        move.b #"T",(a1)+
                        move.b #"_",(a1)+
                        move.b #"C",(a1)+
                        move.b #"_",(a1)+
                        move.b #"G",(a1)+
                        move.b #"L",(a1)+
                        move.b #"O",(a1)+
                        move.b #"B",(a1)+
                        move.b #"A",(a1)+
                        move.b #"L",(a1)+
                        clr.b (a1)+
                        move.l a7,a0
                        moveq #1,d1
                        move.l chat_Channel(a6),d0
                        GOQSO TransmitMacroFile(a6)

.CText_Dumped           add.l #16,a7
                        GOQSO GetConnectMsg
                        tst.l d0
                        beq .CMsg_Dumped
                        sub.l #160,a7
                        move.l a7,a0
                        move.b #"-",(a0)+
                        move.b #"-",(A0)+
                        move.b #">",(a0)+
                        move.b #" ",(a0)+
                        move.l d0,a1
.CMsg_CopyMe            move.b (a1)+,(a0)+
                        tst.b -1(a0)
                        bne .CMsg_CopyMe
                        subq.l #1,a0
                        move.b #$d,(a0)+
                        sub.l a7,a0
                        move.l a0,d0
                        move.l a7,a0
                        movem.l a0/d0,-(sp)
                        GOQSO ConvertToPCLen
                        movem.l (sp)+,a0/d0
                        movem.l a0/d0,-(sp)
                        move.l chat_Channel(a6),d1
                        GOQSO TransmitData
                        movem.l (sp)+,a0/d0
                        move.l chat_Channel(a6),d1
                        move.l d2,-(sp)
                        moveq #2,d2
                        GOQSO WriteTerminalUni
                        move.l (sp)+,d2
                        add.l #160,a7
.CMsg_Dumped
                        move.l chat_ThisQSO(a6),a0              
                        moveq #1,d0
                        GOQSO AudioEffect
                        move.l chat_ThisQSO(A6),a0
                        move.l qso_User(a0),a0
                        cmpa.l #0,a0
                        beq .No_Datacoll
                        tst.l user_Datacollector(a0)
                        beq .No_Datacoll
                        lea Serv_Datacollector,a0
                        GOQSO SearchSpecialServer
                        tst.l d0
                        beq .No_Datacoll
                        move.l d0,a0
                        move.l chat_Channel(a6),d0
                        sub.l a1,a1
                        GOQSO StartServer
.No_Datacoll            moveq #0,d0
                        rts
                        

CHAT_ReceivePacket      movem.l d2,-(sp)
                        move.l chat_ThisQSO(a6),a0
                        tst.l qso_SendPrompt(a0)
                        beq .ReceivePacketRedo
                        clr.l qso_SendPrompt(a0)
                        bsr CHAT_Prompt
.ReceivePacketRedo      move.l chat_ThisQSO(A6),a0
                        GOQSO TestServBufferLin
                        tst.l d0
                        beq .Exit
                        move.l chat_ServerInLine(a6),d1
                        cmp.l #250,d1
                        bge .Dump_Line
                        move.l #250,d2
                        sub.l d1,d2
                        cmp.l d2,d0
                        ble .No_Overmaxim
                        move.l d2,d0
.No_Overmaxim           lea chat_ServerLine(a6),a0
                        add.l d1,a0
                        move.l d1,d2
                        move.l chat_ThisQSO(a6),a1
                        GOQSO ReadServBuffer
                        add.l d0,chat_ServerInLine(a6)
                        lea chat_ServerLine(a6),a0
                        add.l d0,a0
                        add.l d2,a0
                        clr.b (a0)
                        move.l d0,d1
                        tst.l d1
                        beq .No_Outcheck
                        add.l d2,d1

                        sub.l a1,a1
                        lea chat_ServerLine(a6),a0
                        cmp.b #"[",(a0)
                        bne .No_Surpress
.Loop_Surpress          cmp.b #"]",(a0)
                        beq .Surpress_EndBracket
                        cmp.b #" ",(a0)
                        beq .No_Surpress
                        cmp.b #"-",(a0)+
                        bne .Loop_Surpress
                        move.l a0,a1
                        bra .Loop_Surpress
.Surpress_EndBracket    cmp.b #$d,1(a0)
                        bne .No_Surpress
                        cmpa.l #0,a1
                        beq .No_Surpress
                        clr.b 1(a0)
                        lea chat_ServerLine(a6),a0
                        lea chat_ReceivedSID(a6),a1
                        GOQSO ParseSID
                        tst.l d0
                        beq .No_GoodSID

                        move.l chat_ThisQSO(a6),a0
                        lea chat_ReceivedSID(a6),a1
                        GOQSO HandleSID

                        lea chat_ReceivedSID(a6),a0
                        cmp.l #2,sid_Program(a0)
                        beq .XP_SID
                        cmp.l #10,sid_Program(a0)
                        beq .XP_SID
                        cmp.l #1,sid_Program(a0)
                        bne .No_PP_SID

                        ;Valid PP Signature / XP Signature

.XP_SID
                        lea chat_ReceivedSID(a6),a0
                        tst.l sid_SystemType(a0)
                        bne .No_Trans_SID
                        move.l chat_ThisQSO(a6),a0
                        tst.w qso_SelfConnect(a0)
                        beq .No_Trans_SID

                        sub.l #sid_Size,a7
                        move.l a7,a0
                        move.l #1,sid_Program(a0)
                        move.l #-1,sid_Version(a0)
                        move.l #-1,sid_Revision(a0)
                        move.l #-1,sid_Subrevision(a0)
                        clr.l sid_SystemType(a0)
                        move.l chat_Channel(a6),d0
                        GOQSO TransmitSID
                        add.l #sid_Size,a7
.No_Trans_SID           move.l chat_Channel(a6),d0
                        GOQSO TestNameRequest
.No_PP_SID
.No_GoodSID             clr.l chat_PutTerminal(a6)
                        bra .Line_Handled

.No_Surpress            move.l d0,-(sp)
                        move.l chat_PutTerminal(a6),d0

                        move.l d1,chat_PutTerminal(a6)
                        lea chat_ServerLine(a6),a0
                        add.l d0,a0
                        sub.l d1,d0
                        neg.l d0
                        move.l chat_Channel(a6),d1
                        GOQSO WriteTerminal
                        move.l (sp)+,d0

.No_Outcheck
                        lea chat_ServerLine(a6),a0
                        add.l d0,a0
                        add.l d2,a0
                        cmp.b #$0d,-1(a0)
                        bne .ReceivePacketRedo
                        
                        clr.b -1(a0)
                        sub.l #1,chat_ServerInLine(a6)

                        lea chat_ServerLine(A6),a0
                        move.l chat_Channel(a6),d0
                        GOQSO HandleXPLine

                        clr.l chat_PutTerminal(a6)
                        lea chat_ServerLine(A6),a0
                        move.l chat_Channel(A6),d0
                        GOQSO TestForwardConnect
                        
                        lea chat_ServerLine(a6),a0
                        cmp.b #" ",(a0)
                        bne .Test_For_Autobin
                        cmp.b #"g",1(a0)
                        bne .Test_For_Remote
                        cmp.b #"o",2(a0)
                        bne .Test_For_Remote
                        cmp.b #"_",3(a0)
                        bne .Test_For_Remote
                        cmp.b #"7",4(a0)
                        bne .Test_For_7ptxt
                        cmp.b #"+",5(a0)
                        bne .Test_For_Remote
                        cmp.b #".",6(a0)
                        bne .Test_For_Remote
                        bra .Call_7plus_Server
.Test_For_7ptxt         cmp.b #"t",4(a0)
                        bne .Test_For_7PInfo
                        cmp.b #"e",5(a0)
                        bne .Test_For_Remote
                        cmp.b #"x",6(a0)
                        bne .Test_For_Remote
                        cmp.b #"t",7(a0)
                        bne .Test_For_Remote
                        cmp.b #".",8(a0)
                        bne .Test_For_Remote
                        bra .Call_7plus_Server
.Test_For_7PInfo        cmp.b #"i",4(a0)
                        bne .Test_For_Remote
                        cmp.b #"n",5(a0)
                        bne .Test_For_Remote
                        cmp.b #"f",6(a0)
                        bne .Test_For_Remote
                        cmp.b #"o",7(a0)
                        bne .Test_For_Remote
                        cmp.b #".",8(a0)
                        bne .Test_For_Remote
                        
.Call_7plus_Server      lea Serv_Auto7plusSave,a0
                        GOQSO SearchSpecialServer
                        tst.l d0
                        beq .Line_Handled
                        move.l d0,a0
                        move.l chat_Channel(a6),d0
                        lea chat_ServerLine(a6),a1
                        GOQSO StartServer
                        tst.l d0
                        bne .Line_Handled
                        clr.b chat_ServerLine(a6)
                        clr.l chat_ServerInLine(a6)
                        bra .Exit

                        
.Test_For_Autobin       lea chat_ServerLine(a6),a0
                        cmp.b #"#",(a0)
                        bne .Test_For_Remote
                        cmp.b #"B",1(a0)
                        bne .Test_For_Remote
                        cmp.b #"I",2(a0)
                        bne .Test_For_Remote
                        cmp.b #"N",3(a0)
                        bne .Test_For_Remote
                        cmp.b #"#",4(a0)
                        bne .Test_For_Remote
                        lea Serv_AutobinSave,a0
                        GOQSO SearchSpecialServer
                        tst.l d0
                        beq .Autobin_Abort
                        move.l d0,a0
                        move.l chat_Channel(a6),d0
                        lea chat_ServerLine(a6),a1
                        GOQSO StartServer
                        tst.l d0
                        bne .Autobin_Abort
                        clr.b chat_ServerLine(a6)
                        clr.l chat_ServerInLine(a6)
                        bra .Exit
.Autobin_Abort          move.l chat_Channel(a6),d0
                        GOQSO ForceTransmit
                        lea Serv_AutobinAbort,a0
                        move.l chat_Channel(A6),d0
                        moveq #1,d1
                        moveq #0,d2
                        GOQSO TransmitText
                        move.l chat_Channel(a6),d0
                        GOQSO ForceTransmit
                        move.l chat_Channel(A6),d0
                        GOQSO ResetFileTransfer
                        move.l chat_Channel(A6),d0
                        GOQSO RedisplayFileTransfer
                        bra .Line_Handled
                        
                        
.Test_For_Remote        move.l chat_ThisQSO(a6),a0
                        move.l qso_User(a0),a0
                        cmpa.l #0,a0
                        beq .Yes_Remote
                        move.w user_Type(a0),d0
                        cmp.w #4,d0
                        bge .Line_Handled
                        tst.w d0
                        blt .Line_Handled
.Yes_Remote             lea chat_ServerLine(a6),a0
                        cmp.b #"/",(a0)
                        bne .Line_Handled
                        cmp.b #"/",1(a0)
                        bne .Line_Handled
                        sub.l a1,a1
                        lea 2(a0),a0
.Enlarge_Command        move.b (a0),d0
                        tst.l d0
                        beq .Enlarged
                        cmp.b #$20,d0
                        beq .Enlarged_DoSpace
                        cmp.b #$61,d0
                        blt .No_EnlargeCom
                        cmp.b #$7a,d0
                        bgt .No_EnlargeCom
                        sub.b #$20,d0
.No_EnlargeCom          move.b d0,(a0)+
                        bra .Enlarge_Command
.Enlarged_DoSpace       clr.b (a0)
                        move.l a0,a1
                        addq.l #1,a1
.Enlarged               lea chat_ServerLine(a6),a0
                        lea 2(a0),a0
                        cmp.b #"0",(a0)
                        blt .No_Number_Remote
                        cmp.b #"9",(a0)
                        bgt .No_Number_Remote
                        tst.b 1(a0)
                        beq .Start_NumberRemote
                        cmp.b #"0",1(a0)
                        blt .No_Number_Remote
                        cmp.b #"9",1(a0)
                        bgt .No_Number_Remote
                        tst.b 2(a0)
                        bne .No_Number_Remote
.Start_NumberRemote     lea Serv_InterlinkChan,a0
                        GOQSO SearchSpecialServer
                        tst.l d0
                        beq .No_Number_Remote
                        move.l d0,a0
                        move.l chat_Channel(a6),d0
                        lea chat_ServerLine(a6),a1
                        lea 2(a1),a1
                        GOQSO StartServer
                        tst.l d0
                        bne .No_Number_Remote
                        clr.b chat_ServerLine(a6)
                        clr.l chat_ServerInLine(a6)
                        bra .Line_Handled
                        
                        
.No_Number_Remote       lea chat_ServerLine(a6),a0
                        lea 2(a0),a0
                        cmp.b #"I",(a0)
                        bne .No_InfoRemote
                        tst.b 1(a0)
                        beq .Info_Remote
                        cmp.b #"N",1(a0)
                        bne .No_InfoRemote
                        tst.b 2(a0)
                        beq .Info_Remote
                        cmp.b #"F",2(a0)
                        bne .No_InfoRemote
                        tst.b 3(a0)
                        beq .Info_Remote
                        cmp.b #"O",3(a0)
                        bne .No_InfoRemote
                        tst.b 4(a0)
                        bne .No_InfoRemote
.Info_Remote            sub.l #16,a7
                        move.l a7,a1
                        move.b #"C",(a1)+
                        move.b #"H",(a1)+
                        move.b #"A",(a1)+
                        move.b #"T",(a1)+
                        move.b #"_",(a1)+
                        move.b #"I",(a1)+
                        clr.b (a1)+
                        move.l a7,a0
                        moveq #1,d1
                        move.l chat_Channel(a6),d0
                        GOQSO TransmitMacroFile
                        add.l #16,a7
                        tst.l d0
                        beq .Info_Success
                        moveq #2,d0
                        bsr Get_Text
                        move.l d0,a0
                        move.l chat_Channel(a6),d0
                        moveq #1,d1
                        moveq #1,d2
                        GOQSO TransmitText
.Info_Success           bsr CHAT_Prompt
                        bra .Line_Handled
.No_InfoRemote          lea chat_ServerLine(a6),a0
                        lea 2(a0),a0
                        cmp.b #"Q",(a0)
                        bne .No_QuitRemote
                        tst.b 1(a0)
                        beq .Quit_Remote
                        cmp.b #"U",1(a0)
                        bne .No_QuitRemote
                        tst.b 2(a0)
                        beq .Quit_Remote
                        cmp.b #"I",2(a0)
                        bne .No_QuitRemote
                        tst.b 3(a0)
                        beq .Quit_Remote
                        cmp.b #"T",3(a0)
                        bne .No_QuitRemote
                        tst.b 4(a0)
                        bne .No_QuitRemote
.Quit_Remote            sub.l #16,a7
                        move.l chat_ThisQSO(a6),a0
                        lea qso_Call(a0),a0
                        move.l a7,a1
                        move.b #"C",(a1)+
                        move.b #"H",(a1)+
                        move.b #"A",(a1)+
                        move.b #"T",(a1)+
                        move.b #"_",(a1)+
                        move.b #"Q",(a1)+
                        move.b #"_",(a1)+
.Q_Copy_ConnectCall     cmp.b #"-",(a0)
                        beq .Q_Copy_ConnectEnd
                        tst.b (a0)
                        beq .Q_Copy_ConnectEnd
                        move.b (A0)+,(A1)+
                        bra .Q_Copy_ConnectCall
.Q_Copy_ConnectEnd      clr.b (a1)+
                        move.l a7,a0
                        moveq #1,d1
                        move.l chat_Channel(a6),d0


                        GOQSO TransmitMacroFile

                        tst.l d0
                        beq .QText_Dumped
                        move.l a7,a1
                        move.b #"C",(a1)+
                        move.b #"H",(a1)+
                        move.b #"A",(a1)+
                        move.b #"T",(a1)+
                        move.b #"_",(a1)+
                        move.b #"Q",(a1)+
                        move.b #"_",(a1)+
                        move.b #"G",(a1)+
                        move.b #"L",(a1)+
                        move.b #"O",(a1)+
                        move.b #"B",(a1)+
                        move.b #"A",(a1)+
                        move.b #"L",(a1)+
                        clr.b (a1)+
                        move.l a7,a0
                        moveq #1,d1
                        move.l chat_Channel(a6),d0


                        GOQSO TransmitMacroFile

.QText_Dumped           move.l chat_Channel(A6),d0
                        GOQSO ForceTransmit
                        move.l a7,a0
                        move.b #"D",(a0)
                        moveq #1,d0
                        move.l chat_Channel(a6),d1
                        GOQSO TransmitCommand
                        add.l #16,a7
                        bra .Line_Handled
                        
.No_QuitRemote          lea chat_ServerLine(a6),a0
                        lea 2(a0),a0
                        cmp.b #"H",(a0)
                        bne .No_HelpRemote
                        tst.b 1(a0)
                        beq .Help_Remote
                        cmp.b #"E",1(a0)
                        bne .No_HelpRemote
                        tst.b 2(a0)
                        beq .Help_Remote
                        cmp.b #"L",2(a0)
                        bne .No_HelpRemote
                        tst.b 3(a0)
                        beq .Help_Remote
                        cmp.b #"P",3(a0)
                        bne .No_HelpRemote
                        tst.b 4(a0)
                        bne .No_HelpRemote
.Help_Remote            move.l a1,-(sp)
                        sub.l #256,a7
                        move.l a7,a0
                        move.l #"Text",(a0)+
                        move.l #"/Hel",(a0)+
                        move.l #"p/CH",(a0)+
                        move.l #"AT_H",(a0)+
                        move.b #"_",(a0)+
                        movem.l a0/a1/d1,-(sp)
                        move.l chat_ThisQSO(a6),a0
                        GOQSO GetLanguageNode
                        movem.l (sp)+,a0/a1/d1
                        move.l a1,-(sp)
                        move.l d0,a1
                        move.l 16(a1),a1
.Copy_Language_Short    tst.b (a1)
                        beq .Language_Short_Coped
                        move.b (a1)+,(a0)+
                        bra .Copy_Language_Short
.Language_Short_Coped   move.l (sp)+,a1
                        move.b #"_",(a0)+
                        cmp.l #0,a1
                        beq .Help_NoParam
                        tst.b (a1)
                        beq .Help_NoParam
.Copy_HelpParam         move.b (a1)+,d0
                        cmp.b #$61,d0
                        blt .No_EnlargeHelp
                        cmp.b #$7a,d0
                        bgt .No_EnlargeHelp
                        sub.b #$20,d0
.No_EnlargeHelp         move.b d0,(a0)+
                        tst.b -1(a0)
                        bne .Copy_HelpParam
.Help_NoParam           clr.b -1(a0)
                        move.l a7,a0
                        moveq #1,d1
                        move.l chat_Channel(a6),d0
                        GOQSO TransmitMacroDirect
                        add.l #256,a7
                        move.l (sp)+,a1
                        tst.l d0
                        beq .Help_Success
                        sub.l #256,a7
                        move.l a7,a0
                        move.l #"Text",(a0)+
                        move.l #"/Hel",(a0)+
                        move.l #"p/CH",(a0)+
                        move.l #"AT_H",(a0)+
                        move.l #"_EN_",(a0)+
                        cmp.l #0,a1
                        beq .Help_NoParam_2
                        tst.b (a1)
                        beq .Help_NoParam_2
.Copy_HelpParam_2       move.b (a1)+,d0
                        cmp.b #$61,d0
                        blt .No_EnlargeHelp_2
                        cmp.b #$7a,d0
                        bgt .No_EnlargeHelp_2
                        sub.b #$20,d0
.No_EnlargeHelp_2       move.b d0,(a0)+
                        tst.b -1(a0)
                        bne .Copy_HelpParam_2
.Help_NoParam_2         clr.b -1(a0)
                        move.l a7,a0
                        moveq #1,d1
                        move.l chat_Channel(a6),d0
                        GOQSO TransmitMacroDirect
                        add.l #256,a7
                        tst.l d0
                        beq .Help_Success
                        moveq #3,d0
                        bsr Get_Text
                        move.l d0,a0
                        move.l chat_Channel(a6),d0
                        moveq #1,d1
                        moveq #1,d2
                        GOQSO TransmitText
.Help_Success           
                        bsr CHAT_Prompt
                        bra .Line_Handled
                        

.No_HelpRemote          lea chat_ServerLine(a6),a0
                        lea 2(a0),a0
                        cmp.b #"N",(a0)
                        bne .No_NewsRemote
                        tst.b 1(a0)
                        beq .No_NewsRemote
                        cmp.b #"E",1(a0)
                        bne .No_NewsRemote
                        tst.b 2(a0)
                        beq .No_NewsRemote
                        cmp.b #"W",2(a0)
                        bne .No_NewsRemote
                        tst.b 3(a0)
                        beq .No_NewsRemote
                        cmp.b #"S",3(a0)
                        bne .No_NewsRemote
                        tst.b 4(a0)
                        bne .No_NewsRemote
                        move.l chat_Channel(a6),d0
                        GOQSO NewsCommand
                        tst.l d0
                        beq .News_Success
                        moveq #4,d0
                        bsr Get_Text
                        move.l d0,a0
                        move.l chat_Channel(a6),d0
                        moveq #1,d1
                        moveq #1,d2
                        GOQSO TransmitText
.News_Success           bsr CHAT_Prompt
                        bra .Line_Handled
.No_NewsRemote  


                        lea chat_ServerLine(a6),a0
                        lea 2(a0),a0
                        tst.b (a0)
                        beq .Line_Handled
                        movem.l a0/a1,-(sp)
                        GOQSO SearchComServer
                        movem.l (sp)+,a0/a1
                        tst.l d0
                        beq .Unknown_Command
                        move.l chat_ThisQSO(a6),a0
                        move.l #1,qso_SendPrompt(a0)
                        move.l d0,a0
                        move.l chat_Channel(a6),d0
                        move.l a1,-(sp)
                        lea chat_ServerLine(a6),a1
                        clr.b (a1)
                        clr.l chat_ServerInLine(a6)
                        move.l (sp)+,a1
                        GOQSO StartServer
                        move.l chat_ThisQSO(a6),a0
                        cmp.l qso_Server(a0),a6
                        beq .Equal_Handler
                        clr.b chat_ServerLine(a6)
                        clr.l chat_ServerInLine(a6)
                        bra .Exit
.Equal_Handler          tst.l qso_SendPrompt(a0)
                        beq .Line_Handled
                        clr.l qso_SendPrompt(A0)
                        bsr CHAT_Prompt
                        bra .Line_Handled                       
.Unknown_Command        moveq #1,d0
                        bsr Get_Text
                        move.l d0,a0
                        move.l chat_Channel(A6),d0
                        moveq #1,d1
                        moveq #0,d2
                        GOQSO TransmitText
                        lea chat_ServerLine(a6),a0
                        lea 2(a0),a0
                        moveq #-1,d0
.Unknown_Command_C1     addq.l #1,d0
                        tst.b (a0)+
                        bne .Unknown_Command_C1
                        subq.l #1,a0
                        move.b #$d,(a0)+
                        addq.l #1,d0
                        move.l chat_Channel(a6),d1
                        lea chat_ServerLine(a6),a0
                        lea 2(a0),a0
                        movem.l d0-d1/a0,-(sp)
                        GOQSO TransmitData
                        movem.l (sp)+,d0-d1/a0
                        moveq #2,d2
                        GOQSO WriteTerminalUni
                        
.Line_Handled           clr.b chat_ServerLine(a6)
                        clr.l chat_ServerInLine(a6)
                        bra .ReceivePacketRedo


.Dump_Line              clr.b chat_ServerLine(a6)
                        clr.l chat_ServerInLine(a6)
                        clr.l chat_PutTerminal(a6)
                        bra .ReceivePacketRedo
                        
.Exit                   movem.l (Sp)+,d2
                        rts
CHAT_TerminalInput
                        move.l chat_Channel(A6),d1

                        movem.l d0/d1/a0,-(sp)
                        GOQSO TransmitData
                        movem.l (sp)+,d0/d1/a0
                        moveq #2,d2
                        GOQSO WriteTerminalUni

                        rts     

CHAT_Prompt             move.l chat_ThisQSO(a6),a0
                        move.l qso_User(a0),a0
                        cmpa.l #0,a0
                        beq .Yes_Prompt
                        move.w user_Type(a0),d0
                        cmp.w #4,d0
                        bge .No_Prompt
                        tst.w d0
                        blt .No_Prompt
.Yes_Prompt             lea CHAT_PromptText,a0
                        move.l chat_Channel(a6),d0
                        moveq #1,d1
                        move.l d2,-(sp)
                        moveq #1,d2
                        GOQSO TransmitText
                        move.l (sp)+,d2
.No_Prompt              rts

CHAT_Nop                moveq #0,d0
                        rts

                        
CHAT_AskAudio   rts             ;leave audio the same and go back chain

CHAT_FunctionsBegin     
                        AJUMP CHAT_AskAudio             ;allow Audio
                        AJUMP CHAT_Cleanup          ;-48 really Abort
                        AJUMP CHAT_Nop                  ;-42
                        AJUMP CHAT_TerminalInput                ;-36
                        AJUMP CHAT_ReceivePacket                ;-30
                        AJUMP CHAT_Nop                  ;-24
                        AJUMP CHAT_ConnectProced                ;-18
                        AJUMP CHAT_Cleanup              ;-12
                        AJUMP CHAT_Init                 ;-6
CHAT_Functions          



Get_Text                lea _ChatCatalog(pc),a0
                        move.l chat_ThisQSO(a6),a1
                        move.l a2,-(sp)
                        lea _ChatCatalogName(pc),a2
                        GOQSO GetText
                        move.l (sp)+,a2
                        rts


                        include "/Catalogs/Sources/Chat.s"

            
Serv_Datacollector      dc.b "Datacollector",0
Serv_AutobinSave        dc.b "Autobin Save Server",0
Serv_Auto7plusSave      dc.b "7plus Save Server",0
Serv_AutobinAbort       dc.b "#NO#",$0d,0
Serv_InterlinkChan      dc.b "Interlink Channel",0
CHAT_PromptText         dc.b $0d,"%c de %m %d %z>",$0d,0
                      even
                        
                        
                        rsreset
chat_ThisQSO            rs.l 1
chat_Channel            rs.l 1
chat_OldServer          rs.l 1
chat_QSOBase            rs.l 1
chat_ServerInLine       rs.l 1
chat_ServerLine         rs.b 256
chat_PutTerminal        rs.l 1
chat_CodeIncoming       rs.l 1
chat_ReceivedSID        rs.b sid_Size
chat_Size               rs.b 0
                                
                                





