*******************************************************************************
* Locale Catalogues (Example Source - ASSEMBLY!)	 Written by 2-Cool/EX4!
* ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
* This example sources shows how to access the locale.library and use a locale
* catalogue from assembly. The source shows access of strings in a user defined
* catalogue for both the internal strings and ones from the users current local
* language setting..
*******************************************************************************
_LVOOutput		= -60
_LVOWrite		= -48
_LVOOpenLibrary		= -552
_LVOOldOpenLibrary	= -408
_LVOCloseLibrary	= -414
_LVOOpenCatalogA	= -150
_LVOGetCatalogStr	= -72
_LVOCloseCatalog	= -36
LF			= 10
NULL			= 0

*----------------------- Message number definitions..

MSG_HELLO		= 0
MSG_GOODBYE		= 1

CALL		macro
		jsr	_LVO\1(a6)
		endm
	
		incdir	"include:"
		include	"libraries/locale.i"

		section	localtest,code

Begin:	

*-------------- Open DOS Library & Get DOS Output

		move.l	4.w,a6			;get execbase
		lea	DOSName(pc),a1		;name of dos library
		CALL	OldOpenLibrary		;open dos
		move.l	d0,_DOSBase		;save dosbase
		move.l	d0,a6			;d6=DOSBase
		jsr	_LVOOutput(a6)		;get output base
		move.l	d0,_DOSOutput		;save output base

*-------------- Open Locale Library

		move.l	4.w,a6			;get execbase
		lea	LocaleName(pc),a1
		moveq	#38,d0
		CALL	OpenLibrary		;open locale library
		move.l	d0,_LocaleBase		;save locale base
		beq.s	NoCatalog

*-------------- Open Locale Catalogue..

		clr.l	_CatalogBase
		suba.l	a0,a0
		lea	CatalogName(pc),a1
		lea	CatalogTags(pc),a2	;catalogue tags
		move.l	_LocaleBase(pc),a6
		CALL	OpenCatalogA		;open catalog...
		move.l	d0,_CatalogBase		;save catalog base
;		beq.s	Catalog_Failed

*-------------- do example... write string to cli..

NoCatalog:	moveq	#MSG_HELLO,d0		;string no.
		lea	MSG_HELLO.DEF(pc),a1	;default string
		move.l	_CatalogBase(pc),a0	;a0.l = catalog
		move.l	_LocaleBase(pc),a6	;a6.l = localebase
		CALL	GetCatalogStr		;get string..

		move.l	d0,a0
		moveq	#-1,d3
getlen:		addq.l	#1,d3
		tst.b	(a0)+
		bne.s	getlen

		move.l	d0,d2			;str ptr
		move.l	_DOSOutput(pc),d1	;str output
		move.l	_DOSBase(pc),a6		;dosbase
		CALL	Write

*-------------- Close Locale catalogue

		move.l	_CatalogBase(pc),a0	;ptr to open catalogue
		move.l	_LocaleBase(pc),a6
		move.l	a6,d0			;locale library
		beq.s	no_locale		;if not open = no catalogue!
		CALL	CloseCatalog		;close locale catalogue...

*-------------- Close Locale Library

Catalog_Failed:	move.l	4.w,a6			;get execbase
		move.l	_LocaleBase(pc),a1	;locale base
		CALL	CloseLibrary		;close locale library

*-------------- Close DOS Base

no_locale:	move.l	4.w,a6			;get execbase
		move.l	_DOSBase(pc),a1		;dosbase
		CALL	CloseLibrary		;close dos-library

		moveq	#0,d0			;no return code..
		rts

CatalogTags:	dc.l	OC_Language,0			;_LangPref
		dc.l	OC_BuiltInLanguage,_LangBuilt	;no built in language!
		dc.l	TAG_DONE,0

_LangBuilt:	dc.b	'English',0
_LangPref:	dc.b	'Français',0
		even
MSG_HELLO.DEF:	dc.b	LF,'Hello World! (English Built-In Version)',LF,LF,0
		even		
DOSName:	dc.b	'dos.library',0
		even
LocaleName:	dc.b	'locale.library',0
		even
CatalogName:	dc.b	'hello.catalog',0
		even
DS:
_DOSBase:	ds.l	1		;dos base
_DOSOutput:	ds.l	1		;dos outputbase
_LocaleBase:	ds.l	1		;locale base
_CatalogBase:	ds.l	1		;cataloge ptr

		end
