]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - sys/boot/pc98/boot0.5/putssjis.s
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / sys / boot / pc98 / boot0.5 / putssjis.s
1 # Copyright (c) KATO Takenori, 2007.
2 #
3 # All rights reserved.  Unpublished rights reserved under the copyright
4 # laws of Japan.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 #
10 # 1. Redistributions of source code must retain the above copyright
11 #    notice, this list of conditions and the following disclaimer as
12 #    the first lines of this file unmodified.
13 # 2. Redistributions in binary form must reproduce the above copyright
14 #    notice, this list of conditions and the following disclaimer in the
15 #    documentation and/or other materials provided with the distribution.
16 #
17 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #
28 # $FreeBSD$
29 #
30
31         .code16
32         .section        .putssjis, "awx", @progbits
33
34         #
35         # Display string with Shift-JIS support
36         # %si: addres of string, %di: T-VRAM address, %cx: count
37         #
38
39         # Absolute address of putssjis_entry must be 0x1243.
40 putssjis_entry:
41         push    %es
42         push    %ax
43         # Setup the T-VRAM segement address.
44         xorw    %ax, %ax
45         movw    %ax, %es
46         movw    $0xa000, %ax
47         testb   $0x08, %es:0x501
48         jz      normalmode
49         movw    $0xe000, %ax
50 normalmode:
51         movw    %ax, %es
52
53 putssjis_loop:
54         lodsw
55         call    check_sjis
56         jc      put_2byte_char
57
58         # 1 byte character
59         xorb    %ah, %ah
60         testb   $0xe0, %al      # Check control code.
61         jnz     put_1byte_char
62         movb    $0x20, %al      # Convert control code into the space.
63 put_1byte_char:
64         stosw
65         decw    %si
66         jmp     putssjis_loop_end
67
68 put_2byte_char:
69         subb    $0x20, %al
70
71         # Check 2byte "hankaku"
72         cmp     $0x09, %al
73         je      put_2byte_hankaku
74         cmp     $0x0a, %al
75         je      put_2byte_hankaku
76         cmp     $0x0b, %al
77         je      put_2byte_hankaku
78         jmp     put_2byte_zenkaku
79
80 put_2byte_hankaku:
81         stosw
82         jmp     putssjis_loop_end
83
84 put_2byte_zenkaku:
85         stosw
86         orb     $0x80, %ah
87         stosw
88         decw    %cx
89
90 putssjis_loop_end:
91         loop    putssjis_loop
92
93         pop     %ax
94         pop     %es
95         ret
96
97         # Check 2-byte code.
98 check_sjis:
99         cmpb    $0x80, %al
100         jbe     found_ank_kana
101         cmpb    $0xa0, %al
102         jb      found_2byte_char
103         cmpb    $0xe0, %al
104         jb      found_ank_kana
105         cmpb    $0xf0, %al
106         jae     found_ank_kana
107         jmp     found_2byte_char
108 found_ank_kana:
109         clc
110         ret
111
112 found_2byte_char:
113         # Convert Shift-JIS into JIS.
114         cmpb    $0x9f, %al
115         ja      sjis_h_2                # Upper > 0x9f
116         subb    $0x71, %al              # Upper -= 0x71
117         jmp     sjis_lower
118 sjis_h_2:
119         subb    $0xb1, %al              # Upper -= 0xb1
120 sjis_lower:
121         salb    %al                     # Upper *= 2
122         incb    %al                     # Upper += 1
123
124         cmpb    $0x7f, %ah
125         jbe     sjis_l_2
126         decb    %ah                     # Lower -= 1 if lower > 0x7f
127 sjis_l_2:
128         cmpb    $0x9e, %ah
129         jb      sjis_l_3
130         subb    $0x7d, %ah              # Lower -= 0x7d
131         incb    %al                     # Upper += 1
132         jmp     check_2byte_end
133 sjis_l_3:
134         subb    $0x1f, %ah              # Lower -= 0x1f
135 check_2byte_end:
136         stc
137         ret