4 ; The Colour Selector kernel
6 ; © 1994-1998 Straylight
9 ;----- Licensing note -------------------------------------------------------
11 ; This file is part of Straylight's Sapphire library.
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)
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.
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.
27 ;----- Standard header ------------------------------------------------------
32 ;----- External dependencies ------------------------------------------------
43 GET sapphire:dbx.stringSet
46 GET sapphire:_cs.models
48 ;----- Main code ------------------------------------------------------------
50 AREA |Sapphire$$Code|,CODE,READONLY
54 ; On entry: R0 == address of a colour block
55 ; R1 == pointer to routine to call when done
56 ; R2 == R10 to call routine with
57 ; R3 == R12 to call routine with
59 ; On exit: May return error
61 ; Use: Displays a colour selector dialogue box. It allows the user
62 ; to edit a colour (understatement....)
67 BIC R14,R14,#V_flag ;Clear the V flag
68 STMFD R13!,{R0-R4,R10,R14} ;Save a load of registers
70 ; --- Try to create a workspace block ---
72 MOV R0,#cs__dSize ;Get my data size
73 BL alloc ;Try to allocate the memory
74 BLCS alloc_error ;If it failed, get a message
75 BCS %99colSelect ;And tidy up as we go
76 MOV R10,R0 ;Look after this block
78 ; --- Now create a dialogue box ---
80 ADR R0,cs__dbName ;Point to the dialogue name
81 BL dbox_create ;Create the dialogue
82 BVS %98colSelect ;Tidy up if it failed
83 STR R0,cs__frameDb ;Save the dialogue handle
84 ADR R1,cs__handler ;The event handler
85 MOV R2,R10 ;Pass this R10 value
86 MOV R3,R12 ;And this R12 value
87 BL dbox_eventHandler ;Set up the handler
88 ADR R1,cs__dbxBlock ;Point to dbx information
89 BL dbx_declare ;Declare the block
91 ; --- Save the caller's information ---
93 LDR R0,[R13,#0] ;Load his colour's address
94 LDMIA R0,{R1-R3} ;Load the colour arguments
95 ADR R14,cs__address ;Point into the data block
96 STMIA R14,{R0-R3} ;And save all of that stuff
98 ; --- Set up the workspace ---
100 MOV R14,#3 ;Start on low resolution
101 STR R14,cs__resolution ;Save it in the workspace
103 ; --- Set up the initial model ---
105 BL cs__initModel ;Get a model index
106 BVS %97colSelect ;Clean up on an error
107 MOV R4,R2 ;Keep the model number
108 STR R0,cs__modelDb ;Save model's dialogue box
109 BL dbox_window ;Get the window handle
110 MOV R3,R0 ;Put model's db handle in R3
111 LDR R0,cs__frameDb ;Get frame db handle
112 MOV R1,#dbOpen_persist+dbOpen_current
113 BL dbox_open ;Open the dialogue box
114 MOV R1,#csIcon__rgb ;The first model icon number
115 ADD R1,R1,R2 ;Get the correct icon number
116 MOV R2,#1 ;Turn the icon on
117 BL dbox_select ;Select the icon
118 MOV R2,R3 ;Pane window handle
119 BL dbox_window ;Get the window handle
120 MOV R1,#csIcon__models ;The icon handle
121 BL pane_add ;Add the pane
122 BL pane_open ;Open the pane
123 BL cs__setCaret ;And give it the focus
124 95colSelect LDMFD R13!,{R0-R4,R10,PC}^ ;Return to caller
126 97colSelect MOV R4,R0 ;Preserve R0
127 LDR R0,cs__frameDb ;Get the dialogue box handle
128 BL dbox_destroy ;Destroy the dialogue box
129 MOV R0,R4 ;Get R0 back
130 98colSelect MOV R4,R0 ;Preserve R0
131 MOV R0,R10 ;Point to allocated memory
132 BL free ;Free it nicely
133 MOV R0,R4 ;Get R0 back
134 99colSelect ADD R13,R13,#4 ;Don't load R0
135 LDMFD R13!,{R1-R4,R10,R14} ;Load registers
136 ORRS PC,R14,#V_flag ;Return with error
140 cs__dbName DCB "colSelect",0
142 cs__dbxBlock CONTROL csIcon__colour,colButton,R10,0,:INDEX: cs__colour
144 STRSET csIcon__resDisp,R10,:INDEX: cs__resolution, cs__resMenu,cs__resStrings,csIcon__resDisp
145 STRSET csIcon__resMenu,R10,:INDEX: cs__resolution, cs__resMenu,cs__resStrings,csIcon__resDisp
148 cs__resMenu MENU "csRESMT"
149 ITEM "csRESVH:Very high"
159 cs__resStrings DCB "csRESVH:Very high",0
161 DCB "csRESM:Medium",0
164 ; --- cs__initModel ---
166 ; On entry: R2 == colour model number, or 0
168 ; On exit: R0 == dialogue box created by colour model, or error
169 ; R2 == preserved, or index of RGB model
171 ; Use: Initialises a colour model dialogue box.
175 CMP R2,#cs__noModels ;Is the model in range?
176 MOVHS R2,#cMod_rgb ;No -- use RGB then
177 ADD PC,PC,R2,LSL #2 ;Call the function
180 00cs__initModel B rgb_open
184 cs__noModels EQU (%10-%00)/4
186 ; --- cs__setCaret ---
192 ; Use: Sets the caret in the current colour select pane window.
196 STMFD R13!,{R0-R5,R14} ;Save some registers
197 LDR R0,cs__modelDb ;Get the model dialogue
198 BL dbox_window ;And find its window handle
199 MOV R1,#-1 ;In no particular icon
200 MOV R2,#&ff000000 ;Quite a long way away
202 MOV R3,#0 ;Doesn't really matter
203 MOV R4,#&02000000 ;Hide caret, make it small
204 MOV R5,#-1 ;No index into icon, please
205 SWI Wimp_SetCaretPosition ;Set the caret's position
206 LDMFD R13!,{R0-R5,PC}^ ;Return to caller
210 ; --- cs__handler ---
212 ; On entry: R0 == dialogue box event code
213 ; R1-R9 == depend on the event
214 ; R10 == colour selector data
215 ; R12 == nothing much, actually -- corrupted on exit
219 ; Use: Handles events for the main dialogue frame
223 CMP R0,#stringSet_event ;Is this a string set event?
224 BEQ cs__resMenuClk ;Yes -- handle that
226 CMP R0,#dbEvent_OK ;Is it an OK event?
227 CMPNE R0,#csIcon__ok ;Or a click on OK?
228 BEQ cs__ok ;Yes -- handle it then
230 CMP R0,#dbEvent_help ;Does someone want help?
231 BEQ cs__getHelp ;Yes -- deal with that too
233 SUB R12,R0,#csIcon__rgb ;Was it a model icon?
234 CMP R12,#cs__noModels
235 BLO cs__changeModel ;Yes -- deal with it
239 ; --- Handle an OK click/keypress ---
243 STMFD R13!,{R0-R5,R14} ;Save some registers
244 MOV R5,R1 ;Remember mouse button state
245 MOV R0,R9 ;Get my dialogue handle
246 MOV R1,#csIcon__ok ;And the OK button
247 BL dbox_slab ;Press it in nicely
249 ; --- Find the actual colour he chose ---
251 BL dbox_unslab ;Unslab the button
252 LDMFD R13!,{R0-R5,PC}^ ;And return to caller
256 ; --- Give a help message if required ---
258 cs__getHelp B dbox_help ;Just let dbox do it all!
260 ; --- Handle the resolution menu button ---
264 CMP R1,#csIcon__resDisp ;Is this the resolution one?
265 MOVNES PC,R14 ;No -- ignore it then
267 STMFD R13!,{R0,R10,R14} ;Save some registers
268 LDR R10,cs__modelDb ;Get the model's handle too
269 MOV R0,#csEvent__newRes ;The resolution's changed
270 BL dbx_sendEvent ;Send the event out
271 LDMFD R13!,{R0,R10,PC}^ ;And return to caller
275 ; --- Handle a model selection ---
279 STMFD R13!,{R0-R3,R14} ;Stack some registers
280 LDR R1,cs__colour+col_model ;Load the existing model
281 CMP R1,R12 ;Is it the same?
282 LDMEQFD R13!,{R0-R3,PC}^ ;Yes -- return
284 ; --- Tell old model to update colour ---
286 STMFD R13!,{R10} ;Save my instance pointer
287 LDR R10,cs__modelDb ;Get the current panel dbox
288 MOV R0,#csEvent__read ;Tell it to read its settings
289 BL dbx_sendEvent ;Send it the event
290 LDMFD R13!,{R10} ;Restore the instance pointer
292 ; --- First try to get a new model dialogue ---
294 MOV R2,R12 ;Get the new colour model
295 BL cs__initModel ;Try to initialise it nicely
296 BVS %90cs__changeModel ;If it failed, report error
298 ; --- Now remove the old one ---
300 STMFD R13!,{R0,R10} ;Save some important regs
301 LDR R10,cs__modelDb ;Get the current panel dbox
302 MOV R0,R10 ;Get it in R0
303 BL dbox_window ;Find its window handle
304 MOV R3,R0 ;Keep this value nicely
305 SUB R13,R13,#24 ;Space for a caret block
306 MOV R1,R13 ;Point to the caret block
307 SWI Wimp_GetCaretPosition ;Find the caret nicely
308 LDR R0,[R13,#0] ;Load the focus window handle
309 CMP R0,R3 ;Is it the panel?
310 MOVNE R3,#0 ;No -- clear the value then
311 ADD R13,R13,#24 ;Restore the stack pointer
312 MOV R0,#csEvent__close ;Send a close event
313 BL dbx_sendEvent ;Send the event
314 LDMFD R13!,{R0,R10} ;Restore the registers again
316 ; --- Set up the new panel nicely ---
318 STR R0,cs__modelDb ;Store the new db handle
319 STR R2,cs__colour+col_model ;And the new model type
320 BL dbox_window ;Get the new window handle
321 MOV R2,R0 ;This is the new pane
322 LDR R0,cs__frameDb ;Get the main dialogue box
323 BL dbox_window ;And get its window handle
324 MOV R1,#csIcon__models ;The main icon thingy
325 BL pane_swap ;Swap the pane over
326 CMP R3,#0 ;Was the caret in the panel
327 BLNE cs__setCaret ;Yes -- put it in the new one
328 LDMFD R13!,{R0-R3,PC}^ ;Return to caller
330 90 MOV R1,#1 ;Only an OK button please
331 BL errorBox ;Call error box
332 LDMFD R13!,{R0-R3,R14} ;Return to caller
333 ORRS PC,R14,#C_flag ;Don't change the radio state
337 ; --- cs_passBack ---
339 ; On entry: R0-R7 == dialogue box event information
340 ; R10 == pointer to colour selector instance
344 ; Use: Passes an event back to the main colour selector frame dbox.
349 STMFD R13!,{R10,R14} ;Save some registers
350 LDR R10,cs__frameDb ;Get the dialogue handle
351 BL dbx_sendEvent ;Pass the event on
352 LDMFD R13!,{R10,PC}^ ;And return to caller
356 ; --- cs_colChange ---
358 ; On entry: R10 == currently selected dialogue box
362 ; Use: Updates the colour selector's colour display.
367 STMFD R13!,{R0,R1,R14} ;Save some registers
368 LDR R0,cs__frameDb ;Load the frame handle
369 MOV R1,#csIcon__colour ;Get the colour button icon
370 BL dbx_update ;Redraw it nicely
371 LDMFD R13!,{R0,R1,PC}^ ;And return to caller
375 ; --- cs_immediate ---
377 ; On entry: R10 == currently selected dialogue box
379 ; On exit: CS if immediate operations are enabled, or CC
381 ; Use: Informs the caller whether sliders and arrows should cause
382 ; immediate update of the dialogue box, or wait until the
383 ; operation has completed.
388 STMFD R13!,{R0,R1,R14} ;Save some registers
389 LDR R0,cs__frameDb ;Load the frame handle
390 MOV R1,#csIcon__instant ;Get instant effect switch
391 BL dbox_isSelected ;Is it selected?
392 LDMFD R13!,{R0,R1,PC} ;Return this state
396 ; --- cs_resolution ---
398 ; On entry: R10 == currently selected dialogue box
400 ; On exit: R0 == quality value, from 0 (pixel) to 3 (grotty)
402 ; Use: Returns the current resolution value. This is interpreted
403 ; in a model-dependent manner.
408 LDR R0,cs__resolution ;Load the value out
409 MOVS PC,R14 ;Return to caller
413 ;----- Icon numbers ---------------------------------------------------------
416 csIcon__modDisp EQU 2
417 csIcon__modMenu EQU 3
419 csIcon__resDisp EQU 6
420 csIcon__resMenu EQU 7
421 csIcon__instant EQU 8
425 ;----- dbx controls ---------------------------------------------------------
431 STMFD R13!,{R0-R4,R14} ;Stack some registers
432 LDR R0,[R8,#0] ;Get the RGB colour
433 MOV R3,#&180 ;ColourTrans flags
435 SWI XColourTrans_SetGCOL ;Set the colour
437 ; --- If error, try without dithering ---
439 LDRVS R0,[R8,#0] ;Get the RGB colour
440 MOVVS R3,#&080 ;ColourTrans flags
441 MOVVS R4,#0 ;GCOL type
442 SWIVS ColourTrans_SetGCOL ;Set the colour
444 ; --- Do a CLG... cunning! ---
446 SWI OS_WriteI+16 ;Plot the colour nicley
448 LDMFD R13!,{R0-R4,PC}^ ;Return nicley then
450 ;----- Workspace ------------------------------------------------------------
452 AREA |Sapphire$$LibData|,CODE,READONLY
459 ;----- That's all, folks ----------------------------------------------------