-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgecon.c
319 lines (268 loc) · 5.33 KB
/
gecon.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
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
#define _XOPEN_SOURCE 600
#define _DEFAULT_SOURCE
#include <SDL.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdarg.h>
#include <ctype.h>
#include <unistd.h>
#include <signal.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <pwd.h>
#include <termios.h>
#include <poll.h>
#include <errno.h>
#include <pthread.h>
#include <assert.h>
#include <math.h>
#include "terminal.h"
#include "args.h"
//Col phos1 = { 0xFF, 0x82, 0xFF, 0x0F };
Col phos1 = { 0xFF, 0x9F, 0xFF, 0x47 };
Col phos2 = { 0xFF, 0x68, 0xCC, 0x0C };
float Gamma = 1.0/2.2f;
#include "gechars.h"
#define TERMWIDTH 46
#define TERMHEIGHT 26
#define HSPACE 0
#define VSPACE 0
#define FBWIDTH (TERMWIDTH*(CWIDTH+HSPACE)+2*2)
#define FBHEIGHT (TERMHEIGHT*(CHEIGHT+VSPACE)+2*2)
#define WIDTH (2*FBWIDTH)
#define HEIGHT (2*FBHEIGHT)
SDL_Surface *screen;
SDL_Window *window;
SDL_Renderer *renderer;
SDL_Texture *screentex;
const u8 *keystate;
char fb[TERMHEIGHT][TERMWIDTH];
int curx, cury;
int updatebuf = 1;
int updatescreen = 1;
int blink;
int rerun = 0;
int scale = 1;
int full = 0;
SDL_Texture *fonttex[65];
int pty;
#define TEXW ((CWIDTH*2 + BLURRADIUS*2))
#define TEXH ((CHEIGHT*2 + BLURRADIUS*2))
void
createchar(u32 *raster, int c)
{
int i, j;
char *chr = font[c + ' '];
memset(raster, 0, TEXW*TEXH*sizeof(u32));
raster = &raster[BLURRADIUS*TEXW + BLURRADIUS];
for(i = 0; i < CHEIGHT; i++){
for(j = 0; j < CWIDTH; j++){
if(chr[i*CWIDTH+j] == '*'){
raster[(i*2+0)*TEXW + j*2] = 0xFF;
raster[(i*2+0)*TEXW + j*2+1] = 0xFF;
// uncomment to disable scanlines
// raster[(i*2+1)*TEXW + j*2] = 0xFF;
// raster[(i*2+1)*TEXW + j*2+1] = 0xFF;
}
}
}
}
void
blurchar(u32 *dst, u32 *src)
{
Col *s, *d, c;
int x, y;
s = (Col*)src;
d = (Col*)dst;
for(y = 0; y < TEXH; y++){
for(x = 0; x < TEXW; x++){
c = getblur(s, TEXW, TEXH, x, y);
c.a = 255;
d[y*TEXW + x] = c;
}
}
}
void
createfont(void)
{
int i;
int w, h;
u32 *ras1, *ras2;
w = TEXW;
h = TEXH;
ras1 = malloc(w*h*sizeof(u32));
ras2 = malloc(w*h*sizeof(u32));
for(i = 0; i < 65; i++){
createchar(ras1, i);
blurchar(ras2, ras1);
fonttex[i] = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888,
SDL_TEXTUREACCESS_STREAMING, w, h);
SDL_SetTextureBlendMode(fonttex[i], SDL_BLENDMODE_ADD);
SDL_UpdateTexture(fonttex[i], nil, ras2, w*sizeof(u32));
}
}
void
draw(void)
{
int x, y, c;
SDL_Rect r;
r.x = 0;
r.y = 0;
r.w = TEXW;
r.h = TEXH;
if(updatebuf){
updatebuf = 0;
SDL_SetRenderTarget(renderer, screentex);
SDL_SetRenderDrawColor(renderer, 21, 13, 6, 0);
SDL_RenderClear(renderer);
for(x = 0; x < TERMWIDTH; x++)
for(y = 0; y < TERMHEIGHT; y++){
c = fb[y][x];
if(blink && x == curx && y == cury)
c = '_'+1;
if(c >= ' '){
r.x = (2 + x*(CWIDTH+HSPACE))*2 - BLURRADIUS;
r.y = (2 + y*(CHEIGHT+VSPACE))*2 - BLURRADIUS;
SDL_RenderCopy(renderer, fonttex[c-' '], nil, &r);
}
}
SDL_SetRenderTarget(renderer, nil);
updatescreen = 1;
}
if(updatescreen){
updatescreen = 0;
SDL_RenderCopy(renderer, screentex, nil, nil);
SDL_RenderPresent(renderer);
}
}
void
recvchar(int c)
{
int x, y;
if(c == 0136){
fb[cury][curx++] = ' ';
/* blink */
}else if(c >= 040){
/* make characters printable */
if(c >= 0140 && c <= 0177)
c &= ~040;
fb[cury][curx++] = c;
}else switch(c){
case 010: /* BS */
curx--;
break;
case 012: /* LF */
LF:
cury++;
if(cury >= TERMHEIGHT)
cury = 0;
break;
case 014: /* FF */
for(y = 0; y < TERMHEIGHT; y++)
for(x = 0; x < TERMWIDTH; x++)
fb[y][x] = ' ';
goto PR;
break;
case 015: /* CR */
curx = 0;
break;
case 021: /* RLF */
cury--;
break;
case 022: /* FS */
curx++;
if(curx >= TERMWIDTH) {
curx = 0;
goto LF;
}
break;
case 024: /* PR */
PR:
curx = 0;
cury = 0;
break;
}
if(curx < 0)
curx = 0;
if(curx >= TERMWIDTH){
curx = 0;
goto LF;
}
if(cury < 0)
cury = 0;
if(cury >= TERMHEIGHT)
cury = TERMHEIGHT-1;
updatebuf = 1;
}
void*
timethread(void *arg)
{
(void)arg;
/* Cursor blink 7.5 cycles per second. */
struct timespec slp = { 0, 1000*1000*1000/3.25f };
for(;;){
blink = !blink;
updatebuf = 1;
nanosleep(&slp, nil);
}
}
char TERM[] = "dumb";
char *argv0;
char *name;
void
usage(void)
{
panic("usage: %s [-2] [-B] [-f] [-b baudrate] command...", argv0);
}
int
main(int argc, char *argv[])
{
int x, y;
pthread_t thr1, thr2;
struct winsize ws;
scancodemap = scancodemap_upper;
ARGBEGIN{
case 'b':
baud = atoi(EARGF(usage()));
break;
case 'B':
/* Backspace is Rubout. */
scancodemap[SDL_SCANCODE_BACKSPACE] = "\177\177";
break;
case 'r':
rerun = 1;
break;
case '2':
scale++;
break;
case 'f':
full = 1;
break;
default:
usage();
break;
}ARGEND;
if (argc == 0)
usage();
cmd = &argv[0];
mkpty(&ws, TERMHEIGHT, TERMWIDTH, FBWIDTH, FBHEIGHT);
spawn();
mkwindow(&window, &renderer, "GE Datanet 760", WIDTH*scale, HEIGHT*scale);
screentex = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888,
SDL_TEXTUREACCESS_TARGET, WIDTH, HEIGHT);
keystate = SDL_GetKeyboardState(nil);
for(x = 0; x < TERMWIDTH; x++)
for(y = 0; y < TERMHEIGHT; y++)
fb[y][x] = ' ';
initblur(1.5);
createfont();
pthread_create(&thr1, nil, readthread, nil);
pthread_create(&thr2, nil, timethread, nil);
if(full)
toggle_fullscreen();
mainloop();
SDL_Quit();
return 0;
}