コード例 #1
0
ファイル: Debugger.cpp プロジェクト: bigfatbrowncat/Vintage
void Debugger::printMenu()
{
	if (screen.isActive() || state == dsStopped)
	{
		screen.SelectForeColor(0, 0, 0);
		screen.SelectBackColor(192, 192, 192);
		printFixed(screen.getFrameBufferWidth() - 25, screen.getFrameBufferHeight() - 1, L" Hardware debugging tool ", 25);
		screen.SetCursorPosition(0, screen.getFrameBufferHeight() - 1);

		if (state == dsRunningPending || state == dsRunning)
		{
			screen.SelectBackColor(192, 192, 192);
		}
		else
		{
			screen.SelectBackColor(128, 128, 128);
		}
		screen.Write(L"1 Run    ");
		screen.SelectBackColor(0, 0, 0);
		screen.Write(L" ");

		if (state == dsStopped)
		{
			screen.SelectBackColor(192, 192, 192);
		}
		else
		{
			screen.SelectBackColor(128, 128, 128);
		}
		screen.Write(L"2 Pause  ");
		screen.SelectBackColor(0, 0, 0);
		screen.Write(L" ");

		if (state == dsStepOverPending || state == dsRunningOver)
		{
			screen.SelectBackColor(192, 192, 192);
		}
		else
		{
			screen.SelectBackColor(128, 128, 128);
		}
		screen.Write(L"3 Stp ovr");
		screen.SelectBackColor(0, 0, 0);
		screen.Write(L" ");

		if (state == dsStepIntoPending)
		{
			screen.SelectBackColor(192, 192, 192);
		}
		else
		{
			screen.SelectBackColor(128, 128, 128);
		}
		screen.Write(L"4 Stp in ");
		screen.SelectBackColor(0, 0, 0);
		screen.Write(L" ");

		if (state == dsStepOutPending || state == dsRunningOut)
		{
			screen.SelectBackColor(192, 192, 192);
			screen.SelectForeColor(0, 0, 0);
		}
		else if (flowLayers.size() > 1)
		{
			screen.SelectBackColor(128, 128, 128);
			screen.SelectForeColor(0, 0, 0);
		}
		else
		{
			screen.SelectBackColor(0, 0, 0);
			screen.SelectForeColor(128, 128, 128);
		}

		screen.Write(L"5 Stp out");
		screen.SelectBackColor(0, 0, 0);
		screen.Write(L" ");

		if (findBreakpointAt(entries[wSelectedLine].memPos) != breakpoints.end())
		{
			screen.SelectBackColor(192, 192, 192);
			screen.SelectForeColor(0, 0, 0);
		}
		else
		{
			screen.SelectBackColor(128, 128, 128);
			screen.SelectForeColor(0, 0, 0);
		}

		screen.Write(L"6 Breakpt");
		screen.SelectBackColor(0, 0, 0);
		screen.Write(L" ");

		screen.SelectForeColor(0, 0, 0);
		screen.SelectBackColor(128, 128, 128);
		screen.Write(L"7 Halt   ");

		screen.SelectBackColor(0, 0, 0);
		screen.Write(L" ");
		screen.SetCursorPosition(0, screen.getFrameBufferHeight() - 1);
	}
}
コード例 #2
0
void dWorldExportDIF (dWorldID w, FILE *file, const char *prefix)
{
    PrintingContext c;
    c.file = file;
#if defined(dSINGLE)
    c.precision = 7;
#else
    c.precision = 15;
#endif
    c.indent = 1;

    fprintf (file,"-- Dynamics Interchange Format v0.1\n\n%sworld = dynamics.world {\n",prefix);
    c.print ("gravity",w->gravity);
    c.print ("ODE = {");
    c.indent++;
    c.print ("ERP",w->global_erp);
    c.print ("CFM",w->global_cfm);
    c.print ("auto_disable = {");
    c.indent++;
    c.print ("linear_threshold",w->adis.linear_average_threshold);
    c.print ("angular_threshold",w->adis.angular_average_threshold);
    c.print ("average_samples",(int)w->adis.average_samples);
    c.print ("idle_time",w->adis.idle_time);
    c.print ("idle_steps",w->adis.idle_steps);
    fprintf (file,"\t\t},\n\t},\n}\n");
    c.indent -= 3;

    // bodies
    int num = 0;
    fprintf (file,"%sbody = {}\n",prefix);
    for (dxBody *b=w->firstbody; b; b=(dxBody*)b->next) {
        b->tag = num;
        fprintf (file,"%sbody[%d] = dynamics.body {\n\tworld = %sworld,\n",prefix,num,prefix);
        c.indent++;
        c.print ("pos",b->posr.pos);
        c.print ("q",b->q,4);
        c.print ("lvel",b->lvel);
        c.print ("avel",b->avel);
        c.print ("mass",b->mass.mass);
        fprintf (file,"\tI = {{");
        for (int i=0; i<3; i++) {
            for (int j=0; j<3; j++) {
                c.printReal (b->mass.I[i*4+j]);
                if (j < 2) fputc (',',file);
            }
            if (i < 2) fprintf (file,"},{");
        }
        fprintf (file,"}},\n");
        c.printNonzero ("com",b->mass.c);
        c.print ("ODE = {");
        c.indent++;
        if (b->flags & dxBodyFlagFiniteRotation) c.print ("finite_rotation",1);
        if (b->flags & dxBodyDisabled) c.print ("disabled",1);
        if (b->flags & dxBodyNoGravity) c.print ("no_gravity",1);
        if (b->flags & dxBodyAutoDisable) {
            c.print ("auto_disable = {");
            c.indent++;
            c.print ("linear_threshold",b->adis.linear_average_threshold);
            c.print ("angular_threshold",b->adis.angular_average_threshold);
            c.print ("average_samples",(int)b->adis.average_samples);
            c.print ("idle_time",b->adis.idle_time);
            c.print ("idle_steps",b->adis.idle_steps);
            c.print ("time_left",b->adis_timeleft);
            c.print ("steps_left",b->adis_stepsleft);
            c.indent--;
            c.print ("},");
        }
        c.printNonzero ("facc",b->facc);
        c.printNonzero ("tacc",b->tacc);
        if (b->flags & dxBodyFlagFiniteRotationAxis) {
            c.print ("finite_rotation_axis",b->finite_rot_axis);
        }
        c.indent--;
        c.print ("},");
        if (b->geom) {
            c.print ("geometry = {");
            c.indent++;
            for (dxGeom *g=b->geom; g; g=g->body_next) {
                c.print ("{");
                c.indent++;
                printGeom (c,g);
                c.indent--;
                c.print ("},");
            }
            c.indent--;
            c.print ("},");
        }
        c.indent--;
        c.print ("}");
        num++;
    }

    // joints
    num = 0;
    fprintf (file,"%sjoint = {}\n",prefix);
    for (dxJoint *j=w->firstjoint; j; j=(dxJoint*)j->next) {
        c.indent++;
        const char *name = getJointName (j);
        fprintf (file,
            "%sjoint[%d] = dynamics.%s_joint {\n"
            "\tworld = %sworld,\n"
            "\tbody = {"
            ,prefix,num,name,prefix);

        if ( j->node[0].body )
            fprintf (file,"%sbody[%d]",prefix,j->node[0].body->tag);
        if ( j->node[1].body )
            fprintf (file,",%sbody[%d]",prefix,j->node[1].body->tag);
        fprintf (file,"}\n");

        switch (j->type()) {
            case dJointTypeBall: printBall (c,j); break;
            case dJointTypeHinge: printHinge (c,j); break;
            case dJointTypeSlider: printSlider (c,j); break;
            case dJointTypeContact: printContact (c,j); break;
            case dJointTypeUniversal: printUniversal (c,j); break;
            case dJointTypeHinge2: printHinge2 (c,j); break;
            case dJointTypeFixed: printFixed (c,j); break;
            case dJointTypeAMotor: printAMotor (c,j); break;
            case dJointTypeLMotor: printLMotor (c,j); break;
            case dJointTypePR: printPR (c,j); break;
            case dJointTypePU: printPU (c,j); break;
            case dJointTypePiston: printPiston (c,j); break;
            default: c.print("unknown joint");
        }
        c.indent--;
        c.print ("}");
        num++;
    }
}
コード例 #3
0
ファイル: Debugger.cpp プロジェクト: bigfatbrowncat/Vintage
void Debugger::updateUI()
{
	pthread_mutex_lock(&printingMutex);
	if ((screen.isActive() && state == dsRunning) || state == dsStopped)
	{
		if (wSelectedLineFollowsFlow)
		{
			wSelectedLine = findLine(flow);
		}

		// *** Printing code ***

		if (activeWindow == dawCode)
		{
			screen.SelectForeColor(0, 0, 0);
			screen.SelectBackColor(192, 192, 192);
		}
		else
		{
			screen.SelectForeColor(192, 192, 192);
			screen.SelectBackColor(96, 96, 96);
		}
		printFixed(0, topSpace - 1, L" Code ", screen.getFrameBufferWidth());

		int code_lines = screen.getFrameBufferHeight() - topSpace;
		int up = code_lines / 2;
		int down = code_lines - up - 2;

		int prev_addr = 0;
		for (int i = down; i >= -up; i--)
		{
			int index = wSelectedLine/*findLine(flow)*/ + i;

			int y = topSpace + up + i;

			{
				int colorsCount = 0;
				int bgR = 0, bgG = 0, bgB = 0;
				int fgR = 0, fgG = 0, fgB = 0;

				if (i == 0)	// this line is selected now
				{
					bgR += 192; bgG += 192; bgB += 192;
					colorsCount++;
				}

				for (unsigned int i = 1; i < flowLayers.size(); i++)
				{
					int p = flowLayers.size() - i;
					if (entries[index].memPos == flowLayers[i].lastFlow)
					{
						bgR += 255 / pow(2.0, p);
						bgG += 192 / pow(2.0, p);
						bgB += 64 / pow(2.0, p);
						colorsCount ++;
					}
				}

				if (index == findLine(flow)) // flow is here
				{
					bgR += 255; bgG += 192; bgB += 64;
					colorsCount++;
				}

				if (findBreakpointAt(entries[index].memPos) != breakpoints.end()) // flow is here
				{
					bgR += 192; bgG += 32; bgB += 32;
					colorsCount++;
				}

				if (colorsCount > 0)
				{
					bgR /= colorsCount; bgG /= colorsCount; bgB /= colorsCount;
				}

				if (bgR < 64 && bgG < 64 && bgB < 64)
				{
					fgR = 128; fgG = 128; fgB = 128;
				}
				else
				{
					fgR = 0; fgG = 0; fgB = 0;
				}

				screen.SelectForeColor(fgR, fgG, fgB);
				screen.SelectBackColor(bgR, bgG, bgB);
			}

			wstringstream strs;
			if (index >= 0 && index < (int)entries.size() && entries[index].memPos != prev_addr)
			{
				strs << std::setw(8) << setfill(L'0') << std::hex << uppercase << entries[index].memPos << L" ";
				prev_addr = entries[index].memPos;
			}
			else
			{
				strs << L"         ";
			}
			printFixed(1, y, strs.str().c_str(), 9);


			{
				int colorsCount = 0;
				int bgR = 0, bgG = 0, bgB = 0;
				int fgR = 0, fgG = 0, fgB = 0;

				if (i == 0)	// this line is selected now
				{
					bgR += 192; bgG += 192; bgB += 192;
					colorsCount ++;
				}

				for (unsigned int i = 1; i < flowLayers.size(); i++)
				{
					int p = flowLayers.size() - i;
					if (entries[index].memPos == flowLayers[i].lastFlow)
					{
						bgR += 255 / pow(2.0, p);
						bgG += 192 / pow(2.0, p);
						bgB += 64 / pow(2.0, p);
						colorsCount ++;
					}
				}

				if (index == findLine(flow)) // flow is here
				{
					bgR += 255; bgG += 192; bgB += 64;
					colorsCount++;
				}

				if (findBreakpointAt(entries[index].memPos) != breakpoints.end()) // flow is here
				{
					bgR += 192; bgG += 32; bgB += 32;
					colorsCount++;
				}

				if (colorsCount > 0)
				{
					bgR /= colorsCount; bgG /= colorsCount; bgB /= colorsCount;
				}

				if (bgR < 64 && bgG < 64 && bgB < 64)
				{
					fgR = 192; fgG = 192; fgB = 192;
				}
				else
				{
					fgR = 0; fgG = 0; fgB = 0;
				}

				screen.SelectForeColor(fgR, fgG, fgB);
				screen.SelectBackColor(bgR, bgG, bgB);
			}

			wstringstream strs2;
			if (index >= 0 && index < (int)entries.size())
			{
				//printf("0x%X: %s\n", fl->mem_pos, fl->lines.c_str());
				strs2 << entries[index].codeLine << L"\n";
			}
			else
			{
				//printf("0x%X: <<No such address in debug symbols>>\n");
				wstringstream strs2;
				strs2 << L"<< No such address in debug symbols >>\n";
			}
			printFixed(10, y, strs2.str().c_str(), screen.getFrameBufferWidth() - 11);
		}

		printMenu();


		// ** Printing stack **

		int wStackWindowWidth = 9 + 3 * wStackBytes + wStackBytes + 2;

		if (activeWindow == dawStack)
		{
			screen.SelectForeColor(0, 0, 0);
			screen.SelectBackColor(192, 192, 192);
		}
		else
		{
			screen.SelectForeColor(192, 192, 192);
			screen.SelectBackColor(96, 96, 96);
		}
		printFixed(0, 0, L" Stack ", wStackWindowWidth);

		screen.SelectBackColor(0, 0, 0);

		for (int row = wStackTopRow; row < wStackTopRow + topSpace - 3; row++)
		{
			int stack_addr = row * wStackBytes;

			wstringstream strs;
			strs << std::setw(8) << setfill(L'0') << std::hex << uppercase << stack_addr << L" ";

			screen.SelectForeColor(128, 128, 128);
			printFixed(1, row - wStackTopRow + 1, strs.str().c_str(), 9);

			wstringstream strs2;
			wstringstream strs3;

			for (; stack_addr < (row + 1) * wStackBytes; stack_addr ++)
			{
				if (stack_addr < stackAllocatedSize)
				{
					unsigned char i1 = *((unsigned char*)(&stack[stack_addr]));

					//wstringstream strs;
					//strs << std::setw(2) << setfill(L'0') << std::hex << uppercase << i1 << " ";
					const wchar_t* hexchars = L"0123456789ABCDEF";
					wchar_t num[4];
					num[3] = 0;
					num[2] = L' ';
					num[1] = hexchars[i1 % 16];
					num[0] = hexchars[i1 / 16];

					wchar_t ch[2];
					if (i1 == 0)
					{
						ch[0] = ' ';
					}
					else
					{
						ch[0] = i1;
					}
					ch[1] = 0;

					screen.SelectForeColor(192, 192, 192);

					strs2 << num;
					strs3 << ch;
					//printFixed(9 + 1 + 3 * (stack_addr % wStackBytes), row - wStackTopRow + 1, num, 3);
					//printFixed(9 + 1 + wStackBytes * 3 + (stack_addr % wStackBytes), row - wStackTopRow + 1, ch, 1);

				}
				else
				{
					strs2 << L"   ";
					strs3 << L" ";

					//printFixed(9 + 1 + 3 * (stack_addr % wStackBytes), row - wStackTopRow + 1, L"   ", 3);
					//printFixed(9 + 1 + wStackBytes * 3 + (stack_addr % wStackBytes), row - wStackTopRow + 1, L" ", 1);
				}
			}

			strs2 << strs3.str();
			printFixed(9 + 1, row - wStackTopRow + 1, strs2.str().c_str(), wStackWindowWidth - 9);
		}

		// ** Printing heap **

		int wHeapWindowWidth = 2 + 9 + 3 * wHeapBytes + wHeapBytes;

		if (activeWindow == dawHeap)
		{
			screen.SelectForeColor(0, 0, 0);
			screen.SelectBackColor(192, 192, 192);
		}
		else
		{
			screen.SelectForeColor(192, 192, 192);
			screen.SelectBackColor(96, 96, 96);
		}
		printFixed(wStackWindowWidth + 2, 0, L" Heap ", wHeapWindowWidth);

		screen.SelectBackColor(0, 0, 0);

		for (int row = wHeapTopRow; row < wHeapTopRow + topSpace - 3; row++)
		{
			int heap_addr = row * wHeapBytes;

			wstringstream strs;
			strs << L" " << std::setw(8) << setfill(L'0') << std::hex << uppercase << heap_addr << L" ";

			screen.SelectForeColor(128, 128, 128);
			printFixed(wStackWindowWidth + 2, row - wHeapTopRow + 1, strs.str().c_str(), 9);

			wstringstream strs2;
			wstringstream strs3;

			for (; heap_addr < (row + 1) * wHeapBytes; heap_addr ++)
			{
				if (heap_addr < heapSize)
				{
					unsigned char i1 = *((unsigned char*)(&heap[heap_addr]));
					//wstringstream strs;
					//strs << std::setw(2) << setfill(L'0') << std::hex << uppercase << i1 << " ";
					const wchar_t* hexchars = L"0123456789ABCDEF";
					wchar_t num[4];
					num[3] = 0;
					num[2] = L' ';
					num[1] = hexchars[(i1 / 0x1)  & 0xF];
					num[0] = hexchars[(i1 / 0x10) & 0xF] ;

					wchar_t ch[2];
					if (i1 == 0)
					{
						ch[0] = ' ';
					}
					else
					{
						ch[0] = i1;
					}
					ch[1] = 0;

					screen.SelectForeColor(192, 192, 192);

					strs2 << num;
					strs3 << ch;
					//printFixed(wStackWindowWidth + 3 + 9 + 3 * (heap_addr % wHeapBytes), row - wHeapTopRow + 1, num, 3);
					//printFixed(wStackWindowWidth + 3 + 9 + wHeapBytes * 3 + (heap_addr % wHeapBytes), row - wStackTopRow + 1, ch, 1);
				}
				else
				{
					strs2 << L"   ";
					strs3 << L" ";
					//printFixed(wStackWindowWidth + 3 + 9 + 3 * (heap_addr % wHeapBytes), row - wHeapTopRow + 1, L"   ", 3);
					//printFixed(wStackWindowWidth + 3 + 9 + wHeapBytes * 3 + (heap_addr % wHeapBytes), row - wStackTopRow + 1, L" ", 1);
				}
			}

			strs2 << strs3.str();
			printFixed(wStackWindowWidth + 3 + 9, row - wHeapTopRow + 1, strs2.str().c_str(), wHeapWindowWidth - 9);
		}

	}
	pthread_mutex_unlock(&printingMutex);
}