sikthehedgehog / mdtools

A set of tools for developing Mega Drive homebrew
76 stars 8 forks source link

Palette offset command for tilemap in mdtiler #8

Closed andwn closed 6 years ago

andwn commented 6 years ago

Similar to "offset" for tile index it would be nice if it were possible to specify which palette the tilemaps use.

Use case being I hate doing this:

uint16_t index = pal_mode ? 0 : 20;
for(uint16_t y = 0; y < (pal_mode ? 30 : 28); y++) {
    uint16_t maps[20];
    for(uint16_t x = 0; x < 20; x++) {
        maps[x] = illustration_info[id].map[index++] | (PAL2 << TILE_ATTR_PALETTE_SFT);
    }
    DMA_doDma(DMA_VRAM, (uint32_t) maps, VDP_PLAN_A + (y << 7) + (44 << 1), 20, 2);
}

instead of this:

uint16_t index = pal_mode ? 0 : 20;
for(uint16_t y = 0; y < (pal_mode ? 30 : 28); y++) {
    DMA_doDma(DMA_VRAM, (uint32_t) illustration_info[id].map[index], VDP_PLAN_A + (y << 7) + (44 << 1), 20, 2);
    index += 20;
}

and don't want to edit 17 images in GIMP to use index 32-47 instead of 0-15.

sikthehedgehog commented 6 years ago

You can probably add 16384 (0x4000) to the offset to achieve the same effect, forgot if there was a check against this. Noted though.

But yeah, I never bothered with that since I always have to add a value anyway (I have no idea where the assembler decided to place the base tile ID). Probably even better would be to make mdtiler output code (asm or C) so you can put it as part of any arbitrary expression and the assembler or compiler can handle this.

Also reminds me, I need to add a command to allow reassigning palette indices (for when the PNG doesn't match the colors actually used in the game).

andwn commented 6 years ago

I'll give it a shot. I could also probably add the command instead if making you do it :thinking:

Wonder what would be a good name though. palette_offset?

sikthehedgehog commented 6 years ago

Do any of the commands even have an underscore?

andwn commented 6 years ago

None of the other ones do, but a space would be more confusing. Maybe palindex, that's much shorter.

...I'm bad at naming things.

sikthehedgehog commented 6 years ago

Wouldn't it be paloffset? (or basepal but would be inconsistent with offset I guess) Taking an argument from 0 to 7 (0 to 3 for low priority, 4 to 7 for high priority)

I don't even know how to merge patches anyway x_x

Also you'll barf when you see batch.c (the file taking care of parsing commands). I need to clean up that file >_>

andwn commented 6 years ago

i'm sure it's fine have you seen my pause menu code? i still gotta try out adding 0x4000 when i get home

andwn commented 6 years ago

Well I can confirm a huge offset changes the palette (and I assume priority too). Now I have this script that generates scripts and does the math for me. 👀 https://github.com/andwn/cave-story-md/blob/dee7d0b80857b07cf9f15c098fd395164230c149/mdtgen.py

sikthehedgehog commented 6 years ago

Better idea: a way to remap each 16 color row instead of everything (with the defaults being 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, which maps to what mdtiler currently does).

sikthehedgehog commented 6 years ago

Check remappal command in 1.80:

remappal 0 -> 2