Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing ca65 for 65816 jml and jmp opcodes #80

Merged
merged 2 commits into from Feb 17, 2014

Conversation

lintbe
Copy link
Contributor

@lintbe lintbe commented Feb 12, 2014

Added a missing addressing mode for jmp/jml : Absolute Indexed Long
that opcode can be written like jmp[$1234] or jml[$1234]

Removed Absolute Indirect addressing mode for jml since it's not a long adressing mode

added a missing addressing mode for jmp/jml : Absolute Indexed Long
that opcode can be written like jmp[$1234] or jml[$1234]

removed Absolute Inderect addressing mode for jml since it's not a long adressing mode
@@ -84,6 +84,7 @@
#define AM65_IMM_IMPLICIT 0x00800000UL
#define AM65_BLOCKMOVE 0x01000000UL
#define AM65_BLOCKXFER 0x02000000UL
#define AM65_ABS_IND_LONG 0x04000000UL
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the nit-picking but the cc65 source code isn't supposed to contain \t chars.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok sorry I will fix that for next pull requests ...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to apologize!

I presume that you're aware that you can just push another commit to your branch to update this exsisting pull request. You should however drop a note in this discussion that you did so as I won't get automatically notified on new commits.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed !

@oliverschmidt
Copy link
Contributor

Thanks for your interest in contributing to cc65 :-)

As I'm having a hard time to assess its correctness I'll ask on cc65-devel@lists.sourceforge.net for additional input.

@oliverschmidt
Copy link
Contributor

There was no substantial feedback on cc65-devel@lists.sourceforge.net so I'm going to merge this.

oliverschmidt added a commit that referenced this pull request Feb 17, 2014
Fixing ca65 for 65816 jml and jmp opcodes
@oliverschmidt oliverschmidt merged commit 96ef7fd into cc65:master Feb 17, 2014
@greg-king5
Copy link
Contributor

Removed Absolute Indirect addressing mode for jml because it's not a long addressing mode.

The W65C816S's datasheet shows that the opposite is true. That mode is the reason why the jml mnemonic exists! It has two flavors:

  1. jmp (a) jumps through a 16-bit (absolute, near) pointer.
  2. jml (a) jumps through a 24-bit (long, far) pointer.

Both instructions have 16-bit operands (they point to 2-byte or 3-byte data in memory bank zero). (All other addressing modes are the same for both mnemonics.)

Therefore, that mode needs to be put back into ca65.

@greg-king5
Copy link
Contributor

After studying http://westerndesigncenter.com/wdc/documentation/w65c816s.pdf longer, and after reading this request's description again, I think that I was confused by a mode-name typo. jmp [$1234] isn't "Absolute Indexed Long", it is " Absolute Indirect Long". So, my advice changes a little bit: jml ($1234) is the same as jmp [$1234]; ca65 should support both syntaxes.

jml [$1234] now creates the wrong op-code. It makes $7C; it should make the same $DC that my other two examples make.

@greg-king5
Copy link
Contributor

This is a listing from the patched ca65:

ca65 V2.14.0
000000r 1                  .p816
000000r 1  4C 34 12        jmp $1234
000003r 1  5C 34 12 00     jml $1234
000007r 1
000007r 1  5C 56 34 12     jmp $123456
00000Br 1  5C 56 34 12     jml $123456
00000Fr 1
00000Fr 1  6C 34 12        jmp ($1234)
000012r 1               ;  jml ($1234)
000012r 1
000012r 1  4C 34 12        jmp ($1234,x)
000015r 1               ;  jml ($1234,x)
000015r 1
000015r 1  DC 34 12        jmp [$1234]
000018r 1  7C 34 12        jml [$1234]

The first jml has the same operand as the line above it; but, it assembled to four bytes. The "L" in jml changed that Absolute operand into Absolute Long. That's how the third jml is supposed to work (Absolute Indirect is changed into Absolute Indirect Long).

Also, the fourth jmp and the last jml make wrong op-codes.

@lintbe
Copy link
Contributor Author

lintbe commented Feb 19, 2014

Ok I will double check that ...

@oliverschmidt
Copy link
Contributor

See #83 ...

@lintbe
Copy link
Contributor Author

lintbe commented Feb 19, 2014

First I would like to apologize for the adressing mode typo. The adressing mode that I added is "Absolute Indirect Long" wich syntax is jmp/jml [$1234]. There is effectively a bug in the opcode produced for the jml version. It's now fixed output 0xDC instead of 0x7C.

At first I didn't agree when you say that jml($1234) is the same as jmp[$1234].

I didn't based myself on the http://westerndesigncenter.com/wdc/documentation/w65c816s.pdf document but from older reference ("Programming the 65816" from WDC). The pdf in the link is the only reference that indicate that the jml ($1234) is supported for the "Absolute Indirect Long" adressing mode. Everywhere else the '[addr]' syntax is used in the same style as of the "Direct Indirect Long" adressing mode. So I will add that syntax in ca65.

When you look to wdc reference doc it's quite clear that JML alias is only for long adressing modes, now in ca65 code when you specify an adress it will pad her with 0 like jmp $12 will become jmp $0012 (and jml $12 will become jml $000012). That explain the first two instructions in your exemple, even if for me it should not work.

The fix for this is in #83

oliverschmidt added a commit that referenced this pull request Feb 20, 2014
Fix for pull request #80 bad JML opcode and adding syntax for Absolute Indirect Long
Michaelangel007 added a commit to Michaelangel007/cc65 that referenced this pull request Jan 16, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants