Compare commits

...

2 Commits

Author SHA1 Message Date
Yourtion
b50c16d8e0 超时功能 2016-04-18 14:06:26 +08:00
Yourtion
3aea776876 计量时间 2016-04-18 11:42:17 +08:00
3 changed files with 48 additions and 8 deletions

View File

@@ -8,9 +8,10 @@ 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, count = 0;
unsigned int memtotal;
struct MOUSE_DEC mdec;
struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR;
struct SHTCTL *shtctl;
@@ -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);
@@ -62,14 +66,13 @@ void HariMain(void)
sheet_refresh(sht_back, 0, 0, binfo->scrnx, 48); /* 刷新文字 */
for (;;) {
count++; /* 从这里开始 */
sprintf(s, "%010d", count);
sprintf(s, "%010d", timerctl.count);
boxfill8(buf_win, 160, COL8_C6C6C6, 40, 28, 119, 43);
putfonts8_asc(buf_win, 160, 40, 28, COL8_000000, s);
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) {
@@ -118,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);
}
}
}

View File

@@ -169,5 +169,14 @@ void sheet_slide(struct SHEET *sht, int vx0, int vy0);
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);

View File

@@ -5,16 +5,39 @@
#define PIT_CTRL 0x0043
#define PIT_CNT0 0x0040
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;
}
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;
}