;
; libOpts.sh
;
; Allow options for library units to be declared
;
;  1994-1998 Straylight
;

;----- Licensing note -------------------------------------------------------
;
; This file is part of Straylight's Sapphire library.
;
; Sapphire is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2, or (at your option)
; any later version.
;
; Sapphire is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with Sapphire.  If not, write to the Free Software Foundation,
; 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

;----- Overview -------------------------------------------------------------
;
; Functions provided:
;
;  libOpts_register
;  libOpts_find
;
; Macros provided:
;
;  LIBOPT
;  LOEND

		[	:LNOT::DEF:libOpts__dfn
		GBLL	libOpts__dfn

;+		LIB	sapphire:^.bsh.libOpts

; --- libOpts_register ---
;
; On entry:	R0 == address of an options block
;
; On exit:	--
;
; Use:		Adds the block given to the library options.

		IMPORT	libOpts_register

; --- libOpts_find ---
;
; On entry:	R0 == magic marker word
;
; On exit:	CS if found, and
;		  R0 == address of options block
;		else CC, and
;		  R0 corrupted
;
; Use:		Tries to find an option with the given marker, which will
;		normally be a four-character text string.  The first match
;		found will be returned.  The options blocks are searched in
;		reverse order of registration (i.e. blocks registered later
;		will override blocks registered reviously).

		IMPORT	libOpts_find

;----- Macros ---------------------------------------------------------------

		GBLA	lo__c
lo__c		SETA	0
		GBLL	lo__p
lo__p		SETL	{FALSE}

; --- Macro: LIBOPT ---
;
; Arguments:	name == name of this options subblock (4 characters)
;
; Use:		Sets up an options subblock with the given name.

		MACRO
$label		LIBOPT	$name
		ALIGN

		[	lo__p
lo__sz$lo__c	EQU	{PC}-lo__a$lo__c
		]
lo__c		SETA	lo__c+1

$label
		DCB	"$name"
		DCD	lo__sz$lo__c
lo__a$lo__c
lo__p		SETL	{TRUE}

		MEND

; --- Macro: LOEND ---
;
; Arguments:	--
;
; Use:		Terminates a library options block.

		MACRO
		LOEND
		ALIGN

		[	lo__p
lo__sz$lo__c	EQU	{PC}-lo__a$lo__c
		]
lo__c		SETA	lo__c+1
lo__p		SETL	{FALSE}

		DCD	-1

		MEND

		]

;----- That's all, folks ----------------------------------------------------

		END
