--- nono/vm/bitmap.cpp 2026/04/29 17:04:31 1.1.1.3 +++ nono/vm/bitmap.cpp 2026/04/29 17:04:52 1.1.1.6 @@ -1,11 +1,13 @@ // // nono -// Copyright (C) 2018 isaki@NetBSD.org +// Copyright (C) 2020 nono project +// Licensed under nono-license.txt // #include "bitmap.h" #include "bt454.h" #include "cgrom.h" +#include "mpu.h" // // ビットマッププレーン @@ -48,16 +50,30 @@ BitmapDevice::BitmapDevice() logname = "bitmap"; devname = "Bitmap"; devaddr = 0xb1000000; - monitor.Init(42, 11); + monitor_size = nnSize(42, 11); +} + +BitmapDevice::~BitmapDevice() +{ +} +bool +BitmapDevice::Init() +{ // XXX とりあえず。実際は設定による nplane = 1; // プレーン数によってメモリを確保 mem.reset(new uint8 [0x40000 * nplane]); + + return true; } -BitmapDevice::~BitmapDevice() +bool +BitmapDevice::PowerOn() { + // XXX 実際は不定値だと思うけど、観測手段がないのでとりあえず。 + memset(&mem[0], 0xff, 0x40000 * nplane); + return true; } void @@ -66,7 +82,10 @@ BitmapDevice::ResetHard() // 厳密にどの時点でリセットされるのかは知らないけど bmsel = 0; - // RFCNT の初期値は観測困難なので、とりあえず無視。 + // XXX 初期値の観測は困難なので適当 + rfcnt = 0; + hscroll = 0; + vscroll = 0; for (int i = 0; i < MAX_PLANES; i++) { fcs[i] = 5; @@ -80,6 +99,9 @@ BitmapDevice::ResetHard() uint64 BitmapDevice::Read8(uint32 addr) { + // XXX とりあえず RAM と同じウェイトを入れておく (未調査) + gMPU->AddCycle(1); + if (addr < plane0base) { // 書き込み専用 return 0xff; @@ -95,6 +117,9 @@ BitmapDevice::Read8(uint32 addr) uint64 BitmapDevice::Read16(uint32 addr) { + // XXX とりあえず RAM と同じウェイトを入れておく (未調査) + gMPU->AddCycle(1); + if (addr < plane0base) { // 書き込み専用 return 0xffff; @@ -110,6 +135,9 @@ BitmapDevice::Read16(uint32 addr) uint64 BitmapDevice::Read32(uint32 addr) { + // XXX とりあえず RAM と同じウェイトを入れておく (未調査) + gMPU->AddCycle(1); + if (addr < plane0base) { // 書き込み専用 return 0xffffffff; @@ -125,6 +153,9 @@ BitmapDevice::Read32(uint32 addr) uint64 BitmapDevice::Write8(uint32 addr, uint32 data) { + // XXX とりあえず RAM と同じウェイトを入れておく (未調査) + gMPU->AddCycle(1); + switch (addr) { case 0xb1000000: case 0xb1000001: @@ -177,6 +208,9 @@ BitmapDevice::Write8(uint32 addr, uint32 uint64 BitmapDevice::Write16(uint32 addr, uint32 data) { + // XXX とりあえず RAM と同じウェイトを入れておく (未調査) + gMPU->AddCycle(1); + switch (addr) { case 0xb1000000: case 0xb1000002: @@ -225,6 +259,9 @@ BitmapDevice::Write16(uint32 addr, uint3 uint64 BitmapDevice::Write32(uint32 addr, uint32 data) { + // XXX とりあえず RAM と同じウェイトを入れておく (未調査) + gMPU->AddCycle(1); + switch (addr) { case 0xb1000000: // RFCNT @@ -318,8 +355,8 @@ BitmapDevice::Peek8(uint32 addr) return 0xff; } -bool -BitmapDevice::MonitorUpdate() +void +BitmapDevice::MonitorUpdate(TextScreen& monitor) { int i; @@ -349,8 +386,8 @@ BitmapDevice::MonitorUpdate() // 012345 // $0:RGB const uint8 *pal = gBT454->reg.color; - monitor.Print(29, 1, ""); - monitor.Print(32, 2, "RGB RGB"); + monitor.Puts(29, 1, ""); + monitor.Puts(32, 2, "RGB RGB"); for (i = 0; i < 16; i++) { uint rgb = ((pal[i * 3 + 0] & 0xf0) << 4) + @@ -358,8 +395,6 @@ BitmapDevice::MonitorUpdate() ((pal[i * 3 + 2] & 0xf0) >> 4); monitor.Print(29 + (i / 8) * 7, (i % 8) + 3, "$%x:%03x", i, rgb); } - - return true; } // 全画面の更新フラグを立てる @@ -586,7 +621,7 @@ BitmapDevice::EmuConsoleOpen(TextScreen screen_w = textscr->GetCol(); screen_h = textscr->GetRow(); - prev.reset(new uint16[screen_w * screen_h]); + prev.resize(screen_w * screen_h); for (int i = 0; i < screen_w * screen_h; i++) { prev[i] = 0x0020; } @@ -619,7 +654,7 @@ BitmapDevice::EmuConsoleClose() bmsel = 0; textscr = NULL; - prev.reset(); + prev.clear(); } // エミュレータによる出力 @@ -627,7 +662,7 @@ BitmapDevice::EmuConsoleClose() void BitmapDevice::EmuConsoleUpdate() { - const uint16 *text = textscr->GetBuf(); + auto& text = textscr->GetBuf(); // 12ドットフォントなので2文字ずつ (24ビットずつ) 更新する for (int y = 0; y < screen_h; y++) { @@ -646,8 +681,8 @@ BitmapDevice::EmuConsoleUpdate() uint32 ch0 = text[y * screen_w + x]; uint32 ch1 = text[y * screen_w + x + 1]; // その文字のフォントデータ上でのオフセット - uint32 fo0 = 0x3d000 + (ch0 & 0xff) * 48; - uint32 fo1 = 0x3d000 + (ch1 & 0xff) * 48; + const uint8 * const fo0 = BuiltinCGROM::Get12x24(ch0 & 0xff); + const uint8 * const fo1 = BuiltinCGROM::Get12x24(ch1 & 0xff); // 1,2文字目なら true、3,4文字目なら false bool evenpair = ((x & 2) == 0); @@ -659,8 +694,8 @@ BitmapDevice::EmuConsoleUpdate() for (int i = 0; i < 24; i++) { // その文字のフォントデータ - uint32 fdat0 = be16toh(*(uint16*)(&builtin_cgrom[fo0 + i * 2])); - uint32 fdat1 = be16toh(*(uint16*)(&builtin_cgrom[fo1 + i * 2])); + uint32 fdat0 = be16toh(*(const uint16*)(fo0 + i * 2)); + uint32 fdat1 = be16toh(*(const uint16*)(fo1 + i * 2)); // 属性はとりあえず反転のみサポート if ((ch0 & TA::On)) {