ThomasSpeedrunner

Level routine (modded)

Sep 1st, 2014
345
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; ---------------------------------------------------------------------------
  2. ; Level
  3. ; ZONE/SPECIAL STAGE LOOP (MLS values $08, $0C, and $10; bit 7 set indicates
  4. ; that the load routine is running)
  5. ; ---------------------------------------------------------------------------
  6. ; loc_3EC4:
  7. Level:
  8.     move.b  (Game_Mode).w,(Game_Mode_Copy).w
  9.     bset    #7,(Game_Mode).w ; add $80 to screen mode (for pre level sequence)
  10.     tst.w   (Demo_mode_flag).w
  11.     bmi.s   +
  12.     move.b  #$79+$80,d0
  13.     bsr.w   PlaySound_Special   ; fade out music
  14. +
  15.     bsr.w   ClearPLC
  16.     bsr.w   Pal_FadeFrom
  17.     tst.w   (Demo_mode_flag).w
  18.     bmi.w   Level_ClrRam
  19.     move    #$2700,sr
  20.     bsr.w   ClearScreen
  21.     jsr (LoadTitleCard).l ; load title card patterns
  22.     move    #$2300,sr
  23.     moveq   #0,d0
  24.     move.w  d0,(Timer_frames).w
  25.     move.b  (Current_Zone).w,d0
  26.     cmpi.b  #$10,(Game_Mode_Copy).w
  27.     bne.w   +
  28.     moveq   #0,d0
  29.     move.b  (Current_Special_Stage+1).w,d0
  30. +
  31.     ; multiply d0 by 12, the size of a level art load block
  32.     add.w   d0,d0
  33.     add.w   d0,d0
  34.     move.w  d0,d1
  35.     add.w   d0,d0
  36.     add.w   d1,d0
  37.  
  38.     cmpi.b  #$10,(Game_Mode_Copy).w         ; HOLD UP! Are we in a special stage?
  39.     bne.w   +                   ; If we are not, branch. Otherwise...
  40.     lea (SpecialStageArtPointers).l,a2      ; ...load the special stage art pointers to a2 instead.
  41.     bra.w   ++
  42. +
  43.     lea (LevelArtPointers).l,a2         ; Load the level art pointers to a2.
  44. +
  45.     lea (a2,d0.w),a2
  46.     moveq   #0,d0
  47.     move.b  (a2),d0
  48.     beq.s   +
  49.     bsr.w   LoadPLC
  50. +
  51.     moveq   #1,d0
  52.     bsr.w   LoadPLC
  53.     bsr.w   sub_4450
  54.     moveq   #6,d0
  55.     tst.w   (Two_player_mode).w
  56.     bne.s   +
  57.     cmpi.w  #2,(Player_mode).w
  58.     bne.s   Level_ClrRam
  59.     addq.w  #1,d0
  60. +
  61.     tst.b   (Graphics_Flags).w
  62.     bpl.s   +
  63.     addq.w  #2,d0
  64. +
  65.     bsr.w   LoadPLC
  66. ; loc_3F48:
  67. Level_ClrRam:
  68.     clr.b   (Super_Sonic_flag).w
  69.     clr.w   (Closest_Object_X_Dist).w
  70.     clr.w   (Closest_Object_Y_Dist).w
  71.     clr.w   (Closest_Object_Hypotenuse_Dist).w
  72.     clr.b   (Homing_Attack_Chain_Counter).w
  73.     clr.b   (Next_Flight_Anim).w
  74.     clr.b   (Reverse_Gravity_Flag).w
  75.     clr.b   (Current_Shield).w
  76.  
  77.     clearRAM Sprite_Table_Input,$400
  78.     clearRAM Object_RAM,$2400   ; clear object RAM
  79.     clearRAM $FFFFF628,$58
  80.     clearRAM Misc_Variables,$100
  81.     clearRAM $FFFFFE60,$50
  82.     clearRAM $FFFFE700,$100
  83.  
  84.     move.b  #0,(Camera_System_Selection).w
  85.  
  86.     lea (VDP_control_port).l,a6
  87.     move.w  #$8B03,(a6)
  88.     move.w  #$8230,(a6)
  89.     move.w  #$8407,(a6)
  90.     move.w  #$857C,(a6)
  91.     move.w  #$9001,(a6)
  92.     move.w  #$8004,(a6)
  93.     move.w  #$8720,(a6)
  94.     move.w  #$8C81,(a6)
  95.     tst.b   (Debug_cheat_flag).w
  96.     beq.s   loc_4012
  97.     btst    #5,(Ctrl_1_Held).w
  98.     beq.s   +
  99.     move.w  #$8C89,(a6)
  100. +
  101.     btst    #6,(Ctrl_1_Held).w
  102.     beq.s   loc_4012
  103.     move.b  #1,(Debug_mode_flag).w
  104.  
  105. loc_4012:
  106.     move.w  #$8ADF,(Hint_counter_reserve).w ; H-INT every 223rd scanline
  107.     tst.w   (Two_player_mode).w
  108.     beq.s   loc_402C
  109.     move.w  #$8A6B,(Hint_counter_reserve).w ; H-INT every 108th scanline
  110.     move.w  #$8014,(a6)
  111.     move.w  #$8C87,(a6)
  112.  
  113. loc_402C:
  114.     move.w  (Hint_counter_reserve).w,(a6)
  115.     clr.w   (VDP_Command_Buffer).w
  116.     move.w  #VDP_Command_Buffer,(VDP_Command_Buffer_Slot).w
  117.     jsr CheckLevelForWater
  118. ; loc_407C:
  119. Level_LoadPal:
  120.     moveq   #3,d0           ; load Sonic's palette index
  121.     cmpi.w  #2,(Player_mode).w  ; are you playing as Tails?
  122.     bne.s   +           ; if not, branch
  123.     moveq   #$2C,d0         ; load Tails' palette index
  124. +
  125.     cmpi.w  #3,(Player_mode).w  ; are you playing as Knuckles?
  126.     bne.s   +           ; if not, branch
  127.     moveq   #$28,d0         ; load Knuckles' palette index
  128. +
  129.     cmpi.w  #9,(Player_mode).w  ; are you playing as Derpy?
  130.     bne.s   +           ; if not, branch
  131.     moveq   #$33,d0         ; load Derpy's palette index
  132. +
  133.     bsr.w   PalLoad2        ; load the palette line
  134.  
  135.     tst.b   (Last_star_pole_hit).w  ; is it the start of the level?
  136.     beq.s   Level_GetBgm        ; if yes, branch
  137.     move.b  (Saved_Water_move).w,(Water_move).w
  138. ; loc_40AE:
  139. Level_GetBgm:
  140.     tst.w   (Demo_mode_flag).w
  141.     bmi.w   loc_4114
  142.     moveq   #0,d0
  143.     move.b  (Current_Zone).w,d0
  144.     lea MusicList1(pc),a1
  145.     cmpi.b  #0,(Current_Act).w
  146.     beq.s   Level_BgmChkSS
  147.     lea MusicList2(pc),a1
  148.     cmpi.b  #1,(Current_Act).w
  149.     beq.s   Level_BgmChkSS
  150.     lea MusicList3(pc),a1
  151.     cmpi.b  #2,(Current_Act).w
  152.     beq.s   Level_BgmChkSS
  153.     lea MusicList4(pc),a1
  154.  
  155. Level_BgmChkSS:
  156.     cmpi.b  #$10,(Game_Mode_Copy).w
  157.     bne.w   Level_PlayBgm
  158.     moveq   #0,d0
  159.     move.b  (Current_Special_Stage+1).w,d0
  160.     lea MusicListSS(pc),a1
  161. ; loc_40C8:
  162. Level_PlayBgm:
  163.     move.b  (a1,d0.w),d0    ; load from music playlist
  164.     move.w  d0,(Level_Music).w  ; store level music
  165.     bsr.w   PlayMusic   ; play level music
  166.     move.b  #$34,(Object_RAM+$80).w ; load Obj34 (level title card) at $FFFFB080
  167. ; loc_40DA:
  168. Level_TtlCard:
  169.     move.b  #$C,(Delay_Time).w
  170.     bsr.w   DelayProgram
  171.     jsr (RunObjects).l
  172.     jsr (BuildSprites).l
  173.     bsr.w   RunPLC_RAM
  174.     move.w  (Object_RAM+$80+x_pos).w,d0
  175.     cmp.w   (Object_RAM+$80+$30).w,d0   ; has title card sequence finished?
  176.     bne.s   Level_TtlCard   ; if not, branch
  177.     tst.l   (Plc_Buffer).w  ; are there any items in the pattern load cue?
  178.     bne.s   Level_TtlCard   ; if yes, branch
  179.     move.b  #$C,(Delay_Time).w
  180.     bsr.w   DelayProgram
  181.     jsr (Hud_Base).l
  182.  
  183. loc_4114:
  184.     moveq   #3,d0
  185.     bsr.w   PalLoad1    ; load Sonic's palette line
  186.     bsr.w   LevelSizeLoad
  187.     bsr.w   JmpTo_DeformBgLayer
  188.     clr.w   (Vscroll_Factor).w
  189.     move.w  #-$E0,($FFFFF61E).w
  190.  
  191.     clearRAM Horiz_Scroll_Buf,$400
  192.  
  193.     bsr.w   sub_4E98
  194.     bsr.w   JmpTo_loadZoneBlockMaps
  195.     jsr (loc_402D4).l
  196.     bsr.w   JmpTo_loc_E300
  197.     jsr (FloorLog_Unk).l
  198.     bsr.w   LoadCollisionIndexes
  199.     bsr.w   WaterEffects
  200.     bsr.w   InitPlayers
  201.     move.w  #0,(Ctrl_1_Logical).w
  202.     move.w  #0,(Ctrl_2_Logical).w
  203.     move.w  #0,(Ctrl_1).w
  204.     move.w  #0,(Ctrl_2).w
  205.     move.b  #1,(Control_Locked).w
  206.     move.b  #1,($FFFFF7CF).w
  207.     move.b  #0,(Level_started_flag).w
  208. ; Level_ChkWater:
  209.     tst.b   (Water_flag).w  ; does level have water?
  210.     beq.s   Level_ClrHUD    ; if not, branch
  211.     move.b  #4,(Object_RAM+$380).w ; load Obj04 (water surface) at $FFFFB380
  212.     move.w  #$60,(Object_RAM+$380+x_pos).w ; set horizontal offset
  213.     move.b  #4,(Object_RAM+$3C0).w ; load Obj04 (water surface) at $FFFFB3C0
  214.     move.w  #$120,(Object_RAM+$3C0+x_pos).w ; set different horizontal offset
  215. ; Level_LoadObj: misnomer now
  216. Level_ClrHUD:
  217.     moveq   #0,d0
  218.     tst.b   (Last_star_pole_hit).w  ; are you starting from a lamppost?
  219.     bne.s   Level_FromCheckpoint    ; if yes, branch
  220.     move.w  d0,(Ring_count).w   ; clear rings
  221.     move.l  d0,(Timer).w        ; clear time
  222.     move.b  d0,(Extra_life_flags).w ; clear extra lives counter
  223.     move.w  d0,(Ring_count_2P).w    ; ditto for player 2
  224.     move.l  d0,(Timer_2P).w
  225.     move.b  d0,(Extra_life_flags_2P).w
  226. ; loc_41E4:
  227. Level_FromCheckpoint:
  228.     move.b  d0,(Time_Over_flag).w
  229.     move.b  d0,(Time_Over_flag_2P).w
  230.     move.b  d0,($FFFFFF4E).w
  231.     move.w  d0,($FFFFFF4C).w
  232.     move.w  d0,(Debug_placement_mode).w
  233.     move.w  d0,(Level_Inactive_flag).w
  234.     move.b  d0,($FFFFF622).w
  235.     move.b  d0,($FFFFF623).w
  236.     move.w  d0,($FFFFFEF0).w
  237.     move.w  d0,($FFFFFEF2).w
  238.     move.w  d0,($FFFFFEF4).w
  239.     move.w  d0,($FFFFFEF6).w
  240.     move.w  d0,(Loser_Time_Left).w
  241.     bsr.w   OscillateNumInit
  242.     move.b  #1,(Update_HUD_score).w
  243.     move.b  #1,(Update_HUD_rings).w
  244.     move.b  #1,(Update_HUD_timer).w
  245.     move.b  #1,(Update_HUD_timer_2P).w
  246.     jsr (ObjectsManager).l
  247.     jsr (RingsManager).l
  248.     jsr (SpecialCNZBumpers).l
  249.     jsr (RunObjects).l
  250.     jsr (BuildSprites).l
  251.     bsr.w   JmpTo_loc_3FCC4
  252.     bsr.w   SetLevelEndType
  253.     move.w  #0,(Demo_button_index).w
  254.     move.w  #0,(Demo_button_index_2P).w
  255.     lea (DemoScriptPointers).l,a1
  256.     moveq   #0,d0
  257.     move.b  (Current_Zone).w,d0 ; load zone value
  258.     lsl.w   #2,d0
  259.     movea.l (a1,d0.w),a1
  260.     tst.w   (Demo_mode_flag).w
  261.     bpl.s   loc_4290
  262.     lea (dword_498C).l,a1
  263.     move.w  ($FFFFFFF4).w,d0
  264.     subq.w  #1,d0
  265.     lsl.w   #2,d0
  266.     movea.l (a1,d0.w),a1
  267.  
  268. loc_4290:
  269.     move.b  1(a1),(Demo_press_counter).w
  270.     tst.b   (Current_Zone).w
  271.     bne.s   loc_42A8
  272.     lea (Demo_EHZ_Tails).l,a1
  273.     move.b  1(a1),(Demo_press_counter_2P).w
  274.  
  275. loc_42A8:
  276.     move.w  #$668,(Demo_Time_left).w
  277.     tst.w   (Demo_mode_flag).w
  278.     bpl.s   loc_42C8
  279.     move.w  #$21C,(Demo_Time_left).w
  280.     cmpi.w  #4,($FFFFFFF4).w
  281.     bne.s   loc_42C8
  282.     move.w  #$1FE,(Demo_Time_left).w
  283.  
  284. loc_42C8:
  285.     tst.b   (Water_flag).w
  286.     beq.s   loc_42E8
  287.     moveq   #$15,d0
  288.     cmpi.b  #8,(Current_Zone).w
  289.     beq.s   loc_42E4
  290.     moveq   #$16,d0
  291.     cmpi.b  #$D,(Current_Zone).w
  292.     beq.s   loc_42E4
  293.     moveq   #$17,d0
  294.     cmpi.b  #$F,(Current_Zone).w
  295.     beq.s   loc_42E4
  296.     moveq   #$30,d0
  297.  
  298. loc_42E4:
  299.     bsr.w   PalLoad4_Water
  300.  
  301. loc_42E8:
  302.     move.w  #-1,(Object_RAM+$80+$3E).w
  303.     move.b  #$E,(Object_RAM+$1C0+routine).w
  304.     move.w  #$A,(Object_RAM+$1C0+$34).w
  305.  
  306. loc_42EA:
  307.     move.b  #$C,(Delay_Time).w
  308.     bsr.w   DelayProgram
  309.     jsr (RunObjects).l
  310.     jsr (BuildSprites).l
  311.     bsr.w   RunPLC_RAM
  312.     tst.b   (Object_RAM+$140).w
  313.     bne.s   loc_42EA    ; loop while the object at $FFFFB140 is still loaded
  314.  
  315.     lea (Object_RAM+$80).w,a1
  316.     move.b  #$16,routine(a1)
  317.     move.w  #$2D,anim_frame_duration(a1)
  318.     move.b  #$16,next_object+routine(a1)
  319.     move.w  #$2D,next_object+anim_frame_duration(a1)
  320.     tst.b   $80(a1)
  321.     beq.s   +   ; branch if an object has not been loaded at $FFFFB100
  322.     move.b  #$16,$80+routine(a1)
  323.     move.w  #$2D,$80+anim_frame_duration(a1)
  324. +   move.b  #0,(Control_Locked).w
  325.     move.b  #0,($FFFFF7CF).w
  326.     move.b  #1,(Level_started_flag).w
  327.  
  328. ; Level_StartGame: loc_435A:
  329.     bclr    #7,(Game_Mode).w ; clear $80 from the game mode
  330.  
  331. ; ---------------------------------------------------------------------------
  332. ; Main level loop (when all title card and loading sequences are finished)
  333. ; ---------------------------------------------------------------------------
  334. ; loc_4360:
  335. Level_MainLoop:
  336.     bsr.w   PauseGame
  337.     move.b  #8,(Delay_Time).w
  338.     bsr.w   DelayProgram
  339.     addq.w  #1,(Timer_frames).w ; add 1 to level timer
  340.     bsr.w   MoveSonicInDemo
  341.     bsr.w   WaterEffects
  342.     jsr (RunObjects).l
  343.     tst.w   (Level_Inactive_flag).w
  344.     bne.w   Level
  345.     bsr.w   JmpTo_DeformBgLayer
  346.     bsr.w   UpdateWaterSurface
  347.     jsr (RingsManager).l
  348.     cmpi.b  #$C,(Current_Zone).w    ; is it CNZ?
  349.     bne.s   +           ; if not, branch past jsr
  350.     jsr (SpecialCNZBumpers).l
  351. +
  352.     bsr.w   JmpTo_loc_3FCC4
  353.     bsr.w   PalCycle_Load
  354.     bsr.w   RunPLC_RAM
  355.     bsr.w   OscillateNumDo
  356.     bsr.w   ChangeRingFrame
  357.     bsr.w   CheckLoadSignpostArt
  358.     jsr (BuildSprites).l
  359.     jsr (ObjectsManager).l
  360.     cmpi.b  #8,(Game_Mode).w    ; check if in demo mode
  361.     beq.s   loc_43DC
  362.     cmpi.b  #$C,(Game_Mode).w   ; check if in normal play mode
  363.     beq.w   Level_MainLoop
  364.     cmpi.b  #$10,(Game_Mode).w  ; check if in special stage play mode
  365.     beq.w   Level_MainLoop
  366.     rts                     ; Return to whatever code was running before this routine was run.
  367. ; ---------------------------------------------------------------------------
  368.  
  369. loc_43DC:
  370.     tst.w   (Level_Inactive_flag).w
  371.     bne.w   loc_43FA
  372.     tst.w   (Demo_Time_left).w
  373.     beq.w   loc_43FA
  374.     cmpi.b  #8,(Game_Mode).w
  375.     beq.w   Level_MainLoop
  376.     move.b  #0,(Game_Mode).w ; => SegaScreen
  377.     rts                     ; Return to whatever code was running before this routine was run.
  378. ; ---------------------------------------------------------------------------
  379. CheckLevelForWater:
  380.     cmpi.b  #$0F,(Current_Zone).w           ; Are we in Ancient Lake Zone?
  381.     beq.w   Level_InitWater             ; If so, branch.
  382.     cmpi.w  #$0002,(Current_ZoneAndAct).w       ; Are we in Frosty Dusk Zone Act 3?
  383.     beq.w   Level_InitWater             ; If so, branch.
  384.     cmpi.w  #$0004,(Current_Special_Stage).w    ; Are we in the 5th special stage?
  385.     beq.w   Level_InitWater             ; If so, branch.
  386. Level_NoWater:
  387.     move.w  #$1000,d0
  388.     move.w  d0,(Water_Level_1).w ; set water heights
  389.     move.w  d0,(Water_Level_2).w
  390.     move.w  d0,(Water_Level_3).w
  391.     move.b  #0,(Water_flag).w
  392.     rts
  393. Level_InitWater:
  394.     move.b  #1,(Water_flag).w
  395.     move.w  #0,(Two_player_mode).w
  396.     tst.b   (Water_flag).w  ; does level have water?
  397.     beq.w   Level_LoadPal   ; if not, branch
  398.     move.w  #$8014,(a6)
  399.     moveq   #0,d0
  400.     move.w  (Current_ZoneAndAct).w,d0
  401.     lsl.b   #6,d0
  402.     lsr.w   #5,d0
  403.     andi.w  #$FFFE,d0
  404.     lea (WaterHeight).l,a1  ; load water height array
  405.     move.w  (a1,d0.w),d0
  406.     move.w  d0,(Water_Level_1).w ; set water heights
  407.     move.w  d0,(Water_Level_2).w
  408.     move.w  d0,(Water_Level_3).w
  409.     clr.b   (Water_routine).w   ; clear water routine counter
  410.     clr.b   (Water_move).w  ; clear water movement
  411.     move.b  #1,(Water_on).w ; enable water
  412.  
  413. Level_LoadWaterPal:
  414.     tst.b   (Water_flag).w      ; does level have water?
  415.     beq.w   Level_NoWater       ; if not, branch
  416.     moveq   #$15,d0         ; palette number $15
  417.     cmpi.b  #8,(Current_Zone).w
  418.     bne.s   Level_PalNotHPZ     ; branch if level is not HPZ
  419.     cmpi.w  #2,(Player_mode).w  ; are you playing as Tails?
  420.     bne.s   +           ; if not, branch
  421.     moveq   #$2F,d0         ; load Tails' palette index
  422. +
  423.     cmpi.w  #3,(Player_mode).w  ; are you playing as Knuckles?
  424.     bne.s   Level_WaterPal      ; if not, branch
  425.     moveq   #$2B,d0
  426.     bra.s   Level_WaterPal      ; branch
  427.  
  428. Level_PalNotHPZ:
  429.     moveq   #$16,d0         ; palette number $16
  430.     cmpi.b  #$D,(Current_Zone).w
  431.     bne.s   Level_PalNotCFZ     ; branch if level is not CFZ
  432.     cmpi.w  #2,(Player_mode).w  ; are you playing as Tails?
  433.     bne.s   +           ; if not, branch
  434.     moveq   #$2D,d0         ; load Tails' palette index
  435. +
  436.     cmpi.w  #3,(Player_mode).w  ; are you playing as Knuckles?
  437.     bne.s   Level_WaterPal      ; if not, branch
  438.     moveq   #$29,d0
  439.     bra.s   Level_WaterPal      ; branch
  440.  
  441. Level_PalNotCFZ:
  442.     moveq   #$17,d0 ; palette number $17
  443.     cmpi.b  #$F,(Current_Zone).w
  444.     bne.s   Level_PalNotALZ     ; branch if level is not ALZ
  445.     cmpi.w  #2,(Player_mode).w  ; are you playing as Tails?
  446.     bne.s   +           ; if not, branch
  447.     moveq   #$2E,d0         ; load Tails' palette index
  448. +
  449.     cmpi.w  #3,(Player_mode).w  ; are you playing as Knuckles?
  450.     bne.s   Level_WaterPal      ; if not, branch
  451.     moveq   #$2A,d0
  452.  
  453. Level_PalNotALZ:
  454.     moveq   #$30,d0         ; palette number $30
  455.     cmpi.w  #2,(Player_mode).w  ; are you playing as Tails?
  456.     bne.s   +           ; if not, branch
  457.     moveq   #$31,d0         ; load Tails' palette index
  458. +
  459.     cmpi.w  #3,(Player_mode).w  ; are you playing as Knuckles?
  460.     bne.s   Level_WaterPal      ; if not, branch
  461.     moveq   #$32,d0
  462. ; loc_409E:
  463. Level_WaterPal:
  464.     bra.w   PalLoad3_Water  ; load underwater palette (with d0)
  465. ; ---------------------------------------------------------------------------
Advertisement