int ControllerTick = 0; // for timing in japan private byte ReadControls1() { InputCallbacks.Call(); _lagged = false; byte value = 0xFF; switch (SyncSettings.ControllerType) { case "Paddle": { // use analog values from a controller, see http://www.smspower.org/Development/Paddle int paddle1Pos; if (_controller.IsPressed("P1 Left")) paddle1Pos = PaddleMin; else if (_controller.IsPressed("P1 Right")) paddle1Pos = PaddleMax; else paddle1Pos = (int)_controller.GetFloat("P1 Paddle"); int paddle2Pos; if (_controller.IsPressed("P2 Left")) paddle2Pos = PaddleMin; else if (_controller.IsPressed("P2 Right")) paddle2Pos = PaddleMax; else paddle2Pos = (int)_controller.GetFloat("P2 Paddle"); PresetControllerState(1); // Hard-wired together? Controller2SelectHigh = Controller1SelectHigh; if (Controller1SelectHigh) { if ((paddle1Pos & 0x10) == 0) value &= 0xFE; if ((paddle1Pos & 0x20) == 0) value &= 0xFD; if ((paddle1Pos & 0x40) == 0) value &= 0xFB; if ((paddle1Pos & 0x80) == 0) value &= 0xF7; } else { if ((paddle1Pos & 0x01) == 0) value &= 0xFE; if ((paddle1Pos & 0x02) == 0) value &= 0xFD; if ((paddle1Pos & 0x04) == 0) value &= 0xFB; if ((paddle1Pos & 0x08) == 0) value &= 0xF7; } if (_controller.IsPressed("P1 B1")) value &= 0xEF; if (!Controller1SelectHigh) value &= 0xDF; if (Controller2SelectHigh) { if ((paddle2Pos & 0x10) == 0) value &= 0xBF; if ((paddle2Pos & 0x20) == 0) value &= 0x7F; } else { if ((paddle2Pos & 0x01) == 0) value &= 0xBF; if ((paddle2Pos & 0x02) == 0) value &= 0x7F; } PostsetControllerState(1); } break; case "Light Phaser": if (_controller.IsPressed("P1 Trigger")) value &= 0xEF; break; case "Sports Pad": { int p1X; if (_controller.IsPressed("P1 Left")) p1X = SportsPadMin; else if (_controller.IsPressed("P1 Right")) p1X = SportsPadMax; else p1X = (int)_controller.GetFloat("P1 X"); int p1Y; if (_controller.IsPressed("P1 Up")) p1Y = SportsPadMin; else if (_controller.IsPressed("P1 Down")) p1Y = SportsPadMax; else p1Y = (int)_controller.GetFloat("P1 Y"); int p2X; if (_controller.IsPressed("P2 Left")) p2X = SportsPadMin; else if (_controller.IsPressed("P2 Right")) p2X = SportsPadMax; else p2X = (int)_controller.GetFloat("P2 X"); int p2Y; if (_controller.IsPressed("P2 Up")) p2Y = SportsPadMin; else if (_controller.IsPressed("P2 Down")) p2Y = SportsPadMax; else p2Y = (int)_controller.GetFloat("P2 Y"); if (_region == "Japan") { p1X += 128; p1Y += 128; p2X += 128; p2Y += 128; } else { p1X *= -1; p1Y *= -1; p2X *= -1; p2Y *= -1; } PresetControllerState(1); // advance state if (Controller1SelectHigh && (Controller1State % 2 == 0)) { ++Controller1State; } else if (!Controller1SelectHigh && (Controller1State % 2 == 1)) { if (++Controller1State == (_region == "Japan" ? 6 : 4)) Controller1State = 0; } if (Controller2SelectHigh && (Controller2State % 2 == 0)) { ++Controller2State; } else if (!Controller2SelectHigh && (Controller2State % 2 == 1)) { if (++Controller2State == (_region == "Japan" ? 6 : 4)) Controller2State = 0; } switch (Controller1State) { case 0: if ((p1X & 0x10) == 0) value &= 0xFE; if ((p1X & 0x20) == 0) value &= 0xFD; if ((p1X & 0x40) == 0) value &= 0xFB; if ((p1X & 0x80) == 0) value &= 0xF7; break; case 1: if ((p1X & 0x01) == 0) value &= 0xFE; if ((p1X & 0x02) == 0) value &= 0xFD; if ((p1X & 0x04) == 0) value &= 0xFB; if ((p1X & 0x08) == 0) value &= 0xF7; break; case 2: if ((p1Y & 0x10) == 0) value &= 0xFE; if ((p1Y & 0x20) == 0) value &= 0xFD; if ((p1Y & 0x40) == 0) value &= 0xFB; if ((p1Y & 0x80) == 0) value &= 0xF7; break; case 3: if ((p1Y & 0x01) == 0) value &= 0xFE; if ((p1Y & 0x02) == 0) value &= 0xFD; if ((p1Y & 0x04) == 0) value &= 0xFB; if ((p1Y & 0x08) == 0) value &= 0xF7; break; case 4: // specific to Japan: sync via TR value &= 0xDF; break; case 5: // specific to Japan: buttons if (_controller.IsPressed("P1 B1")) value &= 0xFE; if (_controller.IsPressed("P1 B2")) value &= 0xFD; break; } if (_region != "Japan") { // Buttons like normal in Export if (_controller.IsPressed("P1 B1")) value &= 0xEF; if (_controller.IsPressed("P1 B2")) value &= 0xDF; } else { // In Japan, it contains selectHigh if (!Controller1SelectHigh) value &= 0xEF; } switch (Controller2State) { case 0: if ((p2X & 0x10) == 0) value &= 0xBF; if ((p2X & 0x20) == 0) value &= 0x7F; break; case 1: if ((p2X & 0x01) == 0) value &= 0xBF; if ((p2X & 0x02) == 0) value &= 0x7F; break; case 2: if ((p2Y & 0x10) == 0) value &= 0xBF; if ((p2Y & 0x20) == 0) value &= 0x7F; break; case 3: if ((p2Y & 0x01) == 0) value &= 0xBF; if ((p2Y & 0x02) == 0) value &= 0x7F; break; case 5: // specific to Japan: buttons if (_controller.IsPressed("P2 B1")) value &= 0xBF; if (_controller.IsPressed("P2 B2")) value &= 0x7F; break; } PostsetControllerState(1); } break; case "Keyboard": { // use keyboard map to get each bit for (int bit = 0; bit < 8; ++bit) { string key = KeyboardMap[(PortDE & 0x07) * 12 + bit]; if (key != null && _controller.IsPressed(key)) { value &= (byte)~(1 << bit); } } } break; default: // Normal controller if (_controller.IsPressed("P1 Up")) value &= 0xFE; if (_controller.IsPressed("P1 Down")) value &= 0xFD; if (_controller.IsPressed("P1 Left")) value &= 0xFB; if (_controller.IsPressed("P1 Right")) value &= 0xF7; if (_controller.IsPressed("P1 B1")) value &= 0xEF; if (_controller.IsPressed("P1 B2")) value &= 0xDF; if (_controller.IsPressed("P2 Up")) value &= 0xBF; if (_controller.IsPressed("P2 Down")) value &= 0x7F; break; } return value; }
void ButtonCallback() { InputCallbacks.Call(); }
private byte ReadControls2() { InputCallbacks.Call(); _lagged = false; byte value = 0xFF; switch (SyncSettings.ControllerType) { case "Paddle": { // use analog values from a controller, see http://www.smspower.org/Development/Paddle int paddle2Pos; if (_controller.IsPressed("P2 Left")) { paddle2Pos = PaddleMin; } else if (_controller.IsPressed("P2 Right")) { paddle2Pos = PaddleMax; } else { paddle2Pos = (int)_controller.GetFloat("P2 Paddle"); } PresetControllerState(2); if (Controller2SelectHigh) { if ((paddle2Pos & 0x40) == 0) { value &= 0xFE; } if ((paddle2Pos & 0x80) == 0) { value &= 0xFD; } } else { if ((paddle2Pos & 0x04) == 0) { value &= 0xFE; } if ((paddle2Pos & 0x08) == 0) { value &= 0xFD; } } if (_controller.IsPressed("P2 B1")) { value &= 0xFB; } if (!Controller2SelectHigh) { value &= 0xF7; } PostsetControllerState(2); } break; case "Light Phaser": if (LatchLightPhaser) { value &= 0xBF; LatchLightPhaser = false; } break; case "Sports Pad": { int p2X; if (_controller.IsPressed("P2 Left")) { p2X = SportsPadMin; } else if (_controller.IsPressed("P2 Right")) { p2X = SportsPadMax; } else { p2X = (int)_controller.GetFloat("P2 X"); } int p2Y; if (_controller.IsPressed("P2 Down")) { p2Y = SportsPadMin; } else if (_controller.IsPressed("P2 Up")) { p2Y = SportsPadMax; } else { p2Y = (int)_controller.GetFloat("P2 Y"); } if (_region == "Japan") { p2X += 128; p2Y += 128; } else { p2X *= -1; p2Y *= -1; } PresetControllerState(2); if (Controller2SelectHigh && (Controller2State % 2 == 0)) { ++Controller2State; } else if (!Controller2SelectHigh && (Controller2State % 2 == 1)) { if (++Controller2State == (_region == "Japan" ? 6 : 4)) { Controller2State = 0; } } switch (Controller2State) { case 0: if ((p2X & 0x40) == 0) { value &= 0xFE; } if ((p2X & 0x80) == 0) { value &= 0xFD; } break; case 1: if ((p2X & 0x04) == 0) { value &= 0xFE; } if ((p2X & 0x08) == 0) { value &= 0xFD; } break; case 2: if ((p2Y & 0x40) == 0) { value &= 0xFE; } if ((p2Y & 0x80) == 0) { value &= 0xFD; } break; case 3: if ((p2Y & 0x04) == 0) { value &= 0xFE; } if ((p2Y & 0x08) == 0) { value &= 0xFD; } break; } if (_region != "Japan") { // Buttons like normal in Export if (_controller.IsPressed("P2 B1")) { value &= 0xFB; } if (_controller.IsPressed("P2 B2")) { value &= 0xF7; } } else { if (!Controller2SelectHigh) { value &= 0xF7; } } PostsetControllerState(2); } break; case "Keyboard": { value &= 0x7F; // use keyboard map to get each bit for (int bit = 0; bit < 4; ++bit) { string key = KeyboardMap[(PortDE & 0x07) * 12 + bit + 8]; if (key != null && _controller.IsPressed(key)) { value &= (byte)~(1 << bit); } } } break; default: // Normal controller if (_controller.IsPressed("P2 Left")) { value &= 0xFE; } if (_controller.IsPressed("P2 Right")) { value &= 0xFD; } if (_controller.IsPressed("P2 B1")) { value &= 0xFB; } if (_controller.IsPressed("P2 B2")) { value &= 0xF7; } break; } if (_controller.IsPressed("Reset")) { value &= 0xEF; } if ((Port3F & 0x0F) == 5) { if (_region == "Japan") { value &= 0x3F; } else // US / Europe { if (Port3F >> 4 == 0x0F) { value |= 0xC0; } else { value &= 0x3F; } } } return(value); }
public bool FrameAdvance(IController controller, bool render, bool renderSound) { //Console.WriteLine("-----------------------FRAME-----------------------"); //Update the color palette if a setting changed if (GetSettings().Palette == GBHawk.GBHawk.GBSettings.PaletteType.BW) { _GBCore.ppu.color_palette[0] = GBHawk.GBHawk.color_palette_BW[0]; _GBCore.ppu.color_palette[1] = GBHawk.GBHawk.color_palette_BW[1]; _GBCore.ppu.color_palette[2] = GBHawk.GBHawk.color_palette_BW[2]; _GBCore.ppu.color_palette[3] = GBHawk.GBHawk.color_palette_BW[3]; } else { _GBCore.ppu.color_palette[0] = GBHawk.GBHawk.color_palette_Gr[0]; _GBCore.ppu.color_palette[1] = GBHawk.GBHawk.color_palette_Gr[1]; _GBCore.ppu.color_palette[2] = GBHawk.GBHawk.color_palette_Gr[2]; _GBCore.ppu.color_palette[3] = GBHawk.GBHawk.color_palette_Gr[3]; } if (_tracer.IsEnabled()) { _GBCore.cpu.TraceCallback = s => _tracer.Put(s); } else { _GBCore.cpu.TraceCallback = null; } reset_frame = false; if (controller.IsPressed("P1 Power")) { reset_frame = true; } input_frame_length = controller.AxisValue("Input Cycle"); input_frame_length_int = (int)Math.Floor(input_frame_length); if (input_frame_length_int == 0) { input_frame_length_int = 70224; } pass_a_frame = false; InputCallbacks.Call(); DoFrame(controller); bool ret = pass_a_frame; if (pass_a_frame) { // clear the screen as needed if (_GBCore.ppu.clear_screen) { _GBCore.clear_screen_func(); } // reset the frame cycle counter frame_cycle = 0; } current_cycle = 0; _isLag = pass_a_frame; if (_isLag) { _lagCount++; } reset_frame = false; _frame++; return(ret); }
private LibGambatte.Buttons ControllerCallback() { InputCallbacks.Call(); IsLagFrame = false; return(CurrentButtons); }
private byte ReadControls2() { InputCallbacks.Call(); _lagged = false; byte value = 0xFF; PresetControllerState(2); value &= _controllerDeck.ReadPort2_c1(_controller); value &= _controllerDeck.ReadPort2_c2(_controller); PostsetControllerState(2); if (_controller.IsPressed("Reset")) { value &= 0xEF; } if ((Port3F & 0x0F) == 5) { if (_region == SmsSyncSettings.Regions.Japan) { value &= 0x3F; } else // US / Europe { if (Port3F >> 4 == 0x0F) { value |= 0xC0; } else { value &= 0x3F; } } } if (LatchLightPhaser1) { value &= 0xBF; LatchLightPhaser1 = false; } if (LatchLightPhaser2) { value &= 0x7F; LatchLightPhaser2 = false; } if (!IsGameGear_C && SyncSettings.UseKeyboard) { // 7 represents ordinary controller reads if ((PortDE & 7) != 7) { value = 0x7F; for (int bit = 0; bit < 4; ++bit) { string key = KeyboardMap[(PortDE & 0x07) * 12 + bit + 8]; if (key != null && _controller.IsPressed(key)) { value &= (byte)~(1 << bit); } } } } return(value); }
byte ReadInput() { InputCallbacks.Call(); byte value = 0x3F; int player = SelectedController + 1; if (player < 6) { _lagged = false; if (SEL == false) // return buttons { if (Controller.IsPressed("P" + player + " B1")) { value &= 0xFE; } if (Controller.IsPressed("P" + player + " B2")) { value &= 0xFD; } if (Controller.IsPressed("P" + player + " Select")) { value &= 0xFB; } if (Controller.IsPressed("P" + player + " Run")) { value &= 0xF7; } } else { //return directions if (Controller.IsPressed("P" + player + " Up")) { value &= 0xFE; } if (Controller.IsPressed("P" + player + " Right")) { value &= 0xFD; } if (Controller.IsPressed("P" + player + " Down")) { value &= 0xFB; } if (Controller.IsPressed("P" + player + " Left")) { value &= 0xF7; } } } if (Region == "Japan") { value |= 0x40; } if (Type != NecSystemType.TurboCD && BramEnabled == false) { value |= 0x80; } return(value); }
public void GetControllerState(IController controller) { InputCallbacks.Call(); controller_state = _controllerDeck.ReadPort1(controller); }
private byte ReadKeyboard() { InputCallbacks.Call(); //ref TI-9X int ret = 0xFF; //Console.WriteLine("keyboardMask: {0:X2}",keyboardMask); if ((_keyboardMask & 1) == 0) { if (Controller.IsPressed("DOWN")) { ret ^= 1; } if (Controller.IsPressed("LEFT")) { ret ^= 2; } if (Controller.IsPressed("RIGHT")) { ret ^= 4; } if (Controller.IsPressed("UP")) { ret ^= 8; } } if ((_keyboardMask & 2) == 0) { if (Controller.IsPressed("ENTER")) { ret ^= 1; } if (Controller.IsPressed("PLUS")) { ret ^= 2; } if (Controller.IsPressed("MINUS")) { ret ^= 4; } if (Controller.IsPressed("MULTIPLY")) { ret ^= 8; } if (Controller.IsPressed("DIVIDE")) { ret ^= 16; } if (Controller.IsPressed("EXP")) { ret ^= 32; } if (Controller.IsPressed("CLEAR")) { ret ^= 64; } } if ((_keyboardMask & 4) == 0) { if (Controller.IsPressed("DASH")) { ret ^= 1; } if (Controller.IsPressed("3")) { ret ^= 2; } if (Controller.IsPressed("6")) { ret ^= 4; } if (Controller.IsPressed("9")) { ret ^= 8; } if (Controller.IsPressed("PARACLOSE")) { ret ^= 16; } if (Controller.IsPressed("TAN")) { ret ^= 32; } if (Controller.IsPressed("VARS")) { ret ^= 64; } } if ((_keyboardMask & 8) == 0) { if (Controller.IsPressed("DOT")) { ret ^= 1; } if (Controller.IsPressed("2")) { ret ^= 2; } if (Controller.IsPressed("5")) { ret ^= 4; } if (Controller.IsPressed("8")) { ret ^= 8; } if (Controller.IsPressed("PARAOPEN")) { ret ^= 16; } if (Controller.IsPressed("COS")) { ret ^= 32; } if (Controller.IsPressed("PRGM")) { ret ^= 64; } if (Controller.IsPressed("STAT")) { ret ^= 128; } } if ((_keyboardMask & 16) == 0) { if (Controller.IsPressed("0")) { ret ^= 1; } if (Controller.IsPressed("1")) { ret ^= 2; } if (Controller.IsPressed("4")) { ret ^= 4; } if (Controller.IsPressed("7")) { ret ^= 8; } if (Controller.IsPressed("COMMA")) { ret ^= 16; } if (Controller.IsPressed("SIN")) { ret ^= 32; } if (Controller.IsPressed("MATRIX")) { ret ^= 64; } if (Controller.IsPressed("X")) { ret ^= 128; } } if ((_keyboardMask & 32) == 0) { if (Controller.IsPressed("STO")) { ret ^= 2; } if (Controller.IsPressed("LN")) { ret ^= 4; } if (Controller.IsPressed("LOG")) { ret ^= 8; } if (Controller.IsPressed("SQUARED")) { ret ^= 16; } if (Controller.IsPressed("NEG1")) { ret ^= 32; } if (Controller.IsPressed("MATH")) { ret ^= 64; } if (Controller.IsPressed("ALPHA")) { ret ^= 128; } } if ((_keyboardMask & 64) == 0) { if (Controller.IsPressed("GRAPH")) { ret ^= 1; } if (Controller.IsPressed("TRACE")) { ret ^= 2; } if (Controller.IsPressed("ZOOM")) { ret ^= 4; } if (Controller.IsPressed("WINDOW")) { ret ^= 8; } if (Controller.IsPressed("Y")) { ret ^= 16; } if (Controller.IsPressed("2ND")) { ret ^= 32; } if (Controller.IsPressed("MODE")) { ret ^= 64; } if (Controller.IsPressed("DEL")) { ret ^= 128; } } return((byte)ret); }
// core callback for input void input_callback() { InputCallbacks.Call(); IsLagFrame = false; }
public void GetControllerState(IController controller) { InputCallbacks.Call(); controller_state_1 = _controllerDeck.ReadPort1(controller); controller_state_2 = _controllerDeck.ReadPort2(controller); kb_state_row = 8; // nothing pressed if (controller.IsPressed("0")) { kb_state_row = 0; kb_state_col = 7; } if (controller.IsPressed("1")) { kb_state_row = 0; kb_state_col = 6; } if (controller.IsPressed("2")) { kb_state_row = 0; kb_state_col = 5; } if (controller.IsPressed("3")) { kb_state_row = 0; kb_state_col = 4; } if (controller.IsPressed("4")) { kb_state_row = 0; kb_state_col = 3; } if (controller.IsPressed("5")) { kb_state_row = 0; kb_state_col = 2; } if (controller.IsPressed("6")) { kb_state_row = 0; kb_state_col = 1; } if (controller.IsPressed("7")) { kb_state_row = 0; kb_state_col = 0; } if (controller.IsPressed("8")) { kb_state_row = 1; kb_state_col = 7; } if (controller.IsPressed("9")) { kb_state_row = 1; kb_state_col = 6; } if (controller.IsPressed("SPC")) { kb_state_row = 1; kb_state_col = 3; } if (controller.IsPressed("?")) { kb_state_row = 1; kb_state_col = 2; } if (controller.IsPressed("L")) { kb_state_row = 1; kb_state_col = 1; } if (controller.IsPressed("P")) { kb_state_row = 1; kb_state_col = 0; } if (controller.IsPressed("+")) { kb_state_row = 2; kb_state_col = 7; } if (controller.IsPressed("W")) { kb_state_row = 2; kb_state_col = 6; } if (controller.IsPressed("E")) { kb_state_row = 2; kb_state_col = 5; } if (controller.IsPressed("R")) { kb_state_row = 2; kb_state_col = 4; } if (controller.IsPressed("T")) { kb_state_row = 2; kb_state_col = 3; } if (controller.IsPressed("U")) { kb_state_row = 2; kb_state_col = 2; } if (controller.IsPressed("I")) { kb_state_row = 2; kb_state_col = 1; } if (controller.IsPressed("O")) { kb_state_row = 2; kb_state_col = 0; } if (controller.IsPressed("Q")) { kb_state_row = 3; kb_state_col = 7; } if (controller.IsPressed("S")) { kb_state_row = 3; kb_state_col = 6; } if (controller.IsPressed("D")) { kb_state_row = 3; kb_state_col = 5; } if (controller.IsPressed("F")) { kb_state_row = 3; kb_state_col = 4; } if (controller.IsPressed("G")) { kb_state_row = 3; kb_state_col = 3; } if (controller.IsPressed("H")) { kb_state_row = 3; kb_state_col = 2; } if (controller.IsPressed("J")) { kb_state_row = 3; kb_state_col = 1; } if (controller.IsPressed("K")) { kb_state_row = 3; kb_state_col = 0; } if (controller.IsPressed("A")) { kb_state_row = 4; kb_state_col = 7; } if (controller.IsPressed("Z")) { kb_state_row = 4; kb_state_col = 6; } if (controller.IsPressed("X")) { kb_state_row = 4; kb_state_col = 5; } if (controller.IsPressed("C")) { kb_state_row = 4; kb_state_col = 4; } if (controller.IsPressed("V")) { kb_state_row = 4; kb_state_col = 3; } if (controller.IsPressed("B")) { kb_state_row = 4; kb_state_col = 2; } if (controller.IsPressed("M")) { kb_state_row = 4; kb_state_col = 1; } if (controller.IsPressed(".")) { kb_state_row = 4; kb_state_col = 0; } if (controller.IsPressed("-")) { kb_state_row = 5; kb_state_col = 7; } if (controller.IsPressed("*")) { kb_state_row = 5; kb_state_col = 6; } if (controller.IsPressed("/")) { kb_state_row = 5; kb_state_col = 5; } if (controller.IsPressed("=")) { kb_state_row = 5; kb_state_col = 4; } if (controller.IsPressed("YES")) { kb_state_row = 5; kb_state_col = 3; } if (controller.IsPressed("NO")) { kb_state_row = 5; kb_state_col = 2; } if (controller.IsPressed("CLR")) { kb_state_row = 5; kb_state_col = 1; } if (controller.IsPressed("ENT")) { kb_state_row = 5; kb_state_col = 0; } }
private void snes_controller_latch() { InputCallbacks.Call(); }