aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/kotlin/GameBoy.kt10
-rw-r--r--src/main/kotlin/gpu/Gpu.kt9
-rw-r--r--src/main/kotlin/gpu/TestPatternGpu.kt52
3 files changed, 71 insertions, 0 deletions
diff --git a/src/main/kotlin/GameBoy.kt b/src/main/kotlin/GameBoy.kt
new file mode 100644
index 0000000..7c8dfdc
--- /dev/null
+++ b/src/main/kotlin/GameBoy.kt
@@ -0,0 +1,10 @@
+import cpu.Cpu
+import gpu.Gpu
+import java.io.File
+
+class GameBoy(val cpu: Cpu, val gpu: Gpu) {
+
+ fun loadRom(file: File) {
+ this.cpu.loadRom(file.readBytes())
+ }
+} \ No newline at end of file
diff --git a/src/main/kotlin/gpu/Gpu.kt b/src/main/kotlin/gpu/Gpu.kt
new file mode 100644
index 0000000..db95c03
--- /dev/null
+++ b/src/main/kotlin/gpu/Gpu.kt
@@ -0,0 +1,9 @@
+package gpu
+
+import java.awt.Color
+import java.awt.image.BufferedImage
+
+interface Gpu {
+ fun setPixel(x: Int, y: Int, colour: Color)
+ fun getFrame(): BufferedImage
+} \ No newline at end of file
diff --git a/src/main/kotlin/gpu/TestPatternGpu.kt b/src/main/kotlin/gpu/TestPatternGpu.kt
new file mode 100644
index 0000000..6976426
--- /dev/null
+++ b/src/main/kotlin/gpu/TestPatternGpu.kt
@@ -0,0 +1,52 @@
+package gpu
+
+import java.awt.Color
+import java.awt.image.BufferedImage
+import java.io.File
+import javax.imageio.ImageIO
+
+class TestPatternGpu : Gpu {
+
+ private val SCALING_FACTOR = 4
+
+ private val frame = BufferedImage(160 * SCALING_FACTOR, 144 * SCALING_FACTOR, BufferedImage.TYPE_INT_RGB)
+
+ private var lastColour = Color.BLACK
+
+ override fun setPixel(x: Int, y: Int, colour: Color) {
+ (0 until SCALING_FACTOR).forEach { xOffset ->
+ (0 until SCALING_FACTOR).forEach { yOffset ->
+ frame.setRGB((x * SCALING_FACTOR) + xOffset, (y * SCALING_FACTOR) + yOffset, colour.rgb)
+ }
+ }
+ }
+
+ override fun getFrame(): BufferedImage {
+
+ (0 until 144).forEach { y ->
+
+ if(y % 4 == 0) {
+ swapColour()
+ }
+
+ (0 until 160).forEach { x ->
+
+ if(x % 4 == 0) {
+ swapColour()
+ }
+
+ setPixel(x, y, lastColour)
+ }
+ }
+
+ return frame
+ }
+
+ private fun swapColour() {
+ lastColour = if(lastColour == Color.BLACK) {
+ Color.WHITE
+ } else {
+ Color.BLACK
+ }
+ }
+} \ No newline at end of file