vtkPolyData* Foam::vtkPV3Foam::patchVTKMesh
(
    const polyPatch& p
)
{
    vtkPolyData* vtkmesh = vtkPolyData::New();

    if (debug)
    {
        Info<< "<beg> Foam::vtkPV3Foam::patchVTKMesh - " << p.name() << endl;
        printMemory();
    }

    // Convert Foam mesh vertices to VTK
    const Foam::pointField& points = p.localPoints();

    vtkPoints *vtkpoints = vtkPoints::New();
    vtkpoints->Allocate( points.size() );
    forAll(points, i)
    {
        vtkPV3FoamInsertNextPoint(vtkpoints, points[i]);
    }
vtkPolyData* Foam::vtkPV4Foam::patchVTKMesh
(
    const word& name,
    const PatchType& p
)
{
    vtkPolyData* vtkmesh = vtkPolyData::New();

    if (debug)
    {
        Info<< "<beg> Foam::vtkPV4Foam::patchVTKMesh - " << name << endl;
        printMemory();
    }

    // Convert OpenFOAM mesh vertices to VTK
    const Foam::pointField& points = p.localPoints();

    vtkPoints* vtkpoints = vtkPoints::New();
    vtkpoints->Allocate(points.size());
    forAll(points, i)
    {
        vtkInsertNextOpenFOAMPoint(vtkpoints, points[i]);
    }
Ejemplo n.º 3
0
int executeUserCommand(char *assembly, char *bin, struct Processor *proc, char **tokens, int *breakPoints) {
  if (strcmp(tokens[0], "reg")==0) {
    tokens++;
    printReg(proc, tokens);
    return 0;
  } else if (strcmp(tokens[0], "mem")==0) {
    tokens++;
    printMemory(proc, tokens);
    return 0;
  } else if (strcmp(tokens[0], "pc")==0) {
    printPC(proc);
    return 0;
  } else if (strcmp(tokens[0], "search")==0) {
    tokens++;
    search(proc, tokens);
    return 0;
  } else if (strcmp(tokens[0], "stp")==0) {
    step(proc);
    return 0;
  } else if (strcmp(tokens[0], "list")==0) {
    listInstruction(assembly, ((proc->pc)/4)+1);
    return 0;
  } else if (strcmp(tokens[0], "--help")==0) {
    system("cat help.txt | less");
    return 0;
  } else if (strcmp(tokens[0], "run")==0) {
    run(proc,breakPoints);
    return 0;
  } else if (strcmp(tokens[0],"q")==0) {
    return confirmToQuit();
  } else if (strcmp(tokens[0],"break")==0) {
    setBreakPoints(breakPoints,tokens+1);
    return 0;
  }
  return 0;
}
Ejemplo n.º 4
0
/*
The main program
*/
int main()
{     
  int initBytes = 0;
  int numBytes = 0;
  int pid = 0;
  
  //Initialize memory and get rid of newline at the end
  scanf("%d", &initBytes);
  initializeMemory(initBytes);
  
  //Grab the command and call the appropiate method
  char c = getchar();
  while(c != EOF)
  {
    if(!isspace(c))
      printf("%c\n", c);
    if(c == 'A') //allocate
    {
      scanf("%d", &numBytes);
      scanf("%d", &pid);    
	  allocate(numBytes, pid);
    }
    else if(c == 'D') //deallocate
    {
      scanf("%d", &pid);
  	  deallocate(pid);
    }
    else if(c == 'P') //print memory
      printMemory();
	else if(isspace(c))
	  ; // do nothing but don't hit the else
	else
	  fprintf(stderr, "Invalid command, must be 'A' 'D' or 'P'");
	c = getchar();
  }
}
Ejemplo n.º 5
0
/**
 * Executes one instruction
 */
void clockTick(int sig) {
	//Uses bit manipulation to isolate all values
	int instruction = (instructionMemory[programCounter] >> 26) & 0x3f; //000111111
	int field1 = instructionMemory[programCounter] >> 21 & 0x01f;    //00000011111;
	int field2 = (instructionMemory[programCounter] >> 16) & 0x01f;  //0000000000011111;
	int field3 = (instructionMemory[programCounter] >> 11) & 0x01f;  //000000000000000011111;
	int field5 = instructionMemory[programCounter] & 0x03f;   	     //00000000000000000000000000111111; 
	int addressField = instructionMemory[programCounter] & 0x0000ffff; //00000000000000001111111111111111;
	int jType = instructionMemory[programCounter] & 0x03ffffff ; //00000011111111111111111111111111
	
	//Print Summary 
	printf("\nProgram Counter: %d op: %d  field1: %d  field2: %d field3 Register: %d address: %d\n", programCounter, instruction, registers[field1].value, registers[field2].value, field3, addressField);

	switch(instruction) { 
		//add or subtract			
		case 0: 	
			switch(field5) {
				//add					
				case 32:;
					int sum = registers[field1].value + registers[field2].value;
					changeRegisterValue(&registers[field3], sum); 			
					programCounter++;
					break;
				//subtract 
				case 34:;
					int difference = registers[field1].value - registers[field2].value;
					changeRegisterValue(&registers[field3], difference); 			
					programCounter++;
					break;
				//slt 
				case 42:;
					int lessThan = 0;
					if(registers[field1].value < registers[field2].value) {
						lessThan = 1;
					}
					changeRegisterValue(&registers[field3], lessThan); 
					programCounter++;
					break;
				//and 
				case 36:;
					int andValue = 0;
					if(registers[field1].value == 1 && registers[field2].value == 1) {
						andValue = 1;
					}
					changeRegisterValue(&registers[field3], andValue); 
					programCounter++;
					break;
				//end
				case 12:;
					flag = 1;  //call exit 
					break;		
			} 
			break;		
		//addi									
		case 8:;
			int sum = registers[field1].value + addressField; 
			changeRegisterValue(&registers[field2], sum);
			programCounter++;
			break;	
		//sw		
		case 43:;	
			int address1 = registers[field1].value + addressField;
			memory[address1] = registers[field2].value;
			programCounter++;
			break;
		//j
		case 2:;
			int moveTo = (jType-(4194304/4))-9;  //this could be off by 1
			programCounter = moveTo;				
			break;
		//beq
		case 4:;
			if(registers[field1].value == registers[field2].value) {
				programCounter = programCounter + addressField;
			} else {
				programCounter++;
			}
			break;
		//illegal operation 
		default:;
			flag = 1;
			break;				
	}
	printf("REGISTERS\n");
	printRegisters();
	printf("MEMORY\n");
	printMemory();	
	printf("\n");

	//Call next alarm
	alarm(1);
}
vtkUnstructuredGrid* Foam::vtkPV3Foam::volumeVTKMesh
(
    const fvMesh& mesh,
    polyDecomp& decompInfo
)
{
    const cellModel& tet = *(cellModeller::lookup("tet"));
    const cellModel& pyr = *(cellModeller::lookup("pyr"));
    const cellModel& prism = *(cellModeller::lookup("prism"));
    const cellModel& wedge = *(cellModeller::lookup("wedge"));
    const cellModel& tetWedge = *(cellModeller::lookup("tetWedge"));
    const cellModel& hex = *(cellModeller::lookup("hex"));

    vtkUnstructuredGrid* vtkmesh = vtkUnstructuredGrid::New();

    if (debug)
    {
        Info<< "<beg> Foam::vtkPV3Foam::volumeVTKMesh" << endl;
        printMemory();
    }

    const cellShapeList& cellShapes = mesh.cellShapes();

    // Number of additional points needed by the decomposition of polyhedra
    label nAddPoints = 0;

    // Number of additional cells generated by the decomposition of polyhedra
    label nAddCells = 0;

    // face owner is needed to determine the face orientation
    const labelList& owner = mesh.faceOwner();

    labelList& superCells = decompInfo.superCells();
    labelList& addPointCellLabels = decompInfo.addPointCellLabels();

    // Scan for cells which need to be decomposed and count additional points
    // and cells
    if (!reader_->GetUseVTKPolyhedron())
    {
        if (debug)
        {
            Info<< "... scanning for polyhedra" << endl;
        }

        forAll(cellShapes, cellI)
        {
            const cellModel& model = cellShapes[cellI].model();

            if
            (
                model != hex
             && model != wedge
             && model != prism
             && model != pyr
             && model != tet
             && model != tetWedge
            )
            {
                const cell& cFaces = mesh.cells()[cellI];

                forAll(cFaces, cFaceI)
                {
                    const face& f = mesh.faces()[cFaces[cFaceI]];

                    label nQuads = 0;
                    label nTris = 0;
                    f.nTrianglesQuads(mesh.points(), nTris, nQuads);

                    nAddCells += nQuads + nTris;
                }

                nAddCells--;
                nAddPoints++;
            }
        }
    }

    // Set size of additional point addressing array
    // (from added point to original cell)
    addPointCellLabels.setSize(nAddPoints);

    // Set size of additional cells mapping array
    // (from added cell to original cell)

    if (debug)
    {
        Info<<" mesh nCells     = " << mesh.nCells() << nl
            <<"      nPoints    = " << mesh.nPoints() << nl
            <<"      nAddCells  = " << nAddCells << nl
            <<"      nAddPoints = " << nAddPoints << endl;
    }

    superCells.setSize(mesh.nCells() + nAddCells);

    if (debug)
    {
        Info<< "... converting points" << endl;
    }

    // Convert OpenFOAM mesh vertices to VTK
    vtkPoints* vtkpoints = vtkPoints::New();
    vtkpoints->Allocate(mesh.nPoints() + nAddPoints);

    const Foam::pointField& points = mesh.points();

    forAll(points, i)
    {
        vtkInsertNextOpenFOAMPoint(vtkpoints, points[i]);
    }
Ejemplo n.º 7
0
void Foam::vtkPVFoam::convertMeshPatches
(
    vtkMultiBlockDataSet* output,
    int& blockNo
)
{
    arrayRange& range = arrayRangePatches_;
    range.block(blockNo);      // set output block
    label datasetNo = 0;       // restart at dataset 0
    const fvMesh& mesh = *meshPtr_;
    const polyBoundaryMesh& patches = mesh.boundaryMesh();

    if (debug)
    {
        Info<< "<beg> Foam::vtkPVFoam::convertMeshPatches" << endl;
        printMemory();
    }

    for (int partId = range.start(); partId < range.end(); ++partId)
    {
        if (!partStatus_[partId])
        {
            continue;
        }

        const word patchName = getPartName(partId);

        labelHashSet
            patchIds(patches.patchSet(List<wordRe>(1, wordRe(patchName))));

        if (debug)
        {
            Info<< "Creating VTK mesh for patches [" << patchIds <<"] "
                << patchName << endl;
        }

        vtkPolyData* vtkmesh = nullptr;
        if (patchIds.size() == 1)
        {
            vtkmesh = patchVTKMesh(patchName, patches[patchIds.begin().key()]);
        }
        else
        {
            // Patch group. Collect patch faces.
            label sz = 0;
            forAllConstIter(labelHashSet, patchIds, iter)
            {
                sz += patches[iter.key()].size();
            }
            labelList meshFaceLabels(sz);
            sz = 0;
            forAllConstIter(labelHashSet, patchIds, iter)
            {
                const polyPatch& pp = patches[iter.key()];
                forAll(pp, i)
                {
                    meshFaceLabels[sz++] = pp.start()+i;
                }
            }
            UIndirectList<face> fcs(mesh.faces(), meshFaceLabels);
            uindirectPrimitivePatch pp(fcs, mesh.points());

            vtkmesh = patchVTKMesh(patchName, pp);
        }


        if (vtkmesh)
        {
            AddToBlock(output, vtkmesh, range, datasetNo, patchName);
            vtkmesh->Delete();

            partDataset_[partId] = datasetNo++;
        }
    }
void Foam::vtkPV3Foam::convertMeshCellSets
(
    vtkMultiBlockDataSet* output
)
{
    if (debug)
    {
        Info<< "<beg> Foam::vtkPV3Foam::convertMeshCellSets" << endl;
        printMemory();
    }

    const selectionInfo& selector = selectInfoCellSets_;
    vtkDataArraySelection* arraySelection = reader_->GetRegionSelection();

    // Create the cell sets and add as dataset
    if (selector.size())
    {
        const fvMesh& mesh = *meshPtr_;

        for
        (
            int regionId = selector.start();
            regionId < selector.end();
            ++regionId)
        {
            if (!selectedRegions_[regionId])
            {
                continue;
            }

            word selectName = getFirstWord
            (
                arraySelection->GetArrayName(regionId)
            );

            if (debug)
            {
                Info<< "Creating VTK mesh for cellSet: " << selectName
                    << " region index: " << regionId << endl;
            }

            const cellSet cSet(mesh, selectName);
            fvMeshSubset subsetter
            (
                IOobject
                (
                    "set",
                    mesh.time().constant(),
                    mesh,
                    IOobject::NO_READ,
                    IOobject::NO_WRITE
                ),
                mesh
            );
            subsetter.setLargeCellSubset(cSet);

            const label datasetId = GetNumberOfDataSets(output, selector);

            vtkUnstructuredGrid* vtkmesh = vtkUnstructuredGrid::New();

            addVolumeMesh
            (
                subsetter.subMesh(),
                vtkmesh,
                csetSuperCells_[datasetId]
            );

            // renumber - superCells must contain global cell ids
            inplaceRenumber
            (
                subsetter.cellMap(),
                csetSuperCells_[datasetId]
            );

            AddToBlock
            (
                output, selector, datasetId, vtkmesh,
                selectName + ":cellSet"
            );
            selectedRegionDatasetIds_[regionId] = datasetId;
            vtkmesh->Delete();
        }
    }

    if (debug)
    {
        Info<< "<end> Foam::vtkPV3Foam::convertMeshCellSets" << endl;
        printMemory();
    }
}
Ejemplo n.º 9
0
int main(void) {
	irmemloc = (u32*) memalign(0x1000, 0x1000);
	resultStartup = IRU_Initialize(irmemloc, 0x1000);
	resultSetBit = IRU_SetBitRate(0xB);
	recordedIR = (u32*) malloc(REC_SIZE * NUM_OF_BUTTONS); //Currently there are 11(NUM_OF_BUTTONS) recordable buttons. (start switches mode)
	recentIR = (u32*) calloc(REC_SIZE, 0x1); //Whatever was last viewed in memory
	resultGetStatus = irucmd_GetTransferState(&StatusIR);
	srvInit();        // services
	aptInit();        // applets
	hidInit(NULL);    // input
	gfxInitDefault(); // gfx
	
	gfxSetDoubleBuffering(GFX_TOP, true);
	gfxSetDoubleBuffering(GFX_BOTTOM, true);
	bot = gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL);
	top = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);
	
	if(setjmp(exitJmp)) goto exit;
	
	clearScreen();
	gfxFlushBuffers();
	gfxSwapBuffers();
	
	bool startToggle = false;
	bool upToggle = false;
	bool downToggle = false;
	
	while(aptMainLoop()) {
		bot = gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL);
		top = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);
		hidScanInput();
		irrstScanInput();
		
		u32 kHeld = hidKeysHeld();
		circlePosition circlePad;
		circlePosition cStick;
		hidCstickRead(&cStick);
		hidCircleRead(&circlePad);
		touchPosition touch;
		touchRead(&touch);
		
		clearScreen();
		
		char keys[30] = "ABXY URDL SEST LR ZLZR";
		
		if(kHeld & KEY_A) {
			keys[0] = '*';
			ir('A');
		}
		if(kHeld & KEY_B) {
			keys[1] = '*';
			ir('B');
		}
		if(kHeld & KEY_X) {
			keys[2] = '*';
			ir('X');
		}
		if(kHeld & KEY_Y) {
			keys[3] = '*';
			ir('Y');
		}
		if(kHeld & KEY_DUP) {
			keys[5] = '*';
			if(upToggle) {
				if(bitrate < 18) {
					bitrate++;
					resultSetBit = IRU_SetBitRate(bitrate);
				}
				upToggle = false;
			}
		} else {
			upToggle = true;
		}
		if(kHeld & KEY_DRIGHT) {
			keys[6] = '*';
			ir('R');
		}
		if(kHeld & KEY_DDOWN) {
			keys[7] = '*';
			if(downToggle) {
				if(bitrate > 3) {
					bitrate--;
					resultSetBit = IRU_SetBitRate(bitrate);
				}
				downToggle = false;
			}
		} else {
			downToggle = true;
		}
		if(kHeld & KEY_DLEFT) {
			keys[8] = '*';
			ir('L');
		}
		if(kHeld & KEY_SELECT) {
			keys[10] = '*';
			keys[11] = '*';
			ir('S');
		}
		if(kHeld & KEY_START) {
			keys[12] = '*';
			keys[13] = '*';
			if(startToggle) {
				rec = !rec;
				startToggle = false;
			}
		} else {
			startToggle = true;
		}
		if(kHeld & KEY_L) {
			keys[15] = '*';
			ir('L');
		}
		if(kHeld & KEY_R) {
			keys[16] = '*';
			ir('R');
		}
		if(kHeld & KEY_ZL) {
			keys[18] = '*';
			keys[19] = '*';
			ir('1');
		}
		if(kHeld & KEY_ZR) {
			keys[20] = '*';
			keys[21] = '*';
			ir('2');
		}
		drawString(top, 10, 10, keys);
		drawString(top, 10, 20, "Circle Pad   x: %04+d, y: %04+d", circlePad.dx, circlePad.dy);
		drawString(top, 10, 30, "Touch        x: %04d, y: %04d", touch.px, touch.py );
		if(resultStartup == 0) {
			drawString(top, 10, 40, "IR started!");
		} else {
			drawString(top, 10, 40, "IR Init     |Error: %x", resultStartup);
		}
		if(resultSetBit == 0) {
			drawString(top, 10, 50, "IR bit rate works!");
		} else {
			drawString(top, 10, 50, "IR bit rate |Error: %x", resultSetBit);
		}
		if(resultTransferIR == 0) {
			drawString(top, 10, 60, "IR transfer works!");
		} else {
			drawString(top, 10, 60, "IR transfer |Error: %x", resultTransferIR);
		}
		irucmd_GetTransferState(&StatusIR);
		drawString(top, 10, 70, "IR mode: %x", StatusIR);
		drawString(top, 10, 80, "Got %d bytes", TransIR);
		drawString(top, 10, 90, "Bitrate: %d (see IRU:SetBitRate)", bitrate);
		printMemory(NULL,REC_SIZE,10, false); //might be dangerous?
		
		if(rec) {
			drawString(top, 10, 210, "Recording mode active.");
		}else{
			drawString(top, 10, 210, "Sending mode active.");
		}
		drawString(top, 10, 220, "Start + Select to exit.");
		
		if((kHeld & KEY_START) && (kHeld & KEY_SELECT)) longjmp(exitJmp, 1);
		gfxFlushBuffers();
		gspWaitForVBlank();
		gfxSwapBuffers();
	}
	
	exit: //I should really be fixing these.
	
	free(recordedIR); //Crashes the program. Should free on release.
	free(irmemloc); //Crashes the program. Should free on release.
	free(recentIR); //Crashes the program. Should free on release.
	
	IRU_Shutdown(); //Crashes the program. Should free on release.
	gfxExit();
	hidExit();
	aptExit();
	srvExit();
	
	return 0;
}
Ejemplo n.º 10
0
void Foam::vtkPV3Foam::convertMeshCellSets
(
    vtkMultiBlockDataSet* output,
    int& blockNo
)
{
    partInfo& selector = partInfoCellSets_;
    selector.block(blockNo);   // set output block
    label datasetNo = 0;       // restart at dataset 0
    const fvMesh& mesh = *meshPtr_;

    // resize for decomposed polyhedra
    csetPolyDecomp_.setSize(selector.size());

    if (debug)
    {
        Info<< "<beg> Foam::vtkPV3Foam::convertMeshCellSets" << endl;
        printMemory();
    }

    for (int partId = selector.start(); partId < selector.end(); ++partId)
    {
        const word partName = getPartName(partId);

        if (!partStatus_[partId])
        {
            continue;
        }

        if (debug)
        {
            Info<< "Creating VTK mesh for cellSet=" << partName << endl;
        }

        const cellSet cSet(mesh, partName);

        fvMeshSubset subsetMesh
        (
            IOobject
            (
                "set",
                mesh.time().constant(),
                mesh,
                IOobject::NO_READ,
                IOobject::NO_WRITE
            ),
            mesh
        );

        subsetMesh.setLargeCellSubset(cSet);

        vtkUnstructuredGrid* vtkmesh = volumeVTKMesh
        (
            subsetMesh.subMesh(),
            csetPolyDecomp_[datasetNo]
        );

        if (vtkmesh)
        {
            // superCells + addPointCellLabels must contain global cell ids
            inplaceRenumber
            (
                subsetMesh.cellMap(),
                csetPolyDecomp_[datasetNo].superCells()
            );
            inplaceRenumber
            (
                subsetMesh.cellMap(),
                csetPolyDecomp_[datasetNo].addPointCellLabels()
            );

            // copy pointMap as well, otherwise pointFields fail
            csetPolyDecomp_[datasetNo].pointMap() = subsetMesh.pointMap();

            AddToBlock(output, vtkmesh, selector, datasetNo, partName);
            vtkmesh->Delete();

            partDataset_[partId] = datasetNo++;
        }
    }

    // anything added?
    if (datasetNo)
    {
        ++blockNo;
    }

    if (debug)
    {
        Info<< "<end> Foam::vtkPV3Foam::convertMeshCellSets" << endl;
        printMemory();
    }
}
Ejemplo n.º 11
0
/*
 * function processes each command the user enters
 * returns 1 if step or continue
 * returns 0 on success
 * returns -1 on error
 */
int runCommand(char command[])
{
	char *name = strtok(command, " ");
	char *arg1, *arg2, *arg3;
	int arg1value, arg2value;
	struct address translatedAddr;
	if(strcmp(name,"help")==0 || strcmp(name,"h")==0)		//"help" to display all commands
	{
		printf("\n step / s\n\t Single step the exection\n\n");	
		printf(" continue / c\n\t Continue to next breakpoint \n\n");
		printf(" reg / r \n\t Prints the value of all registers \n\n");
		printf(" reg / r <register_name>  \n\t Prints the value of a particular register \n\n");
		printf(" reg / r <register_name1> <register_name2>  \n\t Prints the value of all registers from <register_name1> to <register_name2> \n\n");
		printf(" mem / m <page_num>  \n\t Displays contents of a memory page \n\n");
		printf(" mem / m <page_num1> <page_num2>  \n\t Displays contents of memory pages from <page_num1> to <page_num2>\n\n");
		printf(" pcb / p \n \t Displays the PCB with state as running \n\n");
		printf(" pcb / p <pid> \n\t Displays the <pid> th PCB \n\n");
		printf(" pagetable / pt \n \t Displays the page table at location pointed by PTBR \n\n");
		printf(" pagetable / pt <pid> \n\t Displays the <pid> th page table \n\n");
		printf(" filetable / ft \n \t Displays the System Wide Open File Table\n\n");
		printf(" memfreelist / mf \n \t Displays the Memory Free List\n\n");
		printf(" diskfreelist / df \n \t Displays the Memory copy of Disk Free List\n\n");
		printf(" fat \n \t Displays the Memory Copy of File Allocation Table\n\n");
		printf(" location / l <address> \n \t Displays the content at memory address (Translation takes place in USER mode)\n\n");
		printf(" watch / w <physical address> \n \t Sets a watch point at this address\n\n");
		printf(" watchclear / wc \n \t Clears all the watch points\n\n");
		printf(" exit / e \n\t Exit the interface and Halt the machine\n");
		printf(" help / h\n");
	}	
	else if (strcmp(name,"step") == 0 || strcmp(name,"s") == 0)	//Single Stepping
	{
		step_flag = ENABLE;
		return 1;		
	}
	else if (strcmp(name,"continue") == 0 || strcmp(name,"c") == 0)	//Continue till next breakpoint
	{
		step_flag = DISABLE;
		return 1;		
	}	
	else if (strcmp(name,"reg")==0 || strcmp(name,"r")==0) 	//Prints the registers.
	{
		arg1 = strtok(NULL, " ");
		arg2 = strtok(NULL, " ");	
		if(arg1 == NULL)
			printRegisters(R0, NUM_REGS-1);
		else if(arg2 == NULL)
		{
			arg1value = getRegArg(arg1);
			if(arg1value == -1)
			{
				printf("Illegal argument for \"%s\". See \"help\" for more information",name);
				return -1;
			}
			else
				printRegisters(arg1value,arg1value);
		}
		else
		{
			arg1value = getRegArg(arg1);
			arg2value = getRegArg(arg2);
			if(arg1value == -1 || arg2value == -1)
			{
				printf("Illegal argument for \"%s\". See \"help\" for more information",name);
				return -1;
			}
			else
			{
				if(arg1value > arg2value) 	//swap them
				{
					arg1value = arg1value + arg2value;
					arg2value = arg1value - arg2value;
					arg1value = arg1value - arg2value;
				}
				printRegisters(arg1value,arg2value);
			}
		}
	}	
	else if (strcmp(name,"mem")==0 || strcmp(name,"m")==0)	//displays pages in memory
	{
		arg1 = strtok(NULL, " ");
		arg2 = strtok(NULL, " ");
		if(arg1 == NULL)
		{
			printf("Insufficient argument for \"%s\". See \"help\" for more information",name);
			return -1;
		}
		else if(arg2 == NULL)
		{
			arg1value = atoi(arg1);
			if(arg1value >0 && arg1value < NUM_PAGES)
				printMemory(arg1value);
			else
			{
				printf("Illegal argument for \"%s\". See \"help\" for more information",name);
				return -1;
			}
		}
		else
		{
			arg1value = atoi(arg1);
			arg2value = atoi(arg2);
			if(arg1value > arg2value) 	//swap them
			{
				arg1value = arg1value + arg2value;
				arg2value = arg1value - arg2value;
				arg1value = arg1value - arg2value;
			}
			if(arg1value >0 && arg2value < NUM_PAGES)
			{
				while(arg1value <= arg2value)
				{
					printMemory(arg1value);
					arg1value++;
				}
			}
			else
			{
				printf("Illegal argument for \"%s\". See \"help\" for more information",name);
				return -1;
			}
		}	
	}						
	else if (strcmp(name,"pcb")==0 || strcmp(name,"p")==0)	//displays PCB of a process
	{
		arg1 = strtok(NULL, " ");
		if(arg1 == NULL)  //finds the PCB with state as running
		{
			int page_no, word_no;
			arg1value = 0;
			while(arg1value < NUM_PCB)
			{
				page_no = (READY_LIST + arg1value * PCB_ENTRY + 1) / PAGE_SIZE;
				word_no = (READY_LIST + arg1value * PCB_ENTRY + 1) % PAGE_SIZE;
				if(getInteger(page[page_no].word[word_no]) == STATE_RUNNING)
					break;
				arg1value++;
			}
			if(arg1value == NUM_PCB)
			{
				printf("No PCB found with state as running");
				return -1;
			}
		}
		else
		{
			arg1value = atoi(arg1);
			if(arg1value<0 || arg1value >=NUM_PCB)
			{
				printf("Illegal argument for \"%s\". See \"help\" for more information",name);
				return -1;
			}
		}
		printPCB(arg1value);
	}
	else if (strcmp(name,"pagetable")==0 || strcmp(name,"pt")==0)	//displays Page Table of a process
	{
		arg1 = strtok(NULL, " ");
		if(arg1 == NULL)  //finds the page table using PTBR
		{
			int page_no, word_no;
			arg1value = getInteger(reg[PTBR_REG]);
			if(arg1value < PAGE_TABLE || arg1value > (PAGE_TABLE + ((NUM_PCB-1)*NUM_PAGE_TABLE*PAGE_TABLE_ENTRY)) )
			{
				printf("Illegal PTBR value");
				return -1;
			}
		}
		else
		{			
			if(atoi(arg1) < 0 || atoi(arg1) >= NUM_PCB )
			{
				printf("Illegal argument for \"%s\". See \"help\" for more information",name);
				return -1;
			}
			arg1value = PAGE_TABLE + atoi(arg1) * (PAGE_TABLE_ENTRY * NUM_PAGE_TABLE);
		}
		printPageTable(arg1value);
	}
	else if (strcmp(name,"filetable")==0 || strcmp(name,"ft")==0)	//displays System Wide Open File Table
		printFileTable();
	else if (strcmp(name,"memfreelist")==0 || strcmp(name,"mf")==0)	//displays Memory Free Lisk
		printMemFreeList();
	else if (strcmp(name,"diskfreelist")==0 || strcmp(name,"df")==0)	//displays Disk Free List
		printDiskFreeList();
	else if (strcmp(name,"fat")==0)	//displays File Allocation Table
		printFAT();
	else if (strcmp(name,"location")==0 || strcmp(name,"l")==0 )	//displays a content of a memory location
	{
		arg1 = strtok(NULL, " ");
		if(arg1 == NULL) 
		{
			printf("Insufficient argument for \"%s\". See \"help\" for more information",name);
			return -1;
		}
		translatedAddr = translate_debug(atoi(arg1));
		if(getType(arg1) == TYPE_STR || (translatedAddr.page_no == -1 && translatedAddr.word_no == -1) )
		{
			printf("Illegal argument for \"%s\". See \"help\" for more information",name);
			return -1;
		}
		printLocation(translatedAddr);
	}
	else if (strcmp(name,"watch")==0 || strcmp(name,"w")==0 )	//Sets watch point to a memory location
	{
		arg1 = strtok(NULL, " ");
		if(arg1 == NULL) 
		{
			printf("Insufficient argument for \"%s\". See \"help\" for more information",name);
			return -1;
		}
		if( getType(arg1) == TYPE_STR || atoi(arg1) < 0 || atoi(arg1) >= SIZE_OF_MEM )
		{
			printf("Illegal argument for \"%s\". See \"help\" for more information",name);
			return -1;
		}
		if( watch_count >= NUM_WATCH)
		{
			printf("You have already used %d watch points. No more watch points can be set.\nUse \"watchclear\" to clear all watch points. \n", NUM_WATCH );
			return -1;
		}
		watch[watch_count].addr.page_no = atoi(arg1) / PAGE_SIZE;
		watch[watch_count].addr.word_no = atoi(arg1) % PAGE_SIZE;
		strcpy(watch[watch_count].value, page[watch[watch_count].addr.page_no].word[watch[watch_count].addr.word_no]);
		watch_count++;
		printf("Watch point %d set.\n",watch_count);
	}
	else if (strcmp(name,"watchclear")==0 || strcmp(name,"wc")==0 )	//Clears all watch points
	{
		initialize_Watch();
		printf("All watch points cleared.\n");
	}
	else if (strcmp(name,"exit")==0 || strcmp(name,"e")==0)		//Exits the interface
		exit(0);
	else
	{
		printf("Unknown command \"%s\". See \"help\" for more information",name);
		return -1;
	}
	return 0;
}
Ejemplo n.º 12
0
void Foam::vtkPV3Foam::convertMeshCellZones
(
    vtkMultiBlockDataSet* output,
    int& blockNo
)
{
    arrayRange& range = arrayRangeCellZones_;
    range.block(blockNo);      // set output block
    label datasetNo = 0;       // restart at dataset 0
    const fvMesh& mesh = *meshPtr_;

    // resize for decomposed polyhedra
    zonePolyDecomp_.setSize(range.size());

    if (range.empty())
    {
        return;
    }

    if (debug)
    {
        Info<< "<beg> Foam::vtkPV3Foam::convertMeshCellZones" << endl;
        printMemory();
    }

    const cellZoneMesh& zMesh = mesh.cellZones();
    for (int partId = range.start(); partId < range.end(); ++partId)
    {
        const word zoneName = getPartName(partId);
        const label  zoneId = zMesh.findZoneID(zoneName);

        if (!partStatus_[partId] || zoneId < 0)
        {
            continue;
        }

        if (debug)
        {
            Info<< "Creating VTK mesh for cellZone[" << zoneId << "] "
                << zoneName << endl;
        }

        fvMeshSubset subsetter(mesh);
        subsetter.setLargeCellSubset(zMesh[zoneId]);

        vtkUnstructuredGrid* vtkmesh = volumeVTKMesh
                                       (
                                           subsetter.subMesh(),
                                           zonePolyDecomp_[datasetNo]
                                       );

        if (vtkmesh)
        {
            // superCells + addPointCellLabels must contain global cell ids
            inplaceRenumber
            (
                subsetter.cellMap(),
                zonePolyDecomp_[datasetNo].superCells()
            );
            inplaceRenumber
            (
                subsetter.cellMap(),
                zonePolyDecomp_[datasetNo].addPointCellLabels()
            );

            // copy pointMap as well, otherwise pointFields fail
            zonePolyDecomp_[datasetNo].pointMap() = subsetter.pointMap();

            AddToBlock(output, vtkmesh, range, datasetNo, zoneName);
            vtkmesh->Delete();

            partDataset_[partId] = datasetNo++;
        }
    }

    // anything added?
    if (datasetNo)
    {
        ++blockNo;
    }

    if (debug)
    {
        Info<< "<end> Foam::vtkPV3Foam::convertMeshCellZones" << endl;
        printMemory();
    }
}
void Foam::vtkPV3Foam::convertMeshPointSets
(
    vtkMultiBlockDataSet* output
)
{
    if (debug)
    {
        Info<< "<beg> Foam::vtkPV3Foam::convertMeshPointSets" << endl;
        printMemory();
    }

    const selectionInfo& selector = selectInfoPointSets_;
    vtkDataArraySelection* arraySelection = reader_->GetRegionSelection();

    // Create the point sets and add as dataset
    if (selector.size())
    {
        const fvMesh& mesh = *meshPtr_;

        for
        (
            int regionId = selector.start();
            regionId < selector.end();
            ++regionId
        )
        {
            if (!selectedRegions_[regionId])
            {
                continue;
            }

            word selectName = getFirstWord
            (
                arraySelection->GetArrayName(regionId)
            );


            if (debug)
            {
                Info<< "Creating VTK mesh for pointSet: " << selectName
                    << " region index: " << regionId << endl;
            }

            const pointSet pSet(mesh, selectName);

            const label datasetId = GetNumberOfDataSets(output, selector);

            vtkPolyData* vtkmesh = vtkPolyData::New();
            addPointSetMesh
            (
                mesh,
                pSet,
                vtkmesh
            );
            AddToBlock
            (
                output, selector, datasetId, vtkmesh,
                selectName + ":pointSet"
            );
            selectedRegionDatasetIds_[regionId] = datasetId;
            vtkmesh->Delete();
        }
    }

    if (debug)
    {
        Info<< "<end> Foam::vtkPV3Foam::convertMeshPointSets" << endl;
        printMemory();
    }
}
void Foam::vtkPV3Foam::convertMeshPointZones
(
    vtkMultiBlockDataSet* output
)
{
    if (debug)
    {
        Info<< "<beg> Foam::vtkPV3Foam::convertMeshPointZones" << endl;
        printMemory();
    }

    const selectionInfo& selector = selectInfoPointZones_;
    const fvMesh& mesh = *meshPtr_;

    // Create the point sets and add as dataset
    if (selector.size())
    {
        const pointZoneMesh& pzMesh = mesh.pointZones();

        // use the zoneId directly instead of the name
        for (int zoneI=0; zoneI < selector.size(); ++zoneI)
        {
            const int regionId = selector.start() + zoneI;

            if (!selectedRegions_[regionId])
            {
                continue;
            }

            if (debug)
            {
                Info<< "Creating VTK mesh for pointZone: "
                    << zoneI << endl;
            }

            const label datasetId = GetNumberOfDataSets(output, selector);

            vtkPolyData* vtkmesh = vtkPolyData::New();

            addPointZoneMesh
            (
                mesh,
                pzMesh[zoneI],
                vtkmesh
            );

            AddToBlock
            (
                output, selector, datasetId, vtkmesh,
                pzMesh.names()[zoneI] + ":pointZone"
            );
            selectedRegionDatasetIds_[regionId] = datasetId;
            vtkmesh->Delete();
        }
    }

    if (debug)
    {
        Info<< "<end> Foam::vtkPV3Foam::convertMeshPointZones" << endl;
        printMemory();
    }
}
Ejemplo n.º 15
0
int main(){
    pcap_t *pt;
    char *dev;
    char errbuf[128];
    struct bpf_program fp;
    bpf_u_int32 maskp,netp;
    int ret,i=0,inum;
    int pcap_time_out=5;
    char filter[128];
    unsigned char *packet;
    struct pcap_pkthdr hdr;
    pcap_if_t *alldevs = NULL,*d;
    pid_t pid;
    char ch[10],str = 'n';
    attHead att_head;

    head = init_ip_list(head);
    att_head = init_attHead();
    if(pcap_findalldevs(&alldevs,errbuf)==-1) {
	fprintf(stderr,"find interface failed!\n");
	return;
    }
    for(d=alldevs;d;d=d->next){
	printf("%d. %s\n",++i,d->name);
      	if(d->description)
	    printf("(%s)\n",d->description);
      	else
	    printf("(no description available)\n");
    }
 
    if(i==1)
       	dev=alldevs->name;
    else {
      	printf("input a interface:(1-%d)",i);
      	scanf("%d",&inum);
      	if(inum<1||inum>i) {
	    printf("interface number out of range\n");
	    return;
      	}
       	for(d=alldevs,i=1;i<inum;d=d->next,i++);
	dev=d->name;
    }

    printf("dev:%s\n",dev);
    ret=pcap_lookupnet(dev,&netp,&maskp,errbuf);
    printf("");

    if(ret==-1){
      	fprintf(stderr,"%s\n",errbuf);
      	return;
    }
    pt=pcap_open_live(dev,BUFSIZ,1,pcap_time_out,errbuf);

    if(pt==NULL){
      	fprintf(stderr,"open error :%s\n",errbuf);
      	return;
    }

while(1) {
    printf("if you want to quit press y,else press any other key!\n");
    scanf("%c",&str);
    if(str == 'y')break;
  pid = vfork();
  if(pid < 0){
      printf("fail to fork\n");
  }else if(pid == 0){
      if(signal(SIGALRM,timer_handler) == SIG_ERR){
	  perror("can't set handler for SIGALRM\n");
	  exit(0);
      }
      alarm(1);
      while(1){
      packet=(char *)pcap_next(pt,&hdr);
      if(packet==NULL) continue;
      else{
         printf("\n\n\n");
   	 printf("get a packet\n");
   	 ethernet_packet_callback(NULL,&hdr,packet); 
	 num++;
   	 printf("\n");
	 if(flag == arp){
	     init_data(att_head,num,"arp","xxxxxxxx","broadcast");
	     printMemory(att_head);
	     flag = 0;
	 }
	 else{
	     switch(flag){
		 case ip:
		     strcpy(ch,"ip");break;
		 case tcp:
		     strcpy(ch,"tcp");break;
		 case udp:
		     strcpy(ch,"udp");break;
		 case http:
		     strcpy(ch,"http");break;
		 case oicq:
		     strcpy(ch,"oicq");break;
		 case webqq:
		     strcpy(ch,"webqq");break;
		 case msnms:
		     strcpy(ch,"msnms");break;
		 default:
		     strcpy(ch,"xxx");
		     strcpy(srcip,"xxxxxxxx");
		     strcpy(desip,"xxxxxxxx");
		     other_num++;
		     other_bytes = other_bytes+hdr.len;
		     break;
	     }
		 init_data(att_head,num,ch,srcip,desip);
		 printMemory(att_head);
	         flag = 0;
	 }
     }
  	printf("\n");
	printf("其他包的总数:%d   其他包的总字节数:%ld\n",other_num,other_bytes);
  	printf("ip包的总数:%d   ip包的总字节数:%ld\n",ip_num,ip_bytes);
  	printf("arp包的总数:%d   arp包的总字节数:%ld\n",arp_num,arp_bytes);
  	printf("tcp包的总数:%d   tcp包的总字节数:%ld\n",tcp_num,tcp_bytes);
  	printf("udp包的总数:%d   udp包的总字节数:%ld\n",udp_num,udp_bytes);
  	printf("oicq包的总数:%d   oicq包的总字节数:%ld\n",oicq_num,oicq_bytes);
	printf("http包的总数:%d   http包的总字节数: %ld\n",http_num,http_bytes);
	printf("web qq包的总数:%d   web qq包的总字节数: %ld\n",webqq_num,webqq_bytes);
	printf("msnms包的总数:%d   msnms包的总字节数: %ld\n",msnms_num,msnms_bytes);
	display_ip_list(head);
      }
  } else{
      delete_ip_list(head,1);
      if(wait(NULL) == -1){
      	printf("fail to wait\n");
      	exit(1);
      }
   }
 }
 pcap_close(pt);
 saveTable(att_head);
 free_ip_list(head);
 free_data(att_head);
 return 0;
/*
 pt = pcap_open_offline("msn.pcap",errbuf);
 if(pt == NULL){
     printf("ERROR:could not open pcap file: %s\n",errbuf);
     exit(-1);
 }
 pcap_loop(pt,-1,&ethernet_packet_callback,NULL);
 pcap_close(pt);
 return 0;*/
}
Ejemplo n.º 16
0
/** Handle s2e_op instruction. Instructions:
    0f 3f XX XX XX XX XX XX XX XX
    XX: opcode
 */
void BaseInstructions::handleBuiltInOps(S2EExecutionState* state, uint64_t opcode)
{
    switch((opcode>>8) & 0xFF) {
        case 0: { /* s2e_check */
                uint32_t v = 1;
                state->writeCpuRegisterConcrete(CPU_OFFSET(regs[R_EAX]), &v, 4);
            }
            break;
        case 1: state->enableSymbolicExecution(); break;
        case 2: state->disableSymbolicExecution(); break;

        case 3: { /* s2e_make_symbolic */
            makeSymbolic(state, false);
            break;
        }

        case 4: { /* s2e_is_symbolic */
            isSymbolic(state);
            break;
        }

        case 5: { /* s2e_get_path_id */
            state->writeCpuRegister(offsetof(CPUX86State, regs[R_EAX]),
                klee::ConstantExpr::create(state->getID(), klee::Expr::Int32));
            break;
        }

        case 6: { /* s2e_kill_state */
            killState(state);
            break;
            }

        case 7: { /* s2e_print_expression */
            printExpression(state);
            break;
        }

        case 8: { //Print memory contents
            printMemory(state);
            break;
        }

        case 9:
            state->enableForking();
            break;

        case 10:
            state->disableForking();
            break;

        case 0x10: { /* s2e_print_message */
            printMessage(state, opcode >> 16);
            break;
        }

        case 0x11: { /* s2e_make_concolic */
            makeSymbolic(state, true);
            break;
        }

        case 0x20: /* concretize */
            concretize(state, true);
            break;

        case 0x21: { /* replace an expression by one concrete example */
            concretize(state, false);
            break;
        }

        case 0x30: { /* Get number of active states */
            uint32_t count = s2e()->getExecutor()->getStatesCount();
            state->writeCpuRegisterConcrete(CPU_OFFSET(regs[R_EAX]), &count, sizeof(uint32_t));
            break;
        }

        case 0x31: { /* Get number of active S2E instances */
            uint32_t count = s2e()->getCurrentProcessCount();
            state->writeCpuRegisterConcrete(CPU_OFFSET(regs[R_EAX]), &count, sizeof(uint32_t));
            break;
        }
        case 0x32: { /* Sleep for a given number of seconds */
           sleep(state);
           break;
        }

        case 0x50: { /* disable/enable timer interrupt */
            uint64_t disabled = opcode >> 16;
            if(disabled)
                s2e()->getMessagesStream(state) << "Disabling timer interrupt\n";
            else
                s2e()->getMessagesStream(state) << "Enabling timer interrupt\n";
            state->writeCpuState(CPU_OFFSET(timer_interrupt_disabled),
                                 disabled, 8);
            break;
        }
        case 0x51: { /* disable/enable all apic interrupts */
            uint64_t disabled = opcode >> 16;
            if(disabled)
                s2e()->getMessagesStream(state) << "Disabling all apic interrupt\n";
            else
                s2e()->getMessagesStream(state) << "Enabling all apic interrupt\n";
            state->writeCpuState(CPU_OFFSET(all_apic_interrupts_disabled),
                                 disabled, 8);
            break;
        }

        case 0x52: { /* Gets the current S2E memory object size (in power of 2) */
                uint32_t size = S2E_RAM_OBJECT_BITS;
                state->writeCpuRegisterConcrete(CPU_OFFSET(regs[R_EAX]), &size, 4);
                break;
        }

        case 0x70: /* merge point */
            state->jumpToSymbolicCpp();
            s2e()->getExecutor()->queueStateForMerge(state);
            break;

        default:
            s2e()->getWarningsStream(state)
                << "BaseInstructions: Invalid built-in opcode " << hexval(opcode) << '\n';
            break;
    }
}
void interpretPrompt(References* r, CPUStatus* cpu, int* status)
{
    // show prompt ready
    printf("> ");
    fflush(stdout);

    // get new command
    char* line = (char*) calloc(MAX_STRING_LENGTH, sizeof(char));
    if (line == NULL)
    {
        perror("calloc error in interpretPrompt\n");
        exit(EXIT_FAILURE);
    }
    if (fgets(line, MAX_STRING_LENGTH, stdin) == NULL)
    {
        perror("fgets error in interpretPrompt\n");
        exit(EXIT_FAILURE);
    }

    // remove endline
    removeEndLine(line);

    int assembleCode = 0;

    // interpreter commands
    if (stringEquals(line, "regs") == 0)
    {
        printRegisters(cpu);
        *status = RUN_COMMAND;
        free(line);
        return;
    } else if (stringEquals(line, "mem") == 0)
    {
        printMemory(cpu);
        *status = RUN_COMMAND;
        free(line);
        return;
    } else if (stringEquals(line, "exit") == 0)
    {
        *status = EXECUTE_HALT;
        free(line);
        return;
    } else if (stringEquals(line, "show") == 0)
    {
        printInstructions(r);
        *status = RUN_COMMAND;
        free(line);
        return;
    } else
    {
        // assemble One Pass
        assembleCode = onePass(r, cpu, line);
    }

    // execute interpreter
    if (assembleCode == ASSEMBLE_OK ||
        (assembleCode == ASSEMBLE_LABEL && r->currentAddress > 4))
    {
        interpret(r, cpu, status);
    }

    free(line);
}
Ejemplo n.º 18
0
void Foam::vtkPV3Foam::convertMeshFaceZones
(
    vtkMultiBlockDataSet* output,
    int& blockNo
)
{
    partInfo& selector = partInfoFaceZones_;
    selector.block(blockNo);   // set output block
    label datasetNo = 0;       // restart at dataset 0
    const fvMesh& mesh = *meshPtr_;

    if (!selector.size())
    {
        return;
    }

    if (debug)
    {
        Info<< "<beg> Foam::vtkPV3Foam::convertMeshFaceZones" << endl;
        printMemory();
    }

    const faceZoneMesh& zMesh = mesh.faceZones();
    for (int partId = selector.start(); partId < selector.end(); ++partId)
    {
        const word zoneName = getPartName(partId);
        const label  zoneId = zMesh.findZoneID(zoneName);

        if (!partStatus_[partId] || zoneId < 0)
        {
            continue;
        }

        if (debug)
        {
            Info<< "Creating VTKmesh for faceZone[" << zoneId << "] "
                << zoneName << endl;
        }

        vtkPolyData* vtkmesh = faceZoneVTKMesh(mesh, zMesh[zoneId]);
        if (vtkmesh)
        {
            AddToBlock(output, vtkmesh, selector, datasetNo, zoneName);
            vtkmesh->Delete();

            partDataset_[partId] = datasetNo++;
        }
    }

    // anything added?
    if (datasetNo)
    {
        ++blockNo;
    }

    if (debug)
    {
        Info<< "<end> Foam::vtkPV3Foam::convertMeshFaceZones" << endl;
        printMemory();
    }
}
void printARM (ARM* arm) {
	printRegisters(arm);
	printMemory(arm);
}
Ejemplo n.º 20
0
int main(int argc, char *argv[]) {
	// A201860038A00798E903A818A9028501A60165008501860088D0F5
	// const char program[] = { 0xC8, 0x20, 0x00, 0x00 };
	// const char program[] = { 0xA2, 0x01, 0x86, 0x00, 0x38, 0xA0, 0x07, 0x98, 0xE9, 0x03, 0xA8, 0x18, 0xA9, 0x02, 0x85, 0x01, 0xA6, 0x01, 0x65, 0x00, 0x85, 0x01, 0x86, 0x00, 0x88, 0xD0, 0xF5 };

	if(argc != 2) {
		printf("Usage: %s program \n", argv[0]);
		return -1;
	}

	char *program;
	int program_length = readFileBytes(argv[1], &program);

	printf("Program (%i bytes): \n", program_length);

	int i;
	for(i = 0; i < program_length; i++) {
		printf("%i:%02X ", i, (unsigned char)program[i]);
	}

	printf("\n");

	CPU cpu;
	initializeCPU(&cpu);

	cpu.pc = 0x4000;
	writeMemory(&cpu, program, cpu.pc, program_length);
	// cpu.pc += 559; // 700 // 799
	// cpu.pc += 799; // test 06
	// cpu.pc += 1192; // test 09

	// char *buf = malloc(sizeof(char) * 2);
	// buf[0] = 0xC0;
	// buf[1] = 0x01;
	// writeMemory(&cpu, buf, 0x0105, 2);

	// cpu.ps = 0x1;

	// cpu.a = 0x7;
	// cpu.x = 0x2;
	// cpu.y = 0x3;

	// char *buf2 = malloc(sizeof(char) * 2);
	// buf2[0] = 0x08;
	// buf2[1] = 0xEE;
	// writeMemory(&cpu, buf2, 0x0105, 2);

	// printf("cpu->ps: %i\n", cpu.ps);
	// printf("cpu->sp: %i\n", cpu.sp);

	char str[1];
	// int i;

	for(;;) {
		printf("cpu->pc: %i\n", cpu.pc);
		// scanf("%s", str);
		step(&cpu);
		printMemory(&cpu);
		printf("\n\n\n");
		printf("cpu->sp: %x\n", cpu.sp);
		printf("cpu->a: %x\n", cpu.a);
		printf("cpu->x: %x\n", cpu.x);
		printf("cpu->y: %x\n", cpu.y);
		printf("cpu->ps: %x\n\n", cpu.ps);

		if(cpu.pc == 17825) {
			break;
		}
	}

	printMemory(&cpu);

	printf("### results:\n");
	printf("cpu->sp: %x\n", cpu.sp);
	printf("cpu->a: %x\n", cpu.a);
	printf("cpu->x: %x\n", cpu.x);
	printf("cpu->y: %x\n", cpu.y);
	printf("cpu->ps: %x\n", cpu.ps);
	printf("cpu->cycles: %i\n", cpu.cycles);
	// printf("%s\n", );
	// printbitssimple(cpu.ps);	
	printf("MEMORY 9: %x\n", *cpu.memory[0x80]);
	printf("MEMORY final: %x\n", *cpu.memory[0x0210]);

	freeCPU(&cpu);

	return 0;
}
void Foam::vtkPV3Foam::convertMeshCellZones
(
    vtkMultiBlockDataSet* output
)
{
    if (debug)
    {
        Info<< "<beg> Foam::vtkPV3Foam::convertMeshCellZones" << endl;
        printMemory();
    }

    const selectionInfo& selector = selectInfoCellZones_;
    const fvMesh& mesh = *meshPtr_;

    // Create the cell zone(s) and add as DataSet(CELLZONE, 0..n)
    if (selector.size())
    {
        const cellZoneMesh& czMesh = mesh.cellZones();

        // use the zoneId directly instead of the name
        for (int zoneI=0; zoneI < selector.size(); ++zoneI)
        {
            const int regionId = selector.start() + zoneI;

            if (!selectedRegions_[regionId])
            {
                continue;
            }

            if (debug)
            {
                Info<< "Creating VTK mesh for cellZone: "
                    << zoneI << endl;
            }

            fvMeshSubset subsetter
            (
                IOobject
                (
                    "set",
                    mesh.time().constant(),
                    mesh,
                    IOobject::NO_READ,
                    IOobject::NO_WRITE
                ),
                mesh
            );

            subsetter.setLargeCellSubset(labelHashSet(czMesh[zoneI]));

            const label datasetId = GetNumberOfDataSets(output, selector);

            vtkUnstructuredGrid* vtkmesh = vtkUnstructuredGrid::New();

            addVolumeMesh
            (
                subsetter.subMesh(),
                vtkmesh,
                zoneSuperCells_[datasetId]
            );

            // renumber - superCells must contain global cell ids
            inplaceRenumber
            (
                subsetter.cellMap(),
                zoneSuperCells_[datasetId]
            );

            AddToBlock
            (
                output, selector, datasetId, vtkmesh,
                czMesh.names()[zoneI] + ":cellZone"
            );
            selectedRegionDatasetIds_[regionId] = datasetId;
            vtkmesh->Delete();
        }
    }

    if (debug)
    {
        Info<< "<end> Foam::vtkPV3Foam::convertMeshCellZones" << endl;
        printMemory();
    }
}