Exemple #1
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;
}
Exemple #2
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;
}
Exemple #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[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;
}
Exemple #4
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;
}
Exemple #5
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 ;
}
Exemple #6
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);
}
Exemple #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], *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;
}
Exemple #8
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;
}
Exemple #9
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;
}
Exemple #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;
}
Exemple #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;
}
Exemple #12
0
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);
}
Exemple #13
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 ;
}
Exemple #14
0
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;
}
Exemple #15
0
/* do_search()
 * Description: Perform a lookup of the specified search string in all Clear manifests
 * for the current os release.
 */
static void do_search(struct manifest *MoM, char search_type, char *search_term)
{
	struct list *list;
	struct list *sublist;
	struct file *file;
	struct file *subfile;
	struct list *bundle_info = NULL;
	struct manifest *subman = NULL;
	int i;
	bool done_with_bundle, done_with_search = false;
	bool hit = false;
	bool man_load_failures = false;
	long hit_count = 0;

	list = MoM->manifests;
	while (list && !done_with_search) {
		file = list->data;
		list = list->next;
		done_with_bundle = false;

		/* Load sub-manifest */
		subman = load_manifest(file->last_change, file, MoM, false);
		if (!subman) {
			fprintf(stderr, "Failed to load manifest %s\n", file->filename);
			man_load_failures = true;
			continue;
		}

		/* record contentsize and includes for install size calculation */
		struct bundle_result *bundle = NULL;
		bundle = calloc(sizeof(struct bundle_result), 1);
		ON_NULL_ABORT(bundle);
		/* copy relevant information over for future use */
		strncpy(bundle->bundle_name, subman->component, BUNDLE_NAME_MAXLEN - 1);
		bundle->topsize = subman->contentsize;
		/* do a deep copy of the includes list */
		bundle->includes = list_deep_clone_strs(subman->includes);
		bundle_info = list_prepend_data(bundle_info, bundle);

		if (display_files) {
			/* Display bundle name. Marked up for pattern matchability */
			fprintf(stderr, "--Bundle: %s--\n", file->filename);
		}

		/* Loop through sub-manifest, searching for files matching the desired pattern */
		sublist = subman->files;
		while (sublist && !done_with_bundle) {
			subfile = sublist->data;
			sublist = sublist->next;

			if ((!subfile->is_file) && (!subfile->is_link)) {
				continue;
			}

			if (display_files) {
				/* Just display filename */
				file_search(subfile->filename, NULL, NULL);
			} else if (search_type == '0') {
				/* Search for exact match, not path addition */
				if (file_search(subfile->filename, "", search_term)) {
					report_find(file->filename, subfile->filename, search_term);
					hit = true;
				}
			} else if (search_type == 'l') {
				/* Check each supported library path for a match */
				for (i = 0; lib_paths[i] != NULL; i++) {
					if (file_search(subfile->filename, lib_paths[i], search_term)) {
						report_find(file->filename, subfile->filename, search_term);
						hit = true;
					}
				}
			} else if (search_type == 'b') {
				/* Check each supported path for binaries */
				for (i = 0; bin_paths[i] != NULL; i++) {
					if (file_search(subfile->filename, bin_paths[i], search_term)) {
						report_find(file->filename, subfile->filename, search_term);
						hit = true;
					}
				}
			} else {
				fprintf(stderr, "Unrecognized search type. -b or -l supported\n");
				done_with_search = true;
				break;
			}

			/* Determine the level of completion we've reached */
			if (hit) {
				if (scope == 'b') {
					done_with_bundle = true;
				} else if (scope == 'o') {
					done_with_bundle = true;
					done_with_search = true;
				}

				hit_count++;
			}
			hit = false;
		}

		free_manifest(subman);
	}

	if (!hit_count) {
		fprintf(stderr, "Search term not found.\n");
	}

	bool display_size = (scope != 'o' && !man_load_failures);
	if (display_size) {
		apply_size_penalty(bundle_info);
	}
	list_free_list_and_data(bundle_info, free_bundle_result_data);

	if (num_results != INT_MAX) {
		sort_results();
	} else {
		results = list_sort(results, bundle_size_cmp);
	}

	if (csv_format) {
		print_csv_results();
	} else {
		print_final_results(display_size);
	}
	list_free_list_and_data(results, free_bundle_result_data);
}
Exemple #16
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;
}
Exemple #17
0
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);
            }
        }
    }
}
Exemple #18
0
void load_background_pic(char* buf_back, int *fat)
{
	struct DLL_STRPICENV env;
	char * filebuf, *p;
	char filename[20] ;
	sprintf(filename, "night.bmp");
	p = filename;
	
	int  i, j, fsize, info[8];
	struct RGB picbuf[300*300], *q;	 //这里的空间不能太大,否则内核的栈不够用了
	if(picbuf == 0)
	{
		return;
	}
	struct BOOTINFO *binfo = (struct BOOTINFO *) ADR_BOOTINFO;

	char strbuf[50];
	sprintf(strbuf,p);
	boxfill8(binfo->vram,binfo->scrnx, COL8_848484, 10, 200-16, 200+8*50, 200+16);
	putfonts8_asc(binfo->vram, binfo->scrnx, 10, 200-16, COL8_000000, strbuf);		
	
	//查找文件
	struct FILEINFO *finfo = file_search(p,(struct FILEINFO *) (ADR_DISKIMG + 0x002600), 224); 
	if( finfo ==0 ) //文件找不到
		return;

	sprintf(strbuf,"found %s, clustno = %d, size = %d", filename, finfo->clustno, finfo->size);
	boxfill8(binfo->vram,binfo->scrnx, COL8_848484, 10, 200, 200+8*50, 200+16);
	putfonts8_asc(binfo->vram, binfo->scrnx, 10, 200, COL8_000000, strbuf);					
	
	fsize = finfo->size;
	//加载文件内容
	filebuf = file_loadfile2(finfo->clustno,&fsize,fat);
	
	/* 检查文件类型*/
	if (info_BMP(&env, info, fsize, filebuf) == 0) {
		/* 不是BMP */
		if (info_JPEG(&env, info, fsize, filebuf) == 0) {
			/*  不是JPEG */
			//api_putstr0("file type unknown.\n");
			//api_end();
			memman_free_4k((struct MEMMAN *) MEMMAN_ADDR, (int)filebuf, fsize);
			return;
		}
	}
	sprintf(strbuf,"load file contents, x = %d, y = %d, info[0] = %d",info[2],info[3],info[0]);
	boxfill8(binfo->vram,binfo->scrnx, COL8_848484, 10, 200+16, 200+8*50, 200+16+16);
	putfonts8_asc(binfo->vram, binfo->scrnx, 10, 200+16, COL8_000000, strbuf);			
	
	/* 上面其中一个info函数调用成功的话,info中包含以下信息 */
	/*	info[0] : 文件类型 (1:BMP, 2:JPEG) */
	/*	info[1] : 颜色数信息 */
	/*	info[2] : xsize */
	/*	info[3] : ysize */

	if (info[2] > 500 || info[3] > 400) {
		//error("picture too large.\n");
		memman_free_4k((struct MEMMAN *) MEMMAN_ADDR, (int)filebuf, fsize);
		return;
	}

	if (info[0] == 1) {
		i = decode0_BMP (&env, fsize, filebuf, 4, (char *) picbuf, 0);
	} else {
		i = decode0_JPEG(&env, fsize, filebuf, 4, (char *) picbuf, 0);
	}
	
	sprintf(strbuf,"parse image, i = %d",i);
	boxfill8(binfo->vram,binfo->scrnx, COL8_848484, 10, 200+16+16, 200+8*50, 200+16+16+16);
	putfonts8_asc(binfo->vram, binfo->scrnx, 10, 200+16+16, COL8_000000, strbuf);	

	if (i != 0) {
		//error("decode error.\n");
		memman_free_4k((struct MEMMAN *) MEMMAN_ADDR, (int)filebuf, fsize);
		return;
	}
	
	buf_back = buf_back + binfo->scrnx * ( (binfo->scrny - 24) / 2 - info[3] / 2);

	for (i = 0; i < info[3]; i++) {
		p = buf_back + i * binfo->scrnx + binfo->scrnx / 2 - info[2] / 2;
		q = picbuf + i * info[2];
		for (j = 0; j < info[2]; j++) {
			p[j] = rgb2pal(q[j].r, q[j].g, q[j].b, j, i);
		}
	}
	
	memman_free_4k((struct MEMMAN *) MEMMAN_ADDR, (int)filebuf, fsize);
}
Exemple #19
0
void HariMain(void)
{
  int mmx = -1, mmy = -1, mmx2 = 0;
  struct SHEET *sht = 0, *key_win;
  struct BOOTINFO *binfo = (struct BOOTINFO *)0x0ff0;
  int xsize = (*binfo).scrnx;
  int ysize = (*binfo).scrny;
  int mx = xsize/2;
  int my = ysize/2;
  int new_mx = -1, new_my = 0, new_wx = 0x7fffffff, new_wy = 0;
  int fifobuf[128], keycmd_buf[32], *cons_fifo[2];
  struct MOUSE_DEC mdec;
  unsigned char s[32];
  unsigned int memtotal;
  struct MEMMAN *memman = (struct MEMMAN *)MEMMAN_ADDR;
  int key_shift = 0, key_leds = (binfo->leds >> 4) & 7, keycmd_wait = -1;

  struct SHTCTL *shtctl;
  struct SHEET *sht_back, *sht_mouse;
  unsigned char *buf_back, buf_mouse[256], *buf_cons[2];
  struct TIMER *timer;
  struct FIFO32 fifo, keycmd;

  struct TASK *task_a, *task_cons[2];

  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, '(', ')', '~', '=', '~', '|', 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
  };
  extern char hankaku[4096];

  init_gdtidt ();
  init_pic ();
  io_sti ();

  fifo32_init(&fifo, 32, fifobuf, 0);
  fifo32_init(&keycmd, 32, keycmd_buf, 0);

  init_pit();
  io_out8(PIC0_IMR, 0xf8); /* Allow PIT and Keyboard (11111000) */
  io_out8(PIC1_IMR, 0xef); /* Allow Mouse (11101111) */
  init_keyboard (&fifo, 256);
  enable_mouse (&fifo, 512, &mdec);

  timer = timer_alloc();
  timer_init(timer, &fifo, 1);
  timer_settime(timer, 50);

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

  init_pallete();
  shtctl = shtctl_init (memman, binfo->vram, binfo->scrnx, binfo->scrny);
  sht_back  = sheet_alloc(shtctl);
  sht_mouse = 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);
  sheet_setbuf (sht_mouse, buf_mouse, 16, 16, 99);
  init_screen (buf_back, xsize, ysize);
  init_mouse_cursor8 (buf_mouse, 99);

  *((int *) 0x0fec) = (int) &fifo;

  //=====================
  // Task Settings
  //=====================
  task_a = task_init(memman);
  fifo.task = task_a;
  task_a->langmode = 0;
  task_run (task_a, 1, 0);

  /* console sheet */
  key_win = open_console (shtctl, memtotal);

  //=======================
  // Sheet Setting
  //=======================

  *((int *) 0x0fe4) = (int) shtctl;

  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);

  sheet_refresh (sht_back, 0, 0, binfo->scrnx, 48);

  keywin_on (key_win);

  fifo32_put (&keycmd, KEYCMD_LED);
  fifo32_put (&keycmd, key_leds);

  /* Reading nihongo.fnt */
  unsigned char *nihongo = (unsigned char *)memman_alloc_4k (memman, 16 * 256 + 32 * 94 * 47);
  int *fat = (int *)memman_alloc_4k (memman, 4 * 2880);
  file_readfat (fat, (unsigned char *)(ADR_DISKIMG + 0x000200));
  struct FILEINFO *finfo = file_search ("nihongo.fnt", (struct FILEINFO *)(ADR_DISKIMG + 0x002600), 224);
  if (finfo != 0) {
	int i = finfo->size;
	nihongo = file_loadfile2 (finfo->clustno, &i, fat);
  } else {
	nihongo = (unsigned char *)memman_alloc_4k (memman, 16 * 256 + 32 * 94 * 47);
    for (int i = 0; i < 16 * 256; i++) {
      nihongo[i] = hankaku[i];
    }
    for (int i = 16 * 256; i < 16 * 256 + 32 * 94 * 47; i++) {
      nihongo[i] = 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) {
	  /* execute draw if FIFO is empty */
	  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 {
      int i = fifo32_get(&fifo);
      io_sti();
	  if (key_win != 0 && key_win->flags == 0) {   // input Window is closed
		if (shtctl->top == 1) { // ony mouse and background
		  key_win = 0;
		} else {
		  key_win = shtctl->sheets[shtctl->top - 1];
		  keywin_on (key_win);
		}
	  }
      if (256 <= i && i <= 511) {  // Keyboard Data
		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) {
		  fifo32_put(&key_win->task->fifo, s[0] + 256);
		}
		if (i == 256 + 0x0f && key_win != 0) { // Tab
		  keywin_off (key_win);
		  int 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) {  // Left Shift ON
		  key_shift |= 1;
		}
		if (i == 256 + 0x36) {  // Right Shift ON
		  key_shift |= 2;
		}
		if (i == 256 + 0xaa) {  // Left Shift OFF
		  key_shift &= ~1;
		}
		if (i == 256 + 0xb6) {  // Right Shift ON
		  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) {
		  struct TASK *task = key_win->task;
		  if (task != 0 && task->tss.ss0 != 0) {   /* Shift+F1 */
			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) {  // KeyBoard receive Data
		  keycmd_wait = -1;
		}
		if (i == 256 + 0xfe) {  // KeyBoard failed to receive Data
		  wait_KBC_sendready ();
		  io_out8(PORT_KEYDAT, keycmd_wait);
		}
	  } else if (512 <= i && i <= 767) {  // Mouse Data
        if (mouse_decode(&mdec, i-512) != 0) {
          mx += mdec.x;
          my += mdec.y;
          if (mx < 0) { mx = 0; } if (mx > binfo->scrnx - 1) { mx = binfo->scrnx - 1; }
          if (my < 0) { my = 0; } if (my > binfo->scrny - 1) { my = binfo->scrny - 1; }

          // sprintf(s, "(%d, %d)", mx, my);
          // putfonts8_asc_sht (sht_back, 0, 0, COL8_FFFFFF, COL8_008484, s, 10);

          sheet_slide (sht_mouse, mx, my);

		  new_mx = mx;
		  new_my = my;
          if ((mdec.btn & 0x01) != 0) {
			/* Left Mouse Button is down */
			if (mmx < 0) {
			  /* Normal Mode */
			  for (int j = shtctl->top - 1; j > 0; j--) {
				sht = shtctl->sheets[j];
				int x = mx - sht->vx0;
				int 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) {
					  // "X" button is clicked
					  if ((sht->flags & 0x10) != 0) {
						// Window is made by Application?
						struct TASK *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 {
						struct TASK *task = sht->task;
						sheet_updown (sht, -1);
						keywin_off (key_win);
						key_win = shtctl->sheets[shtctl->top-1];
						keywin_off (key_win);
						io_cli ();
						fifo32_put (&task->fifo, 4);
						io_sti ();
					  }
					}
					break;
				  }
				}
			  }
			} else {
			  // Moving window mode
			  int x = mx - mmx;
			  int 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) {
		struct SHEET *sht2 = shtctl->sheets0 + (i - 2024);
		memman_free_4k (memman, (int)sht2->buf, 256 * 165);
		sheet_free (sht2);
	  }
    }
  }
}
Exemple #20
0
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 */
	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) {
		i = finfo->size;
		nihongo = file_loadfile2(finfo->clustno, &i, fat);
	} else {
		nihongo = (unsigned char *) memman_alloc_4k(memman, 16 * 256 + 32 * 94 * 47);
		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) { /*一般字符、退格键、回车键*/
					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) { /*左Shift ON */
					key_shift |= 1;
				}
				if (i == 256 + 0x36) { /*右Shift ON */
					key_shift |= 2;
				}
				if (i == 256 + 0xaa) { /*左Shift OFF */
					key_shift &= ~1;
				}
				if (i == 256 + 0xb6) { /*右Shift 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) {
					/* 已经收集了3字节的数据,移动光标 */
					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);
			}
		}
	}
}
Exemple #21
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;
}
/*!
 * \brief Find gzip ramdisk offset in old-style Loki image
 *
 * This function will search for gzip headers (`0x1f8b08`) with a flags byte of
 * `0x00` or `0x08`. It will find the first occurrence of either magic string.
 * If both are found, the one with the flags byte set to `0x08` takes precedence
 * as it indiciates that the original filename field is set. This is usually the
 * case for ramdisks packed via the `gzip` command line tool.
 *
 * \pre The file position can be at any offset prior to calling this function.
 *
 * \post The file pointer position is undefined after this function returns.
 *       Use File::seek() to return to a known position.
 *
 * \param[in] reader Reader to set error message
 * \param[in] file File handle
 * \param[in] start_offset Starting offset for search
 * \param[out] gzip_offset_out Pointer to store gzip ramdisk offset
 *
 * \return
 *   * Nothing if a gzip offset is found
 *   * A LokiError if no gzip offsets are found
 *   * A specific error if any file operation fails
 */
oc::result<void>
LokiFormatReader::find_gzip_offset_old(Reader &reader, File &file,
                                       uint32_t start_offset,
                                       uint64_t &gzip_offset_out)
{
    struct SearchResult
    {
        std::optional<uint64_t> flag0_offset;
        std::optional<uint64_t> flag8_offset;
    };

    // gzip header:
    // byte 0-1 : magic bytes 0x1f, 0x8b
    // byte 2   : compression (0x08 = deflate)
    // byte 3   : flags
    // byte 4-7 : modification timestamp
    // byte 8   : compression flags
    // byte 9   : operating system

    static const unsigned char gzip_deflate_magic[] = { 0x1f, 0x8b, 0x08 };

    SearchResult result = {};

    // Find first result with flags == 0x00 and flags == 0x08
    auto result_cb = [&](File &file_, uint64_t offset)
            -> oc::result<FileSearchAction> {
        unsigned char flags;

        // Stop early if possible
        if (result.flag0_offset && result.flag8_offset) {
            return FileSearchAction::Stop;
        }

        // Save original position
        OUTCOME_TRY(orig_offset, file_.seek(0, SEEK_CUR));

        // Seek to flags byte
        OUTCOME_TRYV(file_.seek(static_cast<int64_t>(offset + 3), SEEK_SET));

        // Read next bytes for flags
        auto ret = file_read_exact(file_, &flags, sizeof(flags));
        if (!ret) {
            if (ret.error() == FileError::UnexpectedEof) {
                return FileSearchAction::Stop;
            } else {
                return ret.as_failure();
            }
        }

        if (!result.flag0_offset && flags == 0x00) {
            result.flag0_offset = offset;
        } else if (!result.flag8_offset && flags == 0x08) {
            result.flag8_offset = offset;
        }

        // Restore original position as per contract
        OUTCOME_TRYV(file_.seek(static_cast<int64_t>(orig_offset), SEEK_SET));

        return FileSearchAction::Continue;
    };

    auto ret = file_search(file, start_offset, {}, 0, gzip_deflate_magic,
                           sizeof(gzip_deflate_magic), {}, result_cb);
    if (!ret) {
        if (file.is_fatal()) { reader.set_fatal(); }
        return ret.as_failure();
    }

    // Prefer gzip header with original filename flag since most loki'd boot
    // images will have been compressed manually with the gzip tool
    if (result.flag8_offset) {
        gzip_offset_out = *result.flag8_offset;
    } else if (result.flag0_offset) {
        gzip_offset_out = *result.flag0_offset;
    } else {
        return LokiError::NoRamdiskGzipHeaderFound;
    }

    return oc::success();
}
/*!
 * \brief Find and read Loki ramdisk address
 *
 * \pre The file position can be at any offset prior to calling this function.
 *
 * \post The file pointer position is undefined after this function returns.
 *       Use File::seek() to return to a known position.
 *
 * \param[in] reader Reader to set error message
 * \param[in] file File handle
 * \param[in] hdr Android header
 * \param[in] loki_hdr Loki header
 * \param[out] ramdisk_addr_out Pointer to store ramdisk address
 *
 * \return
 *   * Nothing if the ramdisk address is found
 *   * A LokiError if the ramdisk address is not found
 *   * A specific error code if any file operation fails
 */
oc::result<void>
LokiFormatReader::find_ramdisk_address(Reader &reader, File &file,
                                       const android::AndroidHeader &hdr,
                                       const LokiHeader &loki_hdr,
                                       uint32_t &ramdisk_addr_out)
{
    // If the boot image was patched with a newer version of loki, find the
    // ramdisk offset in the shell code
    uint32_t ramdisk_addr = 0;

    if (loki_hdr.ramdisk_addr != 0) {
        uint64_t offset = 0;

        auto result_cb = [&](File &file_, uint64_t offset_)
                -> oc::result<FileSearchAction> {
            (void) file_;
            offset = offset_;
            return FileSearchAction::Continue;
        };

        auto ret = file_search(file, {}, {}, 0, LOKI_SHELLCODE,
                               LOKI_SHELLCODE_SIZE - 9, 1, result_cb);
        if (!ret) {
            if (file.is_fatal()) { reader.set_fatal(); }
            return ret.as_failure();
        }

        if (offset == 0) {
            return LokiError::ShellcodeNotFound;
        }

        offset += LOKI_SHELLCODE_SIZE - 5;

        auto seek_ret = file.seek(static_cast<int64_t>(offset), SEEK_SET);
        if (!seek_ret) {
            if (file.is_fatal()) { reader.set_fatal(); }
            return seek_ret.as_failure();
        }

        auto read_ret = file_read_exact(file, &ramdisk_addr,
                                        sizeof(ramdisk_addr));
        if (!read_ret) {
            if (file.is_fatal()) { reader.set_fatal(); }
            return read_ret.as_failure();
        }

        ramdisk_addr = mb_le32toh(ramdisk_addr);
    } else {
        // Otherwise, use the default for jflte (- 0x00008000 + 0x02000000)

        if (hdr.kernel_addr > UINT32_MAX - 0x01ff8000) {
            //DEBUG("Invalid kernel address: %" PRIu32, hdr.kernel_addr);
            return LokiError::InvalidKernelAddress;
        }

        ramdisk_addr = hdr.kernel_addr + 0x01ff8000;
    }

    ramdisk_addr_out = ramdisk_addr;
    return oc::success();
}
Exemple #24
0
void HariMain(void)
{
	/*
	**最初的这部分变量没有通过内存管理来分配,它们本身属于操作系统的一部分,存在于bootpack.hrb所在的那块儿内存空间中
	*/
	BOOTINFO *binfo = (BOOTINFO *) ADR_BOOTINFO;
	MOUSE_DECODE mouse_dec;
	MEMMANAGE *memmanage = (MEMMANAGE *)MEMMANAGE_ADDR;
	LAYER_MANAGE *layer_manage;
	LAYER *layer_bg, *layer_mouse;
	FIFO fifo_mutual;									//缓冲区管理,所有中断公用的
	FIFO keycmd_fifo;									
	TASK *task_a, *task;				//后面的那个task只是作为一个临时变量来用的
	int fifobuf[128], keycmd_buf[32], *console_fifo[2];							//缓冲区
	int mCursorX, mCursorY;				//鼠标光标显示位置的横纵坐标
	int key_shift = 0, key_ctrl = 0, key_leds = (binfo->leds >> 4) & 7, keycmd_wait = -1;			//标志键盘输入到哪个窗口中
	int j, x, y, last_mcursorX = -1, last_mcursorY= -1, tmp_layerX = 0;			//last_mcursorX这两个变量记录的是鼠标移动之前的坐标
	int new_mcursorX = -1, new_mcursorY = 0, new_layerX = 0x7fffffff, new_layerY = 0;
	LAYER *layer = 0, *key_to_window, *layer_to_free;							//key_to_window这个变量记录当前的键盘输入到哪个窗口中
	unsigned int memory_total, i;
	unsigned char buf_cursor[mCursorWidth * mCursorHeight];
	unsigned char *buf_bg;		//屏幕的大背景会在init_screen的时候画出来,这里只需要一个指向它的指针即可
	char strings[40];
	int *fat;
	unsigned char *hzset;
	FILEINFO *finfo;
	extern char charset[4096];
	
	mCursorX = binfo->scrnx / 2;			
	mCursorY = (binfo->scrny - 28)/ 2;		//减去下方任务栏的高度
	
	
	/*初始化GDT和IDT表以及PIC板的数据*/
	init_GDTandIDT();				//初始化GDT和IDT表
	init_pic();						//初始化PIC主从板数据,除了IRQ2禁止了全部中断
	io_sti();						//开始接收中断
	
	init_fifo(&keycmd_fifo, 32, keycmd_buf, 0);
	/*初始化接收中断的缓冲区*/
	init_fifo(&fifo_mutual, 128, fifobuf, 0);				//初始化mouseFIFO缓冲区,现在还没任务,先指定为0
	
	/*初始化PIT中断控制*/
	init_PIT();
		/*若要接收鼠标中断需要两个步骤,首先必须使鼠标控制电路(就是键盘控制电路的一部分)有效,然后要使鼠标本身有效*/
	init_keyboard(&fifo_mutual, 256);						//初始化键盘控制器电路
	enable_mouse(&fifo_mutual, 512, &mouse_dec);			//激活鼠标
	
	/*开放各种中断*/
	io_out8(PIC0_IMR, 0xf8);			//PIC0开发IRQ(11111000),开放IRQ0、IRQ1和IRQ2,定时器、键盘中断和从PIC板
	io_out8(PIC1_IMR, 0xef); 			//PIC1开放IRQ(11101111), 开放鼠标中断
	
	/*内存检查*/
	i = memtest(0x00400000, 0xbfffffff) / (1024 * 1024);	//i的单位是MB
	
	/*内存管理*/
	memmanage_init(memmanage);
	memory_total = i * 1024 * 1024;
	memmanage_free_4K(memmanage, 0x00001000, 0x0009e000);
	memmanage_free_4K(memmanage, 0x00400000, memory_total - 0x00400000);
	/*初始化调色板,为图形界面做准备*/
	init_palette();						//初始化调色板
	
	/*初始化图层管理,并且初始化鼠标光标和背景的图层*/
	layer_manage = layer_man_init(memmanage, binfo->vram, binfo->scrnx, binfo->scrny);
	*((int *) 0x0fe4) = (int) layer_manage;
	
	/*初始化任务切换管理*/
	task_a = task_init(memmanage);		//这个task_a其实代表的就是这些鼠标键盘等的任务
	fifo_mutual.task = task_a;			//为鼠标键盘等的缓冲区指定唤醒任务为task_a
	task_run(task_a, 1, 2);
	task_a->lanmode = 0;					//默认的语言模式是英文模式
	
	layer_bg = layer_alloc(layer_manage);			//为背景分配图层
	layer_mouse = layer_alloc(layer_manage);		//为鼠标分配图层
	
	buf_bg = (unsigned char *)memmanage_alloc_4K(memmanage, binfo->scrnx * binfo->scrny);		//为背景图形的内容分配内存
	
	/*为各个图形的图层内容进行设定*/
	layer_set(layer_bg, buf_bg, binfo->scrnx, binfo->scrny, -1);			
	layer_set(layer_mouse, buf_cursor, 16, 16 ,99);
	
	/*初始化整个桌面背景*/
	init_screen(buf_bg, binfo->scrnx, binfo->scrny);				//这个时候的init_screen不再是直接画出背景,而是在mBg内存地址中填写好背景内容
	layer_slide(layer_bg, 0, 0);									//把背景图层从(0,0)坐标开始画
	
	/*初始化鼠标图标*/
	init_mouse_cursor(buf_cursor, 99);								//初始化鼠标光标
	layer_slide(layer_mouse, mCursorX, mCursorY);					//现在显示图形不需要再用displayShape函数了,直接用这个图层管理的绘图函数就行

	/*载入汉字字符库*/
	fat = (int *)memmanage_alloc_4K(memmanage, 4 * 2880);
	file_readfat(fat, (unsigned char *)(ADR_DISKIMG + 0x000200));
	finfo = file_search("hzset.fnt", (FILEINFO *)(ADR_DISKIMG + 0x002600), 224);
	//找到这个字符库文件的话,就把字符库载入
	if(0 != finfo)
	{
		i = finfo->size;				//为了防止finfo->size的值被修改,用了i做中间变量
		hzset = file_load_tekfile(finfo->clusterno, &i, fat);		//函数内部就已经给要解压的文件分配好了内存
	}
	//找不到字符库文件的话,就把内置英文字符库载入,后面的字符全部用方块(0xff)填充
	else
	{
		hzset = (unsigned char *)memmanage_alloc_4K(memmanage, 16 * 256 + 32 * 5170);		//共256个半角英文字符,5170个全角中文字符
		for(i = 0; i < 16 * 256; i++)
		{
			hzset[i] = charset[i];
		}
		for(i = 16 * 256; i < 16 * 256 + 32 * 5170; i++)
		{
			hzset[i] = 0xff;
		}
	}
	*((int *) 0x0fe8) = (int)hzset;
	memmanage_free_4K(memmanage,(int)fat, 4 * 2880);
	
	/*执行一个命令行窗口任务*/
	key_to_window = open_console(layer_manage, memory_total);		//最初的时候由第一个console接收键盘输入
	
	layer_slide(key_to_window, 8, 2);
	/*设置好各个图层的高度*/
	layer_switch(layer_bg, 0);						//把背景图层调为最底层,高度为0
	layer_switch(key_to_window, 1);					//命令行窗口图层调节为第三层,高度为2
	layer_switch(layer_mouse, 2);					//鼠标图层调为最高层,高度为3	
					
	keywindow_on(key_to_window);
	
	//
	fifo_put(&keycmd_fifo, KEYCMD_LED);
	fifo_put(&keycmd_fifo, key_leds);
	
	*((int *) 0x0fec) = (int) &fifo_mutual;			
	for(;;)
	{ 
		if(fifo_status(&keycmd_fifo) > 0 && keycmd_wait < 0)
		{
			keycmd_wait = fifo_get(&keycmd_fifo);
			wait_KBC_sendready();
			io_out8(PORT_KEYDATA, keycmd_wait);
		}
		/*只有在从中断返回的缓冲区中读取数据的时候才需要禁止中断,因为如果这个时候来了中断而没有禁止的话,
		**有可能读脏数据,即把还没有读出的数据的给抹掉或换成别的数据
		*/
		io_cli();		
		if(0 == fifo_status(&fifo_mutual))		//当前没有中断产生
		{
			//利用CPU空闲的时间来执行耗时的绘图工作(这样的话会造成反应很快的表象,但其实,如果中断很多,尤其是鼠标中断很多的时候,
			//会把之前记录下的new_mcursorX覆盖掉,而只绘制最新的图层坐标)
			if(new_mcursorX >= 0)
			{
				io_sti();
				layer_slide(layer_mouse, new_mcursorX, new_mcursorY);
				new_mcursorX = -1;				//绘制完鼠标之后,就把它的坐标设置为负数,反正鼠标不会出去屏幕,为负数的时候就说明不需要重绘鼠标
			}
			//图层的横坐标为0x7fffffff的时候就不需要重绘了,这是作为一个标志的,它为其他值的时候就需要重绘了
			else if(new_layerX != 0x7fffffff)
			{
				io_sti();
				layer_slide(layer, new_layerX, new_layerY);
				new_layerX = 0x7fffffff;
			}
			//如果不需要重绘鼠标和图层的话,就没有什么工作可做了,进入休眠就可以了
			else
			{
				task_sleep(task_a);	//如果没有需要处理的数据,就自己让自己休眠
				/*上面的那个函数直接就跳转到另一个任务中去了,不过,因为每个人物的默认eflags都是开启中断的,
				**所以不用担心,这个任务还是能被唤醒的,耳环醒后的第一个动作就是为了以防万一先开启中断
				*/
				io_sti();		//万一只有自己在运行的话,则无法睡眠,那么就执行hlt指令好了,这样省电嘛	
			}
		}
		else
		{
			i = fifo_get(&fifo_mutual);
			io_sti();
			//窗口被关闭的情况
			if(0 != key_to_window && 0 == key_to_window->flags)
			{
				//如果当前画面上只剩下鼠标和背景的时候
				if(1 == layer_manage->top)
				{
					key_to_window = 0;
				}
				else
				{
					key_to_window = layer_manage->layers_order[layer_manage->top - 1];			//当窗口被关闭的时候,自动切换成最上层的layer接收键盘输入
					keywindow_on(key_to_window);
				}
			}
			/*
			**有一点需要注意,键盘输入只能由console来接收,如果只剩下task_a任务了,那么这个主任务就只接收打开窗口console的输入
			**其他输入一律不处理,否则会陷入死循环
			*/
			//如果是键盘中断的话,需要处理键盘发送来的中断数据
			if((keyboard_offset <= i) && (i <= keyboard_offset + 255))			
			{
				//判断shift键是否按下,然后使用不同的keytable表
				if(i < 0x80 + keyboard_offset)
				{
					if(0 == key_shift)
					{
						strings[0] = key_table[i - keyboard_offset];
					}
					else
					{
						strings[0] = key_table_shift[i - keyboard_offset];
					}
				}
				else
				{
					strings[0] = 0;
				}
				//判断Caps和Shift键的情况以确定输入大写还是小写字母
				if('A' <= strings[0] && strings[0] <= 'Z')
				{
					//小写字母的情况
					if((0 == (key_leds & 4) && 0 == key_shift) || (0 != (key_leds & 4) && 0 != key_shift))
					{
						strings[0] += 0x20;
					}
				}
				//判断按下的字符是否为一般字符,0对应的字符不处理,对退格键和回车键加上了对应字符,他们对应的table表里的元素不再是0
				//切记key_to_window也就是当前的键盘输入接收图层不能使layer_bg,因为这会造成死循环一直向task_a的fifo中无限填充刚刚输入的字符
				if(strings[0] != 0 && key_to_window != 0 && key_to_window != layer_bg)				
				{
					fifo_put(&key_to_window->task->fifo, strings[0] + 256);
				}
				/*这些都是那些不能打印的特殊按键,它们对应的都是0*/
				//按下“TAB键”的处理情况,切换输入窗口
				if(i == keyboard_offset + 0x0f && key_to_window != 0 && key_to_window != layer_bg)					
				{
					//先让当前的窗口的光标OFF掉
					keywindow_off(key_to_window);
					j = key_to_window->height - 1;
					if(0 == j)
					{
						//如果切换之后的图层是最底层的操作系统的图层,那么就切换成最上层的图层
						j = layer_manage->top - 1;
					}
					key_to_window = layer_manage->layers_order[j];
					//使切换到的窗口的光标ON
					keywindow_on(key_to_window);
				}
				//左或右Ctrl ON
				if(0x1d + keyboard_offset == i)
				{
					key_ctrl = 1;
				}
				//左或右Ctrl OFF
				if(0x9d + keyboard_offset == i)
				{
					key_ctrl = 0;
				}
				//左shift ON
				if(0x2a + keyboard_offset == i)
				{
					key_shift |= 1;
				}
				//右shift ON
				if(0x36 + keyboard_offset == i)
				{
					key_shift |= 2;
				}
				//左shift OFF
				if(0xaa + keyboard_offset == i)
				{
					key_shift &= ~1;
				}
				//左shift OFF
				if(0xb6 + keyboard_offset == i)
				{
					key_shift &= ~2;
				}
				/*对各种锁定键的处理*/
				//CapsLock键
				if(i == keyboard_offset + 0x3a)
				{
					key_leds ^= 4;
					fifo_put(&keycmd_fifo, KEYCMD_LED);
					fifo_put(&keycmd_fifo, key_leds);
				}
				//NumLock键
				if(i == keyboard_offset + 0x45)
				{
					key_leds ^= 2;
					fifo_put(&keycmd_fifo, KEYCMD_LED);
					fifo_put(&keycmd_fifo, key_leds);
				}
				//ScrollLock键
				if(i == keyboard_offset + 0x46)
				{
					key_leds ^= 1;
					fifo_put(&keycmd_fifo, KEYCMD_LED);
					fifo_put(&keycmd_fifo, key_leds);
				}
				
				//如果按下了F2,那么就关闭应用程序
				if((i == keyboard_offset + 0x3C) && key_to_window != 0 && key_to_window != layer_bg)
				{
					task = key_to_window->task;				//找到当前接收键盘输入的(即最前面的)图层所对应的任务
					if(0 != task && task->tss.ss0 != 0)
					{
						console_putstring_toend(task->console, "\nTerminate program! :\n");
						io_cli();
						//让CPU直接跳转到console中执行,不再管应用程序,也就是所谓的停止应用程序继续运行
						task->tss.eax = (int) &(task->tss.esp0);
						task->tss.eip = (int) asm_end_app;
						io_sti();
						/*其实在console任务没有什么中断可处理的时候就会进入休眠,强制结束的时候需要先唤醒它,让他执行结束程序处理
						**但是不唤醒的话,在这个应用程序对应的console窗口有显示的时候也可以停止,只是它需要由定时器每隔0.5秒来唤醒一次
						**所以看起来反应并不及时,最大反应时间为0.5秒
						*/
						task_run(task, -1, 0);
					}
					
				}
				//如果按下了F1,就打开一个console
				if((i == keyboard_offset + 0x3B))
				{
					if(key_to_window != 0)
					{
						keywindow_off(key_to_window);
					}					
					key_to_window = open_console(layer_manage, memory_total);
					layer_slide(key_to_window, 300, 2);
					layer_switch(key_to_window, layer_manage->top);
					//自动把键盘输入切换到这个新打开的console中
					keywindow_on(key_to_window);
				}
				//键盘成功接收到数据
				if(i == keyboard_offset + 0xfa)
				{
					keycmd_wait = -1;
				}
				//键盘没有成功接收到数据
				if(i == keyboard_offset + 0xfe)
				{
					wait_KBC_sendready();
					io_out8(PORT_KEYDATA, keycmd_wait);
				}
			}
			//如果是鼠标中断的话,需要处理鼠标发送来的中断数据
			else if((mouse_offset <= i) && (i <= mouse_offset + 255))		
			{
				if(0 != mouse_decode(&mouse_dec, i - mouse_offset))		//只有返回值为1的时候才说明成功接收完成一次鼠标的中断
				{
					
					/*鼠标的移动*/
					//根据mouse_dec里存储的鼠标信息画出新的鼠标图像
					mCursorX += mouse_dec.x;
					mCursorY += mouse_dec.y;
					//不能让鼠标移出画面
					if(mCursorX < 0)
					{
						mCursorX = 0;
					}
					if(mCursorY < 0)
					{
						mCursorY = 0;
					}
					if(mCursorX > binfo->scrnx - 1)
					{
						mCursorX = binfo->scrnx - 1;
					}
					if(mCursorY > binfo->scrny - 1)
					{
						mCursorY = binfo->scrny - 1;
					}
					//记录下鼠标光标的移动到的位置,等待fifo中为空的时候开始绘图
					new_mcursorX = mCursorX;
					new_mcursorY = mCursorY;
					//按下了左键
					if(0 != (mouse_dec.btn & 0x01))
					{
						//如果last_mcursorX小于0,说明当前不是处于窗口移动模式,那么就需要检查现在鼠标按下左键之后有没有落在某个图层的标题栏上
						if(last_mcursorX < 0)
						{
							for(j = layer_manage->top - 1; j > 0; j--)
							{
								layer = layer_manage->layers_order[j];
								//计算一下鼠标的坐标在不在这个图层里面
								x = mCursorX - layer->x;
								y = mCursorY - layer->y;
								if(0 <= x && x < layer->length && 0 <= y && y <= layer->width)
								{
									//鼠标所在区域也不能是涂层的透明区域
									if(layer->buffer[y * layer->length + x] != layer->color_luc)
									{
										layer_switch(layer, layer_manage->top - 1);
										//如果当前的layer不是接收键盘输入的图层(即最前面的图层),那么就需要切换
										if(layer != key_to_window)
										{
											//鼠标左击窗口所做的事情跟按下TAB键的事情差不多
											keywindow_off(key_to_window);
											key_to_window = layer;
											keywindow_on(key_to_window);
										}
										//查看鼠标当前点击的区域是不是窗口的标题栏,并且不能是关闭按钮所在的区域
										if(3 <= x && x < layer->length - 21 && 3 <= y && y <= 21)
										{
											last_mcursorX = mCursorX;
											last_mcursorY = mCursorY;
											tmp_layerX = layer->x;		//这个tmp_layerX只是个要绘制的图层横坐标的过渡部分,真正的坐标还需要处理
											new_layerY = layer->y;
										}
										//这个是鼠标点击到关闭按钮的情况
										if(layer->length - 21 <= x && x <= layer->length - 5 && 5 <= y && y <= 19)
										{	
											//查看该窗口是否为应用程序的窗口,如果是应用程序产生的窗口而不是console的那个黑窗口,那么这个窗口的flags有0x10
											if(0 != (layer->flags & 0x10))
											{
												//这部分处理跟按下ctrl+x的处理基本一样
												task = layer->task;
												console_putstring_toend(task->console, "Break by 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);
											}
											//不是应用程序的话就是console命令行窗口产生的layer
											else
											{
												//不能再这里的task_a中直接关闭,因为还有些console自身管理的定时器和fat等东西无法释放了
												task = layer->task;
												/*这里只是暂时隐藏console的图层,因为对于有的应用程序的命令行窗口关闭需要消耗很多时间,
												**所以为了让用户感觉关闭的很快,就先隐藏,具体的释放等费时的工作交给后面做
												*/
												layer_switch(layer, -1);
												keywindow_off(key_to_window);
												key_to_window = layer_manage->layers_order[layer_manage->top - 1];
												keywindow_on(key_to_window);
												io_cli();
												fifo_put(&task->fifo, 4);
												io_sti();
											}
										}
										break;
									}
								}
							}
						}
						//只要last_mcursorX大于0,说明当前处于窗口移动模式,说明当前鼠标正点击着某个图层的标题栏呢
						else
						{
							x = mCursorX - last_mcursorX;
							y = mCursorY - last_mcursorY;
							new_layerX = (tmp_layerX + x + 2) & ~3;
							new_layerY = new_layerY + y;
							last_mcursorY = mCursorY;			//更新到移动后的坐标
						}
					}
					//如果当前没有按下左键,就把last_mcursorX设置为负数,作为当前不处于窗口移动的依据
					else
					{
						last_mcursorX = -1;
						if(0x7fffffff != new_layerX)
						{
							layer_slide(layer, new_layerX, new_layerY);		//一旦鼠标不点击这窗口移动了,就立即最后一次绘制窗口并且停止窗口的移动
							new_layerX = 0x7fffffff; 
						}
					}
					
				}
			}
			//收到这个之间的数据,说明是让关闭console的
			else if(768 <= i && i <= 1023)
			{
				close_console(layer_manage->layers + (i - 768));
			}
			//关闭命令行的任务
			else if(1024 <= i && i <= 2023)
			{
				close_console_task(taskctl->tasks + (i - 1024));
			}
			//关闭命令行窗口(释放它的图层)
			else if(2024 <= i && i <= 2279)			//图层最多只有256个,加上偏移量之后就是这个范围了
			{
				layer_to_free = layer_manage->layers + (i - 2024);
				memmanage_free_4K(memmanage, (int) layer_to_free->buffer, 256 * 265);
				layer_free(layer_to_free);
			}
		}
	}	
}
Exemple #25
0
int main(int argc, char **argv)
{
  u8 r;
  char filename[255] = "misc/hosts_temp";
  struct addr address;

  if (argc > 1)
  {
    if (strcmp("append", argv[1]) == 0 || strcmp("search", argv[1]) == 0)
    {
      if (argc < 3)
      {
        printf("Unknown address\n");
        return 1;
      }

      r = sscanf(argv[2], "%hhu.%hhu.%hhu.%hhu", &address.chunk.a, &address.chunk.b, &address.chunk.c, &address.chunk.d);
      if (r != 4)
      {
        printf("Ivalid address %u.%u.%u.%u\n", (u32) address.chunk.a, (u32) address.chunk.b, (u32) address.chunk.c, (u32) address.chunk.d);
        return 1;
      }

      r = file_search(filename, address);

      if (strcmp("append", argv[1]) == 0)
      {
        if (r == 1)
        {
          printf("Address %u.%u.%u.%u exists\n", address.chunk.a, address.chunk.b, address.chunk.c, address.chunk.d);
//          return 1;
        }

        r = file_append(filename, address);
        printf("%s address %u.%u.%u.%u!\n", r == 0 ? "Not added" : "Added", address.chunk.a, address.chunk.b, address.chunk.c, address.chunk.d);
      }
      else
      {
        printf("%s address %u.%u.%u.%u!\n", r == 0 ? "Not found" : "Found", address.chunk.a, address.chunk.b, address.chunk.c, address.chunk.d);
      }
    }
    else if (strcmp("print", argv[1]) == 0)
    {
      u32 i;
      struct peers *tmp = file_fetch(filename);

      for (i = 0; i < tmp->cnt; ++i)
        printf("%u.%u.%u.%u\n", tmp->itms[i].chunk.a, tmp->itms[i].chunk.b, tmp->itms[i].chunk.c, tmp->itms[i].chunk.d);

      printf("Found %u hosts\n", tmp->cnt);

      free(tmp);
    }
    else if (strcmp("clean", argv[1]) == 0)
    {
      file_clean(filename);
      printf("Cleaned\n");
    }
    else
      printf("Unknown command\n");
  }

  return 0;
}
Exemple #26
0
/* do_search()
 * Description: Perform a lookup of the specified search string in all Clear manifests
 * for the current os release.
 */
void do_search(struct manifest *MoM, char search_type, char *search_term)
{
	struct list *list;
	struct list *sublist;
	struct file *file;
	struct file *subfile;
	struct manifest *subman = NULL;
	int i, ret;
	bool done_with_bundle, done = false;
	bool hit = false;

	list = MoM->manifests;
	while (list && !done) {
		file = list->data;
		list = list->next;
		done_with_bundle = false;

		/* Load sub-manifest */
		ret = load_manifests(file->last_change, file->last_change, file->filename, NULL, &subman);
		if (ret != 0) {
			printf("Failed to load manifest %s\n", file->filename);
			continue;
		}

		if (display_files) {
			/* Display bundle name. Marked up for pattern matchability */
			printf("--Bundle: %s--\n", file->filename);
		}

		/* Loop through sub-manifest, searching for files matching the desired pattern */
		sublist = subman->files;
		while (sublist && !done_with_bundle) {
			subfile = sublist->data;
			sublist = sublist->next;

			if (!subfile->is_file) {
				continue;
			}

			if (display_files) {
				/* Just display filename */
				file_search(subfile->filename, NULL, NULL);
			} else if (search_type == 'e') {
				/* Search for exact match, not path addition */
				if (file_search(subfile->filename, "", search_term)) {
					report_find(file->filename, subfile->filename);
					hit = true;
					if (!display_all) {
						done = true;
					}

					done_with_bundle = true;
					break;
				}
			} else if (search_type == 'l') {
				/* Check each supported library path for a match */
				for (i = 0; lib_paths[i] != NULL; i++) {
					if (file_search(subfile->filename, lib_paths[i], search_term)) {
						report_find(file->filename, subfile->filename);
						hit = true;
						if (!display_all) {
							done = true;
						}

						done_with_bundle = true;
						break;
					}
				}
			} else if (search_type == 'b') {
				/* Check each supported path for binaries */
				for (i = 0; bin_paths[i] != NULL; i++) {
					if (file_search(subfile->filename, bin_paths[i], search_term)) {
						report_find(file->filename, subfile->filename);
						hit = true;
						if (!display_all) {
							done = true;
						}

						done_with_bundle = true;
						break;
					}
				}
			} else {
				printf("Unrecognized search type. -b or -l supported\n");
				done = true;
				break;
			}
		}

		free_manifest(subman);
	}

	if (!hit) {
		printf("Search term not found.\n");
	}
}
Exemple #27
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, appsiz;
	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) {
		/* ������ �߰ߵǾ��� ��� */
		appsiz = finfo->size;
		p = file_loadfile2(finfo->clustno, &appsiz, fat);
		if (appsiz >= 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, appsiz - 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));
			strcpy(task->name, "console");
			shtctl = (struct SHTCTL *) *((int *) 0x0fe4);
			for (i = 0; i < MAX_SHEETS; i++) {
				sht = &(shtctl->sheets0[i]);
				if ((sht->flags & 0x11) == 0x11 && sht->task == task) {
					/* ���ø����̼� open & ���̾� �߰� */
					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);
			task->langbyte1 = 0;
		} else {
			cons_putstr0(cons, ".hrb file format error.\n");
		}
		memman_free_4k(memman, (int) p, appsiz);
		cons_newline(cons);
		return 1;
	}
	/* ������ �߰ߵ��� �ʾ��� ��� */
	return 0;
}