File indexing completed on 2024-12-01 11:20:32

0001 /***************************************************************************
0002  *   Copyright (C) 2003 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 #include "writeport.h"
0012 
0013 #include "flowcode.h"
0014 #include "libraryitem.h"
0015 #include "icndocument.h"
0016 
0017 #include <KLocalizedString>
0018 
0019 Item *WritePort::construct(ItemDocument *itemDocument, bool newItem, const char *id)
0020 {
0021     return new WritePort(static_cast<ICNDocument *>(itemDocument), newItem, id);
0022 }
0023 
0024 LibraryItem *WritePort::libraryItem()
0025 {
0026     return new LibraryItem(QStringList(QString("flow/writeport")), i18n("Write to Port"), i18n("I\\/O"), "portwrite.png", LibraryItem::lit_flowpart, WritePort::construct);
0027 }
0028 
0029 WritePort::WritePort(ICNDocument *icnDocument, bool newItem, const char *id)
0030     : FlowPart(icnDocument, newItem, id ? id : "writeport")
0031 {
0032     m_name = i18n("Write to Port");
0033     initIOSymbol();
0034     createStdInput();
0035     createStdOutput();
0036 
0037     createProperty("0-var", Variant::Type::Combo);
0038     property("0-var")->setToolbarCaption(i18n("Write"));
0039     property("0-var")->setEditorCaption(i18n("Variable"));
0040     property("0-var")->setValue("x");
0041 
0042     createProperty("1-port", Variant::Type::Port);
0043     property("1-port")->setToolbarCaption(i18nc("write to port", "to"));
0044     property("1-port")->setEditorCaption(i18n("Port"));
0045     property("1-port")->setValue("PORTA");
0046 }
0047 
0048 WritePort::~WritePort()
0049 {
0050 }
0051 
0052 void WritePort::dataChanged()
0053 {
0054     setCaption(i18n("Write %1 to %2", dataString("0-var"), dataString("1-port")));
0055 }
0056 
0057 void WritePort::generateMicrobe(FlowCode *code)
0058 {
0059     code->addCode(dataString("1-port") + " = " + dataString("0-var"));
0060     code->addCodeBranch(outputPart("stdoutput"));
0061 
0062 #if 0
0063     QString var = dataString("var");
0064     QString port = dataString("port");
0065     
0066     // WTF? I don't want to do this!
0067 //  QString newCode = "bsf STATUS,5 ; Move to bank 1\n";
0068     QString newCode;
0069     
0070     if ( FlowCode::isLiteral(var) ) newCode += "movlw " + var + " ; Move " + var + " to working register w\n";
0071     else
0072     {
0073         code->addVariable(var);
0074         newCode += "movf " + var + ",0 ; Move " + var + " to working register w\n";
0075     }
0076     
0077     newCode += "movwf " + port + " ; Move register w to port\n";
0078     
0079     // Same for below as for above
0080 //  newCode += "bcf STATUS,5 ; Come back to bank 0\n";
0081     
0082     newCode += gotoCode("stdoutput") + "\n";
0083     
0084     code->addCodeBlock( id(), newCode );
0085 #endif
0086 }