?login_element?

Subversion Repositories NedoOS

Rev

Rev 533 | Rev 643 | Go to most recent revision | 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.         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. ;de=fil
  171. ;hl=flags
  172. ;bc=filename
  173.         MACRO F_OP
  174.         call open_keeppid
  175.         PUSH HL
  176.         LD hl,ffsfunc.f_open
  177.         call call_ffs
  178.         POP BC
  179.         ENDM
  180.        
  181.     MACRO F_OPEN_CURDRV
  182.         call open_keeppid
  183.         PUSH HL
  184.         LD hl,ffsfunc.f_open
  185.         call call_ffs_curvol
  186.         POP BC
  187.         ENDM
  188.  
  189. ;seek
  190. ;FRESULT f_lseek (
  191. ;       FIL *fp,                /* Pointer to the file object */
  192. ;       DWORD ofs               /* File pointer from top of file */
  193. ;)
  194. ;fp = de
  195. ;ofs in stack
  196.         MACRO F_LSEEK_CURDRV
  197.         ld hl,ffsfunc.f_lseek
  198.         call call_ffs_curvol
  199.         ENDM
  200.  
  201.        
  202. ;/*-----------------------------------------------------------------------*/
  203. ;/* Read File                                                             */
  204. ;/*-----------------------------------------------------------------------*/
  205. ;FRESULT f_read
  206. ;       FIL *fp,                /* Pointer to the file object */
  207. ;       void *buff,             /* Pointer to data buffer */
  208. ;       UINT btr,               /* Number of bytes to read */
  209. ;       UINT *br                /* Pointer to number of bytes read */
  210.         MACRO F_READ_CURDRV
  211.         ld hl,ffsfunc.f_read
  212.         call call_ffs_curvol
  213.         ENDM
  214.        
  215.        
  216. ;/*-----------------------------------------------------------------------*/
  217. ;/* Write File                                                            */
  218. ;/*-----------------------------------------------------------------------*/
  219. ;FRESULT f_write
  220. ;       FIL *fp,                        /* Pointer to the file object */
  221. ;       const void *buff,       /* Pointer to the data to be written */
  222. ;       UINT btw,                       /* Number of bytes to write */
  223. ;       UINT *bw                        /* Pointer to number of bytes written */
  224.         MACRO F_WRITE_CURDRV
  225.         ld hl,ffsfunc.f_write
  226.         call call_ffs_curvol
  227.         ENDM
  228.  
  229. ; /*-----------------------------------------------------------------------*/
  230. ; /* Close File                                                            */
  231. ; /*-----------------------------------------------------------------------*/
  232. ; FRESULT f_close (
  233.         ; FIL *fp               /* Pointer to the file object to be closed */)
  234.     MACRO F_CLOS_CURDRV ;de=fil
  235.     push de
  236.     call BDOS_setpgstructs
  237.     inc de
  238.     inc de
  239.     inc de
  240.     inc de
  241.     inc de
  242.     xor a
  243.     ld (de),a
  244.     pop de
  245.         ld hl,ffsfunc.f_close
  246.         call call_ffs_curvol
  247.         ENDM
  248.  
  249.  
  250.  
  251. ; /*-----------------------------------------------------------------------*/
  252. ; /* Create a Directory Object                                             */
  253. ; /*-----------------------------------------------------------------------*/
  254. ; FRESULT f_opendir
  255.         ; DIR *dj,                      /* Pointer to directory object to create */
  256.         ; TCHAR *path   /* Pointer to the directory path */
  257.  
  258.         MACRO F_OPDIR_CURDRV
  259.         ld hl,ffsfunc.f_opendir
  260.         call call_ffs_curvol
  261.         ENDM
  262.  
  263. ; /*-----------------------------------------------------------------------*/
  264. ; /* Read Directory Entry in Sequence                                      */
  265. ; /*-----------------------------------------------------------------------*/
  266.  
  267. ; FRESULT f_readdir (
  268.         ; DIR *dj,                      /* Pointer to the open directory object */
  269.         ; FILINFO *fno          /* Pointer to file information to return */
  270. ; )
  271.         MACRO F_RDIR_CURDRV
  272.         ld hl,ffsfunc.f_readdir
  273.         call call_ffs_curvol
  274.         ENDM
  275.  
  276.  
  277. ;/*-----------------------------------------------------------------------*/
  278. ;/* Delete a File or Directory                                            */
  279. ;/*-----------------------------------------------------------------------*/
  280. ;FRESULT f_unlink
  281. ;       const TCHAR *path               /* Pointer to the file or directory path */
  282.         MACRO F_UNLINK_CURDRV
  283.         ld hl,ffsfunc.f_unlink
  284.         call call_ffs_curvol
  285.         ENDM
  286.         MACRO F_UNLINK
  287.         ld hl,ffsfunc.f_unlink
  288.         call call_ffs
  289.         ENDM
  290. ;/*-----------------------------------------------------------------------*/
  291. ;/* Create a Directory                                                    */
  292. ;/*-----------------------------------------------------------------------*/
  293. ;FRESULT f_mkdir
  294. ;       const TCHAR *path               /* Pointer to the directory path */
  295.         MACRO F_MKDIR
  296.         ld hl,ffsfunc.f_mkdir
  297.         call call_ffs
  298.         ENDM
  299. ;/*-----------------------------------------------------------------------*/
  300. ;/* Rename File/Directory                                                 */
  301. ;/*-----------------------------------------------------------------------*/
  302. ;FRESULT f_rename
  303. ;       const TCHAR *path_old,  /* Pointer to the old name */
  304. ;       const TCHAR *path_new   /* Pointer to the new name */
  305.  
  306.         MACRO F_RENAME
  307.         ld hl,ffsfunc.f_rename
  308.         call call_ffs
  309.         ENDM
  310.  
  311. ;/*-----------------------------------------------------------------------*/
  312. ;/* Current Drive/Directory Handlings                                     */
  313. ;/*-----------------------------------------------------------------------*/
  314. ;FRESULT f_chdrive
  315. ;       BYTE drv                /* Drive number */
  316. ;       MACRO F_CHDR
  317. ;       LD A,17
  318. ;       call ffs
  319. ;       ENDM
  320. ;       MACRO F_CHDRIVE _DRV
  321. ;       LD e,_DRV
  322. ;       F_CHDR
  323. ;       ENDM
  324.  
  325. ; FRESULT f_chdir (
  326.         ; TCHAR *path   /* Pointer to the directory path */
  327. ; )
  328.         MACRO F_CHDIR
  329.         ld hl,ffsfunc.f_chdir
  330.         call call_ffs
  331.         ENDM
  332.  
  333. ;FRESULT f_getcwd (
  334. ;       DE=TCHAR *path, /* Pointer to the directory path */ буфер
  335. ;       BC=UINT sz_path /* Size of path */) размер буфера
  336.  
  337.         MACRO F_GETCWD_CURDRV
  338.         ld hl,ffsfunc.f_getcwd
  339.         call call_ffs_curvol
  340.         ENDM
  341.  
  342.         ;MACRO F_MUL _ARG
  343.         ;LD DE,0
  344.         ;PUSH DE
  345.         ;LD de,_ARG
  346.         ;push de
  347.         ;LD A,20;19
  348.         ;call ffs
  349.         ;endm
  350.  
  351.  
  352. ;FRESULT f_utime (const TCHAR*, WORD fdate, WORD ftime); /* Change timestamp of the file/dir */
  353. ;de=name
  354. ;bc=date
  355. ;stack=time
  356.         MACRO F_UTIME_CURDRV
  357.         ld hl,ffsfunc.f_utime
  358.         call call_ffs_curvol
  359.         ENDM
  360.  
  361. ;FRESULT f_getutime (const TCHAR*, WORD *ftimedate); /* Get timestamp of the file/dir */
  362. ;de=name
  363. ;bc=pointer to time,date
  364.         MACRO F_GETUTIME
  365.         ld hl,ffsfunc.f_getutime
  366.         call call_ffs_curvol
  367.         ENDM
  368.  
  369.  
  370. ; /* File function return code (FRESULT) */
  371.  
  372. ; typedef enum {
  373.         ; FR_OK = 0,                            /* (0) Succeeded */
  374.         ; FR_DISK_ERR,                  /* (1) A hard error occured in the low level disk I/O layer */
  375.         ; FR_INT_ERR,                           /* (2) Assertion failed */
  376.         ; FR_NOT_READY,                 /* (3) The physical drive cannot work */
  377.         ; FR_NO_FILE,                           /* (4) Could not find the file */
  378.         ; FR_NO_PATH,                           /* (5) Could not find the path */
  379.         ; FR_INVALID_NAME,              /* (6) The path name format is invalid */
  380.         ; FR_DENIED,                            /* (7) Access denied due to prohibited access or directory full */
  381.         ; FR_EXIST,                             /* (8) Access denied due to prohibited access */
  382.         ; FR_INVALID_OBJECT,            /* (9) The file/directory object is invalid */
  383.         ; FR_WRITE_PROTECTED,           /* (10) The physical drive is write protected */
  384.         ; FR_INVALID_DRIVE,             /* (11) The logical drive number is invalid */
  385.         ; FR_NOT_ENABLED,                       /* (12) The volume has no work area */
  386.         ; FR_NO_FILESYSTEM,             /* (13) There is no valid FAT volume on the physical drive */
  387.         ; FR_MKFS_ABORTED,              /* (14) The f_mkfs() aborted due to any parameter error */
  388.         ; FR_TIMEOUT,                           /* (15) Could not get a grant to access the volume within defined period */
  389.         ; FR_LOCKED,                            /* (16) The operation is rejected according to the file sharing policy */
  390.         ; FR_NOT_ENOUGH_CORE,           /* (17) LFN working buffer could not be allocated */
  391.         ; FR_TOO_MANY_OPEN_FILES        /* (18) Number of open files > _FS_SHARE */
  392. ; } FRESULT;
  393.