Re: keyboard help
Bernie Ryan wrote:
> I think your peek and poke are interchanged.
You are correct; my code example shows how to read the buffer, not how to
write it. I've never actually tried writing to the buffer. Well, I've never
successfully written to it, anyway. Once I figured out that it was circular
and fairly small, I figured I had better things to do in life than to mess
with it.
> Also your peeking and poking addresses and not bytes.
Keep in mind that FIRST_INDEX *contains* a value. So to find the scanCode
for the next character in the buffer, you need to get the value out of
FIRST_INDEX and add it to KEY_BUFFER.
As I look at my example, it looks the address that I use for KEY_BUFFER is
actually off by 29 bytes. That is, the actual address of KEY_BUFFER is
probably:
KEY_BUFFER = 1083
so the examples would then read:
scanCode = peek( KEY_BUFFER + peek( FIRST_INDEX ) )
keyCode = peek( KEY_BUFFER + peek( FIRST_INDEX ) + 1 )
Or perhaps more clearly:
-- get the position of the first char in the buffer
index = peek( FIRST_INDEX )
-- look in the buffer for the scan code
scanCode = peek( KEY_BUFFER + index )
-- look in the buffer at the next byte for the key code
keyCode = peek( KEY_BUFFER + index + 1 )
I'm not even going to hazard trying to write an example that updates the
buffers. Among other issues, you have to turn off the interrupts. Otherwise,
if the user presses a key while your routine is running, *bad* things will
happen when the interrupt kicks in and updated the buffer that you were
messing with.
All in all, I think that Ralf's solution was the cleanest.
-- David Cuny
|
Not Categorized, Please Help
|
|