From 2bd5074828efac1c9882491706ed4dbf498ad227 Mon Sep 17 00:00:00 2001 From: Christian Speckner Date: Sat, 26 Nov 2016 00:08:32 +0100 Subject: [PATCH] Add latched input. --- src/emucore/tia/core_6502ts/LatchedInput.cxx | 60 ++++++++++++++++++++ src/emucore/tia/core_6502ts/LatchedInput.hxx | 57 +++++++++++++++++++ src/emucore/tia/core_6502ts/TIA.cxx | 11 +++- src/emucore/tia/core_6502ts/TIA.hxx | 4 ++ src/emucore/tia/core_6502ts/module.mk | 4 +- 5 files changed, 133 insertions(+), 3 deletions(-) create mode 100644 src/emucore/tia/core_6502ts/LatchedInput.cxx create mode 100644 src/emucore/tia/core_6502ts/LatchedInput.hxx diff --git a/src/emucore/tia/core_6502ts/LatchedInput.cxx b/src/emucore/tia/core_6502ts/LatchedInput.cxx new file mode 100644 index 000000000..1a294e35a --- /dev/null +++ b/src/emucore/tia/core_6502ts/LatchedInput.cxx @@ -0,0 +1,60 @@ +//============================================================================ +// +// SSSS tt lll lll +// SS SS tt ll ll +// SS tttttt eeee ll ll aaaa +// SSSS tt ee ee ll ll aa +// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" +// SS SS tt ee ll ll aa aa +// SSSS ttt eeeee llll llll aaaaa +// +// Copyright (c) 1995-2016 by Bradford W. Mott, Stephen Anthony +// and the Stella Team +// +// See the file "License.txt" for information on usage and redistribution of +// this file, and for a DISCLAIMER OF ALL WARRANTIES. +// +// $Id$ +//============================================================================ + +#include "LatchedInput.hxx" + +namespace TIA6502tsCore { + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +LatchedInput::LatchedInput() +{ + reset(); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void LatchedInput::reset() +{ + myModeLatched = false; + myLatchedValue = 0; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void LatchedInput::vblank(uInt8 value) +{ + if (value & 0x40) myModeLatched = true; + else { + myModeLatched = false; + myLatchedValue = 0x80; + } +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +uInt8 LatchedInput::inpt(bool pinState) +{ + uInt8 value = pinState ? 0 : 0x80; + + if (myModeLatched) { + myLatchedValue &= value; + value = myLatchedValue; + } + + return value; +} + +} // namespace TIA6502tsCore { \ No newline at end of file diff --git a/src/emucore/tia/core_6502ts/LatchedInput.hxx b/src/emucore/tia/core_6502ts/LatchedInput.hxx new file mode 100644 index 000000000..896c5523c --- /dev/null +++ b/src/emucore/tia/core_6502ts/LatchedInput.hxx @@ -0,0 +1,57 @@ +//============================================================================ +// +// SSSS tt lll lll +// SS SS tt ll ll +// SS tttttt eeee ll ll aaaa +// SSSS tt ee ee ll ll aa +// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" +// SS SS tt ee ll ll aa aa +// SSSS ttt eeeee llll llll aaaaa +// +// Copyright (c) 1995-2016 by Bradford W. Mott, Stephen Anthony +// and the Stella Team +// +// See the file "License.txt" for information on usage and redistribution of +// this file, and for a DISCLAIMER OF ALL WARRANTIES. +// +// $Id$ +//============================================================================ + +#ifndef TIA_6502TS_CORE_LATCHED_INPUT +#define TIA_6502TS_CORE_LATCHED_INPUT + +#include "bspf.hxx" + +namespace TIA6502tsCore { + +class LatchedInput +{ + public: + + LatchedInput(); + + public: + + void reset(); + + void vblank(uInt8 value); + + uInt8 inpt(bool pinState); + + private: + + bool myModeLatched; + + uInt8 myLatchedValue; + + private: + + LatchedInput(const LatchedInput&) = delete; + LatchedInput(LatchedInput&&) = delete; + LatchedInput& operator=(const LatchedInput&) = delete; + LatchedInput& operator=(LatchedInput&&) = delete; +}; + +} // namespace TIA6502tsCore + +#endif // TIA_6502TS_CORE_LATCHED_INPUT \ No newline at end of file diff --git a/src/emucore/tia/core_6502ts/TIA.cxx b/src/emucore/tia/core_6502ts/TIA.cxx index abf671082..b5d5ee529 100644 --- a/src/emucore/tia/core_6502ts/TIA.cxx +++ b/src/emucore/tia/core_6502ts/TIA.cxx @@ -105,6 +105,9 @@ void TIA::reset() myPlayer1.reset(); myBall.reset(); + myInput0.reset(); + myInput1.reset(); + mySound.reset(); myDelayQueue.reset(); myFrameManager.reset(); @@ -265,11 +268,11 @@ uInt8 TIA::peek(uInt16 address) break; case INPT4: - result = myConsole.leftController().read(Controller::Six) ? 0x80 : 0x00; + result = myInput0.inpt(!myConsole.leftController().read(Controller::Six)); break; case INPT5: - result = myConsole.rightController().read(Controller::Six) ? 0x80 : 0x00; + result = myInput0.inpt(!myConsole.rightController().read(Controller::Six)); break; default: @@ -300,6 +303,10 @@ bool TIA::poke(uInt16 address, uInt8 value) case VBLANK: myLinesSinceChange = 0; + + myInput0.vblank(value); + myInput1.vblank(value); + myFrameManager.setVblank(value & 0x02); break; diff --git a/src/emucore/tia/core_6502ts/TIA.hxx b/src/emucore/tia/core_6502ts/TIA.hxx index ae19b54d9..5c3441f4c 100644 --- a/src/emucore/tia/core_6502ts/TIA.hxx +++ b/src/emucore/tia/core_6502ts/TIA.hxx @@ -31,6 +31,7 @@ #include "Missile.hxx" #include "Player.hxx" #include "Ball.hxx" +#include "LatchedInput.hxx" class Console; @@ -218,6 +219,9 @@ class TIA : public AbstractTIA Player myPlayer1; Ball myBall; + LatchedInput myInput0; + LatchedInput myInput1; + private: TIA() = delete; TIA(const TIA&) = delete; diff --git a/src/emucore/tia/core_6502ts/module.mk b/src/emucore/tia/core_6502ts/module.mk index 46f04145b..4e37e06a7 100644 --- a/src/emucore/tia/core_6502ts/module.mk +++ b/src/emucore/tia/core_6502ts/module.mk @@ -9,7 +9,9 @@ MODULE_OBJS := \ src/emucore/tia/core_6502ts/DrawCounterDecodes.o \ src/emucore/tia/core_6502ts/Missile.o \ src/emucore/tia/core_6502ts/Player.o \ - src/emucore/tia/core_6502ts/Ball.o + src/emucore/tia/core_6502ts/Ball.o \ + src/emucore/tia/core_6502ts/LatchedInput.o + MODULE_DIRS += \ src/emucore/tia/core_6502ts