#!/usr/bin/env python2

#-*- coding: utf-8 -*-
# pyrharckade 2 is a simple pygame front for PIMAME
# version: 2.0A
# guillaume@tuxme.net
# GPL Licence


import pygame
from time import *

import csv
import os
from datetime import datetime
import sys
import subprocess
from pygame.locals import *
from pygame.compat import unicode_
sys.path.insert(0, './CONF/')


if not os.path.exists("./CONF/KeyMapKeyBoard.py"):
	APP="./BIN/SYS.sh 001_CONFIG_KEYBOARD"
	p = subprocess.Popen(APP, shell=True)
	sys.exit("GO play bitch ;)")




from DefFrontEndEmuFile import DefFrontEndEmu
from DefFrontEndGameFile import DefFrontEndGame
from DefReadConfRomFile import DefReadConfRom
from DefReadConfGameFile import DefReadConfGame
from KeyMapKeyBoard import *






#from DefTransition import Transition
pygame.mouse.set_visible(False)
Orientation="X"
if len(sys.argv) == 2:
	if str(sys.argv[1])=="Y":
		Orientation="Y"

if Orientation=="Y":
	from DefFrontEndEmuMapFile import DefFrontEndEmuMapY
else:
	from DefFrontEndEmuMapFile import DefFrontEndEmuMapX




from ConfAllPath import *
from DefResAndSysFile import *
import math
from math import *

Resolution=DefResolution()
System=DefSystem()
if Orientation=="Y":
	MapingEmu=DefFrontEndEmuMapY(Resolution)
else:
	MapingEmu=DefFrontEndEmuMapX(Resolution)
#print str(System)
#print str(Resolution)
ParentOfPyr,ConfRomFile,AllMedia,ConfigKeyboardFile=DefConfPathHome()


#if not os.path.exists(ConfigKeyboardFile):
#	APP="BIN/SYS.sh CONFIG_KEYBOARD"
#	p = subprocess.Popen(APP, shell=True)
#	sys.exit("GO play bitch ;)")

ExitStatus = 0
FrontEndEmu=1
FrontEndGame=0
MAX, MAX_EMU,li,emu=DefReadConfRom(ConfRomFile)

CptGame=0
CptEmu=0


pygame.mixer.init()
pygame.joystick.init()

if pygame.joystick.get_count() != 0:
	mon_joystick = pygame.joystick.Joystick(0)
	mon_joystick.init()
	JOY_TEST = 1
	if HACK_KEY_CARD == 'Y':
		JOY_TEST = 0
else:
	JOY_TEST = 0


while ExitStatus == 0:
	while FrontEndEmu == 1:
#		Transition(Resolution,emu,MapingEmu,li,CptEmu,MAX_EMU,MAX,Orientation)
		FrontEndEmu,ExitStatus,FrontEndGame,EmuChoose,CptEmu=DefFrontEndEmu(Resolution,emu,MapingEmu,li,CptEmu,MAX_EMU,MAX,Orientation,JOY_TEST)
	GamePerEmu,MaxForThisEmu=DefReadConfGame(ConfRomFile,EmuChoose,li)
	while FrontEndGame == 1:
		#print "Go in Game"
		FrontEndGame,ExitStatus,FrontEndEmu,CptEmu=DefFrontEndGame(EmuChoose,Resolution,emu,li,CptGame,MAX_EMU,MAX,CptEmu,GamePerEmu,MaxForThisEmu,Orientation,JOY_TEST)






