Sign in to follow this  
  • entries
    570
  • comments
    2427
  • views
    215895

Untitled

Sign in to follow this  
Mushu

116 views

devkitARM with VS2005

(Note: this tutorial is (for the moment) only for VS, not VCExpress. I'll write up an appendix for Express after I finish with this - dependant on whether or not there's an easy way to use *GASP* makefiles in Express)

UPDATE: The same steps appear to work with the Express Edition as well (ie, EE supports makefile projects). If you encounter any bugs, fire me a PM so I can try and fix them and/or update the guide. Thanks!

(Further note: may take relentless potshots against Mac and Linux users. What's to be expected? Written from the perspective of a monopMicrosoft fanboy :D)

STEP 1: Installing devkitPRO

devkitPRO is the all-in-one package for development on a myriad of console platforms - GBA, PSP, NGC, etc. It contains a bunch of homebrew header files that you'll need, in addition to the toolchains to compile your programs.

Why can't you just compile with MSVS's default compiler? Well, the GBA uses an ARM7 processor which uses the ARM architecture. MSVS's compiler generates x86 code. Attempting to run x86 code on an ARM system is like trying to play games on a Mac - it just doesn't work. So we'll be using the compilation tools included in devkitPRO (a cross-compilation of GCC to generate ARM code) to make teh games.

Okay, so go ahead and pick up the latest windows installer from HERE. I'll be using 1.3.1, since that's the most recent at time of writing, but I doubt they'll make any major changes.

I'm choosing to install the Minimal System stuff, and devkitARM, since that's all we'll need for GBA development. devkitPPC is for GameCube stuff, and devkitPSP for PSP.

Now, when you install the path you install to must _NOT_ contain any spaces, because that'll make the command-line stuff wonky later (if you pass a path with spaces as an argument, ie, make C:\My Documents\pie, you've actually just passed it two parameters. You can probably go in and edit the makefiles to fix this, but I was lazy enough to just install to the default directory - C:\devkitPRO\) [razz]

This is where the installer went wonky on me originally - it installed the devkitARM stuff to some random folder. So, before we start - make sure your devkitPRO folder has the following stuff -

\devkitPRO\devkitARM (the compilation tools)
\devkitPRO\examples (for stealing makefiles)
\devkitPRO\libGBA (for stealing header files >_>)
\devkitPRO\msys (more toolchain stuff)

Okay. So you should have all that now. Lets test and see if it works. Open up a command prompt (Start -> Run -> "cmd") and navigate to the examples folder -

cd C:\devkitpro\examples\gba

Err, before we do this we need to add the toolchains to the default path. This makes it so we can just type in "make" and it'll search for the make tool in the right places. Alternatively you could dump all of the tools in \WINDOWS\system32 but I'd have to kill you for that you dirty dirty hobbit.

Anyway.

path=C:\devkitPRO\msys\bin

Okay, now we're ready to test the toolchains - go ahead and type the "make" command while in the \GBA\examples directory. You should get a long build results list, and I think most of them should work. We're just making sure that you don't get any weird errors or anything (like missing toolchain components, or "tool not found" or something that would say we didn't set stuff up right).

If you've encountered a problem thus far, leave a comment here so I can address the issue. I don't think I've forgotten any steps, but it was previously set up on my system (the command paths especially) so I may have overlooked a possibly minor detail.


STEP 2: Setting up our happy VS2005 Project!!

Okay, so now we're to the point where we can be happy and set up a project. Go ahead and open up VS2005, you sly microsoft fox you. What? Its already open? Because you leave it open all the time to remind yourself that you should be coding (just like I do?) Well <3 <3 <3.

Anyway.

You'll want to, again, create your project in a path that has no spaces or line breaks or squiggle marks. Reasons are mentioned above, but its the same deal - GCC will freak the heck out. Oh, and for that matter, don't tell MSVS you're using GCC instead of its tools. It'll freak the heck out too (those Mac people use GCC >__>).

I've chosen to create a project in C:\GBA\GBA2\ for simplicity's sake, since this is my second GBA project. LOL.

In the "Add New Project" dialogue, choose a makefile project. A makefile is basically a set of instructions on how to build our executable. Normally VS handles all those mundane details for us, but we need to use our special GCC compiler, hense the need for a makefile to invoke special... commands.

Okay, so now you should be at the Application Wizard stuff. Hop over to the debug settings. Change the stuff such that -

Build Command Line: make
Clean Commands: make clean
Rebuild Command Line: make

And leave the rest blank. Note that the Rebuild Command Line should first issue make clean and then make, but I'm too lazy to type that in (I never use Rebuild, I always clean then build if I'm having a problem that Rebuild would cause).

The release configuration should be the same. (Again, it really shouldn't. We should be adding additional commands like -O3 to enable full optimization, but I haven't gone through and done all that fancy smancy stuff yet).

Now we have our nice little project. Its not completely set up yet - we need a makefile!

Thankfully, devkitARM provides us with a good generic makefile for all our beginner needs. It can be found in

C:\devkitPRO\examples\gba\template\Makefile

Paste a copy of this file into your project directory.

Okay, go ahead and hit the build button in VS. In the output window you should get a nice little error from GCC telling you there is no function main defined. This is good. If you got anything else (like. Cannot find 'make' command) then make sure you set the path correctly (see above), and/or leave a comment here for me to fix.

Yay. The problem with this makefile (that I don't like) is that it expects all your *.c and *.cpp files to be in \SOURCE\. I never do that, and VS never does that by default, so we're going to change it to work the VS way - just dump all the files into the project directory YAY! :D

In VS, open up the makefile that's in your project's directory. We're opening it in VS because the line numbers are really nice. To enable line numbers, go to Tools > Options > Text Editor > All Languages and check "Line Numbers". Though I can't see how you'd survive without them :O

Anyway - check out line 21:

SOURCES := source

AHA! This is a well-written makefile, and we only have to change this one line to change the source directory for the whole project. Hooray! So go ahead and change this line to

SOURCES := .

The . tells it to search in the current directory. For a fun fact, a .. would tell it to search in the parent directory. Yay DOS.

There's another little nasty bug, and I'm not sure whether its a makefile problem or a VS problem. In any case, we fix it by editting some definitions in the makefiles.

Change line 38 from

CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -fno-rtti -fnoexceptions

to

CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -fno-rtti

Don't forget to save the makefile.

Okay, so now we need something to compile - how about...

int main() { return 0; }?

Yes my pretties. That will do nicely. Go ahead and create a new source file (main.cpp, for example) and type that lovely line of code into it, and attempt to build it. This time, it should work perfectly and you should get a nice little "ROM Fixed!" message in the output window telling you that there's a ROM waiting for you in your project directory (with the heaps of other stuff because we like putting everything there LOL!).

Hooray!


STEP 3: Launching Visual Boy Advance from within VS

If you've been following me thus far, you should have built a ROM with your happy copy of VS. Try pressing the "debug" button. HAR HAR HAR it doesn't work, because VS is configured to launch the x86 executable built. But we're not building one, we're generating an ARM ROM. Since you're probably not on an ARM system, we can't execute it natively - we need an emulator.

You can get it HERE. I got the Windows/Windows Dev one, simply because the SDL one has multiple files (SDL.dll, etc) and since we're slamming this in our Solution directory, I wanted to minimize the amount of files in there.

Now, we're choosing Visual Boy Advance for two reasons: 1) it supports a command-line interface, which means we can launch it with a ROM from the command line really easily and 2) because there are (supposedly) debugging tools within it. I haven't really tried the debugging stuff, but its supposed to work. Maybe I'll end up writing a tutorial on how to use it. Which would be a good read for me, since I have no idea on how to use it.

Anyway. If you've got a nice solution set up (for multiple GBA projects), you can stick the VBA binary in your solution directory. If not, you should have made a solution, and will have to switch every instance of $(SOLUTIONDIR) with $(PROJECTDIR). Hur hur hur I'm such a lazy bastard :D

Okay, so go back to your project, and open the property pages again. This time click on the "Debugging" tab. This is where we can tell VS what to do when we click the debug button! Change -

Command: $(SOLUTIONDIR)VisualBoyAdvance.exe
Command Arguments: $(PROJECTDIR)$(PROJECTNAME).gba

Press 'okay', and go over and try pressing the debug button again! Visual Boy Advance should pop open with a black screen, which should turn white when your code finishes executing. Which is immediately, since we haven't written any code other than the main stub.


STEP 4: ???

STEP 5: $$$ PROFIT $$$
Sign in to follow this  


3 Comments


Recommended Comments

Great installation guide. Now I'd like to (, and many with me,) see an Express version of this. And I can't wait to see what Step 4 contains. =D

I'll run your stuff on my DSLite if it's worth it you pay for my GDNet+ subscription! ;)

Share this comment


Link to comment
The Express Edition is exactly the same, assuming VCExpress allows you to use makefiles. Lemmie go check...

Yep, it does. The process should be exactly the same then, since the makefile is the only thing you need for it to work. Hooray <3

Share this comment


Link to comment
Okay, uhh, this is a reasonably old entry now, so if you have any questions/concerns that you want answered, please PM them to me. If you don't want them answered (or if its not a question/something that needs to be replied to) then just post it here.

Additionally, Pipo found this page on the devkitPRO site which is another description of the 3rd (?) part of the walkthrough, detailing how to create your handy makefile project in VS2005EE. It also includes a better build command line, which uses a regex (...or something wtf?) which allows VS to parse the errors so you can double click them and it'll navigate to the line which raised them and omfg cool.

Thanks, Pipo!

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now