Subversion Repositories Kolibri OS

Rev

Rev 8695 | Rev 9124 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
8596 turbocat 1
#include 
8655 turbocat 2
#include 
8664 turbocat 3
#include 
8655 turbocat 4
 
8695 turbocat 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
    );
117
    size.x = size_tmp.y;
118
    size.y = size_tmp.x;
119
    return size;
120
}
121
 
8664 turbocat 122
void *memrchr(const void *m, int c, size_t n)
123
{
124
	const unsigned char *s = (const unsigned char*)m;
125
	c = (unsigned char)c;
126
	while (n--) if (s[n]==c) return (void *)(s+n);
127
	return 0;
128
}
129
 
8596 turbocat 130
void kolibri_set_win_center()
131
{
8655 turbocat 132
    ksys_proc_table_t *info = (ksys_proc_table_t*)malloc(sizeof(ksys_proc_table_t));
133
    _ksys_process_info(info, -1);
134
 
135
    ksys_pos_t screen_size= _ksys_screen_size();
136
    int new_x = screen_size.x/2-info->winx_size/2;
137
    int new_y = screen_size.y/2-info->winy_size/2;
138
    _ksys_change_window(new_x, new_y, -1, -1);
8596 turbocat 139
    free(info);
140
}
8655 turbocat 141
 
8695 turbocat 142
int mkdir(const char *path, unsigned v)
8655 turbocat 143
{
8695 turbocat 144
    int status;
145
    ksys70_t dir_opt;
146
    dir_opt.p00 = 9;
147
    dir_opt.p21 = path;
148
    asm_inline(
149
        "int $0x40"
150
        :"=a"(status)
151
        :"a"(70), "b"(&dir_opt)
152
        :"memory"
153
    );
154
    return status;
8655 turbocat 155
}
156
 
8664 turbocat 157
char *dirname (char *path)
158
{
159
  static const char dot[] = ".";
160
  char *last_slash;
161
  /* Find last '/'.  */
162
  last_slash = path != NULL ? strrchr (path, '/') : NULL;
163
  if (last_slash != NULL && last_slash != path && last_slash[1] == '\0')
164
    {
165
      /* Determine whether all remaining characters are slashes.  */
166
      char *runp;
167
      for (runp = last_slash; runp != path; --runp)
168
        if (runp[-1] != '/')
169
          break;
170
      /* The '/' is the last character, we have to look further.  */
171
      if (runp != path)
172
        last_slash = (char*)memrchr((void*)path, '/', runp - path);
173
    }
174
  if (last_slash != NULL)
175
    {
176
      /* Determine whether all remaining characters are slashes.  */
177
      char *runp;
178
      for (runp = last_slash; runp != path; --runp)
179
        if (runp[-1] != '/')
180
          break;
181
      /* Terminate the path.  */
182
      if (runp == path)
183
        {
184
          /* The last slash is the first character in the string.  We have to
185
             return "/".  As a special case we have to return "//" if there
186
             are exactly two slashes at the beginning of the string.  See
187
             XBD 4.10 Path Name Resolution for more information.  */
188
          if (last_slash == path + 1)
189
            ++last_slash;
190
          else
191
            last_slash = path + 1;
192
        }
193
      else
194
        last_slash = runp;
195
      last_slash[0] = '\0';
196
    }
197
  else
198
    /* This assignment is ill-designed but the XPG specs require to
199
       return a string containing "." in any case no directory part is
200
       found and so a static and constant string is required.  */
201
    path = (char *) dot;
202
  return path;
203
}
204
 
205
void setcwd(char* path){
8695 turbocat 206
    asm_inline(
207
        "int $0x40"
208
        ::"a"(30), "b"(1), "c"(path)
209
    );
8664 turbocat 210
}
9097 turbocat 211