usim

Check-in [fd1498981c]
Login

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

Overview
Comment:Add rudimentary SDL2 support.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | ams/sdl1
Files: files | file ages | folders
SHA3-256: fd1498981cee4e988da852ce8f8f0295f1fc27a98c6f7e743e6a04a099e4570e
User & Date: ams 2024-06-04 17:44:18
Context
2024-06-04
17:47
sdl2.c: Fix color. check-in: 5de619b0f2 user: ams tags: ams/sdl1
17:44
Add rudimentary SDL2 support. check-in: fd1498981c user: ams tags: ams/sdl1
2024-06-01
05:18
sdl1.c: Fill in some of the keyboard mappings. check-in: a7a010e029 user: ams tags: ams/sdl1
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to Makefile.

29
30
31
32
33
34
35
36
37
38





39
40
41
42
43
44
45

# X11 as TV backend.
#CFLAGS  += -I/usr/X11R6/include -I/opt/local/include -DWITH_X11=1
#LDFLAGS += -lX11 -L/usr/X11R6/lib -L/opt/local/lib
#USIM_TV_BACKEND = x11.o

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






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

# Headless TV backend.
# CFLAGS +=
# LDFLAGS +=







|
|
|
>
>
>
>
>







29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50

# X11 as TV backend.
#CFLAGS  += -I/usr/X11R6/include -I/opt/local/include -DWITH_X11=1
#LDFLAGS += -lX11 -L/usr/X11R6/lib -L/opt/local/lib
#USIM_TV_BACKEND = x11.o

# 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.
# CFLAGS +=
# LDFLAGS +=

Changes to cadet.c.

183
184
185
186
187
188
189





190
191
192
193
194
195
196
		DEBUG(TRACE_KBD, "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
cadet_allup_key(void)
{
}
#endif

static void







>
>
>
>
>







183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
		DEBUG(TRACE_KBD, "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
cadet_allup_key(void)
{
}
#elif WITH_SDL2
bool
cadet_allup_key(void)
{
}
#endif

static void

Added sdl2.c.































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
/* sdl2.c --- SDL2 routines used by the TV and KBD interfaces
 */

#include <signal.h>

#include <SDL.h>

#include "tv.h"
#include "kbd.h"
#include "mouse.h"
#include "utrace.h"
#include "idle.h"

SDL_Window *window;
SDL_Renderer *renderer;
SDL_Texture *texture;

/*
 * Translation map for the host keyboard to a corresponding Lisp
 * Machine character or modifier.
 */
int sdl2_kbd_map[65535];
int sdl2_modifier_map[8];

/*
 * This is shared between x11.c, and sdl2.c ... the only difference is
 * the hook in send_accumulated_updates.
 */

unsigned long Background;
unsigned long Foreground;

static int u_minh = 0x7fffffff;
static int u_maxh;
static int u_minv = 0x7fffffff;
static int u_maxv;

void
accumulate_update(int h, int v, int hs, int vs)
{
	if (h < u_minh)
		u_minh = h;
	if (h + hs > u_maxh)
		u_maxh = h + hs;
	if (v < u_minv)
		u_minv = v;
	if (v + vs > u_maxv)
		u_maxv = v + vs;
}

static void
send_accumulated_updates(void)
{
	int hs;
	int vs;

	hs = u_maxh - u_minh;
	vs = u_maxv - u_minv;
	if (u_minh != 0x7fffffff && u_minv != 0x7fffffff && u_maxh && u_maxv) {
		SDL_UpdateTexture(texture, NULL, tv_bitmap, tv_width * sizeof (Uint32));
		// Flush
		SDL_RenderClear(renderer);
		SDL_RenderCopy(renderer, texture, NULL, NULL);
		SDL_RenderPresent(renderer);
	}
	u_minh = 0x7fffffff;
	u_maxh = 0;
	u_minv = 0x7fffffff;
	u_maxv = 0;
}

static void
process_key(SDL_KeyboardEvent *e, int keydown)
{
}

void
sdl2_event(void)
{
	SDL_Event ev1, *ev = &ev1;
	
	send_accumulated_updates();
	kbd_dequeue_key_event();
	while (SDL_PollEvent(ev)) {
		switch (ev->type) {
		case SDL_WINDOWEVENT:
			SDL_UpdateTexture(texture, NULL, tv_bitmap, tv_width * sizeof (Uint32));
			// flush
			SDL_RenderClear(renderer);
			SDL_RenderCopy(renderer, texture, NULL, NULL);
			SDL_RenderPresent(renderer);
			break;
		case SDL_QUIT:
			exit(0);
			break;
		}
	}
}

void
sdl2_default_kbd_map(void)
{
	for (int i = 0; i < (int) NELEM(sdl2_kbd_map); i++)
		sdl2_kbd_map[i] = LMCH_NoSymbol;
	for (int i = 0; i < (int) NELEM(sdl2_modifier_map); i++)
		sdl2_modifier_map[i] = KBD_NoSymbol;
}

void
sdl2_init(void)
{
	NOTICE(TRACE_USIM, "tv: using SDL backend for monitor and keyboard\n"); 

	Foreground = 0xff; // White
	Background = 0x0011; // Black

//screen = SDL_CreateWindow("CADR",
//                          SDL_WINDOWPOS_UNDEFINED,
//                          SDL_WINDOWPOS_UNDEFINED,
//                          tv_width, tv_height,
//                          SDL_WINDOW_OPENGL);


	SDL_CreateWindowAndRenderer(tv_width, tv_height, SDL_WINDOW_OPENGL, &window, &renderer);


	SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
	SDL_RenderClear(renderer);
	SDL_RenderPresent(renderer);


	SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");  // make the scaled rendering look smoother.
	SDL_RenderSetLogicalSize(renderer, tv_width, tv_height);

	texture = SDL_CreateTexture(renderer,
				    SDL_PIXELFORMAT_ARGB8888,
				    SDL_TEXTUREACCESS_STREAMING,
				    tv_width, tv_height);




}

Added sdl2.h.

























>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
#pragma once

#include <SDL2/SDL.h>

extern void sdl2_init(void);
extern void sdl2_default_kbd_map(void);
extern void sdl2_event(void);

extern unsigned long Background;
extern unsigned long Foreground;

extern void accumulate_update(int, int, int, int);

Changes to tv.c.

10
11
12
13
14
15
16


17
18
19
20
21
22
23
#include "tv.h"
#include "ucode.h"
#include "utrace.h"
#if WITH_X11
#include "x11.h"
#elif WITH_SDL1
#include "sdl1.h"


#endif

int tv_monitor = 1;		/* Default is Other (1). */

uint32_t tv_width;
uint32_t tv_height;
uint32_t tv_bitmap[1024 * 1024];







>
>







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include "tv.h"
#include "ucode.h"
#include "utrace.h"
#if WITH_X11
#include "x11.h"
#elif WITH_SDL1
#include "sdl1.h"
#elif WITH_SDL2
#include "sdl2.h"
#endif

int tv_monitor = 1;		/* Default is Other (1). */

uint32_t tv_width;
uint32_t tv_height;
uint32_t tv_bitmap[1024 * 1024];
146
147
148
149
150
151
152


153
154
155
156
157
158
159
void
tv_poll(void)
{
#ifdef WITH_X11
	x11_event();
#elif WITH_SDL1
	sdl1_event();


#endif
}

void
tv_init(void)
{
	tv_colorbit = 0;







>
>







148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
void
tv_poll(void)
{
#ifdef WITH_X11
	x11_event();
#elif WITH_SDL1
	sdl1_event();
#elif WITH_SDL2
	sdl2_event();
#endif
}

void
tv_init(void)
{
	tv_colorbit = 0;
172
173
174
175
176
177
178


179
180
181
182
183
184
185
		errx(1, "unknown monitor type: %d", tv_monitor);
		break;
	}
#ifdef WITH_X11
	x11_init();
#elif WITH_SDL1
	sdl1_init();


#endif
	{
		struct itimerval itimer;
		int usecs;

		signal(SIGVTALRM, sigalrm_handler);
		usecs = 16000;







>
>







176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
		errx(1, "unknown monitor type: %d", tv_monitor);
		break;
	}
#ifdef WITH_X11
	x11_init();
#elif WITH_SDL1
	sdl1_init();
#elif WITH_SDL2
	sdl2_init();
#endif
	{
		struct itimerval itimer;
		int usecs;

		signal(SIGVTALRM, sigalrm_handler);
		usecs = 16000;

Changes to x11.c.

496
497
498
499
500
501
502
503
504
505
506
	 */
	do
		XNextEvent(display, &e);
	while (e.type != Expose || e.xexpose.count);
	XFlush(display);
	ximage = XCreateImage(display, visual, (unsigned) color_depth, ZPixmap, 0, (char *) tv_bitmap, tv_width, tv_height, 32, 0);
	ximage->byte_order = LSBFirst;

	idle_gc = XCreateGC(display, window, 0, 0);
	register_idle_change_handler(x11_idle_change_handler);
}







<



496
497
498
499
500
501
502

503
504
505
	 */
	do
		XNextEvent(display, &e);
	while (e.type != Expose || e.xexpose.count);
	XFlush(display);
	ximage = XCreateImage(display, visual, (unsigned) color_depth, ZPixmap, 0, (char *) tv_bitmap, tv_width, tv_height, 32, 0);
	ximage->byte_order = LSBFirst;

	idle_gc = XCreateGC(display, window, 0, 0);
	register_idle_change_handler(x11_idle_change_handler);
}