Mario ASM values

Sep 4th, 2020
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. PlayerFacingDir       = $33
  2. Player_X_Speed        = $57
  3. Player_Y_Speed        = $9f
  4. Player_X_MoveForce    = $0705
  5. Player_Y_MoveForce    = $0433
  6. Player_XSpeedAbsolute = $0700
  7. FrictionAdderHigh     = $0701
  8. FrictionAdderLow      = $0702
  9. RunningSpeed          = $0703
  10. DiffToHaltJump        = $0706
  11. VerticalForce         = $0709
  12. VerticalForceDown     = $070a
  13. MaximumLeftSpeed      = $0450
  14. MaximumRightSpeed     = $0456
  16. JumpspringForce       = $06db
  18. ProcMove:  jsr PlayerPhysicsSub      ;run sub related to jumping and swimming
  19.            lda PlayerChangeSizeFlag  ;if growing/shrinking flag set,
  20.            bne NoMoveSub             ;branch to leave
  21.            lda Player_State
  22.            cmp #$03                  ;get player state
  23.            beq MoveSubs              ;if climbing, branch ahead, leave timer unset
  24.            ldy #$18
  25.            sty ClimbSideTimer        ;otherwise reset timer now
  26. MoveSubs:  jsr JumpEngine
  28.       .dw OnGroundStateSub
  29.       .dw JumpSwimSub
  30.       .dw FallingSub
  31.       .dw ClimbingSub
  33. NoMoveSub: rts
  35. OnGroundStateSub:
  36.          jsr GetPlayerAnimSpeed     ;do a sub to set animation frame timing
  37.          lda Left_Right_Buttons
  38.          beq GndMove                ;if left/right controller bits not set, skip instruction
  39.          sta PlayerFacingDir        ;otherwise set new facing direction
  40. GndMove: jsr ImposeFriction         ;do a sub to impose friction on player's walk/run
  41.         jsr MovePlayerHorizontally ;do another sub to move player horizontally
  42.         sta Player_X_Scroll        ;set returned value as player's movement speed for scroll
  43.          rts
  45. ;--------------------------------
  47. FallingSub:
  48.       lda VerticalForceDown
  49.       sta VerticalForce      ;dump vertical movement force for falling into main one
  50.       jmp LRAir              ;movement force, then skip ahead to process left/right movement
  52. ;--------------------------------
  54. JumpSwimSub:
  55.           ldy Player_Y_Speed         ;if player's vertical speed zero
  56.          bpl DumpFall               ;or moving downwards, branch to falling
  57.          lda A_B_Buttons
  58.          and #A_Button              ;check to see if A button is being pressed
  59.          and PreviousA_B_Buttons    ;and was pressed in previous frame
  60.          bne ProcSwim               ;if so, branch elsewhere
  61.          lda JumpOrigin_Y_Position  ;get vertical position player jumped from
  62.          sec
  63.          sbc Player_Y_Position      ;subtract current from original vertical coordinate
  64.          cmp DiffToHaltJump         ;compare to value set here to see if player is in mid-jump
  65.          bcc ProcSwim               ;or just starting to jump, if just starting, skip ahead
  66. DumpFall: lda VerticalForceDown      ;otherwise dump falling into main fractional
  67.          sta VerticalForce
  68. ProcSwim: lda SwimmingFlag           ;if swimming flag not set,
  69.          beq LRAir                  ;branch ahead to last part
  70.          jsr GetPlayerAnimSpeed     ;do a sub to get animation frame timing
  71.          lda Player_Y_Position
  72.          cmp #$14                   ;check vertical position against preset value
  73.          bcs LRWater                ;if not yet reached a certain position, branch ahead
  74.          lda #$18
  75.          sta VerticalForce          ;otherwise set fractional
  76. LRWater:  lda Left_Right_Buttons     ;check left/right controller bits (check for swimming)
  77.          beq LRAir                  ;if not pressing any, skip
  78.          sta PlayerFacingDir        ;otherwise set facing direction accordingly
  79. LRAir:    lda Left_Right_Buttons     ;check left/right controller bits (check for jumping/falling)
  80.          beq JSMove                 ;if not pressing any, skip
  81.          jsr ImposeFriction         ;otherwise process horizontal movement
  82. JSMove:   jsr MovePlayerHorizontally ;do a sub to move player horizontally
  83.          sta Player_X_Scroll        ;set player's speed here, to be used for scroll later
  84.           lda GameEngineSubroutine
  85.           cmp #$0b                   ;check for specific routine selected
  86.           bne ExitMov1               ;branch if not set to run
  87.           lda #$28
  88.           sta VerticalForce          ;otherwise set fractional
  89. ExitMov1: jmp MovePlayerVertically   ;jump to move player vertically, then leave
  91. PlayerPhysicsSub:
  92.            lda Player_State          ;check player state
  93.            cmp #$03
  94.            bne CheckForJumping       ;if not climbing, branch
  95.            ldy #$00
  96.            lda Up_Down_Buttons       ;get controller bits for up/down
  97.            and Player_CollisionBits  ;check against player's collision detection bits
  98.           beq ProcClimb             ;if not pressing up or down, branch
  99.           iny
  100.           and #%00001000            ;check for pressing up
  101.           bne ProcClimb
  102.           iny
  103. ProcClimb: ldx Climb_Y_MForceData,y  ;load value here
  104.           stx Player_Y_MoveForce    ;store as vertical movement force
  105.           lda #$08                  ;load default animation timing
  106.           ldx Climb_Y_SpeedData,y   ;load some other value here
  107.           stx Player_Y_Speed        ;store as vertical speed
  108.           bmi SetCAnim              ;if climbing down, use default animation timing value
  109.           lsr                       ;otherwise divide timer setting by 2
  110. SetCAnim:  sta PlayerAnimTimerSet    ;store animation timer setting and leave
  111.           rts
  113. CheckForJumping:
  114.        lda JumpspringAnimCtrl    ;if jumpspring animating,
  115.        bne NoJump                ;skip ahead to something else
  116.        lda A_B_Buttons           ;check for A button press
  117.        and #A_Button
  118.        beq NoJump                ;if not, branch to something else
  119.        and PreviousA_B_Buttons   ;if button not pressed in previous frame, branch
  120.        beq ProcJumping
  121. NoJump: jmp X_Physics             ;otherwise, jump to something else
  123. ProcJumping:
  124.           lda Player_State           ;check player state
  125.           beq InitJS                 ;if on the ground, branch
  126.           lda SwimmingFlag           ;if swimming flag not set, jump to do something else
  127.           beq NoJump                 ;to prevent midair jumping, otherwise continue
  128.           lda JumpSwimTimer          ;if jump/swim timer nonzero, branch
  129.           bne InitJS
  130.           lda Player_Y_Speed         ;check player's vertical speed
  131.            bpl InitJS                 ;if player's vertical speed motionless or down, branch
  132.           jmp X_Physics              ;if timer at zero and player still rising, do not swim
  133. InitJS:    lda #$20                   ;set jump/swim timer
  134.           sta JumpSwimTimer
  135.           ldy #$00                   ;initialize vertical force and dummy variable
  136.           sty Player_YMF_Dummy
  137.           sty Player_Y_MoveForce
  138.           lda Player_Y_HighPos       ;get vertical high and low bytes of jump origin
  139.           sta JumpOrigin_Y_HighPos   ;and store them next to each other here
  140.           lda Player_Y_Position
  141.           sta JumpOrigin_Y_Position
  142.           lda #$01                   ;set player state to jumping/swimming
  143.           sta Player_State
  144.           lda Player_XSpeedAbsolute  ;check value related to walking/running speed
  145.           cmp #$09
  146.           bcc ChkWtr                 ;branch if below certain values, increment Y
  147.           iny                        ;for each amount equal or exceeded
  148.           cmp #$10
  149.           bcc ChkWtr
  150.           iny
  151.           cmp #$19
  152.           bcc ChkWtr
  153.           iny
  154.           cmp #$1c
  155.           bcc ChkWtr                 ;note that for jumping, range is 0-4 for Y
  156.           iny
  157. ChkWtr:    lda #$01                   ;set value here (apparently always set to 1)
  158.           sta DiffToHaltJump
  159.           lda SwimmingFlag           ;if swimming flag disabled, branch
  160.           beq GetYPhy
  161.           ldy #$05                   ;otherwise set Y to 5, range is 5-6
  162.           lda Whirlpool_Flag         ;if whirlpool flag not set, branch
  163.           beq GetYPhy
  164.           iny                        ;otherwise increment to 6
  165. GetYPhy:   lda JumpMForceData,y       ;store appropriate jump/swim
  166.           sta VerticalForce          ;data here
  167.           lda FallMForceData,y
  168.           sta VerticalForceDown
  169.           lda InitMForceData,y
  170.           sta Player_Y_MoveForce
  171.           lda PlayerYSpdData,y
  172.           sta Player_Y_Speed
  173.           lda SwimmingFlag           ;if swimming flag disabled, branch
  174.           beq PJumpSnd
  175.           lda #Sfx_EnemyStomp        ;load swim/goomba stomp sound into
  176.           sta Square1SoundQueue      ;square 1's sfx queue
  177.            lda Player_Y_Position
  178.            cmp #$14                   ;check vertical low byte of player position
  179.            bcs X_Physics              ;if below a certain point, branch
  180.            lda #$00                   ;otherwise reset player's vertical speed
  181.           sta Player_Y_Speed         ;and jump to something else to keep player
  182.           jmp X_Physics              ;from swimming above water level
  184. X_Physics: ldy #$00
  185.           sty $00                    ;init value here
  186.           lda Player_State           ;if mario is on the ground, branch
  187.           beq ProcPRun
  188.           lda Player_XSpeedAbsolute  ;check something that seems to be related
  189.           cmp #$19                   ;to mario's speed
  190.            bcs GetXPhy                ;if =>$19 branch here
  191.            bcc ChkRFast               ;if not branch elsewhere
  192. ProcPRun:  iny                        ;if mario on the ground, increment Y
  193.            lda AreaType               ;check area type
  194.            beq ChkRFast               ;if water type, branch
  195.            dey                        ;decrement Y by default for non-water type area
  196.            lda Left_Right_Buttons     ;get left/right controller bits
  197.            cmp Player_MovingDir       ;check against moving direction
  198.            bne ChkRFast               ;if controller bits <> moving direction, skip this part
  199.            lda A_B_Buttons            ;check for b button pressed
  200.            and #B_Button
  201.            bne SetRTmr                ;if pressed, skip ahead to set timer
  202.            lda RunningTimer           ;check for running timer set
  203.            bne GetXPhy                ;if set, branch
  204. ChkRFast:  iny                        ;if running timer not set or level type is water,
  205.            inc $00                    ;increment Y again and temp variable in memory
  206.            lda RunningSpeed
  207.            bne FastXSp                ;if running speed set here, branch
  208.            lda Player_XSpeedAbsolute
  209.            cmp #$21                   ;otherwise check player's walking/running speed
  210.           bcc GetXPhy                ;if less than a certain amount, branch ahead
  211. FastXSp:   inc $00                    ;if running speed set or speed => $21 increment $00
  212.           jmp GetXPhy                ;and jump ahead
  213. SetRTmr:   lda #$0a                   ;if b button pressed, set running timer
  214.           sta RunningTimer
  215. GetXPhy:   lda MaxLeftXSpdData,y      ;get maximum speed to the left
  216.           sta MaximumLeftSpeed
  217.           lda GameEngineSubroutine   ;check for specific routine running
  218.           cmp #$07                   ;(player entrance)
  219.           bne GetXPhy2               ;if not running, skip and use old value of Y
  220.           ldy #$03                   ;otherwise set Y to 3
  221. GetXPhy2:  lda MaxRightXSpdData,y     ;get maximum speed to the right
  222.           sta MaximumRightSpeed
  223.           ldy $00                    ;get other value in memory
  224.           lda FrictionData,y         ;get value using value in memory as offset
  225.           sta FrictionAdderLow
  226.           lda #$00
  227.           sta FrictionAdderHigh      ;init something here
  228.           lda PlayerFacingDir
  229.           cmp Player_MovingDir       ;check facing direction against moving direction
  230.           beq ExitPhy                ;if the same, branch to leave
  231.           asl FrictionAdderLow       ;otherwise shift d7 of friction adder low into carry
  232.           rol FrictionAdderHigh      ;then rotate carry onto d0 of friction adder high
  233. ExitPhy:   rts                        ;and then leave
  235. ChkSkid:    lda SavedJoypadBits        ;get controller bits
  236.            and #%01111111             ;mask out A button
  237.            beq SetAnimSpd             ;if no other buttons pressed, branch ahead of all this
  238.            and #$03                   ;mask out all others except left and right
  239.            cmp Player_MovingDir       ;check against moving direction
  240.            bne ProcSkid               ;if left/right controller bits <> moving direction, branch
  241.            lda #$00                   ;otherwise set zero value here
  242. SetRunSpd:  sta RunningSpeed           ;store zero or running speed here
  243.            jmp SetAnimSpd
  244. ProcSkid:   lda Player_XSpeedAbsolute  ;check player's walking/running speed
  245.             cmp #$0b                   ;against one last amount
  246.             bcs SetAnimSpd             ;if greater than this amount, branch
  247.             lda PlayerFacingDir
  248.             sta Player_MovingDir       ;otherwise use facing direction to set moving direction
  249.             lda #$00
  250.             sta Player_X_Speed         ;nullify player's horizontal speed
  251.            sta Player_X_MoveForce     ;and dummy variable for player
  253. ImposeFriction:
  254.           and Player_CollisionBits  ;perform AND between left/right controller bits and collision flag
  255.           cmp #$00                  ;then compare to zero (this instruction is redundant)
  256.           bne JoypFrict             ;if any bits set, branch to next part
  257.           lda Player_X_Speed
  258.           beq SetAbsSpd             ;if player has no horizontal speed, branch ahead to last part
  259.           bpl RghtFrict             ;if player moving to the right, branch to slow
  260.           bmi LeftFrict             ;otherwise logic dictates player moving left, branch to slow
  261. JoypFrict: lsr                       ;put right controller bit into carry
  262.           bcc RghtFrict             ;if left button pressed, carry = 0, thus branch
  263. LeftFrict: lda Player_X_MoveForce    ;load value set here
  264.           clc
  265.           adc FrictionAdderLow      ;add to it another value set here
  266.           sta Player_X_MoveForce    ;store here
  267.           lda Player_X_Speed
  268.           adc FrictionAdderHigh     ;add value plus carry to horizontal speed
  269.           sta Player_X_Speed        ;set as new horizontal speed
  270.           cmp MaximumRightSpeed     ;compare against maximum value for right movement
  271.           bmi XSpdSign              ;if horizontal speed greater negatively, branch
  272.           lda MaximumRightSpeed     ;otherwise set preset value as horizontal speed
  273.           sta Player_X_Speed        ;thus slowing the player's left movement down
  274.            jmp SetAbsSpd             ;skip to the end
  275. RghtFrict: lda Player_X_MoveForce    ;load value set here
  276.            sec
  277.            sbc FrictionAdderLow      ;subtract from it another value set here
  278.            sta Player_X_MoveForce    ;store here
  279.            lda Player_X_Speed
  280.            sbc FrictionAdderHigh     ;subtract value plus borrow from horizontal speed
  281.            sta Player_X_Speed        ;set as new horizontal speed
  282.            cmp MaximumLeftSpeed      ;compare against maximum value for left movement
  283.            bpl XSpdSign              ;if horizontal speed greater positively, branch
  284.            lda MaximumLeftSpeed      ;otherwise set preset value as horizontal speed
  285.            sta Player_X_Speed        ;thus slowing the player's right movement down
  286. XSpdSign:  cmp #$00                  ;if player not moving or moving to the right,
  287.           bpl SetAbsSpd             ;branch and leave horizontal speed value unmodified
  288.           eor #$ff
  289.           clc                       ;otherwise get two's compliment to get absolute
  290.            adc #$01                  ;unsigned walking/running speed
  291. SetAbsSpd: sta Player_XSpeedAbsolute ;store walking/running speed here and leave
  292.            rts
  294. MovePlayerHorizontally:
  295.       lda JumpspringAnimCtrl  ;if jumpspring currently animating,
  296.       bne ExXMove             ;branch to leave
  297.       tax                     ;otherwise set zero for offset to use player's stuff
  299. MovePlayerVertically:
  300.         ldx #$00                ;set X for player offset
  301.         lda TimerControl
  302.         bne NoJSChk             ;if master timer control set, branch ahead
  303.         lda JumpspringAnimCtrl  ;otherwise check to see if jumpspring is animating
  304.         bne ExXMove             ;branch to leave if so
  305. NoJSChk: lda VerticalForce       ;dump vertical force
  306.         sta $00
  307.         lda #$04                ;set maximum vertical speed here
  308.         jmp ImposeGravitySprObj ;then jump to move player vertically
RAW Paste Data Copied