move the ROM images into datapack

main
Walker Fowlkes 7 months ago
parent 1bcba4cc67
commit a6b0b194c2

@ -11,20 +11,30 @@ import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.item.v1.FabricItemSettings; import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder; import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder;
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
import net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.entity.BlockEntityType; import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.item.BlockItem; import net.minecraft.item.BlockItem;
import net.minecraft.registry.Registry; import net.minecraft.registry.Registry;
import net.minecraft.registry.Registries; import net.minecraft.registry.Registries;
import net.minecraft.resource.Resource;
import net.minecraft.resource.ResourceManager;
import net.minecraft.resource.ResourceType;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
public class RedControl implements ModInitializer { public class RedControl implements ModInitializer {
// This logger is used to write text to the console and the log file. // This logger is used to write text to the console and the log file.
// It is considered best practice to use your mod id as the logger's name. // It is considered best practice to use your mod id as the logger's name.
// That way, it's clear which mod wrote info, warnings, and errors. // That way, it's clear which mod wrote info, warnings, and errors.
public static final Logger LOGGER = LoggerFactory.getLogger("redcontrol"); public static final Logger LOGGER = LoggerFactory.getLogger("redcontrol");
public static final HashMap<String,byte[]> images = new HashMap<>();
//Blocks //Blocks
public static final CpuBlock CPU = new CpuBlock(FabricBlockSettings.create().strength(4.0f)); public static final CpuBlock CPU = new CpuBlock(FabricBlockSettings.create().strength(4.0f));
@ -43,6 +53,29 @@ public class RedControl implements ModInitializer {
// However, some things (like resources) may still be uninitialized. // However, some things (like resources) may still be uninitialized.
// Proceed with mild caution. // Proceed with mild caution.
ResourceManagerHelper.get(ResourceType.SERVER_DATA).registerReloadListener(new SimpleSynchronousResourceReloadListener() {
@Override
public Identifier getFabricId() {
return Identifier.of("redcontrol","image");
}
@Override
public void reload(ResourceManager manager) {
images.clear(); //remove all previous images
for(Map.Entry<Identifier,Resource> entry : manager.findResources("image", path -> true).entrySet()) {
try(InputStream stream = entry.getValue().getInputStream();) {
String[] split = entry.getKey().getPath().split("/");
String file = split[split.length-1];
LOGGER.info("Found image {}",file);
images.put(file,stream.readAllBytes());
} catch(Exception e) {
LOGGER.error("Error occurred while loading resource json {}", entry.getKey().toString(), e);
}
}
}
});
LOGGER.info("Initializing RedControl!"); LOGGER.info("Initializing RedControl!");
Registry.register(Registries.BLOCK, new Identifier("redcontrol", "cpu"), CPU); Registry.register(Registries.BLOCK, new Identifier("redcontrol", "cpu"), CPU);
Registry.register(Registries.BLOCK, new Identifier("redcontrol", "monitor"), MONITOR); Registry.register(Registries.BLOCK, new Identifier("redcontrol", "monitor"), MONITOR);

@ -24,12 +24,7 @@ public class Emulator {
cpu.setLogCallback(new LogConsumer()); cpu.setLogCallback(new LogConsumer());
cpu.setBus(new Bus(bus)); cpu.setBus(new Bus(bus));
ram = new Memory(0x0000, 0x2000 - 1, ((CpuAccessor)cpu).getRedBusState()); ram = new Memory(0x0000, 0x2000 - 1, ((CpuAccessor)cpu).getRedBusState());
try { ram.loadFromBytes(RedControl.images.get("rpcboot.bin"),0x400,0x100);
ram.loadFromFile(Paths.get("/home/astoria/code/java/mods/RedControl/src/main/resources/assets/redcontrol/image/rpcboot.bin"),0x400, 0x100);
} catch (IOException e) {
throw new RuntimeException(e);
}
cpu.getBus().addDevice(ram, ((CpuAccessor)cpu).getRedBusState()); cpu.getBus().addDevice(ram, ((CpuAccessor)cpu).getRedBusState());
cpu.reset(); cpu.reset();
ram.write(0, 2, ((CpuAccessor)cpu).getRedBusState()); ram.write(0, 2, ((CpuAccessor)cpu).getRedBusState());

@ -1,5 +1,6 @@
package net.brokenmoon.redcontrol.blockentities; package net.brokenmoon.redcontrol.blockentities;
import com.simon816.j65el02.device.ByteDiskDriver;
import com.simon816.j65el02.device.DiskDriver; import com.simon816.j65el02.device.DiskDriver;
import com.simon816.j65el02.device.FileDiskDriver; import com.simon816.j65el02.device.FileDiskDriver;
import net.brokenmoon.redcontrol.RedControl; import net.brokenmoon.redcontrol.RedControl;
@ -26,11 +27,7 @@ public class DriveEntity extends Peripheral{
public DriveEntity(BlockPos pos, BlockState state) { public DriveEntity(BlockPos pos, BlockState state) {
super(RedControl.DRIVE_BLOCK_ENTITY, pos, state, 2); super(RedControl.DRIVE_BLOCK_ENTITY, pos, state, 2);
try { this.driver = new ByteDiskDriver(RedControl.images.get("redforth.img"), "Forth", "FORTH");
this.driver = new FileDiskDriver(Paths.get("/home/astoria/code/java/mods/RedControl/src/main/resources/assets/redcontrol/image/redforth.img"), "Forth", "FORTH", false);
} catch (IOException e) {
throw new RuntimeException(e);
}
this.buffer = ByteBuffer.allocateDirect(SECTOR_SIZE); this.buffer = ByteBuffer.allocateDirect(SECTOR_SIZE);
byte[] name = driver.getDriveName(); byte[] name = driver.getDriveName();
byte[] serial = driver.getDriveSerial(); byte[] serial = driver.getDriveSerial();
@ -118,6 +115,7 @@ public class DriveEntity extends Peripheral{
} }
} catch (Exception e) { } catch (Exception e) {
this.command = 0xff; this.command = 0xff;
e.printStackTrace();
} }
} }
} }

Loading…
Cancel
Save