;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"
                        include "utility/utility_lib.i"
                                
_Nil                    moveq #0,d0
                        rts
                        dc.b "ProfCmds"
                
                
CONV_Head               dc.l CONV_Name
                        dc.l 1
                        dc.l CONV_Init
                        dc.l 0
                        dc.l 128                ;Subtype (7=Converse)
                        
CONV_Name               dc.b "CONV",$1,"ERSE",0
                        even
CONV_Init               movem.l a6/a2-a4/d2-d7,-(sp)
                        move.l a0,a4
                        move.l a1,d7
                        move.l d0,d6
                        move.l a3,a6
                        move.l #CONV_Functions-CONV_FunctionsBegin,d0
                        move.l #conv_Size,d1
                        lea CONV_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,conv_QSOBase(a6)
                        move.l d7,conv_OldServer(A6)
                        move.l d6,conv_Channel(a6)
                        move.l a2,conv_Parameter(a6)
                        move.l a4,conv_ThisQSO(a6)
                        move.l a6,conv_ConverseBase(a6)
                        move.l #"CONV",conv_ConverseID(a6)
                        move.l #1,conv_ConvChannel(a6)
                        clr.l conv_SysopLogin(a6)
                        clr.l conv_InputOffset(a6)
                        lea CONV_DumpFunction,a0
                        move.l a0,conv_ConverseDump(a6)
                        move.l #1,conv_SpaceLines(a6)
                        clr.l conv_RepeatHeader(a6)
                        move.l a6,qso_Server(a4)
                        
                        move.l a2,a0
                        GOQSO ParseComLine
                        tst.l d0
                        blt .Invalid_Parameters
                        cmp.l #1,d0
                        bgt .Invalid_Parameters
                        move.l conv_Parameter(a6),a0
                        tst.b (a0)
                        beq .Standard_Channel
                        moveq #0,d1
                        
                        move.b (a0)+,d0
                        cmp.b #"0",d0
                        blt .Invalid_Parameters
                        cmp.b #"9",d0
                        bgt .Invalid_Parameters
                        and.l #$f,d0
                        move.l d0,d1
                        tst.b (a0)
                        beq .Channel_End
                        move.b (a0)+,d0
                        cmp.b #"0",d0
                        blt .Invalid_Parameters
                        cmp.b #"9",d0
                        bgt .Invalid_Parameters
                        and.l #$f,d0
                        mulu #10,d1
                        add.l d0,d1
                        tst.b (a0)
                        bne .Invalid_Parameters
.Channel_End            tst.l d1
                        beq .Invalid_Parameters
                        move.l d1,conv_ConvChannel(A6)                  
.Standard_Channel       moveq #1,d7
.MainInit_Loop          move.l d7,d0
                        GOQSO GetChannelQSO
                        tst.l d0
                        beq .Main_InitLooped
                        move.l d0,a2
                        tst.l qso_Server(a2)
                        beq .Next_DumpChannel
                        move.l a6,-(sp)
                        move.l qso_Server(a2),a6
                        jsr _SVOGetServerType(a6)
                        move.l (Sp)+,a6
                        btst #7,d0
                        beq .Next_DumpChannel
                        move.l d1,a0
                        move.l 8(a0),d0
                        cmp.l conv_ConvChannel(a6),d0
                        bne .Next_DumpChannel
                        tst.l 12(a0)
                        beq .Next_DumpChannel
                        move.l #1,conv_SysopLogin(A6)
.Next_DumpChannel       addq.l #1,d7
                        bra .MainInit_Loop
.Main_InitLooped        sub.l a0,a0
                        moveq #1,d0
                        moveq #0,d1
                        sub.l a1,a1
                        bsr CONV_StartDump
                        moveq #5,d0
                        bsr Get_Text
                        move.l d0,a0
                        move.l conv_Channel(a6),d0
                        moveq #1,d1
                        moveq #0,d2
                        GOQSO TransmitText
                        lea CONV_WritePacket(pc),a0
                        bsr CONV_UserList
                        
                        

.Server_Success         bsr CONV_ReceivePacket
                        movem.l (sp)+,a6/a2-a4/d2-d7
                        moveq #0,d0
                        rts


.Cannot_Serve           movem.l (sp)+,a6/a2-a4/d2-d7
                        moveq #-1,d0
                        rts

.No_User_Possible       moveq #1,d0
                        bra .Abort_With_Text
                        
.Invalid_Parameters     moveq #0,d0
.Abort_With_Text        bsr Get_Text
                        move.l d0,a0
                        move.l conv_Channel(a6),d0
                        moveq #1,d1
                        moveq #0,d2
                        GOQSO TransmitText
                        bsr CONV_Cleanup
                        movem.l (Sp)+,a6/a2-a4/d2-d7
                        moveq #0,d0
                        rts
                        

CONV_Cleanup            sub.l a0,a0
                        moveq #0,d1
                        sub.l a1,a1
                        moveq #0,d0
                        bsr CONV_StartDump
                        move.l conv_OldServer(a6),d0
                        move.l conv_ThisQSO(a6),a0
                        move.l d0,qso_Server(a0)
                        move.l a6,a1
                        move.l ppb_ExecBase(a5),a6
                        sub.l #CONV_Functions-CONV_FunctionsBegin,a1
                        jsr _LVOFreeVec(A6)
                        moveq #0,d0
                        rts

CONV_ConnectProced      rts

CONV_ReceivePacket      movem.l d2-d7/a2-a6,-(sp)
                        tst.l conv_ConvChannel(A6)
                        beq .Exit
.Loop                   move.l conv_ThisQSO(a6),a0
                        GOQSO TestServBufferLin
                        tst.l d0
                        beq .Exit
                        lea conv_Input(a6),a0
                        add.l conv_InputOffset(a6),a0
                        move.l #500,d1
                        sub.l conv_InputOffset(a6),d1
                        cmp.l d1,d0
                        blt .Good_Packs
                        move.l d1,d0
.Good_Packs             
                        move.l conv_ThisQSO(A6),a1
                        GOQSO ReadServBuffer
                        add.l conv_InputOffset(a6),d0
                        move.l d0,d7
                        move.l d0,conv_InputOffset(a6)
                        
                        lea conv_Input(a6),a0
                        add.l d0,a0
                        subq.l #1,a0
                        cmp.l #500,d0
                        beq .Full_Buffer
                        cmp.b #$d,(a0)
                        bne .Exit
                        subq.l #1,d7
                        bra .Gaga_Buffer
.Full_Buffer            cmp.b #$d,(a0)
                        bne .Gaga_Buffer
                        subq.l #1,d7
.Gaga_Buffer            
                        
                        clr.l conv_InputOffset(a6)
                        lea conv_Input(a6),a0
                        move.l d7,d0
                        bsr CONV_AnalizeLine
                        tst.l d0
                        beq .No_PackRemote
                        clr.b conv_OldHeader(a6)
                        cmp.l #1,d0
                        beq .Remote_Channel
                        cmp.l #2,d0
                        beq .Remote_Help
                        cmp.l #3,d0
                        beq .Remote_Disc
                        cmp.l #4,d0
                        beq .Remote_Quit
                        cmp.l #5,d0
                        beq .Remote_SpaceLine
                        cmp.l #6,d0
                        beq .Remote_SendMsg
                        cmp.l #7,d0
                        beq .Remote_Users
                        cmp.l #8,d0
                        beq .Remote_RepeatCall
                        bra .Loop
.Remote_SendMsg         move.l d7,d0
                        lea conv_Input(a6),a0
                        lea 3(a0),a0
                        subq.l #3,d0
                        moveq #0,d1
                        bsr CONV_SendCall
                        tst.l d0
                        beq .Loop
                        bra .Remote_PutText
.Remote_Channel         lea conv_Input(a6),a0
                        lea 3(a0),a0
                        cmp.l #4,d7
                        blt .Remote_Channel_Print
                        moveq #0,d0
                        move.b (a0)+,d1
                        cmp.b #"0",d1
                        blt .Remote_Channel_Wrong
                        cmp.b #"9",d1
                        bgt .Remote_Channel_Wrong
                        and.l #$f,d1
                        move.l d1,d0
                        cmp.l #5,d7
                        blt .Remote_Channel_Set
                        move.b (a0)+,d1
                        cmp.b #"0",d1
                        blt .Remote_Channel_Wrong
                        cmp.b #"9",d1
                        bgt .Remote_Channel_Wrong
                        and.l #$f,d1
                        mulu #10,d0
                        add.l d1,d0
                        cmp.l #6,d7
                        bge .Remote_Channel_Wrong
.Remote_Channel_Set     tst.l d0
                        beq .Remote_Channel_Wrong
                        cmp.l conv_ConvChannel(A6),d0
                        beq .Remote_Channel_Print
                        move.l d0,-(sp)
                        sub.l a0,a0
                        moveq #0,d1
                        sub.l a1,a1
                        moveq #0,d0
                        bsr CONV_StartDump
                        move.l (sp)+,d0
                        move.l d0,conv_ConvChannel(a6)
                        sub.l a0,a0
                        moveq #0,d1
                        sub.l a1,a1
                        moveq #1,d0
                        bsr CONV_StartDump
                        sub.l #128,a7
                        moveq #13,d0
                        bsr Get_Text
                        move.l d0,a0
                        move.l a7,a1
.Remote_Channel_Set_L   tst.b (a0)
                        beq .Remote_Channel_Set_E
                        move.b (A0)+,(a1)+
                        bra .Remote_Channel_Set_L
.Remote_Channel_Set_E move.l conv_ConvChannel(A6),d0
                        divu #10,d0
                        or.l #$300030,d0
                        move.b d0,(a1)+
                        swap d0
                        move.b d0,(a1)+
                        move.b #$d,(a1)+
                        clr.b (A1)+
                        move.l a7,a0
                        move.l a7,a1
                        moveq #-1,d0
.RemChaS_Counter        addq.l #1,d0
                        tst.b (a1)+
                        bne .RemChaS_Counter
                        bsr CONV_WritePacket
                        add.l #128,a7
                        bra .Remote_Users
                        
                        
.Remote_Channel_Print   sub.l #128,a7
                        moveq #13,d0
                        bsr Get_Text
                        move.l d0,a0
                        move.l a7,a1
.Remote_Channel_Print_L tst.b (a0)
                        beq .Remote_Channel_Print_E
                        move.b (A0)+,(a1)+
                        bra .Remote_Channel_Print_L
.Remote_Channel_Print_E move.l conv_ConvChannel(A6),d0
                        divu #10,d0
                        or.l #$300030,d0
                        move.b d0,(a1)+
                        swap d0
                        move.b d0,(a1)+
                        move.b #$d,(a1)+
                        clr.b (A1)+
                        move.l a7,a0
                        move.l a7,a1
                        moveq #-1,d0
.RemCha_Counter         addq.l #1,d0
                        tst.b (a1)+
                        bne .RemCha_Counter
                        bsr CONV_WritePacket
                        add.l #128,a7
                        bra .Loop                       

                        bra .Loop
.Remote_Channel_Wrong   moveq #12,d0
                        bsr Get_Text
                        bra .Remote_PutText

.Remote_SpaceLine       tst.l conv_SpaceLines(a6)
                        beq .Remote_SpaceLineOn
                        clr.l conv_SpaceLines(a6)
                        moveq #8,d0
                        bsr Get_Text
                        bra .Remote_PutText
.Remote_SpaceLineOn     move.l #1,conv_SpaceLines(a6)
                        moveq #9,d0
                        bsr Get_Text
                        bra .Remote_PutText
.Remote_RepeatCall      tst.l conv_RepeatHeader(a6)
                        beq .Remote_RepeatHeaderOn
                        clr.l conv_RepeatHeader(a6)
                        moveq #10,d0
                        bsr Get_Text
                        bra .Remote_PutText
.Remote_RepeatHeaderOn  move.l #1,conv_RepeatHeader(a6)
                        moveq #11,d0
                        bsr Get_Text
                        bra .Remote_PutText

.Remote_Help            moveq #6,d0
                        bsr Get_Text
.Remote_PutText         move.l d0,a0
                        move.l d0,a1
                        moveq #-1,d0
.Help_Counter           addq.l #1,d0
                        tst.b (a1)+
                        bne .Help_Counter
                        bsr CONV_WritePacket
                        bra .Loop                       
.Remote_Disc            move.l #"DDDD",-(sp)
                        move.l a7,a0
                        moveq #1,d0
                        move.l conv_Channel(A6),d1
                        GOQSO TransmitCommand
                        addq.l #4,a7
                        sub.l a1,a1
                        sub.l a0,a0
                        moveq #0,d0
                        moveq #0,d1
                        bsr CONV_StartDump
                        clr.l conv_ConvChannel(a6)
                        bra .Exit
.Remote_Quit            moveq #7,d0
                        bsr Get_Text
                        move.l d0,a0
                        move.l d0,a1
                        moveq #-1,d0
.Quit_Counter           addq.l #1,d0
                        tst.b (a1)+
                        bne .Quit_Counter
                        bsr CONV_WritePacket
                        
                        bsr CONV_AbortServer
                        bra .Exit
.Remote_Users           lea CONV_WritePacket(pc),a0
                        bsr CONV_UserList
                        bra .Loop
                                                
                        
.No_PackRemote          move.l d7,d0
                        lea conv_Input(a6),a0
                        moveq #0,d1
                        sub.l a1,a1
                        bsr CONV_StartDump
                        
                        bra .Loop
                        
                        

                        
                        
.Exit                   movem.l (Sp)+,d2-d7/a2-a6
                        rts

CONV_TerminalInput      movem.l d2-d7/a2-a6,-(sp)
                        move.l d0,d7
                        move.l a0,a4
                        
                        sub.l a1,a1
                
                        
                        
.Start_Dumping          move.l a4,a0
                        move.l d7,d0
                        moveq #0,d1
.Test_Dumping           tst.l d0
                        beq .Dumping_Last
                        subq.l #1,d0
                        cmp.b #$d,(a0)
                        beq .Dumping_Last_CR
                        addq.l #1,a0
                        addq.l #1,d1
                        bra .Test_Dumping
.Dumping_Last_CR        move.l a4,a0
                        move.l d1,d0
                        sub.l d1,d7
                        subq.l #1,d7
                        add.l d1,a4
                        addq.l #1,a4
                        bra .Real_Dump                                          
.Dumping_Last           move.l a4,a0
                        move.l d7,d0
                        sub.l d1,d7
                        add.l d1,a4
.Real_Dump              movem.l a0/d0,-(sp)
                        bsr CONV_AnalizeLine
                        move.l d0,d1
                        movem.l (sp)+,a0/d0
                        tst.l d1
                        beq .No_HelpCommand
                        cmp.l #2,d1
                        beq .Sysop_Help
                        cmp.l #3,d1
                        beq .Sysop_Logout
                        cmp.l #4,d1
                        beq .Sysop_Logout
                        cmp.l #6,d1
                        beq .Sysop_SendMsg
                        cmp.l #7,d1
                        beq .Sysop_ShowUsers
                        bra .Command_Dumped
.Sysop_SendMsg          subq.l #3,d0
                        lea 3(a0),a0
                        moveq #1,d1
                        bsr CONV_SendCall
                        tst.l d0
                        beq .Command_Dumped
                        bra .Sysop_PutText

.No_HelpCommand         tst.l conv_SysopLogin(a6)
                        bne .Sysop_AlreadyIn
                        movem.l d0-d1/a0-a1,-(sp)
                        sub.l a1,a1
                        sub.l a0,a0
                        moveq #1,d0
                        moveq #1,d1
                        bsr CONV_StartDump
                        
                        movem.l (sp)+,d0-d1/a0-a1
.Sysop_AlreadyIn        
                        moveq #1,d1
                        move.l a1,-(sp)
                        bsr CONV_StartDump
                        move.l (sp)+,a1
.Command_Dumped         tst.l d7
                        bgt .Start_Dumping
                        
                        movem.l (sp)+,d2-d7/a2-a6
                        rts     
.Sysop_Logout           tst.l conv_SysopLogin(A6)
                        beq .Command_Dumped
                        move.l a1,-(sp)
                        sub.l a1,a1
                        sub.l a0,a0
                        moveq #0,d0
                        moveq #1,d1
                        bsr CONV_StartDump
                        move.l (sp)+,a1
                        bra .Command_Dumped
.Sysop_ShowUsers        move.l a1,-(Sp)
                        lea CONV_WriteTerminal,a0
                        bsr CONV_UserList
                        move.l (sp)+,a1
                        bra .Command_Dumped
.Sysop_Help             moveq #6,d0
                        bsr Get_Text
.Sysop_PutText          move.l d0,a0
                        move.l d0,a1
                        moveq #-1,d0
.Help_Counter           addq.l #1,d0
                        tst.b (a1)+
                        bne .Help_Counter
                        bsr CONV_WriteTerminal
                        bra .Command_Dumped
                        




CONV_DumpFunction       movem.l d2-d7/a2-a6,-(sp)
                        cmpa.l #0,a0
                        bne .No_Special
                        tst.l d0
                        beq .Logout_Dump
                        cmp.l #1,d0
                        beq .Login_Dump
                        bra .Exit
.Login_Dump             tst.l d1
                        bne .Login_DumpSysop
                        cmp.l conv_ThisQSO(a6),a1
                        beq .Exit
                        bra .Login_DumpString
.Login_DumpSysop        move.l #1,conv_SysopLogin(a6)
.Login_DumpString       moveq #1,d0
                        movem.l a1/d1,-(sp)
                        bsr Get_Text
                        movem.l (sp)+,a1/d1
                        move.l d0,a0
                        bra .Special_GetLength

.Logout_Dump            tst.l d1
                        bne .Logout_DumpSysop
                        cmp.l conv_ThisQSO(a6),a1
                        beq .Exit
                        bra .Logout_DumpString
.Logout_DumpSysop       clr.l conv_SysopLogin(a6)
.Logout_DumpString      moveq #2,d0
                        movem.l a1/d1,-(sp)
                        bsr Get_Text
                        movem.l (sp)+,a1/d1
                        move.l d0,a0
                        bra .Special_GetLength
                        

.Special_GetLength      moveq #-1,d0
                        move.l a0,-(sp)
.Special_GetLength_L    addq.l #1,d0
                        tst.b (a0)+
                        bne .Special_GetLength_L
                        move.l (sp)+,a0
.No_Special             move.l a1,a4
                        move.l a0,a3
                        move.l d0,d7
                        move.l d1,d6
                        
.Print_Heading          lea conv_Output(a6),a2
                        move.b #"{",(a2)+
                        lea qso_Call(a4),a0
                        tst.l d6
                        beq .No_SysopCall
                        move.l conv_ThisQSO(a6),a0
                        lea qso_MyCall(a0),a0
.No_SysopCall           
.Copy_SenderCall        tst.b (a0)
                        beq .SenderCall_End
                        move.b (a0)+,(a2)+
                        bra .Copy_SenderCall
.SenderCall_End         move.b #"}",(a2)+
                        move.b #":",(a2)+
                        lea conv_OldHeader(a6),a0
                        clr.b (a2)
                        lea conv_Output(a6),a1
.Test_OldHeader         move.b (a1)+,d0
                        cmp.b (a0)+,d0
                        bne .OldHeader_OldFash
                        tst.b d0
                        bne .Test_OldHeader
                        bra .OldHeader_Unchanged
.OldHeader_OldFash      lea conv_OldHeader(a6),a0
                        lea conv_Output(a6),a1
.OldHeader_OldFash_L    move.b (a1)+,(a0)+
                        tst.b -1(a0)
                        bne .OldHeader_OldFash_L
                        tst.l conv_SpaceLines(a6)
                        beq .Copy_Message
                        addq.l #1,a2
                        lea conv_Output(a6),a0
                        move.l a2,a1
.OldHeader_SpaceLine_L  move.b -1(a1),(a1)
                        subq.l #1,a1
                        cmp.l a0,a1
                        bge .OldHeader_SpaceLine_L
                        move.b #$d,(a0)
                        bra .Copy_Message
.OldHeader_Unchanged    tst.l conv_RepeatHeader(a6)
                        bne .Copy_Message
                        bra .Clear_Header               
.Clear_Header           lea conv_Output(a6),a0
.Clear_Header_L         cmp.l a2,a0
                        bge .Copy_Message
                        move.b #" ",(a0)+
                        bra .Clear_Header_L
.Copy_Message           moveq #1,d3
                        move.l a2,d4
                        lea conv_Output(a6),a0
                        sub.l a0,d4
                        moveq #76,d5
                        sub.l d4,d5
                        
.Copy_Message_L         tst.l d7
                        ble .Message_Done
                        move.l a3,a0
                        move.l d7,d0
                        bsr .Get_WordLen
                        tst.l d0
                        beq .Message_Done
                        cmp.l #80,d0
                        blt .No_CopyLongWord
                        moveq #80,d0
.No_CopyLongWord        tst.l d3
                        bne .Copy_FirstWord
                        cmp.l d5,d0
                        bgt .Message_Done
.Copy_FirstWord         moveq #0,d3
                        move.l a3,a0
                        add.l d0,a3
                        sub.l d0,d7
                        sub.l d0,d5
.Copy_Message_L2        move.b (A0)+,(a2)+
                        subq.l #1,d0
                        tst.l d0
                        bgt .Copy_Message_L2
                        bra .Copy_Message_L
.Message_Done           
.Close_Message          move.b #$0d,(a2)+
                        lea conv_Output(a6),a0
                        sub.l a0,a2
                        move.l a2,d0
                        tst.l d6
                        bne .Sysop_TransEver
                        
                        move.l conv_ThisQSO(a6),a2
                        cmp.l a2,a4
                        beq .No_TransmitSelf
                        
.Sysop_TransEver        move.l conv_Channel(a6),d1
                        move.l d0,-(sp)
                        GOQSO TransmitData
                        move.l (sp)+,d0
.No_TransmitSelf        lea conv_Output(a6),a0
                        move.l conv_Channel(a6),d1
                        moveq #1,d2
                        tst.l d6
                        beq .No_SysopColor
                        moveq #2,d2
.No_SysopColor          GOQSO WriteTerminalUni
                        tst.l d7
                        bne .Print_Heading
                        

                        
.Exit                   movem.l (sp)+,d2-d7/a2-a6
                        rts

.Get_WordLen            moveq #0,d1
.Get_WordLen_L          tst.l d0
                        beq .Get_WordLen_E
                        subq.l #1,d0
                        addq.l #1,d1
                        cmp.b #" ",(a0)+
                        bne .Get_WordLen_L
.Get_WordLen_E          move.l d1,d0
                        rts

CONV_WritePacket        move.l conv_Channel(a6),d1
                        movem.l a0/d0,-(sp)
                        GOQSO TransmitData
                        movem.l (sp)+,a0/d0
                        move.l conv_Channel(a6),d1
                        moveq #2,d2
                        GOQSO WriteTerminalUni
                        rts
CONV_WriteTerminal      move.l conv_Channel(a6),d1
                        moveq #2,d2
                        GOQSO WriteTerminalUni
                        rts

CONV_AnalizeLine        cmp.l #2,d0
                        blt .No_Remote
                        cmp.b #"/",(a0)
                        bne .No_Remote
                        cmp.l #2,d0
                        beq .Pos_Remote
                        cmp.b #" ",2(a0)
                        beq .Pos_Remote
.No_Remote              moveq #0,d0
                        rts
.Pos_Remote             move.l d0,d1
                        move.b 1(a0),d0
                        cmp.b #"c",d0
                        beq .Remote_Channel
                        cmp.b #"C",d0
                        beq .Remote_Channel
                        cmp.b #"h",d0
                        beq .Remote_Help
                        cmp.b #"H",d0
                        beq .Remote_Help
                        cmp.b #"d",d0
                        beq .Remote_Disconnect
                        cmp.b #"D",d0
                        beq .Remote_Disconnect
                        cmp.b #"q",d0
                        beq .Remote_Quit
                        cmp.b #"Q",d0
                        beq .Remote_Quit
                        cmp.b #"r",d0
                        beq .Remote_SpaceLine
                        cmp.b #"R",d0
                        beq .Remote_SpaceLine
                        cmp.b #"s",d0
                        beq .Remote_SendCall
                        cmp.b #"S",d0
                        beq .Remote_SendCall
                        cmp.b #"u",d0
                        beq .Remote_Users
                        cmp.b #"U",d0
                        beq .Remote_Users
                        cmp.b #"v",d0
                        beq .Remote_CallOff
                        cmp.b #"V",d0
                        beq .Remote_CallOff
                        cmp.b #"?",d0
                        beq .Remote_Help
                        bra .No_Remote
.Remote_Channel         moveq #1,d0
                        rts
.Remote_Help            moveq #2,d0
                        rts
.Remote_Disconnect      moveq #3,d0
                        rts
.Remote_Quit            moveq #4,d0
                        rts
.Remote_SpaceLine       moveq #5,d0
                        rts
.Remote_SendCall        moveq #6,d0
                        rts
.Remote_Users           moveq #7,d0
                        rts
.Remote_CallOff         moveq #8,d0
                        rts
                        
                        
;>A0 Params
;>D0 ParamsLen
;>D1 SysopFlag
;<D0 Text for output

CONV_SendCall           movem.l d2-d7/a2-a4,-(sp)
                        sub.l #16,a7
                        move.l a0,a4
                        move.l d0,d7
                        move.l d1,d6
                        moveq #0,d0
                        tst.l d7
                        ble .Exit
                        move.l a7,a0
                        cmp.b #" ",(a4)
                        beq .Invalid_Call
                        moveq #0,d0
.Conv_SearchCall        tst.l d7
                        beq .No_Message
                        subq.l #1,d7
                        move.b (a4)+,d1
                        cmp.b #" ",d1
                        beq .Call_End
                        addq.l #1,d0
                        cmp.l #16,d0
                        bge .Invalid_Call
                        cmp.b #"a",d1
                        blt .No_Lower_Letter
                        cmp.b #"z",d1
                        bgt .No_Lower_Letter
                        sub.b #32,d1
.No_Lower_Letter        move.b d1,(a0)+
                        bra .Conv_SearchCall
.Call_End               tst.l d7
                        beq .No_Message
                        clr.b (a0)+
                        move.l a4,a0
                        move.l d7,d0
                        move.l d6,d1
                        move.l a7,a1
                        bsr CONV_StartDump
                        tst.l d0
                        bne .Ok_Msg
                        moveq #14,d0
                        bsr Get_Text
                        bra .Exit
.Invalid_Call           moveq #15,d0
                        bsr Get_Text
                        bra .Exit
.No_Message             moveq #16,d0
                        bsr Get_Text
                        bra .Exit

                        
                        
                        
                        
.Ok_Msg                 moveq #0,d0                     
.Exit                   add.l #16,a7
                        movem.l (Sp)+,d2-d7/a2-a4
                        rts
                        



CONV_UserList           move.l a0,a4
                        movem.l d2-d7/a2-a4,-(sp)
                        moveq #3,d0
                        bsr Get_Text
                        move.l d0,a0
                        move.l a0,-(sp)
                        moveq #-1,d0
.Get_HeadSize           addq.l #1,d0
                        tst.b (A0)+
                        bne .Get_HeadSize
                        move.l (sp)+,a0
                        jsr (A4)
                        sub.l #80,a7
                        
                        tst.l conv_SysopLogin(a6)
                        beq .No_SysopLogged
                        move.l a7,a0
                        move.b #" ",(a0)+
                        move.b #" ",(a0)+
                        moveq #10,d0
                        move.l conv_ThisQSO(a6),a2
                        lea qso_MyCall(a2),a1
.Copy_SysopCall_L       tst.b (a1)
                        beq .Copy_SysopCall_E
                        subq.l #1,d0
                        move.b (A1)+,(A0)+
                        bra .Copy_SysopCall_L
.Copy_SysopCall_E       tst.l d0
                        ble .Copy_SysopCall_Spcd
                        subq.l #1,d0
                        move.b #" ",(a0)+
                        bra .Copy_SysopCall_E
.Copy_SysopCall_Spcd    move.b #":",(a0)+
                        move.b #" ",(a0)+
                        move.b #"<",(a0)+
                        move.b #"S",(a0)+
                        move.b #"y",(a0)+
                        move.b #"s",(a0)+
                        move.b #"o",(a0)+
                        move.b #"p",(a0)+
                        move.b #">",(a0)+
                        move.b #$d,(a0)+
                        sub.l a7,a0
                        move.l a0,d0
                        move.l a7,a0
                        jsr (a4)
.No_SysopLogged 
                                
                        moveq #1,d7
.Main_Loop              move.l d7,d0
                        GOQSO GetChannelQSO
                        tst.l d0
                        beq .Main_Looped
                        move.l d0,a2
                        tst.l qso_Server(a2)
                        beq .Next_DumpChannel
                        move.l a6,-(sp)
                        move.l qso_Server(a2),a6
                        jsr _SVOGetServerType(a6)
                        move.l (Sp)+,a6
                        btst #7,d0
                        beq .Next_DumpChannel
                        move.l d1,a0
                        move.l 8(a0),d0
                        cmp.l conv_ConvChannel(a6),d0
                        bne .Next_DumpChannel
                        move.l a7,a0
                        move.b #" ",(a0)+
                        move.b #" ",(a0)+
                        moveq #10,d0
                        lea qso_Call(a2),a1
.Copy_UserCall_L        tst.b (a1)
                        beq .Copy_UserCall_E
                        subq.l #1,d0
                        move.b (A1)+,(A0)+
                        bra .Copy_UserCall_L
.Copy_UserCall_E        tst.l d0
                        ble .Copy_UserCall_Spcd
                        subq.l #1,d0
                        move.b #" ",(a0)+
                        bra .Copy_UserCall_E
.Copy_UserCall_Spcd     move.l qso_User(a2),a1
                        cmpa.l #0,a1
                        beq .Copy_UserCall_Done
                        move.b #":",(a0)+
                        lea user_Name(a1),a1
                        move.b #" ",(a0)+
.Copy_UserCall_NL       tst.b (a1)
                        beq .Copy_UserCall_Done
                        move.b (A1)+,(a0)+
                        bra .Copy_UserCall_NL
.Copy_UserCall_Done     move.b #$d,(a0)+
                        sub.l a7,a0
                        move.l a0,d0
                        move.l a7,a0
                        jsr (a4)
.Next_DumpChannel       addq.l #1,d7
                        bra .Main_Loop
                        
.Main_Looped            
                        
                        
                        add.l #80,a7
                        
                        moveq #4,d0
                        bsr Get_Text
                        move.l d0,a0
                        move.l a0,-(sp)
                        moveq #-1,d0
.Get_TailSize           addq.l #1,d0
                        tst.b (A0)+
                        bne .Get_TailSize
                        move.l (sp)+,a0
                        jsr (A4)
                        
                        movem.l (sp)+,d2-d7/a2-a4
                        rts
                        



;>D0 Length
;>D1 Sysopflag
;>A0 Data
;>A1 Target call or 0
;<D0 Anzahl der Stationen, die Dump Empfangen haben

CONV_StartDump          movem.l d2-d7/a2-a6,-(sp)
                        move.l d0,d6
                        move.l d1,d5
                        move.l a0,a4
                        move.l a1,a3
                        moveq #1,d7
                        moveq #0,d4
.Main_Loop              move.l d7,d0
                        GOQSO GetChannelQSO
                        tst.l d0
                        beq .Main_Looped
                        move.l d0,a2
                        tst.l qso_Server(a2)
                        beq .Next_DumpChannel
                        move.l a6,-(sp)
                        move.l qso_Server(a2),a6
                        jsr _SVOGetServerType(a6)
                        move.l (Sp)+,a6
                        btst #7,d0
                        beq .Next_DumpChannel
                        move.l d1,a0
                        cmpa.l #0,a3
                        bne .Name_For_Channel
                        move.l 8(a0),d0
                        cmp.l conv_ConvChannel(a6),d0
                        bne .Next_DumpChannel
                        bra .Dump_ThisChannel
.Name_For_Channel       move.l a0,d1
                        lea qso_Call(a2),a0
                        move.l a3,a1
.Name_For_Channel_L     move.b (a0)+,d0
                        cmp.b (a1)+,d0
                        bne .Next_DumpChannel
                        tst.b d0
                        bne .Name_For_Channel_L
                        move.l d1,a0
.Dump_ThisChannel       move.l a6,-(sp)
                        move.l conv_ThisQSO(a6),a1
                        move.l (a0),a6
                        move.l 16(a0),a2
                        move.l a4,a0
                        move.l d6,d0
                        move.l d5,d1
                        jsr (a2)
                        move.l (Sp)+,a6
                        addq.l #1,d4
.Next_DumpChannel       addq.l #1,d7
                        bra .Main_Loop
                        
.Main_Looped            move.l d4,d0
                        movem.l (Sp)+,d2-d7/a2-a6
                        rts


CONV_AbortServer        move.l a6,-(sp)
                        move.l conv_ThisQSO(a6),a0
                        GOQSO TestServBuffer
                        move.l d0,-(sp)
                        move.l conv_OldServer(a6),-(sp)
                        bsr CONV_Cleanup
                        move.l (sp)+,a6
                        move.l (Sp)+,d0
                        cmpa.l #0,a6
                        beq .Exit
                        jsr _SVOReceivePacket(A6)
.Exit                   move.l (sp)+,a6
                        rts

CONV_GetServerType      move.l #128,d0
                        lea conv_ConverseBase(a6),a0
                        move.l a0,d1
                        rts

CONV_Nop                        rts

                        
CONV_AskAudio           rts                     ;allow all audio output
                        
CONV_FunctionsBegin     

                        AJUMP CONV_AskAudio
            AJUMP CONV_AbortServer              ;-48
                        AJUMP CONV_GetServerType                ;-42
                        AJUMP CONV_TerminalInput                ;-36
                        AJUMP CONV_ReceivePacket                ;-30
                        AJUMP CONV_Nop                  ;-24
                        AJUMP CONV_ConnectProced                ;-18
                        AJUMP CONV_Cleanup              ;-12
                        AJUMP CONV_Init                 ;-6
CONV_Functions          
                        
                        even
                        
                        
                        rsreset
conv_ThisQSO            rs.l 1
conv_Channel            rs.l 1
conv_OldServer          rs.l 1
conv_QSOBase            rs.l 1
conv_Parameter          rs.l 1
conv_ConverseBase       rs.l 1
conv_ConverseID         rs.l 1
conv_ConvChannel        rs.l 1
conv_SysopLogin         rs.l 1
conv_ConverseDump       rs.l 1
conv_SpaceLines         rs.l 1
conv_RepeatHeader       rs.l 1
conv_InputOffset        rs.l 1
conv_OldHeader          rs.b 80
conv_Input              rs.b 512
conv_Output             rs.b 1024
conv_Size               rs.b 0






Get_Text                lea _ConverseCatalog(pc),a0
                        move.l conv_ThisQSO(a6),a1
                        move.l a2,-(Sp)
                        lea _ConverseCatalogName(pc),a2
                        GOQSO GetText
                        move.l (sp)+,a2
                        rts

                        

                        include "/Catalogs/Sources/Converse.s"
 
