home *** CD-ROM | disk | FTP | other *** search
/ For Beginners & Professional Hackers / cd.iso / docum / dos-ref.doc / examples / chap4.arj / FAKEFRMT.ASM < prev    next >
Encoding:
Assembly Source File  |  1990-09-25  |  3.7 KB  |  102 lines

  1.         title   FAKEFRMT - fake format program
  2.  
  3. ;masm fakefrmt;
  4. ;link fakefrmt;
  5. ;exe2bin fakefrmt.exe fakefrmt.com
  6. ;del fakefrmt.exe
  7.  
  8. CODE    segment
  9.         assume  cs:CODE, ds:CODE
  10.  
  11.         org     100h
  12.  
  13. start:  mov     dx,offset AnyKey
  14.         mov     ah,9
  15.         int     21h
  16.         mov     ax,0C08h        ; wait for user keystroke
  17.         int     21h
  18.         xor     al,3            ; test for CTRL-C (quit)
  19.         jz      Fini
  20.         mov     bx,offset bootsec
  21.         xor     dx,dx           ; logical sector number
  22.         mov     cx,12           ; number of full sectors, 360K
  23.                                 ; change to 14 for 3.5-in 720K,
  24.                                 ; 29 for 1.2Meg, or 33 for 1.44M
  25.         mov     al,0            ; drive code, 1 for B:
  26.         int     26h             ; absolute sector write
  27.         pop     bx              ; flush leftover flags word
  28.         jnc     start           ; loop unless error
  29.         mov     dx,offset ErrMsg
  30.         mov     ah,9
  31.         int     21h
  32. Fini:   mov     ah,4Ch          ; terminate program
  33.         int     21h
  34.  
  35. AnyKey  db      'Press any key (^C to stop)', 0Dh, 0Ah, '$'
  36. ErrMsg  db      'Error on Drive A', 0Dh, 0Ah, '$'
  37.  
  38. bootsec:                        ; this will be the Boot Sector
  39.         jmp     short bootsnd
  40.         nop
  41.  
  42. ; BIOS Parameter Block (BPB)
  43. DiskName        db      'FAKEFRMT'  ; must be exactly 8 chars
  44. BytesPerSect    dw      0200h       ; same for all diskettes
  45. ClusterSize     db      2           ; same for all diskettes
  46. RsrvdSect       dw      1           ; boot sec, same for all
  47. NbrFATs         db      2           ; same for all
  48. RootDirSize     dw      112         ; same for 720K, 224 for 1.2/1.44
  49. TotalSectors    dw      720         ; 720K=1440, 1.2M=2400, 1.44=2880
  50. MediaCode       db      0FDh        ; 720K=F9, 1.2M=F9, 1.44M=F0
  51. SecPerFAT       dw      2           ; 720K=3, 1.2M=7, 1.44M=9
  52. SecPerTrack     dw      9           ; same for 720K, 1.2=15, 1.44=18
  53. NbrOfHeads      dw      2           ; same for all
  54. HiddenSects     dd      0           ; same for all
  55. NotUsed         db      11 dup (0)  ; large sectors, etc.
  56.  
  57. bootsnd:
  58.         mov     ax,cs           ; set up segment regs
  59.         cli                     ; Disable interrupts
  60.         mov     ss,ax
  61.         mov     sp,7C00h        ; where boot sec loads
  62.         sti                     ; Enable interrupts
  63.         mov     ds,ax
  64.         mov     si,7C00h + msg  ; start of message
  65. bootloop:
  66.         lodsb
  67.         cmp     al,0            ; at end yet?
  68.         je      boothalt        ; yes, lock things up
  69.         mov     ah,0Eh          ; no, send via BIOS code
  70.         mov     bx,7
  71.         int     10h
  72.         jmp     short bootloop  ; and go back for next char
  73.  
  74. boothalt:
  75.         jmp     short boothalt  ; dynamic halt
  76.  
  77. msg     equ     $ - bootsec + 0 ; calc message start
  78.         db      'This is a DATA disk only;', 0Dh, 0Ah
  79.         db      'Insert system disk, press any key when '
  80.         db      'ready', 0Dh, 0Ah, 0
  81.  
  82.         org     bootsec + 510   ; skip to end of sector
  83.         db      55h, 0AAh       ; boot sector signature
  84.  
  85. fat1    db      0FDh            ; make this match MediaCode
  86.         db      0FFh, 0FFh
  87.         db      509 dup(0)      ; let assembler do the calc!
  88.         db      1*512 dup (0)   ; 2*512for 720K, 6*512 for 1.2M,
  89.                                 ; or 8*512 for 1.44 meg
  90.  
  91. fat2    db      0FDh            ; make this match MediaCode
  92.         db      0FFh, 0FFh
  93.         db      509 dup(0)
  94.         db      1*512 dup (0)   ; 2*512for 720K, 6*512 for 1.2M,
  95.                                 ; or 8*512 for 1.44 meg
  96.  
  97. rootdir db      7*512 dup (0)   ; 720K same, 14*512 for others
  98.  
  99. CODE    ends
  100.  
  101.         end     start
  102.