[Negitoro-svn] [168] Negitoro 0.0.1 (unstable)

Back to archive index

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ƒ@ƒCƒ‹Œn */
 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‰Â”\ƒVƒŠƒAƒ‹ƒ|[ƒ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‚ƃ}ƒEƒX‚É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) */
-	/* ƒ}ƒEƒX‚ð‹–‰Â(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 @@
 		ƒVƒXƒeƒ€‹N“® 
 		
 	-------------------*/
+
+	/* FAT‚ÌŠm•Û‚ƃVƒXƒeƒ€ƒ^ƒXƒN‹N“® */
+	alloc_global_fat();
+	init_run_system(task_a, &fifo);
 	
-	/* ƒVƒXƒeƒ€ƒ^ƒXƒN */
-	task_run(task_a, 1, 2, "system");
-	fifo.task = task_a;
-	task_a->langmode = 0;
-	debugmsg("Running kernel..");
+	/* ƒtƒ@ƒCƒ‹ƒƒbƒNƒŠƒXƒg‚̏‰Šú‰»‚Æ“o˜^  */
+	init_file_lock();
+	file_lock(SYSTEMFILE_NAME, task_now()->id);
 	
 	/* ”wŒi(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..");
-	
 	/* ƒtƒHƒ“ƒg“ǂݍž‚Ý */
 	file_readfont(FONTFILE, nihongo);
 	debugmsg("Font loaded.. (%s)", FONTFILE);
@@ -144,7 +135,7 @@
 	----------------------------*/
 	
 	/* ‰Eã‚̃ƒ‚ƒŠ•\Ž¦ŠJŽn */
-	((struct MEMMAN *) MEMMAN_ADDR)->disp = 1;
+	mem_display_on(1);
 
 	/* ƒ}ƒEƒX•\Ž¦ */
 	sheet_slide(sht_mouse, mx, my);
@@ -490,6 +481,37 @@
 	}
 }
 
+/// @brief ƒVƒXƒeƒ€ƒ^ƒXƒN‚ð‹N“®‚·‚é
+/// @param task Š„‚è“–‚Ä‚éƒ^ƒXƒN
+/// @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 PITAPIC1‚ƃL[ƒ{[ƒhAƒ}ƒEƒX‚ð‹–‰Â
+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	///<Žg—p‰Â”\ƒV[ƒg”‚̍őå
@@ -422,9 +423,10 @@
 };
 /// @brief ƒtƒ@ƒCƒ‹ƒnƒ“ƒhƒ‹
 struct FILEHANDLE {
-	char *buf;	///< ƒf[ƒ^
-	int size;	///< ƒtƒ@ƒCƒ‹ƒTƒCƒY
-	int pos;	///< “ǂ܂ꂽƒ|ƒWƒVƒ‡ƒ“
+	char *fname;	///< ƒtƒ@ƒCƒ‹–¼
+	char *buf;		///< ƒf[ƒ^
+	int size;		///< ƒtƒ@ƒCƒ‹ƒTƒCƒY
+	int pos;		///< “ǂ܂ꂽƒ|ƒWƒVƒ‡ƒ“
 };
 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ƒ@ƒCƒ‹ƒf[ƒ^
 struct FILEINFO {
 	UCHAR name[8];		///< ƒtƒ@ƒCƒ‹–¼
@@ -489,6 +492,7 @@
 	USHORT clustno;		///< ƒNƒ‰ƒXƒ^”ԍ†
 	UINT32 size;		///< ƒtƒ@ƒCƒ‹ƒTƒCƒY
 };
+
 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 ///< Å‘働ƒbƒNƒtƒ@ƒCƒ‹”
+/// @brief ƒƒbƒN‚³‚ê‚Ä‚¢‚éƒtƒ@ƒCƒ‹ƒf[ƒ^
+struct LOCKED_FILE {
+	UCHAR name[11];		///< ƒtƒ@ƒCƒ‹–¼
+	int flag;			///< ”Ä—pƒtƒ‰ƒO
+	int taskid;			///< ƒƒbƒN‚µ‚Ä‚¢‚éƒ^ƒXƒN‚ÌID
+	int type;			///< Ží—ށiƒtƒ@ƒCƒ‹Aƒ|[ƒgAetcj
+};
+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 -rnƒIƒvƒVƒ‡ƒ“‚ÌŽÀ‘•
 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ƒ‹‚̃ƒbƒN */
+			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ƒ‹‚̃ƒbƒN‚ð‰ð‚­ */
+			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)) {
+			/* ƒƒbƒN‚³‚ꂽƒ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 @@
 	/* ƒ^ƒXƒN‚ªƒRƒ“ƒ\[ƒ‹‚Å‚È‚¯‚ê‚΃_ƒ */
 	if (!task->cons) return;
 	cons = task->cons;
+
+	/* ‰½‚©‚ªƒRƒ}ƒ“ƒhƒ‰ƒCƒ“‚É‘¶Ý‚µ‚½‚ç */
+	if (cmdline[0]) write_history(cmdline);
 	
 	/* ƒRƒ}ƒ“ƒhˆ— */
 	if (!strcmp(name, "mem") && cons->sht) cmd_mem();
@@ -470,19 +473,9 @@
 			/* ƒRƒ}ƒ“ƒh‚Å‚Í‚È‚­AƒAƒvƒŠ‚Å‚à‚È‚­A‚³‚ç‚É‹ós‚Å‚à‚È‚¢ */
 			cputs0("It may be wrong command or not existing file.");
 		}
-		j = 0;
 	}
-
 	
-	/* ‰½‚©‚ªƒRƒ}ƒ“ƒhƒ‰ƒCƒ“‚É‘¶Ý‚µ‚½‚ç */
-	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 ƒfƒBƒXƒNƒCƒ[ƒW“à‚ÌFAT‚̈³k‚ð‚Æ‚­
-/// @param fat ˆ³k‚ð‚Æ‚­FAT
-/// @param img ƒfƒBƒXƒNƒCƒ[ƒW‚̃AƒhƒŒƒX
-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‚©‚ç—¬—pBŽd‘g‚Ý‚Í—Ç‚­•ª‚©‚ç‚È‚¢B
-/// @param no FAT‚Ì‚Ç‚±‚©
-/// @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‚Ì‚à‚̂ƈꏏ‚ɍXV */
-		j = global_alloc_fat[no - 1];
-		k = global_alloc_fat[no];
-
 	} else {	/* no‚ªŠï”‚È‚çŒã‚ë‚Ì‚à‚̂ƈꏏ‚ɍXV */
-		j = global_alloc_fat[no];
-		k = global_alloc_fat[no + 1];
-	}
-
-	/* ƒ}ƒXƒ^‚ðXV */
-	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‚ðXV */
-	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 Žæ“¾‚Å‚«‚È‚¯‚ê‚Î0A‚Å‚«‚½‚ç‚»‚êˆÈŠ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 íœ‚Å‚«‚½‚ç0A‚»‚¤‚Å‚È‚¯‚ê‚Î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 ì¬‚Å‚«‚È‚¯‚ê‚Î0A‚Å‚«‚½‚ç‚»‚êˆÈŠ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 ‘‚«ž‚ÞƒTƒCƒY
-/// @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);
-	
-	/* ‚Æ‚è‚ ‚¦‚¸¡‚Ì‚Æ‚±‚ë‚̓AƒbƒvƒGƒ“ƒh‚¾‚¯     */
-	
-	for (;;) {
-		/* 512ƒoƒCƒgˆÈã‚Ì‚Æ‚«‚Ífat’H‚è‚È‚ª‚ç */
-		/* ˆÈ‰º‚É‚È‚Á‚½‚甲‚¯‚é */
-		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 ƒfƒBƒXƒNƒCƒ[ƒW“à‚ÌFAT‚̈³k‚ð‚Æ‚­
+/// @param fat ˆ³k‚ð‚Æ‚­FAT
+/// @param img ƒfƒBƒXƒNƒCƒ[ƒW‚̃AƒhƒŒƒX
+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‚©‚ç—¬—pBŽd‘g‚Ý‚Í—Ç‚­•ª‚©‚ç‚È‚¢B
+/// @param no FAT‚Ì‚Ç‚±‚©
+/// @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‚Ì‚à‚̂ƈꏏ‚ɍXV */
+		j = global_alloc_fat[no - 1];
+		k = global_alloc_fat[no];
+	} else {	/* no‚ªŠï”‚È‚çŒã‚ë‚Ì‚à‚̂ƈꏏ‚ɍXV */
+		j = global_alloc_fat[no];
+		k = global_alloc_fat[no + 1];
+	}
+
+	/* ƒ}ƒXƒ^‚ðXV */
+	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‚ðXV */
+	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 Žæ“¾‚Å‚«‚È‚¯‚ê‚Î0A‚Å‚«‚½‚ç‚»‚êˆÈŠ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 íœ‚Å‚«‚½‚ç0A‚»‚¤‚Å‚È‚¯‚ê‚Î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 ì¬‚Å‚«‚È‚¯‚ê‚Î0A‚Å‚«‚½‚ç‚»‚êˆÈŠ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 ‘‚«ž‚ÞƒTƒCƒY
+/// @todo ‚à‚Á‚ÆŒ©ˆÕ‚¢ƒR[ƒh‚É‚·‚é
+/// @attention •K‚¸ŒÄ‚яo‚µ‘OŒã‚Ńtƒ@ƒCƒ‹ƒƒbƒN‚ƃAƒ“ƒƒbƒN‚ð‚·‚é‚±‚Æ
+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);
+	
+	/* ‚Æ‚è‚ ‚¦‚¸¡‚Ì‚Æ‚±‚ë‚̓AƒbƒvƒGƒ“ƒh‚¾‚¯ */
+	
+	for (;;) {
+		/* 512ƒoƒCƒgˆÈã‚Ì‚Æ‚«‚Ífat’H‚è‚È‚ª‚ç */
+		/* ˆÈ‰º‚É‚È‚Á‚½‚甲‚¯‚é */
+		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.logƒtƒ@ƒCƒ‹‚É‹L˜^‚·‚é
-///
-/// histsƒRƒ}ƒ“ƒhê—p.
-/// ‚»‚êˆÈŠO‚Å‚ÍŽg‚í‚È‚¢.
-/// @param com ‘‚«ž‚ÞƒRƒ}ƒ“ƒhƒ‰ƒCƒ“
-/// @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 ƒNƒ‰ƒXƒ^ƒiƒ“ƒo[
-/// @param size “Ç‚ÞƒTƒCƒY
-///
  @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ƒ@ƒCƒ‹ƒf[ƒ^
-/// @param max Å‘åƒtƒ@ƒCƒ‹”
-/// @return Œ©‚‚©‚ç‚È‚¯‚ê‚Î0A‚݂‚©‚ê‚΂»‚êˆÈŠ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 ƒNƒ‰ƒXƒ^ƒiƒ“ƒo[
-/// @param psize “Ç‚ÞƒTƒCƒY
-/// @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 ƒtƒHƒ“ƒgƒtƒ@ƒCƒ‹‚̓ǂݍž‚Ý
-/// @param filename ƒtƒ@ƒCƒ‹–¼
-/// @param fontbuf ƒtƒHƒ“ƒgƒf[ƒ^
-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]; /* ƒtƒHƒ“ƒg‚ª‚È‚©‚Á‚½‚Ì‚Å”¼Šp•”•ª‚ðƒRƒs[ */
-		}
-		for (size = 16 * 256; size < 16 * 256 + 32 * 94 * 47; size++) {
-			fontbuf[size] = 0xff; /* ƒtƒHƒ“ƒg‚ª‚È‚©‚Á‚½‚Ì‚Å‘SŠp•”•ª‚ð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 ƒNƒ‰ƒXƒ^ƒiƒ“ƒo[
+/// @param size “Ç‚ÞƒTƒCƒY
+/// @param buf “Ç‚ñ‚¾ƒf[ƒ^‚Ì•Û‘¶æ
+/// @attention •K‚¸ŒÄ‚яo‚µ‘OŒã‚Ńtƒ@ƒCƒ‹ƒƒbƒN‚ƃAƒ“ƒƒbƒN‚ð‚·‚é‚±‚Æ
+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.logƒtƒ@ƒCƒ‹‚É‹L˜^‚·‚é
+///
+/// histsƒRƒ}ƒ“ƒhê—p.
+/// ‚»‚êˆÈŠO‚Å‚ÍŽg‚í‚È‚¢.
+/// @param com ‘‚«ž‚ÞƒRƒ}ƒ“ƒhƒ‰ƒCƒ“
+/// @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ƒ@ƒCƒ‹ƒf[ƒ^
+/// @param max Å‘åƒtƒ@ƒCƒ‹”
+/// @return Œ©‚‚©‚ç‚È‚¯‚ê‚Î0A‚݂‚©‚ê‚΂»‚êˆÈŠ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 ƒNƒ‰ƒXƒ^ƒiƒ“ƒo[
+/// @param psize “Ç‚ÞƒTƒCƒY
+/// @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 ƒtƒHƒ“ƒgƒtƒ@ƒCƒ‹‚̓ǂݍž‚Ý
+/// @param filename ƒtƒ@ƒCƒ‹–¼
+/// @param fontbuf ƒtƒHƒ“ƒgƒf[ƒ^
+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]; /* ƒtƒHƒ“ƒg‚ª‚È‚©‚Á‚½‚Ì‚Å”¼Šp•”•ª‚ðƒRƒs[ */
+			}
+			for (size = 16 * 256; size < 16 * 256 + 32 * 94 * 47; size++) {
+				fontbuf[size] = 0xff; /* ƒtƒHƒ“ƒg‚ª‚È‚©‚Á‚½‚Ì‚Å‘SŠp•”•ª‚ð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ƒ@ƒCƒ‹ƒƒbƒNŠÖŒW.
+///
+/// ƒtƒ@ƒCƒ‹ƒƒbƒN‚ÉŠÖ˜A‚µ‚½ˆ—‚ðs‚¤
+/// @author JsZ
+
+#include "bootpack.h"
+
+/// @brief ƒƒbƒN‚³‚ꂽƒtƒ@ƒCƒ‹ƒŠƒXƒg
+struct LOCKED_FILE locked_files[LOCKED_FILE_MAX];
+
+/// @brief ƒƒbƒN‚³‚ꂽƒtƒ@ƒCƒ‹ƒŠƒXƒg‚ð‰Šú‰»
+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‚ɃƒbƒN‚³‚ê‚Ä‚¢‚é‚©‚Ç‚¤‚©
+/// @param fname ƒtƒ@ƒCƒ‹–¼
+/// @param taskid ƒ^ƒXƒNID
+/// @return ƒƒbƒN‚³‚ê‚Ä‚¢‚ê‚Î1A‚³‚ê‚Ä‚È‚¯‚ê‚Î0
+/// @note taskid == 0 ‚È‚çƒtƒ@ƒCƒ‹–¼‚¾‚¯‚Å‚ÌŠm”F
+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‚эƒbƒN‚·‚é
+/// @param fname ƒƒbƒN‚·‚éƒtƒ@ƒCƒ‹–¼
+/// @param taskid ƒ^ƒXƒNID
+/// @return ƒƒbƒN‚Å‚«‚ê‚Î1A‚Å‚«‚È‚¯‚ê‚Î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ƒ‹‚̃ƒbƒN‚ð‰ð‚­
+/// @param fname ƒƒbƒN‚ð‰ð‚­ƒtƒ@ƒCƒ‹–¼
+/// @return ƒƒbƒN‚ª‰ð‚©‚ê‚ê‚Î1A‚»‚¤‚Å‚È‚¯‚ê‚Î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 Œ©‚‚©‚ê‚Î1A–³‚¯‚ê‚Î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ƒ‹ƒ^ƒXƒN‚̏‰Šú‰»‚ƃ}ƒ‹ƒ`ƒ^ƒXƒN‚̏€”õ
+///
+/// “¯Žž‚ɃAƒCƒhƒ‹ƒ^ƒXƒN‚àì‚Á‚Ä“o˜^‚µ‚Ä‚¢‚é
 /// @return ƒJ[ƒlƒ‹ƒ^ƒXƒN
 struct TASK *task_init(void)
 {




Negitoro-svn メーリングリストの案内
Back to archive index