Get system health since the last boot in C

I need to get the system up and running since the last boot using C.

Target OS - MS DOS.

I tried time()

, ftime()

but they refer to January 1,1970 00:00:00.

Can anyone suggest some solution?

Thanks in advance.

+3


source to share


1 answer


To read the system time in MS-DOS, you can call INT 1a,0

eg. like this (GNU syntax):

unsigned short cx, dx;
__asm__ (
    "mov    $0, %%ah    \n\t"
    "int    $0x1a       \n\t"
    : "=c" (cx), "=d" (dx)
    :
    : "ax"
    );
time_t time = cx;
time <<= 16;
time |= dx;
time = (time_t) ((double)time / 18.2065);

      

This is probably the best choice. If nobody has set this time using INT 1a,1

, you will get seconds from the moment of loading.

Please note that it is only up to 24 hours, if you need longer periods of time you should call regularly and pay attention to the "completeness flag" in al

.

Add another output variable in this case, increment the day counter every time you see a al

non-zero value, and just add days * 86400

to the final result, a rough outline:



unsigned short ax, cx, dx;
static unsigned days = 0;
__asm__ (
    "mov    $0, %%ah    \n\t"
    "int    $0x1a       \n\t"
    : "=a" (ax), "=c" (cx), "=d" (dx)
    );
if (ax & 0xff) ++days;
time_t time = cx;
time <<= 16;
time |= dx;
time = (time_t) ((double)time / 18.2065);
time += days * 86400;

      

I found some additional information that might be helpful here:

The second problem comes from the way BIOS int 0x1A works. Whenever you call this function to retrieve the system time (the current timer value), it also returns the current MIDNIGHT flag and RESET FLAG. But since the BIOS function does not update the DOS date, the next time you ask for the date, it will not update correctly. DOS is aware of the behavior, so when you call any DOS function the MIDNIGHT flag is supported correctly. If you are calling BIOS int 0x1A yourself, you MUST check the value of the MIDNIGHT flag and enable it if it was set.

So, in short, if you need MS-DOS to maintain the correct date while your program is running, you need to do some extra work (like resetting the flag manually and calling INT 21,2A

every time it was found)

+4


source







All Articles