mirror of
https://github.com/mcanlas/6502-opcodes.git
synced 2024-12-23 01:29:47 +00:00
print out more
This commit is contained in:
parent
101c08094f
commit
9b60d46e03
@ -2,7 +2,12 @@ package com.htmlism.mos6502.dsl
|
||||
|
||||
import scala.collection.mutable.ListBuffer
|
||||
|
||||
case class AsmDocument(xs: List[TopLevelAsmDocumentFragment])
|
||||
case class AsmDocument(xs: List[TopLevelAsmDocumentFragment]) {
|
||||
def toAsm: String =
|
||||
xs
|
||||
.map(_.toAsm)
|
||||
.mkString("\n\n")
|
||||
}
|
||||
|
||||
class AsmDocumentContext {
|
||||
private val xs: ListBuffer[TopLevelAsmDocumentFragment] =
|
||||
@ -15,16 +20,28 @@ class AsmDocumentContext {
|
||||
AsmDocument(xs.toList)
|
||||
}
|
||||
|
||||
sealed trait TopLevelAsmDocumentFragment
|
||||
|
||||
case class AsmFragment(xs: List[Statement]) extends TopLevelAsmDocumentFragment {
|
||||
def printOut(): Unit = {
|
||||
xs.map(_.toAsm)
|
||||
.foreach(println)
|
||||
}
|
||||
sealed trait TopLevelAsmDocumentFragment {
|
||||
def toAsm: String
|
||||
}
|
||||
|
||||
case class DefinitionGroup(comment: String, xs: List[Definition[_]]) extends TopLevelAsmDocumentFragment
|
||||
case class AsmFragment(xs: List[Statement]) extends TopLevelAsmDocumentFragment {
|
||||
def toAsm: String =
|
||||
xs.map(_.toAsm).mkString("\n")
|
||||
}
|
||||
|
||||
case class DefinitionGroup(comment: String, xs: List[Definition[_]]) extends TopLevelAsmDocumentFragment {
|
||||
def toAsm: String = {
|
||||
val commentLine =
|
||||
"; " + comment
|
||||
|
||||
val definitionLines =
|
||||
xs
|
||||
.map(d => f"define ${d.name}%-12s${d.value}")
|
||||
|
||||
(commentLine :: definitionLines)
|
||||
.mkString("\n")
|
||||
}
|
||||
}
|
||||
|
||||
class DefinitionGroupContext {
|
||||
private val xs: ListBuffer[Definition[_]] =
|
||||
@ -37,7 +54,11 @@ class DefinitionGroupContext {
|
||||
DefinitionGroup(s, xs.toList)
|
||||
}
|
||||
|
||||
case class Definition[A: Operand](name: String, x: A)
|
||||
case class Definition[A: Operand](name: String, x: A) {
|
||||
lazy val value: String =
|
||||
implicitly[Operand[A]]
|
||||
.toAddressLiteral(x)
|
||||
}
|
||||
|
||||
class AsmBlockContext {
|
||||
private val xs: ListBuffer[Statement] =
|
||||
|
@ -17,21 +17,21 @@ object Color {
|
||||
def all: NonEmptyList[Color] =
|
||||
NonEmptyList.of(
|
||||
Black,
|
||||
White,
|
||||
Red,
|
||||
Cyan,
|
||||
Purple,
|
||||
Green,
|
||||
Blue,
|
||||
Yellow,
|
||||
Orange,
|
||||
Brown,
|
||||
LightRed,
|
||||
DarkGrey,
|
||||
Grey,
|
||||
LightGreen,
|
||||
LightBlue,
|
||||
LightGrey
|
||||
White,
|
||||
Red,
|
||||
Cyan,
|
||||
Purple,
|
||||
Green,
|
||||
Blue,
|
||||
Yellow,
|
||||
Orange,
|
||||
Brown,
|
||||
LightRed,
|
||||
DarkGrey,
|
||||
Grey,
|
||||
LightGreen,
|
||||
LightBlue,
|
||||
LightGrey
|
||||
)
|
||||
|
||||
def label(x: Color): String =
|
||||
|
@ -3,8 +3,8 @@ package com.htmlism.mos6502.dsl
|
||||
import cats.data.NonEmptyList
|
||||
|
||||
/**
|
||||
* Like an enum, but values are specified
|
||||
*/
|
||||
* Like an enum, but values are specified
|
||||
*/
|
||||
trait Mapping[A] {
|
||||
def comment: String
|
||||
|
||||
|
@ -184,9 +184,9 @@ object Direction {
|
||||
|
||||
def value(x: Direction): Int =
|
||||
x match {
|
||||
case Up => 0x77
|
||||
case Down => 0x61
|
||||
case Left => 0x73
|
||||
case Up => 0x77
|
||||
case Down => 0x61
|
||||
case Left => 0x73
|
||||
case Right => 0x64
|
||||
}
|
||||
|
||||
|
@ -44,15 +44,9 @@ class Easy6502Spec extends AnyFlatSpec with should.Matchers {
|
||||
}
|
||||
}
|
||||
|
||||
doc
|
||||
.xs
|
||||
.foreach {
|
||||
case DefinitionGroup(c, xs) =>
|
||||
println(c)
|
||||
xs.foreach(println)
|
||||
case a: AsmFragment =>
|
||||
a.printOut()
|
||||
}
|
||||
println(
|
||||
doc.toAsm
|
||||
)
|
||||
}
|
||||
|
||||
def withAssemblyContext(f: AssemblyContext => Unit): AssemblyContext = {
|
||||
|
Loading…
Reference in New Issue
Block a user