4 ; Load a Sculptrix configuration file
6 ; © 1997-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 ;----- Revision history -----------------------------------------------------
31 ; 1.00 mdw Initial version.
33 ;----- Standard header ------------------------------------------------------
40 ;----- External dependencies ------------------------------------------------
43 IMPORT |Image$$RW$$Limit|
45 ;----- Main code ------------------------------------------------------------
47 AREA |App$$Code|,CODE,READONLY
56 ; Use: Loads a named Sculptrix file. If we're currently in the
57 ; desktop, and Sculptrix thinks that it's necessary, redraw
62 ; --- Set up some workspace ---
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
71 ; --- Read the arguments string ---
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
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
86 ; --- Inspect the arguments ---
88 LDR R14,lc__wantHelp ;Load the help flag
89 CMP R14,#0 ;Is it set?
90 BNE lc__help ;Yes -- give some help
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
97 ; --- Check the file's size for sanity ---
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
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
110 ; --- Load the file into memory ---
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
117 ; --- Check the file's contents for sanity ---
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
125 ; --- Send the configuration to Sculptrix ---
127 ADD R0,R12,#512 + 4 ;Point to actual config data
128 SWI XSculptrix_SetConfig ;Set the configuration
130 ; --- Error checking here ---
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.
138 ADRVS R0,lc__noSculpt ;Point to message
139 SWIVS OS_GenerateError ;And return it to caller
141 ; --- If C is clear, there's nothing to redraw ---
143 ; Also, I may not have to do any redrawing because I was
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
151 ; --- Initialise as a Wimp task ---
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
158 ; --- Read the screen extents ---
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
169 ; --- Now do the redraw ---
171 ; Note that I don't check for errors here.
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
178 ; --- That's it: I'm done now ---
180 SWI OS_Exit ;That's it, then
183 DCB "Not enough memory for LoadConfig to initialise",0
186 lc__argDef DCB "help/s,noredraw/s,",0
189 DCB "You must specify a filename",0
192 DCB "Too large to be a Sculptrix configuration file",0
195 DCB "This isn't a Sculptrix configuration file",0
198 DCB "Sculptrix not loaded or too old",0
204 lc__progName DCB "LoadConfig",0
206 lc__vduVars DCD 4,5,11,12,-1
216 ; Use: Reports a help message and quits.
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
226 lc__helpText DCB "LoadConfig ",27,0,13
228 DCB "Syntax: LoadConfig [<options>] <filename>",13
230 DCB "Options (which may be abbreviated) are:",13
232 DCB "-help",9,9,"Display this help text",13
233 DCB "-noRedraw",9,"Suppress screen redraw",13
238 ;----- Workspace layout -----------------------------------------------------
243 ; --- VDU variables ---
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
251 ; --- Arguments read from command line ---
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
259 ; --- Buffer for loading config files ---
261 lc__loadBuf # 0 ;Buffer start address
262 lc__confMagic # 4 ;Magic number on the front
263 lc__confData # 252 ;Rest of the data
265 lc__wSize EQU {VAR} - lc__wStart
267 ;----- That's all, folks ----------------------------------------------------