/* TIMEDLL.C */
#define DLL

#include <windows.h>
#include <stdio.h>

__declspec(dllexport) void DosTime(short *yearP, char *monthP, char *dayP, 
                              char *hoursP, char *minutesP, char *secondsP,
                              char *hundsP);
__declspec(dllexport) void NtTime(short *yearP, short *monthP, short *dayP, 
                              short *hoursP, short *minutesP, short *secondsP,
                              short *milliP);

__declspec(dllexport) void crtTest();

void WriteStr(char *pStr);


void DosTime(yearP, monthP, dayP, hoursP, minutesP, secondsP, hundsP)
 	    short *yearP;
	    char *monthP, *dayP, *hoursP, *minutesP, *secondsP, *hundsP;

{

    _asm
    {
        mov     ah,2ah
        int     21h
	mov	eax, yearP
	mov	[eax],cx
	mov	eax, monthP
        mov     [eax],dh
	mov	eax, dayP
        mov     [eax],dl

        mov     ah,2ch
        int     21h
	mov	eax, hoursP
	mov	[eax],ch
	mov	eax, minutesP
        mov     [eax],cl
	mov	eax, secondsP
        mov     [eax],dh
	mov	eax, hundsP
        mov     [eax],dl
    }
}

void NtTime(yearP, monthP, dayP, hoursP, minutesP, secondsP, milliP)
	    short *yearP, *monthP, *dayP, *hoursP, *minutesP,
                  *secondsP, *milliP;

{
    SYSTEMTIME sys_time;

    GetLocalTime(&sys_time);

    *yearP = sys_time.wYear;
    *monthP = sys_time.wMonth;
    *dayP = sys_time.wDay;
    *hoursP = sys_time.wHour;
    *minutesP = sys_time.wMinute;
    *secondsP = sys_time.wSecond;
    *milliP = sys_time.wMilliseconds;
    return;
}

ULONG __stdcall DllEntryPoint(void *hDll, ULONG Reason, void *Reserved)
{
        if (Reason == DLL_PROCESS_ATTACH)
        {
                // can't call C library routine (like printf) during process
                // attach:  C library hasn't initialized yet!!
                WriteStr("TIMEDLL: Process attach\r\n$");
        }
        return TRUE;
}

void WriteStr(char *pStr)
{
        _asm {
                push    edx
                mov     edx,pStr
                mov     ah,9
                int     21h
                pop     edx
        }
        return;
}

void crtTest()
{
int foo;

	printf("printing from C, but routine was exported from FORTRAN\n");
	foo = _flushall();
}


