summaryrefslogtreecommitdiff
path: root/sdl2/bindings.scm
blob: cb8dd973eb3baa0ca4381a7f29c85de5caedf0e3 (plain)
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
;;; guile-sdl2 --- FFI bindings for SDL2
;;; Copyright © 2015, 2016, 2021 David Thompson <dthompson2@worcester.edu>
;;; Copyright © 2018 Eero Leno <eero@leno.fi>
;;; Copyright © 2019 Pierre-Antoine Rouby <contact@parouby.fr>
;;; Copyright © 2022 Ekaitz Zarraga <ekaitz@elenq.tech>
;;;
;;; This file is part of guile-sdl2.
;;;
;;; Guile-sdl2 is free software; you can redistribute it and/or modify
;;; it under the terms of the GNU Lesser General Public License as
;;; published by the Free Software Foundation; either version 3 of the
;;; License, or (at your option) any later version.
;;;
;;; Guile-sdl2 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
;;; General Public License for more details.
;;;
;;; You should have received a copy of the GNU Lesser General Public
;;; License along with guile-sdl2.  If not, see
;;; <http://www.gnu.org/licenses/>.

;;; Commentary:
;;
;; Low-level FFI bindings.
;;
;;; Code:

(define-module (sdl2 bindings)
  #:use-module (system foreign)
  #:use-module (sdl2 config))

(define sdl-func
  (let ((lib (dynamic-link* %libsdl2)))
    (lambda (return-type function-name arg-types)
      "Return a procedure for the foreign function FUNCTION-NAME in
the SDL2 shared library.  That function must return a value of
RETURN-TYPE and accept arguments of ARG-TYPES."
      (pointer->procedure return-type
                          (dynamic-func function-name lib)
                          arg-types))))

(define-syntax-rule (define-foreign name return-type func-name arg-types)
  (define-public name
    (sdl-func return-type func-name arg-types)))


;;;
;;; Foreign Types
;;;

(define-public sdl-color
  (list uint8 uint8 uint8 uint8))

(define-public sdl-rect
  (list int int int int))

(define-public sdl-point
  (list int int))

(define sdl-bool int)

(define-public (boolean->sdl-bool b)
  "Convert the boolean B to an SDL_bool."
  (if b 1 0))


;;;
;;; Errors
;;;

(define-foreign sdl-get-error
  '* "SDL_GetError" '())


;;;
;;; Initialization
;;;

(define-public SDL_INIT_TIMER          #x00000001)
(define-public SDL_INIT_AUDIO          #x00000010)
(define-public SDL_INIT_VIDEO          #x00000020)
(define-public SDL_INIT_JOYSTICK       #x00000200)
(define-public SDL_INIT_HAPTIC         #x00001000)
(define-public SDL_INIT_GAMECONTROLLER #x00002000)
(define-public SDL_INIT_EVENTS         #x00004000)

(define-foreign sdl-init
  int "SDL_Init" (list uint32))

(define-foreign sdl-quit
  void "SDL_Quit" '())


;;;
;;; Version
;;;

(define-foreign sdl-get-version
  void "SDL_GetVersion" '(*))


;;;
;;; Blend Mode
;;;

(define-public SDL_BLENDMODE_NONE    #x00000000)
(define-public SDL_BLENDMODE_BLEND   #x00000001)
(define-public SDL_BLENDMODE_ADD     #x00000002)
(define-public SDL_BLENDMODE_MOD     #x00000004)
(define-public SDL_BLENDMODE_MUL     #x00000008)
(define-public SDL_BLENDMODE_INVALID #x7fffffff)

(define-public SDL_BLENDOPERATION_ADD          #x1)
(define-public SDL_BLENDOPERATION_SUBTRACT     #x2)
(define-public SDL_BLENDOPERATION_REV_SUBTRACT #x3)
(define-public SDL_BLENDOPERATION_MINIMUM      #x4)
(define-public SDL_BLENDOPERATION_MAXIMUM      #x5)

(define-public SDL_BLENDFACTOR_ZERO                #x1)
(define-public SDL_BLENDFACTOR_ONE                 #x2)
(define-public SDL_BLENDFACTOR_SRC_COLOR           #x3)
(define-public SDL_BLENDFACTOR_ONE_MINUS_SRC_COLOR #x4)
(define-public SDL_BLENDFACTOR_SRC_ALPHA           #x5)
(define-public SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA #x6)
(define-public SDL_BLENDFACTOR_DST_COLOR           #x7)
(define-public SDL_BLENDFACTOR_ONE_MINUS_DST_COLOR #x8)
(define-public SDL_BLENDFACTOR_DST_ALPHA           #x9)
(define-public SDL_BLENDFACTOR_ONE_MINUS_DST_ALPHA #xa)

(define-foreign sdl-compose-custom-blend-mode
  int "SDL_ComposeCustomBlendMode" (list int int int int int int))


;;;
;;; Video
;;;

(define-public SDL_WINDOW_FULLSCREEN         #x00000001)
(define-public SDL_WINDOW_OPENGL             #x00000002)
(define-public SDL_WINDOW_SHOWN              #x00000004)
(define-public SDL_WINDOW_HIDDEN             #x00000008)
(define-public SDL_WINDOW_BORDERLESS         #x00000010)
(define-public SDL_WINDOW_RESIZABLE          #x00000020)
(define-public SDL_WINDOW_MINIMIZED          #x00000040)
(define-public SDL_WINDOW_MAXIMIZED          #x00000080)
(define-public SDL_WINDOW_INPUT_GRABBED      #x00000100)
(define-public SDL_WINDOW_INPUT_FOCUS        #x00000200)
(define-public SDL_WINDOW_MOUSE_FOCUS        #x00000400)
(define-public SDL_WINDOW_FULLSCREEN_DESKTOP (logior SDL_WINDOW_FULLSCREEN
                                              #x00001000))
(define-public SDL_WINDOW_FOREIGN            #x00000800)
(define-public SDL_WINDOW_ALLOW_HIGHDPI      #x00002000)
(define-public SDL_WINDOW_MOUSE_CAPTURE      #x00004000)

(define-public SDL_WINDOWPOS_CENTERED 805240832)
(define-public SDL_WINDOWPOS_UNDEFINED 536805376)

(define-foreign sdl-create-window
  '* "SDL_CreateWindow" (list '* int int int int uint32))

(define-foreign sdl-destroy-window
  void "SDL_DestroyWindow" '(*))

(define-foreign sdl-get-window-title
  '* "SDL_GetWindowTitle" '(*))

(define-foreign sdl-get-window-size
  void "SDL_GetWindowSize" '(* * *))

(define-foreign sdl-get-window-minimum-size
  void "SDL_GetWindowMinimumSize" '(* * *))

(define-foreign sdl-get-window-maximum-size
  void "SDL_GetWindowMaximumSize" '(* * *))

(define-foreign sdl-get-window-position
  void "SDL_GetWindowPosition" '(* * *))

(define-foreign sdl-get-window-id
  uint32 "SDL_GetWindowID" '(*))

(define-foreign sdl-get-window-from-id
  '* "SDL_GetWindowFromID" (list uint32))

(define-foreign sdl-hide-window
  void "SDL_HideWindow" '(*))

(define-foreign sdl-show-window
  void "SDL_ShowWindow" '(*))

(define-foreign sdl-maximize-window
  void "SDL_MaximizeWindow" '(*))

(define-foreign sdl-minimize-window
  void "SDL_MinimizeWindow" '(*))

(define-foreign sdl-raise-window
  void "SDL_RaiseWindow" '(*))

(define-foreign sdl-restore-window
  void "SDL_RestoreWindow" '(*))

(define-foreign sdl-set-window-bordered
  void "SDL_SetWindowBordered" (list '* sdl-bool))

(define-foreign sdl-set-window-title
  void "SDL_SetWindowTitle" '(* *))

(define-foreign sdl-set-window-icon
  void "SDL_SetWindowIcon" (list '* '*))

(define-foreign sdl-set-window-position
  void "SDL_SetWindowPosition" (list '* int int))

(define-foreign sdl-set-window-size
  void "SDL_SetWindowSize" (list '* int int))

(define-foreign sdl-set-window-minimum-size
  void "SDL_SetWindowMinimumSize" (list '* int int))

(define-foreign sdl-set-window-maximum-size
  void "SDL_SetWindowMaximumSize" (list '* int int))

(define-foreign sdl-set-window-resizable
  void "SDL_SetWindowResizable" (list '* sdl-bool))

(define-foreign sdl-set-window-fullscreen
  int "SDL_SetWindowFullscreen" (list '* uint32))

(define-foreign sdl-gl-create-context
  '* "SDL_GL_CreateContext" '(*))

(define-foreign sdl-gl-delete-context
  void "SDL_GL_DeleteContext" '(*))

(define-foreign sdl-gl-swap-window
  void "SDL_GL_SwapWindow" '(*))

(define-public SDL_GL_RED_SIZE 0)
(define-public SDL_GL_GREEN_SIZE 1)
(define-public SDL_GL_BLUE_SIZE 2)
(define-public SDL_GL_ALPHA_SIZE 3)
(define-public SDL_GL_BUFFER_SIZE 4)
(define-public SDL_GL_DOUBLEBUFFER 5)
(define-public SDL_GL_DEPTH_SIZE 6)
(define-public SDL_GL_STENCIL_SIZE 7)
(define-public SDL_GL_ACCUM_RED_SIZE 8)
(define-public SDL_GL_ACCUM_GREEN_SIZE 9)
(define-public SDL_GL_ACCUM_BLUE_SIZE 10)
(define-public SDL_GL_ACCUM_ALPHA_SIZE 11)
(define-public SDL_GL_STEREO 12)
(define-public SDL_GL_MULTISAMPLEBUFFERS 13)
(define-public SDL_GL_MULTISAMPLESAMPLES 14)
(define-public SDL_GL_ACCELERATED_VISUAL 15)
(define-public SDL_GL_RETAINED_BACKING 16)
(define-public SDL_GL_CONTEXT_MAJOR_VERSION 17)
(define-public SDL_GL_CONTEXT_MINOR_VERSION 18)
(define-public SDL_GL_CONTEXT_EGL 19)
(define-public SDL_GL_CONTEXT_FLAGS 20)
(define-public SDL_GL_CONTEXT_PROFILE_MASK 21)
(define-public SDL_GL_SHARE_WITH_CURRENT_CONTEXT 22)
(define-public SDL_GL_FRAMEBUFFER_SRGB_CAPABLE 23)

(define-foreign sdl-gl-set-attribute
  int "SDL_GL_SetAttribute" (list int int))

(define-foreign sdl-gl-set-swap-interval
  int "SDL_GL_SetSwapInterval" (list int))

(define-public SDL_RENDERER_SOFTWARE #x00000001)
(define-public SDL_RENDERER_ACCELERATED #x00000002)
(define-public SDL_RENDERER_PRESENTVSYNC #x00000004)
(define-public SDL_RENDERER_TARGETTEXTURE #x00000008)

(define-foreign sdl-create-renderer
  '* "SDL_CreateRenderer" (list '* int uint32))

(define-foreign sdl-destroy-renderer
  void "SDL_DestroyRenderer" '(*))

(define-foreign sdl-render-clear
  int "SDL_RenderClear" '(*))

(define-foreign sdl-render-present
  void "SDL_RenderPresent" '(*))

(define-foreign sdl-render-copy
  int "SDL_RenderCopy" '(* * * *))

(define-foreign sdl-render-copy-ex
  int "SDL_RenderCopyEx" (list '* '* '* '* double '* int))

(define-public SDL_TEXTUREACCESS_STATIC    0)
(define-public SDL_TEXTUREACCESS_STREAMING 1)
(define-public SDL_TEXTUREACCESS_TARGET    2)

(define-foreign sdl-create-texture
  '* "SDL_CreateTexture" (list '* uint32 int int int))

(define-foreign sdl-set-render-target
  int "SDL_SetRenderTarget" '(* *))

(define-foreign sdl-get-render-target
  '* "SDL_GetRenderTarget" '(*))

(define-foreign sdl-create-texture-from-surface
  '* "SDL_CreateTextureFromSurface" '(* *))

(define-foreign sdl-destroy-texture
  void "SDL_DestroyTexture" '(*))

(define-foreign sdl-query-texture
  int "SDL_QueryTexture" '(* * * * *))

(define-foreign sdl-set-texture-color-mod
  int "SDL_SetTextureColorMod" (list '* uint8 uint8 uint8))

(define-foreign sdl-get-texture-color-mod
  int "SDL_GetTextureColorMod" '(* * * *))

(define-foreign sdl-set-texture-alpha-mod
  int "SDL_SetTextureAlphaMod" (list '* uint8))

(define-foreign sdl-get-texture-alpha-mod
  int "SDL_GetTextureAlphaMod" '(* *))

(define-foreign sdl-set-texture-blend-mode
  int "SDL_SetTextureBlendMode" (list '* int))

(define-foreign sdl-update-texture
  int "SDL_UpdateTexture" (list '* '* '* int))

(define-foreign sdl-set-render-draw-blend-mode
  int "SDL_SetRenderDrawBlendMode" (list '* int))

(define-foreign sdl-set-render-draw-color
  int "SDL_SetRenderDrawColor" (list '* uint8 uint8 uint8 uint8))

(define-foreign sdl-render-draw-line
  int "SDL_RenderDrawLine" (list '* int int int int))

(define-foreign sdl-render-draw-lines
  int "SDL_RenderDrawLines" (list '* '* int))

(define-foreign sdl-render-draw-point
  int "SDL_RenderDrawPoint" (list '* int int))

(define-foreign sdl-render-draw-points
  int "SDL_RenderDrawPoints" (list '* '* int))

(define-foreign sdl-render-draw-rect
  int "SDL_RenderDrawRect" (list '* '*))

(define-foreign sdl-render-draw-rects
  int "SDL_RenderDrawRects" (list '* '* int))

(define-foreign sdl-render-fill-rect
  int "SDL_RenderFillRect" (list '* '*))

(define-foreign sdl-render-fill-rects
  int "SDL_RenderFillRects" (list '* '* int))

(define-foreign sdl-render-get-integer-scale
  sdl-bool "SDL_RenderGetIntegerScale" (list '*))

(define-foreign sdl-render-get-logical-size
  void "SDL_RenderGetLogicalSize" (list '* '* '*))

(define-foreign sdl-render-get-scale
  void "SDL_RenderGetScale" (list '* '* '*))

(define-foreign sdl-render-get-viewport
  void "SDL_RenderGetViewport" (list '* '*))

(define-foreign sdl-render-set-integer-scale
  int "SDL_RenderSetIntegerScale" (list '* sdl-bool))

(define-foreign sdl-render-set-logical-size
  int "SDL_RenderSetLogicalSize" (list '* int int))

(define-foreign sdl-render-set-scale
  int "SDL_RenderSetScale" (list '* float float))

(define-foreign sdl-render-set-viewport
  int "SDL_RenderSetViewport" (list '* '*))


;;;
;;; Events
;;;

(define-public SDL_QUERY -1)
(define-public SDL_IGNORE 0)
(define-public SDL_DISABLE 0)
(define-public SDL_ENABLE 1)

(define-public SDL_QUIT #x100)
(define-public SDL_APP_TERMINATING #x101)
(define-public SDL_APP_LOWMEMORY #x102)
(define-public SDL_APP_WILLENTERBACKGROUND #x103)
(define-public SDL_APP_DIDENTERBACKGROUND #x104)
(define-public SDL_APP_WILLENTERFOREGROUND #x105)
(define-public SDL_APP_DIDENTERFOREGROUND #x106)
(define-public SDL_WINDOWEVENT #x200)
(define-public SDL_SYSWMEVENT #x201)
(define-public SDL_KEYDOWN #x300)
(define-public SDL_KEYUP #x301)
(define-public SDL_TEXTEDITING #x302)
(define-public SDL_TEXTINPUT #x303)
(define-public SDL_MOUSEMOTION #x400)
(define-public SDL_MOUSEBUTTONDOWN #x401)
(define-public SDL_MOUSEBUTTONUP #x402)
(define-public SDL_MOUSEWHEEL #x403)
(define-public SDL_JOYAXISMOTION #x600)
(define-public SDL_JOYBALLMOTION #x601)
(define-public SDL_JOYHATMOTION #x602)
(define-public SDL_JOYBUTTONDOWN #x603)
(define-public SDL_JOYBUTTONUP #x604)
(define-public SDL_JOYDEVICEADDED #x605)
(define-public SDL_JOYDEVICEREMOVED #x606)
(define-public SDL_CONTROLLERAXISMOTION #x650)
(define-public SDL_CONTROLLERBUTTONDOWN #x651)
(define-public SDL_CONTROLLERBUTTONUP #x652)
(define-public SDL_CONTROLLERDEVICEADDED #x653)
(define-public SDL_CONTROLLERDEVICEREMOVED #x654)
(define-public SDL_CONTROLLERDEVICEREMAPPED #x655)
(define-public SDL_FINGERDOWN #x700)
(define-public SDL_FINGERUP #x701)
(define-public SDL_FINGERMOTION #x702)
(define-public SDL_DOLLARGESTURE #x800)
(define-public SDL_DOLLARRECORD #x801)
(define-public SDL_MULTIGESTURE #x802)
(define-public SDL_CLIPBOARDUPDATE #x900)
(define-public SDL_DROPFILE #x1000)
(define-public SDL_RENDER_TARGETS_RESET #x2000)
(define-public SDL_USEREVENT #x8000)

(define-public SDL_RELEASED 0)
(define-public SDL_PRESSED  1)

(define-public SDL_WINDOWEVENT_NONE         0)
(define-public SDL_WINDOWEVENT_SHOWN        1)
(define-public SDL_WINDOWEVENT_HIDDEN       2)
(define-public SDL_WINDOWEVENT_EXPOSED      3)
(define-public SDL_WINDOWEVENT_MOVED        4)
(define-public SDL_WINDOWEVENT_RESIZED      5)
(define-public SDL_WINDOWEVENT_SIZE_CHANGED 6)
(define-public SDL_WINDOWEVENT_MINIMIZED    7)
(define-public SDL_WINDOWEVENT_MAXIMIZED    8)
(define-public SDL_WINDOWEVENT_RESTORED     9)
(define-public SDL_WINDOWEVENT_ENTER        10)
(define-public SDL_WINDOWEVENT_LEAVE        11)
(define-public SDL_WINDOWEVENT_FOCUS_GAINED 12)
(define-public SDL_WINDOWEVENT_FOCUS_LOST   13)
(define-public SDL_WINDOWEVENT_CLOSE        14)
(define-public SDL_WINDOWEVENT_TAKE_FOCUS   15)
(define-public SDL_WINDOWEVENT_HIT_TEST     16)

(define-foreign sdl-poll-event
  int "SDL_PollEvent" '(*))


;;;
;;; Keycodes and scancodes
;;;

(define-public KMOD_NONE #x0000)
(define-public KMOD_LSHIFT #x0001)
(define-public KMOD_RSHIFT #x0002)
(define-public KMOD_LCTRL #x0040)
(define-public KMOD_RCTRL #x0080)
(define-public KMOD_LALT #x0100)
(define-public KMOD_RALT #x0200)
(define-public KMOD_LGUI #x0400)
(define-public KMOD_RGUI #x0800)
(define-public KMOD_NUM #x1000)
(define-public KMOD_CAPS #x2000)
(define-public KMOD_MODE #x4000)

(define-public SDLK_SCANCODE_MASK (ash 1 30))

(define-public (scancode->keycode scancode)
  (logior scancode SDLK_SCANCODE_MASK))

(define-public SDL_SCANCODE_UNKNOWN 0)
(define-public SDL_SCANCODE_A 4)
(define-public SDL_SCANCODE_B 5)
(define-public SDL_SCANCODE_C 6)
(define-public SDL_SCANCODE_D 7)
(define-public SDL_SCANCODE_E 8)
(define-public SDL_SCANCODE_F 9)
(define-public SDL_SCANCODE_G 10)
(define-public SDL_SCANCODE_H 11)
(define-public SDL_SCANCODE_I 12)
(define-public SDL_SCANCODE_J 13)
(define-public SDL_SCANCODE_K 14)
(define-public SDL_SCANCODE_L 15)
(define-public SDL_SCANCODE_M 16)
(define-public SDL_SCANCODE_N 17)
(define-public SDL_SCANCODE_O 18)
(define-public SDL_SCANCODE_P 19)
(define-public SDL_SCANCODE_Q 20)
(define-public SDL_SCANCODE_R 21)
(define-public SDL_SCANCODE_S 22)
(define-public SDL_SCANCODE_T 23)
(define-public SDL_SCANCODE_U 24)
(define-public SDL_SCANCODE_V 25)
(define-public SDL_SCANCODE_W 26)
(define-public SDL_SCANCODE_X 27)
(define-public SDL_SCANCODE_Y 28)
(define-public SDL_SCANCODE_Z 29)
(define-public SDL_SCANCODE_1 30)
(define-public SDL_SCANCODE_2 31)
(define-public SDL_SCANCODE_3 32)
(define-public SDL_SCANCODE_4 33)
(define-public SDL_SCANCODE_5 34)
(define-public SDL_SCANCODE_6 35)
(define-public SDL_SCANCODE_7 36)
(define-public SDL_SCANCODE_8 37)
(define-public SDL_SCANCODE_9 38)
(define-public SDL_SCANCODE_0 39)
(define-public SDL_SCANCODE_RETURN 40)
(define-public SDL_SCANCODE_ESCAPE 41)
(define-public SDL_SCANCODE_BACKSPACE 42)
(define-public SDL_SCANCODE_TAB 43)
(define-public SDL_SCANCODE_SPACE 44)
(define-public SDL_SCANCODE_MINUS 45)
(define-public SDL_SCANCODE_EQUALS 46)
(define-public SDL_SCANCODE_LEFTBRACKET 47)
(define-public SDL_SCANCODE_RIGHTBRACKET 48)
(define-public SDL_SCANCODE_BACKSLASH 49)
(define-public SDL_SCANCODE_NONUSHASH 50)
(define-public SDL_SCANCODE_SEMICOLON 51)
(define-public SDL_SCANCODE_APOSTROPHE 52)
(define-public SDL_SCANCODE_GRAVE 53)
(define-public SDL_SCANCODE_COMMA 54)
(define-public SDL_SCANCODE_PERIOD 55)
(define-public SDL_SCANCODE_SLASH 56)
(define-public SDL_SCANCODE_CAPSLOCK 57)
(define-public SDL_SCANCODE_F1 58)
(define-public SDL_SCANCODE_F2 59)
(define-public SDL_SCANCODE_F3 60)
(define-public SDL_SCANCODE_F4 61)
(define-public SDL_SCANCODE_F5 62)
(define-public SDL_SCANCODE_F6 63)
(define-public SDL_SCANCODE_F7 64)
(define-public SDL_SCANCODE_F8 65)
(define-public SDL_SCANCODE_F9 66)
(define-public SDL_SCANCODE_F10 67)
(define-public SDL_SCANCODE_F11 68)
(define-public SDL_SCANCODE_F12 69)
(define-public SDL_SCANCODE_PRINTSCREEN 70)
(define-public SDL_SCANCODE_SCROLLLOCK 71)
(define-public SDL_SCANCODE_PAUSE 72)
(define-public SDL_SCANCODE_INSERT 73)
(define-public SDL_SCANCODE_HOME 74)
(define-public SDL_SCANCODE_PAGEUP 75)
(define-public SDL_SCANCODE_DELETE 76)
(define-public SDL_SCANCODE_END 77)
(define-public SDL_SCANCODE_PAGEDOWN 78)
(define-public SDL_SCANCODE_RIGHT 79)
(define-public SDL_SCANCODE_LEFT 80)
(define-public SDL_SCANCODE_DOWN 81)
(define-public SDL_SCANCODE_UP 82)
(define-public SDL_SCANCODE_NUMLOCKCLEAR 83)
(define-public SDL_SCANCODE_KP_DIVIDE 84)
(define-public SDL_SCANCODE_KP_MULTIPLY 85)
(define-public SDL_SCANCODE_KP_MINUS 86)
(define-public SDL_SCANCODE_KP_PLUS 87)
(define-public SDL_SCANCODE_KP_ENTER 88)
(define-public SDL_SCANCODE_KP_1 89)
(define-public SDL_SCANCODE_KP_2 90)
(define-public SDL_SCANCODE_KP_3 91)
(define-public SDL_SCANCODE_KP_4 92)
(define-public SDL_SCANCODE_KP_5 93)
(define-public SDL_SCANCODE_KP_6 94)
(define-public SDL_SCANCODE_KP_7 95)
(define-public SDL_SCANCODE_KP_8 96)
(define-public SDL_SCANCODE_KP_9 97)
(define-public SDL_SCANCODE_KP_0 98)
(define-public SDL_SCANCODE_KP_PERIOD 99)
(define-public SDL_SCANCODE_NONUSBACKSLASH 100)
(define-public SDL_SCANCODE_APPLICATION 101)
(define-public SDL_SCANCODE_POWER 102)
(define-public SDL_SCANCODE_KP_EQUALS 103)
(define-public SDL_SCANCODE_F13 104)
(define-public SDL_SCANCODE_F14 105)
(define-public SDL_SCANCODE_F15 106)
(define-public SDL_SCANCODE_F16 107)
(define-public SDL_SCANCODE_F17 108)
(define-public SDL_SCANCODE_F18 109)
(define-public SDL_SCANCODE_F19 110)
(define-public SDL_SCANCODE_F20 111)
(define-public SDL_SCANCODE_F21 112)
(define-public SDL_SCANCODE_F22 113)
(define-public SDL_SCANCODE_F23 114)
(define-public SDL_SCANCODE_F24 115)
(define-public SDL_SCANCODE_EXECUTE 116)
(define-public SDL_SCANCODE_HELP 117)
(define-public SDL_SCANCODE_MENU 118)
(define-public SDL_SCANCODE_SELECT 119)
(define-public SDL_SCANCODE_STOP 120)
(define-public SDL_SCANCODE_AGAIN 121)
(define-public SDL_SCANCODE_UNDO 122)
(define-public SDL_SCANCODE_CUT 123)
(define-public SDL_SCANCODE_COPY 124)
(define-public SDL_SCANCODE_PASTE 125)
(define-public SDL_SCANCODE_FIND 126)
(define-public SDL_SCANCODE_MUTE 127)
(define-public SDL_SCANCODE_VOLUMEUP 128)
(define-public SDL_SCANCODE_VOLUMEDOWN 129)
(define-public SDL_SCANCODE_KP_COMMA 133)
(define-public SDL_SCANCODE_KP_EQUALSAS400 134)
(define-public SDL_SCANCODE_INTERNATIONAL1 135)
(define-public SDL_SCANCODE_INTERNATIONAL2 136)
(define-public SDL_SCANCODE_INTERNATIONAL3 137)
(define-public SDL_SCANCODE_INTERNATIONAL4 138)
(define-public SDL_SCANCODE_INTERNATIONAL5 139)
(define-public SDL_SCANCODE_INTERNATIONAL6 140)
(define-public SDL_SCANCODE_INTERNATIONAL7 141)
(define-public SDL_SCANCODE_INTERNATIONAL8 142)
(define-public SDL_SCANCODE_INTERNATIONAL9 143)
(define-public SDL_SCANCODE_LANG1 144)
(define-public SDL_SCANCODE_LANG2 145)
(define-public SDL_SCANCODE_LANG3 146)
(define-public SDL_SCANCODE_LANG4 147)
(define-public SDL_SCANCODE_LANG5 148)
(define-public SDL_SCANCODE_LANG6 149)
(define-public SDL_SCANCODE_LANG7 150)
(define-public SDL_SCANCODE_LANG8 151)
(define-public SDL_SCANCODE_LANG9 152)
(define-public SDL_SCANCODE_ALTERASE 153)
(define-public SDL_SCANCODE_SYSREQ 154)
(define-public SDL_SCANCODE_CANCEL 155)
(define-public SDL_SCANCODE_CLEAR 156)
(define-public SDL_SCANCODE_PRIOR 157)
(define-public SDL_SCANCODE_RETURN2 158)
(define-public SDL_SCANCODE_SEPARATOR 159)
(define-public SDL_SCANCODE_OUT 160)
(define-public SDL_SCANCODE_OPER 161)
(define-public SDL_SCANCODE_CLEARAGAIN 162)
(define-public SDL_SCANCODE_CRSEL 163)
(define-public SDL_SCANCODE_EXSEL 164)
(define-public SDL_SCANCODE_KP_00 176)
(define-public SDL_SCANCODE_KP_000 177)
(define-public SDL_SCANCODE_THOUSANDSSEPARATOR 178)
(define-public SDL_SCANCODE_DECIMALSEPARATOR 179)
(define-public SDL_SCANCODE_CURRENCYUNIT 180)
(define-public SDL_SCANCODE_CURRENCYSUBUNIT 181)
(define-public SDL_SCANCODE_KP_LEFTPAREN 182)
(define-public SDL_SCANCODE_KP_RIGHTPAREN 183)
(define-public SDL_SCANCODE_KP_LEFTBRACE 184)
(define-public SDL_SCANCODE_KP_RIGHTBRACE 185)
(define-public SDL_SCANCODE_KP_TAB 186)
(define-public SDL_SCANCODE_KP_BACKSPACE 187)
(define-public SDL_SCANCODE_KP_A 188)
(define-public SDL_SCANCODE_KP_B 189)
(define-public SDL_SCANCODE_KP_C 190)
(define-public SDL_SCANCODE_KP_D 191)
(define-public SDL_SCANCODE_KP_E 192)
(define-public SDL_SCANCODE_KP_F 193)
(define-public SDL_SCANCODE_KP_XOR 194)
(define-public SDL_SCANCODE_KP_POWER 195)
(define-public SDL_SCANCODE_KP_PERCENT 196)
(define-public SDL_SCANCODE_KP_LESS 197)
(define-public SDL_SCANCODE_KP_GREATER 198)
(define-public SDL_SCANCODE_KP_AMPERSAND 199)
(define-public SDL_SCANCODE_KP_DBLAMPERSAND 200)
(define-public SDL_SCANCODE_KP_VERTICALBAR 201)
(define-public SDL_SCANCODE_KP_DBLVERTICALBAR 202)
(define-public SDL_SCANCODE_KP_COLON 203)
(define-public SDL_SCANCODE_KP_HASH 204)
(define-public SDL_SCANCODE_KP_SPACE 205)
(define-public SDL_SCANCODE_KP_AT 206)
(define-public SDL_SCANCODE_KP_EXCLAM 207)
(define-public SDL_SCANCODE_KP_MEMSTORE 208)
(define-public SDL_SCANCODE_KP_MEMRECALL 209)
(define-public SDL_SCANCODE_KP_MEMCLEAR 210)
(define-public SDL_SCANCODE_KP_MEMADD 211)
(define-public SDL_SCANCODE_KP_MEMSUBTRACT 212)
(define-public SDL_SCANCODE_KP_MEMMULTIPLY 213)
(define-public SDL_SCANCODE_KP_MEMDIVIDE 214)
(define-public SDL_SCANCODE_KP_PLUSMINUS 215)
(define-public SDL_SCANCODE_KP_CLEAR 216)
(define-public SDL_SCANCODE_KP_CLEARENTRY 217)
(define-public SDL_SCANCODE_KP_BINARY 218)
(define-public SDL_SCANCODE_KP_OCTAL 219)
(define-public SDL_SCANCODE_KP_DECIMAL 220)
(define-public SDL_SCANCODE_KP_HEXADECIMAL 221)
(define-public SDL_SCANCODE_LCTRL 224)
(define-public SDL_SCANCODE_LSHIFT 225)
(define-public SDL_SCANCODE_LALT 226)
(define-public SDL_SCANCODE_LGUI 227)
(define-public SDL_SCANCODE_RCTRL 228)
(define-public SDL_SCANCODE_RSHIFT 229)
(define-public SDL_SCANCODE_RALT 230)
(define-public SDL_SCANCODE_RGUI 231)
(define-public SDL_SCANCODE_MODE 257)
(define-public SDL_SCANCODE_AUDIONEXT 258)
(define-public SDL_SCANCODE_AUDIOPREV 259)
(define-public SDL_SCANCODE_AUDIOSTOP 260)
(define-public SDL_SCANCODE_AUDIOPLAY 261)
(define-public SDL_SCANCODE_AUDIOMUTE 262)
(define-public SDL_SCANCODE_MEDIASELECT 263)
(define-public SDL_SCANCODE_WWW 264)
(define-public SDL_SCANCODE_MAIL 265)
(define-public SDL_SCANCODE_CALCULATOR 266)
(define-public SDL_SCANCODE_COMPUTER 267)
(define-public SDL_SCANCODE_AC_SEARCH 268)
(define-public SDL_SCANCODE_AC_HOME 269)
(define-public SDL_SCANCODE_AC_BACK 270)
(define-public SDL_SCANCODE_AC_FORWARD 271)
(define-public SDL_SCANCODE_AC_STOP 272)
(define-public SDL_SCANCODE_AC_REFRESH 273)
(define-public SDL_SCANCODE_AC_BOOKMARKS 274)
(define-public SDL_SCANCODE_BRIGHTNESSDOWN 275)
(define-public SDL_SCANCODE_BRIGHTNESSUP 276)
(define-public SDL_SCANCODE_DISPLAYSWITCH 277)
(define-public SDL_SCANCODE_KBDILLUMTOGGLE 278)
(define-public SDL_SCANCODE_KBDILLUMDOWN 279)
(define-public SDL_SCANCODE_KBDILLUMUP 280)
(define-public SDL_SCANCODE_EJECT 281)
(define-public SDL_SCANCODE_SLEEP 282)
(define-public SDL_SCANCODE_APP1 283)
(define-public SDL_SCANCODE_APP2 284)
(define-public SDL_NUM_SCANCODES 512)

(define-public SDLK_UNKNOWN 0)
(define-public SDLK_RETURN 13)
(define-public SDLK_ESCAPE 27)
(define-public SDLK_BACKSPACE 8)
(define-public SDLK_TAB 9)
(define-public SDLK_SPACE 32)
(define-public SDLK_EXCLAIM 33)
(define-public SDLK_QUOTEDBL 34)
(define-public SDLK_HASH 35)
(define-public SDLK_PERCENT 37)
(define-public SDLK_DOLLAR 36)
(define-public SDLK_AMPERSAND 38)
(define-public SDLK_QUOTE 39)
(define-public SDLK_LEFTPAREN 40)
(define-public SDLK_RIGHTPAREN 41)
(define-public SDLK_ASTERISK 42)
(define-public SDLK_PLUS 43)
(define-public SDLK_COMMA 44)
(define-public SDLK_MINUS 45)
(define-public SDLK_PERIOD 46)
(define-public SDLK_SLASH 47)
(define-public SDLK_0 48)
(define-public SDLK_1 49)
(define-public SDLK_2 50)
(define-public SDLK_3 51)
(define-public SDLK_4 52)
(define-public SDLK_5 53)
(define-public SDLK_6 54)
(define-public SDLK_7 55)
(define-public SDLK_8 56)
(define-public SDLK_9 57)
(define-public SDLK_COLON 58)
(define-public SDLK_SEMICOLON 59)
(define-public SDLK_LESS 60)
(define-public SDLK_EQUALS 61)
(define-public SDLK_GREATER 62)
(define-public SDLK_QUESTION 63)
(define-public SDLK_AT 64)
(define-public SDLK_LEFTBRACKET 91)
(define-public SDLK_BACKSLASH 92)
(define-public SDLK_RIGHTBRACKET 93)
(define-public SDLK_CARET 94)
(define-public SDLK_UNDERSCORE 95)
(define-public SDLK_BACKQUOTE 96)
(define-public SDLK_a 97)
(define-public SDLK_b 98)
(define-public SDLK_c 99)
(define-public SDLK_d 100)
(define-public SDLK_e 101)
(define-public SDLK_f 102)
(define-public SDLK_g 103)
(define-public SDLK_h 104)
(define-public SDLK_i 105)
(define-public SDLK_j 106)
(define-public SDLK_k 107)
(define-public SDLK_l 108)
(define-public SDLK_m 109)
(define-public SDLK_n 110)
(define-public SDLK_o 111)
(define-public SDLK_p 112)
(define-public SDLK_q 113)
(define-public SDLK_r 114)
(define-public SDLK_s 115)
(define-public SDLK_t 116)
(define-public SDLK_u 117)
(define-public SDLK_v 118)
(define-public SDLK_w 119)
(define-public SDLK_x 120)
(define-public SDLK_y 121)
(define-public SDLK_z 122)
(define-public SDLK_CAPSLOCK (scancode->keycode SDL_SCANCODE_CAPSLOCK))
(define-public SDLK_F1 (scancode->keycode SDL_SCANCODE_F1))
(define-public SDLK_F2 (scancode->keycode SDL_SCANCODE_F2))
(define-public SDLK_F3 (scancode->keycode SDL_SCANCODE_F3))
(define-public SDLK_F4 (scancode->keycode SDL_SCANCODE_F4))
(define-public SDLK_F5 (scancode->keycode SDL_SCANCODE_F5))
(define-public SDLK_F6 (scancode->keycode SDL_SCANCODE_F6))
(define-public SDLK_F7 (scancode->keycode SDL_SCANCODE_F7))
(define-public SDLK_F8 (scancode->keycode SDL_SCANCODE_F8))
(define-public SDLK_F9 (scancode->keycode SDL_SCANCODE_F9))
(define-public SDLK_F10 (scancode->keycode SDL_SCANCODE_F10))
(define-public SDLK_F11 (scancode->keycode SDL_SCANCODE_F11))
(define-public SDLK_F12 (scancode->keycode SDL_SCANCODE_F12))
(define-public SDLK_PRINTSCREEN (scancode->keycode SDL_SCANCODE_PRINTSCREEN))
(define-public SDLK_SCROLLLOCK (scancode->keycode SDL_SCANCODE_SCROLLLOCK))
(define-public SDLK_PAUSE (scancode->keycode SDL_SCANCODE_PAUSE))
(define-public SDLK_INSERT (scancode->keycode SDL_SCANCODE_INSERT))
(define-public SDLK_HOME (scancode->keycode SDL_SCANCODE_HOME))
(define-public SDLK_PAGEUP (scancode->keycode SDL_SCANCODE_PAGEUP))
(define-public SDLK_DELETE 127)
(define-public SDLK_END (scancode->keycode SDL_SCANCODE_END))
(define-public SDLK_PAGEDOWN (scancode->keycode SDL_SCANCODE_PAGEDOWN))
(define-public SDLK_RIGHT (scancode->keycode SDL_SCANCODE_RIGHT))
(define-public SDLK_LEFT (scancode->keycode SDL_SCANCODE_LEFT))
(define-public SDLK_DOWN (scancode->keycode SDL_SCANCODE_DOWN))
(define-public SDLK_UP (scancode->keycode SDL_SCANCODE_UP))
(define-public SDLK_NUMLOCKCLEAR (scancode->keycode SDL_SCANCODE_NUMLOCKCLEAR))
(define-public SDLK_KP_DIVIDE (scancode->keycode SDL_SCANCODE_KP_DIVIDE))
(define-public SDLK_KP_MULTIPLY (scancode->keycode SDL_SCANCODE_KP_MULTIPLY))
(define-public SDLK_KP_MINUS (scancode->keycode SDL_SCANCODE_KP_MINUS))
(define-public SDLK_KP_PLUS (scancode->keycode SDL_SCANCODE_KP_PLUS))
(define-public SDLK_KP_ENTER (scancode->keycode SDL_SCANCODE_KP_ENTER))
(define-public SDLK_KP_1 (scancode->keycode SDL_SCANCODE_KP_1))
(define-public SDLK_KP_2 (scancode->keycode SDL_SCANCODE_KP_2))
(define-public SDLK_KP_3 (scancode->keycode SDL_SCANCODE_KP_3))
(define-public SDLK_KP_4 (scancode->keycode SDL_SCANCODE_KP_4))
(define-public SDLK_KP_5 (scancode->keycode SDL_SCANCODE_KP_5))
(define-public SDLK_KP_6 (scancode->keycode SDL_SCANCODE_KP_6))
(define-public SDLK_KP_7 (scancode->keycode SDL_SCANCODE_KP_7))
(define-public SDLK_KP_8 (scancode->keycode SDL_SCANCODE_KP_8))
(define-public SDLK_KP_9 (scancode->keycode SDL_SCANCODE_KP_9))
(define-public SDLK_KP_0 (scancode->keycode SDL_SCANCODE_KP_0))
(define-public SDLK_KP_PERIOD (scancode->keycode SDL_SCANCODE_KP_PERIOD))
(define-public SDLK_APPLICATION (scancode->keycode SDL_SCANCODE_APPLICATION))
(define-public SDLK_POWER (scancode->keycode SDL_SCANCODE_POWER))
(define-public SDLK_KP_EQUALS (scancode->keycode SDL_SCANCODE_KP_EQUALS))
(define-public SDLK_F13 (scancode->keycode SDL_SCANCODE_F13))
(define-public SDLK_F14 (scancode->keycode SDL_SCANCODE_F14))
(define-public SDLK_F15 (scancode->keycode SDL_SCANCODE_F15))
(define-public SDLK_F16 (scancode->keycode SDL_SCANCODE_F16))
(define-public SDLK_F17 (scancode->keycode SDL_SCANCODE_F17))
(define-public SDLK_F18 (scancode->keycode SDL_SCANCODE_F18))
(define-public SDLK_F19 (scancode->keycode SDL_SCANCODE_F19))
(define-public SDLK_F20 (scancode->keycode SDL_SCANCODE_F20))
(define-public SDLK_F21 (scancode->keycode SDL_SCANCODE_F21))
(define-public SDLK_F22 (scancode->keycode SDL_SCANCODE_F22))
(define-public SDLK_F23 (scancode->keycode SDL_SCANCODE_F23))
(define-public SDLK_F24 (scancode->keycode SDL_SCANCODE_F24))
(define-public SDLK_EXECUTE (scancode->keycode SDL_SCANCODE_EXECUTE))
(define-public SDLK_HELP (scancode->keycode SDL_SCANCODE_HELP))
(define-public SDLK_MENU (scancode->keycode SDL_SCANCODE_MENU))
(define-public SDLK_SELECT (scancode->keycode SDL_SCANCODE_SELECT))
(define-public SDLK_STOP (scancode->keycode SDL_SCANCODE_STOP))
(define-public SDLK_AGAIN (scancode->keycode SDL_SCANCODE_AGAIN))
(define-public SDLK_UNDO (scancode->keycode SDL_SCANCODE_UNDO))
(define-public SDLK_CUT (scancode->keycode SDL_SCANCODE_CUT))
(define-public SDLK_COPY (scancode->keycode SDL_SCANCODE_COPY))
(define-public SDLK_PASTE (scancode->keycode SDL_SCANCODE_PASTE))
(define-public SDLK_FIND (scancode->keycode SDL_SCANCODE_FIND))
(define-public SDLK_MUTE (scancode->keycode SDL_SCANCODE_MUTE))
(define-public SDLK_VOLUMEUP (scancode->keycode SDL_SCANCODE_VOLUMEUP))
(define-public SDLK_VOLUMEDOWN (scancode->keycode SDL_SCANCODE_VOLUMEDOWN))
(define-public SDLK_KP_COMMA (scancode->keycode SDL_SCANCODE_KP_COMMA))
(define-public SDLK_KP_EQUALSAS400
  (scancode->keycode SDL_SCANCODE_KP_EQUALSAS400))
(define-public SDLK_ALTERASE (scancode->keycode SDL_SCANCODE_ALTERASE))
(define-public SDLK_SYSREQ (scancode->keycode SDL_SCANCODE_SYSREQ))
(define-public SDLK_CANCEL (scancode->keycode SDL_SCANCODE_CANCEL))
(define-public SDLK_CLEAR (scancode->keycode SDL_SCANCODE_CLEAR))
(define-public SDLK_PRIOR (scancode->keycode SDL_SCANCODE_PRIOR))
(define-public SDLK_RETURN2 (scancode->keycode SDL_SCANCODE_RETURN2))
(define-public SDLK_SEPARATOR (scancode->keycode SDL_SCANCODE_SEPARATOR))
(define-public SDLK_OUT (scancode->keycode SDL_SCANCODE_OUT))
(define-public SDLK_OPER (scancode->keycode SDL_SCANCODE_OPER))
(define-public SDLK_CLEARAGAIN (scancode->keycode SDL_SCANCODE_CLEARAGAIN))
(define-public SDLK_CRSEL (scancode->keycode SDL_SCANCODE_CRSEL))
(define-public SDLK_EXSEL (scancode->keycode SDL_SCANCODE_EXSEL))
(define-public SDLK_KP_00 (scancode->keycode SDL_SCANCODE_KP_00))
(define-public SDLK_KP_000 (scancode->keycode SDL_SCANCODE_KP_000))
(define-public SDLK_THOUSANDSSEPARATOR
  (scancode->keycode SDL_SCANCODE_THOUSANDSSEPARATOR))
(define-public SDLK_DECIMALSEPARATOR
  (scancode->keycode SDL_SCANCODE_DECIMALSEPARATOR))
(define-public SDLK_CURRENCYUNIT (scancode->keycode SDL_SCANCODE_CURRENCYUNIT))
(define-public SDLK_CURRENCYSUBUNIT
  (scancode->keycode SDL_SCANCODE_CURRENCYSUBUNIT))
(define-public SDLK_KP_LEFTPAREN (scancode->keycode SDL_SCANCODE_KP_LEFTPAREN))
(define-public SDLK_KP_RIGHTPAREN
  (scancode->keycode SDL_SCANCODE_KP_RIGHTPAREN))
(define-public SDLK_KP_LEFTBRACE (scancode->keycode SDL_SCANCODE_KP_LEFTBRACE))
(define-public SDLK_KP_RIGHTBRACE (scancode->keycode SDL_SCANCODE_KP_RIGHTBRACE))
(define-public SDLK_KP_TAB (scancode->keycode SDL_SCANCODE_KP_TAB))
(define-public SDLK_KP_BACKSPACE (scancode->keycode SDL_SCANCODE_KP_BACKSPACE))
(define-public SDLK_KP_A (scancode->keycode SDL_SCANCODE_KP_A))
(define-public SDLK_KP_B (scancode->keycode SDL_SCANCODE_KP_B))
(define-public SDLK_KP_C (scancode->keycode SDL_SCANCODE_KP_C))
(define-public SDLK_KP_D (scancode->keycode SDL_SCANCODE_KP_D))
(define-public SDLK_KP_E (scancode->keycode SDL_SCANCODE_KP_E))
(define-public SDLK_KP_F (scancode->keycode SDL_SCANCODE_KP_F))
(define-public SDLK_KP_XOR (scancode->keycode SDL_SCANCODE_KP_XOR))
(define-public SDLK_KP_POWER (scancode->keycode SDL_SCANCODE_KP_POWER))
(define-public SDLK_KP_PERCENT (scancode->keycode SDL_SCANCODE_KP_PERCENT))
(define-public SDLK_KP_LESS (scancode->keycode SDL_SCANCODE_KP_LESS))
(define-public SDLK_KP_GREATER (scancode->keycode SDL_SCANCODE_KP_GREATER))
(define-public SDLK_KP_AMPERSAND (scancode->keycode SDL_SCANCODE_KP_AMPERSAND))
(define-public SDLK_KP_DBLAMPERSAND
  (scancode->keycode SDL_SCANCODE_KP_DBLAMPERSAND))
(define-public SDLK_KP_VERTICALBAR
  (scancode->keycode SDL_SCANCODE_KP_VERTICALBAR))
(define-public SDLK_KP_DBLVERTICALBAR
  (scancode->keycode SDL_SCANCODE_KP_DBLVERTICALBAR))
(define-public SDLK_KP_COLON (scancode->keycode SDL_SCANCODE_KP_COLON))
(define-public SDLK_KP_HASH (scancode->keycode SDL_SCANCODE_KP_HASH))
(define-public SDLK_KP_SPACE (scancode->keycode SDL_SCANCODE_KP_SPACE))
(define-public SDLK_KP_AT (scancode->keycode SDL_SCANCODE_KP_AT))
(define-public SDLK_KP_EXCLAM (scancode->keycode SDL_SCANCODE_KP_EXCLAM))
(define-public SDLK_KP_MEMSTORE (scancode->keycode SDL_SCANCODE_KP_MEMSTORE))
(define-public SDLK_KP_MEMRECALL (scancode->keycode SDL_SCANCODE_KP_MEMRECALL))
(define-public SDLK_KP_MEMCLEAR (scancode->keycode SDL_SCANCODE_KP_MEMCLEAR))
(define-public SDLK_KP_MEMADD (scancode->keycode SDL_SCANCODE_KP_MEMADD))
(define-public SDLK_KP_MEMSUBTRACT
  (scancode->keycode SDL_SCANCODE_KP_MEMSUBTRACT))
(define-public SDLK_KP_MEMMULTIPLY
  (scancode->keycode SDL_SCANCODE_KP_MEMMULTIPLY))
(define-public SDLK_KP_MEMDIVIDE (scancode->keycode SDL_SCANCODE_KP_MEMDIVIDE))
(define-public SDLK_KP_PLUSMINUS (scancode->keycode SDL_SCANCODE_KP_PLUSMINUS))
(define-public SDLK_KP_CLEAR (scancode->keycode SDL_SCANCODE_KP_CLEAR))
(define-public SDLK_KP_CLEARENTRY (scancode->keycode SDL_SCANCODE_KP_CLEARENTRY))
(define-public SDLK_KP_BINARY (scancode->keycode SDL_SCANCODE_KP_BINARY))
(define-public SDLK_KP_OCTAL (scancode->keycode SDL_SCANCODE_KP_OCTAL))
(define-public SDLK_KP_DECIMAL (scancode->keycode SDL_SCANCODE_KP_DECIMAL))
(define-public SDLK_KP_HEXADECIMAL
  (scancode->keycode SDL_SCANCODE_KP_HEXADECIMAL))
(define-public SDLK_LCTRL (scancode->keycode SDL_SCANCODE_LCTRL))
(define-public SDLK_LSHIFT (scancode->keycode SDL_SCANCODE_LSHIFT))
(define-public SDLK_LALT (scancode->keycode SDL_SCANCODE_LALT))
(define-public SDLK_LGUI (scancode->keycode SDL_SCANCODE_LGUI))
(define-public SDLK_RCTRL (scancode->keycode SDL_SCANCODE_RCTRL))
(define-public SDLK_RSHIFT (scancode->keycode SDL_SCANCODE_RSHIFT))
(define-public SDLK_RALT (scancode->keycode SDL_SCANCODE_RALT))
(define-public SDLK_RGUI (scancode->keycode SDL_SCANCODE_RGUI))
(define-public SDLK_MODE (scancode->keycode SDL_SCANCODE_MODE))
(define-public SDLK_AUDIONEXT (scancode->keycode SDL_SCANCODE_AUDIONEXT))
(define-public SDLK_AUDIOPREV (scancode->keycode SDL_SCANCODE_AUDIOPREV))
(define-public SDLK_AUDIOSTOP (scancode->keycode SDL_SCANCODE_AUDIOSTOP))
(define-public SDLK_AUDIOPLAY (scancode->keycode SDL_SCANCODE_AUDIOPLAY))
(define-public SDLK_AUDIOMUTE (scancode->keycode SDL_SCANCODE_AUDIOMUTE))
(define-public SDLK_MEDIASELECT (scancode->keycode SDL_SCANCODE_MEDIASELECT))
(define-public SDLK_WWW (scancode->keycode SDL_SCANCODE_WWW))
(define-public SDLK_MAIL (scancode->keycode SDL_SCANCODE_MAIL))
(define-public SDLK_CALCULATOR (scancode->keycode SDL_SCANCODE_CALCULATOR))
(define-public SDLK_COMPUTER (scancode->keycode SDL_SCANCODE_COMPUTER))
(define-public SDLK_AC_SEARCH (scancode->keycode SDL_SCANCODE_AC_SEARCH))
(define-public SDLK_AC_HOME (scancode->keycode SDL_SCANCODE_AC_HOME))
(define-public SDLK_AC_BACK (scancode->keycode SDL_SCANCODE_AC_BACK))
(define-public SDLK_AC_FORWARD (scancode->keycode SDL_SCANCODE_AC_FORWARD))
(define-public SDLK_AC_STOP (scancode->keycode SDL_SCANCODE_AC_STOP))
(define-public SDLK_AC_REFRESH (scancode->keycode SDL_SCANCODE_AC_REFRESH))
(define-public SDLK_AC_BOOKMARKS (scancode->keycode SDL_SCANCODE_AC_BOOKMARKS))
(define-public SDLK_BRIGHTNESSDOWN
  (scancode->keycode SDL_SCANCODE_BRIGHTNESSDOWN))
(define-public SDLK_BRIGHTNESSUP (scancode->keycode SDL_SCANCODE_BRIGHTNESSUP))
(define-public SDLK_DISPLAYSWITCH (scancode->keycode SDL_SCANCODE_DISPLAYSWITCH))
(define-public SDLK_KBDILLUMTOGGLE
  (scancode->keycode SDL_SCANCODE_KBDILLUMTOGGLE))
(define-public SDLK_KBDILLUMDOWN (scancode->keycode SDL_SCANCODE_KBDILLUMDOWN))
(define-public SDLK_KBDILLUMUP (scancode->keycode SDL_SCANCODE_KBDILLUMUP))
(define-public SDLK_EJECT (scancode->keycode SDL_SCANCODE_EJECT))
(define-public SDLK_SLEEP (scancode->keycode SDL_SCANCODE_SLEEP))

(define-foreign sdl-get-keyboard-state
  '* "SDL_GetKeyboardState" '(*))

(define-foreign sdl-get-scancode-from-key
  int "SDL_GetScancodeFromKey" (list int))


;;;
;;; Text Input
;;;

(define-foreign sdl-start-text-input
  void "SDL_StartTextInput" '())

(define-foreign sdl-stop-text-input
  void "SDL_StopTextInput" '())

(define-foreign sdl-is-text-input-active
  sdl-bool "SDL_IsTextInputActive" '())


;;;
;;; Mouse
;;;

(define-public SDL_BUTTON_LEFT   1)
(define-public SDL_BUTTON_MIDDLE 2)
(define-public SDL_BUTTON_RIGHT  3)
(define-public SDL_BUTTON_X1     4)
(define-public SDL_BUTTON_X2     5)

(define-public SDL_MOUSEWHEEL_NORMAL 0)
(define-public SDL_MOUSEWHEEL_FLIPPED 1)

(define (button-mask n)
  (ash 1 (1- n)))

(define-public SDL_BUTTON_LMASK  (button-mask SDL_BUTTON_LEFT))
(define-public SDL_BUTTON_MMASK  (button-mask SDL_BUTTON_MIDDLE))
(define-public SDL_BUTTON_RMASK  (button-mask SDL_BUTTON_RIGHT))
(define-public SDL_BUTTON_X1MASK (button-mask SDL_BUTTON_X1))
(define-public SDL_BUTTON_X2MASK (button-mask SDL_BUTTON_X2))

(define-foreign sdl-get-mouse-state
  uint32 "SDL_GetMouseState" '(* *))

(define-foreign sdl-show-cursor
  int "SDL_ShowCursor" (list int))

(define-foreign sdl-warp-mouse-in-window
  void "SDL_WarpMouseInWindow" (list '* int int))

(define-foreign sdl-warp-mouse-global
  int "SDL_WarpMouseGlobal" (list int int))

(define-public SDL_SYSTEM_CURSOR_ARROW 0)
(define-public SDL_SYSTEM_CURSOR_IBEAM 1)
(define-public SDL_SYSTEM_CURSOR_WAIT 2)
(define-public SDL_SYSTEM_CURSOR_CROSSHAIR 3)
(define-public SDL_SYSTEM_CURSOR_WAITARROW 4)
(define-public SDL_SYSTEM_CURSOR_SIZENWSE 5)
(define-public SDL_SYSTEM_CURSOR_SIZENESW 6)
(define-public SDL_SYSTEM_CURSOR_SIZEWE 7)
(define-public SDL_SYSTEM_CURSOR_SIZENS 8)
(define-public SDL_SYSTEM_CURSOR_SIZEALL 9)
(define-public SDL_SYSTEM_CURSOR_NO 10)
(define-public SDL_SYSTEM_CURSOR_HAND 11)
(define-public SDL_NUM_SYSTEM_CURSORS 12)

(define-foreign sdl-create-system-cursor
  '* "SDL_CreateSystemCursor" (list int))

(define-foreign sdl-create-color-cursor
  '* "SDL_CreateColorCursor" (list '* int int))

(define-foreign sdl-free-cursor
  void "SDL_FreeCursor" (list '*))

(define-foreign sdl-set-cursor
  void "SDL_SetCursor" (list '*))

(define-foreign sdl-get-cursor
  '* "SDL_GetCursor" '())

(define-foreign sdl-show-cursor
  int "SDL_ShowCursor" (list int))


;;;
;;; Sensors
;;;

(define-public SDL_SENSOR_INVALID -1)
(define-public SDL_SENSOR_UNKNOWN 0)
(define-public SDL_SENSOR_ACCEL 1)
(define-public SDL_SENSOR_GYRO 2)
(define-public SDL_SENSOR_ACCEL_L 3)
(define-public SDL_SENSOR_GYRO_L 4)
(define-public SDL_SENSOR_ACCEL_R 5)
(define-public SDL_SENSOR_GYRO_R 6)

(define-public SDL_STANDARD_GRAVITY 9.80665)

(define-foreign sdl-num-sensors
  int "SDL_NumSensors" '())

(define-foreign sdl-sensor-get-device-name
  '* "SDL_SensorGetDeviceName" (list int))

(define-foreign sdl-sensor-get-device-type
  int "SDL_SensorGetDeviceType" (list int))

(define-foreign sdl-sensor-get-device-non-portable-type
  int "SDL_SensorGetDeviceNonPortableType" (list int))

(define-foreign sdl-sensor-get-device-instance-id
  int "SDL_SensorGetDeviceInstanceID" (list int))

(define-foreign sdl-sensor-open
  '* "SDL_SensorOpen" (list int))

(define-foreign sdl-sensor-from-instance-id
  '* "SDL_SensorFromInstanceID" (list int))

(define-foreign sdl-sensor-get-name
  '* "SDL_SensorGetName" '(*))

(define-foreign sdl-sensor-get-type
  int "SDL_SensorGetType" '(*))

(define-foreign sdl-sensor-get-non-portable-type
  int "SDL_SensorGetNonPortableType" '(*))

(define-foreign sdl-sensor-get-instance-id
  int "SDL_SensorGetInstanceID" '(*))

(define-foreign sdl-sensor-get-data
  int "SDL_SensorGetData" (list '* '* int))

;; Only available in very recent versions of SDL2.
;; (define-foreign sdl-sensor-get-data-with-timestamp
;;   int "SDL_SensorGetDataWithTimestamp" (list '* uint64 '* int))

(define-foreign sdl-sensor-close
  void "SDL_SensorClose" '(*))

(define-foreign sdl-sensor-update
  void "SDL_SensorUpdate" '())


;;;
;;; Timer
;;;

(define-foreign sdl-get-ticks
  uint32 "SDL_GetTicks" '())

(define-foreign sdl-get-performance-counter
  uint64 "SDL_GetPerformanceCounter" '())

(define-foreign sdl-get-performance-frequency
  uint64 "SDL_GetPerformanceFrequency" '())


;;;
;;; File I/O
;;;

(define-foreign sdl-rw-from-file
  '* "SDL_RWFromFile" (list '* '*))


;;;
;;; Pixels
;;;

(define-public SDL_PIXELFORMAT_UNKNOWN     0)
(define-public SDL_PIXELFORMAT_INDEX1LSB   286261504)
(define-public SDL_PIXELFORMAT_INDEX1MSB   287310080)
(define-public SDL_PIXELFORMAT_INDEX4LSB   303039488)
(define-public SDL_PIXELFORMAT_INDEX4MSB   304088064)
(define-public SDL_PIXELFORMAT_INDEX8      318769153)
(define-public SDL_PIXELFORMAT_RGB332      336660481)
(define-public SDL_PIXELFORMAT_RGB444      353504258)
(define-public SDL_PIXELFORMAT_RGB555      353570562)
(define-public SDL_PIXELFORMAT_BGR555      357764866)
(define-public SDL_PIXELFORMAT_ARGB4444    355602434)
(define-public SDL_PIXELFORMAT_RGBA4444    356651010)
(define-public SDL_PIXELFORMAT_ABGR4444    359796738)
(define-public SDL_PIXELFORMAT_BGRA4444    360845314)
(define-public SDL_PIXELFORMAT_ARGB1555    355667970)
(define-public SDL_PIXELFORMAT_RGBA5551    356782082)
(define-public SDL_PIXELFORMAT_ABGR1555    359862274)
(define-public SDL_PIXELFORMAT_BGRA5551    360976386)
(define-public SDL_PIXELFORMAT_RGB565      353701890)
(define-public SDL_PIXELFORMAT_BGR565      357896194)
(define-public SDL_PIXELFORMAT_RGB24       386930691)
(define-public SDL_PIXELFORMAT_BGR24       390076419)
(define-public SDL_PIXELFORMAT_RGB888      370546692)
(define-public SDL_PIXELFORMAT_RGBX8888    371595268)
(define-public SDL_PIXELFORMAT_BGR888      374740996)
(define-public SDL_PIXELFORMAT_BGRX8888    375789572)
(define-public SDL_PIXELFORMAT_ARGB8888    372645892)
(define-public SDL_PIXELFORMAT_RGBA8888    373694468)
(define-public SDL_PIXELFORMAT_ABGR8888    376840196)
(define-public SDL_PIXELFORMAT_BGRA8888    377888772)
(define-public SDL_PIXELFORMAT_ARGB2101010 372711428)
(define-public SDL_PIXELFORMAT_YV12        842094169)
(define-public SDL_PIXELFORMAT_IYUV        1448433993)
(define-public SDL_PIXELFORMAT_YUY2        844715353)
(define-public SDL_PIXELFORMAT_UYVY        1498831189)
(define-public SDL_PIXELFORMAT_YVYU        1431918169)


;;;
;;; Surface
;;;

(define-foreign sdl-create-rgb-surface
  '* "SDL_CreateRGBSurface"
  (list uint32 int int int uint32 uint32 uint32 uint32))

(define-foreign sdl-create-rgb-surface-from
  '* "SDL_CreateRGBSurfaceFrom"
  (list '* int int int int uint32 uint32 uint32 uint32))

(define-foreign sdl-free-surface
  void "SDL_FreeSurface" '(*))

(define-foreign sdl-load-bmp-rw
  '* "SDL_LoadBMP_RW" (list '* int))

(define-foreign sdl-convert-surface-format
  '* "SDL_ConvertSurfaceFormat" (list '* uint32 uint32))

(define-foreign sdl-blit-surface
  int "SDL_UpperBlit" '(* * * *))

(define-foreign sdl-blit-scaled
  int "SDL_UpperBlitScaled" '(* * * *))

(define-foreign sdl-fill-rect
  int "SDL_FillRect" (list '* '* uint32))


;;;
;;; Audio
;;;

(define-public AUDIO_U8     #x0008)
(define-public AUDIO_S8     #x8008)
(define-public AUDIO_U16LSB #x0010)
(define-public AUDIO_S16LSB #x8010)
(define-public AUDIO_U16MSB #x1010)
(define-public AUDIO_S16MSB #x9010)
(define-public AUDIO_U16    AUDIO_U16LSB)
(define-public AUDIO_S16    AUDIO_S16LSB)
(define-public AUDIO_S32LSB #x8020)
(define-public AUDIO_S32MSB #x9020)
(define-public AUDIO_S32    AUDIO_S32LSB)
(define-public AUDIO_F32LSB #x8120)
(define-public AUDIO_F32MSB #x9120)
(define-public AUDIO_F32    AUDIO_F32LSB)

(define-public SDL_AUDIO_ALLOW_FREQUENCY_CHANGE 1)
(define-public SDL_AUDIO_ALLOW_FORMAT_CHANGE 2)
(define-public SDL_AUDIO_ALLOW_CHANNELS_CHANGE 4)
(define-public SDL_AUDIO_ALLOW_SAMPLES_CHANGE 8)

(define-foreign sdl-get-num-audio-devices
  int "SDL_GetNumAudioDevices" (list int))

(define-foreign sdl-get-audio-device-name
  '* "SDL_GetAudioDeviceName" (list int int))

(define-foreign sdl-open-audio-device
  int "SDL_OpenAudioDevice" (list '* int '* '* int))


;;;
;;; Joystick
;;;

(define-public SDL_JOYSTICK_POWER_UNKNOWN -1)
(define-public SDL_JOYSTICK_POWER_EMPTY 0)
(define-public SDL_JOYSTICK_POWER_LOW 1)
(define-public SDL_JOYSTICK_POWER_MEDIUM 2)
(define-public SDL_JOYSTICK_POWER_FULL 3)
(define-public SDL_JOYSTICK_POWER_WIRED 4)
(define-public SDL_JOYSTICK_POWER_MAX 5)

(define-foreign sdl-joystick-open
  '* "SDL_JoystickOpen" (list int))

(define-foreign sdl-joystick-close
  void "SDL_JoystickClose" '(*))

(define-foreign sdl-joystick-current-power-level
  int "SDL_JoystickCurrentPowerLevel" '(*))

(define-foreign sdl-joystick-event-state
  int "SDL_JoystickEventState" (list int))

(define-foreign sdl-joystick-from-instance-id
  '* "SDL_JoystickFromInstanceID" (list int32))

(define-foreign sdl-joystick-get-attached
  sdl-bool "SDL_JoystickGetAttached" '(*))

(define-foreign sdl-joystick-get-axis
  int16 "SDL_JoystickGetAxis" (list '* int))

(define-foreign sdl-joystick-get-ball
  int "SDL_JoystickGetBall" (list '* int '* '*))

(define-foreign sdl-joystick-get-button
  uint8 "SDL_JoystickGetButton" (list '* int))

(define-foreign sdl-joystick-get-device-guid
  '* "SDL_JoystickGetDeviceGUID" (list int))

(define-foreign sdl-joystick-get-guid
  '* "SDL_JoystickGetGUID" (list int))

(define-foreign sdl-joystick-get-guid-from-string
  '* "SDL_JoystickGetGUIDFromString" '(*))

(define-foreign sdl-joystick-get-guid-string
  void "SDL_JoystickGetGUIDString" (list '* '* int))

(define-foreign sdl-joystick-get-hat
  uint8 "SDL_JoystickGetHat" (list '* int))

(define-foreign sdl-joystick-instance-id
  int32 "SDL_JoystickInstanceID" '(*))

(define-foreign sdl-joystick-name
  '* "SDL_JoystickName" '(*))

(define-foreign sdl-joystick-name-for-index
  '* "SDL_JoystickNameForIndex" (list int))

(define-foreign sdl-joystick-num-axes
  int "SDL_JoystickNumAxes" '(*))

(define-foreign sdl-joystick-num-balls
  int "SDL_JoystickNumBalls" '(*))

(define-foreign sdl-joystick-num-buttons
  int "SDL_JoystickNumButtons" '(*))

(define-foreign sdl-joystick-num-hats
  int "SDL_JoystickNumHats" '(*))

(define-foreign sdl-num-joysticks
  int "SDL_NumJoysticks" '())

(define-foreign sdl-joystick-update
  void "SDL_JoystickUpdate" '())


;;;
;;; Game Controllers
;;;

(define-public SDL_CONTROLLER_AXIS_INVALID -1)
(define-public SDL_CONTROLLER_AXIS_LEFTX 0)
(define-public SDL_CONTROLLER_AXIS_LEFTY 1)
(define-public SDL_CONTROLLER_AXIS_RIGHTX 2)
(define-public SDL_CONTROLLER_AXIS_RIGHTY 3)
(define-public SDL_CONTROLLER_AXIS_TRIGGERLEFT 4)
(define-public SDL_CONTROLLER_AXIS_TRIGGERRIGHT 5)
(define-public SDL_CONTROLLER_AXIS_MAX 6)

(define-public SDL_CONTROLLER_BUTTON_INVALID -1)
(define-public SDL_CONTROLLER_BUTTON_A 0)
(define-public SDL_CONTROLLER_BUTTON_B 1)
(define-public SDL_CONTROLLER_BUTTON_X 2)
(define-public SDL_CONTROLLER_BUTTON_Y 3)
(define-public SDL_CONTROLLER_BUTTON_BACK 4)
(define-public SDL_CONTROLLER_BUTTON_GUIDE 5)
(define-public SDL_CONTROLLER_BUTTON_START 6)
(define-public SDL_CONTROLLER_BUTTON_LEFTSTICK 7)
(define-public SDL_CONTROLLER_BUTTON_RIGHTSTICK 8)
(define-public SDL_CONTROLLER_BUTTON_LEFTSHOULDER 9)
(define-public SDL_CONTROLLER_BUTTON_RIGHTSHOULDER 10)
(define-public SDL_CONTROLLER_BUTTON_DPAD_UP 11)
(define-public SDL_CONTROLLER_BUTTON_DPAD_DOWN 12)
(define-public SDL_CONTROLLER_BUTTON_DPAD_LEFT 13)
(define-public SDL_CONTROLLER_BUTTON_DPAD_RIGHT 14)
(define-public SDL_CONTROLLER_BUTTON_MISC1 15)
(define-public SDL_CONTROLLER_BUTTON_PADDLE1 16)
(define-public SDL_CONTROLLER_BUTTON_PADDLE2 17)
(define-public SDL_CONTROLLER_BUTTON_PADDLE3 18)
(define-public SDL_CONTROLLER_BUTTON_PADDLE4 19)
(define-public SDL_CONTROLLER_BUTTON_TOUCHPAD 20)
(define-public SDL_CONTROLLER_BUTTON_MAX 21)

(define-foreign sdl-game-controller-add-mappings-from-rw
  int "SDL_GameControllerAddMappingsFromRW" (list '* int))

(define-foreign sdl-game-controller-add-mapping
  int "SDL_GameControllerAddMapping" '(*))

(define-foreign sdl-game-controller-open
  '* "SDL_GameControllerOpen" (list int))

(define-foreign sdl-game-controller-close
  void "SDL_GameControllerClose" '(*))

(define-foreign sdl-game-controller-event-state
  int "SDL_GameControllerEventState" (list int))

(define-foreign sdl-game-controller-from-instance-id
  '* "SDL_GameControllerFromInstanceID" (list int32))

(define-foreign sdl-game-controller-get-attached
  sdl-bool "SDL_GameControllerGetAttached" '(*))

(define-foreign sdl-game-controller-get-axis
  int16 "SDL_GameControllerGetAxis" (list '* int))

(define-foreign sdl-game-controller-get-axis-from-string
  int "SDL_GameControllerGetAxisFromString" '(*))

(define-foreign sdl-game-controller-get-string-for-axis
  '* "SDL_GameControllerGetStringForAxis" (list int))

(define-foreign sdl-game-controller-get-button
  uint8 "SDL_GameControllerGetButton" (list '* int))

(define-foreign sdl-game-controller-get-button-from-string
  int "SDL_GameControllerGetButtonFromString" '(*))

(define-foreign sdl-game-controller-get-string-for-button
  '* "SDL_GameControllerGetStringForButton" (list int))

(define-foreign sdl-game-controller-get-joystick
  '* "SDL_GameControllerGetJoystick" '(*))

(define-foreign sdl-game-controller-mapping
  '* "SDL_GameControllerMapping" '(*))

(define-foreign sdl-game-controller-mapping-for-guid
  '* "SDL_GameControllerMappingForGUID" '(*))

(define-foreign sdl-game-controller-name
  '* "SDL_GameControllerName" '(*))

(define-foreign sdl-game-controller-name-for-index
  '* "SDL_GameControllerNameForIndex" (list int))

(define-foreign sdl-game-controller-update
  void "SDL_GameControllerUpdate" '())

(define-foreign sdl-is-game-controller
  sdl-bool "SDL_IsGameController" (list int))


;;;
;;; Clipboard
;;;

(define-foreign sdl-get-clipboard-text
  '* "SDL_GetClipboardText" '())

(define-foreign sdl-set-clipboard-text
  int "SDL_SetClipboardText" '(*))

(define-foreign sdl-has-clipboard-text
  int "SDL_HasClipboardText" '())

;;;
;;; Hints
;;;

(define-public SDL_HINT_DEFAULT 0)
(define-public SDL_HINT_NORMAL 1)
(define-public SDL_HINT_OVERRIDE 2)

(define-foreign sdl-set-hint-with-priority
  sdl-bool "SDL_SetHintWithPriority" (list '* '* int))

(define-foreign sdl-get-hint
  '* "SDL_GetHint" (list '*))