PDA

View Full Version : plz read



######
02-02-2003, 08:59 AM
hi im trying to read system date using the int86() function in c...problem is it doesnt display the date it displays numbers that mean nothing in particular......can anyone tell me what i'm doing wrong? thank u



#include <dos.h>
#include <stdio.h>
#include <conio.h>

#define DATE 0x2a

int main (void)
{
union REGS regs;
unsigned int cd;

int86(DATE, & regs, & regs);
clrscr();

cd = regs.h.ah;

printf("date: %d",cd);
getch();

return 0;
}

Carlos
02-03-2003, 09:02 AM
I don't know this int86 (?), but assuming it is kinda "placeholder" for BIOS int 01aH, you probably get the values in Binary Coded Digits, e.g. 2003h instead of 2003 decimal.

So, you probably have to convert the returned values from hex to decimal.

However, why don't you just use the adequate C functions (gettime, getdate) instead of troubling with int86?

Or, if you really need ints, use BIOS ints.

Have fun!

ronin
02-06-2003, 03:04 PM
Like Carlos said, you're most likely getting the BCD code. Something like this *might* work provided that you don't want the day of the week too.



#include <stdio.h>

int main(void)
{
unsigned char cent, year, month, day;

static char *months[] =
{ "Error", "January", "February", "March",
"April", "May", "June", "July", "August",
"September", "October", "November",
"December" };

_asm
{
mov ah,0x4
int 0x1A
mov cent,ch
mov year,cl
mov month,dh
mov day,dl
}

switch(month)
{
case 16: month = 10;
break; /* 10000 BCD October */
case 17: month = 11;
break; /* 10001 BCD November */
case 18: month = 12;
break; /* 10010 BCD December */
default: break;
};

printf("System Date: %s %x, %x%s%x",
months[month], day, cent,
(year > 9 ? "" : "0"), year);
return 0;
} I *think* that it covers all cases, but you'd have to run through all the combinations to know for sure. :D