File indexing completed on 2024-05-05 05:46:04

0001 /***************************************************************************
0002  *   Copyright (C) 2003-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 ECCLOCKINPUT_H
0012 #define ECCLOCKINPUT_H
0013 
0014 #include <list>
0015 
0016 #include "component.h"
0017 
0018 class ComponentCallback;
0019 class Simulator;
0020 
0021 template<typename T> class LinkedList;
0022 
0023 /**
0024 @short Boolean clock input
0025 @author David Saxton
0026 */
0027 class ECClockInput : public Component
0028 {
0029 public:
0030     ECClockInput(ICNDocument *icnDocument, bool newItem, const char *id = nullptr);
0031     ~ECClockInput() override;
0032 
0033     static Item *construct(ItemDocument *itemDocument, bool newItem, const char *id);
0034     static LibraryItem *libraryItem();
0035 
0036     /** callback for logic steps, for each logic update step;
0037      only active when the period of the clock is less or equal than LOGIC_UPDATE_PER_STEP */
0038     void stepCallback();
0039     /** callback for linear steps, for each linear update step;
0040      only active when the period of the clock is greater than LOGIC_UPDATE_PER_STEP */
0041     void stepLogic();
0042     /** callback at linear steps; always active */
0043     void stepNonLogic() override;
0044     bool doesStepNonLogic() const override
0045     {
0046         return true;
0047     }
0048 
0049 protected:
0050     void drawShape(QPainter &p) override;
0051     void dataChanged() override;
0052 
0053     uint m_time;
0054     /** unit: simulator logic update tick == 1s / LOGIC_UPDATE_RATE */
0055     uint m_high_time;
0056     /** unit: simulator logic update tick == 1s / LOGIC_UPDATE_RATE */
0057     uint m_low_time;
0058     /** unit: simulator logic update tick == 1s / LOGIC_UPDATE_RATE */
0059     uint m_period;
0060     /** unit: simulator logic update tick == 1s / LOGIC_UPDATE_RATE */
0061     long long m_lastSetTime;
0062     LogicOut *m_pOut;
0063     bool m_bSetStepCallbacks;
0064     bool m_bLastStepCallbackOut;
0065     Simulator *m_pSimulator;
0066     std::list<ComponentCallback> *m_pComponentCallback[100 /* == LOGIC_UPDATE_PER_STEP */];
0067 };
0068 
0069 #endif