home *** CD-ROM | disk | FTP | other *** search
- /***********************************************************/
- /* */
- /* Amiga C Encyclopedia (ACE) V3.0 Amiga C Club (ACC) */
- /* ------------------------------- ------------------ */
- /* */
- /* Book: ACM Intuition Amiga C Club */
- /* Chapter: DirtyInput Tulevagen 22 */
- /* File: Keyboard.c 181 41 LIDINGO */
- /* Author: Anders Bjerin SWEDEN */
- /* Date: 92-05-02 */
- /* Version: 1.10 */
- /* */
- /* Copyright 1992, Anders Bjerin - Amiga C Club (ACC) */
- /* */
- /* Registered members may use this program freely in their */
- /* own commercial/noncommercial programs/articles. */
- /* */
- /***********************************************************/
-
- /* Keyboard() is a handy, easy and fast but naughty function that hits */
- /* the hardware of the Amiga. It checks the keyboard, and returns the */
- /* Raw Key Code. (See chapter (C) SYSTEM DEFAULT CONSOLE KEY MAPPING */
- /* for the full list of Raw Key Codes.) */
- /* */
- /* Synopsis: value = Keyboard(); */
- /* */
- /* value: (UBYTE) Raw Key Code. For example: If the user hits key */
- /* "N", the function returns 36 (hexadecimal). When the user */
- /* releases the key, B6 is returned. */
-
-
- #include <exec/types.h>
- #include <hardware/cia.h>
-
-
-
- /* This will automatically be linked to the CIA A (8520) chip: */
- extern struct CIA far ciaa;
-
-
-
- void main();
- UBYTE Keyboard( void );
-
-
- void main()
- {
- int loop;
-
- for( loop = 0; loop < 100; loop++ )
- printf("Code: %2x\n", Keyboard() );
- }
-
-
-
- UBYTE Keyboard( void )
- {
- UBYTE code;
-
- /* Get a copy of the SDR value and invert it: */
- code = ciaa.ciasdr ^ 0xFF;
-
- /* Shift all bits one step to the right, and put the bit that is */
- /* pushed out last: 76543210 -> 07654321 */
- code = code & 0x01 ? (code>>1)+0x80 : code>>1;
-
- /* Return the Raw Key Code Value: */
- return( code );
- }
-