summaryrefslogtreecommitdiff
path: root/src/glut/dos/PC_HW
diff options
context:
space:
mode:
Diffstat (limited to 'src/glut/dos/PC_HW')
-rw-r--r--src/glut/dos/PC_HW/pc_hw.c141
-rw-r--r--src/glut/dos/PC_HW/pc_hw.h227
-rw-r--r--src/glut/dos/PC_HW/pc_irq.S180
-rw-r--r--src/glut/dos/PC_HW/pc_keyb.c532
-rw-r--r--src/glut/dos/PC_HW/pc_mouse.c243
-rw-r--r--src/glut/dos/PC_HW/pc_timer.c158
6 files changed, 1481 insertions, 0 deletions
diff --git a/src/glut/dos/PC_HW/pc_hw.c b/src/glut/dos/PC_HW/pc_hw.c
new file mode 100644
index 0000000000..d6ffd5650f
--- /dev/null
+++ b/src/glut/dos/PC_HW/pc_hw.c
@@ -0,0 +1,141 @@
+/*
+ * PC/HW routine collection v0.1 for DOS/DJGPP
+ *
+ * Copyright (C) 2002 - Borca Daniel
+ * Email : dborca@yahoo.com
+ * Web : http://www.geocities.com/dborca
+ */
+
+
+#include <dpmi.h>
+#include <fcntl.h>
+#include <sys/stat.h> /* for mode definitions */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "pc_hw.h"
+
+/*
+ * atexit
+ */
+#define MAX_ATEXIT 32
+
+static volatile int atexitcnt;
+static VFUNC atexittbl[MAX_ATEXIT];
+
+static void __attribute__((destructor)) doexit (void)
+{
+ while (atexitcnt) atexittbl[--atexitcnt]();
+}
+
+int pc_clexit (VFUNC f)
+{
+ int i;
+
+ for (i=0;i<atexitcnt;i++) {
+ if (atexittbl[i]==f) {
+ for (atexitcnt--;i<atexitcnt;i++) atexittbl[i] = atexittbl[i+1];
+ atexittbl[i] = 0;
+ return 0;
+ }
+ }
+ return -1;
+}
+
+int pc_atexit (VFUNC f)
+{
+ pc_clexit(f);
+ if (atexitcnt<MAX_ATEXIT) {
+ atexittbl[atexitcnt++] = f;
+ return 0;
+ }
+ return -1;
+}
+
+/*
+ * locked memory allocation
+ */
+void *pc_malloc (size_t size)
+{
+ void *p = malloc(size);
+
+ if (p) {
+ if (_go32_dpmi_lock_data(p, size)) {
+ free(p);
+ return NULL;
+ }
+ }
+
+ return p;
+}
+
+/*
+ * standard redirection
+ */
+static char errname[L_tmpnam];
+static char outname[L_tmpnam];
+
+static int h_out, h_outbak;
+static int h_err, h_errbak;
+
+void pc_open_stderr (void)
+{
+ if (tmpnam(errname)) {
+ h_err = open(errname, O_WRONLY |/* O_BINARY |*/ O_CREAT | O_TRUNC,
+ S_IREAD | S_IWRITE);
+ h_errbak = dup(2);
+ fflush(stderr);
+ dup2(h_err, 2);
+ }
+}
+
+void pc_close_stderr (void)
+{
+ FILE *f;
+ char *line = alloca(512);
+
+ dup2(h_errbak, 2);
+ close(h_err);
+ close(h_errbak);
+
+ if ((f=fopen(errname, "r"))!=NULL) {
+ while (fgets(line, 512, f)) {
+ fputs(line, stderr);
+ }
+ fclose(f);
+ }
+
+ remove(errname);
+}
+
+void pc_open_stdout (void)
+{
+ if (tmpnam(outname)) {
+ h_out = open(outname, O_WRONLY |/* O_BINARY |*/ O_CREAT | O_TRUNC,
+ S_IREAD | S_IWRITE);
+ h_outbak = dup(1);
+ fflush(stdout);
+ dup2(h_out, 1);
+ }
+}
+
+void pc_close_stdout (void)
+{
+ FILE *f;
+ char *line = alloca(512);
+
+ dup2(h_outbak, 1);
+ close(h_out);
+ close(h_outbak);
+
+ if ((f=fopen(outname, "r"))!=NULL) {
+ while (fgets(line, 512, f)) {
+ fputs(line, stdout);
+ }
+ fclose(f);
+ }
+
+ remove(outname);
+}
diff --git a/src/glut/dos/PC_HW/pc_hw.h b/src/glut/dos/PC_HW/pc_hw.h
new file mode 100644
index 0000000000..09fe8051bb
--- /dev/null
+++ b/src/glut/dos/PC_HW/pc_hw.h
@@ -0,0 +1,227 @@
+/*
+ * PC/HW routine collection v0.1 for DOS/DJGPP
+ *
+ * Copyright (C) 2002 - Borca Daniel
+ * Email : dborca@yahoo.com
+ * Web : http://www.geocities.com/dborca
+ */
+
+
+#ifndef PC_HW_H_included
+#define PC_HW_H_included
+
+#include <dpmi.h>
+#include <stdlib.h>
+
+/*
+ * misc C definitions
+ */
+#define FALSE 0
+#define TRUE !FALSE
+
+#define MIN(x,y) (((x) < (y)) ? (x) : (y))
+#define MAX(x,y) (((x) > (y)) ? (x) : (y))
+#define MID(x,y,z) MAX((x), MIN((y), (z)))
+
+typedef void (*VFUNC) (void);
+typedef void (*PFUNC) (void *);
+typedef void (*MFUNC) (int x, int y, int b);
+
+/*
+ * atexit
+ */
+int pc_atexit (VFUNC f);
+int pc_clexit (VFUNC f);
+
+/*
+ * locked memory
+ */
+#define ENDOFUNC(x) static void x##_end() { }
+#define LOCKFUNC(x) _go32_dpmi_lock_code((void *)x, (long)x##_end - (long)x)
+#define LOCKDATA(x) _go32_dpmi_lock_data((void *)&x, sizeof(x))
+
+void *pc_malloc (size_t size);
+
+/*
+ * IRQ
+ */
+#define ENABLE() __asm__ __volatile__ ("sti")
+#define DISABLE() __asm__ __volatile__ ("cli")
+
+extern int pc_install_irq (int i, int (*handler) ());
+extern int pc_remove_irq (int i);
+
+/*
+ * keyboard
+ */
+#define KB_SHIFT_FLAG 0x0001
+#define KB_CTRL_FLAG 0x0002
+#define KB_ALT_FLAG 0x0004
+#define KB_LWIN_FLAG 0x0008
+#define KB_RWIN_FLAG 0x0010
+#define KB_MENU_FLAG 0x0020
+#define KB_SCROLOCK_FLAG 0x0100
+#define KB_NUMLOCK_FLAG 0x0200
+#define KB_CAPSLOCK_FLAG 0x0400
+#define KB_INALTSEQ_FLAG 0x0800
+#define KB_ACCENT1_FLAG 0x1000
+#define KB_ACCENT2_FLAG 0x2000
+#define KB_ACCENT3_FLAG 0x4000
+#define KB_ACCENT4_FLAG 0x8000
+
+#define KEY_A 1
+#define KEY_B 2
+#define KEY_C 3
+#define KEY_D 4
+#define KEY_E 5
+#define KEY_F 6
+#define KEY_G 7
+#define KEY_H 8
+#define KEY_I 9
+#define KEY_J 10
+#define KEY_K 11
+#define KEY_L 12
+#define KEY_M 13
+#define KEY_N 14
+#define KEY_O 15
+#define KEY_P 16
+#define KEY_Q 17
+#define KEY_R 18
+#define KEY_S 19
+#define KEY_T 20
+#define KEY_U 21
+#define KEY_V 22
+#define KEY_W 23
+#define KEY_X 24
+#define KEY_Y 25
+#define KEY_Z 26
+#define KEY_0 27
+#define KEY_1 28
+#define KEY_2 29
+#define KEY_3 30
+#define KEY_4 31
+#define KEY_5 32
+#define KEY_6 33
+#define KEY_7 34
+#define KEY_8 35
+#define KEY_9 36
+#define KEY_0_PAD 37
+#define KEY_1_PAD 38
+#define KEY_2_PAD 39
+#define KEY_3_PAD 40
+#define KEY_4_PAD 41
+#define KEY_5_PAD 42
+#define KEY_6_PAD 43
+#define KEY_7_PAD 44
+#define KEY_8_PAD 45
+#define KEY_9_PAD 46
+#define KEY_F1 47
+#define KEY_F2 48
+#define KEY_F3 49
+#define KEY_F4 50
+#define KEY_F5 51
+#define KEY_F6 52
+#define KEY_F7 53
+#define KEY_F8 54
+#define KEY_F9 55
+#define KEY_F10 56
+#define KEY_F11 57
+#define KEY_F12 58
+#define KEY_ESC 59
+#define KEY_TILDE 60
+#define KEY_MINUS 61
+#define KEY_EQUALS 62
+#define KEY_BACKSPACE 63
+#define KEY_TAB 64
+#define KEY_OPENBRACE 65
+#define KEY_CLOSEBRACE 66
+#define KEY_ENTER 67
+#define KEY_COLON 68
+#define KEY_QUOTE 69
+#define KEY_BACKSLASH 70
+#define KEY_BACKSLASH2 71
+#define KEY_COMMA 72
+#define KEY_STOP 73
+#define KEY_SLASH 74
+#define KEY_SPACE 75
+#define KEY_INSERT 76
+#define KEY_DEL 77
+#define KEY_HOME 78
+#define KEY_END 79
+#define KEY_PGUP 80
+#define KEY_PGDN 81
+#define KEY_LEFT 82
+#define KEY_RIGHT 83
+#define KEY_UP 84
+#define KEY_DOWN 85
+#define KEY_SLASH_PAD 86
+#define KEY_ASTERISK 87
+#define KEY_MINUS_PAD 88
+#define KEY_PLUS_PAD 89
+#define KEY_DEL_PAD 90
+#define KEY_ENTER_PAD 91
+#define KEY_PRTSCR 92
+#define KEY_PAUSE 93
+#define KEY_ABNT_C1 94
+#define KEY_YEN 95
+#define KEY_KANA 96
+#define KEY_CONVERT 97
+#define KEY_NOCONVERT 98
+#define KEY_AT 99
+#define KEY_CIRCUMFLEX 100
+#define KEY_COLON2 101
+#define KEY_KANJI 102
+
+#define KEY_MODIFIERS 103
+
+#define KEY_LSHIFT 103
+#define KEY_RSHIFT 104
+#define KEY_LCONTROL 105
+#define KEY_RCONTROL 106
+#define KEY_ALT 107
+#define KEY_ALTGR 108
+#define KEY_LWIN 109
+#define KEY_RWIN 110
+#define KEY_MENU 111
+#define KEY_SCRLOCK 112
+#define KEY_NUMLOCK 113
+#define KEY_CAPSLOCK 114
+
+#define KEY_MAX 115
+
+extern volatile char pc_key[KEY_MAX];
+
+int pc_install_keyb (void);
+void pc_remove_keyb (void);
+int pc_keypressed (void);
+int pc_readkey (void);
+
+/*
+ * timer
+ */
+int pc_install_int (PFUNC func, void *parm, unsigned int freq);
+void pc_remove_timer (void);
+
+/*
+ * mouse
+ */
+extern volatile int pc_mouse_x, pc_mouse_y, pc_mouse_b;
+
+int pc_install_mouse (void);
+void pc_remove_mouse (void);
+MFUNC pc_install_mouse_handler (MFUNC handler);
+void pc_mouse_area (int x1, int y1, int x2, int y2);
+void pc_mouse_speed (int xspeed, int yspeed);
+void pc_show_mouse (void);
+void pc_scare_mouse (void);
+void pc_unscare_mouse (void);
+
+/*
+ * standard redirection
+ */
+void pc_open_stdout (void);
+void pc_open_stderr (void);
+void pc_close_stdout (void);
+void pc_close_stderr (void);
+
+#endif
diff --git a/src/glut/dos/PC_HW/pc_irq.S b/src/glut/dos/PC_HW/pc_irq.S
new file mode 100644
index 0000000000..2a6302f71a
--- /dev/null
+++ b/src/glut/dos/PC_HW/pc_irq.S
@@ -0,0 +1,180 @@
+/*
+ * PC/HW routine collection v0.1 for DOS/DJGPP
+ *
+ * Copyright (C) 2002 - Borca Daniel
+ * Email : dborca@yahoo.com
+ * Web : http://www.geocities.com/dborca
+ */
+
+
+ .file "pc_irq.S"
+
+ .text
+
+#define IRQ_STACK_SIZE 16384
+
+#define IRQ_WRAPPER_LEN (__irq_wrapper_1-__irq_wrapper_0)
+#define IRQ_OLD (__irq_old_0-__irq_wrapper_0)
+#define IRQ_HOOK (__irq_hook_0-__irq_wrapper_0)
+#define IRQ_STACK (__irq_stack_0-__irq_wrapper_0)
+
+ .balign 4
+common:
+ movw $0x0400, %ax
+ int $0x31
+
+ movl %ss:8(%ebp), %ebx
+ cmpl $15, %ebx
+ jbe 0f
+ fail:
+ orl $-1, %eax
+ popl %edi
+ popl %ebx
+ leave
+ ret
+
+ 0:
+ movl %ebx, %edi
+ imull $IRQ_WRAPPER_LEN, %edi
+ addl $__irq_wrapper_0, %edi
+
+ cmpb $7, %bl
+ jbe 1f
+ movb %dl, %dh
+ subb $8, %dh
+ 1:
+ addb %dh, %bl
+ ret
+
+ .balign 4
+ .global _pc_install_irq
+_pc_install_irq:
+ pushl %ebp
+ movl %esp, %ebp
+ pushl %ebx
+ pushl %edi
+
+ call common
+
+ cmpl $0, IRQ_HOOK(%edi)
+ jne fail
+
+ pushl $IRQ_WRAPPER_LEN
+ pushl %edi
+ call __go32_dpmi_lock_code
+ addl $8, %esp
+ testl %eax, %eax
+ jnz fail
+
+ pushl $IRQ_STACK_SIZE
+ call _pc_malloc
+ popl %edx
+ testl %eax, %eax
+ jz fail
+ addl %edx, %eax
+ movl %eax, IRQ_STACK(%edi)
+
+ movl %ss:12(%ebp), %eax
+ movl %eax, IRQ_HOOK(%edi)
+
+ movw $0x0204, %ax
+ int $0x31
+ movl %edx, IRQ_OLD(%edi)
+ movw %cx, IRQ_OLD+4(%edi)
+ movw $0x0205, %ax
+ movl %edi, %edx
+ movl %cs, %ecx
+ int $0x31
+
+ done:
+ xorl %eax, %eax
+ popl %edi
+ popl %ebx
+ leave
+ ret
+
+ .balign 4
+ .global _pc_remove_irq
+_pc_remove_irq:
+ pushl %ebp
+ movl %esp, %ebp
+ pushl %ebx
+ pushl %edi
+
+ call common
+
+ cmpl $0, IRQ_HOOK(%edi)
+ je fail
+
+ movl $0, IRQ_HOOK(%edi)
+
+ movw $0x0205, %ax
+ movl IRQ_OLD(%edi), %edx
+ movl IRQ_OLD+4(%edi), %ecx
+ int $0x31
+
+ movl IRQ_STACK(%edi), %eax
+ subl $IRQ_STACK_SIZE, %eax
+ pushl %eax
+ call _free
+ popl %eax
+
+ jmp done
+
+#define WRAPPER(x) ; \
+ .balign 4 ; \
+__irq_wrapper_##x: ; \
+ pushal ; \
+ pushl %ds ; \
+ pushl %es ; \
+ pushl %fs ; \
+ pushl %gs ; \
+ movw %ss, %bx ; \
+ movl %esp, %esi ; \
+ movl %cs:___djgpp_ds_alias, %ss ; \
+ movl %cs:__irq_stack_##x, %esp ; \
+ pushl %ss ; \
+ pushl %ss ; \
+ popl %es ; \
+ popl %ds ; \
+ movl ___djgpp_dos_sel, %fs ; \
+ pushl %fs ; \
+ popl %gs ; \
+ call *__irq_hook_##x ; \
+ movw %bx, %ss ; \
+ movl %esi, %esp ; \
+ testl %eax, %eax ; \
+ popl %gs ; \
+ popl %fs ; \
+ popl %es ; \
+ popl %ds ; \
+ popal ; \
+ jz __irq_ignore_##x ; \
+__irq_bypass_##x: ; \
+ ljmp *%cs:__irq_old_##x ; \
+__irq_ignore_##x: ; \
+ iret ; \
+ .balign 4 ; \
+__irq_old_##x: ; \
+ .long 0, 0 ; \
+__irq_hook_##x: ; \
+ .long 0 ; \
+__irq_stack_##x: ; \
+ .long 0
+
+ WRAPPER(0);
+ WRAPPER(1);
+ WRAPPER(2);
+ WRAPPER(3);
+ WRAPPER(4);
+ WRAPPER(5);
+ WRAPPER(6);
+ WRAPPER(7);
+ WRAPPER(8);
+ WRAPPER(9);
+ WRAPPER(10);
+ WRAPPER(11);
+ WRAPPER(12);
+ WRAPPER(13);
+ WRAPPER(14);
+ WRAPPER(15);
diff --git a/src/glut/dos/PC_HW/pc_keyb.c b/src/glut/dos/PC_HW/pc_keyb.c
new file mode 100644
index 0000000000..f5f4bd8e76
--- /dev/null
+++ b/src/glut/dos/PC_HW/pc_keyb.c
@@ -0,0 +1,532 @@
+/*
+ * PC/HW routine collection v0.1 for DOS/DJGPP
+ *
+ * Copyright (C) 2002 - Borca Daniel
+ * Email : dborca@yahoo.com
+ * Web : http://www.geocities.com/dborca
+ */
+
+
+#include <pc.h>
+#include <sys/exceptn.h>
+#include <sys/farptr.h>
+
+#include "pc_hw.h"
+
+
+
+#define KEYB_IRQ 1
+
+#define KEY_BUFFER_SIZE 64
+
+#define KB_MODIFIERS (KB_SHIFT_FLAG | KB_CTRL_FLAG | KB_ALT_FLAG | KB_LWIN_FLAG | KB_RWIN_FLAG | KB_MENU_FLAG)
+#define KB_LED_FLAGS (KB_SCROLOCK_FLAG | KB_NUMLOCK_FLAG | KB_CAPSLOCK_FLAG)
+
+static int keyboard_installed;
+
+static volatile struct {
+ volatile int start, end;
+ volatile int key[KEY_BUFFER_SIZE];
+} key_buffer;
+
+static volatile int key_enhanced, key_pause_loop, key_shifts;
+static int leds_ok = TRUE;
+static int in_a_terrupt = FALSE;
+volatile char pc_key[KEY_MAX];
+
+
+
+/* convert Allegro format scancodes into key_shifts flag bits */
+static unsigned short modifier_table[KEY_MAX - KEY_MODIFIERS] =
+{
+ KB_SHIFT_FLAG, KB_SHIFT_FLAG, KB_CTRL_FLAG,
+ KB_CTRL_FLAG, KB_ALT_FLAG, KB_ALT_FLAG,
+ KB_LWIN_FLAG, KB_RWIN_FLAG, KB_MENU_FLAG,
+ KB_SCROLOCK_FLAG, KB_NUMLOCK_FLAG, KB_CAPSLOCK_FLAG
+};
+
+
+
+/* lookup table for converting hardware scancodes into Allegro format */
+static unsigned char hw_to_mycode[128] =
+{
+ /* 0x00 */ 0, KEY_ESC, KEY_1, KEY_2,
+ /* 0x04 */ KEY_3, KEY_4, KEY_5, KEY_6,
+ /* 0x08 */ KEY_7, KEY_8, KEY_9, KEY_0,
+ /* 0x0C */ KEY_MINUS, KEY_EQUALS, KEY_BACKSPACE, KEY_TAB,
+ /* 0x10 */ KEY_Q, KEY_W, KEY_E, KEY_R,
+ /* 0x14 */ KEY_T, KEY_Y, KEY_U, KEY_I,
+ /* 0x18 */ KEY_O, KEY_P, KEY_OPENBRACE, KEY_CLOSEBRACE,
+ /* 0x1C */ KEY_ENTER, KEY_LCONTROL, KEY_A, KEY_S,
+ /* 0x20 */ KEY_D, KEY_F, KEY_G, KEY_H,
+ /* 0x24 */ KEY_J, KEY_K, KEY_L, KEY_COLON,
+ /* 0x28 */ KEY_QUOTE, KEY_TILDE, KEY_LSHIFT, KEY_BACKSLASH,
+ /* 0x2C */ KEY_Z, KEY_X, KEY_C, KEY_V,
+ /* 0x30 */ KEY_B, KEY_N, KEY_M, KEY_COMMA,
+ /* 0x34 */ KEY_STOP, KEY_SLASH, KEY_RSHIFT, KEY_ASTERISK,
+ /* 0x38 */ KEY_ALT, KEY_SPACE, KEY_CAPSLOCK, KEY_F1,
+ /* 0x3C */ KEY_F2, KEY_F3, KEY_F4, KEY_F5,
+ /* 0x40 */ KEY_F6, KEY_F7, KEY_F8, KEY_F9,
+ /* 0x44 */ KEY_F10, KEY_NUMLOCK, KEY_SCRLOCK, KEY_7_PAD,
+ /* 0x48 */ KEY_8_PAD, KEY_9_PAD, KEY_MINUS_PAD, KEY_4_PAD,
+ /* 0x4C */ KEY_5_PAD, KEY_6_PAD, KEY_PLUS_PAD, KEY_1_PAD,
+ /* 0x50 */ KEY_2_PAD, KEY_3_PAD, KEY_0_PAD, KEY_DEL_PAD,
+ /* 0x54 */ KEY_PRTSCR, 0, KEY_BACKSLASH2, KEY_F11,
+ /* 0x58 */ KEY_F12, 0, 0, KEY_LWIN,
+ /* 0x5C */ KEY_RWIN, KEY_MENU, 0, 0,
+ /* 0x60 */ 0, 0, 0, 0,
+ /* 0x64 */ 0, 0, 0, 0,
+ /* 0x68 */ 0, 0, 0, 0,
+ /* 0x6C */ 0, 0, 0, 0,
+ /* 0x70 */ KEY_KANA, 0, 0, KEY_ABNT_C1,
+ /* 0x74 */ 0, 0, 0, 0,
+ /* 0x78 */ 0, KEY_CONVERT, 0, KEY_NOCONVERT,
+ /* 0x7C */ 0, KEY_YEN, 0, 0
+};
+
+
+
+/* lookup table for converting extended hardware codes into Allegro format */
+static unsigned char hw_to_mycode_ex[128] =
+{
+ /* 0x00 */ 0, KEY_ESC, KEY_1, KEY_2,
+ /* 0x04 */ KEY_3, KEY_4, KEY_5, KEY_6,
+ /* 0x08 */ KEY_7, KEY_8, KEY_9, KEY_0,
+ /* 0x0C */ KEY_MINUS, KEY_EQUALS, KEY_BACKSPACE, KEY_TAB,
+ /* 0x10 */ KEY_CIRCUMFLEX, KEY_AT, KEY_COLON2, KEY_R,
+ /* 0x14 */ KEY_KANJI, KEY_Y, KEY_U, KEY_I,
+ /* 0x18 */ KEY_O, KEY_P, KEY_OPENBRACE, KEY_CLOSEBRACE,
+ /* 0x1C */ KEY_ENTER_PAD, KEY_RCONTROL, KEY_A, KEY_S,
+ /* 0x20 */ KEY_D, KEY_F, KEY_G, KEY_H,
+ /* 0x24 */ KEY_J, KEY_K, KEY_L, KEY_COLON,
+ /* 0x28 */ KEY_QUOTE, KEY_TILDE, 0, KEY_BACKSLASH,
+ /* 0x2C */ KEY_Z, KEY_X, KEY_C, KEY_V,
+ /* 0x30 */ KEY_B, KEY_N, KEY_M, KEY_COMMA,
+ /* 0x34 */ KEY_STOP, KEY_SLASH_PAD, 0, KEY_PRTSCR,
+ /* 0x38 */ KEY_ALTGR, KEY_SPACE, KEY_CAPSLOCK, KEY_F1,
+ /* 0x3C */ KEY_F2, KEY_F3, KEY_F4, KEY_F5,
+ /* 0x40 */ KEY_F6, KEY_F7, KEY_F8, KEY_F9,
+ /* 0x44 */ KEY_F10, KEY_NUMLOCK, KEY_PAUSE, KEY_HOME,
+ /* 0x48 */ KEY_UP, KEY_PGUP, KEY_MINUS_PAD, KEY_LEFT,
+ /* 0x4C */ KEY_5_PAD, KEY_RIGHT, KEY_PLUS_PAD, KEY_END,
+ /* 0x50 */ KEY_DOWN, KEY_PGDN, KEY_INSERT, KEY_DEL,
+ /* 0x54 */ KEY_PRTSCR, 0, KEY_BACKSLASH2, KEY_F11,
+ /* 0x58 */ KEY_F12, 0, 0, KEY_LWIN,
+ /* 0x5C */ KEY_RWIN, KEY_MENU, 0, 0,
+ /* 0x60 */ 0, 0, 0, 0,
+ /* 0x64 */ 0, 0, 0, 0,
+ /* 0x68 */ 0, 0, 0, 0,
+ /* 0x6C */ 0, 0, 0, 0,
+ /* 0x70 */ 0, 0, 0, 0,
+ /* 0x74 */ 0, 0, 0, 0,
+ /* 0x78 */ 0, 0, 0, 0,
+ /* 0x7C */ 0, 0, 0, 0
+};
+
+
+
+/* default mapping table for the US keyboard layout */
+static unsigned short standard_key_ascii_table[KEY_MAX] =
+{
+ /* start */ 0,
+ /* alphabet */ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
+ /* numbers */ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
+ /* numpad */ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
+ /* func keys */ 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
+ /* misc chars */ 27, '`', '-', '=', 8, 9, '[', ']', 13, ';', '\'', '\\', '\\', ',', '.', '/', ' ',
+ /* controls */ 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
+ /* numpad */ '/', '*', '-', '+', '.', 13,
+ /* modifiers */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+};
+
+
+
+/* capslock mapping table for the US keyboard layout */
+static unsigned short standard_key_capslock_table[KEY_MAX] =
+{
+ /* start */ 0,
+ /* alphabet */ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
+ /* numbers */ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
+ /* numpad */ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
+ /* func keys */ 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
+ /* misc chars */ 27, '`', '-', '=', 8, 9, '[', ']', 13, ';', '\'', '\\', '\\', ',', '.', '/', ' ',
+ /* controls */ 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
+ /* numpad */ '/', '*', '-', '+', '.', 13,
+ /* modifiers */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+};
+
+
+
+/* shifted mapping table for the US keyboard layout */
+static unsigned short standard_key_shift_table[KEY_MAX] =
+{
+ /* start */ 0,
+ /* alphabet */ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
+ /* numbers */ ')', '!', '@', '#', '$', '%', '^', '&', '*', '(',
+ /* numpad */ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
+ /* func keys */ 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
+ /* misc chars */ 27, '~', '_', '+', 8, 9, '{', '}', 13, ':', '"', '|', '|', '<', '>', '?', ' ',
+ /* controls */ 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
+ /* numpad */ '/', '*', '-', '+', '.', 13,
+ /* modifiers */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+};
+
+
+
+/* ctrl+key mapping table for the US keyboard layout */
+static unsigned short standard_key_control_table[KEY_MAX] =
+{
+ /* start */ 0,
+ /* alphabet */ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
+ /* numbers */ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ /* numpad */ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
+ /* func keys */ 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
+ /* misc chars */ 27, 2, 2, 2, 127, 127, 2, 2, 10, 2, 2, 2, 2, 2, 2, 2, 2,
+ /* controls */ 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
+ /* numpad */ 2, 2, 2, 2, 2, 10,
+ /* modifiers */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+};
+
+
+
+/* convert numeric pad scancodes into arrow codes */
+static unsigned char numlock_table[10] =
+{
+ KEY_INSERT, KEY_END, KEY_DOWN, KEY_PGDN, KEY_LEFT,
+ KEY_5_PAD, KEY_RIGHT, KEY_HOME, KEY_UP, KEY_PGUP
+};
+
+
+
+/* kb_wait_for_write_ready:
+ * Wait for the keyboard controller to set the ready-for-write bit.
+ */
+static __inline__ int kb_wait_for_write_ready (void)
+{
+ int timeout = 4096;
+
+ while ((timeout>0) && (inportb(0x64)&2)) timeout--;
+
+ return (timeout>0);
+}
+
+
+
+/* kb_wait_for_read_ready:
+ * Wait for the keyboard controller to set the ready-for-read bit.
+ */
+static __inline__ int kb_wait_for_read_ready (void)
+{
+ int timeout = 16384;
+
+ while ((timeout>0) && (!(inportb(0x64)&1))) timeout--;
+
+ return (timeout>0);
+}
+
+
+
+/* kb_send_data:
+ * Sends a byte to the keyboard controller. Returns 1 if all OK.
+ */
+static __inline__ int kb_send_data (unsigned char data)
+{
+ int resends = 4;
+ int timeout, temp;
+
+ do {
+ if (!kb_wait_for_write_ready())
+ return 0;
+
+ outportb(0x60, data);
+ timeout = 4096;
+
+ while (--timeout>0) {
+ if (!kb_wait_for_read_ready())
+ return 0;
+
+ temp = inportb(0x60);
+
+ if (temp == 0xFA)
+ return 1;
+
+ if (temp == 0xFE)
+ break;
+ }
+ } while ((resends-- > 0) && (timeout > 0));
+
+ return 0;
+}
+
+
+
+static void update_leds (int leds)
+{
+ if (leds_ok) {
+ if (!in_a_terrupt)
+ DISABLE();
+
+ if (!kb_send_data(0xED)) {
+ kb_send_data(0xF4);
+ leds_ok = FALSE;
+ } else if (!kb_send_data((leds>>8)&7)) {
+ kb_send_data(0xF4);
+ leds_ok = FALSE;
+ }
+
+ if (!in_a_terrupt)
+ ENABLE();
+ }
+} ENDOFUNC(update_leds)
+
+
+
+static void inject_key (int scancode)
+{
+ unsigned short *table;
+
+ if ((scancode >= KEY_0_PAD) && (scancode <= KEY_9_PAD)) {
+ if (((key_shifts & KB_NUMLOCK_FLAG) != 0) == ((key_shifts & KB_SHIFT_FLAG) != 0)) {
+ scancode = numlock_table[scancode - KEY_0_PAD];
+ }
+ table = standard_key_ascii_table;
+ } else if (key_shifts & KB_CTRL_FLAG) {
+ table = standard_key_control_table;
+ } else if (key_shifts & KB_SHIFT_FLAG) {
+ if (key_shifts & KB_CAPSLOCK_FLAG) {
+ if (standard_key_ascii_table[scancode]==standard_key_capslock_table[scancode]) {
+ table = standard_key_shift_table;
+ } else {
+ table = standard_key_ascii_table;
+ }
+ } else {
+ table = standard_key_shift_table;
+ }
+ } else if (key_shifts & KB_CAPSLOCK_FLAG) {
+ table = standard_key_capslock_table;
+ } else {
+ table = standard_key_ascii_table;
+ }
+
+ key_buffer.key[key_buffer.end++] = (scancode<<16)|table[scancode];
+
+ if (key_buffer.end>=KEY_BUFFER_SIZE)
+ key_buffer.end = 0;
+ if (key_buffer.end==key_buffer.start) {
+ key_buffer.start++;
+ if (key_buffer.start>=KEY_BUFFER_SIZE)
+ key_buffer.start = 0;
+ }
+} ENDOFUNC(inject_key)
+
+static void handle_code (int scancode, int keycode)
+{
+ in_a_terrupt++;
+
+ if (keycode==0) { /* pause */
+ inject_key(scancode);
+ pc_key[KEY_PAUSE] ^= TRUE;
+ } else if (scancode) {
+ int flag;
+
+ if (scancode>=KEY_MODIFIERS) {
+ flag = modifier_table[scancode - KEY_MODIFIERS];
+ } else {
+ flag = 0;
+ }
+ if ((char)keycode<0) { /* release */
+ pc_key[scancode] = FALSE;
+ if (flag&KB_MODIFIERS) {
+ key_shifts &= ~flag;
+ }
+ } else { /* keypress */
+ pc_key[scancode] = TRUE;
+ if (flag&KB_MODIFIERS) {
+ key_shifts |= flag;
+ }
+ if (flag&KB_LED_FLAGS) {
+ key_shifts ^= flag;
+ update_leds(key_shifts);
+ }
+ if (scancode<KEY_MODIFIERS) {
+ inject_key(scancode);
+ }
+ }
+ }
+
+ in_a_terrupt--;
+} ENDOFUNC(handle_code)
+
+static __inline__ void satisfy (void)
+{
+ __asm__("\n\
+ inb $0x61, %%al \n\
+ movb %%al, %%ah \n\
+ orb $0x80, %%al \n\
+ outb %%al, $0x61 \n\
+ xchgb %%al, %%ah \n\
+ outb %%al, $0x61 \n\
+ movb $0x20, %%al \n\
+ outb %%al, $0x20 \n\
+ ":::"%eax");
+}
+
+static int keyboard ()
+{
+ unsigned char temp, scancode;
+
+ temp = inportb(0x60);
+
+ if (temp<=0xe1) {
+ if (key_pause_loop) {
+ if (!--key_pause_loop) handle_code(KEY_PAUSE, 0);
+ } else
+ switch (temp) {
+ case 0xe0:
+ key_enhanced = TRUE;
+ break;
+ case 0xe1:
+ key_pause_loop = 5;
+ break;
+ default:
+ if (key_enhanced) {
+ key_enhanced = FALSE;
+ scancode = hw_to_mycode_ex[temp&0x7f];
+ } else {
+ scancode = hw_to_mycode[temp&0x7f];
+ }
+ handle_code(scancode, temp);
+ }
+ }
+
+ if (((temp==0x4F)||(temp==0x53))&&(key_shifts&KB_CTRL_FLAG)&&(key_shifts&KB_ALT_FLAG)) {
+ __asm__("\n\
+ movb $0x79, %%al \n\
+ call ___djgpp_hw_exception \n\
+ ":::"%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory");
+ }
+
+ satisfy();
+ return 0;
+} ENDOFUNC(keyboard)
+
+
+int pc_keypressed (void)
+{
+ return (key_buffer.start!=key_buffer.end);
+}
+
+int pc_readkey (void)
+{
+ if (keyboard_installed) {
+ int key;
+
+ do {
+ } while (key_buffer.start==key_buffer.end);
+
+ DISABLE();
+ key = key_buffer.key[key_buffer.start++];
+ if (key_buffer.start>=KEY_BUFFER_SIZE)
+ key_buffer.start = 0;
+ ENABLE();
+
+ return key;
+ } else {
+ return 0;
+ }
+}
+
+void pc_remove_keyb (void)
+{
+ if (keyboard_installed) {
+ int s1, s2, s3;
+
+ keyboard_installed = FALSE;
+ pc_clexit(pc_remove_keyb);
+
+ DISABLE();
+ _farsetsel(__djgpp_dos_sel);
+ _farnspokew(0x41c, _farnspeekw(0x41a));
+
+ s1 = _farnspeekb(0x417) & 0x80;
+ s2 = _farnspeekb(0x418) & 0xFC;
+ s3 = _farnspeekb(0x496) & 0xF3;
+
+ if (pc_key[KEY_RSHIFT]) { s1 |= 1; }
+ if (pc_key[KEY_LSHIFT]) { s1 |= 2; }
+ if (pc_key[KEY_LCONTROL]) { s2 |= 1; s1 |= 4; }
+ if (pc_key[KEY_ALT]) { s1 |= 8; s2 |= 2; }
+ if (pc_key[KEY_RCONTROL]) { s1 |= 4; s3 |= 4; }
+ if (pc_key[KEY_ALTGR]) { s1 |= 8; s3 |= 8; }
+
+ if (key_shifts&KB_SCROLOCK_FLAG) s1 |= 16;
+ if (key_shifts&KB_NUMLOCK_FLAG) s1 |= 32;
+ if (key_shifts&KB_CAPSLOCK_FLAG) s1 |= 64;
+
+ _farnspokeb(0x417, s1);
+ _farnspokeb(0x418, s2);
+ _farnspokeb(0x496, s3);
+ update_leds(key_shifts);
+
+ ENABLE();
+ pc_remove_irq(KEYB_IRQ);
+ }
+}
+
+int pc_install_keyb (void)
+{
+ if (keyboard_installed||pc_install_irq(KEYB_IRQ, keyboard)) {
+ return -1;
+ } else {
+ int s1, s2, s3;
+
+ LOCKDATA(key_buffer);
+ LOCKDATA(key_enhanced);
+ LOCKDATA(key_pause_loop);
+ LOCKDATA(key_shifts);
+ LOCKDATA(leds_ok);
+ LOCKDATA(in_a_terrupt);
+ LOCKDATA(pc_key);
+ LOCKDATA(modifier_table);
+ LOCKDATA(hw_to_mycode);
+ LOCKDATA(hw_to_mycode_ex);
+ LOCKDATA(standard_key_ascii_table);
+ LOCKDATA(standard_key_capslock_table);
+ LOCKDATA(standard_key_shift_table);
+ LOCKDATA(standard_key_control_table);
+ LOCKDATA(numlock_table);
+ LOCKFUNC(update_leds);
+ LOCKFUNC(inject_key);
+ LOCKFUNC(handle_code);
+ LOCKFUNC(keyboard);
+
+ DISABLE();
+ _farsetsel(__djgpp_dos_sel);
+ _farnspokew(0x41c, _farnspeekw(0x41a));
+
+ key_shifts = 0;
+ s1 = _farnspeekb(0x417);
+ s2 = _farnspeekb(0x418);
+ s3 = _farnspeekb(0x496);
+
+ if (s1&1) { key_shifts |= KB_SHIFT_FLAG; pc_key[KEY_RSHIFT] = TRUE; }
+ if (s1&2) { key_shifts |= KB_SHIFT_FLAG; pc_key[KEY_LSHIFT] = TRUE; }
+ if (s2&1) { key_shifts |= KB_CTRL_FLAG; pc_key[KEY_LCONTROL] = TRUE; }
+ if (s2&2) { key_shifts |= KB_ALT_FLAG; pc_key[KEY_ALT] = TRUE; }
+ if (s3&4) { key_shifts |= KB_CTRL_FLAG; pc_key[KEY_RCONTROL] = TRUE; }
+ if (s3&8) { key_shifts |= KB_ALT_FLAG; pc_key[KEY_ALTGR] = TRUE; }
+
+ if (s1&16) key_shifts |= KB_SCROLOCK_FLAG;
+ if (s1&32) key_shifts |= KB_NUMLOCK_FLAG;
+ if (s1&64) key_shifts |= KB_CAPSLOCK_FLAG;
+ update_leds(key_shifts);
+
+ key_enhanced = key_pause_loop = 0;
+ key_buffer.start = key_buffer.end = 0;
+ ENABLE();
+
+ pc_atexit(pc_remove_keyb);
+ keyboard_installed = TRUE;
+ return 0;
+ }
+}
diff --git a/src/glut/dos/PC_HW/pc_mouse.c b/src/glut/dos/PC_HW/pc_mouse.c
new file mode 100644
index 0000000000..cc3396cb21
--- /dev/null
+++ b/src/glut/dos/PC_HW/pc_mouse.c
@@ -0,0 +1,243 @@
+/*
+ * PC/HW routine collection v0.1 for DOS/DJGPP
+ *
+ * Copyright (C) 2002 - Borca Daniel
+ * Email : dborca@yahoo.com
+ * Web : http://www.geocities.com/dborca
+ */
+
+
+#include <dpmi.h>
+
+#include "pc_hw.h"
+
+
+
+#define MOUSE_STACK_SIZE 16384
+
+extern void mouse_wrapper (void);
+extern void mouse_wrapper_end (void);
+
+static MFUNC mouse_func;
+static void *mouse_stack;
+static long mouse_callback;
+static __dpmi_regs mouse_regs;
+
+volatile int pc_mouse_x, pc_mouse_y, pc_mouse_b;
+
+static int minx = 0;
+static int maxx = 319;
+static int miny = 0;
+static int maxy = 199;
+
+static int sx = 2;
+static int sy = 2;
+
+static int emulat3 = FALSE;
+
+static int ox, oy;
+
+static void mouse (__dpmi_regs *r)
+{
+ int nx = (signed short)r->x.si / sx;
+ int ny = (signed short)r->x.di / sy;
+ int dx = nx - ox;
+ int dy = ny - oy;
+ ox = nx;
+ oy = ny;
+
+ pc_mouse_b = r->x.bx;
+ pc_mouse_x = MID(minx, pc_mouse_x + dx, maxx);
+ pc_mouse_y = MID(miny, pc_mouse_y + dy, maxy);
+
+ if (emulat3) {
+ if ((pc_mouse_b&3)==3) {
+ pc_mouse_b = 4;
+ }
+ }
+
+ if (mouse_func) {
+ mouse_func(pc_mouse_x, pc_mouse_y, pc_mouse_b);
+ }
+} ENDOFUNC(mouse)
+
+void pc_remove_mouse (void)
+{
+ if (mouse_callback) {
+ pc_clexit(pc_remove_mouse);
+ __asm__("\n\
+ movl %%edx, %%ecx \n\
+ shrl $16, %%ecx \n\
+ movw $0x0304, %%ax \n\
+ int $0x31 \n\
+ movw $0x000c, %%ax \n\
+ xorl %%ecx, %%ecx \n\
+ int $0x33 \n\
+ "::"d"(mouse_callback):"%eax", "%ecx");
+
+ mouse_callback = 0;
+
+ free((void *)((unsigned long)mouse_stack-MOUSE_STACK_SIZE));
+ }
+}
+
+int pc_install_mouse (void)
+{
+ int buttons;
+
+ /* fail if already call-backed */
+ if (mouse_callback) {
+ return 0;
+ }
+
+ /* reset mouse and get status */
+ __asm__("\n\
+ xorl %%eax, %%eax \n\
+ int $0x33 \n\
+ andl %%ebx, %%eax \n\
+ movl %%eax, %0 \n\
+ ":"=g" (buttons)::"%eax", "%ebx");
+ if (!buttons) {
+ return 0;
+ }
+
+ /* lock wrapper */
+ LOCKDATA(mouse_func);
+ LOCKDATA(mouse_stack);
+ LOCKDATA(mouse_callback);
+ LOCKDATA(mouse_regs);
+ LOCKDATA(pc_mouse_x);
+ LOCKDATA(pc_mouse_y);
+ LOCKDATA(pc_mouse_b);
+ LOCKDATA(minx);
+ LOCKDATA(maxx);
+ LOCKDATA(miny);
+ LOCKDATA(maxy);
+ LOCKDATA(sx);
+ LOCKDATA(sy);
+ LOCKDATA(emulat3);
+ LOCKDATA(ox);
+ LOCKDATA(oy);
+ LOCKFUNC(mouse);
+ LOCKFUNC(mouse_wrapper);
+
+ /* grab a locked stack */
+ if ((mouse_stack=pc_malloc(MOUSE_STACK_SIZE))==NULL) {
+ return 0;
+ }
+
+ /* try to hook a call-back */
+ __asm__("\n\
+ pushl %%ds \n\
+ pushl %%es \n\
+ movw $0x0303, %%ax \n\
+ pushl %%ds \n\
+ pushl %%cs \n\
+ popl %%ds \n\
+ popl %%es \n\
+ int $0x31 \n\
+ popl %%es \n\
+ popl %%ds \n\
+ jc 0f \n\
+ shll $16, %%ecx \n\
+ movw %%dx, %%cx \n\
+ movl %%ecx, %0 \n\
+ 0: \n\
+ ":"=g"(mouse_callback)
+ :"S" (mouse_wrapper), "D"(&mouse_regs)
+ :"%eax", "%ecx", "%edx");
+ if (!mouse_callback) {
+ free(mouse_stack);
+ return 0;
+ }
+
+ /* adjust stack */
+ mouse_stack = (void *)((unsigned long)mouse_stack + MOUSE_STACK_SIZE);
+
+ /* install the handler */
+ mouse_regs.x.ax = 0x000c;
+ mouse_regs.x.cx = 0x007f;
+ mouse_regs.x.dx = mouse_callback&0xffff;
+ mouse_regs.x.es = mouse_callback>>16;
+ __dpmi_int(0x33, &mouse_regs);
+
+ emulat3 = buttons<3;
+ pc_atexit(pc_remove_mouse);
+ return buttons;
+}
+
+MFUNC pc_install_mouse_handler (MFUNC handler)
+{
+ MFUNC old;
+
+ if (!mouse_callback && !pc_install_mouse()) {
+ return NULL;
+ }
+
+ old = mouse_func;
+ mouse_func = handler;
+ return old;
+}
+
+void pc_mouse_area (int x1, int y1, int x2, int y2)
+{
+ minx = x1;
+ maxx = x2;
+ miny = y1;
+ maxy = y2;
+}
+
+void pc_mouse_speed (int xspeed, int yspeed)
+{
+ DISABLE();
+
+ sx = MAX(1, xspeed);
+ sy = MAX(1, yspeed);
+
+ ENABLE();
+}
+
+void pc_show_mouse (void)
+{
+ /* not implemented */
+}
+void pc_scare_mouse (void)
+{
+ /* not implemented */
+}
+void pc_unscare_mouse (void)
+{
+ /* not implemented */
+}
+
+__asm__("\n\
+ .balign 4 \n\
+ .global _mouse_wrapper \n\
+_mouse_wrapper: \n\
+ cld \n\
+ lodsl \n\
+ movl %eax, %es:42(%edi) \n\
+ addw $4, %es:46(%edi) \n\
+ pushl %es \n\
+ movl %ss, %ebx \n\
+ movl %esp, %esi \n\
+ movl %cs:___djgpp_ds_alias, %ss \n\
+ movl %cs:_mouse_stack, %esp \n\
+ pushl %ss \n\
+ pushl %ss \n\
+ popl %es \n\
+ popl %ds \n\
+ movl ___djgpp_dos_sel, %fs \n\
+ pushl %fs \n\
+ popl %gs \n\
+ pushl %edi \n\
+ call _mouse \n\
+ popl %edi \n\
+ movl %ebx, %ss \n\
+ movl %esi, %esp \n\
+ popl %es \n\
+ iret \n\
+ \n\
+ .balign 4 \n\
+ .global _mouse_wrapper_end \n\
+_mouse_wrapper_end:");
diff --git a/src/glut/dos/PC_HW/pc_timer.c b/src/glut/dos/PC_HW/pc_timer.c
new file mode 100644
index 0000000000..a8c58f6741
--- /dev/null
+++ b/src/glut/dos/PC_HW/pc_timer.c
@@ -0,0 +1,158 @@
+/*
+ * PC/HW routine collection v0.1 for DOS/DJGPP
+ *
+ * Copyright (C) 2002 - Borca Daniel
+ * Email : dborca@yahoo.com
+ * Web : http://www.geocities.com/dborca
+ */
+
+
+#include <pc.h>
+
+#include "pc_hw.h"
+
+#define TIMER_IRQ 0
+
+#define MAX_TIMERS 8
+
+#define PIT_FREQ 0x1234DD
+
+#define unvolatile(__v, __t) __extension__ ({union { volatile __t __cp; __t __p; } __q; __q.__cp = __v; __q.__p;})
+
+static int timer_installed;
+
+typedef struct {
+ volatile unsigned int counter, clock_ticks, freq;
+ volatile PFUNC func;
+ volatile void *parm;
+} TIMER;
+
+TIMER timer_main, timer_func[MAX_TIMERS];
+
+static int timer ()
+{
+ int i;
+
+ for (i=0;i<MAX_TIMERS;i++) {
+ TIMER *t = &timer_func[i];
+ if (t->func) {
+ t->clock_ticks += t->counter;
+ if (t->clock_ticks>=timer_main.counter) {
+ t->clock_ticks -= timer_main.counter;
+ t->func(unvolatile(t->parm, void *));
+ }
+ }
+ }
+
+ timer_main.clock_ticks += timer_main.counter;
+ if (timer_main.clock_ticks>=0x10000) {
+ timer_main.clock_ticks -= 0x10000;
+ return 1;
+ } else {
+ outportb(0x20, 0x20);
+ return 0;
+ }
+} ENDOFUNC(timer)
+
+void pc_remove_timer (void)
+{
+ if (timer_installed) {
+ timer_installed = FALSE;
+ pc_clexit(pc_remove_timer);
+
+ DISABLE();
+ outportb(0x43, 0x34);
+ outportb(0x40, 0);
+ outportb(0x40, 0);
+ ENABLE();
+
+ pc_remove_irq(TIMER_IRQ);
+ }
+}
+
+static int install_timer (void)
+{
+ if (timer_installed||pc_install_irq(TIMER_IRQ, timer)) {
+ return -1;
+ } else {
+ LOCKDATA(timer_func);
+ LOCKDATA(timer_main);
+ LOCKFUNC(timer);
+
+ timer_main.counter = 0x10000;
+
+ DISABLE();
+ outportb(0x43, 0x34);
+ outportb(0x40, 0);
+ outportb(0x40, 0);
+ timer_main.clock_ticks = 0;
+ ENABLE();
+
+ pc_atexit(pc_remove_timer);
+ timer_installed = TRUE;
+ return 0;
+ }
+}
+
+static TIMER *find_slot (PFUNC func)
+{
+ int i;
+
+ for (i=0;i<MAX_TIMERS;i++) {
+ if (timer_func[i].func==func) {
+ return &timer_func[i];
+ }
+ }
+ for (i=0;i<MAX_TIMERS;i++) {
+ if (!timer_func[i].func) {
+ return &timer_func[i];
+ }
+ }
+
+ return NULL;
+}
+
+int pc_install_int (PFUNC func, void *parm, unsigned int freq)
+{
+ int i;
+ TIMER *t;
+
+ if (!timer_installed) {
+ if (install_timer()) {
+ return -1;
+ }
+ }
+
+ if ((t=find_slot(func))!=NULL) {
+ unsigned int new_counter = PIT_FREQ / freq;
+
+ DISABLE();
+
+ t->func = func;
+ t->parm = parm;
+ t->freq = freq;
+ t->clock_ticks = 0;
+
+ if (new_counter < timer_main.counter) {
+ for (i=0;i<MAX_TIMERS;i++) {
+ if (timer_func[i].func) {
+ timer_func[i].counter = new_counter * timer_func[i].freq / freq;
+ }
+ }
+ outportb(0x43, 0x34);
+ outportb(0x40, (unsigned char)new_counter);
+ outportb(0x40, (unsigned char)(new_counter>>8));
+ timer_main.clock_ticks = 0;
+ timer_main.counter = new_counter;
+ timer_main.freq = freq;
+ } else {
+ t->counter = PIT_FREQ * freq / (timer_main.freq * timer_main.freq);
+ }
+
+ ENABLE();
+
+ return 0;
+ }
+
+ return -1;
+}