File indexing completed on 2024-05-19 09:39:05
0001 /*************************************************************************** 0002 * Copyright (C) 2005 by David Saxton * 0003 * david@bluehaze.org * 0004 * * 0005 * This program is free software; you can redistribute it and/or modify * 0006 * it under the terms of the GNU General Public License as published by * 0007 * the Free Software Foundation; either version 2 of the License, or * 0008 * (at your option) any later version. * 0009 ***************************************************************************/ 0010 0011 #ifndef FLIPFLOP_H 0012 #define FLIPFLOP_H 0013 0014 #include "component.h" 0015 #include "logic.h" 0016 0017 class Simulator; 0018 0019 class ClockedFlipFlop : public CallbackClass, public Component 0020 { 0021 public: 0022 ClockedFlipFlop(ICNDocument *icnDocument, bool newItem, const char *id); 0023 0024 protected: 0025 enum EdgeTrigger { Rising, Falling }; 0026 void dataChanged() override; 0027 virtual void initSymbolFromTrigger() = 0; 0028 EdgeTrigger m_edgeTrigger; 0029 }; 0030 0031 /** 0032 @short Boolean D-Type Flip-Flop 0033 @author David Saxton 0034 */ 0035 class ECDFlipFlop : public ClockedFlipFlop 0036 { 0037 public: 0038 ECDFlipFlop(ICNDocument *icnDocument, bool newItem, const char *id = nullptr); 0039 ~ECDFlipFlop() override; 0040 0041 static Item *construct(ItemDocument *itemDocument, bool newItem, const char *id); 0042 static LibraryItem *libraryItem(); 0043 0044 protected: 0045 void drawShape(QPainter &p) override; 0046 void initSymbolFromTrigger() override; 0047 public: // internal interfaces 0048 void inputChanged(bool newState); 0049 void inStateChanged(bool newState); 0050 void asyncChanged(bool newState); 0051 void clockChanged(bool newState); 0052 0053 protected: 0054 LogicIn *m_pD; 0055 LogicIn *m_pClock; 0056 LogicOut *m_pQ; 0057 LogicOut *m_pQBar; 0058 LogicIn *setp; 0059 LogicIn *rstp; 0060 bool m_bPrevClock; 0061 0062 bool m_prevD; 0063 unsigned long long m_prevDChangeSimTime; 0064 Simulator *m_pSimulator; 0065 }; 0066 0067 /** 0068 @short Boolean JK-Type Flip-Flop 0069 @author Couriousous 0070 */ 0071 class ECJKFlipFlop : public ClockedFlipFlop 0072 { 0073 public: 0074 ECJKFlipFlop(ICNDocument *icnDocument, bool newItem, const char *id = nullptr); 0075 ~ECJKFlipFlop() override; 0076 0077 static Item *construct(ItemDocument *itemDocument, bool newItem, const char *id); 0078 static LibraryItem *libraryItem(); 0079 0080 private: 0081 void drawShape(QPainter &p) override; 0082 void initSymbolFromTrigger() override; 0083 void inStateChanged(bool newState); 0084 public: // internal interfaces 0085 void asyncChanged(bool newState); 0086 void clockChanged(bool newState); 0087 protected: 0088 bool prev_state; 0089 bool m_bPrevClock; 0090 LogicIn *m_pJ; 0091 LogicIn *m_pClock; 0092 LogicIn *m_pK; 0093 LogicIn *setp; 0094 LogicIn *rstp; 0095 LogicOut *m_pQ; 0096 LogicOut *m_pQBar; 0097 }; 0098 0099 /** 0100 @short Boolean Set-Reset Flip-Flop 0101 @author David Saxton 0102 */ 0103 class ECSRFlipFlop : public CallbackClass, public Component 0104 { 0105 public: 0106 ECSRFlipFlop(ICNDocument *icnDocument, bool newItem, const char *id = nullptr); 0107 ~ECSRFlipFlop() override; 0108 0109 static Item *construct(ItemDocument *itemDocument, bool newItem, const char *id); 0110 static LibraryItem *libraryItem(); 0111 0112 public: // internal interfaces 0113 void inStateChanged(bool newState); 0114 protected: 0115 LogicIn *m_pS; 0116 LogicIn *m_pR; 0117 LogicOut *m_pQ; 0118 LogicOut *m_pQBar; 0119 bool old_q1; 0120 bool old_q2; 0121 }; 0122 0123 #endif