Overclock.net - Overclocking.net
     
 
Home Gallery Reviews Blogs Register Today's Posts Mark Forums Read Members List


Go Back   Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming > Application Programming

Reply
 
LinkBack Thread Tools
Old 08-08-09   #1 (permalink)
New to Overclock.net
 
intel nvidia

Join Date: Nov 2007
Location: Surrey, BC, Canada
Posts: 272

Rep: 14 serge2k Unknown
Unique Rep: 14
Trader Rating: 1
Default Removing a printf messes up the output (directx output)

basically I'm just trying to create an emulator for space invaders, its coming along nicely except I decided to change the way I'm doing graphics because someone suggested to me that the new way would be faster.

What I was doing before was rendering every pixel as a vertex then outputting them as points. it worked but was slow.

So now I'm using a texture instead.

Anyway, I'm not going to post all of the code unless I absolutely have to but here is my problem

Code:
void Processor::Write_Byte(u8 val, u16 location)
{
	u16 tmp;
	if(location >= 0x4000)
	{
		tmp = location;
		location -= 0x2000;
	}
	else if(location >= 0x2000)
		tmp = location + 0x2000;
	else
	{
		return ;
	}
	
	
	if(location >= 0x2400 && location < 0x4000)
	{
		graphics->drawSprite(((location-0x2400)%32)*8,(location-0x2400)/32, val);
		
		printf("%d\t%d\n",(location-0x2400)%256,(location-0x2400)/256);
	}
	memory->Write(location, val);
	memory->Write(tmp, val);

}
all that function does is write to memory, handles the mirror, and if it is a write in the video memory it tells my graphics class to draw at a certain point.

The problem is that printf, I was using it for debugging but don't actually want it in the program. It's horrendously slow.

Here is the output from the first screen with the printf



here is it with the printf not executing (commented out)




oh and I realize that the first image still has problems, thats fine it's just the way the video memory is read. It's not an issue at this point as that is easy to correct.

At this point I'm completely confused why the printf can't be removed. It just seems weird.
__________________
System: The Black Box
CPU
E6750
Motherboard
Asus P5N-E SLI
Memory
2GB DDR-2 800 MHz
Graphics Card
EVGA 8800 GTS 640
Hard Drive
2x250GB Seagate in Raid 0, 2x1TB WD Caviar Blacks
Sound Card
integrated
Power Supply
Antec Earthwatts 500W
Case
Antec Sonata 3
CPU cooling
Xigmatek HDT S1283
GPU cooling
stock
OS
Windows 7 Ultimate x64
Monitor
22" LG

Last edited by serge2k : 08-08-09 at 04:55 AM
serge2k is online now   Reply With Quote
Old 08-08-09   #2 (permalink)
4.0ghz
 
Coma's Avatar
 
intel nvidia

Join Date: Jun 2007
Posts: 7,500

Rep: 455 Coma is a proven memberComa is a proven memberComa is a proven memberComa is a proven memberComa is a proven member
Unique Rep: 328
Trader Rating: 0
Default

Paste working and non-working code, because you're probably accidentally changing something else that makes it break.
__________________
System: Akiyama Mio
CPU
E6420 @ stock, 0.98v
Motherboard
Asus P5N-E SLI
Memory
2x1GB OCZ Platinum @ 800MHz 4-4-4-12 1T, 1.9v
Graphics Card
BFG 8800GT 512MB
Hard Drive
WD 250GB, 320GB SATA/3, 16MB Cache
Power Supply
Corsair 520HX
Case
NZXT Apollo Black
CPU cooling
Stock
OS
Ubuntu 9.04 x86 & XP x86
Monitor
Asus VW222U
Coma is offline Overclocked Account   Reply With Quote
Old 08-08-09   #3 (permalink)
New to Overclock.net
 
intel nvidia

Join Date: Nov 2007
Location: Surrey, BC, Canada
Posts: 272

Rep: 14 serge2k Unknown
Unique Rep: 14
Trader Rating: 1
Default

the only change is commenting out that printf.

works
Code:
void Processor::Write_Byte(u8 val, u16 location)
{
	u16 tmp;
	if(location >= 0x4000)
	{
		tmp = location;
		location -= 0x2000;
	}
	else if(location >= 0x2000)
		tmp = location + 0x2000;
	else
	{
		return ;
	}
	
	
	if(location >= 0x2400 && location < 0x4000)
	{
		graphics->drawSprite(((location-0x2400)%32)*8,(location-0x2400)/32, val);
		
		printf("%d\t%d\n",(location-0x2400)%256,(location-0x2400)/256);
	}
	memory->Write(location, val);
	memory->Write(tmp, val);

}
doesn't work

Code:
void Processor::Write_Byte(u8 val, u16 location)
{
	u16 tmp;
	if(location >= 0x4000)
	{
		tmp = location;
		location -= 0x2000;
	}
	else if(location >= 0x2000)
		tmp = location + 0x2000;
	else
	{
		return ;
	}
	
	
	if(location >= 0x2400 && location < 0x4000)
	{
		graphics->drawSprite(((location-0x2400)%32)*8,(location-0x2400)/32, val);
		
		//printf("%d\t%d\n",(location-0x2400)%256,(location-0x2400)/256);
	}
	memory->Write(location, val);
	memory->Write(tmp, val);

}
experimenting a bit

doesn't work
Code:
void Processor::Write_Byte(u8 val, u16 location)
{
	u16 tmp;
	if(location >= 0x4000)
	{
		tmp = location;
		location -= 0x2000;
	}
	else if(location >= 0x2000)
		tmp = location + 0x2000;
	else
	{
		return ;
	}
	
	
	if(location >= 0x2400 && location < 0x4000)
	{
		graphics->drawSprite(((location-0x2400)%32)*8,(location-0x2400)/32, val);
		
		printf("");
	}
	memory->Write(location, val);
	memory->Write(tmp, val);

}
works
Code:
void Processor::Write_Byte(u8 val, u16 location)
{
	u16 tmp;
	if(location >= 0x4000)
	{
		tmp = location;
		location -= 0x2000;
	}
	else if(location >= 0x2000)
		tmp = location + 0x2000;
	else
	{
		return ;
	}
	
	
	if(location >= 0x2400 && location < 0x4000)
	{
		graphics->drawSprite(((location-0x2400)%32)*8,(location-0x2400)/32, val);
		
		printf("t");
	}
	memory->Write(location, val);
	memory->Write(tmp, val);

}
works
Code:
void Processor::Write_Byte(u8 val, u16 location)
{
	u16 tmp;
	if(location >= 0x4000)
	{
		tmp = location;
		location -= 0x2000;
	}
	else if(location >= 0x2000)
		tmp = location + 0x2000;
	else
	{
		return ;
	}
	
	
	if(location >= 0x2400 && location < 0x4000)
	{
		printf("t");
		graphics->drawSprite(((location-0x2400)%32)*8,(location-0x2400)/32, val);
	}
	memory->Write(location, val);
	memory->Write(tmp, val);

}
__________________
System: The Black Box
CPU
E6750
Motherboard
Asus P5N-E SLI
Memory
2GB DDR-2 800 MHz
Graphics Card
EVGA 8800 GTS 640
Hard Drive
2x250GB Seagate in Raid 0, 2x1TB WD Caviar Blacks
Sound Card
integrated
Power Supply
Antec Earthwatts 500W
Case
Antec Sonata 3
CPU cooling
Xigmatek HDT S1283
GPU cooling
stock
OS
Windows 7 Ultimate x64
Monitor
22" LG
serge2k is online now   Reply With Quote
Old 08-09-09   #4 (permalink)
With great difficulty
 
rabidgnome229's Avatar
 
intel nvidia

Join Date: Feb 2006
Location: Pittsburgh
Posts: 5,210

Rep: 614 rabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famous
Unique Rep: 370
FAQs Submitted: 6
Trader Rating: 5
Default

Step through with a debugger and watch for what differs in the program state between the different versions
__________________
System: It goes to eleven
CPU
E6300
Motherboard
DS3
Memory
2GB XMS2 DDR2-800
Graphics Card
EVGA 8600GTS
Hard Drive
1.294 TB
Sound Card
Audigy 2 ZS
Power Supply
Corsair 520HX
Case
Lian-Li v1000B Plus
CPU cooling
TTBT
GPU cooling
Thermalright V2
OS
Arch Linux/XP
Monitor
Samsung 226bw
rabidgnome229 is offline Overclocked Account   Reply With Quote
Old 08-10-09   #5 (permalink)
New to Overclock.net
 
intel nvidia

Join Date: Nov 2007
Location: Surrey, BC, Canada
Posts: 272

Rep: 14 serge2k Unknown
Unique Rep: 14
Trader Rating: 1
Default

I tried stepping through and saw no difference.

heres the source for my chip8 emulator.
Attached Files
File Type: rar Chip 8 Emulator.rar (1.60 MB, 6 views)
__________________
System: The Black Box
CPU
E6750
Motherboard
Asus P5N-E SLI
Memory
2GB DDR-2 800 MHz
Graphics Card
EVGA 8800 GTS 640
Hard Drive
2x250GB Seagate in Raid 0, 2x1TB WD Caviar Blacks
Sound Card
integrated
Power Supply
Antec Earthwatts 500W
Case
Antec Sonata 3
CPU cooling
Xigmatek HDT S1283
GPU cooling
stock
OS
Windows 7 Ultimate x64
Monitor
22" LG

Last edited by serge2k : 08-10-09 at 10:18 PM
serge2k is online now   Reply With Quote
Old 08-11-09   #6 (permalink)
Case Modder
 
Spotswood's Avatar
 
Join Date: Jul 2008
Location: New Hampshire, USA
Posts: 236

Rep: 46 Spotswood is acknowledged by some
Unique Rep: 39
Trader Rating: 0
Default

Are you running this app on a multi-processor machine?

What happens if you replace the printf with this?
Code:
LONG dummy = 0;;
InterlockedIncrement(&dummy);
EDIT: After looking over your code some more, what happens if you write the log messages to a file rather than the console i.e. remove the call to AllocConsole() and change printf to fprintf.
__________________
Rich
Custom Wooden Case Builder
Overclock.net Mod of the Month

Last edited by Spotswood : 08-11-09 at 12:14 AM
Spotswood is offline   Reply With Quote
Old 08-11-09   #7 (permalink)
New to Overclock.net
 
intel nvidia

Join Date: Nov 2007
Location: Surrey, BC, Canada
Posts: 272

Rep: 14 serge2k Unknown
Unique Rep: 14
Trader Rating: 1
Default

The computer is the one in my sig, so yes it is on a dual core.

first suggestion didn't work. I tried just removing the allocconsole and printf statements and that didn't work.
__________________
System: The Black Box
CPU
E6750
Motherboard
Asus P5N-E SLI
Memory
2GB DDR-2 800 MHz
Graphics Card
EVGA 8800 GTS 640
Hard Drive
2x250GB Seagate in Raid 0, 2x1TB WD Caviar Blacks
Sound Card
integrated
Power Supply
Antec Earthwatts 500W
Case
Antec Sonata 3
CPU cooling
Xigmatek HDT S1283
GPU cooling
stock
OS
Windows 7 Ultimate x64
Monitor
22" LG
serge2k is online now   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools



All times are GMT -5. The time now is 12:40 AM.


Overclock.net is a Carbon Neutral Site Creative Commons License

Terms of Service / Forum Rules | Privacy Policy | DMCA Info | Advertising | Become an Official Vendor
Copyright © 2009 Shogun Interactive Development. Most rights reserved.
Page generated in 0.12874 seconds with 9 queries