BLOG main image
LoofBackER's Blog
Jun - Sik , Yang Blog

'PSP Programming'에 해당되는 글 3건

  1. 2008.02.10 PSP programming
  2. 2008.02.10 PSP Programming Tutorial - Lesson 2
  3. 2008.02.10 PSP Programming Tutorial - Lesson 1

PSP programming

분류없음 2008.02.10 23:59 by LoofBackER

출처 : http://blog.naver.com/midgardhr?Redirect=Log&logNo=19261638
<참고자료>
스크랩한 psp 개발 방법
psp-programming.com
pspdev.org
PSP Development Forum


PSP 프로그래밍을 시작해보자.


먼저 이 문서는 http://wiki.ps2dev.org/ 을 기반으로 제작되었다는 점을 명시해둔다.

이 문서를 보고 필자가 따라한 것을 다시 요약한 것이다.

위 홈페이지의 Programming FAQ를 보면 영어 문서로 자세히 설명되어 있다.


PSP SDK는 현재 Unix 기반으로 나오고 있기 때문에

Windows를 쓰고 있다면 Cygwin을 설치하는 일부터 해야한다.

물론 윈도우용 개발 도구도 있는 것 같기는 하지만, 공개용 같지 않다.


Cygwin은 http://www.cygwin.com/ 에서 다운받을 수 있다.

여기서 다운받을 수 있는 cygwin은 전체 설치 파일이 아니고,

실행한 이후 스스로 다운받아 설치하는 버전이다.

기본적으로 기본 옵션대로 설치하지만, 기본 옵션에 없는 2가지를 반드시 설치해야 한다.


첫째로는 Devel을 skip하게 되어있는데 이것을 install로 바꿔주어야 한다.

바꾸는건 skip를 클릭하다보면 글자가 바뀌는데 install이 될 때까지 클릭하면 된다.

필자가 설치했을 때는 1번만 클릭하면 되었었다.


두번재로는 wget를 설치해야 한다. 이것도 Devel과 비슷하게 하면 되는데

install이 아니라 버전 번호가 뜨도록 해주면 된다.


이 두가지는 필수이고, Vim을 사용하기 원하는 사용자는

Editor에서 Vim을 비슷한 방식으로 설치해주면 된다.

Vim도 버전 번호가 뜬다.


그림과 함께 설명하면 좋겠으나, 현재 여건이 여의치 않은 관계로 나중에 추가하기로 한다.


이렇게 하고 기다리면 알아서 다운받고 설치한다.

설치가 다 되면 바탕화면의 cygwin을 한번 실행해보자.

프롬프트가 잘 뜬다면 된것이다. exit를 입력하고 엔터를 치면 자동으로 빠져나온다.


이 실행 과정은 한번 하는게 좋은데, 문제점을 확인하기 위해서도 그렇고,

cygwin은 처음 실행했을 때 home/(Username)의 폴더를 생성한다.

이 폴더에 주로 파일을 넣게 되므로 이후의 과정으로 넘어가기 전에 한번쯤 실행해주는게 좋다.


이제 toolchain을 설치하자.

toolchain은 psp 프로그래밍하는데 필요한 컴파일러와 sdk 등등이다.

http://www.oopo.net에서 다운받을 수 있는데 psp의 toolchain을 받으면 된다.

ps2용 toolchain도 있다.


다운 받은 파일을 home/(Username) 폴더에 넣자. Username은

아마 윈도우 사용자의 이름으로 되어있을 것이다.

여기에 파일을 복사하고 다음과 같이 입력한다.


$ tar xfvz psptoolchain-20050712.tgz

앞의 $는 입력하는 것이 아니라 프롬프트를 나타낸다.

tar부터 입력하면 된다.

이 명령어는 압축을 풀라는 명령어이고, 뒤의 xfvz는 옵션을 주는 부분인데,

지금은 몰라도 된다.

그리고 뒤의 20050712.tgz는 toolchain의 버전에 따라 다르므로,

파일 이름에 있는 그 날짜를 넣으면 된다.


다음으로는

$ cd psptoolchain 으로 들어가서 압축을 푼 폴더에 들어가고

$ chmod a+x ./toolchain.sh 을 실행한 후

$ ./toolchain.sh 를 실행하면 된다.


한줄씩 보면 첫줄은 폴더에 들어가라는 의미이고

두번째 줄은 권한 변경이라고 할 수 있는데, toolchain.sh라는 파일의 속성을

변경하는 것이라는 정도만 알면 되겠다.

마지막줄은 파일을 실행시키는 명령어로, 이 명령이 실행되면

일차적으로 할 일은 다 끝난 것이다.


./toolchain.sh는 여러가지 명령을 순차적으로 처리하는데

시간이 굉장히 오래 걸린다.

어디선가 누군가가 쓴 글에 따르면 3시간 정도 걸렸다고 한다.


이 스크립트 파일을 열어보면 wget을 통해 파일을 다운로드하는 부분이 있는데

이 다운로드가 상당히 느리고, 끊어지는 경우도 많다.

다만 파일이 이미 존재하면 그냥 넘어가는데

파일을 받는 도중 끊어져서 명령 수행이 종료될 경우

다시 실행하면 파일 다운로드가 완료된 것으로 간주, 그냥 다음으로 넘어가므로

뒤에서 문제가 생긴다.

따라서 Flashget과 같은 다운로드 전용 프로그램을 이용,

주소를 붙여 다운로드를 미리해서

폴더에 미리 넣어주면 좋다. 다운로드하는 파일은 4개밖에 없으므로

크게 번거롭지도 않다.


이 작업이 끝나면 환경변수를 설정해야한다.

먼저 어느 위치에 있든지간에 cd를 입력하면 자신의 홈 디렉토리로 이동한다.


$ vim .bashrc를 입력하면 환경변수를 설정하는 파일에 들어가게 된다.

(vim을 사용하지 않는다면 .bashrc파일을 cygwin의 home/(사용자이름) 폴더에서 열어서 수정한다.)


맨 마지막에 다음 세 줄을 추가한다.


export PSPDEV="/usr/local/pspdev"
export PSPSDK="$PSPDEV/psp/sdk"
export PATH="$PATH:$PSPDEV/bin:$PSPSDK/bin"

주로 PATH를 설정하는 것이므로 내용은 신경쓰지 않아도 된다.

:wq를 입력하면 저장하고 빠져나온다.

물론 메모장이나 워드패드를 이용해도 된다.


이제 exit를 입력해서 빠져나가고 다시 실행하자.

(bashrc의 변경사항을 적용시키기 위해서다.)


$ psp-gcc -v 를 입력하자.


Using built-in specs.
Target: psp
Configured with: ../configure --prefix=/usr/local/pspdev --target=psp --enable-languages=c,c++ --with-newlib --enable-cxx-flags=-G0
Thread model: single

gcc version 4.0.0

위와같은 메세지가 보이면 성공적으로 마쳐진 것이다.


다음 번에는 HelloWorld를 출력하는 간단한 어플리케이션을 작성해보도록 하자.


출처 : http://blog.naver.com/midgardhr?Redirect=Log&logNo=19261638

신고
크리에이티브 커먼즈 라이선스
Creative Commons License

PSP Programming Tutorial - Lesson 2

분류없음 2008.02.10 23:50 by LoofBackER

Lesson 02

Creating Your First Program

A walkthrough of the setup, creation and execution of a simple "Hello World" application on the Sony PSP

So, after reading Lesson 01, you have a working development environment in which to create your programs. Now what? Well, this is the part you've all been waiting for, your very first program for the PSP. This tutorial will explain the basics of the C programming language and build the foundation upon which you will build your kingd-- err... programs.

We're going to create a folder hierarchy to organize our projects. Open up a CYGWIN bash shell, and type "mkdir projects" and then hit enter. This command ("mkdir") stands for "make directory" and it will create a directory, or folder, in your current operating directory. So now we have a new folder for all of our projects, navigate into it by typing "cd projects" and hitting enter. Now we are going to create another directory for this specific project. Type "mkdir helloworld" and hit enter. Now switch into the new directory with "cd helloworld."

The next step is to open up a text editor. It doesn't really matter what you open, it can be Notepad, Wordpad, whatever you want. I prefer using an editor that is dedicated to editting C/C++ source code because of the syntax highlighting options that are built in (I use Dev-C++), but honestly, it doesn't matter (so long as you know how to use it).

Now, create a new file and call it "main.c" in our "helloworld" directory. This is going to contain the source code for our program. For those of you who don't know what source code is (and I know there will be a few), the source code is what we write to create a program. It is written in a way that humans can understand. In most languages, the source needs to be converted to a format the computer (or in our case, the PSP) can understand. These are called compiled languages, and C and C++ fall into this category (the conversion is done by the compiler that we set up in Lesson 01). There are a few other programming languages that use what is called an interpreter to interpret the source code and send out machine code on the fly. These are called scripting languages (an example of a scripting language is PHP).

Alright, so we have a new file that is going to hold our source code. Now we need to start writing it. The first part of the program should contain comments to tell anyone reading our code what the aim of the program is, when it was written, and who the author is. Comments are lines of source code that are omitted from the compiled binary (or skipped by the interpretter in scripting languages). Comments are a very important part of your code, because when you (or someone else) come back to edit your source code later, you will not remember all of the intricacies of the program. So, you can leave yourself notes in the form of comments. Comments are signalled with the "//" and "/*" characters. Any time you see a "//" it means that the rest of the line will be a comment. A "/*" means that the compiler (or interpretter) will ignore your code until it reaches a "*/" signal. Comments signalled by the "/*" operator can span many lines, but comments signalled with "//" only comment out the rest of that line.

So, to start off our program, we are going to leave a comment at the top about what it does, when it was created, and who it was written by.

// Hello World - My First App for the PSP

/*
          This program was created by (Your Name Here) on (Date Here)
          It is a simple "Hello World" Application.
*/

The next portion of the program is where we tell the compiler which header files and which include files we are going to use in our program. Basically what the "#include" directive does is copy the code from the file you pass to it into the top of your program. This allows you to keep your program simple, while still using the advanced code that is already written for you. The include directive can include either header files that came with the compiler (or that you add to the compiler), or header files specific to the specific project that you are working on. The way that you discern which of these you are including is by whether you use "<>" to enclose the file or if you use quotes to do it. The less than and greater than signs include a file from the compiler's "include" directory, and the quotes include a file from the same directory as the file including them. We will be including two files in our program. The first is "pspkernel.h." This file will be included in every single program that you write for the PSP. It contains all of the code specific to your PSP. Your program will not work on the PSP if you do not include this file. The second file we are going to include is "pspdebug.h." This file contains several useful functions for debugging your programs, but specifically it includes the function that we are going to use to write text to the screen. So, add this code to your program:

#include <pspkernel.h>
#include <pspdebug.h>

Next we tell the PSP a little bit about the program. This isn't really that important, your program will compile without it, but it is always a good idea to keep it in (if only for forwards compatibility). The first attribute is the name of the program, but it's not really the name of the program that will appear (we'll change that later). The other values are other attributes (just leave it alone), major version, and minor version. We'll just leave all of these except for the name as the defaults. So, add the following line to your program:

PSP_MODULE_INFO("Hello World", 0, 1, 1);

Now we are going to set up the function that we will use to write to the screen. This step is optional, but it makes writing text based programs much easier. The basis behind this line is to change the function that is built into the PSP, called "pspDebugScreenPrintf" into something that's much easier to type. This function is used to write to the screen (which you will see later). What we are basically going to do here is rename "pspDebugScreenPrintf" to "printf." So every time we use "printf" from now on, the compiler will just treat it as if we have typed "pspDebugScreenPrintf." Here's how we'll do it; we'll define "printf" as "pspDebugScreenPrintf" like this:

#define printf pspDebugScreenPrintf

Ok, I have some bad news and some good news. The bad news, the next block of code is pretty complicated. The good news, you don't need to understand it. Here's a brief explanation of what it does (we'll leave the actual syntax and line-by-line explanation until later). Basically what this block of code contains is functions that will be called in our program. The functions will set up your program to run on the PSP and allow you to not worry about your PSP freezing or exiting the game when you don't want it to. Put this block into your program:

/* Exit callback */
int exit_callback(int arg1, int arg2, void *common) {
          sceKernelExitGame();
          return 0;
}

/* Callback thread */
int CallbackThread(SceSize args, void *argp) {
          int cbid;

          cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
          sceKernelRegisterExitCallback(cbid);

          sceKernelSleepThreadCB();

          return 0;
}

/* Sets up the callback thread and returns its thread id */
int SetupCallbacks(void) {
          int thid = 0;

          thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
          if(thid >= 0) {
                    sceKernelStartThread(thid, 0, 0);
          }

          return thid;
}

Next, we are going to define the "main" function. Each program in C and C++ needs a main function. This is where the code is executed from. C (and some of C++) functions in the proceedural paradigm. This means that the code goes in a linear path. For example, if you have the following code:

//Do not put this in your program.
//It is an example.

int myFunction() {
          //Print Out 'A'
          return 0;
}
int main() {
          //Print Out 'B'
          myFunction();
          //Print Out 'C'
          return 0;
}

Where the comments (see above if you don't remember what comments are) do what they say. The program would print out 'B' then it would print out 'A' then 'C' because the compiler starts in the main function. It prints out 'B' then it sees the call to "myFunction" which is defined above it, and goes there, sees that it needs to print out 'A' and then returns to where it left off and prints out 'C.' All of your programs (until you get to advanced C++) will follow this linear structure. So, the "main" function is vital to your program. To define a function, you use the following structure: "[return type] [function name]() {". The return type is what the function will send back to the program. For "main" this should always be of type "int" (which stands for integer). The function name is your name for the function, "main" will obviously be named "main." So, define your function by putting the following line in your code:

int main() {

Now we need to add two lines to set up the screen and to use those functions that we put in earlier (which you didn't need to know how they worked). Even though you don't need to know how those functions worked, it is important to grasp the concept of how to call functions. It is actually very simply. You just put the function name with parenthesis at the end (and if it takes any parameters, you put those in the parenthesis, but we'll cover that later). Every line in your program will need a semicolon at the end. The reason for this is because the compiler does not see any white space. Between lines, you could have 100 empty lines, and the compiler wouldn't care. This is useful because it allows you to format your code how you want, in a way that you can understand. You can group lines together, or do whatever you want with your white space. But, in turn, to end a line, you need a semicolon. So add these two lines to your program to set it up:

pspDebugScreenInit();
SetupCallbacks();

Now it's time to write some code that we will actually be able to see the restults of. Remember when we defined "pspDebugScreenPrintf" as "printf?" Well, now it's time to use that function. The way that we will print text to the screen is by calling the "printf" function with a parameter (I told you we'd cover it later.) A parameter is a variable that you can pass to a function for it to use. These will come in handy later when you're writing your own functions. So, for "printf" to output to the screen, we need to pass a string to it. We will output "Hello World" by passing that string to the function. "Printf" is a powerful function because you can also use it to output other variables to the screen. We would pass these as other parameters, but that will all come in due time. For now, we will just print out "Hello World" to the screen, like so:

printf("Hello World");

And there it is, you have told "printf" to output to the screen. Now we just need to finish some things up and then our source code will be ready to build. We need to pause our program so that we can see the output. If we don't, it will just either freeze, or return you to the PSP Menu. You will never even get to see your beautiful phrase outputted to the screen because it will be erased so fast. So, add this line to pause the program until the "Home" button is pushed and the user is sent back to the PSP Operating System.

sceKernelSleepThread();

Now we need to give our function a return value, since when we defined it ("int main()"), we told the compiler that it would return an integer. So just return a '0' (that's a zero, not a capital 'o') by doing this:

return 0;

And finally, end the function by putting in a closing bracket:

}

And that's it for the program! Now we just have to tell the compiler how we want this project compiled by creating a Makefile. So create a new file called "Makefile" with no extention (ie, no .txt). Once you've done this, open it up in your text editor.

Put the following in your Makefile:

TARGET = hello
OBJS = main.o

CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)

EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = Hello World

PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak

You can use this Makefile as a basis for all of your simple projects. Sometimes you will need to add libraries or whatnot to this file, but for now it is fairly simple. It basically just tells your compiler to take "main.c" and build it using the PSPSDK into a .pbp file that your PSP can read. What you will need to change if you use this Makefile in other projects is where it says "PSP_EBOOT_TITLE = Hello World." You can change where it says "Hello World" to the title of your program, this is the name that will appear on the PSP Game Menu when you select the file.

Now open up a CYGWIN Bash Shell and "cd" into your "projects/helloworld" directory. Type "make" and your shell should output some stuff to you. It will tell you if your source code had any errors that made it uncompilable. Generally, if it gives you a few warnings, it's not a big deal. Errors are what you want to watch out for, warnings are just possible points that could cause bugs.

If you didn't have any errors, congratulations! You have successfully created and compiled your first application for the PSP. I'll bet you're dying to test it out. So, put "C:/cygwin/home/yourUserName/projects/helloworld/EBOOT.PBP" on your PSP just like you would any other homebrew application, and try it out for yourself!

Check out Lesson 03 to learn more about programming for the PSP, such as if/then statements, variables, loops, and button input.

신고
크리에이티브 커먼즈 라이선스
Creative Commons License

PSP Programming Tutorial - Lesson 1

분류없음 2008.02.10 23:49 by LoofBackER

Lesson 01

Setting up the Development Environment

How to get the toolchain and PSPSDK up and running with CYGWIN on a windows machine. The complete newbie's guide.

This is the first installment in a series of tutorials focussed on getting a novice programmer well on his way to developing his own homebrew applications for the Sony Playstation Portable (PSP). If you are reading this, congratulations, you have hurdled one of the biggest obstacles for a programmer. Likely the most difficult thing about programming is getting started. Well, by starting to read this tutorial, you are well on your way.

The first step to creating your own program is getting your environment set up. This environment is how you will convert the source code you write into a compiled file formatted for execution on you PSP. We will be setting up two important tools on our system.

The first of these tools is called CYGWIN. It is basically a Linux emulator for windows. It will create a simulated Linux environment on your computer so that you can run native Linux applications. This may sound intimidating, but don't worry, it's very simple to use.

The second thing you'll need is the toolchain. This is the key to programming for the PSP. It will set up everything you need, from header files, to libraries, to the compiler itself, to the sample programs. Once you have this installed, you will be nearly ready to create your first program.

Now for the part we've all been waiting for: the installation.

The first step is to install CYGWIN. You can download the install file from the CYGWIN website here. After it has finished downloading, open up the executable. You will see a splash screen; click next. Now you will be asked what you want to do. Select the default option of "Install from Internet," and hit the next button. Now you will be prompted where you want to install CYGWIN. Change the install directory to "C:/cygwin" if it is not set as such already (where C: is your local hard drive). Leave the other options set to their defaults and hit next. Now you will be asked where you want to save the installation files. What you select here doesn't really matter, but I suggest putting them someplace where you will be able to find them and delete them after the installation is complete. Once you have selected a suitable location, click next. The next screen will ask about your network settings, if you don't use a proxy (or don't know what a proxy is), just click next on this screen. If it doesn't work, go back and try letting it use Internet Explorer's settings. Now you should be presented with a list of servers to download the installation files from. Any one of these will do, so select one, and then click on next. Now it will download the package list, this could take a few minutes, depending on your connection speed. Once it is done, click on "view" at the top to view the packages available for you to install. You will need the following:

·  autoconf2.1

·  automake1.9

·  gcc

·  gcc-g++

·  make

·  patchutils

·  subversion

·  wget

You can select them by clicking where it says "skip." "Skip" should then change to a version number. Don't worry if other packages are selected; packages that are required by CYGWIN or by other packages you select will be automatically set to install. When you are finished, click next. CYGWIN will now download and install the selected packages. This will quite possibly take a while, so go watch a TV show or do some web surfing while you wait. After the install has finished, you are ready to install the toolchain.

Now, we are going to install the toolchain into our CYGWIN environment. To set up our environment, we will need to run CYGWIN first. So, either from the start menu, or from "C:/cygwin," run a CYGWIN bash shell (cygwin.bat). This will open up a command line. Once you see "yourusername@yourcomputername ~" you may close the window; your environment has successfully set up. To download the latest toolchain, go here. It should be at the very bottom of the page. At the time of writing, the latest toolchain file is dated 20050725. Download this file. When it is finished, use Winrar to extract the file contents to "C:/cygwin/home/user," where "user" is your username.

The toolchain needs a bit of customization to work with CYGWIN, so fire up Wordpad, and open "C:/cygwin/home/user/psptoolchain/toolchain.sh" and do a "Find and Replace" to replace all instances of "gmake" with "make" and all instances of "gpatch" to "patch" and then save the file. Now it's time to install, so open up your CYGWIN bash shell again. Now it's time to introduce you to the Linux command line. You should see a "$" at the beginning of the line. This means that you are running the shell in user mode, as opposed to root (or admin) mode. This is of little importance in CYGWIN, but if you ever use an actual Linux command line, this is an important thing to notice.

We now need to change directories to where we extracted the toolchain. Type "ls" in the bash shell; this stands for list. It will give us an output of all of the files in our current directory (this is similar to "dir" in a Windows command line). Now you should see a folder named "psptoolchain," this is where we want to go. So type "cd psptoolchain" and hit enter. CD stands for change directory, and it will (obviously) switch the current operating directory). Now do a quick "ls" again, and you will see the files in this folder. The one that we want is "toolchain.sh." To execute this file, type "./toolchain.sh" and hit enter. In Linux, "." means the current directory, and ".." means the parent directory, so this command means to execute "toolchain.sh," which is in the current directory. The toolchain.sh script will do the rest, for you. This can take up to several hours, depending on the specifications of your machine. For a frame of reference, my 3.0GHz Pentium 4 took about three hours to run the entire script, so be patient.

Now for the last step. We have to tell CYGWIN where it can find the PSPSDK (which the toolchain just installed) and the toolchain. To do this, we need to change "C:/cygwin/cygwin.bat" to include the paths. So, close CYGWIN, and navigate Explorer to "C:/cygwin" and right click on cygwin.bat. Select "Edit" and a Notepad window should appear with the following:

@echo off

C:
chdir C:\cygwin\bin

bash --login -i


Change this to:

@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

Now you're ready to go! If you have source code that you want to compile, go into that directory with "cd" and type "make" and it should give you an eboot.pbp that you can put on your PSP. If not, check out Lesson 02 to learn how to create your own simple application for the PSP.

신고
크리에이티브 커먼즈 라이선스
Creative Commons License
1 

카테고리

분류 전체보기 (107)
::::::Dairy::::: (5)
:::::what?::::: (1)
:::::Computer::::: (5)
:::::Idea::::: (2)
:::::Want::::: (1)

달력

«   2017/06   »
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30  

티스토리 툴바