1 ; vi:filetype=nasm ts=8 sts=8 sw=8:
10 ; setup stack and the rest of the segment registers
19 ; dl: drive number, save it
27 mov bx, LOADADDR ; es:bx <- destination
30 shr cx, 9 ; cx <- binsize in sectors
31 mov [binsize_sect], cx
35 inc cx ; start from sector 1 (after boot sector)
38 ; inc dest addr by 512
41 ; offset rolled over, bump es to the next 64k
47 cmp cx, [binsize_sect]
67 mov al, ch ; low 8 bits of max cylinder
68 mov ah, cl ; bits 6,7 high bits of max cylinder
71 inc ax ; inc to make it number of cylinders
72 mov [num_cylinders], ax
74 and cx, 3fh ; bits 0-5: sect_per_track
75 mov [sect_per_track], cx
84 ; read_sector expects a linear sector number in cx, converts it to CHS
85 ; and loads the sector at es:bx
87 mov byte [read_retries], 3
89 push cx ; save linear sector number
90 ; calculate track (sidx / sectors_per_track)
93 mov cx, [sect_per_track]
101 ; cylinder (track/heads) in ch [0-7] and cl[6,7]<-[8,9]
104 mov word cx, [num_heads]
106 pop dx ; restore sidx % sectors_per_track to dx
111 ; sector num cl[0-5] is sidx % sectors_per_track + 1
116 ; ah = 2 (read), al = 1 sectors
118 mov byte dl, [driveno]
122 dec word [read_retries]
125 ; error detected, reset controller and retry
128 pop cx ; we push that at the top of the loop
162 sect_per_track: dw 18
172 rderr_str: db 'read error',13,10,0
173 newline_str: db 13,10,0
176 times 510-($-$$) db 0