Subversion Repositories Kolibri OS

Rev

Rev 9124 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 9124 Rev 9790
Line 1... Line 1...
1
#include 
1
#include 
2
#include 
2
#include 
3
#include 
3
#include 
Line 4... Line -...
4
 
-
 
5
#define asm_inline __asm__ __volatile__
-
 
6
 
-
 
7
#pragma pack(push,1)
-
 
8
typedef union{
-
 
9
    unsigned val;
-
 
10
    struct{
-
 
11
        short  x;
-
 
12
        short  y;
-
 
13
    };
-
 
14
}ksys_pos_t;
-
 
15
 
-
 
16
typedef union ksys_oskey_t{
-
 
17
    unsigned val;
-
 
18
    struct{
-
 
19
        unsigned char state;
-
 
20
        unsigned char code;
-
 
21
        unsigned char ctrl_key;
-
 
22
    };
-
 
23
}ksys_oskey_t;
-
 
24
 
-
 
25
typedef struct{
-
 
26
  unsigned     handle;
-
 
27
  unsigned     io_code;
-
 
28
  unsigned     *input;
-
 
29
  int          inp_size;
-
 
30
  void         *output;
-
 
31
  int          out_size;
-
 
32
}ksys_ioctl_t;
-
 
33
 
-
 
34
typedef struct{
-
 
35
    void *data;
-
 
36
    size_t size;
-
 
37
}ksys_ufile_t;
-
 
38
 
-
 
39
 
-
 
40
typedef struct{
-
 
41
    unsigned            p00;
-
 
42
    union{
-
 
43
        uint64_t        p04; 
-
 
44
        struct {
-
 
45
            unsigned    p04dw;
-
 
46
            unsigned    p08dw;
-
 
47
        };
-
 
48
    };
-
 
49
    unsigned            p12;
-
 
50
    union {
-
 
51
        unsigned        p16;
-
 
52
        const char     *new_name;
-
 
53
        void           *bdfe;
-
 
54
        void           *buf16;
-
 
55
        const void     *cbuf16;
-
 
56
    };
-
 
57
    char                p20;
-
 
58
    const char         *p21;
-
 
59
}ksys70_t;
-
 
60
 
-
 
61
typedef struct {
-
 
62
  int cpu_usage;             //+0
-
 
63
  int window_pos_info;       //+4
-
 
64
  short int reserved1;       //+8
-
 
65
  char name[12];             //+10
-
 
66
  int memstart;              //+22
-
 
67
  int memused;               //+26
-
 
68
  int pid;                   //+30
-
 
69
  int winx_start;            //+34
-
 
70
  int winy_start;            //+38
-
 
71
  int winx_size;             //+42
-
 
72
  int winy_size;             //+46
-
 
73
  short int slot_info;       //+50
-
 
74
  short int reserved2;       //+52
-
 
75
  int clientx;               //+54
-
 
76
  int clienty;               //+58
-
 
77
  int clientwidth;           //+62
-
 
78
  int clientheight;          //+66
-
 
79
  unsigned char window_state;//+70
-
 
80
  char reserved3[1024-71];   //+71
-
 
81
}ksys_proc_table_t;
-
 
82
 
-
 
83
#pragma pack(pop)
-
 
84
 
-
 
85
static inline 
-
 
86
int _ksys_process_info(ksys_proc_table_t* table, int pid)
-
 
87
{
-
 
88
    int val;
-
 
89
    asm_inline(
-
 
90
        "int $0x40"
-
 
91
        :"=a"(val)
-
 
92
        :"a"(9), "b"(table), "c"(pid)
-
 
93
        :"memory"
-
 
94
    );
-
 
95
    return val;
-
 
96
}
-
 
97
 
-
 
98
static inline
-
 
99
void _ksys_change_window(int new_x, int new_y, int new_w, int new_h)
-
 
100
{
-
 
101
    asm_inline(
-
 
102
        "int $0x40"
-
 
103
        ::"a"(67), "b"(new_x), "c"(new_y), "d"(new_w),"S"(new_h)
-
 
104
    );
-
 
105
}
-
 
106
 
-
 
107
static inline
-
 
108
ksys_pos_t _ksys_screen_size()
-
 
109
{
-
 
110
	ksys_pos_t size;
-
 
111
    ksys_pos_t size_tmp;
-
 
112
    asm_inline(
-
 
113
        "int $0x40"
-
 
114
        :"=a"(size_tmp)
-
 
115
        :"a"(14)
-
 
116
        :"memory"
-
 
117
    );
-
 
118
    size.x = size_tmp.y;
-
 
119
    size.y = size_tmp.x; 
-
 
120
    return size;
-
 
121
}
-
 
122
 
-
 
123
void *memrchr(const void *m, int c, size_t n)
-
 
124
{
-
 
125
	const unsigned char *s = (const unsigned char*)m;
-
 
126
	c = (unsigned char)c;
-
 
127
	while (n--) if (s[n]==c) return (void *)(s+n);
-
 
128
	return 0;
-
 
129
}
-
 
130
 
-
 
131
void kolibri_set_win_center()
-
 
132
{
-
 
133
    ksys_proc_table_t *info = (ksys_proc_table_t*)malloc(sizeof(ksys_proc_table_t));
-
 
134
    _ksys_process_info(info, -1);
-
 
135
 
-
 
136
    ksys_pos_t screen_size= _ksys_screen_size();
-
 
137
    int new_x = screen_size.x/2-info->winx_size/2;
-
 
138
    int new_y = screen_size.y/2-info->winy_size/2;
-
 
139
    _ksys_change_window(new_x, new_y, -1, -1); 
-
 
140
    free(info);
-
 
141
}
-
 
142
 
-
 
143
int mkdir(const char *path, unsigned v)
-
 
144
{
-
 
145
    int status;
-
 
146
    ksys70_t dir_opt;
-
 
147
    dir_opt.p00 = 9;
-
 
148
    dir_opt.p21 = path;
-
 
149
    asm_inline(
-
 
150
        "int $0x40"
-
 
151
        :"=a"(status)
-
 
152
        :"a"(70), "b"(&dir_opt)
-
 
153
        :"memory"
-
 
154
    );
-
 
155
    return status;
-
 
156
}
-
 
157
 
-
 
158
char *dirname (char *path)
-
 
159
{
-
 
160
  static const char dot[] = ".";
-
 
161
  char *last_slash;
-
 
162
  /* Find last '/'.  */
-
 
163
  last_slash = path != NULL ? strrchr (path, '/') : NULL;
-
 
164
  if (last_slash != NULL && last_slash != path && last_slash[1] == '\0')
-
 
165
    {
-
 
166
      /* Determine whether all remaining characters are slashes.  */
-
 
167
      char *runp;
-
 
168
      for (runp = last_slash; runp != path; --runp)
-
 
169
        if (runp[-1] != '/')
-
 
170
          break;
-
 
171
      /* The '/' is the last character, we have to look further.  */
-
 
172
      if (runp != path)
-
 
173
        last_slash = (char*)memrchr((void*)path, '/', runp - path);
-
 
174
    }
-
 
175
  if (last_slash != NULL)
-
 
176
    {
-
 
177
      /* Determine whether all remaining characters are slashes.  */
-
 
178
      char *runp;
-
 
179
      for (runp = last_slash; runp != path; --runp)
-
 
180
        if (runp[-1] != '/')
-
 
181
          break;
-
 
182
      /* Terminate the path.  */
-
 
183
      if (runp == path)
-
 
184
        {
-
 
185
          /* The last slash is the first character in the string.  We have to
-
 
186
             return "/".  As a special case we have to return "//" if there
-
 
187
             are exactly two slashes at the beginning of the string.  See
-
 
188
             XBD 4.10 Path Name Resolution for more information.  */
-
 
189
          if (last_slash == path + 1)
-
 
190
            ++last_slash;
-
 
191
          else
-
 
192
            last_slash = path + 1;
-
 
193
        }
-
 
194
      else
-
 
195
        last_slash = runp;
-
 
196
      last_slash[0] = '\0';
-
 
197
    }
-
 
198
  else
-
 
199
    /* This assignment is ill-designed but the XPG specs require to
-
 
200
       return a string containing "." in any case no directory part is
-
 
201
       found and so a static and constant string is required.  */
-
 
202
    path = (char *) dot;
-
 
203
  return path;
-
 
204
}
-
 
205
 
-
 
206
void setcwd(char* path){
-
 
207
    asm_inline(
-
 
208
        "int $0x40"
-
 
209
        ::"a"(30), "b"(1), "c"(path)
-
 
210
        :"memory"
-
 
211
    );
-
 
212
}
4
 
213
extern  unsigned screenWidth;
5
extern  unsigned screenWidth;
Line 214... Line 6...
214
extern  unsigned screenHeight; 
6
extern  unsigned screenHeight; 
215
 
7