1
0
mirror of https://github.com/catseye/SixtyPical.git synced 2024-11-22 17:32:01 +00:00

Fix example programs; allow externals to be called.

--HG--
rename : eg/hi.60p => eg/hello-world.60p
This commit is contained in:
Cat's Eye Technologies 2014-04-12 19:13:13 +01:00
parent ad1e159317
commit af7d65ee09
9 changed files with 71 additions and 37 deletions

View File

@ -266,3 +266,27 @@ temporaries are not unioned yet, but they could be.
= .space _temp_4 2
= .space _temp_1 1
= .space _temp_2 2
Declaring and calling an external routine.
| external chrout 65490
| routine main {
| lda #72
| jsr chrout
| lda #73
| jsr chrout
| lda #13
| jsr chrout
| }
= main:
= lda #72
= jsr chrout
= lda #73
= jsr chrout
= lda #13
= jsr chrout
= rts
=
= .data
= .alias chrout 65490

View File

@ -1,15 +1,15 @@
assign byte table screen $0400
assign byte table screen2 1274
assign byte table screen3 1524
assign byte table screen4 1774
assign byte[256] screen $0400
assign byte[256] screen2 1274
assign byte[256] screen3 1524
assign byte[256] screen4 1774
assign byte table colormap 55296
assign byte table colormap2 55546
assign byte table colormap3 55796
assign byte table colormap4 56046
assign byte[256] colormap 55296
assign byte[256] colormap2 55546
assign byte[256] colormap3 55796
assign byte[256] colormap4 56046
assign byte vic_border 53280
assign byte table vic_bg 53281
assign byte[4] vic_bg 53281
assign vector cinv 788
reserve vector save_cinv

View File

@ -1,15 +1,15 @@
assign byte table screen $0400
assign byte table screen2 1274
assign byte table screen3 1524
assign byte table screen4 1774
assign byte[256] screen $0400
assign byte[256] screen2 1274
assign byte[256] screen3 1524
assign byte[256] screen4 1774
assign byte table colormap 55296
assign byte table colormap2 55546
assign byte table colormap3 55796
assign byte table colormap4 56046
assign byte[256] colormap 55296
assign byte[256] colormap2 55546
assign byte[256] colormap3 55796
assign byte[256] colormap4 56046
assign byte vic_border 53280
assign byte table vic_bg 53281
assign byte[4] vic_bg 53281
assign byte joy2 $dc00

13
eg/hello-world.60p Normal file
View File

@ -0,0 +1,13 @@
reserve byte[13] message: "HELLO, WORLD!"
external chrout 65490
routine main {
ldy #0
repeat bne {
lda message, y
jsr chrout
iny
cpy #13
}
lda #13
jsr chrout
}

View File

@ -1,9 +0,0 @@
external chrout 65490
routine main {
lda #72
jsr chrout
lda #73
jsr chrout
lda #13
jsr chrout
}

View File

@ -1,4 +1,4 @@
assign byte table screen 1024
assign byte[256] screen 1024
reserve byte value
routine main {
lda #0

View File

@ -53,14 +53,19 @@ analyzeProgram program@(Program decls routines) =
updateRoutCtx nm dst (UpdatedWith src) routCtx
checkInstr nm (JSR name) progCtx routCtx =
let
Just calledRout = lookupRoutine program name
in
case Map.lookup name progCtx of
Just calledRoutCtx ->
mergeRoutCtxs nm routCtx calledRoutCtx calledRout
Nothing ->
error ("can't call routine '" ++ name ++ "' before it is defined")
case lookupRoutine program name of
Just calledRout ->
case Map.lookup name progCtx of
Just calledRoutCtx ->
mergeRoutCtxs nm routCtx calledRoutCtx calledRout
Nothing ->
error ("can't call routine '" ++ name ++ "' before it is defined")
Nothing ->
-- it must be an external.
-- TODO: merge in any poisoning/outputs that are declared
-- on the external. for now,
routCtx
checkInstr nm (CMP reg addr) progCtx routCtx =
-- TODO: mark Carry bit as "touched" here
routCtx

View File

@ -69,7 +69,7 @@ consistentInitialTableSizes p@(Program decls routines) =
checkAndTransformProgram :: Program -> Maybe Program
checkAndTransformProgram program =
if
trueOrDie "missing 'main' routine" (routineDeclared "main" program) &&
trueOrDie ("missing 'main' routine: " ++ show program) (routineDeclared "main" program) &&
trueOrDie "duplicate location name" (noDuplicateDecls program) &&
trueOrDie "duplicate routine name" (noDuplicateRoutines program) &&
trueOrDie "undeclared routine" (noUseOfUndeclaredRoutines program) &&

View File

@ -111,6 +111,7 @@ isLocationDecl _ = False
isInitializedDecl (Assign _ _ _) = False
isInitializedDecl (Reserve _ _ (v:vs)) = True
isInitializedDecl (Reserve _ _ []) = False
isInitializedDecl _ = False
declaredLocationNames (Program decls _) =
map (getDeclLocationName) (filter (isLocationDecl) decls)