ruby-glfw 0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (206) hide show
  1. data/README +1 -0
  2. data/README.API +73 -0
  3. data/Rakefile +120 -0
  4. data/examples/boing.rb +519 -0
  5. data/examples/gears.rb +327 -0
  6. data/examples/keytest.rb +117 -0
  7. data/examples/listmodes.rb +20 -0
  8. data/examples/mipmaps.rb +104 -0
  9. data/examples/mipmaps.tga +0 -0
  10. data/examples/particles.rb +837 -0
  11. data/examples/pong3d.rb +741 -0
  12. data/examples/pong3d_field.tga +0 -0
  13. data/examples/pong3d_instr.tga +0 -0
  14. data/examples/pong3d_menu.tga +0 -0
  15. data/examples/pong3d_title.tga +0 -0
  16. data/examples/pong3d_winner1.tga +0 -0
  17. data/examples/pong3d_winner2.tga +0 -0
  18. data/examples/splitview.rb +432 -0
  19. data/examples/triangle.rb +89 -0
  20. data/examples/wave.rb +294 -0
  21. data/ext/glfw/glfw.c +1094 -0
  22. data/ext/glfw/mkrf_conf.rb +70 -0
  23. data/glfw-src/Makefile +220 -0
  24. data/glfw-src/compile.ami +61 -0
  25. data/glfw-src/compile.bat +217 -0
  26. data/glfw-src/compile.sh +607 -0
  27. data/glfw-src/docs/Makefile +57 -0
  28. data/glfw-src/docs/Reference.pdf +0 -0
  29. data/glfw-src/docs/UsersGuide.pdf +0 -0
  30. data/glfw-src/docs/cleanup.bat +22 -0
  31. data/glfw-src/docs/glfwdoc.sty +80 -0
  32. data/glfw-src/docs/glfwrm.tex +3034 -0
  33. data/glfw-src/docs/glfwug.tex +2024 -0
  34. data/glfw-src/docs/readme.txt +80 -0
  35. data/glfw-src/examples/Makefile.amigaos.gcc +70 -0
  36. data/glfw-src/examples/Makefile.amigaos.vbcc +70 -0
  37. data/glfw-src/examples/Makefile.dos.djgpp +71 -0
  38. data/glfw-src/examples/Makefile.macosx.gcc +96 -0
  39. data/glfw-src/examples/Makefile.win32.bcc +75 -0
  40. data/glfw-src/examples/Makefile.win32.cross-mgw +79 -0
  41. data/glfw-src/examples/Makefile.win32.cygwin +79 -0
  42. data/glfw-src/examples/Makefile.win32.lcc +74 -0
  43. data/glfw-src/examples/Makefile.win32.mgw +75 -0
  44. data/glfw-src/examples/Makefile.win32.msvc +74 -0
  45. data/glfw-src/examples/Makefile.win32.ow +74 -0
  46. data/glfw-src/examples/Makefile.win32.pellesc +74 -0
  47. data/glfw-src/examples/Makefile.x11.in +54 -0
  48. data/glfw-src/examples/boing.c +606 -0
  49. data/glfw-src/examples/bundle.sh +46 -0
  50. data/glfw-src/examples/gears.c +382 -0
  51. data/glfw-src/examples/keytest.c +264 -0
  52. data/glfw-src/examples/listmodes.c +48 -0
  53. data/glfw-src/examples/mipmaps.c +126 -0
  54. data/glfw-src/examples/mipmaps.tga +0 -0
  55. data/glfw-src/examples/mtbench.c +301 -0
  56. data/glfw-src/examples/mthello.c +48 -0
  57. data/glfw-src/examples/particles.c +1148 -0
  58. data/glfw-src/examples/pong3d.c +839 -0
  59. data/glfw-src/examples/pong3d_field.tga +0 -0
  60. data/glfw-src/examples/pong3d_instr.tga +0 -0
  61. data/glfw-src/examples/pong3d_menu.tga +0 -0
  62. data/glfw-src/examples/pong3d_title.tga +0 -0
  63. data/glfw-src/examples/pong3d_winner1.tga +0 -0
  64. data/glfw-src/examples/pong3d_winner2.tga +0 -0
  65. data/glfw-src/examples/splitview.c +506 -0
  66. data/glfw-src/examples/triangle.c +108 -0
  67. data/glfw-src/examples/wave.c +397 -0
  68. data/glfw-src/images/opengl.gif +0 -0
  69. data/glfw-src/images/osicert.gif +0 -0
  70. data/glfw-src/include/GL/glfw.h +486 -0
  71. data/glfw-src/lib/amigaos/Makefile.amigaos.gcc +128 -0
  72. data/glfw-src/lib/amigaos/Makefile.amigaos.vbcc +128 -0
  73. data/glfw-src/lib/amigaos/SDI_compiler.h +94 -0
  74. data/glfw-src/lib/amigaos/amigaos_enable.c +51 -0
  75. data/glfw-src/lib/amigaos/amigaos_fullscreen.c +319 -0
  76. data/glfw-src/lib/amigaos/amigaos_glext.c +61 -0
  77. data/glfw-src/lib/amigaos/amigaos_init.c +284 -0
  78. data/glfw-src/lib/amigaos/amigaos_joystick.c +359 -0
  79. data/glfw-src/lib/amigaos/amigaos_thread.c +494 -0
  80. data/glfw-src/lib/amigaos/amigaos_time.c +206 -0
  81. data/glfw-src/lib/amigaos/amigaos_window.c +830 -0
  82. data/glfw-src/lib/amigaos/platform.h +337 -0
  83. data/glfw-src/lib/dos/Makefile.dos.djgpp +146 -0
  84. data/glfw-src/lib/dos/dos_enable.c +51 -0
  85. data/glfw-src/lib/dos/dos_events.c +173 -0
  86. data/glfw-src/lib/dos/dos_fullscreen.c +101 -0
  87. data/glfw-src/lib/dos/dos_glext.c +59 -0
  88. data/glfw-src/lib/dos/dos_init.c +105 -0
  89. data/glfw-src/lib/dos/dos_irq.s +246 -0
  90. data/glfw-src/lib/dos/dos_joystick.c +94 -0
  91. data/glfw-src/lib/dos/dos_keyboard.c +694 -0
  92. data/glfw-src/lib/dos/dos_mouse.c +337 -0
  93. data/glfw-src/lib/dos/dos_thread.c +267 -0
  94. data/glfw-src/lib/dos/dos_time.c +309 -0
  95. data/glfw-src/lib/dos/dos_window.c +563 -0
  96. data/glfw-src/lib/dos/platform.h +341 -0
  97. data/glfw-src/lib/enable.c +295 -0
  98. data/glfw-src/lib/fullscreen.c +95 -0
  99. data/glfw-src/lib/glext.c +201 -0
  100. data/glfw-src/lib/image.c +629 -0
  101. data/glfw-src/lib/init.c +108 -0
  102. data/glfw-src/lib/input.c +280 -0
  103. data/glfw-src/lib/internal.h +210 -0
  104. data/glfw-src/lib/joystick.c +101 -0
  105. data/glfw-src/lib/macosx/Makefile.macosx.gcc +172 -0
  106. data/glfw-src/lib/macosx/Makefile.macosx.gcc.universal +166 -0
  107. data/glfw-src/lib/macosx/libglfw.pc.in +11 -0
  108. data/glfw-src/lib/macosx/macosx_enable.c +42 -0
  109. data/glfw-src/lib/macosx/macosx_fullscreen.c +126 -0
  110. data/glfw-src/lib/macosx/macosx_glext.c +52 -0
  111. data/glfw-src/lib/macosx/macosx_init.c +194 -0
  112. data/glfw-src/lib/macosx/macosx_joystick.c +50 -0
  113. data/glfw-src/lib/macosx/macosx_thread.c +414 -0
  114. data/glfw-src/lib/macosx/macosx_time.c +112 -0
  115. data/glfw-src/lib/macosx/macosx_window.c +1279 -0
  116. data/glfw-src/lib/macosx/platform.h +349 -0
  117. data/glfw-src/lib/stream.c +194 -0
  118. data/glfw-src/lib/tga.c +405 -0
  119. data/glfw-src/lib/thread.c +340 -0
  120. data/glfw-src/lib/time.c +83 -0
  121. data/glfw-src/lib/win32/Makefile.win32.bcc +265 -0
  122. data/glfw-src/lib/win32/Makefile.win32.cross-mgw +274 -0
  123. data/glfw-src/lib/win32/Makefile.win32.cygwin +279 -0
  124. data/glfw-src/lib/win32/Makefile.win32.lcc +246 -0
  125. data/glfw-src/lib/win32/Makefile.win32.mgw +243 -0
  126. data/glfw-src/lib/win32/Makefile.win32.msvc +242 -0
  127. data/glfw-src/lib/win32/Makefile.win32.ow +242 -0
  128. data/glfw-src/lib/win32/Makefile.win32.pellesc +242 -0
  129. data/glfw-src/lib/win32/glfwdll.def +67 -0
  130. data/glfw-src/lib/win32/glfwdll_mgw1.def +67 -0
  131. data/glfw-src/lib/win32/glfwdll_mgw2.def +67 -0
  132. data/glfw-src/lib/win32/glfwdll_pellesc.def +65 -0
  133. data/glfw-src/lib/win32/libglfw.pc.in +11 -0
  134. data/glfw-src/lib/win32/platform.h +474 -0
  135. data/glfw-src/lib/win32/win32_dllmain.c +60 -0
  136. data/glfw-src/lib/win32/win32_enable.c +155 -0
  137. data/glfw-src/lib/win32/win32_fullscreen.c +317 -0
  138. data/glfw-src/lib/win32/win32_glext.c +85 -0
  139. data/glfw-src/lib/win32/win32_init.c +356 -0
  140. data/glfw-src/lib/win32/win32_joystick.c +234 -0
  141. data/glfw-src/lib/win32/win32_thread.c +511 -0
  142. data/glfw-src/lib/win32/win32_time.c +146 -0
  143. data/glfw-src/lib/win32/win32_window.c +1714 -0
  144. data/glfw-src/lib/window.c +727 -0
  145. data/glfw-src/lib/x11/Makefile.x11.in +243 -0
  146. data/glfw-src/lib/x11/platform.h +415 -0
  147. data/glfw-src/lib/x11/x11_enable.c +51 -0
  148. data/glfw-src/lib/x11/x11_fullscreen.c +524 -0
  149. data/glfw-src/lib/x11/x11_glext.c +69 -0
  150. data/glfw-src/lib/x11/x11_init.c +275 -0
  151. data/glfw-src/lib/x11/x11_joystick.c +371 -0
  152. data/glfw-src/lib/x11/x11_keysym2unicode.c +902 -0
  153. data/glfw-src/lib/x11/x11_thread.c +507 -0
  154. data/glfw-src/lib/x11/x11_time.c +154 -0
  155. data/glfw-src/lib/x11/x11_window.c +1746 -0
  156. data/glfw-src/license.txt +21 -0
  157. data/glfw-src/readme.html +927 -0
  158. data/glfw-src/support/d/examples/Makefile +59 -0
  159. data/glfw-src/support/d/examples/boing.d +610 -0
  160. data/glfw-src/support/d/examples/gears.d +379 -0
  161. data/glfw-src/support/d/examples/keytest.d +272 -0
  162. data/glfw-src/support/d/examples/listmodes.d +48 -0
  163. data/glfw-src/support/d/examples/mipmaps.d +126 -0
  164. data/glfw-src/support/d/examples/mtbench.d +304 -0
  165. data/glfw-src/support/d/examples/mthello.d +54 -0
  166. data/glfw-src/support/d/examples/particles.d +1150 -0
  167. data/glfw-src/support/d/examples/pong3d.d +840 -0
  168. data/glfw-src/support/d/examples/splitview.d +486 -0
  169. data/glfw-src/support/d/examples/triangle.d +108 -0
  170. data/glfw-src/support/d/examples/wave.d +400 -0
  171. data/glfw-src/support/d/imports/gl.d +4539 -0
  172. data/glfw-src/support/d/imports/glfw.d +349 -0
  173. data/glfw-src/support/d/imports/glu.d +328 -0
  174. data/glfw-src/support/d/lib/glfwdll.def +64 -0
  175. data/glfw-src/support/d/lib/glu32.def +56 -0
  176. data/glfw-src/support/d/lib/makefile +12 -0
  177. data/glfw-src/support/d/lib/opengl32.def +372 -0
  178. data/glfw-src/support/d/readme.html +83 -0
  179. data/glfw-src/support/delphi/examples/Triangle.dpr +105 -0
  180. data/glfw-src/support/delphi/lib/glfw.pas +437 -0
  181. data/glfw-src/support/delphi/readme.html +97 -0
  182. data/glfw-src/support/lua/examples/gears.lua +383 -0
  183. data/glfw-src/support/lua/examples/test1.lua +68 -0
  184. data/glfw-src/support/lua/readme.html +128 -0
  185. data/glfw-src/support/lua/src/luaglfw.c +1179 -0
  186. data/glfw-src/support/lua/src/luaglfw.h +48 -0
  187. data/glfw-src/support/lua/src/runlua.c +82 -0
  188. data/glfw-src/support/masm/examples/fpc.mac +47 -0
  189. data/glfw-src/support/masm/examples/makeit.bat +66 -0
  190. data/glfw-src/support/masm/examples/triangle.asm +232 -0
  191. data/glfw-src/support/masm/include/glfw.inc +326 -0
  192. data/glfw-src/support/masm/include/glu32.inc +55 -0
  193. data/glfw-src/support/masm/include/opengl32.inc +372 -0
  194. data/glfw-src/support/masm/lib/glfwdll.lib +0 -0
  195. data/glfw-src/support/masm/readme.html +170 -0
  196. data/glfw-src/support/msvc80/GLFW.sln +26 -0
  197. data/glfw-src/support/msvc80/GLFW.vcproj +257 -0
  198. data/glfw-src/support/msvc80/GLFWDLL.vcproj +287 -0
  199. data/glfw-src/support/visualbasic/bindings/glfw.bas +320 -0
  200. data/glfw-src/support/visualbasic/bindings/glu32.bas +284 -0
  201. data/glfw-src/support/visualbasic/bindings/opengl32.bas +999 -0
  202. data/glfw-src/support/visualbasic/examples/Triangle.bas +101 -0
  203. data/glfw-src/support/visualbasic/readme.html +164 -0
  204. data/website/index.html +84 -0
  205. data/website/style.css +110 -0
  206. metadata +301 -0
@@ -0,0 +1,246 @@
1
+ //========================================================================
2
+ // GLFW - An OpenGL framework
3
+ // File: dos_irq.s
4
+ // Platform: DOS
5
+ // API version: 2.4
6
+ // WWW: http://glfw.sourceforge.net
7
+ //------------------------------------------------------------------------
8
+ // Copyright (c) 2002-2004 Camilla Berglund
9
+ //
10
+ // This software is provided 'as-is', without any express or implied
11
+ // warranty. In no event will the authors be held liable for any damages
12
+ // arising from the use of this software.
13
+ //
14
+ // Permission is granted to anyone to use this software for any purpose,
15
+ // including commercial applications, and to alter it and redistribute it
16
+ // freely, subject to the following restrictions:
17
+ //
18
+ // 1. The origin of this software must not be misrepresented; you must not
19
+ // claim that you wrote the original software. If you use this software
20
+ // in a product, an acknowledgment in the product documentation would
21
+ // be appreciated but is not required.
22
+ //
23
+ // 2. Altered source versions must be plainly marked as such, and must not
24
+ // be misrepresented as being the original software.
25
+ //
26
+ // 3. This notice may not be removed or altered from any source
27
+ // distribution.
28
+ //
29
+ //========================================================================
30
+
31
+ .file "dos_irq.S"
32
+
33
+ .text
34
+
35
+
36
+ #define IRQ_STACK_SIZE 16384
37
+
38
+ #define IRQ_WRAPPER_LEN (__irq_wrapper_1-__irq_wrapper_0)
39
+ #define IRQ_OLD (__irq_old_0-__irq_wrapper_0)
40
+ #define IRQ_HOOK (__irq_hook_0-__irq_wrapper_0)
41
+ #define IRQ_STACK (__irq_stack_0-__irq_wrapper_0)
42
+
43
+
44
+ //========================================================================
45
+ // common
46
+ //========================================================================
47
+
48
+ .balign 4
49
+ common:
50
+ movw $0x0400, %ax
51
+ int $0x31
52
+
53
+ movl %ss:8(%ebp), %ebx
54
+ cmpl $15, %ebx
55
+ jbe 0f
56
+ fail:
57
+ orl $-1, %eax
58
+ popl %edi
59
+ popl %ebx
60
+ leave
61
+ ret
62
+
63
+ 0:
64
+ movl %ebx, %edi
65
+ imull $IRQ_WRAPPER_LEN, %edi
66
+ addl $__irq_wrapper_0, %edi
67
+
68
+ cmpb $7, %bl
69
+ jbe 1f
70
+ movb %dl, %dh
71
+ subb $8, %dh
72
+ 1:
73
+ addb %dh, %bl
74
+ ret
75
+
76
+
77
+ //========================================================================
78
+ // _glfwInstallDOSIrq()
79
+ //========================================================================
80
+
81
+ .balign 4
82
+ .global __glfwInstallDOSIrq
83
+ __glfwInstallDOSIrq:
84
+ pushl %ebp
85
+ movl %esp, %ebp
86
+ pushl %ebx
87
+ pushl %edi
88
+
89
+ call common
90
+
91
+ cmpl $0, IRQ_HOOK(%edi)
92
+ jne fail
93
+
94
+ pushl $IRQ_WRAPPER_LEN
95
+ pushl %edi
96
+ call __go32_dpmi_lock_code
97
+ addl $8, %esp
98
+ testl %eax, %eax
99
+ jnz fail
100
+
101
+ /* OLD >>
102
+ pushl $IRQ_STACK_SIZE
103
+ call _pc_malloc
104
+ popl %edx
105
+ testl %eax, %eax
106
+ jz fail
107
+ addl %edx, %eax
108
+ movl %eax, IRQ_STACK(%edi)
109
+ << OLD */
110
+
111
+ /* MG: NEW >> */
112
+ pushl $IRQ_STACK_SIZE
113
+ call _malloc
114
+ popl %edx
115
+ testl %eax, %eax
116
+ jz fail
117
+
118
+ pushl %edx
119
+ pushl %eax
120
+ call __go32_dpmi_lock_data
121
+ addl $8, %esp
122
+ testl %eax, %eax
123
+ jnz fail
124
+ subl $8, %esp
125
+ popl %eax
126
+ popl %edx
127
+
128
+ addl %edx, %eax
129
+ movl %eax, IRQ_STACK(%edi)
130
+ /* << NEW */
131
+
132
+ movl ___djgpp_ds_alias, %eax
133
+ movl %eax, IRQ_STACK+4(%edi)
134
+
135
+ movl %ss:12(%ebp), %eax
136
+ movl %eax, IRQ_HOOK(%edi)
137
+
138
+ movw $0x0204, %ax
139
+ int $0x31
140
+ movl %edx, IRQ_OLD(%edi)
141
+ movw %cx, IRQ_OLD+4(%edi)
142
+ movw $0x0205, %ax
143
+ movl %edi, %edx
144
+ movl %cs, %ecx
145
+ int $0x31
146
+
147
+ done:
148
+ xorl %eax, %eax
149
+ popl %edi
150
+ popl %ebx
151
+ leave
152
+ ret
153
+
154
+
155
+ //========================================================================
156
+ // _glfwRemoveDOSIrq()
157
+ //========================================================================
158
+ .balign 4
159
+ .global __glfwRemoveDOSIrq
160
+ __glfwRemoveDOSIrq:
161
+ pushl %ebp
162
+ movl %esp, %ebp
163
+ pushl %ebx
164
+ pushl %edi
165
+
166
+ call common
167
+
168
+ cmpl $0, IRQ_HOOK(%edi)
169
+ je fail
170
+
171
+ movl $0, IRQ_HOOK(%edi)
172
+
173
+ movw $0x0205, %ax
174
+ movl IRQ_OLD(%edi), %edx
175
+ movl IRQ_OLD+4(%edi), %ecx
176
+ int $0x31
177
+
178
+ movl IRQ_STACK(%edi), %eax
179
+ subl $IRQ_STACK_SIZE, %eax
180
+ pushl %eax
181
+ call _free
182
+ popl %eax
183
+
184
+ jmp done
185
+
186
+
187
+ //========================================================================
188
+ // IRQ wrapper code for all 16 different IRQs
189
+ //========================================================================
190
+
191
+ #define WRAPPER(x) ; \
192
+ .balign 4 ; \
193
+ __irq_wrapper_##x: ; \
194
+ pushal ; \
195
+ pushl %ds ; \
196
+ pushl %es ; \
197
+ pushl %fs ; \
198
+ pushl %gs ; \
199
+ movl %ss, %ebx ; \
200
+ movl %esp, %esi ; \
201
+ lss %cs:__irq_stack_##x, %esp ; \
202
+ pushl %ss ; \
203
+ pushl %ss ; \
204
+ popl %es ; \
205
+ popl %ds ; \
206
+ movl ___djgpp_dos_sel, %fs ; \
207
+ pushl %fs ; \
208
+ popl %gs ; \
209
+ call *__irq_hook_##x ; \
210
+ movl %ebx, %ss ; \
211
+ movl %esi, %esp ; \
212
+ testl %eax, %eax ; \
213
+ popl %gs ; \
214
+ popl %fs ; \
215
+ popl %es ; \
216
+ popl %ds ; \
217
+ popal ; \
218
+ jz __irq_ignore_##x ; \
219
+ __irq_bypass_##x: ; \
220
+ ljmp *%cs:__irq_old_##x ; \
221
+ __irq_ignore_##x: ; \
222
+ iret ; \
223
+ .balign 4 ; \
224
+ __irq_old_##x: ; \
225
+ .long 0, 0 ; \
226
+ __irq_hook_##x: ; \
227
+ .long 0 ; \
228
+ __irq_stack_##x: ; \
229
+ .long 0, 0
230
+
231
+ WRAPPER(0);
232
+ WRAPPER(1);
233
+ WRAPPER(2);
234
+ WRAPPER(3);
235
+ WRAPPER(4);
236
+ WRAPPER(5);
237
+ WRAPPER(6);
238
+ WRAPPER(7);
239
+ WRAPPER(8);
240
+ WRAPPER(9);
241
+ WRAPPER(10);
242
+ WRAPPER(11);
243
+ WRAPPER(12);
244
+ WRAPPER(13);
245
+ WRAPPER(14);
246
+ WRAPPER(15);
@@ -0,0 +1,94 @@
1
+ //========================================================================
2
+ // GLFW - An OpenGL framework
3
+ // File: dos_joystick.c
4
+ // Platform: DOS
5
+ // API version: 2.6
6
+ // WWW: http://glfw.sourceforge.net
7
+ //------------------------------------------------------------------------
8
+ // Copyright (c) 2002-2006 Camilla Berglund
9
+ //
10
+ // This software is provided 'as-is', without any express or implied
11
+ // warranty. In no event will the authors be held liable for any damages
12
+ // arising from the use of this software.
13
+ //
14
+ // Permission is granted to anyone to use this software for any purpose,
15
+ // including commercial applications, and to alter it and redistribute it
16
+ // freely, subject to the following restrictions:
17
+ //
18
+ // 1. The origin of this software must not be misrepresented; you must not
19
+ // claim that you wrote the original software. If you use this software
20
+ // in a product, an acknowledgment in the product documentation would
21
+ // be appreciated but is not required.
22
+ //
23
+ // 2. Altered source versions must be plainly marked as such, and must not
24
+ // be misrepresented as being the original software.
25
+ //
26
+ // 3. This notice may not be removed or altered from any source
27
+ // distribution.
28
+ //
29
+ //========================================================================
30
+
31
+ #include "internal.h"
32
+
33
+
34
+ //************************************************************************
35
+ //**** GLFW internal functions ****
36
+ //************************************************************************
37
+
38
+ //========================================================================
39
+ // _glfwInitJoysticks() - Initialize joystick interface
40
+ //========================================================================
41
+
42
+ void _glfwInitJoysticks( void )
43
+ {
44
+ // TODO
45
+ }
46
+
47
+
48
+ //========================================================================
49
+ // _glfwTerminateJoysticks() - Close all opened joystick handles
50
+ //========================================================================
51
+
52
+ void _glfwTerminateJoysticks( void )
53
+ {
54
+ // TODO
55
+ }
56
+
57
+
58
+
59
+ //************************************************************************
60
+ //**** Platform implementation functions ****
61
+ //************************************************************************
62
+
63
+ //========================================================================
64
+ // _glfwPlatformGetJoystickParam() - Determine joystick capabilities
65
+ //========================================================================
66
+
67
+ int _glfwPlatformGetJoystickParam( int joy, int param )
68
+ {
69
+ // TODO
70
+ return 0;
71
+ }
72
+
73
+
74
+ //========================================================================
75
+ // _glfwPlatformGetJoystickPos() - Get joystick axis positions
76
+ //========================================================================
77
+
78
+ int _glfwPlatformGetJoystickPos( int joy, float *pos, int numaxes )
79
+ {
80
+ // TODO
81
+ return 0;
82
+ }
83
+
84
+
85
+ //========================================================================
86
+ // _glfwPlatformGetJoystickButtons() - Get joystick button states
87
+ //========================================================================
88
+
89
+ int _glfwPlatformGetJoystickButtons( int joy, unsigned char *buttons,
90
+ int numbuttons )
91
+ {
92
+ // TODO
93
+ return 0;
94
+ }
@@ -0,0 +1,694 @@
1
+ //========================================================================
2
+ // GLFW - An OpenGL framework
3
+ // File: dos_keyboard.c
4
+ // Platform: DOS
5
+ // API version: 2.6
6
+ // WWW: http://glfw.sourceforge.net
7
+ //------------------------------------------------------------------------
8
+ // Copyright (c) 2002-2006 Camilla Berglund
9
+ //
10
+ // This software is provided 'as-is', without any express or implied
11
+ // warranty. In no event will the authors be held liable for any damages
12
+ // arising from the use of this software.
13
+ //
14
+ // Permission is granted to anyone to use this software for any purpose,
15
+ // including commercial applications, and to alter it and redistribute it
16
+ // freely, subject to the following restrictions:
17
+ //
18
+ // 1. The origin of this software must not be misrepresented; you must not
19
+ // claim that you wrote the original software. If you use this software
20
+ // in a product, an acknowledgment in the product documentation would
21
+ // be appreciated but is not required.
22
+ //
23
+ // 2. Altered source versions must be plainly marked as such, and must not
24
+ // be misrepresented as being the original software.
25
+ //
26
+ // 3. This notice may not be removed or altered from any source
27
+ // distribution.
28
+ //
29
+ //========================================================================
30
+
31
+ #include "internal.h"
32
+
33
+
34
+ //========================================================================
35
+ // Most of the code in this source file is based on two sources of
36
+ // information:
37
+ // 1) The Allegro DOS keyboard driver (allegro\src\dos\dkeybd.c)
38
+ // 2) The document "IBM PC KEYBOARD INFORMATION FOR SOFTWARE DEVELOPERS"
39
+ // by Chris Giese.
40
+ //========================================================================
41
+
42
+ //========================================================================
43
+ // Unicode in GLFW for DOS
44
+ // =======================
45
+ //
46
+ // Keyboard mapping tables in GLFW for DOS use Unicode encoding. The codes
47
+ // are 16-bit unsigned integers, and thus do not cover the entire Unicode
48
+ // standard (but a great deal is covered).
49
+ //
50
+ // Keys or characters that are not supported by GLFW (for instance the
51
+ // PrtScr or Windows keys that are found on most PC keyboards) are coded
52
+ // with 0xFFFF ("not a character" according to the Unicode standard).
53
+ //
54
+ // GLFW special keys, as defined in glfw.h (e.g. GLFW_KEY_LSHIFT) are
55
+ // encoded in the private area of the Unicode standard (i.e. codes in the
56
+ // range E000-F8FF). The encoding is as follows:
57
+ //
58
+ // unicode = 0xE000 + glfw_key - GLFW_KEY_SPECIAL;
59
+ //
60
+ // Every key in the keyboard matrix has a description consisting of four
61
+ // entries: Normal, Shift, Caps, and AltGr.
62
+ //========================================================================
63
+
64
+ //========================================================================
65
+ // Definitions
66
+ //========================================================================
67
+
68
+ // Keyboard interrupt number
69
+ #define KEYB_IRQ 1
70
+
71
+ // Qualifier flags
72
+ #define QUAL_SCROLOCK 0x0001 // Same bits as for controller cmd 0xED
73
+ #define QUAL_NUMLOCK 0x0002 // (set leds)
74
+ #define QUAL_CAPSLOCK 0x0004 // --"--
75
+ #define QUAL_LSHIFT 0x0008
76
+ #define QUAL_RSHIFT 0x0010
77
+ #define QUAL_LALT 0x0020
78
+ #define QUAL_RALT 0x0040
79
+ #define QUAL_LCTRL 0x0080
80
+ #define QUAL_RCTRL 0x0100
81
+
82
+ // Qualifier groups
83
+ #define QUAL_MODIFIERS (QUAL_LSHIFT|QUAL_RSHIFT|QUAL_LALT|QUAL_RALT|\
84
+ QUAL_LCTRL|QUAL_RCTRL)
85
+ #define QUAL_LEDS (QUAL_SCROLOCK|QUAL_NUMLOCK|QUAL_CAPSLOCK)
86
+
87
+
88
+ // Additional non-GLFW keys, defined here for internal processing only
89
+ #define GLFW_KEY_CAPSLOCK (GLFW_KEY_SPECIAL+0x0200)
90
+ #define GLFW_KEY_NUMLOCK (GLFW_KEY_SPECIAL+0x0201)
91
+ #define GLFW_KEY_SCROLOCK (GLFW_KEY_SPECIAL+0x0202)
92
+ #define GLFW_KEY_PAUSE (GLFW_KEY_SPECIAL+0x0203)
93
+
94
+ // Keymap entry definition
95
+ struct key {
96
+ unsigned short Normal, Caps, Shift, AltGr;
97
+ };
98
+
99
+ // Keymap entry macros
100
+ #define NOCHAR(x) {x+0xDF00,x+0xDF00,x+0xDF00,x+0xDF00}
101
+ #define UNDEFINED {0xFFFF,0xFFFF,0xFFFF,0xFFFF}
102
+
103
+
104
+ //========================================================================
105
+ // Global variables
106
+ //========================================================================
107
+
108
+ static struct {
109
+ int volatile KeyEnhanced, KeyPauseLoop, Qualifiers;
110
+ int LedsOK;
111
+ int Interrupt;
112
+ } _glfwKeyDrv;
113
+
114
+ static int _glfwKeyboardInstalled = 0;
115
+
116
+
117
+
118
+ //========================================================================
119
+ // scancode_to_key_us[] - Mapping table for US keyboard layout (XT)
120
+ //========================================================================
121
+
122
+ static struct key scancode_to_key_us[256] =
123
+ {
124
+ /* Standard hardware scancodes */
125
+ /* 0x00 */ UNDEFINED, NOCHAR(GLFW_KEY_ESC),
126
+ /* 0x02 */ {'1','1','!',0xFFFF}, {'2','2','@',0xFFFF},
127
+ /* 0x04 */ {'3','3','#',0xFFFF}, {'4','4','$',0xFFFF},
128
+ /* 0x06 */ {'5','5','%',0xFFFF}, {'6','6','^',0xFFFF},
129
+ /* 0x08 */ {'7','7','&',0xFFFF}, {'8','8','*',0xFFFF},
130
+ /* 0x0A */ {'9','9','(',0xFFFF}, {'0','0',')',0xFFFF},
131
+ /* 0x0C */ {'-','-','_',0xFFFF}, {'=','=','+',0xFFFF},
132
+ /* 0x0E */ NOCHAR(GLFW_KEY_BACKSPACE), NOCHAR(GLFW_KEY_TAB),
133
+ /* 0x10 */ {'q','Q','Q',0xFFFF}, {'w','W','W',0xFFFF},
134
+ /* 0x12 */ {'e','E','E',0xFFFF}, {'r','R','R',0xFFFF},
135
+ /* 0x14 */ {'t','T','T',0xFFFF}, {'y','Y','Y',0xFFFF},
136
+ /* 0x16 */ {'u','U','U',0xFFFF}, {'i','I','I',0xFFFF},
137
+ /* 0x18 */ {'o','O','O',0xFFFF}, {'p','P','P',0xFFFF},
138
+ /* 0x1A */ {'[','[','{',0xFFFF}, {']',']','}',0xFFFF},
139
+ /* 0x1C */ NOCHAR(GLFW_KEY_ENTER), NOCHAR(GLFW_KEY_LCTRL),
140
+ /* 0x1E */ {'a','A','A',0xFFFF}, {'s','S','S',0xFFFF},
141
+ /* 0x20 */ {'d','D','D',0xFFFF}, {'f','F','F',0xFFFF},
142
+ /* 0x22 */ {'g','G','G',0xFFFF}, {'h','H','H',0xFFFF},
143
+ /* 0x24 */ {'j','J','J',0xFFFF}, {'k','K','K',0xFFFF},
144
+ /* 0x26 */ {'l','L','L',0xFFFF}, {';',';',':',0xFFFF},
145
+ /* 0x28 */ {'\'','\'','"',0xFFFF}, {'\\','\\','|',0xFFFF},
146
+ /* 0x2A */ NOCHAR(GLFW_KEY_LSHIFT), {'\\','\\','|',0xFFFF},
147
+ /* 0x2C */ {'z','Z','Z',0xFFFF}, {'x','X','X',0xFFFF},
148
+ /* 0x2E */ {'c','C','C',0xFFFF}, {'v','V','V',0xFFFF},
149
+ /* 0x30 */ {'b','B','B',0xFFFF}, {'n','N','N',0xFFFF},
150
+ /* 0x32 */ {'m','M','M',0xFFFF}, {',',',','<',0xFFFF},
151
+ /* 0x34 */ {'.','.','>',0xFFFF}, {'/','/','?',0xFFFF},
152
+ /* 0x36 */ NOCHAR(GLFW_KEY_RSHIFT), NOCHAR(GLFW_KEY_KP_MULTIPLY),
153
+ /* 0x38 */ NOCHAR(GLFW_KEY_LALT), {' ',' ',' ',0xFFFF},
154
+ /* 0x3A */ NOCHAR(GLFW_KEY_CAPSLOCK), NOCHAR(GLFW_KEY_F1),
155
+ /* 0x3C */ NOCHAR(GLFW_KEY_F2), NOCHAR(GLFW_KEY_F3),
156
+ /* 0x3E */ NOCHAR(GLFW_KEY_F4), NOCHAR(GLFW_KEY_F5),
157
+ /* 0x40 */ NOCHAR(GLFW_KEY_F6), NOCHAR(GLFW_KEY_F7),
158
+ /* 0x42 */ NOCHAR(GLFW_KEY_F8), NOCHAR(GLFW_KEY_F9),
159
+ /* 0x44 */ NOCHAR(GLFW_KEY_F10), NOCHAR(GLFW_KEY_NUMLOCK),
160
+ /* 0x46 */ NOCHAR(GLFW_KEY_SCROLOCK), NOCHAR(GLFW_KEY_KP_7),
161
+ /* 0x48 */ NOCHAR(GLFW_KEY_KP_8), NOCHAR(GLFW_KEY_KP_9),
162
+ /* 0x4A */ NOCHAR(GLFW_KEY_KP_SUBTRACT), NOCHAR(GLFW_KEY_KP_4),
163
+ /* 0x4C */ NOCHAR(GLFW_KEY_KP_5), NOCHAR(GLFW_KEY_KP_6),
164
+ /* 0x4E */ NOCHAR(GLFW_KEY_KP_ADD), NOCHAR(GLFW_KEY_KP_1),
165
+ /* 0x50 */ NOCHAR(GLFW_KEY_KP_2), NOCHAR(GLFW_KEY_KP_3),
166
+ /* 0x52 */ NOCHAR(GLFW_KEY_KP_0), NOCHAR(GLFW_KEY_KP_DECIMAL),
167
+ /* 0x54 */ UNDEFINED, /* PRTSCR */ UNDEFINED,
168
+ /* 0x56 */ {'\\','\\','|',0xFFFF}, NOCHAR(GLFW_KEY_F11),
169
+ /* 0x58 */ NOCHAR(GLFW_KEY_F12), UNDEFINED,
170
+ /* 0x5A */ UNDEFINED, UNDEFINED, /* LWIN */
171
+ /* 0x5C */ UNDEFINED, /* RWIN */ UNDEFINED, /* MENU */
172
+ /* 0x5E */ UNDEFINED, UNDEFINED,
173
+ /* 0x60 */ UNDEFINED, UNDEFINED,
174
+ /* 0x62 */ UNDEFINED, UNDEFINED,
175
+ /* 0x64 */ UNDEFINED, UNDEFINED,
176
+ /* 0x66 */ UNDEFINED, UNDEFINED,
177
+ /* 0x68 */ UNDEFINED, UNDEFINED,
178
+ /* 0x6A */ UNDEFINED, UNDEFINED,
179
+ /* 0x6C */ UNDEFINED, UNDEFINED,
180
+ /* 0x6E */ UNDEFINED, UNDEFINED,
181
+ /* 0x70 */ UNDEFINED, /* KANA */ UNDEFINED,
182
+ /* 0x72 */ UNDEFINED, UNDEFINED, /* ABNT_C1 */
183
+ /* 0x74 */ UNDEFINED, UNDEFINED,
184
+ /* 0x76 */ UNDEFINED, UNDEFINED,
185
+ /* 0x78 */ UNDEFINED, UNDEFINED, /* CONVERT */
186
+ /* 0x7A */ UNDEFINED, UNDEFINED, /* NOCONVERT */
187
+ /* 0x7C */ UNDEFINED, UNDEFINED, /* YEN */
188
+ /* 0x7E */ UNDEFINED, UNDEFINED,
189
+
190
+ /* Extended hardware scancodes (index=scancode+0x80) */
191
+ /* 0xE000 */ UNDEFINED, NOCHAR(GLFW_KEY_ESC),
192
+ /* 0xE002 */ {'1','1','!',0xFFFF}, {'2','2','@',0xFFFF},
193
+ /* 0xE004 */ {'3','3','#',0xFFFF}, {'4','4','$',0xFFFF},
194
+ /* 0xE006 */ {'5','5','%',0xFFFF}, {'6','6','^',0xFFFF},
195
+ /* 0xE008 */ {'7','7','&',0xFFFF}, {'8','8','*',0xFFFF},
196
+ /* 0xE00A */ {'9','9','(',0xFFFF}, {'0','0',')',0xFFFF},
197
+ /* 0xE00C */ {'-','-','_',0xFFFF}, {'=','=','+',0xFFFF},
198
+ /* 0xE00E */ NOCHAR(GLFW_KEY_BACKSPACE), NOCHAR(GLFW_KEY_TAB),
199
+ /* 0xE010 */ UNDEFINED, /* CIRCUMFLEX */ UNDEFINED, /* AT */
200
+ /* 0xE012 */ UNDEFINED, /* COLON2 */ {'r','R','R',0xFFFF},
201
+ /* 0xE014 */ UNDEFINED, /* KANJI */ {'y','Y','Y',0xFFFF},
202
+ /* 0xE016 */ {'u','U','U',0xFFFF}, {'i','I','I',0xFFFF},
203
+ /* 0xE018 */ {'o','O','O',0xFFFF}, {'p','P','P',0xFFFF},
204
+ /* 0xE01A */ {'[','[','{',0xFFFF}, {']',']','}',0xFFFF},
205
+ /* 0xE01C */ NOCHAR(GLFW_KEY_KP_ENTER), NOCHAR(GLFW_KEY_RCTRL),
206
+ /* 0xE01E */ {'a','A','A',0xFFFF}, {'s','S','S',0xFFFF},
207
+ /* 0xE020 */ {'d','D','D',0xFFFF}, {'f','F','F',0xFFFF},
208
+ /* 0xE022 */ {'g','G','G',0xFFFF}, {'h','H','H',0xFFFF},
209
+ /* 0xE024 */ {'j','J','J',0xFFFF}, {'k','K','K',0xFFFF},
210
+ /* 0xE026 */ {'l','L','L',0xFFFF}, {';',';',':',0xFFFF},
211
+ /* 0xE028 */ {'\'','\'','"',0xFFFF}, {'`','`','~',0xFFFF},
212
+ /* 0xE02A */ UNDEFINED, {'\\','\\','|',0xFFFF},
213
+ /* 0xE02C */ {'z','Z','Z',0xFFFF}, {'x','X','X',0xFFFF},
214
+ /* 0xE02E */ {'c','C','C',0xFFFF}, {'v','V','V',0xFFFF},
215
+ /* 0xE030 */ {'b','B','B',0xFFFF}, {'n','N','N',0xFFFF},
216
+ /* 0xE032 */ {'m','M','M',0xFFFF}, {',',',','<',0xFFFF},
217
+ /* 0xE034 */ {'.','.','>',0xFFFF}, NOCHAR(GLFW_KEY_KP_DIVIDE),
218
+ /* 0xE036 */ UNDEFINED, UNDEFINED, /* PRTSCR */
219
+ /* 0xE038 */ NOCHAR(GLFW_KEY_RALT), {' ',' ',' ',0xFFFF},
220
+ /* 0xE03A */ NOCHAR(GLFW_KEY_CAPSLOCK), NOCHAR(GLFW_KEY_F1),
221
+ /* 0xE03C */ NOCHAR(GLFW_KEY_F2), NOCHAR(GLFW_KEY_F3),
222
+ /* 0xE03E */ NOCHAR(GLFW_KEY_F4), NOCHAR(GLFW_KEY_F5),
223
+ /* 0xE040 */ NOCHAR(GLFW_KEY_F6), NOCHAR(GLFW_KEY_F7),
224
+ /* 0xE042 */ NOCHAR(GLFW_KEY_F8), NOCHAR(GLFW_KEY_F9),
225
+ /* 0xE044 */ NOCHAR(GLFW_KEY_F10), NOCHAR(GLFW_KEY_NUMLOCK),
226
+ /* 0xE046 */ NOCHAR(GLFW_KEY_PAUSE), NOCHAR(GLFW_KEY_HOME),
227
+ /* 0xE048 */ NOCHAR(GLFW_KEY_UP), NOCHAR(GLFW_KEY_PAGEUP),
228
+ /* 0xE04A */ NOCHAR(GLFW_KEY_KP_SUBTRACT), NOCHAR(GLFW_KEY_LEFT),
229
+ /* 0xE04C */ NOCHAR(GLFW_KEY_KP_5), NOCHAR(GLFW_KEY_RIGHT),
230
+ /* 0xE04E */ NOCHAR(GLFW_KEY_KP_ADD), NOCHAR(GLFW_KEY_END),
231
+ /* 0xE050 */ NOCHAR(GLFW_KEY_DOWN), NOCHAR(GLFW_KEY_PAGEDOWN),
232
+ /* 0xE052 */ NOCHAR(GLFW_KEY_INSERT), NOCHAR(GLFW_KEY_DEL),
233
+ /* 0xE054 */ UNDEFINED, /* PRTSCR */ UNDEFINED,
234
+ /* 0xE056 */ {'\\','\\','|',0xFFFF}, NOCHAR(GLFW_KEY_F11),
235
+ /* 0xE058 */ NOCHAR(GLFW_KEY_F12), UNDEFINED,
236
+ /* 0xE05A */ UNDEFINED, UNDEFINED, /* LWIN */
237
+ /* 0xE05C */ UNDEFINED, /* RWIN */ UNDEFINED, /* MENU */
238
+ /* 0xE05E */ UNDEFINED, UNDEFINED,
239
+ /* 0xE060 */ UNDEFINED, UNDEFINED,
240
+ /* 0xE062 */ UNDEFINED, UNDEFINED,
241
+ /* 0xE064 */ UNDEFINED, UNDEFINED,
242
+ /* 0xE066 */ UNDEFINED, UNDEFINED,
243
+ /* 0xE068 */ UNDEFINED, UNDEFINED,
244
+ /* 0xE06A */ UNDEFINED, UNDEFINED,
245
+ /* 0xE06C */ UNDEFINED, UNDEFINED,
246
+ /* 0xE06E */ UNDEFINED, UNDEFINED,
247
+ /* 0xE070 */ UNDEFINED, UNDEFINED,
248
+ /* 0xE072 */ UNDEFINED, UNDEFINED,
249
+ /* 0xE074 */ UNDEFINED, UNDEFINED,
250
+ /* 0xE076 */ UNDEFINED, UNDEFINED,
251
+ /* 0xE078 */ UNDEFINED, UNDEFINED,
252
+ /* 0xE07A */ UNDEFINED, UNDEFINED,
253
+ /* 0xE07C */ UNDEFINED, UNDEFINED,
254
+ /* 0xE07E */ UNDEFINED, UNDEFINED
255
+ };
256
+
257
+
258
+
259
+ //************************************************************************
260
+ //**** Keyboard Decoding *************************************************
261
+ //************************************************************************
262
+
263
+ //========================================================================
264
+ // _glfwMapRawKey() - Map a raw scancode to a Unicode character
265
+ //========================================================================
266
+
267
+ static int _glfwMapRawKey( int scancode, int qualifiers )
268
+ {
269
+ struct key *keyvals;
270
+ int keycode;
271
+
272
+ // Get possible key codings for this scancode
273
+ keyvals = &scancode_to_key_us[ scancode ];
274
+
275
+ // Select Unicode code depending on qualifiers
276
+ if( qualifiers & QUAL_RALT )
277
+ {
278
+ keycode = keyvals->AltGr;
279
+ }
280
+ else if( qualifiers & (QUAL_LSHIFT|QUAL_RSHIFT) )
281
+ {
282
+ if( (qualifiers & QUAL_CAPSLOCK) &&
283
+ (keyvals->Normal != keyvals->Caps) )
284
+ {
285
+ keycode = keyvals->Normal;
286
+ }
287
+ else
288
+ {
289
+ keycode = keyvals->Shift;
290
+ }
291
+ }
292
+ else if( qualifiers & QUAL_CAPSLOCK )
293
+ {
294
+ keycode = keyvals->Caps;
295
+ }
296
+ else
297
+ {
298
+ keycode = keyvals->Normal;
299
+ }
300
+
301
+ // Special interpretations
302
+ if( keycode >= 0xE000 && keycode <= 0xE8FF )
303
+ {
304
+ keycode = -(keycode - 0xE000 + GLFW_KEY_SPECIAL);
305
+ }
306
+ else if( keycode == 0xFFFF )
307
+ {
308
+ keycode = 0;
309
+ }
310
+
311
+ return keycode;
312
+ } ENDOFUNC(_glfwMapRawKey)
313
+
314
+
315
+ //========================================================================
316
+ // _glfwCreateKeyEvent() - Add a keyboard event to the event FIFO
317
+ //========================================================================
318
+
319
+ static void _glfwCreateKeyEvent( int scancode, int qualifiers, int action )
320
+ {
321
+ _GLFWdosevent event;
322
+ struct key_event *key = &event.Key;
323
+
324
+ // Create event
325
+ key->Type = _GLFW_DOS_KEY_EVENT;
326
+ key->Key = _glfwMapRawKey( scancode, qualifiers );
327
+ key->KeyNoMod = _glfwMapRawKey( scancode, QUAL_CAPSLOCK );
328
+ key->Action = action;
329
+
330
+ // Post event
331
+ _glfwPostDOSEvent( &event );
332
+ } ENDOFUNC(_glfwCreateKeyEvent)
333
+
334
+
335
+
336
+ //************************************************************************
337
+ //**** Keyboard Communication ********************************************
338
+ //************************************************************************
339
+
340
+ //========================================================================
341
+ // _glfwWaitForReadReady() / _glfwWaitForWriteReady()
342
+ // Wait for the keyboard controller to set the ready-for-read/write bit
343
+ //========================================================================
344
+
345
+ static int _glfwWaitForReadReady( void )
346
+ {
347
+ int timeout = 16384;
348
+ while( (timeout>0) && (!(inportb(0x64)&1)) ) timeout--;
349
+ return timeout > 0;
350
+ } ENDOFUNC(_glfwWaitForReadReady)
351
+
352
+ static int _glfwWaitForWriteReady( void )
353
+ {
354
+ int timeout = 4096;
355
+ while( (timeout>0) && (inportb(0x64)&2) ) timeout--;
356
+ return timeout > 0;
357
+ } ENDOFUNC(_glfwWaitForWriteReady)
358
+
359
+
360
+ //========================================================================
361
+ // _glfwSendKeyboardByte() - Send a byte to the keyboard controller
362
+ //========================================================================
363
+
364
+ static int _glfwSendKeyboardByte( unsigned char data )
365
+ {
366
+ int resends = 4;
367
+ int timeout, ret;
368
+
369
+ do
370
+ {
371
+ if( !_glfwWaitForWriteReady() ) return 0;
372
+
373
+ outportb( 0x60, data );
374
+
375
+ timeout = 4096;
376
+ while( --timeout > 0 )
377
+ {
378
+ if( !_glfwWaitForReadReady() ) return 0;
379
+
380
+ ret = inportb( 0x60 );
381
+ if( ret == 0xFA ) return 1;
382
+ if( ret == 0xFE ) break;
383
+ }
384
+ }
385
+ while( (resends-- > 0) && (timeout > 0) );
386
+
387
+ return 0;
388
+ } ENDOFUNC(_glfwSendKeyboardByte)
389
+
390
+
391
+ //========================================================================
392
+ // _glfwSendKeyboardCommand() - Send a command sequence to the keyboard
393
+ //========================================================================
394
+
395
+ static int _glfwSendKeyboardCommand( unsigned char *cmd, int count )
396
+ {
397
+ int i, ok = 1;
398
+
399
+ // Force atomic keyboard communication session
400
+ if( !_glfwKeyDrv.Interrupt ) DISABLE();
401
+
402
+ // Send command sequence
403
+ for( i = 0; i < count; ++ i )
404
+ {
405
+ if( !_glfwSendKeyboardByte( cmd[i] ) )
406
+ {
407
+ ok = 0;
408
+ break;
409
+ }
410
+ }
411
+
412
+ // Send "clear output buffer, enable keyboard"
413
+ _glfwSendKeyboardByte( 0xF4 );
414
+
415
+ if( !_glfwKeyDrv.Interrupt ) ENABLE();
416
+
417
+ return ok;
418
+ } ENDOFUNC(_glfwSendKeyboardCommand)
419
+
420
+
421
+
422
+ //************************************************************************
423
+ //**** Miscellaneous Handling ********************************************
424
+ //************************************************************************
425
+
426
+ //========================================================================
427
+ // _glfwUpdateLeds() - Update keyboard leds
428
+ //========================================================================
429
+
430
+ static void _glfwUpdateLeds( int qualifiers )
431
+ {
432
+ unsigned char cmd[2];
433
+ cmd[0] = 0xED;
434
+ cmd[1] = qualifiers & 7;
435
+ _glfwSendKeyboardCommand( cmd, 2 );
436
+ } ENDOFUNC(_glfwUpdateLeds)
437
+
438
+
439
+
440
+ //************************************************************************
441
+ //**** Keyboard Interrupt Handler ****************************************
442
+ //************************************************************************
443
+
444
+ //========================================================================
445
+ // _glfwHandleCode() - Handle new scancode event
446
+ //========================================================================
447
+
448
+ static void _glfwHandleCode( int scancode, int keypress )
449
+ {
450
+ if( scancode == GLFW_KEY_PAUSE && keypress )
451
+ {
452
+ // Pause
453
+ _glfwCreateKeyEvent( GLFW_KEY_PAUSE, 0, GLFW_PRESS );
454
+ }
455
+ else if( scancode )
456
+ {
457
+ int tmp, qualifier;
458
+
459
+ // Check if this is a qualifier key
460
+ tmp = scancode_to_key_us[scancode].Normal;
461
+ tmp += GLFW_KEY_SPECIAL - 0xE000;
462
+ if( tmp == GLFW_KEY_LSHIFT ) qualifier = QUAL_LSHIFT;
463
+ else if( tmp == GLFW_KEY_RSHIFT ) qualifier = QUAL_RSHIFT;
464
+ else if( tmp == GLFW_KEY_LCTRL ) qualifier = QUAL_LCTRL;
465
+ else if( tmp == GLFW_KEY_RCTRL ) qualifier = QUAL_RCTRL;
466
+ else if( tmp == GLFW_KEY_LALT ) qualifier = QUAL_LALT;
467
+ else if( tmp == GLFW_KEY_RALT ) qualifier = QUAL_RALT;
468
+ else if( tmp == GLFW_KEY_NUMLOCK ) qualifier = QUAL_NUMLOCK;
469
+ else if( tmp == GLFW_KEY_SCROLOCK ) qualifier = QUAL_SCROLOCK;
470
+ else if( tmp == GLFW_KEY_CAPSLOCK ) qualifier = QUAL_CAPSLOCK;
471
+ else qualifier = 0;
472
+
473
+ if( keypress )
474
+ {
475
+ // Key press
476
+ if( qualifier & QUAL_MODIFIERS )
477
+ {
478
+ _glfwKeyDrv.Qualifiers |= qualifier;
479
+ }
480
+ if( !(qualifier & QUAL_LEDS) )
481
+ {
482
+ _glfwCreateKeyEvent( scancode, _glfwKeyDrv.Qualifiers,
483
+ GLFW_PRESS );
484
+ }
485
+ else
486
+ {
487
+ _glfwKeyDrv.Qualifiers ^= qualifier;
488
+ _glfwUpdateLeds( _glfwKeyDrv.Qualifiers );
489
+ }
490
+ }
491
+ else
492
+ {
493
+ // Key release
494
+ if( qualifier & QUAL_MODIFIERS )
495
+ {
496
+ _glfwKeyDrv.Qualifiers &= ~qualifier;
497
+ }
498
+ if( !(qualifier & QUAL_LEDS) )
499
+ {
500
+ _glfwCreateKeyEvent( scancode, _glfwKeyDrv.Qualifiers,
501
+ GLFW_RELEASE );
502
+ }
503
+ }
504
+ }
505
+ } ENDOFUNC(_glfwHandleCode)
506
+
507
+
508
+ //========================================================================
509
+ // _glfwKeyInterrupt() - Keyboard interrupt routine
510
+ //========================================================================
511
+
512
+ static int _glfwKeyInterrupt( void )
513
+ {
514
+ unsigned char keycode, scancode;
515
+
516
+ _glfwKeyDrv.Interrupt ++;
517
+
518
+ keycode = inportb( 0x60 );
519
+
520
+ if( keycode <= 0xE1 )
521
+ {
522
+ if( _glfwKeyDrv.KeyPauseLoop )
523
+ {
524
+ if( ! --_glfwKeyDrv.KeyPauseLoop )
525
+ _glfwHandleCode( GLFW_KEY_PAUSE, 1 );
526
+ }
527
+ else
528
+ {
529
+ switch( keycode )
530
+ {
531
+ case 0xE0:
532
+ _glfwKeyDrv.KeyEnhanced = 1;
533
+ break;
534
+ case 0xE1:
535
+ _glfwKeyDrv.KeyPauseLoop = 5;
536
+ break;
537
+ default:
538
+ scancode = keycode & 0x7F;
539
+ if( _glfwKeyDrv.KeyEnhanced )
540
+ {
541
+ scancode |= 0x80;
542
+ _glfwKeyDrv.KeyEnhanced = 0;
543
+ }
544
+ _glfwHandleCode( scancode, !(keycode & 0x80) );
545
+ }
546
+ }
547
+ }
548
+
549
+ _glfwKeyDrv.Interrupt --;
550
+
551
+ if( ((keycode==0x4F) || (keycode==0x53)) &&
552
+ (_glfwKeyDrv.Qualifiers & QUAL_LCTRL) &&
553
+ (_glfwKeyDrv.Qualifiers & QUAL_RALT) )
554
+ {
555
+ // Hack alert:
556
+ // Only SIGINT (but not Ctrl-Break) calls the destructors and will
557
+ // safely clean up
558
+ asm(
559
+ "movb $0x79,%%al\n\t"
560
+ "call ___djgpp_hw_exception\n\t"
561
+ :
562
+ :
563
+ : "%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory"
564
+ );
565
+ }
566
+
567
+ asm(
568
+ "inb $0x61,%%al\n\t"
569
+ "movb %%al,%%ah\n\t"
570
+ "orb $0x80,%%al\n\t"
571
+ "outb %%al,$0x61\n\t"
572
+ "xchgb %%al,%%ah\n\t"
573
+ "outb %%al,$0x61\n\t"
574
+ "movb $0x20,%%al\n\t"
575
+ "outb %%al,$0x20\n\t"
576
+ :
577
+ :
578
+ : "%eax"
579
+ );
580
+
581
+ return 0;
582
+ } ENDOFUNC(_glfwKeyInterrupt)
583
+
584
+
585
+
586
+ //************************************************************************
587
+ //**** Keyboard driver interface functions ****
588
+ //************************************************************************
589
+
590
+ //========================================================================
591
+ // _glfwInitKeyboard() - Initialize keyboard driver
592
+ //========================================================================
593
+
594
+ int _glfwInitKeyboard( void )
595
+ {
596
+ int s1, s2, s3;
597
+
598
+ if( _glfwKeyboardInstalled )
599
+ {
600
+ return 0;
601
+ }
602
+
603
+ // Init keyboard state
604
+ _glfwKeyDrv.LedsOK = 1;
605
+ _glfwKeyDrv.Interrupt = 0;
606
+ _glfwKeyDrv.KeyEnhanced = 0;
607
+ _glfwKeyDrv.KeyPauseLoop = 0;
608
+
609
+ // Lock data buffers
610
+ LOCKDATA(_glfwKeyboardInstalled);
611
+ LOCKDATA(_glfwKeyDrv);
612
+ LOCKDATA(scancode_to_key_us);
613
+
614
+ // Lock functions
615
+ LOCKFUNC(_glfwMapRawKey);
616
+ LOCKFUNC(_glfwCreateKeyEvent);
617
+ LOCKFUNC(_glfwWaitForReadReady);
618
+ LOCKFUNC(_glfwWaitForWriteReady);
619
+ LOCKFUNC(_glfwSendKeyboardByte);
620
+ LOCKFUNC(_glfwSendKeyboardCommand);
621
+ LOCKFUNC(_glfwUpdateLeds);
622
+ LOCKFUNC(_glfwHandleCode);
623
+ LOCKFUNC(_glfwKeyInterrupt);
624
+
625
+ _farsetsel( __djgpp_dos_sel );
626
+ _farnspokew( 0x41c, _farnspeekw(0x41a) );
627
+
628
+ // Get current state of key qualifiers
629
+ s1 = _farnspeekb( 0x417 );
630
+ s2 = _farnspeekb( 0x418 );
631
+ s3 = _farnspeekb( 0x496 );
632
+ _glfwKeyDrv.Qualifiers = 0;
633
+ if( s1 & 1 ) _glfwKeyDrv.Qualifiers |= QUAL_RSHIFT;
634
+ if( s1 & 2 ) _glfwKeyDrv.Qualifiers |= QUAL_LSHIFT;
635
+ if( s2 & 1 ) _glfwKeyDrv.Qualifiers |= QUAL_LCTRL;
636
+ if( s2 & 2 ) _glfwKeyDrv.Qualifiers |= QUAL_LALT;
637
+ if( s3 & 4 ) _glfwKeyDrv.Qualifiers |= QUAL_RCTRL;
638
+ if( s3 & 8 ) _glfwKeyDrv.Qualifiers |= QUAL_RALT;
639
+ if( s1 & 16 ) _glfwKeyDrv.Qualifiers |= QUAL_SCROLOCK;
640
+ if( s1 & 32 ) _glfwKeyDrv.Qualifiers |= QUAL_NUMLOCK;
641
+ if( s1 & 64 ) _glfwKeyDrv.Qualifiers |= QUAL_CAPSLOCK;
642
+ _glfwUpdateLeds( _glfwKeyDrv.Qualifiers );
643
+
644
+ // Install keyboard interrupt handler
645
+ if( _glfwInstallDOSIrq( KEYB_IRQ, _glfwKeyInterrupt ) )
646
+ {
647
+ return 0;
648
+ }
649
+
650
+ _glfwKeyboardInstalled = 1;
651
+
652
+ return 1;
653
+ }
654
+
655
+
656
+ //========================================================================
657
+ // _glfwTerminateKeyboard() - Terminate keyboard driver
658
+ //========================================================================
659
+
660
+ void _glfwTerminateKeyboard( void )
661
+ {
662
+ int s1, s2, s3;
663
+
664
+ if( !_glfwKeyboardInstalled )
665
+ {
666
+ return;
667
+ }
668
+
669
+ _glfwKeyboardInstalled = 0;
670
+
671
+ // Uninstall keyboard interrupt handler
672
+ _glfwRemoveDOSIrq( KEYB_IRQ );
673
+
674
+ _farsetsel( __djgpp_dos_sel );
675
+ _farnspokew( 0x41c, _farnspeekw(0x41a) );
676
+
677
+ // Set current state of key qualifiers
678
+ s1 = _farnspeekb( 0x417 ) & 0x80;
679
+ s2 = _farnspeekb( 0x418 ) & 0xFC;
680
+ s3 = _farnspeekb( 0x496 ) & 0xF3;
681
+ if(_glfwKeyDrv.Qualifiers & QUAL_RSHIFT) s1 |= 1;
682
+ if(_glfwKeyDrv.Qualifiers & QUAL_LSHIFT) s1 |= 2;
683
+ if(_glfwKeyDrv.Qualifiers & QUAL_LCTRL) {s2 |= 1; s1 |= 4;}
684
+ if(_glfwKeyDrv.Qualifiers & QUAL_LALT) {s2 |= 2; s1 |= 8;}
685
+ if(_glfwKeyDrv.Qualifiers & QUAL_RCTRL) {s3 |= 4; s1 |= 4;}
686
+ if(_glfwKeyDrv.Qualifiers & QUAL_RALT) {s3 |= 8; s1 |= 8;}
687
+ if(_glfwKeyDrv.Qualifiers & QUAL_SCROLOCK) s1 |= 16;
688
+ if(_glfwKeyDrv.Qualifiers & QUAL_NUMLOCK) s1 |= 32;
689
+ if(_glfwKeyDrv.Qualifiers & QUAL_CAPSLOCK) s1 |= 64;
690
+ _farnspokeb( 0x417, s1 );
691
+ _farnspokeb( 0x418, s2 );
692
+ _farnspokeb( 0x496, s3 );
693
+ _glfwUpdateLeds( _glfwKeyDrv.Qualifiers );
694
+ }