Subversion Repositories Kolibri OS

Rev

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

  1.  
  2. /*
  3.  * Backy_lib.h
  4.  * Author: JohnXenox aka Aleksandr Igorevich.
  5.  */
  6.  
  7. #ifndef __jxl_Date_get_h__
  8. #define __jxl_Date_get_h__
  9.  
  10. #ifdef ___TINY_C___
  11.  
  12. typedef  unsigned int        uint32_t;
  13. typedef  unsigned char       uint8_t;
  14. typedef  unsigned short int  uint16_t;
  15. typedef  unsigned long long  uint64_t;
  16. typedef  char                int8_t;
  17. typedef  short int           int16_t;
  18. typedef  int                 int32_t;
  19. typedef  long long           int64_t;
  20.  
  21. static inline int32_t saveFile(uint32_t nbytes, uint8_t *data, uint32_t enc, uint8_t  *path)
  22. {
  23.     int32_t val;
  24.  
  25.     uint8_t dt[28];  // basic information structure.
  26.  
  27.     (uint32_t)  dt[0]  = 2;       // subfunction number.
  28.     (uint32_t)  dt[4]  = 0;       // reserved.
  29.     (uint32_t)  dt[8]  = 0;       // reserved.
  30.     (uint32_t)  dt[12] = nbytes;  // number of bytes to write.
  31.     (uint8_t *) dt[16] = data;    // pointer to data.
  32.     (uint32_t)  dt[20] = enc;     // string encoding (0 = default, 1 = cp866, 2 = UTF-16LE, 3 = UTF-8).
  33.     (uint8_t *) dt[24] = path;    // pointer to path.
  34.  
  35.     __asm__ __volatile__("int $0x40":"=a"(val):"a"(80), "b"(&dt));
  36.  
  37.     return val;
  38. }
  39.  
  40. #else
  41.  
  42. #include <stdint.h>
  43.  
  44. static inline int32_t saveFile(uint32_t nbytes, uint8_t *data, uint32_t enc, uint8_t  *path)
  45. {
  46.     int32_t val;
  47.  
  48.     struct file_op_t
  49.     {
  50.         uint32_t    fn;
  51.         uint32_t    reserved0;
  52.         uint32_t    reserved1;
  53.         uint32_t    number_of_bytes_to_write;
  54.         void *      pointer_to_data;
  55.         char        path[1];
  56.     } *file_op = calloc(sizeof(*file_op) + strlen(path) + 2, 1); // FIXME: Not works on UTF16LE enc
  57.    
  58.     file_op->fn = 2;
  59.     file_op->number_of_bytes_to_write = nbytes;
  60.     file_op->pointer_to_data = data;
  61.     if (enc != 0)
  62.     {
  63.         file_op->path[0] = enc;
  64.         strcpy(file_op->path + 1, path);
  65.     }
  66.     else
  67.     {
  68.         strcpy(file_op->path, path);
  69.     }
  70.    
  71.     asm volatile ("int $0x40":"=a"(val):"a"(80), "b"(file_op));
  72.     return val;
  73. }
  74.  
  75. #endif
  76.  
  77. static inline uint32_t getDate(void)
  78. {
  79.     uint32_t date;
  80.     __asm__ __volatile__("int $0x40":"=a"(date):"a"(29));
  81.     return date;
  82. }
  83.  
  84.  
  85.  
  86. static inline uint32_t getTime(void)
  87. {
  88.     uint32_t time;
  89.     __asm__ __volatile__("int $0x40":"=a"(time):"a"(3));
  90.     return time;
  91. }
  92.  
  93.  
  94.  
  95. static inline void *openFile(uint32_t *length, const uint8_t *path)
  96. {
  97.     uint8_t *fd;
  98.  
  99.     __asm__ __volatile__ ("int $0x40":"=a"(fd), "=d"(*length):"a" (68), "b"(27),"c"(path));
  100.  
  101.     return fd;
  102. }
  103.  
  104. #endif
  105.