|
![]() |
Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming > Application Programming | |
Removing a printf messes up the output (directx output)
|
||
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) | |||||||||||||
|
New to Overclock.net
|
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);
}
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.
Last edited by serge2k : 08-08-09 at 04:55 AM |
|||||||||||||
|
|
|
|
|
#2 (permalink) | |||||||||||
|
4.0ghz
![]() |
Paste working and non-working code, because you're probably accidentally changing something else that makes it break.
__________________
|
|||||||||||
|
|
|
|
#3 (permalink) | |||||||||||||
|
New to Overclock.net
|
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);
}
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("");
}
memory->Write(location, val);
memory->Write(tmp, val);
}
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);
}
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);
}
|
|||||||||||||
|
|
|
|
|
#4 (permalink) | |||||||||||||
|
With great difficulty
![]() |
Step through with a debugger and watch for what differs in the program state between the different versions
__________________
|
|||||||||||||
|
|
|
|
#5 (permalink) | |||||||||||||
|
New to Overclock.net
|
I tried stepping through and saw no difference.
heres the source for my chip8 emulator.
Last edited by serge2k : 08-10-09 at 10:18 PM |
|||||||||||||
|
|
|
|
|
#6 (permalink) |
|
Case Modder
![]() |
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);
__________________
Rich Custom Wooden Case Builder
Last edited by Spotswood : 08-11-09 at 12:14 AM |
|
|
|
|
|
#7 (permalink) | |||||||||||||
|
New to Overclock.net
|
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.
|
|||||||||||||
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|