All Hdd Function Documentation

TAP_Hdd_Fopen

Topfield Documentation

TYPE_File* TAP_Hdd_Fopen(char *name);

It opens the file whose name is the string pointed to by name

  • name : file name
return value : pointer to the object controlling the file. In case of error, it returns 0.

Additional Documentation


TAP_Hdd_Fread

Topfield Documentation

dword TAP_Hdd_Fread(void *buf, dword blksize, dword blk, TYPE_File *fp);

It reads blk elements of blksize bytes each from the file specified by fp into the buffer specified by buf.

  • buf : pointer of the buffer for reading.
  • blksize : the data size per block.
  • blk : the number of block to be read.
  • fp : pointer to the object controlling the file.
Total reading bytes = blksize * blk

Additional Documentation

The return value is the number of read blocks.


TAP_Hdd_Fwrite

Topfield Documentation

dword TAP_Hdd_Fwrite(void *buf, dword blksize, dword blk, TYPE_File *fp);

It writes blk elements of blksize bytes each to the file specified by fp.

  • buf : pointer of the buffer for writing.
  • blksize : the data size per block.
  • blk : the number of block to be written.
  • fp : pointer to the object controlling the file.
Total writing bytes = blksize * blk

Additional Documentation


TAP_Hdd_Fclose

Topfield Documentation

void TAP_Hdd_Fclose(TYPE_File *fp);

It closes the file fp.

Additional Documentation


TAP_Hdd_FindFirst

Topfield Documentation

dword TAP_Hdd_FindFirst(TYPE_File *file);

It starts to scan the file in the current directory.

  • file : the pointer of TYPE_File which the file information is saved to.
return value : total files in the current directory

Additional Documentation


TAP_Hdd_FindNext

Topfield Documentation

dword TAP_Hdd_FindNext(TYPE_File *file);

It continues to scan the file in the current directory.

  • file : the pointer of TYPE_File which the file information is saved to.
return value : If 0, there is no file. If 1, there is a file.

Additional Documentation

There is a bug with this function. When it is done with all entries, it still returns non-zero for one non-existing entry. Rely on the count returned from TAP_Hdd_FindFirst instead.


TAP_Hdd_Fseek

Topfield Documentation

dword TAP_Hdd_Fseek( TYPE_File *fp, long pos, long where )

It changes the read/write position of the file specified by fp. This position defines the character that will be read or written on the next I/O operation on the file.

  • pos : offset from the file location given by 'where'
  • where : file location. The value are as follows.
    • SEEK_SET : File beginning
    • SEEK_CUR : Current file pointer position
    • SEEK_END : End of file

Additional Documentation

SEEK_END works incorrectly in the same manner as TAP_Hdd_Flen with files

if ( where != SEEK_END || (file && (file->size == 0 || (file->size % 512))) )
	return TAP_Hdd_Fseek( file, pos, where );
return TAP_Hdd_Fseek( file, pos+512, SEEK_END );

libutils? contains a fixit module. Simply include tapapifix.h and calls TAP_Hdd_Fseek will be replaced with a version that includes the above code.

In order to use SEEK_SET, SEEK_CUR and SEEK_END constants you need to include stdio.h -file.


TAP_Hdd_Flen

Topfield Documentation

dword TAP_Hdd_Flen(TYPE_File *fp);

It returns the number of bytes in the opened file specified by fp.

Additional Documentation

There seems to be a bug with various HDD file handling code, particularly the TAP_Hdd_Flen() where it will report the length incorrectly if the length is a multiple of 512bytes. This one stung me ages ago (when wondering why some code I wrote wasn't always processing the last bit of particular file).

The work around is simple-

example:

TYPE_File* fp;
int filelength;
if (( fp = TAP_Hdd_Fopen( LOG_FILE) ))
{
   filelength=TAP_Hdd_Flen( fp );
   if (filelength!=0 && (filelength%512)==0) filelength+=512;  //TOPFIELD BUG WORKAROUND.
snip etc
}

libutils? contains a fixit module. Simply include tapapifix.h and calls to TAP_Hdd_Flen will be replaced with a version that includes the above code.

MikB: As an additional problem, it seems that TAP_Hdd_Flen() is not universally broken. It does in fact return the correct length (even with 512 byte multiples), on the condition that the file was written by the Toppy to its own disk (e.g. created by a TAP). I have been successfully writing files that are forced to be 512 byte multiples, and reading them back correctly without ever being aware of this bug. It only seems to affect files that were imported from the PC, e.g. by Altair. It is these files that are reported short by 512 bytes, if they are a non-zero multiple of 512 bytes.


TAP_Hdd_Ftell

Topfield Documentation

dword TAP_Hdd_Ftell(TYPE_File *fp);

It returns the current read/write position of the file specified by fp. This position defines the character that will be read or written by the next I/O operation on the file.

Additional Documentation


TAP_Hdd_TotalSize

Topfield Documentation

dword TAP_Hdd_TotalSize();

It gets the total capacity of HDD.

Additional Documentation


TAP_Hdd_FreeSize

Topfield Documentation

dword TAP_Hdd_FreeSize();

It gets the usable capacity of HDD.

Additional Documentation


TAP_Hdd_Delete

Topfield Documentation

word TAP_Hdd_Delete(char *name);

It deletes the file or folder whose name is the string pointed to by name.

Additional Documentation

BUG. If the file name contains a period character (".") followed by 36 or more characters (including the extension) the call will cause a crash. Use TAP_Hdd_Rename() first and delete the renamed file.


TAP_Hdd_Exist

Topfield Documentation

bool TAP_Hdd_Exist( char *filename )

It checks the existence of the specified file.

Additional Documentation

This function only acts on files in the current directory. Name must be the filename only and must not contain any path, absolute or relative.


TAP_Hdd_Create

Topfield Documentation

dword TAP_Hdd_Create(char *name, byte attr);

It creates a file or a folder

  • name : file name
  • attr :
    • ATTR_NORMAL : data file
    • ATTR_PROGRAM : program file
    • ATTR_FOLDER : folder

Additional Documentation

  • file name must not contain path (slash or backslash)
  • Returns 0 for success

TAP_Hdd_ChangeDir

Topfield Documentation

word TAP_Hdd_ChangeDir( char *dir )

It changes the current directory into the specified directory. The path must be relative to the current directory.

  • dir : directory name. In case of '..', it is the parent directory. For '/', it is ROOT directory.

Additional Documentation

In firmware before 5.12.00 the return values are

  • 0 = success
  • non zero = failure
In firmares 5.12.00 onwards
  • 0 = failure
  • non zere = success
Using '/' at the beginning to specify the root directory does not work. Using just "/" as a directory seems to be working but if you do that in a tap that's being started from AutoStart -folder it will break all taps being loaded after it.

TAP_Hdd_ChangeDir is not Transactional - if the call fails there is no guarentee that the current directory is the same as it was before you made the call - in fact you will end up with the current directory being the closest valid parent directory of the directory you asked for.

To get to the root directory you can use following code:

TYPE_File f;

while (TAP_Hdd_FindFirst(&f) && !strcmp(f.name, ".")) TAP_Hdd_ChangeDir("..");


TAP_Hdd_PlayTs

Topfield Documentation

int TAP_Hdd_PlayTs(char *name);

It plays the recorded files. The active folder should be set to the folder that contains the recorded files to be played back. (To move the active folder, use TAP_Hdd_ChangeDir() function.)

  • name : filename of recorded service file.
return value : 0 : Success, other value : ERROR

Additional Documentation


TAP_Hdd_StopTs

Topfield Documentation

int TAP_Hdd_StopTs();

It stops the playback. return value : 0 : Success, other value : ERROR

Additional Documentation

Note that if this is called too soon after calling TAP_Hdd_PlayTs(), this can cause a crash. Leave a few seconds between these calls if you need to do this.

TAP_Hdd_StopTs() may crash the Toppy at any time. This is due to a bug in the firmware, which fails to output the "Playback stopped" window. Workaround: leave normal mode via TAP_ExitNormal() prior to calling TAP_Hdd_StopTs().


TAP_Hdd_PlayMp3

Topfield Documentation

int TAP_Hdd_PlayMp3(char *name);

It plays the MP3 files. The active folder should be set to the folder, which contains the MP3 files to be played. (To move the active folder, use TAP_Hdd_ChangeDir() function.)

  • name : filename of MP3 file.
return value : 0 : Success, other value : ERROR

Additional Documentation


TAP_Hdd_StopMp3

Topfield Documentation

int TAP_Hdd_StopMp3();

It stops the MP3 files. return value : 0 : Success, other value : ERROR

Additional Documentation


TAP_Hdd_Rename

Topfield Documentation

bool TAP_Hdd_Rename( char *oldName, char *newName )

It changes the file name. return value : TRUE = Success, FALSE = False

Additional Documentation

This function only acts on files in the current directory. Name must be the filename only and must not contain any path, absolute or relative.

On firmware 5.12.25, this function returns the opposite:

  • 0 = success
  • 1 = failure
Tested on directories and .tap files

TAP_Hdd_StartRecord

Topfield Documentation

bool TAP_Hdd_StartRecord();

It records the current watching service. (Instant recording) return value : TRUE = Success, FALSE = Failure

Additional Documentation


TAP_Hdd_StopRecord

Topfield Documentation

bool TAP_Hdd_StopRecord(byte recSlot);

It stops the recording.

  • recSlot : the recording slot number to be stopped
return value : TRUE = Success, FALSE = Failure

Additional Documentation


TAP_Hdd_GetRecInfo

Topfield Documentation

bool TAP_Hdd_GetRecInfo(byte recSlot, TYPE_RecInfo *recInfo);

It gets the recording information.

  • recSlot : the recording slot number
  • recInfo : pointer of TYPE_RecInfo where the recording information is saved.
For the more information about TYPE_RecInfo, please refer the TAP.H.

return value : TRUE = Success, FALSE = Failure

Additional Documentation

TAP_Hdd_GetRecInfo has a buffer overrun under certain circumstances related to the file being recorded. The maximum overrun seen so far is less than 128 bytes.

libutils? contains a fixit module. Simply include tapapifix.h and calls TAP_Hdd_GetRecInfo will be replaced with a version that pads recInfo with 128 bytes.


TAP_Hdd_GetPlayInfo

Topfield Documentation

bool TAP_Hdd_GetPlayInfo(TYPE_PlayInfo *playInfo)

It gets the playback information.

  • playInfo : pointer to TYPE_PlayInfo where the playback information is saved.
  • return value : TRUE = Success, FALSE = Failure

Additional Documentation

TAP_Hdd_GetPlayInfo has a buffer overrun under certain circumstances related to the file being played back. The maximum overrun seen so far is less than 128 bytes.

libutils? contains a fixit module. Simply include tapapifix.h and calls TAP_Hdd_GetPlayInfo will be replaced with a version that pads playInfo with 128 bytes.


TAP_Hdd_GetHddID

Topfield Documentation

bool TAP_Hdd_GetHddID(char *modelNo, char *serialNo);

It gets the model number and serial number of HDD. Return value : TRUE=success, FALSE=fail

Remarks : The modelNo should be allocated to the size of 40 bytes and serialNo should be 20 bytes.

Additional Documentation


TAP_Hdd_ChangePlaybackPos

Topfield Documentation

bool TAP_Hdd_ChangePlaybackPos(dword blockPos);

It changes the playback position for the specified point. The total block can be gotten from TAP_Hdd_GetPlayInfo().

  • blockPos : The new position
Return value : TRUE - Success, FALSE - Fail

Additional Documentation


TAP_Hdd_GotoBookmark

Topfield Documentation

bool TAP_Hdd_GotoBookmark();

It changes the playback position for the bookmark position which is the nearest one to the right direction. Return value : TRUE - Success, FALSE - Fail

Additional Documentation


TAP_Hdd_SetBookmark

Topfield Documentation

bool TAP_Hdd_SetBookmark();

It sets the bookmark at the current playback position. Return value : TRUE - Success, FALSE - Fail

Additional Documentation