From 0850162d43380f080cce973de585b82f1f5d594f Mon Sep 17 00:00:00 2001 From: Cat's Eye Technologies Date: Thu, 3 Apr 2014 20:29:43 +0100 Subject: [PATCH] Improve game slightly. Add foldRoutine*, use in checker. --- README.markdown | 1 + eg/game.60p | 65 +++++++++++++++++++++++++-------------- src/SixtyPical/Checker.hs | 12 ++++---- src/SixtyPical/Model.hs | 28 ++++++++++++++++- 4 files changed, 76 insertions(+), 30 deletions(-) diff --git a/README.markdown b/README.markdown index 62a78cb..0863140 100644 --- a/README.markdown +++ b/README.markdown @@ -183,3 +183,4 @@ TODO * `jsr (vector)` * `jmp routine` * insist on EOL after each instruction. need spacesWOEOL production +* `copy immediate word` diff --git a/eg/game.60p b/eg/game.60p index a4397da..8f2d9fd 100644 --- a/eg/game.60p +++ b/eg/game.60p @@ -18,7 +18,10 @@ assign vector cinv 788 ; --------- reserve vector save_cinv + assign word position $fb +assign word new_position $fd + reserve word delta reserve byte value reserve word compare_target @@ -45,27 +48,11 @@ routine our_cinv { sta (position), y jsr read_stick jsr advance_pos - - lda #$07 ; just past bottom of screen - sta >compare_target - lda #$e8 - sta compare_target - lda #$00 - sta position adc >delta + sta >new_position +} + +routine install_new_position { + lda new_position sta >position } -routine compare_pos { - lda >position +routine check_new_position_in_bounds { + lda #$07 ; just past bottom of screen + sta >compare_target + lda #$e8 + sta compare_target + lda #$00 + sta new_position cmp >compare_target if beq { - lda j - False -> (COPY A A) - checkInstr other = other + True -> acc + False -> error ("undeclared routine '" ++ routName ++ "'") -- acc + 1 + checkInstr other acc = acc -- -- -- -- -- -- diff --git a/src/SixtyPical/Model.hs b/src/SixtyPical/Model.hs index 6035273..a9a0345 100644 --- a/src/SixtyPical/Model.hs +++ b/src/SixtyPical/Model.hs @@ -125,6 +125,8 @@ declaredRoutineNames (Program decls routines) = routineDeclared routName p = elem routName (declaredRoutineNames p) +-- + mapBlock :: (Instruction -> Instruction) -> [Instruction] -> [Instruction] mapBlock = map @@ -137,7 +139,31 @@ mapRoutines f (rout:routs) = (mapRoutine f rout):(mapRoutines f routs) mapProgramRoutines :: (Instruction -> Instruction) -> Program -> Program -mapProgramRoutines f (Program decls routs) = Program decls $ mapRoutines f routs +mapProgramRoutines f (Program decls routs) = + Program decls $ mapRoutines f routs + +-- + +foldBlock :: (Instruction -> a -> a) -> a -> [Instruction] -> a +foldBlock = foldr + +foldRoutine :: (Instruction -> a -> a) -> a -> Routine -> a +foldRoutine f a (Routine name instrs) = + foldBlock f a instrs + +foldRoutines :: (Instruction -> a -> a) -> a -> [Routine] -> a +foldRoutines f a [] = a +foldRoutines f a (rout:routs) = + let + z = foldRoutine f a rout + in + foldRoutines f z routs + +foldProgramRoutines :: (Instruction -> a -> a) -> a -> Program -> a +foldProgramRoutines f a (Program decls routs) = + foldRoutines f a routs + +-- lookupDecl (Program decls _) name = lookupDecl' (filter (isLocationDecl) decls) name