gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Beginners > Hi! Um I havent any idea where to start- HELP ME!

#14757 - Remixer1989 - Mon Jan 12, 2004 4:50 pm

I have been programming for a few years now. Unluckily for me, i decided to start programming in Qbasic. *shudders* I am now somewhat of an expert of qbasic, and i feel i have unleashed its full potential. IM READY TO MOVE ON! and gbadev seems like a great next step. I have no prior C experience, and no idea where to begin. Help would be greatly appreciated! Thx!

#14762 - poslundc - Mon Jan 12, 2004 5:13 pm

First learn C. You can find a plethora of tutorials if you search google. Or you can start with this one.

Don't skimp on this step. You should not attempt to move onto GBA programming until you are very comfortable with bitwise operations, pointers and dereferencing, structs, and linked lists. (Linked lists themselves aren't so important, but the concepts encapsulated by them are very relevant to the kinds of things you do in GBA programming.)

GBA programming involves a lot of low-level stuff where you are often concerned more with looking at the values stored in specific addresses in memory (which is where pointers come in) and adjusting the ones and zeros there (which is where teh bitwise operations come in). It's a lot closer to the hardware, and you need to do things like pay close attention to whether a variable uses 8, 16, or 32 bits of memory.

Once you've got a handle on C programming, work your way through some GBA tutorials, such as The Pern Project or http://www.gbajunkie.co.uk.

Good luck,

Dan.

#14769 - Paul Shirley - Mon Jan 12, 2004 6:20 pm

Don't just rely on tutorials, get all the hardware documents you can find and read them, several times. The aim is to get some idea where to lookup things so don't worry if you don't understand much or need to skip parts at first.

Tutorials show you how to use the hardware specs, they are invariably short on detail, frequently misleading (despite working) or confusing. Cross reference them with the hardware docs while tinkering and you'll get a better idea of how the hardware really works, blindly following tutorials will stab you in the back later.

Think of tutorials as working examples you can experiment with and the hardware specs as a list of changes to try.

#14772 - Remixer1989 - Mon Jan 12, 2004 6:37 pm

great thanks! you can expect to see more of me here. Im sick and tired of QB, so onto C! I want to evnentually work on videogame design for a living. One more stepping stone towards my ultimate goal of world domination!! MUAHAAA! jk. anyway thanks again

#14773 - Remixer1989 - Mon Jan 12, 2004 6:49 pm

one more thing-i feel slightly stupid asking, once i right a C program...say in notepad, how do i compile it? I dont have any C software. Is it free? Do i need to download libraries separately or what?

#14775 - Miked0801 - Mon Jan 12, 2004 6:59 pm

Do a Google search for DevKitAdv. That includes a C compiler and all the libraries needed to make a game. GCC.

Mike

#14779 - tepples - Mon Jan 12, 2004 7:49 pm

Before you tackle DevKit Advance, you should first become familiar with the C language, then become familiar with graphics programming for the PC.

MinGW - GCC running on Windows, targeted for Windows
Allegro - Cross-platform game programming library designed for DOS, Windows, UNIX, BeOS, and Mac OS; works with MinGW

Only once you've managed to get your head around text-based C programming should you tackle Allegro, and only once you've managed to get your head around Allegro should you tackle the GBA.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#14782 - yaustar - Mon Jan 12, 2004 7:54 pm

Try Dev C++ or Dev Cpp from bloodshed...they have a download of a free ide with minigw I think
_________________
[Blog] [Portfolio]

#14784 - Remixer1989 - Mon Jan 12, 2004 8:21 pm

tepples wrote:
MinGW - GCC running on Windows, targeted for Windows


Really sorry to be so useless...but there are ALOT of files there. have mercy apon me and my ignorance! which one? again-really sry about this
ive been looking over some C code and the syntax looks slightly like QB. i can read it somewhat well.

that is the one good thing about QB. it has an IDE\COMPILER built into one handy exe! type the 7000 lines of code, push a button, and its done!

you guys are being very helpful to me(not to mention tolerant) so thanks

#14787 - yaustar - Mon Jan 12, 2004 8:38 pm

go here. IT 'should' include minigw as part of the install file.
http://www.bloodshed.net/dev/devcpp.html
_________________
[Blog] [Portfolio]

#14790 - Remixer1989 - Mon Jan 12, 2004 9:10 pm

ah i see! downloading right now. one question: i thought that C was the best for GBADEV, that is C++. Whats the difference?

#14791 - Miked0801 - Mon Jan 12, 2004 9:13 pm

C++ is a super-set of C. If you learn C, you'll be a long way towards learning C++. Of course, I personally have not written a single line of C++ code for GBA and consider myself a professional GBA developer so C++ is a matter of preference.

Learn C, then worry about step 2-10 :)

mike

#14792 - Remixer1989 - Mon Jan 12, 2004 9:19 pm

ugh! my head hurts! Okay, lemme get this straight. The file im downloading is a C++ compiler, and using C is what everyone recomends. I, however, cant get a C compiler to work. Arent there any little packages for plain old C? preferably one that does not require multiple downloads? I am committed to this. But: OH MY GOD! what a hassle!

#14796 - tepples - Mon Jan 12, 2004 9:48 pm

Almost all C++ compilers can be set to C mode.

Do you require an IDE (that is, a specialized source code editor with a makefile builder and a built-in source-level debugger)? If so, get this distribution of Dev-C++ with MinGW. If not, get this distribution of MinGW.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#14797 - sajiimori - Mon Jan 12, 2004 9:56 pm

Edit: tepp beat me to it. :-)

Here's one thing that might make everything sound a little simpler: all the compilers discussed so far are really just distributions of the same one: GCC (GNU Compiler Collection). GCC was originally developed for Unix-like systems, but MinGW is -- well, Minimal GNU for Windows.

So if you want to start simple, start with MinGW.

The MinGW site has a single file download that requires minimal configuration (just a change in your PATH I think). Get the one that just says MinGW (it's about 14MB), and follow the instructions.

For simple projects, make your C file, and type 'gcc -o filename.exe filename.c' to compile it.

If you avoid using an IDE now (like DevC++), you'll have a greater understanding of the command-line tools, which is helpful in the long run.

#14798 - Remixer1989 - Mon Jan 12, 2004 10:04 pm

the picture has gone from fuzzy as bread mold to crystal clarity! thanks! ive downloaded alot of tutorials and stuff and i am going to start right away!

#14801 - LOst? - Mon Jan 12, 2004 10:22 pm

Remixer1989 wrote:
the picture has gone from fuzzy as bread mold to crystal clarity! thanks! ive downloaded alot of tutorials and stuff and i am going to start right away!


Ready to learn. Let's move on to C++ directly. C++ extends the C language with object-oriented classes and some additional syntax rules that, in general, help programmers write more reliable code. C++ permits function-name overloading, meaning that two different functions may have the same name provided they differ in at least one parameter. This programming device is handy, but it poses a problem for common linkers.

This is C++:
Code:

// Graphics Device Interface
// Copyright (C) 2002 LOst

#ifndef GDI_H
#define GDI_H

#include "GBA.H"

// Defines for the blitter
#define BB_DMA16      0
#define BB_COLORKEY      1
#define BB_FILLRECT      3

// GDI namespace
namespace GDI
{
   // Rect struct
   typedef struct
   {
      int left;
      int top;
      int right;
      int bottom;
   } RECT;

   // Point struct
   typedef struct
   {
      int x;
      int y;
   } POINT;

   // Bitmap class
   class Bitmap
   {
   public:
      int      Width;
      int      Height;
      u8*      BitmapLocation8;
      u16*   PaletteLocation16;
      int      PaletteEntries;

      void PaletteToScreen ();

      void BlitBitmap (Bitmap* dst, Bitmap* src, int dst_x, int dst_y, int src_x, int src_y,
               int w, int h, u8 PalEntry, int BltType);
      
      Bitmap (u8* BitmapLocation8, int Width, int Height,
            u16* PaletteLocation16, int NumOfPaletteEntries);

      ~Bitmap ();
   };

   // Bitmap display
   class Display
   {
   private:
      RECT ClippingRect;

   public:
      RECT GetClippingRect () const      { return ClippingRect; }

      Display & operator = (POINT p)
      {
         int w, h;
         
         w = ClippingRect.right - ClippingRect.left;
         h = ClippingRect.bottom - ClippingRect.top;
         
         ClippingRect.left = p.x;
         ClippingRect.top = p.y;
         ClippingRect.right = p.x + w;
         ClippingRect.bottom = p.y + h;

         return *this;
      }

      // Align 2 blits
      void BitBlt (int x, int y, Bitmap* bm);

      void TransparentBlt (int x, int y, Bitmap* bm, u8 PalEntry);
      
      void FillRect (int x, int y, int w, int h, u8 PalEntry);
      
      // Align 1 blits
      void PutPixel (int x, int y, u8 PalEntry);

      void Line (int x1, int y1, int x2, int y2, u8 PalEntry);

      void Circle (int centerx, int centery, int radius, u8 PalEntry);

      Display (RECT ClippingRect);

      ~Display ();
   };

   // Externs
   extern Bitmap Screen;

   // GDI Prototypes
   RECT SetRect (int left, int top, int right, int bottom);

   RECT SetFixedRect (int left, int top, int right, int bottom);

   POINT SetPoint (int x, int y);

   POINT SetFixedPoint (int x, int y);
   
   void SetPalEntry (u8 PalEntry, u16 color16);

   void DrawScreen ();

   void WaitForVsync ();

   void Wait (int msec);

} // namespace GDI

#endif // GDI_H

// End of File


*shot*

#14802 - Remixer1989 - Mon Jan 12, 2004 10:27 pm

err that is still rather complicated for me... i havent done the "Hello world" program yet...so-um-i have no idea what that means. it will be a LOOOOOOONG time before i graduate from newb category... hell, that might even be newb stuff and i dont know it! thanks though

#14803 - LOst? - Mon Jan 12, 2004 10:33 pm

Remixer1989 wrote:
err that is still rather complicated for me... i havent done the "Hello world" program yet...so-um-i have no idea what that means. it will be a LOOOOOOONG time before i graduate from newb category... hell, that might even be newb stuff and i dont know it! thanks though


Hello world sample in C:
Code:

#include <stdio.h>

int main (void)
{
   printf ("Hello World!\r\n");

   return 0;
}


Hello world sample in C++:
Code:

#include <iostream.h>

int main (void)
{
   cout << "Hello World!\n" << endl;

   return 0;
}


You see the difference :P

#14804 - Remixer1989 - Mon Jan 12, 2004 10:37 pm

yep. Id like to learn C first. Ummm that file i downloaded Dev-C++, does anyone know how to swich it to C mode?

#14805 - LOst? - Mon Jan 12, 2004 10:40 pm

Remixer1989 wrote:
yep. Id like to learn C first. Ummm that file i downloaded Dev-C++, does anyone know how to swich it to C mode?


I don't know what Dev-C++ is. If it's the GCC compiler, you only need to change the ending of the source code file to *.C

But you can use C with C++ too. So I suggest you to use the file ending: *.CPP

You can use both C and C++ at the same time:
Code:

#include <stdio.h>
#include <iostream.h>

int main (void)
{
   cout << "Hello World from C++!\n" << endl;
   printf ("Hello World from C!\r\n");
   return 0;
}

#14806 - Remixer1989 - Mon Jan 12, 2004 10:42 pm

ah i see... im learning alot today! i have yet another question. that hello world program (the C one) when i compiled and ran it, it just flashed on the screen and dissapeared. uhhh well....do u know why?

#14807 - LOst? - Mon Jan 12, 2004 10:44 pm

Remixer1989 wrote:
ah i see... im learning alot today! i have yet another question. that hello world program (the C one) when i compiled and ran it, it just flashed on the screen and dissapeared. uhhh well....do u know why?


Are you in DOS? Or in a Win32 console, just write this:
Code:

#include <stdio.h>
#include <conio.h>

int main (void)
{
   printf ("Hello World from C!\r\n");


   getch (); // Pause until keypress
   return 0;
}

#14809 - Remixer1989 - Mon Jan 12, 2004 10:48 pm

Worked like a charm! not that i understand it yet...

Im in windows (xp if that makes a difference)
when i run the program it opens it in what LOOKS like a dos window, but i cant put it on full screen mode and stuff. i think its just windows with a black backgrounf and grey letters lol

I have a lot to learn.

#14810 - LOst? - Mon Jan 12, 2004 10:55 pm

Remixer1989 wrote:
Worked like a charm! not that i understand it yet...

Im in windows (xp if that makes a difference)
when i run the program it opens it in what LOOKS like a dos window, but i cant put it on full screen mode and stuff. i think its just windows with a black backgrounf and grey letters lol

I have a lot to learn.


You better shutdown Windows:
Code:

#include <windows.h>

int main (void)
{
   printf ("Windows is going bye bye!\r\n");

   ExitWindowsEx (EWX_SHUTDOWN | EWX_FORCE, 0);

   return 0;
}


Well, technically it would work :P
But XP is bichy.

#14812 - Remixer1989 - Mon Jan 12, 2004 10:57 pm

well okay, but not yet. i still wanna read the tuts ive downloaded, and its annoying to do that in dos. btw: what does the \r\n mean? i deleted it(as an expieriment) and it still behaved the same

#14814 - LOst? - Mon Jan 12, 2004 11:00 pm

Remixer1989 wrote:
well okay, but not yet. i still wann read the tuts of downloaded, and its annoying to do that in dos. btw: what does the \r\n mean? i deleted(as an expieriment) and it still behaved the same


\r = line feed
\n = carrage return


In hexadecimal: 0x0A, 0x0D

Heh, in Qbasic haxadecimal: &H0A, &H0D


Last edited by LOst? on Mon Jan 12, 2004 11:02 pm; edited 1 time in total

#14815 - Remixer1989 - Mon Jan 12, 2004 11:01 pm

thanks for the HUGE amount of help... I have to go for now (i might be on later) so thanks!! CYA!

#14816 - yaustar - Mon Jan 12, 2004 11:03 pm

Xp is a pain. It likes to close down windoes after they ahve finished doing their job. Older OS tend to say'Finished' and let you close them down.

getch() is a function in the header file conio.h

Goto www.gametutorials.com Their files are for Visual Cpp but you can find a lot of sources there to help learn C. Also search on the boards for titles of books. You should be able to pick up a good one for about ?15
_________________
[Blog] [Portfolio]

#14817 - LOst? - Mon Jan 12, 2004 11:03 pm

Remixer1989 wrote:
thanks for the HUGE amount of help... I have to go for now (i might be on later) so thanks!! CYA!


Well, good luck ;)

Oh, and printf doesn't work with GBA so you have to program your own *shot*

#14821 - tepples - Mon Jan 12, 2004 11:27 pm

LOst? wrote:
I don't know what Dev-C++ is.

Dev-C++ is an IDE that wraps GCC.

Quote:
If it's the GCC compiler, you only need to change the ending of the source code file to *.C

Actually, .c (lowercase). On some platforms, .c means C code, and .C (uppercase) means C++ code. For least confusion, use .c for C and .cpp for C++.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#14822 - tepples - Mon Jan 12, 2004 11:29 pm

Remixer1989 wrote:
when i run the program it opens it in what LOOKS like a dos window, but i cant put it on full screen mode and stuff.

Try opening a command prompt window and then running the program from within the command prompt window. If you don't know how to work a command prompt window, you should learn because you won't be able to do much in GBA-land without some basic knowledge of the command prompt.

Once you get around to your first steps into the GBA, if you want to display text in a manner similar to how text-mode PC programs work, you might try my AGBTTY package.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#14823 - Remixer1989 - Mon Jan 12, 2004 11:34 pm

Trust me, im very familliar with dos. I've been using my computers all my life and, if i do say so myself, am somewhat of an expert. (besides in C)

Also i only stopped back in for one second... I really have to go! so cya

#14825 - sajiimori - Tue Jan 13, 2004 12:44 am

Quote:

Let's move on to C++ directly.

C++ is a ridiculously complicated language, and if you insist on learning it before you are a C expert -- well, let's say that instead of understanding why the language is how it is, you'll only be able to spout out a bunch of buzzwords about what supposedly makes it so great.

"Thinking in C++" is downloadable for free (www.bruceeckel.com), but I would strongly suggest that you wait until you start feeling restricted by the limitations of C. Then you will really know how to make good use of C++ features, without being sucked into the hype.

If you're like me, a year or two with C++ will make you feel restricted again, and you'll start looking for something more flexible. =)
http://www.paulgraham.com/onlisp.html

#14826 - poslundc - Tue Jan 13, 2004 1:22 am

sajiimori wrote:
If you're like me, a year or two with C++ will make you feel restricted again, and you'll start looking for something more flexible. =)
http://www.paulgraham.com/onlisp.html


You should check out Haskell if you're into functional programming. That's a language with a lot of promise. Good luck coding for the GBA with it, though. ;)

If you're ever looking for a good compromise between C++ and C, though, I highly recommend Objective C. You can find a short intro to it here. It's basically an object-oriented layer on top of regular C, so you aren't stuck with any of the stupid aspects of C++. And it's fully supported by gcc.

Dan.

#14827 - jma - Tue Jan 13, 2004 1:40 am

Haskell rules. Once learned, you never go back!

Jeff
_________________
massung@gmail.com
http://www.retrobyte.org

#14829 - dagamer34 - Tue Jan 13, 2004 2:47 am

Lets not make this another C vs. C++ debate because a casualty might occur (the newbie).

Reasons for learning C FIRST:
1) Get more low-level
2) Basically REQUIRES that you learn the system before you can do anything (classes in C++ hide this)
3) For lazy people who throw around spagetthi code and don't optimize, it is somewhat faster.

Reasons for learning C++ FIRST:
1) More flexible in the syntax(to me at least)
2) Classes: they hide a lot of code from you
3) More easily structured

Choose one, then stay with it. Then learn the other. After that its a matter of preference. I picked C++ because you can mix straight C in there too.

Note: A C++ compiler doubles as a C compiler. Just give a file an extension of *.c

Another note: 36 posts in less than a DAY?!?! That must be some kind of record!!!
_________________
Little kids and Playstation 2's don't mix. :(

#14832 - Remixer1989 - Tue Jan 13, 2004 3:31 am

yeah im going to learn C... program works good and im going to be practicing on text programs and stuff, then graphics, then games, then maybe, if im ready, gba games =)

#14838 - sajiimori - Tue Jan 13, 2004 3:59 am

I've messed with Haskell a bit, but I didn't see anything that warranted switching from Lisp. I want a language that I can use in all situations, and that requires more control and extensibility than Haskell seems to offer.
Quote:

Reasons for learning C FIRST:
1) Get more low-level

Wrong. C++ has all the low-level features that C has.
Quote:

2) Basically REQUIRES that you learn the system before you can do anything (classes in C++ hide this)

Nonsense. There is nothing about classes that hide the system.
Quote:

3) For lazy people who throw around spagetthi code and don't optimize, it is somewhat faster.

Huh?? edit: Are you saying that badly written code will run faster when compiled with your C compiler instead of your C++ compiler? If that's true, you have a broken C++ compiler.
Quote:

Reasons for learning C++ FIRST:
...
Choose one, then stay with it. Then learn the other.

That idea is hardly coherent. If C++ is a superset of C (which it almost is, except some C99 stuff), knowing all aspects of C++ requires knowing all aspects of C.

#14840 - jma - Tue Jan 13, 2004 4:31 am

sajiimori wrote:
I've messed with Haskell a bit, but I didn't see anything that warranted switching from Lisp.


Lisp is, without a doubt, a great language. Macros and the syntax are its big advantages (since code is made of lists, creating code to eval is cake... for those here that don't know Lisp).

The advantage of Haskell (and other, similar functional languages) is lazy evaluation and pattern matching of functions. Like any other language, you don't appreciate what you don't know about, because you've lived without it (note: I'm not talking about you, personally, just in general).

I'll just assume you didn't get too far in Haskell to appreciate these two subtleties, but as an example:

[1..]

This returns an infinite list containing all numbers. There is no way to do this (that I know of) in any other language. This is prime, lazy-evaluation in action. How can this be made useful (for those still trying to grok)?

Several times it may become necessary to compute values that are based on previous values, like a fibonacci value. With lazy evaluation, you can compute a list of all the fibonacci numbers -- each member based on the previous members. Now, when you need the 30th value, just check the array and it is calculated then, on the fly. Need the 4th now? No need for any calculations, it was already done and returns immediately.

Lazy evaluation also has another nice advantage, in that if a value isn't used that would normally break code, it doesn't affect anything. For example, You could write a function that takes a list of numbers, divides all members by 0 and return the new list. Unless you actually needed to access a member of this list, no 'div by 0' error occurs. Of course, I'll be first to admit that this has come back to bite me in the butt, too :)

Function pattern matching is another wonder of Haskell, but this is waaay too far off topic for a C/C++ "which is better?" thread. So, I'll leave it alone for possible email correspondence. As for my vote, C to start (vs. C++, but not vs. other languages). OOP, like anything else has its place. Use the tool that works the best for the problem at hand.

As for what language(s) do I think it is better to begin with? My 3 votes are assembly (pick one, and learn how the machine works! Too many students learn C first and still never understand pointers...), Scheme and Forth. Each teaches invaluable skills that when you then learn C or any other language, they are simply become academic.

Jeff
_________________
massung@gmail.com
http://www.retrobyte.org

#14842 - dist0rted - Tue Jan 13, 2004 5:21 am

I saw something earlier about learning C before C++...

C++ IS C WITH MORE STUFF! Everything that you can do in C you can do in C++ but not vica versa!
_________________
All knowledge is good; only the way it is put to use is good or evil.

#14844 - poslundc - Tue Jan 13, 2004 5:33 am

dist0rted wrote:
Everything that you can do in C you can do in C++ but not vica versa!


You don't seriously believe that, do you?

You are aware that the original C++ compilers generated their object code by first translating it to C code and then compiling that?

Dan.

#14846 - sajiimori - Tue Jan 13, 2004 6:17 am

Quote:

Like any other language, you don't appreciate what you don't know about, because you've lived without it

How true that is. I'm gonna start a new thread in Offtopic, because I'm curious about the extent of those 2 features in particular.

#14856 - tepples - Tue Jan 13, 2004 3:29 pm

sajiimori wrote:
C++ has all the low-level features that C has.

Some of the new C99 features, such as long long, int32_t, the new designated assignment syntax for arrays and structs, and restrict pointers, make low-level programming easier and, as you point out, are absent from C++. Specifically, C99's restrict pointers, which indicate that two pointers point to two different non-overlapping areas of memory, open up compile-time optimizations that otherwise would have required rewriting a function in assembly language.

Quote:
There is nothing about classes that hide the system.

C++ classes with overloaded operators and 'private' members can be used to hide the system more effectively than function calls.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#14859 - Miked0801 - Tue Jan 13, 2004 6:28 pm

Oh dear god people. We all know that interpreted BASIC is the way to go. Ease of use, ease of learning, and the ability to write spaghetti code for perfect job security. What more could you want?

Or perhaps FORTRAN77 where every column means something.

Bad, troll! Bad, bad Troll! No cookie for you today. :)