mirror of
https://github.com/mcanlas/6502-opcodes.git
synced 2025-04-06 19:37:10 +00:00
label an indexed resource
This commit is contained in:
parent
6924f6c47f
commit
78f05a5103
@ -40,11 +40,11 @@ object DslDemo extends App {
|
||||
// first color example
|
||||
withAssemblyContext { implicit ctx =>
|
||||
val scr =
|
||||
0x0200.indexed
|
||||
IndexedAddressCollection[Color](0x0200, "screen")
|
||||
|
||||
scr(0).write[Color](Color.White)
|
||||
scr(1).write[Color](Color.Green)
|
||||
scr(2).write[Color](Color.Orange)
|
||||
scr.write(0, Color.White)
|
||||
scr.write(1, Color.Green)
|
||||
scr.write(2, Color.Orange)
|
||||
}
|
||||
|
||||
def withAssemblyContext(f: AssemblyContext => Unit): Unit = {
|
||||
@ -64,9 +64,6 @@ object DslDemo extends App {
|
||||
|
||||
def addr: GlobalAddress =
|
||||
GlobalAddress(n)
|
||||
|
||||
def indexed: IndexedAddressCollection =
|
||||
IndexedAddressCollection(n)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,5 @@
|
||||
package com.htmlism.mos6502.dsl
|
||||
|
||||
import com.htmlism._
|
||||
|
||||
object GlobalAddress {
|
||||
implicit val operandGlobal: Operand[GlobalAddress] =
|
||||
new Operand[GlobalAddress] {
|
||||
@ -16,9 +14,4 @@ object GlobalAddress {
|
||||
}
|
||||
}
|
||||
|
||||
case class GlobalAddress(n: Int) {
|
||||
def write[A](x: A)(implicit ctx: AssemblyContext, ev: Operand[A]): Unit = {
|
||||
ctx.push(LDA, x, s"write ${ev.toShow(x)} to address $n")
|
||||
ctx.push(STA, this, "")
|
||||
}
|
||||
}
|
||||
case class GlobalAddress(n: Int)
|
||||
|
@ -1,6 +1,16 @@
|
||||
package com.htmlism.mos6502.dsl
|
||||
|
||||
case class IndexedAddressCollection(baseAddress: Int) {
|
||||
import com.htmlism._
|
||||
|
||||
/**
|
||||
* A typed collection, like memory mapped to screen pixels. Access by index instead of by address.
|
||||
*/
|
||||
case class IndexedAddressCollection[A](baseAddress: Int, name: String)(implicit ev: Operand[A]) {
|
||||
def apply(n: Int): GlobalAddress =
|
||||
GlobalAddress(baseAddress + n)
|
||||
|
||||
def write(n: Int, x: A)(implicit ctx: AssemblyContext): Unit = {
|
||||
ctx.push(LDA, x, s"write ${ev.toShow(x)} to $name ($n)")
|
||||
ctx.push(STA, GlobalAddress(baseAddress + n), "")
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user