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

   

uhWriteGame

Format
#include <ultrahost.h>
int uhWriteGame(int fd, void *addr, int nbytes);


Return Value
On success, uhWriteGame returns the number of bytes actually written. Otherwise, it returns -1 and sets errno to identify 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 uhWriteGame routine attempts to copy nbytes of data from the host beginning at addr to the game. In this case, the operation should be paired on the game side with a osReadHost procedure with the same byte count. Either the host or the game will block until the rendezvous is complete.

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
uhOpenGame
uhCloseGame
uhReadGame
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