From 9512c407470df41850b2bd33ea7f240dbbac5d75 Mon Sep 17 00:00:00 2001 From: Ry Date: Wed, 5 Oct 2022 17:18:14 -0700 Subject: [PATCH] Prevent windows from being moved off-screen --- kernel/window/window.asm | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/kernel/window/window.asm b/kernel/window/window.asm index d564700..05e1401 100644 --- a/kernel/window/window.asm +++ b/kernel/window/window.asm @@ -198,9 +198,36 @@ start_dragging_window_loop: ; r1: Y position ; r2: pointer to window struct move_window: + push r0 + push r1 push r2 + push r3 + push r4 + push r5 + push r6 - add r2, 20 + ; prevent windows from being moved off-screen + add r2, 16 + movz.16 r3, [r2] + add r2, 2 + movz.16 r4, [r2] + mov r5, 640 + mov r6, 480 + sub r5, r3 + sub r6, r4 + + cmp r0, 0x80000000 + ifgt mov r0, 0 + cmp r1, 0x80000000 + ifgt mov r1, 0 + + cmp r0, r5 + ifgt mov r0, r5 + cmp r1, r6 + ifgt mov r1, r6 + + ; move the window + add r2, 2 mov.16 [r2], r0 add r2, 2 mov.16 [r2], r1 @@ -208,7 +235,13 @@ move_window: movz.8 r2, [r2] call move_overlay + pop r6 + pop r5 + pop r4 + pop r3 pop r2 + pop r1 + pop r0 ret ; fill a whole window with a color