/*

		スタートメニュー表示用
		
		3/31 作成

*/
#include "bootpack.h"

/* スタートメニュー描写用のタスクを準備 */
struct SHEET *open_startmenu_task(struct SHTCTL *shtctl)
{
	const int window_h = 220, window_w = 200;
	struct SHEET *sht = sheet_alloc(shtctl);
	struct MEMMAN *memman = (struct MEMMAN *)MEMMAN_ADDR;
	unsigned char *buf = (unsigned char *)memman_alloc_4k(memman, window_w * window_h);
	struct TASK *task = task_alloc();
	sht->flags |= SHEET_STARTMENU_FLAGS;
	sheet_setbuf(sht, buf, window_w, window_h, -1);
	make_startmenu(sht, "NegitoroOS Version0.0.6");
	task->ds_base = memman_alloc_4k(memman, 64 * 1024);
	task->tss.esp = task->ds_base + 64 * 1024;
	task->tss.eip = (int)&startmenu_task;
	task->tss.es = 1 * 8;
	task->tss.cs = 2 * 8;
	task->tss.ss = 1 * 8;
	task->tss.ds = 1 * 8;
	task->tss.fs = 1 * 8;
	task->tss.gs = 1 * 8;
	task_run(task, 4, 2, "smenu");	/* ここの優先度は具合に応じて変更 */
	sht->task = task;
	return sht;
}

/* スタートメニュー描写用タスクの終了 */
void close_startmenu_task(struct TASK *task, struct SHEET *sht, unsigned long mem)
{
	struct MEMMAN *memman = (struct MEMMAN *)MEMMAN_ADDR;
	memman_free_4k(memman, task->ds_base, 64 * 1024);
	task_sleep(sht->task);
	sht->task->flags = 0;
	memman_free_4k(memman, (int)sht->buf, mem);
	sheet_free(sht);
	return;
}

/* スタートメニューを描写 */
void make_startmenu(struct SHEET *sht, char *caption)
{
	/* フレームを表示 */
	boxfill8(sht->buf, sht->bxsize, COL8_000000, 0, 0, sht->bxsize, sht->bysize);
	boxfill8(sht->buf, sht->bxsize, COL8_C6C6C6, 2, 2, sht->bxsize - 3, sht->bysize - 3);
	
	/* 上の方の名前 */
	boxfill8(sht->buf, sht->bxsize, COL8_FFFFFF, 4, 4, sht->bxsize - 5, 25);
	putfonts8_asc(sht->buf, sht->bxsize, 8, 8, COL8_C6C6C6, caption);	
	putfonts8_asc(sht->buf, sht->bxsize, 5, 5, COL8_000000, caption);
	
	/* メニュー項目 */
	putfonts8_asc(sht->buf, sht->bxsize, 5, 35, COL8_000000, "Negitoro Shell");
	putfonts8_asc(sht->buf, sht->bxsize, 5, 60, COL8_000000, "Negitoro Maneger");
	putfonts8_asc(sht->buf, sht->bxsize, 5, 85, COL8_000000, "System Info");
	putfonts8_asc(sht->buf, sht->bxsize, 5, 110, COL8_000000, "Invader");
	putfonts8_asc(sht->buf, sht->bxsize, 5, 135, COL8_000000, "Simple Timer");
	putfonts8_asc(sht->buf, sht->bxsize, 5, 160, COL8_000000, "Simple Editer");
	boxfill8(sht->buf, sht->bxsize, COL8_848484, 5, 185, sht->bxsize - 10, 185);
	putfonts8_asc(sht->buf, sht->bxsize, 5, 195, COL8_000000, "Shutdown by APM");
	
	return;
}

/* スタートメニュー用タスク */
void startmenu_task(void)
{
	for (;;) {
		io_hlt();
	}
	return;
}

