2022-12-07 15:33:29 +00:00
|
|
|
package com.htmlism.firepower.demo
|
|
|
|
|
2022-12-07 19:42:03 +00:00
|
|
|
import scala.util.chaining.*
|
2022-12-07 15:33:29 +00:00
|
|
|
|
2022-12-07 19:42:03 +00:00
|
|
|
import com.htmlism.firepower.core.AsmBlock.Intent
|
|
|
|
import com.htmlism.firepower.core.*
|
2022-12-07 15:33:29 +00:00
|
|
|
|
|
|
|
object SnakeEasy6502:
|
2022-12-07 19:50:12 +00:00
|
|
|
val program: List[MetaIntent.Jump] =
|
2022-12-07 19:42:03 +00:00
|
|
|
List(
|
|
|
|
init.call,
|
|
|
|
loop.call
|
|
|
|
)
|
|
|
|
|
|
|
|
lazy val init =
|
|
|
|
Subroutine("init")
|
|
|
|
|
|
|
|
lazy val loop =
|
|
|
|
Subroutine("loop")
|
|
|
|
|
|
|
|
lazy val initSnake =
|
|
|
|
Subroutine("initSnake")
|
|
|
|
|
2022-12-07 19:50:12 +00:00
|
|
|
def firstCodeBlock(xs: List[MetaIntent.Jump]): AsmBlock.AnonymousCodeBlock =
|
2022-12-07 19:42:03 +00:00
|
|
|
AsmBlock
|
2022-12-07 19:50:12 +00:00
|
|
|
.AnonymousCodeBlock(xs.map(MetaIntent.Jump.toIntent))
|
2022-12-07 19:42:03 +00:00
|
|
|
|
2022-12-07 19:50:12 +00:00
|
|
|
def callGraph(xs: List[MetaIntent.Jump]): List[AsmBlock.NamedCodeBlock] =
|
2022-12-07 19:42:03 +00:00
|
|
|
Nil
|
|
|
|
|
2022-12-07 18:36:57 +00:00
|
|
|
def assemble(opts: AssemblerOptions): List[String] =
|
2022-12-07 19:42:03 +00:00
|
|
|
(firstCodeBlock(program) :: callGraph(program))
|
2022-12-07 15:33:29 +00:00
|
|
|
.map(AsmBlock.toLines(opts.instructionCase))
|
|
|
|
.pipe(xs => AsmBlock.interFlatMap(xs)(List("", ""), identity))
|