diff options
Diffstat (limited to 'src/main/kotlin')
| -rw-r--r-- | src/main/kotlin/gui/CpuRegisterWindow.kt | 52 | ||||
| -rw-r--r-- | src/main/kotlin/gui/DebugWindow.kt | 14 | ||||
| -rw-r--r-- | src/main/kotlin/gui/EmulationOutputWindow.kt | 15 | ||||
| -rw-r--r-- | src/main/kotlin/gui/Run.kt | 5 | ||||
| -rw-r--r-- | src/main/kotlin/gui/WindowContainer.kt | 66 |
5 files changed, 152 insertions, 0 deletions
diff --git a/src/main/kotlin/gui/CpuRegisterWindow.kt b/src/main/kotlin/gui/CpuRegisterWindow.kt new file mode 100644 index 0000000..0de7ad6 --- /dev/null +++ b/src/main/kotlin/gui/CpuRegisterWindow.kt @@ -0,0 +1,52 @@ +package gui + +import cpu.Registers +import glm_.vec2.Vec2 +import imgui.Cond +import imgui.ImGui + +fun paintCpuRegisterWindow(registers: Registers) { + with(ImGui) { + setNextWindowSize(Vec2(200, 300), Cond.FirstUseEver) + setNextWindowPos(Vec2(20, 150), Cond.FirstUseEver) + begin("CPU state") + + text("Registers:") + separator() + + columns(2, "cpuReg", false) + + text(String.format("A: 0x%02X", registers.A)) + nextColumn() + text(String.format("F: 0x%02X", registers.F)) + nextColumn() + text(String.format("B: 0x%02X", registers.B)) + nextColumn() + text(String.format("C: 0x%02X", registers.C)) + nextColumn() + text(String.format("D: 0x%02X", registers.D)) + nextColumn() + text(String.format("E: 0x%02X", registers.E)) + nextColumn() + text(String.format("H: 0x%02X", registers.H)) + nextColumn() + text(String.format("L: 0x%02X", registers.L)) + nextColumn() + text(String.format("SP: 0x%04X", registers.SP)) + nextColumn() + text(String.format("PC: 0x%04X", registers.PC)) + + columns(1) + newLine() + text("Flags:") + separator() + + text("ZERO: ${registers.getFlag(Registers.Flag.ZERO) == 1}") + text("SUBTRACT: ${registers.getFlag(Registers.Flag.SUBTRACT) == 1}") + text("HALF_CARRY: ${registers.getFlag(Registers.Flag.HALF_CARRY) == 1}") + text("CARRY: ${registers.getFlag(Registers.Flag.CARRY) == 1}") + + end() + } +} + diff --git a/src/main/kotlin/gui/DebugWindow.kt b/src/main/kotlin/gui/DebugWindow.kt new file mode 100644 index 0000000..d80d2b3 --- /dev/null +++ b/src/main/kotlin/gui/DebugWindow.kt @@ -0,0 +1,14 @@ +package gui + +import glm_.vec2.Vec2 +import imgui.Cond +import imgui.ImGui + +fun paintDebugWindow() { + with(ImGui) { + setNextWindowPos(Vec2(20, 50), Cond.FirstUseEver) + begin("Debug info") + text("%.1f FPS (%.2f ms/frame)", io.framerate, 1_000f / io.framerate) + end() + } +}
\ No newline at end of file diff --git a/src/main/kotlin/gui/EmulationOutputWindow.kt b/src/main/kotlin/gui/EmulationOutputWindow.kt new file mode 100644 index 0000000..489edbe --- /dev/null +++ b/src/main/kotlin/gui/EmulationOutputWindow.kt @@ -0,0 +1,15 @@ +package gui + +import glm_.vec2.Vec2 +import imgui.Cond +import imgui.ImGui + +fun paintEmulationOutputWindow() { + with(ImGui) { + setNextWindowSize(Vec2(640, 576), Cond.FirstUseEver) + setNextWindowPos(Vec2(400, 50), Cond.FirstUseEver) + begin("Emulation output - 4x scale") + text("TODO - actually render something...") + end() + } +}
\ No newline at end of file diff --git a/src/main/kotlin/gui/Run.kt b/src/main/kotlin/gui/Run.kt new file mode 100644 index 0000000..727c539 --- /dev/null +++ b/src/main/kotlin/gui/Run.kt @@ -0,0 +1,5 @@ +package gui + +fun main(args: Array<String>) { + WindowContainer().run() +}
\ No newline at end of file diff --git a/src/main/kotlin/gui/WindowContainer.kt b/src/main/kotlin/gui/WindowContainer.kt new file mode 100644 index 0000000..5e101b7 --- /dev/null +++ b/src/main/kotlin/gui/WindowContainer.kt @@ -0,0 +1,66 @@ +package gui + +import cpu.Cpu +import glm_.vec4.Vec4 +import gln.checkError +import imgui.Context +import imgui.ImGui +import imgui.destroy +import imgui.impl.LwjglGL3 +import org.lwjgl.opengl.GL11 +import uno.glfw.GlfwWindow +import uno.glfw.glfw + +class WindowContainer { + + var cpu: Cpu + + init { + glfw.init("3.2") + cpu = Cpu() + } + + val window = GlfwWindow(1280, 720, "KGB - KotlinGameBoy").apply { + init() + } + + + fun run() { + + // Enable vsync + glfw.swapInterval = 1 + + val ctx = Context() + LwjglGL3.init(window) + ImGui.styleColorsDark() + + window.loop(::mainLoop) + + LwjglGL3.shutdown() + ctx.destroy() + + window.destroy() + glfw.terminate() + + } + + private fun mainLoop() { + + LwjglGL3.newFrame() + + with(ImGui) { + paintDebugWindow() + paintEmulationOutputWindow() + paintCpuRegisterWindow(cpu.registers) + } + + gln.glViewport(window.framebufferSize) + gln.glClearColor(Vec4(0.45f, 0.55f, 0.6f, 1f)) + GL11.glClear(GL11.GL_COLOR_BUFFER_BIT) + + ImGui.render() + LwjglGL3.renderDrawData(ImGui.drawData!!) + + checkError("mainLoop") + } +}
\ No newline at end of file |