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

46 lines
1.6 KiB
Scala
Raw Normal View History

2022-12-01 12:07:05 +00:00
package com.htmlism.firepower.demo
2023-10-03 20:15:10 +00:00
import scala.util.chaining.*
2022-12-05 14:14:58 +00:00
import zio.*
2022-12-04 22:15:29 +00:00
2024-03-04 14:47:50 +00:00
import com.htmlism.firepower.core.*
2023-10-03 20:15:10 +00:00
import com.htmlism.firepower.core.AsmBlock.*
import com.htmlism.firepower.core.AssemblerOptions.*
2022-12-04 20:40:37 +00:00
import com.htmlism.rufio.withzio.*
2022-12-01 13:17:33 +00:00
2022-12-01 11:50:22 +00:00
object PrintPrograms extends ZIOAppDefault:
2022-12-04 18:26:52 +00:00
private val programs =
2022-12-07 18:36:57 +00:00
List[(String, List[String])](
// FEATURE: writing lines to a file is easy (thanks, rufio)
"two-lines.txt" -> List("foo", "bar"),
2022-12-07 12:45:10 +00:00
// FEATURE: writing paragraphs separated by newlines is easy
2023-01-02 18:02:03 +00:00
"two-paragraphs.txt" -> List(
List("foo", "bar"),
List("alpha", "bravo")
)
2022-12-07 18:36:57 +00:00
.pipe(xxs => AsmBlock.interFlatMap(xxs)(List("", ""), identity)),
2023-01-02 18:02:03 +00:00
"feature-demo.asm" -> FeatureDemo.program,
2022-12-06 20:22:37 +00:00
"print-three-upper-math.asm" -> PrintThree.assemble(
AssemblerOptions(InstructionCase.Uppercase, DefinitionsMode.UseDefinitionsWithMath)
),
2023-01-02 18:02:03 +00:00
"print-three-upper.asm" -> PrintThree.assemble(
2022-12-06 19:58:20 +00:00
AssemblerOptions(InstructionCase.Uppercase, DefinitionsMode.UseDefinitions)
2022-12-06 18:43:48 +00:00
),
2023-01-02 18:02:03 +00:00
"print-three-lower.asm" -> PrintThree.assemble(
2022-12-06 19:30:35 +00:00
AssemblerOptions(InstructionCase.Lowercase, DefinitionsMode.UseLiterals)
2022-12-07 15:33:29 +00:00
),
2023-01-02 18:02:03 +00:00
"snake-easy-6502.asm" -> SnakeEasy6502.assemble(
2022-12-07 15:33:29 +00:00
AssemblerOptions(InstructionCase.Uppercase, DefinitionsMode.UseDefinitions)
2022-12-06 18:43:48 +00:00
)
2022-12-04 18:26:52 +00:00
)
2022-12-04 18:01:22 +00:00
2022-12-04 18:26:52 +00:00
def run: Task[Unit] =
2023-10-23 17:56:45 +00:00
for
2022-12-04 18:26:52 +00:00
// just a traverse in slow motion...
_ <- programs
2023-01-02 18:02:03 +00:00
.map { case (f, xs) => File(s"data/$f").writeLines(xs) }
.foldLeft[Task[Unit]](ZIO.unit)((acc, z) => acc *> z)
2023-10-23 17:56:45 +00:00
yield ()