Thread: PSP C programming tutorials: Episode 1

Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1 PSP C programming tutorials: Episode 1 
    Senior Member PSP Elite Hacker
    Join Date
    Jul 2006
    Posts
    1,794
    Episode 1: The Cygwin Menace

    Welcome to the first in a series of C programming tutorials for the PSP! In this first episode, we will go through the process of setting up an emulated linux environment in windows, and setting up the development environment for the PSP. Some prior linux knowledge would be helpful, but not necessary.

    The first thing we are going to install is Cygwin. This will be your “linux emulator” if you will. You’ll need to download the installer from: http://www.cygwin.com/setup.exe. Next run the installer. Click next at the first screen, then select install from internet. Click next, then make sure the install directory is set to: C:\Cygwin, then click next and make sure that says C:\Cygwin as well. Click next and leave “direct connection” checked, then click next. It will download a list of mirrors (people to download from). Usually any is fine, but I prefer ftp://mirrors.kernel.org being that I’m a linux nerd .

    Click next, then you’ll have to pick the packages you want to install. Now if you want a full blown linux environment, I would suggest installing all the packages, but if you only wanna make some psp programs, the only real one’s you need to change the install options for are “devel” and “web”. Click then arrows next to the package category until it says install:



    Remember, the less you select, the faster it will download, but also, the less you can do. Click next. If you get a screen asking about dependencies, just select them all and click next. It should go through and download all the packages and install them, and then ask you if you want shortcuts and then finish.

    Now comes the fun part, learning to navigate from the command prompt . ok, so now you should have a cygwin shortcut on your desktop, double click on it and a command console should pop up. Yay! You now have linux in windows! Ok, now you’ll need to download the pspsdk (the kit for compiling your code into an eboot). Next, go to http://ps2dev.org/psp/Tools/Toolchai...60120.download and save that somewhere. Now you’ll need to use winrar to extract that file to my documents.

    Next, open up your cygwin promp, and type ls. It should list all the folders under my documents, and you should see one in there called psptoolchain. Next type: cd psptoolchain, then hit enter. Next type: sh toolchain.sh, then hit enter. It should go through and install everything ok, if you get any errors, post here and I will try to help straighten them out. It can take a while to install, so go watch a tv show, take a crap, have a nap, when you come back, it should be finished. Now, the last step in the install is to exit the prompt, then navigate to C:\Cygwin, right click on “cygwin.bat”, then click edit. It will open up in notepad, and you should see something like this:

    Code:
    @echo off
    
    C:
    chdir C:\cygwin\bin
    
    bash --login –i
    You’ll want to change this to:

    Code:
    @echo off
    
    C:
    chdir C:\cygwin\bin
    
    set path=%path%;C:/cygwin/usr/local/pspdev/bin
    set PSPSDK=C:/cygwin/usr/local/pspdev
    
    bash --login –i
    Then save and close. This will tell cygwin where your devkit is located so it can compile the programs correctly. That’s it! You now have a functional PSP development environment, ready to do your evil bidding! This concludes the first episode in the PSP C programming tutorials, next time we will learn a little about coding, and how to actually turn all that gibberish into something useful!

    n8
    Reply With Quote  
     

  2. #2  
    Senior Member PSP Elite Hacker drizzle's Avatar
    Join Date
    Sep 2005
    Posts
    3,205
    MATRIXSUCKS: I have edited your post drizzle in order to put all three episodes in one place, therefore making the information more condense and easier to find.


    Episode 2: Attack of teh n00bs

    Welcome back! In the last episode we went through and installed cygwin and the psp devkit. Now that we got these shiny new tools, you’re anxious to make your own games, right? Hold on there little buddy, we gotta walk before we can run. In this episode, I’m going to explain some of the basics of programming in general, and also get you acquainted with C/C++. Alright, let’s do this, LEEEERRROOYYYY…err…ahem…well that was embarrassing…

    Let’s start with some history. A computer processor is basically millions/billions of switches in a little chip. These are controlled using binary (1(on) and 0(off)) to perform calculations. It is not necessary that you know binary, that’s what people made programming languages are for. The first to be developed, due to the high probability of human error and the enormous pain in the ass of having to work with binary, was assembly language. It’s very primitive, but simple. As programs became more and more complex (and also to save time and headache), other programming languages were spawned.

    C was originally developed by these guys that wanted to be able to create platform independent operating systems (meaning it could work on a pc/mac/any other hardware), so the created a language with standardized syntax that could be compiled and ran on different hardware platforms. This spawned *nix operating systems, which can be compiled to run on virtually any platform. C++ is an improvement on C, adding in the ability to create object-oriented programs (we’ll discuss that another day) as well as a few other improvements. C++ is one of the most widely used programs for end-user applications in the market, largely because there’s not much of a limit to what you can do with it.

    C/C++ is a compiled language. This means that you type out the source code, run it through a compiler/linker which converts it to machine language, and creates an binary executable file. In windows, this would be a exe file, on your psp, it’s an elf/prx file (which is eventually transformed into an EBOOT.PBP file). There are different compilers for different systems, and this is how it builds your code so that it will work on that specific system. There are other types of languages. Java for instance, is an interpreted language, which is translated to machine language every time you run it, rather than having a binary executable.

    Ok, now lets get down to the anatomy of a C program. Here is the most basic example I could think of, the legendary hello world

    Code:
    #include <stdio.h>
    
    int main() {
    	printf("Hello World! C is teh pwnzorz!!!1!one!\n");
    	return 0;
    }
    That wasn’t so bad, was it? Now let’s dissect this bad boy…

    Code:
    #include <stdio.h>
    This is called an include, for obvious reasons, lol. What this does is it accesses the header file stdio.h. A header file contains information for functions that you use in your program. These are basically just to make your life easier, as you won’t have to recode a function every time you want to use it. Stdio.h has information for the printf() function, which I will explain in a few seconds. Say, for instance, you wanted to find the square root of a number. The function for that is sqrt(number), but the sqrt() function is located in Math.h, so you better include it at the beginning of your code, or else you’ll have a mess come compiling time.

    Code:
    int main() {
    This is a function, the main() function to be exact. Every program you make is going to have to have a main() function. A function encloses code that does something. Each function has a type. This type depends on the type of value that the function returns. I suppose this would be a good time to talk about types of values and variables. There are many types of values that you can use in C/C++. Some common ones are int (integer-whole numbers in case you didn’t know), char (character-a single letter, number, or symbol), string (a string of characters), double (a decimal), float (a floating point decimal), and void (nothing, well, actually a null character, but let’s just say nothing for now).

    A variable is just like a variable in algebra. It’s just a container for a value. You must declare the variable by doing something like int x; (note the semicolon. You have to put a semicolon after every statement in a function). To give x a value, all you gotta do is say x=2;, that’s it. Anyways, back to functions. The most common types used for the main() function are void and int. You’ll usually want to use int, you’ll find out why when we get to the end. We’ve spent enough time here, let’s move on.

    Code:
    printf("Hello World! C is teh pwnzorz!!!1!one!\n");
    This calls the printf() function. This function’s located in the stdio.h header file, and it contains the information to make the machine print out a string in the console. You need to give printf() something called an argument, which it then prints to the screen, in this case "Hello World! C is teh pwnzorz!!!1!one!\n" (note the quotes, it’s a string, so it has to be placed in quotes. Also, the \n means “new line”, basically the same as hitting enter). Moving on…

    Code:
     return 0;
    }
    Ok, I promised I’d tell you why you normally want to use int for the type of main(), and I’m a man of my word, so here it is. Every function has to return something (even void, which returns a null value, which stands for nothing. Confusing, I know, but think of it as kinda like the concept of zero). If you were using void, you’d just type return; here. But the reason it’s a good idea to use int is because if you return 0;, then it tells you the program terminated successfully, and if you return 1; it means your program failed. It’s just cleaner that way. Oh yeah, and you have to add a bracket at the end to signify the end of your function. That’s it! Now you would compile the code and then execute the binary that is produced. If you were compiling for a windows machine under visual studio or something like that, you would get something like this:



    I know it was long winded, but I hope that this episode was enough to help get even the most n00bliest of n00bs comfortable with what we’re doing before moving on to the psp. In the next episode, we’ll look at setting up a project in cygwin, and “porting”, if you can call it that, the above example so that we can compile it and run it on a psp! Hopefully this is a useful resource for people. See you next time, same bat-time, same bat-place.
    Before you post please
    Read the sticky's Read the manual Use the search button Google it

    Drizzle's so cool he sh*ts icecubes.
    Reply With Quote  
     

  3. #3  
    Senior Member PSP Elite Hacker
    Join Date
    Dec 2005
    Posts
    1,595
    nice...once i fully understand lua, i might make one for LUA.

    JOIN CYBERNATIONS!!-www.cybernations.net
    Reply With Quote  
     

  4. #4  
    Senior Member I Modded My PSP lead2gold's Avatar
    Join Date
    Aug 2006
    Posts
    359
    yea nice job n8

    i already installed the Cygwin a while ago, but i had to do it twice...
    the default settings do NOT include the devtools...

    The installer is smart enough to pick up all the dependancies if you miss one which is good too.

    Nice post!
    Reply With Quote  
     

  5. #5  
    Senior Member PSP Elite Hacker
    Join Date
    Jul 2006
    Posts
    1,794
    thanks, yeah, I got a 4 day weekend this week, so I should have time to write up episode 2 and episode 3, lol. I was thinkin about makin episode 2 a simple primer to C++, and then finally get into the psp stuff in episode 3, what do you think?
    Reply With Quote  
     

  6. #6  
    Senior Member I Modded My PSP lead2gold's Avatar
    Join Date
    Aug 2006
    Posts
    359
    "We're not worthy! We're not worthy!" - Wayne and Garth

    in all seriousness, no one is going to complain to that man
    Reply With Quote  
     

  7. #7  
    Senior Member PSP Elite Hacker
    Join Date
    Jul 2006
    Posts
    1,794
    lol, I loved those movies, but yeah, I think for episode 2 I'm gonna pick apart a simple hello world program for C, that way people will better understand what's going on when we get to the psp stuff instead of just saying "you type this in just cuz that's what you do", i hate it when people do that, cuz it really doesn't help the reader, and they won't be able to think critically to make unique programs...
    Reply With Quote  
     

  8. #8  
    Senior Member PSP Elite Hacker yaboyryan666's Avatar
    Join Date
    Jul 2006
    Posts
    1,531
    i tried doing this a while back, but no success.
    ░▒▓Dark_Alex▓▒░ is a PSP hacking GOD.
    Dark-Alex.org


    Reply With Quote  
     

  9. #9  
    Senior Member PSP Elite Hacker
    Join Date
    Jul 2006
    Posts
    1,794
    what issues were you having? I may be able to help you out.
    Reply With Quote  
     

  10. #10  
    Senior Member I Modded My PSP ll Teknyx ll's Avatar
    Join Date
    Mar 2006
    Posts
    407
    wow, very nice post n8, i wish i was smart like this
    I have defied gods and demons
    I am your shield, i am your sword
    I know you, your past, your future
    This is the way the world ends


    DevHook 0.46 Easy Installer
    Reply With Quote  
     

  11. #11  
    Senior Member PSP Elite Hacker
    Join Date
    Jul 2006
    Posts
    1,794
    that's why I'm making these tutorials, so you can be
    Reply With Quote  
     

  12. #12  
    Senior Member I Modded My PSP ll Teknyx ll's Avatar
    Join Date
    Mar 2006
    Posts
    407
    lol....but the problem is when i just look at it, its like trying to read chinese
    I have defied gods and demons
    I am your shield, i am your sword
    I know you, your past, your future
    This is the way the world ends


    DevHook 0.46 Easy Installer
    Reply With Quote  
     

  13. #13  
    Senior Member PSP Elite Hacker
    Join Date
    Jul 2006
    Posts
    1,794
    really? damn, I thought I made it noob-proof, my bad, well, if you want anything explained in more detail, feel free to ask and I'd be glad to help.
    Reply With Quote  
     

  14. #14  
    Junior Member
    Join Date
    Oct 2006
    Posts
    8
    me 2 so basicly u can run an emulater on ur cp?????-?????????
    Reply With Quote  
     

  15. #15  
    Senior Member I Modded My PSP Madd Kat's Avatar
    Join Date
    Nov 2006
    Posts
    312
    well yeas but more importantly a linux emulator

    C is not that bad , its like any programming language
    it takes time to learn, the more you know the more you learn.
    Iv been into VB for years, not that it compares..

    This will help me out a bit thanks.

    *EDIT

    i ment this will DEFFENTLY help me out alot..
    after reading threw 2 and 3 while this is installing
    im excited now!!

    thanks for all the info you rock.

    sense Im like a NOOOB in C/C++
    and most of my programming is Web development asp/vb/js ect...
    i dont think ill have anything cool to share for some time
    i did use vb 6 for along time too so i do understand alot of terms
    and stuff like that

    I may try to start by porting some small c apps
    and go from their. anyhoo thanks for putting the right info at our tips

    Jon


    I may be able to type, but spelling is something I forgot to learn...
    Reply With Quote  
     

Page 1 of 2 12 LastLast

Similar Threads

  1. Star wars episode 1 doesnt work ?
    By KKinsane in forum PSP Emulation
    Replies: 0
    Last Post: 11-25-2008, 01:04 AM
  2. PSP C programming tutorials: Episode 3
    By n8thegr8 in forum PSP Homebrew
    Replies: 18
    Last Post: 03-17-2007, 03:43 AM
  3. PSP C programming tutorials: Episode 2
    By n8thegr8 in forum PSP Homebrew
    Replies: 10
    Last Post: 10-18-2006, 06:58 PM
  4. Episode 19 of PSP Hacking 101
    By markcapo in forum PSP Homebrew
    Replies: 5
    Last Post: 09-01-2006, 12:23 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •