|

楼主 |
发表于 2003-10-26 21:46:22
|
显示全部楼层
端口介绍:
http://www.doc.ic.ac.uk/~ih/doc/par/
Input from digital joystick to PC parallel port
Borland C/C++ version
- /* program readjs - input from digital joystick to PC parallel port
- *
- * compiled with Borland C++ version 3.1 under MS-DOS 6.22
- *
- * Copyright (c) 1997, Ian Harries and Imperial College, London, UK
- *
- * IBM-PC Parallel Printer Port Data & Status Registers
- * ====================================================
- * 7 6 5 4 3 2 1 0 I/O Port
- * +---+---+---+---+---+---+---+---+
- * Data | W | E | S | N | B | x | x | x | Base = 278/378/3BC Hex
- * +---+---+---+---+---+---+---+---+
- * Status |~W | E | S | N | B | - | - | - | Base + 1
- * +---+---+---+---+---+---+---+---+
- */
- #include <stdio.h>
- #include <conio.h> /* required only for function declarations */
- #define Data 0x378
- #define Status Data + 1
- #define BS 8 /* ASCII BackSpace */
- void main() {
- int JShigh, JSlow, i, oldbyte, newbyte;
- char backspace = BS;
- printf("\n");
- printf("Ian's Parallel Port JoyStick Reader\n");
- printf("===================================\n");
- printf("\n");
- printf("<Centre + Button> to Quit\n");
- printf("\n");
- oldbyte = 0xff; /* different from newbyte */
- outportb(Data,0xf8); /* output TTL High on enable lines */
- do {
- newbyte = inportb(Status);
- if (newbyte != oldbyte) { /* new joystick status */
- oldbyte = newbyte;
- for (i = 1; i <= 20; i++) { /* clear the previous status report */
- printf("%c",backspace); printf(" "); printf("%c",backspace);
- }
- JSlow = (newbyte & 0x0f) >> 3; /* Button Signal */
- JShigh = (newbyte ^ 0x80) >> 4; /* Direction Signal */
- switch (JShigh) {
- case 0: printf("Centre");
- break;
- case 1: printf("North");
- break;
- case 2: printf("South");
- break;
- case 4: printf("East");
- break;
- case 5: printf("NorthEast");
- break;
- case 6: printf("SouthEast");
- break;
- case 8: printf("West");
- break;
- case 9: printf("NorthWest");
- break;
- case 10: printf("SouthWest");
- }
- if (JSlow == 1)
- printf(" + Button");
- }
- }
- while ((JSlow != 1) || (JShigh != 0));
- printf("\n");
- }
复制代码 |
|