;***** main code *****
;start at 0
;include int code

;RST 0
.rst_0
	di
	jp entrypoint
	ds 4,0

;RST 1 - change for bank in A
.rst_8
	;ds 8,0
	ld B,#7F		;2
	out (C),A		;2
	ret				;1
	ds 3,0
;RST 2 - change mode
.rst_16
	add #8C			;2
	ld B,#7F		;2
	out (C),A		;2
	ret				;1
	ds 1,0
;RST 3 - change bank in rst + 1
.rst_24
	;ds 8,0 
	pop HL		;1
	ld A,(HL)	;1
	inc HL		;1
	push HL		;1
	ld	B,#7F	;2
	out (C),A	;2
;RST 4	- ret only cause end of RST 3
.rst_32
	ret
	ds 7,0
;RST 5
.rst_40
	ds 8,0
;RST 6
.rst_48
	ds 8,0
;RST 7 int
.rst_56
	read "int.asm"
	
.entrypoint
IFNOT output_files
	xor A	;debug force drive A
ENDIF
;save drive passed from loader in A
	ld (current_drive),A
	
	ld SP,#9000

;force bank #C0	
	change_bankM #C0
	
	;cleanup heap
	ld HL,heap_low
	ld DE,heap_low+1
	ld BC,heap-heap_low
	xor A
	ld (HL),A
	dec BC
	ldir

	call TRASH_ArraySetup
	call TRASH_JumpTableSetup
	call TRASH_GenRevTable
	call TRASH_GenBulletTable
	call TRASH_GenLaserTable
	call Trash_GAUGE_Init
	
	call FONT_Init
	;call GAUGE_Init
	
	;call TRASH_BankSetup	;after all !
	
;**************************
;*** LOADING BASE DATAS ***
;**************************

	call GFX_HideScreen
	
	call FDCON

;sound player
	;ld BC,#7FC7
	;out (C),C
	change_bankM #C7
	ld HL,sound_player
	ld DE,#4000
	call Quick_load
	;ld BC,#7FC0
	;out (C),C
	
;add a BP to compile new sound player
IF	debug_soundBP
	break
ENDIF

IF debug_casualBP
	break
ENDIF
	
;IF debug
;	ld BC,#7F10 ;bleu
;	ld A,#55
;	out (C),C
;	out (C),A
;ENDIF
	
	;base sprites
	
	;ld BC,#7FC0		;temp copy to #C7/#C1 ?
	;out (C),C
	change_bankM #C0
	ld HL,spr_base
	ld DE,#4000
	call Quick_load

	ld HL,hiscore_file
	ld DE,hi_score_table ;#8000
	call Quick_load
	
	IF unlock_bonus
		ld A,#FF
		ld HL,level_list
		ld (HL),A
		inc HL
		ld (HL),A
	ENDIF

	
	;ld A,#00
	;ld (hi_score_table),A
	
	;call OptionsSave
	
	;ld HL,#8000
	;ld DE,hi_score_table
	;ld BC,140
	;ldir
	
	;himem
	IF output_files
		ld HL,himem_file
		ld DE,himem_start
		call Quick_load
	ENDIF
	
	;mark bank
	ld A,#C0
	ld (#4000),A

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

	ld SP,#9000
	
	call GFX_Cls
	
	ld HL,game_pal ;default_pal
	call GFX_SetColors
	
	ld HL,crtc_config_game ;crtc_config_options
	call GFX_SetCRTC
	
	
	;ld DE,#C240+26
	;ld HL,fun_ramok
	;ld BC,color_table_options_normal
	;call FONT_DrawStringEX
	
	;ld DE,#C2C0+26
	;ld HL,fun_dsk
	;ld BC,color_table_options_normal
	;call FONT_DrawStringEX
	
	;ld BC,#7F8C+1
	;out (C),C
	change_mode 1
	
	di

	


;show ok message
	;ld DE,#C2C0+26
	;ld HL,fun_dskok
	;ld BC,color_table_options_normal
	;call FONT_DrawStringEX

;enter game	
	jp GAME
	
;HL = address to call
.MAIN_Indirect
	ld (MAIN_Indirect_Addr),HL	
	ld A,L	
	or H	
MAIN_Indirect_Addr EQU $+1
	call nz,0	
	ret
	
	charset_off
.title_file
	db "TITLEDATBIN"
.himem_file
	db "HIMEM   BIN"
.sound_player
	db "SOUND   BIN"
.spr_base
	db "GFX_BASESPR"
.casual_file
	db "CASUAL  BIN"
.hiscore_file
	db "HISCORE DAT"
.master_file
	db "MASTER  FAA"
master_file_termination	EQU $-1	
	charset_on
	

	
;! " x + , . / ?_
;0123456789
;ABCDEFGHIJKLMNOPQRSTUVWXYZ

;Caractères spéciaux 
;©  ( @ )

;Logos 
;No  ( $ % & ' ( ) )
;Irem  ( : ; < = > )

;Objets 
;Curseur  ( # )
;Vie  ( ^ )
;Jauge  ( [ \ ] )

.menu_force
	db 0
	
.default_pal
	db 0,26,20,10
	db #FF
	;db 0,0,0,0
	;db 0,0,0,0
	;db 0,0,0,0
	;db 0
.continue_pal
	db 0,26,20,11
	db #FF
	
.loading_pal
	db 0,26,13,26
	db #FF
	
.game_pal
	db 0,26,11,6,3,20,10,2,1,25,16,18,9,15,4,0
	db 0
	;0, 26, 11, 6, 3, 20/23, 10, 2, 1, 24/25, 16, 18, 9, 15, 4 

	
.crtc_config_options
	db #01,#2E,#02,#31,4,#26,5,0,#06,#16,#07,#1D,#0C,#30,#0D,#00,9,7,#FF
	
.crtc_config_game
	db #01,#20,#02,#2A,4,#26,5,0,#06,#18,#07,32,#0C,#30,#0D,#00,9,7,#FF
	
.crtc_config_loading
	db #01,#20,#02,#2A,4,#26,5,0,#06,#1,#07,10,#0C,#10,#0D,#01,9,7,#FF
	
