Make your own OS in 30 days – day17/18: Idle task and console

Day16’s task_a was sleeping until interrupted, and other task_b0,b1,b2 were running. If we don’t have bx tasks, it needs a different logic.
It introduces an idle task to keep the design simple by always having a task than the main task_a.

void task_idle(void)
{
	for (;;) {
		io_hlt();
	}
}

To allow all tasks to get keyboard input, the task manager defines FIFO queue per task. Then added a console which accepts ‘mem’, ‘cls’ and ‘dir’ commands.
‘dir’ checks 8.3 file name and size.

struct FILEINFO *finfo = (struct FILEINFO *) (ADR_DISKIMG + 0x002600);

if (strcmp(cmdline, "mem") == 0) {
	sprintf(s, "total   %dMB", memtotal / (1024 * 1024));
	putfonts8_asc_sht(sheet, 8, cursor_y, COL8_FFFFFF, COL8_000000, s, 30);
	cursor_y = cons_newline(cursor_y, sheet);
	sprintf(s, "free %dKB", memman_total(memman) / 1024);
	putfonts8_asc_sht(sheet, 8, cursor_y, COL8_FFFFFF, COL8_000000, s, 30);
	cursor_y = cons_newline(cursor_y, sheet);
	cursor_y = cons_newline(cursor_y, sheet);
} else if (strcmp(cmdline, "cls") == 0) {
	for (y = 28; y < 28 + 128; y++) {
		for (x = 8; x < 8 + 240; x++) {
			sheet->buf[x + y * sheet->bxsize] = COL8_000000;
		}
	}
	sheet_refresh(sheet, 8, 28, 8 + 240, 28 + 128);
	cursor_y = 28;
} else if (strcmp(cmdline, "dir") == 0) {
	for (x = 0; x < 224; x++) {
		if (finfo[x].name[0] == 0x00) {
			break;
		}
		if (finfo[x].name[0] != 0xe5) {
			if ((finfo[x].type & 0x18) == 0) {
				sprintf(s, "filename.ext   %7d", finfo[x].size);
				for (y = 0; y < 8; y++) {
					s[y] = finfo[x].name[y];
				}
				s[ 9] = finfo[x].ext[0];
				s[10] = finfo[x].ext[1];
				s[11] = finfo[x].ext[2];
				putfonts8_asc_sht(sheet, 8, cursor_y, COL8_FFFFFF, COL8_000000, s, 30);
				cursor_y = cons_newline(cursor_y, sheet);
			}
		}
	}
	cursor_y = cons_newline(cursor_y, sheet);
}

day17_18

Leave a Reply

Your email address will not be published. Required fields are marked *