N64® Functions Menu

al - Audio Library Functions
gDP - DP GBI Macros
gdSP - General GBI Macros
gSP - SP GBI Macros
gt - Turbo Microcode RDP
gu - Graphics Utilities
Math - Math Functions
nuSys - NuSystem
os - N64 Operating System
sp - Sprite Library Functions
uh - Host to Target IO
64DD - N64 Disk Drive

Nintendo® Confidential

   

uhOpenGame

Format
#include <ultrahost.h>
int uhOpenGame(const char *device);


Return Value
On success, uhOpenGame returns a valid file descriptor. Otherwise, it returns -1 and sets errno to indicate the error.

What This Function Does
The host-to-target IO routines allow a host application to set up a communications channel for the transfer of raw data between the host and the game. They work in concert with OS routines (osReadHost, osWriteHost, osTestHost, osAckRamromRead, and osAckRamromWrite) on the game side.

These routines are part of the Ultra 64 host-side library libultrahost.a, so they are available to the application by adding -lultrahost on the link line.

The uhOpenGame routine opens the given device special file and configures it to listen for game I/O events. Which device should be opened depends on which read and write calls are needed. For uhReadGame and uhWriteGame, uhOpenGame should open the device /dev/u64_data. For uhReadRamrom and uhWriteRamrom, uhOpenGame should open /dev/u64. Note that this is a change from previous releases that specified /dev/u64 for all calls. The file descriptor returned by uhOpenGame is passed to uhReadGame, uhWriteGame, uhReadRamrom, uhWriteRamrom, and uhCloseGame, presuming the open succeeds.

Example
The following example shows how a host application can initiate the game and establish a connection to transfer data. This particular sequence guarantees that no handshaking events are lost. By the time the game sends its first packet of data, the host device driver is ready to acknowledge it. Furthermore, the host side application does not attempt to send data to the game before it has booted.
/* Host side code */
main(int argc, char **argv)
{
pid_t pid;
int  fd, status;

if ((fd = uhOpenGame("/dev/u64_data")) == -1) {
    perror("uhOpenGame");
    return(-1);
}
if ((pid = fork()) == -1) {
    perror("fork);
    return(-1);
} else if (pid == 0) {
    (void)execl("/usr/sbin/gload",
    "/usr/sbin/gload", 0);
    fprintf(stderr, "host: execl(
    return(-1);
}

if (uhReadGame(fd, hostBuffer, 4) == -1) {
    fprintf(stderr, "uhReadGame %s0,
    sys_errlist[errno]);
    return(1);
}

if (uhCloseGame(fd) != 0) {
    perror("uhCloseGame");
    return(-1);
}
if (waitpid(pid, status, WUNTRACED) == -1) {
    perror("waitpid");
    return(-1);
}
}


/* Game side code */
mainproc(void *arg)
{
osWriteHost(gameBuffer, 4);

osExit();
}
See Also
uhCloseGame
uhReadGame
uhWriteGame
uhReadRamrom
uhWriteRamrom
osReadHost
osWriteHost
osTestHost
osAckRamromRead
osAckRamromWrite



Nintendo® Confidential

Warning: all information in this document is confidential and covered by a non-disclosure agreement. You are responsible for keeping this information confidential and protected. Nintendo will vigorously enforce this responsibility.

Copyright © 1998
Nintendo of America Inc. All rights reserved
Nintendo and N64 are registered trademarks of Nintendo
Last updated January 1998