Skip to content

Commit

Permalink
[Decompilation] [th02] Stage tiles: Initial screen of a stage
Browse files Browse the repository at this point in the history
Part of P0236, funded by Yanga.
  • Loading branch information
nmlgc committed Mar 29, 2023
1 parent 6acb385 commit 29cde9b
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 116 deletions.
53 changes: 53 additions & 0 deletions th02/main/tile/tile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "th02/main/playfld.hpp"
#include "th02/main/scroll.hpp"
#include "th02/main/tile/tile.hpp"
#include "th02/formats/map.hpp"
#include "th02/formats/mpn.hpp"

// Terminology:
// • Line: [TILE_W]×1 stripe within a tile
Expand All @@ -31,6 +33,21 @@ extern bool tile_dirty[TILES_X][TILES_Y];
extern bool tile_column_dirty[TILES_X];
// -----

// Map tiles
// ---------

#define section_for_map_row(row, ret) \
/* Sneaky! That's how we can pretend this is an actual function that */ \
/* returns a value. */ \
(row >> MAP_BITS_PER_SECTION); \
ret = map[ret]; \
static_assert((1 << MAP_BITS_PER_SECTION) == MAP_ROWS_PER_SECTION);

inline tile_image_id_t map_tile_image_at(int section, int row, int x) {
return map_section_tiles[section].row[row & (MAP_ROWS_PER_SECTION - 1)][x];
}
// ---------

void pascal near tile_egc_copy_lines_8(vram_offset_t vo_dst, int image)
;
void pascal near tile_egc_copy_8(vram_offset_t vo_topleft, int image)
Expand Down Expand Up @@ -66,6 +83,42 @@ void pascal near tile_grcg_clear_8(vram_offset_t vo_topleft)
} \
}

void pascal near tile_row_put_8(screen_x_t left, vram_y_t top, int row)
{
int section = section_for_map_row(row, section);
for(int tile_x = 0; tile_x < TILES_X; tile_x++) {
int image = map_tile_image_at(section, row, tile_x);
mpn_put_8((left + (tile_x * TILE_W)), top, image);
}
}

void tiles_fill_and_put_initial(void)
{
int x;
int section;

// Skips the last row in the [tile_ring] (at (TILES_Y - 1)) because there's
// no data to fill it with and it's covered by black TRAM cells on the
// initial screen of a stage anyway.
// ZUN landmine: This function only blits to one VRAM page, with the other
// one being covered by tiles_render_all(). That function does actually
// render the entire tile ring, including the row we skipped here.
// Initializing that row at least with *something* might therefore be
// better than skipping it.
for(int y = 0; y < ((PLAYFIELD_H / TILE_H) + 1); y++) {
tile_row_put_8(
PLAYFIELD_LEFT, (PLAYFIELD_BOTTOM - TILE_H - (y * TILE_H)), y
);

section = section_for_map_row(y, section);
for(x = 0; x < TILES_X; x++) {
tile_ring[(PLAYFIELD_H / TILE_H) - y][x] = map_tile_image_at(
section, y, x
);
}
}
}

void pascal tiles_invalidate_rect(
screen_x_t left, vram_y_t top, pixel_t w, pixel_t h
)
Expand Down
6 changes: 6 additions & 0 deletions th02/main/tile/tile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ static const vram_x_t TILE_AREA_VRAM_LEFT = (TILE_AREA_LEFT / BYTE_DOTS);
// redraw all tiles and then reset this flag to `false`.
extern bool tiles_egc_render_all;

// Fills [tile_ring] with the initial screen of tiles at the bottom/start
// of the map, and blits them to the playfield area in VRAM. Reads tile
// images from our data segment, the tile source area is neither read from
// nor written to.
void tiles_fill_and_put_initial(void);

// Marks all tiles for redrawing that lie within the given area of the
// screen.
void pascal tiles_invalidate_rect(
Expand Down
118 changes: 2 additions & 116 deletions th02_main.asm
Original file line number Diff line number Diff line change
Expand Up @@ -1262,121 +1262,7 @@ loc_453A:
retf 2
sub_445A endp


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

; Attributes: bp-based frame

sub_4540 proc near
push bp
mov bp, sp
sub sp, 2
push si
push di
mov ax, [bp+4]
sar ax, 3
mov di, ax
mov al, _map[di]
mov ah, 0
mov di, ax
xor si, si
jmp short loc_458B
; ---------------------------------------------------------------------------

loc_455C:
mov bx, di
imul bx, (MAP_ROWS_PER_SECTION * TILES_X)
mov ax, [bp+4]
and ax, (MAP_ROWS_PER_SECTION - 1)
imul ax, TILES_X
add bx, ax
mov al, _map_section_tiles[bx+si]
mov ah, 0
mov [bp-2], ax
mov ax, si
shl ax, 4
add ax, [bp+8]
push ax ; left
push word ptr [bp+6] ; top
push word ptr [bp-2] ; image
nopcall @mpn_put_8$qiii
inc si

loc_458B:
cmp si, TILES_X
jl short loc_455C
pop di
pop si
leave
retn 6
sub_4540 endp


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

; Attributes: bp-based frame

sub_4596 proc far

var_2 = word ptr -2

push bp
mov bp, sp
sub sp, 2
push si
push di
xor di, di
jmp short loc_45F3
; ---------------------------------------------------------------------------

loc_45A2:
push 20h ; ' '
mov ax, di
shl ax, 4
mov dx, 170h
sub dx, ax
push dx
push di
call sub_4540
mov ax, di
sar ax, 3
mov [bp+var_2], ax
mov bx, [bp+var_2]
mov al, _map[bx]
mov ah, 0
mov [bp+var_2], ax
xor si, si
jmp short loc_45ED
; ---------------------------------------------------------------------------

loc_45CB:
mov bx, [bp+var_2]
imul bx, (MAP_ROWS_PER_SECTION * TILES_X)
mov ax, di
and ax, (MAP_ROWS_PER_SECTION - 1)
imul ax, TILES_X
add bx, ax
mov al, _map_section_tiles[bx+si]
mov bx, 23
sub bx, di
imul bx, TILES_X
mov _tile_ring[bx+si], al
inc si

loc_45ED:
cmp si, TILES_X
jl short loc_45CB
inc di

loc_45F3:
cmp di, 24
jl short loc_45A2
pop di
pop si
leave
retf
sub_4596 endp

extern @tiles_fill_and_put_initial$qv:proc
extern @TILES_INVALIDATE_RECT$QIIII:proc
extern @tiles_egc_render$qv:proc
extern @tiles_render_all$qv:proc
Expand Down Expand Up @@ -1966,7 +1852,7 @@ loc_B8B5:
add sp, 0Ah
call far ptr palette_show
graph_accesspage 1
call sub_4596
call @tiles_fill_and_put_initial$qv
graph_accesspage 0
call @tiles_render_all$qv
call _mpn_free
Expand Down

0 comments on commit 29cde9b

Please sign in to comment.