diff --git a/CasioEmuMsvc/Chipset/Chipset.cpp b/CasioEmuMsvc/Chipset/Chipset.cpp index 84f380e..9a3dc58 100644 --- a/CasioEmuMsvc/Chipset/Chipset.cpp +++ b/CasioEmuMsvc/Chipset/Chipset.cpp @@ -507,13 +507,19 @@ namespace casioemu { if (flash_handle.fail()) PANIC("std::ifstream failed: %s\n", std::strerror(errno)); flash_data = std::vector((std::istreambuf_iterator(flash_handle)), std::istreambuf_iterator()); + flash_data.resize(0x80000,0xff); + memset(&flash_data[0x20000], 0xff, 0x10000); // TODO: check clear ram flag + memset(&flash_data[0x30000], 0, 0x8000); + memset(&flash_data[0x38000], 0xff, 0x8000); + flash_data[0x37FFE] = 0xff; + flash_data[0x37FFF] = 0x44; } { auto ri = rom_info(rom_data, flash_data); if (ri.ok) { - printf("[Chipset] Model: %s\n", ri.ver); - printf("[Chipset] CalcID: %llx\n", *(unsigned long long*)ri.cid); - printf("[Chipset] Target SUM: %02x ,Calculated SUM: %02x\n", ri.desired_sum, ri.real_sum); + printf("[Chipset][Info] Model: %s\n", ri.ver); + printf("[Chipset][Info] CalcID: %llx\n", *(unsigned long long*)ri.cid); + printf("[Chipset][Info] Target SUM: %02x ,Calculated SUM: %02x\n", ri.desired_sum, ri.real_sum); auto res = (ri.real_sum == ri.desired_sum); if (res != real_hardware) printf("[Chipset][Warn] SUM %s!\n", res ? "OK" : "NG"); diff --git a/CasioEmuMsvc/Chipset/MMU.cpp b/CasioEmuMsvc/Chipset/MMU.cpp index 9893518..7213597 100644 --- a/CasioEmuMsvc/Chipset/MMU.cpp +++ b/CasioEmuMsvc/Chipset/MMU.cpp @@ -199,7 +199,7 @@ namespace casioemu { MMURegion* region = byte.region; if (!region || !region->write) { #ifdef DBG - std::cout << std::hex << offset << "<-" << (int)data << std::oct << "\n"; + printf("[MMU][Warn] Unmapped write: %x <- %x\n", (uint32_t)offset, (uint32_t)data); #endif return; } diff --git a/CasioEmuMsvc/Gui/CodeViewer.cpp b/CasioEmuMsvc/Gui/CodeViewer.cpp index 2ca8965..c1938a9 100644 --- a/CasioEmuMsvc/Gui/CodeViewer.cpp +++ b/CasioEmuMsvc/Gui/CodeViewer.cpp @@ -62,7 +62,7 @@ void CodeViewer::SetupHooks() { void CodeViewer::PrepareDisasm() { std::thread t1([this]() { #ifndef _DEBUG - printf("Start to disasm ...\n"); + printf("[UI][Info] Start to disasm ...\n"); uint8_t* beg = (uint8_t*)m_emu->chipset.rom_data.data(); auto rom = beg; auto end = rom + m_emu->chipset.rom_data.size(); @@ -77,7 +77,7 @@ void CodeViewer::PrepareDisasm() { codes.push_back(ce); ss.str(""); } - printf("Finished!\n"); + printf("[UI][Info] Finished!\n"); max_row = codes.size(); #endif is_loaded = true; diff --git a/CasioEmuMsvc/Peripheral/5800Flash.cpp b/CasioEmuMsvc/Peripheral/5800Flash.cpp index 158f4cb..1c13625 100644 --- a/CasioEmuMsvc/Peripheral/5800Flash.cpp +++ b/CasioEmuMsvc/Peripheral/5800Flash.cpp @@ -48,7 +48,7 @@ namespace casioemu { } break; case 3: - printf("Program %x to %x\n", (int)fo, data); + // printf("Program %x to %x\n", (int)fo, data); flash->emulator.chipset.flash_data[fo] = data; flash->flash_mode = 0; return; @@ -69,7 +69,7 @@ namespace casioemu { memset(&flash->emulator.chipset.flash_data[fo], 0xff, 0x7fff); if (fo == 0x20000 || fo == 0x30000) memset(&flash->emulator.chipset.flash_data[fo], 0xff, 0xffff); - printf("Erase %x (%x)\n", (int)fo, data); + // printf("Erase %x (%x)\n", (int)fo, data); return; case 7: if (fo == 0xaaa && data == 0xaa) { @@ -91,7 +91,7 @@ namespace casioemu { // printf("Erase Suspend.\n"); // return; //} - printf("Unknown jedec %05x = %02x\n", (int)fo, data); + printf("[Flash][Warn] Unknown jedec %05x = %02x\n", (int)fo, data); }, emulator); } diff --git a/CasioEmuMsvc/Peripheral/Keyboard.cpp b/CasioEmuMsvc/Peripheral/Keyboard.cpp index 43ae51b..975ecef 100644 --- a/CasioEmuMsvc/Peripheral/Keyboard.cpp +++ b/CasioEmuMsvc/Peripheral/Keyboard.cpp @@ -232,7 +232,7 @@ namespace casioemu { SDL_Keycode button_key; button_key = SDL_GetKeyFromName(button_name); if (button_key == SDLK_UNKNOWN) - printf("[Keyboard] Warn: Key %x is being bind to a invalid or empty key '%s'\n", btn.kiko, button_name); + printf("[Keyboard][Warn] Key %x is being bind to a invalid or empty key '%s'\n", btn.kiko, button_name); uint8_t code = btn.kiko; size_t button_ix; @@ -253,7 +253,7 @@ namespace casioemu { if (button_key != SDLK_UNKNOWN) { bool insert_success = keyboard_map.emplace(button_key, button_ix).second; if (!insert_success) - printf("[Keyboard] Warn: Key '%s' is used twice for key %x\n", button_name, btn.kiko); + printf("[Keyboard][Warn] Key '%s' is used twice for key %x\n", button_name, btn.kiko); } std::string bn2; if (btn.keyname.starts_with("Keypad ")) { @@ -412,7 +412,7 @@ namespace casioemu { case SDL_KEYUP: SDL_Keycode keycode = event.key.keysym.sym; auto iterator = keyboard_map.find(keycode); - printf("Key: %x(%s)\n", keycode, SDL_GetKeyName(keycode)); + printf("[Keyboard][Info] SDL_Keycode: %x(%s)\n", keycode, SDL_GetKeyName(keycode)); if (event.key.keysym.sym == SDLK_F11 && event.key.state) { if (event.key.keysym.mod & KMOD_LCTRL) { emulator.chipset.Reset(); @@ -451,19 +451,19 @@ namespace casioemu { if (!(emulator.hardware_id == HW_CLASSWIZ && (emulator.chipset.data_FCON & 0x03) == 0x03)) emulator.chipset.Reset(); else { - printf("RESETB is BLOCKED.Press Ctrl+F11 to reset.\n"); + printf("[Keyboard][Info] RESETB is BLOCKED.Press Ctrl+F11 to reset.\n"); } } if (button.type == Button::BT_BUTTON) { if (emulator.hardware_id == HW_TI) { // emulator.chipset.MaskableInterrupts[EXI0INT].TryRaise(); - printf("Keycode: 0x%x\n", button.code); + printf("[Keyboard][Info] Keycode: 0x%x\n", button.code); // if (!emulator.chipset.GetRunningState() && button.code == 0x29) { // emulator.chipset.Reset(); // } emulator.chipset.tiKey = button.code; } - printf("ki: %d,ko: %d\n", (int)(log(button.ki_bit) / log(2)), (int)(log(button.ko_bit) / log(2))); + printf("[Keyboard][Info] KI: %d, KO: %d\n", (int)(log(button.ki_bit) / log(2)), (int)(log(button.ko_bit) / log(2))); } if (button.type == Button::BT_BUTTON) { @@ -510,7 +510,7 @@ namespace casioemu { PressButton(buttons[button_index], false); } else { - logger::Info("Invalid button code 0x%02X!\n", code); + printf("[Keyboard][Info] Invalid button code 0x%02X!\n", code); } } } diff --git a/CasioEmuMsvc/Peripheral/ML620Ports.cpp b/CasioEmuMsvc/Peripheral/ML620Ports.cpp index 2087e66..bcc509b 100644 --- a/CasioEmuMsvc/Peripheral/ML620Ports.cpp +++ b/CasioEmuMsvc/Peripheral/ML620Ports.cpp @@ -119,10 +119,14 @@ namespace casioemu { } // 启用 IS reg_ie.Setup( - pbase++, 1, "PortN/Enable", this, MMURegion::IgnoreRead<0>, + pbase++, 1, "PortN/Enable", this, + [](MMURegion* reg, size_t off) -> uint8_t { + auto p = (ML620Port*)reg->userdata; + return p->dat_ie; + }, [](MMURegion* reg, size_t off, uint8_t dat) { auto p = (ML620Port*)reg->userdata; - p->dat_is |= dat; + p->dat_ie |= dat; p->UpdateStatus(); }, emulator); @@ -286,8 +290,10 @@ namespace casioemu { }; void ML620Port::UpdateInterrupt(int pi_tmp) { if (pt.PortExiSelect(ind)) { - auto it = (pi_tmp & (pi_tmp ^ PortInputOld) & TriggerWhenRise) | (PortInputOld & (pi_tmp ^ PortInputOld) & TriggerWhenFall); + auto it = ((pi_tmp & (pi_tmp ^ PortInputOld) & TriggerWhenRise) | (PortInputOld & (pi_tmp ^ PortInputOld) & TriggerWhenFall)) && dat_ie; if (it) { + dat_is |= it; + dat_ie &= ~it; pt.PortTriggerInterrupt(ind); } } diff --git a/CasioEmuMsvc/Peripheral/Screen.cpp b/CasioEmuMsvc/Peripheral/Screen.cpp index e3c8af9..03112b8 100644 --- a/CasioEmuMsvc/Peripheral/Screen.cpp +++ b/CasioEmuMsvc/Peripheral/Screen.cpp @@ -626,55 +626,54 @@ namespace casioemu { ti_col = (ti_col & 0xf) | ((data & 0xf) << 4); } else if ((dh & 0b1100) == 0b0100) { - std::cout << "Set Scroll line " << (data & 0x3f) << "\n"; + // std::cout << "Set Scroll line " << (data & 0x3f) << "\n"; } else if (dh == 0b1011) { // std::cout << "Set page " << (data & 0xf) << "\n"; ti_page = (data & 0xf); } else if ((data >> 3) == 17) { - std::cout << "Set addressing mode\n"; + // std::cout << "Set addressing mode\n"; } else if ((data >> 2) == 58) { - std::cout << "Set bias\n"; + // std::cout << "Set bias\n"; } else if ((data >> 2) == 40) { - std::cout << "Set frame rate\n"; + // std::cout << "Set frame rate\n"; } else if ((data >> 1) == 82) { - std::cout << "Set all display segments\n"; + // std::cout << "Clear all display segments\n"; } else if ((data >> 1) == 83) { - std::cout << "Set inverse display\n"; + // std::cout << "Set inverse display\n"; } else if ((data & 0xf9) == 0xc0) { - std::cout << "Set Com Seg Scan Direction\n"; + // std::cout << "Set Com Seg Scan Direction\n"; } else if (data == 0xe3) { - std::cout << "Nop\n"; + // std::cout << "Nop\n"; } else if (data == 0xe2) { - std::cout << "Software reset\n"; + // std::cout << "Software reset\n"; } else if (data == 0xaf) { - std::cout << "Enabled screen!\n"; + // std::cout << "Enabled screen!\n"; ti_enabled = 1; } else if (data == 0x81) { ti_port_status = 1; } else if (data == 0xae) { - std::cout << "Disabled screen!\n"; + // std::cout << "Disabled screen!\n"; ti_enabled = 0; } else { - std::cout << "Unknown " << std ::hex << (int)data << "\n" - << std::dec; + std::cout << "[Screen][Warn] Unknown ST7525 command: 0x" << std::hex << (int)data << "\n"; } break; } case 1: - std::cout << "Set contrast!\n"; + // std::cout << "Set contrast!\n"; ti_contrast = data; ti_port_status = 0; break; diff --git a/CasioEmuMsvc/Peripheral/TimerBaseCounter.cpp b/CasioEmuMsvc/Peripheral/TimerBaseCounter.cpp index 87ce4de..36fcffa 100644 --- a/CasioEmuMsvc/Peripheral/TimerBaseCounter.cpp +++ b/CasioEmuMsvc/Peripheral/TimerBaseCounter.cpp @@ -150,9 +150,9 @@ namespace casioemu { emulator.chipset.LSCLK_output = 0xFF; LTBR_reset_tick = true; - // emulator.chipset.MaskableInterrupts[LTB0INT].TryRaise(); - // emulator.chipset.MaskableInterrupts[LTB1INT].TryRaise(); - // emulator.chipset.MaskableInterrupts[LTB2INT].TryRaise(); + emulator.chipset.MaskableInterrupts[LTB0INT].TryRaise(); + emulator.chipset.MaskableInterrupts[LTB1INT].TryRaise(); + emulator.chipset.MaskableInterrupts[LTB2INT].TryRaise(); } }; Peripheral* CreateTimerBaseCounter(Emulator& emu) { diff --git a/CasioEmuMsvc/StartupUi/StartupUi.cpp b/CasioEmuMsvc/StartupUi/StartupUi.cpp index 1a5a336..6595e74 100644 --- a/CasioEmuMsvc/StartupUi/StartupUi.cpp +++ b/CasioEmuMsvc/StartupUi/StartupUi.cpp @@ -383,12 +383,19 @@ namespace casioemu { std::ifstream ifs2{"roms.db", std::ifstream::binary}; if (ifs2) Binary::Read(ifs2, RomNames); + else { + printf("[StartupUI][Warn] \"rom.db\" not found. Names may be inaccurate!\n"); + } + std::filesystem::create_directory("models"); for (auto& dir : std::filesystem::directory_iterator("models")) { if (dir.is_directory()) { + printf("[StartupUI][Info] Checking %s\n", dir.path().string().c_str()); auto config = dir.path() / "config.bin"; std::ifstream ifs(config, std::ios::in | std::ios::binary); - if (!ifs) + if (!ifs) { + printf("[StartupUI][Info] Unable to open %s\n", config.string().c_str()); continue; + } ModelInfo mi{}; Binary::Read(ifs, mi); ifs.close(); @@ -472,6 +479,9 @@ namespace casioemu { else { mod.show_sum = false; } + printf("[StartupUI][Debug] Model Summary\n" + "[StartupUI][Debug] Name: %s\n" + "[StartupUI][Debug] Type: %s\n",mod.name.c_str(),mod.type.c_str()); } models.push_back(mod); } diff --git a/CasioEmuMsvc/casioemu.cpp b/CasioEmuMsvc/casioemu.cpp index 36d7343..d300978 100644 --- a/CasioEmuMsvc/casioemu.cpp +++ b/CasioEmuMsvc/casioemu.cpp @@ -39,6 +39,8 @@ using namespace casioemu; int main(int argc, char* argv[]) { #ifdef _WIN32 timeBeginPeriod(1); + SetConsoleCP(65001); // Set to UTF8 + SetConsoleOutputCP(65001); #endif // _WIN32 std::map argv_map; @@ -57,7 +59,7 @@ int main(int argc, char* argv[]) { if (argv_map.find(key) == argv_map.end()) argv_map[key] = value; else - logger::Info("[argv] #%i: key '%s' already set\n", ix, key.c_str()); + logger::Info("[argv][Info] #%i: key '%s' already set\n", ix, key.c_str()); } bool headless = argv_map.find("headless") != argv_map.end();