📄 kernel.c
字号:
break; case BEEP: beep(1000); break; case SHOWREG: shreg(); break; case CHART: for (memcnt = 0; memcnt < 128 * 2; memcnt++) { printf("%02x(%c)%s", memcnt, memcnt == 0xa ? ' ' : memcnt, (memcnt + 1) % 12 ? " " : "\n"); } printf("\n"); break; case STOP: /* stop task n, syntax: stop n */ case START: /* start task n */ { commands a = cmds; /* save the previous command token */ cmds = cmdLex(pcmdsRecd); if (pcmdsRecd->tokenType == NUM) { taskData *p; p = task; do { /* ktask's pid=1, it may not be stopped */ if (p->pid == pcmdsRecd->attribute.numVal && p->pid > 1) { if (a == STOP) p->state = 0; else p->state = 1; break; } p = p->nextTaskLink; } while (p != task); } } break; case INSORT: insertSort(); break; case BINSORT: binsort(); break; case FACTOR: cmds = cmdLex(pcmdsRecd); if (pcmdsRecd->tokenType == NUM) { printf("%d!=%d\n", pcmdsRecd->attribute.numVal, factors(pcmdsRecd->attribute.numVal)); } break; case HANOI: cmds = cmdLex(pcmdsRecd); if (pcmdsRecd->tokenType == NUM) { hanoi(pcmdsRecd->attribute.numVal > 0 ? pcmdsRecd->attribute.numVal : 1, 'a', 'b', 'c'); } break; case ID: printf("%s", pcmdsRecd->attribute.stringVal); break; case NUM: printf("&%d\n", pcmdsRecd->attribute.numVal); break; case DIR: printf("\nDirectory of RamDisk in SNIXOS:\n"); printf(".\n..\n"); listdir(dir_tab); break; case WRFILE: { char *fname; cmds = cmdLex(pcmdsRecd); if (pcmdsRecd->tokenType == ID) { fname = (char *) malloc(strlen (pcmdsRecd->attribute.stringVal)); strcpy(fname, pcmdsRecd->attribute.stringVal); cmds = cmdLex(pcmdsRecd); if (pcmdsRecd->tokenType == ID) { wrfile(fname, pcmdsRecd->attribute.stringVal, strlen(pcmdsRecd->attribute. stringVal)); } free(fname); } } break; case RDFILE: case TYPE: cmds = cmdLex(pcmdsRecd); if (pcmdsRecd->tokenType == ID) { direntry tpdir; direntry *dir = &tpdir; char *aa; int i = 0, flen; if (readdir(pcmdsRecd->attribute.stringVal, dir)) { flen = dir->filesize; aa = (char *) malloc(dir->filesize * sizeof(char)); if (aa == NULL) { printf("malloc failed for TYPE\n"); goto ret1; } rdfile(pcmdsRecd->attribute.stringVal, aa); for (i = 0; i < dir->filesize; i++) printf("%c", *(aa + i)); free(aa); } else { printf("file not found!\n"); } } ret1: break; case DEL: { direntry dirtmp; direntry *dirs = &dirtmp; cmds = cmdLex(pcmdsRecd); if (pcmdsRecd->tokenType == ID) { delFile(pcmdsRecd->attribute.stringVal, dirs); } } break; case COPY: cmds = cmdLex(pcmdsRecd); if (pcmdsRecd->tokenType == ID) { char src[32]; strcpy(src, pcmdsRecd->attribute.stringVal); cmds = cmdLex(pcmdsRecd); if (pcmdsRecd->tokenType == ID) { copyFile(src, pcmdsRecd->attribute.stringVal); } } break; case LISTFAT: listFat(); break; case MYVM: cmds = cmdLex(pcmdsRecd); testas(pcmdsRecd->attribute.stringVal); break; case D0: /* trigger Exception: int 0x00 */ div0(); /*with printf can't easily determine which opcode make the Exp */ /*printf("%d\n", 5/0); */ break; case REBOOT: reboot(); break; case PLAY: play(); break; case DATE: { Time tm; getTime(&tm); printf("%4d-%02d-%02d %02d:%02d:%02d %s\n", tm.year, tm.month, tm.day, tm.hour, tm.min, tm.sec, tm.weekname); } break; case SHCN: /* output Chinese character, syntax shcn qh wh */#ifdef VIDEO_GRAPH_640X480 { unsigned int qh = 16, wh = 1; char aa[] = "aa"; cmds = cmdLex(pcmdsRecd); if (pcmdsRecd->tokenType == NUM) { qh = pcmdsRecd->attribute.numVal; cmds = cmdLex(pcmdsRecd); if (pcmdsRecd->tokenType == NUM) { wh = pcmdsRecd->attribute.numVal; } else { break; } } else { break; } printf("qh=%d wh=%d \n", qh, wh); if (qh < 95 && qh % 95 > 0 && wh < 95 && wh % 95 > 0) { aa[0] = qh; aa[1] = wh; printHZ(25, 27, aa, 1); } }#endif break; case HISTORY: { int i = 0; while (i < MAX_HIST) { printf("%2d %s\n", i, cmdHistory[i]); i++; } } break; case MDP: memdump(); break; case UNKNOWN: printf("No such command found\n"); break; } /* switch end */ cmdIdx = 0; printf("%s", PROMPT); } } }}void ver(){ printf ("\nSnixos Project version 1.0, 2003.6\n(C) Copyright 2003,2004,2005 Jockeyson,KeqiangGao <Snallie@tom.com> \nAll Rights Reserved.\nDistributed under the terms of the GNU General Public License.\n%s\n", rcsDate);}void cnver(){ unsigned char a[] = "SNIXOS中文操作系统"; unsigned char b[] = "版本1.0 版权所有高克强"; unsigned char c[] = "键入help获得帮助"; unsigned char statusBar[] = "SNIXOS中文操作系统 1.0 版权所有JOCKEY"; printHZ(0, 0, a, 0); printHZ(1, 0, b, 0); VGAPrintStr_8x16(1, 28, "<Snallie@tom.com>", 1); printHZ(2, 0, c, 0); printHZ(25, 0, statusBar, 0); /* { int i = 0; for (i = 0; i < 640; i++) VGADrawDot(469, i, 1); } */ VGAScrGotoxy(3, 0); ver(); printf("\n%s", PROMPT);}/* cmdLex: get token from command buffer ,return token string, token type, token attribute */commands cmdLex(tokenRecord * pcmdsRecd){#define WDLEN 30 /* local token buffer length for lexing */ int i; char words[WDLEN]; int p = 0, j; i = cmdIdx; while (isspace(kb[i])) i++; /* skip any space */ if (isalpha(kb[i])) { /* command or an ID, {letter}{letter|digit|.|_}* */ do { words[(p++) % WDLEN] = kb[i++]; } while (kb[i] != EOL && (isalnum(kb[i]) || kb[i] == '-' || kb[i] == '.')); words[(p++) % WDLEN] = EOL; for (j = 0; j < MAXCMDS && strcmp(words, cmdTabs[j].cmdstr); j++); pcmdsRecd->tokenType = (j >= MAXCMDS ? ID : cmdTabs[j].cmdType); strcpy(pcmdsRecd->attribute.stringVal, words); cmdIdx = i; return (j >= MAXCMDS ? UNKNOWN : cmdTabs[j].cmdType); } /* digit manipulation */ if (isdigit(kb[i]) || ((kb[i] == '-' || kb[i] == '+') && isdigit(kb[i + 1]))) { int isPositive = 1; if (kb[i] == '+') isPositive = 1; if (kb[i] == '-') isPositive = 0; pcmdsRecd->attribute.numVal = 0; if (kb[i] == '+' || kb[i] == '-') i++; do { words[p++ % WDLEN] = kb[i++]; pcmdsRecd->attribute.numVal = pcmdsRecd->attribute.numVal * 10 + kb[i - 1] - 0x30; /* ascii to integer */ } while (kb[i] != EOL && isdigit(kb[i])); pcmdsRecd->attribute.numVal = isPositive ? pcmdsRecd->attribute. numVal : -(pcmdsRecd->attribute.numVal); words[p++ % WDLEN] = EOL; strcpy(pcmdsRecd->attribute.stringVal, words); pcmdsRecd->tokenType = NUM; cmdIdx = i; return (NUM); } cmdIdx = i; return -1; /* nothing else */}void threadTask(){ unsigned short int cnt1 = 0; while (1) { cnt1++; if (&cnt1 > 0x9c000) { /* distinguish task by its stack address */ /* printf("thread1:%8X cnt:%d\n", &cnt1, cnt1); */#ifdef VIDEO_GRAPH_640X480 VGAPutChar_8x16(25, 56, cnt1 % 10 + 0x30, 0);#else TXTPutChar(10, 0, cnt1 % 10 + 0x30, 0x1f);#endif cmosDelay(1); } if (&cnt1 < 0x9c000) { /* printf("thread2:%8X cnt:%d\n", &cnt1, cnt1); */#ifdef VIDEO_GRAPH_640X480 VGAPutChar_8x16(25, 58, cnt1 % 10 + 0x30, 1);#else TXTPutChar(12, 0, cnt1 % 10 + 0x30, 0x2f);#endif cmosDelay(3); } }}void cnverTask(){ unsigned char statusBar[] = "SNIXOS中文操作系统 1.0 版权所有JOCKEY"; while (1) { printHZ(25, 0, statusBar, 0); cmosDelay(1); }}void task1(){ unsigned int cnt1 = 0; long a, temp; int i; char *rotation[] = { "-", "\\", "|", "/", }; while (1) { cnt1++;#ifndef VIDEO_GRAPH_640X480 a = temp = cnt1; for (i = 0; i < 8; i++) { a = (a >> (7 - i) * 4) & 0x0000000f; *((char *) (0xb8000 + 104 + i * 2)) = (char) a = (a >= 10) ? a + 0x37 : a + 0x30; *((char *) (0xb8000 + 104 + i * 2 + 1)) = 0x2f; a = temp; }#else VGAPrintStr_8x16(25, 62, rotation[cnt1 % 4], 1); /* rotation on 25,62 */#endif }}void task2(){ unsigned int cnt1 = 0; long a, temp; int i; char *rotation[] = { "-", "\\", "|", "/", }; while (1) { cnt1++;#ifndef VIDEO_GRAPH_640X480 a = temp = cnt1; for (i = 0; i < 8; i++) { a = (a >> (7 - i) * 4) & 0x0000000f; *((char *) (0xb8000 + 124 + i * 2)) = (char) a = (a >= 10) ? a + 0x37 : a + 0x30; *((char *) (0xb8000 + 124 + i * 2 + 1)) = 0x24; a = temp; }#else VGAPrintStr_8x16(25, 64, rotation[cnt1 % 4], 0); /* rotation on 25,64 */#endif i = 0; while (i < 0X2FFFFF) { i++; } }}void timeTask(){ Time tm; char scrtime[] = "0 8 : 2 0 : 2 5 "; char scrtime2[9]; while (1) { getTime(&tm); scrtime[2] = tm.hour % 10 + 0x30; scrtime[0] = tm.hour / 10 + 0x30; scrtime[8] = tm.min % 10 + 0x30; scrtime[6] = tm.min / 10 + 0x30; scrtime[14] = tm.sec % 10 + 0x30; scrtime[12] = tm.sec / 10 + 0x30;#ifndef VIDEO_GRAPH_640X480 memcpy((char *) 0xb8000, scrtime, strlen(scrtime));#else { int i = 0; for (i = 0; i < 16; i += 2) scrtime2[i / 2] = scrtime[i]; VGAPrintStr_8x16(25, 72, scrtime2, 1); }#endif// if (tm.min % 59 == 0 && tm.sec % 59 == 0)// beepup(); }}void motion(){ Time tm; int x, y, pos; char scrtime[] = "0 8 : 2 0 : 2 5 "; char savescr[] = "0 8 : 2 0 : 2 5 "; unsigned short int k = 0; char *rotation[] = { "-", "\\", "|", "/", }; while (1) { getTime(&tm); scrtime[2] = tm.hour % 10 + 0x30; scrtime[0] = tm.hour / 10 + 0x30; scrtime[8] = tm.min % 10 + 0x30; scrtime[6] = tm.min / 10 + 0x30; scrtime[14] = tm.sec % 10 + 0x30; scrtime[12] = tm.sec / 10 + 0x30;#ifndef VIDEO_GRAPH_640X480 x = rand() % 24 + 1; cmosDelay(1); y = rand() % 80;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -