Beiträge von strik im Thema „The Hitchhiker's Guide to GEOS v2020“

    Oh, the way I wrote it does not use undocumented behaviour.

    That's why I swapped the CLD and the CMP w.r.t. the document I linked to: In BCD mode, the CMP behaviour is not document.

    As I use the CLD only after this, though, this is all inside of the 6502 defined behaviour.

    From Bitte melde dich an, um diesen Link zu sehen., even shorter (6 byte, 14 cycles) and slightly modified to not use undocumented behaviour:

    Code
    CMP #$0A   ; 2 cycles
    SED        ; 2 cycles
    ADC #$30   ; 2 cycles
    CLD        ; 2 cycles
    RTS        ; 6 cycles

    Even with an additional SEI/CLI sandwich, we get 8 byte / 18 cycles.

    That is a new trick to me, excellent. If you want I will give you credit for its inclusion as I had yet to have discovered this oddity of decimal mode and will add it to the manual as another alternative.

    That's a known trick that works with many machines. I don't need the credits for this one.
    I once knew a source where it seems to be mentioned for the first time, but I do not remember now. I know, however, that L.A. Leventhal has it in his 6502 book.

    What about the interrupts? AFAIK the standard C64 interrupt handlers are not compatible with decimal mode.

    That's right. I should have mentioned that one must be careful when using it.
    In fact, I have used it mostly in interrupt routines themselves, so this was not a problem. ;)

    From my point of view, this version works best of you want to convert multiple values at once: SEI/SED, then convert everything, then CLD/CLI.

    For a subroutine, it might not be best suited.

    Alternative nib2hex, another size-optimized version (8 byte, 16 cycles):

    Code
    sed      ; (2 cycles)
    clc      ; (2 cycles)
    adc #$90 ; (2 cycles)
    adc #$40 ; (2 cycles)
    cld      ; (2 cycles)
    rts      ; (6 cycles)

    This routine is best suited if you want to convert multiple nibbles at once (omitting the sed/cld sandwich, and thus, 4 cycles)