Skip to content

Commit

Permalink
fix: add plan map mode and fix palette entry mode
Browse files Browse the repository at this point in the history
  • Loading branch information
alekmaul committed Oct 4, 2023
1 parent 1c0c8cf commit 46ca005
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion tools/gfx4snes/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ where filename is a 256 color PNG or BMP file
- `-g` Include high priority bit in map
- `-y` Generate map in pages of 32x32 blocks (good for scrolling)
- `-R` No tile reduction (not advised)
- `-M (1|5|6|7)` Convert the whole picture for mode 1, 5, 6 or 7 format [1]
- `-M (1|5|6|7||9)` Convert the whole picture for mode 1, 5, 6 or 7 format, 9 is without map constraint [1]

### Palette options
- `-a` Rearrange palette, and preserve palette numbers in tilemap
Expand Down
4 changes: 2 additions & 2 deletions tools/gfx4snes/src/arguments.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ cmdp_action_t argument_callback(cmdp_process_param_st *params)
}

// check map mode (default is 1)
if ( (gfx4snes_args.mapscreenmode!=1) && (gfx4snes_args.mapscreenmode!=5) && (gfx4snes_args.mapscreenmode!=6) && (gfx4snes_args.mapscreenmode!=7) )
if ( (gfx4snes_args.mapscreenmode!=1) && (gfx4snes_args.mapscreenmode!=5) && (gfx4snes_args.mapscreenmode!=6) && (gfx4snes_args.mapscreenmode!=7) && (gfx4snes_args.mapscreenmode!=9) )
{
fatal("incorrect value for map mode format [%d]\nconversion terminated.", gfx4snes_args.mapscreenmode); // exit gfx4snes at this point
}
Expand Down Expand Up @@ -139,7 +139,7 @@ cmdp_action_t argument_callback(cmdp_process_param_st *params)
gfx4snes_args.paletteoutput=nbcols;
}
// check palette entry (default is 0)
if ( (gfx4snes_args.paletteentry<0) || (gfx4snes_args.paletteentry>2047) )
if ( (gfx4snes_args.paletteentry<0) || (gfx4snes_args.paletteentry>7) )
{
fatal("incorrect value for palette entry [%d]\nconversion terminated.", gfx4snes_args.paletteentry); // exit gfx4snes at this point
}
Expand Down
2 changes: 1 addition & 1 deletion tools/gfx4snes/src/gfx4snes.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ static cmdp_command_st gfx4snes_command = {
{0, 0, "Palettes options:\n", CMDP_TYPE_NONE, NULL,NULL},
{'a', "pal-rearrange", "rearrange palette and preserve palette numbers in tilemap", CMDP_TYPE_BOOL, &gfx4snes_args.paletterearrange},
{'d', "pal-rounded", "palette rounding (to a maximum value of 63)", CMDP_TYPE_BOOL, &gfx4snes_args.paletteround},
{'e', "pal-entry", "palette entry to add to map tiles {0..15}", CMDP_TYPE_INT4, &gfx4snes_args.paletteentry},
{'e', "pal-entry", "palette entry to add to map tiles {0..7}", CMDP_TYPE_INT4, &gfx4snes_args.paletteentry},
{'o', "pal-col-output", "number of colors to output to filename.pal {0..256}", CMDP_TYPE_INT4, &gfx4snes_args.paletteoutput},
{'p', "pal-output", "include palette for output", CMDP_TYPE_BOOL, &gfx4snes_args.palettesave},
{'u', "pal-col-use", "number of colors to use {4,16,128,[256]}", CMDP_TYPE_INT4, &gfx4snes_args.palettecolors},
Expand Down
19 changes: 13 additions & 6 deletions tools/gfx4snes/src/maps.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ unsigned short *map_convertsnes (unsigned char *imgbuf, int *nbtiles, int blksiz
blksizex = 16;
if (!isquiet) info("will use specific mode 5 & 6 values %d block for x, with tile size %dx%d...",nbblockx,16,blksizey);
}

// if mode 9, just put an infomation message
if (graphicmode==9)
{
if (!isquiet) info("will use specific mode without constrainst for %dx%d blocks with tile size %dx%d...",nbblockx,nbblocky,blksizex,blksizey);
}
// size of a tile block (64 bytes for a 8x8 block)
sizetile = blksizex*blksizey;

Expand All @@ -77,23 +81,22 @@ unsigned short *map_convertsnes (unsigned char *imgbuf, int *nbtiles, int blksiz
fatal("can't allocate enough memory for the buffer in map_convertsnes");
}

// clear map
//memset(map, 0, nbblockx * nbblocky * sizeof(unsigned short));
// some information
if (!isquiet) info("managed a map of %dx%d tiles of %dx%d pixels...",nbblockx,nbblocky,blksizex,blksizey);
if ( !isquiet && is32size) info("rearrange map for 32x32 scrolling...");

// add the palette number to tiles
if (!isquiet) info("add palette entry #%d to tiles in map...",offsetpal);
currenttile = 0;

for (y = 0; y < nbblocky; y++)
{
for (x = 0; x < nbblockx; x++)
{
// get the palette number (0-7 for both 4 & 16 color mode)
paletteno = (nbcolors != 4) ? (imgbuf[currenttile * sizetile] >> 4) & 0x07 : (imgbuf[currenttile * sizetile] >> 2) & 0x07;
tilevalue = ((paletteno + offsetpal) << 10);

if ((tilevalue>>10)>=8) warning ("out of bounds palette %d for tile %d",currenttile,paletteno);

if ((graphicmode==5) || (graphicmode==6))
{
map[y * nbblockx + x] = tilevalue;
Expand Down Expand Up @@ -123,6 +126,10 @@ unsigned short *map_convertsnes (unsigned char *imgbuf, int *nbtiles, int blksiz
else
map[(y + 96 - 32) * 32 + x - 32] = tilevalue;
}
else if (graphicmode==9)
{
map[y * nbblockx + x] = tilevalue;
}
else if (is32size == 1)
{
// create pages of 32x32
Expand Down Expand Up @@ -275,7 +282,7 @@ unsigned short *map_convertsnes (unsigned char *imgbuf, int *nbtiles, int blksiz
int idx = x_mult * 1024 + y * 32 + new_x;
map[idx] += tilevalue;
}
else // 32x32 or 128x128 screen
else // 32x32 or 128x128 screen or with no constrainst
{
map[y * nbblockx + x] += tilevalue;
}
Expand Down

0 comments on commit 46ca005

Please sign in to comment.