		OPT	L-,C+,D-,M+                	;NOlink,case dependant,NOdebug

		;
		;  DOSWatch 1.0  MAY-1991
		;
		;  by
		;
		;  Andreas Voß Wrede
		;  Emdener Straße 11
		;  4400 Münster/Westfalen
		;  (WEST) GERMANY
		;  DATEXP: PSI%4589004317::VOSS_WREDE
		;
		;  with a little help from
		;  HiSoft GenAmiga V1.21 Assembler
		;

		INCDIR	"VWINC:"			;where to look

		;
		include	exec/exec.i
		include	exec/exec_lib.i			;I want to call EXEC
		include	exec/execbase.i			;I want to call EXEC
		include	libraries/dos_lib.i		;and DOS
		include	libraries/dos.i
		include	libraries/dosextens.i
		include	workbench/startup.i
		include	workbench/workbench.i
		include	workbench/icon_lib.i

		;
		; some startup code to make a Workbench execute look like the CLI
		; based loosely on RKM Vol 1 page 4-36
		;		
		EVEN

		movem.l	d0/a0,-(sp)			;save initial values

		clr.l	returnMsg			;WB message
		sub.l	a1,a1
		CALLEXEC FindTask			;find us
		move.l	d0,a4
		tst.l	pr_CLI(a4)			;called by a CLI?
		beq.s	fromWorkbench

		;
		; we were called from the CLI
		;
		move.b	#0,_WB				;WB flag
		bra	end_startup			;and run the user prog

		;
		; we were called from the Workbench
		;
fromWorkbench:	move.b	#1,_WB				;workbench flag
		lea	pr_MsgPort(a4),a0
		CALLEXEC WaitPort			;wait for a message
		lea	pr_MsgPort(a4),a0
		CALLEXEC GetMsg				;then get it
		move.l	d0,returnMsg			;save it for later reply

		;
		; do some other stuff here RSN like the command line etc
		; start by opening the DOS library
		;
end_startup:	move.l	#dosname,a1			;"dos.library"
		moveq	#0,d0				;any version
		CALLEXEC OpenLibrary
		move.l	d0,_DOSBase			;save pointer

		;
		; open icon lib to get WB parameter
		;
		move.l	#iconname,a1			;"icon.library"
		moveq	#0,d0				;any version
		CALLEXEC OpenLibrary
		move.l	d0,_ICONBase			;save pointer

		;
		; open my window 
		;
		move.l	#WindowName,d1
		move.l	#1005,d2			;mode old	
		CALLDOS	Open
		move.l	d0,_VWOutHandle			;output handle
		move.l	d0,_VWInpHandle			;input handle

		;
		; command interface regs from CLI or WB
		;
		movem.l	(sp)+,d0/a0			;restore regs
		cmp.b	#0,_WB				;son of WB?
		beq.s	_ComLin				;no,from CLI


		; WB parameter 
		; .info must be a project with DOSWatch as the
		;  default tool [the tool type entry is optional]
		; * IMPORTANT* .info file must be in same directory
		; as the tool DOSWatch
		;
		; e.g. default tool: DH3:DOSWatch -> sm_NumArgs=2
		; wa_Name(1)="DH3:DOSWatch"
		; wa_Name(2)="DOSWatch"

		move.l	returnMsg,a2			; WB message
		move.l	sm_ArgList(a2),a0		; arguments
		move.l	wa_Name(a0),a0			; get name of tool
		move.l	a0,a5				; save pointer

		move.l	_ICONBase,a6
		jsr	_LVOGetDiskObject(a6)		; read .info file

		tst.l	d0
		bne.s	_ObjOK				; cant read .info
		move.l	#_maintxt003,d2			; so print a 
		jsr	_VWQStrOut			; warning message
		move.l	a5,d2				; restore name
		jsr	_VWQStrOut
		move.l	#_maintxt004,d2
		jsr	_VWQStrOut


_ObjOK:		move.l	d0,a2
		move.l	do_ToolTypes(a2),a0
		move.l	(a0),a0				; ->tool type array
		move.l	a0,a2
		move.l	#0,d0				; find length of parameter
_fzero:		add.l	#1,d0
		cmp.b	#0,(a2)+
		bne.s	_fzero	

		; CLI call or tailored WorkBench SETUP
		;
		; check for leading ? in command line
		;
_ComLin:	cmp.l	#1,d0				; command line
		ble	_go				; NO parameter

		; 
		; we have to replace ending CR with ZERO due to open LOG
		; <d0> is length of command line
		;
		sub	#1,d0
		move.b	#0,(a0,d0)

		;
		; info required ?
		;
		cmp.b	#"?",(a0)
		bne.l	_check1

		;
		; print usage info text
		;
_check0:	move.l	#_maintxt00,d2
		jsr	_VWQStrOut
		move.l	#100,d1				; wait 2 sex
		CALLDOS	Delay
		bra	_fromMain

		;
		; print illegal parameter
		;
_check01:	move.l	#_maintxt001,d2
		jsr	_VWQStrOut
		move.l	#100,d1				; wait 2 sex
		CALLDOS	Delay
		bra	_fromMain

		;
		; check command line
		;
_check1:	cmp.b	#"I",(a0)+			; with read/write?
		beq.s	_check2
		sub.l	#1,a0
		bra.s	_check3
_check2:	cmp.b	#"O",(a0)+
		bne.s	_check01
		move.b	#1,_RWflag
		cmp.b	#3,d0
		ble	_go				; NO more qualifier
		cmp.b	#" ",(a0)+
		bne.s	_check01

_check3:	cmp.b	#"L",(a0)+			; LOG file requested?
		bne.s	_check01
		cmp.b	#"O",(a0)+
		bne.s	_check01
		cmp.b	#"G",(a0)+
		bne.s	_check01
		cmp.b	#" ",(a0)+
		bne.s	_check01

		;
		; open logfile
		;
		move.l	a0,d1				; filename start
		move.l	#1006,d2			; mode new
		CALLDOS	Open
		move.l	d0,_VWLogHandle			;log handle
		cmp.l	#0,d0
		bne	_go
		
		;
		; error opening  logfile
		;
		move.l	#_maintxt002,d2
		jsr	_VWQStrOut
		move.l	_LOGfile,d2
		jsr	_VWQStrOut
		move.l	#100,d1				; wait 2 sex
		CALLDOS	Delay
		bra	_fromMain

		;
		; main program
		;

_go:		bsr	_main				;call our program

		;
		; returns to here with exit code in d0
		;
_fromMain:	move.l	d0,-(sp)			;save it
		tst.l	returnMsg
		beq.s	exitToDOS			;if I was a CLI

		CALLEXEC Forbid
		move.l	returnMsg(pc),a1
		CALLEXEC ReplyMsg

		;
		; close window and DOS library
		;
exitToDOS:	move.l	_VWOutHandle,d1
		CALLDOS	Close		
		move.l	_DOSBase,a1
		CALLEXEC CloseLibrary

		; close icon lib
		;
		move.l	_ICONBase,a1
		CALLEXEC CloseLibrary

		move.l	(sp)+,d0			; restore exit code
		RTS

		;
		; startup code variable
		;
		EVEN
_WB:		dc.b	0
returnMsg:	dc.l	0
_VWOutHandle:	dc.l	0
_VWInpHandle:	dc.l	0
_DOSBase:	dc.l	0
_ICONBase:	dc.l	0
dosname		DOSNAME
		EVEN
iconname:	dc.b	"icon.library",0
		EVEN
WindowName:	dc.b	"CON:0/50/639/120/  DOSWatch V1.0  BY avw  [press F3 to quit]",0
		EVEN


		;
		; maiiiiiin proogram
		;

_main:		move.l	_SysBase,a6		; a very important adress
		move.l	ThisTask(a6),d5		; save it in d5
		move.l	d5,_ThisTask


	; get DOS dispatch vector

		move.l	_DOSBase,d0
		sub.l	#$1e,d0			;e.g. c04ada OPEN WB1.2 1MB
		addq	#4,d0
		move.l	d0,a1
		move.w	(a1),d1			;e.g. $68
		add.w	d1,d0
		move.l	d0,_DOSVec		;will be patched
		addq	#6,d0
		move.l	d0,_DOSVec1		;original code


	; get a free signal

		move.l	#-1,d0			; this one is for
		jsr	_LVOAllocSignal(a6)	; waking DOSWatch up -
		move.l	d0,_Signal		; from DOS calling task


	; init F3 dispatcher 

		jsr	_VWf3			; interrupt service F3 key

	; patch central DOS entry

		jsr	_LVODisable(a6)		; no interrupts
		move.l	_DOSVec,a0		; central DOS entry via LIB
		move.w	#$4ef9,(a0)+  		; JMP
		move.l	#_NEWcode,(a0)		; into my code
		jsr	_LVOEnable(a6)		; enable interrupting

	; prepare TV buffer

		jsr	_VWInitTV		; output into memory


	; BEGIN OF MAIN LOOP
	;
	; wait for signal from patch routine -
	; print some results if DOScall is NOT issued by this program

_main1:		move.l	_SysBase,a6			; 
		move.l	#8,d6				; digits _VWHexOut
		move.l	#0,_used			; reset used flag

	; wait for signal from patched DOS code executed by calling task

		move.l	_Signal,d0			; wait for this
		jsr	_LVOWait(a6)			; and waaiiiit

	; we got a signal - 
	; is it a signal from the F3 interrupt routine?

		move.l	_finish,d0			; may be set by
		cmp.l	#-1,d0				; F3 handler
		beq.l	_main5				; remove it


	; check RWflag (exclude READ WRITE calls ?)

		cmp.b	#0,_RWflag
		bne	_main1x				; DON'T ignore RW

		move.l	_DOSfunction,d0			; is it
		cmp.b	#-$03,d0			; READ ? 
		beq	_main1				; yes
							; is ist 
		cmp.b	#-$06,d0			; WRITE ?
		beq	_main1				; yes
		

   	; **** disable further DOS calls  during display ****

_main1x:	jsr	_LVODisable(a6)			; disable interrupting

	; timestamp and name of task who called DOS

		move.l	_DOSTask,a1			; calling task
		move.l	#_maintxt04,d2
		jsr	_VWMQStrOut			; string out 
		jsr	_VWMTimeStamp			; time string
		; print " from "
		move.l	#_maintxt05,d2
		jsr	_VWMQStrOut
		; name of task 
		move.l	10(a1),d2			; calling task name
		jsr	_VWMQStrOut			; and print

	; name of command loaded (only for a process)

		move.l	8(a1),d0			; put ln_type
		and.l	#$ff000000,d0			; into a byte
		rol.l	#8,d0				; 
		cmpi	#13,d0				; is it a process?
		bne.s	_main3				; NO

		move.l	pr_TaskNum(a1),d0		; Command Name
		beq.s	_main3				; empty
		move.l	#_maintxt34,d2			; [ delimiter
		jsr	_VWMQStrOut
		move.l	pr_CLI(a1),d2
		asl.l	#2,d2				; BCPL convert
		move.l	d2,a2
		move.l	cli_CommandName(a2),d2
		asl.l	#2,d2				; BCPL convert
		move.l	d2,a2
		move.l	#0,d4
		move.b	(a2),d4				; BCPL str len
		cmp.l	#15,d4
		ble.s	_main2
		move.l	#15,d4
_main2:		add.l	#1,d2				; BCPL string
		jsr	_VWMQStrOutB			; BCPL out
		move.l	#_maintxt35,d2			; ] delimiter
		jsr	_VWMQStrOut

	; called DOS function (contents of d0)

_main3:		; print %%%%%%%%%
		move.l	#_maintxt06,d2
		jsr	_VWMQStrOut
		jsr	_VWMPrtCrLf

		move.l	_DOSfunction,d0
		move.l	#8,d6			; 8 digits for output

	; process info about alled DOS function
	; move it into TV buffer

		; < Execute >,-$1b,_DOSRegD1,<NL>,< status:>
_mainf00:	cmp.b	#-$1b,d0
		bne	_mainf01
		move.l	#_maint00,d2
		jsr	_VWMQStrOut
		move.l	_DOSretD0,d0		; status
		jsr	_VWMHexOutZ
		move.l	#_maintxt01,d2		; = (
		jsr	_VWMQStrOut
		move.l	_DOSRegD1,d2		; command
		jsr	_VWMQStrOut
		move.l	#_maintxt02,d2		; ,
		jsr	_VWMQStrOut
		move.l	_DOSRegD2,d2		; input
		jsr	_VWMHexOutZ
		move.l	#_maintxt02,d2		; ,
		jsr	_VWMQStrOut
		move.l	_DOSRegD3,d0		; output
		jsr	_VWMHexOutZ
		bra	_main4

		; < IsInteractive >,-$1a,<NoName>,_DOSRegD1,< status:>
_mainf01:	cmp.b	#-$1a,d0
		bne	_mainf02
		move.l	#_maint01,d3
		jsr	_VWHH
		bra	_main4

		; < Parentdir >,$23,<NoName>,_DOSRegD1,< newlock:>
_mainf02:	cmp.b	#$23,d0
		bne	_mainf03
		move.l	#_maint02,d3
		jsr	_VWHH
		bra	_main4

		; < WaitForChar >,$57,<NoName>,_DOSRegD1,< status:>
_mainf03:	cmp.b	#$57,d0
		bne	_mainf04
		move.l	#_maint03,d3
		jsr	_VWHHH
		bra	_main4

		; < Delay >,$2f,<NoName>,_DOSRegD1,<NL>
_mainf04:	cmp.b	#$2f,d0
		bne	_mainf05
		move.l	#_maint04,d3
		jsr	_VWH
		bra	_main4

		; < DateStamp >,-$19,<NoName>,_DOSRegD1,<NL>
_mainf05:	cmp.b	#-$19,d0
		bne	_mainf06
		move.l	#_maint05,d3
		jsr	_VWH
		bra	_main4

		; < SetProtection >,-$18,_DOSRegD1,<NL>,< status:>
_mainf06:	cmp.b	#-$18,d0
		bne	_mainf07
		move.l	#_maint06,d3
		jsr	_VWHNH
		bra	_main4

		; < SetComment >,-$17,_DOSRegD1,<NL>,< status:>
_mainf07:	cmp.b	#-$17,d0
		bne	_mainf08
		move.l	#_maint07,d3
		jsr	_VWHNH
		bra	_main4

		; < DeviceProc >,-$16,_DOSRegD1,<NL>,< process:>
_mainf08:	cmp.b	#-$16,d0
		bne	_mainf09
		move.l	#_maint08,d3
		jsr	_VWHN
		bra	_main4

		; < QueuPacket >,-$15,<NoName>,_DOSRegD1,< status:>
_mainf09:	cmp.b	#-$15,d0
		bne	_mainf10
		move.l	#_maint09,d3
		jsr	_VWHH
		bra	_main4

		; < GetPacket >,-$14,<NoName>,_DOSRegD1,<status:>
_mainf10:	cmp.b	#-$14,d0
		bne	_mainf11
		move.l	#_maint10,d3
		jsr	_VWHH
		bra	_main4

		; < UnLoadSeg >,$52,<NoName>,_DOSRegD1,<NL>
_mainf11:	cmp.b	#$52,d0
		bne	_mainf12
		move.l	#_maint11,d3
		jsr	_VWH
		bra	_main4

		; < LoadSeg >,-$13,_DOSRegD1,<NL>,< segment:>
_mainf12:	cmp.b	#-$13,d0
		bne	_mainf13
		move.l	#_maint12,d3
		jsr	_VWHN
		bra	_main4

		; < Exit >,$02,<NoName>,_DOSRegD1,<NL>
_mainf13:	cmp.b	#$02,d0
		bne	_mainf14
		move.l	#_maint13,d3
		jsr	_VWH
		bra	_main4

		; < CreateProc >,-$12,_DOSRegD1,<NL>,< process:>
_mainf14:	cmp.b	#-$12,d0
		bne	_mainf15
		move.l	#_maint14,d2
		jsr	_VWMQStrOut
		move.l	_DOSretD0,d0		; process
		jsr	_VWMHexOutZ
		move.l	#_maintxt01,d2		; = (
		jsr	_VWMQStrOut
		move.l	_DOSRegD1,d2		; name
		jsr	_VWMQStrOut
		move.l	#_maintxt02,d2		; ,
		jsr	_VWMQStrOut
		move.l	_DOSRegD2,d0		; pri
		jsr	_VWMHexOutZ
		move.l	#_maintxt02,d2		; ,
		jsr	_VWMQStrOut
		move.l	_DOSRegD3,d0		; segment
		jsr	_VWMHexOutZ
		move.l	#_maintxt02,d2		; ,
		jsr	_VWMQStrOut
		move.l	_DOSRegD4,d0		; stack
		jsr	_VWMHexOutZ
		jsr	_VWMprintTrailer	; )
		bra	_main4

		; < IoErr >,-$11,<NoName>,<NL>,< error:>
_mainf15:	cmp.b	#-$11,d0
		bne	_mainf16
		move.l	#_maint15,d3
		jsr	_VW.H
		bra	_main4

		; < CurrentDir >,-$10,<NoName>,_DOSRegD1,< oldlock:>
_mainf16:	cmp.b	#-$10,d0
		bne	_mainf17
		move.l	#_maint16,d3
		jsr	_VWHH

		move.l	#_LockTXT,d2
		jsr	_VWMQStrOut
		move.l	_DOSRegD1,d0
		jsr	_VWLockInfo
		move.l	d0,d2
		jsr	_VWMQStrOut

		bra	_main4

		; < CreateDir >,-$0f,_DOSRegD1,<NL>,< lock:>
_mainf17:	cmp.b	#-$0f,d0
		bne	_mainf18
		move.l	#_maint17,d3
		jsr	_VWHN
		bra	_main4

		; < Info >,-$0e,<NoName>,_DOSRegD1,< status:>
_mainf18:	cmp.b	#-$0e,d0
		bne	_mainf19
		move.l	#_maint18,d3
		jsr	_VWHHH
		bra	_main4

		; < ExNext >,-$0d,<NoName>,_DOSRegD1,< status:>
_mainf19:	cmp.b	#-$0d,d0
		bne	_mainf20
		move.l	#_maint19,d3
		jsr	_VWHHH
		bra	_main4

		; < Examine >,-$0c,<NoName>,_DOSRegD1,< status:>
_mainf20:	cmp.b	#-$0c,d0
		bne	_mainf21
		move.l	#_maint20,d3
		jsr	_VWHHH

		move.l	#_LockTXT,d2
		jsr	_VWMQStrOut
		move.l	_DOSRegD1,d0
		jsr	_VWLockInfo
		move.l	d0,d2
		jsr	_VWMQStrOut

		bra	_main4

		; < DupLock >,$71,<NoName>,_DOSRegD1,< newlock:>
_mainf21:	cmp.b	#$71,d0
		bne	_mainf22
		move.l	#_maint21,d3
		jsr	_VWHH

		move.l	#_LockTXT,d2
		jsr	_VWMQStrOut
		move.l	_DOSretD0,d0
		jsr	_VWLockInfo
		move.l	d0,d2
		jsr	_VWMQStrOut

		bra	_main4

		; < UnLock >,$6d,<NoName>,_DOSRegD1,<NL>
_mainf22:	cmp.b	#$6d,d0
		bne	_mainf23
		move.l	#_maint22,d3
		jsr	_VWH
		bra	_main4

		; < Lock >,-$0b,_DOSRegD1,<NL>,< lock:>
_mainf23:	cmp.b	#-$0b,d0
		bne	_mainf24
		move.l	#_maint23,d3
		jsr	_VWHNH

		cmp.l	#-1,_DOSRegD2		; write
		bne.s	_mainf23_0
		move.l	#_maint23_0,d2
		jsr	_VWMQStrOut
		bra	_mainf23_1
_mainf23_0:	move.l	#_maint23_1,d2		; read
		jsr	_VWMQStrOut

_mainf23_1:	move.l	_DOSretD0,d0		; lock
		tst.l	d0
		beq	_main4
		move.l	#_LockTXT,d2
		jsr	_VWMQStrOut
		jsr	_VWLockInfo
		move.l	d0,d2
		jsr	_VWMQStrOut
		bra	_main4

		; < Rename >,-$0a,_DOSRegD1,<NL>,< status:>
_mainf24:	cmp.b	#-$0a,d0
		bne	_mainf25
		move.l	#_maint24,d2
		jsr	_VWMQStrOut
		move.l	_DOSretD0,d0		; hex
		jsr	_VWMHexOutZ
		move.l	#_maintxt01,d2		; = (
		jsr	_VWMQStrOut
		move.l	_DOSRegD1,d2		; name
		jsr	_VWMQStrOut
		move.l	_DOSRegD2,d2		; name
		jsr	_VWMQStrOut
		bra	_main4

		; < DeleteFile >,-$09,_DOSRegD1,<NL>,< status:>
_mainf25:	cmp.b	#-$09,d0
		bne	_mainf26
		move.l	#_maint25,d3
		jsr	_VWHN
		bra	_main4

		; < Seek >,-$08,<NoName>,_DOSRegD1,< status:>
_mainf26:	cmp.b	#-$08,d0
		bne	_mainf27
		move.l	#_maint26,d3
		jsr	_VWHHHH
		bra	_main4

		; < Output >,$42,<NoName>,<NL>,< file:>
_mainf27:	cmp.b	#$42,d0
		bne	_mainf28
		move.l	#_maint27,d3
		jsr	_VW.H
		bra	_main4

		; < Input >,$41,<NoName>,<NL>,< file:>
_mainf28:	cmp.b	#$41,d0
		bne	_mainf29
		move.l	#_maint28,d3
		jsr	_VW.H
		bra	_main4

		; < Write >,-$06,<NoName>,_DOSRegD1,< byte:>
_mainf29:	cmp.b	#-$06,d0
		bne	_mainf30
		move.l	#_maint29,d3
		jsr	_VWHHHH
		bra	_main4

		; < Read >,-$03,<NoName>,_DOSRegD1,< byte:>
_mainf30:	cmp.b	#-$03,d0
		bne	_mainf31
		move.l	#_maint30,d3
		jsr	_VWHHHH
		bra	_main4

		; < Close >,$5d,<NoName>,_DOSRegD1,<NL>
_mainf31:	cmp.b	#$5d,d0
		bne	_mainf32
		move.l	#_maint31,d3
		jsr	_VWH
		bra	_main4

		; < Open >,-$01,_DOSRegD1,<NL>,< file:>
_mainf32:	cmp.b	#-$01,d0
		bne	_main4
		move.l	#_maint32,d3
		jsr	_VWHNH

		cmp.l	#1005,_DOSRegD2
		bne.s	_mainf32_0		
		move.l	#_maint32_0,d2		; mode OLD
		jsr	_VWMQStrOut
		bra.s	_mainf32_1
_mainf32_0:	move.l	#_maint32_1,d2		; mode NEW
		jsr	_VWMQStrOut
_mainf32_1:	cmp.l	#0,_DOSretD0
		beq.s	_mainf32_2
		move.l	#_maint32_2,d2		; status SUCCESS
		jsr	_VWMQStrOut
		bra.s	_main4
_mainf32_2:	move.l	#_maint32_3,d2		; status FAILURE
		jsr	_VWMQStrOut


	; ***** enable multitasking *****


_main4:		jsr	_VWMPrtCrLf
		jsr	_LVOEnable(a6)		; enable interrupting

	; put result from memory onto sreen

		jsr	_VWResetTV
		jsr	_VWPrintTV

	; and log it into LOG file , if requested

		move.l	_VWLogHandle,d6
		cmp.b	#0,d6
		BEQ	_main1			; no log
		move.l	_VWOutHandle,d7
		move.l	d6,_VWOutHandle
		jsr	_VWPrintTV
		move.l	d7,_VWOutHandle
		BRA	_main1			; LOOP


	; this code is executed if you press F3
	;
	; remove interrupt routine

_main5:		jsr	_VWRemf3


	; restore THE original code by removing the patch

_RemCode:	move.l	_SysBase,a6
		jsr	_LVODisable(a6)		; no interrupts
		move.l	_DOSVec,a0		; DOS entry
		move.l	#$48E73F3E,(a0)+  	; MOVEM.L D2-7/A2-6,-(A7)
		move.w	#$91C8,(a0)		; SUBA.L  A0,A0
		jsr	_LVOEnable(a6)		; enable interrrupts

	; free memory allocated by TV buffer

		jsr	_VWCloseTV

	; wait a while - just to print the finish message

		move.l	#0,_used		; reset used flag
		move.l	#_maintxt03,d2
		jsr	_VWQStrOut
		move.l	#100,d1
		CALLDOS Delay

	; free the signal

		move.l	_Signal,d0
		move.l	_SysBase,a6
		jsr	_LVOFreeSignal(a6)

	; close log anyway

_mainX:		move.l	_VWLogHandle,d1
		CALLDOS	Close		

		RTS

		;
		; ------------- DATA of main program -------------------------
		;

		EVEN
_mainICR:	equ	$BFEC01			; interrupt control reg
_VWLogHandle:	dc.l	0			; 
_LOGfile	dc.l	0			; pointer to LOG name
_DOSVec:	dc.l	0			; original 
_DOSVec1:	dc.l	0
_DOSTask:	dc.l	0			; address of calling Task
_DOSfunction:	dc.l	0
_DOSRegD1:	dc.l	0
_DOSRegD2:	dc.l	0
_DOSRegD3:	dc.l	0
_DOSRegD4:	dc.l	0
_Signal:	dc.l	0
_ThisTask:	dc.l	0
_DOSretD0:	dc.l	0
_finish:	dc.l	0
_used:		dc.l	0
_RWflag		dc.b	0

		EVEN
_LockTXT:	dc.b	13,10,13,10,"  lock » ",0
		EVEN
_maintxt00:	dc.b	13,10,13,10,"%DOS-I-USE, USAGE: DOSWatch [IO] [LOG <file>]",13,10,0
		EVEN
_maintxt001:	dc.b	13,10,13,10,"%DOS-F-IPA, illegal parameter > USAGE: DOSWatch [IO] [LOG file]",13,10,0
		EVEN
_maintxt002:	dc.b	13,10,13,10,"%DOS-F-NLOG, error opening LOG file ",13,10,0
		EVEN
_maintxt003:	dc.b	13,10,"%DOS-W-TIGN, error opening ",0
		EVEN
_maintxt004:	dc.b	".info - can't get TOOL TYPE entry",13,10,0
		EVEN
_maintxt01:	dc.b	"=(",0
		EVEN
_maintxt02:	dc.b	",",0
		EVEN
_maintxt03:	dc.b	13,10,"%DOS-I-BYE, Thank You For Playing - Program will be finished in 2 seconds.. ",13,10,0
		EVEN
_maintxt04:	dc.b	13,10,"%%%% DOSWatch message at ",0
		EVEN
_maintxt05:	dc.b	" from  ",0
		EVEN
_maintxt06:	dc.b	" %%%%",13,10,0
		EVEN
_maintxt34:	dc.b	"[",0
		EVEN
_maintxt35:	dc.b	"]",0
		EVEN
_maint00:	dc.b	" status=",$9B,"0;33;40mExecute",$9B,"0;31;40m(string,file,file)",0
		EVEN
_maint01:	dc.b	" status=",$9B,"0;33;40mIsInteractive",$9B,"0;31;40m(file)",0
		EVEN
_maint02:	dc.b	" newLock=",$9B,"0;33;40mParentdir",$9B,"0;31;40m(lock)",0
		EVEN
_maint03:	dc.b	" status=",$9B,"0;33;40mWaitForChar",$9B,"0;31;40m(file,timeout)",0
		EVEN
_maint04:	dc.b	" VOID ",$9B,"0;33;40mDelay",$9B,"0;31;40m(timeout)",0
		EVEN
_maint05:	dc.b	" ^date=",$9B,"0;33;40mDateStamp",$9B,"0;31;40m(date)",0
		EVEN
_maint06:	dc.b	" status=",$9B,"0;33;40mSetProtection",$9B,"0;31;40m(name,mask)",0
		EVEN
_maint07:	dc.b	" status=",$9B,"0;33;40mSetcomment",$9B,"0;31;40m(name,comment)",0
		EVEN
_maint08:	dc.b	" processID=",$9B,"0;33;40mDeviceProc",$9B,"0;31;40m(name)",0
		EVEN
_maint09:	dc.b	" status=",$9B,"0;33;40mQueuePacket",$9B,"0;31;40m(packet)",0
		EVEN
_maint10:	dc.b	" status=",$9B,"0;33;40mGetPacket",$9B,"0;31;40m(waitflag)",0
		EVEN
_maint11:	dc.b	" VOID ",$9B,"0;33;40mUnLoadSeg",$9B,"0;31;40m(segment)",0
		EVEN
_maint12:	dc.b	" segment=",$9B,"0;33;40mLoadSeg",$9B,"0;31;40m(filename)",0
		EVEN
_maint13:	dc.b	" VOID ",$9B,"0;33;40mExit",$9B,"0;31;40m(returnCode)",0
		EVEN
_maint14:	dc.b	" processID=",$9B,"0;33;40mCreateProc",$9B,"0;31;40m(name,pri,segList,stackSize)",13,10,13,10," ",0
		EVEN
_maint15:	dc.b	" error=",$9B,"0;33;40mIOErr",$9B,"0;31;40m()",0
		EVEN
_maint16:	dc.b	" oldLock=",$9B,"0;33;40mCurrentDir",$9B,"0;31;40m(lock)",0
		EVEN
_maint17:	dc.b	" lock=",$9B,"0;33;40mCreateDir",$9B,"0;31;40m(name)",0
		EVEN
_maint18:	dc.b	" status=",$9B,"0;33;40mInfo",$9B,"0;31;40m(lock,parameterBlock)",0
		EVEN
_maint19:	dc.b	" status=",$9B,"0;33;40mEXNext",$9B,"0;31;40m(lock,fileInfoBlock)",0
		EVEN
_maint20:	dc.b	" status=",$9B,"0;33;40mExamine",$9B,"0;31;40m(lock,fileInfoBlock)",0
		EVEN
_maint21:	dc.b	" newLock=",$9B,"0;33;40mDupLock",$9B,"0;31;40m(lock)",0
		EVEN
_maint22:	dc.b	" VOID ",$9B,"0;33;40mUnLock",$9B,"0;31;40m(lock)",0
		EVEN
_maint23:	dc.b	" lock=",$9B,"0;33;40mLock",$9B,"0;31;40m(name,type)",0
		EVEN
_maint23_0:	dc.b	" XWrite",0
		EVEN
_maint23_1:	dc.b	" SRead",0
		EVEN
_maint24:	dc.b	" status=",$9B,"0;33;40mRename",$9B,"0;31;40m(oldName,newName)",0
		EVEN
_maint25:	dc.b	" status=",$9B,"0;33;40mDeleteFile",$9B,"0;31;40m(name)",0
		EVEN
_maint26:	dc.b	" position=",$9B,"0;33;40mSeek",$9B,"0;31;40m(file,position,offset)",0
		EVEN
_maint27:	dc.b	" file=",$9B,"0;33;40mOutPut",$9B,"0;31;40m()",0
		EVEN
_maint28:	dc.b	" file=",$9B,"0;33;40mInPut",$9B,"0;31;40m()",0
		EVEN
_maint29:	dc.b	" byte=",$9B,"0;33;40mWrite",$9B,"0;31;40m(file,buffer,length)",0
		EVEN
_maint30:	dc.b	" byte=",$9B,"0;33;40mRead",$9B,"0;31;40m(file,buffer,length)",0
		EVEN
_maint31:	dc.b	" VOID ",$9B,"0;33;40mClose",$9B,"0;31;40m(file)",0
		EVEN
_maint32:	dc.b	" file=",$9B,"0;33;40mOpen",$9B,"0;31;40m(name,accessMode)",0
		EVEN
_maint32_0:	dc.b	13,10,13,10,"  mode: OLD",0
		EVEN
_maint32_1:	dc.b	13,10,13,10,"  mode: NEW",0
		EVEN
_maint32_2:	dc.b	"  status: SUCCESS",0
		EVEN
_maint32_3:	dc.b	"  status: FAILURE",0

		;
		; ------------- SUBS of main program -------------------------
		;

		; this code is for watching DOS calls
		; function code is in d0
		;
		EVEN
_NEWcode:	movem.l	d0-d2/a6,-(sp)		; save some regs
		move.l	_SysBase,a6
		move.l	ThisTask(a6),d2		; address of calling task
		move.l	_ThisTask,d1		; compare with DOSWatch
		cmp.l	d1,d2
		bne	_NEWcode1		; calling Task is NOT me
		bra	_NEWcode2		; NO watch

_NEWcode1:	cmp.l	#0,_used		; 
		beq	_NEWcode3		; used = 0 ,so watch

		move.l	#$BFE001,a6		; LED off
		bset	#1,(a6)
		moveq	#$2f,d0			; DELAY DOS function
		move.l	#1,d1			; wait 1/50 sec
		move.l	_DOSBase,a6		; 
		move.l	#_NEWcode1,-(sp)	; return PC
		MOVEM.L	D2-D7/A2-A6,-(A7)	; orig DOS code
		SUBA.L	A0,A0			; orig DOS code
		move.l	_DOSVec1,-(sp)		; PC just behind patch
		RTS				; call DOS


_NEWcode2:	movem.l	(sp)+,d0-d2/a6		; NO DOSWatch watch
	        MOVEM.L D2-D7/A2-A6,-(A7)	; part of orig code
	        SUBA.L  A0,A0			; part of orig code
		move.l	_DOSVec1,-(sp)		; jump to DOS function
		RTS

_NEWcode3:	move.l	#$BFE001,a6		; LED on
		bclr	#1,(a6)

		move.l	d2,_DOSTask		; save calling task
		move.l	#_used,a6		; incr used_flag
		add.l	#1,(a6)			; 
		movem.l	(sp)+,d0-d2/a6		; restore regs
		move.l	#_NEWcode_1,-(sp)	; this PC for return DOS
	        MOVEM.L D2-D7/A2-A6,-(A7)	; part of orig code
	        SUBA.L  A0,A0			; part of orig code
		move.l	d0,_DOSfunction		; SAVE
		move.l	d1,_DOSRegD1		;  SOME
		move.l	d2,_DOSRegD2		;   IMPORTANT
		move.l	d3,_DOSRegD3		;    VALUES
		move.l	d4,_DOSRegD4		;     FOR LOG
		move.l	_DOSVec1,-(sp)		; jump to DOS function
		RTS

		; woww, just returned from DOS function 
		; note that DOSWatch does NOT reach this code!
		;
_NEWcode_1:	movem.l	d0-d7/a0-a6,-(sp)
		move.l	_SysBase,a6
		move.l	d0,_DOSretD0		; save it
		move.l	_ThisTask,a1		; let DOSWatch know that
		move.l	_Signal,d0		; DOS was called
		jsr	_LVOSignal(a6)
_NEWcode_2:	movem.l	(sp)+,d0-d7/a0-a6
		RTS				; return to DOS caller

		; print string in D3 with header
		;
		EVEN
_VWMprintHeader:	
		move.l	d2,-(sp)
		move.l	#_VWheader,d2
		jsr	_VWMQStrOut
		move.l	d3,d2
		jsr	_VWMQStrOut
		move.l	#_VWheader1,d2
		jsr	_VWMQStrOut
		move.l	(sp)+,d2
		RTS
_VWheader:	dc.b	" ",0
_VWheader1:	dc.b	"   ",0
		EVEN

		; print trailer
		;
		EVEN
_VWMprintTrailer:
		move.l	d2,-(sp)
		move.l	#_VWTrailer,d2
		jsr	_VWMQStrOut
		move.l	(sp)+,d2
		RTS
_VWTrailer:	dc.b	") ",0
		EVEN
	
		; hex = (hex)
		;
_VWHH:		jsr	_VWMprintHeader
		move.l	_DOSretD0,d0		; hex
		jsr	_VWMHexOutZ
		move.l	#_maintxt01,d2		; = (
		jsr	_VWMQStrOut
		move.l	_DOSRegD1,d0		; hex
		jsr	_VWMHexOutZ
		jsr	_VWMprintTrailer
		RTS

		; hex =(hex,hex)
		;
_VWHHH:		jsr	_VWMprintHeader
		move.l	_DOSretD0,d0		; hex
		jsr	_VWMHexOutZ
		move.l	#_maintxt01,d2		; = (
		jsr	_VWMQStrOut
		move.l	_DOSRegD1,d0		; hex
		jsr	_VWMHexOutZ
		move.l	#_maintxt02,d2		; ,
		jsr	_VWMQStrOut
		move.l	_DOSRegD2,d0		; hex
		jsr	_VWMHexOutZ
		jsr	_VWMprintTrailer
		RTS

		; =(hex)
		;
_VWH:		jsr	_VWMprintHeader
		move.l	#_maintxt01,d2		; = (
		jsr	_VWMQStrOut
		move.l	_DOSRegD1,d0		; hex
		jsr	_VWMHexOutZ
		jsr	_VWMprintTrailer
		RTS

		; hex=(name,hex)
		;
_VWHNH:		jsr	_VWMprintHeader
		move.l	_DOSretD0,d0		; hex
		jsr	_VWMHexOutZ
		move.l	#_maintxt01,d2		; = (
		jsr	_VWMQStrOut
		move.l	_DOSRegD1,d2		; name
		jsr	_VWMQStrOut
		move.l	#_maintxt02,d2		; ,
		jsr	_VWMQStrOut
		move.l	_DOSRegD2,d0		; hex
		jsr	_VWMHexOutZ
		jsr	_VWMprintTrailer
		RTS

		; hex=(hex,hex,hex)
		;		
_VWHHHH:	jsr	_VWMprintHeader
		move.l	_DOSretD0,d0		; hex
		jsr	_VWMHexOutZ
		move.l	#_maintxt01,d2		; = (
		jsr	_VWMQStrOut
		move.l	_DOSRegD1,d0		; hex
		jsr	_VWMHexOutZ
		move.l	#_maintxt02,d2		; ,
		jsr	_VWMQStrOut
		move.l	_DOSRegD2,d0		; hex
		jsr	_VWMHexOutZ
		move.l	#_maintxt02,d2		; ,
		jsr	_VWMQStrOut
		move.l	_DOSRegD3,d0		; hex
		jsr	_VWMHexOutZ
		jsr	_VWMprintTrailer
		RTS

		; hex=(name)
		;
_VWHN:		jsr	_VWMprintHeader
		move.l	_DOSretD0,d0		; hex
		jsr	_VWMHexOutZ
		move.l	#_maintxt01,d2		; = (
		jsr	_VWMQStrOut
		move.l	_DOSRegD1,d2		; name
		jsr	_VWMQStrOut
		jsr	_VWMprintTrailer
		RTS

		; hex =()
		;
_VW.H:		jsr	_VWMprintHeader
		move.l	_DOSretD0,d0		; hex
		jsr	_VWMHexOutZ
		move.l	#_maintxt01,d2		; = (
		jsr	_VWMQStrOut
		jsr	_VWMprintTrailer
		RTS

		; init F3 interrupt dispatcher
		;
_VWf3:		movem.l	d0/a1/a6,-(sp)		; for local variables
		move.l	#VBIStruc,a1		; prepare vertical
		move.l	#VBI_name,10(a1)	; interrupt routine
		move.l	#VBI_data,14(a1)	; no data needed
		move.l	#VBI_code,18(a1)	; but code
		move.l	#5,d0			; interrupt number VBI
		jsr	_LVOAddIntServer(a6)	; add server
		movem.l	(sp)+,d0/a1/a6		; restore stack
		RTS				; that's all

VBIStruc:	dc.l	0			; ln_succ
		dc.l	0			; ln_pred
		dc.b	2			; ln_type
		dc.b	0			; ln_pri
		dc.l	0			; ln_name
		dc.l	0			; ln_data
		dc.l	0			; ln_code
VBI_data:	ds.l	1			; data space
VBI_name:	dc.b	"F3-DOSWatch",0		; interrupt name

		; VBI interrupt routine (runs in supervisor mode)
		; <PC.l and SR.w and d0-d1/a0-a1/a5-a6 on super stack>
		;
		EVEN
VBI_code:	movem.l	d0-d2/a2/a6,-(sp)	; for local vars save on SS
		cmp.b	#$5b,VBI_ICR		; is F3 pressed ?
		bne.s	VBI_end			; NO
		move.l	#-1,d0
		move.l	d0,_finish
		move.l	_SysBase,a6
		move.l	_ThisTask,a1		; let task know that
		move.l	_Signal,d0		; F3 was called
		jsr	_LVOSignal(a6)
VBI_end:	movem.l	(sp)+,d0-d2/a2/a6	; restore REGS
		RTS				; return to EXEC code
VBI_ICR		equ	$BFEC01			; interrupt control reg

		; remove interrupt server, cause it runs in task context
		;
		EVEN
_VWRemf3:	movem.l	d0/a1/a6,-(sp)
		move.l	#5,d0
		move.l	#VBIStruc,a1
		move.l	_SysBase,a6
		jsr	_LVORemIntServer(a6)
		movem.l	(sp)+,d0/a1/a6
		RTS

		; set D0 to  Name of locked file ; input D0=lock
		;
		EVEN
_VWLockInfo:	movem.l	d1-d7/a0-a6,-(sp)
		move.l	d0,d1
		move.l	#_InfoBlock,d2
		CALLDOS Examine		
		move.l	#_InfoBlock,d0
		add.l	#8,d0
		movem.l	(sp)+,d1-d7/a0-a6
		RTS

		CNOP 0,4			; address of _InfoBlock
_InfoBlock:	ds.b	260			; MUST be on longword
						; boundary

		; print carriage return & line feed on pTVbuf
		;
		EVEN
_VWMPrtCrLf:	movem.l	d0-d7/a0-a6,-(sp)
		move.l	#_VWCrLf,d2
		jsr	_VWMQStrOut
		movem.l	(sp)+,d0-d7/a0-a6
		RTS
_VWCrLf:	dc.b	13,10,0


		; copy a string D2 into memory pTVbuf
		; endByte=$0 or ETVbuf or D4.L		D4.L overwritten!!!
		; 
		EVEN
_VWMQStrOut:	move.l	#$ffff,d4
_VWMQStrOutB:	movem.l	d0-d7/a0-a6,-(sp)
		move.l	d2,a0				;source
		move.l	_VWpTVbuf,a1			;destination
		move.l	_VWETVbuf,d1			;end of tv buff
		move.l	#0,d3				;string length
_VWMQStrOut_1:	cmp.l	d4,d3				;max chars
		beq.s	_VWMQStrOut_2
		cmp.b	#0,(a0)
		beq.s	_VWMQStrOut_2
		move.b	(a0)+,(a1)+			;copy
		addq	#1,d3				;d3 = length
		cmp.l	a1,d1				;tv buff end?
		ble.s	_VWMQStrOut_2
		bra.s	_VWMQStrOut_1			;no
_VWMQStrOut_2:	move.l	_VWpTVbuf,d0
		add.l	d3,d0
		move.l	d0,_VWpTVbuf
		movem.l	(sp)+,d0-d7/a0-a6
		RTS

		; Hexadecimal output d0 to pTVbuf
		; d6=#8 LONG , d6=#4 WORD , d6=#2 BYTE
		; suppresses leading zeros
		;
		EVEN
_VWMHexOut:	movem.l	d0-d7/a0-a6,-(sp)
		move.l	#0,d3				;blank flag
		bra.s	_VWMHexOut_0
_VWMHexOutZ:	movem.l	d0-d7/a0-a6,-(sp)
		move.l	#1,d3				;no blanks
_VWMHexOut_0:	move.l	_VWETVbuf,d1			;check border
		move.l	_VWpTVbuf,d2			;current pointer		
		add.l	d6,d2				
		cmp.l	d2,d1
		ble	_VWMHexOut_2			;sorry,buffer full

		move.l	#32,d1				;lead zero flag
		move.l	_VWpTVbuf,a1
		move.l 	d0,d7				;save d0
_VWMHexOut_1:	move.l 	d7,d0				;restore d0
		rol.l	#4,d0				;rotate left 4 bits	
		move.l	d0,d7				;save modified d0
		jsr	_VWMNibOut
		subq.b	#1,d6				;counter -1 
		bne	_VWMHexOut_1
_VWMHexOut_2:	movem.l	(sp)+,d0-d7/a0-a6
		RTS

_VWMNibOut:	and.l	#15,d0				;bits 31-4 clear
		cmp.b	#9,d0				;d0 <=9 ?
		ble.s	_VWMNibOut_1
		add.b	#7,d0
_VWMNibOut_1:	add.b	#48,d0

		cmpi	#1,d6				;ignore last digit
		beq.s	_VWMNibOut_2
		cmpi	#48,d0				;zero suppress
		bne.s	_VWMNibOut_2
		cmpi	#32,d1
		bne.s	_VWMNibOut_2
		move.b	#32,d0
		cmpi	#1,d3
		bne.s	_VWMNibOut_2
		move.b	d0,d1				;zero flag
		RTS		

_VWMNibOut_2:	move.b	d0,(a1)+
		move.l	a1,_VWpTVbuf
		move.b	d0,d1				;zero flag
		RTS

		; init TV buffer
		;
		EVEN
_VWInitTV:	movem.l	a0-a6/d0-d7,-(sp)
		move.l	#MEMF_CHIP,d1			;chip mem
		move.l	#20000,d0			;mem size
		CALLEXEC AllocMem		
		tst.l	d0
		bgt.s	_VWInitTV1			;ok
		move.l	_VWTVbufSpare,d0
_VWInitTV1:	move.l	#_VWpTVbuf,a1			;init pTVbuf
		move.l	d0,(a1)
		move.l	d0,_VWTVbuf
		move.l	#20000,d1
		add.l	d1,d0
		sub.l	#1,d0				;for zero terminator	
		move.l	d0,_VWETVbuf			;buffer end
		movem.l	(sp)+,a0-a6/d0-d7
		RTS

		EVEN
_VWTVbufSpare:	ds.b	80				;spare buf 
		EVEN
_VWTVbuf:	dc.l	0				;adr of TVbuf
_VWETVbuf:	dc.l	0				;end of TVBuf
_VWpTVbuf:	dc.l	0				;curr pointer


		; reset TVBuf
		;
		EVEN
_VWResetTV:	move.l	a1,-(sp)
		move.l	_VWpTVbuf,a1
		move.b	#0,(a1)+			;terminator 0
		move.l	#_VWpTVbuf,a1
		move.l	_VWTVbuf,(a1)
		move.l	(sp)+,a1
		RTS

		; print TVBuf
		;
		EVEN
_VWPrintTV:	movem.l	a0-a6/d0-d7,-(sp)
		move.l	_VWTVbuf,d2
		jsr	_VWQStrOut
		movem.l	(sp)+,a0-a6/d0-d7
		RTS


		; close TV buffer , deallocate mem
		;
_VWCloseTV:	movem.l	a0-a6/d0-d7,-(sp)
		move.l	_VWTVbuf,a1
		move.l	#20000,d0
		CALLEXEC FreeMem
		movem.l	(sp)+,a0-a6/d0-d7
		RTS


		; Hexadecimal output d0 to OutHandle
		; d6=#8 LONG , d6=#4 WORD , d6=#2 BYTE
		;
		EVEN
_VWHexOut:	movem.l	d0-d7/a0-a6,-(sp)
		move.l 	d0,d7				;save d0
		move.l	_VWOutHandle,d1
		move.l	#_VWChrOut_buf,d2		;the byte's buffer
		move.l	_DOSBase,a6
		moveq	#1,d3				;print one byte
_VWHexOut_1:	move.l 	d7,d0				;restore d0
		rol.l	#4,d0				;rotate left 4 bits	
		move.l	d0,d7				;save modified d0
		jsr	_VWNibOut
		subq.b	#1,d6				;counter -1 
		bne	_VWHexOut_1
		movem.l	(sp)+,d0-d7/a0-a6
		RTS
_VWNibOut:	and.l	#15,d0				;bits 31-4 clear
		cmp.b	#9,d0				;d0 <=9 ?
		ble.s	_VWNibOut_1
		add.b	#7,d0
_VWNibOut_1:	add.b	#48,d0
		move.b	d0,_VWChrOut_buf
		movem.l	d0-d7/a0-a6,-(sp)
		jsr	_LVOWrite(a6)
		movem.l	(sp)+,d0-d7/a0-a6
		RTS
_VWChrOut_buf:	dc.b	0

		; copy a string to OutHandle start=d2, endByte=$0
		; or for _VWQStrOutB length=D4.L
		; [max. string length=10000]
		;
		EVEN
_VWQStrOut:	movem.l	d0-d7/a0-a6,-(sp)
		move.l	d2,a0
		moveq	#0,d3
_VWQStrOut_1:	cmpi	#10000,d3
		beq.s	_VWQStrOut_2
		addq	#1,d3				;d3 = length
		cmp.b	#0,(a0)+
		bne	_VWQStrOut_1		
		bra.s	_VWQStrOut_2

_VWQStrOutB:	movem.l	d0-d7/a0-a6,-(sp)
		move.l	d4,d3				;d4 = lenght

_VWQStrOut_2:	move.l	_VWOutHandle,d1
		move.l	_DOSBase,a6
		jsr	_LVOWrite(a6)
		movem.l	(sp)+,d0-d7/a0-a6
		RTS

		; Print a time Stamp 
		;
_VWMTimeStamp:	movem.l	d0-d7/a0-a6,-(sp)
		move.l	#3,d6			; digits for DECout
		move.l	#TimeStampVEC,d1
		CALLDOS	DateStamp
		move.l	#TimeStampVEC,a0
		move.l	4(a0),d0		; minutes since midnight
		move.l	d0,d1			; save it
		move.l	8(a0),d7		; 1/50 seconds in this minute
		divu	#60,d0			; midnight minutes /60
		move.l	d0,d3			; and minutes
		and.l	#$0000ffff,d0		; low order word is hours
		jsr	_VWMDecOutZ		; hours
		move.l	#TimeStampTXT,d2
		jsr	_VWMQStrOut
		move.l	d3,d0
		and.l	#$ffff0000,d0		; high order word is minutes
		swap	d0			; nibble swap
		jsr	_VWMDecOutZ		; hours
		move.l	#TimeStampTXT,d2
		jsr	_VWMQStrOut
		divu	#50,d7
		move.l	d7,d0
		and.l	#$0000ffff,d0		; low order word is second
		jsr	_VWMDecOutZ		; hours
		movem.l	(sp)+,d0-d7/a0-a6
		RTS

TimeStampVEC:	dc.l	0
		dc.l	0
		dc.l	0
TimeStampTXT:	dc.b	8,":",0

		; Copy D0 decimal converted to _VWOutHandle
		; D6 = digit count ;Max=11 ; leading ZEROS
		;
		EVEN
_VWDecOutZ:	move.l	d2,-(sp)
		jsr	_VWDecConvZ
		jsr	_VWQStrOut
		move.l	(sp)+,d2		
		RTS

		;  D0 convert to decimal ; D2 is ReceiveBufAdr
		;  D6 = digit count max=11 ; with leading ZERO
		;
		EVEN
_VWDecConvZ:	movem.l	d0/d1/d3/d4/a0/a5,-(sp)
		move.l	#0,d4			; zero flag
		move.l	#11,d1
		move.l	#_VWDecConvBuf,a5
		tst.l	d0
		bne.s	_VWDecConv0
		move.l	#1,d4
		move.l	#1,d0			;treat as zero
_VWDecConv0:	bmi.s	_VWDecConv1
		neg.l	d0
		move.b	#" ",10(a5)
		bra.s	_VWDecConv2
_VWDecConv1:	move.b	#"-",10(a5)
_VWDecConv2:	move.b	#0,11(a5)
		move.l	#_VWDecConvTab,a0
		clr.w	d1
_VWDecConv3:	move.l	(a0)+,d2
		beq.s	_VWDecConv6
		move.l  #-1,d3
_VWDecConv4:	add.l	d2,d0
		dbgt	d3,_VWDecConv4
		sub.l	d2,d0
		addq.w	#1,d3
		bne.s	_VWDecConv5
		tst.w	d1			;lead zero
		bne.s	_VWDecConv5		;yes
		move.b	#"0",(a5)+
		bra.s	_VWDecConv3
_VWDecConv5:	move.l	#-1,d1
		neg.b	d3
		addi.b	#"0",d3
		move.b	d3,(a5)+
		bra.s	_VWDecConv3
_VWDecConv6:	neg.b	d0
		addi.b	#"0",d0
		move.b	d0,(a5)+
		move.l	#_VWDecConvBuf,d2
		cmp.l	#0,d4			;was it a zero?
		beq.s	_VWDecConv60		;no
		sub.l	#1,a5				
		move.b	#"0",(a5)
_VWDecConv60:	move.l	#11,d1
		sub.l	d6,d1
		add.l	d1,d2
		move.l	d2,a0
		sub.l	#1,a0
		cmp.b	#"0",(a0)		
		beq.s	_VWDecConv7
		add.l	#1,a0
		move.b	#"*",(a0)

_VWDecConv7:	movem.l	(sp)+,d0/d1/d3/d4/a0/a5
		RTS

_VWDecConvTab:	dc.l	1000000000
		dc.l	 100000000
		dc.l	  10000000
		dc.l	   1000000
		dc.l	    100000
		dc.l	     10000
		dc.l	      1000
		dc.l	       100
		dc.l	        10
		dc.l	         0
_VWDecConvBuf:	ds.b	12

		; Copy D0 decimal converted to _VWOutHandle
		; D6 = digit count ;Max=11 ; leading ZEROS
		;
		EVEN
_VWMDecOutZ:	move.l	d2,-(sp)
		jsr	_VWDecConvZ
		jsr	_VWMQStrOut
		move.l	(sp)+,d2		
		RTS

		END

