示例#1
0
// Write a rectangle in bytecode as left, top, width, height. Return the position after the rectangle.
TInt CTmCode::InsertRectL(const TRect& aRect,TInt aPos)
{
    TUint8 buffer[20];
    int bytes = WriteNumber(aRect.iTl.iX,buffer);
    bytes += WriteNumber(aRect.iTl.iY,buffer + bytes);
    bytes += WriteNumber(aRect.Width(),buffer + bytes);
    bytes += WriteNumber(aRect.Height(),buffer + bytes);
    iBuffer->InsertL(aPos,buffer,bytes);
    return aPos + bytes;
}
示例#2
0
/*
Write a number in bytecode, using as few bytes as possible. Each byte assigns the low seven bits
to data and uses the high bit as a continuation bit. Return the position after the number.
*/
TInt CTmCode::InsertNumberL(TInt aNumber,TInt aPos)
{
    TUint8 buffer[5];
    int bytes = WriteNumber(aNumber,buffer);
    iBuffer->InsertL(aPos,buffer,bytes);
    return aPos + bytes;
}
示例#3
0
/********************************************************************************************

	INT32 HTMLExportFilter::WriteCircleCoords(DocCoord dcCentre, INT32 lRadius, TCHAR* pcValue, CCLexFile* pfileToWrite, TCHAR* pcBuffer)

	Author:		Graham_Walmsley (Xara Group Ltd) <*****@*****.**>
	Created:	18/4/97
	Inputs:		dcCentre		Centre of the circle to write
				lRadius			Radius of the circle to write
				pfileToWrite	The file to write to (may be NULL)
				pcBuffer		The text buffer to write to (may be NULL)
	Returns:	The number of TCHARs written
	Purpose:	Writes out the coordinates of a circle
				e.g. COORDS="200,200,100"

********************************************************************************************/
INT32 HTMLExportFilter::WriteCircleCoords(DocCoord dcCentre, INT32 lRadius, TCHAR* pcValue, CCLexFile* pfileToWrite, TCHAR* pcBuffer)
{
	//This is the value we will return
	INT32 lCharsWritten=0;

	//First write out a space
	lCharsWritten+=Write(_R(IDS_HTMLEXPORT_SPACE), pfileToWrite, pcBuffer);

	//Now write out COORDS
	lCharsWritten+=Write(_R(IDS_HTMLEXPORT_COORDS), pfileToWrite, pcBuffer);
				   
	//And an equals sign
	lCharsWritten+=Write(_R(IDS_HTMLEXPORT_EQUALS), pfileToWrite, pcBuffer);

	//And an opening quote
	lCharsWritten+=Write(_R(IDS_HTMLEXPORT_QUOTES), pfileToWrite, pcBuffer);

	//The centre
	lCharsWritten+=Write(dcCentre, pfileToWrite, pcBuffer);

	//A comma
	lCharsWritten+=Write(_R(IDS_HTMLEXPORT_COMMA), pfileToWrite, pcBuffer);

	//The radius
	lCharsWritten+=WriteNumber(lRadius, pfileToWrite, pcBuffer);

	//Write a closing quote
	lCharsWritten+=Write(_R(IDS_HTMLEXPORT_QUOTES), pfileToWrite, pcBuffer);

	//And return the number of characters written
	return lCharsWritten;
}
示例#4
0
文件: Time.cpp 项目: bmer/Alchemy
CString CTimeDate::Format (const CString &sFormat) const

//	Format
//
//	Formats a timedate
//
//    %a    abbreviated weekday name (Sun)
//    %A    full weekday name (Sunday)
//    %b    abbreviated month name (Dec)
//    %B    full month name (December)
//    %c    date and time (Dec  2 06:55:15 1979)
//    %d    day of the month (02)
//    %H    hour of the 24-hour day (06)
//    %I    hour of the 12-hour day (06)
//    %j    day of the year, from 001 (335)
//    %m    month of the year, from 01 (12)
//    %M    minutes after the hour (55)
//    %p    AM/PM indicator (AM)
//    %S    seconds after the minute (15)
//    %U    Sunday week of the year, from 00 (48)
//    %w    day of the week, from 0 for Sunday (6)
//    %W    Monday week of the year, from 00 (47)
//    %x    date (Dec  2 1979)
//    %X    time (06:55:15)
//    %y    year of the century, from 00 (79)
//    %Y    year (1979)
//    %Z    time zone name, if any (EST)
//    %%    percent character %

	{
	//	Internet format:
	//
	//	Sun, 06 Nov 1994 08:49:37 GMT

	if (strEquals(sFormat, FORMAT_INTERNET))
		{
		return strPatternSubst(CONSTLIT("%s, %02d %s %d %02d:%02d:%02d GMT"),
				CString(g_szDayNameShort[DayOfWeek()], 3, true),
				m_Time.wDay,
				CString(g_szMonthNameShort[m_Time.wMonth], 3, true),
				m_Time.wYear,
				m_Time.wHour,
				m_Time.wMinute,
				m_Time.wSecond);
		}

	//	Otherwise we expect various fields

	else
		{
		CMemoryWriteStream Stream(0);
		if (Stream.Create() != NOERROR)
			return NULL_STR;

		char *pPos = sFormat.GetASCIIZPointer();
		while (*pPos != '\0')
			{
			if (*pPos == '%')
				{
				pPos++;

				int iLeadingZeros;
				if (*pPos == '0')
					{
					pPos++;

					if (*pPos >= '1' && *pPos <= '9')
						{
						iLeadingZeros = (*pPos) - '0';
						pPos++;
						}
					else
						iLeadingZeros = 2;
					}
				else
					iLeadingZeros = 0;
			
				switch (*pPos)
					{
					case '\0':
						break;

					case 'B':
						Stream.Write(g_szMonthName[m_Time.wMonth], (int)::strlen(g_szMonthName[m_Time.wMonth]));
						pPos++;
						break;

					case 'd':
						WriteNumber(Stream, m_Time.wDay, iLeadingZeros);
						pPos++;
						break;

					case 'I':
						if ((m_Time.wHour % 12) == 0)
							WriteNumber(Stream, 12, iLeadingZeros);
						else
							WriteNumber(Stream, m_Time.wHour % 12, iLeadingZeros);
						pPos++;
						break;

					case 'M':
						WriteNumber(Stream, m_Time.wMinute, 2);
						pPos++;
						break;

					case 'p':
						if (m_Time.wHour < 12)
							Stream.Write("AM", 2);
						else
							Stream.Write("PM", 2);
						pPos++;
						break;

					case 'S':
						WriteNumber(Stream, m_Time.wSecond, 2);
						pPos++;
						break;

					case 'Y':
						WriteNumber(Stream, m_Time.wYear, 0);
						pPos++;
						break;

					default:
						{
						Stream.Write(pPos, 1);
						pPos++;
						}
					}
				}
			else
				{
				Stream.Write(pPos, 1);
				pPos++;
				}
			}

		return CString(Stream.GetPointer(), Stream.GetLength());
		}
	}
示例#5
0
// save all songs from memory into the writeable ROM
void GlobalData::SaveSongs()
{
	REG_IME = 0; // disable interrupts

	// pointers for traversing the data
	structSongData *songtrav = songdata;
	structLoopData *looptrav = NULL;
	structNoteData *notetrav = NULL;
	offset = 0;
	debug("Saving Song data Starting at 0x%lx", (u32)songtrav);
	
	// write the magic string
	WriteNumber(magic, sizeof(u16));

	// go through each song
	while (songtrav)
	{		
		// write song name
		WriteString(songtrav->name);
		debug("Song name: %s", songtrav->name);

		// write bpm
		WriteNumber(songtrav->bpm, sizeof(u16));
		debug("Song speed: %d", songtrav->bpm);
		
		// go through each loop in this song
		looptrav = songtrav->loops;
		debug("looptrav initial address: 0x%lx", (u32)looptrav);
		while (looptrav)
		{
			debug("Writing loop %s", looptrav->name);
			
			// write the loop name
			WriteString(looptrav->name);
			// write the sample number
			WriteNumber(looptrav->sample, sizeof(u16));
			// write the panning direction
			WriteNumber(looptrav->pan, sizeof(bool));
			// write the pitch
			WriteNumber(looptrav->pitch, sizeof(u16));
			// write the number of divisions
			WriteNumber(looptrav->divisions, sizeof(u16));

			// go through each note
			notetrav = looptrav->notes;
			while (notetrav)
			{
				debug("Writing note 0x%lx", notetrav);
				
				// write the note end action;
				WriteNumber(notetrav->noteEnd, sizeof(u8));
				// write the beat offset
				WriteNumber(notetrav->offset, sizeof(u8));
				// write the pitch
				WriteNumber(notetrav->pitch, sizeof(u8));
				// write the swing
				WriteNumber(notetrav->swing, sizeof(u8));
				
				// next note
				notetrav = notetrav->next;
			}
			// write the magic string for end-of-notes
			WriteNumber(magic, sizeof(u16));
			
			// next loop
			looptrav = looptrav->next;
			debug("Next loop: 0x%lx", looptrav);
		}
		// write the magic string for end-of-loops
		WriteNumber(magic, sizeof(u16));
				
		// next song
		songtrav = songtrav->next;
	}

	// write the magic string again for end-of-songs
	WriteNumber(magic, sizeof(u16));

	// reset the offset
	offset = 0;

	REG_IME = 1; // enable interrupts
}
示例#6
0
static int strip_othersubrs(gs_glyph_data_t *gdata, gs_font_type1 *pfont, byte *stripped, byte *SubrsWithMM)
{
    crypt_state state = crypt_charstring_seed;
    gs_bytestring *data = (gs_bytestring *)&gdata->bits;
    byte *source = data->data, *dest = stripped, *end = source + data->size;
    int i, dest_length = 0, CurrentNumberIndex = 0, Stack[64], written;
    int OnlyCalcLength = 0;
    char Buffer[16];

    memset(Stack, 0x00, 64 * sizeof(int));
    if (stripped == NULL) {
        OnlyCalcLength = 1;
        dest = (byte *)&Buffer;
    }

    gs_type1_decrypt(source, source, data->size, &state);

    if(pfont->data.lenIV >= 0) {
        for (i=0;i<pfont->data.lenIV;i++) {
            if (!OnlyCalcLength)
                *dest++ = *source++;
        }
        dest_length += pfont->data.lenIV;
    }
    while (source < end) {
        if (*source < 32) {
            /* Command */
            switch (*source) {
                case 12:
                    if (*(source + 1) == 16) {
                        /* Callothersubsr, the only thing we care about */
                        switch(Stack[CurrentNumberIndex-1]) {
                            /* If we find a Multiple Master call, remove all but the
                             * first set of arguments. Mimics the result of a call.
                             * Adobe 'encourages' the use of Subrs to do MM, but
                             * the spec doens't say you have to, so we need to be
                             * prepared, just in case. I doubt we will ever execute
                             * this code.
                             */
                            case 14:
                                CurrentNumberIndex -= pfont->data.WeightVector.count - 1;
                                for (i = 0;i < CurrentNumberIndex;i++) {
                                    written = WriteNumber(dest, Stack[i]);
                                    dest_length += written;
                                    if (!OnlyCalcLength)
                                        dest += written;
                                }
                                source += 2;
                                break;
                            case 15:
                                CurrentNumberIndex -= (pfont->data.WeightVector.count - 1) * 2;
                                for (i = 0;i < CurrentNumberIndex;i++) {
                                    written = WriteNumber(dest, Stack[i]);
                                    dest_length += written;
                                    if (!OnlyCalcLength)
                                        dest += written;
                                }
                                source += 2;
                                break;
                            case 16:
                                CurrentNumberIndex -= (pfont->data.WeightVector.count - 1) * 3;
                                for (i = 0;i < CurrentNumberIndex;i++) {
                                    written = WriteNumber(dest, Stack[i]);
                                    dest_length += written;
                                    if (!OnlyCalcLength)
                                        dest += written;
                                }
                                source += 2;
                                break;
                            case 17:
                                CurrentNumberIndex -= (pfont->data.WeightVector.count - 1) * 4;
                                for (i = 0;i < CurrentNumberIndex;i++) {
                                    written = WriteNumber(dest, Stack[i]);
                                    dest_length += written;
                                    if (!OnlyCalcLength)
                                        dest += written;
                                }
                                source += 2;
                                break;
                            case 18:
                                CurrentNumberIndex -= (pfont->data.WeightVector.count - 1) * 6;
                                for (i = 0;i < CurrentNumberIndex;i++) {
                                    written = WriteNumber(dest, Stack[i]);
                                    dest_length += written;
                                    if (!OnlyCalcLength)
                                        dest += written;
                                }
                                source += 2;
                                break;
                            default:
                                for (i = 0;i < CurrentNumberIndex;i++) {
                                    written = WriteNumber(dest, Stack[i]);
                                    dest_length += written;
                                    if (!OnlyCalcLength)
                                        dest += written;
                                }
                                if (!OnlyCalcLength) {
                                    *dest++ = *source++;
                                    *dest++ = *source++;
                                } else {
                                    source += 2;
                                }
                                dest_length += 2;
                                break;
                        }
                    } else {
                        for (i = 0;i < CurrentNumberIndex;i++) {
                            written = WriteNumber(dest, Stack[i]);
                            dest_length += written;
                            if (!OnlyCalcLength)
                                dest += written;
                        }
                        if (!OnlyCalcLength) {
                            *dest++ = *source++;
                            *dest++ = *source++;
                        } else {
                            source += 2;
                        }
                        dest_length += 2;
                    }
                    break;
                case 10:
                    if (CurrentNumberIndex != 0 && SubrsWithMM[Stack[CurrentNumberIndex - 1]] != 0) {
                        int index = Stack[CurrentNumberIndex - 1];
                        int StackBase = CurrentNumberIndex - 1 - pfont->data.WeightVector.count * SubrsWithMM[index];

                        CurrentNumberIndex--; /* Remove the subr index */

                        for (i=0;i < StackBase; i++) {
                            written = WriteNumber(dest, Stack[i]);
                            dest_length += written;
                            if (!OnlyCalcLength)
                                dest += written;
                        }
                        for (i=0;i<SubrsWithMM[index];i++) {
                            written = WriteNumber(dest, Stack[StackBase + i]);
                            dest_length += written;
                            if (!OnlyCalcLength)
                                dest += written;
                        }
                        source++;
                    } else {
                        for (i = 0;i < CurrentNumberIndex;i++) {
                            written = WriteNumber(dest, Stack[i]);
                            dest_length += written;
                            if (!OnlyCalcLength)
                                dest += written;
                        }
                        if (!OnlyCalcLength)
                            *dest++ = *source++;
                        else
                            source++;
                        dest_length++;
                    }
                    break;
                default:
                    for (i = 0;i < CurrentNumberIndex;i++) {
                        written = WriteNumber(dest, Stack[i]);
                        dest_length += written;
                        if (!OnlyCalcLength)
                            dest += written;
                    }
                    if (!OnlyCalcLength)
                        *dest++ = *source++;
                    else
                        source++;
                    dest_length++;
            }
            CurrentNumberIndex = 0;
        } else {
            /* Number */
            if (*source < 247) {
                Stack[CurrentNumberIndex++] = *source++ - 139;
            } else {
                if (*source < 251) {
                    Stack[CurrentNumberIndex] = ((*source++ - 247) * 256) + 108;
                    Stack[CurrentNumberIndex++] += *source++;
                } else {
                    if (*source < 255) {
                        Stack[CurrentNumberIndex] = ((*source++ - 251) * -256) - 108;
                        Stack[CurrentNumberIndex++] -= *source++;
                    } else {
                        source++;
                        Stack[CurrentNumberIndex] = *source++ << 24;
                        Stack[CurrentNumberIndex] += *source++ << 16;
                        Stack[CurrentNumberIndex] += *source++ << 8;
                        Stack[CurrentNumberIndex++] += *source++;
                    }
                }
            }
        }
    }
    source = data->data;
    state = crypt_charstring_seed;
    gs_type1_encrypt(source, source, data->size, &state);

    if (!OnlyCalcLength) {
        state = crypt_charstring_seed;
        gs_type1_encrypt(stripped, stripped, dest_length, &state);
    }
    return dest_length;
}
示例#7
0
文件: main_rtx.c 项目: apandit/RTOS
int main() 
{

    rtx_dbug_outs((CHAR *)"rtx: Entering main()\r\n");

    /* get the third party test proc initialization info */
    __REGISTER_TEST_PROCS_ENTRY__();
	
	rtxEnd = &(_end);
	m_nextPid = 1;
	
	// Setting up trap # 0
    // Load vector table for trap # 0
    asm( "move.l #asm_trap_entry, %d0" );
    asm( "move.l %d0, 0x10000080" );
	
	#ifdef _DEBUG_
	rtx_dbug_outs( (CHAR*)"Start\r\n" );
	WriteHex((int)malloc(0) );
	rtx_dbug_outs( (CHAR*)" Address before PCBS\r\n" );
	#endif
	// Allocate and initialize pcbs and its stacks
	//rtxProcess* pcbs = AllocatePCBs( MAX_NUMPROCS );
	pcbs = AllocatePCBs( MAX_NUMPROCS );
	#ifdef _DEBUG_
	WriteHex((int)malloc(0) );
	rtx_dbug_outs( (CHAR*)" Address after PCBS\r\n" );
	#endif
	// Initialize the process manager
	rtxProcMan = InitProcessManager();
	#ifdef _DEBUG_
	WriteHex((int)malloc(0) );
	rtx_dbug_outs( (CHAR*)" Address after Procman?\r\n" );
	#endif
	// Create the null process
	rtxProcess* nullProc = CreateProcess( pcbs, null_process, AllocateStack(256), 0, NULLPROCPRIORITY );
	nullProc->status = READY;
	rtxProcMan->nullProc = nullProc;
	#ifdef _DEBUG_
	WriteHex((int)malloc(0) );
	rtx_dbug_outs( (CHAR*)" Address after nullproc?\r\n" );
	#endif
	//Create the Processes
	rtxProcess* cp2 = CreateProcess( pcbs, &keyboardCommandDecoder, AllocateStack(2048), KCDPID, MEDIUM );
	rtxProcess* cp1 = CreateProcess( pcbs, &CRTDisplay, AllocateStack(512), CRTPID, MEDIUM);
	rtxProcess* cp3 = CreateProcess( pcbs, &UART_PROCESS, AllocateStack(512), UARTPID, HIGH );
	
	CRT = cp1;
   	KCD = cp2;
	UART = cp3;	
	
	// Creating and enqueueing the test processes
	for( m_nextPid = 1 ; m_nextPid < (NUM_TEST_PROCS + 1); m_nextPid++ ){
		EnqueueProcess( 
			rtxProcMan, 
			CreateProcess( 
				pcbs, 
				g_test_proc[m_nextPid-1].entry, 
				AllocateStack( g_test_proc[m_nextPid-1].sz_stack ),
				g_test_proc[m_nextPid-1].pid,
				g_test_proc[m_nextPid-1].priority
			),
			READYQUEUE
		);
	}
	
	// Set the next pid to be 1 greater than last test proc pid
	//m_nextPid = g_test_proc[m_nextPid-2].pid + 1;
	
	// Initialize some of our own system processes
	
	EnqueueProcess( rtxProcMan, cp2,READYQUEUE);
	EnqueueProcess( rtxProcMan, cp1,READYQUEUE );

	
	
	// Initialize the scheduler
	InitializeScheduler( (ProcessManager*)(rtxProcMan) );
	
	// Time to allocate and initialize free memory
	UINT32 numTotalBlocks = ( (UINT32)0x10200000 - (UINT32)malloc(0)) / sizeof(MemoryBlock);
	
	//numTotalBlocks = 1;
	#ifdef _DEBUG_
	WriteHex((int)malloc(0) );
	rtx_dbug_outs( (CHAR*)" Address At start of freemem\r\n" );
	#endif
	// Allocate free memory and create memory table
	MemoryBlock* memstart = AllocateFreeMemory( sizeof(MemoryBlock), numTotalBlocks );
	#ifdef _DEBUG_
	WriteHex((int)malloc(0) );
	rtx_dbug_outs( (CHAR*)" Address after freemem?\r\n" );
	rtx_dbug_outs( (CHAR*)"Allocated Free Memory\r\n" );
	#endif
	InitMemQueue( &freeMemory );
	InitializeMemory( &freeMemory, memstart, numTotalBlocks );
	#ifdef _DEBUG_	
    rtx_dbug_outs( (CHAR*)"Number of free memory blocks: " );
    WriteNumber( freeMemory.count );	
    WriteLine();

	rtx_dbug_outs( (CHAR*)"Initialized Free Memory\r\n" );
	#endif
	
	UINT32 mask;
	
	//disable all interupts 
	asm( "move.w #0x2700,%sr" );
	
	coldfire_vbr_init();
	
	//store the serial ISR at user vector #64
	asm( "move.l #asm_serial_entry,%d0" );
	asm( "move.l %d0,0x10000100" );

	//reset the entire UART 
	SERIAL1_UCR = 0x10;

	//reset the receiver 
	SERIAL1_UCR = 0x20;
	
	//reset the transmitter 
	SERIAL1_UCR = 0x30;

	//reset the error condition
	SERIAL1_UCR = 0x40;

	//install the interupt
	SERIAL1_ICR = 0x17;
	SERIAL1_IVR = 64;

	//enable interrupts on rx only
	SERIAL1_IMR = 0x02;

	//set the baud rate
	SERIAL1_UBG1 = 0x00;
#ifdef _CFSERVER_           /* add -D_CFSERVER_ for cf-server build */
	SERIAL1_UBG2 = 0x49;    /* cf-server baud rate 19200 */ 
#else
	SERIAL1_UBG2 = 0x92;    /* lab board baud rate 9600 */
#endif 

	//set clock mode
	SERIAL1_UCSR = 0xDD;

	//setup the UART (no parity, 8 bits )
	SERIAL1_UMR = 0x13;
	
	//setup the rest of the UART (noecho, 1 stop bit )
	SERIAL1_UMR = 0x07;

	//setup for transmit and receive
	SERIAL1_UCR = 0x05;

	//enable interupts
	mask = SIM_IMR;
	mask &= 0x0003dfff;
	SIM_IMR = mask;

	//enable all interupts
	asm( "move.w #0x2000,%sr" );
	// end of keyboard interrupts
	
	
	// Start it up
	ScheduleNextProcess( rtxProcMan, NULL );
	
    return 0;
}