diff --git a/include/defs.h b/include/defs.h index 470bf1d..57f6d2f 100644 --- a/include/defs.h +++ b/include/defs.h @@ -382,6 +382,10 @@ void vga_putc(int, uint32); void vga_clear(uint32); void vga_screen_reset(void); void vga_set_bg(uint32); +// The mode actually in use. The resolution is a boot-time choice now, so no +// caller may hardcode it. +uint32 vga_get_width(void); +uint32 vga_get_height(void); // Crash-screen primitives: the panic handler lays itself out rather than // printing. See kernel/core/panic.c. int vga_ready(void); diff --git a/kernel/dev/mouse.c b/kernel/dev/mouse.c index 3f3a25f..029c6f7 100644 --- a/kernel/dev/mouse.c +++ b/kernel/dev/mouse.c @@ -66,10 +66,20 @@ mouse_move_locked(int dx, int dy) mouse_state.x += dx; mouse_state.y += dy; + // Clamp to the screen that actually exists. These were the literals 800 and + // 600, which was correct while that was the only mode the loader could set. + // It is a boot-time choice now (press R), and at 1280x800 the pointer simply + // stopped two thirds of the way across -- which reads as the cursor drifting + // away from the host's, rather than as a clamp. + int maxx = (int)vga_get_width(); + int maxy = (int)vga_get_height(); + if(maxx <= 0) maxx = 800; + if(maxy <= 0) maxy = 600; + if(mouse_state.x < 0) mouse_state.x = 0; if(mouse_state.y < 0) mouse_state.y = 0; - if(mouse_state.x >= 800) mouse_state.x = 799; - if(mouse_state.y >= 600) mouse_state.y = 599; + if(mouse_state.x >= maxx) mouse_state.x = maxx - 1; + if(mouse_state.y >= maxy) mouse_state.y = maxy - 1; } // The same pointer, moved by something that is not the PS/2 port. USB HID diff --git a/kernel/dev/vga.c b/kernel/dev/vga.c index abe51ad..63af1ca 100644 --- a/kernel/dev/vga.c +++ b/kernel/dev/vga.c @@ -73,6 +73,20 @@ vga_init(uint64 phys_addr) { // when userspace starts and the display changes owner. } +// The mode that was actually set. Exported because the resolution is chosen at +// boot now (press R -- see boot/bios/stage2.S), so nothing above may assume it. +uint32 +vga_get_width(void) +{ + return vga_width; +} + +uint32 +vga_get_height(void) +{ + return vga_height; +} + void vga_draw_pixel(int x, int y, uint32 color) {