git @ Cat's Eye Technologies SixtyPical / 69df175
Merge branch 'develop-0.18' of https://github.com/catseye/SixtyPical into inconsistent-initialization Chris Pressey 2 years ago
8 changed file(s) with 174 addition(s) and 29 deletion(s). Raw diff Collapse all Expand all
1212 * When the range of a location is known, `inc` and `dec`
1313 on it will usually shift the known instead of invalidating it.
1414 * `cmp` instruction can now perform a 16-bit unsigned comparison
15 of `word` memory locations (at the cost of trashing `a`.)
15 of `word` memory locations and `word` literals (at the cost of
16 trashing the `a` register.)
1617 * Fixed pathological memory use in the lexical scanner - should
1718 be much less inefficient now when parsing large source files.
1819 * Reorganized the examples in `eg/rudiments/` to make them
0 // Include `support/${PLATFORM}.60p` before this source
1 // Should print ENGGL
2
3 word w1
4
5 define main routine
6 outputs w1
7 trashes a, x, y, z, n, c, v
8 {
9 copy 4000, w1
10
11 cmp w1, 4000
12 if z {
13 ld a, 69 // E
14 call chrout
15 } else {
16 ld a, 78 // N
17 call chrout
18 }
19
20 copy 4000, w1
21
22 cmp w1, 4001
23 if z {
24 ld a, 69 // E
25 call chrout
26 } else {
27 ld a, 78 // N
28 call chrout
29 }
30
31 copy 20002, w1
32
33 cmp w1, 20001 // 20002 >= 20001
34 if c {
35 ld a, 71 // G
36 call chrout
37 } else {
38 ld a, 76 // L
39 call chrout
40 }
41
42 copy 20001, w1
43
44 cmp w1, 20001 // 20001 >= 20001
45 if c {
46 ld a, 71 // G
47 call chrout
48 } else {
49 ld a, 76 // L
50 call chrout
51 }
52
53 copy 20000, w1
54
55 cmp w1, 20001 // 20000 < 20001
56 if c {
57 ld a, 71 // G
58 call chrout
59 } else {
60 ld a, 76 // L
61 call chrout
62 }
63 }
00 byte lives
11
2 byte table[16] hexchars : "0123456789ABCDEF"
3
4 define prbyte routine
5 inputs a, hexchars
6 trashes a, z, n, c, v
7 {
8 save x {
9 save a {
10 st off, c
11 shr a
12 shr a
13 shr a
14 shr a
15 and a, 15
16 ld x, a
17 ld a, hexchars + x
18 call chrout
19 }
20 save a {
21 and a, 15
22 ld x, a
23 ld a, hexchars + x
24 call chrout
25 }
26 }
27 }
28
229 define main routine
3 inputs lives
30 inputs lives, hexchars
431 outputs lives
532 trashes a, x, z, n, c, v
6 {
7 ld a, 0
8 st a, lives
9 ld x, lives
10 st off, c
11 add x, 1
12 st x, lives
13 }
33 {
34 ld a, 0
35 st a, lives
36 ld x, lives
37 st off, c
38 inc x
39 st x, lives
40 ld a, lives
41 call prbyte
42 }
+0
-12
eg/rudiments/if.60p less more
0 define main routine
1 inputs a
2 outputs a
3 trashes z, n, c
4 {
5 cmp a, 42
6 if z {
7 ld a, 7
8 } else {
9 ld a, 23
10 }
11 }
0 // Include `support/${PLATFORM}.60p` before this source
1 // Should print YY
2
03 word one
14 word table[256] many
25
36 define main routine
47 inputs one, many
58 outputs one, many
6 trashes a, x, y, n, z
9 trashes a, x, y, c, n, z
710 {
811 ld x, 0
9 ld y, 0
12 ld y, 1
1013 copy 777, one
1114 copy one, many + x
15 copy 888, one
1216 copy one, many + y
17
18 ld x, 1
19 ld y, 0
20
1321 copy many + x, one
22 cmp one, 888
23 if z {
24 ld a, 89
25 call chrout
26 } else {
27 ld a, 78
28 call chrout
29 }
30
1431 copy many + y, one
32 cmp one, 777
33 if z {
34 ld a, 89
35 call chrout
36 } else {
37 ld a, 78
38 call chrout
39 }
1540 }
399399 self.emitter.emit(BNE(Relative(end_label)))
400400 self.emitter.emit(LDA(Absolute(Offset(dest_label, 1))))
401401 self.emitter.emit(CMP(Absolute(Offset(src_label, 1))))
402 self.emitter.resolve_label(end_label)
403 return
404 if isinstance(src, ConstantRef) and src.type == TYPE_WORD:
405 dest_label = self.get_label(dest.name)
406 self.emitter.emit(LDA(Absolute(dest_label)))
407 self.emitter.emit(CMP(Immediate(Byte(src.low_byte()))))
408 end_label = Label('end_label')
409 self.emitter.emit(BNE(Relative(end_label)))
410 self.emitter.emit(LDA(Absolute(Offset(dest_label, 1))))
411 self.emitter.emit(CMP(Immediate(Byte(src.high_byte()))))
402412 self.emitter.resolve_label(end_label)
403413 return
404414 cls = {
12051205 | cmp za, zb
12061206 | }
12071207 ? UnmeaningfulReadError: zb
1208
1209 `cmp` can compare against a literal word.
1210
1211 | word za
1212 |
1213 | define main routine
1214 | inputs za
1215 | trashes a, z, c, n
1216 | {
1217 | cmp za, 4000
1218 | }
1219 = ok
1220
1221 | word za
1222 |
1223 | define main routine
1224 | inputs za
1225 | trashes z, c, n
1226 | {
1227 | cmp za, 4000
1228 | }
1229 ? ForbiddenWriteError: a
12081230
12091231 ### and ###
12101232
394394 | trashes a, z, c, n
395395 | {
396396 | cmp za, zb
397 | cmp za, 4000
397398 | }
398399 = $080D LDA $EA61
399 = $0810 CMP $081C
400 = $0810 CMP $0828
400401 = $0813 BNE $081B
401402 = $0815 LDA $EA62
402 = $0818 CMP $081D
403 = $081B RTS
404 = $081C .byte $BB
405 = $081D .byte $0B
403 = $0818 CMP $0829
404 = $081B LDA $EA61
405 = $081E CMP #$A0
406 = $0820 BNE $0827
407 = $0822 LDA $EA62
408 = $0825 CMP #$0F
409 = $0827 RTS
410 = $0828 .byte $BB
411 = $0829 .byte $0B
406412
407413 Compiling `if`.
408414