svnno****@sourc*****
svnno****@sourc*****
2011年 7月 9日 (土) 12:21:01 JST
Revision: 168 http://sourceforge.jp/projects/negitoro/svn/view?view=rev&revision=168 Author: is2os Date: 2011-07-09 12:21:01 +0900 (Sat, 09 Jul 2011) Log Message: ----------- Negitoro 0.0.1 (unstable) ã³ã¼ãã¬ãã¥ã¼r156ã§ææããã¦ããç¹ãããã¤ãä¿®æ£ãã¾ããã ãã¡ã¤ã«ããã¯ã«é¢é£ããå¦çã®ã³ã¼ãã£ã³ã°ãããªãã®éã«ãªã£ã¦ãã¾ãã¾ããã ããããªãããããã«ã¤ãã¦ã¯ã¾ã ã¾ã æ¹åã®ä½å°ãããããã§ãã ã¾ããé¢æ°cons_runcmdå ã§ã¯hists.logã¸ã®è¨é²ãããããã é¢æ°loggingã§ã®è¨é²ã¯ä¸è¦ã¨æãåé¤ãã¾ããã (kernel) [api.c] ã»api_fopenã¨api_fcloseã§ãã¡ã¤ã«ã®ããã¯ã¨ã¢ã³ããã¯ã®å¦çã追å ã»api_fcloseã§è¿ãå¤ãè¿ãããã«ãã [bootpack.c] ã»ä»¥ä¸ã®é¢æ°ã追å init_run_system alloc_global_fat enable_PICs [bootpack.h] ã»ä»¥ä¸ã®é¢æ°å®ç¾©ã®è¿½å init_run_system alloc_global_fat enable_PICs mem_display_on ãlock.cå å®ç¾©ã®é¢æ°ç¾¤ ã»FILEHANDLEã«fnameã¡ã³ãã追å ã»å®æ°FILENAMEã追å [command.c] ã»histsã³ãã³ãã§ã¡ã¢ãªãéæ¾ãããªããã°ãä¿®æ£ ã»fctlã³ãã³ãã§ãã¡ã¤ã«ã®ããã¯ã¨ã¢ã³ããã¯ããµãã¼ã ã»psã³ãã³ãã§ã®ã¿ã¹ã¯ãªã¹ãã®è¡¨ç¤ºã®ä»æ¹ãå¤æ´ [console.c] ã»é¢æ°loggingã§ã³ãã³ãã®å®è¡ãè¨é²ããã³ã¼ããåé¤ [file.c] ã»ãã¡ã¤ã«ã®èªã¿æ¸ãåå¾ã«ãã¡ã¤ã«ããã¯ã®å¦çã追å [memory.c] ã»ä»¥ä¸ã®é¢æ°ã追å mem_display_on [mtask.c] ã»ã³ã¡ã³ãã®è¿½å [lock.c] ã»ãã¡ã¤ã«ã®è¿½å (apilib) [api022.nas] ã»ã³ã¡ã³ããä¿®æ£ (include) [apilib.h] ã»api_fcloseã®é¢æ°å®ç¾©ãä¿®æ£ Modified Paths: -------------- trunk/apilib/api022.nas trunk/include/apilib.h trunk/kernel/Makefile trunk/kernel/api.c trunk/kernel/bootpack.c trunk/kernel/bootpack.h trunk/kernel/command.c trunk/kernel/console.c trunk/kernel/file.c trunk/kernel/memory.c trunk/kernel/mtask.c Added Paths: ----------- trunk/kernel/lock.c Modified: trunk/apilib/api022.nas =================================================================== --- trunk/apilib/api022.nas 2011-05-25 14:46:49 UTC (rev 167) +++ trunk/apilib/api022.nas 2011-07-09 03:21:01 UTC (rev 168) @@ -7,7 +7,7 @@ [SECTION .text] -_api_fclose: ; void api_fclose(int fhandle); +_api_fclose: ; int api_fclose(int fhandle); MOV EDX,22 MOV EAX,[ESP+4] ; fhandle INT 0x40 Modified: trunk/include/apilib.h =================================================================== --- trunk/include/apilib.h 2011-05-25 14:46:49 UTC (rev 167) +++ trunk/include/apilib.h 2011-07-09 03:21:01 UTC (rev 168) @@ -33,7 +33,7 @@ /* t@Cn */ int api_fopen(char *fname); -void api_fclose(int fhandle); +int api_fclose(int fhandle); void api_fseek(int fhandle, int offset, int mode); int api_fsize(int fhandle, int mode); int api_fread(char *buf, int maxsize, int fhandle); Modified: trunk/kernel/Makefile =================================================================== --- trunk/kernel/Makefile 2011-05-25 14:46:49 UTC (rev 167) +++ trunk/kernel/Makefile 2011-07-09 03:21:01 UTC (rev 168) @@ -2,7 +2,7 @@ fifo.obj keyboard.obj mouse.obj memory.obj sheet.obj timer.obj mtask.obj \ window.obj console.obj file.obj tek.obj alloca.obj int.obj parallel.obj \ command.obj api.obj sound.obj pcic.obj serial.obj color.obj fdc.obj mpm.obj \ - rtc.obj log.obj strtok.obj taskbar.obj bit.obj pci.obj + rtc.obj log.obj strtok.obj taskbar.obj bit.obj pci.obj lock.obj OBJS_IMGCDC = obj/bmp.obj obj/jpeg.obj TOOLPATH = ../../z_tools/ Modified: trunk/kernel/api.c =================================================================== --- trunk/kernel/api.c 2011-05-25 14:46:49 UTC (rev 167) +++ trunk/kernel/api.c 2011-07-09 03:21:01 UTC (rev 168) @@ -175,16 +175,26 @@ finfo = file_search((char *)ebx + ds_base, (struct FILEINFO *) (ADR_DISKIMG + 0x002600), 224); if (finfo != 0) { - reg[7] = (int) fh; - fh->size = finfo->size; - fh->pos = 0; - fh->buf = file_loadfile2(finfo->clustno, &fh->size, global_alloc_fat); + if (file_lock((char *)ebx + ds_base, task_now()->id)) { + reg[7] = (int) fh; + strcpy(fh->fname, (char *)ebx + ds_base); + fh->size = finfo->size; + fh->pos = 0; + fh->buf = file_loadfile2(finfo->clustno, &fh->size, global_alloc_fat); + } else { + reg[7] = 0; + } } } } else if (edx == 22) { fh = (struct FILEHANDLE *) eax; - memman_free_4k((int) fh->buf, fh->size); - fh->buf = 0; + if (file_unlock(fh->fname)) { + memman_free_4k((int) fh->buf, fh->size); + fh->buf = 0; + reg[7] = 1; + } else { + reg[7] = 0; + } } else if (edx == 23) { fh = (struct FILEHANDLE *) eax; if (ecx == 0) { Modified: trunk/kernel/bootpack.c =================================================================== --- trunk/kernel/bootpack.c 2011-05-25 14:46:49 UTC (rev 167) +++ trunk/kernel/bootpack.c 2011-07-09 03:21:01 UTC (rev 168) @@ -65,8 +65,6 @@ /* pÂ\VA|[gÌú» */ init_serialports(0x06); - debugmsg("** Negitoro has just started up! **"); - init_gdtidt(); init_pic(); init_pit(); @@ -75,18 +73,14 @@ /* IDT/PICÌú»ªIíÁ½ÌÅCPUÌèÝÖ~ðð */ io_sti(); + /* L[{[hÆ}EXÉFIFOðèÄé */ fifo32_init(&fifo, 128, fifobuf, 0); init_keyboard(&fifo, 256); enable_mouse(&fifo, 512, &mdec); fifo32_init(&keycmd, 32, keycmd_buf, 0); - debugmsg("Initialized mouse and keyboard buffer.."); + debugmsg("Initialized mouse and keyboard buffer.."); - /* PITÆPIC1ÆL[{[hðÂ(11111000) */ - /* }EXðÂ(11101111) */ - io_out8(PIC0_IMR, 0xf8); - io_out8(PIC1_IMR, 0xef); - debugmsg("Enabled PIT, PIC1, Mouse, keyboard.."); - + enable_PICs(); memtotal = init_memory(); shtctl = shtctl_init(binfo->vram); task_a = task_init(); @@ -99,12 +93,14 @@ VXeN® -------------------*/ + + /* FATÌmÛÆVXe^XNN® */ + alloc_global_fat(); + init_run_system(task_a, &fifo); - /* VXe^XN */ - task_run(task_a, 1, 2, "system"); - fifo.task = task_a; - task_a->langmode = 0; - debugmsg("Running kernel.."); + /* t@CbNXgÌú»Æo^ */ + init_file_lock(); + file_lock(SYSTEMFILE_NAME, task_now()->id); /* wi(sht_back)ÌV[gÝè */ global_sht_back = sheet_alloc(); @@ -120,11 +116,6 @@ mx = (binfo->scrnx - 16) / 2; my = (binfo->scrny - 28 - 16) / 2; - /* fatÍßÉǤɩµÄ¨ */ - global_alloc_fat = (int *)memman_alloc_4k(4 * 2880); - file_readfat(global_alloc_fat, (UCHAR *) (ADR_DISKIMG + FAT_ADDR)); - debugmsg("Memory allocated for FAT.."); - /* tHgÇÝÝ */ file_readfont(FONTFILE, nihongo); debugmsg("Font loaded.. (%s)", FONTFILE); @@ -144,7 +135,7 @@ ----------------------------*/ /* EãÌ\¦Jn */ - ((struct MEMMAN *) MEMMAN_ADDR)->disp = 1; + mem_display_on(1); /* }EX\¦ */ sheet_slide(sht_mouse, mx, my); @@ -490,6 +481,37 @@ } } +/// @brief VXe^XNðN®·é +/// @param task èÄé^XN +/// @param fifo èÄéFIFO +void init_run_system(struct TASK *task, struct FIFO32 *fifo) +{ + task_run(task, 1, 2, "system"); + fifo->task = task; + task->langmode = 0; + debugmsg("Running kernel.."); + return; +} + +/// @brief FATÌ×ÌO[oÈÏðmÛ +void alloc_global_fat(void) +{ + global_alloc_fat = (int *)memman_alloc_4k(4 * 2880); + + file_readfat(global_alloc_fat, (UCHAR *) (ADR_DISKIMG + FAT_ADDR)); + debugmsg("Memory allocated for FAT.."); + + return; +} + +/// @brief PITAPIC1ÆL[{[hA}EXð +void enable_PICs(void) +{ + io_out8(PIC0_IMR, 0xf8); + io_out8(PIC1_IMR, 0xef); + debugmsg("Enabled PIT, PIC1, Mouse, keyboard.."); +} + /// @brief wèµ½V[gÌL[üÍðOFF /// @param key_win OFFÉ·éV[g void keywin_off(struct SHEET *key_win) Modified: trunk/kernel/bootpack.h =================================================================== --- trunk/kernel/bootpack.h 2011-05-25 14:46:49 UTC (rev 167) +++ trunk/kernel/bootpack.h 2011-07-09 03:21:01 UTC (rev 168) @@ -128,6 +128,7 @@ int memman_free_4k(UINT32 addr, UINT32 size); UINT32 init_memory(void); UINT32 get_totalmem(void); +void mem_display_on(int on); /* sheet.c */ #define MAX_SHEETS 256 ///<gpÂ\V[gÌÅå @@ -422,9 +423,10 @@ }; /// @brief t@Cnh struct FILEHANDLE { - char *buf; ///< f[^ - int size; ///< t@CTCY - int pos; ///< ÇÜê½|WV + char *fname; ///< t@C¼ + char *buf; ///< f[^ + int size; ///< t@CTCY + int pos; ///< ÇÜê½|WV }; void close_console(struct SHEET *sht); void close_constask(struct TASK *task); @@ -478,6 +480,7 @@ void cmd_tpci(char *cmdline); /* file.c */ +#define FILENAME 11 /// @brief êÂÌt@Cf[^ struct FILEINFO { UCHAR name[8]; ///< t@C¼ @@ -489,6 +492,7 @@ USHORT clustno; ///< NX^Ô UINT32 size; ///< t@CTCY }; + void file_readfat(int *fat, UCHAR *img); void file_writefat(int no, int data); struct FILEINFO *file_search(char *name, struct FILEINFO *finfo, int max); @@ -502,12 +506,31 @@ void file_readfont(char *filename, UCHAR *fontbuf); void write_history(char *cmdline); +/* lock.c */ +#define LOCKED_FILE_MAX 256 ///< ÅåbNt@C +/// @brief bN³êÄ¢ét@Cf[^ +struct LOCKED_FILE { + UCHAR name[11]; ///< t@C¼ + int flag; ///< ÄptO + int taskid; ///< bNµÄ¢é^XNÌID + int type; ///< íÞit@CA|[gAetcj +}; +extern struct LOCKED_FILE locked_files[LOCKED_FILE_MAX]; +void init_file_lock(void); +int file_lock(char *fname, int taskid); +int file_unlock(char *fname); +int file_islockedby(char *fname, int taskid); +int file_exist(char *fname); + /* bootpack.c */ #define KEYCMD_LED 0xed #define FONTFILE "nihongo.fnt" extern int *global_alloc_fat; extern struct SHEET *global_sht_back; extern int global_mouse_x, global_mouse_y; +void enable_PICs(void); +void init_run_system(struct TASK *task, struct FIFO32 *fifo); +void alloc_global_fat(void); void keywin_off(struct SHEET *key_win); void keywin_on(struct SHEET *key_win); Modified: trunk/kernel/command.c =================================================================== --- trunk/kernel/command.c 2011-05-25 14:46:49 UTC (rev 167) +++ trunk/kernel/command.c 2011-07-09 03:21:01 UTC (rev 168) @@ -80,9 +80,12 @@ /// @todo -rnIvVÌÀ void cmd_fctl(char *cmdline) { + int i; if (!cmdline[0]) { - cputs0(" usage: >fctl <-new|-del|-rn> [filename] <filename>"); + cputs0(" usage: >fctl <-new|-del|-rn|-lk|-unlk> "); + cputs0(" [filename] (filename)"); + cputs0(" <lockedfiles>"); } else { if (!strncmp(cmdline, "-new", 4)) { /* ót@Cì¬ */ @@ -100,6 +103,28 @@ } } else if (!strncmp(cmdline, "-rn", 3)) { /* t@CÌl[ */ + } else if (!strncmp(cmdline, "-lk", 3)) { + /* t@CÌbN */ + if (file_lock(cmdline + 4, task_now()->id)) { + cprintf("%s is locked.\n", cmdline + 4); + } else { + cprintf("%s cannot be locked or is not exist.\n", cmdline + 4); + } + } else if (!strncmp(cmdline, "-unlk", 5)) { + /* t@CÌbNðð */ + if (file_unlock(cmdline + 6)) { + cprintf("%s is unlocked.\n", cmdline + 6); + } else { + cprintf("%s cannot be unlocked or is not exist.\n", cmdline + 4); + } + } else if (!strncmp(cmdline, "lockedfiles", 11)) { + /* bN³ê½t@CÌêð\¦ */ + for (i = 0;i < LOCKED_FILE_MAX;i++) { + if (locked_files[i].flag) { + cprintf("%s(%d)\n", locked_files[i].name, + locked_files[i].taskid); + } + } } else { cputs0("option error."); } @@ -121,13 +146,12 @@ finfo = file_search(HISTORY_FILE, (struct FILEINFO *) (ADR_DISKIMG + 0x002600), 224); if (finfo) { - buf = (UCHAR *)memman_alloc_4k(finfo->size); size = finfo->size; buf = file_loadfile2(finfo->clustno, &size, global_alloc_fat); for (j = 0;j < size;j++) { cons_putchar(task->cons, buf[j], 1); } - memman_free_4k((UINT32)buf, finfo->size); + memman_free_4k(*((UCHAR *)buf), size); } return; @@ -290,7 +314,7 @@ v = taskctl->tasks0[j].id; } - cprintf("%s (%d, %d) %d\n",taskctl->tasks0[j].taskname, + cprintf("%s [%d, %d, %d]\n",taskctl->tasks0[j].taskname, taskctl->tasks0[j].level, taskctl->tasks0[j].priority, v); } } Modified: trunk/kernel/console.c =================================================================== --- trunk/kernel/console.c 2011-05-25 14:46:49 UTC (rev 167) +++ trunk/kernel/console.c 2011-07-09 03:21:01 UTC (rev 168) @@ -419,7 +419,7 @@ /// @param cons æÌR\[ void cons_runcmd(char *cmdline) { - int i, j = 1; + int i; char name[256], *argw; struct CONSOLE *cons; struct TASK *task = task_now(); @@ -443,6 +443,9 @@ /* ^XNªR\[ÅȯêÎ_ */ if (!task->cons) return; cons = task->cons; + + /* ½©ªR}hCɶݵ½ç */ + if (cmdline[0]) write_history(cmdline); /* R}h */ if (!strcmp(name, "mem") && cons->sht) cmd_mem(); @@ -470,19 +473,9 @@ /* R}hÅÍÈAAvÅàÈA³çÉósÅàÈ¢ */ cputs0("It may be wrong command or not existing file."); } - j = 0; } - - /* ½©ªR}hCɶݵ½ç */ - if (cmdline[0]) { - cons_newline(); - write_history(cmdline); - } - - /* R}hªÀs³êêÎL^ */ - if (j) logging(LOG_KERNEL, "com executed : %s", name); - + if (cmdline[0]) cons_newline(); return; } Modified: trunk/kernel/file.c =================================================================== --- trunk/kernel/file.c 2011-05-25 14:46:49 UTC (rev 167) +++ trunk/kernel/file.c 2011-07-09 03:21:01 UTC (rev 168) @@ -1,347 +1,361 @@ -/// @file file.c -/// @brief t@CÖW -/// @author JsZ(is2os) -/// @since 2010-08-23(r41) -/// @todo file_writefileª¢®¬ by JsZ - -#include "bootpack.h" - -/// @brief fBXNC[WàÌFAT̳kðÆ -/// @param fat ³kðÆFAT -/// @param img fBXNC[WÌAhX -void file_readfat(int *fat, UCHAR *img) -{ - int i, j = 0; - - for (i = 0; i < 2880; i += 2) { - fat[i + 0] = (img[j + 0] | img[j + 1] << 8) & 0xfff; - fat[i + 1] = (img[j + 1] >> 4 | img[j + 2] << 4) & 0xfff; - j += 3; - } - - return; -} - -/// @brief FATÉf[^ð«Þ. -/// -/// TbitOS©ç¬pBdgÝÍǪ©çÈ¢B -/// @param no FATÌDZ© -/// @param data «Þf[^ -void file_writefat(int no, int data) -{ - UCHAR *img = (UCHAR *)(ADR_DISKIMG + FAT_ADDR); - int i = no / 2, j, k; - - /* C[WÉf[^ð«Þ */ - global_alloc_fat[no] = data; - - if((no & 1) == 0) { /* noªôÈçOÌàÌÆêÉXV */ - j = global_alloc_fat[no - 1]; - k = global_alloc_fat[no]; - } else { /* noªïÈçãëÌàÌÆêÉXV */ - j = global_alloc_fat[no]; - k = global_alloc_fat[no + 1]; - } - - /* }X^ðXV */ - img[i * 3] = (UCHAR) (j & 0x0ff); - img[i * 3 + 1] = (UCHAR) ((k & 0x00f) << 4 | (j & 0xf00) >> 8); - img[i * 3 + 2] = (UCHAR) ((k & 0xff0) >> 4); - - /* X[uðXV */ - img[2880 + i * 3] = img[i * 3]; - img[2880 + i * 3 + 1] = img[i * 3 + 1]; - img[2880 + i * 3 + 2] = img[i * 3 + 1]; - - return; -} - -/// @brief ó«FATðæ¾ -/// @param fat æ¾·éFAT -/// @return æ¾Å«È¯êÎ0AÅ«½ç»êÈO -USHORT file_getfat(int *fat) -{ - int i; - - for (i = 0; i < 2880; i++) { - if (fat[i] == 0) { - fat[i] = 0x1000; - return i; - } - } - - return 0; -} - -/// @brief t@C¼ðÝè -/// @param finfo Ýè·ét@C -/// @param name t@C¼ -void file_setname(struct FILEINFO *finfo, char *name) -{ - int i, j; - UCHAR s[12]; - - for (i = 0; i < 11; i++) { s[i] = ' '; } - i = 0; - for (j = 0; name[j] != 0; j++) { - if (i >= 11) { return; } - if (name[j] == '.' && j <= 8) { - i = 8; - } else { - s[i] = name[j]; - if ('a' <= s[i] && s[i] <= 'z') { s[i] -= 0x20; } - i++; - } - } - for (i = 0; i < 11; i++) { finfo->name[i] = s[i]; } - - return; -} - -/// @brief wèµ½t@Cðí -/// @param filename t@C¼ -/// @param fat FAT -/// @return íÅ«½ç0A»¤ÅȯêÎ1 -int file_removefile(char *filename, int *fat) -{ - struct FILEINFO *finfo = file_search(filename, (struct FILEINFO *) (ADR_DISKIMG + 0x002600), 224); - - if (finfo != 0) { - if ((finfo->type & 0x18) == 0) { - io_cli(); - finfo->name[0] = 0xe5; /* í */ - file_writefat(finfo->clustno, 0x0000); - io_sti(); - } - return 0; - } - - return 1; -} - -/// @brief ót@Cðì¬ -/// @param filename t@C¼ -/// @param fat FAT -/// @return ì¬Å«È¯êÎ0AÅ«½ç»êÈO -struct FILEINFO *file_createfile(char *filename, int *fat) -{ - struct FILEINFO *finfo = (struct FILEINFO *) (ADR_DISKIMG + 0 x002600); - int i; - - /* t@C̳¢êðT· */ - for (i = 0;i < 224;i++) { - if (finfo[i].type == 0x00 || finfo[i].name[0] == 0xe5) { - /* t@Cðì¬ */ - io_cli(); - file_setname(finfo + i, filename); - finfo[i].size = 0; - finfo[i].type = 0x20; - finfo[i].clustno = file_getfat(fat); - file_writefat(finfo[i].clustno, 0x0fff); - io_sti(); - return finfo + i; - } - } - - return 0; -} - -/// @brief t@CÖ«Þ -/// @param finfo «Þt@C -/// @param buf «Þf[^ -/// @param dsize «ÞTCY -/// @todo àÁÆ©Õ¢R[hÉ·é -void file_writefile(struct FILEINFO *finfo, char *buf, int dsize) -{ - int i, j = 0, l, ncno = 0, nsize, cn = finfo->clustno; - char *img = (char *)(ADR_DISKIMG + 0x003e00); - - /* Æè ¦¸¡ÌƱëÍAbvGh¾¯ */ - - for (;;) { - /* 512oCgÈãÌÆ«ÍfatHèȪç */ - /* ȺÉÈÁ½ç²¯é */ - nsize = finfo->size; - if (dsize <= 512) { - for (i = 0, j = 0;i < dsize;i++ , j++) { - if (nsize + i >= 512) { - for (l = 0;nsize >= 512;nsize -= 512, l++) ; - for (;l > 0;l--) { - if (global_alloc_fat[cn] >= 0x0ff8) { - file_writefat(cn, 0x0fff); - ncno = file_getfat(global_alloc_fat); - file_writefat(cn, ncno); - } - cn = global_alloc_fat[cn]; +/// @file file.c +/// @brief t@CÖW +/// @author JsZ(is2os) +/// @since 2010-08-23(r41) +/// @todo file_writefileª¢®¬ by JsZ + +#include "bootpack.h" + +/// @brief fBXNC[WàÌFAT̳kðÆ +/// @param fat ³kðÆFAT +/// @param img fBXNC[WÌAhX +void file_readfat(int *fat, UCHAR *img) +{ + int i, j = 0; + + for (i = 0; i < 2880; i += 2) { + fat[i + 0] = (img[j + 0] | img[j + 1] << 8) & 0xfff; + fat[i + 1] = (img[j + 1] >> 4 | img[j + 2] << 4) & 0xfff; + j += 3; + } + + return; +} + +/// @brief FATÉf[^ð«Þ. +/// +/// TbitOS©ç¬pBdgÝÍǪ©çÈ¢B +/// @param no FATÌDZ© +/// @param data «Þf[^ +void file_writefat(int no, int data) +{ + UCHAR *img = (UCHAR *)(ADR_DISKIMG + FAT_ADDR); + int i = no / 2, j, k; + + /* C[WÉf[^ð«Þ */ + global_alloc_fat[no] = data; + + if((no & 1) == 0) { /* noªôÈçOÌàÌÆêÉXV */ + j = global_alloc_fat[no - 1]; + k = global_alloc_fat[no]; + } else { /* noªïÈçãëÌàÌÆêÉXV */ + j = global_alloc_fat[no]; + k = global_alloc_fat[no + 1]; + } + + /* }X^ðXV */ + img[i * 3] = (UCHAR) (j & 0x0ff); + img[i * 3 + 1] = (UCHAR) ((k & 0x00f) << 4 | (j & 0xf00) >> 8); + img[i * 3 + 2] = (UCHAR) ((k & 0xff0) >> 4); + + /* X[uðXV */ + img[2880 + i * 3] = img[i * 3]; + img[2880 + i * 3 + 1] = img[i * 3 + 1]; + img[2880 + i * 3 + 2] = img[i * 3 + 1]; + + return; +} + +/// @brief ó«FATðæ¾ +/// @param fat æ¾·éFAT +/// @return æ¾Å«È¯êÎ0AÅ«½ç»êÈO +USHORT file_getfat(int *fat) +{ + int i; + + for (i = 0; i < 2880; i++) { + if (fat[i] == 0) { + fat[i] = 0x1000; + return i; + } + } + + return 0; +} + +/// @brief t@C¼ðÝè +/// @param finfo Ýè·ét@C +/// @param name t@C¼ +void file_setname(struct FILEINFO *finfo, char *name) +{ + int i, j; + UCHAR s[12]; + + for (i = 0; i < 11; i++) { s[i] = ' '; } + i = 0; + for (j = 0; name[j] != 0; j++) { + if (i >= 11) { return; } + if (name[j] == '.' && j <= 8) { + i = 8; + } else { + s[i] = name[j]; + if ('a' <= s[i] && s[i] <= 'z') { s[i] -= 0x20; } + i++; + } + } + for (i = 0; i < 11; i++) { finfo->name[i] = s[i]; } + + return; +} + +/// @brief wèµ½t@Cðí +/// @param filename t@C¼ +/// @param fat FAT +/// @return íÅ«½ç0A»¤ÅȯêÎ1 +int file_removefile(char *filename, int *fat) +{ + struct FILEINFO *finfo; + + if (!file_islockedby(filename, task_now()->id)) { + return 1; + } + + finfo = file_search(filename, (struct FILEINFO *) (ADR_DISKIMG + 0x002600), 224); + if (finfo != 0) { + if ((finfo->type & 0x18) == 0) { + io_cli(); + finfo->name[0] = 0xe5; /* í */ + file_writefat(finfo->clustno, 0x0000); + io_sti(); + } + return 0; + } + + return 1; +} + +/// @brief ót@Cðì¬ +/// @param filename t@C¼ +/// @param fat FAT +/// @return ì¬Å«È¯êÎ0AÅ«½ç»êÈO +struct FILEINFO *file_createfile(char *filename, int *fat) +{ + struct FILEINFO *finfo = (struct FILEINFO *) (ADR_DISKIMG + 0x002600); + int i; + + /* t@C̳¢êðT· */ + for (i = 0;i < 224;i++) { + if (finfo[i].type == 0x00 || finfo[i].name[0] == 0xe5) { + /* t@Cðì¬ */ + io_cli(); + file_setname(finfo + i, filename); + finfo[i].size = 0; + finfo[i].type = 0x20; + finfo[i].clustno = file_getfat(fat); + file_writefat(finfo[i].clustno, 0x0fff); + io_sti(); + return finfo + i; + } + } + + return 0; +} + +/// @brief t@CÖ«Þ +/// @param finfo «Þt@C +/// @param buf «Þf[^ +/// @param dsize «ÞTCY +/// @todo àÁÆ©Õ¢R[hÉ·é +/// @attention K¸ÄÑoµOãÅt@CbNÆAbNð·é±Æ +void file_writefile(struct FILEINFO *finfo, char *buf, int dsize) +{ + int i, j = 0, l, ncno = 0, nsize, cn = finfo->clustno; + char *img = (char *)(ADR_DISKIMG + 0x003e00); + + /* Æè ¦¸¡ÌƱëÍAbvGh¾¯ */ + + for (;;) { + /* 512oCgÈãÌÆ«ÍfatHèȪç */ + /* ȺÉÈÁ½ç²¯é */ + nsize = finfo->size; + if (dsize <= 512) { + for (i = 0, j = 0;i < dsize;i++, j++) { + if (nsize + i >= 512) { + for (l = 0;nsize >= 512;nsize -= 512, l++) ; + for (;l > 0;l--) { + if (global_alloc_fat[cn] >= 0x0ff8) { + file_writefat(cn, 0x0fff); + ncno = file_getfat(global_alloc_fat); + file_writefat(cn, ncno); + } + cn = global_alloc_fat[cn]; } - j = 0; - } - img[cn * 512 + j + nsize] = buf[i]; - } - finfo->size += dsize; - if (global_alloc_fat[cn] == 0x1000) { - file_writefat(cn, 0x0fff); - } - break; - } - - for (i = 0;i < 512;i++) { - img[cn * 512 + i + finfo->size] = buf[i]; - } - dsize -= 512; - buf += 512; - finfo->size += 512; - cn = global_alloc_fat[cn]; - } - - return; -} - -/// @brief hists.logt@CÉL^·é -/// -/// histsR}hêp. -/// »êÈOÅÍgíÈ¢. -/// @param com «ÞR}hC -/// @note t@Cª³¯êÎAèÉ쬷é. -void write_history(char *cmdline) -{ - struct FILEINFO *finfo; - char s[256]; - - finfo = file_search(HISTORY_FILE, (struct FILEINFO *) (ADR_DISKIMG + 0x002600), 224); - if (!finfo) { - file_createfile(HISTORY_FILE, global_alloc_fat); - } - sprintf(s, "%s\n", cmdline); - file_writefile(finfo, s, strlen(s)); - - return; -} - -/// @brief t@CðÇÞ -/// @param clustno NX^io[ -/// @param size ÇÞTCY -/// @param buf Çñ¾f[^ÌÛ¶æ -void file_loadfile(int clustno, int size, char *buf) -{ - int i; - char *img = (char *)(ADR_DISKIMG + 0x003e00); - - for (;;) { - if (size <= 512) { - for (i = 0; i < size; i++) { - buf[i] = img[clustno * 512 + i]; - } - break; - } - for (i = 0; i < 512; i++) { - buf[i] = img[clustno * 512 + i]; - } - size -= 512; - buf += 512; - clustno = global_alloc_fat[clustno]; - } - - return; -} - -/// @brief t@CðT· -/// @param name t@C¼ -/// @param finfo t@Cf[^ -/// @param max Ååt@C -/// @return ©Â©çȯêÎ0AÝ©êλêÈO -struct FILEINFO *file_search(char *name, struct FILEINFO *finfo, int max) -{ - int i, j; - char s[12]; - - for (j = 0; j < 11; j++) { - s[j] = ' '; - } - j = 0; - for (i = 0; name[i] != 0; i++) { - if (j >= 11) { return 0; /* ©Â©çÈ©Á½ */ } - if (name[i] == '.' && j <= 8) { - j = 8; - } else { - s[j] = name[i]; - if ('a' <= s[j] && s[j] <= 'z') { - /* ¬¶Íå¶É¼· */ - s[j] -= 0x20; - } - j++; - } - } - for (i = 0; i < max; ) { - if (finfo->name[0] == 0x00) { - break; - } - if ((finfo[i].type & 0x18) == 0) { - for (j = 0; j < 11; j++) { - if (finfo[i].name[j] != s[j]) { - goto next; - } - } - return finfo + i; /* t@Cª©Â©Á½ */ - } -next: - i++; - } - - return 0; /* ©Â©çÈ©Á½ */ -} - -/// @brief tekðÆ¢Ät@CðÇÞ -/// @param clustno NX^io[ -/// @param psize ÇÞTCY -/// @param fat FAT -/// @return Çñ¾f[^ -char *file_loadfile2(int clustno, int *psize, int *fat) -{ - int size = *psize, size2; - char *buf, *buf2; - - buf = (char *) memman_alloc_4k(size); - file_loadfile(clustno, size, buf); - - if (size >= 17) { - size2 = tek_getsize(buf); - if (size2 > 0) { /* tek³kª©©ÁÄ¢½ */ - buf2 = (char *) memman_alloc_4k(size2); - tek_decomp(buf, buf2, size2); - memman_free_4k((int) buf, size); - buf = buf2; - *psize = size2; - } - } - - return buf; -} - -/// @brief tHgt@CÌÇÝÝ -/// @param filename t@C¼ -/// @param fontbuf tHgf[^ -void file_readfont(char *filename, UCHAR *fontbuf) -{ - struct FILEINFO *finfo; - int size; - extern char hankaku[4096]; - - finfo = file_search(filename, (struct FILEINFO *) (ADR_DISKIMG + 0x002600), 224); - if (finfo) { - size = finfo->size; - fontbuf = file_loadfile2(finfo->clustno, &size, global_alloc_fat); - } else { - fontbuf = (UCHAR *) memman_alloc_4k(16 * 256 + 32 * 94 * 47); - for (size = 0; size < 16 * 256; size++) { - fontbuf[size] = hankaku[size]; /* tHgªÈ©Á½ÌżpªðRs[ */ - } - for (size = 16 * 256; size < 16 * 256 + 32 * 94 * 47; size++) { - fontbuf[size] = 0xff; /* tHgªÈ©Á½ÌÅSpªð0xffÅßs· */ - } - } - - *((int *) 0x0fe8) = (int)fontbuf; - - return; -} + j = 0; + } + img[cn * 512 + j + nsize] = buf[i]; + } + finfo->size += dsize; + if (global_alloc_fat[cn] == 0x1000) { + file_writefat(cn, 0x0fff); + } + break; + } + + for (i = 0;i < 512;i++) { + img[cn * 512 + i + finfo->size] = buf[i]; + } + dsize -= 512; + buf += 512; + finfo->size += 512; + cn = global_alloc_fat[cn]; + } + + return; +} + +/// @brief t@CðÇÞ +/// @param clustno NX^io[ +/// @param size ÇÞTCY +/// @param buf Çñ¾f[^ÌÛ¶æ +/// @attention K¸ÄÑoµOãÅt@CbNÆAbNð·é±Æ +void file_loadfile(int clustno, int size, char *buf) +{ + int i; + char *img = (char *)(ADR_DISKIMG + 0x003e00); + + for (;;) { + if (size <= 512) { + for (i = 0; i < size; i++) { + buf[i] = img[clustno * 512 + i]; + } + break; + } + for (i = 0; i < 512; i++) { + buf[i] = img[clustno * 512 + i]; + } + size -= 512; + buf += 512; + clustno = global_alloc_fat[clustno]; + } + + return; +} + +/// @brief hists.logt@CÉL^·é +/// +/// histsR}hêp. +/// »êÈOÅÍgíÈ¢. +/// @param com «ÞR}hC +/// @note t@Cª³¯êÎAèÉ쬷é. +void write_history(char *cmdline) +{ + struct FILEINFO *finfo; + char s[256]; + + if (!file_exist(HISTORY_FILE)) { + file_createfile(HISTORY_FILE, global_alloc_fat); + } + finfo = file_search(HISTORY_FILE, (struct FILEINFO *) (ADR_DISKIMG + 0x002600), 224); + sprintf(s, "%s\n", cmdline); + + if (file_lock(HISTORY_FILE, task_now()->id)) { + file_writefile(finfo, s, strlen(s)); + file_unlock(HISTORY_FILE); + } + + return; +} + +/// @brief t@CðT· +/// @param name t@C¼ +/// @param finfo t@Cf[^ +/// @param max Ååt@C +/// @return ©Â©çȯêÎ0AÝ©êλêÈO +struct FILEINFO *file_search(char *name, struct FILEINFO *finfo, int max) +{ + int i, j; + char s[12]; + + for (j = 0; j < 11; j++) { + s[j] = ' '; + } + j = 0; + for (i = 0; name[i] != 0; i++) { + if (j >= 11) { return 0; /* ©Â©çÈ©Á½ */ } + if (name[i] == '.' && j <= 8) { + j = 8; + } else { + s[j] = name[i]; + if ('a' <= s[j] && s[j] <= 'z') { + /* ¬¶Íå¶É¼· */ + s[j] -= 0x20; + } + j++; + } + } + for (i = 0; i < max; ) { + if (finfo->name[0] == 0x00) { + break; + } + if ((finfo[i].type & 0x18) == 0) { + for (j = 0; j < 11; j++) { + if (finfo[i].name[j] != s[j]) { + goto next; + } + } + return finfo + i; /* t@Cª©Â©Á½ */ + } +next: + i++; + } + + return 0; /* ©Â©çÈ©Á½ */ +} + +/// @brief tekðÆ¢Ät@CðÇÞ +/// @param clustno NX^io[ +/// @param psize ÇÞTCY +/// @param fat FAT +/// @return Çñ¾f[^ +char *file_loadfile2(int clustno, int *psize, int *fat) +{ + int size = *psize, size2; + char *buf, *buf2; + + buf = (char *) memman_alloc_4k(size); + file_loadfile(clustno, size, buf); + + if (size >= 17) { + size2 = tek_getsize(buf); + if (size2 > 0) { /* tek³kª©©ÁÄ¢½ */ + buf2 = (char *) memman_alloc_4k(size2); + tek_decomp(buf, buf2, size2); + memman_free_4k((int) buf, size); + buf = buf2; + *psize = size2; + } + } + + return buf; +} + +/// @brief tHgt@CÌÇÝÝ +/// @param filename t@C¼ +/// @param fontbuf tHgf[^ +void file_readfont(char *filename, UCHAR *fontbuf) +{ + struct FILEINFO *finfo; + int size; + extern char hankaku[4096]; + + finfo = file_search(filename, (struct FILEINFO *) (ADR_DISKIMG + 0x002600), 224); + if (file_lock(filename, task_now()->id)) { + if (finfo) { + size = finfo->size; + fontbuf = file_loadfile2(finfo->clustno, &size, global_alloc_fat); + } else { + fontbuf = (UCHAR *) memman_alloc_4k(16 * 256 + 32 * 94 * 47); + for (size = 0; size < 16 * 256; size++) { + fontbuf[size] = hankaku[size]; /* tHgªÈ©Á½ÌżpªðRs[ */ + } + for (size = 16 * 256; size < 16 * 256 + 32 * 94 * 47; size++) { + fontbuf[size] = 0xff; /* tHgªÈ©Á½ÌÅSpªð0xffÅßs· */ + } + } + } + file_unlock(filename); + + *((int *) 0x0fe8) = (int)fontbuf; + + return; +} Added: trunk/kernel/lock.c =================================================================== --- trunk/kernel/lock.c (rev 0) +++ trunk/kernel/lock.c 2011-07-09 03:21:01 UTC (rev 168) @@ -0,0 +1,109 @@ +/// @file lock.c +/// @brief t@CbNÖW. +/// +/// t@CbNÉÖAµ½ðs¤ +/// @author JsZ + +#include "bootpack.h" + +/// @brief bN³ê½t@CXg +struct LOCKED_FILE locked_files[LOCKED_FILE_MAX]; + +/// @brief bN³ê½t@CXgðú» +void init_file_lock(void) +{ + int i; + + for (i = 0;i < LOCKED_FILE_MAX;i++) { + memset(locked_files[i].name, 0, FILENAME); + locked_files[i].flag = 0; + locked_files[i].taskid = 0; + locked_files[i].type = 0; + } + + return; +} + +/// @brief »Ìt@Cªwè³ê½IDÉbN³êÄ¢é©Ç¤© +/// @param fname t@C¼ +/// @param taskid ^XNID +/// @return bN³êÄ¢êÎ1A³êÄȯêÎ0 +/// @note taskid == 0 Èçt@C¼¾¯ÅÌmF +int file_islockedby(char *fname, int taskid) +{ + int i; + + if (taskid == 0) { + for (i = 0;i < LOCKED_FILE_MAX;i++) { + if (!strcmp(locked_files[i].name, fname) && + locked_files[i].flag == 1) { + return 1; + } + } + } else { + for (i = 0;i < LOCKED_FILE_MAX;i++) { + if (!strcmp(locked_files[i].name, fname) && + locked_files[i].taskid == taskid && + locked_files[i].flag == 1) { + return 1; + } + } + } + + return 0; +} + +/// @brief t@Cðwèµ½IDÅbN·é +/// @param fname bN·ét@C¼ +/// @param taskid ^XNID +/// @return bNÅ«êÎ1AūȯêÎ0 +int file_lock(char *fname, int taskid) +{ + int i; + + if (!file_exist(fname)) return 0; + if (file_islockedby(fname, taskid)) return 1; + if (!file_islockedby(fname, 0)) { + for (i = 0;i < LOCKED_FILE_MAX;i++) { + if (!locked_files[i].flag) { + strcpy(locked_files[i].name, fname); + locked_files[i].flag = 1; + locked_files[i].taskid = taskid; + return 1; + } + } + } + + return 0; +} + +/// @brief t@CÌbNðð +/// @param fname bNððt@C¼ +/// @return bNªð©êêÎ1A»¤ÅȯêÎ0 +int file_unlock(char *fname) +{ + int i; + + if (!file_exist(fname)) return 0; + + for (i = 0;i < LOCKED_FILE_MAX;i++) { + if (!strcmp(locked_files[i].name, fname)) { + locked_files[i].flag = 0; + return 1; + } + } + + return 0; +} + +/// @brief t@Cª¶Ý·é©Ç¤© +/// @param fname t@C¼ +/// @return ©Â©êÎ1A³¯êÎ0 +int file_exist(char *fname) +{ + if (file_search(fname, (struct FILEINFO *) (ADR_DISKIMG + 0x002600), 224)) { + return 1; + } + return 0; +} + Modified: trunk/kernel/memory.c =================================================================== --- trunk/kernel/memory.c 2011-05-25 14:46:49 UTC (rev 167) +++ trunk/kernel/memory.c 2011-07-09 03:21:01 UTC (rev 168) @@ -215,4 +215,12 @@ UINT32 get_totalmem(void) { return memtest(0x00400000, 0xbfffffff); +} + +/// @brief Ê\¦On/Off +/// @param On©Off +void mem_display_on(int on) +{ + if (on) ((struct MEMMAN *) MEMMAN_ADDR)->disp = 1; + else ((struct MEMMAN *) MEMMAN_ADDR)->disp = 0; } Modified: trunk/kernel/mtask.c =================================================================== --- trunk/kernel/mtask.c 2011-05-25 14:46:49 UTC (rev 167) +++ trunk/kernel/mtask.c 2011-07-09 03:21:01 UTC (rev 168) @@ -69,6 +69,8 @@ } /// @brief J[l^XNÌú»Æ}`^XNÌõ +/// +/// ¯ÉACh^XNàìÁÄo^µÄ¢é /// @return J[l^XN struct TASK *task_init(void) {