mirror of
https://github.com/catseye/SixtyPical.git
synced 2025-01-07 12:29:52 +00:00
A byte
or word
table can be initialized with a list of constants.
This commit is contained in:
parent
2f513f7291
commit
eadf1eb4ae
@ -6,10 +6,11 @@ History of SixtyPical
|
||||
|
||||
* Symbolic constants can be defined with the `const` keyword, and can
|
||||
be used in most places where literal values can be used.
|
||||
* Specifying multiple SixtyPical source files will produce a single
|
||||
compiled result from their combination.
|
||||
* Added `nop` opcode, which compiles to `NOP` (mainly for timing.)
|
||||
* Accessing zero-page with `ld` and `st` generates zero-page opcodes.
|
||||
* A `byte` or `word` table can be initialized with a list of constants.
|
||||
* Specifying multiple SixtyPical source files will produce a single
|
||||
compiled result from their combination.
|
||||
* Rudimentary support for Atari 2600 prelude in a 4K cartridge image,
|
||||
and start of an example program in `eg/atari2600` directory.
|
||||
|
||||
|
@ -122,8 +122,9 @@ class Compiler(object):
|
||||
elif type_ == TYPE_WORD:
|
||||
initial_data = Word(defn.initial)
|
||||
elif TableType.is_a_table_type(type_, TYPE_BYTE):
|
||||
# FIXME convert defn.initial to a serializable type ... or when parsing.
|
||||
initial_data = Table(defn.initial, type_.size)
|
||||
initial_data = Table([Byte(i) for i in defn.initial], type_.size)
|
||||
elif TableType.is_a_table_type(type_, TYPE_WORD):
|
||||
initial_data = Table([Word(i) for i in defn.initial], type_.size)
|
||||
else:
|
||||
raise NotImplementedError(type_)
|
||||
label.set_length(initial_data.size())
|
||||
|
@ -13,6 +13,8 @@ class Emittable(object):
|
||||
|
||||
class Byte(Emittable):
|
||||
def __init__(self, value):
|
||||
if isinstance(value, basestring):
|
||||
value = ord(value)
|
||||
if value < -127 or value > 255:
|
||||
raise IndexError(value)
|
||||
if value < 0:
|
||||
@ -49,6 +51,7 @@ class Word(Emittable):
|
||||
|
||||
class Table(Emittable):
|
||||
def __init__(self, value, size):
|
||||
"""`value` should be an iterable of Emittables."""
|
||||
# TODO: range-checking
|
||||
self.value = value
|
||||
self._size = size
|
||||
@ -57,12 +60,10 @@ class Table(Emittable):
|
||||
return self._size
|
||||
|
||||
def serialize(self, addr=None):
|
||||
bytes = []
|
||||
for b in self.value:
|
||||
bytes.append(chr(ord(b)))
|
||||
while len(bytes) < self.size():
|
||||
bytes.append(chr(0))
|
||||
return ''.join(bytes)
|
||||
buf = ''.join([emittable.serialize() for emittable in self.value])
|
||||
while len(buf) < self.size():
|
||||
buf += chr(0)
|
||||
return buf
|
||||
|
||||
def __repr__(self):
|
||||
return "%s()" % (self.__class__.__name__)
|
||||
|
@ -144,9 +144,9 @@ class Parser(object):
|
||||
self.scanner.scan()
|
||||
else:
|
||||
initial = []
|
||||
initial.append(self.const())
|
||||
initial.append(self.const().value)
|
||||
while self.scanner.consume(','):
|
||||
initial.append(self.const())
|
||||
initial.append(self.const().value)
|
||||
else:
|
||||
initial = self.const().value
|
||||
|
||||
|
@ -198,14 +198,31 @@ Initialized byte table, initialized with list of byte values.
|
||||
= $080D LDX #$00
|
||||
= $080F LDA $0813,X
|
||||
= $0812 RTS
|
||||
= $0813 .byte $57
|
||||
= $0814 PHA
|
||||
= $0815 EOR ($54,X)
|
||||
= $0817 .byte $3F
|
||||
= $0813 .byte $FF
|
||||
= $0814 BRK
|
||||
= $0815 STA ($80,X)
|
||||
= $0817 .byte $7F
|
||||
= $0818 BRK
|
||||
= $0819 BRK
|
||||
= $081A BRK
|
||||
|
||||
Initialized word table, initialized with list of word values.
|
||||
|
||||
| word table[8] message : 65535, 0, 127
|
||||
|
|
||||
| routine main
|
||||
| {
|
||||
| }
|
||||
= $080D RTS
|
||||
= $080E .byte $FF
|
||||
= $080F .byte $FF
|
||||
= $0810 BRK
|
||||
= $0811 BRK
|
||||
= $0812 .byte $7F
|
||||
= $0813 BRK
|
||||
= $0814 BRK
|
||||
= $0815 BRK
|
||||
|
||||
Some instructions.
|
||||
|
||||
| byte foo
|
||||
|
Loading…
Reference in New Issue
Block a user