	include	ssmac.h		;Include macros and offsets
	include	libraries/mui_alt.i
	include	libraries/mui_asm.i
	include	libraries/mui_lib.i

GENERATE_DECLS	equ	1
GENERATE_ENV	equ	1
GENERATE_CODE	equ	1
GENERATE_LOCALE	equ	0

CALLINT	macro
	call	intuition,\1	;My macros doesn't have this macro
	endm

CALLEXEC	macro
	call	exec,\1
	endm

	start	;Start initialization

	get.l	muimasterbase,MUIMASTER_BASE

	IFNE	GENERATE_LOCALE   ; Generate following code only when user wants it.
	sub.l	a0,a0
	lea	catalog_name(pc),a1
	sub.l	a2,a2
	CALLLOCALE	OpenCatalogA
	lea	catalog(pc),a0
	move.l	d0,(a0)
	beq	no_catalog   ;This part of program have to print error message and jump to label 'cleanup'.
	ENDC	;GENERATE_LOCALE

	bsr	InitGUI
	errc.ne	<Cannot create GUI>	;Macro for conditional error

	DoMethod	WI_SpecialChars,#MUIM_Notify,#MUIA_Window_CloseRequest,#TRUE,App,#2,#MUIM_Application_ReturnID,#MUIV_Application_ReturnID_Quit

	seti	WI_SpecialChars,#MUIA_Window_Open,#TRUE	;Open window

	IFNE	GENERATE_ENV
main_loop	DoMethod	App,#MUIM_Application_Input,#signal
	tst.l	d0
	bne.s	1$
	move.l	signal(pc),d0
	CALLEXEC	Wait
	bra.s	main_loop
1$
	cmp.l	#MUIV_Application_ReturnID_Quit,d0
	bne.s	main_loop

cleanup
	IFNE	GENERATE_LOCALE
	move.l	catalog(pc),d0
	beq.s	1$
	move.l	d0,a0
	CALLLOCALE	CloseCatalog
	ENDC	;GENERATE_LOCALE

1$	move.l	App(pc),d0
	beq.s	2$
	move.l	d0,a0
	CALLMUI	MUI_DisposeObject
2$	bra.s	user_cleanup
signal	dc.l	0
user_cleanup
	ENDC	;GENERATE_ENV
	;Here is place for the cleanup routine.

	rts

	IFNE	GENERATE_LOCALE
GetString	move.l	catalog(pc),a0
	sub.l	a1,a1
	CALLLOCALE	GetCatalogStr
	rts

catalog	dc.l	0
	even
	ENDC	;GENERATE_LOCALE

	IFNE	GENERATE_DECLS
InitGUI	movem.l	a2/d2/d7,-(a7)
	move.l	a7,d7
	lea	object_tags(pc),a2
1$	tst.l	(a2)
	beq.s	2$

	move.l	#$8FFFFFFF,d0
	move.l	d0,d2
	subq.l	#1,d2
	lea	8(a2),a0
	moveq	#0,d1
3$	tst.l	(a0)
	beq.s	4$
	cmp.l	(a0),d2
	beq.s	14$
	cmp.l	(a0),d0
	bne.s	5$
	addq.l	#4,d1
5$	addq.l	#8,a0
	bra.s	3$

14$
	IFNE	GENERATE_LOCALE
	movem.l	d0-1,-(a7)
	lea	loc_tag_vals(pc),a1
	move.l	4(a0),d0
	move.l	d0,-(a7)
	lsl.l	#2,d0
	move.l	-4(a1,d0.l),(a0)+
	move.l	(a7)+,d0
	move.l	a0,-(a7)
	bsr	GetString
	move.l	(a7)+,a0
	move.l	d0,a1
	move.l	d0,(a0)+
	cmp.l	#MUIA_Text_HiChar,(a0)
	bne.s	15$
	cmp.l	#MUIA_Text_Contents,-8(a0)
	bne.s	15$
	cmp.b	#'_',(a1)
	bne.s	15$
	moveq	#0,d0
	move.b	2(a1),d0
	move.l	d0,4(a0)
	move.l	d0,12(a0)
	addq.l	#2,a1
	move.l	d0,-4(a0)
15$	movem.l	(a7)+,d0-1
	ENDC	GENERATE_LOCALE
	bra.s	3$

4$	tst.l	d1
	beq.s	10$
	lea	8(a2),a0
	lea	(a7,d1.l),a1
	move.l	a1,-(a7)
7$	tst.l	(a0)
	beq.s	8$
	cmp.l	(a0),d0
	bne.s	9$
	move.l	4(a0),(a0)+
	move.l	-(a1),(a0)+
	bra.s	7$
9$	addq.l	#8,a0
	bra.s	7$

8$	move.l	(a7),a7

10$	move.l	a0,-(a7)
	move.l	(a2),a0
	move.l	(a0),a0
	lea	8(a2),a1
	CALLMUI	MUI_NewObjectA
	move.l	4(a2),a0
	move.l	a0,d1
	beq.s	11$
	move.l	d0,(a0)
11$	move.l	(a7)+,a2
	tst.l	d0
	beq.s	12$
	move.l	d0,-(a7)
	addq.l	#4,a2
	bra.s	1$

2$	move.l	d7,a7
13$	movem.l	(a7)+,a2/d2/d7
	tst.l	d0
	rts

12$	moveq	#0,d0
	cmp.l	d7,a7
	beq.s	13$
	move.l	(a7)+,a0
	CALLMUI	MUI_DisposeObject
	bra.s	12$

_DoMethod	move.l	a2,-(a7)
	move.l	8(a7),a2
	move.l	a2,d0
	beq.s	1$
	lea	12(a7),a1
	move.l	-4(a2),a0
	move.l	8(a0),a6
	jsr	(a6)
	move.l	(a7)+,a2
	rts

1$	moveq	#0,d0
	move.l	(a7)+,a2
	rts

object_tags	dc.l	MUIC_Text,BT_label_0,MUIA_Frame,MUIV_Frame_Button,MUIA_Text_Contents,str9,MUIA_Text_PreParse,PreParse,MUIA_Text_SetMax,FALSE
	dc.l	MUIA_ControlChar,'b',MUIA_Text_HiChar,'b',MUIA_InputMode,MUIV_InputModeRelVerify,MUIA_Background,MUII_ButtonBack,0

	dc.l	MUIC_Text,BT_label_1,MUIA_Frame,MUIV_Frame_Button,MUIA_Text_Contents,str10,MUIA_Text_PreParse,PreParse,MUIA_Text_SetMax,FALSE
	dc.l	MUIA_ControlChar,'b',MUIA_Text_HiChar,'b',MUIA_InputMode,MUIV_InputModeRelVerify,MUIA_Background,MUII_ButtonBack,0

	dc.l	MUIC_Text,BT_label_2,MUIA_Frame,MUIV_Frame_Button,MUIA_Text_Contents,str11,MUIA_Text_PreParse,PreParse,MUIA_Text_SetMax,FALSE
	dc.l	MUIA_ControlChar,'b',MUIA_Text_HiChar,'b',MUIA_InputMode,MUIV_InputModeRelVerify,MUIA_Background,MUII_ButtonBack,0

	dc.l	MUIC_Text,BT_label_3,MUIA_Frame,MUIV_Frame_Button,MUIA_Text_Contents,str12,MUIA_Text_PreParse,PreParse,MUIA_Text_SetMax,FALSE
	dc.l	MUIA_ControlChar,'b',MUIA_Text_HiChar,'b',MUIA_InputMode,MUIV_InputModeRelVerify,MUIA_Background,MUII_ButtonBack,0

	dc.l	MUIC_Group,0,MUIA_Frame,MUIV_Frame_Group,MUIA_FrameTitle,str8,MUIA_Group_Columns,2,$8FFFFFFF,MUIA_Group_Child
	dc.l	$8FFFFFFF,MUIA_Group_Child,$8FFFFFFF,MUIA_Group_Child,$8FFFFFFF,MUIA_Group_Child,0

	dc.l	MUIC_Text,TX_label_0,MUIA_Background,131,MUIA_Text_Contents,STR_TX_label_0,MUIA_Text_SetMax,0,MUIA_Text_SetMin,1
	dc.l	MUIA_Frame,9,0

	dc.l	MUIC_Group,0,$8FFFFFFF,MUIA_Group_Child,$8FFFFFFF,MUIA_Group_Child,0

	dc.l	MUIC_Window,WI_SpecialChars,MUIA_Window_Title,str7,MUIA_Window_ID,'0WIN',$8FFFFFFF,MUIA_Window_RootObject,0

	dc.l	MUIC_Application,App,MUIA_Application_Author,str1,MUIA_Application_Base,str2,MUIA_Application_Title,str3,MUIA_Application_Version,str4
	dc.l	MUIA_Application_Copyright,str5,MUIA_Application_Description,str6,$8FFFFFFF,MUIA_Application_Window,0

	dc.l	0

App	dc.l	0
WI_SpecialChars	dc.l	0
BT_label_0	dc.l	0
BT_label_1	dc.l	0
BT_label_2	dc.l	0
BT_label_3	dc.l	0
TX_label_0	dc.l	0
STR_TX_label_0	dc.b	'',27,'c',27,'iwith the ''special'' characters',10,'',27,'byou will be able',10,'',27,'8',27,'n',27,'bto do what you want !!!',0

catalog_name	dc.b	'RamDisk:Special Chars.catalog',0
str1	dc.b	'Eric Totel',0
str2	dc.b	'SPECCHARS',0
str3	dc.b	'Special Chars',0
str4	dc.b	'$VER: SpecialChars 1.0',0
str5	dc.b	'Eric Totel (c) 1994',0
str6	dc.b	'just a demo !!!',0
str7	dc.b	'Special Chars',0
str8	dc.b	'Buttons',0
str9	dc.b	'',27,'8button_title',0
str10	dc.b	'',27,'8b',27,'0',27,'button_title',0
str11	dc.b	'',27,'i',27,'8b',27,'i',27,'0utton_title',0
str12	dc.b	'',27,'bbutton_title',0
	ENDC	;GENERATE_DECLS

MUIMASTER_BASE	dc.l	0

	tags
	library	muimaster,2	;I want to open muimaster
				;library version at least
				;two at start.
	finish
