Subversion Repositories Kolibri OS

Rev

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

  1. /*
  2. sys/kos.h
  3. An attempt to create new C/C++ wrapper for syscalls
  4. Based on kos32sys.h
  5. KolibriOS Team
  6. */
  7.  
  8. #include <stdint.h>
  9. #include <string.h>
  10.  
  11. /*********************** Types *************************/
  12. typedef unsigned int color_t;
  13.  
  14. // struct for sysfn 70
  15. #pragma pack(push,1)
  16. typedef struct {
  17.         unsigned p00;
  18.         unsigned p04;
  19.         char *p08;
  20.         unsigned p12;
  21.         unsigned p16;
  22.         char p20;
  23.         char *p21;
  24. } kos_Struct70;
  25. #pragma pack(pop)
  26.  
  27. // struct for blitter
  28. struct blit_call {
  29.         int dstx;
  30.         int dsty;
  31.         int w;
  32.         int h;
  33.         int srcx;
  34.         int srcy;
  35.         int srcw;
  36.         int srch;
  37.         void *bitmap;
  38.         int stride;
  39. };
  40.  
  41. // struct for sysfn 9
  42. #pragma pack(push, 1)
  43. struct proc_info {
  44.         unsigned long cpu_usage;
  45.         unsigned short pos_in_stack;
  46.         unsigned short slot;
  47.         unsigned short reserved;
  48.         char name[12];
  49.         unsigned long address;
  50.         unsigned long memory_usage;
  51.         unsigned long ID;
  52.         unsigned long left,top;
  53.         unsigned long width,height;
  54.         unsigned short thread_state;
  55.         unsigned short reserved2;
  56.         unsigned long cleft, ctop, cwidth, cheight;
  57.         unsigned char window_state;
  58.         unsigned char reserved3[1024 - 71];
  59. };
  60. #pragma pack(pop)
  61.  
  62. // struct for sysfn 48
  63. struct kolibri_system_colors {
  64.   color_t frame_area;
  65.   color_t grab_bar;
  66.   color_t grab_bar_button;
  67.   color_t grab_button_text;
  68.   color_t grab_text;
  69.   color_t work_area;
  70.   color_t work_button;
  71.   color_t work_button_text;
  72.   color_t work_text;
  73.   color_t work_graph;
  74. };
  75.  
  76. typedef union __attribute__((packed)) {
  77.         uint32_t val;
  78.         struct {
  79.                 short x;
  80.                 short y;
  81.         };
  82. } pos_t;
  83.  
  84.  
  85. /*********************** Window Syscalls *************************/
  86. static inline void kos_BeginDraw(void) {
  87.         __asm__ __volatile__(
  88.         "int $0x40" ::"a"(12),"b"(1));
  89. };
  90.  
  91. static inline void kos_EndDraw(void) {
  92.         __asm__ __volatile__(
  93.         "int $0x40" ::"a"(12),"b"(2));
  94. };
  95.  
  96. static inline void kos_DrawWindow(int x, int y, int w, int h, const char *title, color_t bgcolor, uint32_t style) {
  97.         __asm__ __volatile__(
  98.         "int $0x40"
  99.         ::"a"(0),
  100.          "b"((x << 16) | ((w-1) & 0xFFFF)),
  101.          "c"((y << 16) | ((h-1) & 0xFFFF)),
  102.          "d"((style << 24) | (bgcolor & 0xFFFFFF)),
  103.          "D"(title),
  104.          "S"(0) : "memory");
  105. };
  106.  
  107. #define ZPOS_DESKTOP     -2
  108. #define ZPOS_ALWAYS_BACK -1
  109. #define ZPOS_NORMAL      0
  110. #define ZPOS_ALWAYS_TOP  1
  111. static inline void kos_SetWindowLayerBehaviour(int zpos) {
  112.         __asm__ __volatile__(
  113.         "int $0x40"
  114.         ::"a"(18),
  115.          "b"(25),
  116.          "c"(2),
  117.          "d"(-1),
  118.          "S"(zpos) : "memory");
  119. };
  120.  
  121. #define OLD -1
  122. static inline void kos_ChangeWindow(int new_x, int new_y, int new_w, int new_h) {
  123.         __asm__ __volatile__(
  124.                 "int $0x40"
  125.                 ::"a"(67), "b"(new_x), "c"(new_y), "d"(new_w),"S"(new_h)
  126.         );
  127. }
  128.  
  129. /*********************** Other GUI functions *************************/
  130. static inline void kos_DrawText(int x, int y, const char *text, color_t color) {
  131.         __asm__ __volatile__(
  132.         "int $0x40"
  133.         ::"a"(4),"d"(text),
  134.           "b"((x << 16) | y),
  135.           "S"(strlen(text)),"c"(color)
  136.          :"memory");
  137. }
  138.  
  139. static inline void kos_DrawButton(int x, int y, int w, int h, int id, color_t color) {
  140.         __asm__ __volatile__(
  141.         "int $0x40"
  142.         ::"a"(8),
  143.           "b"(x * 65536 + w),
  144.           "c"(y * 65536 + h),
  145.           "d"(id),
  146.           "S"(color));
  147. };
  148.  
  149. static inline void kos_DrawButtonWithText(int x, int y, int w, int h, int id, color_t color, const char* text) {
  150.         kos_DrawButton(x, y, w, h, id, color);
  151.  
  152.         int tx = ((((-strlen(text))*8)+w)/2)+x;
  153.         int ty = h/2-7+y;
  154.  
  155.         kos_DrawText(tx, ty, text, 0x90000000);
  156. };
  157.  
  158. static inline void kos_DrawLine(int x_start, int y_start, int x_end, int y_end, color_t color) {
  159.         __asm__ __volatile__(
  160.         "int $0x40"
  161.         ::"a"(38), "d"(color),
  162.           "b"((x_start << 16) | x_end),
  163.           "c"((y_start << 16) | y_end));
  164. }
  165.  
  166. static inline void kos_DrawBar(int x, int y, int w, int h, color_t color) {
  167.         __asm__ __volatile__(
  168.         "int $0x40"
  169.         ::"a"(13), "d"(color),
  170.           "b"((x << 16) | w),
  171.           "c"((y << 16) | h));
  172. }
  173.  
  174. static inline void kos_PutPixel(int x, int y, color_t color) {
  175.         __asm__ __volatile__("int $0x40"
  176.                          ::"a"(1),
  177.                           "b"(x),
  178.                           "c"(y),
  179.                           "d"(color));
  180. }
  181.  
  182. static inline void kos_DrawBitmap(void *bitmap, int x, int y, int w, int h) {
  183.         __asm__ __volatile__(
  184.         "int $0x40"
  185.         ::"a"(7), "b"(bitmap),
  186.           "c"((w << 16) | h),
  187.           "d"((x << 16) | y));
  188. }
  189.  
  190. static inline void Blit(void *bitmap, int dst_x, int dst_y,
  191.                                                 int src_x, int src_y, int w, int h,
  192.                                                 int src_w, int src_h, int stride)
  193. {
  194.         volatile struct blit_call bc;
  195.  
  196.         bc.dstx = dst_x;
  197.         bc.dsty = dst_y;
  198.         bc.w    = w;
  199.         bc.h    = h;
  200.         bc.srcx = src_x;
  201.         bc.srcy = src_y;
  202.         bc.srcw = src_w;
  203.         bc.srch = src_h;
  204.         bc.stride = stride;
  205.         bc.bitmap = bitmap;
  206.  
  207.         __asm__ __volatile__(
  208.         "int $0x40"
  209.         ::"a"(73),"b"(0),"c"(&bc.dstx));
  210. };
  211.  
  212. // Get screen part as image
  213. static inline void kos_ScreenShot(char* image, int x, int y, int w, int h) {
  214.         __asm__ __volatile__(
  215.         "int $0x40"
  216.         ::"a"(36),
  217.          "b"(image),
  218.          "c"(w*65536+h),
  219.          "d"(x*65536+y) : "memory");
  220. };
  221.  
  222. /*********************** Skin *************************/
  223. // Get skin height
  224. static inline uint32_t kos_SkinHeight(void) {
  225.         uint32_t height;
  226.  
  227.         __asm__ __volatile__(
  228.         "int $0x40 \n\t"
  229.         :"=a"(height)
  230.         :"a"(48),"b"(4));
  231.         return height;
  232. };
  233.  
  234. /*********************** Mouse *************************/
  235. #define POS_SCREEN 0
  236. #define POS_WINDOW 1
  237.  
  238. static inline pos_t kos_GetMousePos(int origin) {
  239.         pos_t val;
  240.         __asm__ __volatile__(
  241.         "int $0x40 \n\t"
  242.         "rol $16, %%eax"
  243.         :"=a"(val)
  244.         :"a"(37),"b"(origin));
  245.         return val;
  246. }
  247.  
  248. static inline uint32_t kos_GetMouseButtons(void) {
  249.         uint32_t val;
  250.  
  251.         __asm__ __volatile__(
  252.         "int $0x40"
  253.         :"=a"(val)
  254.         :"a"(37),"b"(2));
  255.         return val;
  256. };
  257.  
  258. static inline uint32_t kos_GetMouseWheels(void) {
  259.         uint32_t val;
  260.  
  261.         __asm__ __volatile__(
  262.         "int $0x40 \n\t"
  263.         :"=a"(val)
  264.         :"a"(37),"b"(7));
  265.         return val;
  266. };
  267.  
  268. static inline uint32_t kos_LoadCursor(void *path, uint32_t flags) {
  269.         uint32_t  val;
  270.         __asm__ __volatile__(
  271.         "int $0x40"
  272.         :"=a"(val)
  273.         :"a"(37), "b"(4), "c"(path), "d"(flags));
  274.         return val;
  275. }
  276.  
  277. static inline uint32_t kos_SetCursor(uint32_t cursor) {
  278.         uint32_t  old;
  279.         __asm__ __volatile__(
  280.         "int $0x40"
  281.         :"=a"(old)
  282.         :"a"(37), "b"(5), "c"(cursor));
  283.         return old;
  284. };
  285.  
  286. static inline int kos_DestroyCursor(uint32_t cursor) {
  287.         int ret;
  288.         __asm__ __volatile__(
  289.         "int $0x40"
  290.         :"=a"(ret)
  291.         :"a"(37), "b"(6), "c"(cursor)
  292.         :"memory");
  293.         return ret;
  294. };
  295.  
  296. /*********************** OS Events *************************/
  297. #define evReDraw  1
  298. #define evKey     2
  299. #define evButton  3
  300. #define evExit    4
  301. #define evDesktop 5
  302. #define evMouse   6
  303. #define evIPC     7
  304. #define evNetwork 8
  305. #define evDebug   9
  306.  
  307. static inline uint32_t kos_WaitForEventTimeout(uint32_t time) {
  308.         uint32_t val;
  309.         __asm__ __volatile__(
  310.         "int $0x40"
  311.         :"=a"(val)
  312.         :"a"(23), "b"(time));
  313.         return val;
  314. };
  315.  
  316. static inline uint32_t kos_CheckForEvent(void) {
  317.         uint32_t val;
  318.         __asm__ __volatile__(
  319.         "int $0x40"
  320.         :"=a"(val)
  321.         :"a"(11));
  322.         return val;
  323. };
  324.  
  325. static inline uint32_t kos_WaitForEvent(void) {
  326.         uint32_t val;
  327.         __asm__ __volatile__(
  328.         "int $0x40"
  329.         :"=a"(val)
  330.         :"a"(10));
  331.         return val;
  332. };
  333.  
  334. /*********************** Eventmask *************************/
  335. #define EVM_REDRAW        1
  336. #define EVM_KEY           2
  337. #define EVM_BUTTON        4
  338. #define EVM_EXIT          8
  339. #define EVM_BACKGROUND    16
  340. #define EVM_MOUSE         32
  341. #define EVM_IPC           64
  342. #define EVM_STACK         128
  343. #define EVM_DEBUG         256
  344. #define EVM_STACK2        512
  345. #define EVM_MOUSE_FILTER  0x80000000
  346. #define EVM_CURSOR_FILTER 0x40000000
  347.  
  348. static inline uint32_t kos_SetMaskForEvents(uint32_t event_mask) {
  349.         uint32_t  old_event_mask;
  350.         __asm__ __volatile__(
  351.         "int $0x40"
  352.         :"=a"(old_event_mask)
  353.         :"a"(40),"b"(event_mask));
  354.  
  355.         return old_event_mask;
  356. };
  357.  
  358. /*********************** Other *************************/
  359. static inline int kos_GetKey() {
  360.         unsigned short key;
  361.         __asm__ __volatile__("int $0x40":"=a"(key):"0"(2));
  362.         if(!(key & 0xFF)) return (key>>8)&0xFF; else return 0;
  363. }
  364.  
  365. static inline uint32_t kos_GetButtonID(void) {
  366.         uint32_t val;
  367.         __asm__ __volatile__(
  368.         "int $0x40"
  369.         :"=a"(val)
  370.         :"a"(17));
  371.         return val>>8;
  372. };
  373.  
  374. static inline void kos_Delay(uint32_t time) {
  375.         __asm__ __volatile__(
  376.         "int $0x40"
  377.         ::"a"(5), "b"(time)
  378.         :"memory");
  379. };
  380.  
  381. static inline pos_t kos_ScreenSize() {
  382.         pos_t size;
  383.         __asm__ __volatile__(
  384.         "int $0x40"
  385.         :"=a"(size)
  386.         :"a"(14));
  387.  
  388.         return size;
  389. };
  390.  
  391. static inline void kos_GetSystemColors(struct kolibri_system_colors *color_table) {
  392.         __asm__ __volatile__ ("int $0x40"
  393.         :
  394.         :"a"(48),"b"(3),"c"(color_table),"d"(40)
  395.         );
  396. }
  397.  
  398. // sysfn 9
  399. static inline void kos_ProcessInfo(char *info) {
  400.         __asm__ __volatile__(
  401.         "int $0x40"
  402.         :
  403.         :"a"(9), "b"(info), "c"(-1)
  404.         :"memory");
  405. };
  406.  
  407. static inline void kos_RunApp(char* app, char* param) {
  408.         kos_Struct70 r;
  409.         r.p00 = 7;
  410.         r.p04 = 0;
  411.         r.p08 = param;
  412.         r.p12 = 0;
  413.         r.p16 = 0;
  414.         r.p20 = 0;
  415.         r.p21 = app;
  416.         __asm__ __volatile__ ("int $0x40"::"a"(70), "b"(&r));
  417. }
  418.  
  419.