-
Notifications
You must be signed in to change notification settings - Fork 0
/
x68k-ite-sixel.diff
621 lines (594 loc) · 15.1 KB
/
x68k-ite-sixel.diff
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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
NetBSD/x68k のコンソール ite(4) で SIXEL 画像を表示できるようにする
パッチ 20241001 版 (for 10.99.x) です。
このパッチをあてて GENERIC カーネルの ITE_SIXEL オプションを有効にして
ビルドしてください。
注意点など:
o SIXEL データのうちパレット定義は無視してパレット番号 = カラーコードと
と解釈して使用しています。テキストVRAMのパレットを変えると、この画像
以外の部分の色も変わってしまうためです。
前回 (20161201) からの変更点:
o 独自16色モードを廃止。
o 独自 sysctl を廃止。
o ケーパビリティ問い合わせに対して SIXEL サポートを応答。
diff --git a/conf/GENERIC b/conf/GENERIC
index 73a5594..5999bea 100644
--- sys/arch/x68k/conf/GENERIC
+++ sys/arch/x68k/conf/GENERIC
@@ -229,6 +229,7 @@ kbd0 at mfp0 # standard keyboard
ite0 at grf0 grfaddr 0 # internal terminal emulator
options ITE_KERNEL_ATTR=4 # bold for kernel messages
# see /sys/arch/x68k/dev/itevar.h
+#options ITE_SIXEL
## floppy disks
fdc0 at intio0 addr 0xe94000 intr 96 dma 0 dmaintr 100 # floppy controller
diff --git a/conf/files.x68k b/conf/files.x68k
index 30baeaa..952d8f3 100644
--- sys/arch/x68k/conf/files.x68k
+++ sys/arch/x68k/conf/files.x68k
@@ -68,6 +68,7 @@ file arch/x68k/dev/grf_tv.c grf | ite
file arch/x68k/dev/grf_gv.c grf | ite
defparam opt_ite.h ITE_KERNEL_ATTR
+defflag opt_ite.h ITE_SIXEL
device ite : tty
attach ite at grf
file arch/x68k/dev/ite.c ite needs-flag
diff --git a/dev/ite.c b/dev/ite.c
index 702d2dc..4fbf0a0 100644
--- sys/arch/x68k/dev/ite.c
+++ sys/arch/x68k/dev/ite.c
@@ -91,6 +91,9 @@ void opm_bell(void);
#define SUBR_CLEAR(ip,sy,sx,h,w) ip->isw->ite_clear(ip,sy,sx,h,w)
#define SUBR_SCROLL(ip,sy,sx,count,dir) \
ip->isw->ite_scroll(ip,sy,sx,count,dir)
+#if defined(ITE_SIXEL)
+#define SUBR_SIXEL(ip,sy,sx) ip->isw->ite_sixel(ip,sy,sx)
+#endif
struct consdev;
@@ -151,6 +154,9 @@ static u_char cons_tabs[MAX_TABS];
static void itestart(struct tty *);
static void iteputchar(int, struct ite_softc *);
+#if defined(ITE_SIXEL)
+static int ite_dcs(const int, struct ite_softc *);
+#endif
static void ite_putstr(const u_char *, int, dev_t);
static int itematch(device_t, cfdata_t, void *);
@@ -1207,10 +1213,18 @@ ite_putstr(const u_char *s, int len, dev_t dev)
if ((ip->flags & (ITE_ACTIVE|ITE_INGRF)) != ITE_ACTIVE)
return;
+#if defined(ITE_SIXEL)
+ /* avoid flicking cursor */
+ if (ip->escape == 0)
+#endif
SUBR_CURSOR(ip, START_CURSOROPT);
for (i = 0; i < len; i++)
if (s[i] != 0)
iteputchar(s[i], ip);
+#if defined(ITE_SIXEL)
+ /* avoid flicking cursor */
+ if (ip->escape == 0)
+#endif
SUBR_CURSOR(ip, END_CURSOROPT);
}
@@ -1220,7 +1234,11 @@ iteputchar(int c, struct ite_softc *ip)
int n, x, y;
char *cp;
+#if defined(ITE_SIXEL)
+ if ((c >= 0x20 && ip->escape != 0) || ip->escape == DCS) {
+#else
if (c >= 0x20 && ip->escape != 0) {
+#endif
switch (ip->escape) {
case ESC:
@@ -1284,6 +1302,11 @@ iteputchar(int c, struct ite_softc *ip)
/* String Terminator */
c = ST;
ip->escape = 0;
+#if defined(ITE_SIXEL)
+ if (ip->decsixel_y != 0) {
+ ite_lf(ip);
+ }
+#endif
break;
case ']':
@@ -1613,8 +1636,13 @@ iteputchar(int c, struct ite_softc *ip)
ite_sendstr(ip,
"\033[?1;1c");
else
+#if defined(ITE_SIXEL)
+ ite_sendstr(ip,
+ "\033[63;4c");
+#else
ite_sendstr(ip,
"\033[63;0c");
+#endif
break;
}
}
@@ -2162,6 +2190,13 @@ iteputchar(int c, struct ite_softc *ip)
}
break;
+#if defined(ITE_SIXEL)
+ case DCS:
+ if (ite_dcs(c, ip) == 0) {
+ return;
+ }
+ break;
+#endif /* ITE_SIXEL */
default:
ip->escape = 0;
return;
@@ -2289,6 +2324,9 @@ iteputchar(int c, struct ite_softc *ip)
case DCS: /* device control string introducer */
ip->escape = DCS;
+#if defined(ITE_SIXEL)
+ ip->dcs_cmd = DCS_START;
+#endif
ip->ap = ip->argbuf;
break;
@@ -2355,6 +2393,291 @@ iteputchar(int c, struct ite_softc *ip)
}
}
+#if defined(ITE_SIXEL)
+/*
+ * Handle DCS.
+ * 0: return in the caller.
+ * !0: break the switch-case in the caller.
+ */
+static int
+ite_dcs(const int c, struct ite_softc *ip)
+{
+ static const uint32_t table[64] = {
+ 0x000000, 0x000001, 0x000010, 0x000011,
+ 0x000100, 0x000101, 0x000110, 0x000111,
+ 0x001000, 0x001001, 0x001010, 0x001011,
+ 0x001100, 0x001101, 0x001110, 0x001111,
+ 0x010000, 0x010001, 0x010010, 0x010011,
+ 0x010100, 0x010101, 0x010110, 0x010111,
+ 0x011000, 0x011001, 0x011010, 0x011011,
+ 0x011100, 0x011101, 0x011110, 0x011111,
+ 0x100000, 0x100001, 0x100010, 0x100011,
+ 0x100100, 0x100101, 0x100110, 0x100111,
+ 0x101000, 0x101001, 0x101010, 0x101011,
+ 0x101100, 0x101101, 0x101110, 0x101111,
+ 0x110000, 0x110001, 0x110010, 0x110011,
+ 0x110100, 0x110101, 0x110110, 0x110111,
+ 0x111000, 0x111001, 0x111010, 0x111011,
+ 0x111100, 0x111101, 0x111110, 0x111111,
+ };
+
+ switch (ip->dcs_cmd) {
+ case DCS_DISCARD:
+ /* discard sixel cause kernel message interrupted */
+ switch (c) {
+ case '-':
+ /* restart from next SIXEL line */
+ ite_lf(ip);
+ goto sixel_restart;
+
+ case CAN:
+ case SUB:
+ /* SUB should also display a reverse question mark... */
+ ip->escape = 0;
+ return 0;
+
+ case ESC:
+ ip->escape = ESC;
+ return 0;
+
+ default:
+ return 0;
+ }
+ break;
+
+ case DCS_START:
+ /* the biggie... */
+ switch (c) {
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ case '8':
+ case '9':
+ case ';':
+ case '$':
+ if (ip->ap < ip->argbuf + MAX_ARGSIZE)
+ *ip->ap++ = c;
+ return 0;
+
+ case 'q':
+ {
+ char *cp;
+
+ /* init sixel */
+ /*
+ * DCS <P1> ; <P2> ; <P3> q
+ * P1 is aspect ratio, XXX not supported.
+ * P2 is bgcolor mode.
+ * 0..2: bgcolor mode, XXX not supported here.
+ * bit2 means 'OR'ed color mode.
+ * This is an original extension.
+ */
+ ip->ap = ip->argbuf;
+ cp = strchr(ip->ap, ';');
+ if (cp != NULL) {
+ int mode;
+ mode = atoi(cp + 1) - '0';
+ ip->decsixel_ormode = (mode & 4);
+ } else {
+ ip->decsixel_ormode = 0;
+ }
+sixel_restart:
+ ip->dcs_cmd = DCS_SIXEL;
+ ip->decsixel_state = DECSIXEL_INIT;
+ ip->decsixel_ph = MAX_SIXEL_WIDTH;
+ ip->decsixel_x = 0;
+ ip->decsixel_y = 0;
+ ip->decsixel_repcount = 0;
+ ip->decsixel_color = ip->fgcolor;
+ memset(ip->decsixel_buf, 0, sizeof(ip->decsixel_buf));
+ return 0;
+ }
+
+ case CAN:
+ case SUB:
+ /* SUB should also display a reverse question mark... */
+ ip->escape = 0;
+ return 0;
+
+ case ESC:
+ ip->escape = ESC;
+ return 0;
+
+ default:
+ return 0;
+ }
+ break;
+
+ case DCS_SIXEL:
+sixel_loop:
+ switch (ip->decsixel_state) {
+ case DECSIXEL_INIT:
+ switch (c) {
+ case CAN:
+ case SUB:
+ /*
+ * SUB should also display a reverse question
+ * mark...
+ */
+ ip->escape = 0;
+ return 0;
+ case ESC:
+ ip->escape = ESC;
+ return 0;
+ case DECSIXEL_REPEAT:
+ ip->decsixel_state = c;
+ ip->decsixel_repcount = 0;
+ return 0;
+ case DECSIXEL_RASTER:
+ case DECSIXEL_COLOR:
+ ip->decsixel_state = c;
+ ip->ap = ip->argbuf;
+ return 0;
+ case '$': /* CR */
+ ip->decsixel_x = 0;
+ return 0;
+ case '-': /* LF */
+ /*
+ * XXX
+ * FONTHEIGHT is defined in ite_tv.c, not here..
+ */
+ if (ip->decsixel_y + 6 > 15) {
+ ite_lf(ip);
+ ip->decsixel_y -= 16;
+ }
+ SUBR_SIXEL(ip, ip->cury, ip->curx);
+ memset(ip->decsixel_buf, 0,
+ sizeof(ip->decsixel_buf));
+ ip->decsixel_x = 0;
+ ip->decsixel_y += 6;
+ return 0;
+ default:
+ if ('?' <= c && c <= '~'
+ && ip->decsixel_x < MAX_SIXEL_WIDTH) {
+ uint32_t d;
+ d = table[c - '?'] * ip->decsixel_color;
+ ip->decsixel_buf[ip->decsixel_x] |= d;
+ ip->decsixel_x++;
+ } else {
+ /* ignore */
+ }
+ return 0;
+ }
+ break;
+ case DECSIXEL_REPEAT:
+ if ('0' <= c && c <= '9') {
+ ip->decsixel_repcount =
+ ip->decsixel_repcount * 10 + (c - '0');
+ } else if ('?' <= c && c <= '~') {
+ uint32_t d;
+ int i;
+ int cnt = MIN(ip->decsixel_repcount,
+ MAX_SIXEL_WIDTH - ip->decsixel_x);
+ d = table[c - '?'] * ip->decsixel_color;
+ for (i = 0; i < cnt; i++) {
+ ip->decsixel_buf[ip->decsixel_x + i] |=
+ d;
+ }
+ ip->decsixel_x += cnt;
+ ip->decsixel_state = DECSIXEL_INIT;
+ } else {
+ /* invalid ? */
+ ip->decsixel_state = DECSIXEL_INIT;
+ }
+ return 0;
+ case DECSIXEL_RASTER:
+ case DECSIXEL_RASTER_PAD:
+ case DECSIXEL_RASTER_PH:
+ case DECSIXEL_RASTER_PV:
+ switch (c) {
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ case '8':
+ case '9':
+ if (ip->ap < ip->argbuf + MAX_ARGSIZE)
+ *ip->ap++ = c;
+ return 0;
+ case ';':
+ default:
+ switch (ip->decsixel_state) {
+ case DECSIXEL_RASTER:
+ /* ignore PAN */
+ ip->ap = ip->argbuf;
+ ip->decsixel_state =
+ DECSIXEL_RASTER_PAD;
+ return 0;
+ case DECSIXEL_RASTER_PAD:
+ /* ignore PAD */
+ ip->ap = ip->argbuf;
+ ip->decsixel_state = DECSIXEL_RASTER_PH;
+ return 0;
+ case DECSIXEL_RASTER_PH:
+ ip->decsixel_ph = ite_zargnum(ip);
+ ip->ap = ip->argbuf;
+ ip->decsixel_state = DECSIXEL_RASTER_PV;
+ return 0;
+ case DECSIXEL_RASTER_PV:
+ /* ignore PV */
+ ip->decsixel_state = DECSIXEL_INIT;
+ /* c is a next sequence char. */
+ goto sixel_loop;
+ default:
+ /* NOTREACHED */
+ return 0;
+ }
+ }
+ return 0;
+ case DECSIXEL_COLOR:
+ switch (c) {
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ case '8':
+ case '9':
+ case ';':
+ if (ip->ap < ip->argbuf + MAX_ARGSIZE)
+ *ip->ap++ = c;
+ return 0;
+ default:
+ *ip->ap = '\0';
+ if (strchr(ip->argbuf, ';')) {
+ /* ignore the palette definition. */
+ } else {
+ /* otherwise, it specifies color. */
+ ip->decsixel_color =
+ ite_zargnum(ip) & 7;
+ }
+ ip->decsixel_state = DECSIXEL_INIT;
+ ip->ap = ip->argbuf;
+ /* c is a next sequence char. */
+ goto sixel_loop;
+ }
+ return 0;
+ }
+ break;
+ }
+
+ /* Continue in caller's switch-case. */
+ return 1;
+}
+#endif /* ITE_SIXEL */
+
static void
iteprecheckwrap(struct ite_softc *ip)
{
@@ -2547,12 +2870,23 @@ itecnputc(dev_t dev, int c)
#ifdef ITE_KERNEL_ATTR
short save_attribute;
#endif
+#if defined(ITE_SIXEL)
+ int save_escape;
+#endif
if (panicstr && !paniced &&
(ip->flags & (ITE_ACTIVE|ITE_INGRF)) != ITE_ACTIVE) {
(void) iteon(dev, 3);
paniced = 1;
}
+
+#if defined(ITE_SIXEL)
+ save_escape = ip->escape;
+ if (ip->escape == DCS) {
+ ip->escape = 0;
+ ip->dcs_cmd = DCS_DISCARD;
+ }
+#endif
#ifdef ITE_KERNEL_ATTR
save_attribute = ip->attribute;
ip->attribute = ITE_KERNEL_ATTR;
@@ -2561,5 +2895,10 @@ itecnputc(dev_t dev, int c)
#ifdef ITE_KERNEL_ATTR
ip->attribute = save_attribute;
#endif
+#if defined(ITE_SIXEL)
+ if (ip->escape == 0) {
+ ip->escape = save_escape;
+ }
+#endif
}
#endif
diff --git a/dev/ite_tv.c b/dev/ite_tv.c
index ddf6ad5..c1c28ab 100644
--- sys/arch/x68k/dev/ite_tv.c
+++ sys/arch/x68k/dev/ite_tv.c
@@ -33,6 +33,8 @@
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ite_tv.c,v 1.20 2024/01/07 07:58:33 isaki Exp $");
+#include "opt_ite.h"
+
#include <sys/param.h>
#include <sys/device.h>
#include <sys/proc.h>
@@ -71,6 +73,9 @@ __KERNEL_RCSID(0, "$NetBSD: ite_tv.c,v 1.20 2024/01/07 07:58:33 isaki Exp $");
static u_int tv_top;
static uint8_t *tv_row[PLANELINES];
+#if defined(ITE_SIXEL)
+static uint8_t *tv_end;
+#endif
static uint8_t *tv_font[256];
static volatile uint8_t *tv_kfont[0x7f];
@@ -89,6 +94,9 @@ static void tv_putc(struct ite_softc *, int, int, int, int);
static void tv_cursor(struct ite_softc *, int);
static void tv_clear(struct ite_softc *, int, int, int, int);
static void tv_scroll(struct ite_softc *, int, int, int, int);
+#if defined(ITE_SIXEL)
+static void tv_sixel(struct ite_softc *, int, int);
+#endif
static inline uint32_t expbits(uint32_t);
static inline void txrascpy(uint8_t, uint8_t, int16_t, uint16_t);
@@ -166,6 +174,9 @@ tv_init(struct ite_softc *ip)
for (i = 0; i < PLANELINES; i++)
tv_row[i] =
(void *)__UNVOLATILE(&IODEVbase->tvram[ROWOFFSET(i)]);
+#if defined(ITE_SIXEL)
+ tv_end = (void *)__UNVOLATILE(&IODEVbase->tvram[ROWOFFSET(i)]);
+#endif
/* shadow ANK font */
memcpy(kern_font, (void *)&IODEVbase->cgrom0_8x16, 256 * FONTHEIGHT);
ite_set_glyph();
@@ -189,6 +200,9 @@ tv_init(struct ite_softc *ip)
ip->isw->ite_cursor = tv_cursor;
ip->isw->ite_clear = tv_clear;
ip->isw->ite_scroll = tv_scroll;
+#if defined(ITE_SIXEL)
+ ip->isw->ite_sixel = tv_sixel;
+#endif
/*
* Initialize colormap
@@ -741,3 +755,54 @@ tv_scroll(struct ite_softc *ip, int srcy, int srcx, int count, int dir)
break;
}
}
+
+#if defined(ITE_SIXEL)
+/*
+ * put SIXEL graphics
+ */
+void
+tv_sixel(struct ite_softc *ip, int sy, int sx)
+{
+ uint8_t *p;
+ int width;
+ int y;
+ int cx;
+ int px;
+ uint16_t data[3];
+ uint8_t color;
+
+ width = MIN(ip->decsixel_ph, MAX_SIXEL_WIDTH);
+ width = MIN(width, PLANEWIDTH - sx * FONTWIDTH);
+
+ p = CHADDR(sy, sx);
+ p += ROWBYTES * ip->decsixel_y;
+ /* boundary check */
+ if (p < tv_row[0]) {
+ p = tv_end + (p - tv_row[0]);
+ }
+
+ for (y = 0; y < 6; y++) {
+ /* for each 16dot word */
+ for (cx = 0; cx < howmany(width, 16); cx++) {
+ data[0] = 0;
+ data[1] = 0;
+ data[2] = 0;
+ for (px = 0; px < 16; px++) {
+ color = ip->decsixel_buf[cx * 16 + px] >> (y * 4);
+ /* x68k console is 8 colors */
+ data[0] = (data[0] << 1) | ((color >> 0) & 1);
+ data[1] = (data[1] << 1) | ((color >> 1) & 1);
+ data[2] = (data[2] << 1) | ((color >> 2) & 1);
+ }
+ *(uint16_t *)(p + cx * 2 ) = data[0];
+ *(uint16_t *)(p + cx * 2 + 0x20000) = data[1];
+ *(uint16_t *)(p + cx * 2 + 0x40000) = data[2];
+ }
+
+ p += ROWBYTES;
+ if (p >= tv_end) {
+ p = tv_row[0] + (p - tv_end);
+ }
+ }
+}
+#endif /* ITE_SIXEL */
diff --git a/dev/itevar.h b/dev/itevar.h
index 7f8177a..e5b4f6b 100644
--- sys/arch/x68k/dev/itevar.h
+++ sys/arch/x68k/dev/itevar.h
@@ -50,6 +50,7 @@ struct itesw {
void (*ite_putc)(struct ite_softc *, int, int, int, int);
void (*ite_cursor)(struct ite_softc *, int);
void (*ite_scroll)(struct ite_softc *, int, int, int, int);
+ void (*ite_sixel)(struct ite_softc *, int, int);
};
enum ite_arraymaxs {
@@ -94,6 +95,28 @@ struct ite_softc {
short save_curx, save_cury, save_attribute, save_char;
char sc_G0, sc_G1, sc_G2, sc_G3;
char *sc_GL, *sc_GR;
+ enum {
+ DCS_START = 0,
+ DCS_SIXEL = 'q', /* DECRQSS also use 'q'... */
+ DCS_DISCARD = -1,
+ } dcs_cmd;
+ enum {
+ DECSIXEL_INIT = 0,
+ DECSIXEL_RASTER_PAD,
+ DECSIXEL_RASTER_PH,
+ DECSIXEL_RASTER_PV,
+ DECSIXEL_REPEAT = '!',
+ DECSIXEL_RASTER = '\"',
+ DECSIXEL_COLOR = '#',
+ } decsixel_state;
+ int decsixel_ph;
+ int decsixel_x;
+ int decsixel_y;
+ int decsixel_repcount;
+ int decsixel_color;
+ int decsixel_ormode;
+#define MAX_SIXEL_WIDTH (768)
+ uint32_t decsixel_buf[MAX_SIXEL_WIDTH];
};
enum emul_level {