;pause or exit
.GAME_CheckPause_rep
	db 0
.GAME_CheckPause

	ld A,(no_hud)
	or A
	ret nz
	
	
	ld A,(GAME_CheckPause_rep)
	or A
	jr z,GAME_CheckPauseCreditCheckAllowed
	dec A
	ld (GAME_CheckPause_rep),A
	

.GAME_CheckPauseCreditCheckAllowed	
	;check for credit add
	ld A,(keymap+6)
	bit 1,A
	jr nz,GAME_CheckPauseNoCredit
;anti rebond	
	ld A,20
	ld (GAME_CheckPause_rep),A
;play sound
	;full mode to be sure to have sfx
	xor A
	call SND_SetMode
	
	ld A,sfx_addcredit
	call SND_SfxPlay
	
	;adapt to selected mode 
	ld A,(option_menu_sound)
	call SND_SetMode
	
;check if we add a credit
	ld A,(Current_Tries)
	inc A
	cp 7
	jr nc,GAME_CheckPauseNoCredit
	ld (Current_Tries),A
	
	
.GAME_CheckPauseNoCredit

	ld A,(keymap+8)
	bit 2,A
	jp z,GAME_ForceOverResetScore ;GAME_FullRestart
	
	call GAME_CheckPauseCheckSpace
	ret nz
	
	;full mode to be sure to have sfx
	xor A
	call SND_SetMode
	
	
	ld B,3
.pause_all_channel_sound	
	push BC
	ld A,B
	dec A
	call SND_SfxSetForcedChannel	
	ld A,sfx_pause
	call SND_SfxPlay
	pop BC
	djnz pause_all_channel_sound
	
	ld A,1
	call SND_SfxSetForcedChannel
	

	
	
	ld DE,HUD_POS+54
	ld HL,GAME_Pause_str
	ld BC,color_table_options_red
	call FONT_DrawStringEX
	
	;wait a bit to finish sound	
	ld E,25
	call DSK_wait
	
	call MUSIC_Pause

.GAME_CheckWaitSpaceA	
	call GAME_CheckPauseCheckSpace
	jr z,GAME_CheckWaitSpaceA	
.GAME_CheckWaitSpaceB

	ld A,(keymap+9)
	
	or %11001111
	cp %11001111
	jp z,GAME_PauseExitGameOver
	bit 4,A
	jr z,GAME_PauseForceExit
	
	call GAME_CheckPauseCheckSpace
	jr nz,GAME_CheckWaitSpaceB
.GAME_CheckWaitSpaceC
	call GAME_CheckPauseCheckSpace
	jr z,GAME_CheckWaitSpaceC

.GAME_PauseForceExit
	
	ld DE,HUD_POS+54
	ld HL,GAME_Unpause_str
	call FONT_DrawString
	
	;adapt to selected mode 
	ld A,(option_menu_sound)
	call SND_SetMode
	
	call MUSIC_UnPause
	
	ret
	
.GAME_PauseExitGameOver
	call MUSIC_UnPause
	jp GAME_ForceOverResetScore	
	
.GAME_CheckPauseCheckSpace
	ld A,(keymap+5)
	bit 7,A	
	ret z
	ld A,(keymap+9)
	bit 6,A
	ret
	
	
.GAME_Pause_str
	str "PAUSE"
.GAME_Unpause_str
	str "     "