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:
; initializes values
JSR initSnake
JSR generateApplePosition
RTS
@ -19,3 +23,9 @@ initSnake:
; initializes the snake
RTS
generateApplePosition:
; generates the position of the apple
RTS

View File

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