?login_element?

Subversion Repositories NedoOS

Rev

Rev 816 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  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. lfn             WORD    ;/* Pointer to the LFN working buffer */
  109. lfn_idx WORD    ;/* Last matched LFN index number (0xFFFF:No LFN) */
  110.         ENDS
  111. DIR_sz=22+4
  112.  
  113. ;/* FILE STATUS STRUCTURE (FILINFO) */
  114. ;       STRUCT FILINFO
  115. ;FSIZE          DWORD           ;/* FILE SIZE */
  116. ;FDATE          WORD            ;/* LAST MODIFIED DATE */
  117. ;FTIME          WORD            ;/* LAST MODIFIED TIME */
  118. ;FATTRIB                BYTE            ;/* ATTRIBUTE */
  119. ;FNAME          BLOCK 13,0      ;/* SHORT FILE NAME (8.3 FORMAT with dot and terminator) */
  120. ;LNAME          BLOCK 64,0      ;/* LONG FILE NAME (ASCIIZ) */
  121. ;       ENDS
  122.  
  123. ;/* File object structure (FIL) */
  124.  
  125.         struct FIL
  126. FS              WORD    ;/* Pointer to the owner file system object */
  127. ID              WORD    ;/* Owner file system mount ID */
  128. FLAG            BYTE    ;/* File status flags */
  129. PAD1            BYTE    ;;TODO добавить тут id приложения-хозяина, чтобы можно было автоматически удалить
  130. FPTR            DWORD   ;/* File read/write pointer (0 on file open) */
  131. FSIZE           DWORD   ;/* File size */
  132. FCLUST          DWORD   ;/* File start cluster (0 when fsize==0) */
  133. CLUST           DWORD   ;/* Current cluster */
  134. DSECT           DWORD   ;/* Current data sector */
  135. DIR_SECT        DWORD   ;/* Sector containing the directory entry */
  136. DIR_PTR         WORD    ;/* Ponter to the directory entry in the window */
  137. BUF             BLOCK 512       ;/* File data read/write buffer */
  138.         ENDS
  139. FIL_sz=32+512
  140.  
  141.  
  142. ;---------------------------------МАКРОСЫ--------------------------------------
  143.  
  144. ;/*-----------------------------------------------------------------------*/
  145. ;/* Mount/Unmount a Logical Drive                                         */
  146. ;/*-----------------------------------------------------------------------*/
  147. ;
  148. ;FRESULT f_mount (
  149. ;       BYTE vol,               /* Logical drive number to be mounted/unmounted */
  150. ;       FATFS *fs               /* Pointer to new file system object (NULL for unmount)*/
  151. ;)
  152.         MACRO F_MOUNT _VOL,_FS  ;vol - уже лежит на стеке.
  153.         ld e,_VOL
  154.         LD bc,_FS
  155.         F_MNT
  156.         ENDM
  157.         MACRO F_MNT
  158.         call ffsfunc.f_mount
  159.         ENDM
  160.  
  161.  
  162. ; FRESULT f_open (
  163.         ; FIL *fp,                      /* Pointer to the blank file object */
  164.         ; TCHAR *path,  /* Pointer to the file name */
  165.         ; BYTE mode                     /* Access mode and file open mode flags */
  166. ; )
  167. ;de=fil
  168. ;hl=flags
  169. ;bc=filename
  170.         MACRO F_OP
  171.         call open_keeppid
  172.         PUSH HL
  173.         LD hl,ffsfunc.f_open
  174.         call call_ffs
  175.         POP BC
  176.         ENDM
  177.        
  178.         MACRO F_OPEN_CURDRV
  179.         call open_keeppid
  180.         PUSH HL
  181.         LD hl,ffsfunc.f_open
  182.         call call_ffs_curvol
  183.         POP BC
  184.         ENDM
  185.  
  186. ;seek
  187. ;FRESULT f_lseek (
  188. ;       FIL *fp,                /* Pointer to the file object */
  189. ;       DWORD ofs               /* File pointer from top of file */
  190. ;)
  191. ;fp = de
  192. ;ofs in stack
  193.         MACRO F_LSEEK_CURDRV
  194.         ld hl,ffsfunc.f_lseek
  195.         call call_ffs_curvol
  196.         ENDM
  197.  
  198.        
  199. ;/*-----------------------------------------------------------------------*/
  200. ;/* Read File                                                             */
  201. ;/*-----------------------------------------------------------------------*/
  202. ;FRESULT f_read
  203. ;       FIL *fp,                /* Pointer to the file object */
  204. ;       void *buff,             /* Pointer to data buffer */
  205. ;       UINT btr,               /* Number of bytes to read */
  206. ;       UINT *br                /* Pointer to number of bytes read */
  207.         MACRO F_READ_CURDRV
  208.         ld hl,ffsfunc.f_read
  209.         call call_ffs_curvol
  210.         ENDM
  211.        
  212.        
  213. ;/*-----------------------------------------------------------------------*/
  214. ;/* Write File                                                            */
  215. ;/*-----------------------------------------------------------------------*/
  216. ;FRESULT f_write
  217. ;       FIL *fp,                        /* Pointer to the file object */
  218. ;       const void *buff,       /* Pointer to the data to be written */
  219. ;       UINT btw,                       /* Number of bytes to write */
  220. ;       UINT *bw                        /* Pointer to number of bytes written */
  221.         MACRO F_WRITE_CURDRV
  222.         ld hl,ffsfunc.f_write
  223.         call call_ffs_curvol
  224.         ENDM
  225.  
  226. ; /*-----------------------------------------------------------------------*/
  227. ; /* Close File                                                            */
  228. ; /*-----------------------------------------------------------------------*/
  229. ; FRESULT f_close (
  230.         ; FIL *fp               /* Pointer to the file object to be closed */)
  231.         MACRO F_CLOS_CURDRV ;de=fil
  232.        ld a,d
  233.        or e
  234.        call nz,f_clos_curdrv_pp
  235.         ENDM
  236.  
  237.  
  238.  
  239. ; /*-----------------------------------------------------------------------*/
  240. ; /* Create a Directory Object                                             */
  241. ; /*-----------------------------------------------------------------------*/
  242. ; FRESULT f_opendir
  243.         ; DIR *dj,                      /* Pointer to directory object to create */
  244.         ; TCHAR *path   /* Pointer to the directory path */
  245.  
  246.         MACRO F_OPDIR_CURDRV
  247.         ld hl,ffsfunc.f_opendir
  248.         call call_ffs_curvol
  249.         ENDM
  250.  
  251. ; /*-----------------------------------------------------------------------*/
  252. ; /* Read Directory Entry in Sequence                                      */
  253. ; /*-----------------------------------------------------------------------*/
  254.  
  255. ; FRESULT f_readdir (
  256.         ; DIR *dj,                      /* Pointer to the open directory object */
  257.         ; FILINFO *fno          /* Pointer to file information to return */
  258. ; )
  259.         MACRO F_RDIR_CURDRV
  260.         ld hl,ffsfunc.f_readdir
  261.         call call_ffs_curvol
  262.         ENDM
  263.  
  264.  
  265. ;/*-----------------------------------------------------------------------*/
  266. ;/* Delete a File or Directory                                            */
  267. ;/*-----------------------------------------------------------------------*/
  268. ;FRESULT f_unlink
  269. ;       const TCHAR *path               /* Pointer to the file or directory path */
  270.         MACRO F_UNLINK_CURDRV
  271.         ld hl,ffsfunc.f_unlink
  272.         call call_ffs_curvol
  273.         ENDM
  274.         MACRO F_UNLINK
  275.         ld hl,ffsfunc.f_unlink
  276.         call call_ffs
  277.         ENDM
  278. ;/*-----------------------------------------------------------------------*/
  279. ;/* Create a Directory                                                    */
  280. ;/*-----------------------------------------------------------------------*/
  281. ;FRESULT f_mkdir
  282. ;       const TCHAR *path               /* Pointer to the directory path */
  283.         MACRO F_MKDIR
  284.         ld hl,ffsfunc.f_mkdir
  285.         call call_ffs
  286.         ENDM
  287. ;/*-----------------------------------------------------------------------*/
  288. ;/* Rename File/Directory                                                 */
  289. ;/*-----------------------------------------------------------------------*/
  290. ;FRESULT f_rename
  291. ;       const TCHAR *path_old,  /* Pointer to the old name */
  292. ;       const TCHAR *path_new   /* Pointer to the new name */
  293.  
  294.         MACRO F_RENAME
  295.         ld hl,ffsfunc.f_rename
  296.         call call_ffs
  297.         ENDM
  298.  
  299. ;/*-----------------------------------------------------------------------*/
  300. ;/* Current Drive/Directory Handlings                                     */
  301. ;/*-----------------------------------------------------------------------*/
  302. ;FRESULT f_chdrive
  303. ;       BYTE drv                /* Drive number */
  304. ;       MACRO F_CHDR
  305. ;       LD A,17
  306. ;       call ffs
  307. ;       ENDM
  308. ;       MACRO F_CHDRIVE _DRV
  309. ;       LD e,_DRV
  310. ;       F_CHDR
  311. ;       ENDM
  312.  
  313. ; FRESULT f_chdir (
  314.         ; TCHAR *path   /* Pointer to the directory path */
  315. ; )
  316.         MACRO F_CHDIR
  317.         ld hl,ffsfunc.f_chdir
  318.         call call_ffs
  319.         ENDM
  320.  
  321. ;FRESULT f_getcwd (
  322. ;       DE=TCHAR *path, /* Pointer to the directory path */ буфер
  323. ;       BC=UINT sz_path /* Size of path */) размер буфера
  324.  
  325.         MACRO F_GETCWD_CURDRV
  326.         ld hl,ffsfunc.f_getcwd
  327.         call call_ffs_curvol
  328.         ENDM
  329.  
  330.         ;MACRO F_MUL _ARG
  331.         ;LD DE,0
  332.         ;PUSH DE
  333.         ;LD de,_ARG
  334.         ;push de
  335.         ;LD A,20;19
  336.         ;call ffs
  337.         ;endm
  338.  
  339. ;FRESULT f_stat (const TCHAR*, FILINFO*);                       /* Get file status */
  340. ;       DE=TCHAR *path,
  341. ;       BC=FILINFO* буфер
  342.         MACRO F_STAT
  343.         ld hl,ffsfunc.f_stat
  344.         call call_ffs
  345.         ENDM
  346.  
  347.  
  348. ;FRESULT f_utime (const TCHAR*, WORD fdate, WORD ftime); /* Change timestamp of the file/dir */
  349. ;de=name
  350. ;bc=date
  351. ;stack=time
  352.         MACRO F_UTIME_CURDRV
  353.         ld hl,ffsfunc.f_utime
  354.         call call_ffs;_curvol
  355.         ENDM
  356.  
  357. ;FRESULT f_getutime (const TCHAR*, WORD *ftimedate); /* Get timestamp of the file/dir */
  358. ;de=name
  359. ;bc=pointer to time,date
  360.         MACRO F_GETUTIME
  361.         ld hl,ffsfunc.f_getutime
  362.         call call_ffs;_curvol
  363.         ENDM
  364.  
  365.  
  366. ; /* File function return code (FRESULT) */
  367.  
  368. ; typedef enum {
  369.         ; FR_OK = 0,                            /* (0) Succeeded */
  370.         ; FR_DISK_ERR,                  /* (1) A hard error occured in the low level disk I/O layer */
  371.         ; FR_INT_ERR,                           /* (2) Assertion failed */
  372.         ; FR_NOT_READY,                 /* (3) The physical drive cannot work */
  373.         ; FR_NO_FILE,                           /* (4) Could not find the file */
  374.         ; FR_NO_PATH,                           /* (5) Could not find the path */
  375.         ; FR_INVALID_NAME,              /* (6) The path name format is invalid */
  376.         ; FR_DENIED,                            /* (7) Access denied due to prohibited access or directory full */
  377.         ; FR_EXIST,                             /* (8) Access denied due to prohibited access */
  378.         ; FR_INVALID_OBJECT,            /* (9) The file/directory object is invalid */
  379.         ; FR_WRITE_PROTECTED,           /* (10) The physical drive is write protected */
  380.         ; FR_INVALID_DRIVE,             /* (11) The logical drive number is invalid */
  381.         ; FR_NOT_ENABLED,                       /* (12) The volume has no work area */
  382.         ; FR_NO_FILESYSTEM,             /* (13) There is no valid FAT volume on the physical drive */
  383.         ; FR_MKFS_ABORTED,              /* (14) The f_mkfs() aborted due to any parameter error */
  384.         ; FR_TIMEOUT,                           /* (15) Could not get a grant to access the volume within defined period */
  385.         ; FR_LOCKED,                            /* (16) The operation is rejected according to the file sharing policy */
  386.         ; FR_NOT_ENOUGH_CORE,           /* (17) LFN working buffer could not be allocated */
  387.         ; FR_TOO_MANY_OPEN_FILES        /* (18) Number of open files > _FS_SHARE */
  388. ; } FRESULT;
  389.