//********************************************************* // ***************************************************** // * Brian Pescatore, bhp7 & Tom Gowing,teg25 * // * Code to read input from Nintendo Entertainment * // * System controllers. The controller uses a * // * serialized mechanism for the data polling. This * // * implementation is configured for two controllers. * // ***************************************************** //********************************************************* #include #include #include #include #include "uart.h" #include "NESController.h" FILE uart_str = FDEV_SETUP_STREAM(uart_putchar, uart_getchar, _FDEV_SETUP_RW); /********* Global Variable Declarations *********/ char curr, prev, display, nes1_L, nes2_L; void initialize (void); void switch_led (void); void nes1_update(void); void nes2_update(void); // Timer 0 ISR: decrements all ms counters ISR (TIMER0_COMPA_vect) { if (update_timer>0) --update_timer; } // Inverts the order of the button presses such that the NES 6502 will recieve the buttons in expected order. char flip(char from) { char to = 0; to |= (from & 0x01);from >>= 1; to <<= 1; to |= (from & 0x01);from >>= 1; to <<= 1; to |= (from & 0x01);from >>= 1; to <<= 1; to |= (from & 0x01);from >>= 1; to <<= 1; to |= (from & 0x01);from >>= 1; to <<= 1; to |= (from & 0x01);from >>= 1; to <<= 1; to |= (from & 0x01);from >>= 1; to <<= 1; to |= (from & 0x01); return to; } void SPIInit() { // Make all pins input except the MISO DDRB = 0x40; // Set up SPI SPCR = (1<