summaryrefslogtreecommitdiff
path: root/v4.0/src/BIOS/READCLOC.INC
diff options
context:
space:
mode:
Diffstat (limited to 'v4.0/src/BIOS/READCLOC.INC')
-rw-r--r--v4.0/src/BIOS/READCLOC.INC165
1 files changed, 165 insertions, 0 deletions
diff --git a/v4.0/src/BIOS/READCLOC.INC b/v4.0/src/BIOS/READCLOC.INC
new file mode 100644
index 0000000..700f0aa
--- /dev/null
+++ b/v4.0/src/BIOS/READCLOC.INC
@@ -0,0 +1,165 @@
1; SCCSID = @(#)readclock.asm 1.2 85/07/25
2;************************************************************************
3;
4; read_real_date reads real-time clock for date and returns the number
5; of days elapsed since 1-1-80 in si
6;
7read_real_date: ;mjb002
8 assume ds:code,es:nothing
9 PUSH AX
10 PUSH CX
11 PUSH DX
12 XOR AH,AH ; throw away clock roll over ;3.30*
13 INT 1AH ;3.30*
14 POP DX
15 POP CX
16 POP AX
17
18 PUSH AX
19 PUSH BX
20 PUSH CX
21 PUSH DX
22 MOV CS:DAYCNT2,1 ;MJB002 REAL TIME CLOCK ERROR FLAG (+1 DA;3.30Y)
23 mov ah,4 ;mjb002 read date function code ;3.30*
24 int 1ah ;mjb002 read real-time clock ;3.30*
25 jnc read_ok ;mjb002 jmp success
26 jmp r_d_ret ;mjb002 jmp error
27read_ok: ;mjb002 ******* get bcd values in binary *****
28 mov byte ptr bin_date_time+0,ch ;mjb002 store as hex value
29 mov byte ptr bin_date_time+1,cl ;mjb002 ...
30 mov byte ptr bin_date_time+2,dh ;mjb002 ...
31 mov byte ptr bin_date_time+3,dl ;mjb002 ...
32 MOV CS:DAYCNT2,2 ;MJB002 READ OF R-T CLOCK SUCCESSFUL ;3.30
33 call bcd_verify ;mjb002 verify bcd values in range
34 jc r_d_ret ;mjb002 jmp some value out of range
35 MOV CS:DAYCNT2,3 ;MJB002 READ OF R-T CLOCK SUCCESSFUL ;3.30
36 call date_verify ;mjb002 verify date values in range
37 jc r_d_ret ;mjb002 jmp some value out of range
38 MOV CS:DAYCNT2,0 ;MJB002 VERIFY SUCCESSFUL ;3.30;3.30
39 call in_bin ;mjb002 convert date to binary
40 ;mjb002 ******* years since 1-1-80 *********
41 mov al,byte ptr bin_date_time+1 ;mjb002 get years into century
42 cbw ;mjb002
43 cmp byte ptr bin_date_time+0,20 ;mjb002 20th century?
44 jnz century_19 ;mjb002 jmp no
45 add ax,100 ;mjb002 add in a century
46century_19: ;mjb002
47 sub ax,80 ;mjb002 subtract off 1-1-80
48 mov cl,4 ;mjb002 leap year every 4
49 div cl ;mjb002 al= # leap year blocks, ah= remainder
50 mov bl,ah ;mjb002 save odd years
51 cbw ;mjb002 zero ah
52 mov cx,366+3*365 ;mjb002 # of days in leap year blocks
53 mul cx ;mjb002 dx:ax is result
54 MOV CS:DAYCNT2,AX ;MJB002 SAVE COUNT OF DAYS ;3.30
55 mov al,bl ;mjb002 get odd years count
56 cbw ;mjb002
57 or ax,ax ;mjb002 is ax= 0?
58 jz leap_year ;mjb002 jmp if none
59 mov cx,365 ;mjb002 days in year
60 mul cx ;mjb002 dx:ax is result
61 ADD CS:DAYCNT2,AX ;MJB002 ADD ON DAYS IN ODD YEARS ;3.30
62 jmp short leap_adjustment ;mjb002 account for leap year
63leap_year: ;mjb002 possibly account for a leap day
64 cmp byte ptr bin_date_time+2,2 ;mjb002 is month february
65 jbe no_leap_adjustment ;mjb002 jan or feb. no leap day yet.
66leap_adjustment: ;mjb002 account for leap day
67 INC CS:DAYCNT2 ;MJB002 ... ;3.30
68no_leap_adjustment: ;mjb002 ******* get days of month *******
69 mov cl,byte ptr bin_date_time+3 ;mjb002 ...
70 xor ch,ch ;mjb002
71 dec cx ;mjb002 because of offset from day 1, not day 0
72 ADD CS:DAYCNT2,CX ;MJB002 ******* GET DAYS IN MONTHS PRECEE;3.30DING *****
73 mov cl,byte ptr bin_date_time+2 ;mjb002 get month
74 xor ch,ch ;mjb002
75 dec cx ;mjb002 january starts at offset 0
76 shl cx,1 ;mjb002 word offset
77 mov si,offset month_table ;mjb002 beginning of month_table
78 add si,cx ;mjb002 point into month table
79 mov ax,word ptr [si];mjb002 get # days in previous months
80 ADD CS:DAYCNT2,AX ;MJB002 ... ;3.30
81r_d_ret: ;mjb002
82 MOV SI,CS:DAYCNT2 ;MJB002 RESULT IN SI ;3.30
83 POP DX
84 POP CX
85 POP BX
86 POP AX
87 ret ;mjb002
88
89r_t_retj:
90 xor cx,cx
91 xor dx,dx
92 jmp r_t_ret
93;
94; Read_Real_Time reads the time from the RTC. on exit, it has the number of
95; ticks (at 18.2 ticks per sec.) in CX:DX.
96;
97Read_Real_Time:
98 mov ah,2 ;3.30*
99 int 1AH ;3.30*
100 jc r_t_retj
101oktime:
102 mov byte ptr bin_date_time,ch ; hours
103 mov byte ptr bin_date_time+1,cl ; minutes
104 mov byte ptr bin_date_time+2,dh ; seconds
105 mov byte ptr bin_date_time+3,0 ; unused for time
106 call bcd_verify
107 jc r_t_retj
108 call time_verify
109 jc r_t_retj
110 call in_bin
111 MOV ch,byte ptr bin_date_time
112 MOV cl,byte ptr bin_date_time+1
113 MOV dh,byte PTR bin_date_time+2
114 MOV dl,byte PTR bin_date_time+3
115 message ftestinit,<"Read Time ">
116 mnum ftestinit,cx
117 message ftestinit,<" ">
118 mnum ftestinit,dx
119 message ftestinit,<cr,lf>
120; get time in ticks in CX:DX
121 CALL word ptr cs:TimeToTicks ;3.30
122 message ftestinit,<"Conv Time ">
123 mnum ftestinit,cx
124 message ftestinit,<" ">
125 mnum ftestinit,dx
126 message ftestinit,<cr,lf>
127r_t_ret:
128 ret
129
130;
131; in_bin converts bin_date_time values from bcd to bin
132;
133in_bin: ;mjb002
134 assume ds:code,es:nothing
135 mov al,byte ptr bin_date_time+0 ; century or hours
136 call bcd_to_bin ; ...
137 mov byte ptr bin_date_time+0,al ;
138 mov al,byte ptr bin_date_time+1 ; years or minutes
139 call bcd_to_bin ; ...
140 mov byte ptr bin_date_time+1,al ;
141 mov al,byte ptr bin_date_time+2 ; months or seconds
142 call bcd_to_bin ; ...
143 mov byte ptr bin_date_time+2,al ;
144 mov al,byte ptr bin_date_time+3 ; days (not used for time)
145 call bcd_to_bin ; ...
146 mov byte ptr bin_date_time+3,al ;
147 ret ;
148;
149; bcd_to_bin converts two bcd nibbles in al (value <= 99.) to
150; a binary representation in al
151; ah is destroyed
152;
153bcd_to_bin: ;mjb002
154 assume ds:nothing,es:nothing
155 mov ah,al ;mjb002 copy bcd number to ah
156 and ax,0f00fh ;mjb002 clear unwanted nibbles
157 mov bl,al ;mjb002 save units place
158 xchg ah,al ;mjb002 10's place to al
159 xor ah,ah ;mjb002 ah not wanted
160 mov cl,4 ;mjb002 shift count
161 shr ax,cl ;mjb004 swap nibbles
162 mov cl,10 ;mjb002 convert al to ...
163 mul cl ;mjb002 ... its binary value
164 add al,bl ;mjb002 add in units
165 ret ;mjb002