Skip to content

Instantly share code, notes, and snippets.

@lpproj
Last active March 27, 2023 12:03
Show Gist options
  • Save lpproj/d4220ba47d01998e4d011bdb7bf076b7 to your computer and use it in GitHub Desktop.
Save lpproj/d4220ba47d01998e4d011bdb7bf076b7 to your computer and use it in GitHub Desktop.
CWSDPMI r7のPC-98対応状況をすこし改善するパッチ
#
*.zip binary
a small patch against cwsdpmi 0.90+ (r7)
mainly for NEC PC-98:
* fix to mis-detect hi-res version of PC-98
* enable some interrupt handler on PC-98 (int 18h, 1Dh, 1Eh and 1Fh)
* allow drive letter '@' for swapfile (drive "@:" is placed as boot drive)
* do not call int 15h, ax=E820h on PC-98
* (CWSPARAM) clear unused space in the field of parameter block
original source:
http://www.delorie.com/pub/djgpp/current/v2misc/csdpmi7s.zip
note (in Japanese, UTF-8):
djgpp標準DPMIサーバであるCWSDPMIのPC-98シリーズ向け修正です。
CWSDPMIはそのままでもノーマルモードのPC-98に対応していますが、標準状態のスワップファイル設定があまりPC-98の環境に優しくないこともあり、若干の追加修正を行いました。
* ハイレゾモードも正しくPC-98と認識するはず
* スワップファイルのドライブ文字として '@' を認識するようにした。@を指定するとMS-DOS起動ドライブとみなされる(DOS4以上。DOS3.xの場合はカレントドライブ)。スワップファイルの標準設定は @:\cwsdpmi.swp となっている。変更する場合は付属のCWSPARAMを使ってCWSDPMIのバイナリを書き換える必要がある
* IBM PC用のメモリ検出BIOSをPC-98では呼び出さないようにした。なお、PC-98で16Mシステム空間を有効にしている場合、XMS3.0ドライバを導入していない状態では(メモリ搭載量にかかわらず)CWSDPMIは16M超のメモリ領域を認識しない
diff --git a/src/control.c b/src/control.c
--- a/src/control.c
+++ b/src/control.c
@@ -58,7 +58,7 @@ word8 use_xms=0;
word16 simstacku;
#endif
-CWSDPMI_pblk CWSpar = { "CWSPBLK", "c:\\cwsdpmi.swp", 0, 0, 128, 3840, 32768UL };
+CWSDPMI_pblk CWSpar = { "CWSPBLK", "@:\\cwsdpmi.swp", 0, 0, 128, 3840, 32768UL };
static char *exception_names[] = {
"Division by Zero",
@@ -269,7 +269,11 @@ void main1(void) /* int argc, char **argv) */
if(CWSFLAG_NOUMB)
_osmajor = 4; /* Don't try to use UMB */
- if(*(word16 far *)MK_FP(0xf000, 0xfff3) == 0xfd80) {
+ _AX = 0x0f00;
+ _BH = 0xff;
+ geninterrupt(0x10);
+ if(_AH == 0x0f && _BH == 0xff) {
+ /* not IBMPC at least (guess PC-98 normal or Hi-res) */
hard_slave_lo = 0x10; /* PC98 slave */
mtype = PC98;
}
@@ -292,6 +296,7 @@ void main1(void) /* int argc, char **argv) */
if(ptr[i] == '-') {
char test = 0x20 | ptr[++i]; /* make lower case if upper */
errmsg("CWSDPMI V0.90+ (r7) Copyright (C) 2010 CW Sandmann ABSOLUTELY NO WARRANTY\n");
+ errmsg("(Patched for NEC PC-98, built on " __DATE__ ")\n");
if(test == 'p') /* persistent, permanent */
one_pass = 0;
else if(test == 'x') /* no eXtensions */
diff --git a/src/cwsparm.c b/src/cwsparm.c
--- a/src/cwsparm.c
+++ b/src/cwsparm.c
@@ -87,6 +87,8 @@ void str_v2s(void *addr, char *buf, int len)
void str_s2v(void *addr, char *buf, int len)
{
+ if (len > 0)
+ memset(addr, 0, len);
if (strcmp(buf, "\"\"") == 0)
*(char *)addr = 0;
else
diff --git a/src/dalloc.c b/src/dalloc.c
--- a/src/dalloc.c
+++ b/src/dalloc.c
@@ -53,6 +53,16 @@ static char* dfilename;
void dalloc_file(char *swapname)
{
dfilename = swapname;
+ if(dfilename && dfilename[0] == '@' && dfilename[1] == ':') {
+ /* workaround for NEC PC-98 series */
+ /* '@:' as boot drive (current drive on DOS 3.x) */
+ _AH = 0x19;
+ geninterrupt(0x21);
+ _DL = _AL + 1;
+ _AX = 0x3305;
+ geninterrupt(0x21);
+ dfilename[0] = 'A'- 1 + _DL;
+ }
}
void dalloc_init(void)
diff --git a/src/exphdlr.c b/src/exphdlr.c
--- a/src/exphdlr.c
+++ b/src/exphdlr.c
@@ -115,6 +115,8 @@ static char far * oldvec;
static int i_21(void), i_2f(void), i_31(void);
+static void init_exception_handler_extra(void);
+
#if 0
void segfault(word32 v)
{
@@ -174,6 +176,7 @@ void init_controllers(void)
for(i=0; i < n_user_hwint; i++)
user_interrupt_handler[i].selector = 0;
}
+ init_exception_handler_extra();
locked_count = 0;
in_rmcb = 0;
@@ -378,6 +381,18 @@ static FUNC exception_handler_list[] = {
/* 2f */ i_2f, U, /* Multiplex for PM execution */
/* 31 */ i_31 /* DPMIsim */
};
+
+static void init_exception_handler_extra(void)
+{
+ if (mtype == PC98) {
+ /* todo: look around FPE implementations on PC-98/FMR enviromnent */
+ /* exception_handler_list[0x10] = UE; */
+ exception_handler_list[0x18] = generic_handler; /* keybord, CRT */
+ exception_handler_list[0x1d] = generic_handler; /* graphic (Hi-res) */
+ exception_handler_list[0x1e] = generic_handler; /* ROM BASIC */
+ exception_handler_list[0x1f] = generic_handler; /* power management, PCMCIA, etc. */
+ }
+}
#undef U
#undef UE
#define NUM_EXCEPTIONS (sizeof(exception_handler_list)/sizeof(exception_handler_list[0]))
diff --git a/src/valloc.c b/src/valloc.c
--- a/src/valloc.c
+++ b/src/valloc.c
@@ -261,7 +261,7 @@ void valloc_init(word16 ies)
unsigned u4mstart, u4mcount, i;
memset(map4m,0,sizeof(map4m));
- if(uextmem(&u4mstart, &u4mcount) ) {
+ if(mtype != PC98 && uextmem(&u4mstart, &u4mcount) ) {
for(i=pn_4m_last+1;i<u4mstart;i++)
vset4m(i, 1); /* Flag non-memory as used in bitmap */
pn_4m_last = u4mstart + u4mcount - 1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment