;Programm:	MView
;Version:	1.06
;Zweck: 	Anzeige von Bildern, Texten, Guides mit DataTypes
;Start: 	9. Oktober 1997
;Assemblieren:	a68k MView.s
;Linken:	dlink MView.o -oMView

;History
;1.00	Erste lauffähige Version (1236)
;	Ausgabe von picinfo (1352)
;1.01	Abbruch bei Bildern mit ESC oder Q (1424)
;	Optimierungen (1348)
;	Bei WBStart kann Verzeichnis gescannt werden
;1.02	Asl-Filerequester integriert (1540)
;1.03	Abbruch per _EasyRequest eingebaut (1784)
;	nächstes file kann übersprungen werden (1812)
;	primitives Parsen von CLI-args (1808)
;	Test auf Verzeichnis nach MatchNext (1828)
;	Tastenäquivalente für ZEIGEN, ÜBERSPRINGEN (1844)
;1.04	Bildinformation um NameInfo ergänzt (1920)
;	Information über HAM/EHB hinter NameInfo (1960)
;	AslRequester höher und ohne .info-Files (1992)
;1.05	Entpacken mit XpkLib (2156)
;	Auswertung der CLI-Args mit ReadArgs() (2116)
;	Option NOREQ/S (2144)
;1.06	Bei Screens mit depth >8 wird abgebrochen, da sonst
;	Absturz. Meldung von A. Neumann (2184)

;verwendete Makros

LibCall     MACRO
   move.l    \1(a4),a6
   jsr	     \2(a6)
   ENDM

SysCall     MACRO
   LibCall   ExecBase,\1
   ENDM

DosCall     MACRO
   LibCall   DosBase,\1
   ENDM

IntCall     MACRO
   LibCall   IntBase,\1
   ENDM

GfxCall     MACRO
   LibCall   GfxBase,\1
   ENDM

Call MACRO			       ; (routine)
   jsr	     \1(a6)
   ENDM

Zero MACRO
   moveq.l   #0,\1
   ENDM

STRUCTURE	MACRO
\1	=	0
SOFFSET SET	\2
	ENDM

BYTE	MACRO
\1	=	SOFFSET
SOFFSET SET	SOFFSET+1
	ENDM

WORD	MACRO
\1	=	SOFFSET
SOFFSET SET	SOFFSET+2
	ENDM

LONG	MACRO
\1	=	SOFFSET
SOFFSET SET	SOFFSET+4
	ENDM

APTR	MACRO
\1	=	SOFFSET
SOFFSET SET	SOFFSET+4
	ENDM

BPTR	MACRO
\1	=	SOFFSET
SOFFSET SET	SOFFSET+4
	ENDM

STRUCT	MACRO
\1	=	SOFFSET
SOFFSET SET	SOFFSET+\2
	ENDM

LABEL	MACRO
\1	=	SOFFSET
	ENDM


AslRequest	= -$03c (request,tagList) (a0/a1)
AllocAslRequest = -$030 (type,tagList) (d0/a0)
AllocVec	= -$2ac (byteSize,requirements) (d0,d1)
Close		= -$024 (file)(D1)
CloseAmigaGuide = -66	(handle) (a0)
CloseLibrary	= -414	(library)   (a1)
CloseWindow	= -$048 (Window)(A0)
CurrentDir	= -126	(lock) (d1)
DeleteFile	= -$048 (name)(D1)
FreeArgs	= -$35a (args) (d1)
FreeAslRequest	= -$036 (request) (a0)
FreeMem 	= -210	(^memBlock, byteSize)   (a1, d0)
FreeVec 	= -$2b2 (memoryBlock) (a1)
GetMsg		= -372	(port)   (a0)
IoErr		= -$084 ()
Lock		= -84	(name, access_mode)   (d1, d2)
Open		= -$01e (name,accessMode)(D1/D2)
OpenAmigaGuideA = -54	(nag, attrs) (a0,a1)
OpenLibrary	= -552	(libName, version)  (a1, d0)
OpenWindow	= -$0cc (OWargs)(A0)
PutStr		= -$3b4 (str) (d1)
QueryOverscan	= -$1da (displayID,rect,oScanType) (a0,a1,d0)
ReadArgs	= -$31e (template,array,args) (d1-d3)
RawDoFmt	= -522	()  (a0,a1,a2,a3)
ReplyMsg	= -378	(message)   (a1)
UnLock		= -90	(lock)   (d1)
Wait		= -318	(signalset)   (d0)
WaitPort	= -384	(port)   (a0)
MatchEnd	= -$342 (anchor) (d1)
MatchFirst	= -$336 (pat,anchor) (d1,d2)
MatchNext	= -$33c (anchor) (d1)
PrintFault	= -$1da (code,header) (d1,d2)
CloseScreen	= -$042 (Screen)(A0)
OpenScreenTagList = -$264 (newScreen,tagList) (a0,a1)
Read		= -$02a (file,buffer,length)(D1/D2/D3)
ScreenToFront	= -$0fc (screen) (a0)
BuildEasyRequestArgs = -$252 (window,easyStruct,idcmp,args) (a0,a1,d0,a3)
FreeSysRequest	= -$174 (Window)(A0)
FindDisplayInfo = -$2d6 (displayID) (d0)
GetDisplayInfoData = -$2f4  (handle,buf,size,tagID,displayID) (a0,a1,d0-d2)
XpkUnpack	= -48

;datatypes
ObtainDataTypeA = -36 (type,handle,attrs)(d0/a0/a1)
ReleaseDataType = -42 (dt)(a0)
NewDTObjectA	= -48 (name,attrs)(d0/a0)
DisposeDTObject = -54 (o)(a0)
GetDTAttrsA	= -66 (o,attrs)(a0/a2)
DoDTMethodA	= -90 (o,win,req,msg)(a0/a1/a2/a3)

MODE_OldFile	= 1005
Access_Read	= -2
XPK_InName	= $80005851	filename
XPK_OutName	= $80005860	filename

dtn_Header	= $1c
dth_Name	= 0
dth_BaseName	= 4
dth_Pattern	= 8
dth_Mask	= 12
dth_GroupID	= 16
dth_ID		= 20
dth_MaskLen	= 24
dth_Pad 	= 26
dth_Flags	= 28

pr_CLI		= $AC
pr_MsgPort	= $5C
pr_COS		= $A0

fib_DirEntryType = 4	If <0 then file >0 = dir
fib_FileName	= 8	Null terminated. Max 30 of 108 chars use
fib_Size	= 124
fib_SIZEOF	= 260

MEMF_Chip	= 2
MEMF_Clear	= $10000

MOUSEBUTTONS	= $00000008
GADGETUP	= $00000040
CLOSEWINDOW	= $00000200
VANILLAKEY	= $00200000
ACTIVEWINDOW	= $00040000
INACTIVEWINDOW	= $00080000

ACTIVATE	= $00001000
RMBTRAP 	= $00010000
BACKDROP	= $00000100
BORDERLESS	= $0800
NOCAREREFRESH	= $00020000
CUSTOMSCREEN	= $000F
SCREENBEHIND	= $0080
SCREENQUIET	= $0100
CUSTOMBITMAP	= $0040
AUTOSCROLL	= $4000

;screen und window tags

SA_Colors32	= $80000043
SA_OverScan	= $80000034
SA_DisplayID	= $80000032
DTAG_NAME	= $80003000

ib_ActiveScreen = 56
sc_Height	= $0e
wd_UserPort	= $56
in_Class	= $14
in_Code 	= $18
in_IAddress	= $1c
gg_GadgetID	= $26

TAG_USER	= $80000000
DTA_Dummy	= TAG_USER+$1000
PDTA_Remap	= DTA_Dummy+211     ;default TRUE
PDTA_ModeID	= DTA_Dummy+200
PDTA_BitMapHeader = DTA_Dummy+201
PDTA_BitMap	= DTA_Dummy+202     ;pointer auf BitMap
PDTA_CRegs	= DTA_Dummy+204
PDTA_NumColors	= DTA_Dummy+209
DTST_FILE	= 2
DTM_PROCLAYOUT	= $602


; STRUCTURE BitMapHeader,0
; WORD	  bmh_Width;	      Breite des Bildes
; WORD	  bmh_Height	      Höhe
; WORD	   bmh_Left	      immer NULL
; WORD	   bmh_Top	      immer NULL
; BYTE	  bmh_Depth
; BYTE	  bmh_Masking	      nicht verwendbar
; BYTE	  bmh_Compression     "
; BYTE	  bmh_Pad	      "
; WORD	  bmh_Transparent     "
; BYTE	  bmh_XAspect	      " (Pixel-Aspekt)
; BYTE	  bmh_YAspect	      "
; WORD	   bmh_PageWidth      " weichen von Width/Heigth
; WORD	   bmh_PageHeight     " zuweilen ab

LF		= 10
ESC		= 27

lib_Version	= 20
ThisTask	= $114
sm_NumArgs	= 28	; the number of elements in ArgList
sm_ArgList	= 36	; the arguments themselves
wa_Lock 	= 0	; a lock descriptor
wa_Name 	= 4	; a string relative to that lock
wa_SIZEOF	= 8
ERROR_NO_MORE_ENTRIES = 232
ERROR_BREAK = 304


;------------------------- globals ------------------------------------

	STRUCTURE Picture,120	;Variablen für Bildanzeige
	APTR	bmap		;Zeiger auf BitMap
	APTR	palette
	APTR	bmh		;BitMapHeader
	LONG	display_ID
	APTR	object
	APTR	cregs
	LONG	ncols		;Zahl der Farben
	APTR	dtname		;Name des DataTypes

     STRUCTURE	globals,0
	STRUCT	mainbuf,180
	STRUCT	EasyStruct,20
	STRUCT	formatbuf,120
	STRUCT	tempbuf,120	;filename(tackon), temp. Titel
	STRUCT	tempname,40	;filename, unpacked
	APTR	WbMsg	     \
	BPTR	outputhandle  | ;Null, wenn Background bzw. WbStart
	APTR	ExecBase      |
	APTR	DosBase       |
	APTR	DTypeBase     |
	APTR	IntBase       |
	APTR	GfxBase       |
	APTR	AGuideBase    |
	APTR	XpkBase       |
	APTR	aslrequest    |
	APTR	AslBase      /
	APTR	ap_Base 	;Start AnchorPath
	APTR	ap_Last 	;=ap_Current
	LONG	ap_BreakBits
	LONG	ap_FoundBreak
	BYTE	ap_Flags
	BYTE	ap_Reserved
	WORD	ap_Strlen
	STRUCT	ap_Info,fib_SIZEOF
	STRUCT	ap_Buf,120
	LONG	OldDir
	WORD	cdflag
	WORD	noxpk			;gesetzt, wenn keine xpkmaster.lib
	WORD	noreq			;gesetzt, wenn kein EasyRequest
	WORD	unpacked		;gesetzt, wenn entpackt
	WORD	filecount
	LABEL	gl_Size


Start:	moveq	#10,d7			;RC
	move.l	4,a6
	Zero	d4
	move.l	ThisTask(a6),a5
	tst.l	pr_CLI(a5)
	bne	Version

from_WB lea	pr_MsgPort(a5),a0       ;WbMsg abholen
	Call	WaitPort
	lea	pr_MsgPort(a5),a0
	Call	GetMsg
	move.l	d0,d4

Version cmp.w	#39,lib_Version(a6)
	bcs	wbexit			;nicht V39+

GetMem	move.l	#gl_Size,d0
	moveq	#1,d1
	swap	d1
	Call	AllocVec
	tst.l	d0
	beq	wbexit
	move.l	d0,a4
	lea	WbMsg(a4),a2
	move.l	d4,(a2)+
	move.l	pr_COS(a5),(a2)+        ;output
	move.l	a6,(a2)+                ;ExecBase
	lea	DosName(pc),a1
	moveq	#39,d0
	Call	OpenLibrary
	move.l	d0,(a2)+                ;DosBase
	beq	CloseBuf
	tst.l	d4
	bne	OpenLibs

	move.l	d0,a6			;started from CLI
	lea	Template(pc),a0
	move.l	a0,d1
	move.l	a4,d2
	moveq	#0,d3
	Call	ReadArgs
	move.l	d0,d5			;d5=RdArgs-struct
	beq	CloseDos
	move.l	a4,a0
	tst.l	(a4)
	beq	\copy
	move.l	(a4),a0
\copy	lea	tempbuf(a4),a1
	move.l	a1,a3
	bsr	_copystr
	move.w	4(a4),noreq(a4)
	move.l	d5,d1
	Call	FreeArgs
OpenLibs
	lea	DTypeName(pc),a1
	moveq	#39,d0
	SysCall OpenLibrary
	move.l	d0,(a2)+
	beq	CloseLibs
	lea	IntName(pc),a1
	Zero	d0
	Call	OpenLibrary
	move.l	d0,(a2)+
	lea	GfxName(pc),a1
	Zero	d0
	Call	OpenLibrary
	move.l	d0,(a2)
;------------------------------------

	bsr	_Main

;------------------------------------
	move.l	AslBase(a4),d0
	beq	CloseLibs
	move.l	d0,a6
	move.l	aslrequest(a4),d0
	beq	\closeasl
	move.l	d0,a0
	Call	FreeAslRequest
\closeasl
	bsr	_CloseLib

CloseLibs
	lea	XpkBase+4(a4),a2
	moveq	#4,d4			;5 libs schließen
\closelib
	move.l	-(a2),a6
	bsr	_CloseLib
	dbf	d4,\closelib

CloseDos
	bsr	_deletetemp		;setzt DosBase
	tst.w	cdflag(a4)
	beq	\closedos
	move.l	OldDir(a4),d1
	Call	CurrentDir
\closedos
	bsr	_CloseLib
CloseBuf
	move.l	WbMsg(a4),d4            ;für ReplyMsg() retten
	move.l	a4,a1
	Call	FreeVec
wbexit	tst.l	d4
	beq	cli_exit
	move.l	d4,a1
	jmp	ReplyMsg(a6)

cli_exit
	move.l	d7,d0
	rts

_CloseLib
	move.l	a6,a1
	move.l	ExecBase(a4),a6
	move.l	a1,d0
	beq	\libend
	Call	CloseLibrary
\libend rts

;------------------------ Main ------------------------------

_Main	tst.l	d4
	bne	WB_Args
	move.l	a3,d4
	bra	Match

WB_Args move.l	d4,a0
	move.l	sm_NumArgs(a0),d4
	move.l	sm_ArgList(a0),a2
	subq.l	#1,d4
	beq	TryFReq 		;Aufruf ohne Argument
\2ndarg addq.l	#8,a2
	move.l	(a2)+,d1                ;wa_Lock
	DosCall CurrentDir
	move.l	d0,OldDir(a4)
	not.w	cdflag(a4)
	move.l	(a2),d4                 ;wa_Name
	bra	Match

TryFReq bsr	_FReq			;kein arg1 (CLI) bzw. Dir (WB)
	tst.l	d4
	beq	MainExit		;kein File gewählt

Match	move.l	d4,d1
	lea	ap_Base(a4),a0
	moveq	#120,d0 		;Puffergröße für Pfad = 120
	move.w	d0,ap_Strlen(a4)
	move.l	a0,d2
	DosCall MatchFirst
	move.l	d0,d1
	beq	CheckDir
	bsr	_errormsg
	bra	MainExit		;Abgang mit Fehlermeldung
CheckDir
	tst.l	ap_Info+fib_DirEntryType(a4)
	bmi	GotMatch
	btst	#1,ap_Flags(a4)
	bne	NextMatch		;ITSWILD, weiterscannen
	lea	ap_Base(a4),a0          ;arg1 (CLI) war ein Verzeichnis
	move.l	a0,d1
	Call	MatchEnd
	bra	TryFReq 		;_FReq mit d4=Verzeichnisname
					;aufrufen
NextMatch
	bsr	_deletetemp		;setzt DosBase
	btst	#1,ap_Flags(a4)         ;ITSWILD=Bit 1
	beq	EndMatch
	lea	ap_Base(a4),a0
	move.w	#$1000,ap_BreakBits+2(a4)       ;CTRL-C
	move.l	a0,d1
	Call	MatchNext
	move.l	d0,d1
	beq	GotMatch		;d0=0=success
	bsr	_errormsg
EndMatch
	lea	ap_Base(a4),a0
	move.l	a0,d1
	DosCall MatchEnd
	Zero	d7
MainExit
	rts


GotMatch
	tst.l	ap_Info+fib_DirEntryType(a4)
	bpl	NextMatch
	tst.l	ap_Info+fib_Size(a4)
	beq	NextMatch
	lea	ap_Buf(a4),a0           ;voller Name mit Pfad
	tst.w	cdflag(a4)
	beq	GotName
	lea	ap_Info+fib_FileName(a4),a0     ;nur BaseName
GotName
	move.l	a0,d4
	bsr	_IsDataType
	bmi	ViewGuide		;Typ ist Text, AGuide oder Sound
	bne	TryXPK			;Typ vermutlich binär (syst)
	bsr	_EasyRequest
	subq.l	#1,d0
	bcs	EndMatch
	bne	NextMatch
	bsr	_GetDataPic		;Typ ist pict, Anzeigen
	move.w	d7,d0
	beq	NextMatch		;Bildanzeige schlug fehl
	addq.w	#1,filecount(a4)
	bclr	#5,d0			;welche Taste wurde gedrückt?
	cmp.b	#'Q',d0
	beq	EndMatch		;Q/ESC=Abbruch
	cmp.b	#ESC,d0
	beq	EndMatch
	bra	NextMatch		;nächste Datei laden

ViewGuide
	bsr	_EasyRequest
	subq.l	#1,d0
	bcs	EndMatch
	bne	NextMatch

\getlib move.l	AGuideBase(a4),d0
	bne	\gotlib 		;amigaguide.lib schon geöffnet
	lea	AGuideName(pc),a1
	moveq	#39,d0
	move.l	ExecBase(a4),a6
	Call	OpenLibrary
	move.l	d0,AGuideBase(a4)
	beq	GetNext 		;keine library
\gotlib
	move.l	d0,a6			;AGuideBase
	move.l	a4,a0
	move.l	a0,a1
	clr.l	(a1)+
	move.l	d4,(a1)+                ;nag_Name
	moveq	#13,d1			;nag_sizeof = 52 bytes
\clrnag clr.l	(a1)+
	dbf	d1,\clrnag
	suba.l	a1,a1
	Call	OpenAmigaGuideA 	;Dokument synchron zeigen
	tst.l	d0
	beq	GetNext
	move.l	d0,a0
	Call	CloseAmigaGuide
	addq.w	#1,filecount(a4)
GetNext bra	NextMatch

TryXPK	tst.w	noxpk(a4)
	bne	GetNext
	tst.w	unpacked(a4)
	bne	GetNext
	lea	ap_Info+fib_FileName(a4),a0
	move.l	a0,(a4)
	lea	temp.fmt(pc),a0
	bsr	_Format
	lea	tempname(a4),a1
	move.l	a1,d3
	bsr	_copystr		;RAM:<file>.xpk

UnPack	move.l	XpkBase(a4),d0
	bne	\gotlib
	lea	XpkName(pc),a1
	Zero	d0
	SysCall OpenLibrary
	move.l	d0,XpkBase(a4)
	seq	noxpk(a4)
	beq	GetNext
\gotlib
	move.l	d0,a6
	move.l	a4,a0
	move.l	#XPK_InName,(a0)+
	move.l	d4,(a0)+                ;filename
	move.l	#XPK_OutName,(a0)+
	move.l	d3,(a0)+
	clr.l	(a0)
	move.l	a4,a0
	Call	XpkUnpack
	tst.l	d0
	bne	GetNext
	move.l	d3,a0
	not.w	unpacked(a4)
	bra	GotName


_IsDataType
	;d4=filename >>d0=0 (success), -1 (nopic), 10 (error)
	moveq	#10,d3
	move.l	d4,d1
	moveq	#Access_Read,d2
	DosCall Lock
	move.l	d0,d6
	beq	\nolock
	move.l	DTypeBase(a4),a6
	move.l	d6,a0			;Lock (filename)
	moveq	#DTST_FILE,d0
	suba.l	a1,a1
	Call	ObtainDataTypeA
	tst.l	d0
	beq	\unlock
	move.l	d0,a0
	move.l	dtn_Header(a0),a0
	move.l	(a0),dtname(a4)         ;für picinfo
	lea	dth_GroupID(a0),a0
	cmp.w	#'sy',(a0)              ;GroupID 'syst'
	beq	\release
	moveq	#-1,d3			;RC=nopic
	cmp.w	#'pi',(a0)              ;GroupID 'pict'
	bne	\release
	Zero	d3
\release
	move.l	d0,a0
	Call	ReleaseDataType
\unlock move.l	d6,d1
	DosCall UnLock
\nolock move.l	d3,d0
	rts

_GetDataPic	;>d4=file >>d7=code
	clr.l	palette(a4)
	Zero	d7
;TagList
	move.l	a4,a0
	move.l	#PDTA_Remap,(a0)+
	clr.l	(a0)+                   ;FALSE
	clr.l	(a0)                    ;TAG_DONE
	move.l	d4,d0			;filename
	move.l	a4,a0
	move.l	DTypeBase(a4),a6
	Call	NewDTObjectA
	move.l	d0,object(a4)
	beq	\error

	move.l	d0,a0			;object
	pea	1
	clr.l	-(sp)
	pea	DTM_PROCLAYOUT
	move.l	sp,a3
	suba.l	a1,a1			;win
	suba.l	a2,a2			;req
	Call	DoDTMethodA
	lea	12(sp),sp
	tst.l	d0
	beq	\error

	clr.l	-(sp)
	pea	bmh(a4)
	move.l	#PDTA_BitMapHeader,-(sp)
	pea	display_ID(a4)
	move.l	#PDTA_ModeID,-(sp)
	pea	cregs(a4)
	move.l	#PDTA_CRegs,-(sp)
	pea	ncols(a4)
	move.l	#PDTA_NumColors,-(sp)
	pea	bmap(a4)
	move.l	#PDTA_BitMap,-(sp)
	move.l	sp,a2
	move.l	object(a4),a0
	Call	GetDTAttrsA
	lea	44(sp),sp
	subq.l	#5,d0
	beq	\dims

\error	bra	freepic

\dims	move.l	bmh(a4),a0
	move.l	(a0),d4                 ;width+height
	Zero	d6
	move.b	8(a0),d6                ;depth

	move.l	display_ID(a4),d0
	move.l	d0,d3
	bmi	\error
	and.w	#$f77f,d0		;HAM-/EHB-Bits ausmaskieren
	clr.l	28(a4)                  ;falls keine NameInfo
	GfxCall FindDisplayInfo
	tst.l	d0
	beq	\print
	move.l	d0,a0
	lea	12(a4),a1
	moveq	#56,d0			;NameInfo_sizeof
	move.l	#DTAG_NAME,d1
	Call	GetDisplayInfoData
\print
	move.l	a4,a1
	lea	ap_Info+8(a4),a0        ;BaseName
	move.l	a0,(a1)+
	move.l	dtname(a4),(a1)+
	move.l	d4,(a1)+
	move.w	d6,(a1)+
	lea	28(a4),a0               ;Name des ScreenMode
	move.l	a0,(a1)
	tst.b	(a0)
	beq	\format 		;keine DisplayInfo
	move.l	a0,a1
	bsr	_copystr
	lea	HAM.txt(pc),a0
	lsl.w	#4,d3			;HAM-Modus?
	bmi	\copy
	addq.l	#7,a0
	lsl.w	#4,d3
	bpl	\format
\copy	bsr	_copystr		;(HAM) bzw. (EHB) anhängen
\format lea	picinfo.fmt(pc),a0
	bsr	_Format
	bsr	_Print
	moveq	#8,d0
	cmp.l	d6,d0
	bcc	\depth_ok		;depth höchtens 8
	moveq	#106,d1
	add.l	d1,d1			;object wrong type
	bsr	_errormsg
	bra	\error

\depth_ok
	move.l	ncols(a4),d3
	moveq	#12,d2
	mulu	d3,d2
	move.l	d2,d0
	addq.l	#8,d0
	moveq	#1,d1
	swap	d1			;MEMF_Clear für palette
	SysCall AllocVec
	move.l	d0,palette(a4)
	beq	\error

	move.l	d0,a1
	swap	d3
	move.l	d3,(a1)+
	move.l	cregs(a4),a0
\cpycolors
	move.b	(a0)+,(a1)+
	subq.l	#1,d2
	bne	\cpycolors

ViewPic move.l	display_ID(a4),a0       ;ModeID
	move.l	a4,a1			;struct Rectangle(MinX,MinY,MaxX,MaxY)
	moveq	#1,d0			;Type OSCAN_TXT
	IntCall QueryOverscan
	tst.l	d0
	beq	\openscreen
	Zero	d0			;Bild horizontal zentrieren
	move.w	4(a4),d1                ;OSCAN-Breite
	move.l	d4,(a4)
	sub.w	(a4),d1                 ;minus Screenbreite
	bcs	\openscreen		;Screen zu groß
	lsr.w	#1,d1			;Differenz durch 2 = sc_Left
	move.w	d1,d0
	swap	d0
\openscreen
	move.l	a4,a0
	move.l	d0,(a0)+                ;x,y
	move.l	d4,(a0)+                ;width+height
	move.w	d6,(a0)+                ;depth
	clr.l	(a0)+                   ;pens, viewmode
	move.w	#CUSTOMSCREEN!SCREENBEHIND!SCREENQUIET!CUSTOMBITMAP!AUTOSCROLL,(a0)+
	clr.l	(a0)+
	clr.l	(a0)+
	clr.l	(a0)+
	move.l	bmap(a4),(a0)+          ;Ende NewScreen

	move.l	a0,a1			;tags
	move.l	#SA_DisplayID,(a0)+
	move.l	display_ID(a4),(a0)+
	move.l	#SA_OverScan,(a0)+
	moveq	#1,d0
	move.l	d0,(a0)+
	move.l	#SA_Colors32,(a0)+
	move.l	palette(a4),(a0)+
	clr.l	(a0)
	move.l	a4,a0
	Call	OpenScreenTagList
	tst.l	d0
	beq	freepic
	move.l	d0,a3

;NewWindow

	move.l	a4,a0
	clr.l	(a0)+
	moveq	#2,d0			;window nur 2x2, spart bis zu 500K
	move.w	d0,(a0)+                ;width
	move.w	d0,(a0)+                ;height
	clr.w	(a0)+
	move.l	#MOUSEBUTTONS!VANILLAKEY!INACTIVEWINDOW,(a0)+
	move.l	#BORDERLESS!ACTIVATE!RMBTRAP,(a0)+
	clr.l	(a0)+
	clr.l	(a0)+
	clr.l	(a0)+
	move.l	a3,(a0)+
	clr.l	(a0)+
	clr.l	(a0)+
	clr.l	(a0)+
	move.w	#CUSTOMSCREEN,(a0)
	move.l	a4,a0
	Call	OpenWindow
	tst.l	d0
	beq	\closescreen
	move.l	d0,a5

	move.l	a3,a0
	Call	ScreenToFront

\wait	move.l	wd_UserPort(a5),a0
	move.l	a0,d3
	SysCall WaitPort
	move.l	d3,a0
	Call	GetMsg
	tst.l	d0
	beq	\wait
\msgloop
	move.l	d0,a1
	move.w	in_Code(a1),d7          ;Code der gedrückten Taste=RC
	Call	ReplyMsg
\nextmsg
	move.l	d3,a0
	Call	GetMsg
	tst.l	d0
	bne	\msgloop
	move.l	a5,a0
	IntCall CloseWindow
\closescreen
	move.l	a3,a0
	Call	CloseScreen
freepic move.l	object(a4),d0
	beq	\palette
	move.l	d0,a0
	move.l	DTypeBase(a4),a6
	Call	DisposeDTObject
\palette
	move.l	palette(a4),d0
	beq	\endfree
	move.l	d0,a1
	SysCall FreeVec
\endfree
	rts
		;>a0=string
_Print	tst.l	outputhandle(a4)
	beq	\end			;keine Ausgabe bei WBStart
	move.l	a0,d1
	DosCall PutStr
\end	rts

_errormsg	;>d1=err
	tst.l	outputhandle(a4)
	beq    \end
	Zero	d2
	DosCall PrintFault
\end	rts

_Format 	;>a0=formatstr >>a0=formatbuf
	move.l	a4,a1
	lea	_PutChar(pc),a2
	lea	formatbuf(a4),a3
	SysCall RawDoFmt
	move.l	a3,a0
	rts

_PutChar
	move.b	d0,(a3)+
	rts

_FReq		;>d4=0/^Dir  >>d4=^Name oder Null
	move.l	d4,d3
	Zero	d4
	lea	AslName(pc),a1
	moveq	#39,d0
	SysCall OpenLibrary
	move.l	d0,AslBase(a4)
	beq	\endfreq
	move.l	d0,a6
	Zero	d0
	suba.l	a0,a0
	Call	AllocAslRequest
	move.l	d0,aslrequest(a4)
	beq	\endfreq
	Zero	d7
	move.l	d0,a5
	move.l	a4,a1
	move.l	#$80080001,d1		;TAG_Hail
	lea	version(pc),a0
	move.l	d1,(a1)+
	move.l	a0,(a1)+
	addq.l	#8,d1			;TAG_Dir
	tst.l	d3
	beq	\nodir
	move.l	d1,(a1)+
	move.l	d3,(a1)+                ;^Dir
\nodir	move.l	IntBase(a4),a0
	move.l	ib_ActiveScreen(a0),a0
	move.w	sc_Height(a0),d0
	moveq	#125,d2
	add.l	d2,d2			;Höhe 250
	cmp.w	d2,d0
	bcs	\done
	subq.l	#3,d1
	move.l	d1,(a1)+                ;TAG_Height=$80080006
	move.l	d2,(a1)+
\done	move.l	#$8008003c,(a1)+        ;TAG_RejectIcons
	moveq	#1,d0
	move.l	d0,(a1)+
	clr.l	(a1)                    ;TAG_Done
	move.l	a4,a1
	move.l	a5,a0
	Call	AslRequest
	tst.l	d0
	beq	\endfreq		;Abbruch durch User
	move.l	8(a5),a0                ;^Dir, Offset 8
	move.l	4(a5),a1                ;^File
	tst.b	(a1)
	beq	\endfreq
	bsr	_tackon 		;kompletter Pfad danach in d4
\endfreq
	rts

_tackon 	; >a0=^Dir a1=^File >>d4=^Filename (in tempbuf)
	move.l	a1,-(sp)
	lea	tempbuf(a4),a1
	move.l	a1,d4
	tst.b	(a0)
	beq	\gotdir
	bsr	_copystr		;Dir kopieren
	move.b	-1(a1),d0
	cmp.b	#':',d0
	beq	\gotdir
	cmp.b	#'/',d0
	beq	\gotdir
	move.b	#'/',(a1)+
\gotdir move.l	(sp)+,a0

_copystr	;a0=Quelle, a1=Ziel
	move.b	(a0)+,(a1)+             ;Namen kopieren,
	bne	_copystr		;solange kein Nullbyte
	subq.l	#1,a1
	rts

_EasyRequest
	moveq	#1,d0
	tst.w	filecount(a4)
	beq	\endrequest
	tst.w	noreq(a4)
	bne	\endrequest		;kein Requester gewünscht
	lea	EasyStruct(a4),a1       ;Aufruf von BuildEasyRequestArgs()
	moveq	#20,d0			;vorbereiten
	move.l	d0,(a1)+                ;es_StructSize=20
	clr.l	(a1)+                   ;es_Flags=NULL
	lea	EasyTitle(pc),a0        ;es_Title=MView Meldung
	move.l	a0,(a1)+
	lea	Bodytext.fmt(pc),a0     ;es_TextFormat
	move.l	a0,(a1)+
	lea	Gadgettext(pc),a0       ;es_GadgetFormat:ANZEIGEN|ABBRECHEN
	move.l	a0,(a1)
	lea	EasyStruct(a4),a1
	move.l	#VANILLAKEY,d0		;IDCMP
	lea	ap_Info+fib_FileName(a4),a0
	move.l	a0,(a4)
	move.l	dtname(a4),4(a4)
	move.l	a4,a3			;Args
	suba.l	a0,a0
	IntCall BuildEasyRequestArgs
	moveq	#1,d1
	cmp.l	d0,d1
	bcc	\endrequest		;kein Requester
	move.l	d0,a3

\wait	move.l	wd_UserPort(a3),a0
	SysCall WaitPort
	move.l	wd_UserPort(a3),a0
	Call	GetMsg
	tst.l	d0
	beq	\wait
	move.l	d0,a1
	move.w	in_Code(a1),d2
	moveq	#GADGETUP,d1
	cmp.l	in_Class(a1),d1
	bne	\freerequest
	move.l	in_IAddress(a1),a0      ;^Gadget
	move.w	gg_GadgetID(a0),d2
\freerequest
	move.l	a3,a0
	IntCall FreeSysRequest
	Zero	d0
	bclr	#5,d2			;force uppercase
	tst.w	d2
	beq	\endrequest		;Abbruch
	moveq	#1,d0
	cmp.w	d0,d2
	beq	\endrequest
	cmp.w	#13,d2			;Return?
	beq	\endrequest		;Zeigen
	cmp.w	#'Z',d2
	beq	\endrequest
	moveq	#2,d0
	cmp.w	d0,d2
	beq	\endrequest		;Nächstes
	cmp.w	#'W',d2
	beq	\endrequest		;N gedrückt
	Zero	d0			;andere Taste gedrückt
\endrequest				;Abbruch
	rts

_deletetemp
	move.l	DosBase(a4),a6
	tst.w	unpacked(a4)
	beq	\deleted
	lea	tempname(a4),a0
	move.l	a0,d1
	DosCall DeleteFile
	clr.w	unpacked(a4)
\deleted
	rts

;---------------------- Datenbereich ------------------------------

DosName 	dc.b	'dos.library',0
IntName 	dc.b	'intuition.library',0
GfxName 	dc.b	'graphics.library',0
AGuideName	dc.b	'amigaguide.library',0
DTypeName	dc.b	'datatypes.library',0
AslName 	dc.b	'asl.library',0
XpkName 	dc.b	'xpkmaster.library',0
Template	dc.b	'DATEI,N=NOREQ/S',0
picinfo.fmt	dc.b	'%s: %s (%dx%dx%d) %s',LF,0
EasyTitle	dc.b	'MView Meldung',0
Bodytext.fmt	dc.b LF,'Nächste Datei: %s',LF
		dc.b	'DataType: %s',0
Gadgettext	dc.b	'ZEIGEN|WEITER|ABBRUCH',0
HAM.txt 	dc.b	' (HAM)',0
EHB.txt 	dc.b	' (EHB)',0
temp.fmt	dc.b	'RAM:%s.xpk',0
version 	dc.b	'$VER:MView 1.06 (30.10.97) von J. Klawitter',0

		END
