void runSimulation(int argc, char **argv) {
    FILE *traceFile;
    
    /*create the page table and initialize it*/
    PAGETABLE *pageTable = calloc(1, sizeof(PAGETABLE));
    pageTable->levelCount = levelCount;
    int offsetBits = ADDRESS_LENGTH - initializePageTable(pageTable, argv, (argc - levelCount));
    
    p2AddrTr trace;     //this struct contains address when fetched from trace file
    if ((traceFile = fopen(argv[argc-levelCount-1],"rb")) == NULL) {
        fprintf(stderr,"cannot open %s for reading\n",argv[argc-levelCount-1]);
        exit(1);
    }
    
    unsigned long addressCount = 0;
    while (!feof(traceFile)) {
        if (nFlag)
            if (addressCount >= limit)      //break out of loop if limit is reached
                break;
        if (NextAddress(traceFile, &trace)) {
            unsigned int address = (unsigned int)trace.addr;
            if (pageLookup(pageTable, address) == NULL) {   //Page has not been seen yet
                pageTable->misses++;
                pageInsert(pageTable, address, pageTable->frameCount);  //insert the new page
                if (pFlag) {
                    unsigned int page = address;
                    page >>= offsetBits;
                    MAP *map = pageLookup(pageTable, address);
                    fprintf(printFile, "%08X -> %08X\n", page, map->frame);
                }
            }
            else
Exemplo n.º 2
0
void CCodeWin::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
{
	int increment=0;

	CFrameWnd::OnVScroll(nSBCode, nPos, pScrollBar);

	switch(nSBCode)
	{
		case SB_LINEUP:
			increment=-1;
			break;
		case SB_LINEDOWN:
			increment=1;
			break;
		case SB_PAGEUP:
			increment=-(mLineCount-1);
			break;
		case SB_PAGEDOWN:
			increment=mLineCount-1;
			break;
		case SB_BOTTOM:
			increment=mMemorySize;
			break;
		case SB_TOP:
			mAddress=0;
			Invalidate();
			break;
		case SB_THUMBPOSITION:
			increment=nPos-(mAddress/CODEWIN_WIDTH);
			break;
		default:
			break;
	}

	if(increment)
	{
		if(increment>0)
		{
			while(increment--) mAddress=NextAddress(mAddress);
		}
		else
		{
			while(increment++) mAddress=PrevAddress(mAddress);
		}

		// Perform bounds checking

		mAddress&=0xffff;
		
		// Update the scrollbar

		SetScrollPos(SB_VERT,mAddress/CODEWIN_WIDTH,TRUE);

		// Force a redraw

		Invalidate(false);
	}
}
Exemplo n.º 3
0
void CCodeWin::OnLButtonDblClk(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	
	CFrameWnd::OnLButtonDblClk(nFlags, point);

	// Work out on which line it occured

	int line=point.y/mCharHeight;
	int address=mAddress;

	for(;line;line--)
	{
		address=NextAddress(address);
	}

	C6502_REGS regs;
	mSystem.GetRegs(regs);

	for(int loop=0;loop<MAX_CPU_BREAKPOINTS;loop++)
	{
		// Unset if already set
		if(address==regs.cpuBreakpoints[loop]) break;
	}

	if(loop>=MAX_CPU_BREAKPOINTS)
	{
		// New breakpoint at next free
		for(int loop=0;loop<MAX_CPU_BREAKPOINTS;loop++)
		{
			// Unset if already set
			if(regs.cpuBreakpoints[loop]>0xffff) break;
		}
		if(loop>=MAX_CPU_BREAKPOINTS)
		{
			MessageBox("All CPU breakpoints are in use, please unset some.","Warning",MB_ICONWARNING);
		}
		else
		{
			regs.cpuBreakpoints[loop]=address;
		}

	}
	else
	{
		// Remove old breakpoint by fudging address
		regs.cpuBreakpoints[loop]=0xffffff;
	}


	mSystem.SetRegs(regs);

	// Post the message to the main window to redraw debug
	AfxGetMainWnd()->PostMessage(WM_COMMAND,IDM_DRAW_DEBUG_WINDOWS);

//	Invalidate(FALSE);
}
Exemplo n.º 4
0
int CCodeWin::Disassemble2(CString &str,int address)
{
	CString tmpstr;
	int opcode,operand;
	int	count=NextAddress(address)-address;

	// Add the address field

	tmpstr.Format("%05x\t",address);
	str+=tmpstr;

	// Dump the data fields

	for(int loop=0;loop<3;loop++)
	{
		if(count-->0)
		{
			tmpstr.Format("%02x ",GetByte(address+loop));
		}
		else
		{
			tmpstr="   ";
		}
		str+=tmpstr;
	}

	str+="    ";

	opcode=GetByte(address);

	// Add the disassembled code

	str+=mLookupTable[opcode].opcode;
	str+=" ";
	tmpstr="";

	// Read the operand
	
	switch(NextAddress(address)-address)
	{
		case 3:
			address++;
			operand=GetByte(address++);
			operand+=(GetByte(address++))<<8;
			break;
		case 2:
			address++;
			operand=GetByte(address++);
			break;
		case 1:
		default:
			address++;
			break;
	}

	// Decode the data

	switch(mLookupTable[opcode].mode)
	{
		case accu:
			tmpstr="A";
			break;
		case imm:
			tmpstr.Format("#$%02x",operand);
			break;
		case absl:
			tmpstr.Format("$%04x",operand);
			break;
		case rel:
			int scrap;
			if(operand>128) scrap=-128+(operand&0x7f); else scrap=operand;
			tmpstr.Format("$%04x",address+scrap);
			break;
		case iabs:
			tmpstr.Format("($%04x)",operand);
			break;			
		case ind:
			tmpstr.Format("($%02x)",operand);
			break;
		case zp:
			tmpstr.Format("$%02x",operand);
			break;
		case zpx:
			tmpstr.Format("$%02x,X",operand);
			break;
		case zpy:
			tmpstr.Format("$%02x,Y",operand);
			break;
		case absx:
			tmpstr.Format("$%04x,X",operand);
			break;
		case absy:
			tmpstr.Format("$%04x,Y",operand);
			break;
		case iabsx:
			tmpstr.Format("($%04x,X)",operand);
			break;
		case zrel:
			scrap=operand>>8;
			if(scrap>128) scrap=-128+(scrap&0x7f);
			tmpstr.Format("$%02x,$%04x",operand&0xff,address+scrap);
			break;
		case indx:
			tmpstr.Format("($%02x,X)",operand);
			break;
		case indy:
			tmpstr.Format("($%02x),Y",operand);
			break;
		case impl:
		case illegal:
		default:
			break;
	}

	str+=tmpstr;

	return address;
}
Exemplo n.º 5
0
void CCodeWin::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	int increment=0;
	bool redraw=false;

	CFrameWnd::OnKeyDown(nChar, nRepCnt, nFlags);

	switch(nChar)
	{
		case VK_LEFT:
			if(mAddress) mAddress--;
			redraw=true;
			break;
		case VK_RIGHT:
			mAddress++;
			redraw=true;
			break;
		case VK_UP:
			increment=-1;
			break;
		case VK_DOWN:
			increment=1;
			break;
		case VK_PRIOR:
			increment=-((int)mLineCount-1);
			break;
		case VK_NEXT:
			increment=(int)mLineCount-1;
			break;
		case VK_END:
			increment=(int)mMemorySize;
			break;
		case VK_HOME:
			mAddress=0;
			redraw=true;
//			Invalidate(FALSE);
			break;
		default:
			// Re-send the message to the main window
			AfxGetMainWnd()->PostMessage(WM_KEYDOWN,nChar,nRepCnt);
			break;
	}

	if(increment)
	{
		increment*=nRepCnt;

		if(increment>0)
		{
			while(increment--) mAddress=NextAddress(mAddress);
		}
		else
		{
			while(increment++) mAddress=PrevAddress(mAddress);
		}

		// Force a redraw

		redraw=true;
	}

	// Perform bounds checking

	if(mAddress<0)mAddress=0;
	if(mAddress>(mMemorySize-mLineCount)) mAddress=mMemorySize-mLineCount;
	mAddress&=mMemorySize-1;
		
	if(redraw)
	{
		// Update the scrollbar

		SetScrollPos(SB_VERT,mAddress/CODEWIN_WIDTH,TRUE);

		Invalidate(FALSE);
	}
}
Exemplo n.º 6
0
void CCodeWin::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	CFont* pOldFont;
	C6502_REGS	regs;
	bool foundpc=false;

	// Select in our font

	pOldFont=dc.SelectObject(mpCodeFont);

	// Find out the PC for highlighting

	mSystem.GetRegs(regs);

	if(mMemorySize>1)
	{
		CString	line;
		int	current_address,address,loop;

		// If in follow mode then check PC will be draw else adjust mAddress
		// we don't follow if the CPU is not running

		if(mFollowPC)
		{
			bool test=false;
			address=mAddress;
			for(loop=0;loop<mLineCount;loop++)
			{
				if(address==regs.PC) test=true;
				address=NextAddress(address);
			}
			if(!test) mAddress=regs.PC;
		}

		// Now repaint

		address=mAddress;

		for(loop=0;loop<mLineCount;loop++)
		{
			line="";
			current_address=address;
			address=Disassemble(line,address);

			
			for(int bps=0;bps<MAX_CPU_BREAKPOINTS;bps++)
			{		
				if(current_address==regs.cpuBreakpoints[bps])
				{
					line.SetAt(0,'*');
				}
			}

			if(current_address!=regs.PC)
			{
				dc.TabbedTextOut(0,loop*mCharHeight,line,7,mTabstops,0);
			}
			else
			{
				COLORREF back,front;
				front=dc.GetTextColor();
				back=dc.GetBkColor();
				dc.SetTextColor(back);
				dc.SetBkColor(front);
				dc.TabbedTextOut(0,loop*mCharHeight,line,7,mTabstops,0);
				dc.SetTextColor(front);
				dc.SetBkColor(back);
			}
		}
	}
	else
	{
		// We have selected an invalid memory range

		dc.TextOut(mCharWidth*12,(mLineCount/2-1)*mCharHeight,"CARTRIDGE BANK IS EMPTY");
	}

	// Select the old font back in

	dc.SelectObject(pOldFont);
}