mirror of
https://github.com/yourtion/30dayMakeOS.git
synced 2026-02-11 22:05:06 +08:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0a166bc8c2 | ||
|
|
2982ab2699 | ||
|
|
c4f1c13129 |
@@ -1,4 +1,4 @@
|
|||||||
/* bootpackのメイン */
|
/* bootpack*/
|
||||||
|
|
||||||
#include "bootpack.h"
|
#include "bootpack.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -52,9 +52,9 @@ void HariMain(void)
|
|||||||
shtctl = shtctl_init(memman, binfo->vram, binfo->scrnx, binfo->scrny);
|
shtctl = shtctl_init(memman, binfo->vram, binfo->scrnx, binfo->scrny);
|
||||||
sht_back = sheet_alloc(shtctl);
|
sht_back = sheet_alloc(shtctl);
|
||||||
sht_mouse = 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_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_back, buf_back, binfo->scrnx, binfo->scrny, -1); /* 没有透明色 */
|
||||||
sheet_setbuf(sht_mouse, buf_mouse, 16, 16, 99); /* 透明色号99 */
|
sheet_setbuf(sht_mouse, buf_mouse, 16, 16, 99); /* 透明色号99 */
|
||||||
sheet_setbuf(sht_win, buf_win, 160, 52, -1); /* 没有透明色 */
|
sheet_setbuf(sht_win, buf_win, 160, 52, -1); /* 没有透明色 */
|
||||||
@@ -65,13 +65,14 @@ void HariMain(void)
|
|||||||
mx = (binfo->scrnx - 16) / 2; /* 按显示在画面中央来计算坐标 */
|
mx = (binfo->scrnx - 16) / 2; /* 按显示在画面中央来计算坐标 */
|
||||||
my = (binfo->scrny - 28 - 16) / 2;
|
my = (binfo->scrny - 28 - 16) / 2;
|
||||||
sheet_slide(sht_mouse, mx, my);
|
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_back, 0);
|
||||||
sheet_updown(sht_win, 1);
|
sheet_updown(sht_win, 1);
|
||||||
sheet_updown(sht_mouse, 2);
|
sheet_updown(sht_mouse, 2);
|
||||||
sprintf(s, "(%3d, %3d)", mx, my);
|
sprintf(s, "(%3d, %3d)", mx, my);
|
||||||
putfonts8_asc(buf_back, binfo->scrnx, 0, 0, COL8_FFFFFF, s);
|
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);
|
putfonts8_asc(buf_back, binfo->scrnx, 0, 32, COL8_FFFFFF, s);
|
||||||
sheet_refresh(sht_back, 0, 0, binfo->scrnx, 48); /* 刷新文字 */
|
sheet_refresh(sht_back, 0, 0, binfo->scrnx, 48); /* 刷新文字 */
|
||||||
|
|
||||||
@@ -82,7 +83,8 @@ void HariMain(void)
|
|||||||
sheet_refresh(sht_win, 40, 28, 120, 44); /* 到这里结束 */
|
sheet_refresh(sht_win, 40, 28, 120, 44); /* 到这里结束 */
|
||||||
|
|
||||||
io_cli();
|
io_cli();
|
||||||
if (fifo8_status(&keyfifo) + fifo8_status(&mousefifo) + fifo8_status(&timerfifo) + fifo8_status(&timerfifo2) + fifo8_status(&timerfifo3)== 0) {
|
if (fifo8_status(&keyfifo) + fifo8_status(&mousefifo) + fifo8_status(&timerfifo)
|
||||||
|
+ fifo8_status(&timerfifo2) + fifo8_status(&timerfifo3) == 0) {
|
||||||
io_sti(); /* 不做HLT */
|
io_sti(); /* 不做HLT */
|
||||||
} else {
|
} else {
|
||||||
if (fifo8_status(&keyfifo) != 0) {
|
if (fifo8_status(&keyfifo) != 0) {
|
||||||
@@ -176,21 +178,19 @@ void make_window8(unsigned char *buf, int xsize, int ysize, char *title)
|
|||||||
"O$$$$$$$$$$$$$$@",
|
"O$$$$$$$$$$$$$$@",
|
||||||
"@@@@@@@@@@@@@@@@"
|
"@@@@@@@@@@@@@@@@"
|
||||||
};
|
};
|
||||||
|
|
||||||
int x, y;
|
int x, y;
|
||||||
char c;
|
char c;
|
||||||
boxfill8(buf, xsize, COL8_C6C6C6, 0, 0, xsize - 1, 0 );
|
boxfill8(buf, xsize, COL8_C6C6C6, 0, 0, xsize - 1, 0 );
|
||||||
boxfill8(buf, xsize, COL8_FFFFFF, 1, 1, xsize - 2, 1 );
|
boxfill8(buf, xsize, COL8_FFFFFF, 1, 1, xsize - 2, 1 );
|
||||||
boxfill8(buf, xsize, COL8_C6C6C6, 0, 0, 0, ysize - 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_FFFFFF, 1, 1, 1, ysize - 2);
|
||||||
boxfill8(buf, xsize, COL8_848484, xsize - 2, 1, xsize - 2, 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_000000, xsize - 1, 0, xsize - 1, ysize - 1);
|
||||||
boxfill8(buf, xsize, COL8_C6C6C6, 2, 2, xsize - 3, ysize - 3);
|
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_000084, 3, 3, xsize - 4, 20 );
|
||||||
boxfill8(buf, xsize, COL8_848484, 1, ysize - 2, xsize - 2, ysize - 2);
|
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_000000, 0, ysize - 1, xsize - 1, ysize - 1);
|
||||||
putfonts8_asc(buf, xsize, 24, 4, COL8_FFFFFF, title);
|
putfonts8_asc(buf, xsize, 24, 4, COL8_FFFFFF, title);
|
||||||
|
|
||||||
for (y = 0; y < 14; y++) {
|
for (y = 0; y < 14; y++) {
|
||||||
for (x = 0; x < 16; x++) {
|
for (x = 0; x < 16; x++) {
|
||||||
c = closebtn[y][x];
|
c = closebtn[y][x];
|
||||||
|
|||||||
@@ -176,8 +176,9 @@ struct TIMER {
|
|||||||
unsigned char data;
|
unsigned char data;
|
||||||
};
|
};
|
||||||
struct TIMERCTL {
|
struct TIMERCTL {
|
||||||
unsigned int count, next;
|
unsigned int count, next, using;
|
||||||
struct TIMER timer[MAX_TIMER];
|
struct TIMER *timers[MAX_TIMER];
|
||||||
|
struct TIMER timers0[MAX_TIMER];
|
||||||
};
|
};
|
||||||
extern struct TIMERCTL timerctl;
|
extern struct TIMERCTL timerctl;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
/*初始化关系 */
|
/*初始化关系 */
|
||||||
|
|
||||||
#include "bootpack.h"
|
#include "bootpack.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
void init_pic(void)
|
void init_pic(void)
|
||||||
/* PIC初始化 */
|
/* PIC初始化 */
|
||||||
@@ -24,8 +25,6 @@ void init_pic(void)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define PORT_KEYDAT 0x0060
|
|
||||||
|
|
||||||
void inthandler27(int *esp)
|
void inthandler27(int *esp)
|
||||||
/* PIC0中断的不完整策略 */
|
/* PIC0中断的不完整策略 */
|
||||||
/* 这个中断在Athlon64X2上通过芯片组提供的便利,只需执行一次 */
|
/* 这个中断在Athlon64X2上通过芯片组提供的便利,只需执行一次 */
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
/* 内存管理 */
|
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>W */
|
||||||
|
|
||||||
#include "bootpack.h"
|
#include "bootpack.h"
|
||||||
|
|
||||||
#define EFLAGS_AC_BIT 0x00040000
|
#define EFLAGS_AC_BIT 0x00040000
|
||||||
#define CR0_CACHE_DISABLE 0x60000000
|
#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;
|
char flg486 = 0;
|
||||||
unsigned int eflg, cr0, i;
|
unsigned int eflg, cr0, i;
|
||||||
@@ -40,7 +40,8 @@ unsigned int memtest(unsigned int start, unsigned int end)
|
|||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
void memman_init(struct MEMMAN *man){
|
void memman_init(struct MEMMAN *man)
|
||||||
|
{
|
||||||
man->frees = 0; /* 可用信息数目 */
|
man->frees = 0; /* 可用信息数目 */
|
||||||
man->maxfrees = 0; /* 用于观察可用状况:frees的最大值 */
|
man->maxfrees = 0; /* 用于观察可用状况:frees的最大值 */
|
||||||
man->lostsize = 0; /* 释放失败的内存的大小总和 */
|
man->lostsize = 0; /* 释放失败的内存的大小总和 */
|
||||||
|
|||||||
@@ -4,7 +4,8 @@
|
|||||||
|
|
||||||
struct FIFO8 mousefifo;
|
struct FIFO8 mousefifo;
|
||||||
|
|
||||||
void inthandler2c(int *esp) {
|
void inthandler2c(int *esp)
|
||||||
|
{
|
||||||
/* 来自PS/2鼠标的中断 */
|
/* 来自PS/2鼠标的中断 */
|
||||||
unsigned char data;
|
unsigned char data;
|
||||||
io_out8(PIC1_OCW2, 0x64); /* 通知PIC IRQ-12 已经受理完毕 */
|
io_out8(PIC1_OCW2, 0x64); /* 通知PIC IRQ-12 已经受理完毕 */
|
||||||
@@ -17,7 +18,8 @@ void inthandler2c(int *esp) {
|
|||||||
#define KEYCMD_SENDTO_MOUSE 0xd4
|
#define KEYCMD_SENDTO_MOUSE 0xd4
|
||||||
#define MOUSECMD_ENABLE 0xf4
|
#define MOUSECMD_ENABLE 0xf4
|
||||||
|
|
||||||
void enable_mouse(struct MOUSE_DEC *mdec) {
|
void enable_mouse(struct MOUSE_DEC *mdec)
|
||||||
|
{
|
||||||
/* 鼠标有效 */
|
/* 鼠标有效 */
|
||||||
wait_KBC_sendready();
|
wait_KBC_sendready();
|
||||||
io_out8(PORT_KEYCMD, KEYCMD_SENDTO_MOUSE);
|
io_out8(PORT_KEYCMD, KEYCMD_SENDTO_MOUSE);
|
||||||
@@ -28,7 +30,8 @@ void enable_mouse(struct MOUSE_DEC *mdec) {
|
|||||||
return;
|
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) {
|
if (mdec->phase == 0) {
|
||||||
/* 等待鼠标的0xfa的阶段 */
|
/* 等待鼠标的0xfa的阶段 */
|
||||||
if (dat == 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;
|
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)
|
void sheet_updown(struct SHEET *sht, int height)
|
||||||
{
|
{
|
||||||
struct SHTCTL *ctl = sht->ctl;
|
struct SHTCTL *ctl = sht->ctl;
|
||||||
@@ -86,7 +158,7 @@ void sheet_updown(struct SHEET *sht, int height)
|
|||||||
}
|
}
|
||||||
ctl->top--; /* 由于显示中的图层减少了一个,所以最上面的图层高度下降 */
|
ctl->top--; /* 由于显示中的图层减少了一个,所以最上面的图层高度下降 */
|
||||||
sheet_refreshmap(ctl, sht->vx0, sht->vy0, sht->vx0 + sht->bxsize, sht->vy0 + sht->bysize, 0);
|
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) { /* 比以前高 */
|
} else if (old < height) { /* 比以前高 */
|
||||||
if (old >= 0) {
|
if (old >= 0) {
|
||||||
@@ -119,83 +191,6 @@ void sheet_refresh(struct SHEET *sht, int bx0, int by0, int bx1, int by1)
|
|||||||
return;
|
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)
|
void sheet_slide(struct SHEET *sht, int vx0, int vy0)
|
||||||
{
|
{
|
||||||
struct SHTCTL *ctl = sht->ctl;
|
struct SHTCTL *ctl = sht->ctl;
|
||||||
|
|||||||
@@ -2,13 +2,14 @@
|
|||||||
|
|
||||||
#include "bootpack.h"
|
#include "bootpack.h"
|
||||||
|
|
||||||
#define PIT_CTRL 0x0043
|
#define PIT_CTRL 0x0043
|
||||||
#define PIT_CNT0 0x0040
|
#define PIT_CNT0 0x0040
|
||||||
#define TIMER_FLAGS_ALLOC 1 /* 已配置状态 */
|
|
||||||
#define TIMER_FLAGS_USING 2 /* 定时器运行中 */
|
|
||||||
|
|
||||||
struct TIMERCTL timerctl;
|
struct TIMERCTL timerctl;
|
||||||
|
|
||||||
|
#define TIMER_FLAGS_ALLOC 1 /* 已配置状态 */
|
||||||
|
#define TIMER_FLAGS_USING 2 /* 定时器运行中 */
|
||||||
|
|
||||||
void init_pit(void)
|
void init_pit(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
@@ -17,8 +18,9 @@ void init_pit(void)
|
|||||||
io_out8(PIT_CNT0, 0x2e);
|
io_out8(PIT_CNT0, 0x2e);
|
||||||
timerctl.count = 0;
|
timerctl.count = 0;
|
||||||
timerctl.next = 0xffffffff; /* 因为最初没有正在运行的定时器 */
|
timerctl.next = 0xffffffff; /* 因为最初没有正在运行的定时器 */
|
||||||
|
timerctl.using = 0;
|
||||||
for (i = 0; i < MAX_TIMER; i++) {
|
for (i = 0; i < MAX_TIMER; i++) {
|
||||||
timerctl.timer[i].flags = 0; /* 未使用 */
|
timerctl.timers0[i].flags = 0; /* 未使用 */
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -27,9 +29,9 @@ struct TIMER *timer_alloc(void)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < MAX_TIMER; i++) {
|
for (i = 0; i < MAX_TIMER; i++) {
|
||||||
if (timerctl.timer[i].flags == 0) {
|
if (timerctl.timers0[i].flags == 0) {
|
||||||
timerctl.timer[i].flags = TIMER_FLAGS_ALLOC;
|
timerctl.timers0[i].flags = TIMER_FLAGS_ALLOC;
|
||||||
return &timerctl.timer[i];
|
return &timerctl.timers0[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0; /* 没找到 */
|
return 0; /* 没找到 */
|
||||||
@@ -50,37 +52,56 @@ void timer_init(struct TIMER *timer, struct FIFO8 *fifo, unsigned char data)
|
|||||||
|
|
||||||
void timer_settime(struct TIMER *timer, unsigned int timeout)
|
void timer_settime(struct TIMER *timer, unsigned int timeout)
|
||||||
{
|
{
|
||||||
|
int e, i, j;
|
||||||
timer->timeout = timeout + timerctl.count;
|
timer->timeout = timeout + timerctl.count;
|
||||||
timer->flags = TIMER_FLAGS_USING;
|
timer->flags = TIMER_FLAGS_USING;
|
||||||
if (timerctl.next > timer->timeout) {
|
e = io_load_eflags();
|
||||||
/* 更新下一次的时刻 */
|
io_cli();
|
||||||
timerctl.next = timer->timeout;
|
/* 搜索注册位置 */
|
||||||
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void inthandler20(int *esp)
|
void inthandler20(int *esp)
|
||||||
{
|
{
|
||||||
int i;
|
int i, j;
|
||||||
io_out8(PIC0_OCW2, 0x60); /* 把IRQ-00信号接收完了的信息通知给PIC */
|
io_out8(PIC0_OCW2, 0x60); /* 把IRQ-00信号接收完了的信息通知给PIC */
|
||||||
timerctl.count++;
|
timerctl.count++;
|
||||||
if (timerctl.next > timerctl.count) {
|
if (timerctl.next > timerctl.count) {
|
||||||
return; /* 还不到下一个时刻,所以结束*/
|
return; /* 还不到下一个时刻,所以结束*/
|
||||||
}
|
}
|
||||||
timerctl.next = 0xffffffff;
|
timerctl.next = 0xffffffff;
|
||||||
for (i = 0; i < MAX_TIMER; i++) {
|
for (i = 0; i < timerctl.using; i++) {
|
||||||
if (timerctl.timer[i].flags == TIMER_FLAGS_USING) {
|
/* timers的定时器都处于动作中,所以不确认flags */
|
||||||
if (timerctl.timer[i].timeout <= timerctl.count) {
|
if (timerctl.timers[i]->timeout > timerctl.count) {
|
||||||
/* 超时 */
|
break;
|
||||||
timerctl.timer[i].flags = TIMER_FLAGS_ALLOC;
|
|
||||||
fifo8_put(timerctl.timer[i].fifo, timerctl.timer[i].data);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
/* 还没有超时 */
|
|
||||||
if (timerctl.next > timerctl.timer[i].timeout) {
|
|
||||||
timerctl.next = timerctl.timer[i].timeout;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
/* 超时*/
|
||||||
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user