lbatobyte.c 1.37 KB

#include <ultra64.h>
#include "../org/include/leodefine.h"
#include "../org/include/leodrive.h"

#ifndef _LONGCMD
#include <leo.h>
#else
#include <leosp.h>
#endif

extern  s32     __leoActive;

/* export from leo_tbl.c */
extern u16 LEOVZONE_TBL[DISK_TYPES][VZONES_PER_DRV];
extern u16 LEOBYTE_TBL2[ZONES_PER_DRV];
extern u8  LEOVZONE_PZONEHD_TBL[DISK_TYPES][VZONES_PER_DRV];

extern u8  LEOdisk_type;

extern 	u16   	leoLba_to_vzone(u32 lba);

s32 LeoLBAToByte(s32 startlba, u32 nlbas, s32 *bytes)
{
  u32 resbytes;
  u32 byte_p_blk;
  u16 zone,vzone;
  u8  flag;
  
  /* 
   * Check for existence of Leo Manager 
   */
  if (!__leoActive) {
    return(-1);
  }
  
#ifdef _DEBUG
  if (startlba > MAX_L_LBA)
    return LEO_ERROR_LBA_OUT_OF_RANGE;

#endif

  resbytes = 0;
  flag = vzone = 1;
  
/*   nlbas += 24; */

  /*
   * Add system blocks
   */
  startlba += 24;
  
  while (nlbas)
  {
    if (flag || (startlba == LEOVZONE_TBL[LEOdisk_type][vzone]))
    {
      vzone      = leoLba_to_vzone(startlba);
      zone       = LEOVZONE_PZONEHD_TBL[LEOdisk_type][vzone];
      if (zone > (u8)7)
	zone -= (u8)7;
      byte_p_blk = LEOBYTE_TBL2[zone];
    }

    resbytes += byte_p_blk;
    nlbas--;
    startlba++;

    if ((nlbas) && (startlba > (u32)MAX_P_LBA))
      return LEO_ERROR_LBA_OUT_OF_RANGE;
	      
    flag = 0;
  }
  *bytes = resbytes;
  
  return LEO_ERROR_GOOD;

} /* LeoLBAToByte() */