Apple II
Technical Notes
_____________________________________________________________________________
                                                  Developer Technical Support


Apple II Miscellaneous
#12:    The Apple II Firmware WAIT Routine

Revised by:    Matt Deatherage                                  November 1988
Written by:    Matt Deatherage                                       May 1988

This Technical Note expands on the already documented descriptions of the 
Apple II firmware WAIT routine, which guaranteed a minimum, not an exact, 
specified delay.
_____________________________________________________________________________

As described in the Apple IIe Technical Reference Manual and the Apple IIc 
Technical Reference Manual, Second Edition, the WAIT routine located in ROM
at $FCA8 waits for a certain amount of time before returning to the calling
program.  The delay is listed in the IIe manual as being 1/2(26+27A+5A^2),
where A is the value in the accumulator when WAIT is called.  The value
returned by this expression is the number of clock cycles taken by the
routine, not the amount of time that passes while it waits.  To obtain the
elapsed time in microseconds, you must multiply the result by the scaling
factor 14 / 14.318181.

Different formulas have appeared in different firmware listings published by 
Apple in the past, but the above formula is in all current publications, and 
has been verified as correct by Developer Technical Support.  If there were 
nothing in the system except a 65C02 (or 65816) microprocessor, this formula 
would be completely accurate.  However, this is not the case in an Apple II, 
as there are interrupts, changing system speeds, fast and slow RAM, and 
numerous other additions to the system that can cause extra overhead when a 
routine is executed.

For these reasons, the WAIT routine should be used only as a minimum delay.  
It should not be expected to wait for exactly the time specified by the WAIT 
formula.

The Apple IIGS Firmware Reference correctly notes this fact, as well as 
including the scaling factor (14 / 14.318181) to return the minimum delay in 
microseconds without further calculation.


Further Reference
o    Apple IIGS Firmware Reference
o    Apple IIe Technical Reference Manual
o    Apple IIc Technical Reference Manual, Second Edition
