mirror of
https://github.com/mcanlas/6502-opcodes.git
synced 2024-12-22 09:30:45 +00:00
output ints
This commit is contained in:
parent
a13a366b2c
commit
6345d6c0fd
@ -0,0 +1,3 @@
|
||||
package com.htmlism.scratchpad
|
||||
trait Companion[A]:
|
||||
def canon: A
|
@ -1,9 +1,12 @@
|
||||
package com.htmlism.scratchpad
|
||||
|
||||
object Encoded:
|
||||
trait Byte[A]
|
||||
trait Byte[A]:
|
||||
def int(x: A): Int
|
||||
|
||||
object Byte:
|
||||
given Encoded.Byte[Int] with {}
|
||||
given Encoded.Byte[Int] with
|
||||
def int(x: Int): Int =
|
||||
x
|
||||
|
||||
trait Word[A]
|
||||
|
@ -0,0 +1,10 @@
|
||||
package com.htmlism.scratchpad
|
||||
|
||||
trait GrantsWriteLeases[A]:
|
||||
def withWriteLease[B](f: WriteLease[A] => B)(using A: Companion[A]): B =
|
||||
val lease =
|
||||
new WriteLease[A]:
|
||||
def canon: A =
|
||||
A.canon
|
||||
|
||||
f(lease)
|
@ -10,6 +10,6 @@ object Load:
|
||||
def constY[B: Encoded.Byte](x: B): Asm1[Reg.Y] =
|
||||
Const(x)
|
||||
|
||||
case class Const[R, A: Encoded.Byte](x: A)(using R: Register[R]) extends Asm1[R]:
|
||||
case class Const[R, A](x: A)(using R: Register[R], A: Encoded.Byte[A]) extends Asm1[R]:
|
||||
def xs: List[String] =
|
||||
List(R.load)
|
||||
List(s"${R.load} ${A.int(x)}")
|
||||
|
@ -12,4 +12,4 @@ object Store:
|
||||
|
||||
case class Byte[R, A](dest: WriteLease.ByteAddress[A])(using R: Register[R]) extends Asm2[R, A]:
|
||||
def xs: List[String] =
|
||||
List(R.store)
|
||||
List(R.store + " " + dest.address)
|
||||
|
@ -18,16 +18,24 @@ object ComplicatedResourceSuite extends FunSuite:
|
||||
|
||||
class PlayerOne extends Player[PlayerOne](40)
|
||||
|
||||
object PlayerOne extends PlayerOne:
|
||||
val lease: WriteLease[PlayerOne] =
|
||||
FastLease(PlayerOne)
|
||||
object PlayerOne extends PlayerOne with GrantsWriteLeases[PlayerOne]:
|
||||
given Companion[PlayerOne] with
|
||||
def canon: PlayerOne =
|
||||
PlayerOne
|
||||
|
||||
class PlayerTwo extends Player[PlayerTwo](80)
|
||||
|
||||
object PlayerTwo extends PlayerTwo:
|
||||
val lease: WriteLease[PlayerTwo] =
|
||||
FastLease(PlayerTwo)
|
||||
object PlayerTwo extends PlayerTwo with GrantsWriteLeases[PlayerTwo]:
|
||||
given Companion[PlayerTwo] with
|
||||
def canon: PlayerTwo =
|
||||
PlayerTwo
|
||||
|
||||
test("use write lease") {
|
||||
expect.eql(List("LDA", "STA"), PlayerOne.setHead(0)(using PlayerOne.lease).xs)
|
||||
val asm =
|
||||
PlayerOne
|
||||
.withWriteLease { implicit w =>
|
||||
PlayerOne.setHead(23).xs
|
||||
}
|
||||
|
||||
expect.eql(List("LDA 23", "STA 40"), asm)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user