git @ Cat's Eye Technologies SixtyPical / 89fa836
Remove --prelude, reform and document --output-formats. Chris Pressey 3 years ago
7 changed file(s) with 98 addition(s) and 34 deletion(s). Raw diff Collapse all Expand all
33 0.16
44 ----
55
6 * Removed `--prelude` in favour of specifying both format and prelude
7 with a single option, `--output-format`. Documentation for same.
68 * `or a, z`, `and a, z`, and `eor a, z` compile to zero-page operations
79 if the address of z < 256.
810 * More thorough tests and justifications written for the case of
6666 * [Literate test suite for SixtyPical compilation](tests/SixtyPical%20Compilation.md)
6767 * [Literate test suite for SixtyPical fallthru optimization](tests/SixtyPical%20Fallthru.md)
6868 * [6502 Opcodes used/not used in SixtyPical](doc/6502%20Opcodes.md)
69 * [Output formats supported by `sixtypical`](doc/Output%20Formats.md)
6970
7071 TODO
7172 ----
8080
8181 fh = sys.stdout
8282
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':
9390 start_addr = 0x0801
9491 prelude = [0x10, 0x08, 0xc9, 0x07, 0x9e, 0x32,
9592 0x30, 0x36, 0x31, 0x00, 0x00, 0x00]
96 elif options.prelude == 'vic20':
97 output_format = 'prg'
93 elif options.output_format == 'vic20-basic-prg':
9894 start_addr = 0x1001
9995 prelude = [0x0b, 0x10, 0xc9, 0x07, 0x9e, 0x34,
10096 0x31, 0x30, 0x39, 0x00, 0x00, 0x00]
101 elif options.prelude == 'atari2600':
102 output_format = 'crtbb'
97 elif options.output_format == 'atari2600-cart':
10398 start_addr = 0xf000
10499 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))
106103
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)
109109
110110 # If we are outputting a .PRG, we output the load address first.
111111 # 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'):
113113 fh.write(Word(start_addr).serialize(0))
114114
115115 emitter = Emitter(start_addr)
120120
121121 # If we are outputting a cartridge with boot and BRK address
122122 # 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':
124124 emitter.pad_to_size(4096 - 4)
125125 emitter.emit(Word(start_addr))
126126 emitter.emit(Word(start_addr))
140140 )
141141
142142 argparser.add_argument(
143 "--origin", type=str, default='0xc000',
143 "--origin", type=str, default=None,
144144 help="Location in memory where the `main` routine will be "
145 "located. Default: 0xc000."
145 "located. Default: depends on output format."
146146 )
147147 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."
158152 )
159153
160154 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.
66 [Falderal]: http://catseye.tc/node/Falderal
77
88 -> 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"
1010
1111 -> Tests for functionality "Compile SixtyPical program"
1212
6464 -> shell command "bin/sixtypical --optimize-fallthru --dump-fallthru-info --analyze-only --traceback %(test-body-file)"
6565
6666 -> 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"
6868
6969 -> Tests for functionality "Dump fallthru info for SixtyPical program"
7070
00 #!/usr/bin/env python
11
2 # script that allows the binary output of sixtypical --prelude=c64 --compile to be
2 # script that allows the binary output of sixtypical --output-format=c64-basic-prg --compile to be
33 # disassembled by https://github.com/tcarmelveilleux/dcc6502
44
55 import sys