home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-386-Vol-2of3.iso / g / gametp20.zip / KEYBOARD.INT < prev    next >
Text File  |  1992-11-06  |  5KB  |  95 lines

  1. Unit KeyBoard;
  2.  
  3. { KeyBoard version 3.5b Copyright (C) 1992 Scott D. Ramsay }
  4.  
  5. {   Even back when I was making games for PC-Compute! I hated the fact }
  6. { that the keyboard can only handle one press at a time.  For games,   }
  7. { one needs to keep the SPACEBAR down (to fire) while using the arrow  }
  8. { keys to move.  The old keyboard int.  Can handle this.  So I wrote   }
  9. { a new keyboard interrupt.                                            }
  10. {   The keyboard is taken over at startup.                             }
  11. {   This Unit changes interrupts, in your own programs chain the       }
  12. { EXITPROC pointer so when exiting the old keyboard int is restored    }
  13. {    example:                                                          }
  14. {      Program QuickTest;                                              }
  15. {                                                                      }
  16. {      Uses Keyboard;                                                  }
  17. {      var                                                             }
  18. {        oldexitproc : pointer;                                        }
  19. {                                                                      }
  20. {      procedure cleanup; far;                                         }
  21. {      begin                                                           }
  22. {        { do your cleanup here }                                      }
  23. {        exitproc := oldexitproc;                                      }
  24. {      end;                                                            }
  25. {                                                                      }
  26. {      begin                                                           }
  27. {        oldexitproc := exitproc;                                      }
  28. {        exitproc := @cleanup;                                         }
  29. {      end.                                                            }
  30. {                                                                      }
  31. {   KEYBOARD.TPU can be used freely in commerical and non-commerical   }
  32. { programs.  As long as you don't give yourself credit for writing     }
  33. { this portion of the code.  When distributing it (free only), please  }
  34. { include all files and samples so others may enjoy using the code.    }
  35. { Enjoy.                                                               }
  36.  
  37. interface
  38.  
  39. var
  40.    ch : char;                        { contains the the ASCII     }
  41.                                      { value of the key pressed   }
  42.                                      { contians #1 if non pressed }
  43.    np : array[1..9,1..2] of boolean; { keypad, true if pressed    }
  44. {  np[7,1] - Q    }                  { np[7,2] - home             }
  45. {  np[8,1] - W    }                  { np[8,2] - up arrow         }
  46. {  np[9,1] - E    }                  { np[9,2] - pgup             }
  47. {  np[4,1] - A    }                  { np[4,2] - left arrow       }
  48. {  np[5,1] - S    }                  { np[5,2] - 5                }
  49. {  np[6,1] - D    }                  { np[6,2] - right arrow      }
  50. {  np[1,1] - Z    }                  { np[1,2] - end              }
  51. {  np[2,1] - X    }                  { np[2,2] - down arrow       }
  52. {  np[3,1] - C    }                  { np[2,3] - page down        }
  53.  
  54. { In games I mostly just use the "np" array "NumericPad"           }
  55. { Look at your keyboard, and you'll see why it's arranged this way }
  56. { Think of the second index number as player 1,player 2            }
  57.  
  58.    portb,                            { current scancode value          }
  59.                                      { < 128 key is down               }
  60.                                      { hi-bit set, scan code released  }
  61.    cleared,                          { True if interrupt not installed }
  62.    plus,                             { True if plus key is pressed     }
  63.    minus,                            { True if minus key is pressed    }
  64.    cold,                             { Set to True if you want to call }
  65.                                      { the old interrupt also, this is }
  66.                                      { kinda flaky. Try not to use     }
  67.    lshft,rshft,                      { True if shifts are pressed      }
  68.    space,                            { True if SPACE key is pressed    }
  69.    bspc,                             { True if bspc is pressed         }
  70.    funct,                            { True if CH is an extended scan-code }
  71.    esc,                              { True if ESC key pressed }
  72.    enter            : boolean;       { True if Enter is pressed }
  73.  
  74. procedure clearbuffer;               { Waits until CH=#1 }
  75. procedure clearkeyint;               { Restores old keyboard int }
  76. procedure cli; inline($fa);          { Disable ints }
  77. procedure sti; inline($fb);          { Enable ints }
  78. function st(h:longint):string;       { convert longint to string }
  79. function vl(h:string):longint;       { convert string to longint }
  80.  
  81. Implementation
  82.  
  83. (***********************************************************************)
  84.  
  85.  
  86. If you have any problems, e-mail at:
  87.  
  88.     ramsays@access.digex.com
  89.  
  90.   The TPU units can be used with in your programs.  If you want the source code, more samples or swap-talk,
  91.    just e-mail me.  I'll give sample use-code for free.  Actual TPU-source
  92.    code prices can be discussed.
  93.  
  94.    Scott D. Ramsay
  95.