Page 1 of 1

SGDK RESCOMP and the quest for two pallets on a single background layer

Posted: Sat Jan 19, 2019 8:32 pm
by Okoboji
So this is going to need some explaining. I want to put two pallets on a single background layer. I know this can be done because I've already done some tests to prove it. The question is how to make this efficient. So consider this code for updating a Foreground row to the buffer:

Code: Select all

void redrawForegroundColumn(u16 columnToUpdate)
{
    // Calculate where in the tilemap the new row's tiles are located.
    const u16* mapDataAddr = fgMap.tilemap + fgRowGroupOffsets[fgCameraTileY >> 3] + fgRowOffsets[fgCameraTileY & 7] + columnToUpdate;

    u16 columnBufferIdx = fgCameraTileY;

    // Copy the tiles into the buffer.
    u16 i;
    for (i = VDP_PLANE_TILE_HEIGHT; i != 0; i--)
    {
    	u16 baseTile = TILE_ATTR_FULL(PALLET, 0, 0, 0, fgTilesetStartIdx);
        columnBufferIdx &= 0x1F;  // columnBufferIdx MOD 32 (VDP_PLANE_TILE_HEIGHT)
        fgColumnBuffer[columnBufferIdx] = baseTile + *mapDataAddr;
        columnBufferIdx++;
        mapDataAddr += fgMap.w;
    }

    // Queue copying the buffer into VRAM.
    DMA_queueDma(DMA_VRAM, (u32) fgColumnBuffer, PLANE_FG + ((columnToUpdate & VDP_PLANE_TILE_WIDTH_MINUS_ONE) << 1), VDP_PLANE_TILE_HEIGHT, VDP_PLANE_TILE_WIDTH_TIMES_TWO);
}
Notice how the base tile is set in the loop. I will be able to set the pallet on the play with either a array or a separate function that looks at the tile being loaded and then it loads the proper pallet onto the buffer.

The problem I'm running into is Rescomp as far as I can tell has no provision for loading up maps with more than one pallet. Admittedly I could get around this problem by compiling the resource in a single pallet and then defining which tiles need other pallets later. But this will be a pain to hand define myself but if that's what needs to happen so be it.

However, this still means I have a problem with Rescomp's outputs. it exports images in assembly 16 bit words when the method I have needs 32 bit unsigned integers.

Code: Select all

nightGrass_tileset_tiles:
    dc.w    0x5555, 0x5555, 0x5555, 0x5555, 0x5555, 0x5555, 0x5555, 0x5555
    dc.w    0x5555, 0x5555, 0x5555, 0x5555, 0x5555, 0x5555, 0x5555, 0x5555
The output I need is a C array such as this one:

Code: Select all

const u32 TILEMAP_TEST_FG_TILES[TILEMAP_TEST_FG_TILE_COUNT][TILE_PIXEL_ROW_COUNT] =
{
    {
        0x11111111,
        0x14444444,
        0x14444444,
        0x14444444,
        0x14444444,
        0x14444444,
        0x14444444,
        0x14444444
    },
    {
        0x11111111,
        0x44444441,
        0x44444441,
        0x44444441,
        0x44444441,
        0x44444441,
        0x44444441,
        0x44444441
    },
    etc.
Does anyone know of a good solution to my problem? I would like to convert the Rescomp outputs into C arrays. I've though about writing a small program that would just turn everything into text. If there is a better way I would like to hear it.

Re: SGDK RESCOMP and the quest for two pallets on a single background layer

Posted: Sat Jan 19, 2019 8:53 pm
by Stef
Why do you want it as 32 bit in C ? You can always cast your 16bit data as 32 bit if needed. About the palette problem, you generated map should take care of multiple palette, if you use TILE_ATTR(PAL1...) then it will just add palette index from the image, so if you have 2 palettes it will use PAL 1 and PAL2.

Re: SGDK RESCOMP and the quest for two pallets on a single background layer

Posted: Sat Jan 19, 2019 9:16 pm
by Okoboji
Oh that's amazing I didn't know that the MAP system did that. I guess the problem is I haven't found any example code demonstrating the Map system so I'm just ignorant to how it works. If there is a demo lying around I could figure it out. I'll try knocking around with it and if I figure it out I'll put some example code up so other people know how to do it too.

edit: Also I should have asked setting the TIL_ATTR(pal1..) and then you can set a tile in the same map to pal2?

Re: SGDK RESCOMP and the quest for two pallets on a single background layer

Posted: Sat Jan 19, 2019 10:24 pm
by Stef
Yeah Indeed there is no example about it.
In fact TILE_ATTR(..) is just the base tile flags that Map data can complete. For now only the palette information can be completed from the map but I eventually plan to add the priority as well :-)