git @ Cat's Eye Technologies SixtyPical / 24f093b
Make all serialize() methods take addr() as an arg, not kwarg. Chris Pressey 3 years ago
3 changed file(s) with 36 addition(s) and 36 deletion(s). Raw diff Collapse all Expand all
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.
112112 if options.output_format in ('prg', 'c64-basic-prg', 'vic20-basic-prg'):
113 fh.write(bytearray(Word(start_addr).serialize()))
113 fh.write(bytearray(Word(start_addr).serialize(0)))
114114
115115 emitter = Emitter(start_addr)
116116 for byte in prelude:
77 raise NotImplementedError
88
99 def serialize(self, addr):
10 """Should return an array of unsigned bytes (integers from 0 to 255.)"""
10 """Should return an array of unsigned bytes (integers from 0 to 255.)
11 `addr` is the address the value is being serialized at; for most objects
12 it makes no difference, but some objects (like relative branches) do care."""
1113 raise NotImplementedError
1214
1315
2426 def size(self):
2527 return 1
2628
27 def serialize(self, addr=None):
29 def serialize(self, addr):
2830 return [self.value]
2931
3032 def __repr__(self):
3941 def size(self):
4042 return 2
4143
42 def serialize(self, addr=None):
44 def serialize(self, addr):
4345 word = self.value
4446 low = word & 255
4547 high = (word >> 8) & 255
5961 def size(self):
6062 return self._size
6163
62 def serialize(self, addr=None):
64 def serialize(self, addr):
6365 buf = []
6466 for emittable in self.value:
65 buf.extend(emittable.serialize())
67 buf.extend(emittable.serialize(addr)) # FIXME: addr + offset
6668 while len(buf) < self.size():
6769 buf.append(0)
6870 return buf
8688 def size(self):
8789 return 2
8890
89 def serialize(self, addr=None, offset=0):
91 def serialize(self, addr, offset=0):
9092 assert self.addr is not None, "unresolved label: %s" % self.name
91 return Word(self.addr + offset).serialize()
93 return Word(self.addr + offset).serialize(addr)
9294
9395 def serialize_relative_to(self, addr):
9496 assert self.addr is not None, "unresolved label: %s" % self.name
95 return Byte(self.addr - (addr + 2)).serialize()
96
97 def serialize_as_zero_page(self, offset=0):
97 return Byte(self.addr - (addr + 2)).serialize(addr)
98
99 def serialize_as_zero_page(self, addr, offset=0):
98100 assert self.addr is not None, "unresolved label: %s" % self.name
99 return Byte(self.addr + offset).serialize()
101 return Byte(self.addr + offset).serialize(addr)
100102
101103 def __repr__(self):
102104 addr_s = ', addr=%r' % self.addr if self.addr is not None else ''
113115 def size(self):
114116 self.label.size()
115117
116 def serialize(self, addr=None):
117 return self.label.serialize(offset=self.offset)
118
119 def serialize_as_zero_page(self, offset=0):
120 return self.label.serialize_as_zero_page(offset=self.offset)
118 def serialize(self, addr):
119 return self.label.serialize(addr, offset=self.offset)
120
121 def serialize_as_zero_page(self, addr, offset=0):
122 return self.label.serialize_as_zero_page(addr, offset=self.offset)
121123
122124 def __repr__(self):
123125 return "%s(%r, %r)" % (self.__class__.__name__, self.label, self.offset)
131133 def size(self):
132134 return 1
133135
134 def serialize(self, addr=None):
135 return [self.label.serialize()[0]]
136 def serialize(self, addr):
137 return [self.label.serialize(addr)[0]]
136138
137139 def __repr__(self):
138140 return "%s(%r)" % (self.__class__.__name__, self.label)
146148 def size(self):
147149 return 1
148150
149 def serialize(self, addr=None):
150 return [self.label.serialize()[1]]
151 def serialize(self, addr):
152 return [self.label.serialize(addr)[1]]
151153
152154 def __repr__(self):
153155 return "%s(%r)" % (self.__class__.__name__, self.label)
77 """Size of the operand for the mode (not including the opcode)"""
88 raise NotImplementedError
99
10 def serialize(self, addr=None):
10 def serialize(self, addr):
1111 raise NotImplementedError
1212
1313 def __repr__(self):
1818 def size(self):
1919 return 0
2020
21 def serialize(self, addr=None):
21 def serialize(self, addr):
2222 return []
2323
2424 def __repr__(self):
3333 def size(self):
3434 return 1
3535
36 def serialize(self, addr=None):
37 return self.value.serialize()
36 def serialize(self, addr):
37 return self.value.serialize(addr)
3838
3939
4040 class Absolute(AddressingMode):
4545 def size(self):
4646 return 2
4747
48 def serialize(self, addr=None):
49 return self.value.serialize()
48 def serialize(self, addr):
49 return self.value.serialize(addr)
5050
5151
5252 class AbsoluteX(Absolute):
6565 def size(self):
6666 return 1
6767
68 def serialize(self, addr=None):
69 return self.value.serialize_as_zero_page()
68 def serialize(self, addr):
69 return self.value.serialize_as_zero_page(addr)
7070
7171
7272 class Indirect(AddressingMode):
7777 def size(self):
7878 return 2
7979
80 def serialize(self, addr=None):
81 return self.value.serialize()
80 def serialize(self, addr):
81 return self.value.serialize(addr)
8282
8383
8484 class IndirectY(ZeroPage):
9393 def size(self):
9494 return 1
9595
96 def serialize(self, addr=None):
96 def serialize(self, addr):
9797 return self.value.serialize_relative_to(addr)
9898
9999
107107 def size(self):
108108 return 1 + self.operand.size() if self.operand else 0
109109
110 def serialize(self, addr=None):
111 serialized_operand = self.operand.serialize(addr)
112 assert isinstance(serialized_operand, list), self.operand.__class__
113 return [self.opcodes[self.operand.__class__]] + serialized_operand
110 def serialize(self, addr):
111 return [self.opcodes[self.operand.__class__]] + self.operand.serialize(addr)
114112
115113 def __repr__(self):
116114 return "%s(%r)" % (self.__class__.__name__, self.operand)