##### Shinobi Library - Memory Card Function

# buSaveExecFile

Saves an executable file

### FORMAT

`

  Sint32 buSaveExecFile( drive, *fname, *buf, nblock, *time, flag )
  Sint32 drive
  const char *fname
  const void *buf
  Uint32 nblock
  BUS_TIME *time
  Sint32 flag

`

### PARAMETER

  `drive` | Extension socket number
  `*fname` | File name
  `*buf` | Read address
  `nblock` | Number of blocks to be read
  `*time` | Time stamp
  `flag` | flag
  `` | BUD_FLAG_VERIFY:Verify enabled
  `` | BUD_FLAG_COPY(n):Copy flag ("n" is the value of the copy flag)

### RETURN

  BUD_ERR_OK | Processing request was received |
  BUD_ERR_BUSY | Busy - request could not be accepted |

### DESCRIPTION

  Saves an executable file.

  The following values can be designated for the argument `drive` which specifies extension sockets.

  BUD_DRIVE_A1 | Extension socket 1 on board A
  BUD_DRIVE_A2 | Extension socket 2 on board A
  BUD_DRIVE_B1 | Extension socket 1 on board B
  BUD_DRIVE_B2 | Extension socket 2 on board B
  BUD_DRIVE_C1 | Extension socket 1 on board C
  BUD_DRIVE_C2 | Extension socket 2 on board C
  BUD_DRIVE_D1 | Extension socket 1 on board D
  BUD_DRIVE_D2 | Extension socket 2 on board D

  In a normal application, this function saves an entire file. If an executable file exists or if a file with the same name already exists, an error results.

### EXAMPLE

        Sint32 ret;
        Sint32 blocks, flag;
        BUS_TIME time;
        SYS_RTC_DATE rtc;
        extern char SaveData[];  /* Data to be saved(512*10 bytes) */
        blocks = 10; /* File size is 10 blocks */
        flag = BUD_FLAG_VERIFY | BUD_FLAG_COPY(0xff); /* Verify enabled | Set copy flag to FFH */
        syRtcGetDate( &rtc );
        time = ( BUS_TIME )rtc;  /* Time stamp setting */
        ret = buSaveExecFile(BUD_DRIVE_A1, "SAVEDATA", SaveData, blocks, &time, flag);
        if (ret != BUD_ERR_OK) return NG;
        while (buStat(BUD_DRIVE_A1) == BUD_STAT_BUSY) {
        }
        if (buGetLastError(BUD_DRIVE_A1) != BUD_ERR_OK) return NG;
        return OK;

### NOTE

  Even if a verify error occurs, the file is still saved. The following are the completion statuses for this function that are obtained by `buStat():`

  BUD_ERR_OK | Normal end
  BUD_ERR_UNFORMAT | Disk is not formatted
  BUD_ERR_NO_DISK | Memory card is not found
  BUD_ERR_DISK_FULL | Executable file already exists
  BUD_ERR_FILE_EXIST | File with the same name already exists

  A save requires (number of blocks being saved x 5 Int). (This time requirement may vary, depending on the status of other drives, etc.) In addition, the address that is specified for "buf" must be on a four-byte boundary.

buSaveExecFile

COPYRIGHT © SEGA ENTERPRISES, LTD., 1998,1999