****************************
********* MENU  ************

* Revision V6

* Comments:
* 	V5	- Fixed some bugs in the credits screen.
*	V6	- DTM Replay
*		- fade changed
*		- new fade added (?)
*	

* and there will come a day without shadows ...

*****************************

menuedata_load	equ	0	; 0 = gespeicherte daten, 1 = original daten
menuedata_save	equ	0	; 0 = nichts, 1 = original daten speichern

;---------------

use_absolute_path	equ	0	* 0= no 1=yes

******* Menu ********

KEY_DELAY	equ	3

***** fire equ's ************

posx		equ	55 	
posy		equ	90
wohin           EQU 	640*posy+posx*2

fire_wide       EQU 	50
fire_high       EQU	94 
fire_colors     EQU 	128

wb		equ	fire_wide
wh		equ	fire_high

div		equ	5

kuglx		equ	71
kugly		equ	78


edge_color	equ	$f800

*************** Code ********************

mainmenu:

* Daten laden ....

		movea.l	screen_1,a0
		jsr	clear_black_240
		movea.l	screen_2,a0
		jsr	clear_black_240

		clr.w	mm_start_running
		clr.w	registry_was_done

		ifne menuedata_save
		bsr	DATAsave
		endc

		move.l	#intsam_file,file_name_ptr
		move.l	samples,file_buf_ptr
		move.l	#mx_intsam_len,file_size
		jsr	load_file
rc_pos01	jsr	registry_get_name
		ifne	show_reg_hex
		bsr	registry_show_hex
		endc

		jsr	reset_init_point
		jsr	paint_init_point
		bsr	DATAload	

		jsr	paint_init_point
		jsr	mm_load_options

* DTM Player starts here ....

		jsr	paint_init_point
		tst.w	qs_music
		bne.s	no_MODULErun
		jsr	MODULErun
no_MODULErun

********** texture precalc ***************

		jsr	paint_init_point
                jsr     calc_fast_divus

********* Some Fire Precalc *********

		jsr	paint_init_point
		bsr	calc_divtable
		jsr	paint_init_point
                bsr     calc_firepal

********** Some Gouraud precalc ***************

		jsr	paint_init_point
		bsr	calc_div_st
		jsr	paint_init_point
                bsr     calc_delta
		jsr	paint_init_point
                bsr     calc_fast_mulus

********* For Kugle Anim *************

		jsr	paint_init_point
		lea	fade_buffer_2+128,a1
		bsr	save_screen	* goro
		lea	fade_buffer_2+128,a0
		bsr	save_kugel	* kugel
		jsr	paint_init_point
		bsr	create_mask	* fire

* Hauptmenu einblenden
	
		jsr	paint_init_point
		jsr	clear_init_point
		bsr	fade_me

* VBL umbiegen 
		move.l	$70.w,old_menu_vbl
		move.l	#menu1_vbl,$70.w


********** Hauptmenu **************

menu1_loop:
          	jsr	vsync

* Kugel keys
		bsr	kugel_move
		bsr	check_return

* Fire		
		bsr     scroll_fire
                bsr     renew_fire
                movea.l screen_1,A5
		bsr     calc_fire

		jsr     swap_me
		neg.w	index

		tst.b	keytable+$1
		beq.s	menu1_loop	

lepo		
		tst.w	qs_music
		bne.s	no_MODULEstop
		bsr	MODULEstop
no_MODULEstop	move.l	old_menu_vbl,$70.w

		rts


;************************************

episode_menu
		tst.w	qs_music
		bne.s	no_MODULEstop2
		bsr	MODULEstop
no_MODULEstop2	move.l	old_menu_vbl,$70.w

		rts


********** Sub Menu Control *******

		include	"include\menu\parts\menucon.s"

************ VBLs ************


menu1_vbl:
		movem.l	d0-a6,-(sp)

* Kugel Animation

		move.l	screen_2,a0
		bsr	kugel

* Goro          
                bsr     restore_screen
                bsr     transform_points
                bsr     create_color_points
		bsr	z_sorting
                bsr     render_gouraud
                bsr     control_axes

		movem.l	(sp)+,d0-a6
		addq.l	#1,vbl_count

		tst.w	dv_flag
		beq.s	m1_no_dv
		move.l	#dummy_vbl_m1,$70.w
m1_no_dv

		rte

menu2_vbl:
		movem.l	d0-a6,-(sp)

* Goro          
                bsr     restore_screen
                bsr     transform_points
                bsr     create_color_points
		bsr	z_sorting
                bsr     render_gouraud
                bsr     control_axes

		movem.l	(sp)+,d0-a6
		addq.l	#1,vbl_count

		tst.w	dv_flag
		beq.s	m2_no_dv
		move.l	#dummy_vbl_m2,$70.w
m2_no_dv
		rte

menu3_vbl:
		movem.l	d0-a6,-(sp)

* Goro          
                bsr     restore_screen
                bsr     transform_points
                bsr     create_color_points
		bsr	z_sorting
                bsr     render_gouraud
                bsr     control_axes

		movem.l	(sp)+,d0-a6
		addq.l	#1,vbl_count

		tst.w	dv_flag
		beq.s	m3_no_dv
		move.l	#dummy_vbl_m3,$70.w
m3_no_dv
		rte

menu4_vbl:
		movem.l	d0-a6,-(sp)

		addq.w	#1,vbl_delay
		cmp.w	#6,vbl_delay
		bne.s	more_waiting

		clr.w	vbl_delay

* edge keys
		lea	credits_offsets,a6
		bsr	edge_move_texture		

more_waiting

		move.w	#edge_color,d0
		swap	d0
		move.w	#edge_color,d0
		move.l	screen_1,a0
		lea	credits_offsets,a6
		bsr	paint_edge


		movem.l	(sp)+,d0-a6
		addq.l	#1,vbl_count

		tst.w	dv_flag
		beq.s	m4_no_dv
		move.l	#dummy_vbl_m4,$70.w
m4_no_dv
		rte

;---------------

dummy_vbl_m1	move.l	#menu1_vbl,$70.w
		rte
dummy_vbl_m2	move.l	#menu2_vbl,$70.w
		rte
dummy_vbl_m3	move.l	#menu3_vbl,$70.w
		rte
dummy_vbl_m4	move.l	#menu4_vbl,$70.w
		rte

;---------------

vbl_delay	dc.w	0

****** kugel steuerung ******

		include	"include\menu\parts\put.s"

************ SUBS *****************


calc_divtable
	lea	divtable,a0
	move.w	#256*8-1,d0
	moveq	#0,d1
divv	move.l	d1,d2
	divu	#div,d2
	subq.w	#1,d2
	bpl.s	not_minus
	moveq	#0,d2
not_minus
	move.w	d2,(a0)+
	addq.w	#1,d1
	dbra	d0,divv
	rts


create_mask:
	lea	fade_buffer_2+128,a0
	lea	mask,a1
	adda.l	#posy*640+posx*2,a0

	move.w	#wh-1,d0
line_lop	
	move.w	#wb-1,d1
pixel_lop
	move.w	(a0)+,(a1)+
	dbra	d1,pixel_lop
	lea	640-wb*2(a0),a0	
	dbra	d0,line_lop
	rts


build_menu
	move.l	screen_1,a0
	move.l	screen_2,a1
	lea	module+128,a2
	move.w	#(320*120)-1,d0
gfx:	move.l	(a2)+,d1
	move.l	d1,(a0)+
	move.l	d1,(a1)+
	dbra	d0,gfx
	rts

******* Loading *******

	include	"include\menu\parts\loading.s"

******** Fading ***********

	include	"include\menu\parts\fade.s"

******* Kugel **********

	include	"include\menu\parts\kugel.s"

******** fire ********

	include	"include\menu\parts\fire.s"

	include	"include\menu\parts\random.s"
                
******* shading  *********

	include	"include\menu\parts\gouraud.s"

******* texture mapping  *********

	include	"include\menu\parts\texture.s"

************ DATA LOADING SPECS ***********

BYTESmodule	dc.l	700000
BYTEStitel1	dc.l	153728
BYTEStitel2	dc.l	153728
BYTEStitel3	dc.l	153728
BYTEStitel4	dc.l	153728
BYTEStitel5	dc.l	31488
BYTESkugel	dc.l	10368
BYTEStxt	dc.l	23168
BYTEStexture	dc.l	41088+320*64*2
BYTESgear	dc.l	8320

BYTEScolor_tables	dc.l	512
BYTESobject		dc.l	50
BYTESflach_info		dc.l	74
BYTESsin_tab		dc.l	512
BYTEScos_tab		dc.l	2048

BYTESa_arp		dc.l	2304
BYTESdsp_buff		dc.l	960
BYTEStempo_tab		dc.l	1536

		ifeq	use_absolute_path-1
FILEmodule	dc.b	"h:\zdevel\zmenu\menu\menudata\menu.dtm",0
FILEtitel1	dc.b	"h:\zdevel\zmenu\menu\menudata\menu.pct",0
FILEtitel2	dc.b	"h:\zdevel\zmenu\menu\menudata\graphic.pct",0
FILEtitel3	dc.b	"h:\zdevel\zmenu\menu\menudata\sound.pct",0
FILEtitel4	dc.b	"h:\zdevel\zmenu\menu\menudata\credits.pct",0
FILEtitel5	dc.b	"h:\zdevel\zmenu\menu\menudata\choose.pct",0
FILEkugel	dc.b	"h:\zdevel\zmenu\menu\menudata\kuglanim.pct",0
FILEtxt		dc.b	"h:\zdevel\zmenu\menu\menudata\txt.pct",0
FILEtexture	dc.b	"h:\zdevel\zmenu\menu\menudata\texture.pct",0
FILEgear	dc.b	"h:\zdevel\zmenu\menu\menudata\gear.pct",0
		even
		else
FILEmodule	dc.b	"data\menudata\fruchtix.dat",0
FILEtitel1	dc.b	"data\menudata\menu.pct",0
FILEtitel2	dc.b	"data\menudata\graphic.pct",0
FILEtitel3	dc.b	"data\menudata\sound.pct",0
FILEtitel4	dc.b	"data\menudata\credits.pct",0
FILEtitel5	dc.b	"data\menudata\choose.pct",0
FILEkugel	dc.b	"data\menudata\kuglanim.pct",0
FILEtxt		dc.b	"data\menudata\txt.pct",0
FILEtexture	dc.b	"data\menudata\texture.pct",0
FILEgear	dc.b	"data\menudata\gear.pct",0

FILEcolor_tables dc.b	"data\menudata\colortab.dat",0
FILEobject	dc.b	"data\menudata\object.dat",0
FILEflach_info	dc.b	"data\menudata\flachinf.dat",0
FILEsin_tab	dc.b	"data\menudata\sintab.dat",0
FILEcos_tab	dc.b	"data\menudata\costab.dat",0

FILEa_arp	dc.b	"data\menudata\aarp.dat",0
FILEdsp_buff	dc.b	"data\menudata\digidsp2.out",0
FILEtempo_tab	dc.b	"data\menudata\tempo.tab",0

		even

		endc

************ DTM Player ***************

		include	"include\menu\parts\module.s"

********************************************

mm_start_running	dc.w	0	; 0 = escape, 1 = running gewaehlt

		even
