Erase only the old hand positions for a less flickery redraw
This commit is contained in:
parent
27bf2bb54c
commit
4396f2935e
89
dosclock.asm
89
dosclock.asm
|
@ -54,12 +54,16 @@ mainloop:
|
||||||
jmp .unchanged
|
jmp .unchanged
|
||||||
|
|
||||||
.changed:
|
.changed:
|
||||||
call clear_screen
|
|
||||||
|
|
||||||
mov [hour], ch
|
mov [hour], ch
|
||||||
mov [minute], cl
|
mov [minute], cl
|
||||||
mov [second], dh
|
mov [second], dh
|
||||||
|
|
||||||
|
; Save old hand positions
|
||||||
|
mov si, hour_position
|
||||||
|
mov di, old_hour_position
|
||||||
|
mov cx, 24
|
||||||
|
call memcpy
|
||||||
|
|
||||||
mov ax, [hour]
|
mov ax, [hour]
|
||||||
|
|
||||||
; 12 hour clock face → map 12…23 to 0…11
|
; 12 hour clock face → map 12…23 to 0…11
|
||||||
|
@ -77,12 +81,10 @@ mainloop:
|
||||||
shr ax, 1
|
shr ax, 1
|
||||||
add bx, ax
|
add bx, ax
|
||||||
|
|
||||||
; Draw hour hand
|
; Calculate hour hand position
|
||||||
mov ax, hour_hand_len
|
mov ax, hour_hand_len
|
||||||
mov bp, line_sx
|
mov bp, hour_position
|
||||||
call calculate_hand_position
|
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,24 +96,40 @@ mainloop:
|
||||||
div word [twelve]
|
div word [twelve]
|
||||||
add bx, ax
|
add bx, ax
|
||||||
|
|
||||||
; Draw minute hand
|
; Calculate minute hand position
|
||||||
mov ax, minute_hand_len
|
mov ax, minute_hand_len
|
||||||
mov bp, line_sx
|
mov bp, minute_position
|
||||||
call calculate_hand_position
|
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]
|
||||||
mul word [six]
|
mul word [six]
|
||||||
mov bx, ax
|
mov bx, ax
|
||||||
|
|
||||||
; Draw second hand
|
; Calculate second hand position
|
||||||
mov ax, second_hand_len
|
mov ax, second_hand_len
|
||||||
mov bp, line_sx
|
mov bp, second_position
|
||||||
call calculate_hand_position
|
call calculate_hand_position
|
||||||
|
|
||||||
|
; Erase hands
|
||||||
|
xor bl, bl
|
||||||
|
mov si, old_hour_position
|
||||||
|
call draw_hand
|
||||||
|
mov si, old_minute_position
|
||||||
|
call draw_hand
|
||||||
|
mov si, old_second_position
|
||||||
|
call draw_hand
|
||||||
|
|
||||||
|
; Draw hands
|
||||||
|
mov si, hour_position
|
||||||
|
mov bl, hour_hand_color
|
||||||
|
call draw_hand
|
||||||
|
mov si, minute_position
|
||||||
|
mov bl, minute_hand_color
|
||||||
|
call draw_hand
|
||||||
|
mov si, second_position
|
||||||
mov bl, second_hand_color
|
mov bl, second_hand_color
|
||||||
call draw_line
|
call draw_hand
|
||||||
|
|
||||||
.unchanged:
|
.unchanged:
|
||||||
hlt
|
hlt
|
||||||
|
@ -125,19 +143,38 @@ exit:
|
||||||
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
clear_screen:
|
; in:
|
||||||
push bp
|
; cx = count
|
||||||
|
; ds:si = source
|
||||||
|
; ds:di = destination
|
||||||
|
memcpy:
|
||||||
|
push cx
|
||||||
|
push si
|
||||||
|
push di
|
||||||
|
push es
|
||||||
|
|
||||||
xor bp, bp
|
mov ax, ds
|
||||||
.loop:
|
mov es, ax
|
||||||
mov word [es:bp], 0
|
|
||||||
add bp, 2
|
|
||||||
cmp bp, 320*200
|
|
||||||
jne .loop
|
|
||||||
|
|
||||||
pop bp
|
rep movsb
|
||||||
|
|
||||||
|
pop es
|
||||||
|
pop di
|
||||||
|
pop si
|
||||||
|
pop cx
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
; in:
|
||||||
|
; si = points data area
|
||||||
|
; bl = color
|
||||||
|
; clobbers:
|
||||||
|
; si, di, cx
|
||||||
|
draw_hand:
|
||||||
|
mov di, line_sx
|
||||||
|
mov cx, 8
|
||||||
|
call memcpy
|
||||||
|
jmp draw_line
|
||||||
|
|
||||||
; in:
|
; in:
|
||||||
; ax = hand length
|
; ax = hand length
|
||||||
; bx = hand angle
|
; bx = hand angle
|
||||||
|
@ -521,6 +558,14 @@ hour dw 0
|
||||||
minute dw 0
|
minute dw 0
|
||||||
second dw 0
|
second dw 0
|
||||||
|
|
||||||
|
hour_position times 4 dw 0
|
||||||
|
minute_position times 4 dw 0
|
||||||
|
second_position times 4 dw 0
|
||||||
|
|
||||||
|
old_hour_position times 4 dw 0
|
||||||
|
old_minute_position times 4 dw 0
|
||||||
|
old_second_position times 4 dw 0
|
||||||
|
|
||||||
line_sx dw 0
|
line_sx dw 0
|
||||||
line_sy dw 0
|
line_sy dw 0
|
||||||
line_ex dw 0
|
line_ex dw 0
|
||||||
|
|
Loading…
Reference in New Issue