Page 1 of 1

RealMode Drive Detection Routine Using BIOS [Problems]

Posted: Tue Oct 06, 2009 6:00 pm
by cr0PE
I have a drive number detection routine that works fine on every computer I have tried it on except one. Here is the code:

Code: Select all

drivedet:		;Detect the number of floppy and hard drives present and save their numbers
	mov ah, 0x15	;INT 0x13 AH=0x15: get disk type
	int 0x13
	jc .next
	cmp ah, 0	; ah=0: no disk present
	jz .next
	cmp ah, 02	; ah=1: floppy without change-line. ah=2: floppy with change-line
	jnbe .drv3
	dec byte [count]
	inc byte [floppies]    ;increment the total floppy count
	push bx
	xor bx, bx
	mov byte bl , [floppies]
	dec bl
	mov byte [fd0+bx], dl   ;save drive number in dl to proper drive number variable
	pop bx
	jmp .next
.drv3:
	dec byte [count]
	inc byte [hds]	;ah=3: hard disk
	push bx
	xor bx, bx
	mov byte bl, [hds]
	dec bl
	mov byte [hd0+bx], dl   ;save drive number in dl to proper drive number variable
	pop bx
.next:
	inc dl
	cmp byte [count], 0	;some retarded BIOSs report duplicate high number drives
	jz .end		
	jmp drivedet	
Before, calling this code I set up the total number of drives (from BIOS) in the byte variable [count] and zero out dl.

The problem computer is a gateway, sorry don't know the model, but it has a AMD Athlon Thunderbird at 1.2Ghz and on it the code just goes into an infinite loop. Like I said this is the only computer it does that on. At first I suspected that the BIOS was giving me an incorrect number of drives, but I found this to be false.

Any ideas would be appreciated. Thanks in advance,
cr0PE

Re: jz falls through on one computer but not others

Posted: Wed Oct 07, 2009 7:41 am
by jal
cr0PE wrote:the code just goes into an infinite loop
Are you sure it's in this code? If so, at what point does it do the infinite loop? And why (i.e. which condition fails)?


JAL

Re: RealMode Drive Detection Routine Using BIOS [Problems]

Posted: Wed Oct 07, 2009 9:32 am
by AJ
Hi,

If one of your first conditions fails (cf set or ah == 0), you jmp to the .next label without decrementing [count].

Cheers,
Adam

Re: RealMode Drive Detection Routine Using BIOS [Problems]

Posted: Thu Oct 08, 2009 5:53 pm
by cr0PE
AJ wrote:Hi,

If one of your first conditions fails (cf set or ah == 0), you jmp to the .next label without decrementing [count].

Cheers,
Adam
Of course. Thanks.