;This patches causes the screen to orientate so that the player is always in the center. !FreeramLinePosH = $60 ;[2 bytes] X position of the line the player will be when moving the screen horizontally. !FreeramDir = $62 ;[1 byte], bits to determine scrolling direction. ;!FreeramDir is a bitwise that indicate the direction of scrolling the screen, format: UDLRudlr. Uppercase ;is screen lock direction, if set, won't scroll in that direction. Lowercase is the current scroll direction ;by the player. Also, the lowercase bits are still set, even if that particular direction is locked. ;Note that this is not finished! ;issues: ; ;-scrolling left doesn't load layer 1 correctly ;-background layer 2 scrolling doesn't work ; ;currently working: ;future features: ;-A shovel knight-styled scrolling screen after hitting the edge of an area. ; ; org $00F71A autoclean JML ScreenScroll freecode ScreenScroll: REP #$20 LDA #$0078 ;\debug. STA !FreeramLinePosH ;/ LDA $94 ;\Let $00~$01 holds the x-coordinates of the player SEC ;|within the borders of the screen in next frame. SBC $1A ;| STA $00 ;/ SEP #$20 LDA $0100 CMP #$12 ;level load 12 REP #$20 BNE skip LDA $00 SEC SBC !FreeramLinePosH JSL AdjustScreenH SEP #$20 JMP done skip: LDA $00 CMP !FreeramLinePosH ; SEP #$20 BNE + ;BEQ NoScroll ;>If mario is exactly on the line, Don't move. JML NoScroll + BPL ScrollRight ;>If mario is right of the line ;ScrollLeft: LDA !FreeramDir ;\Set going left direction bit to indicate the player ORA.b #%00000010 ;|is trying to scroll the screen. STA !FreeramDir ;/ STZ $55 STZ $56 LDA !FreeramDir ;\If left direction locked, then don't scroll. AND.b #%00100000 ;| BNE NoScrollLeft ;/ REP #$20 LDA !FreeramLinePosH ;\If mario is less than 8 pixels left from SEC ;|the line, then snap the screen to the player instantly. SBC $00 ;| CMP #$0008 ;| BCC SnapScreenPosLft ;/ LDA $1462 ;\Otherwise, if the player is too far to the left, then SEC ;|gradually move the screen left SBC #$0008 ;| JSL AdjustScreenH ;/ SEP #$20 NoScrollLeft: BRA done SnapScreenPosLft: LDA !FreeramLinePosH SEC SBC $00 STA $02 LDA $1462 SEC SBC $02 JSL AdjustScreenH SEP #$20 BRA done ScrollRight: LDA !FreeramDir ;\Set going left direction bit to indicate the player ORA.b #%00000010 ;|is trying to scroll the screen. STA !FreeramDir ;/ LDA #$02 STA $55 STA $56 LDA !FreeramDir ;\If right direction locked, then don't scroll AND.b #%00010000 ;| BNE NoScrollRight ;/ REP #$20 LDA $00 ;\If mario is less than 8 pixels right from SEC ;|the line, then snap the screen to the player instantly. SBC !FreeramLinePosH ;| CMP #$0008 ;| BCC SnapScreenPosRgt ;/ LDA $1462 ;\Otherwise, if the player is too far to the right, then CLC ;|gradually move the screen right ADC #$0008 ;| JSL AdjustScreenH ;/ SEP #$20 NoScrollRight: BRA done SnapScreenPosRgt: LDA $00 SEC SBC !FreeramLinePosH STA $02 LDA $1462 CLC ADC $02 JSL AdjustScreenH SEP #$20 BRA done NoScroll: LDA !FreeramDir ;\Clear left and right bits. AND.b #%11111100 ;| STA !FreeramDir ;/ done: JML $00F7A2 PLB RTL AdjustScreenH: STA $04 ;>save for later ;STA $1462 BMI PastLeftEdge ;>If screen x pos < 0, then set it to zero ; LDA $5E ;\If screen x pos > last screen, then set it to position as ; AND #$FF00 ;|last screen. ; CMP $1462 ;| ; BMI PastRightEdge ;/ LDA $04 STA $1462 RTL PastLeftEdge: STZ $1462 RTL PastRightEdge: STA $1462 RTL