	Section Copperlist,code_C

	opt	c-,o-

	move.l  4.w,a6		; exec lib

	lea	dlib,a1
	moveq	#0,d0
	move.l	4.w,a6
	jsr	-$228(a6)
	tst	d0
	beq	error
	move.l	D0,dos		; store address of dos lib

	lea	glib,a1
	moveq	#0,d0
	move.l	4.w,a6
	jsr	-$228(a6)
	tst	d0
	beq	error
	move.l	D0,graphics	; store address of graphics lib
	
	move.l	#Screen+32,d0	; store address of bitplane0
	move.w	d0,bitplane0_lo	; into the copper list
	swap	d0
	move.w	d0,bitplane0_hi
	swap	d0
	add.l	#bplen,d0

	move.w	d0,bitplane1_lo	; into the copper list
	swap	d0
	move.w	d0,bitplane1_hi
	swap	d0
	add.l	#bplen,d0
	
	move.w	d0,bitplane2_lo	; into the copper list
	swap	d0
	move.w	d0,bitplane2_hi
	swap	d0
	add.l	#bplen,d0
	
	move.w	d0,bitplane3_lo	; into the copper list
	swap	d0
	move.w	d0,bitplane3_hi
	swap	d0

	move.l  4.w,a6
	move.l	#scrsize,d0
	move.l	#$10002,d1
	jsr	-198(a6)
	
	move.l	d0,screen2
	move.w	d0,bitplane4_lo
	swap 	d0
	move.w	d0,bitplane4_hi
	
	move.l	graphics,a6
	add.l	#$32,a6
	move.w	#$80,$dff096		; dma control write
	move.l	(a6),old_copper		; store the address of the
	move.l	#my_copper,(a6)		; old copperlist
	move.w	#$8080,$dff096		; dma control write
	move.w	#$8010,$dff09a		; interupt enable bits
	move.l	$6c.w,old_interupt	; store old level 3 int
	move.l	#new_interupt,$6c.w	; store my routine
					; into level 3 int
	jsr	setup_screen
	
	bchg	#1,$bfe001		; turn led off

	jsr	keys

	bchg	#1,$bfe001		; turn led on
	
	move.l	old_interupt,$6c.w	; resore old level 3 int
	move.l	#$10,$dff09a 		; Disable Level 3 Interupt
	move.l	graphics,a6
	add.l	#$32,a6
	move.w	#$0080,$dff096
	move.l	old_copper,(a6)		; restore old copper list
	move.w	#$8080,$dff096
	move.l	graphics,a1
	move.l	4.w,a6
	jsr	-$19e(a6)
	move.l	4.w,a6
	jsr	-138(a6)
	
	move.l  4.w,a6
	move.l	screen2,a1
	move.l	#scrsize,d0
	jsr	-210(a6)

Error:	moveq	#0,d0			; fin
	rts

keys:
	move.b	$bfec01,d0
	cmp.b	#119,d0
	bne	not_return
	
	move.w	#0,d0
	
	move.b	f1+1,d1
	cmp.b	#"F",d1
	beq.s	no_f1
	or.w	#1,d0
no_f1:	
	move.b	f2+1,d1
	cmp.b	#"F",d1
	beq.s	no_f2
	or.w	#2,d0
no_f2:	
	move.b	f3+1,d1
	cmp.b	#"F",d1
	beq.s	no_f3
	or.w	#4,d0
no_f3:	
	move.b	f4+1,d1
	cmp.b	#"F",d1
	beq.s	no_f4
	or.w	#8,d0
no_f4:	
	move.b	f5+1,d1
	cmp.b	#"F",d1
	beq.s	no_f5
	or.w	#16,d0
no_f5:	
	move.b	f6+1,d1
	cmp.b	#"F",d1
	beq.s	no_f6
	or.w	#32,d0
no_f6:	
	move.l	#$1ff,d1
	move.l	#trainer,a0
	move.l	#$100,a1
	
block:	move.b	(a0)+,(a1)+
	dbf	d1,block

	move.b	d0,$11e
	
	
	clr.l	d0
	move.b	f7,d0
	sub.b	#49,d0
	mulu	#4,d0
	add.l	#levels,d0
	move.l	d0,a0
	move.l	(a0),$120
	
	
	move.l	dos,a6
	move.l	#loadme,d1
	clr.l	d2
	clr.l	d3
	
	jsr	-$de(a6)

	rts
	
trainer:	

	move.w	#$10E,$50034
	jmp	$50000
	
	move.l	#$000000124,$80e2
	jmp	$400
	
	dc.w	0
	dc.l	0
	
	move.b	$11e,d0
	and.b	#1,d0
	beq.s	no_lives
	move.w	#$4e71,$84ee	; inf lives
	move.w	#$4e71,$84f0
no_lives:
	move.b	$11e,d0
	and.b	#2,d0
	beq.s	no_shots
	move.w	#$4e71,$a436	; inf shots
no_shots:
	move.b	$11e,d0
	and.b	#4,d0
	beq.s	no_gren
	move.w	#$4e71,$a424	; inf grenades
no_gren:
	move.b	$11e,d0
	and.b	#16,d0
	beq.s	no_token
	move.b	#$60,$1049c	; not drop tokens
no_token:
	move.b	$11e,d0
	and.b	#8,d0
	beq.s	no_weapons
	move.w	#$4e71,$104e0	; not drop weapons
	move.w	#$4e71,$104e2
	move.b	#$60,$104e8
	move.b	#$60,$10506
no_weapons:
	move.b	$11e,d0
	and.b	#32,d0
	beq.s	no_proof
	move.b	#1,$11693
no_proof:
	movem.l	d0-d7/a0-a6,-(sp) 
	move.l	$9552,d0
	cmp.l	#$969c,d0
	bne.s	not_level1
	move.l	$120,d0
	cmp.l	#$969c,d0
	blt.s	not_level1
	move.l	$120,$9552
	move.w	#1,$9556
not_level1:
	movem.l	(sp)+,d0-d7/a0-a6	

	jmp	$10214		; go!!


	

not_return:
	cmp.b	#95,d0
	bne.s	not_f1
	
	lea	f1,a0
	jsr	change
not_f1:
	cmp.b	#93,d0
	bne.s	not_f2
	
	lea	f2,a0
	jsr	change
not_f2:
	cmp.b	#91,d0
	bne.s	not_f3
	
	lea	f3,a0
	jsr	change
not_f3:
	cmp.b	#89,d0
	bne.s	not_f4
	
	lea	f4,a0
	jsr	change
not_f4:
	cmp.b	#87,d0
	bne.s	not_f5
	
	lea	f5,a0
	jsr	change
not_f5:
	cmp.b	#85,d0
	bne.s	not_f6
	
	lea	f6,a0
	jsr	change
not_f6:
	cmp.b	#83,d0
	bne.s	not_f7
	
	move.b	f7,d4
	add.b	#1,d4
	cmp.b	#58,d4
	bne.s	not_f7max
	move.b	#49,d4
not_f7max:
	move.b	d4,f7
	bsr.s	change2

not_f7:
	bra	keys

change:	move.b	(a0),d1
	eor.b	#00,d1
	move.b	d1,(a0)+
	
	move.b	(a0),d1
	eor.b	#08,d1
	move.b	d1,(a0)+
	
	move.b	(a0),d1
	eor.b	#102,d1
	move.b	d1,(a0)+
change2:
	movem.l	d0-d7/a0-a6,-(sp) 
	jsr	refresh
	movem.l	(sp)+,d0-d7/a0-a6	

key:	move.b	$bfec01,d1
	cmp.b	d0,d1
	beq.s	key	
	rts


new_interupt:
	movem.l	d0-d7/a0-a6,-(sp) 

wait_irq:
	and.w	#$10,$dff01e
	beq 	no_music
	move.w	#$10,$dff09c

	move.l	scr2,d0	
	move.w	d0,bitplane4_lo
	swap 	d0
	move.w	d0,bitplane4_hi

no_music:
	movem.l	(sp)+,d0-d7/a0-a6	
	dc.w	$4ef9			; jmp
old_interupt:	dc.l	0		; the old int lev 3

setup_screen:

	lea	cmap,a0
	move.w	(a0)+,d0
	
	lea	screen,a1
	move.w	#15,d0
cmaploop:
	move.w	(a1)+,(a0)+
	addq.l	#2,a0
	subq.w	#1,d0
	bpl.s	cmaploop	

	move.l	screen2,a2
	move.l	a2,newscr
	move.l	a2,scr1
	add.l	#32*400,a2
	move.l	a2,scr2

refresh:
	move.l	scr1,$dff054				; dest mem d
	move.w	#0,$dff064				; source a modulo 
	Move.w	#0,$dff044				; blit 1st word mask source a
	move.w	#0,$dff046
	move.w	#(%0001)*256,$dff040			; blit cont reg 0
	move.w	#%0000000000000100,$dff042		; blit cont reg 1
	Move.w	#0,$dff066				; modulo for dest
	Move.w	#(90*64)+40,$dff058			; blit height,width
	jsr	do_blit

	lea	names,a1
	move.l	scr1,a2
	add.l	#81,a2
	jsr	blit_message

	moveq.l	#10,d0

plot_again:

	add.l	#40*tall,a2
	jsr	blit_message

	move.b	(a1),d0
	bne.s	plot_again
	
	move.l	scr1,d0
	move.l	scr2,d1
	move.l	d1,scr1
	move.l	d0,scr2

	rts
	
blit_message:

	movem.l	d0-d7/a2-a6,-(sp)

	move.l	#0,midadd

	move.l	a1,a6
	clr.b	d0
	moveq.l	#-1,d1
	
blit_message_loop1:

	addq.l	#1,d1
	move.b	(a6),d0
	addq	#1,a6
	cmp.b	#0,d0
	bne.s	blit_message_loop1

	move.w	d1,d5
	and.w	#1,d5
	asl.w	#1,d5
	move.w	d5,mid
	
	move.l	a2,midadd
	move.w	d1,d5

	addq.l	#1,d1
	lsr.l	#1,d1
	moveq.l	#20,d6
	sub.l	d1,d6
	add.l	d6,a2
	move.l	a2,d2
	and.l	#$fffffffe,d2
	move.l	a2,d3
	and.l	#1,d3
	move.l	d2,a2
	
	move.w	#12,d6
	cmp.l	#1,d3
	beq.s	cont_blit_message
	
	add.w	#12,mid
	subq.l	#2,midadd
	
cont_blit_message:
	
	move.w	d6,d7
	mulu	#8192,d7
	
	subq.w	#4,d6
	cmp.w	#4,d6
	bne.s	other_half
	
	move.w	#12,d6
	add.l	#80,a2
	
other_half:

	sub.l	#40,a2
	clr.w	d0
	lea	font,a0
	move.b	(a1),d0
	addq.l	#1,a1
	cmp.b	#0,d0
	bne.s	mess_is_ok

	movem.l	(sp)+,d0-d7/a2-a6	
	
	move.w	mid,d5
	mulu	#8192,d5
	or.w	#(%1001*256)+$f0,d5
	
	move.l	midadd,a3

	Move.l	a3,$dff054		; dest mem d
	Move.l	a2,$dff050		; source mem a
	Move.w	#$ffff,$dff044		; blit 1st word mask source a
	move.w	#$ffff,$dff046		; blit last word mask source a
	move.w	#0,$dff064		; blit modulo for source a
	move.w	d5,$dff040
	move.w	#0,$dff042		; blit cont reg 1
	Move.w	#0,$dff066		; modulo for dest
	Move.w	#(8*64)+40,$dff058	; blit height,width

	jsr	do_blit

dont_centre:
	rts
	
	
mess_is_ok:
	sub	#32,d0
	mulu	#16,d0
	add	d0,a0
	
	Move.l	a2,$dff054		; dest mem d
	Move.l	a0,$dff050		; source mem a
	move.l	a2,$dff048		; source mem c
	Move.w	#$ffff,$dff044		; blit 1st word mask source a
	move.w	#$ffff,$dff046		; blit last word mask source a
	move.w	#0,$dff064		; blit modulo for source a
	move.w	#38,$dff060		; blit modulo for source c	
	or.w	#(%1011*256)+$fa,d7
	move.w	d7,$dff040		; blit cont reg 0
	move.w	#0,$dff042		; blit cont reg 1
	Move.w	#38,$dff066		; modulo for dest
	Move.w	#(8*64)+1,$dff058	; blit height,width

	jsr	do_blit
	
	addq.l	#1,a2
	bra	cont_blit_message

do_blit:
	btst.b	#6,$dff002
	bne.s	do_blit
	rts
	

tadd	equ	230*46



	
	Section	copdat,Data_c

names:
	dc.b	" ",0
	dc.b	"CRACKED BY THE ANGELS",0
	dc.b	" ",0
	dc.b	"MEGA-TRAINED BY SHAGRATT OF LSD",0
	dc.b	" ",0
	dc.b	"F1 - INFINITE LIVES     : "
f1:	dc.b	"OFF",0
	dc.b	"F2 - INFINITE AMMO      : "
f2:	dc.b	"OFF",0
	dc.b	"F3 - INFINITE GRENADES  : "
f3:	dc.b	"OFF",0
	dc.b	"F4 - KEEP WEAPONS       : "
f4:	dc.b	"OFF",0
	dc.b	"F5 - KEEP TOKENS        : "
f5:	dc.b	"OFF",0
	dc.b	"F6 - INVUNERABILITY     : "
f6:	dc.b	"OFF",0
	dc.b	"F7 - START LEVEL (1-9)  : 0"
f7:	dc.b	"1 ",0
	dc.b	" ",0
	dc.b	"RETURN - START GAME",0
	dc.b	" ",0
	dc.b	" ",0
	dc.b	"NOTE: WHEN DRIVE HEADS STOP MOVING",0
	dc.b	"ON THE TITLE PAGE INSERT DISK II",0
	
	dc.b	0


mid:		dc.w	0
midadd:		dc.l	0
old_copper:	dc.l	0
graphics:	dc.l	0
dos:		dc.l	0

my_copper:	dc.w	$100,$4200	; 4 bp - lores - 
		dc.w	$104,$a		; bp control reg
		dc.w	$108,0		; bp modulo - odd
		dc.w	$10a,0		; bp modulo - even
		dc.w	$180,0		; colour 0 to black

		dc.w	$120,0,$122,0
		
		dc.w	$182,$fff
	
		dc.w	$092,$38	; bp start horz
		dc.w	$08e,$2c8c	; bp window start left
		dc.w	$090,$2ce3	; bp window bot right
		dc.w	$094,$2dd0	; bp stop horz
		
cmap:		dc.w	$180,0
		dc.w	$182,0
		dc.w	$184,0
		dc.w	$186,0
		dc.w	$188,0
		dc.w	$18a,0
		dc.w	$18c,0
		dc.w	$18e,0
		dc.w	$190,0
		dc.w	$192,0
		dc.w	$194,0
		dc.w	$196,0
		dc.w	$198,0
		dc.w	$19a,0
		dc.w	$19c,0
		dc.w	$19e,0
	
		
		dc.w	$0e0
bitplane0_hi:	dc.w	0
		dc.w	$e2
bitplane0_lo:	dc.w	0,$e4
bitplane1_hi:	dc.w	0
		dc.w	$e6
bitplane1_lo:	dc.w	0,$e8
bitplane2_hi:	dc.w	0
		dc.w	$ea
bitplane2_lo:	dc.w	0,$ec
bitplane3_hi:	dc.w	0
		dc.w	$ee
bitplane3_lo:	dc.w	0

		dc.b	top_of_copper,1
		dc.w	$ff00,$182,$000
		dc.w	$100,$1200	; 1 bp - lores 
		
		dc.w	$0e0
bitplane4_hi:	dc.w	0
		dc.w	$e2
bitplane4_lo:	dc.w	0
		
		dc.w	$182,$fff
		dc.w	$ffe1,$fffe	; wait for end of ntsc screen
		
		dc.w	$3001,$ff00	; wait for end of pal screen

		dc.w	$9c,$8010	; irq set bits - ?
		dc.w	$ffff,$fffe	; end of copper list
	
glib:		dc.b	"graphics.library",0
		even
dlib:		dc.b	"dos.library",0
		even		

tall		equ	10
	
screen:		incbin	"train.bin";	must have the colour map before the 
				     ;	image, must be 40 horz and any
				     ;  size vertically (within reason).

scrsize:	equ	40*tall*64
screen2:	dc.l	0
font:		incbin	"chrset.wrd"
loadme:		dc.b	"Resistance",0
		even

levels:		dc.l	$9658
		dc.l	$96c8
		dc.l	$9720
		dc.l	$978a
		dc.l	$97e2
		dc.l	$983c
		dc.l	$9896
		dc.l	$98ca
		dc.l	$98fe


		
newscr:		dc.l	0
flag:		dc.l	0

scr1:		dc.l	0
scr2:		dc.l	0

bplen		equ	((screen2-screen)-32)/4
top_of_copper	equ	44+(bplen/40)
down		equ	top_of_copper+108
lookup_list:	dcb.l	150,0



	End
