1// This file is part of SmallBASIC
2//
3// keyboard map
4//
5// This program is distributed under the terms of the GPL v2.0 or later
6// Download the GNU Public License (GPL) from www.gnu.org
7//
8// Copyright(C) 2010 Chris Warren-Smith. [http://tinyurl.com/ja2ss]
9
10#include "common/var.h"
11
12#ifndef KEYMAP_H
13#define KEYMAP_H
14
15#if defined(__cplusplus)
16extern "C" {
17#endif
18
19#define PCKBSIZE 256
20
21// Keyboard codes
22#define SB_KEY_BACKSPACE 8
23#define SB_KEY_DELETE 127
24#define SB_KEY_BREAK 3
25#define SB_KEY_TAB 9
26#define SB_KEY_ENTER 13
27#define SB_KEY_SPACE 32
28#define SB_KEY_ESCAPE 27
29
30// first 16 - common with handhelds any extra key will be there
31#define SB_KEY_PGUP 0xFF01
32#define SB_KEY_PRIOR SB_KEY_PGUP
33#define SB_KEY_PGDN 0xFF02
34#define SB_KEY_NEXT SB_KEY_PGDN
35#define SB_KEY_LEFT 0xFF04
36#define SB_KEY_RIGHT 0xFF05
37#define SB_KEY_UP 0xFF09
38#define SB_KEY_DN 0xFF0A
39#define SB_KEY_DOWN SB_KEY_DN
40
41// second 16 - common on PCs
42#define SB_KEY_INSERT 0xFF10
43#define SB_KEY_HOME 0xFF11
44#define SB_KEY_END 0xFF12
45
46// other application keys
47#define SB_KEY_MENU 0xFF1F
48
49// function keys (16 codes)
50#define SB_KEY_F(x) (0xFFF0+(x))
51#define SB_KEY_SF(x) (0xFFE0+(x))
52
53// Control & Alt keys (parameter = capital character)
54#define SB_KEY_CTRL(c) (0x71000000 + (c))
55#define SB_KEY_ALT(c) (0x72000000 + (c))
56#define SB_KEY_CTRL_ALT(c) (0x73000000 + (c))
57#define SB_KEY_SHIFT(c) (0x74000000 + (c))
58#define SB_KEY_SHIFT_CTRL(c) (0x75000000 + (c))
59#define SB_KEY_ALT_SHIFT(c) (0x76000000 + (c))
60
61// keypad
62#define SB_KEY_KP_DIV 0xFFDA
63#define SB_KEY_KP_MUL 0xFFDB
64#define SB_KEY_KP_MINUS 0xFFDC
65#define SB_KEY_KP_PLUS 0xFFDD
66#define SB_KEY_KP_ENTER 0xFFDE
67#define SB_KEY_KP_HOME 0xFFD7
68#define SB_KEY_KP_UP 0xFFD8
69#define SB_KEY_KP_PGUP 0xFFD9
70#define SB_KEY_KP_LEFT 0xFFD4
71#define SB_KEY_KP_CENTER 0xFFD5
72#define SB_KEY_KP_RIGHT 0xFFD6
73#define SB_KEY_KP_END 0xFFD1
74#define SB_KEY_KP_DOWN 0xFFD2
75#define SB_KEY_KP_PGDN 0xFFD3
76#define SB_KEY_KP_INS 0xFFD0
77#define SB_KEY_KP_DEL 0xFFDF
78#define SB_KEY_MK_PUSH 0xFFC0
79#define SB_KEY_MK_DRAG 0xFFC1
80#define SB_KEY_MK_MOVE 0xFFC2
81#define SB_KEY_MK_RELEASE 0xFFC3
82#define SB_KEY_MK_WHEEL 0xFFC4
83#define SB_PKEY_SIZE_CHG 0xFFC5
84#define SB_KEY_MK_FIRST SB_KEY_MK_PUSH
85#define SB_KEY_MK_LAST SB_PKEY_SIZE_CHG
86
87void keymap_init();
88void keymap_free();
89void keymap_add(uint32_t key, bcip_t ip);
90void keymap_remove(uint32_t key, int level);
91int keymap_invoke(uint32_t key);
92int keymap_kbhit();
93int keymap_kbpeek();
94
95void timer_free(timer_s *timer);
96void timer_add(var_num_t timer, bcip_t ip);
97void timer_run(uint32_t now);
98
99#if defined(__cplusplus)
100}
101#endif
102
103#endif
104