summaryrefslogtreecommitdiff
path: root/reference/C/CONTRIB/SNIP/ext_keys.c
diff options
context:
space:
mode:
Diffstat (limited to 'reference/C/CONTRIB/SNIP/ext_keys.c')
-rwxr-xr-xreference/C/CONTRIB/SNIP/ext_keys.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/reference/C/CONTRIB/SNIP/ext_keys.c b/reference/C/CONTRIB/SNIP/ext_keys.c
new file mode 100755
index 0000000..9ec2846
--- /dev/null
+++ b/reference/C/CONTRIB/SNIP/ext_keys.c
@@ -0,0 +1,56 @@
+/*
+** ext_getch()
+**
+** A getch() work-alike for use with extended keyboards.
+**
+** Parameters: none
+**
+** Returns: Extended key code as follows:
+** 0->255 Normal key
+** 256->511 Numeric pad key or Function key
+** 512->767 Cursor pad key or Numeric pad
+** "duplicate" key (Enter, /, *, -, +)
+**
+** Original Copyright 1992 by Bob Stout as part of
+** the MicroFirm Function Library (MFL)
+**
+** This subset version is hereby donated to the public domain.
+*/
+
+#include <dos.h>
+#include <ctype.h>
+
+#define LoByte(x) ((unsigned char)((x) & 0xff))
+#define HiByte(x) ((unsigned char)((unsigned short)(x) >> 8))
+
+int ext_getch(void)
+{
+ int key;
+ union REGS regs;
+
+ regs.h.ah = 0x10;
+ int86(0x16, &regs, &regs);
+ key = regs.x.ax;
+
+ switch (LoByte(key))
+ {
+ case 0:
+ key = HiByte(key) + 256;
+ break;
+
+ case 0xe0:
+ key = HiByte(key) + 512;
+ break;
+
+ default:
+ if (0xe0 == HiByte(key))
+ key = LoByte(key) + 512;
+ else
+ {
+ if (ispunct(LoByte(key)) && HiByte(key) > 0x36)
+ key = LoByte(key) + 512;
+ else key = LoByte(key);
+ }
+ }
+ return key;
+}