        title   FAKEFRMT - fake format program

;masm fakefrmt;
;link fakefrmt;
;exe2bin fakefrmt.exe fakefrmt.com
;del fakefrmt.exe

CODE    segment
        assume  cs:CODE, ds:CODE

        org     100h

start:  mov     dx,offset AnyKey
        mov     ah,9
        int     21h
        mov     ax,0C08h        ; wait for user keystroke
        int     21h
        xor     al,3            ; test for CTRL-C (quit)
        jz      Fini
        mov     bx,offset bootsec
        xor     dx,dx           ; logical sector number
        mov     cx,12           ; number of full sectors, 360K
                                ; change to 14 for 3.5-in 720K,
                                ; 29 for 1.2Meg, or 33 for 1.44M
        mov     al,0            ; drive code, 1 for B:
        int     26h             ; absolute sector write
        pop     bx              ; flush leftover flags word
        jnc     start           ; loop unless error
        mov     dx,offset ErrMsg
        mov     ah,9
        int     21h
Fini:   mov     ah,4Ch          ; terminate program
        int     21h

AnyKey  db      'Press any key (^C to stop)', 0Dh, 0Ah, '$'
ErrMsg  db      'Error on Drive A', 0Dh, 0Ah, '$'

bootsec:                        ; this will be the Boot Sector
        jmp     short bootsnd
        nop

; BIOS Parameter Block (BPB)
DiskName        db      'FAKEFRMT'  ; must be exactly 8 chars
BytesPerSect    dw      0200h       ; same for all diskettes
ClusterSize     db      2           ; same for all diskettes
RsrvdSect       dw      1           ; boot sec, same for all
NbrFATs         db      2           ; same for all
RootDirSize     dw      112         ; same for 720K, 224 for 1.2/1.44
TotalSectors    dw      720         ; 720K=1440, 1.2M=2400, 1.44=2880
MediaCode       db      0FDh        ; 720K=F9, 1.2M=F9, 1.44M=F0
SecPerFAT       dw      2           ; 720K=3, 1.2M=7, 1.44M=9
SecPerTrack     dw      9           ; same for 720K, 1.2=15, 1.44=18
NbrOfHeads      dw      2           ; same for all
HiddenSects     dd      0           ; same for all
NotUsed         db      11 dup (0)  ; large sectors, etc.

bootsnd:
        mov     ax,cs           ; set up segment regs
        cli                     ; Disable interrupts
        mov     ss,ax
        mov     sp,7C00h        ; where boot sec loads
        sti                     ; Enable interrupts
        mov     ds,ax
        mov     si,7C00h + msg  ; start of message
bootloop:
        lodsb
        cmp     al,0            ; at end yet?
        je      boothalt        ; yes, lock things up
        mov     ah,0Eh          ; no, send via BIOS code
        mov     bx,7
        int     10h
        jmp     short bootloop  ; and go back for next char

boothalt:
        jmp     short boothalt  ; dynamic halt

msg     equ     $ - bootsec + 0 ; calc message start
        db      'This is a DATA disk only;', 0Dh, 0Ah
        db      'Insert system disk, press any key when '
        db      'ready', 0Dh, 0Ah, 0

        org     bootsec + 510   ; skip to end of sector
        db      55h, 0AAh       ; boot sector signature

fat1    db      0FDh            ; make this match MediaCode
        db      0FFh, 0FFh
        db      509 dup(0)      ; let assembler do the calc!
        db      1*512 dup (0)   ; 2*512for 720K, 6*512 for 1.2M,
                                ; or 8*512 for 1.44 meg

fat2    db      0FDh            ; make this match MediaCode
        db      0FFh, 0FFh
        db      509 dup(0)
        db      1*512 dup (0)   ; 2*512for 720K, 6*512 for 1.2M,
                                ; or 8*512 for 1.44 meg

rootdir db      7*512 dup (0)   ; 720K same, 14*512 for others

CODE    ends

        end     start
