Skip to content

Commit

Permalink
[Decompilation] [th03] SPRITE16: Inline method for sprite size assign…
Browse files Browse the repository at this point in the history
…ments

All but one of the writes to these globals follow the consistent scheme
of assigning hardcoded literals to first `w` and then `h`, so it makes
sense to encapsulate the conversion from display-space pixels to VRAM
words and heights in a method.
(On that note, we also need a new type to encode the notion of
VRAM-space heights as opposed to the display-space heights of
`pixel_t`.)

Part of P0280, funded by [Anonymous], Blue Bolt, and JonathKane.
  • Loading branch information
nmlgc committed Apr 21, 2024
1 parent 415bef1 commit 51de5ec
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 22 deletions.
3 changes: 3 additions & 0 deletions pc98.h
Expand Up @@ -28,6 +28,9 @@ typedef unsigned int uvram_byte_amount_t;
typedef unsigned int uvram_word_amount_t;
typedef unsigned int uvram_dword_amount_t;

// VRAM heights. Different from `pixel_t` in 200-line mode.
typedef int vram_h_t;

// TRAM widths or heights
typedef int tram_cell_amount_t;
/// ------
Expand Down
8 changes: 4 additions & 4 deletions th03/main/player/shot.hpp
Expand Up @@ -2,10 +2,10 @@
#define SHOT_SO_PID (320 / 8)

#define SHOT_SPRITE_COUNT 4
#define SHOT_W 16
#define SHOT_H 8
#define SHOT_VRAM_W (SHOT_W / BYTE_DOTS)
#define SHOT_VRAM_H (SHOT_H / 2)

static const pixel_t SHOT_W = 16;
static const pixel_t SHOT_H = 16;
static const vram_byte_amount_t SHOT_VRAM_W = (SHOT_W / BYTE_DOTS);

enum shot_mode_t {
SM_NONE = 0,
Expand Down
6 changes: 0 additions & 6 deletions th03/main/player/shots[bss].asm
@@ -1,12 +1,6 @@
SHOT_VELOCITY = (-12 shl 4)
SHOT_SO_PID = (320 / 8)

SHOT_SPRITE_COUNT = 4
SHOT_W = 16
SHOT_H = 8
SHOT_VRAM_W = (SHOT_W / 8)
SHOT_VRAM_H = (SHOT_H / 2)

; shot_mode_t
SM_NONE = 0
SM_1_PAIR = 1
Expand Down
8 changes: 4 additions & 4 deletions th03/main/sprite16.cpp
Expand Up @@ -37,7 +37,7 @@ void pascal sprite16_sprites_commit(void)
#define SETUP_VARS(left, top, so) \
sprite_offset_local = so; \
putpos_left = left; \
put_w_words = sprite16_put_w.v; \
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; \
Expand All @@ -51,7 +51,7 @@ void pascal sprite16_sprites_commit(void)
_BX = top; \
static_cast<int>(_BX) >>= 1; \
_AL = put_w_words; \
_CX = sprite16_put_h; \
_CX = sprite16_put_size.h; \
_DI = so; \
geninterrupt(SPRITE16); \

Expand Down Expand Up @@ -114,7 +114,7 @@ void pascal sprite16_putx(
_BX = top;
static_cast<int>(_BX) >>= 1;
_AL = put_w_words;
_CX = sprite16_put_h;
_CX = sprite16_put_size.h;
_DI = sprite_offset_local;
while(1) {
should_draw_column = func;
Expand Down Expand Up @@ -157,7 +157,7 @@ void pascal sprite16_put_noclip(
putpos_right <<= 4;
putpos_right += putpos_left;

CALL_PUT(putpos_left, top, sprite16_put_w.v, sprite_offset_local);
CALL_PUT(putpos_left, top, sprite16_put_size.w.v, sprite_offset_local);
}

}
11 changes: 9 additions & 2 deletions th03/main/sprite16.hpp
Expand Up @@ -4,8 +4,15 @@
// SPRITE16_OFFSET.
typedef uvram_byte_amount_t sprite16_offset_t;

extern pixel_t sprite16_put_h;
extern VRAMWord sprite16_put_w;
extern struct {
vram_h_t h;
VRAMWord w;

void set(pixel_t w_, pixel_t h_) {
w = w_;
h = (h_ / 2);
}
} sprite16_put_size;
extern screen_x_t sprite16_clip_left;
extern screen_x_t sprite16_clip_right;

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

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

Expand Down
7 changes: 3 additions & 4 deletions th03/sprite16[bss].asm
@@ -1,8 +1,7 @@
public _sprite16_clip_left, _sprite16_clip_right
public _sprite16_put_h, _sprite16_put_w

public _sprite16_clip_left, _sprite16_clip_right, _sprite16_put_size
_sprite16_clip_left dw ?
_sprite16_clip_right dw ?
label _sprite16_put_size byte
_sprite16_put_h dw ?
_sprite16_put_w db ?
db ?
evendata

0 comments on commit 51de5ec

Please sign in to comment.