Re: Still working on the keyboard: is this function available in Euphoria??

new topic     » goto parent     » topic index » view thread      » older message » newer message

Hayden McKay wrote:

> Isn't the keyboard buffer 32 bytes long starting at 0040:001E  (#41E)?

Normally, yes.
But begin and size of the keyboard buffer can be changed by software, so
it's safer that your program looks for the actual values on the special
computer in the very moment, when it's running.

> Or is the 32 Byte word at 0040:001E just the start position of keyb buffer?

No. The 2 byte word at 0040:0080 (#0480) contains the start position of
the DOS keyboard buffer, see below.

> How did you get 16 bytes long?

The DOS keyboard buffer _normally_ has a size of 32 bytes. Since each
key occupies 2 bytes, there is space for 16 keys. Because it's a
circular buffer, only 15 keys actually can be used.

> I would like some help on this one as I have been stuck writing keyb buffer
> stuff in the past because of some confution here.

The same happened to me, when I first loked into this stuff. smile
The following is a translation of a PowerBASIC program that I wrote
several years ago, to Euphoria.

---------------------------[ begin program ]---------------------------
global type pointer (object x)
   -- 32 bit pointer
   if atom(x) and (x = floor(x))
   and (x >= 0) and (x <= #FFFFFFFF) then
      return 1
   end if
   return 0
end type

global function peek2u (object memory)
   -- usage: val = peek2u(addr)
   --        s   = peek2u({addr, count})
   -- returns unsigned 2-byte-integers
   atom addr
   integer count
   sequence s

   if atom(memory) then
      return and_bits(peek4u(memory), #FFFF)

   else
      addr = memory[1]
      count = memory[2]
      s = repeat(0, count)
      for i = 1 to count do
         s[i] = and_bits(peek4u(addr), #FFFF)
         addr += 2
      end for
      return s
   end if
end function


global function GetKbdLoc ()
   -- return address and size (number of keys) of the DOS keyboard buffer
   -- (each key occupies 2 bytes).
   pointer addr
   integer offBufBeg, offBufEnd, numKeys

   offBufBeg = peek2u(#0480)   -- offset of begin of buffer, normally #001E
   offBufEnd = peek2u(#0482)   -- offset of end   of buffer, normally #003E
   addr = #0400 + offBufBeg    -- segment of BIOS data = #0040
                               --  (address = segment*#10 + offset)
   numKeys = floor((offBufEnd-offBufBeg)/2) - 1
   return {addr, numKeys}
end function


-- Demo
include get.e         -- for wait_key()

sequence temp
temp = GetKbdLoc()
printf(1, "Address of DOS keyboard buffer: #%04x\n", {temp[1]})
printf(1, "Size of DOS keyboard buffer (number of keys): %d\n", {temp[2]})
puts(2, "\nPress any key ...")
if wait_key() then end if
----------------------------[ end program ]----------------------------

<snipped old text>

Regards,
   Juergen

-- 
 /"\  ASCII ribbon campain  |    |\      _,,,---,,_
 \ /  against HTML in       |    /,`.-'`'    -.  ;-;;,_
  X   e-mail and news,      |   |,4-  ) )-,_..;\ (  `'-'
 / \  and unneeded MIME     |  '---''(_/--'  `-'\_)

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu