iea:	equ	$fffa07
ieb:	equ	$fffa09
isra:	equ	$fffa0f
ima:	equ	$fffa13
tbcr:	equ	$fffa1b
tbdr:	equ	$fffa21
vbl_vec:	equ	$70
key_vec:	equ	$118
hbl_vec:	equ	$120
magic:		equ	1650
numstars:	equ	12
speed:		equ	350
zclip:		equ	100
*	sound stuff	*
soundstarth:	equ	2
soundstartm:	equ	4
soundstartl:	equ	6
soundendh:	equ	$e
soundendm:	equ	$10
soundendl:	equ	$12
soundmode:	equ	$20
sounddma:	equ	0


start:
	clr.l   -(SP)           ;Go into supervisor mode
        move.w  #$20,-(SP)
        trap    #1
        addq.l  #6,SP
        move.l  D0,savesup
	dc.w	$a00a

	lea	palsave,a0
	move.l	#$ff8240,a1
	rept	8
	move.l	(a1)+,(a0)+
	endr

	move.w	#4,-(sp)
	trap	#14
	addq.l	#2,sp
	move.w	d0,ressave

	move.w	#0,-(sp)	;set to low res
	move.l	#-1,-(sp)
	move.l	#-1,-(sp)
	move.w	#5,-(sp)
	trap	#14
	add.l	#12,sp
	jsr	getscrn

	bsr	putsounds
	move.l	#picstart,d0
	add.l	#512,d0
	and.w	#%1111111100000000,d0		;make sure of boundry
	move.l	d0,picadd

	lea	pic1,a0
	lea	palettes,a1
	moveq	#7,d7
	lea	pallist,a2
cpals:
	add.l	#32000,a0
	move.l	a1,(a2)+
	bsr	copypals
	dbf	d7,cpals

	move.l	picadd,a1
	lea	pic1,a0
	lea	piclist,a2
	moveq	#7,d7
cscl:
	move.l	a1,(a2)+
	bsr	copyscreen
	add.l	#19104,a0
	dbf	d7,cscl

	move.l	#text,textpointer
mainloop:
	lea	piclist,a0
	lea	pallist,a1
	move.w	frcount,d0
	asl.w	#2,d0
	move.l	(a0,d0.w),d1	;get pic add
	move.l	(a1,d0.w),d2	;get pic add
	tst.l	d1
	bpl.s	picok
	move.w	#0,frcount
	bra	mainloop
picok:
	move.l	d1,picadd
	addq.w	#1,frcount
interlace:
	move.l	d2,-(sp)
	move.l	d1,-(sp)
	move.l	d2,-(sp)
	move.l	d1,-(sp)
	move.w	#1,-(sp)
	jsr	show512
	add.l	#18,sp
	jsr	keyboard
	bsr	dotext
	bra	mainloop

mloop2:
	lea	piclist,a0
	lea	pallist,a1
	move.w	frcount,d0
	asl.w	#2,d0
	move.l	(a0,d0.w),d1	;get pic add
	move.l	(a1,d0.w),d2	;get pic add
	tst.l	d1
	bpl.s	picok2
	move.w	#0,frcount
	bra	mloop2
picok2:
	move.l	d1,picadd
	addq.w	#1,frcount
	move.l	d2,-(sp)
	move.l	d1,-(sp)
	move.l	d2,-(sp)
	move.l	d1,-(sp)
	move.w	#1,-(sp)
	jsr	show512
	add.l	#18,sp
	jsr	keyboard
	rts
counter:	dc.w	0
*************************************************
*	Do text. Puts up text sets flags	*
*	for palette and also contains timing	*
*	info for text duration			*
*************************************************
dotext:
	subq.w	#1,texttimer
	bpl	dtback		;anything to do ?
newtext:
	move.w	#30,counter	;31 pals
	move.w	#0,coloroffset
ntloop1:
	bsr	mloop2		;-1 in fdf will be fade up
	add.w	#32,coloroffset
	sub.w	#1,counter
	bgt	ntloop1

	bsr	cleartext
	bsr	mloop2		;make sure we dont get a slow down on anim
	lea	xoffset,a1
	lea	bottom1,a2
	lea	160(a2),a2	;down a line
	lea	font,a3
pt1:	move.l	textpointer,a0	;where we are in our novel
	moveq	#0,d0
	move.b	(a0)+,d0	;get number of chars in line or end flag
	bpl	puttext		;handles wrap
	move.l	#text,textpointer
	bra	pt1
puttext:
	moveq	#0,d1
	move.b	(a1,d0.w),d1	;get xoffset for 1st char
ptl1:				;do first line
	moveq	#0,d2
	move.b	(a0)+,d2	;get char of text
	cmpi.b	#32,d2		;check for space
	beq	isspace1
	sub.b	#48,d2		;for font calc
	asl.w	#7,d2		;distance into font data
	bsr	putchar
isspace1:
	addq.w	#8,d1		;move across screen
	dbf	d0,ptl1		;do it all agian

	moveq	#0,d0
	move.b	(a0)+,d0	;get number of chars in line or end flag
line2:
	lea	bottom1,a2
	lea	160*18(a2),a2	;down a 16 lines
	moveq	#0,d1
	move.b	(a1,d0.w),d1	;get xoffset for 1st char
ptl2:				;do first line
	moveq	#0,d2
	move.b	(a0)+,d2	;get char of text
	cmpi.b	#32,d2		;check for space
	beq	isspace2
	sub.b	#48,d2		;for font calc
	asl.w	#7,d2		;distance into font data
	bsr	putchar
isspace2:
	addq.w	#8,d1		;move across screen
	dbf	d0,ptl2		;do it all agian
	moveq	#0,d0
	move.b	(a0)+,d0
	asl.w	#3,d0		;max time of 255*8
	move.w	d0,texttimer
	move.l	a0,textpointer

textend:
	move.w	#30,counter	;31 pals
	move.w	#30*32,coloroffset
ntloop2:
	bsr	mloop2		;-1 in fdf will be fade up
	sub.w	#32,coloroffset
	sub.w	#1,counter
	bgt	ntloop2
dtback:
	rts

*************************************************
*	screen add in a2 font in a3		*
*	d2 is offset into font d1 is offset 	*
*	across screen				*
*************************************************
putchar:
	move.l	a2,a6
	move.l	a3,a5
	add.w	d1,a6
	add.w	d2,a5
	rept	16
	move.l	(a5)+,(a6)+
	move.l	(a5)+,(a6)+
	lea	160-8(a6),a6
	endr
	rts


xoffset:
	dc.b	80		;bytes across to start of char cell
	dc.b	72,72,64,64,56,56,48,48,40,40,32,32,24,24,16,16,8,8,0,0

textpointer:	dc.l	0
texttimer:	dc.w	100
coloroffset:	dc.w	0
text:			;notE 40 chars max per text bit
	dc.b	19,'HERES ANOTHER LITTLE'	;19=num of chars for line-1
	dc.b	12,'STE DEMO FROM',20		;timing
	DC.B	12,'MOVING PIXELS'
	DC.B	00,' ',40
	DC.B	18,'THIS ONE BRINGS YOU'
	DC.B	00,' ',15
	DC.B	19,'512 COLOUR ANIMATION'
	DC.B	00,' ',15
	DC.B	14,'DIGITISED SOUND'
	DC.B	00,' ',15
	DC.B	16,'AND A BORING TEXT'
	DC.B	06,'ROUTINE',15
	DC.B	15,'SORRY THERES NOT'
	DC.B	15,'ENOUGH PROCESSOR',10
	DC.B	12,'TIME LEFT FOR'
	DC.B	17,'TRACKER TYPE MUSIC',10
	DC.B	18,'ALL THE PROGRAMMING'
	DC.B	10,'WAS DONE BY',10
	DC.B	10,'TONY BARKER'
	DC.B	00,' ',30
	DC.B	14,'YOU CAN CONTACT'
	DC.B	04,'ME AT',10
	DC.B	03,'2\39'
	DC.B	08,'FRAZER ST',10
	DC.B	18,'LEICHHARDT NSW 2040'
	DC.B	08,'AUSTRALIA',13
**		00,'01234567890123456789'
	DC.B	04,'PHONE'
	DC.B	10,'02 555 7312',10
	DC.B	15,'OR CONTACT ATARI'
	DC.B	08,'AUSTRALIA',7
	DC.B	16,'THEY USUALLY KNOW'
	DC.B	15,'WHERE TO FIND ME',15
	DC.B	17,'DONT YOU JUST HATE'
	DC.B	00,' ',1
	DC.B	15,'IT WHEN THE TEXT'
	DC.B	00,' ',1
	DC.B	19,'GOES BY WAY TOO FAST'
	DC.B	00,' ',1
	DC.B	17,'SEND ME SOME DEMOS'
	DC.B	00,' ',5
	DC.B	18,'SEND ME SOME SOURCE'
	DC.B	00,' ',5
	DC.B	17,'SEND ME SOME MONEY'
	DC.B	00,' ',5
	DC.B	06,'OR JUST'
	DC.B	18,'SEND ME A POST CARD',5
	DC.B	14,'I WOULD LIKE TO'
	DC.B	18,'KNOW WHAT YOU THINK',15
	DC.B	17,'HELLO TO EVERYBODY'
	DC.B	11,'WHO KNOWS ME',5
	dc.b	08,'SPECIALLY'
	DC.B	11,'GARY SPITERI',10
	DC.B	18,'WHO MAY HAVE HELPED'
	DC.B	13,'WITH THE MUSIC',10
**		00,'01234567890123456789'
	DC.B	16,'DEPENDING ON WHAT'
	DC.B	17,'YOURE LISTENING TO',10
	DC.B	06,'BYE BYE'
	DC.B	00,' ',10
	DC.B	01,'10'
	DC.B	00,' ',0
	DC.B	00,'9'
	DC.B	00,' ',0
	DC.B	00,'8'
	DC.B	00,' ',0
	DC.B	00,'7'
	DC.B	00,' ',0
	DC.B	00,'6'
	DC.B	00,' ',0
	DC.B	00,'5'
	DC.B	00,' ',0
	DC.B	00,'4'
	DC.B	00,' ',0
	DC.B	00,'3'
	DC.B	00,' ',0
	DC.B	00,'2'
	DC.B	00,' ',0
	DC.B	00,'1'
	DC.B	00,' ',0
	DC.B	00,'0'
	DC.B	00,' ',0
**		00,'01234567890123456789'
	DC.B	11,'TIME TO WRAP'
	DC.B	00,' ',10
	DC.B	-1				;WRAP FLAG
	even

cleartext:
	lea	bottom2,a6
	moveq	#0,d0
	move.l	d0,d1
	move.l	d1,d2
	move.l	d1,d3
	move.l	d1,d4
	move.l	d1,d5
	move.l	d1,d6
	move.l	d1,d7
	move.l	d1,a0
	move.l	d1,a1
	move.l	d1,a2
	move.l	d1,a3
	move.l	d1,a4
	rept	160
	movem.l	d0-a4,-(a6)
	endr
	rts


frcount:	dc.w	0
picadd:		dc.l	0
copyscreen:
	move	#7999,d0
cspl:
	move.l	(a0)+,(a1)+
	dbf	d0,cspl
	rts
copypals:
	move	#4776-1,d0
cpal:
	move.l	(a0)+,(a1)+
	dbf	d0,cpal
	rts

*********************************************
putsounds:
	move.w	#$7ff,$ff8924
settreb:
	cmpi.w	#$7ff,$ff8924
	bne	settreb
	move.w	#%0000010010001100,d0		;010 for treb vol
	move.w	d0,$ff8922			;send data
setbass:
	cmpi.w	#$7ff,$ff8924
	bne	setbass
	move.w	#%0000010001000110,d0		;010 for treb vol
	move.w	d0,$ff8922			;send data
	move.l	#sound,d0
	move.l	#sounde,d1
*****************************************
*	new sound chip stuff		*
*	pass sound start in d0		*
*	and sound end in d1		*
*****************************************
dosound:
	lea	$ff8900,a0	;sound register base address
	move.w	#0,sounddma(a0)
	move.w	d0,soundstartl(a0)
	lsr.l	#8,d0
	move.w	d0,soundstartm(a0)
	lsr.l	#8,d0
	move.w	d0,soundstarth(a0)
	move.w	d1,soundendl(a0)
	lsr.l	#8,d1
	move.w	d1,soundendm(a0)
	lsr.l	#8,d1
	move.w	d1,soundendh(a0)
	move.w	#%0000000010000001,soundmode(a0)
	move.w	#%0000000000000011,sounddma(a0)
dsback:
	rts


show512:
	MOVEM.L D3-D7/A3-A6,-(A7)	;save regs
	LEA     thisis26a,A6
	ST      $0001(A6)		;set true
	TST.W   $0028(A7)		;was it turn off ?
	BEQ     restoreeverything	;yep

	TST.B   (A6)		;is the vbl and mouse already fixed
	BNE	alreadyin	;yep

	MOVE.W  #2,-(A7)		;get screen physical
	TRAP    #14
	ADDQ.L  #2,A7			;stack cleanup
	MOVE.L  D0,$000C(A6)		;save screen address
	PEA     mousecommand1		;turn mouse off $12
	CLR.W   -(A7)			;length-1
	MOVE.W  #$0019,-(A7)		;send string to int keyboard
	TRAP    #14
	ADDQ.L  #8,A7			;clean stack

	MOVE.B  43(A7),$0002(A6)
	MOVE.B  44(A7),$0003(A6)
	MOVE.L  46(A7),$0004(A6)
	MOVE.B  51(A7),otherscreen1
	MOVE.B  52(A7),otherscreen2
	move.l	54(a7),otherpalette

	PEA	setup512vbl
	MOVE.W  #$0026,-(A7)		;execute in supervisor mode
	TRAP    #$E
	ADDQ.L  #6,A7			;clean stack
	BRA.S   skipalready
alreadyin:
	MOVE.B  $002B(A7),$0002(A6)
	MOVE.B  $002C(A7),$0003(A6)
	MOVE.L  $002E(A7),$0004(A6)
	MOVE.B  51(A7),otherscreen1
	MOVE.B  52(A7),otherscreen2
	move.l	54(a7),otherpalette

skipalready:
	TST.B   $0001(A6)
	BNE.S   skipalready
	BRA	exit

*	Turn off 512 color display	*
restoreeverything:
	TST.B	(A6)		;hadn't been started so no restore
	BEQ	exit
	PEA	restorethings
	MOVE.W	#$0026,-(A7)		;execute in supervisor
	TRAP	#14
	ADDQ.L  #6,A7			;clean stack

restorescreen:
	MOVE.W	#-1,-(A7)		;ignore res
	MOVE.L	$000C(A6),-(A7)		;put saved physbase
	MOVE.L	#-1,-(A7)		;ignore logical
	MOVE.W	#5,-(A7)		;set screen
	TRAP	#14
	LEA	$000C(A7),A7

	PEA	mousecommand2		;08 re-enable mouse
	CLR.W   -(A7)			;length-1
	MOVE.W  #$0019,-(A7)		;int keyboard sen
	TRAP    #14
	ADDQ.L  #8,A7			;clean stack
	SF      (A6)			;back to original state
exit:
	MOVEM.L (A7)+,D3-D7/A3-A6	;restore regs and return
	RTS


setup512vbl:
	LEA	$00FF8240,A0		;color reg 0
	LEA	savecolors,A1
	MOVE.W  #$000F,D7
savecoloop:
	MOVE.W  (A0)+,(A1)+
	dbf	D7,savecoloop

	LEA     $FF8260,A0		;shift mode
	LEA	shiftsave,A1
	MOVE.B  (A0),(A1)		;save the shift mode
	CLR.B   (A0)			;set to low res

	LEA	vblsave,A0
	move.l  $000004CE,(A0)		;vbl que save
	move.b	$ff820a,d7
	btst	#1,d7
	bne	ispal
	LEA     my512vbl,A0
	MOVE.L  A0,$000004CE		;address of my vbl rout
	RTS
ispal:
	LEA     my512vblpal,A0
	MOVE.L  A0,$000004CE		;address of my vbl rout
	RTS

restorethings:
	MOVE.L	vblsave,$000004CE	;restore old vbl
	MOVE.B	shiftsave,$00FF8260	;restore old shift mode
	LEA	$00FF8240,A0		;color 0
	LEA	savecolors,A1
	MOVE.W	#$000F,D7
restorecoloop:
	MOVE.W	(A1)+,(A0)+
	DBF	D7,restorecoloop
	RTS
my512vblpal:
	TST.W   $0000043E	;do nothing if disk activity
	BNE     thisis268
	MOVE    SR,-(A7)	;save the sr
	ORI     #$0700,SR
	lea	palsave2,a0
	move.l	#$ff8240,a1
	rept	8
	move.l	(a0)+,(a1)+
	endr
	LEA     thisis26a,A0
	MOVE.B  $0002(A0),$00FF8201	;vidbasehi
	MOVE.B  $0003(A0),$00FF8203	;"   "  lo
	TST.B   (A0)
	BEQ     thisis246
	LEA     $00FF8240,A4	;color 0
	LEA     $00FF8209,A5	;vid address counter low
	LEA     thisis174p,A6
	MOVE.L	thisis272,A3
	LEA     $0020(A3),A3
	MOVE.W  #148,D7
	CLR.L   D0
waitloopp:
	TST.B   (A5)
	BEQ.S   waitloopp

	MOVE.B  (A5),D0
	adda.l	d0,a6
	JMP     (A6)
thisis174p:
	rept	120
	nop
	endr
colloop1p:
	nop
	NOP
	LEA     (A4),A0
	LEA     (A4),A1
	LEA     (A4),A2
	rept	8
	MOVE.L  (A3)+,(A0)+
	endr
	rept	8
	MOVE.L  (A3)+,(A1)+
	endr
	rept	8
	MOVE.L  (A3)+,(A2)+
	endr
	DBF     D7,colloop1p
	nop
	LEA     (A4),A0
	LEA     (A4),A1
	LEA     (A4),A2
	lea	4608(a3),a3
	rept	8
	MOVE.L  (A3)+,(A0)+
	endr
	rept	8
	MOVE.L  (A3)+,(A1)+
	endr
	rept	8
	MOVE.L  (A3)+,(A2)+
	endr
	LEA     (A4),A0
	LEA     (A4),A1
	LEA     (A4),A2
	lea	-$4a60(A3),A4
	NOP
	NOP
	nop
	rept	8
	MOVE.L  (A3)+,(A0)+
	endr
	rept	8
	MOVE.L  (A3)+,(A1)+
	endr
	rept	8
	MOVE.L  (A4)+,(A2)+
	endr
	LEA     thisis26a,A6
	ST      (A6)
	SF      $0001(A6)
	MOVE.L  $0004(A6),$0008(A6)
	lea	palsave2,a0
	lea	$ff8240,a1
	rept	8
	move.l	(a1)+,(a0)+
	endr

	lea	colors,a0
	add.w	coloroffset,a0
	lea	$ff8240,a1
	rept	8
	move.l	(a0)+,(a1)+
	endr
	lea	tbdr,a0
	move.b	#0,tbcr
	move.b	#200,(a0)
	move.b	#8,tbcr
	nop
	nop
	nop
	nop
	move.b	(a0),d0
wait:
	cmp.b	(a0),d0
	beq.s	wait
	move.l	#bottom1,save
	move.b	save+1,$ff8205
	move.b	save+2,$ff8207
	move.b	save+3,$ff8209
	MOVE    (A7)+,SR		;restore the sr
	RTS

my512vbl:
	TST.W   $0000043E	;flock, why I don't know
	BNE     thisis268
	MOVE    SR,-(A7)	;save the sr
	ORI     #$0700,SR
	lea	palsave2,a0
	move.l	#$ff8240,a1
	rept	8
	move.l	(a0)+,(a1)+
	endr
	LEA     thisis26a,A0
	MOVE.B  $0002(A0),$00FF8201	;vidbasehi
	MOVE.B  $0003(A0),$00FF8203	;"   "  lo
	TST.B   (A0)
	BEQ     thisis246
	LEA     $00FF8240,A4	;color 0
	LEA     $00FF8209,A5	;vid address counter low
	LEA     thisis174,A6
	MOVE.L thisis272,A3
	LEA     $0020(A3),A3
	move.w	#148,d7
	CLR.L   D0
waitloop:
	TST.B   (A5)
	BEQ.S   waitloop

	MOVE.B  (A5),D0
	CMP.B   #$18,D0
	BHI     thisis246
	ADDA.L  D0,A6
	JMP     (A6)
thisis174:
	rept	12
	NOP
	endr
	MOVE.W  #$0018,D0
waitloop2:
	NOP
	DBF     D0,waitloop2
colloop1:
	NOP
	LEA     (A4),A0
	LEA     (A4),A1
	LEA     (A4),A2
	rept	8
	MOVE.L  (A3)+,(A0)+
	endr
	rept	8
	MOVE.L  (A3)+,(A1)+
	endr
	rept	8
	MOVE.L  (A3)+,(A2)+
	endr
	DBF     D7,colloop1

	LEA     (A4),A0
	LEA     (A4),A1
	LEA     (A4),A2
	lea	4608(a3),a3
	rept	8
	MOVE.L  (A3)+,(A0)+
	endr
	rept	8
	MOVE.L  (A3)+,(A1)+
	endr
	rept	8
	MOVE.L  (A3)+,(A2)+
	endr
	LEA     (A4),A0
	LEA     (A4),A1
	LEA     (A4),A2
	lea	-$4a60(A3),A4
	NOP
	NOP
	rept	8
	MOVE.L  (A3)+,(A0)+
	endr
	rept	8
	MOVE.L  (A3)+,(A1)+
	endr
	rept	8
	MOVE.L  (A4)+,(A2)+
	endr
thisis246:
	LEA     thisis26a,A6
	ST      (A6)
	SF      $0001(A6)
	MOVE.L  $0004(A6),$0008(A6)
	lea	palsave2,a0
	lea	$ff8240,a1
	rept	8
	move.l	(a1)+,(a0)+
	endr
	lea	colors,a0
	add.w	coloroffset,a0
	lea	$ff8240,a1
	rept	8
	move.l	(a0)+,(a1)+
	endr
	lea	tbdr,a0
	move.b	#0,tbcr
	move.b	#200,(a0)
	move.b	#8,tbcr
	nop
	nop
	nop
	nop
	move.b	(a0),d0
waitnp:
	cmp.b	(a0),d0
	beq.s	waitnp
	move.l	#bottom1,save
	move.b	save+1,$ff8205
	move.b	save+2,$ff8207
	move.b	save+3,$ff8209


	MOVE    (A7)+,SR		;restore the sr
thisis268:
	RTS
save:	dc.l	0
thisis26a:
	ds.l	2
thisis272:
	ds.l	2
vblsave:
	ds.l	1
savecolors:
	ds.w	16
otherpalette:	dc.l	0
mousecommand1:
	dc.b    $12
mousecommand2:
	dc.b	08
shiftsave:
	dc.b	0
otherscreen1:	dc.b	0
otherscreen2:	dc.b	0
	even
delay:	dc.l	0
****************************************
keyboard:
        move.w  #$ff,-(sp)
        move.w  #6,-(sp)
        trap    #1
        addq.l  #4,sp
        tst.l   d0
        beq     keyback
        swap    d0
quit:   cmpi.w  #$10,d0
        bne     space
        bra     gem
space:
	cmpi.w	#$39,d0
	bne	keyback
	bra	pause
keyback:rts

cldelay:	dc.w	-1
rcldelay:	dc.w	-0
wx:		dc.w	0
wy:		dc.w	0
wz:		dc.w	0
proz:		dc.w	0
*****************************
pause:  
        move.w  #$ff,-(sp)
        move.w  #6,-(sp)
        trap    #1
        addq.l  #4,sp
        tst.l   d0
        beq     pause
        swap    d0
        cmpi.w  #$1e,d0
        bne     keyback 
        bsr     gkey
        cmpi.w  #$32,d0
        bne     keyback
        bsr     gkey
        cmpi.w  #$1e,d0
        bne     keyback
        bsr     gkey
        cmpi.w  #$31,d0
        bne     keyback
        bsr     gkey
        cmpi.w  #$20,d0
        bne     keyback
        bsr     gkey
        cmpi.w  #$1e,d0
        bne     keyback
*	move.w	#1,cheat
	rts

gkey:
        move.w  #$ff,-(sp)
        move.w  #6,-(sp)
        trap    #1
        addq.l  #4,sp
        tst.l   d0
        beq     gkey
        swap    d0
        rts

***********************************
mydocolors:
	move.l	#$ff8240,a1
	moveq	#15,d0
mdcloop:
	move.w	(a0)+,(a1)+
	dbf	d0,mdcloop
	rts

************get screen address***************
getscrn:move.w  #2,-(sp)
        trap    #14
        addq.l  #2,sp
        move.l  d0,screen
*	subi.l	#$9000,d0
        move.l  d0,screen1
        move.l  d0,screen2
        subi.l  #$8000,screen2
        move.l  screen1,seen
        move.l  screen2,hiden
	move.l	screen2,screen3
	subi.l	#$8000,screen3
	rts
screen1:	dc.l	0
screen2:	dc.l	0
screen3:	dc.l	0
seen:	dc.l	0
hiden:	dc.l	0
screen:	dc.l	0


beamer:
	move.l	#$ff8205,a0
	moveq	#0,d0
	move.b	(a0),d0
	asl.l	#8,d0
	adda.w	#2,a0
	move.b	(a0),d0
	asl.l	#8,d0
	adda.w	#2,a0
	move.b	(a0),d0
	move.l	d0,a0
	move.w	#0,(a0)
	rts
flip_scr:
	move.l	seen,d1
	move.l	d1,d2
	add.l	#4000,d1
	add.l	#18000,d2
skloop:
	move.l	#$ff8205,a0
	moveq	#0,d0
	move.b	(a0),d0
	asl.l	#8,d0
	addq.l	#2,a0
	move.b	(a0),d0
	asl.l	#8,d0
	addq.l	#2,a0
	move.b	(a0),d0
	cmp.l	d1,d0
	blt.s	skloop
	cmp.l	d2,d0
	bgt.s	skloop
        move.l  seen,A6
        move.l  hiden,seen
        move.l  A6,hiden
	move.b	seen+1,$ff8201
	move.b	seen+2,$ff8203
	rts

******************************************
*               RETURN TO GEM
gem:
	move.w	#0,$ff8900
	move.w	#0,-(sp)
	jsr	show512
	addq.w	#2,sp

*	move.b	#%11111110,$ff820a
	move.l	#$ff8240,a0
	lea	palsave,a1
	moveq	#15,d7
rspl:
	move.w	(a1)+,d0
	and.w	#$0777,d0
	move.w	d0,(a0)+
	dbf	d7,rspl


        move.w  ressave,-(sp)
        move.l  screen,-(sp)
        move.l  screen,-(sp)
        move.w  #5,-(sp)
        trap    #14
        add.l  #12,sp

	move.l  savesup,-(SP)    ;Back to user mode
        move.w  #$20,-(SP)
        trap    #1
        addq.l  #6,SP
illegal
	clr.w	-(sp)
	trap	#1

rvsave:	dc.l	0
resave:	dc.l	0

myreset:
	rts

	even
mypal:
	dc.w	$0000,$000D,$0116,$0226,$033E,$0447,$0557,$0EEF
	dc.w	$0999,$0AAA,$0BBB,$0444,$0555,$0666,$0EEE,$0FFF



savesup:	dc.l	0
ressave:	dc.w	0
filename:	dc.l	0
bluepalette:
		ds.w	16
palsave:	ds.w	16
palsave2:	ds.w	16
piclist:	dc.l	pic1,pic2,pic3,pic4,pic5,pic6,pic7,pic8,-1
pallist:	dc.l	0,0,0,0,0,0,0,0,-1
sound:
	incbin	'samp2.spl'
sounde:

font:
	incbin	'copyb2.img'
	incbin	'copyb6.img'
	incbin	'copyb7.img'
	incbin	'copyb4.img'
	incbin	'copyb5.img'
colors:
	incbin	'test.bin'

picstart:
	ds.b	3000

pic1:
	incbin	'fr1.spu'
pic2:
	incbin	'fr2.spu'
pic3:
	incbin	'fr3.spu'
pic4:
	incbin	'fr4.spu'
pic5:
	incbin	'fr5.spu'
pic6:
	incbin	'fr6.spu'
pic7:
	incbin	'fr7.spu'
pic8:
	incbin	'fr8.spu'

	section	bss
palettes:
	ds.b	19104*8
bottom1:
	ds.b	8320
bottom2: