-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
183 lines (166 loc) · 5.17 KB
/
main.c
File metadata and controls
183 lines (166 loc) · 5.17 KB
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
/* GFX demo app */
#include <unistd.h>
#include <sys/select.h>
#include "draw.h"
#include "sdl.h"
extern int open_pty(void);
static int term_fd;
extern int angle; /* in console.c */
static void clear_screen(Drawable *dp)
{
draw_clear(dp);
if (dp->font) {
draw_font_string(dp, dp->font, "Use '{' or '}' to rotate text", 20, 20,
0, 0, dp->fgcolor, dp->bgcolor, 1, 0);
}
}
static void sendhost(const char *str)
{
write(term_fd, str, strlen(str));
}
void tmt_callback(tmt_msg_t m, TMT *vt, const void *a, void *p)
{
if (m == TMT_MSG_ANSWER)
sendhost(a);
}
static int sdl_nextevent(struct console *con, struct console *con2)
{
int c;
SDL_Event event;
static int w = 20;
static int h = 10;
//while (SDL_WaitEvent(&event)) {
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_QUIT:
return 1;
case SDL_KEYDOWN:
c = sdl_key(event.key.state, event.key.keysym);
switch (c) {
case '\0': return 0;
case SDLK_UP:
sendhost(TMT_KEY_UP);
return 0;
case SDLK_DOWN:
sendhost(TMT_KEY_DOWN);
return 0;
case SDLK_RIGHT:
sendhost(TMT_KEY_RIGHT);
return 0;
case SDLK_LEFT:
sendhost(TMT_KEY_LEFT);
return 0;
/* test cases follow */
case '~': return 1;
case '_': console_resize(con, --w, --h); return 0;
case '+': console_resize(con, ++w, ++h); return 0;
case '{': angle--;
same:
clear_screen(con->dp);
console_dirty(con, 0, 0, con->cols, con->lines);
return 0;
case '}': angle++; goto same;
}
char c2 = c;
write(term_fd, &c2, 1);
}
}
fd_set fdset;
struct timeval tv;
int ret;
char buf[256];
FD_ZERO(&fdset);
FD_SET(term_fd, &fdset);
tv.tv_sec = 0;
tv.tv_usec = 30000;
ret = select(term_fd + 1, &fdset, NULL, NULL, &tv);
if (ret > 0) {
if (FD_ISSET(term_fd, &fdset)) {
int n = read(term_fd, buf, sizeof(buf));
if (n > 0)
console_write(con, buf, n);
}
}
return 0;
}
int main(int ac, char **av)
{
Drawable *dp;
struct sdl_window *sdl;
if (!sdl_init()) exit(1);
//if (!(dp = create_drawable(MWPF_DEFAULT, 640, 400))) exit(2);
if (!(dp = create_drawable(MWPF_DEFAULT, 1024, 800))) exit(2);
if (!(sdl = sdl_create_window(dp))) exit(3);
#if 1
term_fd = open_pty();
struct console *con;
struct console *con2 = NULL;
dp->font = font_load_font("times_30x37_8");
//dp->font = font_load_font("mssans_11x13_8");
if (!(con = create_console(80, 24))) exit(4);
//console_load_font(con, "unifont_8x16_1");
//console_load_font(con, "cour_11x19_8");
//console_load_font(con, "cour_21x37_8");
//console_load_font(con, "cour_20x37_1");
//console_load_font(con, "mssans_11x13_8");
//console_load_font(con, "rom_8x16_1");
//console_load_font(con, "DOSJ-437.F19");
//console_load_font(con, "VGA-ROM.F16");
//console_load_font(con, "COMPAQP3.F16");
//console_load_font(con, "DOSV-437.F16");
//console_load_font(con, "CGA.F08");
#if !OLDWAY
if (con->font->range == NULL) /* not likely a unicode font */
tmt_unicode_to_acs(con->vt, true);
#endif
//if (!(con2 = create_console(14, 8))) exit(4);
//con2->dp = dp;
//console_load_font(con2, "cour_20x37_1");
//console_load_font(con2, "cour_21x37_8");
//console_load_font(con2, "DOSJ-437.F19");
clear_screen(dp);
draw_flush(dp, 0, 0, 0, 0);
#if 2
/* test invalid UTF-8 */
//console_putchar(con, 0xc0);
//console_putchar(con2, 0xc1);
/* test undefined glyph */
//console_putchar(con, 127);
//console_putchar(con2, 127);
/* test unicode output */
for (int i=0x00A1; i<=0x00AF; i++) {
char buf[32];
int n = xwctomb(buf, i);
if (n > 0)
console_write(con, buf, n);
}
#endif
write(term_fd, "TERM=ansi\n", 10);
for (;;) {
//Rect update = con->update; /* save update rect for dup console */
int flush = angle? 2: 0;
draw_console(con, dp, 3*8, 5*15, flush);
//con->update = update;
//draw_console(con2, dp, 42*8, 5*15, flush);
draw_flush(dp, 0, 0, 0, 0);
if (sdl_nextevent(con, con2))
break;
//continue;
//int x1 = random() % 640;
//int x2 = random() % 640;
//int y1 = random() % 400;
//int y2 = random() % 400;
//int r = random() % 40;
//draw_line(dp, x1, y1, x2, y2);
//draw_thick_line(dp, x1, y1, x2, y2, 6);
//draw_circle(dp, x1, y1, r);
//draw_flood_fill(dp, x1, y1);
//draw_rect(dp, x1, y1, x2, y2);
//draw_fill_rect(dp, x1, y1, x2, y2);
}
free(con);
#endif
SDL_Quit();
free(sdl);
free(dp);
}