7.1 Initialization Functions


Before disk-related routines are executed, the leo manager device driver must be started. The leo manager consists of two independent threads, a command thread and an interrupt thread. As is shown below, the function used to start the leo manager varies depending on whether disk or Game Pak ROM startup is used (For information on disk and Game Pak startup, please see Section 7.7, "Disk Startup and Game Pak Startup."

Initialization Functions

#include<PR/leo.h>

with disk startup

s32 LeoCreateLeoManager(OSPri cmdPri, OSPri intPri, OSMesg *cmdBuf, s32 cmdMsgCnt);

with cassette startup, for Japan

s32 LeoCJCreateLeoManager(OSPri cmdPri, OSPri intPri, OSMesg *cmdBuf, s32 cmdMsgCnt);

with Game Pak startup, for U.S.

s32 LeoCACreateLeoManager(OSPri cmdPri, OSPri intPri, OSMesg *cmdBuf, s32 cmdMsgCnt);

cmdPri M
command thread priority sequence

intPri
interrupt thread priority sequence

cmdBuf
reserved memory area

cmdMsgCnt
number of messages that command queue can store

(When there is no need to distinguish the above 3 functions, describe as Leo*CreateLeoManager()).

Leo*CreateLeoManager( )starts the command thread with the priority sequence cmdPri and the interrupt thread with the priority sequence intPri. cmdBuf and cmdMsgCnt specify the buffer and size, respectively, of the message queue called the command queue. The command queue is a message queue that the 64DD functions use to notify the leo manager of commands. If this queue becomes filled with messages, the subsequent command is not executed, and an error is returned. Sufficiently large numbers must therefore be specified. For cmdBuf, reserve a memory area of sizeof(OSMesg)x cmdMsgCnt, or 4 x cmdMsgCnt bytes.

When the manager is implemented, Leo*CreateLeoManager( ) checks whether a drive is connected. If it finds no drive, it returns a DEVICE_COMMUNICATION_FAILURE error. Otherwise it returns a normal end (LEO_ERROR_GOOD). The programmer must be sure to check the return value for an error. For more information on error handling methods, please see "Chapter 1, Error-Handling sequences."

Some consideration must be given to the handling of instances in which the reset button is pushed during Game Pak startup. Pushing the reset button executes the initialization function again and resets 64DD. When 64DD has been reset it enters a "reset state" in which a "POWERONRESET_DEVICERESET_OCCURRED" error occurs, regardless of which function is used. The function that clears this state is LeoResetClear( )(please see Section 7.5.2, "Clearing a Reset State.") If this function is run within approximately 200 ms of the start of the reset, it will fail to clear the reset state. After this, LeoResetClear( ) must actually be run to determine whether it successfully cleared the reset state. If the function is run and the error code POWERONRESET_DEVICERESET_OCCURRED is returned, the LeoResetClear( ) function must again be run for the next frame. For more information, please see "Chapter 10, Error-Handling Sequences."