	include	ssmac.h
	include	values/mui.gs
	include	libraries/mui_asm.i
	include	libraries/mui_lib.i

MR	EQUR	a4

DEBUG	equ	1

	start

CALLINT	macro
	call	intuition,\1
	endm

	dv.l	errsp
	dv.l	store
	dv.l	store2
	dbuf	buf2,256

	put.l	a7,errsp

	bsr	InitGUI

	DoMethod	WI_label_0,#MUIM_Notify,#MUIA_Window_CloseRequest,#TRUE,app,#2,#MUIM_Application_ReturnID,#MUIV_Application_ReturnID_Quit
	DoMethod	BT_label_1,#MUIM_Notify,#MUIA_Pressed,#TRUE,app,#2,#MUIM_Application_ReturnID,#MUIV_Application_ReturnID_Quit
	DoMethod	LV_label_0,#MUIM_Notify,#MUIA_Listview_DoubleClick,#MUIV_EveryTime,app,#2,#MUIM_Application_ReturnID,#1
	DoMethod	LV_label_0,#MUIM_Notify,#MUIA_List_Active,#MUIV_EveryTime,app,#3,#MUIM_CallHook,#hook_filesel_str,a5
	DoMethod	LV_label_1,#MUIM_Notify,#MUIA_List_Active,#MUIV_EveryTime,app,#3,#MUIM_CallHook,#hook_volsel_str,a5
	DoMethod	STR_label_0,#MUIM_Notify,#MUIA_String_Acknowledge,#MUIV_EveryTime,app,#3,#MUIM_CallHook,#hook_dir_str,a5
	DoMethod	STR_label_1,#MUIM_Notify,#MUIA_String_Acknowledge,#MUIV_EveryTime,app,#2,#MUIM_Application_ReturnID,#1
	DoMethod	BT_label_2,#MUIM_Notify,#MUIA_Pressed,#TRUE,app,#3,#MUIM_CallHook,#hook_parent_str,a5
	DoMethod	BT_label_0,#MUIM_Notify,#MUIA_Pressed,#TRUE,app,#2,#MUIM_Application_ReturnID,#1

	seti	WI_label_0,#MUIA_Window_Open,#TRUE

1$	DoMethod	app,#MUIM_Application_Input,#signal
	tst.l	d0
	bne.s	2$
	move.l	signal(pc),d0
	call	exec,Wait
	bra.s	1$
2$	moveq	#1,d1
	cmp.l	d1,d0
	beq.s	end
	cmp.l	#MUIV_Application_ReturnID_Quit,d0
	bne.s	1$

no_file	err	<You didn''t choose any file>

	rts

end	geta	store,a1
	geti	STR_label_0,#MUIA_String_Contents,a1
	geta	store2,a1
	geti	STR_label_1,#MUIA_String_Contents,a1
	get.l	store2,a0
	tst.b	(a0)
	beq.s	no_file

	get.l	store,a0
	geta	buf2,a1
	tst.b	(a0)
	beq.s	2$
1$	move.b	(a0)+,(a1)+
	bne.s	1$
	subq.l	#2,a1
	cmp.b	#'/',(a1)
	beq.s	2$
	cmp.b	#':',(a1)+
	beq.s	2$
	move.b	#'/',(a1)+
	clr.b	(a1)
2$	push	store2(v)
	pea	buf2(v)
	dtl	<You choosed file ''%s%s''.',10,'>,a0
	move.l	a0,d1
	move.l	a7,d2
	call	dos,VPrintf
	addq.l	#8,a7
	rts

hook_parent_str	dc.l	0
	dc.l	0
	dc.l	hook_parent
	dc.l	hook_parent
	dc.l	0

hook_parent	mpush	a5/a6
	move.l	(a1),a5
	geta	store,a1
	geti	STR_label_0,#MUIA_String_Contents,a1
	get.l	store,a0
	geta	buf2,a1
	moveq	#0,d1
1$	move.b	(a0),(a1)+
	move.b	(a0)+,d0
	beq.s	2$
	cmp.b	#':',d0
	bne.s	3$
	move.l	a1,d1
	bra.s	1$

3$	cmp.b	#'/',d0
	bne.s	1$
	tst.b	(a0)
	beq.s	2$
	move.l	a1,d1
	subq.l	#1,d1
	bra.s	1$

2$	tst.l	d1
	beq	ret

	move.l	d1,a0
	clr.b	(a0)

	geta	buf2,a0
	seti	STR_label_0,#MUIA_String_Contents,a0

	bra	refrdir

hook_dir_str	dc.l	0
	dc.l	0
	dc.l	hook_dir
	dc.l	hook_dir
	dc.l	0

hook_dir	mpush	a5/a6
	move.l	(a1),a5
	geta	store,a1
	geti	STR_label_0,#MUIA_String_Contents,a1
	bra	refrdir

hook_volsel_str	dc.l	0
	dc.l	0
	dc.l	hook_volsel
	dc.l	hook_volsel
	dc.l	0

hook_volsel	mpush	a5/a6
	move.l	(a1),a5
	geta	store,a0
	DoMethod	LV_label_1,#MUIM_List_GetEntry,#MUIV_List_GetEntry_Active,a0
	get.l	store,a0
	seti	STR_label_0,#MUIA_String_Contents,a0
	bra	refrdir

hook_filesel_str	dc.l	0
	dc.l	0
	dc.l	hook_filesel
	dc.l	hook_filesel
	dc.l	0

hook_filesel	mpush	a5/a6
	move.l	(a1),a5
	geta	store,a0
	DoMethod	LV_label_0,#MUIM_List_GetEntry,#MUIV_List_GetEntry_Active,a0
	get.l	store,a0
	move.l	4(a0),d0
	addq.l	#8,a0
	bpl.s	fs_newdir
	seti	STR_label_1,#MUIA_String_Contents,a0
ret	mpop	a5/a6
	rts

fs_newdir	push	a0
	geta	store,a1
	geti	STR_label_0,#MUIA_String_Contents,a1
	geta	buf2,a1
	get.l	store,a0
	moveq	#':',d0
1$	tst.b	(a0)
	beq.s	2$
	move.b	(a0),d0
	move.b	(a0)+,(a1)+
	bra.s	1$
2$	cmp.b	#':',d0
	beq.s	3$
	cmp.b	#'/',d0
	beq.s	3$
	move.b	#'/',(a1)+
3$	pop	a0
4$	move.b	(a0)+,(a1)+
	bne.s	4$
	subq.l	#2,a1
	cmp.b	#'/',(a1)
	bne.s	5$
	clr.b	(a1)
5$	geta	buf2,a0
	seti	STR_label_0,#MUIA_String_Contents,a0

refrdir	get.l	store,a0
	seti	LV_label_0,#MUIA_Dirlist_Directory,a0
	mpop	a5/a6
	rts

cleanup	move.l	app(pc),d0
	beq.s	1$
	move.l	d0,a0
	call	muimaster,MUI_DisposeObject
1$	rts

_DoMethod	push	a2
	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)
	pop	a2
	rts

1$	moveq	#0,d0
	pop	a2
	rts

signal	ds.l	1

InitGUI	mpush	a2/d7
	move.l	a7,d7
	lea	object_tags(pc),a2
1$	tst.l	(a2)
	beq.s	2$

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

4$	tst.l	d1
	beq.s	10$
	lea	8(a2),a0
	lea	(a7,d1.l),a1
	push	a1
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$	pop	a7

10$	push	a0
	move.l	(a2),a0
	move.l	(a0),a0
	lea	8(a2),a1
	call	muimaster,MUI_NewObjectA
	move.l	4(a2),a0
	move.l	a0,d1
	beq.s	11$
	move.l	d0,(a0)
11$	pop	a2
	tst.l	d0
	beq.s	12$
	push	d0
	addq.l	#4,a2
	bra.s	1$

2$	move.l	d7,a7
13$	mpop	a2/d7
	rts

12$	moveq	#0,d0
	cmp.l	d7,a7
	beq.s	13$
	pop	a0
	call	muimaster,MUI_DisposeObject
	bra.s	12$

object_tags	dc.l	MUIC_Dirlist,0,MUIA_Frame,MUIV_Frame_InputList,MUIA_Dirlist_Directory,str9,MUIA_Dirlist_DrawersOnly,0,MUIA_Dirlist_FilesOnly,0,MUIA_Dirlist_FilterDrawers,0
	dc.l	MUIA_Dirlist_MultiSelDirs,0,MUIA_Dirlist_RejectIcons,0,MUIA_Dirlist_SortDirs,MUIV_Dirlist_SortDirs_First,MUIA_Dirlist_SortHighLow,0,MUIA_Dirlist_SortType,0
	dc.l	0

	dc.l	MUIC_Listview,LV_label_0,MUIA_Weight,300,$8FFFFFFF,MUIA_Listview_List,0

	dc.l	MUIC_Volumelist,0,MUIA_Frame,MUIV_Frame_InputList,0

	dc.l	MUIC_Listview,LV_label_1,$8FFFFFFF,MUIA_Listview_List,0

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

	dc.l	MUIC_Text,0,MUIA_Text_PreParse,PreParse2,MUIA_Text_Contents,str10,MUIA_Weight,0,MUIA_InnerLeft,0
	dc.l	MUIA_InnerRight,0,MUIA_Frame,MUIV_Frame_String,MUIA_FramePhantomHoriz,1,0

	dc.l	MUIC_String,STR_label_0,MUIA_Frame,MUIV_Frame_String,MUIA_String_Format,0,0

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

	dc.l	MUIC_Text,0,MUIA_Text_PreParse,PreParse2,MUIA_Text_Contents,str11,MUIA_Weight,0,MUIA_InnerLeft,0
	dc.l	MUIA_InnerRight,0,MUIA_Frame,MUIV_Frame_String,MUIA_FramePhantomHoriz,1,0

	dc.l	MUIC_String,STR_label_1,MUIA_Frame,MUIV_Frame_String,MUIA_String_Format,0,0

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

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

	dc.l	MUIC_Rectangle,0,0

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

	dc.l	MUIC_Rectangle,0,0

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

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

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

	dc.l	MUIC_Window,WI_label_0,MUIA_Window_Title,str7,MUIA_HelpNode,str8,$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_label_0	dc.l	0
LV_label_0	dc.l	0
LV_label_1	dc.l	0
STR_label_0	dc.l	0
STR_label_1	dc.l	0
BT_label_0	dc.l	0
BT_label_2	dc.l	0
BT_label_1	dc.l	0
str1	dc.b	'Misoftware Computing',0
str2	dc.b	'Base',0
str3	dc.b	'FileReq',0
str4	dc.b	'1.0',0
str5	dc.b	'Copyright 1994 Misoftware Computing',0
str6	dc.b	'Chooses file',0
str7	dc.b	'Choose file',0
str8	dc.b	'WI_label_0',0
str9	dc.b	'progdir:',0
str10	dc.b	'Drawer',0
str11	dc.b	'File',0
str12	dc.b	' Okay ',0
str13	dc.b	'Parent',0
str14	dc.b	'Cancel',0
erro1	dc.b	"Failed to create application. MUI Error: %d",10,0

	tags
	library	muimaster,2
	exitrout	cleanup
	finish
