4 ; Handling of the application's private sprite area (MDW)
6 ; © 1994-1998 Straylight
9 ;----- Licensing note -------------------------------------------------------
11 ; This file is part of Straylight's Sapphire library.
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)
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.
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.
27 ;----- Standard header ------------------------------------------------------
32 ;----- External dependencies ------------------------------------------------
37 GET sapphire:resources
41 ;----- Main code ------------------------------------------------------------
43 AREA |Sapphire$$Code|,CODE,READONLY
47 ; On entry: R0 == pointer to filename
49 ; On exit: May return an error
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.
59 STMFD R13!,{R0-R6,R12,R14} ;Stack some registers
60 WSPACE resspr__wSpace ;Find my workspace
62 ; --- Find out how big the sprite file is ---
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
69 ; --- Allocate a buffer for it ---
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
79 ; --- Set up the sprite area and load the file ---
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
88 ; --- Now set up the sprite area ---
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
99 ; --- Link this into the list ---
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
105 LDMFD R13!,{R0-R6,R12,R14} ;Restore all registers
106 BICS PC,R14,#V_flag ;And return to caller
108 ; --- It couldn't load -- tidy up ---
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
115 ; --- Something went wrong -- make an error ---
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
124 resspr__splk DCB "SPLK" ;SprLink's magic number
131 ; --- resspr_area ---
135 ; On exit: R0 == pointer to application's sprite area
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.
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
155 ; --- resspr_init ---
157 ; On entry: R0 == pointer to application name
161 ; Use: Initalises resspr, loading the Sprites resource.
166 STMFD R13!,{R0,R1,R12,R14} ;Save registers
167 WSPACE resspr__wSpace ;Find my workspace
169 ; --- Avoid multiple initialisation ---
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
175 ; --- Fallback position -- use the WIMP area ---
177 ADR R14,resspr__area-20 ;Put obscure address in
178 STR R14,resspr__listEnd ;As the list end
180 MOV R14,#1 ;Use the WIMP area
181 STR R14,resspr__area ;Save as sprite area pointer
183 ; --- Set up the shared resource sprites ---
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
191 ; --- Now initialise res and load the sprites ---
193 LDR R0,[R13,#0] ;Find the application name
194 BL msgs_init ;This will start up res
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
202 ; --- That's it, then ---
204 LDMFD R13!,{R0,R1,R12,PC}^ ;Return to caller
206 resspr__sprites DCB "Sprites",0
212 ;----- Workspace ------------------------------------------------------------
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
221 resspr__wSize EQU {VAR}-resspr__wStart
223 AREA |Sapphire$$LibData|,CODE,READONLY
230 ;----- That's all, folks ----------------------------------------------------