Advertisement
Guest User

UberASM Merged

a guest
Mar 10th, 2017
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;Insert this as gamemode 14 under "main:"
  2.  
  3. incsrc "../SSPDef/Defines.asm"
  4.  
  5. !Freeram_PipeCannonState = $13E6+!addr
  6. ;^[1 byte], the state mario would be when in pipe.
  7.  
  8. !Freeram_PipeCannonTmr = $13E7+!addr
  9. ;^[1 byte], the timer when mario switches action.
  10.  
  11. !freeram_door_dir = $1473+!addr     ;>change this if used by other stuff
  12.  
  13. main:
  14. .ScreenScrollingPipes:
  15.     LDA !Freeram_PipeDir        ;\don't do anything while outside the pipe.
  16.     ORA !Freeram_PipeTmr        ;|
  17.     BNE ..PipeCodeStart     ;|
  18.     JMP ..PipeCodeReturn        ;/
  19.  
  20. ;-------------------------------------------------------
  21. ;Speed tables, Do not change the cap speeds.
  22. ;-------------------------------------------------------
  23. ;         unused| Stem speed   |   Cap speed   |
  24. ;            -   U   R   D   L   U   R   D   L
  25. ;indexes:        0   1   2   3   4   5   6   7   8
  26. ..pipe_x_spd db $00,$00,$20,$00,$E0,$00,$08,$00,$F8 ;>x Speed.
  27. ..pipe_y_spd db $00,$E0,$00,$20,$00,$F0,$00,$10,$00 ;>y speed.
  28.  
  29.  
  30. ;Don't touch these unless you remap the poses: [beta stuff]
  31. ;WalkingFrames:
  32. ;db $00,$00,$00,$00,$01,$01,$01,$01,$02,$02,$02,$02
  33.  
  34. ;---------------------------------
  35. ;This sets mario's status
  36. ;---------------------------------
  37.     ..PipeCodeStart
  38.     ...MarioStatus
  39.     LDA !Freeram_CarrySpr   ;\fix automatic drop item when carrying
  40.     BEQ ....NotCarrying ;|
  41.     LDA #$40        ;|
  42.     BRA ....SetControls ;|
  43.  
  44.     ....NotCarrying
  45.     LDA #$00        ;/
  46.  
  47.     ....SetControls
  48.     STA $15         ;\lock controls
  49.     STZ $16         ;|
  50.     STZ $17         ;|
  51.     STZ $18         ;/
  52.     STZ $13F3+!addr     ;\remove p-balloon
  53.     STZ $1891+!addr     ;/
  54.     STZ $1697+!addr     ;>remove consecutive stomps.
  55.     STZ $140D+!addr     ;>so fire mario cannot shoot fireballs in pipe
  56.  
  57.     LDA !Freeram_EntrExtFlg ;\hide player if timer hits zero when entering.
  58.     CMP #$02        ;|
  59.     BEQ ....NoHide      ;|
  60.     LDA !Freeram_PipeTmr    ;|
  61.     BNE ....NoHide      ;|
  62.     if !PipeDebug == 0
  63.         LDA #$FF    ;|
  64.         STA $78     ;/
  65.     endif
  66.  
  67.     ....NoHide
  68.     LDA $187A+!addr     ;\if on yoshi, then use yoshi poses
  69.     BNE ....OnYoshi     ;/
  70.     STZ $73         ;>so mario cannot remain ducking (unless on yoshi) as he exits.
  71.  
  72.     ....OnYoshi
  73.     LDA !Freeram_PipeDir    ;\different yoshi pose, If going vertical, then yoshi faces the screen.
  74.     CMP #$01        ;|(this should make mario carry carryable sprites in center of him facing the screen)
  75.     BEQ ....YoshiFaceScreen ;|
  76.     CMP #$03        ;|
  77.     BEQ ....YoshiFaceScreen ;|
  78.     CMP #$05        ;|
  79.     BEQ ....YoshiFaceScreen ;|
  80.     CMP #$07        ;|
  81.     BEQ ....YoshiFaceScreen ;/
  82.  
  83.     ....YoshiDuck       ;>horizontal pipe
  84.     LDA $187A+!addr     ;\Do not duck if not riding yoshi.
  85.     BEQ ....NoDuck      ;/
  86.     LDA #$04        ;\crouch on yoshi
  87.     STA $73         ;/
  88.  
  89.     ....NoDuck
  90.     LDA #$01            ;|(this should make mario face left or right carrying sprites to the side)
  91.     BRA ....SkipYoshiFaceScrn   ;/
  92.  
  93.     ....YoshiFaceScreen ;\yoshi face the screen (vertical pipe, Nintendo did this so that yoshi's head
  94.     LDA #$02        ;/doesn't display a glitch graphic).
  95.  
  96.     ....SkipYoshiFaceScrn
  97.     STA $1419+!addr     ;>Even if you are not mounted on yoshi, you still have to write a value here, or carrying sprites don't work.
  98.  
  99.     ....SkipYoshiPose
  100.     if !PipeDebug == 0
  101.         LDA #$01        ;\go behind layers
  102.         STA $13F9+!addr     ;/
  103.     endif
  104.     LDA #$0B        ;\freeze time
  105.     STA $71         ;|
  106.     STA $9D         ;/
  107.     LDA #$01        ;\allow vertical scroll up.
  108.     STA $1404+!addr     ;/
  109.     STZ $14A6+!addr     ;>no spinning.
  110.     STZ $1407+!addr     ;>so mario cannot fly out of the cap
  111.     STZ $72         ;>zero air flag.
  112.     STZ $14A3+!addr     ;>no yoshi tongue
  113.     LDA !Freeram_CarrySpr   ;\if mario not carrying anything, then skip
  114.     BEQ ....NotCarry    ;/
  115.     LDA #$01        ;\force keep carrying
  116.     STA $1470+!addr     ;|
  117.     STA $148F+!addr     ;/
  118.  
  119.     ....NotCarry
  120.     LDA !Freeram_PipeDir    ;\set player speed within pipe (use transfer commands
  121.     TAY         ;|so you can use long freeram address)
  122.     LDA ..pipe_x_spd,y  ;|
  123.     STA $7B         ;|
  124.     LDA ..pipe_y_spd,y  ;|
  125.     STA $7D         ;/
  126. ;-------------------------------
  127. ;Entering and exiting
  128. ;-------------------------------
  129.     ...EnterExitTransition
  130.     LDA !Freeram_EntrExtFlg ;>If mario is out of a pipe and is entering them...
  131.     BNE ....InPipe      ;>if not 0, skip
  132.     JMP ..PipeCodeReturn    ;>branch out of range
  133.  
  134.     ....InPipe
  135.     CMP #$01        ;\If entering a pipe...
  136.     BEQ ....entering_pipe   ;/
  137.     CMP #$02        ;\If exiting a pipe...
  138.     BEQ ....ExitingPipe ;/
  139.     JMP ..PipeCodeReturn
  140.  
  141.     ....entering_pipe   ;
  142.     LDA !Freeram_PipeTmr    ;\If timer is 0, set pose
  143.     BEQ ...pose     ;/
  144.     DEC A           ;\Otherwise decrement it
  145.     STA !Freeram_PipeTmr    ;/
  146.     BEQ ....accel       ;>If decremented from 1 to 0, accelerate for stem speed
  147.     BRA ...pose     ;>Otherwise still set pose.
  148.  
  149.     ....accel
  150.     LDA !Freeram_PipeDir    ;\Use another set of 4 speeds.
  151.     SEC         ;|
  152.     SBC #$04        ;/
  153.     BMI ....AccelDone   ;>Prevent continously decrementing into negative
  154.     STA !Freeram_PipeDir    ;>And set pipe direction
  155.  
  156.     ....AccelDone
  157.     BRA ...pose
  158.  
  159.     ....ExitingPipe     ;
  160.     LDA !Freeram_PipeTmr    ;\if timer already = 0, then skip the reset (so it does it once).
  161.     BEQ ...pose     ;/
  162.     DEC A           ;\otherwise decrement timer.
  163.     STA !Freeram_PipeTmr    ;/
  164.     BEQ ...ResetStatus  ;>Reset status if timer hits zero (happens once after -1 to 0).
  165.  
  166.     ;decel
  167.     LDA !Freeram_PipeDir    ;\Use the first 4 speeds (excluding index 0)
  168.     CLC         ;|
  169.     ADC #$04        ;/
  170.     CMP #$09        ;\Prevent incrementing beyond the 8th index
  171.     BCS ...pose     ;/
  172.     STA !Freeram_PipeDir        ;>Set direction
  173.     BRA ...pose     ;>and skip the reset routine
  174. ;---------------------------------
  175. ;This resets mario's status.
  176. ;It must be exceuted once.
  177. ;---------------------------------
  178.     ...ResetStatus
  179.     LDA !Freeram_CarrySpr   ;\Holding sprites routine
  180.     BEQ ....NotCarry1   ;|
  181.     LDA #$40        ;|
  182.     BRA ....SkipNtCarry1    ;|
  183.  
  184.     ....NotCarry1       ;|
  185.     LDA #$00        ;|
  186.  
  187.     ....SkipNtCarry1    ;|
  188.     STA $15         ;/
  189.     STZ $9D         ;>back in motion
  190.     STZ $13F9+!addr     ;>go in front
  191.     STZ $71         ;>mario can move
  192.     STZ $73         ;>stop crouching (when going exiting down on yoshi)
  193.     STZ $140D+!addr     ;>no spinjump out the pipe (possable if both enter and exit caps are bottoms)
  194.     STZ $7B         ;\cancel speed
  195.     STZ $7D         ;/
  196.     STZ $1419+!addr     ;>revert yoshi
  197.     STZ $149F+!addr     ;>zero cape "rise up timer"
  198.     LDA #$00        ;\reset freeram flags
  199.     STA !Freeram_PipeDir    ;|
  200.     STA !Freeram_PipeTmr    ;|
  201.     STA !Freeram_CarrySpr   ;|
  202.     STA !Freeram_EntrExtFlg ;/>Make code assume mario is out of the pipe.
  203.  
  204.     JMP ..PipeCodeReturn
  205. ;-----------------------------------------
  206. ;code that controls mario's pose
  207. ;-----------------------------------------
  208. ...pose
  209.     LDA !Freeram_PipeDir    ;\set pose according to direction.
  210.     CMP #$01        ;|\Vertical direction
  211.     BEQ ....Vert        ;||
  212.     CMP #$03        ;||
  213.     BEQ ....Vert        ;||
  214.     CMP #$05        ;||
  215.     BEQ ....Vert        ;||
  216.     CMP #$07        ;||
  217.     BEQ ....Vert        ;|/
  218.     CMP #$02        ;|\Horizontal direction
  219.     BEQ ....Horiz       ;||
  220.     CMP #$04        ;||
  221.     BEQ ....Horiz       ;||
  222.     CMP #$06        ;||
  223.     BEQ ....Horiz       ;||
  224.     CMP #$08        ;||
  225.     BEQ ....Horiz       ;//
  226.  
  227.     ....Vert
  228.     LDA $187A+!addr     ;\if mario is riding yoshi, then
  229.     BNE ....YoshiFaceScrn   ;/use face screen instead
  230.     LDA #$0F        ;>vertical pipe pose (without regard to powerup status)
  231.     BRA ....SetPose
  232.  
  233.     ....Horiz
  234.     LDA $187A+!addr     ;\if mario is riding yoshi, then
  235.     BNE ....YoshiFaceHoriz  ;/use "ride yoshi" pose
  236.     LDA #$00
  237.     BRA ....SetPose
  238.  
  239.     ....YoshiFaceScrn
  240.     LDA #$21        ;>pose that mario turns around partically face the screen
  241.     BRA ....SetPose
  242.  
  243.     ....YoshiFaceHoriz
  244.     LDA #$1D        ;>crouch as entering a horizontal pipe on yoshi.
  245.  
  246.     ....SetPose
  247.     STA $13E0+!addr     ;>set player pose
  248.  
  249.     ..PipeCodeReturn
  250.     JSR .PipeCannon
  251.     RTL
  252.    
  253. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  254. ;Paste this in level code in levels you are going to use this.
  255. ;If you wanted multiple levels to use this, simply use JSR PipeCannon
  256. ;to recycle the code (but make sure there are no codes below this code
  257. ;that you wanted it to execute in specific levels, if true then instead
  258. ;of pasting in the levels, paste it past the last RTS at the very bottom
  259. ;and have any levels that use this code all use JSR PipeCannon).
  260. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  261.  
  262.  
  263. .PipeCannon:
  264.     LDA $71                    ;\If dying, don't continue cannon mode.
  265.     CMP #$09                   ;|(fixes time limit bug)
  266.     BNE ..NotDying              ;|
  267.     JML ..Return                ;/
  268. ..NotDying
  269.     LDA !Freeram_PipeCannonTmr ;\Decrement timer
  270.     DEC A                      ;/
  271.     BMI ..NoDecrement           ;>If negative, don't decrement
  272.     STA !Freeram_PipeCannonTmr ;>Store to decrement (#$00 is the smallest value)
  273. ..NoDecrement
  274.  
  275.     LDA !Freeram_PipeCannonState  ;>Load state into A
  276.     BEQ ..NoState                  ;>Allow mario to have control if #$00
  277.     PHA                           ;>This is faster
  278.     LDA #$0B                      ;\Throughout the launch, mario cannot
  279.     STA $71                       ;/move.
  280.     PLA                           ;>Restore it
  281. ..NoState
  282.     ASL                           ;>Left shift bits (*2, because each address has 2 bytes).
  283.     TAX                           ;>Index it with X
  284.     JMP.w (..States,x)
  285.  
  286. ..States
  287.     dw ..Return                    ;>#$00
  288.     dw ...Entering                 ;>#$01
  289.     dw ...Waiting                  ;>#$02
  290.     dw ...PriorShoot               ;>#$03
  291.     dw ...Shoot                    ;>#$04
  292.     dw ..SelfReset                 ;>#$05
  293. ;;;;;;;;;;;;;;;;;;;;;;;;
  294. ...Entering
  295.     LDA !Freeram_PipeCannonTmr ;\If timer runs out, goto next state
  296.     BEQ ....NextState           ;/
  297.     LDA #$01                   ;>Set...
  298.     STA $9D                    ;>...Freeze time
  299.     STA $13F9+!addr            ;>...Behind layers
  300.     LDA #$0F                   ;\Set pose
  301.     STA $13E0+!addr            ;/
  302.     LDA #$10                   ;\Set speed
  303.     STA $7D                    ;/
  304.     STZ $7B                    ;>Blocks don't perfectly halt x speed.
  305.     JMP ..Return
  306.  
  307. ....NextState
  308.     LDA #$02                        ;\Switch state to waiting
  309.     STA !Freeram_PipeCannonState    ;/
  310.     LDA.b #60                       ;\Set timer of the waiting
  311.     STA !Freeram_PipeCannonTmr      ;/
  312.     LDA #$01                        ;>Set...
  313.     STA $13F9+!addr                 ;>...Behind layers (without this, mario goes in front for 1 frame
  314.     BRA ..Return
  315.  
  316. ...Waiting
  317.     LDA !Freeram_PipeCannonTmr ;\If timer runs out, goto next state
  318.     BEQ ....NextState          ;/
  319.     LDA #$01                   ;>Set...
  320.     STA $9D                    ;>...Freeze time
  321.     STA $13F9+!addr            ;>...Behind layers
  322.     STZ $7D                    ;>Stop Y speed
  323.     BRA ..Return
  324.  
  325. ....NextState
  326.     LDA #$03                        ;\Set state to prior shoot
  327.     STA !Freeram_PipeCannonState    ;/
  328.     LDA #$09                        ;\SFX
  329.     STA $1DFC+!addr                 ;/
  330.     LDA.b #04                       ;\Set timer for the go in front of layers (for prior shoot)
  331.     STA !Freeram_PipeCannonTmr      ;/(he must go in front as soon mario gets completly out of pipe)
  332.     STZ $9D                         ;>Unfreeze game
  333.     LDA #$01                        ;>Set...
  334.     STA $13F9+!addr                 ;>...Behind layers (without this, mario goes in front for 1 frame).
  335.     BRA ..Return
  336.  
  337. ...PriorShoot
  338.     LDA !Freeram_PipeCannonTmr      ;\If timer runs out, goto next state
  339.     BEQ ....NextState               ;/
  340.     LDA #$01                        ;\Behind layer as you exit.
  341.     STA $13F9+!addr                 ;/
  342.     STZ $73                         ;>Prevent crouching if mairo crouch slide into cannon.
  343.     LDA #$01                        ;\Behind layers (without this, mario goes in front for 1 frame).
  344.     STA $13F9+!addr                 ;/
  345.     BRA ..SharedCode
  346.  
  347. ....NextState
  348.     LDA #$04                        ;\Set state to post shoot
  349.     STA !Freeram_PipeCannonState    ;/
  350.     LDA #$00                        ;\Clear timer since this last state no longer uses the timer.
  351.     STA !Freeram_PipeCannonTmr      ;/
  352.     LDA #$01                        ;\Behind layers (without this, mario goes in front for 1 frame).
  353.     STA $13F9+!addr                 ;/
  354.     BRA ..Return
  355.  
  356. ...Shoot
  357.     STZ $13F9+!addr            ;>Go in front of layers
  358. ..SharedCode
  359.     LDA #$80                     ;\Shoot player upwards
  360.     STA $7D                      ;/
  361.     LDA #$0B                     ;\Up jump pose
  362.     STA $13E0+!addr              ;|
  363.     STA $72                      ;/
  364.     LDA #$01                     ;\Screen scrolls up.
  365.     STA $1404+!addr              ;/
  366.     LDA $77                      ;\If mario hits a ceiling...
  367.     AND.b #%00001000             ;|
  368.     BEQ ...NotBlocked             ;/
  369.     LDA #$00                     ;\Then cancel out cannon mode
  370.     STA !Freeram_PipeCannonState ;/
  371.     STA $71                      ;>Allow movement.
  372. ...NotBlocked
  373.     BRA ..Return
  374. ..SelfReset
  375.     STZ !Freeram_PipeCannonState ;\This needed to be cleared for 1 frame or there will be
  376.     STZ $71                      ;/glitches.
  377. ..Return
  378.     JSR .SSDoorRoutine
  379.     RTS
  380.    
  381. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  382. ;do not insert this as blocks. This is a non-block ASM code for the
  383. ;screen scrolling doors. put this in gamemode_code.asm in "gamemode_14:"
  384. ;or level_code.asm (if multiple levels, use "JSR levelxxx" to a level that
  385. ;have this code to recycle code and save space).
  386. ;
  387. ;if you wanted to edit the speed, go to the table on the bottom of
  388. ;this code, and change the value.
  389. ;
  390. ;TIP: To have "equal" positive (#$01-#$7F) and negative (#$80-#$FF) speed,
  391. ;use this forumla (all in hex):
  392. ;
  393. ;N=100-P
  394. ;
  395. ;N = negative (left and up speed)
  396. ;P = positive (right and down speed)
  397. ;
  398. ;tip2:
  399. ;you can instantly copy this code by pressing "ctrl+A" to select all then
  400. ;"ctrl+C" to copy
  401. ;
  402. ;freeram address------------------------------------------------------------
  403. ;
  404.  
  405. ;                   ;besides the screen scrolling doors.
  406. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;code begins;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  407. .SSDoorRoutine:
  408.     LDA !freeram_door_dir       ;\if door_mode mode is 00 (not launching)
  409.     BEQ ..returndoor            ;/then return_door_mode
  410.     TAY                         ;\set x and Y speed according to direction
  411.     LDA ..x_speed_table,y       ;|
  412.     STA $7B                     ;|
  413.     LDA ..y_speed_table,y       ;|
  414.     STA $7D                     ;/
  415.     LDA !freeram_door_dir       ;\if going left or right
  416.     CMP #$02                    ;|set facing direction
  417.     BEQ ..face_right            ;|
  418.     CMP #$04                    ;|
  419.     BEQ ..face_left             ;/
  420.     BRA ..skip_face_dir         ;>or don't set it at all if vertical
  421. ..face_right                    ;\set facing direction
  422.     LDA #$01                    ;|
  423.     STA $76                     ;|
  424.     BRA ..skip_face_dir         ;|
  425. ..face_left                     ;|
  426.     STZ $76                     ;/
  427. ..skip_face_dir
  428.     STZ $15             ;\
  429.     STZ $16             ;|lock controls while door mode
  430.     STZ $17             ;|
  431.     STZ $18             ;/
  432.     STZ $149A+!addr     ;>remove kick pose if player enters door immediately after kicking.
  433.     LDA #$FF            ;\hide player
  434.     STA $78             ;/
  435.     LDA #$0B            ;\freeze player (so $9D works)
  436.     STA $71             ;/
  437.     STA $9D             ;>lock animations
  438.     STA $1404+!addr     ;>allow screen to scroll up.
  439.     LDA #$01            ;>load nonzero
  440.     STA $1497+!addr     ;>set Flashing invulnerability timer
  441.     STA $13F9+!addr     ;>go behind layer
  442.     STA $73             ;>maintain ducking flag
  443. ..returndoor
  444.     RTS         ;>if you have a following code from here
  445.                 ;then move the table that was below here
  446.                 ;to the very bottom and have the other codes
  447.                 ;between here and the table below.
  448. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  449. ;x and y speed table. Make sure that the table is right after (or below) the
  450. ;codes that points to it (so this table is after "LDA x_speed_table,y being
  451. ;used), or the game will crash.
  452. ;
  453. ;Each seprate number is a value for mario x and y speed, the order in the table
  454. ;corrosponds the value order present within the selected ram. For example: the
  455. ;first number in the table means that the ram is #$00, the 2nd number is when
  456. ;the ram address = #$01 and so on.
  457. ;(order from left to right)
  458. ;1st number = not used
  459. ;2nd number = up
  460. ;3rd number = right
  461. ;4th number = down
  462. ;5th number = left
  463. ;
  464. ;If you change this, you should also change how many pixels down
  465. ;from the center of the door that mario will exit upwards from
  466. ;door_down.asm in the blocks' definition.
  467. ;
  468. ..x_speed_table
  469.     db $00,$00,$2F,$00,$D1
  470.     RTS
  471. ..y_speed_table
  472.     db $00,$D1,$00,$2F,$00
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement