4 ; Setup program for Sculptrix
6 ; © 1995-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 written to accompany Sculptrix 2.00
33 ;----- Standard header ------------------------------------------------------
40 ;----- External dependencies ------------------------------------------------
44 GET sapphire:defHandler
59 GET sapphire:resources
66 GET sapphire:choices.choices
68 GET sapphire:dbx.colourPot
71 GET sapphire:xfer.load
72 GET sapphire:xfer.save
73 GET sapphire:xfer.saveAs
78 ;----- Icon handles ---------------------------------------------------------
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
89 ;----- Configuration blocks -------------------------------------------------
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
103 ;----- Workspace ------------------------------------------------------------
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
115 sx__wSize EQU {VAR}-sx__wStart
117 sxFlag__safe EQU (1<<0) ;File has been saved
118 sxFlag__saving EQU (1<<1) ;We're saving a file
120 ;----- Main code ------------------------------------------------------------
122 AREA |Client$$Code|,CODE,READONLY
129 ; On exit: Via OS_Exit
131 ; Use: Starts up the application.
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
143 BL seh_throwErrors ;Throw errors at ne, please
144 BL report_catchAll ;Install last error handler
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
153 sx__appName DCB "Setrix",0
157 ; --- sx__preInit ---
161 ; On exit: R0-R10 corrupted
163 ; Use: Does any initialisation required before Sapphire is started,
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
179 ; On exit: R0-R10 corrupted
181 ; Use: Initialises the rest of the application.
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
194 ; --- sx__initWork ---
198 ; On exit: R0-R10 corrupted
200 ; Use: Sets up the workspace.
204 STMFD R13!,{R14} ;Save a register
206 ; --- Set up some odd bits ---
208 MOV R14,#0 ;Clear the handle
209 STR R14,sx__dbox ;Store in the workspace
211 MOV R14,#sxFlag__safe ;The file is safe currently
212 STR R14,sx__flags ;Store the flags away
214 ; --- Set up default filename ---
216 MOV R0,#0 ;Use a default filename
217 BL sx__setFilename ;Set the filename, please
219 ; --- Set up the config buffer ---
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
230 ; --- sx__loadConf ---
234 ; On exit: R0-R10 corrupted
236 ; Use: Loads the default config file, if there is one.
240 STMFD R13!,{R14} ;Save the return address
242 MOV R0,#1 ;Enable use of `Choices'
243 BL choices_useChoices ;So do that, then
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
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
256 90sx__loadConf LDMFD R13!,{PC}^ ;And return to caller
259 sx__confFile DCB "Config",0
263 ; --- sx__iconBar ---
267 ; On exit: R0-R10 corrupted
269 ; Use: Creates the icon bar icon.
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
285 sx__ibSprite DCB "!setrix",0
289 ; --- sx__ibHandler ---
291 ; On entry: R0 == event code
295 ; Use: Handles events for the icon bar icon.
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
310 ; --- Display the icon bar menu ---
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
320 sx__ibMenu MENU "Setrix"
326 ; --- Give help to a user ---
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
334 sx__ibHelpTag DCB "sxhIB",0
338 ; --- sx__mnHandler ---
340 ; On entry: R0 == event code
341 ; R1 == menu item number
345 ; Use: Handles events on the program menu.
349 CMP R0,#mEvent_help ;A help request?
350 BEQ sx__mnHelp ;Yes -- give some help then
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
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
360 00 B sx__showInfo ;Show program information
361 B sx__quit ;Quit the application
363 ; --- Display the Info box ---
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
375 sx__purpose DCB "sxPUR",0
377 ; --- Try to quit the program ---
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
384 ; --- Give some help to the user ---
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
391 sx__mnHelpTag DCB "sxhMN",0
395 ; --- sx__unknowns ---
397 ; On entry: R0 == event code
398 ; R1 == pointer to event data
400 ; On exit: R2-R10 corrupted
403 ; Use: Handles unknown events. Specifically, it looks at PreQuit
404 ; messages, and asks the user if it's OK to quit.
408 CMP R0,#17 ;Is this a message?
409 CMPNE R0,#18 ;Check both types
410 MOVNES PC,R14 ;No -- ignore it then
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
416 ; --- Handle a PreQuit message ---
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
422 ; --- Acknowledge the message to prevent quitting ---
424 MOV R0,R11 ;Point to scratchpad
425 LDR R2,[R1,#0] ;Load the message size
426 BL fastMove ;Copy the message over
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
435 ; --- Now return, claiming the event ---
437 90sx__unknowns LDMFD R13!,{R0,R1,R14} ;Restore registers
438 ORRS PC,R14,#C_flag ;And return, claiming it
442 ; --- sx__okToQuit ---
446 ; On exit: CS if we're allowed to quit
448 ; Use: Ensures that we're allowed to quit. If we're in possession
449 ; of unsaved data, we ask the user first.
453 STMFD R13!,{R0,R1,R14} ;Save some registers
455 ; --- Check whether the data needs saving ---
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
461 ; --- Now ask the user before we go any further ---
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
469 LDMFD R13!,{R0,R1,R14} ;Restore registers
470 BICS PC,R14,#C_flag ;And return not OK
472 90sx__okToQuit LDMFD R13!,{R0,R1,R14} ;Restore registers
473 ORRS PC,R14,#C_flag ;And return OK
475 sx__quitButts BUTTON "sxQTB"
479 sx__quitMsg DCB "sxOTQ",0
483 ;----- Dialogue box handling ------------------------------------------------
485 ; --- sx__showDbox ---
491 ; Use: Opens the main dialogue box, and sets it up.
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
500 ; --- Create the dialogue box ---
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
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
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
516 ; --- Finally, display the dialogue on-screen ---
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
522 ; --- Handle an error ---
524 90sx__showDbox MOV R1,#1 ;Just an OK button
525 BL errorBox ;Display the error
526 LDMFD R13!,{R0-R3,PC}^ ;And return
528 sx__dbName DCB "setrix",0
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
539 COLPOT sxIcon__hilite,R10,sxConf__hilite,0
540 COLPOT sxIcon__slab,R10,sxConf__slab,0
546 ; --- sx__dbClose ---
552 ; Use: Closes the dialogue box.
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
566 ; --- sx__dbHandler ---
568 ; On entry: R0 == dialogue box event code
569 ; R1-R7 == dependent on the event
573 ; Use: Handles events in the main dialogue box.
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
581 CMP R0,#sxIcon__save ;Is it the save icon?
582 BEQ sx__dbSave ;Yes -- handle that
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
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
592 CMP R0,#dbEvent_help ;Is it a help event?
593 BEQ sx__dbHelp ;Yes -- give some help then
595 MOVS PC,R14 ;Otherwise, do nothing
597 ; --- Handle a click on the OK button ---
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
610 ; --- Handle a click on the Save button ---
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
621 ; --- Handle a click on the cancel button ---
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
629 ADD R0,R10,#sxConf__flags ;Point past the magic number
630 SWI Sculptrix_ReadConfig ;Read the config back
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
636 BL dbox_unslab ;Unslab the button
637 LDMFD R13!,{R0-R2,PC}^ ;And return to caller
639 ; --- Give some help to a user ---
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
648 sx__dbHelpTag DCB "sxhDB",0
652 ; --- sx__dbReset ---
654 ; On entry: R0 == dialogue box handle
655 ; R10 == pointer to config buffer
659 ; Use: Resets the settings shown in the dialogue box.
663 STMFD R13!,{R0-R2,R14} ;Save some registers
665 ; --- Do the colour box ---
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
674 ; --- Set the radio buttons ---
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
682 LDMFD R13!,{R0-R2,PC}^ ;And return to caller
684 sx__dbxList DCB sxIcon__cols+0
700 ; On entry: R0 == dialogue box handle
704 ; Use: Reads the settings in the dialogue box, and maybe updates
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
730 ; Use: Updates the Sculptrix configuration.
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
749 ;----- Data transfer --------------------------------------------------------
751 ; --- sx__setFilename ---
753 ; On entry: R0 == pointer to filename, or 0
757 ; Use: Sets the filename used for saving.
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
772 ; --- sx__replace ---
774 ; On entry: R0 == pointer to filename
775 ; R1 == safeness flag
776 ; R2 == pointer to old filename, or 0
778 ; On exit: CS if we can replace the file
780 ; Use: Finds out if it's safe to replace a file.
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
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
793 00 BL res_exists ;Does the file exist?
794 BCC %90sx__replace ;No -- then we can proceed
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
805 LDMFD R13!,{R0-R2,R14} ;Restore registers
806 BICS PC,R14,#C_flag ;And say we mustn't do this
808 90sx__replace LDMFD R13!,{R0-R2,R14} ;Restore registers
809 ORRS PC,R14,#C_flag ;And say we can carry on
811 sx__replButts BUTTON "sxRPLB"
815 sx__replMsg DCB "sxRPLF",0
825 ; Use: Starts a save operation.
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
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
847 sx__savers DCB "sxSVT",0
856 ; --- sx__svClose ---
862 ; Use: Notes that the dialogue box has been closed.
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
877 ; On entry: R0 == pointer to filename
878 ; R1 == safeness flag
880 ; On exit: May return an error
882 ; Use: Saves the configuration to a file.
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
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
901 90sx__svFile ADD R13,R13,#4 ;Don't restore R0
902 LDMFD R13!,{R1-R5,PC} ;Restore other registers
910 ; On exit: R0 == pointer to base
911 ; R1 == length of data
912 ; CS if this is the last block
914 ; Use: Sends data via RAM transfer.
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
926 ; On entry: R0 == pointer to filename, if file is safe
927 ; R1 == safeness flag
931 ; Use: Sets up various nice things, if the file is saved properly.
935 CMP R1,#0 ;Is the file safe?
936 MOVEQS PC,R14 ;No -- do nothing then
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
949 ; On entry: R0 == pointer to error, or 0
953 ; Use: Tidies up after a botched save.
957 CMP R0,#0 ;Is there something here?
958 MOVEQS PC,R14 ;No -- return then
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
979 ; Use: Starts a load operation for a configuration file.
983 STMFD R13!,{R0-R2,R14} ;Save some registers
985 ; --- Make sure we're not the saver ---
987 LDR R14,sx__flags ;Load the flags word
988 TST R14,#sxFlag__saving ;Are we the saver?
989 BNE %80sx__load ;Yes -- oops
991 ; --- Start the load operation ---
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
999 ; --- Report error about saving into ourselves ---
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
1010 sx__loaders B sx__ldInitBuf
1020 ; --- sx__ldInitBuf ---
1022 ; On entry: R0 == pointer to `filename'
1023 ; R1 == extimated size
1026 ; On exit: R0 == pointer to buffer base
1027 ; R1 == pointer to buffer limit
1028 ; R2 == pointer to anchor
1030 ; Use: Creates a buffer for the load job.
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
1041 ; --- sx__ldFile ---
1043 ; On entry: R0 == pointer to `filename'
1044 ; R1 == pointer to real filename
1045 ; R2 == safeness indicator
1049 ; Use: Loads a file into a buffer.
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
1063 ; --- sx__ldDone ---
1065 ; On entry: R0 == pointer to `filename'
1066 ; R1 == safeness indicator
1070 ; Use: Handles a newly loaded file.
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
1081 ; --- Accept the data from the file ---
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
1087 ADR R0,sx__anchor ;Point to the anchor
1088 BL flex_free ;Don't want it any more
1090 ; --- Change information about the file ---
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
1098 ; --- Update the dialogue box and screen ---
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
1106 ; --- Not all was well with the world ---
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
1115 90sx__ldDone LDMFD R13!,{R0-R2,PC}^ ;Return when done
1122 ; --- sx__ldFail ---
1124 ; On entry: R0 == pointer to error
1128 ; Use: Reports errors after a botched load.
1132 CMP R0,#0 ;Is there anything to do?
1133 MOVEQS PC,R14 ;No -- return then
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
1148 ;----- That's all, folks ----------------------------------------------------