Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | - | 1 | Tue Jul 17 11:00:17 2018 Page 1 |
2 | |||
3 | |||
4 | |||
5 | |||
6 | |||
7 | |||
8 | |||
9 | 2500 A.D. 65816 Macro Assembler #26960 - Version 5.02g |
||
10 | ----------------------------------------------------- |
||
11 | |||
12 | Input Filename : src\F8\rtc.asm |
||
13 | Output Filename : obj\F8\rtc.obj |
||
14 | Listing Has Been Relocated |
||
15 | |||
16 | |||
17 | 2606 .LIST on |
||
18 | 2607 |
||
19 | 2608 F8FFB1 .INCLUDE inc\dirp00.inc |
||
20 | 2609 ;---------------------------------------------------------- |
||
21 | 2610 ; DIRP00.ASM |
||
22 | 2611 ; PROGETTO: B1601 |
||
23 | 2612 ; |
||
24 | 2613 ; Variabili in Direct Page $00 |
||
25 | 2614 ;---------------------------------------------------------- |
||
26 | 2615 |
||
27 | 2616 ; sezione COMMON -- questo permette di includere il file in piu' file |
||
28 | 2617 |
||
29 | 2618 .LIST on |
||
30 | 2619 |
||
31 | 2620 DIRP00: .SECTION page0, ref_only, common ;Direct-Page 00 |
||
32 | 2621 |
||
33 | 2622 000000 .ABSOLUTE ;; inizia sempre da $00 |
||
34 | 2623 000000 .ORG 0x00 |
||
35 | 2624 000000 |
||
36 | 2625 000000 0000 JiffyClk .DW ; contatore 10ms 32 bit |
||
37 | 2626 000002 0000 .DW |
||
38 | 2627 000004 SysTmr .DS SYSTMRCNT ; system timer 0 (10ms) |
||
39 | 2628 000008 SysTMF .DS SYSTMRCNT ; flag timer (80 -> start) |
||
40 | 2629 00000C 00 Bnk0Flag .DB ; <7>: flag test RAM banco 0 ok |
||
41 | 2630 ; <6>: flag warm reset |
||
42 | 2631 00000D 00 RTCFlag .DB |
||
43 | 2632 |
||
44 | 2633 00000E diskstat .DS 2 ; flag device on ata bus #0 & #1 |
||
45 | 2634 ; <7>: device ready |
||
46 | 2635 ; <6>: compact flash device (C.F.) |
||
47 | 2636 ; <5>: device identification ok |
||
48 | 2637 ; <4>: MBR loaded |
||
49 | 2638 ; <3>: valid signature in MBR |
||
50 | 2639 ; <2>: first partition found&active |
||
51 | 2640 ; <1>: |
||
52 | 2641 ; <0>: valid partition flag |
||
53 | 2642 |
||
54 | 2643 ; <7>: device ready |
||
55 | 2644 ; <6>: USB device |
||
56 | 2645 ; <5>: compact flash device (C.F.) |
||
57 | 2646 ; <4>: device identification ok |
||
58 | 2647 ; <3>: MBR loaded |
||
59 | 2648 ; <2>: first partition found&active |
||
60 | 2649 ; <1>: always 1 |
||
61 | 2650 ; <0>: valid partition flag |
||
62 | 2651 000010 |
||
63 | Tue Jul 17 11:00:17 2018 Page 2 |
||
64 | |||
65 | |||
66 | |||
67 | |||
68 | 2652 |
||
69 | 2653 00000E atadev .EQU diskstat |
||
70 | 2654 |
||
71 | 2655 000010 usbdev .DS 2 ; flag flash disk on usb bus #0 |
||
72 | 2656 ; <7>: device plugged and ready |
||
73 | 2657 ; <6>: always 1 |
||
74 | 2658 ; <5>: device identification ok |
||
75 | 2659 ; <4>: MBR loaded |
||
76 | 2660 ; <3>: valid signature in MBR |
||
77 | 2661 ; <2>: first partition found&active |
||
78 | 2662 ; <1>: |
||
79 | 2663 ; <0>: valid partition flag |
||
80 | 2664 |
||
81 | 2665 000012 diskmax .DS 16 ; disk max. sector's |
||
82 | 2666 000012 atasec .EQU diskmax |
||
83 | 2667 00001A usbsec .EQU diskmax+8 |
||
84 | 2668 |
||
85 | 2669 |
||
86 | 2670 000022 atambr .DS 8 ; data for first partition found in mbr |
||
87 | 2671 ; first 3 bytes for start sector of partition |
||
88 | 2672 ; last byte for partition type |
||
89 | 2673 00002A usbmbr .DS 8 |
||
90 | 2674 |
||
91 | 2675 000032 ataprt .DS 8 ; total sec's of first partition |
||
92 | 2676 00003A usbprt .DS 8 ; total sec's of first partition |
||
93 | 2677 |
||
94 | 2678 |
||
95 | 2679 000042 00 usb0ch .DB ; usb0 (ch375/ch376) flag |
||
96 | 2680 ; <7>: module on |
||
97 | 2681 ; <6>: ch376 flag |
||
98 | 2682 ; <5:0>: chip version |
||
99 | 2683 |
||
100 | 2684 000043 00 usb0st .DB ; usb0 status |
||
101 | 2685 ; <7>: usb0 host mode ok |
||
102 | 2686 ; <6>: flash disk attached flag |
||
103 | 2687 ; <5>: usb device attached |
||
104 | 2688 |
||
105 | 2689 000044 00 fdcdrv .DB ; phisycal drive status (drive #0) |
||
106 | 2690 ; <7>: disk format established in bit 0&1 |
||
107 | 2691 ; <6>: double step seek done |
||
108 | 2692 ; <5>: trust format bit's (set after ok r/w) |
||
109 | 2693 ; <4>: write protect bit (if disk in drive) |
||
110 | 2694 ; <3>: don't care |
||
111 | 2695 ; <2>: don't care |
||
112 | 2696 ; <1>: HD disk if set else DD disk |
||
113 | 2697 ; <0>: CBM format if set else IBM format |
||
114 | 2698 |
||
115 | 2699 000045 00 vdrive .DB ; virtual drive status (ram disk, drive #1) |
||
116 | 2700 ; <7>: disk format established in bit 0&1 |
||
117 | 2701 ; <6>: change disk simulation (after format) |
||
118 | 2702 ; <5>: don't care |
||
119 | 2703 ; <4>: write protect bit (under sw control) |
||
120 | 2704 ; <3>: don't care |
||
121 | 2705 ; <2>: don't care |
||
122 | 2706 ; <1>: HD disk if set else DD disk |
||
123 | 2707 ; <0>: CBM format if set else IBM format |
||
124 | 2708 |
||
125 | Tue Jul 17 11:00:17 2018 Page 3 |
||
126 | |||
127 | |||
128 | |||
129 | |||
130 | 2709 000046 00 fdcctl .DB ; fdc controller status |
||
131 | 2710 ; <7>: drive is attached |
||
132 | 2711 ; <6>: drive need recalibration (restore) |
||
133 | 2712 ; <5>: FDC controller ok |
||
134 | 2713 ; <4>: motor on |
||
135 | 2714 ; <3>: dma is active |
||
136 | 2715 ; <2>: dma chip ok (post routine) |
||
137 | 2716 ; <1>: clock rate (1=HD,0=DD) |
||
138 | 2717 ; <0>: disk ready |
||
139 | 2718 |
||
140 | 2719 000047 00 fdctrk .DB ; fd: current seek track |
||
141 | 2720 000048 00 fdcerr .DB ; fd: last error code |
||
142 | 2721 000049 00 ataerr .DB ; ata: last error code |
||
143 | 2722 00004A 00 ataxer .DB ; ata: last extended error code |
||
144 | 2723 |
||
145 | 2724 00004B 00 CtrlBrk .DB ; flag CTRL+BREAK (NMI) |
||
146 | 2725 |
||
147 | 2726 00004C 0000 MemTop .DW ; top memoria RAM |
||
148 | 2727 00004E 00 .DB ; banco top mem |
||
149 | 2728 |
||
150 | 2729 00004F 00 DflTxtIn .DB ; device di default text input |
||
151 | 2730 000050 00 DflTxtOut .DB ; device di default text output |
||
152 | 2731 |
||
153 | 2732 000051 COPPtr LP ; long pointer for COP decoding |
||
154 | 2733 000054 00 COPIdx .DB ; COP signature/index |
||
155 | 2734 |
||
156 | 2735 000055 00 BiosEnt .DB ; flag accesso a bios setup |
||
157 | 2736 |
||
158 | 2737 ; variabili utilizzate da ACIA |
||
159 | 2738 000056 spwrk .DS $30 |
||
160 | 2739 |
||
161 | 2740 ; bios mem |
||
162 | 2741 000086 0000 nsize .DW ; dimensione blocco da allocare |
||
163 | 2742 ;bsize .DW ; dimensione vera blocco free |
||
164 | 2743 000088 0000 splitsz .DW ; dimensione blocco splittato |
||
165 | 2744 00008A 0000 bfree .DW ; puntatore blocco free |
||
166 | 2745 00008C 0000 hdrptr .DW ; puntatore header heap |
||
167 | 2746 |
||
168 | 2747 00008E 0000 pbrklv .DW ; current break level of current process |
||
169 | 2748 000090 0000 pbrkmin .DW ; minimum breal level of current process |
||
170 | 2749 000092 0000 pbrkmax .DW ; maximum breal level of current process |
||
171 | 2750 000094 |
||
172 | 2751 ; bios temp. work area |
||
173 | 2752 000094 bwrktmp .DS $28 |
||
174 | 2753 |
||
175 | 2754 0000BC 00 coptmp .DB ; temp. used while cop |
||
176 | 2755 |
||
177 | 2756 0000BD 00 tstser .DB ; check ser/usb test board post |
||
178 | 2757 ; <7>: VIA2 ok |
||
179 | 2758 ; <6>: PICRAM ok |
||
180 | 2759 ; <1>: UART 16C550 ok |
||
181 | 2760 ; <0>: R65C51 ok |
||
182 | 2761 |
||
183 | 2762 |
||
184 | 2763 ;crc16 .DW |
||
185 | 2764 |
||
186 | 2765 0000BD .RELATIVE |
||
187 | Tue Jul 17 11:00:17 2018 Page 4 |
||
188 | |||
189 | |||
190 | |||
191 | |||
192 | 2766 |
||
193 | 2767 .ENDS |
||
194 | 2768 |
||
195 | 2769 [01] .IFDEF _ACIA_INC_ |
||
196 | 2770 .INCLUDE INC\SP.INC |
||
197 | 2771 [00] .ENDIF |
||
198 | 2772 |
||
199 | 2776 .LIST on |
||
200 | 2777 |
||
201 | 2778 000004 MAXFNC .EQU 4 |
||
202 | 2779 |
||
203 | 2780 ; page 0 local var's (declared in bios temp. work area) |
||
204 | 2781 _P0BTMP: .SECTION page0, ref_only, offset bwrktmp ; DP Tmp. BIOS |
||
205 | 2782 |
||
206 | 2783 000094 dmonth .DS 12 ; array of month's day's |
||
207 | 2784 0000A0 0000 cyear .DW ; full year - 1 |
||
208 | 2785 0000A2 0000 ty400 .DW ; full year / 400 |
||
209 | 2786 0000A4 0000 ty100 .DW ; full year / 100 |
||
210 | 2787 0000A6 0000 dvsor .DW ; divisor/remainder |
||
211 | 2788 0000A8 0000 quot .DW ; quotient |
||
212 | 2789 0000AA 0000 date1 .DW ; last march sunday |
||
213 | 2790 0000AC 0000 date2 .DW ; last october sunday |
||
214 | 2791 0000AE 00 dayofw .DB ; day of week (1=sunday...) |
||
215 | 2792 0000AF 00 date .DB ; date (day of month) |
||
216 | 2793 0000B0 00 month .DB |
||
217 | 2794 0000B1 00 year .DB |
||
218 | 2795 0000B2 00 ctry .DB ; century |
||
219 | 2796 0000B3 00 jan1 .DB ; first day of the year |
||
220 | 2797 |
||
221 | 2798 .ENDS |
||
222 | 2799 |
||
223 | 2800 .CODEF8 |
||
224 | 2801 |
||
225 | 2802 .LONGA off |
||
226 | 2803 .LONGI off |
||
227 | 2804 |
||
228 | 2805 ;--------------------------------------------------------------------------- |
||
229 | 2806 ; system call interface |
||
230 | 2807 ;--------------------------------------------------------------------------- |
||
231 | 2808 |
||
232 | 2809 ; handle real time clock |
||
233 | 2810 ; |
||
234 | 2811 ; functions: |
||
235 | 2812 ; |
||
236 | 2813 ; $00: set time (X=seconds, Y=minutes, A=hours) |
||
237 | 2814 ; $01: set date (X=day, Y=month, A=year, B=century) |
||
238 | 2815 ; ?02: get time (X=seconds, Y=minutes, A=hours, B=day of week) |
||
239 | 2816 ; $03: get date (X=day, Y=month, A=year, B=century) |
||
240 | 2817 ; |
||
241 | 2818 F8AF83 sys_rtc: |
||
242 | 2819 F8AF83 |
||
243 | 2820 .PUBLIC sys_rtc |
||
244 | 2821 |
||
245 | 2822 F8AF83 A3 12 lda STKPBR,s ; bank where was executed cop instruction |
||
246 | 2823 F8AF85 85 53 sta COPPtr+2 |
||
247 | 2824 F8AF87 ACC16 ; retrieve function number |
||
248 | 2825 F8AF87 C2 20 rep #PMFLAG |
||
249 | Tue Jul 17 11:00:17 2018 Page 5 |
||
250 | |||
251 | |||
252 | |||
253 | |||
254 | 2826 .LONGA on |
||
255 | 2827 .MNLIST |
||
256 | 2828 F8AF89 A3 10 lda STKPCL,s ; pointer to byte after signature |
||
257 | 2829 F8AF8B 85 51 sta COPPtr |
||
258 | 2830 F8AF8D 1A inc a ; update return address |
||
259 | 2831 F8AF8E 83 10 sta STKPCL,s |
||
260 | 2832 F8AF90 A7 51 lda [COPPtr] ; byte after signature: function number # |
||
261 | 2833 F8AF92 AA tax ; X=function number |
||
262 | 2834 F8AF93 ACC08 ; A,M -> 8 bit |
||
263 | 2835 F8AF93 E2 20 sep #PMFLAG |
||
264 | 2836 .LONGA off |
||
265 | 2837 .MNLIST |
||
266 | 2838 F8AF95 E0 04 cpx #MAXFNC |
||
267 | 2839 F8AF97 B0 06 bcs ?10 ; invalid function |
||
268 | 2840 F8AF99 8A txa |
||
269 | 2841 F8AF9A 0A asl a |
||
270 | 2842 F8AF9B AA tax ; function index |
||
271 | 2843 F8AF9C 7C 3F B2 jmp (JMPTBL,x) |
||
272 | 2844 F8AF9F A9 01 ?10: lda #RTC_BADFNC |
||
273 | 2845 F8AFA1 38 sec |
||
274 | 2846 F8AFA2 6B rtl |
||
275 | 2847 |
||
276 | 2848 ; set rtc time |
||
277 | 2849 F8AFA3 rtcsett: |
||
278 | 2850 F8AFA3 A3 0B lda STKXR,s ; X=seconds |
||
279 | 2851 F8AFA5 AA tax |
||
280 | 2852 F8AFA6 A3 09 lda STKYR,s ; Y=minutes |
||
281 | 2853 F8AFA8 A8 tay |
||
282 | 2854 F8AFA9 A3 0D lda STKCR,s ; A=hours |
||
283 | 2855 F8AFAB 20 DC B0 jsr chktim ; check if valid time |
||
284 | 2856 F8AFAE 90 04 bcc ?10 |
||
285 | 2857 F8AFB0 A9 02 lda #RTC_BADTIME ; return error |
||
286 | 2858 F8AFB2 38 sec |
||
287 | 2859 F8AFB3 6B rtl |
||
288 | 2860 F8AFB4 EB ?10: xba ; B=hours |
||
289 | 2861 F8AFB5 A9 0B lda #RTCCTRLB ; stop time update |
||
290 | 2862 F8AFB7 8D 4C FD sta RTCALE |
||
291 | 2863 F8AFBA A9 80 lda #$80 |
||
292 | 2864 F8AFBC 0C 4D FD tsb RTCDATA |
||
293 | 2865 F8AFBF 9C 4C FD stz RTCALE ; seconds register |
||
294 | 2866 F8AFC2 8E 4D FD stx RTCDATA ; set seconds |
||
295 | 2867 F8AFC5 A9 02 lda #RTCMIN |
||
296 | 2868 F8AFC7 8D 4C FD sta RTCALE |
||
297 | 2869 F8AFCA 8C 4D FD sty RTCDATA ; set minutes |
||
298 | 2870 F8AFCD A9 04 lda #RTCHOURS |
||
299 | 2871 F8AFCF 8D 4C FD sta RTCALE |
||
300 | 2872 F8AFD2 EB xba |
||
301 | 2873 F8AFD3 8D 4D FD sta RTCDATA ; set hours |
||
302 | 2874 F8AFD6 A9 0B lda #RTCCTRLB ; start time update |
||
303 | 2875 F8AFD8 8D 4C FD sta RTCALE |
||
304 | 2876 F8AFDB A9 80 lda #$80 |
||
305 | 2877 F8AFDD 1C 4D FD trb RTCDATA |
||
306 | 2878 F8AFE0 18 clc |
||
307 | 2879 F8AFE1 6B rtl |
||
308 | 2880 |
||
309 | 2881 ; get rtc time |
||
310 | 2882 F8AFE2 rtcgett: |
||
311 | Tue Jul 17 11:00:17 2018 Page 6 |
||
312 | |||
313 | |||
314 | |||
315 | |||
316 | 2883 F8AFE2 78 sei |
||
317 | 2884 F8AFE3 A2 0A ldx #RTCCTRLA ; set bank 1 |
||
318 | 2885 F8AFE5 8E 4C FD stx RTCALE |
||
319 | 2886 F8AFE8 A9 10 lda #$10 |
||
320 | 2887 F8AFEA 0C 4D FD tsb RTCDATA |
||
321 | 2888 F8AFED A2 4A ldx #RTCEXTCTRLA ; check INCR bit 6 |
||
322 | 2889 F8AFEF 8E 4C FD stx RTCALE |
||
323 | 2890 F8AFF2 2C 4D FD ?02: bit RTCDATA |
||
324 | 2891 F8AFF5 70 FB bvs ?02 |
||
325 | 2892 F8AFF7 A2 00 ldx #0 ; seconds |
||
326 | 2893 F8AFF9 8E 4C FD stx RTCALE |
||
327 | 2894 F8AFFC AD 4D FD lda RTCDATA |
||
328 | 2895 F8AFFF 83 0B sta STKXR,s |
||
329 | 2896 F8B001 E8 inx |
||
330 | 2897 F8B002 E8 inx |
||
331 | 2898 F8B003 8E 4C FD stx RTCALE ; minutes |
||
332 | 2899 F8B006 AD 4D FD lda RTCDATA |
||
333 | 2900 F8B009 83 09 sta STKYR,s |
||
334 | 2901 F8B00B E8 inx |
||
335 | 2902 F8B00C E8 inx |
||
336 | 2903 F8B00D 8E 4C FD stx RTCALE ; hours |
||
337 | 2904 F8B010 AD 4D FD lda RTCDATA |
||
338 | 2905 F8B013 83 0D sta STKCR,s |
||
339 | 2906 F8B015 E8 inx |
||
340 | 2907 F8B016 E8 inx |
||
341 | 2908 F8B017 8E 4C FD stx RTCALE ; day of week |
||
342 | 2909 F8B01A AD 4D FD lda RTCDATA |
||
343 | 2910 F8B01D 83 0E sta STKCR+1,s |
||
344 | 2911 F8B01F 58 cli |
||
345 | 2912 F8B020 18 clc |
||
346 | 2913 F8B021 6B rtl |
||
347 | 2914 |
||
348 | 2915 ; get rtc date |
||
349 | 2916 F8B022 rtcgetd: |
||
350 | 2917 F8B022 78 sei |
||
351 | 2918 F8B023 A2 0A ldx #RTCCTRLA ; set bank 1 |
||
352 | 2919 F8B025 8E 4C FD stx RTCALE |
||
353 | 2920 F8B028 A9 10 lda #$10 |
||
354 | 2921 F8B02A 0C 4D FD tsb RTCDATA |
||
355 | 2922 F8B02D A2 4A ldx #RTCEXTCTRLA ; check INCR bit 6 |
||
356 | 2923 F8B02F 8E 4C FD stx RTCALE |
||
357 | 2924 F8B032 2C 4D FD ?02: bit RTCDATA |
||
358 | 2925 F8B035 70 FB bvs ?02 |
||
359 | 2926 F8B037 A2 07 ldx #RTCDDATE ; day |
||
360 | 2927 F8B039 8E 4C FD stx RTCALE |
||
361 | 2928 F8B03C AD 4D FD lda RTCDATA |
||
362 | 2929 F8B03F 83 0B sta STKXR,s |
||
363 | 2930 F8B041 E8 inx |
||
364 | 2931 F8B042 8E 4C FD stx RTCALE ; month |
||
365 | 2932 F8B045 AD 4D FD lda RTCDATA |
||
366 | 2933 F8B048 83 09 sta STKYR,s |
||
367 | 2934 F8B04A E8 inx |
||
368 | 2935 F8B04B 8E 4C FD stx RTCALE ; year |
||
369 | 2936 F8B04E AD 4D FD lda RTCDATA |
||
370 | 2937 F8B051 83 0D sta STKCR,s |
||
371 | 2938 F8B053 A2 48 ldx #RTCCENTURY |
||
372 | 2939 F8B055 8E 4C FD stx RTCALE ; century |
||
373 | Tue Jul 17 11:00:17 2018 Page 7 |
||
374 | |||
375 | |||
376 | |||
377 | |||
378 | 2940 F8B058 AD 4D FD lda RTCDATA |
||
379 | 2941 F8B05B 83 0E sta STKCR+1,s |
||
380 | 2942 F8B05D 58 cli |
||
381 | 2943 F8B05E 18 clc |
||
382 | 2944 F8B05F 6B rtl |
||
383 | 2945 |
||
384 | 2946 F8B060 rtctest: |
||
385 | 2947 .PUBLIC rtctest |
||
386 | 2948 F8B060 0B phd |
||
387 | 2949 F8B061 F4 00 00 pea #0 |
||
388 | 2950 F8B064 2B pld |
||
389 | 2951 F8B065 20 E7 B0 jsr chkdate |
||
390 | 2952 F8B068 90 06 bcc ?02 |
||
391 | 2953 F8B06A A9 03 lda #RTC_BADDATE ; return error |
||
392 | 2954 F8B06C 38 sec |
||
393 | 2955 F8B06D 2B pld |
||
394 | 2956 F8B06E 00 00 brk |
||
395 | 2957 F8B070 20 27 B1 ?02: jsr getdayw ; get day of week |
||
396 | 2958 F8B073 20 91 B1 jsr getlmt |
||
397 | 2959 F8B076 A6 AA ldx date1 |
||
398 | 2960 F8B078 A4 AC ldy date2 |
||
399 | 2961 F8B07A 18 clc |
||
400 | 2962 F8B07B 2B pld |
||
401 | 2963 F8B07C 00 00 brk |
||
402 | 2964 |
||
403 | 2965 F8B07E rtcsetd: |
||
404 | 2966 F8B07E A3 0B lda STKXR,s ; X=date (day of month) |
||
405 | 2967 F8B080 AA tax |
||
406 | 2968 F8B081 A3 09 lda STKYR,s ; Y=month |
||
407 | 2969 F8B083 A8 tay |
||
408 | 2970 F8B084 A3 0E lda STKCR+1,s ; B=century |
||
409 | 2971 F8B086 EB xba |
||
410 | 2972 F8B087 A3 0D lda STKCR,s ; A=year |
||
411 | 2973 F8B089 20 E7 B0 jsr chkdate |
||
412 | 2974 F8B08C 90 04 bcc ?02 |
||
413 | 2975 F8B08E A9 03 lda #RTC_BADDATE ; return error |
||
414 | 2976 F8B090 38 sec |
||
415 | 2977 F8B091 6B rtl |
||
416 | 2978 F8B092 20 27 B1 ?02: jsr getdayw ; get day of week |
||
417 | 2979 F8B095 78 sei |
||
418 | 2980 F8B096 A2 0A ldx #RTCCTRLA ; set bank 1 |
||
419 | 2981 F8B098 8E 4C FD stx RTCALE |
||
420 | 2982 F8B09B A9 10 lda #$10 |
||
421 | 2983 F8B09D 0C 4D FD tsb RTCDATA |
||
422 | 2984 F8B0A0 A9 0B lda #RTCCTRLB ; stop time update |
||
423 | 2985 F8B0A2 8D 4C FD sta RTCALE |
||
424 | 2986 F8B0A5 A9 80 lda #$80 |
||
425 | 2987 F8B0A7 0C 4D FD tsb RTCDATA |
||
426 | 2988 F8B0AA A2 06 ldx #RTCDAY ; day of week |
||
427 | 2989 F8B0AC 8E 4C FD stx RTCALE |
||
428 | 2990 F8B0AF A5 AE lda dayofw |
||
429 | 2991 F8B0B1 8D 4D FD sta RTCDATA |
||
430 | 2992 F8B0B4 E8 inx |
||
431 | 2993 F8B0B5 8E 4C FD stx RTCALE ; date (day of week) |
||
432 | 2994 F8B0B8 A5 AF lda date |
||
433 | 2995 F8B0BA 8D 4D FD sta RTCDATA |
||
434 | 2996 F8B0BD E8 inx |
||
435 | Tue Jul 17 11:00:17 2018 Page 8 |
||
436 | |||
437 | |||
438 | |||
439 | |||
440 | 2997 F8B0BE 8E 4C FD stx RTCALE ; month |
||
441 | 2998 F8B0C1 A5 B0 lda month |
||
442 | 2999 F8B0C3 8D 4D FD sta RTCDATA |
||
443 | 3000 F8B0C6 E8 inx |
||
444 | 3001 F8B0C7 8E 4C FD stx RTCALE ; year |
||
445 | 3002 F8B0CA A5 B1 lda year |
||
446 | 3003 F8B0CC 8D 4D FD sta RTCDATA |
||
447 | 3004 F8B0CF A2 48 ldx #RTCCENTURY |
||
448 | 3005 F8B0D1 8E 4C FD stx RTCALE ; century |
||
449 | 3006 F8B0D4 A5 B2 lda ctry |
||
450 | 3007 F8B0D6 8D 4D FD sta RTCDATA |
||
451 | 3008 F8B0D9 58 cli |
||
452 | 3009 F8B0DA 18 clc |
||
453 | 3010 F8B0DB 6B rtl |
||
454 | 3011 |
||
455 | 3012 ; check time validity |
||
456 | 3013 F8B0DC chktim: |
||
457 | 3014 F8B0DC E0 3C cpx #60 |
||
458 | 3015 F8B0DE B0 06 bcs ?10 |
||
459 | 3016 F8B0E0 C0 3C cpy #60 |
||
460 | 3017 F8B0E2 B0 02 bcs ?10 |
||
461 | 3018 F8B0E4 C9 18 cmp #24 |
||
462 | 3019 F8B0E6 60 ?10: rts ; return CF=1 if invalid time |
||
463 | 3020 |
||
464 | 3021 ; check date validity |
||
465 | 3022 F8B0E7 chkdate: |
||
466 | 3023 F8B0E7 C0 01 cpy #1 ; check month 1..12 |
||
467 | 3024 F8B0E9 B0 02 bcs ?04 |
||
468 | 3025 F8B0EB 38 ?02: sec |
||
469 | 3026 F8B0EC 60 ?03: rts |
||
470 | 3027 F8B0ED C0 0D ?04: cpy #13 |
||
471 | 3028 F8B0EF B0 FB bcs ?03 |
||
472 | 3029 F8B0F1 84 B0 sty month |
||
473 | 3030 F8B0F3 EB xba ; check century |
||
474 | 3031 F8B0F4 C9 64 cmp #100 |
||
475 | 3032 F8B0F6 B0 F4 bcs ?03 |
||
476 | 3033 F8B0F8 85 B2 sta ctry |
||
477 | 3034 F8B0FA EB xba |
||
478 | 3035 F8B0FB C9 64 cmp #100 ; check year |
||
479 | 3036 F8B0FD B0 ED bcs ?03 |
||
480 | 3037 F8B0FF 85 B1 sta year |
||
481 | 3038 F8B101 E0 01 cpx #1 ; check date (day of month) |
||
482 | 3039 F8B103 90 E6 bcc ?02 |
||
483 | 3040 F8B105 86 AF stx date |
||
484 | 3041 F8B107 A2 0B ldx #11 ; build month's array |
||
485 | 3042 F8B109 BF 47 B2 F8 ?05: lda >MDAYTBL,x ; max. days |
||
486 | 3043 F8B10D 95 94 sta dmonth,x |
||
487 | 3044 F8B10F CA dex |
||
488 | 3045 F8B110 10 F7 bpl ?05 |
||
489 | 3046 F8B112 A5 B1 lda year ; century start? |
||
490 | 3047 F8B114 D0 02 bne ?06 ; no...so check if year divisible by 4 |
||
491 | 3048 F8B116 A5 B2 lda ctry ; check if century is divisible by 4 |
||
492 | 3049 F8B118 29 03 ?06: and #$03 ; year/century divisible by 4? |
||
493 | 3050 F8B11A D0 02 bne ?08 ; no...so no leap year |
||
494 | 3051 F8B11C E6 95 inc dmonth+1 ; leap year so february have 29 days |
||
495 | 3052 F8B11E 88 ?08: dey ; month zero based |
||
496 | 3053 F8B11F B6 94 ldx dmonth,y |
||
497 | Tue Jul 17 11:00:17 2018 Page 9 |
||
498 | |||
499 | |||
500 | |||
501 | |||
502 | 3054 F8B121 E4 AF cpx date |
||
503 | 3055 F8B123 90 C6 bcc ?02 ; over month limit |
||
504 | 3056 F8B125 18 clc |
||
505 | 3057 F8B126 60 rts |
||
506 | 3058 |
||
507 | 3059 F8B127 getdayw: |
||
508 | 3060 F8B127 20 F4 B1 jsr fyear |
||
509 | 3061 F8B12A CPU16 |
||
510 | 3062 F8B12A C2 30 rep #(PMFLAG.OR.PXFLAG) |
||
511 | 3063 .LONGA on |
||
512 | 3064 .LONGI on |
||
513 | 3065 .MNLIST |
||
514 | 3066 F8B12C A9 90 01 lda #400 |
||
515 | 3067 F8B12F 85 A6 sta dvsor |
||
516 | 3068 F8B131 A5 A0 lda cyear |
||
517 | 3069 F8B133 20 18 B2 jsr fudiv ; year / 400 |
||
518 | 3070 F8B136 85 A2 sta ty400 |
||
519 | 3071 F8B138 A9 64 00 lda #100 |
||
520 | 3072 F8B13B 85 A6 sta dvsor |
||
521 | 3073 F8B13D A5 A0 lda cyear |
||
522 | 3074 F8B13F 20 18 B2 jsr fudiv ; year / 100 |
||
523 | 3075 F8B142 85 A4 sta ty100 |
||
524 | 3076 F8B144 A5 A0 lda cyear |
||
525 | 3077 F8B146 4A lsr a ; year / 4 |
||
526 | 3078 F8B147 4A lsr a |
||
527 | 3079 F8B148 18 clc |
||
528 | 3080 F8B149 69 23 00 adc #35 |
||
529 | 3081 F8B14C 18 clc |
||
530 | 3082 F8B14D 65 A0 adc cyear ; add year |
||
531 | 3083 F8B14F 18 clc |
||
532 | 3084 F8B150 65 A2 adc ty400 ; add (year / 400) |
||
533 | 3085 F8B152 38 sec |
||
534 | 3086 F8B153 E5 A4 sbc ty100 ; subtract (year / 100) |
||
535 | 3087 F8B155 A2 07 00 ldx #7 |
||
536 | 3088 F8B158 86 A6 stx dvsor |
||
537 | 3089 F8B15A 20 18 B2 jsr fudiv ; divide by 7...remainder is the first day |
||
538 | 3090 F8B15D CPU08 |
||
539 | 3091 F8B15D E2 30 sep #(PMFLAG.OR.PXFLAG) |
||
540 | 3092 .LONGA off |
||
541 | 3093 .LONGI off |
||
542 | 3094 .MNLIST |
||
543 | 3095 F8B15F 98 tya ; first day of the year |
||
544 | 3096 F8B160 85 B3 sta jan1 ; save for later use |
||
545 | 3097 F8B162 18 clc |
||
546 | 3098 F8B163 65 AF adc date ; add current date |
||
547 | 3099 F8B165 3A dec a ; day number (0 based) |
||
548 | 3100 F8B166 A0 00 ldy #0 ; hi byte |
||
549 | 3101 F8B168 A6 B0 ldx month ; add days |
||
550 | 3102 F8B16A CA dex |
||
551 | 3103 F8B16B F0 0A beq ?10 ; january...so nothing to add |
||
552 | 3104 F8B16D CA dex |
||
553 | 3105 F8B16E 18 ?06: clc |
||
554 | 3106 F8B16F 75 94 adc dmonth,x ; add days till previous month |
||
555 | 3107 F8B171 90 01 bcc ?08 |
||
556 | 3108 F8B173 C8 iny |
||
557 | 3109 F8B174 CA ?08: dex |
||
558 | 3110 F8B175 10 F7 bpl ?06 |
||
559 | Tue Jul 17 11:00:17 2018 Page 10 |
||
560 | |||
561 | |||
562 | |||
563 | |||
564 | 3111 F8B177 EB ?10: xba |
||
565 | 3112 F8B178 98 tya |
||
566 | 3113 F8B179 EB xba |
||
567 | 3114 F8B17A CPU16 |
||
568 | 3115 F8B17A C2 30 rep #(PMFLAG.OR.PXFLAG) |
||
569 | 3116 .LONGA on |
||
570 | 3117 .LONGI on |
||
571 | 3118 .MNLIST |
||
572 | 3119 F8B17C A2 07 00 ldx #7 |
||
573 | 3120 F8B17F 86 A6 stx dvsor |
||
574 | 3121 F8B181 20 18 B2 jsr fudiv ; Y -> 0 = monday .. 6 = sunday |
||
575 | 3122 F8B184 CPU08 |
||
576 | 3123 F8B184 E2 30 sep #(PMFLAG.OR.PXFLAG) |
||
577 | 3124 .LONGA off |
||
578 | 3125 .LONGI off |
||
579 | 3126 .MNLIST |
||
580 | 3127 F8B186 C8 iny |
||
581 | 3128 F8B187 C0 07 cpy #7 ; sunday ? |
||
582 | 3129 F8B189 D0 02 bne ?15 ; no |
||
583 | 3130 F8B18B A0 00 ldy #0 ; yes |
||
584 | 3131 F8B18D C8 ?15: iny |
||
585 | 3132 F8B18E 84 AE sty dayofw ; 1=sunday..7=saturday |
||
586 | 3133 F8B190 60 rts |
||
587 | 3134 |
||
588 | 3135 F8B191 getlmt: |
||
589 | 3136 F8B191 A9 00 lda #0 |
||
590 | 3137 F8B193 EB xba |
||
591 | 3138 F8B194 A5 B3 lda jan1 |
||
592 | 3139 F8B196 18 clc |
||
593 | 3140 F8B197 65 94 adc dmonth ; get march, 31 |
||
594 | 3141 F8B199 65 95 adc dmonth+1 |
||
595 | 3142 F8B19B 65 96 adc dmonth+2 |
||
596 | 3143 F8B19D 3A dec a |
||
597 | 3144 F8B19E CPU16 |
||
598 | 3145 F8B19E C2 30 rep #(PMFLAG.OR.PXFLAG) |
||
599 | 3146 .LONGA on |
||
600 | 3147 .LONGI on |
||
601 | 3148 .MNLIST |
||
602 | 3149 F8B1A0 A2 07 00 ldx #7 |
||
603 | 3150 F8B1A3 86 A6 stx dvsor |
||
604 | 3151 F8B1A5 20 18 B2 jsr fudiv ; Y -> 0 = monday .. 6 = sunday |
||
605 | 3152 F8B1A8 CPU08 |
||
606 | 3153 F8B1A8 E2 30 sep #(PMFLAG.OR.PXFLAG) |
||
607 | 3154 .LONGA off |
||
608 | 3155 .LONGI off |
||
609 | 3156 .MNLIST |
||
610 | 3157 F8B1AA A9 1F lda #31 |
||
611 | 3158 F8B1AC C0 06 cpy #6 ; sunday? |
||
612 | 3159 F8B1AE F0 04 beq ?10 ; yes, found first limit |
||
613 | 3160 F8B1B0 3A ?05: dec a ; back one day |
||
614 | 3161 F8B1B1 88 dey |
||
615 | 3162 F8B1B2 10 FC bpl ?05 ; till previous monday |
||
616 | 3163 F8B1B4 85 AA ?10: sta date1 ; last march sunday |
||
617 | 3164 F8B1B6 A9 03 lda #3 |
||
618 | 3165 F8B1B8 85 AB sta date1+1 |
||
619 | 3166 F8B1BA A9 00 lda #0 |
||
620 | 3167 F8B1BC EB xba |
||
621 | Tue Jul 17 11:00:17 2018 Page 11 |
||
622 | |||
623 | |||
624 | |||
625 | |||
626 | 3168 F8B1BD A5 95 lda dmonth+1 ; get october, 31 |
||
627 | 3169 F8B1BF 18 clc |
||
628 | 3170 F8B1C0 65 B3 adc jan1 |
||
629 | 3171 F8B1C2 CPU16CLC |
||
630 | 3172 F8B1C2 C2 31 rep #(PMFLAG.OR.PXFLAG.OR.PCFLAG) |
||
631 | 3173 .LONGA on |
||
632 | 3174 .LONGI on |
||
633 | 3175 .MNLIST |
||
634 | 3176 F8B1C4 69 14 01 adc #276 |
||
635 | 3177 F8B1C7 3A dec a |
||
636 | 3178 F8B1C8 A2 07 00 ldx #7 |
||
637 | 3179 F8B1CB 86 A6 stx dvsor |
||
638 | 3180 F8B1CD 20 18 B2 jsr fudiv ; Y -> 0 = monday .. 6 = sunday |
||
639 | 3181 F8B1D0 CPU08 |
||
640 | 3182 F8B1D0 E2 30 sep #(PMFLAG.OR.PXFLAG) |
||
641 | 3183 .LONGA off |
||
642 | 3184 .LONGI off |
||
643 | 3185 .MNLIST |
||
644 | 3186 F8B1D2 A9 1F lda #31 |
||
645 | 3187 F8B1D4 C0 06 cpy #6 ; sunday? |
||
646 | 3188 F8B1D6 F0 04 beq ?20 ; yes, found first limit |
||
647 | 3189 F8B1D8 3A ?15: dec a ; back one day |
||
648 | 3190 F8B1D9 88 dey |
||
649 | 3191 F8B1DA 10 FC bpl ?15 ; till previous monday |
||
650 | 3192 F8B1DC 85 AC ?20: sta date2 ; last october sunday |
||
651 | 3193 F8B1DE A9 0A lda #10 |
||
652 | 3194 F8B1E0 85 AD sta date2+1 |
||
653 | 3195 F8B1E2 ACC16 |
||
654 | 3196 F8B1E2 C2 20 rep #PMFLAG |
||
655 | 3197 .LONGA on |
||
656 | 3198 .MNLIST |
||
657 | 3199 F8B1E4 A2 00 ldx #0 ; not in DST range |
||
658 | 3200 F8B1E6 A5 AF lda date ; check if date is the DST range |
||
659 | 3201 F8B1E8 C5 AA cmp date1 |
||
660 | 3202 F8B1EA 90 05 bcc ?25 ; not in DST |
||
661 | 3203 F8B1EC C5 AC cmp date2 |
||
662 | 3204 F8B1EE B0 01 bcs ?25 ; not in DST |
||
663 | 3205 F8B1F0 CA dex ; DST time |
||
664 | 3206 ?25: ;stx dstfg |
||
665 | 3207 F8B1F1 ACC08 |
||
666 | 3208 F8B1F1 E2 20 sep #PMFLAG |
||
667 | 3209 .LONGA off |
||
668 | 3210 .MNLIST |
||
669 | 3211 F8B1F3 60 rts |
||
670 | 3212 F8B1F4 |
||
671 | 3213 ; get full year - 1 |
||
672 | 3214 F8B1F4 fyear: |
||
673 | 3215 F8B1F4 A5 B1 lda year |
||
674 | 3216 F8B1F6 85 A4 sta ty100 |
||
675 | 3217 F8B1F8 64 A5 stz ty100+1 |
||
676 | 3218 F8B1FA A5 B2 lda ctry |
||
677 | 3219 F8B1FC 85 A0 sta cyear |
||
678 | 3220 F8B1FE 64 A1 stz cyear+1 |
||
679 | 3221 F8B200 ACC16 |
||
680 | 3222 F8B200 C2 20 rep #PMFLAG |
||
681 | 3223 .LONGA on |
||
682 | 3224 .MNLIST |
||
683 | Tue Jul 17 11:00:17 2018 Page 12 |
||
684 | |||
685 | |||
686 | |||
687 | |||
688 | 3225 F8B202 A5 A0 lda cyear |
||
689 | 3226 F8B204 0A asl a ; x 4 |
||
690 | 3227 F8B205 0A asl a |
||
691 | 3228 F8B206 65 A0 adc cyear ; x 5 |
||
692 | 3229 F8B208 0A asl a ; x 10 |
||
693 | 3230 F8B209 85 A0 sta cyear |
||
694 | 3231 F8B20B 0A asl a ; x 40 |
||
695 | 3232 F8B20C 0A asl a |
||
696 | 3233 F8B20D 65 A0 adc cyear ; x 50 |
||
697 | 3234 F8B20F 0A asl a ; x 100 |
||
698 | 3235 F8B210 65 A4 adc ty100 |
||
699 | 3236 F8B212 3A dec a |
||
700 | 3237 F8B213 85 A0 sta cyear |
||
701 | 3238 F8B215 ACC08 |
||
702 | 3239 F8B215 E2 20 sep #PMFLAG |
||
703 | 3240 .LONGA off |
||
704 | 3241 .MNLIST |
||
705 | 3242 F8B217 60 rts |
||
706 | 3243 |
||
707 | 3244 ; fast unsigned division 16 bit |
||
708 | 3245 ; |
||
709 | 3246 ; entry: C = 16 bit dividend |
||
710 | 3247 ; dvsor = 16 bit divisor |
||
711 | 3248 ; |
||
712 | 3249 ; exit: C = 16 bit quotient |
||
713 | 3250 ; Y = dvsor = 16 bit remainder |
||
714 | 3251 ; |
||
715 | 3252 ; use: all |
||
716 | 3253 ; |
||
717 | 3254 ; note: no check for null divisor |
||
718 | 3255 ; must be called with cpu in 16 bit mode |
||
719 | 3256 ; |
||
720 | 3257 ;----- |
||
721 | 3258 F8B218 fudiv: |
||
722 | 3259 ;----- |
||
723 | 3260 .LONGA on |
||
724 | 3261 .LONGI on |
||
725 | 3262 |
||
726 | 3263 F8B218 A2 01 00 ldx #1 ; bit counter |
||
727 | 3264 F8B21B A8 tay ; Y=dividend |
||
728 | 3265 F8B21C 64 A8 stz quot ; init quotient |
||
729 | 3266 F8B21E A5 A6 lda dvsor ; C=divisor |
||
730 | 3267 F8B220 0A ?10: asl a ; shift divisor: get leftmost bit |
||
731 | 3268 F8B221 B0 06 bcs ?20 ; go to division |
||
732 | 3269 F8B223 E8 inx |
||
733 | 3270 F8B224 E0 11 00 cpx #17 ; test all divisor bit's |
||
734 | 3271 F8B227 D0 F7 bne ?10 |
||
735 | 3272 F8B229 6A ?20: ror a ; put shifted-out bit back |
||
736 | 3273 F8B22A 85 A6 sta dvsor |
||
737 | 3274 F8B22C 98 ?30: tya ; get dividend |
||
738 | 3275 F8B22D 38 sec |
||
739 | 3276 F8B22E E5 A6 sbc dvsor |
||
740 | 3277 F8B230 90 01 bcc ?40 ; can't subctract, retain old dividend |
||
741 | 3278 F8B232 A8 tay ; Y=new dividend |
||
742 | 3279 F8B233 26 A8 ?40: rol quot ; shift carry into quotient (1 if division) |
||
743 | 3280 F8B235 46 A6 lsr dvsor ; shift right divisor for next subtract |
||
744 | 3281 F8B237 CA dex |
||
745 | Tue Jul 17 11:00:17 2018 Page 13 |
||
746 | |||
747 | |||
748 | |||
749 | |||
750 | 3282 F8B238 D0 F2 bne ?30 |
||
751 | 3283 F8B23A 84 A6 sty dvsor ; remainder |
||
752 | 3284 F8B23C A5 A8 lda quot ; C=quotient |
||
753 | 3285 F8B23E 60 rts |
||
754 | 3286 F8B23F |
||
755 | 3287 ;--------------------------------------------------------------------------- |
||
756 | 3288 ; tables |
||
757 | 3289 ;--------------------------------------------------------------------------- |
||
758 | 3290 |
||
759 | 3291 ; rtc function's jump table |
||
760 | 3292 F8B23F JMPTBL: |
||
761 | 3293 F8B23F A3AF 7EB0 E2AF .DW rtcsett, rtcsetd, rtcgett, rtcgetd |
||
762 | 22B0 |
||
763 | 3294 |
||
764 | 3295 ; month's table |
||
765 | 3296 F8B247 MDAYTBL: |
||
766 | 3297 F8B247 1F 1C 1F 1E 1F .DB 31,28,31,30,31,30,31,31,30,31,30,31 |
||
767 | 1E 1F 1F 1E 1F |
||
768 | 1E 1F |
||
769 | |||
770 | |||
771 | Lines Assembled : 3237 Errors : 0 |
||
772 | |||
773 | |||
774 |