Skip to content

Commit

Permalink
[Decompilation] [th03] SPRITE16: Inline methods for playfield clipping
Browse files Browse the repository at this point in the history
Part of P0280, funded by [Anonymous], Blue Bolt, and JonathKane.
  • Loading branch information
nmlgc committed Apr 21, 2024
1 parent 51de5ec commit cdc7e59
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 8 deletions.
7 changes: 4 additions & 3 deletions th03/main/sprite16.cpp
Expand Up @@ -34,16 +34,17 @@ void pascal sprite16_sprites_commit(void)
#define put_w_words (_AL)
#define should_draw_column (_SI)

#define SETUP_VARS(left, top, so) \
#define SETUP_VARS(left, top, so) { \
sprite_offset_local = so; \
putpos_left = left; \
put_w_words = sprite16_put_size.w.v; \
putpos_right_high ^= putpos_right_high; \
static_cast<char>(putpos_right) = put_w_words; \
putpos_right <<= 4; \
putpos_right += putpos_left; \
clip_left = sprite16_clip_left; \
clip_right = sprite16_clip_right;
clip_left = sprite16_clip.left; \
clip_right = sprite16_clip.right; \
}

#define CALL_PUT(left, top, put_w_words, so) \
_AH = SPRITE16_PUT; \
Expand Down
32 changes: 30 additions & 2 deletions th03/main/sprite16.hpp
Expand Up @@ -13,8 +13,36 @@ extern struct {
h = (h_ / 2);
}
} sprite16_put_size;
extern screen_x_t sprite16_clip_left;
extern screen_x_t sprite16_clip_right;
extern struct {
screen_x_t left;
screen_x_t right;

#ifdef PLAYFIELD1_CLIP_LEFT
void reset(void) {
left = PLAYFIELD1_CLIP_LEFT;
right = PLAYFIELD2_CLIP_RIGHT;
}

// Additional variants for static constants
void set_for_pid_0(void) {
left = PLAYFIELD1_CLIP_LEFT;
right = PLAYFIELD1_CLIP_RIGHT;
}

void set_for_pid_1(void) {
left = PLAYFIELD2_CLIP_LEFT;
right = PLAYFIELD2_CLIP_RIGHT;
}
#endif
} sprite16_clip;

#define sprite16_clip_set_for_pid(pid) { \
if(pid == 0) { \
sprite16_clip.set_for_pid_0(); \
} else { \
sprite16_clip.set_for_pid_1(); \
} \
}

enum sprite16_put_func_t {
SPF_NORMAL = 0,
Expand Down
3 changes: 1 addition & 2 deletions th03/main_011.cpp
Expand Up @@ -29,8 +29,7 @@ void pascal near shots_render(void)
shotpair_t near *shotpair = shotpairs;

sprite16_put_size.set(SHOT_W, SHOT_H);
sprite16_clip_left = 0;
sprite16_clip_right = RES_X - 1;
sprite16_clip.reset();

for(int i = 0; i < SHOTPAIR_COUNT; i++, shotpair++) {
if(shotpair->alive) {
Expand Down
3 changes: 2 additions & 1 deletion th03/sprite16[bss].asm
@@ -1,4 +1,5 @@
public _sprite16_clip_left, _sprite16_clip_right, _sprite16_put_size
public _sprite16_clip, _sprite16_put_size
label _sprite16_clip byte
_sprite16_clip_left dw ?
_sprite16_clip_right dw ?
label _sprite16_put_size byte
Expand Down

0 comments on commit cdc7e59

Please sign in to comment.