_LVODateStamp	=	-$C0
_LVODateToStr	=	-$2E8

		section	GetTime,code

ProgStart:	move.l	4.w,a6
		lea	DOSName(pc),a1
		jsr	-408(a6)
		move.l	d0,_DOSBase
		beq.s	DOSFailed

		move.l	d0,a6
		lea	StampStruct(pc),a0
		move.l	a0,d1
		jsr	_LVODateStamp(a6)
		lea	StampStruct(pc),a0
		move.l	a0,d1
		bsr	_DateToStr		;_LVODateToStr(a6)

CloseDOS:	move.l	4.w,a6
		move.l	_DOSBase(pc),a1
		jsr	-414(a6)

DOSFailed:	moveq	#0,d0
		rts

_DOSBase:	dc.l	0
DOSName:	dc.b	'dos.library',0
		even

FORMAT_DOS	equ	0		; dd-mmm-yy
FORMAT_INT	equ	1		; yy-mm-dd
FORMAT_USA	equ	2		; mm-dd-yy
FORMAT_CDN	equ	3		; dd-mm-yy

StampStruct:	ds.l	1		;00  ds_Days      - Number of days since Jan. 1, 1978
		ds.l	1		;04  ds_Minute    - Number of minutes past midnight 
		ds.l	1 		;08  ds_Tick      - Number of ticks past minute 

		dc.b	FORMAT_DOS	;12  dat_Format   - Controls appearance of dat_StrDate
		dc.b	0 		;13  dat_Flags    - Substitute Future, Tomorrow, etc.

		dc.l	CurrDay		;14  dat_StrDay   - Day of the week string (CPTR)
		dc.l	CurrDate	;18  dat_StrDate  - Date string (CPTR)
		dc.l	CurrTime	;22  dat_StrTime  - Time string (CPTR)

CurrDay:	ds.b	16		;ascii "day of week"
CurrDate:	ds.b	16		;"01-Jan-78",0
CurrTime:	ds.b	16		;"00:00:00",0
		cnop	0,4

; /* [DateToStr] ************************************************************/
;
; Below is a Dissassembly from the AMIGA-ROM 3.0 of "dos.library" 
; _LVODateToStr routine which converts a DOS DateStamp to the ascii
; date equivelents ; Day, Date & Time.
;

_DateToStr:	move.l	d1,a0
		movem.l	d2-d7/a2-a5,-(sp)
		move.l	a0,a5

*-------------- Get dat_Format (dd-mmm-yy), (yy-mm-dd), (mm-dd-yy), (dd-mm-yy)

		moveq	#0,d7
		move.b	12(a5),d7	;dat_Format
		blt.s	.weird1

		moveq	#3,d0
		cmp.l	d0,d7
		ble.s	.weird2

.weird1:	moveq	#0,d7
.weird2:	lsl.w	#2,d7

*-------------- Get dat_StrDate (destination buffer)

		move.l	18(a5),d0	;dat_StrDate
		beq	Make_Time	;is there a string ptr?

*-------------- Generate Date

		move.l	d0,a1
		lea	seperator.txt(pc),a0
		moveq	#9,d0
copy_time:	move.b	(a0)+,(a1)+	;fill buffer with seperate_string
		dbra	d0,copy_time

		lea	YearTable1(pc),a4
		add.l	d7,a4
		move.l	(a5),d4		;ds_Days

		cmp.l	#36500,d4	;past 100 years of dates?
		bcc	FormatErr	;if so format error...

		addq.l	#1,d4
		moveq	#2,d5
		moveq	#78,d2

_DT9:		move.l	#365,d3
		and.b	#3,d5
		bne.s	_DT8
		addq.l	#1,d3
_DT8:		cmp.l	d3,d4
		ble.s	_DT7
		sub.l	d3,d4
		addq.w	#1,d2
		addq.b	#1,d5
		bra.s	_DT9

_DT7:		move.l	d2,d1
		cmp.w	#100,d1
		blt.s	_DT6
		sub.w	#100,d1
_DT6:		bsr.s	makeascii2

		lea	MonthTable1(pc),a2
		and.b	#3,d5
		bne.s	_DT5

		lea	MonthTable2(pc),a2
_DT5:		moveq	#1,d2
_DT4:		cmp.w	(a2),d4
		ble.s	CopyMonth
		sub.w	(a2)+,d4
		addq.b	#1,d2
		bra.s	_DT4

CopyMonth:	move.l	d2,d1
		move.l	d1,-(sp)
		bsr.s	makeascii2
		move.l	(sp)+,d1
		tst.l	d7
		bne.s	_DT2
		subq.l	#1,d1

		mulu	#3,d1
		lea	JanFebMarAprM.MSG(pc),a0
		add.l	d1,a0
		subq.l	#2,a1
		move.b	(a0)+,(a1)+
		move.b	(a0)+,(a1)+
		move.b	(a0)+,(a1)+		;copy month

_DT2:		move.l	d4,d1
		bsr.s	makeascii2
		bra.s	Make_Time


makeascii2:	moveq	#0,d0
		move.b	(a4)+,d0
		move.l	18(a5),a1		;dat_StrDate
		add.l	d0,a1
makeascii:	move.b	#'0',d0
		ext.l	d1
		divu	#10,d1
		add.b	d0,d1
		move.b	d1,(a1)+
		swap	d1
		add.b	d0,d1
		move.b	d1,(a1)+
		rts

*-------------- Generate dat_Time


Make_Time:	move.l	22(a5),d0		;dat_StrTime
		beq.s	Get_DayStr

		move.l	d0,a1

		move.l	4(a5),d1		;ds_minute
		cmp.l	#1440,d1
		bcc.s	FormatErr
		divu	#60,d1
		move.l	d1,d2
		bsr.s	makeascii
		move.b	#':',(a1)+
		addq.l	#1,a0
		move.l	d2,d1
		swap	d1
		bsr.s	makeascii
		move.b	#':',(a1)+
		move.l	8(a5),d1		;ds_tick
		cmp.l	#3000,d1
		bcc.s	FormatErr
		divu	#50,d1
		bsr.s	makeascii
		clr.b	(a1)			;null terminate Time_String

*-------------- Get Date String?

Get_DayStr:	move.l	14(a5),d0		;dat_StrDay
		beq.s	FreeRegs
		move.l	d0,a1
		bsr.s	GetDay
copy_day:	move.b	(a0)+,(a1)+		;copy day to dat_StrDay
		bne.s	copy_day
		moveq	#0,d0

FreeRegs:	movem.l	(sp)+,d2-d7/a2-a5
		not.l	d0
		rts

FormatErr:	moveq	#-1,d0
		bra.s	FreeRegs

GetDay:		move.l	(a5),d0			;ds_days
		moveq	#0,d1
		divu	#7,d0
		swap	d0
		lea	dayoffset(pc),a0
		move.b	0(a0,d0.w),d1
		lea	days.txt(pc,d1.w),a0
		rts

JanFebMarAprM.MSG:
		dc.b	'Jan','Feb','Mar','Apr','May','Jun'
		dc.b	'Jul','Aug','Sep','Oct','Nov','Dec'

seperator.txt:	dc.b	'-------',0	;eg 01-Jan-78

MonthTable1:	dc	31	;Days in January (Normal Year)
		dc	28	;Feb
		dc	31	;Mar
		dc	30	;Apr
		dc	31	;May
		dc	30	;Jun
		dc	31	;Jul
		dc	31	;Aug
		dc	30	;Sep
		dc	31	;Oct
		dc	30	;Nov
		dc	31	;Dec

MonthTable2:	dc	31	;Days in January (Leap Year)
		dc	29	;Feb
		dc	31	;Mar
		dc	30	;Apr
		dc	31	;May
		dc	30	;Jun
		dc	31	;Jul
		dc	31	;Aug
		dc	30	;Sep
		dc	31	;Oct
		dc	30	;Nov
		dc	31	;Dec

YearTable1:	dc	1795
		dc	0
		dc	3
		dc	1536
		dc	1536
		dc	768
		dc	1539
		dc	0

days.txt:	dc.b	'Sunday',0
		dc.b	'Monday',0
		dc.b	'Tuesday',0
		dc.b	'Wednesday',0
		dc.b	'Thursday',0
		dc.b	'Friday',0
		dc.b	'Saturday',0

dayoffset:	dc.b	0		;Sun offset to day string
		dc.b	7		;Mon
		dc.b	14		;Tue
		dc.b	22		;Wed
		dc.b	32		;Thu
		dc.b	41		;Fri
		dc.b	48		;Sat
