Subject: Re: Nubus card debugging
To: Dave Huang <khym@azeotrope.org>
From: David A. Gatwood <dgatwood@gatwood.net>
List: port-mac68k
Date: 08/05/2002 13:43:22
On Mon, 5 Aug 2002, Dave Huang wrote:

> On Mon, 5 Aug 2002, David A. Gatwood wrote:
> > Read the comment.  Not sure what DC&D is (but I probably should...).
> 
> I was pretty sure that DC&D is _Designing Cards and Drivers for
> Macintosh II and Macintosh SE_, but I just pulled out my copy, and
> there's no page 159. My copy has chapternumber-pagenumber style page
> numbers (e.g. 1-1 through 1-10, then 2-1 through 2-10, etc...)

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.

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;
	}
}

if (i== 16) {
	// no (valid) card present
} else {
	// the byte lanes are a bitmask stored in i,
	// i.e. byte lane 0 is 2^0, byte lane 1 is 2^1, etc.
}


Thoughts?
David

---------------------------------------------------------------------
David A. Gatwood                                dgatwood@gatwood.net
Developer Docs Writer                             dgatwood@apple.com
Apple Computer                                  dgatwood@mklinux.org

                    Check out my weekly web comic:
                     http://www.techmagazine.org