chiark / gitweb /
Initial revision
[ssr] / StraySrc / Sculptrix / sculptrix / s / config
1 ;
2 ; config.s
3 ;
4 ; Configuration interface 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.wSpace
37
38                 GET     sh.messages
39
40 ;----- Main code ------------------------------------------------------------
41
42                 AREA    |Module$$Code|,CODE,READONLY
43
44 ; --- config_set ---
45 ;
46 ; On entry:     R0 == pointer to config buffer
47 ;
48 ; On exit:      CS if config has changed, else CC
49 ;
50 ; Use:          Reads the config buffer into workspace.
51
52                 EXPORT  config_set
53 config_set      ROUT
54
55                 STMFD   R13!,{R0-R4,R14}        ;Save some registers
56                 MOV     R2,#0                   ;Clear some flags
57
58                 ; --- Copy over the flags ---
59
60                 LDRB    R14,[R0],#4             ;Load the flags out
61                 LDR     R1,sculpt_flags         ;Load our current flags too
62                 AND     R3,R1,#&FF              ;Get the appearance flags
63                 CMP     R3,R14                  ;Is there a change here?
64                 ORRNE   R2,R2,#1                ;Yes -- set the flag
65                 BICNE   R1,R1,#&FF              ;And some of our own
66                 ORRNE   R14,R14,R1              ;Merge the two sets together
67                 STRNE   R14,sculpt_flags        ;And store back in workspace
68
69                 ; --- Now deal with the colour sets ---
70
71                 ADR     R1,sculpt_colours       ;Point to the colour tables
72                 MOV     R3,#4                   ;There are four to do
73 00              LDR     R14,[R0],#2             ;Load the next pair
74                 MOV     R14,R14,LSL #16         ;Shift up to zero low half
75                 ORR     R14,R14,R14,LSR #16     ;And shift down to copy
76                 LDR     R4,[R1,#0]              ;Load the old word
77                 CMP     R4,R14                  ;Do these match?
78                 ORRNE   R2,R2,#1                ;No -- set the flag
79                 STR     R14,[R1],#4             ;Store in my table
80                 SUBS    R3,R3,#1                ;Decrement the counter
81                 BNE     %b00                    ;Loop back for some more
82
83                 ; --- Finally do the other pair ---
84
85                 LDR     R14,[R0,#0]             ;Load the colours
86                 LDR     R1,sculpt_hilight       ;Load the old ones
87                 MOV     R1,R1,LSL #16           ;Shift up nicely
88                 CMP     R1,R14,LSL #16          ;Do these match?
89                 ORRNE   R2,R2,#1                ;No -- set the flag
90                 STRNE   R14,sculpt_hilight      ;A hack, but it works
91
92                 TST     R2,#1                   ;Did anything change
93                 LDMFD   R13!,{R0-R4,R14}        ;Return when done
94                 ORRNES  PC,R14,#C_flag
95                 BICEQS  PC,R14,#C_flag
96
97                 LTORG
98
99 ; --- config_read ---
100 ;
101 ; On entry:     R0 == pointer to a buffer
102 ;               R1 == size of the buffer
103 ;
104 ; On exit:      --
105 ;
106 ; Use:          Writes the config into a buffer
107
108                 EXPORT  config_read
109 config_read     ROUT
110
111                 CMP     R1,#cBuff_size          ;Is the buffer big enough?
112                 ADRCCL  R0,msg_errCfgBuff       ;No -- find the error
113                 ORRCCS  PC,R14,#V_flag          ;And return it to caller
114
115                 STMFD   R13!,{R0-R2,R14}        ;Save some registers
116
117                 ; --- Copy the flags ---
118
119                 LDRB    R14,sculpt_flags        ;Load our flags
120                 STR     R14,[R0],#4             ;Store in output block
121
122                 ; --- Copy the colour tables ---
123
124                 ADR     R1,sculpt_colours       ;Point to the table
125                 MOV     R2,#4                   ;There are four to collect
126 00              LDR     R14,[R1],#4             ;Load the next pair
127                 STRB    R14,[R0],#1             ;Store low byte in block
128                 MOV     R14,R14,LSR #8          ;Shift down by a byte
129                 STRB    R14,[R0],#1             ;Store next byte away
130                 SUBS    R2,R2,#1                ;Decrement counter
131                 BNE     %b00                    ;And loop back until done
132
133                 ; --- Finally do the other pair ---
134
135                 LDR     R14,sculpt_hilight      ;A hack, but it works
136                 STR     R14,[R0,#0]             ;Load the colours
137
138                 LDMFD   R13!,{R0-R2,PC}^        ;Return when done
139
140                 LTORG
141
142 ; --- config_load ---
143 ;
144 ; On entry:     R0 == pointer to filename
145 ;
146 ; On exit:      --
147 ;
148 ; Use:          Loads a configuration file.
149
150                 EXPORT  config_load
151 config_load     ROUT
152
153                 STMFD   R13!,{R14}              ;Save some registers
154                 LDR     R12,[R12,#0]            ;Load my workspace pointer
155
156                 ; --- Find out if the file is suitable ---
157
158                 MOV     R1,R0                   ;Point to the filename
159                 MOV     R0,#17                  ;Read file information
160                 SWI     XOS_File                ;Read the information, then
161                 BVS     %99config_load          ;If failed, return the error
162                 TST     R0,#1                   ;Is it a real file?
163                 BEQ     %98config_load          ;No -- build and error then
164
165                 CMP     R4,#256                 ;Will it fit in my buffer?
166                 ADRCSL  R0,msg_errBadConfig     ;No -- point to the error
167                 BCS     %99config_load          ;And report the error
168
169                 ; --- Load the file into my buffer ---
170
171                 MOV     R0,#16                  ;Load the file, please
172                 ADR     R2,sculpt_misc          ;Point to a buffer
173                 MOV     R3,#0                   ;Please load it here
174                 SWI     XOS_File                ;Do the file load op
175                 BVS     %99config_load          ;If failed, return the error
176
177                 ADR     R0,sculpt_misc          ;Point to the buffer
178                 LDR     R1,[R0],#4              ;Load the first word out
179                 LDR     R14,config__magic       ;Load a magic number
180                 CMP     R1,R14                  ;Do these match up?
181                 ADRNEL  R0,msg_errBadConfig     ;No -- point to the error
182                 BNE     %99config_load          ;And report the error
183
184                 BL      config_set              ;Set the configuration
185                 LDMFD   R13!,{PC}^              ;Return when done
186
187                 ; --- Returning errors ---
188
189 98config_load   MOV     R2,R0                   ;Get the botched object type
190                 MOV     R0,#19                  ;Return me a sensible error
191                 SWI     XOS_File                ;Get the error message
192
193 99              LDMFD   R13!,{R14}              ;Restore the return address
194                 ORRS    PC,R14,#V_flag          ;And return with V set
195
196 config__magic   DCB     "SXCF",0
197
198                 LTORG
199
200 ;----- Config buffer structure ----------------------------------------------
201
202                 ^       0
203 cBuff_flags     #       4                       ;Various nice flags
204 cBuff_stdCols   #       2                       ;Standard border colours
205 cBuff_grpCols   #       2                       ;Group box colours
206 cBuff_shdCols   #       2                       ;Shaded border colours
207 cBuff_shgCols   #       2                       ;Shaded group colours
208 cBuff_hilight   #       1                       ;Highlight colour for default
209 cBuff_slab      #       1                       ;Slab background colour
210                 #       2                       ;Alignment padding
211 cBuff_size      #       0
212
213 ;----- That's all, folks ----------------------------------------------------
214
215                 END