6502-opcodes/src/main/scala/com/htmlism/mos6502/dsl/IndexedAddressCollection.scala

15 lines
522 B
Scala
Raw Normal View History

2020-08-14 19:33:50 +00:00
package com.htmlism.mos6502.dsl
2023-10-03 20:15:10 +00:00
import com.htmlism.mos6502.model.*
2020-08-15 03:41:20 +00:00
/**
* A typed collection, like memory mapped to screen pixels. Access by index instead of by address.
*/
2023-06-19 09:30:17 +00:00
case class IndexedAddressCollection[A](baseAddress: Int, name: String)(using ev: Operand[A]):
2020-08-14 19:33:50 +00:00
def apply(n: Int): GlobalAddress =
GlobalAddress(baseAddress + n)
2020-08-15 03:41:20 +00:00
2023-06-19 09:30:17 +00:00
def write(n: Int, x: A)(using ctx: AssemblyContext): Unit =
2020-08-15 03:41:20 +00:00
ctx.push(LDA, x, s"write ${ev.toShow(x)} to $name ($n)")
ctx.push(STA, GlobalAddress(baseAddress + n), "")