git @ Cat's Eye Technologies SixtyPical / b1e9df0
Add --output-format and --origin command-line options. Chris Pressey 5 years ago
2 changed file(s) with 33 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
00 History of SixtyPical
11 =====================
2
3 0.14
4 ----
5
6 * `--origin` and `--output-format` options added to reference compiler.
7 * Fixed bug when `--prelude` option was missing.
8 * Fixed bug when reporting line numbers of scanner-level syntax errors.
29
310 0.13
411 ----
3636 help="Only parse and analyze the program; do not compile it."
3737 )
3838 argparser.add_argument(
39 "--origin", type=str, default='0xc000',
40 help="Location in memory where the `main` routine will be "
41 "located. Default: 0xc000."
42 )
43 argparser.add_argument(
44 "--output-format", type=str, default='prg',
45 help="Executable format to produce. Options are: prg (.PRG file "
46 "for Commodore 8-bit). Default: prg."
47 )
48 argparser.add_argument(
3949 "--prelude", type=str,
4050 help="Insert a snippet before the compiled program "
4151 "so that it can be LOADed and RUN on a certain platforms. "
42 "Also sets the origin. "
52 "Also sets the origin and format. "
4353 "Options are: c64 or vic20."
4454 )
4555 argparser.add_argument(
91101 sys.exit(0)
92102
93103 fh = sys.stdout
94 start_addr = 0xc000
104
105 if options.origin.startswith('0x'):
106 start_addr = int(options.origin, 16)
107 else:
108 start_addr = int(options.origin, 10)
109
110 output_format = options.output_format
111
95112 prelude = []
96113 if options.prelude == 'c64':
114 output_format = 'prg'
97115 start_addr = 0x0801
98116 prelude = [0x10, 0x08, 0xc9, 0x07, 0x9e, 0x32,
99117 0x30, 0x36, 0x31, 0x00, 0x00, 0x00]
100118 elif options.prelude == 'vic20':
119 output_format = 'prg'
101120 start_addr = 0x1001
102121 prelude = [0x0b, 0x10, 0xc9, 0x07, 0x9e, 0x34,
103122 0x31, 0x30, 0x39, 0x00, 0x00, 0x00]
104 else:
105 raise NotImplementedError
123 elif options.prelude:
124 raise NotImplementedError("Unknown prelude: {}".format(options.prelude))
106125
107 # we are outputting a .PRG, so we output the load address first
108 # we don't use the Emitter for this b/c not part of addr space
109 if not options.debug:
126 # If we are outputting a .PRG, we output the load address first.
127 # We don't use the Emitter for this b/c not part of addr space.
128 if output_format == 'prg':
110129 fh.write(Word(start_addr).serialize(0))
111130
112131 emitter = Emitter(start_addr)