diff options
Diffstat (limited to 'src/stage1_functions.asm')
-rw-r--r-- | src/stage1_functions.asm | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/src/stage1_functions.asm b/src/stage1_functions.asm index c17feeb..e9281c4 100644 --- a/src/stage1_functions.asm +++ b/src/stage1_functions.asm @@ -91,6 +91,10 @@ current_row: ret ; data sections used for reading from disk +SECTORS_PER_CYLINDER: + db 0x13 ; detect parameters enters the correct value here (sectors + 1) +NOF_HEADS: + db 0x02 ; number of heads + 1 SECTORS_TO_LOAD: db NOF_LOAD_SECTORS ; load NOF_LOAD_SECTORS sectors in total CURRENT_SECTOR: @@ -100,6 +104,23 @@ CURRENT_CYLINDER: CURRENT_HEAD: db 0 +; detect disk geometry +; IN dl: drive +detect_disk_geometry: + mov dx, 0 + mov es, dx + mov ah, 0x08 + int 0x13 + add dh, 1 + mov [NOF_HEADS], BYTE dh +; call print_hex +; mov dx, cx +; call print_hex + and cl, 0x3F + add cl, 1 + mov [SECTORS_PER_CYLINDER], BYTE cl + ret + ; read the whole stage2 and kernel from the disk ; IN dl: drive to read from read_from_disk: @@ -118,14 +139,16 @@ read_from_disk: add bx, 0x200 ; advance write buffer position add [CURRENT_SECTOR], BYTE 1 ; next sector - cmp [CURRENT_SECTOR], BYTE 0x13 ; assuming 18 sectors per track for now + mov ch, [SECTORS_PER_CYLINDER] + cmp [CURRENT_SECTOR], ch ; assuming 18 sectors per track for now je .next_head jmp .read_next_sector .next_head: mov [CURRENT_SECTOR], BYTE 1 ; start from first sector again add [CURRENT_HEAD], BYTE 1 ; advance head - cmp [CURRENT_HEAD], BYTE 0x02 ; 2 heads on floppies + mov ch, [NOF_HEADS] + cmp [CURRENT_HEAD], ch ; 2 heads on floppies je .next_track jmp .read_next_sector @@ -177,7 +200,7 @@ read_one_sector_from_disk: jmp $ kill_motor: - mov dx, 0x3F2 - mov al, 0x00 - out dx, al + mov dx, 0x3F2 + mov al, 0x00 + out dx, al ret |