mirror of
https://github.com/yourtion/30dayMakeOS.git
synced 2026-02-05 02:53:19 +08:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c4f1c13129 | ||
|
|
a1142b3a5f | ||
|
|
792c8b7082 | ||
|
|
9e1c17b4d1 |
@@ -8,8 +8,9 @@ void make_window8(unsigned char *buf, int xsize, int ysize, char *title);
|
||||
void HariMain(void)
|
||||
{
|
||||
struct BOOTINFO *binfo = (struct BOOTINFO *) ADR_BOOTINFO;
|
||||
struct FIFO8 timerfifo;
|
||||
char s[40], keybuf[32], mousebuf[128], timerbuf[8];
|
||||
struct FIFO8 timerfifo, timerfifo2, timerfifo3;
|
||||
char s[40], keybuf[32], mousebuf[128], timerbuf[8], timerbuf2[8], timerbuf3[8];
|
||||
struct TIMER *timer, *timer2, *timer3;
|
||||
int mx, my, i;
|
||||
unsigned int memtotal;
|
||||
struct MOUSE_DEC mdec;
|
||||
@@ -28,8 +29,17 @@ void HariMain(void)
|
||||
io_out8(PIC1_IMR, 0xef); /* 开放鼠标中断(11101111) */
|
||||
|
||||
fifo8_init(&timerfifo, 8, timerbuf);
|
||||
settimer(1000, &timerfifo, 1);
|
||||
|
||||
timer = timer_alloc();
|
||||
timer_init(timer, &timerfifo, 1);
|
||||
timer_settime(timer, 1000);
|
||||
fifo8_init(&timerfifo2, 8, timerbuf2);
|
||||
timer2 = timer_alloc();
|
||||
timer_init(timer2, &timerfifo2, 1);
|
||||
timer_settime(timer2, 300);
|
||||
fifo8_init(&timerfifo3, 8, timerbuf3);
|
||||
timer3 = timer_alloc();
|
||||
timer_init(timer3, &timerfifo3, 1);
|
||||
timer_settime(timer3, 50);
|
||||
|
||||
init_keyboard();
|
||||
enable_mouse(&mdec);
|
||||
@@ -72,7 +82,7 @@ void HariMain(void)
|
||||
sheet_refresh(sht_win, 40, 28, 120, 44); /* 到这里结束 */
|
||||
|
||||
io_cli();
|
||||
if (fifo8_status(&keyfifo) + fifo8_status(&mousefifo) + fifo8_status(&timerfifo) == 0) {
|
||||
if (fifo8_status(&keyfifo) + fifo8_status(&mousefifo) + fifo8_status(&timerfifo) + fifo8_status(&timerfifo2) + fifo8_status(&timerfifo3)== 0) {
|
||||
io_sti(); /* 不做HLT */
|
||||
} else {
|
||||
if (fifo8_status(&keyfifo) != 0) {
|
||||
@@ -126,6 +136,23 @@ void HariMain(void)
|
||||
io_sti();
|
||||
putfonts8_asc(buf_back, binfo->scrnx, 0, 64, COL8_FFFFFF, "10[sec]");
|
||||
sheet_refresh(sht_back, 0, 64, 56, 80);
|
||||
} else if (fifo8_status(&timerfifo2) != 0) {
|
||||
i = fifo8_get(&timerfifo2); /* 首先读入(为了设定起始点) */
|
||||
io_sti();
|
||||
putfonts8_asc(buf_back, binfo->scrnx, 0, 80, COL8_FFFFFF, "3[sec]");
|
||||
sheet_refresh(sht_back, 0, 80, 48, 96);
|
||||
} else if (fifo8_status(&timerfifo3) != 0) {
|
||||
i = fifo8_get(&timerfifo3); /* 首先读入(为了设定起始点) */
|
||||
io_sti();
|
||||
if (i != 0) {
|
||||
timer_init(timer3, &timerfifo3, 0); /* 然后设置0 */
|
||||
boxfill8(buf_back, binfo->scrnx, COL8_FFFFFF, 8, 96, 15, 111);
|
||||
} else {
|
||||
timer_init(timer3, &timerfifo3, 1); /* 然后设置1 */
|
||||
boxfill8(buf_back, binfo->scrnx, COL8_008484, 8, 96, 15, 111);
|
||||
}
|
||||
timer_settime(timer3, 50);
|
||||
sheet_refresh(sht_back, 8, 96, 16, 112);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,14 +169,23 @@ 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;
|
||||
#define MAX_TIMER 500
|
||||
struct TIMER {
|
||||
unsigned int timeout, flags;
|
||||
struct FIFO8 *fifo;
|
||||
unsigned char data;
|
||||
};
|
||||
struct TIMERCTL {
|
||||
unsigned int count, next, using;
|
||||
struct TIMER *timers[MAX_TIMER];
|
||||
struct TIMER timers0[MAX_TIMER];
|
||||
};
|
||||
extern struct TIMERCTL timerctl;
|
||||
|
||||
void init_pit(void);
|
||||
struct TIMER *timer_alloc(void);
|
||||
void timer_free(struct TIMER *timer);
|
||||
void timer_init(struct TIMER *timer, struct FIFO8 *fifo, unsigned char data);
|
||||
void timer_settime(struct TIMER *timer, unsigned int timeout);
|
||||
void inthandler20(int *esp);
|
||||
void settimer(unsigned int timeout, struct FIFO8 *fifo, unsigned char data);
|
||||
|
||||
|
||||
@@ -4,40 +4,103 @@
|
||||
|
||||
#define PIT_CTRL 0x0043
|
||||
#define PIT_CNT0 0x0040
|
||||
#define TIMER_FLAGS_ALLOC 1 /* 已配置状态 */
|
||||
#define TIMER_FLAGS_USING 2 /* 定时器运行中 */
|
||||
|
||||
struct TIMERCTL timerctl;
|
||||
|
||||
void init_pit(void)
|
||||
{
|
||||
int i;
|
||||
io_out8(PIT_CTRL, 0x34);
|
||||
io_out8(PIT_CNT0, 0x9c);
|
||||
io_out8(PIT_CNT0, 0x2e);
|
||||
timerctl.count = 0;
|
||||
timerctl.timeout = 0;
|
||||
timerctl.next = 0xffffffff; /* 因为最初没有正在运行的定时器 */
|
||||
timerctl.using = 0;
|
||||
for (i = 0; i < MAX_TIMER; i++) {
|
||||
timerctl.timers0[i].flags = 0; /* 未使用 */
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
struct TIMER *timer_alloc(void)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < MAX_TIMER; i++) {
|
||||
if (timerctl.timers0[i].flags == 0) {
|
||||
timerctl.timers0[i].flags = TIMER_FLAGS_ALLOC;
|
||||
return &timerctl.timers0[i];
|
||||
}
|
||||
}
|
||||
return 0; /* 没找到 */
|
||||
}
|
||||
|
||||
void timer_free(struct TIMER *timer)
|
||||
{
|
||||
timer->flags = 0; /* 未使用 */
|
||||
return;
|
||||
}
|
||||
|
||||
void timer_init(struct TIMER *timer, struct FIFO8 *fifo, unsigned char data)
|
||||
{
|
||||
timer->fifo = fifo;
|
||||
timer->data = data;
|
||||
return;
|
||||
}
|
||||
|
||||
void timer_settime(struct TIMER *timer, unsigned int timeout)
|
||||
{
|
||||
int e, i, j;
|
||||
timer->timeout = timeout + timerctl.count;
|
||||
timer->flags = TIMER_FLAGS_USING;
|
||||
e = io_load_eflags();
|
||||
io_cli();
|
||||
/* 搜索注册位置 */
|
||||
for (i = 0; i < timerctl.using; i++) {
|
||||
if (timerctl.timers[i]->timeout >= timer->timeout) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* i号之后全部后移一位 */
|
||||
for (j = timerctl.using; j > i; j--) {
|
||||
timerctl.timers[j] = timerctl.timers[j - 1];
|
||||
}
|
||||
timerctl.using++;
|
||||
/* 插入到空位上 */
|
||||
timerctl.timers[i] = timer;
|
||||
timerctl.next = timerctl.timers[0]->timeout;
|
||||
io_store_eflags(e);
|
||||
return;
|
||||
}
|
||||
|
||||
void inthandler20(int *esp)
|
||||
{
|
||||
int i, j;
|
||||
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);
|
||||
if (timerctl.next > timerctl.count) {
|
||||
return; /* 还不到下一个时刻,所以结束*/
|
||||
}
|
||||
timerctl.next = 0xffffffff;
|
||||
for (i = 0; i < timerctl.using; i++) {
|
||||
/* timers的定时器都处于动作中,所以不确认flags */
|
||||
if (timerctl.timers[i]->timeout > timerctl.count) {
|
||||
break;
|
||||
}
|
||||
/* 超时*/
|
||||
timerctl.timers[i]->flags = TIMER_FLAGS_ALLOC;
|
||||
fifo8_put(timerctl.timers[i]->fifo, timerctl.timers[i]->data);
|
||||
}
|
||||
/* 正好有i个定时器超时了。其余的进行移位。 */
|
||||
timerctl.using -= i;
|
||||
for (j = 0; j < timerctl.using; j++) {
|
||||
timerctl.timers[j] = timerctl.timers[i + j];
|
||||
}
|
||||
if (timerctl.using > 0) {
|
||||
timerctl.next = timerctl.timers[0]->timeout;
|
||||
} else {
|
||||
timerctl.next = 0xffffffff;
|
||||
}
|
||||
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