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

44 lines
1.4 KiB
Scala
Raw Permalink Normal View History

2022-12-06 17:56:29 +00:00
package com.htmlism.firepower.demo
2023-10-03 20:15:10 +00:00
import scala.util.chaining.*
2022-12-06 17:56:29 +00:00
2023-10-03 20:15:10 +00:00
import cats.syntax.all.*
2022-12-06 17:56:29 +00:00
2023-10-03 20:15:10 +00:00
import com.htmlism.firepower.core.*
2024-03-04 14:47:50 +00:00
import com.htmlism.firepower.core.AsmBlock.*
2022-12-06 17:56:29 +00:00
object PrintThree:
2022-12-07 19:42:03 +00:00
def build(screen: Easy6502.Screen): List[MetaIntent.Move[Easy6502.Color, Easy6502.Screen.Pixel]] =
2022-12-06 17:56:29 +00:00
List(
2022-12-07 19:42:03 +00:00
MetaIntent.Move(Easy6502.Color.White, screen(0)),
MetaIntent.Move(Easy6502.Color.Green, screen(1)),
MetaIntent.Move(Easy6502.Color.Orange, screen(2))
2022-12-06 18:43:48 +00:00
)
2022-12-07 19:42:03 +00:00
val program: List[MetaIntent.Move[Easy6502.Color, Easy6502.Screen.Pixel]] =
2022-12-06 21:53:40 +00:00
build(Easy6502.Screen(0x200))
2022-12-06 20:22:37 +00:00
2022-12-07 18:36:57 +00:00
def assemble(opts: AssemblerOptions): List[String] =
2022-12-06 23:06:09 +00:00
(defines(opts.definitionsMode) ++ codes(opts.definitionsMode))
.map(AsmBlock.toLines(opts.instructionCase))
2022-12-06 19:58:20 +00:00
.pipe(xs => AsmBlock.interFlatMap(xs)(List("", ""), identity))
2022-12-06 23:06:09 +00:00
private def defines(opts: AssemblerOptions.DefinitionsMode) =
opts match
2022-12-06 19:58:20 +00:00
case AssemblerOptions.DefinitionsMode.UseLiterals =>
Nil
2022-12-06 20:38:39 +00:00
case AssemblerOptions.DefinitionsMode.UseDefinitions | AssemblerOptions.DefinitionsMode.UseDefinitionsWithMath =>
2022-12-06 19:58:20 +00:00
program
2022-12-06 20:22:37 +00:00
.flatMap(_.defines)
2022-12-06 19:58:20 +00:00
.distinct
2022-12-07 18:53:05 +00:00
.map { dt =>
AsmBlock.DefinesBlock(dt.description.some, dt.xs)
2022-12-06 19:58:20 +00:00
}
2022-12-06 23:06:09 +00:00
private def codes(opts: AssemblerOptions.DefinitionsMode) =
2022-12-06 18:43:48 +00:00
program
2022-12-07 19:42:03 +00:00
.map(MetaIntent.Move.toIntent(_, opts))
2022-12-06 18:43:48 +00:00
.pipe(AnonymousCodeBlock(_))
.pipe(List(_))