Initial revision
[ssr] / StraySrc / Libraries / Sapphire / s / sapphRes
1 ;
2 ; sapphRes.s
3 ;
4 ; Sapphire shared resources (MDW)
5 ;
6 ; © 1995-1998 Straylight
7 ;
8
9 ;----- Licensing note -------------------------------------------------------
10 ;
11 ; This file is part of Straylight's Sapphire library.
12 ;
13 ; Sapphire is free software; you can redistribute it and/or modify
14 ; it under the terms of the GNU General Public License as published by
15 ; the Free Software Foundation; either version 2, or (at your option)
16 ; any later version.
17 ;
18 ; Sapphire is distributed in the hope that it will be useful,
19 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ; GNU General Public License for more details.
22 ;
23 ; You should have received a copy of the GNU General Public License
24 ; along with Sapphire. If not, write to the Free Software Foundation,
25 ; 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
27 ;----- Standard header ------------------------------------------------------
28
29 GET libs:header
30 GET libs:swis
31
32 GET libs:stream
33
34 ;----- External dependencies ------------------------------------------------
35
36 IMPORT |Image$$RO$$Base|
37
38 IMPORT rsc_sprites
39 IMPORT rsc_msgBase
40 IMPORT rsc_msgLimit
41 IMPORT rsc_tplBase
42 IMPORT rsc_tplLimit
43
44 ;----- Main code ------------------------------------------------------------
45
46 AREA |Main$$Code|,CODE,READONLY
47
48 ; --- sapphRes_find ---
49 ;
50 ; On entry: R0 == resource type code
51 ; R1 == pointer to resource name (only required for
52 ; srType_template)
53 ;
54 ; On exit: CS if found, and
55 ; R0 == address of resource
56 ; R1 == limit (for messages)
57 ; else CC and
58 ; Registers preserved
59 ;
60 ; Use: Looks up the address of a resource in the shared resource
61 ; DLL.
62
63 EXPORT sapphRes_find
64 sapphRes_find ROUT
65
66 CMP R0,#srType_max ;Is the type in range?
67 ADDCC PC,PC,R0,LSL #2 ;Yes -- dispatch it then
68 BICS PC,R14,#C_flag ;Otherwise couldn't find it
69
70 B sr__findSprite ;Find a sprite resource
71 B sr__findMessages ;Find a messages resource
72 B sr__findTemplate ;Find a template resource
73
74 LTORG
75
76 ; --- sr__findSprite ---
77 ;
78 ; On entry: --
79 ;
80 ; On exit: R0 == address of a sprite area
81 ;
82 ; Use: Locates the sprite resource within the DLL.
83
84 sr__findSprite ROUT
85
86 LDR R0,=rsc_sprites ;Find the sprite area
87 ORRS PC,R14,#C_flag ;And return to caller
88
89 LTORG
90
91 ; --- sr__findMessages ---
92 ;
93 ; On entry: --
94 ;
95 ; On exit: R0 == address of messages base
96 ; R1 == address of messages limit
97 ;
98 ; Use: Locates the messages resource within the DLL.
99
100 sr__findMessages ROUT
101
102 ADR R0,sr__msgs ;Point to messages base/limit
103 LDMIA R0,{R0,R1} ;Load them out
104 ORRS PC,R14,#C_flag ;And return to caller
105
106 sr__msgs DCD rsc_msgBase
107 DCD rsc_msgLimit
108
109 LTORG
110
111 ; --- sr__findTemplate ---
112 ;
113 ; On entry: R1 == pointer to template name
114 ;
115 ; On exit: CS and R0 == pointer to embedded template block, or CC
116 ;
117 ; Use: Locates a named window defintion.
118
119 sr__findTemplate ROUT
120
121 STMFD R13!,{R2-R6,R14} ;Save some registers
122 ADR R14,sr__tpls ;Point to base and limit
123 LDMIA R14,{R2,R3} ;Load them out
124
125 ; --- Search the template table ---
126
127 10 CMP R2,R3 ;Have we finished yet?
128 BCS %90sr__findTemplate ;Yes -- then we failed
129
130 ; --- Check for a name match ---
131
132 MOV R4,R1
133 00 LDRB R5,[R4],#1 ;Load first char of name
134 SUB R14,R5,#'A' ;Convert to a letter index
135 CMP R14,#26 ;Is it in range?
136 ORRCC R5,R5,#&20 ;Yes -- convert to lowercase
137 CMP R5,#&20 ;Is the byte a control char?
138 MOVCC R5,#0 ;Yes -- say it's zero
139
140 LDRB R6,[R2],#1 ;Load first char of name
141 SUB R14,R6,#'A' ;Convert to a letter index
142 CMP R14,#26 ;Is it in range?
143 ORRCC R6,R6,#&20 ;Yes -- convert to lowercase
144 CMP R6,#&20 ;Is the byte a control char?
145 MOVCC R6,#0 ;Yes -- say it's zero
146
147 ; --- Compare the characters
148
149 CMP R5,R6 ;Do the chars match?
150 BNE %50sr__findTemplate ;No -- move on to next one
151 CMP R5,#0 ;Is it the end?
152 BNE %b00 ;No -- keep looking
153
154 ; --- Found a match ---
155
156 ADD R2,R2,#3 ;Word align the output
157 BIC R2,R2,#3 ;To make sure
158 LDR R0,[R2,#0] ;Load the template base
159 LDMFD R13!,{R2-R6,R14} ;Restore registers
160 ORRS PC,R14,#C_flag ;And return success
161
162 ; --- Failed -- move on to next entry ---
163
164 50 CMP R6,#&20 ;Reached the end yet?
165 LDRCSB R6,[R2],#1 ;No -- load next byte
166 BCS %b50 ;And keep on looping
167 ADD R2,R2,#4+3 ;Word align the output
168 BIC R2,R2,#3 ;To make sure
169 B %10sr__findTemplate ;And rejoin the main loop
170
171 ; --- Failed entirely ---
172
173 90 LDMFD R13!,{R2-R6,R14} ;Restore registers
174 BICS PC,R14,#C_flag ;And return to caller
175
176 sr__tpls DCD rsc_tplBase
177 DCD rsc_tplLimit
178
179 LTORG
180
181 ;----- Resource types -------------------------------------------------------
182
183 ^ 0
184 srType_sprites # 1 ;Sprite resource, returned as
185 ;address of sprite area
186
187 srType_messages # 1 ;Messages resource, returned
188 ;as address of base and limit
189 ;pair
190
191 srType_template # 1 ;Template (window) resource,
192 ;returned as address of
193 ;embedded template def.
194
195 srType_max # 0
196
197 ;----- That's all, folks ----------------------------------------------------
198
199 END