示例#1
0
//一个小应用程序
void cmd_hlt(CONSOLE *console, int *fat)
{
	MEMMANAGE *memmanage = (MEMMANAGE *)MEMMANAGE_ADDR;
	FILEINFO *finfo = file_search("HLT.HRB", (FILEINFO *)(ADR_DISKIMG + 0x002600), 224);
	SEGMENT_DESCRIPTOR *gdt = (SEGMENT_DESCRIPTOR *)ADR_GDT;
	char *img_adr;
	/*找到这个应用程序的情况*/
	if(0 != finfo)
	{
		//文件内容开始的地址赋值给img_adr
		img_adr = (char *)memmanage_alloc_4K(memmanage, finfo->size);
		//把可能有间断的文件内容复制到一块儿连续的内存中去,这样就可以直接到这块儿内存进行连续的读取了
		file_loadfile(finfo->clusterno, finfo->size, img_adr, fat, (char *)(0x003e00 + ADR_DISKIMG));
		//为这个任务分配一个内存段
		set_segmdesc(gdt + 1003, finfo->size - 1, (int)img_adr, AR_CODE32_ER);
		//跳转到这个hlt任务所在的内存开始执行
		farcall(0, 1003 * 8);
		memmanage_free_4K(memmanage, (int)img_adr, finfo->size);
	}
	/*无法找到这个应用程序的情况*/
	else
	{
		displayStrings_atLayer(console->layer, 8, console->cursor_y, COL8_FFFFFF, COL8_000000, "File not found!");
		console_newline(console);
	}
	console_newline(console);
}
示例#2
0
//显示文件内容的函数
void cmd_type(CONSOLE *console, int *fat, char *cmdline)
{
	MEMMANAGE *memmanage = (MEMMANAGE *)MEMMANAGE_ADDR;
	FILEINFO *finfo = file_search(cmdline + 5, (FILEINFO *)(ADR_DISKIMG + 0x002600), 224);
	char *img_adr;
	int i;
	//文件找到的情况,把内容逐字打印出来
	if(0 != finfo)
	{
		//文件内容开始的地址赋值给img_adr
		img_adr = (char *)memmanage_alloc_4K(memmanage, finfo->size);
		//把可能有间断的文件内容复制到一块儿连续的内存中去,这样就可以直接到这块儿内存进行连续的读取了
		file_loadfile(finfo->clusterno, finfo->size, img_adr, fat, (char *)(0x003e00 + ADR_DISKIMG));
		for(i = 0; i < finfo->size; i++)
		{
			console_putchar(console, img_adr[i], 1);
		}
		memmanage_free_4K(memmanage, (int)img_adr, finfo->size);
	}
	//文件没有找到的情况,打印出错误信息
	else
	{
		displayStrings_atLayer(console->layer, 8, console->cursor_y, COL8_FFFFFF, COL8_000000, "File not found!");
		console_newline(console);
	}
	console_newline(console);
	return ;
}
示例#3
0
int cmd_app(struct CONSOLE *cons, int *fat, char *cmdline)
{
	struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR;
	struct FILEINFO *finfo;
	struct SEGMENT_DESCRIPTOR *gdt = (struct SEGMENT_DESCRIPTOR *) ADR_GDT;
	char name[13], *p, *q;
	struct TASK *task = task_now();
	int i, segsiz, datsiz, esp, dathrb;

	/* コマンドラインからファイル名を生成 */
	for (i = 0; i < 8; i++) {
		if (cmdline[i] <= ' ') {
			break;
		}
		name[i] = cmdline[i];
	}
	name[i] = 0; /* とりあえずファイル名の後ろを0にする */

	/* ファイルを探す */
	finfo = file_search(name, (struct FILEINFO *) (ADR_DISKIMG + 0x002600), 224);
	if (finfo == 0) {
		/* 見つからなかったので後ろに".HRB"をつけてもう一度探してみる */
		name[i    ] = '.';
		name[i + 1] = 'H';
		name[i + 2] = 'R';
		name[i + 3] = 'B';
		name[i + 4] = 0;
		finfo = file_search(name, (struct FILEINFO *) (ADR_DISKIMG + 0x002600), 224);
	}

	if (finfo != 0) {
		/* ファイルが見つかった場合 */
		p = (char *) memman_alloc_4k(memman, finfo->size);
		file_loadfile(finfo->clustno, finfo->size, p, fat, (char *) (ADR_DISKIMG + 0x003e00));
		if (finfo->size >= 36 && strncmp(p + 4, "Hari", 4) == 0 && *p == 0x00) {
			segsiz = *((int *) (p + 0x0000));
			esp    = *((int *) (p + 0x000c));
			datsiz = *((int *) (p + 0x0010));
			dathrb = *((int *) (p + 0x0014));
			q = (char *) memman_alloc_4k(memman, segsiz);
			*((int *) 0xfe8) = (int) q;
			set_segmdesc(gdt + 1003, finfo->size - 1, (int) p, AR_CODE32_ER + 0x60);
			set_segmdesc(gdt + 1004, segsiz - 1,      (int) q, AR_DATA32_RW + 0x60);
			for (i = 0; i < datsiz; i++) {
				q[esp + i] = p[dathrb + i];
			}
			start_app(0x1b, 1003 * 8, esp, 1004 * 8, &(task->tss.esp0));
			memman_free_4k(memman, (int) q, segsiz);
		} else {
			cons_putstr0(cons, ".hrb file format error.\n");
		}
		memman_free_4k(memman, (int) p, finfo->size);
		cons_newline(cons);
		return 1;
	}
	/* ファイルが見つからなかった場合 */
	return 0;
}
示例#4
0
文件: console.c 项目: songtzu/study
static int 
hlt_command(segment_descriptor_t* gdt, 
    mem_mgr_t* memmgr, layer_t* layer, int* fat, int cursor_y)
{
  /* hlt command */
  fileinfo_t* finfo = (fileinfo_t*)(ADR_DISKIMG + 0x002600);
  int x, y;
  char buf[32];
  char* p;

  for (y = 0; y < 11; ++y)
    buf[y] = ' ';
  buf[0] = 'H';
  buf[1] = 'L';
  buf[2] = 'T';
  buf[8] = 'T';
  buf[9] = 'O';
  buf[10] = 'Y';

  for (x = 0; x < 224; ) {
    if (0x00 == finfo[x].name[0])
      break;

    if (0 == (finfo[x].type & 0x18)) {
      for (y = 0; y < 11; ++y) {
        if (finfo[x].name[y] != buf[y])
          goto __hlt_next_file;
      }
      break;  /* found the file */
    }
__hlt_next_file:
    ++x;
  }

  if (x < 224 && (0x00 != finfo[x].name[0])) {
    /* found the file */
    p = (char*)mem_mgr_alloc_4k(memmgr, finfo[x].size);
    file_loadfile(finfo[x].clustno, finfo[x].size, 
        p, fat, (char*)(ADR_DISKIMG + 0x003e00));
    set_segment_descriptor(gdt + 1003, 
        finfo[x].size - 1, (int)p, AR_CODE32_ER);
    farjump(0, 1003 * 8);
    mem_mgr_free_4k(memmgr, (int)p, finfo[x].size);
  }
  else {
    /* do not found the file */
    drawstring_and_refresh(layer, 8, cursor_y, 
        COLOR8_FFFFFF, COLOR8_000000, "File not found.", 15);
    cursor_y = console_newline(cursor_y, layer);
  }

  return console_newline(cursor_y, layer);
}
示例#5
0
int cmd_app(struct CONSOLE *cons, int *fat, char *cmdline)
{
	struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR;
	struct FILEINFO *finfo;
	struct SEGMENT_DESCRIPTOR *gdt = (struct SEGMENT_DESCRIPTOR *) ADR_GDT;
	char name[18], *p;
	int i;

	/* 根据命令行生成文件名 */
	for (i = 0; i < 13; i++) {
		if (cmdline[i] <= ' ') {
			break;
		}
		name[i] = cmdline[i];
	}
	name[i] = 0;                                                /* 暂且将文件名的后面置位0 */
	
	/* 寻找文件 */
	finfo = file_search(name, (struct FILEINFO *) (ADR_DISKIMG + 0x002600), 224);
	if (finfo == 0 && name[i - 1] != '.') {
		/* 由于找不到文件,故在文件名后面加上“.hrb”后重新寻找 */
		name[i    ] = '.';
		name[i + 1] = 'F';
		name[i + 2] = 'E';
		name[i + 3] = 'X';
		name[i + 4] = 0;
		finfo = file_search(name, (struct FILEINFO *) (ADR_DISKIMG + 0x002600), 224);
	}

	if (finfo != 0) {
		/* 找到文件的情况 */
		p = (char *) memman_alloc_4k(memman, finfo->size);
		*((int *) 0xfe8) = (int) p;
		file_loadfile(finfo->clustno, finfo->size, p, fat, (char *) (ADR_DISKIMG + 0x003e00));
		set_segmdesc(gdt + 1003, finfo->size - 1, (int) p, AR_CODE32_ER); // *.fex成功读入内存之后,将其注册为GDT的1003号。1-2号有dsctbl.c使用,3-1002号由mtask.c使用。
		if (finfo->size >= 8 && strncmp(p + 4, "Hari", 4) == 0) {
			p[0] = 0xe8;
			p[1] = 0x16;
			p[2] = 0x00;
			p[3] = 0x00;
			p[4] = 0x00;
			p[5] = 0xcb;
		}
		farcall(0, 1003 * 8);
		memman_free_4k(memman, (int) p, finfo->size);
		cons_newline(cons);
		return 1;
	}
	/* 没有找到文件的情况 */
	return 0;
}
示例#6
0
int cmd_app(struct CONSOLE *cons, int *fat, char *cmdline)
{
	struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR;
	struct FILEINFO *finfo;
	struct SEGMENT_DESCRIPTOR *gdt = (struct SEGMENT_DESCRIPTOR *) ADR_GDT;
	char name[18], *p, *q;
	struct TASK *task = task_now();
	int i;

	/* コマンドラインからファイル名を生成 */
	for (i = 0; i < 13; i++) {
		if (cmdline[i] <= ' ') {
			break;
		}
		name[i] = cmdline[i];
	}
	name[i] = 0; /* とりあえずファイル名の後ろを0にする */

	/* ファイルを探す */
	finfo = file_search(name, (struct FILEINFO *) (ADR_DISKIMG + 0x002600), 224);
	if (finfo == 0 && name[i - 1] != '.') {
		/* 見つからなかったので後ろに".HRB"をつけてもう一度探してみる */
		name[i    ] = '.';
		name[i + 1] = 'H';
		name[i + 2] = 'R';
		name[i + 3] = 'B';
		name[i + 4] = 0;
		finfo = file_search(name, (struct FILEINFO *) (ADR_DISKIMG + 0x002600), 224);
	}

	if (finfo != 0) {
		/* ファイルが見つかった場合 */
		p = (char *) memman_alloc_4k(memman, finfo->size);
		q = (char *) memman_alloc_4k(memman, 64 * 1024);
		*((int *) 0xfe8) = (int) p;
		file_loadfile(finfo->clustno, finfo->size, p, fat, (char *) (ADR_DISKIMG + 0x003e00));
		set_segmdesc(gdt + 1003, finfo->size - 1, (int) p, AR_CODE32_ER + 0x60);
		set_segmdesc(gdt + 1004, 64 * 1024 - 1,   (int) q, AR_DATA32_RW + 0x60);
		if (finfo->size >= 8 && strncmp(p + 4, "Hari", 4) == 0) {
			start_app(0x1b, 1003 * 8, 64 * 1024, 1004 * 8, &(task->tss.esp0));
		} else {
			start_app(0, 1003 * 8, 64 * 1024, 1004 * 8, &(task->tss.esp0));
		}
		memman_free_4k(memman, (int) p, finfo->size);
		memman_free_4k(memman, (int) q, 64 * 1024);
		cons_newline(cons);
		return 1;
	}
	/* ファイルが見つからなかった場合 */
	return 0;
}
示例#7
0
int cmd_app (struct CONSOLE *cons, int *fat, char *cmdline)
{
  struct MEMMAN *memman = (struct MEMMAN *)MEMMAN_ADDR;
  struct FILEINFO *finfo;
  struct SEGMENT_DESCRIPTOR *gdt = (struct SEGMENT_DESCRIPTOR *)ADR_GDT;
  char name [18];
  int i;
  struct TASK *task = task_now ();
  
  for (i = 0; i < 13; i++) {
    if (cmdline[i] <= ' ') {
      break;
    }
    name[i] = cmdline[i];
  }
  name[i] = 0;
  finfo = file_search (name, (struct FILEINFO *)(ADR_DISKIMG + 0x002600), 224);
  if (finfo == 0 && name[i-1] != '.') {
    name [i+0]  = '.';
    name [i+1]  = 'H';
    name [i+2]  = 'R';
    name [i+3]  = 'B';
    name [i+4]  = 0;
    finfo = file_search (name, (struct FILEINFO *)(ADR_DISKIMG + 0x002600), 224);
  }

  if (finfo != 0) {
    char *p = (char *)memman_alloc_4k (memman, finfo->size);
	char *q = (char *)memman_alloc_4k (memman, 64 * 1024);
    *((int *) 0xfe8) = (int) p;
    file_loadfile (finfo->clustno, finfo->size, p, fat, (char *) (ADR_DISKIMG + 0x003e00));
    set_segmdesc (gdt + 1003, finfo->size - 1, (int) p, AR_CODE32_ER + 0x60);
	set_segmdesc (gdt + 1004, 64 * 1024 - 1,   (int) q, AR_DATA32_RW + 0x60);
    if (finfo->size >= 8 && strncmp (p + 4, "Hari", 4) == 0) {
      p[0] = 0xe8;
      p[1] = 0x16;
      p[2] = 0x00;
      p[3] = 0x00;
      p[4] = 0x00;
      p[5] = 0xcb;
    }
	start_app (0, 1003 * 8, 64 * 1024, 1004 * 8, &(task->tss.esp0));
    memman_free_4k (memman, (int) p, finfo->size);
	memman_free_4k (memman, (int) q, 64 * 1024);
    cons_newline (cons);
    return 1;
  }

  return 0;
}
示例#8
0
void cmd_type(struct CONSOLE *cons, int *fat, char *cmdline)
{
	struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR;
	struct FILEINFO *finfo = file_search(cmdline + 5, (struct FILEINFO *) (ADR_DISKIMG + 0x002600), 224);
	char *p;
	if (finfo != 0) {
		/* ファイルが見つかった場合 */
		p = (char *) memman_alloc_4k(memman, finfo->size);
		file_loadfile(finfo->clustno, finfo->size, p, fat, (char *) (ADR_DISKIMG + 0x003e00));
		cons_putstr1(cons, p, finfo->size);
		memman_free_4k(memman, (int) p, finfo->size);
	} else {
		/* ファイルが見つからなかった場合 */
		cons_putstr0(cons, "File not found.\n");
	}
	cons_newline(cons);
	return;
}
示例#9
0
int cmd_app(struct CONSOLE *cons, int *fat, char *cmdline) {
    struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR;
    struct FILEINFO *finfo;
    struct SEGMENT_DESCRIPTOR *gdt = (struct SEGMENT_DESCRIPTOR *) ADR_GDT;
    char name[18], *p;
    int i;

    for (i = 0; i < 13; i++) {
        if (cmdline[i] <= ' ') {
            break;
        }
        name[i] = cmdline[i];
    }
    name[i] = 0;

    finfo = file_search(name, (struct FILEINFO *) (ADR_DISKIMG + 0x002600), 224);
    if (finfo == 0 && name[i-1] != '.') {
        /* 
         * If the file cannot be found
         * Search <filename>.hrb instead
         */
        name[i] = '.';
        name[i + 1] = 'H';
        name[i + 2] = 'R';
        name[i + 3] = 'B';
        name[i + 4] = 0;
        finfo = file_search(name, (struct FILEINFO *) (ADR_DISKIMG + 0x002600), 224);
    }

    if (finfo != 0) {
        /* File is found */
        p = (char *) memman_alloc_4k(memman, finfo->size);
        file_loadfile(finfo->clustno, finfo->size, p, fat, (char *) (ADR_DISKIMG + 0x003e00));
        /* Assign 1003 Segment */
        set_segmdesc(gdt + 1003, finfo->size - 1, (int) p, AR_CODE32_ER);
        farcall(0, 1003 * 8);
        memman_free_4k(memman, (int) p, finfo->size);
        cons_newline(cons);
        return 1;
    }
    return 0;
}
示例#10
0
void cmd_hlt(struct CONSOLE *cons, int *fat)
{
	struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR;
	struct FILEINFO *finfo = file_search("HLT.HRB", (struct FILEINFO *) (ADR_DISKIMG + 0x002600), 224);
	struct SEGMENT_DESCRIPTOR *gdt = (struct SEGMENT_DESCRIPTOR *) ADR_GDT;
	char *p;
	if (finfo != 0) {
		/* ファイルが見つかった場合 */
		p = (char *) memman_alloc_4k(memman, finfo->size);
		file_loadfile(finfo->clustno, finfo->size, p, fat, (char *) (ADR_DISKIMG + 0x003e00));
		set_segmdesc(gdt + 1003, finfo->size - 1, (int) p, AR_CODE32_ER);
		farjmp(0, 1003 * 8);
		memman_free_4k(memman, (int) p, finfo->size);
	} else {
		/* ファイルが見つからなかった場合 */
		putfonts8_asc_sht(cons->sht, 8, cons->cur_y, COL8_FFFFFF, COL8_000000, "File not found.", 15);
		cons_newline(cons);
	}
	cons_newline(cons);
	return;
}
示例#11
0
void cmd_type(struct CONSOLE *cons, int *fat, char *cmdline)
{
	struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR;
	struct FILEINFO *finfo = file_search(cmdline + 5, (struct FILEINFO *) (ADR_DISKIMG + 0x002600), 224);
	char *p;
	int i;
	if (finfo != 0) {
		/* ファイルが見つかった場合 */
		p = (char *) memman_alloc_4k(memman, finfo->size);
		file_loadfile(finfo->clustno, finfo->size, p, fat, (char *) (ADR_DISKIMG + 0x003e00));
		for (i = 0; i < finfo->size; i++) {
			cons_putchar(cons, p[i], 1);
		}
		memman_free_4k(memman, (int) p, finfo->size);
	} else {
		/* ファイルが見つからなかった場合 */
		putfonts8_asc_sht(cons->sht, 8, cons->cur_y, COL8_FFFFFF, COL8_000000, "File not found.", 15);
		cons_newline(cons);
	}
	cons_newline(cons);
	return;
}
示例#12
0
int cmd_app(struct CONSOLE *cons, int *fat,char *cmdline)
{
	struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR;
	struct FILEINFO *finfo = file_search("HLT.HRB", (struct FILEINFO *) (ADR_DISKIMG + 0x002600), 224);
	struct SEGMENT_DESCRIPTOR *gdt = (struct SEGMENT_DESCRIPTOR *) ADR_GDT;
	char *p,name[18];
	int i;
	for(i=0;i <13; i++)
	{
		if(cmdline[i] <= ' ')
			break;
		name[i] = cmdline[i];
		
	}
	name[i] = 0;
	finfo = file_search(name, (struct FILEINFO *) (ADR_DISKIMG + 0x002600), 224);
	if (finfo == 0 && name[i - 1] != '.')
	{
		name[i] = '.';
		name[i+1] = 'H';
		name[i+2] = 'R';
		name[i+3] = 'B';
		name[i+4] = 0;
		// search the file again
		finfo = file_search(name, (struct FILEINFO *) (ADR_DISKIMG + 0x002600), 224);
	}
	
	if (finfo != 0) { // found file
		p = (char *) memman_alloc_4k(memman, finfo->size);
		*((int *) 0xfe8) = (int) p;
		file_loadfile(finfo->clustno, finfo->size, p, fat, (char *) (ADR_DISKIMG + 0x003e00));
		set_segmdesc(gdt + 1003, finfo->size - 1, (int) p, AR_CODE32_ER);
		farcall(0, 1003 * 8); // call
		memman_free_4k(memman, (int) p, finfo->size);
		cons_newline(cons);
		return 1;
	} 
	return 0;
}
示例#13
0
文件: console.c 项目: songtzu/study
void 
cmd_cat(console_t* console, int* fat, char* cmdline)
{
  /* cat command */
  mem_mgr_t* memmgr = (mem_mgr_t*)MEMMGR_ADDR;
  fileinfo_t* finfo = 
    file_search((fileinfo_t*)(ADR_DISKIMG + 0x002600), cmdline + 4, 224);
  char* p;

  if (0 != finfo) {
    /* found the file */
    p = (char*)mem_mgr_alloc_4k(memmgr, finfo->size);
    file_loadfile(finfo->clustno, finfo->size, 
        p, fat, (char*)(ADR_DISKIMG + 0x003e00));
    console_putstr1(console, p, finfo->size);
    mem_mgr_free_4k(memmgr, (int)p, finfo->size);
  }
  else {
    /* donot find the file */
    console_putstr0(console, "File not found.\n");
  }
  console_newline(console);
}
示例#14
0
//显示文件内容的函数
void cmd_type(CONSOLE *console, int *fat, char *cmdline)
{
	MEMMANAGE *memmanage = (MEMMANAGE *)MEMMANAGE_ADDR;
	FILEINFO *finfo = file_search(cmdline + 5, (FILEINFO *)(ADR_DISKIMG + 0x002600), 224);
	char *img_adr;
	int i;
	//文件找到的情况,把内容逐字打印出来
	if(0 != finfo)
	{
		//文件内容开始的地址赋值给img_adr
		img_adr = (char *)memmanage_alloc_4K(memmanage, finfo->size);
		//把可能有间断的文件内容复制到一块儿连续的内存中去,这样就可以直接到这块儿内存进行连续的读取了
		file_loadfile(finfo->clusterno, finfo->size, img_adr, fat, (char *)(0x003e00 + ADR_DISKIMG));
		console_putstring_length(console, img_adr, finfo->size);
		memmanage_free_4K(memmanage, (int)img_adr, finfo->size);
	}
	//文件没有找到的情况,打印出错误信息
	else
	{
		console_putstring_toend(console, "File not found!\n");
	}
	console_newline(console);
	return ;
}
示例#15
0
文件: console.c 项目: songtzu/study
int 
cmd_app(console_t* console, int* fat, char* cmdline)
{
  mem_mgr_t* memmgr = (mem_mgr_t*)MEMMGR_ADDR;
  fileinfo_t* finfo;
  segment_descriptor_t* gdt = (segment_descriptor_t*)ADR_GDT;
  char name[18];
  char* p;
  char* user_app;
  int i;
  task_t* task = task_now();
  int segsize, datasize, esp, datatoy;

  /* generate the filename by cmdline */
  for (i = 0; i < 13; ++i) {
    if (cmdline[i] <= ' ')
      break;
    name[i] = cmdline[i];
  }
  name[i] = 0;

  /* search the file */
  finfo = file_search((fileinfo_t*)(ADR_DISKIMG + 0x002600), name, 224);
  if (0 == finfo && '.' != name[i - 1]) {
    /* can't find the find, add ext and research again */
    name[i + 0] = '.';
    name[i + 1] = 't';
    name[i + 2] = 'o';
    name[i + 3] = 'y';
    name[i + 4] = 0;
    finfo = file_search((fileinfo_t*)(ADR_DISKIMG + 0x002600), name, 224);
  }

  if (0 != finfo) {
    /* find the file */
    p = (char*)mem_mgr_alloc_4k(memmgr, finfo->size);
    file_loadfile(finfo->clustno, finfo->size, 
        p, fat, (char*)(ADR_DISKIMG + 0x003e00));
    if (finfo->size >= 36 && 0 == strncmp(p + 4, "Hari", 4) && 0x00 == *p) {
      segsize   = *((int*)(p + 0x0000));
      esp       = *((int*)(p + 0x000c));
      datasize  = *((int*)(p + 0x0010));
      datatoy   = *((int*)(p + 0x0014));
      user_app  = (char*)mem_mgr_alloc_4k(memmgr, segsize);
      *((int*)0x0fe8) = (int)user_app;
      set_segment_descriptor(gdt + 1003, 
          finfo->size - 1, (int)p, AR_CODE32_ER + 0x60);
      set_segment_descriptor(gdt + 1004, 
          segsize - 1, (int)user_app, AR_DATA32_RW + 0x60);

      for (i = 0; i < datasize; ++i) 
        user_app[esp + i] = p[datatoy + i];
      
      start_user_app(0x1b, 1003 * 8, esp, 1004 * 8, &task->tss.esp0);
      mem_mgr_free_4k(memmgr, (int)user_app, segsize);
    }
    else 
      console_putstr0(console, ".toy file format error.\n");
    
    mem_mgr_free_4k(memmgr, (int)p, finfo->size);
    console_newline(console);
    
    return 1;
  }

  /* do not found the file */
  return 0;
}
示例#16
0
//专门运行应用程序的命令函数,根据命令行来判断是哪个应用程序,并且运行它,如果没有找到这个应用程序,就返回0报错
int cmd_app(CONSOLE *console, int *fat, char *cmdline)
{
	MEMMANAGE *memmanage = (MEMMANAGE *)MEMMANAGE_ADDR;
	FILEINFO *finfo;
	SEGMENT_DESCRIPTOR *gdt = (SEGMENT_DESCRIPTOR *)ADR_GDT;
	TASK *task = task_now();
	char name[30], *img_adr, *data_adr;
	int i;
	//根据命令行生成文件名
	for(i = 0; cmdline[i] != 0; i++)
	{
		name[i] = cmdline[i];
	}
	/*
	//这是原版的代码,真心看不懂这是在干啥……所以写成自己的了,上面那个循环就是
	for(i = 0; i < 13; i++)
	{
		if(cmdline[i] <= ' ')
		{
			break;
		}
		name[i] = cmdline[i];
	}
	name[i] = 0;		//字符串结尾必须是0,所以这里手动加上0
	*/
	finfo = file_search(name, (FILEINFO *)(ADR_DISKIMG + 0x002600), 224);
	//如果因为用户输入没有加上后缀名而找不到,就在这里加上后缀名之后再找
	if(finfo == 0 && name[i] != '.')
	{
		name[i] = '.';
		name[i + 1] = 'H';
		name[i + 2] = 'R';
		name[i + 3] = 'B';
		name[i + 4] = 0;
		finfo = file_search(name, (FILEINFO *)(ADR_DISKIMG + 0x002600), 224);
	}
	//找到文件的情况
	if(0 != finfo)
	{
		//文件内容开始的地址赋值给img_adr
		img_adr = (char *)memmanage_alloc_4K(memmanage, finfo->size);
		*((int *) 0xfe8) = (int)img_adr;		//由于在hello2.nas中没有指定段指针,导致读取数据的时候用了DS寄存器,读到了错误的数据,所以这里特别指定一下地址,并存储到指定位置
		data_adr = (char *)memmanage_alloc_4K(memmanage, 64 * 1024);
		//把可能有间断的文件内容复制到一块儿连续的内存中去,这样就可以直接到这块儿内存进行连续的读取了
		file_loadfile(finfo->clusterno, finfo->size, img_adr, fat, (char *)(0x003e00 + ADR_DISKIMG));
		//为这个任务分配一个内存段,将访问权限加上0x60之后,就可以将段设置成为应用程序专用
		set_segmdesc(gdt + 1003, finfo->size - 1, (int)img_adr, AR_CODE32_ER + 0x60);
		//为应用程序分配的数据段
		set_segmdesc(gdt + 1004, 64 * 1024 - 1, (int)data_adr, AR_DATA32_RW + 0x60);
		//如果应用程序是用C语言写的,那么就要在这里把它调整为从HariMain主函数开始运行,改写最初的6个字节即可
		if(finfo->size >= 8 && 0 == strncmp(img_adr + 4, "Hari", 4))
		{
			img_adr[0] = 0xe8;
			img_adr[1] = 0x16;
			img_adr[2] = 0x00;
			img_adr[3] = 0x00;
			img_adr[4] = 0x00;
			img_adr[5] = 0xcb;
		}
		//跳转到这个hlt任务所在的内存开始执行
		start_app(0, 1003 * 8, 64 * 1024, 1004 * 8, &(task->tss.esp0));
		//任务执行完之后就把这块儿内存释放掉
		memmanage_free_4K(memmanage, (int)img_adr, finfo->size);
		memmanage_free_4K(memmanage, (int)data_adr, 64 * 1024);
		console_newline(console);
		return 1;
	}
	//没找到文件的话直接返回0
	return 0;
}
示例#17
0
void console_task(struct SHEET *sheet, unsigned int memtotal)
{
	struct TIMER *timer;
	struct TASK *task = task_now();
	int i, fifobuf[128], cursor_x = 16, cursor_y = 28, cursor_c = -1;
	char s[30], cmdline[30], *p;
	struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR;
	int x, y;
	struct FILEINFO *finfo = (struct FILEINFO *) (ADR_DISKIMG + 0x002600);
	int *fat = (int *) memman_alloc_4k(memman, 4 * 2880);
	struct SEGMENT_DESCRIPTOR *gdt = (struct SEGMENT_DESCRIPTOR *) ADR_GDT;

	fifo32_init(&task->fifo, 128, fifobuf, task);
	timer = timer_alloc();
	timer_init(timer, &task->fifo, 1);
	timer_settime(timer, 50);
	file_readfat(fat, (unsigned char *) (ADR_DISKIMG + 0x000200));

	/* プロンプト表示 */
	putfonts8_asc_sht(sheet, 8, 28, COL8_FFFFFF, COL8_000000, ">", 1);

	for (;;) {
		io_cli();
		if (fifo32_status(&task->fifo) == 0) {
			task_sleep(task);
			io_sti();
		} else {
			i = fifo32_get(&task->fifo);
			io_sti();
			if (i <= 1) { /* カーソル用タイマ */
				if (i != 0) {
					timer_init(timer, &task->fifo, 0); /* 次は0を */
					if (cursor_c >= 0) {
						cursor_c = COL8_FFFFFF;
					}
				} else {
					timer_init(timer, &task->fifo, 1); /* 次は1を */
					if (cursor_c >= 0) {
						cursor_c = COL8_000000;
					}
				}
				timer_settime(timer, 50);
			}
			if (i == 2) {	/* カーソルON */
				cursor_c = COL8_FFFFFF;
			}
			if (i == 3) {	/* カーソルOFF */
				boxfill8(sheet->buf, sheet->bxsize, COL8_000000, cursor_x, cursor_y, cursor_x + 7, cursor_y + 15);
				cursor_c = -1;
			}
			if (256 <= i && i <= 511) { /* キーボードデータ(タスクA経由) */
				if (i == 8 + 256) {
					/* バックスペース */
					if (cursor_x > 16) {
						/* カーソルをスペースで消してから、カーソルを1つ戻す */
						putfonts8_asc_sht(sheet, cursor_x, cursor_y, COL8_FFFFFF, COL8_000000, " ", 1);
						cursor_x -= 8;
					}
				} else if (i == 10 + 256) {
					/* Enter */
					/* カーソルをスペースで消してから改行する */
					putfonts8_asc_sht(sheet, cursor_x, cursor_y, COL8_FFFFFF, COL8_000000, " ", 1);
					cmdline[cursor_x / 8 - 2] = 0;
					cursor_y = cons_newline(cursor_y, sheet);
					/* コマンド実行 */
					if (strcmp(cmdline, "mem") == 0) {
						/* memコマンド */
						sprintf(s, "total   %dMB", memtotal / (1024 * 1024));
						putfonts8_asc_sht(sheet, 8, cursor_y, COL8_FFFFFF, COL8_000000, s, 30);
						cursor_y = cons_newline(cursor_y, sheet);
						sprintf(s, "free %dKB", memman_total(memman) / 1024);
						putfonts8_asc_sht(sheet, 8, cursor_y, COL8_FFFFFF, COL8_000000, s, 30);
						cursor_y = cons_newline(cursor_y, sheet);
						cursor_y = cons_newline(cursor_y, sheet);
					} else if (strcmp(cmdline, "cls") == 0) {
						/* clsコマンド */
						for (y = 28; y < 28 + 128; y++) {
							for (x = 8; x < 8 + 240; x++) {
								sheet->buf[x + y * sheet->bxsize] = COL8_000000;
							}
						}
						sheet_refresh(sheet, 8, 28, 8 + 240, 28 + 128);
						cursor_y = 28;
					} else if (strcmp(cmdline, "dir") == 0) {
						/* dirコマンド */
						for (x = 0; x < 224; x++) {
							if (finfo[x].name[0] == 0x00) {
								break;
							}
							if (finfo[x].name[0] != 0xe5) {
								if ((finfo[x].type & 0x18) == 0) {
									sprintf(s, "filename.ext   %7d", finfo[x].size);
									for (y = 0; y < 8; y++) {
										s[y] = finfo[x].name[y];
									}
									s[ 9] = finfo[x].ext[0];
									s[10] = finfo[x].ext[1];
									s[11] = finfo[x].ext[2];
									putfonts8_asc_sht(sheet, 8, cursor_y, COL8_FFFFFF, COL8_000000, s, 30);
									cursor_y = cons_newline(cursor_y, sheet);
								}
							}
						}
						cursor_y = cons_newline(cursor_y, sheet);
					} else if (strncmp(cmdline, "type ", 5) == 0) {
						/* typeコマンド */
						/* ファイル名を準備する */
						for (y = 0; y < 11; y++) {
							s[y] = ' ';
						}
						y = 0;
						for (x = 5; y < 11 && cmdline[x] != 0; x++) {
							if (cmdline[x] == '.' && y <= 8) {
								y = 8;
							} else {
								s[y] = cmdline[x];
								if ('a' <= s[y] && s[y] <= 'z') {
									/* 小文字は大文字に直す */
									s[y] -= 0x20;
								} 
								y++;
							}
						}
						/* ファイルを探す */
						for (x = 0; x < 224; ) {
							if (finfo[x].name[0] == 0x00) {
								break;
							}
							if ((finfo[x].type & 0x18) == 0) {
								for (y = 0; y < 11; y++) {
									if (finfo[x].name[y] != s[y]) {
										goto type_next_file;
									}
								}
								break; /* ファイルが見つかった */
							}
		type_next_file:
							x++;
						}
						if (x < 224 && finfo[x].name[0] != 0x00) {
							/* ファイルが見つかった場合 */
							p = (char *) memman_alloc_4k(memman, finfo[x].size);
							file_loadfile(finfo[x].clustno, finfo[x].size, p, fat, (char *) (ADR_DISKIMG + 0x003e00));
							cursor_x = 8;
							for (y = 0; y < finfo[x].size; y++) {
								/* 1文字ずつ出力 */
								s[0] = p[y];
								s[1] = 0;
								if (s[0] == 0x09) {	/* タブ */
									for (;;) {
										putfonts8_asc_sht(sheet, cursor_x, cursor_y, COL8_FFFFFF, COL8_000000, " ", 1);
										cursor_x += 8;
										if (cursor_x == 8 + 240) {
											cursor_x = 8;
											cursor_y = cons_newline(cursor_y, sheet);
										}
										if (((cursor_x - 8) & 0x1f) == 0) {
											break;	/* 4で割り切れたらbreak */
										}
									}
								} else if (s[0] == 0x0a) {	/* 改行 */
									cursor_x = 8;
									cursor_y = cons_newline(cursor_y, sheet);
								} else if (s[0] == 0x0d) {	/* 復帰 */
									/* とりあえずなにもしない */
								} else {	/* 普通の文字 */
									putfonts8_asc_sht(sheet, cursor_x, cursor_y, COL8_FFFFFF, COL8_000000, s, 1);
									cursor_x += 8;
									if (cursor_x == 8 + 240) {
										cursor_x = 8;
										cursor_y = cons_newline(cursor_y, sheet);
									}
								}
							}
							memman_free_4k(memman, (int) p, finfo[x].size);
						} else {
							/* ファイルが見つからなかった場合 */
							putfonts8_asc_sht(sheet, 8, cursor_y, COL8_FFFFFF, COL8_000000, "File not found.", 15);
							cursor_y = cons_newline(cursor_y, sheet);
						}
						cursor_y = cons_newline(cursor_y, sheet);
					} else if (strcmp(cmdline, "hlt") == 0) {
						/* hlt.hrbアプリケーションを起動 */
						for (y = 0; y < 11; y++) {
							s[y] = ' ';
						}
						s[0] = 'H';
						s[1] = 'L';
						s[2] = 'T';
						s[8] = 'H';
						s[9] = 'R';
						s[10] = 'B';
						for (x = 0; x < 224; ) {
							if (finfo[x].name[0] == 0x00) {
								break;
							}
							if ((finfo[x].type & 0x18) == 0) {
								for (y = 0; y < 11; y++) {
									if (finfo[x].name[y] != s[y]) {
										goto hlt_next_file;
									}
								}
								break; /* ファイルが見つかった */
							}
		hlt_next_file:
							x++;
						}
						if (x < 224 && finfo[x].name[0] != 0x00) {
							/* ファイルが見つかった場合 */
							p = (char *) memman_alloc_4k(memman, finfo[x].size);
							file_loadfile(finfo[x].clustno, finfo[x].size, p, fat, (char *) (ADR_DISKIMG + 0x003e00));
							set_segmdesc(gdt + 1003, finfo[x].size - 1, (int) p, AR_CODE32_ER);
							farjmp(0, 1003 * 8);
							memman_free_4k(memman, (int) p, finfo[x].size);
						} else {
							/* ファイルが見つからなかった場合 */
							putfonts8_asc_sht(sheet, 8, cursor_y, COL8_FFFFFF, COL8_000000, "File not found.", 15);
							cursor_y = cons_newline(cursor_y, sheet);
						}
						cursor_y = cons_newline(cursor_y, sheet);
					} else if (cmdline[0] != 0) {
						/* コマンドではなく、さらに空行でもない */
						putfonts8_asc_sht(sheet, 8, cursor_y, COL8_FFFFFF, COL8_000000, "Bad command.", 12);
						cursor_y = cons_newline(cursor_y, sheet);
						cursor_y = cons_newline(cursor_y, sheet);
					}
					/* プロンプト表示 */
					putfonts8_asc_sht(sheet, 8, cursor_y, COL8_FFFFFF, COL8_000000, ">", 1);
					cursor_x = 16;
				} else {
					/* 一般文字 */
					if (cursor_x < 240) {
						/* 一文字表示してから、カーソルを1つ進める */
						s[0] = i - 256;
						s[1] = 0;
						cmdline[cursor_x / 8 - 2] = i - 256;
						putfonts8_asc_sht(sheet, cursor_x, cursor_y, COL8_FFFFFF, COL8_000000, s, 1);
						cursor_x += 8;
					}
				}
			}
			/* カーソル再表示 */
			if (cursor_c >= 0) {
				boxfill8(sheet->buf, sheet->bxsize, cursor_c, cursor_x, cursor_y, cursor_x + 7, cursor_y + 15);
			}
			sheet_refresh(sheet, cursor_x, cursor_y, cursor_x + 8, cursor_y + 16);
		}
	}
}
示例#18
0
int cmd_app(struct CONSOLE *cons, int *fat, char *cmdline)
{
	struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR;
	struct FILEINFO *finfo;
	char name[18], *p, *q;
	struct TASK *task = task_now();
	int i, segsiz, datsiz, esp, dathrb;
	struct SHTCTL *shtctl;
	struct SHEET *sht;

	/* コマンドラインからファイル名を生成 */
	for (i = 0; i < 13; i++) {
		if (cmdline[i] <= ' ') {
			break;
		}
		name[i] = cmdline[i];
	}
	name[i] = 0; /* とりあえずファイル名の後ろを0にする */

	/* ファイルを探す */
	finfo = file_search(name, (struct FILEINFO *) (ADR_DISKIMG + 0x002600), 224);
	if (finfo == 0 && name[i - 1] != '.') {
		/* 見つからなかったので後ろに".HRB"をつけてもう一度探してみる */
		name[i    ] = '.';
		name[i + 1] = 'H';
		name[i + 2] = 'R';
		name[i + 3] = 'B';
		name[i + 4] = 0;
		finfo = file_search(name, (struct FILEINFO *) (ADR_DISKIMG + 0x002600), 224);
	}

	if (finfo != 0) {
		/* ファイルが見つかった場合 */
		p = (char *) memman_alloc_4k(memman, finfo->size);
		file_loadfile(finfo->clustno, finfo->size, p, fat, (char *) (ADR_DISKIMG + 0x003e00));
		if (finfo->size >= 36 && strncmp(p + 4, "Hari", 4) == 0 && *p == 0x00) {
			segsiz = *((int *) (p + 0x0000));
			esp    = *((int *) (p + 0x000c));
			datsiz = *((int *) (p + 0x0010));
			dathrb = *((int *) (p + 0x0014));
			q = (char *) memman_alloc_4k(memman, segsiz);
			task->ds_base = (int) q;
			set_segmdesc(task->ldt + 0, finfo->size - 1, (int) p, AR_CODE32_ER + 0x60);
			set_segmdesc(task->ldt + 1, segsiz - 1,      (int) q, AR_DATA32_RW + 0x60);
			for (i = 0; i < datsiz; i++) {
				q[esp + i] = p[dathrb + i];
			}
			start_app(0x1b, 0 * 8 + 4, esp, 1 * 8 + 4, &(task->tss.esp0));
			shtctl = (struct SHTCTL *) *((int *) 0x0fe4);
			for (i = 0; i < MAX_SHEETS; i++) {
				sht = &(shtctl->sheets0[i]);
				if ((sht->flags & 0x11) == 0x11 && sht->task == task) {
					/* アプリが開きっぱなしにした下じきを発見 */
					sheet_free(sht);	/* 閉じる */
				}
			}
			for (i = 0; i < 8; i++) {	/* クローズしてないファイルをクローズ */
				if (task->fhandle[i].buf != 0) {
					memman_free_4k(memman, (int) task->fhandle[i].buf, task->fhandle[i].size);
					task->fhandle[i].buf = 0;
				}
			}
			timer_cancelall(&task->fifo);
			memman_free_4k(memman, (int) q, segsiz);
		} else {
			cons_putstr0(cons, ".hrb file format error.\n");
		}
		memman_free_4k(memman, (int) p, finfo->size);
		cons_newline(cons);
		return 1;
	}
	/* ファイルが見つからなかった場合 */
	return 0;
}
示例#19
0
文件: bootpack.c 项目: ghassheee/myos
void HariMain(void)
{
    struct BOOTINFO *binfo = (struct BOOTINFO *) ADR_BOOTINFO;
    struct SHTCTL *shtctl;
    char s[40];
    struct FIFO32 fifo, keycmd;
    int fifobuf[128], keycmd_buf[32];
    int mx, my, i, new_mx = -1, new_my = 0, new_wx = 0x7fffffff, new_wy = 0;
    unsigned int memtotal;
    struct MOUSE_DEC mdec;
    struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR;
    unsigned char *buf_back, buf_mouse[256];
    struct SHEET *sht_back, *sht_mouse;
    struct TASK *task_a, *task;
    static char keytable0[0x80] = {
        0,   0,   '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '^', 0x08, 0,
        'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '@', '[', 0x0a, 0, 'A', 'S',
        'D', 'F', 'G', 'H', 'J', 'K', 'L', ';', ':', 0,   0,   ']', 'Z', 'X', 'C', 'V',
        'B', 'N', 'M', ',', '.', '/', 0,   '*', 0,   ' ', 0,   0,   0,   0,   0,   0,
        0,   0,   0,   0,   0,   0,   0,   '7', '8', '9', '-', '4', '5', '6', '+', '1',
        '2', '3', '0', '.', 0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
        0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
        0,   0,   0,   0x5c, 0,  0,   0,   0,   0,   0,   0,   0,   0,   0x5c, 0,  0
    };
    static char keytable1[0x80] = {
        0,   0,   '!', 0x22, '#', '$', '%', '&', 0x27, '(', ')', '~', '=', '~', 0x08, 0,
        'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '`', '{', 0x0a, 0, 'A', 'S',
        'D', 'F', 'G', 'H', 'J', 'K', 'L', '+', '*', 0,   0,   '}', 'Z', 'X', 'C', 'V',
        'B', 'N', 'M', '<', '>', '?', 0,   '*', 0,   ' ', 0,   0,   0,   0,   0,   0,
        0,   0,   0,   0,   0,   0,   0,   '7', '8', '9', '-', '4', '5', '6', '+', '1',
        '2', '3', '0', '.', 0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
        0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
        0,   0,   0,   '_', 0,   0,   0,   0,   0,   0,   0,   0,   0,   '|', 0,   0
    };
    int key_shift = 0, key_leds = (binfo->leds >> 4) & 7, keycmd_wait = -1;
    int j, x, y, mmx = -1, mmy = -1, mmx2 = 0;
    struct SHEET *sht = 0, *key_win, *sht2;
    int *fat;
    unsigned char *nihongo;
    struct FILEINFO *finfo;
    extern char hankaku[4096];

    init_gdtidt();
    init_pic();
    io_sti(); /* IDT/PICの初期化が終わったのでCPUの割り込み禁止を解除 */
    fifo32_init(&fifo, 128, fifobuf, 0);
    *((int *) 0x0fec) = (int) &fifo;
    init_pit();
    init_keyboard(&fifo, 256);
    enable_mouse(&fifo, 512, &mdec);
    io_out8(PIC0_IMR, 0xf8); /* PITとPIC1とキーボードを許可(11111000) */
    io_out8(PIC1_IMR, 0xef); /* マウスを許可(11101111) */
    fifo32_init(&keycmd, 32, keycmd_buf, 0);

    memtotal = memtest(0x00400000, 0xbfffffff);
    memman_init(memman);
    memman_free(memman, 0x00001000, 0x0009e000); /* 0x00001000 - 0x0009efff */
    memman_free(memman, 0x00400000, memtotal - 0x00400000);

    init_palette();
    shtctl = shtctl_init(memman, binfo->vram, binfo->scrnx, binfo->scrny);
    task_a = task_init(memman);
    fifo.task = task_a;
    task_run(task_a, 1, 2);
    *((int *) 0x0fe4) = (int) shtctl;
    task_a->langmode = 0;

    /* sht_back */
    sht_back  = sheet_alloc(shtctl);
    buf_back  = (unsigned char *) memman_alloc_4k(memman, binfo->scrnx * binfo->scrny);
    sheet_setbuf(sht_back, buf_back, binfo->scrnx, binfo->scrny, -1); /* 透明色なし */
    init_screen8(buf_back, binfo->scrnx, binfo->scrny);

    /* sht_cons */
    key_win = open_console(shtctl, memtotal);

    /* sht_mouse */
    sht_mouse = sheet_alloc(shtctl);
    sheet_setbuf(sht_mouse, buf_mouse, 16, 16, 99);
    init_mouse_cursor8(buf_mouse, 99);
    mx = (binfo->scrnx - 16) / 2; /* 画面中央になるように座標計算 */
    my = (binfo->scrny - 28 - 16) / 2;

    sheet_slide(sht_back,  0,  0);
    sheet_slide(key_win,   32, 4);
    sheet_slide(sht_mouse, mx, my);
    sheet_updown(sht_back,  0);
    sheet_updown(key_win,   1);
    sheet_updown(sht_mouse, 2);
    keywin_on(key_win);

    /* 最初にキーボード状態との食い違いがないように、設定しておくことにする */
    fifo32_put(&keycmd, KEYCMD_LED);
    fifo32_put(&keycmd, key_leds);

    /* nihongo.fntの読み込み */
    nihongo = (unsigned char *) memman_alloc_4k(memman, 16 * 256 + 32 * 94 * 47);
    fat = (int *) memman_alloc_4k(memman, 4 * 2880);
    file_readfat(fat, (unsigned char *) (ADR_DISKIMG + 0x000200));
    finfo = file_search("nihongo.fnt", (struct FILEINFO *) (ADR_DISKIMG + 0x002600), 224);
    if (finfo != 0) {
        file_loadfile(finfo->clustno, finfo->size, nihongo, fat, (char *) (ADR_DISKIMG + 0x003e00));
    } else {
        for (i = 0; i < 16 * 256; i++) {
            nihongo[i] = hankaku[i]; /* フォントがなかったので半角部分をコピー */
        }
        for (i = 16 * 256; i < 16 * 256 + 32 * 94 * 47; i++) {
            nihongo[i] = 0xff; /* フォントがなかったので全角部分を0xffで埋め尽くす */
        }
    }
    *((int *) 0x0fe8) = (int) nihongo;
    memman_free_4k(memman, (int) fat, 4 * 2880);

    for (;;) {
        if (fifo32_status(&keycmd) > 0 && keycmd_wait < 0) {
            /* キーボードコントローラに送るデータがあれば、送る */
            keycmd_wait = fifo32_get(&keycmd);
            wait_KBC_sendready();
            io_out8(PORT_KEYDAT, keycmd_wait);
        }
        io_cli();
        if (fifo32_status(&fifo) == 0) {
            /* FIFOがからっぽになったので、保留している描画があれば実行する */
            if (new_mx >= 0) {
                io_sti();
                sheet_slide(sht_mouse, new_mx, new_my);
                new_mx = -1;
            } else if (new_wx != 0x7fffffff) {
                io_sti();
                sheet_slide(sht, new_wx, new_wy);
                new_wx = 0x7fffffff;
            } else {
                task_sleep(task_a);
                io_sti();
            }
        } else {
            i = fifo32_get(&fifo);
            io_sti();
            if (key_win != 0 && key_win->flags == 0) {	/* ウィンドウが閉じられた */
                if (shtctl->top == 1) {	/* もうマウスと背景しかない */
                    key_win = 0;
                } else {
                    key_win = shtctl->sheets[shtctl->top - 1];
                    keywin_on(key_win);
                }
            }
            if (256 <= i && i <= 511) { /* キーボードデータ */
                if (i < 0x80 + 256) { /* キーコードを文字コードに変換 */
                    if (key_shift == 0) {
                        s[0] = keytable0[i - 256];
                    } else {
                        s[0] = keytable1[i - 256];
                    }
                } else {
                    s[0] = 0;
                }
                if ('A' <= s[0] && s[0] <= 'Z') {	/* 入力文字がアルファベット */
                    if (((key_leds & 4) == 0 && key_shift == 0) ||
                            ((key_leds & 4) != 0 && key_shift != 0)) {
                        s[0] += 0x20;	/* 大文字を小文字に変換 */
                    }
                }
                if (s[0] != 0 && key_win != 0) { /* 通常文字、バックスペース、Enter */
                    fifo32_put(&key_win->task->fifo, s[0] + 256);
                }
                if (i == 256 + 0x0f && key_win != 0) {	/* Tab */
                    keywin_off(key_win);
                    j = key_win->height - 1;
                    if (j == 0) {
                        j = shtctl->top - 1;
                    }
                    key_win = shtctl->sheets[j];
                    keywin_on(key_win);
                }
                if (i == 256 + 0x2a) {	/* 左シフト ON */
                    key_shift |= 1;
                }
                if (i == 256 + 0x36) {	/* 右シフト ON */
                    key_shift |= 2;
                }
                if (i == 256 + 0xaa) {	/* 左シフト OFF */
                    key_shift &= ~1;
                }
                if (i == 256 + 0xb6) {	/* 右シフト OFF */
                    key_shift &= ~2;
                }
                if (i == 256 + 0x3a) {	/* CapsLock */
                    key_leds ^= 4;
                    fifo32_put(&keycmd, KEYCMD_LED);
                    fifo32_put(&keycmd, key_leds);
                }
                if (i == 256 + 0x45) {	/* NumLock */
                    key_leds ^= 2;
                    fifo32_put(&keycmd, KEYCMD_LED);
                    fifo32_put(&keycmd, key_leds);
                }
                if (i == 256 + 0x46) {	/* ScrollLock */
                    key_leds ^= 1;
                    fifo32_put(&keycmd, KEYCMD_LED);
                    fifo32_put(&keycmd, key_leds);
                }
                if (i == 256 + 0x3b && key_shift != 0 && key_win != 0) {	/* Shift+F1 */
                    task = key_win->task;
                    if (task != 0 && task->tss.ss0 != 0) {
                        cons_putstr0(task->cons, "\nBreak(key) :\n");
                        io_cli();	/* 強制終了処理中にタスクが変わると困るから */
                        task->tss.eax = (int) &(task->tss.esp0);
                        task->tss.eip = (int) asm_end_app;
                        io_sti();
                        task_run(task, -1, 0);	/* 終了処理を確実にやらせるために、寝ていたら起こす */
                    }
                }
                if (i == 256 + 0x3c && key_shift != 0) {	/* Shift+F2 */
                    /* 新しく作ったコンソールを入力選択状態にする(そのほうが親切だよね?) */
                    if (key_win != 0) {
                        keywin_off(key_win);
                    }
                    key_win = open_console(shtctl, memtotal);
                    sheet_slide(key_win, 32, 4);
                    sheet_updown(key_win, shtctl->top);
                    keywin_on(key_win);
                }
                if (i == 256 + 0x57) {	/* F11 */
                    sheet_updown(shtctl->sheets[1], shtctl->top - 1);
                }
                if (i == 256 + 0xfa) {	/* キーボードがデータを無事に受け取った */
                    keycmd_wait = -1;
                }
                if (i == 256 + 0xfe) {	/* キーボードがデータを無事に受け取れなかった */
                    wait_KBC_sendready();
                    io_out8(PORT_KEYDAT, keycmd_wait);
                }
            } else if (512 <= i && i <= 767) { /* マウスデータ */
                if (mouse_decode(&mdec, i - 512) != 0) {
                    /* マウスカーソルの移動 */
                    mx += mdec.x;
                    my += mdec.y;
                    if (mx < 0) {
                        mx = 0;
                    }
                    if (my < 0) {
                        my = 0;
                    }
                    if (mx > binfo->scrnx - 1) {
                        mx = binfo->scrnx - 1;
                    }
                    if (my > binfo->scrny - 1) {
                        my = binfo->scrny - 1;
                    }
                    new_mx = mx;
                    new_my = my;
                    if ((mdec.btn & 0x01) != 0) {
                        /* 左ボタンを押している */
                        if (mmx < 0) {
                            /* 通常モードの場合 */
                            /* 上の下じきから順番にマウスが指している下じきを探す */
                            for (j = shtctl->top - 1; j > 0; j--) {
                                sht = shtctl->sheets[j];
                                x = mx - sht->vx0;
                                y = my - sht->vy0;
                                if (0 <= x && x < sht->bxsize && 0 <= y && y < sht->bysize) {
                                    if (sht->buf[y * sht->bxsize + x] != sht->col_inv) {
                                        sheet_updown(sht, shtctl->top - 1);
                                        if (sht != key_win) {
                                            keywin_off(key_win);
                                            key_win = sht;
                                            keywin_on(key_win);
                                        }
                                        if (3 <= x && x < sht->bxsize - 3 && 3 <= y && y < 21) {
                                            mmx = mx;	/* ウィンドウ移動モードへ */
                                            mmy = my;
                                            mmx2 = sht->vx0;
                                            new_wy = sht->vy0;
                                        }
                                        if (sht->bxsize - 21 <= x && x < sht->bxsize - 5 && 5 <= y && y < 19) {
                                            /* 「×」ボタンクリック */
                                            if ((sht->flags & 0x10) != 0) {		/* アプリが作ったウィンドウか? */
                                                task = sht->task;
                                                cons_putstr0(task->cons, "\nBreak(mouse) :\n");
                                                io_cli();	/* 強制終了処理中にタスクが変わると困るから */
                                                task->tss.eax = (int) &(task->tss.esp0);
                                                task->tss.eip = (int) asm_end_app;
                                                io_sti();
                                                task_run(task, -1, 0);
                                            } else {	/* コンソール */
                                                task = sht->task;
                                                sheet_updown(sht, -1); /* とりあえず非表示にしておく */
                                                keywin_off(key_win);
                                                key_win = shtctl->sheets[shtctl->top - 1];
                                                keywin_on(key_win);
                                                io_cli();
                                                fifo32_put(&task->fifo, 4);
                                                io_sti();
                                            }
                                        }
                                        break;
                                    }
                                }
                            }
                        } else {
                            /* ウィンドウ移動モードの場合 */
                            x = mx - mmx;	/* マウスの移動量を計算 */
                            y = my - mmy;
                            new_wx = (mmx2 + x + 2) & ~3;
                            new_wy = new_wy + y;
                            mmy = my;	/* 移動後の座標に更新 */
                        }
                    } else {
                        /* 左ボタンを押していない */
                        mmx = -1;	/* 通常モードへ */
                        if (new_wx != 0x7fffffff) {
                            sheet_slide(sht, new_wx, new_wy);	/* 一度確定させる */
                            new_wx = 0x7fffffff;
                        }
                    }
                }
            } else if (768 <= i && i <= 1023) {	/* コンソール終了処理 */
                close_console(shtctl->sheets0 + (i - 768));
            } else if (1024 <= i && i <= 2023) {
                close_constask(taskctl->tasks0 + (i - 1024));
            } else if (2024 <= i && i <= 2279) {	/* コンソールだけを閉じる */
                sht2 = shtctl->sheets0 + (i - 2024);
                memman_free_4k(memman, (int) sht2->buf, 256 * 165);
                sheet_free(sht2);
            }
        }
    }
}
示例#20
0
/* 控制台任务 */
void console_task(struct SHEET *sheet, unsigned int memtotal)
{
	struct TIMER *timer;
	struct TASK *task = task_now();
	int i, fifobuf[128], cursor_x = 16, cursor_y = 28, cursor_c = -1;
	char s[30], cmdline[30], *p;
	struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR;
	int x, y;
	struct FILEINFO *finfo = (struct FILEINFO *) (ADR_DISKIMG + 0x002600);
	int *fat = (int *) memman_alloc_4k(memman, 4 * 2880);
	struct SEGMENT_DESCRIPTOR *gdt = (struct SEGMENT_DESCRIPTOR *) ADR_GDT;

	fifo32_init(&task->fifo, 128, fifobuf, task);
	timer = timer_alloc();
	timer_init(timer, &task->fifo, 1);
	timer_settime(timer, 50);
	file_readfat(fat, (unsigned char *) (ADR_DISKIMG + 0x000200));

	/* 输出一个">" */
	putfonts8_asc_sht(sheet, 8, 28, COL8_FFFFFF, COL8_000000, ">", 1);

	for (;;) {
		io_cli();
		if (fifo32_status(&task->fifo) == 0) {	/* 控制台任务自己的缓冲区中没有数据 */
			task_sleep(task);					/* 睡眠自己 */
			io_sti();
		} else {
			i = fifo32_get(&task->fifo);		/* 读出数据 */
			io_sti();
			if (i <= 1) { 						/* 光标用定时器 */
				if (i != 0) {
					timer_init(timer, &task->fifo, 0); /* 下面是设定0 */
					if (cursor_c >= 0) {			/* 如果需要显示光标 */
						cursor_c = COL8_FFFFFF;
					}
				} else {
					timer_init(timer, &task->fifo, 1); /* 下面是设定1 */
					if (cursor_c >= 0) {			/* 如果需要显示光标 */
						cursor_c = COL8_000000;
					}
				}
				timer_settime(timer, 50);			/* 设置半秒 */
			}
			if (i == 2) {	/* 光标ON */
				cursor_c = COL8_FFFFFF;
			}
			if (i == 3) {	/* 光标OFF */
				/* 直接用黑色将原来光标的位置消去 */
				boxfill8(sheet->buf, sheet->bxsize, COL8_000000, cursor_x, cursor_y, cursor_x + 7, cursor_y + 15);
				cursor_c = -1;
			}
			if (256 <= i && i <= 511) { /* 任务A传送过来的键盘的数据 */
				if (i == 8 + 256) {		/* 注意!在任务A中已经将键值转换成字符的ASCII码了 */
					/* 退格键 */
					if (cursor_x > 16) {
						/* 用空格把光标消去之后 光标向左移8个像素点 */
						putfonts8_asc_sht(sheet, cursor_x, cursor_y, COL8_FFFFFF, COL8_000000, " ", 1);
						cursor_x -= 8;
					}
				} else if (i == 10 + 256) {	/* 如果是回车 (10是换行符的ASCII码) */
					/* Enter */
					/* 用空格将光标擦除 */
					putfonts8_asc_sht(sheet, cursor_x, cursor_y, COL8_FFFFFF, COL8_000000, " ", 1);
					cmdline[cursor_x / 8 - 2] = 0;	/* 计算前面有几个字符 在字符的后面加上'\0' */
													/* 加'\0'是因为C语言中字符串都是以它结尾的 */
													/* 减2是减去'\0'的位置还有一个回车的位置 所*/
													/* 以最后'\0'是刚好在最后一个字符后面 */
					cursor_y = cons_newline(cursor_y, sheet);	/* 换行 */
					/* 执行命令 */
					if (strcmp(cmdline, "mem") == 0) {
						/* mem命令 */
						/* 输出内存总大小和空闲内存大小 */
						sprintf(s, "total   %dMB", memtotal / (1024 * 1024));
						putfonts8_asc_sht(sheet, 8, cursor_y, COL8_FFFFFF, COL8_000000, s, 30);
						cursor_y = cons_newline(cursor_y, sheet);	/* 换行 */
						sprintf(s, "free %dKB", memman_total(memman) / 1024);
						putfonts8_asc_sht(sheet, 8, cursor_y, COL8_FFFFFF, COL8_000000, s, 30);
						cursor_y = cons_newline(cursor_y, sheet);	/* 换行 */
						cursor_y = cons_newline(cursor_y, sheet);	/* 换行 */
					} else if (strcmp(cmdline, "cls") == 0) {
						/* cls命令 */
						/* 最简单。。每个像素都设为黑色..... */
						for (y = 28; y < 28 + 128; y++) {
							for (x = 8; x < 8 + 240; x++) {
								sheet->buf[x + y * sheet->bxsize] = COL8_000000;
							}
						}
						sheet_refresh(sheet, 8, 28, 8 + 240, 28 + 128);
						cursor_y = 28;
					} else if (strcmp(cmdline, "dir") == 0) {
						/* dir命令 */
						for (x = 0; x < 224; x++) {	/* 遍历所有的根目录条目 */
													/* 这个224是在ipl10中定义的 */
							if (finfo[x].name[0] == 0x00) {	/* 该条目不包含任何文件信息 */
								break;
							}
							if (finfo[x].name[0] != 0xe5) {	/* 该条目包含文件信息 */
								if ((finfo[x].type & 0x18) == 0) {	/* 该条目记录的不是目录 也不是非文件信息 */
									sprintf(s, "filename.ext   %7d", finfo[x].size);
									for (y = 0; y < 8; y++) {	/* 设置文件名 */
										s[y] = finfo[x].name[y];
									}
									s[ 9] = finfo[x].ext[0];	/* 设置扩展名 */
									s[10] = finfo[x].ext[1];
									s[11] = finfo[x].ext[2];
									putfonts8_asc_sht(sheet, 8, cursor_y, COL8_FFFFFF, COL8_000000, s, 30);
									cursor_y = cons_newline(cursor_y, sheet);	/* 换行 */
								}
							}
						}
						cursor_y = cons_newline(cursor_y, sheet);	/* 换行 */
					} else if (strncmp(cmdline, "type ", 5) == 0) {
						/* type命令 */
						/* 准备文件名 */
						for (y = 0; y < 11; y++) {
							s[y] = ' ';
						}
						y = 0;
						for (x = 5; y < 11 && cmdline[x] != 0; x++) {
							if (cmdline[x] == '.' && y <= 8) {
								y = 8;
							} else {
								s[y] = cmdline[x];
								if ('a' <= s[y] && s[y] <= 'z') {
									/* 将小写字母转换成大写字母 */
									s[y] -= 0x20;
								} 
								y++;
							}
						}
						/* 寻找文件 */
						for (x = 0; x < 224; ) {
							if (finfo[x].name[0] == 0x00) {	/* 该条目不包含任何文件信息 */
								break;
							}
							if ((finfo[x].type & 0x18) == 0) {	/* 该条目记录的不是目录 也不是非文件信息 */
								for (y = 0; y < 11; y++) {
									if (finfo[x].name[y] != s[y]) {
										goto type_next_file;
									}
								}
								break; /* 找到文件就退出循环 */
							}
		type_next_file:
							x++;
						}
						if (x < 224 && finfo[x].name[0] != 0x00) {
							/* 找到文件的情况 */
							/* 分配内存 这块内存用于存放文件的内容 */
							p = (char *) memman_alloc_4k(memman, finfo[x].size);
							/* 将软盘中该文件的内容复制到p指向的内存中 */
							file_loadfile(finfo[x].clustno, finfo[x].size, p, fat, (char *) (ADR_DISKIMG + 0x003e00));
							cursor_x = 8;	
							for (y = 0; y < finfo[x].size; y++) {
								/* 逐个输出文件中的内容 */
								s[0] = p[y];
								s[1] = 0;
								if (s[0] == 0x09) {	/* 制表符 */
									for (;;) {
										/* 这一小段就不注释了,偷下懒 书中解释的很详细 */
										putfonts8_asc_sht(sheet, cursor_x, cursor_y, COL8_FFFFFF, COL8_000000, " ", 1);
										cursor_x += 8;
										if (cursor_x == 8 + 240) {
											cursor_x = 8;
											cursor_y = cons_newline(cursor_y, sheet);
										}
										if (((cursor_x - 8) & 0x1f) == 0) {
											break;	/* 被32整除则break */
										}
									}
								} else if (s[0] == 0x0a) {	/* 换行 */
									cursor_x = 8;
									cursor_y = cons_newline(cursor_y, sheet);
								} else if (s[0] == 0x0d) {	/* 回车 */
									/* 忽略 */
								} else {	/* 一般字符 */
									putfonts8_asc_sht(sheet, cursor_x, cursor_y, COL8_FFFFFF, COL8_000000, s, 1);
									cursor_x += 8;
									if (cursor_x == 8 + 240) {
										cursor_x = 8;
										cursor_y = cons_newline(cursor_y, sheet);
									}
								}
							}
							/* 输出完毕 将刚申请的内存空间释放掉 */
							memman_free_4k(memman, (int) p, finfo[x].size);
						} else {		/* 文件没有找到 */
							putfonts8_asc_sht(sheet, 8, cursor_y, COL8_FFFFFF, COL8_000000, "File not found.", 15);
							cursor_y = cons_newline(cursor_y, sheet);
						}
						cursor_y = cons_newline(cursor_y, sheet);
					} else if (strcmp(cmdline, "hlt") == 0) {	/* 调用应用程序 */
						for (y = 0; y < 11; y++) {
							s[y] = ' ';
						}
						/* 设置文件名 */
						s[0] = 'H';
						s[1] = 'L';
						s[2] = 'T';
						s[8] = 'H';
						s[9] = 'R';
						s[10] = 'B';
						/* 查找文件 */
						for (x = 0; x < 224; ) {
							if (finfo[x].name[0] == 0x00) {
								break;
							}
							if ((finfo[x].type & 0x18) == 0) {
								for (y = 0; y < 11; y++) {
									if (finfo[x].name[y] != s[y]) {
										goto hlt_next_file;
									}
								}
								break; /* 找到文件 */
							}
		hlt_next_file:
							x++;
						}
						if (x < 224 && finfo[x].name[0] != 0x00) {
							/* 找到文件的情况 */
							/* 分配一块内存 文件将被加载到这个并执行 */
							p = (char *) memman_alloc_4k(memman, finfo[x].size);
							/* 将文件的内容复制到p指向的缓冲区 */
							file_loadfile(finfo[x].clustno, finfo[x].size, p, fat, (char *) (ADR_DISKIMG + 0x003e00));
							/* 为我们的应用程序创建一个描述符 */
							set_segmdesc(gdt + 1003, finfo[x].size - 1, (int) p, AR_CODE32_ER);
							/* 跳转到应用程序执行 */
							farjmp(0, 1003 * 8);
							/* 释放内存 */
							memman_free_4k(memman, (int) p, finfo[x].size);
						} else {
							/* 文件没有找到 */
							putfonts8_asc_sht(sheet, 8, cursor_y, COL8_FFFFFF, COL8_000000, "File not found.", 15);
							cursor_y = cons_newline(cursor_y, sheet);
						}
						cursor_y = cons_newline(cursor_y, sheet);
					} else if (cmdline[0] != 0) {
						/* 控制台有输入但不是上面的命令 */
						putfonts8_asc_sht(sheet, 8, cursor_y, COL8_FFFFFF, COL8_000000, "Bad command.", 12);
						cursor_y = cons_newline(cursor_y, sheet);
						cursor_y = cons_newline(cursor_y, sheet);
					}
					/* 输出一个'>' */
					putfonts8_asc_sht(sheet, 8, cursor_y, COL8_FFFFFF, COL8_000000, ">", 1);
					cursor_x = 16;
				} else {
					/* 一般字符 */
					if (cursor_x < 240) {
						/* 显示一个字符后光标向右移8个像素点 */
						s[0] = i - 256;
						s[1] = 0;
						cmdline[cursor_x / 8 - 2] = i - 256;
						putfonts8_asc_sht(sheet, cursor_x, cursor_y, COL8_FFFFFF, COL8_000000, s, 1);
						cursor_x += 8;
					}
				}
			}
			/* 如果需要显示光标 */
			if (cursor_c >= 0) {
				boxfill8(sheet->buf, sheet->bxsize, cursor_c, cursor_x, cursor_y, cursor_x + 7, cursor_y + 15);
			}
			sheet_refresh(sheet, cursor_x, cursor_y, cursor_x + 8, cursor_y + 16);
		}
	}
}
示例#21
0
void console_task(struct SHEET *sheet, unsigned int memtotal)
{
	struct TIMER *timer;
	struct TASK *task = task_now();
	int i, fifobuf[128], cursor_x = 16, cursor_y = 28, cursor_c = -1;
	char s[30], cmdline[30], *p;
	struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR;
	int x, y;
	struct FILEINFO *finfo = (struct FILEINFO *) (ADR_DISKIMG + 0x002600);
	int *fat = (int *) memman_alloc_4k(memman, 4 * 2880);
	struct SEGMENT_DESCRIPTOR *gdt = (struct SEGMENT_DESCRIPTOR *) ADR_GDT;

	fifo32_init(&task->fifo, 128, fifobuf, task);
	timer = timer_alloc();
	timer_init(timer, &task->fifo, 1);
	timer_settime(timer, 50);
	file_readfat(fat, (unsigned char *) (ADR_DISKIMG + 0x000200));

	
	putfonts8_asc_sht(sheet, 8, 28, COL8_FFFFFF, COL8_000000, ">", 1);

	for (;;) {
		io_cli();
		if (fifo32_status(&task->fifo) == 0) {
			task_sleep(task);
			io_sti();
		} else {
			i = fifo32_get(&task->fifo);
			io_sti();
			if (i <= 1) { 
				if (i != 0) {
					timer_init(timer, &task->fifo, 0); 
					if (cursor_c >= 0) {
						cursor_c = COL8_FFFFFF;
					}
				} else {
					timer_init(timer, &task->fifo, 1); 
					if (cursor_c >= 0) {
						cursor_c = COL8_000000;
					}
				}
				timer_settime(timer, 50);
			}
			if (i == 2) {	
				cursor_c = COL8_FFFFFF;
			}
			if (i == 3) {	
				boxfill8(sheet->buf, sheet->bxsize, COL8_000000, cursor_x, cursor_y, cursor_x + 7, cursor_y + 15);
				cursor_c = -1;
			}
			if (256 <= i && i <= 511) { 
				if (i == 8 + 256) {
					
					if (cursor_x > 16) {
						
						putfonts8_asc_sht(sheet, cursor_x, cursor_y, COL8_FFFFFF, COL8_000000, " ", 1);
						cursor_x -= 8;
					}
				} else if (i == 10 + 256) {
					
					
					putfonts8_asc_sht(sheet, cursor_x, cursor_y, COL8_FFFFFF, COL8_000000, " ", 1);
					cmdline[cursor_x / 8 - 2] = 0;
					cursor_y = cons_newline(cursor_y, sheet);
					
					if (strcmp(cmdline, "mem") == 0) {
						
						sprintf(s, "total   %dMB", memtotal / (1024 * 1024));
						putfonts8_asc_sht(sheet, 8, cursor_y, COL8_FFFFFF, COL8_000000, s, 30);
						cursor_y = cons_newline(cursor_y, sheet);
						sprintf(s, "free %dKB", memman_total(memman) / 1024);
						putfonts8_asc_sht(sheet, 8, cursor_y, COL8_FFFFFF, COL8_000000, s, 30);
						cursor_y = cons_newline(cursor_y, sheet);
						cursor_y = cons_newline(cursor_y, sheet);
					} else if (strcmp(cmdline, "cls") == 0) {
						
						for (y = 28; y < 28 + 128; y++) {
							for (x = 8; x < 8 + 240; x++) {
								sheet->buf[x + y * sheet->bxsize] = COL8_000000;
							}
						}
						sheet_refresh(sheet, 8, 28, 8 + 240, 28 + 128);
						cursor_y = 28;
					} else if (strcmp(cmdline, "dir") == 0) {
						
						for (x = 0; x < 224; x++) {
							if (finfo[x].name[0] == 0x00) {
								break;
							}
							if (finfo[x].name[0] != 0xe5) {
								if ((finfo[x].type & 0x18) == 0) {
									sprintf(s, "filename.ext   %7d", finfo[x].size);
									for (y = 0; y < 8; y++) {
										s[y] = finfo[x].name[y];
									}
									s[ 9] = finfo[x].ext[0];
									s[10] = finfo[x].ext[1];
									s[11] = finfo[x].ext[2];
									putfonts8_asc_sht(sheet, 8, cursor_y, COL8_FFFFFF, COL8_000000, s, 30);
									cursor_y = cons_newline(cursor_y, sheet);
								}
							}
						}
						cursor_y = cons_newline(cursor_y, sheet);
					} else if (strncmp(cmdline, "type ", 5) == 0) {
						
						
						for (y = 0; y < 11; y++) {
							s[y] = ' ';
						}
						y = 0;
						for (x = 5; y < 11 && cmdline[x] != 0; x++) {
							if (cmdline[x] == '.' && y <= 8) {
								y = 8;
							} else {
								s[y] = cmdline[x];
								if ('a' <= s[y] && s[y] <= 'z') {
									
									s[y] -= 0x20;
								} 
								y++;
							}
						}
						
						for (x = 0; x < 224; ) {
							if (finfo[x].name[0] == 0x00) {
								break;
							}
							if ((finfo[x].type & 0x18) == 0) {
								for (y = 0; y < 11; y++) {
									if (finfo[x].name[y] != s[y]) {
										goto type_next_file;
									}
								}
								break; 
							}
		type_next_file:
							x++;
						}
						if (x < 224 && finfo[x].name[0] != 0x00) {
							
							p = (char *) memman_alloc_4k(memman, finfo[x].size);
							file_loadfile(finfo[x].clustno, finfo[x].size, p, fat, (char *) (ADR_DISKIMG + 0x003e00));
							cursor_x = 8;
							for (y = 0; y < finfo[x].size; y++) {
								
								s[0] = p[y];
								s[1] = 0;
								if (s[0] == 0x09) {	
									for (;;) {
										putfonts8_asc_sht(sheet, cursor_x, cursor_y, COL8_FFFFFF, COL8_000000, " ", 1);
										cursor_x += 8;
										if (cursor_x == 8 + 240) {
											cursor_x = 8;
											cursor_y = cons_newline(cursor_y, sheet);
										}
										if (((cursor_x - 8) & 0x1f) == 0) {
											break;	
										}
									}
								} else if (s[0] == 0x0a) {	
									cursor_x = 8;
									cursor_y = cons_newline(cursor_y, sheet);
								} else if (s[0] == 0x0d) {	
									
								} else {	
									putfonts8_asc_sht(sheet, cursor_x, cursor_y, COL8_FFFFFF, COL8_000000, s, 1);
									cursor_x += 8;
									if (cursor_x == 8 + 240) {
										cursor_x = 8;
										cursor_y = cons_newline(cursor_y, sheet);
									}
								}
							}
							memman_free_4k(memman, (int) p, finfo[x].size);
						} else {
							
							putfonts8_asc_sht(sheet, 8, cursor_y, COL8_FFFFFF, COL8_000000, "File not found.", 15);
							cursor_y = cons_newline(cursor_y, sheet);
						}
						cursor_y = cons_newline(cursor_y, sheet);
					} else if (strcmp(cmdline, "hlt") == 0) {
						
						for (y = 0; y < 11; y++) {
							s[y] = ' ';
						}
						s[0] = 'H';
						s[1] = 'L';
						s[2] = 'T';
						s[8] = 'H';
						s[9] = 'R';
						s[10] = 'B';
						for (x = 0; x < 224; ) {
							if (finfo[x].name[0] == 0x00) {
								break;
							}
							if ((finfo[x].type & 0x18) == 0) {
								for (y = 0; y < 11; y++) {
									if (finfo[x].name[y] != s[y]) {
										goto hlt_next_file;
									}
								}
								break; 
							}
		hlt_next_file:
							x++;
						}
						if (x < 224 && finfo[x].name[0] != 0x00) {
							
							p = (char *) memman_alloc_4k(memman, finfo[x].size);
							file_loadfile(finfo[x].clustno, finfo[x].size, p, fat, (char *) (ADR_DISKIMG + 0x003e00));
							set_segmdesc(gdt + 1003, finfo[x].size - 1, (int) p, AR_CODE32_ER);
							farjmp(0, 1003 * 8);
							memman_free_4k(memman, (int) p, finfo[x].size);
						} else {
							
							putfonts8_asc_sht(sheet, 8, cursor_y, COL8_FFFFFF, COL8_000000, "File not found.", 15);
							cursor_y = cons_newline(cursor_y, sheet);
						}
						cursor_y = cons_newline(cursor_y, sheet);
					} else if (cmdline[0] != 0) {
						
						putfonts8_asc_sht(sheet, 8, cursor_y, COL8_FFFFFF, COL8_000000, "Bad command.", 12);
						cursor_y = cons_newline(cursor_y, sheet);
						cursor_y = cons_newline(cursor_y, sheet);
					}
					
					putfonts8_asc_sht(sheet, 8, cursor_y, COL8_FFFFFF, COL8_000000, ">", 1);
					cursor_x = 16;
				} else {
					
					if (cursor_x < 240) {
						
						s[0] = i - 256;
						s[1] = 0;
						cmdline[cursor_x / 8 - 2] = i - 256;
						putfonts8_asc_sht(sheet, cursor_x, cursor_y, COL8_FFFFFF, COL8_000000, s, 1);
						cursor_x += 8;
					}
				}
			}
			
			if (cursor_c >= 0) {
				boxfill8(sheet->buf, sheet->bxsize, cursor_c, cursor_x, cursor_y, cursor_x + 7, cursor_y + 15);
			}
			sheet_refresh(sheet, cursor_x, cursor_y, cursor_x + 8, cursor_y + 16);
		}
	}
}
示例#22
0
文件: console.c 项目: songtzu/study
static int 
cat_command(mem_mgr_t* memmgr, layer_t* layer, int* fat, 
    int cursor_x, int cursor_y, char* cmdline)
{
  /* cat command */
  fileinfo_t* finfo = (fileinfo_t*)(ADR_DISKIMG + 0x002600);
  int x, y;
  char buf[32];
  char* p;

  for (y = 0; y < 11; ++y)
    buf[y] = ' ';
  y = 0;
  for (x = 4; y < 11 && 0 != cmdline[x]; ++x) {
    if ('.' == cmdline[x] && y <= 8)
      y = 8;
    else {
      buf[y] = cmdline[x];
      if ('a' <= buf[y] && buf[y] <= 'z')
        buf[y] -= 0x20;
      ++y;
    }
  }

  /* find file */
  for (x = 0; x < 224; ) {
    if (0x00 == finfo[x].name[0])
      break;
    if (0 == (finfo[x].type & 0x18)) {
      for (y = 0; y < 11; ++y) {
        if (finfo[x].name[y] != buf[y])
          goto __cat_next_file;
      }
      break;
    }
__cat_next_file:
    ++x;
  }
  
  if (x < 224 && 0x00 != finfo[x].name[0]) {
    /* found the file */
    p = (char*)mem_mgr_alloc_4k(memmgr, finfo[x].size);
    file_loadfile(finfo[x].clustno, finfo[x].size, 
        p, fat, (char*)(ADR_DISKIMG + 0x003e00));
    cursor_x = 8;

    for (y = 0; y < finfo[x].size; ++y) {
      /* output the file one character by one character */
      buf[0] = p[y];
      buf[1] = 0;
      if (0x09 == buf[0]) {
        /* tab */
        for ( ; ; ) {
          drawstring_and_refresh(layer, cursor_x, cursor_y, 
              COLOR8_FFFFFF, COLOR8_000000, " ", 1);
          cursor_x += 8;
          if ((8 + 240) == cursor_x) {
            cursor_x = 8;
            cursor_y = console_newline(cursor_y, layer);
          }
          if (0 == ((cursor_x - 8) & 0x1f))
            break;
        }
      }
      else if (0x0a == buf[0]) {
        /* Enter */
        cursor_x = 8;
        cursor_y = console_newline(cursor_y, layer);
      }
      else if (0x0d == buf[0]) {
        /* pass */
      }
      else {
        /* normal characters */
        drawstring_and_refresh(layer, cursor_x, cursor_y, 
            COLOR8_FFFFFF, COLOR8_000000, buf, 1);
        cursor_x += 8;
        if ((8 + 240) == cursor_x) {
          cursor_x = 8;
          cursor_y = console_newline(cursor_y, layer);
        }
      }
    }
    mem_mgr_free_4k(memmgr, (int)p, finfo[x].size);
  }
  else {
    /* can't find the file */
    drawstring_and_refresh(layer, 8, cursor_y, 
        COLOR8_FFFFFF, COLOR8_000000, "File not fount.", 15);
    cursor_y = console_newline(cursor_y, layer);
  }

  return console_newline(cursor_y, layer);
}