Blame | Last modification | View Log | Download | RSS feed
Tue Jul 17 11:00:17 2018 Page 1
2500 A.D. 65816 Macro Assembler #26960 - Version 5.02g
-----------------------------------------------------
Input Filename : src\F8\rtc.asm
Output Filename : obj\F8\rtc.obj
Listing Has Been Relocated
2606 .LIST on
2607
2608 F8FFB1 .INCLUDE inc\dirp00.inc
2609 ;----------------------------------------------------------
2610 ; DIRP00.ASM
2611 ; PROGETTO: B1601
2612 ;
2613 ; Variabili in Direct Page $00
2614 ;----------------------------------------------------------
2615
2616 ; sezione COMMON -- questo permette di includere il file in piu' file
2617
2618 .LIST on
2619
2620 DIRP00: .SECTION page0, ref_only, common ;Direct-Page 00
2621
2622 000000 .ABSOLUTE ;; inizia sempre da $00
2623 000000 .ORG 0x00
2624 000000
2625 000000 0000 JiffyClk .DW ; contatore 10ms 32 bit
2626 000002 0000 .DW
2627 000004 SysTmr .DS SYSTMRCNT ; system timer 0 (10ms)
2628 000008 SysTMF .DS SYSTMRCNT ; flag timer (80 -> start)
2629 00000C 00 Bnk0Flag .DB ; <7>: flag test RAM banco 0 ok
2630 ; <6>: flag warm reset
2631 00000D 00 RTCFlag .DB
2632
2633 00000E diskstat .DS 2 ; flag device on ata bus #0 & #1
2634 ; <7>: device ready
2635 ; <6>: compact flash device (C.F.)
2636 ; <5>: device identification ok
2637 ; <4>: MBR loaded
2638 ; <3>: valid signature in MBR
2639 ; <2>: first partition found&active
2640 ; <1>:
2641 ; <0>: valid partition flag
2642
2643 ; <7>: device ready
2644 ; <6>: USB device
2645 ; <5>: compact flash device (C.F.)
2646 ; <4>: device identification ok
2647 ; <3>: MBR loaded
2648 ; <2>: first partition found&active
2649 ; <1>: always 1
2650 ; <0>: valid partition flag
2651 000010
Tue Jul 17 11:00:17 2018 Page 2
2652
2653 00000E atadev .EQU diskstat
2654
2655 000010 usbdev .DS 2 ; flag flash disk on usb bus #0
2656 ; <7>: device plugged and ready
2657 ; <6>: always 1
2658 ; <5>: device identification ok
2659 ; <4>: MBR loaded
2660 ; <3>: valid signature in MBR
2661 ; <2>: first partition found&active
2662 ; <1>:
2663 ; <0>: valid partition flag
2664
2665 000012 diskmax .DS 16 ; disk max. sector's
2666 000012 atasec .EQU diskmax
2667 00001A usbsec .EQU diskmax+8
2668
2669
2670 000022 atambr .DS 8 ; data for first partition found in mbr
2671 ; first 3 bytes for start sector of partition
2672 ; last byte for partition type
2673 00002A usbmbr .DS 8
2674
2675 000032 ataprt .DS 8 ; total sec's of first partition
2676 00003A usbprt .DS 8 ; total sec's of first partition
2677
2678
2679 000042 00 usb0ch .DB ; usb0 (ch375/ch376) flag
2680 ; <7>: module on
2681 ; <6>: ch376 flag
2682 ; <5:0>: chip version
2683
2684 000043 00 usb0st .DB ; usb0 status
2685 ; <7>: usb0 host mode ok
2686 ; <6>: flash disk attached flag
2687 ; <5>: usb device attached
2688
2689 000044 00 fdcdrv .DB ; phisycal drive status (drive #0)
2690 ; <7>: disk format established in bit 0&1
2691 ; <6>: double step seek done
2692 ; <5>: trust format bit's (set after ok r/w)
2693 ; <4>: write protect bit (if disk in drive)
2694 ; <3>: don't care
2695 ; <2>: don't care
2696 ; <1>: HD disk if set else DD disk
2697 ; <0>: CBM format if set else IBM format
2698
2699 000045 00 vdrive .DB ; virtual drive status (ram disk, drive #1)
2700 ; <7>: disk format established in bit 0&1
2701 ; <6>: change disk simulation (after format)
2702 ; <5>: don't care
2703 ; <4>: write protect bit (under sw control)
2704 ; <3>: don't care
2705 ; <2>: don't care
2706 ; <1>: HD disk if set else DD disk
2707 ; <0>: CBM format if set else IBM format
2708
Tue Jul 17 11:00:17 2018 Page 3
2709 000046 00 fdcctl .DB ; fdc controller status
2710 ; <7>: drive is attached
2711 ; <6>: drive need recalibration (restore)
2712 ; <5>: FDC controller ok
2713 ; <4>: motor on
2714 ; <3>: dma is active
2715 ; <2>: dma chip ok (post routine)
2716 ; <1>: clock rate (1=HD,0=DD)
2717 ; <0>: disk ready
2718
2719 000047 00 fdctrk .DB ; fd: current seek track
2720 000048 00 fdcerr .DB ; fd: last error code
2721 000049 00 ataerr .DB ; ata: last error code
2722 00004A 00 ataxer .DB ; ata: last extended error code
2723
2724 00004B 00 CtrlBrk .DB ; flag CTRL+BREAK (NMI)
2725
2726 00004C 0000 MemTop .DW ; top memoria RAM
2727 00004E 00 .DB ; banco top mem
2728
2729 00004F 00 DflTxtIn .DB ; device di default text input
2730 000050 00 DflTxtOut .DB ; device di default text output
2731
2732 000051 COPPtr LP ; long pointer for COP decoding
2733 000054 00 COPIdx .DB ; COP signature/index
2734
2735 000055 00 BiosEnt .DB ; flag accesso a bios setup
2736
2737 ; variabili utilizzate da ACIA
2738 000056 spwrk .DS $30
2739
2740 ; bios mem
2741 000086 0000 nsize .DW ; dimensione blocco da allocare
2742 ;bsize .DW ; dimensione vera blocco free
2743 000088 0000 splitsz .DW ; dimensione blocco splittato
2744 00008A 0000 bfree .DW ; puntatore blocco free
2745 00008C 0000 hdrptr .DW ; puntatore header heap
2746
2747 00008E 0000 pbrklv .DW ; current break level of current process
2748 000090 0000 pbrkmin .DW ; minimum breal level of current process
2749 000092 0000 pbrkmax .DW ; maximum breal level of current process
2750 000094
2751 ; bios temp. work area
2752 000094 bwrktmp .DS $28
2753
2754 0000BC 00 coptmp .DB ; temp. used while cop
2755
2756 0000BD 00 tstser .DB ; check ser/usb test board post
2757 ; <7>: VIA2 ok
2758 ; <6>: PICRAM ok
2759 ; <1>: UART 16C550 ok
2760 ; <0>: R65C51 ok
2761
2762
2763 ;crc16 .DW
2764
2765 0000BD .RELATIVE
Tue Jul 17 11:00:17 2018 Page 4
2766
2767 .ENDS
2768
2769 [01] .IFDEF _ACIA_INC_
2770 .INCLUDE INC\SP.INC
2771 [00] .ENDIF
2772
2776 .LIST on
2777
2778 000004 MAXFNC .EQU 4
2779
2780 ; page 0 local var's (declared in bios temp. work area)
2781 _P0BTMP: .SECTION page0, ref_only, offset bwrktmp ; DP Tmp. BIOS
2782
2783 000094 dmonth .DS 12 ; array of month's day's
2784 0000A0 0000 cyear .DW ; full year - 1
2785 0000A2 0000 ty400 .DW ; full year / 400
2786 0000A4 0000 ty100 .DW ; full year / 100
2787 0000A6 0000 dvsor .DW ; divisor/remainder
2788 0000A8 0000 quot .DW ; quotient
2789 0000AA 0000 date1 .DW ; last march sunday
2790 0000AC 0000 date2 .DW ; last october sunday
2791 0000AE 00 dayofw .DB ; day of week (1=sunday...)
2792 0000AF 00 date .DB ; date (day of month)
2793 0000B0 00 month .DB
2794 0000B1 00 year .DB
2795 0000B2 00 ctry .DB ; century
2796 0000B3 00 jan1 .DB ; first day of the year
2797
2798 .ENDS
2799
2800 .CODEF8
2801
2802 .LONGA off
2803 .LONGI off
2804
2805 ;---------------------------------------------------------------------------
2806 ; system call interface
2807 ;---------------------------------------------------------------------------
2808
2809 ; handle real time clock
2810 ;
2811 ; functions:
2812 ;
2813 ; $00: set time (X=seconds, Y=minutes, A=hours)
2814 ; $01: set date (X=day, Y=month, A=year, B=century)
2815 ; ?02: get time (X=seconds, Y=minutes, A=hours, B=day of week)
2816 ; $03: get date (X=day, Y=month, A=year, B=century)
2817 ;
2818 F8AF83 sys_rtc:
2819 F8AF83
2820 .PUBLIC sys_rtc
2821
2822 F8AF83 A3 12 lda STKPBR,s ; bank where was executed cop instruction
2823 F8AF85 85 53 sta COPPtr+2
2824 F8AF87 ACC16 ; retrieve function number
2825 F8AF87 C2 20 rep #PMFLAG
Tue Jul 17 11:00:17 2018 Page 5
2826 .LONGA on
2827 .MNLIST
2828 F8AF89 A3 10 lda STKPCL,s ; pointer to byte after signature
2829 F8AF8B 85 51 sta COPPtr
2830 F8AF8D 1A inc a ; update return address
2831 F8AF8E 83 10 sta STKPCL,s
2832 F8AF90 A7 51 lda [COPPtr] ; byte after signature: function number #
2833 F8AF92 AA tax ; X=function number
2834 F8AF93 ACC08 ; A,M -> 8 bit
2835 F8AF93 E2 20 sep #PMFLAG
2836 .LONGA off
2837 .MNLIST
2838 F8AF95 E0 04 cpx #MAXFNC
2839 F8AF97 B0 06 bcs ?10 ; invalid function
2840 F8AF99 8A txa
2841 F8AF9A 0A asl a
2842 F8AF9B AA tax ; function index
2843 F8AF9C 7C 3F B2 jmp (JMPTBL,x)
2844 F8AF9F A9 01 ?10: lda #RTC_BADFNC
2845 F8AFA1 38 sec
2846 F8AFA2 6B rtl
2847
2848 ; set rtc time
2849 F8AFA3 rtcsett:
2850 F8AFA3 A3 0B lda STKXR,s ; X=seconds
2851 F8AFA5 AA tax
2852 F8AFA6 A3 09 lda STKYR,s ; Y=minutes
2853 F8AFA8 A8 tay
2854 F8AFA9 A3 0D lda STKCR,s ; A=hours
2855 F8AFAB 20 DC B0 jsr chktim ; check if valid time
2856 F8AFAE 90 04 bcc ?10
2857 F8AFB0 A9 02 lda #RTC_BADTIME ; return error
2858 F8AFB2 38 sec
2859 F8AFB3 6B rtl
2860 F8AFB4 EB ?10: xba ; B=hours
2861 F8AFB5 A9 0B lda #RTCCTRLB ; stop time update
2862 F8AFB7 8D 4C FD sta RTCALE
2863 F8AFBA A9 80 lda #$80
2864 F8AFBC 0C 4D FD tsb RTCDATA
2865 F8AFBF 9C 4C FD stz RTCALE ; seconds register
2866 F8AFC2 8E 4D FD stx RTCDATA ; set seconds
2867 F8AFC5 A9 02 lda #RTCMIN
2868 F8AFC7 8D 4C FD sta RTCALE
2869 F8AFCA 8C 4D FD sty RTCDATA ; set minutes
2870 F8AFCD A9 04 lda #RTCHOURS
2871 F8AFCF 8D 4C FD sta RTCALE
2872 F8AFD2 EB xba
2873 F8AFD3 8D 4D FD sta RTCDATA ; set hours
2874 F8AFD6 A9 0B lda #RTCCTRLB ; start time update
2875 F8AFD8 8D 4C FD sta RTCALE
2876 F8AFDB A9 80 lda #$80
2877 F8AFDD 1C 4D FD trb RTCDATA
2878 F8AFE0 18 clc
2879 F8AFE1 6B rtl
2880
2881 ; get rtc time
2882 F8AFE2 rtcgett:
Tue Jul 17 11:00:17 2018 Page 6
2883 F8AFE2 78 sei
2884 F8AFE3 A2 0A ldx #RTCCTRLA ; set bank 1
2885 F8AFE5 8E 4C FD stx RTCALE
2886 F8AFE8 A9 10 lda #$10
2887 F8AFEA 0C 4D FD tsb RTCDATA
2888 F8AFED A2 4A ldx #RTCEXTCTRLA ; check INCR bit 6
2889 F8AFEF 8E 4C FD stx RTCALE
2890 F8AFF2 2C 4D FD ?02: bit RTCDATA
2891 F8AFF5 70 FB bvs ?02
2892 F8AFF7 A2 00 ldx #0 ; seconds
2893 F8AFF9 8E 4C FD stx RTCALE
2894 F8AFFC AD 4D FD lda RTCDATA
2895 F8AFFF 83 0B sta STKXR,s
2896 F8B001 E8 inx
2897 F8B002 E8 inx
2898 F8B003 8E 4C FD stx RTCALE ; minutes
2899 F8B006 AD 4D FD lda RTCDATA
2900 F8B009 83 09 sta STKYR,s
2901 F8B00B E8 inx
2902 F8B00C E8 inx
2903 F8B00D 8E 4C FD stx RTCALE ; hours
2904 F8B010 AD 4D FD lda RTCDATA
2905 F8B013 83 0D sta STKCR,s
2906 F8B015 E8 inx
2907 F8B016 E8 inx
2908 F8B017 8E 4C FD stx RTCALE ; day of week
2909 F8B01A AD 4D FD lda RTCDATA
2910 F8B01D 83 0E sta STKCR+1,s
2911 F8B01F 58 cli
2912 F8B020 18 clc
2913 F8B021 6B rtl
2914
2915 ; get rtc date
2916 F8B022 rtcgetd:
2917 F8B022 78 sei
2918 F8B023 A2 0A ldx #RTCCTRLA ; set bank 1
2919 F8B025 8E 4C FD stx RTCALE
2920 F8B028 A9 10 lda #$10
2921 F8B02A 0C 4D FD tsb RTCDATA
2922 F8B02D A2 4A ldx #RTCEXTCTRLA ; check INCR bit 6
2923 F8B02F 8E 4C FD stx RTCALE
2924 F8B032 2C 4D FD ?02: bit RTCDATA
2925 F8B035 70 FB bvs ?02
2926 F8B037 A2 07 ldx #RTCDDATE ; day
2927 F8B039 8E 4C FD stx RTCALE
2928 F8B03C AD 4D FD lda RTCDATA
2929 F8B03F 83 0B sta STKXR,s
2930 F8B041 E8 inx
2931 F8B042 8E 4C FD stx RTCALE ; month
2932 F8B045 AD 4D FD lda RTCDATA
2933 F8B048 83 09 sta STKYR,s
2934 F8B04A E8 inx
2935 F8B04B 8E 4C FD stx RTCALE ; year
2936 F8B04E AD 4D FD lda RTCDATA
2937 F8B051 83 0D sta STKCR,s
2938 F8B053 A2 48 ldx #RTCCENTURY
2939 F8B055 8E 4C FD stx RTCALE ; century
Tue Jul 17 11:00:17 2018 Page 7
2940 F8B058 AD 4D FD lda RTCDATA
2941 F8B05B 83 0E sta STKCR+1,s
2942 F8B05D 58 cli
2943 F8B05E 18 clc
2944 F8B05F 6B rtl
2945
2946 F8B060 rtctest:
2947 .PUBLIC rtctest
2948 F8B060 0B phd
2949 F8B061 F4 00 00 pea #0
2950 F8B064 2B pld
2951 F8B065 20 E7 B0 jsr chkdate
2952 F8B068 90 06 bcc ?02
2953 F8B06A A9 03 lda #RTC_BADDATE ; return error
2954 F8B06C 38 sec
2955 F8B06D 2B pld
2956 F8B06E 00 00 brk
2957 F8B070 20 27 B1 ?02: jsr getdayw ; get day of week
2958 F8B073 20 91 B1 jsr getlmt
2959 F8B076 A6 AA ldx date1
2960 F8B078 A4 AC ldy date2
2961 F8B07A 18 clc
2962 F8B07B 2B pld
2963 F8B07C 00 00 brk
2964
2965 F8B07E rtcsetd:
2966 F8B07E A3 0B lda STKXR,s ; X=date (day of month)
2967 F8B080 AA tax
2968 F8B081 A3 09 lda STKYR,s ; Y=month
2969 F8B083 A8 tay
2970 F8B084 A3 0E lda STKCR+1,s ; B=century
2971 F8B086 EB xba
2972 F8B087 A3 0D lda STKCR,s ; A=year
2973 F8B089 20 E7 B0 jsr chkdate
2974 F8B08C 90 04 bcc ?02
2975 F8B08E A9 03 lda #RTC_BADDATE ; return error
2976 F8B090 38 sec
2977 F8B091 6B rtl
2978 F8B092 20 27 B1 ?02: jsr getdayw ; get day of week
2979 F8B095 78 sei
2980 F8B096 A2 0A ldx #RTCCTRLA ; set bank 1
2981 F8B098 8E 4C FD stx RTCALE
2982 F8B09B A9 10 lda #$10
2983 F8B09D 0C 4D FD tsb RTCDATA
2984 F8B0A0 A9 0B lda #RTCCTRLB ; stop time update
2985 F8B0A2 8D 4C FD sta RTCALE
2986 F8B0A5 A9 80 lda #$80
2987 F8B0A7 0C 4D FD tsb RTCDATA
2988 F8B0AA A2 06 ldx #RTCDAY ; day of week
2989 F8B0AC 8E 4C FD stx RTCALE
2990 F8B0AF A5 AE lda dayofw
2991 F8B0B1 8D 4D FD sta RTCDATA
2992 F8B0B4 E8 inx
2993 F8B0B5 8E 4C FD stx RTCALE ; date (day of week)
2994 F8B0B8 A5 AF lda date
2995 F8B0BA 8D 4D FD sta RTCDATA
2996 F8B0BD E8 inx
Tue Jul 17 11:00:17 2018 Page 8
2997 F8B0BE 8E 4C FD stx RTCALE ; month
2998 F8B0C1 A5 B0 lda month
2999 F8B0C3 8D 4D FD sta RTCDATA
3000 F8B0C6 E8 inx
3001 F8B0C7 8E 4C FD stx RTCALE ; year
3002 F8B0CA A5 B1 lda year
3003 F8B0CC 8D 4D FD sta RTCDATA
3004 F8B0CF A2 48 ldx #RTCCENTURY
3005 F8B0D1 8E 4C FD stx RTCALE ; century
3006 F8B0D4 A5 B2 lda ctry
3007 F8B0D6 8D 4D FD sta RTCDATA
3008 F8B0D9 58 cli
3009 F8B0DA 18 clc
3010 F8B0DB 6B rtl
3011
3012 ; check time validity
3013 F8B0DC chktim:
3014 F8B0DC E0 3C cpx #60
3015 F8B0DE B0 06 bcs ?10
3016 F8B0E0 C0 3C cpy #60
3017 F8B0E2 B0 02 bcs ?10
3018 F8B0E4 C9 18 cmp #24
3019 F8B0E6 60 ?10: rts ; return CF=1 if invalid time
3020
3021 ; check date validity
3022 F8B0E7 chkdate:
3023 F8B0E7 C0 01 cpy #1 ; check month 1..12
3024 F8B0E9 B0 02 bcs ?04
3025 F8B0EB 38 ?02: sec
3026 F8B0EC 60 ?03: rts
3027 F8B0ED C0 0D ?04: cpy #13
3028 F8B0EF B0 FB bcs ?03
3029 F8B0F1 84 B0 sty month
3030 F8B0F3 EB xba ; check century
3031 F8B0F4 C9 64 cmp #100
3032 F8B0F6 B0 F4 bcs ?03
3033 F8B0F8 85 B2 sta ctry
3034 F8B0FA EB xba
3035 F8B0FB C9 64 cmp #100 ; check year
3036 F8B0FD B0 ED bcs ?03
3037 F8B0FF 85 B1 sta year
3038 F8B101 E0 01 cpx #1 ; check date (day of month)
3039 F8B103 90 E6 bcc ?02
3040 F8B105 86 AF stx date
3041 F8B107 A2 0B ldx #11 ; build month's array
3042 F8B109 BF 47 B2 F8 ?05: lda >MDAYTBL,x ; max. days
3043 F8B10D 95 94 sta dmonth,x
3044 F8B10F CA dex
3045 F8B110 10 F7 bpl ?05
3046 F8B112 A5 B1 lda year ; century start?
3047 F8B114 D0 02 bne ?06 ; no...so check if year divisible by 4
3048 F8B116 A5 B2 lda ctry ; check if century is divisible by 4
3049 F8B118 29 03 ?06: and #$03 ; year/century divisible by 4?
3050 F8B11A D0 02 bne ?08 ; no...so no leap year
3051 F8B11C E6 95 inc dmonth+1 ; leap year so february have 29 days
3052 F8B11E 88 ?08: dey ; month zero based
3053 F8B11F B6 94 ldx dmonth,y
Tue Jul 17 11:00:17 2018 Page 9
3054 F8B121 E4 AF cpx date
3055 F8B123 90 C6 bcc ?02 ; over month limit
3056 F8B125 18 clc
3057 F8B126 60 rts
3058
3059 F8B127 getdayw:
3060 F8B127 20 F4 B1 jsr fyear
3061 F8B12A CPU16
3062 F8B12A C2 30 rep #(PMFLAG.OR.PXFLAG)
3063 .LONGA on
3064 .LONGI on
3065 .MNLIST
3066 F8B12C A9 90 01 lda #400
3067 F8B12F 85 A6 sta dvsor
3068 F8B131 A5 A0 lda cyear
3069 F8B133 20 18 B2 jsr fudiv ; year / 400
3070 F8B136 85 A2 sta ty400
3071 F8B138 A9 64 00 lda #100
3072 F8B13B 85 A6 sta dvsor
3073 F8B13D A5 A0 lda cyear
3074 F8B13F 20 18 B2 jsr fudiv ; year / 100
3075 F8B142 85 A4 sta ty100
3076 F8B144 A5 A0 lda cyear
3077 F8B146 4A lsr a ; year / 4
3078 F8B147 4A lsr a
3079 F8B148 18 clc
3080 F8B149 69 23 00 adc #35
3081 F8B14C 18 clc
3082 F8B14D 65 A0 adc cyear ; add year
3083 F8B14F 18 clc
3084 F8B150 65 A2 adc ty400 ; add (year / 400)
3085 F8B152 38 sec
3086 F8B153 E5 A4 sbc ty100 ; subtract (year / 100)
3087 F8B155 A2 07 00 ldx #7
3088 F8B158 86 A6 stx dvsor
3089 F8B15A 20 18 B2 jsr fudiv ; divide by 7...remainder is the first day
3090 F8B15D CPU08
3091 F8B15D E2 30 sep #(PMFLAG.OR.PXFLAG)
3092 .LONGA off
3093 .LONGI off
3094 .MNLIST
3095 F8B15F 98 tya ; first day of the year
3096 F8B160 85 B3 sta jan1 ; save for later use
3097 F8B162 18 clc
3098 F8B163 65 AF adc date ; add current date
3099 F8B165 3A dec a ; day number (0 based)
3100 F8B166 A0 00 ldy #0 ; hi byte
3101 F8B168 A6 B0 ldx month ; add days
3102 F8B16A CA dex
3103 F8B16B F0 0A beq ?10 ; january...so nothing to add
3104 F8B16D CA dex
3105 F8B16E 18 ?06: clc
3106 F8B16F 75 94 adc dmonth,x ; add days till previous month
3107 F8B171 90 01 bcc ?08
3108 F8B173 C8 iny
3109 F8B174 CA ?08: dex
3110 F8B175 10 F7 bpl ?06
Tue Jul 17 11:00:17 2018 Page 10
3111 F8B177 EB ?10: xba
3112 F8B178 98 tya
3113 F8B179 EB xba
3114 F8B17A CPU16
3115 F8B17A C2 30 rep #(PMFLAG.OR.PXFLAG)
3116 .LONGA on
3117 .LONGI on
3118 .MNLIST
3119 F8B17C A2 07 00 ldx #7
3120 F8B17F 86 A6 stx dvsor
3121 F8B181 20 18 B2 jsr fudiv ; Y -> 0 = monday .. 6 = sunday
3122 F8B184 CPU08
3123 F8B184 E2 30 sep #(PMFLAG.OR.PXFLAG)
3124 .LONGA off
3125 .LONGI off
3126 .MNLIST
3127 F8B186 C8 iny
3128 F8B187 C0 07 cpy #7 ; sunday ?
3129 F8B189 D0 02 bne ?15 ; no
3130 F8B18B A0 00 ldy #0 ; yes
3131 F8B18D C8 ?15: iny
3132 F8B18E 84 AE sty dayofw ; 1=sunday..7=saturday
3133 F8B190 60 rts
3134
3135 F8B191 getlmt:
3136 F8B191 A9 00 lda #0
3137 F8B193 EB xba
3138 F8B194 A5 B3 lda jan1
3139 F8B196 18 clc
3140 F8B197 65 94 adc dmonth ; get march, 31
3141 F8B199 65 95 adc dmonth+1
3142 F8B19B 65 96 adc dmonth+2
3143 F8B19D 3A dec a
3144 F8B19E CPU16
3145 F8B19E C2 30 rep #(PMFLAG.OR.PXFLAG)
3146 .LONGA on
3147 .LONGI on
3148 .MNLIST
3149 F8B1A0 A2 07 00 ldx #7
3150 F8B1A3 86 A6 stx dvsor
3151 F8B1A5 20 18 B2 jsr fudiv ; Y -> 0 = monday .. 6 = sunday
3152 F8B1A8 CPU08
3153 F8B1A8 E2 30 sep #(PMFLAG.OR.PXFLAG)
3154 .LONGA off
3155 .LONGI off
3156 .MNLIST
3157 F8B1AA A9 1F lda #31
3158 F8B1AC C0 06 cpy #6 ; sunday?
3159 F8B1AE F0 04 beq ?10 ; yes, found first limit
3160 F8B1B0 3A ?05: dec a ; back one day
3161 F8B1B1 88 dey
3162 F8B1B2 10 FC bpl ?05 ; till previous monday
3163 F8B1B4 85 AA ?10: sta date1 ; last march sunday
3164 F8B1B6 A9 03 lda #3
3165 F8B1B8 85 AB sta date1+1
3166 F8B1BA A9 00 lda #0
3167 F8B1BC EB xba
Tue Jul 17 11:00:17 2018 Page 11
3168 F8B1BD A5 95 lda dmonth+1 ; get october, 31
3169 F8B1BF 18 clc
3170 F8B1C0 65 B3 adc jan1
3171 F8B1C2 CPU16CLC
3172 F8B1C2 C2 31 rep #(PMFLAG.OR.PXFLAG.OR.PCFLAG)
3173 .LONGA on
3174 .LONGI on
3175 .MNLIST
3176 F8B1C4 69 14 01 adc #276
3177 F8B1C7 3A dec a
3178 F8B1C8 A2 07 00 ldx #7
3179 F8B1CB 86 A6 stx dvsor
3180 F8B1CD 20 18 B2 jsr fudiv ; Y -> 0 = monday .. 6 = sunday
3181 F8B1D0 CPU08
3182 F8B1D0 E2 30 sep #(PMFLAG.OR.PXFLAG)
3183 .LONGA off
3184 .LONGI off
3185 .MNLIST
3186 F8B1D2 A9 1F lda #31
3187 F8B1D4 C0 06 cpy #6 ; sunday?
3188 F8B1D6 F0 04 beq ?20 ; yes, found first limit
3189 F8B1D8 3A ?15: dec a ; back one day
3190 F8B1D9 88 dey
3191 F8B1DA 10 FC bpl ?15 ; till previous monday
3192 F8B1DC 85 AC ?20: sta date2 ; last october sunday
3193 F8B1DE A9 0A lda #10
3194 F8B1E0 85 AD sta date2+1
3195 F8B1E2 ACC16
3196 F8B1E2 C2 20 rep #PMFLAG
3197 .LONGA on
3198 .MNLIST
3199 F8B1E4 A2 00 ldx #0 ; not in DST range
3200 F8B1E6 A5 AF lda date ; check if date is the DST range
3201 F8B1E8 C5 AA cmp date1
3202 F8B1EA 90 05 bcc ?25 ; not in DST
3203 F8B1EC C5 AC cmp date2
3204 F8B1EE B0 01 bcs ?25 ; not in DST
3205 F8B1F0 CA dex ; DST time
3206 ?25: ;stx dstfg
3207 F8B1F1 ACC08
3208 F8B1F1 E2 20 sep #PMFLAG
3209 .LONGA off
3210 .MNLIST
3211 F8B1F3 60 rts
3212 F8B1F4
3213 ; get full year - 1
3214 F8B1F4 fyear:
3215 F8B1F4 A5 B1 lda year
3216 F8B1F6 85 A4 sta ty100
3217 F8B1F8 64 A5 stz ty100+1
3218 F8B1FA A5 B2 lda ctry
3219 F8B1FC 85 A0 sta cyear
3220 F8B1FE 64 A1 stz cyear+1
3221 F8B200 ACC16
3222 F8B200 C2 20 rep #PMFLAG
3223 .LONGA on
3224 .MNLIST
Tue Jul 17 11:00:17 2018 Page 12
3225 F8B202 A5 A0 lda cyear
3226 F8B204 0A asl a ; x 4
3227 F8B205 0A asl a
3228 F8B206 65 A0 adc cyear ; x 5
3229 F8B208 0A asl a ; x 10
3230 F8B209 85 A0 sta cyear
3231 F8B20B 0A asl a ; x 40
3232 F8B20C 0A asl a
3233 F8B20D 65 A0 adc cyear ; x 50
3234 F8B20F 0A asl a ; x 100
3235 F8B210 65 A4 adc ty100
3236 F8B212 3A dec a
3237 F8B213 85 A0 sta cyear
3238 F8B215 ACC08
3239 F8B215 E2 20 sep #PMFLAG
3240 .LONGA off
3241 .MNLIST
3242 F8B217 60 rts
3243
3244 ; fast unsigned division 16 bit
3245 ;
3246 ; entry: C = 16 bit dividend
3247 ; dvsor = 16 bit divisor
3248 ;
3249 ; exit: C = 16 bit quotient
3250 ; Y = dvsor = 16 bit remainder
3251 ;
3252 ; use: all
3253 ;
3254 ; note: no check for null divisor
3255 ; must be called with cpu in 16 bit mode
3256 ;
3257 ;-----
3258 F8B218 fudiv:
3259 ;-----
3260 .LONGA on
3261 .LONGI on
3262
3263 F8B218 A2 01 00 ldx #1 ; bit counter
3264 F8B21B A8 tay ; Y=dividend
3265 F8B21C 64 A8 stz quot ; init quotient
3266 F8B21E A5 A6 lda dvsor ; C=divisor
3267 F8B220 0A ?10: asl a ; shift divisor: get leftmost bit
3268 F8B221 B0 06 bcs ?20 ; go to division
3269 F8B223 E8 inx
3270 F8B224 E0 11 00 cpx #17 ; test all divisor bit's
3271 F8B227 D0 F7 bne ?10
3272 F8B229 6A ?20: ror a ; put shifted-out bit back
3273 F8B22A 85 A6 sta dvsor
3274 F8B22C 98 ?30: tya ; get dividend
3275 F8B22D 38 sec
3276 F8B22E E5 A6 sbc dvsor
3277 F8B230 90 01 bcc ?40 ; can't subctract, retain old dividend
3278 F8B232 A8 tay ; Y=new dividend
3279 F8B233 26 A8 ?40: rol quot ; shift carry into quotient (1 if division)
3280 F8B235 46 A6 lsr dvsor ; shift right divisor for next subtract
3281 F8B237 CA dex
Tue Jul 17 11:00:17 2018 Page 13
3282 F8B238 D0 F2 bne ?30
3283 F8B23A 84 A6 sty dvsor ; remainder
3284 F8B23C A5 A8 lda quot ; C=quotient
3285 F8B23E 60 rts
3286 F8B23F
3287 ;---------------------------------------------------------------------------
3288 ; tables
3289 ;---------------------------------------------------------------------------
3290
3291 ; rtc function's jump table
3292 F8B23F JMPTBL:
3293 F8B23F A3AF 7EB0 E2AF .DW rtcsett, rtcsetd, rtcgett, rtcgetd
22B0
3294
3295 ; month's table
3296 F8B247 MDAYTBL:
3297 F8B247 1F 1C 1F 1E 1F .DB 31,28,31,30,31,30,31,31,30,31,30,31
1E 1F 1F 1E 1F
1E 1F
Lines Assembled : 3237 Errors : 0