summaryrefslogtreecommitdiff
path: root/DskImg.HC
blob: d2a0c931f7aaaba60f6597f8d89b891db6522034 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#define CYLINDERS 80
#define SECTORS 18
#define BASE 0x03F0
#define IMG_SIZE 1474560

/*
    Copyright (C) 2025 Harley Travis <yoshi128k@gmail.com>.
    This work is free. You can redistribute it and/or modify it under the
    terms of the Do What The Fuck You Want To Public License, Version 2,
    as published by Sam Hocevar. See the Copying.TXT file for more details.
*/

/*

  Make sure IRQ6 is on and
  pointed to the correct handler!

*/

U8 DskImg()
{
  U64 i;

  // Open image file for writing
  CFile *img = FOpen("Floppy.IMG","w",IMG_SIZE/BLK_SIZE);

  // Initialize the controller
  FDCReset(BASE);
  Sleep(100);

  /*

    Loop through each sector,
    reading each into the buffer,
    then writing it into the file

  */

  for (i = 0; i < CYLINDERS; i++) {
    "Track %d\n", i;
    if (FDCSeek(BASE, i, 0)) {
      FDCReset(BASE);
      FClose(img);
      return 1;
    }
    if (FDCSeek(BASE, i, 1)) {
      FDCReset(BASE);
      FClose(img);
      return 1;
    }
    FDCReadMulti(BASE, i, 0, 1, 18);
    FBlkWrite(img, &FDC_DMA, 36 * i, 36);
  }

  // Return to track 0
  "Returning to track 0...\n";
  if (FDCSeek(BASE, 0, 0)) {
    FDCReset(BASE);
    FClose(img);
    return 1;
  }
  if (FDCSeek(BASE, 0, 1)) {
    FDCReset(BASE);
    FClose(img);
    return 1;
  }

  // Close the image file
  FClose(img);

  return 0;
}

DskImg;