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

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

Post by Mike Gont » Fri, 14 Mar 2008 08:22:07


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 @F
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
@@:
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
@@:
mov al, [si]
lea si, [si+1]
test al, al
je @F
int 10h
jmp @B
@@:
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://www.yqcomputer.com/
 
 
 

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

Post by Skybuck Fl » Fri, 14 Mar 2008 10:20:12

I saved a copy to my disk.

Might come in handy some day, or maybe not :)

Untested though ;)

Thanks anyway :)

Bye,
Skybuck.