| 1 | package com.rox.cartridge; | |
| 2 | ||
| 3 | import java.io.IOException; | |
| 4 | import java.nio.file.Files; | |
| 5 | import java.nio.file.Path; | |
| 6 | ||
| 7 | /** Loads a ".nes" file into a {@link Cartridge}, dispatching to a {@link Mapper} by header mapper number. */ | |
| 8 | public final class RomLoader { | |
| 9 | private RomLoader(){ | |
| 10 | } | |
| 11 | ||
| 12 | /** Read and parse a ".nes" file from disk. */ | |
| 13 | public static Cartridge load(final Path path) throws IOException { | |
| 14 |
1
1. load : replaced return value with null for com/rox/cartridge/RomLoader::load → KILLED |
return fromBytes(Files.readAllBytes(path)); |
| 15 | } | |
| 16 | ||
| 17 | /** Parse already-in-memory iNES file bytes (e.g. a synthetic ROM built for a test/demo). */ | |
| 18 | public static Cartridge fromBytes(final byte[] fileBytes){ | |
| 19 | final INesRom rom = INesRom.parse(fileBytes); | |
| 20 | final Mapper mapper = switch (rom.mapperNumber()){ | |
| 21 | case 0 -> new NromMapper(rom); | |
| 22 | case 1 -> new Mmc1Mapper(rom); | |
| 23 | case 4 -> new Mmc3Mapper(rom); | |
| 24 | default -> throw new IllegalArgumentException("Unsupported mapper: " + rom.mapperNumber()); | |
| 25 | }; | |
| 26 |
1
1. fromBytes : replaced return value with null for com/rox/cartridge/RomLoader::fromBytes → KILLED |
return new Cartridge(rom, mapper); |
| 27 | } | |
| 28 | } | |
Mutations | ||
| 14 |
1.1 |
|
| 26 |
1.1 |