summaryrefslogtreecommitdiffstats
path: root/src/electronics/components/fulladder.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/electronics/components/fulladder.cpp')
-rw-r--r--src/electronics/components/fulladder.cpp91
1 files changed, 91 insertions, 0 deletions
diff --git a/src/electronics/components/fulladder.cpp b/src/electronics/components/fulladder.cpp
new file mode 100644
index 0000000..ad5e40c
--- /dev/null
+++ b/src/electronics/components/fulladder.cpp
@@ -0,0 +1,91 @@
+/***************************************************************************
+ * Copyright (C) 2004 by David Saxton *
+ * david@bluehaze.org *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ ***************************************************************************/
+
+#include "fulladder.h"
+
+#include "logic.h"
+#include "libraryitem.h"
+
+#include <kiconloader.h>
+#include <klocale.h>
+
+
+Item* FullAdder::construct( ItemDocument *itemDocument, bool newItem, const char *id )
+{
+ return new FullAdder( (ICNDocument*)itemDocument, newItem, id );
+}
+
+LibraryItem* FullAdder::libraryItem()
+{
+ return new LibraryItem(
+ QString("ec/adder"),
+ i18n("Adder"),
+ i18n("Integrated Circuits"),
+ "ic1.png",
+ LibraryItem::lit_component,
+ FullAdder::construct
+ );
+}
+
+FullAdder::FullAdder( ICNDocument *icnDocument, bool newItem, const char *id )
+ : Component( icnDocument, newItem, (id) ? id : "adder" )
+{
+ m_name = i18n("Adder");
+// m_desc = i18n("Insert missing adder help here.");
+
+ ALogic = BLogic = inLogic = 0l;
+ outLogic = SLogic = 0l;
+
+ QStringList pins = QStringList::split( ',', "A,B,>,,S,C", true );
+ initDIPSymbol( pins, 48 );
+ initDIP(pins);
+
+ ECNode *node;
+
+ node = ecNodeWithID("S");
+ SLogic = createLogicOut( node, false );
+
+ node = ecNodeWithID("C");
+ outLogic = createLogicOut( node, false );
+
+ node = ecNodeWithID("A");
+ ALogic = createLogicIn(node);
+
+ node = ecNodeWithID("B");
+ BLogic = createLogicIn(node);
+
+ node = ecNodeWithID(">");
+ inLogic = createLogicIn(node);
+
+
+ ALogic->setCallback( this, (CallbackPtr)(&FullAdder::inStateChanged) );
+ BLogic->setCallback( this, (CallbackPtr)(&FullAdder::inStateChanged) );
+ inLogic->setCallback( this, (CallbackPtr)(&FullAdder::inStateChanged) );
+}
+
+FullAdder::~FullAdder()
+{
+}
+
+
+void FullAdder::inStateChanged( bool /*state*/ )
+{
+ const bool A = ALogic->isHigh();
+ const bool B = BLogic->isHigh();
+ const bool in = inLogic->isHigh();
+
+ const bool out = (!A && B && in) || (A && !B && in) || (A && B);
+ const bool S = (!A && !B && in) || (!A && B && !in) || (A && !B && !in) || (A && B && in);
+
+ SLogic->setHigh(S);
+ outLogic->setHigh(out);
+}
+
+