[Maintenance] Start a separate file for recurring sprite blitting algorithms

Part of P0087, funded by -Tom-.
This commit is contained in:
nmlgc 2020-04-13 13:55:52 +02:00
parent 8f824c4297
commit b6fdcb0013
4 changed files with 56 additions and 31 deletions

View File

@ -23,38 +23,8 @@ public @spark_render
and cx, 7 ; & (SPARK_SPRITES - 1)
shl cx, 4 ; * SPARK_SIZE
add si, cx
cmp bx, RES_Y - SPARK_H
ja short @@ywrap_needed
mov cx, SPARK_H ; CX = # of rows copied *before* Y wrap
xor bx, bx ; BX = # of rows copied *after* Y wrap
jmp short @@blit_loop
@@ywrap_needed:
mov cx, RES_Y
sub cx, bx
mov bx, SPARK_H
sub bx, cx
@@blit_loop:
lodsw
or ah, ah
jz short @@8px
mov es:[di], ax
jmp short @@next_row
@@8px:
or al, al
jz short @@next_row
mov es:[di], al
@@next_row:
add di, ROW_SIZE
loop @@blit_loop
or bx, bx
jz short @@ret
sub di, PLANE_SIZE
xchg cx, bx
jmp short @@blit_loop
blit_dots16_empty2opt_emptyopt_roll <bx>, SPARK_H
@@ret:
pop di

53
th04/sprites/blit.inc Normal file
View File

@ -0,0 +1,53 @@
; Shared sprite blitting macros
; -----------------------------
; All of these assume that:
; the GRCG to be active, and set to the intended color and tile
; DS:SI being set to the source sprite data, and ES:DI to the intended
; destination byte within a VRAM plane.
; Modes:
; roll: Y-wrapped
; empty2opt: Not writing the right 8 dots to VRAM if they are 0
; emptyopt: Writing nothing to VRAM if all 16 dots are 0
; Blitting [h] rows, with [top] being the first one.
blit_dots16_empty2opt_emptyopt_roll macro @@top:req, @@h:req
@@rows_after_roll equ <bx>
cmp @@top, (RES_Y - @@h)
ja short @@roll_needed
mov cx, @@h ; CX = # of rows copied *before* Y wrap
xor @@rows_after_roll, @@rows_after_roll
jmp short @@blit_loop
@@roll_needed:
mov cx, RES_Y
sub cx, @@top
mov @@rows_after_roll, @@h
sub @@rows_after_roll, cx
even
@@blit_loop:
lodsw
or ah, ah
jz short @@blit_al?
mov es:[di], ax
jmp short @@next_row
@@blit_al?:
or al, al
jz short @@next_row
mov es:[di], al
@@next_row:
add di, ROW_SIZE
loop @@blit_loop
or @@rows_after_roll, @@rows_after_roll
jz short @@blit_done
sub di, PLANE_SIZE
xchg cx, @@rows_after_roll
jmp short @@blit_loop
@@blit_done:
endm

View File

@ -23,6 +23,7 @@ BINARY = 'M'
include ReC98.inc
include th04/th04.inc
include th04/sprites/main_pat.inc
include th04/sprites/blit.inc
include th04/main/phase.inc
include th04/main/bullet/pattypes.inc

View File

@ -23,6 +23,7 @@ BINARY = 'M'
include ReC98.inc
include th05/th05.inc
include th05/sprites/main_pat.inc
include th04/sprites/blit.inc
include th04/main/phase.inc
include th05/main/bullet/pattypes.inc
include th05/main/player/shot_types.inc