1
0
mirror of https://github.com/catseye/SixtyPical.git synced 2024-06-07 06:29:32 +00:00

Support for copy [ptra]+y, [ptrb]+y to indirect LDA indirect STA

This commit is contained in:
Chris Pressey 2018-04-18 10:57:57 +01:00
parent 4f28f43bde
commit 3c7d95a724
7 changed files with 67 additions and 2 deletions

View File

@ -8,6 +8,7 @@ History of SixtyPical
if the address of z < 256.
* More thorough tests and justifications written for the case of
assigning a routine to a vector with a "wider" type.
* Support for `copy [ptra]+y, [ptrb]+y` to indirect LDA indirect STA.
0.15
----

View File

@ -1,7 +1,7 @@
SixtyPical
==========
_Version 0.15. Work-in-progress, everything is subject to change._
_Version 0.16. Work-in-progress, everything is subject to change._
**SixtyPical** is a 6502-like programming language with advanced
static analysis.
@ -87,6 +87,5 @@ are trashed inside the block.
* Add absolute addressing in shl/shr, absolute-indexed for add, sub, etc.
* Automatic tail-call optimization (could be tricky, w/constraints?)
* Possibly `ld x, [ptr] + y`, possibly `st x, [ptr] + y`.
* Maybe even `copy [ptra] + y, [ptrb] + y`, which can be compiled to indirect LDA then indirect STA!
[VICE]: http://vice-emu.sourceforge.net/

View File

@ -517,6 +517,11 @@ class Analyzer(object):
pass
else:
raise TypeMismatchError(instr, (src, dest))
elif isinstance(src, IndirectRef) and isinstance(dest, IndirectRef):
if isinstance(src.ref.type, PointerType) and isinstance(dest.ref.type, PointerType):
pass
else:
raise TypeMismatchError(instr, (src, dest))
elif isinstance(src, (LocationRef, ConstantRef)) and isinstance(dest, IndexedRef):
if src.type == TYPE_WORD and TableType.is_a_table_type(dest.ref.type, TYPE_WORD):
@ -561,7 +566,12 @@ class Analyzer(object):
context.set_written(dest.ref)
elif isinstance(src, IndirectRef) and isinstance(dest, LocationRef):
context.assert_meaningful(src.ref, REG_Y)
# TODO more sophisticated?
context.set_written(dest)
elif isinstance(src, IndirectRef) and isinstance(dest, IndirectRef):
context.assert_meaningful(src.ref, REG_Y)
# TODO more sophisticated?
context.set_written(dest.ref)
elif isinstance(src, LocationRef) and isinstance(dest, IndexedRef):
context.assert_meaningful(src, dest.ref, dest.index)
context.set_written(dest.ref)

View File

@ -428,6 +428,12 @@ class Compiler(object):
dest_label = self.get_label(dest.name)
self.emitter.emit(LDA(IndirectY(src_label)))
self.emitter.emit(STA(Absolute(dest_label)))
elif isinstance(src, IndirectRef) and isinstance(dest, IndirectRef) and isinstance(src.ref.type, PointerType) and isinstance(dest.ref.type, PointerType):
### copy [ptra] + y, [ptrb] + y
src_label = self.get_label(src.ref.name)
dest_label = self.get_label(dest.ref.name)
self.emitter.emit(LDA(IndirectY(src_label)))
self.emitter.emit(STA(IndirectY(dest_label)))
elif isinstance(src, AddressRef) and isinstance(dest, LocationRef) and isinstance(src.ref.type, BufferType) and isinstance(dest.type, PointerType):
### copy ^buf, ptr
src_label = self.get_label(src.ref.name)

View File

@ -2114,6 +2114,24 @@ Read through a pointer.
| }
= ok
Read and write through two pointers.
| buffer[2048] buf
| pointer ptra
| pointer ptrb
|
| routine main
| inputs buf
| outputs buf
| trashes a, y, z, n, ptra, ptrb
| {
| ld y, 0
| copy ^buf, ptra
| copy ^buf, ptrb
| copy [ptra] + y, [ptrb] + y
| }
= ok
Read through a pointer to the `a` register. Note that this is done with `ld`,
not `copy`.

View File

@ -1037,6 +1037,35 @@ Read through a pointer, into a byte storage location, or the `a` register.
= $081C LDA ($FE),Y
= $081E RTS
Read and write through two pointers.
| buffer[2048] buf
| pointer ptra @ 252
| pointer ptrb @ 254
|
| routine main
| inputs buf
| outputs buf
| trashes a, y, z, n, ptra, ptrb
| {
| ld y, 0
| copy ^buf, ptra
| copy ^buf, ptrb
| copy [ptra] + y, [ptrb] + y
| }
= $080D LDY #$00
= $080F LDA #$24
= $0811 STA $FC
= $0813 LDA #$08
= $0815 STA $FD
= $0817 LDA #$24
= $0819 STA $FE
= $081B LDA #$08
= $081D STA $FF
= $081F LDA ($FC),Y
= $0821 STA ($FE),Y
= $0823 RTS
Write the `a` register through a pointer.
| buffer[2048] buf

View File

@ -565,12 +565,14 @@ Buffers and pointers.
| buffer[2048] buf
| pointer ptr
| pointer ptrb
| byte foo
|
| routine main {
| copy ^buf, ptr
| copy 123, [ptr] + y
| copy [ptr] + y, foo
| copy [ptr] + y, [ptrb] + y
| }
= ok