[Reverse-engineering] Enabling and disabling the EGC

Which involves temporarily enabling a GDC mode change bit.

Completes P0125, funded by [Anonymous].
This commit is contained in:
nmlgc 2020-11-01 20:09:18 +01:00
parent 6a8de71720
commit f6a3246071
8 changed files with 69 additions and 58 deletions

View File

@ -32,7 +32,7 @@ bin\Pipeline\grzview.com: Pipeline\grzview.cpp th01\formats\grz.cpp
$(CC) $(CFLAGS) -Z -mt -lt -nbin\Pipeline\ $** masters.lib
bin\th01\zunsoft.com: th01\zunsoft.c
$(CC) $(CFLAGS) -mt -lt -nbin\th01\ $** masters.lib
$(CC) $(CFLAGS) -mt -lt -DGAME=1 -nbin\th01\ $** masters.lib
# Segment 2 (game-independent code)
# ---------------------------------

View File

@ -12,6 +12,12 @@
#define FLAGS_ZERO (_FLAGS & 0x40) /* JZ */
// ----------------
// Alternate version that doesn't spill the port number to DX
#define outportb2(port, val) __asm { \
mov al, val; \
out port, al; \
}
// Alternate version that sets the value first
#define OUTW2(port, val) __asm { \
mov ax, val; \

View File

@ -21,6 +21,7 @@
; And yes, we can't move this to an include file for some reason.
include libs/master.lib/macros.inc
include th01/hardware/egc.inc
; ===========================================================================
@ -1928,15 +1929,7 @@ sub_BD0 proc near
push ax
push dx
cli
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):
;
graph_egc 1
GRCG_SETMODE_VIA_MOV al, GC_TDW
outw EGC_ACTIVEPLANEREG, 0FFF0h
outw EGC_READPLANEREG, 0FFh
@ -1963,15 +1956,7 @@ sub_C10 proc near
outw EGC_ACTIVEPLANEREG, 0FFF0h
outw EGC_READPLANEREG, 0FFh
outw EGC_MASKREG, 0FFFFh
mov al, 7
out 6Ah, al ; PC-98 GDC (6a):
;
mov al, 4
out 6Ah, al ; PC-98 GDC (6a):
;
mov al, 6
out 6Ah, al ; PC-98 GDC (6a):
;
graph_egc 0
GRCG_OFF_VIA_XOR al
sti
pop dx

View File

@ -1,6 +1,28 @@
#include "defconv.h"
#include "decomp.h"
/// Enabling and disabling
/// ----------------------
#define graph_mode_change(enable_or_disable) \
outportb2(0x6A, (0x06 + enable_or_disable))
// Requires graphics mode changing to be enabled via graph_mode_change(true).
#define graph_mode_egc(enable_or_disable) \
outportb2(0x6A, (0x04 + enable_or_disable))
#define graph_egc(enable_or_disable) \
graph_mode_change(true); \
graph_mode_egc(enable_or_disable); \
graph_mode_change(false);
#define graph_egc_on() \
graph_egc(true);
#define graph_egc_off() \
graph_egc(false);
/// ----------------------
// Requires the EGC to have been activated before.
#define egc_setup_copy() \
OUTW2(EGC_ACTIVEPLANEREG, 0xFFF0); \

View File

@ -1,6 +1,22 @@
; ReC98
; Inlined EGC code
graph_mode_change macro enable_or_disable:req
mov al, (6 + enable_or_disable)
out 6Ah, al
endm
graph_mode_egc macro enable_or_disable:req
mov al, (4 + enable_or_disable)
out 6Ah, al
endm
graph_egc macro enable_or_disable:req
graph_mode_change 1
graph_mode_egc enable_or_disable
graph_mode_change 0
endm
EGC_SETUP_COPY macro
outw2 EGC_ACTIVEPLANEREG, 0FFF0h
egc_selectpat
@ -26,12 +42,9 @@ endm
EGC_START_COPY_INLINED macro
GRCG_OFF_VIA_MOV al
mov al, 7
out 6Ah, al
mov al, 5
out 6Ah, al
graph_mode_change 1
graph_mode_egc 1
GRCG_SETMODE_VIA_MOV al, GC_TDW
mov al, 6
out 6Ah, al
graph_mode_change 0
EGC_SETUP_COPY
endm

View File

@ -6,6 +6,7 @@
#include <master.h>
#include "platform.h"
#include "pc98.h"
#include "th01/hardware/egc.h"
#define CIRCLE_COUNT 4
#define STAR_COUNT 50
@ -209,16 +210,17 @@ void main(void)
mov es, ax
test byte ptr es:0x45C, 0x40
jz hw_setup_done
mov al, 0x7
out 0x6a, al
mov al, 0x20
out 0x6a, al
mov al, 0x6
out 0x6a, al
// Activate all graphics hardware in 16-color mode
and byte ptr es:0x54d, 0x7f
hw_setup_done:
}
graph_mode_change(true); __asm {
mov al, 0x20
out 0x6a, al
}
graph_mode_change(false);
// Activate all graphics hardware in 16-color mode
__asm { and byte ptr es:0x54d, 0x7f }
hw_setup_done:
zunsoft_init();
objects_setup();
while(1) {

View File

@ -2741,16 +2741,10 @@ loc_BD26:
call farfp_1F490
outw2 EGC_ACTIVEPLANEREG, 0FFF0h
outw2 EGC_MASKREG, 0FFFFh
mov al, 7
out 6Ah, al ; PC-98 GDC (6a):
;
mov al, 4
out 6Ah, al ; PC-98 GDC (6a):
;
graph_mode_change 1
graph_mode_egc 0
GRCG_OFF_VIA_MOV al
mov al, 6
out 6Ah, al ; PC-98 GDC (6a):
;
graph_mode_change 0
mov ax, word_2034A
cmp ax, word_20616
jnz short loc_BD62
@ -2843,16 +2837,10 @@ loc_BE3B:
mov byte_1E501, al
outw2 EGC_ACTIVEPLANEREG, 0FFF0h
outw2 EGC_MASKREG, 0FFFFh
mov al, 7
out 6Ah, al ; PC-98 GDC (6a):
;
mov al, 4
out 6Ah, al ; PC-98 GDC (6a):
;
graph_mode_change 1
graph_mode_egc 0
GRCG_OFF_VIA_MOV al
mov al, 6
out 6Ah, al ; PC-98 GDC (6a):
;
graph_mode_change 0
cmp byte_1E501, 0
jz short loc_BE77
inc _scroll_line

View File

@ -94,12 +94,7 @@ egc_start_copy proc near
popf
pop es
assume es:nothing
mov al, 7
out 6Ah, al
mov al, 5
out 6Ah, al
mov al, 6
out 6Ah, al
graph_egc 1
outw EGC_ACTIVEPLANEREG, 0FFF0h
outw EGC_READPLANEREG, 0FFh
outw EGC_MASKREG, 0FFFFh