From 2f72e7951f4ac603556f84bd6b4bbe1cfe30a166 Mon Sep 17 00:00:00 2001 From: "Sunip K. Mukherjee" Date: Thu, 18 Feb 2021 04:44:15 -0500 Subject: [PATCH] Testing CPU --- main.cpp | 52 +++++++++++++++++++++++++++++++--- mos6502 | 2 +- test/6502_functional_test.bin | Bin 0 -> 65536 bytes 3 files changed, 49 insertions(+), 5 deletions(-) create mode 100644 test/6502_functional_test.bin diff --git a/main.cpp b/main.cpp index dcba365..a14e362 100644 --- a/main.cpp +++ b/main.cpp @@ -366,6 +366,43 @@ void CPURun() cpu_stepping = true; cpu_running = true; } + ImGui::SameLine(); + if (ImGui::Button("Load Test")) + { + cpu_stepping = true; + cpu_running = false; + FILE *fp = fopen("test/6502_functional_test.bin", "rb"); + if (fp != NULL) + { + // calculate size + fseek(fp, 0, SEEK_END); + ssize_t sz = ftell(fp); + fseek(fp, 0, SEEK_SET); + + if (sz != 0x10000) + { + printf("Binary file size: %ld bytes, which is not equal to %d bytes\n", sz, 0x10000); + } + else + { + ssize_t rdsz = fread(cpu->mem, 1, sz, fp); + if (rdsz == sz) + { + printf("Binary ROM read OK, setting RESET vector to 0x400\n"); + RESET_VEC = 0x400; + NMI_VEC = cpu->mem[V_NMI]; + NMI_VEC |= ((word)cpu->mem[V_NMI + 1]) << 8; + IRQ_VEC = cpu->mem[V_IRQ_BRK]; + IRQ_VEC |= ((word)cpu->mem[V_IRQ_BRK + 1]) << 8; + } + else + { + printf("Binary ROM read FAILED, read %ld bytes out of %ld bytes\n", rdsz, sz); + } + } + fclose(fp); + } + } ImGui::Separator(); ImGui::Columns(2, "vector_inputs", false); ImGui::Text("Reset Vector: "); @@ -380,6 +417,8 @@ void CPURun() if (num == 0) num = 0x400; RESET_VEC = num; + cpu->mem[V_RESET] = RESET_VEC; + cpu->mem[V_RESET + 1] = RESET_VEC >> 8; } ImGui::PopStyleColor(); ImGui::NextColumn(); @@ -395,6 +434,8 @@ void CPURun() if (num == 0) num = 0x200; NMI_VEC = num; + cpu->mem[V_NMI] = NMI_VEC; + cpu->mem[V_NMI + 1] = NMI_VEC >> 8; } ImGui::PopStyleColor(); ImGui::NextColumn(); @@ -409,7 +450,9 @@ void CPURun() num = 0x300; // 1 second if (num == 0) num = 0x300; - NMI_VEC = num; + IRQ_VEC = num; + cpu->mem[V_IRQ_BRK] = IRQ_VEC; + cpu->mem[V_IRQ_BRK + 1] = IRQ_VEC >> 8; } ImGui::PopStyleColor(); ImGui::Columns(1); @@ -602,8 +645,8 @@ void CodeEditor(bool *active) } for (int j = -1; j < rc[1]; j++) { - word pcaddr = cpu_running ? cpu->pc : 0x0; - word instraddr = cpu_running ? cpu->instr_ptr : 0x0; + word pcaddr = cpu->pc; // : 0x0; + word instraddr = cpu->instr_ptr; // : 0x0; if (j < 0) // address { if (i == 0) // selectable base address @@ -683,7 +726,8 @@ void CodeEditor(bool *active) } else { - ImGui::SelectableInput(label, false, ImGuiSelectableFlags_Disabled, tmp, IM_ARRAYSIZE(tmp)); + ImGui::Text("%s", tmp); + // ImGui::SelectableInput(label, false, ImGuiSelectableFlags_Disabled, tmp, IM_ARRAYSIZE(tmp)); } if (colorpushed) ImGui::PopStyleColor(); diff --git a/mos6502 b/mos6502 index 3ac99ec..eb05fca 160000 --- a/mos6502 +++ b/mos6502 @@ -1 +1 @@ -Subproject commit 3ac99ec9d6cf1e4589f600972e5326b965120cef +Subproject commit eb05fcad3f7f25e25a65c7e25297321ce6f6224d diff --git a/test/6502_functional_test.bin b/test/6502_functional_test.bin new file mode 100644 index 0000000000000000000000000000000000000000..c9a35e1d6bd2e7d85844da2abf7034d5ed820e6e GIT binary patch literal 65536 zcmeHOeQZ_tc|P}C`}!EJ?Th&`-%bk2C1IJAl_4P2c*~Lbt_T zeMQ*p#{Tm?0Z()g-^V2T}&JoAW*ZL3DXBbJV~kJ8GUfTt)P@4x7;&bO{uUu*0z$eFawJhq`p?$}4oQ2o+*Te-OqGYq znesqM8A{5~KcWmH%0TmQ0h0s_jdW*wFwlOf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