
 Section SharpCode,Code_C
ANTALrader=4	;Antal prgs att välja på. Ej mer än 10!
   Incdir Asmdisk1:

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

   	moveq	#0,D0
   	move.w	$dff002,D0
   	or.w	#$8000,D0
   	move.w	d0,dma
   	move.w	#$4000,$dff09A
   	move.w	$dff01E,base

   	move.l	#NewCopper,$dff080
   	tst.w	$dff088
   	move.w	#$85e0,$dff096

		bsr	bild_Init
		bsr	menu_Init
		bsr	fade_Start
		move.b	$dff00a,MOUSEold

Main:  
              	cmp.b	#$ff,$dff006
	        bne.s	Main
pal:	        cmp.b	#$26,$dff006
	        bne.s	pal

            bsr         MoveHori
            bsr         mouse_Start
            bsr         fade_Start

            btst  #6,$bfe001
            bne.s   Main

    	move.l	#GFXname,A1
   	moveq	#0,d0
   	move.l	4,a6
   	jsr	-$0198(a6)
   	move.l	d0,a1
   	move.l	$0026(a1),$dff080
   	tst.w	$dff088
   	jsr	-$019e(a6)
   
   	move.w	dma,$dff096
   	move.w	base,$dff09a
	
		movem.l	(sp)+,d0-d7/a0-a6

		jmp	load
		rts

dma: dc.l 0
base: dc.l 0

GFXname:	dc.b	"graphics.library",0,0
even
GFXbase: dc.l 0

OldCopper:	dc.l	0
NewCopper:
MENUcopper:

SPRITES:	dc.l	$01200000,$01220000,$01240000,$01260000
		dc.l	$01280000,$012a0000,$012c0000,$012e0000
		dc.l	$01300000,$01320000,$01340000,$01360000
		dc.l	$01380000,$013a0000,$013c0000,$013e0000

		dc.w	$0180,$000,$0182,$cc7,$0184,$994,$0186,$771
		dc.w	$0188,$440,$018a,$ccc,$018c,$999,$018e,$666
SPRcols:	dc.w	$01a2,$000,$01aa,$000,$01b2,$000

		dc.w	$008e,$2c81,$0090,$2cc1
		dc.w	$0092,$0038,$0094,$00d0
		dc.w	$0100,$0200,$0102,$0000,$0104,$0000
		dc.w	$0108,2*40,$010a,2*40

LOGObitPs:	dc.w	$00e0,$0000,$00e2,$0000
		dc.w	$00e4,$0000,$00e6,$0000
		dc.w	$00e8,$0000,$00ea,$0000

		dc.w	$5b11,$fffe,$0100,$0200

		dc.w	$6211,$fffe  ;,$0180,$00f
HoriLine:
	dc.l	$01800000,$01800000,$01800000,$01800000,$01800000,$01800000
	dc.l	$01800000,$01800000,$01800000,$01800000,$01800000,$01800000
	dc.l	$01800000,$01800000,$01800000,$01800000,$01800000,$01800000
	dc.l	$01800000,$01800000,$01800000,$01800000,$01800000,$01800000
	dc.l	$01800000,$01800000,$01800000,$01800000,$01800000,$01800000
	dc.l	$01800000,$01800000,$01800000,$01800000,$01800000,$01800000
	dc.l	$01800000,$01800000,$01800000,$01800000,$01800000,$01800000
	dc.l	$01800000,$01800000,$01800000,$01800000,$01800000,$01800000
	dc.l	$01800000,$01800000,$01800000,$01800000,$01800000,$01800000
	dc.l	$01800000


		dc.w	$6311,$fffe,$0180,$000

		dc.w 	$0182,$aaa,$0184,$666,$0186,$444

		dc.w	$0108,40,$010a,40

TEXTbitPs:	dc.w	$00e0,$0000,$00e2,$0000
		dc.w	$00e4,$0000,$00e6,$0000

		dc.w	$6601,$fffe,$0100,$2200

TEXTcolors:
A set $8411
		Rept	10
		dc.w	A,$fffe,$0182,$aaa,$0184,$666,$0186,$444
A set A+$0a00
		Endr

		dc.w	A,$fffe,$0100,$0200

		dc.w	$e911,$fffe   ;,$0180,$00f
HoriLine2:
	dc.l	$01800000,$01800000,$01800000,$01800000,$01800000,$01800000
	dc.l	$01800000,$01800000,$01800000,$01800000,$01800000,$01800000
	dc.l	$01800000,$01800000,$01800000,$01800000,$01800000,$01800000
	dc.l	$01800000,$01800000,$01800000,$01800000,$01800000,$01800000
	dc.l	$01800000,$01800000,$01800000,$01800000,$01800000,$01800000
	dc.l	$01800000,$01800000,$01800000,$01800000,$01800000,$01800000
	dc.l	$01800000,$01800000,$01800000,$01800000,$01800000,$01800000
	dc.l	$01800000,$01800000,$01800000,$01800000,$01800000,$01800000
	dc.l	$01800000,$01800000,$01800000,$01800000,$01800000,$01800000
	dc.l	$01800000


		dc.w	$ea11,$fffe,$0180,$000

		dc.w	$0182,$007,$0184,$00a,$0186
		dc.w	$00a,$0108,0,$010a,0,$0102,$0004
		dc.w	$008e,$2c85,$0090,$2cc1

BitPlanes:	dc.w	$00e0,$0000,$00e2,$0000
		dc.w	$00e4,$0000,$00e6,$0000


		dc.w	$2c11,$fffe,$0100,$0200

		dc.w	$ffff,$fffe

MoveHori:	move.l	#LinePointers,a1
		move.l	#HoriLine+2+53*4,a2
		move.l	#53-1,d7
Loopen:		move.l	#Farger,a0
		add.w	(a1),a0
		cmp.w	#99,(a0)
		bne.S	Pullover
		move.l	#Farger,a0
		clr.w	(a1)+
		bra.S	Muffen
Pullover:	addq.w	#2,(a1)+
		move.w	(a0),(a2)
Muffen:		subq	#4,a2
		dbra	d7,Loopen

MoveHori2:	move.l	#LinePointers2,a1
		move.l	#HoriLine2+2,a2
		move.l	#53-1,d7
Loopen2:	move.l	#Farger,a0
		add.w	(a1),a0
		cmp.w	#99,(a0)
		bne.S	Pullover2
		move.l	#Farger,a0
		clr.w	(a1)+
		bra.S	Muffen2
Pullover2:	addq.w	#2,(a1)+
		move.w	(a0),(a2)
Muffen2:	addq	#4,a2
		dbra	d7,Loopen2
		rts

;--------------------------------------------------------------------
;---                  The Horizontal Line Shit			  ---
;--------------------------------------------------------------------

LinePointers:	dc.w	2,4,6,8,10,12,14,16,18,20,22,24,26,28,30
		dc.w	32,34,36,38,40,42,44,46,48,50,52,54,56,58
		dc.w	60,62,64,66,68,70,72,74,76,78,80,82,84,86
		dc.w	88,90,92,94,96,98,100,102,104,106,108,110
		dc.w	112,114,116

LinePointers2:	dc.w	2,4,6,8,10,12,14,16,18,20,22,24,26,28,30
		dc.w	32,34,36,38,40,42,44,46,48,50,52,54,56,58
		dc.w	60,62,64,66,68,70,72,74,76,78,80,82,84,86
		dc.w	88,90,92,94,96,98,100,102,104,106,108,110
		dc.w	112,114,116

Farger:		

	dc.w	$100,$200,$300,$400,$500,$600,$700,$800,$900,$a00
	dc.w	$b00,$c00,$d00,$e00,$f00
	dc.w	$e00,$d00,$c00,$b00,$a00,$900,$800,$700,$600,$500
	dc.w	$400,$300,$200,$100,$000
	dc.w	$001,$002,$003,$004,$005,$006,$007,$008,$009,$00a
	dc.w	$00b,$00c,$00d,$00e,$00f
	dc.w	$00e,$00d,$00c,$00b,$00a,$009,$008,$007,$006,$005
	dc.w	$004,$003,$002,$001,$000
	dc.w	$101,$202,$303,$404,$505,$606,$707,$808,$909,$a0a
	dc.w	$b0b,$c0c,$d0d,$e0e,$f0f
	dc.w	$e0e,$d0d,$c0c,$b0b,$a0a,$909,$808,$707,$606,$505
	dc.w	$404,$303,$202,$101,$000

	dc.w	99



bild_Init:	move.l	#BILD,d0
		move.w	d0,TEXTbitPs+6
		swap	d0
		move.w	d0,TEXTbitPs+2
		move.l	#BILD+40,d0
		move.w	d0,TEXTbitPs+14
		swap	d0
		move.w	d0,TEXTbitPs+10
                        rts

menu_Init:	move.l	#$ffffffff,$dff044
		move.l	#$00260000,$dff060
		move.l	#$00000026,$dff064

		lea	BILD,a0
		lea	MENUtext,a1
		moveq.l	#13-1,d7	;Y-led
menu_Loop0:	moveq.l	#0,d6		;X-led
menu_Loop1:	moveq.l	#0,d2
		move.b	(a1)+,d2
		sub.b	#32,d2
		lsl.w	#5,d2
		add.l	#CSET21,d2
		move.l	d6,d0
		move.l	d0,d1
		lsr.w	#4,d0
		add.w	d0,d0
		and.w	#$f,d1
		ror.w	#4,d1
		add.w	#$0b5a,d1
		lea	(a0,d0.l),a2
		clr.w	$dff042
		move.w	d1,$dff040
		move.l	a2,$dff048
		move.l	d2,$dff050
		move.l	a2,$dff054
		move.w	#$40*8*2+1,$dff058

menu_Wait0:	btst	#6,$dff002
		bne.s	menu_Wait0

		addq.l	#8,d6
		cmp.l	#320,d6
		bne.s	menu_Loop1
		add.l	#40*10*2,a0
		dbf	d7,menu_Loop0
		
		rts

mouse_Start:	lea	dest,a0
		moveq.l	#0,d0
		move.b	MOUSEpos,d0
		divu	#10,d0
		and.l	#$ffff,d0
		mulu	#6,d0
		add.l	d0,a0
		move.w	#$017,0(a0)
		move.w	#$015,2(a0)
		move.w	#$004,4(a0)

		move.b	$dff00a,d0
		cmp.b	MOUSEold,d0
		beq.s	mouse_Next
		blt.s	mouse_Less
		addq.b	#2,MOUSEpos
		cmp.b	#(ANTALrader*10),MOUSEpos
		bne.s	mouse_Next
		move.b	#0,MOUSEpos
		bra.s	mouse_Next
mouse_Less:	subq.b	#2,MOUSEpos
		cmp.b	#-2,MOUSEpos
		bne.s	mouse_Next
		move.b	#(ANTALrader*10)-2,MOUSEpos
mouse_Next:	move.b	d0,MOUSEold
		lea	dest,a0
		lea	grund,a1
		moveq.l	#0,d0
		move.b	MOUSEpos,d0
		divu	#10,d0
		and.l	#$ffff,d0
		mulu	#6,d0
		add.l	d0,a0
		add.l	d0,a1
		move.w	#$46f,0(a0)
		move.w	#$24d,2(a0)
		move.w	#$13b,4(a0)
		move.w	#$46f,0(a1)
		move.w	#$24d,2(a1)
		move.w	#$13b,4(a1)

mouse_End:	rts

MOUSEold:	dc.b	0,0
MOUSEpos:	dc.b	0,0

fade_Start:	move.l	tal,d0

fade_Loop1:	move.l	#(ANTALrader*3)-1,d1
		clr.l	d5
		move.l	#grund,a0

fade_Loop3:	move.l	#$0000000f,d2
		rol.w	d0,d2
		move.l	#compare,a1
		moveq	#1,d3

fade_Loop2:	move.w	(a0,d5),d4
		and.w	d2,d4
		ror.w	d0,d4
		move.l	#dest,a0
		move.w	d4,(a1)+
		dbra	d3,fade_Loop2

		move.l	#grund,a0
		subq.l	#4,a1
		move.w	(a1),d3
		cmp.w	2(a1),d3
		beq	fade_End
		blt	fade_Next1
		subq.w	#1,d3
		bra	fade_End

fade_Next1:	addq.w	#1,d3

fade_End:	rol.w	d0,d3
		eor.w	#$ffff,d2
		and.w	d2,(a0,d5)
		or.w	d3,(a0,d5)
		addq.l	#2,d5
		dbra	d1,fade_Loop3
		subq.l	#4,d0
		move.l	d0,tal
		cmp.l	#-4,d0
		bne	fade_Norre

		move.l	#8,tal

		move.l	#ANTALrader-1,d7
		move.l	#grund,a0
		move.l	#TEXTcolors,a1

fade_Lpous:	move.w	(a0)+,06(a1)
		move.w	(a0)+,10(a1)
		move.w	(a0)+,14(a1)

		add.l	#16,a1
		dbf	d7,fade_Lpous

fade_Norre:	rts

tal:		dc.l	8
compare:	dc.w	0,0

grund:
		Rept	ANTALrader
		dc.w	$017,$015,$004
		Endr
dest:
		Rept	ANTALrader
		dc.w	$017,$015,$004
		Endr

CSET21:	
	incbin	"Binary/C21"
BILD:		dcb.b	40*10*15*2
		dcb.b	46*2
BILDscr:	dcb.b	46*10*2

;  *******************
;  * L O A D E R ! ! *
;  *******************

OPENLIBRARY:	EQU	-408
CLOSELIBRARY:	EQU	-414
LOADSEG:	EQU	-150
UNLOADSEG:	EQU	-156

load:	

   	MOVE.L	$4.W,A6
		LEA.L	DOSNAME(PC),A1
		JSR	OPENLIBRARY(A6)		; Öppna dos.library
		MOVE.L	D0,DOSBASE		; Spar dosbase
		BEQ.S	EXIT

   	MOVE.L	D0,A6      
      JSR   CHECK_FILES 

		JSR	LOADSEG(A6)		; Ladda objektfil
		MOVE.L	D0,SAVEBPTR		; Spar BPTR
		BEQ.S	FILEERROR
 
		ASL.L	#2,D0
		ADDQ.L	#4,D0
		MOVE.L	D0,A0

		MOVEM.L	D0-D7/A0-A6,-(SP)
		JSR	(A0)			; Starta objektfilen
		MOVEM.L	(SP)+,D0-D7/A0-A6

		MOVE.L	SAVEBPTR(PC),D1
		JSR	UNLOADSEG(A6)		; Deallokera filen

FILEERROR:	MOVE.L	A6,A1
		MOVE.L	$4.W,A6
		JSR	CLOSELIBRARY(A6)	; Stäng dos.library

EXIT:		RTS

CHECK_FILES:
		cmp.b	#0,MOUSEpos
		beq.s	lo2
		cmp.b	#$09,MOUSEpos
		bls.s lo2
      bne.s CH1
      rts 

CH1:	cmp.b	#$0a,MOUSEpos
		beq.s	lo3
		cmp.b	#$11,MOUSEpos
		bls.s lo3
      bne.s CH2
      rts
				
CH2:	cmp.b	#$12,MOUSEpos
		beq.s	lo4
		cmp.b	#$1f,MOUSEpos
		bls.s lo4
      bne.s CH3
      rts

CH3:	cmp.b	#$20,MOUSEpos
		beq.s	lo5		
		bhi.s lo5
      rts

lo2:	MOVE.L	#FILENAME,D1
      RTS
lo3:	MOVE.L	#FILENAME2,D1
      RTS
lo4:	MOVE.L	#FILENAME3,D1
      RTS
lo5:	MOVE.L	#FILENAME4,D1
      RTS

DOSBASE:	DC.L	0
DOSNAME:	DC.B	'dos.library',0
EVEN
SAVEBPTR:	DC.L	0

FILENAME:	DC.B	'dh2:Test/1',0		; Filnamn
FILENAME2:	DC.B	'dh2:Test/2',0		; Filnamn
FILENAME3:	DC.B	'dh2:Test/3',0		; Filnamn
FILENAME4:	DC.B	'dh2:Test/4',0		; Filnamn

; Detta är texten till menyn. Den ska bestå av 13 rader som är 40 tecken breda!
; OBS! 40*13, ändra ej på det!!!!
; Använd bara STORA bokstäver, siffrorna 0-9 och tecknen ! " # $ % & ' ( ) * +
; , - . / : ; < = > ? @

MENUtext:
 DC.B	"       TRACE PRESENTS : HD MENU!        " ;Varför inte skriva en
 DC.B	"----------------------------------------" ;trevlig rubrik?
 DC.B	"                                        "
 DC.B	"    BO JACKSON'S BASEBALL / SKID ROW    " ;Skriv första demonamnet här
 DC.B	"       PINBALL DREAMS / FAIRLIGHT       "
 DC.B	"  FORMULA ONE GRAND PRIX / THE COMPANY  "
 DC.B	"          PUSH OVER / PARADISE          "
 DC.B	"                                        "
 DC.B	"----------------------------------------"
 DC.B	"  SORRY NO MORE GAMES AVAILABLE ON THE  " ;Är det mindre än 10 demos
 DC.B	"  HD RIGHT NOW!.                        " ;kan man skriva vad som
 DC.B	"                            / TRACE     " ;helst på de resterande
 DC.B	"----------------------------------------" ;raderna.

