Skip to content

Commit

Permalink
Multiple consoles
Browse files Browse the repository at this point in the history
  • Loading branch information
komukomo committed Dec 31, 2016
1 parent 04903dd commit 63383bb
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 59 deletions.
84 changes: 44 additions & 40 deletions bootpack.c
Expand Up @@ -16,9 +16,9 @@ void Main(void) {
unsigned int memtotal;
struct MOUSE_DEC mdec;
struct MEMMAN *memman = (struct MEMMAN *)MEMMAN_ADDR;
unsigned char *buf_back, buf_mouse[256], *buf_win, *buf_cons;
struct SHEET *sht_back, *sht_mouse, *sht_win, *sht_cons;
struct TASK *task_a, *task_cons;
unsigned char *buf_back, buf_mouse[256], *buf_win, *buf_cons[2];
struct SHEET *sht_back, *sht_mouse, *sht_win, *sht_cons[2];
struct TASK *task_a, *task_cons[2], *task;
struct TIMER *timer;
static char keytable0[0x80] = {
0, 0, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-',
Expand All @@ -43,7 +43,6 @@ void Main(void) {
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;
struct CONSOLE *cons;
int j, x, y, mmx = -1, mmy = -1;
struct SHEET *sht = 0, *key_win;

Expand Down Expand Up @@ -79,23 +78,27 @@ void Main(void) {
init_screen8(buf_back, binfo->scrnx, binfo->scrny);

/* sht_cons */
sht_cons = sheet_alloc(shtctl);
buf_cons = (unsigned char *)memman_alloc_4k(memman, 256 * 165);
sheet_setbuf(sht_cons, buf_cons, 256, 165, -1); /* 透明色なし */
make_window8(buf_cons, 256, 165, "console", 0);
make_textbox8(sht_cons, 8, 28, 240, 128, COL8_000000);
task_cons = task_alloc();
task_cons->tss.esp = memman_alloc_4k(memman, 64 * 1024) + 64 * 1024 - 12;
task_cons->tss.eip = (int)&console_task;
task_cons->tss.es = 1 * 8;
task_cons->tss.cs = 2 * 8;
task_cons->tss.ss = 1 * 8;
task_cons->tss.ds = 1 * 8;
task_cons->tss.fs = 1 * 8;
task_cons->tss.gs = 1 * 8;
*((int *)(task_cons->tss.esp + 4)) = (int)sht_cons;
*((int *)(task_cons->tss.esp + 8)) = memtotal;
task_run(task_cons, 2, 2); /* level=2, priority=2 */
for (i = 0; i < 2; i++) {
sht_cons[i] = sheet_alloc(shtctl);
buf_cons[i] = (unsigned char *)memman_alloc_4k(memman, 256 * 165);
sheet_setbuf(sht_cons[i], buf_cons[i], 256, 165, -1); /* 透明色なし */
make_window8(buf_cons[i], 256, 165, "console", 0);
make_textbox8(sht_cons[i], 8, 28, 240, 128, COL8_000000);
task_cons[i] = task_alloc();
task_cons[i]->tss.esp = memman_alloc_4k(memman, 64 * 1024) + 64 * 1024 - 12;
task_cons[i]->tss.eip = (int)&console_task;
task_cons[i]->tss.es = 1 * 8;
task_cons[i]->tss.cs = 2 * 8;
task_cons[i]->tss.ss = 1 * 8;
task_cons[i]->tss.ds = 1 * 8;
task_cons[i]->tss.fs = 1 * 8;
task_cons[i]->tss.gs = 1 * 8;
*((int *)(task_cons[i]->tss.esp + 4)) = (int)sht_cons[i];
*((int *)(task_cons[i]->tss.esp + 8)) = memtotal;
task_run(task_cons[i], 2, 2); /* level=2, priority=2 */
sht_cons[i]->task = task_cons[i];
sht_cons[i]->flags |= 0x20; /* カーソルあり */
}

/* sht_win */
sht_win = sheet_alloc(shtctl);
Expand All @@ -117,16 +120,16 @@ void Main(void) {
my = (binfo->scrny - 28 - 16) / 2;

sheet_slide(sht_back, 0, 0);
sheet_slide(sht_cons, 32, 4);
sheet_slide(sht_cons[1], 56, 6);
sheet_slide(sht_cons[0], 8, 2);
sheet_slide(sht_win, 64, 56);
sheet_slide(sht_mouse, mx, my);
sheet_updown(sht_back, 0);
sheet_updown(sht_cons, 1);
sheet_updown(sht_win, 2);
sheet_updown(sht_mouse, 3);
sheet_updown(sht_cons[1], 1);
sheet_updown(sht_cons[0], 2);
sheet_updown(sht_win, 3);
sheet_updown(sht_mouse, 4);
key_win = sht_win;
sht_cons->task = task_cons;
sht_cons->flags |= 0x20; /* カーソルあり */

/* 最初にキーボード状態との食い違いがないように、設定しておくことにする */
fifo32_put(&keycmd, KEYCMD_LED);
Expand Down Expand Up @@ -232,16 +235,17 @@ void Main(void) {
fifo32_put(&keycmd, KEYCMD_LED);
fifo32_put(&keycmd, key_leds);
}
if (i == 256 + 0x3b && key_shift != 0 &&
task_cons->tss.ss0 != 0) { /* Shift+F1 */
cons = (struct CONSOLE *)*((int *)0x0fec);
cons_putstr0(cons, "\nBreak(key) :\n");
io_cli(); /* 強制終了処理中にタスクが変わると困るから */
task_cons->tss.eax = (int)&(task_cons->tss.esp0);
task_cons->tss.eip = (int)asm_end_app;
io_sti();
if (i == 256 + 0x3b && key_shift != 0) {
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();
}
}
if (i == 256 + 0x57 && shtctl->top > 2) { /* F11 */
if (i == 256 + 0x57) { /* F11 */
sheet_updown(shtctl->sheets[1], shtctl->top - 1);
}
if (i == 256 + 0xfa) { /* キーボードがデータを無事に受け取った */
Expand Down Expand Up @@ -302,11 +306,11 @@ void Main(void) {
/* 「×」ボタンクリック */
if ((sht->flags & 0x10) !=
0) { /* アプリが作ったウィンドウか? */
cons = (struct CONSOLE *)*((int *)0x0fec);
cons_putstr0(cons, "\nBreak(mouse) :\n");
task = sht->task;
cons_putstr0(task->cons, "\nBreak(mouse) :\n");
io_cli(); /* 強制終了処理中にタスクが変わると困るから */
task_cons->tss.eax = (int)&(task_cons->tss.esp0);
task_cons->tss.eip = (int)asm_end_app;
task->tss.eax = (int)&(task->tss.esp0);
task->tss.eip = (int)asm_end_app;
io_sti();
}
}
Expand Down
10 changes: 5 additions & 5 deletions bootpack.h
Expand Up @@ -226,6 +226,8 @@ struct TASK {
int level, priority;
struct FIFO32 fifo;
struct TSS32 tss;
struct CONSOLE *cons;
int ds_base;
};
struct TASKLEVEL {
int running; /* 動作しているタスクの数 */
Expand Down Expand Up @@ -261,18 +263,16 @@ struct CONSOLE {
int cur_x, cur_y, cur_c;
struct TIMER *timer;
};
void console_task(struct SHEET *sheet, unsigned int memtotal);
void console_task(struct SHEET *sheet, int memtotal);
void cons_putchar(struct CONSOLE *cons, int chr, char move);
void cons_newline(struct CONSOLE *cons);
void cons_putstr0(struct CONSOLE *cons, char *s);
void cons_putstr1(struct CONSOLE *cons, char *s, int l);
void cons_runcmd(char *cmdline, struct CONSOLE *cons, int *fat,
unsigned int memtotal);
void cmd_mem(struct CONSOLE *cons, unsigned int memtotal);
void cons_runcmd(char *cmdline, struct CONSOLE *cons, int *fat, int memtotal);
void cmd_mem(struct CONSOLE *cons, int memtotal);
void cmd_cls(struct CONSOLE *cons);
void cmd_dir(struct CONSOLE *cons);
void cmd_type(struct CONSOLE *cons, int *fat, char *cmdline);
void cmd_hlt(struct CONSOLE *cons, int *fat);
int cmd_app(struct CONSOLE *cons, int *fat, char *cmdline);
int *hrb_api(int edi, int esi, int ebp, int esp, int ebx, int edx, int ecx,
int eax);
Expand Down
28 changes: 15 additions & 13 deletions console.c
@@ -1,6 +1,6 @@
#include "bootpack.h"

void console_task(struct SHEET *sheet, unsigned int memtotal) {
void console_task(struct SHEET *sheet, int memtotal) {
struct TASK *task = task_now();
struct MEMMAN *memman = (struct MEMMAN *)MEMMAN_ADDR;
int i, fifobuf[128], *fat = (int *)memman_alloc_4k(memman, 4 * 2880);
Expand All @@ -10,7 +10,7 @@ void console_task(struct SHEET *sheet, unsigned int memtotal) {
cons.cur_x = 8;
cons.cur_y = 28;
cons.cur_c = -1;
*((int *)0x0fec) = (int)&cons;
task->cons = &cons;

fifo32_init(&task->fifo, 128, fifobuf, task);
cons.timer = timer_alloc();
Expand Down Expand Up @@ -161,8 +161,7 @@ void cons_putstr1(struct CONSOLE *cons, char *s, int l) {
return;
}

void cons_runcmd(char *cmdline, struct CONSOLE *cons, int *fat,
unsigned int memtotal) {
void cons_runcmd(char *cmdline, struct CONSOLE *cons, int *fat, int memtotal) {
if (mystrcmp(cmdline, "mem") == 0) {
cmd_mem(cons, memtotal);
} else if (mystrcmp(cmdline, "cls") == 0) {
Expand All @@ -180,7 +179,7 @@ void cons_runcmd(char *cmdline, struct CONSOLE *cons, int *fat,
return;
}

void cmd_mem(struct CONSOLE *cons, unsigned int memtotal) {
void cmd_mem(struct CONSOLE *cons, int memtotal) {
struct MEMMAN *memman = (struct MEMMAN *)MEMMAN_ADDR;
char s[60];
mysprintf(s, "total %dMB\nfree %dKB\n\n", memtotal / (1024 * 1024),
Expand Down Expand Up @@ -289,13 +288,16 @@ int cmd_app(struct CONSOLE *cons, int *fat, char *cmdline) {
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);
task->ds_base = (int)q;
set_segmdesc(gdt + task->sel / 8 + 1000, finfo->size - 1, (int)p,
AR_CODE32_ER + 0x60);
set_segmdesc(gdt + task->sel / 8 + 2000, 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));
start_app(0x1b, task->sel + 1000 * 8, esp, task->sel + 2000 * 8,
&(task->tss.esp0));
shtctl = (struct SHTCTL *)*((int *)0x0fe4);
for (i = 0; i < MAX_SHEETS; i++) {
sht = &(shtctl->sheets0[i]);
Expand All @@ -319,9 +321,9 @@ int cmd_app(struct CONSOLE *cons, int *fat, char *cmdline) {

int *hrb_api(int edi, int esi, int ebp, int esp, int ebx, int edx, int ecx,
int eax) {
int ds_base = *((int *)0xfe8);
struct TASK *task = task_now();
struct CONSOLE *cons = (struct CONSOLE *)*((int *)0x0fec);
int ds_base = task->ds_base;
struct CONSOLE *cons = task->cons;
struct SHTCTL *shtctl = (struct SHTCTL *)*((int *)0x0fe4);
struct SHEET *sht;
int *reg = &eax + 1; /* eaxの次の番地 */
Expand Down Expand Up @@ -444,8 +446,8 @@ int *hrb_api(int edi, int esi, int ebp, int esp, int ebx, int edx, int ecx,
}

int *inthandler0c(int *esp) {
struct CONSOLE *cons = (struct CONSOLE *)*((int *)0x0fec);
struct TASK *task = task_now();
struct CONSOLE *cons = task->cons;
char s[30];
cons_putstr0(cons, "\nINT 0C :\n Stack Exception.\n");
mysprintf(s, "EIP = %08X\n", esp[11]);
Expand All @@ -454,8 +456,8 @@ int *inthandler0c(int *esp) {
}

int *inthandler0d(int *esp) {
struct CONSOLE *cons = (struct CONSOLE *)*((int *)0x0fec);
struct TASK *task = task_now();
struct CONSOLE *cons = task->cons;
char s[30];
cons_putstr0(cons, "\nINT 0D :\n General Protected Exception.\n");
mysprintf(s, "EIP = %08X\n", esp[11]);
Expand Down
2 changes: 1 addition & 1 deletion file.c
Expand Up @@ -54,7 +54,7 @@ struct FILEINFO *file_search(char *name, struct FILEINFO *finfo, int max) {
}
}
for (i = 0; i < max;) {
if (finfo[i].name[0] == 0x00) {
if (finfo->name[0] == 0x00) {
break;
}
if ((finfo[i].type & 0x18) == 0) {
Expand Down

0 comments on commit 63383bb

Please sign in to comment.