Subversion Repositories Kolibri OS

Rev

Rev 9097 | 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)
9124 turbocat 116
        :"memory"
8695 turbocat 117
    );
118
    size.x = size_tmp.y;
119
    size.y = size_tmp.x;
120
    return size;
121
}
122
 
8664 turbocat 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
 
8596 turbocat 131
void kolibri_set_win_center()
132
{
8655 turbocat 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);
8596 turbocat 140
    free(info);
141
}
8655 turbocat 142
 
8695 turbocat 143
int mkdir(const char *path, unsigned v)
8655 turbocat 144
{
8695 turbocat 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;
8655 turbocat 156
}
157
 
8664 turbocat 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){
8695 turbocat 207
    asm_inline(
208
        "int $0x40"
209
        ::"a"(30), "b"(1), "c"(path)
9124 turbocat 210
        :"memory"
8695 turbocat 211
    );
8664 turbocat 212
}
9124 turbocat 213
extern  unsigned screenWidth;
214
extern  unsigned screenHeight;
9097 turbocat 215
 
9124 turbocat 216
void kolibri_set_win_max(void){
217
    unsigned multip1, multip2;
218
    ksys_pos_t screen_size = _ksys_screen_size();
219
 
220
    screen_size.y++;
221
    screen_size.x++;
222
 
223
    multip1 = (screen_size.y)/240;
224
    multip2 = (screen_size.y)/200;
225
 
226
    do{
227
        screenWidth =  320 * multip1;
228
        screenHeight = 240 * multip1;
229
 
230
        if(screenWidth<=screen_size.x){
231
            break;
232
        }
233
 
234
        screenWidth = 320 * multip2;
235
        screenHeight = 200 * multip2;
236
 
237
        if(screenWidth<=screen_size.y){
238
            break;
239
        }
240
 
241
        multip1--;
242
        multip2--;
243
 
244
    }while(multip1>0 && multip2>0);
245
}