better mouse demo
This commit is contained in:
parent
0bc7429173
commit
9fec34806e
1 changed files with 54 additions and 20 deletions
|
|
@ -16,40 +16,74 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <framebuffer.h>
|
#include <framebuffer.h>
|
||||||
|
#include <panic.h>
|
||||||
#include <ps2.h>
|
#include <ps2.h>
|
||||||
|
|
||||||
//defined in ps2.asm
|
//defined in ps2.asm
|
||||||
//returns -1 if no byte available
|
//returns -1 if no byte available
|
||||||
int read_ps2_byte();
|
int read_ps2_byte();
|
||||||
|
|
||||||
static uint32_t color = 1;
|
static void process_keyboard_byte(uint8_t byte) {
|
||||||
|
(void)byte;
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
static void change_color() {
|
static uint8_t mouse_packet[3];
|
||||||
|
static int mouse_packet_length = 0;
|
||||||
|
|
||||||
color ^= color << 13;
|
static int total_x = 0;
|
||||||
color ^= color >> 17;
|
static int total_y = 0;
|
||||||
color ^= color << 5;
|
|
||||||
|
|
||||||
for (int y = 0; y < fb_height; ++y)
|
static void process_mouse_byte(uint8_t byte) {
|
||||||
for (int x = 0; x < fb_width; ++x)
|
|
||||||
*(uint32_t *)&fb_base[y * fb_pitch + x * 4] = color & 0x00ffffff;
|
mouse_packet[mouse_packet_length] = byte;
|
||||||
|
if (mouse_packet_length < 2) {
|
||||||
|
++mouse_packet_length;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mouse_packet_length = 0;
|
||||||
|
|
||||||
|
int x = mouse_packet[1];
|
||||||
|
if (mouse_packet[0] & 0x10)
|
||||||
|
x -= 256;
|
||||||
|
|
||||||
|
int y = mouse_packet[2];
|
||||||
|
if (mouse_packet[0] & 0x20)
|
||||||
|
y -= 256;
|
||||||
|
|
||||||
|
total_x += x;
|
||||||
|
total_y -= y;
|
||||||
|
|
||||||
|
if (total_x < 0)
|
||||||
|
total_x = 0;
|
||||||
|
if (total_x >= fb_width)
|
||||||
|
total_x = fb_width - 1;
|
||||||
|
|
||||||
|
if (total_y < 0)
|
||||||
|
total_y = 0;
|
||||||
|
if (total_y >= fb_height)
|
||||||
|
total_y = fb_height - 1;
|
||||||
|
|
||||||
|
fb_base[total_y * fb_pitch + total_x * 4] = 0xff;
|
||||||
|
fb_base[total_y * fb_pitch + total_x * 4 + 1] = 0xff;
|
||||||
|
fb_base[total_y * fb_pitch + total_x * 4 + 2] = 0xff;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void on_keyboard_irq() {
|
void on_keyboard_irq() {
|
||||||
|
while (1) {
|
||||||
while (read_ps2_byte() != -1)
|
int byte = read_ps2_byte();
|
||||||
;
|
if (byte == -1)
|
||||||
|
return;
|
||||||
change_color();
|
process_keyboard_byte(byte);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void on_mouse_irq() {
|
void on_mouse_irq() {
|
||||||
|
while (1) {
|
||||||
while (read_ps2_byte() != -1)
|
int byte = read_ps2_byte();
|
||||||
;
|
if (byte == -1)
|
||||||
|
return;
|
||||||
change_color();
|
process_mouse_byte(byte);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue