mirror of
https://github.com/mcanlas/6502-opcodes.git
synced 2025-03-11 01:34:25 +00:00
add first test
This commit is contained in:
parent
8b91e10133
commit
09b0723787
@ -1,2 +1,3 @@
|
|||||||
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.3.4")
|
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.3.4")
|
||||||
addSbtPlugin("io.github.davidgregory084" % "sbt-tpolecat" % "0.1.13")
|
addSbtPlugin("io.github.davidgregory084" % "sbt-tpolecat" % "0.1.13")
|
||||||
|
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.6.1")
|
||||||
|
@ -120,7 +120,7 @@ class CPU {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class AssemblyContext {
|
class AssemblyContext {
|
||||||
val xs: ListBuffer[Statement] =
|
private val xs: ListBuffer[Statement] =
|
||||||
ListBuffer()
|
ListBuffer()
|
||||||
|
|
||||||
def push(instruction: Instruction): Unit =
|
def push(instruction: Instruction): Unit =
|
||||||
@ -139,4 +139,9 @@ class AssemblyContext {
|
|||||||
xs.map(_.toAsm)
|
xs.map(_.toAsm)
|
||||||
.foreach(println)
|
.foreach(println)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def triplets: List[(String, Option[String], Option[String])] =
|
||||||
|
xs
|
||||||
|
.map(_.toTriplet)
|
||||||
|
.toList
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
package com.htmlism.mos6502.dsl
|
package com.htmlism.mos6502.dsl
|
||||||
|
|
||||||
|
import cats.implicits._
|
||||||
import com.htmlism.mos6502.model.Instruction
|
import com.htmlism.mos6502.model.Instruction
|
||||||
|
|
||||||
sealed trait Statement {
|
sealed trait Statement {
|
||||||
def toAsm: String
|
def toAsm: String
|
||||||
|
|
||||||
|
def toTriplet: (String, Option[String], Option[String])
|
||||||
}
|
}
|
||||||
|
|
||||||
case class UnaryInstruction(instruction: Instruction, comment: Option[String]) extends Statement {
|
case class UnaryInstruction(instruction: Instruction, comment: Option[String]) extends Statement {
|
||||||
@ -18,6 +21,9 @@ case class UnaryInstruction(instruction: Instruction, comment: Option[String]) e
|
|||||||
left
|
left
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def toTriplet: (String, Option[String], Option[String]) =
|
||||||
|
(instruction.toString, None, comment)
|
||||||
}
|
}
|
||||||
|
|
||||||
case class InstructionWithOperand[A](instruction: Instruction, operand: A, comment: Option[String])(
|
case class InstructionWithOperand[A](instruction: Instruction, operand: A, comment: Option[String])(
|
||||||
@ -37,4 +43,7 @@ case class InstructionWithOperand[A](instruction: Instruction, operand: A, comme
|
|||||||
f"$left%-5s $operandStr"
|
f"$left%-5s $operandStr"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def toTriplet: (String, Option[String], Option[String]) =
|
||||||
|
(instruction.toString, ev.toAddressLiteral(operand).some, comment)
|
||||||
}
|
}
|
||||||
|
41
src/test/scala/com/htmlism/mos6502/dsl/Easy6502Spec.scala
Normal file
41
src/test/scala/com/htmlism/mos6502/dsl/Easy6502Spec.scala
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
package com.htmlism.mos6502.dsl
|
||||||
|
|
||||||
|
import cats.implicits._
|
||||||
|
import org.scalatest._
|
||||||
|
import flatspec._
|
||||||
|
import matchers._
|
||||||
|
|
||||||
|
class Easy6502Spec extends AnyFlatSpec with should.Matchers {
|
||||||
|
|
||||||
|
"the three pixel demo" should "have the right instructions" in {
|
||||||
|
val doc =
|
||||||
|
withAssemblyContext { implicit ctx =>
|
||||||
|
val scr =
|
||||||
|
IndexedAddressCollection[Color](0x0200, "screen")
|
||||||
|
|
||||||
|
scr.write(0, Color.White)
|
||||||
|
scr.write(1, Color.Green)
|
||||||
|
scr.write(2, Color.Orange)
|
||||||
|
}
|
||||||
|
|
||||||
|
doc.triplets shouldEqual List(
|
||||||
|
("LDA", "#$01".some, "write White to screen (0)".some),
|
||||||
|
("STA", "$0200".some, "".some),
|
||||||
|
("LDA", "#$05".some, "write Green to screen (1)".some),
|
||||||
|
("STA", "$0201".some, "".some),
|
||||||
|
("LDA", "#$08".some, "write Orange to screen (2)".some),
|
||||||
|
("STA", "$0202".some, "".some)
|
||||||
|
)
|
||||||
|
|
||||||
|
doc.printOut()
|
||||||
|
}
|
||||||
|
|
||||||
|
def withAssemblyContext(f: AssemblyContext => Unit): AssemblyContext = {
|
||||||
|
val ctx: AssemblyContext =
|
||||||
|
new AssemblyContext
|
||||||
|
|
||||||
|
f(ctx)
|
||||||
|
|
||||||
|
ctx
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user