Subversion Repositories pentevo

Rev

Blame | Last modification | View Log | Download | RSS feed | ?url?

  1. #include "std.h"
  2.  
  3. #include "emul.h"
  4. #include "vars.h"
  5. #include "snapshot.h"
  6. #include "fdd.h"
  7.  
  8. #include "util.h"
  9.  
  10. int FDD::index()
  11. {
  12.    return int(this - comp.fdd);
  13. }
  14.  
  15. // return: 0 - CANCEL, 1 - YES/SAVED, 2 - NOT SAVED
  16. char FDD::test()
  17. {
  18.    if (!optype) return 1;
  19.  
  20.    static char changed[] = "Disk A: changed. Save ?"; changed[5] = char(index()+'A');
  21.    int r = MessageBox(GetForegroundWindow(), changed, "Save disk", exitflag? MB_ICONQUESTION | MB_YESNO : MB_ICONQUESTION | MB_YESNOCANCEL);
  22.    if (r == IDCANCEL) return 0;
  23.    if (r == IDNO) return 2;
  24.    // r == IDYES
  25.    unsigned char *image = (unsigned char*)malloc(sizeof snbuf);
  26.    memcpy(image, snbuf, sizeof snbuf);
  27.    savesnap(index());
  28.    memcpy(snbuf, image, sizeof snbuf);
  29.    ::free(image);
  30.  
  31.    if (*(volatile char*)&optype) return 0;
  32.    return 1;
  33. }
  34.  
  35. void FDD::free()
  36. {
  37.    if (rawdata)
  38.        VirtualFree(rawdata, 0, MEM_RELEASE);
  39.  
  40.    motor = 0;
  41.    track = 0;
  42.  
  43.    rawdata = nullptr;
  44.    rawsize = 0;
  45.    cyls = 0;
  46.    sides = 0;
  47.    name[0] = 0;
  48.    dsc[0] = 0;
  49.    memset(trklen, 0,  sizeof(trklen));
  50.    memset(trkd, 0,  sizeof(trkd));
  51.    memset(trki, 0,  sizeof(trki));
  52.    memset(trkwp, 0,  sizeof(trkwp));
  53.    optype = 0;
  54.    snaptype = 0;
  55.    conf.trdos_wp[index()] = 0;
  56.    /*comp.wd.trkcache.clear(); [vv]*/
  57.    t.clear();
  58. }
  59.  
  60. void FDD::newdisk(unsigned cyls, unsigned sides)
  61. {
  62.    free();
  63.  
  64.    FDD::cyls = cyls; FDD::sides = sides;
  65.    unsigned len = MAX_TRACK_LEN;
  66.    unsigned bitmap_len = unsigned(len+7U) >> 3;
  67.    unsigned len2 = len + bitmap_len*2;
  68.    rawsize = align_by(MAX_CYLS * sides * len2, 4096U);
  69.    rawdata = (unsigned char*)VirtualAlloc(nullptr, rawsize, MEM_COMMIT, PAGE_READWRITE);
  70.    // ZeroMemory(rawdata, rawsize); // already done by VirtualAlloc
  71.  
  72.    for (unsigned c = 0; c < MAX_CYLS; c++)
  73.    {
  74.       for (unsigned h = 0; h < sides; h++)
  75.       {
  76.          trklen[c][h] = len;
  77.          trkd[c][h] = rawdata + len2*(c*sides + h);
  78.          trki[c][h] = trkd[c][h] + len;
  79.          trkwp[c][h] = trkd[c][h] + len + bitmap_len;
  80.       }
  81.    }
  82.    // comp.wd.trkcache.clear(); // already done in free()
  83. }
  84.  
  85. int FDD::read(unsigned char type)
  86. {
  87.    int ok = 0;
  88.    switch(type)
  89.    {
  90.    case snTRD: ok = read_trd(); break;
  91.    case snUDI: ok = read_udi(); break;
  92.    case snHOB: ok = read_hob(); break;
  93.    case snSCL: ok = read_scl(); break;
  94.    case snFDI: ok = read_fdi(); break;
  95.    case snTD0: ok = read_td0(); break;
  96.    case snISD: ok = read_isd(); break;
  97.    case snPRO: ok = read_pro(); break;
  98.    case snDSK: ok = read_dsk(); break;
  99.    case snIPF: ok = read_ipf(); break;
  100.    }
  101.    return ok;
  102. }
  103.  
  104. bool done_fdd(bool Cancelable)
  105. {
  106.    for(int i = 0; i < 4; i++)
  107.       if(!comp.fdd[i].test() && Cancelable)
  108.           return false;
  109.    return true;
  110. }
  111.