chiark / gitweb /
Initial revision
[ssr] / StraySrc / Sculptrix / !SConfig / s / loadConfig
1 ;
2 ; loadConfig.s
3 ;
4 ; Load a Sculptrix configuration file
5 ;
6 ; © 1997-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 ;----- Revision history -----------------------------------------------------
28 ;
29 ; Version       By      Change
30 ;
31 ; 1.00          mdw     Initial version.
32
33 ;----- Standard header ------------------------------------------------------
34
35                 GET     libs:header
36                 GET     libs:swis
37
38                 GET     libs:stream
39
40 ;----- External dependencies ------------------------------------------------
41
42                 IMPORT  version
43                 IMPORT  |Image$$RW$$Limit|
44
45 ;----- Main code ------------------------------------------------------------
46
47                 AREA    |App$$Code|,CODE,READONLY
48                 ENTRY
49
50 ; --- main ---
51 ;
52 ; On entry:     --
53 ;
54 ; On exit:      --
55 ;
56 ; Use:          Loads a named Sculptrix file.  If we're currently in the
57 ;               desktop, and Sculptrix thinks that it's necessary, redraw
58 ;               the screen.
59
60 main            ROUT
61
62                 ; --- Set up some workspace ---
63
64                 SWI     OS_GetEnv               ;Read environment information
65                 ADR     R12,|Image$$RW$$Limit|  ;Get end of the program
66                 ADD     R14,R12,#lc__wSize      ;Add on my requirements
67                 CMP     R14,R1                  ;Do I have enough?
68                 ADRCS   R0,lc__noRoom           ;No -- point to error
69                 SWICS   OS_GenerateError        ;And report to the user
70
71                 ; --- Read the arguments string ---
72
73 00              LDRB    R14,[R0],#1             ;Load next byte out
74                 CMP     R14,#&20                ;Is it a space or less?
75                 BHI     %b00                    ;No -- keep going then
76 00              CMP     R14,#&20                ;Is it exactly a space?
77                 LDREQB  R14,[R0],#1             ;Yes -- fetch another one
78                 BEQ     %b00                    ;And keep going
79                 SUB     R1,R0,#1                ;Point back to last char
80
81                 ADR     R0,lc__argDef           ;Point to description string
82                 ADR     R2,lc__args             ;Point to the argument buffer
83                 MOV     R3,#256                 ;Use up lots of buffer space
84                 SWI     OS_ReadArgs             ;Read the arguments in
85
86                 ; --- Inspect the arguments ---
87
88                 LDR     R14,lc__wantHelp        ;Load the help flag
89                 CMP     R14,#0                  ;Is it set?
90                 BNE     lc__help                ;Yes -- give some help
91
92                 LDR     R1,lc__filename         ;Load filename address
93                 CMP     R1,#0                   ;Is this defined?
94                 ADREQ   R0,lc__noFile           ;No -- point to an error
95                 SWIEQ   OS_GenerateError        ;And return the error
96
97                 ; --- Check the file's size for sanity ---
98
99                 MOV     R0,#17                  ;Find out some file info
100                 SWI     OS_File                 ;Read all about the file
101                 TST     R0,#1                   ;Is this a file?
102                 MOVEQ   R2,R0                   ;No -- get the object type
103                 MOVEQ   R0,#19                  ;Return me an error please
104                 SWIEQ   OS_File                 ;And get the error
105
106                 CMP     R4,#256                 ;Is the file too big?
107                 ADRCS   R0,lc__tooBig           ;Yes -- point to error
108                 SWICS   OS_GenerateError        ;And report it to the user
109
110                 ; --- Load the file into memory ---
111
112                 MOV     R0,#16                  ;Load the file into memory
113                 ADD     R2,R12,#512             ;Point to appropriate chunk
114                 MOV     R3,#0                   ;Load where I said, please
115                 SWI     OS_File                 ;Do that, please
116
117                 ; --- Check the file's contents for sanity ---
118
119                 LDR     R0,[R12,#512]           ;Load the first word
120                 LDR     R14,lc__magic           ;Load what it should be
121                 CMP     R0,R14                  ;These should be the same
122                 ADRNE   R0,lc__notConf          ;Point to an error
123                 SWINE   OS_GenerateError        ;And complain if they're not
124
125                 ; --- Send the configuration to Sculptrix ---
126
127                 ADD     R0,R12,#512 + 4         ;Point to actual config data
128                 SWI     XSculptrix_SetConfig    ;Set the configuration
129
130                 ; --- Error checking here ---
131                 ;
132                 ; I know for a fact, because I have the source code in front
133                 ; of me, that Sculptrix_SetConfig never returns an error.
134                 ; Therefore, if V is set right now, I know that Sculptrix
135                 ; isn't actually there, and I can return a slightly more
136                 ; useful error message.
137
138                 ADRVS   R0,lc__noSculpt         ;Point to message
139                 SWIVS   OS_GenerateError        ;And return it to caller
140
141                 ; --- If C is clear, there's nothing to redraw ---
142                 ;
143                 ; Also, I may not have to do any redrawing because I was
144                 ; told not to.
145
146                 SWICC   OS_Exit                 ;C is clear: we're finished
147                 LDR     R14,lc__noRedraw        ;Load the no-redraw flag
148                 CMP     R14,#0                  ;Is it cleared?
149                 SWINE   OS_Exit                 ;No -- we're done then
150
151                 ; --- Initialise as a Wimp task ---
152
153                 MOV     R0,#200                 ;Wimp version number
154                 LDR     R1,lc__task             ;Load the magic number
155                 ADR     R2,lc__progName         ;Point to program name
156                 SWI     XWimp_Initialise        ;Start up as a Wimp app
157
158                 ; --- Read the screen extents ---
159
160                 ADR     R0,lc__vduVars          ;Point to VDU variables
161                 ADR     R1,lc__vduBuff          ;And to the output buffer
162                 SWI     OS_ReadVduVariables     ;Read them in please
163                 LDMIA   R1!,{R1-R4}             ;Load the values out now
164                 ADD     R3,R3,#1                ;Increment width
165                 ADD     R4,R4,#1                ;And height
166                 MOV     R3,R3,LSL R1            ;Shift width up to OS units
167                 MOV     R4,R4,LSL R2            ;And the height too
168
169                 ; --- Now do the redraw ---
170                 ;
171                 ; Note that I don't check for errors here.
172
173                 MOV     R0,#-1                  ;Redraw the whole screen
174                 MOV     R1,#0                   ;From the bottom left
175                 MOV     R2,#0                   ;So set that up
176                 SWI     XWimp_ForceRedraw       ;Redraw everything
177
178                 ; --- That's it: I'm done now ---
179
180                 SWI     OS_Exit                 ;That's it, then
181
182 lc__noRoom      DCD     1
183                 DCB     "Not enough memory for LoadConfig to initialise",0
184
185                 ALIGN
186 lc__argDef      DCB     "help/s,noredraw/s,",0
187
188 lc__noFile      DCD     1
189                 DCB     "You must specify a filename",0
190
191 lc__tooBig      DCD     1
192                 DCB     "Too large to be a Sculptrix configuration file",0
193
194 lc__notConf     DCD     1
195                 DCB     "This isn't a Sculptrix configuration file",0
196
197 lc__noSculpt    DCD     1
198                 DCB     "Sculptrix not loaded or too old",0
199
200 lc__magic       DCB     "SXCF"
201
202 lc__task        DCB     "TASK"
203
204 lc__progName    DCB     "LoadConfig",0
205
206 lc__vduVars     DCD     4,5,11,12,-1
207
208                 LTORG
209
210 ; --- lc__help ---
211 ;
212 ; On entry:     --
213 ;
214 ; On exit:      --
215 ;
216 ; Use:          Reports a help message and quits.
217
218 lc__help        ROUT
219
220                 ADR     R0,lc__helpText         ;Point to help text
221                 MOV     R1,#0                   ;Use system dictionary
222                 ADR     R2,version              ;Point to version string
223                 SWI     OS_PrettyPrint          ;Display the text
224                 SWI     OS_Exit                 ;And exit nicely
225
226 lc__helpText    DCB     "LoadConfig ",27,0,13
227                 DCB     13
228                 DCB     "Syntax: LoadConfig [<options>] <filename>",13
229                 DCB     13
230                 DCB     "Options (which may be abbreviated) are:",13
231                 DCB     13
232                 DCB     "-help",9,9,"Display this help text",13
233                 DCB     "-noRedraw",9,"Suppress screen redraw",13
234                 DCB     0
235
236                 LTORG
237
238 ;----- Workspace layout -----------------------------------------------------
239
240                 ^       0,R12
241 lc__wStart      #       0
242
243                 ; --- VDU variables ---
244
245 lc__vduBuff     #       0                       ;VDU variables output buffer
246 lc__xEig        #       4                       ;X EIG factor
247 lc__yEig        #       4                       ;Y EIG factor
248 lc__scrWidth    #       4                       ;Screen width
249 lc__scrHeight   #       4                       ;Screen height
250
251                 ; --- Arguments read from command line ---
252
253 lc__args        #       0                       ;Argument buffer start
254 lc__wantHelp    #       4                       ;Someone wants some help
255 lc__noRedraw    #       4                       ;Don't redraw the screen
256 lc__filename    #       4                       ;Address of the filename
257 lc__argBuff     #       256 - 12                ;Rest of the argument buffer
258
259                 ; --- Buffer for loading config files ---
260
261 lc__loadBuf     #       0                       ;Buffer start address
262 lc__confMagic   #       4                       ;Magic number on the front
263 lc__confData    #       252                     ;Rest of the data
264
265 lc__wSize       EQU     {VAR} - lc__wStart
266
267 ;----- That's all, folks ----------------------------------------------------
268
269                 END