chiark / gitweb /
Initial revision
[ssr] / StraySrc / Libraries / Sapphire / choices / s / prefs
1 ;
2 ; choices.prefs.s
3 ;
4 ; Management of application's preferences file
5 ;
6 ; © 1995 Straylight
7 ;
8
9 ;----- Standard header ------------------------------------------------------
10
11                 GET     libs:header
12                 GET     libs:swis
13
14                 GET     libs:stream
15
16 ;----- External dependencies ------------------------------------------------
17
18                 GET     sapphire:alloc
19                 GET     sapphire:chunk
20                 GET     sapphire:flex
21                 GET     sapphire:heap
22                 GET     sapphire:res
23                 GET     sapphire:sapphire
24
25                 GET     sapphire:xfer.load
26
27                 GET     sapphire:choices.choices
28
29 ;----- Main code ------------------------------------------------------------
30
31                 AREA    |Sapphire$$Code|,CODE,READONLY
32
33 ; --- prefs_find ---
34 ;
35 ; On entry:     --
36 ;
37 ; On exit:      R0 == chunk handle of loaded preferences file
38 ;
39 ; Use:          Returns the chunk handle of the preferences file.  You can
40 ;               then claim your chunk of options from the preferences file
41 ;               using options_read.
42
43                 EXPORT  prefs_find
44 prefs_find      ROUT
45
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
50
51                 LTORG
52
53 ; --- prefs_init ---
54 ;
55 ; On entry:     R0 == pointer to application name
56 ;
57 ; On exit:      --
58 ;
59 ; Use:          Loads the application's preferences file.
60
61                 EXPORT  prefs_init
62 prefs_init      ROUT
63
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
69
70                 ; --- Initialise bits of the library ---
71
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
76
77                 ; --- Create a chunk file ---
78
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
82
83                 ; --- Now load the preferences file ---
84
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
97
98                 ; --- Tidy up and return ---
99
100                 MOV     R0,R13                  ;Point to the flex anchor
101                 BL      flex_free               ;Free the file block
102
103 99              ADD     R13,R13,#4              ;Clear up the stack space
104                 LDMFD   R13!,{R0-R2,R12,PC}^    ;And return to caller
105
106 prefs__file     DCB     "Choices",0
107
108                 LTORG
109
110 prefs__wSpace   DCD     0
111
112 ;----- Workspace ------------------------------------------------------------
113
114                 ^       0,R12
115 prefs__wStart   #       0
116
117 prefs__handle   #       4                       ;Handle of prefs chunk file
118
119 prefs__wSize    EQU     {VAR}-prefs__wStart
120
121                 AREA    |Sapphire$$LibData|,CODE,READONLY
122
123                 DCD     prefs__wSize
124                 DCD     prefs__wSpace
125                 DCD     0
126                 DCD     prefs_init
127
128 ;----- That's all, folks ----------------------------------------------------
129
130                 END