Initial revision
[ssr] / StraySrc / Sculptrix / !Setrix / s / setrix
1 ;
2 ; setrix.s
3 ;
4 ; Setup program 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 ;----- Revision history -----------------------------------------------------
28 ;
29 ; Version By Change
30 ;
31 ; 1.00 MDW Initial version written to accompany Sculptrix 2.00
32
33 ;----- Standard header ------------------------------------------------------
34
35 GET libs:header
36 GET libs:swis
37
38 GET libs:stream
39
40 ;----- External dependencies ------------------------------------------------
41
42 GET sapphire:buttons
43 GET sapphire:dbox
44 GET sapphire:defHandler
45 GET sapphire:errorBox
46 GET sapphire:fastMove
47 GET sapphire:flex
48 GET sapphire:event
49 GET sapphire:help
50 GET sapphire:hour
51 GET sapphire:ibicon
52 GET sapphire:menu
53 GET sapphire:menuDefs
54 GET sapphire:msgs
55 GET sapphire:progInfo
56 GET sapphire:ptr
57 GET sapphire:report
58 GET sapphire:res
59 GET sapphire:resources
60 GET sapphire:sapphire
61 GET sapphire:screen
62 GET sapphire:seh
63 GET sapphire:string
64 GET sapphire:warning
65
66 GET sapphire:choices.choices
67
68 GET sapphire:dbx.colourPot
69 GET sapphire:dbx.dbx
70
71 GET sapphire:xfer.load
72 GET sapphire:xfer.save
73 GET sapphire:xfer.saveAs
74
75 IMPORT cright
76 IMPORT version
77
78 ;----- Icon handles ---------------------------------------------------------
79
80 sxIcon__cols EQU 12 ;Main colour table
81 sxIcon__hilite EQU 22 ;Highlight colour
82 sxIcon__slab EQU 24 ;Slabbed background
83 sxIcon__ccGrp EQU 26 ;CC-style group box
84 sxIcon__acGrp EQU 27 ;Acorn-style group box
85 sxIcon__ok EQU 28 ;OK button
86 sxIcon__save EQU 29 ;Save button
87 sxIcon__cancel EQU 30 ;Cancel button
88
89 ;----- Configuration blocks -------------------------------------------------
90
91 ^ 0
92 sxConf__magic # 4 ;Magic identifier word
93 sxConf__flags # 4 ;Various flags
94 sxConf__stdCols # 2 ;Standard colour pair
95 sxConf__grpCols # 2 ;Group colour pair
96 sxConf__shdCols # 2 ;Shaded normal colours
97 sxConf__shgCols # 2 ;Shaded group colours
98 sxConf__hilite # 1 ;The highlight colour
99 sxConf__slab # 1 ;The slabbing colour
100 # 2 ;Alignment padding
101 sxConf__size # 0
102
103 ;----- Workspace ------------------------------------------------------------
104
105 ^ 0,R12
106 sx__wStart # 0
107
108 sx__flags # 4 ;Various usefule flags
109 sx__dbox # 4 ;The dialogue box handle
110 sx__anchor # 4 ;A flex anchor for loading
111 sx__config # sxConf__size ;Configuration buffer
112 sx__filename # 256 ;Filename buffer
113 sx__pollBlk # 256 ;Block for Wimp_Poll
114
115 sx__wSize EQU {VAR}-sx__wStart
116
117 sxFlag__safe EQU (1<<0) ;File has been saved
118 sxFlag__saving EQU (1<<1) ;We're saving a file
119
120 ;----- Main code ------------------------------------------------------------
121
122 AREA |Client$$Code|,CODE,READONLY
123 ENTRY
124
125 ; --- main ---
126 ;
127 ; On entry: --
128 ;
129 ; On exit: Via OS_Exit
130 ;
131 ; Use: Starts up the application.
132
133 main ROUT
134
135 ADR R0,sx__appName ;Point to the app name
136 LDR R1,=sx__wSize ;Get the workspace size
137 MOV R2,#0 ;Standard stack size
138 BL sapphire_init ;Set up the memory map
139 BL sx__preInit ;Do pre-initialisation
140 BL sapphire_libInit ;Crank up the library
141 BL sx__init ;Do other initialisation
142
143 BL seh_throwErrors ;Throw errors at ne, please
144 BL report_catchAll ;Install last error handler
145
146 00 MOV R0,#0 ;Don't get idle events
147 ADR R1,sx__pollBlk ;Point to the poll block
148 BL event_poll ;Do some polling
149 BLCC sx__unknowns ;Handle unknowns ourselves
150 BLCC defHandler ;Do default handling
151 B %b00 ;And keep looping
152
153 sx__appName DCB "Setrix",0
154
155 LTORG
156
157 ; --- sx__preInit ---
158 ;
159 ; On entry: --
160 ;
161 ; On exit: R0-R10 corrupted
162 ;
163 ; Use: Does any initialisation required before Sapphire is started,
164
165 sx__preInit ROUT
166
167 STMFD R13!,{R14} ;Save return address
168 BL hour_init ;Initialise hourglass
169 BL hour_on ;Turn on the hourglass
170 BL resources_init ;Fetch shared resources
171 LDMFD R13!,{PC}^ ;And return to caller
172
173 LTORG
174
175 ; --- sx__init ---
176 ;
177 ; On entry: --
178 ;
179 ; On exit: R0-R10 corrupted
180 ;
181 ; Use: Initialises the rest of the application.
182
183 sx__init ROUT
184
185 STMFD R13!,{R14} ;Save return address
186 BL sx__initWork ;Initialise the workspace
187 BL sx__loadConf ;Load the config file
188 BL ptr_blinkOn ;Turn on the blinking cursor
189 BL sx__iconBar ;Set up the icon bar
190 LDMFD R13!,{PC}^ ;And return to caller
191
192 LTORG
193
194 ; --- sx__initWork ---
195 ;
196 ; On entry: --
197 ;
198 ; On exit: R0-R10 corrupted
199 ;
200 ; Use: Sets up the workspace.
201
202 sx__initWork ROUT
203
204 STMFD R13!,{R14} ;Save a register
205
206 ; --- Set up some odd bits ---
207
208 MOV R14,#0 ;Clear the handle
209 STR R14,sx__dbox ;Store in the workspace
210
211 MOV R14,#sxFlag__safe ;The file is safe currently
212 STR R14,sx__flags ;Store the flags away
213
214 ; --- Set up default filename ---
215
216 MOV R0,#0 ;Use a default filename
217 BL sx__setFilename ;Set the filename, please
218
219 ; --- Set up the config buffer ---
220
221 LDR R14,sx__magic ;Load the magic number
222 ADR R0,sx__config ;Point to the config buffer
223 STR R14,[R0],#4 ;Store it in there
224 MOV R1,#sxConf__size-4 ;Size of my buffer
225 SWI Sculptrix_ReadConfig ;Read the configuration
226 LDMFD R13!,{PC}^ ;And return to caller
227
228 LTORG
229
230 ; --- sx__loadConf ---
231 ;
232 ; On entry: --
233 ;
234 ; On exit: R0-R10 corrupted
235 ;
236 ; Use: Loads the default config file, if there is one.
237
238 sx__loadConf ROUT
239
240 STMFD R13!,{R14} ;Save the return address
241
242 MOV R0,#1 ;Enable use of `Choices'
243 BL choices_useChoices ;So do that, then
244
245 ADR R0,sx__confFile ;Point to the file name
246 MOV R1,R11 ;Build name in scratchpad
247 MOV R2,#0 ;Not going to write to it
248 BL choices_find ;Find the filename
249 BCC %90sx__loadConf ;If not there, skip on
250
251 MOV R1,R0 ;Point to the filename
252 ADR R10,sx__config ;Point to config block
253 BL sx__ldFile ;Try to load the file
254 BLVC sx__ldDone ;If OK, set it up nicely
255
256 90sx__loadConf LDMFD R13!,{PC}^ ;And return to caller
257
258 sx__magic DCB "SXCF"
259 sx__confFile DCB "Config",0
260
261 LTORG
262
263 ; --- sx__iconBar ---
264 ;
265 ; On entry: --
266 ;
267 ; On exit: R0-R10 corrupted
268 ;
269 ; Use: Creates the icon bar icon.
270
271 sx__iconBar ROUT
272
273 STMFD R13!,{R14} ;Save a register
274 ADR R0,sx__ibSprite ;Point to the sprite name
275 MOV R1,#0 ;No text, please
276 MOV R2,#-1 ;Put icon on the right
277 MOV R3,#0 ;No priority things, please
278 ADR R4,sx__ibHandler ;Point to the handler
279 ADR R5,sx__config ;No document passed in R10
280 MOV R6,R12 ;Pass workspace in R12
281 BL ibicon_create ;Create the icon, please
282 SWIVS OS_GenerateError ;If failed, raise an error
283 LDMFD R13!,{PC}^ ;And return to caller
284
285 sx__ibSprite DCB "!setrix",0
286
287 LTORG
288
289 ; --- sx__ibHandler ---
290 ;
291 ; On entry: R0 == event code
292 ;
293 ; On exit: --
294 ;
295 ; Use: Handles events for the icon bar icon.
296
297 sx__ibHandler ROUT
298
299 CMP R0,#(%10-%00)/4 ;Is the event in range?
300 ADDCC PC,PC,R0,LSL #2 ;Yes -- dispatch it then
301 MOVS PC,R14 ;Otherwise return now
302
303 00 B sx__showDbox
304 B sx__ibCrtMenu
305 MOVS PC,R14
306 B sx__load
307 B sx__load
308 B sx__ibHelp
309 10
310 ; --- Display the icon bar menu ---
311
312 sx__ibCrtMenu STMFD R13!,{R0-R3,R14} ;Save some registers
313 ADR R0,sx__ibMenu ;Point to the menu block
314 ADR R1,sx__mnHandler ;Point to the handler
315 MOV R2,R10 ;Pass R10 to handler
316 MOV R3,R12 ;Pass R12 to handler
317 BL menu_create ;Create the menu, please
318 LDMFD R13!,{R0-R3,PC}^ ;And return to caller
319
320 sx__ibMenu MENU "Setrix"
321 ITEM "sxINF"
322 SUBWARN
323 ITEM "sxQUT"
324 MENUEND
325
326 ; --- Give help to a user ---
327
328 sx__ibHelp STMFD R13!,{R0,R14} ;Save some registers
329 ADR R0,sx__ibHelpTag ;Point to help tag
330 BL msgs_lookup ;Translate the tag
331 BL help_add ;Add it to the help message
332 LDMFD R13!,{R0,PC}^ ;And return to caller
333
334 sx__ibHelpTag DCB "sxhIB",0
335
336 LTORG
337
338 ; --- sx__mnHandler ---
339 ;
340 ; On entry: R0 == event code
341 ; R1 == menu item number
342 ;
343 ; On exit: --
344 ;
345 ; Use: Handles events on the program menu.
346
347 sx__mnHandler ROUT
348
349 CMP R0,#mEvent_help ;A help request?
350 BEQ sx__mnHelp ;Yes -- give some help then
351
352 CMP R0,#mEvent_select ;Is it a click event?
353 CMPNE R0,#mEvent_subMenu ;Or a submenu warning?
354 MOVNES PC,R14 ;No -- ignore it then
355
356 CMP R1,#(%10-%00)/4 ;Is the item known?
357 ADDCC PC,PC,R1,LSL #2 ;Yes -- dispatch
358 MOVS PC,R14 ;Otherwise ignore the event
359
360 00 B sx__showInfo ;Show program information
361 B sx__quit ;Quit the application
362 10
363 ; --- Display the Info box ---
364
365 sx__showInfo STMFD R13!,{R0-R2,R14} ;Save some registers
366 ADR R0,sx__purpose ;Point to the purpose string
367 BL msgs_lookup ;Translate the message
368 LDR R1,=cright ;Point to copyright message
369 LDR R2,=version ;Point to version string
370 BL progInfo ;Display the dialogue
371 MOVVS R1,#1 ;If error, get button layout
372 BLVS errorBox ;And report to the user
373 LDMFD R13!,{R0-R2,PC}^ ;Return to caller
374
375 sx__purpose DCB "sxPUR",0
376
377 ; --- Try to quit the program ---
378
379 sx__quit STMFD R13!,{R14} ;Save a register
380 BL sx__okToQuit ;Is it all right to quit?
381 SWICS OS_Exit ;Yes -- do it then
382 LDMFD R13!,{PC}^ ;Otherwise return
383
384 ; --- Give some help to the user ---
385
386 sx__mnHelp STMFD R13!,{R0,R14} ;Save some registers
387 ADR R0,sx__mnHelpTag ;Point to the message tag
388 BL menu_help ;Translate and add
389 LDMFD R13!,{R0,PC}^ ;Return when done
390
391 sx__mnHelpTag DCB "sxhMN",0
392
393 LTORG
394
395 ; --- sx__unknowns ---
396 ;
397 ; On entry: R0 == event code
398 ; R1 == pointer to event data
399 ;
400 ; On exit: R2-R10 corrupted
401 ; CS to claim
402 ;
403 ; Use: Handles unknown events. Specifically, it looks at PreQuit
404 ; messages, and asks the user if it's OK to quit.
405
406 sx__unknowns ROUT
407
408 CMP R0,#17 ;Is this a message?
409 CMPNE R0,#18 ;Check both types
410 MOVNES PC,R14 ;No -- ignore it then
411
412 LDR R2,[R1,#16] ;Load the message code
413 CMP R2,#8 ;Is this a PreQuit message?
414 MOVNES PC,R14 ;No -- ignore it then
415
416 ; --- Handle a PreQuit message ---
417
418 STMFD R13!,{R0,R1,R14} ;Save a register
419 BL sx__okToQuit ;Ask the user if this is OK
420 BCS %90sx__unknowns ;Yes -- then return now
421
422 ; --- Acknowledge the message to prevent quitting ---
423
424 MOV R0,R11 ;Point to scratchpad
425 LDR R2,[R1,#0] ;Load the message size
426 BL fastMove ;Copy the message over
427
428 LDR R14,[R11,#8] ;This is a reply
429 STR R14,[R11,#12] ;Store the ref away
430 MOV R0,#19 ;Send as an acknowledgement
431 MOV R1,R11 ;Point to copied message
432 LDR R2,[R11,#4] ;Load the task handle
433 SWI Wimp_SendMessage ;Send the message on
434
435 ; --- Now return, claiming the event ---
436
437 90sx__unknowns LDMFD R13!,{R0,R1,R14} ;Restore registers
438 ORRS PC,R14,#C_flag ;And return, claiming it
439
440 LTORG
441
442 ; --- sx__okToQuit ---
443 ;
444 ; On entry: --
445 ;
446 ; On exit: CS if we're allowed to quit
447 ;
448 ; Use: Ensures that we're allowed to quit. If we're in possession
449 ; of unsaved data, we ask the user first.
450
451 sx__okToQuit ROUT
452
453 STMFD R13!,{R0,R1,R14} ;Save some registers
454
455 ; --- Check whether the data needs saving ---
456
457 LDR R14,sx__flags ;Load my flags word
458 TST R14,#sxFlag__safe ;Is the flag set?
459 BNE %90sx__okToQuit ;Yes -- then return OK
460
461 ; --- Now ask the user before we go any further ---
462
463 ADR R0,sx__quitMsg ;Point to the message
464 BL msgs_lookup ;Translate into English
465 ADR R1,sx__quitButts ;Point to button block
466 BL warning ;Ask the user nicely
467 BCS %90sx__okToQuit ;If OK, return this
468
469 LDMFD R13!,{R0,R1,R14} ;Restore registers
470 BICS PC,R14,#C_flag ;And return not OK
471
472 90sx__okToQuit LDMFD R13!,{R0,R1,R14} ;Restore registers
473 ORRS PC,R14,#C_flag ;And return OK
474
475 sx__quitButts BUTTON "sxQTB"
476 BCANCEL
477 BUTEND
478
479 sx__quitMsg DCB "sxOTQ",0
480
481 LTORG
482
483 ;----- Dialogue box handling ------------------------------------------------
484
485 ; --- sx__showDbox ---
486 ;
487 ; On entry: --
488 ;
489 ; On exit: --
490 ;
491 ; Use: Opens the main dialogue box, and sets it up.
492
493 sx__showDbox ROUT
494
495 STMFD R13!,{R0-R3,R14} ;Save some registers
496 LDR R0,sx__dbox ;Load dialogue box handle
497 CMP R0,#0 ;Is the dialogue box open?
498 BNE %80sx__showDbox ;Yes -- just bring it forward
499
500 ; --- Create the dialogue box ---
501
502 ADR R0,sx__dbName ;Point to the dialogue name
503 BL dbox_create ;Create the dialogue box
504 BVS %90sx__showDbox ;If failed, tidy up
505 STR R0,sx__dbox ;Store the new handle
506
507 ADR R1,sx__dbHandler ;Point to the handler
508 ADR R2,sx__config ;Point to config buffer
509 MOV R3,R12 ;Pass R12 pointer on
510 BL dbox_eventHandler ;Set up the event handler
511
512 ADR R1,sx__dbControls ;Point to dbx defs block
513 BL dbx_declare ;Set up the controls
514 BL sx__dbReset ;Reset the dialogue settings
515
516 ; --- Finally, display the dialogue on-screen ---
517
518 80sx__showDbox MOV R1,#dbOpen_current+dbOpen_persist
519 BL dbox_open ;Display the dialogue box
520 LDMFD R13!,{R0-R3,PC}^ ;And return to caller
521
522 ; --- Handle an error ---
523
524 90sx__showDbox MOV R1,#1 ;Just an OK button
525 BL errorBox ;Display the error
526 LDMFD R13!,{R0-R3,PC}^ ;And return
527
528 sx__dbName DCB "setrix",0
529
530 sx__dbControls COLPOT sxIcon__cols+0,R10,sxConf__stdCols+0,0
531 COLPOT sxIcon__cols+1,R10,sxConf__stdCols+1,0
532 COLPOT sxIcon__cols+2,R10,sxConf__grpCols+0,0
533 COLPOT sxIcon__cols+3,R10,sxConf__grpCols+1,0
534 COLPOT sxIcon__cols+4,R10,sxConf__shdCols+0,0
535 COLPOT sxIcon__cols+5,R10,sxConf__shdCols+1,0
536 COLPOT sxIcon__cols+6,R10,sxConf__shgCols+0,0
537 COLPOT sxIcon__cols+7,R10,sxConf__shgCols+1,0
538
539 COLPOT sxIcon__hilite,R10,sxConf__hilite,0
540 COLPOT sxIcon__slab,R10,sxConf__slab,0
541
542 DBXEND
543
544 LTORG
545
546 ; --- sx__dbClose ---
547 ;
548 ; On entry: --
549 ;
550 ; On exit: --
551 ;
552 ; Use: Closes the dialogue box.
553
554 sx__dbClose ROUT
555
556 STMFD R13!,{R0,R14} ;Save some registers
557 LDR R0,sx__dbox ;Load the dialogue handle
558 BL dbox_writePos ;Save the position back
559 BL dbox_destroy ;Get rid of the dialogue
560 MOV R14,#0 ;Clear the handle in wspace
561 STR R14,sx__dbox ;Store that away
562 LDMFD R13!,{R0,PC}^ ;And return to caller
563
564 LTORG
565
566 ; --- sx__dbHandler ---
567 ;
568 ; On entry: R0 == dialogue box event code
569 ; R1-R7 == dependent on the event
570 ;
571 ; On exit: --
572 ;
573 ; Use: Handles events in the main dialogue box.
574
575 sx__dbHandler ROUT
576
577 CMP R0,#sxIcon__ok ;Is this an OK event?
578 CMPNE R0,#dbEvent_OK ;Check for a return press
579 BEQ sx__dbOK ;Yes -- handle the event
580
581 CMP R0,#sxIcon__save ;Is it the save icon?
582 BEQ sx__dbSave ;Yes -- handle that
583
584 CMP R0,#sxIcon__cancel ;Is this a cancel event
585 CMPNE R0,#dbEvent_cancel ;Check for an escape
586 BEQ sx__dbCancel ;Yes -- handle it
587
588 CMP R0,#dbEvent_load ;Is it a load event
589 CMPNE R0,#dbEvent_save ;Or a save -- I don't mind
590 BEQ sx__load ;Load the file
591
592 CMP R0,#dbEvent_help ;Is it a help event?
593 BEQ sx__dbHelp ;Yes -- give some help then
594
595 MOVS PC,R14 ;Otherwise, do nothing
596
597 ; --- Handle a click on the OK button ---
598
599 sx__dbOK STMFD R13!,{R0-R2,R14} ;Save some registers
600 MOV R2,R1 ;Remember this value
601 LDR R0,sx__dbox ;Load the dialogue handle
602 MOV R1,#sxIcon__ok ;Get the icon handle
603 BL dbox_slab ;Pop the icon in
604 BL sx__dbRead ;Read the icon settings
605 TST R2,#1 ;Is the adjust button down?
606 BLEQ sx__dbClose ;Maybe close the dialogue
607 BL dbox_unslab ;Unslab the button
608 LDMFD R13!,{R0-R2,PC}^ ;And return to caller
609
610 ; --- Handle a click on the Save button ---
611
612 sx__dbSave STMFD R13!,{R0,R1,R14} ;Save some registers
613 LDR R0,sx__dbox ;Load the dialogue handle
614 MOV R1,#sxIcon__save ;Get the icon handle
615 BL dbox_slab ;Pop the icon in
616 BL sx__dbRead ;Read the icon settings
617 BL sx__save ;Start the save box
618 BL dbox_unslab ;Unslab the button
619 LDMFD R13!,{R0,R1,PC}^ ;And return to caller
620
621 ; --- Handle a click on the cancel button ---
622
623 sx__dbCancel STMFD R13!,{R0-R2,R14} ;Save some registers
624 MOV R2,R1 ;Remember this value
625 LDR R0,sx__dbox ;Load the dialogue handle
626 MOV R1,#sxIcon__cancel ;Get the icon handle
627 BL dbox_slab ;Pop the icon in
628
629 ADD R0,R10,#sxConf__flags ;Point past the magic number
630 SWI Sculptrix_ReadConfig ;Read the config back
631
632 TST R2,#1 ;Is the adjust button down?
633 BLEQ sx__dbClose ;Maybe close the dialogue
634 BLNE sx__dbReset ;Maybe reset the settings
635
636 BL dbox_unslab ;Unslab the button
637 LDMFD R13!,{R0-R2,PC}^ ;And return to caller
638
639 ; --- Give some help to a user ---
640
641 sx__dbHelp STMFD R13!,{R0,R14} ;Save some registers
642 ADR R0,sx__dbHelpTag ;Point to the message tag
643 BL msgs_lookup ;Translate the message
644 BL help_add ;Add it to the help message
645 BL dbox_help ;Read help from an icon
646 LDMFD R13!,{R0,PC}^ ;Return when done
647
648 sx__dbHelpTag DCB "sxhDB",0
649
650 LTORG
651
652 ; --- sx__dbReset ---
653 ;
654 ; On entry: R0 == dialogue box handle
655 ; R10 == pointer to config buffer
656 ;
657 ; On exit: --
658 ;
659 ; Use: Resets the settings shown in the dialogue box.
660
661 sx__dbReset ROUT
662
663 STMFD R13!,{R0-R2,R14} ;Save some registers
664
665 ; --- Do the colour box ---
666
667 LDR R0,sx__dbox ;Load the dialogue handle
668 ADR R2,sx__dbxList ;Point to the icon number tbl
669 00 LDRB R1,[R2],#1 ;Load the next number out
670 CMP R1,#&FF ;Is this the end?
671 BLNE dbx_update ;No -- update the icon
672 BNE %b00 ;And loop back
673
674 ; --- Set the radio buttons ---
675
676 LDR R14,[R10,#sxConf__flags] ;Load the flags word
677 TST R14,#1 ;Is the `Acorn style' bit on?
678 MOVEQ R1,#sxIcon__ccGrp ;No -- turn on CC icon
679 MOVNE R1,#sxIcon__acGrp ;Yes -- turn on Acorn icon
680 BL dbox_radio ;Select the right one
681
682 LDMFD R13!,{R0-R2,PC}^ ;And return to caller
683
684 sx__dbxList DCB sxIcon__cols+0
685 DCB sxIcon__cols+1
686 DCB sxIcon__cols+2
687 DCB sxIcon__cols+3
688 DCB sxIcon__cols+4
689 DCB sxIcon__cols+5
690 DCB sxIcon__cols+6
691 DCB sxIcon__cols+7
692 DCB sxIcon__hilite
693 DCB sxIcon__slab
694 DCB &FF
695
696 LTORG
697
698 ; --- sx__dbRead ---
699 ;
700 ; On entry: R0 == dialogue box handle
701 ;
702 ; On exit: --
703 ;
704 ; Use: Reads the settings in the dialogue box, and maybe updates
705 ; the screen.
706
707 sx__dbRead ROUT
708
709 STMFD R13!,{R0,R1,R14} ;Save some registers
710 MOV R1,#sxIcon__acGrp ;Find the Acorn button
711 BL dbox_isSelected ;Is the icon selected?
712 LDR R14,[R10,#sxConf__flags] ;Load the flags word
713 ORRCS R14,R14,#1 ;If on, set the flag
714 BICCC R14,R14,#1 ;Otherwise clear it
715 STR R14,[R10,#sxConf__flags] ;Store the flags back
716 LDR R14,sx__flags ;Load the main flags word
717 BIC R14,R14,#sxFlag__safe ;We've modified the file
718 STR R14,sx__flags ;Save them back now
719 BL sx__update ;Send it off to the module
720 LDMFD R13!,{R0,R1,PC}^ ;Return to caller
721
722 LTORG
723
724 ; --- sx__update ---
725 ;
726 ; On entry: --
727 ;
728 ; On exit: --
729 ;
730 ; Use: Updates the Sculptrix configuration.
731
732 sx__update ROUT
733
734 STMFD R13!,{R0-R4,R14} ;Save some registers
735 ADD R0,R10,#sxConf__flags ;Find the main block
736 SWI Sculptrix_SetConfig ;Set the configuration
737 BCC %90sx__update ;If nothing changed, return
738 BL screen_getInfo ;Read the information
739 ADD R14,R0,#screen_width ;Find the dimensions
740 LDMIA R14,{R3,R4} ;Load them out
741 MOV R0,#-1 ;Redraw the whole screen
742 MOV R1,#0 ;Start at the left
743 MOV R2,#0 ;And the bottom
744 SWI Wimp_ForceRedraw ;Refresh the screen
745 90sx__update LDMFD R13!,{R0-R4,PC}^ ;And return to caller
746
747 LTORG
748
749 ;----- Data transfer --------------------------------------------------------
750
751 ; --- sx__setFilename ---
752 ;
753 ; On entry: R0 == pointer to filename, or 0
754 ;
755 ; On exit: --
756 ;
757 ; Use: Sets the filename used for saving.
758
759 sx__setFilename ROUT
760
761 STMFD R13!,{R0-R2,R14} ;Save some registers
762 CMP R0,#0 ;Do we want the default?
763 ADREQL R0,sx__confFile ;Yes -- use that then
764 ADR R1,sx__filename ;Point to output buffer
765 MOV R2,#256 ;Size of the buffer
766 ORR R2,r2,#&C0000000 ;Suppress nasty transforms
767 SWI OS_GSTrans ;Do the copy
768 LDMFD R13!,{R0-R2,PC}^ ;And return to caller
769
770 LTORG
771
772 ; --- sx__replace ---
773 ;
774 ; On entry: R0 == pointer to filename
775 ; R1 == safeness flag
776 ; R2 == pointer to old filename, or 0
777 ;
778 ; On exit: CS if we can replace the file
779 ;
780 ; Use: Finds out if it's safe to replace a file.
781
782 sx__replace ROUT
783
784 STMFD R13!,{R0-R2,R14} ;Save some registers
785 CMP R1,#0 ;Is the file safe?
786 BEQ %90sx__replace ;No -- then it's OK
787
788 MOVS R1,R2 ;Point to old filename
789 BEQ %f00 ;If none, we must ask
790 BL str_icmp ;Compare the strings
791 BEQ %90sx__replace ;If they match, carry on
792
793 00 BL res_exists ;Does the file exist?
794 BCC %90sx__replace ;No -- then we can proceed
795
796 MOV R2,R0 ;Point to the filename
797 ADR R0,sx__replMsg ;Point to message skeleton
798 BL msgs_lookup ;Translate that for me
799 BL str_buffer ;Find a handy buffer
800 BL str_subst ;And build me a message
801 ADR R1,sx__replButts ;Point to buttons
802 BL warning ;Ask the user about this
803 BCS %90sx__replace ;OK -- carry on then
804
805 LDMFD R13!,{R0-R2,R14} ;Restore registers
806 BICS PC,R14,#C_flag ;And say we mustn't do this
807
808 90sx__replace LDMFD R13!,{R0-R2,R14} ;Restore registers
809 ORRS PC,R14,#C_flag ;And say we can carry on
810
811 sx__replButts BUTTON "sxRPLB"
812 BCANCEL
813 BUTEND
814
815 sx__replMsg DCB "sxRPLF",0
816
817 LTORG
818
819 ; --- sx__save ---
820 ;
821 ; On entry: --
822 ;
823 ; On exit: --
824 ;
825 ; Use: Starts a save operation.
826
827 sx__save ROUT
828
829 STMFD R13!,{R0-R5,R14} ;Save some registers
830 MOV R0,#sxConf__size ;Size of the block
831 LDR R1,=&FFD ;Get the filetype (data)
832 ADR R2,sx__filename ;Point to filename buffer
833 ADR R3,sx__savers ;Point to saver block
834 MOV R4,R10 ;Point to block to save
835 MOV R5,R12 ;Pass workspace along too
836 BL saveAs ;Save the file then
837 BVS %80sx__save ;If it failed, tidy up
838 LDR R14,sx__flags ;Load our flags word
839 ORR R14,R14,#sxFlag__saving ;Set the saving flag
840 STR R14,sx__flags ;Save the flags back
841 B %90sx__save ;And return to caller
842
843 80sx__save MOV R1,#1 ;If it failed, get an OK box
844 BL errorBox ;And report the error
845 90sx__save LDMFD R13!,{R0-R5,PC}^ ;Return when finished
846
847 sx__savers DCB "sxSVT",0
848 B sx__svClose
849 B sx__svFile
850 B sx__svSend
851 B sx__svDone
852 B sx__svFail
853
854 LTORG
855
856 ; --- sx__svClose ---
857 ;
858 ; On entry: --
859 ;
860 ; On exit: --
861 ;
862 ; Use: Notes that the dialogue box has been closed.
863
864 EXPORT sx__svClose
865 sx__svClose ROUT
866
867 STMFD R13!,{R14} ;Save a register
868 LDR R14,sx__flags ;Load our flags word
869 BIC R14,R14,#sxFlag__saving ;Clear the saving flag
870 STR R14,sx__flags ;Save the flags back
871 LDMFD R13!,{PC}^ ;And return to caller
872
873 LTORG
874
875 ; --- sx__svFile ---
876 ;
877 ; On entry: R0 == pointer to filename
878 ; R1 == safeness flag
879 ;
880 ; On exit: May return an error
881 ;
882 ; Use: Saves the configuration to a file.
883
884 sx__svFile ROUT
885
886 STMFD R13!,{R0-R5,R14} ;Save some registers
887 ADR R2,sx__filename ;Point to current name
888 BL sx__replace ;Make sure we can replace
889 MOVCC R0,#0 ;If not, get null error
890 BCC %90sx__svFile ;And skip onwards
891
892 MOV R1,R0 ;Point to the filename
893 MOV R0,#10 ;Save whole file, please
894 LDR R2,=&FFD ;Get the filetype
895 MOV R4,R10 ;Point to the file info
896 ADD R5,R4,#sxConf__size ;Get the size information
897 SWI XOS_File ;Save the file, please
898 BVS %90sx__svFile ;If failed, skip on
899 LDMFD R13!,{R0-R5,PC}^ ;Return to caller
900
901 90sx__svFile ADD R13,R13,#4 ;Don't restore R0
902 LDMFD R13!,{R1-R5,PC} ;Restore other registers
903
904 LTORG
905
906 ; --- sx__svSend ---
907 ;
908 ; On entry: --
909 ;
910 ; On exit: R0 == pointer to base
911 ; R1 == length of data
912 ; CS if this is the last block
913 ;
914 ; Use: Sends data via RAM transfer.
915
916 sx__svSend ROUT
917
918 MOV R0,R10 ;Point to the data
919 MOV R1,#sxConf__size ;Get the size of the data
920 ORRS PC,R14,#C_flag ;And return with C set
921
922 LTORG
923
924 ; --- sx__svDone ---
925 ;
926 ; On entry: R0 == pointer to filename, if file is safe
927 ; R1 == safeness flag
928 ;
929 ; On exit: --
930 ;
931 ; Use: Sets up various nice things, if the file is saved properly.
932
933 sx__svDone ROUT
934
935 CMP R1,#0 ;Is the file safe?
936 MOVEQS PC,R14 ;No -- do nothing then
937
938 STMFD R13!,{R1,R14} ;Save some registers
939 BL sx__setFilename ;Change the filename
940 LDR R14,sx__flags ;Load the flags word
941 ORR R14,R14,#sxFlag__safe ;The file is safe, now
942 STR R14,sx__flags ;Store the flags back
943 LDMFD R13!,{R1,PC}^ ;Return when done
944
945 LTORG
946
947 ; --- sx__svFail ---
948 ;
949 ; On entry: R0 == pointer to error, or 0
950 ;
951 ; On exit: --
952 ;
953 ; Use: Tidies up after a botched save.
954
955 sx__svFail ROUT
956
957 CMP R0,#0 ;Is there something here?
958 MOVEQS PC,R14 ;No -- return then
959
960 STMFD R13!,{R0-R2,R14} ;Save some registers
961 ADD R2,R0,#4 ;Point to error text
962 ADR R0,sx__svError ;Point to a skeleton thing
963 BL msgs_error ;Translate the error
964 MOV R1,#1 ;Just an OK box, please
965 BL errorBox ;Report the error
966 LDMFD R13!,{R0-R2,PC}^ ;And return to caller
967
968 sx__svError DCD 1
969 DCB "sxSVERR",0
970
971 LTORG
972
973 ; --- sx__load ---
974 ;
975 ; On entry: --
976 ;
977 ; On exit: --
978 ;
979 ; Use: Starts a load operation for a configuration file.
980
981 sx__load ROUT
982
983 STMFD R13!,{R0-R2,R14} ;Save some registers
984
985 ; --- Make sure we're not the saver ---
986
987 LDR R14,sx__flags ;Load the flags word
988 TST R14,#sxFlag__saving ;Are we the saver?
989 BNE %80sx__load ;Yes -- oops
990
991 ; --- Start the load operation ---
992
993 ADR R0,sx__loaders ;Point to loaders block
994 MOV R1,R10 ;Pass data pointer
995 MOV R2,R12 ;Pass workspace in R12
996 BL load ;Start the load operation
997 B %90sx__load ;And return to caller
998
999 ; --- Report error about saving into ourselves ---
1000
1001 80sx__load ADR R0,sx__cantSave ;Point to the error
1002 BL msgs_error ;Translate the nastygram
1003 MOV R1,#1 ;Just an OK button, please
1004 BL errorBox ;Report the error
1005 90sx__load LDMFD R13!,{R0-R2,PC}^ ;Return when done
1006
1007 sx__cantSave DCD 1
1008 DCB "sxCSI",0
1009
1010 sx__loaders B sx__ldInitBuf
1011 B load_killBuf
1012 B load_extendBuf
1013 B load_doneBuf
1014 B sx__ldFile
1015 B sx__ldDone
1016 B sx__ldFail
1017
1018 LTORG
1019
1020 ; --- sx__ldInitBuf ---
1021 ;
1022 ; On entry: R0 == pointer to `filename'
1023 ; R1 == extimated size
1024 ; R2 == 0
1025 ;
1026 ; On exit: R0 == pointer to buffer base
1027 ; R1 == pointer to buffer limit
1028 ; R2 == pointer to anchor
1029 ;
1030 ; Use: Creates a buffer for the load job.
1031
1032 sx__ldInitBuf ROUT
1033
1034 MOV R2,#0 ;Clear the flex anchor
1035 STR R2,sx__anchor ;Store this over the top
1036 ADR R2,sx__anchor ;Point to the anchor
1037 B load_initBuf ;And initialise the buffer
1038
1039 LTORG
1040
1041 ; --- sx__ldFile ---
1042 ;
1043 ; On entry: R0 == pointer to `filename'
1044 ; R1 == pointer to real filename
1045 ; R2 == safeness indicator
1046 ;
1047 ; On exit: --
1048 ;
1049 ; Use: Loads a file into a buffer.
1050
1051 sx__ldFile ROUT
1052
1053 STMFD R13!,{R0,R2,R14} ;Save some registers
1054 MOV R2,#0 ;Clear the flex anchor
1055 STR R2,sx__anchor ;Store this over the top
1056 ADR R2,sx__anchor ;Point to the anchor
1057 BL load_file ;Load the file, please
1058 STRVS R0,[R13,#0] ;If failed, return error
1059 LDMFD R13!,{R0,R2,PC} ;And return to caller
1060
1061 LTORG
1062
1063 ; --- sx__ldDone ---
1064 ;
1065 ; On entry: R0 == pointer to `filename'
1066 ; R1 == safeness indicator
1067 ;
1068 ; On exit: --
1069 ;
1070 ; Use: Handles a newly loaded file.
1071
1072 sx__ldDone ROUT
1073
1074 STMFD R13!,{R0-R2,R14} ;Save some registers
1075 LDR R1,sx__anchor ;Load the base of the file
1076 LDR R2,[R1,#sxConf__magic] ;Load the first word out
1077 LDR R14,sx__magic ;Load the magic number
1078 CMP R2,R14 ;Do these match up?
1079 BNE %80sx__ldDone ;No -- complain then
1080
1081 ; --- Accept the data from the file ---
1082
1083 ADR R0,sx__config ;Point to my config buffer
1084 MOV R2,#sxConf__size ;Get the block size
1085 BL fastMove ;Copy the data over
1086
1087 ADR R0,sx__anchor ;Point to the anchor
1088 BL flex_free ;Don't want it any more
1089
1090 ; --- Change information about the file ---
1091
1092 LDR R0,[R13,#0] ;Load the filename used
1093 BL sx__setFilename ;Set this up nicely
1094 LDR R14,sx__flags ;Load the flags word
1095 ORR R14,R14,#sxFlag__safe ;The file is safe, now
1096 STR R14,sx__flags ;Store the flags back
1097
1098 ; --- Update the dialogue box and screen ---
1099
1100 LDR R0,sx__dbox ;Load the dialogue handle
1101 CMP R0,#0 ;Is it defined?
1102 BLNE sx__dbReset ;Yes -- reset the settings
1103 BL sx__update ;And update Sculptrix too
1104 B %90sx__ldDone ;Finally return to caller
1105
1106 ; --- Not all was well with the world ---
1107
1108 80sx__ldDone ADR R0,sx__anchor ;Point to the anchor
1109 BL flex_free ;Don't want it any more
1110 ADR R0,sx__badConfig ;Point to error block
1111 BL msgs_error ;Translate the message
1112 MOV R1,#1 ;Just an OK box, please
1113 BL errorBox ;And report the error
1114
1115 90sx__ldDone LDMFD R13!,{R0-R2,PC}^ ;Return when done
1116
1117 sx__badConfig DCD 1
1118 DCB "sxBDCFG",0
1119
1120 LTORG
1121
1122 ; --- sx__ldFail ---
1123 ;
1124 ; On entry: R0 == pointer to error
1125 ;
1126 ; On exit: --
1127 ;
1128 ; Use: Reports errors after a botched load.
1129
1130 sx__ldFail ROUT
1131
1132 CMP R0,#0 ;Is there anything to do?
1133 MOVEQS PC,R14 ;No -- return then
1134
1135 STMFD R13!,{R0-R2,R14} ;Save some registers
1136 ADD R2,R0,#4 ;Point to the error text
1137 ADR R0,sx__ldErr ;Point to error block
1138 BL msgs_error ;Translate the error
1139 MOV R1,#1 ;Report with an OK box
1140 BL errorBox ;Report it to the user
1141 LDMFD R13!,{R0-R2,PC}^ ;And return to caller
1142
1143 sx__ldErr DCD 1
1144 DCB "sxLDERR",0
1145
1146 LTORG
1147
1148 ;----- That's all, folks ----------------------------------------------------
1149
1150 END