Esempio n. 1
0
extern void
print_current_state()
{
  print_board(HORIZONTAL);
  printf("\n");
  print_board_info(HORIZONTAL);
  g_print = 0;
}
Esempio n. 2
0
static void __init mv_init(void)
{
        /* init the Board environment */
       	mvBoardEnvInit();

        /* init the controller environment */
        if (mvCtrlEnvInit() ) {
            printk( "Controller env initialization failed.\n" );
            return;
        }


	/* Init the CPU windows setting and the access protection windows. */
	if (mvCpuIfInit(mv_sys_map())) {

		printk( "Cpu Interface initialization failed.\n" );
		return;
	}
#if defined (CONFIG_MV78XX0_Z0)
	mvCpuIfBridgeReorderWAInit();
#endif

    	/* Init Tclk & SysClk */
    	mvTclk = mvBoardTclkGet();
   	mvSysclk = mvBoardSysClkGet();
	
        support_wait_for_interrupt = 1;
  
#ifdef CONFIG_JTAG_DEBUG
            support_wait_for_interrupt = 0; /*  for Lauterbach */
#endif
	mv_vfp_init();	
	elf_hwcap &= ~HWCAP_JAVA;

   	serial_initialize();

	/* At this point, the CPU windows are configured according to default definitions in mvSysHwConfig.h */
	/* and cpuAddrWinMap table in mvCpuIf.c. Now it's time to change defaults for each platform.         */
	mvCpuIfAddrDecShow(whoAmI());

    	print_board_info();
}
Esempio n. 3
0
// see .h file for usage
bool ldp::pre_search(const char* pszFrame, bool block_until_search_finishes)
{
	char frame[FRAME_ARRAY_SIZE] = { 0 };
	Uint16 frame_number = 0;	// frame to search to
	bool result = false;
	char s1[81] = { 0 };

	// safety check, if they try to search without checking the search result ...
	if (m_status == LDP_SEARCHING)
	{
		printline("LDP : tried to search without checking for search result first! that's bad!");
		printline(frame);
		
		// this is definitely a Daphne bug if this happens, so log it!
		m_bug_log.push_back("LDP.CPP, pre_search() : tried to search without checking for search result first!");
		return false;
	}
	// end safety check

	// Get the frame that we are on now, before we do the seek
	// This is needed in order to calculate artificial seek delay
	// We must do this before we change 'm_status' due to the way get_current_frame is designed
	m_last_seeked_frame = m_uCurrentFrame;

	// we copy here so that we can safely null-terminate
	strncpy(frame, pszFrame, 5);
	frame[5] = 0;	// terminate the string ...
	frame_number = (Uint16) atoi(frame);

	// If we're seeking to the frame we're already on, then don't seek
	// This optimizes performance for many games and especially improves the coin insert delay
	//  for Dragon's Lair 2.
	if ((m_status == LDP_PAUSED) && (frame_number == m_uCurrentFrame))
	{
		printline("LDP NOTE: ignoring seek because we're already on that frame");
		m_status = LDP_PAUSED;	// just to be safe
		return true;
	}

	m_status = LDP_SEARCHING;	// searching can take a while

	// If we need to alter the frame # before searching
	if (need_frame_conversion())
	{
		Uint16 unadjusted_frame = frame_number;
		frame_number = (Uint16) do_frame_conversion(frame_number);
		framenum_to_frame(frame_number, frame);
		sprintf(s1, "Search to %d (formerly %d) received", frame_number, unadjusted_frame);
	}
	else
	{
		sprintf(s1, "Search to %d received", frame_number);
	}

	outstr(s1);

	// notify us if we're still using outdated blocking searching
	if (block_until_search_finishes) outstr(" [blocking] ");

	// if it's Dragon's Lair/Space Ace, print the board we are on
	if ((g_game->get_game_type() == GAME_LAIR) || (g_game->get_game_type() == GAME_DLE1)
		|| (g_game->get_game_type() == GAME_DLE2)
		|| (g_game->get_game_type() == GAME_ACE))
	{
		Uint8 *cpumem = get_cpu_mem(0);	// get the memory for the first (and only)
		outstr(" - ");
		print_board_info(cpumem[0xA00E], cpumem[0xA00F], cpumem[Z80_GET_IY]);
	}
	else
	{
		newline();
	}

	// If the user requested a delay before seeking, make it now
	if (search_latency > 0)
	{
#ifdef DEBUG
		// search latency needs to be reworked so that think() is getting called ...
		assert(false);
#endif
//		make_delay(get_search_latency());
		printline("WARNING : search latency needs to be redesigned, it is currently disabled");
	}

	m_last_try_frame = (Uint16) atoi(frame);	// the last frame we tried to seek to becomes this current one

	// HERE IS WHERE THE SEARCH ACTUALLY TAKES PLACE

	int difference = frame_number - m_uCurrentFrame;	// how many frames we'd have to skip

	// if the player supports skipping AND user has requested the we skip instead of searching when possible
	// AND if we can skip forward instead of seeking ...
	if (skipping_supported && skip_instead_of_search && ((difference <= max_skippable_frames) && (difference > 1)))
	{
		result = pre_skip_forward((Uint16) difference);
	}

	// otherwise do a regular search
	else
	{
		result = nonblocking_search(frame);
		m_dont_get_search_result = false;	// it's now ok to get the search result

		// if search succeeded
		if (result)
		{
			// if we are to block until the search finishes, then wait here (this is bad, don't do this!)
			// This is only here for backward compatibility!
			if (block_until_search_finishes)
			{
				unsigned int cur_time = refresh_ms_time();
				unsigned int uLastTime = cur_time;	// used to compute m_uBlockedMsSincePlay
				int ldp_stat = -1;

				// we know we may be waiting for a while, so we pause the cpu timer to avoid getting a flood after the seek completes
				cpu_pause();

				// wait for player to change its status or for us to timeout
				while (elapsed_ms_time(cur_time) < 7000)
				{
					ldp_stat = get_status();	// get_status does some stuff that needs to get done, so we don't just read m_status instead

					// if the search is finished
					if (ldp_stat != LDP_SEARCHING)
					{
						break;
					}

					// Since the cpu is paused, we should not use think_delay
					// Also, blocking seeking may be used for skipping in noldp mode for cpu games like super don,
					//  so we cannot use think_delay here.
					MAKE_DELAY(1);

					// VLDP relies on our timers for its timing, so we need to keep the time moving forward during
					//  this period where we're paused. (and we can't use think_delay or pre_think because it can
					//  cause vblank events which can cause irqs while the cpu is supposed to be paused)
					unsigned int uCurTimeTmp = refresh_ms_time();
					m_uBlockedMsSincePlay += (uCurTimeTmp - uLastTime);	// since we're blocked, the blockmssinceplay must increase
					uLastTime = uCurTimeTmp;
					think();
				}

				cpu_unpause();	// done with the delay, so we can unpause

				// if we didn't succeed, then return an error
				if (ldp_stat != LDP_PAUSED)
				{
					printline("LDP : blocking search didn't succeed");
					result = false;
				}
			} // end if we were doing a blocking styled search
		} // if the initial search command was accepted

		// else if search failed immediately
		else
		{
			printline("LDP : search failed immediately");
			m_status = LDP_ERROR;
		}

	} // end regular search (instead of skipping)

	return(result);
}
Esempio n. 4
0
/*****************************************************************************
 * UART
 ****************************************************************************/
static struct resource mv_uart_resources[] = {
	{
		.start		= PORT0_BASE,
		.end		= PORT0_BASE + 0xff,
		.flags		= IORESOURCE_MEM,
	},
	{
		.start          = IRQ_UART0,
		.end            = IRQ_UART0,
		.flags          = IORESOURCE_IRQ,
	},
	{
		.start		= PORT1_BASE,
		.end		= PORT1_BASE + 0xff,
		.flags		= IORESOURCE_MEM,
	},
	{
		.start          = IRQ_UART1,
		.end            = IRQ_UART1,
		.flags          = IORESOURCE_IRQ,
	},
};

static struct plat_serial8250_port mv_uart_data[] = {
	{
		.mapbase	= PORT0_BASE,
		.membase	= (char *)PORT0_BASE,
		.irq		= IRQ_UART0,
		.flags		= UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
		.iotype		= UPIO_MEM,
		.regshift	= 2,
	},
	{
		.mapbase	= PORT1_BASE,
		.membase	= (char *)PORT1_BASE,
		.irq		= IRQ_UART1,
		.flags		= UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
		.iotype		= UPIO_MEM,
		.regshift	= 2,
	},
	{ },
};

static struct platform_device mv_uart = {
	.name			= "serial8250",
	.id			= PLAT8250_DEV_PLATFORM,
	.dev			= {
		.platform_data	= mv_uart_data,
	},
	.num_resources		= ARRAY_SIZE(mv_uart_resources),
	.resource		= mv_uart_resources,
};


static void serial_initialize(void)
{
	mv_uart_data[0].uartclk = mv_uart_data[1].uartclk = mvTclk;
	platform_device_register(&mv_uart);
}

static void __init mv_vfp_init(void)
{

#if defined CONFIG_VFP_FASTVFP
        printk("VFP initialized to Run Fast Mode.\n");
#endif
}

#if defined(MV_88F6183)

#ifdef CONFIG_MV_INCLUDE_AUDIO

typedef struct {
	unsigned int base;
	unsigned int size;
} _audio_mem_info;

typedef struct {
	u32 spdif_rec;
	u32 spdif_play;
	u32 i2s_rec;
	u32 i2s_play;
	_audio_mem_info mem_array[MV_DRAM_MAX_CS + 1];
} _audio_info;

_audio_info audio_info = {1, 1, 1, 1};

 static struct resource mv_snd_resources[] = {
	[0] = {
		.start	= INTER_REGS_BASE + AUDIO_REG_BASE,
		.end	= INTER_REGS_BASE + AUDIO_REG_BASE + SZ_16K -1,
		.flags	= IORESOURCE_MEM,
	},
	[1] = {
		.start	= IRQ_AUDIO_INT,
		.end	= IRQ_AUDIO_INT,
		.flags	= IORESOURCE_IRQ,
	},
	[2] = {
		.start	= NR_IRQS,	/* should obtained from board information*/
		.end	= NR_IRQS,	/* should obtained from board information */
		.flags	= IORESOURCE_IRQ,
	}
 };

static u64 mv_snd_dmamask = 0xFFFFFFFFUL;

static struct platform_device mv_snd_device = {
	.name	= "mv88fx_snd",
	.id	= -1,
	.dev	= {
		.dma_mask		= &mv_snd_dmamask,
		.coherent_dma_mask	= 0xFFFFFFFF,
		.platform_data		= &audio_info,
	},
	.num_resources	= ARRAY_SIZE(mv_snd_resources),
	.resource	= mv_snd_resources,
};

#endif /* #ifdef CONFIG_MV_INCLUDE_AUDIO */

#ifdef CONFIG_MV_INCLUDE_SDIO
static struct resource mvsdmmc_resources[] = {
	[0] = {
		.start	= INTER_REGS_BASE + 0x80000,
		.end	= INTER_REGS_BASE + 0x80000 + SZ_1K -1,
		.flags	= IORESOURCE_MEM,
	},
	[1] = {
		.start	= SDIO_IRQ_NUM,
		.end	= SDIO_IRQ_NUM,
		.flags	= IORESOURCE_IRQ,
	},
	[2] = {
		.start	= NR_IRQS,	/* should obtained from board information*/
		.end	= NR_IRQS,	/* should obtained from board information */
		.flags	= IORESOURCE_IRQ,
	}

};

static u64 mvsdmmc_dmamask = 0xffffffffUL;

static struct platform_device mvsdmmc_device = {
	.name		= "mvsdmmc",
	.id		= -1,
	.dev		= {
		.dma_mask = &mvsdmmc_dmamask,
		.coherent_dma_mask = 0xffffffff,
	},
	.num_resources	= ARRAY_SIZE(mvsdmmc_resources),
	.resource	= mvsdmmc_resources,
};

#endif /* CONFIG_MV_INCLUDE_SDIO */

static struct platform_device *devices[] __initdata = {
#ifdef CONFIG_MV_INCLUDE_AUDIO
	&mv_snd_device,
#endif
#ifdef CONFIG_MV_INCLUDE_SDIO
 	&mvsdmmc_device,
#endif
 	NULL
};

#endif /* #if defined(MV_88F6183) */
static void __init mv_init(void)
{

	unsigned int temp;
        /* init the Board environment */
        if (mvBoardIdGet() != RD_88F6082_MICRO_DAS_NAS)  /* excluded for HDD power problem - to be fixed */
		mvBoardEnvInit();

        /* init the controller environment */
        if( mvCtrlEnvInit() ) {
            printk( "Controller env initialization failed.\n" );
            return;
        }

	if(mvBoardIdGet() == RD_88F5181_POS_NAS) {
		temp = MV_REG_READ(GPP_DATA_OUT_REG(0));
		temp &= ~(1 << 0x5);

		/* for host mode should be set to 0 */
		if(!mvIsUsbHost) {
			temp |= (1 << 0x5);
		}
        	MV_REG_WRITE(GPP_DATA_OUT_REG(0), temp);
	}

	/* Init the CPU windows setting and the access protection windows. */
	if( mvCpuIfInit(mv_sys_map()) ) {

		printk( "Cpu Interface initialization failed.\n" );
		return;
	}

    	/* Init Tclk & SysClk */
    	mvTclk = mvBoardTclkGet();
   	mvSysclk = mvBoardSysClkGet();

	printk("Sys Clk = %d, Tclk = %d\n",mvSysclk ,mvTclk  );
	

    	if ((mvCtrlModelGet() == MV_5281_DEV_ID) || (mvCtrlModelGet() == MV_1281_DEV_ID)
			|| (mvCtrlModelGet() == MV_6183_DEV_ID))
            mv_orion_ver = MV_ORION2; /* Orion II */
    	else
            mv_orion_ver = MV_ORION1; /* Orion I */

        /* Implement workaround for FEr# CPU-C16: Wait for interrupt command */ 
        /* is not processed properly, the workaround is not to use this command */
        /* the erratum is relevant for 5281 devices with revision less than C0 */
        if((mvCtrlModelGet() == MV_5281_DEV_ID)
         && (mvCtrlRevGet() < MV_5281_C0_REV))
        {
            support_wait_for_interrupt = 0;
        }

#ifdef CONFIG_JTAG_DEBUG
            support_wait_for_interrupt = 0; /*  for Lauterbach */
#endif
	mv_vfp_init();
	elf_hwcap &= ~HWCAP_JAVA;

   	serial_initialize();

	/* At this point, the CPU windows are configured according to default definitions in mvSysHwConfig.h */
	/* and cpuAddrWinMap table in mvCpuIf.c. Now it's time to change defaults for each platform.         */
	mvCpuIfAddDecShow();


#if defined(CONFIG_MTD_PHYSMAP)
	mv_mtd_initialize();
#endif
    	print_board_info();

#ifdef CONFIG_MV_INCLUDE_IDMA
    	mvDmaInit();
#endif

#if defined(MV_88F6183)

#ifdef 	CONFIG_MV_INCLUDE_SDIO
	mvsdmmc_resources[2].end = mvBoardSDIOGpioPinGet() + IRQ_GPP_START;
	mvsdmmc_resources[2].start = mvBoardSDIOGpioPinGet() + IRQ_GPP_START;
	irq_int_type[mvBoardSDIOGpioPinGet()] = GPP_IRQ_TYPE_CHANGE_LEVEL;
#endif /* CONFIG_MV_INCLUDE_SDIO */
	
#ifdef CONFIG_MV_INCLUDE_AUDIO
	for (temp=0 ; temp< MV_DRAM_MAX_CS; temp++) {
		MV_DRAM_DEC_WIN win;
		audio_info.mem_array[temp].base = 0;
		audio_info.mem_array[temp].size = 0;

		mvDramIfWinGet(SDRAM_CS0 + temp, &win);

		if (win.enable) {
			audio_info.mem_array[temp].base = win.addrWin.baseLow;
			audio_info.mem_array[temp].size = win.addrWin.size;
		}
	}
#endif /* CONFIG_MV_INCLUDE_AUDIO */
	if ((temp = ARRAY_SIZE(devices) - 1))
		platform_add_devices(devices, temp);

#endif /* MV_88F6183 */
    return;
}
Esempio n. 5
0
// TODO: add player payments for chance/chest
int main(int argc, char ** argv)
{
    struct timeval t1, t2;
    MPI_Init(&argc, &argv);
    gettimeofday(&t1, NULL);
    int rank, size;
    MPI_Comm_rank(MPI_COMM_WORLD, &globalrank);
    MPI_Comm_size(MPI_COMM_WORLD, &size);
    globalsize = size;
    srand(time(NULL) + globalrank);
    struct location board[BSIZE];
    struct player players[NUMPLAYERS];
    int itr = 10000;
    long long bills[4]; // how much you owe each player at end of round
    init_players(players);
    init_board(board);
    char plocation;
    int pvalue;
    int numcomms = 1;
    MPI_Group world_group;
    MPI_Comm_group(MPI_COMM_WORLD, &world_group);
    playerdata d;
    d.money[0] = 0;
    d.money[1] = 0;
    d.money[2] = 0;
    d.money[3] = 0;
    output = (FILE **) malloc(size * sizeof(FILE *));

    // if 1 process created just run sequentially
    if (size == 1)
    {
        int done[4] = {1, 1, 1, 1};
        while (itr)
        {
            itr--;
            int i;
            for (i = 0; i < NUMPLAYERS; i++)
            {
                plocation = 0;
                pvalue = 0;
                if (players[i].money > 0)
                {
                    move(players, board, i, &pvalue, &plocation);
                    if (plocation)
                    {
                        board[plocation].owner = i;
                        players[i].money -= pvalue;
                    }
                }
                else
                {
                    players[i].order = -1;
                    if (done[i])
                    {
                        remove_properties(board, i);
                        done[i] = 0;
                    }
                }
            }
        }
        gettimeofday(&t2, NULL);
        results(players, board);
        double exectime = (t2.tv_sec - t1.tv_sec) * 1000000 + ((t2.tv_usec - t1.tv_usec));
        printf("Exec Time %lf\n", exectime);
        return 0;
    }

    // create a communicator for each monopoly game (for n > 4)
    MPI_Group * gamesel;
    MPI_Comm * games;
    int ranksel[4];
    if (size > 4)
    {
        numcomms = size / 4;
        games = (MPI_Comm *) malloc(numcomms * sizeof(MPI_Comm));
        gamesel = (MPI_Group *) malloc(numcomms * sizeof(MPI_Group));
        int i;
        for (i = 0; i < numcomms; i++)
        {
            ranksel[0] = 4 * i;
            ranksel[1] = 4 * i + 1;
            ranksel[2] = 4 * i + 2;
            ranksel[3] = 4 * i + 3;
            MPI_Group_incl(world_group, 4, ranksel, &gamesel[i]);
            MPI_Comm_create(MPI_COMM_WORLD, gamesel[i], &games[i]);
        }
    }
    else
    {
        // n < 4 so use MPI_COMM_WORLD
        games = (MPI_Comm *) malloc(1 * sizeof(MPI_Comm));
        games[0] = MPI_COMM_WORLD;
        numcomms = 1;
    }

    // create an MPI type so that we can use our player data struct in MPI communication calls
    const int nitems = 5;
    int blocklengths[5] = {4, 1, 1, 1, 1};
    MPI_Datatype types[5] = {MPI_LONG_LONG, MPI_INT, MPI_CHAR, MPI_CHAR, MPI_CHAR};
    MPI_Datatype MPI_MONO_DATA;
    MPI_Aint offsets[5];
    offsets[0] = offsetof(playerdata, money);
    offsets[1] = offsetof(playerdata, pvalue);
    offsets[2] = offsetof(playerdata, plocation);
    offsets[3] = offsetof(playerdata, order);
    offsets[4] = offsetof(playerdata, trade);
    MPI_Type_create_struct(nitems, blocklengths, offsets, types, &MPI_MONO_DATA);
    MPI_Type_commit(&MPI_MONO_DATA);

    MPI_Comm_rank(games[globalrank / 4], &rank);

#ifdef DEBUG
    char fname[10];
    snprintf(fname, 10, "mon%d.dbg", globalrank);
    output[globalrank] = fopen(fname, "w");
    fprintf(output[globalrank], "MAIN begin loop\n");
    print_board_info(board);
#endif
    // run the game for 40000 turns (10000 per player)
    while (itr > 0)
    {
        itr--;
        pvalue = 0;
        plocation = 0;
        d.trade = 0;
        d.order = rank;
#ifdef DEBUG
        fprintf(output[globalrank], "MAIN tag 1 rank %d\n", rank);
#endif
        move(players, board, rank, &pvalue, &plocation);
        d.pvalue = pvalue;
        d.plocation = plocation;
#ifdef DEBUG
        fprintf(output[globalrank], "using comm %d\n", globalrank / 4);
        if (games[globalrank / 4] != MPI_COMM_WORLD)
        {
            fprintf(output[globalrank], "COMM ERROR\n");
        }
#endif
        send_info(&d, players, board, rank, games[globalrank / 4], MPI_MONO_DATA);
#ifdef DEBUG
        fprintf(output[globalrank], "MAIN tag 3 rank %d\n", rank);
        print_board_info(board);
#endif
    }
    
#ifdef DEBUG
    fprintf(output[globalrank], "MAIN last tag rank %d\n", rank);
#endif
    // get results from each process
    gather_results(players, board, games, numcomms, globalrank);
    gettimeofday(&t2, NULL);
    if (globalrank == 0)
    {
        results(players, board);
    }


#ifdef DEBUG
    fclose(output[globalrank]);
#endif
    double exectime = (t2.tv_sec - t1.tv_sec) * 1000000 + ((t2.tv_usec - t1.tv_usec));
    if (globalrank == 0)
    {
        printf("Exec Time %lf\n", exectime);
    }
    MPI_Finalize();

    return 0;
}