;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

MHeard_Entries  EQU 150

                CPU M68000
                SNMAOPT Q+,P+,A+,B-,S+,M+
                NOLIST

AJUMP           MACRO
                        dc.w $4ef9
                        dc.l \1
                        ENDM



                                    ;(O = Optimieren)  
                IDNT QSOProcessModule
                
                XDEF _QSO_Init
                XDEF QSO_Init                   ;() ()
                 ;Initialisierung für QSO-Modul
                XDEF QSO_DoPoll                 ;() ()
                 ;Poll-Routine für QSO-Modul
                XDEF QSO_SendCommand            ;(Length,Channel,Data) (D0,D1,A0)
                 ;Sendet ein Kommando ans TNC
                XDEF QSO_SendData               ;(Length,Channel,Data) (D0,D1,A0)
                 ;Sendet Daten mit Verzögerung ans TNC
                XDEF QSO_ForceTransmit      ;(Channel) (D0)
                 ;Sendet Daten in Verzögerungspuffer sofort
                XDEF QSO_SendDataUser           ;(Length,Channel,Data) (D0,D1,A0)
                 ;User hat Daten im Terminal eingegeben
                XDEF QSO_SendCommandUser        ;(Length,Channel,Data) (D0,D1,A0)
                 ;User hat Befehl im Terminal eingegeben
                XDEF QSO_IncomingMonitor        ;(Length,Type,Hardunit,Data) (D0,D1,D2,A0)
                 ;Empfang eines Monitor-Packets
                XDEF QSO_IncomingChannel        ;(Length,Type,Channel,Data) (D0,D1,D2,A0)
                 ;Empfang eines QSO-Packets             
                XDEF _QSO_InitalizeChannel
                XDEF QSO_InitalizeChannel       ;(Channel,SelfC,PredefServer) (D0,D1,A0)
                XDEF QSO_DoConnect              ;(Channel,SelfC,FreshC) (D0,D1,D2)
                 ;Behandelt einen Connect
                XDEF QSO_DoConnectCText         ;(Channel,FreshSelfC) (D0,D1)
                 ;Ruft die Connectprozedur auf
                XDEF QSO_DoDisconnect           ;(Channel) (D0)
                 ;Behandelt einen Disconnect

                XDEF QSO_StartExtServer         ;(Channel,Cmd,ServerNm,Param) (D0,D1,A0,A1)

                XDEF QSO_StartServer            ;(Channel,Server,Parameter) (D0,D1,A0)
                 ;Startet einen Server
                XDEF QSO_SearchSpecialServer    ;(Name) (A0)
                 ;0=Zeiger auf Spezialserver oder 0
                XDEF QSO_SearchComServer
                XDEF QSO_CRCFile 
                XDEF QSO_ParseComLine
                XDEF QSO_ProcessPathName        ;(OldPath,AddOn,BufferSize) (A0,A1,D0)
                 ;0= OK   1=Access denied  3=Too Long
                XDEF QSO_GetFileInfo            ;(QSO,PathBuf(256)) (A0,A1)
                 ;0= ErrorStat    Lies Daten von offenem File
                XDEF QSO_GetUserDir             ;() ()
                 ;Zeiger auf Userdir zurückgeben
                XDEF QSO_GetSaveDir             ;() ()
                 ;Zeiger auf Savedir zurückgeben

                XDEF QSO_GetQSOText


                XREF QSO_OpenUser_Try
                 ;Zeiger auf die User-Struktur  ;(Call) (A0)
                XREF QSO_OpenUser               ;(Call) (A0)
                 ;Zeiger auf die User-Struktur
                XREF QSO_OpenUser_SSID
                 ;Zeider auf die User-Struktur   (Öffnen einer bestimmten SSID)
                XREF QSO_CloseUser              ;(User) (A0)
                 ;Schließt einen User wieder
                XREF QSO_ChangeUser             ;(User) (A0)
                 ;Meldet Veränderung eines Users (enable SaveBack)
                XREF QSO_OpenStandardUser       ;() ()
                 ;Öffnet den Standard-User                
                XREF QSO_RemoveUser             ;(User) (A0)
                 ;D0=Error Entfernt einen User aus Database (EINZIGER BENUTZER!)
                XREF QSO_InitalizeUsers
                XREF QSO_CleanupUsers

                XDEF QSO_TransmitText

                XDEF QSO_SendPassword           ;(Channel,User) (A0)
                 ;D0=Error Sendet Password / SYS an Station
                XDEF QSO_ValidateLocator        ;(Locator) (A0)
                 ;D0=0 : Locator OK 
                XDEF QSO_UpdateTickerLine       ;(TickerLine) (A0)
                 ;D0=ChangeFlag    Berechnet den Monitor-Ticker-Neu

                XREF _QSO_FreeHoldArray
                XDEF QSO_FreeHoldArray          ;() ()
                 ;Gibt das HoldArray wieder frei                 


                XDEF _QSO_EncryptionOff
                XDEF _QSO_XPKOpenLibrary


                XDEF QSO_ChangeFileType    ;(FileName,Type) (A0,D0)
                 ;Filetype bei Type=-1    Liest/Schreibt Filetyp im Comment
                XDEF QSO_GetPacLen         ;(Channel) (D0)
                 ;D0=Paclen
                XDEF QSO_ControlEncryption ;D0=Channel D1=Mode 0=GoOn 1=GoOff 2=ForceTxOn 3=ForceRxOn 4=ForceTxOff 5=ForceRxOff
                XDEF QSO_MHeardLine
                XDEF QSO_MHeardLineLong
                XDEF QSO_AmigaDateMs
                XDEF QSO_MSDateAmiga
                XDEF QSO_GetChannelQSO     ;(Channel) (D0)
                 ;D0=QSO
                 
                XDEF QSO_FindFreeChannel   ;(Hardunit,Callset) (D0,D1)
                 ;D0 Channel 0=No Free

                XDEF QSO_GetLanguageNode


                XREF _QSO_ControlXPCompress
                XDEF _QSO_GetPacLen
                XDEF _QSO_CompressionOn
                XDEF _QSO_CompressionOff
                XDEF _QSO_ControlEncryption
                XDEF _QSO_FlushXPacketDelay

                XREF QSO_ParseSID
                XREF QSO_TransmitSID

                XREF _QSO_Cleanup
                XREF _QSO_LoadHoldings
                XREF _QSO_HoldRestorePre
                XREF _QSO_HoldRestorePost

                XDEF _QSO_GetQSOText
                XDEF _QSO_TestPasswordString

                XREF MAIN_AddTimeStamp
                XREF MAIN_TestTimeStamp
                XREF MAIN_CleanupChannel
                XREF MAIN_LongToString
                XREF MAIN_WriteServBuffer
                XREF MAIN_ReadServBuffer
                XREF MAIN_TestServBuffer
                XREF MAIN_TestServBufferLin
                XREF MAIN_ResetFileTransfer
                XREF MAIN_RecalcFileTransfer
                XREF MAIN_ConvertToPC
                XREF MAIN_ConvertToAmiga
                XREF MAIN_ConvertToPCLen
                XREF MAIN_ConvertToAmigaLen
                XREF MAIN_GetSecondsAgo
                XREF MAIN_GetConnectMsg
                
                
                XREF GUI_WriteToQSO
                XREF GUI_RefreshPacketHead
                XREF GUI_RefreshConnectHead
                XREF GUI_DisplayEventWindow
                XREF GUI_GeneralError
                XREF GUI_RedisplayFileTransfer
                XREF GUI_GetString
                XREF GUI_GetLanguageTable
                
                
                XREF PACK_TransmitCommand
                XREF PACK_TransmitData
                XREF PACK_GetOutstanding
                XREF PACK_AnalizeLinkStatusL
                XREF PACK_AskParameter
                XREF PACK_GetMonitorUnit


                XREF MAIL_SendMail
                XREF MAIL_WriteMail
                XREF MAIL_OpenMail
                XREF MAIL_CloseMail
                XREF MAIL_SetMailTitle
                XREF MAIL_GetNumberMail
                XREF MAIL_GetMailBid
                XREF MAIL_GetMailFm
                XREF MAIL_GetMailTo
                XREF MAIL_GetMailAt
                XREF MAIL_GetMailTitle
                XREF MAIL_GetMailDate
                XREF MAIL_GetMailStatus
                XREF MAIL_GetMailBytes
                XREF MAIL_TestForMail
                XREF MAIL_SearchMail
                XREF MAIL_GetMailLines
                XREF MAIL_ReadMail
                XREF MAIL_ReadMailLine
                XREF MAIL_MarkAsRead
                XREF MAIL_MarkAsForward
                XREF MAIL_MarkAsIncomp
                XREF MAIL_MarkAs7Plus
                XREF MAIL_MarkAsWantAck
                XREF MAIL_GetMailStatusTxt
                XREF MAIL_GetMailDateTxt
                XREF MAIL_KillMail
                XREF MAIL_SendMailFile
                XREF MAIL_SearchMailBid
                XREF MAIL_GetMailHRoute
                XREF MAIL_GetNextFMail
                XREF MAIL_RemoveFMail
                XREF MAIL_GetForwardDest
                XREF MAIL_GetLatestMail
                XREF MAIL_ComposeRLine
                XREF MAIL_SetNotForward
                XREF MAIL_TestPrivateMail
                XREF MAIL_TestForwardTime

                XREF QSO_FillUserdata
                XREF QSO_WriteUserdata


                XREF QSO_HandleSID

                XREF QSO_GetText

                XREF AUDIO_Effect


                XREF _GUI_LaunchWindowPoll
                XREF _MAIL_HandleMailMacro
                XREF _QSO_HandleNameRequest

                XREF _QSO_LoadLockCall
                XREF _QSO_CheckCall
                XREF _QSO_TestNameRequest
                XREF _UTIL_MsDateAmiga
                XREF _UTIL_AmigaDateMs
                XREF _GUI_GetLastActivity
                XREF _QSO_FindMatchChannel
                XREF _QSO_FindFreeChannel
                XREF _QSO_HuffmanCompress
                XREF _QSO_HuffmanDecompress
                XREF _QSO_HuffmanCompressXP
                XREF _QSO_HuffmanDecompressXP
                XREF _QSO_InitHuffDecompress
                XREF _QSO_DecompressXPStream


                XDEF _QSO_TransmitMacroFile

                incdir "sys:include/"
                include "exec/exec_lib.i"
                include "libraries/dos_lib.i"
                include "libraries/dos.i"
                include "libraries/dosextens.i"
                include "utility/utility_lib.i"
                include "global.i"
                                                

SERV_MinVersion=1
SERV_MaxVersion=1


                SECTION ".text",code

_QSO_Init               exg a4,a5
                        jsr QSO_Init
                        exg a4,a5
                        rts

QSO_Init                exg a4,a5
                        jsr _QSO_LoadLockCall
                        exg a4,a5
                        jsr QSO_InitalizeUsers
                        tst.l d0
                        bne .Init_Error
                        lea _Preferences(a5),a0
                        tst.l pref_EnableHuffman(a0)
                        beq .No_Huffman_Init
                        exg a4,a5
                        jsr _QSO_InitHuffDecompress
                        exg a4,a5
.No_Huffman_Init        move.l a6,-(sp)
                        move.l _SysBase(a5),a6
                        move.l _MaxChannel(a5),d0
                        addq.l #1,d0
                        mulu #dela_Size,d0
                        move.l #$10000,d1
                        jsr _LVOAllocVec(A6)
                        move.l (sp)+,a6
                        tst.l d0
                        beq .QSO_Init_Error
                        move.l d0,_DelayBuffers(a5)

                        XREF _QSO_MHeard_Init
                        exg a4,a5
                        jsr _QSO_MHeard_Init
                        exg a4,a5
                        tst.l d0
                        beq .QSO_Init_Error_2


                        movem.l d2-d7/a2-a6,-(sp)
                        sub.l #fib_SIZEOF+8,a7

                        move.l _SysBase(a5),a6
                        move.l #QSO_Base-QSO_BaseEnd,d0
                        add.l #ppb_Size,d0
                        moveq #1,d1
                        jsr _LVOAllocVec(a6)
                        tst.l d0
                        beq .NoMemoryBase
                        add.l #QSO_Base-QSO_BaseEnd,d0
                        move.l d0,_QSOBase(a5)

                        move.l d0,a0
                        move.l _SysBase(a5),ppb_ExecBase(a0)
                        move.l _DOSBase(a5),ppb_DosBase(a0)
                        move.l _UtilityBase(a5),ppb_UtilityBase(a0)
                        move.l a5,ppb_Global(a0)

                        move.l #QSO_Base-QSO_BaseEnd,d0
                        lea QSO_Base(pc),a1
.Copy_QSOBase           tst.l d0
                        ble .QSOBaseCoped
                        subq.l #1,d0
                        move.b -(a1),-(a0)
                        bra .Copy_QSOBase
.QSOBaseCoped           move.l _SysBase(a5),a6
                        jsr _LVOCacheClearU(a6)

                        move.l a7,d0
                        and.l #$fffffffc,d0
                        addq.l #4,d0
                        move.l d0,a4
                        move.l #Server_Dir,d1
                        moveq #-2,d2
                        move.l _DOSBase(a5),a6
                        jsr _LVOLock(a6)
                        tst.l d0
                        beq .Lock_Freed
                        move.l d0,d7
                        move.l a4,d2
                        move.l d7,d1
                        move.l _DOSBase(a5),a6
                        jsr _LVOExamine(a6)
                        cmp.l #-1,d0
                        bne .Free_Lock
.Examine_Loop           exg a4,a5
                        jsr _GUI_LaunchWindowPoll
                        exg a4,a5
                        move.l a4,d2
                        move.l d7,d1
                        move.l _DOSBase(a5),a6
                        jsr _LVOExNext(a6)
                        cmp.l #-1,d0
                        bne .Free_Lock
                        tst.l fib_DirEntryType(a4)
                        bgt .Examine_Loop
                        tst.l fib_Size(a4)
                        beq .Examine_Loop
                        sub.l #256,a7
                        lea Server_Dir,a0
                        move.l a7,a1
.Copy_ServerRoot        move.b (a0)+,(A1)+
                        tst.b -1(a0)
                        bne .Copy_ServerRoot
                        move.l a7,d1
                        lea fib_FileName(a4),a0
                        move.l a0,d2
                        move.l #256,d3
                        jsr _LVOAddPart(a6)
                        move.l a7,d1
                        jsr _LVOLoadSeg(a6)
                        add.l #256,a7
                        tst.l d0
                        beq .Examine_Loop
                        move.l d0,d6
                        asl.l #2,d0
                        addq.l #4,d0
                        move.l d0,a0
                        cmp.l #"Prof",4(a0)
                        bne .Unload_Seggi
                        moveq #1,d5
                        cmp.l #"Cmds",8(a0)
                        beq .Command_Server
                        moveq #0,d5
                        cmp.l #"Serv",8(a0)
                        bne .Unload_Seggi                       
.Command_Server         lea 12(a0),a0
                        move.l a0,a3
.Service_Loop           move.l #serlis_Size,d0
                        move.l #$10001,d1
                        move.l _SysBase(a5),a6
                        jsr _LVOAllocVec(A6)
                        tst.l d0
                        beq .Server_NoList
                        move.l d0,a2
                        clr.l (a2)
                        clr.l 4(a2)
                        clr.w 8(a2)
                        move.l (a3),10(a2)
                        move.l d6,serlis_SegList(a2)
                        moveq #0,d6
                        move.l d5,serlis_Type(a2)
                        move.l 4(a3),serlis_Version(a2)
                        move.l 8(a3),serlis_ServerInit(a2)
                        move.l 16(a3),serlis_SubType(a2)
                        move.l a2,a1
                        lea _ServerList(a5),a0
                        jsr _LVOAddTail(a6)
                        move.l 12(a3),a3
                        cmpa.l #0,a3
                        bne .Service_Loop
                        bra .Examine_Loop
.Unload_Seggi           move.l d6,d1
                        move.l _DOSBase(a5),a6
                        jsr _LVOUnLoadSeg(a6)
                        bra .Examine_Loop
.Free_Lock              move.l d7,d1
                        move.l _DOSBase(a5),a6
                        jsr _LVOUnLock(a6)
.Lock_Freed             add.l #fib_SIZEOF+8,a7
                        movem.l (sp)+,d2-d7/a2-a6
                        move.l a6,-(Sp)
                        lea _ServerList(a5),a0
                        lea Chat_Server,a1
                        move.l _SysBase(a5),a6
                        jsr _LVOFindName(a6)
                        move.l (sp)+,a6
                        tst.l d0
                        beq .Server_NoChat
                        exg a4,a5
                        jsr _GUI_LaunchWindowPoll
                        jsr _QSO_LoadHoldings
                        exg a4,a5
                        moveq #0,d0
                        rts
.QSO_Init_Error         moveq #82,d0
                        jsr GUI_GeneralError
                        moveq #-1,d0
                        rts
.QSO_Init_Error_2       move.l #196,d0
                        jsr GUI_GeneralError
                        moveq #-1,d0
                        rts









.Server_NoList          tst.l d6
                        beq .Nunload2
                        move.l d6,d1
                        move.l _DOSBase(a5),a6
                        jsr _LVOUnLoadSeg(a6)
.Nunload2               move.l d7,d1
                        move.l _DOSBase(a5),a6
                        jsr _LVOUnLock(a6)
.NoMemoryBase           add.l #fib_SIZEOF+8,a7
                        movem.l (sp)+,d2-d7/a2-a6
                        moveq #83,d0
                        jsr GUI_GeneralError
                        moveq #-1,d0
                        rts
.Server_NoChat          moveq #84,d0
                        jsr GUI_GeneralError
                        moveq #-1,d0
                        rts
.Init_Error             moveq #-1,d0
                        rts
                                                
                        XDEF _QSO_Cleanup2

_QSO_Cleanup2
                        exg a4,a5
                        jsr QSO_FreeHoldArray
                        move.l a6,-(sp)
                        tst.l _QSOBase(A5)
                        beq .No_QSOBase
                        move.l _QSOBase(a5),a1
                        sub.l #QSO_Base-QSO_BaseEnd,a1
                        clr.l _QSOBase(a5)
                        move.l _SysBase(a5),a6
                        jsr _LVOFreeVec(a6)
.No_QSOBase             tst.l _DelayBuffers(a5)
                        beq .No_Delays
                        move.l _DelayBuffers(a5),a1
                        clr.l _DelayBuffers(a5)
                        move.l _SysBase(a5),a6
                        jsr _LVOFreeVec(A6)
.No_Delays

                        XREF _QSO_MHeard_Deinit
                        exg a4,a5
                        jsr _QSO_MHeard_Deinit
                        exg a4,a5



                        move.l _ServerList(a5),a0
                        tst.l (a0)
                        beq .No_Servers
                        move.l a0,-(sp)
                        move.l a0,a1
                        move.l _SysBase(a5),a6
                        jsr _LVORemove(a6)
                        move.l (Sp)+,a0
                        move.l serlis_SegList(a0),d1
                        tst.l d1
                        beq .No_ServSegList
                        movem.l d2-d3/a0/a2-a3,-(sp)
                        move.l _DOSBase(a5),a6
                        jsr _LVOUnLoadSeg(a6)
                        movem.l (sp)+,d2-d3/a0/a2-a3
.No_ServSegList         move.l a0,a1
                        move.l _SysBase(A5),a6
                        jsr _LVOFreeVec(A6)
                        bra .No_Delays
.No_Servers             tst.l _HuffmanSpeedup(a5)
                        beq .No_HuffSpeed
                        move.l _HuffmanSpeedup(A5),a1
                        clr.l _HuffmanSpeedup(A5)
                        move.l _SysBase(a5),a6
                        jsr _LVOFreeVec(a6)
.No_HuffSpeed           move.l (sp)+,a6
                        jsr QSO_CleanupUsers
                        exg a4,a5
                        rts
                        

                        
QSO_DoPoll              movem.l d2-d3/a2-a3,-(sp)
                        add.l #1,_ServerPollCounter(a5)
                        cmp.l #5,_ServerPollCounter(a5)
                        blt .No_ServerPolls
                        clr.l _ServerPollCounter(a5)
                        move.l _QSOs(a5),a4
                        moveq #1,d7
.ServerPolling          cmp.l _MaxChannel(a5),d7
                        bgt .No_ServerPolls
                        tst.l qso_Server(a4)
                        beq .Next_ServerPoll
                        move.l qso_Server(a4),a6
                        move.l a5,-(sp)
                        move.l _QSOBase(a5),a5
                        jsr _SVOPoll(A6)
                        move.l (sp)+,a5
.Next_ServerPoll        add.l #qso_Size,a4
                        addq.l #1,d7
                        bra .ServerPolling
.No_ServerPolls         move.l _DelayBuffers(a5),a2
                        moveq #0,d2
.Dela_Loop              tst.l dela_BytesInBuffer(a2)
                        beq .Dela_NoSend
                        lea dela_DateStamp(a2),a0
                        lea _CurrentDateStamp(a5),a1
                        jsr MAIN_TestTimeStamp
                        tst.l d0
                        bge .Dela_NoSend
                        tst.l d2
                        ble .No_NoDelay
                        move.l d2,d0
                        jsr QSO_GetMaxFrame
                        move.l d0,-(sp)
                        move.l d2,d0
                        jsr PACK_GetOutstanding
                        move.l (sp)+,d1
                        cmp.l d1,d0
                        bge .Dela_NoSend
.No_NoDelay             move.l d2,d0
                        jsr QSO_ForceTransmit
.Dela_NoSend            add.l #dela_Size,a2
                        addq.l #1,d2
                        cmp.l _MaxChannel(a5),d2
                        ble .Dela_Loop
                        movem.l (sp)+,d2-d3/a2-a3
                        rts

_QSO_XPKOpenLibrary     exg a4,a5
                        move.l 4(sp),a0
                        jsr QSO_XPKOpenLibrary
                        exg a4,a5
                        rts


QSO_XPKOpenLibrary      movem.l a2-a6,-(sp)
                        move.l a0,a4

                        cmp.l #-1,qso_XPKType(a4)
                        beq .No_Library
                        cmp.l #-1,qso_XPKEfficiency(a4)
                        beq .No_Library
                        tst.l qso_XPKLibrary(a4)
                        beq .No_LibOpen
                        move.l _SysBase(a5),a6
                        move.l qso_XPKLibrary(a4),a1
                        clr.l qso_XPKLibrary(a4)
                        jsr _LVOCloseLibrary(a6)
.No_LibOpen             sub.l #64,a7
                        move.l a7,a0
                        move.l #"comp",(a0)+
                        move.l #"ress",(a0)+
                        move.l #"ors/",(a0)+
                        move.w #"xp",(a0)+
                        move.b #"k",(a0)+
                        move.l qso_XPKType(a4),d0
                        rol.l #8,d0
                        move.b d0,(a0)+
                        rol.l #8,d0
                        move.b d0,(a0)+
                        rol.l #8,d0
                        move.b d0,(a0)+
                        rol.l #8,d0
                        move.b d0,(a0)+
                        move.b #".",(a0)+
                        move.l #"libr",(a0)+
                        move.w #"ar",(a0)+
                        move.b #"y",(a0)+
                        clr.b (a0)+
                        move.l a7,a1
                        moveq #0,d0
                        move.l _SysBase(a5),a6
                        jsr _LVOOpenLibrary(a6)
                        add.l #64,a7
                        tst.l d0
                        beq .No_Library
                        move.l a0,a3
                        move.l a0,a6
                        jsr -30(a6)
                        move.l d0,a0
                        cmp.l #8,32(a0)
                        bgt .Too_Large_Chunks
                        moveq #0,d0
                        move.w 2(a0),d0
                        cmp.l #-1,qso_XPKSublibrary(a4)
                        beq .Good_SL
                        cmp.l qso_XPKSublibrary(a4),d0
                        bne .Too_Large_Chunks
.Good_SL                move.l a3,qso_XPKLibrary(a4)
                        move.l d0,qso_XPKSublibrary(a4)
                        move.l a3,d0
.Exit                   movem.l (sp)+,a2-a6
                        rts
.Too_Large_Chunks       move.l a6,a1
                        move.l _SysBase(a5),a6
                        jsr _LVOCloseLibrary(a6)
.No_Library             moveq #0,d0
                        bra .Exit

QSO_EncryptionHeader    movem.l d2-d7/a2-a6,-(sp)
                        move.l d1,d2
                        subq.l #1,d2
                        mulu #qso_Size,d2
                        move.l _QSOs(a5),a4
                        add.l d2,a4
                        btst #2,qso_CompressedMode+3(a4)
                        beq .No_Encrypt
                        move.l d0,d6
                        move.l d1,d7
                        move.l a0,a3
                        tst.l d6
                        beq .Only_DumpMe


.Encrypted_Dump         sub.l #128,a7
                        move.l a7,a0
                        moveq #16,d0
.Enc_Dump_Clear         clr.l (a0)+
                        dbf d0,.Enc_Dump_Clear
                        jsr QSO_GetHashedFeedback
                        lea qso_CipherOutputBuffer(a4),a0
                        lea 1024(a0),a0
                        move.l d0,(a0)
                        ror.l #8,d0
                        eor.l #$f1cd94b5,d0
                        move.l d0,4(a0)
                        lea 8(a0),a0
                        move.l a3,a1
                        move.l d6,d0
                        subq.l #1,d0
.Enc_Copy_Me            move.b (a1)+,(a0)+
                        dbf d0,.Enc_Copy_Me
                        move.l a7,a0
                        lea qso_CipherOutputBuffer(a4),a1
                        lea 6(a1),a2
                        move.l a2,8(a0)
                        move.l #506,12(a0)
                        lea 1024(a1),a2
                        move.l a2,(a0)
                        move.l d6,d0
                        addq.l #8,d0
                        move.l d0,4(a0)
                        move.l #100,28(a0)
                        lea 68(a0),a1
                        move.l a1,32(a0)
                        move.l qso_User(a4),a0
                        lea user_CipherKey(a0),a0
                        jsr QSO_MakeXPKPass
                        tst.l qso_XPKLibrary(a4)
                        beq .Failure_Lib
                        move.l qso_XPKLibrary(a4),a6
                        move.l a7,a0
                        jsr -36(a6)
                        move.l a7,a0
                        move.l d0,-(sp)
                        jsr -42(a6)
                        move.l (sp)+,d0
                        tst.l d0
                        bne .Failure_Lib
                        move.l a7,a0
                        move.l 16(a0),d0
                        lea qso_CipherOutputBuffer(a4),a0
                        addq.l #2,d0
                        move.l d0,(a0)
                        subq.l #2,d0
                        and.l #$1ff,d0
                        or.l #$400,d0
                        move.w d0,4(a0)
                        add.l #128,a7
                        bra .Checksum_Block

.Failure_Lib            add.l #128,a7
.Unchanged_Dump         lea qso_CipherOutputBuffer(a4),a0
                        move.l d6,d0
                        addq.l #2,d0
                        move.l d0,(a0)+

                        move.l d6,d0
                        move.w d0,(a0)+         ;Make flags
                        move.l a3,a1
                        move.l d6,d0
                        subq.l #1,d6
.Unchanged_DumpL        move.b (a1)+,(a0)+
                        dbf d6,.Unchanged_DumpL
                        bra .Checksum_Block
.Checksum_Block         tst.l qso_CipherOutputBuffer(a4)
                        beq .Only_DumpMe
                        lea qso_CipherOutputBuffer(a4),a0
                        move.w 4(a0),d0
                        and.l #$1ff,d0
                        lea 6(a0),a0
                        jsr QSO_MakeMiniCheck
                        lea qso_CipherOutputBuffer(a4),a0
                        or.b d0,4(a0)

.Only_DumpMe            lea qso_CipherOutputBuffer(a4),a0
                        tst.l (a0)
                        beq .Nothing_ToOut
                        lea 4(a0),a1
                        moveq #0,d0
                        move.w (a1),d0
                        and.l #$1ff,d0
                        tst.l d0
                        beq .Nothing_ToOut
                        addq.l #2,d0
                        move.l d0,d1
                        lea qso_CipherOutputBuffer(a4),a0
                        move.l (a0),d1
                        sub.l d1,d0
                        addq.l #4,d0
                        move.l a0,a1
                        add.l d0,a1
                        cmp.l #256,d1
                        blt .Only_DumpMe_Goodlen
                        move.l #256,d1
.Only_DumpMe_Goodlen    sub.l d1,(a0)
                        move.l a1,a3
                        move.l d1,d6
                        bra .Return_Encryption
.Nothing_ToOut          lea qso_CipherOutputBuffer(a4),a0
                        clr.l (a0)
                        sub.l a3,a3
                        moveq #0,d6
                        bra .Return_Encryption
.Return_Encryption      move.l a3,a0
                        move.l d6,d0
                        move.l d7,d1
                        movem.l (sp)+,d2-d7/a2-a6
                        rts


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

QSO_MakeMiniCheck       move.l d2,-(sp)
                        moveq #97,d1
                        tst.l d0
                        beq .LoopEnd
.Loop                   move.b (a0)+,d2
                        eor.b d2,d1
                        ror.b #5,d1
                        subq.l #1,d0
                        bne .Loop
.LoopEnd                move.l d1,d0
                        and.b #$80,d0
                        move.l (sp)+,d2
                        rts

;Format                             0=Standard raw xpk
;Bit 15    - Mini checksum          1=
;Bit 14    - ASCII Protection       2=
;Bit 13    - ASCII Protection       3=Reserved for 0x0d catching
;Bit 12\                            4=
;Bit 11 -  - Codier Code            5=
;Bit 10/                            6=
;Bit  9    - Huffman flag           7=
;Bit  8-0  - Länge codiertes Frame

QSO_DecryptionHeader    movem.l d2-d7/a2-a6,-(sp)
                        move.l d1,d2
                        subq.l #1,d2
                        mulu #qso_Size,d2
                        move.l _QSOs(a5),a4
                        add.l d2,a4
                        btst #3,qso_CompressedMode+3(a4)
                        beq .No_Decrypt
                        move.l d0,d6
                        move.l d1,d7
                        move.l a0,a3
                        tst.l d6
                        beq .No_Addon_Data
                        lea qso_CipherInputBuffer(a4),a0
                        move.l (a0),d0
                        add.l d6,d0
                        cmp.l #764,d0
                        bgt .Failure_LevelX
                        move.l (a0),d0
                        add.l d6,(a0)
                        addq.l #4,d0
                        add.l d0,a0
                        move.l a3,a1
                        move.l d6,d0
                        subq.l #1,d0
.Copy_NewIncome         move.b (a1)+,(a0)+
                        dbf d0,.Copy_NewIncome
.No_Addon_Data          lea qso_CipherInputBuffer(a4),a0
                        cmp.l #2,(a0)
                        blt .Decryption_Empty
                        lea 4(a0),a1
                        move.b (a1),d0
                        and.b #$60,d0
                        tst.b d0
                        bne .Failure_LevelX_NC
                        move.b (a1),d0
                        cmp.b #$0d,d0
                        beq .Failure_LevelX_NC

                        moveq #0,d0
                        move.w (a1),d0
                        and.w #$1ff,d0
                        addq.l #2,d0
                        cmp.l (a0),d0
                        bgt .Decryption_Empty
                        move.l (a0),d5
                        sub.l d0,d5
                        lea 4(a0),a2
                        add.l d0,a2

                        move.w 4(a0),d0
                        and.l #$1ff,d0
                        lea 6(a0),a0
                        jsr QSO_MakeMiniCheck
                        lea qso_CipherInputBuffer(a4),a0
                        move.b 4(a0),d1
                        and.b #$80,d1
                        cmp.b d0,d1
                        bne .Failure_LevelX_NC
                        moveq #0,d0
                        move.w 4(a0),d0
                        lea 6(a0),a0
                        bsr .Analize_Packet
                        tst.l d0
                        bne .Failure_LevelX

                        lea qso_CipherInputBuffer(a4),a0
                        move.l d5,(a0)
                        lea 4(a0),a0
                        move.l a2,a1
                        tst.l d5
                        beq .Return_Decryption
                        subq.l #1,d5
.Copy_OldIncome         move.b (a1)+,(a0)+
                        dbf d5,.Copy_OldIncome
.Return_Decryption      move.l a3,a0
                        move.l d6,d0
                        move.l d7,d1
                        movem.l (sp)+,d2-d7/a2-a6
                        rts
.Decryption_Empty       sub.l a3,a3
                        moveq #0,d6
                        bra .Return_Decryption

.Failure_LevelX         moveq #0,d6
                        sub.l a3,a3
.Failure_LevelX_NC      move.l d7,d0
                        jsr QSO_EncryptionOff
                        bra .Return_Decryption

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

.Analize_Packet         move.l d0,d1
                        and.l #$1c00,d1
                        lsr.l #8,d1
                        lsr.l #2,d1
                        tst.l d1
                        beq .No_Encryption
                        cmp.l #1,d1
                        beq .Standard_XPK
                        moveq #1,d0
                        rts
.No_Encryption          move.l a0,a3
                        and.l #$1ff,d0
                        move.l d0,d6
                        moveq #0,d0
                        rts
.Standard_XPK           movem.l d2-d5/d7/a2/a4-a6,-(Sp)
                        move.l d0,d7
                        move.l a0,a2
                        sub.l #128,a7
                        move.l a7,a0
                        moveq #16,d0
.Clear_XPK              clr.l (a0)+
                        dbf d0,.Clear_XPK

                        move.l a7,a0
                        move.l a2,(a0)
                        move.l d7,d0
                        and.l #$1ff,d0
                        move.l d0,4(a0)
                        lea qso_CipherInputBuffer(a4),a1
                        lea 768(a1),a1
                        move.l a1,8(a0)
                        move.l #256,12(a0)
                        move.l #100,28(a0)

                        lea 68(a0),a1
                        move.l a1,32(a0)
                        move.l qso_User(a4),a0
                        lea user_CipherKey(a0),a0
                        jsr QSO_MakeXPKPass

                        move.l a2,a3
                        tst.l qso_XPKLibrary(a4)
                        beq .Failure_Decrypt
                        move.l qso_XPKLibrary(a4),a6
                        move.l a7,a0
                        jsr -54(a6)
                        move.l a7,a0
                        move.l d0,-(sp)
                        jsr -60(a6)
                        move.l (sp)+,d0
                        tst.l d0
                        bne .Failure_Decrypt
                        move.l a7,a0
                        move.l 16(a0),d0
                        cmp.l #9,d0
                        blt .Failure_Decrypt
                        move.l 8(a0),a3
                        lea 8(a3),a3
                        move.l 16(a0),d6
                        subq.l #8,d6
                        add.l #128,a7
                        moveq #0,d0
.Standard_XPKExit       movem.l (sp)+,d2-d5/d7/a2/a4-a6
                        rts
.Failure_Decrypt        add.l #128,a7
                        moveq #1,d0
                        bra .Standard_XPKExit

QSO_MakeXPKPass         move.b #"#",(a1)+
                        moveq #15,d1
.Loop                   move.b (a0)+,d0
                        bsr .XPK_OutByte
                        dbf d1,.Loop
                        clr.b (a1)+
                        rts
.XPK_OutByte            move.l d0,-(sp)
                        lsr.l #4,d0
                        and.l #$f,d0
                        bsr .XPK_OutNibble
                        move.l (sp)+,d0
                        and.l #$f,d0
                        bsr .XPK_OutNibble
                        rts
.XPK_OutNibble          add.b #$30,d0
                        cmp.b #$39,d0
                        ble .XPK_OutThis
                        add.b #$7,d0
.XPK_OutThis            move.b d0,(a1)+
                        rts
QSO_GetHashedFeedback   LEA     _CurrentDateStamp(A5),A0
                        MOVE.L  #$41FE6B92,D0
                        MOVE.L  8(A0),D1
                        EOR.L   D1,D0
                        SUBI.L  #$74EB96EF,D0
                        ROR.L   #8,D0
                        ROR.L   #3,D0
                        MOVE.L  4(A0),D1
                        EOR.L   D1,D0
                        ADDI.L  #$CF9E71FC,D0
                        ROR.L   #8,D0
                        ROR.L   #2,D0
                        MOVE.L  (A0),D1
                        EOR.L   D1,D0
                        SUBI.L  #$9E07F163,D0
                        MOVE.L  8(A0),D1
                        EOR.L   D1,D0
                        ADDI.L  #$3E6C9F41,D0
                        move.l 4(a0),d1
                        ROR.L   #8,D0
                        ROR.L   #2,D0
                        EOR.L   D1,D0
                        SUBI.L  #$7ECF914E,D0
                        RTS


_QSO_InitalizeChannel   exg a4,a5
                        move.l 4(sp),d0
                        move.l 8(sp),d1
                        move.l 12(sp),a0
                        jsr QSO_InitalizeChannel
                        exg a4,a5
                        rts

QSO_InitalizeChannel    movem.l d2-d7/a2-a6,-(sp)
                        move.l d0,d7
                        move.l d1,d6
                        move.l a0,a3
                        subq.l #1,d0
                        mulu #qso_Size,d0
                        move.l _QSOs(a5),a0
                        add.l d0,a0
                        move.l a0,a4
                        
                        cmp.l #0,a3
                        bne .ServerName_Set
                        lea _Preferences(a5),a3
                        lea pref_Callsets(a3),a2
                        lea cals_MyCall(a2),a2
                        moveq #0,d6
.Search_RightCall       lea qso_MyCall(a4),a0
                        move.l a2,a1
.Compare_RightCall      move.b (a0)+,d0
                        move.b (a1)+,d1
                        cmp.b #$61,d0
                        blt .CompCall_J1
                        cmp.b #$7a,d0
                        bgt .CompCall_J1
                        sub.b #$20,d0
.CompCall_J1            cmp.b #$61,d1
                        blt .CompCall_J2
                        cmp.b #$7a,d1
                        bgt .CompCall_J2
                        sub.b #$20,d1
.CompCall_J2
                        cmp.b d0,d1
                        bne .Compare_NextCall
                        tst.b d0
                        beq .Compare_CallFound
                        bra .Compare_RightCall
.Compare_NextCall       add.l #cals_Size,a2
                        addq.l #1,d6
                        cmp.l #8,d6
                        blt .Search_RightCall
                        bra .Take_ChatServer
.Compare_CallFound      mulu #cals_Size,d6
                        lea pref_Callsets(a3),a0
                        add.l d6,a0
                        lea cals_ServerName(a0),a0
                        move.l a0,a3
                        bra .ServerName_Set
.Take_ChatServer        lea Chat_Server,a3
.ServerName_Set         lea _ServerList(a5),a0
                        move.l a3,a1
                        move.l _SysBase(a5),a6
                        jsr _LVOFindName(a6)
                        tst.l d0
                        beq .Error
                        move.l d0,a0
                        tst.l serlis_Type(a0)
                        bne .Error
                        sub.l a1,a1
                        move.l d7,d0
                        jsr QSO_StartServer
                        tst.l d0
                        bne .Error
                        
                
                        
.Exit                   moveq #0,d0
                        movem.l (sp)+,d2-d7/a2-a6
                        rts
.Error                  moveq #-1,d0
                        movem.l (sp)+,d2-d7/a2-a6
                        rts


			XDEF _QSO_StartServer
_QSO_StartServer	exg a4,a5
			move.l 4(sp),d0
			move.l 8(sp),a0
			move.l 12(sp),a1
			jsr QSO_StartServer
			exg a4,a5
			rts


;A0 Server
;A1 Parameter
;D0 Channel

QSO_StartServer         movem.l d2-d7/a2-a6,-(sp)
                        move.l a1,a2
                        move.l d0,d7
                        subq.l #1,d0
                        mulu #qso_Size,d0
                        move.l _QSOs(a5),a3
                        add.l d0,a3
                        move.l a0,a4
                        move.l serlis_Version(a4),d0
                        cmp.l #SERV_MinVersion,d0
                        blt .Error
                        cmp.l #SERV_MaxVersion,d0
                        bgt .Error
                        
                        move.l a3,a0
                        move.l qso_Server(a3),a1
                        move.l _QSOBase(a5),a3
                        move.l d7,d0
                        move.l serlis_ServerInit(a4),a4
                        jsr (a4)
                        tst.l d0
                        bne .Error
                        movem.l (Sp)+,d2-d7/a2-a6
                        moveq #0,d0
                        rts
.Error                  movem.l (sp)+,d2-d7/a2-a6
                        moveq #-1,d0
                        rts

                        XREF _QSO_DoConnect
QSO_DoConnect           exg a4,a5
                        move.l d2,-(sp)
                        move.l d1,-(sp)
                        move.l d0,-(sp)
                        jsr _QSO_DoConnect
                        add.l #12,sp
                        exg a4,a5
                        rts



QSO_DoConnectCText       movem.l d2-d7/a2-a6,-(sp)
                        move.l d0,d7
                        move.l d1,d6

                        tst.l d7
                        ble .Exit
                        move.l d7,d0
                        subq.l #1,d0
                        move.l _QSOs(a5),a0
                        mulu #qso_Size,d0
                        add.l d0,a0
                        move.l a0,a4

                        tst.l d6
                        bne .No_ConnectProc
                        tst.l qso_Server(a4)
                        beq .No_ConnectProc
                        move.l qso_Server(a4),a6
                        move.l a5,-(sp)
                        move.l _QSOBase(a5),a5
                        jsr _SVOConnectProcedure(a6)
                        move.l (sp)+,a5
.No_ConnectProc
.Exit                   movem.l (sp)+,d2-d7/a2-a6
                        rts

QSO_DoDisconnect        jsr MAIN_CleanupChannel
                        jsr GUI_RefreshPacketHead
                        jsr GUI_RefreshConnectHead
                        rts

_QSO_GetPacLen          move.l 4(sp),d0
                        exg a4,a5
                        jsr QSO_GetPacLen
                        exg a4,a5
                        rts

                        
QSO_GetPacLen           jsr QSO_GetChannelQSO
                        tst.l d0
                        beq .PacLen_Std
                        move.l d0,a0
                        move.l qso_User(a0),a0
                        cmpa.l #0,a0
                        beq .PacLen_Std
                        tst.w user_LinkUse(a0)
                        beq .PacLen_SUser
                        moveq #0,d0
                        move.w user_CurPaclen(a0),d0
                        rts
.PacLen_SUser           move.l _UserBaseStandard(a5),a0
                        cmpa.l #0,a0
                        beq .PacLen_Std
                        moveq #0,d0
                        move.w user_CurPaclen(a0),d0
                        rts
.PacLen_Std             move.l #128,d0
                        rts

QSO_GetMaxFrame         jsr QSO_GetChannelQSO
                        tst.l d0
                        beq .MaxFrm_Std
                        move.l d0,a0
                        move.l qso_User(a0),a0
                        cmpa.l #0,a0
                        beq .MaxFrm_Std
                        tst.w user_LinkUse(a0)
                        beq .MaxFrm_SUser
                        moveq #0,d0
                        move.w user_CurMaxFrame(a0),d0
                        rts
.MaxFrm_SUser           move.l _UserBaseStandard(a5),a0
                        cmpa.l #0,a0
                        beq .MaxFrm_Std
                        moveq #0,d0
                        move.w user_CurMaxFrame(a0),d0
                        rts
.MaxFrm_Std             moveq #2,d0
                        rts


QSO_ForceTransmit       movem.l d0-d1/a0,-(sp)
                        tst.l d0
                        ble .BadChannel
                        cmp.l _MaxChannel(a5),d0
                        bgt .BadChannel
                        subq.l #1,d0
                        mulu #qso_Size,d0
                        move.l _QSOs(a5),a0
                        add.l d0,a0
                        tst.l qso_StartupMsg(a0)
                        beq .No_NeedCheck
.BadChannel             movem.l (sp)+,d0-d1/a0
                        rts
.No_NeedCheck           movem.l (sp)+,d0-d1/a0
                        movem.l d2-d3/a2-a3,-(sp)
                        move.l d0,d2
                        mulu #dela_Size,d0
                        move.l d0,d3
                        move.l _DelayBuffers(a5),a2
                        add.l d3,a2
                        tst.l dela_BytesInBuffer(a2)
                        beq .No_Bytes
                        move.l d2,d0
                        tst.l d0
                        beq .No_Compression
                        subq.l #1,d0
                        mulu #qso_Size,d0
                        move.l _QSOs(a5),a0
                        add.l d0,a0
                        btst #0,qso_CompressedMode+3(a0)
                        beq .No_Compression
                        sub.l #256,a7
                        lea dela_Buffer(a2),a0
                        move.l a7,a1
                        move.l dela_BytesInBuffer(a2),d0
                        jsr QSO_HuffmanCompress
                        cmp.l #-1,d0
                        beq .Abort_Compression
                        move.l d2,d1
                        move.l a7,a0
                        jsr QSO_EncryptionHeader
                        tst.l d0
                        beq .Abort_Sending_1
                        jsr PACK_TransmitData
                        add.l #256,a7
                        bra .Compressed_Send
.Abort_Compression      move.l d2,d0
                        subq.l #1,d0
                        mulu #qso_Size,d0
                        move.l _QSOs(a5),a0
                        add.l d0,a0
                        bclr #0,qso_CompressedMode+3(a0)
                        jsr GUI_RefreshConnectHead
.No_Compression         lea dela_Buffer(a2),a0
                        move.l dela_BytesInBuffer(a2),d0
                        move.l d2,d1
.Redo_Encrypt           jsr QSO_EncryptionHeader
                        tst.l d0
                        beq .Abort_Sending_2
                        jsr PACK_TransmitData
.Compressed_Send        moveq #0,d0
                        move.l d2,d1
                        sub.l a0,a0
                        bra .Redo_Encrypt
.Abort_Sending_1        add.l #256,a7
.Abort_Sending_2        clr.l dela_BytesInBuffer(a2)
.No_Bytes               movem.l (sp)+,d2-d3/a2-a3
                        rts

QSO_TransmitDataXFer    move.l d1,-(sp)
                        subq.l #1,d1
                        mulu #qso_Size,d1
                        move.l _QSOs(a5),a1
                        add.l d1,a1
                        move.l (sp)+,d1
                        btst #6,qso_CompressedMode+3(a1)
                        beq .No_XPDelay
                        btst #7,qso_CompressedMode+3(a1)
                        bne .No_XPDelay
                        movem.l d0-d1/a0/a6,-(sp)
                        addq.l #8,d0
                        moveq #1,d1
                        move.l _SysBase(a5),a6
                        move.l a1,-(sp)
                        jsr _LVOAllocVec(a6)
                        move.l (sp)+,a1
                        tst.l d0
                        beq .Memory_Lack


                        lea qso_XPacketDelay(a1),a0
.XPD_Loop               tst.l (a0)
                        beq .XPD_EndFound
                        move.l (a0),a0
                        bra .XPD_Loop
.XPD_EndFound           move.l d0,(a0)
                        move.l d0,a1
                        clr.l (a1)
                        movem.l (sp)+,d0/d1/a0/a6
                        move.l d0,4(a1)
                        lea 8(a1),a1
.XPD_Copy               tst.l d0
                        beq .EndCopy
                        move.b (a0)+,(a1)+
                        subq.l #1,d0
                        bra .XPD_Copy
.EndCopy                rts
.Memory_Lack            movem.l (sp)+,d0/d1/a0/a6
                        rts
.No_XPDelay             jsr QSO_SendDataXPChecked
                        rts


_QSO_FlushXPacketDelay  exg a4,a5
                        move.l 4(sp),d0
                        jsr QSO_FlushXPacketDelay
                        exg a4,a5
                        rts


QSO_FlushXPacketDelay   movem.l a4/a6/d7,-(sp)
                        move.l d0,d7
                        subq.l #1,d0
                        mulu #qso_Size,d0
                        move.l _QSOs(a5),a4
                        add.l d0,a4
.Loop                   tst.l qso_XPacketDelay(a4)
                        beq .Exit
                        move.l qso_XPacketDelay(a4),a0
                        move.l d7,d1
                        move.l 4(a0),d0
                        lea 8(a0),a0
                        jsr QSO_SendDataXPChecked
                        move.l qso_XPacketDelay(a4),a1
                        move.l (a1),qso_XPacketDelay(a4)
                        move.l _SysBase(a5),a6
                        jsr _LVOFreeVec(a6)
                        bra .Loop
.Exit                   movem.l (sp)+,a4/a6/d7
                        rts


QSO_SendData            movem.l d0-d1/a0,-(sp)
                        tst.l d1
                        beq .Transmit_Monitor
                        blt .No_Skippy
                        cmp.l _MaxChannel(a5),d1
                        bgt .No_Skippy
                        move.l d1,d0
                        subq.l #1,d0
                        mulu #qso_Size,d0
                        move.l _QSOs(a5),a0
                        add.l d0,a0
                        tst.l qso_SkipChannel(a0)
                        bne .No_Skippy
                        tst.l qso_StartupMsg(a0)
                        beq .No_NeedCheck
.No_Skippy              movem.l (sp)+,d0-d1/a0
                        rts
.Transmit_Monitor       jsr PACK_TransmitData
                        movem.l (sp)+,d0/d1/a0
                        rts
.No_NeedCheck           movem.l (sp)+,d0/d1/a0
                        jsr QSO_TransmitDataXFer
                        rts
QSO_SendDataXPChecked
                        move.l d1,-(sp)
                        subq.l #1,d1
                        mulu #qso_Size,d1
                        move.l _QSOs(a5),a1
                        add.l d1,a1
                        move.l (sp)+,d1
                        btst #4,qso_CompressedMode+3(a1)
                        beq .QSO_SendDataRealFake


                        movem.l a0/d0,-(sp)
                        movem.l d1/a2,-(sp)
                        sub.l a2,a2
                        move.l a1,a2
                        lea .QSO_SendDataReal(pc),a1
                        jsr QSO_HuffmanCompressXP
                        movem.l (sp)+,d1/a2
                        cmp.l #-1,d0
                        beq .QSO_XPHuffError
                        addq.l #8,a7
                        rts
.QSO_XPHuffError        movem.l (sp)+,a0/d0

.QSO_SendDataRealFake   move.l d1,-(sp)
                        move.l d0,-(sp)
                        move.l a0,-(sp)
                        exg a4,a5
                        bsr .QSO_SendDataReal
                        exg a4,a5
                        add.l #12,sp
                        rts

.QSO_SendDataReal       move.l 4(sp),a0
                        move.l 8(sp),d0
                        move.l 12(sp),d1
                        exg a4,a5
                        movem.l d2-d7/a2-a6,-(sp)
                        tst.l d1
                        blt .Exit
                        move.l d0,d5
                        move.l d1,d6
                        move.l a0,a4
                        mulu #dela_Size,d1
                        move.l _DelayBuffers(a5),a2
                        lea _Preferences(a5),a3
                        add.l d1,a2
                        
                        lea _CurrentDateStamp(a5),a0
                        lea dela_DateStamp(a2),a1
                        clr.l (a1)
                        clr.l 4(a1)
                        move.l pref_DataCollectorTime(a3),d0
                        lsr.l #1,d0
                        move.l d0,8(a1)
                        jsr MAIN_AddTimeStamp
.Loop                   move.l dela_BytesInBuffer(a2),d0
                        move.l d0,-(sp)
                        move.l d6,d0
                        jsr QSO_GetPacLen
                        move.l (sp)+,d1
                        cmp.l d0,d1
                        blt .No_Flushing
                        move.l d6,d0
                        jsr QSO_ForceTransmit
.No_Flushing            tst.l d5
                        beq .Exit
                        subq.l #1,d5
                        move.l dela_BytesInBuffer(a2),d0
                        lea dela_Buffer(a2),a0
                        add.l d0,a0
                        addq.l #1,d0
                        move.l d0,dela_BytesInBuffer(a2)
                        move.b (a4)+,(a0)+
                        bra .Loop
.Exit                   
                        movem.l (sp)+,d2-d7/a2-a6
                        exg a4,a5
                        rts
                                                
                        
                        
                        
                        


QSO_SendCommandUser     tst.l d1
                        beq .Normal_Command
                        blt .Exit
                        tst.l d0
                        beq .Exit
                        cmp.b #$1b,(a0)
                        beq .Escaped_User
.Normal_Command         bra QSO_SendCommand
.Exit                   rts
.Escaped_User           cmp.l #1,d0
                        ble .Exit
                        move.l d2,-(sp)
                        move.l d1,d2
                        moveq #7,d1
                        movem.l a0/d0,-(sp)
                        subq.l #1,d0
                        move.l a0,a1
                        addq.l #1,a0
.Looping_Copy           tst.l d0
                        beq .Looping_Ended
                        move.b (a0)+,(A1)+
                        subq.l #1,d0
                        bra .Looping_Copy
.Looping_Ended          move.b #$d,(A1)+
                        movem.l (sp)+,d0/a0
                        tst.l d2
                        ble .XX_NoCompr
                        movem.l d0-d2/a0,-(sp)
                        move.l d2,d0
                        subq.l #1,d0
                        mulu #qso_Size,d0
                        move.l _QSOs(a5),a1
                        add.l d0,a1
                        btst #1,qso_CompressedMode+3(a1)
                        bne .Echo_Compressed
                        btst #3,qso_CompressedMode+3(a1)
                        bne .Echo_Compressed
                        btst #5,qso_CompressedMode+3(a1)
                        bne .Echo_Compressed
                        movem.l (sp)+,d0-d2/a0
.XX_NoCompr             jsr QSO_IncomingChannel
                        move.l (Sp)+,d2
                        rts
.Echo_Compressed        movem.l (sp)+,d0-d2/a0
                        move.l qso_CompressedMode(a1),-(sp)
                        bclr #1,qso_CompressedMode+3(a1)
                        bclr #3,qso_CompressedMode+3(a1)
                        bclr #5,qso_CompressedMode+3(a1)
                        move.l a1,-(sp)
                        jsr QSO_IncomingChannel
                        move.l (Sp)+,a1
                        move.l (sp)+,d0
                        and.l #$2a,d0
                        btst #0,qso_CompressedMode+3(a1)
                        bne .Echo_CompNotLost
                        bclr #0,d0
                        bclr #1,d0
.Echo_CompNotLost       btst #4,qso_CompressedMode+3(a1)
                        bne .Echo_CompXPNotLost
                        bclr #4,d0
                        bclr #5,d0
.Echo_CompXPNotLost     or.l d0,qso_CompressedMode(a1)
                        move.l (sp)+,d2
                        rts



QSO_SendCommand         movem.l d0-d1/a0,-(sp)
                        tst.l d1
                        ble .No_NeedCheck
                        move.l d1,d0
                        subq.l #1,d0
                        mulu #qso_Size,d0
                        move.l _QSOs(a5),a0
                        add.l d0,a0
                        tst.l qso_StartupMsg(a0)
                        beq .No_NeedCheck
                        movem.l (sp)+,d0-d1/a0
                        rts
.No_NeedCheck           movem.l (sp)+,d0-d1/a0
                        jsr PACK_TransmitCommand
                        rts
QSO_SendDataDirect      movem.l d0-d1/a0,-(sp)
                        tst.l d1
                        ble .No_NeedCheck
                        move.l d1,d0
                        subq.l #1,d0
                        mulu #qso_Size,d0
                        move.l _QSOs(a5),a0
                        add.l d0,a0
                        tst.l qso_StartupMsg(a0)
                        beq .No_NeedCheck
                        movem.l (sp)+,d0-d1/a0
                        rts
.No_NeedCheck           movem.l (sp)+,d0-d1/a0
                        jsr PACK_TransmitData
                        rts

QSO_SendDataUser        tst.l d1
                        beq .SendData_Monitor
                        blt .Exit
                        tst.l d0
                        beq .Exit
                        movem.l d1/a4/a6,-(Sp)
                        subq.l #1,d1
                        mulu #qso_Size,d1
                        move.l _QSOs(A5),a4
                        add.l d1,a4
                        tst.l qso_Server(a4)
                        beq .SendData_NoServ
                        move.l qso_Server(A4),a6
                        move.l a5,-(Sp)
                        move.l _QSOBase(a5),a5
                        jsr _SVOTerminalInput(a6)
                        move.l (sp)+,a5
                        movem.l (sp)+,d1/a4/a6
                        rts
.SendData_NoServ        movem.l (sp)+,d1/a4/a6
.SendData_Monitor       movem.l d0-d1/a0,-(sp)
                        jsr QSO_SendData
                        movem.l (sp)+,d0-d1/a0
                        tst.l d1
                        beq .Exit
                        move.l d2,-(sp)
                        moveq #2,d2
                        jsr GUI_WriteToQSO
                        move.l (Sp)+,d2
                        
.Exit                   rts

QSO_IncomingMonitor

                        move.l d2,-(sp)
                        move.l d1,-(sp)
                        move.l d0,-(sp)
                        move.l a0,-(sp)
                        exg a4,a5
                        XREF _QSO_IncomingMonitor
                        jsr _QSO_IncomingMonitor
                        exg a4,a5
                        add.l #16,sp
                        rts

                        XDEF _QSO_OutputEvent
_QSO_OutputEvent        move.l 4(sp),d0
                        move.l 8(sp),a0
                        move.l 12(sp),a1
                        exg a4,a5
                        jsr QSO_OutputEvent
                        exg a4,a5
                        rts


QSO_OutputEvent         movem.l d7/a3-a4,-(Sp)
                        move.l a0,a4
                        move.l a1,a3
                        move.l d0,d7
.Loop                   cmp.b #$d,(a0)
                        beq .LoopCR
                        tst.b (a0)+
                        bne .Loop
                        subq.l #2,a0
                        cmp.b #$a,(a0)
                        bne .LoopEnd
                        clr.b (a0)
                        bra .LoopEnd
.LoopCR                 move.b #$a,(a0)+
                        bra .Loop
.LoopEnd                move.l a4,a0
                        jsr GUI_DisplayEventWindow
                        
                        cmp.l #1,d7
                        beq .Play_Becher
                        tst.l d7
                        beq .Play_LinkBeep
                        cmp.l #2,d7
                        beq .Play_Funeral
                        bra .Exit
.Play_Becher            moveq #4,d0
                        move.l a3,a0
                        jsr AUDIO_Effect
                        bra .Exit
.Play_Funeral           moveq #8,d0
                        move.l a3,a0
                        jsr AUDIO_Effect
                        bra .Exit
.Play_LinkBeep          moveq #5,d0
                        move.l a3,a0
                        jsr AUDIO_Effect
.Exit                   movem.l (sp)+,d7/a3-a4
                        rts

QSO_IncomingChannel     movem.l d2-d7/a2-a4,-(sp)
                        move.l d0,d6
                        move.l d1,d7
                        move.l d2,d5
                        move.l a0,a4
                        
                        cmp.b #3,d7
                        beq .Incoming_Link
                        cmp.b #7,d7
                        beq .Incoming_Data
                        bra .Old_Incoming
.Exit                   movem.l (sp)+,d2-d7/a2-a4
                        rts
.Incoming_Data          move.l d5,d0
                        subq.l #1,d0
                        mulu #qso_Size,d0
                        move.l _QSOs(a5),a3
                        add.l d0,a3
                        
                        lea _CurrentDateStamp(a5),a0
                        lea qso_ActivityTime(a3),a1
                        move.l (a0),(a1)
                        move.l 4(a0),4(a1)
                        move.l 8(a0),8(A1)

                        tst.l qso_Server(a3)
                        beq .Incoming_Data_NoServ
                        sub.l #320,a7
                        move.l d6,d0
                        move.l a4,a0
.Redo_Decrypt           move.l d5,d1
                        jsr QSO_DecryptionHeader
                        tst.l d0
                        beq .No_DataRemain
                        move.l d0,d6
                        move.l a0,a4
                        btst #1,qso_CompressedMode+3(a3)
                        beq .No_Compression
                        move.l a4,a0
                        move.l a7,a1
                        move.l d6,d0
                        jsr QSO_HuffmanDecompress
                        cmp.l #-1,d0
                        beq .Compression_Failed
                        move.l d0,d6
                        move.l a7,a4
                        bra .No_Compression
.Compression_Failed     bclr #1,qso_CompressedMode+3(a3)
                        bclr #0,qso_CompressedMode+3(a3)
                        jsr GUI_RefreshConnectHead
.No_Compression

                        btst #5,qso_CompressedMode+3(a3)
                        beq .No_XP_Compression

                        move.l d5,d0
                        move.l d6,d1
                        move.l a4,a0
                        lea qso_XPDecompress(a3),a1
                        lea .Incoming_My_Hook_C(pc),a2
                        move.l a3,-(sp)
                        jsr QSO_DecompressXPStream
                        move.l (sp)+,a3
                        ;tst.l d0
                        ;bne .Redo_Decrypt
                        moveq #0,d0
                        sub.l a0,a0
                        bra .Redo_Decrypt
.No_XP_Compression      move.l d5,d0
                        move.l d6,d1
                        move.l a4,a0
                        bsr .Incoming_My_Hook
                        moveq #0,d0
                        sub.l a0,a0
                        bra .Redo_Decrypt



.Incoming_My_Hook_C     exg a4,a5
                        move.l 4(sp),a0
                        move.l 8(sp),d0
                        move.l 12(sp),d1
                        bsr .Incoming_My_Hook
                        exg a4,a5
                        rts


;>D0 Channel
;>D1 Datalength
;>A0 Data

.Incoming_My_Hook       movem.l d2-d7/a2-a6,-(sp)
                        move.l d0,d5
                        subq.l #1,d0
                        mulu #qso_Size,d0
                        move.l _QSOs(a5),a3
                        add.l d0,a3
                        move.l a0,a4
                        move.l d1,d6
                        move.l a6,-(sp)
                        move.l qso_Server(a3),a6
                        move.l a5,-(Sp)
                        move.l _QSOBase(a5),a5
                        jsr _SVOGetServerType(a6)
                        move.l (sp)+,a5
                        move.l (sp)+,a6
                        btst #8,d0
                        bne .No_PrPaHead
.PrPa_StepBack          
                        tst.l d6
                        beq .No_DataRemain_Pac
                        tst.l qso_PrPaPointer(a3)
                        beq .No_PrPaInWork
                        move.l d6,d0
                        move.l qso_PrPaLength(a3),d1
                        sub.l qso_PrPaReceived(a3),d1
                        cmp.l d1,d0
                        ble .PrPa_DataGood
                        move.l d1,d0
.PrPa_DataGood          move.l qso_PrPaPointer(a3),a1
                        add.l qso_PrPaReceived(a3),a1
                        add.l d0,qso_PrPaReceived(a3)
                        move.l a4,a0
                        sub.l d0,d6
                        add.l d0,a4
.Copy_PrPaData          tst.l d0
                        beq .Copy_PrPaDataEnd
                        subq.l #1,d0
                        move.b (a0)+,(a1)+
                        bra .Copy_PrPaData
.Copy_PrPaDataEnd       move.l qso_PrPaReceived(a3),d0
                        cmp.l qso_PrPaLength(a3),d0
                        bne .No_DataRemain_Pac
                        move.l d5,d0
                        move.l qso_PrPaType(a3),d1
                        move.l qso_PrPaLength(a3),d2
                        move.l qso_PrPaVersion(a3),d3
                        move.l qso_PrPaPointer(a3),a0
                        jsr QSO_HandlePrPaIncoming
                        
                        move.l qso_PrPaPointer(a3),a1
                        clr.l qso_PrPaPointer(a3)
                        move.l _SysBase(a5),a6
                        jsr _LVOFreeVec(a6)
                        bra .No_PrPaHead                        
.No_PrPaInWork          cmp.l #14,d6
                        blt .No_PrPaHead
                        cmp.b #"#",(a4)
                        bne .No_PrPaHead
                        cmp.b #"P",1(a4)
                        bne .No_PrPaHead
                        cmp.b #"r",2(a4)
                        bne .No_PrPaHead
                        cmp.b #"P",3(a4)
                        bne .No_PrPaHead
                        cmp.b #"a",4(a4)
                        bne .No_PrPaHead
                        cmp.b #"#",5(a4)
                        bne .No_PrPaHead
                        moveq #0,d0
                        moveq #0,d1
                        moveq #0,d2
                        moveq #0,d3
                        move.w 6(a4),d0
                        move.w 8(a4),d1
                        move.w 10(a4),d2
                        move.w 12(a4),d3
                        add.w d0,d3
                        add.w d1,d3
                        add.w d2,d3
                        cmp.w #$ffff,d3
                        bne .No_PrPaHead
                        move.l d0,qso_PrPaType(a3)
                        move.l d1,qso_PrPaLength(a3)
                        move.l d2,qso_PrPaVersion(a3)
                        clr.l qso_PrPaReceived(a3)
                        move.l d1,d0
                        move.l #$10000,d1
                        move.l _SysBase(a5),a6
                        jsr _LVOAllocVec(a6)
                        tst.l d0
                        beq .No_PrPaHead
                        move.l d0,qso_PrPaPointer(a3)
                        add.l #14,a4
                        sub.l #14,d6
                        bra .PrPa_StepBack
                        
                        
                        
.No_PrPaHead            tst.l d6
                        beq .No_DataRemain_Pac
                        move.l a6,-(sp)
                        move.l qso_Server(a3),a6
                        move.l a4,a0
                        move.l d6,d0
                        move.l a3,a1
                        jsr MAIN_WriteServBuffer
                        move.l a3,a0
                        jsr MAIN_TestServBuffer
                        move.l a5,-(sp)
                        move.l _QSOBase(a5),a5
                        jsr _SVOReceivePacket(a6)
                        move.l (sp)+,a5
                        move.l (sp)+,a6
.No_DataRemain_Pac      movem.l (sp)+,d2-d7/a2-a6
                        rts


.No_DataRemain          add.l #320,a7
                        bra .Exit
.Incoming_Data_NoServ   move.l d6,d0
                        move.l d5,d1
                        moveq #1,d2
                        move.l a4,a0
                        jsr GUI_WriteToQSO
                        bra .Exit
.Incoming_Link          move.l d6,d0
                        move.l d5,d1
                        moveq #$42,d2                   
                        move.l a4,a0
                        jsr GUI_WriteToQSO
                        subq.l #4,a7
                        move.l a7,a0
                        move.b #$d,(a0)
                        moveq #1,d0
                        move.l d5,d1
                        moveq #$21,d2
                        jsr GUI_WriteToQSO
                        addq.l #4,a7
                        sub.l #290,a7
                        move.l a4,a0
                        move.l a7,a1
                        move.l d6,d0
.Incoming_Link_Copy     tst.l d0
                        beq .Incoming_Link_Coped
                        subq.l #1,d0
                        move.b (a0)+,(a1)+
                        bra .Incoming_Link_Copy
.Incoming_Link_Coped    clr.b (A1)+
                        move.l d6,d0
                        move.l a4,a0
                        jsr PACK_AnalizeLinkStatusL
                        move.l d0,d1
                        moveq #0,d0
                        cmp.l #5,d1
                        bne .No_LinkFail
                        moveq #2,d0             
.No_LinkFail            cmp.l #1,d1
                        bne .No_Constat
                        moveq #-1,d0
.No_Constat             move.l a7,a0
                        move.l a3,a1
                        jsr QSO_OutputEvent
                        add.l #290,a7
                        bra .Exit                       
.Old_Incoming           sub.l #290,a7
                        move.l a7,a0
                        move.l a7,a1
                        cmp.b #1,d7
                        beq .DO_RawCopy
                        cmp.b #2,d7
                        beq .DO_RawCopy
                        bra .Exit_Old
.DO_RawCopy             cmp.b #1,d7
                        beq .DO_RawFor1
                        cmp.b #2,d7
                        beq .DO_RawFor2
                        bra .DO_RawNorm
.DO_RawFor1             move.b #"T",(a1)+
                        move.b #"N",(a1)+
                        move.b #"C",(a1)+
                        move.b #" ",(a1)+
                        move.b #"A",(a1)+
                        move.b #"n",(a1)+
                        move.b #"s",(a1)+
                        move.b #"w",(a1)+
                        move.b #"e",(a1)+
                        move.b #"r",(a1)+
                        move.b #":",(a1)+
                        move.b #$d,(A1)+
                        bra .DO_RawNorm
.DO_RawFor2             move.b #"T",(a1)+
                        move.b #"N",(a1)+
                        move.b #"C",(a1)+
                        move.b #" ",(a1)+
                        move.b #"E",(a1)+
                        move.b #"r",(a1)+
                        move.b #"r",(a1)+
                        move.b #"o",(a1)+
                        move.b #"r",(a1)+
                        move.b #":",(a1)+
                        move.b #$d,(A1)+
.DO_RawNorm             move.l d6,d0
                        move.l a4,a0
.DO_RawCopy_L           tst.l d0
                        beq .DO_RawCopied
                        subq.l #1,d0
                        move.b (a0)+,d1
                        tst.b d1
                        beq .DO_RawCopy_L
                        move.b d1,(a1)+
                        bra .DO_RawCopy_L
.DO_RawCopied           clr.b (a1)
                        cmp.l a7,a1
                        beq .Exit_Old
                        moveq #-1,d0
                        move.l a7,a0
                        move.l a3,a1
                        jsr QSO_OutputEvent
.Exit_Old               add.l #290,a7
                        bra .Exit

QSO_WriteTerminal       move.l d2,-(sp)
                        moveq #1,d2
                        jsr GUI_WriteToQSO
                        move.l (sp)+,d2
                        rts
                
QSO_CreateServerBase    movem.l d2-d4/a2-a6,-(sp)
                        move.l d0,d2
                        move.l d1,d3
                        move.l a0,a4
                        add.l d1,d0
                        move.l #$10001,d1
                        move.l _SysBase(a5),a6
                        jsr _LVOAllocVec(a6)
                        tst.l d0
                        beq .Exit
                        move.l d0,a3
                        move.l a3,a1
                        move.l a4,a0
                        sub.l d2,a0
                        move.l d2,d0
.Loop_1                 tst.l d0
                        beq .Looped_1
                        subq.l #1,d0
                        move.b (a0)+,(a1)+
                        bra .Loop_1
.Looped_1               jsr _LVOCacheClearU(a6)
                        move.l a3,d0    
                        add.l d2,d0
        
.Exit                   movem.l (sp)+,d2-d4/a2-a6
                        rts

;>D0 Channel
;>D1 Output terminal
;>D2 Macro decode
;>A0 Text

QSO_TransmitText        movem.l d2-d7/a2-a6,-(sp)
                        move.l d0,d7
                        moveq #0,d6
                        tst.l d1
                        beq .SB_NoTermOut
                        bset #0,d6
.SB_NoTermOut           tst.l d2
                        beq .SB_NoMacroDecode
                        bset #1,d6
.SB_NoMacroDecode       move.l a0,a4
                        tst.l d7
                        bne .Main_Loop
                        clr.b _Temporary(a5)
                        jsr PACK_GetMonitorUnit
                        cmp.l #0,d0
                        blt .Exit
                        cmp.l #8,d0
                        bge .Exit
.Main_Loop              moveq #0,d5
                        move.l a4,a3
.Search_EndSign         move.b (a3)+,d0
                        tst.b d0
                        beq .EndSign_Found
                        btst #1,d6
                        beq .No_MacroDecode
                        cmp.b #"%",d0
                        beq .MacroDecode_Found
.No_MacroDecode         addq.l #1,d5
                        bra .Search_EndSign
.EndSign_Found          moveq #0,d4
                        bra .Putout_Part
.MacroDecode_Found      moveq #1,d4
.Putout_Part            move.l d5,d0
                        move.l d7,d1
                        move.l a4,a0
                        jsr .Subsending_Routine
                        add.l d5,a4
                        tst.l d4
                        beq .Exit
                        cmp.b #"%",(a4)
                        bne .Exit
                        addq.l #1,a4
                        moveq #0,d4
.Analize_Macro          cmp.b #"0",(a4)
                        blt .NoMore_Number
                        cmp.b #"9",(a4)
                        bgt .NoMore_Number
                        move.b (a4)+,d0
                        and.l #$f,d0
                        mulu #10,d4
                        add.l d0,d4
                        bra .Analize_Macro
.NoMore_Number          move.b (a4)+,d0
                        tst.b d0
                        beq .Exit
                        cmp.b #$61,d0
                        blt .No_Macro_Lowcase
                        cmp.b #$7a,d0
                        bgt .No_Macro_Lowcase
                        sub.b #$20,d0
.No_Macro_Lowcase       cmp.b #"%",d0
                        beq .Macro_Escape
                        tst.l d7
                        beq .Macro_InMonitor
                        move.l d7,d1
                        subq.l #1,d1
                        mulu #qso_Size,d1
                        move.l _QSOs(A5),a3
                        add.l d1,a3
.Macro_InMonitor

                        moveq #0,d3
                        ;Macros for Channels + Monitor
                        cmp.b #"D",d0
                        beq .MACRO_SystemDate
                        cmp.b #"H",d0
                        beq .MACRO_HardwareUnit
                        cmp.b #"M",d0
                        beq .MACRO_MyCall
                        cmp.b #"Z",d0
                        beq .MACRO_SystemTime
                        cmp.b #"#",d0
                        beq .MACRO_MailList


                        ;Macros for Channels
                        tst.l d7
                        beq .Main_Loop
                        cmp.b #"A",d0
                        beq .MACRO_ThisDate
                        cmp.b #"B",d0
                        beq .MACRO_Boxcheck
                        cmp.b #"C",d0
                        beq .MACRO_Call
                        cmp.b #"L",d0
                        beq .MACRO_LastDate
                        cmp.b #"N",d0
                        beq .MACRO_Name
                        cmp.b #"O",d0
                        beq .MACRO_Origin
                        cmp.b #"P",d0
                        beq .MACRO_ChannelNumber
                        cmp.b #"T",d0
                        beq .MACRO_LastTime
                        cmp.b #"V",d0
                        beq .MACRO_ThisTime
                        cmp.b #"?",d0
                        beq .MACRO_SkipNameHere
                        cmp.b #"!",d0
                        beq .MACRO_SkipNewsLine
                        cmp.b #"$",d0
                        beq .MACRO_MailMacro
                        bra .Main_Loop
.Main_Loop_NCR          cmp.b #$d,(a4)
                        bne .Main_Loop
                        addq.l #1,a4
                        bra .Main_Loop
                        
.MACRO_MailMacro        tst.b qso_Call(a3)
                        beq .Main_Loop_NCR
                        lea qso_Call(a3),a0
                        jsr MAIL_TestForMail
                        tst.l d0
                        beq .Main_Loop_NCR
                        movem.l d2-d5/a2-a6,-(Sp)
                        sub.l #84,a7
                        move.l d0,d5
                        move.l d0,d4
                        move.l a7,a0
                        tst.w d4
                        beq .MACRO_Mail_NoOld
                        moveq #0,d0
                        move.w d4,d0
                        jsr .Output_Fiver
                        move.l a0,-(sp)
                        move.l a3,a1
                        lea QSO_Texts,a0
                        moveq #16,d0
                        move.l a2,-(sp)
                        lea QSO_Locale,a2
                        jsr QSO_GetText
                        move.l (sp)+,a2
                        move.l (Sp)+,a0
                        move.l d0,a1
.Copy_OldText_L         tst.b (a1)
                        beq .Copy_OldText_Done
                        move.b (A1)+,(a0)+
                        bra .Copy_OldText_L
.Copy_OldText_Done      clr.b (a0)+
                        move.l a7,a0
                        moveq #-1,d0
.MACRO_MailMacro_OG     addq.l #1,d0
                        tst.b (a0)+
                        bne .MACRO_MailMacro_OG
                        move.l d7,d1
                        move.l a7,a0
                        jsr .Subsending_Routine
.MACRO_Mail_NoOld       move.l a7,a0
                        swap d4
                        tst.w d4
                        beq .MACRO_Mail_NoNew
                        moveq #0,d0
                        move.w d4,d0
                        jsr .Output_Fiver
                        move.l a0,-(sp)
                        move.l a3,a1
                        lea QSO_Texts,a0
                        moveq #15,d0
                        move.l a2,-(sp)
                        lea QSO_Locale,a2
                        jsr QSO_GetText
                        move.l (sp)+,a2
                        move.l (Sp)+,a0
                        move.l d0,a1
.Copy_NewText_L         tst.b (a1)
                        beq .Copy_NewText_Done
                        move.b (A1)+,(a0)+
                        bra .Copy_NewText_L
.Copy_NewText_Done      clr.b (a0)+
                        move.l a7,a0
                        moveq #-1,d0
.MACRO_MailMacro_NG     addq.l #1,d0
                        tst.b (a0)+
                        bne .MACRO_MailMacro_NG
                        move.l d7,d1
                        move.l a7,a0
                        jsr .Subsending_Routine
.MACRO_Mail_NoNew       tst.w d4
                        beq .MACRO_MailEnd
                        lea _Preferences(a5),a0
                        tst.l pref_ShowMaillist(a0)
                        beq .MACRO_MailEnd
                        moveq #0,d5
.MACRO_MailMacro_L      lea qso_Call(a3),a0
                        moveq #3,d0
                        move.l d5,d1
                        move.l a7,a1
                        jsr MAIL_GetMailLines
                        tst.l d0
                        beq .MACRO_MailEnd
                        move.l d0,d5
                        move.l a7,a0
                        moveq #-1,d0
.MACRO_MailMacro_LG     addq.l #1,d0
                        tst.b (a0)+
                        bne .MACRO_MailMacro_LG
                        move.l d7,d1
                        move.l a7,a0
                        jsr .Subsending_Routine
                        bra .MACRO_MailMacro_L
.MACRO_MailEnd          add.l #84,a7
                        movem.l (sp)+,d2-d5/a2-a6
                        bra .Main_Loop
.Output_Fiver           movem.l d2-d4,-(sp)
                        moveq #0,d1
                        moveq #0,d2
                        moveq #0,d3
                        moveq #0,d4
                        divu #10000,d0
                        swap d0
                        move.w d0,d1
                        clr.w d0
                        swap d0
                        divu #1000,d1
                        swap d1
                        move.w d1,d2
                        clr.w d1
                        swap d1
                        divu #100,d2
                        swap d2
                        move.w d2,d3
                        clr.w d2
                        swap d2
                        divu #10,d3
                        swap d3
                        move.w d3,d4
                        clr.w d3
                        swap d3
                        tst.l d0
                        bne .FiveNumber_Bid
                        tst.l d1
                        bne .FourNumber_Bid
                        tst.l d2
                        bne .ThreeNumber_Bid
                        tst.l d3
                        bne .TwoNumber_Bid
                        move.b #$10,d3
.TwoNumber_Bid          move.b #$10,d2
.ThreeNumber_Bid        move.b #$10,d1
.FourNumber_Bid         move.b #$10,d0
.FiveNumber_Bid         eor.b #$30,d0
                        eor.b #$30,d1
                        eor.b #$30,d2
                        eor.b #$30,d3
                        eor.b #$30,d4   
                        move.b d0,(a0)+
                        move.b d1,(a0)+
                        move.b d2,(a0)+
                        move.b d3,(a0)+
                        move.b d4,(a0)+
                        movem.l (sp)+,d2-d4
                        rts

.MACRO_HardwareUnit     sub.l #16,a7
                        tst.l d7
                        beq .MACRO_HUnit_Mon
                        move.l qso_HardwareUnit(a3),d0
.MACRO_HUnit_Mon_2      addq.l #1,d0
                        moveq #16,d3
                        move.l a7,a0
                        jsr MAIN_LongToString
                        move.l a7,a2
                        bra .Handle_Macro
.MACRO_HUnit_Mon        jsr PACK_GetMonitorUnit
                        bra .MACRO_HUnit_Mon_2

.MACRO_Boxcheck         sub.l #32,a7
                        moveq #32,d3
                        move.l qso_User(a3),a0
                        cmpa.l #0,a0
                        beq .MACRO_NoBoxcheck
                        move.l user_LastBoxcheck(a0),d0
                        move.l d0,-(sp)
                        jsr MAIL_GetLatestMail
                        move.l (sp)+,d1
                        cmp.l d0,d1
                        beq .MACRO_NoBoxcheck
                        move.l d0,-(sp)
                        lea 4(a7),a0
                        move.l d1,d0
                        addq.l #1,d0
                        jsr MAIN_LongToString
                        lea 4(a7),a0
.MACRO_BoxcheckAppend   tst.b (a0)+
                        bne .MACRO_BoxcheckAppend
                        subq.l #1,a0
                        move.b #"-",(a0)+
                        move.l (sp)+,d0
                        jsr MAIN_LongToString
                        move.l a7,a2
                        bra .Handle_Macro
.MACRO_MailList         tst.l d7
                        bne .MACRO_MailList_General
                        jsr PACK_GetMonitorUnit
                        cmp.l #-1,d0
                        beq .MACRO_MailList_General
                        bra .MACRO_MailList_Special
.MACRO_MailList_General moveq #8,d0
.MACRO_MailList_Special sub.l #200,a7
                        move.l a7,a0
                        move.l #200,d3
                        move.l d0,-(sp)
                        move.l a0,-(sp)
                        exg a4,a5
                        jsr _MAIL_HandleMailMacro
                        exg a4,a5
                        addq.l #8,a7
                        move.l a7,a2
                        bra .Handle_Macro
.MACRO_NoBoxcheck       move.l a7,a0
                        move.l #"----",(a0)
                        clr.b (a0)
                        move.l a7,a2
                        bra .Handle_Macro

.MACRO_ChannelNumber    sub.l #16,a7
                        moveq #16,d3
                        move.l a7,a0
                        move.l d7,d0
                        jsr MAIN_LongToString
                        move.l a7,a2
                        bra .Handle_Macro
.MACRO_Name             lea qso_Name(a3),a2
                        move.l qso_User(a3),a2
                        cmpa.l #0,a2
                        beq .MACRO_Call
                        lea user_Name(a2),a2
                        tst.b (a2)
                        beq .MACRO_Call
                        bra .Handle_Macro
.MACRO_Call             lea qso_Call(a3),a2
                        bra .Handle_Macro
.MACRO_MyCall           tst.l d7
                        beq .MACRO_GlobalMycall
                        lea qso_MyCall(A3),a2
                        bra .Handle_Macro
.MACRO_GlobalMycall     jsr PACK_GetMonitorUnit
                        mulu #devi_Size,d0
                        lea _Preferences(a5),a0
                        lea pref_Devices(a0),a0
                        add.l d0,a0
                        lea devi_GlobalMycall(a0),a2
                        bra .Handle_Macro
.MACRO_ThisTime         lea qso_ConnectTime(a3),a0
                        bra .MACRO_UniTime
.MACRO_ThisDate         lea qso_ConnectTime(a3),a0
                        bra .MACRO_UniDate
.MACRO_LastTime         lea qso_LastLogin(a3),a0
                        move.l (a0),d0
                        or.l 4(a0),d0
                        or.l 8(a0),d0
                        tst.l d0
                        beq .MACRO_LastNoHere
                        bra .MACRO_UniTime
.MACRO_LastDate         lea qso_LastLogin(a3),a0
                        move.l (a0),d0
                        or.l 4(a0),d0
                        or.l 8(a0),d0
                        tst.l d0
                        beq .MACRO_LastNoHere
                        bra .MACRO_UniDate
.MACRO_LastNoHere       sub.l #16,a7
                        moveq #16,d3
                        move.l a7,a0
                        move.l #"????",(a0)+
                        clr.b (a0)
                        move.l a7,a2
                        bra .Handle_Macro

.MACRO_SystemTime       lea _CurrentDateStamp(a5),a0
                        bra .MACRO_UniTime
.MACRO_SystemDate       lea _CurrentDateStamp(a5),a0
                        bra .MACRO_UniDate
.MACRO_Origin           jsr .Origin_Rout
                        move.l d0,d4
                        bra .Fillup_Macro
.MACRO_SkipNameHere     tst.l qso_User(a3)
                        beq .MACRO_SkipNameNoDo
                        move.l qso_User(a3),a0
                        tst.b user_Name(a0)
                        beq .MACRO_SkipNameNoDo
.MACRO_SkipNameDo       move.b (A4),d0
                        tst.b d0
                        beq .Main_Loop
                        addq.l #1,a4
                        cmp.b #$d,d0
                        beq .Main_Loop
                        bra .MACRO_SkipNameDo

.MACRO_SkipNameNoDo     bra .Main_Loop
.MACRO_SkipNewsLine     move.l a3,a0
                        jsr QSO_NewsMacroTest
                        tst.l d0
                        beq .MACRO_SkipNewsNoDo
.MACRO_SkipNewsDo       move.b (A4),d0
                        tst.b d0
                        beq .Main_Loop
                        addq.l #1,a4
                        cmp.b #$d,d0
                        beq .Main_Loop
                        bra .MACRO_SkipNewsDo

.MACRO_SkipNewsNoDo     bra .Main_Loop
                                
.MACRO_UniDate          moveq #16,d3
                        sub.l #16,a7
                        move.l a7,a1
                        jsr QSO_StampToDate
                        move.l a7,a2
                        bra .Handle_Macro
.MACRO_UniTime          moveq #16,d3
                        sub.l #16,a7
                        move.l a7,a1
                        jsr QSO_StampToTime
                        move.l a7,a2
                        bra .Handle_Macro
                        
.Handle_Macro           move.l a2,a0
                        moveq #-1,d0
.Handle_Macro_Count     addq.l #1,d0
                        tst.b (a0)+
                        bne .Handle_Macro_Count
                        tst.l d4
                        beq .No_Length_Process
                        cmp.l d4,d0
                        blt .No_Cut_Macro
                        move.l d4,d0
                        bra .No_Length_Process
.No_Cut_Macro           sub.l d0,d4
                        bra .Sendup_Macro
.No_Length_Process      moveq #0,d4
.Sendup_Macro           move.l d7,d1
                        move.l a2,a0
                        jsr .Subsending_Routine
                        add.l d3,a7
.Fillup_Macro           tst.l d4
                        beq .Main_Loop
                        sub.l #16,a7
                        move.l #"    ",(a7)
                        move.l #"    ",4(a7)
                        move.l #"    ",8(a7)
                        move.l #"    ",12(a7)
.Fillup_Loop            moveq #16,d0
                        cmp.l d4,d0
                        ble .Fillup_Full
                        move.l d4,d0
.Fillup_Full            sub.l d0,d4
                        move.l a7,a0
                        move.l d7,d1
                        jsr .Subsending_Routine
                        tst.l d4
                        bne .Fillup_Loop
                        add.l #16,a7
                        bra .Main_Loop

.Macro_Escape           subq.l #4,a7
                        move.b #"%",(A0)+
                        moveq #1,d0
                        move.l d7,d1
                        move.l a4,a0
                        jsr .Subsending_Routine
                        addq.l #4,a7
                        bra .Main_Loop
.Exit                   tst.l d7
                        bne .Exit_NoMon
                        lea _Temporary(a5),a0
                        move.l a0,a1
                        moveq #-1,d0
.Exit_MonitorDump       addq.l #1,d0
                        tst.b (a1)+
                        bne .Exit_MonitorDump
                        moveq #0,d1
                        jsr QSO_SendData
.Exit_NoMon             movem.l (sp)+,d2-d7/a2-a6
                        rts



.Subsending_Routine     tst.l d1
                        beq .Subsending_Monitor
                        movem.l d0/d1/a0,-(sp)
                        jsr QSO_SendData
                        movem.l (sp)+,d0/d1/a0
                        btst #0,d6
                        beq .No_PutoutTerm
                        moveq #2,d2
                        jsr GUI_WriteToQSO
.No_PutoutTerm          rts
.Subsending_Monitor     lea _Temporary(a5),a1
.Subsending_MonitorL    tst.b (a1)+
                        bne .Subsending_MonitorL
                        subq.l #1,a1
.Subsending_MonitorL2   tst.l d0
                        beq .No_PutoutTerm
                        subq.l #1,d0
                        move.b (a0)+,(A1)+
                        clr.b (a1)
                        bra .Subsending_MonitorL2

.Origin_Rout            movem.l d2-d7/a2-a6,-(sp)
                        sub.l #272,a7
                        move.l d7,256(a7)
                        move.l d6,260(a7)
                        tst.l d4
                        bne .NoNilly_Format
                        moveq #-1,d4
.NoNilly_Format         move.l d4,264(a7)
                        
                        move.l _DOSBase(A5),a6
                        moveq #0,d7
                        lea Origin_File,a1
                        move.l a1,d1
                        move.l #1005,d2
                        jsr _LVOOpen(a6)
                        tst.l d0
                        beq .Return_1
                        move.l d0,d6
                        sub.l #12,a7
                        move.l a7,d1
                        jsr _LVODateStamp(a6)
                        move.l (a7),d0
                        move.l 4(a7),d1
                        move.l 8(a7),d2
                        add.l #12,a7
                        eor.l #$bf897ce8,d0
                        eor.l #$19ed0472,d1
                        move.l d2,d3
                        asl.l #8,d3
                        asl.l #8,d3
                        eor.l #$57cf84576,d2
                        eor.l #$d09ea36bd,d3
                        sub.l d0,d3
                        add.l d2,d1
                        eor.l d0,d2
                        swap d3
                        swap d1
                        eor.l d1,d2
                        swap d2
                        sub.l d3,d0
                        eor.l d1,d0
                        add.l d2,d0
                        move.l d0,d5
                        move.l d6,d1
                        moveq #0,d2
                        moveq #1,d3
                        jsr _LVOSeek(a6)
                        cmp.l #-1,d0
                        beq .Return_2
                        move.l d6,d1
                        moveq #0,d2
                        moveq #0,d3
                        jsr _LVOSeek(a6)
                        cmp.l #-1,d0
                        beq .Return_2
                        tst.l d0
                        beq .Return_2
                        move.l d0,d1
                        move.l d5,d0
                        move.l a6,-(sp)
                        move.l _UtilityBase(a5),a6
                        jsr _LVOUDivMod32(a6)
                        move.l (sp)+,a6
                        move.l d1,d2
                        move.l d6,d1
                        moveq #-1,d3
                        jsr _LVOSeek(a6)
                        cmp.l #-1,d0
                        beq .Return_2
                        moveq #1,d4
.New_OriginBuf          move.l d6,d1
                        move.l a7,d2
                        move.l #256,d3
                        jsr _LVORead(A6)
                        cmp.l #-1,d0
                        beq .Return_2
                        tst.l d0
                        beq .First_Origin
                        move.l d0,d5
                        move.l a7,a0
.Search_Start           tst.l d4
                        bne .Search_Init
                        cmp.b #$a,(a0)
                        beq .Search_Found
.Search_Init            moveq #0,d4
                        cmp.b #"|",(a0)
                        bne .Search_Next
                        moveq #1,d4
.Search_Next            addq.l #1,a0
                        subq.l #1,d5
                        tst.l d5
                        beq .New_OriginBuf
                        bra .Search_Start
.First_Origin           move.l d6,d1
                        moveq #-1,d3
                        moveq #0,d2
                        jsr _LVOSeek(a6)
                        cmp.l #-1,d0
                        beq .Return_2
                        move.l d6,d1
                        move.l a7,d2
                        move.l #256,d3
                        jsr _LVORead(A6)
                        cmp.l #-1,d0
                        beq .Return_2
                        tst.l d0
                        beq .Return_2
                        move.l d0,d5
                        move.l a7,a0
                        bra .Search_Head
.Search_Found           addq.l #1,a0
                        subq.l #1,d5
.Search_Head            moveq #0,d4
                        move.l a0,a4
                        
.Origin_Load            tst.l d5
                        beq .New_InBuf
                        subq.l #1,d5
                        move.b (a0)+,d0
                        cmp.b #$7c,d0
                        beq .Origin_Esc
                        cmp.b #$a,d0
                        beq .Origin_Done
                        addq.l #1,d4
                        bra .Origin_Load
.Origin_Esc             jsr .Origin_FlushBuf
                        tst.l d5
                        beq .New_InBuf
                        subq.l #1,d5
                        move.b (a0)+,d0
                        
                        move.b #$d,268(a7)
                        lea 268(a7),a4
                        moveq #1,d4
                        jsr .Origin_FlushBuf
                        move.l a0,a4
                        moveq #0,d4
                        bra .Origin_Load
                
.New_InBuf              jsr .Origin_FlushBuf
                        move.l d6,d1
                        move.l a7,d2
                        move.l #256,d3
                        jsr _LVORead(A6)
                        cmp.l #-1,d0
                        beq .Return_2
                        tst.l d0
                        beq .First_Origin_T
                        move.l d0,d5
                        move.l a7,a0
                        move.l a0,a4
                        bra .Origin_Load
.First_Origin_T         tst.l d4
                        bne .Return_2
                        bra .First_Origin
.Origin_Done            jsr .Origin_FlushBuf
                        move.l d4,d7                            
.Return_2               move.l d6,d1
                        jsr _LVOClose(a6)
.Return_1               move.l 264(a7),d0
                        add.l #272,a7
                        movem.l (sp)+,d2-d7/a2-a6
                        cmp.l #-1,d0
                        bne .NoNilRet
                        moveq #0,d0
.NoNilRet               rts
.Origin_FlushBuf        tst.l d4
                        beq .No_OriginFlush
                        movem.l d0-d1/a0-a1/d6,-(sp)
                        move.l 288(a7),d0
                        cmp.l #-1,d0
                        beq .Origin_FlushNotOver
                        cmp.l 288(a7),d4
                        ble .Origin_FlushNotOver
                        move.l 288(a7),d4
.Origin_FlushNotOver    move.l d4,d0
                        move.l a4,a0
                        move.l 280(a7),d1
                        move.l 284(a7),D6
                        move.l d0,-(Sp)
                        tst.l d0
                        beq .Origin_FlushEm
                        jsr .Subsending_Routine
.Origin_FlushEm         move.l (sp)+,d0
                        move.l 288(a7),d1
                        cmp.l #-1,d1
                        beq .Nilly_Format
                        sub.l d0,d1
                        move.l d1,288(a7)
.Nilly_Format           movem.l (sp)+,d0-d1/a0-a1/d6
                        moveq #0,d4
.No_OriginFlush         rts


_QSO_TransmitMacroFile  exg a4,a5
                        move.l 4(sp),a0
                        move.l 8(sp),d0
                        move.l 12(sp),d1
                        jsr QSO_TransmitMacroFile
                        exg a4,a5
                        rts
                        
QSO_TransmitMacroFile   move.l d2,-(sp)
                        moveq #1,d2
                        jsr QSO_TMF_Subroutine
                        move.l (sp)+,d2
                        rts
QSO_TransmitMacroDirect move.l d2,-(Sp)
                        moveq #0,d2
                        jsr QSO_TMF_Subroutine
                        move.l (sp)+,d2
                        rts
                        

QSO_TMF_Subroutine      movem.l d2-d7/a2-a6,-(sp)
                        move.l a0,a4
                        move.l d0,d7
                        move.l d1,d6
                        move.l d2,d5
                        sub.l #64,a7

                        move.l d7,d0
                        subq.l #1,d0
                        mulu #qso_Size,d0
                        move.l _QSOs(a5),a0
                        add.l d0,a0
                        move.l a0,a3
.TMF_YesMoni

                        tst.l d5
                        beq .Take_DirectPath
                        tst.l qso_StartupMsg(a0)
                        beq .Take_GlobalCall
                        lea qso_MyCall(a0),a0
                        bra .Call_Took
.Take_GlobalCall        move.l qso_HardwareUnit(a0),d0
                        mulu #devi_Size,d0
                        lea _Preferences(a5),a0
                        lea pref_Devices(a0),a0
                        add.l d0,a0
                        lea devi_GlobalMycall(a0),a0

.Call_Took              move.l a7,a1
.Copy_Call_In           move.b (a0)+,(a1)+
                        tst.b -1(a0)
                        bne .Copy_Call_In
                        move.l a7,d1
                        moveq #64,d3
                        move.l a4,d2
                        move.l _DOSBase(a5),a6
                        jsr _LVOAddPart(a6)
                        cmp.l #-1,d0
                        bne .Error
                        move.l a7,d1
                        move.l #1005,d2
                        jsr _LVOOpen(a6)
                        tst.l d0
                        bne .File_IsOpen
                        move.l a7,a0
                        move.b #"G",(a0)+
                        move.b #"L",(a0)+
                        move.b #"O",(a0)+
                        move.b #"B",(a0)+
                        move.b #"A",(a0)+
                        move.b #"L",(a0)+
                        clr.b (a0)+
                        move.l a7,d1
                        moveq #64,d3
                        move.l a4,d2
                        move.l _DOSBase(a5),a6
                        jsr _LVOAddPart(a6)
                        cmp.l #-1,d0
                        bne .Error
                        move.l a7,d1
                        move.l #1005,d2
                        jsr _LVOOpen(a6)
                        tst.l d0
                        beq .Error
.File_IsOpen            move.l d0,d5
                        add.l #64,a7
                        sub.l #128,a7
.Loop                   move.l d5,d1
                        move.l a7,d2
                        move.l #128,d3
                        move.l _DOSBase(a5),a6
                        jsr _LVOFGets(a6)
                        tst.l d0
                        beq .File_End
                        move.l a7,a0
.Search_End             tst.b (a0)+
                        bne .Search_End
                        cmp.b #$a,-2(a0)
                        bne .EndCR_Over
                        move.b #$d,-2(a0)
.EndCR_Over             move.l d7,d0
                        move.l d6,d1
                        moveq #1,d2
                        move.l a7,a0
                        jsr QSO_TransmitText
                        bra .Loop
.File_End               add.l #128,a7
                        move.l d5,d1
                        move.l _DOSBase(a5),a6
                        jsr _LVOClose(a6)
                        moveq #0,d0
.Exit                   movem.l (sp)+,d2-d7/a2-a6
                        rts
.Error                  add.l #64,a7
                        moveq #-1,d0
                        bra .Exit                       

.Take_DirectPath        move.l a4,d1
                        move.l #1005,d2
                        move.l _DOSBase(A5),a6
                        jsr _LVOOpen(a6)
                        tst.l d0
                        bne .File_IsOpen
                        bra .Error
                        

QSO_StampToTime         move.l 4(a0),d0
                        divu #60,d0
                        and.l #$ffff,d0
                        divu #10,d0
                        or.l #$00300030,d0
                        move.b d0,(a1)+
                        swap d0
                        move.b d0,(a1)+
                        move.b #":",(a1)+
                        move.l 4(a0),d0
                        divu #60,d0
                        swap d0
                        and.l #$ffff,d0
                        divu #10,d0
                        or.l #$00300030,d0
                        move.b d0,(a1)+
                        swap d0
                        move.b d0,(a1)+
                        move.b #":",(a1)+
                        move.l 8(a0),d0
                        divu #50,d0
                        and.l #$ffff,d0
                        divu #10,d0
                        or.l #$00300030,d0
                        move.b d0,(a1)+
                        swap d0
                        move.b d0,(a1)+
                        clr.b (a1)+
                        rts                                             
QSO_StampToDate         movem.l a4-a6/d5-d7,-(sp)
                        move.l a1,a4
                        move.l (a0),d0
                        move.l #60*60*24,d1
                        move.l _UtilityBase(a5),a6
                        jsr _LVOUMult32(a6)
                        sub.l #16,a7
                        move.l a7,a0
                        jsr _LVOAmiga2Date(a6)
                        move.l a4,a1
                        moveq #0,d0
                        move.w 6(a7),d0
                        divu #10,d0
                        or.l #$00300030,d0
                        move.b d0,(a1)+
                        swap d0
                        move.b d0,(a1)+
                        move.b #".",(a1)+
                        moveq #0,d0
                        move.w 8(a7),d0
                        divu #10,d0
                        or.l #$00300030,d0
                        move.b d0,(a1)+
                        swap d0
                        move.b d0,(a1)+
                        move.b #".",(a1)+
                        moveq #0,d0
                        move.w 10(a7),d0
                        divu #100,d0
                        swap d0
                        and.l #$ffff,d0
                        divu #10,d0
                        or.l #$00300030,d0
                        move.b d0,(a1)+
                        swap d0
                        move.b d0,(a1)+
                        clr.b (a1)+
                        add.l #16,a7
                        movem.l (sp)+,a4-a6/d5-d7
                        rts                     
QSO_SearchSpecialServer move.l a6,-(sp)
                        move.l a0,a1
                        lea _ServerList(a5),a0
                        move.l _SysBase(a5),a6
                        jsr _LVOFindName(a6)
                        move.l (sp)+,a6
                        rts
QSO_GetUserDir          cmpa.l #0,a0
                        beq .Standard_User
                        tst.l qso_PrivateDir(a0)
                        beq .Standard_User
                        tst.l qso_User(a0)
                        beq .Standard_User
                        move.l qso_User(a0),a0
                        tst.b user_PrivateDir(a0)
                        beq .Standard_User
                        lea user_PrivateDir(a0),a0
                        move.l a0,d0
                        rts
.Standard_User          lea _Preferences(a5),a1
                        lea pref_RemoteDir(a1),a1
                        move.l a1,d0
                        rts
QSO_GetSaveDir          lea _Preferences(a5),a0
                        lea pref_SaveDir(a0),a0
                        move.l a0,d0
                        rts                                             
                        


QSO_MSDateAmiga         exg a4,a5
                        move.l a0,-(sp)
                        move.l d0,-(sp)
                        jsr _UTIL_MsDateAmiga
                        addq.l #8,sp
                        exg a4,a5
                        rts



;>A0 FileName
;>D0 Type               ;-1 = GetFileType   ;AB 7+ BN AM PC

QSO_ChangeFileType      movem.l d2-d7/a2-a6,-(sp)
                        move.l d0,d6
                        sub.l #fib_SIZEOF+8,a7
                        move.l a7,d0
                        addq.l #4,d0
                        and.l #$fffffffc,d0
                        move.l d0,a4
                        move.l a0,a3
                        
                        move.l a0,d1
                        moveq #-2,d2
                        move.l _DOSBase(a5),a6
                        jsr _LVOLock(a6)
                        tst.l d0
                        beq .Exit
                        move.l d0,d7
                        move.l d7,d1
                        move.l a4,d2
                        jsr _LVOExamine(a6)
                        tst.l d0
                        beq .Exit_2
                        move.l d7,d1
                        jsr _LVOUnLock(a6)
                        lea fib_Comment(a4),a0
                        lea 8(a0),a1
                        cmp.b #" ",(a1)
                        bne .No_OldCom
                        cmp.b #"d",1(a1)
                        bne .No_OldCom
                        cmp.b #"e",2(a1)
                        bne .No_OldCom
                        cmp.b #" ",3(a1)
                        bne .No_OldCom
                        cmp.l #-1,d6
                        beq .Get_Type_Good
                        bra .Overwrite_Old
.No_OldCom              move.l #" de ",(a1)
                        move.l #"????",4(a1)
                        move.w #"??",8(a1)
                        clr.b 10(a1)
.Overwrite_Old          cmp.l #-1,d6
                        beq .Get_Type_Bad
                        move.l d6,d0
                        asl.l #4,d0
                        lea Transfer_Mode_Comments,a0
                        add.l d0,a0
                        lea fib_Comment(a4),a1
                        move.l (a0),(a1)
                        move.l 4(a0),4(a1)
                        lea fib_Comment(a4),a0
                        move.l a0,d2
                        move.l a3,d1
                        jsr _LVOSetComment(a6)
                        bra .Exit
                        
                        
.Exit_2                 move.l d7,d1
                        jsr _LVOUnLock(a6)                      
.Exit                   Add.l #fib_SIZEOF+8,a7
                        movem.l (sp)+,d2-d7/a2-a6
                        rts

.Get_Type_Bad           moveq #-1,d0
                        bra .Exit
.Get_Type_Good          lea fib_Comment(a4),a0
                        moveq #0,d0
                        moveq #8,d5
                        move.l (a0)+,d3
                        move.l (a0)+,d4
                        lea Transfer_Mode_Comments,a0                   
.Get_Type_Good_T        move.l (a0)+,d1
                        move.l (a0)+,d2
                        cmp.l d1,d3
                        bne .Get_Type_Next
                        cmp.l d2,d4
                        beq .Get_Type_Found
.Get_Type_Next          dbf d0,.Get_Type_Good_T
                        moveq #-1,d0
                        bra .Exit
.Get_Type_Found         lsr.l #1,d0
                        bra .Exit

QSO_SetFileInfos        movem.l d2-d4/a2-a3,-(sp)
                        moveq #-1,d4
                        move.l a0,a3
                        cmp.l #-1,qso_TransferCRC(a3)
                        beq .No_CRCAvail
                        lea qso_FileName(a3),a0
                        jsr QSO_CRCFile
                        cmp.l #-1,d0
                        beq .Bad_CRC
                        and.l #$ffff,d0
.Bad_CRC                move.l d0,d4
.No_CRCAvail            lea qso_FileName(a3),a1
                        move.l a1,d1
                        lea qso_TransferFileDate(a3),a1
                        move.l (A1),d0
                        or.l 4(a1),d0
                        or.l 8(a1),d0
                        tst.l d0
                        beq .No_FileDate
                        move.l a1,d2
                        move.l a6,-(Sp)
                        move.l _DOSBase(a5),a6
                        jsr _LVOSetFileDate(A6)
                        move.l (sp)+,a6
.No_FileDate            sub.l #64,a7
                        move.l qso_TransferMode(a3),d0
                        subq.l #1,d0
                        asl.l #3,d0
                        lea Transfer_Mode_Comments,a0
                        add.l d0,a0
                        move.l a7,a1
                        moveq #7,d0
.Copy_TransMode         move.b (a0)+,(a1)+
                        dbf d0,.Copy_TransMode
                        move.b #" ",(a1)+
                        move.b #"d",(a1)+
                        move.b #"e",(a1)+
                        move.b #" ",(a1)+
                        lea qso_Call(a3),a0
.Copy_Call              move.b (a0)+,(a1)+
                        tst.b -1(a0)
                        bne .Copy_Call
                        subq.l #1,a1
                        tst.l qso_TransferTotBytes(a3)
                        ble .No_HalfTransfer
                        move.l qso_TransferTotBytes(a3),d0
                        cmp.l qso_TransferBytes(a3),d0
                        ble .No_HalfTransfer
                        move.b #" ",(A1)+
                        move.b #"I",(a1)+
                        move.b #"N",(a1)+
                        move.b #"C",(a1)+
                        move.b #"O",(a1)+
                        move.b #"M",(a1)+
                        move.b #"P",(a1)+
                        move.b #"!",(a1)+
                        move.l #-1,qso_TransferCRC(a3)
                        bra .Transfer_Incomp
.No_HalfTransfer        move.l qso_TransferBytes(a3),qso_TransferTotBytes(a3)
                        cmp.l qso_TransferCRC(a3),d4
                        beq .CRC_IsGoodCom
                        move.b #" ",(a1)+
                        move.b #"B",(a1)+
                        move.b #"A",(a1)+
                        move.b #"D",(a1)+
                        move.b #"C",(a1)+
                        move.b #"R",(a1)+
                        move.b #"C",(a1)+
                        move.b #"!",(a1)+
.CRC_IsGoodCom          move.l qso_TransferCRC(a3),d0
                        swap d0
                        move.w d4,d0
                        move.l d0,qso_TransferCRC(a3)
.Transfer_Incomp        clr.b (a1)
                        move.l a7,d2
                        lea qso_FileName(a3),a0
                        move.l a0,d1
                        move.l a6,-(sp)
                        move.l _DOSBase(a5),a6
                        jsr _LVOSetComment(A6)
                        move.l (sp)+,a6
                        
                        
                        add.l #64,a7
                        movem.l (sp)+,d2-d4/a2-a3
                        rts




                        XREF _QSO_CRCFile

QSO_CRCFile             exg a4,a5
                        move.l a0,-(sp)
                        jsr _QSO_CRCFile
                        addq.l #4,sp
                        exg a4,a5
                        rts

                        XREF _QSO_CRCFileUntil
QSO_CRCFileUntil        exg a4,a5
                        move.l d0,-(sp)
                        move.l a0,-(sp)
                        jsr _QSO_CRCFileUntil
                        addq.l #8,sp
                        exg a4,a5
                        rts


                        XREF _QSO_CRCFileOffset
QSO_CRCFileOffset       exg a4,a5
                        move.l d0,-(sp)
                        move.l a0,-(sp)
                        jsr _QSO_CRCFileOffset
                        addq.l #8,sp
                        exg a4,a5
                        rts


			XDEF _QSO_SearchComServer

_QSO_SearchComServer	exg a4,a5
			move.l 4(sp),a0
			jsr QSO_SearchComServer
			exg a4,a5
			rts

QSO_SearchComServer     movem.l d5-d7/a3/a4,-(sp)
                        moveq #0,d6                     ;Server Fitlänge
                        moveq #0,d7                     ;Server Entry
                        move.l a0,a4
                        lea _ServerList(a5),a3
.Loop                   move.l (A3),a3
                        tst.l (A3)
                        beq .End_List
                        cmp.l #1,serlis_Type(a3)
                        bne .Loop
                        moveq #0,d1
                        moveq #0,d5
                        move.l 10(a3),a0
                        move.l a4,a1
.Compare                move.b (a0)+,d0
                        cmp.b #$1,d0
                        beq .Gaga_Char
                        cmp.b (a1)+,d0
                        bne .Loop
                        addq.l #1,d5
                        tst.b (a1)
                        beq .Compare_End
                        tst.b (a0)
                        bne .Compare
                        bra .Loop
.Compare_End            tst.l d1
                        bne .GoodCompare
                        cmp.b #1,(a0)
                        beq .GoodCompare
                        tst.b (a0)
                        bne .Loop
.GoodCompare            cmp.l d6,d5
                        ble .Loop
                        move.l d5,d6
                        move.l a3,d7
                        
                        
.End_List               move.l d7,d0                    
.Exit                   movem.l (sp)+,d5-d7/a3/a4
                        rts
.Gaga_Char              tst.l d1
                        bne .Loop
                        moveq #1,d1
                        bra .Compare
                        

QSO_ProcessPathName     movem.l d2-d7/a2-a6,-(sp)
                        move.l d0,d7
                        cmp.l #0,a0
                        beq .Access_Denied
                        cmp.l #0,a1
                        beq .Good_Access
                        move.l a1,a4
                        move.l a0,a3
                        cmp.b #":",(a4)
                        bne .No_Gotoroot
                        clr.b (a3)
                        addq.l #1,a4
.No_Gotoroot            tst.b (a4)
                        beq .Good_Access
.MainLoop               move.l a4,a2
.Searchfor_Parse        move.b (a2)+,d0
                        cmp.b #":",d0
                        beq .Access_Denied
                        tst.b d0
                        beq .Parse_End
                        cmp.b #"/",d0
                        beq .Parse_Slash
                        cmp.b #"\",d0
                        beq .Parse_Slash
                        bra .Searchfor_Parse
.Parse_End              move.l a4,a0
                        move.l a2,d0
                        sub.l a4,d0
                        subq.l #1,d0
                        tst.l d0
                        beq .Good_Access
                        subq.l #1,a2
                        move.l a2,a4
.Test_Add_On_Path       cmp.l #2,d0
                        bgt .Add_On_Dir
                        tst.l d0
                        beq .MainLoop
                        cmp.b #".",(a0)
                        bne .Add_On_Dir
                        cmp.l #1,d0
                        beq .Good_Access
                        cmp.b #".",1(A0)
                        beq .Sub_Down_Dir
.Add_On_Dir             move.l a0,-(sp)
                        move.l a0,d2
                        add.l d0,a0
                        moveq #0,d0
                        move.b (a0),d0
                        clr.b (a0)
                        move.w d0,-(sp)
                        move.l d7,d3
                        move.l a3,d1
                        move.l _DOSBase(a5),a6
                        jsr _LVOAddPart(a6)
                        move.w (sp)+,d1
                        move.l (sp)+,a1
                        move.b d1,(a1)
                        cmp.l #-1,d0
                        bne .Too_Long
                        bra .MainLoop
.Parse_Slash            move.l a4,a0
                        move.l a2,d0
                        sub.l a4,d0
                        subq.l #1,d0
                        move.l a2,a4
                        tst.l d0
                        bne .Test_Add_On_Path
                        cmp.b #"\",-1(a2)
                        beq .Empty_Backslash
.Sub_Down_Dir           tst.b (a3)
                        beq .Access_Denied
                        move.l a3,d1
                        move.l _DOSBase(a5),a6
                        jsr _LVOPathPart(a6)
                        tst.l d0
                        beq .Access_Denied
                        cmp.l #-1,d0
                        beq .Access_Denied
                        move.l d0,a0
                        clr.b (a0)
                        bra .MainLoop


.Empty_Backslash        clr.b (a3)
                        bra .MainLoop                   
.Good_Access            moveq #0,d0
.Exit                   movem.l (sp)+,d2-d7/a2-a6
                        rts
.Access_Denied          moveq #1,d0
                        bra .Exit
.Too_Long               moveq #3,d0
                        bra .Exit

QSO_GetFileInfo         movem.l d2-d7/a2-a6,-(sp)
                        moveq #0,d7
                        move.l a0,a3
                        move.l a1,a2
                        sub.l #fib_SIZEOF+8,a7
                        move.l a7,d0
                        and.l #$fffffffc,d0
                        addq.l #4,d0
                        move.l d0,a4
                        move.l qso_FileID(a3),d1
                        move.l a4,d2
                        move.l _DOSBase(a5),a6
                        jsr _LVOExamineFH(a6)
                        cmp.l #-1,d0
                        bne .CannotExamine
                        lea fib_DateStamp(a4),a0
                        lea qso_TransferFileDate(A3),a1
                        move.l (a0),(a1)
                        move.l 4(a0),4(a1)
                        move.l 8(a0),8(a1)
                        move.l fib_Size(a4),qso_TransferTotBytes(a3)
                        moveq #1,d7
.Test_FileID            moveq #7,d6
                        lea fib_Comment(a4),a0
                        lea Transfer_Mode_Comments,a1
                        move.l d7,d0
                        subq.l #1,d0
                        asl.l #3,d0
                        add.l d0,a1
.Test_FileID_2          move.b (a0)+,d2
                        cmp.b (a1)+,d2
                        bne .Test_FileID_3
                        dbf d6,.Test_FileID_2
                        bra .FileID_Found
.Test_FileID_3          addq.l #1,d7
                        cmp.l #10,d7
                        ble .Test_FileID
                        moveq #0,d7
.FileID_Found           add.l #fib_SIZEOF+8,a7
                        move.l a2,a4
                        move.l qso_FileID(a3),d1
                        move.l a4,d2
                        move.l #256,d3
                        move.l _DOSBase(A5),a6
                        jsr _LVONameFromFH(a6)
                        cmp.l #-1,d0
                        bne .CannotExamine_2
                        moveq #0,d0
.Exit                   move.l d7,d1
                        movem.l (sp)+,d2-d7/a2-a6
                        rts
.CannotExamine          add.l #fib_SIZEOF+8,a7
.CannotExamine_2        moveq #5,d0
                        bra .Exit                       

QSO_AmigaDateMs         exg a4,a5
                        move.l a0,-(sp)
                        jsr _UTIL_AmigaDateMs
                        exg a4,a5
                        addq.l #4,sp
                        rts

QSO_Test7PlusName       tst.b (a0)+
                        bne QSO_Test7PlusName
                        subq.l #5,a0
                        cmp.b #".",(a0)
                        bne .No_7Plus
                        cmp.b #"7",1(a0)
                        beq .7Plus_Sing
                        move.b 1(a0),d0
                        jsr .7Plus_Upper
                        cmp.b #"P",d0
                        beq .7Plus_MorePart
                        cmp.b #"E",d0
                        beq .7Plus_ErrorFile
                        cmp.b #"C",d0
                        beq .7Plus_CorrFile
                        bra .No_7Plus
.7Plus_Sing             move.b 2(a0),d0
                        jsr .7Plus_Upper
                        cmp.b #"P",d0
                        bne .No_7Plus
                        move.b 3(a0),d0
                        jsr .7Plus_Upper
                        cmp.b #"L",d0
                        bne .No_7Plus
                        bra .7Plus_True
.7Plus_MorePart         move.b 2(a0),d0
                        jsr .7Plus_Upper
                        cmp.b #$30,d0
                        blt .No_7Plus
                        cmp.b #$46,d0
                        bgt .No_7Plus
                        cmp.b #$41,d0
                        bge .7Plus_MorePart_1
                        cmp.b #$39,d0
                        bgt .No_7Plus
.7Plus_MorePart_1       move.b 3(a0),d0
                        jsr .7Plus_Upper
                        cmp.b #$30,d0
                        blt .No_7Plus
                        cmp.b #$46,d0
                        bgt .No_7Plus
                        cmp.b #$41,d0
                        bge .7Plus_MorePart_2
                        cmp.b #$39,d0
                        bgt .No_7Plus
.7Plus_MorePart_2       bra .7Plus_True
.7Plus_ErrorFile        move.b 2(a0),d0
                        jsr .7Plus_Upper
                        cmp.b #"R",d0
                        bne .7Plus_MorePart
                        move.b 3(a0),d0
                        jsr .7Plus_Upper
                        cmp.b #"R",d0
                        bne .No_7Plus
                        bra .7Plus_True
.7Plus_CorrFile         move.b 2(a0),d0
                        jsr .7Plus_Upper
                        cmp.b #"O",d0
                        bne .7Plus_MorePart
                        move.b 3(a0),d0
                        jsr .7Plus_Upper
                        cmp.b #"R",d0
                        bne .No_7Plus
                        bra .7Plus_True
.No_7Plus               moveq #0,d0
                        rts
.7Plus_True             moveq #-1,d0
                        rts
.7Plus_Upper            cmp.b #$61,d0
                        blt .No_Upper
                        cmp.b #$7a,d0
                        bgt .No_Upper
                        sub.b #$20,d0
.No_Upper               rts                     


QSO_LineParse           movem.l d2-d7/a2-a6,-(sp)
                        moveq #-1,d7
                        move.l d0,d6    ;Linbuffer Length
                        move.l d1,d5    ;Chars to Add Length
                        move.l d2,d4    ;Flag:  Split Line at Prompt
                        move.l a0,a4    ;Linebuffer
                        move.l a1,a3    ;Chars to Add
                        move.l d6,d3    ;Rest Länge Linebuffer
                        move.l a4,a2    ;Zeiger Schreiben Linebuffer
.SLBE                   tst.l d3
                        beq .Main_Loop
                        subq.l #1,d3
                        tst.b (a2)+
                        bne .SLBE
                        subq.l #1,a2
.Main_Loop              tst.l d5
                        beq .Exit
                        tst.l d3
                        beq .Exit_Gaga
                        move.b (a3)+,(a2)+
                        clr.b (a2)
                        subq.l #1,d5
                        subq.l #1,d3
                        cmp.b #$d,-1(a2)
                        beq .Exit_Gaga
                        tst.l d4
                        beq .Main_Loop
                        cmp.b #">",-1(a2)
                        bne .Main_Loop
                        tst.l d5
                        beq .Exit_Gaga
                        bra .Main_Loop
                        
                        
.Exit_Gaga              move.l d5,d7
.Exit                   move.l d7,d0
                        movem.l (sp)+,d2-d7/a2-a6
                        rts

QSO_ParseComLine        movem.l d2-d7/a2-a6,-(sp)
                        moveq #0,d7
                        move.l a0,a4
                        move.l a0,a3
                        cmpa.l #0,a0
                        beq .Exit
.NewArg_Loop            cmp.b #" ",(a3)
                        bne .NewArg_Begin
                        addq.l #1,a3
                        bra .NewArg_Loop
.NewArg_Begin           move.l a3,a2
                        move.l a3,a1
                        tst.b (a2)
                        beq .Exit
                        moveq #0,d6
                        moveq #0,d5
.ParseArg_Loop          tst.b (a2)
                        beq .Argument_End
                        move.b (a2)+,d0
                        cmp.b #$22,d0
                        beq .Argument_Quotes
                        tst.l d6
                        bne .Quote_Mode
                        cmp.b #" ",d0
                        beq .Argument_End
.Quote_Mode             addq.l #1,d5
                        bra .ParseArg_Loop
.Argument_Quotes        eor.l #1,d6
                        tst.l d6
                        bne .ParseArg_QuotOn
                        move.b (a2),d0
                        tst.b d0
                        beq .Argument_End
                        addq.l #1,a2
                        cmp.b #$20,d0
                        beq .Argument_End
                        bra .Argument_Error
.ParseArg_QuotOn        move.l a2,a3
                        move.l a2,a0
                        subq.l #1,a0
                        cmp.l a0,a1
                        bne .Argument_Error
                        bra .ParseArg_Loop
.Argument_End           tst.l d6
                        bne .Argument_Error
                        move.l a3,a0
.Copy_Argument          tst.l d5
                        beq .NewArg_ForLoop
                        move.b (a0)+,(a4)+
                        subq.l #1,d5
                        bra .Copy_Argument
.NewArg_ForLoop         addq.l #1,d7
                        clr.b (A4)+
                        move.l a2,a3
                        bra .NewArg_Loop
.Exit                   move.l d7,d0
                        movem.l (sp)+,d2-d7/a2-a6
                        rts

.Argument_Error         moveq #-1,d7
                        bra .Exit


QSO_ChangeChannel       cmp.l _ActiveChannel(A5),d0
                        bne .No_UpdateQSOBar
                        move.l d0,-(sp)
                        jsr GUI_RefreshConnectHead
                        move.l (sp)+,d0                 
.No_UpdateQSOBar        rts
                                                

QSO_ValidateLocator     tst.b (a0)
                        beq .Locator_Valid
                        moveq #-1,d0
                        move.l a0,a1
.Count_LocLen           addq.l #1,d0
                        tst.b (a1)+
                        bne .Count_LocLen
                        cmp.l #6,d0
                        bne .Locator_Invalid
                        move.l a0,a1
.Upcase_Loc             move.b (a1),d0
                        cmp.b #"a",d0
                        blt .No_Upcase
                        cmp.b #"z",d0
                        bgt .No_Upcase
                        sub.b #$20,d0
.No_Upcase              move.b d0,(a1)+
                        tst.b d0
                        bne .Upcase_Loc
                        move.b (a0),d0
                        cmp.b #"A",d0
                        blt .Locator_Invalid
                        cmp.b #"R",d0
                        bgt .Locator_Invalid
                        move.b 1(a0),d0
                        cmp.b #"A",d0
                        blt .Locator_Invalid
                        cmp.b #"R",d0
                        bgt .Locator_Invalid
                        move.b 2(A0),d0
                        cmp.b #"0",d0
                        blt .Locator_Invalid
                        cmp.b #"9",d0
                        bgt .Locator_Invalid
                        move.b 3(a0),d0
                        cmp.b #"0",d0
                        blt .Locator_Invalid
                        cmp.b #"9",d0
                        bgt .Locator_Invalid
                        move.b 4(a0),d0
                        cmp.b #"A",d0
                        blt .Locator_Invalid
                        cmp.b #"X",d0
                        bgt .Locator_Invalid
                        move.b 5(a0),d0
                        cmp.b #"A",d0
                        blt .Locator_Invalid
                        cmp.b #"X",d0
                        bgt .Locator_Invalid
.Locator_Valid          moveq #0,d0
                        rts
                        
                        
                        
.Locator_Invalid        moveq #-1,d0
                        rts
                        

;A0 Locator
;A1 Ausgabestring oder 0 für numerisches Format
 
;Numerisches Format:
;
;D0: W.......MMMMMMMM°°°°°°°°°°°°°°°°
;D1: S.......MMMMMMMM°°°°°°°°°°°°°°°°
;
; W/S : Flags für westliche Länge und südliche Breite
; .   : Dezimalstellen * 100 der Minuten
; M   : Gradminuten
; °   : Längen/Breitengrade

QSO_LocatorToClear      movem.l d2-d7/a2-a4,-(sp)
                        move.l a0,a4
                        move.l a1,a3
                        move.l a3,a2
                        jsr QSO_ValidateLocator
                        tst.l d0
                        bne .LocInv
                        
                        moveq #0,d7                     ;Flag W/S
                        moveq #0,d0
                        move.b (a4),d0
                        sub.b #$41,d0
                        mulu #20,d0
                        sub.l #180,d0
                        tst.l d0
                        bge .Locator_On_East
                        bset #0,d7
                        neg.l d0
.Locator_On_East        move.l d0,d3                    ;Degrees E/W
                        moveq #0,d0
                        move.b 2(a4),d0
                        sub.b #$30,d0
                        asl.l #1,d0
                        btst #0,d7
                        bne .Handle_W
                        add.l d0,d3
                        bra .Handle_E
.Handle_W               sub.l d0,d3
.Handle_E               moveq #0,d0
                        move.b 4(a4),d0
                        sub.b #$41,d0
                        move.l d0,d1
                        asl.l #2,d0
                        add.l d1,d0
                        cmp.l #60,d0
                        blt .Locator_No_Carry_E
                        sub.l #60,d0
                        btst #0,d7
                        bne .Handle_W_2
                        addq.l #1,d3
                        bra .Locator_No_Carry_E
.Handle_W_2             subq.l #1,d3
.Locator_No_Carry_E     mulu #100,d0
                        move.l d0,d4                    ;Minutes E/W * 100
                        moveq #0,d0
                        move.b 1(a4),d0
                        sub.b #$41,d0
                        mulu #10,d0
                        sub.l #90,d0
                        tst.l d0
                        bge .Locator_On_North
                        bset #1,d7
                        neg.l d0
.Locator_On_North       move.l d0,d5                    ;Degrees N/S
                        moveq #0,d0
                        move.b 3(a4),d0
                        sub.b #$30,d0
                        btst #1,d7
                        bne .Handle_S
                        add.l d0,d5
                        bra .Handle_N
.Handle_S               sub.l d0,d5
.Handle_N               moveq #0,d0
                        move.b 5(a4),d0
                        sub.b #$41,d0
                        move.l d0,d1
                        asl.l #2,d0
                        add.l d1,d0
                        moveq #0,d1
                        btst #0,d0
                        beq .Locator_No_Carry_N
                        moveq #50,d1
.Locator_No_Carry_N     lsr.l #1,d0
                        mulu #100,d0
                        move.l d0,d6                    ;Minutes S/W * 100
                        add.l d1,d6
                        add.l #250,d4
                        add.l #125,d6
                        btst #0,d7
                        beq .Corrig_NoW
                        move.l #6000,d0
                        sub.l d4,d0
                        move.l d0,d4
                        subq.l #1,d3
.Corrig_NoW             btst #1,d7
                        beq .Corrig_NoS
                        move.l #6000,d0
                        sub.l d6,d0
                        move.l d0,d6
                        subq.l #1,d5
.Corrig_NoS             cmpa.l #0,a3
                        beq .Output_Numeric
                        move.l d3,d0
                        jsr .Output_Degrees
                        move.b #" ",(A3)+
                        move.l d4,d0
                        jsr .Output_Minutes_Total
                        move.b #" ",(A3)+
                        btst #0,d7
                        beq .Output_East
                        move.b #"W",(A3)+
                        bra .Output_West
.Output_East            move.b #"E",(A3)+
.Output_West            move.b #" ",(a3)+
                        move.b #"/",(a3)+
                        move.b #" ",(A3)+
                        move.l d5,d0
                        jsr .Output_Degrees
                        move.b #" ",(a3)+
                        move.l d6,d0
                        jsr .Output_Minutes_Total
                        move.b #" ",(A3)+
                        btst #1,d7
                        beq .Output_North
                        move.b #"S",(A3)+
                        bra .Output_South
.Output_North           move.b #"N",(A3)+
.Output_South           clr.b (a3)+
                        moveq #0,d0
                        movem.l (sp)+,d2-d7/a2-a4
                        rts
                        
                        
                        
.Output_Degrees         moveq #0,d1
                        divu #100,d0
                        tst.w d0
                        beq .Output_Degrees_Deka
                        moveq #1,d1
                        or.b #$30,d0
                        move.b d0,(a3)+
.Output_Degrees_Deka    swap d0
                        ext.l d0
                        divu #10,d0
                        move.l d1,d2
                        or.w d0,d2
                        tst.w d2
                        beq .Output_Degrees_Sing
                        or.b #$30,d0
                        move.b d0,(A3)+
.Output_Degrees_Sing    swap d0
                        or.b #$30,d0
                        move.b d0,(a3)+
                        move.b #"°",(a3)+
                        rts
.Output_Minutes         divu #10,d0
                        or.b #$30,d0
                        move.b d0,(A3)+
                        swap d0
                        or.b #$30,d0
                        move.b d0,(A3)+
                        rts
.Output_Minutes_Dec     tst.l d0
                        beq .Output_Minutes_DecNot
                        move.b #".",(a3)+
                        divu #10,d0
                        or.b #$30,d0
                        move.b d0,(A3)+
                        swap d0
                        tst.w d0
                        beq .Output_Minutes_DecNot
                        or.b #$30,d0
                        move.b d0,(A3)+
.Output_Minutes_DecNot  rts
.Output_Minutes_Total   divu #100,d0
                        swap d0
                        moveq #0,d1
                        move.w d0,d1
                        move.l d1,-(sp)
                        swap d0
                        ext.l d0
                        jsr .Output_Minutes
                        move.l (sp)+,d0
                        jsr .Output_Minutes_Dec
                        move.b #"'",(a3)+
                        rts
                        
.Output_Numeric         moveq #0,d0
                        moveq #0,d1
                        move.l d4,d2
                        divu #100,d2
                        move.b d2,d0
                        swap d2
                        asl.l #8,d2
                        or.w d2,d0
                        swap d0
                        add.l d3,d0
                        btst #0,d7
                        beq .ON_EastDeg
                        bset #31,d0
.ON_EastDeg             move.l d6,d2
                        divu #100,d2
                        move.b d2,d1
                        swap d2
                        asl.l #8,d2
                        or.w d2,d1
                        swap d1
                        add.l d5,d1
                        btst #1,d7
                        beq .ON_SouthDeg
                        bset #31,d1
.ON_SouthDeg            movem.l (sp)+,d2-d7/a2-a4
                        rts
                        

.LocInv                 cmpa.l #0,a3
                        beq .LocInvNum
                        move.b #"?",(a3)+
                        move.b #"?",(a3)+
                        move.b #"?",(a3)+
                        clr.b (a3)+
                        moveq #-1,d0
                        movem.l (sp)+,d2-d7/a2-a4
                        rts
.LocInvNum              moveq #-1,d0
                        moveq #-1,d1
                        movem.l (sp)+,d2-d7/a2-a4
                        rts
                        
                        XREF _QSO_TestForwardConnect

QSO_TestForwardConnect  exg a4,a5
                        move.l a0,-(sp)
                        move.l d0,-(sp)
                        jsr _QSO_TestForwardConnect
                        addq.l #8,sp
                        exg a4,a5
                        rts

QSO_HuffmanCompress     exg a4,a5
                        move.l d0,-(sp)
                        move.l a1,-(sp)
                        move.l a0,-(sp)
                        jsr _QSO_HuffmanCompress
                        add.l #12,sp
                        exg a4,a5
                        rts

QSO_HuffmanCompressXP   exg a4,a5
                        move.l d1,-(sp)
                        move.l d0,-(sp)
                        move.l a2,-(sp)
                        move.l a1,-(sp)
                        move.l a0,-(sp)
                        jsr _QSO_HuffmanCompressXP
                        add.l #20,sp
                        exg a4,a5
                        rts

QSO_HuffmanDecompress   exg a4,a5
                        move.l d0,-(sp)
                        move.l a1,-(sp)
                        move.l a0,-(sp)
                        jsr _QSO_HuffmanDecompress
                        add.l #12,sp
                        exg a4,a5
                        rts

QSO_HuffmanDecompressXP

                        exg a4,a5
                        move.l d0,-(Sp)
                        move.l a2,-(sp)
                        move.l a1,-(sp)
                        move.l a0,-(sp)
                        jsr _QSO_HuffmanDecompressXP
                        add.l #16,sp
                        exg a4,a5
                        rts


QSO_DecompressXPStream  exg a4,a5
                        move.l d0,-(sp)
                        move.l d1,-(sp)
                        move.l a3,-(sp)
                        move.l a2,-(sp)
                        move.l a1,-(sp)
                        move.l a0,-(sp)
                        jsr _QSO_DecompressXPStream
                        add.l #24,sp
                        exg a4,a5
                        rts

_QSO_CompressionOn      exg a4,a5
                        move.l 4(sp),d0
                        jsr QSO_CompressionOn
                        exg a4,a5
                        rts

_QSO_CompressionOff     exg a4,a5
                        move.l 4(sp),d0
                        jsr QSO_CompressionOff
                        exg a4,a5
                        rts


QSO_CompressionOn       move.l d0,-(sp)
                        jsr QSO_GetPacLen
                        move.l (sp)+,d1
                        cmp.l #256,d0
                        bge .Invalid_PacLen
                        tst.l _HuffmanSpeedup(A5)
                        beq .Invalid_Huffman
                        move.l d1,d0
                        tst.l d0
                        ble .Invalid_Huffman
                        subq.l #1,d0
                        mulu #qso_Size,d0
                        move.l _QSOs(A5),a0
                        add.l d0,a0
                        bset #0,qso_CompressedMode+3(a0)
                        bset #1,qso_CompressedMode+3(a0)
                        jsr GUI_RefreshConnectHead
                        moveq #0,d0
                        rts
                        
.Invalid_Huffman        moveq #-2,d0
                        rts
.Invalid_PacLen         moveq #-1,d0
                        rts
                        
QSO_CompressionOff      tst.l d0
                        ble .Exit_E
                        subq.l #1,d0
                        mulu #qso_Size,d0
                        move.l _QSOs(a5),a0
                        add.l d0,a0
                        bclr #0,qso_CompressedMode+3(a0)
                        bclr #1,qso_CompressedMode+3(a0)
                        jsr GUI_RefreshConnectHead
.Exit                   moveq #0,d0
                        rts
.Exit_E                 moveq #1,d0
                        rts

                        XREF _QSO_HandleXPLine
QSO_HandleXPLine        exg a4,a5
                        move.l a0,-(sp)
                        move.l d0,-(sp)
                        jsr _QSO_HandleXPLine
                        addq.l #8,sp
                        exg a4,a5
                        rts

;>D0 Channel
;>D1 Mode (0=On 1=Off 2=OnAck(OnRcvd) 3=OffAck(OffRcvd) 4=OnAckRecvd 5=OffAckRecvd 6=ResyncMe 7=ResyncOther / + 128 for special compress)
QSO_ControlXPCompress
                        exg a4,a5
                        move.l d1,-(sp)
                        move.l d0,-(sp)
                        jsr _QSO_ControlXPCompress
                        addq.l #8,sp
                        exg a4,a5
                        rts

_QSO_EncryptionOn       move.l 4(sp),d0
                        move.l 8(sp),d1
                        exg a4,a5
                        jsr QSO_EncryptionOn
                        exg a4,a5
                        rts
_QSO_EncryptionOff      move.l 4(sp),d0
                        move.l 8(sp),d1
                        exg a4,a5
                        jsr QSO_EncryptionOff
                        exg a4,a5
                        rts


QSO_EncryptionOn        move.l d7,-(sp)
                        move.l d1,d7
                        tst.l d0
                        ble .Exit
                        move.l d0,-(sp)
                        jsr QSO_GetPacLen
                        move.l d0,d1
                        move.l (sp)+,d0
                        cmp.l #248,d1
                        bgt .Error
                        subq.l #1,d0
                        mulu #qso_Size,d0
                        move.l _QSOs(a5),a0
                        add.l d0,a0
                        move.l qso_User(a0),a1
                        cmpa.l #0,a1
                        beq .Error
                        lea user_CipherKey(a1),a1
                        move.l (a1),d0
                        or.l 4(a1),d0
                        or.l 8(a1),d0
                        or.l 12(a1),d0
                        tst.l d0
                        beq .Error
                        move.l a0,-(sp)
                        jsr QSO_XPKOpenLibrary
                        move.l (sp)+,a0
                        tst.l d0
                        beq .Error
                        cmp.l #3,d7
                        beq .ForceRx
                        cmp.l #2,d7
                        beq .ForceTx

                        bset #2,qso_CompressedMode+3(a0)
                        lea qso_CipherInputBuffer(a0),a1
                        clr.l (a1)
                        lea qso_CipherOutputBuffer(a0),a1
                        clr.l (a1)
.Xenoned                jsr GUI_RefreshConnectHead
.Exit                   moveq #0,d0
                        move.l (sp)+,d7
                        rts
.ForceTx                bset #2,qso_CompressedMode+3(a0)
                        lea qso_CipherOutputBuffer(a0),a1
                        clr.l (a1)
                        bra .Xenoned
.ForceRx                bset #3,qso_CompressedMode+3(a0)
                        lea qso_CipherInputBuffer(a0),a1
                        clr.l (a1)
                        bra .Xenoned
                        jsr GUI_RefreshConnectHead
.Error                  moveq #-1,d0
                        move.l (sp)+,d7
                        rts
QSO_EncryptionOff       tst.l d0
                        ble .Exit
                        subq.l #1,d0
                        mulu #qso_Size,d0
                        move.l _QSOs(a5),a0
                        add.l d0,a0
                        bclr #2,qso_CompressedMode+3(a0)
                        bclr #3,qso_CompressedMode+3(a0)
                        move.l #-1,qso_XPKType(a0)
                        move.l #-1,qso_XPKEfficiency(a0)
                        move.l #-1,qso_XPKSublibrary(a0)
                        tst.l qso_XPKLibrary(a0)
                        beq .No_Lib
                        move.l qso_XPKLibrary(a0),a1
                        clr.l qso_XPKLibrary(a0)
                        move.l a6,-(sp)
                        move.l _SysBase(a5),a6
                        jsr _LVOCloseLibrary(a6)
                        move.l (sp)+,a6
.No_Lib                 jsr GUI_RefreshConnectHead
.Exit                   moveq #0,d0
                        rts


QSO_SendPassword        movem.l d2-d7/a2-a6,-(sp)
                        move.l a0,a3
                        move.l d0,d7
                        subq.l #1,d0
                        mulu #qso_Size,d0
                        move.l _QSOs(a5),a0
                        add.l d0,a0
                        move.l a0,a4
                        moveq #-1,d0
                        tst.l qso_Server(a4)
                        beq .Exit
                        move.l qso_User(a4),a0
                        cmpa.l #0,a0
                        beq .Exit
                        move.l a0,a2
                        tst.b user_RPType(a2)
                        beq .Exit
                        tst.b user_RPassword(a2)
                        beq .Exit
                        moveq #0,d0
                        move.b user_RPType(A2),d0
                        cmp.l #1,d0
                        beq .Simple_Pass
                        cmp.l #2,qso_PasswordRemote(a4)
                        beq .Exit
                        tst.l qso_PasswordRemote(a4)
                        bne .Complex_Pass
                        cmpa.l #0,a3
                        bne .Test_For_Box
                        cmp.w #4,d0
                        beq .Send_PW
                        cmp.w #5,d0
                        beq .Send_PW
                        move.l d7,d0
                        moveq #1,d1
                        moveq #0,d2
                        lea .SYS_String(pc),a0
                        jsr QSO_TransmitText
                        move.l #1,qso_PasswordRemote(a4)
.Exit                   movem.l (Sp)+,d2-d7/a2-a6
                        rts

.Test_For_Box           move.l qso_User(a4),a0
                        cmp.l #0,a0
                        beq .Exit
                        move.w user_Type(a0),d0
                        cmp.w #4,d0
                        blt .Exit
                        bra .Complex_Pass

.Send_PW                move.l d7,d0
                        moveq #1,d1
                        moveq #0,d2
                        lea .PW_String(pc),a0
                        jsr QSO_TransmitText
                        move.l #1,qso_PasswordRemote(a4)
                        bra .Exit
.Simple_Pass            move.l d7,d0
                        moveq #1,d1
                        moveq #0,d2
                        lea user_RPassword(a2),a0
                        jsr QSO_TransmitText
                        moveq #0,d0
                        bra .Exit
.Complex_Pass           moveq #0,d6
                        move.b user_RPType(a2),d6
                        moveq #-1,d0
                        cmpa.l #0,a3
                        beq .Exit
                        move.l a3,d5
                        sub.l #80,a7
                        move.l a7,a3

                        move.l qso_User(a4),a0
                        cmpa.l #0,a0
                        beq .No_BoxOnce
                        move.w user_Type(a0),d0
                        cmp.w #4,d0
                        blt .No_BoxOnce
                        move.l #2,qso_PasswordRemote(a4)
                        bra .Box_Once
.No_BoxOnce             clr.l qso_PasswordRemote(a4)
.Box_Once               lea .PW_Table(pc),a0
                        move.l d6,d0
                        tst.l d0
                        blt .Exit_2_R
                        cmp.l #8,d0
                        bge .Exit_2_R
                        asl.l #2,d0
                        add.l d0,a0
                        move.l (a0),a0
                        move.l a4,-(sp)
                        move.l d5,a4
                        jsr (a0)
                        move.l (sp)+,a4
                        tst.l d0
                        bne .Exit_2_R
                        move.b #$d,(a3)+
                        clr.b (a3)+
                        move.l d7,d0
                        moveq #1,d1
                        moveq #0,d2
                        move.l a7,a0
                        jsr QSO_TransmitText
                        
.Exit_2                 add.l #80,a7
                        moveq #0,d0
                        bra .Exit
.Exit_2_R               add.l #80,a7
                        moveq #-1,d0
                        bra .Exit

.Nop                    moveq #-1,d0
                        rts
.Password_Error         moveq #-1,d0
                        rts
.Simple_Password        moveq #-1,d0
                        rts
.Password_500           moveq #-1,d3
                        lea user_RPassword(a2),a0
.Password_500_L0        addq.l #1,d3
                        tst.b (a0)+
                        bne .Password_500_L0
                        moveq #4,d4
.Password_500_L         move.l (a4)+,d0
                        subq.l #1,d0
                        cmp.l d3,d0
                        bge .Password_Error
                        lea user_RPassword(a2),a0
                        add.l d0,a0
                        move.b (a0)+,(a3)+
                        dbf d4,.Password_500_L
                        moveq #0,d0
                        rts

.Password_5RR           jsr .Password_GetHash
                        jsr .Password_GetRandom
                        and.l #$7,d0
                        add.l #11,d0
                        jsr .Password_AddXRand
                        jsr .Password_500
                        tst.l d0
                        bne .Password_Error
                        jsr .Password_GetRandom
                        and.l #$7,d0
                        add.l #12,d0
                        jsr .Password_AddXRand
                        moveq #0,d0
                        rts
.Password_GetHash       lea _CurrentDateStamp(a5),a0
                        move.l (a0),d0
                        ror.l #8,d0
                        ror.l #8,d0
                        eor.l #$12345678,d0
                        move.l 4(a0),d1
                        rol.l #8,d1
                        eor.l #$4e746d1e,d1
                        eor.l d1,d0
                        move.l 8(a0),d1
                        ror.l #8,d1
                        eor.l #$8e730351,d1
                        eor.l d1,d0
                        move.l d0,-(sp)
                        lea _CurrentDateStamp(a5),a0
                        move.l 4(a0),d0
                        ror.l #8,d0
                        ror.l #4,d0
                        eor.l #$eb186eda,d0
                        move.l 8(a0),d1
                        rol.l #7,d1
                        eor.l #$ce710e51,d1
                        eor.l d1,d0
                        move.l (a0),d1
                        ror.l #5,d1
                        eor.l #$b9c4184e,d1
                        eor.l d1,d0
                        move.l (sp)+,d1
                        eor.l d1,d0
                        move.l d0,d2
                        rts
.Password_GetRandom     move.l d2,d0
                        ror.l #8,d0
                        ror.l #4,d0
                        ror.w #7,d0
                        rol.b #3,d0
                        move.l d2,d1
                        eor.l d0,d2
                        swap d1
                        ror.l #8,d1
                        ror.l #4,d1
                        ror.w #7,d1
                        rol.b #3,d1
                        eor.l d1,d2
                        swap d2
                        eor.l #$37ec76a8,d2
                        add.l #$1e81a479,d2
                        ror.l #4,d1
                        rol.l #4,d0
                        eor.b d1,d0
                        and.l #$ff,d0
                        rts
                        
.Password_AddXRand      move.l d0,d3
.Password_AddXRand_L    jsr .Password_GetRandom
                        and.l #$3f,d0
                        jsr .Password_Add1Rand
                        subq.l #1,d3
                        bne .Password_AddXRand_L
                        rts
                        

.Password_Add1Rand      lea .Random_String(pc),a0
                        add.l d0,a0
                        move.b (a0),d0
                        move.b d0,(a3)+
                        rts
                        
.SYS_String             dc.b "SYS",$0d,0
.PW_String              dc.b "PW",$0d,0
.Random_String          dc.b "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ab"
                        even

                        
.PW_Table               dc.l .Nop
                        dc.l .Simple_Password
                        dc.l .Password_500
                        dc.l .Password_5RR
                        dc.l .Password_500
                        dc.l .Password_5RR
                        dc.l .Nop
                        dc.l .Nop

_QSO_TestPasswordString exg a4,a5
                        move.l 4(sp),d0
                        move.l 8(sp),a0
                        jsr QSO_TestPasswordString
                        exg a4,a5
                        rts

QSO_TestPasswordString  movem.l d2-d7/a2-a6,-(sp)
                        move.l d0,d7
                        move.l a0,a4
.Search_GreaterThan     tst.b (a4)
                        beq .Exit
                        cmp.b #">",(A4)+
                        bne .Search_GreaterThan
                        cmp.b #" ",(A4)+
                        bne .Exit
                        cmp.b #"0",(a4)
                        blt .No_Digit_0
                        cmp.b #"9",(a4)
                        ble .Digit_Found
.No_Digit_0             cmp.b #" ",(a4)+
                        bne .Exit
.Digit_Found            sub.l #5*4,a7
                        moveq #0,d0
                        move.l a7,a3
.Read_Digit             cmp.b #"0",(a4)
                        blt .Exit_2
                        cmp.b #"9",(A4)
                        bgt .Exit_2
                        moveq #0,d1
                        move.b (a4)+,d1
                        and.l #$f,d1
                        tst.b (A4)
                        beq .Digit_Ended
                        cmp.b #" ",(A4)
                        beq .Digit_Next
                        cmp.b #"0",(a4)
                        blt .Exit_2
                        cmp.b #"9",(A4)
                        bgt .Exit_2
                        mulu #10,d1
                        add.b (A4)+,d1
                        sub.b #$30,d1
                        cmp.l #80,d1
                        bgt .Exit_2
                        cmp.b #" ",(a4)
                        beq .Digit_Next
                        tst.b (a4)
                        beq .Digit_Ended
                        bra .Exit_2
.Digit_Next             move.l d1,(a3)+
                        addq.l #1,d0
                        addq.l #1,a4
                        cmp.l #5,d0
                        blt .Read_Digit
                        bra .Digit_Ended
.Digit_Ended            move.l d1,(a3)+
                        move.l a7,a0
                        move.l d7,d0
                        jsr QSO_SendPassword
.Exit_2                 add.l #5*4,a7
.Exit                   movem.l (sp)+,d2-d7/a2-a6
                        rts

                        

QSO_GetChannelQSO       move.l _MaxChannel(a5),d1
                        tst.l d0
                        ble .Error
                        cmp.l d1,d0
                        bgt .Error
                        subq.l #1,d0
                        mulu #qso_Size,d0
                        move.l _QSOs(a5),a0
                        add.l d0,a0
                        move.l a0,d0
                        rts
.Error                  moveq #0,d0
                        rts


QSO_NewsCommand         movem.l d2-d7/a2-a6,-(sp)
                        move.l d0,d7
                        jsr QSO_GetChannelQSO
                        move.l d0,a4
                        cmpa.l #0,a4
                        beq .Error
                        lea News_File,a0
                        move.l a0,d1
                        moveq #-2,d2
                        move.l _DOSBase(a5),a6
                        jsr _LVOLock(a6)
                        tst.l d0
                        beq .Error
                        sub.l #fib_SIZEOF+8,a7
                        move.l d0,d6
                        move.l a7,d0
                        and.l #$fffffffc,d0
                        addq.l #4,d0
                        move.l d0,a3
                        
                        move.l a3,d2
                        move.l d6,d1
                        move.l _DOSBase(a5),a6
                        jsr _LVOExamine(a6)
                        cmp.l #-1,d0
                        bne .Error_2
                        lea fib_DateStamp(a3),a0
                        move.l d6,d1
                        move.l (a0),d4
                        move.l 4(a0),d5
                        move.l 8(a0),d6
                        move.l _DOSBase(a5),a6
                        jsr _LVOUnLock(a6)
                        add.l #fib_SIZEOF+8,a7
                        move.l qso_User(a4),a3
                        lea News_File,a0
                        move.l d7,d0
                        moveq #1,d1
                        jsr QSO_TransmitMacroDirect
                        tst.l d0
                        bne .Error
                        cmpa.l #0,a3
                        beq .Good_News
                        lea user_LastNews(a3),a0
                        move.l d4,(a0)
                        move.l d5,4(a0)
                        move.l d6,8(a0)
                        move.l a3,a0
                        jsr QSO_ChangeUser
.Good_News              moveq #0,d0
                        movem.l (sp)+,d2-d7/a2-a6
                        rts
                        
.Error_2                move.l d6,d1
                        move.l _DOSBase(a5),a6
                        jsr _LVOUnLock(A6)
                        add.l #fib_SIZEOF+8,a7
.Error                  movem.l (sp)+,d2-d7/a2-a6
                        moveq #-1,d0
                        rts                     


QSO_NewsMacroTest       movem.l d2-d7/a2-a6,-(sp)
                        move.l a0,a4
                        
                        lea News_File,a0
                        move.l a0,d1
                        moveq #-2,d2
                        move.l _DOSBase(a5),a6
                        jsr _LVOLock(a6)
                        tst.l d0
                        beq .Error
                        sub.l #fib_SIZEOF+8,a7
                        move.l d0,d6
                        move.l a7,d0
                        and.l #$fffffffc,d0
                        addq.l #4,d0
                        move.l d0,a3
                        
                        move.l a3,d2
                        move.l d6,d1
                        move.l _DOSBase(a5),a6
                        jsr _LVOExamine(a6)
                        cmp.l #-1,d0
                        bne .Error_2
                        lea fib_DateStamp(a3),a0
                        move.l d6,d1
                        move.l (a0),d4
                        move.l 4(a0),d5
                        move.l 8(a0),d6
                        move.l _DOSBase(a5),a6
                        jsr _LVOUnLock(a6)
                        add.l #fib_SIZEOF+8,a7
                        
                        
                        move.l qso_User(a4),a0
                        cmpa.l #0,a0
                        beq .Error
                        lea user_LastNews(a0),a0
                        cmp.l (a0),d4
                        bne .New_News
                        cmp.l 4(a0),d5
                        bne .New_News
                        cmp.l 8(a0),d6
                        bne .New_News
                        bra .Error
.New_News               movem.l (sp)+,d2-d7/a2-a6
                        moveq #0,d0
                        rts

.Error_2                move.l d7,d1
                        move.l _DOSBase(a5),a6
                        jsr _LVOUnLock(a6)
                        add.l #fib_SIZEOF+8,a7
.Error                  movem.l (sp)+,d2-d7/a2-a6
                        moveq #-1,d0
                        rts

                        XREF _QSO_UpdateTickerLine
QSO_UpdateTickerLine    move.l a0,-(sp)
                        exg a4,a5
                        jsr _QSO_UpdateTickerLine
                        exg a4,a5
                        move.l (Sp)+,a0
                        rts

QSO_FreeHoldArray       exg a4,a5
                        jsr _QSO_FreeHoldArray
                        exg a4,a5
                        rts

QSO_MHeardLine          exg a4,a5
                        move.l a0,-(sp)
                        move.l d0,-(sp)
                        XREF _QSO_MHeardLine
                        jsr _QSO_MHeardLine
                        add.l #8,sp
                        exg a4,a5
                        rts

QSO_MHeardLineLong
                        exg a4,a5
                        move.l a0,-(sp)
                        move.l d0,-(sp)
                        XREF _QSO_MHeardLineLong
                        jsr _QSO_MHeardLineLong
                        addq.l #8,sp
                        exg a4,a5
                        rts

                        
QSO_AskPassword         movem.l d2-d7/a2-a6,-(sp)
                        move.l d0,d7
                        move.l d1,d6
                        move.l a0,a4
                        jsr QSO_GetChannelQSO
                        tst.l d0
                        beq .Exit
                        move.l d0,a3
                        move.l d6,d0
                        asl.l #2,d0
                        lea .Jump_Table,a0
                        add.l d0,a0
                        move.l (a0),a0
                        jmp (a0)
.Ask_Simple             move.l qso_User(a3),a2
                        cmpa.l #0,a2
                        beq .Exit
                        bra .Simple_Password

.Normal_Mode            move.l qso_User(a3),a0
                        cmpa.l #0,a0
                        beq .Exit
                        tst.b user_LPType(a0)
                        beq .Exit
                        tst.b user_LPassword(a0)
                        beq .Exit
                        move.b user_LPType(a0),d0
                        move.l a0,a2
                        cmp.b #1,d0
                        beq .Simple_Password
                        moveq #3,d6
                        cmp.b #2,d0
                        beq .Exit
                        cmp.b #3,d0
                        beq .Exit
                        moveq #2,d6
                        cmp.b #4,d0
                        beq .Exit
                        cmp.b #5,d0
                        beq .Exit
                        cmp.l #6,d0
                        beq .Password_Poll
                        cmp.l #7,d0
                        beq .Password_Poll

                        moveq #0,d6
                        bra .Exit
.Simple_Password        cmpa.l #0,a4
                        beq .No_Simple
                        tst.b (a4)
                        beq .No_Simple
                        lea user_LPassword(a2),a0
.Simple_Password_Comp   move.b (A4)+,d0
                        cmp.b (a0)+,d0
                        bne .Password_Violation
                        tst.b d0
                        bne .Simple_Password_Comp
                        
                        
                        
.Password_Correct       moveq #1,d6
                        bra .Exit

.No_Simple              moveq #6,d6
                        bra .Exit


.Ask_PW                 move.l qso_User(a3),a0
                        cmpa.l #0,a0
                        beq .Exit
                        move.l a0,a2
                        cmp.b #"p",(a4)
                        beq .Ask_PW_1
                        cmp.b #"P",(a4)
                        bne .Exit
.Ask_PW_1               cmp.b #"w",1(a4)
                        beq .Ask_PW_2
                        cmp.b #"W",1(a4)
                        bne .Exit
.Ask_PW_2               tst.b 2(a4)
                        bne .Exit
                        bra .Password_Poll
                        
                        bra .Exit
.Ask_SYS                move.l qso_User(a3),a0
                        cmpa.l #0,a0
                        beq .Exit
                        move.l a0,a2
                        cmp.b #"s",(a4)
                        beq .Ask_SYS_1
                        cmp.b #"S",(a4)
                        bne .Exit
.Ask_SYS_1              cmp.b #"y",1(a4)
                        beq .Ask_SYS_2
                        cmp.b #"Y",1(a4)
                        bne .Exit
.Ask_SYS_2              cmp.b #"s",2(a4)
                        beq .Ask_SYS_3
                        cmp.b #"S",2(a4)
                        bne .Exit
.Ask_SYS_3              tst.b 3(a4)
                        bne .Exit
                        bra .Password_Poll

.Ask_Chrs               move.l qso_User(a3),a0
                        cmpa.l #0,a0
                        beq .Exit
                        cmpa.l #0,a4
                        beq .Password_Violation
                        move.l a0,a2
                        move.b user_LPType(a2),d0
                        cmp.b #2,d0
                        beq .Ask_Chrs_TheNet
                        cmp.b #3,d0
                        beq .Ask_Chrs_Baycom
                        cmp.b #4,d0
                        beq .Ask_Chrs_TheNet
                        cmp.b #5,d0
                        beq .Ask_Chrs_Baycom
                        cmp.l #6,d0
                        beq .Ask_Chrs_TheNet
                        cmp.l #7,d0
                        beq .Ask_Chrs_Baycom
                        bra .Password_Violation


.Ask_Chrs_TheNet        lea qso_PasswordTemporary(a3),a0
                        lea user_LPassword(a2),a1
.Ask_Chrs_TheNet_L      move.l (a0)+,d0
                        cmp.l #-1,d0
                        beq .Ask_Chrs_TheNet_E
                        move.b -1(a1,d0.l),d0
                        cmp.b (a4)+,d0
                        bne .Password_Violation
                        bra .Ask_Chrs_TheNet_L
.Ask_Chrs_TheNet_E      tst.b (A4)
                        bne .Password_Violation
                        bra .Password_Correct
.Ask_Chrs_Baycom        lea user_LPassword(a2),a1
                        move.l a4,d5
.Ask_Chrs_Baycom_L1     move.l d5,a4
                        lea qso_PasswordTemporary(A3),a0
                        
.Ask_Chrs_Baycom_L2     move.l (a0)+,d0
                        cmp.l #-1,d0
                        beq .Ask_Chrs_Baycom_E
                        move.b -1(a1,d0.l),d0
                        tst.b (A4)
                        beq .Password_Violation
                        cmp.b (a4)+,d0
                        bne .Ask_Chrs_Baycom_N
                        bra .Ask_Chrs_Baycom_L2
.Ask_Chrs_Baycom_E      bra .Password_Correct
.Ask_Chrs_Baycom_N      addq.l #1,d5
                        bra .Ask_Chrs_Baycom_L1
                        
                
.Password_Poll          lea _CurrentDateStamp(a5),a0
                        move.l (a0),d0
                        ror.l #8,d0
                        ror.l #8,d0
                        eor.l #$12345678,d0
                        move.l 4(a0),d1
                        rol.l #8,d1
                        eor.l #$4e746d1e,d1
                        eor.l d1,d0
                        move.l 8(a0),d1
                        ror.l #8,d1
                        eor.l #$8e730351,d1
                        eor.l d1,d0
                        move.l d0,-(sp)
                        lea _CurrentDateStamp(a5),a0
                        move.l 4(a0),d0
                        ror.l #8,d0
                        ror.l #4,d0
                        eor.l #$eb186eda,d0
                        move.l 8(a0),d1
                        rol.l #7,d1
                        eor.l #$ce710e51,d1
                        eor.l d1,d0
                        move.l (a0),d1
                        ror.l #5,d1
                        eor.l #$b9c4184e,d1
                        eor.l d1,d0
                        move.l (sp)+,d1
                        eor.l d1,d0
                        move.l d0,d2
                        lea user_LPassword(a2),a0
                        moveq #-1,d0
.Password_Poll_L1       addq.l #1,d0
                        tst.b (a0)+
                        bne .Password_Poll_L1
                        move.l d0,d5
                        sub.l #64,a7
                        move.l a7,a4
                        lea qso_MyCall(a3),a0
                        moveq #0,d0
.Password_Poll_L2       tst.b (a0)
                        beq .Password_Poll_L2_E
                        move.b (a0)+,(a4)+
                        cmp.b #"-",-1(a4)
                        bne .Password_Poll_L2
                        moveq #1,d0
                        bra .Password_Poll_L2
.Password_Poll_L2_E     tst.l d0
                        bne .Password_Poll_SSID
                        move.b #"-",(A4)+
                        move.b #"0",(a4)+
.Password_Poll_SSID     move.b #">",(a4)+
                        move.b #" ",(A4)+
                        moveq #4,d4
                        move.l d2,d3
                        lea qso_PasswordTemporary(a3),a1
.Password_Poll_L3       move.l a1,-(sp)
                        move.l d3,d0
                        move.l d5,d1
                        move.l _UtilityBase(a5),a6
                        jsr _LVOUDivMod32(a6)
                        addq.l #1,d1
                        move.l (Sp)+,a1
                        move.l d1,(A1)+
                        move.l d0,d3
                        dbf d4,.Password_Poll_L3
                        move.l #-1,(a1)+
                        lea qso_PasswordTemporary(a3),a1
.Password_Poll_L4       move.l (a1)+,d0
                        cmp.l #-1,d0
                        beq .Password_Poll_L4_E
                        move.b #" ",(a4)+
                        divu #10,d0
                        or.l #$00300030,d0
                        cmp.w #$30,d0
                        beq .Password_Poll_J1
                        move.b d0,(A4)+
.Password_Poll_J1       swap d0
                        move.b d0,(A4)+
                        bra .Password_Poll_L4
.Password_Poll_L4_E     move.b #$d,(a4)+
                        clr.b (a4)+
                        move.l d7,d0
                        moveq #1,d1
                        moveq #0,d2
                        move.l a7,a0
                        jsr QSO_TransmitText
                        add.l #64,a7
                        moveq #4,d6
                        bra .Exit
                        
.Password_Violation     moveq #5,d6
                        move.l #"DDDD",-(a7)
                        move.l a7,a0
                        move.l d7,d1
                        moveq #1,d0
                        jsr QSO_SendCommand
                        addq.l #4,a7
                        bra .Exit
.Exit                   move.l d6,d0
                        movem.l (sp)+,d2-d7/a2-a6
                        rts
.Jump_Table             dc.l .Normal_Mode
                        dc.l .Exit
                        dc.l .Ask_PW
                        dc.l .Ask_SYS
                        dc.l .Ask_Chrs
                        dc.l .Exit
                        dc.l .Ask_Simple

;>D0 Hardunit
;>D1 Callset

QSO_FindFreeChannel     exg a4,a5
                        move.l d1,-(sp)
                        move.l d0,-(sp)
                        jsr _QSO_FindFreeChannel
                        addq.l #8,sp
                        exg a4,a5
                        rts

QSO_FindMatchChannel    exg a4,a5
                        move.l d0,-(sp)
                        jsr _QSO_FindMatchChannel
                        addq.l #4,sp
                        exg a4,a5
                        rts

                        XREF _GetStandardLanguage

QSO_GetStandardLanguage exg a4,a5
                        jsr _GetStandardLanguage
                        exg a4,a5 
                        rts

_QSO_GetQSOText         exg a4,a5
                        move.l 4(sp),d0
                        jsr QSO_GetQSOText
                        exg a4,a5
                        rts


QSO_GetQSOText          move.l a2,-(sp)
                        sub.l a1,a1
                        lea QSO_Locale,a2
                        lea QSO_Texts,a0
                        jsr QSO_GetText
                        move.l (sp)+,a2
                        rts

                        XREF _GetLanguageNode
QSO_GetLanguageNode     exg a4,a5
                        move.l a0,-(sp)
                        jsr _GetLanguageNode
                        addq.l #4,sp
                        exg a4,a5
                        rts

;>D0 Channel
;>D1 Type
;>D2 Length
;>D3 Version
;>A0 Data
;<D0 Success=0

QSO_DoPrPaCast          movem.l d2-d7/a2-a6,-(sp)
                        move.l d3,d7
                        move.l d2,d6
                        move.l d1,d5
                        move.l d0,d4
                        move.l a0,a4
                        move.l d2,d0
                        add.l #14,d0
                        move.l #$10000,d1
                        move.l _SysBase(a5),a6
                        jsr _LVOAllocVec(a6)
                        tst.l d0
                        beq .Error
                        move.l d0,a3
                        move.l d4,d0
                        jsr QSO_ForceTransmit
                        move.l #"#PrP",(a3)
                        move.w #"a#",4(a3)
                        move.w d5,6(a3)
                        move.w d6,8(a3)
                        move.w d7,10(a3)
                        move.w #$ffff,d0
                        sub.w d5,d0
                        sub.w d6,d0
                        sub.w d7,d0
                        move.w d0,12(a3)
                        lea 14(a3),a1
                        move.l d6,d0
                        move.l a4,a0
.Copy_Message           tst.l d0
                        beq .EndMsg
                        subq.l #1,d0
                        move.b (a0)+,(a1)+
                        bra .Copy_Message
.EndMsg                 move.l a3,a0
                        move.l d4,d1
                        move.l d6,d0
                        add.l #14,d0
                        jsr QSO_SendData
                        move.l d4,d0
                        jsr QSO_ForceTransmit
                        move.l a3,a1
                        move.l _SysBase(a5),a6
                        jsr _LVOFreeVec(a6)
                        moveq #0,d0
                        movem.l (sp)+,d2-d7/a2-a6
                        rts
.Error                  moveq #1,d0
                        movem.l (sp)+,d2-d7/a2-a6
                        rts

;>D0 Chan
;>D1 Type
;>D2 Length
;>D3 Version
;>A0 Data

QSO_HandlePrPaIncoming  movem.l d2-d7/a2-a6,-(sp)
                        move.l d0,d4
                        move.l d1,d5
                        move.l d2,d6
                        move.l d3,d7
                        move.l a0,a4
                        tst.w d5
                        beq .Handle_CryptIncome
                        
.Exit                   movem.l (sp)+,d2-d7/a2-a6
                        rts
.Error_Version          movem.l (sp)+,d2-d7/a2-a6
                        rts
.Wrong_Length           movem.l (sp)+,d2-d7/a2-a6
                        rts
.Handle_CryptIncome     cmp.l #0,d7
                        beq .Old_Version0
                        cmp.l #1,d7
                        bne .Error_Version
                        cmp.l #1,d6
                        blt .Wrong_Length
                        tst.b (a4)
                        beq .Do_Crypt_On
                        cmp.b #1,(a4)
                        beq .Do_Crypt_OnAck
                        cmp.b #2,(A4)
                        beq .Do_Crypt_Off
                        cmp.b #3,(a4)
                        beq .Do_Crypt_OffAck
                        bra .Exit
.Old_Version0           cmp.b #3,(a4)
                        beq .Exit
                        sub.l #4,a7
                        move.l d4,d0
                        moveq #0,d1
                        moveq #1,d2
                        moveq #0,d3
                        move.l a7,a0
                        move.b #3,(a0)
                        jsr QSO_DoPrPaCast
                        addq.l #4,a7
                        bra .Exit
.Do_Crypt_OffAckE       sub.l #4,a7
                        move.l d4,d0
                        moveq #0,d1
                        moveq #1,d2
                        moveq #1,d3
                        move.l a7,a0
                        move.b #3,(a0)
                        jsr QSO_DoPrPaCast
                        addq.l #4,a7
                        bra .Exit
.Do_Crypt_On            cmp.l #16,d6
                        bne .Do_Crypt_OffAckE
                        move.l d4,d0
                        subq.l #1,d0
                        mulu #qso_Size,d0
                        move.l _QSOs(a5),a0
                        add.l d0,a0
                        move.l a4,a3
                        move.l a0,a4
                        tst.l qso_Server(a4)
                        beq .Exit
                        move.l 4(a3),qso_XPKType(a4)
                        move.l 8(a3),qso_XPKEfficiency(a4)
                        move.l 12(a3),qso_XPKSublibrary(a4)
                        move.l d4,d0
                        jsr QSO_EncryptionOn
                        tst.l d0
                        bne .Do_Crypt_OffAckE
                        bclr #2,qso_CompressedMode+3(a4)
                        move.l d4,d0
                        sub.l #4,a7
                        moveq #0,d1
                        moveq #1,d2
                        moveq #1,d3
                        move.l a7,a0
                        move.b #1,(a0)
                        jsr QSO_DoPrPaCast
                        add.l #4,a7
                        tst.l d0
                        bne .Do_Crypt_OffAckE
                        bset #2,qso_CompressedMode+3(a4)
                        bset #3,qso_CompressedMode+3(a4)
                        jsr GUI_RefreshConnectHead
                        bra .Exit                                       
.Do_Crypt_OnAck         move.l d4,d0
                        subq.l #1,d0
                        mulu #qso_Size,d0
                        move.l _QSOs(a5),a0
                        add.l d0,a0
                        move.l a0,a4
                        bset #3,qso_CompressedMode+3(a4)
                        jsr GUI_RefreshConnectHead
                        bra .Exit
.Do_Crypt_Off           move.l d4,d0
                        subq.l #1,d0
                        mulu #qso_Size,d0
                        move.l _QSOs(a5),a0
                        add.l d0,a0
                        move.l a0,a4
                        tst.l qso_Server(a4)
                        beq .Exit
                        move.l d4,d0
                        sub.l #4,a7
                        moveq #0,d1
                        moveq #1,d2
                        moveq #1,d3
                        move.l a7,a0
                        move.b #3,(a0)
                        jsr QSO_DoPrPaCast
                        addq.l #4,a7
                        move.l d4,d0
                        jsr QSO_EncryptionOff
                        bra .Exit                                       

.Do_Crypt_OffAck        move.l d4,d0
                        jsr QSO_EncryptionOff
                        bra .Exit
                                

_QSO_ControlEncryption  exg a4,a5
                        move.l 4(sp),d0
                        move.l 8(sp),d1
                        jsr QSO_ControlEncryption
                        exg a4,a5
                        rts
        
QSO_ControlEncryption   movem.l d2-d7/a2-a6,-(sp)
                        move.l d1,d6
                        move.l d0,d7
                        tst.l d7
                        ble .Exit
                        move.l d7,d0
                        subq.l #1,d0
                        mulu #qso_Size,d0
                        move.l _QSOs(a5),a0
                        add.l d0,a0
                        move.l a0,a4
                        tst.l qso_Server(a4)
                        beq .Exit
                        move.l qso_User(a4),a0
                        cmpa.l #0,a0
                        beq .Exit
                        lea qso_StationID(a4),a0
                        cmp.l #1,sid_Program(a0)
                        bne .Exit
                        tst.l sid_Version(a0)
                        bgt .Good_Version
                        blt .Exit
                        cmp.l #21,sid_Revision(a0)
                        bgt .Good_Version
                        blt .Exit
                        cmp.l #3,sid_Subrevision(a0)
                        bge .Good_Version
                        bra .Exit
.Good_Version           cmp.l #2,d6
                        beq .ForceTxRxOn
                        cmp.l #3,d6
                        beq .ForceTxRxOn
                        cmp.l #4,d6
                        beq .ForceTxOff
                        cmp.l #5,d6
                        beq .ForceRxOff
                        cmp.l #1,d6
                        beq .Cast_EncOff

                        move.l qso_CompressedMode(a4),d0
                        and.l #$c,d0
                        tst.l d0
                        bne .Exit
.ForceTxRxOn

                        move.l #"IDEA",qso_XPKType(a4)
                        move.l #76,qso_XPKEfficiency(a4)
                        move.l d7,d0
                        move.l d6,d1
                        jsr QSO_EncryptionOn
                        tst.l d0
                        bne .Exit
                        tst.l d6
                        bne .Exit
                        bclr #2,qso_CompressedMode+3(a4)
                        move.l d7,d0
                        sub.l #16,a7
                        moveq #0,d1
                        moveq #16,d2
                        moveq #1,d3
                        move.l a7,a0
                        clr.l (a0)
                        move.l qso_XPKType(a4),4(a0)
                        move.l qso_XPKEfficiency(a4),8(a0)
                        move.l qso_XPKSublibrary(a4),12(a0)
                        jsr QSO_DoPrPaCast
                        add.l #16,a7
                        tst.l d0
                        bne .Error
                        bset #2,qso_CompressedMode+3(a4)
.Exit                   movem.l (sp)+,d2-d7/a2-a6
                        moveq #0,d0
                        rts
.Cast_EncOff            move.l d7,d0
                        subq.l #1,d0
                        mulu #qso_Size,d0
                        move.l _QSOs(a5),a0
                        add.l d0,a0
                        move.l a0,a4
                        tst.l qso_Server(a4)
                        beq .Exit
                        move.l d7,d0
                        sub.l #4,a7
                        moveq #0,d1
                        moveq #1,d2
                        moveq #1,d3
                        move.l a7,a0
                        move.b #2,(a0)
                        jsr QSO_DoPrPaCast
                        add.l #4,a7
                        bclr #2,qso_CompressedMode+3(a4)
                        jsr GUI_RefreshConnectHead
                        bra .Exit
                        
.Error                  move.l d7,d0
                        jsr QSO_EncryptionOff
                        bra .Exit

.ForceTxOff             bclr #2,qso_CompressedMode+3(a4)
                        jsr GUI_RefreshConnectHead
                        bra .Exit
.ForceRxOff             bclr #3,qso_CompressedMode+3(a4)
                        jsr GUI_RefreshConnectHead
                        bra .Exit

QSO_UncompressLink      movem.l d2-d7/a2-a6,-(sp)
                        tst.l d0
                        ble .Exit
                        move.l d0,d7
                        subq.l #1,d0
                        mulu #qso_Size,d0
                        move.l _QSOs(a5),a4
                        add.l d0,a4
                        move.l qso_CompressedMode(a4),d6
                        btst #0,d6
                        bne .Off_Compress
                        btst #1,d6
                        bne .Off_Compress
                        bra .Compress_IsOff
.Off_Compress           sub.l #16,a7
                        move.l #"//CO",(a7)
                        move.l #"MP 0",4(a7)
                        move.b #$0d,8(a7)
                        moveq #9,d0
                        move.l d7,d1
                        move.l a7,a0
                        jsr QSO_SendData
                        add.l #16,a7
                        move.l d7,d0
                        jsr QSO_ForceTransmit
                        move.l d7,d0
                        jsr QSO_CompressionOff
.Compress_IsOff         btst #2,d6
                        bne .Crypt_TurnOff
                        btst #3,d6
                        beq .Crypt_IsOff
.Crypt_TurnOff          move.l d7,d0
                        moveq #0,d1
                        moveq #1,d2
                        moveq #0,d3
                        subq.l #4,a7
                        move.b #2,(a7)
                        move.l a7,a0
                        jsr QSO_HandlePrPaIncoming
                        addq.l #4,a7
.Crypt_IsOff    
.Exit                   movem.l (sp)+,d2-d7/a2-a6
                        rts



QSO_OutputFormat        movem.l d2-d7/a2-a6,-(sp)
                        sub.l #32,a7
                        move.l a5,(a7)
                        clr.l 4(a7)
                        move.l d0,8(a7)
                        move.l d1,12(a7)
                        lea .Output_Proc(pc),a2
                        move.l a7,a3
                        move.l _SysBase(a5),a6
                        jsr _LVORawDoFmt(a6)
                        tst.l 4(a7)
                        beq .End_Output
                        move.l a7,a3
                        jsr .Flush_Output
.End_Output             add.l #32,a7
                        movem.l (sp)+,d2-d7/a2-a6
                        rts
.Flush_Output           movem.l d0-d7/a0-a6,-(sp)
                        move.l (a3),a5
                        move.l 4(a3),d0
                        move.l 8(a3),d1
                        lea 16(a3),a0
                        jsr QSO_SendData
                        tst.l 12(A3)
                        beq .No_Echo
                        move.l 4(A3),d0
                        move.l 8(a3),d1
                        moveq #2,d2
                        lea 16(a3),a0
                        jsr GUI_WriteToQSO
.No_Echo                clr.l 4(A3)
                        movem.l (Sp)+,d0-d7/a0-a6
                        rts
.Output_Proc            move.l a0,-(sp)
                        tst.b d0
                        beq .No_Outputter
                        lea 16(a3),a0
                        add.l 4(a3),a0
                        move.b d0,(a0)
                        add.l #1,4(a3)
                        cmp.l #16,4(a3)
                        blt .No_Outputter
                        jsr .Flush_Output
.No_Outputter           move.l (sp)+,a0
                        rts


;>D0 Channel
;>D1 Command (BOOL)
;>A0 Servername
;>A1 Parameters

QSO_StartExtServer      movem.l d2-d7/a2-a6,-(sp)
                        move.l d0,d6
                        move.l d1,d7

                        move.l a0,a3
                        move.l a1,a4



                        tst.l d6
                        ble .Error
                        cmp.l _MaxChannel(a5),d6
                        bgt .Error
                        moveq #-1,d5
                        move.l _QSOs(a5),a0
                        move.l d6,d0
                        subq.l #1,d0
                        mulu #qso_Size,d0
                        add.l d0,a0
                        tst.l qso_Server(a0)
                        beq .No_Server_Connected
                        move.l a6,-(sp)
                        move.l qso_Server(a0),a6
                        move.l a5,-(sp)
                        move.l _QSOBase(a5),a5
                        jsr _SVOGetServerType(a6)
                        move.l (sp)+,a5
                        move.l (sp)+,a6
                        move.l d0,d5
.No_Server_Connected

                        tst.l d7
                        bne .Command_Serv
                        lea _ServerList(a5),a0
                        move.l a3,a1
                        move.l _SysBase(a5),a6
                        jsr _LVOFindName(a6)
                        tst.l d0
                        beq .Error
                        move.l d0,a2
                        tst.l serlis_Type(a2)
                        bne .Error
                        cmp.l #-1,d5
                        beq .Serv_Serv
                        tst.l d5
                        bne .Error
                        bra .Serv_Serv
.Command_Serv           move.l a3,a0
                        jsr QSO_SearchComServer
                        tst.l d0
                        beq .Error
                        move.l d0,a2
                        tst.l d5
                        bne .Error
                        move.l _QSOs(a5),a0
                        move.l d6,d0
                        subq.l #1,d0
                        mulu #qso_Size,d0
                        add.l d0,a0
                        move.l #1,qso_SendPrompt(a0)

.Serv_Serv              move.l a2,a0
                        move.l a4,a1
                        move.l d6,d0
                        jsr QSO_StartServer
                        tst.l d0
                        bne .Error_SV

                        move.l d6,d0
.Leave                  movem.l (sp)+,d2-d7/a2-a6
                        rts
.Error                  moveq #0,d0
                        bra .Leave
.Error_SV               move.l _QSOs(a5),a0
                        move.l d6,d0
                        subq.l #1,d0
                        mulu #qso_Size,d0
                        add.l d0,a0
                        clr.l qso_SendPrompt(a0)
                        bra .Error



QSO_TestNameRequest     move.l d0,-(sp)
                        exg a4,a5
                        jsr _QSO_TestNameRequest
                        exg a4,a5
                        addq.l #4,sp
                        rts

QSO_GetOutstanding      move.l d0,-(sp)
                        jsr PACK_GetOutstanding
                        move.l (sp)+,d1
                        move.l d1,-(sp)
                        move.l _DelayBuffers(a5),a1
                        mulu #dela_Size,d1
                        add.l d1,a1
                        move.l (sp)+,d1
                        tst.l dela_BytesInBuffer(a1)
                        beq .No_Delayed
                        addq.l #1,d0
.No_Delayed             rts


GUI_GetLastActivity     exg a4,a5
                        move.l a0,-(sp)
                        jsr _GUI_GetLastActivity
                        addq.l #4,sp
                        exg a4,a5
                        rts


                        ;SECTION "QSO Processing Data Module",data


QSO_BaseEnd
                        AJUMP MAIL_TestForwardTime        ;-702 QVO_TestForwardTime
                        AJUMP MAIL_TestPrivateMail        ;-696 QVO_TestPrivateMail
                        AJUMP GUI_GetLastActivity         ;-690 QVO_GetLastActivity
                        AJUMP QSO_TestNameRequest         ;-684 QVO_TestNameRequest
                        AJUMP QSO_HandleXPLine            ;-678 QVO_HandleXPLine
                        AJUMP QSO_ControlXPCompress       ;-672 QVO_ControlXPCompress
                        AJUMP MAIL_MarkAsWantAck          ;-666 QVO_MarkAsWantAck
                        AJUMP MAIL_SetNotForward          ;-660 QVO_SetNotForward
                        AJUMP MAIL_ComposeRLine           ;-654 QVO_ComposeRLine
                        AJUMP MAIL_GetLatestMail          ;-648 QVO_GetLatestMail
                        AJUMP MAIL_GetForwardDest         ;-642 QVO_GetForwardDest
                        AJUMP QSO_WriteUserdata           ;-636 QVO_WriteUserdata
                        AJUMP QSO_FillUserdata            ;-630 QVO_FillUserdata
                        AJUMP MAIL_RemoveFMail            ;-624 QVO_RemoveFMail
                        AJUMP MAIL_GetNextFMail           ;-618 QVO_GetNextFMail
                        AJUMP MAIL_GetMailHRoute          ;-612 QVO_GetMailHRoute
                        AJUMP MAIL_MarkAs7Plus            ;-606 QVO_MarkAs7Plus
                        AJUMP QSO_HandleSID               ;-600 QVO_HandleSID
                        AJUMP QSO_SendPassword            ;-594 QVO_SendPassword
                        AJUMP QSO_TestPasswordString      ;-588 QVO_TestPasswordString
                        AJUMP QSO_ParseSID                ;-582 QVO_ParseSID
                        AJUMP QSO_TransmitSID             ;-576 QVO_TransmitSID
                        AJUMP MAIL_SearchMailBid          ;-570 QVO_SearchMailBid
                        AJUMP MAIL_SendMailFile           ;-564 QVO_SendMailFile                        
                        AJUMP MAIL_KillMail               ;-558 QVO_KillMail
                        AJUMP MAIL_GetMailDateTxt         ;-552 QVO_GetMailDateTxt
                        AJUMP MAIL_GetMailStatusTxt       ;-546 QVO_GetMailStatusTxt
                        AJUMP QSO_OutputFormat            ;-540 QVO_OutputFormat
                        AJUMP MAIL_MarkAsIncomp           ;-534 QVO_MarkAsIncomp
                        AJUMP MAIL_MarkAsForward          ;-528 QVO_MarkAsForward
                        AJUMP MAIL_MarkAsRead             ;-522 QVO_MarkAsRead
                        AJUMP MAIL_ReadMailLine           ;-516 QVO_ReadMailLine
                        AJUMP MAIL_ReadMail               ;-510 QVO_ReadMail
                        AJUMP MAIL_GetMailLines           ;-504 QVO_GetMailLines
                        AJUMP MAIL_SearchMail             ;-498 QVO_SearchMail
                        AJUMP MAIL_TestForMail            ;-492 QVO_TestForMail
                        AJUMP MAIL_GetMailBytes           ;-486 QVO_GetMailBytes
                        AJUMP MAIL_GetMailStatus          ;-480 QVO_GetMailStatus
                        AJUMP MAIL_GetMailDate            ;-472 QVO_GetMailDate
                        AJUMP MAIL_GetMailTitle           ;-468 QVO_GetMailTitle
                        AJUMP MAIL_GetMailAt              ;-462 QVO_GetMailAt
                        AJUMP MAIL_GetMailTo              ;-456 QVO_GetMailTo
                        AJUMP MAIL_GetMailFm              ;-450 QVO_GetMailFm
                        AJUMP MAIL_GetMailBid             ;-444 QVO_GetMailBid
                        AJUMP MAIL_GetNumberMail          ;-438 QVO_GetNumberMail
                        AJUMP MAIL_OpenMail               ;-432 QVO_OpenMail
                        AJUMP MAIL_WriteMail              ;-426 QVO_WriteMail
                        AJUMP MAIL_SetMailTitle           ;-420 QVO_SetMailTitle
                        AJUMP MAIL_CloseMail              ;-414 QVO_CloseMail
                        AJUMP MAIL_SendMail               ;-408 QVO_SendMail                            
                        AJUMP PACK_AskParameter          ;-402 QVO_AskParameter               
                        AJUMP QSO_UncompressLink          ;-396 QVO_UncompressLink
                        AJUMP QSO_GetLanguageNode         ;-390 QVO_GetLanguageNode
                        AJUMP QSO_GetText                 ;-384 QVO_GetText
                        AJUMP GUI_GetLanguageTable        ;-378 QVO_GetLanguageTable
                        AJUMP QSO_GetStandardLanguage     ;-372 QVO_GetStandardLanguage
                        AJUMP QSO_CRCFileUntil            ;-366 QVO_CRCFileUntil
                        AJUMP QSO_CRCFileOffset           ;-360 QVO_CRCFileOffset
                        AJUMP QSO_FindMatchChannel        ;-354 QVO_FindMatchChannel
                        AJUMP QSO_SendDataDirect          ;-348 QVO_TransmitDataDirect
                        AJUMP MAIN_GetConnectMsg          ;-342 QVO_GetConnectMsg
                        AJUMP QSO_GetMaxFrame             ;-336 QVO_GetMaxFrame
                        AJUMP QSO_AskPassword             ;-330 QVO_AskPassword
                        AJUMP QSO_MHeardLineLong          ;-324 QVO_MHeardLineLong
                        AJUMP QSO_MHeardLine              ;-318 QVO_MHeardLine
                        AJUMP QSO_NewsCommand             ;-312 QVO_NewsCommand
                        AJUMP QSO_TransmitMacroDirect     ;-306 QVO_TransmitMacroDirect
                        AJUMP MAIN_GetSecondsAgo          ;-300 QVO_GetSecondsAgo
                        AJUMP QSO_GetChannelQSO           ;-294 QVO_GetChannelQSO
                        AJUMP GUI_GetString               ;-288 QVO_GetString
                        AJUMP QSO_CompressionOff          ;-282 QVO_CompressionOff
                        AJUMP QSO_CompressionOn           ;-276 QVO_CompressionOn
                        AJUMP QSO_TestForwardConnect      ;-270 QVO_TestForwardConnect
                        AJUMP QSO_LocatorToClear          ;-264 QVO_LocatorToClear
                        AJUMP QSO_ValidateLocator         ;-258 QVO_ValidateLocator
                        AJUMP QSO_ChangeChannel           ;-252 QVO_ChangeChannel
                        AJUMP QSO_ChangeUser              ;-246 QVO_ChangeUser
                        AJUMP QSO_CloseUser               ;-240 QVO_CloseUser
                        AJUMP QSO_OpenUser                ;-234 QVO_OpenUSer
                        AJUMP QSO_ParseComLine            ;-228 QVO_ParseComLine
                        AJUMP GUI_DisplayEventWindow      ;-222 QVO_DisplayMsgWin
                        AJUMP QSO_LineParse               ;-216 QVO_LineParse
                        AJUMP QSO_Test7PlusName           ;-210 QVO_Test7PlusName
                        AJUMP MAIN_ConvertToAmigaLen      ;-204 QVO_ConvertToAmigaLen
                        AJUMP MAIN_ConvertToPCLen         ;-198 QVO_ConvertToPCLen
                        AJUMP MAIN_ConvertToAmiga         ;-192 QVO_ConvertToAmiga
                        AJUMP MAIN_ConvertToPC            ;-186 QVO_ConvertToPC
                        AJUMP QSO_GetPacLen               ;-180 QVO_GetPacLen
                        AJUMP QSO_GetOutstanding          ;-174 QVO_GetOutstanding
                        AJUMP MAIN_LongToString           ;-168 QVO_LongToString
                        AJUMP QSO_AmigaDateMs             ;-162 QVO_AmigaDateMs
                        AJUMP QSO_GetFileInfo             ;-156 QVO_GetFileInfo
                        AJUMP QSO_ProcessPathName         ;-150 QVO_ProcessPathName
                        AJUMP QSO_SearchComServer         ;-142 QVO_SearchComServer
                        AJUMP QSO_CRCFile                 ;-136 QVO_CRCFile
                        AJUMP QSO_SetFileInfos            ;-132 QVO_SetFileInfos
                        AJUMP QSO_MSDateAmiga             ;-126 QVO_MsDateAmiga
                        AJUMP QSO_GetSaveDir              ;-120 QVO_GetSaveDir
                        AJUMP QSO_GetUserDir              ;-114 QVO_GetRemoteDir
                        AJUMP GUI_RedisplayFileTransfer   ;-108 QVO_RedisplayFileTransfer
                        AJUMP MAIN_RecalcFileTransfer     ;-102 QVO_RecalcFileTransfer
                        AJUMP MAIN_ResetFileTransfer      ;- 96 QVO_ResetFileTransfer
                        AJUMP QSO_SearchSpecialServer     ;- 90 QVO_SearchSpecialServer
                        AJUMP QSO_StartServer             ;- 84 QVO_StartServer
                        AJUMP MAIN_TestServBufferLin      ;- 78 QVO_TestServBufferLin
                        AJUMP MAIN_TestServBuffer         ;- 72 QVO_TestServBuffer
                        AJUMP MAIN_ReadServBuffer         ;- 66 QVO_ReadServBuffer
                        AJUMP MAIN_WriteServBuffer        ;- 60 QVO_WriteServBuffer
                        AJUMP AUDIO_Effect                ;- 54 QVO_AudioEffect
                        AJUMP QSO_TransmitMacroFile       ;- 48 QVO_TransmitMarcoFile
                        AJUMP QSO_TransmitText            ;- 42 QVO_TransmitText
                        AJUMP QSO_CreateServerBase        ;- 36 QVO_CreateServerBase
                        AJUMP GUI_WriteToQSO              ;- 30 QVO_WriteTerminalUni
                        AJUMP QSO_WriteTerminal           ;- 24 QVO_WriteTerminal
                        AJUMP QSO_ForceTransmit           ;- 18 QVO_ForceTransmit
                        AJUMP QSO_SendData                ;- 12 QVO_TransmitData
                        AJUMP QSO_SendCommand             ;-  6 QVO_TransmitCommand
QSO_Base                



QSO_Locale              dc.b "ProfiPacket/Mail.catalog",0


        even
QSO_Texts
        dc.w 15
        dc.b    ' new messages for you!',$07,$0d,$0d,0
        even                               ;ID 15 mailmacnew

        dc.w 16
        dc.b    ' messages you already read!',$0d,$0d,0
        even                               ;ID 16 mailmacold

        dc.w 17
        dc.b    'Msg#   TSLD Byte To    @ BBS   From   Date/Time Title',$0d,0
        even                               ;ID 17 listhead1

        dc.w 18
        dc.b    '=====  ==   ==== ===== ======= ====== ====/==== ======',$0d,0
        even                               ;ID 18 listhead2

        dc.w -1



                        even;  IMPORTANT !!!! ALIGNMENT FOR MOVE.L
                                                
Transfer_Mode_Comments  dc.b "AUTOBIN "
                        dc.b "AUTOBIN "
                        dc.b "7PLUS   "
                        dc.b "7PLUS   "
                        dc.b "BINARY  "
                        dc.b "BINARY  "
                        dc.b "AMGTEXT "
                        dc.b "AMGTEXT "
                        dc.b "PCTEXT  "
                        dc.b "PCTEXT  "
                        even



Origin_File             dc.b "Text/origin.txt",0
News_File               dc.b "Text/news.txt",0
User_File               dc.b "Data/users.dat",0
Holdings_File           dc.b "Data/connects.dat",0
Server_Dir              dc.b "Servers",0
Chat_Server             dc.b "CHAT",0
                        even
                        
                        rsreset
serlis_Node             rs.b 14                 ;Node
serlis_Type             rs.l 1                  ;0=Server   1=Commands
serlis_SegList          rs.l 1                  ;Seglist to unload
serlis_Version          rs.l 1                  ;Version number
serlis_ServerInit       rs.l 1                  ;Pointer to ServerInit
serlis_SubType          rs.l 1                  ;Subtyp des Servers (Protection)
serlis_Size             rs.l 1          




                        rsreset
dela_DateStamp          rs.b 12
dela_BytesInBuffer      rs.l 1
dela_Buffer             rs.b 256
dela_Size               rs.b 0


