--- nono/vm/videoctlr.cpp 2026/04/29 17:04:36 1.1 +++ nono/vm/videoctlr.cpp 2026/04/29 17:04:42 1.1.1.3 @@ -5,6 +5,7 @@ // #include "videoctlr.h" +#include "mpu.h" // e82000..e823ff パレット // e82400..e824ff R0(e82400.w) のミラー @@ -27,6 +28,12 @@ VideoCtlrDevice::~VideoCtlrDevice() { } +void +VideoCtlrDevice::ResetHard() +{ + // XXX not yet +} + // addr は何ワード目のポートかという意味になるので // $E82002 が addr=1 (番目のワード)。 uint64 @@ -34,6 +41,8 @@ VideoCtlrDevice::Read(uint32 addr) { uint32 data; + gMPU->AddCycle(9); // InsideOut p.135 + if (addr < 0x400 / 2) { // パレット data = palette.w[addr]; @@ -56,9 +65,12 @@ VideoCtlrDevice::Read(uint32 addr) uint64 VideoCtlrDevice::Write(uint32 addr, uint32 data) { + gMPU->AddCycle(11); // InsideOut p.135 + if (addr < 0x400 / 2) { // パレット putlog(3, "パレット $%06x.W <- $%04x", baseaddr + addr * 2, data); palette.w[addr] = data; + MakePalette(); } else if (addr < 0x500 / 2) { // $E82400 (R0) SetR0(data); @@ -122,3 +134,24 @@ VideoCtlrDevice::SetR2(uint32 data) putlog(0, "R2 <- $%04x 未実装書き込み", data); videoctlr.r2 = (data & 0xff7f); } + +// +void +VideoCtlrDevice::MakePalette() +{ + const uint16 *p; + + // パレット前半 256 ワードはグラフィックパレット、 + // テキストパレットは後半。 + p = &palette.w[256]; + + // パレット情報から xBGR32 形式の色データを作成 + // X680x0 のパレットは %GGGGG'RRRRR'BBBBB'I で並んでいる。 + for (int i = 0; i < 16; i++) { + int I = (p[i] & 1) << 2; // 輝度ビット + int R = (((p[i] >> 6) & 0x1f) << 3) + I; + int G = (((p[i] >> 11)) << 3) + I; + int B = (((p[i] >> 1) & 0x1f) << 3) + I; + cooked_palette[i] = R | (G << 8) | (B << 16); + } +}