Ejemplo n.º 1
0
int main(int argc, char *argv[])
{
	printf("Initializing game\n");
	clock_t start, end;
	int remaining_time;
	
	display_init();
    gamepad_init();
    grid_init(grid);
    players_init(grid, players);
    
    display_fill_screen(0);
    g_running = 1;
    
    while(g_running) {
        start = clock();
        
        update_pos(grid, players);
        
        end = clock();
        
        remaining_time = TIME_PER_LOOP - (((end - start)/CLOCKS_PER_SEC)*1000);
        
        if(remaining_time > 0) {
            usleep(remaining_time*1000);
        }
        
        continue;
    }
	exit(EXIT_SUCCESS);
}
Ejemplo n.º 2
0
int main()
{
	// set for 16 MHz clock
	CPU_PRESCALE(0);

	// Configure all port B and port D pins as inputs with pullup resistors.
	DDRD = 0x00;
	DDRB = 0x00;
	PORTB = 0xFF;
	PORTD = 0xFF;

    // Turn the LED on during the configuration
    LED_CONFIG;
    LED_ON;

	// Initialize the USB, and then wait for the host to set configuration.
	usb_init();
	while (!usb_configured());

    // Initialize the gamepad interface
    gamepad_init();

	// Wait an extra second for the PC's operating system to load drivers
	// and do whatever it does to actually be ready for input
	_delay_ms(1000);

    // Timer 0 configuration (~60Hz)
	TCCR0A = 0x00;  // Normal mode
	TCCR0B = 0x05;  // Clock/1024
	TIMSK0 = (1<<TOIE0);

    LED_OFF;

	while (1) {
        while (!ready);  // Block until the next cycle (~60Hz)
        cli();
        ready = 0;
        sei();

        // Read pressed buttons from gamepad interface
        gamepad_read();

        // Reset key array
        reset_keys();

        // Special functions
        // - Software reboot
        if (PRESSED_REBOOT) {
            reboot();
        }

        // 6 keys can be sent at a time, with any number of modifiers.
        //
        // - Buttons A, B, X and Y have their own position in the key array.
        // - Up/down and left/right pairs share one position, as they are
        //     mutually exclusive (you cannot pres up AND down).
        // - L and R use the left and right Shift modifiers.
        // - Select and Start use the left and right Ctrl modifiers.

        if (PRESSED_A) press_key(KEY_Z, 0);
        if (PRESSED_B) press_key(KEY_X, 1);
        if (PRESSED_X) press_key(KEY_A, 2);
        if (PRESSED_Y) press_key(KEY_S, 3);

        if (PRESSED_UP) {
            press_key(KEY_UP, 4);
        } else if (PRESSED_DOWN){
            press_key(KEY_DOWN, 4);
        }

        if (PRESSED_LEFT) {
            press_key(KEY_LEFT, 5);
        } else if (PRESSED_RIGHT){
            press_key(KEY_RIGHT, 5);
        }

        if (PRESSED_L) press_modifier(KEY_LEFT_SHIFT);
        if (PRESSED_R) press_modifier(KEY_RIGHT_SHIFT);
        if (PRESSED_SELECT) press_modifier(KEY_LEFT_CTRL);
        if (PRESSED_START) press_modifier(KEY_RIGHT_CTRL);

        usb_keyboard_send();
	}
}