diff options
author | lantw44 <lantw44@gmail.com> | 2013-01-16 22:51:47 +0800 |
---|---|---|
committer | lantw44 <lantw44@gmail.com> | 2013-01-16 22:56:52 +0800 |
commit | d16cda16bbc5f5d51cce15584014cccafbcf08da (patch) | |
tree | 4d9e3da654e19af3c0e58926828468b1f37a2393 | |
parent | 8e1dce540d5f60eec5ed631af93f4031cd20205e (diff) | |
download | yotos-d16cda16bbc5f5d51cce15584014cccafbcf08da.tar yotos-d16cda16bbc5f5d51cce15584014cccafbcf08da.tar.gz yotos-d16cda16bbc5f5d51cce15584014cccafbcf08da.tar.bz2 yotos-d16cda16bbc5f5d51cce15584014cccafbcf08da.tar.lz yotos-d16cda16bbc5f5d51cce15584014cccafbcf08da.tar.xz yotos-d16cda16bbc5f5d51cce15584014cccafbcf08da.tar.zst yotos-d16cda16bbc5f5d51cce15584014cccafbcf08da.zip |
yotsh 已有設定、讀取記憶體、關機功能,yotrl() 與 getstr() 加入彩色功能
-rw-r--r-- | .gitignore | 4 | ||||
-rw-r--r-- | yotlibc/Makefile | 2 | ||||
-rw-r--r-- | yotlibc/char_vga.s | 3 | ||||
-rw-r--r-- | yotlibc/str_in.c | 52 | ||||
-rw-r--r-- | yotlibc/strbasic.c | 71 | ||||
-rw-r--r-- | yotlibc/yotlibc.h | 9 | ||||
-rw-r--r-- | yotsh.c | 156 |
7 files changed, 228 insertions, 69 deletions
@@ -1,8 +1,10 @@ *.a *.o *.img +*.swp +*.swo +tags 55aa bootsect kernel yotsh - diff --git a/yotlibc/Makefile b/yotlibc/Makefile index ebdc45c..90189f9 100644 --- a/yotlibc/Makefile +++ b/yotlibc/Makefile @@ -2,7 +2,7 @@ .PHONY: all clean .SUFFIXES: .c.o .s.o -OBJ=bccfunc.o str_out.o char_in.o str_in.o char_vga.o char_vhl.o +OBJ=bccfunc.o str_out.o char_in.o str_in.o char_vga.o char_vhl.o strbasic.o all: yotlibc.a diff --git a/yotlibc/char_vga.s b/yotlibc/char_vga.s index 6ac1c20..2a2b1c0 100644 --- a/yotlibc/char_vga.s +++ b/yotlibc/char_vga.s @@ -72,8 +72,7 @@ _char_vga_tobios: mov cx, bx ; preserve bx - mov ah, 0x0f - int 0x10 ; bh is set by int 0x10, ah=0x0f + mov bh, 0x00 mov dl, [_char_vga_cursor_x] mov dh, [_char_vga_cursor_y] mov ah, 0x02 diff --git a/yotlibc/str_in.c b/yotlibc/str_in.c index 529b7ab..6f71791 100644 --- a/yotlibc/str_in.c +++ b/yotlibc/str_in.c @@ -1,8 +1,9 @@ #include "yotlibc.h" -int getstr(dest, maxlen) +int getstr(dest, maxlen, color) char* dest; int maxlen; + int color; { int c, cascii, cscan; int i = 0, j; @@ -18,15 +19,19 @@ int getstr(dest, maxlen) if(cascii >= 32 && cascii < 128){ if(i < maxlen){ dest[i++] = cascii; - chv_putchar(cascii); + chv_putchar_color(cascii, color); chv_sync_cursor(); } }else{ switch(cscan){ case KEYDOWN_SCANCODE_ENTER: dest[i++] = '\0'; - char_vga_cursor_y++; - char_vga_cursor_x = 0; + if(char_vga_cursor_y + 1 >= CHAR_VGA_SCREENY){ + char_vga_cursor_y = CHAR_VGA_SCREENY - 1; + chv_scroll(1); + }else{ + char_vga_cursor_y++; + } chv_sync_cursor(); char_vga_tobios(); return i; @@ -41,7 +46,7 @@ int getstr(dest, maxlen) case KEYDOWN_SCANCODE_ESC: chv_move_cursor(-i); for(j=0; j<i; j++){ - chv_putchar(' '); + chv_putchar_color(' ', color); } chv_move_cursor(-i); chv_sync_cursor(); @@ -54,10 +59,11 @@ int getstr(dest, maxlen) return 0; } -int yotrl(dest, init, maxlen) +int yotrl(dest, init, maxlen, color) char* dest; char* init; int maxlen; + int color; { int c, cascii, cscan; int pos = 0, nowlen = 0, i; @@ -77,7 +83,7 @@ int yotrl(dest, init, maxlen) dest[i] = '\0'; pos = i, nowlen = i; for(ip = dest; *ip != '\0'; ip++){ - chv_putchar(*ip); + chv_putchar_color(*ip, color); } } @@ -93,7 +99,7 @@ int yotrl(dest, init, maxlen) if(pos == nowlen){ dest[pos++] = cascii; nowlen++; - chv_putchar(cascii); + chv_putchar_color(cascii, color); chv_sync_cursor(); }else{ xy.x = char_vga_cursor_x; @@ -102,10 +108,10 @@ int yotrl(dest, init, maxlen) dest[i] = dest[i-1]; } dest[pos] = cascii; - chv_putchar(cascii); + chv_putchar_color(cascii, color); nowlen++, pos++; for(i=pos; i<nowlen; i++){ - chv_putchar(dest[i]); + chv_putchar_color(dest[i], color); } char_vga_cursor_x = xy.x; char_vga_cursor_y = xy.y; @@ -117,7 +123,11 @@ int yotrl(dest, init, maxlen) switch(cscan){ case KEYDOWN_SCANCODE_ENTER: dest[nowlen++] = '\0'; - char_vga_cursor_y++; + if(++char_vga_cursor_y >= CHAR_VGA_SCREENY){ + char_vga_cursor_y--; + chv_scroll(1); + char_vga_cursor_y++; + } char_vga_cursor_x = 0; chv_sync_cursor(); char_vga_tobios(); @@ -154,9 +164,9 @@ int yotrl(dest, init, maxlen) } pos--, nowlen--; for(i=pos; i<nowlen; i++){ - chv_putchar(dest[i]); + chv_putchar_color(dest[i], color); } - chv_putchar(' '); + chv_putchar_color(' ', color); char_vga_cursor_x = xy.x; char_vga_cursor_y = xy.y; chv_sync_cursor(); @@ -173,9 +183,9 @@ int yotrl(dest, init, maxlen) } nowlen--; for(i=pos; i<nowlen; i++){ - chv_putchar(dest[i]); + chv_putchar_color(dest[i], color); } - chv_putchar(' '); + chv_putchar_color(' ', color); char_vga_cursor_x = xy.x; char_vga_cursor_y = xy.y; chv_sync_cursor(); @@ -200,7 +210,7 @@ int yotrl(dest, init, maxlen) case 3: /* Ctrl+C */ chv_move_cursor(-pos); for(i=0; i<nowlen; i++){ - chv_putchar(' '); + chv_putchar_color(' ', color); } chv_move_cursor(-nowlen); chv_sync_cursor(); @@ -216,7 +226,7 @@ int yotrl(dest, init, maxlen) xy.x = char_vga_cursor_x; xy.y = char_vga_cursor_y; for(i=0; i<blank; i++){ - chv_putchar(' '); + chv_putchar_color(' ', color); } nowlen = pos; char_vga_cursor_x = xy.x; @@ -234,10 +244,10 @@ int yotrl(dest, init, maxlen) pos = 0; nowlen -= blank; for(i=0; i<nowlen; i++){ - chv_putchar(dest[i]); + chv_putchar_color(dest[i], color); } for(i=0; i<blank; i++){ - chv_putchar(' '); + chv_putchar_color(' ', color); } char_vga_cursor_x = xy.x; char_vga_cursor_y = xy.y; @@ -263,10 +273,10 @@ int yotrl(dest, init, maxlen) xy.x = char_vga_cursor_x; xy.y = char_vga_cursor_y; for(i=pos; i<nowlen; i++){ - chv_putchar(dest[i]); + chv_putchar_color(dest[i], color); } for(i=0; i<blank; i++){ - chv_putchar(' '); + chv_putchar_color(' ', color); } char_vga_cursor_x = xy.x; char_vga_cursor_y = xy.y; diff --git a/yotlibc/strbasic.c b/yotlibc/strbasic.c new file mode 100644 index 0000000..c73757a --- /dev/null +++ b/yotlibc/strbasic.c @@ -0,0 +1,71 @@ +#include "yotlibc.h" + +int strcmp(s1, s2) + char* s1; + char* s2; +{ + char* str1; + char* str2; + if((*s1 | *s2) && (!*s1 || !*s2)){ + if(*s1){ + return 1; + }else{ + return -1; + } + } + for(str1=s1, str2=s2; *str1 != '\0' && *str2 != '\0'; str1++, str2++){ + if(*str1 > *str2){ + return 2; + }else if(*str1 < *str2){ + return -2; + } + } + if(*str1 != '\0'){ + return 3; + } + if(*str2 != '\0'){ + return -3; + } + return 0; +} + +int strtos(str, store) + char* str; + unsigned int* store; +{ + unsigned int result = 0; + bool ishex = false; + if(*str == '0' && (*(str+1) == 'x' || *(str+1) == 'X')){ + str += 2; + ishex = true; + } + for(; *str != '\0'; str++){ + if(*str >= '0' && *str <= '9'){ + if(ishex){ + result <<= 4; + result += *str - '0'; + }else{ + result *= 10; + result += *str - '0'; + } + }else if(*str >= 'A' && *str <= 'F'){ + if(ishex){ + result <<= 4; + result += *str - 'A' + 10; + }else{ + return 0; + } + }else if(*str >= 'a' && *str <= 'f'){ + if(ishex){ + result <<= 4; + result += *str - 'a' + 10; + }else{ + return 0; + } + }else{ + return 0; /* Failed */ + } + } + *store = result; + return 1; /* OK */ +} diff --git a/yotlibc/yotlibc.h b/yotlibc/yotlibc.h index 1d9e5ca..4a1e6a3 100644 --- a/yotlibc/yotlibc.h +++ b/yotlibc/yotlibc.h @@ -140,14 +140,19 @@ void char_vga_tobios(void); #define KEYDOWN_SCANCODE_KEYPAD_DOT 0x53 /* str_in.c */ -int getstr(char*, int); +int getstr(char*, int, int); /* 讀入一行的函式 * ARG1 = 要存到哪裡 * ARG2 = 最多可以讀多長('\0' 不計入,但要自行保留空間) * RVAL = 實際讀了幾個字 */ -int yotrl(char*, const char*, int); +int yotrl(char*, const char*, int, int); /* 同上,但是是進階版 */ + +/* strbasic.c */ +int strcmp(const char*, const char*); +int strtos(const char*, unsigned int*); + #endif @@ -1,49 +1,121 @@ #include <yotlibc.h> +#define CMDMAX 256 + +#define YOTSH_ENABLED(n) ((ctrlflag)&(n)) +#define YOTSH_AUTOCOPY 0x0001 +#define YOTSH_COUNTER 0x0002 -short rval = 8; -short abc[100]; int main(void){ - XYCOORD xys; - short k; + int cmdcount; + int ctrlflag; + char cmdline[CMDMAX]; + char argcopy[CMDMAX]; + char *cp1, *cp2; + bool end; + unsigned out; extern int char_vga_cursor_x; extern int char_vga_cursor_y; - int i; -// xys.x = 1; -// xys.y = 1; -// chv_set_cursor(&xys); -// char_vga_tobios(); -// putint(char_vga_cursor_x); -// putint(char_vga_cursor_y); - chv_init_cursor(); - chv_memwrite(5, 4); - xys.y = 23; - xys.x = 4; - chv_set_cursor(&xys); - putint(char_vga_cursor_y); - for(i=0; i<9; i++){ - chv_putchar('F'); - } - chv_sync_cursor(); - yotrl(abc, "", 99); - putstr(abc); -// chv_putchar_color('A', CHV_COLORPAIR(CHV_COLOR_GREEN, CHV_COLOR_GRAY)); -// chv_backspace(); -// chv_scroll(25); -// chv_clear(); -// chv_reset_cursor(); -// chv_sync_cursor(); -// chv_putchar('A'); -// char_vga_tobios(); -// putint(22); -// putint(chv_memread(5)); -// putstr("PPP"); - //putstr("KKK:"); - /*while(1){ - int a = getch(); - a = GETCH_SCANCODE(a); - putcharhex(a); + XYCOORD screenxy; + + cmdline[0] = '\0'; + ctrlflag = YOTSH_COUNTER; + + putstr("\r\nYOT OS shell [Real mode]\r\n\r\n"); + + for(cmdcount=1; ; cmdcount++){ + if(YOTSH_ENABLED(YOTSH_COUNTER)){ + putint(cmdcount); + putstr(":"); + }else{ + putstr("<"); + } + + putstr("yotsh> "); + + if(YOTSH_ENABLED(YOTSH_AUTOCOPY)){ + yotrl(cmdline, cmdline, CMDMAX - 1, + CHV_COLORPAIR(CHV_COLOR_LIGHT_CYAN, CHV_COLOR_BLACK)); + }else{ + yotrl(cmdline, NULL, CMDMAX - 1, + CHV_COLORPAIR(CHV_COLOR_LIGHT_RED, CHV_COLOR_BLACK)); + } + + for(cp1=cmdline, cp2=argcopy; *cp1 != ' '&& *cp1 != '\0'; cp1++, cp2++){ + *cp2 = *cp1; + } + + end = ((*cp1 == '\0') ? true : false); + *cp2 = '\0'; + + if(!strcmp(argcopy, "set")){ + cp2 = cmdline + 3; + if(!end){ + cp2++; + } + if((*cp2 == '\0' || *cp2 == '?') || !strcmp(cp2, "help")){ + putstr("YOTSH function list:" + "\r\n autocopy " + "Automatically copy last command to input buffer" + "\r\n counter " + "Enable counter in command prompt" + "\r\n"); + }else if(!strcmp(cp2, "autocopy")){ + ctrlflag |= YOTSH_AUTOCOPY; + }else if(!strcmp(cp2, "counter")){ + ctrlflag |= YOTSH_COUNTER; + }else{ + putstr("yotsh: set: invalid function name `"); + putstr(cp2); + putstr("\'\r\n"); + } + }else if(!strcmp(argcopy, "unset")){ + cp2 = cmdline + 5; + if(!end){ + cp2++; + } + if((*cp2 == '\0' || *cp2 == '?') || !strcmp(cp2, "help")){ + putstr("Please type `set help\' to get function list\r\n"); + }else if(!strcmp(cp2, "autocopy")){ + ctrlflag &= ~(YOTSH_AUTOCOPY); + }else if(!strcmp(cp2, "counter")){ + ctrlflag &= ~(YOTSH_COUNTER); + }else{ + putstr("yotsh: unset: invalid function name `"); + putstr(cp2); + putstr("\'\r\n"); + } + }else if(!strcmp(argcopy, "read")){ + cp2 = cmdline + 4; + if(!end){ + cp2++; + } + if(strtos(cp2, &out)){ + cp1 = out; + out = *cp1 & 0x00ff; + putstr("decimal="); + putint(out); + putstr(", hexadecimal="); + putcharhex(out); + putstr("\r\n"); + }else{ + putstr("yotsh: read: invalid address `"); + putstr(cp2); + putstr("\'\r\n"); + } + }else if(!strcmp(argcopy, "halt") || + !strcmp(argcopy, "poweroff") || + !strcmp(argcopy, "shutdown")){ + asm "int 0x50"; + }else if(!strcmp(argcopy, "reboot")){ + cp1 = 0; + asm "int 0x51"; + }else if(*argcopy != '\0'){ + putstr("yotsh: invalid command `"); + putstr(argcopy); + putstr("\'\r\n"); + }else{ + cmdcount--; + } } - putint(getstr(abc, 10)); - putstr(abc);*/ - return 0xFFFD; + return 0; } |