Subject: Re: Nubus card debugging
To: David A. Gatwood <dgatwood@gatwood.net>
From: Allen Briggs <briggs@wasabisystems.com>
List: port-mac68k
Date: 08/05/2002 20:44:21
On Mon, Aug 05, 2002 at 01:43:22PM -0700, David A. Gatwood wrote:
> That appears to be the first edition.  Later editions were called
> "Designing Cards and Drivers for the Macintosh Family".  The page number
> matches very nicely with the page number in the third edition, so I'm
> assuming that's the one that the comment refers to.

Precisely.

> Judging by that, the code is really, really overkill, and could be
> reduced to eight accesses (four pairs) and two non-nested for loops.
> 
> char array[4];
> 
> for (i=1; i<=4; i++) {
> 	array[4-i] = 0;
> 	if (mac68k_bus_space_probe(base + size - i)) {
> 		array[4-i] = inb(base + size - i);
> 	}
> }
> 
> for (i=1; i<16; i++) {
> 	if (i<2) pos=1;
> 	else if (i<4) pos=2;
> 	else if (i<8) pos=3;
> 	else pos=4;
> 	if (array[i] == (~(i << 4) & 0xf0) | i) {
> 		break;
> 	}
> }

Assuming you mean array[pos] instead of array[i] here, adjust for
0-based arrays w/o overrunning the end, and make array unsigned char
instead of signed...  ;-)
That looks much more reasonable.

-allen

-- 
 Allen Briggs                     briggs@wasabisystems.com
 http://www.wasabisystems.com/    Quality NetBSD CDs, Sales, Support, Service
NetBSD development for Alpha, ARM, M68K, MIPS, PowerPC, SuperH, XScale, etc...