Subversion Repositories Kolibri OS

Rev

Rev 4265 | Rev 5565 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4265 Rev 5201
Line -... Line 1...
-
 
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1
; fetch the UTF-8 character in string+offs to char
2
;;                                                              ;;
2
; common part for all encodings: translate pseudographics
3
;; Copyright (C) KolibriOS team 2013-2014. All rights reserved. ;;
3
; Pseudographics for the boot screen:
4
;; Distributed under terms of the GNU General Public License    ;;
4
; 0x2500 -> 0xC4, 0x2502 -> 0xB3, 0x250C -> 0xDA, 0x2510 -> 0xBF,
5
;;                                                              ;;
-
 
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
 
7
 
-
 
8
$Revision: 5082 $
-
 
9
 
5
; 0x2514 -> 0xC0, 0x2518 -> 0xD9, 0x252C -> 0xC2, 0x2534 -> 0xC1, 0x2551 -> 0xBA
10
; fetch the UTF-8 character in addrspace:offs to char
6
macro fetch_utf8_char string, offs, char, graph
11
macro fetch_utf8_char addrspace, offs, char
7
{ local first_byte, b
12
{ local first_byte, b
8
  virtual at 0
-
 
9
    db string
-
 
10
    if offs >= $
-
 
11
      char = -1
-
 
12
    else
-
 
13
      ; fetch first byte
13
      ; fetch first byte
14
      load first_byte byte from offs
14
  load first_byte byte from addrspace:offs
15
      if first_byte < 0x80
15
      if first_byte < 0x80
16
        char = first_byte
16
        char = first_byte
17
        offs = offs + 1
17
        offs = offs + 1
18
      else if first_byte < 0xC0
18
      else if first_byte < 0xC0
19
        .err Invalid UTF-8 string
19
    err Invalid UTF-8 string
20
      else if first_byte < 0xE0
20
      else if first_byte < 0xE0
21
        char = first_byte and 0x1F
21
        char = first_byte and 0x1F
22
        load b byte from offs + 1
22
    load b byte from addrspace:offs + 1
23
        char = (char shl 6) + (b and 0x3F)
23
        char = (char shl 6) + (b and 0x3F)
24
        offs = offs + 2
24
        offs = offs + 2
25
      else if first_byte < 0xF0
25
      else if first_byte < 0xF0
26
        char = first_byte and 0xF
26
        char = first_byte and 0xF
27
        load b byte from offs + 1
27
    load b byte from addrspace:offs + 1
28
        char = (char shl 6) + (b and 0x3F)
28
        char = (char shl 6) + (b and 0x3F)
29
        load b byte from offs + 2
29
    load b byte from addrspace:offs + 2
30
        char = (char shl 6) + (b and 0x3F)
30
        char = (char shl 6) + (b and 0x3F)
31
        offs = offs + 3
31
        offs = offs + 3
32
      else if first_byte < 0xF8
32
      else if first_byte < 0xF8
33
        char = first_byte and 0x7
33
        char = first_byte and 0x7
34
        load b byte from offs + 1
34
    load b byte from addrspace:offs + 1
35
        char = (char shl 6) + (b and 0x3F)
35
        char = (char shl 6) + (b and 0x3F)
36
        load b byte from offs + 2
36
    load b byte from addrspace:offs + 2
37
        char = (char shl 6) + (b and 0x3F)
37
        char = (char shl 6) + (b and 0x3F)
38
        load b byte from offs + 3
38
    load b byte from addrspace:offs + 3
39
        char = (char shl 6) + (b and 0x3F)
39
        char = (char shl 6) + (b and 0x3F)
40
        offs = offs + 4
40
        offs = offs + 4
41
      else
41
      else
42
        .err Invalid UTF-8 string
42
    err Invalid UTF-8 string
43
      end if
-
 
44
    end if
43
    end if
-
 
44
}
-
 
45
 
-
 
46
; Worker macro for all encodings.
-
 
47
; Common part for all encodings: map characters 0-0x7F trivially,
-
 
48
; translate pseudographics.
-
 
49
; Pseudographics for the boot screen:
-
 
50
; 0x2500 -> 0xC4, 0x2502 -> 0xB3, 0x250C -> 0xDA, 0x2510 -> 0xBF,
-
 
51
; 0x2514 -> 0xC0, 0x2518 -> 0xD9, 0x252C -> 0xC2, 0x2534 -> 0xC1, 0x2551 -> 0xBA
-
 
52
macro convert_utf8 encoding, [arg]
-
 
53
{ common
-
 
54
  local ..addrspace, offs, char
-
 
55
  offs = 0
-
 
56
  virtual at 0
-
 
57
  ..addrspace:: db arg
-
 
58
  ..addrspace#.size = $
45
  end virtual
59
  end virtual
-
 
60
  while offs < ..addrspace#.size
-
 
61
    fetch_utf8_char ..addrspace, offs, char
46
  if char = 0x2500
62
  if char = 0x2500
47
    graph = 0xC4
63
      db 0xC4
48
  else if char = 0x2502
64
  else if char = 0x2502
49
    graph = 0xB3
65
      db 0xB3
50
  else if char = 0x250C
66
  else if char = 0x250C
51
    graph = 0xDA
67
      db 0xDA
52
  else if char = 0x2510
68
  else if char = 0x2510
53
    graph = 0xBF
69
      db 0xBF
54
  else if char = 0x2514
70
  else if char = 0x2514
55
    graph = 0xC0
71
      db 0xC0
56
  else if char = 0x2518
72
  else if char = 0x2518
57
    graph = 0xD9
73
      db 0xD9
58
  else if char = 0x252C
74
  else if char = 0x252C
59
    graph = 0xC2
75
      db 0xC2
60
  else if char = 0x2534
76
  else if char = 0x2534
61
    graph = 0xC1
77
      db 0xC1
62
  else if char = 0x2551
78
  else if char = 0x2551
63
    graph = 0xBA
79
      db 0xBA
-
 
80
    else if char < 0x80
-
 
81
      db char
64
  else
82
  else
65
    graph = 0
83
      encoding char
66
  end if
84
  end if
-
 
85
  end while
-
 
86
}
-
 
87
 
-
 
88
macro declare_encoding encoding
-
 
89
{
-
 
90
  macro encoding [arg]
-
 
91
  \{ common convert_utf8 encoding#char, arg \}
-
 
92
  struc encoding [arg]
-
 
93
  \{ common convert_utf8 encoding#char, arg \}
-
 
94
  macro encoding#char char
67
}
95
}
Line 68... Line 96...
68
 
96
 
69
; Russian: use CP866.
-
 
70
; 0x00-0x7F - trivial map
97
; Russian: use CP866.
71
; 0x410-0x43F -> 0x80-0xAF
98
; 0x410-0x43F -> 0x80-0xAF
72
; 0x440-0x44F -> 0xE0-0xEF
99
; 0x440-0x44F -> 0xE0-0xEF
73
; 0x401 -> 0xF0, 0x451 -> 0xF1
100
; 0x401 -> 0xF0, 0x451 -> 0xF1
74
macro cp866 [arg]
-
 
75
{ local offs, char, graph
-
 
76
  offs = 0
101
declare_encoding cp866
77
  while 1
-
 
78
    fetch_utf8_char arg, offs, char, graph
-
 
79
    if char = -1
-
 
80
      break
-
 
81
    end if
-
 
82
    if graph
-
 
83
      db graph
-
 
84
    else if char < 0x80
-
 
85
      db char
102
{
86
    else if char = 0x401
103
  if char = 0x401
87
      db 0xF0
104
      db 0xF0
88
    else if char = 0x451
105
    else if char = 0x451
89
      db 0xF1
106
      db 0xF1
90
    else if (char < 0x410) | (char > 0x44F)
107
    else if (char < 0x410) | (char > 0x44F)
91
      .err Failed to convert to CP866
108
    err Failed to convert to CP866
92
    else if char < 0x440
109
    else if char < 0x440
93
      db char - 0x410 + 0x80
110
      db char - 0x410 + 0x80
94
    else
111
    else
95
      db char - 0x440 + 0xE0
112
      db char - 0x440 + 0xE0
96
    end if
-
 
97
  end while
-
 
98
}
-
 
99
 
-
 
100
struc cp866 [arg]
-
 
101
{
-
 
102
common
-
 
103
  cp866 arg
113
    end if
Line 104... Line 114...
104
}
114
}
105
 
115
 
106
; Latin-1 encoding
116
; Latin-1 encoding
107
; 0x00-0xFF - trivial map
-
 
108
macro latin1 [arg]
-
 
109
{ local offs, char, graph
117
; 0x00-0xFF - trivial map
110
  offs = 0
-
 
111
  while 1
-
 
112
    fetch_utf8_char arg, offs, char, graph
-
 
113
    if char = -1
-
 
114
      break
-
 
115
    end if
-
 
116
    if graph
118
declare_encoding latin1
117
      db graph
119
{
118
    else if char < 0x100
120
  if char < 0x100
119
      db char
121
      db char
120
    else
122
    else
121
      .err Failed to convert to Latin-1
-
 
122
    end if
-
 
123
  end while
-
 
124
}
-
 
125
 
-
 
126
struc latin1 [arg]
-
 
127
{
-
 
128
common
123
    err Failed to convert to Latin-1
Line 129... Line 124...
129
  latin1 arg
124
    end if
130
}
125
}
131
 
-
 
132
; CP850 encoding
-
 
133
macro cp850 [arg]
126
 
134
{ local offs, char, graph
-
 
135
  offs = 0
-
 
136
  while 1
-
 
137
    fetch_utf8_char arg, offs, char, graph
-
 
138
    if char = -1
-
 
139
      break
-
 
140
    end if
-
 
141
    if graph
-
 
142
      db graph
127
; CP850 encoding
143
    else if char < 0x80
128
declare_encoding cp850
144
      db char
129
{
145
    else if char = 0xBF
130
  if char = 0xBF
146
      db 0xA8
131
      db 0xA8
147
    else if char = 0xE1
132
    else if char = 0xE1
Line 155... Line 140...
155
    else if char = 0xFA
140
    else if char = 0xFA
156
      db 0xA3
141
      db 0xA3
157
    else
142
    else
158
      err Failed to convert to CP850
143
      err Failed to convert to CP850
159
    end if
144
    end if
160
  end while
-
 
161
}
-
 
162
 
-
 
163
struc cp850 [arg]
-
 
164
{
-
 
165
common
-
 
166
  cp850 arg
-
 
167
}
145
}