chiark / gitweb /
Initial revision
[ssr] / StraySrc / Libraries / Sapphire / csapph / s / ctype
1 ;
2 ; ctype.s
3 ;
4 ; A ctype implementation done the proper way
5 ;
6 ; © 1995 Straylight
7 ;
8
9 ;----- Standard header ------------------------------------------------------
10
11                 GET     libs:header
12                 GET     libs:swis
13
14                 GET     libs:stream
15
16 ;----- External dependencies ------------------------------------------------
17
18
19
20 ;----- Main code ------------------------------------------------------------
21
22                 AREA    |Sapphire$$Code|,CODE,READONLY
23
24 ; --- Character table format ---
25 ;
26 ; The table consists of halfword entries, which have the following format:
27 ;
28 ;   Bit         Meaning
29 ;    0          whitespace
30 ;    1          punctuation
31 ;    2          blank
32 ;    3          lower case
33 ;    4          upper case
34 ;    5          digit
35 ;    6          control character
36 ;    7          hex digit
37
38 ; --- ctype_init ---
39 ;
40 ; On entry:     --
41 ;
42 ; On exit:      --
43 ;
44 ; Use:          Sets up the character translation table.
45
46                 EXPORT  ctype_init
47 ctype_init      ROUT
48
49                 STMFD   R13!,{R0-R5,R14}        ;Save some registers
50                 ADR     R2,ctype__table         ;Point to the main table
51                 ADR     R3,ctype__terrTrans     ;Point to territory decode
52
53 10              LDRB    R1,[R3],#1              ;Load property number
54                 CMP     R1,#255                 ;Is this the end?
55                 BEQ     %f10                    ;Yes -- return then
56                 MOV     R0,#-1                  ;Get the current territory
57                 SWI     XTerritory_CharacterPropertyTable
58                 BVS     %90ctype_init           ;If not there, quit now
59                 LDRB    R1,[R3],#1              ;Load the bit number
60
61                 MOV     R4,#0                   ;Initialise a counter
62 00              TST     R4,#&1F000000           ;Run out of bits?
63                 LDREQ   R5,[R0],#4              ;Yes -- load some more then
64                 MOVS    R5,R5,LSR #1            ;Put a bit in carry
65                 LDRB    R14,[R2,R4,LSR #24]     ;Load the byte
66                 BICCC   R14,R14,R1              ;Maybe clear the bit
67                 ORRCS   R14,R14,R1              ;Maybe set it
68                 STRB    R14,[R2,R4,LSR #24]     ;Store the byte back
69                 ADDS    R4,R4,#&01000000        ;Increment the counter
70                 BCC     %b00                    ;And loop until done
71                 B       %b10                    ;Skip back for next bit
72
73 10              MOV     R0,#-1                  ;Use current territory
74                 SWI     XTerritory_UpperCaseTable ;Find upper case table
75                 MOVVC   R1,R0                   ;Remember this value
76                 MOVVC   R0,#-1                  ;Current territory again
77                 SWIVC   XTerritory_LowerCaseTable ;And get the lower table
78                 BVS     %90ctype_init           ;If not there, quit now
79
80                 MOV     R3,#0                   ;Get a counter going
81 00              LDRB    R14,[R2],#1             ;Load the flags byte
82                 MOVS    R14,R14,LSL #28         ;Put letter bits away
83                 LDRCSB  R14,[R0,R3,LSR #24]     ;If uppercase, get lower
84                 LDRMIB  R14,[R1,R3,LSR #24]     ;Otherwise get upper
85                 STRB    R14,[R2,#255]           ;Store in the table nicely
86                 ADDS    R3,R3,#&01000000        ;Move pointers on
87                 BCC     %b00                    ;And keep going until done
88
89 90ctype_init    LDMFD   R13!,{R0-R5,PC}^        ;Return when finished
90
91 S               EQU     1
92 P               EQU     2
93 B               EQU     4
94 L               EQU     8
95 U               EQU     16
96 D               EQU     32
97 C               EQU     64
98 X               EQU     128
99
100 ctype__terrTrans DCB    0,C
101                 DCB     1,U
102                 DCB     2,L
103                 DCB     4,P
104                 DCB     5,S
105                 DCB     6,D
106                 DCB     7,X
107                 DCB     255,255
108
109                 DCD     0
110 ctype__table    DCB     C,   C,   C,   C,       C,   C,   C,   C
111                 DCB     C+S, C+S, C+S, C+S,     C+S, C+S, C,   C
112                 DCB     C,   C,   C,   C,       C,   C,   C,   C
113                 DCB     C,   C,   C,   C,       C,   C,   C,   C
114                 DCB     B,   P,   P,   P,       P,   P,   P,   P
115                 DCB     P,   P,   P,   P,       P,   P,   P,   P
116                 DCB     D,   D,   D,   D,       D,   D,   D,   D
117                 DCB     D,   D,   P,   P,       P,   P,   P,   P
118                 DCB     P,   U+X, U+X, U+X,     U+X, U+X, U+X, U
119                 DCB     U,   U,   U,   U,       U,   U,   U,   U
120                 DCB     U,   U,   U,   U,       U,   U,   U,   U
121                 DCB     U,   U,   U,   P,       P,   P,   P,   P
122                 DCB     P,   L+X, L+X, L+X,     L+X, L+X, L+X, L
123                 DCB     L,   L,   L,   L,       L,   L,   L,   L
124                 DCB     L,   L,   L,   L,       L,   L,   L,   L
125                 DCB     L,   L,   L,   P,       P,   P,   P,   C
126
127                 DCB     P,   P,   P,   P,       P,   U,   L,   P
128                 DCB     P,   P,   P,   P,       P,   P,   P,   P
129                 DCB     P,   P,   P,   P,       P,   P,   P,   P
130                 DCB     P,   P,   U,   L,       P,   P,   P,   P
131                 DCB     P,   P,   P,   P,       P,   P,   P,   P
132                 DCB     P,   P,   P,   P,       P,   P,   P,   P
133                 DCB     P,   P,   P,   P,       P,   P,   P,   P
134                 DCB     P,   P,   P,   P,       P,   P,   P,   P
135                 DCB     U,   U,   U,   U,       U,   U,   U,   U
136                 DCB     U,   U,   U,   U,       U,   U,   U,   U
137                 DCB     U,   U,   U,   U,       U,   U,   U,   P
138                 DCB     U,   U,   U,   U,       U,   U,   U,   L
139                 DCB     L,   L,   L,   L,       L,   L,   L,   L
140                 DCB     L,   L,   L,   L,       L,   L,   L,   L
141                 DCB     L,   L,   L,   L,       L,   L,   L,   P
142                 DCB     L,   L,   L,   L,       L,   L,   L,   L
143
144                 DCB     0,   0,   0,   0,       0,   0,   0,   0
145                 DCB     0,   0,   0,   0,       0,   0,   0,   0
146                 DCB     0,   0,   0,   0,       0,   0,   0,   0
147                 DCB     0,   0,   0,   0,       0,   0,   0,   0
148                 DCB     0,   0,   0,   0,       0,   0,   0,   0
149                 DCB     0,   0,   0,   0,       0,   0,   0,   0
150                 DCB     0,   0,   0,   0,       0,   0,   0,   0
151                 DCB     0,   0,   0,   0,       0,   0,   0,   0
152                 DCB     0,   'a', 'b', 'c',     'd', 'e', 'f', 'g'
153                 DCB     'h', 'i', 'j', 'k',     'l', 'm', 'n', 'o'
154                 DCB     'p', 'q', 'r', 's',     't', 'u', 'v', 'w'
155                 DCB     'x', 'y', 'z', 0,       0,   0,   0,   0
156                 DCB     0,   'A', 'B', 'C',     'D', 'E', 'F', 'G'
157                 DCB     'H', 'I', 'J', 'K',     'L', 'M', 'N', 'O'
158                 DCB     'P', 'Q', 'R', 'S',     'T', 'I', 'V', 'W'
159                 DCB     'X', 'Y', 'Z', 0,       0,   0,   0,   0
160
161                 DCB     0,   0,   0,   0,       0,   '\86', '\85',  0
162                 DCB     0,   0,   0,   0,       0,   0,   0,   0
163                 DCB     0,   0,   0,   0,       0,   0,   0,   0
164                 DCB     0,   0,   '\9b', '\9a',     0,   0,   0,   0
165                 DCB     0,   0,   0,   0,       0,   0,   0,   0
166                 DCB     0,   0,   0,   0,       0,   0,   0,   0
167                 DCB     0,   0,   0,   0,       0,   0,   0,   0
168                 DCB     0,   0,   0,   0,       0,   0,   0,   0
169                 DCB     'à', 'á', 'â', 'ã',     'ä', 'å', 'æ', 'ç'
170                 DCB     'è', 'é', 'ê', 'ë',     'ì', 'í', 'î', 'ï'
171                 DCB     'ð', 'ñ', 'ò', 'ó',     'ô', 'õ', 'ö', 0
172                 DCB     'ø', 'ù', 'ú', 'û',     'ü', 'ý', 'þ', 'ß'
173                 DCB     'À', 'Á', 'Â', 'Ã',     'Ä', 'Å', 'Æ', 'Ç'
174                 DCB     'È', 'É', 'Ê', 'Ë',     'Ì', 'Í', 'Î', 'Ï'
175                 DCB     'Ð', 'Ñ', 'Ò', 'Ó',     'Ô', 'Õ', 'Ö', 0
176                 DCB     'Ø', 'Ù', 'Ú', 'Û',     'Ü', 'Ý', 'Þ', 'Y'
177
178                 LTORG
179
180 ; --- ctype_findTable ---
181 ;
182 ; On entry:     --
183 ;
184 ; On exit:      R0 == pointer to table
185 ;
186 ; Use:          Finds the character table.
187
188                 EXPORT  ctype_findTable
189 ctype_findTable ROUT
190
191                 ADRL    R0,ctype__table
192                 MOVS    PC,R14
193
194                 LTORG
195
196 ; --- Other ctype routines ---
197
198                 EXPORT  toupper
199 toupper         ADRL    R1,ctype__table
200                 LDRB    R2,[R1,R0]!
201                 TST     R2,#L
202                 LDRNEB  R0,[R1,#256]
203                 MOVS    PC,R14
204
205                 EXPORT  tolower
206 tolower         ADRL    R1,ctype__table
207                 LDRB    R2,[R1,R0]!
208                 TST     R2,#U
209                 LDRNEB  R0,[R1,#256]
210                 MOVS    PC,R14
211
212 ;----- That's all, folks ----------------------------------------------------
213
214                 END