diff --git a/day15/bootpack.c b/day15/bootpack.c index 77d8f7a..a8855e6 100644 --- a/day15/bootpack.c +++ b/day15/bootpack.c @@ -6,14 +6,12 @@ void make_textbox8(struct SHEET *sht, int x0, int y0, int sx, int sy, int c); void HariMain(void) { struct BOOTINFO *binfo = (struct BOOTINFO *) ADR_BOOTINFO; // 结构体指针指向储存系统信息的地址 - // 内存管理 struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR; - // 图层管理 + struct FIFO32 fifo; + int fifobuf[128]; struct SHTCTL *shtctl; // 图层背景,鼠标 struct SHEET *sht_bak, *sht_mouse, *sht_win; - // 缓冲区 - struct FIFO32 fifo; // 定义背景缓冲区、鼠标缓冲区 unsigned char *buf_back, buf_mouse[256], *buf_win; // 键盘按键字符表 @@ -26,11 +24,9 @@ void HariMain(void) '2', '3', '0', '.' }; unsigned int memtotal; - int fifobuf[128]; char s[40]; struct TIMER *timer, *timer2, *timer3; int i, mx, my, cursor_x, cursor_c; - init_gdtidt(); // 初始化 全局段记录表,中断记录表 init_pic(); // 初始化 PIC io_sti(); // IDT/PIC 的初始化已经完成,开放 CPU 的中断 @@ -38,7 +34,6 @@ void HariMain(void) io_out8(PIC0_IMR, 0xf8); // 开放PIC1和键盘中断(11111001) io_out8(PIC1_IMR, 0xef); // 开放鼠标中断(11101111) fifo32_init(&fifo, 128, fifobuf); - timer = timer_alloc(); timer2 = timer_alloc(); timer3 = timer_alloc(); @@ -48,14 +43,12 @@ void HariMain(void) timer_settime(timer, 1000); timer_settime(timer2, 300); timer_settime(timer3, 50); - init_keyboard(&fifo, 256); enable_mouse(&fifo, 512, &mdec); memtotal = memtest(0x00400000, 0xbfffffff); memman_init(memman); memman_free(memman, 0x00001000, 0x0009e000); // 0x00001000 - 0x0009efff memman_free(memman, 0x00400000, memtotal - 0x00400000); - init_palette(); // 分配图层、内存 shtctl = shtctl_init(memman, binfo->vram, binfo->scrnx, binfo->scrny); @@ -64,14 +57,11 @@ void HariMain(void) 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); - sheet_setbuf(sht_bak, 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); // 没有透明色 - init_screen(buf_back, binfo->scrnx, binfo->scrny); init_mouse_cursor8(buf_mouse, 99); // 背景色号 99 - // 创建窗口 make_window8(buf_win, 160, 52, "window"); // 创建输入盒子 @@ -80,21 +70,17 @@ void HariMain(void) cursor_c = COL8_FFFFFF; mx = (binfo->scrnx - 16) / 2; my = (binfo->scrny - 28 - 16) / 2; - // 设置在移动图层时进行局部画面刷新 sheet_slide(sht_bak, 0, 0); sheet_slide(sht_mouse, mx, my); sheet_slide(sht_win, 80, 72); - // 设置叠加显示优先级 sheet_updown(sht_bak, 0); sheet_updown(sht_win, 1); sheet_updown(sht_mouse, 2); - putfont8_pos(buf_back, binfo->scrnx, 0, 30, COL8_FFFFFF, "SPARK.OS"); sprintf(s, "memory %dMB free: %dKB", memtotal / (1024 * 1024), memman_total(memman) / 1024); putfonts8_str(buf_back, binfo->scrnx, 0, 50, COL8_FFFFFF, s); - sheet_refresh(sht_bak, 0, 0, sht_bak->bxsize, sht_bak->bysize); for (;;) { @@ -131,7 +117,10 @@ void HariMain(void) } else if (512 <= i && i <= 767) { if (mouse_decode(&mdec, i - 512) != 0) { sprintf(s, "[lcr %4d %4d]", mdec.x, mdec.y); - if ((mdec.btn & 0x01) != 0) s[1] = 'L'; + if ((mdec.btn & 0x01) != 0) { + s[1] = 'L'; + sheet_slide(sht_win, mx - 80, my - 8); + } if ((mdec.btn & 0x02) != 0) s[3] = 'R'; if ((mdec.btn & 0x04) != 0) s[2] = 'C'; putfonts8_str_sht(sht_bak, 0, 32, COL8_FFFFFF, COL8_008484, s); @@ -147,9 +136,7 @@ void HariMain(void) // 显示坐标 putfonts8_str_sht(sht_bak, 0, 16, COL8_FFFFFF, COL8_008484, s); // 描绘鼠标 - // 包含 sheet_refresh sheet_slide(sht_mouse, mx, my); - if ((mdec.btn & 0x01) != 0) sheet_slide(sht_win, mx - 80, my - 8); } } switch (i) { diff --git a/day15/bootpack.h b/day15/bootpack.h index 063862b..ebda6b9 100644 --- a/day15/bootpack.h +++ b/day15/bootpack.h @@ -100,17 +100,6 @@ void init_gdtidt(void); /* fifo.c */ #define FLAGS_OVERRUN 0x0001 -// FIFO 缓冲区模型 -struct FIFO8 { - unsigned char *buf; - int w, r, size, free, flags; -}; - -void fifo8_init(struct FIFO8 *fifo, int size, unsigned char *buf); -int fifo8_put(struct FIFO8 *fifo, unsigned char data); -int fifo8_get(struct FIFO8 *fifo); -int fifo8_status(struct FIFO8 *fifo); - // FIFO 优化缓冲区 struct FIFO32 { int *buf; diff --git a/day15/fifo.c b/day15/fifo.c index 39f434c..dc56a8c 100644 --- a/day15/fifo.c +++ b/day15/fifo.c @@ -1,59 +1,5 @@ #include "bootpack.h" -/** 初始化FIFO缓冲区 */ -void fifo8_init(struct FIFO8 *fifo, int size, unsigned char *buf) -{ - fifo->size = size; - fifo->buf = buf; - // 缓冲区大小 - fifo->free = size; - // 当前索引 - fifo->flags = 0; - // 下一个数据写入位置 - fifo->w = 0; - // 下一个数据读出位置 - fifo->r = 0; -} - -/** 向FIFO存放数据 */ -int fifo8_put(struct FIFO8 *fifo, unsigned char data) -{ - if (fifo->free == 0) { - // 空余没有了,溢出 - fifo->flags |= FLAGS_OVERRUN; - return -1; - } - fifo->buf[fifo->w] = data; - fifo->w++; - if (fifo->w == fifo->size) { - fifo->w = 0; - } - fifo->free--; - return 0; -} - -/** 向FIFO读取数据 */ -int fifo8_get(struct FIFO8 *fifo) -{ - int data; - if (fifo->free == fifo->size) { - return -1; - } - data = fifo->buf[fifo->r]; - fifo->r++; - if (fifo->r == fifo->size) { - fifo->r = 0; - } - fifo->free++; - return data; -} - -/** 报告FIFO状态 */ -int fifo8_status(struct FIFO8 *fifo) -{ - return fifo->size - fifo->free; -} - /** 初始化FIFO缓冲区 */ void fifo32_init(struct FIFO32 *fifo, int size, int *buf) { @@ -79,9 +25,7 @@ int fifo32_put(struct FIFO32 *fifo, int data) } fifo->buf[fifo->w] = data; fifo->w++; - if (fifo->w == fifo->size) { - fifo->w = 0; - } + if (fifo->w == fifo->size) fifo->w = 0; fifo->free--; return 0; } @@ -89,15 +33,10 @@ int fifo32_put(struct FIFO32 *fifo, int data) /** 向FIFO读取数据 */ int fifo32_get(struct FIFO32 *fifo) { - int data; - if (fifo->free == fifo->size) { - return -1; - } - data = fifo->buf[fifo->r]; + if (fifo->free == fifo->size) return -1; + int data = fifo->buf[fifo->r]; fifo->r++; - if (fifo->r == fifo->size) { - fifo->r = 0; - } + if (fifo->r == fifo->size) fifo->r = 0; fifo->free++; return data; } diff --git a/day15/keyboard.c b/day15/keyboard.c index 7e22388..ddb64b5 100644 --- a/day15/keyboard.c +++ b/day15/keyboard.c @@ -17,7 +17,9 @@ void inthandler21(int *esp) /** 等待键盘控制电路准备完毕 */ void wait_KBC_sendready(void) { - for(;;) if ((io_in8(PORT_KEYSTA) & KEYSTA_SEND_NOTREADY) == 0) { break; } + for(;;) { + if ((io_in8(PORT_KEYSTA) & KEYSTA_SEND_NOTREADY) == 0) break; + } } /** 初始化键盘控制电路 diff --git a/day15/mouse.c b/day15/mouse.c index e22cc46..70fe6a8 100644 --- a/day15/mouse.c +++ b/day15/mouse.c @@ -35,10 +35,16 @@ void enable_mouse(struct FIFO32 *fifo, int data0, struct MOUSE_DEC *mdec) int mouse_decode(struct MOUSE_DEC *mdec, unsigned char data) { switch (mdec->phase) { + case 0: + // 等待鼠标就绪 (0xfa) + if (data == 0xfa) mdec->phase = 1; + return 0; /** 等待鼠标发送第一个字节 */ case 1: - mdec->buf[0] = data; - mdec->phase = 2; + if ((data & 0xc8) == 0x08) { + mdec->buf[0] = data; + mdec->phase = 2; + } return 0; /** 等待鼠标发送第二个字节 */ case 2: @@ -58,9 +64,6 @@ int mouse_decode(struct MOUSE_DEC *mdec, unsigned char data) // 鼠标的y方向与画面符号相反 mdec->y = - mdec->y; return 1; - default: - // 等待鼠标就绪 (0xfa) - if (data == 0xfa) mdec->phase = 1; } return -1; } diff --git a/day15/timer.c b/day15/timer.c index be93d8a..10afbf7 100644 --- a/day15/timer.c +++ b/day15/timer.c @@ -79,7 +79,7 @@ void timer_settime(struct TIMER *timer, unsigned int timeout) return; } // 搜索插入位置 - while (1) { + for(;;) { s = t; t = t->next; // 最后面