-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_rom.lua
50 lines (39 loc) · 1.51 KB
/
generate_rom.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
util = require "util"
rom = {}
directory =
"/home/kitten/プロジェクト/Gameboy/Badboy/tests/blargg/cpu_instrs/"
rom.filename = "cpu_instrs.gb"
rom.file = io.open(directory .. rom.filename, "r")
rom.data = {}
util.file_to_bytes(rom.file, rom.data, 0x0000)
if rom.filename ~= "bios.gb" then
rom.name = util.get_name()
rom.name_lower = rom.filename:lower():sub(1, -4):gsub("[^a-zA-Z0-9_]+", "")
if rom.name_lower == "" then
rom.name_lower = rom.name:lower():gsub("[^a-zA-Z0-9_]+", "")
end
rom.destination = "full_rom"
else
rom.name = "BIOS"
rom.name_lower = "bios"
rom.destination = "bios"
end
print(rom.name_lower)
rom.directory = "./CraftBoyDatapack/data/rom_" .. rom.name_lower .. "/"
os.execute("rm -r " .. rom.directory)
os.execute("mkdir " .. rom.directory)
os.execute("mkdir " .. rom.directory .. "functions/")
rom.mcfunction_rom = io.open(rom.directory .. "functions/" .. rom.name_lower ..
".mcfunction", "w")
if rom.destination == "bios" then
rom.mcfunction_rom:write("scoreboard objectives remove bios\n")
rom.mcfunction_rom:write("scoreboard objectives add bios dummy\n")
else
rom.mcfunction_rom:write("scoreboard objectives remove full_rom\n")
rom.mcfunction_rom:write("scoreboard objectives add full_rom dummy\n")
end
for i = 0, #rom.data do
rom.mcfunction_rom:write("scoreboard players set " .. i .. " " ..
rom.destination .. " " .. rom.data[i] .. "\n")
end
rom.mcfunction_rom:close()