Page 1 of 8 1 2 3 ... LastLast
Results 1 to 10 of 74

Thread: The Ultimate Start to Programming

  
  1. #1
    Stinkee2's Avatar
    Stinkee2 is offline Programmer -Hacks Hacker
    Join Date
    Jul 2009
    Location
    ಠ_ಠ
    Posts
    888
    Rep Power
    280

    Default The Ultimate Start to Programming

    Downloadable Tutorial
    The Ultimate Start To Programming.pdf - Thanks to Koetje

    Firstly:

    In this set of tutorials, I will be using some terms that you might not
    know. such terms will be in Yellow. at the end of each tutorial I will
    put a section for these words (In alphabetical order) and will explain
    what they do. If you have any confusion, post it here or even PM me
    if you really want to.


    Also, for now, this tutorial does not go into programming on the psp.
    however, I will soon be editing in a small section about some psp
    specific stuff that you need (or should) know about psp programming
    in order to program on it. I will do this as soon as I find the time I would
    need in order to do that.

    EDIT: I Added it.

    What is this about?
    Too many times I've seen people creating threads such as:

    "How do I start PSP Programming?"
    or
    "Please help me to make an awesome game" <- with no previous experience.


    and then they get shown the PSP dev tutorial and the OSLib tutorials
    by PSDonkey. Don't get me wrong, they are great tutorials. Just, do
    not immediately start learning them if you have no previous learning
    experience. you are almost bound to fail and give up because it's too hard.
    That is what this tutorial is for. It starts out not on the PSP, but with
    console applications.



    Why you may ask is it a bad idea to start with
    the PSPSDK and OSLib?

    Because you first need to know things like if statements and while
    loops and things BEFORE you start with Libraries.


    With that all being said This set tutorials will hopefully get you started
    on a good path to succession in programming given that you meet the
    requirements below. The real tutorial will start in my next post. This one
    is simply an introduction.

    Requirements:

    • Long attention Span
    • Determination
    • ABILITY TO USE A COMPUTER (Knowing terms like Directory, Path, Archive, .RAR)
    • Will Power
    • Time (a time that you have every day possibly, so you can continue to build up your skills without forgetting anything)


    Although, you should know:
    Reading these tutorials will NOT make you an expert on C OR C++. They
    only give you the basic knowledge that you should have before thinking
    about going and doing anything like using libraries or making games.

    I would not recommend attempting to make anything directly after
    finishing these tutorials other than to test your knowledge.

    Then after you've got this all down, start building up your skills by
    making more and more complex programs (not necessarily for the
    PSP either, although it would work. It's just annoying to not be able
    to run the application immediately after compiling it.)

    Terms Used:
    Library - A library is simply a set of files (.h, .c, .cpp) that will provide you
    with some sort of "help" in your software that you are developing, for
    example: OSLib is a library that provides you with Graphics, Sound, and
    other useful game development things.

    .h - Common Header file extension
    .c - extension for a source file written in C
    .cpp - Common extension for a source file written in C++

    Last edited by dbrums; 04-13-2013 at 12:21 PM. Reason: updating
    "PM Oyabun a bunch of gay pr0n and you're in." - ...BeAkEr... (BeAkErOo)

  2. #2
    Stinkee2's Avatar
    Stinkee2 is offline Programmer -Hacks Hacker
    Join Date
    Jul 2009
    Location
    ಠ_ಠ
    Posts
    888
    Rep Power
    280

    Default Tutorial 1: Getting Started

    Tutorial 1: Getting Started
    Judging by the fact that you are reading this text, Congradulations, you
    are about to get started on your journey learning C++!

    It's not an easy thing to do, and you deserve a high five .

    In this tutorial I will explain to you how to set up your IDE (Integrated
    Development Environment) for use with windows. the IDE you will be using
    is called Code Blocks. You will be downloading the version that comes with
    MinGW. MinGW is the Compiler that Code Blocks will be using to Compile all
    the code that we will be writing in these tutorials.

    Where To Download:
    http://www.codeblocks.org/ - Code Blocks web site.
    Download - The Code Blocks Installer with MinGW.

    After Installation
    As I said in the introduction to all this, I assume you have knowledge of
    how to use a computer. This means you know how to install a program.

    After the installation, it is necessary to create a folder in your
    Documents/My Documents directory. Name this folder "Code Blocks".

    This will be where we will be saving ALL our work that we will be doing
    together in the next tutorials.

    Now that that is all done, It is not necessary to do this but it is EXTREMELY
    helpful:
    Follow this tutorial I made for setting up Code Blocks with the PSPSDK
    http://www.psp-hacks.com/forums/f141...locks-t244336/

    But DON'T Download anything other than MinPSPw, ONLY do steps 3
    and 4 in that tutorial as all you will
    need to be doing is adding the PSPSDK include directories to the custom
    Code Blocks
    Compiler setting (Named "PSPSDK"). This step is essential if you want the
    intellisense
    to work. I STRONGLY recommend that you do this step.
    Step 4 in that tutorial is for the build script. which you WILL need. without
    it, you will have to build your source
    code manually. (EEEEK!)


    Terms Used:
    Compiler - A compiler in this case is a set of programs that will take your
    code and all the Libraries that it uses, and Makes it into a computer
    readable format.

    Function - A function is an "instruction" to do something, I guess would
    be a way to put it with out getting ahead of this tutorial. I will definately
    explain it better later on in these tutorials.

    IDE (Integrated Development Environment) - an IDE is the program (Code
    Blocks in this case) that we will be using as a code editor. An IDE is not
    only a code editor, but it also Compiles your code, Runs the executable,
    Highlights your code syntax to make it easier to read, and in this case,
    has Intellisense.

    Intellisense - Intellisense is sort of like google's Search Suggestion thing.
    If you don't know what I'm talking about: go to google, Start typing in
    "Why Wont My P", and you will see a small box come up underneath the
    Search Box with a list of things related to your entered text. Even if you
    do know what I mean, type that into google anyway, it's hilarious .

    The difference between Intellisense and Google's Search Suggestion is
    that Intellisense doesn't show related topics. Intellisense gives you a list
    of already defined content in the files you are using (such as functions).
    Here, Look at this screenshot to see what I mean:

    In this picture you see I started typing "pspd" and it brought up
    everything starting witn "pspD" in all the files I was using.
    Last edited by Stinkee2; 01-31-2011 at 01:09 AM.
    "PM Oyabun a bunch of gay pr0n and you're in." - ...BeAkEr... (BeAkErOo)

  3. #3
    Stinkee2's Avatar
    Stinkee2 is offline Programmer -Hacks Hacker
    Join Date
    Jul 2009
    Location
    ಠ_ಠ
    Posts
    888
    Rep Power
    280

    Default Tutorial 2: Understanding the Simplest of Programs

    Tutorial 2: Understanding the Simplest of Programs

    My goal at the end of this tutorial is for you to fully understand
    everything a simple hello world console application does, and some of the user interface of the Code Blocks IDE.

    Now that we have our IDE installed, you are ready to create a new
    project, and add some code to it.



    So, In Code Blocks, create a new project in your CodeBlocks directory you created in the last tutorial. Name this project "Hello World".






    Now that you got that all set up, take a look at this C++ code:

    Code:
    #include <iostream>
    using namespace std;
    int main()
        {
            cout << "Hello, World!" << endl;
            system("pause");
            return 0;
        }
    Copy that to your "Main.cpp" file and click compile. The compile button in code blocks is this: . It is at the top left


    If all went well, your output should look like that.

    Now for the explanations:
    The first line there is
    Code:
    #include <iostream>
    The #include part just tells the preprocessor that we are going to be
    "using" that library. The '#' symbol indicates that that line will be a
    preprocessor directive.
    Quote Originally Posted by msdn.Microsoft.com
    The #include directive tells the preprocessor to treat the contents of a
    specified file as if those contents had appeared in the source program at
    the point where the directive appears.
    The next line:
    Code:
    using namespace std;
    This line tells the compiler that we will be using the functionality of the namespace "std".

    Quote Originally Posted by cprogramming.com
    One of C++'s less heralded additions is addition of namespaces,
    which can be used to structure a program into "logical units". A
    namespace functions in the same way that a company division
    might function -- inside a namespace you include all functions
    appropriate for fulfilling a certain goal. For instance, if you had
    a program that connected to the Internet, you might have a
    namespace to handle all connection functions
    "std" is the name of the namespace that we will be "using". std I believe stands for "Standard Library".

    Now, here is the actual program:

    Code:
    int main()
        {
            cout << "Hello, World!" << endl;
            system("pause");
            return 0;
        }
    On the line where it says "int main()", we are defining the the main
    function, the entry point to the program. then, we use braces to
    show where the function definition starts and ends.

    on the next line, you see:
    Code:
    cout << "Hello, World!" << endl;
    "cout" is an instance of the ostream object in the standard library,
    when you use it with the "<<" operator and text, it writes that text
    to the screen by default.

    "endl" is tells cout that we want to end the line, and the semicolon at the
    end of the line absolutely HAS to be there. at the end of EVERY line in your
    source code, you will need to put a semicolon. unless you are defining functions. you can not do this:
    Code:
    int main();
        {;
            cout << "Hello, World!" << endl;
            system("pause");
            return 0;
        };
    you can however do it when you declare functions, like this:

    Code:
    void Print(); //Declaration
    int main()
        {
            Print();
            system("pause");
            return 0;
        }
    void Print() //Definition
    {
    cout << "Hello, World!" << endl;
    }
    now that second to last line, "system("pause");" tells the program that
    we want to execute a command prompt command, such as "cd" or "mkdir".
    basic .cmd and .bat stuff. in this case, we will use "pause" though so you
    can actually see your output.

    Why?

    Because if you don't, it will immediately go to the next line, "return 0;".
    and that line tells it to exit the program. so if you do not "pause" the
    program, it will run, then exit faster than the blink of an eye.

    Terms Used:
    declare - a declaration is an occurance of a function but not it's
    definition, you can not declare a function inside a function, you
    must put a semicolon at the end of a function declaration.

    defining - defining a function is just like defining a word, it tells
    about the function in a way, so that the compiler knows what
    to do when you call that function.

    entry point - the entry point is where the program starts, usually
    int main().

    hello world - usually, the first application programmed and ran by a new
    programmer, not always though. usually a good idea.

    operator
    Quote Originally Posted by cplusplus.com
    Once we know of the existence of variables and constants, we can begin
    to operate with them. For that purpose, C++ integrates operators. Unlike
    other languages whose operators are mainly keywords, operators in C++
    are mostly made of signs that are not part of the alphabet but are vailable
    in all keyboards. This makes C++ code shorter and more international, since
    it relies less on English words, but requires a little of learning effort in the
    beginning
    I will talk more about operators later in these tutorials, you do not need to know anything about them right now. .


    preprocessor - the preprocessor is a separate program, invoked by the compiler
    as the first part of compilation.
    preprocessor directive - an "instruction" sent to the preprocessor, ALWAYS
    starts with the '#' symbol, some preprocessor directives include:
    Code:
    #define Word Definition
    Defines "Word" as "Definition", all this tells the preprocessor to do is replace
    every occurance of "Word" with "Definition".
    Code:
    #include "Library.h"
    #include <Library.h>
    Tells the preprocessor to include the file Library.h from either the directory
    of the file containing the #include directive (the one with the quotes) or the
    compilers "Include" folders (the one with the < and >).
    Last edited by Stinkee2; 04-18-2010 at 11:24 AM.
    "PM Oyabun a bunch of gay pr0n and you're in." - ...BeAkEr... (BeAkErOo)

  4. #4
    Stinkee2's Avatar
    Stinkee2 is offline Programmer -Hacks Hacker
    Join Date
    Jul 2009
    Location
    ಠ_ಠ
    Posts
    888
    Rep Power
    280

    Default Tutorial 3: Data Types

    Tutorial 3: Data Types
    In this tutorial, I will teach the meaning of and how to use different types
    of variables.

    Quote Originally Posted by cplusplus.com
    When programming, we store the variables in our computer's memory,
    but the computer has to know what kind of data we want to store in them, since it is not going to occupy the same amount of memory to
    store a simple number than to store a single letter or a large number,
    and they are not going to be interpreted the same way.

    The memory in our computers is organized in bytes. A byte is the minimum
    amount of memory that we can manage in C++. A byte can store a
    relatively small amount of data: one single character or a small integer
    (generally an integer between 0 and 255). In addition, the computer can
    manipulate more complex data types that come from grouping several
    bytes, such as long numbers or non-integer numbers.
    Basic Types:
    int - Int stands for "Integer" and that is what it is... an integer.
    Integers take up 4 bytes in memory and can be equal to anything
    above -2147483648 and below 2147483648. you know, whole numbers..
    such as 1, 2 ,3, 1627, 5, -3, -543, etc...

    float - floating point number. floating point describes a system
    for representing numbers that would be too large or too small to
    be represented as integers. -Wikipedia
    such as: 1.3553412, 3.1415926, 9.80665, -688.579300.
    Takes up 4 bytes in memory.

    double - Double precision floating point number, takes up 8 bytes
    in memory.

    bool - A boolean value, can either be true or false. like 0 and 1 in
    binary. a boolean value is only 1 byte in memory.

    char - A single character, such as 'a','h','G','&','~',etc... Takes up
    1 byte in memory.

    Initialization of variables:
    When we first declare a variable (possibly one of the data types
    above), it is always a good Idea to initialize it. If we do not initialize
    the variable, it's initial value is undefined. which may not be what
    you want. To initialize a variable just means you are "setting its value"
    to something. Take a look at this example of initializing variables of the
    types I showed above:

    Code:
    int Integer = 0;
    float FloatingPointNumber = 25.125f;
    double Double = 45.0125;
    bool Boolean = true;
    char Character = 'C';
    Variables are usually initialized with the '=' sign, but can also be done with
    Parenthesis in C++. like, int Integer (0), or char Character ('$'). that usually
    isn't the case though. at least from what I've seen. You will use these data
    types very frequently in your source code. we will now take a look at one
    way that we can use data types in a program:
    Code:
    #include <iostream>
    using namespace std;
    int main()
        {
            int IInteger = 56927;
            int UInteger;
            cout << "This is the value of the initialized integer: " << IInteger << "." << endl;
            cout << "This is the value of the uninitialized integer: " << UInteger << "." << endl;
            system("pause");
            return 0;
        }


    Ok, Same old main(), cout, and << stuff there. except now you see the <<
    operator again, but with an integer. you can not only use << for text, but
    also variables .

    notice that the line it prints the uninitialized integer (UInteger) on. It says
    4246660. make sure you always initialize your variables at some point before
    using them, yes, that means you can initialize varialbes on seporate lines:
    Code:
    #include <iostream>
    using namespace std;
    int main()
        {
            int IInteger;
            int UInteger;
            IInteger = 987623;
            cout << "This is the value of the initialized integer: " << IInteger << "." << endl;
            cout << "This is the value of the uninitialized integer: " << UInteger << "." << endl;
            system("pause");
            return 0;
        }
    Constant Variables:
    In C++, a constant variable is... well... constant. It never changes, and an
    attempt to do so will invoke a compiler error:
    error: assignment of read-only variable '(Variable Name)'

    What's the point?
    Say you have a variable that you need to stay the same throughout the
    whole program. such as gravity, the gravity on earth pulls things in generally
    at about 9.80665 meters a second, so you declare a constant float with
    that value, and it will never change throughout the whole program.
    Code:
    const float Gravity = 9.80665;
    Variable Arrays:
    A variable array is an array of a certain kind of variable. "What is an array?"
    you might ask... An array is a "Collection" of variables of a certain size,
    can be VERY helpful while programming. to declare an array of a variable,
    you can either use brackets ([ ]) or the asterisk (*).
    Quote Originally Posted by cplusplus.com
    An array is a series of elements of the same type placed in contiguous
    memory locations that can be individually referenced by adding an index
    to a unique identifier.

    That means that, for example, we can store 5 values of type int in an
    array without having to declare 5 different variables, each one with a
    different identifier. Instead of that, using an array we can store 5
    different values of the same type, int for example, with a unique
    identifier.

    For example, an array to contain 5 integer values of type int called
    billy could be represented like this:

    where each blank panel represents an element of the array, that in this
    case are integer values of type int. These elements are numbered from
    0 to 4 since in arrays the first index is always 0, independently of its length.
    In that explanation of arrays, cplusplus.com made an array of 5 integers
    called billy, but you only see up to 4. this is because it starts at 0. but
    look, there are 5 boxes. That array would have been declared like this:
    Code:
    int billy[5]
    Notice how the size of the array is in the braces. another way that this
    could have been done is like this:
    Code:
    int billy[] = {0,1,2,3,4}
    That initializes an array of 5 variables with the variables 0,1,2,3, and 4.

    In this example, It shows how to use * with char to make an array of
    characters (AKA: a string).
    Code:
    #include <iostream>
    using namespace std;
    int main()
        {
            const char *CharArray = "Look, I'm a Character array!";
            cout << CharArray << endl;
            system("pause");
            return 0;
        }
    That is an array of characters and its size is 29. if you count the letters
    (including the spaces) you will see only 28. At the end of a string there is
    an "invisible" character, a NULL character, this character looks like this: "\0"
    as a string or '\0' as a single character. the '\' indicates that it is an escape character.

    Terms Used:
    Escape Character - Certain special characters are represented as escape
    sequences. An escape sequence begins with a '\' (backslash) followed by an
    alphanumeric character. For example, the '\n' escape sequence represents
    the newline character. Note that the two characters of an escape character
    are used as a single character. - Devx.com

    Null - Null means "Nothing", "empty", or "undefined". it is used in strings by
    the escape character '\0' to indicate that is the end of the string.
    Last edited by Stinkee2; 04-18-2010 at 06:46 PM.
    "PM Oyabun a bunch of gay pr0n and you're in." - ...BeAkEr... (BeAkErOo)

  5. #5
    Stinkee2's Avatar
    Stinkee2 is offline Programmer -Hacks Hacker
    Join Date
    Jul 2009
    Location
    ಠ_ಠ
    Posts
    888
    Rep Power
    280

    Default Tutorial 4: if, else, while, for

    Tutorial 4: if, else, while, for
    This tutorial will help you learn how, when, and why to use if, else, while, and for statements.

    Lets get started with the if statement, shall we?

    if
    an "if" statement is exactly what it sounds like, kind of. an "if" statement
    performs a task, only if a specified "test" evaluates to true (bool). this
    "test" goes within the parenthesis for the if statement, and you use it sort
    of like you would a function. look at this example:
    Code:
    if(This Is The Test)
    {
        //Perform some Task here
    }
    There, inside the if statement's parenthesis, is the test. and ANYTHING can
    go there, as long as it eveluates to either true or false. this means you can
    test if two integers are equal, if a float is below a certain point.. anything
    you can think of.

    these are all operators that you can use in if statements (or any other form of boolean test):
    - < : Less than : if(Val1 < Val2)
    - > : Greater than : if(Val1 > Val2)
    - <= : Less than or equal to : if(Val1 <= Val2)
    - >= : Greater than or equal to : if(Val1 >= Val2)
    - == : Equal to : if(Val1 == Val2)
    - != : is Not equal to : if(Val1 != Val2)
    - ! : Not something : Read below.
    - && : And : if(Val1 < Val2 && Val2 >= 0)
    - || : Or : if(Val1 > Val2 || Val2 == 0 || Val1 < 0)

    The ! sign
    In if statements, the '!' sign is very useful, in a "can only do one thing"
    kind of way... the '!' sign can be used to... it's hard to explain. basically
    it means NOT something, like if you have a test that evaluates to false:
    Code:
    Integer1 <= 100 && Integer1 >= 0 //Say Integer1 is 47. or anything between 0 and 100
    If you want to see if that is false instead of true, you would use the '!'
    sign. in order to do that for both tests though, you need to put them
    both in parenthesis and then put '!' in front of it:
    Code:
    !(Integer1 <= 100 && Integer1 >= 0)
    in an if statement, that would look like this:
    Code:
    if(!(Integer1 <= 100 && Integer1 >= 0))
    if you do not enclose the tests, you will need to put a '!' in front of both
    of then individually and should enclose both tests in parenthesis like this:
    Code:
    !(Integer1 <= 100) && !(Integer1 >= 0)
    I hope this helped you understand if statements, Now it is time to move on
    to else.

    else
    Else can only be used in conjunction with the if statement, like this:
    Code:
    if(Val1 != Val2)
    {
         //Do Something
    }
    else
    {
         //Do Something Else
    }
    Else does "something" else if the if statement's test does not evaluate to
    true. so in the code above, if Val2 was equal to Val1, it would do the else
    code, not the if code.
    else if
    else if is the same as else, except it tests something else. look at this code:
    Code:
    if(Val1 + 5 >= Val2)
    {
         //Do Something
    }
    else if(Val1 + 10 >= Val2)
    {
         //Do Something only if: Val1 + 10 >= Val2
    }
    I don't think that needs any further of an explanation, if there is any
    confusion, please tell me and I will add a more detailed explanation .
    while
    The while loop is a VERY important part of any Game / Application
    written in C or C++. the while loop is sort of like an if statement, only
    with a while loop it executes the code over and over again until a break
    statement occurs, or if the test evaluates to false.

    A break statement tells the loop to quit and thats all it does, just put
    "break" somewhere and if it gets executed the loop will stop.

    Look at this example:
    Code:
    #include <iostream>
    using namespace std;
    int main()
        {
            int Var = 0;
            while(Var <= 20)
            {
                cout << "Var: " << Var << "." << endl;
                Var++; //Increment Var.
                if(Var == 15) break; //Break if Var is equal to 15.
            }
            system("pause");
            return 0;
        }
    in that code, I create an integer named Var, initialize it to 0, and then
    Increment (defined below) it in the while loop over and over. Notice in the while loop
    test that it says Var <= 20. This means if Var goes above 20, the test
    will evaluate to false, and the while loop will stop looping. but you also
    see that it will break if Var is ever equal to 15, so it will never reach 20.
    you can fiddle around with that and increase the 15 to 45 and 20 to 60.
    whatever floats your boat.

    Increment (operator ++) - To increment an integer (or float, or
    double,...)
    means to just increase it by one.

    Decrement (operator --) - To decrement a variable means to just decrease
    its value by one.


    Here is the output of that program:


    do while
    Do while isn't much different from while, only it performs the loop before checking if the test is true or false. it is done the same way, except you
    put do in place of the while and you put the while (including its test) at
    the end of the loop (with a semicolon):

    Code:
    #include <iostream>
    using namespace std;
    int main()
        {
            int Var = 0;
            do
            {
                cout << "Var: " << Var << "." << endl;
                Var++; //Increment Var.
                if(Var > 15) break;
            } while(Var <= 20);
            system("pause");
            return 0;
        }
    now, this is the new output:



    Notice now it goes up to 15 instead of 14.
    for
    a for loop is also an extremely important part of programming, it works the
    same as a while loop escept it is a little different. mathbits.com can explain
    it much better than I could:
    Quote Originally Posted by mathbits.com
    The statements in the for loop repeat continuously for a specific
    numberof times. The while and do-while loops repeat until a
    certain condition is met. The for loop repeats until a specific count
    is met. Use a for loop when the number of repetition is know, or can
    be supplied by the user. The coding format is:

    Code:
    for(startExpression; testExpression; countExpression) { block of code; }
    The startExpression is evaluated before the loop begins. It
    is acceptable to declare and assign in the startExpression
    (such as int x = 1;). This startExpression is evaluated only
    once at the beginning of the loop.

    The testExpression will evaluate to TRUE (nonzero) or FALSE
    (zero). While TRUE, the body of the loop repeats. When the
    testExpression becomes FALSE, the looping stops and the
    program continues with the statement immediately following
    the for loop body in the program code.

    The countExpression executes after each trip through the loop.
    The count may increase/decrease by an increment of 1 or of some
    other value. Braces are not required if the body of the for loop
    consists of only ONE statement. Please indent the body of the loop
    for readability.
    Look at this example of a for loop I've written for you:
    Code:
    #include <iostream> 
    
    using namespace std; int main() { for(int Var = 0;Var <= 20;Var++) { cout << "Var: " << Var << "." << endl; if(Var > 15) break; }
    system("pause"); return 0; }

    in the "Start Expression", I create the integer "Var" again.
    in the "Test Expression", I test to see if "Var" is less than or equal to 20.
    in the "Count Expression", I increment "Var".

    Here is the output of that program:

    That is If, else, while, and for put simply. .

    Terms Used:
    // - this is a line comment, it is used to take note of something. line
    comments are completely ignored by the compiler. nothing you put
    in a comment means anything other than a helpful note. a line comment
    can only on ONE line though and it has to be after the "//".

    there is one other type of comment, it's called a comment block I
    think, this is how it's done:
    Code:
    /* <--- Start of comment Block * anything can go here, these * lines mean nothing to the compiler. * however, you do not need to * put the asterisks in the center * like this, it is only necessary in * the start and end of the comment * block. */ <--- End of comment Block
    Last edited by Stinkee2; 04-29-2010 at 12:15 PM.
    "PM Oyabun a bunch of gay pr0n and you're in." - ...BeAkEr... (BeAkErOo)

  6. #6
    Stinkee2's Avatar
    Stinkee2 is offline Programmer -Hacks Hacker
    Join Date
    Jul 2009
    Location
    ಠ_ಠ
    Posts
    888
    Rep Power
    280

    Default Tutorial 5: Completion

    Tutorial 5: Completion
    This is the final tutorial in this set of tutorials, I hope that all this helped
    helped you get a good, basic idea about C++ programming. With these
    tutorials, you now have the knowledge you need to have a successful
    programming life given you have the requirements I stated in the introduction.


    Since the title wasn't very specific about what this tutorial is for, here is
    a better one:

    Tutorial 5: Functions
    In this tutorial you will learn how to create your own functions for use with
    your programs (and other people's if you publish them...).


    As promised in the first tutorial, here is a better explanation of functions:

    Quote Originally Posted by cplusplus.com
    Using functions we can structure our programs in a more modular way,
    accessing all the potential that structured programming can offer to us
    in C++.

    A function is a group of statements that is executed when it is called
    from some point of the program.
    A function can have as many parameters of any type as you want, that
    is the beauty of it.

    Parameters for functions are like arguments to a command prompt command.
    Each parameter consists of a data type specifier followed
    by an identifier, like any regular variable declaration (for example: int x)
    and which acts within the function as a regular local variable. They allow
    to pass arguments to the function when it is called. The different
    parameters are separated by commas.

    in order to keep your code looking neat and organized, it is a good idea
    to have your functions declared at the top, in front of "main()". that is,
    if you must have them even in the same file as "main()". in my opinion,
    it is a good Idea to keep functions & such in seporate files to keep everything
    neat looking and easy to read.

    this is definately not needed, but I think it plays a big part in discouraging
    you to your quitting point when you have a really really long main file filled
    with functions that is hard to read and disorganized. This solves that problem.

    look at this example:
    Code:
    #include <iostream>
    using namespace std;
    int AddInts(int Int1,int Int2);//Declaration
    int main()
        {
            cout << "5 + 5 = " << AddInts(5,5) << "." << endl;
            system("pause");
            return 0;
        }
    int AddInts(int Int1,int Int2)//Definition
        {
            return Int1 + Int2;
        }
    I am going to take apart the function declaration and define what the parts
    are:

    "int AddInts" - Function name and type. This is important, the function
    return value must be the same as the function type.

    "(int Int1,int Int2)" - Parameter list, these variables can be used anywhere
    in the function. the parameter list, as stated above, can have as many
    parameters as you want, of ANY time.

    the return value of a function is very important, and if you do not return
    a value at all, the compiler will throw a warning at you:
    "warning: control reaches end of non void function"

    if your function is of type const char *, you could return a string (such as:
    "This is a function return" or "Hello").
    if your function is an int, you could return 2, 5, or 7. or a variable of type int.

    you can make a function for ANYTHING and you can make it do WHATEVER
    you want, C++ and Computer Science are amazing things, think of the
    accomplishments we have made with it, think about Artificial Intelligence,
    How a program interacts with an operating system.

    Programming is a long, complex road, And if you jump out of the car, you will
    get injured. ask yourself, are you going to get in to the car?

    Spoiler:

    What I mean by that is, the path to becoming a programming expert is long,
    and if you quit, you might have to start all over. that is, if you decide to
    even come back to it.


    Good luck on your stay in the programming world, you will need it .

    Spoiler:

    Also a fuck load of patience.


    Tutorial 6: Moving on to the PSP
    Now that you have the basic programming knowledge, if you choose (I
    don't advise it) you may start PSP programming.

    Spoiler:

    The reason I don't advise it is because it is just so much simpler and
    faster to experiment on the computer with programming. no callbacks or
    anything (unless you're not doing basic stuff, in which case you probably
    don't need this tutorial ).


    The first think I should show you is how to set up a basic psp program,
    "HelloWorld" again.


    Start a new project in Code Blocks, Name it PSP Hello World or something.
    and make sure you are using the PSPSDK compiler made in the part of the
    "Setting up MinPSPw with CodeBlocks" tutorial you should have followed (I
    showed it to you in the first post)

    Now that you have that project all open and stuff, Create a new file
    named "CallBacks.h" and stick this code in it:
    Code:
            int ExitCallback(int Arg1, int Arg2, void *Common)
                {
                    sceKernelExitGame();
                    return 0;
                }
            int CallbackThread(SceSize Args, void *Argp)
                {
                    int CallbackId;
                    CallbackId = sceKernelCreateCallback("Exit Callback", ExitCallback, NULL);
                    sceKernelRegisterExitCallback(CallbackId);
                    sceKernelSleepThreadCB();
                    return 0;
                }
            int SetupCallbacks(void)
                {
                    int ThreadId = 0;
                    ThreadId = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
                    if(ThreadId >= 0)
                    {
                        sceKernelStartThread(ThreadId, 0, 0);
                    }
                    return ThreadId;
                }
            void InitPSP()
                {
                    SetupCallbacks();
                    pspDebugScreenInit();
     
                }
    Those are the callbacks that you might hear a lot about if you have read
    or have tried to start psp programming before. These are important ONLY
    if you want to be able to exit the game with the Home->Exit game menu
    on the psp if I'm not mistaken. I do not feel I need to explain threads and
    such here. If you are interested in learning about threads, google it .


    Now we are going to #include the file you just made (CallBacks.h) from
    the main file that you are going to create (main.cpp).

    Create main.cpp in the same directory as CallBacks.h and put this code in
    it:

    Code:
    #include <psptypes.h>
    #include <pspkernel.h>
    #include <pspdebug.h>
    #include <pspdisplay.h>
    #include "CallBacks.h"
     
    int main()
         {
              InitPSP(); //Initialize the Callbacks
              while(true) //Main Loop
              {
                    //Print HelloWorld
                    pspDebugScreenPrintf("Hello World");
                    /*
                     * So that the screen does not flicker, we must wait for 
                     * the screen to finish drawing before we clear it and write
                     * to it again. if the drawing rate is > the screen refresh rate
                     * then the screen will appear to be flickering. and in this case
                     * since this is so simple it will have a drawing rate of WELL
                     * over the screen refresh rate (60Hz: 60 refreshes a second)
                     */
                    sceDisplayWaitVblankStartCB();
                    /*
                     * Clear the screen before we write again, or else it will fill up
                     * the screen with a bunch of "HelloWorld" and it won't stop.
                     */
                    pspDebugScreenClear();
              }
         }
    I believe the comment blocks speak for all that code, Now I have nothing
    to explain down here . .

    That is the most basic of all PSP programs, If you truely don't want to
    even touch programming on anything other than the psp than I will help
    you no further . Google is your friend .

    Terms Used:
    CallBack -
    Quote Originally Posted by Wikipedia
    In computer programming, a callback is a reference to executable code, or a
    piece of executable code, that is passed as an argument to other code. This
    allows a lower-level software layer to call a subroutine (or function) defined
    in a higher-level layer.
    Again, It was put better there than it would have been if I tried to explain
    it for you .

    Now that you're all hot off the programming grill, why don't you go test your
    programming knowledge by making a few simple console applications for both
    the PC and PSP.

    When you're done experimenting I suggest you read my next tutorial, here:
    http://www.psp-hacks.com/forums/f141...phism-t261299/
    Last edited by Stinkee2; 06-07-2010 at 12:36 AM.
    "PM Oyabun a bunch of gay pr0n and you're in." - ...BeAkEr... (BeAkErOo)

  7. #7
    ZiNgABuRgA's Avatar
    ZiNgABuRgA is offline Senior Member -Hacks Titan
    Join Date
    Sep 2006
    Location
    4CHIN
    Posts
    11,044
    Rep Power
    24

    Default

    Nice guide - did you want this to be kept in this forum though?

    Scanning over it, I did notice this:
    Code:
    !Integer1 <= 100 && !Integer1 >= 0
    Perhaps a bit confusing as the operator order isn't exactly obvious (I cannot remember what it is here).
    I'm guessing you mean:
    Code:
    !(Integer1 <= 100) && !(Integer1 >= 0)
    rather than the not's being applied before the comparison

  8. #8
    Scorpus is offline Senior Member -Hacks Titan
    Join Date
    Jan 2008
    Location
    Australia
    Posts
    4,778
    Rep Power
    289

    Default

    Fantastic work. You might want to add that after following this guide you will NOT end up with a PSP homebrew app

    -Stickied-

  9. #9
    Stinkee2's Avatar
    Stinkee2 is offline Programmer -Hacks Hacker
    Join Date
    Jul 2009
    Location
    ಠ_ಠ
    Posts
    888
    Rep Power
    280

    Default

    Quote Originally Posted by ZiNgABuRgA View Post
    Nice guide - did you want this to be kept in this forum though?

    Scanning over it, I did notice this:
    Code:
    !Integer1 <= 100 && !Integer1 >= 0
    Perhaps a bit confusing as the operator order isn't exactly obvious (I cannot remember what it is here).
    I'm guessing you mean:
    Code:
    !(Integer1 <= 100) && !(Integer1 >= 0)
    rather than the not's being applied before the comparison
    Nope, Scorpus said he would move it once it was finished . and Whoops, you're right, I changed it .

    Quote Originally Posted by Scorpus
    Fantastic work. You might want to add that after following this guide you will NOT end up with a PSP homebrew app

    -Stickied-
    I don't think I have to now that you just said it but I will add it to the top anyway as soon as I get out of school. and I will possibly edit a 6th tutorial in to the post for the 5th one for making a first psp application (explaining the callbacks and whatnot).
    "PM Oyabun a bunch of gay pr0n and you're in." - ...BeAkEr... (BeAkErOo)

  10. #10
    Organized_Chaos's Avatar
    Organized_Chaos is offline Senior Member -Hacks Titan
    Join Date
    May 2008
    Posts
    4,768
    Rep Power
    53962

    Default

    Nice guide, I'm glad you got it finished and stickied
    This is all the motivation I need to start learning how to program again. Thank you

Page 1 of 8 1 2 3 ... LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •