mirror of
https://github.com/catseye/SixtyPical.git
synced 2024-12-01 16:50:09 +00:00
Break the ground where we need to implement word table read/write.
This commit is contained in:
parent
aa5e4119da
commit
84ca6c4e96
@ -6,6 +6,7 @@ History of SixtyPical
|
|||||||
|
|
||||||
* Add word (constant or memory location) to word memory location.
|
* Add word (constant or memory location) to word memory location.
|
||||||
* Add word to pointer (unchecked for now).
|
* Add word to pointer (unchecked for now).
|
||||||
|
* Adding `word table` type (in progress).
|
||||||
* Implementation: `--debug` shows some extra info during analysis.
|
* Implementation: `--debug` shows some extra info during analysis.
|
||||||
* Fixed bug where `copy`ing literal word into word storage used wrong endianness.
|
* Fixed bug where `copy`ing literal word into word storage used wrong endianness.
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ Compare word (constant or memory location) with memory location or pointer. (Ma
|
|||||||
And then write a little demo "game" where you can move a block around the screen with
|
And then write a little demo "game" where you can move a block around the screen with
|
||||||
the joystick.
|
the joystick.
|
||||||
|
|
||||||
### `word table` and `vector table` types
|
### `vector table` type
|
||||||
|
|
||||||
### `low` and `high` address operators
|
### `low` and `high` address operators
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ To turn `word` type into `byte`.
|
|||||||
|
|
||||||
### save registers on stack
|
### save registers on stack
|
||||||
|
|
||||||
This preserves them, so semantically, they can be used even though they
|
This preserves them, so that, semantically, they can be used later even though they
|
||||||
are trashed inside the block.
|
are trashed inside the block.
|
||||||
|
|
||||||
### And at some point...
|
### And at some point...
|
||||||
|
13
eg/word-table.60p
Normal file
13
eg/word-table.60p
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
word one
|
||||||
|
word table many
|
||||||
|
|
||||||
|
routine main
|
||||||
|
inputs one, many
|
||||||
|
outputs one, many
|
||||||
|
trashes a, x, n, z
|
||||||
|
{
|
||||||
|
ld x, 0
|
||||||
|
copy 777, one
|
||||||
|
copy one, many + x
|
||||||
|
copy many + x, one
|
||||||
|
}
|
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
from sixtypical.ast import Program, Routine, Block, Instr
|
from sixtypical.ast import Program, Routine, Block, Instr
|
||||||
from sixtypical.model import (
|
from sixtypical.model import (
|
||||||
ConstantRef, LocationRef, IndirectRef, AddressRef,
|
ConstantRef, LocationRef, IndexedRef, IndirectRef, AddressRef,
|
||||||
TYPE_BIT, TYPE_BYTE, TYPE_WORD, BufferType, PointerType, RoutineType, VectorType,
|
TYPE_BIT, TYPE_BYTE, TYPE_WORD, TYPE_WORD_TABLE, BufferType, PointerType, RoutineType, VectorType,
|
||||||
REG_A, REG_X, REG_Y, FLAG_C
|
REG_A, REG_X, REG_Y, FLAG_C
|
||||||
)
|
)
|
||||||
from sixtypical.emitter import Byte, Label, Offset, LowAddressByte, HighAddressByte
|
from sixtypical.emitter import Byte, Label, Offset, LowAddressByte, HighAddressByte
|
||||||
@ -169,7 +169,7 @@ class Compiler(object):
|
|||||||
raise UnsupportedOpcodeError(instr)
|
raise UnsupportedOpcodeError(instr)
|
||||||
elif isinstance(dest, LocationRef) and src.type == TYPE_WORD and isinstance(dest.type, PointerType):
|
elif isinstance(dest, LocationRef) and src.type == TYPE_WORD and isinstance(dest.type, PointerType):
|
||||||
if isinstance(src, ConstantRef):
|
if isinstance(src, ConstantRef):
|
||||||
dest_label = self.labels[dest.name] # this. is. zero-page.
|
dest_label = self.labels[dest.name]
|
||||||
self.emitter.emit(LDA(ZeroPage(dest_label)))
|
self.emitter.emit(LDA(ZeroPage(dest_label)))
|
||||||
self.emitter.emit(ADC(Immediate(Byte(src.low_byte()))))
|
self.emitter.emit(ADC(Immediate(Byte(src.low_byte()))))
|
||||||
self.emitter.emit(STA(ZeroPage(dest_label)))
|
self.emitter.emit(STA(ZeroPage(dest_label)))
|
||||||
@ -178,7 +178,7 @@ class Compiler(object):
|
|||||||
self.emitter.emit(STA(ZeroPage(Offset(dest_label, 1))))
|
self.emitter.emit(STA(ZeroPage(Offset(dest_label, 1))))
|
||||||
elif isinstance(src, LocationRef):
|
elif isinstance(src, LocationRef):
|
||||||
src_label = self.labels[src.name]
|
src_label = self.labels[src.name]
|
||||||
dest_label = self.labels[dest.name] # this. is. zero-page.
|
dest_label = self.labels[dest.name]
|
||||||
self.emitter.emit(LDA(ZeroPage(dest_label)))
|
self.emitter.emit(LDA(ZeroPage(dest_label)))
|
||||||
self.emitter.emit(ADC(Absolute(src_label)))
|
self.emitter.emit(ADC(Absolute(src_label)))
|
||||||
self.emitter.emit(STA(ZeroPage(dest_label)))
|
self.emitter.emit(STA(ZeroPage(dest_label)))
|
||||||
@ -345,6 +345,17 @@ class Compiler(object):
|
|||||||
self.emitter.emit(STA(ZeroPage(dest_label)))
|
self.emitter.emit(STA(ZeroPage(dest_label)))
|
||||||
self.emitter.emit(LDA(Immediate(LowAddressByte(src_label))))
|
self.emitter.emit(LDA(Immediate(LowAddressByte(src_label))))
|
||||||
self.emitter.emit(STA(ZeroPage(Offset(dest_label, 1))))
|
self.emitter.emit(STA(ZeroPage(Offset(dest_label, 1))))
|
||||||
|
elif isinstance(src, LocationRef) and isinstance(dest, IndexedRef):
|
||||||
|
if src.type == TYPE_WORD and dest.ref.type == TYPE_WORD_TABLE:
|
||||||
|
src_label = self.labels[src.name]
|
||||||
|
dest_label = self.labels[dest.ref.name]
|
||||||
|
raise NotImplementedError("""\
|
||||||
|
What we will need to do here, is to have TWO 'labels' per name, one for the high byte table,
|
||||||
|
and one for the low byte table. Then select AbsoluteX() or AbsoluteY() addressing on those
|
||||||
|
tables. And use that in the STA() part.""")
|
||||||
|
else:
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
elif not isinstance(src, (ConstantRef, LocationRef)) or not isinstance(dest, LocationRef):
|
elif not isinstance(src, (ConstantRef, LocationRef)) or not isinstance(dest, LocationRef):
|
||||||
raise NotImplementedError((src, dest))
|
raise NotImplementedError((src, dest))
|
||||||
elif src.type == TYPE_BYTE and dest.type == TYPE_BYTE:
|
elif src.type == TYPE_BYTE and dest.type == TYPE_BYTE:
|
||||||
|
@ -316,6 +316,23 @@ Copy routine to vector, inside an `interrupts off` block.
|
|||||||
| }
|
| }
|
||||||
= 00c078a90d8d0fc0a9c08d10c05860e860
|
= 00c078a90d8d0fc0a9c08d10c05860e860
|
||||||
|
|
||||||
|
Copy word to word table and back.
|
||||||
|
|
||||||
|
| word one
|
||||||
|
| word table many
|
||||||
|
|
|
||||||
|
| routine main
|
||||||
|
| inputs one, many
|
||||||
|
| outputs one, many
|
||||||
|
| trashes a, x, n, z
|
||||||
|
| {
|
||||||
|
| ld x, 0
|
||||||
|
| copy 777, one
|
||||||
|
| copy one, many + x
|
||||||
|
| copy many + x, one
|
||||||
|
| }
|
||||||
|
= 00c0a200a9009d0dc0bd0dc060....
|
||||||
|
|
||||||
Indirect call.
|
Indirect call.
|
||||||
|
|
||||||
| vector foo outputs x trashes z, n
|
| vector foo outputs x trashes z, n
|
||||||
|
Loading…
Reference in New Issue
Block a user