Ejemplo n.º 1
0
void Demultiplexer::initPins(unsigned newAddressSize) {
	unsigned oldAddressSize = m_aLogic.size();
	unsigned long long oldXLogicCount = m_xLogic.size();
	unsigned long long newXLogicCount = 1 << newAddressSize;

	if (newXLogicCount == oldXLogicCount)
		return;

	QStringList pins;

	for (unsigned i = 0; i < newAddressSize; ++i)
		pins += "A" + QString::number(i);

	for (unsigned i = newAddressSize; i < (newXLogicCount + (newXLogicCount % 2)) / 2; ++i)
		pins += "";

	pins += "X";

	for (unsigned i = (newXLogicCount + (newXLogicCount % 2)) / 2 + 1; i < newXLogicCount; ++i)
		pins += "";

	for (int i = newXLogicCount - 1; i >= 0; --i)
		pins += "X" + QString::number(i);

	initDIPSymbol(pins, 64);
	initDIP(pins);

	setup1pinElement(m_input, ecNodeWithID("X")->pin());

	if (newXLogicCount > oldXLogicCount) {
		m_xLogic.resize(newXLogicCount);
		for (unsigned i = oldXLogicCount; i < newXLogicCount; ++i) {
			setup1pinElement(m_xLogic[i], ecNodeWithID("X" + QString::number(i))->pin());
		}

		m_aLogic.resize(newAddressSize);
		for (unsigned i = oldAddressSize; i < newAddressSize; ++i) {
			setup1pinElement(m_aLogic[i], ecNodeWithID("A" + QString::number(i))->pin());
			m_aLogic[i].setCallback(this, (CallbackPtr)(&Demultiplexer::inStateChanged));
		}
	} else {
		for (unsigned i = newXLogicCount; i < oldXLogicCount; ++i) {
			QString id = "X" + QString::number(i);
			removeDisplayText(id);
			removeElement(&m_xLogic[i], false);
			removeNode(id);
		}

		m_xLogic.resize(newXLogicCount);

		for (unsigned i = newAddressSize; i < oldAddressSize; ++i) {
			QString id = "A" + QString::number(i);
			removeDisplayText(id);
			removeElement(&m_aLogic[i], false);
			removeNode(id);
		}

		m_aLogic.resize(newAddressSize);
	}
}
Ejemplo n.º 2
0
void MultiInputGate::updateSymbolText() {
	if (m_logicSymbolShape == Distinctive)
		removeDisplayText("rect-shape-text");
	else {
		int w = 32 - (m_bInvertedOutput ? 6 : 0);
		QRect r(-16, 4 - height() / 2, w, height() - 4);
		addDisplayText("rect-shape-text", r, m_rectangularShapeText, true, AlignTop | AlignHCenter);
	}
}
Ejemplo n.º 3
0
void BinaryCounter::initPins( unsigned numBits )
{
	if ( m_numBits == numBits )
		return;
	
	QStringList pins;
	pins << "en" << ">" << "u/d" << "r";

	{
	int np = abs(4-int(numBits));
	for ( int i = 0; i < np; i++ )
		pins << " ";
	}
	
	for ( int i = numBits-1; i >= 0; i-- )
		pins << QChar('A'+i);
	
	initDIPSymbol( pins, 64 );
	initDIP(pins);
	
	if ( m_numBits < numBits )
	{
		for ( unsigned i = m_numBits; i < numBits; i++ )
			m_pLogicOut[i] = createLogicOut( ecNodeWithID( QChar('A'+i) ), false );
	}
	else
	{
		for ( unsigned i = numBits; i < m_numBits; i++ )
		{
			QString id = QChar('A'+i);
			removeElement( m_pLogicOut[i], false );
			removeDisplayText(id);
			removeNode(id);
		}
	}
	
	m_numBits = numBits;
	m_maxValue = (1<<m_numBits)-1;
	
	if (!m_bDoneLogicIn)
	{
		enLogic = createLogicIn( ecNodeWithID("en") );
		inLogic = createLogicIn( ecNodeWithID(">") );
		rLogic = createLogicIn( ecNodeWithID("r") );
		udLogic = createLogicIn( ecNodeWithID("u/d") );
	
		enLogic->setCallback( this, (CallbackPtr)(&BinaryCounter::enStateChanged) );
		inLogic->setCallback( this, (CallbackPtr)(&BinaryCounter::inStateChanged) );
		rLogic->setCallback( this, (CallbackPtr)(&BinaryCounter::rStateChanged) );
		udLogic->setCallback( this, (CallbackPtr)(&BinaryCounter::udStateChanged) );
		
		m_bDoneLogicIn = true;
	}
	
	outputValue();
}
Ejemplo n.º 4
0
void PIC_IC::initPackage( MicroInfo * microInfo )
{
	// The code in this function is a stripped down version of that in PICComponent::initPackage
	
	if (!microInfo)
		return;
	
	MicroPackage * microPackage = microInfo->package();
	if (!microPackage)
		return;
	
	//BEGIN Get pin IDs
	QStringList allPinIDs = microPackage->pinIDs();
	QStringList ioPinIDs = microPackage->pinIDs( PicPin::type_bidir | PicPin::type_input | PicPin::type_open );
	
	// Now, we make the unwanted pin ids blank, so a pin is not created for them
	const QStringList::iterator allPinIDsEnd = allPinIDs.end();
	for ( QStringList::iterator it = allPinIDs.begin(); it != allPinIDsEnd; ++it )
	{
		if ( !ioPinIDs.contains(*it) )
			*it = "";
	}
	//END Get pin IDs
	
	
	//BEGIN Remove old stuff
	// Remove old text
	TextMap textMapCopy = m_textMap;
	const TextMap::iterator textMapEnd = textMapCopy.end();
	for ( TextMap::iterator it = textMapCopy.begin(); it != textMapEnd; ++it )
		removeDisplayText(it.key());
	
	// Remove old nodes
	NodeInfoMap nodeMapCopy = m_nodeMap;
	const NodeInfoMap::iterator nodeMapEnd = nodeMapCopy.end();
	for ( NodeInfoMap::iterator it = nodeMapCopy.begin(); it != nodeMapEnd; ++it )
	{
		if ( !ioPinIDs.contains(it.key()) )
			removeNode( it.key() );
	}
	//END Remove old stuff
	
	
	
	//BEGIN Create new stuff
	initDIPSymbol( allPinIDs, 80 );
	initDIP(allPinIDs);
	//END Create new stuff
	
	
	addDisplayText( "picid", QRect(offsetX(), offsetY()-16, width(), 16), microInfo->id() );
}
Ejemplo n.º 5
0
void RAM::initPins()
{
	int oldWordSize = m_dataIn.size();
	int oldAddressSize = m_address.size();
	
	int newWordSize = dataInt("wordSize");
	int newAddressSize = dataInt("addressSize");
	
	if ( newAddressSize == oldAddressSize &&
			newWordSize == oldWordSize )
		return;
	
	QStringList leftPins; // Pins on left of IC
	leftPins << "CS" << "OE" << "WE";
	for ( int i = 0; i < newAddressSize; ++i )
		leftPins << QString("A%1").arg( QString::number(i) );
	
	QStringList rightPins; // Pins on right of IC
	for ( unsigned i = newWordSize; i > 0; --i )
		rightPins << QString("DI%1").arg( QString::number(i-1) );
	for ( unsigned i = newWordSize; i > 0; --i )
		rightPins << QString("DO%1").arg( QString::number(i-1) );
	
	// Make pin lists of consistent sizes
	for ( unsigned i = leftPins.size(); i < rightPins.size(); ++i )
		leftPins.append("");
	for ( unsigned i = rightPins.size(); i < leftPins.size(); ++i )
		rightPins.prepend("");
	
	QStringList pins = leftPins + rightPins;
	
	initDIPSymbol( pins, 72 );
	initDIP(pins);
	
	ECNode *node;
	
	if (!m_pCS)
	{
		node =  ecNodeWithID("CS");
		m_pCS = createLogicIn(node);
		m_pCS->setCallback( this, (CallbackPtr)(&RAM::inStateChanged) );
	}
	
	if (!m_pOE)
	{
		node =  ecNodeWithID("OE");
		m_pOE = createLogicIn(node);
		m_pOE->setCallback( this, (CallbackPtr)(&RAM::inStateChanged) );
	}
	
	if (!m_pWE)
	{
		node =  ecNodeWithID("WE");
		m_pWE = createLogicIn(node);
		m_pWE->setCallback( this, (CallbackPtr)(&RAM::inStateChanged) );
	}
	
	if ( newWordSize > oldWordSize )
	{
		m_dataIn.resize(newWordSize);
		m_dataOut.resize(newWordSize);
		
		for ( int i = oldWordSize; i < newWordSize; ++i )
		{
			node = ecNodeWithID( QString("DI%1").arg( QString::number(i) ) );
			m_dataIn.insert( i, createLogicIn(node) );
			m_dataIn[i]->setCallback( this, (CallbackPtr)(&RAM::inStateChanged) ); 
			
			node = ecNodeWithID( QString("DO%1").arg( QString::number(i) ) );
			m_dataOut.insert( i, createLogicOut(node, false) );
		}
	}
	else if ( newWordSize < oldWordSize )
	{
		for ( int i = newWordSize; i < oldWordSize; ++i )
		{
			QString id = QString("DO%1").arg( QString::number(i) );
			removeDisplayText(id);
			removeElement( m_dataIn[i], false );
			removeNode(id);
			
			id = QString("DI%1").arg( QString::number(i) );
			removeDisplayText(id);
			removeElement( m_dataOut[i], false );
			removeNode(id);
		}
		
		m_dataIn.resize(newWordSize);
		m_dataOut.resize(newWordSize);
	}
	
	if ( newAddressSize > oldAddressSize )
	{
		m_address.resize(newAddressSize);
		
		for ( int i = oldAddressSize; i < newAddressSize; ++i )
		{
			node = ecNodeWithID( QString("A%1").arg( QString::number(i) ) );
			m_address.insert( i, createLogicIn(node) );
			m_address[i]->setCallback( this, (CallbackPtr)(&RAM::inStateChanged) );
		}
	}
	else if ( newAddressSize < oldAddressSize )
	{
		for ( int i = newAddressSize; i < oldAddressSize; ++i )
		{
			QString id = QString("A%1").arg( QString::number(i) );
			removeDisplayText(id);
			removeElement( m_address[i], false );
			removeNode(id);
		}
		
		m_address.resize(newAddressSize);
	}
}
Ejemplo n.º 6
0
void PICComponent::initPackage( MicroInfo * microInfo )
{
	MicroPackage * microPackage = microInfo ? microInfo->package() : 0l;
	
	if ( microPackage )
	{
		m_bCreatedInitialPackage = true;
		
		//BEGIN Get pin IDs
		QStringList allPinIDs = microPackage->pinIDs();
		QStringList ioPinIDs = microPackage->pinIDs( PicPin::type_bidir | PicPin::type_input | PicPin::type_open );
	
		// Now, we make the unwanted pin ids blank, so a pin is not created for them
		const QStringList::iterator allPinIDsEnd = allPinIDs.end();
		for ( QStringList::iterator it = allPinIDs.begin(); it != allPinIDsEnd; ++it )
		{
			if ( !ioPinIDs.contains(*it) )
				*it = "";
		}
		//END Get pin IDs
	
	
		//BEGIN Remove old stuff
		// Remove old text
		TextMap textMapCopy = m_textMap;
		const TextMap::iterator textMapEnd = textMapCopy.end();
		for ( TextMap::iterator it = textMapCopy.begin(); it != textMapEnd; ++it )
			removeDisplayText(it.key());
	
		// Remove the old pins
		deletePICComponentPins();
	
		// Remove old nodes
		NodeInfoMap nodeMapCopy = m_nodeMap;
		const NodeInfoMap::iterator nodeMapEnd = nodeMapCopy.end();
		for ( NodeInfoMap::iterator it = nodeMapCopy.begin(); it != nodeMapEnd; ++it )
		{
			if ( !ioPinIDs.contains(it.key()) )
				removeNode( it.key() );
		}
	
		removeElements();
		//END Remove old stuff
	
	
	
		//BEGIN Create new stuff
		initDIPSymbol( allPinIDs, 80 );
		initDIP(allPinIDs);
	
		PicPinMap picPinMap = microPackage->pins( PicPin::type_bidir | PicPin::type_input | PicPin::type_open );
		const PicPinMap::iterator picPinMapEnd = picPinMap.end();
		for ( PicPinMap::iterator it = picPinMap.begin(); it != picPinMapEnd; ++it )
			m_picComponentPinMap[it.key()] = new PICComponentPin( this, it.value() );
		//END Create new stuff
	
	
		removeDisplayText( "no_file" );
		addDisplayText( "picid", QRect(offsetX(), offsetY()-16, width(), 16), microInfo->id() );
	}
	else
	{
		setSize( -48, -72, 96, 144 );
		removeDisplayText( "picid" );
		addDisplayText( "no_file", sizeRect(), i18n("(No\nprogram\nloaded)") );
	}
	
	
	//BEGIN Update button positions
	int leftpos = (width()-88)/2+offsetX();
	button("run")->setOriginalRect( QRect( leftpos, height()+4+offsetY(), 20, 20 ) );
	button("pause")->setOriginalRect( QRect( leftpos+23, height()+4+offsetY(), 20, 20 ) );
	button("reset")->setOriginalRect( QRect( leftpos+46, height()+4+offsetY(), 20, 20 ) );
	button("reload")->setOriginalRect( QRect( leftpos+69, height()+4+offsetY(), 20, 20 ) );
	updateAttachedPositioning();
	//END Update button positions
}
Ejemplo n.º 7
0
void Multiplexer::initPins(unsigned newAddressSize) {
	unsigned oldAddressSize = m_aLogic.size();
	unsigned long long oldXLogicCount = m_xLogic.size();
	unsigned long long newXLogicCount = 1 << newAddressSize;

	if (newXLogicCount == oldXLogicCount) return;

	QStringList pins;

	const int length = newAddressSize + newXLogicCount;

	for (unsigned i = 0; i < newAddressSize; ++i)
		pins += "A" + QString::number(i);

	for (unsigned i = 0; i < newXLogicCount; ++i)
		pins += "X" + QString::number(i);

// WTF??
	for (int i = 0; i < (length - (length % 2)) / 2; ++i)
		pins += "";

	pins += "X";

// WTF???
	for (int i = 0; i < ((length + (length % 2)) / 2) - 1; ++i)
		pins += "";

	initDIPSymbol(pins, 64);
	initDIP(pins);

	setup1pinElement(m_output, ecNodeWithID("X")->pin());

	if (newXLogicCount > oldXLogicCount) {
		m_xLogic.resize(newXLogicCount);

		for (unsigned i = oldXLogicCount; i < newXLogicCount; ++i) {
			setup1pinElement(m_xLogic[i], ecNodeWithID("X" + QString::number(i))->pin());
			m_xLogic[i].setCallback(this, (CallbackPtr)(&Multiplexer::inStateChanged));
		}

		m_aLogic.resize(newAddressSize);

		for (unsigned i = oldAddressSize; i < newAddressSize; ++i) {
			setup1pinElement(m_aLogic[i], ecNodeWithID("A" + QString::number(i))->pin());
			m_aLogic[i].setCallback(this, (CallbackPtr)(&Multiplexer::inStateChanged));
		}
	} else {
		for (unsigned i = newXLogicCount; i < oldXLogicCount; ++i) {
			QString id = "X" + QString::number(i);
			removeDisplayText(id);
			removeElement(&(m_xLogic[i]), false);
			removeNode(id);
		}

		m_xLogic.resize(newXLogicCount);

		for (unsigned i = newAddressSize; i < oldAddressSize; ++i) {
			QString id = "A" + QString::number(i);
			removeDisplayText(id);
			removeElement(&(m_aLogic[i]), false);
			removeNode(id);
		}

		m_aLogic.resize(newAddressSize);
	}
}