Bob, many thanks for your kind suggestion. In fact, I got a first
prototype going this afternoon using your (and Andy Warren's)
looped-increment idea and it does work. But just out of
stubbornness, I want to at least try a once-through approach
as you have suggested, if only because it seems like "the
right thing to do". I'll be studying your message in detail ;-)
and really appreciate the time you took to type it out.
Brian Aase
On 13 Feb 2001, at 17:05, Bob Ammerman wrote:
{Quote hidden}> Examples below are in a "C" like syntax, but the concepts apply equally well
> to assembly language.
>
> If you have plenty of time to do the update, you could do it like this:
>
> while (delta--)
> IncrementTime();
>
> an 'IncrementTime() routine is much simpler than a full add.
>
> If you have to do a full add at one time, something like this could work:
>
> seconds += delta;
> delta = 0;
> while (seconds > 9)
> {
> ++delta;
> seconds -= 10;
> }
>
> tensecs += delta;
> delta = 0;
> while (tensecs > 5)
> {
> ++delta;
> tensecs -= 6;
> }
>
> minutes += delta;
> if (minutes > 9)
> {
> minutes -= 10;
> ++tenmins;
>
> if (tenmins > 5)
> {
> tenmins -= 6;
>
> // hours is tricky because the sequence is:
> // 12, 1, 2, 3...11 -> 12 and the carry to AM/PM
> // occurs on the transition from 11 to 12
> ++hours;
> if (tenhours == 0)
> {
> if (hours > 9)
> {
> // from 9 to 10 o'clock
> hours = 0;
> tenhours = 1;
> }
> }
> else
> {
> if (hours == 2)
> {
> // from 11 to 12 o'clock
> ampm ^= 0x01; // toggle AM/PM indicator
> }
> else if (hours == 3)
> {
> // from 12 o'clock to 1 o'clock
> hours = 1;
> tenhours = 0;
> }
> }
> }
> }
>
> The above has the advantage that it performs no multiplication or division.
> Military (24-hour) time would be a bit easier.
>
> Warning: the above code is _not_ tested!
>
> Bob Ammerman
> RAm Systems
> (contract development of high performance, high function, low-level
> software)
>
>
>
> {Original Message removed}