chiark / gitweb /
JPEG support and other fixes from Nick Clark
[ssr] / StraySrc / Libraries / Sapphire / s / resources
1 ;
2 ; resources.s
3 ;
4 ; Access to shared resource DLL (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                 GET     sapphire:except
37                 GET     sapphire:sapphire
38
39 rsc__version    EQU     100
40
41 ;----- Main code ------------------------------------------------------------
42
43                 AREA    |Sapphire$$Code|,CODE,READONLY
44
45 ; --- resources_init ---
46 ;
47 ; On entry:     --
48 ;
49 ; On exit:      --
50 ;
51 ; Use:          Initialises the shared resource system, setting up the
52 ;               link to the SapphRes DLL.  Note that this initialisation is
53 ;               /not/ performed automatically.
54
55                 EXPORT  resources_init
56 resources_init  ROUT
57
58                 STMFD   R13!,{R0,R1,R12,R14}    ;Save some registers
59                 WSPACE  rsc__wSpace             ;Find my workspace
60                 LDR     R14,rsc__find           ;Locate the function pointer
61                 CMP     R14,#0                  ;Have I set it up?
62                 LDMNEFD R13!,{R0,R1,R12,PC}^    ;I guess so then
63                 MOV     R14,#0                  ;A nice null pointer
64                 STR     R14,rsc__dllHandle      ;Resource DLL not found yet
65
66                 ; --- Save the application handle
67
68                 SWI     XDLL_SaveHandle         ;Find my current app handle
69                 BVS     %90resources_init       ;Failed -- return now then
70                 STR     R0,rsc__appHandle       ;Save that away
71
72                 ; --- Now do the dynamic linking ---
73
74                 ADR     R0,rsc__dllName         ;Point to the DLL name
75                 LDR     R1,=rsc__version        ;Load the resource version
76                 SWI     XDLL_Find               ;Try to find the version
77                 STRVC   R0,rsc__dllHandle       ;Store the DLL handle
78                 ADRVC   R1,rsc__findRsc         ;Point to routine name
79                 SWIVC   XDLL_FindEntry          ;Try to find the entry
80                 STRVC   R0,rsc__find            ;Store this away nicely
81
82                 ; --- Initialise things which we need ---
83
84                 BL      except_init             ;We need to finalise properly
85
86                 ; --- Set up the finalisation ---
87
88                 ADR     R0,rsc__closeDown       ;Point to the exit handler
89                 MOV     R1,R12                  ;Pass it my workspace
90                 BL      except_atExit           ;And register the handler
91
92 90              LDMFD   R13!,{R0,R1,R12,PC}^    ;Return to caller when done
93
94 rsc__dllName    DCB     "[Sapphire.Resources]",0
95 rsc__findRsc    DCB     "sapphRes_find",0
96
97                 LTORG
98
99 ; --- resources_find ---
100 ;
101 ; On entry:     R0 == resource code
102 ;               R1 == pointer to name (only for rsType_template)
103 ;
104 ; On exit:      CS if found, and
105 ;                 R0 == pointer to resource
106 ;                 R1 == pointer to resource limit (only for rsType_message)
107 ;               else CC and
108 ;                 R0,R1 preserved
109 ;
110 ; Use:          Locates resources in the shared resource DLL.
111
112                 EXPORT  resources_find
113 resources_find  ROUT
114
115                 STMFD   R13!,{R12,R14}          ;Save some registers
116                 WSPACE  rsc__wSpace             ;Locate my workspace address
117                 LDR     R12,rsc__find           ;Load the routine pointer
118                 CMP     R12,#0                  ;Have we found the DLL?
119                 BEQ     %90resources_find       ;No -- skip
120                 MOV     R14,PC                  ;Set up return address
121                 MOV     PC,R12                  ;Call the routine
122                 LDMFD   R13!,{R12,R14}          ;Restore caller's registers
123                 ORRCSS  PC,R14,#C_flag          ;Set C if C must be set
124                 BICCCS  PC,R14,#C_flag          ;Clear C if C must be clear
125
126 90              LDMFD   R13!,{R12,R14}          ;Restore caller's registers
127                 BICS    PC,R14,#C_flag          ;Couldn't find the resource
128
129                 LTORG
130
131 ; --- rsc__closeDown ---
132 ;
133 ; On entry:     --
134 ;
135 ; On exit:      --
136 ;
137 ; Use:          Closes down the shared resource DLL.
138
139 rsc__closeDown  ROUT
140
141                 STMFD   R13!,{R0,R14}           ;Save some registers
142                 LDR     R0,rsc__appHandle       ;Load my application handle
143                 SWI     XDLL_RestoreHandle      ;Set that up nicely
144                 LDR     R0,rsc__dllHandle       ;Recover the DLL handle
145                 SWI     XDLL_Lose               ;No longer need this
146                 LDMFD   R13!,{R0,PC}^           ;And return to caller
147
148                 LTORG
149
150 rsc__wSpace     DCD     0
151
152 ;----- Workspace ------------------------------------------------------------
153
154                 ^       0,R12
155 rsc__wStart     #       0
156
157 rsc__find       #       4                       ;Address of sapphRes_find
158 rsc__appHandle  #       4                       ;Our application handle
159 rsc__dllHandle  #       4                       ;SapphRes's DLL handle
160
161 rsc__wSize      EQU     {VAR}-rsc__wStart
162
163                 AREA    |Sapphire$$LibData|,CODE,READONLY
164
165                 DCD     rsc__wSize
166                 DCD     rsc__wSpace
167                 DCD     0
168                 DCD     0
169
170 ;----- That's all, folks ----------------------------------------------------
171
172                 END