Initial revision
[ssr] / StraySrc / Libraries / Sapphire / s / resspr
1 ;
2 ; resspr.s
3 ;
4 ; Handling of the application's private sprite area (MDW)
5 ;
6 ; © 1994-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 ;----- External dependencies ------------------------------------------------
33
34 GET sapphire:alloc
35 GET sapphire:msgs
36 GET sapphire:res
37 GET sapphire:resources
38 GET sapphire:sapphire
39 GET sapphire:string
40
41 ;----- Main code ------------------------------------------------------------
42
43 AREA |Sapphire$$Code|,CODE,READONLY
44
45 ; --- resspr_load ---
46 ;
47 ; On entry: R0 == pointer to filename
48 ;
49 ; On exit: May return an error
50 ;
51 ; Use: Loads a sprite file into memory and allows it to be
52 ; referenced through resspr_area. Note that Straylight's
53 ; Sprinkle module must be loaded if more than one sprite file
54 ; is to be used for resources.
55
56 EXPORT resspr_load
57 resspr_load ROUT
58
59 STMFD R13!,{R0-R6,R12,R14} ;Stack some registers
60 WSPACE resspr__wSpace ;Find my workspace
61
62 ; --- Find out how big the sprite file is ---
63
64 MOV R1,R0 ;Point to the filename
65 MOV R0,#17 ;Find information about file
66 SWI XOS_File ;Get information about it
67 BVS %99resspr_load ;If it failed, go ahead
68
69 ; --- Allocate a buffer for it ---
70
71 ADD R3,R4,#12+3 ;Add 12 byte overhead and...
72 BIC R3,R3,#3 ;... word align
73 MOV R0,R3 ;Get the size
74 BL alloc ;Allocate the memory
75 BLCS alloc_error ;If it failed, get error
76 BCS %99resspr_load ;And go tidy up
77 MOV R6,R0 ;Remember the address
78
79 ; --- Set up the sprite area and load the file ---
80
81 STR R3,[R0,#0] ;Store size in first word
82 MOV R0,#16 ;Load the file into memory
83 ADD R2,R6,#12 ;Point past first word
84 MOV R3,#0 ;Load where I want it
85 SWI XOS_File ;Load the file
86 BVS %98resspr_load ;If it failed, tidy up
87
88 ; --- Now set up the sprite area ---
89
90 ADD R14,R6,#12 ;Point to sprite block base
91 LDMIA R14,{R0-R2} ;Load those out nicely
92 ADD R1,R1,#8 ;Grow the extension words
93 ADD R2,R2,#8 ;Allow 8 more bytes here
94 LDR R3,resspr__splk ;Get magic word for SprLink
95 LDR R4,resspr__last ;Find the list terminator
96 ADD R14,R6,#4 ;Point to appropriate place
97 STMIA R14,{R0-R4} ;Store all that lot away
98
99 ; --- Link this into the list ---
100
101 LDR R14,resspr__listEnd ;Find the list end
102 STR R6,[R14,#20] ;Store that away nicely
103 STR R6,resspr__listEnd ;This is now the last block
104
105 LDMFD R13!,{R0-R6,R12,R14} ;Restore all registers
106 BICS PC,R14,#V_flag ;And return to caller
107
108 ; --- It couldn't load -- tidy up ---
109
110 98resspr_load MOV R5,R0 ;Keep error pointer safe
111 MOV R0,R6 ;Find the heap block
112 BL free ;Free the block now
113 MOV R0,R5 ;Restore error pointer
114
115 ; --- Something went wrong -- make an error ---
116
117 99resspr_load ADD R2,R0,#4 ;Point to error string
118 ADR R0,resspr__err ;Point to error skeleton
119 BL msgs_error ;Build the error up
120 ADD R13,R13,#4 ;Move stack pointer past R0
121 LDMFD R13!,{R1-R6,R12,R14} ;Restore registers
122 ORRS PC,R14,#V_flag ;And return the error
123
124 resspr__splk DCB "SPLK" ;SprLink's magic number
125
126 resspr__err DCD 1
127 DCB "rsprSLE",0
128
129 LTORG
130
131 ; --- resspr_area ---
132 ;
133 ; On entry: --
134 ;
135 ; On exit: R0 == pointer to application's sprite area
136 ;
137 ; Use: Locates the application's `Sprites' resource in memory and
138 ; returns a pointer to it. If the resource has not been
139 ; loaded, 1 is returned, to indicate to use the WIMP area.
140 ; If multiple sprite files have been loaded, this call returns
141 ; the address of the first: they will have been linked together
142 ; so that Sprinkle will treat them as one big area.
143
144 EXPORT resspr_area
145 resspr_area ROUT
146
147 STMFD R13!,{R14} ;Save a register
148 LDR R0,resspr__wSpace ;Find my workspace
149 LDR R14,sapph_workspace ;Find workspace base address
150 LDR R0,[R0,R14] ;Locate sprite area
151 LDMFD R13!,{PC}^ ;Return to caller
152
153 LTORG
154
155 ; --- resspr_init ---
156 ;
157 ; On entry: R0 == pointer to application name
158 ;
159 ; On exit: --
160 ;
161 ; Use: Initalises resspr, loading the Sprites resource.
162
163 EXPORT resspr_init
164 resspr_init ROUT
165
166 STMFD R13!,{R0,R1,R12,R14} ;Save registers
167 WSPACE resspr__wSpace ;Find my workspace
168
169 ; --- Avoid multiple initialisation ---
170
171 LDR R14,resspr__area ;Get the area pointer
172 CMP R14,#0 ;Is it NULL
173 LDMNEFD R13!,{R0,R1,R12,PC}^ ;No -- we've already done it
174
175 ; --- Fallback position -- use the WIMP area ---
176
177 ADR R14,resspr__area-20 ;Put obscure address in
178 STR R14,resspr__listEnd ;As the list end
179
180 MOV R14,#1 ;Use the WIMP area
181 STR R14,resspr__area ;Save as sprite area pointer
182
183 ; --- Set up the shared resource sprites ---
184
185 MOV R0,#rsType_sprite ;Find the sprite resource
186 BL resources_find ;Try to find the resources
187 STRCS R0,resspr__area ;It will do as a sprite area
188 MOVCC R0,#0 ;Otherwise terminate normally
189 STR R0,resspr__last ;Store that as last pointer
190
191 ; --- Now initialise res and load the sprites ---
192
193 LDR R0,[R13,#0] ;Find the application name
194 BL msgs_init ;This will start up res
195
196 ADR R0,resspr__sprites ;Point to the leafnae
197 MOV R1,R11 ;Build name in scratchpad
198 BL res_find ;Translate the name
199 BLCS resspr_load ;If there, load the file
200 SWIVS OS_GenerateError ;If failed, there's no hope
201
202 ; --- That's it, then ---
203
204 LDMFD R13!,{R0,R1,R12,PC}^ ;Return to caller
205
206 resspr__sprites DCB "Sprites",0
207
208 LTORG
209
210 resspr__wSpace DCD 0
211
212 ;----- Workspace ------------------------------------------------------------
213
214 ^ 0,R12
215 resspr__wStart # 0
216
217 resspr__area # 4 ;Pointer to sprite area
218 resspr__listEnd # 4 ;Last block in the list
219 resspr__last # 4 ;Pointer to list terminator
220
221 resspr__wSize EQU {VAR}-resspr__wStart
222
223 AREA |Sapphire$$LibData|,CODE,READONLY
224
225 DCD resspr__wSize
226 DCD resspr__wSpace
227 DCD 256
228 DCD resspr_init
229
230 ;----- That's all, folks ----------------------------------------------------
231
232 END