Skip to content

Commit

Permalink
[Maintenance] [th01] .GRC: Define the slot count in terms of used slo…
Browse files Browse the repository at this point in the history
…t IDs

Part of P0165, funded by Ember2528.
  • Loading branch information
nmlgc committed Nov 7, 2021
1 parent b28585e commit 5fa2a4d
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 48 deletions.
8 changes: 5 additions & 3 deletions th01/formats/grc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "th01/formats/pf.hpp"
#include "th01/formats/grc.hpp"

int grc_load(int slot, const char fn[PF_FN_LEN])
int grc_load(main_grc_slot_t slot, const char fn[PF_FN_LEN])
{
union {
spriteformat_header_inner_t inner;
Expand Down Expand Up @@ -43,7 +43,9 @@ int grc_load(int slot, const char fn[PF_FN_LEN])
return 0;
}

void grc_put_8(screen_x_t left, vram_y_t top, int slot, int image, int col)
void grc_put_8(
screen_x_t left, vram_y_t top, main_grc_slot_t slot, int image, int col
)
{
vram_offset_t vram_offset_row = vram_offset_shift(left, top);
vram_offset_t vram_offset;
Expand Down Expand Up @@ -91,7 +93,7 @@ void grc_put_8(screen_x_t left, vram_y_t top, int slot, int image, int col)
#undef grc_slot
}

void grc_free(int slot)
void grc_free(main_grc_slot_t slot)
{
for(int i = 0; grc_images[slot].image_count > i; i++) {
if(grc_images[slot].dots[i]) {
Expand Down
10 changes: 6 additions & 4 deletions th01/formats/grc.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/// Uncompressed monochrome 8w×h sprite format
/// ------------------------------------------
#include "th01/formats/sprfmt_h.hpp"
#include "th01/sprites/main_grc.h"

#define GRC_MAGIC "GRCG"

Expand All @@ -12,7 +13,6 @@ struct grc_header_t {
spriteformat_header_inner_t inner;
};

static const int GRC_SLOT_COUNT = 8;
static const int GRC_IMAGES_PER_SLOT = 8;

// In-memory slot structure
Expand All @@ -27,12 +27,14 @@ extern grc_t grc_images[GRC_SLOT_COUNT];

// Loads all images from the .GRC file with the given [fn] inside the
// currently active packfile into the given .GRC [slot]. Always returns 0.
int grc_load(int slot, const char fn[PF_FN_LEN]);
int grc_load(main_grc_slot_t slot, const char fn[PF_FN_LEN]);

// Frees all images in the given [slot].
void grc_free(int slot);
void grc_free(main_grc_slot_t slot);

// Blits the sub[image] from the given [slot] to (⌊left/8⌋*8, top) with the
// given [col]. Correctly clips the sprite at all 4 edges of VRAM.
void grc_put_8(screen_x_t left, vram_y_t top, int slot, int image, int col);
void grc_put_8(
screen_x_t left, vram_y_t top, main_grc_slot_t slot, int image, int col
);
/// ------------------------------------------
8 changes: 4 additions & 4 deletions th01/main/boss/b20m.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ void sariel_load_and_init(void)
ent_shield.load(boss6_1_bos, 0);
anm_wand.load(boss6_2_bos, 0);
anm_dress.load(boss6_3_bos, 1);
grc_load(0, boss6gr1_grc);
grc_load(1, boss6gr2_grc);
grc_load(2, boss6gr3_grc);
grc_load(3, boss6gr4_grc);
grc_load(GRC_SLOT_BOSS_1, boss6gr1_grc);
grc_load(GRC_SLOT_BOSS_2, boss6gr2_grc);
grc_load(GRC_SLOT_BOSS_3, boss6gr3_grc);
grc_load(GRC_SLOT_BOSS_4, boss6gr4_grc);
boss_palette_snap();
void sariel_setup(void);
sariel_setup();
Expand Down
13 changes: 13 additions & 0 deletions th01/sprites/main_grc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
typedef enum {
// .GRC slots that can be freely used by bosses.
GRC_SLOT_BOSS_1 = 0,
GRC_SLOT_BOSS_2 = 1,
GRC_SLOT_BOSS_3 = 2,
GRC_SLOT_BOSS_4 = 3,

GRC_SLOT_BOMB_KUJI_1 = 6, // kuzi1.grc
GRC_SLOT_BOMB_KUJI_2 = 7, // kuzi2.grc
GRC_SLOT_COUNT,

_main_grc_slot_t_FORCE_INT16 = 0x7FFF
} main_grc_slot_t;
8 changes: 8 additions & 0 deletions th01/sprites/main_grc.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
GRC_SLOT_BOSS_1 = 0
GRC_SLOT_BOSS_2 = 1
GRC_SLOT_BOSS_3 = 2
GRC_SLOT_BOSS_4 = 3

GRC_SLOT_BOMB_KUJI_1 = 6
GRC_SLOT_BOMB_KUJI_2 = 7
GRC_SLOT_COUNT = 8
Loading

0 comments on commit 5fa2a4d

Please sign in to comment.