Converting to Eboot

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
ITDemo
Posts: 20
Joined: Sat Nov 17, 2007 8:08 am

Converting to Eboot

Post by ITDemo »

Hi, I am new to the programming side of the psp but i am learning C++,
I have a couple of questions to ask and i would be really thankful if they were answered.
1. How do you let the user input text or numbers.etc
2. Would this code be okay to convert over

Code: Select all

/* 
This is a simple but long conversion program. Made By Gavin Pacini at the age of 11 on the 25th and 26th of January 2008
*/

#include <iostream>
using namespace std;

float startvar, liquid, dis;
int money;
char color2&#91;80&#93;;

int main&#40;&#41;
&#123;
    
    cout << "To start please select a color,\nEnter the word color then a space then a letter from a-f followed by a number\nfrom 1-9, eg. color D5 &#40;enter&#41;\n";
    gets&#40;color2&#41;; // saves input for color
    system&#40;"pause"&#41;;
    
    start&#58;
    system&#40;"cls"&#41;;// clear screen
    system&#40;color2&#41;;// What color to display
    cout << "Hello and welcome to my easy conversion table, made by Gavin Pacini.\n"; // Welcome to program
    system&#40;"pause"&#41;;

    cout << "To start please press a number that matches your category.\n";
    cout << "Press&#58;\n 1 for money,\n 2 for liquid,\n 3 for distance.\n Follwed by Enter.\n"; // Start of table
    cin >> startvar;
    
    if &#40;startvar == 1&#41; goto money;
    if &#40;startvar == 2&#41; goto liquid;
    if &#40;startvar == 3&#41; goto distance; // goto statement for start
    
    
    // start of money table
    money&#58;
    cout << "Now what kind of currency do you want?\n";
    cout << "Press&#58;\n 1 for euro to dollar,\n 2 for euro to sterling,\n 3 for dollar to sterling,\n 4 for dollar to euro,\n 5 for sterling to euro,\n 6 for sterling to dollar.\n"; // ask for money table
    cin >> money;
    
    if &#40;money == 1&#41; goto ed;
    if &#40;money == 2&#41; goto es;
    if &#40;money == 3&#41; goto ds;
    if &#40;money == 4&#41; goto de;
    if &#40;money == 5&#41; goto se;
    if &#40;money == 6&#41; goto sd; // goto statement for money
    
    float ewd, d1, ews, s1, dws, s2, dwe, e1, swe, e2, swd, d2;
    
    
    //euro to dollar using $1
    ed&#58;
    cout << "Please enter an amount of euros.\n";
    cin >> ewd;
    d1 = ewd * 1.47;
    
    cout << "\nDollars&#58; " << d1 <<"\n";
    system&#40;"pause"&#41;;
    goto start;
    
    //euro to sterling using £1
    es&#58;
    cout << "Please enter an amount of euros.\n";
    cin >> ews;
    s1 = ews * .74;
    
    cout << "\nSterling&#58; " << s1 <<"\n";
    system&#40;"pause"&#41;;
    goto start;
    
    //dollar to sterling using £2
    ds&#58;
    cout << "Please enter an amount of dollars.\n";
    cin >> dws;
    s2 = dws * .504;
    
    cout << "\nSterling&#58; " << s2 <<"\n";
    system&#40;"pause"&#41;;
    goto start;
    
    //dollar to euro using €1
    de&#58;
    cout << "Please enter an amount of dollars.\n";
    cin >> dwe;
    e1 = dwe / 1.47;
    
    cout << "\nEuros&#58; " << e1 <<"\n";
    system&#40;"pause"&#41;;
    goto start;
    
    //sterling to euro using €2
    se&#58;
    cout << "Please enter an amount of sterling.\n";
    cin >> swe;
    e2 = swe * 1.34;
    
    cout << "\nEuro&#58; " << e2 <<"\n";
    system&#40;"pause"&#41;;
    goto start;
    
    // sterling to dollar using $2
    sd&#58;
    cout << "Please enter an amount of sterling.\n";
    cin >> swd;
    d2 = swd / 1.98;
    
    cout << "\nDollars&#58; " << d2 <<"\n";
    system&#40;"pause"&#41;;
    goto start;
    
    // End of money Table
    
    
    // Start of liquid Table
    liquid&#58;
    cout << "Now what kind of liquid do you want?\n";
    cout << "Press&#58;\n 1 for gallons to litres,\n 2 for gallons to pints,\n 3 for litres to gallons,\n 4 for litres to pints,\n 5 for pints to litres,\n 6 for pints to gallons.\n"; //asks for liquid table
    cin >> liquid;
    
    if &#40;liquid == 1&#41; goto gl;
    if &#40;liquid == 2&#41; goto gp;
    if &#40;liquid == 3&#41; goto lg;
    if &#40;liquid == 4&#41; goto lp;
    if &#40;liquid == 5&#41; goto pl;
    if &#40;liquid == 6&#41; goto pg;
    
    float gwl, l1, gwp, p1, lwg, g1, lwp, p2, pwl, l2, pwg, g2;
    
    //gallons to litres using l1 &#40;not 11&#41;
    gl&#58;
    cout << "Please enter an amount of gallons.\n";
    cin >> gwl;
    l1 = gwl * 3.7854;
    
    cout << "\nLitres&#58; " << l1 <<"\n";
    system&#40;"pause"&#41;;
    goto start;
    
    //gallons to pints using p1
    gp&#58;
    cout << "Please enter an amount of gallons.\n";
    cin >> gwp;
    p1 = gwp * 8;
    
    cout << "\nPints&#58; " << p1 <<"\n";
    system&#40;"pause"&#41;;
    goto start;
    
    //litres to gallons using g1
    lg&#58;
    cout << "Please enter an amount of litres.\n";
    cin >> lwg;
    g1 = lwg / 3.7854;
    
    cout << "\nGallons&#58; " << g1 <<"\n";
    system&#40;"pause"&#41;;
    goto start;
    
    //litres to pints using p2
    lp&#58;
    cout << "Please enter an amount of litres.\n";
    cin >> lwp;
    p2 = lwp / .454;
    
    cout << "\nPints&#58; " << p2 <<"\n";
    system&#40;"pause"&#41;;
    goto start;
    
    //pints to litres using l2 &#40;not 12&#41;
    pl&#58;
    cout << "Please enter an amount of pints.\n";
    cin >> pwl;
    l2 = pwl * .454;
    
    cout << "\nLitres&#58; " << l2 <<"\n";
    system&#40;"pause"&#41;;
    goto start;
    
    //pints to gallons using g2
    pg&#58;
    cout << "Please enter an amount of pints.\n";
    cin >> pwg;
    g2 = pwg / 8;
    
    cout << "\nGallons&#58; " << g2 <<"\n";
    system&#40;"pause"&#41;;
    goto start;
    
    //End of liquid table
    
    //Start of distance table
    distance&#58;
    cout << "Now what distance do you want?\n";
    cout << "Press&#58;\n 1 for Miles to Km,\n 2 for Km to Miles.\n";
    cin >> dis;
    
    float mwk, k1, kwm, m1;
    
    if &#40;dis == 1&#41; goto mk;
    if &#40;dis == 2&#41; goto km;
    
    // Miles to Kilmetres using k1
    mk&#58;
    cout << "Please enter an amount of miles.\n";
    cin >> mwk;
    k1 = mwk / .625;
    
    cout << "\nKilometres&#58; " << k1 <<"\n";
    system&#40;"pause"&#41;;
    goto start;
    
    // Kilometers to Miles using m1
    km&#58;
    cout << "Please enter an amount of kilometres.\n";
    cin >> kwm;
    m1 = kwm * .625;
    
    cout << "\nMiles&#58; " << m1 <<"\n";
    system&#40;"pause"&#41;;
    goto start;
    
    return 0;
    
&#125;


Please note that this is one of my first apps and works fine on the pc (only tried on windows).
I am using the PSPDev Win32 app and have updated it to the highest thanks in advanced.
Gavin/ITDemo
Last edited by ITDemo on Sat Feb 02, 2008 9:59 pm, edited 1 time in total.
Tinnus
Posts: 67
Joined: Sat Jul 29, 2006 1:12 am

Post by Tinnus »

You basically don't have cin, scanf or any of that in the PSP, but there are stuff like Danzeff's OSK (on screen keyboard) that are specially made for the PSP. I believe you can also use the built-in text entry screen (the onw that the XMB uses, eg. in the browser).

For that matter, there's also not cout. But there's a function called pspScreenDebugPrintf or something like that, that works just like printf from C (the equivalent to cout).

Now, about your coding. Do **** NOT **** use goto's unless you don't have another option. That leads to terrible and ugly code most of the time, where you cannot understand the flow of things. It seems your application could easily be converted to while loops (for going back to the start) and switch statements (used for executing code based on several values a variable could take, which is the perfect case here).

Oh, and don't use system("pause") since it only works in Windows (what you're doing is actually calling the "pause" program from Windows). Instead of that, you could use getchar() or something. But that also won't work in the PSP :) Not to mention all of the times you call this could easily be removed as well. Also, you should deduce that screen("cls") is as bad as, or a worse, idea :)

Now, from what I can see, it seems like you have a lot of potential to be a good programmer, but I'd really advise you to learn all of C++ first, or at least the standard stuff like for, switch, while, functions, etc. You can leave the object-orientation for later if it's too much for you to grasp.

When you feel you understand all of the ideas behind programming, and understand C/C++ good enough as well, get the PSP a go again. It's definately NOT a good idea to tackle a non-standard platform right at the beginning.
Let's see what the PSP reserves... well, I'd say anything is better than Palm OS.
ITDemo
Posts: 20
Joined: Sat Nov 17, 2007 8:08 am

Post by ITDemo »

KK thanks, just 2 more questions
How do you make the screen clear in the psp?(if you can)
and what peice of code do you use on the psp to let them input text? eg. cin,gets.etc
If you know that would be great if not it's ok
Oh and how do you make the makefile?? and i'm using PSP Dev Win32
Thanks again,
Gavin/ITDemo
Tinnus
Posts: 67
Joined: Sat Jul 29, 2006 1:12 am

Post by Tinnus »

There's a function with a name like the one for printf, that clears the screen, I think. You should read the docs in the SDK to see all of these functions.

The Makefile you write in a text editor... :) Use one of the samples in the PSPSDK to get started.

As I said, you usually get text input via something like Danzeff's OSK, that shows some letters where you have to press a direction + key (X, O, triangle and square) or the PSP's built-in text entry system. But usually (for example, in your application, or a game) you will do the most not to require any text input since the PSp was not made for that :)

In your case the best would be (I think) a clever use of functions to set the X and Y of the text output, combined with an arrow (like "->") before the current selection, instead of "1.aaa 2.bbb 3.ccc , input a number" like you do in your program.

Again, I *really* recommend you get going with all this stuff in a PC environment before.
Let's see what the PSP reserves... well, I'd say anything is better than Palm OS.
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

All those questions are answered in the examples and programs already out with source code. I suggest you look over the examples first for simple solutions, then move on to open source games and programs, then finally ask again over what remains uncovered (if anything).
ITDemo
Posts: 20
Joined: Sat Nov 17, 2007 8:08 am

Post by ITDemo »

Thanks guys i'll read through the SDK's while finishing the book on C++. And by the way the conversion program does work on Windows.
Thanks,
Gavin/ITDemo
Post Reply