section .bss drives: equ 16 ; drive table entry struc drive .biosnum: resb 1 .flag: resb 1 .spc: resw 1 .cylinders: resw 1 .dpt: resb dpt_size endstruc ; ptr into currently selected drive drive_ptr: resw 1 drive_table: resb (drives * drive_size) section .text drives_init: ; CX = number of floppy drives in the system int 0x11 mov cl, 6 shr ax, cl inc ax and ax, 3 mov cx, ax mov bx, drive_table xor dx, dx .loop: push cx push dx mov [bx+drive.biosnum], dl ; query bios for floppy format mov ah, 8 push bx int 0x13 pop bx ; set up defaults if invalid data or fail jc .defs test cx, cx jnz .load .defs: ; use defaults: 360k, 40 cyl, 9 sects les di, [0x1e * 4] mov cx, 0x270 mov dh, 1 .load: ; copy dpt push es push ds pop es pop ds push cx mov si, di lea di, [bx+drive.dpt] mov cx, 11 rep movsb pop cx ; restore ds push cs pop ds ; get and save number of cylinders mov ax, cx xchg al, ah rol ah, 1 rol ah, 1 and ax, 0x03FF inc ax mov [bx+drive.cylinders], ax ; save spt mov ax, cx and al, 0x3F mov [bx+drive.dpt+dpt.lastsector], al ; multiply with heads and save sectors per cylinder inc dh mul dh ; ax = al * dh mov [bx+drive.spc], ax ; advance loop pop dx pop cx inc dl add bx, drive_size loop .loop ret