chiark / gitweb /
JPEG support and other fixes from Nick Clark
[ssr] / StraySrc / Libraries / Sapphire / s / libOpts
1 ;
2 ; libOpts.s
3 ;
4 ; Allow options for library units to be declared
5 ;
6 ; © 1994-1998 Straylight
7 ;
8
9 ;----- Licensing note -------------------------------------------------------
10 ;
11 ; This file is part of Straylight's Sapphire library.
12 ;
13 ; Sapphire 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 ; Sapphire 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 Sapphire.  If not, write to the Free Software Foundation,
25 ; 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
27 ;----- Standard header ------------------------------------------------------
28
29                 GET     libs:header
30                 GET     libs:swis
31
32                 GET     libs:stream
33
34 ;----- External dependencies ------------------------------------------------
35
36                 GET     sapphire:sapphire
37                 GET     sapphire:suballoc
38
39 ;----- Main code ------------------------------------------------------------
40
41                 AREA    |Sapphire$$Code|,CODE,READONLY
42
43 ; --- libOpts_register ---
44 ;
45 ; On entry:     R0 == address of an options block
46 ;
47 ; On exit:      --
48 ;
49 ; Use:          Adds the block given to the library options.
50
51                 EXPORT  libOpts_register
52 libOpts_register ROUT
53
54                 STMFD   R13!,{R0,R1,R12,R14}    ;Save some registers
55                 WSPACE  lo__wSpace              ;Locate my workspace
56
57                 BL      sub_init                ;Awaken suballoc just in case
58                 MOV     R1,R0                   ;Look after the block addr
59                 MOV     R0,#8                   ;Allocate a small link block
60                 BL      sub_alloc               ;Try to allocate memory
61                 LDMVSFD R13!,{R0,R1,R12,PC}^    ;If it failed, don't bother
62
63                 STR     R1,[R0,#0]              ;Remember this block pointer
64                 LDR     R14,lo__head            ;Load the current list head
65                 STR     R14,[R0,#4]             ;Save this as the next link
66                 STR     R0,lo__head             ;And save new list head
67                 LDMFD   R13!,{R0,R1,R12,PC}^    ;And return to caller
68
69                 LTORG
70
71 ; --- libOpts_find ---
72 ;
73 ; On entry:     R0 == magic marker word
74 ;
75 ; On exit:      CS if found, and
76 ;                 R0 == address of options block
77 ;               else CC, and
78 ;                 R0 corrupted
79 ;
80 ; Use:          Tries to find an option with the given marker, which will
81 ;               normally be a four-character text string.  The first match
82 ;               found will be returned.  The options blocks are searched in
83 ;               reverse order of registration (i.e. blocks registered later
84 ;               will override blocks registered reviously).
85
86                 EXPORT  libOpts_find
87 libOpts_find    ROUT
88
89                 STMFD   R13!,{R1-R3,R12,R14}    ;Save some registers away
90                 WSPACE  lo__wSpace              ;Find my workspace
91                 MOV     R2,R0                   ;Look after the marker
92                 LDR     R1,lo__head             ;Load the list head block
93
94                 ; --- Scan through the list ---
95
96 10libOpts_find  CMP     R1,#0                   ;Reached the end yet?
97                 BEQ     %50libOpts_find         ;Yes -- return to caller
98                 LDMIA   R1,{R0,R1}              ;Load the block ptr and link
99
100                 ; --- See if we can find it in here ---
101
102 20libOpts_find  LDMIA   R0!,{R3,R14}            ;Load marker and size word
103                 CMP     R2,R3                   ;Does this match up?
104                 BEQ     %40libOpts_find         ;Yes -- found it then
105                 CMP     R3,#-1                  ;Is this the block end?
106                 ADDNE   R0,R0,R14               ;No -- move on to next item
107                 BNE     %20libOpts_find         ;And loop round again
108                 B       %10libOpts_find         ;Try the next options block
109
110                 ; --- Found a match ---
111
112 40libOpts_find  LDMFD   R13!,{R1-R3,R12,R14}    ;Restore registers
113                 ORRS    PC,R14,#C_flag          ;Return successfully
114
115                 ; --- Failed to find a match ---
116
117 50libOpts_find  LDMFD   R13!,{R1-R3,R12,R14}    ;Restore registers
118                 BICS    PC,R14,#C_flag          ;Return unsuccessfully
119
120                 LTORG
121
122 lo__wSpace      DCD     0
123
124 ;----- Workspace ------------------------------------------------------------
125
126                 ^       0,R12
127 lo__wStart      #       0
128
129 lo__head        #       4                       ;Base of the options list
130
131 lo__wSize       EQU     {VAR}-lo__wStart
132
133                 AREA    |Sapphire$$LibData|,CODE,READONLY
134
135                 DCD     lo__wSize
136                 DCD     lo__wSpace
137                 DCD     0
138                 DCD     0
139
140 ;----- That's all, folks ----------------------------------------------------
141
142                 END