Index: trunk/XTIDE_Universal_BIOS/Src/Initialization/Interrupts.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Initialization/Interrupts.asm	(revision 33)
+++ trunk/XTIDE_Universal_BIOS/Src/Initialization/Interrupts.asm	(revision 86)
@@ -1,7 +1,3 @@
-; File name		:	Interrupts.asm
 ; Project name	:	IDE BIOS
-; Created date	:	23.8.2010
-; Last update	:	23.8.2010
-; Author		:	Tomi Tilli
 ; Description	:	Functions for initializing the BIOS.
 
@@ -18,5 +14,5 @@
 ;	Corrupts registers:
 ;		All except segments
-;--------------------------------------------------------------------	
+;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
 Interrupts_InitializeInterruptVectors:
@@ -24,4 +20,5 @@
 	call	Interrupts_InitializeInt19h
 	jmp		SHORT Interrupts_InitializeHardwareIrqHandlers
+	; Maybe all this should be inlined?
 
 
@@ -35,5 +32,5 @@
 ;	Corrupts registers:
 ;		AX, BX, CX, DX, SI, DI
-;--------------------------------------------------------------------	
+;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
 Interrupts_InitializeInt13hAnd40h:
@@ -50,21 +47,8 @@
 	; 40h from 13h. That system locks to infinite loop if we copy 13h to 40h.
 	call	FloppyDrive_IsInt40hInstalled
-	jnc		SHORT .InitializeInt40h
-	ret
-
-;--------------------------------------------------------------------
-; .InitializeInt40h
-;	Parameters:
-;		DX:AX:	Ptr to old INT 13h handler
-;		ES:		BDA and Interrupt Vector segment (zero)
-;	Returns:
-;		Nothing
-;	Corrupts registers:
-;		Nothing
-;--------------------------------------------------------------------	
-ALIGN JUMP_ALIGN
-.InitializeInt40h:
+	jc		SHORT .Return
 	mov		[es:INTV_FLOPPY_FUNC*4], ax		; Store offset
 	mov		[es:INTV_FLOPPY_FUNC*4+2], dx	; Store segment
+.Return:
 	ret
 
@@ -79,5 +63,5 @@
 ;	Corrupts registers:
 ;		BX, SI
-;--------------------------------------------------------------------	
+;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
 Interrupts_InitializeInt19h:
@@ -116,5 +100,5 @@
 ;	Corrupts registers:
 ;		BX, CX, DX, SI, DI
-;--------------------------------------------------------------------		
+;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
 Interrupts_InitializeHardwareIrqHandlers:
@@ -127,5 +111,6 @@
 	call	.InstallLowOrHighIrqHandler
 	loop	.IdeControllerLoop
-	ret
+.Return:
+	ret		; This ret is shared with .InstallLowOrHighIrqHandler
 
 ;--------------------------------------------------------------------
@@ -138,12 +123,12 @@
 ;	Corrupts registers:
 ;		BX, SI
-;--------------------------------------------------------------------		
+;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
 .InstallLowOrHighIrqHandler:
+	test	bl, bl
+	jz		SHORT .Return	; IRQ not used
 	cmp		bl, 8
-	jae		SHORT .InstallHighIrqHandler
-	test	bl, bl
-	jnz		SHORT .InstallLowIrqHandler
-	ret		; IRQ not used
+	jb		SHORT .InstallLowIrqHandler
+	; Fall through to .InstallHighIrqHandler
 
 ;--------------------------------------------------------------------
@@ -156,7 +141,7 @@
 ;	Corrupts registers:
 ;		BX, SI
-;--------------------------------------------------------------------		
-ALIGN JUMP_ALIGN
-.InstallHighIrqHandler:
+;--------------------------------------------------------------------
+;ALIGN JUMP_ALIGN
+;.InstallHighIrqHandler:
 	add		bx, BYTE INTV_IRQ8 - 8			; Interrupt vector number
 	mov		si, HIRQ_InterruptServiceRoutineForIrqs8to15
@@ -172,5 +157,5 @@
 ;	Corrupts registers:
 ;		BX, SI
-;--------------------------------------------------------------------		
+;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
 .InstallLowIrqHandler:
@@ -190,5 +175,5 @@
 ;	Corrupts registers:
 ;		BX
-;--------------------------------------------------------------------	
+;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
 Interrupts_InstallHandlerToVectorInBXFromCSSI:
@@ -212,9 +197,9 @@
 	eMOVZX	bx, BYTE [di+DPT.bIdeOff]
 	mov		al, [cs:bx+IDEVARS.bIRQ]
+	test	al, al
+	jz		SHORT .Return	; Interrupts disabled
 	cmp		al, 8
-	jae		SHORT .UnmaskHighIrqController
-	test	al, al
-	jnz		SHORT .UnmaskLowIrqController
-	ret		; Interrupts disabled
+	jb		SHORT .UnmaskLowIrqController
+	; Fall through to .UnmaskHighIrqController
 
 ;--------------------------------------------------------------------
@@ -227,6 +212,6 @@
 ;		AX, DX
 ;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-.UnmaskHighIrqController:
+;ALIGN JUMP_ALIGN
+;.UnmaskHighIrqController:
 	sub		al, 8				; Slave interrupt number
 	mov		dx, PORT_8259SL_IMR	; Load Slave Mask Register address
@@ -270,3 +255,4 @@
 	out		dx, al				; Write modified Interrupt Mask Register
 	pop		cx
-	ret
+.Return:
+	ret
