-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaclock1.s
502 lines (435 loc) · 9.05 KB
/
aclock1.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
; analogic clock 8086/87 (using 13h graphic mode)
; written by Leonardo Ono (ono.leo@gmail.com)
; 26/09/2017
; target os: DOS (.COM file extension)
; use: nasm aclock.asm -o aclock.com -f bin
; ----------------------------------------------
; TRDOS 386 Adaptation: Erdogan Tan - 29/09/2024
; ----------------------------------------------
; Alternative code (INT 40h only)
; -TRDOS 386 v2.0.9 or later kernel versions-
; 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
bits 32
start:
;mov ah, 2 ; read the time
;int 35h ; TRDOS 386 date&time interrupt
;jnc short start_@
;jmp terminate
;start_@:
;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, 3 ; get time in MSDOS format
mov byte [data.seconds], al ; (dl in MSDOS)
mov byte [data.minutes], ah ; (cl in MSDOS)
shr eax, 16
mov ebp, eax ; al = hour (ch in MSDOS)
mov ah, 60
mul ah
add ax, word [data.minutes]
mov word [data.hours], ax
sys _time, 0 ; get time (seconds) in UNIX format
mov [startticks],eax
call start_graphic_mode
;fninit ; FPU is initialized by TRDOS 386 kernel
call draw_background
.main_loop:
;call update_time
;jc short .skip_draw
call update_angles
mov ecx, 15 ; 0Fh ; white
call draw_pointers
;sys _stdio,1
;mov ah, 11h
;int 32h ; if key pressed, exit
;jnz exit_process
;call sleep_half_s ; wait 0.5 second
call update_time
jc short .skip_draw
sub ecx, ecx ; 0 ; black
call draw_pointers ; clear previous pointers
.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 ; al = character (ascii code)
jz short .main_loop
jmp exit_process
;sleep_half_s:
; ;push ebx
; ;sys _time, 4 ; get tick counts
; ;pop ebx
; ;sub eax, [startticks]
; ;cmp eax, 9
; ;jb short sleep_half_s
; ;add [startticks], eax
;
; nop
; inc ecx
; nop
; cmp byte [srb], -1 ; requested srb value = 0FFh
; jne short sleep_half_s
; mov byte [srb], 0 ; reset
;
; retn
srb: db 0 ; signal response byte (signal from the kernel)
startticks: dd 0
; in:
; edi = angle
; esi = size
update_pointer:
fld qword [edi]
fcos
fld qword [esi]
fmul st1
fistp word [data.x]
ffree st0
fld qword [edi]
fsin
fld qword [esi]
fmul st1
fistp word [data.y]
ffree st0
retn
update_angles:
mov ebx, data.v720
mov esi, data.hours
mov edi, data.angle_h
call update_angle
mov ebx, data.v60
mov esi, data.minutes
mov edi, data.angle_m
call update_angle
mov ebx, data.v60
mov esi, data.seconds
mov edi, data.angle_s
call update_angle
retn
; in:
; ebx = v720 or v60
; esi = hours, minutes or seconds
; edi = angle_h, angle_m or angle_s
update_angle:
fld qword [data.v90deg]
fld qword [data.pi2]
fld qword [ebx]
fild word [esi]
fdiv st1
fmul st2
fsub st3
fstp qword [edi]
ffree st0
ffree st1
ffree st2
retn
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, [data.seconds]
inc al
cmp al,60
jb short updt_1
mov al, 0
updt_1:
;mov al, dh
;call convert_byte_bcd_to_bin
mov byte [data.seconds], al
or al, al
jnz short update_time_ok
mov al, [data.minutes]
inc al
cmp al, 60
jb short updt_2
mov al, 0
updt_2:
;mov al, cl
;call convert_byte_bcd_to_bin
mov byte [data.minutes], al
and al, al
jnz short update_time_ok
inc ebp
mov eax, ebp
cmp al, 24
jb short updt_3
xor eax, eax
mov ebp, eax ; hour = 0
jmp short updt_4
;mov al, ch
;call convert_byte_bcd_to_bin
updt_3:
;mov ah, 0
mov bx, 60
mul bx
updt_4:
add ax, word [data.minutes]
mov word [data.hours], ax ; in number of minutes
;update_time_retn:
;update_time_ok:
retn
; in:
; cx = color index
draw_pointers:
mov edi, data.angle_h
;mov esi, data.size50
mov esi, data.size60
call update_pointer
mov edi, ecx
call draw_pointer
mov edi, data.angle_m
mov esi, data.size80
call update_pointer
mov edi, ecx
call draw_pointer
mov edi, data.angle_s
mov esi, data.size80
call update_pointer
mov edi, ecx
call draw_pointer
retn
; in:
; di = color index
draw_pointer:
pushad
mov eax, 160
mov ebx, 100
mov ecx, 160
mov edx, 100
add cx, word [data.x]
add dx, word [data.y]
call draw_line
popad
retn
; in:
; ecx = number of steps
; ebx = angle incrementation
; edi = angle variable
; esi = radius
draw_circle:
.next:
fld qword [ebx]
fld qword [edi]
fadd st1
fstp qword [edi]
ffree st0
mov edi, data.angle_s
;mov esi, data.size90
call update_pointer
pushad
mov al, 15
mov ecx, 160
add cx, word [data.x]
mov ebx, 100
add bx, word [data.y]
call pset
popad
loop .next
retn
draw_hours_indications:
mov ecx, 12
.next:
push ecx
fld qword [data.v30deg]
fld qword [data.angle_h]
fadd st1
fstp qword [data.angle_h]
ffree st0
mov edi, data.angle_h
mov esi, data.size85
call update_pointer
.draw_square:
mov eax, 159
mov edx, 99
.next_dot:
call .draw_square_dot
inc eax
;cmp eax, 162
cmp al, 162
jb short .next_dot
.dot_next_y:
;mov eax, 159
mov al, 159
inc edx
;cmp edx, 102
cmp dl, 102
jb short .next_dot
pop ecx
loop .next
retn
; eax = x
; edx = y
.draw_square_dot:
pushad
mov ecx, eax
add cx, word [data.x]
mov ebx, edx
add bx, word [data.y]
mov al, 15
call pset
popad
retn
draw_background:
; draw external circle
mov ecx, 720
mov ebx, data.vhalf_deg
mov esi, data.size90
mov edi, data.angle_s
call draw_circle
; draw minutes indications
mov ecx, 60
mov ebx, data.v6deg
mov esi, data.size85
mov edi, data.angle_m
call draw_circle
call draw_hours_indications
retn
exit_process:
sys _timer, 0 ; stop timer
mov ax,0003h ; set video mode to 03h (default)
int 31h ; TRDOS 386 video bios interrupt
terminate:
sys _exit
; in:
; example:
; al = 11h (bcd)
; out:
; al = 0Bh
convert_byte_bcd_to_bin:
;push ebx
mov bl, al
and bl, 0Fh
shr al, 4
mov ah, 10
mul ah
add al, bl
;pop ebx
retn
%include "graphic.s"
data:
.angle_s dq 0
.angle_m dq 0
.angle_h dq 0
.hours dw 0 ; in number of minutes
.minutes dw 0
.seconds dw 0
.size90 dq 90.0
.size85 dq 85.0
.size80 dq 80.0
;.size50 dq 50.0
.size60 dq 60.0
.pi2 dq 6.28318
.vhalf_deg dq 0.00872665
.v6deg dq 0.10472
.v90deg dq 1.5708
.v30deg dq 0.523599
.v60 dq 60.0
.v720 dq 720.0
.x dw 0
.y dw 0
.tmp dd 0