;/*static char *SCCSID = "@(#)timenow.asm	6.4 92/02/21";*/
;***	TIMNOW - Gets times out of the global info seg
;
;	timNow - Gets the current time out of the global info seg
;
;	msNow - Gets the number of milliseconds since boot time
;

.286

.MODEL MEDIUM, PASCAL

ifdef MEDIUM_MODEL
CALLTYPE    equ <far>
else
CALLTYPE    equ <near>
endif

INCL_DOSERRORS	equ	1	; Include the errors from bseerr.inc

include bseerr.inc
include devhlp.inc
include infoseg.inc   ; get struc definition for the info seg

.data

extrn pGIS:dword
extrn pDevHlp:dword

IRP SEG,<_TEXT,_BTXT>

.CODE SEG


;**	timNow - Gets the current time out of the global info seg
;
;	tim = timNow()
;
;	Returns current time in secs since jan 1 1970
;		in (dx:ax)
;

public timNow&SEG
timNow&SEG	proc CALLTYPE
	les	bx,pGIS		; point es:bx to the global info seg
.386

; Get pGIS->time into eax
	mov	eax,dword ptr es:[bx].SIS_BigTime	; get double word
	mov	edx,eax
	shr	edx,16
.286
; dx = hi word, ax = lo word.
	ret
timNow&SEG	endp



;**	msNow - Gets the number of milliseconds since boot time
;
;	cMSec = msNow()
;
;	Returns milliseconds since boot in (dx:ax)
;

public msNow&SEG
msNow&SEG	proc CALLTYPE
	les	bx,pGIS		; point es:bx to the global info seg

.386

; Get pGIS->time into eax
	mov	eax,dword ptr es:[bx].SIS_MsCount	; get double word
	mov	edx,eax
	shr	edx,16
.286
; dx = hi word, ax = lo word.
	ret
msNow&SEG	endp

ENDM


.CODE INIT1

.286

;**	InitpGIS - Uses the DevHlp to get a pointer to the Global Info Seg
;
;	No Returns, just sets up pointer in our data segment
;

public InitpGIS
InitpGIS proc CALLTYPE uses es bx dx

	xor	ax,ax
	mov	al,DHGETDOSV_SYSINFOSEG
	mov	dl,DevHlp_GetDOSVar
	call	[pDevHlp]		   ; call the dev_help
	jc	GIS_Error		   ; jump if Dev help returned error
	mov	es,ax			   ; AX:BX Global Info Seg Selector
	mov	ax,es:[bx]
	mov	word ptr [pGIS+2],ax
	mov	word ptr [pGIS],0
	mov	ax,NO_ERROR		   ; else set NO ERROR
	jmp short GIS_Ret
GIS_Error:
	mov	ax,ERROR_GEN_FAILURE
GIS_Ret:
	ret

InitpGIS endp

end
