dmolony-DiskBrowser/src/com/bytezone/diskbrowser/prodos/write/ExtendedKeyBlock.java

124 lines
4.4 KiB
Java
Raw Normal View History

2021-05-03 20:12:44 +00:00
package com.bytezone.diskbrowser.prodos.write;
import com.bytezone.diskbrowser.utilities.Utility;
// -----------------------------------------------------------------------------------//
public class ExtendedKeyBlock
// -----------------------------------------------------------------------------------//
{
private final ProdosDisk disk;
private final int ptr;
2021-05-05 04:32:38 +00:00
private MiniEntry dataFork;
private MiniEntry resourceFork;
enum ForkType
{
DATA, RESOURCE;
}
2021-05-03 20:12:44 +00:00
// ---------------------------------------------------------------------------------//
2021-05-03 21:24:08 +00:00
public ExtendedKeyBlock (ProdosDisk disk, int ptr)
2021-05-03 20:12:44 +00:00
// ---------------------------------------------------------------------------------//
{
this.disk = disk;
this.ptr = ptr;
}
// ---------------------------------------------------------------------------------//
2021-05-05 04:32:38 +00:00
void addMiniEntry (ForkType type, FileEntry fileEntry)
// ---------------------------------------------------------------------------------//
{
addMiniEntry (type, fileEntry.storageType, fileEntry.keyPointer, fileEntry.blocksUsed,
fileEntry.eof);
}
// ---------------------------------------------------------------------------------//
void addMiniEntry (ForkType type, FileWriter fileWriter)
2021-05-03 20:12:44 +00:00
// ---------------------------------------------------------------------------------//
{
2021-05-05 04:32:38 +00:00
addMiniEntry (type, fileWriter.storageType, fileWriter.keyPointer,
fileWriter.blocksUsed, fileWriter.eof);
}
2021-05-03 20:12:44 +00:00
2021-05-05 04:32:38 +00:00
// ---------------------------------------------------------------------------------//
private void addMiniEntry (ForkType type, byte storageType, int keyPointer,
int blocksUsed, int eof)
// ---------------------------------------------------------------------------------//
{
if (type == ForkType.DATA)
dataFork = new MiniEntry (storageType, keyPointer, blocksUsed, eof);
2021-05-03 20:12:44 +00:00
else
2021-05-05 04:32:38 +00:00
resourceFork = new MiniEntry (storageType, keyPointer, blocksUsed, eof);
2021-05-03 20:12:44 +00:00
}
// ---------------------------------------------------------------------------------//
void read (byte[] buffer)
// ---------------------------------------------------------------------------------//
{
if (buffer[ptr] != 0)
dataFork = new MiniEntry (buffer, 0);
if (buffer[ptr + 0x100] != 0)
resourceFork = new MiniEntry (buffer, 0x100);
}
// ---------------------------------------------------------------------------------//
void write ()
// ---------------------------------------------------------------------------------//
{
if (dataFork != null) // else zero buffer??
2021-05-03 21:24:08 +00:00
dataFork.write (disk.getBuffer (), ptr);
2021-05-03 20:12:44 +00:00
if (resourceFork != null)
2021-05-03 21:24:08 +00:00
resourceFork.write (disk.getBuffer (), ptr + 0x100);
2021-05-03 20:12:44 +00:00
}
// ---------------------------------------------------------------------------------//
class MiniEntry
// ---------------------------------------------------------------------------------//
{
byte storageType; // uses low nibble
int keyBlock;
int blocksUsed;
int eof;
// -------------------------------------------------------------------------------//
MiniEntry (byte[] buffer, int ptr)
// -------------------------------------------------------------------------------//
{
read (buffer, ptr);
}
// -------------------------------------------------------------------------------//
MiniEntry (byte storageType, int keyBlock, int blocksUsed, int eof)
// -------------------------------------------------------------------------------//
{
this.storageType = storageType;
this.keyBlock = keyBlock;
this.blocksUsed = blocksUsed;
this.eof = eof;
}
// -------------------------------------------------------------------------------//
void read (byte[] buffer, int ptr)
// -------------------------------------------------------------------------------//
{
storageType = buffer[ptr];
keyBlock = Utility.getShort (buffer, ptr + 1);
blocksUsed = Utility.getShort (buffer, ptr + 3);
2021-05-03 20:12:44 +00:00
eof = Utility.readTriple (buffer, ptr + 5);
}
// -------------------------------------------------------------------------------//
void write (byte[] buffer, int ptr)
// -------------------------------------------------------------------------------//
{
buffer[ptr] = storageType;
Utility.writeShort (buffer, ptr + 1, keyBlock);
Utility.writeShort (buffer, ptr + 3, blocksUsed);
Utility.writeTriple (buffer, ptr + 5, eof);
}
}
}