inline void ReadController(){ reportBuffer.y = reportBuffer.x = reportBuffer.b1 = reportBuffer.b2 = 0; reportBuffer.rx = reportBuffer.ry = 0; reportBuffer.hat = -1; ReadN64GC(&reportBuffer); }
void ReadController(uchar id) { cli(); // disable interrupts when reading controller uchar skipdb9flag = 0; // don't read DB9 when shared lines are in use by DB15 uchar pcinton = 0; reportBuffer = emptyReportBuffer; reportBuffer.hat = -1; reportBuffer.reportid = id; reportBufferMouse = emptyReportBufferMouse; reportBufferMouse.reportid = id; reportBufferWheel = emptyReportBufferWheel; reportBufferWheel.hat = -1; reportBufferWheel.reportid = id; reportBufferAnalogButtons = emptyReportBufferAnalogButtons; reportBufferAnalogButtons.hat = -1; reportBufferAnalogButtons.reportid = id; hidMode = HIDM_1P; //ReadDreamcast(&reportBuffer); // Check 15 pin connector if (!(PINC & (1<<5))) // Key 1 = L { if (!(PINC & (1<<4))) // Key 2 = L { switch (PINC & 0b00011110) { case 0: // LLLL ReadSaturn(&reportBuffer); skipdb9flag = 1; break; case (1<<1): // LLLH ReadPSX(&reportBuffer, &reportBufferWheel, &reportBufferAnalogButtons); skipdb9flag = 1; break; case ((1<<1)|(1<<2)): // LLHH ReadPCE(&reportBuffer); skipdb9flag = 1; break; case (1<<2): // LLHL ReadPCFX(&reportBuffer); break; case ((1<<2)|(1<<3)): // LHHL hidMode = HIDM_MOUSE; pcinton = 1; if (id == 1) { ReadAmigaMouse(&reportBufferMouse); skipdb9flag = 1; } break; case ((1<<3)|(1<<1)): // LHLH ReadCD32(&reportBuffer); skipdb9flag = 1; break; case (1<<3): // LHLL switch (PINB & 0b110) { case 0b110: // HH ReadAtariDriving(&reportBuffer); break; case 0b000: // LL Read3DO(&reportBuffer); break; case 0b010: // LH ReadSegaPaddle(&reportBuffer); break; } skipdb9flag = 1; break; } } else // Key 2 = H { if (!(PINC & (1<<3))) { ReadTimers(&reportBuffer); // Key 1 = H, DB15-10 = L, Timer based skipdb9flag = 1; } else { if (id == 2) { ReadDualDB9(&reportBuffer); // Key 1 = H, DB15-10 = H, 2P mode skipdb9flag = 1; } hidMode = HIDM_2P; } } } else if (!(PINC & (1<<3))) // Key 1 = H, DB15-10 = L { ReadAnalogue(&reportBuffer, id); skipdb9flag = 1; } else ReadDB15(&reportBuffer); // Key 1 = H, DB15-10 = H // Check 9 pin connector if (!skipdb9flag) { if ( (PIND & ((1<<0)|(1<<3))) == 0) // UP/DN = 0 { if (PIND & (1<<4)) { // N64 / Gamecube ReadN64GC(&reportBuffer); } else { // Famicom ReadFamicom(&reportBuffer, &reportBufferMouse); } } else { ReadDB9(&reportBuffer); } } // Mouse mode joystick support if ((id == 2) & (hidMode == HIDM_MOUSE)) { reportBufferMouse.b1 = reportBuffer.x; reportBufferMouse.x = reportBuffer.y; reportBufferMouse.y = reportBuffer.b1; reportBufferMouse.w = reportBuffer.b2; } if (!pcinton) PCICR &= ~(1<<PCIE0); sei(); // re-enable interrupts after reading controller }