Subversion Repositories MB01 Project

Rev

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

  Tue Jul 17 11:00:15 2018                                                                                               Page    1







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

                       Input  Filename : src\F8\ata.asm
                       Output Filename : obj\F8\ata.obj
                       Listing Has Been Relocated                               


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




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




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




 2745                           
 2746                                   .ENDS
 2747                           
 2748          [01]             .IFDEF          _ACIA_INC_
 2749                                   .INCLUDE INC\SP.INC
 2750          [00]             .ENDIF
 2751                           
 2759                           .LIST on
 2760                           
 2761                           ; direct page for bios disk data
 2762                           _DPDSK: .SECTION page0, ref_only, common, offset 0      ;DISK ID D.P.
 2763                           
 2764                                           ;.ABSOLUTE
 2765                                           ;.ORG   0x00
 2766                           
 2767  000000                   _atamod0        .DS     41      ; model string device ata #0
 2768  000029                   _ataser0        .DS     21      ; serial string device ata #0
 2769  00003E                   _atarev0        .DS     9       ; revision string device ata #0
 2770                           
 2771  000047                   _atamod1        .DS     41      ; model string device ata #1
 2772  000070                   _ataser1        .DS     21      ; serial string device ata #1
 2773  000085                   _atarev1        .DS     9       ; revision string device ata #1
 2774                           
 2775  00008E                   _usbdsc0        .DS     32      ; identification string device usb #0
 2776  0000AE                   _usbdsc1        .DS     32      ; identification string device usb #1
 2777                           
 2778  0000CE                   _maxsecs        .DS     16      ; disk max. sector's
 2779                           
 2780  0000DE                   _DPDSK_END      .DS     0
 2781                           
 2782                                           ;.RELATIVE
 2783                           
 2784                                   .ENDS
 2788                           .LIST on
 2789                           
 2790                                   ;.INCLUDE inc\BIOSSEG.INC
 2791                           
 2792  F8FFB1                           
 2793          000004           WRITETRASF      .EQU    $04     ; write transfer: read ATA, write MEM
 2794          000008           READTRASF       .EQU    $08     ; read  transfer: read MEM, write ATA
 2795                           
 2796          0007D0           BUSYTMO         .EQU    2000    ; 2000ms (timer PB6) - busy timeout
 2797          0007D0           INTTMO          .EQU    2000    ; 2000ms (timer PB6) - interrupt timeout
 2798          00270F           T2MS5           .EQU    ((2500 * PHI2) - 1)     ; timeout 2.5ms
 2799          009C3F           T2MS10          .EQU    ((10000 * PHI2) - 1)    ; timeout 10ms
 2800                           
 2801          000B40           XBMIN           .EQU    $0B40   ; min. x-mem buffer
 2802          001000           XBMAX           .EQU    $1000   ; max. x-mem buffer + 1
 2803          000001           MBMIN           .EQU    $01     ; min. buffer bank
 2804          0000F0           MBMAX           .EQU    $F0     ; max. buffer bank + 1
 2805          000800           MDMAX           .EQU    $0800   ; max. dma buffer
 2806                           
 2807          000020           READSECTOR      .EQU    $20     ; read sector(s)
 2808          000030           WRITESECTOR     .EQU    $30     ; write sector(s)
 2809          0000C8           READDMA         .EQU    $C8     ; read dma sectors
 2810          0000CA           WRITEDMA        .EQU    $CA     ; write dma sectors
 2811                           
  Tue Jul 17 11:00:15 2018                                                                                               Page    5




 2812                           ;FLUSHCACHE     .EQU    $E7
 2813          0000EC           IDENTDEV        .EQU    $EC     ; identify device
 2814                           
 2815                           ; page 0 local var's (declared in bios temp. work area)
 2816                           _P0BTMP:        .SECTION page0, ref_only, offset bwrktmp        ; DP Tmp. BIOS
 2817          000094           ATATMP_START    .EQU    $
 2818                           
 2819  000094  00               drive           .DB             ; ata #0 or ata #1 device
 2820  000095                   lba             DS      3       ; 24 bit sector address
 2821  000098  00               secnum          .DB             ; sector(s) count # (if 0 -> 256 sec.)
 2822  000099  00               seccnt          .DB             ; copy of secnum
 2823  00009A  00               ifrbit          .DB             ; bit to test on VIA3 IFR
 2824  00009B  00               cmdfg           .DB             ; flag for load command block reg's
 2825  00009C  00               ataop           .DB             ; ata operation flag
 2826                                                           ; <7>=0->read, 1->write
 2827                                                           ; <6>=1 compare (ignored in dma mode)
 2828  00009D  00               memfg           .DB             ; using buffer in x-mem flag
 2829  00009E  00               drdyf           .DB             ; test alt. status reg. while read/write block
 2830  00009F  00               match           .DB             ; compare result (match if not null)
 2831  0000A0                   bufp            LP              ; in/out buffer long pointer
 2832  0000A3                   memp            LP              ; start buffer pointer
 2833  0000A6  0000             xbuf            .DW             ; x-mem buffer # ($0B40..$0FFF)
 2834                                                           ; dma buffer # ($0000..$7FFF)
 2835  0000A8  00               xbnk            .DB             ; starting x-mem bank
 2836  0000A9  00               xsave           .DB             ; save x-mem setting
 2837  0000AA  0000             nlba            .DW             ; total sector's count #
 2838  0000AC  0000             ncnt            .DW             ; dma words count #
 2839  0000AE  00               tmp             .DB             ; temp
 2840  0000AF  00               ataofs          .DB             ; temp: ata offset address
 2841  0000B0  0000             wtmp            .DW             ; temp. word
 2842  0000B2  0000             mbrsgn          .DW             ; mbr signature
 2843  0000B4  0000             mbrfg           .DW             ; mbr first partition flag
 2844  0000B6  00               tmpy            .DB
 2845  0000B7  00               dmareq          .DB
 2846                           
 2847          000024           ATATMP_SIZ      .EQU    ($-ATATMP_START)
 2848                                   .ENDS
 2849                           
 2850                           ;---------------------------------------------------------------------------
 2851                           ; code segment -- bank $F8
 2852                           ;---------------------------------------------------------------------------
 2853                           
 2854                                   .CODEF8
 2855  F88839                           
 2856                                   .LONGA  off
 2857                                   .LONGI  off
 2858  F88839                           
 2859                           ;---------------------------------------------------------------------------
 2860                           ; System interface
 2861                           ;---------------------------------------------------------------------------
 2862                           
 2863                           ;---------------------------------------------------------------------------
 2864                           ; sys_atadma - read/write sectors in ata device (dma mode)
 2865                           ;
 2866                           ; prototype: sys_atadma(bDev, dwSec, bNum, nBuf)
 2867                           ;
 2868                           ; Params (7 bytes):
  Tue Jul 17 11:00:15 2018                                                                                               Page    6




 2869                           ;       bDev    = ata device # (0..1)
 2870                           ;       dwSec   = 24 bit address of first sector (LBA)
 2871                           ;       bNum    = number of sectors to read/write; if bNum=0 then bNum=256
 2872                           ;       nBuf    = dma buffer # ($0000..$07FF)
 2873                           ;
 2874                           ; Out:
 2875                           ;       CF = 0 if operation completed successfully
 2876                           ;               C  = uncahnged
 2877                           ;               X  = unchanged
 2878                           ;               Y  = unchanged
 2879                           ;       CF = 1 if error
 2880                           ;               C  = unchanged
 2881                           ;               X  = extended error code (if any)
 2882                           ;               Y  = error code
 2883                           ;       Status register always preserved except carry
 2884                           
 2885                           ; params offset
 2886          000013           nBuf    .SET    STKPRMS
 2887          000015           bNum    .SET    STKPRMS + 2
 2888          000016           dwSec   .SET    STKPRMS + 3
 2889          000019           bDev    .SET    STKPRMS + 6
 2890                           
 2891  F88839                   sys_atadma:
 2892                                   .GLOBAL sys_atadma
 2893                           
 2894  F88839  64 49                    stz     ataerr          ; clear error var's
 2895  F8883B  64 4A                    stz     ataxer
 2896  F8883D                           ACC16                   ; retrieve function number
 2897  F8883D  C2 20                    rep     #PMFLAG
 2898                                   .LONGA  on
 2899                                   .MNLIST
 2900  F8883F  A3 10                    lda     STKPCL,s        ; pointer to byte after signature
 2901  F88841  85 51                    sta     COPPtr
 2902  F88843  1A                       inc     a               ; update return address
 2903  F88844  83 10                    sta     STKPCL,s
 2904  F88846  A3 16                    lda     dwSec,s         ; get 16 bit param's
 2905  F88848  85 95                    sta     lba
 2906  F8884A  A3 13                    lda     nBuf,s
 2907  F8884C  C9 00 08                 cmp     #MDMAX
 2908  F8884F  B0 5A                    bcs     ?11             ; buffer overflow 
 2909  F88851  85 A6                    sta     xbuf
 2910  F88853                           ACC08                   ; A,M -> 8 bit
 2911  F88853  E2 20                    sep     #PMFLAG
 2912                                   .LONGA  off
 2913                                   .MNLIST
 2914  F88855  A3 12                    lda     STKPBR,s        ; bank where was executed cop instruction
 2915  F88857  85 53                    sta     COPPtr+2        
 2916  F88859  A7 51                    lda     [COPPtr]        ; byte after signature
 2917  F8885B  C9 02                    cmp     #$02            ; right value: 0,1
 2918  F8885D  90 04                    bcc     ?00             ; ok
 2919  F8885F  A9 08                    lda     #ATA_BADOP      ; invalid function
 2920  F88861  80 4C                    bra     ?20             ; set error & exit
 2921  F88863  AA               ?00:    tax                     ; X=operation (0=read,1=verify,2=write)
 2922  F88864  BF 98 91 F8              lda     >OPTAB2,x
 2923  F88868  85 9C                    sta     ataop           ; operation ($00, $80)
 2924  F8886A  A3 18                    lda     dwSec+2,s
 2925  F8886C  85 97                    sta     lba+2           ; store first sector lba
  Tue Jul 17 11:00:15 2018                                                                                               Page    7




 2926  F8886E  A0 00                    ldy     #0
 2927  F88870  A3 15                    lda     bNum,s
 2928  F88872  85 98                    sta     secnum          ; sector's count #
 2929  F88874  85 B0                    sta     wtmp            ; for check
 2930  F88876  D0 01                    bne     ?02             ; less than 256
 2931  F88878  C8                       iny                     ; = 256
 2932  F88879  84 B1            ?02:    sty     wtmp+1          ; for later check
 2933  F8887B  A3 19                    lda     bDev,s          ; device
 2934  F8887D  29 01                    and     #1              ; 0 or 1
 2935  F8887F  AA                       tax
 2936  F88880  34 0E                    bit     atadev,x        ; ready?
 2937  F88882  30 04                    bmi     ?03             ; yes
 2938  F88884  A9 01                    lda     #ATA_NOTREADY   ; not ready
 2939  F88886  80 27                    bra     ?20             ; set error & exit
 2940  F88888  86 94            ?03:    stx     drive
 2941  F8888A  A5 B0                    lda     wtmp
 2942  F8888C  85 AD                    sta     ncnt+1          ; ncnt = words count
 2943  F8888E  64 AC                    stz     ncnt
 2944  F88890                           ACC16CLC
 2945  F88890  C2 21                    rep     #(PMFLAG.OR.PCFLAG)
 2946                                   .LONGA  on
 2947                                   .MNLIST
 2948  F88892  C6 AC                    dec     ncnt            ; dma need words count - 1
 2949  F88894  A5 A6                    lda     xbuf            ; buffer #
 2950  F88896  65 B0                    adc     wtmp            ; add sec. #    
 2951  F88898  C9 01 08                 cmp     #MDMAX+1        ; buffer overflow?
 2952  F8889B  B0 0E                    bcs     ?11             ; yes
 2953  F8889D  3A                       dec     a               ; final buffer
 2954  F8889E                           ACC08
 2955  F8889E  E2 20                    sep     #PMFLAG
 2956                                   .LONGA  off
 2957                                   .MNLIST
 2958  F888A0  EB                       xba                     ; transfer must be in one 64Kw bank
 2959  F888A1  C5 A7                    cmp     xbuf+1
 2960  F888A3  D0 08                    bne     ?12             ; error: not same bank
 2961  F888A5  20 10 8C                 jsr     dmardwr         ; execute dma transfer
 2962  F888A8  B0 05                    bcs     ?20             ; error
 2963  F888AA  6B                       rtl
 2964  F888AB                   ?11:    ACC08
 2965  F888AB  E2 20                    sep     #PMFLAG
 2966                                   .LONGA  off
 2967                                   .MNLIST
 2968  F888AD  A9 0A            ?12:    lda     #ATA_MEM        ; bad buffer
 2969  F888AF  AA               ?20:    tax
 2970  F888B0  A9 00                    lda     #0              ; report extended error if any
 2971  F888B2  83 0C                    sta     STKXR+1,s
 2972  F888B4  E0 04                    cpx     #ATA_EBIT
 2973  F888B6  D0 01                    bne     ?22
 2974  F888B8  98                       tya                     ; extended error
 2975  F888B9  83 0B            ?22:    sta     STKXR,s
 2976  F888BB  85 4A                    sta     ataxer          ; extended error code
 2977  F888BD  8A                       txa                     ; A=error code
 2978  F888BE  85 49                    sta     ataerr
 2979  F888C0  38                       sec
 2980  F888C1  6B                       rtl
 2981                           
 2982                           ;---------------------------------------------------------------------------
  Tue Jul 17 11:00:15 2018                                                                                               Page    8




 2983                           ; sys_atarw - read/write/verify sectors in ata device (pio mode)
 2984                           ;
 2985                           ; prototype: sys_atarw(bDev, dwSec, bNum, lpBuf, bFlag)
 2986                           ;
 2987                           ; Params (9 bytes):
 2988                           ;       bDev    = ata device # (0..1)
 2989                           ;       dwSec   = 24 bit address of first sector (LBA)
 2990                           ;       bNum    = number of sectors to read/write; if bNum=0 then bNum=256
 2991                           ;       lpBuf   = long pointer to buffer
 2992                           ;                       if bank(lpBuf+2)=0 or bank=1 buffer is in the x-mem
 2993                           ;                       and in this case lpBuf store the x-mem buffer;
 2994                           ;                       x-mem buffer can be only in range $0B40..$0FFF
 2995                           ;                       if conventional memory, bank must be in range $01..$EF
 2996                           ;       bFlag   = flag
 2997                           ;                       <7>: verify data after writing
 2998                           ;                       ignored in read/verify operation
 2999                           ;
 3000                           ; Out:
 3001                           ;       CF = 0 if operation completed successfully
 3002                           ;               C  = uncahnged
 3003                           ;               X  = unchanged
 3004                           ;               Y  = unchanged
 3005                           ;       CF = 1 if error
 3006                           ;               C  = unchanged
 3007                           ;               X  = extended error code (if any)
 3008                           ;               Y  = error code
 3009                           ;       Status register always preserved except carry
 3010                           
 3011                           ; params offset
 3012          000013           bFlag   .SET    STKPRMS
 3013          000014           lpBuf   .SET    STKPRMS + 1
 3014          000017           bNum    .SET    STKPRMS + 4
 3015          000018           dwSec   .SET    STKPRMS + 5
 3016          00001B           bDev    .SET    STKPRMS + 8
 3017                           
 3018  F888C2                   sys_atarw:
 3019                                   .GLOBAL sys_atarw
 3020                           
 3021  F888C2  64 49                    stz     ataerr          ; clear error var's
 3022  F888C4  64 4A                    stz     ataxer
 3023  F888C6                           ACC16                   ; retrieve function number
 3024  F888C6  C2 20                    rep     #PMFLAG
 3025                                   .LONGA  on
 3026                                   .MNLIST
 3027  F888C8  A3 10                    lda     STKPCL,s        ; pointer to byte after signature
 3028  F888CA  85 51                    sta     COPPtr
 3029  F888CC  1A                       inc     a               ; update return address
 3030  F888CD  83 10                    sta     STKPCL,s
 3031  F888CF  A3 18                    lda     dwSec,s         ; get 16 bit param's
 3032  F888D1  85 95                    sta     lba
 3033  F888D3  A3 14                    lda     lpBuf,s
 3034  F888D5  85 A3                    sta     memp
 3035  F888D7                           ACC08                   ; A,M -> 8 bit
 3036  F888D7  E2 20                    sep     #PMFLAG
 3037                                   .LONGA  off
 3038                                   .MNLIST
 3039  F888D9  A3 12                    lda     STKPBR,s        ; bank where was executed cop instruction
  Tue Jul 17 11:00:15 2018                                                                                               Page    9




 3040  F888DB  85 53                    sta     COPPtr+2        
 3041  F888DD  A7 51                    lda     [COPPtr]        ; byte after signature
 3042  F888DF  C9 03                    cmp     #$03            ; right value: 0,1,2
 3043  F888E1  90 05                    bcc     ?00             ; ok
 3044  F888E3  A9 08                    lda     #ATA_BADOP      ; invalid function
 3045  F888E5  4C 7E 89                 jmp     ?20             ; set error & exit
 3046  F888E8  AA               ?00:    tax                     ; X=operation (0=read,1=verify,2=write)
 3047  F888E9  BF 95 91 F8              lda     >OPTAB,x
 3048  F888ED  10 0B                    bpl     ?01             ; read/verify (ignore bFlag)
 3049  F888EF  A8                       tay
 3050  F888F0  A3 13                    lda     bFlag,s         ; verify flag (after write)?
 3051  F888F2  30 03                    bmi     ?00a            ; yes
 3052  F888F4  98                       tya
 3053  F888F5  80 03                    bra     ?01             ; no
 3054  F888F7  98               ?00a:   tya     
 3055  F888F8  09 40                    ora     #$40            ; yes, set verify flag
 3056  F888FA  85 9C            ?01:    sta     ataop           ; operation ($00, $40, $80, $C0)
 3057  F888FC  A3 1A                    lda     dwSec+2,s
 3058  F888FE  85 97                    sta     lba+2           ; store first sector lba
 3059  F88900  A0 00                    ldy     #0
 3060  F88902  A3 17                    lda     bNum,s
 3061  F88904  85 98                    sta     secnum          ; sector's count #
 3062  F88906  85 B0                    sta     wtmp            ; for check
 3063  F88908  D0 01                    bne     ?02             ; less than 256
 3064  F8890A  C8                       iny                     ; = 256
 3065  F8890B  84 B1            ?02:    sty     wtmp+1          ; for later check
 3066  F8890D  A3 1B                    lda     bDev,s          ; device
 3067  F8890F  29 01                    and     #1              ; 0 or 1
 3068  F88911  AA                       tax
 3069  F88912  34 0E                    bit     atadev,x        ; ready?
 3070  F88914  30 04                    bmi     ?03             ; yes
 3071  F88916  A9 01                    lda     #ATA_NOTREADY   ; not ready
 3072  F88918  80 64                    bra     ?20             ; set error & exit
 3073  F8891A  86 94            ?03:    stx     drive
 3074  F8891C  64 9D                    stz     memfg
 3075  F8891E  A3 16                    lda     lpBuf+2,s       ; buffer bank
 3076  F88920  C9 01                    cmp     #MBMIN          ; x-mem buffer?
 3077  F88922  B0 24                    bcs     ?08             ; no, conventional memory
 3078  F88924                           ACC16
 3079  F88924  C2 20                    rep     #PMFLAG
 3080                                   .LONGA  on
 3081                                   .MNLIST
 3082  F88926  A0 00                    ldy     #0              ; assume no error
 3083  F88928  A5 A3                    lda     memp            ; check x-mem buffer
 3084  F8892A  85 A6                    sta     xbuf
 3085  F8892C  C9 40 0B                 cmp     #XBMIN
 3086  F8892F  90 0A                    bcc     ?04             ; error
 3087  F88931  18                       clc
 3088  F88932  65 B0                    adc     wtmp            ; add sector's count
 3089  F88934  B0 05                    bcs     ?04             ; overflow error
 3090  F88936  C9 01 10                 cmp     #XBMAX+1
 3091  F88939  90 02                    bcc     ?06             ; buffer limits ok
 3092  F8893B  A0 09            ?04:    ldy     #ATA_XMEM       ; Y=x-mem buffer error
 3093  F8893D                   ?06:    ACC08
 3094  F8893D  E2 20                    sep     #PMFLAG
 3095                                   .LONGA  off
 3096                                   .MNLIST
  Tue Jul 17 11:00:15 2018                                                                                               Page   10




 3097  F8893F  98                       tya
 3098  F88940  D0 3C                    bne     ?20             ; set error & exit
 3099  F88942  A9 80                    lda     #$80
 3100  F88944  85 9D                    sta     memfg
 3101  F88946  80 27                    bra     ?14             ; ok, good x-mem buffer
 3102  F88948  85 A5            ?08:    sta     memp+2          ; store buffer bank
 3103  F8894A  C9 F0                    cmp     #MBMAX          ; over max. bank?
 3104  F8894C  B0 1D                    bcs     ?12             ; yes, error
 3105  F8894E  AA                       tax                     ; X=bank
 3106  F8894F                           ACC16
 3107  F8894F  C2 20                    rep     #PMFLAG
 3108                                   .LONGA  on
 3109                                   .MNLIST
 3110  F88951  64 AC                    stz     nlba+2          ; high word (only low byte significative)
 3111  F88953  A5 B0                    lda     wtmp            ; convert secnum in bytes
 3112  F88955  A0 09                    ldy     #9              ; 9 shift (mult by 512)
 3113  F88957  0A               ?10:    asl     a               ; low word
 3114  F88958  26 AC                    rol     nlba+2          ; shift high word
 3115  F8895A  88                       dey
 3116  F8895B  D0 FA                    bne     ?10
 3117  F8895D  18                       clc
 3118  F8895E  65 A3                    adc     memp
 3119  F88960  85 AA                    sta     nlba            ; end address: low word
 3120  F88962                           ACC08
 3121  F88962  E2 20                    sep     #PMFLAG
 3122                                   .LONGA  off
 3123                                   .MNLIST
 3124  F88964  8A                       txa                     ; start bank
 3125  F88965  65 AC                    adc     nlba+2          ; end address: bank
 3126  F88967  C9 F0                    cmp     #MBMAX
 3127  F88969  90 04                    bcc     ?14             ; ok, good buffer
 3128  F8896B  A9 0A            ?12:    lda     #ATA_MEM        ; bad buffer
 3129  F8896D  80 0F                    bra     ?20             ; set error & exit
 3130  F8896F  24 9C            ?14:    bit     ataop
 3131  F88971  30 06                    bmi     ?18             ; write op
 3132  F88973  20 31 8B                 jsr     readsct
 3133  F88976  B0 06                    bcs     ?20             ; read error
 3134  F88978  6B               ?16:    rtl                     ; ok, no error
 3135  F88979  20 F0 89         ?18:    jsr     writesct
 3136  F8897C  90 FA                    bcc     ?16             ; write ok
 3137  F8897E  AA               ?20:    tax
 3138  F8897F  A9 00                    lda     #0              ; report extended error if any
 3139  F88981  83 0C                    sta     STKXR+1,s
 3140  F88983  E0 04                    cpx     #ATA_EBIT
 3141  F88985  D0 01                    bne     ?22
 3142  F88987  98                       tya                     ; extended error
 3143  F88988  83 0B            ?22:    sta     STKXR,s
 3144  F8898A  85 4A                    sta     ataxer          ; extended error code
 3145  F8898C  8A                       txa                     ; A=error code
 3146  F8898D  85 49                    sta     ataerr
 3147  F8898F  38                       sec
 3148  F88990  6B                       rtl
 3149                           
 3150                           ;---------------------------------------------------------------------------
 3151                           ; sys_atactl - control function 
 3152                           ;
 3153                           ; prototype: sys_atactl(A=function#, X=device#)
  Tue Jul 17 11:00:15 2018                                                                                               Page   11




 3154                           ;
 3155                           ; Functions:
 3156                           ;       A=$00:  reset device X
 3157                           ;       A=$01:  identify device X
 3158                           ;       A=$02:  load mbr of device X
 3159                           ;       A=$03:  load pbr of device X
 3160                           ;
 3161                           ; Out:
 3162                           ;       CF = 0 if operation completed successfully
 3163                           ;       CF = 1 if error
 3164                           ;               C  = unchanged
 3165                           ;               X  = extended error code (if any)
 3166                           ;               Y  = error code
 3167                           ;       Status register always preserved except carry
 3168  F88991                   sys_atactl:
 3169                                   .GLOBAL sys_atactl
 3170                           
 3171  F88991  64 49                    stz     ataerr          ; clear error var's
 3172  F88993  64 4A                    stz     ataxer  
 3173  F88995  A3 0B                    lda     STKXR,s
 3174  F88997  29 01                    and     #1
 3175  F88999  85 94                    sta     drive
 3176  F8899B  AA                       tax
 3177  F8899C  34 0E                    bit     atadev,x
 3178  F8899E  10 37                    bpl     ?10             ; not ready
 3179  F889A0  8A                       txa
 3180  F889A1  F0 02                    beq     ?02
 3181  F889A3  A2 10                    ldx     #ATAOFS
 3182  F889A5  86 AF            ?02:    stx     ataofs
 3183  F889A7  A3 0D                    lda     STKCR,s         ; function#
 3184  F889A9  C9 04                    cmp     #$04
 3185  F889AB  B0 2E                    bcs     ?12             ; invalid function
 3186  F889AD  A8                       tay
 3187  F889AE  D0 05                    bne     ?04     
 3188  F889B0  20 1F 8E                 jsr     devres          ; 0: reset device
 3189  F889B3  80 1F                    bra     ?08
 3190  F889B5  A6 94            ?04:    ldx     drive   
 3191  F889B7  3A                       dec     a
 3192  F889B8  F0 11                    beq     ?06             ; 1: ident
 3193  F889BA  3A                       dec     a
 3194  F889BB  F0 03                    beq     ?05             ; 2: load mbr
 3195  F889BD  20 BE 8A                 jsr     getpbr          ; 3: load pbr
 3196  F889C0  A9 E2            ?05:    lda     #11100010B
 3197  F889C2  35 0E                    and     atadev,x
 3198  F889C4  95 0E                    sta     atadev,x        
 3199  F889C6  20 70 90                 jsr     chkmbr          ; 2: load mbr
 3200  F889C9  80 09                    bra     ?08
 3201  F889CB  A9 DF            ?06:    lda     #11011111B      ; 1: ident
 3202  F889CD  35 0E                    and     atadev,x
 3203  F889CF  95 0E                    sta     atadev,x
 3204  F889D1  20 80 8E                 jsr     ident
 3205  F889D4  B0 07            ?08:    bcs     ?14
 3206  F889D6  6B                       rtl
 3207  F889D7  A9 01            ?10:    lda     #ATA_NOTREADY   ; not ready
 3208  F889D9  80 02                    bra     ?14             ; set error & exit
 3209  F889DB  A9 08            ?12:    lda     #ATA_BADOP      ; invalid function
 3210  F889DD  AA               ?14:    tax
  Tue Jul 17 11:00:15 2018                                                                                               Page   12




 3211  F889DE  A9 00                    lda     #0              ; report extended error if any
 3212  F889E0  83 0C                    sta     STKXR+1,s
 3213  F889E2  E0 04                    cpx     #ATA_EBIT
 3214  F889E4  D0 01                    bne     ?16
 3215  F889E6  98                       tya                     ; extended error
 3216  F889E7  83 0B            ?16:    sta     STKXR,s
 3217  F889E9  85 4A                    sta     ataxer          ; extended error code
 3218  F889EB  8A                       txa                     ; A=error code
 3219  F889EC  85 49                    sta     ataerr
 3220  F889EE  38                       sec
 3221  F889EF  6B                       rtl
 3222                           
 3223                           ;---------------------------------------------------------------------------
 3224                           ; basic read/write routines
 3225                           ;---------------------------------------------------------------------------
 3226                           
 3227                                   .LONGA  off
 3228                                   .LONGI  off
 3229                           
 3230                           ; write N (0..256) sector(s) on ata device 
 3231                           ; in:   drive=0 or 1 (ata #0 or ata #1 device)
 3232                           ;       lba[0..2]=24 bits starting sector address
 3233                           ;       secnum=sector(s) count (if 0 -> 256 sect.)
 3234                           ;       memp=long pointer to input buffer
 3235                           ;       memfg<7>=flag buffer x-mem
 3236                           ;       xbuf=x-mem buffer # if using x-mem ($0B40..$0FFF)
 3237                           ;       ataop<6>=flag compare data after writing
 3238                           ; Out:  CF=0 if no error
 3239                           ;       CF=1 if error, A=error code, Y=error reg.
 3240                           ; use:  all
 3241  F889F0                   writesct:
 3242  F889F0  20 E8 8D                 jsr     setbuf          ; set buffer pointer
 3243  F889F3  A9 80                    lda     #$80
 3244  F889F5  85 9B                    sta     cmdfg           ; load command block registers
 3245  F889F7  A9 80                    lda     #$80
 3246  F889F9  14 9C                    trb     ataop           ; we know is a write op...
 3247  F889FB  A0 30                    ldy     #WRITESECTOR    ; write sectors PIO mode
 3248  F889FD  20 78 8D                 jsr     sndcmd          ; return X=ata offset
 3249  F88A00  EA                       nop                     ; delay before to access status reg. (400ns)
 3250  F88A01  EA                       nop
 3251  F88A02  EA                       nop
 3252  F88A03  EA                       nop
 3253                                   ;bra    ?w1     
 3254  F88A04  3C AE FD                 bit     !ATAALTST,x     ; dummy read    
 3255  F88A07  BD A7 FD         ?w0:    lda     !ATAST,x        ; read status reg.
 3256  F88A0A  30 FB                    bmi     ?w0             ; wait BUSY bit=0
 3257  F88A0C  89 21                    bit     #ATADFB+ATAERRB
 3258  F88A0E  D0 47                    bne     ?idle           ; error
 3259  F88A10  89 08                    bit     #ATADRQ         ; ready to transfer?
 3260  F88A12  D0 18                    bne     ?wrb            ; yes, write data block
 3261  F88A14  80 F1                    bra     ?w0             ; wait for DRQ
 3262  F88A16  3C AE FD         ?loop:  bit     !ATAALTST,x     ; dummy read
 3263  F88A19  BD A7 FD         ?w1:    lda     !ATAST,x        ; read status reg.
 3264  F88A1C  30 FB                    bmi     ?w1             ; wait BUSY bit=0
 3265  F88A1E  89 08                    bit     #ATADRQ         ; end of transfer or error?
 3266  F88A20  F0 35                    beq     ?idle           ; yes
 3267  F88A22  A4 99                    ldy     seccnt
  Tue Jul 17 11:00:15 2018                                                                                               Page   13




 3268  F88A24  D0 06                    bne     ?wrb            ; more blocks
 3269  F88A26  A9 40                    lda     #$40
 3270  F88A28  04 9E                    tsb     drdyf           ; data loss
 3271  F88A2A  E6 99                    inc     seccnt
 3272  F88A2C  20 F3 8C         ?wrb:   jsr     wrblk           ; write data block (256 words)
 3273  F88A2F  C6 99                    dec     seccnt          ; update left count #
 3274  F88A31  20 8B 8C         ?int:   jsr     waitint         ; wait interrupt assertion within timeout
 3275  F88A34  90 E0                    bcc     ?loop           ; ok, read status reg.
 3276                           
 3277                                   ; no int. assertion: this happen if device expect more data block
 3278                                   ; write out data block until DRQ bit reset
 3279  F88A36  A9 40                    lda     #$40
 3280  F88A38  04 9E                    tsb     drdyf           ; signal this error
 3281  F88A3A  BD AE FD         ?w2:    lda     !ATAALTST,x
 3282  F88A3D  89 08                    bit     #ATADRQ
 3283  F88A3F  F0 0B                    beq     ?w3             ; no drq        
 3284  F88A41  9E AA FD                 stz     !ATAPORT,x      ; latch data high byte
 3285  F88A44  9E AB FD                 stz     !ATAPORT+1,x    ; latch data high byte
 3286  F88A47  9E A8 FD                 stz     !ATADATA,x      ; write
 3287  F88A4A  80 EE                    bra     ?w2
 3288  F88A4C  BD AE FD         ?w3:    lda     !ATAALTST,x
 3289  F88A4F  BD AE FD                 lda     !ATAALTST,x
 3290  F88A52  BD A7 FD                 lda     !ATAST,x
 3291  F88A55  30 DA                    bmi     ?int
 3292                           
 3293  F88A57  24 9E            ?idle:  bit     drdyf           ; test interrupt timeout error
 3294  F88A59  50 07                    bvc     ?chk            ; no, so test error condition
 3295  F88A5B  20 1F 8E                 jsr     devres          ; reset device because write error
 3296  F88A5E  A9 02                    lda     #ATA_DLOSS      ; data loss while writing
 3297  F88A60  80 28                    bra     ?err
 3298  F88A62  89 20            ?chk:   bit     #ATADFB         ; device fault bit ?
 3299  F88A64  F0 04                    beq     ?chk1           ; no
 3300  F88A66  A9 03                    lda     #ATA_FAULT      ; yes
 3301  F88A68  80 20                    bra     ?err
 3302  F88A6A  89 01            ?chk1:  bit     #ATAERRB        ; error bit ?
 3303  F88A6C  F0 07                    beq     ?chk2           ; no...so write ok
 3304  F88A6E  BC A1 FD                 ldy     !ATAERROR,x     ; read error register
 3305  F88A71  A9 04                    lda     #ATA_EBIT       ; error bits
 3306  F88A73  80 15                    bra     ?err
 3307  F88A75  A5 99            ?chk2:  lda     seccnt          ; all blocks was written?
 3308  F88A77  F0 07                    beq     ?ok             ; yes
 3309  F88A79  20 1F 8E                 jsr     devres          ; reset device because premature ending
 3310  F88A7C  A9 05                    lda     #ATA_DEVRES
 3311  F88A7E  80 0A                    bra     ?err
 3312  F88A80  18               ?ok:    clc                     ; assume no error       
 3313  F88A81  24 9C                    bit     ataop           ; request for verify data?
 3314  F88A83  50 06                    bvc     ?done           ; no, exit (no error)
 3315  F88A85  20 16 8B                 jsr     cmpsct          ; compare written data
 3316  F88A88  90 01                    bcc     ?done           ; ok, no error
 3317                                   ;lda    #ATA_VERF       ; assume always data verify error
 3318  F88A8A  38               ?err:   sec                     ; error flag
 3319  F88A8B  24 9D            ?done:  bit     memfg           ; using x-mem?
 3320  F88A8D  10 05                    bpl     ?rts            ; no
 3321  F88A8F  A6 A9                    ldx     xsave
 3322  F88A91  9D 0A FC                 sta     !CRXME,x        ; restore
 3323  F88A94  60               ?rts:   rts
 3324                           
  Tue Jul 17 11:00:15 2018                                                                                               Page   14




 3325                           ; load MBR in memory
 3326                           ; in:   drive
 3327  F88A95                   getmbr:
 3328  F88A95                           ACC16                   ; set pointer for MBR
 3329  F88A95  C2 20                    rep     #PMFLAG
 3330                                   .LONGA  on
 3331                                   .MNLIST
 3332  F88A97  A9 00 88                 lda     #MBR0ATA
 3333  F88A9A  A6 94                    ldx     drive
 3334  F88A9C  F0 03                    beq     ?02
 3335  F88A9E  A9 00 8A                 lda     #MBR1ATA
 3336  F88AA1  85 A3            ?02:    sta     memp
 3337  F88AA3  85 A0                    sta     bufp
 3338  F88AA5  64 95                    stz     lba             ; read sector=0
 3339  F88AA7                           ACC08
 3340  F88AA7  E2 20                    sep     #PMFLAG
 3341                                   .LONGA  off
 3342                                   .MNLIST
 3343  F88AA9  A9 01                    lda     #^MBR0ATA
 3344  F88AAB  85 A5                    sta     memp+2
 3345  F88AAD  85 A2                    sta     bufp+2
 3346  F88AAF  64 97                    stz     lba+2
 3347  F88AB1  64 9C                    stz     ataop           ; just read
 3348  F88AB3  64 9D                    stz     memfg           ; no x-mem
 3349  F88AB5  A9 01                    lda     #1
 3350  F88AB7  85 98                    sta     secnum          ; read just one block
 3351  F88AB9                           
 3352  F88AB9  4C D9 8B                 jmp     _dmald
 3353  F88ABC                           
 3354  F88ABC  80 7E                    bra     readsct2
 3355                           
 3356                           ; load PBR in memory
 3357                           ; in:   drive
 3358  F88ABE                   getpbr:
 3359  F88ABE  A5 94                    lda     drive
 3360  F88AC0  0A                       asl     a
 3361  F88AC1  0A                       asl     a
 3362  F88AC2  AA                       tax                     ; index to access atambr var
 3363  F88AC3                           ACC16                   ; set pointer for MBR
 3364  F88AC3  C2 20                    rep     #PMFLAG
 3365                                   .LONGA  on
 3366                                   .MNLIST
 3367  F88AC5  A9 00 8C                 lda     #PBR0ATA
 3368  F88AC8  A4 94                    ldy     drive
 3369  F88ACA  F0 03                    beq     ?02
 3370  F88ACC  A9 00 8E                 lda     #PBR1ATA
 3371  F88ACF  85 A3            ?02:    sta     memp
 3372  F88AD1  85 A0                    sta     bufp
 3373  F88AD3  B5 22                    lda     atambr,x        
 3374  F88AD5  85 95                    sta     lba             ; read pbr sector
 3375  F88AD7                           ACC08
 3376  F88AD7  E2 20                    sep     #PMFLAG
 3377                                   .LONGA  off
 3378                                   .MNLIST
 3379  F88AD9  A9 01                    lda     #^MBR0ATA
 3380  F88ADB  85 A5                    sta     memp+2
 3381  F88ADD  85 A2                    sta     bufp+2
  Tue Jul 17 11:00:15 2018                                                                                               Page   15




 3382  F88ADF  B5 24                    lda     atambr+2,x
 3383  F88AE1  85 97                    sta     lba+2
 3384  F88AE3  64 9C                    stz     ataop           ; just read
 3385  F88AE5  64 9D                    stz     memfg           ; no x-mem
 3386  F88AE7  A9 01                    lda     #1
 3387  F88AE9  85 98                    sta     secnum          ; read just one block
 3388  F88AEB                           
 3389  F88AEB  4C D9 8B                 jmp     _dmald
 3390                           
 3391  F88AEE  80 4C                    bra     readsct2
 3392                           
 3393                           ; get identification device data
 3394                           ; in:   drive
 3395  F88AF0                   getid:
 3396  F88AF0                           ACC16                   ; set pointer for identification data
 3397  F88AF0  C2 20                    rep     #PMFLAG
 3398                                   .LONGA  on
 3399                                   .MNLIST
 3400  F88AF2  A9 00 90                 lda     #ID0ATA
 3401  F88AF5  A6 94                    ldx     drive
 3402  F88AF7  F0 03                    beq     ?02
 3403  F88AF9  A9 00 92                 lda     #ID1ATA
 3404  F88AFC  85 A3            ?02:    sta     memp
 3405  F88AFE  85 A0                    sta     bufp
 3406  F88B00                           ACC08
 3407  F88B00  E2 20                    sep     #PMFLAG
 3408                                   .LONGA  off
 3409                                   .MNLIST
 3410  F88B02  A9 01                    lda     #^ID0ATA
 3411  F88B04  85 A5                    sta     memp+2
 3412  F88B06  85 A2                    sta     bufp+2
 3413  F88B08  64 9B                    stz     cmdfg           ; no load command block registers
 3414  F88B0A  64 9C                    stz     ataop           ; just read
 3415  F88B0C  64 9D                    stz     memfg           ; no x-mem
 3416  F88B0E  A9 01                    lda     #1
 3417  F88B10  85 98                    sta     secnum          ; read just one block
 3418  F88B12  A0 EC                    ldy     #IDENTDEV       ; identify device command
 3419  F88B14  80 2E                    bra     piord           ; pio mode read
 3420  F88B16                           
 3421                           ; compare buffer with ata device after writing
 3422  F88B16                   cmpsct:
 3423  F88B16  A5 A3                    lda     memp            ; restore buffer
 3424  F88B18  85 A0                    sta     bufp
 3425  F88B1A  A5 A4                    lda     memp+1
 3426  F88B1C  85 A1                    sta     bufp+1
 3427  F88B1E  A5 A5                    lda     memp+2
 3428  F88B20  85 A2                    sta     bufp+2
 3429  F88B22  24 9D                    bit     memfg           ; using x-mem?
 3430  F88B24  10 16                    bpl     readsct2        ; no
 3431  F88B26  A9 40                    lda     #$40
 3432  F88B28  14 9D                    trb     memfg           ; no restore x-mem setting when finish
 3433  F88B2A  A5 A8                    lda     xbnk
 3434  F88B2C  8D 28 FD                 sta     !PIA0+PIAPRA    ; set bank
 3435  F88B2F  80 0B                    bra     readsct2
 3436                           
 3437                           ; read/compare N (0..256) sector(s) on ata device 
 3438                           ; in:   drive=0 or 1 (ata #0 or ata #1 device)
  Tue Jul 17 11:00:15 2018                                                                                               Page   16




 3439                           ;       lba[0..2]=24 bits starting sector address
 3440                           ;       secnum=sector(s) count (if 0 -> 256 sect.)
 3441                           ;       memp=long pointer to input buffer
 3442                           ;       memfg<7>=flag buffer x-mem
 3443                           ;       memfg<6>=restore x-mem setting on exit
 3444                           ;       xbuf=x-mem buffer # if using x-mem ($0B40..$0FFF)
 3445                           ;       ataop<6>=flag compare data
 3446                           ; Out:  CF=0 if no error
 3447                           ;       CF=1 if error, A=error code, Y=error reg.
 3448                           ; use:  all
 3449  F88B31                   readsct:
 3450  F88B31  24 9D                    bit     memfg           ; using x-mem?
 3451  F88B33  10 04                    bpl     ?02             ; no
 3452  F88B35  A9 40                    lda     #$40
 3453  F88B37  04 9D                    tsb     memfg           ; restore x-mem setting when finish
 3454  F88B39  20 E8 8D         ?02:    jsr     setbuf          ; set buffer pointer
 3455                           
 3456                           ; entry point for compare after writing
 3457  F88B3C                   readsct2:       
 3458  F88B3C  A9 80                    lda     #$80
 3459  F88B3E  85 9B                    sta     cmdfg           ; load command block registers
 3460  F88B40  85 9F                    sta     match           ; good compare
 3461  F88B42  A0 20                    ldy     #READSECTOR     ; read sector(s) command
 3462                           
 3463                           ; entry point for identify device
 3464  F88B44                   piord:
 3465  F88B44  20 78 8D                 jsr     sndcmd          ; return X=ata offset
 3466  F88B47  A5 9A                    lda     ifrbit          ; check interrupt
 3467  F88B49  2C CD FD         ?w1:    bit     VIA3+VIAIFR     ; test CA1/CB1 transition
 3468  F88B4C  F0 FB                    beq     ?w1             ; wait interrupt assertion from ata device
 3469  F88B4E  8D CD FD                 sta     VIA3+VIAIFR     ; clear interrupt flag
 3470  F88B51  BD A7 FD         ?w2:    lda     !ATAST,x        ; wait BUSY bit=0
 3471  F88B54  30 FB                    bmi     ?w2
 3472  F88B56  89 08                    bit     #ATADRQ         ; ready to read a data block?
 3473  F88B58  D0 2E                    bne     ?rdb            ; yes, read first data block
 3474  F88B5A  89 21                    bit     #ATADFB+ATAERRB
 3475  F88B5C  D0 45                    bne     ?chk            ; error -- stop
 3476  F88B5E  80 F1                    bra     ?w2             ; some CF need time to set DRQ  
 3477  F88B60  20 8B 8C         ?loop:  jsr     waitint         ; wait interrupt assertion within timeout
 3478  F88B63  90 1A                    bcc     ?w4             ; ok, read status reg.
 3479  F88B65  A9 40                    lda     #$40            ; no interrupt assertion
 3480  F88B67  04 9E                    tsb     drdyf           ; signal this error
 3481  F88B69  BD AE FD         ?w3:    lda     !ATAALTST,x
 3482  F88B6C  89 08                    bit     #ATADRQ         ; device expect more data block to transfer?
 3483  F88B6E  F0 05                    beq     ?w30            ; no...continue... keep error condition         
 3484  F88B70  BD A8 FD                 lda     !ATADATA,x      ; read wrong data and discard...
 3485  F88B73  80 F4                    bra     ?w3             ; ...until end of data block
 3486  F88B75  BD AE FD         ?w30:   lda     !ATAALTST,x
 3487  F88B78  BD A7 FD                 lda     !ATAST,x
 3488  F88B7B  10 19                    bpl     ?tst
 3489  F88B7D  00 00                    brk
 3490  F88B7F  BD A7 FD         ?w4:    lda     !ATAST,x
 3491  F88B82  30 FB                    bmi     ?w4
 3492  F88B84  89 08                    bit     #ATADRQ         ; device expect more data block to transfer?
 3493  F88B86  F0 0E                    beq     ?tst            ; no... check error condition           
 3494  F88B88  20 B9 8C         ?rdb:   jsr     rdblk           ; read a block (256 words)      
 3495  F88B8B  C6 99            ?nxt:   dec     seccnt          ; update left blocks count #
  Tue Jul 17 11:00:15 2018                                                                                               Page   17




 3496  F88B8D  D0 D1                    bne     ?loop           ; continue until all sectors was readden
 3497  F88B8F  BD A7 FD         ?idle:  lda     !ATAST,x        ; read status reg.
 3498  F88B92  10 02                    bpl     ?tst
 3499  F88B94  00 00                    brk
 3500  F88B96  24 9E            ?tst:   bit     drdyf           ; test interrupt timeout error
 3501  F88B98  50 09                    bvc     ?chk            ; no, so test error condition
 3502  F88B9A  20 1F 8E                 jsr     devres          ; reset device because read error
 3503  F88B9D  A9 05                    lda     #ATA_DEVRES     ; data loss while reading
 3504  F88B9F  A9 FF                    lda     #$FF
 3505  F88BA1  80 29                    bra     ?err    
 3506  F88BA3  89 20            ?chk:   bit     #ATADFB         ; device fault bit ?
 3507  F88BA5  F0 04                    beq     ?chk1           ; no
 3508  F88BA7  A9 03                    lda     #ATA_FAULT      ; yes
 3509  F88BA9  80 21                    bra     ?err            ; error
 3510  F88BAB  89 01            ?chk1:  bit     #ATAERRB        ; error bit ?
 3511  F88BAD  F0 07                    beq     ?chk2           ; no... all seem good
 3512  F88BAF  BC A1 FD                 ldy     !ATAERROR,x     ; read error register
 3513  F88BB2  A9 04                    lda     #ATA_EBIT       ; error bits
 3514  F88BB4  80 16                    bra     ?err
 3515  F88BB6  A4 99            ?chk2:  ldy     seccnt
 3516  F88BB8  F0 07                    beq     ?chk3
 3517  F88BBA  20 1F 8E                 jsr     devres          ; reset device because read error
 3518  F88BBD  A9 02                    lda     #ATA_DLOSS      ; data loss while reading
 3519  F88BBF  80 0B                    bra     ?err
 3520  F88BC1  18               ?chk3:  clc                     ; assume no error       
 3521  F88BC2  24 9C                    bit     ataop           ; was compare data operation?
 3522  F88BC4  50 07                    bvc     ?done           ; no, exit (no error)
 3523  F88BC6  A4 9F                    ldy     match           ; all match?
 3524  F88BC8  D0 03                    bne     ?done           ; ok, good compare
 3525  F88BCA  A9 06                    lda     #ATA_VERF       ; compare error
 3526  F88BCC  38               ?err:   sec                     ; error flag
 3527  F88BCD  24 9D            ?done:  bit     memfg           ; using x-mem?
 3528  F88BCF  10 07                    bpl     ?rts            ; no
 3529  F88BD1  50 05                    bvc     ?rts            ; no restore x-mem setting
 3530  F88BD3  A6 A9                    ldx     xsave
 3531  F88BD5  9D 0A FC                 sta     !CRXME,x        ; restore
 3532  F88BD8  60               ?rts:   rts
 3533                           
 3534                           ; load DMA mbr/pbr
 3535  F88BD9                   _dmald:
 3536  F88BD9  64 A6                    stz     xbuf
 3537  F88BDB  64 A7                    stz     xbuf+1
 3538  F88BDD  64 AD                    stz     ncnt+1
 3539  F88BDF  A9 FF                    lda     #$FF
 3540  F88BE1  85 AC                    sta     ncnt
 3541  F88BE3  20 10 8C                 jsr     dmardwr
 3542  F88BE6  B0 27                    bcs     ?100
 3543  F88BE8  A9 08                    lda     #$08            ; PB3 VIA3
 3544  F88BEA  1C C0 FD                 trb     VIA3+VIAPRB     ; enable 1Mb buffer
 3545  F88BED  AD CF FD                 lda     !VIA3+VIAPRANH
 3546  F88BF0  29 F8                    and     #$F8
 3547  F88BF2  8D CF FD                 sta     !VIA3+VIAPRANH  ; set bank
 3548                           
 3549  F88BF5  A0 00                    ldy     #0
 3550  F88BF7  64 A0                    stz     bufp
 3551  F88BF9  64 A1                    stz     bufp+1
 3552  F88BFB  A9 02                    lda     #2
  Tue Jul 17 11:00:15 2018                                                                                               Page   18




 3553  F88BFD  85 A2                    sta     bufp+2
 3554  F88BFF                           INDEX16
 3555  F88BFF  C2 10                    rep     #PXFLAG
 3556                                   .LONGI  on
 3557                                   .MNLIST
 3558  F88C01  A2 00 02                 ldx     #$200
 3559  F88C04  B7 A0            ?10:    lda     [bufp],y
 3560  F88C06  97 A3                    sta     [memp],y
 3561  F88C08  C8                       iny
 3562  F88C09  CA                       dex
 3563  F88C0A  D0 F8                    bne     ?10
 3564  F88C0C                           INDEX08
 3565  F88C0C  E2 10                    sep     #PXFLAG
 3566                                   .LONGI  off
 3567                                   .MNLIST
 3568  F88C0E  18                       clc
 3569  F88C0F  60               ?100:   rts
 3570                           
 3571                           ; read/write N (0..256) sector(s) on ata device in dma mode 
 3572                           ; in:   drive = 0 or 1 (ata #0 or ata #1 device)
 3573                           ;       ataop = ata operation flag: <7>=0->read, 1->write
 3574                           ;       lba[0..2] = 24 bits starting sector address
 3575                           ;       secnum = sector(s) count (if 0 -> 256 sect.)
 3576                           ;       xbuf = dma buffer #
 3577                           ;       ncnt = words count # - 1
 3578                           ; Out:  CF=0 if no error
 3579                           ;       CF=1 if error, A=error code, Y=error reg.
 3580                           ; use:  all
 3581  F88C10                   dmardwr:
 3582  F88C10  A9 80                    lda     #$80
 3583  F88C12  85 9B                    sta     cmdfg           ; load command block registers
 3584  F88C14  A6 94                    ldx     drive
 3585  F88C16  BF 9E 91 F8              lda     >DMAREQ,x
 3586  F88C1A  85 B1                    sta     wtmp+1          ; check dmareq line
 3587  F88C1C  20 FA 90                 jsr     dmaset          ; dma setup     
 3588  F88C1F  A0 C8                    ldy     #READDMA        ; read sector(s) command
 3589  F88C21  24 9C                    bit     ataop
 3590  F88C23  10 02                    bpl     ?do
 3591  F88C25  A0 CA                    ldy     #WRITEDMA       ; write sector(s) command
 3592  F88C27  20 78 8D         ?do:    jsr     sndcmd          ; return X=ata offset
 3593  F88C2A  64 99                    stz     seccnt
 3594  F88C2C  EA                       nop
 3595  F88C2D  EA                       nop
 3596  F88C2E  EA                       nop
 3597  F88C2F  EA                       nop
 3598  F88C30  BF AE FD 00              lda     >ATAALTST,x
 3599  F88C34  BF A7 FD 00      ?w0:    lda     >ATAST,x        ; wait
 3600  F88C38  29 88                    and     #ATABSY+ATADRQ
 3601  F88C3A  F0 25                    beq     ?chk            ; end - check error
 3602  F88C3C                           
 3603                                   ;lda    !VIA3+VIAPRANH
 3604                                   ;and    wtmp+1          ; dma request?
 3605                                   ;beq    ?w0             ; no
 3606  F88C3C  AF 88 FD 00              lda     >DMA0SR
 3607  F88C40  25 B7                    and     dmareq
 3608  F88C42  F0 F0                    beq     ?w0
 3609                           
  Tue Jul 17 11:00:15 2018                                                                                               Page   19




 3610  F88C44  A9 02                    lda     #$02            ; enable dma
 3611  F88C46  1C 0F FD                 trb     VIA0+VIAPRANH
 3612                           
 3613                                   ;nop
 3614                                   ;nop
 3615                                   ;nop
 3616                                   ;nop
 3617                                   ;lda    ifrbit          ; check interrupt
 3618                           ;?w1:   bit     VIA3+VIAIFR     ; test CA1/CB1 transition
 3619                           ;       beq     ?w1             ; wait interrupt assertion from ata device
 3620                           ;       sta     !VIA3+VIAIFR    ; clear interrupt flag
 3621                           
 3622  F88C49  20 8B 8C                 jsr     waitint
 3623  F88C4C  A9 02                    lda     #$02            ; disable dma
 3624  F88C4E  0C 0F FD                 tsb     VIA0+VIAPRANH
 3625  F88C51  90 0A                    bcc     ?tst            ; seem good: error test
 3626  F88C53                           
 3627                                   ; no interrupt whitin timeout
 3628  F88C53  AF 88 FD 00              lda     >DMA0SR         ; clear status flag
 3629  F88C57  8F 8D FD 00              sta     >DMA0WMCLR      ; reset dma controller
 3630  F88C5B  80 23                    bra     ?res            ; data loss
 3631  F88C5D                           
 3632  F88C5D  BF A7 FD 00      ?tst:   lda     >ATAST,x        ; clear interrupt       
 3633  F88C61  89 20            ?chk:   bit     #ATADFB         ; device fault bit ?
 3634  F88C63  F0 04                    beq     ?chk1           ; no
 3635  F88C65  A9 03                    lda     #ATA_FAULT      ; yes
 3636  F88C67  80 20                    bra     ?err            ; error
 3637  F88C69  89 01            ?chk1:  bit     #ATAERRB        ; error bit ?
 3638  F88C6B  F0 07                    beq     ?chk2           ; no... all seem good
 3639  F88C6D  BC A1 FD                 ldy     !ATAERROR,x     ; read error register
 3640  F88C70  A9 04                    lda     #ATA_EBIT       ; error bits
 3641  F88C72  80 15                    bra     ?err
 3642  F88C74                   ?chk2:
 3643                                   ; check TC on dma status
 3644  F88C74  A5 B0                    lda     wtmp
 3645  F88C76  A6 94                    ldx     drive
 3646  F88C78  3F 9A 91 F8              and     >DMACHNL,x
 3647  F88C7C  F0 05                    beq     ?loss           ; data loss: no TC
 3648  F88C7E                           
 3649                                   ;ldy    seccnt
 3650                                   ;beq    ?chk3
 3651  F88C7E  D0 07                    bne     ?chk3
 3652                           
 3653  F88C80  20 1F 8E         ?res:   jsr     devres          ; reset device because read error
 3654  F88C83  A9 02            ?loss:  lda     #ATA_DLOSS      ; data loss while reading
 3655  F88C85  80 02                    bra     ?err
 3656  F88C87  18               ?chk3:  clc                     ; assume no error       
 3657  F88C88  60                       rts     
 3658  F88C89  38               ?err:   sec                     ; error flag
 3659  F88C8A  60                       rts
 3660                           
 3661  F88C8B                   waitint:
 3662  F88C8B  A9 20                    lda     #$20            ; set T2 count PB6 pulse (1ms)
 3663  F88C8D  0C 0B FD                 tsb     VIA0+VIAACR     
 3664  F88C90  A9 D0                    lda     #<INTTMO        ; interrupt timeout
 3665  F88C92  8D 08 FD                 sta     !VIA0+VIAT2CL
 3666  F88C95  A9 07                    lda     #>INTTMO
  Tue Jul 17 11:00:15 2018                                                                                               Page   20




 3667  F88C97  8D 09 FD                 sta     !VIA0+VIAT2CH
 3668  F88C9A  78                       sei
 3669  F88C9B  A5 9A            ?10:    lda     ifrbit          ; flag bit for test CA1/CB1 
 3670  F88C9D  2C CD FD                 bit     VIA3+VIAIFR
 3671  F88CA0  D0 11                    bne     ?20             ; interrupt assertion (exit with CF=0)
 3672  F88CA2  A9 20                    lda     #T2IFRB
 3673  F88CA4  2C 0D FD                 bit     VIA0+VIAIFR
 3674  F88CA7  F0 F2                    beq     ?10             ; wait for INTTMO ms
 3675  F88CA9  A5 9A                    lda     ifrbit          ; flag bit for test CA1/CB1 
 3676  F88CAB  2C CD FD                 bit     VIA3+VIAIFR
 3677  F88CAE  D0 03                    bne     ?20             ; interrupt assertion
 3678  F88CB0  58                       cli
 3679  F88CB1  38                       sec                     ; timeout
 3680  F88CB2  60                       rts
 3681  F88CB3  8D CD FD         ?20:    sta     VIA3+VIAIFR     ; clear interrupt flag
 3682  F88CB6  58                       cli
 3683  F88CB7  18                       clc
 3684  F88CB8  60                       rts
 3685                           
 3686                           ;---------------------------------------------------------------------------
 3687                           ; low level routines
 3688                           ;---------------------------------------------------------------------------
 3689                           
 3690                                   .LONGA  off
 3691                                   .LONGI  off
 3692                           
 3693                           ; read/compare data block (512 bytes) from ata device
 3694                           ; in:   X=offset ata address
 3695                           ;       ataop<6>=1 if compare, else read
 3696                           ;       match=not null
 3697                           ;       bufp=long pointer to input buffer
 3698                           ;       drdyf<7>=1 if need test DRDY bit in alternate status
 3699                           ;       memfg<7>=flag buffer in x-mem
 3700                           ;out:   bufp updated
 3701                           ;       match=0 if not match
 3702                           ; use:  A,Y
 3703  F88CB9                   rdblk:
 3704  F88CB9  08                       php                     ; save I flag
 3705  F88CBA  78                       sei                     ; disable interrupt
 3706  F88CBB  A0 00                    ldy     #0              ; buffer index
 3707  F88CBD                           INDEX16                 ; X,Y 16 bit - XH,YH cleared
 3708  F88CBD  C2 10                    rep     #PXFLAG
 3709                                   .LONGI  on
 3710                                   .MNLIST
 3711  F88CBF  24 9C                    bit     ataop           ; test bit 6: compare?
 3712  F88CC1  70 16                    bvs     ?12             ; yes
 3713  F88CC3                           
 3714  F88CC3                           ACC16
 3715  F88CC3  C2 20                    rep     #PMFLAG
 3716                                   .LONGA  on
 3717                                   .MNLIST
 3718  F88CC5  BF A8 FD 00      ?02:    lda     >ATADATA,x      ; latch data
 3719  F88CC9  BD AA FD                 lda     !ATAPORT,x      ; read latched data
 3720  F88CCC  97 A0                    sta     [bufp],y
 3721  F88CCE  C8                       iny
 3722  F88CCF  C8                       iny
 3723                                   ;bit    drdyf           ; test DRDY bit in alternate status?
  Tue Jul 17 11:00:15 2018                                                                                               Page   21




 3724                                   ;bpl    ?06             ; no
 3725                           ?04:    ;bit    !ATAALTST-1,x   ; wait DRDY bit high
 3726                                   ;bvc    ?04
 3727  F88CD0  C0 00 02         ?06:    cpy     #$0200                  
 3728  F88CD3  90 F0                    bcc     ?02             ; loop 512 bytes        
 3729  F88CD5                           ACC08
 3730  F88CD5  E2 20                    sep     #PMFLAG
 3731                                   .LONGA  off
 3732                                   .MNLIST
 3733  F88CD7  80 4B                    bra     updp            ; update bufp pointer
 3734                           
 3735                                   ; compare data block
 3736  F88CD9                   ?12:    ACC16
 3737  F88CD9  C2 20                    rep     #PMFLAG
 3738                                   .LONGA  on
 3739                                   .MNLIST
 3740  F88CDB  BF A8 FD 00              lda     >ATADATA,x      ; read data low, latch data high
 3741  F88CDF  BD AA FD                 lda     !ATAPORT,x      ; read latched data
 3742  F88CE2  D7 A0                    cmp     [bufp],y
 3743  F88CE4                           ACC08   
 3744  F88CE4  E2 20                    sep     #PMFLAG
 3745                                   .LONGA  off
 3746                                   .MNLIST
 3747  F88CE6  F0 02                    beq     ?14
 3748  F88CE8  64 9F                    stz     match           ; no match
 3749  F88CEA  C8               ?14:    iny
 3750  F88CEB  C8                       iny
 3751                                   ;bit    drdyf           ; test DRDY bit in alternate status?
 3752                                   ;bpl    ?18             ; no
 3753                           ?16:    ;bit    !ATAALTST,x     ; wait DRDY bit high
 3754                                   ;bvc    ?16
 3755  F88CEC  C0 00 02         ?18:    cpy     #$0200                  
 3756  F88CEF  90 E8                    bcc     ?12             ; loop 512 bytes        
 3757  F88CF1  80 31                    bra     updp            ; update bufp pointer
 3758                           
 3759                           ; write data block (512 bytes) on ata device
 3760                           ; In:   X=offset ata address
 3761                           ;       bufp=long pointer to output buffer
 3762                           ;       drdyf<7>=flag test DRDY bit in alternate status
 3763                           ;       memfg<7>=flag buffer in x-mem
 3764                           ; out:  bufp updated
 3765                           ; use:  A,Y
 3766  F88CF3                   wrblk:
 3767                                   .LONGA  off
 3768                                   .LONGI  off
 3769                           
 3770  F88CF3  08                       php                     ; save I flag
 3771  F88CF4  78                       sei                     ; disable interrupt
 3772  F88CF5  A0 00                    ldy     #0              ; buffer index
 3773  F88CF7                           
 3774  F88CF7                           INDEX16                 ; X,Y 16 bit - XH,YH cleared
 3775  F88CF7  C2 10                    rep     #PXFLAG
 3776                                   .LONGI  on
 3777                                   .MNLIST
 3778                           
 3779                                   ;lda    #$20                    ; /MW0 high
 3780                                   ;trb    VIA1+VIAPRB
  Tue Jul 17 11:00:15 2018                                                                                               Page   22




 3781                           
 3782  F88CF9                           ACC16
 3783  F88CF9  C2 20                    rep     #PMFLAG
 3784                                   .LONGA  on
 3785                                   .MNLIST
 3786                           ?02:    ;ACC16
 3787  F88CFB  B7 A0                    lda     [bufp],y        ; read data
 3788  F88CFD  9F AA FD 00              sta     >ATAPORT,x      ; latch data
 3789                                   ;ACC08
 3790  F88D01                           
 3791  F88D01  A9 00 00                 lda     #0                      ; /MW0 low
 3792  F88D04  0C 00 00                 tsb     !0
 3793  F88D07  A9 00 00                 lda     #0                      ; /MW0 low
 3794  F88D0A  0C 00 00                 tsb     !0
 3795  F88D0D  A9 00 00                 lda     #0                      ; /MW0 low
 3796  F88D10  0C 00 00                 tsb     !0
 3797                           
 3798  F88D13  9F A8 FD 00              sta     >ATADATA,x      ; send data low + latched data high     
 3799  F88D17  C8                       iny
 3800  F88D18  C8                       iny
 3801                                   ;lda    #$20                    ; /MW0 high
 3802                                   ;bit    $ff
 3803                                   ;bpl    ?04
 3804                                   ;tsb    VIA1+VIAPRB
 3805  F88D19                           
 3806                                   ;bit    drdyf           ; test DRDY bit in alternate status?
 3807                                   ;bpl    ?06             ; no
 3808                           ?04:    ;lda    >ATAALTST-1,x
 3809                                   ;bit    !ATAALTST,x
 3810  F88D19  BF AE FD 00              lda     >ATAALTST,x
 3811                                   ;bmi    ?04
 3812                                   ;bvc    ?04
 3813                                   ;asl    a
 3814                                   ;bpl    ?04             ; wait DRDY bit high
 3815                           
 3816  F88D1D  C0 00 02         ?06:    cpy     #$0200                  
 3817  F88D20  90 D9                    bcc     ?02             ; loop 512 bytes
 3818  F88D22                           ACC08
 3819  F88D22  E2 20                    sep     #PMFLAG
 3820                                   .LONGA  off
 3821                                   .MNLIST
 3822                                   ;lda    #$20                    ; /MW0 high
 3823                                   ;tsb    VIA1+VIAPRB
 3824  F88D24                           
 3825                           ; update bufp pointer after read/write data block
 3826  F88D24                   updp:
 3827                                   .LONGI  on
 3828                           
 3829  F88D24  A4 A1                    ldy     bufp+1          ; update bufp
 3830  F88D26  C8                       iny
 3831  F88D27  C8                       iny
 3832  F88D28  84 A1                    sty     bufp+1
 3833  F88D2A  24 9D                    bit     memfg           ; buffer in x-mem?
 3834  F88D2C  10 0F                    bpl     ?10             ; no, all done
 3835  F88D2E  A4 A0                    ldy     bufp
 3836  F88D30  C0 00 40                 cpy     #XMSTOP         ; still in x-mem window?
 3837  F88D33  90 08                    bcc     ?10             ; yes, all done
  Tue Jul 17 11:00:15 2018                                                                                               Page   23




 3838  F88D35  A0 00 20                 ldy     #XMSTART        ; restart at x-mem beginning window...
 3839  F88D38  84 A0                    sty     bufp
 3840  F88D3A  EE 28 FD                 inc     !PIA0+PIAPRA    ; ...and at next x-mem bank 
 3841  F88D3D                   ?10:    CPU08
 3842  F88D3D  E2 30                    sep     #(PMFLAG.OR.PXFLAG)
 3843                                   .LONGA  off
 3844                                   .LONGI  off
 3845                                   .MNLIST
 3846  F88D3F  28                       plp                     ; restore I flag
 3847  F88D40  60                       rts
 3848                           
 3849                           ; enable 8bit transfer
 3850  F88D41                   set8:
 3851  F88D41  A9 01                    lda     #$01
 3852  F88D43  80 02                    bra     setmode
 3853                           
 3854  F88D45                   set16:
 3855  F88D45  A9 81                    lda     #$81
 3856                           
 3857  F88D47                   setmode:
 3858  F88D47  48                       pha
 3859  F88D48  A6 94                    ldx     drive           ; ata device #
 3860  F88D4A  BF A0 91 F8              lda     >IFRTST,x
 3861  F88D4E  85 9A                    sta     ifrbit          ; save right IFR bit to test
 3862  F88D50  8A                       txa
 3863  F88D51  F0 02                    beq     ?02             ; offset of ata 0
 3864  F88D53  A2 10                    ldx     #ATAOFS         ; offset of ata 1
 3865  F88D55  9E AE FD         ?02:    stz     !ATACTRL,x      ; enable ata device to assert interrupt
 3866  F88D58  68                       pla
 3867  F88D59  9D A1 FD                 sta     !ATAFEAT,x
 3868  F88D5C  A5 9A                    lda     ifrbit  
 3869  F88D5E  8D CD FD                 sta     !VIA3+VIAIFR    ; clear CA1/CB1 flag in IFR
 3870  F88D61  A9 EF                    lda     #$EF            ; command
 3871  F88D63  9D A7 FD                 sta     !ATACMD,x       ; store command
 3872  F88D66  A5 9A                    lda     ifrbit
 3873  F88D68  78                       sei
 3874  F88D69  2C CD FD         ?10:    bit     !VIA3+VIAIFR
 3875  F88D6C  F0 FB                    beq     ?10
 3876  F88D6E  58                       cli
 3877  F88D6F  BD A7 FD                 lda     !ATAST,x
 3878  F88D72  BD A1 FD                 lda     !ATAERROR,x
 3879  F88D75  85 FF                    sta     $ff
 3880  F88D77  60                       rts
 3881                           
 3882                           ; send a command to ata device
 3883                           ; after sending a command will wait for interrupt
 3884                           ; in:   Y=command       
 3885                           ;       drive=0 or 1 (ata #0 or ata #1 device)
 3886                           ;       cmdfg<7>=flag load command block registers
 3887                           ;       lba[0..2]=24 bits starting lba (if need)
 3888                           ;       secnum=sector(s) count (if need)
 3889                           ; out:  X=offset ata address
 3890                           ;       irfbit=bit for test CA1/CB1 on VIA 1 (int. line for ata0/1)
 3891                           ;       seccnt=sector(s) count while read/write block
 3892                           ; use:  A,X,Y
 3893  F88D78                   sndcmd:
 3894  F88D78  A5 98                    lda     secnum
  Tue Jul 17 11:00:15 2018                                                                                               Page   24




 3895  F88D7A  85 99                    sta     seccnt          ; save sector(s) count #
 3896  F88D7C  A6 94                    ldx     drive           ; ata device #
 3897  F88D7E  BF A0 91 F8              lda     >IFRTST,x
 3898  F88D82  85 9A                    sta     ifrbit          ; save right IFR bit to test
 3899  F88D84  64 9E                    stz     drdyf
 3900  F88D86  34 0E                    bit     atadev,x        ; set drdy flag for C.F.
 3901  F88D88  50 04                    bvc     ?01
 3902  F88D8A  A9 80                    lda     #$80
 3903  F88D8C  85 9E                    sta     drdyf
 3904  F88D8E  8A               ?01:    txa
 3905  F88D8F  F0 02                    beq     ?01a            ; offset of ata 0
 3906  F88D91  A2 10                    ldx     #ATAOFS         ; offset of ata 1
 3907  F88D93                   ?01a:
 3908  F88D93  A9 40                    lda     #$40
 3909  F88D95  9F A6 FD 00              sta     >ATADEV,x
 3910                           
 3911                                   ;stz    !ATADEV,x
 3912  F88D99  EA                       nop
 3913  F88D9A  3C AE FD         ?01c:   bit     !ATAALTST,x     : wait device ready
 3914  F88D9D  30 FB                    bmi     ?01c
 3915  F88D9F  50 F9                    bvc     ?01c
 3916  F88DA1                           
 3917  F88DA1  A9 00                    lda     #0
 3918  F88DA3  9F AE FD 00              sta     >ATACTRL,x      ; enable ata device to assert interrupt
 3919  F88DA7                           
 3920                                   ;stz    !ATACTRL,x      ; enable ata device to assert interrupt
 3921  F88DA7  EA                       nop
 3922  F88DA8  24 9B                    bit     cmdfg
 3923  F88DAA  10 2B                    bpl     ?15
 3924  F88DAC                           
 3925                                   ;lda    #0              ; dev. reg. for command that not need params
 3926                                   ;sta    !ATADEV,x
 3927                                   ;bit    cmdfg
 3928                                   ;bpl    ?02a
 3929  F88DAC  A9 40            ?02:    lda     #$40            ; device 0 & lba is limited to 24 bits
 3930  F88DAE  9F A6 FD 00              sta     >ATADEV,x       ; store dev. register
 3931                                   ;nop
 3932                                   ;nop
 3933                                   ;nop
 3934                                   ;nop
 3935  F88DB2  3C AE FD         ?02a:   bit     !ATAALTST,x     : wait device ready
 3936  F88DB5  30 FB                    bmi     ?02a
 3937  F88DB7  50 F9                    bvc     ?02a
 3938                                   ;stz    !ATACTRL,x      ; enable ata device to assert interrupt
 3939                                   ;nop
 3940                                   ;nop
 3941                                   ;lda    #0              ; dev. reg. for command that not need params
 3942                                   ;bit    cmdfg
 3943                                   ;bpl    ?04
 3944                                   ;lda    #$E0            ; device 0 & lba is limited to 24 bits
 3945                                   ;lda    #$40
 3946                           ?04:    ;sta    >ATADEV,x       ; store dev. register
 3947                           ?06:    ;sta    >ATADEV,x
 3948                                   ;bit    !ATAALTST,x     ; wait device ready
 3949                                   ;bmi    ?06
 3950                                   ;bvc    ?06
 3951                                   ;bit    cmdfg           ; will load command block register's?
  Tue Jul 17 11:00:15 2018                                                                                               Page   25




 3952                                   ;bpl    ?16             ; no
 3953  F88DB9  A5 99                    lda     seccnt          ; store sectors count
 3954  F88DBB  9F A2 FD 00              sta     >ATASCTCNT,x
 3955                           ?08:    ;bit    !ATAALTST,x     ; wait device ready
 3956                                   ;bmi    ?08
 3957                                   ;bvc    ?08
 3958  F88DBF  A5 95                    lda     lba             ; store starting sector
 3959  F88DC1  9F A3 FD 00              sta     >ATALBAL,x
 3960                           ?10:    ;bit    !ATAALTST,x     ; wait device ready
 3961                                   ;bmi    ?10
 3962                                   ;bvc    ?10
 3963  F88DC5  A5 96                    lda     lba+1
 3964  F88DC7  9F A4 FD 00              sta     >ATALBAM,x
 3965                           ?12:    ;bit    !ATAALTST,x     ; wait device ready
 3966                                   ;bmi    ?12
 3967                                   ;bvc    ?12
 3968  F88DCB  A5 97                    lda     lba+2
 3969  F88DCD  9F A5 FD 00              sta     >ATALBAH,x
 3970                           ?14:    ;bit    !ATAALTST,x     ; wait device ready
 3971                                   ;bmi    ?14
 3972                                   ;bvc    ?14
 3973  F88DD1  A9 40                    lda     #$40
 3974  F88DD3  9F A6 FD 00              sta     >ATADEV,x       ; store dev. register
 3975  F88DD7  3C AE FD         ?15:    bit     !ATAALTST,x     ; wait device ready
 3976  F88DDA  30 FB                    bmi     ?15
 3977  F88DDC  50 F9                    bvc     ?15
 3978                           
 3979  F88DDE  A5 9A            ?16:    lda     ifrbit  
 3980  F88DE0  8D CD FD                 sta     !VIA3+VIAIFR    ; clear CA1/CB1 flag in IFR
 3981  F88DE3  98                       tya                     ; command
 3982  F88DE4  9D A7 FD                 sta     !ATACMD,x       ; store command
 3983  F88DE7  60                       rts
 3984                           
 3985                           ; set buffer pointer
 3986                           ; use: A,B,X
 3987  F88DE8                   setbuf:
 3988  F88DE8  A6 A5                    ldx     memp+2
 3989  F88DEA  24 9D                    bit     memfg           ; using x-mem?
 3990  F88DEC                           ACC16
 3991  F88DEC  C2 20                    rep     #PMFLAG
 3992                                   .LONGA  on
 3993                                   .MNLIST
 3994  F88DEE  10 26                    bpl     ?10             ; no, just set bufp=memp
 3995  F88DF0  A5 A6                    lda     xbuf            ; x-mem buffer #
 3996  F88DF2  0A                       asl     a               ; x16 -> B=x-mem bank
 3997  F88DF3  0A                       asl     a
 3998  F88DF4  0A                       asl     a
 3999  F88DF5  0A                       asl     a
 4000  F88DF6  EB                       xba                     ; 00xx,10xx,20xx,...,E0xx,F0xx
 4001  F88DF7  AA                       tax                     ; X=x-mem bank
 4002  F88DF8  86 A8                    stx     xbnk            ; save starting bank
 4003  F88DFA  8E 28 FD                 stx     PIA0+PIAPRA     ; set bank
 4004  F88DFD  29 00 F0                 and     #$F000          ; mask off
 4005  F88E00  4A                       lsr     a               ; 00xx,02xx,04xx,...,1Cxx,1Exx
 4006  F88E01  4A                       lsr     a
 4007  F88E02  4A                       lsr     a               ; 0000,0200,0400,...,1C00,1E00
 4008  F88E03  09 00 20                 ora     #XMSTART        ; point to starting buffer
  Tue Jul 17 11:00:15 2018                                                                                               Page   26




 4009  F88E06  85 A3                    sta     memp
 4010  F88E08  AE 0A FC                 ldx     CRXME           ; save x-mem setting
 4011  F88E0B  86 A9                    stx     xsave
 4012  F88E0D  8E 0B FC                 stx     CRXMEON         ; enable x-mem in window $012000 - $013FFF
 4013  F88E10  A2 01                    ldx     #XMBANK
 4014  F88E12  86 A5                    stx     memp+2
 4015  F88E14  80 02                    bra     ?20
 4016  F88E16  A5 A3            ?10:    lda     memp            ; set bufp=memp
 4017  F88E18  85 A0            ?20:    sta     bufp
 4018  F88E1A  86 A2                    stx     bufp+2
 4019  F88E1C                           ACC08
 4020  F88E1C  E2 20                    sep     #PMFLAG
 4021                                   .LONGA  off
 4022                                   .MNLIST
 4023  F88E1E  60                       rts
 4024                           
 4025                           ; software reset on ata device
 4026                           ; in:   X=offset ata address
 4027  F88E1F                   devres:
 4028  F88E1F  A9 04                    lda     #CTRLSRST       ; software reset control
 4029  F88E21  9D AE FD                 sta     !ATACTRL,x
 4030  F88E24  20 55 8E                 jsr     ?40             ; delay 16uS (need at least 5uS)
 4031  F88E27  9E AE FD                 stz     ATACTRL,x       ; stop software reset
 4032  F88E2A  20 3B 8E                 jsr     ?20             ; wait for 2.5ms
 4033  F88E2D  20 5E 8E                 jsr     wbusy           ; wait busy low
 4034  F88E30  30 05                    bmi     ?04             ; device not ready
 4035  F88E32  0A                       asl     a               ; N=DRDY status bit
 4036  F88E33  10 02                    bpl     ?04             ; device not ready
 4037  F88E35  18                       clc
 4038  F88E36  60                       rts
 4039  F88E37  A9 01            ?04:    lda     #ATA_NOTREADY
 4040  F88E39  38                       sec                     ; error
 4041  F88E3A  60                       rts
 4042                           
 4043  F88E3B  A9 20            ?20:    lda     #$20            ; timer 2.5mS
 4044  F88E3D  1C 0B FD                 trb     VIA0+VIAACR
 4045  F88E40  A9 0F                    lda     #<T2MS5
 4046  F88E42  8D 08 FD                 sta     VIA0+VIAT2CL
 4047  F88E45  A9 27                    lda     #>T2MS5
 4048  F88E47  8D 09 FD                 sta     VIA0+VIAT2CH
 4049  F88E4A                   ?22:    TASKSW  
 4050  F88E4A  02 00                    cop     FN_TASKSW
 4051  F88E4C  00                       .DB     $00
 4052                                   .MNLIST
 4053  F88E4D  A9 20                    lda     #T2IFRB
 4054  F88E4F  2C 0D FD                 bit     VIA0+VIAIFR
 4055  F88E52  F0 F6                    beq     ?22
 4056  F88E54  60                       rts
 4057                           
 4058  F88E55  A9 09            ?40:    lda     #9              ; 16uS delay
 4059  F88E57  3A               ?42:    dec     a
 4060  F88E58  D0 FD                    bne     ?42
 4061  F88E5A  EA                       nop
 4062  F88E5B  EA                       nop
 4063  F88E5C  EA                       nop
 4064  F88E5D  60                       rts
 4065                           
  Tue Jul 17 11:00:15 2018                                                                                               Page   27




 4066                           ; wait for status bit busy low within BUSYTMO timeout
 4067                           ; in:   X=ata # offset
 4068                           ;       NF=0 if status bit busy low
 4069                           ;       NF=1 if status bit busy high or if timeout
 4070                           ; use:  A
 4071  F88E5E                   wbusy:
 4072  F88E5E  A9 20                    lda     #$20            ; set T2 count PB6 pulse (1ms)
 4073  F88E60  0C 0B FD                 tsb     VIA0+VIAACR     
 4074  F88E63  A9 D0                    lda     #<BUSYTMO       ; timeout status bit busy
 4075  F88E65  8D 08 FD                 sta     !VIA0+VIAT2CL
 4076  F88E68  A9 07                    lda     #>BUSYTMO
 4077  F88E6A  8D 09 FD                 sta     !VIA0+VIAT2CH
 4078  F88E6D  BD A7 FD         ?10:    lda     !ATAST,x        ; read status
 4079  F88E70  10 0D                    bpl     ?20             ; OK - busy -> L, return NF = 0
 4080  F88E72                           TASKSW                  ; switch task while wait
 4081  F88E72  02 00                    cop     FN_TASKSW
 4082  F88E74  00                       .DB     $00
 4083                                   .MNLIST
 4084  F88E75  A9 20                    lda     #T2IFRB
 4085  F88E77  2C 0D FD                 bit     VIA0+VIAIFR     ; test timeout
 4086  F88E7A  F0 F1                    beq     ?10             ; loop
 4087  F88E7C  BD A7 FD                 lda     !ATAST,x        ; read status - return NF = busy bit
 4088  F88E7F  60               ?20:    rts
 4089                           
 4090                           ; get device identification data
 4091                           ; in:   drive
 4092                           ; out:  CF=1 if error, A=error code
 4093  F88E80                   ident:
 4094  F88E80  A6 94                    ldx     drive
 4095  F88E82  B5 0E                    lda     atadev,x
 4096  F88E84  29 DF                    and     #11011111B
 4097  F88E86  95 0E                    sta     atadev,x
 4098  F88E88  29 9F                    and     #10011111B
 4099  F88E8A  85 B6                    sta     tmpy            ; hard disk flag
 4100  F88E8C  8A                       txa
 4101  F88E8D  0A                       asl     a
 4102  F88E8E  0A                       asl     a
 4103  F88E8F  AA                       tax
 4104  F88E90  86 B0                    stx     wtmp            ; index for atasec var. access
 4105  F88E92                           ACC16
 4106  F88E92  C2 20                    rep     #PMFLAG
 4107                                   .LONGA  on
 4108                                   .MNLIST
 4109  F88E94  74 12                    stz     atasec,x        ; clear atasec var.
 4110  F88E96  74 14                    stz     atasec+2,x
 4111  F88E98                           ACC08
 4112  F88E98  E2 20                    sep     #PMFLAG
 4113                                   .LONGA  off
 4114                                   .MNLIST
 4115  F88E9A  20 F0 8A                 jsr     getid
 4116  F88E9D  B0 6E                    bcs     ?10             ; error
 4117  F88E9F  A0 00                    ldy     #0
 4118  F88EA1  98                       tya
 4119  F88EA2                           INDEX16
 4120  F88EA2  C2 10                    rep     #PXFLAG
 4121                                   .LONGI  on
 4122                                   .MNLIST
  Tue Jul 17 11:00:15 2018                                                                                               Page   28




 4123  F88EA4  18               ?02:    clc                     ; loop checksum computation
 4124  F88EA5  77 A3                    adc     [memp],y
 4125  F88EA7  C8                       iny
 4126  F88EA8  C0 00 02                 cpy     #$200
 4127  F88EAB  90 F7                    bcc     ?02
 4128  F88EAD  EB                       xba                     ; B = checksum
 4129  F88EAE  88                       dey
 4130  F88EAF  88                       dey
 4131  F88EB0  B7 A3                    lda     [memp],y
 4132  F88EB2  C9 A5                    cmp     #$A5            ; valid signature checksum?
 4133  F88EB4                           INDEX08
 4134  F88EB4  E2 10                    sep     #PXFLAG
 4135                                   .LONGI  off
 4136                                   .MNLIST
 4137  F88EB6  D0 03                    bne     ?04             ; no -- assume data ok
 4138  F88EB8  EB                       xba                     ; checksum vill be zero
 4139  F88EB9  D0 53                    bne     ?15             ; wrong checksum
 4140  F88EBB  A0 14            ?04:    ldy     #10*2           ; offset 'serial number' string
 4141  F88EBD  A2 0A                    ldx     #10             ; words length
 4142  F88EBF  20 12 8F                 jsr     ?50             ; adjust string
 4143  F88EC2  A0 2E                    ldy     #23*2           ; offset 'firmware revision' string
 4144  F88EC4  A2 04                    ldx     #4              ; words length
 4145  F88EC6  20 12 8F                 jsr     ?50             ; adjust string
 4146  F88EC9  A0 36                    ldy     #27*2           ; offset 'model name' string
 4147  F88ECB  A2 14                    ldx     #20             ; words length
 4148  F88ECD  20 12 8F                 jsr     ?50             ; adjust string
 4149  F88ED0  A2 14                    ldx     #10*2           ; pointer to 'serial number' string
 4150  F88ED2  A0 27                    ldy     #(10*2)+(10*2)-1        ; pointer to end of string
 4151  F88ED4  20 21 8F                 jsr     ?60             ; terminate string
 4152  F88ED7  A2 36                    ldx     #27*2           ; pointer to 'model name' string
 4153  F88ED9  A0 5D                    ldy     #(27*2)+(20*2)-1        ; pointer to end of string
 4154  F88EDB  20 21 8F                 jsr     ?60             ; terminate string
 4155  F88EDE  A0 78                    ldy     #60*2           ; word 60/61: total sector's count #
 4156  F88EE0  A6 B0                    ldx     wtmp
 4157  F88EE2                           ACC16
 4158  F88EE2  C2 20                    rep     #PMFLAG
 4159                                   .LONGA  on
 4160                                   .MNLIST
 4161  F88EE4  B7 A3                    lda     [memp],y
 4162  F88EE6  85 AA                    sta     nlba
 4163  F88EE8  95 12                    sta     atasec,x        ; store max. user sectors
 4164  F88EEA  C8                       iny
 4165  F88EEB  C8                       iny
 4166  F88EEC  B7 A3                    lda     [memp],y
 4167  F88EEE  85 AC                    sta     nlba+2
 4168  F88EF0  95 14                    sta     atasec+2,x
 4169  F88EF2  A7 A3                    lda     [memp]          ; C.F. identification
 4170  F88EF4  A6 94                    ldx     drive
 4171  F88EF6  A4 B6                    ldy     tmpy            ; hard disk flag
 4172  F88EF8  C9 8A 84                 cmp     #$848A          ; classic word 0 for C.F.
 4173  F88EFB  F0 07                    beq     ?06             ; is C.F.
 4174  F88EFD  C9 4A 04                 cmp     #$044A          ; alternate word 0 for CF
 4175  F88F00  F0 02                    beq     ?06             ; is C.F.
 4176  F88F02  94 0E                    sty     atadev,x        ; is H.D.
 4177  F88F04                   ?06:    ACC08
 4178  F88F04  E2 20                    sep     #PMFLAG
 4179                                   .LONGA  off
  Tue Jul 17 11:00:15 2018                                                                                               Page   29




 4180                                   .MNLIST
 4181  F88F06  B5 0E                    lda     atadev,x
 4182  F88F08  09 20                    ora     #$20            ; flag identify ok
 4183  F88F0A  95 0E                    sta     atadev,x
 4184  F88F0C  18                       clc                     ; no error
 4185  F88F0D  60               ?10:    rts
 4186  F88F0E  A9 07            ?15:    lda     #ATA_IDCKS      ; checksum error
 4187  F88F10  38                       sec
 4188  F88F11  60                       rts
 4189                           
 4190                                   ; swap low byte with high byte in string
 4191                                   ; Y = string offset
 4192                                   ; X = words string length
 4193  F88F12                   ?50:    ACC16
 4194  F88F12  C2 20                    rep     #PMFLAG
 4195                                   .LONGA  on
 4196                                   .MNLIST
 4197  F88F14  B7 A3            ?52:    lda     [memp],y
 4198  F88F16  EB                       xba
 4199  F88F17  97 A3                    sta     [memp],y
 4200  F88F19  C8                       iny
 4201  F88F1A  C8                       iny
 4202  F88F1B  CA                       dex
 4203  F88F1C  D0 F6                    bne     ?52
 4204  F88F1E                           ACC08
 4205  F88F1E  E2 20                    sep     #PMFLAG
 4206                                   .LONGA  off
 4207                                   .MNLIST
 4208  F88F20  60                       rts
 4209                           
 4210                                   ; terminate serial string and model string with null
 4211                                   ; Y=end of string
 4212                                   ; X=start of string
 4213  F88F21  86 AE            ?60:    stx     tmp     
 4214  F88F23  B7 A3            ?62:    lda     [memp],y
 4215  F88F25  C9 20                    cmp     #' '
 4216  F88F27  D0 05                    bne     ?64
 4217  F88F29  88                       dey
 4218  F88F2A  C4 AE                    cpy     tmp
 4219  F88F2C  B0 F5                    bcs     ?62
 4220  F88F2E  C8               ?64:    iny
 4221  F88F2F  A9 00                    lda     #0
 4222  F88F31  97 A3                    sta     [memp],y
 4223  F88F33  60                       rts
 4224                           
 4225                           ;--------------------------------------------------------------------------
 4226                           ; init routines
 4227                           ;---------------------------------------------------------------------------
 4228                           
 4229                                   .LONGA  off
 4230                                   .LONGI  off
 4231                           
 4232                           ; check & init ata devices
 4233  F88F34                   initata:
 4234                                   .PUBLIC initata
 4235                           
 4236  F88F34                           ACC16
  Tue Jul 17 11:00:15 2018                                                                                               Page   30




 4237  F88F34  C2 20                    rep     #PMFLAG
 4238                                   .LONGA  on
 4239                                   .MNLIST
 4240  F88F36  A9 00 88                 lda     #!MBR0ATA       ; clear ident, MBR & PBR data mem
 4241  F88F39  85 A0                    sta     bufp
 4242  F88F3B  A2 01                    ldx     #^MBR0ATA
 4243  F88F3D  86 A2                    stx     bufp+2
 4244  F88F3F  A0 00                    ldy     #0
 4245  F88F41                           INDEX16
 4246  F88F41  C2 10                    rep     #PXFLAG
 4247                                   .LONGI  on
 4248                                   .MNLIST
 4249  F88F43  98                       tya                     ; clear A
 4250  F88F44  97 A0            ?02:    sta     [bufp],y
 4251  F88F46  C8                       iny
 4252  F88F47  C8                       iny
 4253  F88F48  C0 00 0C                 cpy     #$0C00
 4254  F88F4B  90 F7                    bcc     ?02
 4255  F88F4D                           CPU08
 4256  F88F4D  E2 30                    sep     #(PMFLAG.OR.PXFLAG)
 4257                                   .LONGA  off
 4258                                   .LONGI  off
 4259                                   .MNLIST
 4260  F88F4F  AA                       tax                     ; device #0
 4261  F88F50  20 5F 8F                 jsr     ?04
 4262  F88F53                           TASKSW
 4263  F88F53  02 00                    cop     FN_TASKSW
 4264  F88F55  00                       .DB     $00
 4265                                   .MNLIST
 4266  F88F56  A2 01                    ldx     #1              ; device #1
 4267  F88F58  20 5F 8F                 jsr     ?04
 4268  F88F5B                           TASKSW
 4269  F88F5B  02 00                    cop     FN_TASKSW
 4270  F88F5D  00                       .DB     $00
 4271                                   .MNLIST
 4272  F88F5E  60                       rts
 4273                           
 4274                           ; check devices on bus ata
 4275                           ; in:   X=device ata #
 4276  F88F5F  86 94            ?04:    stx     drive
 4277  F88F61  74 0E                    stz     atadev,x        ; clear device flag
 4278  F88F63  8A                       txa
 4279  F88F64  F0 02                    beq     ?06             ; offset of ata #0=0
 4280  F88F66  A2 10                    ldx     #ATAOFS
 4281  F88F68  86 AF            ?06:    stx     ataofs
 4282  F88F6A  20 3C 90                 jsr     ?60             ; print start msg
 4283  F88F6D  A6 AF                    ldx     ataofs
 4284  F88F6F  20 5E 8E                 jsr     wbusy           ; wait for busy flag low
 4285  F88F72  30 1B                    bmi     ?10             ; assume no device on ata #0
 4286  F88F74  20 D3 8F                 jsr     ?30             ; check device signature
 4287  F88F77                           
 4288  F88F77  A9 00                    lda     #$00
 4289  F88F79  9D A6 FD                 sta     !ATADEV,x       ; store dev. register
 4290                           
 4291  F88F7C  B0 1B                    bcs     ?15             ; not found or not HD/CF
 4292  F88F7E                           
 4293          [01]                     .IFDEF  MODE8
  Tue Jul 17 11:00:15 2018                                                                                               Page   31




 4294                                   jsr     set8
 4295          [00]                     .ENDIF
 4296  F88F7E                           
 4297  F88F7E  20 80 8E                 jsr     ident           ; identify device
 4298  F88F81  B0 44                    bcs     ?25             ; error (A=error code)
 4299  F88F83  24 55                    bit     BiosEnt
 4300  F88F85  50 03                    bvc     ?08             ; skip
 4301  F88F87  20 FD 8F                 jsr     ?50             ; print identification data
 4302  F88F8A  20 1F 8E         ?08:    jsr     devres  
 4303                                   ;jsr    chkmbr          ; load&check MBR        
 4304  F88F8D  18                       clc                     ; no error      
 4305  F88F8E  60                       rts
 4306                           
 4307  F88F8F  20 B3 8F         ?10:    jsr     ?20             ; print 'device not found'
 4308  F88F92                           SCNPRINT
 4309  F88F92  02 01                    cop     $01
 4310                                   .MNLIST
 4311  F88F94  2E 0D 00                 .DB     '.', 13, 0
 4312  F88F97  38                       sec
 4313  F88F98  60                       rts
 4314                           
 4315  F88F99  20 B3 8F         ?15:    jsr     ?20             ; print 'device not found'
 4316  F88F9C                           SCNPRINT
 4317  F88F9C  02 01                    cop     $01
 4318                                   .MNLIST
 4319  F88F9E  20 6F 72 20 6E           .DB     ' or not H.D./C.F.', 13, 0
               6F 74 20 48 2E 
               44 2E 2F 43 2E 
               46 2E 0D 00 
 4320  F88FB1  38                       sec
 4321  F88FB2  60                       rts
 4322                           
 4323  F88FB3                   ?20:    SCNPRINT
 4324  F88FB3  02 01                    cop     $01
 4325                                   .MNLIST
 4326  F88FB5  64 65 76 69 63           .DB     'device not found', $00
               65 20 6E 6F 74 
               20 66 6F 75 6E 
               64 00 
 4327  F88FC6  60                       rts
 4328                           
 4329                           ?25:    ; fail to identify device
 4330  F88FC7  48                       pha                     ; error code
 4331  F88FC8  4B                       phk
 4332  F88FC9  F4 B4 91                 pea     #!STR2
 4333  F88FCC  A9 05                    lda     #5
 4334  F88FCE  48                       pha
 4335  F88FCF                           BPRINTF
 4336  F88FCF  02 11                    cop     $11
 4337                                   .MNLIST
 4338  F88FD1  38                       sec
 4339  F88FD2  60                       rts
 4340                           
 4341                           ; check device signature after reset
 4342                           ; in:   drive=ata #
 4343                           ;       ataofs=ata # offset
 4344                           ; out:  CF=0 if found device
  Tue Jul 17 11:00:15 2018                                                                                               Page   32




 4345                           ;       CF=1 if not device or not HD/CF
 4346  F88FD3  A4 AF            ?30:    ldy     ataofs
 4347  F88FD5  A2 03                    ldx     #3              ; test signature device HD/CF
 4348  F88FD7  BF A2 91 F8      ?34:    lda     >ATASGN,x
 4349  F88FDB  D9 A2 FD                 cmp     !ATASCTCNT,y    ; test signature
 4350  F88FDE  D0 1B                    bne     ?36             ; no HD/CF
 4351  F88FE0  C8                       iny
 4352  F88FE1  CA                       dex
 4353  F88FE2  10 F3                    bpl     ?34
 4354  F88FE4  B9 A2 FD                 lda     !ATASCTCNT,y    ; device #
 4355  F88FE7  29 10                    and     #$10            ; mask dev bit
 4356  F88FE9  D0 10                    bne     ?36             ; will be 0
 4357  F88FEB  C8                       iny
 4358  F88FEC  B9 A2 FD                 lda     !ATASCTCNT,y    ; status reg.
 4359  F88FEF  29 40                    and     #ATADRDY        ; DRDY bit will be set
 4360  F88FF1  F0 08                    beq     ?36             ; device not found or not HD/CF
 4361  F88FF3  A9 C0                    lda     #$C0            ; flag device
 4362  F88FF5  A6 94                    ldx     drive           ; for now force C.F type
 4363  F88FF7  95 0E                    sta     atadev,x        ; found device on ata # 
 4364  F88FF9  18                       clc
 4365  F88FFA  60                       rts
 4366  F88FFB  38               ?36:    sec
 4367  F88FFC  60                       rts
 4368                           
 4369                           ?50:    ; print identification string
 4370  F88FFD  A6 94                    ldx     drive
 4371  F88FFF  34 0E                    bit     atadev,x
 4372  F89001                           ACC16CLC
 4373  F89001  C2 21                    rep     #(PMFLAG.OR.PCFLAG)
 4374                                   .LONGA  on
 4375                                   .MNLIST
 4376  F89003  A9 DA 91                 lda     #!STR3
 4377  F89006  50 03                    bvc     ?51
 4378  F89008  A9 E8 91                 lda     #!STR4
 4379  F8900B  85 B0            ?51:    sta     wtmp            ; H.D or C.F string
 4380  F8900D  A9 36 00                 lda     #27*2
 4381  F89010  65 A3                    adc     memp
 4382  F89012  85 A0                    sta     bufp            ; model name string
 4383  F89014  A5 AA                    lda     nlba
 4384  F89016  85 95                    sta     lba
 4385  F89018  A5 AC                    lda     nlba+2
 4386  F8901A  A2 0B                    ldx     #11             ; divide by 2048 (11 shift)...
 4387  F8901C  4A               ?52:    lsr     a               ; ... and get rounded size in Mb
 4388  F8901D  66 95                    ror     lba
 4389  F8901F  CA                       dex
 4390  F89020  D0 FA                    bne     ?52
 4391  F89022  85 97                    sta     lba+2
 4392  F89024  48                       pha                     ; 2
 4393  F89025  A5 95                    lda     lba
 4394  F89027  48                       pha                     ; 2
 4395  F89028                           ACC08
 4396  F89028  E2 20                    sep     #PMFLAG
 4397                                   .LONGA  off
 4398                                   .MNLIST
 4399  F8902A  A5 A5                    lda     memp+2
 4400  F8902C  48                       pha                     ; 1
 4401  F8902D  D4 A0                    pei     (bufp)          ; 2
  Tue Jul 17 11:00:15 2018                                                                                               Page   33




 4402  F8902F  4B                       phk                     ; 1
 4403  F89030  D4 B0                    pei     (wtmp)          ; 2
 4404  F89032  4B                       phk                     ; 1
 4405  F89033  F4 F6 91                 pea     #!STRF1         ; 2
 4406  F89036  A9 0E                    lda     #14             ; 1
 4407  F89038  48                       pha
 4408  F89039                           BPRINTF
 4409  F89039  02 11                    cop     $11
 4410                                   .MNLIST
 4411  F8903B  60                       rts
 4412                           
 4413                           ; print check message at boot
 4414                           ; in:   drive=ata # device
 4415  F8903C  24 55            ?60:    bit     BiosEnt
 4416  F8903E  50 0C                    bvc     ?62             ; skip
 4417  F89040  A6 94                    ldx     drive
 4418  F89042  DA                       phx
 4419  F89043  4B                       phk
 4420  F89044  F4 A6 91                 pea     #!STR1
 4421  F89047  A9 05                    lda     #5
 4422  F89049  48                       pha
 4423  F8904A                           BPRINTF
 4424  F8904A  02 11                    cop     $11
 4425                                   .MNLIST
 4426  F8904C  60               ?62:    rts
 4427                           
 4428                           ; long version
 4429  F8904D                   lchkmbr:
 4430                                   .PUBLIC lchkmbr
 4431                           
 4432  F8904D  8B                       phb
 4433  F8904E  0B                       phd
 4434  F8904F  F4 00 00                 pea     #0
 4435  F89052  2B                       pld
 4436  F89053  A9 00                    lda     #0
 4437  F89055  48                       pha
 4438  F89056  AB                       plb
 4439  F89057  86 94                    stx     drive
 4440  F89059  20 70 90                 jsr     chkmbr
 4441  F8905C  2B                       pld
 4442  F8905D  AB                       plb
 4443  F8905E  6B                       rtl
 4444                           
 4445                           ; check mbr for usb flash disk
 4446  F8905F                   chkumbr:
 4447                                   .PUBLIC chkumbr
 4448                           
 4449  F8905F  86 94                    stx     drive
 4450  F89061                           ACC16                   ; set pointer for MBR
 4451  F89061  C2 20                    rep     #PMFLAG
 4452                                   .LONGA  on
 4453                                   .MNLIST
 4454  F89063  A9 00 94                 lda     #MBR0USB
 4455  F89066  85 A3                    sta     memp
 4456  F89068                           ACC08
 4457  F89068  E2 20                    sep     #PMFLAG
 4458                                   .LONGA  off
  Tue Jul 17 11:00:15 2018                                                                                               Page   34




 4459                                   .MNLIST
 4460  F8906A  A9 01                    lda     #^MBR0USB
 4461  F8906C  85 A5                    sta     memp+2
 4462  F8906E  80 06                    bra     chkmbr2
 4463                           
 4464                           ; load & check MBR on device
 4465                           ; in:   drive
 4466                           ; out:  CF=1 if error, A=error code
 4467  F89070                   chkmbr:
 4468  F89070  20 95 8A                 jsr     getmbr          ; load MBR
 4469  F89073  90 01                    bcc     chkmbr2         
 4470  F89075  60                       rts                     ; error
 4471  F89076                           
 4472                           ; entry point for usb flash disk
 4473  F89076                   chkmbr2:
 4474  F89076  A9 10                    lda     #$10            ; set bit mbr loaded
 4475  F89078  85 AE                    sta     tmp
 4476  F8907A                           CPU16
 4477  F8907A  C2 30                    rep     #(PMFLAG.OR.PXFLAG)
 4478                                   .LONGA  on
 4479                                   .LONGI  on
 4480                                   .MNLIST
 4481  F8907C  A0 FE 01                 ldy     #$01FE          ; signature pointer
 4482  F8907F  B7 A3                    lda     [memp],y
 4483  F89081  85 B2                    sta     mbrsgn          ; mbr signature
 4484  F89083  A0 C2 01                 ldy     #$01C2          ; partition type pointer
 4485  F89086  B7 A3                    lda     [memp],y
 4486  F89088  85 B0                    sta     wtmp            ; partition type
 4487  F8908A  A0 C6 01                 ldy     #$01C6          ; partition start pointer
 4488  F8908D  B7 A3                    lda     [memp],y
 4489  F8908F  85 AA                    sta     nlba            ; partition start
 4490  F89091  C8                       iny
 4491  F89092  C8                       iny
 4492  F89093  B7 A3                    lda     [memp],y
 4493  F89095  85 AC                    sta     nlba+2
 4494  F89097  A0 BE 01                 ldy     #$01BE          ; partition flag pointer
 4495  F8909A  B7 A3                    lda     [memp],y
 4496  F8909C  85 B4                    sta     mbrfg           ; partition flag
 4497  F8909E  A5 B2                    lda     mbrsgn
 4498  F890A0  C9 55 AA                 cmp     #$AA55
 4499  F890A3                           CPU08
 4500  F890A3  E2 30                    sep     #(PMFLAG.OR.PXFLAG)
 4501                                   .LONGA  off
 4502                                   .LONGI  off
 4503                                   .MNLIST
 4504  F890A5  D0 49                    bne     ?20             ; invalid mbr signature
 4505  F890A7  A9 18                    lda     #$18            ; add valid mbr signature flag
 4506  F890A9  85 AE                    sta     tmp
 4507  F890AB  A5 B4                    lda     mbrfg
 4508  F890AD  F0 02                    beq     ?vv
 4509  F890AF  10 3F                    bpl     ?20             ; first partition invalid       
 4510  F890B1  A9 1C            ?vv:    lda     #$1C            ; add active partition flag
 4511  F890B3  85 AE                    sta     tmp
 4512  F890B5  A5 94                    lda     drive
 4513  F890B7  0A                       asl     a
 4514  F890B8  0A                       asl     a
 4515  F890B9  AA                       tax                     ; index for access to atambr var
  Tue Jul 17 11:00:15 2018                                                                                               Page   35




 4516  F890BA  A5 B0                    lda     wtmp            ; partition type
 4517  F890BC  A8                       tay
 4518  F890BD  95 25                    sta     atambr+3,x      ; store partition type
 4519  F890BF  A5 AC                    lda     nlba+2          ; store partition start
 4520  F890C1  95 24                    sta     atambr+2,x
 4521  F890C3  A5 AB                    lda     nlba+1
 4522  F890C5  95 23                    sta     atambr+1,x
 4523  F890C7  A5 AA                    lda     nlba
 4524  F890C9  95 22                    sta     atambr,x
 4525  F890CB  A5 AD                    lda     nlba+3          ; must be 0
 4526  F890CD  D0 21                    bne     ?20
 4527  F890CF  C0 06                    cpy     #$06            ; just FAT16 type
 4528  F890D1  F0 08                    beq     ?10
 4529  F890D3  C0 04                    cpy     #$04            ; FAT 16 for disk less than 32Mb
 4530  F890D5  F0 04                    beq     ?10
 4531  F890D7  C0 0E                    cpy     #$0E
 4532  F890D9  D0 15                    bne     ?20
 4533  F890DB                   ?10:    CPU16
 4534  F890DB  C2 30                    rep     #(PMFLAG.OR.PXFLAG)
 4535                                   .LONGA  on
 4536                                   .LONGI  on
 4537                                   .MNLIST
 4538  F890DD  A0 CA 01                 ldy     #$01CA          ; partition sec's count pointer
 4539  F890E0  B7 A3                    lda     [memp],y
 4540  F890E2  95 32                    sta     ataprt,x
 4541  F890E4  C8                       iny
 4542  F890E5  C8                       iny
 4543  F890E6  B7 A3                    lda     [memp],y
 4544  F890E8  95 34                    sta     ataprt+2,x
 4545  F890EA                           CPU08
 4546  F890EA  E2 30                    sep     #(PMFLAG.OR.PXFLAG)
 4547                                   .LONGA  off
 4548                                   .LONGI  off
 4549                                   .MNLIST
 4550  F890EC  A9 1D                    lda     #$1D            ; add valid partition type
 4551  F890EE  85 AE                    sta     tmp
 4552  F890F0  A6 94            ?20:    ldx     drive           ; update device flag
 4553  F890F2  B5 0E                    lda     atadev,x
 4554  F890F4  05 AE                    ora     tmp
 4555  F890F6  95 0E                    sta     atadev,x
 4556  F890F8  18                       clc
 4557  F890F9  60               ?30:    rts
 4558                           
 4559                           ; dma setup for a transfer cycle on channel 1/2
 4560                           ; in:   drive = 0 or 1 (ata #0 or ata #1 device)
 4561                           ;       ataop = ata operation flag: <7>=0->read, 1->write
 4562                           ;       ncnt = words count - 1 #
 4563                           ;       xbuf = dma buffer # ($0000..$07FF)
 4564  F890FA                   dmaset:
 4565                                   ; dma buffer is organized in 8 x 128Kb banks or 8 x 64Kw banks
 4566                                   ; PB0..PB2 of VIA3 set MA16..MA18 lines of 512Kw ram (DMA access)
 4567                                   ;
 4568  F890FA  AF 88 FD 00              lda     >DMA0SR         ; clear status flag
 4569  F890FE  8F 8D FD 00              sta     >DMA0WMCLR
 4570  F89102                           
 4571  F89102  A9 00                    lda     #$00
 4572  F89104  8F 88 FD 00              sta     >DMA0WCMD
  Tue Jul 17 11:00:15 2018                                                                                               Page   36




 4573  F89108                           
 4574  F89108  AD C0 FD                 lda     !VIA3+VIAPRB    ; set bank
 4575  F8910B  29 E8                    and     #11101000B      ; mask off 3 lower's bits, clear PB4 (ata 0)   
 4576  F8910D  05 A7                    ora     xbuf+1          ; high byte of buffer # select the bank
 4577  F8910F  09 20                    ora     #00100000B      ; set /FDC line high (ata dma access)
 4578  F89111  A6 94                    ldx     drive
 4579  F89113  F0 02                    beq     ?via            ; select ata 0
 4580  F89115  09 10                    ora     #00010000B      ; select ata 1 (PB4 high)
 4581  F89117  8D C0 FD         ?via:   sta     !VIA3+VIAPRB    ; set bank & ata #
 4582  F8911A  BF 9A 91 F8              lda     >DMACHNL,x
 4583  F8911E  85 B0                    sta     wtmp            ; dma channel
 4584  F89120  09 04                    ora     #$04
 4585  F89122  8F 8A FD 00              sta     >DMA0WMSKB      ; mask off bit channel 1/2
 4586  F89126  BF 9C 91 F8              lda     >DMAREQB,x
 4587  F8912A  85 B7                    sta     dmareq
 4588  F8912C  A9 04                    lda     #WRITETRASF
 4589  F8912E  24 9C                    bit     ataop
 4590  F89130  10 02                    bpl     ?set            ; read: dma read ata port and write buffer
 4591  F89132  A9 08                    lda     #READTRASF      ; write: dma read buffer and write to ata
 4592  F89134  05 B0            ?set:   ora     wtmp            ; channel -  A=transfer mode
 4593  F89136  8F 8B FD 00              sta     >DMA0MODE       ; set DMA transfer mode
 4594                                   ;lda    xbuf            ; high address
 4595  F8913A  9B                       txy
 4596  F8913B  8F 8C FD 00              sta     >DMA0WCLRFF     ; clear F/F
 4597  F8913F  D0 1F                    bne     ?chn2           ; set channel 2
 4598  F89141                           
 4599                                   ; set channel 1
 4600  F89141  A9 00                    lda     #0
 4601  F89143  8F 82 FD 00              sta     >DMAC0+DMAADDR1 ; store low buffer address
 4602  F89147  A5 A6                    lda     xbuf            ; high address
 4603  F89149  8F 82 FD 00              sta     >DMAC0+DMAADDR1 ; store high buffer address
 4604  F8914D  EA                       nop
 4605  F8914E  8F 8C FD 00              sta     >DMA0WCLRFF     ; clear F/F
 4606  F89152  A5 AC                    lda     ncnt            ; low count
 4607  F89154  8F 83 FD 00              sta     >DMAC0+DMACNT1  ; store low count
 4608  F89158  A5 AD                    lda     ncnt+1          ; high count
 4609  F8915A  8F 83 FD 00              sta     >DMAC0+DMACNT1  ; store high count
 4610  F8915E  80 1D                    bra     ?cnt
 4611  F89160                           
 4612                                   ; set channel 2
 4613  F89160  A9 00            ?chn2:  lda     #0
 4614  F89162  8F 84 FD 00              sta     >DMAC0+DMAADDR2 ; store low buffer address
 4615  F89166  A5 A6                    lda     xbuf            ; high address
 4616  F89168  8F 84 FD 00              sta     >DMAC0+DMAADDR2 ; store high buffer address
 4617  F8916C  EA                       nop
 4618  F8916D  8F 8C FD 00              sta     >DMA0WCLRFF     ; clear F/F
 4619  F89171  A5 AC                    lda     ncnt            ; low count
 4620  F89173  8F 85 FD 00              sta     >DMAC0+DMACNT2  ; store low count
 4621  F89177  A5 AD                    lda     ncnt+1          ; high count
 4622  F89179  8F 85 FD 00              sta     >DMAC0+DMACNT2  ; store high count
 4623  F8917D  8F 8C FD 00      ?cnt:   sta     >DMA0WCLRFF     ; clear F/F     
 4624  F89181  A5 B0                    lda     wtmp
 4625  F89183  8F 8A FD 00              sta     >DMA0WMSKB      ; un-mask bit channel 1/2
 4626  F89187  A9 04                    lda     #00000100B      ; VIA0 PA3 set dma direction
 4627  F89189  24 9C                    bit     ataop
 4628  F8918B  30 04                    bmi     ?dir            ; clear direction (write to ata)
 4629  F8918D  0C 0F FD                 tsb     VIA0+VIAPRANH   ; set direction (write to mem)
  Tue Jul 17 11:00:15 2018                                                                                               Page   37




 4630  F89190  60                       rts
 4631  F89191  1C 0F FD         ?dir:   trb     VIA0+VIAPRANH   ; clear direction
 4632  F89194  60                       rts
 4633  F89195                           
 4634                           ;--------------------------------------------------------------------------
 4635                           ; tables
 4636                           ;---------------------------------------------------------------------------
 4637                           
 4638                           ; operation flag (read, verify, write)
 4639  F89195                   OPTAB:
 4640  F89195  00 40 80                 .DB     $00, $40, $80
 4641                           
 4642                           ; dma operations: read, write
 4643  F89198                   OPTAB2:
 4644  F89198  00 80                    .DB     $00, $80
 4645                           
 4646                           ; dma channel related to drive #
 4647  F8919A                   DMACHNL:
 4648  F8919A  01 02                    .DB     $01, $02
 4649                           
 4650                           ; dma channel request bit related to drive #
 4651  F8919C                   DMAREQB:
 4652  F8919C  20 40                    .DB     $20, $40
 4653                           
 4654                           ; DMAREQ bit (PA7, PA6)
 4655  F8919E                   DMAREQ:
 4656  F8919E  80 40                    .DB     $80, $40
 4657                           
 4658                           ; for test VIA1 IFR (interrupt from ata device)
 4659  F891A0                   IFRTST:
 4660  F891A0  02 01                    .DB     CA1IFRB, CA2IFRB
 4661                           
 4662                           ; HD/CF signature (in reverse order)    
 4663  F891A2                   ATASGN:
 4664  F891A2  00 00 01 01              .DB     $00, $00, $01, $01
 4665                           
 4666  F891A6                   STR1:
 4667  F891A6  61 74 61 20 20           .DB     'ata   #%bu...', 0
               20 23 25 62 75 
               2E 2E 2E 00 
 4668                           
 4669  F891B4                   STR2:
 4670  F891B4  66 61 69 6C 20           .DB     'fail to identify device (error %bu).', 13, 0
               74 6F 20 69 64 
               65 6E 74 69 66 
               79 20 64 65 76 
               69 63 65 20 28 
               65 72 72 6F 72 
               20 25 62 75 29 
               2E 0D 00 
 4671                           
 4672  F891DA                   STR3:
 4673  F891DA  48 61 72 64 20           .DB     'Hard Disk    ', 0
               44 69 73 6B 20 
               20 20 20 00 
 4674                           
 4675  F891E8                   STR4:
  Tue Jul 17 11:00:15 2018                                                                                               Page   38




 4676  F891E8  43 6F 6D 70 61           .DB     'Compact Flash', 0
               63 74 20 46 6C 
               61 73 68 00 
 4677  F891F6                           
 4678  F891F6                   STRF1:
 4679  F891F6  25 73 20 25 2D           .DB     '%s %-42.41s %,7u Mb', 13, 0
               34 32 2E 34 31 
               73 20 25 2C 37 
               75 20 4D 62 0D 
               00 
 4680                           
 4681                           ; string's address (drive # indexed)
 4682  F8920B                   DSKMODEL:
 4683  F8920B  00 47 8E AE              .DB     <_atamod0, <_atamod1, <_usbdsc0, <_usbdsc1
 4684                           
 4685  F8920F                   DSKMODELH:
 4686  F8920F  00 00 00 00              .DB     >_atamod0, >_atamod1, >_usbdsc0, >_usbdsc1
 4687  F89213                           
 4688  F89213                   DSKSER:
 4689  F89213  29 70                    .DB     <_ataser0, <_ataser1
 4690                           
 4691  F89215                   DSKSERH:
 4692  F89215  00 00                    .DB     >_ataser0, >_ataser1
 4693  F89217                           
 4694  F89217                   DSKREV:
 4695  F89217  3E 85                    .DB     <_atarev0, <_atarev1
 4696                           
 4697  F89219                   DSKREVH:
 4698  F89219  00 00                    .DB     >_atarev0, >_atarev1


             Lines Assembled : 4510                  Errors : 0