1
0
mirror of https://github.com/catseye/SixtyPical.git synced 2024-11-29 18:49:22 +00:00

I kind of forgot that indirect JSR needs a trampoline first :/

This commit is contained in:
Chris Pressey 2015-10-20 13:15:21 +01:00
parent f16cb75677
commit 16649042cb
4 changed files with 54 additions and 3 deletions

View File

@ -9,7 +9,7 @@ from sixtypical.model import (
) )
from sixtypical.emitter import Byte, Label, Offset from sixtypical.emitter import Byte, Label, Offset
from sixtypical.gen6502 import ( from sixtypical.gen6502 import (
Immediate, Absolute, AbsoluteX, AbsoluteY, Relative, Immediate, Absolute, AbsoluteX, AbsoluteY, Indirect, Relative,
LDA, LDX, LDY, STA, STX, STY, LDA, LDX, LDY, STA, STX, STY,
TAX, TAY, TXA, TYA, TAX, TAY, TXA, TYA,
CLC, SEC, ADC, SBC, ROL, ROR, CLC, SEC, ADC, SBC, ROL, ROR,
@ -193,8 +193,16 @@ class Compiler(object):
else: else:
raise UnsupportedOpcodeError(instr) raise UnsupportedOpcodeError(instr)
elif opcode == 'call': elif opcode == 'call':
location = instr.location
label = self.labels[instr.location.name] label = self.labels[instr.location.name]
if isinstance(location.type, RoutineType):
self.emitter.emit(JSR(Absolute(label))) self.emitter.emit(JSR(Absolute(label)))
elif isinstance(location.type, VectorType):
# XXX NOT QUITE RIGHT, IS IT?
# We need to simulate an indirect JSR!
self.emitter.emit(JMP(Indirect(label)))
else:
raise NotImplementedError
elif opcode == 'if': elif opcode == 'if':
cls = { cls = {
False: { False: {

View File

@ -1119,3 +1119,32 @@ Routines are read-only.
| copy vec, foo | copy vec, foo
| } | }
? TypeMismatchError ? TypeMismatchError
Indirect call.
| vector foo outputs x trashes z, n
|
| routine bar outputs x trashes z, n {
| ld x, 200
| }
|
| routine main inputs bar outputs x, foo trashes a, z, n {
| copy bar, foo
| call foo
| }
= ok
Calling the vector has indeed trashed stuff etc,
| vector foo trashes x, z, n
|
| routine bar trashes x, z, n {
| ld x, 200
| }
|
| routine main inputs bar outputs x, foo trashes z, n {
| ld x, 0
| copy bar, foo
| call foo
| }
? UninitializedOutputError: x

View File

@ -261,3 +261,17 @@ Copy instruction inside interrupts off block.
| } | }
| } | }
= 00c078ad0fc08d11c0ad10c08d12c05860e860 = 00c078ad0fc08d11c0ad10c08d12c05860e860
Indirect call.
| vector foo outputs x trashes z, n
|
| routine bar outputs x trashes z, n {
| ld x, 200
| }
|
| routine main inputs bar outputs x, foo trashes a, z, n {
| copy bar, foo
| call foo
| }
= 00c0

View File

@ -409,7 +409,7 @@ Indirect call.
| ld x, 200 | ld x, 200
| } | }
| |
| routine main { | routine main inputs bar outputs x, foo trashes a, z, n {
| copy bar, foo | copy bar, foo
| call foo | call foo
| } | }