6502-opcodes/src/test/scala/com/htmlism/mos6502/dsl/Easy6502Spec.scala

96 lines
2.0 KiB
Scala
Raw Normal View History

2020-08-15 05:27:13 +00:00
package com.htmlism.mos6502.dsl
import cats.implicits._
2020-08-15 06:04:21 +00:00
import org.scalatest.flatspec._
import org.scalatest.matchers._
2020-08-15 05:27:13 +00:00
2020-08-16 15:33:49 +00:00
import com.htmlism.mos6502.model._
2020-08-15 05:27:13 +00:00
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(
2020-08-16 05:56:17 +00:00
("LDA", "#white".some, "write White to screen (0)".some),
2020-08-15 05:27:13 +00:00
("STA", "$0200".some, "".some),
2020-08-16 05:56:17 +00:00
("LDA", "#green".some, "write Green to screen (1)".some),
2020-08-15 05:27:13 +00:00
("STA", "$0201".some, "".some),
2020-08-16 05:56:17 +00:00
("LDA", "#orange".some, "write Orange to screen (2)".some),
2020-08-15 05:27:13 +00:00
("STA", "$0202".some, "".some)
)
doc.printOut()
}
2020-08-16 04:16:10 +00:00
"define style dsl" should "compile" in {
val doc =
asmDoc { implicit ctx =>
enum[Color]
2020-08-16 04:58:25 +00:00
asm { implicit a =>
val scr =
IndexedAddressCollection[Color](0x0200, "screen")
scr.write(0, Color.White)
scr.write(1, Color.Green)
scr.write(2, Color.Orange)
}
2020-08-16 04:16:10 +00:00
}
2020-08-16 05:17:39 +00:00
println(
doc.toAsm
)
2020-08-16 04:16:10 +00:00
}
2020-08-16 15:33:49 +00:00
"loop demo" should "compile" in {
val doc =
asmDoc { implicit ctx =>
asm { implicit a =>
2020-08-21 08:04:35 +00:00
registers.X.loop("incrementing", 2 upTo 5) { implicit a =>
2020-08-16 15:33:49 +00:00
a.push(INY)
}
}
}
println(
doc.toAsm
)
}
2020-08-16 16:55:21 +00:00
"sub demo" should "compile" in {
val init =
sub("init") { implicit a =>
registers.X.incr
}
val doc =
asmDoc { implicit ctx =>
asm { implicit a =>
jump(init)
}
}
println(
doc.toAsm
)
}
2020-08-15 05:27:13 +00:00
def withAssemblyContext(f: AssemblyContext => Unit): AssemblyContext = {
val ctx: AssemblyContext =
new AssemblyContext
f(ctx)
ctx
}
}