mirror of
https://github.com/mcanlas/6502-opcodes.git
synced 2025-08-15 15:27:19 +00:00
resource as named operand
This commit is contained in:
@@ -15,11 +15,23 @@ case class ReadWriteLocation[A: Operand](name: String, address: ZeroAddress) {
|
|||||||
|
|
||||||
def write(x: A)(implicit ctx: AssemblyContext): Unit = {
|
def write(x: A)(implicit ctx: AssemblyContext): Unit = {
|
||||||
ctx.push(LDA, x)
|
ctx.push(LDA, x)
|
||||||
ctx.push(STA, address) // should be named address
|
ctx.push(STA, this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
object ReadWriteLocation {
|
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]] =
|
implicit def namedResourceForReadWriteLocation[A]: NamedResource[ReadWriteLocation[A]] =
|
||||||
new NamedResource[ReadWriteLocation[A]] {
|
new NamedResource[ReadWriteLocation[A]] {
|
||||||
def toDefinitions(x: ReadWriteLocation[A]): List[Definition[ZeroAddress]] =
|
def toDefinitions(x: ReadWriteLocation[A]): List[Definition[ZeroAddress]] =
|
||||||
|
@@ -78,8 +78,7 @@ class Easy6502Spec extends AnyFlatSpec with should.Matchers {
|
|||||||
val initSnake =
|
val initSnake =
|
||||||
sub("initSnake") { implicit a =>
|
sub("initSnake") { implicit a =>
|
||||||
snakeDirection.write(Right)
|
snakeDirection.write(Right)
|
||||||
|
snakeLength.write(4) // 2 * 2
|
||||||
snakeLength.read
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val generateApplePosition =
|
val generateApplePosition =
|
||||||
|
Reference in New Issue
Block a user