aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--build.gradle26
-rw-r--r--src/main/kotlin/gui/CpuRegisterWindow.kt52
-rw-r--r--src/main/kotlin/gui/DebugWindow.kt14
-rw-r--r--src/main/kotlin/gui/EmulationOutputWindow.kt15
-rw-r--r--src/main/kotlin/gui/Run.kt5
-rw-r--r--src/main/kotlin/gui/WindowContainer.kt66
7 files changed, 179 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index fae5b6b..fd6986c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -23,5 +23,6 @@ bin
*.log
*.swp
*.bak
+*.ini
src/main/kotlin/Scratch.kt \ No newline at end of file
diff --git a/build.gradle b/build.gradle
index 71b1199..5f657cb 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,3 +1,5 @@
+import org.gradle.internal.os.OperatingSystem
+
buildscript {
ext.kotlin_version = '1.2.31'
@@ -16,6 +18,9 @@ apply plugin: 'kotlin'
repositories {
mavenCentral()
+ maven { url "https://dl.bintray.com/kotlin/kotlin-dev" }
+ maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
+ maven { url 'https://jitpack.io' }
}
test {
@@ -25,6 +30,27 @@ test {
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
+ compile 'com.github.kotlin-graphics:imgui:v1.62-beta-02'
+
+ switch (OperatingSystem.current()) {
+ case OperatingSystem.WINDOWS:
+ ext.lwjglNatives = "natives-windows"
+ break
+ case OperatingSystem.LINUX:
+ ext.lwjglNatives = "natives-linux"
+ break
+ case OperatingSystem.MAC_OS:
+ ext.lwjglNatives = "natives-macos"
+ break
+ }
+
+ // Look up which modules and versions of LWJGL are required and add setup the appropriate natives.
+ configurations.compile.resolvedConfiguration.getResolvedArtifacts().forEach {
+ if (it.moduleVersion.id.group == "org.lwjgl") {
+ runtime "org.lwjgl:${it.moduleVersion.id.name}:${it.moduleVersion.id.version}:${lwjglNatives}"
+ }
+ }
+
testCompile 'io.kotlintest:kotlintest-runner-junit5:3.1.7'
}
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