*******************************************************************************
* 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
	
		section	localtest,code

Begin:		lea	DS(pc),a4		;varbase,usually allocate this!

*-------------- 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,(a4)			;save dosbase
		move.l	d0,a6			;d6=DOSBase
		jsr	_LVOOutput(a6)		;get output base
		move.l	d0,_DOSOutput-DS(a4)	;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-DS(a4)	;save locale base
		beq.s	NoCatalog

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

		clr.l	_CatalogBase-DS(a4)
		lea	CatalogeName(pc),a1
		suba.l	a0,a0
		suba.l	a2,a2
		move.l	_LocaleBase-DS(a4),a6
		CALL	OpenCatalogA		;open catalog...
		move.l	d0,_CatalogBase-DS(a4)	;save catalog base

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

NoCatalog:	moveq	#MSG_HELLO,d0		;string no.
		bsr	_GetString

;-------------> d0=string ptr
;               d1=string length..

		move.l	d0,d2			;str ptr
		move.l	d1,d3			;str length
		move.l	_DOSOutput-DS(a4),d1	;str output
		move.l	(a4),a6			;dosbase
		CALL	Write

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

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

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

		move.l	4.w,a6			;get execbase
		move.l	_LocaleBase-DS(a4),a1	;locale base
		CALL	CloseLibrary		;close locale library

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

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

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

******************************************************************************
* GetString: Gets a string from the locale catalogue...
* ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
* $Inputs:	d0.l = string no.
* $Outputs:	d0.l = string ptr
*		d1.l = string length
******************************************************************************
		
_GetString:	lea	Strings(pc),a1
		bra.s	FindString
StrLoop:	add.w	(a1)+,a1		;add strlen to str ptr
FindString:	cmp.l	(a1)+,d0		;str id, matched internal?
		bne.s	StrLoop	
		moveq	#0,d1
		move.w	(a1)+,d1		;d1=str length, a1=str ptr
		move.l	_CatalogBase-DS(a4),d2
		beq.s	Use_Internal
		move.l	d2,a0
		move.l	a6,-(sp)
		move.l	_LocaleBase-DS(a4),a6
		CALL	GetCatalogStr
		move.l	(sp)+,a6
		move.l	d0,a1
		move.l	d0,a0
getlen		tst.l	(a0)+
		bne.s	getlen
		subq.l	#1,a0
		sub.l	d0,a0
		move.l	a0,d1
		rts
Use_Internal:	move.l	a1,d0
		rts

DOSName:	dc.b	'dos.library',0
		even
LocaleName:	dc.b	'locale.library',0
		even
CatalogeName:	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

*-------------- Cataloge String Definitions..

Strings:	dc.l	MSG_HELLO			;String ID No.
		dc	str1end-str1			;String Length..
str1		dc.b	LF,'Hello World! (Internal Version!)',LF,LF,NULL
		even
str1end:
;		dc.l	MSG_GOODBYE			;String ID No.
;		dc	str2end-str2			;String Length..
;str2:		dc.b	LF,'Later dude!',LF,NULL
;		even
;str2end:

		end
