
MODE	EQU	%0000000001100100

SCREEN	EQU	$300000
SSTACK	EQU	$400000

SNX	EQU	094
LGH	EQU	110
MNH	EQU	070
TEH	EQU	024
MEH	EQU	036

	SECTION	TEXT

	DC.W	$A00A

	CLR.L	-(SP)
	MOVE.W	#$20,-(SP)
	TRAP	#1
	ADDQ.L	#6,SP

	MOVE.L	D0,S_SSP1
	MOVE.L	SP,S_SSP2

	LEA	SSTACK,SP

	BSR	PINITS

	BSR	WITKEY

	BSR	PEXITS

	MOVE.L	S_SSP2,SP

	MOVE.L	S_SSP1,-(SP)
	MOVE.W	#$20,-(SP)
	TRAP	#1
	ADDQ.L	#6,SP

	DC.W	$A009

	CLR.W	-(SP)
	TRAP	#1

PINITS	MOVEM.L	D0-D7/A0-A6,-(SP)

	MOVE.W	#2,-(SP)
	TRAP	#14
	ADDQ.L	#2,SP

	MOVE.L	D0,S_PHY

	MOVE.W	#3,-(SP)
	TRAP	#14
	ADDQ.L	#2,SP

	MOVE.L	D0,S_LOG

	MOVE.W	#-1,-(SP)
	MOVE.W	#88,-(SP)
	TRAP	#14
	ADDQ.L	#4,SP

	MOVE.W	D0,S_MODE

	MOVE.W	#MODE,-(SP)
	MOVE.W	#3,-(SP)
	PEA	SCREEN
	PEA	SCREEN
	MOVE.W	#5,-(SP)
	TRAP	#14
	LEA	14(SP),SP

	MOVEC	CACR,D0
	MOVE.L	D0,S_CACR
	ANDI.W	#$FEFE,D0
	MOVEC	D0,CACR

	MOVE.L	$00000070.W,S_0070
	MOVE.L	$00000120.W,S_0120
	MOVE.B	$FFFFFA07.W,S_FA07
	MOVE.B	$FFFFFA13.W,S_FA13
	MOVE.B	$FFFFFA09.W,S_FA09
	MOVE.B	$FFFFFA15.W,S_FA15
	MOVE.B	$FFFFFA17.W,S_FA17

	MOVE	#$2700,SR

	CLR.B	$FFFFFA07.W
	CLR.B	$FFFFFA13.W
	CLR.B	$FFFFFA09.W
	CLR.B	$FFFFFA15.W

	MOVE.L	#VBLSNX,$0070.W
	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