Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add wrapping of HFS disk images into full device images
Required for allowing DingusPPC to boot from disk images. Also allows Saved HD to be exported to an .hda file that can be used with BlueSCSI and other software that expects a full device image. The base device image header was generated by Disk Jockey 2.5.2.2 (it's the first 0xc000 or 48 KB of an empty device image - the HFS image can be appended to it and a couple of fields be updated). Updates #219 Updates #234
- Loading branch information
Showing
19 changed files
with
201 additions
and
22 deletions.
There are no files selected for viewing
Git LFS file not shown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,6 +89,6 @@ | |
color: #00c; | ||
} | ||
|
||
.Dialog-Cancel { | ||
.Dialog-Normal-Button { | ||
font-weight: normal; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const BLOCK_SIZE = 512; | ||
|
||
export function generateDeviceImageHeader( | ||
baseHeader: ArrayBuffer, | ||
hfsPartitionSize: number | ||
): ArrayBuffer { | ||
const headerSize = baseHeader.byteLength; | ||
if (headerSize !== 0xc000) { | ||
console.warn( | ||
"Expected base header to be 0xc000 bytes, got 0x" + | ||
headerSize.toString(16) + | ||
" bytes, results may be unpredictable" | ||
); | ||
} | ||
const header = baseHeader.slice(0); | ||
const headerView = new DataView(header); | ||
|
||
const totalSize = hfsPartitionSize + headerSize; | ||
const totalBlocks = totalSize / BLOCK_SIZE; | ||
headerView.setInt32(0x4, totalBlocks); // sbBlkCount | ||
|
||
const hfsBlocks = hfsPartitionSize / BLOCK_SIZE; | ||
headerView.setInt32(0x060c, hfsBlocks); // pmPartBlkCnt? | ||
headerView.setInt32(0x0654, hfsBlocks); // pmDataCnt? | ||
|
||
return header; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import {generateDeviceImageHeader} from "./emulator-common-device-image"; | ||
import {type EmulatorWorkerDisk} from "./emulator-worker-disks"; | ||
|
||
export class EmulatorWorkerDeviceImageDisk implements EmulatorWorkerDisk { | ||
#disk: EmulatorWorkerDisk; | ||
#deviceHeader: ArrayBuffer; | ||
|
||
constructor(disk: EmulatorWorkerDisk, baseDeviceHeader: ArrayBuffer) { | ||
this.#disk = disk; | ||
this.#deviceHeader = generateDeviceImageHeader( | ||
baseDeviceHeader, | ||
disk.size | ||
); | ||
} | ||
|
||
get name(): string { | ||
return this.#disk.name; | ||
} | ||
|
||
get size(): number { | ||
return this.#disk.size + this.#deviceHeader.byteLength; | ||
} | ||
|
||
read(buffer: Uint8Array, offset: number, length: number): number { | ||
if (offset < this.#deviceHeader.byteLength) { | ||
if (offset + length > this.#deviceHeader.byteLength) { | ||
throw new Error( | ||
"Cannot read from both device header and disk in one op" | ||
); | ||
} | ||
buffer.set(new Uint8Array(this.#deviceHeader, offset, length)); | ||
return length; | ||
} | ||
const diskOffset = offset - this.#deviceHeader.byteLength; | ||
return this.#disk.read(buffer, diskOffset, length); | ||
} | ||
|
||
write(buffer: Uint8Array, offset: number, length: number): number { | ||
if (offset < this.#deviceHeader.byteLength) { | ||
if (offset + length > this.#deviceHeader.byteLength) { | ||
throw new Error( | ||
"Cannot write to both device header and disk in one op" | ||
); | ||
} | ||
|
||
new Uint8Array(this.#deviceHeader, offset).set( | ||
buffer.subarray(0, length) | ||
); | ||
return length; | ||
} | ||
const diskOffset = offset - this.#deviceHeader.byteLength; | ||
return this.#disk.write(buffer, diskOffset, length); | ||
} | ||
|
||
validate?(): void { | ||
this.#disk.validate?.(); | ||
} | ||
} |
Oops, something went wrong.