usim

Check-in [9835eb47e1]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Meh .. X11 / SDL2 stuff.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | ams/sdl
Files: files | file ages | folders
SHA3-256: 9835eb47e165c8d9964d8f99d5ccdde1c77dcea2f448c84ac585ff6ee79c0a89
User & Date: ams 2024-06-17 13:58:23
Context
2024-06-18
07:02
sdl2.c: Include <X11/keysym.h> and <X11/X.h>. check-in: 401803fc1b user: ams tags: ams/sdl
2024-06-17
13:58
Meh .. X11 / SDL2 stuff. check-in: 9835eb47e1 user: ams tags: ams/sdl
13:47
Some minor cleaning and stuff ... check-in: c4512a7049 user: ams tags: ams/sdl
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to Makefile.

34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

# SDL (version 1) as TV backend.
#CFLAGS += $(shell sdl-config --cflags) -DWITH_SDL1=1 
#LDFLAGS += $(shell sdl-config --libs)
#USIM_TV_BACKEND = sdl1.o

# SDL (version 2) as TV backend.
CFLAGS += $(shell sdl2-config --cflags) -DWITH_SDL2=1 
LDFLAGS += $(shell sdl2-config --libs)
USIM_TV_BACKEND = sdl2.o

# Bullshit hack.
CFLAGS += -I/opt/homebrew/include -Wno-nonportable-include-path

# Headless TV backend.







|







34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

# SDL (version 1) as TV backend.
#CFLAGS += $(shell sdl-config --cflags) -DWITH_SDL1=1 
#LDFLAGS += $(shell sdl-config --libs)
#USIM_TV_BACKEND = sdl1.o

# SDL (version 2) as TV backend.
CFLAGS += $(shell sdl2-config --cflags) -DWITH_SDL2=1  -I/usr/X11R6/include
LDFLAGS += $(shell sdl2-config --libs)
USIM_TV_BACKEND = sdl2.o

# Bullshit hack.
CFLAGS += -I/opt/homebrew/include -Wno-nonportable-include-path

# Headless TV backend.

Changes to cadet.c.

69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
	int v;

	v = (1 << 15) | (mods & 01777);
	if (iob_csr & (1 << 5))
		kbd_queue_key_event(v);	/* Already something there, queue this. */
	else {
		kbd_scancode = (1 << 16) | v;
//		printf("cadet_allup_event() - kbd_scancode = 0%o\n", kbd_scancode);
		if (iob_csr & (1 << 2)) {
			iob_csr |= 1 << 5;
			assert_unibus_interrupt(0260);
		}
	}
}








|







69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
	int v;

	v = (1 << 15) | (mods & 01777);
	if (iob_csr & (1 << 5))
		kbd_queue_key_event(v);	/* Already something there, queue this. */
	else {
		kbd_scancode = (1 << 16) | v;
		printf("cadet_allup_event() - kbd_scancode = 0%o\n", kbd_scancode);
		if (iob_csr & (1 << 2)) {
			iob_csr |= 1 << 5;
			assert_unibus_interrupt(0260);
		}
	}
}

120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
		bucky = modifier_map[modifier];
		for (int i = 0; i < modmap->max_keypermod; i++) {
			KeyCode keycode;

			keycode = modmap->modifiermap[modifier * modmap->max_keypermod + i];
			if (keymap[keycode / 8] & (1 << keycode % 8)) {
				keymap[keycode / 8] &= ~(1 << keycode % 8);	/* Clear the key in KEYMAP. */
//				printf("cadet_allup_key() - bucky pressed (%d); keycode = %d\n", bucky, keycode);
				switch (bucky) {
				case KBD_SHIFT:
					mods |= CADET_ALLUP_SHIFT;
					shifts |= (1 << CADET_IX_SHIFT);
					break;
				case KBD_TOP:
					mods |= CADET_ALLUP_TOP;







|







120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
		bucky = modifier_map[modifier];
		for (int i = 0; i < modmap->max_keypermod; i++) {
			KeyCode keycode;

			keycode = modmap->modifiermap[modifier * modmap->max_keypermod + i];
			if (keymap[keycode / 8] & (1 << keycode % 8)) {
				keymap[keycode / 8] &= ~(1 << keycode % 8);	/* Clear the key in KEYMAP. */
				printf("cadet_allup_key() - bucky pressed (%d); keycode = %d\n", bucky, keycode);
				switch (bucky) {
				case KBD_SHIFT:
					mods |= CADET_ALLUP_SHIFT;
					shifts |= (1 << CADET_IX_SHIFT);
					break;
				case KBD_TOP:
					mods |= CADET_ALLUP_TOP;
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
				case KBD_HYPER:
					mods |= CADET_ALLUP_HYPER;
					break;
				case KBD_SUPER:
					mods |= CADET_ALLUP_SUPER;
					break;
				default:
//					printf("kbd (cadet): unknown bucky key: 0%o\n", modifier_map[modifier]);
					break;
				}
			}
		}
	}
	XFreeModifiermap(modmap);
	/*
	 * Check if any other key than modifiers (that got cleared
	 * above) are set.  If that is the case, do not generate an
	 * all-up event.
	 */
	for (int i = 0; i < 32; i++) {
		if (keymap[i] != 0) {
//			printf("cadet_allup_key() - found a key that is up which is not a shift; keymap[%d] = 0%o\n", i, keymap[i]);
			allup = false;
			break;
		}
	}
	if (allup == true) {
//		printf("cadet_allup_key() - all-up event; mods = 0%o, shifts = 0%o\n", mods, shifts);
		cadet_shifts = shifts;	 /* Keep track of shifts.  */
		cadet_allup_event(mods); /* Generate all-up event. */
	}
	return allup;
}
#elif WITH_SDL1
bool







|













|





|







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
				case KBD_HYPER:
					mods |= CADET_ALLUP_HYPER;
					break;
				case KBD_SUPER:
					mods |= CADET_ALLUP_SUPER;
					break;
				default:
					printf("kbd (cadet): unknown bucky key: 0%o\n", modifier_map[modifier]);
					break;
				}
			}
		}
	}
	XFreeModifiermap(modmap);
	/*
	 * Check if any other key than modifiers (that got cleared
	 * above) are set.  If that is the case, do not generate an
	 * all-up event.
	 */
	for (int i = 0; i < 32; i++) {
		if (keymap[i] != 0) {
			printf("cadet_allup_key() - found a key that is up which is not a shift; keymap[%d] = 0%o\n", i, keymap[i]);
			allup = false;
			break;
		}
	}
	if (allup == true) {
		printf("cadet_allup_key() - all-up event; mods = 0%o, shifts = 0%o\n", mods, shifts);
		cadet_shifts = shifts;	 /* Keep track of shifts.  */
		cadet_allup_event(mods); /* Generate all-up event. */
	}
	return allup;
}
#elif WITH_SDL1
bool
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
	state = SDL_GetKeyboardState(&statesize);
	for (int i = 0; allup && i < statesize; i++) {
		int bucky;

		if (state[i] != 1)
			continue;
		bucky = modifier_map[i];
//		printf("cadet_allup_key() - bucky pressed (%d), i = %d\n", bucky, i);
		switch (bucky) {
		case KBD_SHIFT:
			mods |= CADET_ALLUP_SHIFT;
			shifts |= (1 << CADET_IX_SHIFT);
			break;
		case KBD_TOP:
			mods |= CADET_ALLUP_TOP;







|







211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
	state = SDL_GetKeyboardState(&statesize);
	for (int i = 0; allup && i < statesize; i++) {
		int bucky;

		if (state[i] != 1)
			continue;
		bucky = modifier_map[i];
		printf("cadet_allup_key() - bucky pressed (%d), i = %d\n", bucky, i);
		switch (bucky) {
		case KBD_SHIFT:
			mods |= CADET_ALLUP_SHIFT;
			shifts |= (1 << CADET_IX_SHIFT);
			break;
		case KBD_TOP:
			mods |= CADET_ALLUP_TOP;
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
		case KBD_HYPER:
			mods |= CADET_ALLUP_HYPER;
			break;
		case KBD_SUPER:
			mods |= CADET_ALLUP_SUPER;
			break;
		default:
//			printf("kbd (cadet): unknown bucky key: 0%o\n", modifier_map[i]);
			/* Hack: ignore modifier key which isn't bound */
//			if (i >= SDLK_NUMLOCK && i <= SDLK_COMPOSE)
//				break;
			allup = false;
			break;
		}
	}
	if (allup == true) {
//		printf("cadet_allup_key() - all-up event; mods = 0%o, shifts = 0%o\n", mods, shifts);
		cadet_shifts = shifts;
		cadet_allup_event(mods);
	}
	return allup;
}
#endif

static void
cadet_process_shift(int scc, int keydown)
{
//	printf("cadet_process_shift(scc = 0%o, keydown = %d)\n", scc, keydown);
	if (keydown) {
		if ((scc == CADET_LEFT_GREEK) || (scc == CADET_RIGHT_GREEK))
			cadet_shifts |= (1 << CADET_IX_GREEK);
		else if ((scc == CADET_LEFT_TOP) || (scc == CADET_RIGHT_TOP))
			cadet_shifts |= (1 << CADET_IX_TOP);
		else if ((scc == CADET_LEFT_SHIFT) || (scc == CADET_RIGHT_SHIFT))
			cadet_shifts |= (1 << CADET_IX_SHIFT);







|








|










|







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
		case KBD_HYPER:
			mods |= CADET_ALLUP_HYPER;
			break;
		case KBD_SUPER:
			mods |= CADET_ALLUP_SUPER;
			break;
		default:
			printf("kbd (cadet): unknown bucky key: 0%o\n", modifier_map[i]);
			/* Hack: ignore modifier key which isn't bound */
//			if (i >= SDLK_NUMLOCK && i <= SDLK_COMPOSE)
//				break;
			allup = false;
			break;
		}
	}
	if (allup == true) {
		printf("cadet_allup_key() - all-up event; mods = 0%o, shifts = 0%o\n", mods, shifts);
		cadet_shifts = shifts;
		cadet_allup_event(mods);
	}
	return allup;
}
#endif

static void
cadet_process_shift(int scc, int keydown)
{
	printf("cadet_process_shift(scc = 0%o, keydown = %d)\n", scc, keydown);
	if (keydown) {
		if ((scc == CADET_LEFT_GREEK) || (scc == CADET_RIGHT_GREEK))
			cadet_shifts |= (1 << CADET_IX_GREEK);
		else if ((scc == CADET_LEFT_TOP) || (scc == CADET_RIGHT_TOP))
			cadet_shifts |= (1 << CADET_IX_TOP);
		else if ((scc == CADET_LEFT_SHIFT) || (scc == CADET_RIGHT_SHIFT))
			cadet_shifts |= (1 << CADET_IX_SHIFT);
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
	int wantshift;		/* Index into second column in cadet_kbd_map. */
	int shkey;		/* Shift key being pressed. */
	int oshift;

	if (!keydown && cadet_allup_key() == true)
		return;
	oshift = cadet_shifts;
//	printf("kbd (cadet): keysym = 0%o, bi = %d\n", keysym, bi);
	if (bi != -1) {
		int bucky;

		bucky = modifier_map[bi];
		if (bucky == KBD_NoSymbol) {
//			printf("kbd (cadet): unbound modifier (keysym = 0%o)\n", keysym);
			return;
		}
		scc = cadet_modifier_map[bucky];
		cadet_process_shift(scc, keydown);
//		printf("kbd (cadet): bucky pressed; scc = 0%o, shifts = 0%o (previous: 0%o)\n", scc, cadet_shifts, oshift);
		kbd_event(scc, keydown);
		return;
	}
	lmchar = kbd_map[keysym];
//	printf("kbd (cadet): kbd_map[%d] (lmchar) = 0%o\n", keysym, kbd_map[keysym]);
	if (lmchar > LMCH_CODE_LIMIT || lmchar == LMCH_NoSymbol) {
//		printf("kbd (cadet): unable to translate to lispm key (keysym = 0%o)\n", keysym);
		return;
	}
	scc = cadet_kbd_map[lmchar][0];
	wantshift = cadet_kbd_map[lmchar][1];
//	printf("kbd (cadet): non bucky pressed; scc = 0%o, wantshift = %d\n", scc, wantshift);
	/*
	 * If modifiers correct, just post the event, else
	 * queue the event and post the appropriate shifts.
	 */
	if (((wantshift == CADET_IX_UNSHIFT) && ((cadet_shifts & (1 << CADET_IX_SHIFT)) == 0)) || (cadet_shifts & (1 << wantshift))) {
		kbd_event(scc, keydown);
		return;







|





|




|




|

|




|







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
	int wantshift;		/* Index into second column in cadet_kbd_map. */
	int shkey;		/* Shift key being pressed. */
	int oshift;

	if (!keydown && cadet_allup_key() == true)
		return;
	oshift = cadet_shifts;
	printf("kbd (cadet): keysym = 0%o, bi = %d\n", keysym, bi);
	if (bi != -1) {
		int bucky;

		bucky = modifier_map[bi];
		if (bucky == KBD_NoSymbol) {
			printf("kbd (cadet): unbound modifier (keysym = 0%o)\n", keysym);
			return;
		}
		scc = cadet_modifier_map[bucky];
		cadet_process_shift(scc, keydown);
		printf("kbd (cadet): bucky pressed; scc = 0%o, shifts = 0%o (previous: 0%o)\n", scc, cadet_shifts, oshift);
		kbd_event(scc, keydown);
		return;
	}
	lmchar = kbd_map[keysym];
	printf("kbd (cadet): kbd_map[%d] (lmchar) = 0%o\n", keysym, kbd_map[keysym]);
	if (lmchar > LMCH_CODE_LIMIT || lmchar == LMCH_NoSymbol) {
		printf("kbd (cadet): unable to translate to lispm key (keysym = 0%o)\n", keysym);
		return;
	}
	scc = cadet_kbd_map[lmchar][0];
	wantshift = cadet_kbd_map[lmchar][1];
	printf("kbd (cadet): non bucky pressed; scc = 0%o, wantshift = %d\n", scc, wantshift);
	/*
	 * If modifiers correct, just post the event, else
	 * queue the event and post the appropriate shifts.
	 */
	if (((wantshift == CADET_IX_UNSHIFT) && ((cadet_shifts & (1 << CADET_IX_SHIFT)) == 0)) || (cadet_shifts & (1 << wantshift))) {
		kbd_event(scc, keydown);
		return;

Changes to sdl2.c.

329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
//		if (mod & Mod4Mask)
//			knight_process_bucky(Mod4MapIndex, &bi);
//		if (mod & Mod5Mask)
//			knight_process_bucky(Mod5MapIndex, &bi);
		knight_process_key(e.keysym.sym, bi, keydown);
	} else {
		bi = sdl2_bucky(e.keysym.mod);

		cadet_process_key(keysym, bi, keydown);
	}
}

void
sdl2_event(void)
{







<







329
330
331
332
333
334
335

336
337
338
339
340
341
342
//		if (mod & Mod4Mask)
//			knight_process_bucky(Mod4MapIndex, &bi);
//		if (mod & Mod5Mask)
//			knight_process_bucky(Mod5MapIndex, &bi);
		knight_process_key(e.keysym.sym, bi, keydown);
	} else {
		bi = sdl2_bucky(e.keysym.mod);

		cadet_process_key(keysym, bi, keydown);
	}
}

void
sdl2_event(void)
{
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
		case SDL_KEYUP:
			process_key(ev.key, 0);
			break;
		case SDL_MOUSEMOTION:
		case SDL_MOUSEBUTTONDOWN:
		case SDL_MOUSEBUTTONUP:
			// Need to at least go past date prompt for mouse to work.
//			mouse_event(ev.button.x, ev.button.y, ev.button.button);
			break;
		case SDL_QUIT:
			exit(0);
			break;
		}
	}
}







|







363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
		case SDL_KEYUP:
			process_key(ev.key, 0);
			break;
		case SDL_MOUSEMOTION:
		case SDL_MOUSEBUTTONDOWN:
		case SDL_MOUSEBUTTONUP:
			// Need to at least go past date prompt for mouse to work.
			mouse_event(ev.button.x, ev.button.y, ev.button.button);
			break;
		case SDL_QUIT:
			exit(0);
			break;
		}
	}
}