VaneOSのメインGitリポジトリです。
リビジョン | 4c94eb3d98bb038a6741caedcaff32087069e4f2 (tree) |
---|---|
日時 | 2014-10-19 15:38:28 |
作者 | ![]() |
コミッター | vosystems |
時間取得関数作成
@@ -2,6 +2,7 @@ | ||
2 | 2 | *System Functions |
3 | 3 | *(C) 2014 VOSystems. |
4 | 4 | */ |
5 | +#include <stdio.h> | |
5 | 6 | |
6 | 7 | int vram_start_address; |
7 | 8 | char vmode; |
@@ -56,3 +57,34 @@ void init_qemuvga0(int x, int y, int c, int flag) | ||
56 | 57 | } |
57 | 58 | return; |
58 | 59 | } |
60 | + | |
61 | +void readrtc(unsigned char *t) | |
62 | +{ | |
63 | + char err; | |
64 | + static unsigned char adr[7] = { 0x00, 0x02, 0x04, 0x07, 0x08, 0x09, 0x32 }; | |
65 | + static unsigned char max[7] = { 0x60, 0x59, 0x23, 0x31, 0x12, 0x99, 0x99 }; | |
66 | + int i; | |
67 | + for (;;) { /* 読み込みが成功するまで繰り返す */ | |
68 | + err = 0; | |
69 | + for (i = 0; i < 7; i++) { | |
70 | + io_out8(0x70, adr[i]); | |
71 | + t[i] = io_in8(0x71); | |
72 | + } | |
73 | + for (i = 0; i < 7; i++) { | |
74 | + io_out8(0x70, adr[i]); | |
75 | + if (t[i] != io_in8(0x71) || (t[i] & 0x0f) > 9 || t[i] > max[i]) { | |
76 | + err = 1; | |
77 | + } | |
78 | + } | |
79 | + if (err == 0) { | |
80 | + return; | |
81 | + } | |
82 | + } | |
83 | +} | |
84 | + | |
85 | +void printtime(void) | |
86 | +{ | |
87 | + unsigned char s[24], t[7]; | |
88 | + readrtc(t); | |
89 | + printf("\r%X%X/%X/%X %X:%X:%X", t[6], t[5], t[4], t[3], t[2], t[1], t[0]); | |
90 | +} |
@@ -24,6 +24,7 @@ | ||
24 | 24 | #include<Graphic.h> |
25 | 25 | #include<Message.h> |
26 | 26 | #include<timer.h> |
27 | +#include<System.h> | |
27 | 28 | |
28 | 29 | /*PROTOTYPE*/ |
29 | 30 | void outPortByte( unsigned short address, unsigned char value ); |
@@ -129,11 +130,26 @@ void cstart(unsigned long magic, unsigned long addr) | ||
129 | 130 | |
130 | 131 | printf("Free Memory = %d MiB\n\n",memman_total(memman)/(1024*1024)); |
131 | 132 | |
133 | + int in=0; | |
134 | + while(in!='q'){ | |
135 | + printtime(); | |
136 | + if(kbhit()=='q')break; | |
137 | + io_hlt(); | |
138 | + } | |
139 | + putchar('\n'); | |
140 | + | |
132 | 141 | puts("KernelShell/Root/>"); |
133 | 142 | scanf("%s",&cmd); |
134 | - printf("%s",cmd); | |
135 | - | |
136 | - while(1); | |
143 | + if(strcmp("time",cmd)==0){ | |
144 | + int in=0; | |
145 | + while(in!='q'){ | |
146 | + printtime(); | |
147 | + if(kbhit()!=0)in=getch(); | |
148 | + io_hlt(); | |
149 | + } | |
150 | + } | |
151 | + printf("%d %d %d",strcmp("time",cmd),strcmp("time\0",cmd),strcmp("time\n",cmd)); | |
152 | + while(1)io_hlt(); | |
137 | 153 | return; |
138 | 154 | } |
139 | 155 |
@@ -26,6 +26,10 @@ unsigned short* screen; | ||
26 | 26 | char attr; |
27 | 27 | unsigned int X,Y; |
28 | 28 | |
29 | +int kbhit(void) | |
30 | +{ | |
31 | + return Generate_Scancode_To_ASCII_Code(); | |
32 | +} | |
29 | 33 | void scanf(const char* fmt,...) |
30 | 34 | { |
31 | 35 | va_list arg; |
@@ -104,18 +108,22 @@ void scanf(const char* fmt,...) | ||
104 | 108 | putchar(*cmd); |
105 | 109 | *cmd='\0'; |
106 | 110 | break; |
111 | + | |
107 | 112 | }else if(*cmd==' '){ |
108 | 113 | putchar(' '); |
109 | 114 | *cmd='\0'; |
110 | 115 | break; |
116 | + | |
111 | 117 | }else if(*cmd=='\b' && count>0){ |
112 | 118 | *cmd-- = '\0'; |
113 | 119 | count--; |
114 | 120 | putchar('\b'); |
121 | + | |
115 | 122 | }else{ |
116 | 123 | putchar(*cmd); |
117 | 124 | count++; |
118 | 125 | cmd++; |
126 | + | |
119 | 127 | } |
120 | 128 | }while(1); |
121 | 129 |
@@ -187,7 +195,7 @@ void putchar(const char ch) | ||
187 | 195 | X+=2; |
188 | 196 | |
189 | 197 | }else if(ch=='\r'){ |
190 | - while(X>=0) | |
198 | + while(X>0) | |
191 | 199 | { |
192 | 200 | *screen-- = (unsigned short)NUM_NULL; |
193 | 201 | --X; |
@@ -269,7 +277,7 @@ void printINFO(const char* msg) | ||
269 | 277 | return; |
270 | 278 | } |
271 | 279 | |
272 | -char * uint_to_str(char *buf, unsigned src, int base) { | |
280 | +char * uint_to_str_big_hex(char *buf, unsigned src, int base) { | |
273 | 281 | char *p = buf; |
274 | 282 | char *p1, *p2; |
275 | 283 |
@@ -290,46 +298,25 @@ char * uint_to_str(char *buf, unsigned src, int base) { | ||
290 | 298 | return buf; |
291 | 299 | } |
292 | 300 | |
293 | -void sprintf(char* s,char* fmt,...) | |
294 | -{ | |
295 | - char **arg = (char **) &fmt; | |
296 | - char c; | |
297 | - arg++; | |
301 | +char * uint_to_str_small_hex(char *buf, unsigned src, int base) { | |
302 | + char *p = buf; | |
303 | + char *p1, *p2; | |
298 | 304 | |
299 | - while((c = *fmt++) != 0) { | |
300 | - if(c != '%'){ | |
301 | - *s++ =c; | |
302 | - | |
303 | - }else{ | |
304 | - char buf[64]; | |
305 | - char *p; | |
306 | - c = *fmt++; | |
307 | - | |
308 | - if(c=='d'){ | |
309 | - // if value is minus, put '-' in the head | |
310 | - if( 0 > *((int *) arg) ) { | |
311 | - *s++ ='-'; | |
312 | - *((int *) arg) *= -1; | |
313 | - } | |
314 | - p = uint_to_str(buf, *((unsigned *) arg++), 10); | |
315 | - strcpy(s,p); | |
316 | - | |
317 | - }else if(c=='x'){ | |
318 | - p = uint_to_str(buf, *((unsigned *) arg++), 16); | |
319 | - strcpy(s,p); | |
320 | - | |
321 | - }else if(c=='s'){ | |
322 | - p = *arg++; | |
323 | - puts(p); | |
324 | - }else if(c=='c'){ | |
325 | - p=*arg++; | |
326 | - char send=*p; | |
327 | - putchar(send); | |
328 | - }else{ | |
329 | - putchar(c); | |
330 | - } | |
331 | - } | |
332 | - } | |
305 | + do { | |
306 | + *p++ = "0123456789abcdef"[src%base]; | |
307 | + } while(src /= base); | |
308 | + | |
309 | + // Terminate BUF | |
310 | + *p = 0; | |
311 | + | |
312 | + // Reverse BUF | |
313 | + for(p1=buf, p2=p-1; p1 < p2; p1++, p2--) { | |
314 | + char tmp = *p1; | |
315 | + *p1 = *p2; | |
316 | + *p2 = tmp; | |
317 | + } | |
318 | + | |
319 | + return buf; | |
333 | 320 | } |
334 | 321 | |
335 | 322 | void printf(char* fmt, ...) |
@@ -353,11 +340,15 @@ void printf(char* fmt, ...) | ||
353 | 340 | putchar('-'); |
354 | 341 | *((int *) arg) *= -1; |
355 | 342 | } |
356 | - p = uint_to_str(buf, *((unsigned *) arg++), 10); | |
343 | + p = uint_to_str_small_hex(buf, *((unsigned *) arg++), 10); | |
357 | 344 | puts(p); |
358 | 345 | |
359 | 346 | }else if(c=='x'){ |
360 | - p = uint_to_str(buf, *((unsigned *) arg++), 16); | |
347 | + p = uint_to_str_small_hex(buf, *((unsigned *) arg++), 16); | |
348 | + puts(p); | |
349 | + | |
350 | + }else if(c=='X'){ | |
351 | + p = uint_to_str_big_hex(buf, *((unsigned *) arg++), 16); | |
361 | 352 | puts(p); |
362 | 353 | |
363 | 354 | }else if(c=='s'){ |
@@ -2,7 +2,7 @@ | ||
2 | 2 | |
3 | 3 | */ |
4 | 4 | #include<string.h> |
5 | - | |
5 | +/* | |
6 | 6 | int strcmp(const char* ch1,const char* ch2) |
7 | 7 | { |
8 | 8 | while(*ch1==*ch2) |
@@ -18,6 +18,25 @@ int strcmp(const char* ch1,const char* ch2) | ||
18 | 18 | } |
19 | 19 | return 1; |
20 | 20 | } |
21 | +*//* | |
22 | +int strcmp(const char *s1, const char *s2) | |
23 | +{ | |
24 | + register const unsigned char *ss1, *ss2; | |
25 | + for (ss1 = (const unsigned char*)s1, ss2 = (const unsigned char*)s2; *ss1 == *ss2 && *ss1 != '\0'; ss1++, ss2++); | |
26 | + return *ss1 - *ss2; | |
27 | +} | |
28 | +*/ | |
29 | +int strcmp(const char *s1, const char *s2) | |
30 | +{ | |
31 | + while (*s1 == *s2++) | |
32 | + { | |
33 | + if (*s1++ == 0) | |
34 | + { | |
35 | + return 0; | |
36 | + } | |
37 | + } | |
38 | + return *(unsigned char *)s1 - *(unsigned char *)--s2; | |
39 | +} | |
21 | 40 | |
22 | 41 | void strcpy(char* copy,const char* source) |
23 | 42 | { |
@@ -46,5 +46,6 @@ void ClearScreen(void); | ||
46 | 46 | void puts(const char* msg); |
47 | 47 | void putchar(const char); |
48 | 48 | void printOK(const char* msg); |
49 | +int kbhit(void); | |
49 | 50 | |
50 | 51 | #endif |
@@ -30,9 +30,7 @@ extern unsigned int X,Y; | ||
30 | 30 | #define DOUBLE_BYTE 8 |
31 | 31 | #define FLOAT_BYTE 4 |
32 | 32 | |
33 | -#if (!defined(NULL)) | |
34 | - #define NULL ((void *) 0) | |
35 | -#endif | |
33 | +#define NULL ((void *) 0) | |
36 | 34 | |
37 | 35 | #define NUM_NULL 0 |
38 | 36 | /* |