Subversion Repositories MB01 Project

Rev

Blame | Last modification | View Log | Download | RSS feed

  Tue Jul 17 11:00:19 2018                                                                                               Page    1







          2500 A.D. 65816 Macro Assembler #26960 - Version 5.02g
          -----------------------------------------------------

                       Input  Filename : src\F9\fscbm.asm
                       Output Filename : obj\F9\fscbm.obj
                       Listing Has Been Relocated                               


 2601                           .LIST           on
 2602                           
 2603  F8FFB1                           .INCLUDE inc\dirp00.inc
 2604                           ;----------------------------------------------------------
 2605                           ; DIRP00.ASM
 2606                           ; PROGETTO: B1601
 2607                           ;
 2608                           ; Variabili in Direct Page $00
 2609                           ;----------------------------------------------------------
 2610                           
 2611                           ; sezione COMMON -- questo permette di includere il file in piu' file
 2612                           
 2613                           .LIST on
 2614                           
 2615                           DIRP00: .SECTION page0, ref_only, common        ;Direct-Page 00
 2616                           
 2617  000000                           .ABSOLUTE               ;; inizia sempre da $00
 2618  000000                           .ORG            0x00
 2619  000000                           
 2620  000000  0000             JiffyClk        .DW                     ; contatore 10ms 32 bit
 2621  000002  0000                             .DW
 2622  000004                   SysTmr          .DS     SYSTMRCNT       ; system timer 0 (10ms)
 2623  000008                   SysTMF          .DS     SYSTMRCNT       ; flag timer (80 -> start)
 2624  00000C  00               Bnk0Flag        .DB                     ; <7>: flag test RAM banco 0 ok
 2625                                                                   ; <6>: flag warm reset
 2626  00000D  00               RTCFlag         .DB
 2627                           
 2628  00000E                   diskstat        .DS     2       ; flag device on ata bus #0 & #1
 2629                                                           ; <7>: device ready
 2630                                                           ; <6>: compact flash device (C.F.)
 2631                                                           ; <5>: device identification ok
 2632                                                           ; <4>: MBR loaded
 2633                                                           ; <3>: valid signature in MBR
 2634                                                           ; <2>: first partition found&active
 2635                                                           ; <1>:
 2636                                                           ; <0>: valid partition flag
 2637                           
 2638                                                           ; <7>: device ready
 2639                                                           ; <6>: USB device
 2640                                                           ; <5>: compact flash device (C.F.)
 2641                                                           ; <4>: device identification ok
 2642                                                           ; <3>: MBR loaded
 2643                                                           ; <2>: first partition found&active
 2644                                                           ; <1>: always 1
 2645                                                           ; <0>: valid partition flag
 2646  000010                                                   
  Tue Jul 17 11:00:19 2018                                                                                               Page    2




 2647                           
 2648          00000E           atadev          .EQU    diskstat
 2649                           
 2650  000010                   usbdev          .DS     2       ; flag flash disk on usb bus #0
 2651                                                           ; <7>: device plugged and ready
 2652                                                           ; <6>: always 1 
 2653                                                           ; <5>: device identification ok
 2654                                                           ; <4>: MBR loaded
 2655                                                           ; <3>: valid signature in MBR
 2656                                                           ; <2>: first partition found&active
 2657                                                           ; <1>:
 2658                                                           ; <0>: valid partition flag
 2659                           
 2660  000012                   diskmax         .DS     16      ; disk max. sector's
 2661          000012           atasec          .EQU    diskmax
 2662          00001A           usbsec          .EQU    diskmax+8
 2663                           
 2664                           
 2665  000022                   atambr          .DS     8       ; data for first partition found in mbr
 2666                                                           ; first 3 bytes for start sector of partition
 2667                                                           ; last byte for partition type
 2668  00002A                   usbmbr          .DS     8
 2669                           
 2670  000032                   ataprt          .DS     8       ; total sec's of first partition
 2671  00003A                   usbprt          .DS     8       ; total sec's of first partition
 2672                           
 2673                           
 2674  000042  00               usb0ch          .DB     ; usb0 (ch375/ch376) flag
 2675                                                   ; <7>: module on
 2676                                                   ; <6>: ch376 flag
 2677                                                   ; <5:0>: chip version
 2678                           
 2679  000043  00               usb0st          .DB     ; usb0 status
 2680                                                   ; <7>: usb0 host mode ok
 2681                                                   ; <6>: flash disk attached flag
 2682                                                   ; <5>: usb device attached
 2683                           
 2684  000044  00               fdcdrv          .DB             ; phisycal drive status (drive #0)
 2685                                                           ; <7>: disk format established in bit 0&1 
 2686                                                           ; <6>: double step seek done
 2687                                                           ; <5>: trust format bit's (set after ok r/w)
 2688                                                           ; <4>: write protect bit (if disk in drive)
 2689                                                           ; <3>: don't care
 2690                                                           ; <2>: don't care                               
 2691                                                           ; <1>: HD disk if set else DD disk
 2692                                                           ; <0>: CBM format if set else IBM format
 2693                           
 2694  000045  00               vdrive          .DB             ; virtual drive status (ram disk, drive #1)
 2695                                                           ; <7>: disk format established in bit 0&1 
 2696                                                           ; <6>: change disk simulation (after format)
 2697                                                           ; <5>: don't care
 2698                                                           ; <4>: write protect bit (under sw control)
 2699                                                           ; <3>: don't care
 2700                                                           ; <2>: don't care                               
 2701                                                           ; <1>: HD disk if set else DD disk
 2702                                                           ; <0>: CBM format if set else IBM format
 2703                           
  Tue Jul 17 11:00:19 2018                                                                                               Page    3




 2704  000046  00               fdcctl          .DB             ; fdc controller status
 2705                                                           ; <7>: drive is attached
 2706                                                           ; <6>: drive need recalibration (restore)
 2707                                                           ; <5>: FDC controller ok
 2708                                                           ; <4>: motor on
 2709                                                           ; <3>: dma is active
 2710                                                           ; <2>: dma chip ok (post routine)
 2711                                                           ; <1>: clock rate (1=HD,0=DD)
 2712                                                           ; <0>: disk ready
 2713                           
 2714  000047  00               fdctrk          .DB             ; fd: current seek track
 2715  000048  00               fdcerr          .DB             ; fd: last error code
 2716  000049  00               ataerr          .DB             ; ata: last error code
 2717  00004A  00               ataxer          .DB             ; ata: last extended error code
 2718                           
 2719  00004B  00               CtrlBrk         .DB             ; flag CTRL+BREAK (NMI)
 2720                           
 2721  00004C  0000             MemTop          .DW             ; top memoria RAM
 2722  00004E  00                               .DB             ; banco top mem
 2723                           
 2724  00004F  00               DflTxtIn        .DB             ; device di default text input 
 2725  000050  00               DflTxtOut       .DB             ; device di default text output
 2726                           
 2727  000051                   COPPtr          LP              ; long pointer for COP decoding
 2728  000054  00               COPIdx          .DB             ; COP signature/index
 2729                           
 2730  000055  00               BiosEnt         .DB             ; flag accesso a bios setup
 2731                           
 2732                           ; variabili utilizzate da ACIA
 2733  000056                   spwrk           .DS     $30
 2734                           
 2735                           ; bios mem
 2736  000086  0000             nsize           .DW     ; dimensione blocco da allocare
 2737                           ;bsize          .DW     ; dimensione vera blocco free
 2738  000088  0000             splitsz         .DW     ; dimensione blocco splittato
 2739  00008A  0000             bfree           .DW     ; puntatore blocco free
 2740  00008C  0000             hdrptr          .DW     ; puntatore header heap
 2741                           
 2742  00008E  0000             pbrklv          .DW     ; current break level of current process
 2743  000090  0000             pbrkmin         .DW     ; minimum breal level of current process
 2744  000092  0000             pbrkmax         .DW     ; maximum breal level of current process
 2745  000094                           
 2746                           ; bios temp. work area
 2747  000094                   bwrktmp         .DS     $28
 2748                           
 2749  0000BC  00               coptmp          .DB     ; temp. used while cop
 2750                           
 2751  0000BD  00               tstser          .DB     ; check ser/usb test board post
 2752                                                   ; <7>: VIA2 ok
 2753                                                   ; <6>: PICRAM ok
 2754                                                   ; <1>: UART 16C550 ok
 2755                                                   ; <0>: R65C51 ok
 2756                           
 2757                           
 2758                           ;crc16          .DW
 2759                           
 2760  0000BD                           .RELATIVE
  Tue Jul 17 11:00:19 2018                                                                                               Page    4




 2761                           
 2762                                   .ENDS
 2763                           
 2764          [01]             .IFDEF          _ACIA_INC_
 2765                                   .INCLUDE INC\SP.INC
 2766          [00]             .ENDIF
 2767                           
 2771                           .LIST on
 2772                           
 2773  F8FFB1                           .INCLUDE inc\dpcbmfs.inc
 2774                           ;; cbm-fs
 2775                           
 2776          001000           VIECMAX         .EQU    $1000
 2777                           
 2778          000005           mxfils          .EQU    5       ; max # filenames in cmd string
 2779          000060           cmdlen          .EQU    96      ; length of command buffer (+ terminator #0)
 2780          000061           fntlen          .EQU    97      ; length of canonical file name table 
 2781          00001B           nbsiz           .EQU    27      ; nambuf text size
 2782          000018           dirlen          .EQU    24      ; directory length used
 2783          000008           maxfd           .EQU    8       ; max # file descriptors
 2784          00000A           intfd           .EQU    maxfd+2 ; internal # file descriptors
 2785          00000F           mxchnls         .EQU    15      ; max # data channels
 2786          000008           irdfd           .EQU    maxfd   ; internal fd for read file
 2787          000009           iwrfd           .EQU    maxfd+1 ; internal fd for write file
 2788                           
 2789          000010           bindx           .EQU    16      ; bam offset index
 2790          000006           bamsiz          .EQU    6       ; # bytes/track in bam
 2791          000028           numsec          .EQU    40      ; number of logical sectors (blocks)
 2792          00000A           phisec          .EQU    10      ; number of phisycal sectors / track
 2793          000028           dirtrk          .EQU    40      ; system logical track
 2794          000003           dirst           .EQU    3       ; starting directory sector
 2795          000051           maxtrk          .EQU    81      ; max. logical track + 1
 2796          000001           startrk         .EQU    1       ; logical starting track
 2797                           
 2798                           ; max. available blocks's #
 2799          000C58           maxblks         .EQU    (numsec*(maxtrk-1)-numsec)
 2800                           
 2801          000044           dskvern         .EQU    $44     ; disk version number
 2802          000033           dosvern         .EQU    $33     ; dos version number
 2803          00008D           subvern         .EQU    $8D     ; disk sub-version number header ofs. 29 & 30
 2804          0000C0           iobyte          .EQU    $C0     ; default bam i/o byte
 2805                           
 2806          000004           MAXDOSDRV       .EQU    4       ; dos drives are 0..3
 2807                           
 2808                           ;deltyp         .EQU    0        ; deleted type
 2809          000001           seqtyp          .EQU    1       ; sequential type
 2810          000002           prgtyp          .EQU    2       ; program type
 2811          000003           usrtyp          .EQU    3       ; user type
 2812          000004           reltyp          .EQU    4       ; relative type
 2813          000005           partyp          .EQU    5       ; partition type
 2814          000006           exetyp          .EQU    6       ; new executable type
 2815          000007           typmsk          .EQU    7       ; mask for type bits
 2816                           
 2817                           ; internal use: open function's
 2818          000000           rdmode          .EQU    0        ; open read mode
 2819          000001           wtmode          .EQU    1       ; open write mode
 2820          000002           apmode          .EQU    2       ; open append mode
  Tue Jul 17 11:00:19 2018                                                                                               Page    5




 2821          000003           mdmode          .EQU    3       ; open modify mode
 2822          000003           lddir           .EQU    3       ; load directory
 2823          000004           seqdir          .EQU    4       ; open dir as seq. file
 2824          000005           damode          .EQU    5       ; open direct access type
 2825                           
 2826                           ; error codes
 2827          000014           rdtrk           .EQU    20      ; track read error 
 2828          000015           badfmt          .EQU    21      ; bad disk format (or unformatted disk)
 2829          000016           wrtrk           .EQU    22      ; track write error
 2830          000018           rdsec           .EQU    24      ; read error
 2831          000019           wrsec           .EQU    25      ; write error
 2832          00001A           wpon            .EQU    26      ; write protect on
 2833          00001D           badid           .EQU    29      ; disk id mismatch
 2834          00001E           badsyn          .EQU    30      ; general syntax
 2835          00001F           badcmd          .EQU    31      ; invalid command
 2836          000020           longln          .EQU    32      ; long line
 2837          000021           badfn           .EQU    33      ; invalid filname
 2838          000022           nofile          .EQU    34      ; no file given
 2839          000023           baddrv          .EQU    35      ; illegal drive number
 2840          000024           badchn          .EQU    36      ; illegal channel number
 2841          000025           nullln          .EQU    37      ; empty command string
 2842          000027           notsam          .EQU    39      ; cannot rename across drives
 2843          000028           flock           .EQU    40      ; locked file
 2844          000029           fsplt           .EQU    41      ; write file not closed
 2845          00002A           bnotm           .EQU    42      ; unmatch blocks count
 2846          00002B           invlnk          .EQU    43      ; invalid file link
 2847          00002C           badlst          .EQU    44      ; wrong index in last block
 2848          00003C           filopn          .EQU    60      ; file open
 2849          00003D           filnop          .EQU    61      ; file not open
 2850          00003E           flntfd          .EQU    62      ; file not found
 2851          00003F           flexst          .EQU    63      ; file exists
 2852          000040           mistyp          .EQU    64      ; file type mismatch
 2853          000042           badts           .EQU    66      ; illegal track or sector
 2854          000043           systs           .EQU    67      ; illegal system t or s
 2855          000044           wrfil           .EQU    68      ; write only file
 2856          000045           rdfil           .EQU    69      ; read only file
 2857          000046           nochnl          .EQU    70      ; no channel available
 2858          000047           direrr          .EQU    71      ; directory error
 2859          000048           dskful          .EQU    72      ; disk full
 2860          000049           cbmv2           .EQU    73      ; cbm emulator version
 2861          00004A           nodriv          .EQU    74      ; drive not ready
 2862          00004B           opnchn          .EQU    75      ; channel is open
 2863          00004C           nolinx          .EQU    76      ; no logical index available
 2864          00004D           fmter           .EQU    77      ; format error
 2865          00004E           ibmfmt          .EQU    78      ; ibm-formatted disk
 2866          00004F           syterr          .EQU    79      ; system track read error
 2867          000050           dirlnk          .EQU    80      ; corrupted directory link
 2868          000051           bamcnt          .EQU    81      ; corrupted bam
 2869          000052           badcat          .EQU    82      ; recursive concat
 2870          000053           badtlk          .EQU    83      ; invalid talk command
 2871          000054           badlsn          .EQU    84      ; invalid listen command
 2872                           
 2873                           ; sezione COMMON -- questo permette di includere il file in piu' file
 2874                           
 2875                           DPCBMFS: .SECTION page0, ref_only, common
 2876  000000                           .ABSOLUTE               ;; inizia sempre da $00
 2877  000000                           .ORG    0x00
  Tue Jul 17 11:00:19 2018                                                                                               Page    6




 2878                           
 2879          000000           zpstart         .EQU    $
 2880                           
 2881  000000                   delsec          .DS     2       ; sector of 1st avail entry
 2882  000002                   delind          .DS     2       ; index of 1st avail entry
 2883  000004                   dirsec          .DS     2       ; directory sector of last not empty entry
 2884  000006                   index           .DS     2       ; index of last not empty entry
 2885  000008  00               track           .DB             ; current track
 2886  000009  00               sector          .DB             ; current sector
 2887  00000A                   dirp            LP              ; long pointer to directory entry
 2888  00000D  00               nxtsec          .DB             ; next sector in dir link
 2889  00000E  00               type            .DB             ; active file type
 2890  00000F  00               mode            .DB             ; active file mode
 2891  000010  00               typflg          .DB             ; match by type flag
 2892  000011  00               patflg          .DB             ; pattern presence flag
 2893  000012  00               f1cnt           .DB             ; file stream 1 count
 2894  000013  00               f2cnt           .DB             ; file stream total count
 2895  000014  00               f1ptr           .DB             ; file stream 1 pointer
 2896  000015  00               f2ptr           .DB             ; file stream 2 pointer
 2897  000016  00               entfnd          .DB             ; dir-entry found flag ($FF = not found)
 2898  000017  00               found           .DB             ; flag found in file stream
 2899  000018  00               tgflg           .DB             ; drive toggle flag
 2900                                                           ; <7>: search both drives
 2901                                                           ; <6>: drvnum was toggled
 2902                           
 2903  000019  00               drvnum          .DB             ; current drive
 2904                           
 2905  00001A                   filtbl          .DS     mxfils  ; filename pointer
 2906  00001F  00               tmpxxx          .DB             ; extra byte for filtbl/tmp byte
 2907  000020                   filtrk          .DS     mxfils  ; 1st link/track
 2908  000025                   filsec          .DS     mxfils  ;    /sector
 2909  00002A                   entsec          .DS     mxfils  ; sector of directory entry
 2910  00002F                   entind          .DS     mxfils  ; index of directory entry
 2911  000034                   fildrv          .DS     mxfils  ; default flag, drive #
 2912  000039                   pattyp          .DS     mxfils  ; pattern,replace,closed-flags,type
 2913                           
 2914          00003E           dpsave          .EQU    $ - zpstart
 2915                           
 2916                           ;----------------------
 2917                           
 2918  00003E                   tlp             LP              ; tmp long pointer
 2919  000041  00               cmdsiz          .DB             ; cmd string size
 2920  000042  00               char            .DB             ; tmp store char
 2921  000043  00               image           .DB             ; file stream image
 2922                           
 2923          000041           qfmt            .EQU    cmdsiz  ; quick format flag
 2924          000042           idch1           .EQU    char    ; ID format char 1
 2925          000043           idch2           .EQU    image   ; ID format char 2
 2926          000042           opntm           .EQU    char    ; <7>: open type in parameter
 2927                                                           ; <6>: open mode in parameter
 2928                           
 2929                           ; virtual iec -----------------------------------------
 2930  000044  00               sa              .DB             ; persistent second addr. virtual iec
 2931  000045  00               viecbuf         .DB             ; virtual iec buffered data
 2932  000046  0000             viecsiz         .DW
 2933  000048  0000             viecndx         .DW
 2934  00004A                   vieclp          LP
  Tue Jul 17 11:00:19 2018                                                                                               Page    7




 2935  00004D  00               viecfg          .DB             ; virtual iec flag
 2936                                                           ; <7>: active talk/listen
 2937                                                           ; <6>: talk (listen if 0)
 2938                           
 2939  00004E  00               vcmdix          .DB             ; index to command string
 2940  00004F  00               vbufnum         .DB             ; viec buffer #
 2941  000050  00               vcmdsiz         .DB             ; size of virtuasl iec buffer (channel 15)
 2942  000051  00               veof            .DB             ; eof flag
 2943                           
 2944                           ;-----------------------------------------------------
 2945  000052  00               chnl            .DB             ; channel param
 2946  000053  00               cmdnum          .DB             ; command #
 2947  000054  00               bchn            .DB             ; block-op channel
 2948  000055  00               subcmd          .DB             ; blk subcommand # or open type cmd
 2949                           
 2950  000056  00               lsterr          .DB             ; last error
 2951                           
 2952  000057  00               lindx           .DB             ; logical index (internal file descriptor)
 2953  000058  00               linuse          .DB             ; lindx use flags (1=free, 0=busy)
 2954  000059                   lintab          .DS     mxchnls ; lindx table ($FF = free)
 2955                                                           ; <7>: write type fd
 2956                                                           ; <6>: direct access type fd
 2957                                                           ; <5>: directory load type fd
 2958                                                           ; <3>: drive
 2959                                                           ; <2:0> = logical index
 2960                           
 2961  000068                   drvfg           .DS     2       ; drive flag
 2962                                                           ; <7>: cbm formatted disk
 2963                                                           ; <6>: valid format in bit 1,0
 2964                                                           ; <5>: flag verify in bam iobyte
 2965                                                           ; <4>: flag write protect on
 2966                                                           ; <3>: flag new version
 2967                                                           ;
 2968                                                           ; <1:0> 00 DD ibm format
 2969                                                           ;       01 DD cbm format
 2970                                                           ;       10 HD ibm format
 2971                                                           ;       11 HD cbm format (not used)
 2972                           
 2973  00006A  0000             ndbf            .DW             ; # of disk blocks free drive 0
 2974  00006C  0000                             .DW             ; # of disk blocks free drive 1
 2975                           
 2976  00006E                   sysbuf          .DS     2       ; DMA buffer # of system track cache
 2977  000070                   trkbuf          .DS     2       ; DMA buffer # of data track cache
 2978  000072                   wrtbuf          .DS     2       ; DMA buffer # of write buffer cache
 2979  000074                   dirofs          .DS     2       ; directory cache buffer high pointer (dma)
 2980  000076                   dirbnk          .DS     2       ; directory cache buffer bank (dma)
 2981  000078                   trkofs          .DS     2       ; track cache buffer high pointer (dma)
 2982  00007A                   trkbnk          .DS     2       ; track cache buffer bank (dma)
 2983  00007C                   wrtofs          .DS     2       ; write cache pointer
 2984  00007E                   wrtbnk          .DS     2       
 2985  000080                   tcache          .DS     2       ; current track in cache (0 invalidate cache)
 2986  000082                   wcache          .DS     2       ; current track in write cache (0 inv. cache)
 2987                           
 2988  000084                   wbam            .DS     2       ; dirty bam flag
 2989                           
 2990  000086  0000             bsize           .DW             ; size of buffer while read/write op
 2991  000088  0000             btrf            .DW             ; count of transf. bytes
  Tue Jul 17 11:00:19 2018                                                                                               Page    8




 2992          000086           ntot            .EQU    bsize   ; free block's counter while check file system
 2993          000088           bcnt            .EQU    btrf    ; block's count while chech file system
 2994                           
 2995  00008A                   bufp            LP              ; long pointer to read data buffer (cache)
 2996  00008D                   bmpnt           LP              ; bam long pointer
 2997  000090                   wbuf            LP              ; long pointer to write data buffer
 2998                           
 2999  000093  00               tmp0            .DB             ; temp. byte
 3000  000094  0000             wtmp            .DW             ; tmp word
 3001                           
 3002  000096                   fdst            .DS     maxfd   ; fd status
 3003                                                           ; <7>: ready
 3004                                                           ; <6>: eof flag
 3005                                                           ; <0>: drive
 3006  00009E                   dsec            .DS     maxfd   ; sector of dir entry
 3007  0000A6                   dind            .DS     maxfd   ; index of dir entry
 3008  0000AE                   ftrk            .DS     maxfd   ; current file track (hi dir ptr for dir list)
 3009  0000B6                   fsec            .DS     maxfd   ; current file sector (rdlst for dir list)
 3010  0000BE                   fdptr           .DS     maxfd   ; file buffer pointer
 3011  0000C6                   fdblk           .DS     maxfd   ; current file block # count
 3012  0000CE                                   .DS     maxfd   ; dir. ptr for dir list
 3013  0000D6                   fdlst           .DS     maxfd   ; local buffer last byte ptr 
 3014  0000DE                   fdix            .DS     maxfd   ; local buffer pointer
 3015                           
 3016                           
 3017  0000E6  00               wrop            .DB             ; flag write-op
 3018  0000E7  00               data            .DB             ; buffered byte
 3019  0000E8  00               rddrv           .DB             ; drive # to read (buffered operation) 
 3020  0000E9  00               rdidx           .DB             ; pointer to read buffer (buffered operation)
 3021  0000EA  00               rdlst           .DB             ; pointer to last byte (buffered operation)
 3022  0000EB  00               rdeof           .DB             ; eof condition (buffered operation)
 3023  0000EC  00               wrdrv           .DB             ; drive # to write (buffered operation)
 3024  0000ED  00               wridx           .DB             ; pointer to write buffer (buffered operation)
 3025  0000EE  00               wsec            .DB             ; last dirty sector in write cache
 3026  0000EF  00               wfirst          .DB             ; first dirty sector in write cache
 3027  0000F0  0000             wcnt            .DW             ; block's # of write file (buffered operation)
 3028                           
 3029  0000F2  00               pdrv            .DB             ; used by disk access routines: drive #
 3030  0000F3  00               pside           .DB             ; side #
 3031  0000F4  00               psec            .DB             ; start sector #
 3032  0000F5  00               pcnt            .DB             ; sector(s) count #
 3033  0000F6  00               pbuf            .DB             ; dma buffer #
 3034                           
 3035  0000F7  00               dblfd           .DB             ; double index lindx
 3036  0000F8  00               trap            .DB             ; flag error trap
 3037  0000F9  00               cmdtrap         .DB             ; no error if command string is empty
 3038                           
 3039  0000F9                           .RELATIVE
 3040                                   .ENDS
 3041                           
 3042                           ; CBM FS work area
 3043                           CBMFSW: .SECTION common, ref_only
 3044  000000                           .ABSOLUTE
 3045  00E100                           .ORG    CBMFSW_START
 3046                           
 3047  00E100                   cmdbuf          .DS     cmdlen  ; command buffer
 3048  00E160  00                               .DB             ; for terminator '0'
  Tue Jul 17 11:00:19 2018                                                                                               Page    9




 3049  00E161                   fntab           .DS     fntlen  ; room for one dos filename (80) + one cbm...
 3050                                                           ; filename (17) or for 5 cbm file names (85)
 3051  00E1C2                           
 3052  00E1C2                   nambuf          .DS     nbsiz   ; directory buffer
 3053  00E1DD                   nambuf2         .DS     19      ; buffer for store quoted file name
 3054                           
 3055  00E1F0  0000 0000        dskser          .LWORD          ; serial in new version
 3056  00E1F4  0000 0000                        .LWORD
 3057                           
 3058  00E1F8  0000             tos             .DW             ; saved stack pointer
 3059  00E1FA  00               etrk            .DB             ; save track & sector for fmterr function
 3060  00E1FB  00               esec            .DB
 3061  00E1FC                   dskid1          .DS     2       ; disk id 1
 3062  00E1FE                   dskid2          .DS     2       ; disk id 2
 3063                           
 3064  00E200                           .RELATIVE
 3065                                   .ENDS
 3066                           
 3067                           CBMVIEC: .SECTION common, ref_only
 3068  000000                           .ABSOLUTE
 3069  00E200                           .ORG    CBMVIEC_START
 3070                           
 3071  00E200                   vixtab          .DS     16
 3072  00E210                   vsiztab         .DS     16
 3073  00E220                   vftab           .DS     16
 3074  00E230  00               vopnsa          .DB             ; SA for open command
 3075  00E231  00                               .DB
 3076  00E232                   vieccmd         .DS     cmdlen
 3077  00E292  00                               .DB
 3078                           
 3079                           
 3080  00E292                           .RELATIVE
 3081                                   .ENDS
 3082                           
 3083                           
 3084                                   .CODEF9
 3085                                   .LONGA off
 3086                                   .LONGI off
 3087                           
 3088                                   .EXTERN gctime16
 3089                           
 3090                           ;---------------------------------------------------------------------------
 3091                           ; System interface
 3092                           ;---------------------------------------------------------------------------
 3093                           
 3094                           ; virtual iec interface
 3095                           
 3096                           ; open procedure
 3097                           ;       call vlsnopn (A=sa)
 3098                           ;       call vsndcmd (A=byte)
 3099                           ;       call vunlsnopn
 3100                           ; vlsnopn - listen for open
 3101                           ; first call when send command or open file
 3102                           ; A=sa
 3103  F92A6F                   vlsnopn:
 3104                                   .GLOBAL vlsnopn
 3105                           
  Tue Jul 17 11:00:19 2018                                                                                               Page   10




 3106  F92A6F  0B                       phd
 3107  F92A70  F4 00 7E                 pea     #CBMFSP0
 3108  F92A73  2B                       pld                     ; set dp to emulator
 3109  F92A74  8B                       phb                     ; save current dbr
 3110  F92A75  A2 00                    ldx     #0
 3111  F92A77  DA                       phx
 3112  F92A78  AB                       plb                     ; set dbr=0
 3113  F92A79  29 0F                    and     #$0F
 3114  F92A7B  8D 30 E2                 sta     !vopnsa         ; save SA
 3115  F92A7E  64 4E                    stz     vcmdix          ; clear command string index
 3116  F92A80  AB                       plb
 3117  F92A81  2B                       pld
 3118  F92A82  6B                       rtl
 3119  F92A83                           
 3120                           ; vsndcmd: send cmd byte (A)
 3121  F92A83                   vsndcmd:
 3122                                   .GLOBAL vsndcmd
 3123                           
 3124  F92A83  DA                       phx
 3125  F92A84  0B                       phd
 3126  F92A85  F4 00 7E                 pea     #CBMFSP0
 3127  F92A88  2B                       pld                     ; set dp to emulator
 3128  F92A89  8B                       phb                     ; save current dbr
 3129  F92A8A  A2 00                    ldx     #0
 3130  F92A8C  DA                       phx
 3131  F92A8D  AB                       plb                     ; set dbr=0
 3132  F92A8E  A6 4E                    ldx     vcmdix
 3133  F92A90  E0 60                    cpx     #cmdlen
 3134  F92A92  B0 06                    bcs     ?end            ; string too long, no store
 3135  F92A94  9D 32 E2                 sta     !vieccmd,x      ; store
 3136  F92A97  E8                       inx
 3137  F92A98  86 4E                    stx     vcmdix          ; update string index
 3138  F92A9A  AB               ?end:   plb
 3139  F92A9B  2B                       pld
 3140  F92A9C  FA                       plx
 3141  F92A9D  6B                       rtl
 3142                           
 3143                           ; vunlsnopn - ulisten after open command
 3144                           ; CF=1 if error
 3145  F92A9E                   vunlsnopn:
 3146                                   .GLOBAL vunlsnopn
 3147                           
 3148  F92A9E  0B                       phd
 3149  F92A9F  F4 00 7E                 pea     #CBMFSP0
 3150  F92AA2  2B                       pld                     ; set dp to emulator
 3151  F92AA3  8B                       phb                     ; save current dbr
 3152  F92AA4  A2 00                    ldx     #0
 3153  F92AA6  DA                       phx
 3154  F92AA7  AB                       plb                     ; set dbr=0
 3155  F92AA8  AD 30 E2                 lda     !vopnsa         ; open SA
 3156  F92AAB  20 B1 2A                 jsr     vopen           ; exec open cmd
 3157  F92AAE  AB                       plb
 3158  F92AAF  2B                       pld
 3159  F92AB0  6B                       rtl
 3160  F92AB1                           
 3161                           ; vopen: local for open
 3162                           ; A=sa, X=0
  Tue Jul 17 11:00:19 2018                                                                                               Page   11




 3163  F92AB1                   vopen:
 3164  F92AB1  85 52                    sta     chnl            ; channel for exec command
 3165  F92AB3  C9 0F                    cmp     #$0F
 3166  F92AB5  D0 01                    bne     ?trp
 3167  F92AB7  CA                       dex                     ; accept null string in cmd channel
 3168  F92AB8  86 F9            ?trp:   stx     cmdtrap
 3169  F92ABA  A9 32                    lda     #<vieccmd       ; set pointer of command string
 3170  F92ABC  85 3E                    sta     tlp
 3171  F92ABE  A9 E2                    lda     #>vieccmd
 3172  F92AC0  85 3F                    sta     tlp+1
 3173  F92AC2  64 40                    stz     tlp+2           ; cmd. string in bank 0
 3174  F92AC4  A6 4E                    ldx     vcmdix
 3175  F92AC6  9E 32 E2                 stz     !vieccmd,x      ; terminate command string
 3176  F92AC9  20 8D 2F                 jsr     parsex          ; parse & execute command string
 3177  F92ACC  64 4E                    stz     vcmdix          ; clear command buffer index
 3178  F92ACE  B0 1B                    bcs     ?end            ; error
 3179  F92AD0  A6 52                    ldx     chnl
 3180  F92AD2  E0 0F                    cpx     #$0F
 3181  F92AD4  D0 02                    bne     ?dat            ; data channel
 3182  F92AD6  18                       clc
 3183  F92AD7  60                       rts
 3184  F92AD8  B5 57            ?dat:   lda     lindx,x
 3185  F92ADA  29 07                    and     #$07
 3186  F92ADC  0A                       asl     a
 3187  F92ADD  AA                       tax                     ; double index #
 3188  F92ADE                           ACC16CLC                ; CF=0, no error
 3189  F92ADE  C2 21                    rep     #(PMFLAG.OR.PCFLAG)
 3190                                   .LONGA  on
 3191                                   .MNLIST
 3192  F92AE0  9E 00 E2                 stz     !vixtab,x
 3193  F92AE3  9E 10 E2                 stz     !vsiztab,x
 3194  F92AE6  9E 20 E2                 stz     !vftab,x        ; pre-read flag & eof
 3195  F92AE9                           ACC08
 3196  F92AE9  E2 20                    sep     #PMFLAG
 3197                                   .LONGA  off
 3198                                   .MNLIST
 3199  F92AEB  60               ?end:   rts
 3200                           
 3201                           ; call after open (X = sa)
 3202  F92AEC                   vopnlst:
 3203                                   .GLOBAL vopnlst
 3204  F92AEC  DA                       phx
 3205  F92AED  0B                       phd
 3206  F92AEE  F4 00 7E                 pea     #CBMFSP0
 3207  F92AF1  2B                       pld                     ; set dp to emulator
 3208  F92AF2  8B                       phb                     ; save current dbr
 3209  F92AF3  A9 00                    lda     #0
 3210  F92AF5  48                       pha
 3211  F92AF6  AB                       plb                     ; set dbr=0
 3212  F92AF7  B5 57            ?dat:   lda     lindx,x
 3213  F92AF9  29 07                    and     #$07
 3214  F92AFB  0A                       asl     a
 3215  F92AFC  AA                       tax                     ; double index #
 3216  F92AFD                           ACC16CLC                ; CF=0, no error
 3217  F92AFD  C2 21                    rep     #(PMFLAG.OR.PCFLAG)
 3218                                   .LONGA  on
 3219                                   .MNLIST
  Tue Jul 17 11:00:19 2018                                                                                               Page   12




 3220  F92AFF  9E 00 E2                 stz     !vixtab,x
 3221  F92B02  9E 10 E2                 stz     !vsiztab,x
 3222  F92B05  9E 20 E2                 stz     !vftab,x        ; pre-read flag & eof
 3223  F92B08                           ACC08
 3224  F92B08  E2 20                    sep     #PMFLAG
 3225                                   .LONGA  off
 3226                                   .MNLIST
 3227  F92B0A  AB                       plb
 3228  F92B0B  2B                       pld
 3229  F92B0C  FA                       plx
 3230  F92B0D  6B                       rtl
 3231                           
 3232                           ; A,X,Y=long pointer to command string
 3233                           ; B=sa
 3234  F92B0E                   viec8open:
 3235  F92B0E  0B                       phd                     ; save current dp
 3236  F92B0F  F4 00 7E                 pea     #CBMFSP0
 3237  F92B12  2B                       pld                     ; set dp to emulator
 3238  F92B13  85 3E                    sta     tlp             ; set command string ptr
 3239  F92B15  86 3F                    stx     tlp+1
 3240  F92B17  84 40                    sty     tlp+2
 3241  F92B19  EB                       xba                     ; channel #
 3242  F92B1A  29 0F                    and     #$0F
 3243  F92B1C  85 52                    sta     chnl
 3244  F92B1E  8B                       phb                     ; save current dbr
 3245  F92B1F  A2 00                    ldx     #0
 3246  F92B21  DA                       phx
 3247  F92B22  AB                       plb                     ; set dbr=0
 3248  F92B23  C9 0F                    cmp     #$0F
 3249  F92B25  D0 01                    bne     ?trp
 3250  F92B27  CA                       dex                     ; accept null string in cmd channel
 3251  F92B28  86 F9            ?trp:   stx     cmdtrap
 3252  F92B2A  20 8D 2F                 jsr     parsex          ; parse & execute command string
 3253  F92B2D  B0 1E                    bcs     ?end            ; error
 3254  F92B2F  A6 52                    ldx     chnl
 3255  F92B31  E0 0F                    cpx     #$0F
 3256  F92B33  D0 05                    bne     ?dat            ; data channel
 3257  F92B35  64 4E                    stz     vcmdix          ; clear command buffer index
 3258  F92B37  18                       clc
 3259  F92B38  F0 13                    beq     ?end
 3260  F92B3A  B5 57            ?dat:   lda     lindx,x
 3261  F92B3C  29 07                    and     #$07
 3262  F92B3E  0A                       asl     a
 3263  F92B3F  AA                       tax                     ; double index #
 3264  F92B40                           ACC16CLC
 3265  F92B40  C2 21                    rep     #(PMFLAG.OR.PCFLAG)
 3266                                   .LONGA  on
 3267                                   .MNLIST
 3268  F92B42  9E 00 E2                 stz     !vixtab,x
 3269  F92B45  9E 10 E2                 stz     !vsiztab,x
 3270  F92B48  9E 20 E2                 stz     !vftab,x        ; pre-read flag & eof
 3271  F92B4B                           ACC08
 3272  F92B4B  E2 20                    sep     #PMFLAG
 3273                                   .LONGA  off
 3274                                   .MNLIST
 3275  F92B4D  AB               ?end:   plb                     ; restore dbr
 3276  F92B4E  2B                       pld                     ; restore dp
  Tue Jul 17 11:00:19 2018                                                                                               Page   13




 3277  F92B4F  6B                       rtl                     ; return CF=1 if error
 3278                           
 3279                           ; listen command
 3280                           ; A=sa
 3281  F92B50                   viec8lsn:
 3282                                   .GLOBAL viec8lsn
 3283                           
 3284  F92B50  DA                       phx                     ; save X, Y
 3285  F92B51  5A                       phy
 3286  F92B52  0B                       phd                     ; save current dp
 3287  F92B53  F4 00 7E                 pea     #CBMFSP0
 3288  F92B56  2B                       pld                     ; set dp to cbmfs emulator
 3289  F92B57  8B                       phb                     ; save dbr
 3290  F92B58  A2 00                    ldx     #0
 3291  F92B5A  DA                       phx
 3292  F92B5B  AB                       plb                     ; set dbr = 0
 3293  F92B5C  85 52                    sta     chnl            ; save sa       
 3294  F92B5E  29 0F                    and     #$0F
 3295  F92B60  AA                       tax                     ; X=sa
 3296  F92B61                           
 3297  F92B61  9C 30 E2                 stz     !vopnsa
 3298                           
 3299  F92B64  24 4D                    bit     viecfg          ; already active?
 3300  F92B66  10 12                    bpl     ?tst            ; no
 3301  F92B68  E4 44                    cpx     sa
 3302  F92B6A  D0 07                    bne     ?bad
 3303  F92B6C                           
 3304  F92B6C  A0 FF                    ldy     #$FF
 3305  F92B6E  8C 30 E2                 sty     .ABS.vopnsa
 3306  F92B71  80 15                    bra     ?dat
 3307                           
 3308  F92B73  A9 54            ?bad:   lda     #badlsn         ; invalid listen command
 3309  F92B75  20 35 2E                 jsr     viecerr         ; set error
 3310  F92B78  80 2F                    bra     ?end            ; exit with CF=1
 3311  F92B7A  20 10 2E         ?tst:   jsr     vtstwr          ; test if write channel
 3312  F92B7D  B0 2A                    bcs     ?end            ; error
 3313  F92B7F  E0 0F                    cpx     #$0F
 3314  F92B81  D0 05                    bne     ?dat            ; data channel
 3315  F92B83  64 4E                    stz     vcmdix          ; clear index
 3316  F92B85  18                       clc
 3317  F92B86  80 21                    bra     ?end            ; exit
 3318  F92B88  A6 4F            ?dat:   ldx     vbufnum
 3319  F92B8A                           
 3320  F92B8A  18                       clc
 3321  F92B8B  2C 30 E2                 bit     !vopnsa
 3322  F92B8E  30 19                    bmi     ?end
 3323                           
 3324  F92B90                           ACC16CLC
 3325  F92B90  C2 21                    rep     #(PMFLAG.OR.PCFLAG)
 3326                                   .LONGA  on
 3327                                   .MNLIST
 3328  F92B92  BF CA 2E F9              lda     >viecdma,x
 3329  F92B96  85 4A                    sta     vieclp
 3330  F92B98  A0 03                    ldy     #DMABNK+1       ; bank $80..$BF
 3331  F92B9A  84 4C                    sty     vieclp+2
 3332  F92B9C  BF 00 E2 00              lda     vixtab,x        ; get current index
 3333  F92BA0  85 48                    sta     viecndx         
  Tue Jul 17 11:00:19 2018                                                                                               Page   14




 3334  F92BA2  A9 00 10                 lda     #VIECMAX        ; max. size of buffer
 3335  F92BA5  85 46                    sta     viecsiz
 3336  F92BA7                           ACC08
 3337  F92BA7  E2 20                    sep     #PMFLAG
 3338                                   .LONGA  off
 3339                                   .MNLIST
 3340  F92BA9  A5 52            ?end:   lda     chnl
 3341  F92BAB  AB                       plb
 3342  F92BAC  2B                       pld
 3343  F92BAD  7A                       ply
 3344  F92BAE  FA                       plx
 3345  F92BAF  6B                       rtl
 3346                           
 3347                           ; talk command
 3348                           ; A=sa
 3349  F92BB0                   viec8tlk:
 3350                                   .GLOBAL viec8tlk
 3351                           
 3352  F92BB0  DA                       phx                     ; save X, Y
 3353  F92BB1  5A                       phy
 3354  F92BB2  0B                       phd                     ; save current dp
 3355  F92BB3  F4 00 7E                 pea     #CBMFSP0
 3356  F92BB6  2B                       pld                     ; set dp to cbmfs emulator
 3357  F92BB7  8B                       phb                     ; save dbr
 3358  F92BB8  A2 00                    ldx     #0
 3359  F92BBA  DA                       phx
 3360  F92BBB  AB                       plb                     ; set dbr = 0
 3361  F92BBC  85 52                    sta     chnl            ; save sa       
 3362  F92BBE  29 0F                    and     #$0F
 3363  F92BC0  AA                       tax                     ; X=sa
 3364  F92BC1                           
 3365  F92BC1  9C 30 E2                 stz     !vopnsa
 3366                           
 3367  F92BC4  24 4D                    bit     viecfg          ; already active?
 3368  F92BC6  10 12                    bpl     ?tst            ; no
 3369  F92BC8  E4 44                    cpx     sa
 3370  F92BCA  D0 07                    bne     ?bad
 3371  F92BCC  A0 FF                    ldy     #$FF
 3372  F92BCE  8C 30 E2                 sty     .ABS.vopnsa
 3373  F92BD1  80 2B                    bra     ?dat
 3374                           
 3375  F92BD3  A9 53            ?bad:   lda     #badtlk         ; invalid talk command
 3376  F92BD5  20 35 2E                 jsr     viecerr         ; set error
 3377  F92BD8  80 6D                    bra     ?end            ; exit with CF=1
 3378  F92BDA  20 F5 2D         ?tst:   jsr     vtstrd          ; test if read channel
 3379  F92BDD  B0 68                    bcs     ?end            ; error
 3380  F92BDF  E0 0F                    cpx     #$0F
 3381  F92BE1  D0 1B                    bne     ?dat            ; data channel
 3382  F92BE3  20 44 57                 jsr     fnderr          ; find last error
 3383  F92BE6  A0 FF                    ldy     #$FF            ; store error string
 3384  F92BE8  C8               ?lp:    iny     
 3385  F92BE9  B7 3E                    lda     [tlp],y
 3386  F92BEB  99 32 E2                 sta     vieccmd,y
 3387  F92BEE  D0 F8                    bne     ?lp
 3388  F92BF0  A9 0D                    lda     #$0D
 3389  F92BF2  99 32 E2                 sta     vieccmd,y
 3390  F92BF5  C8                       iny
  Tue Jul 17 11:00:19 2018                                                                                               Page   15




 3391  F92BF6  84 50                    sty     vcmdsiz         ; buffer size
 3392  F92BF8  64 4E                    stz     vcmdix          ; clear index
 3393  F92BFA  C2 41                    rep     #PCFLAG+PVFLAG  ; CF=VF=0: no error, no eof
 3394  F92BFC  80 49                    bra     ?end            ; exit
 3395  F92BFE  A6 4F            ?dat:   ldx     vbufnum
 3396  F92C00  BD 21 E2                 lda     !vftab+1,x
 3397  F92C03  85 51                    sta     veof            ; eof flag
 3398  F92C05                           
 3399  F92C05  2C 30 E2                 bit     !vopnsa
 3400  F92C08  30 19                    bmi     ?dat2
 3401                           
 3402  F92C0A                           ACC16CLC                ; CF=0
 3403  F92C0A  C2 21                    rep     #(PMFLAG.OR.PCFLAG)
 3404                                   .LONGA  on
 3405                                   .MNLIST
 3406  F92C0C  BF CA 2E F9              lda     >viecdma,x
 3407  F92C10  85 4A                    sta     vieclp          ; set buffer pointer
 3408  F92C12  A0 03                    ldy     #DMABNK+1
 3409  F92C14  84 4C                    sty     vieclp+2
 3410  F92C16  BF 00 E2 00              lda     vixtab,x
 3411  F92C1A  85 48                    sta     viecndx         ; current index
 3412  F92C1C  BD 10 E2                 lda     !vsiztab,x
 3413  F92C1F  85 46                    sta     viecsiz         ; current buffer size
 3414  F92C21                           ACC08
 3415  F92C21  E2 20                    sep     #PMFLAG
 3416                                   .LONGA  off
 3417                                   .MNLIST
 3418  F92C23  24 51            ?dat2:  bit     veof            ; eof?
 3419  F92C25  30 1E                    bmi     ?eof            ; yes: exit with CF=0, VF=1
 3420  F92C27  3C 20 E2                 bit     !vftab,x        ; pre-read flag
 3421  F92C2A  30 0A                    bmi     ?ok             ; already pre-readed
 3422  F92C2C  20 4E 2C                 jsr     vbufrd          ; pre-read into buffer
 3423  F92C2F  A9 80                    lda     #$80
 3424  F92C31  9D 20 E2                 sta     !vftab,x        ; set pre-read flag
 3425  F92C34  B0 11                    bcs     ?end            ; read error
 3426  F92C36                   ?ok:    ACC16CV                 ; CF=0, VF=0
 3427  F92C36  C2 61                    rep     #(PMFLAG.OR.PCFLAG.OR.PVFLAG)
 3428                                   .LONGA  on
 3429                                   .MNLIST
 3430  F92C38  A5 46                    lda     viecsiz         ; buffer is empty?
 3431  F92C3A                           ACC08
 3432  F92C3A  E2 20                    sep     #PMFLAG
 3433                                   .LONGA  off
 3434                                   .MNLIST
 3435  F92C3C  D0 09                    bne     ?end            ; no
 3436  F92C3E  A9 C0                    lda     #$C0
 3437  F92C40  85 51                    sta     veof            ; set eof flag
 3438  F92C42  9D 21 E2                 sta     !vftab+1,x
 3439  F92C45  E2 40            ?eof:   sep     #PVFLAG         ; VF=1: eof
 3440  F92C47  A5 52            ?end:   lda     chnl
 3441  F92C49  AB                       plb
 3442  F92C4A  2B                       pld
 3443  F92C4B  7A                       ply
 3444  F92C4C  FA                       plx
 3445  F92C4D  6B                       rtl
 3446                           
 3447                           ; CF=1 if read error
  Tue Jul 17 11:00:19 2018                                                                                               Page   16




 3448  F92C4E                   vbufrd:
 3449  F92C4E                           ACC16
 3450  F92C4E  C2 20                    rep     #PMFLAG
 3451                                   .LONGA  on
 3452                                   .MNLIST
 3453  F92C50  A5 4A                    lda     vieclp          ; set read buffer
 3454  F92C52  A4 4C                    ldy     vieclp+2
 3455  F92C54  85 90                    sta     wbuf
 3456  F92C56  84 92                    sty     wbuf+2
 3457  F92C58  A9 00 10                 lda     #VIECMAX        ; buffer max. size
 3458  F92C5B  85 86                    sta     bsize
 3459  F92C5D  64 88                    stz     btrf            ; clear transferred count
 3460  F92C5F  64 46                    stz     viecsiz         ; empty buffer
 3461  F92C61  64 48                    stz     viecndx
 3462  F92C63                           ACC08
 3463  F92C63  E2 20                    sep     #PMFLAG
 3464                                   .LONGA  off
 3465                                   .MNLIST
 3466  F92C65  A0 00                    ldy     #0              ; pre-read into buffer
 3467  F92C67  A6 44                    ldx     sa
 3468  F92C69  86 52                    stx     chnl
 3469  F92C6B  20 4F 43                 jsr     fd_rw
 3470  F92C6E  A6 4F                    ldx     vbufnum
 3471  F92C70                           ACC16
 3472  F92C70  C2 20                    rep     #PMFLAG
 3473                                   .LONGA  on
 3474                                   .MNLIST
 3475  F92C72  A9 00 00                 lda     #0
 3476  F92C75  B0 02                    bcs     ?st             ; error
 3477  F92C77  A5 88                    lda     btrf            ; count of transf. bytes
 3478  F92C79  85 46            ?st:    sta     viecsiz
 3479  F92C7B  9D 10 E2                 sta     !vsiztab,x
 3480  F92C7E                           ACC08
 3481  F92C7E  E2 20                    sep     #PMFLAG
 3482                                   .LONGA  off
 3483                                   .MNLIST
 3484  F92C80  60                       rts
 3485                           
 3486                           ; A=data
 3487  F92C81                   viec8put:
 3488                                   .GLOBAL viec8put
 3489                           
 3490  F92C81  DA                       phx                     ; save X, Y
 3491  F92C82  5A                       phy
 3492  F92C83  0B                       phd                     ; save current dp
 3493  F92C84  F4 00 7E                 pea     #CBMFSP0
 3494  F92C87  2B                       pld                     ; set dp to cbmfs emulator
 3495  F92C88  8B                       phb                     ; save dbr
 3496  F92C89  A2 00                    ldx     #0
 3497  F92C8B  DA                       phx
 3498  F92C8C  AB                       plb                     ; set dbr = 0
 3499  F92C8D  85 45                    sta     viecbuf         ; save data to put
 3500  F92C8F  24 4D                    bit     viecfg          ; current sa is active?
 3501  F92C91  10 02                    bpl     ?ern            ; no
 3502  F92C93  50 0F                    bvc     ?ok             ; ready to listen
 3503  F92C95  A9 46            ?ern:   lda     #nochnl         ; no channel available
 3504  F92C97  80 04                    bra     ?er
  Tue Jul 17 11:00:19 2018                                                                                               Page   17




 3505  F92C99  A6 44            ?erl:   ldx     sa              ; channel # error
 3506  F92C9B  A9 20                    lda     #longln         ; command too long
 3507  F92C9D  20 35 2E         ?er:    jsr     viecerr
 3508  F92CA0  A5 45                    lda     viecbuf
 3509  F92CA2  80 4E                    bra     ?end            ; return CF=1
 3510  F92CA4  A6 44            ?ok:    ldx     sa              ; trust on sa channel
 3511  F92CA6  E0 0F                    cpx     #$0F
 3512  F92CA8  D0 0E                    bne     ?dat            ; put to data channel
 3513  F92CAA  A6 4E                    ldx     vcmdix          ; current buffer index
 3514  F92CAC  E0 60                    cpx     #cmdlen
 3515  F92CAE  B0 E9                    bcs     ?erl            ; command line too long 
 3516  F92CB0  9D 32 E2                 sta     !vieccmd,x      ; store
 3517  F92CB3  E8                       inx
 3518  F92CB4  86 4E                    stx     vcmdix          ; update index
 3519                                   ;cmp    #$0D            ; terminate command string?
 3520                                   ;bne    ?clc            ; no, wait terminator
 3521                                   ;stz    !vieccmd-1,x    ; terminate string with null
 3522                                   ;lda    #$0F
 3523                                   ;xba                    ; B=channel 15
 3524                                   ;lda    #<vieccmd       ; set pointer to command string
 3525                                   ;ldx    #>vieccmd
 3526                                   ;ldy    #0              ; command string in bank 0
 3527                                   ;stz    vcmdix          ; clear buffer index
 3528                                   ;jsr    viec8cmd        ; exexcute command in channel 15
 3529                                   ;lda    #$0D
 3530  F92CB6  80 3A                    bra     ?end            ; CF set if error
 3531  F92CB8  A2 00            ?dat:   ldx     #0
 3532  F92CBA                           INDEX16
 3533  F92CBA  C2 10                    rep     #PXFLAG
 3534                                   .LONGI  on
 3535                                   .MNLIST
 3536  F92CBC  A4 48                    ldy     viecndx         ; index into buffer
 3537  F92CBE  C4 46                    cpy     viecsiz
 3538  F92CC0  B0 07                    bcs     ?wr             ; flush buffer
 3539  F92CC2  97 4A                    sta     [vieclp],y      ; store
 3540  F92CC4  C8                       iny
 3541  F92CC5  84 48                    sty     viecndx         ; update index
 3542  F92CC7  80 27                    bra     ?xy8            ; exit with CF=0
 3543  F92CC9  A4 4A            ?wr:    ldy     vieclp          ; flush buffer on disk
 3544  F92CCB  84 90                    sty     wbuf            ; set buffer pointer
 3545  F92CCD  A5 4C                    lda     vieclp+2
 3546  F92CCF  85 92                    sta     wbuf+2
 3547  F92CD1  A4 46                    ldy     viecsiz
 3548  F92CD3  84 86                    sty     bsize           ; buffer size
 3549  F92CD5  86 88                    stx     btrf            ; clear transferred count
 3550  F92CD7  86 48                    stx     viecndx         ; clear index
 3551                                   ;stx    viecsiz         ; clear size
 3552  F92CD9                           CPU08
 3553  F92CD9  E2 30                    sep     #(PMFLAG.OR.PXFLAG)
 3554                                   .LONGA  off
 3555                                   .LONGI  off
 3556                                   .MNLIST
 3557  F92CDB  A6 44                    ldx     sa              ; set channel #
 3558  F92CDD  86 52                    stx     chnl
 3559  F92CDF  A0 01                    ldy     #1              ; write op
 3560  F92CE1  20 4F 43                 jsr     fd_rw
 3561  F92CE4  A5 45                    lda     viecbuf         ; data to store
  Tue Jul 17 11:00:19 2018                                                                                               Page   18




 3562  F92CE6  B0 0A                    bcs     ?end            ; error
 3563  F92CE8  A0 01                    ldy     #1
 3564  F92CEA                           INDEX16
 3565  F92CEA  C2 10                    rep     #PXFLAG
 3566                                   .LONGI  on
 3567                                   .MNLIST
 3568  F92CEC  87 4A                    sta     [vieclp]        ; store
 3569  F92CEE  84 48                    sty     viecndx         ; next index = 1
 3570  F92CF0                   ?xy8:   INDEX08 
 3571  F92CF0  E2 10                    sep     #PXFLAG
 3572                                   .LONGI  off
 3573                                   .MNLIST
 3574  F92CF2  AB               ?end:   plb     
 3575  F92CF3  2B                       pld
 3576  F92CF4  7A                       ply
 3577  F92CF5  FA                       plx
 3578  F92CF6  6B                       rtl
 3579                           
 3580  F92CF7                   viec8get:
 3581                                   .GLOBAL viec8get
 3582                           
 3583  F92CF7  DA                       phx                     ; save X, Y
 3584  F92CF8  5A                       phy
 3585  F92CF9  0B                       phd                     ; save current dp
 3586  F92CFA  F4 00 7E                 pea     #CBMFSP0
 3587  F92CFD  2B                       pld                     ; set dp to cbmfs emulator
 3588  F92CFE  8B                       phb                     ; save dbr
 3589  F92CFF  A2 00                    ldx     #0
 3590  F92D01  DA                       phx
 3591  F92D02  AB                       plb                     ; set dbr = 0
 3592  F92D03  24 4D                    bit     viecfg          ; current sa is active?
 3593  F92D05  10 02                    bpl     ?ern            ; no
 3594  F92D07  70 09                    bvs     ?ok             ; ready to talk
 3595  F92D09  A9 46            ?ern:   lda     #nochnl         ; no channel available
 3596  F92D0B  20 35 2E                 jsr     viecerr
 3597  F92D0E  A9 0D                    lda     #$0D
 3598  F92D10  80 5C                    bra     ?end            ; return CF=1
 3599  F92D12  A6 44            ?ok:    ldx     sa              ; talk channel
 3600  F92D14  E0 0F                    cpx     #$0F
 3601  F92D16  D0 1E                    bne     ?dat            ; data channel
 3602  F92D18  A9 0D                    lda     #$0D
 3603  F92D1A  A4 50                    ldy     vcmdsiz         ; if buffer is empty...
 3604  F92D1C  F0 4A                    beq     ?eof            ; ... return CR & VF=1 (eof)
 3605  F92D1E  A6 4E                    ldx     vcmdix          ; index into buffer
 3606  F92D20  E4 50                    cpx     vcmdsiz         ; if buffer is terminated...
 3607  F92D22  90 03                    bcc     ?get
 3608  F92D24  18                       clc                     ; ... return CR & VF=1 (eof)
 3609  F92D25  80 41                    bra     ?eof
 3610  F92D27  BD 32 E2         ?get:   lda     !vieccmd,x      ; get data
 3611  F92D2A  E8                       inx
 3612  F92D2B  86 4E                    stx     vcmdix
 3613  F92D2D  E4 50                    cpx     vcmdsiz         ; if not last data...
 3614  F92D2F  B8                       clv
 3615  F92D30  90 3C                    bcc     ?end            ; ...exit with VF=0
 3616  F92D32  64 56                    stz     lsterr          ; clear last error
 3617  F92D34  80 32                    bra     ?eof            ; return VF=1 (eof)
 3618  F92D36  A2 00            ?dat:   ldx     #0
  Tue Jul 17 11:00:19 2018                                                                                               Page   19




 3619  F92D38                           INDEX16CLC              ; CF=0
 3620  F92D38  C2 11                    rep     #(PXFLAG.OR.PCFLAG)
 3621                                   .LONGI  on
 3622                                   .MNLIST
 3623  F92D3A  A9 0D                    lda     #$0D            ; return CR if eof      
 3624  F92D3C  24 51                    bit     veof            ; eof flag ?
 3625  F92D3E  30 2E                    bmi     ?end            ; exit with CF=0, VF=1
 3626  F92D40  A4 46                    ldy     viecsiz         ; if buffer is empty...
 3627  F92D42  F0 24                    beq     ?eof            ; ... return CR & VF=1 (eof)
 3628  F92D44  A4 48                    ldy     viecndx         ; index into buffer     
 3629  F92D46  B7 4A                    lda     [vieclp],y      ; get data
 3630  F92D48  C8                       iny
 3631  F92D49  84 48                    sty     viecndx         ; update index
 3632  F92D4B  C4 46                    cpy     viecsiz
 3633  F92D4D  B8                       clv
 3634  F92D4E  90 1E                    bcc     ?end            ; no eof                
 3635  F92D50  C0 00 10                 cpy     #VIECMAX        ; partial buffer?
 3636  F92D53  85 45                    sta     viecbuf         ; save data
 3637  F92D55  90 1E                    bcc     ?eof2           ; yes, eof
 3638  F92D57                           INDEX08
 3639  F92D57  E2 10                    sep     #PXFLAG
 3640                                   .LONGI  off
 3641                                   .MNLIST
 3642  F92D59  20 4E 2C                 jsr     vbufrd          ; pre-read buffer       
 3643  F92D5C  A5 45                    lda     viecbuf         ; data
 3644  F92D5E  B0 0E                    bcs     ?end            ; error
 3645  F92D60                           INDEX16CV
 3646  F92D60  C2 51                    rep     #(PXFLAG.OR.PCFLAG.OR.PVFLAG)
 3647                                   .LONGI  on
 3648                                   .MNLIST
 3649  F92D62  A4 88                    ldy     btrf            ; count of transf. bytes
 3650  F92D64  84 46                    sty     viecsiz
 3651                                   ;bne    ?end            ; is not last char
 3652  F92D66  80 06                    bra     ?end
 3653  F92D68                   ?eof:   CPU08VF                 ; eof so set VF = 1
 3654  F92D68  E2 70                    sep     #(PMFLAG.OR.PXFLAG.OR.PVFLAG)
 3655                                   .LONGA  off
 3656                                   .LONGI  off
 3657                                   .MNLIST
 3658  F92D6A  A2 C0                    ldx     #$C0
 3659  F92D6C  86 51                    stx     veof            ; set eof flag
 3660  F92D6E                   ?end:   CPU08
 3661  F92D6E  E2 30                    sep     #(PMFLAG.OR.PXFLAG)
 3662                                   .LONGA  off
 3663                                   .LONGI  off
 3664                                   .MNLIST
 3665  F92D70  AB                       plb
 3666  F92D71  2B                       pld
 3667  F92D72  7A                       ply
 3668  F92D73  FA                       plx
 3669  F92D74  6B                       rtl
 3670  F92D75                   ?eof2:  CPU08
 3671  F92D75  E2 30                    sep     #(PMFLAG.OR.PXFLAG)
 3672                                   .LONGA  off
 3673                                   .LONGI  off
 3674                                   .MNLIST
 3675  F92D77  B8                       clv
  Tue Jul 17 11:00:19 2018                                                                                               Page   20




 3676  F92D78  A9 C0                    lda     #$C0
 3677  F92D7A  85 51                    sta     veof
 3678  F92D7C  A5 45                    lda     viecbuf
 3679  F92D7E  80 EE                    bra     ?end
 3680                           
 3681                           ; unlisten
 3682  F92D80                   v8unlsn:
 3683                                   .GLOBAL v8unlsn
 3684                           
 3685  F92D80  DA                       phx
 3686  F92D81  0B                       phd                     ; save current dp
 3687  F92D82  F4 00 7E                 pea     #CBMFSP0
 3688  F92D85  2B                       pld                     ; set dp to cbmfs emulator
 3689  F92D86  8B                       phb                     ; save dbr
 3690  F92D87  A9 00                    lda     #0
 3691  F92D89  48                       pha
 3692  F92D8A  AB                       plb                     ; set dbr = 0
 3693  F92D8B  24 4D                    bit     viecfg          ; current sa is active?
 3694  F92D8D  10 10                    bpl     ?end            ; no
 3695  F92D8F  70 0E                    bvs     ?end            ; channel is talking
 3696  F92D91  A5 44                    lda     sa
 3697  F92D93  C9 0F                    cmp     #$0F
 3698  F92D95  D0 05                    bne     ?clr
 3699  F92D97  20 B1 2A                 jsr     vopen
 3700  F92D9A  80 04                    bra     ?end2
 3701  F92D9C  20 C3 2D         ?clr:   jsr     v8clr
 3702  F92D9F  18               ?end:   clc     
 3703  F92DA0  AB               ?end2:  plb
 3704  F92DA1  2B                       pld
 3705  F92DA2  FA                       plx
 3706  F92DA3  6B                       rtl
 3707  F92DA4                           
 3708                           ; untalk
 3709  F92DA4                   v8untlk:
 3710                                   .GLOBAL v8untlk
 3711                           
 3712  F92DA4  DA                       phx
 3713  F92DA5  0B                       phd                     ; save current dp
 3714  F92DA6  F4 00 7E                 pea     #CBMFSP0
 3715  F92DA9  2B                       pld                     ; set dp to cbmfs emulator
 3716  F92DAA  8B                       phb                     ; save dbr
 3717  F92DAB  A9 00                    lda     #0
 3718  F92DAD  48                       pha
 3719  F92DAE  AB                       plb                     ; set dbr = 0
 3720  F92DAF  24 4D                    bit     viecfg          ; current sa is active?
 3721  F92DB1  10 0B                    bpl     ?end            ; no
 3722  F92DB3  50 09                    bvc     ?end            ; channel is listening
 3723  F92DB5  A6 44                    ldx     sa
 3724  F92DB7  E0 0F                    cpx     #$0F
 3725  F92DB9  F0 03                    beq     ?end
 3726  F92DBB  20 C3 2D                 jsr     v8clr
 3727  F92DBE  AB               ?end:   plb
 3728  F92DBF  2B                       pld
 3729  F92DC0  FA                       plx
 3730  F92DC1  18                       clc
 3731  F92DC2  6B                       rtl
 3732  F92DC3                           
  Tue Jul 17 11:00:19 2018                                                                                               Page   21




 3733                           ; clear channel
 3734  F92DC3                   v8clr:
 3735  F92DC3  A6 4F                    ldx     vbufnum
 3736  F92DC5  A5 51                    lda     veof
 3737  F92DC7  9F 21 E2 00              sta     vftab+1,x
 3738  F92DCB                           ACC16
 3739  F92DCB  C2 20                    rep     #PMFLAG
 3740                                   .LONGA  on
 3741                                   .MNLIST
 3742  F92DCD  A5 48                    lda     viecndx
 3743  F92DCF  9F 00 E2 00              sta     vixtab,x
 3744  F92DD3  A5 46                    lda     viecsiz
 3745  F92DD5  9F 10 E2 00              sta     vsiztab,x
 3746  F92DD9                           ACC08
 3747  F92DD9  E2 20                    sep     #PMFLAG
 3748                                   .LONGA  off
 3749                                   .MNLIST
 3750  F92DDB  64 4D                    stz     viecfg
 3751  F92DDD  60                       rts
 3752                           
 3753                           ; A,X,Y=long pointer to command string
 3754                           ; B=sa
 3755  F92DDE                   viec8cmd:
 3756  F92DDE  85 3E                    sta     tlp             ; set pointer to command string
 3757  F92DE0  86 3F                    stx     tlp+1
 3758  F92DE2  84 40                    sty     tlp+2
 3759  F92DE4  A2 00                    ldx     #0
 3760  F92DE6  EB                       xba     
 3761  F92DE7  29 0F                    and     #$0F
 3762  F92DE9  85 52                    sta     chnl
 3763  F92DEB  C9 0F                    cmp     #$0F
 3764  F92DED  D0 01                    bne     ?trp
 3765  F92DEF  CA                       dex                     ; accept null string in cmd channel
 3766  F92DF0  86 F9            ?trp:   stx     cmdtrap
 3767  F92DF2  4C 8D 2F                 jmp     parsex          ; parse & execute command string
 3768                           
 3769                           ; test channel for read
 3770                           ; x = channel #
 3771  F92DF5                   vtstrd:
 3772  F92DF5  E0 0F                    cpx     #$0F
 3773  F92DF7  F0 0F                    beq     ?ok             ; is command channel
 3774  F92DF9  B5 59                    lda     lintab,x        ; test if given channel is open
 3775  F92DFB  A8                       tay
 3776  F92DFC  C9 FF                    cmp     #$FF
 3777  F92DFE  F0 2F                    beq     verrnochn       ; channel not open
 3778  F92E00  98                       tya
 3779  F92E01  30 30                    bmi     verrbadchn      ; channel not open for read
 3780  F92E03  29 07                    and     #$07
 3781  F92E05  0A                       asl     a
 3782  F92E06  85 4F                    sta     vbufnum         ; buffer number #
 3783  F92E08  86 44            ?ok:    stx     sa              ; save channel #
 3784  F92E0A  A9 C0                    lda     #$C0            ; set active talk sa
 3785  F92E0C  85 4D                    sta     viecfg
 3786  F92E0E  18                       clc                     ; no error
 3787  F92E0F  60                       rts
 3788                           
 3789                           ; test channel for write
  Tue Jul 17 11:00:19 2018                                                                                               Page   22




 3790                           ; x = channel #
 3791  F92E10                   vtstwr:
 3792  F92E10  E0 0F                    cpx     #$0F
 3793  F92E12  F0 13                    beq     ?set            ; is command channel
 3794  F92E14  B5 59                    lda     lintab,x        ; test if given channel is open
 3795  F92E16  A8                       tay
 3796  F92E17  C9 FF                    cmp     #$FF
 3797  F92E19  F0 14                    beq     verrnochn       ; channel not open
 3798  F92E1B  98                       tya
 3799  F92E1C  30 04                    bmi     ?ok             ; ok is a write channel
 3800  F92E1E  0A                       asl     a               ; test bit 6 - direct access
 3801  F92E1F  10 12                    bpl     verrbadchn      ; channel not open for write
 3802  F92E21  98                       tya
 3803  F92E22  29 07            ?ok:    and     #$07
 3804  F92E24  0A                       asl     a
 3805  F92E25  85 4F                    sta     vbufnum         ; buffer number #
 3806  F92E27  86 44            ?set:   stx     sa              ; save channel #
 3807  F92E29  A9 80                    lda     #$80            ; set active listen sa
 3808  F92E2B  85 4D                    sta     viecfg
 3809  F92E2D  18                       clc                     ; no error
 3810  F92E2E  60                       rts
 3811                           
 3812  F92E2F                   verrnochn:
 3813  F92E2F  A9 3D                    lda     #filnop
 3814  F92E31  80 02                    bra     viecerr
 3815  F92E33                   verrbadchn:
 3816  F92E33  A9 24                    lda     #badchn
 3817  F92E35                   viecerr:
 3818  F92E35  8E FA E1                 stx     etrk
 3819  F92E38  9C FB E1                 stz     esec
 3820  F92E3B  85 56                    sta     lsterr
 3821  F92E3D  38                       sec
 3822  F92E3E  60                       rts
 3823                           
 3824  F92E3F                   verrlsn:
 3825  F92E3F  A9 54                    lda     #badlsn
 3826  F92E41  80 F2                    bra     viecerr
 3827                           
 3828                           ; test channel for close
 3829                           ; A=sa
 3830  F92E43                   vtstcls:
 3831  F92E43  64 51                    stz     veof            ; clear flush buffer flag
 3832  F92E45  29 0F                    and     #$0F
 3833  F92E47  AA                       tax
 3834  F92E48  E0 0F                    cpx     #$0F
 3835  F92E4A  F0 3E                    beq     ?end
 3836  F92E4C  24 4D                    bit     viecfg
 3837  F92E4E  30 EF                    bmi     verrlsn
 3838  F92E50  B5 59                    lda     lintab,x
 3839  F92E52  C9 FF                    cmp     #$FF
 3840  F92E54  F0 D9                    beq     verrnochn
 3841  F92E56  A8                       tay
 3842  F92E57  29 07                    and     #$07
 3843  F92E59  0A                       asl     a
 3844  F92E5A  85 4F                    sta     vbufnum
 3845  F92E5C  98                       tya
 3846  F92E5D  30 03                    bmi     ?set
  Tue Jul 17 11:00:19 2018                                                                                               Page   23




 3847  F92E5F  0A                       asl     a
 3848  F92E60  10 02                    bpl     ?ok
 3849  F92E62  85 51            ?set:   sta     veof            ; set flush buffer flag
 3850  F92E64  86 44            ?ok:    stx     sa
 3851  F92E66  24 51                    bit     veof
 3852  F92E68  10 20                    bpl     ?end
 3853  F92E6A  A6 4F                    ldx     vbufnum
 3854  F92E6C                           ACC16CLC                ; CF=0
 3855  F92E6C  C2 21                    rep     #(PMFLAG.OR.PCFLAG)
 3856                                   .LONGA  on
 3857                                   .MNLIST
 3858  F92E6E  BF CA 2E F9              lda     >viecdma,x
 3859  F92E72  85 90                    sta     wbuf            ; set buffer pointer
 3860  F92E74  A0 03                    ldy     #DMABNK+1
 3861  F92E76  84 92                    sty     wbuf+2
 3862  F92E78  BD 00 E2                 lda     !vixtab,x
 3863  F92E7B  85 86                    sta     bsize           ; current index
 3864  F92E7D  64 88                    stz     btrf            ; clear transferred count
 3865  F92E7F  9E 00 E2                 stz     !vixtab,x
 3866  F92E82                           ACC08
 3867  F92E82  E2 20                    sep     #PMFLAG
 3868                                   .LONGA  off
 3869                                   .MNLIST
 3870  F92E84  D0 02                    bne     ?sa             ; ok, will flush buffer
 3871  F92E86  64 51                    stz     veof            ; nothing to flush
 3872  F92E88  A6 44            ?sa:    ldx     sa
 3873  F92E8A  18               ?end:   clc
 3874  F92E8B  60                       rts
 3875                           
 3876                           ; close
 3877  F92E8C                   A=sa
 3878  F92E8C                   v8close:
 3879                                   .GLOBAL v8close
 3880                           
 3881  F92E8C  0B                       phd                     ; save current dp
 3882  F92E8D  F4 00 7E                 pea     #CBMFSP0
 3883  F92E90  2B                       pld                     ; set dp to cbmfs emulator
 3884  F92E91  8B                       phb                     ; save dbr
 3885  F92E92  A2 00                    ldx     #0
 3886  F92E94  DA                       phx
 3887  F92E95  AB                       plb                     ; set dbr = 0
 3888  F92E96  20 43 2E                 jsr     vtstcls
 3889  F92E99  B0 2C                    bcs     ?end            ; error
 3890  F92E9B  E0 0F                    cpx     #$0F
 3891  F92E9D  18                       clc
 3892  F92E9E  F0 27                    beq     ?end
 3893  F92EA0  86 52                    stx     chnl
 3894  F92EA2  24 51                    bit     veof            ; need ro flush buffer?
 3895  F92EA4  10 0D                    bpl     ?cls            ; no, close file
 3896  F92EA6  A6 44                    ldx     sa              ; set channel #
 3897  F92EA8  86 52                    stx     chnl
 3898  F92EAA  A0 01                    ldy     #1              ; write op
 3899  F92EAC  20 4F 43                 jsr     fd_rw
 3900  F92EAF  A6 44                    ldx     sa              ; set channel #
 3901  F92EB1  86 52                    stx     chnl            ; ignore error
 3902  F92EB3  20 AF 44         ?cls:   jsr     fdcls           ; close file(s)
 3903  F92EB6  64 4D                    stz     viecfg
  Tue Jul 17 11:00:19 2018                                                                                               Page   24




 3904  F92EB8  A6 4F                    ldx     vbufnum
 3905  F92EBA                           ACC16   
 3906  F92EBA  C2 20                    rep     #PMFLAG
 3907                                   .LONGA  on
 3908                                   .MNLIST
 3909  F92EBC  9E 00 E2                 stz     vixtab,x
 3910  F92EBF  9E 10 E2                 stz     vsiztab,x
 3911  F92EC2  9E 20 E2                 stz     vftab,x
 3912  F92EC5                           ACC08
 3913  F92EC5  E2 20                    sep     #PMFLAG
 3914                                   .LONGA  off
 3915                                   .MNLIST
 3916  F92EC7  AB               ?end:   plb
 3917  F92EC8  2B                       pld
 3918  F92EC9  6B                       rtl
 3919                           
 3920  F92ECA                   viecdma:
 3921  F92ECA  0000 0010 0020           .DW     $0000, $1000, $2000, $3000
               0030 
 3922  F92ED2  0040 0050 0060           .DW     $4000, $5000, $6000, $7000
               0070 
 3923  F92EDA                           
 3924                           ;---------------------------------------------------------------------------
 3925                           ; COP_cbmfs_cmd - send command to CBM file system emulator
 3926                           ;
 3927                           ; prototype: COP_cbmfs_cmd(sCmd, bChnl)
 3928                           ;
 3929                           ; Params (4 bytes):
 3930                           ;       sCmd    = command string long pointer
 3931                           ;       bChnl   = channel number $00..$0F
 3932                           ;                       $00             input only
 3933                           ;                       $01             output only
 3934                           ;                       $02..$0E        data channel
 3935                           ;                       $0F             command channel
 3936                           ;
 3937                           ; Out:
 3938                           ;       CF = 0 if operation completed successfully
 3939                           ;               A,X,Y preserved
 3940                           ;       CF = 1 if error
 3941                           ;               A, X preserved
 3942                           ;               Y = error code (cbm style)
 3943                           ;       Status register always preserved except carry
 3944                           
 3945                           ; params offset
 3946          000013           bChnl   .SET    STKPRMS
 3947          000014           sCmd    .SET    STKPRMS + 1
 3948                           
 3949  F92EDA                   COP_cbmfs_cmd:
 3950                                   .GLOBAL COP_cbmfs_cmd
 3951                           
 3952  F92EDA                           ACC16
 3953  F92EDA  C2 20                    rep     #PMFLAG
 3954                                   .LONGA  on
 3955                                   .MNLIST
 3956  F92EDC  A9 00 7E                 lda     #CBMFSP0        ; set DP -- not need to be saved
 3957  F92EDF  5B                       tcd
 3958  F92EE0  A3 14                    lda     sCmd,s          ; get command string long pointer
  Tue Jul 17 11:00:19 2018                                                                                               Page   25




 3959  F92EE2  85 3E                    sta     tlp
 3960  F92EE4                           ACC08
 3961  F92EE4  E2 20                    sep     #PMFLAG
 3962                                   .LONGA  off
 3963                                   .MNLIST
 3964  F92EE6  A3 16                    lda     sCmd+2,s
 3965  F92EE8  85 40                    sta     tlp+2
 3966  F92EEA  A3 13                    lda     bChnl,s
 3967  F92EEC  29 0F                    and     #$0F            ; mask
 3968  F92EEE  85 52                    sta     chnl
 3969  F92EF0  64 F9                    stz     cmdtrap
 3970  F92EF2  20 8D 2F                 jsr     parsex          ; parse & execute command string
 3971  F92EF5  6B                       rtl                     ; return CF=1 if error
 3972                           
 3973                           ; internal file system command 
 3974                           ; A,X,Y=long pointer to command string
 3975  F92EF6                   cbmfs_cmd:
 3976                                   .PUBLIC cbmfs_cmd
 3977                           
 3978  F92EF6  0B                       phd                     ; save current dp
 3979  F92EF7  F4 00 7E                 pea     #CBMFSP0
 3980  F92EFA  2B                       pld                     ; set dp to emulator
 3981  F92EFB  85 3E                    sta     tlp             ; set command string ptr
 3982  F92EFD  86 3F                    stx     tlp+1
 3983  F92EFF  84 40                    sty     tlp+2
 3984  F92F01  A9 0F                    lda     #$0F            ; command to channel 15
 3985  F92F03  85 52                    sta     chnl
 3986  F92F05  8B                       phb                     ; save current dbr
 3987  F92F06  A9 00                    lda     #0
 3988  F92F08  48                       pha
 3989  F92F09  AB                       plb                     ; set dbr=0
 3990  F92F0A  64 F9                    stz     cmdtrap
 3991  F92F0C  20 8D 2F                 jsr     parsex          ; parse & execute command string        
 3992  F92F0F  AB                       plb                     ; restore dbr
 3993  F92F10  2B                       pld                     ; restore dp
 3994  F92F11  60                       rts                     ; return CF=1 if error (A=error code)
 3995                           
 3996                           ; internal file system command
 3997                           ; return error string pointer (C=pointer, X=bank)
 3998  F92F12                   cbmfs_err:
 3999                                   .PUBLIC cbmfs_err
 4000                           
 4001  F92F12  0B                       phd                     ; save current dp
 4002  F92F13  F4 00 7E                 pea     #CBMFSP0
 4003  F92F16  2B                       pld                     ; set dp to emulator
 4004  F92F17  20 44 57                 jsr     fnderr
 4005  F92F1A  A0 00                    ldy     #0
 4006  F92F1C  B7 3E            ?02:    lda     [tlp],y
 4007  F92F1E  F0 10                    beq     ?06
 4008  F92F20  C9 61                    cmp     #'a'
 4009  F92F22  90 06                    bcc     ?04
 4010  F92F24  C9 7B                    cmp     #'z'+1
 4011  F92F26  B0 02                    bcs     ?04
 4012  F92F28  29 DF                    and     #$DF
 4013  F92F2A  99 00 E1         ?04:    sta     cmdbuf,y
 4014  F92F2D  C8                       iny
 4015  F92F2E  80 EC                    bra     ?02
  Tue Jul 17 11:00:19 2018                                                                                               Page   26




 4016  F92F30  99 00 E1         ?06:    sta     cmdbuf,y        
 4017  F92F33  A9 E1                    lda     #>cmdbuf
 4018  F92F35  EB                       xba
 4019  F92F36  A9 00                    lda     #<cmdbuf
 4020  F92F38  A2 00                    ldx     #0
 4021  F92F3A  AB                       plb                     ; restore dbr
 4022  F92F3B  2B                       pld                     ; restore dp
 4023  F92F3C  60                       rts
 4024  F92F3D                           
 4025                           ;---------------------------------------------------------------------------
 4026                           ; COP_cbmfs_rw - read/write on channel (in an open file)
 4027                           ;
 4028                           ; prototype: COP_cbmfs_rw(lpBuf, wSize, bChnl)
 4029                           ;
 4030                           ; Params (6 bytes):
 4031                           ;       lpBuf   = long pointer to buffer
 4032                           ;       wSize   = size (16 bit) of buffer if read or bytes count to write
 4033                           ;       bChnl   = channel number ($00..$0F)
 4034                           ;
 4035                           ; Out:
 4036                           ;       CF = 0 if operation completed successfully
 4037                           ;               C  = number of bytes transferred
 4038                           ;               X  = unchanged
 4039                           ;               Y  = unchanged
 4040                           ;       CF = 1 if error
 4041                           ;               C  = number of bytes transferred
 4042                           ;               X  = unchanged
 4043                           ;               Y  = error code (cbm-like)
 4044                           ;       Status register always preserved except carry
 4045                           ;
 4046                           ; Note:
 4047                           ;       Write to channel 15 ($0F) is no-op and return C = 0 and carry = 0
 4048                           ;       Use COP_cbmfs_cmd function to send command on channel 15
 4049                           ;       Read on channel 15 ($0F) return last error message
 4050                           ;       and need at least 96 bytes buffer large
 4051                           
 4052                           ; params offset
 4053          000013           bChnl   .SET    STKPRMS
 4054          000014           wSize   .SET    STKPRMS + 1
 4055          000016           lpBuf   .SET    STKPRMS + 3
 4056                           
 4057  F92F3D                   COP_cbmfs_rw:
 4058                                   .GLOBAL COP_cbmfs_rw
 4059                           
 4060  F92F3D                           ACC16                   ; retrieve function number
 4061  F92F3D  C2 20                    rep     #PMFLAG
 4062                                   .LONGA  on
 4063                                   .MNLIST
 4064  F92F3F  A3 10                    lda     STKPCL,s        ; pointer to byte after signature
 4065  F92F41  85 51                    sta     COPPtr
 4066  F92F43  1A                       inc     a               ; update return address
 4067  F92F44  83 10                    sta     STKPCL,s
 4068  F92F46                           ACC08                   ; A,M -> 8 bit
 4069  F92F46  E2 20                    sep     #PMFLAG
 4070                                   .LONGA  off
 4071                                   .MNLIST
 4072  F92F48  A3 12                    lda     STKPBR,s        ; bank where was executed cop instruction
  Tue Jul 17 11:00:19 2018                                                                                               Page   27




 4073  F92F4A  85 53                    sta     COPPtr+2        
 4074  F92F4C  A7 51                    lda     [COPPtr]        ; byte after signature (0->read, 1->write)
 4075  F92F4E  A8                       tay                     ; Y = read(0)/write(1)
 4076  F92F4F                           ACC16
 4077  F92F4F  C2 20                    rep     #PMFLAG
 4078                                   .LONGA  on
 4079                                   .MNLIST
 4080  F92F51  A9 00 7E                 lda     #CBMFSP0        ; set DP -- not need to be saved
 4081  F92F54  5B                       tcd
 4082  F92F55  A3 14                    lda     wSize,s         ; get buffer size
 4083  F92F57  85 86                    sta     bsize
 4084  F92F59  64 88                    stz     btrf            ; clear transferred count
 4085  F92F5B  A3 16                    lda     lpBuf,s         ; dest. buffer poinnter
 4086  F92F5D  85 90                    sta     wbuf
 4087  F92F5F                           ACC08                   ; A,M -> 8 bit
 4088  F92F5F  E2 20                    sep     #PMFLAG
 4089                                   .LONGA  off
 4090                                   .MNLIST
 4091  F92F61  A3 18                    lda     lpBuf+2,s
 4092  F92F63  85 92                    sta     wbuf+2
 4093  F92F65  A3 13                    lda     bChnl,s         ; get channel
 4094  F92F67  29 0F                    and     #$0F            ; mask
 4095  F92F69  AA                       tax
 4096  F92F6A  86 52                    stx     chnl
 4097  F92F6C  20 4F 43                 jsr     fd_rw           ; return carry = 1 if error
 4098  F92F6F  AA                       tax                     ; save error code if any
 4099  F92F70                           ACC16
 4100  F92F70  C2 20                    rep     #PMFLAG
 4101                                   .LONGA  on
 4102                                   .MNLIST
 4103  F92F72  A5 88                    lda     btrf            ; return count of transf. bytes to caller
 4104  F92F74  83 0D                    sta     STKCR,s
 4105  F92F76                           ACC08
 4106  F92F76  E2 20                    sep     #PMFLAG
 4107                                   .LONGA  off
 4108                                   .MNLIST
 4109  F92F78  8A                       txa
 4110  F92F79  6B                       rtl     
 4111                           
 4112                           ;---------------------------------------------------------------------------
 4113                           ; COP_cbmfs_close
 4114                           ;
 4115                           ; prototype: COP_cbmfs_close
 4116                           ;
 4117                           ; Params: none in stack
 4118                           ;       A = channel to close ($00..$0F)
 4119                           ;       closing chnl $0F close all open files
 4120                           ;
 4121                           ; Out:
 4122                           ;       CF = 0 if operation completed successfully
 4123                           ;               C  = unchanged
 4124                           ;               X  = unchanged
 4125                           ;               Y  = unchanged
 4126                           ;       CF = 1 if error
 4127                           ;               C  = unchanged
 4128                           ;               X  = unchanged
 4129                           ;               Y  = error code (cbm-like)
  Tue Jul 17 11:00:19 2018                                                                                               Page   28




 4130                           ;       Status register always preserved except carry
 4131                           ;
 4132  F92F7A                   COP_cbmfs_close:
 4133                                   .GLOBAL COP_cbmfs_close
 4134                           
 4135  F92F7A                           ACC16
 4136  F92F7A  C2 20                    rep     #PMFLAG
 4137                                   .LONGA  on
 4138                                   .MNLIST
 4139  F92F7C  A9 00 7E                 lda     #CBMFSP0        ; set DP -- not need to be saved
 4140  F92F7F  5B                       tcd
 4141  F92F80                           ACC08   
 4142  F92F80  E2 20                    sep     #PMFLAG
 4143                                   .LONGA  off
 4144                                   .MNLIST
 4145  F92F82  A3 0D                    lda     STKCR,s         ; get channel
 4146  F92F84  29 0F                    and     #$0F
 4147  F92F86  AA                       tax
 4148  F92F87  86 52                    stx     chnl
 4149  F92F89  20 AF 44                 jsr     fdcls
 4150  F92F8C  6B                       rtl
 4151                           
 4152                           ;---------------------------------------------------------------------------
 4153                           ; parse command string & execute command
 4154                           ;---------------------------------------------------------------------------
 4155                           
 4156                           ; parse & execute command string
 4157  F92F8D                   parsex:
 4158  F92F8D                           ACC16
 4159  F92F8D  C2 20                    rep     #PMFLAG
 4160                                   .LONGA  on
 4161                                   .MNLIST
 4162  F92F8F  3B                       tsc                     ; save current stack pointer
 4163  F92F90  8D F8 E1                 sta     !tos
 4164  F92F93                           ACC08
 4165  F92F93  E2 20                    sep     #PMFLAG
 4166                                   .LONGA  off
 4167                                   .MNLIST
 4168  F92F95  64 56                    stz     lsterr
 4169  F92F97  20 D1 42                 jsr     cmdset          ; trim & up case input string
 4170  F92F9A  A4 41                    ldy     cmdsiz
 4171  F92F9C  F0 40                    beq     ?10             ; empty command string
 4172  F92F9E  A5 52                    lda     chnl
 4173  F92FA0  C9 0F                    cmp     #$0F
 4174  F92FA2  D0 3F                    bne     ?30             ; open command
 4175  F92FA4  A2 10                    ldx     #ncmds-1        ; check first letter...
 4176  F92FA6  AD 00 E1                 lda     !cmdbuf         ; ...with cmd table
 4177  F92FA9  DF 58 5A F9      ?02:    cmp     >cmdtbl,x
 4178  F92FAD  F0 06                    beq     ?04
 4179  F92FAF  CA                       dex
 4180  F92FB0  10 F7                    bpl     ?02
 4181  F92FB2  4C FD 40                 jmp     e_badcmd
 4182  F92FB5  86 53            ?04:    stx     cmdnum
 4183  F92FB7  A4 41                    ldy     cmdsiz          ; if just one char is an arror !
 4184  F92FB9  88                       dey
 4185  F92FBA  F0 24                    beq     ?20             ; syntax error
 4186  F92FBC  E0 0F                    cpx     #ndcmd          ; no check drive for block-op
  Tue Jul 17 11:00:19 2018                                                                                               Page   29




 4187  F92FBE  B0 0F                    bcs     ?06
 4188  F92FC0  AD 01 E1                 lda     !cmdbuf+1
 4189  F92FC3  A0 00                    ldy     #0              ; check cbm drive (0 or 1)
 4190  F92FC5  E0 09                    cpx     #pcmd-1         ; if M command, first drive will be dos drive
 4191  F92FC7  D0 01                    bne     ?05
 4192  F92FC9  88                       dey                     ; check dos drive
 4193  F92FCA  20 98 3D         ?05:    jsr     chkdrv
 4194  F92FCD  85 19                    sta     drvnum          ; save first drive in command string
 4195  F92FCF  E0 0A            ?06:    cpx     #pcmd           ; limit of not parsed cmd
 4196  F92FD1  B0 05                    bcs     ?08
 4197  F92FD3  20 0E 41                 jsr     tagcmd          ; full parse command
 4198  F92FD6  A6 53                    ldx     cmdnum
 4199  F92FD8  8A               ?08:    txa
 4200  F92FD9  0A                       asl     a
 4201  F92FDA  AA                       tax
 4202  F92FDB  FC C4 5A                 jsr     (cjump,x)
 4203  F92FDE  18               ?10:    clc                     ; return no error
 4204  F92FDF  60                       rts
 4205                           
 4206  F92FE0  4C 05 41         ?20:    jmp     e_badsyn
 4207                           
 4208                           ;---------------------------------------------------------------------------
 4209                           ; open function's
 4210                           ;---------------------------------------------------------------------------
 4211                           
 4212                           ; parse open command on channel 0..14
 4213                           ; covered cases:
 4214                           ;       "*"
 4215                           ;       "dr:*"
 4216                           ;       "#"
 4217                           ;       "$"
 4218                           ;       "$dr"
 4219                           ;       "$dr:pattern=type"
 4220                           ;       "filename,type,mode" (drive #0)
 4221                           ;       "[@]dr:filename,type,mode"
 4222                           ; in:   A = channel #
 4223  F92FE3  AA               ?30:    tax                     ; check free chnl
 4224  F92FE4  B4 59                    ldy     lintab,x
 4225  F92FE6  C0 FF                    cpy     #$FF
 4226  F92FE8  F0 05                    beq     ?31             ; ok, chnl is free
 4227  F92FEA  A9 4B                    lda     #opnchn
 4228  F92FEC  4C ED 56                 jmp     chnerr
 4229  F92FEF  AE 00 E1         ?31:    ldx     cmdbuf          ; first char of cmd string
 4230  F92FF2  64 19                    stz     drvnum          ; set drive 0 as default
 4231  F92FF4  64 55                    stz     subcmd          ; default open file
 4232  F92FF6  A8                       tay                     ; channel
 4233  F92FF7  D0 30                    bne     ?36             ; not "load" channel (0)
 4234  F92FF9  E0 2A                    cpx     #'*'            ; load first program on drive 0?
 4235  F92FFB  D0 2C                    bne     ?36
 4236  F92FFD  A9 2A            ?32:    lda     #'*'            ; file = "*"
 4237  F92FFF  8F 00 E1 00              sta     cmdbuf
 4238  F93003  9C 01 E1                 stz     cmdbuf+1
 4239  F93006  A9 01                    lda     #1
 4240  F93008  85 41                    sta     cmdsiz
 4241  F9300A  A2 00                    ldx     #<cmdbuf
 4242  F9300C  86 1A                    stx     filtbl          ; file ptr
 4243  F9300E  A9 80                    lda     #$80
  Tue Jul 17 11:00:19 2018                                                                                               Page   30




 4244  F93010  85 39                    sta     pattyp
 4245  F93012  A9 00                    lda     #0
 4246  F93014  A5 19                    lda     drvnum
 4247  F93016  85 34                    sta     fildrv
 4248  F93018  A9 02                    lda     #prgtyp
 4249  F9301A  85 10                    sta     typflg          ; filter prog. type in search
 4250  F9301C  64 0F                    stz     mode            ; read mode
 4251  F9301E  A9 01                    lda     #1
 4252  F93020  85 12                    sta     f1cnt
 4253  F93022  85 13                    sta     f2cnt
 4254  F93024  64 55                    stz     subcmd          ; open file read mode
 4255  F93026  4C C4 30                 jmp     ?78
 4256  F93029  E0 24            ?36:    cpx     #'$'            ; open directory ?
 4257  F9302B  D0 1D                    bne     ?48
 4258  F9302D  98                       tya
 4259  F9302E  D0 0A                    bne     ?40             ; open directory as seq. file
 4260  F93030  20 AB 41                 jsr     prsldd          ; parse string for load directory cmd
 4261  F93033  A9 03                    lda     #lddir          ; load dir
 4262  F93035  85 55                    sta     subcmd
 4263  F93037  4C C4 30                 jmp     ?78
 4264  F9303A  88               ?40:    dey                     ; error if channel = 1
 4265  F9303B  F0 0A                    beq     ?44
 4266  F9303D  20 31 42                 jsr     simprs          ; simple parser for set drive
 4267  F93040  A9 04                    lda     #seqdir
 4268  F93042  85 55                    sta     subcmd          ; open directory as seq. file
 4269  F93044  4C C7 30                 jmp     ?80             ; no pattern here
 4270  F93047  4C 8E 3D         ?44:    jmp     e_badchn
 4271  F9304A  E0 23            ?48:    cpx     #'#'            ; open direct access?
 4272  F9304C  D0 12                    bne     ?60
 4273  F9304E  A6 41                    ldx     cmdsiz
 4274  F93050  CA                       dex                     ; #xxx is unsupported
 4275  F93051  F0 03                    beq     ?52             ; ok
 4276  F93053  4C 05 41         ?50:    jmp     e_badsyn        
 4277  F93056  C0 02            ?52:    cpy     #2
 4278  F93058  90 ED                    bcc     ?44             ; can't use ch 0 & 1
 4279  F9305A  A9 05                    lda     #damode         ; open direct access type
 4280  F9305C  85 55                    sta     subcmd
 4281  F9305E  80 67                    bra     ?80             ; no pattern for direct access type
 4282  F93060  20 66 41         ?60:    jsr     prsopn          ; parse "@dr:filename,type,mode"
 4283  F93063  A2 00                    ldx     #0
 4284  F93065  86 0F                    stx     mode            ; default read mode
 4285  F93067  86 42                    stx     <opntm          ; flag type & mode in parameters
 4286  F93069  E8                       inx
 4287  F9306A  86 0E                    stx     type            ; defaul type: seq
 4288  F9306C  E4 12                    cpx     f1cnt           ; f1cnt now hold # params
 4289  F9306E  B0 0B                    bcs     ?64             ; no parameter's
 4290  F93070  20 D0 30                 jsr     ?100            ; at least one param: check for type & mode
 4291  F93073  E8                       inx
 4292  F93074  E4 12                    cpx     f1cnt
 4293  F93076  B0 03                    bcs     ?64             ; only one parameter
 4294  F93078  20 D0 30                 jsr     ?100            ; set type & mode
 4295  F9307B  A4 0E            ?64:    ldy     type
 4296  F9307D  C0 04                    cpy     #reltyp
 4297  F9307F  F0 D2                    beq     ?50             ; error (unsupported type)
 4298  F93081  C0 05                    cpy     #partyp
 4299  F93083  F0 CE                    beq     ?50             ; error (unsupported type)
 4300  F93085  A6 52                    ldx     chnl
  Tue Jul 17 11:00:19 2018                                                                                               Page   31




 4301  F93087  E0 02                    cpx     #2
 4302  F93089  B0 0C                    bcs     ?66             ; not load / save
 4303  F9308B  86 0F                    stx     mode            ; force read on chn 0 and write on chn 1
 4304  F9308D  24 42                    bit     opntm
 4305  F9308F  30 0C                    bmi     ?68             ; type from parameter
 4306  F93091  A9 02                    lda     #prgtyp         ; set default type for load/save
 4307  F93093  85 0E                    sta     type
 4308  F93095  80 06                    bra     ?68
 4309  F93097  24 42            ?66:    bit     opntm
 4310  F93099  30 04                    bmi     ?70             ; type from param
 4311  F9309B  A9 01                    lda     #seqtyp         ; default type: seq
 4312  F9309D  85 0E            ?68:    sta     type
 4313  F9309F  A6 0F            ?70:    ldx     mode
 4314  F930A1  E0 01                    cpx     #wtmode
 4315  F930A3  D0 17                    bne     ?76
 4316  F930A5  24 39                    bit     pattyp          ; no wildcards for write
 4317  F930A7  10 05                    bpl     ?74
 4318  F930A9  A9 21            ?72:    lda     #badfn
 4319  F930AB  4C 07 41                 jmp     cmderr
 4320  F930AE  AF 00 E1 00      ?74:    lda     cmdbuf          ; check replace write mode
 4321  F930B2  C9 40                    cmp     #'@'
 4322  F930B4  D0 06                    bne     ?76
 4323  F930B6  A9 80                    lda     #$80            ; set flag replace mode
 4324  F930B8  85 E6                    sta     wrop
 4325  F930BA  A6 0F                    ldx     mode
 4326  F930BC  86 55            ?76     stx     subcmd          ; open file sub-command (read, write, append)
 4327  F930BE  E4 03                    cpx     mdmode          ; is like read mode
 4328  F930C0  D0 02                    bne     ?78
 4329  F930C2  64 55                    stz     subcmd
 4330  F930C4  20 AC 3F         ?78:    jsr     buildfn         ; build table of canonical names
 4331  F930C7  A5 55            ?80:    lda     subcmd
 4332  F930C9  0A                       asl     a
 4333  F930CA  AA                       tax
 4334  F930CB  FC F0 5A                 jsr     (opncmd,x)      ; execute open func.
 4335  F930CE  18                       clc                     ; return no error
 4336  F930CF  60                       rts
 4337                           
 4338                           ; check type & mode
 4339  F930D0  B4 1A            ?100:   ldy     filtbl,x        ; get ptr
 4340  F930D2  B9 00 E1                 lda     cmdbuf,y        ; get char
 4341  F930D5  DA                       phx
 4342  F930D6  A2 04                    ldx     #nmodes
 4343  F930D8  CA               ?102:   dex
 4344  F930D9  30 0C                    bmi     ?104            ; no valid mode
 4345  F930DB  DF 7A 5A F9              cmp     >modlst,x
 4346  F930DF  D0 F7                    bne     ?102
 4347  F930E1  86 0F                    stx     mode            ; mode found
 4348  F930E3  A9 40                    lda     #$40
 4349  F930E5  04 42                    tsb     <opntm          ; set flag mode
 4350  F930E7  A2 06            ?104:   ldx     #ntypes
 4351  F930E9  CA               ?106:   dex
 4352  F930EA  30 0C                    bmi     ?108            ; no valid type
 4353  F930EC  DF 7E 5A F9              cmp     >tplst,x
 4354  F930F0  D0 F7                    bne     ?106
 4355  F930F2  86 0E                    stx     type            ; type found
 4356  F930F4  A9 80                    lda     #$80
 4357  F930F6  04 42                    tsb     <opntm          ; set flag type
  Tue Jul 17 11:00:19 2018                                                                                               Page   32




 4358  F930F8  FA               ?108:   plx
 4359  F930F9  60                       rts
 4360                           
 4361                           ;---------------------------------------------------------------------------
 4362                           ; open file for reading subcommand
 4363                           ;---------------------------------------------------------------------------
 4364  F930FA                   opnrd:
 4365  F930FA  20 03 31                 jsr     opread          ; open an read fd
 4366  F930FD  20 AB 57                 jsr     tread           ; pre-read in read cache
 4367  F93100  64 F8                    stz     trap            ; no trap error
 4368  F93102  60                       rts
 4369                           
 4370                           ; open a read fd
 4371                           ; common routine for open read & open append
 4372  F93103                   opread:
 4373  F93103  20 97 4B                 jsr     optsch          ; init drive and set up search opt.
 4374  F93106  20 70 4A                 jsr     ffst            ; look for file entry
 4375  F93109  A5 20                    lda     filtrk
 4376  F9310B  D0 05                    bne     ?02             ; ok, file found
 4377  F9310D  A9 3E                    lda     #flntfd
 4378  F9310F  4C 07 41                 jmp     cmderr          ; file not found
 4379  F93112  A5 39            ?02:    lda     pattyp
 4380  F93114  29 07                    and     #typmsk         ; type from file
 4381  F93116  A6 0E                    ldx     type            ; del. type is invalid !!
 4382  F93118  D0 04                    bne     ?04             ; type from parameter
 4383  F9311A  85 0E                    sta     type            ; type from file
 4384  F9311C  80 09                    bra     ?06
 4385  F9311E  C5 0E            ?04:    cmp     type            ; match type from file?
 4386  F93120  F0 05                    beq     ?06             ; yes
 4387  F93122  A9 40                    lda     #mistyp         ; type mismatch
 4388  F93124  4C 07 41                 jmp     cmderr
 4389  F93127  A5 0F            ?06:    lda     mode
 4390  F93129  AA                       tax
 4391  F9312A  C9 03                    cmp     #mdmode
 4392  F9312C  F0 0B                    beq     ?08             ; open always, even splat file
 4393  F9312E  A9 20                    lda     #$20            ; this is a splat file?
 4394  F93130  24 39                    bit     pattyp
 4395  F93132  F0 05                    beq     ?08             ; no -- open
 4396  F93134  A9 29                    lda     #fsplt
 4397  F93136  4C 07 41                 jmp     cmderr          ; write file not closed
 4398  F93139  E0 02            ?08:    cpx     #apmode
 4399  F9313B  D0 0B                    bne     ?10
 4400  F9313D  A9 40                    lda     #$40
 4401  F9313F  24 39                    bit     pattyp          ; locked file?
 4402  F93141  F0 05                    beq     ?10             ; no
 4403  F93143  A9 28                    lda     #flock
 4404  F93145  4C 07 41                 jmp     cmderr          ; locked file
 4405  F93148  20 28 47         ?10:    jsr     opnrfd          ; open read fd
 4406  F9314B  A9 80                    lda     #$80
 4407  F9314D  85 F8                    sta     trap            ; trap disk error while open
 4408  F9314F  60                       rts
 4409                           
 4410                           ;---------------------------------------------------------------------------
 4411                           ; open file for writing subcommand
 4412                           ;---------------------------------------------------------------------------
 4413  F93150                   opnwr:
 4414  F93150  20 97 4B                 jsr     optsch          ; init drive and set up search opt.
  Tue Jul 17 11:00:19 2018                                                                                               Page   33




 4415  F93153  20 70 4A                 jsr     ffst            ; look for file entry
 4416  F93156  A5 20                    lda     filtrk
 4417  F93158  F0 27                    beq     ?08             ; ok, file not found: can create it
 4418  F9315A  24 E6                    bit     wrop            ; replace file?
 4419  F9315C  30 05                    bmi     ?02             ; yes
 4420  F9315E  A9 3F                    lda     #flexst
 4421  F93160  4C 07 41                 jmp     cmderr          ; file exists
 4422  F93163  A5 39            ?02:    lda     pattyp          ; splat file?
 4423  F93165  89 20                    bit     #$20
 4424  F93167  F0 05                    beq     ?04             ; no
 4425  F93169  A9 29                    lda     #fsplt
 4426  F9316B  4C 07 41                 jmp     cmderr          ; write file not closed
 4427  F9316E  29 07            ?04:    and     #typmsk         ; type from file
 4428  F93170  A6 0E                    ldx     type            ; del. type is invalid !!
 4429  F93172  D0 04                    bne     ?06             ; type from parameter
 4430  F93174  85 0E                    sta     type            ; type from file
 4431  F93176  80 0B                    bra     ?10
 4432  F93178  C5 0E            ?06:    cmp     type            ; match type from file?
 4433  F9317A  F0 07                    beq     ?10             ; yes
 4434  F9317C  A9 40                    lda     #mistyp         ; type mismatch
 4435  F9317E  4C 07 41                 jmp     cmderr
 4436  F93181  64 E6            ?08:    stz     wrop            ; create file
 4437  F93183  20 52 47         ?10:    jsr     opnwfd          ; open file for write
 4438  F93186  A6 19                    ldx     drvnum
 4439  F93188  74 68                    stz     drvfg,x
 4440  F9318A  60                       rts
 4441                           
 4442                           ;---------------------------------------------------------------------------
 4443                           ; open file for append subcommand
 4444                           ;---------------------------------------------------------------------------
 4445  F9318B                   opnap:
 4446  F9318B  20 03 31                 jsr     opread          ; first of all open an read fd
 4447  F9318E  64 E6                    stz     wrop            ; use as temp. eof flag
 4448  F93190  A5 2A                    lda     entsec          ; set dir to entry
 4449  F93192  85 09                    sta     sector
 4450  F93194  A0 28                    ldy     #dirtrk
 4451  F93196  84 08                    sty     track
 4452  F93198  A7 0A                    lda     [dirp]          ; clear flag closed file
 4453  F9319A  29 4F                    and     #$4F
 4454  F9319C  87 0A                    sta     [dirp]
 4455  F9319E  20 57 36                 jsr     wrdsec          ; update dir on disk
 4456  F931A1  A5 20                    lda     filtrk
 4457  F931A3  85 08                    sta     track           ; set up first block
 4458  F931A5  A5 25                    lda     filsec
 4459  F931A7  85 09                    sta     sector
 4460  F931A9                           ACC16
 4461  F931A9  C2 20                    rep     #PMFLAG
 4462                                   .LONGA  on
 4463                                   .MNLIST
 4464  F931AB  64 F0                    stz     wcnt            ; clear block's counter
 4465  F931AD  A6 F7                    ldx     dblfd
 4466  F931AF  B5 C6                    lda     fdblk,x
 4467  F931B1  85 94                    sta     wtmp            ; set limit for read block's #
 4468  F931B3                           ACC08
 4469  F931B3  E2 20                    sep     #PMFLAG
 4470                                   .LONGA  off
 4471                                   .MNLIST
  Tue Jul 17 11:00:19 2018                                                                                               Page   34




 4472  F931B5  20 C1 57         ?02:    jsr     wread           ; read whole track in write cache
 4473  F931B8  20 5A 56                 jsr     setwb           ; set cache ptr to right sector
 4474  F931BB                   ?04:    ACC16   
 4475  F931BB  C2 20                    rep     #PMFLAG
 4476                                   .LONGA  on
 4477                                   .MNLIST
 4478  F931BD  A5 F0                    lda     wcnt            ; update block's counter
 4479  F931BF  1A                       inc     a
 4480  F931C0  85 F0                    sta     wcnt
 4481  F931C2  C5 94                    cmp     wtmp            ; sanity check
 4482  F931C4                           ACC08
 4483  F931C4  E2 20                    sep     #PMFLAG
 4484                                   .LONGA  off
 4485                                   .MNLIST
 4486  F931C6  90 0B                    bcc     ?08             ; for now is ok
 4487  F931C8  F0 05                    beq     ?06             ; reached block's count #
 4488  F931CA  A9 2A            ?05:    lda     #bnotm  
 4489  F931CC  4C FB 56                 jmp     doserr          ; unmatch blocks count
 4490  F931CF  A9 80            ?06:    lda     #$80
 4491  F931D1  85 E6                    sta     wrop            ; signal count match
 4492  F931D3  A0 01            ?08:    ldy     #1
 4493  F931D5  B7 90                    lda     [wbuf],y        ; next sector
 4494  F931D7  A8                       tay
 4495  F931D8  A7 90                    lda     [wbuf]          ; next track
 4496  F931DA  F0 1A                    beq     ?10             ; end of file?
 4497  F931DC  84 09                    sty     sector          ; next sector
 4498  F931DE  C9 51                    cmp     #maxtrk
 4499  F931E0  B0 45                    bcs     ?15             ; invalid track in link
 4500  F931E2  C0 28                    cpy     #numsec
 4501  F931E4  B0 41                    bcs     ?15             ; invalid sector in link
 4502  F931E6  C5 08                    cmp     track           ; same track?
 4503  F931E8  85 08                    sta     track
 4504  F931EA  D0 C9                    bne     ?02             ; will read a new track 
 4505  F931EC  18                       clc
 4506  F931ED  98                       tya
 4507  F931EE  A6 19                    ldx     drvnum
 4508  F931F0  75 7C                    adc     wrtofs,x        ; sector in the same track
 4509  F931F2  85 91                    sta     wbuf+1
 4510  F931F4  80 C5                    bra     ?04             ; next data block       
 4511  F931F6  24 E6            ?10:    bit     wrop            ; here block's count should match
 4512  F931F8  10 D0                    bpl     ?05             ; unmatch
 4513  F931FA  C0 02                    cpy     #2              ; last block wrong index?
 4514  F931FC  90 30                    bcc     ?20             ; yes
 4515  F931FE  C8                       iny                     ; bump pointer
 4516  F931FF  A6 57                    ldx     lindx
 4517  F93201  94 BE                    sty     fdptr,x         ; start index for append
 4518  F93203  A5 09                    lda     sector
 4519  F93205  95 B6                    sta     fsec,x          ; current file sector
 4520  F93207  A5 08                    lda     track
 4521  F93209  95 AE                    sta     ftrk,x          ; current file track
 4522  F9320B                           ACC16
 4523  F9320B  C2 20                    rep     #PMFLAG
 4524                                   .LONGA  on
 4525                                   .MNLIST
 4526  F9320D  A5 F0                    lda     wcnt            ; append !!
 4527  F9320F  3A                       dec     a               ; one less...when close file...
 4528  F93210  A6 F7                    ldx     dblfd           ; one more block will be added
  Tue Jul 17 11:00:19 2018                                                                                               Page   35




 4529  F93212  95 C6                    sta     fdblk,x         ; store current block's count
 4530  F93214                           ACC08
 4531  F93214  E2 20                    sep     #PMFLAG
 4532                                   .LONGA  off
 4533                                   .MNLIST
 4534  F93216  A9 80                    lda     #$80            ; now set fd for write
 4535  F93218  05 57                    ora     lindx
 4536  F9321A  A6 52                    ldx     chnl
 4537  F9321C  95 59                    sta     lintab,x
 4538  F9321E  A6 57                    ldx     lindx
 4539  F93220  64 F8                    stz     trap            ; no trap error
 4540  F93222  A6 19                    ldx     drvnum
 4541  F93224  74 68                    stz     drvfg,x
 4542  F93226  60                       rts
 4543                           
 4544  F93227  85 08            ?15:    sta     track           ; invalid link
 4545  F93229  A9 2B                    lda     #invlnk
 4546  F9322B  4C FB 56                 jmp     doserr          ; invalid file link
 4547                           
 4548  F9322E  84 09            ?20:    sty     sector          ; wrong index in last block
 4549  F93230  A9 2C                    lda     #badlst
 4550  F93232  4C FB 56                 jmp     doserr
 4551                           
 4552                           ;---------------------------------------------------------------------------
 4553                           ; load directory subcommand
 4554                           ;---------------------------------------------------------------------------
 4555                           ; start directory loading function
 4556  F93235                   loaddir:
 4557  F93235  20 97 4B                 jsr     optsch          ; init drive
 4558  F93238  20 BB 47                 jsr     getrfd          ; get a free fd
 4559  F9323B  A6 52                    ldx     chnl
 4560  F9323D  B5 59                    lda     lintab,x
 4561  F9323F  09 20                    ora     #$20            ; flag dir. listing
 4562  F93241  95 59                    sta     lintab,x
 4563  F93243  20 2D 4A                 jsr     blknb           ; clear name buffer
 4564  F93246  20 3D 56                 jsr     sethdp          ; set dir header pointer
 4565  F93249  20 15 49                 jsr     setfdp          ; set buffer pointer
 4566  F9324C  A9 04                    lda     #4              ; set ptr to start of disk name
 4567  F9324E  85 0A                    sta     dirp
 4568  F93250  A0 16                    ldy     #22             ; offset 26 - copy all till start of name
 4569  F93252  B7 0A            ?02:    lda     [dirp],y
 4570  F93254  C9 A0                    cmp     #$A0
 4571  F93256  D0 02                    bne     ?04
 4572  F93258  A9 20                    lda     #' '
 4573  F9325A  99 C4 E1         ?04:    sta     nambuf+2,y
 4574  F9325D  88                       dey
 4575  F9325E  10 F2                    bpl     ?02
 4576  F93260  A9 14                    lda     #SCN_RVSON
 4577  F93262  8D C2 E1                 sta     !nambuf
 4578  F93265  A9 22                    lda     #'"'            ; send name in quotes
 4579  F93267  8D C3 E1                 sta     !nambuf+1
 4580  F9326A  8D D4 E1                 sta     !nambuf+18
 4581  F9326D  A9 20                    lda     #$20
 4582  F9326F  8D D5 E1                 sta     !nambuf+19
 4583  F93272  A0 00                    ldy     #0              ; start to fill buffer
 4584  F93274  A9 01                    lda     #1              ; put sal in buffer
 4585  F93276  AA                       tax
  Tue Jul 17 11:00:19 2018                                                                                               Page   36




 4586  F93277  97 8A                    sta     [bufp],y
 4587  F93279  C8                       iny
 4588  F9327A  A9 04                    lda     #4              ; put sah in buffer
 4589  F9327C  97 8A                    sta     [bufp],y
 4590  F9327E  C8                       iny
 4591  F9327F  8A                       txa                     ; insert fhoney links (0101)
 4592  F93280  97 8A                    sta     [bufp],y
 4593  F93282  C8                       iny
 4594  F93283  97 8A                    sta     [bufp],y
 4595  F93285  C8                       iny
 4596  F93286  A5 19                    lda     drvnum          ; put in drive #
 4597  F93288  97 8A                    sta     [bufp],y
 4598  F9328A  C8                       iny
 4599  F9328B  A9 00                    lda     #0
 4600  F9328D  97 8A                    sta     [bufp],y
 4601  F9328F  C8                       iny
 4602  F93290  20 1F 4A                 jsr     movbuf          ; get disk name (27 bytes)
 4603  F93293  88                       dey                     ; adjust (-2 bytes)...
 4604  F93294  88                       dey                     ; ...to have 32 bytes with terminator
 4605  F93295  A9 00                    lda     #0              ; terminator: end of this line
 4606  F93297  97 8A                    sta     [bufp],y
 4607  F93299  C8                       iny                     ; here will be 32
 4608  F9329A  5A                       phy
 4609  F9329B  20 70 4A                 jsr     ffst            ; start find dir entry
 4610  F9329E  7A                       ply
 4611  F9329F  64 EA                    stz     rdlst
 4612  F932A1  64 EB                    stz     rdeof
 4613  F932A3  64 E9                    stz     rdidx
 4614  F932A5  20 28 49                 jsr     dlist           ; fill buffer with first block
 4615  F932A8  4C 06 47                 jmp     savzp           ; save zp var's after starting dir search
 4616                           
 4617                           ;---------------------------------------------------------------------------
 4618                           ; open directory as seq. file subcommand
 4619                           ;---------------------------------------------------------------------------
 4620  F932AB                   opndir:
 4621  F932AB  20 97 4B                 jsr     optsch          ; init drive
 4622  F932AE  20 BB 47                 jsr     getrfd          ; get free fd
 4623  F932B1  A6 57                    ldx     lindx           ; X=fd
 4624  F932B3  A9 28                    lda     #dirtrk         ; open directory
 4625  F932B5  95 AE                    sta     ftrk,x
 4626  F932B7  74 B6                    stz     fsec,x
 4627  F932B9  A9 02                    lda     #2
 4628  F932BB  95 BE                    sta     fdptr,x         ; start of buffer
 4629  F932BD  60                       rts
 4630                           
 4631                           ;---------------------------------------------------------------------------
 4632                           ; open direct access subcommand
 4633                           ;---------------------------------------------------------------------------
 4634  F932BE                   opnblk:
 4635  F932BE  20 BB 47                 jsr     getrfd          ; get free fd
 4636  F932C1  A6 52                    ldx     chnl
 4637  F932C3  B5 59                    lda     lintab,x
 4638  F932C5  09 40                    ora     #$40            ; direct access flag
 4639  F932C7  95 59                    sta     lintab,x
 4640  F932C9  60                       rts
 4641                           
 4642                           ;---------------------------------------------------------------------------
  Tue Jul 17 11:00:19 2018                                                                                               Page   37




 4643                           ; scratch command
 4644                           ;---------------------------------------------------------------------------
 4645  F932CA                   scratch:
 4646  F932CA  20 B1 42                 jsr     fs1set          ; set type filter if any
 4647  F932CD  20 8D 41                 jsr     alldrs          ; set all drives/file ptr's
 4648  F932D0  20 AC 3F                 jsr     buildfn         ; build canonical file names
 4649  F932D3  20 97 4B                 jsr     optsch          ; init all drive's
 4650  F932D6  64 42                    stz     char            ; use as counter
 4651  F932D8  20 70 4A                 jsr     ffst            ; start search
 4652  F932DB  30 4A                    bmi     ?30             ; no match files
 4653  F932DD  64 43            ?15:    stz     image           ; flag  
 4654  F932DF  20 37 48                 jsr     tstfd           ; is an open file?
 4655  F932E2  90 1E                    bcc     ?20             ; yes - don't scratch
 4656  F932E4  A6 19                    ldx     drvnum
 4657  F932E6  A9 10                    lda     #$10
 4658  F932E8  34 68                    bit     drvfg,x
 4659  F932EA  D0 16                    bne     ?20             ; disk write protect on - skip
 4660  F932EC  A7 0A                    lda     [dirp]          ; type & flags
 4661  F932EE  10 12                    bpl     ?20             ; not properly closed - skip splat file
 4662  F932F0  89 40                    bit     #$40
 4663  F932F2  D0 0E                    bne     ?20             ; skip locked file
 4664  F932F4  29 07                    and     #typmsk         ; mask type
 4665  F932F6  C9 04                    cmp     #reltyp
 4666  F932F8  F0 08                    beq     ?20             ; skip rel files
 4667  F932FA  C9 05                    cmp     #partyp
 4668  F932FC  F0 04                    beq     ?20             ; skip part type
 4669  F932FE  A9 80                    lda     #$80            ; candidate to be deleted
 4670  F93300  85 43                    sta     image
 4671  F93302  20 5F 33         ?20:    jsr     shownam         ; show file name
 4672  F93305  24 43                    bit     image
 4673  F93307  10 16                    bpl     ?25
 4674  F93309  A9 00                    lda     #0
 4675  F9330B  87 0A                    sta     [dirp]          ; delete entry
 4676  F9330D  20 57 36                 jsr     wrdsec          ; update dir on disk
 4677  F93310  A6 16                    ldx     entfnd
 4678  F93312  B5 20                    lda     filtrk,x        ; get first t&s of file
 4679  F93314  85 08                    sta     track
 4680  F93316  B5 25                    lda     filsec,x
 4681  F93318  85 09                    sta     sector
 4682  F9331A  20 38 33                 jsr     delfil          ; delete file by links
 4683  F9331D  E6 42                    inc     char            ; update counter of scratched files
 4684  F9331F  20 2C 3B         ?25:    jsr     donemsg 
 4685  F93322  20 66 4A                 jsr     ffre            ; search next matching file
 4686  F93325  10 B6                    bpl     ?15             ; more files
 4687  F93327  A6 42            ?30:    ldx     char
 4688  F93329  8E FA E1                 stx     etrk            ; report scratched file's #
 4689  F9332C  9C FB E1                 stz     esec
 4690  F9332F  A9 01                    lda     #1
 4691  F93331  85 56                    sta     lsterr          ; not a true error
 4692  F93333  64 68                    stz     drvfg           ; invalidate all drive's
 4693  F93335  64 69                    stz     drvfg+1
 4694  F93337  60                       rts
 4695                           
 4696                           ; delete file by link
 4697                           ; track & sector first t&s of the file
 4698  F93338                   delfil:
 4699  F93338  20 AB 57                 jsr     tread           ; read whole track in cache
  Tue Jul 17 11:00:19 2018                                                                                               Page   38




 4700  F9333B  20 4A 56                 jsr     setcp           ; set cache ptr to right sector
 4701  F9333E  20 CD 4D         ?02:    jsr     frets           ; free current t&s in bam
 4702  F93341  A0 01                    ldy     #1
 4703  F93343  B7 8A                    lda     [bufp],y        ; next sector
 4704  F93345  A8                       tay
 4705  F93346  A7 8A                    lda     [bufp]          ; next track
 4706  F93348  F0 12                    beq     ?10             ; end of file
 4707  F9334A  84 09                    sty     sector          ; next sector
 4708  F9334C  C5 08                    cmp     track           ; same track?
 4709  F9334E  85 08                    sta     track
 4710  F93350  D0 E6                    bne     delfil          ; will read a new track 
 4711  F93352  18                       clc
 4712  F93353  98                       tya
 4713  F93354  A6 19                    ldx     drvnum
 4714  F93356  75 78                    adc     trkofs,x        ; sector in the same track
 4715  F93358  85 8B                    sta     bufp+1
 4716  F9335A  80 E2                    bra     ?02             ; follow link   
 4717  F9335C  4C 10 4E         ?10:    jmp     mapout          ; update & write out bam
 4718                           
 4719  F9335F                   shownam:
 4720  F9335F  20 B0 33                 jsr     movnam
 4721  F93362  D4 94                    pei     (wtmp)
 4722  F93364  A9 00                    lda     #^nambuf
 4723  F93366  48                       pha
 4724  F93367  F4 C2 E1                 pea     #!nambuf
 4725  F9336A  A5 19                    lda     drvnum
 4726  F9336C  48                       pha
 4727  F9336D  4B                       phk
 4728  F9336E  F4 77 33                 pea     #!?100
 4729  F93371  A9 0A                    lda     #10
 4730  F93373  48                       pha
 4731  F93374                           BPRINTF
 4732  F93374  02 11                    cop     $11
 4733                                   .MNLIST
 4734  F93376  60                       rts
 4735                           
 4736  F93377  0D 64 65 6C 65   ?100:   .DB     $0D, 'delete #%bu:%s (%04hu blocks):...', $00
               74 65 20 23 25 
               62 75 3A 25 73 
               20 28 25 30 34 
               68 75 20 62 6C 
               6F 63 6B 73 29 
               3A 2E 2E 2E 00 
 4737                           
 4738                           ; move directory entry to namebuf
 4739                           ; in:   X=index in file stream
 4740  F9339A                   movnamx:
 4741  F9339A  B5 34                    lda     fildrv,x        ; set directory entry
 4742  F9339C  29 01                    and     #1
 4743  F9339E  85 19                    sta     drvnum
 4744  F933A0  DA                       phx
 4745  F933A1  20 3D 56                 jsr     sethdp
 4746  F933A4  FA                       plx
 4747  F933A5  B5 2A                    lda     entsec,x
 4748  F933A7  18                       clc
 4749  F933A8  65 0B                    adc     dirp+1
 4750  F933AA  85 0B                    sta     dirp+1          ; set dir. pointer to file entry
  Tue Jul 17 11:00:19 2018                                                                                               Page   39




 4751  F933AC  B5 2F                    lda     entind,x
 4752  F933AE  85 0A                    sta     dirp
 4753                           
 4754                           ; move directory entry to namebuf 
 4755  F933B0                   movnam:
 4756  F933B0  20 2D 4A                 jsr     blknb           ; blank nambuf
 4757  F933B3  A0 1D                    ldy     #29             ;  & adjust spacing
 4758  F933B5  B7 0A                    lda     [dirp],y        ; hi blocks #
 4759  F933B7  85 95                    sta     wtmp+1
 4760  F933B9  88                       dey
 4761  F933BA  B7 0A                    lda     [dirp],y        ; low blocks #
 4762  F933BC  85 94                    sta     wtmp
 4763  F933BE  A2 00                    ldx     #0              ; file name start
 4764  F933C0  A9 22                    lda     #'"'
 4765  F933C2  8D C2 E1                 sta     !nambuf
 4766  F933C5  A0 03                    ldy     #3
 4767  F933C7  B7 0A            ?04:    lda     [dirp],y
 4768  F933C9  29 7F                    and     #$7F
 4769  F933CB  9D C3 E1                 sta     !nambuf+1,x
 4770  F933CE  E8                       inx
 4771  F933CF  C8                       iny
 4772  F933D0  E0 10                    cpx     #16
 4773  F933D2  90 F3                    bcc     ?04
 4774  F933D4  A9 22                    lda     #'"'
 4775  F933D6  9D C3 E1                 sta     !nambuf+1,x
 4776  F933D9  E8                       inx
 4777  F933DA  E8                       inx
 4778  F933DB  A7 0A                    lda     [dirp]          ; set type chars
 4779  F933DD  30 07                    bmi     ?06
 4780  F933DF  A8                       tay
 4781  F933E0  A9 2A                    lda     #'*'            ; file not closed: splat file
 4782  F933E2  9D C3 E1                 sta     !nambuf+1,x
 4783  F933E5  98                       tya
 4784  F933E6  E8               ?06:    inx
 4785  F933E7  9B                       txy                     ; Y = nambuf index
 4786  F933E8  48                       pha
 4787  F933E9  29 07                    and     #typmsk
 4788  F933EB  AA                       tax                     ; X = file type
 4789  F933EC  BF 84 5A F9              lda     >typlst,x
 4790  F933F0  99 C3 E1                 sta     nambuf+1,y
 4791  F933F3  C8                       iny
 4792  F933F4  BF 8A 5A F9              lda     >tp1lst,x
 4793  F933F8  99 C3 E1                 sta     nambuf+1,y
 4794  F933FB  C8                       iny
 4795  F933FC  BF 90 5A F9              lda     >tp2lst,x
 4796  F93400  99 C3 E1                 sta     nambuf+1,y
 4797  F93403  C8                       iny
 4798  F93404  BB                       tyx
 4799  F93405  68                       pla
 4800  F93406  0A                       asl     a
 4801  F93407  10 05                    bpl     ?08             ; file not locked
 4802  F93409  A9 3C                    lda     #'<'
 4803  F9340B  9D C3 E1                 sta     !nambuf+1,x     ; file locked
 4804  F9340E  E8               ?08:    inx
 4805  F9340F  9E C3 E1                 stz     nambuf+1,x
 4806  F93412  60                       rts
 4807                           
  Tue Jul 17 11:00:19 2018                                                                                               Page   40




 4808                           ;---------------------------------------------------------------------------
 4809                           ; new disk command (format)
 4810                           ;---------------------------------------------------------------------------
 4811                           
 4812                           ; quick format command
 4813  F93413                   quickf:
 4814  F93413  20 83 41                 jsr     onedrv          ; set just one drive/file ptr
 4815  F93416  20 AC 3F                 jsr     buildfn         ; build canonical file names
 4816  F93419  A9 C0                    lda     #$C0
 4817  F9341B  80 08                    bra     newdsk2
 4818  F9341D                           
 4819                           ; standard cbm format command
 4820  F9341D                   newdsk:
 4821  F9341D  20 83 41                 jsr     onedrv          ; set just one drive/file ptr
 4822  F93420  20 AC 3F                 jsr     buildfn         ; build canonical file names
 4823  F93423  A9 80                    lda     #$80
 4824  F93425                   newdsk2:
 4825  F93425  85 41                    sta     <qfmt           ; assume no ID disk given => quick format
 4826  F93427  A5 12                    lda     f1cnt           ; saved total count
 4827  F93429  C9 01                    cmp     #1
 4828  F9342B  F0 29                    beq     ?06             ; just disk name: quick format
 4829  F9342D  C9 02                    cmp     #2
 4830  F9342F  F0 03                    beq     ?04             ; given disk ID in filtab
 4831  F93431  4C 05 41         ?02:    jmp     e_badsyn        ; error if more data
 4832  F93434  A6 1B            ?04:    ldx     filtbl+1        ; pointer to ID string
 4833  F93436  20 55 40                 jsr     fndlmt          ; find string limit
 4834  F93439  98                       tya                     ; string size
 4835  F9343A  F0 F5                    beq     ?02             ; empty string
 4836  F9343C  C9 03                    cmp     #3
 4837  F9343E  B0 F1                    bcs     ?02             ; more than 2 char's
 4838  F93440  A6 1B                    ldx     filtbl+1
 4839  F93442  BD 00 E1                 lda     !cmdbuf,x
 4840  F93445  20 9F 35                 jsr     ?50             ; check ID char: just alphanumeric
 4841  F93448  85 42                    sta     <idch1
 4842  F9344A  BD 01 E1                 lda     !cmdbuf+1,x
 4843  F9344D  20 9F 35                 jsr     ?50
 4844  F93450  85 43                    sta     <idch2
 4845  F93452  A9 80                    lda     #$80
 4846  F93454  14 41                    trb     <qfmt           ; clear bit 7: given ID in cmd string
 4847  F93456  A5 34            ?06:    lda     fildrv
 4848  F93458  29 01                    and     #1
 4849  F9345A  85 19                    sta     drvnum
 4850  F9345C  AA                       tax
 4851  F9345D  74 68                    stz     drvfg,x         ; invalid drive
 4852  F9345F  20 B4 56                 jsr     dsktst          ; check if disk is ready
 4853  F93462  A9 10                    lda     #$10
 4854  F93464  34 68                    bit     drvfg,x         ; disk write protect on?
 4855  F93466  F0 05                    beq     ?07             ; no
 4856  F93468  A9 1A                    lda     #wpon
 4857  F9346A  4C 07 41                 jmp     cmderr  
 4858  F9346D                   ?07:    FDCGETFMT               ; query disk format
 4859  F9346D  02 30                    cop     $30
 4860  F9346F  04                       .DB     $04
 4861                                   .MNLIST
 4862  F93470  B0 17                    bcs     ?08             ; unformatted or not recognized format
 4863  F93472  98                       tya                     ; format in bit 1,0
 4864  F93473  C9 01                    cmp     #1
  Tue Jul 17 11:00:19 2018                                                                                               Page   41




 4865  F93475  D0 12                    bne     ?08             ; not the right format
 4866  F93477  20 8F 57                 jsr     sysrd           ; try to read system track
 4867  F9347A  B0 0D                    bcs     ?08             ; error reading system track
 4868  F9347C  20 3E 55                 jsr     hdrtst          ; test right dir. format
 4869  F9347F  90 11                    bcc     ?10             ; ok, can be used quick format
 4870  F93481  24 41                    bit     <qfmt
 4871  F93483  30 08                    bmi     ?09             ; no ID given
 4872  F93485  50 2B                    bvc     ?20             ; cbm standard: go to full format
 4873  F93487  80 0F                    bra     ?12             ; quick format with given ID
 4874  F93489  24 41            ?08:    bit     <qfmt           ; here quick format not possible
 4875  F9348B  10 25                    bpl     ?20             ; go to full format
 4876  F9348D  A9 4D            ?09:    lda     #fmter          ; not given disk ID
 4877  F9348F  4C 07 41                 jmp     cmderr
 4878  F93492  24 41            ?10:    bit     <qfmt
 4879  F93494  30 2E                    bmi     ?30             ; no ID given so quick format
 4880  F93496  50 0C                    bvc     ?15             ; standard cbm format: compare given ID
 4881  F93498  A5 42            ?12:    lda     <idch1          ; quick format with given ID
 4882  F9349A  9D FC E1                 sta     !dskid1,x
 4883  F9349D  A5 43                    lda     <idch2
 4884  F9349F  9D FE E1                 sta     !dskid2,x
 4885  F934A2  80 20                    bra     ?30             ; quick format
 4886  F934A4  A5 42            ?15:    lda     <idch1          ; now check given ID with disk ID
 4887  F934A6  DD FC E1                 cmp     !dskid1,x
 4888  F934A9  D0 07                    bne     ?20             ; unmatch: full format
 4889  F934AB  A5 43                    lda     <idch2
 4890  F934AD  DD FE E1                 cmp     !dskid2,x
 4891  F934B0  F0 12                    beq     ?30             ; match: quick format
 4892  F934B2  A5 42            ?20:    lda     <idch1          ; full format: start low level format
 4893  F934B4  9D FC E1                 sta     !dskid1,x       ; store given disk ID
 4894  F934B7  A5 43                    lda     <idch2
 4895  F934B9  9D FE E1                 sta     !dskid2,x
 4896  F934BC                           SCN_CR
 4897  F934BC                           SCNPRCHAR
 4898                                   .MLIST
 4899  F934BC  02 07                    cop     $07
 4900                                   .MNLIST
 4901  F934BE  0D                       .DB     $0D
 4902                                   .MNLIST
 4903  F934BF  20 E1 58                 jsr     llfmt
 4904                                   ;SCN_CR
 4905  F934C2  80 0C                    bra     ?31             ; make empty file system
 4906  F934C4  A5 19            ?30:    lda     drvnum          ; quick format
 4907  F934C6  48                       pha
 4908  F934C7  4B                       phk
 4909  F934C8  F4 2E 35                 pea     #!?40
 4910  F934CB  A9 05                    lda     #5
 4911  F934CD  48                       pha
 4912  F934CE                           BPRINTF
 4913  F934CE  02 11                    cop     $11
 4914                                   .MNLIST
 4915  F934D0  20 3D 56         ?31:    jsr     sethdp          ; make empty file system
 4916  F934D3  20 B3 35                 jsr     ?60             ; clear cache
 4917  F934D6  20 9C 4E                 jsr     newmap          ; create a new bam
 4918  F934D9  20 4C 4F                 jsr     newhdr          ; create a new header
 4919  F934DC  64 8D                    stz     bmpnt           ; ptr to new bam
 4920  F934DE  E6 0B                    inc     dirp+1          ; set up bam
 4921  F934E0                           INDEX16
  Tue Jul 17 11:00:19 2018                                                                                               Page   42




 4922  F934E0  C2 10                    rep     #PXFLAG
 4923                                   .LONGI  on
 4924                                   .MNLIST
 4925  F934E2  A0 FF 01                 ldy     #$01FF          ; transfer the new bam
 4926  F934E5  B7 8D            ?32:    lda     [bmpnt],y
 4927  F934E7  97 0A                    sta     [dirp],y
 4928  F934E9  88                       dey
 4929  F934EA  10 F9                    bpl     ?32
 4930  F934EC                           INDEX08
 4931  F934EC  E2 10                    sep     #PXFLAG
 4932                                   .LONGI  off
 4933                                   .MNLIST
 4934  F934EE  E6 0B                    inc     dirp+1          ; set up first dir block
 4935  F934F0  E6 0B                    inc     dirp+1
 4936  F934F2  A9 00                    lda     #0
 4937  F934F4  87 0A                    sta     [dirp]          ; null link
 4938  F934F6  A0 01                    ldy     #1
 4939  F934F8  3A                       dec     a
 4940  F934F9  97 0A                    sta     [dirp],y
 4941  F934FB  A4 1A                    ldy     filtbl
 4942  F934FD  B9 00 E1         ?34:    lda     cmdbuf,y
 4943  F93500  F0 0A                    beq     ?36
 4944  F93502  30 03                    bmi     ?35
 4945  F93504  C8                       iny
 4946  F93505  80 F6                    bra     ?34
 4947  F93507  A9 00            ?35:    lda     #0
 4948  F93509  99 00 E1                 sta     cmdbuf,y
 4949  F9350C  20 D7 57         ?36:    jsr     syswr           ; write out system track
 4950  F9350F  74 68                    stz     drvfg,x         ; invalidate drive
 4951  F93511  D4 94                    pei     (wtmp)
 4952  F93513  BD FE E1                 lda     !dskid2,x
 4953  F93516  48                       pha
 4954  F93517  BD FC E1                 lda     !dskid1,x
 4955  F9351A  48                       pha
 4956  F9351B  A9 00                    lda     #^cmdbuf
 4957  F9351D  48                       pha
 4958  F9351E  A9 E1                    lda     #>cmdbuf
 4959  F93520  48                       pha
 4960  F93521  A5 1A                    lda     filtbl
 4961  F93523  48                       pha
 4962  F93524  4B                       phk
 4963  F93525  F4 6A 35                 pea     #!?42
 4964  F93528  A9 0B                    lda     #11
 4965  F9352A  48                       pha
 4966  F9352B                           BPRINTF
 4967  F9352B  02 11                    cop     $11
 4968                                   .MNLIST
 4969  F9352D  60                       rts
 4970                           
 4971  F9352E  0D 51 75 69 63   ?40:    .DB     $0D, 'Quick format diskette on drive #%bu - cbm 1581 format type', 0
               6B 20 66 6F 72 
               6D 61 74 20 64 
               69 73 6B 65 74 
               74 65 20 6F 6E 
               20 64 72 69 76 
               65 20 23 25 62 
               75 20 2D 20 63 
  Tue Jul 17 11:00:19 2018                                                                                               Page   43




               62 6D 20 31 35 
               38 31 20 66 6F 
               72 6D 61 74 20 
               74 79 70 65 00 
 4972  F9356A  0D 44 69 73 6B   ?42:    .DB     $0D, 'Disk name: "%s", ID: "%c%c", total free blocks: %hu', 0
               20 6E 61 6D 65 
               3A 20 22 25 73 
               22 2C 20 49 44 
               3A 20 22 25 63 
               25 63 22 2C 20 
               74 6F 74 61 6C 
               20 66 72 65 65 
               20 62 6C 6F 63 
               6B 73 3A 20 25 
               68 75 00 
 4973                           
 4974  F9359F  C9 30            ?50:    cmp     #'0'             ; check ID
 4975  F935A1  90 0D                    bcc     ?56
 4976  F935A3  C9 3A                    cmp     #'9'+1
 4977  F935A5  90 08                    bcc     ?54
 4978  F935A7  C9 41                    cmp     #'A'
 4979  F935A9  90 05                    bcc     ?56
 4980  F935AB  C9 5B                    cmp     #'Z'+1
 4981  F935AD  B0 01                    bcs     ?56
 4982  F935AF  60               ?54:    rts
 4983  F935B0  4C 05 41         ?56:    jmp     e_badsyn        ; ID error 
 4984                           
 4985  F935B3                   ?60:    CPU16                   ; clear system cache
 4986  F935B3  C2 30                    rep     #(PMFLAG.OR.PXFLAG)
 4987                                   .LONGA  on
 4988                                   .LONGI  on
 4989                                   .MNLIST
 4990  F935B5  A0 FE 13                 ldy     #$1400-2        ; $1400 words
 4991  F935B8  A9 00 00                 lda     #0
 4992  F935BB  97 0A            ?62:    sta     [dirp],y
 4993  F935BD  88                       dey
 4994  F935BE  88                       dey
 4995  F935BF  10 FA                    bpl     ?62
 4996  F935C1                           CPU08
 4997  F935C1  E2 30                    sep     #(PMFLAG.OR.PXFLAG)
 4998                                   .LONGA  off
 4999                                   .LONGI  off
 5000                                   .MNLIST
 5001  F935C3  60                       rts
 5002                           
 5003                           ;---------------------------------------------------------------------------
 5004                           ; rename command
 5005                           ;---------------------------------------------------------------------------
 5006  F935C4                   rename:
 5007  F935C4  20 8D 41                 jsr     alldrs          ; set all drives/file ptr's
 5008  F935C7  20 AC 3F                 jsr     buildfn         ; build canonical file names
 5009  F935CA  A5 35                    lda     fildrv+1
 5010  F935CC  29 01                    and     #1
 5011  F935CE  85 35                    sta     fildrv+1
 5012  F935D0  45 34                    eor     fildrv          ; compare drive's #
 5013  F935D2  F0 05                    beq     ?01             ; ok, same drive
 5014  F935D4  A9 27                    lda     #notsam
  Tue Jul 17 11:00:19 2018                                                                                               Page   44




 5015  F935D6  4C 07 41                 jmp     cmderr          ; cannot rename across drives
 5016  F935D9  20 38 4A         ?01:    jsr     lookup          ; lookup for both file's
 5017  F935DC  20 20 36                 jsr     chkfs1          ; check fs1 and fs2
 5018  F935DF  A2 01                    ldx     #1              ; check file name 2 not open
 5019  F935E1  20 28 48                 jsr     tstopn          ; cannot rename an open file
 5020  F935E4  A5 2B                    lda     entsec+1        ; set sector of dir entry for file 2
 5021  F935E6  85 09                    sta     sector
 5022  F935E8  20 C3 4C                 jsr     setdptr         ; set ptr to dir cache
 5023  F935EB  A5 30                    lda     entind+1        ; set pointer to entry
 5024  F935ED  85 0A                    sta     dirp
 5025  F935EF  A7 0A                    lda     [dirp]          ; get type and flags
 5026  F935F1  89 40                    bit     #$40
 5027  F935F3  D0 0F                    bne     ?04             ; locked file
 5028  F935F5  A6 1A                    ldx     filtbl          ; pointer to file 1 name
 5029  F935F7  A0 03                    ldy     #3              ; pointer to file name on dir entry
 5030  F935F9  BD 00 E1         ?02:    lda     !cmdbuf,x       ; move new file name
 5031  F935FC  F0 59                    beq     wrdsec          ; end -- write out sector
 5032  F935FE  97 0A                    sta     [dirp],y
 5033  F93600  E8                       inx
 5034  F93601  C8                       iny
 5035  F93602  80 F5                    bra     ?02
 5036                           
 5037  F93604  A9 28            ?04:    lda     #flock
 5038  F93606  4C 07 41                 jmp     cmderr
 5039  F93609                           
 5040                           ; check file 2 stream for existence (all should exist)
 5041  F93609                   chkfs2:
 5042  F93609  A5 3A                    lda     pattyp+1        ; 1st file bears type
 5043  F9360B  29 07                    and     #typmsk
 5044  F9360D  85 0E                    sta     type
 5045  F9360F  A6 13                    ldx     f2cnt
 5046  F93611  CA               ?10:    dex
 5047  F93612  E4 12                    cpx     f1cnt
 5048  F93614  90 09                    bcc     ?20             ; skip file in fs1 stream
 5049  F93616  B5 20                    lda     filtrk,x
 5050  F93618  D0 F7                    bne     ?10             ; ok, exist - check next
 5051  F9361A  A9 3E                    lda     #flntfd         ; input file not found
 5052  F9361C  4C 07 41                 jmp     cmderr
 5053  F9361F  60               ?20:    rts
 5054                           
 5055                           ; check file 1 stream for non-existence (all should not exist)
 5056  F93620                   chkfs1:
 5057  F93620  20 09 36                 jsr     chkfs2          ; check fs 2 stream for existence
 5058  F93623  B5 20            ?25:    lda     filtrk,x        ; check fs1 stream
 5059  F93625  F0 05                    beq     ?30
 5060  F93627  A9 3F                    lda     #flexst         ; file exist
 5061  F93629  4C 07 41                 jmp     cmderr
 5062  F9362C  CA               ?30:    dex                     ; check next file
 5063  F9362D  10 F4                    bpl     ?25
 5064  F9362F  60                       rts
 5065                           
 5066                           ;---------------------------------------------------------------------------
 5067                           ; exist command - check file existance
 5068                           ;---------------------------------------------------------------------------
 5069  F93630                   exist:
 5070  F93630  20 83 41                 jsr     onedrv          ; set just one drive/file ptr
 5071  F93633  20 AC 3F                 jsr     buildfn         ; build canonical file names
  Tue Jul 17 11:00:19 2018                                                                                               Page   45




 5072  F93636  20 38 4A                 jsr     lookup          ; lookup for file
 5073  F93639  A5 20                    lda     filtrk
 5074  F9363B  D0 2F                    bne     gtx             ; ok
 5075  F9363D  A9 3E                    lda     #flntfd
 5076  F9363F  4C 07 41                 jmp     cmderr
 5077                           
 5078                           ;---------------------------------------------------------------------------
 5079                           ; lock command - set lock bit in file type (set read only file)
 5080                           ;---------------------------------------------------------------------------
 5081  F93642                   lock:
 5082  F93642  20 5C 36                 jsr     gettyp          ; set dir entry ptr & get file type
 5083  F93645  89 40                    bit     #$40            ; test lock bit
 5084  F93647  D0 23                    bne     gtx             ; already locked, done
 5085  F93649  A8                       tay                     ; save type
 5086  F9364A  20 6D 36                 jsr     wptst           ; check if write protect
 5087  F9364D  A2 00                    ldx     #0              ; check file not open
 5088  F9364F  20 28 48                 jsr     tstopn          ; cannot do in an open file
 5089  F93652  98                       tya                     ; restore type
 5090  F93653  09 40                    ora     #$40            ; set lock bit
 5091  F93655  87 0A                    sta     [dirp]
 5092  F93657                           
 5093                                   ; write out sector
 5094                           
 5095                           ; write given directory sector on disk
 5096  F93657                   wrdsec:
 5097  F93657  A9 01                    lda     #1              ; write out just 1 sec
 5098  F93659  4C 11 58                 jmp     wrsys
 5099                           
 5100                           ; find file, set dir pointer, get file type & flag
 5101  F9365C                   gettyp:
 5102  F9365C  20 30 36                 jsr     exist           ; file exist in dir entry?
 5103  F9365F  A5 2A                    lda     entsec          ; set sector of dir entry
 5104  F93661  85 09                    sta     sector
 5105  F93663  20 C3 4C                 jsr     setdptr         ; set ptr to dir cache
 5106  F93666  A5 2F                    lda     entind          ; set pointer to entry
 5107  F93668  85 0A                    sta     dirp
 5108  F9366A  A7 0A                    lda     [dirp]          ; get type and flags
 5109  F9366C  60               gtx:    rts
 5110                           
 5111                           ; abort if disk is write protect
 5112  F9366D                   wptst:
 5113  F9366D  A6 19                    ldx     drvnum
 5114  F9366F  A9 10                    lda     #$10
 5115  F93671  34 68                    bit     drvfg,x
 5116  F93673  F0 F7                    beq     gtx             ; ok, no write protect
 5117  F93675  A9 1A                    lda     #wpon           ; write protect on
 5118  F93677  4C F5 56                 jmp     drverr
 5119                           
 5120                           ;---------------------------------------------------------------------------
 5121                           ; unlock command - clear lock bit in file type
 5122                           ;---------------------------------------------------------------------------
 5123  F9367A                   unlock:
 5124  F9367A  20 5C 36                 jsr     gettyp          ; set dir entry ptr & get file type
 5125  F9367D  89 40                    bit     #$40            ; test lock bit
 5126  F9367F  F0 EB                    beq     gtx             ; already unlocked, done
 5127  F93681  A8                       tay                     ; save type
 5128  F93682  20 6D 36                 jsr     wptst           ; check if write protect
  Tue Jul 17 11:00:19 2018                                                                                               Page   46




 5129  F93685  A2 00                    ldx     #0              ; check file not open
 5130  F93687  20 28 48                 jsr     tstopn          ; cannot do in an open file
 5131  F9368A  98                       tya                     ; restore type
 5132  F9368B  29 BF                    and     #$BF            ; reset lock bit
 5133  F9368D  87 0A                    sta     [dirp]
 5134  F9368F  80 C6                    bra     wrdsec          ; write out sector
 5135                           
 5136                           ;---------------------------------------------------------------------------
 5137                           ; transfer command (copy file from ibm-dos disk)
 5138                           ;---------------------------------------------------------------------------
 5139  F93691                   transf:
 5140  F93691  A9 40                    lda     #$40
 5141  F93693  85 35                    sta     fildrv+1        ; source drive is dos drive !
 5142  F93695  20 8D 41                 jsr     alldrs
 5143  F93698  A5 35                    lda     fildrv+1        ; dos drive will be in command string
 5144  F9369A  30 06                    bmi     ?02             ; no drive in cmd string
 5145  F9369C  29 07                    and     #7
 5146  F9369E  C5 34                    cmp     fildrv          ; will be not the same
 5147  F936A0  D0 03                    bne     ?04             ; ok
 5148  F936A2  4C 89 3D         ?02:    jmp     e_baddrv
 5149  F936A5  20 AC 3F         ?04:    jsr     buildfn         ; build canonical file names
 5150  F936A8  A9 40                    lda     #$40
 5151  F936AA  14 35                    trb     fildrv+1
 5152  F936AC  60                       rts
 5153                           
 5154                           ;---------------------------------------------------------------------------
 5155                           ; move command (copy file to ibm-dos disk)
 5156                           ;---------------------------------------------------------------------------
 5157  F936AD                   move:
 5158  F936AD  A9 40                    lda     #$40
 5159  F936AF  85 34                    sta     fildrv          ; dest drive is dos drive !
 5160  F936B1  20 8D 41                 jsr     alldrs
 5161  F936B4  A5 35                    lda     fildrv+1        ; cbm drive will be in command string
 5162  F936B6  30 08                    bmi     ?02             ; no drive in cmd string
 5163  F936B8  A5 34                    lda     fildrv
 5164  F936BA  29 07                    and     #7
 5165  F936BC  C5 35                    cmp     fildrv+1        ; will not be the same
 5166  F936BE  D0 03                    bne     ?04             ; ok
 5167  F936C0  4C 89 3D         ?02:    jmp     e_baddrv
 5168  F936C3  20 AC 3F         ?04:    jsr     buildfn         ; build canonical file names
 5169  F936C6  A9 40                    lda     #$40
 5170  F936C8  14 34                    trb     fildrv
 5171  F936CA  60                       rts
 5172                           
 5173                           ;---------------------------------------------------------------------------
 5174                           ; append command
 5175                           ;---------------------------------------------------------------------------
 5176  F936CB                   append:
 5177  F936CB  20 8D 41                 jsr     alldrs          ; set all drives/file ptr's
 5178  F936CE  20 AC 3F                 jsr     buildfn         ; build canonical file names
 5179  F936D1  A9 40                    lda      #$40
 5180  F936D3  85 55                    sta     subcmd          ; flag concat
 5181  F936D5  20 38 4A                 jsr     lookup          ; look up all files
 5182  F936D8  A6 34                    ldx     fildrv          ; test if dest drive is wp on
 5183  F936DA  A9 10                    lda     #$10
 5184  F936DC  34 68                    bit     drvfg,x
 5185  F936DE  F0 05                    beq     ?04
  Tue Jul 17 11:00:19 2018                                                                                               Page   47




 5186  F936E0  A9 1A                    lda     #wpon
 5187  F936E2  4C 07 41                 jmp     cmderr
 5188  F936E5  A5 20            ?04:    lda     filtrk
 5189  F936E7  D0 05                    bne     ?06             ; ok, dest file exist
 5190  F936E9  A9 3E                    lda     #flntfd
 5191  F936EB  4C 07 41                 jmp     cmderr
 5192  F936EE  A2 00            ?06:    ldx     #0              ; dest file will not be open
 5193  F936F0  20 28 48                 jsr     tstopn
 5194  F936F3  A2 01                    ldx     #1
 5195  F936F5  20 FE 37                 jsr     tstdup          ; check recursive concat
 5196  F936F8  20 09 36                 jsr     chkfs2          ; check if fs2 exist
 5197  F936FB  20 ED 37                 jsr     tstfs2          ; check not open
 5198  F936FE  A6 13                    ldx     f2cnt           ; fs1 & fs2 seq type only
 5199  F93700  CA               ?08:    dex                     ; index
 5200  F93701  30 18                    bmi     ?14
 5201  F93703  B5 39                    lda     pattyp,x
 5202  F93705  89 20                    bit     #$20
 5203  F93707  D0 0D                    bne     ?12             ; error: splat file
 5204  F93709  29 07                    and     #typmsk
 5205  F9370B  C9 01                    cmp     #seqtyp
 5206  F9370D  D0 02                    bne     ?10             ; error: mismatch type
 5207  F9370F  80 EF                    bra     ?08
 5208  F93711  A9 40            ?10:    lda     #mistyp         ; file type mismatch
 5209  F93713  4C 07 41                 jmp     cmderr
 5210  F93716  A9 29            ?12:    lda     #fsplt          ; error: write file not closed
 5211  F93718  4C 07 41                 jmp     cmderr  
 5212  F9371B  A5 39            ?14:    lda     pattyp          ; dest file is locked?
 5213  F9371D  89 40                    bit     #$40
 5214  F9371F  F0 05                    beq     ?16             ; no
 5215  F93721  A9 28                    lda     #flock          ; error: locked file
 5216  F93723  4C 07 41                 jmp     cmderr
 5217  F93726  29 07            ?16:    and     #typmsk
 5218  F93728  85 0E                    sta     type
 5219  F9372A  20 1D 38                 jsr     movdst          ; set up dest file name
 5220  F9372D  20 EE 39                 jsr     skend           ; seek end: prepare for append
 5221  F93730  A2 01                    ldx     #1
 5222  F93732  20 3A 39                 jsr     cat             ; concat fs2 to fs1
 5223  F93735  A6 34                    ldx     fildrv          ; invalidate dest drive...
 5224  F93737  74 68                    stz     drvfg,x         ; ...so force init next time
 5225  F93739  60                       rts
 5226                           
 5227                           ;---------------------------------------------------------------------------
 5228                           ; copy command
 5229                           ;
 5230                           ;       Cddr=sdr                ; copy all files from sdr to ddr (not same dr)
 5231                           ;       Cddr:[*]=sdr:[*]        ; copy all files from sdr to ddr (not same dr)
 5232                           ;       Cddr:[*]=sdr:fname      ; copy sdr:fname to ddr:fname (not same drive)
 5233                           ;       Cddr:dest=[sdr:]fname   ; copy sdr:fname to ddr:dest
 5234                           ;       Cddr:dest=[sdr1:]fname1,[sdr2:]fname2,[sdr3:]fname3,[sdr4:]fname4
 5235                           ;---------------------------------------------------------------------------
 5236  F9373A                   copy:
 5237  F9373A  20 6E 40                 jsr     prscpy          ; parse cmd string
 5238  F9373D  20 AC 3F                 jsr     buildfn         ; build canonical file names
 5239  F93740  24 39                    bit     pattyp          ; dest file is '*' ?
 5240  F93742  10 03                    bpl     ?02
 5241  F93744  4C 3D 38                 jmp     cpall           ; yes - copy disk-to-disk
 5242  F93747  64 55            ?02:    stz     subcmd          ; flag copy+cat
  Tue Jul 17 11:00:19 2018                                                                                               Page   48




 5243  F93749  20 38 4A                 jsr     lookup          ; look up all files
 5244  F9374C  A6 34                    ldx     fildrv          ; test if dest drive is wp on
 5245  F9374E  A9 10                    lda     #$10
 5246  F93750  34 68                    bit     drvfg,x
 5247  F93752  F0 05                    beq     ?04
 5248  F93754  A9 1A                    lda     #wpon
 5249  F93756  4C 07 41                 jmp     cmderr
 5250  F93759  A5 13            ?04:    lda     f2cnt
 5251  F9375B  C9 03                    cmp     #3              ; just copy f2 to f1?
 5252  F9375D  90 4B                    bcc     ?20             ; yes
 5253  F9375F  A5 35                    lda     fildrv+1        ; now test if first file of fs2 stream...
 5254  F93761  29 01                    and     #1
 5255  F93763  C5 34                    cmp     fildrv          ; ...is the same of the file on fs1 stream
 5256  F93765  D0 43                    bne     ?20             ; must create dest file
 5257  F93767  A5 2F                    lda     entind
 5258  F93769  C5 30                    cmp     entind+1
 5259  F9376B  D0 3D                    bne     ?20             ; must create dest file
 5260  F9376D  A5 2A                    lda     entsec
 5261  F9376F  C5 2B                    cmp     entsec+1
 5262  F93771  D0 37                    bne     ?20             ; must create dest file
 5263                           
 5264                                   ; file1=file2 so append file3,file4... to file1         
 5265                                   ; all files in fs2 stream will exist and will not be open
 5266  F93773  A2 02                    ldx     #2
 5267  F93775  20 FE 37                 jsr     tstdup          ; check recursive concat
 5268  F93778  20 09 36                 jsr     chkfs2          ; check if fs2 exist
 5269  F9377B  20 ED 37                 jsr     tstfs2          ; check not open
 5270  F9377E  A5 0E                    lda     type            ; this is file1=file2 type
 5271  F93780  C9 01                    cmp     #seqtyp         ; just seq. tipe can be concat.
 5272  F93782  F0 05                    beq     ?06
 5273  F93784  A9 40            ?05:    lda     #mistyp         ; file type mismatch
 5274  F93786  4C 07 41                 jmp     cmderr
 5275  F93789  20 1D 38         ?06:    jsr     movdst          ; set up dest file name
 5276  F9378C  A5 39                    lda     pattyp          ; dest file is locked?
 5277  F9378E  89 40                    bit     #$40
 5278  F93790  F0 05                    beq     ?08             ; no
 5279  F93792  A9 28                    lda     #flock          ; error: locked file
 5280  F93794  4C 07 41                 jmp     cmderr
 5281  F93797  89 20            ?08:    bit     #$20            ; splat file?
 5282  F93799  F0 05                    beq     ?10             ; no
 5283  F9379B  A9 29            ?09:    lda     #fsplt          ; error: write file not closed
 5284  F9379D  4C 07 41                 jmp     cmderr  
 5285  F937A0  20 D3 37         ?10:    jsr     ?70             ; check all files f3..fn (seq type, no splat)   
 5286  F937A3  20 EE 39                 jsr     skend           ; seek end: prepare for append
 5287  F937A6  A2 02                    ldx     #2
 5288  F937A8  80 21                    bra     ?24
 5289                           
 5290                           ?20:    ; file1 should be created, then copy file2 to file1 and concat...
 5291                                   ; ...file3,file4... to file1 (if type is seq)
 5292  F937AA  20 20 36                 jsr     chkfs1          ; fs1 should not exist, fs2 all should exist
 5293  F937AD  20 ED 37                 jsr     tstfs2          ; check fs2 not open
 5294  F937B0  20 1D 38                 jsr     movdst          ; set up dest file name
 5295  F937B3  A5 3A                    lda     pattyp+1
 5296  F937B5  89 20                    bit     #$20            ; file1 will not be splat
 5297  F937B7  D0 E2                    bne     ?09             ; error: source file is splat file
 5298  F937B9  29 07                    and     #typmsk 
 5299  F937BB  C9 04                    cmp     #reltyp
  Tue Jul 17 11:00:19 2018                                                                                               Page   49




 5300  F937BD  F0 C5                    beq     ?05             ; skip rel files
 5301  F937BF  C9 05                    cmp     #partyp
 5302  F937C1  F0 C1                    beq     ?05             ; skip part type
 5303  F937C3  20 D3 37                 jsr     ?70             ; check all files f3..fn (seq type, no splat)
 5304  F937C6  20 93 39                 jsr     setwrf          ; ok, create dest file
 5305  F937C9  A2 01                    ldx     #1
 5306  F937CB  20 3A 39         ?24:    jsr     cat             ; copy/concat
 5307  F937CE  A6 34                    ldx     fildrv          ; invalidate dest drive...
 5308  F937D0  74 68                    stz     drvfg,x         ; ...so force init next time
 5309  F937D2  60                       rts
 5310                           
 5311                           ?70:    ; check f3..fn: must be just seq. type and no splat
 5312  F937D3  A6 13                    ldx     f2cnt
 5313  F937D5  E0 03                    cpx     #3
 5314  F937D7  90 13                    bcc     ?74             ; skip this test if just 2 files
 5315  F937D9  CA               ?72:    dex                     ; index
 5316  F937DA  E0 02                    cpx     #2
 5317  F937DC  90 0E                    bcc     ?74
 5318  F937DE  B5 39                    lda     pattyp,x
 5319  F937E0  89 20                    bit     #$20
 5320  F937E2  D0 B7                    bne     ?09             ; error: splat file
 5321  F937E4  29 07                    and     #typmsk
 5322  F937E6  C9 01                    cmp     #seqtyp
 5323  F937E8  D0 9A                    bne     ?05             ; error: mismatch type
 5324  F937EA  80 ED                    bra     ?72
 5325  F937EC  60               ?74:    rts
 5326                           
 5327                           ; check file 2 stream for open (all should not be open) (80)
 5328  F937ED                   tstfs2:
 5329  F937ED  A6 13                    ldx     f2cnt
 5330  F937EF  CA               ?82:    dex
 5331  F937F0  E4 12                    cpx     f1cnt
 5332  F937F2  90 09                    bcc     ?84             ; skip file in fs1 stream
 5333  F937F4  86 16                    stx     entfnd
 5334  F937F6  20 28 48                 jsr     tstopn
 5335  F937F9  A6 16                    ldx     entfnd
 5336  F937FB  80 F2                    bra     ?82
 5337  F937FD  60               ?84:    rts
 5338                           
 5339                           ; in fs2 stream will not be th dest file
 5340                           ; in:   X=index of start test
 5341  F937FE                   tstdup:
 5342  F937FE  B5 34                    lda     fildrv,x
 5343  F93800  29 01                    and     #1
 5344  F93802  C5 34                    cmp     fildrv
 5345  F93804  D0 0C                    bne     ?06
 5346  F93806  B5 20                    lda     filtrk,x
 5347  F93808  C5 20                    cmp     filtrk
 5348  F9380A  D0 06                    bne     ?06
 5349  F9380C  B5 25                    lda     filsec,x
 5350  F9380E  C5 25                    cmp     filsec
 5351  F93810  F0 06                    beq     ?10             ; match
 5352  F93812  E8               ?06:    inx
 5353  F93813  E4 13                    cpx     f2cnt
 5354  F93815  90 E7                    bcc     tstdup
 5355  F93817  60                       rts
 5356  F93818  A9 52            ?10:    lda     #badcat         ; recursive concat
  Tue Jul 17 11:00:19 2018                                                                                               Page   50




 5357  F9381A  4C 07 41                 jmp     cmderr
 5358                           
 5359                           ; move first file name to namebuf2 (90)
 5360  F9381D                   movdst:
 5361  F9381D  A2 00                    ldx     #0              ; file name start
 5362  F9381F  A9 22                    lda     #'"'
 5363  F93821  8D DD E1                 sta     !nambuf2
 5364  F93824  A4 1A                    ldy     filtbl
 5365  F93826  B9 00 E1         ?94:    lda     !cmdbuf,y
 5366  F93829  29 7F                    and     #$7F
 5367  F9382B  9D DE E1                 sta     !nambuf2+1,x
 5368  F9382E  E8                       inx
 5369  F9382F  C8                       iny
 5370  F93830  E0 10                    cpx     #16
 5371  F93832  90 F2                    bcc     ?94
 5372  F93834  A9 22                    lda     #'"'
 5373  F93836  9D DE E1                 sta     !nambuf2+1,x
 5374  F93839  9E DF E1                 stz     !nambuf2+2,x
 5375  F9383C  60                       rts
 5376                           
 5377                           ; copy disk-to-disk (with pattern, no concat)
 5378  F9383D                   cpall:
 5379  F9383D  A9 80                    lda     #$80
 5380  F9383F  85 55                    sta     subcmd          ; flag disk-to-disk copy
 5381  F93841  A5 34                    lda     fildrv
 5382  F93843  29 01                    and     #1
 5383  F93845  85 34                    sta     fildrv
 5384  F93847  85 36                    sta     fildrv+2        ; save dest drive
 5385  F93849  A5 35                    lda     fildrv+1
 5386  F9384B  29 01                    and     #1
 5387  F9384D  85 35                    sta     fildrv+1
 5388  F9384F  A5 1A                    lda     filtbl
 5389  F93851  85 1C                    sta     filtbl+2        ; save file name 1 ptr
 5390  F93853  20 97 4B                 jsr     optsch          ; init all drive's
 5391  F93856  64 18                    stz     tgflg           ; search just one drive
 5392  F93858  A5 35                    lda     fildrv+1
 5393  F9385A  85 19                    sta     drvnum          ; search just in src. drive
 5394  F9385C  85 34                    sta     fildrv
 5395  F9385E  A5 1B                    lda     filtbl+1
 5396  F93860  85 1A                    sta     filtbl
 5397  F93862  A9 01                    lda     #1
 5398  F93864  85 12                    sta     f1cnt
 5399  F93866  85 13                    sta     f2cnt           ; fake: just one file in stream!
 5400  F93868  20 70 4A                 jsr     ffst            ; start search on src drive
 5401  F9386B  30 3B                    bmi     ?20             ; no files
 5402  F9386D  64 43            ?02:    stz     image           ; flag
 5403  F9386F  64 16                    stz     entfnd          ; file is in fs1 stream!
 5404  F93871  20 37 48                 jsr     tstfd           ; is an open file?
 5405  F93874  90 1C                    bcc     ?04             ; yes - don't copy
 5406  F93876  A6 36                    ldx     fildrv+2
 5407  F93878  A9 10                    lda     #$10
 5408  F9387A  34 68                    bit     drvfg,x
 5409  F9387C  D0 14                    bne     ?04             ; dest disk write protect on - skip     
 5410  F9387E  A7 0A                    lda     [dirp]          ; type & flags
 5411  F93880  85 3C                    sta     pattyp+3
 5412  F93882  10 0E                    bpl     ?04             ; not properly closed - skip splat file
 5413  F93884  29 07                    and     #typmsk         ; mask type
  Tue Jul 17 11:00:19 2018                                                                                               Page   51




 5414  F93886  C9 04                    cmp     #reltyp
 5415  F93888  F0 08                    beq     ?04             ; skip rel files
 5416  F9388A  C9 05                    cmp     #partyp
 5417  F9388C  F0 04                    beq     ?04             ; skip part type
 5418  F9388E  A9 80                    lda     #$80            ; candidate to be copied
 5419  F93890  85 43                    sta     image
 5420  F93892  20 C6 38         ?04:    jsr     ?50             ; lookup dest drive for file
 5421  F93895  A2 01                    ldx     #1              ; set up one read file
 5422  F93897  86 15                    stx     f2ptr
 5423  F93899  20 A9 38                 jsr     ?30             ; create & copy
 5424  F9389C  20 21 39         ?10:    jsr     ?80             ; set back search data for src drive    
 5425  F9389F  20 66 4A                 jsr     ffre            ; search next matching file
 5426  F938A2  10 C9                    bpl     ?02             ; more files
 5427  F938A4  A6 36                    ldx     fildrv+2        ; invalidate dest drive...
 5428  F938A6  74 68                    stz     drvfg,x         ; ...so force init next time
 5429  F938A8  60               ?20:    rts
 5430                           
 5431                                   ; create dest file and copy one file
 5432  F938A9  20 56 3A         ?30:    jsr     cpymsg          ; show message
 5433  F938AC  24 43                    bit     image           ; skip?
 5434  F938AE  10 13                    bpl     ?34             ; yes
 5435  F938B0  20 93 39                 jsr     setwrf          ; setup write file (create)
 5436  F938B3  20 C2 39                 jsr     setrdf          ; setup read file
 5437  F938B6  20 B8 45         ?32:    jsr     bufget          ; loop copy (buffered)
 5438  F938B9  20 08 46                 jsr     bufput
 5439  F938BC  A5 EB                    lda     rdeof
 5440  F938BE  F0 F6                    beq     ?32             ; no eof
 5441  F938C0  20 5D 39                 jsr     clswrf          ; close dest file
 5442  F938C3  4C 2C 3B         ?34:    jmp     donemsg
 5443                           
 5444  F938C6  20 B0 33         ?50:    jsr     movnam          ; fill name buffer with src file
 5445  F938C9  24 43                    bit     image
 5446  F938CB  10 53                    bpl     ?54             ; skip this file
 5447  F938CD  A5 20                    lda     filtrk          ; save search data for file name 2
 5448  F938CF  85 21                    sta     filtrk+1
 5449  F938D1  A5 25                    lda     filsec
 5450  F938D3  85 26                    sta     filsec+1
 5451  F938D5  A5 2A                    lda     entsec
 5452  F938D7  85 2B                    sta     entsec+1
 5453  F938D9  A5 2F                    lda     entind
 5454  F938DB  85 30                    sta     entind+1
 5455  F938DD  A5 39                    lda     pattyp
 5456  F938DF  85 3A                    sta     pattyp+1
 5457  F938E1  64 20                    stz     filtrk          ; set search data for file name 1
 5458  F938E3  64 25                    stz     filsec
 5459  F938E5  64 2A                    stz     entsec
 5460  F938E7  64 2F                    stz     entind
 5461  F938E9  64 39                    stz     pattyp
 5462  F938EB  A5 36                    lda     fildrv+2        ; restore dest drive
 5463  F938ED  85 34                    sta     fildrv
 5464  F938EF  85 19                    sta     drvnum
 5465  F938F1  A6 1C                    ldx     filtbl+2        ; restore file name 1 ptr
 5466  F938F3  86 1A                    stx     filtbl
 5467  F938F5  A0 03                    ldy     #3              ; move the entry name to file name 1
 5468  F938F7  B7 0A            ?52:    lda     [dirp],y
 5469  F938F9  9D 00 E1                 sta     !cmdbuf,x
 5470  F938FC  E8                       inx
  Tue Jul 17 11:00:19 2018                                                                                               Page   52




 5471  F938FD  C8                       iny
 5472  F938FE  C0 13                    cpy     #19
 5473  F93900  90 F5                    bcc     ?52
 5474  F93902  A9 01                    lda     #1              ; now lookup file name on dest drv
 5475  F93904  85 12                    sta     f1cnt
 5476  F93906  85 13                    sta     f2cnt           ; fake: just one file in stream!
 5477  F93908  20 3B 4A                 jsr     lookup2
 5478  F9390B  A9 01                    lda     #1              ; restore real situation
 5479  F9390D  85 12                    sta     f1cnt
 5480  F9390F  1A                       inc     a
 5481  F93910  85 13                    sta     f2cnt
 5482  F93912  A5 3C                    lda     pattyp+3
 5483  F93914  29 07                    and     #typmsk
 5484  F93916  85 0E                    sta     type            ; file type for copied file
 5485  F93918  A5 20                    lda     filtrk          ; check if dest file already exist
 5486  F9391A  F0 04                    beq     ?54             ; ok
 5487  F9391C  64 43                    stz     image           ; can't copy this file
 5488  F9391E  64 0E                    stz     type
 5489  F93920  60               ?54:    rts
 5490                           
 5491  F93921  64 20            ?80:    stz     filtrk          ; set search data for file name 2
 5492  F93923  64 25                    stz     filsec
 5493  F93925  64 2A                    stz     entsec
 5494  F93927  64 2F                    stz     entind
 5495  F93929  A5 35                    lda     fildrv+1
 5496  F9392B  85 19                    sta     drvnum          ; search in src. drive
 5497  F9392D  85 34                    sta     fildrv
 5498  F9392F  A5 1B                    lda     filtbl+1
 5499  F93931  85 1A                    sta     filtbl
 5500  F93933  A9 01                    lda     #1
 5501  F93935  85 12                    sta     f1cnt
 5502  F93937  85 13                    sta     f2cnt           ; fake: just one file in stream!
 5503  F93939  60                       rts
 5504                           
 5505                           ; copy/concat
 5506                           ; in:   X=index of first file to concat
 5507  F9393A                   cat:
 5508  F9393A  A9 80                    lda     #$80
 5509  F9393C  85 43                    sta     image           ; assume all good
 5510  F9393E  86 15            ?102:   stx     f2ptr           ; start file
 5511  F93940  20 9A 33                 jsr     movnamx         ; set up file name in nambuf
 5512  F93943  20 56 3A                 jsr     cpymsg          ; show message
 5513  F93946  20 C2 39                 jsr     setrdf          ; setup read file
 5514  F93949  20 B8 45         ?104:   jsr     bufget          ; loop copy
 5515  F9394C  20 08 46                 jsr     bufput
 5516  F9394F  A5 EB                    lda     rdeof
 5517  F93951  F0 F6                    beq     ?104            ; no eof
 5518  F93953  20 2C 3B                 jsr     donemsg
 5519  F93956  A6 15                    ldx     f2ptr           ; concat more file, if any
 5520  F93958  E8                       inx
 5521  F93959  E4 13                    cpx     f2cnt
 5522  F9395B  90 E1                    bcc     ?102            ; append
 5523                                   ;jmp    clswrf
 5524                           
 5525                           ; close write file when finish to copy
 5526  F9395D                   clswrf:
 5527  F9395D  A5 2A                    lda     entsec          ; set dir. ptr to dest file
  Tue Jul 17 11:00:19 2018                                                                                               Page   53




 5528  F9395F  85 09                    sta     sector
 5529  F93961  A0 28                    ldy     #dirtrk
 5530  F93963  84 08                    sty     track
 5531  F93965  A6 EC                    ldx     wrdrv
 5532  F93967  86 19                    stx     drvnum
 5533  F93969  20 3D 56                 jsr     sethdp
 5534  F9396C  18                       clc
 5535  F9396D  65 09                    adc     sector
 5536  F9396F  85 0B                    sta     dirp+1          ; set dir. pointer to file entry
 5537  F93971  A5 2F                    lda     entind
 5538  F93973  85 0A                    sta     dirp
 5539  F93975  A7 0A                    lda     [dirp]          ; set flag closed file
 5540  F93977  09 80                    ora     #$80
 5541  F93979  87 0A                    sta     [dirp]
 5542  F9397B  A0 1C                    ldy     #28             ; store block's #
 5543  F9397D                           ACC16
 5544  F9397D  C2 20                    rep     #PMFLAG
 5545                                   .LONGA  on
 5546                                   .MNLIST
 5547  F9397F  A5 F0                    lda     wcnt
 5548  F93981  1A                       inc     a               ; take in account last block
 5549  F93982  97 0A                    sta     [dirp],y
 5550  F93984                           ACC08
 5551  F93984  E2 20                    sep     #PMFLAG
 5552                                   .LONGA  off
 5553                                   .MNLIST
 5554  F93986  20 10 4E                 jsr     mapout          ; check&update bam on disk
 5555  F93989  A5 09                    lda     sector
 5556  F9398B  C9 04                    cmp     #4              ; dir sec already updated with bam?
 5557  F9398D  90 03                    bcc     ?02             ; yes
 5558  F9398F  20 57 36                 jsr     wrdsec          ; update directory
 5559  F93992  60               ?02:    rts
 5560                           
 5561                           ; setup write file
 5562  F93993                   setwrf:
 5563  F93993  A5 34                    lda     fildrv          ; drive #
 5564  F93995  29 01                    and     #1
 5565  F93997  85 EC                    sta     wrdrv
 5566  F93999  85 19                    sta     drvnum
 5567  F9399B  64 09                    stz     sector
 5568  F9399D  A9 28                    lda     #dirtrk
 5569  F9399F  85 08                    sta     track
 5570  F939A1  20 3D 56                 jsr     sethdp
 5571  F939A4  20 D2 4B                 jsr     addfil          ; create file in directory
 5572  F939A7  A4 20                    ldy     filtrk          ; take first t&s
 5573  F939A9  84 08                    sty     track
 5574  F939AB  A5 25                    lda     filsec
 5575  F939AD  85 09                    sta     sector
 5576  F939AF  85 EE                    sta     wsec            ; current write sector
 5577  F939B1  85 EF                    sta     wfirst          ; this is first sector
 5578  F939B3  20 C1 57                 jsr     wread           ; pre-read whole track
 5579  F939B6  20 5A 56                 jsr     setwb           ; set wbuf pointer
 5580  F939B9  A9 02                    lda     #2
 5581  F939BB  85 ED                    sta     wridx           ; start index
 5582  F939BD  64 F0                    stz     wcnt            ; clear block's count
 5583  F939BF  64 F1                    stz     wcnt+1
 5584  F939C1  60                       rts
  Tue Jul 17 11:00:19 2018                                                                                               Page   54




 5585                           
 5586                           ; setup read file
 5587  F939C2                   setrdf:
 5588  F939C2  A6 15                    ldx     f2ptr           ; index=1..n-1
 5589  F939C4  B5 34                    lda     fildrv,x
 5590  F939C6  29 01                    and     #1
 5591  F939C8  85 19                    sta     drvnum
 5592  F939CA  85 E8                    sta     rddrv
 5593  F939CC  B4 20                    ldy     filtrk,x        ; first t&s of file
 5594  F939CE  84 08                    sty     track
 5595  F939D0  B5 25                    lda     filsec,x
 5596  F939D2  85 09                    sta     sector
 5597  F939D4  20 AB 57                 jsr     tread           ; read whole track
 5598  F939D7  20 4A 56                 jsr     setcp           ; set bufp pointer
 5599  F939DA  64 EA                    stz     rdlst           ; assume full block
 5600  F939DC  A0 01                    ldy     #1
 5601  F939DE  B7 8A                    lda     [bufp],y
 5602  F939E0  A8                       tay
 5603  F939E1  A7 8A                    lda     [bufp]
 5604  F939E3  D0 02                    bne     ?04
 5605  F939E5  84 EA                    sty     rdlst           ; last byte pointer
 5606  F939E7  64 EB            ?04:    stz     rdeof
 5607  F939E9  A9 02                    lda     #2
 5608  F939EB  85 E9                    sta     rdidx
 5609  F939ED  60                       rts
 5610                           
 5611                           ; seek end: open file and put pointer to last byte of file
 5612                           ; use write cache for append
 5613  F939EE                   skend:
 5614  F939EE  A5 34                    lda     fildrv
 5615  F939F0  29 01                    and     #1
 5616  F939F2  85 EC                    sta     wrdrv           ; set up write drv
 5617  F939F4  85 19                    sta     drvnum
 5618  F939F6  A5 2A                    lda     entsec          ; set dir ptr to entry
 5619  F939F8  85 09                    sta     sector
 5620  F939FA  A0 28                    ldy     #dirtrk
 5621  F939FC  84 08                    sty     track
 5622  F939FE  20 3D 56                 jsr     sethdp
 5623  F93A01  18                       clc
 5624  F93A02  65 09                    adc     sector
 5625  F93A04  85 0B                    sta     dirp+1          ; set dir. pointer to file entry
 5626  F93A06  A5 2F                    lda     entind
 5627  F93A08  85 0A                    sta     dirp
 5628  F93A0A  A7 0A                    lda     [dirp]          ; clear flag closed file
 5629  F93A0C  29 7F                    and     #$7F
 5630  F93A0E  87 0A                    sta     [dirp]
 5631  F93A10  20 57 36                 jsr     wrdsec          ; update dir on disk
 5632  F93A13  A5 20                    lda     filtrk
 5633  F93A15  85 08                    sta     track
 5634  F93A17  A5 25                    lda     filsec
 5635  F93A19  85 09                    sta     sector
 5636  F93A1B  64 F0                    stz     wcnt
 5637  F93A1D  64 F1                    stz     wcnt+1
 5638  F93A1F  20 C1 57         ?02:    jsr     wread           ; read whole track in write cache
 5639  F93A22  20 5A 56                 jsr     setwb           ; set cache ptr to right sector
 5640  F93A25  E6 F0            ?04:    inc     wcnt
 5641  F93A27  D0 02                    bne     ?06
  Tue Jul 17 11:00:19 2018                                                                                               Page   55




 5642  F93A29  E6 F1                    inc     wcnt+1
 5643  F93A2B  A0 01            ?06:    ldy     #1
 5644  F93A2D  B7 90                    lda     [wbuf],y        ; next sector
 5645  F93A2F  A8                       tay
 5646  F93A30  A7 90                    lda     [wbuf]          ; next track
 5647  F93A32  F0 12                    beq     ?10             ; end of file
 5648  F93A34  84 09                    sty     sector          ; next sector
 5649  F93A36  C5 08                    cmp     track           ; same track?
 5650  F93A38  85 08                    sta     track
 5651  F93A3A  D0 E3                    bne     ?02             ; will read a new track 
 5652  F93A3C  18                       clc
 5653  F93A3D  98                       tya
 5654  F93A3E  A6 19                    ldx     drvnum
 5655  F93A40  75 7C                    adc     wrtofs,x        ; sector in the same track
 5656  F93A42  85 91                    sta     wbuf+1
 5657  F93A44  80 DF                    bra     ?04             ; follow link   
 5658  F93A46  C8               ?10:    iny                     ; bump pointer  
 5659  F93A47  84 ED                    sty     wridx           ; start index for append
 5660  F93A49  A5 09                    lda     sector
 5661  F93A4B  85 EE                    sta     wsec            ; current write sector
 5662  F93A4D  85 EF                    sta     wfirst          ; this is first sector
 5663  F93A4F                           ACC16
 5664  F93A4F  C2 20                    rep     #PMFLAG
 5665                                   .LONGA  on
 5666                                   .MNLIST
 5667  F93A51  C6 F0                    dec     wcnt            ; append !!
 5668  F93A53                           ACC08
 5669  F93A53  E2 20                    sep     #PMFLAG
 5670                                   .LONGA  off
 5671                                   .MNLIST
 5672  F93A55  60                       rts
 5673                           
 5674                           ; show message while copy/concat
 5675  F93A56                   cpymsg:
 5676  F93A56  24 55                    bit     subcmd
 5677  F93A58  10 1C                    bpl     ?02             ; copy/concat
 5678  F93A5A                           
 5679                                   ; show msg while disk-to-disk copy
 5680  F93A5A  A5 34                    lda     fildrv          ; dest drive
 5681  F93A5C  29 01                    and     #1
 5682  F93A5E  48                       pha     
 5683  F93A5F  D4 94                    pei     (wtmp)          ; block's count #
 5684  F93A61  A9 00                    lda     #^nambuf
 5685  F93A63  48                       pha
 5686  F93A64  F4 C2 E1                 pea     #!nambuf
 5687  F93A67  A5 35                    lda     fildrv+1        ; source drive
 5688  F93A69  29 01                    and     #1
 5689  F93A6B  48                       pha
 5690  F93A6C  4B                       phk
 5691  F93A6D  F4 A7 3A                 pea     #!?20
 5692  F93A70  A9 0B                    lda     #11             ; params #
 5693  F93A72  48                       pha
 5694  F93A73                           BPRINTF
 5695  F93A73  02 11                    cop     $11
 5696                                   .MNLIST
 5697  F93A75  60                       rts
 5698                           
  Tue Jul 17 11:00:19 2018                                                                                               Page   56




 5699                                   ; show msg while copy/concat
 5700  F93A76  A9 00            ?02:    lda     #^nambuf        ; dest file name
 5701  F93A78  48                       pha
 5702  F93A79  F4 DD E1                 pea     #!nambuf2
 5703  F93A7C  A5 34                    lda     fildrv          ; dest drive
 5704  F93A7E  29 01                    and     #1
 5705  F93A80  48                       pha     
 5706  F93A81  D4 94                    pei     (wtmp)          ; block's count #
 5707  F93A83  A9 00                    lda     #^nambuf
 5708  F93A85  48                       pha
 5709  F93A86  F4 C2 E1                 pea     #!nambuf
 5710  F93A89  A5 35                    lda     fildrv+1        ; source drive
 5711  F93A8B  29 01                    and     #1
 5712  F93A8D  48                       pha
 5713  F93A8E  4B                       phk                     ; string bank
 5714  F93A8F  24 55                    bit     subcmd
 5715  F93A91  70 0B                    bvs     ?04             ; always append
 5716  F93A93  A6 15                    ldx     f2ptr
 5717  F93A95  E0 02                    cpx     #2
 5718  F93A97  B0 05                    bcs     ?04             ; append
 5719  F93A99  F4 D6 3A                 pea     #!?30           ; copy
 5720  F93A9C  80 03                    bra     ?06
 5721  F93A9E  F4 01 3B         ?04:    pea     #!?40
 5722  F93AA1  A9 0E            ?06:    lda     #14             ; params #
 5723  F93AA3  48                       pha
 5724  F93AA4                           BPRINTF
 5725  F93AA4  02 11                    cop     $11
 5726                                   .MNLIST
 5727  F93AA6  60                       rts
 5728                           
 5729  F93AA7  0D 63 6F 70 79   ?20:    .DB     $0D, 'copy #%bu:%s (%04hu blocks) to drive #%bu:...', $00
               20 23 25 62 75 
               3A 25 73 20 28 
               25 30 34 68 75 
               20 62 6C 6F 63 
               6B 73 29 20 74 
               6F 20 64 72 69 
               76 65 20 23 25 
               62 75 3A 2E 2E 
               2E 00 
 5730  F93AD6  0D 63 6F 70 79   ?30:    .DB     $0D, 'copy #%bu:%s (%04hu blocks) to #%bu:%s...', $00
               20 23 25 62 75 
               3A 25 73 20 28 
               25 30 34 68 75 
               20 62 6C 6F 63 
               6B 73 29 20 74 
               6F 20 23 25 62 
               75 3A 25 73 2E 
               2E 2E 00 
 5731  F93B01  0D 63 61 74 20   ?40:    .DB     $0D, 'cat  #%bu:%s (%04hu blocks) to #%bu:%s...', $00
               20 23 25 62 75 
               3A 25 73 20 28 
               25 30 34 68 75 
               20 62 6C 6F 63 
               6B 73 29 20 74 
               6F 20 23 25 62 
               75 3A 25 73 2E 
  Tue Jul 17 11:00:19 2018                                                                                               Page   57




               2E 2E 00 
 5732                           
 5733  F93B2C                   donemsg:
 5734  F93B2C  A9 3B                    lda     #>?10
 5735  F93B2E  EB                       xba
 5736  F93B2F  A9 3F                    lda     #<?10
 5737  F93B31  24 43                    bit     image
 5738  F93B33  10 05                    bpl     ?02             ; skip
 5739  F93B35  A9 3B                    lda     #>?20
 5740  F93B37  EB                       xba
 5741  F93B38  A9 45                    lda     #<?20
 5742  F93B3A  A2 F9            ?02:    ldx     #^?10
 5743  F93B3C                           SCNSTROUT
 5744  F93B3C  02 03                    cop     $03
 5745                                   .MNLIST
 5746  F93B3E  60                       rts
 5747                           
 5748  F93B3F  73 6B 69 70 2E   ?10:    .DB     'skip.', 0
               00 
 5749  F93B45  64 6F 6E 65 2E   ?20:    .DB     'done.', 0
               00 
 5750                           
 5751                           ;---------------------------------------------------------------------------
 5752                           ; validate/file check command's
 5753                           ;---------------------------------------------------------------------------
 5754                           ; check file system but without change it
 5755  F93B4B                   fcheck:
 5756  F93B4B  20 05 3C                 jsr     initd
 5757  F93B4E  A0 00                    ldy     #$00
 5758  F93B50  80 13                    bra     vdate1
 5759                           
 5760                           ; check file system and change it
 5761  F93B52                   vdate:
 5762  F93B52  20 05 3C                 jsr     initd
 5763  F93B55  A6 19                    ldx     drvnum
 5764  F93B57  A0 80                    ldy     #$80            ; update file system
 5765  F93B59  B5 68                    lda     drvfg,x
 5766  F93B5B  89 08                    bit     #$08            ; test if new version
 5767  F93B5D  F0 04                    beq     ?10             ; only check without correct in old version
 5768  F93B5F  89 10                    bit     #$10            ; write protect on?
 5769  F93B61  F0 02                    beq     vdate1          ; no -- proceed
 5770  F93B63  A0 00            ?10:    ldy     #$00            ; check only -- no update
 5771                           
 5772  F93B65                   vdate1:
 5773  F93B65  84 E6                    sty     wrop
 5774  F93B67  A5 19                    lda     drvnum
 5775  F93B69  48                       pha
 5776  F93B6A  4B                       phk
 5777  F93B6B  24 E6                    bit     wrop
 5778  F93B6D  30 05                    bmi     ?02
 5779  F93B6F  F4 A4 3B                 pea     #!?60
 5780  F93B72  80 03                    bra     ?03     
 5781  F93B74  F4 D8 3B         ?02:    pea     #!?70
 5782  F93B77  A9 05            ?03:    lda     #5
 5783  F93B79  48                       pha
 5784  F93B7A                           BPRINTF
 5785  F93B7A  02 11                    cop     $11
  Tue Jul 17 11:00:19 2018                                                                                               Page   58




 5786                                   .MNLIST
 5787  F93B7C  20 9C 4E                 jsr     newmap          ; set new aux bam
 5788  F93B7F  64 02                    stz     delind
 5789  F93B81                           ACC16
 5790  F93B81  C2 20                    rep     #PMFLAG
 5791                                   .LONGA  on
 5792                                   .MNLIST
 5793  F93B83  A9 58 0C                 lda     #maxblks        ; max. available block's
 5794  F93B86  85 86                    sta     ntot            ; updated in aux bam
 5795  F93B88  85 88                    sta     bcnt            ; updated in file check
 5796  F93B8A                           ACC08
 5797  F93B8A  E2 20                    sep     #PMFLAG
 5798                                   .LONGA  off
 5799                                   .MNLIST
 5800  F93B8C  20 2D 4B                 jsr     srchst          ; search first file
 5801  F93B8F  F0 0B                    beq     ?10             ; end search
 5802                           
 5803  F93B91  20 08 50         ?04:    jsr     chkfil          ; found one - check
 5804  F93B94  20 65 4B                 jsr     srre            ; next entry
 5805  F93B97  D0 F8                    bne     ?04
 5806  F93B99  20 A7 52                 jsr     chkdir
 5807  F93B9C  20 19 53         ?10:    jsr     updbam
 5808  F93B9F  A6 19                    ldx     drvnum
 5809  F93BA1  74 68                    stz     drvfg,x
 5810  F93BA3  60                       rts
 5811                           
 5812  F93BA4  0D 63 68 65 63   ?60:    .DB     $0D, 'check file system on drive #%bu (without changes).', 0
               6B 20 66 69 6C 
               65 20 73 79 73 
               74 65 6D 20 6F 
               6E 20 64 72 69 
               76 65 20 23 25 
               62 75 20 28 77 
               69 74 68 6F 75 
               74 20 63 68 61 
               6E 67 65 73 29 
               2E 00 
 5813  F93BD8  0D 76 61 6C 69   ?70:    .DB     $0D, 'validate file system with bam on drive %bu.', 0
               64 61 74 65 20 
               66 69 6C 65 20 
               73 79 73 74 65 
               6D 20 77 69 74 
               68 20 62 61 6D 
               20 6F 6E 20 64 
               72 69 76 65 20 
               25 62 75 2E 00 
 5814                           
 5815                           ;---------------------------------------------------------------------------
 5816                           ; initialize command
 5817                           ;---------------------------------------------------------------------------
 5818  F93C05                   initd:
 5819  F93C05  A5 41                    lda     cmdsiz
 5820  F93C07  C9 03                    cmp     #3
 5821  F93C09  90 03                    bcc     ?02
 5822  F93C0B  4C 05 41                 jmp     e_badsyn
 5823  F93C0E  20 31 42         ?02:    jsr     simprs  
 5824  F93C11  A6 19                    ldx     drvnum          ; force init
  Tue Jul 17 11:00:19 2018                                                                                               Page   59




 5825  F93C13  74 68                    stz     drvfg,x
 5826  F93C15  4C 6A 56                 jmp     drvint
 5827                           
 5828                           ;---------------------------------------------------------------------------
 5829                           ; duplicate command
 5830                           ;---------------------------------------------------------------------------
 5831  F93C18                   dupd:
 5832  F93C18  20 D7 40                 jsr     prsdtd          ; check src & dst drive
 5833  F93C1B  A5 35                    lda     fildrv+1
 5834  F93C1D  29 01                    and     #1
 5835  F93C1F  85 19                    sta     drvnum
 5836  F93C21  85 35                    sta     fildrv+1
 5837  F93C23  49 01                    eor     #$01
 5838  F93C25  85 42                    sta     char
 5839  F93C27  20 6A 56                 jsr     drvint          ; init source drive
 5840  F93C2A  20 8A 4B                 jsr     togdrv          ; toggle drive
 5841  F93C2D  20 B4 56                 jsr     dsktst          ; check if dest drive is ready
 5842  F93C30  A6 19                    ldx     drvnum
 5843  F93C32  A9 10                    lda     #$10            ; test if write protect
 5844  F93C34  34 68                    bit     drvfg,x
 5845  F93C36  F0 05                    beq     ?04
 5846  F93C38  A9 1A                    lda     #wpon
 5847  F93C3A  4C F5 56                 jmp     drverr
 5848  F93C3D                   ?04:    SCN_CR
 5849  F93C3D                           SCNPRCHAR
 5850                                   .MLIST
 5851  F93C3D  02 07                    cop     $07
 5852                                   .MNLIST
 5853  F93C3F  0D                       .DB     $0D
 5854                                   .MNLIST
 5855  F93C40  20 E1 58                 jsr     llfmt           ; format dest. drive
 5856  F93C43                           SCN_CR
 5857  F93C43                           SCNPRCHAR
 5858                                   .MLIST
 5859  F93C43  02 07                    cop     $07
 5860                                   .MNLIST
 5861  F93C45  0D                       .DB     $0D
 5862                                   .MNLIST
 5863  F93C46  A9 01                    lda     #1
 5864  F93C48  85 08                    sta     track           ; track counter
 5865  F93C4A  64 09                    stz     sector
 5866  F93C4C                           SCNGETPOS
 5867  F93C4C  02 18                    cop     $18
 5868  F93C4E  02                       .DB     $02
 5869                                   .MNLIST
 5870  F93C4F  86 94                    stx     wtmp
 5871  F93C51  84 95                    sty     wtmp+1
 5872  F93C53  A6 94            ?10:    ldx     wtmp
 5873  F93C55  A4 95                    ldy     wtmp+1
 5874  F93C57                           SCNSETPOS
 5875  F93C57  02 18                    cop     $18
 5876  F93C59  03                       .DB     $03
 5877                                   .MNLIST
 5878  F93C5A  A5 19                    lda     drvnum
 5879  F93C5C  48                       pha                     ; dest drive
 5880  F93C5D  A5 35                    lda     fildrv+1
 5881  F93C5F  48                       pha                     ; src drive
  Tue Jul 17 11:00:19 2018                                                                                               Page   60




 5882  F93C60  A5 08                    lda     track
 5883  F93C62  48                       pha
 5884  F93C63  4B                       phk                     ; bank of format str
 5885  F93C64  F4 90 3C                 pea     #!?100          ; address of format str
 5886  F93C67  A9 07                    lda     #7              ; # params
 5887  F93C69  48                       pha
 5888  F93C6A                           BPRINTF 
 5889  F93C6A  02 11                    cop     $11
 5890                                   .MNLIST
 5891  F93C6C  A6 42                    ldx     char            ; 0 if drive 1, 1 if drive 0
 5892  F93C6E  B5 70                    lda     trkbuf,x        ; A=dma buffer #        
 5893  F93C70  A6 35                    ldx     fildrv+1        ; X=src drive
 5894  F93C72  20 63 58                 jsr     readtk          ; read whole track
 5895  F93C75  A6 42                    ldx     char            ; 0 if drive 1, 1 if drive 0
 5896  F93C77  B5 70                    lda     trkbuf,x        ; A=dma buffer #        
 5897  F93C79  A6 19                    ldx     drvnum          ; X=dest drive
 5898  F93C7B  20 DF 57                 jsr     writetk         ; write whole track
 5899  F93C7E  E6 08                    inc     track
 5900  F93C80  A5 08                    lda     track
 5901  F93C82  C9 51                    cmp     #maxtrk
 5902  F93C84  90 CD                    bcc     ?10
 5903  F93C86                           SCN_CR
 5904  F93C86                           SCNPRCHAR
 5905                                   .MLIST
 5906  F93C86  02 07                    cop     $07
 5907                                   .MNLIST
 5908  F93C88  0D                       .DB     $0D
 5909                                   .MNLIST
 5910  F93C89  A6 19                    ldx     drvnum
 5911  F93C8B  74 68                    stz     drvfg,x         ; invalid drive
 5912  F93C8D  4C 6A 56                 jmp     drvint          ; init dest drive
 5913                           
 5914  F93C90  63 6F 70 79 20   ?100:   .DB     'copy track #%02bu from drive #%bu to drive #%bu', $00
               74 72 61 63 6B 
               20 23 25 30 32 
               62 75 20 66 72 
               6F 6D 20 64 72 
               69 76 65 20 23 
               25 62 75 20 74 
               6F 20 64 72 69 
               76 65 20 23 25 
               62 75 00 
 5915                           
 5916                           ;---------------------------------------------------------------------------
 5917                           ; block-op commands
 5918                           ;---------------------------------------------------------------------------
 5919                           
 5920                           ; U1 & U2 commands
 5921                           ; U1 is the same of B-R and U2 is the same of B-W
 5922                           ; U1: ch dr trk blk
 5923                           ; U1: ch,dr,trk,blk
 5924                           ; U2: ch dr trk blk
 5925                           ; U2: ch,dr,trk,blk
 5926  F93CC0                   blku:
 5927  F93CC0  AD 01 E1                 lda     !cmdbuf+1
 5928  F93CC3  3A                       dec     a
 5929  F93CC4  C9 30                    cmp     #'0'
  Tue Jul 17 11:00:19 2018                                                                                               Page   61




 5930  F93CC6  F0 04                    beq     ?02
 5931  F93CC8  C9 31                    cmp     #'1'
 5932  F93CCA  D0 07                    bne     e_badcmd2
 5933  F93CCC  29 01            ?02:    and     #$01
 5934  F93CCE  AA                       tax                     ; X=0 => R, X=1 => W
 5935  F93CCF  A0 02                    ldy     #$02            ; index next char
 5936  F93CD1  80 21                    bra     blkprs
 5937                           
 5938  F93CD3                   e_badcmd2:
 5939  F93CD3  4C FD 40                 jmp     e_badcmd
 5940                           
 5941  F93CD6                   e_badsyn2:
 5942  F93CD6  4C 05 41                 jmp     e_badsyn
 5943                           
 5944                           ; block-op commands
 5945                           ; B-R: ch dr trk blk
 5946                           ; B-R: ch,dr,trk,blk
 5947                           ; B-W: ch dr trk blk
 5948                           ; B-W: ch,dr,trk,blk
 5949                           ; B-A: dr trk blk
 5950                           ; B-A: dr,trk,blk
 5951                           ; B-F: dr trk blk
 5952                           ; B-F: dr,trk,blk
 5953                           ; B-P: ch pos
 5954                           ; B-P: ch,pos
 5955  F93CD9                   blkb:
 5956  F93CD9  AD 01 E1                 lda     !cmdbuf+1
 5957  F93CDC  C9 2D                    cmp     #'-'            ; subcommands seperator
 5958  F93CDE  D0 F6                    bne     e_badsyn2
 5959  F93CE0  A2 04                    ldx     #ncmds2-1
 5960  F93CE2  AD 02 E1                 lda     !cmdbuf+2
 5961  F93CE5  F0 EF                    beq     e_badsyn2       ; syntax error if no more char's
 5962  F93CE7  DF 69 5A F9      ?02:    cmp     >cmdstb,x       ; match subcommand
 5963  F93CEB  F0 05                    beq     ?04
 5964  F93CED  CA                       dex
 5965  F93CEE  10 F7                    bpl     ?02
 5966  F93CF0  30 E1                    bmi     e_badcmd2       ; error
 5967  F93CF2  A0 03            ?04:    ldy     #3              ; index next char
 5968                           
 5969                           ; common routine for block-op
 5970                           ; X=0 => R, X=1 => W, X=2 => A, X=3 => F, X=4 => P
 5971  F93CF4                   blkprs:
 5972  F93CF4  86 55                    stx     subcmd          ; subcommand
 5973  F93CF6  B9 00 E1                 lda     cmdbuf,y        ; must be seperator
 5974  F93CF9  C9 3A                    cmp     #':'
 5975  F93CFB  D0 D9                    bne     e_badsyn2
 5976  F93CFD  C8               ?02:    iny
 5977  F93CFE  B9 00 E1                 lda     cmdbuf,y
 5978  F93D01  F0 D3                    beq     e_badsyn2       ; end of string is an error here
 5979  F93D03  C9 20                    cmp     #' '            ; skip blanks after semicolon
 5980  F93D05  F0 F6                    beq     ?02
 5981  F93D07  A2 FF                    ldx     #$FF            ; table index
 5982  F93D09  E8               ?04:    inx
 5983  F93D0A  E0 04                    cpx     #mxfils-1
 5984  F93D0C  B0 C8                    bcs     e_badsyn2       ; full param's table
 5985  F93D0E  20 B5 3D                 jsr     asc2bin         ; convert ascii to byte and put in table
 5986  F93D11  88                       dey
  Tue Jul 17 11:00:19 2018                                                                                               Page   62




 5987  F93D12  C8               ?06:    iny     
 5988  F93D13  B9 00 E1                 lda     cmdbuf,y        ; loop for param's parsing
 5989  F93D16  F0 0A                    beq     ?08             ; end parsing
 5990  F93D18  C9 20                    cmp     #' '            ; skip blank seperator
 5991  F93D1A  F0 F6                    beq     ?06
 5992  F93D1C  C9 2C                    cmp     #','            ; skip comma seperator
 5993  F93D1E  F0 F2                    beq     ?06
 5994  F93D20  D0 E7                    bne     ?04             ; parse next digit
 5995  F93D22  E8               ?08:    inx
 5996  F93D23  86 12                    stx     f1cnt           ; param's counter
 5997  F93D25  A9 04                    lda     #4              ; 4 param's for R, W (0 & 1)
 5998  F93D27  A4 55                    ldy     subcmd
 5999  F93D29  F0 0B                    beq     ?10
 6000  F93D2B  88                       dey
 6001  F93D2C  F0 08                    beq     ?10
 6002  F93D2E  3A                       dec     a               ; 3 param's for A, F (2 & 3)
 6003  F93D2F  88                       dey
 6004  F93D30  F0 04                    beq     ?10
 6005  F93D32  88                       dey
 6006  F93D33  F0 01                    beq     ?10
 6007  F93D35  3A                       dec     a               ; 2 param's for P (4)
 6008  F93D36  85 1F            ?10:    sta     tmpxxx
 6009  F93D38  E4 1F                    cpx     tmpxxx
 6010  F93D3A  D0 9A                    bne     e_badsyn2       ; wrong param's count
 6011  F93D3C  A4 55                    ldy     subcmd
 6012  F93D3E  C0 04                    cpy     #4
 6013  F93D40  B0 0F                    bcs     ?14             ; skip drive check for P subcmd 
 6014  F93D42  A2 01                    ldx     #1              ; for R,W second param is drive number
 6015  F93D44  C0 02                    cpy     #2
 6016  F93D46  90 01                    bcc     ?12
 6017  F93D48  CA                       dex                     ; for A,F first param is drive number
 6018  F93D49  B5 25            ?12:    lda     filsec,x        ; check drive number
 6019  F93D4B  C9 02                    cmp     #2
 6020  F93D4D  B0 3A                    bcs     e_baddrv
 6021  F93D4F  85 19                    sta     drvnum
 6022  F93D51  C0 02            ?14:    cpy     #2              ; check channel # for R(0),W(1),P(4)
 6023  F93D53  90 04                    bcc     ?16
 6024  F93D55  C0 04                    cpy     #4
 6025  F93D57  D0 0C                    bne     ?18
 6026  F93D59  A5 25            ?16:    lda     filsec          ; channel # is first param
 6027  F93D5B  C9 02                    cmp     #2              ; valid channel: 2..14
 6028  F93D5D  90 2F                    bcc     e_badchn
 6029  F93D5F  C9 0F                    cmp     #15
 6030  F93D61  B0 2B                    bcs     e_badchn
 6031  F93D63  85 52                    sta     chnl
 6032  F93D65  C0 04            ?18:    cpy     #4
 6033  F93D67  F0 1A                    beq     ?22             ; skip trk & sec check for P subcmd
 6034  F93D69  A2 01                    ldx     #1              ; trk for A, F
 6035  F93D6B  C0 02                    cpy     #2
 6036  F93D6D  B0 01                    bcs     ?20
 6037  F93D6F  E8                       inx                     ; trk for R, W
 6038  F93D70  B5 25            ?20:    lda     filsec,x
 6039  F93D72  85 08                    sta     track
 6040  F93D74  F0 1D                    beq     e_badts
 6041  F93D76  C9 51                    cmp     #maxtrk
 6042  F93D78  B0 19                    bcs     e_badts
 6043  F93D7A  E8                       inx                     ; check sector #
  Tue Jul 17 11:00:19 2018                                                                                               Page   63




 6044  F93D7B  B5 25                    lda     filsec,x
 6045  F93D7D  85 09                    sta     sector
 6046  F93D7F  C9 28                    cmp     #numsec
 6047  F93D81  B0 10                    bcs     e_badts
 6048  F93D83  98               ?22:    tya
 6049  F93D84  0A                       asl     a
 6050  F93D85  AA                       tax
 6051  F93D86  7C E6 5A                 jmp     (scjmp,x)
 6052                           
 6053  F93D89                   e_baddrv:
 6054  F93D89  A9 23                    lda     #baddrv
 6055  F93D8B  4C F5 56                 jmp     drverr
 6056                           
 6057  F93D8E                   e_badchn:
 6058  F93D8E  A9 24                    lda     #badchn
 6059  F93D90  4C ED 56                 jmp     chnerr
 6060                           
 6061  F93D93                   e_badts:
 6062  F93D93  A9 42                    lda     #badts
 6063  F93D95  4C FB 56                 jmp     doserr
 6064                           
 6065                           ; check drive number in A
 6066                           ; in:   A = digit drive number ('0', '1', ...)
 6067                           ;       Y = 0 if check cbm drive (just 0,1)
 6068                           ;       Y = $FF if check dos drive (0..7)
 6069                           ; out:  A = drive number (0, 1, ...)
 6070  F93D98                   chkdrv:
 6071  F93D98  C9 30                    cmp     #'0'             ; drive 0 and 1 always valid
 6072  F93D9A  F0 16                    beq     ?02
 6073  F93D9C  C9 31                    cmp     #'1'
 6074  F93D9E  F0 12                    beq     ?02
 6075  F93DA0  C8                       iny                     ; not zero if check cbm drive
 6076  F93DA1  D0 E6                    bne     e_baddrv        ; invalid cbm drive
 6077  F93DA3  C9 38                    cmp     #'8'
 6078  F93DA5  B0 E2                    bcs     e_baddrv        ; valid dos drive: 0..7
 6079  F93DA7  C9 30                    cmp     #'0'
 6080  F93DA9  90 DE                    bcc     e_baddrv
 6081  F93DAB  E9 30                    sbc     #'0'
 6082  F93DAD  C9 04                    cmp     #MAXDOSDRV
 6083  F93DAF  B0 D8                    bcs     e_baddrv        
 6084  F93DB1  60                       rts
 6085  F93DB2  29 01            ?02:    and     #$01
 6086  F93DB4  60                       rts
 6087                           
 6088                           ; convert ascii string to byte
 6089                           ; in:   A = first digit
 6090                           ;       X = table index
 6091                           ;       Y = cmdbuf index
 6092                           ; out:  X = table index
 6093                           ;       Y = index of first not-digit
 6094  F93DB5                   asc2bin:
 6095  F93DB5  64 1F                    stz     tmpxxx          ; partial value
 6096  F93DB7  C9 30                    cmp     #'0'             ; first char must be a digit
 6097  F93DB9  90 2F                    bcc     ?08
 6098  F93DBB  C9 3A                    cmp     #'9'+1
 6099  F93DBD  B0 2B                    bcs     ?08
 6100  F93DBF  E9 2F            ?02:    sbc     #'0'-1           ; convert digit (here always CF = 0)    
  Tue Jul 17 11:00:19 2018                                                                                               Page   64




 6101  F93DC1  EB                       xba                     ; B = digit
 6102  F93DC2  18                       clc
 6103  F93DC3  A5 1F                    lda     tmpxxx          ; partial null?
 6104  F93DC5  F0 0B                    beq     ?04             ; yes, skip mult * 10
 6105  F93DC7  C9 1A                    cmp     #26             ; this value make overflow
 6106  F93DC9  B0 1F                    bcs     ?08
 6107  F93DCB  0A                       asl     a               ; safety multiply * 10
 6108  F93DCC  0A                       asl     a
 6109  F93DCD  65 1F                    adc     tmpxxx
 6110  F93DCF  0A                       asl     a               ; always carry = 0 here
 6111  F93DD0  85 1F                    sta     tmpxxx
 6112  F93DD2  EB               ?04:    xba     
 6113  F93DD3  65 1F                    adc     tmpxxx
 6114  F93DD5  B0 13                    bcs     ?08             ; overflow
 6115  F93DD7  85 1F                    sta     tmpxxx
 6116  F93DD9  C8                       iny                     ; next char
 6117  F93DDA  B9 00 E1                 lda     cmdbuf,y
 6118  F93DDD  C9 30                    cmp     #'0'             ; continue conversion if next char is a digit
 6119  F93DDF  90 04                    bcc     ?06
 6120  F93DE1  C9 3A                    cmp     #'9'+1
 6121  F93DE3  90 DA                    bcc     ?02
 6122  F93DE5  A5 1F            ?06:    lda     tmpxxx          ; store value in table
 6123  F93DE7  95 25                    sta     filsec,x
 6124  F93DE9  60                       rts
 6125                           
 6126  F93DEA  4C 05 41         ?08:    jmp     e_badsyn
 6127                           
 6128                           ; block read
 6129  F93DED                   blkrd:
 6130  F93DED  20 69 3F                 jsr     tstda           ; check direct access fd type
 6131  F93DF0  20 79 3F                 jsr     dskbuf          ; set tlp ptr to buffer return X=drive...
 6132  F93DF3                           
 6133                                   ; param's in reverse order
 6134  F93DF3  A5 09                    lda     sector
 6135  F93DF5  48                       pha
 6136  F93DF6  A5 08                    lda     track
 6137  F93DF8  48                       pha
 6138  F93DF9  A5 19                    lda     drvnum
 6139  F93DFB  48                       pha
 6140  F93DFC  A5 52                    lda     chnl
 6141  F93DFE  48                       pha
 6142  F93DFF  A9 F9                    lda     #^?01
 6143  F93E01  48                       pha
 6144  F93E02  F4 34 3E                 pea     #!?01
 6145  F93E05  A9 08                    lda     #8              ; num params
 6146  F93E07  48                       pha
 6147  F93E08                           BPRINTF
 6148  F93E08  02 11                    cop     $11
 6149                                   .MNLIST
 6150                           
 6151                           
 6152  F93E0A  20 B7 58                 jsr     readsec
 6153  F93E0D  A5 09                    lda     sector
 6154  F93E0F  4A                       lsr     a
 6155  F93E10  90 02                    bcc     ?02
 6156  F93E12  E6 3F                    inc     tlp+1           ; odd sector
 6157  F93E14  A0 00            ?02:    ldy     #0
  Tue Jul 17 11:00:19 2018                                                                                               Page   65




 6158  F93E16  B7 3E            ?04:    lda     [tlp],y
 6159  F93E18  97 8A                    sta     [bufp],y
 6160  F93E1A  C8                       iny
 6161  F93E1B  D0 F9                    bne     ?04
 6162                                   ;rts
 6163  F93E1D  A5 F6                    lda     pbuf
 6164  F93E1F  48                       pha
 6165  F93E20  A5 40                    lda     tlp+2
 6166  F93E22  48                       pha
 6167  F93E23  D4 3E                    pei     (tlp)
 6168  F93E25  A5 8C                    lda     bufp+2
 6169  F93E27  48                       pha
 6170  F93E28  D4 8A                    pei     (bufp)
 6171  F93E2A  4B                       phk
 6172  F93E2B  F4 65 3E                 pea     #!?10
 6173  F93E2E  A9 0B                    lda     #11
 6174  F93E30  48                       pha
 6175  F93E31                           BPRINTF 
 6176  F93E31  02 11                    cop     $11
 6177                                   .MNLIST
 6178  F93E33  60                       rts
 6179  F93E34                   ?01:
 6180  F93E34  0D 42 2D 52 3A           .DB     $0D, 'B-R: chnl=%bd, drive=%bd, track=%bd, sector=%bd', 0
               20 63 68 6E 6C 
               3D 25 62 64 2C 
               20 64 72 69 76 
               65 3D 25 62 64 
               2C 20 74 72 61 
               63 6B 3D 25 62 
               64 2C 20 73 65 
               63 74 6F 72 3D 
               25 62 64 00 
 6181  F93E65  0D 62 75 66 70   ?10:    .DB     $0D, 'bufp: %P, tlp: %P, DMA: %bX', 0
               3A 20 25 50 2C 
               20 74 6C 70 3A 
               20 25 50 2C 20 
               44 4D 41 3A 20 
               25 62 58 00 
 6182                           
 6183                           ; block write
 6184  F93E82                   blkwr:
 6185                                   ; param's in reverse order
 6186  F93E82  A5 09                    lda     sector
 6187  F93E84  48                       pha
 6188  F93E85  A5 08                    lda     track
 6189  F93E87  48                       pha
 6190  F93E88  A5 19                    lda     drvnum
 6191  F93E8A  48                       pha
 6192  F93E8B  A5 54                    lda     bchn
 6193  F93E8D  48                       pha
 6194  F93E8E  A9 F9                    lda     #^?01
 6195  F93E90  48                       pha
 6196  F93E91  F4 9A 3E                 pea     #!?01
 6197  F93E94  A9 08                    lda     #8              ; num params
 6198  F93E96  48                       pha
 6199  F93E97                           BPRINTF
 6200  F93E97  02 11                    cop     $11
  Tue Jul 17 11:00:19 2018                                                                                               Page   66




 6201                                   .MNLIST
 6202  F93E99  60                       rts
 6203  F93E9A                   ?01:
 6204  F93E9A  42 2D 57 3A 20           .DB     'B-W: chnl=%bd, drive=%bd, track=%bd, sector=%bd', 0
               63 68 6E 6C 3D 
               25 62 64 2C 20 
               64 72 69 76 65 
               3D 25 62 64 2C 
               20 74 72 61 63 
               6B 3D 25 62 64 
               2C 20 73 65 63 
               74 6F 72 3D 25 
               62 64 00 
 6205                           
 6206                           ; block allocate sector
 6207  F93ECA                   blkalc:
 6208                                   ; param's in reverse order
 6209  F93ECA  A5 09                    lda     sector
 6210  F93ECC  48                       pha
 6211  F93ECD  A5 08                    lda     track
 6212  F93ECF  48                       pha
 6213  F93ED0  A5 19                    lda     drvnum
 6214  F93ED2  48                       pha
 6215  F93ED3  A9 F9                    lda     #^?01
 6216  F93ED5  48                       pha
 6217  F93ED6  F4 DF 3E                 pea     #!?01
 6218  F93ED9  A9 07                    lda     #7              ; num params
 6219  F93EDB  48                       pha
 6220  F93EDC                           BPRINTF
 6221  F93EDC  02 11                    cop     $11
 6222                                   .MNLIST
 6223  F93EDE  60                       rts
 6224  F93EDF                   ?01:
 6225  F93EDF  42 2D 41 3A 20           .DB     'B-A: drive=%bd, track=%bd, sector=%bd', 0
               64 72 69 76 65 
               3D 25 62 64 2C 
               20 74 72 61 63 
               6B 3D 25 62 64 
               2C 20 73 65 63 
               74 6F 72 3D 25 
               62 64 00 
 6226                           
 6227                           ; block free sector
 6228  F93F05                   blkfree:
 6229                                   ; param's in reverse order
 6230  F93F05  A5 09                    lda     sector
 6231  F93F07  48                       pha
 6232  F93F08  A5 08                    lda     track
 6233  F93F0A  48                       pha
 6234  F93F0B  A5 19                    lda     drvnum
 6235  F93F0D  48                       pha
 6236  F93F0E  A9 F9                    lda     #^?01
 6237  F93F10  48                       pha
 6238  F93F11  F4 1A 3F                 pea     #!?01
 6239  F93F14  A9 07                    lda     #7              ; num params
 6240  F93F16  48                       pha
 6241  F93F17                           BPRINTF
  Tue Jul 17 11:00:19 2018                                                                                               Page   67




 6242  F93F17  02 11                    cop     $11
 6243                                   .MNLIST
 6244  F93F19  60                       rts
 6245  F93F1A                   ?01:
 6246  F93F1A  42 2D 46 3A 20           .DB     'B-F: drive=%bd, track=%bd, sector=%bd', 0
               64 72 69 76 65 
               3D 25 62 64 2C 
               20 74 72 61 63 
               6B 3D 25 62 64 
               2C 20 73 65 63 
               74 6F 72 3D 25 
               62 64 00 
 6247                           
 6248                           ; block set buffer position
 6249                           ; pos is in filsec+1
 6250  F93F40                   blkpos:
 6251                           
 6252                                   ; param's in reverse order
 6253  F93F40  A5 26                    lda     filsec+1
 6254  F93F42  48                       pha
 6255  F93F43  A5 54                    lda     bchn
 6256  F93F45  48                       pha
 6257  F93F46  A9 F9                    lda     #^?01
 6258  F93F48  48                       pha
 6259  F93F49  F4 52 3F                 pea     #!?01
 6260  F93F4C  A9 06                    lda     #6; num params
 6261  F93F4E  48                       pha
 6262  F93F4F                           BPRINTF
 6263  F93F4F  02 11                    cop     $11
 6264                                   .MNLIST
 6265  F93F51  60                       rts
 6266  F93F52                   ?01:
 6267  F93F52  42 2D 50 3A 20           .DB     'B-P: chnl=%bd, pos=%bu', 0
               63 68 6E 6C 3D 
               25 62 64 2C 20 
               70 6F 73 3D 25 
               62 75 00 
 6268                           
 6269                           ; check that chnl is open and direct type access
 6270  F93F69                   tstda:
 6271  F93F69  20 F2 48                 jsr     isopn           ; check chn is open
 6272  F93F6C  20 CA 48                 jsr     fnddafd         ; check is direct access type
 6273  F93F6F  B0 03                    bcs     ?10
 6274  F93F71  4C 15 49                 jmp     setfdp          ; set buffer for this fd & return X=lindx
 6275  F93F74  A9 40            ?10:    lda     #mistyp
 6276  F93F76  4C ED 56                 jmp     chnerr          ; file type mismatch
 6277                           
 6278                           ; set buffer pointer for block-read / block-write
 6279                           ; buffer is after dir. cache of the selected drive
 6280                           ; set tmpxxx to dma buffer #
 6281                           ; set Y=wtmp to phisycal sector
 6282                           ; set pside to side
 6283  F93F79                   dskbuf:
 6284  F93F79  20 6A 56                 jsr     drvint          ; init drive
 6285  F93F7C  A6 19                    ldx     drvnum          ; set buffer ptr
 6286  F93F7E  86 F2                    stx     pdrv
 6287  F93F80  B5 6E                    lda     sysbuf,x        ; dma # of dir. cache
  Tue Jul 17 11:00:19 2018                                                                                               Page   68




 6288  F93F82  18                       clc
 6289  F93F83  69 14                    adc     #phisec*2
 6290  F93F85  1A                       inc     a
 6291  F93F86  65 57                    adc     lindx
 6292  F93F88  85 F6                    sta     pbuf
 6293  F93F8A  A0 02                    ldy     #DMABNK         ; bank for buffer #00..#7F
 6294  F93F8C  0A                       asl     a               ; get high pointer
 6295  F93F8D  90 01                    bcc     ?02
 6296  F93F8F  C8                       iny                     ; next bank
 6297  F93F90  64 3E            ?02:    stz     tlp
 6298  F93F92  85 3F                    sta     tlp+1
 6299  F93F94  84 40                    sty     tlp+2
 6300  F93F96  A5 09                    lda     sector          ; 0..39
 6301  F93F98  4A                       lsr     a               ; 0..19
 6302  F93F99  A0 00                    ldy     #0              ; side 0
 6303  F93F9B  C9 0A                    cmp     #phisec         ; 0..9 -> side 0, 10..19 -> side 1
 6304  F93F9D  90 03                    bcc     ?04
 6305  F93F9F  E9 0A                    sbc     #phisec
 6306  F93FA1  C8                       iny                     ; side 1
 6307  F93FA2  1A               ?04:    inc     a               ; A = phisycal sec
 6308  F93FA3  85 F4                    sta     psec
 6309  F93FA5  84 F3                    sty     pside
 6310  F93FA7  A9 01                    lda     #1
 6311  F93FA9  85 F5                    sta     pcnt
 6312  F93FAB  60                       rts
 6313                           
 6314                           ;---------------------------------------------------------------------------
 6315                           ; names string utilities
 6316                           ;---------------------------------------------------------------------------
 6317                           
 6318                           ; build canonical file name's table
 6319                           ; check for empty or too long file name
 6320                           ; check for not allowed char's in file name
 6321                           ; convert '*' in right number of '?'
 6322                           ; pad file name with $A0
 6323  F93FAC                   buildfn:
 6324  F93FAC  A2 00                    ldx     #0
 6325  F93FAE  A9 61                    lda     #<fntab         ; set ptr to first file name
 6326  F93FB0  85 3E                    sta     tlp
 6327  F93FB2  A9 E1                    lda     #>fntab
 6328  F93FB4  85 3F                    sta     tlp+1
 6329  F93FB6  86 14            ?02:    stx     f1ptr           ; table index
 6330  F93FB8  B5 34                    lda     fildrv,x
 6331  F93FBA  85 1F                    sta     tmpxxx          ; ibm/dos drive flag (bit 6)
 6332  F93FBC  B5 1A                    lda     filtbl,x
 6333  F93FBE  AA                       tax                     ; pointer to string
 6334  F93FBF  20 55 40                 jsr     fndlmt          ; find string limit
 6335  F93FC2  98                       tya                     ; string size
 6336  F93FC3  D0 03                    bne     ?03
 6337  F93FC5  4C 01 41                 jmp     e_nofile        ; empty: no file given error
 6338  F93FC8  24 1F            ?03:    bit     tmpxxx
 6339  F93FCA  70 48                    bvs     ?18             ; canonical ibm/dos file name
 6340  F93FCC  C9 11                    cmp     #17
 6341  F93FCE  B0 27                    bcs     ?08             ; too long: badfn error
 6342  F93FD0  BD 00 E1                 lda     !cmdbuf,x       ; check if string start with blank
 6343  F93FD3  C9 20                    cmp     #' '
 6344  F93FD5  F0 20                    beq     ?08             ; first char is blank: badfn error
  Tue Jul 17 11:00:19 2018                                                                                               Page   69




 6345  F93FD7  A0 00                    ldy     #0              ; store canonical file name
 6346  F93FD9  BD 00 E1         ?04:    lda     !cmdbuf,x
 6347  F93FDC  F0 22                    beq     ?12             ; end of string
 6348  F93FDE  86 42                    stx     char
 6349  F93FE0  A2 05                    ldx     #nbadch-1       ; check forbidden char's in file name
 6350  F93FE2  DF 96 5A F9      ?06:    cmp     >badchr,x
 6351  F93FE6  F0 0F                    beq     ?08             ; bad char: badfn error
 6352  F93FE8  CA                       dex
 6353  F93FE9  10 F7                    bpl     ?06
 6354  F93FEB  A6 42                    ldx     char
 6355  F93FED  C9 2A                    cmp     #'*'            ; special char
 6356  F93FEF  F0 0B                    beq     ?10             ; handle star char
 6357  F93FF1  91 3E                    sta     (tlp),y         ; store char
 6358  F93FF3  E8                       inx
 6359  F93FF4  C8                       iny
 6360  F93FF5  80 E2                    bra     ?04             ; loop
 6361  F93FF7  A9 21            ?08:    lda     #badfn          ; badfn error
 6362  F93FF9  4C 07 41                 jmp     cmderr
 6363  F93FFC  A9 3F            ?10:    lda     #'?'            ; fill residual name with '?'
 6364  F93FFE  80 02                    bra     ?14
 6365  F94000  A9 A0            ?12:    lda     #$A0            ; pad name with $A0
 6366  F94002  88               ?14:    dey
 6367  F94003  C8               ?16:    iny
 6368  F94004  C0 10                    cpy     #16
 6369  F94006  B0 04                    bcs     ?17
 6370  F94008  91 3E                    sta     (tlp),y
 6371  F9400A  80 F7                    bra     ?16
 6372  F9400C  A9 00            ?17:    lda     #0              ; string terminator
 6373  F9400E  91 3E                    sta     (tlp),y
 6374  F94010  C8                       iny                     ; offset to add for next string 
 6375  F94011  18                       clc
 6376  F94012  80 05                    bra     ?20
 6377  F94014  20 2A 40         ?18:    jsr     dosfn           ; handle dos file name
 6378  F94017  B0 DE                    bcs     ?08             ; bad dos file name
 6379  F94019  A5 3E            ?20:    lda     tlp             ; set new file name pointer
 6380  F9401B  A6 14                    ldx     f1ptr
 6381  F9401D  95 1A                    sta     filtbl,x
 6382  F9401F  98                       tya
 6383  F94020  65 3E                    adc     tlp             ; here always CF = 0
 6384  F94022  85 3E                    sta     tlp             ; always stay in the same page !
 6385  F94024  E8                       inx                     ; next file name
 6386  F94025  E4 13                    cpx     f2cnt
 6387  F94027  90 8D                    bcc     ?02
 6388  F94029  60                       rts
 6389                           
 6390                           ; get canonical name of dos file name
 6391  F9402A                   dosfn:
 6392  F9402A  CA                       dex                     ; store 'X:' at beginning
 6393  F9402B  CA                       dex
 6394  F9402C  A5 1F                    lda     tmpxxx
 6395  F9402E  29 07                    and     #7
 6396  F94030  18                       clc
 6397  F94031  69 41                    adc     #'A'            ; convert in drive letter
 6398  F94033  9D 00 E1                 sta     !cmdbuf,x
 6399  F94036  A9 3A                    lda     #':'
 6400  F94038  9D 01 E1                 sta     !cmdbuf+1,x     ; check name type A:/xxx...
 6401  F9403B  A9 00                    lda     #0              ; bank of src string
  Tue Jul 17 11:00:19 2018                                                                                               Page   70




 6402  F9403D  48                       pha
 6403  F9403E  A9 E1                    lda     #>cmdbuf
 6404  F94040  48                       pha                     ; pointer of source string
 6405  F94041  A9 00                    lda     #<cmdbuf
 6406  F94043  86 42                    stx     char
 6407  F94045  65 42                    adc     char            ; add offset
 6408  F94047  48                       pha
 6409  F94048  A9 00                    lda     #0              ; bank of dest string
 6410  F9404A  48                       pha
 6411  F9404B  D4 3E                    pei     (tlp)           ; dest string pointer
 6412  F9404D  A9 80                    lda     #$80
 6413  F9404F  48                       pha                     ; fileflag (file)
 6414  F94050                           TRUENAM                 ; get canonical name (sys call)
 6415  F94050  02 FE                    cop     $FE
 6416                                   .MNLIST
 6417  F94052  A0 50                    ldy     #80             ; offset to add for next string 
 6418  F94054  60                       rts
 6419                           
 6420                           ; find string limit in cmdbuf pointed to by X
 6421                           ; in:   X = string pointer
 6422                           ; out:  X = string pointer
 6423                           ;       Y = string size
 6424  F94055                   fndlmt:
 6425  F94055  DA                       phx                     ; save ptr
 6426  F94056  A0 00                    ldy     #0              ; string size
 6427  F94058  BD 00 E1         ?02:    lda     !cmdbuf,x
 6428  F9405B  F0 0F                    beq     ?06             ; end of string
 6429  F9405D  C9 2C                    cmp     #','
 6430  F9405F  F0 08                    beq     ?04             ; 'comma' limited
 6431  F94061  C9 3D                    cmp     #'='
 6432  F94063  F0 04                    beq     ?04             ; 'equal' limited
 6433  F94065  C8                       iny
 6434  F94066  E8                       inx
 6435  F94067  80 EF                    bra     ?02             ; loop next char
 6436  F94069  9E 00 E1         ?04:    stz     !cmdbuf,x       ; string limit
 6437  F9406C  FA               ?06:    plx                     ; restore ptr
 6438  F9406D  60                       rts
 6439                           
 6440                           ;---------------------------------------------------------------------------
 6441                           ; parse command string utilities
 6442                           ;---------------------------------------------------------------------------
 6443                           
 6444                           ; special case: parse command string for copy command
 6445  F9406E                   prscpy:
 6446  F9406E  20 6A 42                 jsr     prscln          ; find ":"
 6447  F94071  D0 21                    bne     ?20             ; ok, found ":"
 6448  F94073  20 D7 40                 jsr     prsdtd          ; look for "Cddrv=sdrv"
 6449  F94076  A2 5E            ?10:    ldx     #cmdlen-2
 6450  F94078  A9 2A                    lda     #'*'            ; put "*" at buffer end
 6451  F9407A  9D 00 E1                 sta     !cmdbuf,x
 6452  F9407D  9E 01 E1                 stz     !cmdbuf+1,x
 6453  F94080  86 1B                    stx     filtbl+1        ; file2 ptr -> "*"
 6454  F94082  86 1A                    stx     filtbl          ; file1 ptr -> "*" 
 6455  F94084  A9 80                    lda     #$80
 6456  F94086  85 3A                    sta     pattyp+1        ; file2 pattern flag    
 6457  F94088  A2 01            ?14:    ldx     #1              ; set up cnt's
 6458  F9408A  86 12                    stx     f1cnt
  Tue Jul 17 11:00:19 2018                                                                                               Page   71




 6459  F9408C  E8                       inx
 6460  F9408D  86 13                    stx     f2cnt
 6461  F9408F  A9 80                    lda     #$80            ; file1 pattern flag
 6462  F94091  85 39                    sta     pattyp
 6463  F94093  60                       rts
 6464  F94094  20 13 41         ?20:    jsr     tagcmd2         ; continue normal parsing
 6465  F94097  20 8D 41                 jsr     alldrs          ; put drv's in filtbl
 6466  F9409A  A5 43                    lda     image           ; get parse image
 6467  F9409C  29 55                    and     #%01010101      ; mask off copy (fs1 & fs2 just one file)
 6468  F9409E  D0 2E                    bne     ?30             ; concat
 6469  F940A0                           
 6470                                   ; now parse string "ddrv:file1=sdrv:file2"
 6471  F940A0  A6 1A                    ldx     filtbl          ; check file1
 6472  F940A2  BD 00 E1                 lda     !cmdbuf,x
 6473  F940A5  C9 2A                    cmp     #'*'            ; file1="*"?
 6474  F940A7  F0 04                    beq     ?22
 6475  F940A9  C9 3D                    cmp     #'='            ; file1 = NULL?
 6476  F940AB  D0 21                    bne     ?30             ; no, check normal copy
 6477                           
 6478                           ?22:    ; now string is the form "ddrv:*=sdrv:file2" or "ddrv:=sdrv:file2"
 6479                                   ; so operation is type DTD with unspecified file1
 6480  F940AD  A5 35                    lda     fildrv+1        ; check drv not equal
 6481  F940AF  29 07                    and     #$07
 6482  F940B1  C5 34                    cmp     fildrv
 6483  F940B3  F0 50                    beq     e_badsyn        ; cannot be equal
 6484  F940B5  A6 1B                    ldx     filtbl+1        ; check file2
 6485  F940B7  BD 00 E1                 lda     !cmdbuf,x
 6486  F940BA  F0 BA                    beq     ?10             ; file2 = NULL -> file2 = "*"
 6487  F940BC  C9 2A                    cmp     #'*'
 6488  F940BE  F0 B6                    beq     ?10             ; file2 = "*"
 6489  F940C0  A2 5E                    ldx     #cmdlen-2
 6490  F940C2  A9 2A                    lda     #'*'            ; put "*" at buffer end
 6491  F940C4  9D 00 E1                 sta     !cmdbuf,x
 6492  F940C7  9E 01 E1                 stz     !cmdbuf+1,x
 6493  F940CA  86 1A                    stx     filtbl          ; file1 ptr -> "*"      
 6494  F940CC  80 BA                    bra     ?14             ; retain file2, file1 pattern flag
 6495                           
 6496                           ?30:    ; check for normal copy: no pattern, fs1=1 file, fs2=n files
 6497  F940CE  A5 43                    lda     image           ; chk for normal
 6498  F940D0  29 D9                    and     #%11011001
 6499  F940D2  D0 31                    bne     e_badsyn
 6500  F940D4  64 39                    stz     pattyp          ; clear file1 pattern flag
 6501  F940D6  60                       rts
 6502                           
 6503                           ; special case: parse string for disk-to-disk operation (DTD)
 6504                           ; i.e.: "Cddrv=sdrv", "Dddrv=sdrv"
 6505  F940D7                   prsdtd:
 6506  F940D7  A9 3D                    lda     #'='            ; find "="
 6507  F940D9  20 6F 42                 jsr     parse
 6508  F940DC  F0 27                    beq     e_badsyn        ; error
 6509  F940DE  B9 00 E1                 lda     cmdbuf,y        ; test src drive
 6510  F940E1  20 5D 42                 jsr     tst0v1
 6511  F940E4  30 13                    bmi     e_baddrv2       ; error
 6512  F940E6  85 35                    sta     fildrv+1        ; src drive
 6513  F940E8  88                       dey
 6514  F940E9  88                       dey                     ; back to dest drive
 6515  F940EA  B9 00 E1                 lda     cmdbuf,y
  Tue Jul 17 11:00:19 2018                                                                                               Page   72




 6516  F940ED  20 5D 42                 jsr     tst0v1          ; test dest drive
 6517  F940F0  30 07                    bmi     e_baddrv2
 6518  F940F2  C5 35                    cmp     fildrv+1        ; cannot be equal
 6519  F940F4  F0 0F                    beq     e_badsyn
 6520  F940F6  85 34                    sta     fildrv          ; dest drive
 6521  F940F8  60                       rts
 6522                           
 6523  F940F9                   e_baddrv2:
 6524  F940F9  A9 23                    lda     #baddrv
 6525  F940FB  80 0A                    bra     cmderr
 6526  F940FD                   e_badcmd:
 6527  F940FD  A9 1F                    lda     #badcmd
 6528  F940FF  80 06                    bra     cmderr
 6529  F94101                   e_nofile:
 6530  F94101  A9 22                    lda     #nofile         ; no files
 6531  F94103  80 02                    bra     cmderr
 6532  F94105                   e_badsyn:
 6533  F94105  A9 1E                    lda     #badsyn         ; err: bad syntax
 6534  F94107                   cmderr:
 6535  F94107  64 08                    stz     track           ; cmd level err proc
 6536  F94109  64 09                    stz     sector
 6537  F9410B  4C FB 56                 jmp     doserr
 6538                           
 6539                           ; tag cmd string,setup cmd.. struc, image & file pntrs
 6540                           ; parse command line for R,S,N,A,T,M,L,K,E
 6541                           ;
 6542                           ; image bits
 6543                           ;            pgdrpgdr
 6544                           ;            fs1 fs2
 6545                           ;   bit reps:  pattern
 6546                           ;              greater than one file 
 6547                           ;              drive:filename 
 6548                           ;              not drive:filename (inverted d bit)
 6549                           ;
 6550                           ;   fs1 only    XX100001
 6551                           ;   fs1 & fs2   XX10XX10
 6552                           ;   fs1         XX10XX00 (fs2 optional)
 6553                           
 6554                           
 6555  F9410E                   tagcmd:
 6556  F9410E  20 6A 42                 jsr     prscln
 6557  F94111  F0 EE                    beq     e_nofile        ; missing ':' -- error
 6558                           
 6559  F94113                   tagcmd2:
 6560  F94113  88                       dey
 6561  F94114  88                       dey
 6562  F94115  84 1A                    sty     filtbl          ; ":"-1 starts fs1
 6563  F94117  8A                       txa
 6564  F94118  D0 E7                    bne     e_nofile        ; err: "," before ":"
 6565                           
 6566  F9411A                   prseq:
 6567  F9411A  A9 3D                    lda     #'='            ; search: "="
 6568  F9411C  20 6F 42                 jsr     parse
 6569  F9411F  8A                       txa                     ; ?file count= 1-1?
 6570  F94120  F0 02                    beq     ?40
 6571  F94122  A9 40                    lda     #%01000000      ; g1-bit - fs1 count > 1
 6572  F94124  09 21            ?40:    ora     #%00100001      ; d1,r2-bits - def. drive fs1, fs2 file req.
  Tue Jul 17 11:00:19 2018                                                                                               Page   73




 6573  F94126  85 43                    sta     image           ; fs structure
 6574  F94128  E8                       inx
 6575  F94129  86 12                    stx     f1cnt           ; fs1 file count
 6576  F9412B  86 13                    stx     f2cnt           ; init for no fs2
 6577  F9412D  A5 11                    lda     patflg
 6578  F9412F  F0 06                    beq     ?50
 6579  F94131  A9 80                    lda     #%10000000      ; p1-bit
 6580  F94133  04 43                    tsb     image
 6581  F94135  64 11                    stz     patflg          ; clear pattern flag
 6582  F94137  98               ?50:    tya                     ; ptr to fs2
 6583  F94138  F0 21                    beq     ?75             ; no '=' -> no fs2
 6584  F9413A  95 1A                    sta     filtbl,x
 6585  F9413C  A5 12                    lda     f1cnt           ; fs2 is here now,...
 6586  F9413E  85 15                    sta     f2ptr           ; ...now set f2 ptr
 6587  F94140  A9 8D                    lda     #$8d            ; dummy: find cr-shifted (till end of line)
 6588  F94142  20 6F 42                 jsr     parse           ; parse rest of cmd string
 6589  F94145  E8                       inx                     ; advance filtbl ptr to end
 6590  F94146  86 13                    stx     f2cnt           ; save it
 6591  F94148  CA                       dex                     ; restore for test
 6592  F94149  A5 11                    lda     patflg          ; save last pattern
 6593  F9414B  F0 02                    beq     ?60             ; ?any patterns?
 6594  F9414D  A9 08                    lda     #%00001000      ; yes, p2-bit
 6595  F9414F  E4 12            ?60:    cpx     f1cnt           ; ?f2cnt=f1cnt+1?
 6596  F94151  F0 02                    beq     ?70
 6597  F94153  09 04                    ora     #%00000100      ; g2-bit
 6598  F94155  09 03            ?70:    ora     #%00000011      ; d2-bit,r2-bit
 6599  F94157  45 43                    eor     image           ; eor clears r2-bit
 6600  F94159  85 43                    sta     image
 6601  F9415B  A5 43            ?75:    lda     image
 6602  F9415D  A6 53                    ldx     cmdnum
 6603  F9415F  3F 6E 5A F9              and     >struct,x       ; match cmd template
 6604  F94163  D0 A0                    bne     e_badsyn
 6605  F94165  60                       rts
 6606                           
 6607                           ; parse command string for "open"
 6608  F94166                   prsopn:
 6609  F94166  A9 80                    lda     #$80
 6610  F94168  85 93                    sta     tmp0            ; accept default drive
 6611  F9416A  20 6A 42                 jsr     prscln          ; look for ":"
 6612  F9416D  D0 03                    bne     ?02             ; found
 6613  F9416F  BB                       tyx                     ; not found: y=0
 6614  F94170  F0 07                    beq     ?06             ; bra
 6615  F94172  8A               ?02:    txa
 6616  F94173  D0 90                    bne     e_badsyn        ; comma before ":"
 6617  F94175  88                       dey                     ; back up to ":"
 6618  F94176  F0 01                    beq     ?06             ; 1st char is ":"
 6619  F94178  88                       dey
 6620  F94179  84 1A            ?06:    sty     filtbl          ; save filename ptr
 6621  F9417B  A9 8D                    lda     #$8d            ; parse cmd string
 6622  F9417D  20 6F 42                 jsr     parse
 6623  F94180  E8                       inx
 6624  F94181  86 13                    stx     f2cnt
 6625                           
 6626                           ; set 1st drive and table pointers
 6627  F94183                   onedrv:
 6628  F94183  A5 13                    lda     f2cnt           ; save f2cnt
 6629  F94185  85 12                    sta     f1cnt
  Tue Jul 17 11:00:19 2018                                                                                               Page   74




 6630  F94187  A9 01                    lda     #1              ; set pointer to first file
 6631  F94189  85 13                    sta     f2cnt
 6632  F9418B  85 15                    sta     f2ptr
 6633  F9418D                           
 6634                           ;set up all drives from f2cnt (all files in stream)
 6635  F9418D                   alldrs:
 6636  F9418D  A4 19                    ldy     drvnum          ; default drive is last parsed drive 
 6637  F9418F  A2 00                    ldx     #0              ; ...into file entry table...
 6638  F94191  86 14            ?10     stx     f1ptr           ; ...on sector ptr byte
 6639  F94193  B5 34                    lda     fildrv,x        ; set bit 6 if dos drive 
 6640  F94195  85 42                    sta     char
 6641  F94197  B5 1A                    lda     filtbl,x
 6642  F94199  20 EF 41                 jsr     setdrv
 6643  F9419C  A6 14                    ldx     f1ptr
 6644  F9419E  95 1A                    sta     filtbl,x        ; incr ptr past ":"
 6645                                                           ; bits rep drives
 6646  F941A0  98                       tya
 6647  F941A1  05 42                    ora     char            ; restore bit 6
 6648  F941A3  95 34                    sta     fildrv,x        ; bit7: default drive
 6649  F941A5  E8                       inx                     ; bit0: drive #
 6650  F941A6  E4 13                    cpx     f2cnt
 6651  F941A8  90 E7                    bcc     ?10
 6652  F941AA  60                       rts      
 6653                           
 6654                           ; parse string for load directory command
 6655                           ; cover these situations:
 6656                           ; "$"
 6657                           ; "$x"
 6658                           ; "$x:pattern=type"
 6659  F941AB                   prsldd:
 6660  F941AB  A9 0B                    lda     #ldcmd          ; this is used as index for check image
 6661  F941AD  85 53                    sta     cmdnum
 6662  F941AF  A9 80                    lda     #$80            ; load only drive zero
 6663  F941B1  A6 41                    ldx     cmdsiz
 6664  F941B3  CA                       dex
 6665  F941B4  F0 0B                    beq     ?02             ; "$" case
 6666  F941B6  CA                       dex                     ; load by name
 6667  F941B7  D0 20                    bne     ?03
 6668  F941B9  AD 01 E1                 lda     !cmdbuf+1       ; "$x" case
 6669  F941BC  20 5D 42                 jsr     tst0v1
 6670  F941BF  30 18                    bmi     ?03             ; x is not a drive number
 6671  F941C1  85 34            ?02:    sta     fildrv          ; specified drive or default drive
 6672  F941C3  86 1A                    stx     filtbl          ; file ptr -- here X = 0
 6673  F941C5  E8                       inx
 6674  F941C6  86 12                    stx     f1cnt           ; just file 1 stream
 6675  F941C8  86 13                    stx     f2cnt
 6676  F941CA  A9 80                    lda     #$80
 6677  F941CC  85 39                    sta     pattyp
 6678  F941CE  A9 2A                    lda     #'*'            ; in fact open "$x:*"
 6679  F941D0  8D 00 E1                 sta     !cmdbuf
 6680  F941D3  9C 01 E1                 stz     !cmdbuf+1
 6681  F941D6  86 41                    stx     cmdsiz
 6682  F941D8  60                       rts
 6683  F941D9  20 6A 42         ?03:    jsr     prscln          ; "$x:pattern=type" case
 6684  F941DC  D0 05                    bne     ?05             ; found ":"
 6685  F941DE  20 1E 43                 jsr     cmdrst          ; search by name on both drives
 6686  F941E1  A0 03                    ldy     #3
  Tue Jul 17 11:00:19 2018                                                                                               Page   75




 6687  F941E3  88               ?05:    dey
 6688  F941E4  88                       dey
 6689  F941E5  84 1A                    sty     filtbl
 6690  F941E7  20 1A 41                 jsr     prseq           ; parse & set tables
 6691  F941EA  20 B1 42                 jsr     fs1set
 6692  F941ED  80 9E                    bra     alldrs      
 6693                           
 6694                           ;---------------------------------------
 6695                           ;  set drive number
 6696                           ;  determines drive # from text or
 6697                           ;  uses default (-d)
 6698                           ;  a: in,out: index, cmdbuf
 6699                           ;  y: in: default drive
 6700                           ;     out: drive number, - if default
 6701                           ;  char<6> set if check dos drive
 6702                           ;---------------------------------------
 6703  F941EF                   setdrv:
 6704  F941EF  AA                       tax                     ; x= cmdbuf index
 6705  F941F0  A9 3A                    lda     #':'
 6706  F941F2  DD 01 E1                 cmp     !cmdbuf+1,x     ; for xxx:file
 6707  F941F5  F0 0D                    beq     ?40             ;       ^
 6708  F941F7  DD 00 E1                 cmp     !cmdbuf,x       ; for xxx:file
 6709  F941FA  D0 2E                    bne     ?50             ;        ^
 6710  F941FC  E8                       inx                     ; found ":", so...
 6711  F941FD  80 2B                    bra     ?50
 6712  F941FF  29 01            ?22:    and     #1              ; convert to numeric
 6713  F94201  A8               ?24:    tay                     ; set new default drive
 6714  F94202  8A                       txa                     ; a=index & xxxxfile
 6715  F94203  60                       rts                     ;               ^
 6716  F94204  BD 00 E1         ?40:    lda     !cmdbuf,x
 6717  F94207  E8                       inx                     ;  xxx:file
 6718  F94208  E8                       inx                     ;    --^
 6719  F94209  C9 30                    cmp     #'0'             ; for xx0:file
 6720  F9420B  F0 F2                    beq     ?22             ;         ^
 6721  F9420D  C9 31                    cmp     #'1'            ; for xx1:file
 6722  F9420F  F0 EE                    beq     ?22             ;         ^
 6723  F94211  24 42                    bit     char            ; test bit 6
 6724  F94213  50 11                    bvc     ?48             ; check default cbm drive
 6725  F94215  C9 38                    cmp     #'8'
 6726  F94217  B0 0A                    bcs     ?45             ; valid dos drive: 0..7
 6727  F94219  C9 30                    cmp     #'0'
 6728  F9421B  90 06                    bcc     ?45
 6729  F9421D  E9 30                    sbc     #'0'
 6730  F9421F  C9 04                    cmp     #MAXDOSDRV
 6731  F94221  90 DE                    bcc     ?24             ; dos drive ok  
 6732  F94223  4C 89 3D         ?45:    jmp     e_baddrv
 6733  F94226  24 93            ?48:    bit     tmp0            ; for default baddrv error!
 6734  F94228  10 F9                    bpl     ?45
 6735  F9422A  98               ?50:    tya                     ; for xxx,file or xx=file
 6736  F9422B  09 80                    ora     #$80            ;         ^          ^
 6737  F9422D  29 87                    and     #$87            ; drive= -default
 6738  F9422F  80 D0                    bra     ?24
 6739  F94231                           
 6740                           ; simple parser - set just the drive number
 6741                           ; called by open directory command
 6742  F94231                   simprs:
 6743  F94231  64 1A                    stz     filtbl
  Tue Jul 17 11:00:19 2018                                                                                               Page   76




 6744  F94233  20 6A 42                 jsr     prscln          ; search colon
 6745  F94236  F0 04                    beq     ?02             ; ":" not found, Y = next char
 6746  F94238  88                       dey
 6747  F94239  88                       dey
 6748  F9423A  84 1A                    sty     filtbl          ; ptr to char before ":"
 6749  F9423C  64 43            ?02:    stz     image
 6750  F9423E  A4 1A                    ldy     filtbl
 6751  F94240  B9 00 E1         ?04:    lda     cmdbuf,y
 6752  F94243  20 5D 42                 jsr     tst0v1
 6753  F94246  10 10                    bpl     ?20             ; ok, found drive #
 6754  F94248  C8                       iny
 6755  F94249  C4 41                    cpy     cmdsiz
 6756  F9424B  B0 05                    bcs     ?10             ; end of string
 6757  F9424D  A4 41                    ldy     cmdsiz
 6758  F9424F  88                       dey
 6759  F94250  D0 EE                    bne     ?04
 6760  F94252  C6 43            ?10:    dec     image           ; invalidate cmd template
 6761  F94254  A5 19                    lda     drvnum          ; use default drive
 6762  F94256  09 80                    ora     #$80
 6763  F94258  29 81            ?20:    and     #$81
 6764  F9425A  85 34                    sta     fildrv
 6765  F9425C  60                       rts
 6766                           
 6767                           ;test char in accum for "0" or "1"
 6768  F9425D  C9 30            tst0v1: cmp     #'0'
 6769  F9425F  F0 06                    beq     ?02
 6770  F94261  C9 31                    cmp     #'1'
 6771  F94263  F0 02                    beq     ?02
 6772  F94265  09 80                    ora     #$80            ; use default drive
 6773  F94267  29 81            ?02:    and     #$81            ; mask dr #
 6774  F94269  60                       rts      
 6775                           
 6776                           ; find pos'n of ":"
 6777  F9426A                   prscln:
 6778  F9426A  A0 00                    ldy     #0              ; buffer ptr
 6779  F9426C  BB                       tyx                     ; comma counter
 6780  F9426D  A9 3A                    lda     #':'         
 6781                           
 6782                           ;parse string
 6783                           ;  looks for special chars,
 6784                           ;  returning when var'bl char
 6785                           ;  is found
 6786                           ;   a: var'bl char
 6787                           ;   x: in,out: index, filtbl+1
 6788                           ;   y: in: index, cmdbuf
 6789                           ;     out: new ptr, =0 if none
 6790                           ;         (z=1) if y=0
 6791  F9426F                   parse:  
 6792  F9426F  85 42                    sta     char            ; save var'bl char
 6793  F94271  B9 00 E1         ?10:    lda     cmdbuf,y        ; match char
 6794  F94274  F0 29                    beq     ?30             ; end of string
 6795  F94276  C8                       iny
 6796  F94277  C5 42                    cmp     char
 6797  F94279  F0 26                    beq     ?35             ; found char
 6798  F9427B  C9 2A                    cmp     #'*'            ; match pattern chars
 6799  F9427D  F0 04                    beq     ?20
 6800  F9427F  C9 3F                    cmp     #'?'
  Tue Jul 17 11:00:19 2018                                                                                               Page   77




 6801  F94281  D0 02                    bne     ?25
 6802  F94283  E6 11            ?20:    inc     patflg          ; set pattern flag
 6803  F94285  C9 2C            ?25:    cmp     #','            ; match file separator
 6804  F94287  D0 E8                    bne     ?10             ; loop
 6805  F94289  94 1B                    sty     filtbl+1,x      ; put ptrs in table
 6806  F9428B  A5 11                    lda     patflg          ; save pattern for file
 6807  F9428D  29 7F                    and     #$7f
 6808  F9428F  F0 06                    beq     ?28
 6809  F94291  A9 80                    lda     #$80            ; retain pattern presence...
 6810  F94293  95 39                    sta     pattyp,x
 6811  F94295  85 11                    sta     patflg          ; ...but clear count
 6812  F94297  E8               ?28:    inx
 6813  F94298  E0 05                    cpx     #mxfils
 6814  F9429A  90 D5                    bcc     ?10             ; no more than mxfils
 6815  F9429C  4C 05 41                 jmp     e_badsyn        ; too many files
 6816  F9429F  A0 00            ?30:    ldy     #0              ; y=0 (z=1)
 6817  F942A1  A5 41            ?35:    lda     cmdsiz
 6818  F942A3  95 1B                    sta     filtbl+1,x
 6819  F942A5  A5 11                    lda     patflg
 6820  F942A7  29 7F                    and     #$7f
 6821  F942A9  F0 04                    beq     ?40
 6822  F942AB  A9 80                    lda     #$80
 6823  F942AD  95 39                    sta     pattyp,x
 6824  F942AF  98               ?40:    tya                     ; z is set
 6825  F942B0  60                       rts
 6826                           
 6827                           ; set ptrs to one file stream & chk type
 6828                           ; for command that allow pattern=type
 6829  F942B1                   fs1set: 
 6830  F942B1  A2 00                    ldx     #0
 6831  F942B3  A5 12                    lda     f1cnt
 6832  F942B5  C5 13                    cmp     f2cnt
 6833  F942B7  F0 15                    beq     ?15             ; just one file in stream
 6834  F942B9  C6 13                    dec     f2cnt
 6835  F942BB  A6 13                    ldx     f2cnt
 6836  F942BD  B5 1A                    lda     filtbl,x
 6837  F942BF  AA                       tax
 6838  F942C0  BD 00 E1                 lda     !cmdbuf,x
 6839  F942C3  A2 05                    ldx     #ntypes-1
 6840  F942C5  DF 84 5A F9      ?10:    cmp     >typlst,x
 6841  F942C9  F0 03                    beq     ?15
 6842  F942CB  CA                       dex
 6843  F942CC  D0 F7                    bne     ?10
 6844  F942CE  86 10            ?15:    stx     typflg
 6845  F942D0  60                       rts
 6846                           
 6847                           ; copy local cmd string, initialize command tables, ptrs, etc.
 6848                           ; command string, as parameter, is terminated with '0' or CR
 6849  F942D1                   cmdset:
 6850  F942D1  A0 00                    ldy     #0
 6851  F942D3  A7 3E            ?02:    lda     [tlp]           ; trim left
 6852  F942D5  F0 2A                    beq     ?10             ; end of cmd
 6853  F942D7  C9 0D                    cmp     #$0D
 6854  F942D9  F0 18                    beq     ?06             ; end of cmd
 6855  F942DB  C9 20                    cmp     #' '            ; trim blanks
 6856  F942DD  D0 0A                    bne     ?03
 6857  F942DF  E6 3E                    inc     tlp
  Tue Jul 17 11:00:19 2018                                                                                               Page   78




 6858  F942E1  D0 F0                    bne     ?02
 6859  F942E3  E6 3F                    inc     tlp+1
 6860  F942E5  D0 EC                    bne     ?02
 6861  F942E7  F0 22                    beq     ?11             ; long line
 6862  F942E9  88               ?03:    dey
 6863  F942EA  C8               ?04:    iny
 6864  F942EB  B7 3E                    lda     [tlp],y
 6865  F942ED  F0 12                    beq     ?10             ; end of cmd
 6866  F942EF  C9 0D                    cmp     #$0D
 6867  F942F1  D0 04                    bne     ?08
 6868  F942F3  A9 00            ?06:    lda     #0              ; end of cmd
 6869  F942F5  80 0A                    bra     ?10
 6870  F942F7  C9 61            ?08:    cmp     #'a'            ; convert up case
 6871  F942F9  90 06                    bcc     ?10
 6872  F942FB  C9 7B                    cmp     #'z'+1
 6873  F942FD  B0 02                    bcs     ?10
 6874  F942FF  29 DF                    and     #$DF
 6875  F94301  99 00 E1         ?10:    sta     cmdbuf,y
 6876  F94304  AA                       tax
 6877  F94305  F0 09                    beq     ?12
 6878  F94307  C0 60                    cpy     #cmdlen
 6879  F94309  90 DF                    bcc     ?04
 6880  F9430B  A9 20            ?11:    lda     #longln         ; long line error
 6881  F9430D  4C 07 41                 jmp     cmderr
 6882  F94310  84 41            ?12:    sty     cmdsiz          ; not counting final '0'
 6883  F94312  24 F9                    bit     cmdtrap
 6884  F94314  30 08                    bmi     cmdrst          ; cmd. empty string is ok
 6885  F94316  BB                       tyx
 6886  F94317  D0 05                    bne     cmdrst
 6887  F94319  A9 25                    lda     #nullln         ; empty command string error
 6888  F9431B  4C 07 41                 jmp     cmderr
 6889  F9431E                           
 6890                           ; clear vars & tbls
 6891  F9431E                   cmdrst:
 6892  F9431E  A0 00                    ldy     #0
 6893  F94320  98                       tya
 6894  F94321  85 0E                    sta     type
 6895  F94323  85 0F                    sta     mode
 6896  F94325  85 10                    sta     typflg
 6897  F94327  85 14                    sta     f1ptr
 6898  F94329  85 15                    sta     f2ptr
 6899  F9432B  85 12                    sta     f1cnt
 6900  F9432D  85 13                    sta     f2cnt
 6901  F9432F  85 11                    sta     patflg
 6902  F94331  85 56                    sta     lsterr
 6903  F94333  85 93                    sta     tmp0
 6904  F94335  85 1F                    sta     tmpxxx
 6905  F94337  85 F8                    sta     trap
 6906  F94339  85 E6                    sta     wrop
 6907  F9433B  A2 05                    ldx     #mxfils
 6908  F9433D  95 19            ?10:    sta     filtbl-1,x
 6909  F9433F  95 29                    sta     entsec-1,x
 6910  F94341  95 2E                    sta     entind-1,x
 6911  F94343  95 33                    sta     fildrv-1,x
 6912  F94345  95 38                    sta     pattyp-1,x
 6913  F94347  95 1F                    sta     filtrk-1,x
 6914  F94349  95 24                    sta     filsec-1,x
  Tue Jul 17 11:00:19 2018                                                                                               Page   79




 6915  F9434B  CA                       dex
 6916  F9434C  D0 EF                    bne     ?10
 6917  F9434E  60                       rts      
 6918                           
 6919                           ;---------------------------------------------------------------------------
 6920                           ; read/write on fd
 6921                           ;---------------------------------------------------------------------------
 6922                           
 6923                           ; buffered read/write on file
 6924                           ; in:   X = channel
 6925                           ;       Y = op (read/write)
 6926  F9434F                   fd_rw:
 6927  F9434F                           ACC16
 6928  F9434F  C2 20                    rep     #PMFLAG
 6929                                   .LONGA  on
 6930                                   .MNLIST
 6931  F94351  3B                       tsc                     ; save current stack pointer
 6932  F94352  8D F8 E1                 sta     !tos
 6933  F94355                           ACC08
 6934  F94355  E2 20                    sep     #PMFLAG
 6935                                   .LONGA  off
 6936                                   .MNLIST
 6937  F94357  E0 0F                    cpx     #$0F
 6938  F94359  D0 26                    bne     ?08             ; file
 6939  F9435B  98                       tya
 6940  F9435C  F0 02                    beq     ?02             ; read on channel 15
 6941  F9435E  18                       clc                     ; write on channel 15 is no-op
 6942  F9435F  60                       rts
 6943  F94360  20 1A 57         ?02:    jsr     fmterr          ; format error string (bytes # in btrf)
 6944  F94363  64 56                    stz     lsterr  
 6945  F94365  A0 00                    ldy     #0
 6946  F94367                           INDEX16
 6947  F94367  C2 10                    rep     #PXFLAG
 6948                                   .LONGI  on
 6949                                   .MNLIST
 6950  F94369  B9 00 E1         ?04:    lda     cmdbuf,y
 6951  F9436C  97 90                    sta     [wbuf],y
 6952  F9436E  F0 0A                    beq     ?06             ; end of transfer
 6953  F94370  C8                       iny
 6954  F94371  C4 86                    cpy     bsize
 6955  F94373  90 F4                    bcc     ?04
 6956  F94375  88                       dey
 6957  F94376  A9 00                    lda     #0              ; trunc string
 6958  F94378  97 90                    sta     [wbuf],y
 6959  F9437A  C8               ?06:    iny
 6960  F9437B  84 88                    sty     btrf
 6961  F9437D                           INDEX08 
 6962  F9437D  E2 10                    sep     #PXFLAG
 6963                                   .LONGI  off
 6964                                   .MNLIST
 6965  F9437F  18                       clc
 6966  F94380  60                       rts
 6967  F94381  64 56            ?08:    stz     lsterr
 6968  F94383  64 E6                    stz     wrop
 6969  F94385  98                       tya
 6970  F94386  F0 04                    beq     ?10
 6971  F94388  A9 80                    lda     #$80
  Tue Jul 17 11:00:19 2018                                                                                               Page   80




 6972  F9438A  85 E6                    sta     wrop
 6973  F9438C  20 76 48         ?10:    jsr     fndfd           ; check file (read/write)
 6974  F9438F  20 E2 48                 jsr     fddrv           ; get associate drive #
 6975  F94392  B5 59                    lda     lintab,x
 6976  F94394  89 20                    bit     #$20
 6977  F94396  F0 03                    beq     ?12
 6978  F94398  4C 70 44                 jmp     fdlist          ; buffered load dir
 6979  F9439B  89 40            ?12:    bit     #$40
 6980  F9439D  F0 03                    beq     ?14
 6981  F9439F  4C 82 45                 jmp     fdda
 6982  F943A2  24 E6            ?14:    bit     wrop
 6983  F943A4  30 5F                    bmi     fdwrite
 6984                           ;       bmi     ?14
 6985                           ;       jmp     fdread
 6986                           ;?14:   jmp     fdwrite
 6987                           
 6988                           ; read a block of data from file and transfer to destination buffer
 6989                           ; before to call this function these var's should be initialized:
 6990                           ;       lindx   =file descriptor (logical index)
 6991                           ;       bsize   =size of destination buffer
 6992                           ;       wbuf    =long pointer to destination buffer
 6993                           ;
 6994                           ; this function return when:
 6995                           ;       1) destination buffer is full, and/or
 6996                           ;       2) the eof condition is true
 6997                           ;          in this case the bit 7 of fdst is set
 6998                           ;
 6999                           ; on exit, btrf contain the effective transferred bytes count #
 7000                           ;
 7001  F943A6                   fdread:
 7002  F943A6  64 88                    stz     btrf            ; clear count of readden bytes
 7003  F943A8  64 89                    stz     btrf+1
 7004  F943AA  A6 57                    ldx     lindx           ; file descriptor
 7005  F943AC  34 96                    bit     fdst,x          ; test if eof
 7006  F943AE  30 53                    bmi     ?40             ; yes, eof
 7007  F943B0  A5 19                    lda     drvnum          ; set up read drive #
 7008  F943B2  85 E8                    sta     rddrv
 7009  F943B4  B4 AE                    ldy     ftrk,x
 7010  F943B6  84 08                    sty     track           ; set up current file track
 7011  F943B8  B5 B6                    lda     fsec,x
 7012  F943BA  85 09                    sta     sector          ; setup current file sector
 7013  F943BC  B4 BE                    ldy     fdptr,x
 7014  F943BE  84 E9                    sty     rdidx           ; set file pointer in this blk
 7015  F943C0  20 AB 57                 jsr     tread           ; read whole track in read cache
 7016  F943C3  20 4A 56                 jsr     setcp           ; set up bufp pointer
 7017  F943C6  64 EA                    stz     rdlst           ; assume full block (not last blk)
 7018  F943C8  A0 01                    ldy     #1
 7019  F943CA  B7 8A                    lda     [bufp],y        ; read link to next block
 7020  F943CC  A8                       tay                     ; next sector or last byte ptr
 7021  F943CD  A7 8A                    lda     [bufp]          ; next libnk track
 7022  F943CF  D0 02                    bne     ?10             ; no end of file
 7023  F943D1  84 EA                    sty     rdlst           ; last byte pointer (this is last blk)
 7024  F943D3  64 EB            ?10:    stz     rdeof           ; clear eof flag
 7025  F943D5  20 B8 45         ?20:    jsr     bufget          ; get next byte from disk buffer
 7026  F943D8                           INDEX16
 7027  F943D8  C2 10                    rep     #PXFLAG
 7028                                   .LONGI  on
  Tue Jul 17 11:00:19 2018                                                                                               Page   81




 7029                                   .MNLIST
 7030  F943DA  A4 88                    ldy     btrf            ; current dest buffer ptr
 7031  F943DC  97 90                    sta     [wbuf],y        ; store in dest buffer
 7032  F943DE  C8                       iny
 7033  F943DF  84 88                    sty     btrf            ; update ptr
 7034  F943E1  C4 86                    cpy     bsize           ; check size of dest buffer
 7035  F943E3                           INDEX08
 7036  F943E3  E2 10                    sep     #PXFLAG
 7037                                   .LONGI  off
 7038                                   .MNLIST
 7039  F943E5  B0 04                    bcs     ?30             ; dest buffer is full
 7040  F943E7  A5 EB                    lda     rdeof           ; eof?
 7041  F943E9  F0 EA                    beq     ?20             ; no -- get next byte
 7042  F943EB  A6 57            ?30:    ldx     lindx
 7043  F943ED  A4 08                    ldy     track
 7044  F943EF  94 AE                    sty     ftrk,x          ; save current fd
 7045  F943F1  A5 09                    lda     sector
 7046  F943F3  95 B6                    sta     fsec,x
 7047  F943F5  A4 E9                    ldy     rdidx
 7048  F943F7  94 BE                    sty     fdptr,x
 7049  F943F9  A5 EB                    lda     rdeof
 7050  F943FB  F0 06                    beq     ?40             ; no eof
 7051  F943FD  A9 80                    lda     #$80
 7052  F943FF  15 96                    ora     fdst,x
 7053  F94401  95 96                    sta     fdst,x          ; eof signal
 7054  F94403  18               ?40:    clc     
 7055  F94404  60                       rts
 7056                           
 7057                           ; write a block of data from source buffer to file
 7058                           ; before to call this function these var's should be initialized:
 7059                           ;       lindx   =file descriptor (logical index)
 7060                           ;       bsize   =number of bytes to write
 7061                           ;       wbuf    =long pointer to destination buffer
 7062                           ;
 7063                           ; on exit, btrf contain the effective transferred bytes count #
 7064                           ;
 7065  F94405                   fdwrite:
 7066  F94405  64 EB                    stz     rdeof
 7067  F94407                           ACC16
 7068  F94407  C2 20                    rep     #PMFLAG
 7069                                   .LONGA  on
 7070                                   .MNLIST
 7071  F94409  64 88                    stz     btrf            ; clear count of written bytes
 7072  F9440B  A5 86                    lda     bsize           ; nothing to write?
 7073  F9440D                           ACC08
 7074  F9440D  E2 20                    sep     #PMFLAG
 7075                                   .LONGA  off
 7076                                   .MNLIST
 7077  F9440F  F0 5D                    beq     ?10             ; yes, nothing
 7078  F94411  A6 57                    ldx     lindx           ; file descriptor
 7079  F94413  A5 19                    lda     drvnum          ; set up write drive #
 7080  F94415  85 EC                    sta     wrdrv
 7081  F94417  B4 AE                    ldy     ftrk,x
 7082  F94419  84 08                    sty     track           ; set up current file track
 7083  F9441B  B5 B6                    lda     fsec,x
 7084  F9441D  85 09                    sta     sector          ; setup current file sector
 7085  F9441F  85 EE                    sta     wsec            ; current sector to write in cache
  Tue Jul 17 11:00:19 2018                                                                                               Page   82




 7086  F94421  85 EF                    sta     wfirst          ; first sector to write in cache        
 7087  F94423  B4 BE                    ldy     fdptr,x
 7088  F94425  84 ED                    sty     wridx           ; set file pointer in this blk  
 7089  F94427  A6 F7                    ldx     dblfd
 7090  F94429                           ACC16
 7091  F94429  C2 20                    rep     #PMFLAG
 7092                                   .LONGA  on
 7093                                   .MNLIST
 7094  F9442B  B5 C6                    lda     fdblk,x         ; set up block's count
 7095  F9442D  85 F0                    sta     wcnt
 7096  F9442F  A5 90                    lda     wbuf            ; wbuf is used by write cache
 7097  F94431  85 8A                    sta     bufp            ; bufp is the src. buffer
 7098  F94433                           ACC08
 7099  F94433  E2 20                    sep     #PMFLAG
 7100                                   .LONGA  off
 7101                                   .MNLIST
 7102  F94435  A5 92                    lda     wbuf+2
 7103  F94437  85 8C                    sta     bufp+2
 7104  F94439  20 C1 57                 jsr     wread           ; pre-read track in write cache
 7105  F9443C  20 5A 56                 jsr     setwb           ; set buffer wbuf to cache
 7106  F9443F                   ?02:    INDEX16
 7107  F9443F  C2 10                    rep     #PXFLAG
 7108                                   .LONGI  on
 7109                                   .MNLIST
 7110  F94441  A4 88                    ldy     btrf            ; transfer src. buffer to cache
 7111  F94443  B7 8A                    lda     [bufp],y
 7112  F94445  C8                       iny
 7113  F94446  84 88                    sty     btrf            ; bump pointer
 7114  F94448  C4 86                    cpy     bsize
 7115  F9444A                           INDEX08
 7116  F9444A  E2 10                    sep     #PXFLAG
 7117                                   .LONGI  off
 7118                                   .MNLIST
 7119  F9444C  08                       php
 7120  F9444D  20 08 46                 jsr     bufput          ; put in cache  
 7121  F94450  28                       plp
 7122  F94451  90 EC                    bcc     ?02             ; loop
 7123  F94453  20 7A 46                 jsr     wrtcache        ; flush cache on disk
 7124  F94456  A6 57                    ldx     lindx
 7125  F94458  A5 08                    lda     track
 7126  F9445A  95 AE                    sta     ftrk,x
 7127  F9445C  A5 09                    lda     sector
 7128  F9445E  95 B6                    sta     fsec,x
 7129  F94460  A4 ED                    ldy     wridx
 7130  F94462  94 BE                    sty     fdptr,x
 7131  F94464  A6 F7                    ldx     dblfd
 7132  F94466                           ACC16
 7133  F94466  C2 20                    rep     #PMFLAG
 7134                                   .LONGA  on
 7135                                   .MNLIST
 7136  F94468  A5 F0                    lda     wcnt
 7137  F9446A  95 C6                    sta     fdblk,x
 7138  F9446C                           ACC08
 7139  F9446C  E2 20                    sep     #PMFLAG
 7140                                   .LONGA  off
 7141                                   .MNLIST
 7142  F9446E  18               ?10:    clc
  Tue Jul 17 11:00:19 2018                                                                                               Page   83




 7143  F9446F  60                       rts
 7144                           
 7145                           ; read a block of data from dir listing and transfer to destination buffer
 7146                           ; before to call this function these var's should be initialized:
 7147                           ;       lindx   =file descriptor (logical index)
 7148                           ;       bsize   =size of destination buffer
 7149                           ;       wbuf    =long pointer to destination buffer
 7150                           ;
 7151                           ; this function return when:
 7152                           ;       1) destination buffer is full, and/or
 7153                           ;       2) the eof condition is true
 7154                           ;          in this case the bit 7 of fdst is set
 7155                           ;
 7156                           ; on exit, btrf contain the effective transferred bytes count #
 7157                           ;
 7158  F94470                   fdlist:
 7159  F94470  20 15 49                 jsr     setfdp          ; set buffer for this fd & return X=lindx
 7160  F94473  64 88                    stz     btrf            ; clear count of readden bytes
 7161  F94475  64 89                    stz     btrf+1
 7162  F94477  34 96                    bit     fdst,x          ; test if eof
 7163  F94479  30 32                    bmi     ?40             ; yes, eof
 7164  F9447B  B4 BE                    ldy     fdptr,x
 7165  F9447D  84 E9                    sty     rdidx           ; set file pointer in this blk
 7166  F9447F  64 EB                    stz     rdeof           ; clear eof flag
 7167  F94481  20 D7 46                 jsr     exxzp           ; get zp var's for dir searching        
 7168  F94484  20 B3 46         ?20:    jsr     bufget2         ; get next byte from list buffer
 7169  F94487                           INDEX16
 7170  F94487  C2 10                    rep     #PXFLAG
 7171                                   .LONGI  on
 7172                                   .MNLIST
 7173  F94489  A4 88                    ldy     btrf            ; current dest buffer ptr
 7174  F9448B  97 90                    sta     [wbuf],y        ; store in dest buffer
 7175  F9448D  C8                       iny
 7176  F9448E  84 88                    sty     btrf            ; update ptr
 7177  F94490  C4 86                    cpy     bsize           ; check size of dest buffer
 7178  F94492                           INDEX08
 7179  F94492  E2 10                    sep     #PXFLAG
 7180                                   .LONGI  off
 7181                                   .MNLIST
 7182  F94494  B0 04                    bcs     ?30             ; dest buffer is full
 7183  F94496  A5 EB                    lda     rdeof           ; eof?
 7184  F94498  F0 EA                    beq     ?20             ; no -- get next byte
 7185  F9449A  20 D7 46         ?30:    jsr     exxzp           ; restore zp var's      
 7186  F9449D  A6 57                    ldx     lindx
 7187  F9449F  A4 E9                    ldy     rdidx
 7188  F944A1  94 BE                    sty     fdptr,x
 7189  F944A3  A5 EB                    lda     rdeof
 7190  F944A5  F0 06                    beq     ?40             ; no eof
 7191  F944A7  A9 80                    lda     #$80
 7192  F944A9  15 96                    ora     fdst,x
 7193  F944AB  95 96                    sta     fdst,x          ; eof signal
 7194  F944AD  18               ?40:    clc     
 7195  F944AE  60                       rts
 7196                           
 7197                           ; close file
 7198                           ; in:   X = channel
 7199                           ; if chnl=15 all open files will be closed
  Tue Jul 17 11:00:19 2018                                                                                               Page   84




 7200  F944AF                   fdcls:
 7201  F944AF                           ACC16
 7202  F944AF  C2 20                    rep     #PMFLAG
 7203                                   .LONGA  on
 7204                                   .MNLIST
 7205  F944B1  3B                       tsc                     ; save current stack pointer
 7206  F944B2  8D F8 E1                 sta     !tos
 7207  F944B5                           ACC08
 7208  F944B5  E2 20                    sep     #PMFLAG
 7209                                   .LONGA  off
 7210                                   .MNLIST
 7211  F944B7  8A                       txa
 7212  F944B8  F0 2E                    beq     ?28             ; read only chnl so just free lindx & chnl
 7213  F944BA  E0 0F                    cpx     #$0F
 7214  F944BC  D0 0E                    bne     ?20             ; close channel 1..14
 7215  F944BE  A2 0E                    ldx     #mxchnls-1      ; closing chnl 15 close all open files
 7216  F944C0  86 52            ?02:    stx     chnl
 7217  F944C2  20 CC 44                 jsr     ?20             ; close chnl X
 7218  F944C5  A6 52                    ldx     chnl
 7219  F944C7  CA                       dex
 7220  F944C8  10 F6                    bpl     ?02
 7221  F944CA  18               ?04:    clc     
 7222  F944CB  60                       rts
 7223  F944CC  B5 59            ?20:    lda     lintab,x        ; close chnl X
 7224  F944CE  C9 FF                    cmp     #$FF
 7225  F944D0  F0 F8                    beq     ?04             ; is closed
 7226  F944D2  89 40                    bit     #$40            ; direct access?
 7227  F944D4  D0 0F                    bne     ?26             ; yes, just update bam
 7228  F944D6  29 07                    and     #$07
 7229  F944D8  85 57                    sta     lindx           ; associated logical index
 7230  F944DA  20 E2 48                 jsr     fddrv           ; get associated drive
 7231  F944DD  20 B2 48                 jsr     fndwfd          ; look for write fd
 7232  F944E0  B0 06                    bcs     ?28             ; read fd: just free lindx
 7233  F944E2  20 ED 44                 jsr     clswfd
 7234  F944E5  20 02 58         ?26:    jsr     bamout  
 7235  F944E8  20 F0 47         ?28:    jsr     frefd           ; free fd
 7236  F944EB  18                       clc
 7237  F944EC  60                       rts
 7238                           
 7239                           ; close a write file
 7240                           ;in:    X=lindx
 7241  F944ED                   clswfd:
 7242  F944ED  A5 19                    lda     drvnum          ; set up write drive #
 7243  F944EF  85 EC                    sta     wrdrv
 7244  F944F1  B4 AE                    ldy     ftrk,x
 7245  F944F3  84 08                    sty     track           ; set up current file track
 7246  F944F5  B5 B6                    lda     fsec,x
 7247  F944F7  85 09                    sta     sector          ; setup current file sector
 7248  F944F9  85 EE                    sta     wsec            ; current sector to write in cache
 7249  F944FB  85 EF                    sta     wfirst          ; first sector to write in cache        
 7250  F944FD  B4 BE                    ldy     fdptr,x
 7251  F944FF  84 ED                    sty     wridx           ; set file pointer in this blk  
 7252  F94501  A6 F7                    ldx     dblfd
 7253  F94503                           ACC16
 7254  F94503  C2 20                    rep     #PMFLAG
 7255                                   .LONGA  on
 7256                                   .MNLIST
  Tue Jul 17 11:00:19 2018                                                                                               Page   85




 7257  F94505  B5 C6                    lda     fdblk,x         ; set up block's count
 7258  F94507  1A                       inc     a               ; take in count last blk
 7259  F94508  85 F0                    sta     wcnt
 7260  F9450A                           CPU08
 7261  F9450A  E2 30                    sep     #(PMFLAG.OR.PXFLAG)
 7262                                   .LONGA  off
 7263                                   .LONGI  off
 7264                                   .MNLIST
 7265  F9450C  20 C1 57                 jsr     wread           ; pre-read track in write cache
 7266  F9450F  20 5A 56                 jsr     setwb           ; set buffer bufw to cache
 7267  F94512  A9 00                    lda     #0              ; null link in this block
 7268  F94514  87 90                    sta     [wbuf]          ; finalize sector
 7269  F94516  A0 01                    ldy     #1
 7270  F94518  A5 ED                    lda     wridx           ; last byte ptr (+1)
 7271  F9451A  3A                       dec     a
 7272  F9451B  97 90                    sta     [wbuf],y
 7273  F9451D  20 7A 46                 jsr     wrtcache        ; write out cache
 7274  F94520  A6 57                    ldx     lindx
 7275  F94522  B5 9E                    lda     dsec,x          ; set dir. ptr to file entry
 7276  F94524  85 09                    sta     sector
 7277  F94526  A0 28                    ldy     #dirtrk
 7278  F94528  84 08                    sty     track
 7279  F9452A  20 3D 56                 jsr     sethdp
 7280  F9452D  18                       clc
 7281  F9452E  65 09                    adc     sector
 7282  F94530  85 0B                    sta     dirp+1          ; set dir. pointer to file entry
 7283  F94532  A6 57                    ldx     lindx
 7284  F94534  B5 A6                    lda     dind,x
 7285  F94536  85 0A                    sta     dirp
 7286  F94538  A7 0A                    lda     [dirp]          ; set flag closed file
 7287  F9453A  AA                       tax
 7288  F9453B  29 4F                    and     #$4F            ; reset replace mode
 7289  F9453D  09 80                    ora     #$80
 7290  F9453F  87 0A                    sta     [dirp]
 7291  F94541  A0 1C                    ldy     #28             ; store block's #
 7292  F94543                           ACC16
 7293  F94543  C2 20                    rep     #PMFLAG
 7294                                   .LONGA  on
 7295                                   .MNLIST
 7296  F94545  A5 F0                    lda     wcnt
 7297  F94547  97 0A                    sta     [dirp],y
 7298  F94549                           ACC08
 7299  F94549  E2 20                    sep     #PMFLAG
 7300                                   .LONGA  off
 7301                                   .MNLIST
 7302  F9454B  8A                       txa
 7303  F9454C  89 20                    bit     #$20            ; replace flag?
 7304  F9454E  F0 2F                    beq     ?10             ; no
 7305  F94550  A0 1A                    ldy     #26
 7306  F94552  B7 0A                    lda     [dirp],y        ; get new start link
 7307  F94554  AA                       tax                     ; X=new track
 7308  F94555  C8                       iny
 7309  F94556  B7 0A                    lda     [dirp],y
 7310  F94558  EB                       xba                     ; B=new sec
 7311  F94559  A0 01                    ldy     #1
 7312  F9455B  B7 0A                    lda     [dirp],y        ; old start track
 7313  F9455D  48                       pha
  Tue Jul 17 11:00:19 2018                                                                                               Page   86




 7314  F9455E  8A                       txa                     ; new start track
 7315  F9455F  97 0A                    sta     [dirp],y
 7316  F94561  FA                       plx                     ; X=old start track
 7317  F94562  C8                       iny
 7318  F94563  B7 0A                    lda     [dirp],y        ; old start sec
 7319  F94565  EB                       xba                     ; A=new start sec, B=old start sec
 7320  F94566  97 0A                    sta     [dirp],y
 7321  F94568  EB                       xba                     ; A=old start sec
 7322  F94569  A0 1B                    ldy     #27
 7323  F9456B  97 0A                    sta     [dirp],y        ; save old start sector
 7324  F9456D  48                       pha
 7325  F9456E  88                       dey
 7326  F9456F  8A                       txa
 7327  F94570  97 0A                    sta     [dirp],y        ; save old start track
 7328  F94572  48                       pha
 7329  F94573  20 57 36                 jsr     wrdsec          ; update directory
 7330  F94576  68                       pla
 7331  F94577  85 08                    sta     track
 7332  F94579  68                       pla
 7333  F9457A  85 09                    sta     sector
 7334  F9457C  4C 38 33                 jmp     delfil          ; delete old file
 7335  F9457F  4C 57 36         ?10:    jmp     wrdsec
 7336                           
 7337  F94582                   fdda:
 7338  F94582  64 88                    stz     btrf            ; clear count of readden bytes
 7339  F94584  64 89                    stz     btrf+1
 7340  F94586  A6 57                    ldx     lindx           ; file descriptor
 7341  F94588  24 E6                    bit     wrop
 7342                                   ;bmi    ???
 7343  F9458A  34 96                    bit     fdst,x          ; test if eof
 7344  F9458C  30 28                    bmi     ?40             ; yes, eof
 7345  F9458E  B4 BE                    ldy     fdptr,x
 7346  F94590  A4 88            ?10:    ldy     btrf            ; current dest buffer ptr
 7347  F94592  97 90                    sta     [wbuf],y        ; store in dest buffer
 7348  F94594  C8                       iny
 7349  F94595  84 88                    sty     btrf            ; update ptr
 7350  F94597  C4 86                    cpy     bsize           ; check size of dest buffer
 7351  F94599                           INDEX08
 7352  F94599  E2 10                    sep     #PXFLAG
 7353                                   .LONGI  off
 7354                                   .MNLIST
 7355  F9459B  B0 01                    bcs     ?30             ; dest buffer is full
 7356  F9459D  98                       tya                     ; eof?
 7357                                   ;bne    ?20             ; no -- get next byte
 7358  F9459E  A6 57            ?30:    ldx     lindx
 7359  F945A0  A4 08                    ldy     track
 7360  F945A2  94 AE                    sty     ftrk,x          ; save current fd
 7361  F945A4  A5 09                    lda     sector
 7362  F945A6  95 B6                    sta     fsec,x
 7363  F945A8  A4 E9                    ldy     rdidx
 7364  F945AA  94 BE                    sty     fdptr,x
 7365  F945AC  A5 EB                    lda     rdeof
 7366  F945AE  F0 06                    beq     ?40             ; no eof
 7367  F945B0  A9 80                    lda     #$80
 7368  F945B2  15 96                    ora     fdst,x
 7369  F945B4  95 96                    sta     fdst,x          ; eof signal
 7370  F945B6  18               ?40:    clc     
  Tue Jul 17 11:00:19 2018                                                                                               Page   87




 7371  F945B7  60                       rts
 7372                           
 7373                           ; get next byte from read cache in buffered operation
 7374                           ; read a new whole track in cache if needed
 7375                           ; update pointer and set EOF status in rdeof
 7376                           ; out:  A = byte
 7377                           ;       rdeof not null if EOF
 7378                           ;       rdidx updated
 7379                           ; before to call this function:
 7380                           ;       pre-read whole track in cache
 7381                           ;       set bufp long pointer to cache and sector
 7382                           ;       set rdix=2, rdeof=0, rddrv=drive#
 7383                           ;       rdlst=0 if file have a next block
 7384                           ;            =last index if this is last block of file
 7385  F945B8                   bufget:
 7386  F945B8  A4 E9                    ldy     rdidx           ; current buffer pointer
 7387  F945BA  A5 EA                    lda     rdlst
 7388  F945BC  F0 08                    beq     ?02             ; full buffer
 7389  F945BE  C4 EA                    cpy     rdlst           ; end of buffer?
 7390  F945C0  D0 04                    bne     ?02             ; no    
 7391  F945C2  B7 8A                    lda     [bufp],y        ; get byte
 7392  F945C4  80 07                    bra     ?04
 7393  F945C6  B7 8A            ?02:    lda     [bufp],y        ; get byte
 7394  F945C8  C8                       iny                     ; bump ptr and set/reset Z
 7395  F945C9  84 E9                    sty     rdidx
 7396  F945CB  D0 06                    bne     ?05             ; exit (no EOF)
 7397  F945CD  A4 EA            ?04:    ldy     rdlst
 7398  F945CF  F0 03                    beq     ?06             ; read next file block
 7399  F945D1  84 EB                    sty     rdeof           ; EOF
 7400  F945D3  60               ?05:    rts
 7401  F945D4  85 E7            ?06:    sta     data            ; save byte
 7402  F945D6  A6 E8                    ldx     rddrv
 7403  F945D8  86 19                    stx     drvnum
 7404  F945DA  A0 01                    ldy     #1              ; read link to next block
 7405  F945DC  B7 8A                    lda     [bufp],y
 7406  F945DE  85 09                    sta     sector
 7407  F945E0  A8                       tay
 7408  F945E1  A7 8A                    lda     [bufp]          ; read link
 7409  F945E3  C5 08                    cmp     track           ; same track?
 7410  F945E5  85 08                    sta     track
 7411  F945E7  F0 05                    beq     ?08             ; ok, still in cache
 7412  F945E9  20 AB 57                 jsr     tread           ; read whole track
 7413  F945EC  A4 09                    ldy     sector
 7414  F945EE  98               ?08:    tya                     ; set pointer to track/sec cache
 7415  F945EF  18                       clc
 7416  F945F0  75 78                    adc     trkofs,x        ; add start of dma buffer
 7417  F945F2  85 8B                    sta     bufp+1
 7418  F945F4  64 EA                    stz     rdlst           ; assume full buffer
 7419  F945F6  A0 01                    ldy     #1
 7420  F945F8  B7 8A                    lda     [bufp],y        ; next sector
 7421  F945FA  A8                       tay
 7422  F945FB  A7 8A                    lda     [bufp]          ; next track
 7423  F945FD  D0 02                    bne     ?10             ; is not last block
 7424  F945FF  84 EA                    sty     rdlst           ; is last block
 7425  F94601  A0 02            ?10:    ldy     #2
 7426  F94603  84 E9                    sty     rdidx           ; set start pointer for next get
 7427  F94605  A5 E7                    lda     data            ; get byte
  Tue Jul 17 11:00:19 2018                                                                                               Page   88




 7428  F94607  60                       rts                     ; not EOF
 7429                           
 7430                           ; put byte in write cache in buffered operation
 7431                           ; update buffer pointer, allocate a new t&s if needed
 7432                           ; update t&s link of the file and write out the cache if needed
 7433                           ; in:   A=byte
 7434                           ;       wridx=buffer pointer
 7435                           ;       wrdrv=drive#
 7436                           ;       wfirst=first sector written in this track
 7437                           ;       wsec=current sector written in this track
 7438                           ;       wcnt=current count of file block's
 7439                           ;       rdeof=flag eof when put last byte
 7440                           ;       wbuf=long pointer to cache and sector
 7441                           ; before to call this function will pre-read the track
 7442                           ; of first block of the file (into write cache)
 7443  F94608                   bufput:
 7444  F94608  A4 ED                    ldy     wridx           ; need to allocate a new block?
 7445  F9460A  D0 07                    bne     ?04             ; no, store
 7446  F9460C                           
 7447                                   ; this can happen when append data to current file
 7448                                   ; and last byte of last block was $FF
 7449                                   ; need to allocate a new block
 7450  F9460C  85 E7                    sta     data            ; save byte to store
 7451                                   ;lda    wsec            ; must save just this sector
 7452                                   ;sta    wfirst          ; set first=last sector
 7453  F9460E  20 35 46                 jsr     ?08             ; update cache and alloc new sector...
 7454  F94611  A5 E7                    lda     data            ; ...return Y=wrdix
 7455  F94613  97 90            ?04:    sta     [wbuf],y        ; store data at
 7456  F94615  A5 EB                    lda     rdeof           ; test eof
 7457  F94617  D0 04                    bne     ?06             ; eof: this is last byte
 7458  F94619  C8                       iny                     ; bump pointer
 7459  F9461A  84 ED                    sty     wridx
 7460                                   ;beq    ?08             ; need a new block
 7461  F9461C  60                       rts
 7462  F9461D  A9 00            ?06:    lda     #0              ; null link in this block
 7463  F9461F  87 90                    sta     [wbuf]          ; finalize sector
 7464  F94621  A0 01                    ldy     #1
 7465  F94623  A5 ED                    lda     wridx           ; last byte ptr
 7466  F94625  97 90                    sta     [wbuf],y
 7467  F94627  A6 EC                    ldx     wrdrv           ; restore drive #
 7468  F94629  86 19                    stx     drvnum
 7469  F9462B  B5 82                    lda     wcache,x        ; restore current track
 7470  F9462D  85 08                    sta     track
 7471  F9462F  20 7A 46                 jsr     wrtcache        ; write out cache
 7472  F94632  E6 ED                    inc     wridx           ; bump pointer (can be null!!)
 7473  F94634  60                       rts
 7474  F94635  A6 EC            ?08:    ldx     wrdrv           ; set drive #
 7475  F94637  86 19                    stx     drvnum
 7476  F94639  B5 82                    lda     wcache,x        ; restore current t&s
 7477  F9463B  85 08                    sta     track
 7478  F9463D  A5 EE                    lda     wsec
 7479  F9463F  85 09                    sta     sector
 7480  F94641  20 FC 4C                 jsr     nxtts           ; alloc a new sector
 7481  F94644  A6 19                    ldx     drvnum
 7482  F94646  A0 01                    ldy     #1
 7483  F94648  A5 09                    lda     sector          ; set link to new sector 
 7484  F9464A  97 90                    sta     [wbuf],y
  Tue Jul 17 11:00:19 2018                                                                                               Page   89




 7485  F9464C  A8                       tay                     ; Y=sector
 7486  F9464D  A5 08                    lda     track
 7487  F9464F  87 90                    sta     [wbuf]
 7488  F94651  D5 82                    cmp     wcache,x        ; same track?
 7489  F94653  F0 12                    beq     ?10             ; yes
 7490  F94655  48                       pha                     ; save new track
 7491  F94656  B5 82                    lda     wcache,x        ; set old track
 7492  F94658  85 08                    sta     track
 7493  F9465A  20 7A 46                 jsr     wrtcache        ; write out cache
 7494  F9465D  68                       pla
 7495  F9465E  85 08                    sta     track           ; restore new track
 7496  F94660  20 C1 57                 jsr     wread           ; read the new whole track in write cache
 7497  F94663  A4 09                    ldy     sector
 7498  F94665  84 EF                    sty     wfirst          ; set first dirty sec   
 7499  F94667  84 EE            ?10:    sty     wsec            ; update current sector
 7500  F94669  18                       clc
 7501  F9466A  98                       tya
 7502  F9466B  75 7C                    adc     wrtofs,x        ; set pointer to sector
 7503  F9466D  85 91                    sta     wbuf+1
 7504  F9466F                           ACC16
 7505  F9466F  C2 20                    rep     #PMFLAG
 7506                                   .LONGA  on
 7507                                   .MNLIST
 7508  F94671  E6 F0                    inc     wcnt            ; update block's #
 7509  F94673                           ACC08
 7510  F94673  E2 20                    sep     #PMFLAG
 7511                                   .LONGA  off
 7512                                   .MNLIST
 7513  F94675  A0 02                    ldy     #2              ; set start of pointer
 7514  F94677  84 ED                    sty     wridx
 7515  F94679  60                       rts
 7516                           
 7517  F9467A                   wrtcache:
 7518  F9467A  A6 19                    ldx     drvnum
 7519  F9467C  A5 EF                    lda     wfirst          ; first dirty sec
 7520  F9467E  4A                       lsr     a
 7521  F9467F  85 1F                    sta     tmpxxx          ; dma buffer offset
 7522  F94681  A8                       tay
 7523  F94682  A5 EE                    lda     wsec            ; last dirty sector of this track
 7524  F94684  4A                       lsr     a
 7525  F94685  C9 0A                    cmp     #phisec         ; if last is in side 0...
 7526  F94687  90 09                    bcc     ?10             ; ...write out side 0 only
 7527  F94689  C0 0A                    cpy     #phisec         ; if first is in side 1...
 7528  F9468B  B0 05                    bcs     ?10             ; ...write out side 1 only
 7529  F9468D  B5 72                    lda     wrtbuf,x        ; dma buffer #
 7530  F9468F  4C DF 57                 jmp     writetk         ; write out whole track
 7531  F94692  64 F3            ?10:    stz     pside           ; assume side 0
 7532  F94694  1A                       inc     a               ; A = last phis. sec
 7533  F94695  C8                       iny                     ; Y = first phis. sec
 7534  F94696  90 0B                    bcc     ?15             ; write out side 0
 7535  F94698  E6 F3                    inc     pside           ; side 1
 7536  F9469A  E9 0A                    sbc     #phisec
 7537  F9469C  EB                       xba                     ; B = last phis. sec
 7538  F9469D  98                       tya
 7539  F9469E  38                       sec
 7540  F9469F  E9 0A                    sbc     #phisec
 7541  F946A1  A8                       tay                     ; Y = first phis. sec.
  Tue Jul 17 11:00:19 2018                                                                                               Page   90




 7542  F946A2  EB                       xba                     ; A = last phis. sec
 7543  F946A3  84 94            ?15:    sty     wtmp
 7544  F946A5  38                       sec
 7545  F946A6  E5 94                    sbc     wtmp            ; last - start + 1...
 7546  F946A8  1A                       inc     a               ; ...number's of sec to write out
 7547  F946A9  EB                       xba                     ; B = sec. count #
 7548  F946AA  B5 72                    lda     wrtbuf,x
 7549  F946AC  18                       clc
 7550  F946AD  65 1F                    adc     tmpxxx          ; add sector offset
 7551  F946AF  EB                       xba                     ; B = dma buffer #, A = sec. count #    
 7552  F946B0  4C 86 58                 jmp     writesec
 7553                           
 7554                           ; get next byte from dir listing cache -- special case for loaddir 
 7555                           ; update pointer and set EOF status in rdeof
 7556                           ; out:  A = byte
 7557                           ;       rdeof not null if EOF
 7558                           ;       rdidx updated
 7559                           ; before to call this function:
 7560                           ;       prepare dir listing in cache
 7561                           ;       set bufp long pointer to cache
 7562                           ;       set rdix=0, rdeof=0, rddrv=drive#
 7563                           ;       rdlst=0 if dir.listing have a next block
 7564                           ;            =last index if this is last block of dir. listing
 7565  F946B3                   bufget2:
 7566  F946B3  A4 E9                    ldy     rdidx           ; current buffer pointer
 7567  F946B5  A5 EA                    lda     rdlst
 7568  F946B7  F0 08                    beq     ?02             ; use full buffer
 7569  F946B9  C4 EA                    cpy     rdlst           ; end of buffer?
 7570  F946BB  D0 04                    bne     ?02             ; no    
 7571  F946BD  B7 8A                    lda     [bufp],y        ; get byte
 7572  F946BF  80 07                    bra     ?04
 7573  F946C1  B7 8A            ?02:    lda     [bufp],y        ; get byte
 7574  F946C3  C8                       iny                     ; bump ptr and set/reset Z
 7575  F946C4  84 E9                    sty     rdidx
 7576  F946C6  D0 06                    bne     ?05             ; exit (no EOF)
 7577  F946C8  A4 EA            ?04:    ldy     rdlst
 7578  F946CA  F0 03                    beq     ?06             ; read next dir listing block
 7579  F946CC  84 EB                    sty     rdeof           ; EOF
 7580  F946CE  60               ?05:    rts
 7581  F946CF  85 E7            ?06:    sta     data            ; save byte
 7582  F946D1  20 28 49                 jsr     dlist           ; fill buffer with dir listing
 7583  F946D4  A5 E7                    lda     data            ; get byte
 7584  F946D6  60                       rts
 7585                           
 7586                           ; exchange zero page var's while dir listing
 7587                           ; will be used the next buffer (dir list use just one buffer)
 7588  F946D7                   exxzp:
 7589  F946D7  A2 3D                    ldx     #dpsave-1       ; exchange page 0 var's for dir. search
 7590  F946D9  9B                       txy
 7591  F946DA  E6 8B                    inc     bufp+1          ; next buffer
 7592  F946DC  B7 8A            ?02:    lda     [bufp],y
 7593  F946DE  EB                       xba
 7594  F946DF  B5 00                    lda     zpstart,x
 7595  F946E1  97 8A                    sta     [bufp],y
 7596  F946E3  EB                       xba
 7597  F946E4  95 00                    sta     zpstart,x
 7598  F946E6  88                       dey
  Tue Jul 17 11:00:19 2018                                                                                               Page   91




 7599  F946E7  CA                       dex
 7600  F946E8  10 F2                    bpl     ?02
 7601  F946EA  A9 80                    lda     #$80
 7602  F946EC  85 8A                    sta     bufp
 7603  F946EE  A2 60                    ldx     #fntlen-1       ; exchange file name table
 7604  F946F0  9B                       txy
 7605  F946F1  B7 8A            ?04:    lda     [bufp],y
 7606  F946F3  EB                       xba
 7607  F946F4  BD 61 E1                 lda     !fntab,x
 7608  F946F7  97 8A                    sta     [bufp],y
 7609  F946F9  EB                       xba
 7610  F946FA  9D 61 E1                 sta     !fntab,x
 7611  F946FD  88                       dey
 7612  F946FE  CA                       dex
 7613  F946FF  10 F0                    bpl     ?04
 7614  F94701  64 8A                    stz     bufp            ; restore buffer ptr to listing buffer
 7615  F94703  C6 8B                    dec     bufp+1
 7616  F94705  60                       rts
 7617                           
 7618                           ; save page 0 and file name table in next buffer while dir listing
 7619  F94706                   savzp:
 7620  F94706  A2 3D                    ldx     #dpsave-1       ; save page 0 var's for dir. search
 7621  F94708  9B                       txy
 7622  F94709  E6 8B                    inc     bufp+1          ; next buffer
 7623  F9470B  B5 00            ?02:    lda     zpstart,x
 7624  F9470D  97 8A                    sta     [bufp],y
 7625  F9470F  88                       dey
 7626  F94710  CA                       dex
 7627  F94711  10 F8                    bpl     ?02
 7628  F94713  A9 80                    lda     #$80
 7629  F94715  85 8A                    sta     bufp
 7630  F94717  A2 60                    ldx     #fntlen-1       ; exchange file name table
 7631  F94719  9B                       txy
 7632  F9471A  BD 61 E1         ?04:    lda     !fntab,x
 7633  F9471D  97 8A                    sta     [bufp],y
 7634  F9471F  88                       dey
 7635  F94720  CA                       dex
 7636  F94721  10 F7                    bpl     ?04
 7637  F94723  64 8A                    stz     bufp            ; restore buffer ptr to listing buffer
 7638  F94725  C6 8B                    dec     bufp+1
 7639  F94727  60                       rts
 7640                           
 7641                           ;---------------------------------------------------------------------------
 7642                           ; logical channels helper's
 7643                           ;---------------------------------------------------------------------------
 7644                           
 7645                           ; open a read file
 7646  F94728                   opnrfd:
 7647  F94728  20 BB 47                 jsr     getrfd          ; get a free file descriptor for read
 7648  F9472B  A6 57                    ldx     lindx           ; X=fd
 7649  F9472D  A5 2A                    lda     entsec          ; store dir entry in fd table
 7650  F9472F  A4 2F                    ldy     entind
 7651  F94731  95 9E                    sta     dsec,x
 7652  F94733  94 A6                    sty     dind,x
 7653  F94735  A4 20                    ldy     filtrk          ; store first t&s of file
 7654  F94737  84 08                    sty     track
 7655  F94739  A5 25                    lda     filsec
  Tue Jul 17 11:00:19 2018                                                                                               Page   92




 7656  F9473B  85 09                    sta     sector
 7657  F9473D  94 AE                    sty     ftrk,x
 7658  F9473F  95 B6                    sta     fsec,x
 7659  F94741  A9 02                    lda     #2
 7660  F94743  95 BE                    sta     fdptr,x         ; start of buffer
 7661  F94745  A0 1C                    ldy     #28
 7662  F94747                           ACC16
 7663  F94747  C2 20                    rep     #PMFLAG
 7664                                   .LONGA  on
 7665                                   .MNLIST
 7666  F94749  B7 0A                    lda     [dirp],y        ; store file block's count
 7667  F9474B  A6 F7                    ldx     dblfd
 7668  F9474D  95 C6                    sta     fdblk,x
 7669  F9474F                           ACC08
 7670  F9474F  E2 20                    sep     #PMFLAG
 7671                                   .LONGA  off
 7672                                   .MNLIST
 7673  F94751  60                       rts
 7674                           
 7675                           ; open a write file
 7676                           ; if wrop<7>=0 create file
 7677                           ; if wrop<7>=1 replace file
 7678  F94752                   opnwfd:
 7679  F94752  20 B8 47                 jsr     getwfd          ; get a free file descriptor for write
 7680  F94755  A9 80                    lda     #$80
 7681  F94757  85 F8                    sta     trap            ; trap error for free chnl on error
 7682  F94759  24 E6                    bit     wrop
 7683  F9475B  10 2C                    bpl     ?04             ; create file on dir
 7684  F9475D  20 63 4D                 jsr     intts           ; get a starting t&s for file
 7685  F94760  A7 0A                    lda     [dirp]
 7686  F94762  09 20                    ora     #$20            ; set replace flag on dir entry
 7687  F94764  87 0A                    sta     [dirp]
 7688  F94766  A0 1A                    ldy     #26             ; set replacing link on dir entry
 7689  F94768  A5 08                    lda     track
 7690  F9476A  97 0A                    sta     [dirp],y
 7691  F9476C  85 20                    sta     filtrk
 7692  F9476E  C8                       iny
 7693  F9476F  A5 09                    lda     sector
 7694  F94771  85 25                    sta     filsec
 7695  F94773  97 0A                    sta     [dirp],y
 7696  F94775  20 02 58                 jsr     bamout          ; save bam on disk
 7697  F94778  A5 2A                    lda     entsec
 7698  F9477A  C9 04                    cmp     #4              ; dir entry already sve with bam?
 7699  F9477C  90 17                    bcc     ?10             ; yes
 7700  F9477E  85 09                    sta     sector          ; set sector of dir. entry
 7701  F94780  A9 28                    lda     #dirtrk
 7702  F94782  85 08                    sta     track
 7703  F94784  20 57 36                 jsr     wrdsec          ; save dir sector on disk
 7704  F94787  80 0C                    bra     ?10
 7705  F94789  A9 28            ?04:    lda     #dirtrk
 7706  F9478B  85 08                    sta     track
 7707  F9478D  64 09                    stz     sector
 7708  F9478F  20 3D 56                 jsr     sethdp
 7709  F94792  20 D2 4B                 jsr     addfil          ; create file in directory
 7710  F94795  A6 57            ?10:    ldx     lindx
 7711  F94797  A5 2A                    lda     entsec          ; store dir entry in fd table
 7712  F94799  A4 2F                    ldy     entind
  Tue Jul 17 11:00:19 2018                                                                                               Page   93




 7713  F9479B  95 9E                    sta     dsec,x
 7714  F9479D  94 A6                    sty     dind,x
 7715  F9479F  A4 20                    ldy     filtrk          ; store first t&s of file
 7716  F947A1  84 08                    sty     track
 7717  F947A3  A5 25                    lda     filsec
 7718  F947A5  85 09                    sta     sector
 7719  F947A7  94 AE                    sty     ftrk,x
 7720  F947A9  95 B6                    sta     fsec,x
 7721  F947AB  A9 02                    lda     #2
 7722  F947AD  95 BE                    sta     fdptr,x         ; start of buffer
 7723  F947AF  A6 F7                    ldx     dblfd
 7724  F947B1  74 C6                    stz     fdblk,x         ; clear block's count
 7725  F947B3  74 C7                    stz     fdblk+1,x
 7726  F947B5  64 F8                    stz     trap            ; clear trap error
 7727  F947B7  60                       rts
 7728                           
 7729                           ; allocates a new logical index and associate at given channel
 7730                           ; getwfd allocate a write lindx
 7731                           ; getrfd allocate a read lindx
 7732  F947B8                   getwfd:
 7733  F947B8  38                       sec                     ; set .c=1 indicate write
 7734  F947B9  B0 01                    bcs     getlx
 7735  F947BB                   getrfd:
 7736  F947BB  18                       clc                     ; set .c=0 indicate read
 7737  F947BC                   getlx:
 7738  F947BC  08                       php                     ; save r/w flag (.c)
 7739  F947BD  20 13 48                 jsr     fndlnx          ; get next lindx open
 7740  F947C0  85 57                    sta     lindx
 7741  F947C2  AA                       tax
 7742  F947C3  74 96                    stz     fdst,x
 7743  F947C5  74 9E                    stz     dsec,x
 7744  F947C7  74 A6                    stz     dind,x
 7745  F947C9  74 AE                    stz     ftrk,x
 7746  F947CB  74 B6                    stz     fsec,x
 7747  F947CD  74 BE                    stz     fdptr,x
 7748  F947CF  74 D6                    stz     fdlst,x
 7749  F947D1  74 DE                    stz     fdix,x
 7750  F947D3  0A                       asl     a
 7751  F947D4  85 F7                    sta     dblfd
 7752  F947D6  8A                       txa
 7753  F947D7  A6 52                    ldx     chnl
 7754  F947D9  28                       plp
 7755  F947DA  90 02                    bcc     ?04             ; read
 7756  F947DC  09 80                    ora     #$80            ; set write flag
 7757  F947DE  95 59            ?04:    sta     lintab,x
 7758  F947E0  A5 19                    lda     drvnum
 7759  F947E2  0A                       asl     a
 7760  F947E3  0A                       asl     a
 7761  F947E4  0A                       asl     a
 7762  F947E5  15 59                    ora     lintab,x
 7763  F947E7  95 59                    sta     lintab,x        ; save lindx in lintab
 7764  F947E9  A6 F7                    ldx     dblfd
 7765  F947EB  74 C6                    stz     fdblk,x
 7766  F947ED  74 C7                    stz     fdblk+1,x
 7767  F947EF  60                       rts
 7768                           
 7769                           ; free a file descriptor
  Tue Jul 17 11:00:19 2018                                                                                               Page   94




 7770  F947F0                   frefd:
 7771  F947F0  A6 52                    ldx     chnl
 7772  F947F2  C9 0F                    cmp     #$0F            ; free rd/wrt chnls
 7773  F947F4  F0 1C                    beq     ?25             ; but don't free ch15
 7774  F947F6  B5 59                    lda     lintab,x
 7775  F947F8  C9 FF                    cmp     #$FF
 7776  F947FA  F0 16                    beq     ?25             ; already free
 7777  F947FC  29 07                    and     #$07
 7778  F947FE  85 57                    sta     lindx
 7779  F94800  A9 FF                    lda     #$FF
 7780  F94802  95 59                    sta     lintab,x        ; mark free in lintab
 7781  F94804  A6 57                    ldx     lindx           ; release lindx
 7782  F94806  74 96                    stz     fdst,x
 7783  F94808  A9 01                    lda     #1
 7784  F9480A  CA               ?15:    dex
 7785  F9480B  30 03                    bmi     ?10
 7786  F9480D  0A                       asl     a
 7787  F9480E  D0 FA                    bne     ?15
 7788  F94810  04 58            ?10:    tsb     linuse          ; 1=free 0=used   
 7789  F94812  60               ?25:    rts
 7790                           
 7791                           ; find free lindx to use and mark used in linuse
 7792                           ; return lindx in A
 7793  F94813                   fndlnx:
 7794  F94813  A0 00                    ldy     #0              ; bit counter
 7795  F94815  A9 01                    lda     #1              ; any bit is a logical index
 7796  F94817  24 58            ?10:    bit     linuse          ; 1=free 0=used
 7797  F94819  D0 09                    bne     ?30             ; free index
 7798  F9481B  C8                       iny
 7799  F9481C  0A                       asl     a               ; shift '1' 8 times
 7800  F9481D  D0 F8                    bne     ?10
 7801  F9481F  A9 4C                    lda     #nolinx         ; no free lindx available
 7802  F94821  4C 07 41                 jmp     cmderr
 7803  F94824  14 58            ?30:    trb     linuse          ; mark bit used
 7804  F94826  98                       tya                     ; return lindx in .a
 7805  F94827  60                       rts
 7806                           
 7807                           ; check if entry in file table is open and abort if it is
 7808                           ; in:   X = file stream index to check
 7809                           ; A destroyed
 7810  F94828                   tstopn:
 7811  F94828  5A                       phy
 7812  F94829  86 16                    stx     entfnd          ; index 0..n-1
 7813  F9482B  20 37 48                 jsr     tstfd
 7814  F9482E  B0 05                    bcs     ?02
 7815  F94830  A9 3C                    lda     #filopn
 7816  F94832  4C 07 41                 jmp     cmderr
 7817  F94835  7A               ?02:    ply
 7818  F94836  60                       rts
 7819                           
 7820                           ; test if entfnd is active file from lindx tbl
 7821                           ; c=1 file not active
 7822                           ; c=0 file active x=entfnd,y=lindx
 7823                           ; use tmp0 & tmpxxx
 7824  F94837                   tstfd:
 7825  F94837  A2 00                    ldx     #0              ; start search at top
 7826  F94839  86 93            ?20:    stx     tmp0            ; save to look on
  Tue Jul 17 11:00:19 2018                                                                                               Page   95




 7827  F9483B  B5 59                    lda     lintab,x        ; get lindx
 7828  F9483D  C9 FF                    cmp     #$ff
 7829  F9483F  D0 08                    bne     ?40             ; allocated so test it
 7830  F94841  A6 93            ?30:    ldx     tmp0            ; not active
 7831  F94843  E8                       inx
 7832  F94844  E0 0F                    cpx     #mxchnls        ; searched all?
 7833  F94846  90 F1                    bcc     ?20             ; no
 7834  F94848  60                       rts                     ; yes, CF = 1
 7835  F94849  86 93            ?40:    stx     tmp0            ; save x
 7836  F9484B  AA                       tax
 7837  F9484C  29 07                    and     #$07
 7838  F9484E  A8                       tay                     ; Y = lindx
 7839  F9484F  8A                       txa
 7840  F94850  29 08                    and     #$08            ; get drive #
 7841  F94852  4A                       lsr     a
 7842  F94853  4A                       lsr     a
 7843  F94854  4A                       lsr     a
 7844  F94855  4A                       lsr     a
 7845  F94856  85 1F                    sta     tmpxxx
 7846  F94858  A6 16                    ldx     entfnd          ; index entry found
 7847  F9485A  B5 34                    lda     fildrv,x
 7848  F9485C  29 01                    and     #1
 7849  F9485E  C5 1F                    cmp     tmpxxx          ; same drive # ?
 7850  F94860  D0 DF                    bne     ?30             ; no
 7851  F94862  BB                       tyx
 7852  F94863  B5 9E                    lda     dsec,x          ; yes - same dir. entry ?
 7853  F94865  A6 16                    ldx     entfnd
 7854  F94867  D5 2A                    cmp     entsec,x
 7855  F94869  D0 D6                    bne     ?30             ; no
 7856  F9486B  BB                       tyx
 7857  F9486C  B5 A6                    lda     dind,x
 7858  F9486E  A6 16                    ldx     entfnd
 7859  F94870  D5 2F                    cmp     entind,x
 7860  F94872  D0 CD                    bne     ?30             ; no
 7861  F94874  18                       clc                     ; active file so CF = 0
 7862  F94875  60                       rts
 7863                           
 7864                           ; return file descriptor of the right type (read or write)
 7865                           ; return X = lindx (fd)
 7866  F94876                   fndfd:
 7867  F94876  20 F2 48                 jsr     isopn           ; check if file is open
 7868  F94879  34 59                    bit     lintab,x
 7869  F9487B  50 0A                    bvc     ?08
 7870  F9487D  20 CA 48                 jsr     fnddafd         ; direct access
 7871  F94880  90 18                    bcc     ?20
 7872  F94882  A9 40                    lda     #mistyp
 7873  F94884  4C ED 56                 jmp     chnerr
 7874  F94887  24 E6            ?08:    bit     wrop
 7875  F94889  30 0A                    bmi     ?10             ; write file
 7876  F9488B  20 A0 48                 jsr     fndrfd          ; check read file
 7877  F9488E  90 0A                    bcc     ?20
 7878  F94890  A9 44                    lda     #wrfil          ; write file only
 7879  F94892  4C ED 56                 jmp     chnerr
 7880  F94895  20 B2 48         ?10:    jsr     fndwfd          ; check write file
 7881  F94898  B0 01                    bcs     ?30             ; read file only
 7882  F9489A  60               ?20:    rts
 7883  F9489B  A9 45            ?30:    lda     #rdfil
  Tue Jul 17 11:00:19 2018                                                                                               Page   96




 7884  F9489D  4C ED 56                 jmp     chnerr
 7885                           
 7886                           ; find lindx of read fd
 7887                           ; CF = 0 if chnl is a read channel, A=X = lindx
 7888                           ; CF = 1 if chnl is not a read channel
 7889  F948A0                   fndrfd:
 7890  F948A0  A6 52                    ldx     chnl
 7891  F948A2  38                       sec
 7892  F948A3  B5 59                    lda     lintab,x
 7893  F948A5  30 0A                    bmi     ?02
 7894  F948A7  29 07                    and     #$07
 7895  F948A9  85 57                    sta     lindx
 7896  F948AB  AA                       tax
 7897  F948AC  0A                       asl     a
 7898  F948AD  85 F7                    sta     dblfd
 7899  F948AF  8A                       txa
 7900  F948B0  18                       clc
 7901  F948B1  60               ?02:    rts
 7902                           
 7903                           ; find lindx of write fd
 7904                           ; CF = 0 if chnl is a write channel, A=X = lindx
 7905                           ; CF = 1 if chnl is not a write channel
 7906  F948B2                   fndwfd:
 7907  F948B2  A6 52                    ldx     chnl
 7908  F948B4  B5 59                    lda     lintab,x
 7909  F948B6  A8                       tay
 7910  F948B7  0A                       asl     a
 7911  F948B8  90 0E                    bcc     ?20             ; bit 7 = 0, not ok
 7912  F948BA  30 0C                    bmi     ?20             ; bit 7 & 6 = 1, not ok
 7913  F948BC  98                       tya
 7914  F948BD  29 07                    and     #$07
 7915  F948BF  85 57                    sta     lindx
 7916  F948C1  AA                       tax
 7917  F948C2  0A                       asl     a
 7918  F948C3  85 F7                    sta     dblfd
 7919  F948C5  8A                       txa
 7920  F948C6  18                       clc
 7921  F948C7  60                       rts
 7922  F948C8  38               ?20:    sec
 7923  F948C9  60                       rts
 7924                           
 7925                           ; find lindx of direct access fd
 7926                           ; CF = 0 if chnl is direct access type, A=X = lindx
 7927                           ; CF = 1 if not
 7928  F948CA                   fnddafd:
 7929  F948CA  A6 52                    ldx     chnl
 7930  F948CC  B5 59                    lda     lintab,x
 7931  F948CE  A8                       tay
 7932  F948CF  0A                       asl     a
 7933  F948D0  B0 0D                    bcs     ?10             ; bit 7=1, not ok
 7934  F948D2  10 0C                    bpl     ?20             ; bit 6=0, not ok
 7935  F948D4  98                       tya                     ; ok, just bit 6=1
 7936  F948D5  29 07                    and     #$07
 7937  F948D7  85 57                    sta     lindx
 7938  F948D9  AA                       tax
 7939  F948DA  0A                       asl     a
 7940  F948DB  85 F7                    sta     dblfd
  Tue Jul 17 11:00:19 2018                                                                                               Page   97




 7941  F948DD  8A                       txa
 7942  F948DE  18                       clc
 7943  F948DF  60               ?10:    rts
 7944  F948E0  38               ?20:    sec
 7945  F948E1  60                       rts
 7946                           
 7947                           ; get drive associated with fd
 7948  F948E2                   fddrv:
 7949  F948E2  A6 52                    ldx     chnl
 7950  F948E4  B5 59                    lda     lintab,x
 7951  F948E6  C9 FF                    cmp     #$FF
 7952  F948E8  F0 07                    beq     ?04
 7953  F948EA  29 08                    and     #$08            ; drive is in bit 3
 7954  F948EC  4A                       lsr     a
 7955  F948ED  4A                       lsr     a
 7956  F948EE  4A                       lsr     a
 7957  F948EF  85 19                    sta     drvnum
 7958  F948F1  60               ?04:    rts
 7959                           
 7960                           ; test if given channel is open
 7961  F948F2                   isopn:
 7962  F948F2  A6 52                    ldx     chnl
 7963  F948F4  B5 59                    lda     lintab,x
 7964  F948F6  C9 FF                    cmp     #$FF
 7965  F948F8  F0 01                    beq     ?02             ; channel not open
 7966  F948FA  60                       rts
 7967  F948FB  A9 3D            ?02:    lda     #filnop
 7968  F948FD  4C ED 56                 jmp     chnerr
 7969                           
 7970                           ; get first available channel in range 2..14
 7971                           ; return channel in X and chnl
 7972  F94900                   getfre:
 7973  F94900  A2 02                    ldx     #2              ; start from chnl 2
 7974  F94902  B5 59            ?02:    lda     lintab,x
 7975  F94904  C9 FF                    cmp     #$FF
 7976  F94906  F0 0A                    beq     ?04
 7977  F94908  E8                       inx
 7978  F94909  E0 0F                    cpx     #mxchnls
 7979  F9490B  90 F5                    bcc     ?02
 7980  F9490D  A9 46                    lda     #nochnl         ; no channels available
 7981  F9490F  4C 07 41                 jmp     cmderr
 7982  F94912  86 52            ?04:    stx     chnl
 7983  F94914  60                       rts
 7984                           
 7985                           ; set pointer to buffer associated with logical index
 7986                           ; return X = lindx
 7987  F94915                   setfdp:
 7988  F94915  A5 57                    lda     lindx
 7989  F94917  AA                       tax
 7990  F94918  18                       clc
 7991  F94919  69 D4                    adc     #DMALXBUF       ; buffer # for index = 0
 7992  F9491B  A0 02                    ldy     #DMABNK         ; bank for buffer #00..#7F
 7993  F9491D  0A                       asl     a               ; get high pointer
 7994  F9491E  90 01                    bcc     ?02
 7995  F94920  C8                       iny                     ; next bank
 7996  F94921  64 8A            ?02:    stz     bufp            ; set buffer pointer
 7997  F94923  85 8B                    sta     bufp+1
  Tue Jul 17 11:00:19 2018                                                                                               Page   98




 7998  F94925  84 8C                    sty     bufp+2
 7999  F94927  60                       rts
 8000                           
 8001                           ;---------------------------------------------------------------------------
 8002                           ; directory listing
 8003                           ;---------------------------------------------------------------------------
 8004                           
 8005                           ; fill buffer with dir listing
 8006                           ; any list line is 32 bytes long and in cbm basic format
 8007                           ; first 2 bytes is the basic line link
 8008                           ; follow 2 bytes with blocks count of file (like a basic line number)
 8009                           ; follow file name and type
 8010                           ; last byte is null fo terminate basic line
 8011                           ; when listing terminate two null will be appended for terminate basic text
 8012                           ;
 8013                           ; in:   Y=current pointer to dest buffer
 8014                           ; out:  rdlst is ptr to last byte (if not null ending listing)
 8015  F94928                   dlist:  
 8016  F94928  A9 01                    lda     #1              ; insert fhoney links ($0101)
 8017  F9492A  97 8A                    sta     [bufp],y
 8018  F9492C  C8                       iny
 8019  F9492D  97 8A                    sta     [bufp],y
 8020  F9492F  C8                       iny
 8021  F94930  20 67 49                 jsr     getnam          ; get file name and fill name buffer
 8022  F94933  B0 16                    bcs     ?10             ; CF=1 if last entry
 8023  F94935  A5 94                    lda     wtmp            ; put blocks #
 8024  F94937  97 8A                    sta     [bufp],y
 8025  F94939  C8                       iny
 8026  F9493A  A5 95                    lda     wtmp+1
 8027  F9493C  97 8A                    sta     [bufp],y
 8028  F9493E  C8                       iny
 8029  F9493F  20 1F 4A                 jsr     movbuf          ; move 27 bytes from name buffer
 8030  F94942  A9 00                    lda     #0              ; end of entry
 8031  F94944  97 8A                    sta     [bufp],y
 8032  F94946  C8                       iny
 8033  F94947  D0 DF                    bne     dlist           ; next entry
 8034  F94949  80 19                    bra     ?20             ; buffer is full
 8035  F9494B  A5 94            ?10:    lda     wtmp            ; this is end of listing
 8036  F9494D  97 8A                    sta     [bufp],y        ; send free blocks #
 8037  F9494F  C8                       iny
 8038  F94950  A5 95                    lda     wtmp+1
 8039  F94952  97 8A                    sta     [bufp],y
 8040  F94954  C8                       iny
 8041  F94955  20 1F 4A                 jsr     movbuf          ; move 27 bytes from name buffer
 8042  F94958  88                       dey                     ; -2 bytes for make room for double null
 8043  F94959  88                       dey
 8044  F9495A  A9 00                    lda     #0              ; end of listing (000)
 8045  F9495C  97 8A                    sta     [bufp],y
 8046  F9495E  C8                       iny
 8047  F9495F  97 8A                    sta     [bufp],y
 8048  F94961  C8                       iny
 8049  F94962  97 8A                    sta     [bufp],y
 8050  F94964  84 EA            ?20:    sty     rdlst           ; set end pointer (not 0 if end)
 8051  F94966  60                       rts
 8052                           
 8053                           ; get next file entry from directory
 8054                           ; if listing is complete return with CF=1
  Tue Jul 17 11:00:19 2018                                                                                               Page   99




 8055  F94967                   getnam:
 8056  F94967  5A                       phy                     ; save buffer index
 8057  F94968  A5 16                    lda     entfnd
 8058  F9496A  10 1E                    bpl     ?10             ; more files
 8059  F9496C  20 2D 4A                 jsr     blknb           ; this is end of listing                
 8060  F9496F  A2 0B                    ldx     #msglen-1
 8061  F94971  BF 9C 5A F9      ?02:    lda     >fremsg,x
 8062  F94975  9D C2 E1                 sta     !nambuf,x
 8063  F94978  CA                       dex
 8064  F94979  10 F6                    bpl     ?02
 8065  F9497B  A5 19                    lda     drvnum
 8066  F9497D  0A                       asl     a
 8067  F9497E  AA                       tax
 8068  F9497F  B5 6A                    lda     ndbf,x          ; save free block's count
 8069  F94981  85 94                    sta     wtmp
 8070  F94983  B5 6B                    lda     ndbf+1,x
 8071  F94985  85 95                    sta     wtmp+1
 8072  F94987  7A                       ply
 8073  F94988  38                       sec                     ; CF=1 end of listing
 8074  F94989  60                       rts
 8075                           
 8076  F9498A  A2 18            ?10:    ldx     #dirlen         ; set number blocks
 8077  F9498C  A0 1D                    ldy     #29             ;  & adjust spacing
 8078  F9498E  B7 0A                    lda     [dirp],y        ; hi blocks #
 8079  F94990  85 95                    sta     wtmp+1
 8080  F94992  F0 02                    beq     ?12
 8081  F94994  A2 16                    ldx     #dirlen-2       ; blocks < 256
 8082  F94996  88               ?12:    dey
 8083  F94997  B7 0A                    lda     [dirp],y        ; low blocks #
 8084  F94999  85 94                    sta     wtmp
 8085  F9499B  E0 16                    cpx     #dirlen-2
 8086  F9499D  F0 0A                    beq     ?14
 8087  F9499F  C9 0A                    cmp     #10
 8088  F949A1  90 06                    bcc     ?14             ; blocks < 10
 8089  F949A3  CA                       dex
 8090  F949A4  C9 64                    cmp     #100
 8091  F949A6  90 01                    bcc     ?14             ; blocks < 100
 8092  F949A8  CA                       dex
 8093  F949A9  20 2D 4A         ?14:    jsr     blknb           ; clear name buffer
 8094  F949AC  A7 0A                    lda     [dirp]          ; set type chars
 8095  F949AE  48                       pha
 8096  F949AF  0A                       asl     a               ; (used in bcs for check closed flag)
 8097  F949B0  10 05                    bpl     ?15             ; file not locked
 8098  F949B2  A9 3C                    lda     #'<'
 8099  F949B4  9D C3 E1                 sta     !nambuf+1,x     ; file locked
 8100  F949B7  68               ?15:    pla
 8101  F949B8  29 0F                    and     #$0f
 8102  F949BA  9B                       txy                     ; Y = nambuf index
 8103  F949BB  AA                       tax                     ; X = file type
 8104  F949BC  BF 90 5A F9              lda     >tp2lst,x
 8105  F949C0  99 C2 E1                 sta     nambuf,y
 8106  F949C3  88                       dey
 8107  F949C4  BF 8A 5A F9              lda     >tp1lst,x
 8108  F949C8  99 C2 E1                 sta     nambuf,y
 8109  F949CB  88                       dey
 8110  F949CC  BF 84 5A F9              lda     >typlst,x
 8111  F949D0  99 C2 E1                 sta     nambuf,y
  Tue Jul 17 11:00:19 2018                                                                                               Page  100




 8112  F949D3  88                       dey
 8113  F949D4  88                       dey
 8114  F949D5  B0 05                    bcs     ?20             ; (from asl)
 8115  F949D7  A9 2A                    lda     #'*'            ; file not closed: splat file
 8116  F949D9  99 C3 E1                 sta     nambuf+1,y
 8117  F949DC  A9 A0            ?20:    lda     #$A0
 8118  F949DE  99 C2 E1                 sta     nambuf,y
 8119  F949E1  BB                       tyx                     ; X = nambuf index
 8120  F949E2  CA                       dex
 8121  F949E3  A0 12                    ldy     #18             ; end of file name
 8122  F949E5  B7 0A            ?22:    lda     [dirp],y        ; move file name
 8123  F949E7  9D C2 E1                 sta     !nambuf,x
 8124  F949EA  CA                       dex
 8125  F949EB  88                       dey
 8126  F949EC  C0 03                    cpy     #3
 8127  F949EE  B0 F5                    bcs     ?22
 8128  F949F0  A9 22                    lda     #'"'            ; send name in quotes
 8129  F949F2  9D C2 E1                 sta     !nambuf,x    
 8130  F949F5  E8               ?30:    inx
 8131  F949F6  E0 20                    cpx     #$20            ; max 32 bytes
 8132  F949F8  B0 0B                    bcs     ?35
 8133  F949FA  BD C2 E1                 lda     !nambuf,x
 8134  F949FD  C9 22                    cmp     #'"'
 8135  F949FF  F0 04                    beq     ?35
 8136  F94A01  C9 A0                    cmp     #$A0            ; stop at first padding byte
 8137  F94A03  D0 F0                    bne     ?30
 8138  F94A05  A9 22            ?35:    lda     #'"'
 8139  F94A07  9D C2 E1                 sta     !nambuf,x
 8140  F94A0A  E8               ?37:    inx
 8141  F94A0B  E0 20                    cpx     #$20
 8142  F94A0D  B0 0A                    bcs     ?40
 8143  F94A0F  A9 7F                    lda     #$7F            ; clear bit of any char
 8144  F94A11  3D C2 E1                 and     !nambuf,x
 8145  F94A14  9D C2 E1                 sta     !nambuf,x
 8146  F94A17  80 F1                    bra     ?37
 8147  F94A19  20 88 4A         ?40:    jsr     fndfil          ; put dir ptr to next entry
 8148  F94A1C  7A                       ply
 8149  F94A1D  18                       clc                     ; CF=0 no ending listing
 8150  F94A1E  60                       rts
 8151                           
 8152                           ; move file name to listing buf
 8153  F94A1F                   movbuf:
 8154  F94A1F  A2 00                    ldx     #0
 8155  F94A21  BD C2 E1         ?02:    lda     !nambuf,x
 8156  F94A24  97 8A                    sta     [bufp],y
 8157  F94A26  C8                       iny
 8158  F94A27  E8                       inx
 8159  F94A28  E0 1B                    cpx     #nbsiz
 8160  F94A2A  D0 F5                    bne     ?02
 8161  F94A2C  60                       rts
 8162                           
 8163                           ; blank nambuf
 8164  F94A2D                   blknb:
 8165  F94A2D  A0 1B                    ldy     #nbsiz
 8166  F94A2F  A9 20                    lda     #' '
 8167  F94A31  99 C1 E1         ?02:    sta     nambuf-1,y
 8168  F94A34  88                       dey
  Tue Jul 17 11:00:19 2018                                                                                               Page  101




 8169  F94A35  D0 FA                    bne     ?02
 8170  F94A37  60                       rts
 8171                           
 8172                           ;---------------------------------------------------------------------------
 8173                           ; directory search helper's
 8174                           ;---------------------------------------------------------------------------
 8175                           
 8176                           ; lookup all files in stream and fill tbls w/info
 8177  F94A38                   lookup:
 8178  F94A38  20 97 4B                 jsr     optsch          ; init drive(s)
 8179  F94A3B                   lookup2:
 8180  F94A3B  A6 19            ?05:    ldx     drvnum  
 8181  F94A3D  74 02                    stz     delind,x
 8182  F94A3F  20 2D 4B                 jsr     srchst          ; start search
 8183  F94A42  D0 10                    bne     ?25             ; valid entry
 8184  F94A44  24 18            ?10:    bit     tgflg           ; end of dir - search both drives?
 8185  F94A46  10 1D                    bpl     ?40             ; no, so exit
 8186  F94A48  70 1B                    bvs     ?40             ; other drive already searched, so exit
 8187  F94A4A  20 8A 4B                 jsr     togdrv          ; toggle drvnum
 8188  F94A4D  80 EC                    bra     ?05             ; lookup on other drive
 8189  F94A4F  20 76 4B         ?20:    jsr     search          ; find valid fn
 8190  F94A52  F0 0D                    beq     ?30             ; end of directory
 8191  F94A54  20 A6 4A         ?25:    jsr     compar          ; compare dir w/ table
 8192  F94A57  A5 17                    lda     found           ; found flag
 8193  F94A59  D0 0A                    bne     ?40             ; all fn's found
 8194  F94A5B  A5 16                    lda     entfnd
 8195  F94A5D  30 F0                    bmi     ?20             ; no match, continue searching dir
 8196  F94A5F  10 F3                    bpl     ?25             ; last match, compare again tables
 8197  F94A61  A5 17            ?30:    lda     found
 8198  F94A63  F0 DF                    beq     ?10             ; lookup other drive, if need
 8199  F94A65  60               ?40:    rts
 8200                           
 8201                           ; find next file name matching
 8202                           ; any file in stream & return
 8203                           ; with entry found stuffed into tables
 8204                           ; return N=1 if lookup exhausted, otherwise N=0
 8205                           ; ffst start a search
 8206                           ; findfil continue a search
 8207                           ; ffre re-entry a search
 8208  F94A66                   ffre:
 8209  F94A66  20 65 4B                 jsr     srre            ; find file re-entry
 8210  F94A69  F0 10                    beq     ffend           ; end of directory
 8211  F94A6B  D0 20                    bne     ffcp            ; found valid entry
 8212                           
 8213  F94A6D                   ffst0:  
 8214  F94A6D  20 8A 4B                 jsr     togdrv          ; toggle drvnum and start again search
 8215                                                           ; lookup it in the other drive
 8216  F94A70                   ffst:
 8217  F94A70  A6 19                    ldx     drvnum          ; find file start entry
 8218  F94A72  74 02                    stz     delind,x
 8219  F94A74  20 2D 4B                 jsr     srchst
 8220  F94A77  D0 14                    bne     ffcp            ; found valid entry
 8221  F94A79  85 17                    sta     found           ; found=0 if end of directory      
 8222  F94A7B  A5 17            ffend:  lda     found           ; = $FF if lookup completed
 8223  F94A7D  D0 08                    bne     ?04             ; exit with N=1
 8224  F94A7F  24 18                    bit     tgflg           ; search both drives?
 8225  F94A81  10 02                    bpl     ?02             ; no, so exit with N=1
  Tue Jul 17 11:00:19 2018                                                                                               Page  102




 8226  F94A83  50 E8                    bvc     ffst0           ; start searching on the other drive
 8227                                                           ; if not already searched
 8228  F94A85  A9 FF            ?02:    lda     #$FF            ; exit with N=1
 8229  F94A87  60               ?04:    rts
 8230                           
 8231  F94A88                   fndfil:
 8232  F94A88  20 76 4B                 jsr     search          ; find file continuous...
 8233  F94A8B  F0 EE                    beq     ffend           ; end of directory
 8234  F94A8D  20 A6 4A         ffcp:   jsr     compar          ; compare file names and fill tables
 8235  F94A90  A6 16                    ldx     entfnd
 8236  F94A92  10 05                    bpl     ?30             ; file stream tabulated
 8237  F94A94  A5 17                    lda     found
 8238  F94A96  F0 F0                    beq     fndfil          ; continue searching      
 8239  F94A98  60                       rts                     ; N=1 - stop search
 8240  F94A99  A5 10            ?30:    lda     typflg
 8241  F94A9B  F0 08                    beq     ?40             ; no type restriction - exit N=0
 8242  F94A9D  B5 39                    lda     pattyp,x
 8243  F94A9F  29 07                    and     #typmsk
 8244  F94AA1  C5 10                    cmp     typflg
 8245  F94AA3  D0 E3                    bne     fndfil
 8246  F94AA5  60               ?40:    rts                     ; exit N=0
 8247                           
 8248                           ;compare all filenames in stream table
 8249                           ;  with each valid entry in the 
 8250                           ;  directory and matches are tabulated
 8251                           ;  Z=0,N=1 and found=$FF if table exhausted
 8252                           ;  Z=1,N=0 and found=0 if table not exhausted
 8253                           ;  entfnd = index of matching files stream or $FF in no match
 8254                           ;  at first match this function exit
 8255                           ;  if a search involve both drives, first will be processed table for
 8256                           ;  drvnum and after will be processed table for the other drive
 8257  F94AA6                   compar:
 8258  F94AA6  A2 FF                    ldx     #$FF
 8259  F94AA8  86 16                    stx     entfnd          ; set entry not found
 8260  F94AAA  E8                       inx
 8261  F94AAB  86 11                    stx     patflg
 8262  F94AAD  20 12 4B                 jsr     ?90             ; check unfound entry in file stream
 8263  F94AB0  F0 06                    beq     ?10             ; unfound, so will be tabulated
 8264  F94AB2  60               ?02:    rts                     ; all are found
 8265  F94AB3  20 1A 4B         ?05:    jsr     ?91             ; check next entry in file stream
 8266  F94AB6  D0 FA                    bne     ?02             ; all are found
 8267  F94AB8  A5 19            ?10:    lda     drvnum          ; current drive
 8268  F94ABA  55 34                    eor     fildrv,x
 8269  F94ABC  4A                       lsr     a
 8270  F94ABD  B0 F4                    bcs     ?05             ; drive doesn't match, check next file
 8271  F94ABF  B5 1A            ?20:    lda     filtbl,x        ; good drive match
 8272  F94AC1  AA                       tax                     ; pointer to pattern
 8273  F94AC2  A0 03                    ldy     #3              ; offset of entry name in directory sec
 8274  F94AC4  BD 00 E1         ?30:    lda     !cmdbuf,x       ; compare byte
 8275  F94AC7  F0 0C                    beq     ?40             ; match filename !
 8276  F94AC9  D7 0A                    cmp     [dirp],y
 8277  F94ACB  F0 04                    beq     ?32             ; match byte
 8278  F94ACD  C9 3F                    cmp     #'?'            ; '?' match any byte
 8279  F94ACF  D0 E2                    bne     ?05             ; no match so check next entry in file stream 
 8280  F94AD1  E8               ?32:    inx
 8281  F94AD2  C8                       iny
 8282  F94AD3  80 EF                    bra     ?30
  Tue Jul 17 11:00:19 2018                                                                                               Page  103




 8283  F94AD5  A6 15            ?40:    ldx     f2ptr           ; file name match
 8284  F94AD7  86 16                    stx     entfnd          ; save index in file stream     
 8285  F94AD9  B5 39                    lda     pattyp,x        ; store info in tables
 8286  F94ADB  29 80                    and     #$80
 8287  F94ADD  85 11                    sta     patflg          ; pattern flag
 8288  F94ADF  9B                       txy
 8289  F94AE0  A6 19                    ldx     drvnum
 8290  F94AE2  B5 06                    lda     index,x
 8291  F94AE4  BB                       tyx
 8292  F94AE5  95 2F                    sta     entind,x
 8293  F94AE7  A5 09                    lda     sector
 8294  F94AE9  95 2A                    sta     entsec,x
 8295  F94AEB  A7 0A                    lda     [dirp]
 8296  F94AED  48                       pha
 8297  F94AEE  29 40                    and     #$40            ; mask on lock bit
 8298  F94AF0  85 93                    sta     tmp0
 8299  F94AF2  68                       pla
 8300  F94AF3  29 DF                    and     #$FF-$20        ; mask off bit 5 ($DF)
 8301  F94AF5  30 02                    bmi     ?42             ; if is closed
 8302  F94AF7  09 20                    ora     #$20            ; file not closed: set bit 5
 8303  F94AF9  29 27            ?42:    and     #$27            ; mask open bit and type
 8304  F94AFB  05 93                    ora     tmp0            ; plus lock bit
 8305  F94AFD  85 93                    sta     tmp0
 8306  F94AFF  A9 80                    lda     #$80
 8307  F94B01  35 39                    and     pattyp,x        ; <7>: pattern
 8308  F94B03  05 93                    ora     tmp0            ; <6>: lock bit, <5>: closed flag
 8309  F94B05  95 39                    sta     pattyp,x        ; <2:0>: file type
 8310  F94B07  A0 01                    ldy     #1              ; first track & sector of file
 8311  F94B09  B7 0A                    lda     [dirp],y
 8312  F94B0B  95 20                    sta     filtrk,x
 8313  F94B0D  C8                       iny
 8314  F94B0E  B7 0A                    lda     [dirp],y
 8315  F94B10  95 25                    sta     filsec,x
 8316  F94B12                           
 8317                                   ; restart table check -- in this way exit always with found=0
 8318                                   ; if tables not exhausted 
 8319                           
 8320                           ; check table for unfound files
 8321  F94B12  A9 FF            ?90:    lda     #$FF
 8322  F94B14  85 17                    sta     found
 8323  F94B16  A5 13                    lda     f2cnt
 8324  F94B18  85 15                    sta     f2ptr
 8325  F94B1A  C6 15            ?91:    dec     f2ptr
 8326  F94B1C  30 0E                    bmi     ?99             ; table exhausted
 8327                                                           ; exit with Z=0,N=1 and found=$FF
 8328  F94B1E  A6 15                    ldx     f2ptr
 8329  F94B20  B5 39                    lda     pattyp,x
 8330  F94B22  30 04                    bmi     ?95             ; wildcards: still must search
 8331  F94B24  B5 20                    lda     filtrk,x
 8332  F94B26  D0 F2                    bne     ?91             ; already tabulated so skip
 8333  F94B28  A9 00            ?95:    lda     #0              ; exit with Z=1,N=0...
 8334  F94B2A  85 17                    sta     found           ; ... and found=0  
 8335  F94B2C  60               ?99:    rts
 8336                           
 8337                           ; search directory 
 8338                           ;  returns with valid entry w/ delind=0
 8339                           ;  or returns w/ 1st deleted entry w/ delind=1 
  Tue Jul 17 11:00:19 2018                                                                                               Page  104




 8340                           ;  srchst will initiate a search
 8341                           ;  search will continue a search
 8342                           ;  srre will re-entry a search
 8343  F94B2D                   srchst:
 8344  F94B2D  A6 19                    ldx     drvnum
 8345  F94B2F  A0 00                    ldy     #0              ; init deleted sector
 8346  F94B31  94 00                    sty     delsec,x
 8347  F94B33  88                       dey
 8348  F94B34  84 16                    sty     entfnd          ; = $FF => not found
 8349  F94B36  A9 28                    lda     #dirtrk         ; start search at beginning
 8350  F94B38  85 08                    sta     track
 8351  F94B3A  A9 03                    lda     #dirst          ; /1st dir blk
 8352  F94B3C  85 09            srnews: sta     sector          ; search from beginning or from a new sector     
 8353  F94B3E  20 C3 4C                 jsr     setdptr         ; set dir buffer ptr
 8354  F94B41  A7 0A            srnext: lda     [dirp]          ; search next entry
 8355  F94B43  D0 11                    bne     ?02             ; not empty entry
 8356  F94B45  B5 00                    lda     delsec,x        ; deleted entry found
 8357  F94B47  D0 2D                    bne     search          ; deleted entry already found
 8358  F94B49  A5 09                    lda     sector          ; store sector of empty entry
 8359  F94B4B  95 00                    sta     delsec,x
 8360  F94B4D  A5 0A                    lda     dirp            ; get current index of entry
 8361  F94B4F  B4 02                    ldy     delind,x        ; bit1: want deleted entry
 8362  F94B51  95 02                    sta     delind,x        ; store index of empty entry
 8363  F94B53  F0 21                    beq     search          ; delind=0 => want valid entry
 8364  F94B55  60                       rts                     ; (Z=0)
 8365  F94B56  A9 01            ?02:    lda     #1
 8366  F94B58  D5 02                    cmp     delind,x        ; ?looking for empty entry?
 8367  F94B5A  F0 1A                    beq     search          ; yes => continue searching
 8368                                                           ; no! found not empty entry
 8369  F94B5C  A5 0A                    lda     dirp            ; found not empty entry
 8370  F94B5E  95 06                    sta     index,x         ; save index
 8371  F94B60  A5 09                    lda     sector
 8372  F94B62  95 04                    sta     dirsec,x        ; save sector
 8373  F94B64  60                       rts                     ; (Z=0)
 8374                           
 8375                           ; re-entry from a search        
 8376  F94B65                   srre:   
 8377  F94B65  A6 19                    ldx     drvnum          ; get last used accessed search
 8378  F94B67  A9 28                    lda     #dirtrk
 8379  F94B69  85 08                    sta     track
 8380  F94B6B  B5 04                    lda     dirsec,x        ; found entry sector
 8381  F94B6D  85 09                    sta     sector
 8382  F94B6F  20 C3 4C                 jsr     setdptr         ; set dir buffer ptr
 8383  F94B72  B5 06                    lda     index,x         ; found entry index
 8384  F94B74  85 0A                    sta     dirp            ; set dir buffer low ptr
 8385  F94B76                           
 8386                           ; continue a searching
 8387  F94B76                   search:
 8388  F94B76  A6 19                    ldx     drvnum
 8389  F94B78  A9 FF                    lda     #$FF
 8390  F94B7A  85 16                    sta     entfnd
 8391  F94B7C  A9 20                    lda     #32             ; incr by 32
 8392  F94B7E  18                       clc
 8393  F94B7F  65 0A                    adc     dirp
 8394  F94B81  85 0A                    sta     dirp            ; next entry...
 8395  F94B83  90 BC                    bcc     srnext          ; ...in same sector
 8396  F94B85  A5 0D                    lda     nxtsec          ; next dir sector
  Tue Jul 17 11:00:19 2018                                                                                               Page  105




 8397  F94B87  D0 B3                    bne     srnews          ; not last dir sec      
 8398  F94B89  60                       rts                     ; exit with Z = 1
 8399                           
 8400                           ; toggle drive number in drvnum
 8401  F94B8A                   togdrv:
 8402  F94B8A  A5 19                    lda     drvnum
 8403  F94B8C  49 01                    eor     #1
 8404  F94B8E  29 01                    and     #1
 8405  F94B90  85 19                    sta     drvnum
 8406  F94B92  A9 40                    lda     #$40            ; set bit 6 for signaling toggle
 8407  F94B94  04 18                    tsb     tgflg
 8408  F94B96  60                       rts
 8409                           
 8410                           ; set tgflg for search option on both drives and init drive's
 8411                           ; read system directory and check integrity of header
 8412  F94B97                   optsch:
 8413  F94B97  A9 00                    lda     #0
 8414  F94B99  85 18                    sta     tgflg
 8415  F94B9B  A6 13                    ldx     f2cnt           ; scan file stream
 8416  F94B9D  A8               ?02:    tay                     ; option search
 8417  F94B9E  CA                       dex                     ; adjust pointer
 8418  F94B9F  30 0E                    bmi     ?06             ; end scanning
 8419  F94BA1  B5 34                    lda     fildrv,x
 8420  F94BA3  4A                       lsr     a               ; CF = drive
 8421  F94BA4  98                       tya
 8422  F94BA5  B0 04                    bcs     ?04             ; drive #1
 8423  F94BA7  09 01                    ora     #1              ; drive #0 (bit 0)
 8424  F94BA9  80 F2                    bra     ?02
 8425  F94BAB  09 02            ?04:    ora     #2              ; drive #1 (bit 1)
 8426  F94BAD  80 EE                    bra     ?02
 8427  F94BAF  C9 03            ?06:    cmp     #3
 8428  F94BB1  D0 04                    bne     ?08             ; just one drive tabulated in file stream
 8429  F94BB3  A9 80                    lda     #$80            ; search both drives flag
 8430  F94BB5  85 18                    sta     tgflg
 8431  F94BB7  A5 34            ?08:    lda     fildrv          ; set drvnum for first file on stream
 8432  F94BB9  29 01                    and     #1
 8433  F94BBB  85 19                    sta     drvnum
 8434  F94BBD  20 6A 56                 jsr     drvint          ; init drive and system track cache
 8435  F94BC0  24 18                    bit     tgflg
 8436  F94BC2  10 0D                    bpl     ?10             ; just one drive
 8437  F94BC4  A5 19                    lda     drvnum
 8438  F94BC6  48                       pha                     ; save
 8439  F94BC7  49 01                    eor     #$01            ; toggle drive #
 8440  F94BC9  85 19                    sta     drvnum
 8441  F94BCB  20 6A 56                 jsr     drvint
 8442  F94BCE  68                       pla                     ; restore drive #
 8443  F94BCF  85 19                    sta     drvnum
 8444  F94BD1  60               ?10:    rts
 8445                           
 8446                           ;---------------------------------------------------------------------------
 8447                           ; track & sector allocation helper's - bam helper's
 8448                           ;---------------------------------------------------------------------------
 8449                           
 8450                           ; add a new file to directory in first available empty entry
 8451                           ; add a new sector to directory chain if no empty entry available
 8452  F94BD2                   addfil:
 8453                           ;       ;jsr    curblk          ; last used accessed search
  Tue Jul 17 11:00:19 2018                                                                                               Page  106




 8454  F94BD2  64 41                    stz     cmdsiz          ; not null if will be allocated new dir sec     
 8455  F94BD4  A5 0E                    lda     type
 8456  F94BD6  48                       pha
 8457  F94BD7  A5 34                    lda     fildrv          ; use this drive
 8458  F94BD9  29 01                    and     #1
 8459  F94BDB  AA                       tax                     ; required drive
 8460  F94BDC  45 19                    eor     drvnum          ; compare with last accessed drive
 8461  F94BDE  4A                       lsr     a
 8462  F94BDF  90 0D                    bcc     ?08             ; same drive, use last accessed search
 8463  F94BE1  86 19                    stx     drvnum          ; set current drive
 8464  F94BE3  A9 01                    lda     #1
 8465  F94BE5  95 02                    sta     delind,x        ; look for empty entry
 8466  F94BE7  20 2D 4B                 jsr     srchst
 8467  F94BEA  F0 1A                    beq     ?15             ; all full, alloc new dir sector
 8468  F94BEC  D0 27                    bne     ?18             ; found one
 8469  F94BEE  B5 00            ?08:    lda     delsec,x        ; already called srchst here!!
 8470  F94BF0  F0 0B                    beq     ?10             ; deleted entry not located
 8471  F94BF2  C5 09                    cmp     sector          ; resident sector?
 8472  F94BF4  F0 21                    beq     ?20             ; yes
 8473  F94BF6  85 09                    sta     sector          ; sector of empty entry
 8474  F94BF8  20 C3 4C                 jsr     setdptr 
 8475  F94BFB  80 1A                    bra     ?20             ; use it
 8476  F94BFD  A9 01            ?10:    lda     #1              ; find empty entry
 8477  F94BFF  95 02                    sta     delind,x
 8478  F94C01  20 65 4B                 jsr     srre            ; restart search
 8479  F94C04  D0 0F                    bne     ?18             ; found one
 8480  F94C06  20 8D 4C         ?15:    jsr     nxdrbk          ; all full, alloc new directory sector
 8481  F94C09  A6 19                    ldx     drvnum
 8482  F94C0B  A5 09                    lda     sector
 8483  F94C0D  95 00                    sta     delsec,x
 8484  F94C0F  A9 02                    lda     #2
 8485  F94C11  95 02                    sta     delind,x
 8486  F94C13  80 06                    bra     ?21
 8487  F94C15  A6 19            ?18:    ldx     drvnum
 8488  F94C17  B5 02            ?20:    lda     delind,x
 8489  F94C19  85 0A                    sta     dirp            ; low pointer
 8490  F94C1B  68               ?21:    pla
 8491  F94C1C  85 0E                    sta     type            ; set type
 8492  F94C1E  85 39                    sta     pattyp
 8493  F94C20  87 0A                    sta     [dirp]
 8494  F94C22  20 63 4D                 jsr     intts           ; allocate init t&s for new file
 8495  F94C25  A5 08                    lda     track
 8496  F94C27  85 20                    sta     filtrk          ; ...table & entry
 8497  F94C29  A0 01                    ldy     #1
 8498  F94C2B  97 0A                    sta     [dirp],y
 8499  F94C2D  A5 09                    lda     sector
 8500  F94C2F  85 25                    sta     filsec          ; set sector link in...
 8501  F94C31  C8                       iny
 8502  F94C32  97 0A                    sta     [dirp],y        ; ...table & entry
 8503  F94C34  C8                       iny
 8504  F94C35  A6 1A                    ldx     filtbl
 8505  F94C37  BD 00 E1         ?22:    lda     !cmdbuf,x       ; copy file name        
 8506  F94C3A  F0 06                    beq     ?24
 8507  F94C3C  97 0A                    sta     [dirp],y
 8508  F94C3E  E8                       inx
 8509  F94C3F  C8                       iny
 8510  F94C40  80 F5                    bra     ?22
  Tue Jul 17 11:00:19 2018                                                                                               Page  107




 8511  F94C42  97 0A            ?24:    sta     [dirp],y        ; clear # of blocks &...
 8512  F94C44  C8                       iny                     ; ...& replace links
 8513  F94C45  C0 1E                    cpy     #30
 8514  F94C47  90 F9                    bcc     ?24
 8515  F94C49  A6 19                    ldx     drvnum
 8516  F94C4B  B5 00                    lda     delsec,x
 8517  F94C4D  85 2A                    sta     entsec
 8518  F94C4F  B5 02                    lda     delind,x
 8519  F94C51  85 2F                    sta     entind
 8520  F94C53  74 02                    stz     delind,x
 8521  F94C55  74 00                    stz     delsec,x
 8522  F94C57                           
 8523                                   ; now must save bam, old dir sector, and new dir sec
 8524                                   ; bam is in phis. sec 1 & 2
 8525                                   ; dir sec 3 is in phis. sec. 2
 8526  F94C57  20 10 4E                 jsr     mapout          ; save bam if dirty
 8527  F94C5A  A5 41                    lda     cmdsiz          ; prev. dir sec. if any
 8528  F94C5C  A4 2A                    ldy     entsec          ; current dir sec
 8529  F94C5E  AA                       tax
 8530  F94C5F  F0 11                    beq     ?34
 8531  F94C61  4A                       lsr     a               ; to phis. sec.
 8532  F94C62  1A                       inc     a
 8533  F94C63  C9 03                    cmp     #3
 8534  F94C65  90 0B                    bcc     ?34             ; saved with bam
 8535  F94C67  48                       pha                     ; save old dir psec
 8536  F94C68  5A                       phy                     ; save current dir sec
 8537  F94C69  86 09                    stx     sector          ; write out old dir sec
 8538  F94C6B  20 57 36                 jsr     wrdsec
 8539  F94C6E  7A                       ply
 8540  F94C6F  84 09                    sty     sector          ; restore current dir sec
 8541  F94C71  68                       pla
 8542  F94C72  85 41            ?34:    sta     cmdsiz          ; restore old dir psec
 8543  F94C74  98                       tya                     ; current dir sec
 8544  F94C75  84 09                    sty     sector
 8545  F94C77  4A                       lsr     a
 8546  F94C78  1A                       inc     a               ; current dir psec
 8547  F94C79  C9 03                    cmp     #3
 8548  F94C7B  90 07                    bcc     ?36
 8549  F94C7D  C5 41                    cmp     cmdsiz          ; compare with prev, if any
 8550  F94C7F  F0 03                    beq     ?36             ; already saved
 8551  F94C81  20 57 36                 jsr     wrdsec          ; write out current dir sec
 8552  F94C84  A5 20            ?36:    lda     filtrk
 8553  F94C86  85 08                    sta     track
 8554  F94C88  A5 25                    lda     filsec
 8555  F94C8A  85 09                    sta     sector
 8556                                   ;;sta   dind,x
 8557                                   ;;sta   dsec,x
 8558  F94C8C  60                       rts
 8559  F94C8D                           
 8560                           ; allocate next directory block on system track
 8561                           ; and mark as used in bam
 8562                           ; dirp, track & sector filled with current values
 8563  F94C8D                   nxdrbk:
 8564  F94C8D  A5 09                    lda     sector
 8565  F94C8F  85 41                    sta     cmdsiz          ; save current directory block
 8566  F94C91  64 0A                    stz     dirp            ; pointer to start of current sector
 8567  F94C93  20 00 4D                 jsr     nxtds           ; allocate a new dir block
  Tue Jul 17 11:00:19 2018                                                                                               Page  108




 8568  F94C96  A4 09                    ldy     sector
 8569  F94C98  C0 03                    cpy     #dirst
 8570  F94C9A  90 57                    bcc     e_dskful0       ; must be > dirst
 8571  F94C9C  A5 08                    lda     track           ; put link in current block
 8572  F94C9E  87 0A                    sta     [dirp]
 8573  F94CA0  98                       tya                     ; sector
 8574  F94CA1  A0 01                    ldy     #1
 8575  F94CA3  97 0A                    sta     [dirp],y        ; the new allocated sec
 8576  F94CA5  64 0D                    stz     nxtsec          ; this is last dir sec
 8577  F94CA7  20 3D 56                 jsr     sethdp          ; preset dir pointer to header
 8578  F94CAA  18                       clc
 8579  F94CAB  65 09                    adc     sector          ; add sector offset
 8580  F94CAD  85 0B                    sta     dirp+1
 8581  F94CAF  A0 01                    ldy     #1
 8582  F94CB1  A9 FF                    lda     #$FF            ; put next link: $00, $FF
 8583  F94CB3  97 0A                    sta     [dirp],y
 8584  F94CB5  1A                       inc     a
 8585  F94CB6  87 0A                    sta     [dirp]
 8586  F94CB8  C8                       iny
 8587  F94CB9  97 0A            ?02:    sta     [dirp],y        ; clear block
 8588  F94CBB  C8                       iny
 8589  F94CBC  D0 FB                    bne     ?02
 8590  F94CBE  A9 02                    lda     #2              ; preset pointer to first entry
 8591  F94CC0  85 0A                    sta     dirp
 8592  F94CC2  60                       rts
 8593                           
 8594                           ; set directory pointer for drvnum and sector
 8595                           ; also, set nxtsec for directory search
 8596                           ; preset dir pointer to first entry on sector
 8597                           ; return X = drive #
 8598  F94CC3                   setdptr:
 8599  F94CC3  A6 19                    ldx     drvnum
 8600  F94CC5  B5 74                    lda     dirofs,x
 8601  F94CC7  B4 76                    ldy     dirbnk,x
 8602  F94CC9  18                       clc
 8603  F94CCA  65 09                    adc     sector          ; add sector offset
 8604  F94CCC  64 0A                    stz     dirp            ; set pointer to dir link
 8605  F94CCE  85 0B                    sta     dirp+1
 8606  F94CD0  84 0C                    sty     dirp+2
 8607  F94CD2                           ACC16
 8608  F94CD2  C2 20                    rep     #PMFLAG
 8609                                   .LONGA  on
 8610                                   .MNLIST
 8611  F94CD4  A7 0A                    lda     [dirp]          ; A = nxt track, B = nxt sector
 8612  F94CD6  AA                       tax                     ; X = nxt track
 8613  F94CD7  EB                       xba                     ; B = nxt track, A = nxt sector
 8614  F94CD8  C9 FF 00                 cmp     #$00FF          ; last dir. sector?
 8615  F94CDB                           ACC08
 8616  F94CDB  E2 20                    sep     #PMFLAG
 8617                                   .LONGA  off
 8618                                   .MNLIST
 8619  F94CDD  F0 05                    beq     ?04             ; yes, this is final sector
 8620  F94CDF  E0 28                    cpx     #dirtrk         ; check system track
 8621  F94CE1  D0 0B                    bne     e_dirlnk        ; dir error
 8622  F94CE3  3A                       dec     a               ; adjust sector
 8623  F94CE4  1A               ?04:    inc     a               ; = 0 if link is $FF    
 8624  F94CE5  85 0D                    sta     nxtsec          ; next sector (0 if no more sec)
  Tue Jul 17 11:00:19 2018                                                                                               Page  109




 8625  F94CE7  A6 19                    ldx     drvnum
 8626  F94CE9  A9 02                    lda     #2              ; index of first entry
 8627  F94CEB  85 0A                    sta     dirp
 8628  F94CED  60                       rts
 8629                           
 8630  F94CEE                   e_dirlnk:
 8631  F94CEE  A9 50                    lda     #dirlnk
 8632  F94CF0  4C FB 56                 jmp     doserr
 8633                           
 8634  F94CF3                   e_dskful0:
 8635  F94CF3  A6 19                    ldx     drvnum          ; invalidate drive
 8636  F94CF5  74 68                    stz     drvfg,x
 8637                           
 8638  F94CF7                   e_dskful:
 8639  F94CF7  A9 48                    lda     #dskful
 8640  F94CF9  4C 07 41                 jmp     cmderr
 8641                           
 8642                           ; returns next available trk & sec
 8643                           ; given current t & s
 8644                           ;  allocation is from trk 40
 8645                           ;  towards 1 & 80, by full tracks
 8646  F94CFC                   nxtts:
 8647                                   ;;jsr   gethdr          ; ??? set current t&s for file
 8648  F94CFC  A9 03                    lda     #3
 8649  F94CFE  85 93                    sta     tmp0            ; set pass count
 8650                           
 8651                           ; allocate new directory sector 
 8652  F94D00                   nxtds:
 8653  F94D00  20 5D 4E                 jsr     bamtrk
 8654  F94D03  A7 8D                    lda     [bmpnt]         ; free blocks count
 8655  F94D05  D0 32                    bne     ?06             ; available blocks
 8656  F94D07  A5 08                    lda     track
 8657  F94D09  C9 28                    cmp     #dirtrk         ; directory full
 8658  F94D0B  F0 EA                    beq     e_dskful        
 8659  F94D0D  90 14                    bcc     ?02             ; track < dirtrack
 8660  F94D0F  E6 08                    inc     track           ; track > dirtrack
 8661  F94D11  A5 08                    lda     track
 8662  F94D13  C9 51                    cmp     #maxtrk
 8663  F94D15  D0 E9                    bne     nxtds
 8664  F94D17  A2 27                    ldx     #dirtrk-1       ; track := dirtrack - 1
 8665  F94D19  86 08                    stx     track
 8666  F94D1B  64 09                    stz     sector
 8667  F94D1D  C6 93                    dec     tmp0
 8668  F94D1F  D0 DF                    bne     nxtds       
 8669  F94D21  F0 D4                    beq     e_dskful
 8670  F94D23  A5 08            ?02:    lda     track
 8671  F94D25  C9 01                    cmp     #startrk
 8672  F94D27  90 04                    bcc     ?03
 8673  F94D29  C6 08                    dec     track
 8674  F94D2B  D0 D3                    bne     nxtds
 8675  F94D2D  A2 29            ?03:    ldx     #dirtrk+1       ; start again
 8676  F94D2F  86 08                    stx     track           ; track := dirtrack + 1
 8677  F94D31  64 09                    stz     sector
 8678  F94D33  C6 93                    dec     tmp0
 8679  F94D35  D0 C9                    bne     nxtds
 8680  F94D37  F0 BE                    beq     e_dskful
 8681  F94D39  E6 09            ?06:    inc     sector          ; increment current sec
  Tue Jul 17 11:00:19 2018                                                                                               Page  110




 8682  F94D3B  A9 28                    lda     #numsec         ; find next sec
 8683  F94D3D  C5 09                    cmp     sector          ; is it over?
 8684  F94D3F  B0 0B                    bcs     ?10             ; no..it's ok
 8685  F94D41  38                       sec
 8686  F94D42  A5 09                    lda     sector
 8687  F94D44  E9 28                    sbc     #numsec
 8688  F94D46  85 09                    sta     sector
 8689  F94D48  F0 02                    beq     ?10
 8690  F94D4A  C6 09                    dec     sector          ; -1
 8691  F94D4C  20 F8 4D         ?10:    jsr     getsec
 8692  F94D4F  D0 51                    bne     wused           ; ok, this block is free
 8693  F94D51  64 09            ?12:    stz     sector          ; start again with sector = 0
 8694  F94D53  20 F8 4D                 jsr     getsec
 8695  F94D56  D0 4A                    bne     wused           ; ok
 8696                           
 8697  F94D58                   e_direrr:
 8698  F94D58  A9 47                    lda     #direrr
 8699  F94D5A  4C FB 56                 jmp     doserr
 8700                           
 8701  F94D5D                   e_direrr0:
 8702  F94D5D  A6 19                    ldx     drvnum
 8703  F94D5F  74 68                    stz     drvfg,x         ; invalidate drive
 8704  F94D61  80 F5                    bra     e_direrr
 8705                           
 8706                           ; find first track & sector for a new file
 8707  F94D63                   intts:
 8708  F94D63  A9 01                    lda     #1              ; set a counter
 8709  F94D65  85 93                    sta     tmp0
 8710  F94D67  A9 28            ?s1:    lda     #dirtrk         ; track:= dirtrk-tmp0
 8711  F94D69  38                       sec
 8712  F94D6A  E5 93                    sbc     tmp0
 8713  F94D6C  85 08                    sta     track
 8714  F94D6E  08                       php
 8715  F94D6F  C9 01                    cmp     #startrk        ; ok?
 8716  F94D71  B0 03                    bcs     ?01             ; yes - startrk < track
 8717  F94D73  28                       plp                     ; discard
 8718  F94D74  80 0C                    bra     ?s2             ; track = 0 so start again toward max track
 8719  F94D76  28               ?01:    plp                     ; check result of sbc
 8720  F94D77  90 09                    bcc     ?s2             ; if track <= 0...
 8721  F94D79  F0 07                    beq     ?s2             ; ...start again toward max track
 8722  F94D7B  20 5D 4E                 jsr     bamtrk          ; set the bam pntr
 8723  F94D7E  A7 8D                    lda     [bmpnt]         ; any free block?
 8724  F94D80  D0 19                    bne     ?10             ; found free sector
 8725  F94D82  A9 28            ?s2:    lda     #dirtrk         ; trk= dirtrk+tmp0
 8726  F94D84  18                       clc
 8727  F94D85  65 93                    adc     tmp0
 8728  F94D87  85 08                    sta     track
 8729  F94D89  E6 93                    inc     tmp0            ; next trk
 8730  F94D8B  C9 51                    cmp     #maxtrk
 8731  F94D8D  90 05                    bcc     ?s3             ; ok
 8732  F94D8F  A9 43                    lda     #systs          ; error, no free sector
 8733  F94D91  4C FB 56                 jmp     doserr
 8734  F94D94  20 5D 4E         ?s3:    jsr     bamtrk          ; set ptr
 8735  F94D97  A7 8D                    lda     [bmpnt]
 8736  F94D99  F0 CC                    beq     ?s1             ; not free... try next track
 8737  F94D9B  64 09            ?10:    stz     sector
 8738  F94D9D  20 F8 4D                 jsr     getsec          ; get sector
  Tue Jul 17 11:00:19 2018                                                                                               Page  111




 8739  F94DA0  F0 BB                    beq     e_direrr0       ; no free sector
 8740                                   ;;jmp   wused
 8741                           
 8742                           ; sector allocation - mark bam for used sector
 8743  F94DA2                   wused:
 8744  F94DA2  20 5D 4E                 jsr     bamtrk          ; get bam index
 8745  F94DA5  20 4A 4E                 jsr     bambit
 8746  F94DA8  F0 22                    beq     ?10             ; used, no action
 8747  F94DAA  B7 8D                    lda     [bmpnt],y       ; get bits
 8748  F94DAC  5F A8 5A F9              eor     >bmask,x        ; toggle: mark sec used
 8749  F94DB0  97 8D                    sta     [bmpnt],y
 8750  F94DB2  A7 8D                    lda     [bmpnt]         ; count -1
 8751  F94DB4  3A                       dec     a
 8752  F94DB5  87 8D                    sta     [bmpnt]         ; save it
 8753  F94DB7  A6 19                    ldx     drvnum
 8754  F94DB9  A9 80                    lda     #$80
 8755  F94DBB  95 84                    sta     wbam,x          ; set it dirty  
 8756  F94DBD  A5 08                    lda     track
 8757  F94DBF  C9 28                    cmp     #dirtrk
 8758  F94DC1  F0 09                    beq     ?10
 8759  F94DC3  8A                       txa
 8760  F94DC4  0A                       asl     a
 8761  F94DC5  AA                       tax
 8762  F94DC6                           ACC16
 8763  F94DC6  C2 20                    rep     #PMFLAG
 8764                                   .LONGA  on
 8765                                   .MNLIST
 8766  F94DC8  D6 6A                    dec     ndbf,x          ; update total free block's
 8767  F94DCA                           ACC08
 8768  F94DCA  E2 20                    sep     #PMFLAG
 8769                                   .LONGA  off
 8770                                   .MNLIST
 8771  F94DCC  60               ?10:    rts
 8772                           
 8773                           ; free a sector - mark bam for free sector
 8774  F94DCD                   frets:
 8775  F94DCD  20 5D 4E                 jsr     bamtrk          ; mrk bam free
 8776  F94DD0  20 4A 4E                 jsr     bambit
 8777  F94DD3  D0 22                    bne     ?10             ; free already
 8778  F94DD5  B7 8D                    lda     [bmpnt],y       ; not free, free it
 8779  F94DD7  1F A8 5A F9              ora     bmask,x
 8780  F94DDB  97 8D                    sta     [bmpnt],y
 8781  F94DDD  A7 8D                    lda     [bmpnt]
 8782  F94DDF  1A                       inc     a               ; add one to # blocks free
 8783  F94DE0  87 8D                    sta     [bmpnt]
 8784  F94DE2  A6 19                    ldx     drvnum
 8785  F94DE4  A9 80                    lda     #$80
 8786  F94DE6  95 84                    sta     wbam,x          ; set it dirty
 8787  F94DE8  A5 08                    lda     track
 8788  F94DEA  C9 28                    cmp     #dirtrk
 8789  F94DEC  F0 09                    beq     ?10
 8790  F94DEE  8A                       txa
 8791  F94DEF  0A                       asl     a
 8792  F94DF0  AA                       tax
 8793  F94DF1                           ACC16
 8794  F94DF1  C2 20                    rep     #PMFLAG
 8795                                   .LONGA  on
  Tue Jul 17 11:00:19 2018                                                                                               Page  112




 8796                                   .MNLIST
 8797  F94DF3  F6 6A                    inc     ndbf,x          ; update total free block's
 8798  F94DF5                           ACC08
 8799  F94DF5  E2 20                    sep     #PMFLAG
 8800                                   .LONGA  off
 8801                                   .MNLIST
 8802  F94DF7  60               ?10:    rts
 8803                           
 8804                           ; find a free block in current track
 8805                           ; return Z = 0 if sector is a free block
 8806                           ; use tmp0
 8807  F94DF8                   getsec:
 8808  F94DF8  20 5D 4E                 jsr     bamtrk          ; set bam and block bit ptr
 8809  F94DFB  20 7D 4E                 jsr     avck            ; chk bits & count
 8810  F94DFE  A5 09            ?10:    lda     sector
 8811  F94E00  C9 28                    cmp     #numsec
 8812  F94E02  B0 09                    bcs     ?20             ; not free blocks in this track
 8813  F94E04  20 4A 4E                 jsr     bambit          ; get block offset
 8814  F94E07  D0 06                    bne     ?30             ; ok is free
 8815  F94E09  E6 09                    inc     sector          ; try next block numb.
 8816  F94E0B  80 F1                    bra     ?10             ; loop
 8817  F94E0D  A9 00            ?20:    lda     #0              ; nothing free
 8818  F94E0F  60               ?30:    rts                     ; (z=0): free
 8819                           
 8820                           ; write out bam of current drive, if dirty
 8821                           ; use wtmp, wtmp+1, tmp0
 8822  F94E10                   mapout:
 8823  F94E10  A6 19                    ldx     drvnum
 8824  F94E12  34 84                    bit     wbam,x          ; dirty?
 8825  F94E14  10 33                    bpl     ?50             ; no, no write
 8826  F94E16  A9 51                    lda     #maxtrk         ; verify bam first
 8827  F94E18  85 94                    sta     wtmp            ; set trk counter
 8828  F94E1A  B5 74                    lda     dirofs,x        ; preset bam ptr
 8829  F94E1C  1A                       inc     a               ; bam 1
 8830  F94E1D  B4 76                    ldy     dirbnk,x
 8831  F94E1F  85 8E                    sta     bmpnt+1
 8832  F94E21  1A                       inc     a
 8833  F94E22  85 95                    sta     wtmp+1          ; bam 2
 8834  F94E24  84 8F                    sty     bmpnt+2
 8835  F94E26  A9 10            ?10:    lda     #bindx          ; bam offset
 8836  F94E28  85 8D            ?20:    sta     bmpnt           ; lsb
 8837  F94E2A  20 7D 4E                 jsr     avck            ; check this trk
 8838  F94E2D  C6 94                    dec     wtmp            ; do next trk
 8839  F94E2F  F0 11                    beq     ?30             ; verify done
 8840  F94E31  18                       clc                     ; update bam pointer
 8841  F94E32  A5 8D                    lda     bmpnt
 8842  F94E34  69 06                    adc     #6              ; 6 byte per trk
 8843  F94E36  90 F0                    bcc     ?20             ; same bam
 8844  F94E38  A5 8E                    lda     bmpnt+1
 8845  F94E3A  C5 95                    cmp     wtmp+1
 8846  F94E3C  F0 04                    beq     ?30             ; end check
 8847  F94E3E  E6 8E                    inc     bmpnt+1         ; do next bam
 8848  F94E40  80 E4                    bra     ?10
 8849  F94E42  20 02 58         ?30:    jsr     bamout          ; wrt the bams
 8850  F94E45  A6 19            ?40:    ldx     drvnum
 8851  F94E47  74 84                    stz     wbam,x          ; set it clean now!
 8852  F94E49  60               ?50:    rts
  Tue Jul 17 11:00:19 2018                                                                                               Page  113




 8853                           
 8854                           ; check if a block is free or not
 8855                           ; in:   bmpnt = bam pointer
 8856                           ;       sector = block number (0..39)
 8857                           ; out:  Z = 0 if blocks is free
 8858                           ;       Y,X = bam byte index and bit index
 8859  F94E4A                   bambit:
 8860  F94E4A  A5 09                    lda     sector          ; get block bit in bam
 8861  F94E4C  4A                       lsr     a               ; sectr/8
 8862  F94E4D  4A                       lsr     a
 8863  F94E4E  4A                       lsr     a
 8864  F94E4F  A8                       tay
 8865  F94E50  C8                       iny                     ; adjust it
 8866  F94E51  A5 09                    lda     sector          ; get remainder
 8867  F94E53  29 07                    and     #$07
 8868  F94E55  AA                       tax                     ; bit mask index
 8869  F94E56  B7 8D                    lda     [bmpnt],y
 8870  F94E58  3F A8 5A F9              and     >bmask,x        ; = 0 if not free
 8871  F94E5C  60                       rts
 8872                           
 8873                           ; set bam pointer for track and drvnum
 8874  F94E5D                   bamtrk:
 8875  F94E5D  A6 19                    ldx     drvnum
 8876  F94E5F  B5 76                    lda     dirbnk,x
 8877  F94E61  85 8F                    sta     bmpnt+2         ; set bank pointer
 8878  F94E63  B4 74                    ldy     dirofs,x        ; high pointer
 8879  F94E65  C8                       iny                     ; set for bam 1
 8880  F94E66  A5 08                    lda     track
 8881  F94E68  C9 29                    cmp     #41             ; which bam ?
 8882  F94E6A  90 03                    bcc     ?04             ; bam1
 8883  F94E6C  E9 28                    sbc     #40             ; range 40 trk per bam
 8884  F94E6E  C8                       iny                     ; it's bam2
 8885  F94E6F  84 8E            ?04:    sty     bmpnt+1
 8886  F94E71  0A                       asl     a               ; trk x6 offset
 8887  F94E72  85 8D                    sta     bmpnt           ; save x2
 8888  F94E74  0A                       asl     a               ; x4
 8889  F94E75  18                       clc                     ; total=x6
 8890  F94E76  65 8D                    adc     bmpnt           ;
 8891  F94E78  69 0A                    adc     #bindx-6        ; bam offset -1 trk blk
 8892  F94E7A  85 8D                    sta     bmpnt
 8893  F94E7C  60                       rts
 8894                           
 8895                           ; check count of free blocks in track
 8896                           ; use tmp0
 8897  F94E7D                   avck:
 8898  F94E7D  64 93                    stz     tmp0            ; blk counter
 8899  F94E7F  A0 05                    ldy     #bamsiz-1       ; offset of last byte
 8900  F94E81  A2 08            ?10:    ldx     #8              ; bit counter
 8901  F94E83  B7 8D                    lda     [bmpnt],y
 8902  F94E85  0A               ?20:    asl     a               ; used ?
 8903  F94E86  90 02                    bcc     ?30             ; no
 8904  F94E88  E6 93                    inc     tmp0            ; count it
 8905  F94E8A  CA               ?30:    dex
 8906  F94E8B  D0 F8                    bne     ?20             ; do next bit
 8907  F94E8D  88                       dey                     ; do next byte
 8908  F94E8E  D0 F1                    bne     ?10
 8909  F94E90  A7 8D                    lda     [bmpnt]         ; stored count of free blocks
  Tue Jul 17 11:00:19 2018                                                                                               Page  114




 8910  F94E92  C5 93                    cmp     tmp0
 8911  F94E94  D0 01                    bne     ?40             ; counts don't match
 8912  F94E96  60                       rts
 8913  F94E97  A9 51            ?40:    lda     #bamcnt
 8914  F94E99  4C 07 41                 jmp     cmderr
 8915                           
 8916                           ; build bam for an empty new disk
 8917  F94E9C                   newmap:
 8918  F94E9C  A6 19                    ldx     drvnum          ; init buffer for bam1&bam2
 8919  F94E9E  B5 74                    lda     dirofs,x
 8920  F94EA0  B4 76                    ldy     dirbnk,x
 8921  F94EA2  18                       clc
 8922  F94EA3  69 28                    adc     #numsec         ; buffer allocated after dir. cache
 8923  F94EA5  1A                       inc     a               ; +1
 8924  F94EA6  85 8E                    sta     bmpnt+1         ; bmpnt -> bam 1
 8925  F94EA8  84 8F                    sty     bmpnt+2
 8926  F94EAA  1A                       inc     a
 8927  F94EAB  85 3F                    sta     tlp+1           ; tlp -> bam 2
 8928  F94EAD  84 40                    sty     tlp+2
 8929  F94EAF  64 8D                    stz     bmpnt
 8930  F94EB1  64 3E                    stz     tlp
 8931  F94EB3  A0 00                    ldy     #0
 8932  F94EB5  98                       tya
 8933  F94EB6  97 8D            ?02:    sta     [bmpnt],y       ; clear bam1&bam2
 8934  F94EB8  97 3E                    sta     [tlp],y
 8935  F94EBA  C8                       iny
 8936  F94EBB  D0 F9                    bne     ?02
 8937  F94EBD  A9 28                    lda     #dirtrk         ; link to bam2
 8938  F94EBF  87 8D                    sta     [bmpnt]         ; set trk links
 8939  F94EC1  98                       tya                     ; Y=0 -- end trk link
 8940  F94EC2  87 3E                    sta     [tlp]           ;
 8941  F94EC4  A9 02                    lda     #2              ; link to bam2
 8942  F94EC6  C8                       iny                     ; 1
 8943  F94EC7  97 8D                    sta     [bmpnt],y
 8944  F94EC9  A9 FF                    lda     #$ff            ; sector end link
 8945  F94ECB  97 3E                    sta     [tlp],y
 8946  F94ECD  A9 44                    lda     #dskvern        ; disk version number
 8947  F94ECF  C8                       iny                     ; 2
 8948  F94ED0  97 8D                    sta     [bmpnt],y
 8949  F94ED2  97 3E                    sta     [tlp],y
 8950  F94ED4  49 FF                    eor     #$FF            ; complement  
 8951  F94ED6  C8                       iny                     ; 3
 8952  F94ED7  97 8D                    sta     [bmpnt],y
 8953  F94ED9  97 3E                    sta     [tlp],y
 8954  F94EDB  BD FC E1                 lda     !dskid1,x       ; ID 1
 8955  F94EDE  C8                       iny                     ; 4
 8956  F94EDF  97 8D                    sta     [bmpnt],y
 8957  F94EE1  97 3E                    sta     [tlp],y
 8958  F94EE3  BD FE E1                 lda     !dskid2,x       ; ID 2
 8959  F94EE6  C8                       iny                     ; 5
 8960  F94EE7  97 8D                    sta     [bmpnt],y
 8961  F94EE9  97 3E                    sta     [tlp],y
 8962  F94EEB  A9 C0                    lda     #iobyte         ; default i/o byte
 8963  F94EED  C8                       iny                     ; 6
 8964  F94EEE  97 8D                    sta     [bmpnt],y
 8965  F94EF0  97 3E                    sta     [tlp],y
 8966  F94EF2  A0 10            ?04:    ldy     #bindx          ; bam offset
  Tue Jul 17 11:00:19 2018                                                                                               Page  115




 8967  F94EF4  A9 28            ?06:    lda     #numsec
 8968  F94EF6  97 8D                    sta     [bmpnt],y       ; store free block's in this track
 8969  F94EF8  C8                       iny
 8970  F94EF9  A2 05                    ldx     #5              ; bytes counter
 8971  F94EFB  A9 FF                    lda     #$FF            ; all free
 8972  F94EFD  97 8D            ?08:    sta     [bmpnt],y       ; write out bit map
 8973  F94EFF  C8                       iny
 8974  F94F00  CA                       dex
 8975  F94F01  D0 FA                    bne     ?08
 8976  F94F03  98                       tya                     ; done?
 8977  F94F04  D0 EE                    bne     ?06             ; no
 8978  F94F06  A5 8E                    lda     bmpnt+1
 8979  F94F08  C5 3F                    cmp     tlp+1           ; both bams done?
 8980  F94F0A  F0 04                    beq     ?10             ; yep...
 8981  F94F0C  E6 8E                    inc     bmpnt+1         ; do the next bam
 8982  F94F0E  80 E2                    bra     ?04             ; next bam
 8983  F94F10                   ?10:    ACC16
 8984  F94F10  C2 20                    rep     #PMFLAG
 8985                                   .LONGA  on
 8986                                   .MNLIST
 8987  F94F12  A9 58 0C                 lda     #maxblks        ; max. available block's
 8988  F94F15  85 94                    sta     wtmp
 8989  F94F17                           ACC08
 8990  F94F17  E2 20                    sep     #PMFLAG
 8991                                   .LONGA  off
 8992                                   .MNLIST
 8993  F94F19  C6 8E                    dec     bmpnt+1         ; back to bam 1
 8994  F94F1B  A9 28                    lda     #dirtrk         ; alloc sector for system track
 8995  F94F1D  0A                       asl     a               ; trk x6 offset
 8996  F94F1E  85 8D                    sta     bmpnt           ; save x2
 8997  F94F20  0A                       asl     a               ; x4
 8998  F94F21  18                       clc                     ; total=x6
 8999  F94F22  65 8D                    adc     bmpnt           ;
 9000  F94F24  69 0A                    adc     #bindx-6        ; bam offset -1 trk blk
 9001  F94F26  85 8D                    sta     bmpnt           ; pointer to bitmap for system track
 9002  F94F28  64 09                    stz     sector          ; allocate 3 sectors & directory sector
 9003  F94F2A  20 39 4F                 jsr     ?20             ; sec. 0
 9004  F94F2D  E6 09                    inc     sector
 9005  F94F2F  20 39 4F                 jsr     ?20             ; sec. 1
 9006  F94F32  E6 09                    inc     sector
 9007  F94F34  20 39 4F                 jsr     ?20             ; sec. 2
 9008  F94F37  E6 09                    inc     sector          ; sec. 3 usually for dir.
 9009  F94F39  20 4A 4E         ?20:    jsr     bambit
 9010  F94F3C  F0 0D                    beq     ?30             ; used, no action
 9011  F94F3E  B7 8D                    lda     [bmpnt],y       ; get bits
 9012  F94F40  5F A8 5A F9              eor     >bmask,x        ; toggle: mark sec used
 9013  F94F44  97 8D                    sta     [bmpnt],y
 9014  F94F46  A7 8D                    lda     [bmpnt]         ; count -1
 9015  F94F48  3A                       dec     a
 9016  F94F49  87 8D                    sta     [bmpnt]         ; save it
 9017  F94F4B  60               ?30:    rts
 9018                           
 9019                           ; build a new disk header in system cache
 9020  F94F4C                   newhdr:
 9021  F94F4C  A0 01                    ldy     #1
 9022  F94F4E  A9 28                    lda     #dirtrk         ; directory track
 9023  F94F50  87 0A                    sta     [dirp]
  Tue Jul 17 11:00:19 2018                                                                                               Page  116




 9024  F94F52  A9 03                    lda     #dirst          ; link to first dir. block
 9025  F94F54  97 0A                    sta     [dirp],y
 9026  F94F56  C8                       iny                     ; 2
 9027  F94F57  A9 44                    lda     #dskvern
 9028  F94F59  97 0A                    sta     [dirp],y        ; disk version number
 9029  F94F5B  C8                       iny
 9030  F94F5C  C8                       iny                     ; 4
 9031  F94F5D  A6 1A                    ldx     filtbl          ; ptr to disk name
 9032  F94F5F  BD 00 E1         ?02:    lda     !cmdbuf,x       ; store disk name
 9033  F94F62  F0 06                    beq     ?04
 9034  F94F64  97 0A                    sta     [dirp],y
 9035  F94F66  C8                       iny
 9036  F94F67  E8                       inx
 9037  F94F68  80 F5                    bra     ?02
 9038  F94F6A  A9 A0            ?04:    lda     #$A0
 9039  F94F6C  97 0A                    sta     [dirp],y        ; 20
 9040  F94F6E  C8                       iny
 9041  F94F6F  97 0A                    sta     [dirp],y
 9042  F94F71  C8                       iny                     ; 22
 9043  F94F72  A6 19                    ldx     drvnum
 9044  F94F74  BD FC E1                 lda     !dskid1,x       ; store ID 1
 9045  F94F77  97 0A                    sta     [dirp],y
 9046  F94F79  C8                       iny                     ; 23
 9047  F94F7A  BD FE E1                 lda     !dskid2,x       ; store ID 2
 9048  F94F7D  97 0A                    sta     [dirp],y
 9049  F94F7F  C8                       iny                     ; 24
 9050  F94F80  A9 A0                    lda     #$A0
 9051  F94F82  97 0A                    sta     [dirp],y
 9052  F94F84  C8                       iny                     ; 25
 9053  F94F85  A9 33                    lda     #dosvern        ; store dos version number
 9054  F94F87  97 0A                    sta     [dirp],y
 9055  F94F89  C8                       iny                     ; 26
 9056  F94F8A  A9 44                    lda     #dskvern
 9057  F94F8C  97 0A                    sta     [dirp],y        ; disk version number
 9058  F94F8E  C8                       iny                     ; 27
 9059  F94F8F  A9 A0                    lda     #$A0
 9060  F94F91  97 0A                    sta     [dirp],y
 9061  F94F93  C8                       iny                     ; 28
 9062  F94F94  A9 A0                    lda     #$A0
 9063  F94F96  97 0A                    sta     [dirp],y
 9064  F94F98  A0 1E                    ldy     #30
 9065  F94F9A  A9 8D                    lda     #subvern        ; store sub-version
 9066  F94F9C  97 0A                    sta     [dirp],y
 9067  F94F9E  C8                       iny                     ; 31
 9068  F94F9F  49 FF                    eor     #$FF
 9069  F94FA1  97 0A                    sta     [dirp],y
 9070  F94FA3                           CPU16
 9071  F94FA3  C2 30                    rep     #(PMFLAG.OR.PXFLAG)
 9072                                   .LONGA  on
 9073                                   .LONGI  on
 9074                                   .MNLIST
 9075  F94FA5  20 A5 1B                 jsr     gctime16        ; compact time&date (ret CPU16)
 9076  F94FA8  A0 20 00                 ldy     #32
 9077  F94FAB  97 0A                    sta     [dirp],y        ; store 32 bit serial
 9078  F94FAD  8A                       txa
 9079  F94FAE  C8                       iny
 9080  F94FAF  C8                       iny
  Tue Jul 17 11:00:19 2018                                                                                               Page  117




 9081  F94FB0  97 0A                    sta     [dirp],y
 9082  F94FB2  A9 58 0C                 lda     #maxblks
 9083  F94FB5  85 94                    sta     wtmp
 9084  F94FB7                           CPU08   
 9085  F94FB7  E2 30                    sep     #(PMFLAG.OR.PXFLAG)
 9086                                   .LONGA  off
 9087                                   .LONGI  off
 9088                                   .MNLIST
 9089  F94FB9  60                       rts
 9090                           
 9091                           ;---------------------------------------------------------------------------
 9092                           ; file system check routines
 9093                           ;---------------------------------------------------------------------------
 9094                           
 9095                           ; mark aux bam for used sector
 9096  F94FBA                   mkbam:
 9097  F94FBA  A6 19                    ldx     drvnum          ; set pointer to aux bam
 9098  F94FBC  B5 74                    lda     dirofs,x
 9099  F94FBE  B4 76                    ldy     dirbnk,x
 9100  F94FC0  84 8F                    sty     bmpnt+2 
 9101  F94FC2  18                       clc
 9102  F94FC3  69 28                    adc     #numsec         ; buffer allocated after dir. cache
 9103  F94FC5  1A                       inc     a               ; +1
 9104  F94FC6  A8                       tay
 9105  F94FC7  A5 09                    lda     sector
 9106  F94FC9  C9 28                    cmp     #numsec
 9107  F94FCB  B0 3A                    bcs     ?04
 9108  F94FCD  A5 08                    lda     track
 9109  F94FCF  F0 36                    beq     ?04
 9110  F94FD1  C9 51                    cmp     #maxtrk
 9111  F94FD3  B0 32                    bcs     ?04
 9112  F94FD5  C9 29                    cmp     #41             ; which bam ?
 9113  F94FD7  90 03                    bcc     ?02             ; bam1
 9114  F94FD9  E9 28                    sbc     #40             ; range 40 trk per bam
 9115  F94FDB  C8                       iny                     ; it's bam2
 9116  F94FDC  84 8E            ?02:    sty     bmpnt+1
 9117  F94FDE  0A                       asl     a               ; trk x6 offset
 9118  F94FDF  85 8D                    sta     bmpnt           ; save x2
 9119  F94FE1  0A                       asl     a               ; x4
 9120  F94FE2  18                       clc                     ; total=x6
 9121  F94FE3  65 8D                    adc     bmpnt           ;
 9122  F94FE5  69 0A                    adc     #bindx-6        ; bam offset -1 trk blk
 9123  F94FE7  85 8D                    sta     bmpnt
 9124  F94FE9  20 4A 4E                 jsr     bambit
 9125  F94FEC  F0 19                    beq     ?04             ; used, no action
 9126  F94FEE  B7 8D                    lda     [bmpnt],y       ; get bits
 9127  F94FF0  5F A8 5A F9              eor     >bmask,x        ; toggle: mark sec used
 9128  F94FF4  97 8D                    sta     [bmpnt],y
 9129  F94FF6  A7 8D                    lda     [bmpnt]         ; count -1
 9130  F94FF8  3A                       dec     a
 9131  F94FF9  87 8D                    sta     [bmpnt]         ; save it
 9132  F94FFB  A5 08                    lda     track
 9133  F94FFD  C9 28                    cmp     #dirtrk
 9134  F94FFF  F0 06                    beq     ?04
 9135  F95001                           ACC16
 9136  F95001  C2 20                    rep     #PMFLAG
 9137                                   .LONGA  on
  Tue Jul 17 11:00:19 2018                                                                                               Page  118




 9138                                   .MNLIST
 9139  F95003  C6 86                    dec     ntot            ; update total free block's
 9140  F95005                           ACC08
 9141  F95005  E2 20                    sep     #PMFLAG
 9142                                   .LONGA  off
 9143                                   .MNLIST
 9144  F95007  60               ?04:    rts
 9145                           
 9146                           ; check file consistency and update aux bam
 9147                           ; enter with start t&s of the file
 9148  F95008                   chkfil:
 9149  F95008  A5 09                    lda     sector          ; save dir. sector
 9150  F9500A  85 2A                    sta     entsec
 9151  F9500C  A7 0A                    lda     [dirp]
 9152  F9500E  85 0E                    sta     type
 9153  F95010  A0 01                    ldy     #1
 9154  F95012  B7 0A                    lda     [dirp],y
 9155  F95014  85 08                    sta     track           ; set up first t&s
 9156  F95016  C8                       iny
 9157  F95017  B7 0A                    lda     [dirp],y
 9158  F95019  85 09                    sta     sector  
 9159  F9501B  A9 22                    lda     #'"'
 9160  F9501D  8D DD E1                 sta     !nambuf2
 9161  F95020  A2 00                    ldx     #0
 9162  F95022  C8                       iny
 9163  F95023  B7 0A            ?02:    lda     [dirp],y
 9164  F95025  30 09                    bmi     ?04
 9165  F95027  9D DE E1                 sta     !nambuf2+1,x
 9166  F9502A  C8                       iny
 9167  F9502B  E8                       inx
 9168  F9502C  E0 10                    cpx     #16
 9169  F9502E  90 F3                    bcc     ?02
 9170  F95030  A9 22            ?04:    lda     #'"'
 9171  F95032  9D DE E1                 sta     !nambuf2+1,x
 9172  F95035  9E DF E1                 stz     !nambuf2+2,x
 9173  F95038  A0 1C                    ldy     #28             ; check block's count
 9174  F9503A                           ACC16
 9175  F9503A  C2 20                    rep     #PMFLAG
 9176                                   .LONGA  on
 9177                                   .MNLIST
 9178  F9503C  B7 0A                    lda     [dirp],y
 9179  F9503E  85 94                    sta     wtmp            ; stored file block's count
 9180  F95040  64 F0                    stz     wcnt            ; clear block's counter
 9181  F95042                           ACC08
 9182  F95042  E2 20                    sep     #PMFLAG
 9183                                   .LONGA  off
 9184                                   .MNLIST
 9185  F95044  A5 0E                    lda     type
 9186  F95046  30 2B                    bmi     ?12
 9187  F95048  A9 00                    lda     #^nambuf2
 9188  F9504A  48                       pha
 9189  F9504B  F4 DD E1                 pea     #!nambuf2
 9190  F9504E  4B                       phk                     ; splat file msg
 9191  F9504F  F4 85 51                 pea     #!?100
 9192  F95052  A9 07                    lda     #7
 9193  F95054  48                       pha
 9194  F95055                           BPRINTF
  Tue Jul 17 11:00:19 2018                                                                                               Page  119




 9195  F95055  02 11                    cop     $11
 9196                                   .MNLIST
 9197  F95057  24 E6                    bit     wrop
 9198  F95059  30 03                    bmi     ?08             ; ok, delete splat file
 9199  F9505B  4C 7B 51                 jmp     ?90             ; skip & exit
 9200  F9505E  A9 00            ?08:    lda     #0              ; delete entry
 9201  F95060  87 0A                    sta     [dirp]
 9202  F95062  A5 2A                    lda     entsec
 9203  F95064  85 09                    sta     sector
 9204  F95066  20 57 36                 jsr     wrdsec          ; update dir
 9205  F95069  A2 F9                    ldx     #^?105
 9206  F9506B  A9 51                    lda     #>?105
 9207  F9506D  EB                       xba
 9208  F9506E  A9 9D                    lda     #<?105
 9209  F95070                           SCNSTROUT
 9210  F95070  02 03                    cop     $03
 9211                                   .MNLIST
 9212  F95072  60               ?10:    rts
 9213  F95073  29 07            ?12:    and     #typmsk
 9214  F95075  C9 04                    cmp     #reltyp
 9215  F95077  F0 F9                    beq     ?10             ; skip
 9216  F95079  C9 05                    cmp     #partyp
 9217  F9507B  F0 F5                    beq     ?10             ; skip
 9218  F9507D  A5 08                    lda     track
 9219  F9507F  F0 0A                    beq     ?13             ; invalid track
 9220  F95081  C9 51                    cmp     #maxtrk
 9221  F95083  B0 06                    bcs     ?13             ; invalid track
 9222  F95085  A5 09                    lda     sector
 9223  F95087  C9 28                    cmp     #numsec
 9224  F95089  90 03                    bcc     ?14             ; invalid sector?
 9225  F9508B  4C 2B 51         ?13:    jmp     ?30
 9226  F9508E  20 AB 57         ?14:    jsr     tread           ; read whole track in cache
 9227  F95091  20 4A 56                 jsr     setcp           ; set cache ptr to right sector
 9228  F95094                   ?16:    ACC16CLC
 9229  F95094  C2 21                    rep     #(PMFLAG.OR.PCFLAG)
 9230                                   .LONGA  on
 9231                                   .MNLIST
 9232  F95096  E6 F0                    inc     wcnt            ; update file block's counter
 9233  F95098  C6 88                    dec     bcnt            ; update total free block's
 9234  F9509A  A5 94                    lda     wtmp            ; stored block's #
 9235  F9509C  69 20 00                 adc     #32             ; add a guard
 9236  F9509F  C5 F0                    cmp     wcnt            ; compare with computed block's #
 9237  F950A1                           ACC08
 9238  F950A1  E2 20                    sep     #PMFLAG
 9239                                   .LONGA  off
 9240                                   .MNLIST
 9241  F950A3  B0 03                    bcs     ?17
 9242  F950A5  4C 65 51                 jmp     ?50             ; hmmm...never reach end of file? 
 9243  F950A8  20 BA 4F         ?17:    jsr     mkbam           ; mark aux bam
 9244  F950AB  A0 01                    ldy     #1
 9245  F950AD  B7 8A                    lda     [bufp],y        ; next sector
 9246  F950AF  A8                       tay
 9247  F950B0  A7 8A                    lda     [bufp]          ; next track
 9248  F950B2  F0 1D                    beq     ?18             ; end of file?
 9249  F950B4  C9 51                    cmp     #maxtrk
 9250  F950B6  B0 04                    bcs     ?17a            ; invalid track in link
 9251  F950B8  C0 28                    cpy     #numsec         ; invalid sector in link?
  Tue Jul 17 11:00:19 2018                                                                                               Page  120




 9252  F950BA  90 03                    bcc     ?17b    
 9253  F950BC  4C 47 51         ?17a:   jmp     ?40
 9254  F950BF  84 09            ?17b:   sty     sector          ; next sector
 9255  F950C1  C5 08                    cmp     track           ; same track?
 9256  F950C3  85 08                    sta     track
 9257  F950C5  D0 C7                    bne     ?14             ; will read a new track 
 9258  F950C7  18                       clc
 9259  F950C8  98                       tya
 9260  F950C9  A6 19                    ldx     drvnum
 9261  F950CB  75 78                    adc     trkofs,x        ; sector in the same track
 9262  F950CD  85 8B                    sta     bufp+1
 9263                                   ;jsr    mkbam           ; mark aux bam
 9264  F950CF  80 C3                    bra     ?16             ; follow link   
 9265  F950D1  C0 02            ?18:    cpy     #2              ; in last block must be >= 2
 9266  F950D3  90 3F                    bcc     ?20
 9267  F950D5                           ACC16
 9268  F950D5  C2 20                    rep     #PMFLAG
 9269                                   .LONGA  on
 9270                                   .MNLIST
 9271  F950D7  A5 94                    lda     wtmp            ; check block's count
 9272  F950D9  C5 F0                    cmp     wcnt
 9273  F950DB                           ACC08
 9274  F950DB  E2 20                    sep     #PMFLAG
 9275                                   .LONGA  off
 9276                                   .MNLIST
 9277  F950DD  F0 93                    beq     ?10             ; ok, match -- exit
 9278  F950DF  D4 94                    pei     (wtmp)
 9279  F950E1  D4 F0                    pei     (wcnt)
 9280  F950E3  A9 00                    lda     #^nambuf2
 9281  F950E5  48                       pha
 9282  F950E6  F4 DD E1                 pea     #!nambuf2
 9283  F950E9  4B                       phk                     ; unmatch msg
 9284  F950EA  F4 AC 51                 pea     #!?115
 9285  F950ED  A9 0B                    lda     #11
 9286  F950EF  48                       pha
 9287  F950F0                           BPRINTF
 9288  F950F0  02 11                    cop     $11
 9289                                   .MNLIST
 9290  F950F2  24 E6                    bit     wrop
 9291  F950F4  30 03                    bmi     ?19
 9292  F950F6  4C 7B 51                 jmp     ?90             ; skip & exit
 9293  F950F9  A0 1C            ?19:    ldy     #28             ; correct
 9294  F950FB                           ACC16
 9295  F950FB  C2 20                    rep     #PMFLAG
 9296                                   .LONGA  on
 9297                                   .MNLIST
 9298  F950FD  A5 F0                    lda     wcnt
 9299  F950FF  97 0A                    sta     [dirp],y
 9300  F95101                           ACC08
 9301  F95101  E2 20                    sep     #PMFLAG
 9302                                   .LONGA  off
 9303                                   .MNLIST
 9304  F95103  A5 2A                    lda     entsec
 9305  F95105  85 09                    sta     sector
 9306  F95107  20 57 36                 jsr     wrdsec          ; update dir
 9307  F9510A  A2 F9                    ldx     #^?130
 9308  F9510C  A9 52                    lda     #>?130
  Tue Jul 17 11:00:19 2018                                                                                               Page  121




 9309  F9510E  EB                       xba
 9310  F9510F  A9 4C                    lda     #<?130
 9311  F95111                           SCNSTROUT       
 9312  F95111  02 03                    cop     $03
 9313                                   .MNLIST
 9314  F95113  60                       rts
 9315  F95114  A5 09            ?20:    lda     sector
 9316  F95116  48                       pha
 9317  F95117  A5 08                    lda     track
 9318  F95119  48                       pha
 9319  F9511A  5A                       phy                     ; last ptr
 9320  F9511B  A9 00                    lda     #^nambuf2
 9321  F9511D  48                       pha
 9322  F9511E  F4 DD E1                 pea     #!nambuf2
 9323  F95121  4B                       phk                     ; corrupted last link
 9324  F95122  F4 E3 51                 pea     #!?120
 9325  F95125  A9 0A                    lda     #10
 9326  F95127  48                       pha
 9327  F95128                           BPRINTF
 9328  F95128  02 11                    cop     $11
 9329                                   .MNLIST
 9330  F9512A  60                       rts                     ; no correction possible here
 9331  F9512B  A5 09            ?30:    lda     sector          ; invalid start track and/or sector
 9332  F9512D  48                       pha
 9333  F9512E  A5 08                    lda     track
 9334  F95130  48                       pha 
 9335  F95131  A9 00                    lda     #^nambuf2
 9336  F95133  48                       pha
 9337  F95134  F4 DD E1                 pea     #!nambuf2
 9338  F95137  4B                       phk
 9339  F95138  F4 1D 52                 pea     #!?125
 9340  F9513B  A9 09                    lda     #9
 9341  F9513D  48                       pha
 9342  F9513E                           BPRINTF
 9343  F9513E  02 11                    cop     $11
 9344                                   .MNLIST
 9345  F95140  24 E6                    bit     wrop
 9346  F95142  10 37                    bpl     ?90             ; skip
 9347  F95144  4C 5E 50                 jmp     ?08             ; delete entry
 9348                           
 9349  F95147  A6 09            ?40:    ldx     sector          ; invalid link
 9350  F95149  DA                       phx
 9351  F9514A  A6 08                    ldx     track
 9352  F9514C  DA                       phx
 9353  F9514D  5A                       phy                     ; possible invalid sec link
 9354  F9514E  48                       pha                     ; possible invalid trk link
 9355  F9514F  A9 00                    lda     #^nambuf2
 9356  F95151  48                       pha
 9357  F95152  F4 DD E1                 pea     #!nambuf2
 9358  F95155  4B                       phk
 9359  F95156  F4 55 52                 pea     #!?135
 9360  F95159  A9 0B                    lda     #11
 9361  F9515B  48                       pha
 9362  F9515C                           BPRINTF
 9363  F9515C  02 11                    cop     $11
 9364                                   .MNLIST
 9365  F9515E  24 E6                    bit     wrop
  Tue Jul 17 11:00:19 2018                                                                                               Page  122




 9366  F95160  10 19                    bpl     ?90             ; skip
 9367  F95162  4C 5E 50                 jmp     ?08             ; delete entry
 9368                           
 9369  F95165  A9 00            ?50:    lda     #^nambuf2       ; eof not found...
 9370  F95167  48                       pha
 9371  F95168  F4 DD E1                 pea     #!nambuf2
 9372  F9516B  4B                       phk
 9373  F9516C  F4 8C 52                 pea     #!?140
 9374  F9516F  A9 07                    lda     #7
 9375  F95171  48                       pha
 9376  F95172                           BPRINTF
 9377  F95172  02 11                    cop     $11
 9378                                   .MNLIST
 9379  F95174  24 E6                    bit     wrop
 9380  F95176  10 03                    bpl     ?90             ; skip
 9381  F95178  4C 5E 50                 jmp     ?08             ; delete entry
 9382                           
 9383  F9517B  A2 F9            ?90:    ldx     #^?110          ; show 'skip' msg & exit
 9384  F9517D  A9 51                    lda     #>?110
 9385  F9517F  EB                       xba
 9386  F95180  A9 A6                    lda     #<?110
 9387  F95182                           SCNSTROUT
 9388  F95182  02 03                    cop     $03
 9389                                   .MNLIST
 9390  F95184  60                       rts
 9391                           
 9392  F95185  0D 66 69 6C 65   ?100:   .DB     $0D, 'file %s: not closed...', 0
               20 25 73 3A 20 
               6E 6F 74 20 63 
               6C 6F 73 65 64 
               2E 2E 2E 00 
 9393  F9519D  64 65 6C 65 74   ?105:   .DB     'deleted.', 0
               65 64 2E 00 
 9394  F951A6  73 6B 69 70 2E   ?110:   .DB     'skip.', 0
               00 
 9395  F951AC  0D 66 69 6C 65   ?115:   .DB     $0D, 'file %s: unmatch blocks count (actual %hu vs. %hu)...', 0
               20 25 73 3A 20 
               75 6E 6D 61 74 
               63 68 20 62 6C 
               6F 63 6B 73 20 
               63 6F 75 6E 74 
               20 28 61 63 74 
               75 61 6C 20 25 
               68 75 20 76 73 
               2E 20 25 68 75 
               29 2E 2E 2E 00 
 9396  F951E3  0D 66 69 6C 65   ?120:   .DB     $0D, 'file %s: last link (t:0,s:%bu) corrupted at t:%bu,s:%bu.', 0
               20 25 73 3A 20 
               6C 61 73 74 20 
               6C 69 6E 6B 20 
               28 74 3A 30 2C 
               73 3A 25 62 75 
               29 20 63 6F 72 
               72 75 70 74 65 
               64 20 61 74 20 
               74 3A 25 62 75 
               2C 73 3A 25 62 
  Tue Jul 17 11:00:19 2018                                                                                               Page  123




               75 2E 00 
 9397  F9521D  0D 66 69 6C 65   ?125:   .DB     $0D, 'file %s: invalid start block (t:%bu,s:%bu)...', 0
               20 25 73 3A 20 
               69 6E 76 61 6C 
               69 64 20 73 74 
               61 72 74 20 62 
               6C 6F 63 6B 20 
               28 74 3A 25 62 
               75 2C 73 3A 25 
               62 75 29 2E 2E 
               2E 00 
 9398  F9524C  63 6F 72 72 65   ?130:   .DB     'correct.', 0
               63 74 2E 00 
 9399  F95255  0D 66 69 6C 65   ?135:   .DB     $0D, 'file %s: invalid link (t:%bu,s:%bu) at t:%bu,s:%bu...', 0
               20 25 73 3A 20 
               69 6E 76 61 6C 
               69 64 20 6C 69 
               6E 6B 20 28 74 
               3A 25 62 75 2C 
               73 3A 25 62 75 
               29 20 61 74 20 
               74 3A 25 62 75 
               2C 73 3A 25 62 
               75 2E 2E 2E 00 
 9400  F9528C  0D 66 69 6C 65   ?140:   .DB     $0D, 'file %s: EOF not found...', 0
               20 25 73 3A 20 
               45 4F 46 20 6E 
               6F 74 20 66 6F 
               75 6E 64 2E 2E 
               2E 00 
 9401                           
 9402                           ; check directory consistence & update aux bam
 9403  F952A7                   chkdir:
 9404  F952A7  A9 28                    lda     #dirtrk
 9405  F952A9  85 08                    sta     track
 9406  F952AB  64 09                    stz     sector
 9407  F952AD  20 AB 57                 jsr     tread           ; read whole track in cache
 9408  F952B0  20 4A 56                 jsr     setcp           ; set cache ptr to right sector
 9409  F952B3  20 BA 4F         ?02:    jsr     mkbam           ; mark aux bam
 9410  F952B6  A0 01                    ldy     #1
 9411  F952B8  B7 8A                    lda     [bufp],y        ; next sector
 9412  F952BA  A8                       tay
 9413  F952BB  A7 8A                    lda     [bufp]          ; next track
 9414  F952BD  F0 12                    beq     ?04             ; end of dir?
 9415  F952BF  84 09                    sty     sector          ; next sector
 9416  F952C1  C5 08                    cmp     track           ; same track?
 9417  F952C3  85 08                    sta     track
 9418  F952C5  D0 0E                    bne     ?10             ; error!        
 9419  F952C7  18                       clc
 9420  F952C8  98                       tya
 9421  F952C9  A6 19                    ldx     drvnum
 9422  F952CB  75 78                    adc     trkofs,x        ; sector in the same track
 9423  F952CD  85 8B                    sta     bufp+1
 9424  F952CF  80 E2                    bra     ?02             ; follow link   
 9425  F952D1  C0 FF            ?04:    cpy     #$FF            ; must be $FF
 9426  F952D3  F0 10                    beq     ?15
 9427  F952D5  A5 09            ?10:    lda     sector
  Tue Jul 17 11:00:19 2018                                                                                               Page  124




 9428  F952D7  48                       pha
 9429  F952D8  5A                       phy                     ; last ptr
 9430  F952D9  A5 08                    lda     track
 9431  F952DB  48                       pha
 9432  F952DC  4B                       phk                     ; unmatch msg
 9433  F952DD  F4 E6 52                 pea     #!?20
 9434  F952E0  A9 07                    lda     #7
 9435  F952E2  48                       pha
 9436  F952E3                           BPRINTF
 9437  F952E3  02 11                    cop     $11
 9438                                   .MNLIST
 9439  F952E5  60               ?15:    rts
 9440                           
 9441  F952E6  0D 64 69 72 65   ?20:    .DB     $0D, 'directory: wrong link (t:%bu,s:%bu) at sector %bu', 0
               63 74 6F 72 79 
               3A 20 77 72 6F 
               6E 67 20 6C 69 
               6E 6B 20 28 74 
               3A 25 62 75 2C 
               73 3A 25 62 75 
               29 20 61 74 20 
               73 65 63 74 6F 
               72 20 25 62 75 
               00 
 9442                           
 9443                           ; report file block's count & update bam if validation
 9444  F95319                   updbam:
 9445  F95319  20 C4 53                 jsr     ?30             ; for safety check again aux bam free block's
 9446  F9531C                           ACC16
 9447  F9531C  C2 20                    rep     #PMFLAG
 9448                                   .LONGA  on
 9449                                   .MNLIST
 9450  F9531E  A5 86                    lda     ntot
 9451  F95320  C5 94                    cmp     wtmp
 9452  F95322                           ACC08
 9453  F95322  E2 20                    sep     #PMFLAG
 9454                                   .LONGA  off
 9455                                   .MNLIST
 9456  F95324  F0 1B                    beq     ?06
 9457  F95326  D4 94                    pei     (wtmp)
 9458  F95328  D4 86                    pei     (ntot)
 9459  F9532A  4B                       phk
 9460  F9532B  F4 8A 54                 pea     #!?65
 9461  F9532E  A9 08                    lda     #8
 9462  F95330  48                       pha
 9463  F95331                           BPRINTF
 9464  F95331  02 11                    cop     $11
 9465                                   .MNLIST
 9466  F95333  24 E6            ?02:    bit     wrop
 9467  F95335  10 09                    bpl     ?04
 9468  F95337  A9 54                    lda     #>?70
 9469  F95339  EB                       xba
 9470  F9533A  A9 B6                    lda     #<?70
 9471  F9533C  A2 F9                    ldx     #^?70
 9472  F9533E                           SCNSTROUT
 9473  F9533E  02 03                    cop     $03
 9474                                   .MNLIST
  Tue Jul 17 11:00:19 2018                                                                                               Page  125




 9475  F95340  60               ?04:    rts
 9476  F95341  D4 88            ?06:    pei     (bcnt)
 9477  F95343  4B                       phk
 9478  F95344  F4 0F 54                 pea     #!?50
 9479  F95347  A9 06                    lda     #6
 9480  F95349  48                       pha
 9481  F9534A                           BPRINTF
 9482  F9534A  02 11                    cop     $11
 9483                                   .MNLIST
 9484  F9534C  D4 86                    pei     (ntot)
 9485  F9534E  4B                       phk
 9486  F9534F  F4 38 54                 pea     #!?55
 9487  F95352  A9 06                    lda     #6
 9488  F95354  48                       pha
 9489  F95355                           BPRINTF
 9490  F95355  02 11                    cop     $11
 9491                                   .MNLIST
 9492  F95357  A5 19                    lda     drvnum
 9493  F95359  0A                       asl     a
 9494  F9535A  AA                       tax
 9495  F9535B  B5 6A                    lda     ndbf,x
 9496  F9535D  B4 6B                    ldy     ndbf+1,x
 9497  F9535F  5A                       phy
 9498  F95360  48                       pha
 9499  F95361  4B                       phk
 9500  F95362  F4 61 54                 pea     #!?60
 9501  F95365  A9 06                    lda     #6
 9502  F95367  48                       pha
 9503  F95368                           BPRINTF
 9504  F95368  02 11                    cop     $11
 9505                                   .MNLIST
 9506  F9536A                           ACC16
 9507  F9536A  C2 20                    rep     #PMFLAG
 9508                                   .LONGA  on
 9509                                   .MNLIST
 9510  F9536C  A5 88                    lda     bcnt
 9511  F9536E  C5 86                    cmp     ntot
 9512  F95370                           ACC08
 9513  F95370  E2 20                    sep     #PMFLAG
 9514                                   .LONGA  off
 9515                                   .MNLIST
 9516  F95372  F0 0F                    beq     ?08
 9517  F95374  D4 86                    pei     (ntot)
 9518  F95376  D4 88                    pei     (bcnt)
 9519  F95378  4B                       phk
 9520  F95379  F4 D6 54                 pea     #!?75
 9521  F9537C  A9 08                    lda     #8
 9522  F9537E  48                       pha
 9523  F9537F                           BPRINTF
 9524  F9537F  02 11                    cop     $11
 9525                                   .MNLIST
 9526  F95381  80 B0                    bra     ?02
 9527  F95383                           
 9528                                   ; ok, bam can be updated
 9529  F95383  24 E6            ?08:    bit     wrop
 9530  F95385  10 3C                    bpl     ?10             ; no bam update
 9531  F95387  20 3D 56                 jsr     sethdp          ; update bam on disk
  Tue Jul 17 11:00:19 2018                                                                                               Page  126




 9532  F9538A  E6 0B                    inc     dirp+1          ; set up bam
 9533  F9538C  A6 19                    ldx     drvnum          ; set pointer to aux bam
 9534  F9538E  A9 80                    lda     #$80
 9535  F95390  95 84                    sta     wbam,x          ; set bam dirty
 9536  F95392  B5 74                    lda     dirofs,x
 9537  F95394  B4 76                    ldy     dirbnk,x
 9538  F95396  84 8F                    sty     bmpnt+2 
 9539  F95398  18                       clc
 9540  F95399  69 28                    adc     #numsec         ; buffer allocated after dir. cache
 9541  F9539B  1A                       inc     a               ; +1
 9542  F9539C  85 8E                    sta     bmpnt+1
 9543  F9539E  64 8D                    stz     bmpnt           ; ptr to new bam
 9544  F953A0                           INDEX16
 9545  F953A0  C2 10                    rep     #PXFLAG
 9546                                   .LONGI  on
 9547                                   .MNLIST
 9548  F953A2  A0 FF 01                 ldy     #$01FF          ; transfer the new bam
 9549  F953A5  B7 8D            ?09:    lda     [bmpnt],y
 9550  F953A7  97 0A                    sta     [dirp],y
 9551  F953A9  88                       dey
 9552  F953AA  10 F9                    bpl     ?09
 9553  F953AC                           INDEX08
 9554  F953AC  E2 10                    sep     #PXFLAG
 9555                                   .LONGI  off
 9556                                   .MNLIST
 9557  F953AE  A9 55                    lda     #>?85
 9558  F953B0  EB                       xba
 9559  F953B1  A9 27                    lda     #<?85
 9560  F953B3  A2 F9                    ldx     #^?85
 9561  F953B5                           SCNSTROUT
 9562  F953B5  02 03                    cop     $03
 9563                                   .MNLIST
 9564  F953B7  20 10 4E                 jsr     mapout          ; write out map
 9565  F953BA  A9 55                    lda     #>?80
 9566  F953BC  EB                       xba
 9567  F953BD  A9 10                    lda     #<?80
 9568  F953BF  A2 F9                    ldx     #^?80
 9569  F953C1                           SCNSTROUT
 9570  F953C1  02 03                    cop     $03
 9571                                   .MNLIST
 9572  F953C3  60               ?10:    rts
 9573                           ?30:    ; calc # of blocks free
 9574  F953C4  64 94                    stz     wtmp
 9575  F953C6  64 95                    stz     wtmp+1
 9576  F953C8  A0 01                    ldy     #startrk
 9577  F953CA  88                       dey
 9578  F953CB  C8               ?32:    iny
 9579  F953CC  84 08                    sty     track
 9580  F953CE  C0 28                    cpy     #dirtrk
 9581  F953D0  F0 F9                    beq     ?32             ; skip dir track
 9582  F953D2  C0 51                    cpy     #maxtrk         ; done ?
 9583  F953D4  B0 14                    bcs     ?34             ; yes
 9584  F953D6  20 EB 53                 jsr     ?40             ; set up next bam trk
 9585  F953D9  A4 08                    ldy     track           ; retrivie track
 9586  F953DB  A9 00                    lda     #0
 9587  F953DD  EB                       xba                     ; B = 0
 9588  F953DE  A7 8D                    lda     [bmpnt]         ; A = get blks free
  Tue Jul 17 11:00:19 2018                                                                                               Page  127




 9589  F953E0                           ACC16CLC
 9590  F953E0  C2 21                    rep     #(PMFLAG.OR.PCFLAG)
 9591                                   .LONGA  on
 9592                                   .MNLIST
 9593  F953E2  65 94                    adc     wtmp            ; up data count
 9594  F953E4  85 94                    sta     wtmp
 9595  F953E6                           ACC08
 9596  F953E6  E2 20                    sep     #PMFLAG
 9597                                   .LONGA  off
 9598                                   .MNLIST
 9599  F953E8  80 E1                    bra     ?32
 9600  F953EA  60               ?34:    rts
 9601                           
 9602  F953EB  A6 19            ?40:    ldx     drvnum          ; set pointer to aux bam
 9603  F953ED  B5 74                    lda     dirofs,x
 9604  F953EF  B4 76                    ldy     dirbnk,x
 9605  F953F1  84 8F                    sty     bmpnt+2 
 9606  F953F3  18                       clc
 9607  F953F4  69 28                    adc     #numsec         ; buffer allocated after dir. cache
 9608  F953F6  1A                       inc     a               ; +1
 9609  F953F7  A8                       tay
 9610  F953F8  A5 08                    lda     track
 9611  F953FA  C9 29                    cmp     #41             ; which bam ?
 9612  F953FC  90 03                    bcc     ?42             ; bam1
 9613  F953FE  E9 28                    sbc     #40             ; range 40 trk per bam
 9614  F95400  C8                       iny                     ; it's bam2
 9615  F95401  84 8E            ?42:    sty     bmpnt+1
 9616  F95403  0A                       asl     a               ; trk x6 offset
 9617  F95404  85 8D                    sta     bmpnt           ; save x2
 9618  F95406  0A                       asl     a               ; x4
 9619  F95407  18                       clc                     ; total=x6
 9620  F95408  65 8D                    adc     bmpnt           ;
 9621  F9540A  69 0A                    adc     #bindx-6        ; bam offset -1 trk blk
 9622  F9540C  85 8D                    sta     bmpnt
 9623  F9540E  60                       rts
 9624                           
 9625  F9540F  0D 74 6F 74 61   ?50:    .DB     $0D, 'total computed free block''s:     % 4hu.', 0
               6C 20 63 6F 6D 
               70 75 74 65 64 
               20 66 72 65 65 
               20 62 6C 6F 63 
               6B 27 73 3A 20 
               20 20 20 20 25 
               20 34 68 75 2E 
               00 
 9626  F95438  0D 74 6F 74 61   ?55:    .DB     $0D, 'total free block''s from new BAM: % 4hu.', 0
               6C 20 66 72 65 
               65 20 62 6C 6F 
               63 6B 27 73 20 
               66 72 6F 6D 20 
               6E 65 77 20 42 
               41 4D 3A 20 25 
               20 34 68 75 2E 
               00 
 9627  F95461  0D 74 6F 74 61   ?60:    .DB     $0D, 'total free block''s from old BAM: % 4hu.', 0
               6C 20 66 72 65 
               65 20 62 6C 6F 
  Tue Jul 17 11:00:19 2018                                                                                               Page  128




               63 6B 27 73 20 
               66 72 6F 6D 20 
               6F 6C 64 20 42 
               41 4D 3A 20 25 
               20 34 68 75 2E 
               00 
 9628  F9548A  0D 6E 65 77 20   ?65:    .DB     $0D, 'new BAM free block''s unmatch: %hu vs. %hu.', 0
               42 41 4D 20 66 
               72 65 65 20 62 
               6C 6F 63 6B 27 
               73 20 75 6E 6D 
               61 74 63 68 3A 
               20 25 68 75 20 
               76 73 2E 20 25 
               68 75 2E 00 
 9629  F954B6  0D 42 41 4D 20   ?70:    .DB     $0D, 'BAM on disk cannot be updated.', 0
               6F 6E 20 64 69 
               73 6B 20 63 61 
               6E 6E 6F 74 20 
               62 65 20 75 70 
               64 61 74 65 64 
               2E 00 
 9630  F954D6  0D 63 6F 6D 70   ?75:    .DB     $0D, 'computed free block''s (%hu) unmatch new BAM count (%hu).', 0
               75 74 65 64 20 
               66 72 65 65 20 
               62 6C 6F 63 6B 
               27 73 20 28 25 
               68 75 29 20 75 
               6E 6D 61 74 63 
               68 20 6E 65 77 
               20 42 41 4D 20 
               63 6F 75 6E 74 
               20 28 25 68 75 
               29 2E 00 
 9631  F95510  0D 66 69 6C 65   ?80:    .DB     $0D, 'file system is clean.', 0
               20 73 79 73 74 
               65 6D 20 69 73 
               20 63 6C 65 61 
               6E 2E 00 
 9632  F95527  0D 75 70 64 61   ?85:    .DB     $0D, 'update BAM on disk...', 0
               74 65 20 42 41 
               4D 20 6F 6E 20 
               64 69 73 6B 2E 
               2E 2E 00 
 9633                           
 9634                           ;---------------------------------------------------------------------------
 9635                           ; drive's initialitation
 9636                           ;---------------------------------------------------------------------------
 9637                           
 9638                           ; check directory header
 9639                           ; X = drive #
 9640                           ; return CF = 0 if ok, otherwise CF = 1
 9641  F9553E                   hdrtst:
 9642  F9553E  20 3D 56                 jsr     sethdp          ; set dir pointer
 9643  F95541  A7 0A                    lda     [dirp]          ; track link
 9644  F95543  C9 28                    cmp     #dirtrk
 9645  F95545  D0 6D                    bne     ?02             ; error
  Tue Jul 17 11:00:19 2018                                                                                               Page  129




 9646  F95547  A0 01                    ldy     #1
 9647  F95549  B7 0A                    lda     [dirp],y        ; sec link
 9648  F9554B  C9 03                    cmp     #dirst
 9649  F9554D  D0 65                    bne     ?02             ; error
 9650  F9554F  C8                       iny
 9651  F95550  B7 0A                    lda     [dirp],y        ; disk version number
 9652  F95552  C9 44                    cmp     #dskvern
 9653  F95554  D0 5E                    bne     ?02             ; error
 9654  F95556  A0 1A                    ldy     #26
 9655  F95558  D7 0A                    cmp     [dirp],y        ; compare with vernum at offset 26
 9656  F9555A  D0 58                    bne     ?02             ; error
 9657  F9555C  88                       dey                     ; offset 25
 9658  F9555D  B7 0A                    lda     [dirp],y        ; dos version number
 9659  F9555F  C9 33                    cmp     #dosvern
 9660  F95561  D0 51                    bne     ?02             ; error
 9661  F95563  A0 16                    ldy     #22
 9662  F95565  B7 0A                    lda     [dirp],y        ; disk ID 1
 9663  F95567  9D FC E1                 sta     !dskid1,x
 9664  F9556A  C8                       iny
 9665  F9556B  B7 0A                    lda     [dirp],y        ; disk ID 2
 9666  F9556D  9D FE E1                 sta     !dskid2,x
 9667  F95570  A9 F7                    lda     #$F7
 9668  F95572  35 68                    and     drvfg,x         ; clear bit 3 (assume no new version)
 9669  F95574  95 68                    sta     drvfg,x
 9670  F95576  A0 1E                    ldy     #30
 9671  F95578  B7 0A                    lda     [dirp],y        ; disk sub-version
 9672  F9557A  F0 28                    beq     ?01             ; standard version
 9673  F9557C  C9 8D                    cmp     #subvern
 9674  F9557E  D0 24                    bne     ?01
 9675  F95580  49 FF                    eor     #$FF            ; compliment
 9676  F95582  C8                       iny                     ; offset 31
 9677  F95583  D7 0A                    cmp     [dirp],y        ; compare with sub-ver at ofs. 30
 9678  F95585  D0 1D                    bne     ?01             ; standard version
 9679  F95587  A9 08                    lda     #$08            ; set bit 3: new version
 9680  F95589  15 68                    ora     drvfg,x
 9681  F9558B  95 68                    sta     drvfg,x
 9682  F9558D  C8                       iny                     ; offset 32: serial 32 bit
 9683  F9558E  8A                       txa
 9684  F9558F  0A                       asl     a               ; * 4 - index double word
 9685  F95590  0A                       asl     a
 9686  F95591  AA                       tax
 9687  F95592                           ACC16
 9688  F95592  C2 20                    rep     #PMFLAG
 9689                                   .LONGA  on
 9690                                   .MNLIST
 9691  F95594  B7 0A                    lda     [dirp],y        ; store serial
 9692  F95596  9D F0 E1                 sta     !dskser,x
 9693  F95599  C8                       iny
 9694  F9559A  C8                       iny
 9695  F9559B  B7 0A                    lda     [dirp],y        
 9696  F9559D  9D F2 E1                 sta     !dskser+2,x
 9697  F955A0                           ACC08
 9698  F955A0  E2 20                    sep     #PMFLAG
 9699                                   .LONGA  off
 9700                                   .MNLIST
 9701  F955A2  A6 19                    ldx     drvnum
 9702  F955A4  E6 0B            ?01:    inc     dirp+1          ; set ptr to bam1
  Tue Jul 17 11:00:19 2018                                                                                               Page  130




 9703  F955A6  A7 0A                    lda     [dirp]          ; track link
 9704  F955A8  C9 28                    cmp     #dirtrk
 9705  F955AA  D0 08                    bne     ?02             ; error
 9706  F955AC  A0 01                    ldy     #1
 9707  F955AE  B7 0A                    lda     [dirp],y        ; sec link
 9708  F955B0  C9 02                    cmp     #dirst-1        ; will be 1 below of dir start
 9709  F955B2  F0 02                    beq     ?04             ; ok
 9710  F955B4  38               ?02:    sec                     ; return disk id mismatch error
 9711  F955B5  60               ?03:    rts
 9712  F955B6  20 1A 56         ?04:    jsr     chkbam          ; check bam 1 header
 9713  F955B9  B0 FA                    bcs     ?03             ; error
 9714  F955BB  B7 0A                    lda     [dirp],y        ; bam 1 iobyte
 9715  F955BD  10 06                    bpl     ?06
 9716  F955BF  A9 20                    lda     #$20            ; set bit 5 drive flag
 9717  F955C1  15 68                    ora     drvfg,x
 9718  F955C3  95 68                    sta     drvfg,x
 9719  F955C5  E6 0B            ?06:    inc     dirp+1          ; set ptr to bam2
 9720  F955C7  A7 0A                    lda     [dirp]          ; track link
 9721  F955C9  D0 E9                    bne     ?02             ; error, will be 0
 9722  F955CB  A0 01                    ldy     #1
 9723  F955CD  B7 0A                    lda     [dirp],y        ; sec link
 9724  F955CF  C9 FF                    cmp     #$FF
 9725  F955D1  D0 E1                    bne     ?02             ; error, will be $FF
 9726  F955D3  20 1A 56                 jsr     chkbam          ; check bam 2 header
 9727  F955D6  B0 DD                    bcs     ?03             ; error
 9728  F955D8  B7 0A                    lda     [dirp],y        ; bam 1 iobyte
 9729  F955DA  10 06                    bpl     nfcalc
 9730  F955DC  A9 20                    lda     #$20            ; set bit 5 drive flag
 9731  F955DE  34 68                    bit     drvfg,x
 9732  F955E0  F0 D2                    beq     ?02             ; mismatch with bam 1
 9733                           
 9734                           ; calc # of disk blocks free
 9735  F955E2                   nfcalc:
 9736  F955E2  A5 08                    lda     track
 9737  F955E4  48                       pha
 9738  F955E5  A5 19                    lda     drvnum
 9739  F955E7  0A                       asl     a
 9740  F955E8  AA                       tax                     ; index
 9741  F955E9  74 6A                    stz     ndbf,x
 9742  F955EB  74 6B                    stz     ndbf+1,x
 9743  F955ED  86 93                    stx     tmp0            ; save index
 9744  F955EF  A0 01                    ldy     #startrk
 9745  F955F1  88                       dey
 9746  F955F2  C8               ?02:    iny
 9747  F955F3  84 08                    sty     track
 9748  F955F5  C0 28                    cpy     #dirtrk
 9749  F955F7  F0 F9                    beq     ?02             ; skip dir track
 9750  F955F9  C0 51                    cpy     #maxtrk         ; done ?
 9751  F955FB  B0 16                    bcs     ?04             ; yes
 9752  F955FD  20 5D 4E                 jsr     bamtrk          ; set up next bam trk
 9753  F95600  A4 08                    ldy     track           ; retrivie track
 9754  F95602  A9 00                    lda     #0
 9755  F95604  EB                       xba                     ; B = 0
 9756  F95605  A7 8D                    lda     [bmpnt]         ; A = get blks free
 9757  F95607  A6 93                    ldx     tmp0            ; retrivie index
 9758  F95609                           ACC16CLC
 9759  F95609  C2 21                    rep     #(PMFLAG.OR.PCFLAG)
  Tue Jul 17 11:00:19 2018                                                                                               Page  131




 9760                                   .LONGA  on
 9761                                   .MNLIST
 9762  F9560B  75 6A                    adc     ndbf,x          ; up data count
 9763  F9560D  95 6A                    sta     ndbf,x
 9764  F9560F                           ACC08
 9765  F9560F  E2 20                    sep     #PMFLAG
 9766                                   .LONGA  off
 9767                                   .MNLIST
 9768  F95611  80 DF                    bra     ?02
 9769  F95613  18               ?04:    clc
 9770  F95614  68                       pla
 9771  F95615  85 08                    sta     track
 9772  F95617  A6 19                    ldx     drvnum
 9773  F95619  60                       rts                     ; return with carry = 0
 9774                           
 9775                           ; check bam header
 9776                           ; Y = 1 when called
 9777  F9561A                   chkbam:
 9778  F9561A  C8                       iny
 9779  F9561B  B7 0A                    lda     [dirp],y        ; bam disk version number
 9780  F9561D  C9 44                    cmp     #dskvern
 9781  F9561F  D0 07                    bne     ?02             ; error
 9782  F95621  C8                       iny                     ; offset 3
 9783  F95622  49 FF                    eor     #$FF            ; complement
 9784  F95624  D7 0A                    cmp     [dirp],y        ; bam1 compl. disk version number
 9785  F95626  F0 02                    beq     ?04
 9786  F95628  38               ?02:    sec                     ; return disk id mismatch error
 9787  F95629  60                       rts
 9788  F9562A  C8               ?04:    iny                     ; offset 4
 9789  F9562B  B7 0A                    lda     [dirp],y        ; bam disk id 1
 9790  F9562D  DD FC E1                 cmp     !dskid1,x
 9791  F95630  D0 F6                    bne     ?02
 9792  F95632  C8                       iny                     ; offset 5
 9793  F95633  B7 0A                    lda     [dirp],y        ; bam disk id 2
 9794  F95635  DD FE E1                 cmp     !dskid2,x
 9795  F95638  D0 EE                    bne     ?02
 9796  F9563A  C8                       iny
 9797  F9563B  18                       clc                     ; ok
 9798  F9563C  60                       rts
 9799  F9563D                           
 9800                           ; set pointer to directory header
 9801                           ; return with X = drive
 9802  F9563D                   sethdp:
 9803  F9563D  A6 19                    ldx     drvnum
 9804  F9563F  B5 74                    lda     dirofs,x
 9805  F95641  B4 76                    ldy     dirbnk,x
 9806  F95643  64 0A                    stz     dirp            ; set pointer to system track cache
 9807  F95645  85 0B                    sta     dirp+1
 9808  F95647  84 0C                    sty     dirp+2
 9809  F95649  60                       rts
 9810                           
 9811                           ; set pointer to track cache & sector
 9812                           ; return with X = drive
 9813  F9564A                   setcp:
 9814  F9564A  A6 19                    ldx     drvnum
 9815  F9564C  B5 78                    lda     trkofs,x
 9816  F9564E  B4 7A                    ldy     trkbnk,x
  Tue Jul 17 11:00:19 2018                                                                                               Page  132




 9817  F95650  64 8A                    stz     bufp            ; set pointer to track cache
 9818  F95652  18                       clc
 9819  F95653  65 09                    adc     sector
 9820  F95655  85 8B                    sta     bufp+1
 9821  F95657  84 8C                    sty     bufp+2
 9822  F95659  60                       rts
 9823                           
 9824                           ; set pointer to write cache & sector
 9825                           ; return with X = drive
 9826  F9565A                   setwb:
 9827  F9565A  A6 19                    ldx     drvnum
 9828  F9565C  B5 7C                    lda     wrtofs,x
 9829  F9565E  B4 7E                    ldy     wrtbnk,x
 9830  F95660  64 90                    stz     wbuf            ; set pointer to write cache
 9831  F95662  18                       clc
 9832  F95663  65 09                    adc     sector
 9833  F95665  85 91                    sta     wbuf+1
 9834  F95667  84 92                    sty     wbuf+2
 9835  F95669  60                       rts
 9836                           
 9837                           ; drive initialitation
 9838                           ; check if drive is ready or if disk was changed
 9839                           ; get low level disk format
 9840                           ; read system track (logical track 40) and put in cache
 9841                           ; fill drvfg flag for the given drive
 9842  F9566A                   drvint:
 9843  F9566A  20 9C 56                 jsr     fmttst          ; check low level disk format...
 9844  F9566D  B5 68                    lda     drvfg,x         ; ...if drive is ready
 9845  F9566F  30 2A                    bmi     ?10             ; system track already in cache
 9846  F95671  4A                       lsr     a               ; if <0> = 0 => ibm disk
 9847  F95672  90 08                    bcc     ?02
 9848  F95674  4A                       lsr     a               ; if <1> = 0 => DD cbm disk
 9849  F95675  90 0A                    bcc     ?04
 9850  F95677  A9 15                    lda     #badfmt         ; unsupported HD cbm format
 9851  F95679  4C F5 56                 jmp     drverr
 9852  F9567C  A9 4E            ?02:    lda     #ibmfmt         ; is ibm format
 9853  F9567E  4C F5 56                 jmp     drverr
 9854  F95681  20 8F 57         ?04:    jsr     sysrd           ; read system track into cache  
 9855  F95684  B0 09                    bcs     ?06             ; error reading system track
 9856  F95686  20 3E 55                 jsr     hdrtst          ; check directory header
 9857  F95689  90 08                    bcc     ?08             ; ok
 9858  F9568B  A9 1D                    lda     #badid          ; mismatch header
 9859  F9568D  80 66                    bra     drverr
 9860  F9568F  A9 4F            ?06:    lda     #syterr
 9861  F95691  80 62                    bra     drverr
 9862  F95693  A6 19            ?08:    ldx     drvnum          ; set good flag for drive
 9863  F95695  A9 80                    lda     #$80
 9864  F95697  15 68                    ora     drvfg,x
 9865  F95699  95 68                    sta     drvfg,x
 9866  F9569B  60               ?10:    rts
 9867                           
 9868                           ; test if disk is low-level formatted
 9869                           ; report format in drvfg
 9870                           ; return with X = drive
 9871  F9569C                   fmttst:
 9872  F9569C  20 B4 56                 jsr     dsktst          ; check if disk inside drive
 9873  F9569F  34 68                    bit     drvfg,x         ; check if already tested
  Tue Jul 17 11:00:19 2018                                                                                               Page  133




 9874  F956A1  70 10                    bvs     ?04             ; yes, format already recognized
 9875  F956A3                           FDCGETFMT               ; query disk format
 9876  F956A3  02 30                    cop     $30
 9877  F956A5  04                       .DB     $04
 9878                                   .MNLIST
 9879  F956A6  90 04                    bcc     ?02             ; ok, recognized format
 9880  F956A8  A9 15                    lda     #badfmt
 9881  F956AA  80 49                    bra     drverr
 9882  F956AC  98               ?02:    tya                     ; format in bit 1,0
 9883  F956AD  09 40                    ora     #$40
 9884  F956AF  15 68                    ora     drvfg,x
 9885  F956B1  95 68                    sta     drvfg,x
 9886  F956B3  60               ?04:    rts
 9887                           
 9888                           ; check if disk is inserted on a drive
 9889                           ; return with X = drive
 9890  F956B4                   dsktst:
 9891  F956B4  A6 19                    ldx     drvnum          ; drive 0 or 1
 9892  F956B6                           FDCTST                  ; check if disk inserted
 9893  F956B6  02 30                    cop     $30
 9894  F956B8  03                       .DB     $03
 9895                                   .MNLIST
 9896  F956B9  B0 06                    bcs     ?02             ; check if disk was changed
 9897  F956BB  34 68                    bit     drvfg,x         ; check if disk was inside drive at boot time
 9898  F956BD  30 2D                    bmi     ?08             ; no, already init so exit
 9899  F956BF  10 0E                    bpl     ?07             ; invalidate all cached data
 9900  F956C1  C0 11            ?02:    cpy     #FDC_CHANGE     ; check error code
 9901  F956C3  F0 05                    beq     ?06             ; disk changed
 9902  F956C5  A9 4A            ?04:    lda     #nodriv         ; abort: no disk
 9903  F956C7  4C 07 41                 jmp     cmderr
 9904  F956CA                   ?06:    FDCTST                  ; check again
 9905  F956CA  02 30                    cop     $30
 9906  F956CC  03                       .DB     $03
 9907                                   .MNLIST
 9908  F956CD  B0 F6                    bcs     ?04             ; fatal error
 9909  F956CF  74 68            ?07:    stz     drvfg,x         ; invalidate drive flags bcs disk changed
 9910  F956D1  74 84                    stz     wbam,x
 9911  F956D3  74 04                    stz     dirsec,x
 9912  F956D5  74 06                    stz     index,x
 9913  F956D7  74 02                    stz     delind,x
 9914  F956D9  74 00                    stz     delsec,x
 9915  F956DB  74 80                    stz     tcache,x
 9916  F956DD  74 82                    stz     wcache,x        
 9917  F956DF                           FDCGETST                ; get status drive
 9918  F956DF  02 30                    cop     $30
 9919  F956E1  02                       .DB     $02
 9920                                   .MNLIST
 9921  F956E2  B0 E1                    bcs     ?04
 9922  F956E4  98                       tya
 9923  F956E5  0A                       asl     a               ; test bit 6
 9924  F956E6  10 04                    bpl     ?08
 9925  F956E8  A9 10                    lda     #$10
 9926  F956EA  95 68                    sta     drvfg,x
 9927  F956EC  60               ?08:    rts
 9928                           
 9929                           ;---------------------------------------------------------------------------
 9930                           ; error procedure's
  Tue Jul 17 11:00:19 2018                                                                                               Page  134




 9931                           ;---------------------------------------------------------------------------
 9932                           
 9933                           ; main error procedure
 9934                           ; in:   A = error code
 9935                           ;       track & sector
 9936                           ;               t & s = 0 for command error
 9937                           ;               t = drvnum for drive error level
 9938                           ;               t = chnl for channel error level
 9939                           ; abort any procedure and return to caller with error code
 9940                           
 9941  F956ED                   chnerr:
 9942  F956ED  A6 52                    ldx     chnl
 9943  F956EF  86 08                    stx     track
 9944  F956F1  64 09                    stz     sector
 9945  F956F3  80 06                    bra     doserr
 9946                           
 9947  F956F5                   drverr:
 9948  F956F5  A6 19                    ldx     drvnum          ; track = drive #
 9949  F956F7  86 08                    stx     track
 9950  F956F9  64 09                    stz     sector
 9951                           
 9952  F956FB                   doserr:
 9953  F956FB  85 56                    sta     lsterr          ; last error
 9954  F956FD  A6 08                    ldx     track           ; save track & sector for later use
 9955  F956FF  8E FA E1                 stx     etrk
 9956  F95702  A6 09                    ldx     sector
 9957  F95704  8E FB E1                 stx     esec
 9958  F95707  24 F8                    bit     trap            ; set flag while open functiom
 9959  F95709  10 05                    bpl     ?10
 9960  F9570B  20 F0 47                 jsr     frefd           ; free fd
 9961  F9570E  64 F8                    stz     trap
 9962  F95710                   ?10:    INDEX16
 9963  F95710  C2 10                    rep     #PXFLAG
 9964                                   .LONGI  on
 9965                                   .MNLIST
 9966  F95712  AE F8 E1                 ldx     tos
 9967  F95715  9A                       txs                     ; recover stack pointer
 9968  F95716                           INDEX08
 9969  F95716  E2 10                    sep     #PXFLAG
 9970                                   .LONGI  off
 9971                                   .MNLIST
 9972  F95718  38                       sec                     ; error code in accum.
 9973  F95719  60                       rts
 9974                           
 9975                           ; format error message -- called reading channel 15
 9976  F9571A                   fmterr:
 9977  F9571A  20 44 57                 jsr     fnderr          ; find error string
 9978  F9571D  AE FB E1                 ldx     esec            ; push params for _bsprintf
 9979  F95720  DA                       phx                     ; sector (1b)
 9980  F95721  AE FA E1                 ldx     etrk
 9981  F95724  DA                       phx                     ; track (1b)
 9982  F95725  4B                       phk                     ; error string bank (1b)
 9983  F95726  D4 3E                    pei     (tlp)           ; error string ptr (2b)
 9984  F95728  A5 56                    lda     lsterr  
 9985  F9572A  48                       pha                     ; error code (1b)
 9986  F9572B  F4 60 00                 pea     #cmdlen         ; size of dest. string (2b)
 9987  F9572E  A9 00                    lda     #^cmdbuf        ; dest string bank (1b)
  Tue Jul 17 11:00:19 2018                                                                                               Page  135




 9988  F95730  48                       pha
 9989  F95731  F4 00 E1                 pea     #cmdbuf         ; dest string pointer (2b)
 9990  F95734  4B                       phk                     ; fmt string bank (1b)
 9991  F95735  F4 FC 5A                 pea     #erfmt          ; fmt string pointer (2b)
 9992  F95738  A9 0F                    lda     #15
 9993  F9573A  48                       pha                     ; # params bytes (1b)
 9994  F9573B                           BSPRINTF
 9995  F9573B  02 12                    cop     $12
 9996                                   .MNLIST
 9997  F9573D                           ACC16
 9998  F9573D  C2 20                    rep     #PMFLAG
 9999                                   .LONGA  on
10000                                   .MNLIST
10001  F9573F  85 88                    sta     btrf            ; save count of bytes
10002  F95741                           ACC08
10003  F95741  E2 20                    sep     #PMFLAG
10004                                   .LONGA  off
10005                                   .MNLIST
10006  F95743  60                       rts
10007                           
10008                           ; find basic error string
10009  F95744                   fnderr:
10010  F95744  A5 56                    lda     lsterr
10011  F95746  F0 04                    beq     ?00
10012  F95748  C9 49                    cmp     #cbmv2
10013  F9574A  D0 06                    bne     ?01
10014  F9574C  9C FA E1         ?00:    stz     etrk
10015  F9574F  9C FB E1                 stz     esec
10016  F95752  A9 11            ?01:    lda     #<ertbl
10017  F95754  85 3E                    sta     tlp
10018  F95756  A9 5B                    lda     #>ertbl
10019  F95758  85 3F                    sta     tlp+1
10020  F9575A  A9 F9                    lda     #^ertbl
10021  F9575C  85 40                    sta     tlp+2
10022  F9575E  A7 3E            ?02:    lda     [tlp]           ; check error code
10023  F95760  C5 56                    cmp     lsterr
10024  F95762  F0 24                    beq     ?10             ; match
10025  F95764  A0 01                    ldy     #1
10026  F95766  B7 3E            ?04:    lda     [tlp],y
10027  F95768  F0 03                    beq     ?06             ; end of string
10028  F9576A  C8                       iny
10029  F9576B  80 F9                    bra     ?04             ; find end of string
10030  F9576D  C8               ?06:    iny
10031  F9576E  B7 3E                    lda     [tlp],y
10032  F95770  F0 0C                    beq     ?08             ; end of table -- string not found
10033  F95772  18                       clc
10034  F95773  98                       tya
10035  F95774  65 3E                    adc     tlp
10036  F95776  85 3E                    sta     tlp
10037  F95778  90 E4                    bcc     ?02             ; next string
10038  F9577A  E6 3F                    inc     tlp+1
10039  F9577C  80 E0                    bra     ?02
10040  F9577E  A9 B1            ?08:    lda     #<uerr          ; unknow error
10041  F95780  85 3E                    sta     tlp
10042  F95782  A9 5E                    lda     #>uerr
10043  F95784  85 3F                    sta     tlp+1
10044  F95786  80 06                    bra     ?12
  Tue Jul 17 11:00:19 2018                                                                                               Page  136




10045  F95788  E6 3E            ?10:    inc     tlp             ; found string
10046  F9578A  D0 02                    bne     ?12
10047  F9578C  E6 3F                    inc     tlp+1
10048  F9578E  60               ?12:    rts
10049                           
10050                           ;---------------------------------------------------------------------------
10051                           ; phisycal access to disk
10052                           ;---------------------------------------------------------------------------
10053  F9578F                           
10054                           ; read system track
10055                           ; return CF=1 if error
10056                           ; X=drive #
10057  F9578F                   sysrd:
10058  F9578F  86 F2                    stx     pdrv    
10059  F95791  A9 05                    lda     #5              ; try to read system track
10060  F95793  85 93                    sta     tmp0            ; set pass count
10061  F95795  DA               ?02:    phx                     ; drive #
10062  F95796  A9 27                    lda     #dirtrk-1       ; physical system track
10063  F95798  48                       pha
10064  F95799  B5 6E                    lda     sysbuf,x        ; dma buffer #
10065  F9579B  48                       pha
10066  F9579C  A9 01                    lda     #1              ; cbm format
10067  F9579E  48                       pha
10068  F9579F                           FDCTKRD                 ; read whole track
10069  F9579F  02 35                    cop     $35
10070  F957A1  00                       .DB     $00
10071                                   .MNLIST
10072  F957A2  A6 F2                    ldx     pdrv
10073  F957A4  90 04                    bcc     ?04
10074  F957A6  C6 93                    dec     tmp0
10075  F957A8  D0 EB                    bne     ?02             ; try again
10076  F957AA  60               ?04:    rts
10077                           
10078                           ; read whole track into drive read cache, if not already in cache
10079  F957AB                   tread:
10080  F957AB  A6 19                    ldx     drvnum
10081  F957AD  B5 80                    lda     tcache,x        ; invalid cache?
10082  F957AF  F0 06                    beq     ?02             ; yes so read track
10083  F957B1  C5 08                    cmp     track           ; already in cache?
10084  F957B3  F0 0B                    beq     ?04             ; yes
10085  F957B5  74 80                    stz     tcache,x        ; invalidate cache
10086  F957B7  B5 70            ?02:    lda     trkbuf,x        ; dma buffer #
10087  F957B9  20 63 58                 jsr     readtk
10088                                   ;ldx    drvnum
10089  F957BC  A5 08                    lda     track
10090  F957BE  95 80                    sta     tcache,x        ; validate cache
10091  F957C0  60               ?04:    rts
10092                           
10093                           ; read whole track into drive write cache, if not already in cache
10094  F957C1                   wread:
10095  F957C1  A6 19                    ldx     drvnum
10096  F957C3  B5 82                    lda     wcache,x        ; invalid cache?
10097  F957C5  F0 06                    beq     ?02             ; yes so read track
10098  F957C7  C5 08                    cmp     track           ; already in cache?
10099  F957C9  F0 0B                    beq     ?04             ; yes
10100  F957CB  74 82                    stz     wcache,x        ; invalidate cache
10101  F957CD  B5 72            ?02:    lda     wrtbuf,x        ; dma buffer #
  Tue Jul 17 11:00:19 2018                                                                                               Page  137




10102  F957CF  20 63 58                 jsr     readtk
10103                                   ;ldx    drvnum
10104  F957D2  A5 08                    lda     track
10105  F957D4  95 82                    sta     wcache,x        ; validate cache
10106  F957D6  60               ?04:    rts
10107                           
10108                           ; write out the system track
10109  F957D7                   syswr:
10110  F957D7  A0 28                    ldy     #dirtrk
10111  F957D9  84 08                    sty     track
10112  F957DB  A6 19                    ldx     drvnum
10113  F957DD  B5 6E                    lda     sysbuf,x        ; dma buffer #
10114                           
10115                           ; write out a whole track from dma buffer
10116                           ; in:   A=dma buffer#
10117                           ;       X=drive #
10118                           ;       track=logical track
10119  F957DF                   writetk:
10120  F957DF  85 F6                    sta     pbuf            ; dma buffer #
10121  F957E1  86 F2                    stx     pdrv
10122  F957E3  A9 05                    lda     #5              ; write out whole track
10123  F957E5  85 93                    sta     tmp0            ; set pass count
10124  F957E7  DA               ?02:    phx                     ; drive #
10125  F957E8  A5 08                    lda     track
10126  F957EA  3A                       dec     a               ; phisycal track
10127  F957EB  48                       pha
10128  F957EC  A5 F6                    lda     pbuf
10129  F957EE  48                       pha                     ; dma buffer #
10130  F957EF  A9 81                    lda     #$81
10131  F957F1  48                       pha                     ; cbm format
10132  F957F2                           FDCTKWR
10133  F957F2  02 35                    cop     $35
10134  F957F4  02                       .DB     $02
10135                                   .MNLIST
10136  F957F5  A6 F2                    ldx     pdrv
10137  F957F7  90 69                    bcc     lsp             ; ok no error
10138  F957F9  C6 93                    dec     tmp0
10139  F957FB  D0 EA                    bne     ?02             ; try again
10140  F957FD  A9 16                    lda     #wrtrk
10141  F957FF  4C FB 56                 jmp     doserr
10142                           
10143                           ; update on disk bam of current drive
10144                           ; write out logical sector 1 & 2 (phisycal sec 1 & 2)
10145  F95802                   bamout:
10146  F95802  A9 02                    lda     #2
10147  F95804  85 F5                    sta     pcnt            ; number of sector's to write out
10148  F95806  A6 19                    ldx     drvnum          ; X = drive #
10149  F95808  B5 6E                    lda     sysbuf,x        ; dma buffer #
10150  F9580A  EB                       xba                     ; B = dma buffer #
10151  F9580B  A9 01                    lda     #1              ; A = first phisycal sector to write
10152  F9580D  A0 00                    ldy     #0              ; Y = side 0
10153  F9580F  80 05                    bra     wrsys2
10154                           
10155                           ; write given directory sector on disk
10156                           ; A = number of sec. to write out
10157  F95811                   wrsys:
10158  F95811  85 F5                    sta     pcnt            ; number of sector's to write out
  Tue Jul 17 11:00:19 2018                                                                                               Page  138




10159  F95813  20 4D 58                 jsr     lsec2p          ; convert logical sec to phis. sec & side
10160                           
10161                           ; X=drive #
10162                           ; Y=side
10163                           ; A=start phisycal sec
10164                           ; B=dma buffer #
10165                           ; tpcnt=count #
10166  F95816                   wrsys2:
10167  F95816  85 F4                    sta     psec            ; first phisycal sector
10168  F95818  EB                       xba
10169  F95819  85 F6                    sta     pbuf            ; dma buffer #
10170  F9581B  86 F2                    stx     pdrv
10171  F9581D  84 F3                    sty     pside
10172  F9581F  A9 28                    lda     #dirtrk
10173  F95821  85 08                    sta     track
10174  F95823                           
10175                                   ; prepare stack params for call system function:
10176                                   ; FDCWRITE(bDrive, bTrk, bHead, bSect, bNum, bBuf, bFlag)
10177  F95823  A9 05                    lda     #5
10178  F95825  85 93                    sta     tmp0            ; set pass count
10179  F95827  DA               ?02:    phx                     ; drive #
10180  F95828  A5 08                    lda     track
10181  F9582A  3A                       dec     a               ; phisycal track
10182  F9582B  48                       pha
10183  F9582C  A5 F3                    lda     pside
10184  F9582E  48                       pha                     ; side (head)
10185  F9582F  A5 F4                    lda     psec
10186  F95831  48                       pha                     ; phisycal sector
10187  F95832  A5 F5                    lda     pcnt
10188  F95834  48                       pha                     ; sector's count to write out
10189  F95835  A5 F6                    lda     pbuf
10190  F95837  48                       pha                     ; dma buffer
10191  F95838  A9 81                    lda     #$81            ; A = 1
10192  F9583A  48                       pha                     ; flag (cbm format, verify)
10193  F9583B                           FDCWRITE
10194  F9583B  02 31                    cop     $31
10195  F9583D  02                       .DB     $02
10196                                   .MNLIST
10197  F9583E  A6 F2                    ldx     pdrv
10198  F95840  90 20                    bcc     lsp
10199  F95842  C6 93                    dec     tmp0
10200  F95844  D0 E1                    bne     ?02             ; try again
10201  F95846  74 68                    stz     drvfg,x         ; ...invalidate drive #
10202  F95848  A9 19                    lda     #wrsec          ; write error
10203  F9584A  4C FB 56                 jmp     doserr
10204  F9584D                           
10205                           ; translate logical sector into phisycal sector & side
10206                           ; in:   sector = logical sector
10207                           ; out:  X = drive #
10208                           ;       A = sector #
10209                           ;       Y = side #
10210                           ;       B = dma buffer #
10211  F9584D                   lsec2p:
10212  F9584D  A6 19                    ldx     drvnum
10213  F9584F  A5 09                    lda     sector          ; 0..39
10214  F95851  4A                       lsr     a               ; 0..19
10215  F95852  A8                       tay                     ; save
  Tue Jul 17 11:00:19 2018                                                                                               Page  139




10216  F95853  18                       clc                     ; add base dma buffer
10217  F95854  75 6E                    adc     sysbuf,x                
10218  F95856  EB                       xba                     ; B = dma buffer # that contain phis. sec.
10219  F95857  98                       tya
10220  F95858  A0 00                    ldy     #0              ; side 0
10221  F9585A  C9 0A                    cmp     #phisec         ; 0..9 -> side 0, 10..19 -> side 1
10222  F9585C  90 03                    bcc     ?02
10223  F9585E  E9 0A                    sbc     #phisec
10224  F95860  C8                       iny                     ; side 1
10225  F95861  1A               ?02:    inc     a               ; A = phisycal sec
10226  F95862  60               lsp:    rts
10227                           
10228                           ; read a whole track into dma buffer
10229                           ; in:   A=dma buffer#
10230                           ;       X=drive #
10231                           ;       track=logical track
10232  F95863                   readtk:
10233  F95863  85 F6                    sta     pbuf            ; dma buffer #
10234  F95865  86 F2                    stx     pdrv
10235  F95867  A9 05                    lda     #5
10236  F95869  85 93                    sta     tmp0            ; set pass count
10237  F9586B  DA               ?02:    phx                     ; drive #
10238  F9586C  A5 08                    lda     track           ; physical track
10239  F9586E  3A                       dec     a
10240  F9586F  48                       pha
10241  F95870  A5 F6                    lda     pbuf            ; dma buffer #
10242  F95872  48                       pha
10243  F95873  A9 01                    lda     #1              ; cbm format
10244  F95875  48                       pha
10245  F95876                           FDCTKRD                 ; read whole track
10246  F95876  02 35                    cop     $35
10247  F95878  00                       .DB     $00
10248                                   .MNLIST
10249  F95879  A6 F2                    ldx     pdrv
10250  F9587B  90 E5                    bcc     lsp             ; ok, no error
10251  F9587D  C6 93                    dec     tmp0
10252  F9587F  D0 EA                    bne     ?02             ; try again
10253  F95881  A9 14                    lda     #rdtrk          ; error reading whole track
10254  F95883  4C FB 56                 jmp     doserr
10255                           
10256                           ; write out sector(s) from dma buffer
10257                           ; in:   X=drive
10258                           ;       Y=start phisycal sector
10259                           ;       A=sector's count #
10260                           ;       B=dma buffer #
10261                           ;       pside=side
10262                           ; use tmp0
10263  F95886                   writesec:
10264  F95886  85 F5                    sta     pcnt            ; count #
10265  F95888  EB                       xba
10266  F95889  85 F6                    sta     pbuf            ; dma buffer #
10267  F9588B  84 F4                    sty     psec
10268  F9588D  86 F2                    stx     pdrv
10269  F9588F  A9 05                    lda     #5              ; set pass count
10270  F95891  85 93                    sta     tmp0
10271  F95893  DA               ?02:    phx                     ; drive #
10272  F95894  A5 08                    lda     track
  Tue Jul 17 11:00:19 2018                                                                                               Page  140




10273  F95896  3A                       dec     a
10274  F95897  48                       pha                     ; phisycal track
10275  F95898  A5 F3                    lda     pside
10276  F9589A  48                       pha                     ; side
10277  F9589B  A5 F4                    lda     psec
10278  F9589D  48                       pha                     ; start phisycal sector
10279  F9589E  A5 F5                    lda     pcnt
10280  F958A0  48                       pha                     ; count #: how much sec's
10281  F958A1  A5 F6                    lda     pbuf
10282  F958A3  48                       pha                     ; dma buffer #
10283  F958A4  A9 81                    lda     #$81
10284  F958A6  48                       pha                     ; cbm format
10285  F958A7                           FDCWRITE
10286  F958A7  02 31                    cop     $31
10287  F958A9  02                       .DB     $02
10288                                   .MNLIST
10289  F958AA  A6 F2                    ldx     pdrv
10290  F958AC  90 B4                    bcc     lsp             ; ok no error
10291  F958AE  C6 93                    dec     tmp0
10292  F958B0  D0 E1                    bne     ?02             ; try again
10293  F958B2  A9 19                    lda     #wrsec
10294  F958B4  4C FB 56                 jmp     doserr
10295                           
10296                           ; read sector(s) into dma buffer
10297                           ; use tmp0
10298  F958B7                   readsec:
10299  F958B7  A9 05                    lda     #5              ; set pass count
10300  F958B9  85 93                    sta     tmp0
10301  F958BB  A5 F2            ?02:    lda     pdrv            ; drive #
10302  F958BD  48                       pha
10303  F958BE  A5 08                    lda     track
10304  F958C0  3A                       dec     a
10305  F958C1  48                       pha                     ; phisycal track
10306  F958C2  A5 F3                    lda     pside
10307  F958C4  48                       pha                     ; side
10308  F958C5  A5 F4                    lda     psec
10309  F958C7  48                       pha                     ; start phisycal sector
10310  F958C8  A5 F5                    lda     pcnt
10311  F958CA  48                       pha                     ; count #: how much sec's
10312  F958CB  A5 F6                    lda     pbuf
10313  F958CD  48                       pha                     ; dma buffer #
10314  F958CE  A9 01                    lda     #1
10315  F958D0  48                       pha                     ; cbm format
10316  F958D1                           FDCREAD
10317  F958D1  02 31                    cop     $31
10318  F958D3  00                       .DB     $00
10319                                   .MNLIST
10320  F958D4  A6 F2                    ldx     pdrv
10321  F958D6  90 8A                    bcc     lsp             ; ok no error
10322  F958D8  C6 93                    dec     tmp0
10323  F958DA  D0 DF                    bne     ?02             ; try again
10324  F958DC  A9 18                    lda     #rdsec
10325  F958DE  4C FB 56                 jmp     doserr
10326                           
10327                           ;---------------------------------------------------------------------------
10328                           ; low level format
10329                           ;---------------------------------------------------------------------------
  Tue Jul 17 11:00:19 2018                                                                                               Page  141




10330                           
10331  F958E1                   llfmt:
10332  F958E1  20 5F 59                 jsr     ?110
10333  F958E4  A5 19                    lda     drvnum
10334  F958E6  48                       pha                     ; drive #
10335  F958E7  A9 C1                    lda     #$C1
10336  F958E9  48                       pha                     ; flag (notify, verify, cbm fmt)
10337  F958EA  A9 00                    lda     #0
10338  F958EC  48                       pha                     ; fill byte
10339  F958ED  4B                       phk                     ; adress of callback
10340  F958EE  F4 03 59                 pea     #!?08
10341  F958F1                           FDCFORMAT
10342  F958F1  02 33                    cop     $33
10343                                   .MNLIST
10344  F958F3  90 0D                    bcc     ?06             ; ok
10345  F958F5  C0 0B                    cpy     #FDC_WP
10346  F958F7  D0 04                    bne     ?02
10347  F958F9  A9 1A                    lda     #wpon
10348  F958FB  80 02                    bra     ?04
10349  F958FD  A9 4D            ?02:    lda     #fmter
10350  F958FF  4C F5 56         ?04:    jmp     drverr
10351  F95902  60               ?06:    rts
10352                           
10353                           ; callback function while formatting
10354                           ; In    - A = drive
10355                           ;         X = head
10356                           ;         Y = track
10357                           ;         B = sector/track
10358                           ;         CF = 0 when called first time
10359  F95903                   ?08:
10360  F95903  0B                       phd                     ; save DP
10361  F95904  F4 00 7E                 pea     #CBMFSP0        ; set new DP
10362  F95907  2B                       pld
10363  F95908  DA                       phx     
10364  F95909  C8                       iny                     ; show track 1..80
10365  F9590A  5A                       phy
10366  F9590B  B0 07                    bcs     ?10
10367  F9590D                           SCNGETPOS               ; first time get position on screen
10368  F9590D  02 18                    cop     $18
10369  F9590F  02                       .DB     $02
10370                                   .MNLIST
10371  F95910  86 94                    stx     wtmp
10372  F95912  84 95                    sty     wtmp+1
10373                                   ;;SCN_CR
10374                                   ;;bra   ?20
10375  F95914  A6 94            ?10:    ldx     wtmp
10376  F95916  A4 95                    ldy     wtmp+1
10377  F95918                           SCNSETPOS
10378  F95918  02 18                    cop     $18
10379  F9591A  03                       .DB     $03
10380                                   .MNLIST
10381  F9591B                   ?20:                                    
10382                                                           ; X = head - param format in stack
10383                                                           ; Y = track - param format in stack
10384  F9591B  48                       pha                     ; A = drive #
10385  F9591C  4B                       phk                     ; bank of format str
10386  F9591D  F4 27 59                 pea     #!?100          ; address of format str
  Tue Jul 17 11:00:19 2018                                                                                               Page  142




10387  F95920  A9 07                    lda     #7              ; # params
10388  F95922  48                       pha
10389  F95923                           BPRINTF
10390  F95923  02 11                    cop     $11
10391                                   .MNLIST
10392  F95925  2B                       pld
10393  F95926  6B                       rtl
10394                           
10395  F95927  66 6F 72 6D 61   ?100:   .DB     'format diskette on drive #%bu (track #%02bu, side #%bu)', $00
               74 20 64 69 73 
               6B 65 74 74 65 
               20 6F 6E 20 64 
               72 69 76 65 20 
               23 25 62 75 20 
               28 74 72 61 63 
               6B 20 23 25 30 
               32 62 75 2C 20 
               73 69 64 65 20 
               23 25 62 75 29 
               00 
10396                           
10397                           ?110:   ; format msg
10398  F9595F  A5 19                    lda     drvnum
10399  F95961  48                       pha
10400  F95962  4B                       phk
10401  F95963  F4 75 59                 pea     #!?120
10402  F95966  A9 05                    lda     #5
10403  F95968  48                       pha
10404  F95969                           BPRINTF
10405  F95969  02 11                    cop     $11
10406                                   .MNLIST
10407  F9596B  A9 59                    lda     #>?130
10408  F9596D  EB                       xba
10409  F9596E  A9 AB                    lda     #<?130
10410  F95970  A2 F9                    ldx     #^?130
10411  F95972                           SCNSTROUT
10412  F95972  02 03                    cop     $03
10413                                   .MNLIST
10414  F95974  60                       rts
10415                           
10416  F95975  0D 46 6F 72 6D   ?120:   .DB     $0D, 'Format diskette on drive #%bu - cbm 1581 format type', 0
               61 74 20 64 69 
               73 6B 65 74 74 
               65 20 6F 6E 20 
               64 72 69 76 65 
               20 23 25 62 75 
               20 2D 20 63 62 
               6D 20 31 35 38 
               31 20 66 6F 72 
               6D 61 74 20 74 
               79 70 65 00 
10417  F959AB  0D 53 69 64 65   ?130:   .DB     $0D, 'Sides: 2, tracks: 80/side, sectors: 10/track, total: 1600', $0D, 0
               73 3A 20 32 2C 
               20 74 72 61 63 
               6B 73 3A 20 38 
               30 2F 73 69 64 
               65 2C 20 73 65 
  Tue Jul 17 11:00:19 2018                                                                                               Page  143




               63 74 6F 72 73 
               3A 20 31 30 2F 
               74 72 61 63 6B 
               2C 20 74 6F 74 
               61 6C 3A 20 31 
               36 30 30 0D 00 
10418                           
10419                           ;---------------------------------------------------------------------------
10420                           ; emulator initialitation
10421                           ;---------------------------------------------------------------------------
10422                           
10423                           ; init emulator -- called at boot time
10424  F959E7                   fscbmint:
10425                                   .GLOBAL fscbmint
10426  F959E7                           
10427  F959E7  0B                       phd                     ; save DP
10428  F959E8  F4 00 7E                 pea     #CBMFSP0        ; set DP of cbm f.s.
10429  F959EB  2B                       pld
10430  F959EC  A2 00                    ldx     #0
10431  F959EE  74 00            ?02:    stz     <zpstart,x
10432  F959F0  9E 00 E1                 stz     CBMFSW_START,x
10433  F959F3  E8                       inx
10434  F959F4  D0 F8                    bne     ?02
10435  F959F6  A9 FF                    lda     #$FF
10436  F959F8  85 58                    sta     linuse          ; all free
10437  F959FA  A2 0E                    ldx     #mxchnls-1
10438  F959FC  95 59            ?04:    sta     lintab,x        ; all free
10439  F959FE  CA                       dex
10440  F959FF  10 FB                    bpl     ?04
10441  F95A01  A9 49                    lda     #cbmv2          ; emulator compatibility
10442  F95A03  85 56                    sta     lsterr
10443  F95A05  A9 00                    lda     #DR0SYS
10444  F95A07  85 6E                    sta     sysbuf          ; drive 0 system track cache
10445  F95A09  20 51 5A                 jsr     ?100
10446  F95A0C  85 74                    sta     dirofs
10447  F95A0E  84 76                    sty     dirbnk
10448  F95A10  A9 24                    lda     #DR1SYS
10449  F95A12  85 6F                    sta     sysbuf+1        ; drive 1 system track cache
10450  F95A14  20 51 5A                 jsr     ?100
10451  F95A17  85 75                    sta     dirofs+1
10452  F95A19  84 77                    sty     dirbnk+1
10453  F95A1B  A9 48                    lda     #DR0CACHE
10454  F95A1D  85 70                    sta     trkbuf          ; drive 0 track cache
10455  F95A1F  20 51 5A                 jsr     ?100
10456  F95A22  85 78                    sta     trkofs
10457  F95A24  84 7A                    sty     trkbnk
10458  F95A26  A9 DC                    lda     #DR1CACHE
10459  F95A28  85 71                    sta     trkbuf+1        ; drive 1 track cache
10460  F95A2A  20 51 5A                 jsr     ?100
10461  F95A2D  85 79                    sta     trkofs+1
10462  F95A2F  84 7B                    sty     trkbnk+1
10463  F95A31  64 80                    stz     tcache          ; invalidate track cache
10464  F95A33  64 81                    stz     tcache+1
10465  F95A35  A9 6C                    lda     #DMAFREE0       ; drive 0 write cache
10466  F95A37  85 72                    sta     wrtbuf
10467  F95A39  20 51 5A                 jsr     ?100
10468  F95A3C  85 7C                    sta     wrtofs
  Tue Jul 17 11:00:19 2018                                                                                               Page  144




10469  F95A3E  84 7E                    sty     wrtbnk
10470  F95A40  A9 C0                    lda     #DMAFREE1       ; drive 1 write cache
10471  F95A42  85 73                    sta     wrtbuf+1
10472  F95A44  20 51 5A                 jsr     ?100
10473  F95A47  85 7D                    sta     wrtofs+1
10474  F95A49  84 7F                    sty     wrtbnk+1
10475  F95A4B  64 82                    stz     wcache          ; invalidate write cache
10476  F95A4D  64 83                    stz     wcache+1
10477  F95A4F  2B                       pld
10478  F95A50  60                       rts
10479                           
10480                           ; calc effective high pointer
10481                           ; in:   A = dma buffer
10482                           ; out:  Y = bank
10483                           ;       A = high pointer
10484  F95A51  A0 02            ?100:   ldy     #DMABNK         ; bank for buffer #00..#7F
10485  F95A53  0A                       asl     a               ; get high pointer
10486  F95A54  90 01                    bcc     ?102
10487  F95A56  C8                       iny                     ; next bank
10488  F95A57  60               ?102:   rts
10489                           
10490                           ;---------------------------------------------------------------------------
10491                           ; tables
10492                           ;---------------------------------------------------------------------------
10493                           
10494                           ; command search table
10495                           ; Rename Scratch New Exist Lock unlocK Append Transfer Move Quick-format
10496  F95A58  52 53 4E 45 4C   cmdtbl  .DB     'RSNELKATMQ'    ; these call tagcmd routine
               4B 41 54 4D 51 
10497          00000A           pcmd    .EQU    $ - cmdtbl      ; limit of no parsed cmds
10498          00000B           ldcmd   .EQU    pcmd + 1        ; load dir cmd image
10499                           ; Copy Validate Filecheck Init Duplicate 
10500  F95A62  43 56 46 49 44           .DB     'CVFID'
10501          00000F           ndcmd   .EQU    $ - cmdtbl      ; limit for check drive
10502                           ; Block-op User
10503  F95A67  42 55                    .DB     'BU'
10504          000011           ncmds   .EQU    $ - cmdtbl
10505                           
10506                           ; Block-op subcmds: Read, Write, Alloc, Free, Position 
10507  F95A69  52 57 41 46 50   cmdstb  .DB     'RWAFP'
10508          000005           ncmds2  .EQU    $ - cmdstb
10509                           
10510                           ; template mask for cmds
10511  F95A6E                   struct:
10512  F95A6E  DD                       .DB     %11011101       ; Rename
10513  F95A6F  1C                       .DB     %00011100       ; Scratch (=type is optional)
10514  F95A70  9E                       .DB     %10011110       ; New
10515  F95A71  DE                       .DB     %11011110       ; Exist
10516  F95A72  DE                       .DB     %11011110       ; Lock
10517  F95A73  DE                       .DB     %11011110       ; unlocK
10518  F95A74  D9                       .DB     %11011001       ; Append
10519  F95A75  DD                       .DB     %11011101       ; Transfer
10520  F95A76  DD                       .DB     %11011101       ; Move
10521  F95A77  9E                       .DB     %10011110       ; QuickF (like New)
10522  F95A78                           
10523  F95A78  51                       .DB     %01010001       ; Copy (basic mask)
10524  F95A79  1C                       .DB     %00011100       ; load dir template
  Tue Jul 17 11:00:19 2018                                                                                               Page  145




10525                           
10526  F95A7A  52 57 41 4D      modlst  .DB     'RWAM'          ; mode table
10527          000004           nmodes  .EQU    $ - modlst
10528  F95A7E  44 53 50 55 4C   tplst   .DB     'DSPULC'        ; file type table
               43 
10529  F95A84  44 53 50 55 52   typlst  .DB     'DSPURC'        ; del,seq,prog,user,rel,cbm
               43 
10530          000006           ntypes  .EQU    $ - typlst
10531  F95A8A  45 45 52 53 45   tp1lst  .DB     'EERSEB'
               42 
10532  F95A90  4C 51 47 52 4C   tp2lst  .DB     'LQGRLM'
               4D 
10533                           
10534                           ; cbm file name bad char's
10535  F95A96  3A 2C 3D 24 22   badchr  .DB     ':,=$"@'        ; char's not allowed in file name
               40 
10536          000006           nbadch  .EQU    $ - badchr
10537                           
10538  F95A9C  62 6C 6F 63 6B   fremsg  .DB     'blocks free.'
               73 20 66 72 65 
               65 2E 
10539          00000C           msglen  .EQU    $-fremsg       
10540                           
10541                           ; bit mask
10542  F95AA8  01 02 04 08 10   bmask   .DB     $01, $02, $04, $08, $10, $20, $40, $80
               20 40 80 
10543  F95AB0  0100 0200 0400   wmask   .DW     $0001, $0002, $0004, $0008, $0010, $0020, $0040, $0080
               0800 1000 2000 
               4000 8000 
10544  F95AC0  0001 0002                .DW     $0100, $0200
10545                           
10546                           ; command functions table
10547  F95AC4                   cjump:
10548  F95AC4  C435 CA32 1D34           .DW     rename, scratch, newdsk, exist, lock, unlock
               3036 4236 7A36 
10549  F95AD0  CB36 9136 AD36           .DW     append, transf, move, quickf, copy, vdate, fcheck
               1334 3A37 523B 
               4B3B 
10550  F95ADE  053C 183C D93C           .DW     initd, dupd, blkb, blku
               C03C 
10551                           
10552                           ; subcommand functions table
10553  F95AE6                   scjmp:
10554  F95AE6  ED3D 823E CA3E           .DW     blkrd, blkwr, blkalc, blkfree, blkpos
               053F 403F 
10555                           
10556                           ; read, write, append, load dir, open dir, open blk
10557  F95AF0                   opncmd:
10558  F95AF0  FA30 5031 8B31           .DW     opnrd, opnwr, opnap, loaddir, opndir, opnblk
               3532 AB32 BE32 
10559                           
10560                           ; error msg
10561  F95AFC  25 30 32 62 75   erfmt:  .DB     '%02bu,%s,%02bu,%02bu', 0
               2C 25 73 2C 25 
               30 32 62 75 2C 
               25 30 32 62 75 
               00 
  Tue Jul 17 11:00:19 2018                                                                                               Page  146




10562                           
10563  F95B11                   ertbl:
10564  F95B11  00 4F 6B 00              .DB     $00,    'Ok', 0                                         ; 00
10565  F95B15  01 46 69 6C 65           .DB     $01,    'Files scratched', 0                            ; 01
               73 20 73 63 72 
               61 74 63 68 65 
               64 00 
10566  F95B26  14 54 72 61 63           .DB     rdtrk,  'Track read error', 0                           ; 20
               6B 20 72 65 61 
               64 20 65 72 72 
               6F 72 00 
10567  F95B38  15 42 61 64 20           .DB     badfmt, 'Bad disk format (or unformatted disk)', 0      ; 21
               64 69 73 6B 20 
               66 6F 72 6D 61 
               74 20 28 6F 72 
               20 75 6E 66 6F 
               72 6D 61 74 74 
               65 64 20 64 69 
               73 6B 29 00 
10568  F95B5F  16 54 72 61 63           .DB     wrtrk,  'Track write error', 0                          ; 22
               6B 20 77 72 69 
               74 65 20 65 72 
               72 6F 72 00 
10569  F95B72  18 52 65 61 64           .DB     rdsec,  'Read error', 0                                 ; 24
               20 65 72 72 6F 
               72 00 
10570  F95B7E  19 57 72 69 74           .DB     wrsec,  'Write error', 0                                ; 25
               65 20 65 72 72 
               6F 72 00 
10571  F95B8B  1A 57 72 69 74           .DB     wpon,   'Write protect on', 0                           ; 26
               65 20 70 72 6F 
               74 65 63 74 20 
               6F 6E 00 
10572  F95B9D  1D 44 69 73 6B           .DB     badid,  'Disk ID mismatch', 0                           ; 29
               20 49 44 20 6D 
               69 73 6D 61 74 
               63 68 00 
10573  F95BAF  1E 47 65 6E 65           .DB     badsyn, 'General syntax error', 0                       ; 30
               72 61 6C 20 73 
               79 6E 74 61 78 
               20 65 72 72 6F 
               72 00 
10574  F95BC5  1F 49 6E 76 61           .DB     badcmd, 'Invalid command', 0                            ; 31
               6C 69 64 20 63 
               6F 6D 6D 61 6E 
               64 00 
10575  F95BD6  20 43 6F 6D 6D           .DB     longln, 'Command line too long', 0                      ; 32
               61 6E 64 20 6C 
               69 6E 65 20 74 
               6F 6F 20 6C 6F 
               6E 67 00 
10576  F95BED  21 49 6E 76 61           .DB     badfn,  'Invalid file name', 0                          ; 33
               6C 69 64 20 66 
               69 6C 65 20 6E 
               61 6D 65 00 
10577  F95C00  22 4D 69 73 73           .DB     nofile, 'Missing file name', 0                          ; 34
               69 6E 67 20 66 
  Tue Jul 17 11:00:19 2018                                                                                               Page  147




               69 6C 65 20 6E 
               61 6D 65 00 
10578  F95C13  23 49 6C 6C 65           .DB     baddrv, 'Illegal drive number', 0                       ; 35
               67 61 6C 20 64 
               72 69 76 65 20 
               6E 75 6D 62 65 
               72 00 
10579  F95C29  24 49 6C 6C 65           .DB     badchn, 'Illegal channel number', 0                     ; 36
               67 61 6C 20 63 
               68 61 6E 6E 65 
               6C 20 6E 75 6D 
               62 65 72 00 
10580  F95C41  25 45 6D 70 74           .DB     nullln, 'Empty command string', 0                       ; 37
               79 20 63 6F 6D 
               6D 61 6E 64 20 
               73 74 72 69 6E 
               67 00 
10581  F95C57  27 43 61 6E 6E           .DB     notsam, 'Cannot rename across drives', 0                ; 39
               6F 74 20 72 65 
               6E 61 6D 65 20 
               61 63 72 6F 73 
               73 20 64 72 69 
               76 65 73 00 
10582  F95C74  28 4C 6F 63 6B           .DB     flock,  'Locked file', 0                                ; 40
               65 64 20 66 69 
               6C 65 00 
10583  F95C81  29 57 72 69 74           .DB     fsplt,  'Write file not closed', 0                      ; 41
               65 20 66 69 6C 
               65 20 6E 6F 74 
               20 63 6C 6F 73 
               65 64 00 
10584  F95C98  2A 55 6E 6D 61           .DB     bnotm,  'Unmatch blocks count', 0                       ; 42
               74 63 68 20 62 
               6C 6F 63 6B 73 
               20 63 6F 75 6E 
               74 00 
10585  F95CAE  2B 49 6E 76 61           .DB     invlnk, 'Invalid file link', 0                          ; 43
               6C 69 64 20 66 
               69 6C 65 20 6C 
               69 6E 6B 00 
10586  F95CC1  2C 57 72 6F 6E           .DB     badlst, 'Wrong index in last block', 0                  ; 44
               67 20 69 6E 64 
               65 78 20 69 6E 
               20 6C 61 73 74 
               20 62 6C 6F 63 
               6B 00 
10587  F95CDC  3C 46 69 6C 65           .DB     filopn, 'File open', 0                                  ; 60
               20 6F 70 65 6E 
               00 
10588  F95CE7  3D 46 69 6C 65           .DB     filnop, 'File not open', 0                              ; 61
               20 6E 6F 74 20 
               6F 70 65 6E 00 
10589  F95CF6  3E 46 69 6C 65           .DB     flntfd, 'File not found', 0                             ; 62
               20 6E 6F 74 20 
               66 6F 75 6E 64 
               00 
10590  F95D06  3F 46 69 6C 65           .DB     flexst, 'File exists', 0                                ; 63
  Tue Jul 17 11:00:19 2018                                                                                               Page  148




               20 65 78 69 73 
               74 73 00 
10591  F95D13  40 46 69 6C 65           .DB     mistyp, 'File type mismatch', 0                         ; 64
               20 74 79 70 65 
               20 6D 69 73 6D 
               61 74 63 68 00 
10592  F95D27  42 49 6C 6C 65           .DB     badts,  'Illegal track or sector', 0                    ; 55
               67 61 6C 20 74 
               72 61 63 6B 20 
               6F 72 20 73 65 
               63 74 6F 72 00 
10593  F95D40  43 49 6C 6C 65           .DB     systs,  'Illegal system track or sector', 0             ; 67
               67 61 6C 20 73 
               79 73 74 65 6D 
               20 74 72 61 63 
               6B 20 6F 72 20 
               73 65 63 74 6F 
               72 00 
10594  F95D60  44 57 72 69 74           .DB     wrfil,  'Write only file', 0                            ; 68
               65 20 6F 6E 6C 
               79 20 66 69 6C 
               65 00 
10595  F95D71  45 52 65 61 64           .DB     rdfil,  'Read only file', 0                             ; 69    
               20 6F 6E 6C 79 
               20 66 69 6C 65 
               00 
10596  F95D81  46 4E 6F 20 63           .DB     nochnl, 'No channel available',0                        ; 70
               68 61 6E 6E 65 
               6C 20 61 76 61 
               69 6C 61 62 6C 
               65 00 
10597  F95D97  47 44 69 72 65           .DB     direrr, 'Directory error', 0                            ; 71
               63 74 6F 72 79 
               20 65 72 72 6F 
               72 00 
10598  F95DA8  48 44 69 73 6B           .DB     dskful, 'Disk full', 0                                  ; 72
               20 66 75 6C 6C 
               00 
10599  F95DB3  49 43 42 4D 20           .DB     cbmv2,  'CBM DOS V10 1581 Emulator', 0                  ; 73
               44 4F 53 20 56 
               31 30 20 31 35 
               38 31 20 45 6D 
               75 6C 61 74 6F 
               72 00 
10600  F95DCE  4A 44 72 69 76           .DB     nodriv, 'Drive not ready', 0                            ; 74
               65 20 6E 6F 74 
               20 72 65 61 64 
               79 00 
10601  F95DDF  4B 43 68 61 6E           .DB     opnchn, 'Channel is open',0                             ; 75
               6E 65 6C 20 69 
               73 20 6F 70 65 
               6E 00 
10602  F95DF0  4C 4E 6F 20 6C           .DB     nolinx, 'No logical index available',0                  ; 76
               6F 67 69 63 61 
               6C 20 69 6E 64 
               65 78 20 61 76 
               61 69 6C 61 62 
  Tue Jul 17 11:00:19 2018                                                                                               Page  149




               6C 65 00 
10603  F95E0C  4D 46 6F 72 6D           .DB     fmter,  'Format error', 0                               ; 77
               61 74 20 65 72 
               72 6F 72 00 
10604  F95E1A  4E 49 42 4D 20           .DB     ibmfmt, 'IBM formatted disk', 0                         ; 78
               66 6F 72 6D 61 
               74 74 65 64 20 
               64 69 73 6B 00 
10605  F95E2E  4F 53 79 73 74           .DB     syterr, 'System track read error', 0                    ; 79
               65 6D 20 74 72 
               61 63 6B 20 72 
               65 61 64 20 65 
               72 72 6F 72 00 
10606  F95E47  50 43 6F 72 72           .DB     dirlnk, 'Corrupted directory link', 0                   ; 80
               75 70 74 65 64 
               20 64 69 72 65 
               63 74 6F 72 79 
               20 6C 69 6E 6B 
               00 
10607  F95E61  51 43 6F 72 72           .DB     bamcnt, 'Corrupted bam', 0                              ; 81
               75 70 74 65 64 
               20 62 61 6D 00 
10608  F95E70  52 52 65 63 75           .DB     badcat, 'Recursive concat', 0                           ; 82
               72 73 69 76 65 
               20 63 6F 6E 63 
               61 74 00 
10609  F95E82  53 49 6E 76 61           .DB     badtlk, 'Invalid talk command', 0                       ; 83
               6C 69 64 20 74 
               61 6C 6B 20 63 
               6F 6D 6D 61 6E 
               64 00 
10610  F95E98  54 49 6E 76 61           .DB     badlsn, 'Invalid listen command', 0                     ; 84
               6C 69 64 20 6C 
               69 73 74 65 6E 
               20 63 6F 6D 6D 
               61 6E 64 00 
10611  F95EB0                           
10612  F95EB0  00                       .DB     0        ; end of table
10613                           
10614  F95EB1                   uerr:
10615  F95EB1  55 6E 6B 6E 6F           .DB     'Unknow error', 0
               77 20 65 72 72 
               6F 72 00 


             Lines Assembled : 10081                  Errors : 0