git @ Cat's Eye Technologies SixtyPical / af7d65e
Fix example programs; allow externals to be called. --HG-- rename : eg/hi.60p => eg/hello-world.60p Cat's Eye Technologies 8 years ago
9 changed file(s) with 71 addition(s) and 37 deletion(s). Raw diff Collapse all Expand all
265265 = .space _temp_4 2
266266 = .space _temp_1 1
267267 = .space _temp_2 2
268
269 Declaring and calling an external routine.
270
271 | external chrout 65490
272 | routine main {
273 | lda #72
274 | jsr chrout
275 | lda #73
276 | jsr chrout
277 | lda #13
278 | jsr chrout
279 | }
280 = main:
281 = lda #72
282 = jsr chrout
283 = lda #73
284 = jsr chrout
285 = lda #13
286 = jsr chrout
287 = rts
288 =
289 = .data
290 = .alias chrout 65490
291
0 assign byte table screen $0400
1 assign byte table screen2 1274
2 assign byte table screen3 1524
3 assign byte table screen4 1774
0 assign byte[256] screen $0400
1 assign byte[256] screen2 1274
2 assign byte[256] screen3 1524
3 assign byte[256] screen4 1774
44
5 assign byte table colormap 55296
6 assign byte table colormap2 55546
7 assign byte table colormap3 55796
8 assign byte table colormap4 56046
5 assign byte[256] colormap 55296
6 assign byte[256] colormap2 55546
7 assign byte[256] colormap3 55796
8 assign byte[256] colormap4 56046
99
1010 assign byte vic_border 53280
11 assign byte table vic_bg 53281
11 assign byte[4] vic_bg 53281
1212
1313 assign vector cinv 788
1414 reserve vector save_cinv
0 assign byte table screen $0400
1 assign byte table screen2 1274
2 assign byte table screen3 1524
3 assign byte table screen4 1774
0 assign byte[256] screen $0400
1 assign byte[256] screen2 1274
2 assign byte[256] screen3 1524
3 assign byte[256] screen4 1774
44
5 assign byte table colormap 55296
6 assign byte table colormap2 55546
7 assign byte table colormap3 55796
8 assign byte table colormap4 56046
5 assign byte[256] colormap 55296
6 assign byte[256] colormap2 55546
7 assign byte[256] colormap3 55796
8 assign byte[256] colormap4 56046
99
1010 assign byte vic_border 53280
11 assign byte table vic_bg 53281
11 assign byte[4] vic_bg 53281
1212
1313 assign byte joy2 $dc00
1414
0 reserve byte[13] message: "HELLO, WORLD!"
1 external chrout 65490
2 routine main {
3 ldy #0
4 repeat bne {
5 lda message, y
6 jsr chrout
7 iny
8 cpy #13
9 }
10 lda #13
11 jsr chrout
12 }
+0
-9
eg/hi.60p less more
0 external chrout 65490
1 routine main {
2 lda #72
3 jsr chrout
4 lda #73
5 jsr chrout
6 lda #13
7 jsr chrout
8 }
0 assign byte table screen 1024
0 assign byte[256] screen 1024
11 reserve byte value
22 routine main {
33 lda #0
5252 updateRoutCtx nm dst (UpdatedWith src) routCtx
5353
5454 checkInstr nm (JSR name) progCtx routCtx =
55 let
56 Just calledRout = lookupRoutine program name
57 in
58 case Map.lookup name progCtx of
59 Just calledRoutCtx ->
60 mergeRoutCtxs nm routCtx calledRoutCtx calledRout
61 Nothing ->
62 error ("can't call routine '" ++ name ++ "' before it is defined")
55 case lookupRoutine program name of
56 Just calledRout ->
57 case Map.lookup name progCtx of
58 Just calledRoutCtx ->
59 mergeRoutCtxs nm routCtx calledRoutCtx calledRout
60 Nothing ->
61 error ("can't call routine '" ++ name ++ "' before it is defined")
62 Nothing ->
63 -- it must be an external.
64 -- TODO: merge in any poisoning/outputs that are declared
65 -- on the external. for now,
66 routCtx
67
6368 checkInstr nm (CMP reg addr) progCtx routCtx =
6469 -- TODO: mark Carry bit as "touched" here
6570 routCtx
6868 checkAndTransformProgram :: Program -> Maybe Program
6969 checkAndTransformProgram program =
7070 if
71 trueOrDie "missing 'main' routine" (routineDeclared "main" program) &&
71 trueOrDie ("missing 'main' routine: " ++ show program) (routineDeclared "main" program) &&
7272 trueOrDie "duplicate location name" (noDuplicateDecls program) &&
7373 trueOrDie "duplicate routine name" (noDuplicateRoutines program) &&
7474 trueOrDie "undeclared routine" (noUseOfUndeclaredRoutines program) &&
110110 isInitializedDecl (Assign _ _ _) = False
111111 isInitializedDecl (Reserve _ _ (v:vs)) = True
112112 isInitializedDecl (Reserve _ _ []) = False
113 isInitializedDecl _ = False
113114
114115 declaredLocationNames (Program decls _) =
115116 map (getDeclLocationName) (filter (isLocationDecl) decls)