home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / demos / 134 / pascal / keycod.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1987-04-17  |  2.4 KB  |  49 lines

  1. {The question has been asked of how the game MEGAROIDS from Megamax can
  2.  handle _multiple_ keypresses simultaniously and still sort out when
  3.  each key has been pressed and released individually.  The following
  4.  program shows one possible solution.  Use it as you see fit, adapt it,
  5.  play with it, and let me see all of your great games you come up with!
  6. NOTE:   Some may say 'Why not simply use an event routine or a GEMDOS
  7.  call?' That works most of the time, but this routine will return not
  8.  only multiple key presses, but also the SHIFT,CONTROL,ALT,CAPS_LOCK and
  9.  all Function keys _individually_ which the various conin calls will not!}
  10.  
  11. {$ P-, R- }     {MUST turn range and bounds checking off!}
  12. PROGRAM   PEEKKEY;
  13.   VAR Key : INTEGER ;  { Used to store value of key pressed}
  14.  
  15.  FUNCTION    Super ( Address : Long_INTEGER ) : Long_INTEGER ;
  16.      GEMDOS( $20 ) ; { Switches in/out of SUPERVISOR Mode!!! }
  17.  
  18.  FUNCTION    Peek( Address : Long_INTEGER ) : BYTE ;
  19.   VAR SuperStack : Long_INTEGER ;{ Save this to return to USER mode.}
  20.       Switch_em : RECORD        { A weird looking variable declaration}
  21.         CASE    BOOLEAN   of    {  but the only way it works in Pascal}
  22.          False : ( L_Int : Long_INTEGER ) ;
  23.          True  : (  ptr  : ^INTEGER) ;
  24.         END ; {RECORD}
  25.       Temp     : INTEGER ;
  26.  BEGIN
  27.   SuperStack := Super( 0 )   ; { Enter SUPERVISOR Mode; must use '0'}
  28.   Switch_em.L_Int := Address ; {Change Long to pointer }
  29.   Temp := Switch_em.ptr^     ; {get what it points to  }
  30.   SuperStack := Super(SuperStack); { MUST go back to user mode}
  31.   Peek := ShR(Temp,8)        ; {Then give Key the right byte}
  32.  END ; {Peek}
  33.  
  34. BEGIN {Main}
  35.  While Key <> $10 {The 'Q' key} DO
  36.   BEGIN
  37.    Key := Peek( $FFFC02 ) ; { Find HARDWARE key-code}
  38.    Writeln ( Key :2:H) ;    { Output results in HEX }
  39.   END ; {While; loop again}
  40. END.  {Main}
  41.  
  42. { ADDITIONAL NOTE:  The value stored in $FFFC02 will be between 0 & 114 ($72)
  43. when a key is pressed.  Then when _that_ key is _released_ the original value
  44. + 128 ($80) is returned. I.E. pressing the 'Q' key sends 16 ($10), releasing
  45. it gives 144 ($90).  This means _any_ number of keys can be pressed together!
  46. The other values, those 115 thru 127, inclusive, and over 242 are mostly
  47. related to mouse events and the keyboard processor and should not be passed.}
  48.                 { Mark_Kelling }
  49. əəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəə