135

Turbo Pascal programs start by calibrating a delay loop (so that the Delay function knows how much to spin to achieve a certain delay). The calibration counts the number of times a certain loop is run for 55ms (as measurable using the PC’s timer interrupt with its default setting), then divides the number of loops by 55 so that Delay can then busy-wait in ...


39

The problem is simple. At initialisation, Nibbles measures the time it takes to perform 1000 empty iterations of a FOR loop with a DOUBLE counter in order to determine how many such iterations are required to produce a ½ ms delay. Back when this code was written, CPUs were pretty slow (and FPUs even more so, if they were available at all), so it was ...


36

DOSBox, with the default CPU speed of 3000 cycles on this Linux box, runs nibbles.bas without problems.


6

40 for t=t0+t*60 to t ... will repeat at least once and then for as long as t0+t*60 (i.e. start time + duration) does not equal t. So this: captures t0+t*60 (the desired end time) such that t can be reused; and after the first iteration, continuously tests ti (which has been stored to t) against the desired end time. i.e. Commodore's implementation of for ...


5

TL;DR: FOR T=<target value> TO T uses T as a temporary variable to store the target value inside the FOR stack frame, where it is used later to compare with the actual value of T after an iteration. This eliminates the need for a second, helper variable. Works whenever T is/can be set within the loop. The Long Read: I imitated the code in CBM prg ...


2

Commodore BASIC has a quirk that it will run a FOR loop at least once. This is what allows your t variable to update at least once, allowing the loop to be valid. Raffzahn's explained how it works, but according to BASIC standards, it shouldn't. The ANSI/NBS Special Publication 500-70/1 test suite from 1980 go into great detail about how BASIC should behave. ...


1

On the modern CPU the FOR loop executes so quickly that the difference in the TIMER before and after is zero. Hence the line: speed = speed * .5 / (stopTime# - startTime#) gives a divide by zero error, because (stopTime# - startTime#) equals zero. The simplest solution would simply be to set the speed variable manually, until you find something that gives a ...


Only top voted, non community-wiki answers of a minimum length are eligible