-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaclock4.s
1414 lines (1261 loc) · 28.8 KB
/
aclock4.s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
; ****************************************************************************
; aclock4.s - TRDOS 386 (TRDOS v2.0) Kernel - Analog Clock Demo - Mode 105h
; ----------------------------------------------------------------------------
;
; Erdogan Tan - 30/09/2024
;
; [ Last Modification: 02/10/2024 ]
;
; ****************************************************************************
; Modified from 'aclock3.s'. (Video Mode 13h)
; (Analog Clock display code without FPU instructions) -VESA VBE Mode 105h-
; ((Only INT 40h system calls))
; 20/08/2024 ; TRDOS 386 v2.0.9 (exit code)
; TRDOS 386 system calls (temporary list!)
_ver equ 0
_exit equ 1
_fork equ 2
_read equ 3
_write equ 4
_open equ 5
_close equ 6
_wait equ 7
_creat equ 8
_link equ 9
_unlink equ 10 ; _delete
_exec equ 11
_chdir equ 12
_time equ 13
_mkdir equ 14
_chmod equ 15
_chown equ 16
_break equ 17
_stat equ 18
_seek equ 19
_tell equ 20
_mount equ 21
_umount equ 22
_setuid equ 23
_getuid equ 24
_stime equ 25
_quit equ 26
_intr equ 27
_fstat equ 28
_emt equ 29
_mdate equ 30
_video equ 31
_audio equ 32
_timer equ 33
_sleep equ 34
_msg equ 35
_geterr equ 36
_fpsave equ 37
_pri equ 38
_rele equ 39
_fff equ 40
_fnf equ 41
_alloc equ 42
_dalloc equ 43
_calbac equ 44
_dma equ 45
_stdio equ 46 ; TRDOS 386 v2.0.9
%macro sys 1-4
; 29/04/2016 - TRDOS 386 (TRDOS v2.0)
; 03/09/2015
; 13/04/2015
; Retro UNIX 386 v1 system call.
%if %0 >= 2
mov ebx, %2
%if %0 >= 3
mov ecx, %3
%if %0 = 4
mov edx, %4
%endif
%endif
%endif
mov eax, %1
;int 30h
int 40h ; TRDOS 386 (TRDOS v2.0)
%endmacro
; Retro UNIX 386 v1 and TRDOS 386 v2 system call format:
; sys systemcall (eax) <arg1 (ebx)>, <arg2 (ecx)>, <arg3 (edx)>
; ----------------------------------------------------------------------------
bits 32
start:
;; clear bss
;mov edi, bss_start
;mov ecx, (bss_end - bss_start)/4
;;xor eax, eax
;rep stosd
sys _time, 0 ; get time in unix/epoch format
mov [ptime], eax ; seconds since unix epoch time
; program message
mov esi, program_msg
call print_msg
;;;;
; Set squares of number from 1 to 90
mov edi, _squares
;mov ecx, 90
mov ecx, 200 ; 1 to 200
mov ebx, 1
_ss_x:
mov eax, ebx
mul ebx
stosd
inc ebx
loop _ss_x
; x2+y2 = r2
; Set Y values for X values from 1 to Radius - 1
mov edi, _fx
;mov eax, 90
mov eax, 200 ; 1 to 200
mov [radius], eax
mov ebx, eax
mul ebx
mov ebp, eax ; _r2 (square of the radius)
_yy_x:
dec ebx
jz short start_@
mov eax, ebx
mul eax
; eax = square of ebx
mov edx, ebp ; _r2
sub edx, eax
call get_squareroot
stosd
jmp short _yy_x
;;;;
; show program message for 1 second
start_@:
sys _time, 0 ; get time in unix/epoch format
nop
cmp eax, [ptime]
je short start_@ ; same second
; 1 second has been passed
;mov ah, 2 ; read the time
;int 35h ; TRDOS 386 date&time interrupt
;jnc short start_@@
;jmp terminate
;start_@@:
;mov ah,11h
;int 32h
;jz short main
;xor ah, ah
;int 32h
start_@@:
sys _stdio, 1 ; getchar (no wait)
;jc short main
and eax, eax
jnz short start_@@
main:
;sys _time, 4 ; get tick counts
;mov [startticks], eax
mov bl, -1 ; signal response byte
mov bh, 1 ; 18.2 ticks per seconds
mov ecx, 9 ; approx. 0.5 seconds
;mov bh, 3 ; 1 second unit(RTC)
;mov ecx, 1 ; 1 second only
mov edx, srb
sys _timer ; start timer
sys _time, 0 ; get time (seconds) in UNIX format
mov [startticks], eax
;sys _time, 3 ; get time (& date) in MSDOS format
; (eax = time, edx = date)
sys _time, 1 ; get time in MSDOS format
mov [second], al ; (dl in MSDOS)
mov [minute], ah ; (cl in MSDOS)
shr eax, 16 ; al = hour (ch in MSDOS)
mov [hour], al
; MAP VGA video buffer to user (as 1 to 1)
;xor ebx, ebx
;mov bh, 5 ; Direct access/map to VGA memory
mov bh, 6 ; Direct access to Linear Frame Buffer
mov bl, 05h ; Direct access for VESA video mode 105h
sys _video
; eax = Linear Frame Buffer Address if > 0
or eax, eax ; VGA memory address
jz terminate ; error (eax = 0)
mov [LFB_Address], eax
; set video mode to 13h
;mov al, 13h ; function 00h, mode 13h
;int 31h ; TRDOS 386 - Video interrupt
;sys _video, 0813h ; set video mode to 13h
; set video mode to VESA VBE Mode 105h
; 1024*768 pixels, 256 colors
sys _video, 08FFh, 105h
; draw clock circle and indicators
call draw_background
;;;
;mov byte [_x0], 159
;mov byte [_y0], 99
mov word [_x0], (1024/2)-1
mov word [_y0], (768/2)-1
;;;
; set initial h/m/s parameters
call update_time
mov al, [hour]
mov [phour], al
mov al, [minute]
mov [pminute], al ; previous
mov [phminute], al ; previous for akrep
mov al, [second]
mov [psecond], al ; previous
mov [pmsecond], al ; previous for yelkovan
jmp short draw_hh_mh_sh
main_loop:
call update_time
jc short skip_draw
draw_hh_mh_sh:
; draw akrep (hour hand)
call draw_hour_hand
; draw yelkovan (minute hand)
call draw_minute_hand
; draw second hand
call draw_second_hand
; draw center mark
call draw_centermark
; waith for 0.5 second
;call wait_half_second
skip_draw:
;mov ah, 01h ; see if key pressed
;int 32h ; TRDOS 386 keyboard interrupt
;jz short main_loop ; loop if no key pressed
;xor ah, ah ; key pressed so clear it
;int 32h
sys _stdio, 1 ; getchar (no wait)
or eax, eax
jz short main_loop
;;; beep option (enabled/disabled by SPACEBAR)
cmp al, 20h
jne short exit_process
xor byte [nobeep], 0FFh
jmp short main_loop
nobeep: db 0FFh
;;;
;jmp short exit_process
exit_process:
;mov ax, 03h ; set video mode to 03h (default)
;int 31h ; TRDOS 386 video bios interrupt
sys _video, 0803h ; set video mode to 03h
terminate:
sys _timer, 0 ; stop timer
sys _exit, 0 ; return to TRDOS 386 MainProg
hangemhigh:
; CPU must not come here !
nop
jmp short hangemhigh
srb: db 0
ptime: ;db 0
startticks:
dd 0
LFB_Address:
dd 0
; ------------------------------------------------------------
update_time:
; push esi
; ;mov esi, -1
; mov esi, 10
;update_time_@:
; mov ah, 2 ; read the time
; int 35h ; TRDOS 386 date&time interrupt
; ;jc short update_time_retn
; jnc short update_time_@@
; ; RTC update phase
; dec esi
; jnz short update_time_@
; pop esi
; ;jmp exit_process
; stc
; retn
;update_time_@@:
; pop esi
; ch = hours (bcd)
; cl = minutes (bcd)
; dh = seconds (bcd)
; wait 1 second (kernel timer setup)
cmp byte [srb], 0FFh ; check signal response byte
jb short update_time_ok ; cf = 1
mov byte [srb], 0 ; reset for next 1 second
; get time in UNIX/Epoch format (seconds)
sys _time, 0
cmp eax, [startticks] ; is same second ?
jne short updt_0 ; no, 1 second passed
; wait 0.5 second more
stc
update_time_ok:
retn
updt_0:
mov [startticks], eax
mov al, [second]
inc al
cmp al, 60
jb short updt_1
mov al, 0
updt_1:
;mov al, dh
;call convert_bcd_to_bin
mov [second], al
or al, al
jnz short update_time_ok
mov al, [minute]
inc al
cmp al, 60
jb short updt_2
mov al, 0
updt_2:
;mov al, cl
;call convert_bcd_to_bin
mov [minute], al
and al, al
jnz short update_time_ok
mov al, [hour]
inc al
cmp al, 24
jb short updt_3
mov al, 0
updt_3:
;mov al, ch
;call convert_bcd_to_bin
mov [hour], al
clc
;update_time_retn:
;update_time_ok:
retn
; ------------------------------------------------------------
;wait_half_second:
; push ebx
; sys _time, 4 ; get tick counts
; pop ebx
; sub eax, [startticks]
; cmp eax, 9
; jb short wait_half_second
; add [startticks], eax
;
; ;nop
; ;inc ecx
; ;nop
; ;cmp byte [srb], -1
; ;jne short wait_half_second
;
; retn
; ------------------------------------------------------------
;convert_bcd_to_bin:
; mov bl, al
; and bl, 0Fh
; shr al, 4
; mov ah, 10
; mul ah
; add al, bl
; retn
; ------------------------------------------------------------
draw_background:
; INPUT:
; none
;
; Modified registers: esi, edi, eax, ecx, ebx, edx
;mov dword [_x0], 160
;mov dword [_y0], 100
;mov dword [radius], 90
mov dword [_x0], (1024/2)
mov dword [_y0], (768/2)
mov dword [radius], 200
mov byte [color], 0Bh ; cyan
;mov byte [color], 0Eh ; yellow
;mov byte [color], 0Fh ; white
call draw_circle ; writes pixels to pixel buffer
; writes all circle pixels to video buffer
;call write_circle
; draw minute indicators
call draw_minute_dots
; draw hour (5 minutes) indicators
call draw_hour_squares
retn
; ------------------------------------------------------------
draw_circle:
; INPUT:
; [_x0]
; [_y0]
; [radius]
; [color]
;
; Modified registers: esi, edi, eax, ecx, ebx, edx, ebp
; set pixel pointer position to start of circle buffer
mov eax, circlebuffer
mov [pixelpos], eax
_dc_ph0:
; quarter 1
; start from y = 0, x = radius
xor eax, eax
mov [_y1], eax ; 0
mov [phase], al ; 0
mov ebp, [radius]
mov [_x1], ebp ; y = 0, x = r
mov esi, _fx
_dc_ph0_n:
dec dword [_x1]
lodsd
_dc_ph0_x:
mov edx, [_y1]
inc edx
cmp edx, eax
jnb short _dc_ph0_y
push eax
mov [_y1], edx
call get_start_offset
call write_pixel
pop eax
jmp short _dc_ph0_x
_dc_ph0_y:
mov [_y1], eax
call get_start_offset
call write_pixel
dec ebp
jnz short _dc_ph0_n
_dc_ph1:
; quarter 2
; start from y = radius, x = 0
inc byte [phase]
xor eax, eax
mov [_x1], eax ; 0
mov ebp, [radius]
mov [_y1], ebp ; y = r, x = 0
mov esi, _fx
_dc_ph1_n:
dec dword [_y1]
lodsd
_dc_ph1_x:
mov edx, [_x1]
inc edx
cmp edx, eax
jnb short _dc_ph1_y
push eax
mov [_x1], edx
call get_start_offset
call write_pixel
pop eax
jmp short _dc_ph1_x
_dc_ph1_y:
mov [_x1], eax
call get_start_offset
call write_pixel
dec ebp
jnz short _dc_ph1_n
_dc_ph2:
; quarter 3
; start from y = 0, x = radius
inc byte [phase]
xor eax, eax
mov [_y1], eax ; 0
mov ebp, [radius]
mov [_x1], ebp ; y = 0, x = r
mov esi, _fx
_dc_ph2_n:
dec dword [_x1]
lodsd
_dc_ph2_x:
mov edx, [_y1]
inc edx
cmp edx, eax
jnb short _dc_ph2_y
push eax
mov [_y1], edx
call get_start_offset
call write_pixel
pop eax
jmp short _dc_ph2_x
_dc_ph2_y:
mov [_y1], eax
call get_start_offset
call write_pixel
dec ebp
jnz short _dc_ph2_n
_dc_ph3:
; quarter 4
; start from y = radius, x = 0
inc byte [phase]
xor eax, eax
mov [_x1], eax ; 0
mov ebp, [radius]
mov [_y1], ebp ; y = r, x = 0
mov esi, _fx
_dc_ph3_n:
dec dword [_y1]
lodsd
_dc_ph3_x:
mov edx, [_x1]
inc edx
cmp edx, eax
jnb short _dc_ph3_y
push eax
mov [_x1], edx
call get_start_offset
call write_pixel
pop eax
jmp short _dc_ph3_x
_dc_ph3_y:
mov [_x1], eax
call get_start_offset
call write_pixel
dec ebp
jnz short _dc_ph3_n
_dc_ph4:
;retn
; ------------------------------------------------------------
write_dots:
write_line:
write_circle:
mov esi, circlebuffer
;mov edi, 0A0000h ; VGA video buffer
mov edi, [LFB_Address]
mov ecx, [pixelpos]
sub ecx, esi
shr ecx, 2
mov bl, [color]
;ecx = pixel count
write_circle_@:
lodsd
mov [edi+eax], bl ; pixel color
loop write_circle_@
retn
; ------------------------------------------------------------
write_pixel:
; eax = (screen) pixel position
mov edi, [pixelpos]
stosd
mov [pixelpos], edi
retn
; ------------------------------------------------------------
get_start_offset:
;mov eax, 320
mov eax, 1024
mov edx, [_y0]
cmp byte [phase], 0
ja short gso_1
gso_0:
; quarter 1
sub edx, [_y1] ; y = 0 -> r
mul edx
add eax, [_x0]
add eax, [_x1] ; x = r -> 0
retn
gso_1:
cmp byte [phase], 1
ja short gso_2
; quarter 2
sub edx, [_y1] ; y = r -> 0
mul edx
add eax, [_x0]
sub eax, [_x1] ; x = 0 -> -r
retn
gso_2:
cmp byte [phase], 2
ja short gso_3
; quarter 3
add edx, [_y1] ; y = 0 -> -r
mul edx
add eax, [_x0]
sub eax, [_x1] ; x = -r -> 0
retn
gso_3:
; quarter 4
add edx, [_y1] ; y = -r -> 0
mul edx
add eax, [_x0]
add eax, [_x1] ; x = 0 -> r
retn
; ------------------------------------------------------------
;black_circle:
; xor ah, ah
; xchg [color], ah ; color = 0
; push eax
; call drawcircle
; pop eax
; xchg [color], ah ; restore color
; retn
; ------------------------------------------------------------
beep:
;;; beep option
test byte [nobeep], 0FFh
jnz short beep_retn
;;;
; call beep function (16/64 second, 886Hz)
sys _audio, 16, 1331
; STDERR beep method is not usable in VESA VBE mode
;sys _stdio, 3, 07h ; write beep char to STDERR
beep_retn:
retn
; ------------------------------------------------------------
draw_minute_dots:
; INPUT:
; none
;
; Modified registers: esi, edi, eax, ecx, ebx, edx
;mov dword [angle], 0
;mov byte [radius], 85
mov byte [radius], 188
;mov byte [_x0], 160
;mov byte [_y0], 100
mov dword [step], 6
mov byte [dcount], 60
mov dword [pixelpos], circlebuffer
; reset for indicator dots
xor eax, eax ; angle = 0
call draw_dots
;mov byte [angle], 0
call write_dots
retn
; ------------------------------------------------------------
draw_dots:
dmd_0:
mov [angle], eax
; eax = angle
call getcosinus
; get cosine value * 16777216 for angle in AL
; eax = cos(angle) * 16777216
call getxy
mov [_x1], eax ; projection of end point on x-axis
mov eax, [angle]
call getsinus
; get sine value * 16777216 for angle in AL
; eax = sin(angle) * 16777216
call getxy
mov [_y1], eax ; projection of end point on y-axis
mov byte [phase], 0 ; quarter 1
mov eax, [angle]
cmp eax, 90
jna short dmd_1
inc byte [phase] ; quarter 2
cmp eax, 180
jna short dmd_1
inc byte [phase] ; quarter 3
cmp eax, 270
jna short dmd_1
inc byte [phase] ; quarter 4
dmd_1:
; cover coordinates to video buffer offset
call get_start_offset
call write_pixel ; save it to pixel buffer
dec byte [dcount]
jz short dmd_2
mov eax, [step]
add eax, [angle]
jmp dmd_0
dmd_2:
retn
; ------------------------------------------------------------
draw_hour_squares:
; INPUT:
; none
;
; Modified registers: esi, edi, eax, ecx, ebx, edx
;mov dword [angle], 0
;mov byte [radius], 85
mov byte [radius], 188
mov dword [step],30
mov dword [pixelpos], circlebuffer
; reset for indicator dots
xor eax, eax
dhs_@:
;mov dword [_x0], 159
;mov dword [_y0], 99
mov dword [_x0], (1024/2)-2
mov dword [_y0], (768/2)-2
dhs_0:
mov byte [dcount], 1
call draw_dots
mov eax, [_x0]
;cmp eax, 162
cmp eax, (1024/2)+2
jnb short dhs_2
inc eax
dhs_1:
mov [_x0], eax
mov eax, [angle]
jmp short dhs_0
dhs_2:
mov eax, [_y0]
;cmp eax, 102
cmp eax, (768/2)+2
jnb short dhs_3
inc eax
mov [_y0], eax
;mov al, 159
mov eax, (1024/2)-2
jmp short dhs_1
dhs_3:
mov eax, [angle]
add eax, [step]
cmp eax, 360
jb short dhs_@
; write all of hour indicator pixels
; to VGA video buffer
;mov dword [angle], 0
call write_dots
retn
; ------------------------------------------------------------
getsinus:
; Input:
; EAX = angle
; output:
; EAX = sin(angle) * 16777216
;
; Modified registers: eax, esi
;
; Note: absolute (+) values are needed only.
; (see 'get_start_offset' procedure)
cmp eax, 180
jb short gsin_@
sub eax, 180
gsin_@:
;movzx esi, al
mov esi, eax
shl esi, 2 ; * 4
add esi, sinustable
mov eax, [esi]
mov [sin], eax
retn
; ------------------------------------------------------------
getcosinus:
; Input:
; EAX = angle
; output:
; EAX = cos(angle) * 16777216
;
; Modified registers: eax, esi
; Note: absolute (+) values are needed only.
; (see 'get_start_offset' procedure)
cmp eax, 180
jb short gcos_0
sub eax, 180
gcos_0:
add eax, 90
jmp short getsinus
cmp al, 90 ; 90 degrees
jb short gcos_1
sub al, 90
mov esi, cos_90
jmp short gcos_2
gcos_1:
mov esi, cos_0
gcos_2:
;movzx eax, al
shl eax, 2 ; * 4
add esi, eax
mov eax, [esi]
mov [cos], eax
retn
; ------------------------------------------------------------
getxy:
; Input:
; EAX = sin or cos value * 16777216
; output:
; EAX = x or y projection
;
; Modified registers: eax, edx, (ecx)
;
;mov edx, [radius]
;mul edx
mul dword [radius] ; [hipotenus]
;mov ecx, 16777216
;div ecx
shr eax, 24
retn
; ------------------------------------------------------------
get_squareroot:
; input: edx = square of the number (y)
; output: eax = approx. square root of ebx
mov esi, _squares
push ebx
xor ebx, ebx
mov ecx, [radius] ; max. value of radius is 89
q_sr_x:
lodsd
cmp eax, edx
jnb short q_sr_ok
inc ebx
loop q_sr_x
q_sr_ok:
mov eax, ebx
pop ebx
retn
; ------------------------------------------------------------
draw_hour_hand: ; draw akrep
; INPUT:
; [hour]
; [phour]
; [phminute]
;
; Modified registers: esi, edi, eax, ecx, ebx, edx, ebp
movzx eax, byte [phour] ; previous hour
;;;
mov dl, [phminute]
sub dl, [minute] ; is 2 minutes passed?
jnb short chk_m_pm
neg dl
chk_m_pm:
cmp dl, 2
jnb short skip_mh_chk
;;;
;movzx eax, byte [phour] ; previous hour
cmp al, [hour]
je short dhh_@ ; skip black/erase line stage
skip_mh_chk:
mov byte [color], 0 ; black
call dhh_@@ ; draw black line
; (erase previous hour hand)
xor eax, eax
mov al, [minute]
mov [phminute], al ; set current minute as prev
mov al, [hour]
mov [phour], al ; set current hour as previous
dhh_@:
mov byte [color], 0Fh ; draw white line (hour hand)
dhh_@@:
cmp al, 12
jb short skip_24hto12h
sub al, 12
skip_24hto12h:
mov ecx, 30 ; 30 degrees per hour
mul ecx
mov cl, [phminute]
shr cl, 1 ; 60 minutes -> 30 degrees
;adc cl, 0 ; round up if half degree
add eax, ecx
;mov byte [radius], 65 ; [hipotenus], length
mov byte [radius], 140
dmh_@@@:
dsh_@@@:
; convert clockwise angle to counterclockwise angle
neg eax ; -x
add eax, 450 ; 450 - x ; (360+90-x)
cmp eax, 360
jb short dhh_@@@ ; <= 12
sub eax, 360 ; 2nd tour of hourhand
dhh_@@@:
; convert clockwise angle to counterclockwise angle
mov [angle], eax
call draw_line
retn
; ------------------------------------------------------------
draw_minute_hand: ; draw yelkovan
; INPUT:
; [minute]
; [pminute]
; [pmsecond]
;
; Modified registers: esi, edi, eax, ecx, ebx, edx, ebp
movzx eax, byte [pminute] ; previous minute
;;;
mov dl, [pmsecond]
sub dl, [second] ; is 5 seconds passed?
jnb short chk_s_ps
neg dl
chk_s_ps:
cmp dl, 5
jnb short skip_sm_chk
;;;
;movzx eax, byte [pminute] ; previous minute
cmp al, [minute]
je short dmh_@ ; skip black/erase line stage
skip_sm_chk:
mov byte [color], 0 ; black
call dmh_@@ ; draw black line
; (erase previous minute hand)
;;;
; redraw houndhand if blanked
mov al, [phour]
mov ah, 5
mul ah
mov ah, [pminute]
cmp al, ah
jne short skip_redraw_hh
call draw_hour_hand
skip_redraw_hh:
;;;
xor eax, eax
mov al, [second]
mov [pmsecond], al ; set current second as prev
mov al, [minute]
mov [pminute], al ; set current minute as prev
dmh_@:
mov byte [color], 0Fh ; draw white line (minute hand)
dmh_@@:
mov ecx, 6 ; 6 degrees per minute
mul ecx
push eax
xor eax, eax
mov al, [pmsecond]
;xor edx, edx
mov cl, 10
div ecx ; 60 seconds -> 6 degrees
pop edx