首页 > 代码库 > 20天自制操作系统(八)
20天自制操作系统(八)
移动鼠标并显示鼠标坐标
struct MOUSE_DEC { unsigned char buf[3], phase; int x, y, btn;}; enable_mouse(&mdec); for (;;) { io_cli(); //无数据则等待 if (fifo8_status(&keyfifo) + fifo8_status(&mousefifo) == 0) { io_stihlt(); } else { if (fifo8_status(&keyfifo) != 0) { i = fifo8_get(&keyfifo); io_sti(); sprintf(s, "%02X", i); boxfill8(binfo->vram, binfo->scrnx, COL8_008484, 0, 16, 15, 31); putfonts8_asc(binfo->vram, binfo->scrnx, 0, 16, COL8_FFFFFF, s); } //处理鼠标消息 else if (fifo8_status(&mousefifo) != 0) { i = fifo8_get(&mousefifo); io_sti(); if (mouse_decode(&mdec, i) != 0) { sprintf(s, "[lcr %4d %4d]", mdec.x, mdec.y); if ((mdec.btn & 0x01) != 0) //bit0=1 { s[1] = ‘L‘; } if ((mdec.btn & 0x02) != 0) //bit1=1 { s[3] = ‘R‘; } if ((mdec.btn & 0x04) != 0) //bit2=1 { s[2] = ‘C‘; } boxfill8(binfo->vram, binfo->scrnx, COL8_008484, 32, 16, 32 + 15 * 8 - 1, 31); putfonts8_asc(binfo->vram, binfo->scrnx, 32, 16, COL8_FFFFFF, s); //背景色填充原来的鼠标位置 boxfill8(binfo->vram, binfo->scrnx, COL8_008484, mx, my, mx + 15, my + 15); //更新坐标 mx += mdec.x; my += mdec.y; //越界处理 if (mx < 0) { mx = 0; } if (my < 0) { my = 0; } if (mx > binfo->scrnx - 16) { mx = binfo->scrnx - 16; } if (my > binfo->scrny - 16) { my = binfo->scrny - 16; } //输出鼠标坐标 sprintf(s, "(%3d, %3d)", mx, my); //抹掉原坐标 boxfill8(binfo->vram, binfo->scrnx, COL8_008484, 0, 0, 79, 15); putfonts8_asc(binfo->vram, binfo->scrnx, 0, 0, COL8_FFFFFF, s); //画出新坐标下的鼠标 putblock8_8(binfo->vram, binfo->scrnx, 16, 16, mx, my, mcursor, 16); } } } }
看一看效果:
有一个严重的缺陷!
什么原因造成的?
void HariMain(void){ ... //COL8_008484为屏幕背景色 init_mouse_cursor8(mcursor, COL8_008484); ...}void init_mouse_cursor8(char *mouse, char bc){ static char cursor[16][16] = { "**************..", "*OOOOOOOOOOO*...", "*OOOOOOOOOO*....", "*OOOOOOOOO*.....", "*OOOOOOOO*......", "*OOOOOOO*.......", "*OOOOOOO*.......", "*OOOOOOOO*......", "*OOOO**OOO*.....", "*OOO*..*OOO*....", "*OO*....*OOO*...", "*O*......*OOO*..", "**........*OOO*.", "*..........*OOO*", "............*OO*", ".............***" }; int x, y; for (y = 0; y < 16; y++) { for (x = 0; x < 16; x++) { if (cursor[y][x] == ‘*‘) { mouse[y * 16 + x] = COL8_000000; } if (cursor[y][x] == ‘O‘) { mouse[y * 16 + x] = COL8_FFFFFF; } if (cursor[y][x] == ‘.‘) { mouse[y * 16 + x] = bc; //屏幕背景色 } } } return;}void putblock8_8(char *vram, int vxsize, int pxsize, int pysize, int px0, int py0, char *buf, int bxsize){ int x, y; for (y = 0; y < pysize; y++) { for (x = 0; x < pxsize; x++) { vram[(py0 + y) * vxsize + (px0 + x)] = buf[y * bxsize + x]; } } return;}
看上面代码就知道原因了,如何修改呢?
putblock8_8加一个函数判断坐标
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。