CMOS clock patch (dates not changing when left overnight)

Here you can discuss the development of patches.

CMOS clock patch (dates not changing when left overnight)

Postby merlin128 » 2006-8-07 @ 16:10

I used DOSBox to run Foxpro v2.6 for DOS on a new pc with windows xp.
The application was locking up.. now it works.. however, if I leave the app up all night long.. the next day is still shows the previous date.. the date does not update unless I close the app.. and reopen it..
This causes a problem because the app is scheduled to run reports over the weekend when nobody is here..

is there anyway to get DOSBox to see the date change..
merlin128
Newbie
 
Posts: 2
Joined: 2006-8-07 @ 16:04

Re: Dates do not change when left running overnight.

Postby Qbix » 2006-8-07 @ 16:16

code it in. at the moment dosbox doesn't check this.
Water flows down the stream
How to ask questions the smart way!
User avatar
Qbix
DOSBox Author
 
Posts: 10452
Joined: 2002-11-27 @ 14:50
Location: Fryslan

Re: Dates do not change when left running overnight.

Postby jal » 2006-8-08 @ 13:40

Qbix wrote:code it in. at the moment dosbox doesn't check this.


Shouldn't be that hard? Presumably the app just calls int 21h to check the date, why can't DOSbox return the current date then? Does it cache it somewhere? (Same goes for the RTC.)


JAL
User avatar
jal
Member
 
Posts: 494
Joined: 2004-1-02 @ 15:30
Location: Amersfoort, Netherlands

Re: Dates do not change when left running overnight.

Postby Qbix » 2006-8-08 @ 13:43

well dosbox it's dos uses the 18.2 hz timer to keep track of the time. (it reads that bios value and converts it).
Water flows down the stream
How to ask questions the smart way!
User avatar
Qbix
DOSBox Author
 
Posts: 10452
Joined: 2002-11-27 @ 14:50
Location: Fryslan

Re: Dates do not change when left running overnight.

Postby merlin128 » 2006-8-09 @ 05:29

I tried the DOSBOX CVS.. this does have a date and time command.. but still. the app only sees the date that it was launched.. when left running overnight it still thinks its the previous day..
merlin128
Newbie
 
Posts: 2
Joined: 2006-8-07 @ 16:04

Re: Dates do not change when left running overnight.

Postby dvwjr » 2006-8-09 @ 06:04

Probably the best solution would be for you to pay a C coder to modify the DOSBOX v0.65 source to include the functionality you desire. This was a problem with PC/MS-DOS back in the day...

Since you are using DOSBOX for a legacy commercial application written in FoxPro for DOS (v2.60) then you realise that the developers target games, not commercial applications. It would be great if the functionality you desire were already there - but think of this as an opportunity to add to DOSBOX and solve your legacy app problem quite easily.

Here is the technical information you need:

Technical Notes Database

TN839C.txt :How does DOS update the Date at Midnight ?
Category :DEBUG TOOLS
Platform :All
Product :TD 2.0

Description:

MIDNIGHT UPDATE: How does DOS update the DATE at Midnight ?
-----------------------------------------------------------
When BIOS detects that it is midnight, it clears out the tick-counter (unsigned long at location 0x40:0x6C) to start a new day and sets the midnight flag (unsigned int at location 0x40:0x70) to 1. The calendar of the PC, however, is maintained by the CLOCK$ device. When one asks DOS for the time or date (i.e. at the DOS prompt or via INT 0x21, Func. 0x2A/0x2Ch), the latter passes the request to the CLOCK$ device. The device uses the BIOS Function 0x1A to fulfill the request. When called upon, BIOS always returns the contents of the midnight flag in register AL and then resets the flag to zero if necessary. The CLOCK$ device verifies the value in register AL after calling BIOS and adjusts the calendar date if necessary. Then DOS merely returns to the user the answer received from the CLOCK$ device.

However, the above scenario has two major loopholes:

(i) What if somebody other than the CLOCK$ device (i.e. Other than DOS) were to call the BIOS function 0x1A just after midnight?

(ii) What if a machine were to remain running but unattended for two days or more with no requests for the date/time being made to DOS?

Both of the above would result in an incorrect date on the computer. In the first case mentioned above, the caller of INT 0x1A will be notified that Midnight just passed by but the calendar will not be updated since the CLOCK$ device is out of the loop.

BIOS does not treat the Midnight Flag as a counter which must be incremented for each midnight passed by. It merely sets the flag to 1 for each midnight passed. Therefore in the second case above, the CLOCK$ device (if eventually called upon) will be unable to properly identify the actual number of midnights gone by.

What are the solutions ?
------------------------
For the first case mentioned above, direct calls to BIOS for the current date/time should be avoided and DOS should be called instead. This is unfortunately easier said than done. For example, applications performing asynchronous processing must constantly monitor the time which is, at best, difficult to do via DOS calls given the non-reentrant nature of the latter.

For the second case mentioned above, one workaround would be to use a TSR which constantly monitors the Midnight Flag. Once the latter is set, a call to DOS for the current Date is made by the TSR after determining that it is safe to do so. This would ensure that the calendar gets updated when the PC is running but left unattended.


What if my TSR makes calls to BIOS INT 0x1A in the background ?
----------------------------------------------------------------
(According to a message posted in the IBMPRO Forum on CIS, there is a commercial utility which sends faxes at regular intervals and uses BIOS to monitor the time ) ?

In this case the TSR may intercept every call to the BIOS INT 0x1A and determine (via the DOS BUSY FLAG ?) whether the call is actually being made via a DOS call [ To be absolutely certain, the TSR could also TRAP INT 21h ] and if the call is not done via DOS, the TSR can verify the Midnight Flag and take appropriate steps by calling DOS if necessary.

NOTE: The current version of the Borland C++' startup code makes a call to the BIOS Interrupt 0x1A. Running a BC++ application just after midnight may prevent the Calendar Date from being properly updated. Users which do not call any of the C/C++ clock() related functions, can safely comment out lines 264-267 from c0.asm and create a new copy of the startup code object if necessary.


Reference:

7/2/98 10:42:13 AM


Source: Borland Developer Network "How does DOS update the Date at Midnight?"



Best of luck,

dvwjr
dvwjr
Member
 
Posts: 359
Joined: 2002-11-23 @ 23:32

Re: Dates do not change when left running overnight.

Postby Qbix » 2006-8-09 @ 06:26

our timer function (which increases the tick-counter) doesn't take in account (yet) the passing of midnight. Hence the 1 in AL is never set.
Futher our DOS functions which query the time don't use int 1A.
Futher We don't have a CLOCK device.

The smallist (possibly working) solution would be to add the checking of passing after midnight in the timer-tick increase function.
and to make our dos functions which query the time/date check for the passing after midnight.
Water flows down the stream
How to ask questions the smart way!
User avatar
Qbix
DOSBox Author
 
Posts: 10452
Joined: 2002-11-27 @ 14:50
Location: Fryslan

Re: Dates do not change when left running overnight.

Postby ykhwong » 2006-8-09 @ 07:31

You can change date by using my cvs build. (usage : date [day] [month] [year])
However, that's not exactly an ultimate solution.
ykhwong
Oldbie
 
Posts: 627
Joined: 2004-3-17 @ 15:35

Re: Dates do not change when left running overnight.

Postby jal » 2006-8-09 @ 08:22

ykhwong wrote:You can change date by using my cvs build. (usage : date [day] [month] [year])
However, that's not exactly an ultimate solution.


Wouldn't it be a lot easier to just read the system time (with e.g. time()), and convert that to the right value (with e.g. localtime()) at the int 21h call, not using the BIOS values? The fact that 'real' DOS does it this way shouldn't stop DOSbox from doing a better job?


JAL
User avatar
jal
Member
 
Posts: 494
Joined: 2004-1-02 @ 15:30
Location: Amersfoort, Netherlands

Re: Dates do not change when left running overnight.

Postby wd » 2006-8-09 @ 09:31

> The fact that 'real' DOS does it this way shouldn't stop DOSbox from doing a better job?

It's just that nobody cares about it, so if you want it you got to code it yourself.
wd
DOSBox Author
 
Posts: 10818
Joined: 2003-12-03 @ 21:23

Re: Dates do not change when left running overnight.

Postby DosFreak » 2006-8-09 @ 11:01

I think this may affect games as well.....I wish I could remember where that post was that mentioned their problem. :(
Game Acronym List
DosBox CVS Builds
DosBox Feature Request Thread
DosBox FAQ
PC Game Compatibility List
"Who's got time to read all the way down to the bottom of an email?"
User avatar
DosFreak
l33t++
 
Posts: 9542
Joined: 2002-6-30 @ 16:35
Location: Your Head

Re: Dates do not change when left running overnight.

Postby wd » 2006-8-09 @ 20:14

I'm sure you can avoid running that game just before midnight,
or at least in a timeframe where the timechange flag does not matter.
wd
DOSBox Author
 
Posts: 10818
Joined: 2003-12-03 @ 21:23

Re: Dates do not change when left running overnight.

Postby jal » 2006-8-10 @ 08:38

wd wrote:> The fact that 'real' DOS does it this way shouldn't stop DOSbox from doing a better job?

It's just that nobody cares about it, so if you want it you got to code it yourself.


I should, if only I had the time to do it...


JAL
User avatar
jal
Member
 
Posts: 494
Joined: 2004-1-02 @ 15:30
Location: Amersfoort, Netherlands

Re: Dates do not change when left running overnight.

Postby wd » 2006-8-10 @ 11:52

> I should, if only I had the time to do it...

That's exactly the point.
wd
DOSBox Author
 
Posts: 10818
Joined: 2003-12-03 @ 21:23

Re: Dates do not change when left running overnight.

Postby ChaosFish » 2006-8-10 @ 20:57

The title of this thread so makes me want to make a stupid joke.
User avatar
ChaosFish
Member
 
Posts: 409
Joined: 2003-9-05 @ 18:38
Location: Israel

Re: Dates do not change when left running overnight.

Postby jal » 2006-8-14 @ 12:44

wd wrote:> I should, if only I had the time to do it...

That's exactly the point.


Well, I couldn't resist, so I'm working on a patch (enhancement?) that makes changes to the CMOS clock, using an offset to the real time reported by time() and the time set by changing the CMOS clock. Also, the DOS date/time calls then set and retrieve the CMOS clock. Thus, one could set the DOS date/time to any value and it actually works. I'll post it as soon as I have done some thorough bug testing, which may not be before the end of this week...

B.t.w., I noticed the 12h/24h bit is set by DOSbox upon intialization to 24h, but changing it afterwards doesn't change the way the time is reported back. I also fixed that.


JAL

P.S. This should really be in the developers forum...
User avatar
jal
Member
 
Posts: 494
Joined: 2004-1-02 @ 15:30
Location: Amersfoort, Netherlands

Re: Dates do not change when left running overnight.

Postby eL_PuSHeR » 2006-8-14 @ 13:08

*** Moving to DOSBox Development section ***
Intel i7 5960X
Gigabye GA-X99-Gaming 5
8 GB DDR4 (2100)
8 GB GeForce GTX 1070 G1 Gaming (Gigabyte)
User avatar
eL_PuSHeR
Moderator
 
Posts: 6451
Joined: 2003-6-20 @ 16:39

Re: DOSBox CMOS clock patch (dates not changing when left overnight)

Postby wd » 2006-8-14 @ 20:42

> Thus, one could set the DOS date/time to any value and it actually works.

That'd be cool, was thinking about using offsets for a set time
function myself, but quite a bunch of functions depend on it.
wd
DOSBox Author
 
Posts: 10818
Joined: 2003-12-03 @ 21:23

Re: DOSBox CMOS clock patch (dates not changing when left overnight)

Postby jal » 2006-8-15 @ 10:16

wd wrote:> Thus, one could set the DOS date/time to any value and it actually works.

That'd be cool, was thinking about using offsets for a set time
function myself, but quite a bunch of functions depend on it.


I'll have to scan the DOSbox sources to see if time() and/or localtime() and alike functions are used for other low-level functions. Do you have any specific functions in mind I should pay special attention to (apart from the DOS int 21h time/date functions)?


JAL
User avatar
jal
Member
 
Posts: 494
Joined: 2004-1-02 @ 15:30
Location: Amersfoort, Netherlands

Re: DOSBox CMOS clock patch (dates not changing when left overnight)

Postby wd » 2006-8-15 @ 10:36

Don't know, at the moment the dos time/bios time/cmos time/ticks
are consistent, but i'm not sure in what way they are really dependent
under dos. Maybe the file create times might be a problem (afair
dosbox leaves the current system time set on them).
wd
DOSBox Author
 
Posts: 10818
Joined: 2003-12-03 @ 21:23

Next

Return to DOSBox Patches

Who is online

Users browsing this forum: No registered users and 1 guest