gbpakgetstatus.c 1.76 KB
/*---------------------------------------------------------------------
        Copyright (C) 1997, Nintendo.
        
        File            gbpakgetstatus.c
        Coded    by     Koji Mitsunari. Oct  2, 1997.
        Modified by     Koji Mitsunari. Apr 16, 1998.
        Comments        Get status of 64GB-PAK 
   
        $Id: 
   ---------------------------------------------------------------------*/

/**************************************************************************
 *
 *  $Revision: 1.2 $
 *  $Date: 2003/03/25 20:42:32 $
 *  $Source: 
 *
 **************************************************************************/

#include "osint.h"
#include "controller.h"

s32
osGbpakGetStatus(OSPfs *pfs, u8 *status)
{
#ifdef BBPLAYER
    return PFS_ERR_DEVICE;
#else
  s32	ret, i;
  u32	temp[BLOCKSIZE/(sizeof(u32)/sizeof(u8))];

  /* Check if the bank may be changed */
  ret =  __osContRamRead(pfs->queue, pfs->channel, PFS_BANK_ADDR, (u8 *)temp);
  if (ret == PFS_ERR_NEW_PACK || ((u8 *)temp)[BLOCKSIZE-1] != OS_GBPAK_ID) {
    if ((ret = osGbpakInit(pfs->queue, pfs, pfs->channel)) != 0) {
      return(ret);
    }
  }

  /* Read status data */
  ret =  __osContRamRead(pfs->queue, pfs->channel, GB_POWER_ADDR, (u8 *)temp);
  if (ret == 0)  {
    if ((ret = __osPfsGetStatus(pfs->queue, pfs->channel)) != 0){
      return(ret);
    }
    *status = ((u8 *)temp)[0];
    for (i = 1 ; i < BLOCKSIZE ; i ++){
      *status |= ((u8 *)temp)[i];
    }
    *status &= (OS_GBPAK_GBCART_PULL|OS_GBPAK_RSTB_DETECTION);
    *status |= ((u8 *)temp)[BLOCKSIZE-1];

    if ((*status & 0x80) == 0) {
      ret = PFS_ERR_NO_GBCART;
    } else if ((*status & 0x40) != 0) {
      ret = PFS_ERR_NEW_GBCART;
    }
  } else if (ret == PFS_ERR_NEW_PACK) {
    ret = PFS_ERR_CONTRFAIL;
  } 

  return(ret);
#endif
}