;
; *** init code that will be trashed ***
.Trash_GAUGE_Init

;interlace tiles
	ld B,48
	ld IY,GAUGE_Gfx
	ld IX,GAUGE_Left
	ld DE,4
	
.Trash_GAUGE_Init_Loop

	ld A,(IY+0)
	ld (IX+0),A
	
	ld A,(IY+1)
	ld (IX+1),A

	ld A,(IY+2)
	ld (IX+3),A
	
	ld A,(IY+3)
	ld (IX+2),A

	add IX,DE
	add IY,DE
	djnz Trash_GAUGE_Init_Loop
	
	ret
.GAUGE_Gfx
	incbin "gfx/beam_left.pm1"
	incbin "gfx/beam_right.pm1"
	incbin "gfx/beam0.pm1"	
	incbin "gfx/beam1.pm1"		
	incbin "gfx/beam2.pm1"
	incbin "gfx/beam3.pm1"
	incbin "gfx/beam4.pm1"
	incbin "gfx/beam5.pm1"
	incbin "gfx/beam6.pm1"
	incbin "gfx/beam7.pm1"
	incbin "gfx/beam8.pm1"
	incbin "gfx/beam_full.pm1"

TRASH_GenLaserTable:

	ld HL,laser_move_TableTemp
	ld DE,LaserMove_Table
	ld BC,16
	ldir
	ret
.laser_move_TableTemp
	dw	laser_move0
	dw	laser_move1
	dw	laser_move2
	dw	laser_move3
	dw	laser_move4
	dw	laser_move5
	dw	laser_move6
	dw	laser_move7	

TRASH_GenBulletTable:
	ld HL,BULLETS_TableTemp
	ld DE,BULLETS_Table
	ld BC,32
	ldir
	ret

.BULLETS_TableTemp
	dw	BULLETS_Table_Dir0	;0000	0
	dw	BULLETS_Table_Dir0  ;0001		1
	dw	BULLETS_Table_Dir4	;0010		2
	dw	BULLETS_Table_Dir0	;0011		3
	dw	BULLETS_Table_Dir6	;0100		4
	dw	BULLETS_Table_Dir7	;0101		5
	dw	BULLETS_Table_Dir5	;0110		6
	dw	BULLETS_Table_Dir0	;0111		7
	dw	BULLETS_Table_Dir2	;1000		8
	dw	BULLETS_Table_Dir1	;1001		9
	dw	BULLETS_Table_Dir3	;1010		10
	dw	BULLETS_Table_Dir0	;1011		11
	dw	BULLETS_Table_Dir0	;1100		12
	dw	BULLETS_Table_Dir0	;1101		13
	dw	BULLETS_Table_Dir0	;1110		14
	dw	BULLETS_Table_Dir0	;1111		15

	
;
TRASH_GenRevTable:
	ld HL,rev_table
	

.make_rev_loop

if r_mode
	ld A,L
	and %10001000 ;get 1
	or A  ;reset carry
	rra  ;0100
	rra  ;0010
	rra  ;0001
	ld B,A

	ld A,L
	and %01000100 ;get 2
	or A
	rra ;0010
	or B
	ld B,A

	ld A,L
	and %00100010 ;get 3
	or a
	rla ;0100
	or B
	ld B,A

	ld A,L
	and %00010001
	or a
	rla ;0010
	rla ;0100
	rla ;1000
	or B
else
	ld A,L
	and %10101010
	or A
	rra
	ld B,A

	ld A,L
	and %01010101
	or A
	rla
	or B
endif

	ld (HL),A
	
	inc L
	jr nz,make_rev_loop

	ret

TRASH_JumpTableSetup:
	ld BC,256
	ld HL,REND_JumpTable
	ld DE,rend_table
	ldir
	
	ld BC,256
	ld HL,REND_JumpTableBis
	ld DE,rend_table+256
	ldir
	
	ret

TRASH_ArraySetup:
	ld IX,temp_array
	ld IY,ATTR_Addr
	ld B,20
	
.TRASH_ArraySetup_loop	
	ld E,(IX)
	ld D,(IX+1)
	ld HL,ATTR_Line_Base
	add HL,DE	
	ld (IY),L
	ld (IY+1),H
	inc IX
	inc IX
	inc IY
	inc IY
	djnz TRASH_ArraySetup_loop	
	ret

TRASH_BankSetup:

	ld BC,#7FC4
	ld HL,#4000
	
	repeat 4
	out (C),C
	ld (HL),C
	inc C
	rend
	
	ld C,#C0
	out (C),C
	ld (HL),C
	
	ret

;*** gen color tables for font
TRASH_InitColorTables:

	;ld BC,#7FC0
	;out (C),C

	ld HL,color_table_options_normal
	ld DE,options_normal_colors
	call TRASH_GenColorTable
	
	ld HL,color_table_options_red
	ld DE,options_red_colors
	call TRASH_GenColorTable
	
	ld HL,color_table_game_text
	ld DE,game_text_colors
	call TRASH_GenColorTable
	
	ret
	
.options_normal_colors
	db 0,3,2,1
	
.options_red_colors
	db 0,3,3,1
	
.title_bold_colors
	db 0,3,2,1
	
.game_text_colors
	db 0,1,2,2
	

	
;*** gen a color table for font ***
;HL = table address
;DE = new colors
	
TRASH_GenColorTable:

;get new color table in HL
	push HL
	ld HL,#C000
	ex DE,HL
	ld BC,4
	ldir
	pop HL
	exx
	ld HL,#C000	;temporary table adress
	exx

.TRASH_GCT_loop1

	exx
	xor A
	ld B,A	;B pix 0
	ld C,A	;C pix  1
	ld D,A	;D pix 2
	ld E,A	;E pix 3	
	exx
	
	ld A,L
	
	exx

;************************
;*** first extract colors	***
;************************	
	
;pix	
; A = 0123 0123
;bit
; A = 0000 1111
	
;*** bit 1***
	
	rra	;pix 3 
	rl E
	
	rra ;pix 2 
	rl D
	
	rra ;pix 1
	rl C
	
	rra ;pix 0
	rl B
	
;*** bit 0***

	rra	;pix 3 
	rl E
	
	rra ;pix 2 
	rl D
	
	rra ;pix 1
	rl C
	
	rra ;pix 0
	rl B
	
;********************************
;*** second convert to new colors ***
;********************************

	ld L,B
	ld B,(HL) ;pix 0
	
	ld L,C
	ld C,(HL) ;pix 1
	
	ld L,D
	ld D,(HL) ;pix 2
	
	ld L,E
	ld E,(HL) ;pix 3

;****************************	
;*** third , rebuild byte totaly ***
;****************************

;pix	
; A = 0123 0123
;bit
; A = 0000 1111

	xor A

;bit 0	
	
	rr B	;pix 0
	rla
	
	rr C	;pix 1
	rla
	
	rr D	;pix 2
	rla
	
	rr E	;pix 3
	rla
	
;bit 1
	
	rr B	;pix 0
	rla
	
	rr C	;pix 1
	rla
	
	rr D	;pix 2
	rla
	
	rr E	;pix 3
	rla

;************************************
;*** fourth , write byte and finish loop ***
;************************************

	exx
	
	ld (HL),A
	
	inc L
	jp nz,TRASH_GCT_loop1	

	ret
	