This post is going to be huge... sorry for that.
The [Wait] and the [Delay] characters are a little bit troublesome.
The routine which displays the script characters in screen was hacked by RPGe to allow displaying a VWF. It works accumulating the graphics of the different characters to display in a buffer and whenever the buffer reaches 16 pixels width or more, the first 16 pixels of the buffer (64 bytes) are written in VRAM and the buffer cleared.
There is a flag [$00:0BA7] which is set to 0 when the buffer is not fully filed and 1 or more when the buffer have 16 or more pixel columns to display.
That means that flag is written, to trigger the display of the buffer, also with some special characters: [End Of Line], [End of Dialogue], [Autoclose], [Wait] and [Delay].
The first three of them are not a problem. [Wait] and [Delay] are.
When the buffer is written to VRAM, the pointer to VRAM is incremented by 64 bytes but the buffer is not cleared.
That means, when a [Wait] or [Delay] are reached, the buffer is going to be written on the screen, with the right side of the buffer blank, which is right, but after the wait the buffer is going to be displayed again fully filled, some pixels ahead.
In example, the sequence "Hello[Delay] my friend!" will be displayed as:
- Before the wait "Hello"
- After the wait "Hello o my friend!"
I have not been able to find how to reset the buffer and anyway the VRAM pointer is increased, so the next location to write in the screen after a wait is always issued...
RPGe deal with this writing four blanks before a wait and jumping to next line after waiting. I didn't like that shortcut.
To fix it, I propose four edits:
FIRST:
E0/31A8 is the address where the flag is written after a wait. Currently the code increment the flag and the accumulated width in 16 pixels.
My attempt is avoiding the width increment as it only throws right the next characters to display.
As A7 is used only as a flag, and for anything else (as long as I know) I am writing #$42 in it.
E0/31A8 <= A9, 42, 85, A7, 6B, EA, EA, EA, EA, EA
$E0/31A8 A9 42 LDA $#42 ; .
$E0/31AA 85 A7 STA $A7 ; writeBufferFlag = 0x42
$E0/31AC 6B RTL ; return
$E0/31AD EA EA EA EA NOP NOP NOP NOP ; ...
$E0/31B1 EA NOP ; ...
SECOND:
C0/8E23 is the method write the buffer in the VRAM.
My attempt is not clearing the flag here and doing an additional treatment at the very end of the method.
C0/8E23 <= EA, EA
$C0/8E23 64 A7 STZ $A7 -> EA EA NOP NOP
C0/8ECE <= 22, 30, 4C, E0
$C0/8ECE A5 06 LDA $06 -> 22 30 4C E0 JSL $E04C30
$C0/8ED0 E2 20 SEP #$20 ..
; E04C30 will be a new method
THIRD:
From E04C30 and forward, the bank E0 only contains blanks.
My attempt is writing a method here which takes back the pointer to VRAM in 64 bytes whenever the flag variable contains a value > 0x40.
E04C30 <= A5, A7, 29, FF, 00, C9, 40, 00,
90, 08, A5, A9, 38, E9, 40, 00,
85, A9, A5, 06, E2, 20, 85, A7,
6B
A5 A7 LDA A7 ; .
29 FF 00 AND #$00FF ; .
C9 40 00 CMP #$0040 ; .
90 08 BCC $08 ; if (writeBufferFlag >= 0x40){
A5 A9 LDA $A9 ; .
38 SEC ; .
E9 40 00 SBC #$0040 ; Pointer to paint -= 0x40;
85 A9 STA $A9 ; }
A5 06 LDA $06 ; // Normal routine solving
E2 20 SEP #$20 ; // A width set to 8 bit
85 A7 STA $A7 ; writeBufferFlag = A = 0;
6B RTL ; return;
These editions solve the issue and the texts are displayed as expected.