Skip to content

Commit

Permalink
[Maintenance] [th04/th05] Declare scrolling variables and functions i…
Browse files Browse the repository at this point in the history
…n C land

Part of P0089, funded by [Anonymous] and Blue Bolt.
  • Loading branch information
nmlgc committed May 3, 2020
1 parent 708d9fc commit 5531ed9
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 21 deletions.
24 changes: 24 additions & 0 deletions th04/main/scroll.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// [scroll_line] is advanced by 1 for every 16 units.
extern SubpixelLength8 scroll_subpixel_line;

// Amount to add to [scroll_subpixel_line] every frame.
extern SubpixelLength8 scroll_speed;

// Current line at the top of VRAM.
extern int scroll_line;
extern int scroll_line_on_page[2];

// Playfield-space pixels scrolled in the last frame.
extern Subpixel scroll_last_delta;

// If false, the game doesn't draw stage tiles, assuming that someone else
// draws the background.
extern bool scroll_active;

// Transforms [y] to its corresponding VRAM line, adding the current
// [scroll_line] or 0 if scrolling is disabled.
int pascal near scroll_subpixel_y_to_vram_seg1(subpixel_t y);
int pascal near scroll_subpixel_y_to_vram_seg3(subpixel_t y);
// Like the one above, but always adds [scroll_line], even if scrolling is
// disabled.
int pascal near scroll_subpixel_y_to_vram_always(subpixel_t y);
7 changes: 1 addition & 6 deletions th04/main/scroll[bss].asm
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
public _scroll_subpixel_line, _scroll_speed, _scroll_line, _scroll_active
; [scroll_line] is advanced by 1 for every 16 units.
_scroll_subpixel_line db ?
; Amount to add to [_scroll_subpixel_line] every frame.
_scroll_speed db ?
; Current line at the top of VRAM.
_scroll_line dw ?
; Amount of 1/16th-pixel units scrolled in the last frame.
_scroll_last_delta dw ?
; If set to 0, the game assumes that the background is drawn by someone else!
_scroll_active db ?
db ?
evendata
4 changes: 0 additions & 4 deletions th04/main/scroll_y_1.asm
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
; Transforms the 1/16-pixel on-screen Y coordinate [sy] to its corresponding
; VRAM line given the current scrolling offset.

; int pascal near scroll_subpixel_y_to_vram(int sy);
public SCROLL_SUBPIXEL_Y_TO_VRAM_SEG1
scroll_subpixel_y_to_vram_seg1 proc near
@@sy = word ptr 2
Expand Down
2 changes: 0 additions & 2 deletions th04/main/scroll_y_3.asm
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
; See scroll_subpixel_y_to_vram_seg1().
public SCROLL_SUBPIXEL_Y_TO_VRAM_SEG3
scroll_subpixel_y_to_vram_seg3 proc near
@@sy = word ptr 2
Expand Down Expand Up @@ -26,7 +25,6 @@ scroll_subpixel_y_to_vram_seg3 proc near
scroll_subpixel_y_to_vram_seg3 endp


; Like the one above, but transforming even if scrolling is disabled.
public SCROLL_SUBPIXEL_Y_TO_VRAM_ALWAYS
scroll_subpixel_y_to_vram_always proc near
@@sy = word ptr 2
Expand Down
2 changes: 1 addition & 1 deletion th04/main/tiles_invalidate.asm
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ tiles_invalidate_around proc near
mov bh, 0
mov bl, _page_back
add bx, bx
add ax, _scroll_line_on_plane[bx]
add ax, _scroll_line_on_page[bx]
jns short @@scroll_wrap?
add ax, RES_Y
jmp short @@invalidate
Expand Down
4 changes: 2 additions & 2 deletions th04/main/tiles_invalidate[bss].asm
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
public _scroll_line_on_plane, _tile_invalidate_box
_scroll_line_on_plane dw 2 dup(?)
public _scroll_line_on_page, _tile_invalidate_box
_scroll_line_on_page dw 2 dup(?)
_tile_invalidate_box Point <?>
6 changes: 3 additions & 3 deletions th04_main.asm
Original file line number Diff line number Diff line change
Expand Up @@ -920,8 +920,8 @@ sub_B1D0 proc near
mov byte_2D00A, 0
mov _scroll_line, 0
mov word_25100, 0
mov _scroll_line_on_plane[0 * 2], 0
mov _scroll_line_on_plane[1 * 2], 0
mov _scroll_line_on_page[0 * 2], 0
mov _scroll_line_on_page[1 * 2], 0
mov _scroll_subpixel_line, 0
mov byte_25104, 0
mov byte_250FE, 0
Expand Down Expand Up @@ -2516,7 +2516,7 @@ sub_CCD6 proc near
add ax, ax
mov dx, _scroll_line
mov bx, ax
mov _scroll_line_on_plane[bx], dx
mov _scroll_line_on_page[bx], dx
cmp byte_250FE, 0
jz short loc_CCFE
cmp _scroll_active, 0
Expand Down
6 changes: 3 additions & 3 deletions th05_main.asm
Original file line number Diff line number Diff line change
Expand Up @@ -1074,8 +1074,8 @@ sub_B55A proc near
mov byte_2C96C, 0
mov _scroll_line, 0
mov word_23F06, 0
mov _scroll_line_on_plane[0 * 2], 0
mov _scroll_line_on_plane[1 * 2], 0
mov _scroll_line_on_page[0 * 2], 0
mov _scroll_line_on_page[1 * 2], 0
mov _scroll_subpixel_line, 0
mov byte_23EFC, 0
mov byte_23F04, 0
Expand Down Expand Up @@ -7473,7 +7473,7 @@ loc_10223:
add ax, ax
mov dx, _scroll_line
mov bx, ax
mov _scroll_line_on_plane[bx], dx
mov _scroll_line_on_page[bx], dx
cmp byte_23F04, 0
jz short loc_1024F
cmp _scroll_active, 0
Expand Down

0 comments on commit 5531ed9

Please sign in to comment.