4 ; Management of application's preferences file
9 ;----- Standard header ------------------------------------------------------
16 ;----- External dependencies ------------------------------------------------
25 GET sapphire:xfer.load
27 GET sapphire:choices.choices
29 ;----- Main code ------------------------------------------------------------
31 AREA |Sapphire$$Code|,CODE,READONLY
37 ; On exit: R0 == chunk handle of loaded preferences file
39 ; Use: Returns the chunk handle of the preferences file. You can
40 ; then claim your chunk of options from the preferences file
46 STMFD R13!,{R14} ;Save a register
47 WSPACE prefs__wSpace,R0 ;Find my workspace
48 LDR R0,[R0,#:INDEX:prefs__handle]
49 LDMFD R13!,{PC}^ ;And return to caller
55 ; On entry: R0 == pointer to application name
59 ; Use: Loads the application's preferences file.
64 STMFD R13!,{R0-R2,R12,R14} ;Save some registers
65 WSPACE prefs__wSpace ;Find my workspace
66 LDR R14,prefs__handle ;Get the prefs chunk file
67 CMP R14,#0 ;Is it already created?
68 LDMNEFD R13!,{R0-R2,R12,PC}^ ;Yes -- nothing doing
70 ; --- Initialise bits of the library ---
72 BL res_init ;So I can find resources
73 BL flex_init ;For memory management
74 BL alloc_init ;For memory management too
75 BL heap_init ;So that it doesn't get upset
77 ; --- Create a chunk file ---
79 BL chunk_create ;Create the file
80 SWIVS OS_GenerateError ;If it failed, take it badly
81 STR R0,prefs__handle ;Save that away for later
83 ; --- Now load the preferences file ---
85 ADR R0,prefs__file ;Point to leafname
86 MOV R1,R11 ;Find a spare buffer
87 BL choices_find ;Get a complete filename
88 LDMCCFD R13!,{R0-R2,R12,PC}^ ;If file not there, stop
89 MOV R1,R0 ;Point to this name
90 SUB R13,R13,#4 ;Make a flex anchor
91 MOV R2,R13 ;Point to this anchor
92 BL load_file ;And load the file into it
93 BVS %99prefs_init ;If it failed, tidy up
94 MOV R1,R13 ;Point to the anchor
95 LDR R0,prefs__handle ;Load the chunk file anchor
96 BL chunk_read ;Read the preferences file
98 ; --- Tidy up and return ---
100 MOV R0,R13 ;Point to the flex anchor
101 BL flex_free ;Free the file block
103 99 ADD R13,R13,#4 ;Clear up the stack space
104 LDMFD R13!,{R0-R2,R12,PC}^ ;And return to caller
106 prefs__file DCB "Choices",0
112 ;----- Workspace ------------------------------------------------------------
117 prefs__handle # 4 ;Handle of prefs chunk file
119 prefs__wSize EQU {VAR}-prefs__wStart
121 AREA |Sapphire$$LibData|,CODE,READONLY
128 ;----- That's all, folks ----------------------------------------------------