Subversion Repositories Kolibri OS

Rev

Rev 5565 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
5201 serge 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
5565 serge 3
;; Copyright (C) KolibriOS team 2013-2015. All rights reserved. ;;
5201 serge 4
;; Distributed under terms of the GNU General Public License    ;;
5
;;                                                              ;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7
 
8
$Revision: 5082 $
9
 
10
; fetch the UTF-8 character in addrspace:offs to char
11
macro fetch_utf8_char addrspace, offs, char
3555 Serge 12
{ local first_byte, b
5984 serge 13
  ; fetch first byte
5201 serge 14
  load first_byte byte from addrspace:offs
5984 serge 15
  if first_byte < 0x80
16
    char = first_byte
17
    offs = offs + 1
18
  else if first_byte < 0xC0
5201 serge 19
    err Invalid UTF-8 string
5984 serge 20
  else if first_byte < 0xE0
21
    char = first_byte and 0x1F
5201 serge 22
    load b byte from addrspace:offs + 1
5984 serge 23
    char = (char shl 6) + (b and 0x3F)
24
    offs = offs + 2
25
  else if first_byte < 0xF0
26
    char = first_byte and 0xF
5201 serge 27
    load b byte from addrspace:offs + 1
5984 serge 28
    char = (char shl 6) + (b and 0x3F)
5201 serge 29
    load b byte from addrspace:offs + 2
5984 serge 30
    char = (char shl 6) + (b and 0x3F)
31
    offs = offs + 3
32
  else if first_byte < 0xF8
33
    char = first_byte and 0x7
5201 serge 34
    load b byte from addrspace:offs + 1
5984 serge 35
    char = (char shl 6) + (b and 0x3F)
5201 serge 36
    load b byte from addrspace:offs + 2
5984 serge 37
    char = (char shl 6) + (b and 0x3F)
5201 serge 38
    load b byte from addrspace:offs + 3
5984 serge 39
    char = (char shl 6) + (b and 0x3F)
40
    offs = offs + 4
41
  else
5201 serge 42
    err Invalid UTF-8 string
5984 serge 43
  end if
5201 serge 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 = $
3555 Serge 59
  end virtual
5201 serge 60
  while offs < ..addrspace#.size
61
    fetch_utf8_char ..addrspace, offs, char
5984 serge 62
    if char = 0x2500
5201 serge 63
      db 0xC4
5984 serge 64
    else if char = 0x2502
5201 serge 65
      db 0xB3
5984 serge 66
    else if char = 0x250C
5201 serge 67
      db 0xDA
5984 serge 68
    else if char = 0x2510
5201 serge 69
      db 0xBF
5984 serge 70
    else if char = 0x2514
5201 serge 71
      db 0xC0
5984 serge 72
    else if char = 0x2518
5201 serge 73
      db 0xD9
5984 serge 74
    else if char = 0x252C
5201 serge 75
      db 0xC2
5984 serge 76
    else if char = 0x2534
5201 serge 77
      db 0xC1
5984 serge 78
    else if char = 0x2551
5201 serge 79
      db 0xBA
80
    else if char < 0x80
81
      db char
5984 serge 82
    else
5201 serge 83
      encoding char
5984 serge 84
    end if
5201 serge 85
  end while
3555 Serge 86
}
87
 
5201 serge 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
95
}
96
 
3555 Serge 97
; Russian: use CP866.
98
; 0x410-0x43F -> 0x80-0xAF
99
; 0x440-0x44F -> 0xE0-0xEF
100
; 0x401 -> 0xF0, 0x451 -> 0xF1
5201 serge 101
declare_encoding cp866
102
{
103
  if char = 0x401
5984 serge 104
    db 0xF0
105
  else if char = 0x451
106
    db 0xF1
107
  else if (char < 0x410) | (char > 0x44F)
5201 serge 108
    err Failed to convert to CP866
5984 serge 109
  else if char < 0x440
110
    db char - 0x410 + 0x80
111
  else
112
    db char - 0x440 + 0xE0
113
  end if
3555 Serge 114
}
115
 
116
; Latin-1 encoding
117
; 0x00-0xFF - trivial map
5201 serge 118
declare_encoding latin1
119
{
120
  if char < 0x100
5984 serge 121
    db char
122
  else
5201 serge 123
    err Failed to convert to Latin-1
5984 serge 124
  end if
3555 Serge 125
}
126
 
5201 serge 127
; CP850 encoding
128
declare_encoding cp850
4265 Serge 129
{
5201 serge 130
  if char = 0xBF
5984 serge 131
    db 0xA8
132
  else if char = 0xE1
133
    db 0xA0
134
  else if char = 0xE9
135
    db 0x82
136
  else if char = 0xED
137
    db 0xA1
138
  else if char = 0xF3
139
    db 0xA2
140
  else if char = 0xFA
141
    db 0xA3
142
  else
143
    err Failed to convert to CP850
144
  end if
3555 Serge 145
}