Skip to content
Snippets Groups Projects
int13.c 5.6 KiB
Newer Older
Alexandre Julliard's avatar
Alexandre Julliard committed
/*
 * BIOS interrupt 13h handler
 */

Alexandre Julliard's avatar
Alexandre Julliard committed
#include <stdlib.h>
Alexandre Julliard's avatar
Alexandre Julliard committed
#include <unistd.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#ifdef linux
# include <linux/fd.h>
Alexandre Julliard's avatar
Alexandre Julliard committed
#endif
Alexandre Julliard's avatar
Alexandre Julliard committed
#include "miscemu.h"
Alexandre Julliard's avatar
Alexandre Julliard committed
/* #define DEBUG_INT */
Alexandre Julliard's avatar
Alexandre Julliard committed
#include "drive.h"
Alexandre Julliard's avatar
Alexandre Julliard committed

Alexandre Julliard's avatar
Alexandre Julliard committed
/**********************************************************************
 *	    INT_Int13Handler (WPROCS.119)
Alexandre Julliard's avatar
Alexandre Julliard committed
 *
 * Handler for int 13h (disk I/O).
 */
void WINAPI INT_Int13Handler( CONTEXT86 *context )
Alexandre Julliard's avatar
Alexandre Julliard committed
{
Alexandre Julliard's avatar
Alexandre Julliard committed
    switch(AH_reg(context))
Alexandre Julliard's avatar
Alexandre Julliard committed
    {
Alexandre Julliard's avatar
Alexandre Julliard committed
	case 0x00:                            /* RESET DISK SYSTEM     */
		break; /* no return ? */
	case 0x01:			      /* STATUS OF DISK SYSTEM */
		AL_reg(context) = 0; /* successful completion */
		break;
	case 0x02:			      /* READ SECTORS INTO MEMORY */
		AL_reg(context) = 0; /* number of sectors read */
		AH_reg(context) = 0; /* status */
		break;
	case 0x03:			      /* WRITE SECTORS FROM MEMORY */
		break; /* no return ? */
Alexandre Julliard's avatar
Alexandre Julliard committed
	case 0x04:                            /* VERIFY DISK SECTOR(S) */
		AL_reg(context) = 0; /* number of sectors verified */
Alexandre Julliard's avatar
Alexandre Julliard committed
		AH_reg(context) = 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
		break;
	       
	case 0x05:                                     /* FORMAT TRACK */
Alexandre Julliard's avatar
Alexandre Julliard committed
        case 0x06:             /* FORMAT TRACK AND SET BAD SECTOR FLAGS */
        case 0x07:             /* FORMAT DRIVE STARTING AT GIVEN TRACK  */
Alexandre Julliard's avatar
Alexandre Julliard committed
            /* despite what Ralf Brown says, 0x06 and 0x07 seem to
             * set CFLAG, too (at least my BIOS does that) */
            AH_reg(context) = 0x0c;
            SET_CFLAG(context);
            break;
Alexandre Julliard's avatar
Alexandre Julliard committed

	case 0x08:                              /* GET DRIVE PARAMETERS  */
Alexandre Julliard's avatar
Alexandre Julliard committed
		if (DL_reg(context) & 0x80) { /* hard disk ? */
			AH_reg(context) = 0x07;
			SET_CFLAG(context);
		}
		else { /* floppy disk */
#ifdef linux
			unsigned int i, nr_of_drives = 0;			
			BYTE drive_nr = DL_reg(context);
                        int floppy_fd;
                        struct floppy_drive_params floppy_parm;
Alexandre Julliard's avatar
Alexandre Julliard committed

                        AH_reg(context) = 0x00; /* success */

                        for (i = 0; i < MAX_DOS_DRIVES; i++, root[0]++)
                            if (GetDriveTypeA(root) == DRIVE_REMOVABLE) nr_of_drives++;
Alexandre Julliard's avatar
Alexandre Julliard committed
                        DL_reg(context) = nr_of_drives;

			if (drive_nr > 1) { /* invalid drive ? */
				BX_reg(context) = 0;
				CX_reg(context) = 0;
				DH_reg(context) = 0;
				break;
			}

                        if ( (floppy_fd = DRIVE_OpenDevice( drive_nr, O_NONBLOCK)) == -1)
                        {
                                WARN("(GET DRIVE PARAMETERS): Can't determine floppy geometry !\n");
Alexandre Julliard's avatar
Alexandre Julliard committed
                                BX_reg(context) = 0;
                                CX_reg(context) = 0;
                                DH_reg(context) = 0;
                                break;
                        }
                        ioctl(floppy_fd, FDGETDRVPRM, &floppy_parm);
                        close(floppy_fd);

			BL_reg(context) = floppy_parm.cmos;

			/* CH = low eight bits of max cyl
			   CL = max sec nr (bits 5-0),
			   hi two bits of max cyl (bits 7-6)
			   DH = max head nr */ 
			DH_reg(context) = 0x01;
			switch (BL_reg(context))
			{
			    case 0: /* no drive */
				CX_reg(context) = 0x0;
				DX_reg(context) = 0x0;
				break;
			    case 1: /* 360 K */
				CX_reg(context) = 0x2709;
				break;
			    case 2: /* 1.2 M */
				CX_reg(context) = 0x4f0f;
				break;
			    case 3: /* 720 K */
				CX_reg(context) = 0x4f09;
				break;
			    case 4: /* 1.44 M */
				CX_reg(context) = 0x4f12;
				break;
			    case 5:
			    case 6: /* 2.88 M */
				CX_reg(context) = 0x4f24;
				break;
			}
			context->SegEs = 0x0000; /* FIXME: drive parameter table */
Alexandre Julliard's avatar
Alexandre Julliard committed
			DI_reg(context) = 0x0000;
#else
                	AH_reg(context) = 0x01;
                	SET_CFLAG(context);
                	break;
#endif
		}
Alexandre Julliard's avatar
Alexandre Julliard committed
		break;

        case 0x09:         /* INITIALIZE CONTROLLER WITH DRIVE PARAMETERS */
	case 0x0a:         /* FIXED DISK - READ LONG (XT,AT,XT286,PS)     */
	case 0x0b:	   /* FIXED DISK - WRITE LONG (XT,AT,XT286,PS)    */
Alexandre Julliard's avatar
Alexandre Julliard committed
	case 0x0c:         /* SEEK TO CYLINDER                            */
	case 0x0d:         /* ALTERNATE RESET HARD DISKS                  */
Alexandre Julliard's avatar
Alexandre Julliard committed
	case 0x10:         /* CHECK IF DRIVE READY                        */
	case 0x11:         /* RECALIBRATE DRIVE                           */
	case 0x14:         /* CONTROLLER INTERNAL DIAGNOSTIC              */
Alexandre Julliard's avatar
Alexandre Julliard committed
		AH_reg(context) = 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
		break;

	case 0x15:	   /* GET DISK TYPE (AT,XT2,XT286,CONV,PS) */
		if (DL_reg(context) & 0x80) { /* hard disk ? */
			AH_reg(context) = 3; /* fixed disk */
			SET_CFLAG(context);
		}
		else { /* floppy disk ? */
			AH_reg(context) = 2; /* floppy with change detection */
			SET_CFLAG(context);
		}
		break;
Alexandre Julliard's avatar
Alexandre Julliard committed
	case 0x0e:                    /* READ SECTOR BUFFER (XT only)      */
	case 0x0f:                    /* WRITE SECTOR BUFFER (XT only)     */
        case 0x12:                    /* CONTROLLER RAM DIAGNOSTIC (XT,PS) */
	case 0x13:                    /* DRIVE DIAGNOSTIC (XT,PS)          */
Alexandre Julliard's avatar
Alexandre Julliard committed
		AH_reg(context) = 0x01;
                SET_CFLAG(context);
Alexandre Julliard's avatar
Alexandre Julliard committed
		break;

	case 0x16:	   /* FLOPPY - CHANGE OF DISK STATUS */
		AH_reg(context) = 0; /* FIXME - no change */
		break;
Alexandre Julliard's avatar
Alexandre Julliard committed
	case 0x17:	   /* SET DISK TYPE FOR FORMAT */
		if (DL_reg(context) < 4)
		    AH_reg(context) = 0x00; /* successful completion */
		else
		    AH_reg(context) = 0x01; /* error */
		break;
	case 0x18:         /* SET MEDIA TYPE FOR FORMAT */
Alexandre Julliard's avatar
Alexandre Julliard committed
		if (DL_reg(context) < 4)
		    AH_reg(context) = 0x00; /* successful completion */
		else
		    AH_reg(context) = 0x01; /* error */
		break;
	case 0x19:	   /* FIXED DISK - PARK HEADS */
Alexandre Julliard's avatar
Alexandre Julliard committed
	default:
Alexandre Julliard's avatar
Alexandre Julliard committed
		INT_BARF( context, 0x13 );
Alexandre Julliard's avatar
Alexandre Julliard committed
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
}