Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Assembly x86 > The floppy disk...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 2 Topic 4569 of 4646
Post > Topic >>

The floppy disk is dead, long live the floppy disk.

by Mike Gonta <spamtrap@[EMAIL PROTECTED] > Mar 12, 2008 at 04:24 PM

The following code when assembled with FASM and written to a
USB flash drive will boot and run as either floppy disk emulation
or hard drive emulation depending on the bios setup.
It will boot and run froim a real floppy disk or with VFD and Qemu.
It will boot and run with Qemu from a USB flash drive even if the
PC will not boot from USB.


use16
org 7C00h

bpb:
  jmp WORD start
  db "        "
  dw 512                     ; bytes per sector
  db 1                       ; sectors per cluster
  dw (1+fat_1-sector_2)/512  ; reserved sector count
  db 2                       ; number of FATs
  dw 16*14                   ; root directory entries
  dw 18*2*80                 ; sector count
  db 0F0h                    ; media byte
  dw 9                       ; sectors per FAT
..sectors_per_track:
  dw 18
..number_of_heads:
  dw 2
  dd 0                       ; hidden sectors
  dd 0                       ; number of sectors huge
..drive_number:
  db 0
  db 0                       ; reserved
  db 29h                     ; signature
  dd 12345678h               ; volume ID
  db "           "           ; volume label
  db "FAT12   "              ; fileSysType

start:
  cli
  xor ax, ax
  mov ds, ax
  mov es, ax
  mov ss, ax
  mov esp, 0FFFCh            ; stack pointer at top of segment 0

  mov [bpb.drive_number], dl
  cmp dl, 80h
  jne @[EMAIL PROTECTED]
  mov ah, 8
  int 13h                    ; check hard disk format
  and cx, 3Fh                ; maximum
  mov [bpb.sectors_per_track], cx
  mov [bpb.number_of_heads], dh
@[EMAIL PROTECTED]
  mov bx, 1000h              ; load address
  mov ax, 211h               ; read 17 sectors
  mov cx, 2                  ; start at next sector
  mov dx, [bpb.drive_number]
  int 13h

  mov ax, 18
  xor dx, dx
  div WORD [bpb.sectors_per_track]
  add dx, 1
  mov cx, dx
  xor dx, dx
  div WORD [bpb.number_of_heads]
  mov dh, dl
  shl ax, 6
  or cx, ax

  mov ax, 212h              ; read next 18 sectors
  add bx, 512*17
  mov dl, [bpb.drive_number]
  int 13h

  jmp 0:1000h

  TIMES 510-($-$$) db 0
  dw 0AA55h

org 1000h
sector_2:
  TIMES (512*35)-(fat_1-hello) db 90h
hello:
  mov si, hello_world
  mov ah, 0Eh
@[EMAIL PROTECTED]
  mov al, [si]
  lea si, [si+1]
  test al, al
  je @[EMAIL PROTECTED]
  int 10h
  jmp @[EMAIL PROTECTED]
  xor ax, ax
  int 16h
  int 19h
hello_world: db "Hello World", 0

fat_1:
  db 0F0h,0FFh,0FFh
  TIMES 512*9-($-fat_1) db 0
fat_2:
  db 0F0h,0FFh,0FFh
  TIMES 512*9-($-fat_2) db 0
root:
  db "           ",8
  TIMES 512*14-($-root) db 0


Mike Gonta
look and see - many look but few see

http://mikegonta.com




 2 Posts in Topic:
The floppy disk is dead, long live the floppy disk.
Mike Gonta <spamtrap@  2008-03-12 16:24:01 
Re: The floppy disk is dead, long live the floppy disk.
Noob <root@[EMAIL PROT  2008-03-13 10:04:29 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Tue May 13 7:58:56 CDT 2008.