WIP FT_000

This commit is contained in:
Luciano Ciccariello 2023-11-20 18:53:43 +00:00
parent a460b833f7
commit 049493c95a
5 changed files with 102 additions and 11 deletions

View File

@ -233,10 +233,7 @@ $(BUILD_DIR)/RWRP.BIN: $(BUILD_DIR)/strwrp.elf
$(BUILD_DIR)/F_RWRP.BIN:
$(GFXSTAGE) e assets/st/rwrp $@
tt_000: tt_000_dirs $(BUILD_DIR)/TT_000.BIN
$(BUILD_DIR)/TT_000.BIN: $(BUILD_DIR)/tt_000.elf
$(OBJCOPY) -O binary $< $@
printf '\x00' | dd of=$@ bs=1 seek=40959 count=1 conv=notrunc
tt_000: tt_000_dirs $(BUILD_DIR)/TT_000.BIN $(BUILD_DIR)/FT_000.BIN
mad_fix: stmad_dirs $$(call list_o_files,st/mad) $$(call list_o_files,st)
$(LD) $(LD_FLAGS) -o $(BUILD_DIR)/stmad_fix.elf \

View File

@ -57,3 +57,9 @@ $(BUILD_DIR)/assets/st/sel/memcard_%.png.o: assets/st/sel/memcard_%.png
rm $(BUILD_DIR)/assets/st/sel/memcard_$*.png.s
$(AS) $(AS_FLAGS) -o $(BUILD_DIR)/assets/st/sel/memcard_$*.pal.o $(BUILD_DIR)/assets/st/sel/memcard_$*.pal.s
rm $(BUILD_DIR)/assets/st/sel/memcard_$*.pal.s
$(BUILD_DIR)/TT_%.BIN: $(BUILD_DIR)/tt_%.elf
$(OBJCOPY) -O binary $< $@
printf '\x00' | dd of=$@ bs=1 seek=40959 count=1 conv=notrunc
$(BUILD_DIR)/FT_%.BIN: disks/$(VERSION)/SERVANT/FT_%.BIN
cp $< $@

View File

@ -22,3 +22,4 @@ c1284f0c662f3c8fdb8a7c17cebf8e5cf1d96c1b build/us/F_WRP.BIN
3bbdd3b73f8f86cf5f6c88652e9e6452a7fb5992 build/us/RWRP.BIN
ee1aaa34f3464b1d1cd72052cec7a4b9089d1887 build/us/F_RWRP.BIN
82dd4ae1c4e3dc0fd483a49e5e4ab4fc5e25ada7 build/us/TT_000.BIN
43776ee1b830dd601e3fa06d7311152db15c7e1d build/us/FT_000.BIN

View File

@ -18,7 +18,6 @@ options:
use_legacy_include_asm: no
migrate_rodata_to_functions: no
asm_jtbl_label_macro: jlabel
extensions_path: tools/splat_ext
section_order:
- ".data"
- ".rodata"

View File

@ -2,6 +2,31 @@
import argparse
import png
import n64img.image
from typing import List, Tuple
def generate_grey_palette() -> List[Tuple[int, int, int, int]]:
def generate_grey_color(intensity: int) -> Tuple[int, int, int, int]:
return intensity, intensity, intensity, 255
return [
generate_grey_color(0x00),
generate_grey_color(0x11),
generate_grey_color(0x22),
generate_grey_color(0x33),
generate_grey_color(0x44),
generate_grey_color(0x55),
generate_grey_color(0x66),
generate_grey_color(0x77),
generate_grey_color(0x88),
generate_grey_color(0x99),
generate_grey_color(0xAA),
generate_grey_color(0xBB),
generate_grey_color(0xCC),
generate_grey_color(0xDD),
generate_grey_color(0xEE),
]
def get_encoded_image(file_name: str) -> bytearray:
@ -35,12 +60,75 @@ def get_encoded_image(file_name: str) -> bytearray:
return data
parser = argparse.ArgumentParser(description="convert 4bpp PNGs into binary")
parser.add_argument("input")
parser.add_argument("output")
def encode(input, output):
data = get_encoded_image(input)
with open(output, "wb") as f_out:
f_out.write(data)
def decode_image(data: bytes, output: str, w: int, h: int, bpp: int):
if bpp == 4:
img = n64img.image.CI4(data, w, h)
elif bpp == 8:
img = n64img.image.CI8(data, w, h)
else:
raise f"bpp '{bpp}' invalid"
img.little_endian = True
img.palette = generate_grey_palette()
img.write(output)
def decode(input: str, output: str, w: int, h: int, bpp: int):
with open(input, "rb") as f_out:
raw_data = f_out.read()
img_size = int(w * h * bpp / 8)
img_count = int(len(raw_data) / img_size)
print(f"img_size: {img_size}")
print(f"img_count: {img_count}")
if img_count == 1:
decode_image(raw_data, output, w, h, bpp)
else:
image_base_name = output.replace(".png", "").replace(".PNG", "")
in_data = raw_data
for i in range(0, img_count):
name = f"{image_base_name}_{i}.png"
decode_image(in_data[:img_size], name, w, h, bpp)
in_data = in_data[img_size:]
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="convert images between PNG and BIN")
subparsers = parser.add_subparsers(dest="command")
encode_parser = subparsers.add_parser(
"encode",
description="Encode a PNG file into BIN",
)
encode_parser.add_argument("input")
encode_parser.add_argument("output")
decode_parser = subparsers.add_parser(
"decode",
description="Encode a BIN file into PNG",
)
decode_parser.add_argument("input")
decode_parser.add_argument("output")
decode_parser.add_argument(
"--bpp", "-b", type=int, help="Bits per pixel: 4 = 4bpp (default), 8 = 8bpp"
)
decode_parser.add_argument("--width", type=int, help="Image width (default: 128)")
decode_parser.add_argument("--height", type=int, help="Image height (default: 128)")
args = parser.parse_args()
data = get_encoded_image(args.input)
with open(args.output, "wb") as f_out:
f_out.write(data)
if args.command == "encode":
encode(args.input, args.output)
elif args.command == "decode":
if not args.bpp:
args.bpp = 4
if not args.width:
args.width = 128
if not args.height:
args.height = 128
decode(args.input, args.output, args.width, args.height, args.bpp)
else:
parser.print_help()