Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Disclaimer
- All here is for educational purpose and shoud be used at your own risk!!! GAMEBOY(c) from NINTENDO(r)
- Just onother simple GBDK tutorial(by VKcorp)
- CONTENTS
- PART0: Knowledge needed(done)
- PART1: What do you need(done)
- PART2: Installing gbdk(done)
- PART3: The programs(done)
- PART4: A little bit of C(done)
- PART5: Coding1 variables + basic instructions(done)
- PART6: Makefile(copmpiling)( done)
- PART7: Sprites(not done)
- PART8:TKS(done)
- Part0: Knowledge needed
- Common sense + how to use your OS and browser. Know that a GB is a GameBoy.
- Part1: What do you need??
- Force of Will
- A version of GBDK(gameboy dev kit)
- Tile Editor
- GB Tool Kit and a Map Builder(not needed for this tutorial)
- Notepad, vi, or any text editor
- An emulator
- You can get all this stuff + more documentation on: http://www.devrs.com/gb
- Part2: Installing GBDK
- On windows:
- -Unzip all to c:\
- -Run: c:\SDK\gb-gb\x.x.x\lib\make.bat
- -Done
- On *nix:
- -Decompress GBDK to a folder
- -Get a way to be root(su root), if you need get john the ripper to crack the password, if you get cought say "it was for educational purposes"
- -run: make
- -run: make install
- -Done
- Part3: The programs
- GBDK
- -On the bins you will find:
- -as: assembler
- -cpp: c++ compiler
- -lcc: the binary we're gonna use
- -link: linker(joins object(compiled) files)
- -Includes: are files that you will need to make any use of the compiler, unless you write your own. They are headers wich you insert when you begin your source ex #include <gb.h>
- Tile Editor
- -The tile editor is pretty easy to use, just when you export files you goto: export to..., and change the type to GBDK C file. NOTE: if you are exporting more than 1 sprite, dont forget to change the To: textbox. Also you can change the label to any name like Retard_Head but dont use spaces, or... YOU DIE!
- <no pics in plain text buddy>
- About the emulator: read the documentation that comes with it.
- PART4: A Little bit of C
- Some terms to learn:
- The four things computers and any useful machines have: input, output, storage, and logic. Input/Output: Immediately you can recognize that the GB has input through it's buttons. No input would be complete without some way of acknowledging it, output. In the case of our GB, we have a LCD screen capable of displaying 4 colors. Input/output seem to go hand in hand wherever you look. When something goes in, something comes out. In lew of this, the two things are usually globbed together under one term: "i/o", an abbreviation for input/output. Storage: Temporary and Permanent: We know that the GB has a i/o, but where does it keep the game data? The game screen seen is simply a display of the data where the GB keeps the shows whast um on the video ram(VRAM). Internally the GB has some place to store this data. This is, obviously, known as storage. When you turn off your gb its all gone. This means the data for the video is in temporary storage(RAM). In computery terms, our version of temporary storage might be defined as data storage which is reset, blanked, or invalid when necessary power is lost or shut off. Sounds complex, but just think: you turn of your gb. All temporary storage is gone. Than you take you gamepack out and turn the GB on and tadah!! The GAMEBOY logo apears! How, it was stored in the permanent storage(ROM) in this case the gameboy bios, that data was than copyed to the VRAM so that you could see it!!
- Any given storage, regardless of permanence, will have one of two different access privileges: read-only or read/write (I've never heard of write-only, but it if you create it you wont get rich). Read-only can never be changed while read/write storage can. It's that simple. And lastly the concept of storage could be described simply in terms of i/o from a storage machine/device. Say your GB storage is a little chip inside the GB. Reading data from that storage would be output from that chip received as input; and vice versa when writing.
- Logic: our machine can access input, display output, and keep a game screen in it's storage; but how does it bring all these things together and control them? Logic. You can think of logic as instructions that encompass reading input, writing output, and making decisions.
- Lets look at the logic for a supposed car game.
- If in the START button on the main screen is pressed start a new race.
- If you press left or right your car steers.
- If the A button is pressed, increase the speed by 2 every second and update the speedometer.
- If the B button is pressed, use a nitro and take one nitro out of your remaining ones.
- If your gas tank was filled, update the gas display.
- If the gallons of gas are smaller or equal to zero, stop the car.
- Easy huh!!??
- Identifiers(functions): would be like the names you use in spoken language. The character value of the name itself means nothing(like Joe doesnt have a meaning like table), it's who the name refers to that's important. An identifier basically a name or made up of names, just like you probably(unless your name is table) have a last and a first name. These identifiers act just like names because they "identify" something other than the name itself. An identifier is simply a label for data and/or functionality. Some very common identifyers are: main(), printf(), if() and many others. As said you can make up you identifyers:
- #include <stdio.h>
- myfunction(int q){
- if(q<10)printf("%d is less then 10",q);
- }
- main(){
- myfunction(5);
- }
- The output is:
- 5 is less then 10
- The function myfuncion() tests if q is less then then and then, if so is prints it.
- Operators: its simple: no oparators no logic. Operators are very important in C as in other languages. They compare, modify and set variables and constants. The operands are:
- NAME SYMBOL FUNCTION
- Equals = assigns
- Plus + add
- Minus - subtract
- Asterisk * Multiply
- Slash / Divides
- Comparisson equals == Compares if 2 values and/or variables/constants are the same
- Less then < Compares if A is less then B
- Greater then > Compares if A is greater then B
- Less then or equals <= Compares if A is less or equals to B
- Greanter then or equals <= Compares if A is less or equals to B
- Not equals to != Compares if A is not equal to B
- Double crazy e && AND logical
- Double vertical bar || OR logical
- The smallest C program: The smallest prgram you can write in C is:
- main(){}
- The output would be nothing.
- The compiler wont work if you dont have this inside your code. main() is the main function needed for your program. Is there where the compiler will put the other functions to work.
- Variable: exactly like in Maths, something that changes, varys. A variable in C is a placeholder for a value. A variable is used to store information used by the program. When you define a variable in your program, you tell the compiler how much memory to set aside Based on the type of variable, the compiler sets aside the required number of bytes of memory. In C there a several types of variables int(integers), char(ASCII characters), void(null), float(real numbers), double(large real numbers).
- Comments: in C if you want to put a special comment like a disclaimer or some hints one your source code you can do it with /**/ or //. Here is how:
- /* comment here
- saf dafds
- fsdaf
- */
- printf()("hi"); //this prints hi, but this comments wont be printed
- /*
- *this is
- *a legal
- *comment
- *very used in this format
- */
- Constants: they are also data storage locations. However the value of a constant remains the same throughout the whole program and you cannot set another value to a constant once it has been defined with a value. A constant can be defined by using #define name_of_the_constant value
- Includes: in C as in pretty much every other programming lenguages includes are very important. Includes are the insertion of other files in the header of your code, those files can contain basic functions like main() or if() or it can contain some other thing like the image maps for you game. You insert a include in a code with #include <filename.h> if you want for the compiler to look for the file in the default include folder(include/) or you change the <> for " " if you want the compiler to look for the include file in the same folder as your source code is.
- Loops:
- The While Loop: A while loop causes the set of statements within the loop to repeat again and again as long as the starting condition is true. The usage for the while loop is as follows:
- while (condition) //like while(a<10) it mean while a is less then 10 repat
- {
- statements;
- }
- The For Loop: A for loop is used for iteration of a set of statements like the while loop but it combines three different operations into one statement: initializing the index(a variable), checking for termination of loop, and incrementing the index. The usage for the for loop is:
- for (initialize index; test condition; increment index) /* like for(a=0;a<10;a++) it means a starts at 0 and while a is less then 10 a will be increased by 1 and the statements will be repeated*/
- {
- statements;
- }
- The index is initializd to a starting value. The statements within the loop are executed as long as the test condition evaluates to true. The test condition can be any valid C expression. The index is incremented after each iteration of the loop. Note that the increment index actually can map to any legal statement though it is mostly used in the way shown above.
- About the structure: You can write a whole C program in one line as the ; is what determines the end of a like:
- #include <stdio.h>
- main(){printf("Hello");printf("World");printf("IM HERE");}
- is completely accepted by a c compiler as:
- #include <stdio.h> //add the standard i/o header to your code
- main(void) //starts the main part of the code
- {
- printf("Hello World IM HERE");
- /*this up there will cause the GB to output whats between the quotes to the LCD*/
- /*to compile this source create a new file named hw.c and insert this lines in the file then save it in \sdk\gb-gb\x-x-x\bin. Run: lcc hw.c -o hw.gb have fun:)*/
- }
- The outputs for both will be:
- Hello World IM HERE
- the code above also is. All functions in C MUST contain () like main(); or cls();. In those 2 exemples the value requered beteween the parentesis is NONE or void wich is a type of variable that indicates 0. This is not accepted:
- #include <stdio.h>
- ma
- in(void)
- {
- pri
- ntf("Hell
- o World");
- }
- A instruction gotta be placed in the same line, unless your space on the line ends like:
- printf("fakdkljsdglkfdlasfjhlkghlhyrtiuyknm,fhckajhvmdfhyui fjhgkl hfkh k lfhk hklhk lhkljfdh klh kjlh sdkh klyfiu yewih kjheryi hkh kdshsfadhjhdskhfdlskhfakljhk lhkl hklhd khk hkhsdkhdfhkj kjh kjhkhf khd khkjf hkjhk hkjhd hkjdf hkh fkjhkj kdheiywriyrrh");
- Thats completely legal if you dont hit return since it would still be seen as a whole single line if you dont have word warp active. Also if you write 2 printf in separate lines the will still be in the same line, you have to use \n to skip lines:
- main(){printf(){"Hello\nWorld");}
- PART5: Coding1 variables + basic indentifyers
- Here is the commented source of a gb program that slowly prints a nice Hey Fuck You. Remember that the makefile will work only that comes with this zip file if you put it on a subdir on the BIN folder of you SBDK.
- /*
- *Open This in Full Window with no word wrap
- *This is a source was created by Vinicius Kursancew
- *Feel free to modify and distribute
- *This software has no warranty and dont blame me if your computer blows up while you use it
- */
- #include <gb.h> //include the Gameboy header with some specific identifyers
- ps(char ch){ //starts the ps custom identifyer, wich needs data input between the ()
- printf("%c",ch); //prints to the screen the value that ch contains
- delay(150); //waits for 0.3 seconds and proceed you can change it if you want
- } //ends this function
- main(){ //start of the main section of the program
- int rep; //defines a integer: rep
- disable_interrupts(); //turns off teh interrupts
- for(rep=0;rep<10;rep++){ //start the for loop: rep starts at 0, when the structure is done ad 1 to rep and if rep is not less then 10 stop and proceed with the rest of the program, it means that 9 lines will be printed
- printf("\n"); //prints a blank line
- ps('H'); //now we are using our function, it will print H(always pu between ' ' when a single character
- ps('e');
- ps('y');
- ps('!');
- ps('F');
- ps('u');
- ps('c');
- ps('k');
- ps(''); //Here a blank space is inserted
- ps('Y');
- ps('o');
- ps('u');
- ps('!');
- } //ends the for loop
- delay(2000); //waits for 2 seconds
- reset(); //resets the gameboy
- } //ends the main function
- Save this source in the SDD\gb-gb\x-x-x\bin\tut1\fuck.c (if you are using notepad dont forget to take .txt out)
- PART6: MAKEFILE(compiling)
- OK we got the source, now we have to compile, great! We will make a make.bat file. Open your favourite editor. Copy this to it:
- ..\lcc -Wa-l -c -o fuck.o fuck.c
- ..\lcc -Wl-m -Wl-yp0x143=0x80 -o Fuck.gb fuck.o
- Saving if for DOS/Windows users.
- -Save it and move it to make.bat
- -run it
- For *nix users:
- -Save it as mk
- -change the attributes to 4775(chmod 4775 mk)
- -run it
- PART7: SPRITES
- Yes lets put people on gameboy! Remember that the makefile will work only that comes with this zip file if you put it on a subdir on the BIN folder of you SBDK
- /*
- * in this source you will(maybe) learn how to place a background, a sprite and move the sprite around
- * use it at your own risk
- */
- #include <gb.h> //include the file gb.h to the header
- #include "i.h" //include our images to the header(its in this zipfile)
- int main(void){ //starts the main function
- int x,y,st,key,z; //define th integers x and y wich will be used to define the pacman position, key will be used later
- x=20; //set x as 20
- y=20; //set y as 20
- st=0; //sprite type(1=closed 0=open)
- z=0; //set z=0, z will be used for testing if its time to change sprite or not
- set_bkg_data(0,0,back); //set our backgroud data(1st tile, number of tiles, name of the bkg)
- set_sprite_data(0,3,sprt); //set our sprite data
- wait_vbl_done(); //wait for the visual blank to be done
- set_sprite_tile(0,0); //set our tile 0 as the tile 0 of our tile data-pacman open
- set_sprite_tile(1,1); //set our tile 1 as the 1st tile of our tile data-pacman closed
- SHOW_BKG; //display the background
- move_sprite(st,x,y); //place the sprite 0 in 20,20
- move_sprite(1,200,200); //place sprite 1 off the screen
- SHOW_SPRITES; //display the sprites
- key=0; //set key=0, key will be used to store joystick data
- while(!0){ //repeat the while structure forever
- key=joypad(); //set key with the current joypad value(Button up, down, A...)
- if(key==J_UP){ //if the up pad is pressed
- y-=1; //reduce y by one
- move_sprite(st,x,y); //move current sprite 1 point up
- }
- key=joypad(); //set key with the current joypad value(Button up, down, A...)
- if(key==J_DOWN){ //if the down pad is pressed
- y++;
- move_sprite(st,x,y); //move current sprite 1 point down
- }
- key=joypad(); //set key with the current joypad value(Button up, down, A...)
- if(key==J_LEFT){ //if the left pad is pressed
- x-=1;
- move_sprite(st,x,y); //move current sprite 1 point left
- set_sprite_prop(0,S_FLIPX); //flip sprite
- set_sprite_prop(1,S_FLIPX); //flip sprite
- }
- key=joypad(); //set key with the current joypad value(Button up, down, A...)
- if(key==J_RIGHT){ //if the right pad is pressed
- x++;
- move_sprite(st,x,y); //move current sprite 1 point right
- set_sprite_prop(0,0x00); //unfilp sprite
- set_sprite_prop(1,0x00); //unflip sprite
- }
- delay(20); //wait 20 ms
- z+=1; //add 1 to z
- if(z==5){ //if z is equals to 10
- move_sprite(st,200,200); //move current pacman out of screen
- if(st==0){ //if pacman is open now is closed
- st=1;
- move_sprite(1,x,y);
- z=0;
- goto jmp;
- }
- if(st==1){ //if pacman is closed now is open
- move_sprite(0,x,y);
- st=0;
- jmp:
- z=0;
- }
- }
- }
- reset(); //reset the GB
- }
- PART8: TKS
- There isnt a lot to put here i pretty much learned C by reading books in my library... thanks to H. Mulder tools, Jeff's devrs.com, Christopher W. Fraser and David R. Hanson.
- Me:
- V. Kursancew, born 8/25/85
- Questions about THIS TUTORIAL: vkcorp@zaz.com.br
- UIN 43437330 or PeDrEiRo- on EFnet
- This doc was written in July/2001
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement