Subversion Repositories NedoOS

Rev

Rev 119 | Rev 533 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download

  1. ; Эдесь лежат макросы FatFs.
  2. ; Все аргументы передаются через стек, в порядке их перечисления.
  3. ; Длинна аргумента кратна двум, то есть, если аргумент типа BYTE,
  4. ; то он занимает на стеке два байта.
  5. ; Если аргумент типа DWORD, то на стек сначала кладем старшие два байта, затем младшие.
  6. ; После выполнения функции все аргументы остаются на стеке,
  7. ; не забывайте снимать ненужные (за исключением f_voltopart).
  8. ;
  9. ; При попадании в функцию на стеке должен быть адрес возврата, затем список переменных.
  10. ;
  11. ; Строковая переменная должна заканчиватся 0x0 (нулём).
  12. ; Можно использовать как абсолютный, так и относительный путь:
  13. ;       "file.txt"              A file in the current directory of the current drive
  14. ;       "/file.txt"             A file in the root directory of the current drive
  15. ;       ""                              The current directory of the current drive
  16. ;       "/"                             The root directory of the current drive
  17. ;       "2:"                    The current directory of the drive 2
  18. ;       "2:/"                   The root directory of the drive 2
  19. ;       "2:file.txt"    A file in the current directory of the drive 2
  20. ;       "../file.txt"   A file in the parent directory
  21. ;       "."                             This directory
  22. ;       ".."                    Parent directory of the current directory
  23. ;       "dir1/.."               The current directory
  24. ;       "/.."                   The root directory (sticks the top level)
  25.  
  26. ; Возвращаемый параметр лежит в HL, если DWORD то DEHL.
  27. ;
  28. ; Левые порты должны быть скрыты (MEM_HIDE)
  29. ; Стек должен быть в текущем адресном пространстве (юзается очень сильно байт 100-200
  30. ; свободно может заюзать). И переменные(если на них есть указатель в
  31. ; аргументах, а также глобальные переменные типа FATFS), тоже должны быть доступны.
  32.         include "ffsfunc.asm"
  33.         STRUCT  FFS_DRV
  34. init                    defw
  35. status                  defw
  36. rd_to_usp               defw
  37. rd_to_buf               defw
  38. wr_fr_usp               defw
  39. wr_fr_buf               defw
  40. RTC                             defw
  41. strcpy_lib2usp  defw
  42. strcpy_usp2lib  defw
  43. memcpy_lib2usp  defw
  44. memcpy_usp2lib  defw
  45. memcpy_buf2usp  defw
  46. memcpy_usp2buf  defw
  47.  
  48. dio_drv                 defb
  49. dma_addr                defw
  50. lba_ptr                 defw
  51. count                   defb
  52.  
  53. curr_fatfs              defw
  54. curr_dir0               defw
  55. curr_dir2               defw
  56.         ENDS
  57. ;(((OUT&03fff)==037f7)&&(VAL==0))
  58. ;------------------------СТРУКТУРЫ FATFS --------------------------------------
  59.  
  60. FA_READ=0x01                    ;Specifies read access to the object. Data can be read from the file.
  61.                                         ;Combine with FA_WRITE for read-write access.
  62. FA_WRITE=0x02                   ;Specifies write access to the object. Data can be written to the file.
  63.                                         ;Combine with FA_READ for read-write access.
  64. FA_OPEN_EXISTING=0x00   ;Opens the file. The function fails if the file is not existing. (Default)
  65. FA_OPEN_ALWAYS=0x10     ;Opens the file if it is existing. If not, a new file is created.
  66.                                         ;To append data to the file, use f_lseek function after file open in this method.
  67. FA_CREATE_NEW=0x04              ;Creates a new file. The function fails with FR_EXIST if the file is existing.
  68. FA_CREATE_ALWAYS=0x08   ;Creates a new file. If the file is existing, it is truncated and overwritten.
  69.  
  70.  
  71.  
  72. /* File system object structure (FATFS) */
  73.  
  74.         STRUCT FATFS
  75. fs_type         BYTE;           /* FAT sub-type (0:Not mounted) */
  76. drv             BYTE 0;         /* Physical drive number */
  77. part            BYTE 0;         /* Partition # (0-4) 0-auto*/
  78. csize           BYTE;           /* Sectors per cluster (1,2,4...128) */
  79. n_fats          BYTE;           /* Number of FAT copies (1,2) */
  80. wflag           BYTE;           /* win[] dirty flag (1:must be written back) */
  81. fsi_flag        BYTE;           /* fsinfo dirty flag (1:must be written back) */
  82. id              WORD;           /* File system mount ID */
  83. n_rootdir       WORD;           /* Number of root directory entries (FAT12/16) */
  84. last_clust      DWORD;          /* Last allocated cluster */
  85. free_clust      DWORD;          /* Number of free clusters */
  86. fsi_sector      DWORD;          /* fsinfo sector (FAT32) */
  87. cdir            DWORD;          /* Current directory start cluster (0:root) */ ;TODO use
  88. n_fatent        DWORD;          /* Number of FAT entries (= number of clusters + 2) */
  89. fsize           DWORD;          /* Sectors per FAT */
  90. fatbase         DWORD;          /* FAT start sector */
  91. dirbase         DWORD;          /* Root directory start sector (FAT32:Cluster#) */
  92. database        DWORD;          /* Data start sector */
  93. winsect         DWORD;          /* Current sector appearing in the win[] */
  94. win             BLOCK 512;      /* Disk access window for Directory, FAT (and Data on tiny cfg) */
  95.         ENDS
  96. FATFS_sz=51+512
  97.  
  98. ;/* Directory object structure (DIR) */
  99.         STRUCT DIR
  100. FS              WORD    ;/* POINTER TO THE OWNER FILE SYSTEM OBJECT */
  101. ID              WORD    ;/* OWNER FILE SYSTEM MOUNT ID */
  102. INDEX           WORD    ;/* CURRENT READ/WRITE INDEX NUMBER */
  103. SCLUST          DWORD   ;/* TABLE START CLUSTER (0:ROOT DIR) */ ;видимо, в том же формате, что FATFS.cdir
  104. CLUST           DWORD   ;/* CURRENT CLUSTER */
  105. SECT            DWORD   ;/* CURRENT SECTOR */
  106. DIR             WORD    ;/* POINTER TO THE CURRENT SFN ENTRY IN THE WIN[] */
  107. FN              WORD    ;/* POINTER TO THE SFN (IN/OUT) {FILE[8],EXT[3],STATUS[1]} */
  108.         ENDS
  109. DIR_sz=22
  110.  
  111. /* FILE STATUS STRUCTURE (FILINFO) */
  112.         STRUCT FILINFO
  113. FSIZE           DWORD           ;/* FILE SIZE */
  114. FDATE           WORD            ;/* LAST MODIFIED DATE */
  115. FTIME           WORD            ;/* LAST MODIFIED TIME */
  116. FATTRIB         BYTE            ;/* ATTRIBUTE */
  117. FNAME           BLOCK 13,0      ;/* SHORT FILE NAME (8.3 FORMAT) */
  118. ;MARK           byte            ;marking
  119. ;NEXT           WORD
  120. ;NEXTP          BYTE
  121. ;PREV           WORD
  122. ;PREVP          BYTE
  123. ;RESERV         dw
  124.         ENDS
  125.  
  126. /* File object structure (FIL) */
  127.  
  128.         struct FIL
  129. FS              WORD    ;/* Pointer to the owner file system object */
  130. ID              WORD    ;/* Owner file system mount ID */
  131. FLAG            BYTE    ;/* File status flags */
  132. PAD1            BYTE    ;;TODO добавить тут id приложения-хозяина, чтобы можно было автоматически удалить
  133. FPTR            DWORD   ;/* File read/write pointer (0 on file open) */
  134. FSIZE           DWORD   ;/* File size */
  135. FCLUST          DWORD   ;/* File start cluster (0 when fsize==0) */
  136. CLUST           DWORD   ;/* Current cluster */
  137. DSECT           DWORD   ;/* Current data sector */
  138. DIR_SECT        DWORD   ;/* Sector containing the directory entry */
  139. DIR_PTR         WORD    ;/* Ponter to the directory entry in the window */
  140. BUF             BLOCK 512       ;/* File data read/write buffer */
  141.         ENDS
  142. FIL_sz=32+512
  143.  
  144.  
  145. ;---------------------------------МАКРОСЫ--------------------------------------
  146.  
  147. ;/*-----------------------------------------------------------------------*/
  148. ;/* Mount/Unmount a Logical Drive                                         */
  149. ;/*-----------------------------------------------------------------------*/
  150. ;
  151. ;FRESULT f_mount (
  152. ;       BYTE vol,               /* Logical drive number to be mounted/unmounted */
  153. ;       FATFS *fs               /* Pointer to new file system object (NULL for unmount)*/
  154. ;)
  155.         MACRO F_MOUNT _VOL,_FS  ;vol - уже лежит на стеке.
  156.         ld e,_VOL
  157.         LD bc,_FS
  158.         F_MNT
  159.         ENDM
  160.         MACRO F_MNT
  161.                 call ffsfunc.f_mount
  162.         ENDM
  163.  
  164.  
  165. ; FRESULT f_open (
  166.         ; FIL *fp,                      /* Pointer to the blank file object */
  167.         ; TCHAR *path,  /* Pointer to the file name */
  168.         ; BYTE mode                     /* Access mode and file open mode flags */
  169. ; )
  170.         MACRO F_OP
  171.         PUSH HL
  172.         LD hl,ffsfunc.f_open
  173.         call call_ffs
  174.         POP BC
  175.         ENDM
  176.        
  177.     MACRO F_OPEN_CURDRV
  178.         PUSH HL
  179.         LD hl,ffsfunc.f_open
  180.         call call_ffs_curvol
  181.         POP BC
  182.         ENDM
  183.  
  184.  
  185. ;seek
  186. ;FRESULT f_lseek (
  187. ;       FIL *fp,                /* Pointer to the file object */
  188. ;       DWORD ofs               /* File pointer from top of file */
  189. ;)
  190. ;fp = de
  191. ;ofs in stack
  192.         MACRO F_LSEEK_CURDRV
  193.         ld hl,ffsfunc.f_lseek
  194.         call call_ffs_curvol
  195.         ENDM
  196.  
  197.        
  198. ;/*-----------------------------------------------------------------------*/
  199. ;/* Read File                                                             */
  200. ;/*-----------------------------------------------------------------------*/
  201. ;FRESULT f_read
  202. ;       FIL *fp,                /* Pointer to the file object */
  203. ;       void *buff,             /* Pointer to data buffer */
  204. ;       UINT btr,               /* Number of bytes to read */
  205. ;       UINT *br                /* Pointer to number of bytes read */
  206.         MACRO F_READ_CURDRV
  207.         ld hl,ffsfunc.f_read
  208.         call call_ffs_curvol
  209.         ENDM
  210.        
  211.        
  212. ;/*-----------------------------------------------------------------------*/
  213. ;/* Write File                                                            */
  214. ;/*-----------------------------------------------------------------------*/
  215. ;FRESULT f_write
  216. ;       FIL *fp,                        /* Pointer to the file object */
  217. ;       const void *buff,       /* Pointer to the data to be written */
  218. ;       UINT btw,                       /* Number of bytes to write */
  219. ;       UINT *bw                        /* Pointer to number of bytes written */
  220.         MACRO F_WRITE_CURDRV
  221.         ld hl,ffsfunc.f_write
  222.         call call_ffs_curvol
  223.         ENDM
  224.  
  225. ; /*-----------------------------------------------------------------------*/
  226. ; /* Close File                                                            */
  227. ; /*-----------------------------------------------------------------------*/
  228. ; FRESULT f_close (
  229.         ; FIL *fp               /* Pointer to the file object to be closed */)
  230.     MACRO F_CLOS_CURDRV
  231.         ld hl,ffsfunc.f_close
  232.         call call_ffs_curvol
  233.         ENDM
  234.  
  235.  
  236.  
  237. ; /*-----------------------------------------------------------------------*/
  238. ; /* Create a Directory Object                                             */
  239. ; /*-----------------------------------------------------------------------*/
  240. ; FRESULT f_opendir
  241.         ; DIR *dj,                      /* Pointer to directory object to create */
  242.         ; TCHAR *path   /* Pointer to the directory path */
  243.  
  244.         MACRO F_OPDIR_CURDRV
  245.         ld hl,ffsfunc.f_opendir
  246.         call call_ffs_curvol
  247.         ENDM
  248.  
  249. ; /*-----------------------------------------------------------------------*/
  250. ; /* Read Directory Entry in Sequence                                      */
  251. ; /*-----------------------------------------------------------------------*/
  252.  
  253. ; FRESULT f_readdir (
  254.         ; DIR *dj,                      /* Pointer to the open directory object */
  255.         ; FILINFO *fno          /* Pointer to file information to return */
  256. ; )
  257.         MACRO F_RDIR_CURDRV
  258.         ld hl,ffsfunc.f_readdir
  259.         call call_ffs_curvol
  260.         ENDM
  261.  
  262.  
  263. ;/*-----------------------------------------------------------------------*/
  264. ;/* Delete a File or Directory                                            */
  265. ;/*-----------------------------------------------------------------------*/
  266. ;FRESULT f_unlink
  267. ;       const TCHAR *path               /* Pointer to the file or directory path */
  268.         MACRO F_UNLINK_CURDRV
  269.         ld hl,ffsfunc.f_unlink
  270.         call call_ffs_curvol
  271.         ENDM
  272.         MACRO F_UNLINK
  273.         ld hl,ffsfunc.f_unlink
  274.         call call_ffs
  275.         ENDM
  276. ;/*-----------------------------------------------------------------------*/
  277. ;/* Create a Directory                                                    */
  278. ;/*-----------------------------------------------------------------------*/
  279. ;FRESULT f_mkdir
  280. ;       const TCHAR *path               /* Pointer to the directory path */
  281.         MACRO F_MKDIR
  282.         ld hl,ffsfunc.f_mkdir
  283.         call call_ffs
  284.         ENDM
  285. ;/*-----------------------------------------------------------------------*/
  286. ;/* Rename File/Directory                                                 */
  287. ;/*-----------------------------------------------------------------------*/
  288. ;FRESULT f_rename
  289. ;       const TCHAR *path_old,  /* Pointer to the old name */
  290. ;       const TCHAR *path_new   /* Pointer to the new name */
  291.  
  292.         MACRO F_RENAME
  293.         ld hl,ffsfunc.f_rename
  294.         call call_ffs
  295.         ENDM
  296.  
  297. ;/*-----------------------------------------------------------------------*/
  298. ;/* Current Drive/Directory Handlings                                     */
  299. ;/*-----------------------------------------------------------------------*/
  300. ;FRESULT f_chdrive
  301. ;       BYTE drv                /* Drive number */
  302. ;       MACRO F_CHDR
  303. ;       LD A,17
  304. ;       call ffs
  305. ;       ENDM
  306. ;       MACRO F_CHDRIVE _DRV
  307. ;       LD e,_DRV
  308. ;       F_CHDR
  309. ;       ENDM
  310.  
  311. ; FRESULT f_chdir (
  312.         ; TCHAR *path   /* Pointer to the directory path */
  313. ; )
  314.         MACRO F_CHDIR
  315.         ld hl,ffsfunc.f_chdir
  316.         call call_ffs
  317.         ENDM
  318.  
  319. ;FRESULT f_getcwd (
  320. ;       DE=TCHAR *path, /* Pointer to the directory path */ буфер
  321. ;       BC=UINT sz_path /* Size of path */) размер буфера
  322.  
  323.         MACRO F_GETCWD_CURDRV
  324.         ld hl,ffsfunc.f_getcwd
  325.         call call_ffs_curvol
  326.         ENDM
  327.  
  328.         ;MACRO F_MUL _ARG
  329.         ;LD DE,0
  330.         ;PUSH DE
  331.         ;LD de,_ARG
  332.         ;push de
  333.         ;LD A,20;19
  334.         ;call ffs
  335.         ;endm
  336.  
  337.  
  338. ;FRESULT f_utime (const TCHAR*, WORD fdate, WORD ftime); /* Change timestamp of the file/dir */
  339. ;de=name
  340. ;bc=date
  341. ;stack=time
  342.         MACRO F_UTIME_CURDRV
  343.         ld hl,ffsfunc.f_utime
  344.         call call_ffs_curvol
  345.         ENDM
  346.  
  347. ;FRESULT f_getutime (const TCHAR*, WORD *ftimedate); /* Get timestamp of the file/dir */
  348. ;de=name
  349. ;bc=pointer to time,date
  350.         MACRO F_GETUTIME
  351.         ld hl,ffsfunc.f_getutime
  352.         call call_ffs_curvol
  353.         ENDM
  354.  
  355.  
  356. ; /* File function return code (FRESULT) */
  357.  
  358. ; typedef enum {
  359.         ; FR_OK = 0,                            /* (0) Succeeded */
  360.         ; FR_DISK_ERR,                  /* (1) A hard error occured in the low level disk I/O layer */
  361.         ; FR_INT_ERR,                           /* (2) Assertion failed */
  362.         ; FR_NOT_READY,                 /* (3) The physical drive cannot work */
  363.         ; FR_NO_FILE,                           /* (4) Could not find the file */
  364.         ; FR_NO_PATH,                           /* (5) Could not find the path */
  365.         ; FR_INVALID_NAME,              /* (6) The path name format is invalid */
  366.         ; FR_DENIED,                            /* (7) Access denied due to prohibited access or directory full */
  367.         ; FR_EXIST,                             /* (8) Access denied due to prohibited access */
  368.         ; FR_INVALID_OBJECT,            /* (9) The file/directory object is invalid */
  369.         ; FR_WRITE_PROTECTED,           /* (10) The physical drive is write protected */
  370.         ; FR_INVALID_DRIVE,             /* (11) The logical drive number is invalid */
  371.         ; FR_NOT_ENABLED,                       /* (12) The volume has no work area */
  372.         ; FR_NO_FILESYSTEM,             /* (13) There is no valid FAT volume on the physical drive */
  373.         ; FR_MKFS_ABORTED,              /* (14) The f_mkfs() aborted due to any parameter error */
  374.         ; FR_TIMEOUT,                           /* (15) Could not get a grant to access the volume within defined period */
  375.         ; FR_LOCKED,                            /* (16) The operation is rejected according to the file sharing policy */
  376.         ; FR_NOT_ENOUGH_CORE,           /* (17) LFN working buffer could not be allocated */
  377.         ; FR_TOO_MANY_OPEN_FILES        /* (18) Number of open files > _FS_SHARE */
  378. ; } FRESULT;
  379.