mirror of
https://github.com/yourtion/30dayMakeOS.git
synced 2026-02-04 18:43:25 +08:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0a166bc8c2 | ||
|
|
2982ab2699 | ||
|
|
c4f1c13129 | ||
|
|
a1142b3a5f | ||
|
|
792c8b7082 | ||
|
|
9e1c17b4d1 | ||
|
|
b50c16d8e0 |
@@ -1,4 +1,4 @@
|
||||
/* bootpackのメイン */
|
||||
/* bootpack*/
|
||||
|
||||
#include "bootpack.h"
|
||||
#include <stdio.h>
|
||||
@@ -8,7 +8,9 @@ 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, 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;
|
||||
@@ -20,13 +22,25 @@ 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);
|
||||
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);
|
||||
memtotal = memtest(0x00400000, 0xbfffffff);
|
||||
@@ -38,9 +52,9 @@ void HariMain(void)
|
||||
shtctl = shtctl_init(memman, binfo->vram, binfo->scrnx, binfo->scrny);
|
||||
sht_back = sheet_alloc(shtctl);
|
||||
sht_mouse = sheet_alloc(shtctl);
|
||||
sht_win = sheet_alloc(shtctl);
|
||||
sht_win = sheet_alloc(shtctl);
|
||||
buf_back = (unsigned char *) memman_alloc_4k(memman, binfo->scrnx * binfo->scrny);
|
||||
buf_win = (unsigned char *) memman_alloc_4k(memman, 160 * 52);
|
||||
buf_win = (unsigned char *) memman_alloc_4k(memman, 160 * 52);
|
||||
sheet_setbuf(sht_back, buf_back, binfo->scrnx, binfo->scrny, -1); /* 没有透明色 */
|
||||
sheet_setbuf(sht_mouse, buf_mouse, 16, 16, 99); /* 透明色号99 */
|
||||
sheet_setbuf(sht_win, buf_win, 160, 52, -1); /* 没有透明色 */
|
||||
@@ -51,13 +65,14 @@ void HariMain(void)
|
||||
mx = (binfo->scrnx - 16) / 2; /* 按显示在画面中央来计算坐标 */
|
||||
my = (binfo->scrny - 28 - 16) / 2;
|
||||
sheet_slide(sht_mouse, mx, my);
|
||||
sheet_slide(sht_win, 80, 72);
|
||||
sheet_slide(sht_win, 80, 72);
|
||||
sheet_updown(sht_back, 0);
|
||||
sheet_updown(sht_win, 1);
|
||||
sheet_updown(sht_win, 1);
|
||||
sheet_updown(sht_mouse, 2);
|
||||
sprintf(s, "(%3d, %3d)", mx, my);
|
||||
putfonts8_asc(buf_back, binfo->scrnx, 0, 0, COL8_FFFFFF, s);
|
||||
sprintf(s, "memory %dMB free : %dKB", memtotal / (1024 * 1024), memman_total(memman) / 1024);
|
||||
sprintf(s, "memory %dMB free : %dKB",
|
||||
memtotal / (1024 * 1024), memman_total(memman) / 1024);
|
||||
putfonts8_asc(buf_back, binfo->scrnx, 0, 32, COL8_FFFFFF, s);
|
||||
sheet_refresh(sht_back, 0, 0, binfo->scrnx, 48); /* 刷新文字 */
|
||||
|
||||
@@ -68,7 +83,8 @@ 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)
|
||||
+ fifo8_status(&timerfifo2) + fifo8_status(&timerfifo3) == 0) {
|
||||
io_sti(); /* 不做HLT */
|
||||
} else {
|
||||
if (fifo8_status(&keyfifo) != 0) {
|
||||
@@ -117,6 +133,28 @@ 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);
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -140,21 +178,19 @@ void make_window8(unsigned char *buf, int xsize, int ysize, char *title)
|
||||
"O$$$$$$$$$$$$$$@",
|
||||
"@@@@@@@@@@@@@@@@"
|
||||
};
|
||||
|
||||
int x, y;
|
||||
char c;
|
||||
boxfill8(buf, xsize, COL8_C6C6C6, 0, 0, xsize - 1, 0 );
|
||||
boxfill8(buf, xsize, COL8_FFFFFF, 1, 1, xsize - 2, 1 );
|
||||
boxfill8(buf, xsize, COL8_C6C6C6, 0, 0, 0, ysize - 1);
|
||||
boxfill8(buf, xsize, COL8_FFFFFF, 1, 1, 1, ysize - 2);
|
||||
boxfill8(buf, xsize, COL8_848484, xsize - 2, 1, xsize - 2, ysize - 2);
|
||||
boxfill8(buf, xsize, COL8_000000, xsize - 1, 0, xsize - 1, ysize - 1);
|
||||
boxfill8(buf, xsize, COL8_C6C6C6, 2, 2, xsize - 3, ysize - 3);
|
||||
boxfill8(buf, xsize, COL8_000084, 3, 3, xsize - 4, 20 );
|
||||
boxfill8(buf, xsize, COL8_848484, 1, ysize - 2, xsize - 2, ysize - 2);
|
||||
boxfill8(buf, xsize, COL8_000000, 0, ysize - 1, xsize - 1, ysize - 1);
|
||||
boxfill8(buf, xsize, COL8_C6C6C6, 0, 0, xsize - 1, 0 );
|
||||
boxfill8(buf, xsize, COL8_FFFFFF, 1, 1, xsize - 2, 1 );
|
||||
boxfill8(buf, xsize, COL8_C6C6C6, 0, 0, 0, ysize - 1);
|
||||
boxfill8(buf, xsize, COL8_FFFFFF, 1, 1, 1, ysize - 2);
|
||||
boxfill8(buf, xsize, COL8_848484, xsize - 2, 1, xsize - 2, ysize - 2);
|
||||
boxfill8(buf, xsize, COL8_000000, xsize - 1, 0, xsize - 1, ysize - 1);
|
||||
boxfill8(buf, xsize, COL8_C6C6C6, 2, 2, xsize - 3, ysize - 3);
|
||||
boxfill8(buf, xsize, COL8_000084, 3, 3, xsize - 4, 20 );
|
||||
boxfill8(buf, xsize, COL8_848484, 1, ysize - 2, xsize - 2, ysize - 2);
|
||||
boxfill8(buf, xsize, COL8_000000, 0, ysize - 1, xsize - 1, ysize - 1);
|
||||
putfonts8_asc(buf, xsize, 24, 4, COL8_FFFFFF, title);
|
||||
|
||||
for (y = 0; y < 14; y++) {
|
||||
for (x = 0; x < 16; x++) {
|
||||
c = closebtn[y][x];
|
||||
|
||||
@@ -169,10 +169,23 @@ void sheet_slide(struct SHEET *sht, int vx0, int vy0);
|
||||
void sheet_free(struct SHEET *sht);
|
||||
|
||||
/* timer.c */
|
||||
#define MAX_TIMER 500
|
||||
struct TIMER {
|
||||
unsigned int timeout, flags;
|
||||
struct FIFO8 *fifo;
|
||||
unsigned char data;
|
||||
};
|
||||
struct TIMERCTL {
|
||||
unsigned int count;
|
||||
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);
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/*初始化关系 */
|
||||
|
||||
#include "bootpack.h"
|
||||
#include <stdio.h>
|
||||
|
||||
void init_pic(void)
|
||||
/* PIC初始化 */
|
||||
@@ -24,8 +25,6 @@ void init_pic(void)
|
||||
return;
|
||||
}
|
||||
|
||||
#define PORT_KEYDAT 0x0060
|
||||
|
||||
void inthandler27(int *esp)
|
||||
/* PIC0中断的不完整策略 */
|
||||
/* 这个中断在Athlon64X2上通过芯片组提供的便利,只需执行一次 */
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/* 内存管理 */
|
||||
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>W */
|
||||
|
||||
#include "bootpack.h"
|
||||
|
||||
#define EFLAGS_AC_BIT 0x00040000
|
||||
#define EFLAGS_AC_BIT 0x00040000
|
||||
#define CR0_CACHE_DISABLE 0x60000000
|
||||
|
||||
unsigned int memtest(unsigned int start, unsigned int end)
|
||||
unsigned int memtest(unsigned int start, unsigned int end)
|
||||
{
|
||||
char flg486 = 0;
|
||||
unsigned int eflg, cr0, i;
|
||||
@@ -40,7 +40,8 @@ unsigned int memtest(unsigned int start, unsigned int end)
|
||||
return i;
|
||||
}
|
||||
|
||||
void memman_init(struct MEMMAN *man){
|
||||
void memman_init(struct MEMMAN *man)
|
||||
{
|
||||
man->frees = 0; /* 可用信息数目 */
|
||||
man->maxfrees = 0; /* 用于观察可用状况:frees的最大值 */
|
||||
man->lostsize = 0; /* 释放失败的内存的大小总和 */
|
||||
|
||||
@@ -4,7 +4,8 @@
|
||||
|
||||
struct FIFO8 mousefifo;
|
||||
|
||||
void inthandler2c(int *esp) {
|
||||
void inthandler2c(int *esp)
|
||||
{
|
||||
/* 来自PS/2鼠标的中断 */
|
||||
unsigned char data;
|
||||
io_out8(PIC1_OCW2, 0x64); /* 通知PIC IRQ-12 已经受理完毕 */
|
||||
@@ -17,7 +18,8 @@ void inthandler2c(int *esp) {
|
||||
#define KEYCMD_SENDTO_MOUSE 0xd4
|
||||
#define MOUSECMD_ENABLE 0xf4
|
||||
|
||||
void enable_mouse(struct MOUSE_DEC *mdec) {
|
||||
void enable_mouse(struct MOUSE_DEC *mdec)
|
||||
{
|
||||
/* 鼠标有效 */
|
||||
wait_KBC_sendready();
|
||||
io_out8(PORT_KEYCMD, KEYCMD_SENDTO_MOUSE);
|
||||
@@ -28,7 +30,8 @@ void enable_mouse(struct MOUSE_DEC *mdec) {
|
||||
return;
|
||||
}
|
||||
|
||||
int mouse_decode(struct MOUSE_DEC *mdec, unsigned char dat) {
|
||||
int mouse_decode(struct MOUSE_DEC *mdec, unsigned char dat)
|
||||
{
|
||||
if (mdec->phase == 0) {
|
||||
/* 等待鼠标的0xfa的阶段 */
|
||||
if (dat == 0xfa) {
|
||||
|
||||
151
12_day/sheet.c
151
12_day/sheet.c
@@ -53,6 +53,78 @@ void sheet_setbuf(struct SHEET *sht, unsigned char *buf, int xsize, int ysize, i
|
||||
return;
|
||||
}
|
||||
|
||||
void sheet_refreshmap(struct SHTCTL *ctl, int vx0, int vy0, int vx1, int vy1, int h0)
|
||||
{
|
||||
int h, bx, by, vx, vy, bx0, by0, bx1, by1;
|
||||
unsigned char *buf, sid, *map = ctl->map;
|
||||
struct SHEET *sht;
|
||||
if (vx0 < 0) { vx0 = 0; }
|
||||
if (vy0 < 0) { vy0 = 0; }
|
||||
if (vx1 > ctl->xsize) { vx1 = ctl->xsize; }
|
||||
if (vy1 > ctl->ysize) { vy1 = ctl->ysize; }
|
||||
for (h = h0; h <= ctl->top; h++) {
|
||||
sht = ctl->sheets[h];
|
||||
sid = sht - ctl->sheets0; /* 将进行了减法计算的地址作为图层号码使用 */
|
||||
buf = sht->buf;
|
||||
bx0 = vx0 - sht->vx0;
|
||||
by0 = vy0 - sht->vy0;
|
||||
bx1 = vx1 - sht->vx0;
|
||||
by1 = vy1 - sht->vy0;
|
||||
if (bx0 < 0) { bx0 = 0; }
|
||||
if (by0 < 0) { by0 = 0; }
|
||||
if (bx1 > sht->bxsize) { bx1 = sht->bxsize; }
|
||||
if (by1 > sht->bysize) { by1 = sht->bysize; }
|
||||
for (by = by0; by < by1; by++) {
|
||||
vy = sht->vy0 + by;
|
||||
for (bx = bx0; bx < bx1; bx++) {
|
||||
vx = sht->vx0 + bx;
|
||||
if (buf[by * sht->bxsize + bx] != sht->col_inv) {
|
||||
map[vy * ctl->xsize + vx] = sid;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void sheet_refreshsub(struct SHTCTL *ctl, int vx0, int vy0, int vx1, int vy1, int h0, int h1)
|
||||
{
|
||||
int h, bx, by, vx, vy, bx0, by0, bx1, by1;
|
||||
unsigned char *buf, *vram = ctl->vram, *map = ctl->map, sid;
|
||||
struct SHEET *sht;
|
||||
|
||||
/* 如果refresh的范围超出了画面则修正 */
|
||||
if (vx0 < 0) { vx0 = 0; }
|
||||
if (vy0 < 0) { vy0 = 0; }
|
||||
if (vx1 > ctl->xsize) { vx1 = ctl->xsize; }
|
||||
if (vy1 > ctl->ysize) { vy1 = ctl->ysize; }
|
||||
for (h = h0; h <= h1; h++) {
|
||||
sht = ctl->sheets[h];
|
||||
buf = sht->buf;
|
||||
sid = sht - ctl->sheets0;
|
||||
|
||||
/* 使用vx0~vy1,对bx0~by1进行倒推 */
|
||||
bx0 = vx0 - sht->vx0;
|
||||
by0 = vy0 - sht->vy0;
|
||||
bx1 = vx1 - sht->vx0;
|
||||
by1 = vy1 - sht->vy0;
|
||||
if (bx0 < 0) { bx0 = 0; } /* 处理刷新范围在图层外侧 */
|
||||
if (by0 < 0) { by0 = 0; }
|
||||
if (bx1 > sht->bxsize) { bx1 = sht->bxsize; } /* 应对不同的重叠方式 */
|
||||
if (by1 > sht->bysize) { by1 = sht->bysize; }
|
||||
for (by = by0; by < by1; by++) {
|
||||
vy = sht->vy0 + by;
|
||||
for (bx = bx0; bx < bx1; bx++) {
|
||||
vx = sht->vx0 + bx;
|
||||
if (map[vy * ctl->xsize + vx] == sid) {
|
||||
vram[vy * ctl->xsize + vx] = buf[by * sht->bxsize + bx];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void sheet_updown(struct SHEET *sht, int height)
|
||||
{
|
||||
struct SHTCTL *ctl = sht->ctl;
|
||||
@@ -86,7 +158,7 @@ void sheet_updown(struct SHEET *sht, int height)
|
||||
}
|
||||
ctl->top--; /* 由于显示中的图层减少了一个,所以最上面的图层高度下降 */
|
||||
sheet_refreshmap(ctl, sht->vx0, sht->vy0, sht->vx0 + sht->bxsize, sht->vy0 + sht->bysize, 0);
|
||||
sheet_refreshsub(ctl, sht->vx0, sht->vy0, sht->vx0 + sht->bxsize, sht->vy0 + sht->bysize, 0, old - 1);
|
||||
sheet_refreshsub(ctl, sht->vx0, sht->vy0, sht->vx0 + sht->bxsize, sht->vy0 + sht->bysize, 0, old - 1);
|
||||
}
|
||||
} else if (old < height) { /* 比以前高 */
|
||||
if (old >= 0) {
|
||||
@@ -119,83 +191,6 @@ void sheet_refresh(struct SHEET *sht, int bx0, int by0, int bx1, int by1)
|
||||
return;
|
||||
}
|
||||
|
||||
void sheet_refreshsub(struct SHTCTL *ctl, int vx0, int vy0, int vx1, int vy1, int h0, int h1)
|
||||
{
|
||||
int h, bx, by, vx, vy, bx0, by0, bx1, by1;
|
||||
unsigned char *buf, *vram = ctl->vram, *map = ctl->map, sid;
|
||||
struct SHEET *sht;
|
||||
|
||||
/* 如果refresh的范围超出了画面则修正 */
|
||||
if (vx0 < 0) { vx0 = 0; }
|
||||
if (vy0 < 0) { vy0 = 0; }
|
||||
if (vx1 > ctl->xsize) { vx1 = ctl->xsize; }
|
||||
if (vy1 > ctl->ysize) { vy1 = ctl->ysize; }
|
||||
|
||||
for (h = h0; h <= ctl->top; h++) {
|
||||
sht = ctl->sheets[h];
|
||||
buf = sht->buf;
|
||||
sid = sht -ctl->sheets0;
|
||||
|
||||
/* 使用vx0~vy1,对bx0~by1进行倒推 */
|
||||
bx0 = vx0 - sht->vx0;
|
||||
by0 = vy0 - sht->vy0;
|
||||
bx1 = vx1 - sht->vx0;
|
||||
by1 = vy1 - sht->vy0;
|
||||
if (bx0 < 0) { bx0 = 0; } /* 处理刷新范围在图层外侧 */
|
||||
if (by0 < 0) { by0 = 0; }
|
||||
if (bx1 > sht->bxsize) { bx1 = sht->bxsize; } /* 应对不同的重叠方式 */
|
||||
if (by1 > sht->bysize) { by1 = sht->bysize; }
|
||||
|
||||
for (by = by0; by < by1; by++) {
|
||||
vy = sht->vy0 + by;
|
||||
for (bx = bx0; bx < bx1; bx++) {
|
||||
vx = sht->vx0 + bx;
|
||||
if (map[vy * ctl->xsize + vx] == sid) {
|
||||
vram[vy * ctl->xsize + vx] = buf[by * sht->bxsize + bx];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void sheet_refreshmap(struct SHTCTL *ctl, int vx0, int vy0, int vx1, int vy1, int h0)
|
||||
{
|
||||
int h, bx, by, vx, vy, bx0, by0, bx1, by1;
|
||||
unsigned char *buf, sid, *map = ctl->map;
|
||||
struct SHEET *sht;
|
||||
|
||||
if (vx0 < 0) { vx0 = 0; }
|
||||
if (vy0 < 0) { vy0 = 0; }
|
||||
if (vx1 > ctl->xsize) { vx1 = ctl->xsize; }
|
||||
if (vy1 > ctl->ysize) { vy1 = ctl->ysize; }
|
||||
|
||||
for (h = h0; h <= ctl->top; h++) {
|
||||
sht = ctl->sheets[h];
|
||||
sid = sht - ctl->sheets0; /* 将进行了减法计算的地址作为图层号码使用 */
|
||||
buf = sht->buf;
|
||||
bx0 = vx0 - sht->vx0;
|
||||
by0 = vy0 - sht->vy0;
|
||||
bx1 = vx1 - sht->vx0;
|
||||
by1 = vy1 - sht->vy0;
|
||||
if (bx0 < 0) { bx0 = 0; }
|
||||
if (by0 < 0) { by0 = 0; }
|
||||
if (bx1 > sht->bxsize) { bx1 = sht->bxsize; }
|
||||
if (by1 > sht->bysize) { by1 = sht->bysize; }
|
||||
|
||||
for (by = by0; by < by1; by++) {
|
||||
vy = sht->vy0 + by;
|
||||
for (bx = bx0; bx < bx1; bx++) {
|
||||
vx = sht->vx0 + bx;
|
||||
if (buf[by * sht->bxsize + bx] != sht->col_inv) {
|
||||
map[vy * ctl->xsize + vx] = sid;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void sheet_slide(struct SHEET *sht, int vx0, int vy0)
|
||||
{
|
||||
struct SHTCTL *ctl = sht->ctl;
|
||||
|
||||
@@ -2,23 +2,106 @@
|
||||
|
||||
#include "bootpack.h"
|
||||
|
||||
#define PIT_CTRL 0x0043
|
||||
#define PIT_CNT0 0x0040
|
||||
#define PIT_CTRL 0x0043
|
||||
#define PIT_CNT0 0x0040
|
||||
|
||||
struct TIMERCTL timerctl;
|
||||
|
||||
#define TIMER_FLAGS_ALLOC 1 /* 已配置状态 */
|
||||
#define TIMER_FLAGS_USING 2 /* 定时器运行中 */
|
||||
|
||||
void init_pit(void)
|
||||
{
|
||||
io_out8(PIT_CTRL, 0x43);
|
||||
int i;
|
||||
io_out8(PIT_CTRL, 0x34);
|
||||
io_out8(PIT_CNT0, 0x9c);
|
||||
io_out8(PIT_CNT0, 0x2e);
|
||||
timerctl.count = 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.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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user