From 70d1e1c230cc484e7292891ed05b9780b553f10b Mon Sep 17 00:00:00 2001 From: nmlgc Date: Thu, 6 Dec 2018 17:00:31 +0100 Subject: [PATCH] [Reverse-engineering] [th04/th05] Inlined GRCG color setting calls Funded by -Tom-. --- libs/master.lib/macros.inc | 22 +++++++++++++ th04_main.asm | 67 +++----------------------------------- th04_maine.asm | 13 +------- th04_op.asm | 13 +------- th05_main.asm | 67 +++----------------------------------- th05_maine.asm | 26 ++------------- th05_op.asm | 27 ++------------- 7 files changed, 38 insertions(+), 197 deletions(-) diff --git a/libs/master.lib/macros.inc b/libs/master.lib/macros.inc index 54f298c5..04d3ed3f 100644 --- a/libs/master.lib/macros.inc +++ b/libs/master.lib/macros.inc @@ -80,3 +80,25 @@ GRCG_OFF_VIA_XOR macro value_reg:req out 7Ch, value_reg endm ; ------------------------ + +; GRCG color setting macros +; ------------------------- +; In contrast to master.lib's own grcg_setcolor(), these keep the current +; GRCG mode. +GRCG_SETCOLOR_DIRECT_CLOBBERING macro port_reg:req, col_reg:req + mov port_reg, 7Eh + rept 4 + shr ah, 1 + sbb al, al + out dx, al + endm +endm + +GRCG_SETCOLOR_DIRECT macro col_reg:req + rept 4 + shr col_reg, 1 + sbb al, al + out 7Eh, al + endm +endm +; ------------------------- diff --git a/th04_main.asm b/th04_main.asm index 148bbbe4..c6376e10 100644 --- a/th04_main.asm +++ b/th04_main.asm @@ -2961,19 +2961,7 @@ sub_C15C endp sub_C162 proc near cli - mov dx, 7Eh ; '~' - shr ah, 1 - sbb al, al - out dx, al - shr ah, 1 - sbb al, al - out dx, al - shr ah, 1 - sbb al, al - out dx, al - shr ah, 1 - sbb al, al - out dx, al + GRCG_SETCOLOR_DIRECT_CLOBBERING dx, ah sti retn sub_C162 endp @@ -3519,18 +3507,7 @@ sub_C42C endp sub_C4C0 proc near - shr ah, 1 - sbb al, al - out 7Eh, al - shr ah, 1 - sbb al, al - out 7Eh, al - shr ah, 1 - sbb al, al - out 7Eh, al - shr ah, 1 - sbb al, al - out 7Eh, al + GRCG_SETCOLOR_DIRECT ah retn sub_C4C0 endp @@ -3643,18 +3620,7 @@ sub_C546 proc near nop loc_C57A: - shr ah, 1 - sbb al, al - out 7Eh, al - shr ah, 1 - sbb al, al - out 7Eh, al - shr ah, 1 - sbb al, al - out 7Eh, al - shr ah, 1 - sbb al, al - out 7Eh, al + GRCG_SETCOLOR_DIRECT ah mov ch, 10h mov di, bx cmp di, 7850h @@ -3704,18 +3670,7 @@ loc_C5DC: ; --------------------------------------------------------------------------- loc_C5E2: - shr ah, 1 - sbb al, al - out 7Eh, al - shr ah, 1 - sbb al, al - out 7Eh, al - shr ah, 1 - sbb al, al - out 7Eh, al - shr ah, 1 - sbb al, al - out 7Eh, al + GRCG_SETCOLOR_DIRECT ah mov ch, 10h mov di, bx cmp di, 7850h @@ -18767,19 +18722,7 @@ sub_13E8C endp sub_13EF6 proc near cli - mov dx, 7Eh ; '~' - shr ah, 1 - sbb al, al - out dx, al - shr ah, 1 - sbb al, al - out dx, al - shr ah, 1 - sbb al, al - out dx, al - shr ah, 1 - sbb al, al - out dx, al + GRCG_SETCOLOR_DIRECT_CLOBBERING dx, ah sti retn sub_13EF6 endp diff --git a/th04_maine.asm b/th04_maine.asm index d68dd958..940960c0 100644 --- a/th04_maine.asm +++ b/th04_maine.asm @@ -5326,18 +5326,7 @@ loc_D1FC: push ds mov dx, [bp+0Ah] GRCG_NOINT_SETMODE_VIA_MOV al, GC_RMW - shr dx, 1 - sbb al, al - out 7Eh, al - shr dx, 1 - sbb al, al - out 7Eh, al - shr dx, 1 - sbb al, al - out 7Eh, al - shr dx, 1 - sbb al, al - out 7Eh, al + GRCG_SETCOLOR_DIRECT dx mov ax, 0A800h mov es, ax assume es:nothing diff --git a/th04_op.asm b/th04_op.asm index 9eed31f5..8a531fbd 100644 --- a/th04_op.asm +++ b/th04_op.asm @@ -5549,18 +5549,7 @@ arg_8 = word ptr 0Eh push ds mov dx, [bp+arg_4] GRCG_NOINT_SETMODE_VIA_MOV al, GC_RMW - shr dx, 1 - sbb al, al - out 7Eh, al - shr dx, 1 - sbb al, al - out 7Eh, al - shr dx, 1 - sbb al, al - out 7Eh, al - shr dx, 1 - sbb al, al - out 7Eh, al + GRCG_SETCOLOR_DIRECT dx mov ax, 0A800h mov es, ax assume es:nothing diff --git a/th05_main.asm b/th05_main.asm index db28f4f9..ee0e64a9 100644 --- a/th05_main.asm +++ b/th05_main.asm @@ -6944,18 +6944,7 @@ sub_E02E endp sub_E0C2 proc near - shr ah, 1 - sbb al, al - out 7Eh, al - shr ah, 1 - sbb al, al - out 7Eh, al - shr ah, 1 - sbb al, al - out 7Eh, al - shr ah, 1 - sbb al, al - out 7Eh, al + GRCG_SETCOLOR_DIRECT ah retn sub_E0C2 endp @@ -7068,18 +7057,7 @@ sub_E148 proc near nop loc_E17C: - shr ah, 1 - sbb al, al - out 7Eh, al - shr ah, 1 - sbb al, al - out 7Eh, al - shr ah, 1 - sbb al, al - out 7Eh, al - shr ah, 1 - sbb al, al - out 7Eh, al + GRCG_SETCOLOR_DIRECT ah mov ch, 10h mov di, bx cmp di, 7850h @@ -7129,18 +7107,7 @@ loc_E1DE: ; --------------------------------------------------------------------------- loc_E1E4: - shr ah, 1 - sbb al, al - out 7Eh, al - shr ah, 1 - sbb al, al - out 7Eh, al - shr ah, 1 - sbb al, al - out 7Eh, al - shr ah, 1 - sbb al, al - out 7Eh, al + GRCG_SETCOLOR_DIRECT ah mov ch, 10h mov di, bx cmp di, 7850h @@ -7901,19 +7868,7 @@ sub_E6E8 endp sub_E6EE proc near cli - mov dx, 7Eh ; '~' - shr ah, 1 - sbb al, al - out dx, al - shr ah, 1 - sbb al, al - out dx, al - shr ah, 1 - sbb al, al - out dx, al - shr ah, 1 - sbb al, al - out dx, al + GRCG_SETCOLOR_DIRECT_CLOBBERING dx, ah sti retn sub_E6EE endp @@ -21975,19 +21930,7 @@ sub_159E6 endp sub_15A04 proc near cli - mov dx, 7Eh ; '~' - shr ah, 1 - sbb al, al - out dx, al - shr ah, 1 - sbb al, al - out dx, al - shr ah, 1 - sbb al, al - out dx, al - shr ah, 1 - sbb al, al - out dx, al + GRCG_SETCOLOR_DIRECT_CLOBBERING dx, ah sti retn sub_15A04 endp diff --git a/th05_maine.asm b/th05_maine.asm index e3a7bed7..c2648eff 100644 --- a/th05_maine.asm +++ b/th05_maine.asm @@ -168,18 +168,7 @@ arg_4 = word ptr 0Ah nop loc_2E02: - shr ah, 1 - sbb al, al - out 7Eh, al - shr ah, 1 - sbb al, al - out 7Eh, al - shr ah, 1 - sbb al, al - out 7Eh, al - shr ah, 1 - sbb al, al - out 7Eh, al + GRCG_SETCOLOR_DIRECT ah mov ch, dl loc_2E1C: @@ -8275,18 +8264,7 @@ arg_8 = word ptr 0Eh push ds mov dx, [bp+arg_4] GRCG_NOINT_SETMODE_VIA_MOV al, GC_RMW - shr dx, 1 - sbb al, al - out 7Eh, al - shr dx, 1 - sbb al, al - out 7Eh, al - shr dx, 1 - sbb al, al - out 7Eh, al - shr dx, 1 - sbb al, al - out 7Eh, al + GRCG_SETCOLOR_DIRECT dx mov ax, 0A800h mov es, ax assume es:nothing diff --git a/th05_op.asm b/th05_op.asm index 1409fe1a..094e2c4b 100644 --- a/th05_op.asm +++ b/th05_op.asm @@ -5139,18 +5139,7 @@ arg_8 = word ptr 0Eh push ds mov dx, [bp+arg_4] GRCG_NOINT_SETMODE_VIA_MOV al, GC_RMW - shr dx, 1 - sbb al, al - out 7Eh, al - shr dx, 1 - sbb al, al - out 7Eh, al - shr dx, 1 - sbb al, al - out 7Eh, al - shr dx, 1 - sbb al, al - out 7Eh, al + GRCG_SETCOLOR_DIRECT dx mov ax, 0A800h mov es, ax assume es:nothing @@ -5843,19 +5832,7 @@ sub_DB0D endp sub_DB21 proc near cli - mov dx, 7Eh ; '~' - shr ah, 1 - sbb al, al - out dx, al - shr ah, 1 - sbb al, al - out dx, al - shr ah, 1 - sbb al, al - out dx, al - shr ah, 1 - sbb al, al - out dx, al + GRCG_SETCOLOR_DIRECT_CLOBBERING dx, ah sti retn sub_DB21 endp