;
; roVersion.s
;
; Handling of the RISC OS version (MDW)
;
;  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.

;----- Standard header ------------------------------------------------------

		GET	libs:swis
		GET	libs:header

;----- External dependencies ------------------------------------------------

		GET	sapphire:sapphire

;----- Main code ------------------------------------------------------------

		AREA	|Sapphire$$Code|,CODE,READONLY

; --- rov_init ---
;
; On entry:	--
;
; On exit:	--
;
; Use:		Sets up the OS version in a cache.

		EXPORT	rov_init
rov_init	ROUT

		STMFD	R13!,{R0-R4,R12,R14}	;Save some registers away
		WSPACE	rov__wSpace		;Find my workspace pointer
		LDR	R14,rov__version	;Get the cached version
		CMP	R14,#0			;Is it set up yet?
		LDMNEFD	R13!,{R0-R4,R12,PC}^	;Yes -- return to caller

		; --- Work out the RISC OS version properly ---

		MOV	R0,#129			;Read key (or OS version) :-/
		MOV	R1,#0			;Want OS version
		MOV	R2,#255			;Still want OS version
		SWI	OS_Byte			;Read the version number

		ADR	R2,rov__verTable	;Point to my version table
		MOV	R0,#-1			;Start off with bad version
10rov_init	LDMIA	R2!,{R3,R4}		;Load the version numbers
		CMP	R3,R1			;Does this version match?
		MOVLE	R0,R4			;Yes -- use this version
		BGT	%10rov_init		;Otherwise continue search

		STR	R0,rov__version		;Save this version away
		LDMFD	R13!,{R0-R4,R12,PC}^	;Return to caller

rov__verTable	DCD	&A5,350
		DCD	&A4,310
		DCD	&A3,300
		DCD	&A2,201
		DCD	&A1,200
		DCD	0,0

rov__wSpace	DCD	0

		LTORG

; --- rov_version ---
;
; On entry:	--
;
; On exit:	R0 == current RISC OS version
;
; Use:		Returns the current operating system version number.

		EXPORT	rov_version
rov_version	ROUT

		STMFD	R13!,{R14}		;Save a register
		LDR	R0,rov__wSpace		;Find my workspace offset
		LDR	R14,sapph_workspace	;Find workspace base
		LDR	R0,[R0,R14]		;Load version number
		LDMFD	R13!,{PC}^		;Return to caller

		LTORG

;----- Workspace ------------------------------------------------------------

		^	0,R12
rov__wStart	#	0

rov__version	#	4			;Current OS version number

rov__wSize	EQU	{VAR}-rov__wStart

		AREA	|Sapphire$$LibData|,CODE,READONLY

		DCD	rov__wSize
		DCD	rov__wSpace
		DCD	0
		DCD	rov_init

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

		END
