git @ Cat's Eye Technologies SixtyPical / eadf1eb
A `byte` or `word` table can be initialized with a list of constants. Chris Pressey 3 years ago
5 changed file(s) with 36 addition(s) and 16 deletion(s). Raw diff Collapse all Expand all
55
66 * Symbolic constants can be defined with the `const` keyword, and can
77 be used in most places where literal values can be used.
8 * Added `nop` opcode, which compiles to `NOP` (mainly for timing.)
9 * Accessing zero-page with `ld` and `st` generates zero-page opcodes.
10 * A `byte` or `word` table can be initialized with a list of constants.
811 * Specifying multiple SixtyPical source files will produce a single
912 compiled result from their combination.
10 * Added `nop` opcode, which compiles to `NOP` (mainly for timing.)
11 * Accessing zero-page with `ld` and `st` generates zero-page opcodes.
1213 * Rudimentary support for Atari 2600 prelude in a 4K cartridge image,
1314 and start of an example program in `eg/atari2600` directory.
1415
121121 elif type_ == TYPE_WORD:
122122 initial_data = Word(defn.initial)
123123 elif TableType.is_a_table_type(type_, TYPE_BYTE):
124 # FIXME convert defn.initial to a serializable type ... or when parsing.
125 initial_data = Table(defn.initial, type_.size)
124 initial_data = Table([Byte(i) for i in defn.initial], type_.size)
125 elif TableType.is_a_table_type(type_, TYPE_WORD):
126 initial_data = Table([Word(i) for i in defn.initial], type_.size)
126127 else:
127128 raise NotImplementedError(type_)
128129 label.set_length(initial_data.size())
1212
1313 class Byte(Emittable):
1414 def __init__(self, value):
15 if isinstance(value, basestring):
16 value = ord(value)
1517 if value < -127 or value > 255:
1618 raise IndexError(value)
1719 if value < 0:
4850
4951 class Table(Emittable):
5052 def __init__(self, value, size):
53 """`value` should be an iterable of Emittables."""
5154 # TODO: range-checking
5255 self.value = value
5356 self._size = size
5659 return self._size
5760
5861 def serialize(self, addr=None):
59 bytes = []
60 for b in self.value:
61 bytes.append(chr(ord(b)))
62 while len(bytes) < self.size():
63 bytes.append(chr(0))
64 return ''.join(bytes)
62 buf = ''.join([emittable.serialize() for emittable in self.value])
63 while len(buf) < self.size():
64 buf += chr(0)
65 return buf
6566
6667 def __repr__(self):
6768 return "%s()" % (self.__class__.__name__)
143143 self.scanner.scan()
144144 else:
145145 initial = []
146 initial.append(self.const())
146 initial.append(self.const().value)
147147 while self.scanner.consume(','):
148 initial.append(self.const())
148 initial.append(self.const().value)
149149 else:
150150 initial = self.const().value
151151
197197 = $080D LDX #$00
198198 = $080F LDA $0813,X
199199 = $0812 RTS
200 = $0813 .byte $57
201 = $0814 PHA
202 = $0815 EOR ($54,X)
203 = $0817 .byte $3F
200 = $0813 .byte $FF
201 = $0814 BRK
202 = $0815 STA ($80,X)
203 = $0817 .byte $7F
204204 = $0818 BRK
205205 = $0819 BRK
206206 = $081A BRK
207
208 Initialized word table, initialized with list of word values.
209
210 | word table[8] message : 65535, 0, 127
211 |
212 | routine main
213 | {
214 | }
215 = $080D RTS
216 = $080E .byte $FF
217 = $080F .byte $FF
218 = $0810 BRK
219 = $0811 BRK
220 = $0812 .byte $7F
221 = $0813 BRK
222 = $0814 BRK
223 = $0815 BRK
207224
208225 Some instructions.
209226