Division by zero


 │ Division by zero │

The program attempted to divide a number by zero during a /, mod, or div operation.

It often happens due to CRT initialization. For the very moment there are many different fixes available.

It has to be emphasized that the most popular patch (maid by Klaus Hartnegg) does nothing more than preventing error 200 from happening. Klaus Hartnegg restricted himself to not making patch that changes the length of CRT.TPU, so he couldn't get everything right. The Delay procedure misbehaves in his patch (actual duration is less than specified).

There are many other patches, but the most popular (not counting Klaus Hartnegg's one) try to fix error 200 without breaking Delay by merely increasing empty loop counter size to 32 bits. This is a better solution, but doesn't work well in modern mutitasking OSes which do not guarantee equal amounts of processor timeslices.

Finally, there are unpopular patches that rely solely on a system time. We have an improved patch of this kind. Not only it relies on system time, but also tries not to waste CPU in IDLE. It calls yield interrupt call if supported or HLT assembler instruction in pure DOS. We have tested it in NTVDM and DOSBox. It works fine in NTVDM. In DOSBox, however, there is a small issue with it: DOSBox implements yield API with a stub returning success, so your compiled program will not try HLT and will waste CPU time in idle (in pure DOSBox). This is a DOSBox problem. DOSBox developers told that DOSBox is for games, and games do not idle. So if you want DOSBox not to waste CPU time while your programs go idle, you should use DOSIDLE or something like this invoking HLT where necessarily.

The patch given below also tries to maintain precision. It relies on DOS system time, so it can't be more precise than 1/18 of second. This patch compensates this fact by having a remainder. So if you put Delay(1) somewhere in the loop, the program won't just waste CPU time never yielding. Instead, in 1 case out of 52 your program will yield a tick. We have compared remainderless and remainderful Delay implementation. We have written a simple program that prints a system time (according to DOS system time) and calls Delay(1000) in a loop. Milliseconds are always different in every second, but their pattern repeats so one can notice whether Delay drifts or not. Remainderless implementation have a noticeble drift. Our remainderful version was running for hours (tested in NTVDM and DOSBox), and it looks like every delay was exactly 1 second. It is probably the best patch ever created.

Download patched CRT.TPU

We do not distribute separate .TPU downloads. If you really need to extract a particular unit, use TPUMOVER.


| G+
Код для вставки: :: :: :: ::
Поделиться: // //