Index: /trunk/XTIDE_Universal_BIOS/Inc/macros.inc
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Inc/macros.inc	(revision 86)
+++ /trunk/XTIDE_Universal_BIOS/Inc/macros.inc	(revision 86)
@@ -0,0 +1,41 @@
+; Project name	:	XTIDE Universal BIOS
+; Description	:	This is the place to put various generic macros.
+;					Should be included immediately after emulate.inc
+
+;--------------------------------------------------------------------
+; Skips the immediately following 2 byte instruction by using it
+; as an immediate value to a dummy instruction.
+; Destroys the contents of %1.
+;
+; SKIP2B
+;	Parameters:
+;		%1:		Any 16 bit general purpose register or F for flags.
+;	Returns:
+;		Nothing
+;	Corrupts registers:
+;		%1
+;--------------------------------------------------------------------
+%macro SKIP2B 1
+	%ifidni		%1, f
+		db	03Dh					; Opcode byte for CMP AX, <immed>
+		;db	0A9h					; Alt. version TEST AX, <immed>
+	%elifidni	%1, ax
+		db	0B8h					; Opcode byte for MOV AX, <immed>
+	%elifidni	%1, cx
+		db	0B9h					; Opcode byte for MOV CX, <immed>
+	%elifidni	%1, dx
+		db	0BAh					; Opcode byte for MOV DX, <immed>
+	%elifidni	%1, bx
+		db	0BBh					; Opcode byte for MOV BX, <immed>
+	%elifidni	%1, sp
+		db	0BCh					; Opcode byte for MOV SP, <immed>
+	%elifidni	%1, bp
+		db	0BDh					; Opcode byte for MOV BP, <immed>
+	%elifidni	%1, si
+		db	0BEh					; Opcode byte for MOV SI, <immed>
+	%elifidni	%1, di
+		db	0BFh					; Opcode byte for MOV DI, <immed>
+	%else
+		%error "Invalid parameter passed to SKIP2B"
+	%endif
+%endmacro
Index: /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Common/HError.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Common/HError.asm	(revision 85)
+++ /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Common/HError.asm	(revision 86)
@@ -1,7 +1,3 @@
-; File name		:	HError.asm
 ; Project name	:	IDE BIOS
-; Created date	:	30.11.2007
-; Last update	:	24.8.2010
-; Author		:	Tomi Tilli
 ; Description	:	Error checking functions for BIOS Hard disk functions.
 
@@ -34,6 +30,11 @@
 ALIGN JUMP_ALIGN
 HError_ProcessErrorsAfterPollingBSY:
+%ifndef USE_186
 	call	HError_GetStatusAndErrorRegistersToAXandStoreThemToBDA
 	jmp		SHORT GetBiosErrorCodeToAHfromStatusAndErrorRegistersInAX
+%else
+	push	GetBiosErrorCodeToAHfromStatusAndErrorRegistersInAX
+	; Fall through to HError_GetStatusAndErrorRegistersToAXandStoreThemToBDA
+%endif
 
 
Index: /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Common/HIRQ.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Common/HIRQ.asm	(revision 85)
+++ /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Common/HIRQ.asm	(revision 86)
@@ -1,7 +1,3 @@
-; File name		:	HIRQ.asm
 ; Project name	:	IDE BIOS
-; Created date	:	11.12.2009
-; Last update	:	24.8.2010
-; Author		:	Tomi Tilli
 ; Description	:	Interrupt handling related functions.
 
@@ -41,5 +37,5 @@
 	LOAD_BDA_SEGMENT_TO	ds, ax			; Zero AX
 	cli									; Disable interrupts
-	cmp		al, [ds:BDA.bHDTaskFlg]		; Task flag already set?
+	cmp		al, [BDA.bHDTaskFlg]		; Task flag already set?
 	jc		SHORT .ReturnFromWaitNotify	;  If so, skip OS notification
 
Index: /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Common/HPIO.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Common/HPIO.asm	(revision 85)
+++ /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Common/HPIO.asm	(revision 86)
@@ -1,11 +1,7 @@
-; File name		:	HPIO.asm
 ; Project name	:	IDE BIOS
-; Created date	:	14.12.2007
-; Last update	:	1.8.2010
-; Author		:	Tomi Tilli
 ; Description	:	PIO transfer functions.
 
 ; Structure containing variables for PIO transfer functions
-struc PIOVARS
+struc PIOVARS, -6
 	.fnXfer			resb	2	; Offset to transfer function
 	.wBlockSize		resb	2	; Block size in WORDs
@@ -63,5 +59,5 @@
 	; Create PIOVARS to stack
 	eENTER	PIOVARS_size, 0
-	sub		bp, BYTE PIOVARS_size			; SS:BP now points to PIOVARS
+
 	push	si
 	mov		si, g_rgfnPioRead				; Offset to read function lookup
@@ -75,8 +71,5 @@
 
 	; Destroy stack frame
-	rcl		al, 1							; CF to AL bit 0
-	add		bp, BYTE PIOVARS_size
 	eLEAVE
-	rcr		al, 1							; Restore CF
 	mov		di, bx							; Restore DI
 	pop		es
@@ -158,5 +151,5 @@
 .BlockLoop:
 	call	HStatus_WaitIrqOrDrq		; Wait until ready to transfer
-	jc		SHORT .RetError				; Return if error (code in AH)
+	jc		SHORT HPIO_WriteToDrive.RetError	; Return if error (code in AH)
 	mov		cx, [bp+PIOVARS.wBlockSize]	; Load block size
 	sub		[bp+PIOVARS.wWordsLeft], cx	; Transferring last (possibly partial) block?
@@ -169,6 +162,4 @@
 	call	[bp+PIOVARS.fnXfer]			; Transfer possibly partial block
 	jmp		HStatus_WaitBsyDefTime		; Check for errors
-.RetError:
-	ret
 
 
@@ -195,5 +186,5 @@
 	; Create PIOVARS to stack
 	eENTER	PIOVARS_size, 0
-	sub		bp, BYTE PIOVARS_size			; SS:BP now points to PIOVARS
+
 	mov		si, g_rgfnPioWrite				; Offset to write function lookup
 	call	HPIO_InitializePIOVARS			; Store word count and block size
@@ -205,11 +196,10 @@
 
 	; Destroy stack frame
-	rcl		al, 1							; CF to AL bit 0
-	add		bp, BYTE PIOVARS_size
 	eLEAVE
-	rcr		al, 1							; Restore CF
+
 	pop		si
 	pop		es
 	ret
+
 
 ;--------------------------------------------------------------------
@@ -243,5 +233,5 @@
 	jnc		SHORT .BlockLoop				; If no error, loop while blocks left
 .RetError:
-	ret
+	ret										; This ret is shared with HPIO_ReadFromDrive
 ALIGN JUMP_ALIGN
 .XferLastBlock:
Index: /trunk/XTIDE_Universal_BIOS/Src/Initialization/DetectDrives.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Initialization/DetectDrives.asm	(revision 85)
+++ /trunk/XTIDE_Universal_BIOS/Src/Initialization/DetectDrives.asm	(revision 86)
@@ -1,9 +1,4 @@
-; File name		:	DetectDrives.asm
 ; Project name	:	IDE BIOS
-; Created date	:	17.3.2010
-; Last update	:	23.8.2010
-; Author		:	Tomi Tilli
 ; Description	:	Functions for detecting drive for the BIOS.
-
 
 ; Section containing code
@@ -80,6 +75,5 @@
 DetectDrives_DetectMasterDrive:
 	mov		bh, MASK_IDE_DRVHD_SET		; Select Master drive
-	jmp		SHORT DetectDrives_StartDetection
-ALIGN JUMP_ALIGN
+	SKIP2B	ax							; mov ax, <next instruction>
 DetectDrives_DetectSlaveDrive:
 	mov		bh, MASK_IDE_DRVHD_SET | FLG_IDE_DRVHD_DRV
@@ -134,26 +128,4 @@
 	call	AH25h_GetDriveInfo
 	mov		si, di						; ES:SI now points to ATA information
-	ret
-
-
-;--------------------------------------------------------------------
-; Reads ATAPI information from the drive (for CD/DVD-ROMs).
-;
-; DetectDrives_ReadAtapiInfoFromDrive
-;	Parameters:
-;		BH:		Drive Select byte for Drive and Head Register
-;		CS:BP:	Ptr to IDEVARS for the drive
-;		DS:		RAMVARS segment
-;		ES:		Zero (BDA segment)
-;	Returns:
-;		ES:SI	Ptr to ATAPI information (read with IDENTIFY PACKET DEVICE command)
-;		CF:		Cleared if ATAPI-information read successfully
-;				Set if any error
-;	Corrupts registers:
-;		AX, BL, CX, DX, DI
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-DetectDrives_ReadAtapiInfoFromDrive:
-	stc
 	ret
 
@@ -188,4 +160,27 @@
 
 ;--------------------------------------------------------------------
+; Reads ATAPI information from the drive (for CD/DVD-ROMs).
+;
+; DetectDrives_ReadAtapiInfoFromDrive
+;	Parameters:
+;		BH:		Drive Select byte for Drive and Head Register
+;		CS:BP:	Ptr to IDEVARS for the drive
+;		DS:		RAMVARS segment
+;		ES:		Zero (BDA segment)
+;	Returns:
+;		ES:SI	Ptr to ATAPI information (read with IDENTIFY PACKET DEVICE command)
+;		CF:		Cleared if ATAPI-information read successfully
+;				Set if any error
+;	Corrupts registers:
+;		AX, BL, CX, DX, DI
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+DetectDrives_ReadAtapiInfoFromDrive:
+	;stc
+	;ret
+	; Fall through to DetectDrives_CreateBiosTablesForCDROM
+
+
+;--------------------------------------------------------------------
 ; Creates all BIOS tables for detected CD/DVD-ROM.
 ;
Index: /trunk/XTIDE_Universal_BIOS/Src/Initialization/DetectPrint.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Initialization/DetectPrint.asm	(revision 85)
+++ /trunk/XTIDE_Universal_BIOS/Src/Initialization/DetectPrint.asm	(revision 86)
@@ -1,7 +1,3 @@
-; File name		:	DetectPrint.asm
 ; Project name	:	IDE BIOS
-; Created date	:	28.3.2010
-; Last update	:	9.4.2010
-; Author		:	Tomi Tilli
 ; Description	:	Functions for printing drive detection strings.
 
@@ -25,6 +21,5 @@
 	ePUSH_T	ax, ROMVARS.szTitle
 	mov		si, g_szRomAt
-	mov		dh, 4						; 4 bytes pushed to stack
-	jmp		PrintString_JumpToFormat
+	jmp		SHORT DetectPrint_4BytesPushedToStack
 
 
@@ -67,4 +62,5 @@
 	push	ax
 	mov		si, g_szDetect
+DetectPrint_4BytesPushedToStack:
 	mov		dh, 4						; 4 bytes pushed to stack
 	jmp		PrintString_JumpToFormat
Index: /trunk/XTIDE_Universal_BIOS/Src/Initialization/FloppyDrive.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Initialization/FloppyDrive.asm	(revision 85)
+++ /trunk/XTIDE_Universal_BIOS/Src/Initialization/FloppyDrive.asm	(revision 86)
@@ -1,7 +1,3 @@
-; File name		:	FloppyDrive.asm
 ; Project name	:	IDE BIOS
-; Created date	:	25.3.2010
-; Last update	:	13.9.2010
-; Author		:	Tomi Tilli
 ; Description	:	Various floppy drive related functions that
 ;					Boot Menu uses.
@@ -21,5 +17,5 @@
 ;	Corrupts registers:
 ;		BX, CX, DI
-;--------------------------------------------------------------------	
+;--------------------------------------------------------------------
 ;ALIGN JUMP_ALIGN
 FloppyDrive_IsInt40hInstalled:
@@ -40,5 +36,5 @@
 ;	Corrupts registers:
 ;		BX, CX, DI
-;--------------------------------------------------------------------	
+;--------------------------------------------------------------------
 ;ALIGN JUMP_ALIGN
 .VerifyInt40hHandlerSinceSomeBiosesSimplyReturnFromInt40h:
@@ -84,11 +80,11 @@
 ;	Corrupts registers:
 ;		DH
-;--------------------------------------------------------------------	
+;--------------------------------------------------------------------
 ;ALIGN JUMP_ALIGN
 .LoadInt40hVerifyParameters:
-	xor		dx, dx				; Floppy drive 0
+	mov		ah, 08h				; Get Drive Parameters
+	cwd							; Floppy drive 0
 	mov		di, dx
 	mov		es, dx				; ES:DI = 0000:0000h to guard against BIOS bugs
-	mov		ah, 08h				; Get Drive Parameters
 	ret
 
@@ -171,5 +167,5 @@
 
 	mov		ah, 08h					; Get Drive Parameters
-	xor		dx, dx					; Floppy Drive 00h
+	cwd								; Floppy Drive 00h
 	int		INTV_FLOPPY_FUNC
 	mov		cl, dl					; Number of Floppy Drives to CL
Index: /trunk/XTIDE_Universal_BIOS/Src/Initialization/Interrupts.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Initialization/Interrupts.asm	(revision 85)
+++ /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
Index: /trunk/XTIDE_Universal_BIOS/Src/Initialization/PrintString.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Initialization/PrintString.asm	(revision 85)
+++ /trunk/XTIDE_Universal_BIOS/Src/Initialization/PrintString.asm	(revision 86)
@@ -1,9 +1,4 @@
-; File name		:	PrintString.asm
 ; Project name	:	IDE BIOS
-; Created date	:	19.3.2010
-; Last update	:	31.3.2010
-; Author		:	Tomi Tilli
 ; Description	:	Functions for printing strings used in this IDE BIOS.
-
 
 ; Section containing code
@@ -13,5 +8,5 @@
 ; Prints string with formatting parameters.
 ; Do not call PrintString_JumpToFormat!!! Jump there only!
-; 
+;
 ; PrintString_JumpToFormat
 ;	Parameters:
@@ -42,5 +37,5 @@
 ;--------------------------------------------------------------------
 ; Prints STOP terminated string from wanted segment.
-; 
+;
 ; PrintString_FromCS
 ; PrintString_FromES
@@ -56,14 +51,9 @@
 PrintString_FromCS:
 	push	ds
-	push	cs					; Push string segment...
-	pop		ds					; ...and pop it to DS
-	call	PrintString_FromDS
-	pop		ds
-	ret
-
-ALIGN JUMP_ALIGN
+	push	cs					; Push string segment here...
+	SKIP2B	ax					; mov ax, <next 2 bytes/instructions>
 PrintString_FromES:
 	push	ds
-	push	es					; Push string segment...
+	push	es					; ...or here...
 	pop		ds					; ...and pop it to DS
 	call	PrintString_FromDS
Index: /trunk/XTIDE_Universal_BIOS/Src/Libraries/menu/menucrsr.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Libraries/menu/menucrsr.asm	(revision 85)
+++ /trunk/XTIDE_Universal_BIOS/Src/Libraries/menu/menucrsr.asm	(revision 86)
@@ -1,7 +1,3 @@
-; File name		:	menucrsr.asm
 ; Project name	:	Menu library
-; Created date	:	10.11.2009
-; Last update	:	17.1.2010
-; Author		:	Tomi Tilli
 ; Description	:	ASM library to menu system.
 ;					Contains menu cursor functions.
@@ -160,8 +156,7 @@
 ALIGN JUMP_ALIGN
 MenuCrsr_SetCursor:
-	xor		bx, bx						; Zero page
 	mov		ah, 02h						; Set Cursor Position and Size
-	int		10h
-	ret
+	SKIP2B	bx							; mov bx, <next instruction>
+	; Fall through to MenuCrsr_GetCursor
 
 
@@ -178,8 +173,8 @@
 ;		AX, BX
 ;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
+;ALIGN JUMP_ALIGN
 MenuCrsr_GetCursor:
+	mov		ah, 03h						; Get Cursor Position and Size
 	xor		bx, bx						; Zero page
-	mov		ah, 03h						; Get Cursor Position and Size
 	int		10h
 	ret
Index: /trunk/XTIDE_Universal_BIOS/Src/Main.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Main.asm	(revision 85)
+++ /trunk/XTIDE_Universal_BIOS/Src/Main.asm	(revision 86)
@@ -1,13 +1,12 @@
-; File name		:	Main.asm
 ; Project name	:	XTIDE Universal BIOS
-; Created date	:	28.7.2007
-; Last update	:	28.11.2010
-; Author		:	Tomi Tilli
+; Authors		:	Tomi Tilli
+;				:	aitotat@gmail.com
+;				:
+;				:	Krister Nordvall
+;				:	krille_n_@hotmail.com
+;				:
 ; Description	:	Main file for BIOS. This is the only file that needs
 ;					to be compiled since other files are included to this
 ;					file (so no linker needed, Nasm does it all).
-;
-;					Tomi Tilli
-;					aitotat@gmail.com
 
 ORG 000h						; Code start offset 0000h
@@ -15,4 +14,5 @@
 ; Included .inc files
 %include "emulate.inc"			; Must be included first!
+%include "macros.inc"			; For generic macros
 %include "BiosData.inc"			; For BIOS Data area equates
 %include "Interrupts.inc"		; For interrupt equates
