File: keytest.c

package info (click to toggle)
hatari 2.2.0%2Bdfsg-1
  • links: PTS
  • area: main
  • in suites: buster
  • size: 11,932 kB
  • sloc: ansic: 160,820; python: 5,589; objc: 1,913; asm: 1,523; sh: 1,348; makefile: 99; xml: 32
file content (168 lines) | stat: -rw-r--r-- 3,599 bytes parent folder | download | duplicates (4)
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
/* ------------------------------------
 * Program to show what keycodes evnt_multi & co.
 * return...
 */

#ifdef __AHCC__
# include <aes.h>
# include <tos.h>
#else
# ifdef __SOZOBONX__
#  include <minimum.h>
#  include <osbind.h>
#  include <xgemfast.h>
# endif
#endif
#include <stdlib.h>
#include <stdio.h>

#ifndef FALSE
#define FALSE 0
#define TRUE  !FALSE
#endif

/* resource set indices for KEYTEST */
#define TREEMENU   0 /* menu */
#define MENUINFO   7 /* STRING in tree TREE001 */
#define MENUTABL  16 /* STRING in tree TREE001 */
#define MENUQUIT  18 /* STRING in tree TREE001 */

#define MY_MU (MU_MESAG | MU_KEYBD)

OBJECT *tree_menu;

/* ------------------------------------
 * Function prototypes.
 */
static void prg_init (void);
static void prg_exit (void);
static void msg_handler (short *msgbuf);
static void do_menu (short entry);
static void ascii_table (void);
static void show_key (short key, short state);

/* ------------------------------------
 * Standard GEM handling functions (main loop).
 */

int main()
{
	short  mbuf[8];
	short  evnt_m, m1fl, pmx1, pmy1, pm1w, pm1h,
	       m2fl, pmx2, pmy2, pm2w, pm2h, pmx, pmy, pmstate,
	       state, key, clicks, tlo_cnt, thi_cnt;
	m1fl = pmx1 = pmy1 = pm1w = pm1h = 0;
	m2fl = pmx2 = pmy2 = pm2w = pm2h = 0;
	tlo_cnt = thi_cnt = 0;

	prg_init ();
	graf_mouse(0, ARROW);
	while (TRUE) {
		/* mouse button, mouse co-ordinate 1,
		 * mouse co-ordinate 2, message and timer events.
		 * mouse co-ordinate, mouse button, special key and normal key states.
		 * number of mouse clicks.
		 */
		evnt_m = evnt_multi(MY_MU, 259, 3, 0, m1fl, pmx1, pmy1, pm1w, pm1h,
				    m2fl, pmx2, pmy2, pm2w, pm2h, mbuf, tlo_cnt, thi_cnt,
				    &pmx, &pmy, &pmstate ,&state, &key, &clicks);

		if (evnt_m & MU_MESAG)
			msg_handler (mbuf);

		if (evnt_m & MU_KEYBD)
			show_key (key, state);
	}
	return 0;
}

/* ------------------------------------
 * GEM startup.
 */
static void prg_init (void)
{
	appl_init ();

	if (!rsrc_load ("keytest.rsc")) {
		appl_exit ();
		exit (1);
	}

	/* TREEMENU should be defines, generated by the rsc editor */
	rsrc_gaddr (R_TREE, TREEMENU, &tree_menu);
	menu_bar (tree_menu, TRUE);		/* show menubar */
}

/* GEM exit. */
static void prg_exit (void)
{
	menu_bar (tree_menu, FALSE);
	rsrc_free ();
	appl_exit ();
	exit (0);
}

/* message handling code. */
static void msg_handler (short *msgbuf)
{
	switch (msgbuf[0]) {
	case MN_SELECTED:
		/* handle menu entry */
		do_menu (msgbuf[4]);
		/* de-invert menu title */
		menu_tnormal (tree_menu, msgbuf[3], 1);
		break;
	}
}

/* ------------------------------------
 * Selection handling functions.
 */
static void do_menu (short entry)
{
	switch (entry) {
	case MENUINFO:
		form_alert (1, "[1][|Show keycodes and status|  of shift/alt/ctrl as|returned by evnt_multi()][ OK ]");
		break;

	case MENUTABL:
		ascii_table ();
		break;
		
	case MENUQUIT:
		prg_exit ();
	}
}

static void ascii_table (void)
{
	int x, y;
	Cconws ("\33Y#  . | 0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f \15\12");
	Cconws ("----------------------------------------------------\15\12");

	for (y = 2; y < 16; y ++) {
		Cconout(' ');
		Cconout('0' + y);
		Cconout(' ');
		Cconout('|');
		
		for (x = 0; x < 16; x ++) {
			Cconout(' ');
			Cconout(x + y * 0x10);
			Cconout(' ');
		}
		Cconws("\15\12");
	}
}

void show_key (short key, short state)
{
	char  buf[128];

	sprintf (buf, "[1][Mod state:  $%02x (%d)|Scan code:  $%02x (%d)|ASCII code: $%02x (%d)][ OK ]",
		 state, state, key>>8, key>>8, key&0xff, key&0xff);
	form_alert (1, buf);

	if ((key & 0xFF) == 27)
		prg_exit ();
}