[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Newbie Assembly



"Simon Biber" <simon@basilisk2.cjb.net> wrote:

> I've written this program which clears the HGR screen to a colour (white by
> default). It works! Can someone help me to see if this is an optimal way of
> doing this?
> 
> 300:    LDA #FF
> 302:    LDX #3F
> 304:    LDY #00
> 306:    STX $030E
> 309:    STY $030D
> 30C:    STA $0100
> 30F:    DEY
> 310:    BNE $0306
> 312:    DEX
> 313:    CPX #19
> 315:    BNE $0304
> 
> You can change to a different colour by putting the bit-pattern into $0301.

The usual way to clear the screen is with the (zp),y addressing mode:

(PTR and PTR+1 are in zero page)

        LDX #$20		; Set pointer to $2000
        STX PTR+1		; Also set X to $20 pages
        LDY #0          
        STY PTR
		LDA #$FF
LOOP	STA (PTR),Y
		INY
		BNE LOOP
		INC PTR+1
		DEX				; X counts down $20 pages
		BNE LOOP

This takes 2+3+2+3+2+32(256(6+2+3)-1+5+2)-1 = 90335 cycles, or about 1/11th
of a second. If you need to do it faster, you can do this:

        LDA #$FF
        LDX #0
LOOP    STA $2000,X
        STA $2100,X
        STA $2200,X
        ..etc..
        STA $3E00,X
        STA $3F00,X
        INX
        BNE LOOP

This takes 2+2+256(32(5)+2+3)-1 = 42239 cycles, which is about twice
as fast.

Paul Guertin
pg@sff.net