6502-opcodes/firepower-demo/src/main/scala/com/htmlism/firepower/demo/Easy6502.scala

69 lines
1.8 KiB
Scala
Raw Permalink Normal View History

2022-12-06 19:30:35 +00:00
package com.htmlism.firepower.demo
2022-12-07 19:42:03 +00:00
import scala.util.chaining.*
import com.htmlism.firepower.core.Definable
2022-12-06 19:58:20 +00:00
2022-12-06 19:30:35 +00:00
object Easy6502:
enum Color:
case Black, White, Red, Cyan, Purple, Green, Blue, Yellow, Orange, Brown, LightRed, DarkGrey, Grey, LightGreen,
LightBlue, LightGrey
object Color:
given Definable[Color] with
2022-12-07 18:53:05 +00:00
def table(x: Color): Definable.Table =
2022-12-06 19:58:20 +00:00
Color
.values
.iterator
.map { c =>
"COLOR_" + c.toString -> c.ordinal
2022-12-06 19:58:20 +00:00
}
2022-12-07 18:53:05 +00:00
.toList
.pipe(Definable.Table("Colors that each screen pixel can be set to", _))
2022-12-06 19:58:20 +00:00
2022-12-06 19:30:35 +00:00
extension (x: Color)
def toComment: String =
x.toString
extension (x: Color)
def toValue: Int =
x.ordinal
2022-12-06 19:58:20 +00:00
extension (x: Color)
def toDefine: String =
"COLOR_" + x.toString
2022-12-06 20:22:37 +00:00
2022-12-06 22:06:53 +00:00
extension (x: Color)
def toDefineWithMath: String =
"COLOR_" + x.toString
2022-12-06 20:22:37 +00:00
class Screen(baseAddr: Int):
def apply(offset: Int): Screen.Pixel =
Screen.Pixel(baseAddr, offset)
object Screen:
case class Pixel(baseAddr: Int, offset: Int)
object Pixel:
given Definable[Pixel] with
2022-12-07 18:53:05 +00:00
def table(x: Pixel): Definable.Table =
// define table needs to be a function of an instance
Definable.Table("The screen as a collection of pixels", List("SCREEN" -> x.baseAddr))
2022-12-06 20:22:37 +00:00
extension (x: Pixel)
def toComment: String =
s"Screen(${x.offset})"
extension (x: Pixel)
def toValue: Int =
x.baseAddr + x.offset
extension (x: Pixel)
def toDefine: String =
2023-10-03 20:15:10 +00:00
if x.offset == 0 then "SCREEN"
else "TODO"
2022-12-06 22:06:53 +00:00
extension (x: Pixel)
def toDefineWithMath: String =
"SCREEN+" + x.offset