Merge branch 'develop-0.18' of https://github.com/catseye/SixtyPical into inconsistent-initialization
Chris Pressey
6 years ago
12 | 12 |
* When the range of a location is known, `inc` and `dec`
|
13 | 13 |
on it will usually shift the known instead of invalidating it.
|
14 | 14 |
* `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.)
|
16 | 17 |
* Fixed pathological memory use in the lexical scanner - should
|
17 | 18 |
be much less inefficient now when parsing large source files.
|
18 | 19 |
* 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 |
}
|
0 | 0 |
byte lives
|
1 | 1 |
|
|
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 |
|
2 | 29 |
define main routine
|
3 | |
inputs lives
|
|
30 |
inputs lives, hexchars
|
4 | 31 |
outputs lives
|
5 | 32 |
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 | |
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 |
|
0 | 3 |
word one
|
1 | 4 |
word table[256] many
|
2 | 5 |
|
3 | 6 |
define main routine
|
4 | 7 |
inputs one, many
|
5 | 8 |
outputs one, many
|
6 | |
trashes a, x, y, n, z
|
|
9 |
trashes a, x, y, c, n, z
|
7 | 10 |
{
|
8 | 11 |
ld x, 0
|
9 | |
ld y, 0
|
|
12 |
ld y, 1
|
10 | 13 |
copy 777, one
|
11 | 14 |
copy one, many + x
|
|
15 |
copy 888, one
|
12 | 16 |
copy one, many + y
|
|
17 |
|
|
18 |
ld x, 1
|
|
19 |
ld y, 0
|
|
20 |
|
13 | 21 |
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 |
|
14 | 31 |
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 |
}
|
15 | 40 |
}
|
399 | 399 |
self.emitter.emit(BNE(Relative(end_label)))
|
400 | 400 |
self.emitter.emit(LDA(Absolute(Offset(dest_label, 1))))
|
401 | 401 |
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()))))
|
402 | 412 |
self.emitter.resolve_label(end_label)
|
403 | 413 |
return
|
404 | 414 |
cls = {
|