Subversion Repositories Kolibri OS

Rev

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

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