📄 kernel.c,v
字号:
} } 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 版权所有高克强"; 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 版权所有高克强"; 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; pos = 0xb8000 + x * 80 * 2 + y * 2; memcpy(savescr, (char *) pos, strlen(savescr)); memcpy((char *) pos, scrtime, strlen(scrtime)); cmosDelay(1); memcpy((char *) pos, savescr, strlen(savescr));#else cmosDelay(2); VGAPrintStr_8x16(25, 68, rotation[k = (k--) % 4], 0); /* rotation on 25,68 */#endif }}void banner(){#define WHITE_TXT 0x07 /* white on black text */#define FORWARD 1#define BACKWARD -1 int row = 1; int i = 31 * 2; char chs = 'A'; char *vidmem = (char *) 0xb8000; int lr = FORWARD; unsigned short int k = 0; char *rotation[] = { "-", "\\", "|", "/", }; while (1) {#ifndef VIDEO_GRAPH_640X480 if (i < 160 * row && lr == FORWARD) { if (i == 49 * 2 * row) lr = BACKWARD; vidmem[i] = '>'; /* chs; */ vidmem[i + 1] = WHITE_TXT; cmosDelay(1); vidmem[i + 1] = 00; i += 2; } else if (i >= 160 * (row - 1) && lr == BACKWARD) { if (i == 31 * 2 * row) lr = FORWARD; i -= 2; vidmem[i] = '<'; /* chs; */ vidmem[i + 1] = WHITE_TXT; cmosDelay(1); vidmem[i + 1] = 00; }#else VGAPrintStr_8x16(25, 66, rotation[k = (k++) % 4], 1); /* rotation on 25,66 */ cmosDelay(1);#endif }}#define RUNNABLE 1void newTask(unsigned int taskEntrance, char *taskname){#define TASKSTACK 0X9FFF0 static unsigned int taskcnt = 0; taskData *taskP; taskP = (taskData *) malloc(sizeof(taskData)); taskcnt++; taskP->cs = 0x08; taskP->ip = (unsigned int) taskEntrance; taskP->flag = 0x200; /* interrupt enabled */ taskP->state = RUNNABLE; taskP->ksts = 0; taskP->sp = TASKSTACK - (taskcnt - 1) * 0x1000; /* 0x1000(4K) bytes/stack/task */ taskP->bp = TASKSTACK - (taskcnt - 1) * 0x1000; taskP->pid = taskcnt; /* task id */ strncpy(taskP->taskName, taskname, 9); taskP->nextTaskLink = taskTail->nextTaskLink; taskTail->nextTaskLink = taskP; taskTail = taskP;}void initTask(){ /* init a dummy task structure */ task = (taskData *) malloc(sizeof(taskData)); task->cs = 0x08; task->ip = (unsigned int) 0x00; /* any integer */ task->flag = 0x200; task->state = 0; /* may not set task0's state RUNNABLE!! */ task->ksts = 0; task->sp = (unsigned int) 0; /* dummy spaceholder */ task->bp = (unsigned int) 0; /* dummy spaceholder */ task->pid = (unsigned int) 0; strcpy(task->taskName, "dummy"); task->nextTaskLink = task; taskTail = task; curTask = task;}void scheduler(){ /* Save state of running task in a task table slot */ curTask->ax = eax_reg; curTask->bx = ebx_reg; curTask->cx = ecx_reg; curTask->dx = edx_reg; curTask->si = esi_reg; curTask->di = edi_reg; curTask->sp = esp_reg; curTask->bp = ebp_reg; curTask->flag = eflag_reg; curTask->cs = cs_reg; curTask->ip = eip_reg; curTask->ksts = 0; /* Choose the next task */ while ((curTask->nextTaskLink)->state == 0) curTask = curTask->nextTaskLink; curTask = curTask->nextTaskLink; /* Restore new task state */ eax_reg = curTask->ax; ebx_reg = curTask->bx; ecx_reg = curTask->cx; edx_reg = curTask->dx; esi_reg = curTask->si; edi_reg = curTask->di; esp_reg = curTask->sp; ebp_reg = curTask->bp; eflag_reg = curTask->flag; cs_reg = curTask->cs; eip_reg = curTask->ip; curTask->ksts = 1;}int rand(){ return tickcount % 100;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -