Re: [stella] Colour Display Programme

Subject: Re: [stella] Colour Display Programme
From: Piero Cavina <p.cavina@xxxxxxxxxxxxx>
Date: Thu, 18 Sep 1997 15:37:08 +0100
At 19:27 -0400 16-09-1997, crackers@xxxxxxxx wrote:

>I've only tested it out on an emulator so far. Here's the programme.

Here are some advices to help you to improve your 6502 programming...

>doit	STA  WSYNC	;not much going on here, just repeat the
>	dex		;same scanline 192 times
>	beq  done
>	jmp  doit
>
>done	rts

uh, avoid 'spaghetti' when you can... look at this...:

doit    STA  WSYNC
        dex
        bne  doit

done    rts


>
>oscan   jsr  joy	;go check the joystick
>	LDX  #$1E
>
>waste	STA  WSYNC      ;no game logic so let's blow the overscan
>	DEX
>	BNE  waste
>	RTS

be careful... this way you aren't checking the joystick during overscan,
but during the 193th scanline.
If you want to do things in overtime, you've to set up the timer like
you've done for vblank.
Otherwise put the call to 'joy' in vertb.


>joy	lda  SWCHA	;check the joystick ports
>	cmp  #$7F	;see if it's moved right (joystick 1)
>        beq  right
>        cmp  #$BF	;see if it's moved left  (joystick 1)
>        beq  left
>        rts

>right   inc  DELAY	;our joystick delay timer is increased
>	lda  DELAY
>        cmp  #$1E	;check to see if we've had enough delay (30 frames)
>	bpl  clrup	;yep. Let's increase the colour
>        rts
>
>left    inc  DELAY	;joystick timer increased
>	lda  DELAY
>        cmp  #$1E	;30 frames yet?
>	bpl  clrdwn	;yep, decrease colour
>        rts

hmmm... try to avoid copies of the same code... and it usually better to
have counters going backwards...:

I've switched from left/right to up/down... it's easier this way... :-))

joy     lda  SWCHA ;0's=pushed 1's=not pushed
        eor  #$FF  ; invert, 1's=pushed, 0's=not pushed
        and  #%00000011 ; clear what isn't interesting - joy 1 pushed up or
down?
        bne  pushed ; yep
nope
        rts
pushed
        dec  DELAY
        bpl  nope ; still delaying

        ldx  #30  ; reload delay
        stx  DELAY

        lsr ; move bit 0 of A into C = Pushed up?
        bcc down ; no, it must be down

up      lda  COLOUR
        cmp  #$FE ; max?
        bcs  nope ; yep, don't inc
        inc  COLOUR
        inc  COLOUR
        rts

down    lda  COLOUR
        beq  nope ; min, don't dec
        dec  COLOUR
        dec  COLOUR
        rts

This is not tested, and probably Jim has already posted a shorter version!
hehe  :-)

Please not that your code isn't bad: it's not optimized, but there's a
certain order, which is always important for a beginner.

I recommend you to get a 6502 reference and study carefully what happens to
the processor status register (the C, Z, N flags...) when the instructions
are executed. This will help you to understand how to use those branch
instructions (BPL, BCC...) in the best way.

P.





--
Archives updated once/day at http://www.biglist.com/lists/stella/archives/
Unsubscribing and other info at http://www.biglist.com/lists/stella/stella.html

Current Thread