chiark / gitweb /
Initial revision
[ssr] / StraySrc / Sculptrix / sculptrix / s / colours
1 ;
2 ; colours.s
3 ;
4 ; Colour handling for Sculptrix
5 ;
6 ; © 1995-1998 Straylight
7 ;
8
9 ;----- Licensing note -------------------------------------------------------
10 ;
11 ; This file is part of Straylight's Sculptrix.
12 ;
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)
16 ; any later version.
17 ;
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.
22 ;
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.
26
27 ;----- Standard header ------------------------------------------------------
28
29                 GET     libs:header
30                 GET     libs:swis
31
32                 GET     libs:stream
33
34 ;----- External dependencies ------------------------------------------------
35
36                 GET     sh.vString
37
38 ;----- Main code ------------------------------------------------------------
39
40                 AREA    |Module$$Code|,CODE,READONLY
41
42 ; --- colours_read ---
43 ;
44 ; On entry:     R1 == pointer to icon block
45 ;
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
49 ;
50 ; Use:          Works out colours of an icon.
51
52                 EXPORT  colours_read
53 colours_read    ROUT
54
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
60
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
64
65                 ; --- Extract colours from string ---
66
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
73
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
77                 CMP     R0,#10                  ;Too big?
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
81
82                 LDRB    R1,[R14,#0]             ;Load the background colour
83                 SUB     R1,R1,#'0'              ;Convert to digit
84                 CMP     R1,#10                  ;Too big?
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
90
91                 LTORG
92
93 ; --- colours_set ---
94 ;
95 ; On entry:     R1 == pointer to icon /state/ block
96 ;               R2 == new background colour
97 ;
98 ; On exit:      R2 == old background colour
99 ;
100 ; Use:          Changes the background colour of an icon.
101
102                 EXPORT  colours_set
103 colours_set     ROUT
104
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
111
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
115
116                 ; --- Handle anti-aliasing ---
117
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
126
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
133
134                 LTORG
135
136 ;----- That's all, folks ----------------------------------------------------
137
138                 END