Exec=4		; base address of exec.library
Level3=$6c	; interrupt handler (for VBlank, Copper and Blitter)
Forbid=-132		; stop multitasking
Permit=-138		; allow multitasking
OpenLibrary=-408	; open system calls
CloseLibrary=-414	; no more need for opened system calls

start:
move.l	sp,initialSP	; save old stack pointer
clr.w Volume1
clr.w Volume2
clr.w UD
clr.w delay
clr.b TestWord1
clr.b TestWord2
;load sound into $50000

move.l 4,a6
lea lib,a1
clr.l d0
jsr -408(a6)
move.l d0,a6
move.l d0,DosBase

soundload:
move.l #soundfilename,d1
move.l #$03ed,d2
jsr -30(a6)
cmp.l #0,d0
beq error
move.l d0,file
move.l d0,d1
move.l #$50000,d2
move.l #$1ffb8,d3
jsr -42(a6)
move.l file,d1
jsr -36(a6)
jmp sstart

error:
rts

soundfilename:
dc.b 'df1:Supremacy/sound',0

even
sstart:
period:
move.l #3580000,d0
divu $50004,d0

move.l $50000,d2
divu #2,d2

move.l #$50006,$dff0a0	;Location Hi
move.l #$50006,$dff0b0
move.w d2,$dff0a4	;Length
move.w d2,$dff0b4
move.w d0,$dff0a6	;Period
move.w d0,$dff0b6
move.w #$00,$dff0a8	;Volume
move.w #$00,$dff0b8

move.w #$8203,$dff096

FadeUp:
cmp.w #$3f,Volume2
beq rest
move.w Volume2,$dff0b8
add.w #$01,Volume2
move.w #$ffff,d4
waiter:
dbra d4,waiter
jmp FadeUp

rest:	move.l	Exec,a6		; jmp offset table (exec.library)
	lea	GfxName,a1	; name of library to open
	jsr	OpenLibrary(a6)	; get access
	move.l	d0,GfxBase	; store pointer to library base	
	add.l	#$32,d0		; now point to LOFCopList in active
	move.l	d0,a5		; VIEW structure

; not needed: jsr  Forbid(a6) ; stop multitasking

	move.w	#$4000,$dff09a	; stop interrupt processing
	move.w	#$0080,$dff096	; stop Copper DMA
	move.l	Level3,OldVector; pointer to old interrupt handler
	move.l	#Inter,Level3	; install new Level 3 Handler
	move.l	(a5),OldCopper	; save original Copper list
;	move.l	#CopList,(a5)	; install my own Copper list
	move.w	#$8080,$dff096	; restart Copper DMA 
	move.w	#$c000,$dff09a	; allow interrupt processing again
;
vmouse:
btst #6,$bfe001
bne vmouse

	move.w	#$4000,$dff09a	; stop interrupt processing
	move.w	#$0080,$dff096	; stop Copper DMA
	move.l	OldVector,Level3 ; original Level 3 handler
	move.l	OldCopper,(a5)	;  original Copper list
	move.w	#$8080,$dff096	; restart Copper DMA 
	move.w	#$c000,$dff09a	; allow interrupt processing again 

	move.l	Exec,a6
; not needed: jsr Permit(a6) ; restart multitasking

	move.l	GfxBase,a1	; pointer to library base
	jsr	CloseLibrary(a6) ; close that library
	move.l	DosBase,a1
	jsr	CloseLibrary(a6) ; close that library
;	move.l	initialSP,sp	; original stack pointer

FadeDn:
cmp.w #$0,Volume1
bne subber
move.b #$01,TestWord1
bra faderest
Subber:
subq.w #$01,Volume1
faderest:
cmp.w #$0,Volume2
bne subber2
move.b #$01,TestWord2
bra faderest2
Subber2:
subq.w #$01,Volume2

faderest2:
move.w Volume1,$dff0a8
move.w Volume2,$dff0b8
move.w #$ffff,d4
waiter2:
dbra d4,waiter2

cmp.b #$1,TestWord1
beq anothertest
jmp fadedn
anothertest:
cmp.b #$1,TestWord2
beq finish
jmp fadedn

finish:	move.w 	#$f,$dff096
	clr.l	d0		; report no errors
	rts

Inter:
movem.l d0-d7/a0-a6,-(a7)

btst #5,$dff01c
bne Vblank
bra EndHandler

Vblank:
add.w #$01,delay
cmp.w #$05,delay
bne endhandler
clr.w delay

tst.w UD
bne Otherway

Vol1:
Cmp.w #$3f,Volume1
beq VolClr
move.w Volume1,$dff0a8
move.w Volume2,$dff0b8
addq.w #$01,Volume1
bchg #1,$bfe001
subq.w #$01,Volume2
jmp Endhandler

VolClr:
move.w #$1,UD
move.w #$3f,Volume1
move.w #$0,Volume2

Otherway:
Cmp.w #$0,Volume1
beq VolClr2
move.w Volume1,$dff0a8
move.w Volume2,$dff0b8
subq.w #$01,Volume1
bchg #1,$bfe001
addq.w #$01,Volume2
jmp Endhandler

VolClr2:
move.w #$0,UD
move.w #$0,Volume1
move.w #$3f,Volume2

;My own prg

Endhandler:
movem.l (a7)+,d0-d7/a0-a6
dc.w $4ef9

OldVector:
dc.l 0

GfxName:	DC.B 'graphics.library',0
lib:		dc.b 'dos.library',0

even

;variables
initialSP:	blk.l 1,0
GfxBase:	blk.l 1,0
OldCopper:	blk.l 1,0
file:		dc.l 0
DosBase:	dc.l 0
Volume1:	dc.w 0
Volume2:	dc.w $3f
UD:		dc.w 0
delay:		dc.w 0
TestWord1:	dc.b 0
TestWord2:	dc.b 0

CopList:
dc.w $0180,$000f
dc.w $0182,$0f0f
dc.w $00e0,$0000
dc.w $00e2,$0000
dc.w $ffff,$fffe
