chiark / gitweb /
Initial revision
[ssr] / StraySrc / Libraries / Sapphire / dbx / s / fileIcon
1 ;
2 ; dbx.fileIcon.s
3 ;
4 ; Draggable file icons as dbx controls (MDW)
5 ;
6 ; © 1994 Straylight
7 ;
8
9 ;----- Standard header ------------------------------------------------------
10
11                 GET     libs:header
12                 GET     libs:swis
13
14 ;----- External dependencies ------------------------------------------------
15
16                 GET     sapphire:dbox
17                 GET     sapphire:sapphire
18                 GET     sapphire:screen
19                 GET     sapphire:string
20                 GET     sapphire:win
21
22                 GET     sapphire:dbx.dbx
23                 GET     sapphire:dbx._dbxMacs
24
25 ;----- Main code ------------------------------------------------------------
26
27                 AREA    |Sapphire$$Code|,CODE,READONLY
28
29 ; --- fileIcon_sprName ---
30 ;
31 ; On entry:     R0 == filetype
32 ;               R1 == pointer to filename
33 ;
34 ; On exit:      R0 == pointer to sprite name to use
35 ;
36 ; Use:          Works out the sprite name to use for the given filetype and
37 ;               name pair.
38
39                 EXPORT  fileIcon_sprName
40 fileIcon_sprName ROUT
41
42                 STMFD   R13!,{R1-R3,R14}        ;Save some registers
43
44                 ; --- Get some easy cases out the way ---
45
46                 CMP     R0,#&3000               ;Is it untyped?
47                 ADREQ   R0,fi__xxx              ;Yes -- point to the default
48                 BEQ     %90fileIcon_sprName     ;And skip to the end
49                 CMP     R0,#&1000               ;Is it a directory?
50                 ADREQ   R0,fi__dir              ;Point to the sprite name
51                 BEQ     %90fileIcon_sprName     ;And skip to the end
52                 CMP     R0,#&2000               ;Is this an application?
53                 BEQ     %50fileIcon_sprName     ;Yes -- handle that nicely
54
55                 ; --- It's just a simple file ---
56
57                 MOV     R3,R0                   ;Look after the filetype
58                 MOV     R0,R11                  ;Use scratchpad for name
59                 ADR     R1,fi__file             ;Point to sprite name prefix
60                 BL      str_cpy                 ;Copy the string over
61                 MOV     R2,#2                   ;Three characters to write
62
63                 ; --- Write the hex number on the end ---
64
65 00              AND     R14,R3,#&F              ;Get the bottom nibble
66                 MOV     R3,R3,LSR #4            ;And shift down the type
67                 ADD     R14,R14,#'0'            ;Convert to a digit
68                 CMP     R14,#'9'                ;Is it a letter, really?
69                 ADDGT   R14,R14,#'a'-'9'-1      ;Yes -- make it so
70                 STRB    R14,[R0,R2]             ;Store the letter then
71                 SUBS    R2,R2,#1                ;Do the next character
72                 BGE     %00fileIcon_sprName     ;If more -- do them
73                 MOV     R2,#0                   ;A NULL byte
74                 STRB    R2,[R0,#3]              ;Terminate the string
75                 MOV     R0,R11                  ;Point to the string
76                 BL      fi__sExist              ;Does it exist?
77                 ADRCC   R0,fi__xxx              ;No -- use default sprite
78                 B       %90fileIcon_sprName     ;And return to caller
79
80                 ; --- The thingy is an application ---
81
82 50              MOV     R0,R1                   ;Point to start of filename
83 51              LDRB    R14,[R1],#1             ;Get a character
84                 CMP     R14,#'.'                ;Is it a dot?
85                 MOVEQ   R0,R1                   ;Yes -- remember position
86                 CMP     R14,#32                 ;Is it a control char?
87                 BGE     %51fileIcon_sprName     ;No -- keep looping
88                 BL      fi__sExist              ;Does it exist?
89                 ADRCC   R0,fi__app              ;No -- use default sprite
90
91 90              LDMFD   R13!,{R1-R3,PC}^        ;Return to caller
92
93 fi__xxx         DCB     "file_xxx",0
94 fi__app         DCB     "application",0
95 fi__file        DCB     "file_",0
96 fi__dir         DCB     "directory",0
97
98                 LTORG
99
100 ; --- fi__sExist ---
101 ;
102 ; On entry:     R0 == pointer to sprite name
103 ;
104 ; On exit:      CS if the sprite exists, CC if it doesn't
105 ;
106 ; Use:          Informs you whether a sprite exists
107
108 fi__sExist      ROUT
109
110                 STMFD   R13!,{R0-R6,R14}        ;Save some registers
111                 MOV     R2,R0                   ;Point to the sprite name
112                 MOV     R0,#40                  ;Read sprite information
113                 SWI     XWimp_SpriteOp          ;Get the information
114                 LDMFD   R13!,{R0-R6,R14}        ;Restore registers
115                 ORRVCS  PC,R14,#C_flag          ;If it exists, set C
116                 BICVSS  PC,R14,#C_flag          ;Otherwise clear C
117
118                 LTORG
119
120 ; --- fileIcon ---
121 ;
122 ; Control data: +0
123 ;
124 ; Workspace:    +0 == filetype of object to display
125 ;               +4 == address of filename
126 ;               +8
127 ;
128 ; Flags:        --
129 ;
130 ; Use:          Control which displays a filetype icon, and allows it to
131 ;               be dragged.
132
133                 EXPORT  fileIcon
134 fileIcon        ROUT
135
136                 DBXWS   fi__wSpace
137                 DCD     dbxMask_click+dbxMask_redraw
138
139                 CMP     R0,#dbxEvent_click      ;Is it a click event?
140                 BEQ     %50fileIcon             ;Yes -- deal with it
141
142                 ; --- We must have a redraw event then ---
143
144                 STMFD   R13!,{R0-R3,R14}        ;Stack some registers
145
146                 ; --- Find out if it should be invisible ---
147
148                 LDMIA   R12,{R0,R14}            ;Get vanished dbox,icon
149                 CMP     R0,R10                  ;Check dialogues match
150                 CMPEQ   R1,R14                  ;And the icon handles
151                 LDMEQFD R13!,{R0-R3,PC}^        ;Yes -- leave icon blank
152
153                 ; --- Just fill in the sprite ---
154
155                 SUB     R13,R13,#40             ;Get me a block, please
156                 MOV     R0,R10                  ;The dialogue box
157                 BL      dbox_window             ;Get the window handle
158                 STMIA   R13,{R0,R1}             ;Store window, icon handle
159                 MOV     R1,R13                  ;Point to the block
160                 SWI     Wimp_GetIconState       ;Get the icon state
161                 LDMIA   R8,{R0,R1}              ;Load filetype/name
162                 BL      fileIcon_sprName        ;Get the sprite name
163                 MOV     R1,R0                   ;Put spritename in R1
164                 MOV     R0,#&1A                 ;The icon flags
165                 ORR     R0,R0,#&100             ;...continued
166                 LDR     R14,[R13,#24]           ;Load the icon flags word
167                 EOR     R14,R14,#&005F0000      ;Toggle ESG and shaded bits
168                 TST     R14,#&00400000          ;Is the shaded bit set?
169                 TSTNE   R14,#&001F0000          ;No -- check the ESG then
170                 ORREQ   R0,R0,#&00400000        ;Yes -- set the shaded bit
171                 MOV     R2,#1                   ;Use Wimp sprite area
172                 MOV     R3,#12                  ;Size of indirected buffer
173                 ADD     R14,R13,#24             ;Point into the block
174                 STMIA   R14,{R0-R3}             ;Store into the block
175                 ADD     R1,R13,#8               ;For use with PlotIcon
176                 SWI     Wimp_PlotIcon           ;Plot the icon
177                 ADD     R13,R13,#40             ;Reclaim the block
178                 LDMFD   R13!,{R0-R3,PC}^        ;Return to the caller
179
180                 ; --- We have been given a click event ---
181
182 50              TST     R2,#&F0                 ;Was it a drag event?
183                 MOVEQS  PC,R14                  ;No -- return
184
185                 STMFD   R13!,{R0-R7,R14}        ;Save some registers away
186
187                 ; --- Find out if we can use DragAYum ---
188
189                 MOV     R0,#161                 ;Read CMOS locations
190                 MOV     R1,#28                  ;Various strange status flags
191                 SWI     OS_Byte                 ;Get the CMOS value there
192                 TST     R2,#2                   ;Is the bit set?
193                 BEQ     %60fileIcon             ;No -- use normal drag box
194
195                 ; --- Set things up for DragALuvvley ---
196
197                 MOV     R0,R10                  ;Get the dialogue box handle
198                 LDR     R1,[R13,#4]             ;Get the icon handle to use
199                 BL      dbx_controlBBox         ;Get the icon bounding box
200                 BL      screen_getInfo          ;Get some screen information
201                 ADD     R0,R0,#screen_dx        ;Point to the pixel sizes
202                 LDMIA   R0,{R0,R1}              ;Get the pixel sizes
203                 ADD     R4,R4,R0                ;Make the coordinates...
204                 ADD     R5,R5,R1                ;... inclusive again
205                 STMFD   R13!,{R2-R5}            ;Store these on the stack
206                 LDMIA   R8,{R0,R1}              ;Get the filetype and name
207                 BL      fileIcon_sprName        ;Convert into a sprite name
208                 MOV     R2,R0                   ;Point to it in R2
209                 MOV     R3,R13                  ;Point to my coords block
210                 MOV     R1,#1                   ;Sprite area containing icon
211                 MOV     R0,#&C5                 ;Various gadgetty flags
212                 SWI     XDragASprite_Start      ;Start the drag up
213                 ADD     R13,R13,#16             ;Clear up the coords block
214                 BVS     %60fileIcon             ;If it failed, use normal box
215
216                 ; --- Make the file icon `vanish' ---
217
218                 MOV     R0,R10                  ;Get the dialogue handle
219                 LDR     R1,[R13,#4]             ;Get the icon handle too
220                 STMIA   R12,{R0,R1}             ;Save them as having vanished
221                 BL      dbox_window             ;Get the dialogue handle
222                 MOV     R2,#0                   ;Don't fiddle the flags
223                 MOV     R3,#0                   ;Really don't do this
224                 STMFD   R13!,{R0-R3}            ;Save them on the stack
225                 MOV     R1,R13                  ;Point to the block
226                 SWI     Wimp_SetIconState       ;Prod icon into redrawing
227                 ADD     R13,R13,#16             ;Recover the stack space
228                 B       %80fileIcon             ;Skip to setting up unknowns
229
230                 ; --- Use an old-fashioned type drag box ---
231
232 60              SUB     R13,R13,#56             ;Make way for a drag block
233                 MOV     R0,R10                  ;Get the dialogue handle
234                 LDR     R1,[R13,#60]            ;Get the icon handle to use
235                 BL      dbx_controlBBox         ;Get the icon bounding box
236                 BL      screen_getInfo          ;Get some screen information
237                 ADD     R14,R0,#screen_width    ;Point to screen dimensions
238                 LDMIA   R14,{R6,R7}             ;Load them out of the block
239
240                 ; --- Convert the coordinates ---
241
242                 LDMIA   R0,{R0,R1}              ;Get the eigen factors
243                 MOV     R14,#1                  ;For shifting about a bit
244                 MOV     R0,R14,LSL R0           ;Get the x pixel size
245                 MOV     R1,R14,LSL R1           ;And the y pixel size
246                 ADD     R4,R4,R0                ;Convert back to exclusive...
247                 ADD     R5,R5,R1                ;... coordinates (grr...)
248
249                 ; --- Now build the main drag block ---
250
251                 MOV     R0,R10                  ;Get the dialogue handle
252                 BL      dbox_window             ;Convert to a window handle
253                 MOV     R1,#5                   ;Fixed-size drag box
254                 MOV     R14,R13                 ;Point to the block
255                 STMIA   R14!,{R0-R5}            ;Save window, type and box
256                 MOV     R4,#0                   ;Set boundaries to the...
257                 MOV     R5,#0                   ;... whole screen
258                 STMIA   R14!,{R4-R7}            ;Save the boundaries too
259                 MOV     R1,R13                  ;Point to the drag block
260                 SWI     Wimp_DragBox            ;Start up the drag
261                 ADD     R13,R13,#56             ;Restore the stack again
262
263                 ; --- Set up the unknown handler and return ---
264
265 80              ADR     R0,fi__unknown          ;Point to my handler proc
266                 LDR     R1,[R13,#4]             ;Pass icon handle in R4
267                                                 ;See, it does have use!
268                 MOV     R2,R10                  ;Pass dialogue handle in R10
269                 MOV     R3,R12                  ;And my workspace in R12
270                 BL      win_unknownHandler      ;Register the magic handler
271                 LDMFD   R13!,{R0-R7,R14}        ;Unstack a load of registers
272                 ORRS    PC,R14,#C_flag          ;Return and claim the click
273
274 fi__wSpace      DCD     0
275
276                 LTORG
277
278 ; --- fi__unknown ---
279 ;
280 ; On entry:     R0 == an event code
281 ;               R1 == pointer to any associated event data
282 ;
283 ; On exit:      CS if I handled it
284 ;
285 ; Use:          Stops the drag and sends a drag finished event to the
286 ;               dialogue box.
287
288 fi__unknown     ROUT
289
290                 CMP     R0,#7                   ;Is this a drag finished?
291                 MOVNES  PC,R14                  ;No -- not interested then
292
293                 ; --- Send the mouse position to the dialogue ---
294
295                 STMFD   R13!,{R0-R3,R14}        ;Save some registers away
296                 SWI     XDragASprite_Stop       ;Stop thy silly dragging
297                 SUB     R13,R13,#24             ;Make some space
298                 MOV     R1,R13                  ;Point to the block created
299                 SWI     Wimp_GetPointerInfo     ;Get the current position
300                 MOV     R0,#fIcon_event         ;Get the event code
301                 MOV     R1,R4                   ;Send to the correct icon
302                 ADD     R14,R13,#12             ;Get window and icon handles
303                 LDMIA   R14,{R2,R3}             ;Load them from the block
304                 ADD     R13,R13,#24             ;Restore the stack pointer
305                 BL      dbx_sendEvent           ;Deliver the event then
306
307                 ; --- Now disable the unknown handler ---
308
309                 ADR     R0,fi__unknown          ;Point to my handler proc
310                 MOV     R1,R4                   ;Pass icon handle in R4
311                 MOV     R2,R10                  ;Pass dialogue handle in R10
312                 MOV     R3,R12                  ;And my workspace in R12
313                 BL      win_removeUnknownHandler ;Deregister the handler
314                 LDMFD   R13!,{R0-R3,R14}        ;Unstack a load of registers
315                 ORRS    PC,R14,#C_flag          ;Return and claim the click
316
317                 LTORG
318
319 ; --- fileIcon_reAppear ---
320 ;
321 ; On entry:     --
322 ;
323 ; On exit:      --
324 ;
325 ; Use:          Makes the currently vanished file icon reappear.
326
327                 EXPORT  fileIcon_reAppear
328 fileIcon_reAppear
329
330                 STMFD   R13!,{R0-R3,R12,R14}    ;Save some registers
331                 WSPACE  fi__wSpace              ;Locate my workspace
332                 LDMIA   R12,{R0,R1}             ;Get the vanished dbox/icon
333                 CMP     R0,#0                   ;Is the dialogue null?
334                 LDMEQFD R13!,{R0-R3,R12,PC}^    ;Yes -- ignore this call
335                 MOV     R14,#0                  ;Zero out the vanished dbox
336                 STR     R14,fi__dbox            ;Save it over the old one
337                 BL      dbox_window             ;Get the dialogue handle
338                 MOV     R2,#0                   ;Don't fiddle the flags
339                 MOV     R3,#0                   ;Really don't do this
340                 STMFD   R13!,{R0-R3}            ;Save them on the stack
341                 MOV     R1,R13                  ;Point to the block
342                 SWI     Wimp_SetIconState       ;Prod icon into redrawing
343                 ADD     R13,R13,#16             ;Recover the stack space
344                 LDMFD   R13!,{R0-R3,R12,PC}^    ;Return to caller
345
346                 LTORG
347
348 ; --- fileIcon_closed ---
349 ;
350 ; On entry:     R0 == dialogue box handle
351 ;
352 ; On exit:      --
353 ;
354 ; Use:          Informs fileIcon that the specified dialogue box has closed.
355
356                 EXPORT  fileIcon_closed
357 fileIcon_closed ROUT
358
359                 STMFD   R13!,{R12,R14}          ;Save some registers
360                 WSPACE  fi__wSpace              ;Find my workspace pointer
361                 LDR     R14,fi__dbox            ;Load the current dbox handle
362                 CMP     R14,R0                  ;Is it a match?
363                 MOVEQ   R14,#0                  ;Yes -- get a dummy handle
364                 STREQ   R14,fi__dbox            ;And store in its place
365                 LDMFD   R13!,{R12,PC}^          ;Return to caller
366
367                 LTORG
368
369 fIcon_event     EQU     &80000003
370
371 ;----- Workspace ------------------------------------------------------------
372
373                 ^       0,R12
374 fi__wStart      #       0
375
376 fi__dbox        #       4                       ;Dbox with vanished icon
377 fi__icon        #       4                       ;The vanished icon
378
379 fi__wSize       EQU     {VAR}-fi__wStart
380
381                 AREA    |Sapphire$$LibData|,CODE,READONLY
382
383                 DCD     fi__wSize
384                 DCD     fi__wSpace
385                 DCD     16
386                 DCD     0
387
388 ;----- That's all, folks ----------------------------------------------------
389
390                 END