-
Notifications
You must be signed in to change notification settings - Fork 0
/
aclock3.txt
1681 lines (1681 loc) · 94.8 KB
/
aclock3.txt
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
1 ; ****************************************************************************
2 ; aclock3.s - TRDOS 386 (TRDOS v2.0) Kernel - Analog Clock Demo - Mode 13h
3 ; ----------------------------------------------------------------------------
4 ;
5 ; Erdogan Tan - 30/09/2024
6 ;
7 ; [ Last Modification: 01/10/2024 ]
8 ;
9 ; ****************************************************************************
10 ; ref: aclock.s, circle4.s, line7.s (TRDOS 386 demo programs)
11
12 ; (Analog Clock display code without FPU instructions)
13 ; ((ONly INT 40h system calls))
14
15 ; 20/08/2024 ; TRDOS 386 v2.0.9 (exit code)
16 ; TRDOS 386 system calls (temporary list!)
17 _ver equ 0
18 _exit equ 1
19 _fork equ 2
20 _read equ 3
21 _write equ 4
22 _open equ 5
23 _close equ 6
24 _wait equ 7
25 _creat equ 8
26 _link equ 9
27 _unlink equ 10 ; _delete
28 _exec equ 11
29 _chdir equ 12
30 _time equ 13
31 _mkdir equ 14
32 _chmod equ 15
33 _chown equ 16
34 _break equ 17
35 _stat equ 18
36 _seek equ 19
37 _tell equ 20
38 _mount equ 21
39 _umount equ 22
40 _setuid equ 23
41 _getuid equ 24
42 _stime equ 25
43 _quit equ 26
44 _intr equ 27
45 _fstat equ 28
46 _emt equ 29
47 _mdate equ 30
48 _video equ 31
49 _audio equ 32
50 _timer equ 33
51 _sleep equ 34
52 _msg equ 35
53 _geterr equ 36
54 _fpsave equ 37
55 _pri equ 38
56 _rele equ 39
57 _fff equ 40
58 _fnf equ 41
59 _alloc equ 42
60 _dalloc equ 43
61 _calbac equ 44
62 _dma equ 45
63 _stdio equ 46 ; TRDOS 386 v2.0.9
64
65 %macro sys 1-4
66 ; 29/04/2016 - TRDOS 386 (TRDOS v2.0)
67 ; 03/09/2015
68 ; 13/04/2015
69 ; Retro UNIX 386 v1 system call.
70 %if %0 >= 2
71 mov ebx, %2
72 %if %0 >= 3
73 mov ecx, %3
74 %if %0 = 4
75 mov edx, %4
76 %endif
77 %endif
78 %endif
79 mov eax, %1
80 ;int 30h
81 int 40h ; TRDOS 386 (TRDOS v2.0)
82 %endmacro
83
84 ; Retro UNIX 386 v1 and TRDOS 386 v2 system call format:
85 ; sys systemcall (eax) <arg1 (ebx)>, <arg2 (ecx)>, <arg3 (edx)>
86 ; ----------------------------------------------------------------------------
87
88 bits 32
89 start:
90 ;; clear bss
91 ;mov edi, bss_start
92 ;mov ecx, (bss_end - bss_start)/4
93 ;;xor eax, eax
94 ;rep stosd
95
96 sys _time, 0 ; get time in unix/epoch format
66 <1>
67 <1>
68 <1>
69 <1>
70 <1> %if %0 >= 2
71 00000000 BB00000000 <1> mov ebx, %2
72 <1> %if %0 >= 3
73 <1> mov ecx, %3
74 <1> %if %0 = 4
75 <1> mov edx, %4
76 <1> %endif
77 <1> %endif
78 <1> %endif
79 00000005 B80D000000 <1> mov eax, %1
80 <1>
81 0000000A CD40 <1> int 40h
97 0000000C A3[7B010000] mov [ptime], eax ; seconds since unix epoch time
98
99 ; program message
100 00000011 BE[C90B0000] mov esi, program_msg
101 00000016 E8C6080000 call print_msg
102
103 ;;;;
104 ; Set squares of number from 0 to 89
105 0000001B BF[540C0000] mov edi, _squares
106 00000020 B95A000000 mov ecx, 90
107 00000025 BB01000000 mov ebx, 1
108 _ss_x:
109 0000002A 89D8 mov eax, ebx
110 0000002C F7E3 mul ebx
111 0000002E AB stosd
112 0000002F 43 inc ebx
113 00000030 E2F8 loop _ss_x
114
115 ; x2+y2 = r2
116 ; Set Y values for X values from 1 to Radius - 1
117 00000032 BF[C00D0000] mov edi, _fx
118 00000037 B85A000000 mov eax, 90
119 0000003C A3[180C0000] mov [radius], eax
120 00000041 89C3 mov ebx, eax
121 00000043 F7E3 mul ebx
122 00000045 89C5 mov ebp, eax ; _r2 (square of the radius)
123 _yy_x:
124 00000047 4B dec ebx
125 00000048 7410 jz short start_@
126 0000004A 89D8 mov eax, ebx
127 0000004C F7E0 mul eax
128 ; eax = square of ebx
129 0000004E 89EA mov edx, ebp ; _r2
130 00000050 29C2 sub edx, eax
131 00000052 E870050000 call get_squareroot
132 00000057 AB stosd
133 00000058 EBED jmp short _yy_x
134 ;;;;
135
136 ; show program message for 1 second
137 start_@:
138 sys _time, 0 ; get time in unix/epoch format
66 <1>
67 <1>
68 <1>
69 <1>
70 <1> %if %0 >= 2
71 0000005A BB00000000 <1> mov ebx, %2
72 <1> %if %0 >= 3
73 <1> mov ecx, %3
74 <1> %if %0 = 4
75 <1> mov edx, %4
76 <1> %endif
77 <1> %endif
78 <1> %endif
79 0000005F B80D000000 <1> mov eax, %1
80 <1>
81 00000064 CD40 <1> int 40h
139 00000066 90 nop
140 00000067 3B05[7B010000] cmp eax, [ptime]
141 0000006D 74EB je short start_@ ; same second
142
143 ; 1 second has been passed
144
145 ;mov ah, 2 ; read the time
146 ;int 35h ; TRDOS 386 date&time interrupt
147 ;jnc short start_@@
148 ;jmp terminate
149 ;start_@@:
150 ;mov ah,11h
151 ;int 32h
152 ;jz short main
153 ;xor ah, ah
154 ;int 32h
155 start_@@:
156 sys _stdio, 1 ; getchar (no wait)
66 <1>
67 <1>
68 <1>
69 <1>
70 <1> %if %0 >= 2
71 0000006F BB01000000 <1> mov ebx, %2
72 <1> %if %0 >= 3
73 <1> mov ecx, %3
74 <1> %if %0 = 4
75 <1> mov edx, %4
76 <1> %endif
77 <1> %endif
78 <1> %endif
79 00000074 B82E000000 <1> mov eax, %1
80 <1>
81 00000079 CD40 <1> int 40h
157 ;jc short main
158 0000007B 21C0 and eax, eax
159 0000007D 75F0 jnz short start_@@
160 main:
161 ;sys _time, 4 ; get tick counts
162 ;mov [startticks], eax
163
164 0000007F B3FF mov bl, -1 ; signal response byte
165 00000081 B701 mov bh, 1 ; 18.2 ticks per seconds
166 00000083 B909000000 mov ecx, 9 ; approx. 0.5 seconds
167 ;mov bh, 3 ; 1 second unit(RTC)
168 ;mov ecx, 1 ; 1 second only
169 00000088 BA[7A010000] mov edx, srb
170 sys _timer ; start timer
66 <1>
67 <1>
68 <1>
69 <1>
70 <1> %if %0 >= 2
71 <1> mov ebx, %2
72 <1> %if %0 >= 3
73 <1> mov ecx, %3
74 <1> %if %0 = 4
75 <1> mov edx, %4
76 <1> %endif
77 <1> %endif
78 <1> %endif
79 0000008D B821000000 <1> mov eax, %1
80 <1>
81 00000092 CD40 <1> int 40h
171
172 sys _time, 0 ; get time (seconds) in UNIX format
66 <1>
67 <1>
68 <1>
69 <1>
70 <1> %if %0 >= 2
71 00000094 BB00000000 <1> mov ebx, %2
72 <1> %if %0 >= 3
73 <1> mov ecx, %3
74 <1> %if %0 = 4
75 <1> mov edx, %4
76 <1> %endif
77 <1> %endif
78 <1> %endif
79 00000099 B80D000000 <1> mov eax, %1
80 <1>
81 0000009E CD40 <1> int 40h
173 000000A0 A3[7B010000] mov [startticks], eax
174
175 ;sys _time, 3 ; get time (& date) in MSDOS format
176 ; (eax = time, edx = date)
177 sys _time, 1 ; get time in MSDOS format
66 <1>
67 <1>
68 <1>
69 <1>
70 <1> %if %0 >= 2
71 000000A5 BB01000000 <1> mov ebx, %2
72 <1> %if %0 >= 3
73 <1> mov ecx, %3
74 <1> %if %0 = 4
75 <1> mov edx, %4
76 <1> %endif
77 <1> %endif
78 <1> %endif
79 000000AA B80D000000 <1> mov eax, %1
80 <1>
81 000000AF CD40 <1> int 40h
178 000000B1 A2[440C0000] mov [second], al ; (dl in MSDOS)
179 000000B6 8825[430C0000] mov [minute], ah ; (cl in MSDOS)
180 000000BC C1E810 shr eax, 16 ; al = hour (ch in MSDOS)
181 000000BF A2[420C0000] mov [hour], al
182
183 ; MAP VGA video buffer to user (as 1 to 1)
184 ;xor ebx, ebx
185 000000C4 B705 mov bh, 5 ; Direct access/map to VGA memory
186 sys _video
66 <1>
67 <1>
68 <1>
69 <1>
70 <1> %if %0 >= 2
71 <1> mov ebx, %2
72 <1> %if %0 >= 3
73 <1> mov ecx, %3
74 <1> %if %0 = 4
75 <1> mov edx, %4
76 <1> %endif
77 <1> %endif
78 <1> %endif
79 000000C6 B81F000000 <1> mov eax, %1
80 <1>
81 000000CB CD40 <1> int 40h
187 ; eax = 0A0000h
188 000000CD 3D00000A00 cmp eax, 0A0000h ; VGA memory address
189 000000D2 0F8587000000 jne terminate ; error (eax = 0)
190
191 ; set video mode to 13h
192 ;mov al, 13h ; function 00h, mode 13h
193 ;int 31h ; TRDOS 386 - Video interrupt
194 sys _video, 0813h ; set video mode to 13h
66 <1>
67 <1>
68 <1>
69 <1>
70 <1> %if %0 >= 2
71 000000D8 BB13080000 <1> mov ebx, %2
72 <1> %if %0 >= 3
73 <1> mov ecx, %3
74 <1> %if %0 = 4
75 <1> mov edx, %4
76 <1> %endif
77 <1> %endif
78 <1> %endif
79 000000DD B81F000000 <1> mov eax, %1
80 <1>
81 000000E2 CD40 <1> int 40h
195
196 ; draw clock circle and indicators
197 000000E4 E800010000 call draw_background
198
199 ;;;
200 000000E9 C605[200C0000]9F mov byte [_x0], 159
201 ;mov byte [_y0], 99
202 ;;;
203
204 ; set initial h/m/s parameters
205 000000F0 E88A000000 call update_time
206 000000F5 A0[420C0000] mov al, [hour]
207 000000FA A2[450C0000] mov [phour], al
208 000000FF A0[430C0000] mov al, [minute]
209 00000104 A2[460C0000] mov [pminute], al ; previous
210 00000109 A2[480C0000] mov [phminute], al ; previous for akrep
211 0000010E A0[440C0000] mov al, [second]
212 00000113 A2[470C0000] mov [psecond], al ; previous
213 00000118 A2[490C0000] mov [pmsecond], al ; previous for yelkovan
214 0000011D EB07 jmp short draw_hh_mh_sh
215 main_loop:
216 0000011F E85B000000 call update_time
217 00000124 720F jc short skip_draw
218 draw_hh_mh_sh:
219 ; draw akrep (hour hand)
220 00000126 E8B6040000 call draw_hour_hand
221
222 ; draw yelkovan (minute hand)
223 0000012B E83A050000 call draw_minute_hand
224
225 ; draw second hand
226 00000130 E8BC050000 call draw_second_hand
227
228 ; waith for 0.5 second
229 ;call wait_half_second
230 skip_draw:
231 ;mov ah, 01h ; see if key pressed
232 ;int 32h ; TRDOS 386 keyboard interrupt
233 ;jz short main_loop ; loop if no key pressed
234 ;xor ah, ah ; key pressed so clear it
235 ;int 32h
236 sys _stdio, 1 ; getchar (no wait)
66 <1>
67 <1>
68 <1>
69 <1>
70 <1> %if %0 >= 2
71 00000135 BB01000000 <1> mov ebx, %2
72 <1> %if %0 >= 3
73 <1> mov ecx, %3
74 <1> %if %0 = 4
75 <1> mov edx, %4
76 <1> %endif
77 <1> %endif
78 <1> %endif
79 0000013A B82E000000 <1> mov eax, %1
80 <1>
81 0000013F CD40 <1> int 40h
237 00000141 09C0 or eax, eax
238 00000143 74DA jz short main_loop
239
240 ;;; beep option (enabled/disabled by SPACEBAR)
241 00000145 3C20 cmp al, 20h
242 00000147 750A jne short exit_process
243 00000149 8035[52010000]FF xor byte [nobeep], 0FFh
244 00000150 EBCD jmp short main_loop
245 00000152 FF nobeep: db 0FFh
246 ;;;
247
248 ;jmp short exit_process
249
250 exit_process:
251 ;mov ax, 03h ; set video mode to 03h (default)
252 ;int 31h ; TRDOS 386 video bios interrupt
253 sys _video, 0803h ; set video mode to 03h
66 <1>
67 <1>
68 <1>
69 <1>
70 <1> %if %0 >= 2
71 00000153 BB03080000 <1> mov ebx, %2
72 <1> %if %0 >= 3
73 <1> mov ecx, %3
74 <1> %if %0 = 4
75 <1> mov edx, %4
76 <1> %endif
77 <1> %endif
78 <1> %endif
79 00000158 B81F000000 <1> mov eax, %1
80 <1>
81 0000015D CD40 <1> int 40h
254 terminate:
255 sys _timer, 0 ; stop timer
66 <1>
67 <1>
68 <1>
69 <1>
70 <1> %if %0 >= 2
71 0000015F BB00000000 <1> mov ebx, %2
72 <1> %if %0 >= 3
73 <1> mov ecx, %3
74 <1> %if %0 = 4
75 <1> mov edx, %4
76 <1> %endif
77 <1> %endif
78 <1> %endif
79 00000164 B821000000 <1> mov eax, %1
80 <1>
81 00000169 CD40 <1> int 40h
256 sys _exit, 0 ; return to TRDOS 386 MainProg
66 <1>
67 <1>
68 <1>
69 <1>
70 <1> %if %0 >= 2
71 0000016B BB00000000 <1> mov ebx, %2
72 <1> %if %0 >= 3
73 <1> mov ecx, %3
74 <1> %if %0 = 4
75 <1> mov edx, %4
76 <1> %endif
77 <1> %endif
78 <1> %endif
79 00000170 B801000000 <1> mov eax, %1
80 <1>
81 00000175 CD40 <1> int 40h
257
258 hangemhigh:
259 ; CPU must not come here !
260 00000177 90 nop
261 00000178 EBFD jmp short hangemhigh
262
263 0000017A 00 srb: db 0
264 ptime: ;db 0
265 startticks:
266 0000017B 00000000 dd 0
267
268 ; ------------------------------------------------------------
269
270 update_time:
271 ; push esi
272 ; ;mov esi, -1
273 ; mov esi, 10
274 ;update_time_@:
275 ; mov ah, 2 ; read the time
276 ; int 35h ; TRDOS 386 date&time interrupt
277 ; ;jc short update_time_retn
278 ; jnc short update_time_@@
279 ; ; RTC update phase
280 ; dec esi
281 ; jnz short update_time_@
282 ; pop esi
283 ; ;jmp exit_process
284 ; stc
285 ; retn
286 ;update_time_@@:
287 ; pop esi
288
289 ; ch = hours (bcd)
290 ; cl = minutes (bcd)
291 ; dh = seconds (bcd)
292
293 ; wait 1 second (kernel timer setup)
294 0000017F 803D[7A010000]FF cmp byte [srb], 0FFh ; check signal response byte
295 00000186 721C jb short update_time_ok ; cf = 1
296
297 00000188 C605[7A010000]00 mov byte [srb], 0 ; reset for next 1 second
298
299 ; get time in UNIX/Epoch format (seconds)
300 sys _time, 0
66 <1>
67 <1>
68 <1>
69 <1>
70 <1> %if %0 >= 2
71 0000018F BB00000000 <1> mov ebx, %2
72 <1> %if %0 >= 3
73 <1> mov ecx, %3
74 <1> %if %0 = 4
75 <1> mov edx, %4
76 <1> %endif
77 <1> %endif
78 <1> %endif
79 00000194 B80D000000 <1> mov eax, %1
80 <1>
81 00000199 CD40 <1> int 40h
301 0000019B 3B05[7B010000] cmp eax, [startticks] ; is same second ?
302 000001A1 7502 jne short updt_0 ; no, 1 second passed
303 ; wait 0.5 second more
304 000001A3 F9 stc
305 update_time_ok:
306 000001A4 C3 retn
307 updt_0:
308 000001A5 A3[7B010000] mov [startticks], eax
309
310 000001AA A0[440C0000] mov al, [second]
311 000001AF FEC0 inc al
312 000001B1 3C3C cmp al, 60
313 000001B3 7202 jb short updt_1
314 000001B5 B000 mov al, 0
315 updt_1:
316 ;mov al, dh
317 ;call convert_bcd_to_bin
318 000001B7 A2[440C0000] mov [second], al
319
320 000001BC 08C0 or al, al
321 000001BE 75E4 jnz short update_time_ok
322
323 000001C0 A0[430C0000] mov al, [minute]
324 000001C5 FEC0 inc al
325 000001C7 3C3C cmp al, 60
326 000001C9 7202 jb short updt_2
327 000001CB B000 mov al, 0
328 updt_2:
329 ;mov al, cl
330 ;call convert_bcd_to_bin
331 000001CD A2[430C0000] mov [minute], al
332
333 000001D2 20C0 and al, al
334 000001D4 75CE jnz short update_time_ok
335
336 000001D6 A0[420C0000] mov al, [hour]
337 000001DB FEC0 inc al
338 000001DD 3C18 cmp al, 24
339 000001DF 7202 jb short updt_3
340 000001E1 B000 mov al, 0
341 updt_3:
342 ;mov al, ch
343 ;call convert_bcd_to_bin
344 000001E3 A2[420C0000] mov [hour], al
345 ;update_time_retn:
346 ;update_time_ok:
347 000001E8 C3 retn
348
349 ; ------------------------------------------------------------
350
351 ;wait_half_second:
352 ; push ebx
353 ; sys _time, 4 ; get tick counts
354 ; pop ebx
355 ; sub eax, [startticks]
356 ; cmp eax, 9
357 ; jb short wait_half_second
358 ; add [startticks], eax
359 ;
360 ; ;nop
361 ; ;inc ecx
362 ; ;nop
363 ; ;cmp byte [srb], -1
364 ; ;jne short wait_half_second
365 ;
366 ; retn
367
368 ; ------------------------------------------------------------
369
370 ;convert_bcd_to_bin:
371 ; mov bl, al
372 ; and bl, 0Fh
373 ; shr al, 4
374 ; mov ah, 10
375 ; mul ah
376 ; add al, bl
377 ; retn
378
379 ; ------------------------------------------------------------
380
381 draw_background:
382 ; INPUT:
383 ; none
384 ;
385 ; Modified registers: esi, edi, eax, ecx, ebx, edx
386
387 000001E9 C705[200C0000]A000- mov dword [_x0], 160
387 000001F1 0000
388 000001F3 C705[240C0000]6400- mov dword [_y0], 100
388 000001FB 0000
389 000001FD C705[180C0000]5A00- mov dword [radius], 90
389 00000205 0000
390 00000207 C605[1C0C0000]0B mov byte [color], 0Bh ; cyan
391 ;mov byte [color], 0Eh ; yellow
392 ;mov byte [color], 0Fh ; white
393 0000020E E80B000000 call draw_circle ; writes pixels to pixel buffer
394 ; writes all circle pixels to video buffer
395 ;call write_circle
396
397 ; draw minute indicators
398 00000213 E82C020000 call draw_minute_dots
399 ; draw hour (5 minutes) indicators
400 00000218 E8CF020000 call draw_hour_squares
401 0000021D C3 retn
402
403 ; ------------------------------------------------------------
404
405 draw_circle:
406 ; INPUT:
407 ; [_x0]
408 ; [_y0]
409 ; [radius]
410 ; [color]
411 ;
412 ; Modified registers: esi, edi, eax, ecx, ebx, edx, ebp
413
414 ; set pixel pointer position to start of circle buffer
415 0000021E B8[300F0000] mov eax, circlebuffer
416 00000223 A3[2C0F0000] mov [pixelpos], eax
417 _dc_ph0:
418 ; quarter 1
419 ; start from y = 0, x = radius
420 00000228 31C0 xor eax, eax
421 0000022A A3[2C0C0000] mov [_y1], eax ; 0
422 0000022F A2[410C0000] mov [phase], al ; 0
423 00000234 8B2D[180C0000] mov ebp, [radius]
424 0000023A 892D[280C0000] mov [_x1], ebp ; y = 0, x = r
425 00000240 BE[C00D0000] mov esi, _fx
426 _dc_ph0_n:
427 00000245 FF0D[280C0000] dec dword [_x1]
428 0000024B AD lodsd
429 _dc_ph0_x:
430 0000024C 8B15[2C0C0000] mov edx, [_y1]
431 00000252 42 inc edx
432 00000253 39C2 cmp edx, eax
433 00000255 7314 jnb short _dc_ph0_y
434 00000257 50 push eax
435 00000258 8915[2C0C0000] mov [_y1], edx
436 0000025E E84C010000 call get_start_offset
437 00000263 E839010000 call write_pixel
438 00000268 58 pop eax
439 00000269 EBE1 jmp short _dc_ph0_x
440 _dc_ph0_y:
441 0000026B A3[2C0C0000] mov [_y1], eax
442 00000270 E83A010000 call get_start_offset
443 00000275 E827010000 call write_pixel
444 0000027A 4D dec ebp
445 0000027B 75C8 jnz short _dc_ph0_n
446 _dc_ph1:
447 ; quarter 2
448 ; start from y = radius, x = 0
449 0000027D FE05[410C0000] inc byte [phase]
450 00000283 31C0 xor eax, eax
451 00000285 A3[280C0000] mov [_x1], eax ; 0
452 0000028A 8B2D[180C0000] mov ebp, [radius]
453 00000290 892D[2C0C0000] mov [_y1], ebp ; y = r, x = 0
454 00000296 BE[C00D0000] mov esi, _fx
455 _dc_ph1_n:
456 0000029B FF0D[2C0C0000] dec dword [_y1]
457 000002A1 AD lodsd
458 _dc_ph1_x:
459 000002A2 8B15[280C0000] mov edx, [_x1]
460 000002A8 42 inc edx
461 000002A9 39C2 cmp edx, eax
462 000002AB 7314 jnb short _dc_ph1_y
463 000002AD 50 push eax
464 000002AE 8915[280C0000] mov [_x1], edx
465 000002B4 E8F6000000 call get_start_offset
466 000002B9 E8E3000000 call write_pixel
467 000002BE 58 pop eax
468 000002BF EBE1 jmp short _dc_ph1_x
469 _dc_ph1_y:
470 000002C1 A3[280C0000] mov [_x1], eax
471 000002C6 E8E4000000 call get_start_offset
472 000002CB E8D1000000 call write_pixel
473 000002D0 4D dec ebp
474 000002D1 75C8 jnz short _dc_ph1_n
475 _dc_ph2:
476 ; quarter 3
477 ; start from y = 0, x = radius
478 000002D3 FE05[410C0000] inc byte [phase]
479 000002D9 31C0 xor eax, eax
480 000002DB A3[2C0C0000] mov [_y1], eax ; 0
481 000002E0 8B2D[180C0000] mov ebp, [radius]
482 000002E6 892D[280C0000] mov [_x1], ebp ; y = 0, x = r
483 000002EC BE[C00D0000] mov esi, _fx
484 _dc_ph2_n:
485 000002F1 FF0D[280C0000] dec dword [_x1]
486 000002F7 AD lodsd
487 _dc_ph2_x:
488 000002F8 8B15[2C0C0000] mov edx, [_y1]
489 000002FE 42 inc edx
490 000002FF 39C2 cmp edx, eax
491 00000301 7314 jnb short _dc_ph2_y
492 00000303 50 push eax
493 00000304 8915[2C0C0000] mov [_y1], edx
494 0000030A E8A0000000 call get_start_offset
495 0000030F E88D000000 call write_pixel
496 00000314 58 pop eax
497 00000315 EBE1 jmp short _dc_ph2_x
498 _dc_ph2_y:
499 00000317 A3[2C0C0000] mov [_y1], eax
500 0000031C E88E000000 call get_start_offset
501 00000321 E87B000000 call write_pixel
502 00000326 4D dec ebp
503 00000327 75C8 jnz short _dc_ph2_n
504 _dc_ph3:
505 ; quarter 4
506 ; start from y = radius, x = 0
507 00000329 FE05[410C0000] inc byte [phase]
508 0000032F 31C0 xor eax, eax
509 00000331 A3[280C0000] mov [_x1], eax ; 0
510 00000336 8B2D[180C0000] mov ebp, [radius]
511 0000033C 892D[2C0C0000] mov [_y1], ebp ; y = r, x = 0
512 00000342 BE[C00D0000] mov esi, _fx
513 _dc_ph3_n:
514 00000347 FF0D[2C0C0000] dec dword [_y1]
515 0000034D AD lodsd
516 _dc_ph3_x:
517 0000034E 8B15[280C0000] mov edx, [_x1]
518 00000354 42 inc edx
519 00000355 39C2 cmp edx, eax
520 00000357 7314 jnb short _dc_ph3_y
521 00000359 50 push eax
522 0000035A 8915[280C0000] mov [_x1], edx
523 00000360 E84A000000 call get_start_offset
524 00000365 E837000000 call write_pixel
525 0000036A 58 pop eax
526 0000036B EBE1 jmp short _dc_ph3_x
527 _dc_ph3_y:
528 0000036D A3[280C0000] mov [_x1], eax
529 00000372 E838000000 call get_start_offset
530 00000377 E825000000 call write_pixel
531 0000037C 4D dec ebp
532 0000037D 75C8 jnz short _dc_ph3_n
533 _dc_ph4:
534 ;retn
535
536 ; ------------------------------------------------------------
537
538 write_dots:
539 write_line:
540 write_circle:
541 0000037F BE[300F0000] mov esi, circlebuffer
542 00000384 BF00000A00 mov edi, 0A0000h ; VGA video buffer
543 00000389 8B0D[2C0F0000] mov ecx, [pixelpos]
544 0000038F 29F1 sub ecx, esi
545 00000391 C1E902 shr ecx, 2
546 00000394 8A1D[1C0C0000] mov bl, [color]
547 ;ecx = pixel count
548 write_circle_@:
549 0000039A AD lodsd
550 0000039B 881C07 mov [edi+eax], bl ; pixel color
551 0000039E E2FA loop write_circle_@
552 000003A0 C3 retn
553
554 ; ------------------------------------------------------------
555
556 write_pixel:
557 ; eax = (screen) pixel position
558 000003A1 8B3D[2C0F0000] mov edi, [pixelpos]
559 000003A7 AB stosd
560 000003A8 893D[2C0F0000] mov [pixelpos], edi
561 000003AE C3 retn
562
563 ; ------------------------------------------------------------
564
565 get_start_offset:
566 000003AF B840010000 mov eax, 320
567 000003B4 8B15[240C0000] mov edx, [_y0]
568 000003BA 803D[410C0000]00 cmp byte [phase], 0
569 000003C1 7715 ja short gso_1
570 gso_0:
571 ; quarter 1
572 000003C3 2B15[2C0C0000] sub edx, [_y1] ; y = 0 -> r
573 000003C9 F7E2 mul edx
574 000003CB 0305[200C0000] add eax, [_x0]
575 000003D1 0305[280C0000] add eax, [_x1] ; x = r -> 0
576 000003D7 C3 retn
577 gso_1:
578 000003D8 803D[410C0000]01 cmp byte [phase], 1
579 000003DF 7715 ja short gso_2
580 ; quarter 2
581 000003E1 2B15[2C0C0000] sub edx, [_y1] ; y = r -> 0
582 000003E7 F7E2 mul edx
583 000003E9 0305[200C0000] add eax, [_x0]
584 000003EF 2B05[280C0000] sub eax, [_x1] ; x = 0 -> -r
585 000003F5 C3 retn
586 gso_2:
587 000003F6 803D[410C0000]02 cmp byte [phase], 2
588 000003FD 7715 ja short gso_3
589 ; quarter 3
590 000003FF 0315[2C0C0000] add edx, [_y1] ; y = 0 -> -r
591 00000405 F7E2 mul edx
592 00000407 0305[200C0000] add eax, [_x0]
593 0000040D 2B05[280C0000] sub eax, [_x1] ; x = -r -> 0
594 00000413 C3 retn
595 gso_3:
596 ; quarter 4
597 00000414 0315[2C0C0000] add edx, [_y1] ; y = -r -> 0
598 0000041A F7E2 mul edx
599 0000041C 0305[200C0000] add eax, [_x0]
600 00000422 0305[280C0000] add eax, [_x1] ; x = 0 -> r
601 00000428 C3 retn
602
603 ; ------------------------------------------------------------
604
605 ;black_circle:
606 ; xor ah, ah
607 ; xchg [color], ah ; color = 0
608 ; push eax
609 ; call drawcircle
610 ; pop eax
611 ; xchg [color], ah ; restore color
612 ; retn
613
614 ; ------------------------------------------------------------
615
616 beep:
617 ;;; beep option
618 00000429 F605[52010000]FF test byte [nobeep], 0FFh
619 00000430 7511 jnz short beep_retn
620 ;;;
621
622 ; call beep function (16/64 second, 886Hz)
623 ;sys _audio, 16, 1331
624 sys _stdio, 3, 07h ; write beep char to STDERR
66 <1>
67 <1>
68 <1>
69 <1>
70 <1> %if %0 >= 2
71 00000432 BB03000000 <1> mov ebx, %2
72 <1> %if %0 >= 3
73 00000437 B907000000 <1> mov ecx, %3
74 <1> %if %0 = 4
75 <1> mov edx, %4
76 <1> %endif
77 <1> %endif
78 <1> %endif
79 0000043C B82E000000 <1> mov eax, %1
80 <1>
81 00000441 CD40 <1> int 40h
625 beep_retn:
626 00000443 C3 retn
627
628 ; ------------------------------------------------------------
629
630 draw_minute_dots:
631 ; INPUT:
632 ; none
633 ;
634 ; Modified registers: esi, edi, eax, ecx, ebx, edx
635
636 ;mov dword [angle], 0
637 00000444 C605[180C0000]55 mov byte [radius], 85
638 ;mov byte [_x0], 160
639 ;mov byte [_y0], 100
640 0000044B C705[3C0C0000]0600- mov dword [step], 6
640 00000453 0000
641 00000455 C605[400C0000]3C mov byte [dcount], 60
642
643 0000045C C705[2C0F0000]- mov dword [pixelpos], circlebuffer
643 00000462 [300F0000]
644 ; reset for indicator dots
645
646 00000466 31C0 xor eax, eax ; angle = 0
647 00000468 E806000000 call draw_dots
648
649 ;mov byte [angle], 0
650 0000046D E80DFFFFFF call write_dots
651 00000472 C3 retn
652
653 ; ------------------------------------------------------------
654
655 draw_dots:
656 dmd_0:
657 00000473 A3[380C0000] mov [angle], eax
658 ; eax = angle
659 00000478 E810010000 call getcosinus
660 ; get cosine value * 16777216 for angle in AL
661 ; eax = cos(angle) * 16777216
662 0000047D E83B010000 call getxy
663 00000482 A3[280C0000] mov [_x1], eax ; projection of end point on x-axis
664 00000487 A1[380C0000] mov eax, [angle]
665 0000048C E8DD000000 call getsinus
666 ; get sine value * 16777216 for angle in AL
667 ; eax = sin(angle) * 16777216
668 00000491 E827010000 call getxy
669 00000496 A3[2C0C0000] mov [_y1], eax ; projection of end point on y-axis
670
671 0000049B C605[410C0000]00 mov byte [phase], 0 ; quarter 1
672 000004A2 A1[380C0000] mov eax, [angle]
673 000004A7 83F85A cmp eax, 90
674 000004AA 7620 jna short dmd_1
675 000004AC FE05[410C0000] inc byte [phase] ; quarter 2
676 000004B2 3DB4000000 cmp eax, 180
677 000004B7 7613 jna short dmd_1
678 000004B9 FE05[410C0000] inc byte [phase] ; quarter 3
679 000004BF 3D0E010000 cmp eax, 270
680 000004C4 7606 jna short dmd_1
681 000004C6 FE05[410C0000] inc byte [phase] ; quarter 4
682 dmd_1:
683 ; cover coordinates to video buffer offset
684 000004CC E8DEFEFFFF call get_start_offset
685 000004D1 E8CBFEFFFF call write_pixel ; save it to pixel buffer
686
687 000004D6 FE0D[400C0000] dec byte [dcount]
688 000004DC 740D jz short dmd_2
689 000004DE A1[3C0C0000] mov eax, [step]
690 000004E3 0305[380C0000] add eax, [angle]
691 000004E9 EB88 jmp dmd_0
692 dmd_2:
693 000004EB C3 retn
694
695 ; ------------------------------------------------------------
696
697 draw_hour_squares:
698 ; INPUT:
699 ; none
700 ;
701 ; Modified registers: esi, edi, eax, ecx, ebx, edx
702
703 ;mov dword [angle], 0
704 000004EC C605[180C0000]55 mov byte [radius], 85
705
706 000004F3 C705[3C0C0000]1E00- mov dword [step],30
706 000004FB 0000
707
708 000004FD C705[2C0F0000]- mov dword [pixelpos], circlebuffer
708 00000503 [300F0000]
709 ; reset for indicator dots
710 00000507 31C0 xor eax, eax
711 dhs_@:
712 00000509 C705[200C0000]9F00- mov dword [_x0], 159
712 00000511 0000
713 00000513 C705[240C0000]6300- mov dword [_y0], 99
713 0000051B 0000
714 dhs_0:
715 0000051D C605[400C0000]01 mov byte [dcount], 1
716 00000524 E84AFFFFFF call draw_dots
717 00000529 A1[200C0000] mov eax, [_x0]
718 0000052E 3DA2000000 cmp eax, 162
719 00000533 730D jnb short dhs_2
720 00000535 40 inc eax
721 dhs_1:
722 00000536 A3[200C0000] mov [_x0], eax
723 0000053B A1[380C0000] mov eax, [angle]
724 00000540 EBDB jmp short dhs_0
725 dhs_2:
726 00000542 A1[240C0000] mov eax, [_y0]
727 00000547 83F866 cmp eax, 102
728 0000054A 730A jnb short dhs_3
729 0000054C 40 inc eax
730 0000054D A3[240C0000] mov [_y0], eax
731 00000552 B09F mov al, 159
732 00000554 EBE0 jmp short dhs_1
733 dhs_3:
734 00000556 A1[380C0000] mov eax, [angle]
735 0000055B 0305[3C0C0000] add eax, [step]
736 00000561 3D68010000 cmp eax, 360
737 00000566 72A1 jb short dhs_@
738
739 ; write all of hour indicator pixels
740 ; to VGA video buffer
741 ;mov dword [angle], 0
742 00000568 E812FEFFFF call write_dots
743 0000056D C3 retn
744
745 ; ------------------------------------------------------------
746
747 getsinus:
748 ; Input:
749 ; EAX = angle
750 ; output:
751 ; EAX = sin(angle) * 16777216
752 ;
753 ; Modified registers: eax, esi
754 ;
755
756 ; Note: absolute (+) values are needed only.
757 ; (see 'get_start_offset' procedure)
758
759 0000056E 3DB4000000 cmp eax, 180
760 00000573 7205 jb short gsin_@
761 00000575 2DB4000000 sub eax, 180
762 gsin_@:
763 ;movzx esi, al
764 0000057A 89C6 mov esi, eax
765 0000057C C1E602 shl esi, 2 ; * 4
766 0000057F 81C6[F5080000] add esi, sinustable
767 00000585 8B06 mov eax, [esi]