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\fsint.asm
Output Filename : obj\F9\fsint.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:20 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:20 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:20 2018 Page 4
2766
2767 .ENDS
2768
2769 [01] .IFDEF _ACIA_INC_
2770 .INCLUDE INC\SP.INC
2771 [00] .ENDIF
2772
2786 .LIST on
2787
2788 000060 KBDBUFLEN .EQU 96 ; dimensione buffer di tastiera
2789
2790 DIRP01: .SECTION page0, ref_only, common ;Direct-Page 01
2791
2792 000000 .ABSOLUTE ;; inizia sempre da $00
2793 000000 .ORG 0x00
2794
2795 000000
2796 000000 KbdBuf .DS KBDBUFLEN ; buffer della tastiera
2797 000060 00 KbdITail .DB ; coda buffer tastiera
2798 000061 00 KbdIHead .DB ; testa buffer tastiera
2799 000062 00 KbdCnt .DB ; numero bytes nel buffer
2800 000063 00 KbdShift .DB
2801 000064 00 KbdFlag .DB
2802 000065 00 KbdToggle .DB
2803 000066 00 KbdSt .DB ; status tastiera dopo reset
2804 000067 00 PS2Ctl .DB ; flag controller PS2 keyboard
2805
2806 000068 00 LCDFlag .DB
2807 000069 00 LCDTmp .DB
2808 00006A 0000 LCDVal .DW
2809
2810 00006C 00 VBBFlag .DB ; flag video board
2811 00006D 00 VBBRam .DB ; flag video RAM
2812
2813 00006E 00 ScnLinTmp .DB
2814 00006F 00 ScnChBase .DB ; base video ram VDC
2815 000070 00 ScnAttBase .DB ; base ram attributi VDC
2816 000071 00 ScnCursMode .DB ; VDC cursore default
2817 000072 00 ScnSaveAttr .DB
2818 000073 00 ScnInsert .DB
2819 000074 00 ScnAutoIns .DB ; bit 7 -> autoins - bit 6 -> modo input
2820 000075 00 ScnScroll .DB
2821 000076 00 ScnMaxRow .DB ; max. righe finestra (-1)
2822 000077 00 ScnMaxCols .DB ; max. colonne finestra (-1)
2823
2824 000078 ScnMapTabs1 .DS 10
2825 000082 ScnMapTabs2 .DS 4
2826 000086
2827 000086 0000 ScnPtr .DW ; puntatore video ram linea corrente
2828 000088 00 .DB
2829
2830 000089 00 ScnFiltLen .DB ; lunghezza set caratteri filtro
2831
2832 00008A 0000 ScnAtPtr .DW ; puntatore attributi ram linea corrente
2833 00008C 00 .DB
2834
2835 00008D 00 ScnTmpx .DB ; temporaneo: durante put char
Tue Jul 17 11:00:20 2018 Page 5
2836 00008E
2837 00008E 00 ScnTop .DB ; riga superiore finestra
2838 00008F 00 ScnLeft .DB ; colonna sinistra finestra
2839 000090 00 ScnBottom .DB ; riga inferiore finestra
2840 000091 00 ScnRight .DB ; colonna destra finestra
2841 000092 00 ScnAttr .DB ; attributo default
2842 000093 00 ScnAttr2 .DB ; attributo alternativo
2843 000094 00 ScnRow .DB ; riga cursore
2844 000095 00 ScnCol .DB ; colonna cursore
2845 000096 00 ScnRowStart .DB ; riga di start input
2846 000097 00 ScnInput .DB ; riga di fine input
2847 000098 00 ScnColStart .DB ; colonna di start input
2848 000099 00 ScnSaveX .DB
2849 00009A 00 ScnSaveY .DB
2850 00009B 00 ScnTmpL .DB
2851 00009C 00 ScnTmpH .DB
2852 00009D 00 ScnSaveRow .DB
2853 00009E 00 ScnSaveCol .DB
2854 00009F 00 ScnCurChr .DB
2855 0000A0 00 ScnLstChr .DB
2856 0000A1 00 ScnCR .DB
2857 0000A2 0000 ScnPrm .DW ; puntatore long utilizzato da print imm
2858 0000A4 00 .DB ; banco puntatore ScnPrm
2859 0000A5 00 ScnMode .DB ; flag modo schermo
2860
2861 0000A6 ScnPtr1 LP
2862
2863 0000A9 00 ScnDefCol .DB ; default foreground color
2864
2865 0000AA ScnPtr2 LP
2866
2867 0000AD 00 ScnDefBkgCol .DB ; default background color
2868 0000AE 00 ScnInpRow .DB ; modo input line: riga start input
2869 0000AF 00 ScnInpCol .DB ; modo input line: colonna start input
2870 0000B0 00 ScnLstRow .DB ; modo input line: riga stop input
2871 0000B1 00 ScnLstCol .DB ; modo input line: colonna stop input
2872 0000B2 00 ScnFlag .DB ; Bit 7: input line - Bit 6: input riga unica
2873 0000B3 00 ScnMask .DB ; flag tasti funzione editor di linea
2874 0000B4 00 ScnFilt .DB ; filtro tasti editor di linea
2875 0000B5 00 ScnCntrl .DB ; flag ASCII/CONTROL
2876 ;DflTxtIn .DB ; device di default text input
2877 ;DflTxtOut .DB ; device di default text output
2878 0000B6
2879 000047 SCNCLRLEN .EQU ($ - ScnLinTmp - 1)
2880
2881 ;SCNCLRLEN .EQU (DflTxtOut - ScnLinTmp)
2882
2883 ; variabili monitor
2884 0000B6 00 SMAddrL .DB ; address low/high
2885 0000B7 00 SMAddrH .DB
2886 0000B8 00 SMAddrK .DB ; address bank
2887 0000B9 00 SMFlag32 .DB ; flag parametro 32 bit
2888 0000BA 00 SMTmpL .DB ; temp. low/high
2889 0000BB 00 SMTmpH .DB
2890 0000BC 00 SMTmpK .DB ; temp. bank
2891 0000BD 00 SMTmpKK .DB ; high byte param. 32 bit
2892 0000BE 00 SMSizeL .DB ; size low/high
Tue Jul 17 11:00:20 2018 Page 6
2893 0000BF 00 SMSizeH .DB
2894 0000C0 00 SMSizeK .DB ; size bank
2895 0000C1 00 SMXAddrL .DB ; address low/high XM
2896 0000C2 00 SMXAddrH .DB
2897 0000C3 00 SMXAddrK .DB ; address bank XM
2898 0000C4 00 SMbndx .DB ; indice input buffer
2899 0000C5 00 SMnprm .DB ; numero parametri riga di comando
2900 0000C6 00 SMdumb .DB
2901 0000C7 00 SMkr .DB
2902 0000C8 0000 SMpc .DW
2903 0000CA 00 SMsr .DB
2904 0000CB 00 SMbr .DB
2905 0000CC 0000 SMdp .DW
2906 0000CE 0000 SMac .DW
2907 0000D0 0000 SMxr .DW
2908 0000D2 0000 SMyr .DW
2909 0000D4 0000 SMsp .DW
2910
2911 0000D6 00 SMAuxL .DB
2912 0000D7 00 SMAuxH .DB
2913
2914 0000D8 00 asmlong .DB ; flag for CPU in 16 mode
2915 ; <7> -> A/M in 16 bit mode
2916 ; <6> -> X/Y in 16 bit mode
2917 0000D9 00 asmcpu .DB ; <7> -> 8 bit family
2918 ; <6> -> 65C02 cmos version
2919
2920 0000DA 00 SMctx .DB ; context (if = $00 no quit command)
2921 0000DB SMrsm LP ; long pointer to resume caller context
2922
2923 0000DE 00 rtcadr .DB ; rtc internal ram address
2924 0000DF 00 rtcbnk .DB ; RTC internal bank ram
2925 0000E0 00 cmdlin .DB ;
2926 0000E1 00 SMesc .DB
2927
2928 0000E2 SMXTmp: .DS 26 ; 26 bytes tmp
2929
2930 0000E2 SMTmp2 .EQU SMXTmp
2931 0000E4 SMTmp3 .EQU SMXTmp+2
2932 0000E6 SMdwTmp1 .EQU SMXTmp+4
2933 0000EA SMdwTmp2 .EQU SMXTmp+8
2934 0000EE SMFsrc .EQU SMXTmp+12 ; source bank for flash update
2935 0000EF SMFflag .EQU SMXTmp+13 ; flag file for flash update
2936 0000F0 SMXPos2 .EQU SMXTmp+14
2937 0000F1 SMYPos2 .EQU SMXTmp+15
2938 0000F2 SMXPos3 .EQU SMXTmp+16
2939 0000F3 SMYPos3 .EQU SMXTmp+17
2940 ;SMAuxL .EQU SMXTmp+18
2941 ;SMAuxH .EQU SMXTmp+19
2942 0000F6 SMXPos .EQU SMXTmp+20
2943 0000F7 SMYPos .EQU SMXTmp+21
2944 0000F8 SMdwTmp3 .EQU SMXTmp+22
2945
2946 0000E2 atcmd .EQU SMXTmp ; save @ command
2947 0000E3 atnum .EQU SMXTmp+1 ; @ command index
2948 0000E4 atflag .EQU SMXTmp+2 ; @ L,S,V,R,W start address flag
2949 0000E5 atbnk .EQU SMXTmp+3 ; @ L,S,V,R,W bank
Tue Jul 17 11:00:20 2018 Page 7
2950 0000E6 atstr .EQU SMXTmp+4 ; @ command string start (word)
2951 0000E8 atstart .EQU SMXTmp+6 ; @ L,S,V,R,W start address (word)
2952 0000EA atend .EQU SMXTmp+8 ; @ S,W end address (word)
2953 0000EC atbuf .EQU SMXTmp+10 ; @ local buffer pointer (word)
2954 0000EE atipb .EQU SMXTmp+12 ; @ bank of input buffer
2955 0000EF atdir .EQU SMXTmp+13 ; @ load dir flag
2956 0000F0 atptr .EQU SMXTmp+14 ; @ load dir pointer (word)
2957 0000F2 atsiz .EQU SMXTmp+16 ; @ buffer size (word)
2958 0000F5 atlp .EQU SMXTmp+19 ; @ long pointer
2959 0000F8 atsa .EQU SMXTmp+22 ; @ sa
2960
2961 0000E2 btmpx .EQU SMXTmp ; asc2bin conversion
2962 0000E3 brtcsec .EQU SMXTmp+1
2963 0000E4 brtcmin .EQU SMXTmp+2
2964 0000E5 brtchour .EQU SMXTmp+3
2965 0000E6 brtcday .EQU SMXTmp+4
2966 0000E7 brtcmonth .EQU SMXTmp+5
2967 0000E8 brtcyear .EQU SMXTmp+6
2968 0000E9 brtcct .EQU SMXTmp+7
2969
2970
2971 0000FC .RELATIVE
2972
2973 .ENDS
2974
2998 .LIST on
2999
3000 ;---------------------------------------------------------------------------
3001
3002 000020 HPLMAX .EQU 32 ; Max. subdirectory level
3003
3004 000200 BCBCNT .EQU $200 ; BCB's struct's count #
3005 000C00 BCBXBNK .EQU $0C00 ; starting BCB x-mem buffer #
3006 000040 DMACNT .EQU 64
3007
3008 0000E0 FAT0X .EQU $E0 ; x-mem bank for fat table of ata #0
3009 0000F0 FAT1X .EQU $F0 ; x-mem bank for fat table of ata #1
3010
3011 F8FFB1 .INCLUDE INC\LDT.INC
3012 ; LDT.INC
3013
3014 [01] .IFNDEF __LDT_INC__
3015 000001 __LDT_INC__ .SET 1
3016
3017 .LIST on
3018 ;---------------------------------------------------------------------------
3019 ; Logical Drive Table (LDT) -- page 0 offset's
3020 ;---------------------------------------------------------------------------
3021
3022 F8FFB1 STRUCT LDT
3023 _LDT .SECTION page0,common,ref_only,offset 0 ;LDT Struct
3024 ;.ABSOLUTE
3025 ;.ORG 0
3026 .MNLIST
3027 000000 00 ldt_fg1 .DB ; logical volume flag's
3028 ; <7>: device ready (fdc drive or ata device)
3029 ; <6>: if=1->HD/CF else->FD
Tue Jul 17 11:00:20 2018 Page 8
3030 ; <1:0>: phisycal device number
3031
3032 000001 00 ldt_fg2 .DB ; <7>: valid volume (fat volume or cbm disk)
3033 ; <6>: if=1->FAT else->CBM (FD only)
3034 ; <5>: disk format checked
3035 ; <1:0>: disk format (fdc only)
3036
3037 000002 0000 ldt_root .DW ; lba of root dir
3038 000004 0000 ldt_fat1 .DW ; lba of fat1 table
3039 000006 0000 ldt_fat2 .DW ; lba of fat2 table
3040 000008 0000 ldt_cls .DW ; lba of first data cluster
3041 00000A 0000 ldt_max .DW ; max usable cluster + 1
3042 00000C 0000 ldt_rent .DW ; root dir. max. entries
3043 00000E 0000 ldt_cent .DW ; max. entries in dir. cluster
3044 000010 0000 ldt_eoc .DW ; end of cluster chain marker
3045 000012 0000 ldt_free .DW ; count of free cluster's
3046 000014 0000 ldt_nxt .DW ; next free cluster
3047 000016 0000 ldt_fsiz .DW ; fat table size
3048
3049 000018 00 ldt_csiz .DB ; cluster size (1,2,4,8,16,32,64)
3050 000019 00 ldt_cshf .DB ; cluster shift (0,1,2,3,4,5,6)
3051 00001A 00 ldt_rsiz .DB ; root dir. size (sector's)
3052 00001B 00 ldt_mcls .DB ; mask for clust. module: 00,01,03,07,0F,1F,3F
3053 00001C 0000 ldt_cdlp .DW ; current working dir list pointer
3054 00001E 0000 ldt_cdcls .DW ; current working dir start cluster
3055 000020 00 ldt_cdlvl .DB ; current working dir level count
3056
3057 000021 00 ldt_ptype .DB
3058 000022 0000 0000 ldt_pstart .LWORD
3059 000026 0000 0000 ldt_psize .LWORD
3060
3061 000022 ldt_fp .EQU ldt_pstart ; fat table buffer long pointer
3062 000025 ldt_fbuf .EQU ldt_pstart+3 ; fat table: x-mem base bank/dma buffer
3063
3064 000026 ldt_pbr .EQU ldt_psize ; long pointer to PBR cache buffer
3065 000029 ldt_fmt .EQU ldt_psize+3
3066
3067 00002A ESTRUCT LDT
3068 00002A LDTSIZE .DS 0
3069 ;.RELATIVE
3070 .ENDS
3071 .MNLIST
3072
3073 [00] .ENDIF
3074
3075 F8FFB1
3076 ;---------------------------------------------------------------------------
3077 ; Hierarchical Path List (HPL) -- 16 bit offset's
3078 ;---------------------------------------------------------------------------
3079
3080 F8FFB1 LSTRUCT HPL
3081 _HPL .SECTION common,ref_only,offset 0 ;HPL Struct
3082 .MNLIST
3083 000000 0000 hpl_cls .DW ; parent cluster
3084 000002 0000 hpl_ix .DW ; entry index in parent cluster
3085 000004 hpl_fcb .DS 11 ; fcb name
3086 00000F 00 hpl_lst .DB ; unused
Tue Jul 17 11:00:20 2018 Page 9
3087 000010 ESTRUCT HPL
3088 000010 HPLSIZE .DS 0
3089 ;.RELATIVE
3090 .ENDS
3091 .MNLIST
3092
3093 ;---------------------------------------------------------------------------
3094 ; Buffer Control Block (BCB) -- 16 bit offset's
3095 ;---------------------------------------------------------------------------
3096
3097 F8FFB1 LSTRUCT BCB
3098 _BCB .SECTION common,ref_only,offset 0 ;BCB Struct
3099 .MNLIST
3100 000000 0000 bcb_next .DW ; next logical linked BCB
3101 000002 00 bcb_drv .DB ; logical drive
3102 000003 00 bcb_sec .DB ; sector offset
3103 000004 0000 bcb_cls .DW ; cluster
3104 000006 0000 bcb_lba .DW ; sector lba address
3105 000008 0000 bcb_lbah .DW ; lba high
3106 000008 bcb_head .EQU bcb_lbah ; floppy head
3107 00000A 0000 bcb_buf .DW ; x-mem buffer number
3108 00000A bcb_trk .EQU bcb_buf ; floppy track(low) & sector(hi)
3109 00000C 0000 bcb_ptr .DW ; buffer pointer
3110 00000E 0000 bcb_xbnk .DW ; buffer pointer hi & x-mem bank
3111 00000E bcb_dma .EQU bcb_xbnk ; buffer pointer hi & dma buffer
3112 000010 ESTRUCT BCB
3113 000010 BCBSIZE .DS 0
3114 ;.RELATIVE
3115 .ENDS
3116 .MNLIST
3117
3118 ;---------------------------------------------------------------------------
3119 ; hash Control Block (BCB) -- 16 bit offset's
3120 ;---------------------------------------------------------------------------
3121
3122 F8FFB1 LSTRUCT HCB
3123 _HCB .SECTION common,ref_only,offset 0 ;HCB Struct
3124 .MNLIST
3125 000000 0000 hcb_next .DW ; pointer to next HCB
3126 000002 0000 hcb_cls .DW ; cluster number
3127 000004 0000 hcb_seq .DW ; sequence number + logical drive number
3128 000006 0000 hcb_cnt .DW ; number of hashed entries
3129 000008 hcb_data .DS 0 ; hash buffer data
3130 000008 ESTRUCT HCB
3131 000008 HCBSIZE .DS 0
3132 ;.RELATIVE
3133 .ENDS
3134 .MNLIST
3135
3136 ;---------------------------------------------------------------------------
3137 ; TOS Working Segment
3138 ;---------------------------------------------------------------------------
3139
3140 000001 WKB .EQU .SEG.TOSSEG ; TOS working bank
3141
3142 010000 TS .SET TOSSEG
3143 01FFFF TE .SET TOSSEG + $FFFF
Tue Jul 17 11:00:20 2018 Page 10
3144 018C00 TO0 .SET $018C00
3145 019E00 TO1 .SET TOSWKM
3146
3147 .comment @
3148 _TOS0: .SECTION ref_only, common, offset TO0, range TS TE ;FAT Struct's
3149 _TOS0_START .DS 0
3150
3151 _pbr0 .DS 512
3152 _pbr1 .DS 512
3153 _pbr2 .DS 512
3154 _pbr3 .DS 512
3155
3156 _TOS0_END .DS 0
3157 TOS0SIZ .EQU (_TOS0_END - _TOS0_START)
3158 .ENDS
3159 @
3160
3161 _TOS1: .SECTION ref_only, common, offset TO1, range TS TE ;FAT Struct's
3162 019E00 _TOS1_START .DS 0
3163
3164 ; current working directory HPL
3165 019E00 cwdl0 .DS (HPLSIZE*HPLMAX)
3166 01A000 cwdl1 .DS (HPLSIZE*HPLMAX)
3167 01A200 cwdl2 .DS (HPLSIZE*HPLMAX)
3168 01A400 cwdl3 .DS (HPLSIZE*HPLMAX)
3169
3170 ; current building path HPL
3171 01A600 cbpl .DS (HPLSIZE*HPLMAX)
3172 01A600 HPL_CLS .EQU hpl_cls+cbpl
3173 01A602 HPL_IX .EQU hpl_ix+cbpl
3174 01A604 HPL_FCB .EQU hpl_fcb+cbpl
3175
3176 ; BCB list's
3177 01A800 bcbstart .DS (BCBCNT*BCBSIZE)
3178 01C800 bcbend .DS 0
3179 01C800 dmastart .DS (DMACNT*BCBSIZE)
3180 01CC00 dmaend .DS 0
3181 01CC00 dma0s .DS (17*BCBSIZE)
3182 01CD10 dma1s .DS (17*BCBSIZE)
3183
3184 01CE20 _TOS1_END .DS 0
3185 003020 TOS1SIZ .EQU (_TOS1_END - _TOS1_START)
3186 .ENDS
3187
3188 ;---------------------------------------------------------------------------
3189 ; HCB Segment
3190 ;---------------------------------------------------------------------------
3191
3192 000004 HCBBNK .EQU .SEG.HCBSEG
3193 040000 HS .SET HCBSEG
3194 04FFFF HE .SET HCBSEG + $FFFF
3195 040000 HO .SET HCBSEG
3196
3197 _HCBS: .SECTION ref_only, common, offset HO, range HS HE ;HCB's List
3198 040000 hcb_bnk .DS 8
3199 040008 hcbstart .DS 0
3200 .ENDS
Tue Jul 17 11:00:20 2018 Page 11
3201
3202 ;.comment @
3203 ;---------------------------------------------------------------------------
3204 ; direct page for LDT var's
3205 ;---------------------------------------------------------------------------
3206
3207 ; P0OS
3208 DPOS: .SECTION page0, common, ref_only, offset 0 ;OS Main D.P.
3209
3210 ;sysbuf .DS 2 ; floppy track 0 cache buffer
3211 000000 00 defhsec .DB ; default hidden sector's in fdisk
3212 000001 00 .DB
3213 000002 0000 cmdstk .DW ; saved stack on TOS command's
3214 000004 bpath .DS 80
3215
3216 000054 bpath1 .DS 0
3217 .ENDS
3218 ;@
3219
3220 ; P0LDT
3221 DPLDT: .SECTION page0, common, ref_only, offset 0 ;LDT D.P.
3222
3223 000000 ldt0 .DS LDTSIZE
3224 00002A ldt1 .DS LDTSIZE
3225 000054 ldt2 .DS LDTSIZE
3226 00007E ldt3 .DS LDTSIZE
3227 0000A8 ldt4 .DS LDTSIZE
3228
3229 0000D2 ldtp .DS 6 ; pointer to LDT's in DPLDT page
3230
3231 0000D8 sysbuf .DS 4 ; floppy track 0 cache buffer
3232
3233 .ENDS
3234
3235 ;---------------------------------------------------------------------------
3236 ; direct page for FAT var's
3237 ;---------------------------------------------------------------------------
3238
3239 ; P0FAT
3240 DPFAT: .SECTION page0, common, ref_only, offset 0 ;FAT D.P.
3241
3242 000000 0000 ostos .DW ; saved top of stack
3243 000002 00 ioerr .DB ; i/o error
3244 000003 00 ioerr2 .DB ; extended i/o error
3245 000004 0000 hcbroot .DW ; HCB struct's list
3246 000006 0000 hcblst .DW ; the last one HCB
3247 000008 00 hsiz .DB ; how many sector's an HCB can hold
3248 000009 00 hlog2 .DB ; shift count related to hsiz
3249 00000A 0000 bcbroot .DW ; BCB buffer's list
3250 00000C 0000 bcblst .DW ; the last one BCB
3251 00000E 0000 dmaroot .DW ; dma BCB buffer's list
3252 000010 0000 dmalst .DW ; the last one dma BCB
3253 000012 0000 dmabcb .DW ; BCB list for floppy root, cluster#2,#3
3254 000014 00 fspt .DB ; sector per track (floppy)
3255 000015 00 pdrive .DB ; phisycal drive number
3256 000016 00 bplvl .DB ; subdir level while build path
3257 000017 00 defdrv .DB ; default drive
Tue Jul 17 11:00:20 2018 Page 12
3258
3259 ; the first block of ldt_ var's is copied from the LDT struct
3260 000018 00 ldtfg1 .DB ; logical volume flag's
3261 ; <7>: device ready (fdc drive or ata device)
3262 ; <6>: if=1->HD/CF else->FD
3263 ; <0>: phisycal device number
3264
3265 000019 00 ldtfg2 .DB ; <7>: valid volume (fat volume or cbm disk)
3266 ; <6>: if=1->FAT else->CBM (FD only)
3267 ; <5>: disk format checked
3268 ; <1:0>: disk format (fdc only)
3269
3270 00001A ldtfp LP ; fat table buffer long pointer
3271 00001D 00 ldtfbuf .DB ; fat table: x-mem base bank/dma buffer
3272
3273 00001E 0000 ldtroot .DW ; lba of root dir
3274 000020 0000 ldtfat1 .DW ; lba of fat1 table
3275 000022 0000 ldtfat2 .DW ; lba of fat2 table
3276 000024 0000 ldtcls .DW ; lba of first data cluster
3277 000026 0000 ldtmax .DW ; max usable cluster + 1
3278 000028 00 ldtcsiz .DB ; cluster size (1,2,4,8,16,32,64)
3279 000029 00 ldtcshf .DB ; cluster shift (0,1,2,3,4,5,6)
3280 00002A 00 ldtfsiz .DB ; fat table size (if 0 -> 256)
3281 00002B 00 ldtrsiz .DB ; root dir. size (sector's)
3282 00002C 0000 ldtrent .DW ; root dir. max. entries
3283 00002E 0000 ldtcent .DW ; max. entries in dir. cluster
3284 000030 0000 ldteoc .DW ; end of cluster chain marker
3285 000032 00 ldtmcls .DB ; mask for clust. module: 00,01,03,07,0F,1F,3F
3286 000033 00 ldtfmt .DB ; floppy disk format (0,1,2, FF if ata device)
3287 000034 0000 ldtcdlp .DW ; current working dir list pointer
3288 000036 0000 ldtcdcls .DW ; current working dir start cluster
3289 000038 0000 ldtfree .DW ; count of free cluster's
3290 00003A 0000 ldtnxt .DW ; next free cluster
3291 00003C 00 ldtcdlvl .DB ; current working dir level count
3292 00003D ldtpbr LP ; long pointer to PBR cache buffer
3293
3294 000040 0000 chdcls .DW ; last accessed chained dir. cluster
3295 000042 0000 clsofs .DW ; cluster's offset from start of chain
3296
3297 ; not change order of the 2 following var's: will be accessed as 16 bit var
3298 000044 00 entofs .DB ; entry offset from start of sector
3299 000045 00 secofs .DB ; sector's offset from start of cluster
3300
3301 000046 0000 dircls .DW ; directory cluster
3302 000048 0000 dcnt .DW ; directory entry counter
3303 00004A 0000 lba .DW ; lba sector address
3304 00004C 0000 lbah .DW ; lba is 24 bit's only
3305 00004E 0000 xbuf .DW ; x-mem buffer transfer number
3306
3307 00004C fhead .EQU lbah ; fd head
3308 00004E ftrack .EQU xbuf ; fd track
3309 00004F fsec .EQU xbuf+1 ; fd sector
3310
3311 000050 00 dfcbtyp .DB ; FCB type to search
3312 000051 00 dfcbatt .DB ; attribute of found FCB
3313
3314 000052 00 curdrv .DB ; current logical drive
Tue Jul 17 11:00:20 2018 Page 13
3315 000053 fcbs .DS 11 ; file control block name
3316
3317 ;dcmask .DW ; mask to start of cluster
3318 ; FFF0, FFE0, FFC0, FF80, FF00, FE00
3319
3320 00005E 0000 fcbp .DW ; FCB buffer long pointer
3321 000060 0000 .DW ; low=fcbp+2, high=x-mem bank or dma buffer
3322 000061 dmabuf .EQU fcbp+3 ; dma buffer #
3323 000061 xmbank .EQU fcbp+3 ; x-mem bank #
3324
3325 ; temp area
3326 000062 00 hcbseq .DB
3327 000063 00 hcbdrv .DB
3328 000064 0000 bcbcls .DW
3329 000066 00 bcbdrv .DB
3330 000067 00 bcbsec .DB
3331
3332 000068 0000 thash .DW
3333 000068 hcbrec .EQU thash
3334 000068 wtmp .EQU thash
3335
3336 00006A 0000 hlast .DW
3337 00006C 0000 hcbcls .DW
3338 00006E 0000 hcbx .DW
3339 000070 0000 hcby .DW
3340 00006A tmpp .EQU hlast ; temp. long pointer
3341 00006E tmpx .EQU hcbx
3342 00006F wild .EQU hcbx+1
3343 000070 fsiz .EQU hcby
3344 000071 fptr .EQU hcby+1
3345 00006E ldrv .EQU hcbx
3346 00006F tmpldt .EQU hcbx+1
3347
3348 000072 0000 fhash .DW
3349 000074 0000 fcbofs .DW
3350 000076 00 bcbload .DB
3351 000077 00 xstart .DB
3352 000078 00 xend .DB
3353 000079 00 seccnt .DB
3354 00007A 00 maxseq .DB
3355 00007B 00 dsiz .DB
3356
3357 00007C 00 haswld .DB
3358 00007D 00 strix .DB
3359 00007E pathp LP ; long pointer to path string
3360
3361 ; TEMP
3362 000081 0000 quot .DW
3363 000083 0000 dvsor .DW
3364 000085 0000 troot .DW
3365 000087 0000 tlst .DW
3366 000089 0000 bdmask .DW
3367 00008B 0000 bcmask .DW
3368
3369 00008D 00 hcbuse .DB
3370
3371 .ENDS
Tue Jul 17 11:00:20 2018 Page 14
3372
3377 .LIST on
3378
3379 ; P0OS
3380 ; page 0 (LDT var's) local var's
3381 _FSTMP: .SECTION page0, ref_only, offset bpath
3382 000004 FSTMP_START .EQU $
3383
3384 000004 0000 0000 maxsec .LWORD ; ata device max sector's
3385 000008 0000 0000 hidsec .LWORD ; hidden sectors
3386 00000C 0000 0000 totsec .LWORD ; partition size in sector's
3387 000010 0000 maxcnt .DW ; max. cluster's count
3388 000012 0000 first .DW ; relative first data sector
3389
3390 000012 totrsv .EQU first
3391 000004 bcbbnk .EQU maxsec
3392 000006 hcbsiz .EQU maxsec+2
3393 000010 hcbrem .EQU maxcnt
3394 000004 tbdrv .EQU maxsec
3395 000006 tbcls .EQU maxsec+2
3396 000008 tblba .EQU hidsec
3397 00000A tbhead .EQU hidsec+2
3398 00000C tbtrk .EQU totsec
3399 00000E tbptr .EQU totsec+2
3400 000010 tbdma .EQU maxcnt
3401 000004 fdopt .EQU maxsec
3402 000005 fdarg .EQU maxsec+1
3403 000006 fdlbl .EQU maxsec+2
3404
3405 000014 0000 clscnt .DW ; cluster's count #
3406 000016 0000 rsvsec .DW ; reserved sector's
3407 000018 0000 fatsiz .DW ; FAT16 fat table size
3408 00001A 0000 rootsiz .DW ; root directory size
3409 00001C 0000 rootent .DW ; root dir. max. entries
3410 00001E 0000 clsent .DW ; sub-diectory max. entries
3411 000020 0000 root .DW ; root dir start
3412 000022 0000 fat1 .DW ; fat1 table start
3413 000024 0000 fat2 .DW ; fat 2 table start
3414 000026 0000 start .DW ; first data sector
3415 000028 0000 maxcls .DW ; last usable cluster+1
3416 00002A 0000 xfatb .DW ; x-mem fat table buffer
3417
3418 00002A fdix .EQU xfatb ; floppy disk index DD/HD
3419 00002B media .EQU xfatb+1 ; floppy disk media field
3420
3421 00002C 0000 flba .DW ; low 16 bit lba
3422 00002E 0000 freecnt .DW ; free cluster's count
3423 000030 0000 freecls .DW ; first free cluster
3424
3425 00002E remsec .EQU freecnt
3426
3427 000032 pbrp LP ; PBR pointer
3428 000035 00 clssiz .DB ; cluster size
3429 000036 00 clsshf .DB ; cluster shift
3430 000037 00 clsmod .DB
3431 000038 00 xbnk .DB ; x-mem bank
3432 000039 00 lunit .DB ; unity letter
Tue Jul 17 11:00:20 2018 Page 15
3433 00003A tp LP ; fat cache pointer
3434 00003D 00 fdfmt .DB ; floppy format
3435 00003E 00 pdev .DB ; phisycal device
3436 00003F 00 ldev .DB ; logical device
3437 000040 00 ldtcur .DB ; current LDT ptr
3438 000041 00 lflag .DB ; flag load fat table
3439 000042 00 rtcsec .DB ; seconds
3440 000043 00 rtcmin .DB ; minutes
3441
3442 000042 badcls .EQU rtcsec
3443
3444 000044 00 rtchour .DB ; hours
3445 000045 00 rtcday .DB ; day of month
3446 000046 00 rtcmonth .DB ; month
3447 000047 00 rtcyear .DB ; year
3448 000048 0000 ctime .DW ; compact time
3449 00004A 0000 cdate .DW
3450 00004C tlp LP
3451 00004F 00 fd2ix .DB
3452
3453 00004F nulptr .EQU fd2ix ; flag null ptr
3454
3455 000050 00 rootbnk .DB
3456
3457 000050 getfmt .EQU rootbnk ; get format from floppy disk
3458
3459 000051 00 fatbnk .DB
3460 000052 00 clsbnk .DB
3461 000053 00 sec100 .DB ; tenths of seconds for ctime (ms stamp)
3462
3463 000050 FSTMP_SIZ .EQU ($-FSTMP_START)
3464 .ENDS
3468 .LIST on
3469 .GLOBAL ldt4
3470
3471 ; default hidden sectors
3472 00003F HIDSEC .EQU $3F
3473 ; default hashed sector's
3474 000001 DEFHSIZ .EQU 1
3475 000000 DEFHLOG2 .EQU 0
3476
3477 ; max. clusters count + 1
3478 00FFF5 MAXF16 .EQU $FFF5
3479 000FF5 MAXF12 .EQU $0FF5
3480 ; End-of-Chain marker (EOC marker)
3481 00FFF8 F16EOC .EQU $FFF8
3482 000FF8 F12EOC .EQU $0FF8
3483 F8FFB1
3484 ;---------------------------------------------------------------------------
3485 ; code segment -- bank $F9
3486 ;---------------------------------------------------------------------------
3487
3488 .CODEF9
3489 .PUBLIC fssetup, gctime16, bldldt, lhdfmt, shpart, lfdisk
3490 .EXTERN cbmfs_cmd
3491
3492 .LONGA off
Tue Jul 17 11:00:20 2018 Page 16
3493 .LONGI off
3494
3495 ;---------------------------------------------------------------------------
3496 ; setup
3497 ;---------------------------------------------------------------------------
3498
3499 F90305 lusbldt:
3500 .PUBLIC lusbldt
3501
3502 F90305 8B phb
3503 F90306 A9 00 lda #0
3504 F90308 48 pha
3505 F90309 AB plb
3506 F9030A 0B phd
3507 F9030B F4 00 40 pea #P0LDT
3508 F9030E 2B pld ; set dp page
3509 F9030F 20 15 03 jsr usbldt
3510 F90312 2B pld
3511 F90313 AB plb
3512 F90314 6B rtl
3513 F90315
3514 ; LDT for usb #0 device (E)
3515 F90315 usbldt:
3516 F90315 0B phd
3517 F90316 F4 00 42 pea #P0OS
3518 F90319 2B pld
3519 F9031A A2 29 ldx #LDTSIZE-1
3520 F9031C 74 A8 ?zm: stz ldt4,x
3521 F9031E CA dex
3522 F9031F 10 FB bpl ?zm
3523 F90321 AD 10 00 lda !usbdev ; phisycal usb #0 device
3524 F90324 29 C0 and #$C0
3525 F90326 09 02 ora #$02 ; phisycal drive #2
3526 F90328 8D A8 40 sta !P0LDT+ldt4+ldt_fg1
3527 F9032B A9 00 lda #<PBR0USB ; set PBR pointer
3528 F9032D 8D CE 40 sta !P0LDT+ldt4+ldt_pbr
3529 F90330 A9 96 lda #>PBR0USB
3530 F90332 8D CF 40 sta !P0LDT+ldt4+ldt_pbr+1
3531 F90335 A9 01 lda #^PBR0USB
3532 F90337 8D D0 40 sta !P0LDT+ldt4+ldt_pbr+2
3533 F9033A A9 FF lda #$FF
3534 F9033C 8D D1 40 sta !P0LDT+ldt4+ldt_fmt
3535 F9033F ACC16
3536 F9033F C2 20 rep #PMFLAG
3537 .LONGA on
3538 .MNLIST
3539 F90341 A9 F8 FF lda #F16EOC
3540 F90344 8D B8 40 sta !P0LDT+ldt4+ldt_eoc ; FAT16 end of chain marker
3541 F90347 ACC08
3542 F90347 E2 20 sep #PMFLAG
3543 .LONGA off
3544 .MNLIST
3545 F90349 2B pld
3546 F9034A A9 45 lda #'E' ; usb #0 device: 'E'
3547 F9034C 85 39 sta lunit ; logical drive letter
3548 F9034E SCNPRINT
3549 F9034E 02 01 cop $01
Tue Jul 17 11:00:20 2018 Page 17
3550 .MNLIST
3551 F90350 63 68 65 63 6B .DB 'check <E>: ', 0
20 3C 45 3E 3A
20 00
3552 F9035C AD 10 00 lda !usbdev
3553 F9035F C9 FF cmp #$FF
3554 F90361 F0 31 beq ?ok
3555 F90363
3556 F90363 SCNPRINT
3557 F90363 02 01 cop $01
3558 .MNLIST
3559 F90365 75 6E 70 61 72 .DB 'unpartitioned disk or invalid partition ID.', 13, 0
74 69 74 69 6F
6E 65 64 20 64
69 73 6B 20 6F
72 20 69 6E 76
61 6C 69 64 20
70 61 72 74 69
74 69 6F 6E 20
49 44 2E 0D 00
3560 F90392 38 sec
3561 F90393 60 rts
3562
3563 F90394 20 3C 0B ?ok: jsr usbchk16 ; check partition PBR
3564 F90397 90 29 bcc ?ok1
3565 F90399
3566 F90399 ?inv: SCNPRINT
3567 F90399 02 01 cop $01
3568 .MNLIST
3569 F9039B 69 6E 76 61 6C .DB 'invalid partition type (not FAT16).', 13, 0
69 64 20 70 61
72 74 69 74 69
6F 6E 20 74 79
70 65 20 28 6E
6F 74 20 46 41
54 31 36 29 2E
0D 00
3570 F903C0 38 sec
3571 F903C1 60 rts
3572 F903C2
3573 F903C2 20 18 0D ?ok1: jsr fcalc ; fat data calc
3574 F903C5 B0 D2 bcs ?inv ; invalid partition
3575 F903C7
3576 F903C7 ACC16 ; move LDT
3577 F903C7 C2 20 rep #PMFLAG
3578 .LONGA on
3579 .MNLIST
3580 F903C9 A5 20 lda root
3581 F903CB 8D AA 40 sta !P0LDT+ldt4+ldt_root
3582 F903CE A5 22 lda fat1
3583 F903D0 8D AC 40 sta !P0LDT+ldt4+ldt_fat1
3584 F903D3 A5 24 lda fat2
3585 F903D5 8D AE 40 sta !P0LDT+ldt4+ldt_fat2
3586 F903D8 A5 26 lda start
3587 F903DA 8D B0 40 sta !P0LDT+ldt4+ldt_cls
3588 F903DD A5 28 lda maxcls
3589 F903DF 8D B2 40 sta !P0LDT+ldt4+ldt_max
Tue Jul 17 11:00:20 2018 Page 18
3590 F903E2 A5 1C lda rootent
3591 F903E4 8D B4 40 sta !P0LDT+ldt4+ldt_rent
3592 F903E7 A5 1E lda clsent
3593 F903E9 8D B6 40 sta !P0LDT+ldt4+ldt_cent
3594 F903EC A5 2E lda freecnt
3595 F903EE 8D BA 40 sta !P0LDT+ldt4+ldt_free
3596 F903F1 A5 30 lda freecls
3597 F903F3 8D BC 40 sta !P0LDT+ldt4+ldt_nxt
3598 F903F6 ACC08
3599 F903F6 E2 20 sep #PMFLAG
3600 .LONGA off
3601 .MNLIST
3602 F903F8 A5 35 lda clssiz
3603 F903FA 8D C0 40 sta !P0LDT+ldt4+ldt_csiz
3604 F903FD A5 36 lda clsshf
3605 F903FF 8D C1 40 sta !P0LDT+ldt4+ldt_cshf
3606 F90402 A5 18 lda fatsiz
3607 F90404 8D BE 40 sta !P0LDT+ldt4+ldt_fsiz
3608 F90407 A5 1A lda rootsiz
3609 F90409 8D C2 40 sta !P0LDT+ldt4+ldt_rsiz
3610 F9040C A5 37 lda clsmod
3611 F9040E 8D C3 40 sta !P0LDT+ldt4+ldt_mcls
3612
3613 F90411 A9 E0 lda #$E0
3614 F90413 8D A9 40 sta !P0LDT+ldt4+ldt_fg2
3615 F90416 18 clc
3616 F90417 60 rts
3617
3618 F90418 fssetup:
3619 F90418 0B phd
3620 F90419 F4 00 42 pea #P0OS
3621 F9041C 2B pld ; set dp page
3622 F9041D A2 3B ldx #RTCSHID ; default hidden sector's (for fdisk)
3623 F9041F 8E 4C FD stx RTCALE ; from RTC RAM in bank 0 & 1
3624 F90422 AD 4D FD lda RTCDATA ; read saved value
3625 F90425 C9 40 cmp #$40 ; invalid?
3626 F90427 90 05 bcc ?01b ; no
3627 F90429 A9 3F ?01: lda #HIDSEC ; get default value
3628 F9042B 8D 4D FD sta RTCDATA ; save default value
3629 F9042E 85 00 ?01b: sta defhsec
3630 F90430 C9 00 cmp #0
3631 F90432 D0 07 bne ?01c
3632 F90434 A9 3F lda #HIDSEC ; get default value
3633 F90436 8D 4D FD sta RTCDATA ; save default value
3634 F90439 85 00 sta defhsec
3635 F9043B A2 3C ?01c: ldx #RTCHUSE ; flag use hash block's
3636 F9043D 8E 4C FD stx RTCALE
3637 F90440 AD 4D FD lda RTCDATA ; read saved value
3638 F90443 C9 FF cmp #$FF
3639 F90445 D0 05 bne ?02
3640 F90447 A9 80 lda #$80 ; default value (use hash)
3641 F90449 8D 4D FD sta RTCDATA ; save default value
3642 F9044C 8D 8D 41 ?02: sta !P0FAT+hcbuse
3643 F9044F A2 3D ldx #RTCHLOG2 ; sector's per hcb block
3644 F90451 8E 4C FD stx RTCALE
3645 F90454 AD 4D FD lda RTCDATA ; read saved value
3646 F90457 C9 FF cmp #$FF
Tue Jul 17 11:00:20 2018 Page 19
3647 F90459 F0 04 beq ?03
3648 F9045B C9 07 cmp #7 ; valid value: 0..6
3649 F9045D 90 05 bcc ?04
3650 F9045F A9 04 ?03: lda #$04 ; default value (16 sector's per block)
3651 F90461 8D 4D FD sta RTCDATA ; save default value
3652 F90464 8D 09 41 ?04: sta !P0FAT+hlog2
3653 F90467 AA tax
3654 F90468 BF 61 1C F9 lda >CLSSIZE,x ; get block size in sector's
3655 F9046C 8D 08 41 sta !P0FAT+hsiz
3656 F9046F ACC16
3657 F9046F C2 20 rep #PMFLAG
3658 .LONGA on
3659 .MNLIST
3660 F90471 A9 10 00 lda #16 ; get max. entries per block
3661 F90474 9B txy
3662 F90475 F0 04 beq ?04b ; no shift
3663 F90477 0A ?04a: asl a ; mult * 16 to get entries #
3664 F90478 CA dex
3665 F90479 D0 FC bne ?04a
3666 F9047B 0A ?04b: asl a ; 2 bytes per entry
3667 F9047C 69 08 00 adc #HCBSIZE ; plus HCB header
3668 F9047F 85 06 sta hcbsiz ; effective HCB size
3669 F90481 38 sec
3670 F90482 A9 00 00 lda #0
3671 F90485 E9 08 00 sbc #hcbstart
3672 F90488 85 10 sta hcbrem ; free room in bank
3673 F9048A A0 00 ldy #0
3674 F9048C CPU16
3675 F9048C C2 30 rep #(PMFLAG.OR.PXFLAG)
3676 .LONGA on
3677 .LONGI on
3678 .MNLIST
3679 F9048E A2 1E 30 ldx #TOS1SIZ-2 ; clear TOS work area
3680 F90491 98 tya
3681 F90492 9F 00 9E 01 ?05: sta >_TOS1_START,x
3682 F90496 CA dex
3683 F90497 CA dex
3684 F90498 10 F8 bpl ?05
3685 F9049A BB tyx
3686 F9049B 9F 00 00 04 ?10: sta >hcb_bnk,x ; clear HCB bank
3687 F9049F E8 inx
3688 F904A0 E8 inx
3689 F904A1 D0 F8 bne ?10
3690 F904A3 CPU08
3691 F904A3 E2 30 sep #(PMFLAG.OR.PXFLAG)
3692 .LONGA off
3693 .LONGI off
3694 .MNLIST
3695 F904A5 8B phb ; save dbr
3696 F904A6 A9 01 lda #WKB
3697 F904A8 48 pha
3698 F904A9 AB plb ; set dbr to fat work area
3699 F904AA CPU16
3700 F904AA C2 30 rep #(PMFLAG.OR.PXFLAG)
3701 .LONGA on
3702 .LONGI on
3703 .MNLIST
Tue Jul 17 11:00:20 2018 Page 20
3704 F904AC A9 00 0C lda #BCBXBNK ; init BCB struct's for at drive's buffer's
3705 F904AF 85 04 sta bcbbnk
3706 F904B1 A9 00 A8 lda #bcbstart
3707 F904B4 8F 0A 41 00 sta >P0FAT+bcbroot
3708 F904B8 AA tax
3709 F904B9 A5 04 ?15: lda bcbbnk
3710 F904BB 9D 0A 00 sta !bcb_buf,x
3711 F904BE 0A asl a
3712 F904BF 0A asl a
3713 F904C0 0A asl a
3714 F904C1 0A asl a ; x-mem bank
3715 F904C2 A8 tay
3716 F904C3 29 00 FF and #$FF00 ; low byte = buffer hi ptr
3717 F904C6 1A inc a ; bank 1
3718 F904C7 9D 0E 00 sta !bcb_xbnk,x ; store buffer high ptr + x-mem bank
3719 F904CA 98 tya
3720 F904CB EB xba ; C=0000,1000,2000,...,E000,F000
3721 F904CC 29 00 F0 and #$F000
3722 F904CF 4A lsr a
3723 F904D0 4A lsr a
3724 F904D1 4A lsr a ; C=0000,0200,0400,...,1C00,1E00
3725 F904D2 09 00 20 ora #XMSTART ; C=2000,2200,2400,...,3C00,3E00
3726 F904D5 9D 0C 00 sta !bcb_ptr,x
3727 F904D8 A9 FF FF lda #$FFFF
3728 F904DB 9D 02 00 sta !bcb_drv,x ; drive+sec = $FFFF -> unused
3729 F904DE E6 04 inc bcbbnk
3730 F904E0 8A txa
3731 F904E1 18 clc
3732 F904E2 69 10 00 adc #BCBSIZE
3733 F904E5 C9 00 C8 cmp #bcbend
3734 F904E8 B0 06 bcs ?20
3735 F904EA 9D 00 00 sta !bcb_next,x
3736 F904ED AA tax
3737 F904EE 80 C9 bra ?15
3738 F904F0 9E 00 00 ?20: stz !bcb_next,x ; last struct
3739 F904F3 8A txa
3740 F904F4 8F 0C 41 00 sta >P0FAT+bcblst
3741 F904F8 CPU08
3742 F904F8 E2 30 sep #(PMFLAG.OR.PXFLAG)
3743 .LONGA off
3744 .LONGI off
3745 .MNLIST
3746 F904FA A9 80 lda #BCBDMA ; init BCB's struct's in dma buffer's
3747 F904FC 85 05 sta bcbbnk+1 ; dma buffer # in high byte
3748 F904FE 20 96 06 jsr ?100 ; get dma bank
3749 F90501 84 04 sty bcbbnk
3750 F90503 CPU16
3751 F90503 C2 30 rep #(PMFLAG.OR.PXFLAG)
3752 .LONGA on
3753 .LONGI on
3754 .MNLIST
3755 F90505 A9 00 C8 lda #dmastart
3756 F90508 8F 0E 41 00 sta >P0FAT+dmaroot
3757 F9050C AA tax
3758 F9050D A9 FF FF ?25: lda #$FFFF ; invalidate buffer
3759 F90510 9D 02 00 sta !bcb_drv,x ; drive+sec = $FFFF -> unused
3760 F90513 A5 04 lda bcbbnk
Tue Jul 17 11:00:20 2018 Page 21
3761 F90515 9D 0E 00 sta !bcb_dma,x ; store buffer high ptr + dma buffer #
3762 F90518 A8 tay
3763 F90519 29 00 7F and #$7F00 ; strip off bit 15
3764 F9051C 0A asl a
3765 F9051D 9D 0C 00 sta !bcb_ptr,x ; buffer pointer
3766 F90520 98 tya
3767 F90521 EB xba
3768 F90522 1A inc a ; increment bank
3769 F90523 EB xba
3770 F90524 85 04 sta bcbbnk
3771 F90526 8A txa
3772 F90527 18 clc
3773 F90528 69 10 00 adc #BCBSIZE
3774 F9052B C9 00 CC cmp #dmaend
3775 F9052E B0 06 bcs ?30
3776 F90530 9D 00 00 sta !bcb_next,x ; pointer to next BCB
3777 F90533 AA tax
3778 F90534 80 D7 bra ?25
3779 F90536 9E 00 00 ?30: stz !bcb_next,x ; last struct
3780 F90539 8A txa
3781 F9053A 8F 10 41 00 sta >P0FAT+dmalst
3782 F9053E A2 00 CC ldx #dma0s
3783 F90541 A9 FF FF lda #$FFFF ; invalidate buffer
3784 F90544 9D 02 00 sta !bcb_drv,x ; drive+sec = $FFFF -> unused
3785 F90547 A2 10 CD ldx #dma1s
3786 F9054A 9D 02 00 sta !bcb_drv,x ; drive+sec = $FFFF -> unused
3787 F9054D CPU08
3788 F9054D E2 30 sep #(PMFLAG.OR.PXFLAG)
3789 .LONGA off
3790 .LONGI off
3791 .MNLIST
3792 F9054F A9 04 lda #HCBBNK ; init HCB struct's
3793 F90551 48 pha
3794 F90552 AB plb
3795 F90553 CPU16
3796 F90553 C2 30 rep #(PMFLAG.OR.PXFLAG)
3797 .LONGA on
3798 .LONGI on
3799 .MNLIST
3800 F90555 A9 08 00 lda #hcbstart
3801 F90558 8F 04 41 00 sta >P0FAT+hcbroot
3802 F9055C AA tax
3803 F9055D A9 FF FF ?35: lda #$FFFF
3804 F90560 9D 04 00 sta !hcb_seq,x ; unused HCB
3805 F90563 A5 10 lda hcbrem ; free room
3806 F90565 38 sec
3807 F90566 E5 06 sbc hcbsiz
3808 F90568 90 10 bcc ?40 ; no more room
3809 F9056A C5 06 cmp hcbsiz
3810 F9056C 90 0C bcc ?40 ; no more room
3811 F9056E 85 10 sta hcbrem ; save new free room
3812 F90570 8A txa
3813 F90571 18 clc
3814 F90572 65 06 adc hcbsiz
3815 F90574 9D 00 00 sta !hcb_next,x
3816 F90577 AA tax ; next HCB
3817 F90578 80 E3 bra ?35
Tue Jul 17 11:00:20 2018 Page 22
3818 F9057A 9E 00 00 ?40: stz !hcb_next,x ; last HCB
3819 F9057D 8A txa
3820 F9057E 8F 06 41 00 sta >P0FAT+hcblst
3821 F90582 CPU08
3822 F90582 E2 30 sep #(PMFLAG.OR.PXFLAG)
3823 .LONGA off
3824 .LONGI off
3825 .MNLIST
3826 F90584 AB plb ; restore dbr
3827 F90585 0B phd
3828 F90586 F4 00 40 pea #P0LDT ; switch to LDT D.P.
3829 F90589 2B pld
3830 F9058A A2 A8 ldx #ldt4 ; set up LDT ptr's
3831 F9058C 86 D6 stx ldtp+4 ; logical drive #4
3832 ;ldx #ldt5 ; set up LDT ptr's
3833 ;stx ldtp+5 ; logical drive #4
3834 F9058E A2 00 ldx #ldt0 ; set up LDT ptr's
3835 F90590 86 D2 stx ldtp ; logical drive #0
3836 F90592 AD 46 00 lda !fdcctl ; phisycal drive 0 ready flag
3837 F90595 29 80 and #$80
3838 F90597 95 00 sta ldt_fg1,x
3839 F90599 A2 2A ldx #ldt1
3840 F9059B 86 D3 stx ldtp+1 ; logical drive #1
3841 F9059D A9 81 lda #$81 ; virtual drive 1 always ready
3842 F9059F 95 00 sta ldt_fg1,x
3843 F905A1 A2 54 ldx #ldt2
3844 F905A3 86 D4 stx ldtp+2 ; logical drive #2
3845 F905A5 AD 0E 00 lda !atadev ; phisycal ata device #0
3846 F905A8 29 80 and #$80
3847 F905AA 09 40 ora #$40 ; ata device #0
3848 F905AC 95 00 sta ldt_fg1,x
3849 F905AE A2 7E ldx #ldt3
3850 F905B0 86 D5 stx ldtp+3 ; logical drive #3
3851 F905B2 AD 0F 00 lda !atadev+1 ; phisycal ata device #1
3852 F905B5 29 80 and #$80
3853 F905B7 09 41 ora #$41 ; ata device #1
3854 F905B9 95 00 sta ldt_fg1,x
3855 F905BB A9 00 lda #DR0SYS
3856 F905BD 85 D8 sta sysbuf ; drive 0 system track cache
3857 F905BF AA tax
3858 F905C0 E8 inx
3859 F905C1 86 25 stx ldt0+ldt_fbuf
3860 F905C3 20 96 06 jsr ?100
3861 F905C6 85 27 sta ldt0+ldt_pbr+1 ; set PBR pointer
3862 F905C8 84 28 sty ldt0+ldt_pbr+2
3863 F905CA 64 26 stz ldt0+ldt_pbr
3864 F905CC 1A inc a ; drive 0 fat table dma buffer
3865 F905CD 1A inc a
3866 F905CE 85 23 sta ldt0+ldt_fp+1 ; set fat pointer
3867 F905D0 84 24 sty ldt0+ldt_fp+2
3868 F905D2 64 22 stz ldt0+ldt_fp
3869 F905D4 A9 24 lda #DR1SYS
3870 F905D6 85 DA sta sysbuf+2 ; drive 1 system track cache
3871 F905D8 AA tax
3872 F905D9 E8 inx
3873 F905DA 86 4F stx ldt1+ldt_fbuf
3874 F905DC 20 96 06 jsr ?100
Tue Jul 17 11:00:20 2018 Page 23
3875 F905DF 85 51 sta ldt1+ldt_pbr+1 ; set PBR pointer
3876 F905E1 84 52 sty ldt1+ldt_pbr+2
3877 F905E3 64 50 stz ldt1+ldt_pbr
3878 F905E5 1A inc a ; drive 1 fat table dma buffer
3879 F905E6 1A inc a
3880 F905E7 85 4D sta ldt1+ldt_fp+1 ; set fat pointer
3881 F905E9 84 4E sty ldt1+ldt_fp+2
3882 F905EB 64 4C stz ldt1+ldt_fp
3883 F905ED A9 E0 lda #FAT0X
3884 F905EF 85 79 sta ldt2+ldt_fbuf ; fat cache buffer drive #2
3885 F905F1 A9 F0 lda #FAT1X
3886 F905F3 85 A3 sta ldt3+ldt_fbuf ; fat cache buffer drive #3
3887 F905F5 A9 20 lda #>XMSTART
3888 F905F7 A0 01 ldy #XMBANK
3889 F905F9 64 76 stz ldt2+ldt_fp ; set fat drive # 2 pointer
3890 F905FB 85 77 sta ldt2+ldt_fp+1
3891 F905FD 84 78 sty ldt2+ldt_fp+2
3892 F905FF 64 A0 stz ldt3+ldt_fp ; set fat drive # 3 pointer
3893 F90601 85 A1 sta ldt3+ldt_fp+1
3894 F90603 84 A2 sty ldt3+ldt_fp+2
3895 F90605 AF 89 1C F9 lda >PBRPTR2
3896 F90609 85 7C sta ldt2+ldt_pbr+2
3897 F9060B AF 8A 1C F9 lda >PBRPTR2+1
3898 F9060F 85 A6 sta ldt3+ldt_pbr+2
3899 F90611 A9 FF lda #$FF
3900 F90613 85 29 sta ldt0+ldt_fmt
3901 F90615 85 53 sta ldt1+ldt_fmt
3902 F90617 85 7D sta ldt2+ldt_fmt
3903 F90619 85 A7 sta ldt3+ldt_fmt
3904 F9061B ACC16
3905 F9061B C2 20 rep #PMFLAG
3906 .LONGA on
3907 .MNLIST
3908 F9061D AF 85 1C F9 lda >PBRPTR
3909 F90621 85 7A sta ldt2+ldt_pbr
3910 F90623 AF 87 1C F9 lda >PBRPTR+2
3911 F90627 85 A4 sta ldt3+ldt_pbr
3912 F90629 A9 F8 0F lda #F12EOC
3913 F9062C 85 10 sta ldt0+ldt_eoc ; FAT12 end of chain marker
3914 F9062E 85 3A sta ldt1+ldt_eoc
3915 F90630 A9 F8 FF lda #F16EOC
3916 F90633 85 64 sta ldt2+ldt_eoc ; FAT16 end of chain marker
3917 F90635 85 8E sta ldt3+ldt_eoc
3918 F90637 A9 00 9E lda #cwdl0
3919 F9063A 85 1C sta ldt0+ldt_cdlp ; current directory pointer drive #0
3920 F9063C A9 00 A0 lda #cwdl1
3921 F9063F 85 46 sta ldt1+ldt_cdlp ; current directory pointer drive #1
3922 F90641 A9 00 A2 lda #cwdl2
3923 F90644 85 70 sta ldt2+ldt_cdlp ; current directory pointer drive #2
3924 F90646 A9 00 A4 lda #cwdl3
3925 F90649 85 9A sta ldt3+ldt_cdlp ; current directory pointer drive #3
3926 F9064B 64 1E stz ldt0+ldt_cdcls ; current directory cluster
3927 F9064D 64 48 stz ldt1+ldt_cdcls
3928 F9064F 64 72 stz ldt2+ldt_cdcls
3929 F90651 64 9C stz ldt3+ldt_cdcls
3930 F90653 A0 00 ldy #0
3931 F90655 84 20 sty ldt0+ldt_cdlvl ; current directory level
Tue Jul 17 11:00:20 2018 Page 24
3932 F90657 84 4A sty ldt1+ldt_cdlvl
3933 F90659 84 74 sty ldt2+ldt_cdlvl
3934 F9065B 84 9E sty ldt3+ldt_cdlvl
3935 F9065D 64 12 stz ldt0+ldt_free ; clear free cluster's count & next free clu.
3936 F9065F 64 14 stz ldt0+ldt_nxt
3937 F90661 64 3C stz ldt1+ldt_free
3938 F90663 64 3E stz ldt1+ldt_nxt
3939 F90665 64 66 stz ldt2+ldt_free
3940 F90667 64 68 stz ldt2+ldt_nxt
3941 F90669 64 90 stz ldt3+ldt_free
3942 F9066B 64 92 stz ldt3+ldt_nxt
3943 F9066D ACC08
3944 F9066D E2 20 sep #PMFLAG
3945 .LONGA off
3946 .MNLIST
3947 F9066F 2B pld ; restore DP
3948 F90670 A2 01 ldx #1 ; test virtual drive (drive #1)
3949 F90672 20 D3 08 jsr ldtfd
3950 F90675 90 13 bcc ?90 ; ok
3951 F90677 A9 82 lda #$82 ; force HD format
3952 F90679 8D 45 00 sta !vdrive
3953 F9067C A9 02 lda #2
3954 F9067E A0 00 ldy #0
3955 F90680 A2 01 ldx #1
3956 F90682 20 BF 0D jsr newf12 ; make fat12 file system (no error!)
3957 F90685 A2 01 ldx #1
3958 F90687 20 D3 08 jsr ldtfd ; test again virtual drive
3959 F9068A A2 02 ?90: ldx #2 ; build LDT for ata device's
3960 F9068C 20 9D 06 ?95: jsr ldt16
3961 F9068F E8 inx
3962 F90690 E0 04 cpx #MAXDRV
3963 F90692 90 F8 bcc ?95
3964 F90694 2B pld
3965 F90695 60 rts
3966
3967 F90696 A0 02 ?100: ldy #DMABNK ; bank for buffer #00..#7F
3968 F90698 0A asl a ; get high pointer
3969 F90699 90 01 bcc ?102
3970 F9069B C8 iny ; next bank
3971 F9069C 60 ?102: rts
3972
3973 ; X=logical, DBR=0, DPR=P0LDT
3974 F9069D ldt16:
3975 .EXTERN lchkmbr
3976
3977 F9069D 86 3F stx ldev ; logical drive
3978 F9069F 9B txy
3979 F906A0 BE D2 40 ldx !P0LDT+ldtp,y
3980 F906A3 86 40 stx ldtcur ; current LDT ptr
3981 F906A5 3C 00 40 bit !P0LDT+ldt_fg1,x
3982 F906A8 10 5C bpl ?15 ; not ready
3983 F906AA 50 5A bvc ?15 ; floppy disk
3984 F906AC BD 00 40 lda !P0LDT+ldt_fg1,x
3985 F906AF 29 03 and #3
3986 F906B1 85 3E sta pdev ; phisycal drive
3987 F906B3 18 clc
3988 F906B4 69 43 adc #'C' ; ata device: 'C' or 'D'
Tue Jul 17 11:00:20 2018 Page 25
3989 F906B6 85 39 sta lunit ; logical drive letter
3990 F906B8 20 09 07 jsr ?20 ; check message
3991 F906BB 20 67 07 jsr ?30 ; load PBR
3992 F906BE 20 A3 07 jsr ?40 ; check PBR
3993 F906C1 20 D1 07 jsr ?50 ; fat calc
3994 F906C4 A6 40 ldx ldtcur
3995 F906C6 BC 25 40 ldy !P0LDT+ldt_fbuf,x
3996 F906C9 84 38 sty xbnk
3997 F906CB ACC16
3998 F906CB C2 20 rep #PMFLAG
3999 .LONGA on
4000 .MNLIST
4001 F906CD 98 tya
4002 F906CE 0A asl a
4003 F906CF 0A asl a
4004 F906D0 0A asl a
4005 F906D1 0A asl a
4006 F906D2 85 2A sta xfatb
4007 F906D4 A5 22 lda fat1
4008 F906D6 85 2C sta flba
4009 F906D8 BD 22 40 lda !P0LDT+ldt_fp,x
4010 F906DB 85 3A sta tp
4011 F906DD BC 24 40 ldy !P0LDT+ldt_fp+2,x
4012 F906E0 84 3C sty tp+2
4013 F906E2 ACC08
4014 F906E2 E2 20 sep #PMFLAG
4015 .LONGA off
4016 .MNLIST
4017 F906E4 A9 00 lda #0 ; try to load fat1 table
4018 F906E6 20 D8 07 jsr ?60
4019 F906E9 90 0D bcc ?10 ; ok
4020 F906EB ACC16
4021 F906EB C2 20 rep #PMFLAG
4022 .LONGA on
4023 .MNLIST
4024 F906ED A5 24 lda fat2
4025 F906EF 85 2C sta flba
4026 F906F1 ACC08
4027 F906F1 E2 20 sep #PMFLAG
4028 .LONGA off
4029 .MNLIST
4030 F906F3 A9 80 lda #$80 ; try to read fat2 table (no return if error)
4031 F906F5 20 D8 07 jsr ?60
4032 F906F8 20 22 08 ?10: jsr ?80 ; count free cluster's
4033 F906FB 20 6D 0D jsr mvldt ; move data to LDT
4034 F906FE A9 E0 lda #$E0
4035 F90700 9D 01 40 sta !P0LDT+ldt_fg2,x
4036 F90703 20 67 08 jsr ?100 ; print summary data
4037 F90706 A6 3F ?15: ldx ldev
4038 F90708 60 rts
4039
4040 F90709 A5 39 ?20: lda lunit ; print check message
4041 F9070B 48 pha
4042 F9070C 4B phk
4043 F9070D F4 5A 07 pea #!?25
4044 F90710 A9 05 lda #5
4045 F90712 48 pha
Tue Jul 17 11:00:20 2018 Page 26
4046 F90713 BPRINTF
4047 F90713 02 11 cop $11
4048 .MNLIST
4049 F90715 A6 3E ldx pdev
4050 F90717 BD 0E 00 lda !atadev,x ; check ata device flag
4051 F9071A 29 BD and #10111101B ; ready&ident&valid MBR partition
4052 F9071C C9 BD cmp #10111101B
4053 F9071E F0 08 beq ?36a ; ok
4054 F90720 A6 3E ldx pdev ; load MBR
4055 F90722 22 4D 90 F8 jsl lchkmbr
4056 F90726 B0 01 bcs ?36b
4057 F90728 60 ?36a: rts
4058
4059 F90729 ?36b:
4060 F90729 SCNPRINT
4061 F90729 02 01 cop $01
4062 .MNLIST
4063 F9072B 75 6E 70 61 72 .DB 'unpartitioned disk or invalid partition ID.', 13, 0
74 69 74 69 6F
6E 65 64 20 64
69 73 6B 20 6F
72 20 69 6E 76
61 6C 69 64 20
70 61 72 74 69
74 69 6F 6E 20
49 44 2E 0D 00
4064 F90758 80 44 bra ?32 ; no or invalid partition
4065
4066 F9075A 63 68 65 63 6B ?25: .DB 'check <%c>: ', 0
20 3C 25 63 3E
3A 20 00
4067
4068 F90767 A6 3E ?30: ldx pdev ; load PBR
4069 F90769 A9 03 lda #3
4070 F9076B ATACTL
4071 F9076B 02 41 cop $41
4072 .MNLIST
4073 F9076D 90 33 bcc ?36 ; ok
4074 F9076F SCNPRINT
4075 F9076F 02 01 cop $01
4076 .MNLIST
4077 F90771 75 6E 61 62 6C .DB 'unable to load partition boot record (PBR).', 13, 0
65 20 74 6F 20
6C 6F 61 64 20
70 61 72 74 69
74 69 6F 6E 20
62 6F 6F 74 20
72 65 63 6F 72
64 20 28 50 42
52 29 2E 0D 00
4078 F9079E 68 ?32: pla ; discard return address
4079 F9079F 68 pla
4080 F907A0 A6 3F ?34: ldx ldev
4081 F907A2 60 ?36: rts
4082 F907A3
4083 F907A3 20 65 0B ?40: jsr chk16 ; check PBR
4084 F907A6 90 FA bcc ?36
Tue Jul 17 11:00:20 2018 Page 27
4085 F907A8 ?45: SCNPRINT
4086 F907A8 02 01 cop $01
4087 .MNLIST
4088 F907AA 69 6E 76 61 6C .DB 'invalid partition type (not FAT16).', 13, 0
69 64 20 70 61
72 74 69 74 69
6F 6E 20 74 79
70 65 20 28 6E
6F 74 20 46 41
54 31 36 29 2E
0D 00
4089 F907CF 80 CD bra ?32
4090
4091 F907D1 20 18 0D ?50: jsr fcalc ; fat calc
4092 F907D4 90 CC bcc ?36
4093 F907D6 80 D0 bra ?45
4094
4095 F907D8 85 41 ?60: sta lflag
4096
4097 F907DA A6 3E ldx pdev
4098 F907DC AD CF FD lda !VIA3+VIAPRANH
4099 F907DF 29 F8 and #$F8
4100 F907E1 1F 20 08 F9 ora >?69,x
4101 F907E5 8D CF FD sta !VIA3+VIAPRANH ; set bank
4102
4103 F907E8 A6 3E ldx pdev
4104 F907EA DA phx ; phisical drive
4105 F907EB A9 00 lda #0
4106 F907ED 48 pha ; lba high
4107 F907EE D4 2C pei (flba) ; lba low
4108 F907F0 A5 18 lda fatsiz
4109 F907F2 48 pha ; sector's count
4110 F907F3
4111 ;pha ; use x-mem buffer
4112 ;pei (xfatb) ; x-mem buffer
4113 ;pha ; flag=0
4114 ;ATAREAD
4115 F907F3
4116 F907F3 BF 20 08 F9 lda >?69,x
4117 F907F7 48 pha
4118 F907F8 A9 00 lda #0
4119 F907FA 48 pha
4120 F907FB ATADMARD
4121 F907FB 02 42 cop $42
4122 F907FD 00 .DB $00
4123 .MNLIST
4124 F907FE
4125 F907FE 90 A2 bcc ?36 ; ok no error
4126 F90800 24 41 bit lflag
4127 F90802 10 9E bpl ?36 ; try fat2 table
4128 F90804 SCNPRINT
4129 F90804 02 01 cop $01
4130 .MNLIST
4131 F90806 66 61 74 20 74 .DB 'fat table load error.', 13, 0
61 62 6C 65 20
6C 6F 61 64 20
65 72 72 6F 72
Tue Jul 17 11:00:20 2018 Page 28
2E 0D 00
4132 ;bra ?32
4133 F9081D 4C 9E 07 jmp ?32
4134 F90820 05 06 ?69: .DB $05, $06 ; FAT table bank
4135
4136 F90822 64 3A ?80: stz tp
4137 F90824 64 3B stz tp+1
4138 F90826 A9 02 lda #$02
4139 F90828 85 3C sta tp+2
4140
4141 F9082A A6 3E ldx pdev
4142 F9082C AD CF FD lda !VIA3+VIAPRANH
4143 F9082F 29 F8 and #$F8
4144 F90831 1F 20 08 F9 ora >?69,x
4145 F90835 8D CF FD sta !VIA3+VIAPRANH ; set bank
4146 F90838 A9 08 lda #$08 ; PB3 VIA3
4147 F9083A 1C C0 FD trb VIA3+VIAPRB ; enable 1Mb buffer
4148 F9083D
4149 F9083D A2 00 ldx #0 ; cluster number
4150 F9083F CPU16
4151 F9083F C2 30 rep #(PMFLAG.OR.PXFLAG)
4152 .LONGA on
4153 .LONGI on
4154 .MNLIST
4155 F90841 9B txy
4156 F90842 64 2E stz freecnt
4157 F90844 64 30 stz freecls
4158 F90846 B7 3A ?85a: lda [tp],y ; scan fat table
4159 F90848 D0 08 bne ?90a ; not free
4160 F9084A E6 2E inc freecnt ; update free cluster's count
4161 F9084C A5 30 lda freecls ; already set?
4162 F9084E D0 02 bne ?90a ; yes
4163 F90850 86 30 stx freecls ; set first free cluster
4164 F90852 E8 ?90a: inx
4165 F90853 E4 28 cpx maxcls ; end of table?
4166 F90855 B0 0D bcs ?95a ; yes
4167 F90857 C8 iny
4168 F90858 C8 iny
4169 F90859 D0 EB bne ?85a
4170 F9085B A5 3B lda tp+1
4171 F9085D 69 00 01 adc #$0100
4172 F90860 85 3B sta tp+1
4173 F90862 80 E2 bra ?85a
4174 F90864 ?95a: CPU08
4175 F90864 E2 30 sep #(PMFLAG.OR.PXFLAG)
4176 .LONGA off
4177 .LONGI off
4178 .MNLIST
4179 F90866 60 rts
4180
4181 .COMMENT @
4182
4183 ldx CRXME ; save X mem setting
4184 phx
4185 sta !CRXMEON ; enable X mem in window $012000 - $013FFF
4186 lda xbnk
4187 sta !PIA0+PIAPRA ; set x-mem bank
Tue Jul 17 11:00:20 2018 Page 29
4188 phb ; save DBR
4189 lda tp+2
4190 pha
4191 plb ; set DBR to fat table cache
4192 ldx #0 ; cluster number
4193 CPU16
4194 txy
4195 stz freecnt
4196 stz freecls
4197 ?85: lda (tp),y ; scan fat table
4198 bne ?90 ; not free
4199 inc freecnt ; update free cluster's count
4200 lda freecls ; already set?
4201 bne ?90 ; yes
4202 stx freecls ; set first free cluster
4203 ?90: inx
4204 cpx maxcls ; end of table?
4205 bcs ?95 ; yes
4206 iny
4207 iny
4208 cpy #XMWSIZ ; end of x-mem window?
4209 bcc ?85 ; no
4210 ACC08
4211 lda >PIA0+PIAPRA ; update x-mem bank
4212 inc a
4213 sta >PIA0+PIAPRA
4214 ACC16
4215 ldy #0
4216 bra ?85
4217 ?95: CPU08
4218 plb ; restore DBR
4219 plx ; restore X mem setting
4220 sta !CRXME,x
4221 rts
4222 @
4223
4224 F90867 ?100: ACC16 ; print summary
4225 F90867 C2 20 rep #PMFLAG
4226 .LONGA on
4227 .MNLIST
4228 F90869 A5 28 lda maxcls
4229 F9086B 3A dec a
4230 F9086C 3A dec a
4231 F9086D 85 28 sta maxcls
4232 F9086F ACC08
4233 F9086F E2 20 sep #PMFLAG
4234 .LONGA off
4235 .MNLIST
4236 F90871 A5 35 lda clssiz
4237 F90873 48 pha
4238 F90874 D4 2E pei (freecnt)
4239 F90876 D4 28 pei (maxcls)
4240 F90878 4B phk
4241 F90879 F4 82 08 pea #!?110
4242 F9087C A9 09 lda #9
4243 F9087E 48 pha
4244 F9087F BPRINTF
Tue Jul 17 11:00:20 2018 Page 30
4245 F9087F 02 11 cop $11
4246 .MNLIST
4247 F90881 60 rts
4248
4249 F90882 25 2C 68 75 20 ?110: .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
4250
4251 ; build LDT for floppy disk
4252 ; X=logical drive
4253 F908BA bldldt:
4254 F908BA A9 00 lda #0
4255 F908BC 8B phb
4256 F908BD 48 pha
4257 F908BE AB plb
4258 F908BF 0B phd
4259 F908C0 F4 00 42 pea #P0OS
4260 F908C3 2B pld
4261 F908C4 20 D3 08 jsr ldtfd
4262 F908C7 2B pld
4263 F908C8 AB plb
4264 F908C9 60 rts
4265
4266 F908CA testldt:
4267 F908CA A2 00 ldx #0
4268 F908CC 20 BA 08 jsr bldldt
4269 F908CF 00 00 brk
4270 F908D1 00 00 brk
4271
4272 ; build LDT for floppy disk media
4273 ; X=logical device, DPR=P0LDT
4274 F908D3 ldtfd:
4275 F908D3 86 3F stx ldev ; logical drive
4276 F908D5 9B txy
4277 F908D6 BE D2 40 ldx !P0LDT+ldtp,y
4278 F908D9 86 40 stx ldtcur ; current LDT ptr
4279 F908DB 3C 00 40 bit !P0LDT+ldt_fg1,x
4280 F908DE 10 34 bpl ?15 ; not ready
4281 F908E0 70 32 bvs ?15 ; ata device
4282 F908E2 9E 01 40 stz !P0LDT+ldt_fg2,x ; reset flag 2
4283 F908E5 BD 00 40 lda !P0LDT+ldt_fg1,x
4284 F908E8 29 03 and #3
4285 F908EA 85 3E sta pdev ; phisycal drive
4286 F908EC 20 18 09 jsr ?20 ; check media format
4287 F908EF 20 44 09 jsr ?30 ; load PBR
4288 F908F2 20 59 09 jsr ?40 ; check PBR
4289 F908F5 20 60 09 jsr ?50 ; fat calc
4290 F908F8 20 67 09 jsr ?60 ; count free cluster's
Tue Jul 17 11:00:20 2018 Page 31
4291 F908FB A5 3D lda fdfmt
4292 F908FD C9 01 cmp #1 ; DD ibm disk?
4293 F908FF D0 03 bne ?10 ; no
4294 F90901 20 AF 09 jsr ?90 ; pre-read cluster #4
4295 F90904 20 6D 0D ?10: jsr mvldt ; move data to LDT
4296 F90907 A9 E0 lda #$E0 ; update flag 2
4297 F90909 05 3D ora fdfmt
4298 F9090B 9D 01 40 sta !P0LDT+ldt_fg2,x
4299 F9090E 9E 20 40 stz !P0LDT+ldt_cdlvl,x ; set to root directory
4300 F90911 20 CA 09 jsr ?100 ; setup BCB list for root, cluster #2,#3
4301 F90914 A6 3F ?15: ldx ldev
4302 F90916 18 clc
4303 F90917 60 rts
4304
4305 F90918 AA ?20: tax ; try to get media format
4306 F90919 FDCGETFMT
4307 F90919 02 30 cop $30
4308 F9091B 04 .DB $04
4309 .MNLIST
4310 F9091C B0 38 bcs ?34 ; unformatted disk?
4311 F9091E 84 3D sty fdfmt ; save media format
4312 F90920 C0 01 cpy #1 ; cbm format?
4313 F90922 D0 34 bne ?35 ; no, so return
4314 F90924 A9 49 lda #'I' ; send init command to cbm emulator
4315 F90926 85 04 sta bpath
4316 F90928 A5 3E lda pdev
4317 F9092A 09 30 ora #'0' ; drive
4318 F9092C 85 05 sta bpath+1
4319 F9092E 64 06 stz bpath+2
4320 F90930 A9 04 lda #bpath ; address of command string
4321 F90932 A2 42 ldx #>P0OS
4322 F90934 A0 00 ldy #0
4323 F90936 20 F6 2E jsr cbmfs_cmd
4324 F90939 B0 1B bcs ?34 ; skip return address if error
4325 F9093B A9 A1 lda #10100001B ; set flag 2
4326 F9093D A6 40 ldx ldtcur
4327 F9093F 9D 01 40 sta !P0LDT+ldt_fg2,x
4328 F90942 80 12 bra ?34 ; skip return address & CF=0
4329
4330 F90944 A6 3E ?30: ldx pdev ; read system track (track 0)
4331 F90946 DA phx ; phsycal drive
4332 F90947 A9 00 lda #0
4333 F90949 48 pha ; track=0
4334 F9094A BD D8 40 lda !P0LDT+sysbuf,x ; dma buffer #
4335 F9094D 48 pha
4336 F9094E A5 3D lda fdfmt ; format
4337 F90950 48 pha
4338 F90951 FDCTKRD ; read whole track
4339 F90951 02 35 cop $35
4340 F90953 00 .DB $00
4341 .MNLIST
4342 F90954 90 02 bcc ?35 ; ok
4343 F90956 68 ?34: pla ; discard return address
4344 F90957 68 pla
4345 F90958 60 ?35: rts
4346
4347 F90959 20 42 0C ?40: jsr chk12 ; check floppy disk PBR
Tue Jul 17 11:00:20 2018 Page 32
4348 F9095C 90 FA bcc ?35 ; ok
4349 F9095E 80 F6 bra ?34 ; skip return address
4350
4351 F90960 20 18 0D ?50: jsr fcalc ; fat calc
4352 F90963 90 F3 bcc ?35
4353 F90965 80 EF bra ?34 ; skip return address
4354
4355 F90967 A6 40 ?60: ldx ldtcur ; compute free cluster's
4356 F90969 ACC16
4357 F90969 C2 20 rep #PMFLAG
4358 .LONGA on
4359 .MNLIST
4360 F9096B BD 22 40 lda !P0LDT+ldt_fp,x
4361 F9096E 85 3A sta tp
4362 F90970 BC 24 40 ldy !P0LDT+ldt_fp+2,x
4363 F90973 8B phb
4364 F90974 5A phy
4365 F90975 AB plb
4366 F90976 A2 00 ldx #0 ; cluster number
4367 F90978 CPU16
4368 F90978 C2 30 rep #(PMFLAG.OR.PXFLAG)
4369 .LONGA on
4370 .LONGI on
4371 .MNLIST
4372 F9097A 9B txy ; Y=fat table index
4373 F9097B 64 2E stz freecnt
4374 F9097D 64 30 stz freecls
4375 F9097F B1 3A ?65: lda (tp),y ; even index cluster
4376 F90981 29 FF 0F and #$0FFF
4377 F90984 D0 08 bne ?70 ; not free
4378 F90986 E6 2E inc freecnt ; update free cluster's count
4379 F90988 A5 30 lda freecls ; already set?
4380 F9098A D0 02 bne ?70 ; yes
4381 F9098C 86 30 stx freecls ; set first free cluster
4382 F9098E E8 ?70: inx
4383 F9098F E4 28 cpx maxcls ; end of table?
4384 F90991 B0 18 bcs ?80 ; yes
4385 F90993 C8 iny ; odd index cluster
4386 F90994 B1 3A lda (tp),y
4387 F90996 4A lsr a ; shift x 4
4388 F90997 4A lsr a
4389 F90998 4A lsr a
4390 F90999 4A lsr a
4391 F9099A D0 08 bne ?75
4392 F9099C E6 2E inc freecnt ; update free cluster's count
4393 F9099E A5 30 lda freecls ; already set?
4394 F909A0 D0 02 bne ?75 ; yes
4395 F909A2 86 30 stx freecls ; set first free cluster
4396 F909A4 C8 ?75: iny
4397 F909A5 C8 iny ; pointer to next cluster
4398 F909A6 E8 inx
4399 F909A7 E4 28 cpx maxcls
4400 F909A9 90 D4 bcc ?65
4401 F909AB ?80: CPU08
4402 F909AB E2 30 sep #(PMFLAG.OR.PXFLAG)
4403 .LONGA off
4404 .LONGI off
Tue Jul 17 11:00:20 2018 Page 33
4405 .MNLIST
4406 F909AD AB plb
4407 F909AE 60 rts
4408
4409 F909AF A6 3E ?90: ldx pdev ; pre-read cluster #4 DD disk
4410 F909B1 DA phx ; phsycal drive
4411 F909B2 F4 00 01 pea #$0100 ; track=1, head=0
4412 F909B5 F4 02 01 pea #$0102 ; start sec=1, sec num=2
4413 F909B8 BD D8 40 lda !P0LDT+sysbuf,x ; dma buffer #
4414 F909BB 18 clc ; using first buffer after...
4415 F909BC 69 14 adc #20 ; ...system track 0
4416 F909BE 48 pha
4417 F909BF A5 3D lda fdfmt ; format
4418 F909C1 48 pha
4419 F909C2 FDCTKRD ; read whole track
4420 F909C2 02 35 cop $35
4421 F909C4 00 .DB $00
4422 .MNLIST
4423 F909C5 90 02 bcc ?95 ; ok
4424 F909C7 68 pla ; discard return address
4425 F909C8 68 pla
4426 F909C9 60 ?95: rts
4427
4428 F909CA A5 3F ?100: lda ldev ; setup BCB list for root
4429 F909CC 85 04 sta tbdrv
4430 F909CE 64 07 stz tbcls+1
4431 F909D0 64 0B stz tbhead+1
4432 F909D2 64 09 stz tblba+1
4433 F909D4 A6 3E ldx pdev
4434 F909D6 A9 07 lda #$07 ; first DD root sec
4435 F909D8 A4 3D ldy fdfmt
4436 F909DA F0 02 beq ?105
4437 F909DC A9 13 lda #$13 ; first HD root sec
4438 F909DE 18 ?105: clc
4439 F909DF 7D D8 40 adc !P0LDT+sysbuf,x
4440 F909E2 AA tax
4441 F909E3 A0 02 ldy #DMABNK ; bank for buffer #00..#7F
4442 F909E5 0A asl a ; get high pointer
4443 F909E6 90 01 bcc ?110
4444 F909E8 C8 iny ; next bank
4445 F909E9 84 10 ?110: sty tbdma
4446 F909EB 64 0E stz tbptr
4447 F909ED 3A dec a
4448 F909EE 3A dec a
4449 F909EF 85 0F sta tbptr+1
4450 F909F1 CA dex
4451 F909F2 86 11 stx tbdma+1 ; dma buffer #
4452 F909F4 A2 00 ldx #0
4453 F909F6 A5 3D lda fdfmt
4454 F909F8 F0 02 beq ?115
4455 F909FA A2 0E ldx #?501
4456 F909FC 8B ?115: phb
4457 F909FD A9 01 lda #WKB
4458 F909FF 48 pha
4459 F90A00 AB plb
4460 F90A01 INDEX16
4461 F90A01 C2 10 rep #PXFLAG
Tue Jul 17 11:00:20 2018 Page 34
4462 .LONGI on
4463 .MNLIST
4464 F90A03 A0 00 CC ldy #dma0s
4465 F90A06 A5 3E lda pdev
4466 F90A08 F0 03 beq ?120
4467 F90A0A A0 10 CD ldy #dma1s
4468 F90A0D BF 7C 0A F9 ?120: lda >?500,x ; lba
4469 F90A11 F0 5A beq ?125 ; end of list
4470 F90A13 85 08 sta tblba
4471 F90A15 BF 9C 0A F9 lda >?510,x ; sec. offset
4472 F90A19 85 05 sta tbdrv+1
4473 F90A1B BF 1C 0B F9 lda >?550,x ; cluster #
4474 F90A1F 85 06 sta tbcls
4475 F90A21 BF DC 0A F9 lda >?530,x ; head #
4476 F90A25 85 0A sta tbhead
4477 F90A27 BF BC 0A F9 lda >?520,x ; track #
4478 F90A2B 85 0C sta tbtrk
4479 F90A2D BF FC 0A F9 lda >?540,x ; sector #
4480 F90A31 85 0D sta tbtrk+1
4481 F90A33 A5 0F lda tbptr+1 ; update buffer ptr
4482 F90A35 1A inc a
4483 F90A36 1A inc a
4484 F90A37 85 0F sta tbptr+1
4485 F90A39 E6 11 inc tbdma+1 ; update dma buffer #
4486 F90A3B ACC16CLC
4487 F90A3B C2 21 rep #(PMFLAG.OR.PCFLAG)
4488 .LONGA on
4489 .MNLIST
4490 F90A3D A5 04 lda tbdrv
4491 F90A3F 99 02 00 sta bcb_drv,y
4492 F90A42 A5 06 lda tbcls
4493 F90A44 99 04 00 sta bcb_cls,y
4494 F90A47 A5 08 lda tblba
4495 F90A49 99 06 00 sta bcb_lba,y
4496 F90A4C A5 0A lda tbhead
4497 F90A4E 99 08 00 sta bcb_head,y
4498 F90A51 A5 0C lda tbtrk
4499 F90A53 99 0A 00 sta bcb_trk,y
4500 F90A56 A5 0E lda tbptr
4501 F90A58 99 0C 00 sta bcb_ptr,y
4502 F90A5B A5 10 lda tbdma
4503 F90A5D 99 0E 00 sta bcb_dma,y
4504 F90A60 98 tya
4505 F90A61 69 10 00 adc #BCBSIZE
4506 F90A64 99 00 00 sta bcb_next,y
4507 F90A67 A8 tay
4508 F90A68 ACC08
4509 F90A68 E2 20 sep #PMFLAG
4510 .LONGA off
4511 .MNLIST
4512 F90A6A E8 inx
4513 F90A6B 80 A0 bra ?120
4514 F90A6D ?125: ACC16
4515 F90A6D C2 20 rep #PMFLAG
4516 .LONGA on
4517 .MNLIST
4518 F90A6F 98 tya
Tue Jul 17 11:00:20 2018 Page 35
4519 F90A70 38 sec
4520 F90A71 E9 10 00 sbc #BCBSIZE
4521 F90A74 AA tax
4522 F90A75 9E 00 00 stz !bcb_next,x
4523 F90A78 CPU08
4524 F90A78 E2 30 sep #(PMFLAG.OR.PXFLAG)
4525 .LONGA off
4526 .LONGI off
4527 .MNLIST
4528 F90A7A AB plb
4529 F90A7B 60 rts
4530
4531 ; DD system track lba
4532 F90A7C 07 08 09 0A 0B ?500: .DB $07, $08, $09, $0A, $0B, $0C, $0D, $0E, $0F, $10, $11, $12
0C 0D 0E 0F 10
11 12
4533 F90A88 13 00 .DB $13, $00
4534 00000E ?501 .EQU $-?500
4535 ; HD system track lba
4536 F90A8A 13 14 15 16 17 .DB $13, $14, $15, $16, $17, $18, $19, $1A, $1B, $1C, $1D, $1E
18 19 1A 1B 1C
1D 1E
4537 F90A96 1F 20 21 22 23 .DB $1F, $20, $21, $22, $23, $00
00
4538
4539 ?510: ; DD sector offset
4540 F90A9C 00 01 02 03 04 .DB 0, 1, 2, 3, 4, 5, 6, 0, 1, 0, 1, 0, 1, 0
05 06 00 01 00
01 00 01 00
4541 ; HD sector offset
4542 F90AAA 00 01 02 03 04 .DB 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 0, 0, 0, 0
05 06 07 08 09
0A 0B 0C 0D 00
00 00 00
4543 F90ABC
4544 ?520: ; DD track
4545 F90ABC 00 00 00 00 00 .DB 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0
00 00 00 00 00
00 01 01 00
4546 ; HD track
4547 F90ACA 00 00 00 00 00 .DB 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
00 00 00 00 00
00 00 00 00 00
00 00 00
4548 F90ADC
4549 ?530: ; DD head
4550 F90ADC 00 00 01 01 01 .DB 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0
01 01 01 01 01
01 00 00 00
4551 ; HD head
4552 F90AEA 01 01 01 01 01 .DB 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0
01 01 01 01 01
01 01 01 01 01
01 01 00
4553 F90AFC
4554 ?540: ; DD sector #
4555 F90AFC 08 09 01 02 03 .DB 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 0
Tue Jul 17 11:00:20 2018 Page 36
04 05 06 07 08
09 01 02 00
4556 ; HD sector #
4557 F90B0A 02 03 04 05 06 .DB 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
07 08 09 0A 0B
0C 0D 0E 0F
4558 F90B18 10 11 12 00 .DB 16, 17, 18, 0
4559
4560 ?550: ; DD cluster #
4561 F90B1C 00 00 00 00 00 .DB 0, 0, 0, 0, 0, 0, 0, 2, 2, 3, 3, 4, 4, 0
00 00 02 02 03
03 04 04 00
4562 ; HD cluster #
4563 F90B2A 00 00 00 00 00 .DB 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
00 00 00 00 00
00 00 00 00
4564 F90B38 02 03 04 00 .DB 2, 3, 4, 0
4565
4566 ; check fat16 volume in pbr record on usb #0 disk
4567 F90B3C usbchk16:
4568 F90B3C A9 00 lda #<PBR0USB
4569 F90B3E 85 32 sta pbrp
4570 F90B40 A9 96 lda #>PBR0USB
4571 F90B42 85 33 sta pbrp+1
4572 F90B44 A9 01 lda #^PBR0USB
4573 F90B46 85 34 sta pbrp+2
4574 F90B48 ACC16
4575 F90B48 C2 20 rep #PMFLAG
4576 .LONGA on
4577 .MNLIST
4578 F90B4A AD 2A 00 lda !usbmbr ; partition start
4579 F90B4D 85 08 sta hidsec ; this is also hidden sectors count
4580 F90B4F AD 2C 00 lda !usbmbr+2
4581 F90B52 29 FF 00 and #$00FF
4582 F90B55 85 0A sta hidsec+2
4583 F90B57 AD 3A 00 lda !usbprt ; total partition sector's
4584 F90B5A 85 0C sta totsec
4585 F90B5C AD 3C 00 lda !usbprt+2
4586 F90B5F 85 0E sta totsec+2
4587 F90B61 ACC08
4588 F90B61 E2 20 sep #PMFLAG
4589 .LONGA off
4590 .MNLIST
4591 F90B63 80 2E bra chk16c
4592 F90B65
4593 ; check fat16 volume in pbr record
4594 F90B65 chk16:
4595 F90B65 A9 FF lda #$FF
4596 F90B67 85 3D sta fdfmt
4597 F90B69 A5 3E lda pdev ; phisycal drive
4598 F90B6B 0A asl a
4599 F90B6C 0A asl a
4600 F90B6D AA tax
4601 F90B6E ACC16
4602 F90B6E C2 20 rep #PMFLAG
4603 .LONGA on
4604 .MNLIST
Tue Jul 17 11:00:20 2018 Page 37
4605 F90B70 BD 22 00 lda !atambr,x ; partition start
4606 F90B73 85 08 sta hidsec ; this is also hidden sectors count
4607 F90B75 BD 24 00 lda !atambr+2,x
4608 F90B78 29 FF 00 and #$00FF
4609 F90B7B 85 0A sta hidsec+2
4610 F90B7D BD 32 00 lda !ataprt,x ; total partition sector's
4611 F90B80 85 0C sta totsec
4612 F90B82 BD 34 00 lda !ataprt+2,x
4613 F90B85 85 0E sta totsec+2
4614 F90B87 A6 40 ldx ldtcur ; LDT ptr
4615 F90B89 BD 26 40 lda !P0LDT+ldt_pbr,x
4616 F90B8C 85 32 sta pbrp
4617 F90B8E BC 28 40 ldy !P0LDT+ldt_pbr+2,x
4618 F90B91 84 34 sty pbrp+2
4619
4620 ; entry point to check usb #0 disk
4621 F90B93 chk16c:
4622 F90B93 ACC16
4623 F90B93 C2 20 rep #PMFLAG
4624 .LONGA on
4625 .MNLIST
4626 F90B95 A6 33 ldx pbrp+1
4627 F90B97 E8 inx
4628 F90B98 86 33 stx pbrp+1
4629 F90B9A A9 F5 FF lda #MAXF16
4630 F90B9D 85 10 sta maxcnt
4631 F90B9F A0 FE ldy #$FE ; pointer to pbr signature
4632 F90BA1 B7 32 lda [pbrp],y
4633 F90BA3 C9 55 AA cmp #$AA55
4634 F90BA6 D0 67 bne ?10 ; signature error
4635 F90BA8 CA dex
4636 F90BA9 86 33 stx pbrp+1
4637 F90BAB A0 0B ldy #$0B ; pointer to bytes per sector
4638 F90BAD B7 32 lda [pbrp],y
4639 F90BAF C9 00 02 cmp #$0200 ; must be always 512 bytes per sector
4640 F90BB2 D0 5B bne ?10 ; error
4641 F90BB4 A0 1C ldy #$1C ; pointer to hidden sector's count
4642 F90BB6 B7 32 lda [pbrp],y ; typical value: $3F
4643 F90BB8 C5 08 cmp hidsec ; must match
4644 F90BBA D0 53 bne ?10
4645 F90BBC C8 iny
4646 F90BBD C8 iny
4647 F90BBE B7 32 lda [pbrp],y
4648 F90BC0 C5 0A cmp hidsec+2
4649 F90BC2 D0 4B bne ?10
4650 F90BC4 C9 00 00 cmp #0
4651 F90BC7 D0 46 bne ?10 ; must be 0
4652 F90BC9 A0 0E ldy #$0E ; pointer to reserved sector's
4653 F90BCB B7 32 lda [pbrp],y ; typical value: 1 (no mandatory)
4654 F90BCD 85 16 sta rsvsec
4655 F90BCF A0 11 ldy #$11 ; pointer to root dir entry #
4656 F90BD1 B7 32 lda [pbrp],y
4657 F90BD3 F0 3A beq ?10 ; fat32?
4658 F90BD5 C9 00 02 cmp #$0200 ; typical value: not mandatory...
4659 F90BD8 D0 35 bne ?10 ; ...but this will be
4660 F90BDA 85 1C sta rootent
4661 F90BDC 4A lsr a ; divide by 16...
Tue Jul 17 11:00:20 2018 Page 38
4662 F90BDD 4A lsr a
4663 F90BDE 4A lsr a
4664 F90BDF 4A lsr a ;...to get root dir size in sec's
4665 F90BE0 85 1A sta rootsiz
4666 F90BE2 A0 13 ldy #$13 ; pointer to tot. sec16
4667 F90BE4 B7 32 lda [pbrp],y
4668 F90BE6 F0 0A beq ?06 ; invalid: is valid field tot. sec32
4669 F90BE8 C5 0C cmp totsec
4670 F90BEA D0 23 bne ?10 ; error
4671 F90BEC A5 0E lda totsec+2 ; must be 0
4672 F90BEE D0 1F bne ?10 ; errore
4673 F90BF0 F0 10 beq ?08 ; ok
4674 F90BF2 A0 20 ?06: ldy #$20 ; pointer to tot. sec32
4675 F90BF4 B7 32 lda [pbrp],y
4676 F90BF6 C5 0C cmp totsec
4677 F90BF8 D0 15 bne ?10 ; error
4678 F90BFA C8 iny
4679 F90BFB C8 iny
4680 F90BFC B7 32 lda [pbrp],y
4681 F90BFE C5 0E cmp totsec+2
4682 F90C00 D0 0D bne ?10 ; error
4683 F90C02 A0 16 ?08: ldy #$16 ; pointer to fat size (FAT16)
4684 F90C04 B7 32 lda [pbrp],y
4685 F90C06 85 18 sta fatsiz
4686 F90C08 F0 05 beq ?10 ; hmmm... is fat32... not good
4687 F90C0A C9 01 01 cmp #257 ; fat16 table size limited to 256 sec. max
4688 F90C0D 80 01 bra ?12
4689 F90C0F 38 ?10: sec
4690 F90C10 ?12: CPU08
4691 F90C10 E2 30 sep #(PMFLAG.OR.PXFLAG)
4692 .LONGA off
4693 .LONGI off
4694 .MNLIST
4695 F90C12 B0 20 bcs ?18 ; error
4696 F90C14 A0 15 ldy #$15 ; pointer to media byte
4697 F90C16 B7 32 lda [pbrp],y ; must be $F8
4698 F90C18 C9 F8 cmp #$F8
4699 F90C1A D0 17 bne ?16
4700 F90C1C A0 10 ldy #$10 ; pointer to count of fat table's
4701 F90C1E B7 32 lda [pbrp],y
4702 F90C20 C9 02 cmp #2 ; must be 2
4703 F90C22 D0 0F bne ?16
4704 F90C24 A0 0D ldy #$0D ; pointer to sector(s) per cluster
4705 F90C26 B7 32 lda [pbrp],y
4706 F90C28 A2 06 ldx #CLSCNT-1
4707 F90C2A DF 61 1C F9 ?14: cmp >CLSSIZE,x
4708 F90C2E F0 05 beq ?20
4709 F90C30 CA dex
4710 F90C31 10 F7 bpl ?14
4711 F90C33 38 ?16: sec
4712 F90C34 60 ?18: rts
4713 F90C35 85 35 ?20: sta clssiz
4714 F90C37 3A dec a
4715 F90C38 85 37 sta clsmod
4716 F90C3A BF 68 1C F9 lda >CLSSHIFT,x
4717 F90C3E 85 36 sta clsshf
4718 F90C40 18 clc
Tue Jul 17 11:00:20 2018 Page 39
4719 F90C41 60 rts
4720
4721 ; check floppy disk PBR
4722 F90C42 chk12:
4723 ;ldx pdev ; phisycal drive
4724 ;lda !fdcdrv,x ; get format from bios
4725 ;and #00000011B
4726 ;sta fdfmt ; format to check (0 or 2)
4727 F90C42 A5 3D lda fdfmt
4728 F90C44 4A lsr a ; index DD/HD
4729 F90C45 85 2A sta fdix
4730 F90C47 0A asl a
4731 F90C48 85 4F sta fd2ix
4732 F90C4A ACC16
4733 F90C4A C2 20 rep #PMFLAG
4734 .LONGA on
4735 .MNLIST
4736 F90C4C A9 F5 0F lda #MAXF12
4737 F90C4F 85 10 sta maxcnt
4738 F90C51 A6 40 ldx ldtcur ; LDT ptr
4739 F90C53 BD 26 40 lda !P0LDT+ldt_pbr,x
4740 F90C56 85 32 sta pbrp
4741 F90C58 BC 28 40 ldy !P0LDT+ldt_pbr+2,x
4742 F90C5B 84 34 sty pbrp+2
4743 F90C5D A6 33 ldx pbrp+1
4744 F90C5F E8 inx
4745 F90C60 86 33 stx pbrp+1
4746 F90C62 A0 FE ldy #$FE ; pointer to pbr signature
4747 F90C64 B7 32 lda [pbrp],y
4748 F90C66 C9 55 AA cmp #$AA55
4749 F90C69 D0 79 bne ?10 ; signature error
4750 F90C6B CA dex
4751 F90C6C 86 33 stx pbrp+1
4752 F90C6E A6 4F ldx fd2ix ; X=DD/HD double index
4753 F90C70 A0 0B ldy #$0B ; pointer to bytes per sector
4754 F90C72 B7 32 lda [pbrp],y
4755 F90C74 C9 00 02 cmp #$0200 ; must be always 512 bytes per sector
4756 F90C77 D0 6B bne ?10 ; error
4757 F90C79 A0 0E ldy #$0E ; pointer to reserved sector's
4758 F90C7B B7 32 lda [pbrp],y ; mandatory value: 1
4759 F90C7D 85 16 sta rsvsec
4760 F90C7F 3A dec a
4761 F90C80 D0 62 bne ?10 ; error
4762 F90C82 A0 11 ldy #$11 ; pointer to root dir entry #
4763 F90C84 B7 32 lda [pbrp],y
4764 F90C86 DF 6F 1C F9 cmp >FDROOT,x ; mandatory
4765 F90C8A D0 58 bne ?10 ; error
4766 F90C8C 85 1C sta rootent
4767 F90C8E 4A lsr a ; divide by 16...
4768 F90C8F 4A lsr a
4769 F90C90 4A lsr a
4770 F90C91 4A lsr a ;...to get root dir size in sec's
4771 F90C92 85 1A sta rootsiz
4772 F90C94 A0 13 ldy #$13 ; pointer to tot. sec.
4773 F90C96 B7 32 lda [pbrp],y
4774 F90C98 DF 73 1C F9 cmp >FDSEC,x
4775 F90C9C D0 46 bne ?10 ; error
Tue Jul 17 11:00:20 2018 Page 40
4776 F90C9E 85 0C sta totsec
4777 F90CA0 A0 16 ldy #$16 ; pointer to fat size (FAT12)
4778 F90CA2 B7 32 lda [pbrp],y
4779 F90CA4 DF 77 1C F9 cmp >FDFAT,x
4780 F90CA8 D0 3A bne ?10 ; error
4781 F90CAA 85 18 sta fatsiz
4782 F90CAC A0 18 ldy #$18 ; pointer to sector's per track
4783 F90CAE B7 32 lda [pbrp],y
4784 F90CB0 DF 7B 1C F9 cmp >FDSPT,x
4785 F90CB4 D0 2E bne ?10 ; error
4786 F90CB6 A0 1A ldy #$1A ; pointer to sides count #
4787 F90CB8 B7 32 lda [pbrp],y
4788 F90CBA C9 02 00 cmp #2 ; must be 2
4789 F90CBD D0 25 bne ?10 ; error
4790 F90CBF A0 1C ldy #$1C ; pointer to hidden sec
4791 F90CC1 B7 32 lda [pbrp],y
4792 F90CC3 D0 1F bne ?10 ; must be 0
4793 F90CC5 A0 1E ldy #$1E
4794 F90CC7 B7 32 lda [pbrp],y
4795 F90CC9 D0 19 bne ?10 ; must be 0
4796 F90CCB A0 20 ldy #$20 ; tot sec32
4797 F90CCD B7 32 lda [pbrp],y
4798 F90CCF D0 13 bne ?10 ; must be 0
4799 F90CD1 85 08 sta hidsec
4800 F90CD3 85 0A sta hidsec+2
4801 F90CD5 85 0E sta totsec+2
4802 F90CD7 A0 22 ldy #$22
4803 F90CD9 B7 32 lda [pbrp],y
4804 F90CDB D0 07 bne ?10 ; must be 0
4805 F90CDD A0 24 ldy #$24 ; rsvd1 & rsvd2
4806 F90CDF B7 32 lda [pbrp],y
4807 F90CE1 18 clc
4808 F90CE2 F0 01 beq ?12 ; must be 0
4809 F90CE4 38 ?10: sec
4810 F90CE5 ?12: ACC08
4811 F90CE5 E2 20 sep #PMFLAG
4812 .LONGA off
4813 .MNLIST
4814 F90CE7 B0 2A bcs ?16 ; exit&error
4815 F90CE9 A6 2A ldx fdix
4816 F90CEB A0 0D ldy #$0D ; pointer to sector(s) per cluster
4817 F90CED B7 32 lda [pbrp],y
4818 F90CEF DF 7F 1C F9 cmp >FDCLS,x
4819 F90CF3 D0 1D bne ?14 ; error
4820 F90CF5 85 35 sta clssiz
4821 F90CF7 3A dec a
4822 F90CF8 85 37 sta clsmod
4823 F90CFA BF 81 1C F9 lda >FDSHF,x
4824 F90CFE 85 36 sta clsshf
4825 F90D00 A0 10 ldy #$10 ; pointer to count of fat table's
4826 F90D02 B7 32 lda [pbrp],y
4827 F90D04 C9 02 cmp #2 ; must be 2
4828 F90D06 D0 0A bne ?14
4829 F90D08 A0 15 ldy #$15 ; pointer to media byte
4830 F90D0A B7 32 lda [pbrp],y
4831 F90D0C DF 83 1C F9 cmp >FDMEDIA,x
4832 F90D10 F0 02 beq ?18
Tue Jul 17 11:00:20 2018 Page 41
4833 F90D12 38 ?14: sec
4834 F90D13 60 ?16: rts
4835 F90D14 85 2B ?18: sta media
4836 F90D16 18 clc
4837 F90D17 60 rts
4838
4839 ; compute fat param's
4840 F90D18 fcalc:
4841 F90D18 ACC16CLC
4842 F90D18 C2 21 rep #(PMFLAG.OR.PCFLAG)
4843 .LONGA on
4844 .MNLIST
4845 F90D1A A5 08 lda hidsec
4846 F90D1C 65 16 adc rsvsec
4847 F90D1E B0 4A bcs ?14 ; error
4848 F90D20 85 22 sta fat1 ; fat1 table lba
4849 F90D22 65 18 adc fatsiz
4850 F90D24 85 24 sta fat2 ; fat2 table lba
4851 F90D26 B0 42 bcs ?14 ; error
4852 F90D28 65 18 adc fatsiz
4853 F90D2A B0 3E bcs ?14 ; error
4854 F90D2C 85 20 sta root ; root dir. lba
4855 F90D2E 65 1A adc rootsiz
4856 F90D30 B0 38 bcs ?14 ; error
4857 F90D32 85 26 sta start ; first data sector lba
4858 F90D34 38 sec
4859 F90D35 E5 08 sbc hidsec
4860 F90D37 85 12 sta first ; first relative data sec
4861 F90D39 38 sec
4862 F90D3A A5 0C lda totsec ; tot. data sec
4863 F90D3C E5 12 sbc first
4864 F90D3E 85 14 sta clscnt ; cluster count
4865 F90D40 A5 0E lda totsec+2
4866 F90D42 E9 00 00 sbc #0
4867 F90D45 A4 36 ldy clsshf
4868 F90D47 F0 06 beq ?12 ; no shift
4869 F90D49 4A ?10: lsr a
4870 F90D4A 66 14 ror clscnt
4871 F90D4C 88 dey
4872 F90D4D D0 FA bne ?10
4873 F90D4F 48 ?12: pha
4874 F90D50 68 pla
4875 F90D51 38 sec
4876 F90D52 D0 16 bne ?14 ; error: must be 0
4877 F90D54 A5 14 lda clscnt
4878 F90D56 C5 10 cmp maxcnt
4879 F90D58 90 03 bcc ?13
4880 F90D5A A9 F4 FF lda #MAXF16-1 ; limit max. count
4881 F90D5D 1A ?13: inc a ; here CF=0
4882 F90D5E 1A inc a ; max. usable cluster+1=N+2 (2..N+1)
4883 F90D5F 85 28 sta maxcls
4884 F90D61 A6 35 ldx clssiz
4885 F90D63 8A txa ; B=0, A=clssiz
4886 F90D64 0A asl a ; 16 entries per sec...
4887 F90D65 0A asl a
4888 F90D66 0A asl a
4889 F90D67 0A asl a ; here CF=0
Tue Jul 17 11:00:20 2018 Page 42
4890 F90D68 85 1E sta clsent ; entries in cluster
4891 F90D6A ?14: ACC08
4892 F90D6A E2 20 sep #PMFLAG
4893 .LONGA off
4894 .MNLIST
4895 F90D6C 60 rts
4896
4897 ; move computed fat var's to LDT
4898 F90D6D mvldt:
4899 F90D6D A6 40 ldx ldtcur
4900 F90D6F ACC16
4901 F90D6F C2 20 rep #PMFLAG
4902 .LONGA on
4903 .MNLIST
4904 F90D71 A5 20 lda root
4905 F90D73 9D 02 40 sta !P0LDT+ldt_root,x
4906 F90D76 A5 22 lda fat1
4907 F90D78 9D 04 40 sta !P0LDT+ldt_fat1,x
4908 F90D7B A5 24 lda fat2
4909 F90D7D 9D 06 40 sta !P0LDT+ldt_fat2,x
4910 F90D80 A5 26 lda start
4911 F90D82 9D 08 40 sta !P0LDT+ldt_cls,x
4912 F90D85 A5 28 lda maxcls
4913 F90D87 9D 0A 40 sta !P0LDT+ldt_max,x
4914 F90D8A A5 1C lda rootent
4915 F90D8C 9D 0C 40 sta !P0LDT+ldt_rent,x
4916 F90D8F A5 1E lda clsent
4917 F90D91 9D 0E 40 sta !P0LDT+ldt_cent,x
4918 F90D94 A5 2E lda freecnt
4919 F90D96 9D 12 40 sta !P0LDT+ldt_free,x
4920 F90D99 A5 30 lda freecls
4921 F90D9B 9D 14 40 sta !P0LDT+ldt_nxt,x
4922 F90D9E ACC08
4923 F90D9E E2 20 sep #PMFLAG
4924 .LONGA off
4925 .MNLIST
4926 F90DA0 A5 35 lda clssiz
4927 F90DA2 9D 18 40 sta !P0LDT+ldt_csiz,x
4928 F90DA5 A5 36 lda clsshf
4929 F90DA7 9D 19 40 sta !P0LDT+ldt_cshf,x
4930 F90DAA A5 18 lda fatsiz
4931 F90DAC 9D 16 40 sta !P0LDT+ldt_fsiz,x
4932 F90DAF A5 1A lda rootsiz
4933 F90DB1 9D 1A 40 sta !P0LDT+ldt_rsiz,x
4934 F90DB4 A5 37 lda clsmod
4935 F90DB6 9D 1B 40 sta !P0LDT+ldt_mcls,x
4936 F90DB9 A5 3D lda fdfmt
4937 F90DBB 9D 29 40 sta !P0LDT+ldt_fmt,x
4938 F90DBE 60 rts
4939
4940 ;---------------------------------------------------------------------------
4941 ; new fat file system
4942 ;---------------------------------------------------------------------------
4943
4944 ; make a new fresh fat12 file system on floppy disk
4945 ; in: A=format (0 or 2)
4946 ; X=logical drive
Tue Jul 17 11:00:20 2018 Page 43
4947 ; Y=$FF if label is specified
4948 F90DBF newf12:
4949 F90DBF 85 3D sta fdfmt
4950 F90DC1 86 3F stx ldev
4951 F90DC3 84 41 sty lflag
4952 F90DC5 4A lsr a
4953 F90DC6 85 2A sta fdix ; DD/HD index
4954 F90DC8 9B txy
4955 F90DC9 BE D2 40 ldx !P0LDT+ldtp,y
4956 F90DCC 86 40 stx ldtcur
4957 F90DCE BD 00 40 lda !P0LDT+ldt_fg1,x
4958 F90DD1 29 03 and #3
4959 F90DD3 85 3E sta pdev ; phisycal drive
4960 F90DD5 24 41 bit lflag
4961 F90DD7 30 0C bmi ?10 ; label specified
4962 F90DD9 A2 0A ldx #10 ; move standard label
4963 F90DDB BF 8B 1C F9 ?05: lda >PBRLBL,x
4964 F90DDF 9D 53 41 sta !P0FAT+fcbs,x
4965 F90DE2 CA dex
4966 F90DE3 10 F6 bpl ?05
4967 F90DE5 A6 2A ?10: ldx fdix
4968 F90DE7 BF 83 1C F9 lda >FDMEDIA,x
4969 F90DEB 85 2B sta media ; media type
4970 F90DED ACC16
4971 F90DED C2 20 rep #PMFLAG
4972 .LONGA on
4973 .MNLIST
4974 F90DEF A6 40 ldx ldtcur
4975 F90DF1 BD 26 40 lda !P0LDT+ldt_pbr,x ; set PBR pointer
4976 F90DF4 85 32 sta pbrp
4977 F90DF6 BC 28 40 ldy !P0LDT+ldt_pbr+2,x
4978 F90DF9 84 34 sty pbrp+2
4979 F90DFB BD 22 40 lda !P0LDT+ldt_fp,x ; set fat1 table pointer
4980 F90DFE 85 3A sta tp
4981 F90E00 BC 24 40 ldy !P0LDT+ldt_fp+2,x
4982 F90E03 84 3C sty tp+2
4983 F90E05 A9 B1 1C lda #F12HDD ; boot sector header DD
4984 F90E08 A4 3D ldy fdfmt
4985 F90E0A F0 03 beq ?12
4986 F90E0C A9 CD 1C lda #F12HHD ; boot sector header HD
4987 F90E0F 85 4C ?12: sta tlp
4988 F90E11 A0 F9 ldy #.SEG.F12HDD
4989 F90E13 84 4E sty tlp+2
4990 F90E15 A9 00 24 lda #$2400 ; bytes for DD whole track
4991 F90E18 A4 3D ldy fdfmt
4992 F90E1A F0 03 beq ?15
4993 F90E1C A9 00 48 lda #$4800 ; bytes for HD whole track
4994 F90E1F A2 00 ?15: ldx #0
4995 F90E21 INDEX16
4996 F90E21 C2 10 rep #PXFLAG
4997 .LONGI on
4998 .MNLIST
4999 F90E23 A8 tay
5000 F90E24 88 dey
5001 F90E25 88 dey ; index
5002 F90E26 8A txa ; clear C
5003 F90E27 97 32 ?20: sta [pbrp],y ; clear track buffer
Tue Jul 17 11:00:20 2018 Page 44
5004 F90E29 88 dey
5005 F90E2A 88 dey
5006 F90E2B 10 FA bpl ?20
5007 F90E2D A0 FE 01 ldy #$01FE ; store signature in boot sector
5008 F90E30 A9 55 AA lda #$AA55
5009 F90E33 97 32 sta [pbrp],y
5010 F90E35 CPU08
5011 F90E35 E2 30 sep #(PMFLAG.OR.PXFLAG)
5012 .LONGA off
5013 .LONGI off
5014 .MNLIST
5015 F90E37 A0 1B ldy #F12HSIZ-1 ; move boot sector header
5016 F90E39 B7 4C ?25: lda [tlp],y
5017 F90E3B 97 32 sta [pbrp],y
5018 F90E3D 88 dey
5019 F90E3E 10 F9 bpl ?25
5020 F90E40 A0 26 ldy #$26 ; extended boot signature flag
5021 F90E42 A9 29 lda #$29
5022 F90E44 97 32 sta [pbrp],y
5023 F90E46 A0 2B ldy #$2B ; volume label pointer
5024 F90E48 BD 53 41 ?30: lda !P0FAT+fcbs,x
5025 F90E4B 97 32 sta [pbrp],y
5026 F90E4D E8 inx
5027 F90E4E C8 iny
5028 F90E4F E0 0B cpx #11
5029 F90E51 90 F5 bcc ?30
5030 F90E53 A2 00 ldx #0
5031 F90E55 BF A1 1C F9 ?35: lda >F12NAM,x ; store system name
5032 F90E59 97 32 sta [pbrp],y
5033 F90E5B E8 inx
5034 F90E5C C8 iny
5035 F90E5D E0 08 cpx #8
5036 F90E5F 90 F4 bcc ?35
5037 F90E61 20 C7 1B jsr gettime ; get time stamp
5038 F90E64 A0 27 ldy #$27
5039 F90E66 ACC16
5040 F90E66 C2 20 rep #PMFLAG
5041 .LONGA on
5042 .MNLIST
5043 F90E68 A5 48 lda ctime ; store volume serial number
5044 F90E6A 97 32 sta [pbrp],y
5045 F90E6C C8 iny
5046 F90E6D C8 iny
5047 F90E6E A5 4A lda cdate
5048 F90E70 97 32 sta [pbrp],y
5049 F90E72 A9 00 0E lda #$0E00 ; DD root directory offset
5050 F90E75 A4 3D ldy fdfmt
5051 F90E77 F0 03 beq ?40
5052 F90E79 A9 00 26 lda #$2600 ; HD root directory offset
5053 F90E7C 18 ?40: clc
5054 F90E7D 65 32 adc pbrp
5055 F90E7F 85 4C sta tlp ; root directory pointer
5056 F90E81 A4 34 ldy pbrp+2
5057 F90E83 84 4E sty tlp+2
5058 F90E85 A5 48 lda ctime ; store volume label write/creation time
5059 F90E87 A0 0E ldy #$0E ; index of creation
5060 F90E89 97 4C sta [tlp],y
Tue Jul 17 11:00:20 2018 Page 45
5061 F90E8B A0 16 ldy #$16 ; index of write time
5062 F90E8D 97 4C sta [tlp],y
5063 F90E8F C8 iny
5064 F90E90 C8 iny
5065 F90E91 A5 4A lda cdate
5066 F90E93 97 4C sta [tlp],y
5067 F90E95 A0 10 ldy #$10
5068 F90E97 97 4C sta [tlp],y
5069 F90E99 ACC08
5070 F90E99 E2 20 sep #PMFLAG
5071 .LONGA off
5072 .MNLIST
5073 F90E9B A0 0D ldy #13
5074 F90E9D A5 53 lda sec100
5075 F90E9F 97 4C sta [tlp],y
5076 F90EA1 A2 00 ldx #0 ; store volume label in root directory
5077 F90EA3 9B txy
5078 F90EA4 BD 53 41 ?45: lda !P0FAT+fcbs,x
5079 F90EA7 97 4C sta [tlp],y
5080 F90EA9 E8 inx
5081 F90EAA C8 iny
5082 F90EAB E0 0B cpx #11
5083 F90EAD 90 F5 bcc ?45
5084 F90EAF A9 08 lda #DA_VOLUME ; store label attribute
5085 F90EB1 97 4C sta [tlp],y
5086 F90EB3 ACC16CLC
5087 F90EB3 C2 21 rep #(PMFLAG.OR.PCFLAG)
5088 .LONGA on
5089 .MNLIST
5090 F90EB5 A9 00 06 lda #$0600 ; fat 2 offset
5091 F90EB8 A4 3D ldy fdfmt
5092 F90EBA F0 03 beq ?50
5093 F90EBC A9 00 12 lda #$1200
5094 F90EBF 65 3A ?50: adc tp
5095 F90EC1 85 4C sta tlp ; fat 2 pointer
5096 F90EC3 A4 3C ldy tp+2
5097 F90EC5 84 4E sty tlp+2
5098 F90EC7 A9 FF FF lda #$FFFF ; store fake cluster 0&1
5099 F90ECA A0 01 ldy #1
5100 F90ECC 97 3A sta [tp],y
5101 F90ECE 97 4C sta [tlp],y
5102 F90ED0 ACC08
5103 F90ED0 E2 20 sep #PMFLAG
5104 .LONGA off
5105 .MNLIST
5106 F90ED2 A5 2B lda media
5107 F90ED4 87 3A sta [tp]
5108 F90ED6 87 4C sta [tlp]
5109 F90ED8 A6 3E ldx pdev ; write whole track on disk
5110 F90EDA DA phx ; drive #
5111 F90EDB A9 00 lda #0 ; track #0
5112 F90EDD 48 pha
5113 F90EDE BD D8 40 lda !P0LDT+sysbuf,x
5114 F90EE1 48 pha ; dma buffer #
5115 F90EE2 A5 3D lda fdfmt
5116 F90EE4 09 80 ora #$80 ; verf flag
5117 F90EE6 48 pha ; format
Tue Jul 17 11:00:20 2018 Page 46
5118 F90EE7 FDCTKWR
5119 F90EE7 02 35 cop $35
5120 F90EE9 02 .DB $02
5121 .MNLIST
5122 F90EEA 60 nx: rts ; return CF=1 if error
5123
5124 ; create partition on fixed disk X and format it
5125 ; in: X=logical drive
5126 ; Y=$FF if label is specified
5127 F90EEB lfdisk:
5128 F90EEB 20 83 11 jsr prenew ; prepare for partitioning
5129 F90EEE B0 FA bcs nx
5130 F90EF0 A5 39 lda lunit
5131 F90EF2 48 pha
5132 F90EF3 4B phk
5133 F90EF4 F4 27 0F pea #!?08
5134 F90EF7 A9 05 lda #5
5135 F90EF9 48 pha
5136 F90EFA BPRINTF
5137 F90EFA 02 11 cop $11
5138 .MNLIST
5139 F90EFC 20 AF 19 jsr newprt ; prepare for a new partition
5140 F90EFF 90 4F bcc ?10
5141 F90F01 SCNPRINT
5142 F90F01 02 01 cop $01
5143 .MNLIST
5144 F90F03 65 72 72 6F 72 .DB 'error computing a new partition.', 13, 0
20 63 6F 6D 70
75 74 69 6E 67
20 61 20 6E 65
77 20 70 61 72
74 69 74 69 6F
6E 2E 0D 00
5145 F90F25 38 sec
5146 F90F26 60 ?05: rts
5147
5148 F90F27 0D 70 61 72 74 ?08: .DB 13, 'partitioning fixed disk on drive <%c>:', 13, 0
69 74 69 6F 6E
69 6E 67 20 66
69 78 65 64 20
64 69 73 6B 20
6F 6E 20 64 72
69 76 65 20 3C
25 63 3E 3A 0D
00
5149
5150 F90F50 A9 80 ?10: lda #$80
5151 F90F52 85 41 sta lflag ; flag creation new pbr/mbr
5152 F90F54 80 05 bra lfmt2
5153 F90F56
5154 ; format main partition on fixed disk X
5155 ; in: X=logical drive
5156 ; Y=$FF if label is specified
5157 F90F56 lhdfmt:
5158 F90F56 20 40 17 jsr prefmt ; format pre-task
5159 F90F59 B0 8F bcs nx
5160 F90F5B
Tue Jul 17 11:00:20 2018 Page 47
5161 F90F5B lfmt2:
5162 F90F5B 20 B5 17 jsr showprt
5163 F90F5E 20 30 1B jsr askcont
5164 F90F61 90 01 bcc ?01
5165 F90F63 60 rts
5166 F90F64 ?01: SCN_CR
5167 F90F64 SCNPRCHAR
5168 .MLIST
5169 F90F64 02 07 cop $07
5170 .MNLIST
5171 F90F66 0D .DB $0D
5172 .MNLIST
5173 F90F67 24 41 bit lflag
5174 F90F69 10 2C bpl ?02
5175 F90F6B 20 ED 12 jsr newpbr ; create a new pbr/mbr
5176 F90F6E
5177 ; transfer to DMA buffer
5178 F90F6E 8B phb
5179 F90F6F A9 08 lda #$08 ; PB3 VIA3
5180 F90F71 1C C0 FD trb VIA3+VIAPRB ; enable 1Mb buffer
5181 F90F74 AD CF FD lda !VIA3+VIAPRANH
5182 F90F77 29 F8 and #$F8
5183 F90F79 8D CF FD sta !VIA3+VIAPRANH ; set bank $00
5184 F90F7C CPU16
5185 F90F7C C2 30 rep #(PMFLAG.OR.PXFLAG)
5186 .LONGA on
5187 .LONGI on
5188 .MNLIST
5189 F90F7E A9 FF 01 lda #$01FF
5190 F90F81 A0 00 42 ldy #$4200 ; dest -> $024200 (buffer $21)
5191 F90F84 A6 32 ldx pbrp ; source
5192 F90F86 54 02 01 mvn #1, #2
5193 F90F89 A9 FF 01 lda #$01FF
5194 F90F8C A0 00 40 ldy #$4000 ; dest -> $024000 (buffer $20)
5195 F90F8F A6 4C ldx tlp ; source
5196 F90F91 54 02 01 mvn #1, #2
5197 F90F94 CPU08
5198 F90F94 E2 30 sep #(PMFLAG.OR.PXFLAG)
5199 .LONGA off
5200 .LONGI off
5201 .MNLIST
5202 F90F96 AB plb
5203
5204 F90F97 A5 51 ?02: lda fatbnk
5205 F90F99 20 1F 14 jsr newfat
5206 F90F9C A5 50 lda rootbnk
5207 F90F9E 20 71 14 jsr newroot
5208 F90FA1 A5 52 lda clsbnk
5209 F90FA3 20 F8 14 jsr newcls
5210 F90FA6 20 F3 1A jsr askfmt
5211 F90FA9 90 03 bcc ?04 ; quick format
5212 F90FAB 20 63 10 jsr fmtcls ; write out cluster's
5213 F90FAE ?04: SCN_CR
5214 F90FAE SCNPRCHAR
5215 .MLIST
5216 F90FAE 02 07 cop $07
5217 .MNLIST
Tue Jul 17 11:00:20 2018 Page 48
5218 F90FB0 0D .DB $0D
5219 .MNLIST
5220 F90FB1 24 41 bit lflag
5221 F90FB3 10 0A bpl ?06 ; skip MBR&PBR write out
5222 F90FB5 20 04 16 jsr wrmbr ; write out MBR
5223 F90FB8 B0 63 bcs ?10 ; error
5224 F90FBA 20 C8 15 jsr wrpbr ; write out PBR
5225 F90FBD B0 5E bcs ?10
5226 F90FBF A9 00 ?06: lda #0
5227 F90FC1 EB xba ; B=0
5228 F90FC2 A5 51 lda fatbnk
5229 F90FC4 ACC16
5230 F90FC4 C2 20 rep #PMFLAG
5231 .LONGA on
5232 .MNLIST
5233 F90FC6 0A asl a
5234 F90FC7 0A asl a
5235 F90FC8 0A asl a
5236 F90FC9 0A asl a
5237 F90FCA 85 2A sta xfatb ; x-mem fat buffer
5238 F90FCC A5 22 lda fat1
5239 F90FCE 85 2C sta flba
5240 F90FD0 ACC08
5241 F90FD0 E2 20 sep #PMFLAG
5242 .LONGA off
5243 .MNLIST
5244 F90FD2 A2 01 ldx #1 ; write out fat1
5245 F90FD4 20 7B 16 jsr wrfat
5246 F90FD7 B0 44 bcs ?10
5247 F90FD9 A5 24 lda fat2
5248 F90FDB 85 2C sta flba
5249 F90FDD A5 25 lda fat2+1
5250 F90FDF 85 2D sta flba+1
5251 F90FE1 A2 02 ldx #2 ; write out fat1
5252 F90FE3 20 7B 16 jsr wrfat
5253 F90FE6 B0 35 bcs ?10
5254 F90FE8 A9 00 lda #0
5255 F90FEA EB xba ; B=0
5256 F90FEB A5 50 lda rootbnk
5257 F90FED ACC16
5258 F90FED C2 20 rep #PMFLAG
5259 .LONGA on
5260 .MNLIST
5261 F90FEF 0A asl a
5262 F90FF0 0A asl a
5263 F90FF1 0A asl a
5264 F90FF2 0A asl a
5265 F90FF3 85 2A sta xfatb ; x-mem fat buffer
5266 F90FF5 A5 20 lda root
5267 F90FF7 85 2C sta flba
5268 F90FF9 ACC08
5269 F90FF9 E2 20 sep #PMFLAG
5270 .LONGA off
5271 .MNLIST
5272 F90FFB 20 7D 15 jsr wrroot
5273 F90FFE B0 1D bcs ?10
5274 F91000 A6 3E ldx pdev ; update drive flag
Tue Jul 17 11:00:20 2018 Page 49
5275 F91002 B5 0E lda atadev,x
5276 F91004 29 E0 and #$E0
5277 F91006 09 1D ora #$1D
5278 F91008 95 0E sta atadev,x
5279 F9100A 20 6D 0D jsr mvldt
5280 F9100D A9 E0 lda #$E0
5281 F9100F 9D 01 40 sta !P0LDT+ldt_fg2,x
5282 F91012 9E 20 40 stz !P0LDT+ldt_cdlvl,x
5283 F91015 9E 1E 40 stz !P0LDT+ldt_cdcls,x
5284 F91018 9E 1F 40 stz !P0LDT+ldt_cdcls+1,x
5285 F9101B 18 clc
5286 F9101C 60 ?08: rts
5287 F9101D A6 40 ?10: ldx ldtcur ; invalidate logical drive if error
5288 F9101F 9E 01 40 stz !P0LDT+ldt_fg2,x
5289 F91022 A6 3E ldx pdev ; invalidate drive if error
5290 F91024 B5 0E lda atadev,x
5291 F91026 29 E0 and #$E0
5292 F91028 95 0E sta atadev,x
5293 F9102A 8A txa
5294 F9102B 0A asl a
5295 F9102C 0A asl a
5296 F9102D AA tax
5297 F9102E A0 00 ldy #0
5298 F91030 CPU16
5299 F91030 C2 30 rep #(PMFLAG.OR.PXFLAG)
5300 .LONGA on
5301 .LONGI on
5302 .MNLIST
5303 F91032 9E 22 00 stz !atambr,x
5304 F91035 9E 24 00 stz !atambr+2,x
5305 F91038 9E 32 00 stz !ataprt,x
5306 F9103B 9E 34 00 stz !ataprt+2,x
5307 F9103E 98 tya ; C=0
5308 F9103F 97 4C ?15: sta [tlp],y ; clear MBR
5309 F91041 C8 iny
5310 F91042 C8 iny
5311 F91043 C0 00 02 cpy #$200
5312 F91046 90 F7 bcc ?15
5313 F91048 CPU08
5314 F91048 E2 30 sep #(PMFLAG.OR.PXFLAG)
5315 .LONGA off
5316 .LONGI off
5317 .MNLIST
5318 F9104A A5 3E lda pdev ; write out an empty invalid MBR
5319 F9104C 48 pha ; ata drive
5320 F9104D A9 00 lda #0
5321 F9104F 48 pha
5322 F91050 F4 00 00 pea #0 ; lba=0
5323 F91053 A9 01 lda #1
5324 F91055 48 pha ; write 1 sector
5325 F91056 A5 4E lda tlp+2
5326 F91058 48 pha ; buffer pointer
5327 F91059 D4 4C pei (tlp)
5328 F9105B A9 00 lda #$00 ; no verify after write
5329 F9105D 48 pha
5330 F9105E ATAWRITE
5331 F9105E 02 40 cop $40
Tue Jul 17 11:00:20 2018 Page 50
5332 F91060 02 .DB $02
5333 .MNLIST
5334 F91061 38 sec ; return error status
5335 F91062 60 ?20: rts
5336
5337 F91063 fmtcls:
5338 F91063 SCN_CR
5339 F91063 SCNPRCHAR
5340 .MLIST
5341 F91063 02 07 cop $07
5342 .MNLIST
5343 F91065 0D .DB $0D
5344 .MNLIST
5345 F91066 SCNPRINT
5346 F91066 02 01 cop $01
5347 .MNLIST
5348 F91068 70 72 65 73 73 .DB 'press <CTRL+BREAK> to stop.', 13, 0
20 3C 43 54 52
4C 2B 42 52 45
41 4B 3E 20 74
6F 20 73 74 6F
70 2E 0D 00
5349 F91085 SCNGETPOS
5350 F91085 02 18 cop $18
5351 F91087 02 .DB $02
5352 .MNLIST
5353 F91088 86 4F stx fd2ix
5354 F9108A A9 00 lda #0
5355 F9108C 85 13 sta first+1 ; cluster size 16 bit
5356 F9108E 85 16 sta rsvsec ; lba hi
5357 F91090 A6 35 ldx clssiz
5358 F91092 86 12 stx first
5359 F91094 A2 01 ldx #XMBANK
5360 F91096 86 3C stx tp+2
5361 F91098 EB xba ; B=0
5362 F91099 A5 52 lda clsbnk
5363 F9109B ACC16
5364 F9109B C2 20 rep #PMFLAG
5365 .LONGA on
5366 .MNLIST
5367 F9109D 0A asl a
5368 F9109E 0A asl a
5369 F9109F 0A asl a
5370 F910A0 0A asl a
5371 F910A1 85 2A sta xfatb ; x-mem fat buffer
5372 F910A3 A5 26 lda start
5373 F910A5 85 2C sta flba ; cluster #2 lba
5374 F910A7 A9 02 00 lda #2
5375 F910AA 85 14 sta clscnt ; start with cluster #2
5376 F910AC A5 28 lda maxcls
5377 F910AE 3A dec a
5378 F910AF 85 10 sta maxcnt
5379 F910B1 64 42 stz badcls
5380 F910B3 ACC08
5381 F910B3 E2 20 sep #PMFLAG
5382 .LONGA off
5383 .MNLIST
Tue Jul 17 11:00:20 2018 Page 51
5384 F910B5 A6 4F ?10: ldx fd2ix ; set screen position
5385 F910B7 A0 00 ldy #0
5386 F910B9 SCNSETPOS
5387 F910B9 02 18 cop $18
5388 F910BB 03 .DB $03
5389 .MNLIST
5390 F910BC D4 10 pei (maxcnt)
5391 F910BE D4 14 pei (clscnt)
5392 F910C0 4B phk
5393 F910C1 F4 49 11 pea #!?100
5394 F910C4 A9 08 lda #8
5395 F910C6 48 pha
5396 F910C7 BPRINTF
5397 F910C7 02 11 cop $11
5398 .MNLIST
5399 F910C9 A5 3E lda pdev
5400 F910CB 48 pha ; ata drive
5401 F910CC A5 16 lda rsvsec
5402 F910CE 48 pha
5403 F910CF D4 2C pei (flba) ; fat table lba
5404 F910D1 A5 12 lda first
5405 F910D3 48 pha ; write n sector
5406 F910D4
5407 ;lda #0
5408 ;pha ; A=0 -> x-mem buffer
5409 ;pei (xfatb)
5410 ;lda #$80 ; verify after write
5411 ;pha
5412 ;ATAWRITE
5413 F910D4
5414 F910D4 F4 40 00 pea #$40
5415 F910D7 ATADMAWR
5416 F910D7 02 42 cop $42
5417 F910D9 01 .DB $01
5418 .MNLIST
5419
5420 F910DA 90 03 bcc ?20 ; write ok
5421 ;brk
5422 F910DC 20 1B 11 jsr ?40 ; mark bad cluster
5423 F910DF ?20: ACC16
5424 F910DF C2 20 rep #PMFLAG
5425 .LONGA on
5426 .MNLIST
5427 F910E1 A5 14 lda clscnt
5428 F910E3 1A inc a
5429 F910E4 C5 28 cmp maxcls
5430 F910E6 B0 10 bcs ?30
5431 F910E8 85 14 sta clscnt
5432 F910EA A5 2C lda flba
5433 F910EC A2 00 ldx #0
5434 F910EE 65 12 adc first
5435 F910F0 85 2C sta flba
5436 F910F2 90 02 bcc ?25
5437 F910F4 E8 inx
5438 F910F5 18 clc
5439 F910F6 86 16 ?25: stx rsvsec
5440 F910F8 ?30: ACC08
Tue Jul 17 11:00:20 2018 Page 52
5441 F910F8 E2 20 sep #PMFLAG
5442 .LONGA off
5443 .MNLIST
5444 F910FA B0 0A bcs ?35
5445 F910FC AD 4B 00 lda !CtrlBrk
5446 F910FF 9C 4B 00 stz !CtrlBrk
5447 F91102 C9 80 cmp #$80
5448 F91104 D0 AF bne ?10
5449 F91106 ?35: SCNPRINT
5450 F91106 02 01 cop $01
5451 .MNLIST
5452 F91108 64 6F 6E 65 2E .DB 'done.', 13, 0
0D 00
5453 F9110F D4 42 pei (badcls)
5454 F91111 4B phk
5455 F91112 F4 69 11 pea #!?110
5456 F91115 A9 06 lda #6
5457 F91117 48 pha
5458 F91118 BPRINTF
5459 F91118 02 11 cop $11
5460 .MNLIST
5461 F9111A 60 rts
5462
5463 F9111B AE 0A FC ?40: ldx CRXME ; save X mem setting
5464 F9111E DA phx
5465 F9111F 8D 0B FC sta !CRXMEON ; enable X mem in window $012000 - $013FFF
5466 F91122 A5 15 lda clscnt+1 ; A=sector (one sec. = 256 cluster #)
5467 F91124 AA tax
5468 F91125 4A lsr a ; divide by 16 to get x-mem buffer bank
5469 F91126 4A lsr a
5470 F91127 4A lsr a
5471 F91128 4A lsr a
5472 F91129 18 clc
5473 F9112A 65 51 adc fatbnk ; add fat table base base bank
5474 F9112C 8D 28 FD sta !PIA0+PIAPRA ; set bank
5475 F9112F 8A txa
5476 F91130 EB xba
5477 F91131 A5 14 lda clscnt
5478 F91133 ACC16
5479 F91133 C2 20 rep #PMFLAG
5480 .LONGA on
5481 .MNLIST
5482 F91135 29 FF 0F and #$0FFF ; mask 4096 cluster's
5483 F91138 0A asl a
5484 F91139 85 3A sta tp
5485 F9113B A9 F7 FF lda #$FFF7
5486 F9113E 87 3A sta [tp]
5487 F91140 E6 42 inc badcls
5488 F91142 ACC08
5489 F91142 E2 20 sep #PMFLAG
5490 .LONGA off
5491 .MNLIST
5492 F91144 FA plx ; restore X mem setting
5493 F91145 9D 0A FC sta !CRXME,x
5494 F91148 60 rts
5495
5496 F91149 63 6C 65 61 72 ?100: .DB 'clear cluster %05hu of %05hu...', 0
Tue Jul 17 11:00:20 2018 Page 53
20 63 6C 75 73
74 65 72 20 25
30 35 68 75 20
6F 66 20 25 30
35 68 75 2E 2E
2E 00
5497 F91169 64 65 66 65 63 ?110: .DB 'defective cluster(s): %hu', 0
74 69 76 65 20
63 6C 75 73 74
65 72 28 73 29
3A 20 25 68 75
00
5498
5499 ; common pre task routine for format fixed disk
5500 ; in: X=logical drive
5501 ; Y=$FF if label is specified
5502 F91183 prenew:
5503 F91183 86 3F stx ldev
5504 F91185 84 41 sty lflag
5505 F91187 9B txy
5506 F91188 BE D2 40 ldx !P0LDT+ldtp,y
5507 F9118B 86 40 stx ldtcur
5508 F9118D 3C 00 40 bit !P0LDT+ldt_fg1,x
5509 F91190 10 02 bpl ?01 ; not ready
5510 F91192 70 10 bvs ?03 ; ok, ata device
5511 F91194 98 ?01: tya
5512 F91195 18 clc
5513 F91196 69 41 adc #'A'
5514 F91198 48 pha
5515 F91199 4B phk
5516 F9119A F4 BA 12 pea #!?100
5517 F9119D A9 05 lda #5
5518 F9119F 48 pha
5519 F911A0 BPRINTF
5520 F911A0 02 11 cop $11
5521 .MNLIST
5522 F911A2 38 sec
5523 F911A3 60 rts
5524 F911A4 BD 00 40 ?03: lda !P0LDT+ldt_fg1,x
5525 F911A7 29 03 and #3
5526 F911A9 85 3E sta pdev ; phisycal drive
5527 F911AB 18 clc
5528 F911AC 69 43 adc #'C' ; ata device: 'C' or 'D'
5529 F911AE 85 39 sta lunit ; logical drive letter
5530 F911B0 24 41 bit lflag
5531 F911B2 30 0C bmi ?10 ; label specified
5532 F911B4 A2 0A ldx #10 ; move standard label
5533 F911B6 BF 96 1C F9 ?05: lda >NOLBL,x
5534 F911BA 9D 53 41 sta !P0FAT+fcbs,x
5535 F911BD CA dex
5536 F911BE 10 F6 bpl ?05
5537 F911C0 64 41 ?10: stz lflag
5538 F911C2 A5 3E lda pdev
5539 F911C4 0A asl a
5540 F911C5 0A asl a
5541 F911C6 AA tax
5542 F911C7 ACC16
Tue Jul 17 11:00:20 2018 Page 54
5543 F911C7 C2 20 rep #PMFLAG
5544 .LONGA on
5545 .MNLIST
5546 F911C9 BD 12 00 lda !atasec,x ; max. disk usable sector's
5547 F911CC 85 04 sta maxsec
5548 F911CE BD 14 00 lda !atasec+2,x
5549 F911D1 85 06 sta maxsec+2
5550 F911D3 BD 22 00 lda !atambr,x
5551 F911D6 85 08 sta hidsec
5552 F911D8 BD 24 00 lda !atambr+2,x
5553 F911DB 29 FF 00 and #$00FF
5554 F911DE 85 0A sta hidsec+2
5555 F911E0 BD 32 00 lda !ataprt,x
5556 F911E3 85 0C sta totsec
5557 F911E5 BD 34 00 lda !ataprt+2,x
5558 F911E8 85 0E sta totsec+2
5559 F911EA A6 40 ldx ldtcur
5560 F911EC BD 26 40 lda !P0LDT+ldt_pbr,x ; set PBR pointer
5561 F911EF 85 32 sta pbrp
5562 F911F1 BC 28 40 ldy !P0LDT+ldt_pbr+2,x
5563 F911F4 84 34 sty pbrp+2
5564 F911F6 BD 22 40 lda !P0LDT+ldt_fp,x ; set fat1 table pointer
5565 F911F9 85 3A sta tp
5566 F911FB BC 24 40 ldy !P0LDT+ldt_fp+2,x
5567 F911FE 84 3C sty tp+2
5568 F91200 A9 00 88 lda #MBR0ATA ; set pointer for MBR
5569 F91203 A4 3E ldy pdev
5570 F91205 F0 0A beq ?15
5571 F91207 A9 00 8A lda #MBR1ATA
5572 F9120A C0 01 cpy #1
5573 F9120C F0 03 beq ?15
5574 F9120E A9 00 94 lda #MBR0USB
5575 F91211 85 4C ?15: sta tlp
5576 F91213 A0 01 ldy #^MBR0ATA
5577 F91215 84 4E sty tlp+2
5578 F91217 BC 25 40 ldy !P0LDT+ldt_fbuf,x
5579 F9121A 84 51 sty fatbnk ; x-mem bank for fat cache buffer
5580 F9121C BD 02 40 lda !P0LDT+ldt_root,x
5581 F9121F 85 20 sta root
5582 F91221 BD 04 40 lda !P0LDT+ldt_fat1,x
5583 F91224 85 22 sta fat1
5584 F91226 BD 06 40 lda !P0LDT+ldt_fat2,x
5585 F91229 85 24 sta fat2
5586 F9122B BD 08 40 lda !P0LDT+ldt_cls,x
5587 F9122E 85 26 sta start
5588 F91230 BD 0C 40 lda !P0LDT+ldt_rent,x
5589 F91233 85 1C sta rootent
5590 F91235 BD 0E 40 lda !P0LDT+ldt_cent,x
5591 F91238 85 1E sta clsent
5592 F9123A BD 12 40 lda !P0LDT+ldt_free,x
5593 F9123D 85 2E sta freecnt
5594 F9123F BD 14 40 lda !P0LDT+ldt_nxt,x
5595 F91242 85 30 sta freecls
5596 F91244 BC 18 40 ldy !P0LDT+ldt_csiz,x
5597 F91247 84 35 sty clssiz
5598 F91249 BD 0A 40 lda !P0LDT+ldt_max,x
5599 F9124C 85 28 sta maxcls
Tue Jul 17 11:00:20 2018 Page 55
5600 F9124E 3A dec a
5601 F9124F 3A dec a
5602 F91250 85 14 sta clscnt
5603 F91252 BC 19 40 ldy !P0LDT+ldt_cshf,x
5604 F91255 84 36 sty clsshf
5605 F91257 A0 B4 ldy #$B4
5606 F91259 84 50 sty rootbnk ; root dir. x-mem bank
5607 F9125B A0 B8 ldy #$B8
5608 F9125D 84 52 sty clsbnk ; cluster x-mem bank
5609 F9125F ACC08
5610 F9125F E2 20 sep #PMFLAG
5611 .LONGA off
5612 .MNLIST
5613 F91261 A0 00 ldy #0
5614 F91263 BD 16 40 lda !P0LDT+ldt_fsiz,x
5615 F91266 85 18 sta fatsiz
5616 F91268 D0 01 bne ?16
5617 F9126A C8 iny
5618 F9126B 84 19 ?16: sty fatsiz+1
5619 F9126D BD 1A 40 lda !P0LDT+ldt_rsiz,x
5620 F91270 85 1A sta rootsiz
5621 F91272 BD 1B 40 lda !P0LDT+ldt_mcls,x
5622 F91275 85 37 sta clsmod
5623 F91277 BD 29 40 lda !P0LDT+ldt_fmt,x
5624 F9127A 85 3D sta fdfmt
5625 F9127C BD 01 40 lda !P0LDT+ldt_fg2,x
5626 F9127F 64 41 stz lflag ; invalid partition flag
5627 F91281 29 E0 and #$E0 ; valid partition?
5628 F91283 C9 E0 cmp #$E0
5629 F91285 D0 31 bne ?50 ; no
5630 F91287 85 41 sta lflag ; valid partition flag
5631 F91289 ACC16
5632 F91289 C2 20 rep #PMFLAG
5633 .LONGA on
5634 .MNLIST
5635 F9128B A5 14 lda clscnt
5636 F9128D 85 2E sta remsec
5637 F9128F A9 00 00 lda #0
5638 F91292 A4 36 ldy clsshf
5639 F91294 F0 06 beq ?25
5640 F91296 06 2E ?20: asl remsec
5641 F91298 2A rol a
5642 F91299 88 dey
5643 F9129A D0 FA bne ?20
5644 F9129C 85 30 ?25: sta remsec+2
5645 F9129E 18 clc
5646 F9129F A5 26 lda start
5647 F912A1 65 2E adc remsec
5648 F912A3 85 2E sta remsec
5649 F912A5 90 02 bcc ?30
5650 F912A7 E6 30 inc remsec+2
5651 F912A9 38 ?30: sec
5652 F912AA A5 04 lda maxsec
5653 F912AC E5 2E sbc remsec
5654 F912AE 85 2E sta remsec
5655 F912B0 A5 06 lda maxsec+2
5656 F912B2 E5 30 sbc remsec+2
Tue Jul 17 11:00:20 2018 Page 56
5657 F912B4 85 30 sta remsec+2
5658 F912B6 ACC08
5659 F912B6 E2 20 sep #PMFLAG
5660 .LONGA off
5661 .MNLIST
5662 F912B8 18 ?50: clc
5663 F912B9 60 rts
5664
5665 F912BA 0D 65 72 72 6F ?100: .DB 13, 'error: drive <%c> not ready or not a fixed disk.', 13, 0
72 3A 20 64 72
69 76 65 20 3C
25 63 3E 20 6E
6F 74 20 72 65
61 64 79 20 6F
72 20 6E 6F 74
20 61 20 66 69
78 65 64 20 64
69 73 6B 2E 0D
00
5666
5667 ; set a new MBR/PBR for ata drive
5668 F912ED newpbr:
5669 F912ED A0 00 ldy #0
5670 F912EF A5 3E lda pdev
5671 F912F1 0A asl a
5672 F912F2 0A asl a
5673 F912F3 AA tax ; device index
5674 F912F4 CPU16
5675 F912F4 C2 30 rep #(PMFLAG.OR.PXFLAG)
5676 .LONGA on
5677 .LONGI on
5678 .MNLIST
5679 F912F6 98 tya ; C=0
5680 F912F7 97 32 ?10: sta [pbrp],y ; clear PBR...
5681 F912F9 97 4C sta [tlp],y ; ...and MBR
5682 F912FB C8 iny
5683 F912FC C8 iny
5684 F912FD C0 FE 01 cpy #$01FE
5685 F91300 90 F5 bcc ?10
5686 F91302 A9 55 AA lda #$AA55 ; put signature
5687 F91305 97 32 sta [pbrp],y
5688 F91307 97 4C sta [tlp],y
5689 F91309 A0 BE 01 ldy #$01BE ; ptr to first partition in MBR
5690 F9130C ACC08
5691 F9130C E2 20 sep #PMFLAG
5692 .LONGA off
5693 .MNLIST
5694 F9130E A9 80 lda #$80
5695 F91310 97 4C sta [tlp],y ; first active partition
5696 F91312 C8 iny ; $01BF
5697 F91313 A9 01 lda #1 ; fake CHS
5698 F91315 97 4C sta [tlp],y
5699 F91317 C8 iny ; $01C0
5700 F91318 97 4C sta [tlp],y
5701 F9131A C8 iny ; $01C1
5702 F9131B A9 00 lda #0
5703 F9131D 97 4C sta [tlp],y
Tue Jul 17 11:00:20 2018 Page 57
5704 F9131F C8 iny ; $01C2
5705 F91320 A9 06 lda #6 ; partition type = FAT16
5706 F91322 97 4C sta [tlp],y
5707 F91324 C8 iny ; $01C3
5708 F91325 A9 FE lda #$FE ; fake CHS
5709 F91327 97 4C sta [tlp],y
5710 F91329 C8 iny ; $01C4
5711 F9132A 1A inc a
5712 F9132B 97 4C sta [tlp],y
5713 F9132D C8 iny ; $01C5
5714 F9132E 97 4C sta [tlp],y
5715 F91330 C8 iny ; $01C6 -> partition start lba
5716 F91331 ACC16
5717 F91331 C2 20 rep #PMFLAG
5718 .LONGA on
5719 .MNLIST
5720 F91333 A5 08 lda hidsec
5721 F91335 97 4C sta [tlp],y
5722 F91337 9D 22 00 sta !atambr,x
5723 F9133A C8 iny
5724 F9133B C8 iny
5725 F9133C A5 0A lda hidsec+2 ; this is always null
5726 F9133E 97 4C sta [tlp],y
5727 F91340 09 00 06 ora #$0600 ; partition type
5728 F91343 9D 24 00 sta !atambr+2,x
5729 F91346 C8 iny
5730 F91347 C8 iny ; $01CA -> partition total sectors
5731 F91348 A5 0C lda totsec
5732 F9134A AA tax
5733 F9134B 97 4C sta [tlp],y
5734 F9134D C8 iny
5735 F9134E C8 iny
5736 F9134F A5 0E lda totsec+2
5737 F91351 97 4C sta [tlp],y
5738 F91353 F0 09 beq ?15 ; now switch to PBR
5739 F91355 A0 22 00 ldy #$22 ; partition total sectors 32 high
5740 F91358 97 32 sta [pbrp],y
5741 F9135A 88 dey
5742 F9135B 88 dey
5743 F9135C 80 03 bra ?20
5744 F9135E A0 13 00 ?15: ldy #$13 ; partition total sectors 16
5745 F91361 8A ?20: txa
5746 F91362 97 32 sta [pbrp],y
5747 F91364 INDEX08
5748 F91364 E2 10 sep #PXFLAG
5749 .LONGI off
5750 .MNLIST
5751 F91366 A0 1C ldy #$1C ; hidden sectors
5752 F91368 A5 08 lda hidsec
5753 F9136A 97 32 sta [pbrp],y
5754 F9136C C8 iny
5755 F9136D C8 iny
5756 F9136E A5 0A lda hidsec+2
5757 F91370 97 32 sta [pbrp],y
5758 F91372 A0 0B ldy #$0B ; bytes per sector
5759 F91374 A9 00 02 lda #$0200
5760 F91377 97 32 sta [pbrp],y
Tue Jul 17 11:00:20 2018 Page 58
5761 F91379 A0 11 ldy #$11 ; root directory entries
5762 F9137B 97 32 sta [pbrp],y
5763 F9137D 85 1C sta rootent
5764 F9137F A0 16 ldy #$16 ; fat table size
5765 F91381 A5 18 lda fatsiz
5766 F91383 97 32 sta [pbrp],y
5767 F91385 A0 0E ldy #$0E ; reserved sectors count
5768 F91387 A9 01 00 lda #1
5769 F9138A 97 32 sta [pbrp],y
5770 F9138C 1A inc a ; C=2
5771 F9138D CPU08
5772 F9138D E2 30 sep #(PMFLAG.OR.PXFLAG)
5773 .LONGA off
5774 .LONGI off
5775 .MNLIST
5776 F9138F A0 10 ldy #$10 ; fat's count = 2
5777 F91391 97 32 sta [pbrp],y
5778 F91393 A0 0D ldy #$0D ; sector(s) per cluster
5779 F91395 A5 35 lda clssiz
5780 F91397 97 32 sta [pbrp],y
5781 F91399 A0 15 ldy #$15 ; media type = F8
5782 F9139B A9 F8 lda #$F8
5783 F9139D 97 32 sta [pbrp],y
5784 F9139F A0 26 ldy #$26 ; extended signature flag
5785 F913A1 A9 29 lda #$29
5786 F913A3 97 32 sta [pbrp],y
5787 F913A5 A0 0A ldy #3+8-1 ; OEM name end
5788 F913A7 A2 07 ldx #7
5789 F913A9 BF B4 1C F9 ?25: lda >OEMNAM,x
5790 F913AD 97 32 sta [pbrp],y
5791 F913AF 88 dey
5792 F913B0 CA dex
5793 F913B1 10 F6 bpl ?25
5794 F913B3 E8 inx ; X=0
5795 F913B4 A0 2B ldy #$2B ; volume label pointer
5796 F913B6 BD 53 41 ?30: lda !P0FAT+fcbs,x
5797 F913B9 97 32 sta [pbrp],y
5798 F913BB E8 inx
5799 F913BC C8 iny
5800 F913BD E0 0B cpx #11
5801 F913BF 90 F5 bcc ?30
5802 F913C1 A2 00 ldx #0
5803 F913C3 BF A9 1C F9 ?35: lda >F16NAM,x ; store system name string
5804 F913C7 97 32 sta [pbrp],y
5805 F913C9 E8 inx
5806 F913CA C8 iny
5807 F913CB E0 08 cpx #8
5808 F913CD 90 F4 bcc ?35
5809 F913CF A5 3E lda pdev
5810 F913D1 0A asl a
5811 F913D2 0A asl a
5812 F913D3 AA tax ; device index
5813 F913D4 ACC16
5814 F913D4 C2 20 rep #PMFLAG
5815 .LONGA on
5816 .MNLIST
5817 F913D6 A5 0C lda totsec
Tue Jul 17 11:00:20 2018 Page 59
5818 F913D8 9D 32 00 sta !ataprt,x
5819 F913DB A5 0E lda totsec+2
5820 F913DD 9D 34 00 sta !ataprt+2,x
5821 F913E0 ACC08
5822 F913E0 E2 20 sep #PMFLAG
5823 .LONGA off
5824 .MNLIST
5825 F913E2 20 C7 1B jsr gettime ; get time stamp
5826 F913E5 A9 EB lda #$EB ; this signature in first 3 bytes...
5827 F913E7 87 32 sta [pbrp] ; ...only for microsoft!
5828 F913E9 A0 01 ldy #1
5829 F913EB A9 00 lda #0
5830 F913ED 97 32 sta [pbrp],y
5831 F913EF C8 iny
5832 F913F0 A9 90 lda #$90
5833 F913F2 97 32 sta [pbrp],y
5834 F913F4 A0 27 ldy #$27
5835 F913F6 ACC16
5836 F913F6 C2 20 rep #PMFLAG
5837 .LONGA on
5838 .MNLIST
5839 F913F8 A5 48 lda ctime ; store volume serial number
5840 F913FA 97 32 sta [pbrp],y
5841 F913FC C8 iny
5842 F913FD C8 iny
5843 F913FE A5 4A lda cdate
5844 F91400 97 32 sta [pbrp],y
5845 F91402 A6 35 ldx clssiz
5846 F91404 9B txy
5847 F91405 8A txa ; B=0, A=clssiz
5848 F91406 0A asl a ; 16 entries per sec...
5849 F91407 0A asl a
5850 F91408 0A asl a
5851 F91409 0A asl a ; here CF=0
5852 F9140A 85 1E sta clsent ; entries in cluster
5853 F9140C 88 dey
5854 F9140D 84 37 sty clsmod
5855 F9140F A5 14 lda clscnt
5856 F91411 85 2E sta freecnt
5857 F91413 A9 02 00 lda #2
5858 F91416 85 30 sta freecls
5859 F91418 ACC08
5860 F91418 E2 20 sep #PMFLAG
5861 .LONGA off
5862 .MNLIST
5863 F9141A A9 FF lda #$FF
5864 F9141C 85 3D sta fdfmt
5865 F9141E 60 rts
5866
5867 ; new empty fat table
5868 ; in: A=fat bank buffer
5869 F9141F newfat:
5870
5871 ; clear 128k - buffer $100
5872 F9141F AD CF FD lda !VIA3+VIAPRANH
5873 F91422 29 F8 and #$F8
5874 F91424 09 01 ora #$01
Tue Jul 17 11:00:20 2018 Page 60
5875 F91426 8D CF FD sta !VIA3+VIAPRANH ; set bank 1 (buffer $100)
5876 F91429 A2 00 ldx #0
5877 F9142B 8A txa
5878 F9142C INDEX16
5879 F9142C C2 10 rep #PXFLAG
5880 .LONGI on
5881 .MNLIST
5882 F9142E 9F 00 00 02 ?01: sta >$020000,x
5883 F91432 9F 00 00 03 sta >$030000,x
5884 F91436 E8 inx
5885 F91437 D0 F5 bne ?01
5886 F91439 A9 F8 lda #$FFF8 ; set fake cluster 0&1
5887 F9143B 8F 00 00 02 sta >$020000
5888 F9143F A9 FF lda #$FFFF
5889 F91441 8F 02 00 02 sta >$020002
5890 F91445 INDEX08
5891 F91445 E2 10 sep #PXFLAG
5892 .LONGI off
5893 .MNLIST
5894
5895 F91447 AE 0A FC ldx CRXME ; save X mem setting
5896 F9144A DA phx
5897 F9144B 8D 0B FC sta !CRXMEON ; enable X mem in window $012000 - $013FFF
5898 F9144E 8B phb ; save DBR
5899 F9144F A2 01 ldx #XMBANK
5900 F91451 DA phx
5901 F91452 AB plb ; set DBR to fat table cache
5902 F91453 A0 10 ldy #16 ; clear 16 8k-blocks
5903 F91455 20 27 15 jsr clrxmem
5904 F91458 CPU16
5905 F91458 C2 30 rep #(PMFLAG.OR.PXFLAG)
5906 .LONGA on
5907 .LONGI on
5908 .MNLIST
5909 F9145A A2 00 20 ldx #XMSTART
5910 F9145D A9 F8 FF lda #$FFF8 ; set fake cluster 0&1
5911 F91460 9D 00 00 sta !0,x
5912 F91463 A9 FF FF lda #$FFFF
5913 F91466 9D 02 00 sta !2,x
5914 F91469 CPU08
5915 F91469 E2 30 sep #(PMFLAG.OR.PXFLAG)
5916 .LONGA off
5917 .LONGI off
5918 .MNLIST
5919 F9146B AB plb ; restore DBR
5920 F9146C FA plx ; restore X mem setting
5921 F9146D 9D 0A FC sta !CRXME,x
5922 F91470 60 rts
5923
5924 ; new empty root directory
5925 ; in: A=root directory bank buffer
5926 F91471 newroot:
5927
5928 ; clear 16k - buffer $00
5929 F91471 AD CF FD lda !VIA3+VIAPRANH
5930 F91474 29 F8 and #$F8
5931 F91476 8D CF FD sta !VIA3+VIAPRANH ; set bank 1 (buffer $100)
Tue Jul 17 11:00:20 2018 Page 61
5932 F91479 8B phb
5933 F9147A A9 02 lda #$02
5934 F9147C 48 pha
5935 F9147D AB plb
5936 F9147E INDEX16
5937 F9147E C2 10 rep #PXFLAG
5938 .LONGI on
5939 .MNLIST
5940 F91480 A2 FF 3F ldx #$3FFF
5941 F91483 9E 00 00 ?01: stz !$0,x
5942 F91486 CA dex
5943 F91487 10 FA bpl ?01
5944 F91489 INDEX08
5945 F91489 E2 10 sep #PXFLAG
5946 .LONGI off
5947 .MNLIST
5948 F9148B A9 08 lda #DA_VOLUME
5949 F9148D 99 01 00 sta !0+1,y
5950 F91490 BF 53 41 00 ?04: lda >P0FAT+fcbs,x
5951 F91494 99 00 00 sta !0,y
5952 F91497 88 dey
5953 F91498 CA dex
5954 F91499 10 F5 bpl ?04
5955 F9149B ACC16
5956 F9149B C2 20 rep #PMFLAG
5957 .LONGA on
5958 .MNLIST
5959 F9149D A5 48 lda ctime ; set creation time&date...
5960 F9149F 8D 0E 00 sta !0+14
5961 F914A2 8D 16 00 sta !0+22 ; ...and write time&date
5962 F914A5 A5 4A lda cdate
5963 F914A7 8D 10 00 sta !0+16
5964 F914AA 8D 18 00 sta !0+24
5965 F914AD ACC08
5966 F914AD E2 20 sep #PMFLAG
5967 .LONGA off
5968 .MNLIST
5969 F914AF A5 53 lda sec100
5970 F914B1 8D 0D 00 sta !0+13
5971 F914B4 AB plb ; restore DBR
5972 F914B5
5973 F914B5 AE 0A FC ldx CRXME ; save X mem setting
5974 F914B8 DA phx
5975 F914B9 8D 0B FC sta !CRXMEON ; enable X mem in window $012000 - $013FFF
5976 F914BC 8B phb ; save DBR
5977 F914BD A2 01 ldx #XMBANK
5978 F914BF DA phx
5979 F914C0 AB plb ; set DBR to fat table cache
5980 F914C1 A0 02 ldy #2 ; clear 2 8k-blocks
5981 F914C3 20 27 15 jsr clrxmem
5982 F914C6 A2 0A ldx #10
5983 F914C8 9B txy ; set volume label
5984 F914C9 A9 08 lda #DA_VOLUME
5985 F914CB 99 01 20 sta !XMSTART+1,y
5986 F914CE BF 53 41 00 ?10: lda >P0FAT+fcbs,x
5987 F914D2 99 00 20 sta !XMSTART,y
5988 F914D5 88 dey
Tue Jul 17 11:00:20 2018 Page 62
5989 F914D6 CA dex
5990 F914D7 10 F5 bpl ?10
5991 F914D9 ACC16
5992 F914D9 C2 20 rep #PMFLAG
5993 .LONGA on
5994 .MNLIST
5995 F914DB A5 48 lda ctime ; set creation time&date...
5996 F914DD 8D 0E 20 sta !XMSTART+14
5997 F914E0 8D 16 20 sta !XMSTART+22 ; ...and write time&date
5998 F914E3 A5 4A lda cdate
5999 F914E5 8D 10 20 sta !XMSTART+16
6000 F914E8 8D 18 20 sta !XMSTART+24
6001 F914EB ACC08
6002 F914EB E2 20 sep #PMFLAG
6003 .LONGA off
6004 .MNLIST
6005 F914ED A5 53 lda sec100
6006 F914EF 8D 0D 20 sta !XMSTART+13
6007 F914F2 AB plb ; restore DBR
6008 F914F3 FA plx ; restore X mem setting
6009 F914F4 9D 0A FC sta !CRXME,x
6010 F914F7 60 rts
6011
6012 ; new empty cluster
6013 ; in: A=cluster bank buffer
6014 F914F8 newcls:
6015
6016 ; clear 32k - buffer $80
6017 F914F8 AD CF FD lda !VIA3+VIAPRANH
6018 F914FB 29 F8 and #$F8
6019 F914FD 8D CF FD sta !VIA3+VIAPRANH ; set bank 0 (buffer $80)
6020 F91500 A9 00 lda #0
6021 F91502 INDEX16
6022 F91502 C2 10 rep #PXFLAG
6023 .LONGI on
6024 .MNLIST
6025 F91504 A2 FF 7F ldx #$7FFF
6026 F91507 9F 00 80 02 ?01: sta >$028000,x
6027 F9150B CA dex
6028 F9150C 10 F9 bpl ?01
6029 F9150E INDEX08
6030 F9150E E2 10 sep #PXFLAG
6031 .LONGI off
6032 .MNLIST
6033
6034 F91510 AE 0A FC ldx CRXME ; save X mem setting
6035 F91513 DA phx
6036 F91514 8D 0B FC sta !CRXMEON ; enable X mem in window $012000 - $013FFF
6037 F91517 8B phb ; save DBR
6038 F91518 A2 01 ldx #XMBANK
6039 F9151A DA phx
6040 F9151B AB plb ; set DBR to fat table cache
6041 F9151C A0 04 ldy #4 ; clear 4 8k-blocks
6042 ;jsr clrxmem
6043 F9151E 20 51 15 jsr clrxmem2
6044
6045 F91521 AB plb ; restore DBR
Tue Jul 17 11:00:20 2018 Page 63
6046 F91522 FA plx ; restore X mem setting
6047 F91523 9D 0A FC sta !CRXME,x
6048 F91526 60 rts
6049
6050 ; clear x-mem buffer's
6051 ; in: A=starting bank
6052 ; Y=bank count
6053 ; DBR=x-mem bank
6054 ; out: x-mem bank set to starting bank
6055 F91527 clrxmem:
6056 F91527 85 38 sta xbnk
6057 F91529 8F 28 FD 00 sta >PIA0+PIAPRA
6058 F9152D ?10: CPU16
6059 F9152D C2 30 rep #(PMFLAG.OR.PXFLAG)
6060 .LONGA on
6061 .LONGI on
6062 .MNLIST
6063 F9152F A2 00 20 ldx #XMSTART ; start of x-mem window
6064 F91532 9E 00 00 ?15: stz !0,x
6065 F91535 E8 inx
6066 F91536 E8 inx
6067 F91537 E0 00 40 cpx #XMSTOP
6068 F9153A 90 F6 bcc ?15
6069 F9153C CPU08
6070 F9153C E2 30 sep #(PMFLAG.OR.PXFLAG)
6071 .LONGA off
6072 .LONGI off
6073 .MNLIST
6074 F9153E AF 28 FD 00 lda >PIA0+PIAPRA ; update x-mem bank
6075 F91542 1A inc a
6076 F91543 8F 28 FD 00 sta >PIA0+PIAPRA
6077 F91547 88 dey
6078 F91548 D0 E3 bne ?10 ; next block
6079 F9154A A5 38 lda xbnk
6080 F9154C 8F 28 FD 00 sta >PIA0+PIAPRA
6081 F91550 60 rts
6082
6083 F91551 clrxmem2:
6084 F91551 85 38 sta xbnk
6085 F91553 8F 28 FD 00 sta >PIA0+PIAPRA
6086 F91557 ?10: INDEX16
6087 F91557 C2 10 rep #PXFLAG
6088 .LONGI on
6089 .MNLIST
6090 F91559 A2 00 20 ldx #XMSTART ; start of x-mem window
6091 F9155C A9 00 lda #0
6092 F9155E 9D 00 00 ?15: sta !0,x
6093 F91561 E8 inx
6094 F91562 1A inc a
6095 F91563 E0 00 40 cpx #XMSTOP
6096 F91566 90 F6 bcc ?15
6097 F91568 CPU08
6098 F91568 E2 30 sep #(PMFLAG.OR.PXFLAG)
6099 .LONGA off
6100 .LONGI off
6101 .MNLIST
6102 F9156A AF 28 FD 00 lda >PIA0+PIAPRA ; update x-mem bank
Tue Jul 17 11:00:20 2018 Page 64
6103 F9156E 1A inc a
6104 F9156F 8F 28 FD 00 sta >PIA0+PIAPRA
6105 F91573 88 dey
6106 F91574 D0 E1 bne ?10 ; next block
6107 F91576 A5 38 lda xbnk
6108 F91578 8F 28 FD 00 sta >PIA0+PIAPRA
6109 F9157C 60 rts
6110 F9157D
6111 ; write out root directory (xfatb=x-mem root dir. cache buffer)
6112 F9157D wrroot:
6113 F9157D A5 39 lda lunit
6114 F9157F 48 pha
6115 F91580 4B phk
6116 F91581 F4 A2 15 pea #!?10
6117 F91584 A9 05 lda #5
6118 F91586 48 pha
6119 F91587 BPRINTF
6120 F91587 02 11 cop $11
6121 .MNLIST
6122 F91589 A5 3E lda pdev
6123 F9158B 48 pha ; ata drive
6124 F9158C A9 00 lda #0
6125 F9158E 48 pha
6126 F9158F D4 20 pei (root) ; root dir. lba
6127 F91591 A0 20 ldy #32
6128 F91593 5A phy ; write 32 sector
6129 F91594
6130 ;pha ; A=0 -> x-mem buffer
6131 ;pei (xfatb)
6132 ;lda #$80 ; verify after write
6133 ;pha
6134 ;ATAWRITE
6135
6136 F91594 F4 00 00 pea #$0 ; buffer #
6137 F91597 ATADMAWR
6138 F91597 02 42 cop $42
6139 F91599 01 .DB $01
6140 .MNLIST
6141 F9159A
6142 F9159A B0 03 bcs ?05
6143 F9159C 4C 41 16 jmp wrok
6144 F9159F 4C 4C 16 ?05: jmp wrerr ; error
6145
6146 F915A2 77 72 69 74 65 ?10: .DB 'write root directory on drive <%c>...', 0
20 72 6F 6F 74
20 64 69 72 65
63 74 6F 72 79
20 6F 6E 20 64
72 69 76 65 20
3C 25 63 3E 2E
2E 2E 00
6147
6148 ; write out PBR (pointer: pbrp)
6149 F915C8 wrpbr:
6150 F915C8 A5 39 lda lunit
6151 F915CA 48 pha
6152 F915CB 4B phk
Tue Jul 17 11:00:20 2018 Page 65
6153 F915CC F4 E9 15 pea #!?10
6154 F915CF A9 05 lda #5
6155 F915D1 48 pha
6156 F915D2 BPRINTF
6157 F915D2 02 11 cop $11
6158 .MNLIST
6159 F915D4 A5 3E lda pdev
6160 F915D6 48 pha ; ata drive
6161 F915D7 A9 00 lda #0
6162 F915D9 48 pha
6163 F915DA D4 08 pei (hidsec) ; lba=partition start
6164 F915DC A9 01 lda #1
6165 F915DE 48 pha ; write 1 sector
6166 F915DF
6167 ;lda pbrp+2
6168 ;pha ; buffer pointer
6169 ;pei (pbrp)
6170 ;lda #$80 ; verify after write
6171 ;pha
6172 ;ATAWRITE
6173
6174 F915DF F4 21 00 pea #$21 ; buffer #
6175 F915E2 ATADMAWR
6176 F915E2 02 42 cop $42
6177 F915E4 01 .DB $01
6178 .MNLIST
6179 F915E5
6180 F915E5 90 5A bcc wrok
6181 F915E7 B0 63 bcs wrerr ; error
6182
6183 F915E9 77 72 69 74 65 ?10: .DB 'write PBR on drive <%c>...', 0
20 50 42 52 20
6F 6E 20 64 72
69 76 65 20 3C
25 63 3E 2E 2E
2E 00
6184
6185 ; write out MBR (pointer: tlp)
6186 F91604 wrmbr:
6187 F91604 A5 39 lda lunit
6188 F91606 48 pha
6189 F91607 4B phk
6190 F91608 F4 26 16 pea #!?10
6191 F9160B A9 05 lda #5
6192 F9160D 48 pha
6193 F9160E BPRINTF
6194 F9160E 02 11 cop $11
6195 .MNLIST
6196 F91610 A5 3E lda pdev
6197 F91612 48 pha ; ata drive
6198 F91613 A9 00 lda #0
6199 F91615 48 pha
6200 F91616 F4 00 00 pea #0 ; lba=0
6201 F91619 A9 01 lda #1
6202 F9161B 48 pha ; write 1 sector
6203 F9161C
6204 ;lda tlp+2
Tue Jul 17 11:00:20 2018 Page 66
6205 ;pha ; buffer pointer
6206 ;pei (tlp)
6207 ;lda #$80 ; verify after write
6208 ;pha
6209 ;ATAWRITE
6210 F9161C F4 20 00 pea #$20 ; buffer #
6211 F9161F ATADMAWR
6212 F9161F 02 42 cop $42
6213 F91621 01 .DB $01
6214 .MNLIST
6215 F91622
6216 F91622 90 1D bcc wrok
6217 F91624 B0 26 bcs wrerr ; error
6218
6219 F91626 77 72 69 74 65 ?10: .DB 'write MBR on drive <%c>...', 0
20 4D 42 52 20
6F 6E 20 64 72
69 76 65 20 3C
25 63 3E 2E 2E
2E 00
6220 F91641
6221 F91641 wrok:
6222 F91641 SCNPRINT
6223 F91641 02 01 cop $01
6224 .MNLIST
6225 F91643 64 6F 6E 65 2E .DB 'done.', 13, 0
0D 00
6226 F9164A 18 clc
6227 F9164B 60 rts ; CF=1 if error
6228
6229 F9164C wrerr:
6230 F9164C DA phx ; bit error
6231 F9164D 5A phy ; error code
6232 F9164E 4B phk
6233 F9164F F4 59 16 pea #!?10
6234 F91652 A9 06 lda #6
6235 F91654 48 pha
6236 F91655 BPRINTF
6237 F91655 02 11 cop $11
6238 .MNLIST
6239 F91657 38 sec
6240 F91658 60 rts
6241 F91659
6242 F91659 65 72 72 6F 72 ?10: .DB 'error %02bX (bits error: %02bX).', 13, 0
20 25 30 32 62
58 20 28 62 69
74 73 20 65 72
72 6F 72 3A 20
25 30 32 62 58
29 2E 0D 00
6243
6244 ; write out fat table (xfatb=x-mem fat cache buffer, X=fat)
6245 F9167B wrfat:
6246 F9167B A5 39 lda lunit
6247 F9167D 48 pha
6248 F9167E DA phx
6249 F9167F 4B phk
Tue Jul 17 11:00:20 2018 Page 67
6250 F91680 F4 9D 16 pea #!?10
6251 F91683 A9 06 lda #6
6252 F91685 48 pha
6253 F91686 BPRINTF
6254 F91686 02 11 cop $11
6255 .MNLIST
6256 F91688 A5 3E lda pdev
6257 F9168A 48 pha ; ata drive
6258 F9168B A9 00 lda #0
6259 F9168D 48 pha
6260 F9168E D4 2C pei (flba) ; fat table lba
6261 F91690 A4 18 ldy fatsiz
6262 F91692 5A phy ; write n sector
6263 F91693
6264 ;pha ; A=0 -> x-mem buffer
6265 ;pei (xfatb)
6266 ;lda #$80 ; verify after write
6267 ;pha
6268 ;ATAWRITE
6269
6270 F91693 F4 00 01 pea #$100 ; buffer #
6271 F91696 ATADMAWR
6272 F91696 02 42 cop $42
6273 F91698 01 .DB $01
6274 .MNLIST
6275 F91699
6276 F91699 90 A6 bcc wrok
6277 F9169B B0 AF bcs wrerr ; error
6278
6279 F9169D 77 72 69 74 65 ?10: .DB 'write FAT%bu table on drive <%c>...', 0
20 46 41 54 25
62 75 20 74 61
62 6C 65 20 6F
6E 20 64 72 69
76 65 20 3C 25
63 3E 2E 2E 2E
00
6280
6281 ; A=drive
6282 F916C1 shpart:
6283 F916C1 AA tax
6284 F916C2 A0 00 ldy #0
6285 F916C4 20 83 11 jsr prenew ; move data of partition
6286 F916C7 B0 1D bcs ?30
6287 F916C9 A5 39 lda lunit
6288 F916CB 48 pha
6289 F916CC 4B phk
6290 F916CD 24 41 bit lflag
6291 F916CF 30 0A bmi ?20 ; valid partition
6292 F916D1 F4 0A 17 pea #!?110
6293 F916D4 A9 05 lda #5
6294 F916D6 48 pha
6295 F916D7 BPRINTF
6296 F916D7 02 11 cop $11
6297 .MNLIST
6298 F916D9 80 0B bra ?30
6299 F916DB F4 E7 16 ?20: pea #!?100
Tue Jul 17 11:00:20 2018 Page 68
6300 F916DE A9 05 lda #5
6301 F916E0 48 pha
6302 F916E1 BPRINTF
6303 F916E1 02 11 cop $11
6304 .MNLIST
6305 F916E3 20 B5 17 jsr showprt
6306 F916E6 60 ?30: rts
6307
6308 F916E7 0D 70 61 72 74 ?100: .DB 13, 'partition summary on drive <%c>:', 13, 0
69 74 69 6F 6E
20 73 75 6D 6D
61 72 79 20 6F
6E 20 64 72 69
76 65 20 3C 25
63 3E 3A 0D 00
6309 F9170A 0D 6E 6F 20 76 ?110: .DB 13, 'no valid partition found on drive <%c>.', 13, 0
61 6C 69 64 20
70 61 72 74 69
74 69 6F 6E 20
66 6F 75 6E 64
20 6F 6E 20 64
72 69 76 65 20
3C 25 63 3E 2E
0D 00
6310
6311 F91734 atanewp:
6312 .PUBLIC atanewp
6313 F91734 0B phd
6314 F91735 F4 00 40 pea #P0LDT
6315 F91738 2B pld
6316 F91739 A0 00 ldy #0
6317 F9173B 20 EB 0E jsr lfdisk
6318 F9173E 2B pld
6319 F9173F 6B rtl
6320
6321 ; fixed disk pre-format routine
6322 ; in: X=logical drive
6323 ; Y=$FF if label is specified
6324 F91740 prefmt:
6325 F91740 20 83 11 jsr prenew ; move data of partition
6326 F91743 B0 1E bcs ?30 ; no valid partition
6327 F91745 A5 39 lda lunit
6328 F91747 48 pha
6329 F91748 4B phk
6330 F91749 24 41 bit lflag
6331 F9174B 30 0A bmi ?20 ; valid partition
6332 F9174D F4 8B 17 pea #!?110
6333 F91750 A9 05 lda #5
6334 F91752 48 pha
6335 F91753 BPRINTF
6336 F91753 02 11 cop $11
6337 .MNLIST
6338 F91755 80 0C bra ?30
6339 F91757 F4 64 17 ?20: pea #!?100
6340 F9175A A9 05 lda #5
6341 F9175C 48 pha
6342 F9175D BPRINTF
Tue Jul 17 11:00:20 2018 Page 69
6343 F9175D 02 11 cop $11
6344 .MNLIST
6345 F9175F 20 B5 17 jsr showprt
6346 F91762 18 clc
6347 F91763 60 ?30: rts
6348
6349 F91764 0D 66 6F 72 6D ?100: .DB 13, 'format main partition on drive <%c>:', 13, 0
61 74 20 6D 61
69 6E 20 70 61
72 74 69 74 69
6F 6E 20 6F 6E
20 64 72 69 76
65 20 3C 25 63
3E 3A 0D 00
6350 F9178B 0D 6E 6F 20 76 ?110: .DB 13, 'no valid partition found on drive <%c>.', 13, 0
61 6C 69 64 20
70 61 72 74 69
74 69 6F 6E 20
66 6F 75 6E 64
20 6F 6E 20 64
72 69 76 65 20
3C 25 63 3E 2E
0D 00
6351 F917B5
6352 ; print partition data
6353 F917B5 showprt:
6354 F917B5 D4 06 pei (maxsec+2)
6355 F917B7 D4 04 pei (maxsec)
6356 F917B9 D4 06 pei (maxsec+2)
6357 F917BB D4 04 pei (maxsec)
6358 F917BD 4B phk
6359 F917BE F4 59 18 pea #!?10
6360 F917C1 A9 0C lda #12
6361 F917C3 48 pha
6362 F917C4 BPRINTF
6363 F917C4 02 11 cop $11
6364 .MNLIST
6365 F917C6 D4 0A pei (hidsec+2)
6366 F917C8 D4 08 pei (hidsec)
6367 F917CA D4 0A pei (hidsec+2)
6368 F917CC D4 08 pei (hidsec)
6369 F917CE 4B phk
6370 F917CF F4 79 18 pea #!?20
6371 F917D2 A9 0C lda #12
6372 F917D4 48 pha
6373 F917D5 BPRINTF
6374 F917D5 02 11 cop $11
6375 .MNLIST
6376 F917D7 D4 0E pei (totsec+2)
6377 F917D9 D4 0C pei (totsec)
6378 F917DB D4 0E pei (totsec+2)
6379 F917DD D4 0C pei (totsec)
6380 F917DF 4B phk
6381 F917E0 F4 99 18 pea #!?30
6382 F917E3 A9 0C lda #12
6383 F917E5 48 pha
6384 F917E6 BPRINTF
Tue Jul 17 11:00:20 2018 Page 70
6385 F917E6 02 11 cop $11
6386 .MNLIST
6387 F917E8 D4 30 pei (remsec+2)
6388 F917EA D4 2E pei (remsec)
6389 F917EC D4 30 pei (remsec+2)
6390 F917EE D4 2E pei (remsec)
6391 F917F0 4B phk
6392 F917F1 F4 B9 18 pea #!?40
6393 F917F4 A9 0C lda #12
6394 F917F6 48 pha
6395 F917F7 BPRINTF
6396 F917F7 02 11 cop $11
6397 .MNLIST
6398 F917F9 D4 18 pei (fatsiz)
6399 F917FB D4 18 pei (fatsiz)
6400 F917FD 4B phk
6401 F917FE F4 D9 18 pea #!?50
6402 F91801 A9 08 lda #8
6403 F91803 48 pha
6404 F91804 BPRINTF
6405 F91804 02 11 cop $11
6406 .MNLIST
6407 F91806 D4 14 pei (clscnt)
6408 F91808 D4 14 pei (clscnt)
6409 F9180A 4B phk
6410 F9180B F4 FD 18 pea #!?60
6411 F9180E A9 08 lda #8
6412 F91810 48 pha
6413 F91811 BPRINTF
6414 F91811 02 11 cop $11
6415 .MNLIST
6416 F91813 A5 35 lda clssiz
6417 F91815 48 pha
6418 F91816 48 pha
6419 F91817 4B phk
6420 F91818 F4 21 19 pea #!?70
6421 F9181B A9 06 lda #6
6422 F9181D 48 pha
6423 F9181E BPRINTF
6424 F9181E 02 11 cop $11
6425 .MNLIST
6426 F91820 F4 00 00 pea #0
6427 F91823 D4 22 pei (fat1)
6428 F91825 4B phk
6429 F91826 F4 4F 19 pea #!?75
6430 F91829 A9 08 lda #8
6431 F9182B 48 pha
6432 F9182C BPRINTF
6433 F9182C 02 11 cop $11
6434 .MNLIST
6435 F9182E F4 00 00 pea #0
6436 F91831 D4 24 pei (fat2)
6437 F91833 4B phk
6438 F91834 F4 67 19 pea #!?80
6439 F91837 A9 08 lda #8
6440 F91839 48 pha
6441 F9183A BPRINTF
Tue Jul 17 11:00:20 2018 Page 71
6442 F9183A 02 11 cop $11
6443 .MNLIST
6444 F9183C F4 00 00 pea #0
6445 F9183F D4 20 pei (root)
6446 F91841 4B phk
6447 F91842 F4 7F 19 pea #!?85
6448 F91845 A9 08 lda #8
6449 F91847 48 pha
6450 F91848 BPRINTF
6451 F91848 02 11 cop $11
6452 .MNLIST
6453 F9184A F4 00 00 pea #0
6454 F9184D D4 26 pei (start)
6455 F9184F 4B phk
6456 F91850 F4 97 19 pea #!?90
6457 F91853 A9 08 lda #8
6458 F91855 48 pha
6459 F91856 BPRINTF
6460 F91856 02 11 cop $11
6461 .MNLIST
6462 F91858 60 rts
6463
6464 F91859 74 6F 74 61 6C ?10: .DB 'total sector(s) : %08X %, +10u', 13, 0
20 73 65 63 74
6F 72 28 73 29
20 3A 20 25 30
38 58 20 25 2C
20 2B 31 30 75
0D 00
6465 F91879 70 61 72 74 69 ?20: .DB 'partition start : %08X %, +10u', 13, 0
74 69 6F 6E 20
73 74 61 72 74
20 3A 20 25 30
38 58 20 25 2C
20 2B 31 30 75
0D 00
6466 F91899 70 61 72 74 69 ?30: .DB 'partition size : %08X %, +10u', 13, 0
74 69 6F 6E 20
73 69 7A 65 20
20 3A 20 25 30
38 58 20 25 2C
20 2B 31 30 75
0D 00
6467 F918B9 75 6E 75 73 65 ?40: .DB 'unused sector(s): %08X %, +10u', 13, 0
64 20 73 65 63
74 6F 72 28 73
29 3A 20 25 30
38 58 20 25 2C
20 2B 31 30 75
0D 00
6468 F918D9 66 61 74 20 74 ?50: .DB 'fat table size : % 8.4hX %, +10hu', 13, 0
61 62 6C 65 20
73 69 7A 65 20
20 3A 20 25 20
38 2E 34 68 58
20 25 2C 20 2B
31 30 68 75 0D
Tue Jul 17 11:00:20 2018 Page 72
00
6469 F918FD 63 6C 75 73 74 ?60: .DB 'clusters count : % 8.4hX %, +10hu', 13, 0
65 72 73 20 63
6F 75 6E 74 20
20 3A 20 25 20
38 2E 34 68 58
20 25 2C 20 2B
31 30 68 75 0D
00
6470 F91921 63 6C 75 73 74 ?70: .DB 'cluster size : % 8.4bX %, +10bu sector(s)', 13, 0
65 72 20 73 69
7A 65 20 20 20
20 3A 20 25 20
38 2E 34 62 58
20 25 2C 20 2B
31 30 62 75 20
73 65 63 74 6F
72 28 73 29 0D
00
6471 F9194F 66 61 74 31 20 ?75: .DB 'fat1 table start: %08X', 13, 0
74 61 62 6C 65
20 73 74 61 72
74 3A 20 25 30
38 58 0D 00
6472 F91967 66 61 74 32 20 ?80: .DB 'fat2 table start: %08X', 13, 0
74 61 62 6C 65
20 73 74 61 72
74 3A 20 25 30
38 58 0D 00
6473 F9197F 72 6F 6F 74 20 ?85: .DB 'root dir. start : %08X', 13, 0
64 69 72 2E 20
73 74 61 72 74
20 3A 20 25 30
38 58 0D 00
6474 F91997 63 6C 75 73 74 ?90: .DB 'cluster #2 start: %08X', 13, 0
65 72 20 23 32
20 73 74 61 72
74 3A 20 25 30
38 58 0D 00
6475
6476 ; compute a new disk partition
6477 F919AF newprt:
6478 F919AF A5 3E lda pdev ; phisycal drive
6479 F919B1 0A asl a
6480 F919B2 0A asl a
6481 F919B3 AA tax
6482 F919B4 A5 00 lda defhsec
6483 F919B6 85 08 sta hidsec ; hidden sector's
6484 F919B8 64 09 stz hidsec+1
6485 F919BA ACC16
6486 F919BA C2 20 rep #PMFLAG
6487 .LONGA on
6488 .MNLIST
6489 F919BC 64 0A stz hidsec+2
6490 F919BE BD 12 00 lda !atasec,x ; max. disk usable sector's
6491 F919C1 85 04 sta maxsec
6492 F919C3 BD 14 00 lda !atasec+2,x
Tue Jul 17 11:00:20 2018 Page 73
6493 F919C6 85 06 sta maxsec+2
6494 F919C8 A9 01 00 lda #1
6495 F919CB 85 16 sta rsvsec ; reserved sector for PBR
6496 F919CD A9 20 00 lda #32
6497 F919D0 85 1A sta rootsiz ; root directory sector's
6498 F919D2 A5 08 lda hidsec
6499 F919D4 1A inc a ; leave one sector at partition end
6500 F919D5 85 2E sta remsec
6501 F919D7 38 sec
6502 F919D8 A5 04 lda maxsec
6503 F919DA E5 2E sbc remsec
6504 F919DC 85 0C sta totsec ; total partition sector's
6505 F919DE A5 06 lda maxsec+2
6506 F919E0 E5 0A sbc hidsec+2 ; this is null
6507 F919E2 85 0E sta totsec+2
6508 F919E4 18 clc
6509 F919E5 A5 08 lda hidsec ; compute total reserved sector's
6510 F919E7 65 16 adc rsvsec
6511 F919E9 65 1A adc rootsiz
6512 F919EB 85 12 sta totrsv
6513 F919ED A5 06 lda maxsec+2
6514 F919EF C9 40 00 cmp #$0040 ; disk size > 2gb?
6515 F919F2 90 1F bcc ?05 ; no
6516 F919F4 A2 40 ldx #$40 ; yes, so...
6517 F919F6 86 35 stx clssiz ; ...cluser size=64 sector's...
6518 F919F8 A2 06 ldx #6
6519 F919FA 86 36 stx clsshf
6520 F919FC A9 00 01 lda #$0100 ; ...and fat size=max (256 sector's)...
6521 F919FF 85 18 sta fatsiz
6522 F91A01 A9 F4 FF lda #MAXF16-1
6523 F91A04 85 14 sta clscnt ; ...and cluster's count=max ($FFF4)...
6524 F91A06 A9 30 FF lda #$FF30 ; ...and set partition totsec=$3FFF30
6525 F91A09 85 0C sta totsec
6526 F91A0B A9 3F 00 lda #$003F
6527 F91A0E 85 0E sta totsec+2
6528 F91A10 4C A3 1A jmp ?50 ; done for disk > 2Gb
6529 F91A13 ?05: CPU08 ; now disk <= 2Gb
6530 F91A13 E2 30 sep #(PMFLAG.OR.PXFLAG)
6531 .LONGA off
6532 .LONGI off
6533 .MNLIST
6534 F91A15 A5 06 lda maxsec+2
6535 F91A17 A2 00 ldx #0
6536 F91A19 DF 61 1C F9 ?10: cmp >CLSSIZE,x
6537 F91A1D 90 06 bcc ?15 ; X=shift
6538 F91A1F E8 inx
6539 F91A20 E0 07 cpx #7
6540 F91A22 90 F5 bcc ?10
6541 F91A24 CA dex
6542 F91A25 BF 61 1C F9 ?15: lda >CLSSIZE,x
6543 F91A29 85 35 sta clssiz ; cluster size
6544 F91A2B 86 36 stx clsshf ; cluster shift
6545 F91A2D CPU16
6546 F91A2D C2 30 rep #(PMFLAG.OR.PXFLAG)
6547 .LONGA on
6548 .LONGI on
6549 .MNLIST
Tue Jul 17 11:00:20 2018 Page 74
6550 F91A2F 38 sec ; compute approximate fat size
6551 F91A30 A5 04 lda maxsec
6552 F91A32 E5 12 sbc totrsv
6553 F91A34 85 10 sta maxcnt
6554 F91A36 A5 06 lda maxsec+2
6555 F91A38 E9 00 00 sbc #0
6556 F91A3B 9B txy
6557 F91A3C F0 06 beq ?25 ; no shift
6558 F91A3E 4A ?20: lsr a ; divide by cluster size
6559 F91A3F 66 10 ror maxcnt
6560 F91A41 CA dex
6561 F91A42 D0 FA bne ?20
6562 F91A44 AA ?25: tax ; now C must be cleared
6563 F91A45 D0 59 bne ?48 ; error... shoul'nt happen
6564 F91A47 CPU08
6565 F91A47 E2 30 sep #(PMFLAG.OR.PXFLAG)
6566 .LONGA off
6567 .LONGI off
6568 .MNLIST
6569 F91A49 A5 11 lda maxcnt+1 ; high byte is fat size!
6570 F91A4B 1A inc a
6571 F91A4C D0 01 bne ?30
6572 F91A4E E8 inx ; fat size=256
6573 F91A4F 85 18 ?30: sta fatsiz
6574 F91A51 86 19 stx fatsiz+1
6575 F91A53 ACC16CLC
6576 F91A53 C2 21 rep #(PMFLAG.OR.PCFLAG)
6577 .LONGA on
6578 .MNLIST
6579 F91A55 A5 16 ?35: lda rsvsec ; now compute clusters count
6580 F91A57 65 18 adc fatsiz
6581 F91A59 65 18 adc fatsiz
6582 F91A5B 65 1A adc rootsiz
6583 F91A5D 85 14 sta clscnt
6584 F91A5F 38 sec
6585 F91A60 A5 0C lda totsec
6586 F91A62 E5 14 sbc clscnt
6587 F91A64 85 14 sta clscnt
6588 F91A66 A5 0E lda totsec+2
6589 F91A68 E9 00 00 sbc #0
6590 F91A6B A6 36 ldx clsshf
6591 F91A6D INDEX16
6592 F91A6D C2 10 rep #PXFLAG
6593 .LONGI on
6594 .MNLIST
6595 F91A6F F0 06 beq ?45
6596 F91A71 4A ?40: lsr a
6597 F91A72 66 14 ror clscnt
6598 F91A74 CA dex
6599 F91A75 D0 FA bne ?40
6600 F91A77 AA ?45: tax ; now C must be cleared
6601 F91A78 D0 26 bne ?48 ; error... shoul'nt happen
6602 F91A7A INDEX08
6603 F91A7A E2 10 sep #PXFLAG
6604 .LONGI off
6605 .MNLIST
6606 F91A7C A5 14 lda clscnt
Tue Jul 17 11:00:20 2018 Page 75
6607 F91A7E C9 F5 FF cmp #MAXF16
6608 F91A81 90 04 bcc ?46
6609 F91A83 A9 F4 FF lda #MAXF16-1
6610 F91A86 18 clc
6611 F91A87 1A ?46: inc a ; add fake cluster 0&1
6612 F91A88 1A inc a
6613 F91A89 69 FF 00 adc #$00FF ; round to fit sector
6614 F91A8C 29 00 FF and #$FF00
6615 F91A8F EB xba
6616 F91A90 90 03 bcc ?47
6617 F91A92 69 00 01 adc #$0100
6618 F91A95 C5 18 ?47: cmp fatsiz
6619 F91A97 F0 0A beq ?50 ; ok, fat size is right
6620 F91A99 90 08 bcc ?50 ; ok, fat size is right
6621 F91A9B E6 18 inc fatsiz ; increment fat size
6622 F91A9D 18 clc
6623 F91A9E 80 B5 bra ?35 ; try again
6624 F91AA0 38 ?48: sec
6625 F91AA1 80 4D bra ?55
6626 F91AA3 ?50: INDEX08
6627 F91AA3 E2 10 sep #PXFLAG
6628 .LONGI off
6629 .MNLIST
6630 F91AA5 18 clc
6631 F91AA6 A5 12 lda totrsv
6632 F91AA8 65 18 adc fatsiz
6633 F91AAA 65 18 adc fatsiz
6634 F91AAC 85 12 sta totrsv
6635 F91AAE A5 14 lda clscnt
6636 F91AB0 85 2E sta remsec
6637 F91AB2 1A inc a
6638 F91AB3 1A inc a
6639 F91AB4 85 28 sta maxcls
6640 F91AB6 A9 00 00 lda #0
6641 F91AB9 A6 36 ldx clsshf
6642 F91ABB F0 06 beq ?52
6643 F91ABD 06 2E ?51: asl remsec
6644 F91ABF 2A rol a
6645 F91AC0 CA dex
6646 F91AC1 D0 FA bne ?51
6647 F91AC3 85 30 ?52: sta remsec+2
6648 F91AC5 A5 2E lda remsec
6649 F91AC7 18 clc
6650 F91AC8 65 12 adc totrsv
6651 F91ACA 85 2E sta remsec
6652 F91ACC 90 02 bcc ?53
6653 F91ACE E6 30 inc remsec+2
6654 F91AD0 A5 04 ?53: lda maxsec
6655 F91AD2 38 sec
6656 F91AD3 E5 2E sbc remsec
6657 F91AD5 85 2E sta remsec
6658 F91AD7 A5 06 lda maxsec+2
6659 F91AD9 E5 30 sbc remsec+2
6660 F91ADB 85 30 sta remsec+2
6661 F91ADD 18 clc
6662 F91ADE A5 08 lda hidsec
6663 F91AE0 65 16 adc rsvsec
Tue Jul 17 11:00:20 2018 Page 76
6664 F91AE2 85 22 sta fat1
6665 F91AE4 65 18 adc fatsiz
6666 F91AE6 85 24 sta fat2
6667 F91AE8 65 18 adc fatsiz
6668 F91AEA 85 20 sta root
6669 F91AEC 65 1A adc rootsiz
6670 F91AEE 85 26 sta start
6671 F91AF0 ?55: CPU08
6672 F91AF0 E2 30 sep #(PMFLAG.OR.PXFLAG)
6673 .LONGA off
6674 .LONGI off
6675 .MNLIST
6676 F91AF2 60 rts
6677
6678 F91AF3 askfmt:
6679 F91AF3 SCNPRINT
6680 F91AF3 02 01 cop $01
6681 .MNLIST
6682 F91AF5 63 6F 6E 74 69 .DB 'continue with the quick format? <Y/N>?', 0
6E 75 65 20 77
69 74 68 20 74
68 65 20 71 75
69 63 6B 20 66
6F 72 6D 61 74
3F 20 3C 59 2F
4E 3E 3F 00
6683 F91B1C 20 90 1B ?10: jsr getkey
6684 F91B1F B0 FB bcs ?10 ; control key
6685 F91B21 AA tax
6686 F91B22 EB xba
6687 F91B23 A8 tay
6688 F91B24 D0 F6 bne ?10 ; CTL, ALT, SHIFT
6689 F91B26 E0 79 cpx #'y'
6690 F91B28 18 clc
6691 F91B29 F0 04 beq ?20
6692 F91B2B E0 6E cpx #'n'
6693 F91B2D D0 ED bne ?10
6694 F91B2F 60 ?20: rts
6695
6696 ; return CF=0 if YES, CF=1 if NO
6697 F91B30 askcont:
6698 F91B30 SCNPRINT
6699 F91B30 02 01 cop $01
6700 .MNLIST
6701 F91B32 57 41 52 4E 49 .DB 'WARNING! Proceeding, all data on the disk will be erased. Continue <Y/N>?', 0
4E 47 21 20 50
72 6F 63 65 65
64 69 6E 67 2C
20 61 6C 6C 20
64 61 74 61 20
6F 6E 20 74 68
65 20 64 69 73
6B 20 77 69 6C
6C 20 62 65 20
65 72 61 73 65
64 2E 20 43 6F
6E 74 69 6E 75
Tue Jul 17 11:00:20 2018 Page 77
65 20 3C 59 2F
4E 3E 3F 00
6702 F91B7C 20 90 1B ?10: jsr getkey
6703 F91B7F B0 FB bcs ?10 ; control key
6704 F91B81 AA tax
6705 F91B82 EB xba
6706 F91B83 A8 tay
6707 F91B84 D0 F6 bne ?10 ; CTL, ALT, SHIFT
6708 F91B86 E0 79 cpx #'y'
6709 F91B88 18 clc
6710 F91B89 F0 04 beq ?20
6711 F91B8B E0 6E cpx #'n'
6712 F91B8D D0 ED bne ?10
6713 F91B8F 60 ?20: rts
6714 F91B90
6715 ; wait a pressed key
6716 F91B90 getkey:
6717 F91B90 ?02: KBGETIN ; system call - get key
6718 F91B90 02 17 cop $17
6719 .MNLIST
6720 F91B92 C9 00 cmp #0
6721 F91B94 F0 FA beq ?02 ; loop -- wait pressed key
6722 F91B96 AA tax ; X=key code
6723 F91B97 EB xba
6724 F91B98 18 clc
6725 F91B99 A8 tay ; Y=control key flag
6726 F91B9A 10 01 bpl ?04
6727 F91B9C 38 sec ; flag control key
6728 F91B9D AF 64 01 00 ?04: lda >DP01ADDR+KbdFlag
6729 F91BA1 EB xba ; B = flag ALT, CTL, SHIFT
6730 F91BA2 18 clc
6731 F91BA3 8A txa ; key code
6732 F91BA4 60 rts
6733
6734 ;---------------------------------------------------------------------------
6735 ; compact time function's
6736 ;---------------------------------------------------------------------------
6737
6738 ; get compact time for file timestamp
6739 ; return cpu in 16 bit mode
6740 ; C=low compact time, X=high compact time
6741 F91BA5 gctime16:
6742 F91BA5 CPU08
6743 F91BA5 E2 30 sep #(PMFLAG.OR.PXFLAG)
6744 .LONGA off
6745 .LONGI off
6746 .MNLIST
6747 F91BA7 0B phd
6748 F91BA8 F4 00 40 pea #P0LDT
6749 F91BAB 2B pld ; set dp page
6750 F91BAC 20 08 1C jsr getrtc
6751 F91BAF 20 CA 1B jsr cpctime
6752 F91BB2 CPU16
6753 F91BB2 C2 30 rep #(PMFLAG.OR.PXFLAG)
6754 .LONGA on
6755 .LONGI on
6756 .MNLIST
Tue Jul 17 11:00:20 2018 Page 78
6757 F91BB4 A5 48 lda ctime
6758 F91BB6 A6 4A ldx cdate
6759 F91BB8 2B pld
6760 F91BB9 60 rts
6761 F91BBA
6762 .LONGA off
6763 .LONGI off
6764
6765 ; get compact time for file timestamp
6766 F91BBA getctime:
6767 F91BBA 0B phd
6768 F91BBB F4 00 42 pea #P0OS
6769 F91BBE 2B pld ; set dp page
6770 F91BBF 20 08 1C jsr getrtc
6771 F91BC2 20 CA 1B jsr cpctime
6772 F91BC5 2B pld
6773 F91BC6 60 rts
6774
6775 ; compact time
6776 F91BC7 gettime:
6777 F91BC7 20 08 1C jsr getrtc
6778 F91BCA cpctime:
6779 F91BCA 38 sec
6780 F91BCB A5 47 lda rtcyear ; subctract 1980
6781 F91BCD E9 50 sbc #$50 ; without century...
6782 F91BCF 18 clc ; ...we assume century=20
6783 F91BD0 69 64 adc #$64 ; add 100
6784 F91BD2 EB xba ; B = 0.127 (till 2101)
6785 F91BD3 A5 46 lda rtcmonth ; shift month
6786 F91BD5 0A asl a
6787 F91BD6 0A asl a
6788 F91BD7 0A asl a
6789 F91BD8 0A asl a
6790 F91BD9 ACC16
6791 F91BD9 C2 20 rep #PMFLAG
6792 .LONGA on
6793 .MNLIST
6794 F91BDB 0A asl a ; shift year+month
6795 F91BDC ACC08
6796 F91BDC E2 20 sep #PMFLAG
6797 .LONGA off
6798 .MNLIST
6799 F91BDE 05 45 ora rtcday
6800 F91BE0 85 4A sta cdate ; compact date
6801 F91BE2 EB xba
6802 F91BE3 85 4B sta cdate+1
6803 F91BE5 A5 42 lda rtcsec
6804 F91BE7 4A lsr a
6805 F91BE8 85 48 sta ctime
6806 F91BEA 64 53 stz sec100
6807 F91BEC 90 04 bcc ?10
6808 F91BEE A9 64 lda #100
6809 F91BF0 85 53 sta sec100 ; millisecond stamp
6810 F91BF2 A5 44 ?10: lda rtchour
6811 F91BF4 EB xba
6812 F91BF5 A5 43 lda rtcmin
6813 F91BF7 0A asl a
Tue Jul 17 11:00:20 2018 Page 79
6814 F91BF8 0A asl a
6815 F91BF9 ACC16
6816 F91BF9 C2 20 rep #PMFLAG
6817 .LONGA on
6818 .MNLIST
6819 F91BFB 0A asl a
6820 F91BFC 0A asl a
6821 F91BFD 0A asl a
6822 F91BFE ACC08
6823 F91BFE E2 20 sep #PMFLAG
6824 .LONGA off
6825 .MNLIST
6826 F91C00 05 48 ora ctime ; compact time
6827 F91C02 85 48 sta ctime
6828 F91C04 EB xba
6829 F91C05 85 49 sta ctime+1
6830 F91C07 60 rts
6831 F91C08
6832 ; get real time clock
6833 F91C08 getrtc:
6834 F91C08 8B phb
6835 F91C09 A9 00 lda #0
6836 F91C0B 48 pha
6837 F91C0C AB plb
6838 F91C0D 08 php
6839 F91C0E 78 sei
6840 F91C0F A2 0A ldx #RTCCTRLA ; set bank 1
6841 F91C11 8E 4C FD stx RTCALE
6842 F91C14 A9 10 lda #$10
6843 F91C16 0C 4D FD tsb RTCDATA
6844 F91C19 A2 4A ldx #RTCEXTCTRLA ; check INCR bit 6
6845 F91C1B 8E 4C FD stx RTCALE
6846 F91C1E 2C 4D FD ?02: bit RTCDATA
6847 F91C21 70 FB bvs ?02
6848 F91C23 A2 00 ldx #0 ; seconds
6849 F91C25 8E 4C FD stx RTCALE
6850 F91C28 AD 4D FD lda RTCDATA
6851 F91C2B 85 42 sta rtcsec
6852 F91C2D E8 inx
6853 F91C2E E8 inx
6854 F91C2F 8E 4C FD stx RTCALE ; minutes
6855 F91C32 AD 4D FD lda RTCDATA
6856 F91C35 85 43 sta rtcmin
6857 F91C37 E8 inx
6858 F91C38 E8 inx
6859 F91C39 8E 4C FD stx RTCALE ; hours
6860 F91C3C AD 4D FD lda RTCDATA
6861 F91C3F 85 44 sta rtchour
6862 F91C41 E8 inx
6863 F91C42 E8 inx
6864 F91C43 E8 inx
6865 F91C44 8E 4C FD stx RTCALE ; day
6866 F91C47 AD 4D FD lda RTCDATA
6867 F91C4A 85 45 sta rtcday
6868 F91C4C E8 inx
6869 F91C4D 8E 4C FD stx RTCALE ; month
6870 F91C50 AD 4D FD lda RTCDATA
Tue Jul 17 11:00:20 2018 Page 80
6871 F91C53 85 46 sta rtcmonth
6872 F91C55 E8 inx
6873 F91C56 8E 4C FD stx RTCALE ; year
6874 F91C59 AD 4D FD lda RTCDATA
6875 F91C5C 85 47 sta rtcyear
6876 F91C5E 28 plp
6877 F91C5F AB plb
6878 F91C60 60 rts
6879
6880 ;---------------------------------------------------------------------------
6881 ; tables
6882 ;---------------------------------------------------------------------------
6883 F91C61
6884 ; sector's per cluster table
6885 F91C61 CLSSIZE:
6886 F91C61 01 02 04 08 10 .DB $01, $02, $04, $08, $10, $20, $40
20 40
6887
6888 000007 CLSCNT .EQU $-CLSSIZE
6889
6890 ; sector's per cluster shift table
6891 F91C68 CLSSHIFT:
6892 F91C68 00 01 02 03 04 .DB $00, $01, $02, $03, $04, $05, $06
05 06
6893 F91C6F
6894 ; costant's for fat formatted floppy disk (D.D. & H.D. format)
6895 ; root dir. entry count
6896 F91C6F FDROOT:
6897 F91C6F 7000 E000 .DW $0070, $00E0
6898 ; total sector's
6899 F91C73 FDSEC:
6900 F91C73 A005 400B .DW $05A0, $0B40
6901 ; fat size
6902 F91C77 FDFAT:
6903 F91C77 0300 0900 .DW $0003, $0009
6904 ; sector's per track
6905 F91C7B FDSPT:
6906 F91C7B 0900 1200 .DW 9, 18
6907 ; sector per cluster
6908 F91C7F FDCLS:
6909 F91C7F 02 01 .DB 2, 1
6910 ; shift value
6911 F91C81 FDSHF:
6912 F91C81 01 00 .DB 1, 0
6913 ; media value
6914 F91C83 FDMEDIA:
6915 F91C83 F9 F0 .DB $F9, $F0
6916
6917 ; ata device PBR buffer pointer
6918 F91C85 PBRPTR:
6919 F91C85 008C 008E .DW .LOW16.PBR0ATA, .LOW16.PBR1ATA
6920 F91C89 PBRPTR2:
6921 F91C89 01 01 .DB .SEG.PBR0ATA, .SEG.PBR1ATA
6922
6923 ; standard label
6924 F91C8B PBRLBL:
6925 F91C8B 44 4F 53 20 44 .DB 'DOS DISK '
Tue Jul 17 11:00:20 2018 Page 81
49 53 4B 20 20
20
6926
6927 F91C96 NOLBL:
6928 F91C96 4E 4F 20 4E 41 .DB 'NO NAME '
4D 45 20 20 20
20
6929
6930 ; standard fat12 system name
6931 F91CA1 F12NAM:
6932 F91CA1 46 41 54 31 32 .DB 'FAT12 '
20 20 20
6933
6934 ; standard fat16 system name
6935 F91CA9 F16NAM:
6936 F91CA9 46 41 54 31 36 .DB 'FAT16 '
20 20 20
6937
6938 ; boot sector header DD fat12
6939 F91CB1 F12HDD:
6940 F91CB1 EB 34 90 .DB $EB, $34, $90
6941 F91CB4 OEMNAM:
6942 F91CB4 49 42 4D 20 20 .DB 'IBM 3.3'
33 2E 33
6943 F91CBC 00 02 02 01 00 .DB $00, $02, $02, $01, $00, $02
02
6944 F91CC2 70 00 A0 05 F9 .DB $70, $00, $A0, $05, $F9, $03, $00
03 00
6945 F91CC9 12 00 02 00 .DB $12, $00, $02, $00
6946 F91CCD
6947 00001C F12HSIZ .EQU ($ - F12HDD)
6948
6949 ; boot sector header HD fat12
6950 F91CCD F12HHD:
6951 F91CCD EB 34 90 .DB $EB, $34, $90
6952 F91CD0 49 42 4D 20 20 .DB 'IBM 3.3'
33 2E 33
6953 F91CD8 00 02 01 01 00 .DB $00, $02, $01, $01, $00, $02
02
6954 F91CDE E0 00 40 0B F0 .DB $E0, $00, $40, $0B, $F0, $09, $00
09 00
6955 F91CE5 12 00 02 00 .DB $12, $00, $02, $00
Lines Assembled : 6423 Errors : 0