mirror of
https://github.com/mcanlas/6502-opcodes.git
synced 2025-01-04 14:32:31 +00:00
specify byte width
This commit is contained in:
parent
3c1d811aef
commit
65065e074e
@ -1,7 +1,7 @@
|
|||||||
package com.htmlism.nescant
|
package com.htmlism.nescant
|
||||||
|
|
||||||
trait Sink[A]
|
trait ByteSink[A]
|
||||||
|
|
||||||
object Sink {
|
object ByteSink {
|
||||||
// TODO int cannot be a source
|
// TODO int cannot be a source
|
||||||
}
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
package com.htmlism.nescant
|
||||||
|
|
||||||
|
trait ByteSource[A]
|
||||||
|
|
||||||
|
object ByteSource {
|
||||||
|
implicit val sourceForInt: ByteSource[Int] =
|
||||||
|
new ByteSource[Int] {}
|
||||||
|
}
|
@ -1,11 +1,11 @@
|
|||||||
package com.htmlism.nescant
|
package com.htmlism.nescant
|
||||||
|
|
||||||
object GlobalAddress {
|
object GlobalAddress {
|
||||||
implicit val sourceForGlobalAddress: Source[GlobalAddress] =
|
implicit val sourceForGlobalAddress: ByteSource[GlobalAddress] =
|
||||||
new Source[GlobalAddress] {}
|
new ByteSource[GlobalAddress] {}
|
||||||
|
|
||||||
implicit val sinkForGlobalAddress: Sink[GlobalAddress] =
|
implicit val sinkForGlobalAddress: ByteSink[GlobalAddress] =
|
||||||
new Sink[GlobalAddress] {}
|
new ByteSink[GlobalAddress] {}
|
||||||
}
|
}
|
||||||
|
|
||||||
case class GlobalAddress(n: Int)
|
case class GlobalAddress(n: Int)
|
||||||
|
@ -8,11 +8,11 @@ package com.htmlism.nescant
|
|||||||
case class ReadWriteLocation[A](name: String, address: ZeroPageAddress)
|
case class ReadWriteLocation[A](name: String, address: ZeroPageAddress)
|
||||||
|
|
||||||
object ReadWriteLocation {
|
object ReadWriteLocation {
|
||||||
implicit def sourceForReadWriteLocation[A: Operand]: Source[ReadWriteLocation[A]] =
|
implicit def sourceForReadWriteLocation[A: Operand]: ByteSource[ReadWriteLocation[A]] =
|
||||||
new Source[ReadWriteLocation[A]] {}
|
new ByteSource[ReadWriteLocation[A]] {}
|
||||||
|
|
||||||
implicit def sinkForReadWriteLocation[A: Operand]: Sink[ReadWriteLocation[A]] =
|
implicit def sinkForReadWriteLocation[A: Operand]: ByteSink[ReadWriteLocation[A]] =
|
||||||
new Sink[ReadWriteLocation[A]] {}
|
new ByteSink[ReadWriteLocation[A]] {}
|
||||||
|
|
||||||
implicit def operandForReadWriteLocation[A: Operand]: Operand[ReadWriteLocation[A]] =
|
implicit def operandForReadWriteLocation[A: Operand]: Operand[ReadWriteLocation[A]] =
|
||||||
new Operand[ReadWriteLocation[A]] {
|
new Operand[ReadWriteLocation[A]] {
|
||||||
|
@ -1,8 +0,0 @@
|
|||||||
package com.htmlism.nescant
|
|
||||||
|
|
||||||
trait Source[A]
|
|
||||||
|
|
||||||
object Source {
|
|
||||||
implicit val sourceForInt: Source[Int] =
|
|
||||||
new Source[Int] {}
|
|
||||||
}
|
|
@ -12,8 +12,8 @@ package com.htmlism.nescant
|
|||||||
case class VolatileDevice[A](name: String, address: ZeroPageAddress)
|
case class VolatileDevice[A](name: String, address: ZeroPageAddress)
|
||||||
|
|
||||||
object VolatileDevice {
|
object VolatileDevice {
|
||||||
implicit def sourceForVolatileDevice[A: Operand]: Source[VolatileDevice[A]] =
|
implicit def sourceForVolatileDevice[A: Operand]: ByteSource[VolatileDevice[A]] =
|
||||||
new Source[VolatileDevice[A]] {}
|
new ByteSource[VolatileDevice[A]] {}
|
||||||
|
|
||||||
implicit def operandForVolatileDevice[A: Operand]: Operand[VolatileDevice[A]] =
|
implicit def operandForVolatileDevice[A: Operand]: Operand[VolatileDevice[A]] =
|
||||||
new Operand[VolatileDevice[A]] {
|
new Operand[VolatileDevice[A]] {
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
package com.htmlism.nescant
|
package com.htmlism.nescant
|
||||||
|
|
||||||
object ZeroPageAddress {
|
object ZeroPageAddress {
|
||||||
implicit val sourceForZeroPageAddress: Source[ZeroPageAddress] =
|
implicit val sourceForZeroPageAddress: ByteSource[ZeroPageAddress] =
|
||||||
new Source[ZeroPageAddress] {}
|
new ByteSource[ZeroPageAddress] {}
|
||||||
|
|
||||||
implicit val sinkForZeroPageAddress: Sink[ZeroPageAddress] =
|
implicit val sinkForZeroPageAddress: ByteSink[ZeroPageAddress] =
|
||||||
new Sink[ZeroPageAddress] {}
|
new ByteSink[ZeroPageAddress] {}
|
||||||
}
|
}
|
||||||
|
|
||||||
case class ZeroPageAddress(n: Int)
|
case class ZeroPageAddress(n: Int)
|
||||||
|
@ -9,8 +9,8 @@ package object dsl {
|
|||||||
GlobalAddress(n)
|
GlobalAddress(n)
|
||||||
}
|
}
|
||||||
|
|
||||||
implicit class SinkOps[A: Sink](x: A) {
|
implicit class SinkOps[A: ByteSink](x: A) {
|
||||||
def write[B: Source](src: B): Unit = {
|
def write[B: ByteSource](src: B): Unit = {
|
||||||
val _ = src
|
val _ = src
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,21 @@
|
|||||||
|
package com.htmlism.nescant
|
||||||
|
package dsl
|
||||||
|
|
||||||
|
import org.scalatest.flatspec._
|
||||||
|
import org.scalatest.matchers._
|
||||||
|
|
||||||
|
class ByteSinkSpec extends AnyFlatSpec with should.Matchers {
|
||||||
|
"A zero page address" should "be a byte-wide sync" in {
|
||||||
|
123.z.write(456)
|
||||||
|
}
|
||||||
|
|
||||||
|
"A global address" should "be a byte-wide sync" in {
|
||||||
|
123.g.write(456)
|
||||||
|
}
|
||||||
|
|
||||||
|
"A read write location" should "be a byte-wide sync" in {
|
||||||
|
val sink = ReadWriteLocation[Int]("", 0.z)
|
||||||
|
|
||||||
|
sink.write(456)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
package com.htmlism.nescant
|
||||||
|
package dsl
|
||||||
|
|
||||||
|
import org.scalatest.flatspec._
|
||||||
|
import org.scalatest.matchers._
|
||||||
|
|
||||||
|
class ByteSourceSpec extends AnyFlatSpec with should.Matchers {
|
||||||
|
private val sink =
|
||||||
|
123.z
|
||||||
|
|
||||||
|
"A number" should "be a byte-wide source" in {
|
||||||
|
sink.write(456)
|
||||||
|
}
|
||||||
|
|
||||||
|
"A zero page address" should "be a byte-wide source" in {
|
||||||
|
sink.write(456.z)
|
||||||
|
}
|
||||||
|
|
||||||
|
"A global address" should "be a byte-wide source" in {
|
||||||
|
sink.write(456.g)
|
||||||
|
}
|
||||||
|
|
||||||
|
"A volatile device" should "be a byte-wide source" in {
|
||||||
|
val src = VolatileDevice[Int]("", 0.z)
|
||||||
|
|
||||||
|
sink.write(src)
|
||||||
|
}
|
||||||
|
|
||||||
|
"A read write location" should "be a byte-wide source" in {
|
||||||
|
val src = ReadWriteLocation[Int]("", 0.z)
|
||||||
|
|
||||||
|
sink.write(src)
|
||||||
|
}
|
||||||
|
}
|
@ -1,21 +0,0 @@
|
|||||||
package com.htmlism.nescant
|
|
||||||
package dsl
|
|
||||||
|
|
||||||
import org.scalatest.flatspec._
|
|
||||||
import org.scalatest.matchers._
|
|
||||||
|
|
||||||
class SinkSpec extends AnyFlatSpec with should.Matchers {
|
|
||||||
"A zero page address" should "be a sink" in {
|
|
||||||
123.z.write(456)
|
|
||||||
}
|
|
||||||
|
|
||||||
"A global address" should "be a sink" in {
|
|
||||||
123.g.write(456)
|
|
||||||
}
|
|
||||||
|
|
||||||
"A read write location" should "be a sink" in {
|
|
||||||
val sink = ReadWriteLocation[Int]("", 0.z)
|
|
||||||
|
|
||||||
sink.write(456)
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,31 +0,0 @@
|
|||||||
package com.htmlism.nescant
|
|
||||||
package dsl
|
|
||||||
|
|
||||||
import org.scalatest.flatspec._
|
|
||||||
import org.scalatest.matchers._
|
|
||||||
|
|
||||||
class SourceSpec extends AnyFlatSpec with should.Matchers {
|
|
||||||
"A number" should "be a source" in {
|
|
||||||
123.z.write(456)
|
|
||||||
}
|
|
||||||
|
|
||||||
"A zero page address" should "be a source" in {
|
|
||||||
123.z.write(456.z)
|
|
||||||
}
|
|
||||||
|
|
||||||
"A global address" should "be a source" in {
|
|
||||||
123.z.write(456.g)
|
|
||||||
}
|
|
||||||
|
|
||||||
"A volatile device" should "be a source" in {
|
|
||||||
val src = VolatileDevice[Int]("", 0.z)
|
|
||||||
|
|
||||||
123.z.write(src)
|
|
||||||
}
|
|
||||||
|
|
||||||
"A read write location" should "be a source" in {
|
|
||||||
val src = ReadWriteLocation[Int]("", 0.z)
|
|
||||||
|
|
||||||
123.z.write(src)
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user