C/C++ Programming Help Thread
This is a discussion on C/C++ Programming Help Thread within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; I don't use IDE's... can't get to grips with them I prefer to dive into a makefile instead. I'm reading ...
-
02-05-2009, 04:24 PM #9661I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
I don't use IDE's... can't get to grips with them I prefer to dive into a makefile instead.
I'm reading in binary mode, and theres no line breaks, just a continuous line of "stuff". Check the files to see what I mean.
I've also noticed another problem, when I hard coded the map files, it loaded the first map file, the second one wouldn't load though it just closed after the first, again this isn't something that happens on Vista. I thought there wasn't supposed to be any differences between C++ on Windows and Linux's standard libraries
-Aura
Blah I haven't got a clue what I'm doing, is there any documentation on the website on what to do or something?
Geändert von Auraomega (02-05-2009 um 04:55 PM Uhr)
-
02-06-2009, 05:14 AM #9662
whats a makefile got to do with using an ide? use both.
well I'd wager its more a problem with your code than the standard library.I've also noticed another problem, when I hard coded the map files, it loaded the first map file, the second one wouldn't load though it just closed after the first, again this isn't something that happens on Vista. I thought there wasn't supposed to be any differences between C++ on Windows and Linux's standard libraries
but since you are not showing us the code its hard to say. I'd suggest not using any of the *scanf* functions.-- Code Monkey : Sarien, Fishguts, Cracks and Crevices --
"Did IQ's just drop sharply while I was away?" (Ripley)
-
02-06-2009, 05:27 AM #9663I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
I did show the code, check the spoiler on the first post on this problem, theres also the dump and map files.
Theres also no problem with my code per se, because it runs fine on Vista, surely cross platform code that runs on Vista would also run on Linux?
After more work, and with the aid of kuroneko, we've worked out that the y dimension is the one with the problems, the x dimension is read correctly at 48, yet the y always fails to read on my other maps.
And using fscanf is the easiest and most logical way for me, I'm reading an integer with either 1 or 2 digits, with an x inbetween, so fscanf(FILE, "%ix%i", *xDim, *yDim); seems the best way forward.
-Aura
EDIT:
Slightly modified my code to give a nicer layout in the dump, the new dump is in the spoiler below:
Spoiler for Dump:
The first bit is the file name, the second is the x and y dimensions, as you can see x is read correctly but y fails.
Now the same dump on Vista:
Spoiler for Dump(Vista):
Theres obviously a difference between Windoze and Linux's standard libraries otherwise this would not happen.
-
02-06-2009, 06:44 AM #9664
aah I see the code. Ill check it out.
if your reading bytes with fgetc why not just have
x = fgetc(mapFile);
y = fgetc(mapfile);
and avoid the craptasticness that is scanf set of functions?
again I'd still vote the problem is not with the linux std libs, if there were it would have been found out by now, but since nobody else is having the same problem with standard fopen/fread/fgetc functions as you are...
fwiw Im building on linux and windows for psp/gpx/pc on several projects and different machines/versions of windows (2k/xp, mingw,openwatcom,vc) and several flavours of linux without any problems with basic posix functions.-- Code Monkey : Sarien, Fishguts, Cracks and Crevices --
"Did IQ's just drop sharply while I was away?" (Ripley)
-
02-06-2009, 07:32 AM #9665I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
I agree, but it simply doesn't make sense as to why it works on one system and not another. What I'm saying is I think theres a subtle difference between the two and I'm tripping up this difference.
As for fgetc, I'm reading either a single or two digit number, which means one or two bytes, fgetc just isn't going to cut it (yes I know I could read it into a string and atoi it). The simple case is, if I'm having this problem then I'd like to know WHAT the problem is so I can avoid it in the future.
Also, dunno if this is assosiated, but I wanted to compile someone in OGL but couldn't find the libraries and stuff, so I downloaded a NeHe tut and compiled that, except that doesn't seem to run as expected either. It was NeHe lesson 10 with SDL, I've tried compiling on my PC to see if its a code error but it can't find the links to GL_BGR or GL_BGR_EXT so I can't tell whats going on.
-Aura
-
02-06-2009, 08:01 AM #9666
-- Code Monkey : Sarien, Fishguts, Cracks and Crevices --
"Did IQ's just drop sharply while I was away?" (Ripley)
-
02-06-2009, 09:28 AM #9667I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
You're right, I don't have a clue. fgetc returns 1 byte of data, 99x99 is 5 bytes, each dimension would therefore be 2 bytes. Personally I can't see how fgetc is useful here. Maybe you'd like to give me a working example of how to use fgetc to read 2 bytes per dimension?
-Aura
-
02-06-2009, 01:12 PM #9668QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
The .map files you provided are text files, not binary.
[Blog] [Portfolio]
[Homebrew Illuminati - Serious Homebrew Development Forums]
[I want to make Homebrew FAQ] [How I broke into the Games Industry]
[Programming Book List] [Programming Article List]
-
02-06-2009, 01:39 PM #9669I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
Huh, maybe my understanding of text and binary files are wrong but, if its not standard ascii characters and not readable by a text editor, its a binary file right? I mean I'm using 0x01, 0x02 and 0x03 a lot, from what I can see the only text is the first bit with the dimensions.
And now another problem has cropped up... I hard coded the dimensions, so the map loaded, but the second map fails to load at all. Running the string through a for loop and using sprintf it gives 1.map on the first go, 2.map on the second on Vista, but 11.map on Linux :Argh:
And now... to make issues even worse, Vista cannot see the folders on the memory card only Ubuntu can... great I can't even show you the code for the for loop -.-
-Aura
EDIT:
Backed up the files and formatted the SD, anyway the code for that loop is below:
Spoiler for Loop:Geändert von Auraomega (02-06-2009 um 01:55 PM Uhr)
-
02-06-2009, 05:34 PM #9670xMod.
- Registriert seit
- Oct 2008
- Ort
- Melbourne, Australia
- Beiträge
- 675
- Points
- 4.576
- Level
- 43
- My Mood
-
- Downloads
- 0
- Uploads
- 0
any1 got any libCurl examples?
~!SlasheR!~
-
02-07-2009, 05:47 PM #9671I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
A couple of questions, the bool type, is that only 1 bit, or is it actually a byte (seems most likely) acting as a bit that can only have 2 states (true and false)?
ASM being hardware specific, does that mean that PC games are not coded in ASM as it would be different for each setup? To inline ASM into a C++ project I should use __asm{ } right?
Are there any good compression guides out there? I'm looking to add compression to my encryption and a quick Google search didn't return much useful.
-Aura
-
02-08-2009, 08:41 AM #9672QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
The files that you provided were readable by a text editor. If it wasn't a standard text file, then you wouldn't have been able to use fscanf formatting in the first place.
Binary files are generally illegible when opened in notepad. A .doc file is binary file. A .txt file is also a binary file. They are just both 'readable' when opened by the right program.[Blog] [Portfolio]
[Homebrew Illuminati - Serious Homebrew Development Forums]
[I want to make Homebrew FAQ] [How I broke into the Games Industry]
[Programming Book List] [Programming Article List]
-
02-08-2009, 12:05 PM #9673I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
When I open my map files in notepad they won't work, you sure you didn't check my dump? I did dump that in readable format. Well it opens in a text editor, but its just a bunch of white spaces and ¬ at 90 degrees. I thought binary files were anything that didn't contain the standard ASCII letters, or does it cover the full range of ASCII (0-255) even though some don't actually appear on screen?
-Aura
-
02-08-2009, 02:21 PM #9674QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
I opened 2.map and got
Ah, you have data pass the 48x27 which my text editor doesn't show but the copy and paste does. Joy. In which case, it is game on, now I can try it for myself.Code:48x27
My preliminary guess is that it is reading the bytes after '7' as part of the number until it hits a delimiter (eg a 0 byte). Don't forget the ASCII table values are between 0-255 so technically, every byte in a file can be represented by an ASCII character. As far as fscanf is concerned, it probably sees everything pass the 'x' as one really long string and attempts to convert it to an integer which it can't hence 0?
Stick a zero byte after the '7' and see what happens.
If you map sizes are not going to be bigger then 255x255, then you can store the dimensions in the first 2 bytes of the file rather then having it in plain text.
-=Double Post Merge =-
Plain text = human readable
Binary = Not human readable
Not all of the ASCII table is human readable.Geändert von yaustar (02-08-2009 um 02:35 PM Uhr) Grund: Automerged Doublepost
[Blog] [Portfolio]
[Homebrew Illuminati - Serious Homebrew Development Forums]
[I want to make Homebrew FAQ] [How I broke into the Games Industry]
[Programming Book List] [Programming Article List]
-
02-08-2009, 04:05 PM #9675I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
I see, sorry its been a while since I saw an ASCII table, after looking at one the last readable value is 127, I had it in my head that it spanned all 256.
As for the problem, we've discovered the problem, apparently the first map had a corrupted byte at the end, 0x0A, which is unaccounted for, this somehow caused yDim to become 0 on Ubuntu but not on Windows, and I have a feeling its because of a buffer overflow in the read function, after reviewing the code (something I should have done after digging up this half finished project) I noticed that the buffer was also getting the EOF on the end, the buffer was 48*27 - the biggest map size - so when it read 48*27 plus the EOF, it knocked the yDim (I assume) to 0, and also the stage to 0 when the last bit wasn't corrupted, which would also explain why the map continously reset itself to 1.map on Ubuntu but not Windows.
The subtle difference between to two? I'm assuming its only on memory.
-Aura
-
02-08-2009, 06:25 PM #9676
Does anybody know a method of using a malloc-type action in kernel mode? It's been driving me insane looking for how malloc in itself would be able to derive from heap functions.
I gone and made that one power spoofer and that gay cheat device.
-
02-08-2009, 06:57 PM #9677I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
In pspsysmem_kernel.h the function void *sceKernelAllocHeapMemory (SceUID heapid, SceSize size); should do what you require.
You'll have to allocate a heap yourself though, unless anyone here knows how to access already created heaps? You know, like the on you define at the start of your code for KB, can't think of the precompiler for it, or for calling on ones in other modules that you haven't got the address for?
-Aura
-
02-08-2009, 07:20 PM #9678
-
02-11-2009, 08:36 AM #9679
Achievements:
- Registriert seit
- Aug 2008
- Beiträge
- 12
- Points
- 2.512
- Level
- 30
- Downloads
- 0
- Uploads
- 0
Hello, I've a question about a menu...
I do some menues with pspDebugScreenPrintf to show text in screen, but when I do this, to change selected option, I've to clear screen and show other selected menu, and it blink, how I can do a menu with debug functions without blink it?
Thx. Gladiator
-
02-11-2009, 12:12 PM #9680I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
Use the GU or something thats double buffered (that way you're not drawing directly on the screen). graphics.c examples on PSP-Programming or OSLib should do that nicely. I'd also suggest using intraFont for a more "professional" look, as it uses the Sony font files.
-Aura
-
02-11-2009, 01:26 PM #9681
Achievements:
- Registriert seit
- Aug 2008
- Beiträge
- 12
- Points
- 2.512
- Level
- 30
- Downloads
- 0
- Uploads
- 0
-
02-13-2009, 08:20 AM #9682QJ Gamer Blue
- Registriert seit
- Dec 2007
- Ort
- Netherlands
- Beiträge
- 148
- Points
- 5.672
- Level
- 48
- Downloads
- 0
- Uploads
- 0
Hi,
Does anybody know how to draw a rectangle through the PSP GU?
(Without using graphics.c etc.)
Ty
[SIZE="1"][color=#D1D1FF]______________________________________________________________[/color]
[i]Last edited by basfreak; 01-01-1990 at [color=#666686]12:00 PM[/color][/i].[/SIZE]
-
02-13-2009, 11:03 AM #9683I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
Theres some pretty good tutorials on PSP-Programming.com, heres a list of them. And a direct link to the polygon tutorial.
Some of the links are dead, but from what I can see the GU tutorials all work fine bar no images. They are based off of the NeHe tutorials, so if theres a missing file, check on there and see if the file exists under a similar lesson.
-Aura
-
02-13-2009, 01:32 PM #9684
Achievements:
- Registriert seit
- Aug 2008
- Beiträge
- 12
- Points
- 2.512
- Level
- 30
- Downloads
- 0
- Uploads
- 0
Well.. I do my own "sample" of Intrafont, I just printf an image, and then, I write with intrafont in the screen, but de image, blink :/ xD. This is my sample, Can you learn me how I can do it without blink?
Sorry for my bad english, I'm spanish...Code:#include <pspkernel.h> #include <pspgu.h> #include <pspgum.h> #include <pspdisplay.h> #include <png.h> #include "graphics.h" #include "intraFont.h" PSP_MODULE_INFO("Sample Intrafont by Recse", 0, 1, 1); PSP_MAIN_THREAD_ATTR(PSP_THREAD_ATTR_USER); static int running = 1; int exit_callback(int arg1, int arg2, void *common) { running=0; sceKernelExitGame(); return 0; } int CallbackThread(SceSize args, void *argp) { int cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL); sceKernelRegisterExitCallback(cbid); sceKernelSleepThreadCB(); return 0; } int SetupCallbacks(void) { int thid = sceKernelCreateThread("CallbackThread", CallbackThread, 0x11, 0xFA0, PSP_THREAD_ATTR_USER, 0); if (thid >= 0) sceKernelStartThread(thid, 0, 0); return thid; } int main() { char buffer[200]; Image* Menu; intraFont* ltn0; pspDebugScreenInit(); initGraphics(); intraFontInit(); SetupCallbacks(); ltn0=intraFontLoad("flash0:/font/ltn0.pgf",0); sprintf(buffer, "Imagen.png"); Menu = loadImage(buffer); blitAlphaImageToScreen(0 ,0 ,480 , 272, Menu, 0, 0); while(1) { guStart(); sceGuTexMode(GU_PSM_8888,0,0,GU_TRUE); intraFontSetStyle(ltn0, 1.0f,0xff78e7e8,0x96000000,INTRAFONT_ALIGN_CENTER); intraFontPrint(ltn0, 240, 45,"Zample IntraFont, By (gladii :P)"); sceGuFinish(); sceGuSync(0,0); sceDisplayWaitVblankStart(); flipScreen(); } intraFontUnload(ltn0); intraFontShutdown(); return 0; }Geändert von Gladiator (02-13-2009 um 01:46 PM Uhr)
-
02-13-2009, 01:34 PM #9685QJ Gamer Green
- Registriert seit
- May 2007
- Beiträge
- 70
- Points
- 3.522
- Level
- 37
- Downloads
- 0
- Uploads
- 0
Gladiator: You're blitting the image outside of the while loop, thus it only gets called once. Put the image blitting function in the while loop.
[url="http://www.safarial.homebrewheaven.net"]Blog[/url]
-
02-13-2009, 01:47 PM #9686
Achievements:
- Registriert seit
- Aug 2008
- Beiträge
- 12
- Points
- 2.512
- Level
- 30
- Downloads
- 0
- Uploads
- 0
In what Position I must put it in the while loop?
-
02-13-2009, 03:25 PM #9687I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
First off, change:
to:Code:sprintf(buffer, "Imagen.png"); Menu = loadImage(buffer);
Theres no need to use a buffer...Code:Menu = loadImage("Imagen.png");
Also, you're code could do with some tidying, keep a check on my sig, I'll be adding a nice link on how to format code to make it readable.Code:while(1) { blitAlphaImageToScreen(0 ,0 ,480 , 272, Menu, 0, 0); guStart(); sceGuTexMode(GU_PSM_8888,0,0,GU_TRUE); intraFontSetStyle(ltn0, 1.0f,0xff78e7e8,0x96000000,INTRAFONT_ALIGN_CENTER); intraFontPrint(ltn0, 240, 45,"Zample IntraFont, By (gladii :P)"); sceGuFinish(); sceGuSync(0,0); sceDisplayWaitVblankStart(); flipScreen(); } intraFontUnload(ltn0); intraFontShutdown(); return 0; }
Can someone help me with a peice of code? I'm trying to read a file and remove all the returns and \s, my code so far is:
except its not quite working with '\n'.Code:c = fgetc(fp); for(int loop = 0; c != EOF; loop++) { if((c != '\n') && (c != '\\')) { buffer[loop] = c; } c = fgetc(fp); }
-Aura
-
02-13-2009, 03:46 PM #9688
Achievements:
- Registriert seit
- Aug 2008
- Beiträge
- 12
- Points
- 2.512
- Level
- 30
- Downloads
- 0
- Uploads
- 0
Okay, I do it, I remove sprintf, change loadImage(buffer); by loadImage("imagen.png"); and I put blitImage in the beginning of while loop, the psp return me this:
rcalero. net /images /ba6b3d731d .bmp
-
02-13-2009, 04:03 PM #9689I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
I'm not sure I follow.
Also, I should probably mention I've never used the GU and graphics.c together, and I can't say its advisable either, it'll probably create more problems than it'll solve.
-Aura
-
02-13-2009, 05:18 PM #9690QJ Gamer Blue
- Registriert seit
- Sep 2005
- Ort
- Chigasaki, Japan
- Beiträge
- 226
- Points
- 4.980
- Level
- 45
- Downloads
- 0
- Uploads
- 0
Looks fine to me. What's the not quite bit? Note that when fp is opened in binary mode, different platforms offer different line endings. Under *nix a '\n' is sufficient. Under win32 you may want to remove '\r' as well. Just guessing here (maybe you actually want to remove line endings), but this code definitely removes '\n' and '\'.


LinkBack URL
About LinkBacks

Mit Zitat antworten

Hello everyone I am new here and I am glad to be part of this amazing community and I think there...
New to forum