; Slayer - a desktop anti-virus for RISC OS
; Copyright (C) 1996 - 2000 Kiwi Software (UK)
;
; This program 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 of the License, or
; any later version.
;
; This program 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 this program; if not, write to the Free Software
; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
;
; info@kiwisoft.co.uk
; -------------------------------------------------------------------------


#name ^.HelpPicker
#type &ff8
#base &8000

			mov	r0, #70				; read/write country number
			mov	r1, #127			; read country
			swi	XOS_Byte			; call OS_Byte
			movvc	r3, r1				; r3 now = country number

			movvc	r1, #&43			; Service_International
			movvc	r2, #2
			;       r3 already filled in
			adrvc	r4, buffer			; pointer to buffer
			movvc	r5, #24				; 256 bytes long

			swivc	XOS_ServiceCall			; call the service
			bvs	noHelpError

			; right, r4 + r5 = pointer to after <Obey$Dir>.*territory*
			; copy the '.!Help' after it.

			add	r4, r4, r5			; add the offset to the base

			adr	r1, helpString			; -> '.!Help'
			adr	r10, obeyString			; -> end of helpString

._loop			ldrb	r2, [r1], #1			; load a byte, increase ptr by 1
			strb	r2, [r4], #1			; save a byte, increase ptr by 1
			teq	r1, r10				; has it reached the end of helpStr?
			bne	_loop				; if not, copy another byte

                        ; now we have a possible filename; check to see if the file exists.
                        ; if it doesn't; resort to <Obey$Dir>.UK.!Help

                        add	r1, r0, #10			; add 1 to skip '/'
                        mov	r0, #17				; reason code into r0
                        swi	XOS_File			; call OS_File
                        subvc	r0, r1, #10			; sub 1 to get back to '/'
                        swivc	OS_CLI				; execute the command line
                        swivc	XOS_Exit

			; right then; that help file doesn't exist; copy ukString into the buffer,
			; and execute that instead.

			adr	r1, ukString			; -> 'UK.!Help'
			adr	r2, buffer

._loop2			ldrb	r3, [r1], #1			; load a byte, increase ptr by 1
			strb	r3, [r2], #1			; save a byte, increase ptr by 1
			teq	r3, #0				; have we got to the null yet?
			bne	_loop2				; no, copy next byte

			;adr	r0, obeyString			; address of command line
			mov	r0, r10
			swi	XOS_CLI				; execute it
			swivc	XOS_Exit			; if no error; quit cleanly

.noHelpError

			adr	r0, noHelpFile			; there was an error...
			swi	OS_GenerateError		; tell the use there was no !Help

.noHelpFile		dcd	0
			dcb	"Unable to find a !Help file.",0
			align

.ukString		dcb "UK"
.helpString		dcb ".!Help",0
.obeyString		dcb "Filer_Run ", 60, "Obey$Dir", 62, ".Resources."
.buffer
