From 27bf2bb54c8eb78b4cca7a8372c0ffd253454feb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juhani=20Krekel=C3=A4?= Date: Fri, 11 Mar 2022 21:51:25 +0200 Subject: [PATCH] Separate calculating hand position from drawing it --- dosclock.asm | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/dosclock.asm b/dosclock.asm index a78fad6..049b759 100644 --- a/dosclock.asm +++ b/dosclock.asm @@ -79,8 +79,10 @@ mainloop: ; Draw hour hand mov ax, hour_hand_len - mov cl, hour_hand_color - call draw_hand + mov bp, line_sx + call calculate_hand_position + mov bl, hour_hand_color + call draw_line ; 1 minute = 5° rotation of minute hand mov ax, [minute] @@ -94,8 +96,10 @@ mainloop: ; Draw minute hand mov ax, minute_hand_len - mov cl, minute_hand_color - call draw_hand + mov bp, line_sx + call calculate_hand_position + mov bl, minute_hand_color + call draw_line ; 1 second = 5° rotation of second hand mov ax, [second] @@ -104,8 +108,10 @@ mainloop: ; Draw second hand mov ax, second_hand_len - mov cl, second_hand_color - call draw_hand + mov bp, line_sx + call calculate_hand_position + mov bl, second_hand_color + call draw_line .unchanged: hlt @@ -135,30 +141,30 @@ clear_screen: ; in: ; ax = hand length ; bx = hand angle -; cl = hand color -draw_hand: +; bp = points data area +; out: +; [bp] = start x +; [bp + 2] = start y +; [bp + 4] = end x +; [bp + 6] = end y +calculate_hand_position: push ax - push bx push dx - mov word [line_sx], midpoint_x - mov word [line_sy], midpoint_y - mov word [line_ex], midpoint_x - mov word [line_ey], midpoint_y + mov word [bp], midpoint_x + mov word [bp + 2], midpoint_y + mov word [bp + 4], midpoint_x + mov word [bp + 6], midpoint_y mov dx, ax call sinx - add [line_ex], ax + add [bp + 4], ax mov ax, dx call cosx - sub [line_ey], ax - - mov bl, cl - call draw_line + sub [bp + 6], ax pop dx - pop bx pop ax ret