From 51de5ec036d4d6590857b06768cb02c956dea481 Mon Sep 17 00:00:00 2001 From: nmlgc Date: Tue, 16 Apr 2024 15:31:17 +0200 Subject: [PATCH] [Decompilation] [th03] SPRITE16: Inline method for sprite size assignments 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. --- pc98.h | 3 +++ th03/main/player/shot.hpp | 8 ++++---- th03/main/player/shots[bss].asm | 6 ------ th03/main/sprite16.cpp | 8 ++++---- th03/main/sprite16.hpp | 11 +++++++++-- th03/main_011.cpp | 3 +-- th03/sprite16[bss].asm | 7 +++---- 7 files changed, 24 insertions(+), 22 deletions(-) diff --git a/pc98.h b/pc98.h index 9e5b636a..d447cfc3 100644 --- a/pc98.h +++ b/pc98.h @@ -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; /// ------ diff --git a/th03/main/player/shot.hpp b/th03/main/player/shot.hpp index 43cbae7d..3b2f4489 100644 --- a/th03/main/player/shot.hpp +++ b/th03/main/player/shot.hpp @@ -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, diff --git a/th03/main/player/shots[bss].asm b/th03/main/player/shots[bss].asm index 21ca5a36..48b3dee2 100644 --- a/th03/main/player/shots[bss].asm +++ b/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 diff --git a/th03/main/sprite16.cpp b/th03/main/sprite16.cpp index d7b4253b..c01251c4 100644 --- a/th03/main/sprite16.cpp +++ b/th03/main/sprite16.cpp @@ -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(putpos_right) = put_w_words; \ putpos_right <<= 4; \ @@ -51,7 +51,7 @@ void pascal sprite16_sprites_commit(void) _BX = top; \ static_cast(_BX) >>= 1; \ _AL = put_w_words; \ - _CX = sprite16_put_h; \ + _CX = sprite16_put_size.h; \ _DI = so; \ geninterrupt(SPRITE16); \ @@ -114,7 +114,7 @@ put: _BX = top; static_cast(_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; @@ -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); } } diff --git a/th03/main/sprite16.hpp b/th03/main/sprite16.hpp index accc61e3..72aaf768 100644 --- a/th03/main/sprite16.hpp +++ b/th03/main/sprite16.hpp @@ -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; diff --git a/th03/main_011.cpp b/th03/main_011.cpp index 4490fa46..06af9b1b 100644 --- a/th03/main_011.cpp +++ b/th03/main_011.cpp @@ -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; diff --git a/th03/sprite16[bss].asm b/th03/sprite16[bss].asm index 8e7d4403..abb7df3e 100644 --- a/th03/sprite16[bss].asm +++ b/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