File loaders
Use emuLib’s FileLoader to read BIN, Intel HEX (I8HEX), TAP, or TZX files. The loader calls your listener as it reads each block. Use the same block interface to load program bytes into memory or pass tape blocks to a playback device.
Reading blocks
FileLoader.Format format = FileLoader.Format.fromPath(path).orElse(FileLoader.Format.BIN);
FileLoader.load(path, format, block -> {
byte[] bytes = block.getData();
// Inspect, export or consume the block's bytes and metadata.
});
BIN provides the file’s bytes in a single block without an address. Intel HEX provides one block per contiguous address range. Use Format.fromPath() to choose the format from the extension. Fall back to BIN only if your tool accepts raw bytes for unknown extensions.
Use IntelHEX.parse(path) when you need an address-to-byte map. It ignores checksums and reports malformed input with its line number.
Loading into memory
For BIN and HEX, a plugin can consume the same API directly:
FileLoader.load(path, format, block -> {
int address = block.getAddress().orElse(startAddress);
memory.write(address, Numbers.nativeBytesToBytes(block.getData()));
});
For TAP/TZX, byte-mem pairs Spectrum CODE headers with subsequent data blocks using shared packet/header decoding. The plugin validates checksums, declared lengths and complete turbo bytes; it ignores BASIC/arrays and rejects unsupported TZX blocks. Each load has fresh pairing state. Memory placement is a plugin responsibility. Direct loading does not execute BASIC or decode custom loaders and recordings into memory.
Tape playback
FileLoader.Format format = FileLoader.Format.fromPath(path)
.filter(FileLoader.Format::isTape)
.orElseThrow(() -> new IOException("Unsupported tape file"));
FileLoader.load(path, format, tapeListener);
Use TapeListener when you need playback signals such as pulses and pauses. Pulse lengths are in Z80 T-states. The loader follows TZX jumps, loops, and calls. The device schedules the resulting signals against guest time.
Interrupt the loading thread to cancel loading. Use a separate stateful listener for each concurrent load.