Blame | Last modification | View Log | Download | RSS feed
Tue Jul 17 11:00:20 2018 Page 1
2500 A.D. 65816 Macro Assembler #26960 - Version 5.02g
-----------------------------------------------------
Input Filename : src\F9\fsstart.asm
Output Filename : obj\F9\fsstart.obj
Listing Has Been Relocated
2582 .LIST on
2583
2584 F8FFB1 .INCLUDE inc\dirp00.inc
2585 ;----------------------------------------------------------
2586 ; DIRP00.ASM
2587 ; PROGETTO: B1601
2588 ;
2589 ; Variabili in Direct Page $00
2590 ;----------------------------------------------------------
2591
2592 ; sezione COMMON -- questo permette di includere il file in piu' file
2593
2594 .LIST on
2595
2596 DIRP00: .SECTION page0, ref_only, common ;Direct-Page 00
2597
2598 000000 .ABSOLUTE ;; inizia sempre da $00
2599 000000 .ORG 0x00
2600 000000
2601 000000 0000 JiffyClk .DW ; contatore 10ms 32 bit
2602 000002 0000 .DW
2603 000004 SysTmr .DS SYSTMRCNT ; system timer 0 (10ms)
2604 000008 SysTMF .DS SYSTMRCNT ; flag timer (80 -> start)
2605 00000C 00 Bnk0Flag .DB ; <7>: flag test RAM banco 0 ok
2606 ; <6>: flag warm reset
2607 00000D 00 RTCFlag .DB
2608
2609 00000E diskstat .DS 2 ; flag device on ata bus #0 & #1
2610 ; <7>: device ready
2611 ; <6>: compact flash device (C.F.)
2612 ; <5>: device identification ok
2613 ; <4>: MBR loaded
2614 ; <3>: valid signature in MBR
2615 ; <2>: first partition found&active
2616 ; <1>:
2617 ; <0>: valid partition flag
2618
2619 ; <7>: device ready
2620 ; <6>: USB device
2621 ; <5>: compact flash device (C.F.)
2622 ; <4>: device identification ok
2623 ; <3>: MBR loaded
2624 ; <2>: first partition found&active
2625 ; <1>: always 1
2626 ; <0>: valid partition flag
2627 000010
Tue Jul 17 11:00:20 2018 Page 2
2628
2629 00000E atadev .EQU diskstat
2630
2631 000010 usbdev .DS 2 ; flag flash disk on usb bus #0
2632 ; <7>: device plugged and ready
2633 ; <6>: always 1
2634 ; <5>: device identification ok
2635 ; <4>: MBR loaded
2636 ; <3>: valid signature in MBR
2637 ; <2>: first partition found&active
2638 ; <1>:
2639 ; <0>: valid partition flag
2640
2641 000012 diskmax .DS 16 ; disk max. sector's
2642 000012 atasec .EQU diskmax
2643 00001A usbsec .EQU diskmax+8
2644
2645
2646 000022 atambr .DS 8 ; data for first partition found in mbr
2647 ; first 3 bytes for start sector of partition
2648 ; last byte for partition type
2649 00002A usbmbr .DS 8
2650
2651 000032 ataprt .DS 8 ; total sec's of first partition
2652 00003A usbprt .DS 8 ; total sec's of first partition
2653
2654
2655 000042 00 usb0ch .DB ; usb0 (ch375/ch376) flag
2656 ; <7>: module on
2657 ; <6>: ch376 flag
2658 ; <5:0>: chip version
2659
2660 000043 00 usb0st .DB ; usb0 status
2661 ; <7>: usb0 host mode ok
2662 ; <6>: flash disk attached flag
2663 ; <5>: usb device attached
2664
2665 000044 00 fdcdrv .DB ; phisycal drive status (drive #0)
2666 ; <7>: disk format established in bit 0&1
2667 ; <6>: double step seek done
2668 ; <5>: trust format bit's (set after ok r/w)
2669 ; <4>: write protect bit (if disk in drive)
2670 ; <3>: don't care
2671 ; <2>: don't care
2672 ; <1>: HD disk if set else DD disk
2673 ; <0>: CBM format if set else IBM format
2674
2675 000045 00 vdrive .DB ; virtual drive status (ram disk, drive #1)
2676 ; <7>: disk format established in bit 0&1
2677 ; <6>: change disk simulation (after format)
2678 ; <5>: don't care
2679 ; <4>: write protect bit (under sw control)
2680 ; <3>: don't care
2681 ; <2>: don't care
2682 ; <1>: HD disk if set else DD disk
2683 ; <0>: CBM format if set else IBM format
2684
Tue Jul 17 11:00:20 2018 Page 3
2685 000046 00 fdcctl .DB ; fdc controller status
2686 ; <7>: drive is attached
2687 ; <6>: drive need recalibration (restore)
2688 ; <5>: FDC controller ok
2689 ; <4>: motor on
2690 ; <3>: dma is active
2691 ; <2>: dma chip ok (post routine)
2692 ; <1>: clock rate (1=HD,0=DD)
2693 ; <0>: disk ready
2694
2695 000047 00 fdctrk .DB ; fd: current seek track
2696 000048 00 fdcerr .DB ; fd: last error code
2697 000049 00 ataerr .DB ; ata: last error code
2698 00004A 00 ataxer .DB ; ata: last extended error code
2699
2700 00004B 00 CtrlBrk .DB ; flag CTRL+BREAK (NMI)
2701
2702 00004C 0000 MemTop .DW ; top memoria RAM
2703 00004E 00 .DB ; banco top mem
2704
2705 00004F 00 DflTxtIn .DB ; device di default text input
2706 000050 00 DflTxtOut .DB ; device di default text output
2707
2708 000051 COPPtr LP ; long pointer for COP decoding
2709 000054 00 COPIdx .DB ; COP signature/index
2710
2711 000055 00 BiosEnt .DB ; flag accesso a bios setup
2712
2713 ; variabili utilizzate da ACIA
2714 000056 spwrk .DS $30
2715
2716 ; bios mem
2717 000086 0000 nsize .DW ; dimensione blocco da allocare
2718 ;bsize .DW ; dimensione vera blocco free
2719 000088 0000 splitsz .DW ; dimensione blocco splittato
2720 00008A 0000 bfree .DW ; puntatore blocco free
2721 00008C 0000 hdrptr .DW ; puntatore header heap
2722
2723 00008E 0000 pbrklv .DW ; current break level of current process
2724 000090 0000 pbrkmin .DW ; minimum breal level of current process
2725 000092 0000 pbrkmax .DW ; maximum breal level of current process
2726 000094
2727 ; bios temp. work area
2728 000094 bwrktmp .DS $28
2729
2730 0000BC 00 coptmp .DB ; temp. used while cop
2731
2732 0000BD 00 tstser .DB ; check ser/usb test board post
2733 ; <7>: VIA2 ok
2734 ; <6>: PICRAM ok
2735 ; <1>: UART 16C550 ok
2736 ; <0>: R65C51 ok
2737
2738
2739 ;crc16 .DW
2740
2741 0000BD .RELATIVE
Tue Jul 17 11:00:20 2018 Page 4
2742
2743 .ENDS
2744
2745 [01] .IFDEF _ACIA_INC_
2746 .INCLUDE INC\SP.INC
2747 [00] .ENDIF
2748
2762 .LIST on
2763
2764 000060 KBDBUFLEN .EQU 96 ; dimensione buffer di tastiera
2765
2766 DIRP01: .SECTION page0, ref_only, common ;Direct-Page 01
2767
2768 000000 .ABSOLUTE ;; inizia sempre da $00
2769 000000 .ORG 0x00
2770
2771 000000
2772 000000 KbdBuf .DS KBDBUFLEN ; buffer della tastiera
2773 000060 00 KbdITail .DB ; coda buffer tastiera
2774 000061 00 KbdIHead .DB ; testa buffer tastiera
2775 000062 00 KbdCnt .DB ; numero bytes nel buffer
2776 000063 00 KbdShift .DB
2777 000064 00 KbdFlag .DB
2778 000065 00 KbdToggle .DB
2779 000066 00 KbdSt .DB ; status tastiera dopo reset
2780 000067 00 PS2Ctl .DB ; flag controller PS2 keyboard
2781
2782 000068 00 LCDFlag .DB
2783 000069 00 LCDTmp .DB
2784 00006A 0000 LCDVal .DW
2785
2786 00006C 00 VBBFlag .DB ; flag video board
2787 00006D 00 VBBRam .DB ; flag video RAM
2788
2789 00006E 00 ScnLinTmp .DB
2790 00006F 00 ScnChBase .DB ; base video ram VDC
2791 000070 00 ScnAttBase .DB ; base ram attributi VDC
2792 000071 00 ScnCursMode .DB ; VDC cursore default
2793 000072 00 ScnSaveAttr .DB
2794 000073 00 ScnInsert .DB
2795 000074 00 ScnAutoIns .DB ; bit 7 -> autoins - bit 6 -> modo input
2796 000075 00 ScnScroll .DB
2797 000076 00 ScnMaxRow .DB ; max. righe finestra (-1)
2798 000077 00 ScnMaxCols .DB ; max. colonne finestra (-1)
2799
2800 000078 ScnMapTabs1 .DS 10
2801 000082 ScnMapTabs2 .DS 4
2802 000086
2803 000086 0000 ScnPtr .DW ; puntatore video ram linea corrente
2804 000088 00 .DB
2805
2806 000089 00 ScnFiltLen .DB ; lunghezza set caratteri filtro
2807
2808 00008A 0000 ScnAtPtr .DW ; puntatore attributi ram linea corrente
2809 00008C 00 .DB
2810
2811 00008D 00 ScnTmpx .DB ; temporaneo: durante put char
Tue Jul 17 11:00:20 2018 Page 5
2812 00008E
2813 00008E 00 ScnTop .DB ; riga superiore finestra
2814 00008F 00 ScnLeft .DB ; colonna sinistra finestra
2815 000090 00 ScnBottom .DB ; riga inferiore finestra
2816 000091 00 ScnRight .DB ; colonna destra finestra
2817 000092 00 ScnAttr .DB ; attributo default
2818 000093 00 ScnAttr2 .DB ; attributo alternativo
2819 000094 00 ScnRow .DB ; riga cursore
2820 000095 00 ScnCol .DB ; colonna cursore
2821 000096 00 ScnRowStart .DB ; riga di start input
2822 000097 00 ScnInput .DB ; riga di fine input
2823 000098 00 ScnColStart .DB ; colonna di start input
2824 000099 00 ScnSaveX .DB
2825 00009A 00 ScnSaveY .DB
2826 00009B 00 ScnTmpL .DB
2827 00009C 00 ScnTmpH .DB
2828 00009D 00 ScnSaveRow .DB
2829 00009E 00 ScnSaveCol .DB
2830 00009F 00 ScnCurChr .DB
2831 0000A0 00 ScnLstChr .DB
2832 0000A1 00 ScnCR .DB
2833 0000A2 0000 ScnPrm .DW ; puntatore long utilizzato da print imm
2834 0000A4 00 .DB ; banco puntatore ScnPrm
2835 0000A5 00 ScnMode .DB ; flag modo schermo
2836
2837 0000A6 ScnPtr1 LP
2838
2839 0000A9 00 ScnDefCol .DB ; default foreground color
2840
2841 0000AA ScnPtr2 LP
2842
2843 0000AD 00 ScnDefBkgCol .DB ; default background color
2844 0000AE 00 ScnInpRow .DB ; modo input line: riga start input
2845 0000AF 00 ScnInpCol .DB ; modo input line: colonna start input
2846 0000B0 00 ScnLstRow .DB ; modo input line: riga stop input
2847 0000B1 00 ScnLstCol .DB ; modo input line: colonna stop input
2848 0000B2 00 ScnFlag .DB ; Bit 7: input line - Bit 6: input riga unica
2849 0000B3 00 ScnMask .DB ; flag tasti funzione editor di linea
2850 0000B4 00 ScnFilt .DB ; filtro tasti editor di linea
2851 0000B5 00 ScnCntrl .DB ; flag ASCII/CONTROL
2852 ;DflTxtIn .DB ; device di default text input
2853 ;DflTxtOut .DB ; device di default text output
2854 0000B6
2855 000047 SCNCLRLEN .EQU ($ - ScnLinTmp - 1)
2856
2857 ;SCNCLRLEN .EQU (DflTxtOut - ScnLinTmp)
2858
2859 ; variabili monitor
2860 0000B6 00 SMAddrL .DB ; address low/high
2861 0000B7 00 SMAddrH .DB
2862 0000B8 00 SMAddrK .DB ; address bank
2863 0000B9 00 SMFlag32 .DB ; flag parametro 32 bit
2864 0000BA 00 SMTmpL .DB ; temp. low/high
2865 0000BB 00 SMTmpH .DB
2866 0000BC 00 SMTmpK .DB ; temp. bank
2867 0000BD 00 SMTmpKK .DB ; high byte param. 32 bit
2868 0000BE 00 SMSizeL .DB ; size low/high
Tue Jul 17 11:00:20 2018 Page 6
2869 0000BF 00 SMSizeH .DB
2870 0000C0 00 SMSizeK .DB ; size bank
2871 0000C1 00 SMXAddrL .DB ; address low/high XM
2872 0000C2 00 SMXAddrH .DB
2873 0000C3 00 SMXAddrK .DB ; address bank XM
2874 0000C4 00 SMbndx .DB ; indice input buffer
2875 0000C5 00 SMnprm .DB ; numero parametri riga di comando
2876 0000C6 00 SMdumb .DB
2877 0000C7 00 SMkr .DB
2878 0000C8 0000 SMpc .DW
2879 0000CA 00 SMsr .DB
2880 0000CB 00 SMbr .DB
2881 0000CC 0000 SMdp .DW
2882 0000CE 0000 SMac .DW
2883 0000D0 0000 SMxr .DW
2884 0000D2 0000 SMyr .DW
2885 0000D4 0000 SMsp .DW
2886
2887 0000D6 00 SMAuxL .DB
2888 0000D7 00 SMAuxH .DB
2889
2890 0000D8 00 asmlong .DB ; flag for CPU in 16 mode
2891 ; <7> -> A/M in 16 bit mode
2892 ; <6> -> X/Y in 16 bit mode
2893 0000D9 00 asmcpu .DB ; <7> -> 8 bit family
2894 ; <6> -> 65C02 cmos version
2895
2896 0000DA 00 SMctx .DB ; context (if = $00 no quit command)
2897 0000DB SMrsm LP ; long pointer to resume caller context
2898
2899 0000DE 00 rtcadr .DB ; rtc internal ram address
2900 0000DF 00 rtcbnk .DB ; RTC internal bank ram
2901 0000E0 00 cmdlin .DB ;
2902 0000E1 00 SMesc .DB
2903
2904 0000E2 SMXTmp: .DS 26 ; 26 bytes tmp
2905
2906 0000E2 SMTmp2 .EQU SMXTmp
2907 0000E4 SMTmp3 .EQU SMXTmp+2
2908 0000E6 SMdwTmp1 .EQU SMXTmp+4
2909 0000EA SMdwTmp2 .EQU SMXTmp+8
2910 0000EE SMFsrc .EQU SMXTmp+12 ; source bank for flash update
2911 0000EF SMFflag .EQU SMXTmp+13 ; flag file for flash update
2912 0000F0 SMXPos2 .EQU SMXTmp+14
2913 0000F1 SMYPos2 .EQU SMXTmp+15
2914 0000F2 SMXPos3 .EQU SMXTmp+16
2915 0000F3 SMYPos3 .EQU SMXTmp+17
2916 ;SMAuxL .EQU SMXTmp+18
2917 ;SMAuxH .EQU SMXTmp+19
2918 0000F6 SMXPos .EQU SMXTmp+20
2919 0000F7 SMYPos .EQU SMXTmp+21
2920 0000F8 SMdwTmp3 .EQU SMXTmp+22
2921
2922 0000E2 atcmd .EQU SMXTmp ; save @ command
2923 0000E3 atnum .EQU SMXTmp+1 ; @ command index
2924 0000E4 atflag .EQU SMXTmp+2 ; @ L,S,V,R,W start address flag
2925 0000E5 atbnk .EQU SMXTmp+3 ; @ L,S,V,R,W bank
Tue Jul 17 11:00:20 2018 Page 7
2926 0000E6 atstr .EQU SMXTmp+4 ; @ command string start (word)
2927 0000E8 atstart .EQU SMXTmp+6 ; @ L,S,V,R,W start address (word)
2928 0000EA atend .EQU SMXTmp+8 ; @ S,W end address (word)
2929 0000EC atbuf .EQU SMXTmp+10 ; @ local buffer pointer (word)
2930 0000EE atipb .EQU SMXTmp+12 ; @ bank of input buffer
2931 0000EF atdir .EQU SMXTmp+13 ; @ load dir flag
2932 0000F0 atptr .EQU SMXTmp+14 ; @ load dir pointer (word)
2933 0000F2 atsiz .EQU SMXTmp+16 ; @ buffer size (word)
2934 0000F5 atlp .EQU SMXTmp+19 ; @ long pointer
2935 0000F8 atsa .EQU SMXTmp+22 ; @ sa
2936
2937 0000E2 btmpx .EQU SMXTmp ; asc2bin conversion
2938 0000E3 brtcsec .EQU SMXTmp+1
2939 0000E4 brtcmin .EQU SMXTmp+2
2940 0000E5 brtchour .EQU SMXTmp+3
2941 0000E6 brtcday .EQU SMXTmp+4
2942 0000E7 brtcmonth .EQU SMXTmp+5
2943 0000E8 brtcyear .EQU SMXTmp+6
2944 0000E9 brtcct .EQU SMXTmp+7
2945
2946
2947 0000FC .RELATIVE
2948
2949 .ENDS
2950
2958 .LIST on
2959
2960 F8FFB1 .INCLUDE INC\LDT.INC
2961 ; LDT.INC
2962
2963 [02] .IFNDEF __LDT_INC__
2964 000001 __LDT_INC__ .SET 1
2965
2966 .LIST on
2967 ;---------------------------------------------------------------------------
2968 ; Logical Drive Table (LDT) -- page 0 offset's
2969 ;---------------------------------------------------------------------------
2970
2971 F8FFB1 STRUCT LDT
2972 _LDT .SECTION page0,common,ref_only,offset 0 ;LDT Struct
2973 ;.ABSOLUTE
2974 ;.ORG 0
2975 .MNLIST
2976 000000 00 ldt_fg1 .DB ; logical volume flag's
2977 ; <7>: device ready (fdc drive or ata device)
2978 ; <6>: if=1->HD/CF else->FD
2979 ; <1:0>: phisycal device number
2980
2981 000001 00 ldt_fg2 .DB ; <7>: valid volume (fat volume or cbm disk)
2982 ; <6>: if=1->FAT else->CBM (FD only)
2983 ; <5>: disk format checked
2984 ; <1:0>: disk format (fdc only)
2985
2986 000002 0000 ldt_root .DW ; lba of root dir
2987 000004 0000 ldt_fat1 .DW ; lba of fat1 table
2988 000006 0000 ldt_fat2 .DW ; lba of fat2 table
2989 000008 0000 ldt_cls .DW ; lba of first data cluster
Tue Jul 17 11:00:20 2018 Page 8
2990 00000A 0000 ldt_max .DW ; max usable cluster + 1
2991 00000C 0000 ldt_rent .DW ; root dir. max. entries
2992 00000E 0000 ldt_cent .DW ; max. entries in dir. cluster
2993 000010 0000 ldt_eoc .DW ; end of cluster chain marker
2994 000012 0000 ldt_free .DW ; count of free cluster's
2995 000014 0000 ldt_nxt .DW ; next free cluster
2996 000016 0000 ldt_fsiz .DW ; fat table size
2997
2998 000018 00 ldt_csiz .DB ; cluster size (1,2,4,8,16,32,64)
2999 000019 00 ldt_cshf .DB ; cluster shift (0,1,2,3,4,5,6)
3000 00001A 00 ldt_rsiz .DB ; root dir. size (sector's)
3001 00001B 00 ldt_mcls .DB ; mask for clust. module: 00,01,03,07,0F,1F,3F
3002 00001C 0000 ldt_cdlp .DW ; current working dir list pointer
3003 00001E 0000 ldt_cdcls .DW ; current working dir start cluster
3004 000020 00 ldt_cdlvl .DB ; current working dir level count
3005
3006 000021 00 ldt_ptype .DB
3007 000022 0000 0000 ldt_pstart .LWORD
3008 000026 0000 0000 ldt_psize .LWORD
3009
3010 000022 ldt_fp .EQU ldt_pstart ; fat table buffer long pointer
3011 000025 ldt_fbuf .EQU ldt_pstart+3 ; fat table: x-mem base bank/dma buffer
3012
3013 000026 ldt_pbr .EQU ldt_psize ; long pointer to PBR cache buffer
3014 000029 ldt_fmt .EQU ldt_psize+3
3015
3016 00002A ESTRUCT LDT
3017 00002A LDTSIZE .DS 0
3018 ;.RELATIVE
3019 .ENDS
3020 .MNLIST
3021
3022 [01] .ENDIF
3023
3024
3025 000100 CLSBUF .EQU $100 ; dma buffer of cluster cache
3026 000040 CLSMAXSIZ .EQU 64 ; max. size of cluster in sector's
3027
3028 ;---------------------------------------------------------------------------
3029 ; FAT Working Segment
3030 ;---------------------------------------------------------------------------
3031
3032 010000 FATSEG .EQU $010000
3033 000001 FATBNK .EQU .SEG.FATSEG ; FAT working bank
3034
3035 010000 FS .SET FATSEG
3036 01FFFF FE .SET FATSEG + $FFFF
3037 018C00 FO .SET $018C00
3038
3039 _FATS: .SECTION ref_only, common, offset FO, range FS FE ;FAT Segment
3040 018C00 _FATS_START .DS 0
3041
3042 018C00 _pbr0 .DS 512
3043 018E00 _pbr1 .DS 512
3044 019000 _pbr2 .DS 512
3045 019200 _pbr3 .DS 512
3046
Tue Jul 17 11:00:20 2018 Page 9
3047 019400 _FATS_END .DS 0
3048 000800 FATSSIZ .EQU (_FATS_END - _FATS_START)
3049 .ENDS
3050
3051 ;---------------------------------------------------------------------------
3052 ; direct page for LDT tables (P0LDT direct page)
3053 ;---------------------------------------------------------------------------
3054
3055 _DPLDT: .SECTION page0, common, ref_only, offset 0 ;LDT D.P.
3056
3057 000000 ldt0 .DS LDTSIZE
3058 00002A ldt1 .DS LDTSIZE
3059 000054 ldt2 .DS LDTSIZE
3060 00007E ldt3 .DS LDTSIZE
3061 0000A8 ldt4 .DS LDTSIZE
3062 0000D2 ldt5 .DS LDTSIZE
3063
3064 0000FC _DPLDT_END .DS 0
3065
3066 .ENDS
3067
3068
3069 ;---------------------------------------------------------------------------
3070 ; FAT var's direct page (P0FAT direct page)
3071 ;---------------------------------------------------------------------------
3072
3073 _DPFAT: .SECTION page0, common, ref_only, offset 0 ;FAT D.P.
3074
3075 000000 00 ldtfg1 .DB ; logical volume flag's
3076 ; <7>: device ready (fdc drive or ata device)
3077 ; <6>: if=1->HD/CF else->FD
3078 ; <0>: phisycal device number
3079
3080 000001 00 ldtfg2 .DB ; <7>: valid volume (fat volume or cbm disk)
3081 ; <6>: if=1->FAT else->CBM (FD only)
3082 ; <5>: disk format checked
3083 ; <1:0>: disk format (fdc only)
3084
3085 000002 0000 ldtroot .DW ; lba of root dir
3086 000004 0000 ldtfat1 .DW ; lba of fat1 table
3087 000006 0000 ldtfat2 .DW ; lba of fat2 table
3088 000008 0000 ldtcls .DW ; lba of first data cluster
3089 00000A 0000 ldtmax .DW ; max usable cluster + 1
3090 00000C 0000 ldtrent .DW ; root dir. max. entries
3091 00000E 0000 ldtcent .DW ; max. entries in dir. cluster
3092 000010 0000 ldteoc .DW ; end of cluster chain marker
3093 000012 0000 ldtfree .DW ; count of free cluster's
3094 000014 0000 ldtnxt .DW ; next free cluster
3095 000016 0000 ldtfsiz .DW ; fat table size
3096
3097 000018 00 ldtcsiz .DB ; cluster size (1,2,4,8,16,32,64)
3098 000019 00 ldtcshf .DB ; cluster shift (0,1,2,3,4,5,6)
3099 00001A 00 ldtrsiz .DB ; root dir. size (sector's)
3100 00001B 00 ldtmcls .DB ; mask for clust. module: 00,01,03,07,0F,1F,3F
3101 00001C 0000 ldtcdlp .DW ; current working dir list pointer
3102 00001E 0000 ldtcdcls .DW ; current working dir start cluster
3103 000020 00 ldtcdlvl .DB ; current working dir level count
Tue Jul 17 11:00:20 2018 Page 10
3104
3105 ; ---------------------------
3106
3107 000021 00 curldt .DB ; pointer to current LDT
3108 000022 ldtp .DS 6 ; LDT's pointer
3109 000028 00 defdrv .DB ; default logical drive
3110 000029 00 curdrv .DB ; current logical drive
3111
3112 00002A 0000 0000 lba .LWORD ; current lba
3113 00002E 0000 wseccnt .DW ; sector count
3114
3115 000030 00 defhsec .DB ; default hidden sector's in fdisk
3116 000031 00 pdrive .DB ; phisycal drive number (temp.)
3117
3118 000032 _fattmp .DS 48
3119
3120 .ENDS
3121
3127 .LIST on
3128
3129 _FATTMP: .SECTION page0, ref_only, offset _fattmp
3130 000032 FATTMP_START .EQU $
3131
3132 000032 0000 0000 hidsec .LWORD ; hidden sectors
3133 000036 0000 0000 totsec .LWORD ; partition size in sector's
3134 00003A 0000 0000 maxsec .LWORD ; device max sector's count
3135 00003E 0000 freecnt .DW ; free cluster's count
3136 00003E mbrflag .EQU freecnt ; mbr partition flag (low 8 bits only)
3137 000040 0000 nextfree .DW ; next free cluster
3138 000042 0000 maxcls .DW ; last usable cluster+1
3139 000042 mbrtype .EQU maxcls ; mbr partition type (low 8 bits only)
3140 000044 0000 fatsize .DW ; FAT16 fat table size
3141 000046 0000 clscnt .DW ; cluster's count #
3142 000048 0000 ncnt .DW ; generic counter
3143
3144 00004A 00 ldrv .DB ; temp.: logical drive
3145 00004B 00 ldttmp .DB ; temp.: LDT pointer
3146 00004C 00 pdev .DB ; temp.: phisycal drive
3147
3148 00001B FATTMP_SIZ .EQU ($ - FATTMP_START)
3149 .ENDS
3150
3151
3152 ;---------------------------------------------------------------------------
3153 ; code segment -- bank $F9
3154 ;---------------------------------------------------------------------------
3155
3156 .CODEF9
3157
3158 .comment @
3159 ; getfreecnt - compute free cluster's count scanning fat table
3160 ; in: X = logical drive
3161 ; out: LDT of logical drive is updated
3162 ; CF = 1 if error
3163 ;
3164 ; fat table is loaded in dma buffer # $100, devoted to cluster cache and
3165 ; limited to 64 sectors
Tue Jul 17 11:00:20 2018 Page 11
3166 ;
3167 getfreecnt:
3168 stx ldrv ; logical drive
3169 ldy ldtp,x ; LDT pointer
3170 sty ldttmp ; save LDT pointer
3171 stz tlp ; init dma buffer pointer
3172 stz tlp+1
3173 lda #DMABNK
3174 sta tlp+2
3175 lda !P0LDT+ldt_fg1,y
3176 and #00000011B
3177 sta pdrive ; phisycal drive
3178 ACC16
3179 lda !P0LDT+ldt_fat1,y
3180 sta lba ; start sector of fat 1 table
3181 stz lba+2
3182 stz freecnt ; count of free clusters
3183 stz nxtfree ; free next cluster
3184 stz clscnt ; cluster numbering
3185 lda !P0LDT+ldt_max,y
3186 sta maxcls ; max. cluster number + 1
3187 lda !P0LDT+ldt_fsiz,y
3188 sta fatsize ; store fat table size
3189
3190 ?lp: lda fatsize
3191 cmp #CLSMAXSIZ
3192 bcc ?less
3193 lda #CLSMAXSIZ
3194 ?less: sta wseccnt ; sectors count #
3195 ACC08
3196 lda pdrive ; phisycal device #
3197 pha
3198 pei (lba+2) ; start sector
3199 pei (lba)
3200 lda seccnt ; sector's count
3201 pha
3202 pea #CLSBUF ; dma cliuster buffer
3203 DISKRD ; read dik sector
3204 bcs ?? ; error (Y = error code)
3205
3206 ldy #0
3207 CPU16
3208 lda wseccnt
3209 xba
3210 asl a ; bytes count #
3211 sta ncnt
3212 ldx clscnt ; X = current cluster number
3213 ?lpf: lda [tlp],y ; scan fat table
3214 bne ?nxt ; not free
3215 inc freecnt ; update free cluster's count
3216 lda nxtfree ; already set?
3217 bne ?nxt ; yes
3218 stx nxtfree ; set first free cluster
3219 ?nxt: inx ; update cluster number
3220 iny
3221 iny
3222 cpx maxcls ; end of table?
Tue Jul 17 11:00:20 2018 Page 12
3223 bcs ?done ; yes
3224 cpy ncnt ; end of partial table?
3225 bcc ?lpf ; no
3226 stx cluster ; save current cluster number
3227 INDEX08
3228 lda fatsize
3229 sec
3230 sbc wseccnt
3231 beq ?done ; end
3232 sta fatsize
3233 clc
3234 lda lba
3235 adc wseccnt
3236 bcc ?lp
3237 inc lba+2
3238 bra ?lp
3239 ?done: CPU08
3240 clc
3241 ?err: ACC16
3242 ldy ldttmp ; LDT pointer
3243 lda freecnt
3244 sta !P0LDT+ldt_free,y
3245 lda nxtfree
3246 sta !P0LDT+ldt_nxt,y
3247 ACC08
3248 rts
3249 @
3250
3251 .comment @
3252 ; load & check disk mbr
3253 mbrld:
3254 lda pdev ; phisycal device #
3255 pha
3256 pea #0 ; load sector #0
3257 pea #0
3258 lda #1 ; load 1 sector
3259 pha
3260 pea #$0100 ; dma buffer #256
3261 DISKRD ; read dik sector
3262 bcs ?? ; error (Y = error code)
3263
3264 lda #$10 ; set bit mbr loaded
3265 sta tmp
3266 CPU16
3267 ldy #$01FE ; signature pointer
3268 lda [bufp],y
3269 sta mbrsgn ; mbr signature
3270 ldy #$01C2 ; partition type pointer
3271 lda [bufp],y
3272 sta wtmp ; partition type
3273 ldy #$01C6 ; partition start pointer
3274 lda [bufp],y
3275 sta nlba ; partition start
3276 iny
3277 iny
3278 lda [bufp],y
3279 sta nlba+2
Tue Jul 17 11:00:20 2018 Page 13
3280 ldy #$01BE ; partition flag pointer
3281 lda [bufp],y
3282 sta mbrfg ; partition flag
3283 lda mbrsgn
3284 cmp #$AA55
3285 CPU08
3286 bne ?20 ; invalid mbr signature
3287 lda #$18 ; add valid mbr signature flag
3288 sta tmp
3289 lda mbrfg ; must be $80 or 0
3290 beq ?vv
3291 bpl ?20 ; first partition invalid
3292 ?vv: lda #$1C ; add active partition flag
3293 sta tmp
3294 lda drive
3295 asl a
3296 asl a
3297 tax ; index for access to atambr var
3298 lda wtmp ; partition type
3299 tay
3300 sta atambr+3,x ; store partition type
3301 lda nlba+2 ; store partition start
3302 sta atambr+2,x
3303 lda nlba+1
3304 sta atambr+1,x
3305 lda nlba
3306 sta atambr,x
3307 lda nlba+3 ; must be 0
3308 bne ?20
3309 cpy #$06 ; just FAT16 type
3310 beq ?10
3311 cpy #$04 ; FAT 16 for disk less than 32Mb
3312 beq ?10
3313 cpy #$0E
3314 bne ?20
3315 ?10: CPU16
3316 ldy #$01CA ; partition sec's count pointer
3317 lda [bufp],y
3318 sta ataprt,x
3319 iny
3320 iny
3321 lda [bufp],y
3322 sta ataprt+2,x
3323 CPU08
3324 lda #$1D ; add valid partition type
3325 sta tmp
3326 ?20: ldx drive ; update device flag
3327 lda atadev,x
3328 ora tmp
3329 sta atadev,x
3330 clc
3331 ?30: rts
3332
3333 ; load & check pbr
3334 lda pdev ; phisycal device #
3335 pha
3336 pei (lba+2) ; load pbr sector
Tue Jul 17 11:00:20 2018 Page 14
3337 pea (lba)
3338 lda #1 ; load 1 sector
3339 pha
3340 pea #$0100 ; dma buffer #256
3341 DISKRD ; read dik sector
3342 bcs ?? ; error (Y = error code)
3343
3344 lda pdev ; phisycal drive
3345 asl a
3346 asl a
3347 asl a
3348 tax
3349 ACC16
3350 lda !atambr,x ; partition start
3351 sta hidsec ; this is also hidden sectors count
3352 lda !atambr+2,x
3353 and #$00FF
3354 sta hidsec+2
3355 lda !ataprt,x ; total partition sector's
3356 sta totsec
3357 lda !ataprt+2,x
3358 sta totsec+2
3359 ldx ldtcur ; LDT ptr
3360
3361 ; entry point to check usb #0 disk
3362 chk16c:
3363 ACC16
3364 ldx pbrp+1
3365 inx
3366 stx pbrp+1
3367 lda #MAXF16
3368 sta maxcnt
3369 ldy #$FE ; pointer to pbr signature
3370 lda [pbrp],y
3371 cmp #$AA55
3372 bne ?10 ; signature error
3373 dex
3374 stx pbrp+1
3375 ldy #$0B ; pointer to bytes per sector
3376 lda [pbrp],y
3377 cmp #$0200 ; must be always 512 bytes per sector
3378 bne ?10 ; error
3379 ldy #$1C ; pointer to hidden sector's count
3380 lda [pbrp],y ; typical value: $3F
3381 cmp hidsec ; must match
3382 bne ?10
3383 iny
3384 iny
3385 lda [pbrp],y
3386 cmp hidsec+2
3387 bne ?10
3388 cmp #0
3389 bne ?10 ; must be 0
3390 ldy #$0E ; pointer to reserved sector's
3391 lda [pbrp],y ; typical value: 1 (no mandatory)
3392 sta rsvsec
3393 ldy #$11 ; pointer to root dir entry #
Tue Jul 17 11:00:20 2018 Page 15
3394 lda [pbrp],y
3395 beq ?10 ; fat32?
3396 cmp #$0200 ; typical value: not mandatory...
3397 bne ?10 ; ...but this will be
3398 sta rootent
3399 lsr a ; divide by 16...
3400 lsr a
3401 lsr a
3402 lsr a ;...to get root dir size in sec's
3403 sta rootsiz
3404 ldy #$13 ; pointer to tot. sec16
3405 lda [pbrp],y
3406 beq ?06 ; invalid: is valid field tot. sec32
3407 cmp totsec
3408 bne ?10 ; error
3409 lda totsec+2 ; must be 0
3410 bne ?10 ; errore
3411 beq ?08 ; ok
3412 ?06: ldy #$20 ; pointer to tot. sec32
3413 lda [pbrp],y
3414 cmp totsec
3415 bne ?10 ; error
3416 iny
3417 iny
3418 lda [pbrp],y
3419 cmp totsec+2
3420 bne ?10 ; error
3421 ?08: ldy #$16 ; pointer to fat size (FAT16)
3422 lda [pbrp],y
3423 sta fatsiz
3424 beq ?10 ; hmmm... is fat32... not good
3425 cmp #257 ; fat16 table size limited to 256 sec. max
3426 bra ?12
3427 ?10: sec
3428 ?12: CPU08
3429 bcs ?18 ; error
3430 ldy #$15 ; pointer to media byte
3431 lda [pbrp],y ; must be $F8
3432 cmp #$F8
3433 bne ?16
3434 ldy #$10 ; pointer to count of fat table's
3435 lda [pbrp],y
3436 cmp #2 ; must be 2
3437 bne ?16
3438 ldy #$0D ; pointer to sector(s) per cluster
3439 lda [pbrp],y
3440 ldx #CLSCNT-1
3441 ?14: cmp >CLSSIZE,x
3442 beq ?20
3443 dex
3444 bpl ?14
3445 ?16: sec
3446 ?18: rts
3447 ?20: sta clssiz
3448 dec a
3449 sta clsmod
3450 lda >CLSSHIFT,x
Tue Jul 17 11:00:20 2018 Page 16
3451 sta clsshf
3452 clc
3453 rts
3454
3455 @
3456
3457
3458 ;---------------------------------------------------------------------------
3459 ; tables
3460 ;---------------------------------------------------------------------------
3461
3462 ; address of pbr buffer of fixed disk's
3463 F902F3 PBRBUFL:
3464 ;.DB <_pbr0, <_pbr1, <_pbr2, <_pbr3
3465 F902F3 PBRBUFH:
3466 F902F3 8C 8E 90 92 .DB >_pbr0, >_pbr1, >_pbr2, >_pbr3
3467 F902F7
3468 ; sector's per cluster table
3469 F902F7 CLSSIZE:
3470 F902F7 01 02 04 08 10 .DB $01, $02, $04, $08, $10, $20, $40
20 40
3471
3472 000007 CLSCNT .EQU $-CLSSIZE
3473
3474 ; sector's per cluster shift table
3475 F902FE CLSSHIFT:
3476 F902FE 00 01 02 03 04 .DB $00, $01, $02, $03, $04, $05, $06
05 06
Lines Assembled : 3455 Errors : 0