Subversion Repositories Kolibri OS

Rev

Rev 8193 | 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. // Copied from TCC
  11. char* strrev(char *p)
  12. {
  13.         char *q = p, *res = p, z;
  14.         while(q && *q) ++q; /* find eos */
  15.         for(--q; p < q; ++p, --q)
  16.         {
  17.         z = *p;
  18.         *p = *q;
  19.         *q = z;
  20.         }
  21.         return res;
  22. }
  23. char* itoab(unsigned int n, char* s, int  b)
  24. {
  25.         char *ptr;
  26.         int lowbit;
  27.         ptr = s;
  28.         b >>= 1;
  29.         do {
  30.         lowbit = n & 1;
  31.         n = (n >> 1) & 0x7FFFFFFF;
  32.         *ptr = ((n % b) << 1) + lowbit;
  33.         if(*ptr < 10) *ptr += '0'; else *ptr += 55;
  34.         ++ptr;
  35.         } while(n /= b);
  36.         *ptr = 0;
  37.         return strrev(s);
  38. }
  39.  
  40. /*
  41. typedef  unsigned int        uint32_t;
  42. typedef  unsigned char       uint8_t;
  43. typedef  unsigned short int  uint16_t;
  44. typedef  unsigned long long  uint64_t;
  45. typedef  char                int8_t;
  46. typedef  short int           int16_t;
  47. typedef  int                 int32_t;
  48. typedef  long long           int64_t;
  49. */
  50. static inline uint32_t getDate(void)
  51. {
  52.     uint32_t date;
  53.     __asm__ __volatile__("int $0x40":"=a"(date):"a"(29));
  54.     return date;
  55. }
  56.  
  57.  
  58.  
  59. static inline uint32_t getTime(void)
  60. {
  61.     uint32_t time;
  62.     __asm__ __volatile__("int $0x40":"=a"(time):"a"(3));
  63.     return time;
  64. }
  65.  
  66.  
  67.  
  68. static inline void *openFile(uint32_t *length, const uint8_t *path)
  69. {
  70.     uint8_t *fd;
  71.  
  72.     __asm__ __volatile__ ("int $0x40":"=a"(fd), "=d"(*length):"a" (68), "b"(27),"c"(path));
  73.  
  74.     return fd;
  75. }
  76.  
  77. struct saveFileStruct
  78. {
  79.     int p1;
  80.     int p2;
  81.     int p3;
  82.     int p4;
  83.  
  84.     char* p5;
  85.     int p6;
  86.     char* p7;
  87. };
  88.  
  89. static inline int32_t saveFile(uint32_t nbytes, uint8_t *data, uint32_t enc, uint8_t  *path)
  90. {
  91.     int32_t val;
  92.  
  93.     struct saveFileStruct dt; // basic information structure.
  94.    
  95.     dt.p1 = 2;       // subfunction number.
  96.     dt.p2= 0;        // reserved.
  97.     dt.p3 = 0;       // reserved.
  98.     dt.p4 = nbytes;  // number of bytes to write.
  99.     dt.p5 = data;    // pointer to data.
  100.     dt.p6 = enc;     // string encoding (0 = default, 1 = cp866, 2 = UTF-16LE, 3 = UTF-8).
  101.     dt.p7 = path;    // pointer to path.
  102.  
  103.     __asm__ __volatile__("int $0x40":"=a"(val):"a"(80), "b"(&dt):"memory");
  104.  
  105.     return val;
  106. }
  107.  
  108. int checkStateOnSave(int state)
  109. {
  110.     #if defined (lang_en)
  111.  
  112.         switch(state)
  113.         {
  114.             case 2:  con_printf("\nThe function isn't supported for the given file system!\n");
  115.                      return 2;
  116.  
  117.             case 3:  con_printf("\nUnknown file system!\n");
  118.                      return 3;
  119.  
  120.             case 5:  con_printf("\nFile isn't found!\n");
  121.                      return 5;
  122.  
  123.             case 6:  con_printf("\nEnd of a file, EOF!\n");
  124.                      return 6;
  125.  
  126.             case 7:  con_printf("\nPointer lies outside of application memory!\n");
  127.                      return 7;
  128.  
  129.             case 8:  con_printf("\nDisk is full!\n");
  130.                      return 8;
  131.  
  132.             case 9:  con_printf("\nFile system error!\n");
  133.                      return 9;
  134.  
  135.             case 10: con_printf("\nAccess denied!\n");
  136.                      return 10;
  137.  
  138.             case 11: con_printf("\nDevice error!\n");
  139.                      return 11;
  140.  
  141.             case 12: con_printf("\nFile system requires more memory!\n");
  142.                      return 12;
  143.         }
  144.  
  145.     #elif defined (lang_ru)
  146.  
  147.         switch(state)
  148.         {
  149.             case 2:  con_printf("\n”ã­ªæ¨ï ­¥ ¯®¤¤¥à¦¨¢ ¥âáï ¤«ï ¤ ­­®© ä ©«®¢®© á¨á⥬ë!\n");
  150.                      return 2;
  151.  
  152.             case 3:  con_printf("\n¥¨§¢¥áâ­ ï ä ©«®¢ ï á¨á⥬ !\n");
  153.                      return 3;
  154.  
  155.             case 5:  con_printf("\n” ©« ­¥ ­ ©¤¥­!\n");
  156.                      return 5;
  157.  
  158.             case 6:  con_printf("\n” ©« § ª®­ç¨«áï!\n");
  159.                      return 6;
  160.  
  161.             case 7:  con_printf("\n“ª § â¥«ì ¢­¥ ¯ ¬ï⨠¯à¨«®¦¥­¨ï!\n");
  162.                      return 7;
  163.  
  164.             case 8:  con_printf("\n„¨áª § ¯®«­¥­!\n");
  165.                      return 8;
  166.  
  167.             case 9:  con_printf("\nŽè¨¡ª  ä ©«®¢®© á¨á⥬ë!\n");
  168.                      return 9;
  169.  
  170.             case 10: con_printf("\n„®áâ㯠§ ¯à¥éñ­!\n");
  171.                      return 10;
  172.  
  173.             case 11: con_printf("\nŽè¨¡ª  ãáâனá⢠!\n");
  174.                      return 11;
  175.  
  176.             case 12: con_printf("\n” ©«®¢®© á¨á⥬¥ ­¥¤®áâ â®ç­® ®¯¥à â¨¢­®© ¯ ¬ïâ¨!\n");
  177.                      return 12;
  178.         }
  179.  
  180.     #endif
  181. }
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189. #endif
  190.