osContStartReadData osContStartReadData (function)

osContStartReadData, osContGetReadData

Obtains data from controller


#include <ultra64.h>        /* os.h */
s32 osContStartReadData(OSMesgQueue *mq);
void osContGetReadData(OSContPad *pad);


The osContStartReadData function issues a read data command to obtain the current positon of 3D stick and button settings from the Controller. The osContGetReadData function returns these data to the location pointed to by the pad argument. You can obtain such information that the A Button of the Controller is pressed down or that how much 3D stick is tilted. These two functins must be paired to use.

The message queue pointed to by the mq argument must be an initialized message queue associated with the OS_EVENT_SI event. Please see the osSetEventMesg function in the N64 Online Function Reference Manual, for details on how to create this association.

The osContStartReadData function is called only to issue read command, and the message for completed data reading is returned to the message queue mq. Therefore, the osContGetReadData function should be called to obtain data after the osContStartReadData function is called, and osRecvMesg receives a message indicating data reading is completed. The osContStartReadData function takes around 2 milliseconds to complete its data reading and for osRecvMesg to receive a final message. Other processes such as re-drawing the screen can be performed while you are waiting.

You must supply a block of memory large enough for MAXCONTROLLERS structures of type OSContStatus. If the osContSetCh function (please see osContSetCh) sets the number of direct-type SI devices accessed at a value less than the MAXCONTROLLERS number, then the area secured can be smaller than the MAXCONTROLLERS number, provided more devices are not added later.

typedef struct {
    u16 button;     /* Controller button data */
    s8  stick_x;    /* Control stick's X coordinate position*/
    s8  stick_y;    /* Control stick's Y coordinate position*/
    u8  errno;      /* Error values returned from the Controller */
} OSContPad;

The Control Stick's coordinate positions stick_x and stick_y are signed characters with a range of -128 to 127. However, for the actual program we recommend using values within the ranges shown below:

button and the following static variables are ANDed to check which mouse button has been clicked. For instance, button is ANDed with START_BUTTON to check if the bit is ON in order to check if the start button has been clicked.

If an error occurs when reading data from the Controller, the following error numbers are returned to errno of OSContPad structure. If it is successful, 0 is returned.

The controller does not respond. The controller is not inserted.

The controller sends data at a higher data transfer rate than the hardware can handle. In this case, you should ignore the data.


void	mainproc(void)
  OSMesgQueue     intMesgQueue;
  OSMesg          intMesgBuf[1];
  OSContStatus    sdata[MAXCONTROLLERS];
  OSContPad       rdata[MAXCONTROLLERS];
  u8              pattern;
  int             i;
  int             cont_exist = 0;

  osCreateMesgQueue(&intMesgQueue, intMesgBuf, 1);
  osSetEventMesg(OS_EVENT_SI, &intMesgQueue, NULL);
  osContInit(&intMesgQueue, &pattern, &sdata[0]);

  /* Confirm if controller is inserted */
  for(i = 0; i < MAXCONTROLLERS; i++){
    if(((pattern >> i) & 1) && (sdata[i].errno == 0)){
     if((sdata[i].type & CONT_TYPE_MASK) == CONT_TYPE_NORMAL){
        osSyncPrintf("controller is inserted in port %d\n",i);
        cont_exist = 1;

  /* if controller is inserted */
    /* start reading controller data */
    /* Confirm the end of reading */
    osRecvMesg(&intMesgQueue, NULL, OS_MESG_BLOCK);
    /* get controller data */

See Also

osContInit, osContReset, osContStartQuery, osContSetCh, osSetEventMesg, and osRecvMesg

Revision History

1999/02/01 Completely revised
1999/04/30 Changed format