83Plus:Software:usb8x/Asm Interface/MSD
The mass storage driver works through a series of U_CALL entry points, much like the HID driver.
It requires two RAM buffers, one for internal use and one for a sector buffer. File handles used for opened files (explained later) also require around 27 bytes. The size of all three of these buffers can be obtained through the MSDVersion U_CALL. The size of the internal buffer is typically 254 bytes and the sector buffer is 512 bytes.
The entry point which requires these buffers is the MSD_Initialize U_CALL. Its memory can be dynamically allocated to appBackUpScreen (taking up practically all of it) with the code below:
U_CALL MSDVersion ld de,appBackUpScreen push de add hl,de ex de,hl pop hl U_CALL MSD_Initialize
For file system operations, you will then make calls to UFI_Initialize and FAT_Initialize. All entry points will return with the carry flag set if there are problems, with more detailed information available via [[../GetErrorCode|GetErrorCode]].
No knowledge of the intimate details of FAT16 are required. However, the "starting cluster" of a directory is used in several routines. This is a 16-bit number uniquely indentifying a directory. It is beneficial to use this number rather than an extremely long ASCIIZ directory path which wastes memory. It is easily obtained with FAT_getStartingCluster by passing an ASCIIZ directory path to it.
Entry Points
If all three of the initializing U_CALLs succeed, the other following entry points can then be called.
MSDVersion | Gets mass storage driver version and memory requirements |
MSD_Initialize | Initializes mass storage driver |
UFI_Initialize | Initializes connected mass storage device for sector read/write operations |
UFI_Read | Reads sector at (MSDLBA) address into sector buffer |
UFI_Write | Writes memory in sector buffer to (MSDLBA) address |
FAT_Initialize | Initializes connected mass storage device for FAT16 file system operations |
DOS_openFile | Opens a file and populates file handle with important information |
DOS_fileSeek | Sets seek pointer for file handle to specified offset |
DOS_fileRead | Read bytes from a file |
DOS_fileWrite | Write bytes to a file and grows it if necessary |
DOS_updateAttributes | Update "last modified" date/time and other attributes |
DOS_createFile | Create new file in specified directory with size 0 |
DOS_createDirectory | Create new subdirectory in specified directory |
DOS_renameFileEntry | Rename specified file or folder |
DOS_deleteFileEntry | Delete file or folder (including contents) |
DOS_countFilesInDir | Get number of files/folders in specified directory |
DOS_getNextFile | Get first/next file in specified directory |
DOS_getFileSize | Get size of file |
DOS_getDirEntry | Get directory entry for specified file/folder |
FAT_nameConvertTo11 | Convert name to 11-character format (ex. "README TXT ")
|
FAT_nameConvertFrom11 | Convert name to ASCIIZ format (ex. "readme.txt") |
FAT_lookupPath | Find whether specified file/directory exists |
FAT_findFileInCluster | Get directory entry for a file in specified folder |
FAT_getStartingCluster | Get starting cluster of specified directory |
MSD_ImportVariable | Imports 8x* file in specified directory as calculator variable in RAM/Flash |
MSD_ExportVariable | Exports calculator variable in RAM/Flash as 8x* file in specified directory |