joncampbell123 / dosbox-x

DOSBox-X fork of the DOSBox project
GNU General Public License v2.0
2.8k stars 383 forks source link

PC-98: Borland conio.h text output functions not emulated correctly #769

Closed nmlgc closed 4 months ago

nmlgc commented 6 years ago

Two issues here:

Here's my test source code, with a binary and linker map, compiled using the Japanese version of Turbo C++ Version 4.02 Copyright (c) 1994 Borland International.

Correct output on Neko Project 21, and what you would expect from how the same binary behaves on IBM-compatibles: colorbug np21

Output on DOSBox-X: colorbug dosbox-x

I've narrowed down the first issue to __NEC_WHEREXY reading the wrong row value from [0060:0110], but wouldn't know how to fix this properly and non-hacky.

joncampbell123 commented 6 years ago

Ick...

This is why the DOS kernel in DOSBox-X is written to start the DOS kernel at segment 80h instead of 60h in PC-98 mode, so that fixed variables could be allocated between 60h and 7Fh. Apparently it is considered normal for PC-98 games to read state directly from DOS kernel memory. Case in point: Touhou Project won't clear the text layer properly unless it can read the number of text layer rows from a fixed address somewhere around 60:114 (I forget exactly).

joncampbell123 commented 6 years ago

So to fix this, CON device emulation in PC-98 mode needs to mirror the cursor position at that address.

joncampbell123 commented 6 years ago

Booting a real PC-98 DOS bootdisk, I see where the row and column are stored:

pc98rowval

joncampbell123 commented 6 years ago

I suppose it was time to move console emulation away from re-using IBM PC BIOS locations anyway...

I just pushed a commit that removes cursor position from 40:xx and puts it in segment 60:110-60:11C in the same way that normal DOS does it.

I don't think I broke anything, but it's best to double-check.

It does allow your program to print properly IF run when the cursor is at the bottom of the screen, and it allows the last line to appear otherwise.

Borland C is making unknown calls to INT DCh that I do not know how to emulate.

LOG: PC-98 INT 1Ah unknown call AX=040F BX=3574 CX=0000 DX=3574 SI=356E DI=3580 DS=0306 ES=0306
LOG: PC-98 INT DCh unknown call AX=0310 BX=0CA0 CX=3010 DX=1410 SI=356E DI=3580 DS=0306 ES=A000
LOG: PC-98 INT DCh unknown call AX=0300 BX=0006 CX=3010 DX=1500 SI=356E DI=3580 DS=0306 ES=0000
LOG: PC-98 INT DCh unknown call AX=0300 BX=0006 CX=3110 DX=1500 SI=356E DI=3580 DS=0306 ES=0000
joncampbell123 commented 6 years ago

Argh, hold on, the ANSI cursor positioning code is messed up right now...

joncampbell123 commented 6 years ago

Okay, try it now.

nmlgc commented 6 years ago

Looks almost correct now when printed at the bottom of the screen, except that cputs() shouldn't move the cursor to the beginning of a line at the end of the string.

colorbug 2 bottom

Calling it from further above swallows the first line though.

colorbug 2 top

That will all be covered once all the addresses from memdos.txt are mapped, I guess?

( I instead went with ANSI escape sequences for the program I'm writing, since the conio.h APIs would still need slightly different code to cover both IBM and PC-98.)

joncampbell123 commented 6 years ago

I just fixed a silly bug in the ANSI emulation that might have caused this issue.

joncampbell123 commented 6 years ago

Just checked the COLORBUG.COM file, still happens.

joncampbell123 commented 5 years ago

The latest commit seems to be able to render COLORBUG.COM properly now.

nmlgc commented 4 months ago

Yup, this has been working for a while.