*
* Main.asm - Hauptprogramm des C64-Emulators/Einstellungsfenster
*
* Copyright (C) 1994-1995 by Christian Bauer
*

		MACHINE	68020

		INCLUDE	"exec/types.i"
		INCLUDE	"exec/macros.i"
		INCLUDE	"exec/memory.i"
		INCLUDE	"exec/execbase.i"
		INCLUDE	"dos/dos.i"
		INCLUDE	"intuition/intuition.i"
		INCLUDE	"graphics/displayinfo.i"
		INCLUDE	"libraries/gadtools.i"
		INCLUDE	"libraries/asl.i"
		INCLUDE	"libraries/locale.i"
		INCLUDE	"libraries/cybergraphics.i"
		INCLUDE	"workbench/workbench.i"
		INCLUDE	"FrodoPrefs.i"
		INCLUDE	"Frodo_rev.i"
CATCOMP_NUMBERS	= 1
		INCLUDE	"Strings.i"

		XREF	_SysBase	;Startup
		XREF	_DOSBase
		XDEF	_main

		XDEF	_UtilityBase
		XDEF	_IntuitionBase
		XDEF	_GfxBase
		XDEF	_GadToolsBase
		XDEF	_AslBase
		XDEF	_EGSBase
		XDEF	_VilIntuiBase
		XDEF	_CyberGfxBase
		XDEF	_CiaBase
		XDEF	_MiscBase
		XDEF	_SID6581Base

		XDEF	ShowPrefs

		XREF	PrefsNGads

		XDEF	MainTask

		XDEF	TheLocale	;Strings.o
		XREF	GetString

		XREF	TheRAM		;6510.asm
		XREF	TheBasic
		XREF	TheKernal
		XREF	TheChar
		XREF	TheColor
		XREF	Init6510
		XREF	Start6510
		XREF	Stop6510
		XREF	Wait6510
		XREF	Pause6510
		XREF	Resume6510
		XREF	Localize6510

		XREF	Reset6526	;6526.asm
		XREF	ChangedKeys
		XREF	CIACycles
		XREF	Joystick1On
		XREF	Joystick2On
		XREF	JoystickSwap
		XREF	KeyboardYZ

		XREF	OpenGraphics	;6569.asm
		XREF	CloseGraphics
		XREF	WaitForClick
		XREF	AmigaToFront
		XREF	EmulToFront
		XREF	DisplayID
		XREF	ScreenType
		XREF	NormalCycles
		XREF	BadLineCycles
		XREF	Collisions
		XREF	Overscan
		XREF	SkipLatch

		XREF	Reset6581	;6581.asm
		XREF	ChangedSID
		XREF	PauseSound
		XREF	ResumeSound
		XREF	CloseSID
		XREF	UseSIDCard

		XREF	Open1541	;1541.asm
		XREF	Close1541
		XREF	ChangedDirs
		XREF	CloseIEC
		XREF	ChangedIEC
		XREF	Dir8
		XREF	Dir9
		XREF	Dir10
		XREF	Dir11
		XREF	Drv8IsIEC
		XREF	Drv9IsIEC
		XREF	Drv10IsIEC
		XREF	Drv11IsIEC
		XREF	OtherIEC
		XREF	MapSlash

		SECTION	"CODE",CODE


**
** Definitionen
**

; CyberGfx
CModeRequest	= -66


**
** Makros
**

; LongInt-Wert aus Integer-Gadget a0 lesen
GetInt		MACRO	;Ziel
		move.l	gg_SpecialInfo(a0),a0
		move.l	si_LongInt(a0),\1
		ENDM


**
** Hauptprogramm
**

; Task holen
_main		move.l	_SysBase,a6
		sub.l	a1,a1
		JSRLIB	FindTask
		move.l	d0,MainTask

; Libraries öffnen
		moveq	#37,d0
		lea	UtilityName,a1
		JSRLIB	OpenLibrary
		move.l	d0,_UtilityBase
		beq	NoUtility

		moveq	#37,d0
		lea	IntuiName,a1
		JSRLIB	OpenLibrary
		move.l	d0,_IntuitionBase
		beq	NoIntui

		moveq	#37,d0
		lea	GfxName,a1
		JSRLIB	OpenLibrary
		move.l	d0,_GfxBase
		beq	NoGfx

		moveq	#37,d0
		lea	GadToolsName,a1
		JSRLIB	OpenLibrary
		move.l	d0,_GadToolsBase
		beq	NoGadTools

		moveq	#38,d0
		lea	AslName,a1
		JSRLIB	OpenLibrary
		move.l	d0,_AslBase
		beq	NoAsl

		moveq	#37,d0
		lea	IconName,a1
		JSRLIB	OpenLibrary
		move.l	d0,_IconBase
		beq	NoIcon

		moveq	#0,d0
		lea	SID6581Name,a1
		JSRLIB	OpenLibrary
		move.l	d0,_SID6581Base

		lea	CiaResName,a1
		JSRLIB	OpenResource
		move.l	d0,_CiaBase
		beq	NoCiaRes

		lea	MiscResName,a1
		JSRLIB	OpenResource
		move.l	d0,_MiscBase
		beq	NoMiscRes

; Locale öffnen und Catalog laden
		move.l	_SysBase,a6
		moveq	#37,d0
		lea	LocaleName,a1
		JSRLIB	OpenLibrary
		move.l	d0,_LocaleBase
		beq	1$
		move.l	d0,a6
		sub.l	a0,a0
		lea	CatalogName,a1
		sub.l	a2,a2
		JSRLIB	OpenCatalogA
		move.l	d0,TheCatalog

; Datenstrukturen lokalisieren
1$		bsr	Localize
		bsr	Localize6510

; 68020 vorhanden?
		move.l	_SysBase,a0
		move.w	AttnFlags(a0),d0
		btst	#AFB_68020,d0
		beq	No68020Exit

; ScreenMode- und Directory-Requester holen
		move.l	_AslBase,a6
		moveq	#ASL_ScreenModeRequest,d0
		lea	ScreenReqTags,a0
		JSRLIB	AllocAslRequest
		move.l	d0,ScreenRequester
		beq	NoMemExit

		moveq	#ASL_FileRequest,d0
		lea	DirReqTags,a0
		JSRLIB	AllocAslRequest
		move.l	d0,DirRequester
		beq	NoMemExit

; Vorgegebene Einstellungen
		move.w	#63,PNormalCycles
		move.w	#23,PBadLineCycles
		move.w	#63,PCIACycles
		clr.w	PJoystick1On
		move.w	#-1,PJoystick2On
		clr.w	PJoystickSwap
		clr.l	PDisplayID
		clr.w	PScreenType
		clr.b	PDir8
		clr.b	PDir9
		clr.b	PDir10
		clr.b	PDir11
		clr.w	PUseSIDCard
		clr.w	KeyboardYZ
		move.w	#-1,PCollisions
		move.w	#-1,PMapSlash
		move.w	#-1,PFastReset
		move.w	#OSCAN_TEXT,POverscan
		move.w	#1,PSkipLatch

; Einstellungen laden
		move.l	_DOSBase,a6
		move.l	#PrefsFileName,d1
		move.l	#MODE_OLDFILE,d2
		JSRLIB	Open
		move.l	d0,d7
		beq	NoEmulPrefs

		move.l	d7,d1
		move.l	#ThePrefs,d2
		move.l	#PrefsLength,d3
		JSRLIB	Read

		move.l	d7,d1
		JSRLIB	Close
NoEmulPrefs

; Einstellungsfenster darstellen
		clr.w	PrefsFromEmul
		bsr	DoThePrefs

; Einstellungen übernehmen, wenn OK geklickt, sonst beenden
		tst.l	d7
		beq	Exit
		bsr	SetPrefs

; Dateikram vorbereiten
		jsr	Open1541
		jsr	ChangedIEC
		bsr	IECErrorReq

; Speicher für alles holen (die unteren Worte müssen mit den C64-Adressen
; übereinstimmen, außer CharROM)
		move.l	_SysBase,a6
		move.l	#$30000,d0		;192K
		move.l	#MEMF_ANY|MEMF_CLEAR,d1
		JSRLIB	AllocVec
		move.l	d0,RAMBlock
		beq	NoMemExit

		add.l	#$ffff,d0		;Auf xxxx0000 bringen
		clr.w	d0
		move.l	d0,TheRAM
		add.l	#$11000,d0
		move.l	d0,TheChar		;yyyy1000
		add.l	#$9000,d0
		move.l	d0,TheBasic		;yyyya000
		add.l	#$3800,d0
		move.l	d0,TheColor		;yyyyd800
		add.l	#$0800,d0
		move.l	d0,TheKernal		;yyyye000

; Opcodes $22 (undefiniert) ab $10000 installieren,
; für den Fall, daß ein Programm den Wraparound bei $ffff macht
		move.l	TheRAM,a0
		lea	$10000(a0),a0
		moveq	#256/4-1,d0
1$		move.l	#$22222222,(a0)+
		dbra	d0,1$

; ROMs laden
		move.l	_DOSBase,a6
		move.l	#BasicFileName,d1	;Basic
		move.l	#MODE_OLDFILE,d2
		JSRLIB	Open
		move.l	d0,d7
		beq	NoBasicExit
		move.l	d0,d1
		move.l	TheBasic,d2
		move.l	#$2000,d3
		JSRLIB	Read
		move.l	d7,d1
		JSRLIB	Close

		move.l	#KernalFileName,d1	;Kernal
		move.l	#MODE_OLDFILE,d2
		JSRLIB	Open
		move.l	d0,d7
		beq	NoKernalExit
		move.l	d0,d1
		move.l	TheKernal,d2
		move.l	#$2000,d3
		JSRLIB	Read
		move.l	d7,d1
		JSRLIB	Close

		move.l	#CharFileName,d1	;Char
		move.l	#MODE_OLDFILE,d2
		JSRLIB	Open
		move.l	d0,d7
		beq	NoCharExit
		move.l	d0,d1
		move.l	TheChar,d2
		move.l	#$1000,d3
		JSRLIB	Read
		move.l	d7,d1
		JSRLIB	Close

; Betriebssystem patchen
		move.l	TheKernal,a0
		move.w	#$f200,$0d40(a0)	;IECOut
		move.w	#$f201,$0d23(a0)	;IECOutATN
		move.w	#$f202,$0d36(a0)	;IECOutSec
		move.w	#$f203,$0e13(a0)	;IECIn
		move.w	#$f204,$0def(a0)	;IECSetATN
		move.w	#$f205,$0dbe(a0)	;IECRelATN
		move.w	#$f206,$0dcc(a0)	;IECTurnaround
		move.w	#$f207,$0e03(a0)	;IECRelease
		bsr	PatchReset

; Bildschirm öffnen
		jsr	OpenGraphics
		cmp.l	#1,d0
		beq	NoScreenExit
		cmp.l	#2,d0
		beq	NoMemExit
		cmp.l	#3,d0
		beq	NoEGSExit
		cmp.l	#4,d0
		beq	NoVilIntuiExit
		cmp.l	#5,d0
		beq	NoDisplayIDExit
		cmp.l	#6,d0
		beq	ScrTooSmallExit
		cmp.l	#7,d0
		beq	NoCyberGfxExit
		cmp.l	#8,d0
		beq	NoCyberModeExit

; Alles initialisieren
		jsr	Reset6526
		jsr	Reset6581
		jsr	Init6510

; 6510 starten
		jsr	Start6510
		tst.l	d0
		bne	NoMemExit

; Auf Mausklick warten
		jsr	WaitForClick

; Programm beenden
		bra	Exit

*
* Fehlerbehandlung/Beenden
*

		MACHINE	68000

No68020Exit	moveq	#MSG_NO68020,d0
		lea	TheLocale,a0
		jsr	GetString
		lea	ErrorReq,a1
		move.l	d0,es_TextFormat(a1)
		sub.l	a0,a0
		sub.l	a2,a2
		sub.l	a3,a3
		move.l	_IntuitionBase,a6
		JSRLIB	EasyRequestArgs
		bra	NoCiaRes

		MACHINE	68020

NoMemExit	moveq	#MSG_NOMEM,d0
		bra	ReqExit

NoScreenExit	moveq	#MSG_NOSCREEN,d0
		bra	ReqExit

NoEGSExit	moveq	#MSG_NOEGS,d0
		bra	ReqExit

NoVilIntuiExit	moveq	#MSG_NOVILINTUI,d0
		bra	ReqExit

NoCyberGfxExit	moveq	#MSG_NOCYBERGFX,d0
		bra	ReqExit

NoDisplayIDExit	moveq	#MSG_NODISPLAYID,d0
		bra	ReqExit

NoCyberModeExit	moveq	#MSG_NOCYBERMODE,d0
		bra	ReqExit

ScrTooSmallExit	moveq	#MSG_SCRTOOSMALL,d0
		bra	ReqExit

NoKernalExit	moveq	#MSG_NOKERNAL,d0
		bra	ReqExit

NoBasicExit	moveq	#MSG_NOBASIC,d0
		bra	ReqExit

NoCharExit	moveq	#MSG_NOCHAR,d0

ReqExit		lea	TheLocale,a0
		jsr	GetString
		lea	ErrorReq,a1
		move.l	d0,es_TextFormat(a1)
		sub.l	a0,a0
		sub.l	a2,a2
		sub.l	a3,a3
		move.l	_IntuitionBase,a6
		JSRLIB	EasyRequestArgs

Exit		jsr	Stop6510
		jsr	Reset6581	;Stoppt diesen Lärm!
		jsr	CloseSID
		jsr	CloseGraphics
		jsr	CloseIEC
		jsr	Close1541

		move.l	_SysBase,a6

		move.l	RAMBlock,d0
		beq	1$
		move.l	d0,a1
		JSRLIB	FreeVec

1$		move.l	DirRequester,d0
		beq	2$
		move.l	_AslBase,a6
		move.l	d0,a0
		JSRLIB	FreeAslRequest

2$		move.l	ScreenRequester,d0
		beq	3$
		move.l	_AslBase,a6
		move.l	d0,a0
		JSRLIB	FreeAslRequest

3$
		MACHINE	68000

NoMiscRes
NoCiaRes	move.l	_SysBase,a6
		move.l	_SID6581Base,d0
		beq	NoSID6581
		move.l	d0,a1
		JSRLIB	CloseLibrary

NoSID6581	move.l	_CyberGfxBase,d0
		beq	NoCyberGfx
		move.l	d0,a1
		JSRLIB	CloseLibrary

NoCyberGfx	move.l	_VilIntuiBase,d0
		beq	NoVilIntui
		move.l	d0,a1
		JSRLIB	CloseLibrary

NoVilIntui	move.l	_EGSBase,d0
		beq	NoEGS
		move.l	d0,a1
		JSRLIB	CloseLibrary

NoEGS		move.l	_LocaleBase,d0		;Catalog schließen
		beq	NoLocale
		move.l	d0,a6
		move.l	TheCatalog,a0
		JSRLIB	CloseCatalog
		move.l	a6,a1
		move.l	_SysBase,a6
		JSRLIB	CloseLibrary

NoLocale	move.l	_IconBase,a1
		JSRLIB	CloseLibrary

NoIcon		move.l	_AslBase,a1
		JSRLIB	CloseLibrary

NoAsl		move.l	_GadToolsBase,a1
		JSRLIB	CloseLibrary

NoGadTools	move.l	_GfxBase,a1
		JSRLIB	CloseLibrary

NoGfx		move.l	_IntuitionBase,a1
		JSRLIB	CloseLibrary

NoIntui		move.l	_UtilityBase,a1
		JSRLIB	CloseLibrary

NoUtility	moveq	#0,d0
		rts

		MACHINE	68020


**
** Je nach Zustand von FastReset den Speichertest aus dem ROM entfernen
**

PatchReset	move.l	TheKernal(pc),a0
		tst.w	FastReset
		bne	1$
		move.w	#$d0e8,$1d84(a0)
		rts
1$		move.w	#$a000,$1d84(a0)
		rts


**
** Preferences
**

*
* Preferences aus dem Emulator heraus
*

; C64 anhalten und nach hinten legen
ShowPrefs	jsr	Pause6510
		jsr	PauseSound
		jsr	AmigaToFront

; Aktuelle Preferences holen
		bsr	GetPrefs

; Fenster öffnen und handhaben
		move.w	#-1,PrefsFromEmul
		bsr	DoThePrefs

; Prefs setzen, wenn OK geklickt
		tst.l	d7
		beq	1$
		bsr	SetPrefs
		jsr	ChangedDirs	;Die stehen hier (und nicht in SetPrefs),
		jsr	ChangedIEC	; weil beim ersten Aufruf von SetPrefs
		bsr	IECErrorReq	; noch nicht alles initialisiert ist
		bsr	PatchReset
1$

; C64 nach vorn holen und wieder starten
		jsr	EmulToFront
		jsr	ResumeSound
		jsr	Resume6510
		rts

*
* Handhabung des Preferences-Fensters
*

; Fenster öffnen
DoThePrefs	jsr	SetupScreen
		tst.l	d0
		bne	PrefsError
		jsr	OpenPrefsWindow
		tst.l	d0
		bne	PrefsError
		bsr	SetGadgets
		move.l	PrefsWnd,ScreenReqWindow
		move.l	PrefsWnd,DirReqWindow

; EventLoop
EventLoop	move.l	_SysBase,a6
		move.l	PrefsWnd,a0
		move.l	wd_UserPort(a0),a0
		JSRLIB	WaitPort

GetEvent	move.l	_GadToolsBase,a6
		move.l	PrefsWnd,a0
		move.l	wd_UserPort(a0),a0
		JSRLIB	GT_GetIMsg
		tst.l	d0
		beq	EventLoop

		move.l	d0,a1
		move.l	im_Class(a1),TheClass
		move.w	im_Code(a1),TheCode
		move.l	im_IAddress(a1),TheGadget
		JSRLIB	GT_ReplyIMsg

; Klasse auswerten
		move.l	TheClass,d0
		and.l	#IDCMP_GADGETUP,d0
		beq	NotGadget

; GadgetUp
		move.l	TheGadget,a0

; OK
		cmp.w	#GD_OK,gg_GadgetID(a0)
		bne	1$
		moveq	#-1,d7
		bra	PrefsDone

; Cancel
1$		cmp.w	#GD_Cancel,gg_GadgetID(a0)
		bne	2$
		moveq	#0,d7
		bra	PrefsDone

; Save
2$		cmp.w	#GD_Save,gg_GadgetID(a0)
		bne	4$
		bsr	SaveThePrefs
		bra	GetEvent

; Joystick1On
4$		cmp.w	#GD_Joystick1On,gg_GadgetID(a0)
		bne	5$
		not.w	PJoystick1On
		bra	GetEvent

; Joystick2On
5$		cmp.w	#GD_Joystick2On,gg_GadgetID(a0)
		bne	6$
		not.w	PJoystick2On
		bra	GetEvent

; JoystickSwap
6$		cmp.w	#GD_JoystickSwap,gg_GadgetID(a0)
		bne	7$
		not.w	PJoystickSwap
		bra	GetEvent

; GetDisplayID
7$		cmp.w	#GD_GetDisplayID,gg_GadgetID(a0)
		bne	8$
		tst.w	PrefsFromEmul		;Nur beim Start
		bne	GetEvent

		cmp.w	#4,PScreenType		;CyberGfx?
		beq	71$

		move.l	_AslBase,a6		;Nein
		move.l	ScreenRequester,a0
		move.l	PDisplayID,ScreenReqID
		move.w	POverscan,ScreenReqOScan+2
		lea	DoScreenReqTags,a1
		JSRLIB	AslRequest
		tst.l	d0
		beq	GetEvent

		move.l	ScreenRequester,a0
		move.l	sm_DisplayID(a0),PDisplayID
		move.w	sm_OverscanType(a0),POverscan
		bsr	SetDisplayIDGad
		bra	GetEvent

71$		tst.l	_CyberGfxBase
		bne	72$
		move.l	_SysBase,a6		;Ja
		moveq	#40,d0
		lea	CyberGfxName,a1
		JSRLIB	OpenLibrary
		move.l	d0,_CyberGfxBase
		beq	GetEvent

72$		move.l	_CyberGfxBase,a6
		sub.l	a0,a0
		lea	DoCyberReqTags,a1
		move.l	Scr,CyberReqScreen
		jsr	CModeRequest(a6)
		tst.l	d0
		beq	GetEvent

		move.l	d0,PDisplayID
		bsr	SetDisplayIDGad
		bra	GetEvent

; ScreenType
8$		cmp.w	#GD_ScreenType,gg_GadgetID(a0)
		bne	9$
		tst.w	PrefsFromEmul		;Nur beim Start
		bne	GetEvent
		move.w	TheCode,PScreenType
		bra	GetEvent

; Use SID Card
9$		cmp.w	#GD_UseSIDCard,gg_GadgetID(a0)
		bne	10$
		not.w	PUseSIDCard
		bra	GetEvent

; Drive 8 is on IEC cable
10$		cmp.w	#GD_Drv8IsIEC,gg_GadgetID(a0)
		bne	11$
		not.w	PDrv8IsIEC
		beq	101$
		lea	DisableTags,a3
		bra	102$
101$		lea	EnableTags,a3
102$		lea	PrefsGadgets,a0
		move.l	GDX_Dir8*4(a0),a0
		move.l	PrefsWnd,a1
		sub.l	a2,a2
		JSRLIB	GT_SetGadgetAttrsA
		bra	GetEvent

; Drive 9 is on IEC cable
11$		cmp.w	#GD_Drv9IsIEC,gg_GadgetID(a0)
		bne	12$
		not.w	PDrv9IsIEC
		beq	111$
		lea	DisableTags,a3
		bra	112$
111$		lea	EnableTags,a3
112$		lea	PrefsGadgets,a0
		move.l	GDX_Dir9*4(a0),a0
		move.l	PrefsWnd,a1
		sub.l	a2,a2
		JSRLIB	GT_SetGadgetAttrsA
		bra	GetEvent

; Drive 10 is on IEC cable
12$		cmp.w	#GD_Drv10IsIEC,gg_GadgetID(a0)
		bne	13$
		not.w	PDrv10IsIEC
		beq	121$
		lea	DisableTags,a3
		bra	122$
121$		lea	EnableTags,a3
122$		lea	PrefsGadgets,a0
		move.l	GDX_Dir10*4(a0),a0
		move.l	PrefsWnd,a1
		sub.l	a2,a2
		JSRLIB	GT_SetGadgetAttrsA
		bra	GetEvent

; Drive 11 is on IEC cable
13$		cmp.w	#GD_Drv11IsIEC,gg_GadgetID(a0)
		bne	14$
		not.w	PDrv11IsIEC
		beq	131$
		lea	DisableTags,a3
		bra	132$
131$		lea	EnableTags,a3
132$		lea	PrefsGadgets,a0
		move.l	GDX_Dir11*4(a0),a0
		move.l	PrefsWnd,a1
		sub.l	a2,a2
		JSRLIB	GT_SetGadgetAttrsA
		bra	GetEvent

; Get Directory for drive 8
14$		cmp.w	#GD_GetDir8,gg_GadgetID(a0)
		bne	15$
		lea	SetDir8Tags,a3
		lea	PDir8,a4
		move.l	#GD_Dir8,d4
		bsr	DoGetDirName
		bra	GetEvent

; Get Directory for drive 9
15$		cmp.w	#GD_GetDir9,gg_GadgetID(a0)
		bne	16$
		lea	SetDir9Tags,a3
		lea	PDir9,a4
		move.l	#GD_Dir9,d4
		bsr	DoGetDirName
		bra	GetEvent

; Get Directory for drive 10
16$		cmp.w	#GD_GetDir10,gg_GadgetID(a0)
		bne	17$
		lea	SetDir10Tags,a3
		lea	PDir10,a4
		move.l	#GD_Dir10,d4
		bsr	DoGetDirName
		bra	GetEvent

; Get Directory for drive 11
17$		cmp.w	#GD_GetDir11,gg_GadgetID(a0)
		bne	18$
		lea	SetDir11Tags,a3
		lea	PDir11,a4
		move.l	#GD_Dir11,d4
		bsr	DoGetDirName
		bra	GetEvent

; Use IEC cable for device numbers 4-15
18$		cmp.w	#GD_OtherIEC,gg_GadgetID(a0)
		bne	19$
		not.w	POtherIEC
		bra	GetEvent

; American keyboard layout
19$		cmp.w	#GD_KeyboardYZ,gg_GadgetID(a0)
		bne	20$
		not.w	PKeyboardYZ
		bra	GetEvent

; Enable sprite collisions
20$		cmp.w	#GD_Collisions,gg_GadgetID(a0)
		bne	21$
		not.w	PCollisions
		bra	GetEvent

; Map '/' character in file names to '\'
21$		cmp.w	#GD_MapSlash,gg_GadgetID(a0)
		bne	22$
		not.w	PMapSlash
		bra	GetEvent

; Skip memory test on reset
22$		cmp.w	#GD_FastReset,gg_GadgetID(a0)
		bne	23$
		not.w	PFastReset
		bra	GetEvent

23$		bra	GetEvent

; Refresh
NotGadget	move.l	TheClass,d0
		and.l	#IDCMP_REFRESHWINDOW,d0
		beq	NotRefresh
		move.l	PrefsWnd,a0
		JSRLIB	GT_BeginRefresh
		move.l	PrefsWnd,a0
		moveq	#-1,d0
		JSRLIB	GT_EndRefresh
		bra	GetEvent

; Tastatur
NotRefresh	move.l	TheClass,d0
		and.l	#IDCMP_VANILLAKEY,d0
		beq	GetEvent

		cmp.w	#'o',TheCode		;O - OK
		bne	1$
		moveq	#-1,d7
		bra	PrefsDone

1$		cmp.w	#'s',TheCode		;S - Save
		bne	2$
		bsr	SaveThePrefs
		bra	GetEvent

2$		cmp.w	#'c',TheCode		;C - Cancel
		bne	3$
		moveq	#0,d7
		bra	PrefsDone

3$		bra	GetEvent

; Fertig mit den Prefs
PrefsDone	bsr	GetGadgets
		jsr	ClosePrefsWindow
PrefsError	jsr	CloseDownScreen
		rts

*
* Auswahl eines Verzeichnisses
* a3: Zeiger auf Tags zum Ändern des zugehörigen Stringgadgets
* a4: Zeiger auf Puffer für Namen (256 Bytes)
* d4: ID des Stringgadgets, das anschließend geändert werden soll
*

DoGetDirName	move.l	a4,a0			;Verzeichnisname kopieren
		lea	DirName,a1
		moveq	#256/4-1,d0
1$		move.l	(a0)+,(a1)+
		dbra	d0,1$

		move.l	_AslBase,a6		;Requester darstellen
		move.l	DirRequester,a0
		lea	DoDirReqTags,a1
		JSRLIB	AslRequest
		tst.l	d0
		beq	3$

		move.l	DirRequester,a0		;OK geklickt, Name zurückkopieren
		move.l	fr_Drawer(a0),a0
		move.l	a4,a1
		moveq	#256/4-1,d0
2$		move.l	(a0)+,(a1)+
		dbra	d0,2$

		move.l	_GadToolsBase,a6	;Name-Gadget neu setzen
		lea	PrefsGadgets,a0
		move.l	(a0,d4.w*4),a0
		move.l	PrefsWnd,a1
		sub.l	a2,a2			;a3 enthält bereits den Zeiger auf die Tags
		JSRLIB	GT_SetGadgetAttrsA

3$		rts

*
* Gadgets setzen
*

SetCheckGad	MACRO	;Name
		tst.w	P\1
		beq	\@1$
		move.l	GDX_\1*4(a5),a0
		move.l	PrefsWnd,a1
		sub.l	a2,a2
		lea	SetCheckTags,a3
		JSRLIB	GT_SetGadgetAttrsA
\@1$
		ENDM

SetGadgets	move.l	_GadToolsBase,a6
		lea	PrefsGadgets,a5

		move.l	GDX_NormalCycles*4(a5),a0
		move.l	PrefsWnd,a1
		sub.l	a2,a2
		lea	SetIntegerTags,a3
		moveq	#0,d0
		move.w	PNormalCycles,d0
		move.l	d0,SetIntTagsVal
		JSRLIB	GT_SetGadgetAttrsA

		move.l	GDX_BadLineCycles*4(a5),a0
		move.l	PrefsWnd,a1
		sub.l	a2,a2
		lea	SetIntegerTags,a3
		moveq	#0,d0
		move.w	PBadLineCycles,d0
		move.l	d0,SetIntTagsVal
		JSRLIB	GT_SetGadgetAttrsA

		move.l	GDX_CIACycles*4(a5),a0
		move.l	PrefsWnd,a1
		sub.l	a2,a2
		lea	SetIntegerTags,a3
		moveq	#0,d0
		move.w	PCIACycles,d0
		move.l	d0,SetIntTagsVal
		JSRLIB	GT_SetGadgetAttrsA

		move.l	GDX_SkipLatch*4(a5),a0
		move.l	PrefsWnd,a1
		sub.l	a2,a2
		lea	SetIntegerTags,a3
		moveq	#0,d0
		move.w	PSkipLatch,d0
		move.l	d0,SetIntTagsVal
		JSRLIB	GT_SetGadgetAttrsA

		SetCheckGad	Joystick1On
		SetCheckGad	Joystick2On
		SetCheckGad	JoystickSwap
		SetCheckGad	UseSIDCard
		SetCheckGad	KeyboardYZ
		SetCheckGad	Collisions
		SetCheckGad	FastReset
		SetCheckGad	Drv8IsIEC
		SetCheckGad	Drv9IsIEC
		SetCheckGad	Drv10IsIEC
		SetCheckGad	Drv11IsIEC
		SetCheckGad	OtherIEC
		SetCheckGad	MapSlash

		tst.w	PDrv8IsIEC
		beq	6$
		move.l	GDX_Dir8*4(a5),a0
		move.l	PrefsWnd,a1
		sub.l	a2,a2
		lea	DisableTags,a3
		JSRLIB	GT_SetGadgetAttrsA

6$		tst.w	PDrv9IsIEC
		beq	7$
		move.l	GDX_Dir9*4(a5),a0
		move.l	PrefsWnd,a1
		sub.l	a2,a2
		lea	DisableTags,a3
		JSRLIB	GT_SetGadgetAttrsA

7$		tst.w	PDrv10IsIEC
		beq	8$
		move.l	GDX_Dir10*4(a5),a0
		move.l	PrefsWnd,a1
		sub.l	a2,a2
		lea	DisableTags,a3
		JSRLIB	GT_SetGadgetAttrsA

8$		tst.w	PDrv11IsIEC
		beq	9$
		move.l	GDX_Dir11*4(a5),a0
		move.l	PrefsWnd,a1
		sub.l	a2,a2
		lea	DisableTags,a3
		JSRLIB	GT_SetGadgetAttrsA

9$		move.l	GDX_ScreenType*4(a5),a0
		move.l	PrefsWnd,a1
		sub.l	a2,a2
		lea	SetCycleTags,a3
		moveq	#0,d0
		move.w	PScreenType,d0
		move.l	d0,SetCycTagsVal
		JSRLIB	GT_SetGadgetAttrsA

		move.l	GDX_Dir8*4(a5),a0
		move.l	PrefsWnd,a1
		sub.l	a2,a2
		lea	SetDir8Tags,a3
		JSRLIB	GT_SetGadgetAttrsA

		move.l	GDX_Dir9*4(a5),a0
		move.l	PrefsWnd,a1
		sub.l	a2,a2
		lea	SetDir9Tags,a3
		JSRLIB	GT_SetGadgetAttrsA

		move.l	GDX_Dir10*4(a5),a0
		move.l	PrefsWnd,a1
		sub.l	a2,a2
		lea	SetDir10Tags,a3
		JSRLIB	GT_SetGadgetAttrsA

		move.l	GDX_Dir11*4(a5),a0
		move.l	PrefsWnd,a1
		sub.l	a2,a2
		lea	SetDir11Tags,a3
		JSRLIB	GT_SetGadgetAttrsA

		tst.w	PrefsFromEmul		;Vom Emulator aufgerufen:
		beq	1$			; Bildschirmtyp und -modus
		move.l	GDX_GetDisplayID*4(a5),a0 ; ausschalten
		move.l	PrefsWnd,a1
		sub.l	a2,a2
		lea	DisableTags,a3
		JSRLIB	GT_SetGadgetAttrsA

		move.l	GDX_ScreenType*4(a5),a0
		move.l	PrefsWnd,a1
		sub.l	a2,a2
		lea	DisableTags,a3
		JSRLIB	GT_SetGadgetAttrsA

1$		bra	SetDisplayIDGad

*
* DisplayID-Gadget setzen
*

SetDisplayIDGad move.l	_GfxBase,a6		;DisplayID
		sub.l	a0,a0
		lea	ModeNameBuf,a1
		moveq	#nif_SIZEOF,d0
		move.l	#DTAG_NAME,d1
		move.l	PDisplayID,d2
		JSRLIB	GetDisplayInfoData
		move.l	_GadToolsBase,a6
		lea	PrefsGadgets,a0
		move.l	GDX_DisplayID*4(a0),a0
		move.l	PrefsWnd,a1
		sub.l	a2,a2
		lea	SetDIDTags,a3
		JMPLIB	GT_SetGadgetAttrsA

*
* Gadgets holen
*

GetGadgets	lea	PrefsGadgets,a1
		move.l	GDX_NormalCycles*4(a1),a0
		GetInt	d0
		move.w	d0,PNormalCycles

		move.l	GDX_BadLineCycles*4(a1),a0
		GetInt	d0
		move.w	d0,PBadLineCycles

		move.l	GDX_CIACycles*4(a1),a0
		GetInt	d0
		move.w	d0,PCIACycles

		move.l	GDX_SkipLatch*4(a1),a0
		GetInt	d0
		move.w	d0,PSkipLatch

		move.l	GDX_Dir8*4(a1),a0
		move.l	gg_SpecialInfo(a0),a0
		move.l	si_Buffer(a0),a0
		lea	PDir8,a2
		moveq	#256/4-1,d0
11$		move.l	(a0)+,(a2)+
		dbra	d0,11$

		move.l	GDX_Dir9*4(a1),a0
		move.l	gg_SpecialInfo(a0),a0
		move.l	si_Buffer(a0),a0
		lea	PDir9,a2
		moveq	#256/4-1,d0
12$		move.l	(a0)+,(a2)+
		dbra	d0,12$

		move.l	GDX_Dir10*4(a1),a0
		move.l	gg_SpecialInfo(a0),a0
		move.l	si_Buffer(a0),a0
		lea	PDir10,a2
		moveq	#256/4-1,d0
13$		move.l	(a0)+,(a2)+
		dbra	d0,13$

		move.l	GDX_Dir11*4(a1),a0
		move.l	gg_SpecialInfo(a0),a0
		move.l	si_Buffer(a0),a0
		lea	PDir11,a2
		moveq	#256/4-1,d0
14$		move.l	(a0)+,(a2)+
		dbra	d0,14$
		rts

*
* Einstellungen setzen
*

SetPrefs	move.w	PNormalCycles,NormalCycles
		move.w	PBadLineCycles,BadLineCycles
		move.w	PCIACycles,CIACycles
		move.w	PJoystick1On,Joystick1On
		move.w	PJoystick2On,Joystick2On
		move.w	PJoystickSwap,JoystickSwap
		move.w	PDrv8IsIEC,Drv8IsIEC
		move.w	PDrv9IsIEC,Drv9IsIEC
		move.w	PDrv10IsIEC,Drv10IsIEC
		move.w	PDrv11IsIEC,Drv11IsIEC
		move.w	POtherIEC,OtherIEC
		move.w	PCollisions,Collisions
		move.w	POverscan,Overscan
		move.w	PMapSlash,MapSlash
		move.w	PFastReset,FastReset

		move.w	PSkipLatch,SkipLatch
		bne	2$
		move.w	#1,SkipLatch		;Keine Null zulassen
2$
		tst.w	PrefsFromEmul
		bne	1$
		move.l	PDisplayID,DisplayID	;Nur beim Start
		move.w	PScreenType,ScreenType
1$
		lea	PDir8,a0
		lea	Dir8,a1
		moveq	#256/4-1,d0
11$		move.l	(a0)+,(a1)+
		dbra	d0,11$

		lea	PDir9,a0
		lea	Dir9,a1
		moveq	#256/4-1,d0
12$		move.l	(a0)+,(a1)+
		dbra	d0,12$

		lea	PDir10,a0
		lea	Dir10,a1
		moveq	#256/4-1,d0
13$		move.l	(a0)+,(a1)+
		dbra	d0,13$

		lea	PDir11,a0
		lea	Dir11,a1
		moveq	#256/4-1,d0
14$		move.l	(a0)+,(a1)+
		dbra	d0,14$

		move.w	PUseSIDCard,UseSIDCard
		jsr	ChangedSID

		move.w	PKeyboardYZ,KeyboardYZ
		jmp	ChangedKeys

*
* Einstellungen holen
*

GetPrefs	move.w	NormalCycles,PNormalCycles
		move.w	BadLineCycles,PBadLineCycles
		move.w	CIACycles,PCIACycles
		move.w	Joystick1On,PJoystick1On
		move.w	Joystick2On,PJoystick2On
		move.w	JoystickSwap,PJoystickSwap
		move.w	UseSIDCard,PUseSIDCard
		move.w	Drv8IsIEC,PDrv8IsIEC
		move.w	Drv9IsIEC,PDrv9IsIEC
		move.w	Drv10IsIEC,PDrv10IsIEC
		move.w	Drv11IsIEC,PDrv11IsIEC
		move.w	OtherIEC,POtherIEC
		move.w	KeyboardYZ,PKeyboardYZ
		move.w	Collisions,PCollisions
		move.w	Overscan,POverscan
		move.w	MapSlash,PMapSlash
		move.w	FastReset,PFastReset
		move.l	DisplayID,PDisplayID
		move.w	ScreenType,PScreenType
		move.w	SkipLatch,PSkipLatch

		lea	Dir8,a0
		lea	PDir8,a1
		moveq	#256/4-1,d0
11$		move.l	(a0)+,(a1)+
		dbra	d0,11$

		lea	Dir9,a0
		lea	PDir9,a1
		moveq	#256/4-1,d0
12$		move.l	(a0)+,(a1)+
		dbra	d0,12$

		lea	Dir10,a0
		lea	PDir10,a1
		moveq	#256/4-1,d0
13$		move.l	(a0)+,(a1)+
		dbra	d0,13$

		lea	Dir11,a0
		lea	PDir11,a1
		moveq	#256/4-1,d0
14$		move.l	(a0)+,(a1)+
		dbra	d0,14$
		rts

*
* Einstellungen speichern
*

SaveThePrefs	bsr	GetGadgets

		move.l	_DOSBase,a6		;Datei öffnen
		move.l	#PrefsFileName,d1
		move.l	#MODE_NEWFILE,d2
		JSRLIB	Open
		move.l	d0,d6
		beq	2$

		move.l	d6,d1			;Einstellungen schreiben
		move.l	#ThePrefs,d2
		move.l	#PrefsLength,d3
		JSRLIB	Write

		move.l	d6,d1			;Datei schließene
		JSRLIB	Close

		move.l	_IconBase,a6		;Icon bereits vorhanden?
		lea	PrefsFileName,a0
		JSRLIB	GetDiskObject
		tst.l	d0
		beq	1$
		move.l	d0,a0			;Ja, dann nichts machen
		JSRLIB	FreeDiskObject
		rts

1$		lea	PrefsFileName,a0	;Nein, Icon erzeugen
		lea	PrefsIcon,a1
		JSRLIB	PutDiskObject
2$		rts

*
* Requester entsprechend dem Rückgabewert von ChangedIEC anzeigen
* d0: Rückgabewert
*

IECErrorReq	tst.l	d0
		beq	1$
		cmp.l	#1,d0
		bne	2$
		lea	NoParPortReq,a1
		bra	3$
2$		lea	NoTimerReq,a1
3$		move.l	a6,-(sp)
		move.l	_IntuitionBase,a6
		sub.l	a0,a0
		move.l	a0,a2
		move.l	a0,a3
		JSRLIB	EasyRequestArgs
		move.l	(sp)+,a6
1$		rts


*
* Strings in Datenstrukturen lokalisieren
*

GetStr		MACRO	;Label
		lea	TheLocale,a0
		move.l	#\1,d0
		jsr	GetString
		ENDM

Localize	move.l	_UtilityBase,a6

		GetStr	MSG_REQTITLE
		move.l	d0,ErrorReq+es_Title
		move.l	d0,NoParPortReq+es_Title
		move.l	d0,NoTimerReq+es_Title

		GetStr	MSG_SCREENTITLE
		move.l	d0,d2
		lea	PrefsWindowTags,a0
		move.l	#WA_ScreenTitle,d0
		JSRLIB	FindTagItem
		move.l	d0,a0
		move.l	d2,4(a0)

		GetStr	MSG_PREFSTITLE
		move.l	d0,d2
		lea	PrefsWindowTags,a0
		move.l	#WA_Title,d0
		JSRLIB	FindTagItem
		move.l	d0,a0
		move.l	d2,4(a0)

		GetStr	MSG_REQGADS
		move.l	d0,ErrorReq+es_GadgetFormat

		GetStr	MSG_REQGADS2
		move.l	d0,NoParPortReq+es_GadgetFormat
		move.l	d0,NoTimerReq+es_GadgetFormat

		GetStr	MSG_NOPARPORT
		move.l	d0,NoParPortReq+es_TextFormat

		GetStr	MSG_NOTIMER
		move.l	d0,NoTimerReq+es_TextFormat

		GetStr	MSG_SCREENHAIL
		move.l	d0,ScreenHailText
		move.l	d0,CyberHailText

		GetStr	MSG_DIRHAIL
		move.l	d0,DirHailText

		lea	GadTransTable,a2
		lea	PrefsNGads,a3
1$		lea	TheLocale,a0
		move.l	(a2)+,d0
		beq	2$
		jsr	GetString
		move.l	(a2)+,d1
		mulu.l	#gng_SIZEOF,d1
		move.l	d0,gng_GadgetText(a3,d1.w)
		bra	1$
2$		rts

GadTransTable	dc.l	MSG_OK_GAD,GDX_OK
		dc.l	MSG_SAVE_GAD,GDX_Save
		dc.l	MSG_CANCEL_GAD,GDX_Cancel
		dc.l	MSG_JOYSTICK1ON_GAD,GDX_Joystick1On
		dc.l	MSG_JOYSTICK2ON_GAD,GDX_Joystick2On
		dc.l	MSG_JOYSTICKSWAP_GAD,GDX_JoystickSwap
		dc.l	MSG_GETDISPLAYID_GAD,GDX_GetDisplayID
		dc.l	MSG_DISPLAYID_GAD,GDX_DisplayID
		dc.l	MSG_SCREENTYPE_GAD,GDX_ScreenType
		dc.l	MSG_NORMALCYCLES_GAD,GDX_NormalCycles
		dc.l	MSG_BADLINECYCLES_GAD,GDX_BadLineCycles
		dc.l	MSG_CIACYCLES_GAD,GDX_CIACycles
		dc.l	MSG_DIR8_GAD,GDX_Dir8
		dc.l	MSG_DIR9_GAD,GDX_Dir9
		dc.l	MSG_DIR10_GAD,GDX_Dir10
		dc.l	MSG_DIR11_GAD,GDX_Dir11
		dc.l	MSG_USESIDCARD_GAD,GDX_UseSIDCard
		dc.l	MSG_OTHERIEC_GAD,GDX_OtherIEC
		dc.l	MSG_KEYBOARDYZ_GAD,GDX_KeyboardYZ
		dc.l	MSG_COLLISIONS_GAD,GDX_Collisions
		dc.l	MSG_MAPSLASH_GAD,GDX_MapSlash
		dc.l	MSG_FASTRESET_GAD,GDX_FastReset
		dc.l	MSG_SKIPLATCH_GAD,GDX_SkipLatch
		dc.l	0,0


**
** Konstanten
**

; Strings
Version		VERSTAG
UtilityName	dc.b	"utility.library",0
IntuiName	dc.b	"intuition.library",0
GfxName		dc.b	"graphics.library",0
GadToolsName	dc.b	"gadtools.library",0
AslName		dc.b	"asl.library",0
IconName	dc.b	"icon.library",0
LocaleName	dc.b	"locale.library",0
SID6581Name	dc.b	"6581sid.library",0
CyberGfxName	dc.b	"cybergraphics.library",0
CiaResName	dc.b	"ciaa.resource",0
MiscResName	dc.b	"misc.resource",0

CatalogName	dc.b	"Frodo.catalog",0
PrefsFileName	dc.b	"PROGDIR:Frodo Prefs",0
BasicFileName	dc.b	"PROGDIR:Basic ROM",0
KernalFileName	dc.b	"PROGDIR:Kernal ROM",0
CharFileName	dc.b	"PROGDIR:Char ROM",0
		CNOP	0,4


**
** Datenbereich
**

_UtilityBase	dc.l	0
_IntuitionBase	dc.l	0
_GfxBase	dc.l	0
_GadToolsBase	dc.l	0
_AslBase	dc.l	0
_IconBase	dc.l	0
_EGSBase	dc.l	0
_VilIntuiBase	dc.l	0
_CyberGfxBase	dc.l	0
_SID6581Base	dc.l	0
_CiaBase	dc.l	0
_MiscBase	dc.l	0

TheLocale			;Struktur für GetString
_LocaleBase	dc.l	0
TheCatalog	dc.l	0

MainTask	dc.l	0	;Emulator-Haupttask

ScreenRequester	dc.l	0	;ScreenMode-Requester
DirRequester	dc.l	0	;Directory-Requester

RAMBlock	dc.l	0	;Zeiger auf Speicherbereich

TheClass	dc.l	0	;Für Preferences
TheGadget	dc.l	0
TheCode		dc.w	0

PrefsFromEmul	dc.w	0	;#0: Einstellungen vom Emulator aus aufgerufen

; Prefs-Icon
PrefsIcon	dc.w	WB_DISKMAGIC,WB_DISKVERSION
		dc.l	0
		dc.w	0,0,54,23
		dc.w	4,1,1
		dc.l	PrefsI1,0,0,0,0
		dc.w	0
		dc.l	1
		dc.b	WBPROJECT,0
		dc.l	0,0
		dc.l	NO_ICON_POSITION,NO_ICON_POSITION
		dc.l	0,0,0

; Image für Prefs-Icon
PrefsI1		dc.w	0,0,54,22,8
		dc.l	PrefsI1Data
		dc.b	255,0
		dc.l	0

; Requester
ErrorReq	dc.l	20,0,0,0,0
NoParPortReq	dc.l	20,0,0,0,0
NoTimerReq	dc.l	20,0,0,0,0

; Tags zum Setzen von Gadgets
SetDir8Tags	dc.l	GTST_String,PDir8
		dc.l	0,0
SetDir9Tags	dc.l	GTST_String,PDir9
		dc.l	0,0
SetDir10Tags	dc.l	GTST_String,PDir10
		dc.l	0,0
SetDir11Tags	dc.l	GTST_String,PDir11
		dc.l	0,0
SetIntegerTags	dc.l	GTIN_Number
SetIntTagsVal	dc.l	0
		dc.l	0,0
SetCheckTags	dc.l	GTCB_Checked,-1
		dc.l	0,0
SetCycleTags	dc.l	GTCY_Active
SetCycTagsVal	dc.l	0
		dc.l	0,0
SetDIDTags	dc.l	GTTX_Text,ModeNameBuf+16
		dc.l	0,0
DisableTags	dc.l	GA_Disabled,-1
		dc.l	0,0
EnableTags	dc.l	GA_Disabled,0
		dc.l	0,0

; Tags für ScreenMode-Requester
ScreenReqTags	dc.l	ASLSM_TitleText
ScreenHailText	dc.l	0
		dc.l	ASLSM_SleepWindow,-1
		dc.l	ASLSM_DoOverscanType,-1
		dc.l	ASLSM_PropertyMask,DIPF_IS_HAM|DIPF_IS_EXTRAHALFBRITE|DIPF_IS_DUALPF
		dc.l	ASLSM_PropertyFlags,0
		dc.l	0,0

DoScreenReqTags	dc.l	ASLSM_InitialDisplayID
ScreenReqID	dc.l	0
		dc.l	ASLSM_InitialOverscanType
ScreenReqOScan	dc.l	0
		dc.l	ASLSM_Window
ScreenReqWindow	dc.l	0
		dc.l	0,0

DoCyberReqTags	dc.l	CYBRMREQ_Screen
CyberReqScreen	dc.l	0
		dc.l	CYBRMREQ_WinTitle
CyberHailText	dc.l	0
		dc.l	CYBRMREQ_MinWidth,384
		dc.l	CYBRMREQ_MinHeight,272
		dc.l	CYBRMREQ_MaxDepth,8
		dc.l	0,0

; Tags für den Directory-Requester
DirReqTags	dc.l	ASLFR_TitleText
DirHailText	dc.l	0
		dc.l	ASLFR_SleepWindow,-1
		dc.l	ASLFR_Flags2,FRF_REJECTICONS|FRF_DRAWERSONLY
		dc.l	0,0

DoDirReqTags	dc.l	ASLFR_InitialDrawer,DirName
		dc.l	ASLFR_Window
DirReqWindow	dc.l	0
		dc.l	0,0


**
** Icon-Daten
**

		SECTION	"CHIPDATA",DATA,CHIP

PrefsI1Data	dc.w	$0000,$0000,$0000,$0400,$0000,$0000,$0000,$0C00
		dc.w	$0003,$FFC0,$0000,$0C00,$000C,$0030,$0000,$0C00
		dc.w	$0010,$7E08,$0000,$0C00,$0020,$8104,$0000,$0C00
		dc.w	$0020,$4104,$0000,$0C00,$0020,$4104,$0000,$0C00
		dc.w	$0010,$8204,$0000,$0C00,$000F,$0C08,$0000,$0C00
		dc.w	$0000,$3010,$0000,$0C00,$0000,$4060,$0000,$0C00
		dc.w	$0000,$8180,$0000,$0C00,$0001,$0E00,$0000,$0C00
		dc.w	$0000,$8400,$0000,$0C00,$0000,$7800,$0000,$0C00
		dc.w	$0000,$8400,$0000,$0C00,$0000,$8400,$0000,$0C00
		dc.w	$0000,$7800,$0000,$0C00,$0000,$0000,$0000,$0C00
		dc.w	$0000,$0000,$0000,$0C00,$7FFF,$FFFF,$FFFF,$FC00

		dc.w	$FFFF,$FFFF,$FFFF,$F800,$D555,$5557,$D555,$5000
		dc.w	$D554,$001F,$F555,$5000,$D553,$FFCF,$F555,$5000
		dc.w	$D54F,$81F7,$F555,$5000,$D55F,$54FB,$F555,$5000
		dc.w	$D55F,$94FB,$FFD5,$5000,$D55F,$94F9,$7FF5,$5000
		dc.w	$D54F,$55F9,$7FD5,$5000,$D550,$53F5,$7FD5,$5000
		dc.w	$D555,$4FE5,$5F55,$5000,$D555,$3F95,$60D5,$5000
		dc.w	$D555,$7E7D,$6055,$5000,$D554,$F1FD,$6035,$5000
		dc.w	$D555,$79FF,$FFD5,$5000,$D555,$05FF,$F555,$5000
		dc.w	$D555,$797F,$F555,$5000,$D555,$797F,$F555,$5000
		dc.w	$D555,$055F,$F555,$5000,$D555,$5557,$D555,$5000
		dc.w	$D555,$5555,$5555,$5000,$8000,$0000,$0000,$0000

		dc.w	$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000
		dc.w	$0000,$0007,$C000,$0000,$0000,$000F,$E000,$0000
		dc.w	$0000,$0007,$E000,$0000,$0000,$0003,$E000,$0000
		dc.w	$0000,$0000,$6000,$0000,$0000,$0000,$1FC0,$0000
		dc.w	$0000,$0000,$1F80,$0000,$0000,$0000,$1F00,$0000
		dc.w	$0000,$0000,$0000,$0000,$0000,$0000,$1F00,$0000
		dc.w	$0000,$0070,$1F80,$0000,$0000,$00F0,$1FC0,$0000
		dc.w	$0000,$00FC,$6000,$0000,$0000,$007F,$E000,$0000
		dc.w	$0000,$003F,$E000,$0000,$0000,$001F,$E000,$0000
		dc.w	$0000,$0007,$C000,$0000,$0000,$0000,$0000,$0000
		dc.w	$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000

		dc.w	$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000
		dc.w	$0000,$0007,$C000,$0000,$0000,$000F,$E000,$0000
		dc.w	$0000,$0007,$E000,$0000,$0000,$0003,$E000,$0000
		dc.w	$0000,$0000,$6000,$0000,$0000,$0000,$1FC0,$0000
		dc.w	$0000,$0000,$1F80,$0000,$0000,$0000,$1F00,$0000
		dc.w	$0000,$0000,$0000,$0000,$0000,$0000,$1F00,$0000
		dc.w	$0000,$0070,$1F80,$0000,$0000,$00F0,$1FC0,$0000
		dc.w	$0000,$00FC,$6000,$0000,$0000,$007F,$E000,$0000
		dc.w	$0000,$003F,$E000,$0000,$0000,$001F,$E000,$0000
		dc.w	$0000,$0007,$C000,$0000,$0000,$0000,$0000,$0000
		dc.w	$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000

		dc.w	$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000
		dc.w	$0000,$0007,$C000,$0000,$0000,$000F,$E000,$0000
		dc.w	$0000,$0007,$E000,$0000,$0000,$0003,$E000,$0000
		dc.w	$0000,$0000,$6000,$0000,$0000,$0000,$1FC0,$0000
		dc.w	$0000,$0000,$1F80,$0000,$0000,$0000,$1F00,$0000
		dc.w	$0000,$0000,$0000,$0000,$0000,$0000,$1F00,$0000
		dc.w	$0000,$0070,$1F80,$0000,$0000,$00F0,$1FC0,$0000
		dc.w	$0000,$00FC,$6000,$0000,$0000,$007F,$E000,$0000
		dc.w	$0000,$003F,$E000,$0000,$0000,$001F,$E000,$0000
		dc.w	$0000,$0007,$C000,$0000,$0000,$0000,$0000,$0000
		dc.w	$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000

		dc.w	$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000
		dc.w	$0000,$0007,$C000,$0000,$0000,$000F,$E000,$0000
		dc.w	$0000,$0007,$E000,$0000,$0000,$0003,$E000,$0000
		dc.w	$0000,$0000,$6000,$0000,$0000,$0000,$1FC0,$0000
		dc.w	$0000,$0000,$1F80,$0000,$0000,$0000,$1F00,$0000
		dc.w	$0000,$0000,$0000,$0000,$0000,$0000,$1F00,$0000
		dc.w	$0000,$0070,$1F80,$0000,$0000,$00F0,$1FC0,$0000
		dc.w	$0000,$00FC,$6000,$0000,$0000,$007F,$E000,$0000
		dc.w	$0000,$003F,$E000,$0000,$0000,$001F,$E000,$0000
		dc.w	$0000,$0007,$C000,$0000,$0000,$0000,$0000,$0000
		dc.w	$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000

		dc.w	$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000
		dc.w	$0000,$0007,$C000,$0000,$0000,$000F,$E000,$0000
		dc.w	$0000,$0007,$E000,$0000,$0000,$0003,$E000,$0000
		dc.w	$0000,$0000,$6000,$0000,$0000,$0000,$1FC0,$0000
		dc.w	$0000,$0000,$1F80,$0000,$0000,$0000,$1F00,$0000
		dc.w	$0000,$0000,$0000,$0000,$0000,$0000,$1F00,$0000
		dc.w	$0000,$0070,$1F80,$0000,$0000,$00F0,$1FC0,$0000
		dc.w	$0000,$00FC,$6000,$0000,$0000,$007F,$E000,$0000
		dc.w	$0000,$003F,$E000,$0000,$0000,$001F,$E000,$0000
		dc.w	$0000,$0007,$C000,$0000,$0000,$0000,$0000,$0000
		dc.w	$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000

		dc.w	$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000
		dc.w	$0000,$0007,$C000,$0000,$0000,$000F,$E000,$0000
		dc.w	$0000,$0007,$E000,$0000,$0000,$0003,$E000,$0000
		dc.w	$0000,$0000,$6000,$0000,$0000,$0000,$1FC0,$0000
		dc.w	$0000,$0000,$1F80,$0000,$0000,$0000,$1F00,$0000
		dc.w	$0000,$0000,$0000,$0000,$0000,$0000,$1F00,$0000
		dc.w	$0000,$0070,$1F80,$0000,$0000,$00F0,$1FC0,$0000
		dc.w	$0000,$00FC,$6000,$0000,$0000,$007F,$E000,$0000
		dc.w	$0000,$003F,$E000,$0000,$0000,$001F,$E000,$0000
		dc.w	$0000,$0007,$C000,$0000,$0000,$0000,$0000,$0000
		dc.w	$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000


**
** Nicht initialisierte Daten
**

		SECTION	"BSS",BSS
ModeNameBuf	ds.b	nif_SIZEOF	;Puffer für GetDisplayInfoData
DirName		ds.b	256		;Puffer für Directory-Requester

; Einstellungen
ThePrefs
Pdummy		ds.w	1
PNormalCycles	ds.w	1
PBadLineCycles	ds.w	1
PCIACycles	ds.w	1
PJoystick1On	ds.w	1
PJoystick2On	ds.w	1
PJoystickSwap	ds.w	1
PDisplayID	ds.l	1
PScreenType	ds.w	1
PDir8		ds.b	256
PDir9		ds.b	256
PDir10		ds.b	256
PDir11		ds.b	256
PDrv8IsIEC	ds.w	1
PDrv9IsIEC	ds.w	1
PDrv10IsIEC	ds.w	1
PDrv11IsIEC	ds.w	1
PUseSIDCard	ds.w	1
POtherIEC	ds.w	1
PKeyboardYZ	ds.w	1
PCollisions	ds.w	1
POverscan	ds.w	1
PMapSlash	ds.w	1
PFastReset	ds.w	1
PSkipLatch	ds.w	1
PrefsLength	= *-ThePrefs

FastReset	ds.w	1	;Prefs: Speichertest bei Reset abschalten

		END
