[stella] Help With Vertical Scroll

Subject: [stella] Help With Vertical Scroll
From: Aaron Bergstrom <Aaron.Bergstrom@xxxxxxxxxxxxxx>
Date: Sun, 02 Feb 2003 13:17:12 -0600
I've been working on a vertically scrolling playfield. It scrolls fine going down. And it scrolls fine going up too, except for when it reaches the very end of the playing field where it just quickly jumps to the end. Can anyone tell me why? I'm using the Stella emulator to test it. The scroll is controlled by the up/down of the left joystick..

Thanks,

Aaron
    processor 6502
    include vcs.h
    org $F000
Scanline = $80
CountSet = $81
CountYHold = $82
ScoreCount = $83
LastYC = $84
LastPF = $85

Start
        SEI
        CLD
        LDX  #$FF
        TXS
        LDA  #0
ClearMem
        STA 0,X
        DEY
        BNE ClearMem
        LDA #$00
        STA COLUBK
        LDA #$0E
        STA COLUPF
	LDA #192
	STA Scanline
	JSR CenterPF ; line up playfield

MainLoop
VSyncSetup
        LDA #2
        STA VSYNC
        STA WSYNC
        STA WSYNC
        STA WSYNC
        LDA #43
        STA TIM64T
        LDA #0
        STA VSYNC

	  LDA #0
        STA PF0
        STA PF1
        STA PF2

	  LDA #-1
	  CMP LastPF
	  BEQ VBlankWait
;Scroll Down
UpDown
	  LDA #$10	;Up?
	  BIT SWCHA 
	  BEQ ScrollUp

;Scroll Up
	  LDA #$20	;Down?
	  BIT SWCHA 
	  BEQ ScrollDown

LeftRight
	LDA #0
	STA SWCHA
	JMP VBlankWait

ScrollDown
	LDY LastYC
	LDX LastPF
	CPX lineSets
	BNE DownAllowed
	CPY #0
	BNE DownAllowed
	JMP LeftRight

ScrollUp
	LDY CountYHold
	LDX CountSet
	TYA
	CMP count,X
	BNE UpAllowed
	CPX #0
	BNE UpAllowed
	JMP LeftRight

DownAllowed
	LDY CountYHold
	LDX CountSet
	CPY #1
	BEQ NewYLoad
	DEY
	STY CountYHold
	JMP LeftRight

UpAllowed
	TYA
	CMP count,X
	BEQ NewYUSLoad
	INY
	STY CountYHold
	JMP LeftRight

NewYLoad
	INX
	LDY count,X
	STX CountSet
	STY CountYHold
	JMP LeftRight

NewYUSLoad
	DEX
	LDY count,X
	STX CountSet
	STY CountYHold
	JMP LeftRight

VBlankWait
        LDA #0
        TAX
        LDA INTIM
        BNE VBlankWait
        LDA #1
        STA CTRLPF
	  LDY #32
        STA WSYNC
        STA VBLANK
ScoreKernal
	STA WSYNC
	DEC Scanline
	DEY 
	CPY #0
	BNE ScoreKernal
	LDX CountSet
	LDY CountYHold
	JMP QuickDec

DrawPlayfield
	DEC Scanline
	CPY #0
	BEQ ChangeX
	STA WSYNC
	DEY
	JMP ScanlineCheck

QuickDec
	DEC Scanline
	DEY
	JMP QuickLoad

ChangeX
	INX
	LDY count,X

QuickLoad
	STA WSYNC
	LDA left_pf0,X
	STA PF0
	LDA left_pf1,X
	STA PF1
	LDA left_pf2,X
	STA PF2

ScanlineCheck
	LDA #0
	CMP Scanline
	BNE DrawPlayfield

End
        LDA #2
        STA WSYNC
        STA VBLANK
	  LDA #192
	  STA Scanline
	  STX LastPF
	  STY LastYC
        LDY #30

OverScan
        STA WSYNC
        DEY
        BNE OverScan
        JMP MainLoop

CenterPF
	LDA halfValue
	STA CountSet
	LDX #0
	LDY count,X

CountDown
	LDA CountSet
	CMP #0
	BEQ PFScreenAdjust
	CPY #1
	BEQ Increase; increase X register

	DEC CountSet
	DEY
	JMP CountDown

Increase
	INX
	LDY count,X
	JMP CountDown

PFScreenAdjust
	LDA count,X
	STA CountYHold
	LDA halfScreen
	STA CountSet

CountUp
	LDA CountSet
	CMP #0
	BEQ SaveStartPF
	CPY CountYHold
	BEQ Decrease
	DEC CountSet
	INY
	JMP CountUp

Decrease
	DEX
	LDY #1
	LDA count,X
	STA CountYHold
	JMP CountUp

SaveStartPF
	STX CountSet
	STY CountYHold
	LDA #-1
	STA LastYC
	STA LastPF
	RTS

left_pf0
  .byte $00;taker 1
  .byte $00; 2
  .byte $00; 3
  .byte $00; 4
  .byte $80; 5
  .byte $80; 5
  .byte $80; 6
  .byte $00; 6
  .byte $00; 7
  .byte $00;taker 1
  .byte $00; 1
left_pf1
  .byte $00;taker 2
  .byte $3F; 2
  .byte $40; 3
  .byte $80; 4
  .byte $00; 5
  .byte $FF; 5
  .byte $00; 6
  .byte $80; 6
  .byte $40; 7
  .byte $3F;taker 2
  .byte $00; 1
left_pf2
  .byte $00;taker 3
  .byte $FF; 2
  .byte $00; 3
  .byte $00; 4
  .byte $00; 5
  .byte $FF; 5
  .byte $00; 6
  .byte $00; 6
  .byte $00; 7
  .byte $FF;taker 3
  .byte $00; 1
count
  .byte $08; 8;taker 4
  .byte $04; 4;taker 4
  .byte $04; 4;taker 4
  .byte $04; 4;taker 4
  .byte $80; 128;taker 4
  .byte $04; 4;taker 4
  .byte $80; 128;taker 4
  .byte $04; 4;taker 4
  .byte $04; 4;taker 4
  .byte $04; 4;taker 4
  .byte $08; 8

halfValue
  .byte $96

halfScreen
  .byte $50

lineSets
  .byte $0A

    org $FFFC
    .word Start
    .word Start

Attachment: testfile.bin
Description: Binary data

Current Thread