4 ; The Colour Selector kernel
9 ;----- Standard header ------------------------------------------------------
14 ;----- External dependencies ------------------------------------------------
25 GET sapphire:dbx.stringSet
28 GET sapphire:_cs.models
30 ;----- Main code ------------------------------------------------------------
32 AREA |Sapphire$$Code|,CODE,READONLY
36 ; On entry: R0 == address of a colour block
37 ; R1 == pointer to routine to call when done
38 ; R2 == R10 to call routine with
39 ; R3 == R12 to call routine with
41 ; On exit: May return error
43 ; Use: Displays a colour selector dialogue box. It allows the user
44 ; to edit a colour (understatement....)
49 BIC R14,R14,#V_flag ;Clear the V flag
50 STMFD R13!,{R0-R4,R10,R14} ;Save a load of registers
52 ; --- Try to create a workspace block ---
54 MOV R0,#cs__dSize ;Get my data size
55 BL alloc ;Try to allocate the memory
56 BLCS alloc_error ;If it failed, get a message
57 BCS %99colSelect ;And tidy up as we go
58 MOV R10,R0 ;Look after this block
60 ; --- Now create a dialogue box ---
62 ADR R0,cs__dbName ;Point to the dialogue name
63 BL dbox_create ;Create the dialogue
64 BVS %98colSelect ;Tidy up if it failed
65 STR R0,cs__frameDb ;Save the dialogue handle
66 ADR R1,cs__handler ;The event handler
67 MOV R2,R10 ;Pass this R10 value
68 MOV R3,R12 ;And this R12 value
69 BL dbox_eventHandler ;Set up the handler
70 ADR R1,cs__dbxBlock ;Point to dbx information
71 BL dbx_declare ;Declare the block
73 ; --- Save the caller's information ---
75 LDR R0,[R13,#0] ;Load his colour's address
76 LDMIA R0,{R1-R3} ;Load the colour arguments
77 ADR R14,cs__address ;Point into the data block
78 STMIA R14,{R0-R3} ;And save all of that stuff
80 ; --- Set up the workspace ---
82 MOV R14,#3 ;Start on low resolution
83 STR R14,cs__resolution ;Save it in the workspace
85 ; --- Set up the initial model ---
87 BL cs__initModel ;Get a model index
88 BVS %97colSelect ;Clean up on an error
89 MOV R4,R2 ;Keep the model number
90 STR R0,cs__modelDb ;Save model's dialogue box
91 BL dbox_window ;Get the window handle
92 MOV R3,R0 ;Put model's db handle in R3
93 LDR R0,cs__frameDb ;Get frame db handle
94 MOV R1,#dbOpen_persist+dbOpen_current
95 BL dbox_open ;Open the dialogue box
96 MOV R1,#csIcon__rgb ;The first model icon number
97 ADD R1,R1,R2 ;Get the correct icon number
98 MOV R2,#1 ;Turn the icon on
99 BL dbox_select ;Select the icon
100 MOV R2,R3 ;Pane window handle
101 BL dbox_window ;Get the window handle
102 MOV R1,#csIcon__models ;The icon handle
103 BL pane_add ;Add the pane
104 BL pane_open ;Open the pane
105 BL cs__setCaret ;And give it the focus
106 95colSelect LDMFD R13!,{R0-R4,R10,PC}^ ;Return to caller
108 97colSelect MOV R4,R0 ;Preserve R0
109 LDR R0,cs__frameDb ;Get the dialogue box handle
110 BL dbox_destroy ;Destroy the dialogue box
111 MOV R0,R4 ;Get R0 back
112 98colSelect MOV R4,R0 ;Preserve R0
113 MOV R0,R10 ;Point to allocated memory
114 BL free ;Free it nicely
115 MOV R0,R4 ;Get R0 back
116 99colSelect ADD R13,R13,#4 ;Don't load R0
117 LDMFD R13!,{R1-R4,R10,R14} ;Load registers
118 ORRS PC,R14,#V_flag ;Return with error
122 cs__dbName DCB "colSelect",0
124 cs__dbxBlock CONTROL csIcon__colour,colButton,R10,0,:INDEX: cs__colour
126 STRSET csIcon__resDisp,R10,:INDEX: cs__resolution, cs__resMenu,cs__resStrings,csIcon__resDisp
127 STRSET csIcon__resMenu,R10,:INDEX: cs__resolution, cs__resMenu,cs__resStrings,csIcon__resDisp
130 cs__resMenu MENU "csRESMT"
131 ITEM "csRESVH:Very high"
141 cs__resStrings DCB "csRESVH:Very high",0
143 DCB "csRESM:Medium",0
146 ; --- cs__initModel ---
148 ; On entry: R2 == colour model number, or 0
150 ; On exit: R0 == dialogue box created by colour model, or error
151 ; R2 == preserved, or index of RGB model
153 ; Use: Initialises a colour model dialogue box.
157 CMP R2,#cs__noModels ;Is the model in range?
158 MOVHS R2,#cMod_rgb ;No -- use RGB then
159 ADD PC,PC,R2,LSL #2 ;Call the function
162 00cs__initModel B rgb_open
166 cs__noModels EQU (%10-%00)/4
168 ; --- cs__setCaret ---
174 ; Use: Sets the caret in the current colour select pane window.
178 STMFD R13!,{R0-R5,R14} ;Save some registers
179 LDR R0,cs__modelDb ;Get the model dialogue
180 BL dbox_window ;And find its window handle
181 MOV R1,#-1 ;In no particular icon
182 MOV R2,#&ff000000 ;Quite a long way away
184 MOV R3,#0 ;Doesn't really matter
185 MOV R4,#&02000000 ;Hide caret, make it small
186 MOV R5,#-1 ;No index into icon, please
187 SWI Wimp_SetCaretPosition ;Set the caret's position
188 LDMFD R13!,{R0-R5,PC}^ ;Return to caller
192 ; --- cs__handler ---
194 ; On entry: R0 == dialogue box event code
195 ; R1-R9 == depend on the event
196 ; R10 == colour selector data
197 ; R12 == nothing much, actually -- corrupted on exit
201 ; Use: Handles events for the main dialogue frame
205 CMP R0,#stringSet_event ;Is this a string set event?
206 BEQ cs__resMenuClk ;Yes -- handle that
208 CMP R0,#dbEvent_OK ;Is it an OK event?
209 CMPNE R0,#csIcon__ok ;Or a click on OK?
210 BEQ cs__ok ;Yes -- handle it then
212 CMP R0,#dbEvent_help ;Does someone want help?
213 BEQ cs__getHelp ;Yes -- deal with that too
215 SUB R12,R0,#csIcon__rgb ;Was it a model icon?
216 CMP R12,#cs__noModels
217 BLO cs__changeModel ;Yes -- deal with it
221 ; --- Handle an OK click/keypress ---
225 STMFD R13!,{R0-R5,R14} ;Save some registers
226 MOV R5,R1 ;Remember mouse button state
227 MOV R0,R9 ;Get my dialogue handle
228 MOV R1,#csIcon__ok ;And the OK button
229 BL dbox_slab ;Press it in nicely
231 ; --- Find the actual colour he chose ---
233 BL dbox_unslab ;Unslab the button
234 LDMFD R13!,{R0-R5,PC}^ ;And return to caller
238 ; --- Give a help message if required ---
240 cs__getHelp B dbox_help ;Just let dbox do it all!
242 ; --- Handle the resolution menu button ---
246 CMP R1,#csIcon__resDisp ;Is this the resolution one?
247 MOVNES PC,R14 ;No -- ignore it then
249 STMFD R13!,{R0,R10,R14} ;Save some registers
250 LDR R10,cs__modelDb ;Get the model's handle too
251 MOV R0,#csEvent__newRes ;The resolution's changed
252 BL dbx_sendEvent ;Send the event out
253 LDMFD R13!,{R0,R10,PC}^ ;And return to caller
257 ; --- Handle a model selection ---
261 STMFD R13!,{R0-R3,R14} ;Stack some registers
262 LDR R1,cs__colour+col_model ;Load the existing model
263 CMP R1,R12 ;Is it the same?
264 LDMEQFD R13!,{R0-R3,PC}^ ;Yes -- return
266 ; --- Tell old model to update colour ---
268 STMFD R13!,{R10} ;Save my instance pointer
269 LDR R10,cs__modelDb ;Get the current panel dbox
270 MOV R0,#csEvent__read ;Tell it to read its settings
271 BL dbx_sendEvent ;Send it the event
272 LDMFD R13!,{R10} ;Restore the instance pointer
274 ; --- First try to get a new model dialogue ---
276 MOV R2,R12 ;Get the new colour model
277 BL cs__initModel ;Try to initialise it nicely
278 BVS %90cs__changeModel ;If it failed, report error
280 ; --- Now remove the old one ---
282 STMFD R13!,{R0,R10} ;Save some important regs
283 LDR R10,cs__modelDb ;Get the current panel dbox
284 MOV R0,R10 ;Get it in R0
285 BL dbox_window ;Find its window handle
286 MOV R3,R0 ;Keep this value nicely
287 SUB R13,R13,#24 ;Space for a caret block
288 MOV R1,R13 ;Point to the caret block
289 SWI Wimp_GetCaretPosition ;Find the caret nicely
290 LDR R0,[R13,#0] ;Load the focus window handle
291 CMP R0,R3 ;Is it the panel?
292 MOVNE R3,#0 ;No -- clear the value then
293 ADD R13,R13,#24 ;Restore the stack pointer
294 MOV R0,#csEvent__close ;Send a close event
295 BL dbx_sendEvent ;Send the event
296 LDMFD R13!,{R0,R10} ;Restore the registers again
298 ; --- Set up the new panel nicely ---
300 STR R0,cs__modelDb ;Store the new db handle
301 STR R2,cs__colour+col_model ;And the new model type
302 BL dbox_window ;Get the new window handle
303 MOV R2,R0 ;This is the new pane
304 LDR R0,cs__frameDb ;Get the main dialogue box
305 BL dbox_window ;And get its window handle
306 MOV R1,#csIcon__models ;The main icon thingy
307 BL pane_swap ;Swap the pane over
308 CMP R3,#0 ;Was the caret in the panel
309 BLNE cs__setCaret ;Yes -- put it in the new one
310 LDMFD R13!,{R0-R3,PC}^ ;Return to caller
312 90 MOV R1,#1 ;Only an OK button please
313 BL errorBox ;Call error box
314 LDMFD R13!,{R0-R3,R14} ;Return to caller
315 ORRS PC,R14,#C_flag ;Don't change the radio state
319 ; --- cs_passBack ---
321 ; On entry: R0-R7 == dialogue box event information
322 ; R10 == pointer to colour selector instance
326 ; Use: Passes an event back to the main colour selector frame dbox.
331 STMFD R13!,{R10,R14} ;Save some registers
332 LDR R10,cs__frameDb ;Get the dialogue handle
333 BL dbx_sendEvent ;Pass the event on
334 LDMFD R13!,{R10,PC}^ ;And return to caller
338 ; --- cs_colChange ---
340 ; On entry: R10 == currently selected dialogue box
344 ; Use: Updates the colour selector's colour display.
349 STMFD R13!,{R0,R1,R14} ;Save some registers
350 LDR R0,cs__frameDb ;Load the frame handle
351 MOV R1,#csIcon__colour ;Get the colour button icon
352 BL dbx_update ;Redraw it nicely
353 LDMFD R13!,{R0,R1,PC}^ ;And return to caller
357 ; --- cs_immediate ---
359 ; On entry: R10 == currently selected dialogue box
361 ; On exit: CS if immediate operations are enabled, or CC
363 ; Use: Informs the caller whether sliders and arrows should cause
364 ; immediate update of the dialogue box, or wait until the
365 ; operation has completed.
370 STMFD R13!,{R0,R1,R14} ;Save some registers
371 LDR R0,cs__frameDb ;Load the frame handle
372 MOV R1,#csIcon__instant ;Get instant effect switch
373 BL dbox_isSelected ;Is it selected?
374 LDMFD R13!,{R0,R1,PC} ;Return this state
378 ; --- cs_resolution ---
380 ; On entry: R10 == currently selected dialogue box
382 ; On exit: R0 == quality value, from 0 (pixel) to 3 (grotty)
384 ; Use: Returns the current resolution value. This is interpreted
385 ; in a model-dependent manner.
390 LDR R0,cs__resolution ;Load the value out
391 MOVS PC,R14 ;Return to caller
395 ;----- Icon numbers ---------------------------------------------------------
406 csIcon__instant EQU 12
407 csIcon__resDisp EQU 14
408 csIcon__resMenu EQU 15
410 ;----- dbx controls ---------------------------------------------------------
416 STMFD R13!,{R0-R4,R14} ;Stack some registers
417 LDR R0,[R8,#0] ;Get the RGB colour
418 MOV R3,#&180 ;ColourTrans flags
420 SWI XColourTrans_SetGCOL ;Set the colour
422 ; --- If error, try without dithering ---
424 LDRVS R0,[R8,#0] ;Get the RGB colour
425 MOVVS R3,#&080 ;ColourTrans flags
426 MOVVS R4,#0 ;GCOL type
427 SWIVS ColourTrans_SetGCOL ;Set the colour
429 ; --- Do a CLG... cunning! ----
431 SWI OS_WriteI+16 ;Plot the colour nicley
433 LDMFD R13!,{R0-R4,PC}^ ;Return nicley then
435 ;----- That's all, folks ----------------------------------------------------