Re: [cc65] lines of code, memory, etc

From: Ullrich von Bassewitz <uz1musoftware.de>
Date: 2008-12-29 00:11:30
On Fri, Nov 28, 2008 at 05:38:15PM -0300, Tachdaun wrote:
> Which would you choose?

If it's a library routine and or speed/memory critical, it might be worth
writing it in inline assembler:

        static unsigned readjoy (void)
        {
            asm ("ldx #0");
            asm ("stx tmp1");
            asm ("ldx #8");
        Loop:
            asm ("lda %w", joypad);
            asm ("ror a");
            asm ("ror tmp1");
            asm ("dex");
            asm ("bne %g", Loop);
            asm ("lda tmp1");
            return __AX__;
        }

Now as you write this, and I read my answer, I remember that there is a
joystick driver for the nes that comes with cc65. And it contains similar
code:

; ------------------------------------------------------------------------
; READ: Read a particular joystick passed in A.
;

READJOY:
        and     #$01            ; Fix joystick number
        tay                     ; Joystick number (0,1) into Y

; Read joystick

        lda     #1
        sta     APU_PAD1,y
        lda     #0
        sta     APU_PAD1,y
        sta     tmp1

        ldx     #8
@L1:    asl     tmp1
        lda     APU_PAD1,y
        and     #$01
        beq     @L2
        lda     tmp1
        ora     #$01
        sta     tmp1
@L2:    dex
        bne     @L1

        lda     tmp1
;       ldx     #$00            ; fix X
        rts

Besides that fact that the code could be written better, why not just use the
existing driver?

Regards


        Uz


-- 
Ullrich von Bassewitz                                  uz@musoftware.de
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Mon Dec 29 00:14:35 2008

This archive was generated by hypermail 2.1.8 : 2008-12-29 00:14:37 CET