chiark / gitweb /
JPEG support and other fixes from Nick Clark
[ssr] / StraySrc / Libraries / Sapphire / s / winUtils
1 ;
2 ; winUtils.s
3 ;
4 ; Various window utility functions (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:screen
35
36 ;----- Main code ------------------------------------------------------------
37
38                 AREA    |Sapphire$$Code|,CODE,READONLY
39
40 ; --- winUtils_setTitle ---
41 ;
42 ; On entry:     R0 == pointer to string to set in title
43 ;               R1 == pointer to title bar buffer
44 ;               R2 == window handle to write to
45 ;
46 ; On exit:      --
47 ;
48 ; Use:          Sets a window's title string.  If the string is different,
49 ;               the title is redrawn.  The contortion to do this is
50 ;               unpleasant, and is not to be performed in public.
51
52                 EXPORT  winUtils_setTitle
53 winUtils_setTitle ROUT
54
55                 STMFD   R13!,{R0-R6,R14}        ;Save some registers
56
57                 ; --- Copy the string over nicely ---
58
59                 MOV     R3,#0                   ;Not changed anything yet
60 00              LDRB    R4,[R0],#1              ;Get a byte from new string
61                 LDRB    R5,[R1],#1              ;Get a byte from old string
62
63                 CMP     R4,#' '                 ;Convert control chars...
64                 MOVLT   R4,#0                   ;... to null bytes
65                 CMP     R5,#' '                 ;And again for the other char
66                 MOVLT   R5,#0
67
68                 CMP     R4,R5                   ;Are they different?
69                 MOVNE   R3,#1                   ;Yes -- set the flag
70                 STRNEB  R4,[R1,#-1]             ;And store in the buffer
71
72                 CMP     R4,#0                   ;Is this the end of it all?
73                 BNE     %00winUtils_setTitle    ;No -- go round for another
74                 STRB    R4,[R1,#-1]             ;Terminate string with NULL
75
76                 ; --- Return if it was the same ---
77
78                 CMP     R3,#0                   ;Did we do anything?
79                 LDMEQFD R13!,{R0-R6,PC}^        ;No -- return right now
80
81                 ; --- Read the window coordinates (yuk) ---
82
83                 SUB     R13,R13,#36             ;Make way for a window block
84                 STR     R2,[R13,#0]             ;Store the handle in there
85                 MOV     R1,R13                  ;Point to the block
86                 SWI     Wimp_GetWindowState     ;Get the window information
87
88                 LDR     R14,[R13,#32]           ;Get the window flags
89                 TST     R14,#&00010000          ;Check that it's open
90                 ADDEQ   R13,R13,#36             ;No -- reclaim stack space
91                 LDMEQFD R13!,{R0-R6,PC}^        ;No -- return right now
92
93                 LDMIB   R13,{R2-R5}             ;Load the coordinates out
94                 SWI     Wimp_GetWindowOutline   ;Now find the real position
95                 LDR     R6,[R13,#16]            ;Load the top coordinate
96
97                 MOV     R0,#-1                  ;Redraw everything (yuk)
98                 MOV     R1,R2                   ;The left hand side to do
99                 MOV     R2,R5                   ;The bottom part to do
100                 MOV     R3,R4                   ;The right hand side to do
101                 MOV     R4,R6                   ;And the top part to do
102                 SWI     Wimp_ForceRedraw        ;Force the screen update
103
104                 ADD     R13,R13,#36             ;Restore the stack again
105                 LDMFD   R13!,{R0-R6,PC}^        ;Return to caller
106
107                 LTORG
108
109 ; --- winUtils_setPosition ---
110 ;
111 ; On entry:     R0 == window opening style
112 ;               R1 == pointer to window state block
113 ;               R2,R3 == extra arguments for displaying the window
114 ;
115 ; On exit:      R2,R3 contain position for opening with Wimp_CreateMenu
116 ;
117 ; Use:          Modifies the window state block pointed to by R0 so that the
118 ;               window appears as required in the given opening style.  The
119 ;               window is always moved to the top.
120
121                 EXPORT  winUtils_setPosition
122 winUtils_setPosition ROUT
123
124                 STMFD   R13!,{R0,R1,R4-R8,R14}  ;Save some registers
125
126                 ; --- Set up values in registers ---
127
128                 LDMIB   R1,{R4-R7}              ;Load the window position
129                 SUB     R6,R6,R4                ;Get window width in R6
130                 SUB     R7,R7,R5                ;And window height in R7
131
132                 ; --- Dispatch to display style handler ---
133
134                 CMP     R0,#(%10-%00)/4         ;Is the opening style known?
135                 MOV     R8,PC                   ;Set up return address
136                 ADDCC   PC,PC,R0,LSL #2         ;Call positioning routine
137                 B       %50winUtils_setPosition ;And write values back
138
139                 ; --- Branch table for window positioning ---
140
141 00              MOVS    PC,R8                   ;Do nothing -- leave as is
142                 B       %15winUtils_setPosition ;Centre window on the screen
143                 B       %20winUtils_setPosition ;Centre window over pointer
144                 B       %25winUtils_setPosition ;Set y position as given
145                 B       %30winUtils_setPosition ;Set top left as given
146 10
147                 ; --- Centre a window on the screen ---
148
149 15              BL      screen_getInfo          ;Find the screen information
150                 ADD     R14,R0,#screen_width    ;Point to width/height info
151                 LDMIA   R14,{R2,R3}             ;Load the values out
152                 SUB     R4,R2,R6                ;Centre the window...
153                 MOV     R4,R4,LSR #1            ;... horizontally
154                 SUB     R5,R3,R7                ;Also centre it...
155                 MOV     R5,R5,LSR #1            ;... vertically
156                 MOVS    PC,R8                   ;And return to set the state
157
158                 ; --- Centre a window over the pointer ---
159
160 20              SWI     OS_Mouse                ;Find immediate pointer pos
161                 SUB     R4,R0,R6,LSR #1         ;Centre the x position
162                 SUB     R5,R1,R7,LSR #1         ;And the y position
163                 LDR     R1,[R13,#4]             ;Reload the block pointer
164                 MOVS    PC,R8                   ;And return to caller
165
166                 ; --- Open window at given y position ---
167
168 25              SUB     R5,R2,R7                ;Sort out the y positioning
169                 MOVS    PC,R8                   ;And return to caller
170
171                 ; --- Open window at given position ---
172
173 30              MOV     R4,R2                   ;Set up the left hand side
174                 SUB     R5,R3,R7                ;And set up the *top*
175                 MOVS    PC,R8                   ;Return to main program
176
177                 ; --- Now sort out all the return values ---
178
179 50              ADD     R6,R4,R6                ;Work out window right pos
180                 ADD     R7,R5,R7                ;And the window top position
181                 STMIB   R1,{R4-R7}              ;Save all the values in there
182                 MOV     R14,#-1                 ;Ensure window opens on top
183                 STR     R14,[R1,#28]            ;Save in `behind' field
184                 MOV     R2,R4                   ;Return left side in R2
185                 MOV     R3,R7                   ;And top edge in R3
186                 LDMFD   R13!,{R0,R1,R4-R8,PC}^  ;And return to caller
187
188                 LTORG
189
190 ; --- winUtils_findValid ---
191 ;
192 ; On entry:     R0 == pointer to icon block
193 ;               R1 == character to find in block (not case-sensitive)
194 ;               R2 == old pointer to search from, or 0
195 ;
196 ; On exit:      R1 == character forced to lower case
197 ;               CS if found, and
198 ;                 R2 points to command string
199 ;               else CC and
200 ;                 R2 corrupted
201 ;
202 ; Use:          Tries to find a validation string command in the given
203 ;               icon block.
204
205                 EXPORT  winUtils_findValid
206 winUtils_findValid ROUT
207
208                 BIC     R14,R14,#C_flag         ;Assume we won't find it
209                 STMFD   R13!,{R3,R14}           ;Preserve for later use
210
211                 ; --- Ensure the icon is text and indirected ---
212
213                 LDR     R3,[R0,#16]             ;Get flags word
214                 TST     R3,#1<<23               ;Is it deleted?
215                 MOVEQ   R14,#&100               ;Can't put 101 in one instr
216                 ORREQ   R14,R14,#&01            ;Check indirect and text
217                 ANDEQ   R3,R3,R14               ;Mask the bits off
218                 CMPEQ   R3,R14                  ;Were they both set?
219                 LDMNEFD R13!,{R3,PC}^           ;No -- return huffily
220
221                 ; --- Find the validation string ---
222
223                 LDR     R3,[R0,#24]             ;Get pointer to valid string
224                 CMP     R3,#-1                  ;Is it empty?
225                 LDMEQFD R13!,{R3,PC}^           ;No -- return huffily
226
227                 ; --- Start from the right index ---
228
229                 ORR     R1,R1,#&20              ;Make valid char lower case
230                 CMP     R2,#0                   ;Is it the start?
231                 ADDNE   R2,R2,#1                ;No -- miss out one char
232                 BNE     %02winUtils_findValid   ;And skip this command
233                 MOV     R2,R3                   ;Start at the beginning
234
235                 ; --- Check the first char of a validation string ---
236
237 00              LDRB    R14,[R2],#1             ;Get a byte from string
238                 ORR     R3,R14,#&20             ;Make lower case
239                 CMP     R3,R1                   ;Is it a match?
240                 SUBEQ   R2,R2,#1                ;Point back to character
241                 LDMEQFD R13!,{R3,R14}           ;And return
242                 ORREQS  PC,R14,#C_flag          ;Set C on exit for this
243                 MOV     R3,#0                   ;Not an excaped character
244
245                 ; --- Skip ahead to the next validation string ---
246
247 01              CMP     R14,#' '                ;Is it a control char?
248                 LDMLTFD R13!,{R3,PC}^           ;Yes -- return
249                 CMP     R3,#1                   ;Are we escaping?
250                 MOVEQ   R3,#0                   ;Yes -- done that now
251                 BEQ     %02winUtils_findValid   ;So skip this bit
252                 CMP     R14,#';'                ;Is it a semicolon?
253                 BEQ     %00winUtils_findValid   ;Yes -- try a new command
254                 CMP     R14,#'\'                ;Is it a backslash?
255                 MOVEQ   R3,#1                   ;Yes -- escape next char
256 02              LDRB    R14,[R2],#1             ;Get another character
257                 B       %01winUtils_findValid   ;And try again
258
259                 LTORG
260
261 ; --- winUtils_shaded ---
262 ;
263 ; On entry:     R0 == window handle
264 ;               R1 == icon handle
265 ;
266 ; On exit:      CS if icon is shaded, CC otherwise
267 ;
268 ; Use:          Informs caller whether an icon is shaded in the Sapphire
269 ;               sense (ESG 31 or shaded bit set).
270
271                 EXPORT  winUtils_shaded
272 winUtils_shaded ROUT
273
274                 STMFD   R13!,{R0,R1,R14}        ;Save some registers
275                 SUB     R13,R13,#40             ;Make an icon block
276                 STMIA   R13,{R0,R1}             ;Save icons in the block
277                 MOV     R1,R13                  ;Point to the block
278                 SWI     Wimp_GetIconState       ;Read the icon information
279                 LDR     R14,[R13,#24]           ;Load the icon flags
280                 EOR     R14,R14,#&005F0000      ;Toggle shaded and ESG bits
281                 TST     R14,#&00400000          ;Was the shaded bit set?
282                 TSTNE   R14,#&001F0000          ;No -- test the ESG bits
283                 ADD     R13,R13,#40             ;Restore the stack pointer
284                 LDMFD   R13!,{R0,R1,R14}        ;Unstack loads of registers
285                 ORREQS  PC,R14,#C_flag          ;Set C if icon is shaded
286                 BICNES  PC,R14,#C_flag          ;Clear C if not shaded
287
288                 LTORG
289
290 ;----- That's all, folks ----------------------------------------------------
291
292                 END