Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export HDA into img file #321

Open
mmaciola opened this issue Feb 15, 2025 · 0 comments
Open

Export HDA into img file #321

mmaciola opened this issue Feb 15, 2025 · 0 comments

Comments

@mmaciola
Copy link

mmaciola commented Feb 15, 2025

It is definitely necessary to be able to export files out from this emulator.
Currently windows95.img works one way only and state-v3.bin is not readable to extract files.

We need a function that will update the img file or understand why this is problematic.

My current attempts:

  /**
   * Save the emulator's modified disk image to disk.
   */
  private async saveDiskImage(): Promise<void> {
    const { emulator } = this.state;
    const imgPath = (await getStatePath()).replace('.bin', '.img');

    console.log(`saveDiskImage into:` + imgPath);

    if (!emulator || !emulator.disk_images || !emulator.disk_images.hda) {
      console.log(`saveDiskImage: No disk image present`);
      return;
    }

    try {
      // Convert SyncBuffer to a Uint8Array
      const diskBuffer = new Uint8Array(emulator.disk_images.hda);
  
      // Save the raw buffer as an .img file
      await fs.outputFile(imgPath, Buffer.from(diskBuffer));
      console.log(`Disk image saved to ${imgPath}`);
    } catch (error) {
      console.warn(`saveDiskImage: Could not save disk image`, error);
      fs.appendFileSync('log.txt', `saveDiskImage: Could not save disk image: ${error.message}\n${error.stack}\n`);
    }
  }

As I understand this won't work, having blocks, we could:

  // Apply modified blocks
  const blockSize = 0x200;
  for (const { sector, data } of writtenBlocks) {
    const offset = sector * blockSize;
    if (offset + data.length <= diskBuffer.length) {
      data.copy(diskBuffer, offset);
    } else {
      console.warn(`saveDiskImage: Block at sector ${sector} exceeds disk size`);
    }
  }
@mmaciola mmaciola changed the title Hda export into img file Export HDA into img file Feb 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant