chiark / gitweb /
Create readable text `.bas' for each tokenized BASIC `,ffb' file.
[ssr] / StraySrc / Libraries / Sapphire / dbx / s / colourPot
1 ;
2 ; colourPot.s
3 ;
4 ; dbx control for selecting Wimp colours (MDW)
5 ;
6 ; © 1995 Straylight
7 ;
8
9 ;----- Standard header ------------------------------------------------------
10
11                 GET     libs:header
12                 GET     libs:swis
13
14                 GET     libs:stream
15
16 ;----- External dependencies ------------------------------------------------
17
18                 GET     sapphire:colourBox
19                 GET     sapphire:dbox
20                 GET     sapphire:errorBox
21                 GET     sapphire:screen
22                 GET     sapphire:winUtils
23
24                 GET     sapphire:dbx.dbx
25                 GET     sapphire:dbx._dbxMacs
26
27 ;----- Main code ------------------------------------------------------------
28
29                 AREA    |Sapphire$$Code|,CODE,READONLY
30
31 ; --- colourPot ---
32 ;
33 ; Control data: +0 == null terminated title string, or empty for default
34 ;               +n
35 ;
36 ; Workspace:    +0 == current colour selected
37 ;               +1
38 ;
39 ; Flags:        bit 8 == allow transparent
40 ;
41 ; Use:          Provides a `colour button' which allows the user to choose
42 ;               a Wimp colour.
43
44                 EXPORT  colourPot
45 colourPot       ROUT
46
47                 DBXWS   cp__wSpace
48                 DCD     dbxMask_click + dbxMask_redraw
49
50                 CMP     R0,#dbxEvent_click      ;Is this a click event?
51                 BEQ     %50colourPot            ;Yes -- deal with that then
52
53                 ; --- Redraw a colour pot ---
54
55                 STMFD   R13!,{R14}              ;Save a register
56                 LDRB    R14,[R8,#0]             ;Load current colour
57                 CMP     R14,#255                ;Is it transparent?
58                 BEQ     %20colourPot            ;Yes -- deal with that then
59
60                 ; --- Handle shading of icons ---
61                 ;
62                 ; We use the Wimp's shading algorithm from RISC OS 3.5 for
63                 ; this -- clear a bunch of bits!  This is extremely odd,
64                 ; since it doesn't take the lightness/darkness of the colour
65                 ; into account, but it does appear to be standard...
66
67                 STMFD   R13!,{R0-R3}            ;Save more registers
68                 ORR     R2,R14,#&80             ;Set the `background' bit
69                 MOV     R0,R10                  ;Get the dialogue handle
70                 BL      dbox_window             ;Get the window handle
71                 BL      winUtils_shaded         ;Is the icon shaded?
72                 ANDCS   R2,R2,#&82              ;Yes -- oddly clear bits
73                 MOV     R0,R2                   ;Get colour in R0
74                 SWI     Wimp_SetColour          ;Set the colour up
75                 SWI     OS_WriteI+16            ;Clear graphics window
76                 LDMFD   R13!,{R0-R3,PC}^        ;And return to caller
77
78                 ; --- Fill transparent with hatching ---
79
80 20colourPot     STMFD   R13!,{R0-R7}            ;Save lots of registers
81                 MOV     R6,R2                   ;Look after left x coord
82                 MOV     R7,R3                   ;And the bottom y coord too
83
84                 ; --- Work out a colour translation table ---
85                 ;
86                 ; We will shade the pattern sprite if we need to, by using
87                 ; an alternate palette table.
88
89                 MOV     R0,R10                  ;Get the dbox handle
90                 BL      dbox_window             ;Translate to window handle
91                 BL      winUtils_shaded         ;Is the icon shaded?
92                 MOV     R0,#0                   ;My sprite is mode 0
93                 ADRCC   R1,cp__hatchPal         ;Point to the palette
94                 ADRCS   R1,cp__shadePal         ;Whichever is appropriate
95                 MOV     R2,#-1                  ;Create for current mode
96                 MOV     R3,#-1                  ;And the current palette
97                 MOV     R4,R11                  ;Build it in the scratchpad
98                 SWI     ColourTrans_SelectTable ;Build the translate table
99
100                 ; --- Now set up a zoom block ---
101
102                 BL      screen_getInfo          ;Read current screen info
103                 ADD     R14,R0,#screen_dx       ;Find current pixel sizes
104                 LDMIA   R14,{R2,R3}             ;Load these out as divisors
105                 MOV     R0,#2                   ;Sprite x width is 2
106                 MOV     R1,#4                   ;And the y height is 4
107                 STMFD   R13!,{R0-R3}            ;Save these on the stack
108
109                 ; --- Finally, plot the sprite ---
110
111                 MOV     R0,#52                  ;Plot sprite scaled
112                 ORR     R0,R0,#(1<<9)           ;We have a sprite pointer
113                 MOV     R1,#&1000               ;Use a bogus sprite area
114                 ADR     R2,cp__hatchSprite      ;Point to the sprite data
115                 MOV     R3,R6                   ;Recover the x coordinate
116                 MOV     R4,R7                   ;And the y coordinate
117                 MOV     R5,#0                   ;Just plot the thing
118                 MOV     R6,R13                  ;Point to zoom block
119                 MOV     R7,R11                  ;And to the translate table
120                 SWI     OS_SpriteOp             ;Plot the sprite
121                 ADD     R13,R13,#16             ;Restore the stack pointer
122                 LDMFD   R13!,{R0-R7,PC}^        ;And return to caller
123
124                 ; --- Sprite definition ---
125                 ;
126                 ; Here for compactness.
127
128 cp__hatchPal    DCD     &FFFFFF00
129                 DCD     &00000000
130
131 cp__shadePal    DCD     &FFFFFF00
132                 DCD     &BABABA00
133
134 cp__hatchSprite DCD     44+9*4
135                 DCB     "hatchptn",0,0,0,0
136                 DCD     0
137                 DCD     8
138                 DCD     0
139                 DCD     17
140                 DCD     44
141                 DCD     44
142                 DCD     0
143
144                 DCD     &00030303
145                 DCD     &0000cccc
146                 DCD     &00003030
147                 DCD     &0000cccc
148                 DCD     &00030303
149                 DCD     &0000cccc
150                 DCD     &00003030
151                 DCD     &0000cccc
152                 DCD     &00030303
153
154                 ; --- Handle a mouse click on the button ---
155
156 50colourPot     TST     R2,#2                   ;Is this a menu click?
157                 BNE     %70colourPot            ;Yes -- bring up the dialogue
158                 TST     R2,#5                   ;Make sure it's not a drag
159                 MOVEQS  PC,R14                  ;If it is, ignore it
160
161                 ; --- Handle a SELECT or ADJUST click ---
162
163                 STMFD   R13!,{R0,R14}           ;Save some registers
164                 LDRB    R0,[R8,#0]              ;Load the current colour
165                 TST     R0,#&F0                 ;Any top bits set?
166                 MOVNE   R0,#0                   ;Yes -- force a wraparound
167                 BNE     %f00                    ;And skip on
168                 TST     R2,#1                   ;Is this an adjust click?
169                 RSBNE   R0,R0,#15               ;Invert the colour if reqd
170                 MOV     R0,R0,LSL #28           ;Shift into top nibble
171                 ADDS    R0,R0,#(1<<28)          ;Increment the colour
172                 LDREQ   R14,[R9,#-12]           ;Load the flags word
173                 EOREQ   R14,R14,#(1<<8)         ;Complement trans bit
174                 TSTEQ   R14,#(1<<8)             ;Are we allowing transparent?
175                 MOVEQ   R0,#255                 ;Yes -- do that then
176                 MOVNE   R0,R0,LSR #28           ;Otherwise shift down again
177 00              TSTNE   R2,#1                   ;Was it an adjust click?
178                 RSBNE   R0,R0,#15               ;Yes -- uninvert the colour
179                 STRB    R0,[R8,#0]              ;Save the colour back again
180                 BL      cp__update              ;We've updated the colour
181                 LDMFD   R13!,{R0,PC}^           ;Return to caller
182
183                 ; --- Handle MENU click --
184
185 70colourPot     STMFD   R13!,{R0-R4,R14}        ;Save some registers
186                 STMIA   R12,{R1,R8,R10}         ;Save useful information
187                 LDRB    R0,[R9,#0]              ;Load first byte of title
188                 CMP     R0,#&20                 ;Is this string empty?
189                 ADRCC   R0,cp__title            ;Yes -- use default string
190                 MOVCS   R0,R9                   ;No -- point to user's title
191                 LDRB    R1,[R8,#0]              ;Find the current colour
192                 LDR     R14,[R9,#-12]           ;Load the control's flags
193                 TST     R14,#(1<<8)             ;Does he allow transparent?
194                 ORRNE   R1,R1,#(1<<8)           ;Yes -- then so shall we
195                 ADR     R2,cp__handler          ;Point to my handler
196                 MOV     R3,#0                   ;Don't care about R10
197                 MOV     R4,R12                  ;Pass workspace in R12
198                 BL      colourBox               ;Try to display the dialogue
199                 MOVVS   R1,#1                   ;If it failed, display error
200                 BLVS    errorBox                ;In a one-button errorbox
201                 LDMFD   R13!,{R0-R4,PC}^        ;Return to caller
202
203 cp__title       DCB     "cpTITLE",0
204
205                 LTORG
206
207 ; --- cp__handler ---
208 ;
209 ; On entry:     R0 == event code
210 ;               R1 == colour chosen
211 ;
212 ; On exit:      --
213 ;
214 ; Use:          Handles events for our colour box.
215
216 cp__handler     ROUT
217
218                 CMP     R0,#cbEvent_select      ;User made a selection?
219                 MOVNES  PC,R14                  ;No -- don't care
220                 STMFD   R13!,{R1,R8,R10,R14}    ;Save some registers
221                 MOV     R14,R1                  ;Look after the colour
222                 LDMIA   R12,{R1,R8,R10}         ;Load icon, data, and dbox
223                 STRB    R14,[R8,#0]             ;Save the new colour
224                 BL      cp__update              ;Tell client we've updated
225                 LDMFD   R13!,{R1,R8,R10,PC}^    ;And return to caller
226
227                 LTORG
228
229 ; --- cp__update ---
230 ;
231 ; On entry:     R1 == icon handle
232 ;               R8 == address of control data
233 ;               R10 == dialogue box handle
234 ;
235 ; On exit:      --
236 ;
237 ; Use:          Updates the dialogue box and sends our owner an event.
238
239 cp__update      ROUT
240
241                 STMFD   R13!,{R0,R2,R14}        ;Save some registers
242                 MOV     R0,R10                  ;Get the dialogue handle
243                 BL      dbx_update              ;Redraw the control
244                 MOV     R0,#colourPot_event     ;Get the event code
245                 LDRB    R2,[R8,#0]              ;Load the current colour
246                 BL      dbx_sendEvent           ;Send the event off
247                 LDMFD   R13!,{R0,R2,PC}^        ;And return to caller
248
249                 LTORG
250
251 cp__wSpace      DCD     0
252
253 ;----- Magic constants ------------------------------------------------------
254
255 colourPot_event EQU     &80000006
256
257 ;----- Workspace ------------------------------------------------------------
258
259                 ^       0,R12
260 cp__wStart      #       0
261
262 cp__icon        #       4                       ;Current control's icon
263 cp__addr        #       4                       ;Address of colour byte
264 cp__dbox        #       4                       ;Current control's dialogue
265
266 cp__wSize       EQU     {VAR}-cp__wStart
267
268                 AREA    |Sapphire$$LibData|,CODE,READONLY
269
270                 DCD     cp__wSize
271                 DCD     cp__wSpace
272                 DCD     0
273                 DCD     0
274
275 ;----- That's all, folks ----------------------------------------------------
276
277                 END