--- nono/vm/msxdos.cpp 2026/04/29 17:05:29 1.1.1.4 +++ nono/vm/msxdos.cpp 2026/04/29 17:05:33 1.1.1.5 @@ -16,6 +16,7 @@ #include "memorystream.h" #include "mpu64180.h" #include "subram.h" +#include "xpbus.h" #include #include #include @@ -49,7 +50,9 @@ MSXDOSDevice::Init() return false; } + cursor_x = 0; xp = GetMPU64180Device(); + xpbus = GetXPbusDevice(); // システムコール処理のコールバックを設定 xp->SetSYSCALLCallback(msxdos_callback, this); @@ -87,9 +90,9 @@ MSXDOSDevice::Init() IODeviceStream xs(subram); const uint16 _doscall = 0x7000; const uint16 _term = 0x7010; - const uint16 _trap_handler = 0x7020; - const uint16 _rominit = 0x7030; - const uint16 _msg_trap = 0x7050; + const uint16 _rominit = 0x7020; + const uint16 _msg_trap = 0x7040; + const uint16 _trap_handler = 0x7060; // リセットベクタ xs.SetOffset(0x0000); @@ -99,6 +102,14 @@ MSXDOSDevice::Init() xs.Write1(0xc3); // 0005: JP _doscall xs.Write2LE(_doscall); + // RST エントリの初期化 + for (int i = 1; i < 8; i++) { + xs.SetOffset(i * 8); + xs.Write1(0x0e); // +00: LD C,`RST xxH` + xs.Write1(0xc7 | (i << 3)); + xs.Write2(0xedff); // +02: SYSCALL + } + // ここから ROM。 // CP/M は 0005H の飛び先がワークの先頭らしく、ここより前を // SP として使っているらしいので、先頭に DOSCALL ハンドラを用意。 @@ -119,15 +130,6 @@ MSXDOSDevice::Init() xs.Write1(0x76); // 7014: HALT xs.Write2(0x18fd); // 7015: JR 7014H ; 念のため - // トラップハンドラ。メッセージを出して終了。 - xs.SetOffset(_trap_handler); - xs.Write1(0x11); // 7020: LD DE,msg_trap - xs.Write2LE(_msg_trap); - xs.Write2(0x0e09); // 7023: LD C,09H - xs.Write2(0xedff); // 7025: SYSCALL - xs.Write1(0xc3); // 7026: JP _term - xs.Write2LE(_term); - // XP 側の初期化ルーチン。 // 0000H 番地をトラップハンドラに向け変えて、 // 0100H にジャンプ。戻ってきたら終了。 @@ -148,6 +150,27 @@ MSXDOSDevice::Init() xs.SetOffset(_msg_trap); xs.WriteString("trap occured!\x0d\x0a$"); + // トラップハンドラ。 + // XXX: とりあえず未定義命令をスキップしたい。 + // まだ LD IXH,n のようなオペランドを持つ命令をうまくスキップできない。 + xs.SetOffset(_trap_handler); + xs.Write1(0xe3); // +00: EX (SP),HL + xs.Write1(0xf5); // +01: PUSH AF + xs.Write1(0x23); // +02: INC HL + xs.Write3(0xed3834); // +03: IN0 A,(34H) + xs.Write1(0xf2); // +06: JP P,_term + xs.Write2LE(_term); + xs.Write2(0xcb77); // +09: BIT 6,A + xs.Write2(0x2802); // +0b: JR Z,@f + xs.Write1(0x23); // +0d: INC HL + xs.Write1(0x23); // +0e: INC HL + // @@: + xs.Write2(0xcbbf); // +0f: RES 7,A + xs.Write3(0xed3934); // +11: OUT0 (34H),A + xs.Write1(0xf1); // +14: POP AF + xs.Write1(0xe3); // +15: EX (SP),HL + xs.Write1(0xc9); // +16: RET + // 実行ファイルオープン std::vector src; if (LoadBinary(gMainApp.exec_file, src) == false) { @@ -240,18 +263,32 @@ msxdos_callback(void *arg) msxdosdev->Syscall(); } +// 1 文字表示 +void +MSXDOSDevice::Putc(int ch) +{ + putchar(ch); + cursor_x++; + if (ch == '\r' || ch == '\n') { + cursor_x = 0; + } +} + // DOS コールの処理 void MSXDOSDevice::Syscall() { switch (xp->reg.c) { case 0x00: // _TERM + if (cursor_x != 0) { + Putc('\n'); + } putmsg(1, "DOS _TERM"); Human68kDevice::RequestExit(0); break; case 0x02: // _PUTC - putchar(xp->reg.e); + Putc(xp->reg.e); fflush(stdout); break; @@ -259,15 +296,28 @@ MSXDOSDevice::Syscall() { uint16 de = xp->reg.GetDE(); uint8 ch; - for (; (ch = xp->Read1(de)) != '$'; de++) { - putchar(ch); + for (; (ch = xpbus->Read1(de)) != '$'; de++) { + Putc(ch); } fflush(stdout); break; } + case 0xc7: + case 0xcf: + case 0xd7: + case 0xdf: + case 0xe7: + case 0xef: + case 0xf7: + case 0xff: + putmsg(0, "RST %2Xh default handler, aborted.", (xp->reg.c & 0x38)); + Human68kDevice::RequestExit(0); + break; + default: - putmsg(0, "Syscall: unsupported DOSCALL C=%02XH", xp->reg.c); + putmsg(0, "Syscall: unsupported DOSCALL C=%02XH at $%04x", xp->reg.c, + xp->reg.pc); break; } }