Skip to content

Commit

Permalink
implement credits
Browse files Browse the repository at this point in the history
  • Loading branch information
fgsfdsfgs committed Aug 27, 2021
1 parent 8d86101 commit 234d4aa
Show file tree
Hide file tree
Showing 17 changed files with 483 additions and 37 deletions.
2 changes: 2 additions & 0 deletions iso.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
<file name="armsitem.bsc" type="data"/>
<file name="credit.bsc" type="data"/>
<file name="stagesel.bsc" type="data"/>
<file name="credit.crd" type="data"/>
</dir>
<dir name="0" srcdir="data/0">
<file name="stage00.stg" type="data"/>
<file name="stage01.stg" type="data"/>
<file name="stage02.stg" type="data"/>
<file name="stage03.stg" type="data"/>
Expand Down
38 changes: 32 additions & 6 deletions src/engine/graphics.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ gfx_surf_t gfx_surf[GFX_MAX_SURFACES];
// common clear color
const u8 gfx_clear_rgb[3] = { 0x00, 0x00, 0x20 };

// when TRUE, don't show loading screens
bool gfx_suppress_loading = FALSE;

static struct fb
{
DRAWENV draw;
Expand Down Expand Up @@ -355,6 +358,8 @@ void gfx_draw_clear_immediate(const u8 *rgb) {
}

void gfx_draw_loading(void) {
if (gfx_suppress_loading)
return;
// clear both framebuffers
gfx_draw_clear_immediate(gfx_clear_rgb);
// just plop it into the currently shown framebuffer
Expand All @@ -368,19 +373,40 @@ void gfx_draw_loading(void) {
LoadImage(&rc, (u_long *)img_loading);
}

void gfx_upload_image(u8 *data, int w, int h, const int mode, const int surf_id) {
void gfx_upload_image(u8 *data, int w, int h, const int mode, const int surf_id, const bool sync) {
const int shift = 2 - mode;
w >>= shift;
if (shift) ++h; // CLUT underneath image
// upload into bottom right corner of VRAM and hope it doesn't hit anything
RECT rect = { 1024 - ALIGN(w, 16), 512 - h, w, h };
gfx_surf[surf_id].clut = shift ? getClut(rect.x, rect.y + h - 1) : 0;

RECT rect = { 0, 0, w, h };
if (gfx_surf[surf_id].tex_x || gfx_surf[surf_id].tex_y) {
// there's already a surface with this ID, overwrite it
rect.x = gfx_surf[surf_id].tex_x;
rect.y = gfx_surf[surf_id].tex_y;
} else {
// slam it into the bottom right corner and hope it doesn't overwrite anything
rect.x = 1024 - ALIGN(w, 16);
rect.y = 512 - h - 1;
}

if (mode == 0) {
// 16 colors; CLUT is safely underneath image
++rect.h;
gfx_surf[surf_id].clut = getClut(rect.x, rect.y + h);
} else if (mode == 1) {
// 256 colors; CLUT is too big for this shit, we have to do a separate upload
// shove it into the bottommost line under the framebuffer
RECT clutrect = { 0, 511, 256, 1 };
u8 *clutptr = data + (rect.w * rect.h * 2);
LoadImage(&clutrect, (u_long *)clutptr);
gfx_surf[surf_id].clut = getClut(clutrect.x, clutrect.y);
}

gfx_surf[surf_id].mode = mode;
gfx_surf[surf_id].id = surf_id;
gfx_surf[surf_id].tex_x = rect.x;
gfx_surf[surf_id].tex_y = rect.y;
LoadImage(&rect, (u_long *)data);
DrawSync(0);
if (sync) DrawSync(0);
}

int gfx_upload_gfx_bank(gfx_bank_t *bank, u8 *bank_data) {
Expand Down
22 changes: 21 additions & 1 deletion src/engine/graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,30 @@ typedef struct {
// [surfdata_h * VRAM_PAGE_WIDTH] words of surface data follows
} gfx_bank_t;

/* essentially same shit but for RAM storage */

typedef struct {
s16 mode; // 1 for 256-color, 0 for 16-color, -1 for no image
u16 w; // width, in words
u16 h; // height, in vram lines
u16 size; // size, in words
u32 ofs; // offset from beginning of ram_surfbank_t
} gfx_ramsurf_t;

typedef struct {
u32 numsurf; // total number of surfaces in bank, each surface has its own clut
gfx_ramsurf_t surf[]; // [numsurf] surface headers
// surface data follows:
// for each surface:
// some words: image data \ total: `size` words
// 16 or 256 words: clut data /
} gfx_rambank_t;

#pragma pack(pop)

extern gfx_surf_t gfx_surf[];
extern const u8 gfx_clear_rgb[3];
extern bool gfx_suppress_loading;

typedef struct {
rect_t r; // rect inside surface
Expand Down Expand Up @@ -81,7 +101,7 @@ void gfx_pop_cliprect(const int layer);

// if mode != 2, CLUT is immediately after the image (data + w * h) and may be up to w bytes in size
// w must be aligned to 16
void gfx_upload_image(u8 *data, int w, int h, const int mode, const int surf_id);
void gfx_upload_image(u8 *data, int w, int h, const int mode, const int surf_id, const bool sync);

// converts the `rect` field of `r` into tpage address, UVs and XYWH instead of LTRB
static inline void gfx_set_texrect(gfx_texrect_t *tr, const int s) {
Expand Down
Loading

0 comments on commit 234d4aa

Please sign in to comment.