mirror of
https://github.com/catseye/SixtyPical.git
synced 2025-02-19 20:30:45 +00:00
Improve game slightly. Add foldRoutine*, use in checker.
This commit is contained in:
parent
962f2ad452
commit
0850162d43
@ -183,3 +183,4 @@ TODO
|
|||||||
* `jsr (vector)`
|
* `jsr (vector)`
|
||||||
* `jmp routine`
|
* `jmp routine`
|
||||||
* insist on EOL after each instruction. need spacesWOEOL production
|
* insist on EOL after each instruction. need spacesWOEOL production
|
||||||
|
* `copy immediate word`
|
||||||
|
65
eg/game.60p
65
eg/game.60p
@ -18,7 +18,10 @@ assign vector cinv 788
|
|||||||
; ---------
|
; ---------
|
||||||
|
|
||||||
reserve vector save_cinv
|
reserve vector save_cinv
|
||||||
|
|
||||||
assign word position $fb
|
assign word position $fb
|
||||||
|
assign word new_position $fd
|
||||||
|
|
||||||
reserve word delta
|
reserve word delta
|
||||||
reserve byte value
|
reserve byte value
|
||||||
reserve word compare_target
|
reserve word compare_target
|
||||||
@ -45,27 +48,11 @@ routine our_cinv {
|
|||||||
sta (position), y
|
sta (position), y
|
||||||
jsr read_stick
|
jsr read_stick
|
||||||
jsr advance_pos
|
jsr advance_pos
|
||||||
|
jsr check_new_position_in_bounds
|
||||||
lda #$07 ; just past bottom of screen
|
|
||||||
sta >compare_target
|
|
||||||
lda #$e8
|
|
||||||
sta <compare_target
|
|
||||||
jsr compare_pos
|
|
||||||
|
|
||||||
if bcs {
|
if bcs {
|
||||||
jsr reset_position
|
jsr install_new_position
|
||||||
} else {
|
} else { }
|
||||||
|
|
||||||
lda #$04
|
|
||||||
sta >compare_target
|
|
||||||
lda #$00
|
|
||||||
sta <compare_target
|
|
||||||
jsr compare_pos
|
|
||||||
|
|
||||||
if bcc {
|
|
||||||
jsr reset_position
|
|
||||||
} else { }
|
|
||||||
}
|
|
||||||
jmp (save_cinv)
|
jmp (save_cinv)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,17 +67,49 @@ routine advance_pos {
|
|||||||
clc
|
clc
|
||||||
lda <position
|
lda <position
|
||||||
adc <delta
|
adc <delta
|
||||||
sta <position
|
sta <new_position
|
||||||
lda >position
|
lda >position
|
||||||
adc >delta
|
adc >delta
|
||||||
|
sta >new_position
|
||||||
|
}
|
||||||
|
|
||||||
|
routine install_new_position {
|
||||||
|
lda <new_position
|
||||||
|
sta <position
|
||||||
|
lda >new_position
|
||||||
sta >position
|
sta >position
|
||||||
}
|
}
|
||||||
|
|
||||||
routine compare_pos {
|
routine check_new_position_in_bounds {
|
||||||
lda >position
|
lda #$07 ; just past bottom of screen
|
||||||
|
sta >compare_target
|
||||||
|
lda #$e8
|
||||||
|
sta <compare_target
|
||||||
|
jsr compare_new_pos
|
||||||
|
|
||||||
|
if bcs {
|
||||||
|
clc
|
||||||
|
} else {
|
||||||
|
|
||||||
|
lda #$04
|
||||||
|
sta >compare_target
|
||||||
|
lda #$00
|
||||||
|
sta <compare_target
|
||||||
|
jsr compare_new_pos
|
||||||
|
|
||||||
|
if bcc {
|
||||||
|
clc
|
||||||
|
} else {
|
||||||
|
sec
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
routine compare_new_pos {
|
||||||
|
lda >new_position
|
||||||
cmp >compare_target
|
cmp >compare_target
|
||||||
if beq {
|
if beq {
|
||||||
lda <position
|
lda <new_position
|
||||||
cmp <compare_target
|
cmp <compare_target
|
||||||
} else {
|
} else {
|
||||||
}
|
}
|
||||||
|
@ -38,17 +38,17 @@ noIndexedAccessOfNonTables p@(Program decls routines) =
|
|||||||
|
|
||||||
noUseOfUndeclaredRoutines p@(Program decls routines) =
|
noUseOfUndeclaredRoutines p@(Program decls routines) =
|
||||||
let
|
let
|
||||||
mappedProgram = mapProgramRoutines (checkInstr) p
|
undeclaredRoutines = foldProgramRoutines (checkInstr) 0 p
|
||||||
in
|
in
|
||||||
mappedProgram == p
|
undeclaredRoutines == 0
|
||||||
where
|
where
|
||||||
routineNames = declaredRoutineNames p
|
routineNames = declaredRoutineNames p
|
||||||
-- TODO also check COPYROUTINE here
|
-- TODO also check COPYROUTINE here
|
||||||
checkInstr j@(JSR routName) =
|
checkInstr j@(JSR routName) acc =
|
||||||
case routName `elem` routineNames of
|
case routName `elem` routineNames of
|
||||||
True -> j
|
True -> acc
|
||||||
False -> (COPY A A)
|
False -> error ("undeclared routine '" ++ routName ++ "'") -- acc + 1
|
||||||
checkInstr other = other
|
checkInstr other acc = acc
|
||||||
|
|
||||||
-- -- -- -- -- --
|
-- -- -- -- -- --
|
||||||
|
|
||||||
|
@ -125,6 +125,8 @@ declaredRoutineNames (Program decls routines) =
|
|||||||
routineDeclared routName p =
|
routineDeclared routName p =
|
||||||
elem routName (declaredRoutineNames p)
|
elem routName (declaredRoutineNames p)
|
||||||
|
|
||||||
|
--
|
||||||
|
|
||||||
mapBlock :: (Instruction -> Instruction) -> [Instruction] -> [Instruction]
|
mapBlock :: (Instruction -> Instruction) -> [Instruction] -> [Instruction]
|
||||||
mapBlock = map
|
mapBlock = map
|
||||||
|
|
||||||
@ -137,7 +139,31 @@ mapRoutines f (rout:routs) =
|
|||||||
(mapRoutine f rout):(mapRoutines f routs)
|
(mapRoutine f rout):(mapRoutines f routs)
|
||||||
|
|
||||||
mapProgramRoutines :: (Instruction -> Instruction) -> Program -> Program
|
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 (Program decls _) name =
|
||||||
lookupDecl' (filter (isLocationDecl) decls) name
|
lookupDecl' (filter (isLocationDecl) decls) name
|
||||||
|
Loading…
x
Reference in New Issue
Block a user