	section lame,code_c

openlibrary= 	-408		; Hier sind vordefinierte Adressen
closelibrary= 	-414		; und Offsets, die wir spaeter
forbid= 	-132		; brauchen werden
permit= 	-138

Trap_vec0  = $80
Execbase   = $4
Oldopen    = -$198
Intenar    = $01c
Intena     = $09a
Dmaconr    = $002
Dmacon     = $096
Cop1lch    = $080
Copjmp1    = $088
Vposr      = $004

	Move.l	#Start,$80.w	; Trap vector 0
	Trap	#0		; Execute trap 0 to give full control of the
	Rts			; 68000, needs an RTE to return.

Start:  ori.b #$80,$bfd100		; Abwürgen der Laufwerke
	ori.b #$8,$bfd100
	andi.b #$f7,$bfd100
	ori.b #$10,$bfd100
	andi.b #$ef,$bfd100
	
	bsr	KillSys
	bsr	copper
	bsr	main
	bsr	setupsys

	Rte		; Return from exception 
		

*****************************************************************************
;Killsys - Disable operating system and interrupts
*****************************************************************************
Killsys:
	Move.l	$4.w,a6		; Execbase vector
	Lea	Gfxname(pc),a1	; Pointer to "graphics.library" into a1
	Jsr	Oldopen(a6)	; Open this library
	Lea	$dff000,a6	; Pointer to custom chips
	Move.l	d0,a0		; Address of the graphics library
	Move.l	38(a0),Sys_copl		; Remember the System copperlist
	Move	Intenar(a6),Int_set	; System interrupts
	Move	#$7fff,Intena(a6)	; Now switch off all interrupts
	Move.l	$6c.w,Vbl_vec		; System vertical blanking int.
	Move	Dmaconr(a6),Dma_set	; System DMA
	Move	#$7fff,Dmacon(a6)	; Clear all DMA
	Move	#$87c0,Dmacon(a6)	; Now set the required DMA channels

	Move.l	#Cop,Cop1lch(a6)	; Init. our own copperlist
	Clr	Copjmp1(a6)

	Rts

Gfxname:		dc.b "graphics.library",0
	Even
*****************************************************************************
;Sysreturn - Re-enable operating system and interrupts
*****************************************************************************
Setupsys:
	Lea	$dff000,a6
	Move	#$7fff,Intena(a6)	; Clear all interrupts
	Move.l	Vbl_vec,$6c.w	; Restore VBL interrupt
	Move	Int_set,d0
	Or	#$c000,d0
	Move	d0,Intena(a6)		; Restore system interrupts
	Move	#$7fff,Dmacon(a6)
	Move	Dma_set,d0
	Or	#$8200,d0
	Move	d0,Dmacon(a6)		; Restore system DMA
	Move.l	Sys_copl,Cop1lch(a6)	; Restore system copperlist
	Clr	Copjmp1(a6)
	Rts

Vbl_vec:          	dc.l 0
Int_set:          	dc.l 0
Dma_set:          	dc.l 0
Sys_copl:          	dc.l 0



Main:
	Move.l	Vposr(a6),d0
	And.l	#$1ff00,d0
	Cmp.l	#$00100,d0	; Wait for vertical position 1
	Bne.s	Main

; PROGRAMM
	bsr	copy
	bsr	vers
	btst	#6,$bfe001
	bne	Main
	rts

copy:
	MOVE.L	#$24,D4
	LEA	tab,A1   ;tab
	LEA	newcopper,A0   	
goon:	MOVE.L	#8,D0
hello:	MOVE.W	(A1)+,6(A0)
	CMP.L	tabend,A1   ;tabend
	BNE.S	bingo
	LEA	tab,A1	;tab
bingo:	ADD.L	#$00000008,A0
	cmp.l	#newcopper+[8*230],a0
	bne	njet
	add.l	#16,a0
njet:	SUBQ.W	#1,D0
	BNE	hello
	SUB.L	#14,A1
	SUBQ.W	#1,D4
	BNE	goon
	RTS	
vers:
	LEA	tab,A0
	LEA	tabend-2,A1
	MOVE.W	(A0),D0
looping:MOVE.W	2(A0),(A0)
	ADDQ.L	#2,A0
	CMP.L	A0,A1
	BNE	looping
	MOVE.W	D0,(A1)
	RTS	

copper:
	MOVE.L	#$1a11FFFE,D0
	MOVE.L	#$01800000,D1
	MOVE.W	#$00b0,D4
	LEA	newcopper,A0
bingo1:	MOVE.L	D0,(A0)+
	MOVE.L	D1,(A0)+
	ADD.L	#$01000000,D0
	SUB.W	#1,D4
	BNE	bingo1

	MOVE.L	D0,(A0)+
	MOVE.L	#$01800000,(A0)+
	MOVE.L	#$CB11FFFE,(A0)+
	MOVE.L	#$01800000,(A0)+
	MOVE.L	#$CC11FFFE,(A0)+
	MOVE.L	#$01800000,(A0)+
	MOVE.L	#$CD11FFFE,(A0)+
	MOVE.L	#$01800000,(A0)+
	MOVE.L	#$CE11FFFE,D1
	MOVE.L	#$01800000,D2
	MOVE.W	#$006E,D0
bingo2:	MOVE.L	D1,(A0)+
	MOVE.L	#$01800000,(A0)+
	ADD.L	#$01000000,D1
	ADD.L	#2,D2
	SUB.W	#1,D0
	CMP.L	#$0011FFFE,D1
	BNE	bingo2
	SUB.W	#1,D0
	MOVE.L	#$FFE1FFFE,(A0)+
	MOVE.L	#$01B00000,(A0)+
	MOVE.L	#$01B00000,(A0)+
	MOVE.L	#$01B00000,(A0)+
bingo3:	MOVE.L	D1,(A0)+
	MOVE.L	#$01800000,(A0)+
	ADD.L	#$01000000,D1
	ADD.L	#2,D2
	SUB.W	#1,D0
	BNE	bingo3
	rts
	

tab:
	dc.W	$000A,$000B,$000C,$000D,$000E,$000F,$000E,$000D,$000C,$000B
	dc.W	$000A,$0009,$0008,$0007,$0006,$0005,$0004,$0003,$0002,$0001
	dc.W	$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000
	dc.W	$0000,$0000,$0100,$0200,$0300,$0400,$0500,$0600,$0700,$0800
	dc.W	$0900,$0A00,$0B00,$0C00,$0D00,$0E00,$0F00,$0E00,$0D00,$0C00
	dc.W	$0B00,$0A00,$0900,$0800,$0700,$0600,$0500,$0400,$0300,$0200
	dc.W	$0100,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000
	dc.W	$0000,$0000,$0000,$0000,$0001,$0002,$0003,$0004,$0005,$0006
	dc.W	$0007,$0008,$0009,$000A,$000B,$000C,$000D,$000E,$000F,$000E
	dc.W	$000D,$000C,$000B
tabend:



cop:		dc.w	$0100,$0000
newcopper:			; Unsere Copperliste
	blk.b $918,0
copperend:
		dc.w  $ffff,$fffe
