Showing posts with label Homebrew. Show all posts
Showing posts with label Homebrew. Show all posts

Friday, November 20, 2009

Programming games for Nintendo WII part 1

The first thing that you need to start Wii programming is to get the proper development tool. You will need the DevkitPPC witch is the part of the DevkitPro toolchain used for Wii and Gamecube development. These guides describe setting up such a system.

Installing devkitPPC forWindows

  • Go to this page and download the latest Windows installer.
  • Let it install to the C:\devkitPro\ to make it easier to follow the tutorial for now.
  • When installing it, you can deselect devkitARM and devkitPSP
  • Click next until it finishes installing

Setup your project folder

  • Under no circumstances should you place projects within the devkitPro folder. The windows updater can and will overwrite/delete your files.
  • Create a new folder outside the devkitPro folder, c:\projects\wii for example. This path should not contain spaces.
  • Copy the folder C:\devkitPro\examples\wii\template\ to this new directory and rename it to "helloworld" so that the full path is c:\projects\wii\helloworld\

Compile the Hello World Example

  • Assuming you installed Programmer's Notepad through the installer, double click the .pnproj file in your new project.
  • Click on Tools->make or use the ALT+1 key combination
  • The output window at the bottom will show the build progress
Note: If you are having trouble compiling some programs under Windows Vista (eg. libogc cvs), try unsetting PLATFORM variable. (in msys shell, "unset PLATFORM")

Run the Hello World Example on the emulator

  • Now, browse to the helloworld folder. There should be a helloworld.dol file here now.
  • Run the hellworld.dol in an emulator. As of 31-Mar-2009, emulators for the Wii are not 100% compatible and feature complete. Dolphin can successfully run some homebrew. See the Dolphin page for more information. Another emulator is Gcube. Gcube does not run homebrew compiled in Wii mode, but can run homebrew if compiled for the GameCube mode. See the Gcube page for more information.

Run the Hello World Example on the Wii using wiiload

  • For this to work, you need to have the Homebrew Channel installed on your Wii and a way to access the Wii via TCP.
  • Get wiiload.exe from the Homebrew Channel archive (should be in wiiload\win32) and copy it to C:\devkitPro\msys\bin.
  • Set the environment variable WIILOAD to something like "tcp:192.168.0.30" (replace the IP with your Wii's IP). This can be done via Control Panel -> System -> Advanced -> Environment Variables. Then restart windows.
  • Start the Homebrew Channel on your Wii.
  • Click on Tools -> run or use the ALT+R key combination.
  • The output window at the bottom will show the upload progress (so does the Homebrew Channel) and the example will be started on your Wii when it's done. 

Installing devkitPPC for Linux

Installing through the repositories

It may be possible to install devkitPPC via your linux distro repositories. Try searching for devkitPPC MYDISTRO [1].
If you are using Ubuntu or Debian, there is a repository with .deb files maintained by UCLM university.
1. Add to sources.list file the lines
deb http://arco.esi.uclm.es/~francisco.moya/debian ./
deb http://arco.esi.uclm.es/~francisco.moya/debian-amd64 ./
deb-src http://arco.esi.uclm.es/~francisco.moya/debian ./
2. Execute sudo apt-get update
3. Execute sudo apt-get install devkitpro-ppc
The files will be installed at /opt/devkitPro with read-only permission. You can do a copy of the examples directory in your user space and then compile and run in the normal way.
cp -r /opt/devkitPro/examples/ .
cd examples/wii/template
make
make run

Installing devkitPPC from DevkitPro packages

A premade archive of these files (organized according to the directory structure below) is available here
Note: The US mirror for DevkitPPC can be slow, so you might have to switch to a European one.
Note: Extract the files from the devkitPPC tarball using "tar -xvjf " to preserve symlinks, etc...
  • Create a folder for devkitpro and extract everything into it such that you have this directory structure:
devkitpro
  devkitPPC
  wii-examples
  libogc (extract the libfat tar under this directory as well)
  • Edit ~/.bashrc and add
export DEVKITPRO=/path/to/devkitpro # replace this by your actual path
export DEVKITPPC=$DEVKITPRO/devkitPPC
PATH=$PATH:$DEVKITPPC/bin
  • Optionally, find out your Wii's IP with the homebrew channel and add
export WIILOAD=tcp:192.168.1.5 # replace this by your Wii's IP
  • Restart your terminal or type
source ~/.bashrc

Compiling a Hello World

  • Enter devkitpro/wii-examples/template and simply type
make
  • To run the example on your Wii, start the homebrew channel and type
make run
VoilĂ ! You just compiled your first Wii program!

Compiling Insight Debugger

A custom version of the Insight graphical debugger is included as part of the DevkitPro package, however currently there are no linux binaries available. In order to successfully compile the source under linux, you need to run the following sequence of commands from the directory where you unpacked the source:
for f in `find`; do dos2unix ${f}; done
./configure --target=powerpc-gekko
make
make install prefix=/directory/to/install/to

Using DDD (GNU Data Display Debugger)

An alternative to Insight is DDD
It has the advantage that you won't have to compile it on linux
For instance to install it on ubuntu just use the following command:
sudo apt-get install ddd
Then you use ddd with powerpc-gecko-gdb with the following:
ddd --debugger path-to-powerpc-gecko-gdb
And finally you can use the console at the bottom to connect to your wii and load the symbols as you would using gdb from the console
For instructions on how to use gdb or insight for remote debugging, see Remote Debugging with GDB

Installing devkitPPC for Mac OS X

 

  • First make sure you have Xcode tools 3 (note that this requires Leopard) or above installed then go here and download the latest Mac distro (actually we don't have the latest release as pkg. Try the higher release with a pkg. If you see the latest release with a pkg, please remove this). Also download gcube emulator for mac.
  • Double-click the devkitPPC.pkg and follow the set-up instructions then log out and back in or restart.

Compile the Hello World Example

  • Launch Xcode
  • Select "New project..." from the File menu
  • Select "devkitPPC Wii Project"
  • Name your project, and pick a place to save it
  • Hit "Build"
  • The completed .dol file will (by default) be found in build/Development

Run the Hello World Example

  • To run the file again open Terminal and type “gcube ~/Desktop/WiiBrew/devkitPPC\GameCube\Project/build/Development/devkitPPC” no quotes obviously.
  • The resulting dol should be compatible with the Twilight Hack. Unfortunately dols compiled with CVS libogc and future stable releases will not be compatible with Gcube.

Some Code snippets

libogc provides a jump back to the loader through the standard libc exit function. exit(0) will immediately return, all other values will display a console screen with the exit code.
  • Add this in your main while loop, under "VIDEO_WaitVSync()":
PAD_ScanPads();
int buttonsDown = PAD_ButtonsHeld(0);
if( (buttonsDown & PAD_TRIGGER_Z) && (buttonsDown & PAD_BUTTON_START)) {
  exit(0);
}
 
source wiibrew.org/wiki/Devkitppc_setup

Sunday, October 25, 2009

Super NES Programming/Initialization Tutorial

Required tools

Assembler directives

If you decide to put the init routine and the header in separate files, it will be necessary to tell the assembler to include them.
.include "header.inc"
.include "Snes_Init.asm"
VBlank:    ; Needed to satisfy interrupt definition in "header.inc"
    RTI
This part can be skipped by putting the header and init code in your main file.

Starting the program

In the header file, the label "Start" is declared as the reset vector, so that is where the program shall begin executing:
Start:

Initializing the SNES

Most demos reset the SNES to a known state. Since emulators probably start in a known state, it may be unnecessary to reset the state for an emulated ROM. Resetting the SNES, however, may be necessary for the demo to run on actual SNES hardware.
To reset the SNES, we set a number of hardware registers to zero and zero all the bytes in WRAM. Here, we use the initialization macro Snes_Init from the file "Snes_Init.asm" from the SNES Devkit, which does this for us:
; Initialize the SNES.
    Snes_Init

Setting the background color

First, we set the accumulator to 8 bits, to modify single bytes of RAM. We do this by setting the appropriate bit in the CPU status register:
sep     #$20        ; Set the A register to 8-bit.

Step 1: Force VBlank

The SNES refreshes its screen to match the signal output to the television, so knowing how the television updates its image can help you understand how certain special effects are performed in the SNES.
A television displays an image on the screen using an electron beam, which it sweeps across the screen from left to right, one horizontal line at a time from top to bottom. Additionally, television images are interlaced, meaning that the television alternates displaying a screenful of all the even-numbered scanlines with a screenful of all the odd-numbered scanlines; each screen of even- or odd-numbered scanlines is called a field. An NTSC television (as used in the U.S. and Japan) displays roughly 30 frames per second, while a PAL television (as used everywhere else) displays 25 frames per second. Thus, an NTSC television displays about 60 fields per second, while a PAL television displays 50 fields per second.
Between lines, when the electron beam is being moved from the right end of one scanline to the left beginning of the next scanline, the electron beam is turned off; this is called the horizontal blank or HBlank. Certain special effects -- like the perspective effects of the Final Fantasy VI airship -- can be performed on the SNES by changing graphics settings during HBlank.
Likewise, between fields, when the electron beam is being moved from the bottom of the screen to the top, the electron beam is turned off; this is called vertical blank or VBlank. If you update the screen while the electron beam is turned on, the results displayed to the user are unpredictable; they may shear or have other artifacts. Therefore, you want to make all your modifications to the screen during HBlank or VBlank. Since VBlank is much longer than HBlank and covers the whole screen, most updates should be done during VBlank. VBlank occurs once per field, or about 60 times per second on NTSC machines and 50 times per second on PAL machines.
There are two ways to ensure that your code executes during a VBlank:
  • Wait for a VBlank non-maskable interrupt (NMI).
  • Turn off the screen by setting the eighth bit of the Screen Display Register ($2100).
Here, we force VBlank by turning off the screen, using the following code:
lda     #%10000000  ; Force VBlank by turning off the screen.
    sta     $2100

Step 2: Setting the Background Color

The SNES stores 16-bit colors in the following format:
  • High byte: 0bbbbbgg
  • Low byte: gggrrrrr
The color that we will use is 00000000 11100000 (0 blue, 7 green, 0 red) -- a dark green. We set the background color of the screen using the Color Data Register ($2122):
lda     #%11100000  ; Load the low byte of the green color.
   sta     $2122
   lda     #000000  ; Load the high byte of the green color.
   sta     $2122

Step 3: Ending VBlank

We end the VBlank by turning the screen back on and setting the brightness to 15, again using the Screen Display Register ($2100):
lda     #001111  ; End VBlank, setting brightness to 15 (100%).
   sta     $2100

Ending the program

Unlike many computer programs, SNES programs aren't really designed to end. SNES games are intended to keep running until the user turns the system off or presses reset. In our case, though, the SNES has done all that we wanted it to do, and now we would like it to sit still and not change anything. We accomplish this with an infinite loop:
; Loop forever.
Forever:
    jmp Forever
If we didn't have this loop at the end, the SNES would start executing any code or data that happened to follow our program, which may make the SNES do something that we didn't intend.
Alternatively, we also could've used the "STP" command. This command stalls the SNES' CPU until the console is reset. The endless loop is a good practice, though, because eventually we'll need a main program loop, and that is what this will become.

Assembling the ROM

Once we have our program in a file -- let's call it "Greenspace.asm" -- we want to assemble it into a ROM image, so that we can run it in an emulator. First, we execute the WLA 65816 assembler to turn the assembly file into an object file:
wla-65816 -vo Greenspace.asm Greenspace.obj
This should create the object file "Greenspace.obj".
Then, we need to link the object file into a ROM. The WLA linker requires a link file that lists the files to be linked. We'll make one called "Greenspace.link" with the following contents:
[objects]
Greenspace.obj 
Then, all we need to do is to execute the WLA linker:
wlalink -vr Greenspace.link Greenspace.smc
This should create the ROM image "Greenspace.smc", which we can then run in an emulator.
To make the compile and link steps easier to run repeatedly -- as we might want to do when alternating between editing and testing -- we can put the commands in a shell script, "Greenspace.bat" in DOS/Windows, or "Greenspace.sh" for UNIX.
wla-65816 -vo Greenspace.asm Greenspace.obj
wlalink -vr Greenspace.link Greenspace.smc
If you use UNIX you need to add #!/bin/bash as the first line of the file. Under Windows, it's a good idea to add @echo off as the first line.

Complete source code

; SNES Initialization Tutorial code
; This code is in the public domain.

.include "Header.inc"
.include "Snes_Init.asm"

; Needed to satisfy interrupt definition in "Header.inc".
VBlank:
  RTI

.bank 0
.section "MainCode"

Start:
    ; Initialize the SNES.
    Snes_Init

    ; Set the background color to green.
    sep     #$20        ; Set the A register to 8-bit.
    lda     #%10000000  ; Force VBlank by turning off the screen.
    sta     $2100
    lda     #%11100000  ; Load the low byte of the green color.
    sta     $2122
    lda     #000000  ; Load the high byte of the green color.
    sta     $2122
    lda     #001111  ; End VBlank, setting brightness to 15 (100%).
    sta     $2100

    ; Loop forever.
Forever:
    jmp Forever

.ends
source
en.wikibooks.org/wiki/Super_NES_Programming/Initialization_Tutorial

Thursday, October 8, 2009

Play Homebrew applications on Nintendo DSi

For those who do not know what homebrew applications are and they have never used one i must say that they have not seen what a DSI can do. DSI is a magnificent computational machine with many capabilities and must not be limited to licensed games for this console. Nintendo DS Homebrew applications are free software that has been created by independent developers and has not the Nintendo lisence. You can find applications such as these by a simple google search Nintendo DSi homebrew applications. There are thousands of games, with commercial quality that can be downloaded absolutely free. but there are mp3/4 players, internet browsers and many more application  All you need is a flash card and the proper DSI rom. The ligal purpose of these mod cards are to play Hombrew applications but thay can play and lisenced backup roms that can be downloaded from the web. Of course this is completely illegal.
There are many mods i know theEZ FLash Vi, M3i Zero, AceKard 2i, R4I Gold and others. I have the AceKard 2i and the steps that you must do to play homebrew are.


Format a MicroSD card with the the formatter that you can find at http://gbatemp.net/index.php?download=4003
Get the latest version of the AKAIO software from http://gbatemp.net/index.php?download=5069 and put the _aio folder with the akmenu4.nds in the root directory of the MicroSD card
Extract the ak2loader.nds into _aio/loaders
Insert the MicroSD card into your Acekard
Insert the Acekard in your DSi
And play

There is and a video guide on youtube about this