chitselb / pettil

6502 Forth-83 dialect for the Commodore PET 2001
http://pettil.tumblr.com
34 stars 3 forks source link

Slightly improved enter ? #79

Open barrym95838 opened 3 years ago

barrym95838 commented 3 years ago

Can we improve enter a tiny bit by taking advantage of the likelihood that our IP won't wrap past $FFFF?

enter: ; pull temp from R:, push pip+2 to R:, pip = temp+1
    ldy pip
    cpy #$FE
    lda pip+1
    adc #0
    sta z
    pla
    adc #1
    sta pip
    pla
    adc #0
    sta pip+1
    lda z
    pha
    tya
    adc #2
    pha
    jmp nexto
chitselb commented 3 years ago

This is vastly improved, because ENTER happens all the time! Dropping 6 clocks and 7 bytes is awesome! I don't completely trust it yet, but the brevity of code is greatly appreciated.

barrym95838 commented 3 years ago

I count only 4 clocks and 1 byte of improvement (from finding an arrangement that loses the CLC and replaces INY INY with ADC #2), hence my choice of the word "slightly" :-).

barrym95838 commented 3 years ago

Hmm ... my suggested improvement tries to duplicate the behavior of your original ENTER, but it could be that both are vulnerable to a JSR ENTER that the compiler lays down at $xxFC, because that would trigger the JMP ($xxFF) bug inside your NEXT. If you haven't already done so, you gotta somehow make sure that never happens.

chitselb commented 3 years ago

ENTER/EXIT may presume that the compiler didn't bag us, in the same manner that NEXT presumes that page-hopping was properly handled by the compiler

On Wed, Dec 30, 2020 at 3:51 PM barrym95838 notifications@github.com wrote:

Hmm ... my suggested improvement tries to duplicate the behavior of your original ENTER, but it could be that both are vulnerable to a JSR ENTER that the compiler lays down at $xxFC, because that would trigger the JMP ($xxFF) bug inside your NEXT. If you haven't already done so, you gotta somehow make sure that never happens.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/chitselb/pettil/issues/79#issuecomment-752754478, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABZ6TIG4VVLQWAOBLLJKSLSXOHFTANCNFSM4T6JBG3Q .