[Reverse-engineering] [th04/th05] EGC-powered page 1→0 region copies

This commit is contained in:
wintiger0222 2019-12-07 16:37:29 +09:00 committed by nmlgc
parent 0dcfc445b8
commit cb45bf5a80
6 changed files with 144 additions and 348 deletions

3
th04/hardware/egc.h Normal file
View File

@ -0,0 +1,3 @@
// Blits the rectangle from (⌊x/16⌋*16, y) to (⌈((x + w)/16)*16⌉, (y + h))
// from VRAM page 1 to the same position on VRAM page 0.
void pascal egc_copy_rect_1_to_0(int x, int y, int w, int h);

111
th04/hardware/egccopyr.asm Normal file
View File

@ -0,0 +1,111 @@
public EGC_COPY_RECT_1_TO_0
egc_copy_rect_1_to_0 proc far
@@h = word ptr [bp+6]
@@w = word ptr [bp+8]
@@y = word ptr [bp+10]
@@x = word ptr [bp+12]
@@row equ bx
@@stride equ bp
push bp
mov bp, sp
push di
if GAME eq 4
cld
endif
call egc_start_copy
outw EGC_MODE_ROP_REG, EGC_COMPAREREAD or EGC_WS_ROP or EGC_RL_MEMREAD or 0F0h
mov ax, @@x
mov dx, @@y
mov bx, ax
sar bx, 4
shl bx, 1
shl dx, 6
add bx, dx
shr dx, 2
add bx, dx
mov di, bx
and ax, 0Fh
mov cx, ax
add ax, @@w
shr ax, 4
or cx, cx
jz short @@x_on_word_boundary
inc ax
@@x_on_word_boundary:
mov _egccopyr_width_words, ax
mov cx, (ROW_SIZE / 2)
sub cx, ax
shl cx, 1
mov @@row, @@h
mov @@stride, cx
mov ax, GRAM_400
mov es, ax
assume es:nothing
@@next_row:
mov cx, _egccopyr_width_words
@@next_word:
if GAME eq 5
or di, di
js short @@skip
cmp di, (ROW_SIZE * RES_Y)
jnb short @@skip
endif
mov al, 1
out 0A6h, al
mov dx, es:[di]
xor ax, ax
out 0A6h, al
if GAME eq 5
mov es:[di], dx
@@skip:
add di, 2
else
mov ax, dx
stosw
endif
loop @@next_word
add di, @@stride
dec @@row
jns short @@next_row
call egc_off
pop di
pop bp
retf 8
egc_copy_rect_1_to_0 endp
align 2
public egc_start_copy
egc_start_copy proc near
push es
push 0
pop es
pushf
cli
GRCG_SETMODE_VIA_MOV al, GC_TDW
mov es:[495h], al
popf
pop es
assume es:nothing
mov al, 7
out 6Ah, al
mov al, 5
out 6Ah, al
mov al, 6
out 6Ah, al
outw EGC_ACTIVEPLANEREG, 0FFF0h
outw EGC_READPLANEREG, 0FFh
outw EGC_MASKREG, 0FFFFh
mov dx, EGC_ADDRRESSREG
sub ax, ax
out dx, ax
outw EGC_BITLENGTHREG, 0Fh
retn
egc_start_copy endp

View File

@ -0,0 +1,2 @@
public _egccopyr_width_words
_egccopyr_width_words dw ?

View File

@ -550,7 +550,7 @@ arg_2 = word ptr 6
push 100h push 100h
push ax push ax
push 800010h push 800010h
call sub_E378 call egc_copy_rect_1_to_0
call grcg_setcolor pascal, GC_RMW, [bp+arg_0] call grcg_setcolor pascal, GC_RMW, [bp+arg_0]
mov [bp+var_2], si mov [bp+var_2], si
mov bx, si mov bx, si
@ -615,7 +615,7 @@ loc_AB59:
call cdg_put pascal, 352, di, 36 call cdg_put pascal, 352, di, 36
pushd 180h pushd 180h
push 2800010h push 2800010h
call sub_E378 call egc_copy_rect_1_to_0
mov _graph_putsa_fx_func, 2 mov _graph_putsa_fx_func, 2
mov bx, [bp+var_2] mov bx, [bp+var_2]
shl bx, 2 shl bx, 2
@ -675,7 +675,7 @@ loc_ABF7:
push 0E0h push 0E0h
push [bp+var_4] push [bp+var_4]
push 0C00010h push 0C00010h
call sub_E378 call egc_copy_rect_1_to_0
loc_AC08: loc_AC08:
call grcg_setcolor pascal, GC_RMW, [bp+arg_0] call grcg_setcolor pascal, GC_RMW, [bp+arg_0]
@ -849,7 +849,7 @@ loc_ADC0:
call cdg_put call cdg_put
pushd 180h pushd 180h
push 2800010h push 2800010h
call sub_E378 call egc_copy_rect_1_to_0
mov _graph_putsa_fx_func, 2 mov _graph_putsa_fx_func, 2
mov bx, si mov bx, si
shl bx, 2 shl bx, 2
@ -955,7 +955,7 @@ sub_AE96 proc near
mov byte_10DAC, 0 mov byte_10DAC, 0
push 0C000E0h push 0C000E0h
push 12000A0h push 12000A0h
call sub_E378 call egc_copy_rect_1_to_0
xor si, si xor si, si
jmp short loc_AED6 jmp short loc_AED6
; --------------------------------------------------------------------------- ; ---------------------------------------------------------------------------
@ -1120,7 +1120,7 @@ sub_B052 proc near
mov byte_10DAD, 0 mov byte_10DAD, 0
push 11000E0h push 11000E0h
push 0A00090h push 0A00090h
call sub_E378 call egc_copy_rect_1_to_0
xor si, si xor si, si
jmp short loc_B08D jmp short loc_B08D
; --------------------------------------------------------------------------- ; ---------------------------------------------------------------------------
@ -1583,7 +1583,7 @@ arg_2 = word ptr 6
shl ax, 4 shl ax, 4
push ax push ax
push 10h push 10h
call sub_E378 call egc_copy_rect_1_to_0
push si push si
push di push di
push 2 push 2
@ -1654,7 +1654,7 @@ arg_2 = word ptr 6
shl ax, 4 shl ax, 4
push ax push ax
push 10h push 10h
call sub_E378 call egc_copy_rect_1_to_0
push si push si
push di push di
push 6 push 6
@ -1778,7 +1778,7 @@ arg_2 = word ptr 6
shl ax, 4 shl ax, 4
push ax push ax
push 20h ; ' ' push 20h ; ' '
call sub_E378 call egc_copy_rect_1_to_0
push si push si
push di push di
push 5 push 5
@ -4997,112 +4997,8 @@ include th02/initop.asm
include th04/formats/cdg_put_noalpha.asm include th04/formats/cdg_put_noalpha.asm
include th04/hardware/input_sense.asm include th04/hardware/input_sense.asm
include th04/snd/se.asm include th04/snd/se.asm
include th04/hardware/egccopyr.asm
; =============== S U B R O U T I N E ======================================= even
; Attributes: bp-based frame
sub_E378 proc far
arg_0 = word ptr 6
arg_2 = word ptr 8
arg_4 = word ptr 0Ah
arg_6 = word ptr 0Ch
push bp
mov bp, sp
push di
cld
call sub_E3E8
outw EGC_MODE_ROP_REG, EGC_COMPAREREAD or EGC_WS_ROP or EGC_RL_MEMREAD or 0F0h
mov ax, [bp+arg_6]
mov dx, [bp+arg_4]
mov bx, ax
sar bx, 4
shl bx, 1
shl dx, 6
add bx, dx
shr dx, 2
add bx, dx
mov di, bx
and ax, 0Fh
mov cx, ax
add ax, [bp+arg_2]
shr ax, 4
or cx, cx
jz short loc_E3B0
inc ax
loc_E3B0:
mov word_11A54, ax
mov cx, 28h ; '('
sub cx, ax
shl cx, 1
mov bx, [bp+arg_0]
mov bp, cx
mov ax, 0A800h
mov es, ax
assume es:nothing
loc_E3C4:
mov cx, word_11A54
loc_E3C8:
mov al, 1
out 0A6h, al
mov dx, es:[di]
xor ax, ax
out 0A6h, al
mov ax, dx
stosw
loop loc_E3C8
add di, bp
dec bx
jns short loc_E3C4
call egc_off
pop di
pop bp
retf 8
sub_E378 endp
; ---------------------------------------------------------------------------
nop
; =============== S U B R O U T I N E =======================================
sub_E3E8 proc near
push es
push 0
pop es
pushf
cli
GRCG_SETMODE_VIA_MOV al, GC_TDW
mov byte ptr es:[495h], al
popf
pop es
assume es:nothing
mov al, 7
out 6Ah, al ; PC-98 GDC (6a):
;
mov al, 5
out 6Ah, al ; PC-98 GDC (6a):
;
mov al, 6
out 6Ah, al ; PC-98 GDC (6a):
;
outw EGC_ACTIVEPLANEREG, 0FFF0h
outw EGC_READPLANEREG, 0FFh
outw EGC_MASKREG, 0FFFFh
mov dx, EGC_ADDRRESSREG
sub ax, ax
out dx, ax
outw EGC_BITLENGTHREG, 0Fh
retn
sub_E3E8 endp
; ---------------------------------------------------------------------------
nop
include th04/bgimage.asm include th04/bgimage.asm
include th04/bgimage_put_rect.asm include th04/bgimage_put_rect.asm
include th04/formats/cdg_load.asm include th04/formats/cdg_load.asm
@ -5442,7 +5338,7 @@ include libs/master.lib/bgm[bss].asm
include th02/snd/load[bss].asm include th02/snd/load[bss].asm
include th04/mem[bss].asm include th04/mem[bss].asm
include th04/hardware/input[bss].asm include th04/hardware/input[bss].asm
word_11A54 dw ? include th04/hardware/egccopyr[bss].asm
include th04/formats/cdg[bss].asm include th04/formats/cdg[bss].asm
dd ? ; dd ? ;
dd ? ; dd ? ;

View File

@ -460,7 +460,7 @@ arg_6 = word ptr 0Ah
push si push si
push di push di
push 14000C8h push 14000C8h
call sub_F3FC call egc_copy_rect_1_to_0
pop di pop di
pop si pop si
pop bp pop bp
@ -1301,7 +1301,7 @@ loc_AE42:
loc_AE64: loc_AE64:
push 0A00040h push 0A00040h
push 14000C8h push 14000C8h
call sub_F3FC call egc_copy_rect_1_to_0
jmp loc_AF8F ; default jmp loc_AF8F ; default
; --------------------------------------------------------------------------- ; ---------------------------------------------------------------------------
@ -8298,115 +8298,7 @@ include th05/snd/delaymea.asm
include th05/hardware/frame_delay.asm include th05/hardware/frame_delay.asm
db 0 db 0
include th04/formats/cdg_load.asm include th04/formats/cdg_load.asm
include th04/hardware/egccopyr.asm
; =============== S U B R O U T I N E =======================================
; Attributes: bp-based frame
sub_F3FC proc far
arg_0 = word ptr 6
arg_2 = word ptr 8
arg_4 = word ptr 0Ah
arg_6 = word ptr 0Ch
push bp
mov bp, sp
push di
call sub_F478
outw EGC_MODE_ROP_REG, EGC_COMPAREREAD or EGC_WS_ROP or EGC_RL_MEMREAD or 0F0h
mov ax, [bp+arg_6]
mov dx, [bp+arg_4]
mov bx, ax
sar bx, 4
shl bx, 1
shl dx, 6
add bx, dx
shr dx, 2
add bx, dx
mov di, bx
and ax, 0Fh
mov cx, ax
add ax, [bp+arg_2]
shr ax, 4
or cx, cx
jz short loc_F433
inc ax
loc_F433:
mov word_12F86, ax
mov cx, 28h ; '('
sub cx, ax
shl cx, 1
mov bx, [bp+arg_0]
mov bp, cx
mov ax, GRAM_400
mov es, ax
assume es:nothing
loc_F447:
mov cx, word_12F86
loc_F44B:
or di, di
js short loc_F463
cmp di, 7D00h
jnb short loc_F463
mov al, 1
out 0A6h, al
mov dx, es:[di]
xor ax, ax
out 0A6h, al
mov es:[di], dx
loc_F463:
add di, 2
loop loc_F44B
add di, bp
dec bx
jns short loc_F447
call egc_off
pop di
pop bp
retf 8
sub_F3FC endp
; ---------------------------------------------------------------------------
nop
; =============== S U B R O U T I N E =======================================
sub_F478 proc near
push es
push 0
pop es
pushf
cli
GRCG_SETMODE_VIA_MOV al, GC_TDW
mov es:[495h], al
popf
pop es
assume es:nothing
mov al, 7
out 6Ah, al ; PC-98 GDC (6a):
;
mov al, 5
out 6Ah, al ; PC-98 GDC (6a):
;
mov al, 6
out 6Ah, al ; PC-98 GDC (6a):
;
outw EGC_ACTIVEPLANEREG, 0FFF0h
outw EGC_READPLANEREG, 0FFh
outw EGC_MASKREG, 0FFFFh
mov dx, EGC_ADDRRESSREG
sub ax, ax
out dx, ax
outw EGC_BITLENGTHREG, 0Fh
retn
sub_F478 endp
maine_02_TEXT ends maine_02_TEXT ends
.data .data
@ -8876,7 +8768,7 @@ include th05/formats/pi_slot_headers[bss].asm
include th04/hardware/input[bss].asm include th04/hardware/input[bss].asm
include th04/formats/cdg[bss].asm include th04/formats/cdg[bss].asm
include libs/master.lib/pfint21[bss].asm include libs/master.lib/pfint21[bss].asm
word_12F86 dw ? include th04/hardware/egccopyr[bss].asm
dd ? ; dd ? ;
dd ? ; dd ? ;
dd ? ; dd ? ;

View File

@ -453,7 +453,7 @@ arg_2 = word ptr 6
push 100h push 100h
push ax push ax
push 800010h push 800010h
call sub_E2D8 call egc_copy_rect_1_to_0
call grcg_setcolor pascal, GC_RMW, [bp+arg_0] call grcg_setcolor pascal, GC_RMW, [bp+arg_0]
mov [bp+var_2], si mov [bp+var_2], si
mov bx, si mov bx, si
@ -520,7 +520,7 @@ loc_A69A:
call cdg_put pascal, 352, di, 36 call cdg_put pascal, 352, di, 36
pushd 180h pushd 180h
push 2800010h push 2800010h
call sub_E2D8 call egc_copy_rect_1_to_0
mov _graph_putsa_fx_func, 2 mov _graph_putsa_fx_func, 2
mov bx, [bp+var_2] mov bx, [bp+var_2]
shl bx, 2 shl bx, 2
@ -579,7 +579,7 @@ loc_A737:
push 0E0h push 0E0h
push [bp+var_4] push [bp+var_4]
push 0C00010h push 0C00010h
call sub_E2D8 call egc_copy_rect_1_to_0
call grcg_setcolor pascal, GC_RMW, [bp+arg_0] call grcg_setcolor pascal, GC_RMW, [bp+arg_0]
mov bx, [bp+arg_2] mov bx, [bp+arg_2]
cmp bx, 7 cmp bx, 7
@ -753,7 +753,7 @@ loc_A900:
call cdg_put call cdg_put
pushd 180h pushd 180h
push 2800010h push 2800010h
call sub_E2D8 call egc_copy_rect_1_to_0
mov _graph_putsa_fx_func, 2 mov _graph_putsa_fx_func, 2
mov bx, si mov bx, si
shl bx, 2 shl bx, 2
@ -859,7 +859,7 @@ sub_A9D6 proc near
mov byte_11DD4, 0 mov byte_11DD4, 0
push 0C000FAh push 0C000FAh
push 12000A0h push 12000A0h
call sub_E2D8 call egc_copy_rect_1_to_0
xor si, si xor si, si
jmp short loc_AA16 jmp short loc_AA16
; --------------------------------------------------------------------------- ; ---------------------------------------------------------------------------
@ -1034,7 +1034,7 @@ sub_ABCF proc near
mov byte_11DD5, 0 mov byte_11DD5, 0
push 11000FAh push 11000FAh
push 0A00090h push 0A00090h
call sub_E2D8 call egc_copy_rect_1_to_0
xor si, si xor si, si
jmp short loc_AC0A jmp short loc_AC0A
; --------------------------------------------------------------------------- ; ---------------------------------------------------------------------------
@ -1525,7 +1525,7 @@ arg_2 = word ptr 6
shl ax, 4 shl ax, 4
push ax push ax
push 10h push 10h
call sub_E2D8 call egc_copy_rect_1_to_0
push si push si
push di push di
push 2 push 2
@ -1596,7 +1596,7 @@ arg_2 = word ptr 6
shl ax, 4 shl ax, 4
push ax push ax
push 10h push 10h
call sub_E2D8 call egc_copy_rect_1_to_0
push si push si
push di push di
push 6 push 6
@ -1720,7 +1720,7 @@ arg_2 = word ptr 6
shl ax, 4 shl ax, 4
push ax push ax
push 20h ; ' ' push 20h ; ' '
call sub_E2D8 call egc_copy_rect_1_to_0
push si push si
push di push di
push 5 push 5
@ -4799,116 +4799,8 @@ include th04/formats/cdg_put_nocolors.asm
include th05/hardware/frame_delay.asm include th05/hardware/frame_delay.asm
db 0 db 0
include th04/formats/cdg_load.asm include th04/formats/cdg_load.asm
include th04/hardware/egccopyr.asm
; =============== S U B R O U T I N E ======================================= even
; Attributes: bp-based frame
sub_E2D8 proc far
arg_0 = word ptr 6
arg_2 = word ptr 8
arg_4 = word ptr 0Ah
arg_6 = word ptr 0Ch
push bp
mov bp, sp
push di
call sub_E354
outw EGC_MODE_ROP_REG, EGC_COMPAREREAD or EGC_WS_ROP or EGC_RL_MEMREAD or 0F0h
mov ax, [bp+arg_6]
mov dx, [bp+arg_4]
mov bx, ax
sar bx, 4
shl bx, 1
shl dx, 6
add bx, dx
shr dx, 2
add bx, dx
mov di, bx
and ax, 0Fh
mov cx, ax
add ax, [bp+arg_2]
shr ax, 4
or cx, cx
jz short loc_E30F
inc ax
loc_E30F:
mov word_12EFE, ax
mov cx, 28h ; '('
sub cx, ax
shl cx, 1
mov bx, [bp+arg_0]
mov bp, cx
mov ax, GRAM_400
mov es, ax
assume es:nothing
loc_E323:
mov cx, word_12EFE
loc_E327:
or di, di
js short loc_E33F
cmp di, 7D00h
jnb short loc_E33F
mov al, 1
out 0A6h, al
mov dx, es:[di]
xor ax, ax
out 0A6h, al
mov es:[di], dx
loc_E33F:
add di, 2
loop loc_E327
add di, bp
dec bx
jns short loc_E323
call egc_off
pop di
pop bp
retf 8
sub_E2D8 endp
; ---------------------------------------------------------------------------
nop
; =============== S U B R O U T I N E =======================================
sub_E354 proc near
push es
push 0
pop es
pushf
cli
GRCG_SETMODE_VIA_MOV al, GC_TDW
mov es:[495h], al
popf
pop es
assume es:nothing
mov al, 7
out 6Ah, al ; PC-98 GDC (6a):
;
mov al, 5
out 6Ah, al ; PC-98 GDC (6a):
;
mov al, 6
out 6Ah, al ; PC-98 GDC (6a):
;
outw EGC_ACTIVEPLANEREG, 0FFF0h
outw EGC_READPLANEREG, 0FFh
outw EGC_MASKREG, 0FFFFh
mov dx, EGC_ADDRRESSREG
sub ax, ax
out dx, ax
outw EGC_BITLENGTHREG, 0Fh
retn
sub_E354 endp
align 2
op_02_TEXT ends op_02_TEXT ends
.data .data
@ -5696,7 +5588,7 @@ include th05/formats/pi_slot_headers[bss].asm
include th04/hardware/input[bss].asm include th04/hardware/input[bss].asm
include th04/formats/cdg[bss].asm include th04/formats/cdg[bss].asm
include libs/master.lib/pfint21[bss].asm include libs/master.lib/pfint21[bss].asm
word_12EFE dw ? include th04/hardware/egccopyr[bss].asm
dd ? ; dd ? ;
dd ? ; dd ? ;
dd ? ; dd ? ;