;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


HARD_TASKPRI    EQU 5

                CPU M68000
                SNMAOPT Q+,P+,A+,B-,S+,M+
                NOLIST
                                    ;(O = Optimieren)  
                IDNT PacketInterface
                
                                
                XDEF PACK_Init                  ;() ()
                 ;Initialisiert den Hardwaretreiber
                XDEF PACK_Cleanup               ;() ()
                 ;Deinitialisiert den Hardwaretreiber
                XDEF PACK_DoPoll                ;() ()
                 ;Pollroutine für den HardwareTreiber
                XDEF PACK_TransmitCommand       ;(Length,Channel,Data) (D0,D1,A0)
                 ;Sendet ein Kommando zum TNC     D0<>0=Not enough mem
                XDEF PACK_TransmitData          ;(Length,Channel,Data) (D0,D1,A0)
                 ;Sendet ein Datenpaket zum TNC   D0<>0=Not enough mem 
                XDEF PACK_GetOutstanding        ;(Channel) (D0)
                 ;Gibt Zahl der ausstehenden Packets in D0 zurück
                XDEF PACK_UpdateTNCTime         ;() ()
                 ;Sendet aktuelle Zeit zum TNC
                XDEF PACK_AnalizeLinkStatusL    ;(LinkEventLine,LineLen) (A0,D0)
                 ;D0:LinkStatusNummer
                XDEF PACK_AskParameter          ;(Channel,12LArray) (D0,A0)
                 ;D0:OK=0  Liest Linkparameter von TNC (12 Longword Array)


                XDEF PACK_SetMonitorUnit        ;(Unit) (D0)

                XDEF PACK_GetMonitorUnit        ;
                 ;D0:Unit -1=All

                XREF GUI_RefreshPacketHead
                XREF GUI_RefreshConnectHead
                XREF GUI_ChangeHardStatus
                
                XREF MAIN_HardwareInitChan
                
                XREF QSO_IncomingMonitor
                XREF QSO_IncomingChannel
                XREF QSO_InitalizeChannel
                XREF QSO_DoConnect
                XREF QSO_DoConnectCText
                XREF QSO_DoDisconnect
                XREF QSO_OpenStandardUser
                XREF QSO_CloseUser
                XREF QSO_GetPacLen

                XREF _GUI_LaunchWindowPoll
                
                XDEF _PACK_Init

                incdir "sys:include/"
                include "libraries/dos_lib.i"
                include "utility/utility_lib.i"
                include "exec/exec_lib.i"
                include "exec/tasks.i"
                include "devices/serial.i"
                include "global.i"
                
                SECTION ".text",code
                

_PACK_Init              exg a4,a5
                        jsr PACK_Init
                        exg a4,a5
                        rts

PACK_Init               move.l #-1,_MonitorHUnit(a5)
                        moveq #0,d0
                        jsr PACK_LaunchHardUnit
                        moveq #1,d0
                        jsr PACK_LaunchHardUnit
                        moveq #2,d0
                        jsr PACK_LaunchHardUnit
                        moveq #3,d0
                        jsr PACK_LaunchHardUnit
                        moveq #4,d0
                        jsr PACK_LaunchHardUnit
                        moveq #5,d0
                        jsr PACK_LaunchHardUnit
                        moveq #6,d0
                        jsr PACK_LaunchHardUnit
                        moveq #7,d0
                        jsr PACK_LaunchHardUnit
                        jsr GUI_RefreshPacketHead
                        jsr GUI_RefreshConnectHead
                        moveq #0,d0
                        rts
PACK_Cleanup            moveq #0,d0
                        jsr PACK_LandHardUnit
                        moveq #1,d0
                        jsr PACK_LandHardUnit
                        moveq #2,d0
                        jsr PACK_LandHardUnit
                        moveq #3,d0
                        jsr PACK_LandHardUnit
                        moveq #4,d0
                        jsr PACK_LandHardUnit
                        moveq #5,d0
                        jsr PACK_LandHardUnit
                        moveq #6,d0
                        jsr PACK_LandHardUnit
                        moveq #7,d0
                        jsr PACK_LandHardUnit
                        moveq #0,d0
                        rts

PACK_DoPoll             moveq #0,d0
                        jsr PACK_PollHardUnit
                        moveq #1,d0
                        jsr PACK_PollHardUnit
                        moveq #2,d0
                        jsr PACK_PollHardUnit
                        moveq #3,d0
                        jsr PACK_PollHardUnit
                        moveq #4,d0
                        jsr PACK_PollHardUnit
                        moveq #5,d0
                        jsr PACK_PollHardUnit
                        moveq #6,d0
                        jsr PACK_PollHardUnit
                        moveq #7,d0
                        jsr PACK_PollHardUnit
                        moveq #0,d0
                        jsr PACK_GetUnitStatus
                        moveq #1,d0
                        jsr PACK_GetUnitStatus
                        moveq #2,d0
                        jsr PACK_GetUnitStatus
                        moveq #3,d0
                        jsr PACK_GetUnitStatus
                        moveq #4,d0
                        jsr PACK_GetUnitStatus
                        moveq #5,d0
                        jsr PACK_GetUnitStatus
                        moveq #6,d0
                        jsr PACK_GetUnitStatus
                        moveq #7,d0
                        jsr PACK_GetUnitStatus
                        moveq #0,d0
                        rts



PACK_SetMonitorUnit     move.l d0,_MonitorHUnit(a5)
                        rts

PACK_GetMonitorUnit     move.l _MonitorHUnit(a5),d0
                        rts


;>D0 Channel
;>A0 ParamArray
;<D0 Success = 0

PACK_AskParameter       movem.l d2-d7/a2-a6,-(sp)
                        move.l d0,d7
                        moveq #-1,d0
                        tst.l d7
                        ble .Exit
                        move.l a0,a4
                        move.l d7,d0
                        jsr QSO_GetPacLen
                        move.l d0,(a4)
                        lea 4(a4),a4
                        lea .Command_List(pc),a3
                        moveq #10,d6
.Put_Commands           move.l a3,a0
                        moveq #-1,d0
.Put_Commands_GetLen    addq.l #1,d0
                        tst.b (a0)+
                        bne .Put_Commands_GetLen
                        move.l d7,d1
                        exg.l a3,a0
                        jsr PACK_TransmitCommand
                        dbf d6,.Put_Commands
                        
                        moveq #79,d6
.Wait_DoneTime          move.l _DOSBase(a5),a6
                        moveq #5,d1
                        jsr _LVODelay(a6)
                        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

                        move.l qso_HardwareUnit(a3),d0
                        asl.l #2,d0
                        lea _HardUnits(a5),a0
                        add.l d0,a0
                        moveq #-1,d0
                        move.l (a0),a0
                        cmpa.l #0,a0
                        beq .Exit
                        
                        move.l qso_ChannelInPackets(a3),a0
                        tst.l (a0)
                        beq .No_InputPackets
        
                        move.l _SysBase(a5),a6
                        jsr _LVOForbid(a6)
                        lea qso_ChannelInPackets(a3),a1
                        moveq #0,d2
.Count_Rights           move.l (a1),a1
                        tst.l (a1)
                        beq .Rights_Counted
                        cmp.w #1,14(a1)
                        beq .Yes_Right
                        cmp.w #2,14(a1)
                        bne .Count_Rights
.Yes_Right              addq.l #1,d2
                        bra .Count_Rights
                        
.Rights_Counted         jsr _LVOPermit(a6)
                        cmp.l #11,d2
                        blt .No_InputPackets
                        
                        
                        moveq #0,d0
                        bra .AllPacks_Here
                                        
.No_InputPackets        dbf d6,.Wait_DoneTime
                        moveq #-1,d0
                        bra .Exit
.AllPacks_Here          move.l _SysBase(a5),a6
                        jsr _LVOForbid(a6)
                        lea qso_ChannelInPackets+4(a3),a2
                        moveq #10,d6
                        move.l 4(a2),a2
.AllPacks_Here_Searchy  tst.l (a2)
                        beq .Searchy_End
                        cmp.w #1,14(a2)
                        beq .Searchy_Good
                        cmp.w #2,14(a2)
                        bne .AllPacks_Here_Searchy
.Searchy_Good           move.l d6,d0
                        move.l a2,a0
                        move.l 4(a2),a2
                        jsr .Searchy_Sub
                        subq.l #1,d6
                        tst.l d6
                        bge .AllPacks_Here_Searchy
                        bra .Searchy_End
.Searchy_End            move.l _SysBase(a5),a6
                        jsr _LVOPermit(a6)
                        moveq #0,d0
                        bra .Exit
.Searchy_Sub            movem.l a0/d0,-(sp)
                        move.l _SysBase(a5),a6
                        move.l a0,a1
                        jsr _LVORemove(a6)
                        movem.l (sp)+,a0/d0
                        cmp.w #2,14(a0)
                        beq .Sub_Error
                        move.l d0,d1
                        movem.l a0-a6/d1-d7,-(sp)
                        move.l 16(a0),d7
                        lea 20(a0),a4
                        moveq #0,d6             ;Stellenwert
                        moveq #0,d5             ;Summe
.Sub_ReadVal            tst.l d7
                        beq .Sub_GoodValue
                        moveq #0,d0
                        move.b (a4)+,d0
                        subq.l #1,d7
                        cmp.b #" ",d0
                        beq .Sub_GoodValue
                        cmp.b #"(",d0
                        beq .Sub_GoodValue
                        cmp.b #"0",d0
                        blt .Sub_Error_2
                        cmp.b #"9",d0
                        bgt .Sub_Error_2
                        sub.b #$30,d0
                        move.l d0,d4
                        tst.l d6
                        beq .Sub_ReadValFirst
                        move.l d5,d0
                        moveq #10,d1
                        move.l _UtilityBase(a5),a6
                        jsr _LVOUMult32(a6)
                        add.l d4,d0
                        move.l d0,d5
                        bra .Sub_ReadVal
.Sub_ReadValFirst       move.l d4,d5
                        moveq #1,d6
                        bra .Sub_ReadVal
                        
                        
                        
.Sub_GoodValue          tst.l d6
                        beq .Sub_Error_2
                        move.l d5,d0
                        movem.l (sp)+,a0-a6/d1-d7
                        asl.l #2,d1
                        move.l a4,a1
                        add.l d1,a1
                        move.l d0,(a1)
.Sub_Free               move.l a0,a1
                        move.l _SysBase(a5),a6
                        jsr _LVOFreeVec(a6)
                        rts
.Sub_Error_2            movem.l (sp)+,a0-a6/d1-d7
                        move.l d1,d0
.Sub_Error              asl.l #2,d0
                        move.l a4,a1
                        add.l d0,a1
                        move.l #-1,(a1)
                        bra .Sub_Free
                                                
.Exit                   movem.l (sp)+,d2-d7/a2-a6
                        rts



.Command_List           dc.b "F",0      ;Frack
                        dc.b "N",0      ;Versuche
                        dc.b "O",0      ;Maxframe
                        dc.b "P",0      ;Persistence
                        dc.b "W",0      ;Slot time
                        dc.b "@I",0     ;IPoll
                        dc.b "R",0      ;Digipeating
                        dc.b "@T2",0    ;Timer 2
                        dc.b "@T3",0    ;Timer 3
                        dc.b "T",0      ;TX Delay
                        dc.b "@TA",0    ;TXTail
                        
PACK_TransmitCommand    move.l d2,-(sp)
                        moveq #1,d2
                        jsr PACK_TransmitEvent
                        move.l (sp)+,d2
                        rts
PACK_TransmitData       move.l d2,-(sp)
                        moveq #0,d2
                        jsr PACK_TransmitEvent
                        move.l (sp)+,d2
                        rts
PACK_TransmitEvent      movem.l d2-d6/a2-a6,-(sp)
                        tst.l d0
                        beq .Exit
                        move.l d0,d5
                        move.l d1,d4
                        move.l d2,d3
                        move.l a0,a4
                        move.l d4,d0
                        tst.l d0
                        beq .Dont_Worry_Mon
                        subq.l #1,d0
                        mulu #qso_Size,d0
                        move.l _QSOs(a5),a0
                        add.l d0,a0
                        move.l qso_HardwareUnit(a0),d0
                        asl.l #2,d0
                        lea _HardUnits(a5),a1
                        add.l d0,a1
                        tst.l (a1)
                        beq .Exit
                        move.l a0,d6
.Dont_Worry_Mon         move.l _SysBase(a5),a6
                        moveq #20,d0
                        add.l d5,d0
                        move.l #$10001,d1
                        jsr _LVOAllocVec(A6)
                        tst.l d0
                        beq .Error
                        move.l d0,a3
                        clr.l (a3)
                        clr.l 4(a3)
                        clr.w 8(a3)
                        clr.l 10(a3)
                        move.w d3,14(a3)
                        move.l d5,16(a3)
                        move.l d5,d0
                        lea 20(a3),a1
                        move.l a4,a0
.Copy_Event             tst.l d0
                        beq .Copy_Ended
                        subq.l #1,d0
                        move.b (a0)+,(a1)+
                        bra .Copy_Event
.Copy_Ended             tst.l d4
                        beq .Dump_Monitor
                        move.l d6,a0
                        lea qso_ChannelOutPackets(a0),a0
                        move.l a0,-(sp)
                        jsr _LVOForbid(a6)
                        move.l (sp)+,a0
                        move.l a3,a1
                        jsr _LVOAddTail(a6)
                        jsr _LVOPermit(a6)
                        bra .Exit                       
.Dump_Monitor           move.l a3,a4
                        add.l #20,d5
                        moveq #0,d4
.Dump_Monitor_L         lea _HardUnits(a5),a0
                        move.l d4,d0
                        asl.l #2,d0
                        add.l d0,a0
                        tst.l (a0)
                        beq .Dump_Monitor_Next
                        cmp.l #-1,_MonitorHUnit(a5)
                        beq .Dump_Mon_Real
                        cmp.l _MonitorHUnit(a5),d4
                        bne .Dump_Monitor_Next
.Dump_Mon_Real          move.l (a0),a2
                        move.l d5,d0
                        move.l #$10001,d1
                        jsr _LVOAllocVec(A6)
                        tst.l d0
                        beq .Error_2
                        move.l d0,a3
                        move.l a4,a0
                        move.l a3,a1
                        move.l d5,d0
.Copy_MonEvent          tst.l d0
                        beq .Copied_MonEvent
                        subq.l #1,d0
                        move.b (a0)+,(a1)+
                        bra .Copy_MonEvent
.Copied_MonEvent        jsr _LVOForbid(a6)
                        move.l a3,a1
                        lea hard_MonitorOutPackets(a2),a0
                        jsr _LVOAddTail(a6)
                        jsr _LVOPermit(A6)
.Dump_Monitor_Next      addq.l #1,d4
                        cmp.l #4,d4
                        blt .Dump_Monitor_L
                        move.l a4,a1
                        jsr _LVOFreeVec(a6)
                        bra .Exit
                        

.Exit                   moveq #0,d0
                        movem.l (Sp)+,d2-d6/a2-a6
                        rts
.Error_2                move.l a4,a1
                        jsr _LVOFreeVec(A6)
.Error                  moveq #-1,d0
                        movem.l (Sp)+,d2-d6/a2-a6
                        rts

PACK_GetOutstanding     subq.l #1,d0
                        mulu #qso_Size,d0
                        move.l _QSOs(A5),a0
                        add.l d0,a0
                        move.l a6,-(sp)
                        move.l a0,-(sp)
                        move.l _SysBase(a5),a6
                        jsr _LVOForbid(a6)
                        move.l (sp)+,a0
                        moveq #0,d0
                        move.l qso_Unack(a0),d0
                        add.l qso_NotSent(a0),d0
                        lea qso_ChannelOutPackets(a0),a0
.Loop                   move.l (a0),a0
                        tst.l (a0)
                        beq .Exit
                        cmp.w #1,14(a0)
                        beq .Loop
                        addq.l #1,d0
                        bra .Loop
.Exit                   move.l d0,-(sp)
                        jsr _LVOPermit(a6)
                        move.l (Sp)+,d0
                        move.l (Sp)+,a6
                        rts
                                                
                
PACK_PollHardUnit       movem.l d2-d7/a2-a6,-(sp)
                        move.l d0,d7
                        asl.l #2,d0
                        lea _HardUnits(a5),a0
                        add.l d0,a0
                        move.l (a0),a4
                        cmpa.l #0,a4
                        beq .Exit
                        move.l hard_MaxChannel(a4),d6
                        moveq #1,d5
                        moveq #0,d3
.Loop                   cmp.l d6,d5
                        bgt .Exit_L
                        move.l d5,d0
                        subq.l #1,d0
                        asl.l #2,d0
                        lea hard_ChannelAddress(a4),a0
                        lea hard_ChannelNumber(a4),a1
                        add.l d0,a0
                        add.l d0,a1
                        move.l (a0),a3
                        move.l (a1),d4
                        cmp.l _ActiveChannel(a5),d4
                        bne .No_Need_Updateing
                        btst #1,qso_UpdateFlag(a3)
                        beq .No_UpdateQSOBar
                        bclr #1,qso_UpdateFlag(a3)
                        jsr GUI_RefreshConnectHead
.No_UpdateQSOBar        
.No_Need_Updateing      move.l qso_ChannelInPackets(a3),a0
                        tst.l (a0)
                        beq .No_InputPackets
                        move.l _SysBase(a5),a6
                        jsr _LVOForbid(a6)
                        move.l qso_ChannelInPackets(a3),a1
                        move.l a1,-(sp)
                        jsr _LVORemove(A6)
                        jsr _LVOPermit(a6)
                        move.l (Sp)+,a1
                        
                        cmp.w #3,14(a1)
                        bne .PACKT_NoLinkStat_2
                        move.l a1,-(sp)
                        move.l a1,a0
                        jsr PACK_AnalizeLinkStatus
                        move.l (Sp)+,a1
                        cmp.l #1,d0
                        beq .PACKT_SkipConnect
.PACKT_NoLinkStat_2     lea 20(a1),a0
                        move.l 16(a1),d0
                        moveq #0,d1
                        move.w 14(a1),d1
                        move.l a1,-(sp)
                        move.l d4,d2
                        jsr QSO_IncomingChannel
                        move.l (sp)+,a1
.PACKT_SkipConnect      cmp.w #3,14(a1)
                        bne .PACKT_NoLinkStat
                        move.l a1,-(sp)
                        move.l a1,a0
                        move.l a1,-(Sp)
                        jsr PACK_AnalizeLinkStatus
                        move.l (Sp)+,a1
                        cmp.l #-1,d0
                        beq .PACKT_LinkStatDone
                        tst.l d0
                        beq .PACKT_Disconnect
                        cmp.l #1,d0
                        beq .PACKT_Connect
                        cmp.l #2,d0
                        beq .PACKT_LinkReset
                        cmp.l #3,d0
                        beq .PACKT_LinkReset
                        cmp.l #4,d0
                        beq .PACKT_Disconnect
                        cmp.l #5,d0
                        beq .PACKT_Disconnect
                        bra .PACKT_LinkStatDone
.PACKT_Disconnect       clr.w qso_SelfConnect(a3)
                        tst.l qso_Server(a3)
                        bne .PACKT_DisconnectR
                        cmp.b #"-",qso_Call(a3)
                        beq .PACKT_LinkStatDone
                        bra .PACKT_DisconnectR
.PACKT_LinkReset        move.l d1,d0
                        move.l a1,d1
                        move.l a3,a0
                        jsr PACK_AnalizeLinkPath
                        bra .PACKT_LinkStatDone
.PACKT_Connect

                        move.l a1,-(sp)
                        move.l d2,-(sp)
                        moveq #0,d2
                        move.b qso_Call(A3),d2
                        move.l d1,d0
                        move.l a1,d1
                        move.l a3,a0
                        jsr PACK_AnalizeLinkPath
                        move.l d2,a0
                        move.l d4,d0
                        moveq #0,d1
                        moveq #0,d2
                        tst.l qso_StartupMsg(a3)
                        bne .PACKT_ConNoSelf
                        cmp.l #"-",a0
                        bne .PACKT_ConSelf
                        tst.w qso_SelfConnect(a3)
                        beq .PACKT_ConNoSelf
.PACKT_ConSelf          moveq #1,d1
                        bra .PACKT_DoConny
.PACKT_ConNoSelf        moveq #1,d2
.PACKT_DoConny          jsr QSO_DoConnect
                        move.l (sp)+,d2
                        move.l (sp)+,a1
                        lea 20(a1),a0
                        move.l 16(a1),d0
                        moveq #0,d1
                        move.w 14(a1),d1
                        move.l a1,-(sp)
                        move.l d4,d2
                        jsr QSO_IncomingChannel
                        move.l (sp)+,a1
                        move.l d4,d0
                        moveq #0,d1
                        move.w qso_SelfConnect(a3),d1
                        jsr QSO_DoConnectCText

                        bra .PACKT_LinkStatDone
.PACKT_DisconnectR      move.l d4,d0
                        jsr QSO_DoDisconnect
                        bra .PACKT_LinkStatDone
.PACKT_LinkStatDone     move.l (sp)+,a1
.PACKT_NoLinkStat
                        cmp.l qso_StartupMsg(a3),a1
                        bne .No_Disclose_PacketSend
                        clr.l qso_StartupMsg(a3)
.No_Disclose_PacketSend move.l _SysBase(a5),a6
                        jsr _LVOFreeVec(a6)
                        bra .No_Need_Updateing
                        
.No_InputPackets        addq.l #1,d5
                        bra .Loop
                        
                
.Exit_L                 move.l hard_MonitorInPackets(a4),a0
                        tst.l (A0)
                        beq .No_MonitorIn
                        cmp.w #5,14(a0)
                        bne .Monitor_Outputter
                        move.l (a0),a0
                        tst.l (a0)
                        beq .No_MonitorIn
.Monitor_Outputter      move.l _SysBase(a5),a6
                        jsr _LVOForbid(a6)
                        move.l hard_MonitorInPackets(a4),a1
                        move.l a1,-(sp)
                        jsr _LVORemove(A6)
                        jsr _LVOPermit(a6)
                        move.l (Sp)+,a1
                        lea 20(a1),a0
                        move.l 16(a1),d0
                        moveq #0,d1
                        move.w 14(a1),d1
                        move.l a1,-(sp)
                        move.l hard_Unit(a4),d2
                        jsr QSO_IncomingMonitor
                        move.l (sp)+,a1
                        move.l _SysBase(a5),a6
                        jsr _LVOFreeVec(a6)
                        bra .Exit_L
                        
.No_MonitorIn           
                        
.Exit                   movem.l (sp)+,d2-d7/a2-a6
                        rts
                        



PACK_LaunchHardUnit     movem.l d2-d7/a2-a6,-(sp)
                        move.l d0,d7
                        lea _Preferences(a5),a4
                        lea pref_Devices(a4),a1
                        move.l d7,d0
                        mulu #devi_Size,d0
                        add.l d0,a1
                        lea devi_ExecDevice(a1),a0
                        tst.b (a0)
                        beq .Exit
                        lea devi_GlobalMycall(a1),a0
                        tst.b (a0)
                        beq .Exit
                        tst.l devi_Channels(a1)
                        beq .Exit
                        move.l #hard_Size,d0
                        move.l #$10001,d1
                        move.l _SysBase(a5),a6
                        jsr _LVOAllocVec(A6)
                        moveq #1,d1
                        tst.l d0
                        beq .Error_Exit
                        move.l d0,a4
                        move.l d7,hard_Unit(a4)
                        lea _Preferences(a5),a0
                        move.l a0,hard_Preferences(a4)
                        clr.l hard_PleaseLeave(a4)
                        move.l #1,hard_DontGetData(A4)
                        clr.l hard_LaunchProgress(A4)
                        move.l a5,hard_Global(a4)
                        
                        move.l #-1,hard_MonitorF(a4)
                        move.l #-1,hard_MonitorN(a4)
                        move.l #-1,hard_MonitorO(a4)
                        jsr QSO_OpenStandardUser
                        tst.l d0
                        beq .No_LinkParams
                        move.l d0,a0
                        moveq #0,d0
                        move.w user_CurFrack(a0),d0
                        move.l d0,hard_MonitorF(a4)
                        move.w user_CurTries(a0),d0
                        move.l d0,hard_MonitorN(a4)
                        move.w user_CurMaxFrame(a0),d0
                        move.l d0,hard_MonitorO(a4)
                        jsr QSO_CloseUser
.No_LinkParams          
                                                        
                        move.l a7,a2
                        clr.l -(a7)
                        lea PACK_ProcEntryPoint,a0
                        move.l a0,-(sp)
                        move.l #$800003eb,-(sp)
                        lea Process_Name,a0
                        move.l a0,-(sp)
                        move.l #$800003f4,-(sp)
                        move.l #-100,-(sp)
                        move.l #$800003f5,-(sp)
                        move.l a7,d1
                        move.l _DOSBase(a5),a6
                        jsr _LVOCreateNewProc(a6)
                        move.l a2,a7
                        tst.l d0
                        beq .Exit_NoTask
                        move.l d0,a0
                        move.l a0,hard_Task(a4)
                        move.l a4,TC_Userdata(a0)
                        move.l a0,a1
                        moveq #HARD_TASKPRI,d0
                        move.l _SysBase(a5),a6
                        jsr _LVOSetTaskPri(a6)

.Wait_For_Done          move.l _DOSBase(a5),a6
                        moveq #1,d1
                        jsr _LVODelay(a6)
                        exg a4,a5
                        jsr _GUI_LaunchWindowPoll
                        exg a4,a5
                        move.l d0,d2
                        move.l _SysBase(a5),a6
                        jsr _LVOForbid(a6)
                        move.l hard_Task(a4),a0
                        cmpa.l #0,a0
                        beq .Wait_ExitTask
                        tst.l TC_Userdata(a0)
                        beq .Wait_GoodTask
                        tst.l hard_ResyncNumber(a4)
                        bne .Waiting_Resync
                        move.l hard_LaunchProgress(a4),-(sp)
                        bra .Waiting_NoResync
.Waiting_Resync         tst.l d2
                        beq .No_MustAbort
                        move.l #264,hard_ResyncNumber(a4)
.No_MustAbort           move.l #2,-(sp)
.Waiting_NoResync       move.l hard_ResyncNumber(a4),-(sp)
                        jsr _LVOPermit(a6)
                        move.l (sp)+,d2
                        move.l (sp)+,d1
                        move.l hard_Unit(a4),d0
                        jsr GUI_ChangeHardStatus
                        bra .Wait_For_Done
.Wait_ExitTask          move.l _SysBase(a5),a6
                        jsr _LVOPermit(A6)
                        move.l hard_Status(a4),-(sp)
                        move.l a4,a1
                        jsr _LVOFreeVec(A6)
                        move.l (sp)+,d1
                        bra .Error_Exit
.Wait_GoodTask          move.l _SysBase(a5),a6
                        jsr _LVOPermit(A6)
                        move.l d7,d0
                        asl.l #2,d0
                        lea _HardUnits(a5),a0
                        add.l d0,a0
                        move.l a4,(a0)
                        
                        move.l d7,d0
                        jsr PACK_SendTimeTNC
                
                        
                        exg a4,a5
                        jsr _GUI_LaunchWindowPoll
                        exg a4,a5

                        

                        move.l d7,d0
                        moveq #8,d1
                        moveq #0,d2
                        jsr GUI_ChangeHardStatus
                        sub.l #32,a7
                        move.l a7,a0
                        move.l #"Text",(a0)+
                        move.l #"/TNC",(a0)+
                        move.l #"_Ini",(a0)+
                        move.w #"t/",(a0)+
                        move.l #"TNC0",(a0)+
                        move.l #"_Ini",(a0)+
                        move.l #"t.tx",(a0)+
                        move.b #"t",(A0)+
                        clr.b (a0)+
                        move.l hard_Unit(a4),d0
                        move.l a7,a0
                        jsr PACK_TransmitInitFile
                        move.l a7,a0
                        move.l #"Text",(a0)+
                        move.l #"/TNC",(a0)+
                        move.l #"_Ini",(a0)+
                        move.w #"t/",(a0)+
                        move.l hard_Unit(a4),d0
                        addq.l #1,d0
                        or.l #"TNC0",d0
                        move.l d0,(a0)+
                        move.l #"_Ini",(a0)+
                        move.l #"t.tx",(a0)+
                        move.b #"t",(A0)+
                        clr.b (a0)+
                        move.l hard_Unit(a4),d0
                        move.l a7,a0
                        jsr PACK_TransmitInitFile
                        add.l #32,a7

                        exg a4,a5
                        jsr _GUI_LaunchWindowPoll
                        exg a4,a5

                        move.l a4,a0
                        jsr PACK_WaitForHardUnit
                        
                        move.l d7,d0
                        moveq #9,d1
                        moveq #0,d2
                        jsr GUI_ChangeHardStatus
                        clr.l hard_DontGetData(a4)
                        moveq #0,d7
.Chan_Polly             exg a4,a5
                        jsr _GUI_LaunchWindowPoll
                        exg a4,a5
                        cmp.l hard_MaxChannel(a4),d7
                        bge .Chan_Polly_End
                        lea hard_ChannelNumber(a4),a0
                        lea hard_ChannelAddress(a4),a1
                        move.l d7,d0
                        asl.l #2,d0
                        add.l d0,a0
                        add.l d0,a1
                        move.l (a0),d6
                        move.l (a1),a3
                        cmp.w #1,qso_StartupFlag(A3)
                        bne .No_More_Wait
                        move.l _DOSBase(A5),a6
                        moveq #1,d1
                        jsr _LVODelay(a6)
                        bra .Chan_Polly
.No_More_Wait           move.l qso_ChannelInPackets(a3),a0
                        tst.l (a0)
                        beq .Chan_Polly_Empty
                        move.l qso_ChannelInPackets(a3),a2      
                        move.l a2,a0
                        jsr PACK_AnalizeLinkStatus
                        cmp.l #-1,d0
                        bne .FirstCall_Found
.FirstCall_Loop         move.l (a2),a2
                        tst.l (A2)
                        beq .FirstCall_NotFound
                        move.l a2,a0
                        jsr PACK_AnalizeLinkStatus
                        cmp.l #-1,d0
                        beq .FirstCall_Loop
                        cmp.w #1,d0
                        beq .Set_To_NoCall
.FirstCall_Analizing    move.l d1,d0
                        move.l a2,d1
                        move.l a3,a0
                        jsr PACK_AnalizeLinkPath
                        bra .Verify_CallConnect
                        
.FirstCall_NotFound     lea qso_HardCall(a3),a0
                        lea qso_Call(a3),a1
                        move.l (a0),(a1)
                        move.l 4(a0),4(a1)
                        move.w 8(a0),8(a1)
                        lea qso_HardPath(a3),a0
                        lea qso_Path(a3),a1
                        moveq #79,d0
.FirstCall_NotFound_L   move.b (a0)+,(a1)+
                        dbf d0,.FirstCall_NotFound_L
.Verify_CallConnect     tst.b qso_Call(a3)
                        bne .FirstCall_NotFound_G
.Set_To_NoCall          lea qso_Call(a3),a0
                        move.l #"NOCA",(a0)
                        move.w #"LL",4(a0)
                        clr.w 6(a0)
                        clr.b qso_Path(a3)
.FirstCall_NotFound_G   move.l d6,d0
                        moveq #0,d1
                        moveq #0,d2
                        jsr QSO_DoConnect
                        bra .FirstCall_FoundGood
.FirstCall_Found        tst.l d0
                        beq .FirstCall_FoundGood
                        cmp.w #1,d0
                        beq .FirstCall_FoundGood
                        move.l qso_ChannelInPackets(a3),a2      
                        bra .FirstCall_Analizing
                        
.FirstCall_FoundGood    lea qso_ChannelInPackets(a3),a2
                        move.l 8(a2),a2
.LastCon_SearchBegin    tst.l 4(a2)
                        beq .Chan_Polly_Next
                        move.l a2,a0
                        jsr PACK_AnalizeLinkStatus
                        cmp.l #1,d0
                        beq .LastCon_DoOneBefore
                        cmp.l #4,d0
                        beq .LastCon_DoThis
                        cmp.l #5,d0
                        beq .LastCon_DoThis
                        move.l 4(a2),a2
                        bra .LastCon_SearchBegin
.LastCon_DoOneBefore    move.l 4(a2),a2
                        tst.l 4(a2)
                        beq .Chan_Polly_Next
.LastCon_DoThis         move.l a2,qso_StartupMsg(a3)
.Chan_Polly_Empty       tst.b qso_HardCall(a3)
                        beq .Chan_Polly_Next
                        lea qso_HardCall(a3),a0
                        lea qso_Call(a3),a1
                        move.l (a0),(a1)
                        move.l 4(a0),4(a1)
                        move.w 8(a0),8(a1)
                        lea qso_HardPath(a3),a0
                        lea qso_Path(a3),a1
                        moveq #79,d0
.CPE_L                  move.b (a0)+,(a1)+
                        dbf d0,.CPE_L
                        move.l d6,d0
                        moveq #0,d1
                        moveq #0,d2
                        jsr QSO_DoConnect
.Chan_Polly_Next        clr.w qso_StartupFlag(a3)
                        addq.l #1,d7
                        bra .Chan_Polly
.Chan_Polly_End         move.l hard_Unit(a4),d7
                        move.l d7,d0
                        jsr PACK_GetUnitStatus
                        moveq #0,d0
                        bra .ExitGood

.Exit                   move.l d7,d0
                        jsr PACK_GetUnitStatus
                        moveq #-1,d0
.ExitGood               movem.l (sp)+,d2-d7/a2-a6
                        rts
.Exit_NoTask            move.l _SysBase(a5),a6
                        jsr _LVOPermit(A6)
                        move.l a4,a1
                        jsr _LVOFreeVec(A6)
                        moveq #1,d1
.Error_Exit             move.l d7,d0
                        asl.l #2,d0
                        lea _HardUnitErrors(a5),a0
                        add.l d0,a0
                        move.l d1,(a0)
                        bra .Exit

PACK_DumpMonitor        movem.l d2-d7/a2-a6,-(sp)
                        move.l d1,d7
                        asl.l #2,d1
                        lea _HardUnits(a5),a1
                        add.l d1,a1
                        move.l (a1),a4
                        cmpa.l #0,a4
                        beq .Dump_Error
                        move.l d0,d4
                        move.l a0,a3
                        move.l d4,d0
                        add.l #20,d0
                        move.l #$10001,d1
                        move.l _SysBase(a5),a6
                        jsr _LVOAllocVec(A6)
                        tst.l d0
                        beq .Dump_Error
                        move.l d0,a2
                        move.w #1,14(a2)
                        move.l d4,16(a2)
                        lea 20(A2),a1
                        move.l a3,a0
.Copy_To_Event          tst.l d4
                        ble .Event_Coped
                        move.b (A0)+,(a1)+
                        subq.l #1,d4
                        bra .Copy_To_Event
.Event_Coped            lea hard_MonitorOutPackets(a4),a0
                        move.l a0,-(sp)
                        move.l _SysBase(A5),a6
                        jsr _LVOForbid(A6)
                        move.l (Sp)+,a0
                        move.l a2,a1
                        jsr _LVOAddTail(A6)
                        jsr _LVOPermit(A6)
.Dump_Error             movem.l (Sp)+,d2-d7/a2-a6
                        rts

PACK_GetUnitStatus      movem.l d2-d7/a2-a6,-(sp)
                        move.l d0,d7
                        asl.l #2,d0
                        lea _HardUnits(a5),a0
                        add.l d0,a0
                        move.l (A0),d0
                        tst.l d0
                        beq .Status_NoUnit
                        move.l d0,a0
                        move.l hard_Status(a0),d0
                        tst.l d0
                        bne .Status_Unit
                        tst.l hard_ResyncNeeded(a0)
                        beq .Status_Unit
                        moveq #-2,d0
                        move.l hard_ResyncNumber(a0),d2
                        bra .Status_Unit
.Status_NoUnit          lea _HardUnitErrors(a5),a0
                        move.l d7,d0
                        asl.l #2,d0
                        add.l d0,a0
                        move.l (A0),d0
.Status_Unit            move.l d0,d1
                        addq.l #4,d1
                        move.l d7,d0
                        moveq #0,d2
                        jsr GUI_ChangeHardStatus
                        movem.l (sp)+,d2-d7/a2-a6
                        rts
                        

PACK_LandHardUnit       movem.l d2-d7/a2-a6,-(sp)
                        move.l d0,d7
                        asl.l #2,d0
                        lea _HardUnits(a5),a0
                        add.l d0,a0
                        move.l (A0),d0
                        tst.l d0
                        beq .Exit
                        move.l a0,a4
                        move.l d0,a3
                        
                        move.l #1,hard_DontGetData(a3)
                        
                        move.l a3,a0
                        jsr PACK_WaitForHardUnit
                        tst.l d0
                        bne .Do_Leaving
                        sub.l #100,a7
                        move.l hard_Unit(a3),d0
                        lea _Preferences(a5),a0
                        mulu #devi_Size,d0
                        add.l d0,a0
                        lea devi_GlobalMycall(a0),a0
                        move.l a7,a1
                        move.b #"I",(a1)+
                        move.b #" ",(a1)+
.LEAVE_CopyMyCall       move.b (a0)+,(a1)+
                        tst.b -1(a0)
                        bne .LEAVE_CopyMyCall
                        subq.l #1,a1
                        sub.l a7,a1
                        move.l a1,d0
                        move.l d7,d1
                        move.l a7,a0
                        jsr PACK_DumpMonitor
                        add.l #100,a7
                        sub.l #32,a7
                        move.l a7,a0
                        move.l #"Text",(A0)+
                        move.l #"/TNC",(a0)+
                        move.l #"_Ini",(a0)+
                        move.w #"t/",(a0)+
                        move.l #"TNC0",(a0)+
                        move.l #"_Dei",(a0)+
                        move.l #"nit.",(a0)+
                        move.w #"tx",(A0)+
                        move.b #"t",(a0)+
                        clr.b (a0)+
                        move.l hard_Unit(a3),d0
                        move.l a7,a0
                        jsr PACK_TransmitInitFile
                        move.l a7,a0
                        move.l #"Text",(A0)+
                        move.l #"/TNC",(a0)+
                        move.l #"_Ini",(a0)+
                        move.w #"t/",(a0)+
                        move.l hard_Unit(a3),d0
                        or.l #"TNC0",d0
                        move.l d0,(a0)+
                        move.l #"_Dei",(a0)+
                        move.l #"nit.",(a0)+
                        move.w #"tx",(A0)+
                        move.b #"t",(a0)+
                        clr.b (a0)+
                        move.l hard_Unit(a3),d0
                        move.l a7,a0
                        jsr PACK_TransmitInitFile
                        add.l #32,a7
                        
                        
                        
                        move.l a3,a0
                        jsr PACK_WaitForHardUnit
                        
.Do_Leaving             move.l #1,hard_PleaseLeave(a3)
.Wait_Leave             tst.l hard_Task(A3)
                        beq .Leaved
                        move.l _DOSBase(A5),a6
                        moveq #1,d1
                        jsr _LVODelay(a6)
                        bra .Wait_Leave
.Leaved                 move.l a3,a1
                        move.l _SysBase(a5),a6
                        jsr _LVOFreeVec(A6)
                        clr.l (A4)
.Exit                   movem.l (sp)+,d2-d7/a2-a6
                        rts
                        
PACK_WaitForHardUnit    movem.l d2-d7/a2-a6,-(sp)
                        move.l a0,a4
                        moveq #-1,d7
                        moveq #100,d6
                        moveq #0,d5
.WaitTest_Loop          exg a4,a5
                        jsr _GUI_LaunchWindowPoll
                        exg a4,a5

                        tst.l d5
                        bne .WaitTest_Channel
                        move.l hard_MonitorOutPackets(a4),a0
                        tst.l (a0)
                        beq .WaitTest_NextChannel
                        bra .WaitTest_Alloced
.WaitTest_Channel       cmp.l hard_MaxChannel(a4),d5
                        bgt .Test_Good
                        lea hard_ChannelAddress(a4),a0
                        move.l d5,d0
                        subq.l #1,d0
                        asl.l #2,d0
                        add.l d0,a0
                        move.l (a0),a0
                        move.l qso_ChannelOutPackets(a0),a0
                        tst.l (a0)
                        beq .WaitTest_NextChannel
                        bra .WaitTest_Alloced
.WaitTest_NextChannel   addq.l #1,d5
                        bra .WaitTest_Loop
.WaitTest_Alloced       moveq #10,d1
                        move.l _DOSBase(a5),a6
                        jsr _LVODelay(A6)
                        subq.l #1,d6
                        tst.l d6
                        ble .Exit
                        bra .WaitTest_Loop
                        
.Test_Good              moveq #0,d7                     
.Exit                   move.l d7,d0
                        movem.l (sp)+,d2-d7/a2-a6
                        rts

;>D0 Hardunit
;>A0 Initfilename       

PACK_TransmitInitFile   movem.l d2-d7/a2-a6,-(sp)
                        move.l a0,a4
                        move.l d0,d7
                        asl.l #2,d0
                        lea _HardUnits(a5),a0
                        add.l d0,a0
                        move.l (A0),d0
                        tst.l d0
                        beq .Error
                        move.l d0,a3
                        move.l _DOSBase(a5),a6
                        move.l a4,d1
                        move.l #1005,d2
                        jsr _LVOOpen(a6)
                        tst.l d0
                        beq .Error
                        move.l d0,d6
                        sub.l #256,a7
.Main_Loop              move.l a7,d2
                        move.l d6,d1
                        moveq #120,d3
                        move.l _DOSBase(a5),a6
                        jsr _LVOFGets(a6)
                        tst.l d0
                        beq .File_Done
                        move.l a7,a0
.Cut_0A                 tst.b (a0)+
                        bne .Cut_0A
                        subq.l #2,a0
                        cmp.b #$0a,(a0)
                        bne .NoCut_0A
                        clr.b (a0)
.NoCut_0A               move.l a7,a0
                        tst.b (a0)
                        beq .Main_Loop
                        move.l a7,d1
                        lea 128(a7),a0
                        move.l a0,d2
                        jsr _LVOStrToLong(a6)
                        cmp.l #-1,d0
                        beq .Main_Loop
                        tst.l d0
                        beq .Main_Loop
                        move.l 128(a7),d5
                        tst.l d5
                        blt .Main_Loop
                        cmp.l hard_MaxChannel(a3),d5
                        bgt .Main_Loop
                        move.l a7,a2
                        add.l d0,a2
                        tst.b (a2)
                        beq .Main_Loop
                        cmp.b #" ",(A2)
                        bne .Main_Loop
.Wait_SpaceEnd          tst.b (a2)
                        beq .Main_Loop
                        cmp.b #" ",(a2)
                        bne .Space_Ended
                        addq.l #1,a2
                        bra .Wait_SpaceEnd
.Space_Ended            moveq #0,d4
                        lea 128(a7),a1
.File_PutChar           tst.b (A2)
                        beq .Put_Char_End
                        move.b (a2)+,d0
                        cmp.b #"^",d0
                        bne .Put_Char_Do
                        tst.b (A2)
                        beq .Put_Char_End
                        move.b (a2)+,d0
                        cmp.b #"^",d0
                        beq .Put_Char_Do
                        and.b #$1f,d0
                        bra .Put_Char_Do
.Put_Char_Do            move.b d0,(a1)+
                        addq.l #1,d4
                        bra .File_PutChar
.Put_Char_End           move.l d4,d0
                        add.l #20,d0
                        move.l #$10001,d1
                        move.l _SysBase(a5),a6
                        jsr _LVOAllocVec(A6)
                        tst.l d0
                        beq .Error_2
                        move.l d0,a2
                        move.w #1,14(a2)
                        move.l d4,16(a2)
                        lea 20(A2),a1
                        lea 128(a7),a0
.Copy_To_Event          tst.l d4
                        ble .Event_Coped
                        move.b (A0)+,(a1)+
                        subq.l #1,d4
                        bra .Copy_To_Event
.Event_Coped            lea hard_MonitorOutPackets(a3),a0
                        tst.l d5
                        beq .Coped_Monitor
                        move.l d5,d0
                        subq.l #1,d0
                        asl.l #2,d0
                        lea hard_ChannelAddress(a3),a0
                        add.l d0,a0
                        move.l (a0),a0
                        lea qso_ChannelOutPackets(a0),a0
.Coped_Monitor          move.l a0,-(sp)
                        move.l _SysBase(A5),a6
                        jsr _LVOForbid(A6)
                        move.l (Sp)+,a0
                        move.l a2,a1
                        jsr _LVOAddTail(A6)
                        jsr _LVOPermit(A6)
                        bra .Main_Loop
                        
.File_Done              add.l #256,a7
                        move.l d6,d1
                        move.l _DOSBase(a5),a6
                        jsr _LVOClose(a6)
                        moveq #0,d0
.Exit                   movem.l (sp)+,d2-d7/a2-a6
                        rts
.Error                  moveq #-1,d0
                        bra .Exit
.Error_2                add.l #256,a7
                        move.l d6,d1
                        move.l _DOSBase(a5),a6
                        jsr _LVOClose(a6)
                        moveq #-1,d0
                        bra .Exit
PACK_AnalizeLinkStatusL movem.l d2-d7/a2-a4,-(sp)
                        move.l a0,a3
                        lea Link_Status,a0
                        move.l d0,d7
                        bra PACK_AnalizeLinkStatusC
PACK_AnalizeLinkStatus  movem.l d2-d7/a2-a4,-(sp)
                        move.l a0,a4
                        cmp.w #3,14(a4)
                        bne .Unknown_Link
                        lea Link_Status,a0
                        move.l 16(a4),d7
                        lea 20(a4),a3
                        bra PACK_AnalizeLinkStatusC
.Unknown_Link           moveq #-1,d0
                        moveq #-1,d1
                        movem.l (sp)+,d2-d7/a2-a4
                        rts

PACK_AnalizeLinkStatusC
.Search_Space           tst.l d7
                        beq .Unknown_Link
                        subq.l #1,d7
                        move.b (a3)+,d0
                        cmp.b #" ",d0
                        bne .Search_Space
                        moveq #0,d5
.Loop_1                 move.l a3,a1
                        move.l d7,d6
.Loop_2                 cmp.b #-1,(a0)
                        beq .Unknown_Link
                        tst.b (a0)
                        beq .Link_IsCorrect
                        tst.l d6
                        beq .Next_Link
                        subq.l #1,d6
                        move.b (a1)+,d0
                        cmp.b (a0)+,d0
                        bne .Next_Link
                        bra .Loop_2
.Next_Link              tst.b (a0)+
                        bne .Next_Link
                        addq.l #1,d5
                        bra .Loop_1
.Link_IsCorrect         move.l d5,d0
                        move.l a1,d1
                        movem.l (sp)+,d2-d7/a2-a4
                        rts
.Unknown_Link           moveq #-1,d0
                        moveq #-1,d1
                        movem.l (sp)+,d2-d7/a2-a4
                        rts

;D0 StringStart
;D1 LinkPacket
;A0 QSO-Structure
PACK_AnalizeLinkPath    movem.l d2-d7/a2-a6,-(sp)
                        move.l d1,a1
                        move.l 16(a1),d6
                        lea 20(a1),a1
                        move.l d0,d2
                        sub.l a1,d2
                        sub.l d2,d6
                        move.l d0,a4
                        lea qso_Path(a3),a0
                        moveq #7,d0
.Clear_Path             clr.b (a0)
                        add.l #10,a0
                        dbf d0,.Clear_Path

                        cmp.b #":",1(a4)
                        bne .No_PortI
                        moveq #0,d0
                        move.b (a4),d0
                        sub.b #$30,d0
                        cmp.l #8,d0
                        bgt .No_PortI
                        tst.l d0
                        ble .No_PortI
                        move.l d0,qso_HardwarePort(a3)
                        addq.l #2,a4
.No_PortI               lea qso_Call(a3),a0
                        jsr PACK_StringToCall
                        Tst.l d0
                        bne .String_Error
                        bset #0,d5
                        lea qso_Path(a3),a2
                        moveq #7,d4
                        cmp.l #4,d7
                        blt .No_Via
                        cmp.b #"v",(a4)
                        bne .No_Via
                        cmp.b #"i",1(a4)
                        bne .No_Via
                        cmp.b #"a",2(a4)
                        bne .No_Via
                        cmp.b #" ",3(a4)
                        bne .No_Via
                        addq.l #4,a4
                        subq.l #4,d7
.Via_Skip               tst.l d7
                        beq .No_Via
                        cmp.b #" ",(A4)
                        bne .No_Via
                        addq.l #1,a4
                        subq.l #1,d7
                        bra .Via_Skip
.No_Via                 move.l a2,a0
                        tst.l d7
                        beq .String_Error
                        cmp.b #"-",(a4)
                        beq .String_Error
                        jsr PACK_StringToCall
                        tst.l d0
                        bne .String_Error
                        bset #0,d5
                        lea 10(a2),a2
                        dbf d4,.No_Via
.String_Error           
.Exit                   movem.l (sp)+,d2-d7/a2-a6
                        rts

PACK_UpdateTNCTime      moveq #0,d0
                        jsr PACK_SendTimeTNC
                        moveq #1,d0
                        jsr PACK_SendTimeTNC
                        moveq #2,d0
                        jsr PACK_SendTimeTNC
                        moveq #3,d0
                        jsr PACK_SendTimeTNC
                        moveq #4,d0
                        jsr PACK_SendTimeTNC
                        moveq #5,d0
                        jsr PACK_SendTimeTNC
                        moveq #6,d0
                        jsr PACK_SendTimeTNC
                        moveq #7,d0
                        jsr PACK_SendTimeTNC
                        rts

PACK_SendTimeTNC        movem.l a3/a2/a4/a6,-(sp)
                        asl.l #2,d0
                        lea _HardUnits(a5),a0
                        add.l d0,a0
                        move.l (a0),a4
                        cmpa.l #0,a4
                        beq .No_TNC
                        move.l a4,a0
                        jsr PACK_WaitForHardUnit
                        move.l _DOSBase(A5),a6
                        lea _CurrentDateStamp(a5),a0
                        move.l a0,d1
                        jsr _LVODateStamp(A6)
                        lea _CurrentDateStamp(a5),a0
                        move.l (a0),d0
                        sub.l #14,a7
                        move.l a7,a1
                        move.l a1,-(sp)
                        move.l 8(a0),-(sp)
                        move.l 4(a0),-(sp)
                        move.l #60*24,d1
                        move.l _UtilityBase(a5),a6
                        jsr _LVOUMult32(a6)
                        add.l (sp)+,d0
                        move.l #60,d1
                        jsr _LVOUMult32(a6)
                        move.l (sp)+,d1
                        divu #50,d1
                        ext.l d1
                        add.l d1,d0
                        move.l (sp)+,a0
                        move.l a0,-(sp)
                        jsr _LVOAmiga2Date(a6)
                        move.l (Sp)+,a0
                        move.l a0,a3
                        move.l #10,d0
                        add.l #20,d0
                        move.l #$10001,d1
                        move.l _SysBase(a5),a6
                        jsr _LVOAllocVec(A6)
                        tst.l d0
                        beq .Error_Date
                        move.l d0,a2
                        move.w #1,14(a2)
                        move.l #10,16(a2)
                        move.b #"K",20(A2)
                        move.b #" ",21(A2)
                        moveq #0,d0
                        move.w 4(A3),d0
                        divu #10,d0
                        or.l #$300030,d0
                        move.b d0,22(A2)
                        swap d0
                        move.b d0,23(a2)
                        move.b #":",24(a2)
                        moveq #0,d0
                        move.w 2(A3),d0
                        divu #10,d0
                        or.l #$300030,d0
                        move.b d0,25(A2)
                        swap d0
                        move.b d0,26(a2)
                        move.b #":",27(a2)
                        moveq #0,d0
                        move.w (A3),d0
                        divu #10,d0
                        or.l #$300030,d0
                        move.b d0,28(A2)
                        swap d0
                        move.b d0,29(a2)
                        lea hard_MonitorOutPackets(a4),a0
                        move.l a0,-(sp)
                        move.l _SysBase(A5),a6
                        jsr _LVOForbid(A6)
                        move.l (Sp)+,a0
                        move.l a2,a1
                        jsr _LVOAddTail(A6)
                        jsr _LVOPermit(A6)
                        move.l #10,d0
                        add.l #20,d0
                        move.l #$10001,d1
                        move.l _SysBase(a5),a6
                        jsr _LVOAllocVec(A6)
                        tst.l d0
                        beq .Error_Date
                        move.l d0,a2
                        move.w #1,14(a2)
                        move.l #10,16(a2)
                        move.b #"K",20(A2)
                        move.b #" ",21(A2)
                        moveq #0,d0
                        move.w 6(A3),d0
                        divu #10,d0
                        or.l #$300030,d0
                        move.b d0,22(A2)
                        swap d0
                        move.b d0,23(a2)
                        move.b #".",24(a2)
                        moveq #0,d0
                        move.w 8(A3),d0
                        divu #10,d0
                        or.l #$300030,d0
                        move.b d0,25(A2)
                        swap d0
                        move.b d0,26(a2)
                        move.b #".",27(a2)
                        moveq #0,d0
                        move.w 10(A3),d0
                        divu #100,d0
                        swap d0
                        ext.l d0
                        divu #10,d0
                        or.l #$300030,d0
                        move.b d0,28(A2)
                        swap d0
                        move.b d0,29(a2)
                        lea hard_MonitorOutPackets(a4),a0
                        move.l a0,-(sp)
                        move.l _SysBase(A5),a6
                        jsr _LVOForbid(A6)
                        move.l (Sp)+,a0
                        move.l a2,a1
                        jsr _LVOAddTail(A6)
                        jsr _LVOPermit(A6)
                        
.Error_Date             add.l #14,a7
.No_TNC                 movem.l (Sp)+,a3/a2/a4/a6
                        rts



                        
                        ;SECTION "Packet Interface Process Code Module",code
                        cnop 0,4
PACK_ProcEntryPoint     move.l $4,a6
                        sub.l a1,a1
                        jsr _LVOFindTask(a6)
                        move.l d0,a0
.Wait_UserData          tst.l TC_Userdata(a0)
                        beq .Wait_UserData
                        move.l TC_Userdata(a0),a5
                        move.l a6,hard_ExecBase(a5)
                        

                        lea hard_MonitorInPackets(a5),a0
                        move.l a0,(a0)
                        addq.l #4,(a0)
                        clr.l 4(a0)
                        move.l a0,8(a0)
                        clr.l 12(a0)
                        lea hard_MonitorOutPackets(a5),a0
                        move.l a0,(a0)
                        addq.l #4,(a0)
                        clr.l 4(a0)
                        move.l a0,8(a0)
                        clr.l 12(a0)
                        
                        
                        lea Dos,a1
                        moveq #37,d0
                        move.l hard_ExecBase(a5),a6
                        jsr _LVOOpenLibrary(a6)
                        tst.l d0
                        beq PACK_LeaveProcess
                        move.l d0,hard_DosBase(A5)
                        lea Utility,a1
                        moveq #37,d0
                        move.l hard_ExecBase(a5),a6
                        jsr _LVOOpenLibrary(a6)
                        tst.l d0
                        beq PACK_LeaveProcess
                        move.l d0,hard_UtilityBase(a5)
                        jsr _LVOCreateMsgPort(a6)
                        move.l #1,hard_Status(a5)
                        tst.l d0
                        beq PACK_LeaveProcess
                        clr.l hard_Status(a5)
                        move.l d0,hard_IOPort(a5)
                        move.l d0,a0
                        moveq #IOEXTSER_SIZE,d0
                        jsr _LVOCreateIORequest(a6)
                        move.l #1,hard_Status(a5)
                        tst.l d0
                        beq PACK_LeaveProcess
                        clr.l hard_Status(a5)
                        move.l d0,hard_IORequest(a5)
                        move.l hard_Preferences(A5),a2
                        move.l hard_Unit(a5),d0
                        mulu #devi_Size,d0
                        add.l d0,a2


                        lea devi_ExecDevice(a2),a0
                        move.l devi_ExecUnit(a2),d0
                        move.l devi_ExecFlags(a2),d1
                        move.l hard_IORequest(a5),a1
                        move.l hard_ExecBase(a5),a6
                        jsr _LVOOpenDevice(a6)
                        move.l #1,hard_Status(a5)
                        tst.l d0
                        bne PACK_LeaveProcess
                        clr.l hard_Status(a5)
                        move.l #1,hard_DeviceOpen(A5)
                        move.l hard_IORequest(a5),a1
                        move.l devi_ExecBaud(a2),d0
                        move.l #4096,IO_RBUFLEN(a1)
                        clr.l IO_EXTFLAGS(a1)
                        move.l d0,IO_BAUD(a1)
                        clr.l IO_TERMARRAY(a1)
                        clr.l IO_TERMARRAY+4(a1)
                        move.b #8,IO_READLEN(A1)
                        move.b #8,IO_WRITELEN(a1)
                        move.b #1,IO_STOPBITS(a1)
                        move.b #144,IO_SERFLAGS(a1)
                        clr.b IO_STATUS(a1)
                        move.w #SDCMD_SETPARAMS,IO_COMMAND(a1)
                        move.l hard_ExecBase(a5),a6
                        jsr _LVODoIO(a6)
                        move.l hard_IORequest(a5),a1
                        move.l #2,hard_Status(a5)
                        tst.b IO_ERROR(A1)
                        bne PACK_LeaveProcess
                        clr.l hard_Status(a5)
                        move.l #1,hard_LaunchProgress(a5)
                
                        
                        jsr PACK_Test_HostMode
                        tst.l d0
                        bne .TNC_InHostMode
                        
                        jsr PACK_Set_HostMode
.Redo_StartResync       jsr PACK_Test_HostMode
                        tst.l d0
                        bne .TNC_InHostMode
                        
                        move.l #2,hard_LaunchProgress(a5)
                        move.l #1,hard_ResyncNeeded(A5)
.Res_Loop               move.l hard_DosBase(A5),a6
                        moveq #8,d1
                        jsr _LVODelay(a6)
                        tst.l hard_PleaseLeave(a5)
                        bne PACK_LeaveProcess
                        tst.l hard_Status(a5)
                        bne .CannotSet_HostMode
                        tst.l hard_ResyncNeeded(A5)
                        beq .TNC_InHostMode_Rsnc
                        clr.l hard_BytesInInput(a5)
                        jsr PACK_DoResync
                        bra .Res_Loop
.TNC_InHostMode_Rsnc    moveq #24,d2
.TNC_InHostMode_Rsnc_L  jsr PACK_TestInterface
                        tst.l d0
                        bne .TNC_InHostMode
                        moveq #1,d1
                        move.l hard_DosBase(a5),a6
                        move.l d2,-(sp)
                        jsr _LVODelay(a6)
                        move.l (sp)+,d2
                        dbf d2,.TNC_InHostMode_Rsnc_L                           
                        bra .Redo_StartResync
.CannotSet_HostMode     move.l #3,hard_Status(a5)
                        bra PACK_LeaveProcess
                        
                        
.TNC_InHostMode         move.l #3,hard_LaunchProgress(a5)
                        move.l hard_Preferences(A5),a0
                        move.l hard_Unit(A5),d0
                        mulu #devi_Size,d0
                        lea pref_Devices(a0),a0
                        add.l d0,a0
                        lea devi_GlobalMycall(a0),a0

                        sub.l #20,a7
                        move.l a7,a1
                        move.b #"I",(a1)+
                        move.b #" ",(A1)+
.GlobalI_Copy_Call      tst.b (A0)
                        beq .GlobalI_CopyEnd
                        move.b (a0)+,(a1)+
                        bra .GlobalI_Copy_Call
.GlobalI_CopyEnd        sub.l a7,a1
                        move.l a1,d1
                        move.l a7,a0
                        moveq #0,d0
                        jsr PACK_SendCommand
                        add.l #20,a7
                        tst.l d0
                        bne .Task_Success_Launch
                        
                        move.l hard_Global(a5),a4
                        moveq #0,d7                     ;Maximum Channel
                        moveq #1,d6                     ;Parse Channel
                        move.l _MaxChannel(a4),d5     ;Maximum AbsChannel
                        move.l hard_Unit(A5),d4         ;Hardware Unit
.ChannelTablize_L       cmp.l d5,d6
                        bgt .ChannelTablize_E
                        move.l _QSOs(a4),a0
                        move.l d6,d0
                        subq.l #1,d0
                        mulu #qso_Size,d0
                        add.l d0,a0
                        tst.l qso_SkipChannel(a0)
                        bne .ChannelTablize_Next
                        cmp.l qso_HardwareUnit(a0),d4
                        bne .ChannelTablize_Next
                        move.l qso_HardwareChannel(a0),d0
                        cmp.l d7,d0
                        ble .ChannelTablize_NoMax
                        move.l d0,d7
.ChannelTablize_NoMax   subq.l #1,d0
                        asl.l #2,d0
                        lea hard_ChannelAddress(a5),a1
                        add.l d0,a1
                        move.l a0,(a1)
                        lea hard_ChannelNumber(a5),a1
                        add.l d0,a1
                        move.l d6,(a1)
.ChannelTablize_Next    addq.l #1,d6
                        bra .ChannelTablize_L
.ChannelTablize_E       move.l d7,hard_MaxChannel(a5)
                        sub.l #10,a7
                        move.l a7,a1
                        move.b #"Y",(a1)+
                        move.b #" ",(A1)+
                        move.l hard_MaxChannel(a5),d0
                        divu #10,d0
                        tst.w d0
                        beq .SendY_NotFirstNum
                        or.b #$30,d0
                        move.b d0,(a1)+
.SendY_NotFirstNum      swap d0
                        or.b #$30,d0
                        move.b d0,(a1)+
                        sub.l a7,a1
                        move.l a1,d1
                        move.l a7,a0
                        moveq #0,d0
                        jsr PACK_SendCommand
                        add.l #10,a7
                        tst.l d0
                        bne .Task_Success_Launch
                        
                        cmp.l #-1,hard_MonitorF(a5)
                        beq .LinkParams_Set
                        sub.l #64,a7
                        
                        move.l a7,a2
                        move.b #"F",(a2)+
                        move.b #" ",(a2)+
                        move.l hard_MonitorF(a5),d0
                        move.w #10000,d1
                        jsr .Output_Dezi
                        sub.l a7,a2
                        move.l a2,d1
                        moveq #0,d0
                        move.l a7,a0
                        jsr PACK_SendCommand
                        move.l a7,a2
                        move.b #"N",(a2)+
                        move.b #" ",(a2)+
                        move.l hard_MonitorN(a5),d0
                        move.w #10000,d1
                        jsr .Output_Dezi
                        sub.l a7,a2
                        move.l a2,d1
                        moveq #0,d0
                        move.l a7,a0
                        jsr PACK_SendCommand
                        move.l a7,a2
                        move.b #"O",(a2)+
                        move.b #" ",(a2)+
                        move.l hard_MonitorO(a5),d0
                        move.w #10000,d1
                        jsr .Output_Dezi
                        sub.l a7,a2
                        move.l a2,d1
                        moveq #0,d0
                        move.l a7,a0
                        jsr PACK_SendCommand
                        
                        
                        add.l #64,a7
                        bra .LinkParams_Set
                        
.Output_Dezi            movem.l d2-d7/a6,-(sp)
                        moveq #1,d2
                        move.l d0,d3
                        move.l d1,d4
.Output_Dezi_L          move.l d3,d0
                        move.l d4,d1
                        move.l hard_UtilityBase(a5),a6
                        jsr _LVOUDivMod32(a6)
                        divu #10,d0
                        swap d0
                        ext.l d0
                        move.l d0,d5
                        move.l d1,d3
                        move.l d4,d0
                        moveq #10,d1
                        jsr _LVOUDivMod32(A6)
                        move.l d0,d4
                        move.l d5,d0
                        tst.l d0
                        bne .No_Nil
                        tst.l d2
                        beq .No_Nil
                        tst.l d4
                        beq .No_Nil
                        bra .Nilling
.No_Nil                 moveq #0,d2
                        or.b #$30,d0
                        move.b d0,(a2)+
.Nilling                tst.l d4
                        bne .Output_Dezi_L
                        movem.l (Sp)+,d2-d7/a6
                        rts
                        
.LinkParams_Set 
                        
                        move.l hard_MaxChannel(a5),d7
                        moveq #1,d6
.Poll_Channels          cmp.l d7,d6
                        bgt .Poll_Channels_E
                        sub.l #4,a7
                        move.l a7,a1
                        move.b #"L",(a1)+
                        moveq #1,d1
                        move.l a7,a0
                        move.l d6,d0
                        jsr PACK_SendCommand
                        add.l #4,a7
                        tst.l d0
                        bne .Task_Success_Launch
                        jsr PACK_ProcessLinkStat
                        move.l d6,d0
                        subq.l #1,d0
                        asl.l #2,d0
                        lea hard_ChannelAddress(a5),a0
                        add.l d0,a0
                        move.l (a0),a3
                        clr.w qso_StartupFlag(a3)
                        move.l qso_NotDisplayedLink(a3),d0
                        add.l qso_NotDisplayed(a3),d0
                        tst.l d0
                        beq .No_NeedStartup
                        move.w #1,qso_StartupFlag(a3)
.No_NeedStartup         tst.l qso_LinkStatus(a3)
                        bne .NoPollReset
                        sub.l #20,a7
                        move.l a7,a1
                        move.b #"I",(a1)+
                        move.b #" ",(A1)+
                        lea qso_MyCall(a3),a0
                        moveq #0,d0
                        tst.b (a0)
                        beq .DownLink_UnCall
.DownLink_CallCop       tst.b (a0)
                        beq .DownLink_CallCopE
                        move.b (a0)+,(A1)+      
                        bra .DownLink_CallCop
.DownLink_CallCopE      sub.l a7,a1
                        move.l a1,d1
                        move.l a7,a0
                        move.l d6,d0
                        jsr PACK_SendCommand
.DownLink_UnCall        add.l #20,a7
                        tst.l d0
                        bne .Poll_Channels_L
                        
                        
.NoPollReset    
.Poll_Channels_L        addq.l #1,d6
                        bra .Poll_Channels
.Poll_Channels_E        sub.l #4,a7
                        move.l a7,a1
                        move.b #"G",(a1)+
                        move.l #1,d1
                        move.l a7,a0
                        move.l #255,d0
                        jsr PACK_SendCommand
                        add.l #4,a7
                        tst.l d0
                        bne .Task_Success_Launch
                        lea hard_InputBuffer(a5),a0
                        cmp.b #$ff,(a0)
                        bne .No_ExtendedHostmode
                        cmp.b #$01,1(a0)
                        bne .No_ExtendedHostmode
                        move.l #1,hard_ExtendedHostmode(a5)
                        bra .Hostmode_Tested
.No_ExtendedHostmode    clr.l hard_ExtendedHostmode(a5)
                        move.l #4,hard_LaunchProgress(a5)
                        
.Hostmode_Tested                        
                        
.Task_Success_Launch    tst.l hard_Status(a5)
                        bne PACK_LeaveProcess
                        move.l hard_Task(a5),a0
                        clr.l TC_Userdata(a0)
                        clr.l hard_TimeSlice(a5)
                        clr.l hard_TimeSliceSub(a5)
                        move.l #1,hard_UpdateSlice(a5)
                        clr.l hard_BytesInInput(a5)
                        bra .PACK_Arrived
.Loop                   move.l hard_DosBase(A5),a6
                        moveq #2,d1
                        tst.l hard_ResyncNeeded(A5)
                        beq .No_Need_RS
                        moveq #8,d1
.No_Need_RS             jsr _LVODelay(a6)
                        tst.l hard_PleaseLeave(a5)
                        bne PACK_LeaveProcess
                        tst.l hard_Status(a5)
                        bne .Loop
                        tst.l hard_ResyncNeeded(A5)
                        bne .Loop_Resync
                        tst.l hard_BytesInOutput(a5)
                        beq .No_Need_Interfaceing
                        jsr PACK_TestInterface
                        tst.l d0
                        bne .PACK_Arrived
                        add.l #1,hard_EventTimer(a5)
                        cmp.l #25,hard_EventTimer(A5)
                        blt .No_Need_Interfaceing
                        clr.l hard_EventTimer(a5)
                        move.l #1,hard_ResyncNeeded(a5)
                        clr.l hard_ResyncNumber(a5)
                        bra .Loop_Resync        
.PACK_Arrived           lea PACK_ExtHostModeServer(pc),a0
                        tst.l hard_ExtendedHostmode(a5)
                        bne .PACK_Extended
                        lea PACK_HostModeServer(pc),a0
.PACK_Extended          move.l a0,a1
                        moveq #0,d0
                        move.l hard_TimeSlice(a5),d1
                        asl.l #1,d1
                        add.l d1,a0
                        move.w (a0),d0
                        add.l d0,a1
                        moveq #0,d0
                        tst.l hard_BytesInInput(a5)
                        beq .PACK_BIPEmpty
                        moveq #1,d0
.PACK_BIPEmpty          jsr (a1)
                        clr.l hard_BytesInInput(A5)
                        tst.l d0
                        beq .No_Need_Interfaceing
                        add.l #1,hard_TimeSlice(a5)
                        and.l #$7,hard_TimeSlice(a5)
                        clr.l hard_TimeSliceSub(a5)
                        bra .PACK_Arrived
                        
.No_Need_Interfaceing   
                        bra .Loop
.Loop_Resync            clr.l hard_BytesInInput(a5)
                        jsr PACK_DoResync
                        bra .Loop

PACK_HostModeServer     dc.w PACK_GetActiveChan-PACK_HostModeServer
                        dc.w PACK_PollUpdateChan-PACK_HostModeServer
                        dc.w PACK_PollMonitorChan-PACK_HostModeServer
                        dc.w PACK_GetTNCData-PACK_HostModeServer
                        dc.w PACK_PutTNCData-PACK_HostModeServer
                        dc.w .Nop-PACK_HostModeServer
                        dc.w .Nop-PACK_HostModeServer
                        dc.w .Nop-PACK_HostModeServer
                        
.Nop                    moveq #1,d0
                        rts

PACK_ExtHostModeServer  dc.w PACK_TestExtended-PACK_ExtHostModeServer
                        dc.w PACK_GetActiveChan-PACK_ExtHostModeServer
                        dc.w PACK_PollUpdateChan-PACK_ExtHostModeServer
                        dc.w PACK_GetTNCData-PACK_ExtHostModeServer
                        dc.w PACK_PutTNCData-PACK_ExtHostModeServer
                        dc.w .Nop-PACK_ExtHostModeServer
                        dc.w .Nop-PACK_ExtHostModeServer
                        dc.w .Nop-PACK_ExtHostModeServer
                        
.Nop                    moveq #1,d0
                        rts

PACK_TestExtended       tst.l d0
                        bne .DO_Already
                        sub.l #4,a7
                        move.l a7,a1
                        move.b #"G",(a1)+
                        move.l #$ff,d0
                        moveq #1,d1
                        moveq #1,d2
                        move.l a7,a0
                        jsr PACK_SendEvent
                        add.l #4,a7
                        moveq #0,d0
                        rts
.Exit_NoJob             moveq #1,d0
                        rts
.DO_Already             lea hard_InputBuffer(a5),a0
                        cmp.b #$ff,(a0)
                        bne .Clear_Extended
                        tst.b 1(a0)
                        beq .No_New
                        cmp.b #$1,1(a0)
                        bne .No_New
                        lea 2(a0),a0
.Main_Loop              moveq #0,d0
                        move.b (a0)+,d0
                        tst.l d0
                        beq .No_New
                        subq.l #1,d0
                        tst.l d0
                        beq .New_Monitor
                        blt .Main_Loop
                        cmp.l hard_MaxChannel(a5),d0
                        bgt .Main_Loop
                        subq.l #1,d0
                        asl.l #2,d0
                        lea hard_ChannelAddress(a5),a1
                        add.l d0,a1
                        move.l (a1),a1
                        move.l #1,qso_ChannelUpdate(a1)
                        bra .Main_Loop
.New_Monitor            move.l #1,hard_MonitorUpdate(a5)
                        bra .Main_Loop
                        
                        
.No_New                 moveq #1,d0
                        rts
.Clear_Extended         clr.l hard_ExtendedHostmode(a5)
                        moveq #1,d0
                        rts
PACK_GetActiveChan      tst.l d0
                        bne .DO_Already
                        move.l hard_Global(a5),a0
                        move.l _ActiveChannel(a0),d0
                        tst.l d0
                        ble .Exit_NoJob
                        subq.l #1,d0
                        mulu #qso_Size,d0
                        move.l _QSOs(a0),a0
                        add.l d0,a0
                        move.l qso_HardwareUnit(a0),d0
                        cmp.l hard_Unit(a5),d0
                        bne .Exit_NoJob
                        move.l qso_HardwareChannel(a0),d0
                        sub.l #4,a7
                        move.l a7,a1
                        move.b #"L",(a1)+
                        moveq #1,d1
                        moveq #1,d2
                        move.l a7,a0
                        jsr PACK_SendEvent
                        add.l #4,a7
                        moveq #0,d0
                        rts
.Exit_NoJob             moveq #1,d0
                        rts
.DO_Already             jsr PACK_ProcessLinkStat
                        moveq #1,d0
                        rts

PACK_PollMonitorChan    tst.l d0
                        bne .DO_Already
                        moveq #0,d0
                        sub.l #4,a7
                        move.l a7,a1
                        move.b #"L",(a1)+
                        moveq #1,d1
                        moveq #1,d2
                        move.l a7,a0
                        jsr PACK_SendEvent
                        add.l #4,a7
                        moveq #0,d0
                        rts
.Exit_NoJob             moveq #1,d0
                        rts
.DO_Already             jsr PACK_ProcessLinkStat
                        moveq #1,d0
                        rts

PACK_PollUpdateChan     tst.l d0
                        bne .DO_Already
                        moveq #-1,d1
                        move.l hard_Global(a5),a0
                        move.l _ActiveChannel(a0),d0
                        tst.l d0
                        ble .No_Overjump
                        subq.l #1,d0
                        mulu #qso_Size,d0
                        move.l _QSOs(a0),a0
                        add.l d0,a0
                        move.l qso_HardwareUnit(a0),d0
                        cmp.l hard_Unit(a5),d0
                        bne .No_Overjump
                        move.l qso_HardwareChannel(a0),d0
                        move.l d0,d1
                        
.No_Overjump            move.l hard_UpdateSlice(a5),d0
                        cmp.l d1,d0
                        bne .No_Activi
                        addq.l #1,d0
                        cmp.l hard_MaxChannel(a5),d0
                        ble .No_Activi
                        moveq #1,d0
.No_Activi              move.l d0,d1
                        addq.l #1,d1
                        cmp.l hard_MaxChannel(a5),d1
                        ble .No_Reup
                        moveq #1,d1
.No_Reup                move.l d1,hard_UpdateSlice(a5)
                        sub.l #4,a7
                        move.l a7,a1
                        move.b #"L",(a1)+
                        moveq #1,d1
                        moveq #1,d2
                        move.l a7,a0
                        jsr PACK_SendEvent
                        add.l #4,a7
                        moveq #0,d0
                        rts
.Exit_NoJob             moveq #1,d0
                        rts
.DO_Already             jsr PACK_ProcessLinkStat
                        moveq #0,d0
                        add.l #1,hard_TimeSliceSub(a5)
                        cmp.l #3,hard_TimeSliceSub(a5)
                        blt PACK_PollUpdateChan
                        moveq #1,d0
                        rts
PACK_GetTNCData         tst.l hard_DontGetData(a5)
                        bne .Exit_NoJob
                        tst.l d0
                        bne .DO_Already
                        moveq #0,d0
                        tst.l hard_MonitorUpdate(A5)
                        bne .Do_TNCGetty
                        lea hard_ChannelAddress(A5),a1
                        move.l hard_MaxChannel(A5),d1
                        moveq #1,d0
.Looping_Chans          tst.l d1
                        beq .Exit_NoJob
                        subq.l #1,d1
                        move.l (a1)+,a0
                        tst.l qso_ChannelUpdate(a0)
                        bne .Do_TNCGetty
                        addq.l #1,d0
                        bra .Looping_Chans
                        
                        
.Do_TNCGetty            move.l d0,hard_TNCGetChannel(a5)
                        sub.l #4,a7
                        move.l a7,a1
                        move.b #"G",(a1)+
                        moveq #1,d1
                        moveq #1,d2
                        move.l a7,a0
                        jsr PACK_SendEvent
                        add.l #4,a7
                        moveq #0,d0
                        rts
.Exit_NoJob             moveq #1,d0
                        rts
.DO_Already             lea hard_InputBuffer(a5),a0
                        moveq #0,d0
                        move.b (a0),d0
                        cmp.l hard_TNCGetChannel(a5),d0
                        bne .Blubbered
                        move.b 1(a0),d0
                        tst.b d0
                        beq .Blubber_Channel
                        cmp.b #1,d0
                        beq .Blubber_Channel
                        cmp.b #2,d0
                        beq .Blubber_Channel
                        cmp.b #3,d0
                        beq .Blubber_ASC0
                        cmp.b #4,d0
                        beq .Blubber_ASC0
                        cmp.b #5,d0
                        beq .Blubber_ASC0
                        moveq #0,d1
                        move.b 2(a0),d1
                        addq.l #1,d1
                        lea 3(a0),a0
                        bra .Blubber_BYTES
.Blubber_ASC0           lea 2(a0),a0
                        move.l a0,a1
                        moveq #-1,d1
.Blubber_ASC0L          addq.l #1,d1
                        tst.b (a1)+
                        bne .Blubber_ASC0L
.Blubber_BYTES          move.l a0,a2
                        move.l d0,d2
                        move.l d1,d3
                        moveq #20,d0
                        add.l d3,d0
                        move.l a6,-(sp)
                        move.l hard_ExecBase(a5),a6
                        move.l #$10001,d1
                        jsr _LVOAllocVec(A6)
                        move.l (Sp)+,a6
                        tst.l d0
                        beq .Blubbered
                        move.l d0,a1
                        clr.l (a1)
                        clr.l 4(A1)
                        clr.w 8(A1)
                        clr.l 10(A1)
                        move.w d2,14(a1)
                        move.l d3,16(a1)
                        move.l a2,a0
                        lea 20(a1),a2
.Blubber_Copy           tst.l d3
                        ble .Blubber_Copied
                        subq.l #1,d3
                        move.b (a0)+,(a2)+
                        bra .Blubber_Copy
.Blubber_Copied         move.l a6,-(sp)
                        move.l a1,-(sp)
                        move.l hard_ExecBase(a5),a6
                        jsr _LVOForbid(a6)
                        move.l (sp)+,a1
                        lea hard_MonitorInPackets(a5),a0
                        tst.l hard_TNCGetChannel(A5)
                        beq .Blubber_ToMon
                        move.l hard_TNCGetChannel(a5),d0
                        subq.l #1,d0
                        asl.l #2,d0
                        lea hard_ChannelAddress(a5),a0
                        add.l d0,a0
                        move.l (a0),a0
                        lea qso_ChannelInPackets(a0),a0
.Blubber_ToMon          jsr _LVOAddTail(a6)
                        jsr _LVOPermit(a6)
                        move.l (sp)+,a6
                        tst.l hard_TNCGetChannel(a5)
                        beq .Blubbered
                        lea hard_InputBuffer(a5),a0
                        cmp.b #3,1(a0)
                        bne .Blubbered
                        sub.l #4,a7
                        move.l a7,a1
                        move.b #"L",(a1)+
                        moveq #1,d1
                        move.l a7,a0
                        move.l hard_TNCGetChannel(a5),d0
                        jsr PACK_SendCommand
                        add.l #4,a7
                        tst.l d0
                        bne .Blubbered
                        jsr PACK_ProcessLinkStat
.Blubbered              moveq #0,d0
                        add.l #1,hard_TimeSliceSub(a5)
                        cmp.l #20,hard_TimeSliceSub(a5)
                        blt PACK_GetTNCData
                        moveq #1,d0
                        rts
.Blubber_Channel        tst.l hard_TNCGetChannel(a5)
                        beq .Blubber_Monitor
                        move.l hard_TNCGetChannel(a5),d0
                        subq.l #1,d0
                        asl.l #2,d0
                        lea hard_ChannelAddress(a5),a0
                        add.l d0,a0
                        move.l (a0),a0
                        clr.l qso_ChannelUpdate(a0)
                        cmp.w #1,qso_StartupFlag(a0)
                        bne .Blubbered
                        move.w #2,qso_StartupFlag(a0)
                        bra .Blubbered                          
.Blubber_Monitor        clr.l hard_MonitorUpdate(a5)
                        bra .Blubbered

PACK_PutTNCData         tst.l d0
                        bne .DO_Already
                        moveq #0,d0
                        move.l hard_MonitorOutPackets(a5),a0
                        tst.l (a0)
                        bne .Do_TNCPutty
                        lea hard_ChannelAddress(A5),a1
                        move.l hard_MaxChannel(A5),d1
                        moveq #1,d0
.Looping_Chans          tst.l d1
                        beq .Exit_NoJob
                        subq.l #1,d1
                        move.l (a1)+,a0
                        move.l qso_ChannelOutPackets(a0),a0
.Do_TNCPutty_Ojp        tst.l (a0)
                        bne .Do_TNCPutty_Test
                        addq.l #1,d0
                        bra .Looping_Chans
.Do_TNCPutty_Test       move.l a2,-(sp)
                        move.l d2,-(Sp)
                        move.l -4(a1),a2
                        move.l qso_NotSent(a2),d2
                        add.l qso_Unack(a2),d2
                        cmp.l #14,d2
                        blt .Do_TNCPutty_Gd_2
                        move.l (sp)+,d2
                        cmp.w #1,14(a0)
                        bne .Do_TNCPutty_Ovr
                        cmp.b #"c",20(a0)
                        beq .Do_TNCPutty_Ovr
                        cmp.b #"C",20(a0)
                        beq .Do_TNCPutty_Ovr
                        cmp.b #"d",20(a0)
                        beq .Do_TNCPutty_Ovr
                        cmp.b #"D",20(a0)
                        beq .Do_TNCPutty_Ovr
                        bra .Do_TNCPutty_Gd
.Do_TNCPutty_Ovr        move.l (Sp)+,a2
                        move.l (a0),a0
                        bra .Do_TNCPutty_Ojp
.Do_TNCPutty_Gd_2       move.l (sp)+,d2
.Do_TNCPutty_Gd         move.l (Sp)+,a2
.Do_TNCPutty            move.l d0,hard_TNCGetChannel(a5)
                        move.l a0,hard_TNCPutObject(a5)
                        tst.l d0
                        beq .Do_TNC_Reput
                        cmp.w #1,14(a0)
                        bne .Do_TNC_Reput
                        move.l 16(a0),d0
                        cmp.l #2,d0
                        blt .Do_TNC_Reput
                        lea 20(a0),a0
                        cmp.b #"c",(a0)
                        beq .Do_TNC_IsCQues
                        cmp.b #"C",(a0)
                        bne .Do_TNC_Reput
.Do_TNC_IsCQues         move.b #"C",(a0)
                        subq.l #1,d0
                        addq.l #1,a0
.Do_TNC_TestDummyC      tst.l d0
                        beq .Dummy_C
                        subq.l #1,d0
                        cmp.b #" ",(a0)
                        bne .TNC_Put_Increase
                        addq.l #1,a0
                        bra .Do_TNC_TestDummyC
.Dummy_C                move.l hard_TNCPutObject(a5),a0
                        move.l #1,16(a0)
                        bra .Do_TNC_Reput

.TNC_Put_Increase       move.l hard_TNCGetChannel(a5),d0
                        subq.l #1,d0
                        asl.l #2,d0
                        lea hard_ChannelAddress(A5),a0
                        add.l d0,a0
                        move.l (a0),a0
                        cmp.l #1,qso_LinkStatus(a0)
                        bne .Do_TNC_Reput_NoLinkSR
                        move.w #1,qso_SelfConnect(a0)
                        bra .Do_TNC_Reput_Duad
.Do_TNC_Reput_NoLinkSR  tst.l qso_LinkStatus(a0)
                        bne .Do_TNC_Reput_Duad
                        add.w #1,qso_SelfConnect(a0)
                        cmp.w #1,qso_SelfConnect(a0)
                        beq .Do_TNC_Reput
                        move.l a2,-(sp)
                        move.l a0,a2
                        movem.l d0-d2/a0-a5,-(sp)
                        move.l hard_TNCGetChannel(a5),d7
                        move.l d7,d0
                        subq.l #1,d0
                        asl.l #2,d0
                        lea hard_ChannelNumber(a5),a0
                        add.l d0,a0
                        move.l (a0),d0
                        move.l hard_Global(a5),a4
                        lea _Preferences(a4),a3
                        subq.l #1,d0
                        move.l d0,d2
                        mulu #qso_Size,d0
                        move.l _QSOs(a4),a4
                        add.l d0,a4
                        lea pref_Callsets(a3),a2
                        move.l qso_CallSet(a4),d0
                        mulu #cals_Size,d0
                        add.l d0,a2
                        lea cals_MyCall(a2),a2
                        tst.b (a2)
                        beq .Do_TNC_Reput_TriadSP
                        lea qso_MyCall(A4),a0
                        move.l (a2),(a0)
                        move.l 4(a2),4(a0)
                        move.w 8(a2),8(A0)
                        movem.l (sp)+,d0-d2/a0-a5                       
                        
                        lea qso_MyCall(a2),a0
                        sub.l a1,a1
                        moveq #0,d1
.CI_Look_For_SSID       tst.b (a0)
                        beq .CI_Look_For_SSID_End
                        cmp.b #"-",(a0)
                        beq .CI_SSID_String
                        addq.l #1,a0
                        bra .CI_Look_For_SSID
.CI_SSID_String         addq.l #1,a0
                        move.l a0,a1
                        tst.b (a0)
                        beq .CI_Look_For_SSID_End
                        cmp.b #$30,(a0)
                        blt .CI_Look_For_SSID_End
                        cmp.b #$39,(a0)
                        bgt .CI_Look_For_SSID_End
                        move.b (a0),d0
                        and.l #$f,d0
                        move.l d0,d1
                        tst.b 1(a0)
                        beq .CI_Look_For_SSID_End
                        cmp.b #$30,1(a0)
                        blt .CI_Look_For_SSID_End
                        cmp.b #$39,1(a0)
                        bgt .CI_Look_For_SSID_End
                        move.b 1(a0),d0
                        and.l #$f,d0
                        mulu #10,d1
                        add.l d0,d1
                        tst.b 2(a0)
                        bne .CI_Look_For_SSID_Err
                        cmp.l #15,d1
                        bgt .CI_Look_For_SSID_Err
                        bra .CI_Look_For_SSID_End
.CI_Look_For_SSID_Err   move.w #18,qso_SelfConnect(a2)
                        move.l (sp)+,a2
                        bra .Do_TNC_Reput                       
.CI_Look_For_SSID_End   
.CI_NextDo              moveq #0,d0
                        move.w qso_SelfConnect(a2),d0
                        subq.l #2,d0
                        add.l d1,d0
                        and.l #$f,d0
                        move.l d0,d2
                        divu #10,d0
                        cmpa.l #0,a1
                        bne .CI_SSID_Already_Here
                        lea qso_MyCall(a2),a0
.CI_SSID_Create         tst.b (a0)+
                        bne .CI_SSID_Create
                        subq.l #1,a0
                        move.b #"-",(a0)+
                        move.l a0,a1
.CI_SSID_Already_Here   tst.l d0
                        bne .CI_SSID_IsAny
                        clr.b -1(a1)
                        sub.l a1,a1
                        bra .CI_SSID_IsNothing
                        
.CI_SSID_IsAny          move.l a1,a0
                        tst.b d0
                        beq .CI_SSID_NoHigh
                        or.b #$30,d0
                        move.b d0,(a0)+
.CI_SSID_NoHigh         swap d0
                        or.b #$30,d0
                        move.b d0,(a0)+
                        clr.b (a0)+
.CI_SSID_IsNothing      move.l d1,-(sp)
                        moveq #0,d0
                        move.l hard_TNCPutObject(a5),a0
                        move.l 16(a0),d1
                        lea 20(a0),a0
                        subq.l #2,d1
                        addq.l #2,a0
.CI_Tst_GetOffi         tst.l d1
                        beq .CI_Tst_Ojmp
                        move.b (a0),d0
                        cmp.b #" ",(a0)
                        bne .CI_Tst_Found
                        subq.l #1,d1
                        addq.l #1,a0
                        bra .CI_Tst_GetOffi
.CI_Tst_Found           move.l hard_TNCGetChannel(A5),d0
                        jsr .TSID_Sub
.CI_Tst_Ojmp            move.l (sp)+,d1
                        tst.l d0
                        bne .CI_NextAlloc
.CI_NextAllocAban
                        move.l a2,a0
                        move.l (Sp)+,a2
                        sub.l #20,a7
                        move.l a7,a1
                        move.b #"I",(a1)+
                        move.b #" ",(a1)+
                        lea qso_MyCall(a0),a0
.CI_CopyCall            tst.b (a0)
                        beq .CI_CallCopied
                        move.b (a0)+,(a1)+
                        bra .CI_CopyCall
.CI_CallCopied          sub.l a7,a1
                        move.l a1,d1
                        move.l a7,a0
                        move.l hard_TNCGetChannel(a5),d0
                        jsr PACK_SendCommand
                        add.l #20,a7
.Do_TNC_Reput           move.l hard_TNCGetChannel(A5),d0
                        move.l hard_TNCPutObject(a5),a0
                        moveq #0,d1
                        move.w 14(a0),d1
                        move.l 16(a0),d2
                        lea 20(a0),a0
                        jsr PACK_SendEvent
                        moveq #0,d0
                        rts
.Do_TNC_Reput_TriadSP   movem.l (sp)+,d0-d2/a0-a5                       
                        move.l (sp)+,a2
.Do_TNC_Reput_Triad     move.l hard_TNCGetChannel(a5),d0
                        subq.l #1,d0
                        asl.l #2,d0
                        lea hard_ChannelAddress(A5),a0
                        add.l d0,a0
                        move.l (a0),a0
                        move.w #18,qso_SelfConnect(a0)
                        bra .Do_TNC_Reput
.Do_TNC_Reput_Duad      move.l hard_TNCGetChannel(a5),d0
                        subq.l #1,d0
                        asl.l #2,d0
                        lea hard_ChannelAddress(A5),a0
                        add.l d0,a0
                        move.l (a0),a0
                        move.w #1,qso_SelfConnect(a0)
                        bra .Do_TNC_Reput

.Exit_NoJob             moveq #1,d0
                        rts
.CI_NextAlloc           cmp.w #18,qso_SelfConnect(a2)
                        beq .CI_NextAllocAban
                        add.w #1,qso_SelfConnect(a2)
                        bra .CI_NextDo
.DO_Already             move.l hard_TNCPutObject(a5),a0
                        move.l hard_TNCGetChannel(a5),d0
                        tst.l d0
                        beq .Do_TNC_Alred
                        cmp.w #1,14(a0)
                        bne .Do_TNC_Alred
                        move.l 16(a0),d0
                        cmp.l #2,d0
                        blt .Do_TNC_Alred
                        lea 20(a0),a0
                        cmp.b #"C",(a0)
                        bne .Do_TNC_Alred

                        move.l hard_TNCGetChannel(A5),d0
                        subq.l #1,d0
                        asl.l #2,d0
                        lea hard_ChannelAddress(A5),a0
                        add.l d0,a0
                        move.l (a0),a0
                        cmp.w #18,qso_SelfConnect(a0)
                        bge .Do_TNC_Alred_R
                        lea hard_InputBuffer(a5),a0
                        moveq #0,d0
                        move.b (a0),d0
                        cmp.l hard_TNCGetChannel(A5),d0
                        bne .Exit_NoJob
                        move.b 1(a0),d0
                        cmp.b #1,d0
                        beq .Do_TNC_Alred_R
                        cmp.b #2,d0
                        bne .Do_TNC_Alred
                        lea 2(a0),a0
                        lea Station_Already,a1
.Compare_Already        move.b (a1)+,d0
                        tst.b d0
                        beq .TNC_Put_Increase_Test
                        move.b (a0)+,d1
                        cmp.b d0,d1
                        bne .Do_TNC_Alred_R
                        bra .Compare_Already
.TNC_Put_Increase_Test  move.l hard_TNCGetChannel(A5),d0
                        subq.l #1,d0
                        asl.l #2,d0
                        lea hard_ChannelAddress(A5),a0
                        add.l d0,a0
                        move.l (a0),a0
                        tst.l qso_LinkStatus(a0)
                        beq .TNC_Put_Increase
                        bra .Do_TNC_Alred_R
.Do_TNC_Alred_R         move.l hard_TNCGetChannel(A5),d0
                        subq.l #1,d0
                        asl.l #2,d0
                        lea hard_ChannelAddress(A5),a0
                        add.l d0,a0
                        move.l (a0),a0
                        clr.w qso_SelfConnect(a0)
.Do_TNC_Alred           lea hard_InputBuffer(a5),a0
                        moveq #0,d0
                        move.b (a0),d0
                        cmp.l hard_TNCGetChannel(A5),d0
                        bne .Exit_NoJob
                        move.b 1(a0),d0
                        tst.b d0
                        beq .Blubbered
                        cmp.b #1,d0
                        beq .Blubber_ASC0
                        cmp.b #2,d0
                        beq .Blubber_ASC0
                        bra .Blubbered
.Blubber_ASC0           lea 2(a0),a0
                        move.l a0,a1
                        moveq #-1,d1
.Blubber_ASC0L          addq.l #1,d1
                        tst.b (a1)+
                        bne .Blubber_ASC0L
                        move.l a0,a2
                        move.l d0,d2
                        move.l d1,d3
                        moveq #20,d0
                        add.l d3,d0
                        move.l a6,-(sp)
                        move.l hard_ExecBase(a5),a6
                        move.l #$10001,d1
                        jsr _LVOAllocVec(A6)
                        move.l (Sp)+,a6
                        tst.l d0
                        beq .Blubbered
                        move.l d0,a1
                        clr.l (a1)
                        clr.l 4(A1)
                        clr.w 8(A1)
                        clr.l 10(A1)
                        move.w d2,14(a1)
                        move.l d3,16(a1)
                        move.l a2,a0
                        lea 20(a1),a2
.Blubber_Copy           tst.l d3
                        ble .Blubber_Copied
                        subq.l #1,d3
                        move.b (a0)+,(a2)+
                        bra .Blubber_Copy
.Blubber_Copied         move.l a6,-(sp)
                        move.l a1,-(sp)
                        move.l hard_ExecBase(a5),a6
                        jsr _LVOForbid(a6)
                        move.l (sp)+,a1
                        lea hard_MonitorInPackets(a5),a0
                        tst.l hard_TNCGetChannel(A5)
                        beq .Blubber_ToMon
                        move.l hard_TNCGetChannel(a5),d0
                        subq.l #1,d0
                        asl.l #2,d0
                        lea hard_ChannelAddress(a5),a0
                        add.l d0,a0
                        move.l (a0),a0
                        lea qso_ChannelInPackets(a0),a0
.Blubber_ToMon          jsr _LVOAddTail(a6)
                        jsr _LVOPermit(a6)
                        move.l (sp)+,a6
.Blubbered              move.l hard_TNCGetChannel(a5),d0
                        tst.l d0
                        beq .No_Countup_Mon
                        move.l hard_TNCPutObject(a5),a0
                        cmp.w #1,14(a0)
                        beq .No_Countup_Mon
                        subq.l #1,d0
                        asl.l #2,d0
                        lea hard_ChannelAddress(a5),a0
                        add.l d0,a0
                        move.l (A0),a0
                        add.l #1,qso_NotSent(a0)
                        bset #1,qso_UpdateFlag(a0)
.No_Countup_Mon         move.l a6,-(sp)
                        move.l hard_ExecBase(a5),a6
                        jsr _LVOForbid(a6)
                        move.l hard_TNCPutObject(a5),a1
                        jsr _LVORemove(a6)
                        jsr _LVOPermit(a6)
                        move.l hard_TNCPutObject(a5),a1
                        jsr _LVOFreeVec(a6)
                        move.l (sp)+,a6
                        moveq #0,d0
                        add.l #1,hard_TimeSliceSub(a5)
                        cmp.l #20,hard_TimeSliceSub(a5)
                        blt PACK_PutTNCData
                        moveq #1,d0
                        rts

.TSID_Sub               movem.l d1-d7/a0-a6,-(sp)
                        move.l d0,d7
                        move.l d1,d6
                        move.l a0,d4
                        lea hard_ChannelAddress(a5),a0
                        subq.l #1,d0
                        asl.l #2,d0
                        add.l d0,a0
                        move.l (a0),a3
                        lea hard_ChannelAddress(a5),a4
                        moveq #1,d5
.TSID_Loop              cmp.l hard_MaxChannel(a5),d5
                        bgt .TSID_Good
                        cmp.l d5,d7
                        beq .TSID_Next
                        move.l (a4),a2
                        tst.l qso_LinkStatus(a2)
                        beq .TSID_Next
                        lea qso_MyCall(a2),a0
                        lea qso_MyCall(a3),a1
.TSID_Check_1           move.b (a0)+,d0
                        move.b (a1)+,d1
                        jsr .TSID_Enla
                        cmp.b d1,d0
                        bne .TSID_Next
                        tst.b d0
                        bne .TSID_Check_1
                        lea qso_HardCall(a2),a0
                        move.l d4,a1
                        move.l d6,d2
.TSID_Check_2           move.b (a0)+,d0
                        tst.l d2
                        beq .TSID_MustEnd
                        subq.l #1,d2
                        move.b (a1)+,d1
                        cmp.b #$20,d1
                        beq .TSID_MustEnd
                        jsr .TSID_Enla
                        cmp.b d1,d0
                        bne .TSID_Next
                        bra .TSID_Check_2
.TSID_MustEnd           tst.b d0
                        bne .TSID_Next
                        bra .TSID_Impo
                        
.TSID_Next              add.l #4,a4
                        addq.l #1,d5
                        bra .TSID_Loop                  
.TSID_Good              moveq #0,d0
.TSID_Exit              movem.l (sp)+,d1-d7/a0-a6
                        rts
.TSID_Impo              moveq #-1,d0
                        bra .TSID_Exit                  

.TSID_Enla              cmp.b #$61,d0
                        blt .TSID_NoEnla1
                        cmp.b #$7a,d0
                        bgt .TSID_NoEnla1
                        sub.b #$20,d0
.TSID_NoEnla1           cmp.b #$61,d1
                        blt .TSID_NoEnla2
                        cmp.b #$7a,d1
                        bgt .TSID_NoEnla2
                        sub.b #$20,d1
.TSID_NoEnla2           rts                                     

PACK_ProcessLinkStat    movem.l d2-d7/a2-a6,-(sp)
                        move.l hard_BytesInInput(a5),d6
                        lea hard_InputBuffer(a5),a4
                        moveq #0,d0
                        move.b (a4),d0
                        cmp.l hard_MaxChannel(a5),d0
                        bgt .Exit
                        move.l d0,d7
                        tst.l d0
                        beq .Analize_Monitor
                        cmp.b #1,1(a4)
                        bne .Exit
                        lea 2(a4),a4
                        subq.l #2,d6
                        subq.l #1,d0
                        asl.l #2,d0
                        lea hard_ChannelAddress(a5),a0
                        add.l d0,a0
                        move.l (a0),a3
                        moveq #0,d5                     ;1=QSO-Leiste
                        jsr PACK_StringToInt
                        tst.l d0
                        blt .String_Error
                        move.l d0,qso_NotDisplayedLink(a3)
                        jsr PACK_StringToInt
                        tst.l d0
                        blt .String_Error
                        move.l d0,qso_NotDisplayed(a3)
                        jsr PACK_StringToInt
                        tst.l d0
                        blt .String_Error
                        cmp.l qso_NotSent(a3),d0
                        beq .Good_NotSent
                        bset #1,d5
                        move.l d0,qso_NotSent(a3)
.Good_NotSent           jsr PACK_StringToInt
                        tst.l d0
                        blt .String_Error
                        cmp.l qso_Unack(A3),d0
                        beq .Good_Unack
                        bset #1,d5
                        move.l d0,qso_Unack(A3)
.Good_Unack             jsr PACK_StringToInt
                        tst.l d0
                        blt .String_Error
                        cmp.l qso_Tries(a3),d0
                        beq .Good_Tries
                        bset #1,d5
                        move.l d0,qso_Tries(a3)
.Good_Tries             jsr PACK_StringToInt
                        tst.l d0
                        blt .String_Error
                        cmp.l qso_LinkStatus(a3),d0
                        beq .Good_LinkStatus
                        bset #1,d5
                        tst.l qso_LinkStatus(a3)
                        beq .NL_LinkUp
                        tst.l d0
                        beq .NL_LinkDown
                        bra .NL_LinkKeep
.NL_LinkUp              tst.w qso_SelfConnect(a3)
                        bne .NL_LinkUpSelf
.NL_LinkUpSelf          movem.l d0-d1/a0-a1,-(sp)
                        sub.l #4,a7
                        move.l a7,a1
                        move.b #"C",(a1)+
                        moveq #1,d1
                        move.l a7,a0
                        move.l d7,d0
                        jsr PACK_SendCommand
                        add.l #4,a7
                        tst.l d0
                        bne .NL_LinkKeep_2
                        jsr PACK_ProcessLinkC
                        movem.l (sp)+,d0-d1/a0-a1
                        movem.l d0-d1/a0-a1,-(sp)
                        sub.l #4,a7
                        move.l a7,a1
                        move.b #"I",(a1)+
                        moveq #1,d1
                        move.l a7,a0
                        move.l d7,d0
                        jsr PACK_SendCommand
                        add.l #4,a7
                        tst.l d0
                        bne .NL_LinkKeep_2
                        jsr PACK_ProcessLinkI
                        movem.l (sp)+,d0-d1/a0-a1
                        bra .NL_LinkKeep
.NL_LinkKeep_2          movem.l (Sp)+,d0-d1/a0-a1
                        bra .NL_LinkKeep
.NL_LinkDown            movem.l d0-d2/a0-a5,-(sp)
                        move.l d7,d0
                        subq.l #1,d0
                        asl.l #2,d0
                        lea hard_ChannelNumber(a5),a0
                        add.l d0,a0
                        move.l (a0),d0
                        move.l hard_Global(a5),a5
                        jsr MAIN_HardwareInitChan
                        movem.l (sp)+,d0-d2/a0-a5                       
                        movem.l d0-d1/a0-a1,-(sp)
                        lea qso_MyCall(a3),a0
                        tst.b (a0)
                        beq .NL_LinkKeep_2
                        sub.l #20,a7
                        move.l a7,a1
                        move.b #"I",(a1)+
                        move.b #" ",(A1)+
                        lea qso_MyCall(a3),a0
.DownLink_CallCop       tst.b (a0)
                        beq .DownLink_CallCopE
                        move.b (a0)+,(A1)+      
                        bra .DownLink_CallCop
.DownLink_CallCopE      sub.l a7,a1
                        move.l a1,d1
                        move.l a7,a0
                        move.l d7,d0
                        jsr PACK_SendCommand
                        add.l #20,a7
                        tst.l d0
                        bne .NL_LinkKeep_2
                        
                        bra .NL_LinkKeep_2
                        
.NL_LinkKeep            move.l d0,qso_LinkStatus(a3)
.Good_LinkStatus        
.String_Error           or.b d5,qso_UpdateFlag(a3)
                        move.l qso_NotDisplayed(a3),d0
                        add.l qso_NotDisplayedLink(a3),d0
                        tst.l d0
                        beq .Exit
                        move.l #1,qso_ChannelUpdate(A3)
.Exit                   movem.l (sp)+,d2-d7/a2-a6
                        rts
.Analize_Monitor        clr.l hard_MonitorUpdate(a5)
                        cmp.b #1,1(a4)
                        bne .Exit
                        lea 2(a4),a4
                        subq.l #2,d6
                        moveq #0,d5                     ;Updater
                                                        ;0=C-Leiste
                                                        ;1=QSO-Leiste
                        jsr PACK_StringToInt
                        tst.l d0
                        blt .Exit
                        tst.l d0
                        bne .Do_UppiMonitor
                        jsr PACK_StringToInt
                        tst.l d0
                        blt .Exit
                        tst.l d0
                        bne .Do_UppiMonitor
                        bra .Exit
                        
.Do_UppiMonitor         move.l #1,hard_MonitorUpdate(a5)
                        bra .Exit
PACK_ProcessLinkC       movem.l d2-d7/a2-a6,-(sp)
                        move.l hard_BytesInInput(a5),d6
                        lea hard_InputBuffer(a5),a4
                        moveq #0,d0
                        move.b (a4),d0
                        cmp.l hard_MaxChannel(a5),d0
                        bgt .Exit
                        tst.l d0
                        beq .Exit
                        cmp.b #1,1(a4)
                        bne .Exit
                        lea 2(a4),a4
                        subq.l #2,d6
                        subq.l #1,d0
                        asl.l #2,d0
                        lea hard_ChannelAddress(a5),a0
                        add.l d0,a0
                        move.l (a0),a3
                        lea qso_HardPath(a3),a0
                        moveq #7,d0
.Clear_Path             clr.b (a0)
                        add.l #10,a0
                        dbf d0,.Clear_Path
                        cmp.b #":",1(A4)
                        bne .No_PortI
                        moveq #0,d0
                        move.b (a4),d0
                        sub.b #$30,d0
                        cmp.l #8,d0
                        bgt .No_PortI
                        tst.l d0
                        ble .No_PortI
                        move.l d0,qso_HardwarePort(a3)
                        addq.l #2,a4
.No_PortI               lea qso_HardCall(a3),a0
                        jsr PACK_StringToCall
                        Tst.l d0
                        bne .String_Error
                        bset #0,d5
                        lea qso_HardPath(a3),a2
                        moveq #7,d4
                        cmp.l #4,d7
                        blt .No_Via
                        cmp.b #"v",(a4)
                        bne .No_Via
                        cmp.b #"i",1(a4)
                        bne .No_Via
                        cmp.b #"a",2(a4)
                        bne .No_Via
                        cmp.b #" ",3(a4)
                        bne .No_Via
                        addq.l #4,a4
                        subq.l #4,d7
.Via_Skip               tst.l d7
                        beq .No_Via
                        cmp.b #" ",(A4)
                        bne .No_Via
                        addq.l #1,a4
                        subq.l #1,d7
                        bra .Via_Skip
.No_Via                 move.l a2,a0
                        jsr PACK_StringToCall
                        tst.l d0
                        bne .String_Error
                        bset #0,d5
                        lea 10(a2),a2
                        dbf d4,.No_Via
.String_Error           
.Exit                   movem.l (sp)+,d2-d7/a2-a6
                        rts

PACK_ProcessLinkI       movem.l d2-d7/a2-a6,-(sp)
                        move.l hard_BytesInInput(a5),d6
                        lea hard_InputBuffer(a5),a4
                        moveq #0,d0
                        move.b (a4),d0
                        cmp.l hard_MaxChannel(a5),d0
                        bgt .Exit
                        tst.l d0
                        beq .Exit
                        cmp.b #1,1(a4)
                        bne .Exit
                        lea 2(a4),a4
                        subq.l #2,d6
                        subq.l #1,d0
                        asl.l #2,d0
                        lea hard_ChannelAddress(a5),a0
                        add.l d0,a0
                        move.l (a0),a3
                        moveq #0,d5                     ;Updater
                                                        ;0=C-Leiste
                                                        ;1=QSO-Leiste
                        lea qso_MyCall(a3),a0
                        jsr PACK_StringToCall
                        Tst.l d0
                        bne .String_Error
                        bset #0,d5
                        
.String_Error           or.b d5,qso_UpdateFlag(a3)
.Exit                   movem.l (sp)+,d2-d7/a2-a6
                        rts


                        
;********************************ATTENTION! SPECIAL ROUTINE*****************

PACK_StringToInt        moveq #0,d0
.Loop                   tst.l d6
                        beq .Bad_String
                        move.b (a4)+,d1
                        subq.l #1,d6
                        tst.b d1
                        beq .Good_String_SP
                        cmp.b #$20,d1
                        beq .Good_String_SP
                        cmp.b #$30,d1
                        blt .Bad_String
                        cmp.b #$39,d1
                        bgt .Bad_String
                        and.b #$f,d1
                        mulu #10,d0
                        add.l d1,d0
                        cmp.l #65536*256,d0
                        bgt .Bad_String
                        bra .Loop
.Good_String_SP         tst.l d6
                        beq .Good_String
                        cmp.b #$20,(a4)
                        bne .Good_String
                        addq.l #1,a4
                        bra .Good_String_SP
.Good_String            rts
                        
.Bad_String             moveq #-1,d0
                        rts

;********************************ATTENTION! SPECIAL ROUTINE*****************

PACK_StringToCall       moveq #0,d0
.Loop                   tst.l d6
                        beq .Good_String
                        move.b (a4)+,d1
                        subq.l #1,d6
                        tst.b d1
                        beq .Good_String_SP
                        cmp.b #$20,d1
                        beq .Good_String_SP
                        move.b d1,(a0)+
                        bra .Loop
.Good_String_SP         tst.l d6
                        beq .Good_String
                        cmp.b #$20,(a4)
                        bne .Good_String
                        addq.l #1,a4
                        bra .Good_String_SP
.Good_String            clr.b (A0)
                        rts
                        
.Bad_String             moveq #-1,d0
                        rts
                        

PACK_SendData           move.l d2,-(sp)
                        move.l d1,d2
                        moveq #0,d1
                        jsr PACK_SendEvent
                        move.l (Sp)+,d2
                        jsr PACK_WaitEvent
                        rts
PACK_SendCommand        move.l d2,-(Sp)
                        move.l d1,d2
                        moveq #1,d1
                        jsr PACK_SendEvent
                        move.l (Sp)+,d2
                        jsr PACK_WaitEvent
                        rts

PACK_WaitEvent          move.l a6,-(Sp)
                        tst.l hard_BytesInOutput(a5)
                        beq .Exit
.Loop                   move.l hard_DosBase(A5),a6
                        moveq #2,d1
                        tst.l hard_ResyncNeeded(A5)
                        beq .No_Need_RS
                        moveq #8,d1
.No_Need_RS             jsr _LVODelay(a6)
                        tst.l hard_Status(a5)
                        bne .Exit
                        tst.l hard_ResyncNeeded(A5)
                        bne .Loop_Resync
                        tst.l hard_BytesInOutput(a5)
                        beq .Exit
                        jsr PACK_TestInterface
                        tst.l d0
                        bne .PACK_Arrived
                        add.l #1,hard_EventTimer(a5)
                        cmp.l #25,hard_EventTimer(A5)
                        blt .No_Need_Interfaceing
                        clr.l hard_EventTimer(a5)
                        move.l #1,hard_ResyncNeeded(a5)
                        clr.l hard_ResyncNumber(a5)
                        bra .Loop_Resync        
.PACK_Arrived           move.l (sp)+,a6
                        moveq #0,d0
                        rts
                        
.No_Need_Interfaceing   
                        bra .Loop
.Loop_Resync            clr.l hard_BytesInInput(a5)
                        jsr PACK_DoResync
                        bra .Loop
                        
.Exit                   move.l (Sp)+,a6
                        moveq #-1,d0
                        rts
                        

PACK_SendEvent          tst.l d2
                        beq .Exit
                        tst.l hard_Status(a5)
                        bne .Exit
                        lea hard_OutputBuffer(a5),a1
                        move.b d0,(a1)
                        move.b d1,1(a1)
                        move.b d2,2(a1)
                        sub.b #1,2(a1)
                        lea 3(a1),a1
                        move.l d2,d0
.Loop                   tst.l d0
                        beq .Loop_End
                        subq.l #1,d0
                        move.b (A0)+,(a1)+
                        bra .Loop
.Loop_End               addq.l #3,d2
                        move.l d2,d0
                        jsr PACK_SendBytesToTNC
.Exit                   rts
                        



PACK_DoResync           move.l hard_BytesInOutput(a5),-(sp)
                        jsr PACK_TestInterface
                        move.l (sp)+,d1
                        move.l d1,hard_BytesInOutput(a5)
                        tst.l d0
                        beq .Resync_NextByte
.Resync_Giveup          sub.l #264,a7
                        lea hard_OutputBuffer(a5),a0
                        move.l a7,a1
                        moveq #65,d0
.Copy_Output            move.l (A0)+,(a1)+
                        dbf d0,.Copy_Output
                        move.l hard_BytesInOutput(a5),-(sp)
                        jsr PACK_Test_HostMode
                        tst.l d0
                        bne .Is_Hosty
                        jsr PACK_Set_HostMode
                        jsr PACK_Test_HostMode
                        tst.l d0
                        bne .Is_Hosty
                        move.l #3,hard_Status(A5)
                        clr.l hard_ResyncNumber(A5)
                        clr.l hard_ResyncNeeded(a5)
                        bra .Galaga_Back
.Resync_NextByte        cmp.l #264,hard_ResyncNumber(a5)
                        bge .Resync_Giveup
                        sub.l #4,a7
                        move.l a7,a0
                        move.b #1,(A0)
                        move.l hard_IORequest(a5),a1
                        move.w #CMD_WRITE,IO_COMMAND(a1)
                        move.l a0,IO_DATA(a1)
                        move.l #1,IO_LENGTH(a1)
                        move.l a6,-(sp)
                        move.l hard_ExecBase(A5),a6
                        jsr _LVODoIO(a6)
                        move.l (Sp)+,a6
                        add.l #4,a7
                        add.l #1,hard_ResyncNumber(a5)
                        rts
                        
.Is_Hosty               clr.l hard_ResyncNeeded(A5)
                        clr.l hard_ResyncNumber(A5)
                        clr.l hard_Status(A5)
                        bra .Galaga_Back
                        
.Galaga_Back            move.l (Sp)+,d1
                        move.l d1,hard_BytesInOutput(a5)
                        move.l a7,a0
                        lea hard_OutputBuffer(a5),a1
                        moveq #65,d1
.Copy_Output_2          move.l (a0)+,(a1)+
                        dbf d1,.Copy_Output_2
                        add.l #264,a7
                        tst.l hard_BytesInOutput(a5)
                        beq .No_Resend
                        move.l hard_BytesInOutput(A5),d0
                        jsr PACK_SendBytesToTNC
.No_Resend              rts
                        
                        

PACK_SendBytesToTNC     move.l d0,hard_BytesInOutput(a5)
                        clr.l hard_BytesInInput(a5)
                        lea hard_OutputBuffer(a5),a0
                        move.l hard_IORequest(a5),a1
                        move.l a0,IO_DATA(a1)
                        move.l d0,IO_LENGTH(a1)
                        move.w #CMD_WRITE,IO_COMMAND(a1)
                        move.l a6,-(Sp)
                        move.l hard_ExecBase(a5),a6
                        jsr _LVODoIO(A6)
                        move.l (Sp)+,a6
                        clr.l hard_EventTimer(a5)
                        rts
                        
PACK_Test_HostMode      jsr PACK_ClearInterface
                        lea hard_OutputBuffer(a5),a0
                        move.b #1,(a0)
                        move.b #1,1(a0)
                        move.b #1,2(a0)
                        move.b #1,3(a0)
                        move.b #1,4(a0)
                        moveq #5,d0
                        jsr PACK_SendBytesToTNC
                        moveq #24,d2
.Wait_Test_Host         jsr PACK_TestInterface
                        tst.l d0
                        bne .Test_Host_Got
                        moveq #1,d1
                        move.l hard_DosBase(a5),a6
                        move.l d2,-(sp)
                        jsr _LVODelay(a6)
                        move.l (sp)+,d2
                        dbf d2,.Wait_Test_Host
.No_Hostmode            moveq #0,d0
                        rts
.Test_Host_Got          lea hard_InputBuffer(a5),a0
                        cmp.b #1,(a0)
                        bne .No_Hostmode
                        cmp.b #2,1(a0)
                        bne .No_Hostmode
                        moveq #1,d0
                        rts
                        
PACK_Set_HostMode       jsr PACK_ClearInterface
                        lea hard_OutputBuffer(a5),a0
                        move.b #17,(a0)
                        move.b #21,1(a0)
                        move.b #27,2(a0)
                        move.b #"J",3(a0)
                        move.b #"H",4(a0)
                        move.b #"O",5(a0)
                        move.b #"S",6(a0)
                        move.b #"T",7(a0)
                        move.b #"1",8(a0)
                        move.b #$d,9(a0)
                        moveq #10,d0
                        jsr PACK_SendBytesToTNC
                        moveq #15,d1
                        move.l hard_DosBase(a5),a6
                        jsr _LVODelay(A6)
                        jsr PACK_ClearInterface
                        rts


PACK_ClearInterface     move.l a6,-(sp)
                        moveq #4,d1
                        move.l hard_DosBase(a5),a6
                        jsr _LVODelay(a6)
                        move.l (sp)+,a6
                        clr.l hard_BytesInOutput(A5)
                        clr.l hard_BytesInInput(a5)
                        jsr PACK_TestInterface
                        tst.l hard_BytesInInput(a5)
                        bne PACK_ClearInterface
                        rts

PACK_TestInterface      move.l hard_IORequest(a5),a1
                        move.w #SDCMD_QUERY,IO_COMMAND(a1)
                        move.l a6,-(Sp)
                        move.l hard_ExecBase(a5),a6
                        jsr _LVODoIO(a6)
                        move.l (Sp)+,a6
                        move.l hard_IORequest(a5),a1
                        tst.b IO_ERROR(a1)
                        bne .Error_Interface
                        move.l IO_ACTUAL(a1),d0
                        tst.l d0
                        beq .Interface_Empty
                        move.l #264,d1
                        sub.l hard_BytesInInput(a5),d1
                        cmp.l d1,d0
                        ble .Packet_Good
                        move.l d1,d0
.Packet_Good            move.l d0,IO_LENGTH(a1)
                        lea hard_InputBuffer(a5),a0
                        add.l hard_BytesInInput(a5),a0
                        move.l a0,IO_DATA(a1)
                        move.w #CMD_READ,IO_COMMAND(A1)
                        move.l a6,-(sp)
                        move.l hard_ExecBase(A5),a6
                        jsr _LVODoIO(a6)
                        move.l (sp)+,a6
                        move.l hard_IORequest(a5),a1
                        tst.b IO_ERROR(a1)
                        bne .Error_Interface
                        move.l IO_ACTUAL(a1),d0
                        move.l hard_BytesInInput(a5),d1
                        add.l d0,d1
                        move.l d1,hard_BytesInInput(A5)
.Error_Interface        
.Interface_Empty        tst.l hard_BytesInOutput(a5)
                        beq .Buffer_Empty
                        tst.l hard_BytesInInput(A5)
                        beq .Buffer_Empty 
                        cmp.l #2,hard_BytesInInput(a5)
                        blt .Buffer_Empty
                        move.l hard_BytesInInput(a5),d0
                        subq.l #2,d0
                        lea hard_InputBuffer(a5),a0
                        moveq #0,d1
                        move.b 1(a0),d1
                        lea 2(a0),a0
                        tst.b d1
                        beq .TNC_Empt
                        cmp.b #1,d1
                        beq .TNC_ASCII0
                        cmp.b #2,d1
                        beq .TNC_ASCII0
                        cmp.b #3,d1
                        beq .TNC_ASCII0
                        cmp.b #4,d1
                        beq .TNC_ASCII0
                        cmp.b #5,d1
                        beq .TNC_ASCII0
                        cmp.b #6,d1
                        beq .TNC_Length
                        cmp.b #7,d1
                        beq .TNC_Length
.TNC_Error              clr.l hard_BytesInInput(a5)
                        bra PACK_TestInterface
.TNC_Empt               tst.l d0
                        bne .TNC_Error
                        bra .TNC_Done
.TNC_ASCII0             tst.l d0
                        beq .Buffer_Empty
                        move.b (a0)+,d1
                        subq.l #1,d0
                        tst.b d1
                        bne .TNC_ASCII0
                        tst.l d0
                        bne .TNC_Error
                        bra .TNC_Done
.TNC_Length             tst.l d0
                        beq .Buffer_Empty
                        moveq #0,d1
                        move.b (a0)+,d1
                        subq.l #1,d0
                        addq.l #1,d1
                        cmp.l d1,d0
                        blt .Buffer_Empty
                        beq .TNC_Done
                        bra .TNC_Error
.Buffer_Empty           moveq #0,d0
                        rts
.TNC_Done               clr.l hard_BytesInOutput(a5)
                        moveq #1,d0
                        rts                     
                        
PACK_LeaveProcess       tst.l hard_DeviceOpen(a5)
                        beq .No_SetTerminalMode
                        
                        jsr PACK_ClearInterface
                        lea hard_OutputBuffer(a5),a0
                        clr.b (a0)
                        move.b #1,1(a0)
                        move.b #5,2(a0)
                        move.b #"J",3(a0)
                        move.b #"H",4(a0)
                        move.b #"O",5(a0)
                        move.b #"S",6(a0)
                        move.b #"T",7(a0)
                        move.b #"0",8(a0)
                        moveq #9,d0
                        jsr PACK_SendBytesToTNC
                        move.l hard_DosBase(a5),a6
                        moveq #10,d1
                        jsr _LVODelay(a6)
                        jsr PACK_ClearInterface
.No_SetTerminalMode     tst.l hard_DeviceOpen(a5)
                        beq .No_DeviceOpen
                        clr.l hard_DeviceOpen(A5)
                        move.l hard_IORequest(a5),a1
                        move.l hard_ExecBase(a5),a6
                        jsr _LVOCloseDevice(A6)
.No_DeviceOpen          tst.l hard_IORequest(a5)
                        beq .No_IORequest
                        move.l hard_IORequest(a5),a0
                        clr.l hard_IORequest(a5)
                        move.l hard_ExecBase(A5),a6
                        jsr _LVODeleteIORequest(a6)
.No_IORequest           tst.l hard_IOPort(a5)
                        beq .No_IOPort
                        move.l hard_IOPort(a5),a0
                        clr.l hard_IOPort(a5)
                        move.l hard_ExecBase(A5),a6
                        jsr _LVODeleteMsgPort(a6)
.No_IOPort              tst.l hard_DosBase(a5)
                        beq .No_Dos
                        move.l hard_DosBase(a5),a1
                        clr.l hard_DosBase(a5)
                        move.l hard_ExecBase(a5),a6
                        jsr _LVOCloseLibrary(a6)
.No_Dos                 move.l hard_ExecBase(a5),a6
                        jsr _LVOForbid(A6)
                        lea hard_MonitorInPackets(a5),a0
                        jsr .Free_AllPacks
                        lea hard_MonitorOutPackets(a5),a0
                        jsr .Free_AllPacks
                        clr.l hard_Task(a5)
                        rts
.Free_AllPacks          move.l a0,a4
.Free_AllPackLoop       move.l (a4),a3
                        tst.l (a3)
                        beq .Free_AllPackEnd
                        move.l a3,a1
                        move.l hard_ExecBase(a5),a6
                        jsr _LVORemove(A6)
                        move.l a3,a1
                        jsr _LVOFreeVec(A6)
                        bra .Free_AllPackLoop
.Free_AllPackEnd        rts




                        ;SECTION "Packet Interface Data Module",data
Process_Name            dc.b "TNC Hardware Server",0
Dos                     dc.b "dos.library",0
Utility                 dc.b "utility.library",0
Station_Already         dc.b "STATION ALREADY CONNECTED",0
Link_Status             dc.b "BUSY fm ",0                       ;0
                        dc.b "CONNECTED to ",0                  ;1
                        dc.b "LINK RESET fm ",0                 ;2
                        dc.b "LINK RESET to ",0                 ;3
                        dc.b "DISCONNECTED fm ",0               ;4
                        dc.b "LINK FAILURE with ",0             ;5
                        dc.b "CONNECT REQUEST fm ",0            ;6
                        dc.b "FRAME REJECT fm ",0               ;7
                        dc.b "FRAME REJECT to ",0               ;8
                        dc.b -1,0
                even
                        

                        rsreset
hard_Task               rs.l 1          ;Zeiger auf dazugehörenden Hardwaretask
hard_Global             rs.l 1          ;Zeiger auf ProfiPacket Global-Array
hard_Unit               rs.l 1          ;Nummer des Hard-Units
hard_Preferences        rs.l 1          ;Zeiger auf die Preferences-Struktur
hard_PleaseLeave        rs.l 1          ;Flag : 0 = Normalbetrieb 1=Server beenden
hard_IORequest          rs.l 1          ;Zeiger auf IORequest-Struktur
hard_IOPort             rs.l 1          ;Zeiger auf IOPort-Struktur
hard_ExecBase           rs.l 1          ;Zeiger auf exec.library
hard_DosBase            rs.l 1          ;Zeiger auf dos.library
hard_UtilityBase        rs.l 1          ;Zeiger auf utility.library
hard_DeviceOpen         rs.l 1          ;Flag : 1 = Device ist geöffnet
hard_InputBuffer        rs.b 264        ;Input-Buffer für TNC-Reply
hard_BytesInInput       rs.l 1          ;Zahl der Bytes im Input-Buffer
hard_OutputBuffer       rs.b 264        ;Output-Buffer für TNC-Befehl
hard_BytesInOutput      rs.l 1          ;Zahl der Bytes im Output-Buffer
hard_Status             rs.l 1          ;0= Idle
                                        ;1= Cannot open device
                                        ;2= Cannot set parameters
                                        ;3= Cannot set TNC to hostmode /SyncError

hard_ResyncNeeded       rs.l 1          ;Flag : 1 = TNC benötigt Resync
hard_ResyncNumber       rs.l 1          ;Nummer des Resyncversuches
hard_EventTimer         rs.l 1          ;Timer für Event-Timeout
hard_ChannelAddress     rs.l 40         ;Zeiger auf die Kanaladressen
hard_ChannelNumber      rs.l 40         ;Zeiger auf die Kanalnummern
hard_MaxChannel         rs.l 1          ;Nummer der höchsten Kanals
hard_ExtendedHostmode   rs.l 1          ;Extended Hostmode ist verfügbar
hard_TimeSlice          rs.l 1          ;Position auf der Zeitscheibe
hard_TimeSliceSub       rs.l 1          ;Unterposition auf der Zeitscheibe
hard_UpdateSlice        rs.l 1          ;Speicher für aktuellen Updatechannel
hard_MonitorInPackets   rs.b 16         ;Liste für Monitor-Input-Packets
hard_MonitorOutPackets  rs.b 16         ;Liste für Monitor-Output-Packets
hard_MonitorUpdate      rs.l 1          ;Monitor trägt neue Daten
hard_TNCGetChannel      rs.l 1          ;Kanal von dem TNC Info bezieht
hard_TNCPutObject       rs.l 1          ;Object das dem TNC gesendet wird
hard_DontGetData        rs.l 1          ;Flag: Keine Daten vom TNC abholen
hard_LaunchProgress     rs.l 1          ;Fortschritt des TNC Startups
                                        ;0 = Initalize Interface
                                        ;1 = Set TNC to Hostmode
                                        ;2 = Resyncing
                                        ;3 = Initalizing TNC
                                        ;4 = TNC Initalized
hard_MonitorF           rs.l 1          ;Frackzeit Monitor
hard_MonitorN           rs.l 1          ;Versuche Monitor
hard_MonitorO           rs.l 1          ;MaxFrame Monitor
hard_Size               rs.b 0

        
