Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1.  
  2. /*
  3.  * Backy_lib.h
  4.  * Author: JohnXenox aka Aleksandr Igorevich.
  5.  */
  6.  
  7. #ifndef __Backy_lib_h__
  8. #define __Backy_lib_h__
  9.  
  10. typedef  unsigned int        uint32_t;
  11. typedef  unsigned char       uint8_t;
  12. typedef  unsigned short int  uint16_t;
  13. typedef  unsigned long long  uint64_t;
  14. typedef  char                int8_t;
  15. typedef  short int           int16_t;
  16. typedef  int                 int32_t;
  17. typedef  long long           int64_t;
  18.  
  19. static inline uint32_t getDate(void)
  20. {
  21.     uint32_t date;
  22.     __asm__ __volatile__("int $0x40":"=a"(date):"a"(29));
  23.     return date;
  24. }
  25.  
  26.  
  27.  
  28. static inline uint32_t getTime(void)
  29. {
  30.     uint32_t time;
  31.     __asm__ __volatile__("int $0x40":"=a"(time):"a"(3));
  32.     return time;
  33. }
  34.  
  35.  
  36.  
  37. static inline void *openFile(uint32_t *length, const uint8_t *path)
  38. {
  39.     uint8_t *fd;
  40.  
  41.     __asm__ __volatile__ ("int $0x40":"=a"(fd), "=d"(*length):"a" (68), "b"(27),"c"(path));
  42.  
  43.     return fd;
  44. }
  45.  
  46.  
  47.  
  48. static inline int32_t saveFile(uint32_t nbytes, uint8_t *data, uint32_t enc, uint8_t  *path)
  49. {
  50.     int32_t val;
  51.  
  52.     uint8_t dt[28];  // basic information structure.
  53.  
  54.     (uint32_t)  dt[0]  = 2;       // subfunction number.
  55.     (uint32_t)  dt[4]  = 0;       // reserved.
  56.     (uint32_t)  dt[8]  = 0;       // reserved.
  57.     (uint32_t)  dt[12] = nbytes;  // number of bytes to write.
  58.     (uint8_t *) dt[16] = data;    // pointer to data.
  59.     (uint32_t)  dt[20] = enc;     // string encoding (0 = default, 1 = cp866, 2 = UTF-16LE, 3 = UTF-8).
  60.     (uint8_t *) dt[24] = path;    // pointer to path.
  61.  
  62.     __asm__ __volatile__("int $0x40":"=a"(val):"a"(80), "b"(&dt));
  63.  
  64.     return val;
  65. }
  66.  
  67.  
  68.  
  69.  
  70.  
  71. int checkStateOnSave(int state)
  72. {
  73.     #if defined (lang_en)
  74.  
  75.         switch(state)
  76.         {
  77.             case 2:  con_printf("\nThe function isn't supported for the given file system!\n");
  78.                      return 2;
  79.  
  80.             case 3:  con_printf("\nUnknown file system!\n");
  81.                      return 3;
  82.  
  83.             case 5:  con_printf("\nFile isn't found!\n");
  84.                      return 5;
  85.  
  86.             case 6:  con_printf("\nEnd of a file, EOF!\n");
  87.                      return 6;
  88.  
  89.             case 7:  con_printf("\nPointer lies outside of application memory!\n");
  90.                      return 7;
  91.  
  92.             case 8:  con_printf("\nDisk is full!\n");
  93.                      return 8;
  94.  
  95.             case 9:  con_printf("\nFile system error!\n");
  96.                      return 9;
  97.  
  98.             case 10: con_printf("\nAccess denied!\n");
  99.                      return 10;
  100.  
  101.             case 11: con_printf("\nDevice error!\n");
  102.                      return 11;
  103.  
  104.             case 12: con_printf("\nFile system requires more memory!\n");
  105.                      return 12;
  106.         }
  107.  
  108.     #elif defined (lang_ru)
  109.  
  110.         switch(state)
  111.         {
  112.             case 2:  con_printf("\n”ã­ªæ¨ï ­¥ ¯®¤¤¥à¦¨¢ ¥âáï ¤«ï ¤ ­­®© ä ©«®¢®© á¨á⥬ë!\n");
  113.                      return 2;
  114.  
  115.             case 3:  con_printf("\n¥¨§¢¥áâ­ ï ä ©«®¢ ï á¨á⥬ !\n");
  116.                      return 3;
  117.  
  118.             case 5:  con_printf("\n” ©« ­¥ ­ ©¤¥­!\n");
  119.                      return 5;
  120.  
  121.             case 6:  con_printf("\n” ©« § ª®­ç¨«áï!\n");
  122.                      return 6;
  123.  
  124.             case 7:  con_printf("\n“ª § â¥«ì ¢­¥ ¯ ¬ï⨠¯à¨«®¦¥­¨ï!\n");
  125.                      return 7;
  126.  
  127.             case 8:  con_printf("\n„¨áª § ¯®«­¥­!\n");
  128.                      return 8;
  129.  
  130.             case 9:  con_printf("\nŽè¨¡ª  ä ©«®¢®© á¨á⥬ë!\n");
  131.                      return 9;
  132.  
  133.             case 10: con_printf("\n„®áâ㯠§ ¯à¥éñ­!\n");
  134.                      return 10;
  135.  
  136.             case 11: con_printf("\nŽè¨¡ª  ãáâனá⢠!\n");
  137.                      return 11;
  138.  
  139.             case 12: con_printf("\n” ©«®¢®© á¨á⥬¥ ­¥¤®áâ â®ç­® ®¯¥à â¨¢­®© ¯ ¬ïâ¨!\n");
  140.                      return 12;
  141.         }
  142.  
  143.     #endif
  144. }
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152. #endif
  153.