Skip to content

Commit

Permalink
Fixed Interrupt Status and Interrupt Enable logic in GPIO
Browse files Browse the repository at this point in the history
  • Loading branch information
telecomadm1145 committed Aug 20, 2024
1 parent 7b4a274 commit 7059dd3
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 38 deletions.
12 changes: 9 additions & 3 deletions CasioEmuMsvc/Chipset/Chipset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,13 +507,19 @@ namespace casioemu {
if (flash_handle.fail())
PANIC("std::ifstream failed: %s\n", std::strerror(errno));
flash_data = std::vector<unsigned char>((std::istreambuf_iterator<char>(flash_handle)), std::istreambuf_iterator<char>());
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");
Expand Down
2 changes: 1 addition & 1 deletion CasioEmuMsvc/Chipset/MMU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions CasioEmuMsvc/Gui/CodeViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions CasioEmuMsvc/Peripheral/5800Flash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -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);
}
Expand Down
14 changes: 7 additions & 7 deletions CasioEmuMsvc/Peripheral/Keyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 ")) {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
}
}
Expand Down
12 changes: 9 additions & 3 deletions CasioEmuMsvc/Peripheral/ML620Ports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}
Expand Down
27 changes: 13 additions & 14 deletions CasioEmuMsvc/Peripheral/Screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions CasioEmuMsvc/Peripheral/TimerBaseCounter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
12 changes: 11 additions & 1 deletion CasioEmuMsvc/StartupUi/StartupUi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 3 additions & 1 deletion CasioEmuMsvc/casioemu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string, std::string> argv_map;
Expand All @@ -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();

Expand Down

0 comments on commit 7059dd3

Please sign in to comment.