Compare commits

..

4 Commits

Author SHA1 Message Date
Yourtion
efb6028e00 取消定时器 2016-05-11 15:32:26 +08:00
Yourtion
9475d3d828 定时器API 2016-05-11 15:24:10 +08:00
Yourtion
b27c562b98 用鼠标切换输入窗口 2016-05-11 14:57:20 +08:00
Yourtion
bde8ac972b 将输入切换到应用程序窗口 2016-05-11 14:49:22 +08:00
8 changed files with 243 additions and 29 deletions

View File

@@ -148,10 +148,17 @@ walk.bim : walk.obj a_nask.obj Makefile
walk.hrb : walk.bim Makefile
$(BIM2HRB) walk.bim walk.hrb 48k
noodle.bim : noodle.obj a_nask.obj Makefile
$(OBJ2BIM) @$(RULEFILE) out:noodle.bim stack:1k map:noodle.map \
noodle.obj a_nask.obj
noodle.hrb : noodle.bim Makefile
$(BIM2HRB) noodle.bim noodle.hrb 40k
haribote.img : ipl10.bin haribote.sys Makefile \
hello.hrb hello2.hrb a.hrb hello3.hrb hello4.hrb hello5.hrb \
winhelo.hrb winhelo2.hrb winhelo3.hrb star1.hrb stars.hrb stars2.hrb \
lines.hrb walk.hrb
lines.hrb walk.hrb noodle.hrb
$(EDIMG) imgin:../z_tools/fdimg0at.tek \
wbinimg src:ipl10.bin len:512 from:0 to:0 \
copy from:haribote.sys to:@: \
@@ -171,6 +178,7 @@ haribote.img : ipl10.bin haribote.sys Makefile \
copy from:stars2.hrb to:@: \
copy from:lines.hrb to:@: \
copy from:walk.hrb to:@: \
copy from:noodle.hrb to:@: \
imgout:haribote.img
# 其他指令

View File

@@ -17,6 +17,10 @@
GLOBAL _api_linewin
GLOBAL _api_closewin
GLOBAL _api_getkey
GLOBAL _api_alloctimer
GLOBAL _api_inittimer
GLOBAL _api_settimer
GLOBAL _api_freetimer
[SECTION .text]
@@ -186,3 +190,34 @@ _api_getkey: ; int api_getkey(int mode);
MOV EAX,[ESP+4] ; mode
INT 0x40
RET
_api_alloctimer: ; int api_alloctimer(void);
MOV EDX,16
INT 0x40
RET
_api_inittimer: ; void api_inittimer(int timer, int data);
PUSH EBX
MOV EDX,17
MOV EBX,[ESP+ 8] ; timer
MOV EAX,[ESP+12] ; data
INT 0x40
POP EBX
RET
_api_settimer: ; void api_settimer(int timer, int time);
PUSH EBX
MOV EDX,18
MOV EBX,[ESP+ 8] ; timer
MOV EAX,[ESP+12] ; time
INT 0x40
POP EBX
RET
_api_freetimer: ; void api_freetimer(int timer);
PUSH EBX
MOV EDX,19
MOV EBX,[ESP+ 8] ; timer
INT 0x40
POP EBX
RET

View File

@@ -5,6 +5,9 @@
#define KEYCMD_LED 0xed
int keywin_off(struct SHEET *key_win, struct SHEET *sht_win, int cur_c, int cur_x);
int keywin_on(struct SHEET *key_win, struct SHEET *sht_win, int cur_c);
void HariMain(void)
{
struct BOOTINFO *binfo = (struct BOOTINFO *) ADR_BOOTINFO;
@@ -40,10 +43,10 @@ void HariMain(void)
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_to = 0, key_shift = 0, key_leds = (binfo->leds >> 4) & 7, keycmd_wait = -1;
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;
struct SHEET *sht = 0, *key_win;
init_gdtidt();
init_pic();
@@ -120,6 +123,9 @@ void HariMain(void)
sheet_updown(sht_cons, 1);
sheet_updown(sht_win, 2);
sheet_updown(sht_mouse, 3);
key_win = sht_win;
sht_cons->task = task_cons;
sht_cons->flags |= 0x20; /*有光标*/
/*为了避免和键盘当前状态冲突,在一开始先进行设置*/
fifo32_put(&keycmd, KEYCMD_LED);
@@ -139,6 +145,10 @@ void HariMain(void)
} else {
i = fifo32_get(&fifo);
io_sti();
if (key_win->flags == 0) { /*输入窗口被关闭*/
key_win = shtctl->sheets[shtctl->top - 1];
cursor_c = keywin_on(key_win, sht_win, cursor_c);
}
if (256 <= i && i <= 511) { /* 键盘数据*/
if (i < 0x80 + 256) { /*将按键编码转换为字符编码*/
if (key_shift == 0) {
@@ -155,7 +165,7 @@ void HariMain(void)
}
}
if (s[0] != 0) { /*一般字符*/
if (key_to == 0) { /*发送给任务A */
if (key_win == sht_win) { /*发送给任务A */
if (cursor_x < 128) {
/*显示一个字符之后将光标后移一位*/
s[1] = 0;
@@ -163,42 +173,33 @@ void HariMain(void)
cursor_x += 8;
}
} else { /*发送给命令行窗口*/
fifo32_put(&task_cons->fifo, s[0] + 256);
fifo32_put(&key_win->task->fifo, s[0] + 256);
}
}
if (i == 256 + 0x0e) { /* 退格键 */
if (key_to == 0) { /*发送给任务A */
if (key_win == sht_win) { /*发送给任务A */
if (cursor_x > 8) {
/*用空白擦除光标后将光标前移一位*/
putfonts8_asc_sht(sht_win, cursor_x, 28, COL8_000000, COL8_FFFFFF, " ", 1);
cursor_x -= 8;
}
} else { /*发送给命令行窗口*/
fifo32_put(&task_cons->fifo, 8 + 256);
fifo32_put(&key_win->task->fifo, 8 + 256);
}
}
if (i == 256 + 0x1c) { /*回车键*/
if (key_to != 0) { /*发送至命令行窗口*/
fifo32_put(&task_cons->fifo, 10 + 256);
if (key_win != sht_win) { /*发送至命令行窗口*/
fifo32_put(&key_win->task->fifo, 10 + 256);
}
}
if (i == 256 + 0x0f) { /* Tab */
if (key_to == 0) {
key_to = 1;
make_wtitle8(buf_win, sht_win->bxsize, "task_a", 0);
make_wtitle8(buf_cons, sht_cons->bxsize, "console", 1);
cursor_c = -1; /* 不显示光标 */
boxfill8(sht_win->buf, sht_win->bxsize, COL8_FFFFFF, cursor_x, 28, cursor_x + 7, 43);
fifo32_put(&task_cons->fifo, 2); /*命令行窗口光标ON */
} else {
key_to = 0;
make_wtitle8(buf_win, sht_win->bxsize, "task_a", 1);
make_wtitle8(buf_cons, sht_cons->bxsize, "console", 0);
cursor_c = COL8_000000;
fifo32_put(&task_cons->fifo, 3); /*命令行窗口光标OFF */
if (i == 256 + 0x0f) { /* Tab */
cursor_c = keywin_off(key_win, sht_win, cursor_c, cursor_x);
j = key_win->height - 1;
if (j == 0) {
j = shtctl->top - 1;
}
sheet_refresh(sht_win, 0, 0, sht_win->bxsize, 21);
sheet_refresh(sht_cons, 0, 0, sht_cons->bxsize, 21);
key_win = shtctl->sheets[j];
cursor_c = keywin_on(key_win, sht_win, cursor_c);
}
if (i == 256 + 0x2a) { /*左Shift ON */
key_shift |= 1;
@@ -281,13 +282,18 @@ void HariMain(void)
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) {
cursor_c = keywin_off(key_win, sht_win, cursor_c, cursor_x);
key_win = sht;
cursor_c = keywin_on(key_win, sht_win, cursor_c);/*到此结束*/
}
if (3 <= x && x < sht->bxsize - 3 && 3 <= y && y < 21) {
mmx = mx; /*进入窗口移动模式*/
mmy = my;
}
if (sht->bxsize - 21 <= x && x < sht->bxsize - 5 && 5 <=y && y < 19) {
/*点击“×”按钮*/
if (sht->task != 0) { /*该窗口是否为应用程序窗口?*/
if ((sht->flags & 0x10) != 0) { /*该窗口是否为应用程序窗口?*/
cons = (struct CONSOLE *) *((int *) 0x0fec);
cons_putstr0(cons, "\nBreak(mouse) :\n");
io_cli(); /*强制结束处理中禁止切换任务*/
@@ -336,3 +342,30 @@ void HariMain(void)
}
}
}
int keywin_off(struct SHEET *key_win, struct SHEET *sht_win, int cur_c, int cur_x)
{
change_wtitle8(key_win, 0);
if (key_win == sht_win) {
cur_c = -1; /*删除光标*/
boxfill8(sht_win->buf, sht_win->bxsize, COL8_FFFFFF, cur_x, 28, cur_x + 7, 43);
} else {
if ((key_win->flags & 0x20) != 0) {
fifo32_put(&key_win->task->fifo, 3); /*命令行窗口光标OFF */
}
}
return cur_c;
}
int keywin_on(struct SHEET *key_win, struct SHEET *sht_win, int cur_c)
{
change_wtitle8(key_win, 1);
if (key_win == sht_win) {
cur_c = COL8_000000; /*显示光标*/
} else {
if ((key_win->flags & 0x20) != 0) {
fifo32_put(&key_win->task->fifo, 2); /*命令行窗口光标ON */
}
}
return cur_c;
}

View File

@@ -176,7 +176,8 @@ void sheet_free(struct SHEET *sht);
#define MAX_TIMER 500
struct TIMER {
struct TIMER *next;
unsigned int timeout, flags;
unsigned int timeout;
char flags, flags2;
struct FIFO32 *fifo;
int data;
};
@@ -192,6 +193,8 @@ void timer_free(struct TIMER *timer);
void timer_init(struct TIMER *timer, struct FIFO32 *fifo, int data);
void timer_settime(struct TIMER *timer, unsigned int timeout);
void inthandler20(int *esp);
int timer_cancel(struct TIMER *timer);
void timer_cancelall(struct FIFO32 *fifo);
/* mtask.c */
#define MAX_TASKS 1000 /*最大任务数量*/
@@ -233,6 +236,7 @@ void make_window8(unsigned char *buf, int xsize, int ysize, char *title, char ac
void putfonts8_asc_sht(struct SHEET *sht, int x, int y, int c, int b, char *s, int l);
void make_textbox8(struct SHEET *sht, int x0, int y0, int sx, int sy, int c);
void make_wtitle8(unsigned char *buf, int xsize, char *title, char act);
void change_wtitle8(struct SHEET *sht, char act);
/* console.c */
struct CONSOLE {

View File

@@ -303,11 +303,12 @@ int cmd_app(struct CONSOLE *cons, int *fat, char *cmdline)
shtctl = (struct SHTCTL *) *((int *) 0x0fe4);
for (i = 0; i < MAX_SHEETS; i++) {
sht = &(shtctl->sheets0[i]);
if (sht->flags != 0 && sht->task == task) {
if ((sht->flags & 0x11) == 0x11 && sht->task == task) {
/*找到被应用程序遗留的窗口*/
sheet_free(sht); /*关闭*/
}
}
timer_cancelall(&task->fifo);
memman_free_4k(memman, (int) q, segsiz);
} else {
cons_putstr0(cons, ".hrb file format error.\n");
@@ -344,6 +345,7 @@ int *hrb_api(int edi, int esi, int ebp, int esp, int ebx, int edx, int ecx, int
} else if (edx == 5) {
sht = sheet_alloc(shtctl);
sht->task = task;
sht->flags |= 0x10;
sheet_setbuf(sht, (char *) ebx + ds_base, esi, edi, eax);
make_window8((char *) ebx + ds_base, esi, edi, (char *) ecx + ds_base, 0);
sheet_slide(sht, 100, 50);
@@ -413,11 +415,20 @@ int *hrb_api(int edi, int esi, int ebp, int esp, int ebx, int edx, int ecx, int
if (i == 3) { /*光标OFF */
cons->cur_c = -1;
}
if (256 <= i && i <= 511) { /*键盘数据通过任务A*/
if (i >= 256) { /*键盘数据通过任务A*/
reg[7] = i - 256;
return 0;
}
}
} else if (edx == 16) {
reg[7] = (int) timer_alloc();
((struct TIMER *) reg[7])->flags2 = 1; /*允许自动取消*/
} else if (edx == 17) {
timer_init((struct TIMER *) ebx, &task->fifo, eax + 256);
} else if (edx == 18) {
timer_settime((struct TIMER *) ebx, eax);
} else if (edx == 19) {
timer_free((struct TIMER *) ebx);
}
return 0;
}

42
24_day/noodle.c Normal file
View File

@@ -0,0 +1,42 @@
#include <stdio.h>
int api_openwin(char *buf, int xsiz, int ysiz, int col_inv, char *title);
void api_putstrwin(int win, int x, int y, int col, int len, char *str);
void api_boxfilwin(int win, int x0, int y0, int x1, int y1, int col);
void api_initmalloc(void);
char *api_malloc(int size);
int api_getkey(int mode);
int api_alloctimer(void);
void api_inittimer(int timer, int data);
void api_settimer(int timer, int time);
void api_end(void);
void HariMain(void)
{
char *buf, s[12];
int win, timer, sec = 0, min = 0, hou = 0;
api_initmalloc();
buf = api_malloc(150 * 50);
win = api_openwin(buf, 150, 50, -1, "noodle");
timer = api_alloctimer();
api_inittimer(timer, 128);
for (;;) {
sprintf(s, "%5d:%02d:%02d", hou, min, sec);
api_boxfilwin(win, 28, 27, 115, 41, 7);/*白色*/
api_putstrwin(win, 28, 27, 0, 11, s); /*黑色*/
api_settimer(timer, 100); /* 1秒 */
if (api_getkey(1) != 128) {
break;
}
sec++;
if (sec == 60) {
sec = 0;
min++;
if (min == 60) {
min = 0;
hou++;
}
}
}
api_end();
}

View File

@@ -36,6 +36,7 @@ struct TIMER *timer_alloc(void)
for (i = 0; i < MAX_TIMER; i++) {
if (timerctl.timers0[i].flags == 0) {
timerctl.timers0[i].flags = TIMER_FLAGS_ALLOC;
timerctl.timers0[i].flags2 = 0;
return &timerctl.timers0[i];
}
}
@@ -116,3 +117,53 @@ void inthandler20(int *esp)
}
return;
}
int timer_cancel(struct TIMER *timer)
{
int e;
struct TIMER *t;
e = io_load_eflags();
io_cli(); /*在设置过程中禁止改变定时器状态*/
if (timer->flags == TIMER_FLAGS_USING) { /*是否需要取消?*/
if (timer == timerctl.t0) {
/*第一个定时器的取消处理*/
t = timer->next;
timerctl.t0 = t;
timerctl.next = t->timeout;
} else {
/*非第一个定时器的取消处理*/
/*找到timer前一个定时器*/
t = timerctl.t0;
for (;;) {
if (t->next == timer) {
break;
}
t = t->next;
}
t->next = timer->next;
/*将之前“timer的下一个”指向“timer的下一个”*/
}
timer->flags = TIMER_FLAGS_ALLOC;
io_store_eflags(e);
return 1; /*取消处理成功*/
}
io_store_eflags(e);
return 0; /*不需要取消处理*/
}
void timer_cancelall(struct FIFO32 *fifo)
{
int e, i;
struct TIMER *t;
e = io_load_eflags();
io_cli(); /*在设置过程中禁止改变定时器状态*/
for (i = 0; i < MAX_TIMER; i++) {
t = &timerctl.timers0[i];
if (t->flags != 0 && t->flags2 != 0 && t->fifo == fifo) {
timer_cancel(t);
timer_free(t);
}
}
io_store_eflags(e);
return;
}

View File

@@ -86,3 +86,33 @@ void make_textbox8(struct SHEET *sht, int x0, int y0, int sx, int sy, int c)
boxfill8(sht->buf, sht->bxsize, c, x0 - 1, y0 - 1, x1 + 0, y1 + 0);
return;
}
void change_wtitle8(struct SHEET *sht, char act)
{
int x, y, xsize = sht->bxsize;
char c, tc_new, tbc_new, tc_old, tbc_old, *buf = sht->buf;
if (act != 0) {
tc_new = COL8_FFFFFF;
tbc_new = COL8_000084;
tc_old = COL8_C6C6C6;
tbc_old = COL8_848484;
} else {
tc_new = COL8_C6C6C6;
tbc_new = COL8_848484;
tc_old = COL8_FFFFFF;
tbc_old = COL8_000084;
}
for (y = 3; y <= 20; y++) {
for (x = 3; x <= xsize - 4; x++) {
c = buf[y * xsize + x];
if (c == tc_old && x <= xsize - 22) {
c = tc_new;
} else if (c == tbc_old) {
c = tbc_new;
}
buf[y * xsize + x] = c;
}
}
sheet_refresh(sht, 3, 3, xsize, 21);
return;
}