  m                  ;----------------------------------------------------------------------------
;	the real bootblock of the game noughty ones cracked by kingdom
;	signed galaxy/kingdom
;----------------------------------------------------------------------------

;	jmp	$60000		;!!!
;	org	$60000		;!!!
;	load	$60000		;!!!

;----------------------------------------------------------------------------
;
;----------------------------------------------------------------------------
start:
	move.l	4.w,a6
	cmp.l	#$100000,$3e(a6)
	blt.b	fakefast

	move.l	#$90000,a5
	bra.b	main

fakefast:
	tst.l	$4e(a6)
	beq.b	realfast

	move.l	#$c10000,a5
	bra.b	main

realfast:
	move.l	#$200000,a5

;----------------------------------------------------------------------------
;	normal init routines.. dma, irq and copper (clear color)
;----------------------------------------------------------------------------
main:
	lea	$dff000,a6
	move.w	#$4000,$9a(a6)
	move.w	#$4000,$9c(a6)
	move.w	#$180,$96(a6)
	move.w	#$0,$180(a6)
	move.w	#$20,$1dc(a6)

	lea	$7fffc,sp

;----------------------------------------------------------------------------
;	this routine copys itself to $6f000
;----------------------------------------------------------------------------
	lea	$6f000,a0
	lea	routine(pc),a1
	move.w	#end-routine-1,d7

copyloop:
	move.b	(a1)+,(a0)+
	dbra	d7,copyloop

;----------------------------------------------------------------------------
;	jump into the new location
;----------------------------------------------------------------------------
	jmp	$6f000

;----------------------------------------------------------------------------
;	the main programm which will be located at $6f000
;----------------------------------------------------------------------------
;	the few lines below makes a copy again... cool stuff!!
;----------------------------------------------------------------------------
routine:
	lea	otherroutine(pc),a0
	lea	$7c700,a1
	move.w	#end-otherroutine-1,d7

othercopy:
	move.b	(a0)+,(a1)+
	dbra	d7,othercopy

;----------------------------------------------------------------------------
;	1st jump into that routine but why!
;----------------------------------------------------------------------------
;	below lines seem to match with what we are talked about...
;	you know d0=filename , a0 = startadress , jsr = loader :)))))
;----------------------------------------------------------------------------
	moveq	#$0,d0
	move.l	a5,a0			;depends what memory i got!
	jsr	$7c700

;----------------------------------------------------------------------------
;	jump in the address you got...
;----------------------------------------------------------------------------
	jsr	(a0)

	move.w	#$3fff,$dff09a

;----------------------------------------------------------------------------
;	2nd jump!
;----------------------------------------------------------------------------
;	below lines seem to match with what we are talked about...
;	you know d0=filename , a0 = startadress , jsr = loader :)))))
;----------------------------------------------------------------------------
	moveq	#$2,d0
	lea	$3000,a0
	jsr	$7c700

;----------------------------------------------------------------------------
;	check if memory was enough!
;----------------------------------------------------------------------------
	move.l	4.w,a6
	move.w	$128(a6),d0
	btst	#$1,d0
	beq.b	lde

	jsr	-$96(a6)

	move.l	d0,d1
	movec	cacr,d0
	tst.w	d0
	bmi.b	ld6
	ori.w	#$8,d0
	movec	d0,cacr
	bra.b	ld8

ld6:
	cpusha	ic

ld8:
	move.l	d1,d0
	jsr	-$9c(a6)

;----------------------------------------------------------------------------
;	jump into that stuff!
;----------------------------------------------------------------------------
lde:
	jmp	$3000

;----------------------------------------------------------------------------
;	this is what i call 'get the data and jump into it'
;----------------------------------------------------------------------------
otherroutine:
	movem.l	d1-d7/a0-a6,-(sp)
	lea	table(pc),a1		;get the table
	lsl.w	#$3,d0			;get the right longword
	add.w	d0,a1			;---------------------^
	move.l	$0(a1),d5		;get the startsector \ routine know
	move.l	$4(a1),d6		;get the datalength  / how long to read
	moveq	#$0,d0
	moveq	#$0,d7
	lea	buffer(pc),a1
	bsr.w	decoder

	move.l	d6,d0
	movem.l	(sp)+,d1-d7/a0-a6
	rts

;----------------------------------------------------------------------------
;	table of what? seem to be the datalength of the files!
;----------------------------------------------------------------------------
table:
	dc.l	$00400,$11198;interact	;hah! it's like a poker game 50-50
	dc.l	$11598,$0c4a2;password	;but seem that i won this game :)
	dc.l	$1da3a,$24672;tittle	;the structure!
	dc.l	$420ac,$246da;game	;---------------------------------
	dc.l	$66786,$00b2c;inpic1	;
	dc.l	$672b2,$0f4b4;level1	; sector number , datalength
	dc.l	$76766,$00c7c;inpic2	;
	dc.l	$773e2,$0f36c;level2	;---------------------------------
	dc.l	$8674e,$009b8;inpic3	;
	dc.l	$87106,$0ed00;level3	; offset/512 = sectornumber
	dc.l	$95e06,$00d84;inpic4	;
	dc.l	$96b8a,$0f4d4;level4	; and
	dc.l	$a605e,$00864;inpic5	;
	dc.l	$a68c2,$12314;level5	; datalength/512 = sectors to be
	dc.l	$b8bd6,$01b64;inpic6+	; read!!!
	dc.l	$ba73a,$168e4;level6+	;
	dc.l	$00000			;null

;----------------------------------------------------------------------------
;	the decoder of the mfm format! mainroutine
;----------------------------------------------------------------------------
decoder:
	movem.l	d1-d7/a0-a6,-(sp)
	lea	$dff024,a5
	bsr.b	l20a

	bne.b	l1a2

	moveq	#-$1,d0
	bra.b	l1ec

l1a2:
	lea	l3be(pc),a6
	move.l	a1,(a6)
	move.w	#$7f00,$7a(a5)
	move.w	#$9500,$7a(a5)
	move.w	#$8210,$72(a5)
	move.w	#$4489,$5a(a5)
	move.l	#$55555555,d4
	lea	l3c2(pc),a4
	tst.b	(a4)+
	bne.b	tracklength

	bsr.b	getciareg

;----------------------------------------------------------------------------
;	check track 0
;----------------------------------------------------------------------------
trackzero:
	btst	#$4,$f01(a6)
	beq.b	tracklength

	bsr.b	otherdirection

	bra.b	trackzero

tracklength:
	divu	#$1600,d5
	move.b	d5,(a4)
	clr.w	d5
	swap	d5
	bsr.w	l358

	bsr.b	selectdrive

l1ec:
	tst.l	d0
	movem.l	(sp)+,d1-d7/a0-a6
	rts

;----------------------------------------------------------------------------
;	select drive
;----------------------------------------------------------------------------
selectdrive:
	bsr.b	getciareg

	or.b	#$f9,(a6)
	and.b	#$87,(a6)
	or.b	#$f9,(a6)

getciareg:
	lea	$bfd100,a6
	rts

l20a:
	addq.b	#$3,d0
	bsr.b	selectdrive

	st	d1
	moveq	#$2,d2
	and.b	#$7f,(a6)
	bclr	d0,d1
	and.b	d1,(a6)
	btst	d2,$f01(a6)
	bne.b	delay

	bsr.b	direction

	bsr.b	otherdirection

	btst	d2,$f01(a6)
	bne.b	delay

l22a:
	moveq	#$0,d0
	rts

;----------------------------------------------------------------------------
;	delay routine
;----------------------------------------------------------------------------
delay:
	move.w	#$8000,d0

delayloop:
	bsr.b	l264

	subq.w	#$1,d0
	beq.b	l22a

	btst	#$5,$f01(a6)
	bne.b	delayloop

	moveq	#$1,d0
	rts

;----------------------------------------------------------------------------
;	change directions
;----------------------------------------------------------------------------
direction:
	bclr	#$1,(a6)
	bra.b	stepheads

otherdirection:
	bset	#$1,(a6)

;----------------------------------------------------------------------------
;	step heads
;----------------------------------------------------------------------------
stepheads:
	bclr	#$0,(a6)
	bset	#$0,(a6)
	move.l	d7,-(sp)
	moveq	#$5a,d2

waiting:
	bsr.b	l264

	dbra	d2,waiting

	move.l	(sp)+,d7
	rts

;----------------------------------------------------------------------------
;	never used this... dunno what use it might have!
;----------------------------------------------------------------------------
l264:
	move.l	d7,-(sp)
	move.b	-$1e(a5),d7

l26a:
	cmp.b	-$1e(a5),d7
	beq.b	l26a

	move.l	(sp)+,d7
	rts

l274:
	lea	l3c2(pc),a6
	move.b	(a6)+,d1
	move.b	(a6),d0
	move.b	d0,-(a6)
	bsr.b	getciareg

	bset	#$2,(a6)
	lsr.b	#$1,d0
	bcc.b	l28c

	bclr	#$2,(a6)

l28c:
	lsr.b	#$1,d1

l28e:
	cmp.b	d1,d0
	beq.b	diskready

	bcs.b	l29a

	bsr.b	direction

	addq.b	#$1,d1
	bra.b	l28e

l29a:
	bsr.b	otherdirection

	subq.b	#$1,d1
	bra.b	l28e

;----------------------------------------------------------------------------
;	disk ready
;----------------------------------------------------------------------------
diskready:
	btst	#$5,$f01(a6)
	bne.b	diskready

	rts

;----------------------------------------------------------------------------
;	decoder
;----------------------------------------------------------------------------
l2aa:
	move.w	#$4000,(a5)
	bsr.b	l274

	subq.w	#$1,-$2(a4)
	beq.b	l32c

	move.l	l3be(pc),a2
	move.l	a2,-$4(a5)
	move.w	#$9a00,(a5)
	move.w	#$9a00,(a5)
	move.w	#$2,$78(a5)
	move.w	#$8000,d1

l2d0:
	bsr.b	l264

	subq.w	#$1,d1
	beq.b	l32c

	btst	#$1,-$5(a5)
	beq.b	l2d0

	move.w	#$4000,(a5)
	moveq	#$a,d3

l2e6:
	lea	$800(a2),a3

l2ea:
	cmp.w	#$4489,(a2)+
	bne.b	l2ea

	cmp.w	#$4489,(a2)
	bne.b	l2fc

	cmp.l	a3,a2
	bcs.b	l2ea

	bra.b	l2aa

l2fc:
	move.l	a2,a3
	move.w	#$438,d7
	bsr.b	l33c

	bne.b	l2aa

	move.l	$4(a2),d1
	bsr.b	l330

	lsr.w	#$6,d0
	lea	$38(a2),a2
	move.l	a2,$0(a4,d0.w)
	lea	$200(a2),a6
	moveq	#$7f,d2

l31c:
	bsr.b	l32e

	move.l	d0,(a2)+
	dbra	d2,l31c

	move.l	a6,a2
	dbra	d3,l2e6

	moveq	#$1,d1

l32c:
	rts

l32e:
	move.l	(a6)+,d1

l330:
	and.l	d4,d1
	move.l	(a2),d0
	and.l	d4,d0
	add.l	d0,d0
	or.l	d1,d0
	rts

l33c:
	movem.l	d1/a3,-(sp)
	moveq	#$0,d0
	lsr.w	#$2,d7
	subq.w	#$1,d7

l346:
	move.l	(a3)+,d1
	eor.l	d1,d0
	dbra	d7,l346

	and.l	d4,d0
	tst.l	d0
	movem.l	(sp)+,d1/a3
	rts

l358:
	move.l	a0,a1
	add.l	d6,a1
	moveq	#$0,d6
	divu	#$200,d5
	swap	d5
	move.w	d5,d6
	swap	d5
	link	a4,#-$2e
	moveq	#$2c,d0
	sub.l	d0,a4

l370:
	move.w	#$4,-$2(a4)

l376:
	bsr.w	l2aa

	beq.b	l3aa

	moveq	#$a,d0
	sub.w	d5,d0
	lsl.w	#$2,d5
	lea	$0(a4,d5.w),a2
	add.l	d6,(a2)

l388:
	move.l	(a2)+,a3
	move.w	#$1ff,d1
	sub.w	d6,d1

l390:
	move.b	(a3)+,(a0)+
	cmp.l	a0,a1
	beq.b	l3b4

	dbra	d1,l390

	moveq	#$0,d6
	dbra	d0,l388

	moveq	#$0,d5
	lea	l3c3(pc),a6
	addq.b	#$1,(a6)
	bra.b	l370

l3aa:
	subq.w	#$1,-$2(a4)
	bpl.b	l376

	moveq	#-$1,d0
	bra.b	l3b6

l3b4:
	moveq	#$0,d0

l3b6:
	moveq	#$2c,d1
	add.l	d1,a4
	unlk	a4
	rts


;----------------------------------------------------------------------------
;	data
;----------------------------------------------------------------------------
l3be:
	dc.l	$0

l3c2:
	dc.b	$0

l3c3:
	dc.b	$0

buffer:
	dc.l	$0,$0,$0,$0,$0
	dc.l	$0,$0,$0,$0,$0
	dc.l	$0,$0,$0,$0,$0

end:
