// Used to generate the WebMSX SymbOS FD Driver (-FDWMSX.DRV)

// Constants

    stobnkx equ #202    ;memory mapping, when low level routines read/write sector data
    bnkmonx equ #203    ;set special memory mapping during mass storage access (show destination/source memory block at #8000), HL=address; will be corrected from #0000-#ffff to #8000-#bfff
    bnkmofx equ #206    ;reset special memory mapping during mass storage access (show OS memory at #8000)
    bnkdofx equ #209    ;hide mass storage device rom (switch back to memory mapper slot config at #4000)
    stoadrx equ #20c    ;get device data record
    stobufx equ #212    ;address of 512byte buffer


// Header - starts at 0x1000 - 32

            0fe0    "SMD2"          ; db 4 ID
            0fe4    70 00           ; dw code length (END - START)
            0fe6    04 00           ; dw number of relocate table entries
            0fe8    00 x8           ; ds 8 reserved
            0ff0    00 05 00        ; db Version Minor, Version Major, Type (-1=NUL, 0=FDC, 1=IDE, 2=SD, 3=SCSI)
            0ff3    "WebMSX FD    " ; db 13 comment

// Jump table for Main Routines - starts at 0x1000

START       1000    20 10           ; DRVIMP address
            1002    40 10           ; DRVOUT address
            1004    60 10           ; DRVACT address
            1006    08 10           ; DRVMOF address

// Driver info section?

            1008    c9 00 00        ; ds 3 (?) Appears to be DRVMOF routine. Using just a RET
            100b    01              ; bit[0-4] = driver ID (1=philips), bit[5-7] = storage type (0=FD)
            100c    00 x4           ; ds 4 (?)
            1010    00 x3           ; ds 3 slot config for switching device rom at #4000. Not used
            1013    00 x13          ; filler space

// Main Routines

DRVIMP      1020    f5              ; push af
            1021    3a 02 02        ; ld a,(stobnkx)
            1024    eb              ; ex de, hl
            1025    cd 03 02        ; call bnkmonx
            1028    f1              ; pop af
            1029    4f              ; ld c, a
            102a    af              ; xor a         ( A = 0 Device Unavailable )
            102b    37              ; scf           ( Error if EXT not processed )
            102c    ed f4           ; EXT F4        ( Enters with C=device (0-7), IY,IX=logical sector number, B=number of sectors, HL=dest address )
            102e    cd 06 02        ; call bnkmofx
            1031    c9              ; RET
            1032    00 x14          ; filler

DRVOUT      1040    f5              ; push af
            1041    3a 02 02        ; ld a,(stobnkx)
            1044    eb              ; ex de, hl
            1045    cd 03 02        ; call bnkmonx
            1048    f1              ; pop af
            1049    4f              ; ld c, a
            104a    af              ; xor a         ( A = 0 Device Unavailable )
            104b    37              ; scf           ( Error if EXT not processed )
            104c    ed f5           ; EXT F5        ( Enters with C=device (0-7), IY,IX=logical sector number, B=number of sectors, HL=source address )
            104e    cd 06 02        ; call bnkmofx
            1051    c9              ; RET
            1052    00 x14          ; filler

DRVACT      1060    f5              ; push af
            1061    cd 0c 02        ; call stoadrx
            1064    f1              ; pop af
            1065    4f              ; ld c, a
            106a    af              ; xor a         ( A = 0 Device Unavailable )
            106b    37              ; scf           ( Error if EXT not processed )
            1068    ed f6           ; EXT F6        ( Enters with C=device (0-7), HL=device info block address )
            106a    c9              ; RET
            106b    00 x4           ; filler

// Relocation Table ( 4 entries)

END
REL_TAB     1050    00 10
            1052    02 10
            1054    04 10
            1056    06 10




// Main Routines Complex version

DRVIMP      1020    f5              ; push af
            1021    c5              ; push bc
            1022    dd e5           ; push ix
            1024    fd e5           ; push iy
            1026    d5              ; push de
            1027    cd 0c 02        ; call stoadrx
            102a    d1              ; pop de
            102b    e5              ; push hl
            102c    eb              ; ex de, hl
            102d    3a 02 02        ; ld a,(stobnkx)
            1030    cd 03 02        ; call bnkmonx
            1033    eb              ; ex de, hl
            1034    e1              ; pop hl
            1035    fd e1           ; pop iy
            1037    dd e1           ; pop ix
            1039    c1              ; pop bc
            103a    f1              ; pop af
            103b    ed f4           ; EXT F4
            103d    cd 06 02        ; call bnkmofx
            1040    c9              ; RET
            1041    00 x15          ; filler

DRVOUT      1050    f5              ; push af
            1051    c5              ; push bc
            1052    dd e5           ; push ix
            1054    fd e5           ; push iy
            1056    d5              ; push de
            1057    cd 0c 02        ; call stoadrx
            105a    d1              ; pop de
            105b    e5              ; push hl
            105c    eb              ; ex de, hl
            105d    3a 02 02        ; ld a,(stobnkx)
            1060    cd 03 02        ; call bnkmonx
            1063    eb              ; ex de, hl
            1064    e1              ; pop hl
            1065    fd e1           ; pop iy
            1067    dd e1           ; pop ix
            1069    c1              ; pop bc
            106a    f1              ; pop af
            106b    ed f5           ; EXT F5
            106d    cd 06 02        ; call bnkmofx
            1070    c9              ; RET
            1071    00 x15          ; filler

DRVACT      1080    f5              ; push af
            1081    cd 0c 02        ; call stoadrx
            1084    f1              ; pop af
            1085    ed f6           ; EXT F6
            1087    c9              ; RET
            1088    00 x8           ; filler
