Tutorial

## 8 Appendix - Using the Controller Pak with NuSystem

### [1] Handling the Controller with NuSystem

Exclusive control is necessary when accessing devices like the Controller, Controller Pak and Rumble Pak which utilize the serial interface in N64.

In NuSystem, the controller manager handles access to the serial interface for the Controller, Controller Pak and Rumble Pak. Thus, the game application does not need to bother itself with the question of exclusive control, and instead can just access the devices.

### [2] Procedure for accessing the Controller Pak

The following procedure is used to access the Controller Pak. Note that different error checks are made at each step. Device error checks are made in step (1), game note error checks in step (2), and note access error checks in step (3). Apportioning the errors in this manner simplifies the procedure for accessing the Controller Pak.

#### (1) Recognize Controller Pak

Check to see if a Controller Pak has been inserted into the Controller.

Example:

>     NUContPakFile pakFile;

>     nuContPakOpen(&pakFile, 0);

>     if(pakFile.error){
>     	// process errors  PFS_ERR_NOPACK, PFS_ERR_NEW_PACK,
>     	// PFS_ERR_CONTRFAIL, PFS_ERR_ID_FATAL,  PFS_ERR_DEVICE
>     }

#### (2) Open the Game Note

If a Controller Pak is recognized, the next step is to open the game note you want to access. This step is similar to "File Open" in DOS.

Before accessing a note the company code and game code is set in the controller manager. (These values are normally unique to each game, so once they have been set there is no particular reason to reset them.)

After this, the note with the specified note name and extension is opened.

In NuSystem there are two ways to specify the note name and extension. One way is with the N64 font code, and the other is with the ASCII code. N64 requires that N64 font code be used for the note name and extension, but this is a big nuisance for the programmer. For this reason, a function has been prepared in NuSystem that enables the name and extension to be specified using JIS code. The conversion of JIS code to N64 font code is carried out internally by the function. (The code conversion functions are nuContPakJisToN64 and nuContPakN64ToJis. Note that the kana voiced and semi-voiced consonant marks are also converted, so the number of characters will change.)

Example:

>     // register company code and game code
>     nuContPakCodeSet("64", "mami");

>     // open note
>     nuContPakFileOpenJis(&pakFile, "mami no himitu", "a"
>     			,NU_CONT_PAKCREATE, 256);

>     if(!pakFile.error){
>     	// process errors PFS_ERR_INCONSISTENT,  PFS_ERR_INVALID,
>     	// PFS_DATA_FULL, PFS_DIR_FULL
>     }

#### (3) Read/write to Game Note

When the game note opens without errors, read/write can be performed.

>     u8 buffer[256];
>     nuContPakFileRead(&pakFile, 0, 256, buffer);

>     if(!pakFile.error){
>     	// process errors PFS_ERR_BAD_DATA
>     }

#### (4) Controller Pak Access Flow Diagram

>                                        Class of
>           -------------   error        errors checked
>         < nuContPakOpen >------------>PFS_ERR_NOPACK
>           -------------               PFS_ERR_NEW_PACK
>                |                      PFS_ERR_CONTRFAIL
>                |                      PFS_ERR_ID_FATAL
>                |/                     PFS_ERR_DEVICE
>          ---------------   error
>        < nuContPakFileOen >---------->PFS_ERR_INCONSISTENT
>          ---------------              PFS_ERR_INVALID
>                |                      PFS_ERR_DATA_FULL
>                |                      PFS_ERR_DIR_FULL
>                |/
>        -------------------   error
>      <   nuConrPakFileRead >--------->PFS_ERR_BAD_DATA
>      <or nuConrPakFileWrite>
>        -------------------
>                |
>                |/

### [3] Notes Concerning Controller Pak Access

The Controller Pak can be removed during use. Some game programs do not recognize that this has happened, so it is a good idea to use the described procedure whenever accessing the Controller Pak. Step (1) to recognize the Controller Pak is particularly important with game applications that use both the Controller Pak and Rumble Pak.