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

[KERNAL] PRIMM: Add 65C816 native mode support and optimize the code #352

Merged
merged 3 commits into from
Nov 15, 2024

Conversation

Fulgen301
Copy link
Collaborator

@Fulgen301 Fulgen301 commented Aug 17, 2024

PRIMM is the only KERNAL library function left that uses abs,x addressing for stack access, thereby not working with a 65C816 in native mode where the stack page might have been moved. This PR adds an implementation that uses the 65C816's stack-relative addressing to work with arbitrary stack pointers; it also optimizes the 65C02's code path.

@mooinglemur mooinglemur marked this pull request as draft August 22, 2024 15:17
@Fulgen301 Fulgen301 marked this pull request as ready for review November 13, 2024 16:22
@Fulgen301 Fulgen301 changed the title [KERNAL] PRIMM: Add 65C816 native mode support and optimize the 65C02 code to use (zp) instead of (zp),y with y = 0 [KERNAL] PRIMM: Add 65C816 native mode support and optimize the code Nov 13, 2024
@Fulgen301
Copy link
Collaborator Author

With the new implementations,

jsr PRIMM
.asciiz "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"

now takes 36493 cycles instead of 38703 cycles on the 65C02 and 36490 cycles on the 65C816. (Measurements taken via the emulator's cycle counter).
The implementations essentially use the exact same code, with the 65C816 leveraging its stack addressing modes for lda $XX,S instead of lda $01XX,x.

Copy link
Collaborator

@mooinglemur mooinglemur left a comment

Choose a reason for hiding this comment

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

Thanks!

@mooinglemur mooinglemur merged commit d91bc55 into X16Community:master Nov 15, 2024
1 check passed
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.

2 participants