U0 InstallDrive(U8 drv_let)
{
    U8 *st;

    while (!DriveCheck(blkdev.let_to_drive[drv_let - 'A'], FALSE))
        Sleep(1);
    Sleep(1000);

    ExePrint("CopyTree(\"::/\",\"%C:/\");",         drv_let);
    ExePrint("DirMake(\"%C:/Tmp\");",               drv_let);
    ExePrint("DirMake(\"%C:/Tmp/ScreenShots\");",   drv_let);
    ExePrint("DirMake(\"%C:/Home\");",              drv_let);

    st = MStrPrint("%C:/Home/DoDistro.ZC", drv_let);
    if (!FileFind(st))
        Copy("::/Misc/DoDistro.ZC", st);
    Free(st);

    st = MStrPrint("%C:/Home/MakeHome.ZC", drv_let);
    if (!FileFind(st))
        Copy("::/MakeHome.ZC", st);
    Free(st);
}

Bool VMPartDisk(CTask *task, I64 ata_port)
{
    if (ata_port > -1)
    {
        XTalkWait(task, "DiskPart(,1.0);\nC\n%d\nY", ata_port); // DOUBLE CHECK INFILE
        return TRUE;
    }
    else
        return FALSE;
}

U0 VMInstallDrive(CTask *task, U8 drv_let, I64 ata_port, I64 atapi_port)
{// DOUBLE CHECK INFILE
    InstallDrive(drv_let);
    XTalkWait(task, "BootHDIns('%C');\n\nB\n0x20000\n", drv_let);
    if (ata_port > -1)
        XTalkWait(task, "C\n%d\n", ata_port);
    if (atapi_port > -1)
        XTalkWait(task, "T%d\n", atapi_port);
    XTalkWait(task, "\n\n\n"); //Exit Drives, skip Disk Cache and Options
}

U0 VMInstallWiz()
{
    CTask       *task;
    I64          i, atapi_port = -1, ata_port = -1;
    CAHCIPort   *port;

    task = User;
    TaskWait(task);
    task->border_src    = BDS_CONST;
    task->border_attr   = LTGRAY << 4 + DriveTextAttrGet(':') & 15;
    task->text_attr     = LTGRAY << 4 + BLUE;
    task->win_inhibit   = WIG_TASK_DEFAULT - WIF_SELF_BORDER;
    WinHorz(Fs->win_left, Fs->win_right, task);
    WinVert(Fs->win_top,  (Fs->win_top + Fs->win_bottom) >> 2 - 1, task);
    WinVert(task->win_bottom + 3, Fs->win_bottom);
    WinToTop(Fs);


    ////////////////////////////////////
    SATARep;
    for (i = 0; i < AHCI_MAX_PORTS; i++)
    {
        if (PCIBt(&blkdev.ahci_hba->ports_implemented, i))
        {
            port = &blkdev.ahci_hba->ports[i];
            if (port->signature == AHCI_PxSIG_ATA)
            {
                ata_port = i;
                break;
            }
        }
    }
    for (i = 0; i < AHCI_MAX_PORTS; i++)
    {
        if (PCIBt(&blkdev.ahci_hba->ports_implemented, i))
        {
            port = &blkdev.ahci_hba->ports[i];
            if (port->signature == AHCI_PxSIG_ATAPI)
            {
                atapi_port = i;
                break;
            }
        }
    }

    if (VMPartDisk(task, ata_port))
    {
        VMInstallDrive(task, 'C', ata_port, atapi_port);
        BootMHDIns('C');
    }

    Copy("::/Misc/Auto/BootMHD2.ZC", "C:/System/Boot/BootMHD2.ZC");

    ////////////////////////////////////

    WinVert(task->win_top, Fs->win_bottom);
    Kill(task);
}

Bool DoInstall()
{
    I64 res = FALSE, vm_install = TRUE;

    vm_install = TRUE;
    DocBottom;
    VMInstallWiz();
    res = TRUE;
    OnceDrive('C', "PopUp(\"#include \\\"/Misc/Auto/AutoFullDistro0\\\";\");");
    BootRAM("C:" BOOT_DIR_KERNEL_ZXE);
    return res;
}

Bool OSInstall()
{
    return DoInstall();
}

#if __CMD_LINE__
OSInstall();
#endif