; -----------------------------------------------------------------------------
; Write character into UTF-16BE (MAC, big endian) buffer
; -----------------------------------------------------------------------------
; INPUT: EAX = Unicode character
; EDI = destination buffer
; EBP = remaining space in buffer
; OUTPUT: EDI = next destination buffer
; EBP = next remaining space in buffer
; DESTROYS: EAX
; -----------------------------------------------------------------------------
; ------------- 1 Word (almost 16 bits, 0000..D7FF or E000..FFFF)
CharUTF16BEW: or ebp,ebp ; check free space
jz CharUTF16BEW7 ; buffer full
cmp eax,0ffffh ; 1 word?
ja CharUTF16BEW6 ; more than 1 word
xchg al,ah ; exchange byte order
dec ebp ; decrease remaining space
jz CharUTF16LEW3 ; buffer full
dec ebp ; decrease remaining space
stosw ; store character
ret
; ------------- 2 Words (20 bits, 110110xxxxxxxxxx 110111xxxxxxxxxx
; = D800..DBFF DC00..DFFF)
CharUTF16BEW6: push eax ; push EAX
shr eax,10 ; EAX <- high 10 bits
add eax,0d800h-40h ; add high surrogate start - base
xchg al,ah ; exchange byte order
dec ebp ; decrease remaining space
jz CharUTF16LEW8 ; buffer full
stosw ; store high word
pop eax ; pop EAX
dec ebp ; decrease remaining space
jz CharUTF16BEW7 ; buffer full
and eax,3ffh ; mask low 10 bits
add eax,0dc00h ; add low surrogate start
xchg al,ah ; exchange byte order
dec ebp ; decrease remaining space
jz CharUTF16LEW3 ; buffer full
dec ebp ; decrease remaining space
stosw ; store low word
CharUTF16BEW7: ret
|