Merge branch 'develop-0.16' of https://github.com/catseye/SixtyPical into save-block
Chris Pressey
4 years ago
3 | 3 | 0.16 |
4 | 4 | ---- |
5 | 5 | |
6 | * Removed `--prelude` in favour of specifying both format and prelude | |
7 | with a single option, `--output-format`. Documentation for same. | |
6 | 8 | * `or a, z`, `and a, z`, and `eor a, z` compile to zero-page operations |
7 | 9 | if the address of z < 256. |
8 | 10 | * More thorough tests and justifications written for the case of |
66 | 66 | * [Literate test suite for SixtyPical compilation](tests/SixtyPical%20Compilation.md) |
67 | 67 | * [Literate test suite for SixtyPical fallthru optimization](tests/SixtyPical%20Fallthru.md) |
68 | 68 | * [6502 Opcodes used/not used in SixtyPical](doc/6502%20Opcodes.md) |
69 | * [Output formats supported by `sixtypical`](doc/Output%20Formats.md) | |
69 | 70 | |
70 | 71 | TODO |
71 | 72 | ---- |
80 | 80 | |
81 | 81 | fh = sys.stdout |
82 | 82 | |
83 | if options.origin.startswith('0x'): | |
84 | start_addr = int(options.origin, 16) | |
85 | else: | |
86 | start_addr = int(options.origin, 10) | |
87 | ||
88 | output_format = options.output_format | |
89 | ||
90 | prelude = [] | |
91 | if options.prelude == 'c64': | |
92 | output_format = 'prg' | |
83 | if options.output_format == 'raw': | |
84 | start_addr = 0x0000 | |
85 | prelude = [] | |
86 | elif options.output_format == 'prg': | |
87 | start_addr = 0xc000 | |
88 | prelude = [] | |
89 | elif options.output_format == 'c64-basic-prg': | |
93 | 90 | start_addr = 0x0801 |
94 | 91 | prelude = [0x10, 0x08, 0xc9, 0x07, 0x9e, 0x32, |
95 | 92 | 0x30, 0x36, 0x31, 0x00, 0x00, 0x00] |
96 | elif options.prelude == 'vic20': | |
97 | output_format = 'prg' | |
93 | elif options.output_format == 'vic20-basic-prg': | |
98 | 94 | start_addr = 0x1001 |
99 | 95 | prelude = [0x0b, 0x10, 0xc9, 0x07, 0x9e, 0x34, |
100 | 96 | 0x31, 0x30, 0x39, 0x00, 0x00, 0x00] |
101 | elif options.prelude == 'atari2600': | |
102 | output_format = 'crtbb' | |
97 | elif options.output_format == 'atari2600-cart': | |
103 | 98 | start_addr = 0xf000 |
104 | 99 | prelude = [0x78, 0xd8, 0xa2, 0xff, 0x9a, 0xa9, |
105 | 0x00,0x95, 0x00, 0xca, 0xd0, 0xfb] | |
100 | 0x00, 0x95, 0x00, 0xca, 0xd0, 0xfb] | |
101 | else: | |
102 | raise NotImplementedError("Unknown output format: {}".format(options.output_format)) | |
106 | 103 | |
107 | elif options.prelude: | |
108 | raise NotImplementedError("Unknown prelude: {}".format(options.prelude)) | |
104 | if options.origin is not None: | |
105 | if options.origin.startswith('0x'): | |
106 | start_addr = int(options.origin, 16) | |
107 | else: | |
108 | start_addr = int(options.origin, 10) | |
109 | 109 | |
110 | 110 | # If we are outputting a .PRG, we output the load address first. |
111 | 111 | # We don't use the Emitter for this b/c not part of addr space. |
112 | if output_format == 'prg': | |
112 | if options.output_format in ('prg', 'c64-basic-prg', 'vic20-basic-prg'): | |
113 | 113 | fh.write(Word(start_addr).serialize(0)) |
114 | 114 | |
115 | 115 | emitter = Emitter(start_addr) |
120 | 120 | |
121 | 121 | # If we are outputting a cartridge with boot and BRK address |
122 | 122 | # at the end, pad to ROM size minus 4 bytes, and emit addresses. |
123 | if output_format == 'crtbb': | |
123 | if options.output_format == 'atari2600-cart': | |
124 | 124 | emitter.pad_to_size(4096 - 4) |
125 | 125 | emitter.emit(Word(start_addr)) |
126 | 126 | emitter.emit(Word(start_addr)) |
140 | 140 | ) |
141 | 141 | |
142 | 142 | argparser.add_argument( |
143 | "--origin", type=str, default='0xc000', | |
143 | "--origin", type=str, default=None, | |
144 | 144 | help="Location in memory where the `main` routine will be " |
145 | "located. Default: 0xc000." | |
145 | "located. Default: depends on output format." | |
146 | 146 | ) |
147 | 147 | argparser.add_argument( |
148 | "--output-format", type=str, default='prg', | |
149 | help="Executable format to produce. Options are: prg, crtbb. " | |
150 | "Default: prg." | |
151 | ) | |
152 | argparser.add_argument( | |
153 | "--prelude", type=str, | |
154 | help="Insert a snippet of code before the compiled program so that " | |
155 | "it can be booted automatically on a particular platform. " | |
156 | "Also sets the origin and format. " | |
157 | "Options are: c64, vic20, atari2600." | |
148 | "--output-format", type=str, default='raw', | |
149 | help="Executable format to produce; also sets a default origin. " | |
150 | "Options are: raw, prg, c64-basic-prg, vic20-basic-prg, atari2600-cart." | |
151 | "Default: raw." | |
158 | 152 | ) |
159 | 153 | |
160 | 154 | argparser.add_argument( |
0 | Output Formats | |
1 | ============== | |
2 | ||
3 | `sixtypical` can generate an output file in a number of formats. | |
4 | ||
5 | ### `raw` | |
6 | ||
7 | The file contains only the emitted bytes of the compiled SixtyPical | |
8 | program. | |
9 | ||
10 | The default origin is $0000; it is not unlikely you will want to | |
11 | override this. | |
12 | ||
13 | Note that the origin is not stored in the output file in this format; | |
14 | that information must be recorded separately. | |
15 | ||
16 | ### `prg` | |
17 | ||
18 | The first two bytes of the file contain the origin address in | |
19 | little-endian format. The remainder of the file is the emitted bytes | |
20 | of the compiled SixtyPical program, starting at that origin. | |
21 | ||
22 | The default origin is $C000; it is likely you will want to | |
23 | override this. | |
24 | ||
25 | This format coincides with Commodore's PRG format for disk files, | |
26 | thus its name. | |
27 | ||
28 | ### `c64-basic-prg` | |
29 | ||
30 | The first few bytes of the file contain a short Commodore 2.0 BASIC | |
31 | program. Directly after this is the emitted bytes of the compiled | |
32 | SixtyPical program. The BASIC program contains a `SYS` to that code. | |
33 | ||
34 | The default origin is $0801; it is unlikely that you will want to | |
35 | override this. | |
36 | ||
37 | This format allows the PRG file to be loaded and run on a Commodore 64 | |
38 | with | |
39 | ||
40 | LOAD"FOO.PRG",8:RUN | |
41 | ||
42 | ### `vic20-basic-prg` | |
43 | ||
44 | Exactly like `--c64-basic-prg` except intended for the Commodore VIC-20. | |
45 | ||
46 | The default origin is $1001; it is unlikely that you will want to | |
47 | override this. | |
48 | ||
49 | This format allows the PRG file to be loaded and run on a VIC-20 with | |
50 | ||
51 | LOAD"FOO.PRG",8:RUN | |
52 | ||
53 | ### `atari2600-cart` | |
54 | ||
55 | The file starts with a short machine-language prelude which is intended | |
56 | to initialize an Atari 2600 system, followed by the emitted bytes of the | |
57 | compiled SixtyPical program. | |
58 | ||
59 | The file is padded to 4096 bytes in length. The padding is mostly | |
60 | zeroes, except for the final 4 bytes of the file, which consist of | |
61 | two addresses in little-endian format; both are the origin address. | |
62 | ||
63 | The default origin is $F000; it is unlikely you will want to | |
64 | override this. | |
65 | ||
66 | This is the format used by Atari 2600 cartridges. |
6 | 6 | [Falderal]: http://catseye.tc/node/Falderal |
7 | 7 | |
8 | 8 | -> Functionality "Compile SixtyPical program" is implemented by |
9 | -> shell command "bin/sixtypical --prelude=c64 --traceback %(test-body-file) >/tmp/foo && tests/appliances/bin/dcc6502-adapter </tmp/foo" | |
9 | -> shell command "bin/sixtypical --output-format=c64-basic-prg --traceback %(test-body-file) >/tmp/foo && tests/appliances/bin/dcc6502-adapter </tmp/foo" | |
10 | 10 | |
11 | 11 | -> Tests for functionality "Compile SixtyPical program" |
12 | 12 |
64 | 64 | -> shell command "bin/sixtypical --optimize-fallthru --dump-fallthru-info --analyze-only --traceback %(test-body-file)" |
65 | 65 | |
66 | 66 | -> Functionality "Compile SixtyPical program with fallthru optimization" is implemented by |
67 | -> shell command "bin/sixtypical --prelude=c64 --optimize-fallthru --traceback %(test-body-file) >/tmp/foo && tests/appliances/bin/dcc6502-adapter </tmp/foo" | |
67 | -> shell command "bin/sixtypical --output-format=c64-basic-prg --optimize-fallthru --traceback %(test-body-file) >/tmp/foo && tests/appliances/bin/dcc6502-adapter </tmp/foo" | |
68 | 68 | |
69 | 69 | -> Tests for functionality "Dump fallthru info for SixtyPical program" |
70 | 70 |