osGbpakReadWrite (function)

Reads/writes to the memory of the Game Boy Game Pak using the N64 Transfer Pak

Syntax

#include <ultra64.h>     /* ultra64.h */
s32 osGbpakReadWrite(OSPfs *pfs, u16 flag, u16 address, u8 *buffer, u16
size);

Description

osGbpakReadWrite function reads/writes to Game Boy Game Pak. It can be used to access the Game Pak memory when a Game Boy Game Pak is inserted into the N64 Transfer Pak.

Before calling osGbpakReadWrite, N64 Transfer Pak must be initialized by osGbpakInit, use osGbpakReadId to read the Game Boy ROM registration area, turn the power on, and check both company code and game title. In addition, the connector must be checked by osGbpakCheckConnector.

The OSpfs structure pfs must be initialized by osGbpakInit. Specify in flag either OS_READ or OS_WRITE. When OS_READ is specified, data is read from the Game Boy Game Pak, while OS_WRITE specifies writing data to the Game Boy Game Pak. Specify in address the value of the Game Boy Game Pak's CPU address (0x0000 - 0xbfff). The number of bytes to read or write is specifed by size. address and size must be multiples of 32. buffer is a pointer to the buffer in RDRAM where the read or write is performed.

Note: Please refer to the Game Boy Programming Manual, Chapter 8 "Game Boy Memory Controllers" for information concerning ROM/RAM Bank switching.

Caution is required when dealing with the returned values. This function cannot determine whether the Game Boy Game Pak has been pulled out, or whether Game Boy Game Paks have been exchanged. That is to say, a "0" (normal termination) is returned even if the Game Boy Game Pak has been removed. Before and after this function is called, osGbpakGetStatus or osGbpakReadId should be called for a status check. It should also be confirmed that the Game Boy Game Pak has not been removed and reinserted.

Return value is an error code. If the function terminates normally, a value of 0 is returned. If an error occurs, one of the following error codes is returned:

PFS_ERR_NOPACK

Nothing is inserted in the specified Controller.

PFS_ERR_CONTRFAIL

Data transfers with the controller have failed. The Controller may not be connected correctly, or there may be some problem with the N64 Transfer Pak or the Controller connector.

PFS_ERR_INVALID

There are problems in the way the function was called or in the arguments specified. This error does not occur as long as the function usage is normal.

When the Game Boy Game Pak is not being accessed for reading or writing using osGbpakReadWrite, the Game Boy Game Pak power should be turned off using osGbpakPower.

See Also

osContInit, osGbpakInit, osGbpakGetStatus, osGbpakPower, osGbpakReadId, and osGbpakCheckConnector

Revision History

1999/04/13 Added PFS_ERR_INVALID error ID
1999/04/30 Changed format