Skip to content

Commit

Permalink
[Decompilation] [th03/th04/th05] Music Room: Rendering a single title
Browse files Browse the repository at this point in the history
Part of P0264, funded by [Anonymous] and Blue Bolt.
  • Loading branch information
nmlgc committed Feb 3, 2024
1 parent 5b4f24a commit a520b0c
Show file tree
Hide file tree
Showing 6 changed files with 168 additions and 258 deletions.
113 changes: 113 additions & 0 deletions th02/op/m_music.cpp
@@ -1,5 +1,18 @@
#include "platform.h"
#include "x86real.h"
#include "pc98.h"
#include "planar.h"
#include "shiftjis.hpp"
#include "master.hpp"
#include "th02/v_colors.hpp"
extern "C" {
#if (GAME >= 4)
#include "th04/hardware/bgimage.hpp"
#include "th04/hardware/grppsafx.h"
#else
#include "th01/hardware/grppsafx.h"
#endif
}
#if (GAME == 5)
#include "th05/shiftjis/music.hpp"

Expand All @@ -15,6 +28,43 @@
#endif
#endif

// Colors
// ------

static const vc_t COL_TRACKLIST_SELECTED = ((GAME >= 4) ? 3 : V_WHITE);
static const vc_t COL_TRACKLIST = ((GAME >= 4) ? 5 : 3);
// ------

// Coordinates
// -----------

static const screen_x_t TRACKLIST_LEFT = ((GAME == 5) ? 12 : 16);
#if (GAME == 5)
static const int TRACKLIST_VISIBLE_COUNT = 12;

static const screen_y_t TRACKLIST_TOP = 96;
static const pixel_t TRACKLIST_H = (TRACKLIST_VISIBLE_COUNT * GLYPH_H);
#else
inline screen_y_t track_top(uint8_t sel) {
#if (GAME == 4)
return (8 + (sel * GLYPH_H));
#elif (GAME == 3)
return (40 + (sel * GLYPH_H));
#elif (GAME == 2)
return ((static_cast<tram_y_t>(sel) + 6) * GLYPH_H);
#endif
}

inline int16_t track_fx(vc_t col) {
if(GAME >= 4) {
return col;
} else {
return (col | FX_WEIGHT_BOLD);
}
}
#endif
// -----------

// Polygon state
// -------------

Expand All @@ -27,4 +77,67 @@ bool polygons_initialized = false;
#if (GAME <= 4)
uint8_t track_playing = 0;
#endif
extern page_t music_page;
// ---------------

#if (GAME == 5)
// TH05 selection state
// --------------------

extern int track_id_at_top;
extern int track_playing;
// --------------------

void pascal near track_unput_or_put(uint8_t track_sel, bool16 put)
{
enum {
CURSOR_LEFT = TRACKLIST_LEFT,
CURSOR_RIGHT = (CURSOR_LEFT + TRACKLIST_W),
CURSOR_TOP = TRACKLIST_TOP,
CURSOR_BOTTOM = (TRACKLIST_TOP + GLYPH_H - 1),
};

const shiftjis_t* choice;
vc_t col = COL_TRACKLIST;

// ZUN bloat: The code could have been a lot simpler if [TRACKLIST_TOP]
// was added here rather than just before graph_putsa_fx(). Then, [top]
// could have been a `screen_y_t`.
pixel_t top = ((track_sel - track_id_at_top) * GLYPH_H);
if((top < 0) || (top >= TRACKLIST_H)) {
return;
}
if(put) {
grcg_setcolor(GC_RMW, COL_TRACKLIST);
grcg_hline(CURSOR_LEFT, CURSOR_RIGHT, (CURSOR_TOP + top));
grcg_hline(CURSOR_LEFT, CURSOR_RIGHT, (CURSOR_BOTTOM + top));
grcg_vline(CURSOR_LEFT, (CURSOR_TOP + top), (CURSOR_BOTTOM + top));
grcg_vline(CURSOR_RIGHT, (CURSOR_TOP + top), (CURSOR_BOTTOM + top));
grcg_off();
} else {
// ZUN bloat: Blitting [TRACKLIST_W] pixels starting at
// [TRACKLIST_LEFT] is enough.
bgimage_put_rect_16(0, (CURSOR_TOP + top), 320, GLYPH_H);
}
if(track_sel == track_playing) {
col = COL_TRACKLIST_SELECTED;
}

choice = MUSIC_CHOICES[game_sel][track_sel];
top += TRACKLIST_TOP;
graph_putsa_fx(TRACKLIST_LEFT, top, col, choice);
}
#else
void pascal near track_put(uint8_t sel, vc_t col)
{
page_t other_page = (1 - music_page);
graph_accesspage(other_page);
graph_putsa_fx(
TRACKLIST_LEFT, track_top(sel), track_fx(col), MUSIC_CHOICES[sel]
);
graph_accesspage(music_page);
graph_putsa_fx(
TRACKLIST_LEFT, track_top(sel), track_fx(col), MUSIC_CHOICES[sel]
);
}
#endif
23 changes: 6 additions & 17 deletions th02/op_06.cpp
Expand Up @@ -48,24 +48,13 @@ page_t music_page;
dots8_t *screen_back_B;
Planar<dots8_t far *> cmt_back;

void pascal near draw_track(unsigned char sel, unsigned char color)
{
page_t other_page = (1 - music_page);
graph_accesspage(other_page);
graph_putsa_fx(
16, ((sel + 6) * GLYPH_H), (color | FX_WEIGHT_BOLD), MUSIC_CHOICES[sel]
);
graph_accesspage(music_page);
graph_putsa_fx(
16, ((sel + 6) * GLYPH_H), (color | FX_WEIGHT_BOLD), MUSIC_CHOICES[sel]
);
}
void pascal near track_put(uint8_t sel, vc_t col);

void pascal near draw_tracks(unsigned char sel)
{
int i;
for(i = 0; i < sizeof(MUSIC_CHOICES) / sizeof(MUSIC_CHOICES[0]); i++) {
draw_track(i, (i == sel) ? V_WHITE : 3);
track_put(i, (i == sel) ? V_WHITE : 3);
}
}

Expand Down Expand Up @@ -267,7 +256,7 @@ void pascal musicroom(void)
controls:
input_sense();
if(key_det & INPUT_UP) {
draw_track(music_sel, 3);
track_put(music_sel, 3);
if(music_sel > 0) {
music_sel--;
} else {
Expand All @@ -276,10 +265,10 @@ void pascal musicroom(void)
if(music_sel == TRACK_COUNT) {
music_sel--;
}
draw_track(music_sel, V_WHITE);
track_put(music_sel, V_WHITE);
}
if(key_det & INPUT_DOWN) {
draw_track(music_sel, 3);
track_put(music_sel, 3);
if(music_sel < SEL_QUIT) {
music_sel++;
} else {
Expand All @@ -288,7 +277,7 @@ void pascal musicroom(void)
if(music_sel == TRACK_COUNT) {
music_sel++;
}
draw_track(music_sel, V_WHITE);
track_put(music_sel, V_WHITE);
}
if(key_det & INPUT_SHOT || key_det & INPUT_OK) {
if(music_sel != SEL_QUIT) {
Expand Down
66 changes: 7 additions & 59 deletions th03_op.asm
Expand Up @@ -1324,59 +1324,8 @@ _main endp
op_01_TEXT ends

OP_MUSIC_TEXT segment byte public 'CODE' use16

; =============== S U B R O U T I N E =======================================

; Attributes: bp-based frame
public DRAW_TRACK
draw_track proc near

var_1 = byte ptr -1
@@color = byte ptr 4
@@sel = byte ptr 6

enter 2, 0
mov al, 1
sub al, _music_page
mov [bp+var_1], al
graph_accesspage al
push 16
mov al, [bp+@@sel]
mov ah, 0
shl ax, 4
add ax, 40
push ax
mov al, [bp+@@color]
mov ah, 0
or ax, FX_WEIGHT_BOLD
push ax
mov al, [bp+@@sel]
mov ah, 0
shl ax, 2
mov bx, ax
pushd _MUSIC_CHOICES[bx]
call graph_putsa_fx
graph_accesspage _music_page
push 16
mov al, [bp+@@sel]
mov ah, 0
shl ax, 4
add ax, 40
push ax
mov al, [bp+@@color]
mov ah, 0
or ax, FX_WEIGHT_BOLD
push ax
mov al, [bp+@@sel]
mov ah, 0
shl ax, 2
mov bx, ax
pushd _MUSIC_CHOICES[bx]
call graph_putsa_fx
leave
retn 4
draw_track endp

@TRACK_PUT$QUCUC procdesc pascal near \
sel:byte, col:byte

; =============== S U B R O U T I N E =======================================

Expand Down Expand Up @@ -1408,7 +1357,7 @@ loc_A5A6:

loc_A5A8:
push ax
call draw_track
call @track_put$qucuc
inc si

loc_A5AD:
Expand Down Expand Up @@ -1488,7 +1437,7 @@ loc_ACD3:
call input_mode_interface
test _input_sp.lo, low INPUT_UP
jz short loc_AD0E
call draw_track pascal, word ptr _music_sel, 3
call @track_put$qucuc pascal, word ptr _music_sel, 3
cmp _music_sel, 0
jbe short loc_ACF5
dec _music_sel
Expand All @@ -1504,12 +1453,12 @@ loc_ACFA:
dec _music_sel

loc_AD05:
call draw_track pascal, word ptr _music_sel, V_WHITE
call @track_put$qucuc pascal, word ptr _music_sel, V_WHITE

loc_AD0E:
test _input_sp.lo, low INPUT_DOWN
jz short loc_AD44
call draw_track pascal, word ptr _music_sel, 3
call @track_put$qucuc pascal, word ptr _music_sel, 3
cmp _music_sel, 14h
jnb short loc_AD2B
inc _music_sel
Expand All @@ -1525,7 +1474,7 @@ loc_AD30:
inc _music_sel

loc_AD3B:
call draw_track pascal, word ptr _music_sel, V_WHITE
call @track_put$qucuc pascal, word ptr _music_sel, V_WHITE

loc_AD44:
test _input_sp.lo, low INPUT_SHOT
Expand Down Expand Up @@ -3321,7 +3270,6 @@ SHARED ends
extern _SinTable8:word:256
extern _CosTable8:word:256

extern _MUSIC_CHOICES:dword
extern _MUSIC_FILES:dword
extern _track_playing:byte
extern _polygons_initialized:byte
Expand Down

0 comments on commit a520b0c

Please sign in to comment.