mirror of
https://github.com/yourtion/30dayMakeOS.git
synced 2026-02-03 01:53:24 +08:00
超时功能
This commit is contained in:
@@ -8,7 +8,8 @@ void make_window8(unsigned char *buf, int xsize, int ysize, char *title);
|
||||
void HariMain(void)
|
||||
{
|
||||
struct BOOTINFO *binfo = (struct BOOTINFO *) ADR_BOOTINFO;
|
||||
char s[40], keybuf[32], mousebuf[128];
|
||||
struct FIFO8 timerfifo;
|
||||
char s[40], keybuf[32], mousebuf[128], timerbuf[8];
|
||||
int mx, my, i;
|
||||
unsigned int memtotal;
|
||||
struct MOUSE_DEC mdec;
|
||||
@@ -20,13 +21,16 @@ void HariMain(void)
|
||||
init_gdtidt();
|
||||
init_pic();
|
||||
io_sti(); /* IDT/PIC的初始化已经完成,于是开放CPU的中断 */
|
||||
|
||||
fifo8_init(&keyfifo, 32, keybuf);
|
||||
fifo8_init(&mousefifo, 128, mousebuf);
|
||||
init_pit();
|
||||
io_out8(PIC0_IMR, 0xf8); /* PIT和PIC1和键盘设置为许可(11111000) */
|
||||
io_out8(PIC1_IMR, 0xef); /* 开放鼠标中断(11101111) */
|
||||
|
||||
fifo8_init(&timerfifo, 8, timerbuf);
|
||||
settimer(1000, &timerfifo, 1);
|
||||
|
||||
|
||||
init_keyboard();
|
||||
enable_mouse(&mdec);
|
||||
memtotal = memtest(0x00400000, 0xbfffffff);
|
||||
@@ -68,7 +72,7 @@ void HariMain(void)
|
||||
sheet_refresh(sht_win, 40, 28, 120, 44); /* 到这里结束 */
|
||||
|
||||
io_cli();
|
||||
if (fifo8_status(&keyfifo) + fifo8_status(&mousefifo) == 0) {
|
||||
if (fifo8_status(&keyfifo) + fifo8_status(&mousefifo) + fifo8_status(&timerfifo) == 0) {
|
||||
io_sti(); /* 不做HLT */
|
||||
} else {
|
||||
if (fifo8_status(&keyfifo) != 0) {
|
||||
@@ -117,6 +121,11 @@ void HariMain(void)
|
||||
sheet_refresh(sht_back, 0, 0, 80, 16); /* 刷新文字 */
|
||||
sheet_slide(sht_mouse, mx, my); /* 包含sheet_refresh含sheet_refresh */
|
||||
}
|
||||
} else if (fifo8_status(&timerfifo) != 0) {
|
||||
i = fifo8_get(&timerfifo); /* 首先读入(为了设定起始点) */
|
||||
io_sti();
|
||||
putfonts8_asc(buf_back, binfo->scrnx, 0, 64, COL8_FFFFFF, "10[sec]");
|
||||
sheet_refresh(sht_back, 0, 64, 56, 80);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,8 +171,12 @@ void sheet_free(struct SHEET *sht);
|
||||
/* timer.c */
|
||||
struct TIMERCTL {
|
||||
unsigned int count;
|
||||
unsigned int timeout;
|
||||
struct FIFO8 *fifo;
|
||||
unsigned char data;
|
||||
};
|
||||
extern struct TIMERCTL timerctl;
|
||||
|
||||
void init_pit(void);
|
||||
void inthandler20(int *esp);
|
||||
void settimer(unsigned int timeout, struct FIFO8 *fifo, unsigned char data);
|
||||
|
||||
@@ -9,10 +9,11 @@ struct TIMERCTL timerctl;
|
||||
|
||||
void init_pit(void)
|
||||
{
|
||||
io_out8(PIT_CTRL, 0x43);
|
||||
io_out8(PIT_CTRL, 0x34);
|
||||
io_out8(PIT_CNT0, 0x9c);
|
||||
io_out8(PIT_CNT0, 0x2e);
|
||||
timerctl.count = 0;
|
||||
timerctl.timeout = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -20,5 +21,23 @@ void inthandler20(int *esp)
|
||||
{
|
||||
io_out8(PIC0_OCW2, 0x60); /* 把IRQ-00信号接收完了的信息通知给PIC */
|
||||
timerctl.count++;
|
||||
if (timerctl.timeout > 0) { /* 如果已经设定了超时 */
|
||||
timerctl.timeout--;
|
||||
if (timerctl.timeout == 0) {
|
||||
fifo8_put(timerctl.fifo, timerctl.data);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void settimer(unsigned int timeout, struct FIFO8 *fifo, unsigned char data)
|
||||
{
|
||||
int eflags;
|
||||
eflags = io_load_eflags();
|
||||
io_cli();
|
||||
timerctl.timeout = timeout;
|
||||
timerctl.fifo = fifo;
|
||||
timerctl.data = data;
|
||||
io_store_eflags(eflags);
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user