Author Topic: Tutorial: How to make a simple N64 program (Beware: Many pictures)  (Read 31107 times)

0 Members and 1 Guest are viewing this topic.

Offline sanni

  • Moderator
  • Hero Member
  • *****
  • Posts: 504
Did you ever wanted to create your own program on the N64?

Yes? Then let me invite you to this little tutorial :)
No? Well I hope you still find it entertaining ;)

First of all I have no clue about what I'm going to talk here, I can't program and all that will follow after this warning is a just a documentation of me applying the principles of copy&paste and trial&error.
But this is actually a good thing because I will explain everything from a beginners perspective so it should be easy for everyone to follow.

Disclamer: I only used Open Source Software, everything I discuss or link here is completly legal.
Introduction:
Thanks to Shaun Taylor's amazing work on libdragon it has become very easy to write little programs for your favorite console the N64.

In this tutorial we will use the virtualization software VirtualBox together with Ubuntu and libdragon to create a 100% legal development kit for the N64.

Every step will be documented with a picture.

Step 1: Setting up VirtualBox

A) First you need to download and install Virtualbox: https://www.virtualbox.org/wiki/Downloads

B) Next you need to download and extract my premade hdd image that contains both Ubuntu and libdragon preinstalled.
Since both libdragon and Ubuntu are open source it's absolutly legal to link you to this image: https://mega.nz/#!hENlWAYC!tLgxtEqsRVoNuUq2oq10t1p2g17e1SNPASnwhdszZ3A (1000MB)
If you need a program to extract the file I recommend 7zip

C) After you started VirtualBox you need to create a new virtual machine


D) Name it N64DEV and make sure to select Linux and Ubuntu from the dropdown menues


E) In the "Virtual Hard Disk" window click on "Use existing hard disk"(1), then click on the browse icon(2) and select the hdd image you downloaded earlier(3)


F) After setting up your Virtual Machine click on "Start" to run it


Step 2: Inside Ubuntu

A) Log in with password: dev


IMPORTANT: To change the keyboard layout click on the little "Deu" icon on the top bar and choose your keyboard layout.

B) On the top bar click "Places" and then "Home Folder"


C) Browse to libdragon/examples(1) right-click on "spritemap"(2) and select Copy(3) to Desktop(4). Then rename the new folder on the desktop to n64forever.

The examples directory has many coding examples that teach you how to program with libdragon. Instead of creating our little program from scratch we will just copy one of the examples and alter it to our liking.

D) I want to put the N64 Forever logo into our program.
So I downloaded and resized it to approx 200 pixels on my Windows machine, saved it as N64Forever.PNG and then transfered it to Ubuntu.
To transfer the picture to Ubuntu running in the virtual machine I used a service called dropbox. But you could upload it on mediafire or any other online storage site too. Then open Firefox in the virtual machine and download it again.


E) To use the picture in our program we have to convert it first. So copy the picture onto the desktop. Right-click somewhere on the desktop and select "Open in Terminal".
A black window should pop up.
Write the following in it:
Code: [Select]
$N64_INST/bin/mksprite 32 N64Forever.png n64f.spritePress Return/Enter to execute the command.


F) A new file called n64f.sprite should be on your desktop now. Double click on the n64forever folder on your desktop(the one you created in step 2C) and then open the filesystem directory.
Delete the files that are already in there(1) and move our n64f.sprite in this directory(2).


Step 3: Editing the Makefile

A) First we need to edit the Makefile in our n64forever directory. Since we just copied it from the spritemap example.
Rightclick on Makefile and choose "Open with Geany"


B) We need to replace
Code: [Select]
PROG_NAME = spritemapin line 9 with
Code: [Select]
PROG_NAME = n64forever
And
Code: [Select]
$(N64TOOL) -b -l 2M -t "Spritemap Test"in line 20 with
Code: [Select]
$(N64TOOL) -b -l 2M -t "n64forever"



C) Save the file and close Geany.

Step 4: Programming

A) In our n64forever directory rename spritemap.c to n64forever.c

Next right-click on it and choose "Open with Geany"

B) Now alter the code like this
Code: [Select]
#include <stdio.h>
#include <malloc.h>
#include <string.h>
#include <stdint.h>
#include <libdragon.h>
#include <stdlib.h>

int main(void)
{
    /* enable interrupts (on the CPU) */
    init_interrupts();

    /* Initialize Display */
    display_init( RESOLUTION_320x240, DEPTH_32_BPP, 2, GAMMA_NONE, ANTIALIAS_RESAMPLE );
   
/* Initialize Filesystem */
    dfs_init( DFS_DEFAULT_LOCATION );
   
    /* Initialize Controller */
    controller_init();
   
    /* Read in single sprite */
    int fp = dfs_open("/n64f.sprite");
    sprite_t *n64f = malloc( dfs_size( fp ) );
    dfs_read( n64f, 1, dfs_size( fp ), fp );
    dfs_close( fp );
   
    /* define two variables */
    int x = 40;
    int y = 100;

    /* Main loop test */
    while(1)
    {
        static display_context_t disp = 0;

        /* Grab a render buffer */
        while( !(disp = display_lock()) );
       
        /* Fill the screen */
        graphics_fill_screen( disp, 0 );
       
/* Create Place for Text */
char tStr[256];

        /* Text */
        graphics_draw_text( disp, 10, 10, "N64 FOREVER" );

/* Logo */
graphics_draw_sprite_trans( disp, x, y, n64f );

        /* Scan for User input */
        controller_scan();
        struct controller_data keys = get_keys_down();

/* If Dpad is pressed move Image */
        if( keys.c[0].up )
        {
y = y+5;
        }
        else if( keys.c[0].down )
        {
y = y-5;
        }
        else if( keys.c[0].left )
        {
x = x-5;
        }
        else if( keys.c[0].right )
        {
x = x+5;
        }

sprintf(tStr, "X: %d\n", x );
graphics_draw_text( disp, 10, 20, tStr );
sprintf(tStr, "Y: %d\n", y );
graphics_draw_text( disp, 10, 30, tStr );
       
        /* Update Display */
        display_show(disp);
    }
}

You will notice that we deleted quite a bit and added a few lines of our own.

C) Save the changes

Step 5: Compiling

A) Right click somewhere in our n64forever directory and choose "Open in Terminal"

B) In the box that pops up write
Code: [Select]
makeAnd execute by pressing Return/Enter.


C) If everything worked it should look like this:

If not you probably got a typo, check which line it complains about and fix it in the code.

D) Lots of new files should have been created, but we only care for n64forever.v64. Thats our rom we want to run on our N64.
You can use the Mess emulator to test your program on your PC:
http://messui.the-chronicles.org/



Step 6: Upload the program
To get the n64forever.v64 rom to your Windows machine use dropbox or mediafire again. Upload it through Firefox in Ubuntu then download it again from within Windows.



Step 7: Running the program
To run the program on your N64, you need a flashcart. Just copy the n64forever.v64 to the flashcarts SD card and launch it from the flashcarts menu.


And thats how our program looks like:

You can move the N64 Forever logo around the screen with the dpad.
« Last Edit: November 23, 2015, 03:41:24 PM by sanni »

Offline ChillyWilly

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1751
  • Just a coding machine.
Re: Tutorial: How to make a simple N64 program (Beware: Many pictures)
« Reply #1 on: July 31, 2012, 05:57:58 AM »
Great tutorial! One thing... when you get to the point of opening a terminal to make the program, look at the bottom left of Geany - there's some vertical tabs, one of which says "terminal" - click that tab and you are in a terminal... you can even set a preference in Geany so that the terminal is in the directory of the currently active file. Make sure the makefile (or another file in the same directory) is active and you won't need to do anything but run "make" in the Geany terminal.

Offline ChillyWilly

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1751
  • Just a coding machine.
Re: Tutorial: How to make a simple N64 program (Beware: Many pictures)
« Reply #2 on: November 03, 2012, 01:12:45 AM »
If you use anything but the official Nintendo SDK or the PsyQ SDK, you'll find the only emulator that runs it is MESS. MESS is designed to run at a low level, while all other emulators currently out run at the highest level for best speed. MESS needs some small files to run N64 roms... I posted them for the last compo. You can find them in my post here.

Offline sanni

  • Moderator
  • Hero Member
  • *****
  • Posts: 504
Re: Tutorial: How to make a simple N64 program (Beware: Many pictures)
« Reply #3 on: November 04, 2012, 12:18:30 PM »
MESS Tutorial:

Downloads:

Mess emulator with messui: http://messui.the-chronicles.org/
N64.zip(search for N64.zip in that list then copy the downloaded n64.zip into a directory called roms inside the emulators folder): http://www.emunews.eu/mess-bioses/
Finally, if you want to use a real N64 controller, you need an usb adapter. I recommend this one: http://www.raphnet-tech.com/products/gc_n64_usb_adapters/index.php?category=N64

1) Create a "mess" folder. Put the "mess.exe" and the "messui.exe" into that.

2) Then create a "roms" folder inside the "mess" folder. Put the "N64.zip" there.

3) If you are on Windows 7, always run "messui.exe" as Administrator(right click "run as administrator") or it won't save any settings.

4) After you launched MESSUI.exe search for Nintendo 64 in the list, click on it, and in the middle column choose the "Device View" tab and press [...] then mount to put the rom into the cartslot.

5) Next go to "File" and choose "run N64"

6) Type OK twice or move the arrow keys and your program should run.

7) You can change the controls in MESS if you click "File" then "Show Tab Menu" then choose "Input (this System)" while the N64 emulation is running.

Offline MrElephant

  • Newbie
  • *
  • Posts: 2
  • NEO newbie
Re: Tutorial: How to make a simple N64 program (Beware: Many pictures)
« Reply #4 on: November 16, 2014, 05:51:16 PM »
I know this topic is very very old, but if someone could upload the n64 dev kit again
it would be very helpful (the one that came with linux in the first post).
This is one of the very few tutorials I could find explaining how to get started and
having this kit would be very helpful.

I am sorry about replying to an old thread, but I thought it was necessary because
there are people out there who want to make n64 homebrews and the official
homebrew kit is very very compicated.

Sorry for bothering everyone

Thanks Again
-MrElephant
« Last Edit: November 16, 2014, 06:07:43 PM by MrElephant »

Offline sanni

  • Moderator
  • Hero Member
  • *****
  • Posts: 504
Re: Tutorial: How to make a simple N64 program (Beware: Many pictures)
« Reply #5 on: November 17, 2014, 09:48:02 PM »
I updated the link in the first post. Let me know if it doesn't work.  ;D

Offline MrElephant

  • Newbie
  • *
  • Posts: 2
  • NEO newbie
Re: Tutorial: How to make a simple N64 program (Beware: Many pictures)
« Reply #6 on: December 21, 2014, 07:59:02 AM »
All right.  I will do that. I couldnt download it until now because I was finishing up my semester at college, and was also starting a new internship.
Thanks again for making a new link. :)


Offline sanni

  • Moderator
  • Hero Member
  • *****
  • Posts: 504
Re: Tutorial: How to make a simple N64 program (Beware: Many pictures)
« Reply #7 on: January 02, 2015, 07:15:46 PM »
Btw. if you are living in the PAL region and for some reason your TV won't display your homebrew correctly then you can force the homebrew to 50Hz for PAL by hex editing the rom at offset 3E(.z64) or 3F(.v64) from 00 to 50.
« Last Edit: January 02, 2015, 11:24:28 PM by sanni »

Offline degenatrons

  • Newbie
  • *
  • Posts: 2
  • NEO newbie
Re: Tutorial: How to make a simple N64 program (Beware: Many pictures)
« Reply #8 on: November 20, 2015, 06:00:48 PM »
Hi,

I'd love to take a look at this dev kit VM but the DL link is dead.  I appreciate this is an old post.  Would be great if you could update the link and I can follow your excellent instruction to get started in N64 dev.  Here's hoping.

Jon

Offline sanni

  • Moderator
  • Hero Member
  • *****
  • Posts: 504
Re: Tutorial: How to make a simple N64 program (Beware: Many pictures)
« Reply #9 on: November 23, 2015, 03:41:59 PM »
Link updated.

Offline degenatrons

  • Newbie
  • *
  • Posts: 2
  • NEO newbie
Re: Tutorial: How to make a simple N64 program (Beware: Many pictures)
« Reply #10 on: November 23, 2015, 10:02:22 PM »
Link updated.
oh man  :)
Thanks for your update sanni.  Grabbing it now.


Offline Conle

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2200
Re: Tutorial: How to make a simple N64 program (Beware: Many pictures)
« Reply #11 on: November 25, 2015, 01:45:05 PM »
Why isn't this topic sticky already?  ^-^  Let me fix this   ~sm-54.gif~.gif