This commit is contained in:
Mark Canlas 2020-08-14 17:08:59 -04:00
parent ebb9588e04
commit 575b5710b7
3 changed files with 37 additions and 6 deletions

View File

@ -134,6 +134,8 @@ class AssemblyContext {
xs.append(InstructionWithOperand(instruction, x: A, s.some))
def printOut(): Unit = {
xs.foreach(println)
xs
.map(_.toAsm)
.foreach(println)
}
}

View File

@ -9,7 +9,7 @@ object GlobalAddress {
case class GlobalAddress(n: Int) {
def write[A](x: A)(implicit ctx: AssemblyContext, ev: Operand[A]): Unit = {
ctx.push(LDA, x, s"2: write value ${ev.toString(x)} to address $n")
ctx.push(STA, this)
ctx.push(LDA, x, s"write value ${ev.toString(x)} to address $n")
ctx.push(STA, this, "")
}
}

View File

@ -2,8 +2,37 @@ package com.htmlism.mos6502.dsl
import com.htmlism._
sealed trait Statement
sealed trait Statement {
def toAsm: String
}
case class UnaryInstruction(instruction: Instruction, comment: Option[String]) extends Statement
case class UnaryInstruction(instruction: Instruction, comment: Option[String]) extends Statement {
def toAsm: String = {
val left =
instruction.toString
case class InstructionWithOperand[A : Operand](instruction: Instruction, operand: A, comment: Option[String]) extends Statement
comment match {
case Some(c) =>
f"$left%-16s ; " + c
case None =>
left
}
}
}
case class InstructionWithOperand[A](instruction: Instruction, operand: A, comment: Option[String])(implicit ev: Operand[A]) extends Statement {
def toAsm: String = {
val left =
instruction.toString
val operandStr =
ev.toString(operand)
comment match {
case Some(c) =>
f"$left%-5s $operandStr%-11s; " + c
case None =>
f"$left%-5s $operandStr"
}
}
}