2000-05-06 21:34:20 +02:00
|
|
|
/****************************************************************/
|
|
|
|
/* */
|
|
|
|
/* systime.c */
|
|
|
|
/* */
|
|
|
|
/* DOS/C Date/Time Functions */
|
|
|
|
/* */
|
|
|
|
/* Copyright (c) 1998 */
|
|
|
|
/* Pasquale J. Villani */
|
|
|
|
/* All Rights Reserved */
|
|
|
|
/* */
|
|
|
|
/* This file is part of DOS-C. */
|
|
|
|
/* */
|
|
|
|
/* DOS-C is free software; you can redistribute it and/or */
|
|
|
|
/* modify it under the terms of the GNU General Public License */
|
|
|
|
/* as published by the Free Software Foundation; either version */
|
|
|
|
/* 2, or (at your option) any later version. */
|
|
|
|
/* */
|
|
|
|
/* DOS-C is distributed in the hope that it will be useful, but */
|
|
|
|
/* WITHOUT ANY WARRANTY; without even the implied warranty of */
|
|
|
|
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See */
|
|
|
|
/* the GNU General Public License for more details. */
|
|
|
|
/* */
|
|
|
|
/* You should have received a copy of the GNU General Public */
|
|
|
|
/* License along with DOS-C; see the file COPYING. If not, */
|
|
|
|
/* write to the Free Software Foundation, 675 Mass Ave, */
|
|
|
|
/* Cambridge, MA 02139, USA. */
|
|
|
|
/****************************************************************/
|
|
|
|
|
|
|
|
#include "portab.h"
|
|
|
|
#include "time.h"
|
|
|
|
#include "date.h"
|
|
|
|
#include "globals.h"
|
|
|
|
|
|
|
|
#ifdef VERSION_STRINGS
|
|
|
|
static BYTE *RcsId = "$Id$";
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* $Log$
|
2001-11-04 20:47:39 +01:00
|
|
|
* Revision 1.7 2001/11/04 19:47:39 bartoldeman
|
|
|
|
* kernel 2025a changes: see history.txt
|
|
|
|
*
|
2001-08-19 14:58:36 +02:00
|
|
|
* Revision 1.6 2001/08/19 12:58:36 bartoldeman
|
|
|
|
* Time and date fixes, Ctrl-S/P, findfirst/next, FCBs, buffers, tsr unloading
|
|
|
|
*
|
2001-04-15 05:21:50 +02:00
|
|
|
* Revision 1.5 2001/04/15 03:21:50 bartoldeman
|
|
|
|
* See history.txt for the list of fixes.
|
|
|
|
*
|
2001-03-21 03:56:26 +01:00
|
|
|
* Revision 1.4 2001/03/21 02:56:26 bartoldeman
|
|
|
|
* See history.txt for changes. Bug fixes and HMA support are the main ones.
|
|
|
|
*
|
2000-05-25 22:56:23 +02:00
|
|
|
* Revision 1.3 2000/05/25 20:56:21 jimtabor
|
|
|
|
* Fixed project history
|
|
|
|
*
|
2000-05-08 06:30:00 +02:00
|
|
|
* Revision 1.2 2000/05/08 04:30:00 jimtabor
|
|
|
|
* Update CVS to 2020
|
2000-05-06 21:34:20 +02:00
|
|
|
*
|
2000-05-25 22:56:23 +02:00
|
|
|
* Revision 1.1.1.1 2000/05/06 19:34:53 jhall1
|
|
|
|
* The FreeDOS Kernel. A DOS kernel that aims to be 100% compatible with
|
|
|
|
* MS-DOS. Distributed under the GNU GPL.
|
|
|
|
*
|
2000-05-06 21:34:20 +02:00
|
|
|
* Revision 1.3 1999/05/04 16:40:30 jprice
|
|
|
|
* ror4 date fix
|
|
|
|
*
|
|
|
|
* Revision 1.2 1999/04/12 03:21:18 jprice
|
|
|
|
* more ror4 patches. Changes for multi-block IO
|
|
|
|
*
|
|
|
|
* Revision 1.1.1.1 1999/03/29 15:41:34 jprice
|
|
|
|
* New version without IPL.SYS
|
|
|
|
*
|
|
|
|
* Revision 1.5 1999/02/08 05:55:58 jprice
|
|
|
|
* Added Pat's 1937 kernel patches
|
|
|
|
*
|
|
|
|
* Revision 1.4 1999/02/04 03:14:07 jprice
|
|
|
|
* Formating. Added comments.
|
|
|
|
*
|
|
|
|
* Revision 1.3 1999/02/01 01:48:41 jprice
|
|
|
|
* Clean up; Now you can use hex numbers in config.sys. added config.sys screen function to change screen mode (28 or 43/50 lines)
|
|
|
|
*
|
|
|
|
* Revision 1.2 1999/01/22 04:13:27 jprice
|
|
|
|
* Formating
|
|
|
|
*
|
|
|
|
* Revision 1.1.1.1 1999/01/20 05:51:01 jprice
|
|
|
|
* Imported sources
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Rev 1.6 06 Dec 1998 8:47:30 patv
|
|
|
|
* Bug fixes.
|
|
|
|
*
|
|
|
|
* Rev 1.5 04 Jan 1998 23:15:22 patv
|
|
|
|
* Changed Log for strip utility
|
|
|
|
*
|
|
|
|
* Rev 1.4 03 Jan 1998 8:36:50 patv
|
|
|
|
* Converted data area to SDA format
|
|
|
|
*
|
|
|
|
* Rev 1.3 29 May 1996 21:03:40 patv
|
|
|
|
* bug fixes for v0.91a
|
|
|
|
*
|
|
|
|
* Rev 1.2 19 Feb 1996 3:21:34 patv
|
|
|
|
* Added NLS, int2f and config.sys processing
|
|
|
|
*
|
|
|
|
* Rev 1.1 01 Sep 1995 17:54:16 patv
|
|
|
|
* First GPL release.
|
|
|
|
*
|
|
|
|
* Rev 1.0 02 Jul 1995 8:32:20 patv
|
|
|
|
* Initial revision.
|
|
|
|
*/
|
|
|
|
|
2001-03-21 03:56:26 +01:00
|
|
|
|
2001-08-19 14:58:36 +02:00
|
|
|
UWORD days[2][13] =
|
2000-05-06 21:34:20 +02:00
|
|
|
{
|
|
|
|
{0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365},
|
|
|
|
{0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366}
|
|
|
|
};
|
|
|
|
|
2001-03-21 03:56:26 +01:00
|
|
|
extern request
|
|
|
|
ClkReqHdr;
|
|
|
|
|
|
|
|
/*
|
|
|
|
return a pointer to an array with the days for that year
|
|
|
|
*/
|
2000-05-06 21:34:20 +02:00
|
|
|
|
2001-08-19 14:58:36 +02:00
|
|
|
UWORD *is_leap_year_monthdays(UWORD y)
|
2001-03-21 03:56:26 +01:00
|
|
|
{
|
|
|
|
/* this is correct in a strict mathematical sense
|
|
|
|
return ((y) & 3 ? days[0] : (y) % 100 ? days[1] : (y) % 400 ? days[0] : days[1]); */
|
|
|
|
|
|
|
|
/* this will work until 2200 - long enough for me - and saves 0x1f bytes */
|
|
|
|
|
|
|
|
if ((y & 3) || y == 2100) return days[0];
|
|
|
|
|
|
|
|
return days[1];
|
|
|
|
}
|
2000-05-06 21:34:20 +02:00
|
|
|
|
2001-08-19 14:58:36 +02:00
|
|
|
UWORD DaysFromYearMonthDay(UWORD Year, UWORD Month, UWORD DayOfMonth)
|
2001-03-21 03:56:26 +01:00
|
|
|
{
|
|
|
|
if (Year < 1980) return 0;
|
|
|
|
|
|
|
|
return DayOfMonth - 1
|
|
|
|
+ is_leap_year_monthdays(Year)[Month - 1]
|
|
|
|
+ ((Year - 1980) * 365)
|
|
|
|
+ ((Year - 1980 + 3) / 4);
|
|
|
|
|
|
|
|
}
|
2000-05-06 21:34:20 +02:00
|
|
|
|
2001-03-21 03:56:26 +01:00
|
|
|
/* common - call the clock driver */
|
|
|
|
void ExecuteClockDriverRequest(BYTE command)
|
2000-05-06 21:34:20 +02:00
|
|
|
{
|
|
|
|
ClkReqHdr.r_length = sizeof(request);
|
2001-03-21 03:56:26 +01:00
|
|
|
ClkReqHdr.r_command = command;
|
2000-05-06 21:34:20 +02:00
|
|
|
ClkReqHdr.r_count = sizeof(struct ClockRecord);
|
|
|
|
ClkReqHdr.r_trans = (BYTE FAR *) (&ClkRecord);
|
|
|
|
ClkReqHdr.r_status = 0;
|
|
|
|
execrh((request FAR *) & ClkReqHdr, (struct dhdr FAR *)clock);
|
2001-03-21 03:56:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
VOID DosGetTime(BYTE FAR * hp, BYTE FAR * mp, BYTE FAR * sp, BYTE FAR * hdp)
|
|
|
|
{
|
|
|
|
ExecuteClockDriverRequest(C_INPUT);
|
|
|
|
|
2000-05-06 21:34:20 +02:00
|
|
|
if (ClkReqHdr.r_status & S_ERROR)
|
|
|
|
return;
|
|
|
|
|
|
|
|
*hp = ClkRecord.clkHours;
|
|
|
|
*mp = ClkRecord.clkMinutes;
|
|
|
|
*sp = ClkRecord.clkSeconds;
|
|
|
|
*hdp = ClkRecord.clkHundredths;
|
|
|
|
}
|
|
|
|
|
2001-11-04 20:47:39 +01:00
|
|
|
COUNT DosSetTime(BYTE h, BYTE m, BYTE s, BYTE hd)
|
2000-05-06 21:34:20 +02:00
|
|
|
{
|
2001-03-21 03:56:26 +01:00
|
|
|
BYTE Month, DayOfMonth, DayOfWeek; COUNT Year;
|
|
|
|
|
2000-05-06 21:34:20 +02:00
|
|
|
DosGetDate((BYTE FAR *) & DayOfWeek, (BYTE FAR *) & Month,
|
|
|
|
(BYTE FAR *) & DayOfMonth, (COUNT FAR *) & Year);
|
|
|
|
|
2001-11-04 20:47:39 +01:00
|
|
|
ClkRecord.clkHours = h;
|
|
|
|
ClkRecord.clkMinutes = m;
|
|
|
|
ClkRecord.clkSeconds = s;
|
|
|
|
ClkRecord.clkHundredths = hd;
|
2000-05-06 21:34:20 +02:00
|
|
|
|
2001-03-21 03:56:26 +01:00
|
|
|
ClkRecord.clkDays = DaysFromYearMonthDay(Year, Month, DayOfMonth);
|
|
|
|
|
|
|
|
ExecuteClockDriverRequest(C_OUTPUT);
|
2000-05-06 21:34:20 +02:00
|
|
|
|
|
|
|
if (ClkReqHdr.r_status & S_ERROR)
|
|
|
|
return char_error(&ClkReqHdr, (struct dhdr FAR *)clock);
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID DosGetDate(wdp, mp, mdp, yp)
|
|
|
|
BYTE FAR *wdp,
|
|
|
|
FAR * mp,
|
|
|
|
FAR * mdp;
|
|
|
|
COUNT FAR *yp;
|
|
|
|
{
|
2001-08-19 14:58:36 +02:00
|
|
|
UWORD c;
|
|
|
|
UWORD *pdays;
|
|
|
|
UWORD Year,Month;
|
2001-03-21 03:56:26 +01:00
|
|
|
|
|
|
|
ExecuteClockDriverRequest(C_INPUT);
|
2000-05-06 21:34:20 +02:00
|
|
|
|
|
|
|
if (ClkReqHdr.r_status & S_ERROR)
|
|
|
|
return;
|
|
|
|
|
2001-03-21 03:56:26 +01:00
|
|
|
for (Year = 1980, c = ClkRecord.clkDays; ;)
|
2000-05-06 21:34:20 +02:00
|
|
|
{
|
2001-03-21 03:56:26 +01:00
|
|
|
pdays = is_leap_year_monthdays(Year);
|
|
|
|
if (c >= pdays[12])
|
2000-05-06 21:34:20 +02:00
|
|
|
{
|
|
|
|
++Year;
|
2001-03-21 03:56:26 +01:00
|
|
|
c -= pdays[12];
|
2000-05-06 21:34:20 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* c contains the days left and count the number of days for */
|
|
|
|
/* that year. Use this to index the table. */
|
|
|
|
Month = 1;
|
2001-03-21 03:56:26 +01:00
|
|
|
while (c >= pdays[Month])
|
2000-05-06 21:34:20 +02:00
|
|
|
{
|
|
|
|
++Month;
|
|
|
|
}
|
|
|
|
|
|
|
|
*mp = Month;
|
2001-03-21 03:56:26 +01:00
|
|
|
*mdp = c - pdays[Month-1] + 1;
|
2000-05-06 21:34:20 +02:00
|
|
|
*yp = Year;
|
|
|
|
|
|
|
|
/* Day of week is simple. Take mod 7, add 2 (for Tuesday */
|
|
|
|
/* 1-1-80) and take mod again */
|
|
|
|
|
2001-03-21 03:56:26 +01:00
|
|
|
*wdp = (ClkRecord.clkDays + 2) % 7;
|
2000-05-06 21:34:20 +02:00
|
|
|
}
|
|
|
|
|
2001-11-04 20:47:39 +01:00
|
|
|
COUNT DosSetDate(Month, DayOfMonth, Year)
|
|
|
|
UWORD Month,
|
|
|
|
DayOfMonth,
|
|
|
|
Year;
|
2000-05-06 21:34:20 +02:00
|
|
|
{
|
2001-11-04 20:47:39 +01:00
|
|
|
UWORD *pdays;
|
2001-03-21 03:56:26 +01:00
|
|
|
pdays = is_leap_year_monthdays(Year);
|
|
|
|
|
2000-05-06 21:34:20 +02:00
|
|
|
if (Year < 1980 || Year > 2099
|
|
|
|
|| Month < 1 || Month > 12
|
2001-03-21 03:56:26 +01:00
|
|
|
|| DayOfMonth < 1
|
|
|
|
|| DayOfMonth > pdays[Month] - pdays[Month-1])
|
2000-05-06 21:34:20 +02:00
|
|
|
return DE_INVLDDATA;
|
2001-03-21 03:56:26 +01:00
|
|
|
|
2000-05-06 21:34:20 +02:00
|
|
|
|
|
|
|
DosGetTime((BYTE FAR *) & ClkRecord.clkHours,
|
|
|
|
(BYTE FAR *) & ClkRecord.clkMinutes,
|
|
|
|
(BYTE FAR *) & ClkRecord.clkSeconds,
|
|
|
|
(BYTE FAR *) & ClkRecord.clkHundredths);
|
|
|
|
|
2001-03-21 03:56:26 +01:00
|
|
|
ClkRecord.clkDays = DaysFromYearMonthDay(Year, Month, DayOfMonth);
|
|
|
|
|
|
|
|
ExecuteClockDriverRequest(C_OUTPUT);
|
2000-05-06 21:34:20 +02:00
|
|
|
|
|
|
|
if (ClkReqHdr.r_status & S_ERROR)
|
|
|
|
return char_error(&ClkReqHdr, (struct dhdr FAR *)clock);
|
|
|
|
return SUCCESS;
|
|
|
|
}
|