

        SECTION  AMIXPR,CODE	;(c)1992 Gellermann +49/621/715101-0

        incdir   "include/"
        include  "exec/exec_lib.i"
        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"
	xdef _xprsequence
     xref _CallersLog
     xref _UDLog
     xref _MYScreen
     xref _ReceivePath
     xref _xprinit
     xref _protocol
     xref _SendPath
     xref _sendopt
     xref _DOSBase
     xref _IntuitionBase
     xref _myxprunit
     xref _myxprdevice
     xref _GfxBase
     xref _DTBT
     xref _TBT
     xref _TTTM
     xref _TTEFF
     xref _TTCPS
     xref _Online_NFiles
     xref _BatchXfer
_xprsequence:
;located here bcuz the doslib must be open for printHELP but
;the xprlib must not be open since we have yet to determine
;the xpr_protocolname
				;decode the switches
main_loop
     moveq    #0,d0
     move.l   _protocol,a1
     CALLEXEC OpenLibrary
     tst.l    d0
     bne      XPRok
     rts
XPRok
        move.l   d0,_XPRBase

        lea      SerIO,a1		;IOExtSer Struktur
        clr.l    d0         
        clr.l    d1
	   move.b	  _myxprunit,d0
        move.b   #$B4,IO_SERFLAGS(a1)	;set radboogie,7wire,(shared=b4)
        move.l   _myxprdevice,a0		;exclusive = $94
        CALLEXEC OpenDevice
        tst.l    d0
        bne      ClSer

        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		;replyport eintragen
        move.l   #SerReply,MN_REPLYPORT(a1)

;---------------------------------------;OPEN DEVICES

        lea      TimeIO,a1		;timer.device
        move.l   #UNIT_MICROHZ,d0
        clr.l    d1
        lea      timer_name,a0
        CALLEXEC OpenDevice
        sub.l    a1,a1
        CALLEXEC FindTask
        lea      TimeReply,a1
        move.l   d0,MP_SIGTASK(a1)
        CALLEXEC AddPort
        lea      TimeIO,a1		;replyport eintragen
        move.l   #TimeReply,MN_REPLYPORT(a1)
 

;---------------------------------------;ALLOC RAM
	move.l	#10000,d0		;Logbuffer
	move.l	#$30001,d1
	CALLEXEC	AllocMem
	tst.l	d0
	beq	noRAM
	move.l	d0,LBMin
        bsr      MAINEVENT
     move.l	LBMin,a1
     move.l	#10000,d0
     CALLEXEC	FreeMem
noRAM
        lea      TimeIO,a1
        CALLEXEC CloseDevice
        lea      TimeReply,a1
        CALLEXEC RemPort
ClTimer
        lea      SerIO,a1
        CALLEXEC CloseDevice
        lea      SerReply,a1
        CALLEXEC RemPort
ClSer
ClFont
        move.l   _XPRBase,a1
        CALLEXEC CloseLibrary
        move.l  #0,d0			;Return Code 0 = OK
        rts

;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
MAINEVENT
     move.l #0,_DTBT     ;clear xfer stats
     move.l #0,_TBT
     move.l #0,_TTTM
     move.l #0,_TTEFF
     move.l #0,_TTCPS
     move.l #0,_Online_NFiles
     bsr ResetTmps
     move.l #msg,tex		;write-pointer
     move.l #20,yps          ;y-Startposition
     move.l #0,d0
     move.b _sendopt,d0
     tst.b d0
     bne noRECEIVE
     bsr	Receive
	rts
noRECEIVE
     bsr Send
     rts
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Receive	;"amixpr r path"
	;        ^Pointer

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

	   move.l	  _ReceivePath,a2
        move.b   #"P",(a2)
        lea      XPR_IO,a0
        move.l   a2,(a0)
        move.l   _XPRBase,a6
        jsr      -36(a6)		;Setup receive path

	bsr	 openWINDOW

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

	bsr	 closeWINDOW

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

        rts

Send	;amixpr s path/name1 path/name2 ... 256bytes max (use -b !!!)
	;       ^Pointer

	   bsr	 openWINDOW
        lea      XPR_IO,a0
        move.l   _xprinit,(a0)
        move.l   _XPRBase,a6
        jsr      -36(a6)		;Setup general params

        move.l   _SendPath,a1            
        lea      XPR_IO,a0
	   move.l   a1,(a0)		;give pointer to ffirst/fnext
	   move.l   _XPRBase,a6
	   jsr      -42(a6)		;Send

	   bsr	 closeWINDOW

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

ResetTmps  ;clear the cps, eff, & time temp variables
     move.l #0,TmpCps
     move.l #0,TmpEff
     move.l #0,TmpTim
     move.l #0,TmpSiz
     rts

AddTmps    ;add the temp variables to the main ones.
     move.l d0,-(SP)
     move.l TmpCps,d0
     add.l d0,_TTCPS
     move.l TmpEff,d0
     add.l d0,_TTEFF
     move.l TmpTim,d0
     add.l d0,_TTTM
     
     move.b _sendopt,d0
     tst.b d0
     beq noRecSize
     move.l TmpSiz,d0
     add.l d0,_TBT
     move.l #1,d0
     add.l d0,_Online_NFiles
noRecSize
     move.l (SP)+,d0
     bsr ResetTmps
     rts

;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;--------------------------------------XPR CALLBACK ROUTINEN--------------
;
;----------------------------------xpr_fopen
xpr_fopen	;a0^FileName a1^Axxsmode return:d0=handle or 0

	move.l  a0,d1
	move.b	(a1),d0
	bclr.l	#5,d0		;cap. letters
	cmpi.b	#"R",d0
        bne	noMODE_READ
        move.l	#MODE_OLDFILE,d2
        CALLDOS	Open		;d1^name d2=modus
	rts

noMODE_READ
        cmpi.b	#"W",d0
        bne	noMODE_WRITE
        move.l	#MODE_NEWFILE,d2
        CALLDOS	Open
	rts

noMODE_WRITE
        cmpi.b	#"A",d0
        bne	noMODE_APPEND
	move.l	d1,d5           ;save ^name
        move.l	#MODE_OLDFILE,d2
        CALLDOS	Open
        tst.l	d0
        bne	OPENok
	move.l	d5,d1
        move.l	#MODE_NEWFILE,d2
        CALLDOS	Open
	rts
OPENok
	move.l	 d0,d5		;save handle
        move.l   d0,d1		;goto end of file (append)
        move.l   #0,d2
        move.l   #OFFSET_END,d3
        CALLDOS  Seek
	move.l	 d5,d0		;handle in d0 must be returned
	rts

noMODE_APPEND
	clr.l	d0
	rts			;do nothing

;----------------------------------xpr_fclose
xpr_fclose
	move.l	a0,d1
	CALLDOS	Close
     bsr AddTmps
	rts

;the fclose is the only callback-routine that gets
;called after every filexfer in a batch
;so we build a string of log entries
;here and save it after the xprlib returns.
;----------------------------------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
;the most important routine for isdn: gets called between
;every 1k block transfered.. keep it very simple and fast ore it
;will take away 2000cps.. no `%complete` calculation and stuff..

        move.l  a0,Asave        ;save ptr to xpr_update (build_log)
	   move.l	(a0),d5		;update mask (what fields have changed)

;-------
	btst.l	#1,d5	
	beq	noFileName

        move.l  #11*8,d0	
        move.l  #20,d1		;filename
        bsr     updatemove
	move.l	#Fill,a0
	move.l	#40,d0
	bsr	updatetext
        move.l  #11*8,d0	
        move.l  #20,d1
        bsr     updatemove
        move.l  Asave,a0
        move.l  8(a0),a0	;^Fname
        clr.l   d0
        move.l  a0,a1
update0
	cmpi.b  #15,(a1)+
        bcs     update4
        addq.b  #1,d0
	cmpi.b	#40,d0		;print max 40 chars
	bne	update0
update4
	bsr     updatetext

noFileName
;-------
	btst.l	#2,d5	
	beq	noFileSize

        move.l  Asave,a0
        move.l  12(a0),d0	;filesize
        move.l  12(a0),TmpSiz
        lea     Ruelps,a0
        bsr     ULONGtoASCII
        move.l  #11*8,d0
        move.l  #30,d1
        bsr     updatemove
        lea     Ruelps,a0
        move.l  #8,d0
        bsr     updatetext
noFileSize
;-------
	btst.l	#3,d5	
	beq	noMSG

        move.l  #1*8,d0	
        move.l  #90,d1
        bsr     updatemove
	move.l	#Fill,a0
	move.l	#50,d0
	bsr	updatetext
        move.l  #1*8,d0	
        move.l  #90,d1
        bsr     updatemove
        move.l  Asave,a0
        move.l  16(a0),a0
        clr.l   d0
        move.l  a0,a1
update00
	cmpi.b  #15,(a1)+
        bcs     update44
        addq.b  #1,d0
	cmpi.b	#50,d0		;print max 50 chars
	bne	update00
update44
	bsr     updatetext
noMSG
;-------
	btst.l	#4,d5
	beq	noERROR

        move.l  #1*8,d0	
        move.l  #100,d1	
        bsr     updatemove
	move.l	#Fill,a0
	move.l	#50,d0
	bsr	updatetext
        move.l  #1*8,d0	
        move.l  #100,d1	
        bsr     updatemove
        move.l  Asave,a0
        move.l  20(a0),a0
        clr.l   d0
        move.l  a0,a1
update000
	cmpi.b  #15,(a1)+
        bcs     update444
        addq.b  #1,d0
	cmpi.b	#50,d0		;print max 50 chars
	bne	update000
update444
	bsr     updatetext
noERROR
;-------
	btst.l	#16,d5
	beq	noCPS

        move.l  Asave,a0
        move.l  68(a0),d0	;cps
        move.l  d0,TmpCps
        lea     Ruelps,a0
        bsr     ULONGtoASCII
        move.l  #11*8,d0
        move.l  #70,d1
        bsr     updatemove
        lea     Ruelps,a0
        move.l  #8,d0
        bsr     updatetext
noCPS
;-------
	btst.l	#7,d5
	beq	noBYTES

        move.l  Asave,a0	
        move.l  32(a0),d0	;position
        lea     Ruelps,a0
        bsr     ULONGtoASCII
        move.l  #11*8,d0
        move.l  #40,d1
        bsr     updatemove
        lea     Ruelps,a0
        move.l  #8,d0
        bsr     updatetext
noBYTES
;-------
	btst.l	#15,d5
	beq	noELAPSED

        move.l  #11*8,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
noELAPSED
;-------
	btst.l	#14,d5
	beq	noEXPECT

        move.l  #11*8,d0
        move.l  #50,d1
        bsr     updatemove
        move.l  Asave,a0
        move.l  60(a0),a0	;^expect time
        move.l  #8,d0		;maxlen
        bsr     updatetext
noEXPECT
;-------
update_end
        rts

;----------------------------------xpr_chkabort
xpr_chkabort	;abort if ESCAPE or CLOSEWINDOW or CARRIER LOST
		;also called between every 1k block

        move.l   UDwindowptr,a0	;IDCMP-Windowport holen
        move.l   wd_UserPort(a0),a0
        CALLEXEC GetMsg
        tst.l    d0
        beq      noMESSAGE

        move.l   d0,a1
        move.l   im_Class(a1),d4
        move.w   im_Code(a1),d5 ;.Word!
	CALLEXEC ReplyMsg

        cmpi.l   #CLOSEWINDOW,d4
        beq      yoABORT
	cmpi.l	 #RAWKEY,d4
	bne	 xpr_chkabort
	cmpi.b	 #$45,d5
	beq	 yoABORT	;escape key pressed (only when win active)
        bra	 xpr_chkabort 	;another msg?

noMESSAGE
        bsr	 xpr_squery     ;vielleicht zu lang fuer isdn?
	move.w	 IO_STATUS(a1),d0
        btst	 #5,d0		;CARRIER LOST?
	bne	 yoABORT
noABORT
        clr.l   d0 
        rts
yoABORT
        move.l   #-1,d0		;d0 nonzero = abort
        rts


;----------------------------------xpr_chkmisc
xpr_chkmisc 
	rts
;----------------------------------xpr_sread
xpr_sread

        move.l   a0,Anull	;IO_DATA
        move.l   d0,Dnull       ;IO_LENGTH
        move.l   d1,Deins	;timeout or 0

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

        bsr      xpr_squery     ;read all bytes available
        tst.l    d0		;IO_ACTUAL
        bne      sumTHERE
        rts                     ;return with count=0

sumTHERE
        cmp.l    Dnull,d0
        bcc      readOK		;more than asked for?
        move.l   d0,Dnull	;read only as much as requested
readOK
        lea      SerIO,a1
        move.w   #CMD_READ,IO_COMMAND(a1)
        move.l   Dnull,IO_LENGTH(a1)
        move.l   Anull,IO_DATA(a1)
        CALLEXEC DoIO
        move.l   IO_ACTUAL(a1),d0
        rts


wantsTIMEOUT
        lea      SerIO,a1
        move.w   #CMD_READ,IO_COMMAND(a1)
        move.l   Dnull,IO_LENGTH(a1)
        move.l   Anull,IO_DATA(a1)
        CALLEXEC SendIO		;DoIO would not return

        lea      TimeIO,a1
        move.w   #TR_ADDREQUEST,IO_COMMAND(a1)
        move.l   Deins,$24(a1)	;timeout in microsecs
        move.l   #0,$20(a1)	;0 secs
        CALLEXEC SendIO

;--------
waitEVENT
        clr.l    d0		;wait: either asked # of bytes arrive or
        clr.l    d1		;timerequest returns (timeout)

        lea      SerReply,a1	;generate waitmaske
        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		;timeout!enough_bytes

;--------
        lea      SerIO,a1	;ok, iam back who signaled me?
        CALLEXEC CheckIO	;was it the SerReqptr?
        beq      noSERIAL
        CALLEXEC WaitIO		;SERIAL did it: cleanup serial

        lea      TimeIO,a1	;abort timer
        CALLEXEC AbortIO
        lea      TimeIO,a1
        CALLEXEC WaitIO		;cleanup timer

        lea      SerIO,a1
        move.l   IO_ACTUAL(a1),d0 ;probably the IO_ACTUAL = # of asked bytes
        rts

;-------
noSERIAL
        lea      TimeIO,a1	;timeout?
        CALLEXEC CheckIO
        beq      noTIMER	;something else did it...return to sleep
        CALLEXEC WaitIO		;TIMER did it: cleanup timer

        lea       SerIO,a1	;abort serial
        CALLEXEC AbortIO
        lea       SerIO,a1
        CALLEXEC WaitIO		;cleanup serial

        lea      SerIO,a1
        move.l   IO_ACTUAL(a1),d0 ;probably IO_ACTUAL=0
        rts
;-------
noTIMER
	bra	 waitEVENT

;----------------------------------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
;---------------------------------xpr_ffirst
xpr_ffirst	;a0^buffer in which we must copy the first filename,0
		;a1^xpr_filename (from lib-call)

	tst.b	(a1)		;"amixpr s ",0
	beq	ffirst_null
	cmpi.b	#" ",(a1)	;"amixpr s  ",0
	beq	ffirst_null

ffirst_loop
	move.b	(a1)+,(a0)+

	tst.b	(a1)
	beq	ffirst_end	

	cmpi.b	#" ",(a1)
	beq	ffirst_end
	bra	ffirst_loop

ffirst_end
	move.b	#0,(a0) ;terminate name with zero
	move.l	a1,d0	;wird fnext uebergeben in d0!
        rts

ffirst_null
	clr.l	d0	;no file found
        rts
;---------------------------------xpr_fnext
xpr_fnext	;a0^buffer for the next filename

	move.l	d0,a1		;erwarte in d0 ^ auf ende vom letzten namen
                                ;                   oldname oldname
	tst.b	(a1)+           ;                                  ^
	beq	fnext_null	;"oldname",0
	tst.b	(a1)
	beq	fnext_null	;"oldname ",0
	cmpi.b	#" ",(a1)
	beq	fnext_null      ;"oldname  "

fnext_loop
	move.b	(a1)+,(a0)+

	tst.b	(a1)
	beq	fnext_end	

	cmpi.b	#" ",(a1)	;liest solange bis er ein space findet	
	beq	fnext_end
	bra	fnext_loop

fnext_end
	move.b	#0,(a0)
	move.l	a1,d0
	rts

fnext_null
	clr.l	d0	;no file found
        rts


;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;-=-=-=-= PROCEDURES -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


;----------------------------------
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

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

	move.l	UDwindowptr,a1
	move.l	wd_RPort(a1),a1
	move.l	#1,d0
	CALLGRAF	SetAPen		;colour of text in window

	move.l	UDwindowptr,a1
	move.l	wd_RPort(a1),a1

	move.l	#1*8,d0	
	move.l	#76,d1			;ypos stripe
	bsr	updatemove

	move	#51*8,d0	
	move	#76,d1	
	move.l  UDwindowptr,a1
	move.l	wd_RPort(a1),a1
	CALLGRAF	Draw

	moveq	#5,d5			;Anzahl Zeilen -1
text    moveq	#1*8,d0			;Text ausgeben
	move.l	yps,d1
	move.l	UDwindowptr,a1
	move.l	wd_RPort(a1),a1
	CALLGRAF	Move		;Cursor setzen
	move.l	UDwindowptr,a1
	move.l	wd_RPort(a1),a1
	move.l	tex,a0
	moveq	#50,d0
	CALLGRAF	Text
	add.l	#10,yps			;1 Zeile =10 Pixel hoch
	add.l	#50,tex			;1 Zeile =20 Zeichen
	dbra	d5,text

noopenWINDOW
	rts
;---------------------------------------;
closeWINDOW
        move.l   UDwindowptr,a0
        CALLINT  CloseWindow        
nocloseWINDOW
	rts
;---------------------------------------;



;--------------------------------------------
ULONGtoASCII	;a0->8byte Buffer for the String; d0=ULONG to work on
                ;this is ULONGtoDecimalstring not ULONGtoHEX$

		movem.l	d1/d2/a1,-(a7)

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

		movem.l	(a7)+,d1/d2/a1
		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
		cnop	0,4


;---------------------------------------;
HEXStringULONG	;a0^HEX$(8byte) a1^ULONG(4byte)

	movem.l	d0/d1/d2/a2,-(a7)	;save the registers we use
	move.l	#3,d1			;not a0! (must count on)
HEX00
	move.b	(a0)+,d0	;get first asciibyte
	bset.l	#5,d0		;only small chars. digits unchanged
	move.l	#15,d2          ;0123456789abcde or f
	lea	HEXTAB(pc),a2
HEX02
	cmp.b	(a2,d2),d0
	beq	HEX01
	dbra	d2,HEX02
HEX01
	mulu	#16,d2		;d2=position in hextab (0-15)
	move.b	d2,(a1)		;high nibble (*16)
	move.b	(a0)+,d0	;same with the low nibble
	bset.l	#5,d0		;change to small char
	move.l	#15,d2
HEX03
	cmp.b	(a2,d2),d0
	beq	HEX04
	dbra	d2,HEX03
HEX04
        add.b	d2,(a1)+	;add to highnib
	dbra	d1,HEX00	;4 times (e.g.: 00 c0 12 34)
	movem.l	(a7)+,d0/d1/d2/a2
	rts

HEXTAB	dc.b	"0123456789abcdef"
	cnop	0,4

;---------------------------------------;

;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;-=-=-=-= DATA -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

XPR_IO
	dc.l	0
	dc.l	xpr_fopen	;a pointer to this struct must be given
	dc.l	xpr_fclose	;whenever calling a xprlib function
	dc.l	xpr_fread
	dc.l	xpr_fwrite
	dc.l	xpr_sread
	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	;not implemented
	dc.l	0		;xpr_setserial	;not implemented
	dc.l	xpr_ffirst
	dc.l	xpr_fnext
	dc.l	xpr_finfo
	dc.l	xpr_fseek
	dc.l	4		;alle 4 EXT fields 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

;----------------------------------------------
SerIO		ds.b	96	;IOExtSer  Alloc for Message and Replyports
SerReply	ds.b	48

;----------------------------------------------
TimeIO		ds.b	48
TimeReply	ds.b	48
;----------------------------------------------
		cnop	0,4

UDwindowdef
		dc.w	14*8,5*8	;coordinates of left-top edge
		dc.w	52*8,14*8       ;x/y size
		dc.b	-1,-1
		dc.l	CLOSEWINDOW!RAWKEY
		dc.l	UDW_Gadgets!UDW_Extras
		dc.l	0
		dc.l	0
		dc.l	UDW_Title
SPTR		dc.l	_MYScreen		;SCREENPOINTER
		dc.l	0
		dc.w	0,0
		dc.w	0,0
STYPE		dc.w	CUSTOMSCREEN	;SCREENTYPE
		cnop	0,4

UDW_Gadgets	equ	WINDOWDRAG!WINDOWCLOSE
UDW_Extras	equ	SMART_REFRESH!ACTIVATE
		cnop	0,4

_XPRBase        dc.l    0
UDwindowptr	dc.l	0
Asave		dc.l	0
Anull		dc.l	0
Aeins		dc.l	0
Dnull		dc.l	0
Deins		dc.l	0
LBMin	dc.l	0	;^start of allocated logbuffer
		cnop	0,4

;-------


Ruelps	dc.b	"........",0
	cnop	0,4
Fill	dc.b	"                                                  " ;LEN=50
	cnop	0,4
;-------
msg	dc.b	"FileName:                                         " ;20
	dc.b	"FileSize:          :                              " ;30
	dc.b	"Position:          :                              " ;40
	dc.b	"APX Time:          :                              " ;50
	dc.b	" Elapsed:          :                              " ;60
	dc.b	"     CPS:          :                              " ;70
	cnop	0,4
tex	dc.l	msg		;write-pointer
yps	dc.l	20		;y-Startposition
;-------

TmpCps dc.l 0
TmpEff dc.l 0
TmpTim dc.l 0
TmpSiz dc.l 0

UDW_Title	dc.b	"         AmiXpress Transfer Window               ",0
		cnop	0,4
int_name	INTNAME
		cnop	0,4
timer_name	TIMERNAME
		cnop	0,4
dos_name	DOSNAME
		cnop	0,4
graf_name	GRAFNAME
		cnop	0,4

FIB		ds.b	260		;file-info-block alloc
		cnop	0,4

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


