chiark / gitweb /
JPEG support and other fixes from Nick Clark
[ssr] / StraySrc / Libraries / Sapphire / s / tspr
1 ;
2 ; tspr.s
3 ;
4 ; Toolsprite hacking for things like border sizes (TMA)
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:screen
35                 GET     sapphire:wimp
36
37 ;----- Main code ------------------------------------------------------------
38
39                 AREA    |Sapphire$$Code|,CODE,READONLY
40
41 ; --- tspr_getSprAddr ---
42 ;
43 ; On entry:     --
44 ;
45 ; On exit:      R0 == pointer to tool sprites, or 0 if none
46 ;
47 ; Use:          Returns a pointer to the toolsprites. If the user is using
48 ;               RISC OS 2, or there are no toolsprites defined, then
49 ;               0 is returned.
50
51                 EXPORT  tspr_getSprAddr
52 tspr_getSprAddr ROUT
53
54                 STMFD   R13!,{R1,R2,R14}        ;Stack some registers
55
56                 BL      wimp_version            ;Get the wimp version number
57                 CMP     R0,#300                 ;Are we using RISC OS 2?
58                 MOVLT   R0,#0                   ;Yes -- no sprites then
59                 BLT     %90tspr_getSprAddr      ;...and return
60                 SWIEQ   Wimp_BaseOfSprites      ;We want this for 3.00
61                 MOVEQ   R0,R1                   ;...RAM resident part please
62                 BEQ     %90tspr_getSprAddr      ;...and return
63                 MOV     R1,#94                  ;We need to test with 350...
64                 ADD     R1,R1,#256              ;...so create the number
65                 CMP     R0,R1                   ;Is version < 3.50?
66                 BLT     %10                     ;Yes -- deal with it then
67
68                 ; --- We are using RISC OS 3.50 or higher ---
69
70                 MOV     R0,#9                   ;Read toolsprite control blk
71                 SWI     Wimp_ReadSysInfo        ;Find it then
72                 B       %90tspr_getSprAddr      ;And return
73
74                 ; --- We are using RISC OS 3.01 - 3.49 ---
75
76 10              ADR     R1,tspr__versionList    ;Point to the version list
77 20              LDR     R2,[R1],#4              ;Load the version number
78                 CMP     R0,R2                   ;Is it the one we want?
79                 BLT     %90tspr_getSprAddr      ;It isn't in list -- return
80                 BEQ     %30tspr_getSprAddr      ;It is -- deal with it
81                 CMP     R2,#-1                  ;Are we at the end?
82                 MOVEQ   R0,#0                   ;Yes -- no sprite then
83                 BEQ     %90tspr_getSprAddr      ;...return
84                 ADD     R1,R1,#4                ;Skip past address field
85                 B       %20tspr_getSprAddr      ;And keep searching
86
87                 ; --- We have located the version number ---
88
89 30              STMFD   R13!,{R3-R5}            ;Stack some more registers
90                 LDR     R14,[R1]                ;Get the address offset
91                 MOV     R0,#18                  ;Look-up module name
92                 ADR     R1,tspr__moduleName     ;Point to the module name
93                 SWI     OS_Module               ;Get information then
94                 LDR     R0,[R4,R14]             ;Get the toolsprite address
95                 SUB     R0,R0,#4                ;Correct it nicely
96                 LDMFD   R13!,{R3-R5}            ;Get registers back
97
98                 ; --- Return to caller ---
99
100 90              LDMFD   R13!,{R1,R2,PC}^        ;Unstack registers and return
101
102 tspr__moduleName
103                 DCB     "WindowManager",0
104                 ALIGN
105
106 tspr__versionList
107                 DCD     316,1676
108                 DCD     322,1708
109                 DCD     -1
110
111                 LTORG
112
113 ; --- tspr_borderWidths ---
114 ;
115 ; On entry:     --
116 ;
117 ; On exit:      R0 == title bar height
118 ;               R1 == vertical scroll bar width
119 ;               R2 == horizontal scroll bar height
120 ;
121 ; Use:          Return the width of window tools by looking at the
122 ;               sprites associated with them, rather than creating
123 ;               a temporary window.
124
125                 EXPORT  tspr_borderWidths
126 tspr_borderWidths ROUT
127
128                 STMFD   R13!,{R3-R10,R14}       ;Stack some registers
129
130                 ; --- Find out about the current mode ---
131
132                 BL      screen_getInfo          ;Get some screen information
133                 MOV     R7,#0                   ;Flags word so far
134                 LDR     R9,[R0,#screen_xEig]    ;Get the xEig Factor
135                 LDR     R10,[R0,#screen_yEig]   ;and the yEig Factor
136                 CMP     R9,#1                   ;Are we in a high...
137                 CMPEQ   R10,#1                  ;...resolution mode?
138                 ORREQ   R7,R7,#1                ;Yes -- remember this
139                 LDR     R1,[R0,#screen_bpp]     ;Get the bpp
140                 CMP     R1,#1                   ;Monochrome mode?
141                 ORREQ   R7,R7,#2                ;Yes -- remember this too
142
143                 ; --- Are we using tool sprites? ---
144
145                 BL      tspr_getSprAddr         ;Find the address of sprites
146                 CMP     R0,#0                   ;Are there any?
147                 BEQ     %80tspr_borderWidths    ;No -- get RISC OS 2 defaults
148                 MOV     R8,R0                   ;Put sprite block in R8
149
150                 ; --- Use sprites to get the border widths ---
151                 ;
152                 ; First, find out about the title bar
153
154                 ADR     R3,tspr__titleName      ;Point to title bar sprite ^
155                 BL      %50tspr_borderWidths    ;Get sprite information
156                 MOV     R0,R4                   ;The returned height
157                 BVC     %20tspr_borderWidths    ;All OK -- now vertical
158                 TST     R7,#1                   ;Are we in a high res mode?
159                 MOVNE   R0,#42                  ;Yes -- use this height
160                 MOVEQ   R0,#44                  ;No -- use this height
161
162                 ; --- Now the vertical scroll bar ---
163
164 20              ADR     R3,tspr__vertName       ;Point to vert bar sprite ^
165                 BL      %50tspr_borderWidths    ;Get sprite information
166                 MOVVC   R1,R3                   ;The returned height
167                 MOVVS   R1,#42                  ;The default width
168
169                 ; --- Finally the horizontal scroll bar height ---
170
171 30              ADR     R3,tspr__horzName       ;Point to horz bar sprite ^
172                 BL      %50tspr_borderWidths    ;Get sprite information
173                 MOV     R2,R4                   ;The returned height
174                 BVC     %90tspr_borderWidths    ;All OK -- now return
175                 TST     R7,#1                   ;Are we in a high res mode?
176                 MOVNE   R2,#42                  ;Yes -- use this height
177                 MOVEQ   R2,#44                  ;No -- use this height
178                 B       %90tspr_borderWidths    ;Return to caller
179
180                 ; --- Find out about the given sprite ---
181
182 50              BIC     R14,R14,#V_flag         ;No error yet
183                 STMFD   R13!,{R0-R2,R14}        ;Preserve these values
184                 MOV     R14,R3                  ;Remember this pointer
185                 LDR     R2,[R3,R7,LSL#2]        ;Actually point to the name
186                 MOV     R1,R8                   ;The sprite block
187                 MOV     R0,#256+40              ;Read sprite information
188                 SWI     XOS_SpriteOp            ;Read info
189                 LDRVS   R2,[R14]                ;Error -- get default name
190                 MOVVS   R0,#256+40              ;...read sprite information
191                 SWIVS   XOS_SpriteOp            ;...try again
192                 MOVVC   R3,R3,LSL R9            ;Calculate width in OS units
193                 MOVVC   R4,R4,LSL R10           ;Calculate height in OS units
194                 LDMFD   R13!,{R0-R2,R14}        ;Get registers back
195                 ORRVSS  PC,R14,#V_flag          ;Return with error
196                 BICVCS  PC,R14,#V_flag          ;Or maybe without
197
198                 ; --- Use RISC OS 2 defaults ---
199
200 80              MOV     R1,#42                  ;This is width in all modes
201                 TST     R7,#1                   ;Are we in a high res mode?
202                 MOVNE   R0,#42                  ;Yes -- use this height
203                 MOVEQ   R0,#44                  ;No -- use this height
204                 MOV     R2,R0                   ;This height is the same
205
206                 ; --- Return to the caller ---
207
208 90              LDMFD   R13!,{R3-R10,PC}^       ;Return
209
210 tspr__titleName DCD     tbarlcap
211                 DCD     tbarlcap22
212                 DCD     tbarlcap0
213                 DCD     tbarlcap23
214
215 tspr__vertName  DCD     vwellbcap
216                 DCD     vwellbcap22
217                 DCD     vwellbcap0
218                 DCD     vwellbcap23
219
220 tspr__horzName  DCD     hwelllcap
221                 DCD     hwelllcap22
222                 DCD     hwelllcap0
223                 DCD     hwelllcap23
224
225 tbarlcap        DCB     "tbarlcap",0
226 tbarlcap22      DCB     "tbarlcap22",0
227 tbarlcap0       DCB     "tbarlcap0",0
228 tbarlcap23      DCB     "tbarlcap23",0
229
230 vwellbcap       DCB     "vwellbcap",0
231 vwellbcap22     DCB     "vwellbcap22",0
232 vwellbcap0      DCB     "vwellbcap0",0
233 vwellbcap23     DCB     "vwellbcap23",0
234
235 hwelllcap       DCB     "hwelllcap",0
236 hwelllcap22     DCB     "hwelllcap22",0
237 hwelllcap0      DCB     "hwelllcap0",0
238 hwelllcap23     DCB     "hwelllcap23",0
239
240                 LTORG
241
242 ; --- tspr_adjustBox ---
243 ;
244 ; On entry:     R1 == pointer to Wimp_OpenWindow block to modify
245 ;
246 ; On exit:      Block updated in place
247 ;
248 ; Use:          Updates the open block to ensure that the window is opened
249 ;               on the screen.
250
251                 EXPORT  tspr_adjustBox
252 tspr_adjustBox  ROUT
253
254                 ; --- Find out which gadgets the window has ---
255
256                 STMFD   R13!,{R0-R11,R14}       ;Save a job load of regs
257                 SUB     R13,R13,#36             ;Space for a window state
258                 LDR     R0,[R1,#0]              ;Load the caller's handle
259                 STR     R0,[R13,#0]             ;Save it in my block
260                 MOV     R1,R13                  ;Point to my state block
261                 SWI     Wimp_GetWindowState     ;Find the window information
262                 LDR     R3,[R13,#32]            ;Load the window flags out
263                 ADD     R13,R13,#36             ;Reclaim the stack space
264
265                 ; --- Now mangle the window block ---
266
267                 BL      tspr_borderWidths       ;Get the border widths
268                 LDR     R4,[R13,#4]             ;Load his pointer back again
269                 LDMIB   R4,{R5-R8}              ;Load the coordinates out
270                 TST     R3,#&0f000000           ;Is there a top-row gadget?
271                 ADDNE   R8,R8,R0                ;Yes -- add title bar height
272                 TST     R3,#&10000000           ;Is there a vert. scrollbar?
273                 ADDNE   R7,R7,R1                ;Yes -- add scrollbar width
274                 TST     R3,#&40000000           ;Is there a horiz. one?
275                 SUBNE   R6,R6,R2                ;Yes -- sub scrollbar height
276
277                 ; --- Get the screen dimensions ---
278
279                 BL      screen_getInfo          ;Find the screen information
280                 MOV     R11,R0                  ;Remember this block's pos
281                 ADD     R0,R0,#screen_width     ;Find the screen width
282                 LDMIA   R0,{R9,R10}             ;Load width and height
283
284                 ; --- Now load the original coords again ---
285
286                 LDMIB   R4,{R0-R3}              ;Load the coordinates out
287
288                 ; --- Mangle the x coordinates first ---
289
290                 SUB     R14,R7,R5               ;Get the window width
291                 CMP     R14,R9                  ;Is this wider than screen?
292                 SUBGT   R0,R0,R5                ;Yes -- fit it exactly then
293                 SUBGT   R2,R7,R2                ;And fit right edge to screen
294                 SUBGT   R2,R9,R2
295
296                 SUBS    R14,R7,R9               ;Is the right edge on?
297                 SUBGT   R2,R2,R14               ;No -- shift it back on then
298                 SUBGT   R0,R0,R14               ;Ensure the width is constant
299
300                 SUBS    R14,R5,#0               ;Is the left edge on?
301                 SUBLT   R0,R0,R14               ;No -- shift it back on
302                 SUBLT   R2,R2,R14               ;Ensure constant width again
303
304                 ; --- Now mangle the y coordinates ---
305
306                 SUBS    R14,R8,R6               ;Get the window height
307                 CMP     R14,R10                 ;Is this higher than screen?
308                 SUBGT   R1,R1,R6                ;Yes -- fit it exactly then
309                 SUBGT   R3,R8,R3                ;And fit top edge to screen
310                 SUBGT   R3,R10,R3
311
312                 SUBS    R14,R8,R10              ;Is the top edge on?
313                 SUBGT   R3,R3,R14               ;No -- shift it back on then
314                 SUBGT   R1,R1,R14               ;Ensure height is constant
315
316                 LDR     R14,[R11,#screen_dy]    ;Get screen dy value
317                 SUBS    R14,R6,R14              ;Is the bottom edge on?
318                 SUBLT   R1,R1,R14               ;No -- shift it back on
319                 SUBLT   R3,R3,R14               ;Ensure constant height again
320
321                 ; --- Store it back and return ---
322
323                 STMIB   R4,{R0-R3}              ;Store coordinates back again
324                 LDMFD   R13!,{R0-R11,PC}^       ;Return to caller
325
326                 LTORG
327
328 ;----- That's all, folks ----------------------------------------------------
329
330                 END