コード例 #1
0
ファイル: uart.cpp プロジェクト: TheProjecter/pockemul
Cuart::BIT_TYPE Cuart::sendBit(void)
{

    if (oldstate_in	== 0) oldstate_in = pTIMER->state;
    BYTE		data		= 0;
    int			deltastate	= 0;

    Sii_LfWait = 100;
    Sii_wait	= TICKS_BDS;
    if (! Sii_TransferStarted) return Bit_0;

    // If there are new data in baInput
    if (outputBuffer.size())
    {
        deltastate = pTIMER->state - oldstate_in;

        if (deltastate < Sii_wait) return(currentBit);

//        oldstate_in	= pTIMER->state;
        oldstate_in	+= deltastate;

        data	= outputBuffer.at(0);

        data = (data == 0x0A ? 0x0D : data);
        currentBit		= byteToBit(data);

        switch (currentBit)
        {
        case Bit_Start:	currentBit = Bit_1;
                        Sii_wait = TICKS_BDS;
                        return(currentBit);		// START BIT
        case Bit_0:
        case Bit_1:     AddLog(LOG_SIO,tr("Envoie bit = %1").arg(currentBit==Bit_1?1:0));
                        Sii_wait = TICKS_BDS;
                        return(currentBit);		// DATA BIT

        case Bit_Stop:	currentBit = Bit_0;
                        Sii_wait = TICKS_BDS;
                        if (data == 0x0D)
                        {
                            Sii_wait=Sii_LfWait*pTIMER->pPC->getfrequency()/1000;
                            AddLog(LOG_SIO,tr("LF found, wait %1 ms").arg(Sii_LfWait));
                        }
                        outputBuffer.remove(0,1);										// Next Char
                        return(currentBit);
        }
    }

    if (
        Sii_TransferStarted &&
        (outputBuffer.size() == 0) )
    {
        Sii_startbitsent	= false;
        Sii_stopbitsent		= true;
        Sii_TransferStarted	= false;
        Set_CD(0);
        AddLog(LOG_SIO,tr("END TRANSMISSION"));
    }

    return(Bit_0);
}
コード例 #2
0
ファイル: sio.cpp プロジェクト: pockemul/PockEmul
// Implement parity
bool Csio::transmit(void)
{

    if (oldstate_in	== 0) oldstate_in = pTIMER->state;
	BYTE		data		= 0;
    quint64			deltastate	= 0;

	Sii_LfWait = 100;
    Sii_wait	= TICKS_BDS;
	
// If there are new data in baInput
	if (! Sii_TransferStarted) return 0;

    //if ( Sii_ndx < baInput.size() )
    if (baInput.size())
	{
        deltastate = pTIMER->state - oldstate_in;

        if (deltastate < Sii_wait) return(currentBit);


        oldstate_in	= pTIMER->state;
//		oldstate_in	+= deltastate;

        data	= baInput.at(0);


        // Update Input proressbar
        emit valueChanged((int)((Sii_ndx*100)/byteBufferSize+.5));
        Refresh_Display = true;
		data = (data == 0x0A ? 0x0D : data);
        currentBit		= byteToBit(data);
		
        switch (currentBit)
		{
        case 3:	currentBit = 1;
                Sii_wait = TICKS_BDS;
                if (mainwindow->dialoganalogic) mainwindow->dialoganalogic->setMarker(1);
                return(currentBit);		// START BIT
		case 0:
        case 1:	AddLog(LOG_SIO,tr("Envoie bit = %1").arg(currentBit));
                Sii_wait = TICKS_BDS;
                if (mainwindow->dialoganalogic) mainwindow->dialoganalogic->setMarker(2);
                return(currentBit);		// DATA BIT

        case 2:	currentBit = 0;
                Sii_wait = TICKS_BDS;

                if (data == 0x0D)
                {
                    Sii_wait+=Sii_LfWait*pTIMER->pPC->getfrequency()/1000;
                    AddLog(LOG_SIO,tr("LF found, wait %1 ms").arg(Sii_LfWait));
                }

                baInput.remove(0,1);										// Next Char
                Sii_ndx++;
                if (mainwindow->dialoganalogic) mainwindow->dialoganalogic->setMarker(4);
                return(currentBit);
		}
	}

	if (
		Sii_TransferStarted &&
        (baInput.size() == 0) )
	{
		// End of file
//		Sii_ndx				= 0;
//		Set_Sii_bit(0);
        Sii_startbitsent	= false;
        Sii_stopbitsent		= true;
        Sii_TransferStarted	= false;
		Set_CD(0);
		clearInput();
		AddLog(LOG_SIO,tr("END TRANSMISSION"));
	}

	return(0);
}