From d211a22c9f155498b8ad2c79956f143035cc363b Mon Sep 17 00:00:00 2001 From: nmlgc Date: Fri, 21 Dec 2018 23:03:25 +0100 Subject: [PATCH] [Reverse-engineering] [th04/th05] GRCG-powered playfield row filling Isn't it quite a bit risky to do that without a CLD in front? Funded by zorg. --- th04/hardware/grcg.inc | 8 ++++ th04/hardware/grcg_fill_rows.asm | 14 ++++++ th04_main.asm | 75 +++++--------------------------- th05_main.asm | 62 ++++---------------------- 4 files changed, 42 insertions(+), 117 deletions(-) create mode 100644 th04/hardware/grcg_fill_rows.asm diff --git a/th04/hardware/grcg.inc b/th04/hardware/grcg.inc index e6d24999..33d1b56e 100644 --- a/th04/hardware/grcg.inc +++ b/th04/hardware/grcg.inc @@ -22,3 +22,11 @@ GRCG_SETCOLOR_DIRECT_NOINT_DEF macro instance ret _grcg_setcolor_direct_noint_&instance endp endm + +; Convenience macro to prepare ES:DI. +GRCG_FILL_PLAYFIELD_ROWS macro y:req, num_rows:req, scratch_sgm:= + mov scratch_sgm, GRAM_400 + (((y + PLAYFIELD_Y) * ROW_SIZE) shr 4) + mov es, scratch_sgm + mov di, ((num_rows - 1) * ROW_SIZE) + PLAYFIELD_VRAM_X + call _grcg_fill_playfield_rows +endm diff --git a/th04/hardware/grcg_fill_rows.asm b/th04/hardware/grcg_fill_rows.asm new file mode 100644 index 00000000..18e5afce --- /dev/null +++ b/th04/hardware/grcg_fill_rows.asm @@ -0,0 +1,14 @@ +; Fills the given playfield rows between ES:0 (top row) and ES:DI (left byte +; in the bottom row) with the current GRCG tile. +; Assumes that the GRCG is set to TDW mode. + +; void __usercall grcg_fill_playfield_rows(void far *vram_byte_at_bottom_left); +public _grcg_fill_playfield_rows +_grcg_fill_playfield_rows proc near + mov cx, PLAYFIELD_VRAM_W / 4 + rep stosd + sub di, ROW_SIZE + PLAYFIELD_VRAM_W + jge short _grcg_fill_playfield_rows + retn +_grcg_fill_playfield_rows endp + even diff --git a/th04_main.asm b/th04_main.asm index 0423931d..5b3a5a54 100644 --- a/th04_main.asm +++ b/th04_main.asm @@ -2525,11 +2525,7 @@ sub_BE68 endp sub_BECC proc near push di - mov ax, GRAM_400 + ((112 + PLAYFIELD_Y) * ROW_SIZE) shr 4 - mov es, ax - assume es:nothing - mov di, (255 * ROW_SIZE) + PLAYFIELD_VRAM_X - call sub_12068 + GRCG_FILL_PLAYFIELD_ROWS 112, 256 pop di retn sub_BECC endp @@ -2719,11 +2715,7 @@ loc_C002: stosd sub di, ROW_SIZE + 12 jge short loc_C002 - mov ax, GRAM_400 + (PLAYFIELD_Y * ROW_SIZE) shr 4 - mov es, ax - assume es:nothing - mov di, (111 * ROW_SIZE) + PLAYFIELD_VRAM_X - call sub_12068 + GRCG_FILL_PLAYFIELD_ROWS 0, 112 pop di retn sub_BFF8 endp @@ -2924,11 +2916,7 @@ sub_C0FC endp sub_C148 proc near push di - mov ax, GRAM_400 + (((192 + PLAYFIELD_Y) * ROW_SIZE) shr 4) - mov es, ax - assume es:nothing - mov di, (175 * ROW_SIZE) + 4 - call sub_12068 + GRCG_FILL_PLAYFIELD_ROWS 192, 176 pop di retn sub_C148 endp @@ -8316,16 +8304,8 @@ sub_E8A3 endp sub_EA70 proc near push di - mov ax, GRAM_400 + ((192 + PLAYFIELD_Y) * ROW_SIZE) shr 4 - mov es, ax - assume es:nothing - mov di, (191 * ROW_SIZE) + PLAYFIELD_VRAM_X - call sub_12068 - mov ax, GRAM_400 + (PLAYFIELD_Y * ROW_SIZE) shr 4 - mov es, ax - assume es:nothing - mov di, (79 * ROW_SIZE) + PLAYFIELD_VRAM_X - call sub_12068 + GRCG_FILL_PLAYFIELD_ROWS 192, 192 + GRCG_FILL_PLAYFIELD_ROWS 0, 80 pop di retn sub_EA70 endp @@ -8801,11 +8781,7 @@ sub_ED71 endp sub_EDE2 proc near push di - mov dx, GRAM_400 + (PLAYFIELD_Y * ROW_SIZE) shr 4 - mov es, dx - assume es:nothing - mov di, (119 * ROW_SIZE) + PLAYFIELD_VRAM_X - call sub_12068 + GRCG_FILL_PLAYFIELD_ROWS 0, 120, dx cli mov dx, 7Eh ; '~' xor al, al @@ -8814,11 +8790,7 @@ sub_EDE2 proc near out dx, al out dx, al sti - mov ax, GRAM_400 + ((248 + PLAYFIELD_Y) * ROW_SIZE) shr 4 - mov es, ax - assume es:nothing - mov di, (119 * ROW_SIZE) + PLAYFIELD_VRAM_X - call sub_12068 + GRCG_FILL_PLAYFIELD_ROWS 248, 120 pop di retn sub_EDE2 endp @@ -15178,16 +15150,8 @@ sub_11FC8 endp sub_1200A proc near push di - mov ax, GRAM_400 + (PLAYFIELD_Y * ROW_SIZE) shr 4 - mov es, ax - assume es:nothing - mov di, (39 * ROW_SIZE) + PLAYFIELD_VRAM_X - call sub_12068 - mov ax, GRAM_400 + (((314 + PLAYFIELD_Y) * ROW_SIZE) shr 4) - mov es, ax - assume es:nothing - mov di, (53 * ROW_SIZE) + PLAYFIELD_VRAM_X - call sub_12068 + GRCG_FILL_PLAYFIELD_ROWS 0, 40 + GRCG_FILL_PLAYFIELD_ROWS 314, 54 pop di retn sub_1200A endp @@ -15234,29 +15198,12 @@ sub_12024 endp sub_1205A proc near push di - mov ax, GRAM_400 + (PLAYFIELD_Y * ROW_SIZE) shr 4 - mov es, ax - assume es:nothing - mov di, (PLAYFIELD_H - 1) * ROW_SIZE + PLAYFIELD_VRAM_X - call sub_12068 + GRCG_FILL_PLAYFIELD_ROWS 0, PLAYFIELD_H pop di retn sub_1205A endp - -; =============== S U B R O U T I N E ======================================= - - -sub_12068 proc near - mov cx, 0Ch - rep stosd - sub di, 80h - jge short sub_12068 - retn -sub_12068 endp - -; --------------------------------------------------------------------------- - nop +include th04/hardware/grcg_fill_rows.asm ; =============== S U B R O U T I N E ======================================= diff --git a/th05_main.asm b/th05_main.asm index 825ec77b..7df3578a 100644 --- a/th05_main.asm +++ b/th05_main.asm @@ -4558,20 +4558,7 @@ sub_CFEE proc near retn sub_CFEE endp - -; =============== S U B R O U T I N E ======================================= - - -sub_D024 proc near - mov cx, 0Ch - rep stosd - sub di, 80h - jge short sub_D024 - retn -sub_D024 endp - -; --------------------------------------------------------------------------- - nop +include th04/hardware/grcg_fill_rows.asm ; =============== S U B R O U T I N E ======================================= @@ -6349,11 +6336,7 @@ sub_DD42 proc near out dx, al out dx, al sti - mov dx, GRAM_400 + (((192 + PLAYFIELD_Y) * ROW_SIZE) shr 4) - mov es, dx - assume es:nothing - mov di, (175 * ROW_SIZE) + 4 - call sub_D024 + GRCG_FILL_PLAYFIELD_ROWS 192, 176, dx mov ax, GRAM_400 + (PLAYFIELD_Y * ROW_SIZE) shr 4 mov es, ax assume es:nothing @@ -6592,11 +6575,7 @@ sub_DE7A endp sub_DEA6 proc near push di - mov ax, GRAM_400 + (((192 + PLAYFIELD_Y) * ROW_SIZE) shr 4) - mov es, ax - assume es:nothing - mov di, (175 * ROW_SIZE) + 4 - call sub_D024 + GRCG_FILL_PLAYFIELD_ROWS 192, 176 pop di retn sub_DEA6 endp @@ -6607,11 +6586,7 @@ sub_DEA6 endp sub_DEB4 proc near push di - mov ax, GRAM_400 + (PLAYFIELD_Y * ROW_SIZE) shr 4 - mov es, ax - assume es:nothing - mov di, (204 * ROW_SIZE) + PLAYFIELD_VRAM_X - call sub_D024 + GRCG_FILL_PLAYFIELD_ROWS 0, 205 pop di retn sub_DEB4 endp @@ -6827,11 +6802,7 @@ sub_DFBA endp sub_E01E proc near push di - mov ax, GRAM_400 + (((192 + PLAYFIELD_Y) * ROW_SIZE) shr 4) - mov es, ax - assume es:nothing - mov di, (175 * ROW_SIZE) + 4 - call sub_D024 + GRCG_FILL_PLAYFIELD_ROWS 192, 176 pop di retn sub_E01E endp @@ -8148,16 +8119,8 @@ sub_E8FE endp sub_E914 proc near push di - mov ax, GRAM_400 + (PLAYFIELD_Y * ROW_SIZE) shr 4 - mov es, ax - assume es:nothing - mov di, (103 * ROW_SIZE) + PLAYFIELD_VRAM_X - call sub_D024 - mov ax, GRAM_400 + ((296 + PLAYFIELD_Y) * ROW_SIZE) shr 4 - mov es, ax - assume es:nothing - mov di, (71 * ROW_SIZE) + PLAYFIELD_VRAM_X - call sub_D024 + GRCG_FILL_PLAYFIELD_ROWS 0, 104 + GRCG_FILL_PLAYFIELD_ROWS 296, 72 pop di retn sub_E914 endp @@ -8180,11 +8143,7 @@ sub_E92E proc near out dx, al popf push di - mov ax, GRAM_400 + (PLAYFIELD_Y * ROW_SIZE) shr 4 - mov es, ax - assume es:nothing - mov di, (PLAYFIELD_H - 1) * ROW_SIZE + PLAYFIELD_VRAM_X - call sub_D024 + GRCG_FILL_PLAYFIELD_ROWS 0, PLAYFIELD_H GRCG_OFF_VIA_XOR al pop di retn @@ -8206,10 +8165,7 @@ sub_E950 proc near out dx, al popf push di - mov ax, GRAM_400 + (PLAYFIELD_Y * ROW_SIZE) shr 4 - mov es, ax - mov di, (239 * ROW_SIZE) + PLAYFIELD_VRAM_X - call sub_D024 + GRCG_FILL_PLAYFIELD_ROWS 0, 240 GRCG_OFF_VIA_XOR al pop di retn