1.4 Controller Pak Functions

In this section, we explain specific ways of using the Controller Pak. Many other functions have been prepared for the Controller Pak in addition to the ones explained here. For information about these see the Function Manual and the Sample Programs.


1.4.1 Setting the Company Code and the Game Code

Before accessing the Controller Pak, use the nuContPakCodeSet function to set the company code and the game code (initial code) in the Controller Manager.


Function name: nuContPakCodeSet
Syntax: void nuContPakCodeSet(u8* companyCode, u8* gameCode)
Arguments: companyCode Company code
  gameCode Game code (initial code)
Return value: None

These values are unique to the game, so unless you are accessing data created by other game software, you don't have to reset these values once they have been set.


1.4.2 Opening the Controller Pak Device

To gain access to the Controller Pak, first you must open the device.


Function name: nuContPakOpen
Syntax: s32 nuContPakOpen(NUContPakFile *file, u32 cont_no)
Arguments: file Controller Pak file structure
  cont_no The number of the Controller to open
Return value: Error

The pointer to the NUContPakFile structure is passed to the file argument. If a Controller Pak is inserted, a NUContPakFile type file structure is initialized so the Controller Pak can be accessed. This structure contains the pointer to the N64 OS OSPfs structure and various information managed by the Controller Pak Manager.

The return value of this function is the error value when a device is opened. At the same time, the error value is also stored in the NUContPakFile structure.


1.4.3 Opening a Game Note

If the Controller Pak can be identified, the next thing to do is to open the game note that you want to access.


Function name: nuContPakFileOpen
Syntax: s32 nuContPakFileOpen(NUContPakFile *file, u8* noteName,
       u8* extName, u32 mode, s32 size)
Arguments: file Controller Pak file structure
  noteName  Game note name (16 bytes in N64 font code)
  extName Note extension (1 byte in N64 font code)
  mode Specifies whether to create a new game note, or not if one exists.
NU_CONT_PAK_MODE_CREATE Creates a game note if none exists.
NU_CONT_PAK_MODE_NOCREATE Does not create a game note.
  size The size of the created game note when "mode" is NU_CONT_PAK_MODE_CREATE.
    This value is invalid when the mode is NU_CONT_PAK_MODE_NOCREATE.
Return value: None

When NU_CONT_PAK_MODE_CREATE is specified for mode, a game note of the specified size is created if the game note does not exist. However, as mentioned above, game notes are managed in units of 256 bytes, so the size of the area actually reserved is rounded up to a multiple of 256.

The N64 OS prescribes that the N64 font code be used for the note name and extension. However, in the NuSystem, codes are converted within functions, and functions are prepared that enable you to use ASCII code for the noteName and extName arguments. There are also functions that let you specify the opening of notes using JIS code.


Function name: nuContPakFileOpenJis
Syntax: s32 nuContPakFileOpenJis(NUContPakFile *file, u8* noteName,
        u8* extName, u32 mode, s32 size)
Arguments: file Controller Pak file structure
  noteName Note name (JIS)
    Terminal NULL (Converted to N64 font code 16 bytes)
  extName Extension (JIS)
    Terminal NULL (Converted to N64 font code 1 byte)
  mode,size The same as nuContPakFileOpen
Return value: None

Be careful when converting from JIS code to N64 font code, because the number of characters may change when you convert characters of voiced sounds (daku-ten(sonant) and handaku-ten(p sound)). The two functions nuContPakJisToN64 and nuContPakN64ToJis have been prepared for converting the code.

1.4.4 Reading/Writing with Game Notes

Once the game note can be opened without any problems, you can perform read/writes with the game note. The following functions have been prepared to read/write Controller Pak data:


Function name: nuContPakFileFread
Syntax: s32 nuContPakFileFread(NUContPakFile *file,
        s32 offset, s32 size, u8* buf)
Arguments: file Controller Pak structure
  offset Offset position
  size Size to read
  buf Buffer where read data is stored
Return value: Error

Function name: nuContPakFileFwrite
Syntax: ss32 nuContPakFileFwrite(NUContPakFile *file,
        s32 offset, s32 size, u8* buf)
Arguments: file Controller Pak structure
  offset Offset position to write
  size Size to write
  buf Buffer where data to be written is stored
Return value: Error

In the N64 OS functions for read/writes with the Controller Pak, the offset and size arguments must be specified as multiples of 32. However, there are no such restrictions in the NuSystem functions described above because the functions adjust internally to perform the reading process.

1.4.5 A Note of Caution about Controller Pak Access

There is always the chance that the Controller Pak will be removed/inserted during game play. Thus, please be sure to perform the complete procedure from nuContPakOpen to actual reading/writing every time you access the Controller Pak, even for software that prohibits the game player from removing/inserting the Controller Pak during game play.