diff --git a/doc/ca65.sgml b/doc/ca65.sgml index 567fa55a9..b65d337bb 100644 --- a/doc/ca65.sgml +++ b/doc/ca65.sgml @@ -184,7 +184,7 @@ Here is a description of all the command line options: Enable an emulation feature. This is identical as using @@ -2833,6 +2833,23 @@ See: , + + Affects 65816 mode only. + + Allows jsr and jmp to produce long jumps if the target + address has been previously declared in a far segment, + or imported as far. + Otherwise jsl and jml must be used instead. + + Also allows to convert rts + to a long return rtl when the enclosing scope or memory model + indicates returning from a far procedure. + + This permits compatibility with the old behavior of this assembler, or other + assemblers which similarly allowed jsr and jmp to be used + this way. + loose_char_term Accept single quotes as well as double quotes as terminators for char @@ -4002,7 +4019,9 @@ See: ,In 65816 mode, replace a In 65816 mode, if the feature is enabled, + smart mode will replace a AddrSize == ADDR_SIZE_FAR) { + if (LongJsrJmpRts) { + PutJMP (Ins); + } else { + InsDesc InsAbs = *Ins; + InsAbs.AddrMode &= ~(AM65_ABS_LONG); + PutJMP (&InsAbs); + } +} + + + +static void PutJSR816 (const InsDesc* Ins) +/* Handle the JSR instruction for the 816. +** Allowing the long_jsr_jmp_rts feature to permit a long JSR. +*/ +{ + if (LongJsrJmpRts) { + PutAll (Ins); + } else { + InsDesc InsAbs = *Ins; + InsAbs.AddrMode &= ~(AM65_ABS_LONG); + PutJMP (&InsAbs); + } +} + + + +static void PutRTS (const InsDesc* Ins attribute ((unused))) +/* Handle the RTS instruction for the 816. In smart mode emit a RTL opcode if +** the enclosing scope is FAR, but only if the long_jsr_jmp_rts feature applies. +*/ +{ + if (LongJsrJmpRts && SmartMode && CurrentScope->AddrSize == ADDR_SIZE_FAR) { Emit0 (0x6B); /* RTL */ } else { Emit0 (0x60); /* RTS */ diff --git a/test/dasm/65816.info b/test/dasm/65816.info index 2a3394680..a6d836688 100644 --- a/test/dasm/65816.info +++ b/test/dasm/65816.info @@ -3,5 +3,5 @@ GLOBAL { }; RANGE { START $8000; END $8229; ADDRMODE "MX"; TYPE Code;}; -RANGE { START $822a; END $824b; ADDRMODE "mx"; TYPE Code;}; +RANGE { START $822a; END $825b; ADDRMODE "mx"; TYPE Code;}; diff --git a/test/dasm/test65816.s b/test/dasm/test65816.s index 3d764fb6e..1b447d0fe 100644 --- a/test/dasm/test65816.s +++ b/test/dasm/test65816.s @@ -151,10 +151,11 @@ BVC LABEL BVS LABEL BRL LABEL JMP $1234 -JMP $FEDCBA +JML $FEDCBA JMP ($1234) JMP ($1234,X) JMP [$1234] +JML [$1234] ; alternative to JMP [] JSL $123456 JSR $1234 JSR ($1234,X) @@ -271,3 +272,15 @@ BIT #$5432 LDA #$5432 LDX #$5432 LDY #$5432 + +; test of smart and long_jsr_jmp_rts +.smart +.proc short_rts : far +RTS ; not promoted to RTL +.endproc +.feature long_jsr_jmp_rts +JSR $FEDCBA ; promoted to JSL +JMP $FEDCBA ; promoted to JML +.proc long_rts : far +RTS ; promoted to RTL +.endproc