Blame | Last modification | View Log | Download | RSS feed
Tue Jul 17 11:00:18 2018 Page 1
2500 A.D. 65816 Macro Assembler #26960 - Version 5.02g
-----------------------------------------------------
Input Filename : src\F8\usbdsk.asm
Output Filename : obj\F8\usbdsk.obj
Listing Has Been Relocated
2583 .LIST on
2584
2585 F8FFB1 .INCLUDE inc\dirp00.inc
2586 ;----------------------------------------------------------
2587 ; DIRP00.ASM
2588 ; PROGETTO: B1601
2589 ;
2590 ; Variabili in Direct Page $00
2591 ;----------------------------------------------------------
2592
2593 ; sezione COMMON -- questo permette di includere il file in piu' file
2594
2595 .LIST on
2596
2597 DIRP00: .SECTION page0, ref_only, common ;Direct-Page 00
2598
2599 000000 .ABSOLUTE ;; inizia sempre da $00
2600 000000 .ORG 0x00
2601 000000
2602 000000 0000 JiffyClk .DW ; contatore 10ms 32 bit
2603 000002 0000 .DW
2604 000004 SysTmr .DS SYSTMRCNT ; system timer 0 (10ms)
2605 000008 SysTMF .DS SYSTMRCNT ; flag timer (80 -> start)
2606 00000C 00 Bnk0Flag .DB ; <7>: flag test RAM banco 0 ok
2607 ; <6>: flag warm reset
2608 00000D 00 RTCFlag .DB
2609
2610 00000E diskstat .DS 2 ; flag device on ata bus #0 & #1
2611 ; <7>: device ready
2612 ; <6>: compact flash device (C.F.)
2613 ; <5>: device identification ok
2614 ; <4>: MBR loaded
2615 ; <3>: valid signature in MBR
2616 ; <2>: first partition found&active
2617 ; <1>:
2618 ; <0>: valid partition flag
2619
2620 ; <7>: device ready
2621 ; <6>: USB device
2622 ; <5>: compact flash device (C.F.)
2623 ; <4>: device identification ok
2624 ; <3>: MBR loaded
2625 ; <2>: first partition found&active
2626 ; <1>: always 1
2627 ; <0>: valid partition flag
2628 000010
Tue Jul 17 11:00:18 2018 Page 2
2629
2630 00000E atadev .EQU diskstat
2631
2632 000010 usbdev .DS 2 ; flag flash disk on usb bus #0
2633 ; <7>: device plugged and ready
2634 ; <6>: always 1
2635 ; <5>: device identification ok
2636 ; <4>: MBR loaded
2637 ; <3>: valid signature in MBR
2638 ; <2>: first partition found&active
2639 ; <1>:
2640 ; <0>: valid partition flag
2641
2642 000012 diskmax .DS 16 ; disk max. sector's
2643 000012 atasec .EQU diskmax
2644 00001A usbsec .EQU diskmax+8
2645
2646
2647 000022 atambr .DS 8 ; data for first partition found in mbr
2648 ; first 3 bytes for start sector of partition
2649 ; last byte for partition type
2650 00002A usbmbr .DS 8
2651
2652 000032 ataprt .DS 8 ; total sec's of first partition
2653 00003A usbprt .DS 8 ; total sec's of first partition
2654
2655
2656 000042 00 usb0ch .DB ; usb0 (ch375/ch376) flag
2657 ; <7>: module on
2658 ; <6>: ch376 flag
2659 ; <5:0>: chip version
2660
2661 000043 00 usb0st .DB ; usb0 status
2662 ; <7>: usb0 host mode ok
2663 ; <6>: flash disk attached flag
2664 ; <5>: usb device attached
2665
2666 000044 00 fdcdrv .DB ; phisycal drive status (drive #0)
2667 ; <7>: disk format established in bit 0&1
2668 ; <6>: double step seek done
2669 ; <5>: trust format bit's (set after ok r/w)
2670 ; <4>: write protect bit (if disk in drive)
2671 ; <3>: don't care
2672 ; <2>: don't care
2673 ; <1>: HD disk if set else DD disk
2674 ; <0>: CBM format if set else IBM format
2675
2676 000045 00 vdrive .DB ; virtual drive status (ram disk, drive #1)
2677 ; <7>: disk format established in bit 0&1
2678 ; <6>: change disk simulation (after format)
2679 ; <5>: don't care
2680 ; <4>: write protect bit (under sw control)
2681 ; <3>: don't care
2682 ; <2>: don't care
2683 ; <1>: HD disk if set else DD disk
2684 ; <0>: CBM format if set else IBM format
2685
Tue Jul 17 11:00:18 2018 Page 3
2686 000046 00 fdcctl .DB ; fdc controller status
2687 ; <7>: drive is attached
2688 ; <6>: drive need recalibration (restore)
2689 ; <5>: FDC controller ok
2690 ; <4>: motor on
2691 ; <3>: dma is active
2692 ; <2>: dma chip ok (post routine)
2693 ; <1>: clock rate (1=HD,0=DD)
2694 ; <0>: disk ready
2695
2696 000047 00 fdctrk .DB ; fd: current seek track
2697 000048 00 fdcerr .DB ; fd: last error code
2698 000049 00 ataerr .DB ; ata: last error code
2699 00004A 00 ataxer .DB ; ata: last extended error code
2700
2701 00004B 00 CtrlBrk .DB ; flag CTRL+BREAK (NMI)
2702
2703 00004C 0000 MemTop .DW ; top memoria RAM
2704 00004E 00 .DB ; banco top mem
2705
2706 00004F 00 DflTxtIn .DB ; device di default text input
2707 000050 00 DflTxtOut .DB ; device di default text output
2708
2709 000051 COPPtr LP ; long pointer for COP decoding
2710 000054 00 COPIdx .DB ; COP signature/index
2711
2712 000055 00 BiosEnt .DB ; flag accesso a bios setup
2713
2714 ; variabili utilizzate da ACIA
2715 000056 spwrk .DS $30
2716
2717 ; bios mem
2718 000086 0000 nsize .DW ; dimensione blocco da allocare
2719 ;bsize .DW ; dimensione vera blocco free
2720 000088 0000 splitsz .DW ; dimensione blocco splittato
2721 00008A 0000 bfree .DW ; puntatore blocco free
2722 00008C 0000 hdrptr .DW ; puntatore header heap
2723
2724 00008E 0000 pbrklv .DW ; current break level of current process
2725 000090 0000 pbrkmin .DW ; minimum breal level of current process
2726 000092 0000 pbrkmax .DW ; maximum breal level of current process
2727 000094
2728 ; bios temp. work area
2729 000094 bwrktmp .DS $28
2730
2731 0000BC 00 coptmp .DB ; temp. used while cop
2732
2733 0000BD 00 tstser .DB ; check ser/usb test board post
2734 ; <7>: VIA2 ok
2735 ; <6>: PICRAM ok
2736 ; <1>: UART 16C550 ok
2737 ; <0>: R65C51 ok
2738
2739
2740 ;crc16 .DW
2741
2742 0000BD .RELATIVE
Tue Jul 17 11:00:18 2018 Page 4
2743
2744 .ENDS
2745
2746 [01] .IFDEF _ACIA_INC_
2747 .INCLUDE INC\SP.INC
2748 [00] .ENDIF
2749
2758 .LIST on
2759 ;---------------------------------------------------------------------------
2760 ; Logical Drive Table (LDT) -- page 0 offset's
2761 ;---------------------------------------------------------------------------
2762
2763 F8FFB1 STRUCT LDT
2764 _LDT .SECTION page0,common,ref_only,offset 0 ;LDT Struct
2765 ;.ABSOLUTE
2766 ;.ORG 0
2767 .MNLIST
2768 000000 00 ldt_fg1 .DB ; logical volume flag's
2769 ; <7>: device ready (fdc drive or ata device)
2770 ; <6>: if=1->HD/CF else->FD
2771 ; <1:0>: phisycal device number
2772
2773 000001 00 ldt_fg2 .DB ; <7>: valid volume (fat volume or cbm disk)
2774 ; <6>: if=1->FAT else->CBM (FD only)
2775 ; <5>: disk format checked
2776 ; <1:0>: disk format (fdc only)
2777
2778 000002 0000 ldt_root .DW ; lba of root dir
2779 000004 0000 ldt_fat1 .DW ; lba of fat1 table
2780 000006 0000 ldt_fat2 .DW ; lba of fat2 table
2781 000008 0000 ldt_cls .DW ; lba of first data cluster
2782 00000A 0000 ldt_max .DW ; max usable cluster + 1
2783 00000C 0000 ldt_rent .DW ; root dir. max. entries
2784 00000E 0000 ldt_cent .DW ; max. entries in dir. cluster
2785 000010 0000 ldt_eoc .DW ; end of cluster chain marker
2786 000012 0000 ldt_free .DW ; count of free cluster's
2787 000014 0000 ldt_nxt .DW ; next free cluster
2788 000016 0000 ldt_fsiz .DW ; fat table size
2789
2790 000018 00 ldt_csiz .DB ; cluster size (1,2,4,8,16,32,64)
2791 000019 00 ldt_cshf .DB ; cluster shift (0,1,2,3,4,5,6)
2792 00001A 00 ldt_rsiz .DB ; root dir. size (sector's)
2793 00001B 00 ldt_mcls .DB ; mask for clust. module: 00,01,03,07,0F,1F,3F
2794 00001C 0000 ldt_cdlp .DW ; current working dir list pointer
2795 00001E 0000 ldt_cdcls .DW ; current working dir start cluster
2796 000020 00 ldt_cdlvl .DB ; current working dir level count
2797
2798 000021 00 ldt_ptype .DB
2799 000022 0000 0000 ldt_pstart .LWORD
2800 000026 0000 0000 ldt_psize .LWORD
2801
2802 000022 ldt_fp .EQU ldt_pstart ; fat table buffer long pointer
2803 000025 ldt_fbuf .EQU ldt_pstart+3 ; fat table: x-mem base bank/dma buffer
2804
2805 000026 ldt_pbr .EQU ldt_psize ; long pointer to PBR cache buffer
2806 000029 ldt_fmt .EQU ldt_psize+3
2807
Tue Jul 17 11:00:18 2018 Page 5
2808 00002A ESTRUCT LDT
2809 00002A LDTSIZE .DS 0
2810 ;.RELATIVE
2811 .ENDS
2812 .MNLIST
2813
2814 [00] .ENDIF
2815
2816 F8FFB1
2817 .LIST on
2818
2819 ; page 0 local var's (declared in bios temp. work area)
2820 _P0BTMP: .SECTION page0, ref_only, offset bwrktmp ; DP Tmp. BIOS
2821 000094 USB0TMP_START .EQU $
2822 000094 00 usbtmp .DB
2823 000095 00 nretry .DB
2824 000096 00 seccnt .DB
2825 000097 00 pktcnt .DB
2826 000098 lba .DS 4
2827 00009C 0000 bufndx .DW
2828 00009E bufp LP
2829 0000A1 tlp LP
2830 0000A4 0000 fatsize .DW
2831 0000A6 0000 wseccnt .DW
2832 0000A8 0000 freecnt .DW
2833 0000AA 0000 nxtfree .DW
2834 0000AC 0000 cluster .DW
2835 0000AE 0000 maxcls .DW
2836 0000B0 00 clssiz .DB
2837 0000B1 00 sec256 .DB
2838 0000A4 usbbuf .EQU fatsize
2839
2840 .EXTERN PAGE0 ldt4
2841
2842 00001E USB0TMP_SIZ .EQU ($-USB0TMP_START)
2843 .ENDS
2844
2845 ;---------------------------------------------------------------------------
2846 ; code segment -- bank $F8
2847 ;---------------------------------------------------------------------------
2848
2849 .CODEF8
2850 F8B253
2851 .LONGA off
2852 .LONGI off
2853
2854 ; called by ISR after plug flash disk
2855 F8B253 usbdskon:
2856 .PUBLIC usbdskon
2857
2858 F8B253 A9 08 lda #CB2IFRB
2859 F8B255 8D CE FD sta !VIA3+VIAIER ; for now disable ch37x interrupt
2860 F8B258 A9 0A lda #10
2861 F8B25A 85 95 sta nretry ; retries times
2862 F8B25C A9 40 lda #$40
2863 F8B25E 04 43 tsb usb0st ; set bit <6>: plugged in
2864 F8B260 24 42 bit usb0ch
Tue Jul 17 11:00:18 2018 Page 6
2865 F8B262 50 03 bvc ?ch5 ; ch375
2866 F8B264 4C F0 B2 jmp ?ch6 ; ch376
2867 F8B267
2868 ; ch375: first of all send command CMD_DISK_INIT
2869 ;
2870 F8B267 20 32 B7 ?ch5: jsr delay10ms ; delay
2871 F8B26A A9 51 lda #CMD_DISK_INIT ; init usb disk on ch375
2872 F8B26C 20 0A B4 jsr cmdwait
2873 F8B26F 90 0F bcc ?nxt
2874 F8B271 24 43 bit usb0st
2875 F8B273 50 74 bvc ?off ; disconnected
2876 F8B275 A5 43 lda usb0st
2877 F8B277 4A lsr a
2878 F8B278 90 68 bcc ?nod ; no flash disk
2879 F8B27A C6 95 dec nretry
2880 F8B27C D0 E9 bne ?ch5 ; try again
2881 F8B27E 80 62 bra ?nod ; no chances
2882 F8B280 A9 00 ?nxt: lda #0
2883 F8B282 85 95 sta nretry
2884 F8B284 20 32 B7 ?ch51: jsr delay10ms
2885 F8B287 A9 53 lda #CMD_DISK_SIZE ; get total sectors & sector size
2886 F8B289 20 0A B4 jsr cmdwait
2887 F8B28C 90 0F bcc ?nxt2
2888 F8B28E 24 43 bit usb0st
2889 F8B290 50 57 bvc ?off ; disconnected
2890 F8B292 A5 43 lda usb0st
2891 F8B294 4A lsr a
2892 F8B295 90 4B bcc ?nod ; no flash disk
2893 F8B297 C6 95 ?dec: dec nretry
2894 F8B299 D0 E9 bne ?ch51 ; try again
2895 F8B29B F0 45 beq ?nod ; no chances
2896 F8B29D A9 28 ?nxt2: lda #CMD_RD_USB_DATA
2897 F8B29F 8D D1 FD sta !usb0cmd ; read 8 bytes
2898 F8B2A2 EA nop
2899 F8B2A3 EA nop
2900 F8B2A4 EA nop
2901 F8B2A5 EA nop
2902
2903 ; expect 8 bytes: 32 bit for total sectors...
2904 ; followed by 32 bit for sector size
2905
2906 F8B2A6 AD D0 FD lda !usb0dat
2907 F8B2A9 C9 08 cmp #$08
2908 F8B2AB D0 EA bne ?dec ; retry
2909 F8B2AD
2910 ; data are in big endian, so get in reverse order
2911 F8B2AD A2 07 ldx #7
2912 F8B2AF AD D0 FD ?lp1: lda !usb0dat
2913 F8B2B2 95 A4 sta usbbuf,x
2914 F8B2B4 CA dex
2915 F8B2B5 10 F8 bpl ?lp1
2916 F8B2B7 A5 A5 lda usbbuf+1
2917 F8B2B9 C9 02 cmp #$02 ; just 512 bytes per sec.
2918 F8B2BB D0 25 bne ?nod ; unsupported sector size
2919 F8B2BD A9 0B lda #CMD_PREFIX ; set packet size per sector
2920 F8B2BF 8D D1 FD sta !usb0cmd
2921 F8B2C2 EA nop
Tue Jul 17 11:00:18 2018 Page 7
2922 F8B2C3 EA nop
2923 F8B2C4 EA nop
2924 F8B2C5 A9 39 lda #PFX_SET_PKT_P_SEC
2925 F8B2C7 8D D0 FD sta !usb0dat
2926 F8B2CA EA nop
2927 F8B2CB A9 08 lda #$08 ; one sector = 8 packets (1 pack = 64 bytes)
2928 F8B2CD 8D D0 FD sta !usb0dat
2929 F8B2D0 A5 A8 lda usbbuf+4
2930 F8B2D2 85 1A sta usbsec
2931 F8B2D4 A5 A9 lda usbbuf+5
2932 F8B2D6 85 1B sta usbsec+1
2933 F8B2D8 A5 AA lda usbbuf+6
2934 F8B2DA 85 1C sta usbsec+2
2935 F8B2DC A5 AB lda usbbuf+7
2936 F8B2DE 85 1D sta usbsec+3
2937 F8B2E0 80 5F bra ?dev
2938
2939 F8B2E2 A9 20 ?nod: lda #$20
2940 F8B2E4 04 43 tsb usb0st ; unknow device plugged
2941 F8B2E6 4C 76 B3 jmp ?end
2942 F8B2E9
2943 F8B2E9 A9 7F ?off: lda #$7F
2944 F8B2EB 14 43 trb usb0st ; device unplugged
2945 F8B2ED 4C 76 B3 jmp ?end
2946
2947 ; handle flash disk plug on ch376 chip
2948 F8B2F0 20 32 B7 ?ch6: jsr delay10ms ; delay
2949 F8B2F3 A9 31 lda #CMD_DISK_MOUNT ; try to mount flash disk
2950 F8B2F5 20 0A B4 jsr cmdwait
2951 F8B2F8 90 0F bcc ?nxt3
2952 F8B2FA 24 43 bit usb0st
2953 F8B2FC 50 EB bvc ?off ; disconnected
2954 F8B2FE A5 43 lda usb0st
2955 F8B300 4A lsr a
2956 F8B301 90 DF bcc ?nod ; no flash disk
2957 F8B303 C6 95 dec nretry
2958 F8B305 F0 DB beq ?nod ; no chances
2959 F8B307 D0 E7 bne ?ch6 ; try again
2960 F8B309 64 95 ?nxt3: stz nretry
2961 F8B30B 20 32 B7 ?nxt31: jsr delay10ms ; delay
2962 F8B30E A9 3E lda #CMD_DISK_CAPACITY
2963 F8B310 20 0A B4 jsr cmdwait
2964 F8B313 90 0F bcc ?nxt4
2965 F8B315 24 43 bit usb0st
2966 F8B317 50 D0 bvc ?off ; disconnected
2967 F8B319 A5 43 lda usb0st
2968 F8B31B 4A lsr a
2969 F8B31C 90 C4 bcc ?nod ; no flash disk
2970 F8B31E C6 95 ?dec1: dec nretry
2971 F8B320 F0 C0 beq ?nod ; no chances
2972 F8B322 D0 E7 bne ?nxt31 ; try again
2973 F8B324 A9 28 ?nxt4: lda #CMD_RD_USB_DATA
2974 F8B326 8D D1 FD sta !usb0cmd ; expect 4 bytes
2975 F8B329 EA nop
2976 F8B32A EA nop
2977 F8B32B EA nop
2978 F8B32C EA nop
Tue Jul 17 11:00:18 2018 Page 8
2979 F8B32D AD D0 FD lda !usb0dat
2980 F8B330 C9 04 cmp #$04
2981 F8B332 D0 EA bne ?dec1 ; retry
2982 F8B334 A0 04 ldy #4
2983 F8B336 A2 00 ldx #0
2984 F8B338 AD D0 FD ?lp2: lda !usb0dat
2985 F8B33B 95 1A sta usbsec,x
2986 F8B33D E8 inx
2987 F8B33E 88 dey
2988 F8B33F D0 F7 bne ?lp2
2989
2990 F8B341 A9 58 ?dev: lda #CMD_DISK_INQUIRY
2991 F8B343 20 0A B4 jsr cmdwait
2992 F8B346 90 06 bcc ?dev1
2993 F8B348 24 43 bit usb0st
2994 F8B34A 50 9D bvc ?off ; disconnected
2995 F8B34C 80 94 bra ?nod
2996 F8B34E 20 E4 B3 ?dev1: jsr rddata
2997 F8B351 8B phb
2998 F8B352 A9 01 lda #^USBBUF
2999 F8B354 48 pha
3000 F8B355 AB plb
3001 F8B356 A2 FF ldx #$FF
3002 F8B358 E8 ?dev2: inx
3003 F8B359 BD C4 9D lda !.LOW16.USBBUF+8,x
3004 F8B35C C9 20 cmp #' ' ; skip beginning blanks
3005 F8B35E F0 F8 beq ?dev2
3006 F8B360 A0 00 ldy #0
3007 F8B362 BD C4 9D ?dev3: lda !.LOW16.USBBUF+8,x
3008 F8B365 99 80 9D sta USB0STR,y
3009 F8B368 F0 04 beq ?dev4
3010 F8B36A E8 inx
3011 F8B36B C8 iny
3012 F8B36C 80 F4 bra ?dev3
3013 F8B36E AB ?dev4: plb
3014 F8B36F A9 E0 lda #$E0
3015 F8B371 85 10 sta usbdev
3016 F8B373
3017 F8B373 20 81 B3 jsr getmbr
3018
3019 F8B376 A9 08 ?end: lda #CB2IFRB
3020 F8B378 8D CD FD sta !VIA3+VIAIFR
3021 F8B37B A9 88 lda #CB2IFRB+$80
3022 F8B37D 8D CE FD sta !VIA3+VIAIER ; re-enable ch37x interrupt
3023 F8B380 6B rtl
3024
3025 F8B381 getmbr:
3026 .EXTERN chkumbr
3027 F8B381
3028 F8B381 A9 01 lda #1
3029 F8B383 85 96 sta seccnt
3030 F8B385 A9 00 lda #<MBR0USB
3031 F8B387 85 9E sta bufp
3032 F8B389 A9 94 lda #>MBR0USB
3033 F8B38B 85 9F sta bufp+1
3034 F8B38D A9 01 lda #^MBR0USB
3035 F8B38F 85 A0 sta bufp+2
Tue Jul 17 11:00:18 2018 Page 9
3036 F8B391 64 98 stz lba
3037 F8B393 64 99 stz lba+1
3038 F8B395 64 9A stz lba+2
3039 F8B397 64 9B stz lba+3
3040 F8B399 20 2D B5 jsr readsec
3041 F8B39C B0 35 bcs ?end ; error
3042 F8B39E A2 02 ldx #2 ; drive #2
3043 F8B3A0 20 5F 90 jsr chkumbr ; check mbr
3044 F8B3A3 B0 2E bcs ?end ; error
3045 F8B3A5 A5 10 lda usbdev
3046 F8B3A7 C9 FD cmp #$FD
3047 F8B3A9 38 sec
3048 F8B3AA D0 27 bne ?end
3049 F8B3AC A9 01 lda #1
3050 F8B3AE 85 96 sta seccnt
3051 F8B3B0 A9 00 lda #<PBR0USB
3052 F8B3B2 85 9E sta bufp
3053 F8B3B4 A9 96 lda #>PBR0USB
3054 F8B3B6 85 9F sta bufp+1
3055 F8B3B8 A9 01 lda #^PBR0USB
3056 F8B3BA 85 A0 sta bufp+2
3057 F8B3BC A5 2A lda usbmbr
3058 F8B3BE 85 98 sta lba
3059 F8B3C0 A5 2B lda usbmbr+1
3060 F8B3C2 85 99 sta lba+1
3061 F8B3C4 A5 2C lda usbmbr+2
3062 F8B3C6 85 9A sta lba+2
3063 F8B3C8 64 9B stz lba+3 ; FAT16 only!!
3064 F8B3CA 20 2D B5 jsr readsec
3065 F8B3CD B0 04 bcs ?end
3066 F8B3CF A9 02 lda #$02
3067 F8B3D1 04 10 tsb usbdev ; pbr ok
3068 F8B3D3
3069 F8B3D3 08 ?end: php
3070 F8B3D4 A5 55 lda BiosEnt
3071 F8B3D6 4A lsr a
3072 F8B3D7 B0 09 bcs ?done ; boot phase
3073 F8B3D9 TXT_CR
3074 F8B3D9 TXTPRCHAR
3075 .MLIST
3076 F8B3D9 02 08 cop $08
3077 .MNLIST
3078 F8B3DB 0D .DB $0D
3079 .MNLIST
3080 F8B3DC 20 47 B6 jsr showusb0
3081 F8B3DF 20 D1 B6 jsr shusb0fat
3082 F8B3E2 28 ?done: plp
3083 F8B3E3 60 rts
3084 F8B3E4
3085 ; read block data
3086 F8B3E4 rddata:
3087 F8B3E4 A9 28 lda #CMD_RD_USB_DATA
3088 F8B3E6 8D D1 FD sta !usb0cmd
3089 F8B3E9 EA nop
3090 F8B3EA EA nop
3091 F8B3EB EA nop
3092 F8B3EC EA nop
Tue Jul 17 11:00:18 2018 Page 10
3093 F8B3ED AD D0 FD lda !usb0dat
3094 F8B3F0 F0 17 beq ?end
3095 F8B3F2 A8 tay
3096 F8B3F3 A2 00 ldx #0
3097 F8B3F5 84 94 sty usbtmp
3098 F8B3F7 AD D0 FD ?lp: lda !usb0dat
3099 F8B3FA 9F BC 9D 01 sta >USBBUF,x
3100 F8B3FE E8 inx
3101 F8B3FF 88 dey
3102 F8B400 D0 F5 bne ?lp
3103 F8B402 98 tya
3104 F8B403 9F BC 9D 01 sta >USBBUF,x
3105 F8B407 A5 94 lda usbtmp
3106 F8B409 60 ?end: rts
3107
3108 ; send command and wait interrupt
3109 F8B40A cmdwait:
3110 F8B40A 8D D1 FD sta !usb0cmd
3111 F8B40D A9 01 lda #$01
3112 F8B40F 14 43 trb usb0st ; clear retry flag: bit <0>
3113 F8B411 A9 08 ?wi: lda #CB2IFRB
3114 F8B413 2C CD FD bit !VIA3+VIAIFR
3115 F8B416 F0 F9 beq ?wi ; wait interrupt
3116 F8B418 8D CD FD sta !VIA3+VIAIFR ; clear flag
3117 F8B41B A9 22 lda #CMD_GET_STATUS
3118 F8B41D 8D D1 FD sta !usb0cmd
3119 F8B420 EA nop ; 2uS
3120 F8B421 EA nop
3121 F8B422 EA nop
3122 F8B423 EA nop
3123 F8B424 AD D0 FD lda !usb0dat ; read interrupt code
3124 F8B427 C9 14 cmp #USB_INT_SUCCESS
3125 F8B429 F0 48 beq ?ok
3126 F8B42B C9 16 cmp #USB_INT_DISCONNECT
3127 F8B42D F0 46 beq ?off ; disconnected
3128 F8B42F 24 42 bit usb0ch
3129 F8B431 50 04 bvc ?chk ; ch375: skip next test
3130 F8B433 C9 82 cmp #ERR_DISK_DISCON
3131 F8B435 F0 3E beq ?off ; disconnected (ch376 only)
3132 F8B437 C9 1F ?chk: cmp #USB_INT_DISK_ERR
3133 F8B439 D0 3E bne ?nod ; no flash disk
3134 F8B43B 24 42 bit usb0ch
3135 F8B43D 50 0D bvc ?ch5 ; ch375 handle in different way
3136 F8B43F A9 2B lda #VAR_DISK_STATUS
3137 F8B441 20 7B B4 jsr readvar8 ; read internal status ch376
3138 F8B444 F0 33 beq ?nod ; unknow device
3139 F8B446 C9 03 cmp #DEF_DISK_MOUNTED
3140 F8B448 90 2F bcc ?nod ; unknow device
3141 F8B44A 80 21 bra ?ret ; set retry flag
3142 F8B44C A9 5A ?ch5: lda #CMD_DISK_R_SENSE
3143 F8B44E 8D D1 FD sta !usb0cmd
3144 F8B451 A9 08 ?wi2: lda #CB2IFRB
3145 F8B453 2C CD FD bit !VIA3+VIAIFR
3146 F8B456 F0 F9 beq ?wi2 ; wait interrupt
3147 F8B458 8D CD FD sta !VIA3+VIAIFR ; clear flag
3148 F8B45B
3149 F8B45B A9 22 lda #CMD_GET_STATUS
Tue Jul 17 11:00:18 2018 Page 11
3150 F8B45D 8D D1 FD sta !usb0cmd
3151 F8B460 EA nop ; 2uS
3152 F8B461 EA nop
3153 F8B462 EA nop
3154 F8B463 EA nop
3155 F8B464 AD D0 FD lda !usb0dat ; read interrupt code
3156 F8B467 85 FD sta $FD
3157
3158 F8B469 C9 14 cmp #USB_INT_SUCCESS
3159 F8B46B D0 0C bne ?nod ; unknow device
3160 F8B46D A9 01 ?ret: lda #$01
3161 F8B46F 04 43 tsb usb0st ; set retry flag
3162 F8B471 38 sec
3163 F8B472 60 rts
3164 F8B473 18 ?ok: clc
3165 F8B474 60 rts
3166 F8B475 A9 40 ?off: lda #$40
3167 F8B477 14 43 trb usb0st ; clear bit <6>
3168 F8B479 38 ?nod: sec
3169 F8B47A 60 rts
3170 F8B47B
3171 ; ch376 specific
3172 ; A = var 8
3173 ; return A = var. value
3174 F8B47B readvar8:
3175 F8B47B EB xba
3176 F8B47C A9 0A lda #CMD_READ_VAR8
3177 F8B47E 8D D1 FD sta !usb0cmd
3178 F8B481 EA nop
3179 F8B482 EA nop
3180 F8B483 EA nop
3181 F8B484 EB xba
3182 F8B485 8D D0 FD sta !usb0dat
3183 F8B488 EA nop
3184 F8B489 EA nop
3185 F8B48A EA nop
3186 F8B48B EA nop
3187 F8B48C AD D0 FD lda !usb0dat
3188 F8B48F 60 rts
3189
3190 ; scan fat table of usb #0 device
3191 ; first 64K of dma buffer are reserved to cluster read/write
3192 ; scan fat table reading 64 sectors at time
3193 F8B490 scanufat:
3194 F8B490 64 A1 stz tlp ; init dma buffer pointer
3195 F8B492 64 A2 stz tlp+1
3196 F8B494 A9 02 lda #DMABNK
3197 F8B496 85 A3 sta tlp+2
3198 F8B498 AD C0 40 lda !P0LDT+ldt4+ldt_csiz
3199 F8B49B 85 B0 sta clssiz
3200 F8B49D ACC16
3201 F8B49D C2 20 rep #PMFLAG
3202 .LONGA on
3203 .MNLIST
3204 F8B49F AD AC 40 lda !P0LDT+ldt4+ldt_fat1
3205 F8B4A2 85 98 sta lba ; start sector of fat 1 table
3206 F8B4A4 64 9A stz lba+2
Tue Jul 17 11:00:18 2018 Page 12
3207 F8B4A6 64 A8 stz freecnt ; count of free clusters
3208 F8B4A8 64 AA stz nxtfree ; free next cluster
3209 F8B4AA 64 AC stz cluster ; cluster sequence
3210 F8B4AC AD B2 40 lda !P0LDT+ldt4+ldt_max
3211 F8B4AF 85 AE sta maxcls ; max. cluster number + 1
3212 F8B4B1 ACC08
3213 F8B4B1 E2 20 sep #PMFLAG
3214 .LONGA off
3215 .MNLIST
3216 F8B4B3 A2 00 ldx #0
3217 F8B4B5 AD BE 40 lda !P0LDT+ldt4+ldt_fsiz
3218 F8B4B8 85 A4 sta fatsize ; store fat table size
3219 F8B4BA D0 01 bne ?st ; less than 256 sectors
3220 F8B4BC E8 inx ; fat size = 256 sectors
3221 F8B4BD 86 A5 ?st: stx fatsize+1
3222 F8B4BF 64 A7 stz wseccnt+1
3223 F8B4C1
3224 F8B4C1 ACC16
3225 F8B4C1 C2 20 rep #PMFLAG
3226 .LONGA on
3227 .MNLIST
3228 F8B4C3 A5 A1 ?lp: lda tlp
3229 F8B4C5 85 9E sta bufp
3230 F8B4C7 A6 A3 ldx tlp+2
3231 F8B4C9 86 A0 stx bufp+2
3232 F8B4CB A5 A4 lda fatsize
3233 F8B4CD C9 40 00 cmp #64
3234 F8B4D0 90 03 bcc ?less
3235 F8B4D2 A9 40 00 lda #64
3236 F8B4D5 ?less: ACC08
3237 F8B4D5 E2 20 sep #PMFLAG
3238 .LONGA off
3239 .MNLIST
3240 F8B4D7 85 96 sta seccnt ; sectors count #
3241 F8B4D9 85 A6 sta wseccnt
3242 F8B4DB 20 2D B5 jsr readsec ; read fat
3243 F8B4DE B0 3E bcs ?err ; some errors
3244 F8B4E0 A0 00 ldy #0
3245 F8B4E2 CPU16
3246 F8B4E2 C2 30 rep #(PMFLAG.OR.PXFLAG)
3247 .LONGA on
3248 .LONGI on
3249 .MNLIST
3250 F8B4E4 A5 A6 lda wseccnt
3251 F8B4E6 EB xba
3252 F8B4E7 0A asl a ; bytes count #
3253 F8B4E8 85 9C sta bufndx
3254 F8B4EA A6 AC ldx cluster
3255 F8B4EC B7 A1 ?lpf: lda [tlp],y ; scan fat table
3256 F8B4EE D0 08 bne ?nxt ; not free
3257 F8B4F0 E6 A8 inc freecnt ; update free cluster's count
3258 F8B4F2 A5 AA lda nxtfree ; already set?
3259 F8B4F4 D0 02 bne ?nxt ; yes
3260 F8B4F6 86 AA stx nxtfree ; set first free cluster
3261 F8B4F8 E8 ?nxt: inx ; update cluster number
3262 F8B4F9 C8 iny
3263 F8B4FA C8 iny
Tue Jul 17 11:00:18 2018 Page 13
3264 F8B4FB E4 AE cpx maxcls ; end of table?
3265 F8B4FD B0 1C bcs ?done ; yes
3266 F8B4FF C4 9C cpy bufndx ; end of partial table?
3267 F8B501 90 E9 bcc ?lpf ; no
3268 F8B503 86 AC stx cluster ; save current cluster number
3269 F8B505 INDEX08
3270 F8B505 E2 10 sep #PXFLAG
3271 .LONGI off
3272 .MNLIST
3273 F8B507 A5 A4 lda fatsize
3274 F8B509 38 sec
3275 F8B50A E5 A6 sbc wseccnt
3276 F8B50C F0 0D beq ?done ; end
3277 F8B50E 85 A4 sta fatsize
3278 F8B510 18 clc
3279 F8B511 A5 98 lda lba
3280 F8B513 65 A6 adc wseccnt
3281 F8B515 90 AC bcc ?lp
3282 F8B517 E6 9A inc lba+2
3283 F8B519 80 A8 bra ?lp
3284 F8B51B ?done: CPU08
3285 F8B51B E2 30 sep #(PMFLAG.OR.PXFLAG)
3286 .LONGA off
3287 .LONGI off
3288 .MNLIST
3289 F8B51D 18 clc
3290 F8B51E ?err: ACC16
3291 F8B51E C2 20 rep #PMFLAG
3292 .LONGA on
3293 .MNLIST
3294 F8B520 A5 A8 lda freecnt
3295 F8B522 8D BA 40 sta !P0LDT+ldt4+ldt_free
3296 F8B525 A5 AA lda nxtfree
3297 F8B527 8D BC 40 sta !P0LDT+ldt4+ldt_nxt
3298 F8B52A ACC08
3299 F8B52A E2 20 sep #PMFLAG
3300 .LONGA off
3301 .MNLIST
3302 F8B52C 60 rts
3303 F8B52D
3304 ; read sector(s)
3305 F8B52D readsec:
3306 F8B52D A9 08 lda #CB2IFRB
3307 F8B52F 8D CE FD sta !VIA3+VIAIER ; disable ch37x interrupt
3308 F8B532 A9 08 lda #CB2IFRB
3309 F8B534 8D CD FD sta !VIA3+VIAIFR ; clear flag
3310 F8B537 A9 54 lda #CMD_DISK_READ ; start to read sector(s)
3311 F8B539 8D D1 FD sta !usb0cmd
3312 F8B53C EA nop
3313 F8B53D EA nop
3314 F8B53E 64 B1 stz sec256
3315 F8B540 A5 98 lda lba ; send starting lba
3316 F8B542 8D D0 FD sta !usb0dat
3317 F8B545 EA nop
3318 F8B546 A5 99 lda lba+1
3319 F8B548 8D D0 FD sta !usb0dat
3320 F8B54B EA nop
Tue Jul 17 11:00:18 2018 Page 14
3321 F8B54C A5 9A lda lba+2
3322 F8B54E 8D D0 FD sta !usb0dat
3323 F8B551 EA nop
3324 F8B552 A5 9B lda lba+3
3325 F8B554 8D D0 FD sta !usb0dat
3326 F8B557 A5 96 lda seccnt ; sector(s) count #
3327 F8B559 D0 05 bne ?go
3328 F8B55B 3A dec a
3329 F8B55C 85 B1 sta sec256
3330 F8B55E 85 96 sta seccnt
3331 F8B560 8D D0 FD ?go: sta !usb0dat
3332 F8B563
3333 F8B563 64 9C stz bufndx
3334 F8B565 64 9D stz bufndx+1
3335 F8B567 A9 08 lda #$08 ; 8 packets per sector
3336 F8B569 85 97 sta pktcnt
3337 F8B56B 80 0B bra ?wi
3338 F8B56D
3339 F8B56D A9 08 ?sct: lda #$08 ; 8 packets per sector
3340 F8B56F 85 97 sta pktcnt
3341 F8B571 A9 55 ?pkt: lda #CMD_DISK_RD_GO ; read next packet
3342 F8B573 8D D1 FD sta !usb0cmd
3343 F8B576 EA nop
3344 F8B577 EA nop
3345 F8B578 20 30 B6 ?wi: jsr waitint ; wait ch interrupt
3346 F8B57B C9 1D cmp #USB_INT_DISK_READ
3347 F8B57D D0 38 bne ?done ; finish or error
3348 F8B57F A9 28 lda #CMD_RD_USB_DATA
3349 F8B581 8D D1 FD sta !usb0cmd ; read a packet (64 bytes)
3350 F8B584 EA nop
3351 F8B585 EA nop
3352 F8B586 EA nop
3353 F8B587 EA nop
3354 F8B588 AE D0 FD ldx !usb0dat
3355 F8B58B E0 40 cpx #$40
3356 F8B58D D0 65 bne ?err
3357 F8B58F
3358 F8B58F INDEX16
3359 F8B58F C2 10 rep #PXFLAG
3360 .LONGI on
3361 .MNLIST
3362 F8B591 A4 9C ldy bufndx ; current buffer index
3363 F8B593 AD D0 FD ?rdl: lda !usb0dat ; read & store loop
3364 F8B596 97 9E sta [bufp],y
3365 F8B598 C8 iny
3366 F8B599 CA dex
3367 F8B59A D0 F7 bne ?rdl
3368 F8B59C 84 9C sty bufndx
3369 F8B59E INDEX08
3370 F8B59E E2 10 sep #PXFLAG
3371 .LONGI off
3372 .MNLIST
3373 F8B5A0 C6 97 dec pktcnt ; more packets to read?
3374 F8B5A2 D0 CD bne ?pkt ; yes
3375 F8B5A4 ACC16CLC
3376 F8B5A4 C2 21 rep #(PMFLAG.OR.PCFLAG)
3377 .LONGA on
Tue Jul 17 11:00:18 2018 Page 15
3378 .MNLIST
3379 F8B5A6 A5 9F lda bufp+1
3380 F8B5A8 69 02 00 adc #$0002 ; update: add 512
3381 F8B5AB 85 9F sta bufp+1
3382 F8B5AD 64 9C stz bufndx
3383 F8B5AF ACC08
3384 F8B5AF E2 20 sep #PMFLAG
3385 .LONGA off
3386 .MNLIST
3387 F8B5B1 C6 96 dec seccnt
3388 F8B5B3 D0 B8 bne ?sct ; next sector if any
3389 F8B5B5 80 BA bra ?pkt ; get last interrupt
3390 F8B5B7
3391 F8B5B7 C9 14 ?done: cmp #USB_INT_SUCCESS
3392 F8B5B9 D0 24 bne ?tst ; test error condition
3393 F8B5BB A5 97 lda pktcnt ; pktcnt & seccnt must be both zero
3394 F8B5BD 05 96 ora seccnt
3395 F8B5BF D0 3C bne ?sec
3396 F8B5C1 24 B1 bit sec256
3397 F8B5C3 10 17 bpl ?ok ; finish
3398 ; read one more sector
3399 F8B5C5 ACC16CLC
3400 F8B5C5 C2 21 rep #(PMFLAG.OR.PCFLAG)
3401 .LONGA on
3402 .MNLIST
3403 F8B5C7 A5 98 lda lba
3404 F8B5C9 69 FF 00 adc #255
3405 F8B5CC 85 98 sta lba
3406 F8B5CE A5 9A lda lba+2
3407 F8B5D0 69 00 00 adc #0
3408 F8B5D3 85 9A sta lba+2
3409 F8B5D5 ACC08
3410 F8B5D5 E2 20 sep #PMFLAG
3411 .LONGA off
3412 .MNLIST
3413 F8B5D7 E6 96 inc seccnt
3414 F8B5D9 4C 2D B5 jmp readsec
3415 F8B5DC 18 ?ok: clc
3416 F8B5DD 80 1F bra ?end
3417 F8B5DF C9 16 ?tst: cmp #USB_INT_DISCONNECT
3418
3419 F8B5E1 85 FF sta $ff
3420 F8B5E3
3421 F8B5E3 F0 14 beq ?off ; device unplugged
3422 F8B5E5 C9 17 cmp #USB_INT_BUF_OVER
3423 F8B5E7 F0 0B beq ?err ; sense disk error
3424 F8B5E9 C9 1F cmp #USB_INT_DISK_ERR
3425 F8B5EB F0 07 beq ?err
3426 F8B5ED 20 09 B6 jsr dskrdy
3427 F8B5F0 B0 07 bcs ?off ; unplugged?
3428 F8B5F2 80 09 bra ?sec
3429 F8B5F4 20 19 B6 ?err: jsr dskerr
3430 F8B5F7 80 04 bra ?sec
3431 F8B5F9 A9 7F ?off: lda #$7F
3432 F8B5FB 14 43 trb usb0st
3433 F8B5FD 38 ?sec: sec ; error flag
3434 F8B5FE A9 08 ?end: lda #CB2IFRB ; clear CB2 flag
Tue Jul 17 11:00:18 2018 Page 16
3435 F8B600 8D CD FD sta !VIA3+VIAIFR
3436 F8B603 A9 88 lda #CB2IFRB+$80
3437 F8B605 8D CE FD sta !VIA3+VIAIER ; re-enable ch37x interrupt
3438 F8B608 60 rts
3439
3440 ; test disk ready
3441 F8B609 dskrdy:
3442 F8B609 A9 59 lda #CMD_DISK_READY
3443 F8B60B 8D D1 FD sta !usb0cmd
3444 F8B60E EA nop
3445 F8B60F 20 30 B6 jsr waitint
3446 F8B612 C9 14 cmp #USB_INT_SUCCESS
3447 F8B614 18 clc
3448 F8B615 F0 01 beq ?end
3449 F8B617 38 sec
3450 F8B618 60 ?end: rts
3451
3452 ; sensing disk error
3453 F8B619 dskerr:
3454 F8B619 A9 5A lda #CMD_DISK_R_SENSE
3455 F8B61B 8D D1 FD sta !usb0cmd
3456 F8B61E EA nop
3457 F8B61F 20 30 B6 jsr waitint
3458 F8B622 C9 14 cmp #USB_INT_SUCCESS
3459 F8B624 F0 02 beq ?get
3460 F8B626 38 sec ; error
3461 F8B627 60 rts
3462 F8B628 20 60 B7 ?get: jsr delay5ms
3463 F8B62B 20 E4 B3 jsr rddata ; get error string
3464 F8B62E 18 clc
3465 F8B62F 60 rts
3466
3467 F8B630 waitint:
3468 F8B630 A9 08 lda #CB2IFRB
3469 F8B632 2C CD FD bit !VIA3+VIAIFR
3470 F8B635 F0 F9 beq waitint ; wait interrupt
3471 F8B637 8D CD FD sta !VIA3+VIAIFR ; clear flag
3472 F8B63A A9 22 lda #CMD_GET_STATUS
3473 F8B63C 8D D1 FD sta !usb0cmd
3474 F8B63F EA nop ; 2uS
3475 F8B640 EA nop
3476 F8B641 EA nop
3477 F8B642 EA nop
3478 F8B643 AD D0 FD lda !usb0dat ; read interrupt code
3479 F8B646 60 rts
3480
3481 F8B647 showusb0:
3482 .PUBLIC showusb0
3483
3484 F8B647 24 43 bit usb0st
3485 F8B649 50 5A bvc ?end ; no device plugged
3486 F8B64B 24 10 bit usbdev
3487 F8B64D 10 28 bpl ?unkn ; unknow device
3488 F8B64F ACC16CLC
3489 F8B64F C2 21 rep #(PMFLAG.OR.PCFLAG)
3490 .LONGA on
3491 .MNLIST
Tue Jul 17 11:00:18 2018 Page 17
3492 F8B651 A5 1A lda usbsec
3493 F8B653 85 98 sta lba
3494 F8B655 A5 1C lda usbsec+2
3495 F8B657 A2 0B ldx #11 ; divide by 2048 (11 shift)...
3496 F8B659 4A ?shr: lsr a ; ... and get rounded size in Mb
3497 F8B65A 66 98 ror lba
3498 F8B65C CA dex
3499 F8B65D D0 FA bne ?shr
3500 F8B65F 85 9A sta lba+2
3501 F8B661 48 pha ; 2
3502 F8B662 A5 98 lda lba
3503 F8B664 48 pha ; 2
3504 F8B665 ACC08
3505 F8B665 E2 20 sep #PMFLAG
3506 .LONGA off
3507 .MNLIST
3508 F8B667 A9 01 lda #^USB0STR ; bank that hold device string
3509 F8B669 48 pha
3510 F8B66A F4 80 9D pea #USB0STR
3511 F8B66D 4B phk ; format string
3512 F8B66E F4 A6 B6 pea #?fstr
3513 F8B671 A9 0B lda #11
3514 F8B673 48 pha
3515 F8B674 BPRINTF
3516 F8B674 02 11 cop $11
3517 .MNLIST
3518 F8B676 60 rts
3519 F8B677
3520 F8B677 ?unkn: SCNPRINT
3521 F8B677 02 01 cop $01
3522 .MNLIST
3523 F8B679 75 73 62 20 20 .DB 'usb #0: unknow device (not flash disk).', $0D, $00
20 23 30 3A 20
20 75 6E 6B 6E
6F 77 20 64 65
76 69 63 65 20
28 6E 6F 74 20
66 6C 61 73 68
20 64 69 73 6B
29 2E 0D 00
3524 F8B6A5 60 ?end: rts
3525
3526 F8B6A6 ?fstr:
3527 ;.DB 'usb #0: flash disk: %-42.41s %,7u Mb', 13, 0
3528 F8B6A6 75 73 62 20 20 .DB 'usb #0: usb drive E: %-42.41s %,7u Mb', 13, 0
20 23 30 3A 20
20 75 73 62 20
64 72 69 76 65
20 45 3A 20 20
25 2D 34 32 2E
34 31 73 20 25
2C 37 75 20 4D
62 0D 00
3529
3530 F8B6D1 shusb0fat:
3531 .PUBLIC shusb0fat
3532 .EXTERN lusbldt
Tue Jul 17 11:00:18 2018 Page 18
3533
3534 F8B6D1 24 10 bit usbdev
3535 F8B6D3 10 24 bpl ?end ; no disk device plugged
3536 F8B6D5 22 05 03 F9 jsl lusbldt
3537 F8B6D9 B0 1E bcs ?end
3538 F8B6DB 20 90 B4 jsr scanufat
3539 F8B6DE ACC16 ; print summary
3540 F8B6DE C2 20 rep #PMFLAG
3541 .LONGA on
3542 .MNLIST
3543 F8B6E0 A5 AE lda maxcls
3544 F8B6E2 3A dec a
3545 F8B6E3 3A dec a
3546 F8B6E4 85 AE sta maxcls
3547 F8B6E6 ACC08
3548 F8B6E6 E2 20 sep #PMFLAG
3549 .LONGA off
3550 .MNLIST
3551 F8B6E8 A5 B0 lda clssiz
3552 F8B6EA 48 pha
3553 F8B6EB D4 A8 pei (freecnt)
3554 F8B6ED D4 AE pei (maxcls)
3555 F8B6EF 4B phk
3556 F8B6F0 F4 FA B6 pea #!?fstr
3557 F8B6F3 A9 09 lda #9
3558 F8B6F5 48 pha
3559 F8B6F6 BPRINTF
3560 F8B6F6 02 11 cop $11
3561 .MNLIST
3562 F8B6F8 18 clc
3563 F8B6F9 60 ?end: rts
3564
3565 F8B6FA 25 2C 68 75 20 ?fstr: .DB '%,hu cluster(s) (free: %,hu, 1 cluster=%bu sector(s)).', 13, 0
63 6C 75 73 74
65 72 28 73 29
20 28 66 72 65
65 3A 20 25 2C
68 75 2C 20 31
20 63 6C 75 73
74 65 72 3D 25
62 75 20 73 65
63 74 6F 72 28
73 29 29 2E 0D
00
3566
3567
3568 009C40 T10MS .EQU (10 * 1000 * PHI2)
3569 F8B732 delay10ms:
3570 F8B732 A9 20 lda #$20 ; T2 count PHI2 pulses
3571 F8B734 1C 0B FD trb VIA0+VIAACR
3572 F8B737 A9 40 lda #<T10MS
3573 F8B739 8D 08 FD sta !VIA0+VIAT2CL
3574 F8B73C A9 9C lda #>T10MS
3575 F8B73E 8D 09 FD sta !VIA0+VIAT2CH
3576 F8B741 AD 0D FD ?wl: lda !VIA0+VIAIFR
3577 F8B744 89 20 bit #T2IFRB
3578 F8B746 F0 F9 beq ?wl
Tue Jul 17 11:00:18 2018 Page 19
3579 F8B748 60 rts
3580
3581 000FA0 T01MS .EQU (1000 * PHI2)
3582 F8B749 delay1ms:
3583 F8B749 A9 20 lda #$20 ; T2 count PHI2 pulses
3584 F8B74B 1C 0B FD trb VIA0+VIAACR
3585 F8B74E A9 A0 lda #<T01MS
3586 F8B750 8D 08 FD sta !VIA0+VIAT2CL
3587 F8B753 A9 0F lda #>T01MS
3588 F8B755 8D 09 FD sta !VIA0+VIAT2CH
3589 F8B758 AD 0D FD ?wl: lda !VIA0+VIAIFR
3590 F8B75B 89 20 bit #T2IFRB
3591 F8B75D F0 F9 beq ?wl
3592 F8B75F 60 rts
3593
3594 004E20 T05MS .EQU (5000 * PHI2)
3595 F8B760 delay5ms:
3596 F8B760 A9 20 lda #$20 ; T2 count PHI2 pulses
3597 F8B762 1C 0B FD trb VIA0+VIAACR
3598 F8B765 A9 20 lda #<T05MS
3599 F8B767 8D 08 FD sta !VIA0+VIAT2CL
3600 F8B76A A9 4E lda #>T05MS
3601 F8B76C 8D 09 FD sta !VIA0+VIAT2CH
3602 F8B76F AD 0D FD ?wl: lda !VIA0+VIAIFR
3603 F8B772 89 20 bit #T2IFRB
3604 F8B774 F0 F9 beq ?wl
3605 F8B776 60 rts
3606 F8B777
3607 000080 T32US .EQU (32 * PHI2)
3608
3609 F8B777 delay32us:
3610 F8B777 A9 20 lda #$20 ; T2 count PHI2 pulses
3611 F8B779 1C 0B FD trb VIA0+VIAACR
3612 F8B77C A9 80 lda #T32US
3613 F8B77E 8D 08 FD sta !VIA0+VIAT2CL
3614 F8B781 9C 09 FD stz !VIA0+VIAT2CH
3615 F8B784 AD 0D FD ?55: lda !VIA0+VIAIFR
3616 F8B787 89 20 bit #T2IFRB
3617 F8B789 F0 F9 beq ?55
3618 F8B78B 60 rts
Lines Assembled : 3528 Errors : 0