added gen apple example

This commit is contained in:
Mark Canlas 2022-12-07 18:19:49 -05:00
parent 9d038a0160
commit c1a6ed0714
2 changed files with 25 additions and 9 deletions

View File

@ -6,6 +6,10 @@
init: init:
; initializes values ; initializes values
JSR initSnake
JSR generateApplePosition
RTS RTS
@ -19,3 +23,9 @@ initSnake:
; initializes the snake ; initializes the snake
RTS RTS
generateApplePosition:
; generates the position of the apple
RTS

View File

@ -21,7 +21,8 @@ object SnakeEasy6502:
.copy(intents = .copy(intents =
() => () =>
List( List(
initSnake.call initSnake.call,
generateApplePosition.call
) )
) )
@ -31,6 +32,9 @@ object SnakeEasy6502:
lazy val initSnake = lazy val initSnake =
Subroutine("initSnake", "initializes the snake") Subroutine("initSnake", "initializes the snake")
lazy val generateApplePosition =
Subroutine("generateApplePosition", "generates the position of the apple")
def firstCodeBlock(xs: List[MetaIntent]): AsmBlock.AnonymousCodeBlock = def firstCodeBlock(xs: List[MetaIntent]): AsmBlock.AnonymousCodeBlock =
AsmBlock AsmBlock
.AnonymousCodeBlock(xs.map(_.toIntent)) .AnonymousCodeBlock(xs.map(_.toIntent))
@ -49,20 +53,22 @@ object SnakeEasy6502:
case head :: tail => case head :: tail =>
if (callGraph.contains(head.target)) callGraphRecur(callGraph, tail) if (callGraph.contains(head.target)) callGraphRecur(callGraph, tail)
else else
val rts =
AsmBlock.Intent(
None,
List(
AsmBlock.Intent.Instruction.zero("rts")
)
)
val sub = val sub =
AsmBlock.NamedCodeBlock( AsmBlock.NamedCodeBlock(
head.target, head.target,
head.description.some, head.description.some,
List( head.xs.map(_.toIntent) :+ rts
AsmBlock.Intent(
None,
List(
AsmBlock.Intent.Instruction.zero("rts")
)
)
)
) )
// breadth-first expansion
callGraphRecur(callGraph.updated(head.target, sub), todo ::: head.xs) callGraphRecur(callGraph.updated(head.target, sub), todo ::: head.xs)
case Nil => case Nil =>