[comp.sys.mac.programmer] Looping >64K times with DBRA

ldo@waikato.ac.nz (Lawrence D'Oliveiro, Waikato University) (10/19/90)

I was prompted to post this by something I saw in the 6.0.6b19 change
history notes I picked up from apple.com. In the section that explains
the Sound Manager changes, there is a note about a fix to SndStartFilePlay
to let it handle buffers bigger than 64K bytes. The note says "Fixed by
not using a DBRA loop."

I assume this means they avoided using the DBRA instruction altogether.
Actually, there is a way to use a DBRA (or two of them) to iterate
a loop more than 64K times. Here's a simple skeletal example. Assume
that "count" is a D-register that has been set up to contain the correct
unsigned longword loop count (any value from 0 up to 4294967295 is valid--
note this is the actual loop count, *not* the count minus 1), here's how
you'd use DBRA:

	bra	bottom_of_loop
top_of_loop:
; do whatever must be done inside loop
bottom_of_loop:
	dbra	count, top_of_loop
	swap	count
	dbra	count, another_64K
	bra.s	out_of_loop
another_64K:
	swap	count
	bra.s	top_of_loop
out_of_loop:
; whatever comes after loop

Note that, since the extra code is only executed once in 64K iterations,
the extra time overhead for supporting longword counts is negligible.

By the way, congrats to Apple for including the System 7.0 Sound Manager
in 6.0.6/6.0.7! I expect 6.0.8 will have TrueType in it...

Lawrence D'Oliveiro                       fone: +64-71-562-889
Computer Services Dept                     fax: +64-71-384-066
University of Waikato            electric mail: ldo@waikato.ac.nz
Hamilton, New Zealand    37^ 47' 26" S, 175^ 19' 7" E, GMT+12:00
You are in a twisty little maze of Word 4.0 dialog boxes, all different.