Separate calculating hand position from drawing it

This commit is contained in:
Juhani Krekelä 2022-03-11 21:51:25 +02:00
parent 70e6513b76
commit 27bf2bb54c
1 changed files with 25 additions and 19 deletions

View File

@ -79,8 +79,10 @@ mainloop:
; Draw hour hand ; Draw hour hand
mov ax, hour_hand_len mov ax, hour_hand_len
mov cl, hour_hand_color mov bp, line_sx
call draw_hand call calculate_hand_position
mov bl, hour_hand_color
call draw_line
; 1 minute = 5° rotation of minute hand ; 1 minute = 5° rotation of minute hand
mov ax, [minute] mov ax, [minute]
@ -94,8 +96,10 @@ mainloop:
; Draw minute hand ; Draw minute hand
mov ax, minute_hand_len mov ax, minute_hand_len
mov cl, minute_hand_color mov bp, line_sx
call draw_hand call calculate_hand_position
mov bl, minute_hand_color
call draw_line
; 1 second = 5° rotation of second hand ; 1 second = 5° rotation of second hand
mov ax, [second] mov ax, [second]
@ -104,8 +108,10 @@ mainloop:
; Draw second hand ; Draw second hand
mov ax, second_hand_len mov ax, second_hand_len
mov cl, second_hand_color mov bp, line_sx
call draw_hand call calculate_hand_position
mov bl, second_hand_color
call draw_line
.unchanged: .unchanged:
hlt hlt
@ -135,30 +141,30 @@ clear_screen:
; in: ; in:
; ax = hand length ; ax = hand length
; bx = hand angle ; bx = hand angle
; cl = hand color ; bp = points data area
draw_hand: ; out:
; [bp] = start x
; [bp + 2] = start y
; [bp + 4] = end x
; [bp + 6] = end y
calculate_hand_position:
push ax push ax
push bx
push dx push dx
mov word [line_sx], midpoint_x mov word [bp], midpoint_x
mov word [line_sy], midpoint_y mov word [bp + 2], midpoint_y
mov word [line_ex], midpoint_x mov word [bp + 4], midpoint_x
mov word [line_ey], midpoint_y mov word [bp + 6], midpoint_y
mov dx, ax mov dx, ax
call sinx call sinx
add [line_ex], ax add [bp + 4], ax
mov ax, dx mov ax, dx
call cosx call cosx
sub [line_ey], ax sub [bp + 6], ax
mov bl, cl
call draw_line
pop dx pop dx
pop bx
pop ax pop ax
ret ret