--- nono/vm/crtc.cpp 2026/04/29 17:05:24 1.1.1.11 +++ nono/vm/crtc.cpp 2026/04/29 17:05:59 1.1.1.16 @@ -14,37 +14,30 @@ // +$80..+$ff は何かが読める。 // 仕様は $e80480.w に1ポートあるので、これがワードで全域にミラーされている? // 全体としては この $800 バイトずつが繰り返して見える。 +// +// CRTC はデバイスの配置としては BusIO_B 相当で、バイトアクセスも行えるが、 +// 内部はバイトレジスタではなくワード単位を基本構造としている。そのため +// BusIO は使わず自力で処理する。ログの観点からもこのほうが都合がいい。 #include "crtc.h" +#include "event.h" #include "mfp.h" -#include "renderer.h" +#include "monitor.h" #include "scheduler.h" #include "tvram.h" +#include "videoctlr.h" // InsideOut p.135 -const busdata wait = busdata::Wait(9 * 40_nsec); +/*static*/ const busdata +CRTCDevice::wait = busdata::Wait(9 * 40_nsec); // コンストラクタ CRTCDevice::CRTCDevice() : inherited(OBJ_CRTC) { - hsync_event.func = ToEventCallback(&CRTCDevice::HSyncCallback); - hsync_event.Regist("CRTC H-Sync"); - vdisp_event.func = ToEventCallback(&CRTCDevice::VDispCallback); - vdisp_event.Regist("CRTC V-Disp"); - - // ラスターコピーは実際には CRTC の機能ではなく TVRAM (VRAM チップ) の - // 機能だが、イベントの時間管理が発生するのは CRTC 側なのでここで管理。 - // X68030 搭載の VRAM チップは HM514402A だが、ここでは X68000 XVI 搭載の - // HM53461 の値を使用し、これが最小 190nsec * 2 らしいので - // とりあえず 400nsec としておく。 - raster_event.func = ToEventCallback(&CRTCDevice::RasterCallback); - raster_event.time = 400_nsec; - raster_event.Regist("CRTC Raster Copy"); - - monitor.func = ToMonitorCallback(&CRTCDevice::MonitorUpdate); - monitor.SetSize(62, 14); - monitor.Regist(ID_MONITOR_CRTC); + monitor = gMonitorManager->Regist(ID_MONITOR_CRTC, this); + monitor->SetCallback(&CRTCDevice::MonitorScreen); + monitor->SetSize(79, 27); } // デストラクタ @@ -56,13 +49,27 @@ CRTCDevice::~CRTCDevice() bool CRTCDevice::Init() { - if (inherited::Init() == false) { - return false; - } - mfp = GetMFPDevice(); - renderer = GetRenderer(); tvram = GetTVRAMDevice(); + videoctlr = GetVideoCtlrDevice(); + + auto evman = GetEventManager(); + hsync_event = evman->Regist(this, + ToEventCallback(&CRTCDevice::HSyncCallback), + "CRTC H-Sync"); + vdisp_event = evman->Regist(this, + ToEventCallback(&CRTCDevice::VDispCallback), + "CRTC V-Disp"); + + // ラスターコピーは実際には CRTC の機能ではなく TVRAM (VRAM チップ) の + // 機能だが、イベントの時間管理が発生するのは CRTC 側なのでここで管理。 + // X68030 搭載の VRAM チップは HM514402A だが、ここでは X68000 XVI 搭載の + // HM53461 の値を使用し、これが最小 190nsec * 2 らしいので + // とりあえず 400nsec としておく。 + raster_event = evman->Regist(this, + ToEventCallback(&CRTCDevice::RasterCallback), + "CRTC Raster Copy"); + raster_event->time = 400_nsec; return true; } @@ -76,60 +83,55 @@ CRTCDevice::ResetHard(bool poweron) // XXX 適当 // すぐに水平同期と垂直帰線期間を開始する - hsync_event.time = 0; - hsync_event.code = 1; + hsync_state = 1; + hsync_event->time = 0; scheduler->RestartEvent(hsync_event); - vdisp_event.time = 0; - vdisp_event.code = 1; + vdisp_state = 1; + vdisp_event->time = 0; scheduler->RestartEvent(vdisp_event); } -busdata -CRTCDevice::Read8(uint32 addr) +/*static*/ inline uint32 +CRTCDevice::Decoder(uint32 addr) { - busdata data = Peek16(addr); - - if (__predict_false(loglevel >= 2)) { - uint32 offset = addr & 0xfff; - if (offset < 0x400) { - // CRTC レジスタは 0x40 バイトでミラー - uint32 regno = (offset & 0x3f) / 2; - // R20, R21 のみ読み出し可能だが、 - // R21 へのアクセスは多いのでログレベルを上げておく。 - if (regno == 21) { - putlog(3, "R%02d.%c -> $%02x", regno, - (((addr & 1) == 0) ? 'H' : 'L'), data.Data()); - } else if (regno < countof(crtc.r)) { - putlogn("R%02d.%c -> $%02x", regno, - (((addr & 1) == 0) ? 'H' : 'L'), data.Data()); - } else { - putlog(3, "$%06x -> $%02x", addr, data.Data()); - } - } - } - - data |= wait; - return data; + return addr & 0x7ff; } busdata -CRTCDevice::Read16(uint32 addr) +CRTCDevice::Read(busaddr addr) { - busdata data = Peek16(addr); + uint32 offset = Decoder(addr.Addr()); + busdata data = Peek2(offset); + + uint32 reqsize = addr.GetSize(); + if (reqsize == 1) { + if ((offset & 1) == 0) { + data >>= 8; + } else { + data &= 0xff; + } + data |= BusData::Size1; + } else { + data |= BusData::Size2; + } if (__predict_false(loglevel >= 2)) { - uint32 offset = addr & 0xfff; if (offset < 0x400) { // CRTC レジスタは 0x40 バイトでミラー - uint32 regno = (offset & 0x3f) / 2; - // R20, R21 のみ読み出し可能だが、 - // R21 へのアクセスは多いのでログレベルを上げておく - if (regno == 21) { - putlog(3, "R%02d -> $%04x", regno, data.Data()); - } else if (regno < countof(crtc.r)) { - putlog(2, "R%02d -> $%04x", regno, data.Data()); + uint32 regno = (offset >> 1) & 0x1f; + if (regno < countof(crtc.r)) { + // R20, R21 のみ読み出し可能だが、 + // R21 へのアクセスは多いのでログレベルを上げておく。 + int lv = (regno == 21) ? 3 : 2; + if (reqsize == 1) { + putlog(lv, "R%02u.%c -> $%02x", regno, + (((offset & 1) == 0) ? 'H' : 'L'), data.Data()); + } else { + putlog(lv, "R%02u -> $%04x", regno, data.Data()); + } } else { - putlog(3, "$%06x -> $%04x", addr, data.Data()); + putlog(3, "$%06x -> $%0*x", addr.Addr(), + reqsize * 2, data.Data()); } } } @@ -139,70 +141,61 @@ CRTCDevice::Read16(uint32 addr) } busdata -CRTCDevice::Write8(uint32 addr, uint32 data) +CRTCDevice::Write(busaddr addr, uint32 data) { busdata r; + uint32 offset = Decoder(addr.Addr()); + uint32 reqsize = addr.GetSize(); + uint32 datasize = std::min(2 - (offset & 1), reqsize); + data >>= (reqsize - datasize) * 8; - uint32 offset = addr & 0xfff; if (offset < 0x400) { // CRTC レジスタは 0x40 バイトでミラー - uint32 regno = (offset & 0x3f) / 2; + uint32 regno = (offset >> 1) & 0x1f; if (regno < countof(crtc.r)) { - uint32 tmp; - if ((addr & 1) == 0) { - tmp = (data << 8) | (crtc.r[regno] & 0xff); + if (datasize == 1) { + // バイト書き込み + if ((offset & 1) == 0) { + data = (data << 8) | (crtc.r[regno] & 0xff); + } else { + data = (crtc.r[regno] & 0xff00) | data; + } } else { - tmp = (crtc.r[regno] & 0xff00) | data; + // ワード書き込み } - SetReg(regno, tmp); + SetReg(regno, data); } else { // ここ何がいるんだ? - putlog(2, "$%06x <- $%02x", addr, data); + putlog(2, "$%06x <- $%0*x", addr.Addr(), datasize * 2, data); } } else { // 動作ポート if ((offset & 0x80) == 0) { // +$00..+$7f r.SetBusErr(); - } else { // +$80..+$ff - WriteOp(data); - } - } - - r |= wait; - return r; -} - -busdata -CRTCDevice::Write16(uint32 addr, uint32 data) -{ - busdata r; - - uint32 offset = addr & 0xfff; - if (offset < 0x400) { - // CRTC レジスタは 0x40 バイトでミラー - uint32 regno = (offset & 0x3f) / 2; - if (regno < countof(crtc.r)) { - SetReg(regno, data); } else { - // ここ何がいるんだ? - putlog(2, "$%06x <- $%04x", addr, data); - } - } else { // 動作ポート - if ((offset & 0x80) == 0) { // +$00..+$7f - r.SetBusErr(); - } else { // +$80..+$ff + if (datasize == 1) { + // バイト書き込み + if ((offset & 1) == 0) { + data = (data << 8) | crtc.op; + } else { + data = (crtc.op & 0xff00) | data; + } + } else { + // ワード書き込み + } WriteOp(data); } } r |= wait; + r |= busdata::Size(datasize); return r; } busdata -CRTCDevice::Peek8(uint32 addr) +CRTCDevice::Peek1(uint32 addr) { - busdata data = Peek16(addr); + busdata data = Peek2(addr); if (data.IsOK()) { if ((addr & 1) == 0) { return data.Data() >> 8; @@ -210,19 +203,19 @@ CRTCDevice::Peek8(uint32 addr) return data.Data() & 0xff; } } else { - return busdata::BusErr; + return BusData::BusErr; } } // addr のワードとしての読み出し値を返す。 -// これは内部用で Read*() からも呼ばれるので、 -// バスエラーなら busdata::BusErr を返す。 +// これは内部用で Read() からも呼ばれるので、 +// バスエラーなら BusData::BusErr を返す。 busdata -CRTCDevice::Peek16(uint32 addr) const +CRTCDevice::Peek2(uint32 addr) const { busdata data; - uint32 offset = addr & 0xfff; + uint32 offset = Decoder(addr); if (offset < 0x400) { // CRTC レジスタは 0x40 バイトでミラー uint32 regno = (offset & 0x3f) / 2; @@ -244,8 +237,32 @@ CRTCDevice::Peek16(uint32 addr) const return data; } +// 今の所、標準設定しかサポートしていないので、違う時だけログを出したりする。 +static const uint16 crtc_supported[] = { + 0x0089, // R00 + 0x000e, // R01 + 0x001c, // R02 + 0x007c, // R03 + 0x0237, // R04 + 0x0005, // R05 + 0x0028, // R06 + 0x0228, // R07 + 0, // R08 + 0, // R09 + 0, // R10 + 0, // R11 + 0x0000, // R12 + 0x0000, // R13 + 0x0000, // R14 + 0x0000, // R15 + 0x0000, // R16 + 0x0000, // R17 + 0x0000, // R18 + 0x0000, // R19 +}; + void -CRTCDevice::MonitorUpdate(Monitor *, TextScreen& screen) +CRTCDevice::MonitorScreen(Monitor *, TextScreen& screen) { int y; uint16 val; @@ -266,31 +283,47 @@ CRTCDevice::MonitorUpdate(Monitor *, Tex screen.Print(0, y++, "R10:$%04x (Text ScrollX)", crtc.r[10]); screen.Print(0, y++, "R11:$%04x (Text ScrollY)", crtc.r[11]); + screen.Print(0, y++, "R12:$%04x (Grp. Page0 X)", crtc.r[12]); + screen.Print(0, y++, "R13:$%04x (Grp. Page0 Y)", crtc.r[13]); + screen.Print(0, y++, "R14:$%04x (Grp. Page1 X)", crtc.r[14]); + screen.Print(0, y++, "R15:$%04x (Grp. Page1 Y)", crtc.r[15]); + screen.Print(0, y++, "R16:$%04x (Grp. Page2 X)", crtc.r[16]); + screen.Print(0, y++, "R17:$%04x (Grp. Page2 Y)", crtc.r[17]); + screen.Print(0, y++, "R18:$%04x (Grp. Page3 X)", crtc.r[18]); + screen.Print(0, y++, "R19:$%04x (Grp. Page3 Y)", crtc.r[19]); + + for (uint i = 0; i < countof(crtc_supported); i++) { + if (8 <= i && i < 12) { + continue; + } + if (crtc.r[i] != crtc_supported[i]) { + screen.Print(29, (i < 8 ? i : i - 2), TA::On, + "(not supported value)"); + } + } + + // 3 4 5 6 7 + // 90123456789012345678901234567890123456789012345678 + // SIZ=1024x1024 COL=65536 HF=31kHz VD=undef HD=50MHz val = crtc.r[20]; screen.Print(0, y, "R20:$%04x (Mode)", val); - screen.Print(29, y, TA::OnOff(val & CRTC::R20_MEM), "MEM"); - static const char * const r20col_str[] = { - "16", - "256", - "undef", - "65536", - }; - screen.Print(33, y, "COL=%s", r20col_str[(val >> 8) & 3]); - screen.Print(43, y, TA::OnOff(val & CRTC::R20_HF), "HF"); + screen.Print(29, y, "SIZ=%s", VideoCtlrDevice::siz_str[(val >> 10) & 1]); + screen.Print(43, y, "COL=%s", VideoCtlrDevice::col_str[(val >> 8) & 3]); + screen.Print(53, y, "HF=%ukHz", 15 + (val & 0x10)); static const char * const r20vd_str[] = { "256", "512", "1024", "undef", }; - screen.Print(46, y, "VD=%s", r20vd_str[(val >> 2) & 3]); + screen.Print(62, y, "VD=%s", r20vd_str[(val >> 2) & 3]); static const char * const r20hd_str[] = { "256", "512", "768", "50MHz", }; - screen.Print(55, y, "HD=%s", r20hd_str[val & 3]); + screen.Print(71, y, "HD=%s", r20hd_str[val & 3]); y++; val = crtc.r[21]; @@ -313,6 +346,11 @@ CRTCDevice::MonitorUpdate(Monitor *, Tex val, (val >> 8), (val & 0xff)); screen.Print(0, y++, "R23:$%04x (Text Access Mask)", crtc.r[23]); + + // ビデオコントローラもここに並べたほうが読みやすいか。 + y++; + screen.Puts(0, y++, "