kirjavascript / Flex2

sega megadrive sprite editor
MIT License
57 stars 4 forks source link

[Suggestion] Sonic Crackers mapping/DPLC support #63

Open MDTravisYT opened 11 months ago

MDTravisYT commented 11 months ago

Sonic Crackers is an extremely early prototype of Chaotix, which still runs primarily on the Mega Drive, Investigating its mappings/DPLC format, it's very different from what the main classics use, which makes sense as it runs on a completely new engine. I may not have the skill to add a custom script to Flex 2 for Crackers currently, if that's even possible, but I hope support for it gets added to the main program someday. Documentation is present in Markey Jester's disassembly.

Mappings documentation from disassembly: ; Guide as Documented by Hivebrain ; ; Each mappings block consists of six bytes: ; ; dc.b $SS,$YY,$TT,$TT,$XX,$ZZ ; ; $SS = Shape and size of sprite piece ; $YY = Y position of sprite piece ; $TTTT = Tile to read in VRam ; $XX = X position of sprite piece ; $ZZ = whether it's the last map to use in the sprite or not (00 Include next map in sprite/FF End of sprite) ; DPLC documentation from disassembly: ; --------------------------------------------------------------------------- ; PLC and Mapping Main Index Block - Sonic ; --------------------------------------------------------------------------- ; An Example of the setout: ; ; vvMapping Pointersvv vvPLC Pointersvv ; ; dc.w "Location"-Map_Sonic, "Location"-PLC_Sonic ; dc.w "Location"-Map_Sonic, "Location"-PLC_Sonic ; dc.w "Location"-Map_Sonic, "Location"-PLC_Sonic ; etc, etc ; ---------------------------------------------------------------------------

kirjavascript commented 11 months ago

flexcrackers

I managed to read the crackers mapping data

However, each sprite image seems to use a label that I need to retain if I want to support writing

MDTravisYT commented 11 months ago

Awesome! I may not need writing just yet, but reading will absolutely help me work with this stuff. Thanks for this!

kirjavascript commented 11 months ago

in that case you can use this script for reading only;

// Flex 2 Mapping Definition - Sonic Crackers

const {
    mappings,
    dplcs,
    offsetTable,
    write,
    read,
    dc,
    nybble,
    endFrame,
    skipFrame,
    signed,
    asm,
} = Flex2;

mappings([
    [
        () => {
            return (({ mapping }) => {
                read(nybble);
                mapping.width = read(2) + 1;
                mapping.height = read(2) + 1;
                mapping.top = read(dc.b, signed);
                mapping.art = read(dc.w) - 1692;
                mapping.left = read(dc.b, signed);
                mapping.palette = 0;
                mapping.priority = 0;
                mapping.vflip = 0;
                mapping.hflip = 0
                if (read(dc.b) === 0xFF) return endFrame;
            });
        },
        ({ sprite }) => {
            return ({ mapping }, frameIndex) => {
                write(nybble, 0);
                write(2, mapping.width - 1);
                write(2, mapping.height - 1);
                write(dc.b, mapping.top);
                write(dc.w, mapping.art + 1692);
                write(dc.b, mapping.left);
                // 0 or FF depending on last one
            };
        },
    ],
]);

dplcs([
    [
        () => {
            return (({ mapping }) => {
                const tiles = read(dc.w);
                read(dc.w); // dma src
                const addr = read(12);
                read(4);
                read(dc.w); // dma dst
                read(dc.w); // end of plc

                const swapped = (tiles >> 8) + ((tiles & 0xFF) << 8);
                mapping.size = swapped / 0x10;
                mapping.art = addr;
                return endFrame;
            });
        },
        ({ sprite }) => {
        },
    ],
]);
MDTravisYT commented 11 months ago

It appears that each map has its own tile offset. Instead of manually modifying the script each time, it'd be neat to have some form of way to edit the tile offset the art is loaded to/read from.

kirjavascript commented 7 months ago

I have added an extra input for the tile offset and it'll be available in the next version!