Subject: Re: machdep.c and OF 3 keyboard handling
To: None <>
From: Derek Peschel <>
List: port-macppc
Date: 12/10/2001 14:51:49
On Fri, Dec 07, 2001 at 06:41:37AM -0800, Derek Peschel wrote:

> Though I haven't looked for the detailed BootROM version (more detailed
> than "OpenFirmware 3") I did discover a way to see if a method exists.
> It's FIND, and it takes a counted address (basically, pointer to string
> and length of string).  I believe it returns:
> Unfortunately trying it with literal strings, as in
> " words" find
> never gave me any useful results.

Now I understand FORTH strings better, so I've gotten useful results from
FIND.  This will allow our code to see which method (`usb-kbd-ihandle or
`usb-kbd-ihandles) exists, with no error messages cluttering the screen.

FORTH strings have a length (up to 255) and data.  Sometimes the length
is stored just before the data, and sometimes the length is stored
separately from the data.  There are two different conventions
for putting strings on the stack:

	- a pointer to the length byte; add one for a pointer
	  to the first data byte

	- the length (top of stack) and a pointer to the first
	  data byte (2nd in stack)

The word COUNT converts from the first convention to the second.
There is no UNCOUNT since there's no way to tell the address of the length
given only the length itself.  You could store the length before the
first data byte, but then you might erase some other data.

FIND starts by calling COUNT.  Unfortunately, pushing a literal string
already gives you the COUNT form of pointer.  You don't want to call COUNT
twice, and you can't call UNCOUNT (there is none).  At the OF prompt,
it's simplest to copy the definition of FIND, except for the COUNT,
to a new word.

The C code doesn't need to use OF to push literal strings -- instead,
C can just allocate a buffer (including the length byte) and call FIND.
Then we won't care if FIND's definition changes as long as the interface
stays the same.

-- Derek