4 ; Allow options for library units to be declared
6 ; © 1994-1998 Straylight
9 ;----- Licensing note -------------------------------------------------------
11 ; This file is part of Straylight's Sapphire library.
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)
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.
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.
27 ;----- Standard header ------------------------------------------------------
34 ;----- External dependencies ------------------------------------------------
39 ;----- Main code ------------------------------------------------------------
41 AREA |Sapphire$$Code|,CODE,READONLY
43 ; --- libOpts_register ---
45 ; On entry: R0 == address of an options block
49 ; Use: Adds the block given to the library options.
51 EXPORT libOpts_register
54 STMFD R13!,{R0,R1,R12,R14} ;Save some registers
55 WSPACE lo__wSpace ;Locate my workspace
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
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
71 ; --- libOpts_find ---
73 ; On entry: R0 == magic marker word
75 ; On exit: CS if found, and
76 ; R0 == address of options block
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).
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
94 ; --- Scan through the list ---
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
100 ; --- See if we can find it in here ---
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
110 ; --- Found a match ---
112 40libOpts_find LDMFD R13!,{R1-R3,R12,R14} ;Restore registers
113 ORRS PC,R14,#C_flag ;Return successfully
115 ; --- Failed to find a match ---
117 50libOpts_find LDMFD R13!,{R1-R3,R12,R14} ;Restore registers
118 BICS PC,R14,#C_flag ;Return unsuccessfully
124 ;----- Workspace ------------------------------------------------------------
129 lo__head # 4 ;Base of the options list
131 lo__wSize EQU {VAR}-lo__wStart
133 AREA |Sapphire$$LibData|,CODE,READONLY
140 ;----- That's all, folks ----------------------------------------------------