4 ; Colour handling for Sculptrix
6 ; © 1995-1998 Straylight
9 ;----- Licensing note -------------------------------------------------------
11 ; This file is part of Straylight's Sculptrix.
13 ; Sculptrix 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 ; Sculptrix 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 Sculptrix. If not, write to the Free Software Foundation,
25 ; 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 ;----- Standard header ------------------------------------------------------
34 ;----- External dependencies ------------------------------------------------
38 ;----- Main code ------------------------------------------------------------
40 AREA |Module$$Code|,CODE,READONLY
42 ; --- colours_read ---
44 ; On entry: R1 == pointer to icon block
46 ; On exit: R0 == foreground in bits 0-3, background in bits 4-7
47 ; CS if colours in validation string, and
48 ; R14 == address of colours in there, or 0
50 ; Use: Works out colours of an icon.
55 ORR R14,R14,#C_flag ;Set C flag for exit
56 STMFD R13!,{R1,R2,R14} ;Save some registers
57 LDR R14,[R1,#16] ;Load the icon flags
58 TST R14,#&40 ;Is the icon antialiased?
59 BNE %50colours_read ;Yes -- skip on then
61 MOV R0,R14,LSR #24 ;Get the colours
62 LDMFD R13!,{R1,R2,R14} ;Restore registers
63 BICS PC,R14,#C_flag ;Colours not in valid string
65 ; --- Extract colours from string ---
67 50colours_read MOV R0,#'f' ;Find the validation command
68 MOV R2,#0 ;Start at the beginning
69 BL vString_find ;Locate the string
70 MOVCC R14,#0 ;If not found, clear ptr
71 MOVCC R0,#&07 ;Return black-on-white
72 BCC %90colours_read ;And skip on
74 ADD R14,R2,#1 ;Point at the characters
75 LDRB R0,[R14,#1] ;Load the foreground colour
76 SUB R0,R0,#'0' ;Convert to digit
78 SUBCS R0,R0,#7 ;Yes -- must be a letter
79 CMP R0,#16 ;Still too big?
80 SUBCS R0,R0,#&20 ;Yes -- lowercase then
82 LDRB R1,[R14,#0] ;Load the background colour
83 SUB R1,R1,#'0' ;Convert to digit
85 SUBCS R1,R1,#7 ;Yes -- must be a letter
86 CMP R1,#16 ;Still too big?
87 SUBCS R1,R1,#&20 ;Yes -- lowercase then
88 ORR R0,R0,R1,LSL #4 ;Merge the two together
89 90colours_read LDMFD R13!,{R1,R2,PC}^ ;And return to caller
95 ; On entry: R1 == pointer to icon /state/ block
96 ; R2 == new background colour
98 ; On exit: R2 == old background colour
100 ; Use: Changes the background colour of an icon.
105 STMFD R13!,{R0-R3,R14} ;Save some registers
106 ADD R1,R1,#8 ;Point to the main icon data
107 BL colours_read ;Read the old colours
108 MOV R0,R0,LSR #4 ;Shift down the colour
109 STR R0,[R13,#8] ;Return this in R2 later
110 BCS %50colours_set ;Handle anti-aliasing
112 MOV R2,R2,LSL #28 ;Put colours in right place
113 MOV R3,#&F0000000 ;Just change background colr
114 B %70colours_set ;And change the colour
116 ; --- Handle anti-aliasing ---
118 50colours_set CMP R14,#0 ;Can we do this?
119 BEQ %90colours_set ;No -- don't then
120 ADD R2,R2,#'0' ;Convert to decimal
121 CMP R2,#'9'+1 ;Is it in range?
122 ADDCS R2,R2,#7 ;No -- make it a letter
123 STRB R2,[R14,#0] ;Store background colour
124 MOV R2,#0 ;Don't change flags
125 MOV R3,#0 ;No, really, don't
127 70colours_set LDMDB R1,{R0,R1} ;Load window and icon handle
128 STMFD R13!,{R0-R3} ;Save them registers
129 MOV R1,R13 ;Point to the block
130 SWI XWimp_SetIconState ;Set the icon state
131 ADD R13,R13,#16 ;Restore the stack
132 90colours_set LDMFD R13!,{R0-R3,PC}^ ;And return to caller
136 ;----- That's all, folks ----------------------------------------------------