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

/**************************************************************************
 *
 *  $Revision: 1.1.1.1 $
 *  $Date: 2002/05/02 03:28:44 $
 *  $Source: 
 *
 **************************************************************************/

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

s32
__osGbpakSetBank(OSPfs *pfs, u8 bank)
{
  int	i;
  s32	ret;
  u8	temp[BLOCKSIZE];

  if (bank >= GBPAK_MAX_BANK) return(PFS_ERR_INVALID);
  for ( i = 0 ; i < BLOCKSIZE ; temp[i++] = bank);
  ret =  __osContRamWrite(pfs->queue, pfs->channel, GB_GBBANK_ADDR, temp, 0);
  if (ret == PFS_ERR_NEW_PACK) {
    ret = osGbpakInit(pfs->queue, pfs, pfs->channel);
    if (ret == 0) {
      ret =  __osContRamWrite(pfs->queue, pfs->channel, GB_GBBANK_ADDR,
			      temp, 0);
      if (ret == PFS_ERR_NEW_PACK) {
	ret = PFS_ERR_CONTRFAIL;
      }
    }
  }
  if ( ret == 0 ) {
    pfs->banks = bank;	/* GB BANK */
  }
  return(ret);
}