resource as named operand

This commit is contained in:
Mark Canlas 2020-08-26 10:26:37 -04:00
parent d42ed22153
commit 5fe085e09a
2 changed files with 14 additions and 3 deletions

View File

@ -15,11 +15,23 @@ case class ReadWriteLocation[A: Operand](name: String, address: ZeroAddress) {
def write(x: A)(implicit ctx: AssemblyContext): Unit = {
ctx.push(LDA, x)
ctx.push(STA, address) // should be named address
ctx.push(STA, this)
}
}
object ReadWriteLocation {
implicit def operandForReadWriteLocation[A]: Operand[ReadWriteLocation[A]] =
new Operand[ReadWriteLocation[A]] {
def toAddressLiteral(x: ReadWriteLocation[A]): String =
x.name
def toShow(x: ReadWriteLocation[A]): String =
x.name
def operandType: OperandType =
MemoryLocation
}
implicit def namedResourceForReadWriteLocation[A]: NamedResource[ReadWriteLocation[A]] =
new NamedResource[ReadWriteLocation[A]] {
def toDefinitions(x: ReadWriteLocation[A]): List[Definition[ZeroAddress]] =

View File

@ -78,8 +78,7 @@ class Easy6502Spec extends AnyFlatSpec with should.Matchers {
val initSnake =
sub("initSnake") { implicit a =>
snakeDirection.write(Right)
snakeLength.read
snakeLength.write(4) // 2 * 2
}
val generateApplePosition =