示例#1
0
/************************************************************ DOC:

CLASS

	moOStream

NAME

	Write - call this function to write some data from a file
	RawWrite - the implementation dependent write function

SYNOPSIS

	virtual int Write(const void *buffer, size_t length);

	protected:
	virtual int RawWrite(const void *buffer, size_t length) = 0;

PARAMETERS

	buffer - a pointer where the data read will be saved
	length - the number of bytes to read in buffer

DESCRIPTION

	The Write() function will call the RawWrite() after it passed the
	user data to the current output filter. The filter is in charge
	of transforming the user data in a raw format to be saved in the
	stream.

	The RawWrite() function is implementation dependent and thus
	is a pure virtual here. The moFile, for instance, defines the
	RawWrite() as the fwrite() function in some input disk file or
	some other simple character stream.

NOTES

	Because a filter may shrink (a compressor for instance) or
	enlarge (UTF8 to UTF32 for instance) the returned value
	could be interpreted in different ways. It was therefore
	decided that the number of bytes read from the user buffer
	pointer was the number we needed to return. This means
	more or less bytes may actually have been written to the
	final output stream.

RETURN VALUE

	the number of bytes from buffer written
	0 when nothing can be written
	-1 when an error occurs
 
SEE ALSO

	Put()

*/
int moOStream::Write(const void *buffer, size_t length)
{
	int		l, total, sz;
	char		buf[BUFSIZ];	/* Flawfinder: ignore */

	if(!f_output_filter) {
		return RawWrite(buffer, length);
	}

	total = 0;
	do {
		l = f_output_filter->Write(buffer, moMin(f_output_filter->FreeSpace(), length));
		if(l < 0) {
			return -1;
		}
		buffer = static_cast<const char *>(buffer) + l;
		length -= l;
		for(;;) {
			sz = f_output_filter->Read(buf, sizeof(buf));
			if(sz <= 0) {
				// not enough data for this transform filter
				break;
			}
			sz = RawWrite(buf, sz);
			if(sz < 0) {
				return -1;
			}
		}
		total += l;
	} while(length != 0);

	return total;
}
示例#2
0
static int OnTimerNotify(WindowControl *Sender)
{

   // Do we have a premature shutdown request from system quit?
   if (RUN_MODE==RUN_SHUTDOWN) {
	#if TESTBENCH
	StartupStore(_T("... dlGStartup shutdown requested\n"));
	#endif
	wf->SetModalResult(mrOK);
   }

   #if 0
   static short i=0;
   if(i++ % 2 == 0) // called at 2hz, run once per second
	return 0;

   if (RUN_MODE==RUN_WELCOME) {
	TCHAR mes[100];
	_stprintf(mes,_T("Version %S.%S (%S)"),LKVERSION,LKRELEASE,__DATE__);
	short r,g,b;
	r=rand()%256; g=rand()%256; b=rand()%256;
	RawWrite(Sender->GetDeviceContext(),mes,12,1, RGB(r,g,b),WTMODE_NORMAL);
   }
   #endif
   return 0;
}
示例#3
0
bool Bytebuffer::WriteString(std::string &Input, bool Typechecked)
{
    if (Typechecked)
        WriteDatatype(eBytebufferType::ASCIISTRING);

    return RawWrite((uint32_t)Input.size(), (void *)Input.c_str());
}
示例#4
0
/*****************************************************************************
 * FUNCTION: SendRAWDataFrame
 *
 * RETURNS: TRUE or FALSE
 *
 * PARAMS:
 *      UINT8* pBuf -> pointer to the command buffer.
 *      UINT16 bufLen -> length in bytes of the buffer (pBuf).
 *
 *
 *  NOTES: SendRAWDataFrame sends a Data Transmit request to the WF chip
 *          using the Random Access Window (RAW) interface.  The pre-buffer
 *          is used by the WF MAC to send routing information for the packet
 *          while pBuf is the request that was submitted by the application.
 *          The order of operations are
 *              1) reserve a memory buffer of sufficient length on the WF chip
 *              using RawMove.
 *              2) Write the bytes for the pre-buffer and then the buffer
 *              using the RawSetByte. Because the bytes are written
 *              sequentially there is no need to call WFRawSetIndex
 *              to adjust the write position.
 *              3) instruct the WF chip that the command is ready for
 *              processing.
 *              4) perform any necessary cleanup.
 *****************************************************************************/
void SendRAWDataFrame(UINT16 bufLen)
{
    UINT8 txDataPreamble[4] = { WF_DATA_REQUEST_TYPE, WF_STD_DATA_MSG_SUBTYPE, 1, 0};

    RawWrite(RAW_TX_ID, 0, sizeof(txDataPreamble), txDataPreamble);
    
    RawSendTxBuffer(bufLen);
}
示例#5
0
bool Bytebuffer::WriteBlob(uint32_t DataLength, void *DataBuffer, bool Typechecked)
{
    if (Typechecked)
        WriteDatatype(eBytebufferType::BLOB);

    TemplateWrite(DataLength);
    return RawWrite(DataLength, DataBuffer);
}
示例#6
0
bool Bytebuffer::WriteBlob(std::basic_string<uint8_t> *Input, bool Typechecked)
{
    if (Typechecked)
        WriteDatatype(eBytebufferType::BLOB);

    TemplateWrite<uint32_t>((uint32_t)Input->size());
    return RawWrite((uint32_t)Input->size(), (void *)Input->data());
}
示例#7
0
bool Bytebuffer::RawWrite(uint32_t WriteCount, void *InBuffer)
{
    // If we don't have a buffer, increment and leave.
    if (InBuffer == nullptr)
    {
        InternalPosition += WriteCount;
        return true;
    }

    // If we are at the end of the stream, append.
    if (InternalPosition == InternalBuffer.size())
    {
        InternalBuffer.append((const uint8_t *)InBuffer, WriteCount);
        InternalPosition += WriteCount;
        return true;
    }

    // Range check.
    if (InternalPosition > InternalBuffer.size())
    {
        //fDebugPrint("%s tried to write out of bounds.", __func__);
        return false;
    }

    // If we can fit the data in already allocated memory, copy.
    if (InternalPosition + WriteCount < InternalBuffer.size())
    {
        for (uint32_t i = 0; i < WriteCount; ++i)
            InternalBuffer[i] = ((const uint8_t *)InBuffer)[i];

        InternalPosition += WriteCount;
        return true;
    }

    // Write the data as preallocated and appended.
    uint32_t AllocatedBytes = (uint32_t)InternalBuffer.size() - InternalPosition;
    return RawWrite(AllocatedBytes, InBuffer)
        && RawWrite(WriteCount - AllocatedBytes, (uint8_t *)InBuffer + AllocatedBytes);
}
示例#8
0
文件: sound.c 项目: ficoos/fceu-next
void FCEUD_WriteSoundData(int32 *Buffer, int Count)
{
 static int16 MBuffer[2 * 96000 / 50];  /* * 2 for safety. */
 int P;

 if(!bittage)
 {
  for(P=0;P<Count;P++)
   *(((uint8*)MBuffer)+P)=((int8)(Buffer[P]>>8))^128;
  RawWrite(MBuffer,Count);
 }
 else
 {
  for(P=0;P<Count;P++)
/*****************************************************************************
  Function:
	void SendRAWDataFrame(UINT16 bufLen)

  Summary:
	Sends a data frame to the WiFi chip for transmission to the 802.11 network.

  Description:
    After the TCP/IP stack has created a data frame and called MACFlush() this
    function is called to notify the WiFi chip to transmit the data frame to the 
    802.11 network.  The actual data frame starts at index 4 in the allocated buffer.
    The first 4 bytes (indexes 0 - 3) were reserved, and this function fills them
    in with an internal preamble which notifies the WiFi chip that this is a data
    frame to send (as opposed to a management frame).

  Precondition:
	None

  Parameters:
	bufLen -- number of data bytes that comprise the data frame.
	             
  Returns:
  	None
  	
  Remarks:
	None
*****************************************************************************/
void SendRAWDataFrame(UINT16 bufLen)
{
    /* create internal preamble */
    UINT8 txDataPreamble[4] = { WF_DATA_REQUEST_TYPE, WF_STD_DATA_MSG_SUBTYPE, 1, 0};

    /* write out internal preamble, starting at index 0 in the raw window */
    RawWrite(RAW_DATA_TX_ID, 0, sizeof(txDataPreamble), txDataPreamble);

    /* Notify WiFi device that there is a transmit frame to send .  The frame will */
    /* be automatically deallocated after RF transmission is completed.            */
    RawMove(RAW_DATA_TX_ID, RAW_MAC, FALSE, bufLen);
    
    /* this raw window is logically no longer mounted.  The WiFi chip will  */
    /* automatically deallocate after RF transmission.                      */
    SetRawWindowState(RAW_DATA_TX_ID, WF_RAW_UNMOUNTED);
}
示例#10
0
bool Bytebuffer::WriteDatatype(eBytebufferType Type)
{
    return RawWrite(1, &Type);
}
示例#11
0
static void OnSplashPaint(WindowControl * Sender, HDC hDC){

 TCHAR srcfile[MAX_PATH];
 TCHAR fprefix[20];

 if (RUN_MODE==RUN_SHUTDOWN) return;

 if (RUN_MODE==RUN_WELCOME) 
	_tcscpy(fprefix,_T("LKSTART"));
 else
	_tcscpy(fprefix,_T("LKPROFILE"));

 LoadSplash(hDC,fprefix);

  if (RUN_MODE==RUN_WELCOME) {
	TCHAR mes[100];
	int pos=0;
	switch (ScreenSize) {
		case ss800x480:
			pos=12;
			break;
		case ss400x240:
			pos=12;
			break;
		case ss480x272:
			if (ScreenSizeX==854)
				pos=14;
			else
				pos=11;
			break;
		case ss640x480:
			pos=12;
			break;
		case ss320x240:
			pos=12;
			break;
		case ss896x672:
			pos=14;
			break;
		// --------- portrait -------------
		case ss240x320:
			pos=17;
			break;
		case ss480x640:
			pos=17;
			break;
		case ss272x480:
			pos=18;
			break;
		case ss240x400:
			pos=16;
			break;
		case ss480x800:
			pos=18;
			break;
		default:
			pos=11;
			break;
	}
	if (fullresetasked) {
		_stprintf(mes,_T("*** %s ***"),gettext(_T("_@M1757_")));
		RawWrite(hDC,mes,pos,1, RGB_DARKWHITE,WTMODE_NORMAL);
	} else {
#ifndef LKCOMPETITION
		_stprintf(mes,_T("Version %S.%S (%S)"),LKVERSION,LKRELEASE,__DATE__);
#else
		_stprintf(mes,_T("V%S.%S COMPETITION"),LKVERSION,LKRELEASE,__DATE__);
#endif
		RawWrite(hDC,mes,pos,1, RGB_DARKWHITE,WTMODE_NORMAL);
	}
  }

  if (RUN_MODE!=RUN_WELCOME) {

	// FillRect(hDC,&ScreenSizeR, LKBrush_Black); // REMOVE 

	TCHAR mes[100];
#ifndef LKCOMPETITION
	_stprintf(mes,_T("%S v%S.%S - %s"),LKFORK,LKVERSION,LKRELEASE,gettext(_T("_@M2054_")));
#else
	_stprintf(mes,_T("%SC v%S.%S - %s"),LKFORK,LKVERSION,LKRELEASE,gettext(_T("_@M2054_")));
#endif
	RawWrite(hDC,mes,1,1, RGB_LIGHTGREY,WTMODE_NORMAL);

	unsigned long freeram = CheckFreeRam()/1024;
	TCHAR buffer[MAX_PATH];
	LocalPath(buffer);
	unsigned long freestorage = FindFreeSpace(buffer);
	_stprintf(mes,_T("free ram %.1ldM  storage %.1ldM"), freeram/1024,freestorage/1024);
	RawWrite(hDC,mes,3,0, RGB_LIGHTGREY,WTMODE_NORMAL);

	if ( ScreenSize != ss320x240 && ScreenLandscape )
	RawWrite(hDC,_T("_______________________"),2,2, RGB_LIGHTGREY,WTMODE_NORMAL);

	if (fullresetasked) {
		_stprintf(mes,_T("%s"),gettext(_T("_@M1757_")));	// LK8000 PROFILES RESET
		RawWrite(hDC,mes,5,2, RGB_ICEWHITE, WTMODE_OUTLINED);
		_stprintf(mes,_T("%s"),gettext(_T("_@M1759_")));	// SELECTED IN SYSTEM
		RawWrite(hDC,mes,6,2, RGB_ICEWHITE, WTMODE_OUTLINED);
	} else {
		_stprintf(mes,_T("%s"),PilotName_Config);
		RawWrite(hDC,mes,4,2, RGB_ICEWHITE, WTMODE_OUTLINED);

		_stprintf(mes,_T("%s"),AircraftRego_Config);
		RawWrite(hDC,mes,5,2, RGB_AMBER, WTMODE_OUTLINED);

		_stprintf(mes,_T("%s"),AircraftType_Config);
		RawWrite(hDC,mes,6,2, RGB_AMBER, WTMODE_OUTLINED);

    LKASSERT(szPolarFile[0]);
		extern void LK_wsplitpath(const WCHAR* path, WCHAR* drv, WCHAR* dir, WCHAR* name, WCHAR* ext);
		LK_wsplitpath(szPolarFile, (WCHAR*) NULL, (WCHAR*) NULL, srcfile, (WCHAR*) NULL);

		_stprintf(mes,_T("%s %s"),gettext(_T("_@M528_")),srcfile);  // polar file
		RawWrite(hDC,mes,7,2, RGB_AMBER, WTMODE_OUTLINED);

    LKASSERT(startProfileFile[0]);
		LK_wsplitpath(startProfileFile, (WCHAR*) NULL, (WCHAR*) NULL, srcfile, (WCHAR*) NULL);
		_stprintf(mes,_T("%s: %s"),MsgToken(1746),srcfile);  
		RawWrite(hDC,mes,11,1, RGB_ICEWHITE, WTMODE_NORMAL);
	}


	// RawWrite(hDC,_T("_______________________"),8,2, RGB_LIGHTGREY,WTMODE_NORMAL); // REMOVE FOR THE 3.0

	return;
  }

}
示例#12
0
static void OnSplashPaint(WindowControl * Sender, LKSurface& Surface) {

    TCHAR srcfile[MAX_PATH];

    if (RUN_MODE == RUN_SHUTDOWN) return;

    if(RUN_MODE == RUN_WELCOME) {
        if(!StartBitmap) {
            StartBitmap = LoadSplash(_T("LKSTART"));
        }
        if(StartBitmap) {
            DrawSplash(Surface, StartBitmap);
        }
    } else {
        if(!ProfileBitmap) {
            ProfileBitmap = LoadSplash(_T("LKPROFILE"));
        }
        if(ProfileBitmap) {
            DrawSplash(Surface, ProfileBitmap);
        }
    }

    if (RUN_MODE == RUN_WELCOME) {
        TCHAR mes[100];
        int pos = 0;
        switch (ScreenSize) {
            case ss480x272:
                if (ScreenSizeX == 854)
                    pos = 14;
                else
#ifdef __linux__
                    pos = 12;
#else
                    pos = 11;
#endif
                break;
                // --------- portrait -------------
            case ss240x320:
#ifdef __linux__
                pos = 19;
#else
                pos = 17;
#endif
                break;
            default:
                // customized definition
                if (ScreenLandscape) {
                    switch (ScreenGeometry) {
                        case SCREEN_GEOMETRY_43:
                            pos = 12;
                            break;
                        case SCREEN_GEOMETRY_53:
                            pos = 12;
                            break;
                        case SCREEN_GEOMETRY_169:
                            pos = 11;
                            break;
                        default:
                            pos = 11;
                            break;
                    }
                } else {
                    // Portrait
                    // try to get a rule for text position...
                    switch (ScreenGeometry) {
                        case SCREEN_GEOMETRY_43:
#ifdef __linux__
                            pos = 18;
#else
                            pos = 17;
#endif
                            break;
                        case SCREEN_GEOMETRY_53:
                            pos = 20;
                            break;
                        case SCREEN_GEOMETRY_169:
#ifdef __linux__
                            pos = 22;
#else
                            pos = 20;
#endif
                            break;
                        default:
                            pos = 21;
                            break;
                    }

                }
                break;
        }
        if (FullResetAsked) {
            _stprintf(mes, _T("*** %s ***"), MsgToken(1757));
            RawWrite(Surface, mes, pos, 1, RGBDARKWHITE, WTMODE_NORMAL);
        } else {
#ifndef LKCOMPETITION
            _stprintf(mes, _T("Version %s.%s (%s)"), _T(LKVERSION), _T(LKRELEASE), _T(__DATE__));
#else
            _stprintf(mes, _T("V%s.%s (%s) COMPETITION"), _T(LKVERSION), _T(LKRELEASE), _T(__DATE__));
#endif
            RawWrite(Surface, mes, pos, 1, RGBDARKWHITE, WTMODE_NORMAL);
#ifdef KOBO
            if(IsKoboOTGKernel()) {
                RawWrite(Surface, _T("- USB host kernel -"), pos+1, 1, RGBDARKWHITE, WTMODE_NORMAL);
            }
#endif
        }
    }

    if (RUN_MODE != RUN_WELCOME) {

        // FillRect(hDC,&ScreenSizeR, LKBrush_Black); // REMOVE

        TCHAR mes[100];
#ifndef LKCOMPETITION
        _stprintf(mes, _T("%s v%s.%s - %s"), _T(LKFORK), _T(LKVERSION), _T(LKRELEASE), MsgToken(2054));
#else
        _stprintf(mes, _T("%sC v%s.%s - %s"), _T(LKFORK), _T(LKVERSION), _T(LKRELEASE), MsgToken(2054));
#endif
        #ifdef DITHER
        RawWrite(Surface, mes, 1, 1, RGBLIGHTGREY, WTMODE_OUTLINED);
        #else
        RawWrite(Surface, mes, 1, 1, RGBLIGHTGREY, WTMODE_NORMAL);
        #endif

        size_t freeram = CheckFreeRam() / 1024;
        TCHAR buffer[MAX_PATH];
        LocalPath(buffer);
        size_t freestorage = FindFreeSpace(buffer);
        _stprintf(mes, _T("free ram %.1uM  storage %.1uM"), (unsigned int) freeram / 1024, (unsigned int) freestorage / 1024);
        #ifdef DITHER
        RawWrite(Surface, mes, 3, 0, RGBLIGHTGREY, WTMODE_OUTLINED);
        #else
        RawWrite(Surface, mes, 3, 0, RGBLIGHTGREY, WTMODE_NORMAL);
        #endif

        if (ScreenSize != ss320x240 && ScreenLandscape)
            RawWrite(Surface, _T("_______________________"), 2, 2, RGBLIGHTGREY, WTMODE_NORMAL);

        if (FullResetAsked) {
            _stprintf(mes, _T("%s"), MsgToken(1757)); // LK8000 PROFILES RESET
            RawWrite(Surface, mes, 5, 2, RGBICEWHITE, WTMODE_OUTLINED);
            _stprintf(mes, _T("%s"), MsgToken(1759)); // SELECTED IN SYSTEM
            RawWrite(Surface, mes, 6, 2, RGBICEWHITE, WTMODE_OUTLINED);
        } else {
            _stprintf(mes, _T("%s"), PilotName_Config);
            RawWrite(Surface, mes, 4, 2, RGBICEWHITE, WTMODE_OUTLINED);

            _stprintf(mes, _T("%s"), AircraftRego_Config);
            RawWrite(Surface, mes, 5, 2, RGBAMBER, WTMODE_OUTLINED);

            _stprintf(mes, _T("%s"), AircraftType_Config);
            RawWrite(Surface, mes, 6, 2, RGBAMBER, WTMODE_OUTLINED);

            LKASSERT(szPolarFile[0]);
            extern void LK_tsplitpath(const TCHAR* path, TCHAR* drv, TCHAR* dir, TCHAR* name, TCHAR * ext);
            LK_tsplitpath(szPolarFile, (TCHAR*) NULL, (TCHAR*) NULL, srcfile, (TCHAR*) NULL);

            _stprintf(mes, _T("%s %s"), MsgToken(528), srcfile); // polar file
            RawWrite(Surface, mes, 7, 2, RGBAMBER, WTMODE_OUTLINED);

            LKASSERT(startProfileFile[0]);
            LK_tsplitpath(startProfileFile, (TCHAR*) NULL, (TCHAR*) NULL, srcfile, (TCHAR*) NULL);
            _stprintf(mes, _T("%s: %s"), MsgToken(1746), srcfile);
            RawWrite(Surface, mes, 11, 1, RGBICEWHITE, WTMODE_NORMAL);
        }


        // RawWrite(hDC,_T("_______________________"),8,2, RGB_LIGHTGREY,WTMODE_NORMAL); // REMOVE FOR THE 3.0

        return;
    }

}