        opt      l-
        SECTION  XPRZterm,CODE
        incdir   "include/"             ;OMA
        include  "exec/exec_lib.i"      ;Mr.Geller in 1990.
        include  "intuition/intuition.i"
        include  "intuition/intuition_lib.i"
        include  "libraries/dos_lib.i"
        include  "libraries/dosextens.i"
        include  "devices/serial.i"
        include  "devices/timer.i"
        include  "graphics/graphics_lib.i"
        include  "graphics/text.i"

;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
* startup.i      zum start von der WB.
        movem.l  d0/a0,-(sp)            ;rette Kommandozeile
        clr.l    _WBenchMsg             ;sicherheitshalber
        sub.l    a1,a1                  ;a1=0 = eigener Task
        CALLEXEC FindTask               ;wo sind wir?
        move.l   d0,a4                  ;Adresse retten
        tst.l    pr_CLI(a4)             ;Laufen wir unter WB?
        beq.s    fromWB                 ;wenn so
        movem.l  (sp)+,d0/a0            ;Parms Kommandozeile holen
        bra      run                    ;und starten
fromWB  lea      pr_MsgPort(a4),a0
        CALLEXEC WaitPort               ;Warte auf Start-Message
        lea      pr_MsgPort(a4),a0      ;sie ist da
        CALLEXEC GetMsg                 ;hole sie
        move.l   d0,_WBenchMsg          ;immer Msg sichern!
        movem.l  (sp)+,d0/a0            ;bringe Stack i.O.
run     bsr.s    _main                  ;rufe unser Programm auf
        move.l   d0,-(sp)               ;rette seinen Return-Code
        tst.l    _WBenchMsg             ;gibt's eine WB-Message
        beq.s    _exit                  ;nein: dann war's CLI
        CALLEXEC Forbid                 ;keine Unterbrechung jetzt
        move.l   _WBenchMsg(pc),a1      ;hole die Message
        CALLEXEC ReplyMsg               ;und gib sie zurueck
_exit   move.l   (sp)+,d0               ;hole Return-Code
        rts                             ;das war's
_WBenchMsg       ds.l        1
        cnop     0,2
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

PRINT	macro		          ;Macro zur Ausgabe eines Textes
	   move	     #\1,d0
	   move	     #\2,d1	
	   move.l     UDwindowptr,a1
	   move.l     wd_RPort(a1),a1
	   CALLGRAF   Move		
	   move	     #\3,d0	
	   move.l	  UDwindowptr,a1
	   move.l	  wd_RPort(a1),a1
	   CALLGRAF   SetAPen
	   lea	     \4,a0	
	   move.l	  #\5,d0	
	   move.l	  UDwindowptr,a1		
	   move.l	  wd_RPort(a1),a1	
	   CALLGRAF   Text
	   endm


;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
_main

;----------------------------------LIBS OEFFNEN

        moveq    #0,d0
        lea      int_name(pc),a1
        CALLEXEC OpenLibrary
        tst.l    d0
        beq      EXIT
        lea      _IntuitionBase(pc),a0
        move.l   d0,(a0)

        moveq    #0,d0
        lea      dos_name(pc),a1
        CALLEXEC OpenLibrary
        tst.l    d0
        beq      ClInt
        lea      _DOSBase(pc),a0
        move.l   d0,(a0)

        moveq    #0,d0
        lea      graf_name(pc),a1
        CALLEXEC OpenLibrary
        tst.l    d0
        beq      ClDos
        lea      _GfxBase(pc),a0
        move.l   d0,(a0)

        moveq    #0,d0
        lea      xpr_name(pc),a1
        CALLEXEC OpenLibrary
        tst.l    d0
        beq      ClGraf
        lea      _XPRBase(pc),a0
        move.l   d0,(a0)

;----------------------------------DEVICES OEFFNEN

        sub.l    a1,a1             ;Replyport einrichten
        CALLEXEC FindTask          ;eigenen Task eintragen
        lea      SerReply,a1
        move.l   d0,MP_SIGTASK(a1) 
        CALLEXEC AddPort           ;reply (message-)port einrichten
        lea      SerIO,a1          ;IOExtSer Struktur
        clr.l    d0         
        clr.l    d1
        move.b   #$B4,IO_SERFLAGS(a1) ;set radboogie,7wire,(shared=b4)
        lea      ser_name,a0          ;exclusive = $94
        CALLEXEC OpenDevice
        tst.l    d0
        bne      ClXpr
        lea      SerIO,a1             ;replyport eintragen
        move.l   #SerReply,MN_REPLYPORT(a1)

;-------
        sub.l    a1,a1
        CALLEXEC FindTask
        lea      TimeReply,a1
        move.l   d0,MP_SIGTASK(a1)
        CALLEXEC AddPort
        lea      TimeIO,a1
        move.l   #UNIT_MICROHZ,d0
        clr.l    d1
        lea      timer_name,a0
        CALLEXEC OpenDevice
        tst.l    d0
        bne      ClSer
        lea      TimeIO,a1             ;replyport eintragen
        move.l   #TimeReply,MN_REPLYPORT(a1)
 
;-------
        lea      windowdef(pc),a0  ;CON: braucht zusaetzlich
        CALLINT  OpenWindow        ;ein window, dem es zugeordnet
        tst.l    d0                ;wird.
        beq      ClTimer           ;
        move.l   d0,windowptr      ;

        sub.l    a1,a1
        CALLEXEC FindTask
        lea      ConReply,a1
        move.l   d0,MP_SIGTASK(a1)
        CALLEXEC AddPort
        lea      ConIO,a1
        move.l   windowptr,IO_DATA(a1) ;CON: diesem fenster zugeordnet
        move.l   #48,IO_LENGTH(a1)     ;48 = laenge windowdef
        clr.l    d0
        clr.l    d1
        lea      con_name,a0
        CALLEXEC OpenDevice
        tst.l    d0
        bne      ClWdw
        lea      ConIO,a1              ;replyport eintragen
        move.l   #ConReply,MN_REPLYPORT(a1)

;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
        bsr      TERMINAL
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

ClCon                        ;ALLES BEENDEN
        lea      ConIO,a1
        CALLEXEC CloseDevice
ClWdw
        lea      ConReply,a1
        CALLEXEC RemPort
        move.l   windowptr,a0
        CALLINT  CloseWindow        
ClTimer
        lea      TimeIO,a1
        CALLEXEC CloseDevice
ClSer
        lea      TimeReply,a1
        CALLEXEC RemPort
        lea      SerIO,a1
        CALLEXEC CloseDevice
ClXpr
        lea      SerReply,a1
        CALLEXEC RemPort
        move.l   _XPRBase,a1
        CALLEXEC CloseLibrary
ClGraf
        move.l   _GfxBase,a1
        CALLEXEC CloseLibrary
ClDos
        move.l   _DOSBase,a1
        CALLEXEC CloseLibrary
ClInt
        move.l   _IntuitionBase,a1
        CALLEXEC CloseLibrary
EXIT                               ;PROGRAMMENDE
        move.l  #0,d0              ;Return Code 0 = OK
        rts

;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
SetClock

        move.l   #25,d1
        CALLDOS  Delay

        lea      SerIO,a1
        move.w   #CMD_WRITE,IO_COMMAND(a1)
        move.l   #MuellLen,IO_LENGTH(a1)
        move.l   #Muell,IO_DATA(a1)
        CALLEXEC DoIO

        move.l   #50,d1
        CALLDOS  Delay

        lea      SerIO,a1
        move.w   #99,IO_COMMAND(a1)
        CALLEXEC DoIO

        rts
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
TERMINAL
;        bsr      SetClock
;        rts


m0
        bsr      xpr_squery                 ;wieviele bytes eingetrudelt?
        cmpi.l   #2000,d0
        bcs      m8  ;d0 kleiner pufferlaenge
        move.l   #2000,d0 ;wenn ueber 2000
m8       
        move.l   d0,Dnull                   
        tst.l    d0
        bne      m9
        move.l   #1,Dnull                   ;wenn 0 dann 1 byte anfordern.
m9
        lea      SerIO,a1                   ;post SER:readrequest for X byte
        move.l   #SerReply,MN_REPLYPORT(a1)
        move.w   #CMD_READ,IO_COMMAND(a1)
        move.l   Dnull,IO_LENGTH(a1)
        move.l   #SerPuff,IO_DATA(a1)
        CALLEXEC SendIO

        lea      ConIO,a1                   ;post CON:readrequest for 1 byte
        move.l   #ConReply,MN_REPLYPORT(a1)
        move.w   #CMD_READ,IO_COMMAND(a1)
        move.l   #1,IO_LENGTH(a1)
        move.l   #ConPuff,IO_DATA(a1)
        CALLEXEC SendIO

m1
        clr.l    d0                         ;gehe schlafen, bis einer der
        clr.l    d1                         ;beiden readrequests 
        lea      SerReply,a1                ;erfuellt wird (1000% multitask) 
        move.b   MP_SIGBIT(a1),d1
        bset.l   d1,d0
        lea      ConReply,a1
        move.b   MP_SIGBIT(a1),d1
        bset.l   d1,d0
        CALLEXEC Wait
 
        lea      ConIO,a1     ;taste?
        CALLEXEC CheckIO
        beq      m2           ;nein
        CALLEXEC WaitIO       ;cleanup con

        lea      SerIO,a1   ;serrequest abbrechen
        CALLEXEC AbortIO
        lea      SerIO,a1
        CALLEXEC WaitIO       ;cleanup

        cmp.b    #"å",ConPuff
        bne      m001
        rts      ;exit
m001
        cmp.b    #"ð",ConPuff
        bne      m002
        bsr      Download
m002
        cmp.b    #"µ",ConPuff
        bne      m003
        bsr      Upload
m003        

        lea      SerIO,a1   ;den Tastenwert ins modem
        move.l   #SerReply,MN_REPLYPORT(a1)
        move.w   #CMD_WRITE,IO_COMMAND(a1)
        move.l   #1,IO_LENGTH(a1)
        move.l   #ConPuff,IO_DATA(a1)
        CALLEXEC DoIO

        bra      m0

m2
        lea      SerIO,a1
        CALLEXEC CheckIO      ;war es der SerReq?
        beq      m1           ;nein
        CALLEXEC WaitIO       ;cleanup serial

        lea      ConIO,a1     ;Conrequest abbrechen
        CALLEXEC AbortIO
        lea      ConIO,a1
        CALLEXEC WaitIO       ;cleanup

        lea      ConIO,a1     ;X serielle bytes ins fenster
        move.l   #ConReply,MN_REPLYPORT(a1)
        move.w   #CMD_WRITE,IO_COMMAND(a1)
        move.l   Dnull,IO_LENGTH(a1)
        move.l   #SerPuff,IO_DATA(a1)
        CALLEXEC DoIO

        bra      m0

;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;XPR_Update logfile schreiben

WriteLog
        move.l   #XPRLOG,d1
        move.l   #MODE_NEWFILE,d2
        CALLDOS  Open
        move.l   d0,XPRhandle
;-------   
        move.l   d0,d1
        move.l   #Status,d2
        move.l   #2,d3      ;2 bytes: Status + EOL(10)=erste protokollzeile
        CALLDOS  Write
;-------
        move.l   Asave,a3   ;zeiger auf XPR_Update
        move.l   4(a3),a3   ;offset4 = Zeiger auf Protokollname
        bsr      p00        ;ins Protfile schreiben +EOL
        move.l   Asave,a3
        move.l   8(a3),a3   ;offset8 = Zeiger auf Filename
        bsr      p00

        move.l   Asave,a3
        move.l   12(a3),d2  ;12 = Langwort FileSize
        bsr      p10        ;umwandeln in 8 asciibytes und schreiben +EOL

        move.l   Asave,a3
        move.l   16(a3),a3  ;"a generic message" -- DONE oder sowas..
        bsr      p00
        move.l   Asave,a3
        move.l   20(a3),a3  ;letzte Errormessage soweit vorhanden
        bsr      p00

        move.l   Asave,a3
        move.l   24(a3),d2  ;blocks transfered
        bsr      p10
        move.l   Asave,a3
        move.l   28(a3),d2  ;blockgroesse (1024 oder kleiner)
        bsr      p10
        move.l   Asave,a3
        move.l   32(a3),d2  ;bytes transfered
        bsr      p10
        move.l   Asave,a3
        move.l   36(a3),d2  ;anzahl errors
        bsr      p10
        move.l   Asave,a3
        move.l   40(a3),d2  ;anzahl timeouts
        bsr      p10
        move.l   Asave,a3
        move.l   44(a3),d2  ;pakettyp (?)
        bsr      p10
        move.l   Asave,a3
        move.l   48(a3),d2  ;verzoegerung zwischen paketen (msecs)
        bsr      p10
        move.l   Asave,a3
        move.l   52(a3),d2  ;verzoegerung zwischen zeichen (xprascii wohl..)
        bsr      p10

        move.l   Asave,a3
        move.l   56(a3),a3  ;blockcheck  : "CRC-32" oder so
        bsr      p00
        move.l   Asave,a3
        move.l   60(a3),a3  ;erwartete transferzeit
        bsr      p00
        move.l   Asave,a3
        move.l   64(a3),a3  ;Elapsed Time: echte U/D zeit nicht erwartete
        bsr      p00

        move.l   Asave,a3
        move.l   68(a3),d2  ;CPS RATE !!
        bsr      p10

;-------
        move.l   XPRhandle,d1
        CALLDOS  Close
        rts      ;ENDE

;----------------------------------                             
p00
        move.l   #1,d3           ;String(^a3) ins Log schreiben+EOL
        move.l   a3,a4
p01     cmpi.b   #15,(a4)+
        bcs      p02
        addq.b   #1,d3
        bra      p01
p02     move.b   #10,-(a4)       ;EOL
        move.l   XPRhandle,d1
        move.l   a3,d2
        CALLDOS  Write
        RTS
;-------
p10     move.l   #LON,a0        ;langwort wandeln und ins prot+EOL
        bsr      makeASC
        move.l   #LON,d2
        move.l   XPRhandle,d1
        move.l   #9,d3
        CALLDOS  Write
        RTS

LON     dc.b     "12345678",10,0  ;Puffer fuer wandlung LONG->Ascii dezimal
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Download

        lea      XPR_IO,a0
        move.l   #iname,(a0)
        move.l   _XPRBase,a6
        jsr      -36(a6)            ;Setup general params

        lea      UDwindowdef(pc),a0 ;infowindow auf.
        CALLINT  OpenWindow
        move.l   d0,UDwindowptr

        lea      XPR_IO,a0          ;xprz lib routine anspringen
        move.l   _XPRBase,a6
        jsr      -48(a6)            ;Receive

        addi.b   #"0",d0            ;makeascii
        move.b   d0,Status

        move.l   UDwindowptr,a0
        CALLINT  CloseWindow        

        lea      XPR_IO,a0
        move.l   _XPRBase,a6
        jsr      -30(a6)            ;Cleanup


        bsr      WriteLog
        move.l   #0,Flagge
        rts

;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Upload

        lea      XPR_IO,a0
        move.l   #iname,(a0)
        move.l   _XPRBase,a6
        jsr      -36(a6)            ;Setup
         
        move.l   #connam,d1         ;welles file
        move.l   #MODE_OLDFILE,d2           
        CALLDOS  Open
        move.l   d0,conhandle
        move.l   d0,d1             
        move.l   #cname,d2
        move.l   #70,d3
        CALLDOS  Read
        lea      cname,a0
        subq.b   #1,d0
        move.b   #0,(a0,d0)         ;null am ende
        move.l   conhandle,d1
        CALLDOS  Close
         
        lea      UDwindowdef(pc),a0
        CALLINT  OpenWindow
        move.l   d0,UDwindowptr

        lea      cname,a1
        lea      XPR_IO,a0
        move.l   a1,(a0)            ;xpr_filename
        move.l   _XPRBase,a6
        jsr      -42(a6)            ;Upload

        addi.b   #"0",d0            ;makeascii
        move.b   d0,Status

        move.l   UDwindowptr,a0
        CALLINT  CloseWindow        

        lea      XPR_IO,a0
        move.l   _XPRBase,a6
        jsr      -30(a6)            ;Cleanup

        bsr      WriteLog
        move.l   #0,Flagge
        rts

;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 
Muell     dc.b "ATDI99",13,10
MuellLen  equ  *-Muell
          cnop 0,4
Status    dc.b 0,10,0,0 ;successful(1) oda fail(0) +EOL=erste Zeile im Prot
          cnop 0,4
XPRLOG    dc.b "S:XPRLOG",0
          cnop 0,4
XPRhandle dc.l 0
          cnop 0,4
connam    dc.b "CON:10/150/620/30/......enter full u/l path, man.....",0
          cnop 0,4
conhandle dc.l 0
          cnop 0,4
iname     dc.b "TN, ON, RN, AY, KY, SN, DN, F0, Pdh1:, B64",0
cname     ds.b 80 ;               download path: ^^^^^^^^^^
          cnop 0,4
SerPuff   ds.b 2001
          cnop 0,4
ConPuff   ds.b 100
          cnop 0,4
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;--------------------------------------XPR CALLBACK ROUTINEN--------------


;----------------------------------xpr_open
xpr_fopen

        MOVE.L  A0,D1
        CMP.B   #"r",(A1)   ;Mode Read
        BNE.S   fopen1
        MOVE.L  #$3ED,D2
fopen1
        CMP.B   #"w",(A1)   ;Mode Write
        BNE.S   fopen2
        MOVE.L  #$3EE,D2
fopen2
        CMP.B   #"a",(A1)   ;Mode Append
        BNE.S   fopen3
        MOVE.L  #$3EC,D2
fopen3
        CALLDOS Open
        RTS
;----------------------------------xpr_fclose
xpr_fclose
             move.l  a0,d1
             CALLDOS Close
             rts
;----------------------------------xpr_fread
xpr_fread
             move.l  d1,d3  ;Laenge
             move.l  a0,d2  ;Buffer
             move.l  a1,d1  ;Handle
             CALLDOS Read
             rts
;----------------------------------xpr_fwrite
xpr_fwrite
             move.l  d1,d3  ;Laenge
             move.l  a0,d2  ;Buffer
             move.l  a1,d1  ;Handle
             CALLDOS Write
             rts
;----------------------------------xpr_fseek
xpr_fseek
             move.l  d1,d3  ;Modus offset_beginning/current/end
             move.l  d0,d2  ;Abstand
             move.l  a0,d1  ;Handle
             subq.l  #1,d3
             CALLDOS Seek
             tst.l   d0
             bmi.s   fseek1
             clr.l   d0 ;0=success
fseek1
             rts
;----------------------------------xpr_finfo
xpr_finfo

        MOVE.L  D0,-(SP)
        MOVE.L  A0,D1
        MOVE.L  #-2,D2
        CALLDOS Lock
        MOVE.L  D0,D1
        BEQ     finfo2
        MOVE.L  D0,-(SP)
        MOVE.L  D0,D1
        MOVE.L  #FIB,D2
        CALLDOS Examine
        MOVE.L  (SP)+,D1
        CALLDOS UnLock
        MOVE.L  (SP),D0
        CMP.L   #2,D0
        BEQ     finfo1
        CMP.L   #1,D0
        BNE     finfo2
        lea     FIB,a0
        move.l  124(a0),d0 ;anzahl bytes
        BRA     finfo3
finfo1  CLR.L   D0
        BRA     finfo3
finfo2  CLR.L   D0
finfo3  CLR.L   (SP)+
        RTS
;----------------------------------xpr_update
xpr_update

        MOVE.L  A0,Asave

        cmp     #0,Flagge
        bne     update1
        move.l  #-1,Flagge
;-------
        move.l  #10,d0    ;das hier wird nur 1mal pro transfer geprintet
        move.l  #20,d1    ;filename
        bsr     updatemove
        move.l  Asave,a0
        move.l  8(a0),a0  ;^Fname
        clr.l   d0
        move.l  a0,a1
update0 cmpi.b  #"/",(a1) ;laenge ermitteln
        bne     update3
        move.l  a1,a0
        clr.l   d0
update3 cmpi.b  #0,(a1)+
        beq     update4
        addq.b  #1,d0
        bra     update0
update4 bsr     updatetext

        move.l  #10,d0
        move.l  #40,d1
        bsr     updatemove
        lea     SIZE,a0
        move.l  #18,d0
        bsr     updatetext

        move.l  #10,d0
        move.l  #30,d1
        bsr     updatemove
        lea     CPS,a0
        move.l  #18,d0
        bsr     updatetext

        move.l  #10,d0
        move.l  #50,d1
        bsr     updatemove
        lea     BYT,a0
        move.l  #18,d0
        bsr     updatetext

        move.l  #10,d0
        move.l  #60,d1
        bsr     updatemove
        lea     TIME,a0
        move.l  #18,d0
        bsr     updatetext

;-------
update1
        move.l  Asave,a0            ;dieses nach jedem block
        move.l  68(a0),d2
        lea     CPS+18,a0
        bsr     makeASC
        move.l  #154,d0
        move.l  #30,d1
        bsr     updatemove
        lea     CPS+18,a0
        move.l  #8,d0
        bsr     updatetext

        move.l  Asave,a0
        move.l  12(a0),d2
        lea     SIZE+18,a0
        bsr     makeASC
        move.l  #154,d0
        move.l  #40,d1
        bsr     updatemove
        lea     SIZE+18,a0
        move.l  #8,d0
        bsr     updatetext

        move.l  Asave,a0
        move.l  32(a0),d2
        lea     BYT+18,a0
        bsr     makeASC
        move.l  #154,d0
        move.l  #50,d1
        bsr     updatemove
        lea     BYT+18,a0
        move.l  #8,d0
        bsr     updatetext

        move.l  #10,d0
        move.l  #60,d1
        bsr     updatemove
        move.l  Asave,a0
        move.l  64(a0),a0                ;^elapsed time
        move.l  #8,d0                    ;maxlen
        bsr     updatetext

        move.l  #154,d0
        move.l  #60,d1
        bsr     updatemove
        move.l  Asave,a0
        move.l  60(a0),a0                ;^expect time
        move.l  #8,d0                    ;maxlen
        bsr     updatetext

        rts

CPS     dc.b    "BytesProSekunde  :12345678"
SIZE    dc.b    "FileGröße        :12345678"
BYT     dc.b    "Schon übertragen :12345678"
TIME    dc.b    "00:00:00<<<<<>>>>>00:00:00"
Asave   dc.l    0,0
Flagge  dc.l    0,0


UDwindowdef     cnop 0,4
        dc.w    170,60
        dc.w    300,80
        dc.b    -1,-1
        dc.l    CLOSEWINDOW
        dc.l    UDW_Gadgets!UDW_Extras  
        dc.l    0
        dc.l    0
        dc.l    UDW_Title
        dc.l    0
        dc.l    0
        dc.w    0,0
        dc.w    0,0
STYPE   dc.w    WBENCHSCREEN
        cnop    0,4

UDW_Gadgets equ   WINDOWDRAG!WINDOWDEPTH!WINDOWCLOSE
UDW_Extras  equ   SMART_REFRESH!ACTIVATE
UDW_Title   dc.b  "XPR>>>>>>Z",0
            cnop  0,4
UDwindowptr dc.l  0
            cnop  0,4

updatemove                         ;d0=x;d1=y
        move.l   UDwindowptr,a1
        move.l   wd_RPort(a1),a1
        CALLGRAF Move                
        rts
updatetext                         ;a0=^buffer;d0=anzahl
        move.l   UDwindowptr,a1
        move.l   wd_RPort(a1),a1
        CALLGRAF Text
        rts
;----------------------------------xpr_chkabort
xpr_chkabort

        move.l   UDwindowptr,a0    ;IDCMP-Windowport holen
        move.l   wd_UserPort(a0),a0
        CALLEXEC GetMsg
        tst.l    d0                ;nix da
        beq      chkabort1
        move.l   d0,a1
        move.l   im_Class(a1),Dsave
        CALLEXEC ReplyMsg
        cmp.l    #CLOSEWINDOW,Dsave
        bne      chkabort1
        move.l   #-1,d0            ;abort
        rts
chkabort1
        clr.l   d0 
        rts                        ;d0 nonzero = abort

Dsave   dc.l    0
;----------------------------------xpr_chkmisc
xpr_chkmisc 
             rts
;----------------------------------xpr_sread
xpr_sread

        move.l   a0,Anull
        move.l   d0,Dnull
        move.l   d1,Deins

        tst.l    d1                ;timeout gefordert ?
        bne      sread7            ;wenn ja

        bsr      xpr_squery
        tst.l    d0                ;was im port?
        bne      sread0            ;wenn ja
        rts
sread0
        cmp.l    Dnull,d0
        bls.s    sreadX            ;mehr angekommen als gefordert?
        move.l   Dnull,d0          ;nur geforderte zahl lesen
sreadX
        lea      SerIO,a1          ;abholen
        move.w   #CMD_READ,IO_COMMAND(a1)
        move.l   d0,IO_LENGTH(a1)
        move.l   Anull,IO_DATA(a1)
        CALLEXEC DoIO
        move.l   IO_ACTUAL(a1),d0
        rts

sread7
        lea      SerIO,a1
        move.w   #CMD_READ,IO_COMMAND(a1)
        move.l   Dnull,IO_LENGTH(a1)
        move.l   Anull,IO_DATA(a1)
        CALLEXEC SendIO            ;man beachte: nur sendio nicht doio!

        lea      TimeIO,a1
        move.w   #9,IO_COMMAND(a1) ;add timerequest
        move.l   Deins,$24(a1)     ;timeout microsecs
        move.l   #0,$20(a1)        ;null secs
        clr.b    IO_FLAGS(a1)
        CALLEXEC SendIO
;--------
sread1
        clr.l    d0                ;warten: entweder geforderte bytes
        clr.l    d1                ;angekommen oder timeout
        lea      SerReply,a1       ;waitmaske erstellen
        move.b   MP_SIGBIT(a1),d1
        bset.l   d1,d0
        lea      TimeReply,a1
        move.b   MP_SIGBIT(a1),d1
        bset.l   d1,d0
        CALLEXEC Wait
;--------
        lea      SerIO,a1
        CALLEXEC CheckIO      ;war es der SerReq?
        beq      sread2       ;nein
        CALLEXEC WaitIO       ;cleanup serial

        lea      TimeIO,a1    ;timerrequest abbrechen
        CALLEXEC AbortIO
        lea      TimeIO,a1
        CALLEXEC WaitIO       ;cleanup

        lea      SerIO,a1
        move.l   IO_ACTUAL(a1),d0
        rts
;-------
sread2
        lea      TimeIO,a1    ;timeout?
        CALLEXEC CheckIO
        beq      sread1       ;nein
        CALLEXEC WaitIO       ;cleanup timer

        lea      SerIO,a1     ;readrequest abbrechen
        CALLEXEC AbortIO
        lea      SerIO,a1
        CALLEXEC WaitIO       ;cleanup

        lea      SerIO,a1
        move.l   IO_ACTUAL(a1),d0 ;soviele bytes gelesen
        rts
;----------------------------------xpr_swrite
xpr_swrite

        lea      SerIO,a1
        move.w   #CMD_WRITE,IO_COMMAND(a1)
        move.l   d0,IO_LENGTH(a1)
        move.l   a0,IO_DATA(a1)
        CALLEXEC DoIO
        rts
;----------------------------------xpr_sflush
xpr_sflush

        lea      SerIO,a1
        move.w   #CMD_FLUSH,IO_COMMAND(a1)
        CALLEXEC DoIO
        rts
;----------------------------------xpr_squery
xpr_squery

        lea      SerIO,a1
        move.w   #SDCMD_QUERY,IO_COMMAND(a1)
        CALLEXEC DoIO
        move.l   IO_ACTUAL(a1),d0
        rts
;----------------------------------xpr_unlink
xpr_unlink

        MOVE.L  A0,D1
        CALLDOS DeleteFile
        TST.L   D0
        BEQ     unlink1
        MOVEQ   #-$1,D0
        BRA     unlink2
unlink1 CLR.L   D0
unlink2 RTS
;---------------------------------xpr_getptr
xpr_getptr
        CLR.L        D0
        RTS
;---------------------------------xpr_options
xpr_options
        RTS
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;-=-=-=-=-DATENBEREICH=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

XPR_IO       dc.l  0
             dc.l  xpr_fopen  ;diese struct bekommt XPR beim aufruf mit
             dc.l  xpr_fclose ;auf den weg und weiss dann, wo die callback
             dc.l  xpr_fread  ;dinger sitzen. wenn da steht "dc.l 0" dann
             dc.l  xpr_fwrite ;hab ich die routine noch nicht eingebaut
             dc.l  xpr_sread  ;und XPR springt sie nicht an. (optional)
             dc.l  xpr_swrite
             dc.l  xpr_sflush
             dc.l  xpr_update
             dc.l  xpr_chkabort
             dc.l  xpr_chkmisc
             dc.l  0          ;xpr_gets
             dc.l  0          ;xpr_setserial
             dc.l  0          ;xpr_ffirst
             dc.l  0          ;xpr_fnext
             dc.l  xpr_finfo
             dc.l  xpr_fseek
             dc.l  4          ;alle 4 ext fields sind programmiert
             dc.l  0
             dc.l  xpr_options;EXT1
             dc.l  xpr_unlink ;EXT2
             dc.l  xpr_squery ;EXT3
             dc.l  xpr_getptr ;EXT4
             dc.l  0,0,0,0
             cnop  0,4

;------------IOExtSer--------------------------
SerIO        ds.b    100      ;Alloc fuer Message und Replyports
SerReply     ds.b    100
;----------------------------------------------
TimeIO       ds.b    100
TimeReply    ds.b    100
;----------------------------------------------
ConIO        ds.b    100
ConReply     ds.b    100
;----------------------------------------------

          cnop  0,4
windowdef dc.w  0,0
          dc.w  640,256
          dc.b  -1,-1
          dc.l  WINDOWCLOSE
          dc.l  W_Gadgets!W_Extras
          dc.l  0,0
          dc.l  W_Title
          dc.l  0,0
          dc.w  200,30
          dc.w  640,256
          dc.w  WBENCHSCREEN
W_Gadgets equ   WINDOWSIZING!WINDOWDRAG!WINDOWDEPTH
W_Extras  equ   SMART_REFRESH!ACTIVATE
W_Title   dc.b  "ALT-Quit, ALT-Download, ALT-Upload",0,0
          cnop  0,4


Anull          dc.l    0   ;scratschregister
Aeins          dc.l    0
Dnull          dc.l    0
Deins          dc.l    0
handle         dc.l    0

_DOSBase       dc.l    0
_XPRBase       dc.l    0
_IntuitionBase dc.l    0
_GfxBase       dc.l    0
windowptr      dc.l    0

FIB          ds.b    500  ;file-info-block (da steht irgendwann die filesize)
             cnop    0,4

int_name     INTNAME
             cnop    0,4
con_name     dc.b    "console.device",0
             cnop    0,4
timer_name   TIMERNAME
             cnop    0,4
ser_name     dc.b    "isdn.device",0
             cnop    0,4
dos_name     DOSNAME
             cnop    0,4
graf_name    GRAFNAME
             cnop    0,4
xpr_name     dc.b    "xprzmodem.library",0
             cnop    0,4

;--------------------------------------------
makeASC              ;a0->Puffer; d2=Langwort

        moveq        #7,d0       ;8 Stellen...
        lea.l        Potenzen,a1
next    move         #"0",d1
make1   addq         #1,d1
        sub.l        (a1),d2        
        bcc          make1
        subq         #1,d1
        add.l        (a1),d2        
        move.b       d1,(a0)+
        tst.l        (a1)+
        dbra         d0,next
        rts

Potenzen dc.l        10000000
         dc.l        1000000
         dc.l        100000
         dc.l        10000
         dc.l        1000
         dc.l        100
         dc.l        10
         dc.l        1
         dc.l        0


;---------------------------------------------------------------------
             END
;---------------------------------------------------------------------


