...............................................................................
    SAMPLE CODE FOR VIPER GC, V0.1
...............................................................................

INTRODUCTION

    Here is a sample code for Viper GC that will show you how to use its
    special features. The following are the currently documented features:
    
    - Run patched (or unpatched) Original BIOS from your own code
    - Read the second DIP switch of the Viper GC Programmer
    - Control of the lid sensor passthru
    - Reflash the Viper GC directly from the GC
    
    This package is not a tutorial about GC programming, there are lots of 
    other resources for that!

TOOLS NEEDED

    - devkitPPC_r8 Cross Compiler (see Resource section)


VIPER GC FLASH FORMAT

    Bytes 0x00-0x03 : "VIPR"
    Byte  0x04      : Configuration Flags (default = 0x00)
                            FLAG_DISABLE_CHIP    = 0x01
                            FLAG_EXTENDED_MODE   = 0x04 
                            FLAG_COMMAND_MODE    = 0x08 
                            FLAG_GC_FLASH_ACCESS = 0x80
    Byte  0x05      : Lid sensor status at boot time (default = 0xFF)
                            FLAG_LID_OPEN        = 0x00
                            FLAG_LID_CLOSED      = 0x01
                            FLAG_LID_PASSTHRU    = 0x02
    Bytes 0x06-0x0F : Padding
    Bytes 0x10-0x1F : BIOS Name (16 characters or zero terminated string)
    Bytes 0x20-.... : Encrypted BIOS, loaded at 0x81300000 in GC memory
                          
                          
    FLAG_DISABLE_CHIP disables the Viper GC (GC boots to original BIOS)
    FLAG_EXTENDED_MODE must be set if you want to run patched Original BIOS or
                       if you want to use command mode
    FLAG_COMMAND_MODE must be set if you want to use the Viper commands
    FLAG_GC_FLASH_ACCESS must be set if you want to allow access to the Viper
                         GC flash from the GC

                                                                           
SPECIAL COMMANDS
    
    READ CARFULLY :
    
      Command mode is NOT AVAILABLE after any BBA, Modem, Memorycard 1, 
      IPL, SRAM or RTC access as they share the same bus and will interfere with
      the communication. Call ViperExitCommandMode() before doing an access
      to any of these devices if you're in command mode.

    Read viper.h and viper.c files for more information about using
    the Viper GC commands.    

    DON'T FORGET :

    - If FLAG_COMMAND_MODE is set, then FLAG_EXTENDED_MODE _must_ be set.
    - If FLAG_EXTENDED_MODE is set, you _must_ call ViperInit(), and that 
      _before_ doing any access to the already-mentioned critical devices.
      You _can't_ call ViperInit() if this flag is not set     
    - If FLAG_COMMAND_MODE is set, then the Viper GC is automatically in
      command mode after ViperInit() is called. Don't forget to call 
      ViperExitCommandMode() before hotresetting the GC / running a game /
      accessing the IPL, SRAM, RTC, Memcard 1, BBA or modem


ENCRYPTED BIOS ?

    As specified in the Viper GC Flash format, the content of the BIOS must
    be encrypted with a keystream. If you have this keystream, just "xor" it
    with the decrypted BIOS content to obtain the encrypted equivalent. 
    
    Is the Keystream needed?
    
        No. This package provides the source and binary of a small loader 
        (binload) that runs a gamecube program which doesn't have to be 
        encrypted, or the Original BIOS if the 'X' button is pressed. 
        The loader itself was already encrypted with the correct keystream. 
        The downfall of using this loader is that it takes 1 or 2 seconds to
        boot the program/BIOS (it takes less than one second if the original
        program/BIOS is simply encrypted with the keystream)
    
    How to obtain the keystream ?
    
        After calling ViperInit(), the content of the ENCRYPTED Original BIOS
        is located at ADDR_ENCRYPTED_IPL and the content of the DECRYPTED
        Original BIOS is located at ADDR_IPL. By making a "xor" of the two
        buffers, you just obtained the keystream needed to encrypt your own
        BIOS! You just need a way to transfer it to the PC.
        
    
BINLOAD USAGE

    Let's build a concrete Viper Flash File using binload in a DOS box. For 
    this example we need MAZE DEMO by dovoto and DOLTOOL by loser, use google
    to find those two files.
    
    Maze demo zip file contains a file named intro1.dol. It's in DOL format, 
    but binload needs BIN format (starting at 0x80003100), so we must convert
    it with doltool:
        
        doltool -b intro1.dol
        
    We now obtained intro1.bin. Let's append it to binload
    
        copy /b binload.bin+intro1.bin maze.vgc
        
    That's it! Flash the file on your Viper GC and you should see the 
    homebrew maze on your screen! Don't forget that you can hold X at startup
    to run the Original BIOS.        
   

DO I NEED TO UNPLUG THE PARALLEL PORT CABLE WHEN I TURN ON THE GC ?

    User manual states that the Parallel Port connector has to be unplugged
    when you don't want to update the flash. This is to avoid any problem 
    with any Parallel Port interface for the common users. It is possible 
    anyway to leave the Parallel Port connector plugged if you are a developper
    in most of the cases.
    Problems may appear when the computer just started and Parallel port was
    not yet used. If Viper GC is booting to Original BIOS or dispays a black 
    screen instead of running the content of its flash, try the "Reset Parallel 
    Port" function of the Viper GC Flashing software, or just write 0x00 to the 
    Parallel Port Data Bus.
    Also, you don't need to change any DIP switch, the Viper GC can be 
    reprogrammed regardless of the state of the DIP switches.

   
AND NOW...

    Please look at the source files for more information, viper.h contains
    a description of the Viper API. Have fun exploring the Viper GC potential!


RESOURCES

    DevkitPro, Cross compiler & Libraries for Gamecube
         http://sourceforge.net/projects/devkitpro   

    GC-Linux, Gamecube Linux, hosts the best Gamecube Programming Documentation
         http://www.gc-linux.org

    Google, Search for Gamecube Development! :-)
         http://www.google.com                  


LEGAL DISCLAIMER
    
    All trademarks are the property of their respective owners