MythTV  master
lang.c
Go to the documentation of this file.
1 #include <string.h>
2 #include "vt.h"
3 #include "lang.h"
4 
5 int latin1 = -1;
6 
7 static unsigned char lang_char[256];
8 
9 /* Yankable latin charset :-)
10  !"#$%&'()*+,-./0123456789:;<=>?
11  @ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_
12  `abcdefghijklmnopqrstuvwxyz{|}~
13  ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿
14  ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞß
15  àáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ
16 */
17 
18 
19 
20 static struct mark { const char *m_g0, *m_latin1, *m_latin2; } marks[16] =
21 {
22  /* none */ { "#",
23  "\xA4", /* ¤ */
24  "$" },
25  /* grave - ` */ { " aeiouAEIOU", /* `àèìòùÀÈÌÒÙ */
26  "`\xE0\xE8\xEC\xF2\xF9\xC0\xC8\xCC\xD2\xD9",
27  "`aeiouAEIOU" },
28  /* acute - ' */ { " aceilnorsuyzACEILNORSUYZ",
29  "'\xE1\x63\xE9\xEDln\xF3rs\xFA\xFDz\xC1\x43\xC9\xCDLN\xD3RS\xDA\xDDZ", /* 'ácéílnórsúýzÁCÉÍLNÓRSÚÝZ */
30  "'\xE1\xE6\xE9\xED\xE5\xF1\xF3\xE0\xB6\xFA\xFD\xBC\xC1\xC6\xC9\xCD\xC5\xD1\xD3\xC0\xA6\xDAݬ" /* 'áæéíåñóà¶úý¼ÁÆÉÍÅÑÓÀ¦Úݬ */ },
31  /* cirumflex - ^ */ { " aeiouAEIOU",
32  "^\xE2\xEA\xEE\xF4\xFB\xC2\xCA\xCE\xD4\xDB", /* ^âêîôûÂÊÎÔÛ */
33  "^\xE2\x65\xEE\xF4\x75\xC2\x45\xCE\xD4\x55" }, /* ^âeîôuÂEÎÔU */
34  /* tilde - ~ */ { " anoANO",
35  "~\xE3\xF1\xF5\xC3\xD1\xD5", /* ~ãñõÃÑÕ */
36  "~anoANO" },
37  /* ??? - <AF> */ { "",
38  "",
39  "" },
40  /* breve - u */ { "aA",
41  "aA",
42  "\xE3\xC3" /* ãà */ },
43  /* abovedot - · */ { "zZ",
44  "zZ",
45  "\xBF\xAF" /* ¿¯ */ },
46  /* diaeresis ¨ */ { "aeiouAEIOU",
47  "\xE4\xEB\xEF\xF6\xFC\xC4\xCB\xCF\xD6\xDC", /* äëïöüÄËÏÖÜ */
48  "\xE4\xEB\x69\xF6\xFC\xC4\xCB\x49\xD6\xDC" /* äëiöüÄËIÖÜ */},
49  /* ??? - . */ { "",
50  "",
51  "" },
52  /* ringabove - ° */ { " auAU",
53  "\xB0\xE5\x75\xC5\x55", /* °åuÅU */
54  "\xB0\x61\xF9\x41\xD9" /* °aùAÙ */ },
55  /* cedilla - ¸ */ { "cstCST",
56  "\xE7\x73\x74\xC7\x53\x54", /* çstÇST */
57  "\xE7\xBA\xFE\xC7\xAA\xDE" /* çºþÇªÞ */ },
58  /* ??? - _ */ { " ",
59  "_",
60  "_" },
61  /* dbl acute - " */ { " ouOU",
62  "\"ouOU",
63  "\x22\xF5\xFB\xD5\xDB" /* \"õûÕÛ */ },
64  /* ogonek - \, */ { "aeAE",
65  "aeAE",
66  "\xB1\xEA\xA1\xCA" /* ±ê¡Ê */ },
67  /* caron - v */ { "cdelnrstzCDELNRSTZ",
68  "cdelnrstzCDELNRSTZ",
69  "\xE8\xEF\xEC\xB5\xF2\xF8\xB9\xBB\xBE\xC8\xCF̥\xD2ة\xAB\xAE" /* èïìµòø¹»¾ÈÏÌ¥ÒØ©«® */ },
70 };
71 
72 static unsigned char g2map_latin1[] =
73  /*0123456789abcdef*/
74  "\x20\xA1\xA2\xA3\x24\xA5\x23\xA7\xA4\x27\x22\xAB\x20\x20\x20\x20" /* ¡¢£$¥#§¤'\"« */
75  "\xB0\xB1\xB2\xB3\xD7\xB5\xB6\xB7\xF7\x27\x22\xBB\xBC\xBD\xBE\xBF" /* °±²³×µ¶·÷'\"»¼½¾¿ */
76  "\x20\x60\xB4\x5E\x7E\x20\x20\x20\xA8\x2e\xB0\xB8\x5F\x22\x20\x20" /* `´^~ ¨.°¸_\" */
77  "\x5F\xB9\xAE\xA9\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20" /* _¹®© */
78  "\x20\xC6\xD0\xAA\x48\x20\x49\x4C\x4C\xD8\x20\xBA\xDE\x54\x4E\x6E" /* ÆЪH ILLØ ºÞTNn */
79  "\x4B\xE6\x64\xF0\x68\x69\x69\x6C\x6C\xF8\x20\xDF\xFE\x74\x6E\x7f"; /* Kædðhiillø ßþtn\x7f" */
80 
81 static unsigned char g2map_latin2[] =
82  /*0123456789abcdef*/
83  "\x20\x69\x63\x4C\x24\x59\x23\xA7\xA4\x27\x22\x3C\x20\x20\x20\x20" /* icL$Y#§¤'\"< */
84  "\xB0\x20\x20\x20\xD7\x75\x20\x20\xF7\x27\x22\x3E\x20\x20\x20\x20" /* ° ×u ÷'\"> */
85  "\x20\x60\xB4\x5E\x7E\x20\xA2\xFF\xA8\x2E\xB0\xB8\x5F\xBD\xB2\xB7" /* `´^~ ¢ÿ¨.°¸_½²· */
86  "\x2D\x20\x52\x43\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20" /* - RC */
87  "\x20\x20\xD0\x61\x48\x20\x69\x4C\xA3\x4F\x20\x6F\x70\x54\x4E\x6e" /* ÐaH iL£O opTNn */
88  "\x4B\x20\xF0\x64\x68\x69\x69\x6C\xB3\x6F\x20\xDF\x70\x74\x6e\x7f"; /* K ðdhiil³o ßptn\x7f" */
89 
90 
91 
92 void
93 lang_init(void)
94 {
95  int i;
96 
97  memset(lang_char, 0, sizeof(lang_char));
98  for (i = 1; i <= 13; i++)
99  lang_char[(unsigned char)(lang_chars[0][i])] = i;
100 }
101 
102 
103 void
104 conv2latin(unsigned char *p, int n, int lang)
105 {
106  int gfx = 0;
107 
108  while (n--)
109  {
110  int c;
111  if (lang_char[c = *p])
112  {
113  if (! gfx || (c & 0xa0) != 0x20)
114  *p = lang_chars[lang + 1][lang_char[c]];
115  }
116  else if ((c & 0xe8) == 0)
117  gfx = c & 0x10;
118  p++;
119  }
120 }
121 
122 
123 
124 void
126 {
127  eh->next_des = 0;
128 }
129 
130 void
131 add_enhance(struct enhance *eh, int dcode, unsigned int *data)
132 {
133  if (dcode == eh->next_des)
134  {
135  memcpy(eh->trip + dcode * 13, data, 13 * sizeof(*data));
136  eh->next_des++;
137  }
138  else
139  eh->next_des = -1;
140 }
141 
142 void
143 do_enhancements(struct enhance *eh, struct vt_page *vtp)
144 {
145  int row = 0;
146 
147  if (eh->next_des < 1)
148  return;
149 
150  for (unsigned int *p = eh->trip, *e = p + eh->next_des * 13; p < e; p++)
151  if (*p % 2048 != 2047)
152  {
153  int adr = *p % 64;
154  int mode = *p / 64 % 32;
155  int data = *p / 2048 % 128;
156 
157  //printf("%2x,%d,%d ", mode, adr, data);
158  if (adr < 40)
159  {
160  // col functions
161  switch (mode)
162  {
163  case 15: // char from G2 set
164  if (adr < VT_WIDTH && row < VT_HEIGHT)
165  {
166  if (latin1)
167  vtp->data[row][adr] = g2map_latin1[data-32];
168  else
169  vtp->data[row][adr] = g2map_latin2[data-32];
170  }
171  break;
172  case 16 ... 31: // char from G0 set with diacritical mark
173  if (adr < VT_WIDTH && row < VT_HEIGHT)
174  {
175  struct mark *mark = marks + (mode - 16);
176  char *x;
177 
178  if ((x = strchr(mark->m_g0, data)))
179  {
180  if (latin1)
181  data = mark->m_latin1[x - mark->m_g0];
182  else
183  data = mark->m_latin2[x - mark->m_g0];
184  }
185  vtp->data[row][adr] = data;
186  }
187  break;
188  }
189  }
190  else
191  {
192  // row functions
193  if ((adr -= 40) == 0)
194  adr = 24;
195 
196  switch (mode)
197  {
198  case 1: // full row color
199  case 4: // set active position
200  row = adr;
201  break;
202  case 7: // address row 0 (+ full row color)
203  if (adr == 23)
204  row = 0;
205  break;
206  }
207  }
208  }
209  //printf("\n");
210 }
211 
void lang_init(void)
Definition: lang.c:93
int latin1
Definition: lang.c:5
void init_enhance(struct enhance *eh)
Definition: lang.c:125
void add_enhance(struct enhance *eh, int dcode, unsigned int *data)
Definition: lang.c:131
#define VT_WIDTH
Definition: vt.h:4
static unsigned char g2map_latin2[]
Definition: lang.c:81
Definition: lang.h:13
Definition: lang.c:20
static unsigned char lang_char[256]
Definition: lang.c:7
static unsigned char g2map_latin1[]
Definition: lang.c:72
Definition: vt.h:36
const char * m_latin1
Definition: lang.c:20
unsigned char data[VT_HEIGHT][VT_WIDTH]
Definition: vt.h:43
static struct mark marks[16]
const char * m_latin2
Definition: lang.c:20
const char * m_g0
Definition: lang.c:20
#define VT_HEIGHT
Definition: vt.h:5
void do_enhancements(struct enhance *eh, struct vt_page *vtp)
Definition: lang.c:143
int next_des
Definition: lang.h:15
const unsigned char lang_chars[][16]
Definition: vbilut.cpp:4
unsigned int trip[13 *16]
Definition: lang.h:16
void conv2latin(unsigned char *p, int n, int lang)
Definition: lang.c:104