Advertisement
Guest User

Custom scrolling

a guest
Jun 7th, 2019
281
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. init:
  2.     STZ $1411
  3. RTL
  4.  
  5. main:
  6.     STZ $04 : STZ $05 : STZ $06 ; Clear some scratch RAM
  7.     LDX #$0C ; > Set-up for a loop through the sprites
  8.     -
  9.         DEX   ; \ Leave the loop if we ran out of sprites
  10.         BMI + ; /
  11.         LDA $9E,X ; \ Keep looping if the sprite isn't a
  12.         CMP #$63  ; |   checkerboarded/brown line-guided platform
  13.         BNE -     ; /
  14.         LDA $14C8,X ; \ O and it has to be alive
  15.         CMP #$08    ; |
  16.         BMI -       ; /
  17.         LDA $04         ; \
  18.         CLC : ADC $E4,X ; | Add the position of the sprite to $04
  19.         STA $04         ; |
  20.         LDA $05         ; |
  21.         ADC $14E0,X     ; |
  22.         STA $05         ; /
  23.         INC $06 ; > Hey, we found one!
  24.         LDA $06 : CMP #$02 ; \ Stop looking after we found 2
  25.     BNE -                  ; /
  26.         LSR $05 ; \ Divide $04 by 2
  27.         ROR $04 ; /
  28.     -
  29.         LDA $04        ; \
  30.         SEC : SBC #$80 ; | Subtract 0x80 from the average to find the camera
  31.         STA $04        ; |   position
  32.         LDA $05        ; |
  33.         SBC #$00       ; /
  34.         BMI ++         ; \ Set $04 if its value is position
  35.             STA $05    ; /
  36.             REP #$30   ; \ And update all the relevant RAM addresses
  37.         BRA .moveFix   ; /
  38.         ++       ; \ Otherwise, set the camera position to 0
  39.         REP #$30 ; |
  40.         STZ $04  ; /
  41.     BRA .moveFix ; > Update all the relevant RAM addresses
  42.     +       ; > If we ran out of sprites to search
  43.     LDA $06 ; > And we found a sprite
  44.     BNE -   ; > Don't divide $04 by 2
  45.     LDA #$01  ; \ If we found no sprites, then center the camera around mario
  46.     STA $1411 ; /
  47. RTL
  48. .moveFix ; > This sets all the relevant RAM addresses
  49.     LDA $04
  50.     STA $1462
  51.     LDA $1A
  52.     SEC : SBC $04
  53.     SEP #$30
  54.     LDA $17BD
  55.     LDA $04 : STA $1A
  56.     LDA $05 : STA $1B
  57. RTL
Advertisement
RAW Paste Data Copied
Advertisement