diff options
author | Brian Paul <[email protected]> | 2003-06-16 14:32:44 +0000 |
---|---|---|
committer | Brian Paul <[email protected]> | 2003-06-16 14:32:44 +0000 |
commit | 642699a19f1c07336a6fadacd6d5a9028f5d346f (patch) | |
tree | 6664c6c8937aba9a8d96a8a6a7c0ddc74151e04e /src/glut | |
parent | 710207c46f523ca3607c522ffa45a7c07a3354b4 (diff) |
DOS updates for new tree (Daniel Borca)
Diffstat (limited to 'src/glut')
-rw-r--r-- | src/glut/dos/Makefile.DJ | 270 | ||||
-rw-r--r-- | src/glut/dos/PC_HW/pc_hw.c | 290 | ||||
-rw-r--r-- | src/glut/dos/PC_HW/pc_hw.h | 450 | ||||
-rw-r--r-- | src/glut/dos/PC_HW/pc_irq.S | 364 | ||||
-rw-r--r-- | src/glut/dos/PC_HW/pc_keyb.c | 1084 | ||||
-rw-r--r-- | src/glut/dos/PC_HW/pc_mouse.c | 556 | ||||
-rw-r--r-- | src/glut/dos/PC_HW/pc_timer.c | 316 | ||||
-rw-r--r-- | src/glut/dos/callback.c | 328 | ||||
-rw-r--r-- | src/glut/dos/color.c | 118 | ||||
-rw-r--r-- | src/glut/dos/extens.c | 126 | ||||
-rw-r--r-- | src/glut/dos/glutint.h | 300 | ||||
-rw-r--r-- | src/glut/dos/init.c | 508 | ||||
-rw-r--r-- | src/glut/dos/menu.c | 232 | ||||
-rw-r--r-- | src/glut/dos/mouse.c | 120 | ||||
-rw-r--r-- | src/glut/dos/overlay.c | 182 | ||||
-rw-r--r-- | src/glut/dos/state.c | 284 | ||||
-rw-r--r-- | src/glut/dos/window.c | 520 |
17 files changed, 3025 insertions, 3023 deletions
diff --git a/src/glut/dos/Makefile.DJ b/src/glut/dos/Makefile.DJ index 52c347cda34..c870d23d444 100644 --- a/src/glut/dos/Makefile.DJ +++ b/src/glut/dos/Makefile.DJ @@ -1,134 +1,136 @@ -# Mesa 3-D graphics library
-# Version: 4.0
-#
-# Copyright (C) 1999 Brian Paul All Rights Reserved.
-#
-# Permission is hereby granted, free of charge, to any person obtaining a
-# copy of this software and associated documentation files (the "Software"),
-# to deal in the Software without restriction, including without limitation
-# the rights to use, copy, modify, merge, publish, distribute, sublicense,
-# and/or sell copies of the Software, and to permit persons to whom the
-# Software is furnished to do so, subject to the following conditions:
-#
-# The above copyright notice and this permission notice shall be included
-# in all copies or substantial portions of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
-# BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
-# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-# DOS/DJGPP glut makefile v1.3 for Mesa
-#
-# Copyright (C) 2002 - Borca Daniel
-# Email : [email protected]
-# Web : http://www.geocities.com/dborca
-
-
-#
-# Available options:
-#
-# Environment variables:
-# CFLAGS
-#
-# MKGLUT absolute path to original GLUT.
-# default = $(TOP)/src-glut
-#
-# Targets:
-# all: build GLUT
-# clean: remove object files
-#
-
-
-
-.PHONY: all clean
-
-TOP = ..
-GLIDE ?= $(TOP)/include/glide3
-MKGLUT ?= $(TOP)/src-glut
-LIBDIR = $(TOP)/lib
-GLUT_LIB = libglut.a
-GLUT_DXE = glut.dxe
-GLUT_IMP = libiglut.a
-
-CC = gcc
-CFLAGS += -I- -I$(TOP)/include -I. -I$(MKGLUT) -IPC_HW
-
-AR = ar
-ARFLAGS = rus
-
-HAVEDXE3 = $(wildcard $(DJDIR)/bin/dxe3gen.exe)
-
-ifeq ($(wildcard $(addsuffix /rm.exe,$(subst ;, ,$(PATH)))),)
-UNLINK = del $(subst /,\,$(1))
-else
-UNLINK = $(RM) $(1)
-endif
-
-CORE_SOURCES = \
- callback.c \
- color.c \
- extens.c \
- init.c \
- menu.c \
- mouse.c \
- overlay.c \
- state.c \
- window.c
-
-PC_HW_SOURCES = \
- PC_HW/pc_hw.c \
- PC_HW/pc_keyb.c \
- PC_HW/pc_mouse.c \
- PC_HW/pc_timer.c \
- PC_HW/pc_irq.S
-
-MKGLUT_SOURCES = \
- $(MKGLUT)/glut_bitmap.c \
- $(MKGLUT)/glut_bwidth.c \
- $(MKGLUT)/glut_stroke.c \
- $(MKGLUT)/glut_swidth.c \
- $(MKGLUT)/glut_shapes.c \
- $(MKGLUT)/glut_teapot.c \
- $(MKGLUT)/glut_8x13.c \
- $(MKGLUT)/glut_9x15.c \
- $(MKGLUT)/glut_hel10.c \
- $(MKGLUT)/glut_hel12.c \
- $(MKGLUT)/glut_hel18.c \
- $(MKGLUT)/glut_tr10.c \
- $(MKGLUT)/glut_tr24.c \
- $(MKGLUT)/glut_roman.c \
- $(MKGLUT)/glut_mroman.c \
- $(MKGLUT)/glut_util.c
-
-SOURCES = $(CORE_SOURCES) $(PC_HW_SOURCES) $(MKGLUT_SOURCES)
-
-OBJECTS = $(addsuffix .o,$(basename $(SOURCES)))
-
-.c.o:
- $(CC) -o $@ $(CFLAGS) -c $<
-.S.o:
- $(CC) -o $@ $(CFLAGS) -c $<
-.s.o:
- $(CC) -o $@ $(CFLAGS) -x assembler-with-cpp -c $<
-
-all: $(LIBDIR)/$(GLUT_LIB) $(LIBDIR)/$(GLUT_DXE) $(LIBDIR)/$(GLUT_IMP)
-
-$(LIBDIR)/$(GLUT_LIB): $(OBJECTS)
- $(AR) $(ARFLAGS) $(LIBDIR)/$(GLUT_LIB) $(OBJECTS)
-
-$(LIBDIR)/$(GLUT_DXE) $(LIBDIR)/$(GLUT_IMP): $(OBJECTS)
-ifeq ($(HAVEDXE3),)
- $(warning Missing DXE3 package... Skipping $(GLUT_DXE))
-else
- -dxe3gen -o $(LIBDIR)/$(GLUT_DXE) -I $(LIBDIR)/$(GLUT_IMP) -D "MesaGLUT DJGPP" -E _glut -P gl.dxe -P glu.dxe -U $(OBJECTS)
-endif
-
-clean:
- -$(call UNLINK,*.o)
- -$(call UNLINK,PC_HW/*.o)
- -$(call UNLINK,$(MKGLUT)/*.o)
-
--include depend
+# Mesa 3-D graphics library +# Version: 4.0 +# +# Copyright (C) 1999 Brian Paul All Rights Reserved. +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +# DOS/DJGPP glut makefile v1.4 for Mesa +# +# Copyright (C) 2002 - Borca Daniel +# Email : [email protected] +# Web : http://www.geocities.com/dborca + + +# +# Available options: +# +# Environment variables: +# CFLAGS +# +# MKGLUT absolute path to original GLUT. +# default = $(TOP)/src-glut +# +# Targets: +# all: build GLUT +# clean: remove object files +# + + + +.PHONY: all clean + +TOP = ../../.. +GLIDE ?= $(TOP)/include/glide3 +MKGLUT ?= $(TOP)/src/glut/glx +LIBDIR = $(TOP)/lib +GLUT_LIB = libglut.a +GLUT_DXE = glut.dxe +GLUT_IMP = libiglut.a + +export LD_LIBRARY_PATH := $(LD_LIBRARY_PATH);$(LIBDIR) + +CC = gcc +CFLAGS += -I- -I$(TOP)/include -I. -I$(MKGLUT) -IPC_HW + +AR = ar +ARFLAGS = rus + +HAVEDXE3 = $(wildcard $(DJDIR)/bin/dxe3gen.exe) + +ifeq ($(wildcard $(addsuffix /rm.exe,$(subst ;, ,$(PATH)))),) +UNLINK = del $(subst /,\,$(1)) +else +UNLINK = $(RM) $(1) +endif + +CORE_SOURCES = \ + callback.c \ + color.c \ + extens.c \ + init.c \ + menu.c \ + mouse.c \ + overlay.c \ + state.c \ + window.c + +PC_HW_SOURCES = \ + PC_HW/pc_hw.c \ + PC_HW/pc_keyb.c \ + PC_HW/pc_mouse.c \ + PC_HW/pc_timer.c \ + PC_HW/pc_irq.S + +MKGLUT_SOURCES = \ + $(MKGLUT)/glut_bitmap.c \ + $(MKGLUT)/glut_bwidth.c \ + $(MKGLUT)/glut_stroke.c \ + $(MKGLUT)/glut_swidth.c \ + $(MKGLUT)/glut_shapes.c \ + $(MKGLUT)/glut_teapot.c \ + $(MKGLUT)/glut_8x13.c \ + $(MKGLUT)/glut_9x15.c \ + $(MKGLUT)/glut_hel10.c \ + $(MKGLUT)/glut_hel12.c \ + $(MKGLUT)/glut_hel18.c \ + $(MKGLUT)/glut_tr10.c \ + $(MKGLUT)/glut_tr24.c \ + $(MKGLUT)/glut_roman.c \ + $(MKGLUT)/glut_mroman.c \ + $(MKGLUT)/glut_util.c + +SOURCES = $(CORE_SOURCES) $(PC_HW_SOURCES) $(MKGLUT_SOURCES) + +OBJECTS = $(addsuffix .o,$(basename $(SOURCES))) + +.c.o: + $(CC) -o $@ $(CFLAGS) -c $< +.S.o: + $(CC) -o $@ $(CFLAGS) -c $< +.s.o: + $(CC) -o $@ $(CFLAGS) -x assembler-with-cpp -c $< + +all: $(LIBDIR)/$(GLUT_LIB) $(LIBDIR)/$(GLUT_DXE) $(LIBDIR)/$(GLUT_IMP) + +$(LIBDIR)/$(GLUT_LIB): $(OBJECTS) + $(AR) $(ARFLAGS) $(LIBDIR)/$(GLUT_LIB) $(OBJECTS) + +$(LIBDIR)/$(GLUT_DXE) $(LIBDIR)/$(GLUT_IMP): $(OBJECTS) +ifeq ($(HAVEDXE3),) + $(warning Missing DXE3 package... Skipping $(GLUT_DXE)) +else + -dxe3gen -o $(LIBDIR)/$(GLUT_DXE) -Y $(LIBDIR)/$(GLUT_IMP) -D "MesaGLUT DJGPP" -E _glut -P gl.dxe -P glu.dxe -U $(OBJECTS) +endif + +clean: + -$(call UNLINK,*.o) + -$(call UNLINK,PC_HW/*.o) + -$(call UNLINK,$(MKGLUT)/*.o) + +-include depend diff --git a/src/glut/dos/PC_HW/pc_hw.c b/src/glut/dos/PC_HW/pc_hw.c index f08286d4c49..b1fd84bdb67 100644 --- a/src/glut/dos/PC_HW/pc_hw.c +++ b/src/glut/dos/PC_HW/pc_hw.c @@ -1,145 +1,145 @@ -/*
- * PC/HW routine collection v1.3 for DOS/DJGPP
- *
- * Copyright (C) 2002 - Borca Daniel
- * Email : [email protected]
- * 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 <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 outname[L_tmpnam];
-static int h_out, h_outbak;
-static char errname[L_tmpnam];
-static int h_err, h_errbak;
-
-int pc_open_stdout (void)
-{
- tmpnam(outname);
-
- if ((h_out=open(outname, O_WRONLY | O_CREAT | O_TEXT | O_TRUNC, S_IREAD | S_IWRITE)) > 0) {
- h_outbak = dup(STDOUT_FILENO);
- fflush(stdout);
- dup2(h_out, STDOUT_FILENO);
- }
-
- return h_out;
-}
-
-void pc_close_stdout (void)
-{
- FILE *f;
- char *line = alloca(512);
-
- if (h_out > 0) {
- dup2(h_outbak, STDOUT_FILENO);
- close(h_out);
- close(h_outbak);
-
- f = fopen(outname, "rt");
- while (fgets(line, 512, f)) {
- fputs(line, stdout);
- }
- fclose(f);
-
- remove(outname);
- }
-}
-
-int pc_open_stderr (void)
-{
- tmpnam(errname);
-
- if ((h_err=open(errname, O_WRONLY | O_CREAT | O_TEXT | O_TRUNC, S_IREAD | S_IWRITE)) > 0) {
- h_errbak = dup(STDERR_FILENO);
- fflush(stderr);
- dup2(h_err, STDERR_FILENO);
- }
-
- return h_err;
-}
-
-void pc_close_stderr (void)
-{
- FILE *f;
- char *line = alloca(512);
-
- if (h_err > 0) {
- dup2(h_errbak, STDERR_FILENO);
- close(h_err);
- close(h_errbak);
-
- f = fopen(errname, "rt");
- while (fgets(line, 512, f)) {
- fputs(line, stderr);
- }
- fclose(f);
-
- remove(errname);
- }
-}
+/* + * PC/HW routine collection v1.3 for DOS/DJGPP + * + * Copyright (C) 2002 - Borca Daniel + * Email : [email protected] + * 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 <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 outname[L_tmpnam]; +static int h_out, h_outbak; +static char errname[L_tmpnam]; +static int h_err, h_errbak; + +int pc_open_stdout (void) +{ + tmpnam(outname); + + if ((h_out=open(outname, O_WRONLY | O_CREAT | O_TEXT | O_TRUNC, S_IREAD | S_IWRITE)) > 0) { + h_outbak = dup(STDOUT_FILENO); + fflush(stdout); + dup2(h_out, STDOUT_FILENO); + } + + return h_out; +} + +void pc_close_stdout (void) +{ + FILE *f; + char *line = alloca(512); + + if (h_out > 0) { + dup2(h_outbak, STDOUT_FILENO); + close(h_out); + close(h_outbak); + + f = fopen(outname, "rt"); + while (fgets(line, 512, f)) { + fputs(line, stdout); + } + fclose(f); + + remove(outname); + } +} + +int pc_open_stderr (void) +{ + tmpnam(errname); + + if ((h_err=open(errname, O_WRONLY | O_CREAT | O_TEXT | O_TRUNC, S_IREAD | S_IWRITE)) > 0) { + h_errbak = dup(STDERR_FILENO); + fflush(stderr); + dup2(h_err, STDERR_FILENO); + } + + return h_err; +} + +void pc_close_stderr (void) +{ + FILE *f; + char *line = alloca(512); + + if (h_err > 0) { + dup2(h_errbak, STDERR_FILENO); + close(h_err); + close(h_errbak); + + f = fopen(errname, "rt"); + while (fgets(line, 512, f)) { + fputs(line, stderr); + } + fclose(f); + + remove(errname); + } +} diff --git a/src/glut/dos/PC_HW/pc_hw.h b/src/glut/dos/PC_HW/pc_hw.h index c029005b53c..26bb8ba17df 100644 --- a/src/glut/dos/PC_HW/pc_hw.h +++ b/src/glut/dos/PC_HW/pc_hw.h @@ -1,225 +1,225 @@ -/*
- * PC/HW routine collection v1.3 for DOS/DJGPP
- *
- * Copyright (C) 2002 - Borca Daniel
- * Email : [email protected]
- * 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 z, 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))
-#define LOCKBUFF(x, l) _go32_dpmi_lock_data((void *)x, l)
-
-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
-
-int pc_install_keyb (void);
-void pc_remove_keyb (void);
-int pc_keypressed (void);
-int pc_readkey (void);
-int pc_keydown (int code);
-int pc_keyshifts (void);
-
-/*
- * timer
- */
-int pc_install_int (PFUNC func, void *parm, unsigned int freq);
-void pc_remove_timer (void);
-
-/*
- * mouse
- */
-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);
-int pc_query_mouse (int *x, int *y, int *z);
-void pc_warp_mouse (int x, int y);
-
-/*
- * standard redirection
- */
-int pc_open_stdout (void);
-int pc_open_stderr (void);
-void pc_close_stdout (void);
-void pc_close_stderr (void);
-
-#endif
+/* + * PC/HW routine collection v1.3 for DOS/DJGPP + * + * Copyright (C) 2002 - Borca Daniel + * Email : [email protected] + * 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 z, 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)) +#define LOCKBUFF(x, l) _go32_dpmi_lock_data((void *)x, l) + +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 + +int pc_install_keyb (void); +void pc_remove_keyb (void); +int pc_keypressed (void); +int pc_readkey (void); +int pc_keydown (int code); +int pc_keyshifts (void); + +/* + * timer + */ +int pc_install_int (PFUNC func, void *parm, unsigned int freq); +void pc_remove_timer (void); + +/* + * mouse + */ +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); +int pc_query_mouse (int *x, int *y, int *z); +void pc_warp_mouse (int x, int y); + +/* + * standard redirection + */ +int pc_open_stdout (void); +int 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 index 7f0b747d342..6d99bd805ee 100644 --- a/src/glut/dos/PC_HW/pc_irq.S +++ b/src/glut/dos/PC_HW/pc_irq.S @@ -1,182 +1,182 @@ -/*
- * PC/HW routine collection v1.3 for DOS/DJGPP
- *
- * Copyright (C) 2002 - Borca Daniel
- * Email : [email protected]
- * 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 ___djgpp_ds_alias, %eax
- movl %eax, IRQ_STACK+4(%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 ; \
- movl %ss, %ebx ; \
- movl %esp, %esi ; \
- lss %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 ; \
- movl %ebx, %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, 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);
+/* + * PC/HW routine collection v1.3 for DOS/DJGPP + * + * Copyright (C) 2002 - Borca Daniel + * Email : [email protected] + * 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 ___djgpp_ds_alias, %eax + movl %eax, IRQ_STACK+4(%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 ; \ + movl %ss, %ebx ; \ + movl %esp, %esi ; \ + lss %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 ; \ + movl %ebx, %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, 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 index ec509c2ace7..d3c87bc5bde 100644 --- a/src/glut/dos/PC_HW/pc_keyb.c +++ b/src/glut/dos/PC_HW/pc_keyb.c @@ -1,542 +1,542 @@ -/*
- * PC/HW routine collection v1.3 for DOS/DJGPP
- *
- * Copyright (C) 2002 - Borca Daniel
- * Email : [email protected]
- * 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;
-static 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 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)) {
- /* Hack alert:
- only SIGINT (but not Ctrl-Break)
- calls the destructors and will safely clean up
- */
- __asm("\n\
- movb $0x79, %%al \n\
- call ___djgpp_hw_exception \n\
- ":::"%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory");
- }
-
- __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");
- return 0;
-} ENDOFUNC(keyboard)
-
-
-int pc_keypressed (void)
-{
- return (key_buffer.start!=key_buffer.end);
-}
-
-int pc_readkey (void)
-{
- if (keyboard_installed) {
- int key;
-
- while (key_buffer.start==key_buffer.end) {
- __dpmi_yield();
- }
-
- 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;
- }
-}
-
-int pc_keydown (int code)
-{
- return pc_key[code];
-}
-
-int pc_keyshifts (void)
-{
- return key_shifts;
-}
-
-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;
- }
-}
+/* + * PC/HW routine collection v1.3 for DOS/DJGPP + * + * Copyright (C) 2002 - Borca Daniel + * Email : [email protected] + * 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; +static 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 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)) { + /* Hack alert: + only SIGINT (but not Ctrl-Break) + calls the destructors and will safely clean up + */ + __asm("\n\ + movb $0x79, %%al \n\ + call ___djgpp_hw_exception \n\ + ":::"%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory"); + } + + __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"); + return 0; +} ENDOFUNC(keyboard) + + +int pc_keypressed (void) +{ + return (key_buffer.start!=key_buffer.end); +} + +int pc_readkey (void) +{ + if (keyboard_installed) { + int key; + + while (key_buffer.start==key_buffer.end) { + __dpmi_yield(); + } + + 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; + } +} + +int pc_keydown (int code) +{ + return pc_key[code]; +} + +int pc_keyshifts (void) +{ + return key_shifts; +} + +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 index cf8fb668ba0..fc0902ce81b 100644 --- a/src/glut/dos/PC_HW/pc_mouse.c +++ b/src/glut/dos/PC_HW/pc_mouse.c @@ -1,278 +1,278 @@ -/*
- * PC/HW routine collection v1.3 for DOS/DJGPP
- *
- * Copyright (C) 2002 - Borca Daniel
- * Email : [email protected]
- * Web : http://www.geocities.com/dborca
- */
-
-
-#include <dpmi.h>
-#include <sys/exceptn.h>
-#include <sys/segments.h>
-
-#include "pc_hw.h"
-
-
-
-#define PC_CUTE_WHEEL 1 /* CuteMouse WheelAPI */
-
-#define MOUSE_STACK_SIZE 16384
-
-#define CLEAR_MICKEYS() \
- do { \
- __asm __volatile ("movw $0xb, %%ax; int $0x33":::"%eax", "%ecx", "%edx"); \
- ox = oy = 0; \
- } while (0)
-
-extern void mouse_wrap (void);
-extern int mouse_wrap_end[];
-
-static MFUNC mouse_func;
-static long mouse_callback;
-static __dpmi_regs mouse_regs;
-
-static volatile struct {
- volatile int x, y, z, b;
-} pc_mouse;
-
-static int minx = 0;
-static int maxx = 319;
-static int miny = 0;
-static int maxy = 199;
-static int minz = 0;
-static int maxz = 255;
-
-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;
-#if PC_CUTE_WHEEL
- int dz = (signed char)r->h.bh;
-#endif
- ox = nx;
- oy = ny;
-
- pc_mouse.b = r->h.bl;
- pc_mouse.x = MID(minx, pc_mouse.x + dx, maxx);
- pc_mouse.y = MID(miny, pc_mouse.y + dy, maxy);
-#if PC_CUTE_WHEEL
- pc_mouse.z = MID(minz, pc_mouse.z + dz, maxz);
-#endif
-
- 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.z, 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 *)(mouse_wrap_end[0] - 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_callback);
- LOCKDATA(mouse_regs);
- LOCKDATA(pc_mouse);
- LOCKDATA(minx);
- LOCKDATA(maxx);
- LOCKDATA(miny);
- LOCKDATA(maxy);
- LOCKDATA(minz);
- LOCKDATA(maxz);
- LOCKDATA(sx);
- LOCKDATA(sy);
- LOCKDATA(emulat3);
- LOCKDATA(ox);
- LOCKDATA(oy);
- LOCKFUNC(mouse);
- LOCKFUNC(mouse_wrap);
-
- mouse_wrap_end[1] = __djgpp_ds_alias;
- /* grab a locked stack */
- if ((mouse_wrap_end[0] = (int)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_wrap), "D"(&mouse_regs)
- :"%eax", "%ecx", "%edx");
- if (!mouse_callback) {
- free((void *)mouse_wrap_end[0]);
- return 0;
- }
-
- /* adjust stack */
- mouse_wrap_end[0] += MOUSE_STACK_SIZE;
-
- /* install the handler */
- mouse_regs.x.ax = 0x000c;
-#if PC_CUTE_WHEEL
- mouse_regs.x.cx = 0x7f | 0x80;
-#else
- mouse_regs.x.cx = 0x7f;
-#endif
- mouse_regs.x.dx = mouse_callback&0xffff;
- mouse_regs.x.es = mouse_callback>>16;
- __dpmi_int(0x33, &mouse_regs);
-
- CLEAR_MICKEYS();
-
- 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();
-}
-
-int pc_query_mouse (int *x, int *y, int *z)
-{
- *x = pc_mouse.x;
- *y = pc_mouse.y;
- *z = pc_mouse.z;
- return pc_mouse.b;
-}
-
-void pc_warp_mouse (int x, int y)
-{
- CLEAR_MICKEYS();
-
- pc_mouse.x = MID(minx, x, maxx);
- pc_mouse.y = MID(miny, y, maxy);
-
- if (mouse_func) {
- mouse_func(pc_mouse.x, pc_mouse.y, pc_mouse.z, pc_mouse.b);
- }
-}
-
-/* Hack alert:
- * `mouse_wrap_end' actually holds the
- * address of stack in a safe data selector.
- */
-__asm("\n\
- .text \n\
- .p2align 5,,31 \n\
- .global _mouse_wrap \n\
-_mouse_wrap: \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\
- lss %cs:_mouse_wrap_end, %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\
- .global _mouse_wrap_end \n\
-_mouse_wrap_end:.long 0, 0");
+/* + * PC/HW routine collection v1.3 for DOS/DJGPP + * + * Copyright (C) 2002 - Borca Daniel + * Email : [email protected] + * Web : http://www.geocities.com/dborca + */ + + +#include <dpmi.h> +#include <sys/exceptn.h> +#include <sys/segments.h> + +#include "pc_hw.h" + + + +#define PC_CUTE_WHEEL 1 /* CuteMouse WheelAPI */ + +#define MOUSE_STACK_SIZE 16384 + +#define CLEAR_MICKEYS() \ + do { \ + __asm __volatile ("movw $0xb, %%ax; int $0x33":::"%eax", "%ecx", "%edx"); \ + ox = oy = 0; \ + } while (0) + +extern void mouse_wrap (void); +extern int mouse_wrap_end[]; + +static MFUNC mouse_func; +static long mouse_callback; +static __dpmi_regs mouse_regs; + +static volatile struct { + volatile int x, y, z, b; +} pc_mouse; + +static int minx = 0; +static int maxx = 319; +static int miny = 0; +static int maxy = 199; +static int minz = 0; +static int maxz = 255; + +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; +#if PC_CUTE_WHEEL + int dz = (signed char)r->h.bh; +#endif + ox = nx; + oy = ny; + + pc_mouse.b = r->h.bl; + pc_mouse.x = MID(minx, pc_mouse.x + dx, maxx); + pc_mouse.y = MID(miny, pc_mouse.y + dy, maxy); +#if PC_CUTE_WHEEL + pc_mouse.z = MID(minz, pc_mouse.z + dz, maxz); +#endif + + 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.z, 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 *)(mouse_wrap_end[0] - 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_callback); + LOCKDATA(mouse_regs); + LOCKDATA(pc_mouse); + LOCKDATA(minx); + LOCKDATA(maxx); + LOCKDATA(miny); + LOCKDATA(maxy); + LOCKDATA(minz); + LOCKDATA(maxz); + LOCKDATA(sx); + LOCKDATA(sy); + LOCKDATA(emulat3); + LOCKDATA(ox); + LOCKDATA(oy); + LOCKFUNC(mouse); + LOCKFUNC(mouse_wrap); + + mouse_wrap_end[1] = __djgpp_ds_alias; + /* grab a locked stack */ + if ((mouse_wrap_end[0] = (int)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_wrap), "D"(&mouse_regs) + :"%eax", "%ecx", "%edx"); + if (!mouse_callback) { + free((void *)mouse_wrap_end[0]); + return 0; + } + + /* adjust stack */ + mouse_wrap_end[0] += MOUSE_STACK_SIZE; + + /* install the handler */ + mouse_regs.x.ax = 0x000c; +#if PC_CUTE_WHEEL + mouse_regs.x.cx = 0x7f | 0x80; +#else + mouse_regs.x.cx = 0x7f; +#endif + mouse_regs.x.dx = mouse_callback&0xffff; + mouse_regs.x.es = mouse_callback>>16; + __dpmi_int(0x33, &mouse_regs); + + CLEAR_MICKEYS(); + + 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(); +} + +int pc_query_mouse (int *x, int *y, int *z) +{ + *x = pc_mouse.x; + *y = pc_mouse.y; + *z = pc_mouse.z; + return pc_mouse.b; +} + +void pc_warp_mouse (int x, int y) +{ + CLEAR_MICKEYS(); + + pc_mouse.x = MID(minx, x, maxx); + pc_mouse.y = MID(miny, y, maxy); + + if (mouse_func) { + mouse_func(pc_mouse.x, pc_mouse.y, pc_mouse.z, pc_mouse.b); + } +} + +/* Hack alert: + * `mouse_wrap_end' actually holds the + * address of stack in a safe data selector. + */ +__asm("\n\ + .text \n\ + .p2align 5,,31 \n\ + .global _mouse_wrap \n\ +_mouse_wrap: \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\ + lss %cs:_mouse_wrap_end, %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\ + .global _mouse_wrap_end \n\ +_mouse_wrap_end:.long 0, 0"); diff --git a/src/glut/dos/PC_HW/pc_timer.c b/src/glut/dos/PC_HW/pc_timer.c index 36c02910a3e..bf39bd0a4c0 100644 --- a/src/glut/dos/PC_HW/pc_timer.c +++ b/src/glut/dos/PC_HW/pc_timer.c @@ -1,158 +1,158 @@ -/*
- * PC/HW routine collection v1.3 for DOS/DJGPP
- *
- * Copyright (C) 2002 - Borca Daniel
- * Email : [email protected]
- * 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;
-
-static 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;
-}
+/* + * PC/HW routine collection v1.3 for DOS/DJGPP + * + * Copyright (C) 2002 - Borca Daniel + * Email : [email protected] + * 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; + +static 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; +} diff --git a/src/glut/dos/callback.c b/src/glut/dos/callback.c index 67e52ee59f0..8ab75e794c5 100644 --- a/src/glut/dos/callback.c +++ b/src/glut/dos/callback.c @@ -1,164 +1,164 @@ -/*
- * Mesa 3-D graphics library
- * Version: 3.4
- * Copyright (C) 1995-1998 Brian Paul
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the Free
- * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-/*
- * DOS/DJGPP glut driver v1.3 for Mesa
- *
- * Copyright (C) 2002 - Borca Daniel
- * Email : [email protected]
- * Web : http://www.geocities.com/dborca
- */
-
-
-#include "glutint.h"
-
-
-
-GLUTidleCB g_idle_func = NULL;
-
-
-
-void APIENTRY glutDisplayFunc (GLUTdisplayCB func)
-{
- g_curwin->display = func;
-}
-
-
-
-void APIENTRY glutReshapeFunc (GLUTreshapeCB func)
-{
- g_curwin->reshape = func;
-}
-
-
-
-void APIENTRY glutKeyboardFunc (GLUTkeyboardCB func)
-{
- g_curwin->keyboard = func;
-}
-
-
-
-void APIENTRY glutMouseFunc (GLUTmouseCB func)
-{
- g_curwin->mouse = func;
-}
-
-
-
-void APIENTRY glutMotionFunc (GLUTmotionCB func)
-{
- g_curwin->motion = func;
-}
-
-
-
-void APIENTRY glutPassiveMotionFunc (GLUTpassiveCB func)
-{
- g_curwin->passive = func;
-}
-
-
-
-void APIENTRY glutEntryFunc (GLUTentryCB func)
-{
- g_curwin->entry = func;
-}
-
-
-
-void APIENTRY glutVisibilityFunc (GLUTvisibilityCB func)
-{
- g_curwin->visibility = func;
-}
-
-
-
-void APIENTRY glutWindowStatusFunc (GLUTwindowStatusCB func)
-{
-}
-
-
-
-void APIENTRY glutIdleFunc (GLUTidleCB func)
-{
- g_idle_func = func;
-}
-
-
-
-void APIENTRY glutTimerFunc (unsigned int millis, GLUTtimerCB func, int value)
-{
-}
-
-
-
-void APIENTRY glutSpecialFunc (GLUTspecialCB func)
-{
- g_curwin->special = func;
-}
-
-
-
-void APIENTRY glutSpaceballMotionFunc (GLUTspaceMotionCB func)
-{
-}
-
-
-
-void APIENTRY glutSpaceballRotateFunc (GLUTspaceRotateCB func)
-{
-}
-
-
-
-void APIENTRY glutSpaceballButtonFunc (GLUTspaceButtonCB func)
-{
-}
-
-
-
-void APIENTRY glutDialsFunc (GLUTdialsCB func)
-{
-}
-
-
-
-void APIENTRY glutButtonBoxFunc (GLUTbuttonBoxCB func)
-{
-}
-
-
-
-void APIENTRY glutTabletMotionFunc (GLUTtabletMotionCB func)
-{
-}
-
-
-
-void APIENTRY glutTabletButtonFunc (GLUTtabletButtonCB func)
-{
-}
-
-
-
-void APIENTRY glutJoystickFunc (GLUTjoystickCB func, int interval)
-{
-}
+/* + * Mesa 3-D graphics library + * Version: 3.4 + * Copyright (C) 1995-1998 Brian Paul + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +/* + * DOS/DJGPP glut driver v1.3 for Mesa + * + * Copyright (C) 2002 - Borca Daniel + * Email : [email protected] + * Web : http://www.geocities.com/dborca + */ + + +#include "glutint.h" + + + +GLUTidleCB g_idle_func = NULL; + + + +void APIENTRY glutDisplayFunc (GLUTdisplayCB func) +{ + g_curwin->display = func; +} + + + +void APIENTRY glutReshapeFunc (GLUTreshapeCB func) +{ + g_curwin->reshape = func; +} + + + +void APIENTRY glutKeyboardFunc (GLUTkeyboardCB func) +{ + g_curwin->keyboard = func; +} + + + +void APIENTRY glutMouseFunc (GLUTmouseCB func) +{ + g_curwin->mouse = func; +} + + + +void APIENTRY glutMotionFunc (GLUTmotionCB func) +{ + g_curwin->motion = func; +} + + + +void APIENTRY glutPassiveMotionFunc (GLUTpassiveCB func) +{ + g_curwin->passive = func; +} + + + +void APIENTRY glutEntryFunc (GLUTentryCB func) +{ + g_curwin->entry = func; +} + + + +void APIENTRY glutVisibilityFunc (GLUTvisibilityCB func) +{ + g_curwin->visibility = func; +} + + + +void APIENTRY glutWindowStatusFunc (GLUTwindowStatusCB func) +{ +} + + + +void APIENTRY glutIdleFunc (GLUTidleCB func) +{ + g_idle_func = func; +} + + + +void APIENTRY glutTimerFunc (unsigned int millis, GLUTtimerCB func, int value) +{ +} + + + +void APIENTRY glutSpecialFunc (GLUTspecialCB func) +{ + g_curwin->special = func; +} + + + +void APIENTRY glutSpaceballMotionFunc (GLUTspaceMotionCB func) +{ +} + + + +void APIENTRY glutSpaceballRotateFunc (GLUTspaceRotateCB func) +{ +} + + + +void APIENTRY glutSpaceballButtonFunc (GLUTspaceButtonCB func) +{ +} + + + +void APIENTRY glutDialsFunc (GLUTdialsCB func) +{ +} + + + +void APIENTRY glutButtonBoxFunc (GLUTbuttonBoxCB func) +{ +} + + + +void APIENTRY glutTabletMotionFunc (GLUTtabletMotionCB func) +{ +} + + + +void APIENTRY glutTabletButtonFunc (GLUTtabletButtonCB func) +{ +} + + + +void APIENTRY glutJoystickFunc (GLUTjoystickCB func, int interval) +{ +} diff --git a/src/glut/dos/color.c b/src/glut/dos/color.c index 490839968ec..cfb2ff926af 100644 --- a/src/glut/dos/color.c +++ b/src/glut/dos/color.c @@ -1,59 +1,59 @@ -/*
- * Mesa 3-D graphics library
- * Version: 3.4
- * Copyright (C) 1995-1998 Brian Paul
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the Free
- * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-/*
- * DOS/DJGPP glut driver v1.3 for Mesa
- *
- * Copyright (C) 2002 - Borca Daniel
- * Email : [email protected]
- * Web : http://www.geocities.com/dborca
- */
-
-
-#include "glutint.h"
-#include "GL/dmesa.h"
-
-
-
-#define CLAMP(i) ((i) > 1.0 ? 1.0 : ((i) < 0.0 ? 0.0 : (i)))
-
-
-
-void APIENTRY glutSetColor (int ndx, GLfloat red, GLfloat green, GLfloat blue)
-{
- if (g_display_mode & GLUT_INDEX) {
- if ((ndx >= 0) && (ndx < (256 - RESERVED_COLORS))) {
- DMesaSetCI(ndx, CLAMP(red), CLAMP(green), CLAMP(blue));
- }
- }
-}
-
-
-
-GLfloat APIENTRY glutGetColor (int ndx, int component)
-{
- return 0.0;
-}
-
-
-
-void APIENTRY glutCopyColormap (int win)
-{
-}
+/* + * Mesa 3-D graphics library + * Version: 3.4 + * Copyright (C) 1995-1998 Brian Paul + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +/* + * DOS/DJGPP glut driver v1.3 for Mesa + * + * Copyright (C) 2002 - Borca Daniel + * Email : [email protected] + * Web : http://www.geocities.com/dborca + */ + + +#include "glutint.h" +#include "GL/dmesa.h" + + + +#define CLAMP(i) ((i) > 1.0 ? 1.0 : ((i) < 0.0 ? 0.0 : (i))) + + + +void APIENTRY glutSetColor (int ndx, GLfloat red, GLfloat green, GLfloat blue) +{ + if (g_display_mode & GLUT_INDEX) { + if ((ndx >= 0) && (ndx < (256 - RESERVED_COLORS))) { + DMesaSetCI(ndx, CLAMP(red), CLAMP(green), CLAMP(blue)); + } + } +} + + + +GLfloat APIENTRY glutGetColor (int ndx, int component) +{ + return 0.0; +} + + + +void APIENTRY glutCopyColormap (int win) +{ +} diff --git a/src/glut/dos/extens.c b/src/glut/dos/extens.c index ca4da058cd0..bc6cfe0f5ff 100644 --- a/src/glut/dos/extens.c +++ b/src/glut/dos/extens.c @@ -1,63 +1,63 @@ -/*
- * Mesa 3-D graphics library
- * Version: 3.4
- * Copyright (C) 1995-1998 Brian Paul
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the Free
- * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-/*
- * DOS/DJGPP glut driver v1.3 for Mesa
- *
- * Copyright (C) 2002 - Borca Daniel
- * Email : [email protected]
- * Web : http://www.geocities.com/dborca
- */
-
-
-#include <string.h>
-
-#include "GL/glut.h"
-
-
-
-int APIENTRY glutExtensionSupported (const char *extension)
-{
- static const GLubyte *extensions = NULL;
- const GLubyte *last, *where;
-
- /* Extension names should not have spaces. */
- if (strchr(extension, ' ') || *extension == '\0') {
- return GL_FALSE;
- }
-
- /* Not my problem if you don't have a valid OpenGL context */
- if (!extensions) {
- extensions = glGetString(GL_EXTENSIONS);
- }
-
- /* Take care of sub-strings etc. */
- for (last = extensions;;) {
- if ((where = (GLubyte *)strstr((const char *)last, extension)) == NULL) {
- return GL_FALSE;
- }
- last = where + strlen(extension);
- if (where == extensions || *(where - 1) == ' ') {
- if (*last == ' ' || *last == '\0') {
- return GL_TRUE;
- }
- }
- }
-}
+/* + * Mesa 3-D graphics library + * Version: 3.4 + * Copyright (C) 1995-1998 Brian Paul + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +/* + * DOS/DJGPP glut driver v1.3 for Mesa + * + * Copyright (C) 2002 - Borca Daniel + * Email : [email protected] + * Web : http://www.geocities.com/dborca + */ + + +#include <string.h> + +#include "GL/glut.h" + + + +int APIENTRY glutExtensionSupported (const char *extension) +{ + static const GLubyte *extensions = NULL; + const GLubyte *last, *where; + + /* Extension names should not have spaces. */ + if (strchr(extension, ' ') || *extension == '\0') { + return GL_FALSE; + } + + /* Not my problem if you don't have a valid OpenGL context */ + if (!extensions) { + extensions = glGetString(GL_EXTENSIONS); + } + + /* Take care of sub-strings etc. */ + for (last = extensions;;) { + if ((where = (GLubyte *)strstr((const char *)last, extension)) == NULL) { + return GL_FALSE; + } + last = where + strlen(extension); + if (where == extensions || *(where - 1) == ' ') { + if (*last == ' ' || *last == '\0') { + return GL_TRUE; + } + } + } +} diff --git a/src/glut/dos/glutint.h b/src/glut/dos/glutint.h index dfc42754df8..e8dffb581be 100644 --- a/src/glut/dos/glutint.h +++ b/src/glut/dos/glutint.h @@ -1,150 +1,150 @@ -/*
- * Mesa 3-D graphics library
- * Version: 4.0
- * Copyright (C) 1995-1998 Brian Paul
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the Free
- * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-/*
- * DOS/DJGPP glut driver v1.3 for Mesa
- *
- * Copyright (C) 2002 - Borca Daniel
- * Email : [email protected]
- * Web : http://www.geocities.com/dborca
- */
-
-
-#ifndef __glutint_h__
-#define __glutint_h__
-
-#include <GL/glut.h>
-
-#include "GL/dmesa.h"
-
-
-
-/* GLUT function types */
-typedef void (GLUTCALLBACK *GLUTdisplayCB) (void);
-typedef void (GLUTCALLBACK *GLUTreshapeCB) (int, int);
-typedef void (GLUTCALLBACK *GLUTkeyboardCB) (unsigned char, int, int);
-typedef void (GLUTCALLBACK *GLUTmouseCB) (int, int, int, int);
-typedef void (GLUTCALLBACK *GLUTmotionCB) (int, int);
-typedef void (GLUTCALLBACK *GLUTpassiveCB) (int, int);
-typedef void (GLUTCALLBACK *GLUTentryCB) (int);
-typedef void (GLUTCALLBACK *GLUTvisibilityCB) (int);
-typedef void (GLUTCALLBACK *GLUTwindowStatusCB) (int);
-typedef void (GLUTCALLBACK *GLUTidleCB) (void);
-typedef void (GLUTCALLBACK *GLUTtimerCB) (int);
-typedef void (GLUTCALLBACK *GLUTmenuStateCB) (int); /* DEPRECATED. */
-typedef void (GLUTCALLBACK *GLUTmenuStatusCB) (int, int, int);
-typedef void (GLUTCALLBACK *GLUTselectCB) (int);
-typedef void (GLUTCALLBACK *GLUTspecialCB) (int, int, int);
-typedef void (GLUTCALLBACK *GLUTspaceMotionCB) (int, int, int);
-typedef void (GLUTCALLBACK *GLUTspaceRotateCB) (int, int, int);
-typedef void (GLUTCALLBACK *GLUTspaceButtonCB) (int, int);
-typedef void (GLUTCALLBACK *GLUTdialsCB) (int, int);
-typedef void (GLUTCALLBACK *GLUTbuttonBoxCB) (int, int);
-typedef void (GLUTCALLBACK *GLUTtabletMotionCB) (int, int);
-typedef void (GLUTCALLBACK *GLUTtabletButtonCB) (int, int, int, int);
-typedef void (GLUTCALLBACK *GLUTjoystickCB) (unsigned int, int, int, int);
-
-typedef struct GLUTwindow {
- int num; /* window id */
-
- DMesaBuffer buffer;
-
- int show_mouse;
-
- /* GLUT settable or visible window state. */
- int xpos;
- int ypos;
- int width; /* window width in pixels */
- int height; /* window height in pixels */
-
- /* Per-window callbacks. */
- GLUTdisplayCB display; /* redraw */
- GLUTreshapeCB reshape; /* resize (width,height) */
- GLUTmouseCB mouse; /* mouse (button,state,x,y) */
- GLUTmotionCB motion; /* motion (x,y) */
- GLUTpassiveCB passive; /* passive motion (x,y) */
- GLUTentryCB entry; /* window entry/exit (state) */
- GLUTkeyboardCB keyboard; /* keyboard (ASCII,x,y) */
- GLUTkeyboardCB keyboardUp; /* keyboard up (ASCII,x,y) */
- GLUTwindowStatusCB windowStatus; /* window status */
- GLUTvisibilityCB visibility; /* visibility */
- GLUTspecialCB special; /* special key */
- GLUTspecialCB specialUp; /* special up key */
- GLUTbuttonBoxCB buttonBox; /* button box */
- GLUTdialsCB dials; /* dials */
- GLUTspaceMotionCB spaceMotion; /* Spaceball motion */
- GLUTspaceRotateCB spaceRotate; /* Spaceball rotate */
- GLUTspaceButtonCB spaceButton; /* Spaceball button */
- GLUTtabletMotionCB tabletMotion; /* tablet motion */
- GLUTtabletButtonCB tabletButton; /* tablet button */
- GLUTjoystickCB joystick; /* joystick */
-} GLUTwindow;
-
-extern GLUTidleCB g_idle_func;
-extern GLUTmenuStatusCB g_menu_status_func;
-
-extern GLboolean g_redisplay;
-
-extern GLuint g_bpp; /* HW: bits per pixel */
-extern GLuint g_refresh; /* HW: vertical refresh rate */
-extern GLuint g_screen_w, g_screen_h; /* HW: physical screen size */
-extern GLint g_driver_caps;
-
-extern GLuint g_fps;
-
-extern GLuint g_display_mode; /* display bits */
-extern int g_init_x, g_init_y; /* initial window position */
-extern GLuint g_init_w, g_init_h; /* initial window size */
-
-extern int g_mouse; /* non-zero if mouse installed */
-extern int g_mouse_x, g_mouse_y; /* mouse coords, relative to current win */
-
-extern GLUTwindow *g_curwin; /* current window */
-
-extern char *__glutProgramName; /* program name */
-
-extern void __glutInitMouse (void);
-
-/* private routines from glut_util.c */
-extern char * __glutStrdup(const char *string);
-extern void __glutWarning(char *format,...);
-extern void __glutFatalError(char *format,...);
-extern void __glutFatalUsage(char *format,...);
-
-
-
-/* hmmm... */
-#include "pc_hw/pc_hw.h"
-
-
-
-#define MAX_WINDOWS 2
-
-#define DEFAULT_WIDTH 300
-#define DEFAULT_HEIGHT 300
-#define DEFAULT_BPP 16
-
-#define DEPTH_SIZE 16
-#define STENCIL_SIZE 8
-#define ACCUM_SIZE 16
-
-#define RESERVED_COLORS 0
-
-#endif /* __glutint_h__ */
+/* + * Mesa 3-D graphics library + * Version: 4.0 + * Copyright (C) 1995-1998 Brian Paul + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +/* + * DOS/DJGPP glut driver v1.3 for Mesa + * + * Copyright (C) 2002 - Borca Daniel + * Email : [email protected] + * Web : http://www.geocities.com/dborca + */ + + +#ifndef __glutint_h__ +#define __glutint_h__ + +#include <GL/glut.h> + +#include "GL/dmesa.h" + + + +/* GLUT function types */ +typedef void (GLUTCALLBACK *GLUTdisplayCB) (void); +typedef void (GLUTCALLBACK *GLUTreshapeCB) (int, int); +typedef void (GLUTCALLBACK *GLUTkeyboardCB) (unsigned char, int, int); +typedef void (GLUTCALLBACK *GLUTmouseCB) (int, int, int, int); +typedef void (GLUTCALLBACK *GLUTmotionCB) (int, int); +typedef void (GLUTCALLBACK *GLUTpassiveCB) (int, int); +typedef void (GLUTCALLBACK *GLUTentryCB) (int); +typedef void (GLUTCALLBACK *GLUTvisibilityCB) (int); +typedef void (GLUTCALLBACK *GLUTwindowStatusCB) (int); +typedef void (GLUTCALLBACK *GLUTidleCB) (void); +typedef void (GLUTCALLBACK *GLUTtimerCB) (int); +typedef void (GLUTCALLBACK *GLUTmenuStateCB) (int); /* DEPRECATED. */ +typedef void (GLUTCALLBACK *GLUTmenuStatusCB) (int, int, int); +typedef void (GLUTCALLBACK *GLUTselectCB) (int); +typedef void (GLUTCALLBACK *GLUTspecialCB) (int, int, int); +typedef void (GLUTCALLBACK *GLUTspaceMotionCB) (int, int, int); +typedef void (GLUTCALLBACK *GLUTspaceRotateCB) (int, int, int); +typedef void (GLUTCALLBACK *GLUTspaceButtonCB) (int, int); +typedef void (GLUTCALLBACK *GLUTdialsCB) (int, int); +typedef void (GLUTCALLBACK *GLUTbuttonBoxCB) (int, int); +typedef void (GLUTCALLBACK *GLUTtabletMotionCB) (int, int); +typedef void (GLUTCALLBACK *GLUTtabletButtonCB) (int, int, int, int); +typedef void (GLUTCALLBACK *GLUTjoystickCB) (unsigned int, int, int, int); + +typedef struct GLUTwindow { + int num; /* window id */ + + DMesaBuffer buffer; + + int show_mouse; + + /* GLUT settable or visible window state. */ + int xpos; + int ypos; + int width; /* window width in pixels */ + int height; /* window height in pixels */ + + /* Per-window callbacks. */ + GLUTdisplayCB display; /* redraw */ + GLUTreshapeCB reshape; /* resize (width,height) */ + GLUTmouseCB mouse; /* mouse (button,state,x,y) */ + GLUTmotionCB motion; /* motion (x,y) */ + GLUTpassiveCB passive; /* passive motion (x,y) */ + GLUTentryCB entry; /* window entry/exit (state) */ + GLUTkeyboardCB keyboard; /* keyboard (ASCII,x,y) */ + GLUTkeyboardCB keyboardUp; /* keyboard up (ASCII,x,y) */ + GLUTwindowStatusCB windowStatus; /* window status */ + GLUTvisibilityCB visibility; /* visibility */ + GLUTspecialCB special; /* special key */ + GLUTspecialCB specialUp; /* special up key */ + GLUTbuttonBoxCB buttonBox; /* button box */ + GLUTdialsCB dials; /* dials */ + GLUTspaceMotionCB spaceMotion; /* Spaceball motion */ + GLUTspaceRotateCB spaceRotate; /* Spaceball rotate */ + GLUTspaceButtonCB spaceButton; /* Spaceball button */ + GLUTtabletMotionCB tabletMotion; /* tablet motion */ + GLUTtabletButtonCB tabletButton; /* tablet button */ + GLUTjoystickCB joystick; /* joystick */ +} GLUTwindow; + +extern GLUTidleCB g_idle_func; +extern GLUTmenuStatusCB g_menu_status_func; + +extern GLboolean g_redisplay; + +extern GLuint g_bpp; /* HW: bits per pixel */ +extern GLuint g_refresh; /* HW: vertical refresh rate */ +extern GLuint g_screen_w, g_screen_h; /* HW: physical screen size */ +extern GLint g_driver_caps; + +extern GLuint g_fps; + +extern GLuint g_display_mode; /* display bits */ +extern int g_init_x, g_init_y; /* initial window position */ +extern GLuint g_init_w, g_init_h; /* initial window size */ + +extern int g_mouse; /* non-zero if mouse installed */ +extern int g_mouse_x, g_mouse_y; /* mouse coords, relative to current win */ + +extern GLUTwindow *g_curwin; /* current window */ + +extern char *__glutProgramName; /* program name */ + +extern void __glutInitMouse (void); + +/* private routines from glut_util.c */ +extern char * __glutStrdup(const char *string); +extern void __glutWarning(char *format,...); +extern void __glutFatalError(char *format,...); +extern void __glutFatalUsage(char *format,...); + + + +/* hmmm... */ +#include "pc_hw/pc_hw.h" + + + +#define MAX_WINDOWS 2 + +#define DEFAULT_WIDTH 300 +#define DEFAULT_HEIGHT 300 +#define DEFAULT_BPP 16 + +#define DEPTH_SIZE 16 +#define STENCIL_SIZE 8 +#define ACCUM_SIZE 16 + +#define RESERVED_COLORS 0 + +#endif /* __glutint_h__ */ diff --git a/src/glut/dos/init.c b/src/glut/dos/init.c index 9553cf2532e..5d09561dac3 100644 --- a/src/glut/dos/init.c +++ b/src/glut/dos/init.c @@ -1,254 +1,254 @@ -/*
- * Mesa 3-D graphics library
- * Version: 4.0
- * Copyright (C) 1995-1998 Brian Paul
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the Free
- * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-/*
- * DOS/DJGPP glut driver v1.3 for Mesa
- *
- * Copyright (C) 2002 - Borca Daniel
- * Email : [email protected]
- * Web : http://www.geocities.com/dborca
- */
-
-
-#include <string.h>
-
-#include "glutint.h"
-
-
-
-GLboolean g_redisplay = GL_FALSE;
-
-GLuint g_bpp = DEFAULT_BPP;
-GLuint g_refresh = 0;
-GLuint g_screen_w, g_screen_h;
-GLint g_driver_caps;
-
-GLuint g_fps = 0;
-
-GLuint g_display_mode = 0;
-int g_init_x = 0, g_init_y = 0;
-GLuint g_init_w = DEFAULT_WIDTH, g_init_h = DEFAULT_HEIGHT;
-
-char *__glutProgramName = NULL;
-
-
-
-void APIENTRY glutInit (int *argc, char **argv)
-{
- char *str;
- const char *env;
-
- if ((env = getenv("DMESA_GLUT_BPP")) != NULL) {
- g_bpp = atoi(env);
- }
- if ((env = getenv("DMESA_GLUT_REFRESH")) != NULL) {
- g_refresh = atoi(env);
- }
-
- /* Determine program name. */
- str = strrchr(argv[0], '/');
- if (str == NULL) {
- str = argv[0];
- } else {
- str++;
- }
- __glutProgramName = __glutStrdup(str);
-
- /* check if GLUT_FPS env var is set */
- if ((env = getenv("GLUT_FPS")) != NULL) {
- if ((g_fps = atoi(env)) <= 0) {
- g_fps = 5000; /* 5000 milliseconds */
- }
- }
-
- /* Initialize timer */
- glutGet(GLUT_ELAPSED_TIME);
-}
-
-
-
-void APIENTRY glutInitDisplayMode (unsigned int mode)
-{
- g_display_mode = mode;
-}
-
-
-
-void APIENTRY glutInitWindowPosition (int x, int y)
-{
- g_init_x = x;
- g_init_y = y;
-}
-
-
-
-void APIENTRY glutInitWindowSize (int width, int height)
-{
- g_init_w = width;
- g_init_h = height;
-}
-
-
-
-void APIENTRY glutMainLoop (void)
-{
- GLboolean idle;
- static int old_mouse_x = 0;
- static int old_mouse_y = 0;
- static int old_mouse_b = 0;
-
- {
- GLint screen_size[2];
- DMesaGetIntegerv(DMESA_GET_SCREEN_SIZE, screen_size);
- g_screen_w = screen_size[0];
- g_screen_h = screen_size[1];
- DMesaGetIntegerv(DMESA_GET_DRIVER_CAPS, &g_driver_caps);
- }
-
- pc_install_keyb();
- __glutInitMouse();
-
- glutPostRedisplay();
- if (g_curwin->reshape) {
- g_curwin->reshape(g_curwin->width, g_curwin->height);
- }
- if (g_curwin->visibility) {
- g_curwin->visibility(GLUT_VISIBLE);
- }
-
- while (GL_TRUE) {
- idle = GL_TRUE;
-
- if (g_redisplay && g_curwin->display) {
- idle = GL_FALSE;
- g_redisplay = GL_FALSE;
-
- if (g_curwin->show_mouse && !(g_display_mode & GLUT_DOUBLE)) {
- /* XXX scare mouse */
- g_curwin->display();
- /* XXX unscare mouse */
- } else {
- g_curwin->display();
- }
- }
-
- if (g_mouse) {
- int mouse_x;
- int mouse_y;
- int mouse_z;
- int mouse_b;
-
- /* query mouse */
- mouse_b = pc_query_mouse(&mouse_x, &mouse_y, &mouse_z);
-
- /* relative to window coordinates */
- g_mouse_x = mouse_x - g_curwin->xpos;
- g_mouse_y = mouse_y - g_curwin->ypos;
-
- /* mouse was moved? */
- if ((mouse_x != old_mouse_x) || (mouse_y != old_mouse_y)) {
- idle = GL_FALSE;
- old_mouse_x = mouse_x;
- old_mouse_y = mouse_y;
-
- if (mouse_b) {
- /* any button pressed */
- if (g_curwin->motion) {
- g_curwin->motion(g_mouse_x, g_mouse_y);
- }
- } else {
- /* no button pressed */
- if (g_curwin->passive) {
- g_curwin->passive(g_mouse_x, g_mouse_y);
- }
- }
- }
-
- /* button state changed? */
- if (mouse_b != old_mouse_b) {
- GLUTmouseCB mouse_func;
-
- if ((mouse_func = g_curwin->mouse)) {
- if ((old_mouse_b & 1) && !(mouse_b & 1))
- mouse_func(GLUT_LEFT_BUTTON, GLUT_UP, g_mouse_x, g_mouse_y);
- else if (!(old_mouse_b & 1) && (mouse_b & 1))
- mouse_func(GLUT_LEFT_BUTTON, GLUT_DOWN, g_mouse_x, g_mouse_y);
-
- if ((old_mouse_b & 2) && !(mouse_b & 2))
- mouse_func(GLUT_RIGHT_BUTTON, GLUT_UP, g_mouse_x, g_mouse_y);
- else if (!(old_mouse_b & 2) && (mouse_b & 2))
- mouse_func(GLUT_RIGHT_BUTTON, GLUT_DOWN, g_mouse_x, g_mouse_y);
-
- if ((old_mouse_b & 4) && !(mouse_b & 4))
- mouse_func(GLUT_MIDDLE_BUTTON, GLUT_UP, g_mouse_x, g_mouse_y);
- else if (!(old_mouse_b & 3) && (mouse_b & 4))
- mouse_func(GLUT_MIDDLE_BUTTON, GLUT_DOWN, g_mouse_x, g_mouse_y);
- }
-
- idle = GL_FALSE;
- old_mouse_b = mouse_b;
- }
- }
-
- if (pc_keypressed()) {
- int key;
- int glut_key;
-
- idle = GL_FALSE;
- key = pc_readkey();
-
- switch (key>>16) {
- case KEY_F1: glut_key = GLUT_KEY_F1; goto special;
- case KEY_F2: glut_key = GLUT_KEY_F2; goto special;
- case KEY_F3: glut_key = GLUT_KEY_F3; goto special;
- case KEY_F4: glut_key = GLUT_KEY_F4; goto special;
- case KEY_F5: glut_key = GLUT_KEY_F5; goto special;
- case KEY_F6: glut_key = GLUT_KEY_F6; goto special;
- case KEY_F7: glut_key = GLUT_KEY_F7; goto special;
- case KEY_F8: glut_key = GLUT_KEY_F8; goto special;
- case KEY_F9: glut_key = GLUT_KEY_F9; goto special;
- case KEY_F10: glut_key = GLUT_KEY_F10; goto special;
- case KEY_F11: glut_key = GLUT_KEY_F11; goto special;
- case KEY_F12: glut_key = GLUT_KEY_F12; goto special;
- case KEY_LEFT: glut_key = GLUT_KEY_LEFT; goto special;
- case KEY_UP: glut_key = GLUT_KEY_UP; goto special;
- case KEY_RIGHT: glut_key = GLUT_KEY_RIGHT; goto special;
- case KEY_DOWN: glut_key = GLUT_KEY_DOWN; goto special;
- case KEY_PGUP: glut_key = GLUT_KEY_PAGE_UP; goto special;
- case KEY_PGDN: glut_key = GLUT_KEY_PAGE_DOWN; goto special;
- case KEY_HOME: glut_key = GLUT_KEY_HOME; goto special;
- case KEY_END: glut_key = GLUT_KEY_END; goto special;
- case KEY_INSERT: glut_key = GLUT_KEY_INSERT; goto special;
- special:
- if (g_curwin->special) {
- g_curwin->special(glut_key, g_mouse_x, g_mouse_y);
- }
- break;
- default:
- if (g_curwin->keyboard) {
- g_curwin->keyboard(key & 0xFF, g_mouse_x, g_mouse_y);
- }
- }
- }
-
- if (idle && g_idle_func)
- g_idle_func();
- }
-}
+/* + * Mesa 3-D graphics library + * Version: 4.0 + * Copyright (C) 1995-1998 Brian Paul + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +/* + * DOS/DJGPP glut driver v1.3 for Mesa + * + * Copyright (C) 2002 - Borca Daniel + * Email : [email protected] + * Web : http://www.geocities.com/dborca + */ + + +#include <string.h> + +#include "glutint.h" + + + +GLboolean g_redisplay = GL_FALSE; + +GLuint g_bpp = DEFAULT_BPP; +GLuint g_refresh = 0; +GLuint g_screen_w, g_screen_h; +GLint g_driver_caps; + +GLuint g_fps = 0; + +GLuint g_display_mode = 0; +int g_init_x = 0, g_init_y = 0; +GLuint g_init_w = DEFAULT_WIDTH, g_init_h = DEFAULT_HEIGHT; + +char *__glutProgramName = NULL; + + + +void APIENTRY glutInit (int *argc, char **argv) +{ + char *str; + const char *env; + + if ((env = getenv("DMESA_GLUT_BPP")) != NULL) { + g_bpp = atoi(env); + } + if ((env = getenv("DMESA_GLUT_REFRESH")) != NULL) { + g_refresh = atoi(env); + } + + /* Determine program name. */ + str = strrchr(argv[0], '/'); + if (str == NULL) { + str = argv[0]; + } else { + str++; + } + __glutProgramName = __glutStrdup(str); + + /* check if GLUT_FPS env var is set */ + if ((env = getenv("GLUT_FPS")) != NULL) { + if ((g_fps = atoi(env)) <= 0) { + g_fps = 5000; /* 5000 milliseconds */ + } + } + + /* Initialize timer */ + glutGet(GLUT_ELAPSED_TIME); +} + + + +void APIENTRY glutInitDisplayMode (unsigned int mode) +{ + g_display_mode = mode; +} + + + +void APIENTRY glutInitWindowPosition (int x, int y) +{ + g_init_x = x; + g_init_y = y; +} + + + +void APIENTRY glutInitWindowSize (int width, int height) +{ + g_init_w = width; + g_init_h = height; +} + + + +void APIENTRY glutMainLoop (void) +{ + GLboolean idle; + static int old_mouse_x = 0; + static int old_mouse_y = 0; + static int old_mouse_b = 0; + + { + GLint screen_size[2]; + DMesaGetIntegerv(DMESA_GET_SCREEN_SIZE, screen_size); + g_screen_w = screen_size[0]; + g_screen_h = screen_size[1]; + DMesaGetIntegerv(DMESA_GET_DRIVER_CAPS, &g_driver_caps); + } + + pc_install_keyb(); + __glutInitMouse(); + + glutPostRedisplay(); + if (g_curwin->reshape) { + g_curwin->reshape(g_curwin->width, g_curwin->height); + } + if (g_curwin->visibility) { + g_curwin->visibility(GLUT_VISIBLE); + } + + while (GL_TRUE) { + idle = GL_TRUE; + + if (g_redisplay && g_curwin->display) { + idle = GL_FALSE; + g_redisplay = GL_FALSE; + + if (g_curwin->show_mouse && !(g_display_mode & GLUT_DOUBLE)) { + /* XXX scare mouse */ + g_curwin->display(); + /* XXX unscare mouse */ + } else { + g_curwin->display(); + } + } + + if (g_mouse) { + int mouse_x; + int mouse_y; + int mouse_z; + int mouse_b; + + /* query mouse */ + mouse_b = pc_query_mouse(&mouse_x, &mouse_y, &mouse_z); + + /* relative to window coordinates */ + g_mouse_x = mouse_x - g_curwin->xpos; + g_mouse_y = mouse_y - g_curwin->ypos; + + /* mouse was moved? */ + if ((mouse_x != old_mouse_x) || (mouse_y != old_mouse_y)) { + idle = GL_FALSE; + old_mouse_x = mouse_x; + old_mouse_y = mouse_y; + + if (mouse_b) { + /* any button pressed */ + if (g_curwin->motion) { + g_curwin->motion(g_mouse_x, g_mouse_y); + } + } else { + /* no button pressed */ + if (g_curwin->passive) { + g_curwin->passive(g_mouse_x, g_mouse_y); + } + } + } + + /* button state changed? */ + if (mouse_b != old_mouse_b) { + GLUTmouseCB mouse_func; + + if ((mouse_func = g_curwin->mouse)) { + if ((old_mouse_b & 1) && !(mouse_b & 1)) + mouse_func(GLUT_LEFT_BUTTON, GLUT_UP, g_mouse_x, g_mouse_y); + else if (!(old_mouse_b & 1) && (mouse_b & 1)) + mouse_func(GLUT_LEFT_BUTTON, GLUT_DOWN, g_mouse_x, g_mouse_y); + + if ((old_mouse_b & 2) && !(mouse_b & 2)) + mouse_func(GLUT_RIGHT_BUTTON, GLUT_UP, g_mouse_x, g_mouse_y); + else if (!(old_mouse_b & 2) && (mouse_b & 2)) + mouse_func(GLUT_RIGHT_BUTTON, GLUT_DOWN, g_mouse_x, g_mouse_y); + + if ((old_mouse_b & 4) && !(mouse_b & 4)) + mouse_func(GLUT_MIDDLE_BUTTON, GLUT_UP, g_mouse_x, g_mouse_y); + else if (!(old_mouse_b & 3) && (mouse_b & 4)) + mouse_func(GLUT_MIDDLE_BUTTON, GLUT_DOWN, g_mouse_x, g_mouse_y); + } + + idle = GL_FALSE; + old_mouse_b = mouse_b; + } + } + + if (pc_keypressed()) { + int key; + int glut_key; + + idle = GL_FALSE; + key = pc_readkey(); + + switch (key>>16) { + case KEY_F1: glut_key = GLUT_KEY_F1; goto special; + case KEY_F2: glut_key = GLUT_KEY_F2; goto special; + case KEY_F3: glut_key = GLUT_KEY_F3; goto special; + case KEY_F4: glut_key = GLUT_KEY_F4; goto special; + case KEY_F5: glut_key = GLUT_KEY_F5; goto special; + case KEY_F6: glut_key = GLUT_KEY_F6; goto special; + case KEY_F7: glut_key = GLUT_KEY_F7; goto special; + case KEY_F8: glut_key = GLUT_KEY_F8; goto special; + case KEY_F9: glut_key = GLUT_KEY_F9; goto special; + case KEY_F10: glut_key = GLUT_KEY_F10; goto special; + case KEY_F11: glut_key = GLUT_KEY_F11; goto special; + case KEY_F12: glut_key = GLUT_KEY_F12; goto special; + case KEY_LEFT: glut_key = GLUT_KEY_LEFT; goto special; + case KEY_UP: glut_key = GLUT_KEY_UP; goto special; + case KEY_RIGHT: glut_key = GLUT_KEY_RIGHT; goto special; + case KEY_DOWN: glut_key = GLUT_KEY_DOWN; goto special; + case KEY_PGUP: glut_key = GLUT_KEY_PAGE_UP; goto special; + case KEY_PGDN: glut_key = GLUT_KEY_PAGE_DOWN; goto special; + case KEY_HOME: glut_key = GLUT_KEY_HOME; goto special; + case KEY_END: glut_key = GLUT_KEY_END; goto special; + case KEY_INSERT: glut_key = GLUT_KEY_INSERT; goto special; + special: + if (g_curwin->special) { + g_curwin->special(glut_key, g_mouse_x, g_mouse_y); + } + break; + default: + if (g_curwin->keyboard) { + g_curwin->keyboard(key & 0xFF, g_mouse_x, g_mouse_y); + } + } + } + + if (idle && g_idle_func) + g_idle_func(); + } +} diff --git a/src/glut/dos/menu.c b/src/glut/dos/menu.c index e8f7b0a75b0..31e05f0c472 100644 --- a/src/glut/dos/menu.c +++ b/src/glut/dos/menu.c @@ -1,116 +1,116 @@ -/*
- * Mesa 3-D graphics library
- * Version: 3.4
- * Copyright (C) 1995-1998 Brian Paul
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the Free
- * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-/*
- * DOS/DJGPP glut driver v1.3 for Mesa
- *
- * Copyright (C) 2002 - Borca Daniel
- * Email : [email protected]
- * Web : http://www.geocities.com/dborca
- */
-
-
-#include "glutint.h"
-
-
-
-GLUTmenuStatusCB g_menu_status_func = NULL;
-
-
-
-void APIENTRY glutMenuStateFunc (GLUTmenuStateCB func)
-{
- g_menu_status_func = (GLUTmenuStatusCB)func;
-}
-
-
-
-void APIENTRY glutMenuStatusFunc (GLUTmenuStatusCB func)
-{
- g_menu_status_func = func;
-}
-
-
-
-int APIENTRY glutCreateMenu (GLUTselectCB func)
-{
- return 0;
-}
-
-
-
-void APIENTRY glutDestroyMenu (int menu)
-{
-}
-
-
-
-int APIENTRY glutGetMenu (void)
-{
- return 0;
-}
-
-
-
-void APIENTRY glutSetMenu (int menu)
-{
-}
-
-
-
-void APIENTRY glutAddMenuEntry (const char *label, int value)
-{
-}
-
-
-
-void APIENTRY glutAddSubMenu (const char *label, int submenu)
-{
-}
-
-
-
-void APIENTRY glutChangeToMenuEntry (int item, const char *label, int value)
-{
-}
-
-
-
-void APIENTRY glutChangeToSubMenu (int item, const char *label, int submenu)
-{
-}
-
-
-
-void APIENTRY glutRemoveMenuItem (int item)
-{
-}
-
-
-
-void APIENTRY glutAttachMenu (int button)
-{
-}
-
-
-
-void APIENTRY glutDetachMenu (int button)
-{
-}
+/* + * Mesa 3-D graphics library + * Version: 3.4 + * Copyright (C) 1995-1998 Brian Paul + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +/* + * DOS/DJGPP glut driver v1.3 for Mesa + * + * Copyright (C) 2002 - Borca Daniel + * Email : [email protected] + * Web : http://www.geocities.com/dborca + */ + + +#include "glutint.h" + + + +GLUTmenuStatusCB g_menu_status_func = NULL; + + + +void APIENTRY glutMenuStateFunc (GLUTmenuStateCB func) +{ + g_menu_status_func = (GLUTmenuStatusCB)func; +} + + + +void APIENTRY glutMenuStatusFunc (GLUTmenuStatusCB func) +{ + g_menu_status_func = func; +} + + + +int APIENTRY glutCreateMenu (GLUTselectCB func) +{ + return 0; +} + + + +void APIENTRY glutDestroyMenu (int menu) +{ +} + + + +int APIENTRY glutGetMenu (void) +{ + return 0; +} + + + +void APIENTRY glutSetMenu (int menu) +{ +} + + + +void APIENTRY glutAddMenuEntry (const char *label, int value) +{ +} + + + +void APIENTRY glutAddSubMenu (const char *label, int submenu) +{ +} + + + +void APIENTRY glutChangeToMenuEntry (int item, const char *label, int value) +{ +} + + + +void APIENTRY glutChangeToSubMenu (int item, const char *label, int submenu) +{ +} + + + +void APIENTRY glutRemoveMenuItem (int item) +{ +} + + + +void APIENTRY glutAttachMenu (int button) +{ +} + + + +void APIENTRY glutDetachMenu (int button) +{ +} diff --git a/src/glut/dos/mouse.c b/src/glut/dos/mouse.c index 7ba6358bc26..373ac49ffed 100644 --- a/src/glut/dos/mouse.c +++ b/src/glut/dos/mouse.c @@ -1,60 +1,60 @@ -/*
- * Mesa 3-D graphics library
- * Version: 3.4
- * Copyright (C) 1995-1998 Brian Paul
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the Free
- * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-/*
- * DOS/DJGPP glut driver v1.3 for Mesa
- *
- * Copyright (C) 2002 - Borca Daniel
- * Email : [email protected]
- * Web : http://www.geocities.com/dborca
- */
-
-
-#include "glutint.h"
-
-
-
-int g_mouse;
-int g_mouse_x = 0, g_mouse_y = 0;
-
-
-
-void __glutInitMouse (void)
-{
- if ((g_mouse = pc_install_mouse())) {
- pc_mouse_area(g_curwin->xpos, g_curwin->ypos, g_curwin->xpos + g_curwin->width - 1, g_curwin->ypos + g_curwin->height - 1);
-
- g_curwin->show_mouse = (g_curwin->mouse || g_curwin->motion || g_curwin->passive);
- }
-}
-
-
-
-void APIENTRY glutSetCursor (int cursor)
-{
- /* XXX completely futile until full mouse support (maybe never) */
-}
-
-
-
-void APIENTRY glutWarpPointer (int x, int y)
-{
- pc_warp_mouse(x, y);
-}
+/* + * Mesa 3-D graphics library + * Version: 3.4 + * Copyright (C) 1995-1998 Brian Paul + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +/* + * DOS/DJGPP glut driver v1.3 for Mesa + * + * Copyright (C) 2002 - Borca Daniel + * Email : [email protected] + * Web : http://www.geocities.com/dborca + */ + + +#include "glutint.h" + + + +int g_mouse; +int g_mouse_x = 0, g_mouse_y = 0; + + + +void __glutInitMouse (void) +{ + if ((g_mouse = pc_install_mouse())) { + pc_mouse_area(g_curwin->xpos, g_curwin->ypos, g_curwin->xpos + g_curwin->width - 1, g_curwin->ypos + g_curwin->height - 1); + + g_curwin->show_mouse = (g_curwin->mouse || g_curwin->motion || g_curwin->passive); + } +} + + + +void APIENTRY glutSetCursor (int cursor) +{ + /* XXX completely futile until full mouse support (maybe never) */ +} + + + +void APIENTRY glutWarpPointer (int x, int y) +{ + pc_warp_mouse(x, y); +} diff --git a/src/glut/dos/overlay.c b/src/glut/dos/overlay.c index d0e2a859c7b..b36f94c49a5 100644 --- a/src/glut/dos/overlay.c +++ b/src/glut/dos/overlay.c @@ -1,91 +1,91 @@ -/*
- * Mesa 3-D graphics library
- * Version: 3.4
- * Copyright (C) 1995-1998 Brian Paul
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the Free
- * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-/*
- * DOS/DJGPP glut driver v1.3 for Mesa
- *
- * Copyright (C) 2002 - Borca Daniel
- * Email : [email protected]
- * Web : http://www.geocities.com/dborca
- */
-
-
-#include "glutint.h"
-
-
-
-int APIENTRY glutLayerGet (GLenum info)
-{
- switch (info) {
- case GLUT_OVERLAY_POSSIBLE:
- case GLUT_HAS_OVERLAY:
- return GL_FALSE;
- case GLUT_LAYER_IN_USE:
- return GLUT_NORMAL;
- case GLUT_NORMAL_DAMAGED:
- return GL_FALSE;
- case GLUT_OVERLAY_DAMAGED:
- case GLUT_TRANSPARENT_INDEX:
- default:
- return -1;
- }
-}
-
-
-
-void APIENTRY glutOverlayDisplayFunc (GLUTdisplayCB func)
-{
-}
-
-
-
-void APIENTRY glutEstablishOverlay (void)
-{
-}
-
-
-
-void APIENTRY glutRemoveOverlay (void)
-{
-}
-
-
-
-void APIENTRY glutUseLayer (GLenum layer)
-{
-}
-
-
-
-void APIENTRY glutPostOverlayRedisplay (void)
-{
-}
-
-
-
-void APIENTRY glutShowOverlay (void)
-{
-}
-
-
-
-void APIENTRY glutHideOverlay (void)
-{
-}
+/* + * Mesa 3-D graphics library + * Version: 3.4 + * Copyright (C) 1995-1998 Brian Paul + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +/* + * DOS/DJGPP glut driver v1.3 for Mesa + * + * Copyright (C) 2002 - Borca Daniel + * Email : [email protected] + * Web : http://www.geocities.com/dborca + */ + + +#include "glutint.h" + + + +int APIENTRY glutLayerGet (GLenum info) +{ + switch (info) { + case GLUT_OVERLAY_POSSIBLE: + case GLUT_HAS_OVERLAY: + return GL_FALSE; + case GLUT_LAYER_IN_USE: + return GLUT_NORMAL; + case GLUT_NORMAL_DAMAGED: + return GL_FALSE; + case GLUT_OVERLAY_DAMAGED: + case GLUT_TRANSPARENT_INDEX: + default: + return -1; + } +} + + + +void APIENTRY glutOverlayDisplayFunc (GLUTdisplayCB func) +{ +} + + + +void APIENTRY glutEstablishOverlay (void) +{ +} + + + +void APIENTRY glutRemoveOverlay (void) +{ +} + + + +void APIENTRY glutUseLayer (GLenum layer) +{ +} + + + +void APIENTRY glutPostOverlayRedisplay (void) +{ +} + + + +void APIENTRY glutShowOverlay (void) +{ +} + + + +void APIENTRY glutHideOverlay (void) +{ +} diff --git a/src/glut/dos/state.c b/src/glut/dos/state.c index 38b03a72ab5..245d2ef621c 100644 --- a/src/glut/dos/state.c +++ b/src/glut/dos/state.c @@ -1,142 +1,142 @@ -/*
- * Mesa 3-D graphics library
- * Version: 3.4
- * Copyright (C) 1995-1998 Brian Paul
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the Free
- * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-/*
- * DOS/DJGPP glut driver v1.3 for Mesa
- *
- * Copyright (C) 2002 - Borca Daniel
- * Email : [email protected]
- * Web : http://www.geocities.com/dborca
- */
-
-
-#include "glutint.h"
-
-
-
-#define FREQUENCY 100
-
-
-
-static int timer_installed;
-static volatile int ticks;
-
-
-
-static void ticks_timer (void *p)
-{
- (void)p;
- ticks++;
-} ENDOFUNC(ticks_timer)
-
-
-
-int APIENTRY glutGet (GLenum type)
-{
- switch (type) {
- case GLUT_WINDOW_X:
- return g_curwin->xpos;
- case GLUT_WINDOW_Y:
- return g_curwin->ypos;
- case GLUT_WINDOW_WIDTH:
- return g_curwin->width;
- case GLUT_WINDOW_HEIGHT:
- return g_curwin->height;
- case GLUT_WINDOW_STENCIL_SIZE:
- return STENCIL_SIZE;
- case GLUT_WINDOW_DEPTH_SIZE:
- return DEPTH_SIZE;
- case GLUT_WINDOW_RGBA:
- return !(g_display_mode & GLUT_INDEX);
- case GLUT_WINDOW_COLORMAP_SIZE:
- return (g_display_mode & GLUT_INDEX) ? (256 - RESERVED_COLORS) : 0;
- case GLUT_SCREEN_WIDTH:
- return g_screen_w;
- case GLUT_SCREEN_HEIGHT:
- return g_screen_h;
- case GLUT_INIT_WINDOW_X:
- return g_init_x;
- case GLUT_INIT_WINDOW_Y:
- return g_init_y;
- case GLUT_INIT_WINDOW_WIDTH:
- return g_init_w;
- case GLUT_INIT_WINDOW_HEIGHT:
- return g_init_h;
- case GLUT_INIT_DISPLAY_MODE:
- return g_display_mode;
- case GLUT_ELAPSED_TIME:
- if (!timer_installed) {
- timer_installed = GL_TRUE;
- LOCKDATA(ticks);
- LOCKFUNC(ticks_timer);
- pc_install_int(ticks_timer, NULL, FREQUENCY);
- }
- return ticks*1000/FREQUENCY;
- default:
- return -1;
- }
-}
-
-
-
-int APIENTRY glutDeviceGet (GLenum type)
-{
- switch (type) {
- case GLUT_HAS_KEYBOARD:
- return GL_TRUE;
- case GLUT_HAS_MOUSE:
- return (g_mouse != 0);
- case GLUT_NUM_MOUSE_BUTTONS:
- return g_mouse;
- case GLUT_HAS_SPACEBALL:
- case GLUT_HAS_DIAL_AND_BUTTON_BOX:
- case GLUT_HAS_TABLET:
- return GL_FALSE;
- case GLUT_NUM_SPACEBALL_BUTTONS:
- case GLUT_NUM_BUTTON_BOX_BUTTONS:
- case GLUT_NUM_DIALS:
- case GLUT_NUM_TABLET_BUTTONS:
- return 0;
- default:
- return -1;
- }
-}
-
-
-
-int APIENTRY glutGetModifiers (void)
-{
- int mod = 0;
- int shifts = pc_keyshifts();
-
- if (shifts & (KB_SHIFT_FLAG | KB_CAPSLOCK_FLAG)) {
- mod |= GLUT_ACTIVE_SHIFT;
- }
-
- if (shifts & KB_ALT_FLAG) {
- mod |= GLUT_ACTIVE_ALT;
- }
-
- if (shifts & KB_CTRL_FLAG) {
- mod |= GLUT_ACTIVE_CTRL;
- }
-
- return mod;
-}
+/* + * Mesa 3-D graphics library + * Version: 3.4 + * Copyright (C) 1995-1998 Brian Paul + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +/* + * DOS/DJGPP glut driver v1.3 for Mesa + * + * Copyright (C) 2002 - Borca Daniel + * Email : [email protected] + * Web : http://www.geocities.com/dborca + */ + + +#include "glutint.h" + + + +#define FREQUENCY 100 + + + +static int timer_installed; +static volatile int ticks; + + + +static void ticks_timer (void *p) +{ + (void)p; + ticks++; +} ENDOFUNC(ticks_timer) + + + +int APIENTRY glutGet (GLenum type) +{ + switch (type) { + case GLUT_WINDOW_X: + return g_curwin->xpos; + case GLUT_WINDOW_Y: + return g_curwin->ypos; + case GLUT_WINDOW_WIDTH: + return g_curwin->width; + case GLUT_WINDOW_HEIGHT: + return g_curwin->height; + case GLUT_WINDOW_STENCIL_SIZE: + return STENCIL_SIZE; + case GLUT_WINDOW_DEPTH_SIZE: + return DEPTH_SIZE; + case GLUT_WINDOW_RGBA: + return !(g_display_mode & GLUT_INDEX); + case GLUT_WINDOW_COLORMAP_SIZE: + return (g_display_mode & GLUT_INDEX) ? (256 - RESERVED_COLORS) : 0; + case GLUT_SCREEN_WIDTH: + return g_screen_w; + case GLUT_SCREEN_HEIGHT: + return g_screen_h; + case GLUT_INIT_WINDOW_X: + return g_init_x; + case GLUT_INIT_WINDOW_Y: + return g_init_y; + case GLUT_INIT_WINDOW_WIDTH: + return g_init_w; + case GLUT_INIT_WINDOW_HEIGHT: + return g_init_h; + case GLUT_INIT_DISPLAY_MODE: + return g_display_mode; + case GLUT_ELAPSED_TIME: + if (!timer_installed) { + timer_installed = GL_TRUE; + LOCKDATA(ticks); + LOCKFUNC(ticks_timer); + pc_install_int(ticks_timer, NULL, FREQUENCY); + } + return ticks*1000/FREQUENCY; + default: + return -1; + } +} + + + +int APIENTRY glutDeviceGet (GLenum type) +{ + switch (type) { + case GLUT_HAS_KEYBOARD: + return GL_TRUE; + case GLUT_HAS_MOUSE: + return (g_mouse != 0); + case GLUT_NUM_MOUSE_BUTTONS: + return g_mouse; + case GLUT_HAS_SPACEBALL: + case GLUT_HAS_DIAL_AND_BUTTON_BOX: + case GLUT_HAS_TABLET: + return GL_FALSE; + case GLUT_NUM_SPACEBALL_BUTTONS: + case GLUT_NUM_BUTTON_BOX_BUTTONS: + case GLUT_NUM_DIALS: + case GLUT_NUM_TABLET_BUTTONS: + return 0; + default: + return -1; + } +} + + + +int APIENTRY glutGetModifiers (void) +{ + int mod = 0; + int shifts = pc_keyshifts(); + + if (shifts & (KB_SHIFT_FLAG | KB_CAPSLOCK_FLAG)) { + mod |= GLUT_ACTIVE_SHIFT; + } + + if (shifts & KB_ALT_FLAG) { + mod |= GLUT_ACTIVE_ALT; + } + + if (shifts & KB_CTRL_FLAG) { + mod |= GLUT_ACTIVE_CTRL; + } + + return mod; +} diff --git a/src/glut/dos/window.c b/src/glut/dos/window.c index 839241a9b09..cfc2f965c04 100644 --- a/src/glut/dos/window.c +++ b/src/glut/dos/window.c @@ -1,260 +1,260 @@ -/*
- * Mesa 3-D graphics library
- * Version: 4.1
- * Copyright (C) 1995-1998 Brian Paul
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the Free
- * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-/*
- * DOS/DJGPP glut driver v1.3 for Mesa
- *
- * Copyright (C) 2002 - Borca Daniel
- * Email : [email protected]
- * Web : http://www.geocities.com/dborca
- */
-
-
-#include <stdio.h>
-
-#include "glutint.h"
-#include "GL/dmesa.h"
-
-
-
-GLUTwindow *g_curwin;
-static GLuint swaptime, swapcount;
-
-static DMesaVisual visual = NULL;
-static DMesaContext context = NULL;
-static GLUTwindow *windows[MAX_WINDOWS];
-
-
-
-static void clean (void)
-{
- int i;
-
- for (i=1; i<=MAX_WINDOWS; i++) {
- glutDestroyWindow(i);
- }
- if (context) DMesaDestroyContext(context);
- if (visual) DMesaDestroyVisual(visual);
-
- pc_close_stdout();
- pc_close_stderr();
-}
-
-
-
-int APIENTRY glutCreateWindow (const char *title)
-{
- int i;
- int m8width = (g_init_w + 7) & ~7;
-
- if (!visual) {
- if ((visual=DMesaCreateVisual(g_init_x + m8width, g_init_y + g_init_h, g_bpp, g_refresh,
- g_display_mode & GLUT_DOUBLE,
- !(g_display_mode & GLUT_INDEX),
- g_display_mode & GLUT_ALPHA,
- g_display_mode & GLUT_DEPTH ?DEPTH_SIZE :0,
- g_display_mode & GLUT_STENCIL?STENCIL_SIZE:0,
- g_display_mode & GLUT_ACCUM ?ACCUM_SIZE :0))==NULL) {
- return 0;
- }
-
- if ((context=DMesaCreateContext(visual, NULL))==NULL) {
- DMesaDestroyVisual(visual);
- return 0;
- }
-
- pc_open_stdout();
- pc_open_stderr();
- pc_atexit(clean);
- }
-
- for (i=0; i<MAX_WINDOWS; i++) {
- if (windows[i] == NULL) {
- DMesaBuffer b;
- GLUTwindow *w;
-
- if ((w=(GLUTwindow *)calloc(1, sizeof(GLUTwindow))) == NULL) {
- return 0;
- }
-
- if ((b=DMesaCreateBuffer(visual, g_init_x, g_init_y, m8width, g_init_h))==NULL) {
- free(w);
- return 0;
- }
- if (!DMesaMakeCurrent(context, b)) {
- DMesaDestroyBuffer(b);
- free(w);
- return 0;
- }
-
- g_curwin = windows[i] = w;
-
- w->num = ++i;
- w->xpos = g_init_x;
- w->ypos = g_init_y;
- w->width = m8width;
- w->height = g_init_h;
- w->buffer = b;
-
- return i;
- }
- }
-
- return 0;
-}
-
-
-
-int APIENTRY glutCreateSubWindow (int win, int x, int y, int width, int height)
-{
- return GL_FALSE;
-}
-
-
-
-void APIENTRY glutDestroyWindow (int win)
-{
- if (windows[--win]) {
- DMesaDestroyBuffer(windows[win]->buffer);
- free(windows[win]);
- windows[win] = NULL;
- }
-}
-
-
-
-void APIENTRY glutPostRedisplay (void)
-{
- g_redisplay = GL_TRUE;
-}
-
-
-
-void APIENTRY glutSwapBuffers (void)
-{
- if (g_curwin->show_mouse) {
- /* XXX scare mouse */
- DMesaSwapBuffers(g_curwin->buffer);
- /* XXX unscare mouse */
- } else {
- DMesaSwapBuffers(g_curwin->buffer);
- }
-
- if (g_fps) {
- GLint t = glutGet(GLUT_ELAPSED_TIME);
- swapcount++;
- if (swaptime == 0)
- swaptime = t;
- else if (t - swaptime > g_fps) {
- double time = 0.001 * (t - swaptime);
- double fps = (double)swapcount / time;
- fprintf(stderr, "GLUT: %d frames in %.2f seconds = %.2f FPS\n", swapcount, time, fps);
- swaptime = t;
- swapcount = 0;
- }
- }
-}
-
-
-
-int APIENTRY glutGetWindow (void)
-{
- return g_curwin->num;
-}
-
-
-
-void APIENTRY glutSetWindow (int win)
-{
- g_curwin = windows[win - 1];
-}
-
-
-
-void APIENTRY glutSetWindowTitle (const char *title)
-{
-}
-
-
-
-void APIENTRY glutSetIconTitle (const char *title)
-{
-}
-
-
-
-void APIENTRY glutPositionWindow (int x, int y)
-{
- if (DMesaMoveBuffer(x, y)) {
- g_curwin->xpos = x;
- g_curwin->ypos = y;
- }
-}
-
-
-
-void APIENTRY glutReshapeWindow (int width, int height)
-{
- if (DMesaResizeBuffer(width, height)) {
- g_curwin->width = width;
- g_curwin->height = height;
- if (g_curwin->reshape) {
- g_curwin->reshape(width, height);
- } else {
- glViewport(0, 0, width, height);
- }
- }
-}
-
-
-
-void APIENTRY glutFullScreen (void)
-{
-}
-
-
-
-void APIENTRY glutPopWindow (void)
-{
-}
-
-
-
-void APIENTRY glutPushWindow (void)
-{
-}
-
-
-
-void APIENTRY glutIconifyWindow (void)
-{
-}
-
-
-
-void APIENTRY glutShowWindow (void)
-{
-}
-
-
-
-void APIENTRY glutHideWindow (void)
-{
-}
+/* + * Mesa 3-D graphics library + * Version: 4.1 + * Copyright (C) 1995-1998 Brian Paul + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +/* + * DOS/DJGPP glut driver v1.3 for Mesa + * + * Copyright (C) 2002 - Borca Daniel + * Email : [email protected] + * Web : http://www.geocities.com/dborca + */ + + +#include <stdio.h> + +#include "glutint.h" +#include "GL/dmesa.h" + + + +GLUTwindow *g_curwin; +static GLuint swaptime, swapcount; + +static DMesaVisual visual = NULL; +static DMesaContext context = NULL; +static GLUTwindow *windows[MAX_WINDOWS]; + + + +static void clean (void) +{ + int i; + + for (i=1; i<=MAX_WINDOWS; i++) { + glutDestroyWindow(i); + } + if (context) DMesaDestroyContext(context); + if (visual) DMesaDestroyVisual(visual); + + pc_close_stdout(); + pc_close_stderr(); +} + + + +int APIENTRY glutCreateWindow (const char *title) +{ + int i; + int m8width = (g_init_w + 7) & ~7; + + if (!visual) { + if ((visual=DMesaCreateVisual(g_init_x + m8width, g_init_y + g_init_h, g_bpp, g_refresh, + g_display_mode & GLUT_DOUBLE, + !(g_display_mode & GLUT_INDEX), + g_display_mode & GLUT_ALPHA, + g_display_mode & GLUT_DEPTH ?DEPTH_SIZE :0, + g_display_mode & GLUT_STENCIL?STENCIL_SIZE:0, + g_display_mode & GLUT_ACCUM ?ACCUM_SIZE :0))==NULL) { + return 0; + } + + if ((context=DMesaCreateContext(visual, NULL))==NULL) { + DMesaDestroyVisual(visual); + return 0; + } + + pc_open_stdout(); + pc_open_stderr(); + pc_atexit(clean); + } + + for (i=0; i<MAX_WINDOWS; i++) { + if (windows[i] == NULL) { + DMesaBuffer b; + GLUTwindow *w; + + if ((w=(GLUTwindow *)calloc(1, sizeof(GLUTwindow))) == NULL) { + return 0; + } + + if ((b=DMesaCreateBuffer(visual, g_init_x, g_init_y, m8width, g_init_h))==NULL) { + free(w); + return 0; + } + if (!DMesaMakeCurrent(context, b)) { + DMesaDestroyBuffer(b); + free(w); + return 0; + } + + g_curwin = windows[i] = w; + + w->num = ++i; + w->xpos = g_init_x; + w->ypos = g_init_y; + w->width = m8width; + w->height = g_init_h; + w->buffer = b; + + return i; + } + } + + return 0; +} + + + +int APIENTRY glutCreateSubWindow (int win, int x, int y, int width, int height) +{ + return GL_FALSE; +} + + + +void APIENTRY glutDestroyWindow (int win) +{ + if (windows[--win]) { + DMesaDestroyBuffer(windows[win]->buffer); + free(windows[win]); + windows[win] = NULL; + } +} + + + +void APIENTRY glutPostRedisplay (void) +{ + g_redisplay = GL_TRUE; +} + + + +void APIENTRY glutSwapBuffers (void) +{ + if (g_curwin->show_mouse) { + /* XXX scare mouse */ + DMesaSwapBuffers(g_curwin->buffer); + /* XXX unscare mouse */ + } else { + DMesaSwapBuffers(g_curwin->buffer); + } + + if (g_fps) { + GLint t = glutGet(GLUT_ELAPSED_TIME); + swapcount++; + if (swaptime == 0) + swaptime = t; + else if (t - swaptime > g_fps) { + double time = 0.001 * (t - swaptime); + double fps = (double)swapcount / time; + fprintf(stderr, "GLUT: %d frames in %.2f seconds = %.2f FPS\n", swapcount, time, fps); + swaptime = t; + swapcount = 0; + } + } +} + + + +int APIENTRY glutGetWindow (void) +{ + return g_curwin->num; +} + + + +void APIENTRY glutSetWindow (int win) +{ + g_curwin = windows[win - 1]; +} + + + +void APIENTRY glutSetWindowTitle (const char *title) +{ +} + + + +void APIENTRY glutSetIconTitle (const char *title) +{ +} + + + +void APIENTRY glutPositionWindow (int x, int y) +{ + if (DMesaMoveBuffer(x, y)) { + g_curwin->xpos = x; + g_curwin->ypos = y; + } +} + + + +void APIENTRY glutReshapeWindow (int width, int height) +{ + if (DMesaResizeBuffer(width, height)) { + g_curwin->width = width; + g_curwin->height = height; + if (g_curwin->reshape) { + g_curwin->reshape(width, height); + } else { + glViewport(0, 0, width, height); + } + } +} + + + +void APIENTRY glutFullScreen (void) +{ +} + + + +void APIENTRY glutPopWindow (void) +{ +} + + + +void APIENTRY glutPushWindow (void) +{ +} + + + +void APIENTRY glutIconifyWindow (void) +{ +} + + + +void APIENTRY glutShowWindow (void) +{ +} + + + +void APIENTRY glutHideWindow (void) +{ +} |