Advertisement
vladikcomper

Sonic 1 Megahack - A bit of SYZ 3 boss code

Mar 1st, 2013
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. ; ===============================================================
  3. ; ---------------------------------------------------------------
  4. ; SYZ 3 boss
  5. ; ---------------------------------------------------------------
  6.  
  7. camXbase    = $2C00
  8. camYbase    = $500
  9.  
  10. FontBase    = $7000
  11. FontTBase   = (FontBase/$20)
  12. CharBase    = FontTBase-' '
  13.  
  14. WindowWidth = 32
  15. WindowHeight    = 15
  16. WindowXpos  = 4
  17. WindowYpos  = 4
  18.  
  19. ; ---------------------------------------------------------------
  20.  
  21. xpos    = 8
  22. ypos    = $C
  23.  
  24. timer   = $38
  25. gen_ok  = $1D   ; b Set, when generator finishes work
  26. btn_ev  = $1E   ; b Buttons routine on press event
  27. btn_id  = $1F   ; b Id of the button pressed
  28. var1    = $30
  29. var2    = $32
  30. var3    = $34
  31.  
  32. obj_SYZ3boss:
  33.  
  34.     ; Load buttons
  35.     move.b  #0,btn_ev(a0)
  36.     moveq   #2,d6           ; do 3 objects
  37.     move.w  #camXbase+$60,d1    ; d1 = start X-pos
  38.     moveq   #1,d2           ; d2 = button id
  39.     moveq   #120,d3         ; d3 = initial timer
  40.  
  41. @CreateButton:
  42.     jsr SingleObjLoad2
  43.     move.b  #$19,(a1)
  44.     move.l  #obj_SYZ3boss_Button,obj(a1)
  45.     move.b  d2,btn_id(a1)    
  46.     addq.b  #1,d2
  47.     move.w  d1,xpos(a1)
  48.     move.w  #camYbase-8,ypos(a1)
  49.     move.w  a0,parent(a1)
  50.     move.w  d3,timer(a1)
  51.     addi.w  #60,d3
  52.     addi.w  #$40,d1
  53.     dbf d6,@CreateButton
  54.  
  55.     move.l  #@WaitCamera,obj(a0)
  56.     rts
  57.  
  58.     ; Wait until Sonic aproaches boss arena
  59. @WaitCamera:
  60.     cmpi.w  #camXbase,($FFFFF700).w
  61.     bcc.s   @SetFadeOut
  62.     rts
  63.  
  64.     ; Fade out music
  65. @SetFadeOut:
  66.     ori.w   #$8000,($FFFFD002).w    ; send Sonic to Hi-Plane!
  67.     move.l  #@WaitFadeOut,obj(a0)
  68.     move.b  #4,($FFFFD040+$24).w    ; set HUD to hide
  69.     move.w  #5*60,timer(a0)
  70.  
  71.     ; Prepare non-noob palete
  72.     moveq   #3,d0
  73.     jsr PalLoad1_NonNoob
  74.     moveq   #8,d0
  75.     jsr PalLoad1_NonNoob
  76.     move.w  #$3F,($FFFFF626).w
  77.  
  78.     moveq   #$FFFFFFE0,d0
  79.     jmp PlaySound
  80.  
  81.     ; Wait some time
  82. @WaitFadeOut:
  83.     subq.w  #1,timer(a0)
  84.     beq.s   @LoadBoss
  85.  
  86.     ; Convert palette to non-noob colors!
  87.     move.b  ($FFFFFE05).w,d0
  88.     andi.b  #%111,d0
  89.     bne.s   @0
  90.     move.w  a0,-(sp)
  91.     jsr Pal_FadeIn
  92.     move.w  (sp)+,a0
  93. @0  rts
  94.  
  95. @LoadBoss:
  96.     move.l  #SYZ3boss_WindowProc,obj(a0)
  97.     move.b  #4,routine2(a1)
  98.     move.w  #camXbase+160,xpos(a1)
  99.     move.w  #camYbase-$40,ypos(a1)
  100.     move.w  xpos(a1),xpos2(a1)
  101.     move.w  ypos(a1),ypos2(a1)
  102.     move.w  #$300,yvel(a1)
  103.     move.b  #8,hits(a1)
  104.     move.w  a1,parent(a0)
  105.     move.l  #Nem_Eggman,d0
  106.     move.w  #$8000,d1
  107.     jsr SendToPLC
  108.  
  109.     ; Load font
  110.     vram    (FontBase)
  111.     lea MsgFont,a1
  112.     moveq   #95,d0      ; number of tiles
  113.     moveq   #1,d1       ; 0 mask
  114.     moveq   #6,d2       ; 1 mask
  115.     jsr Load1bpp
  116.  
  117.     ; Setup appear event
  118.     move.b  #0,routine(a0)
  119.     move.w  #19,var1(a0)
  120.     move.w  #20,var2(a0)
  121.     move.w  #16,var3(a0)
  122.     move.w  #2,timer(a0)
  123.  
  124.     ; Play boss tuna
  125.     moveq   #$FFFFFF8C,d0
  126.     jmp PlaySound
  127.  
  128. ; ===============================================================
  129. ; ---------------------------------------------------------------
  130. ; Window Processing Routine
  131. ; ---------------------------------------------------------------
  132.  
  133. SYZ3boss_WindowProc:
  134.     move    #$2700,sr   ; disable interrupta
  135.     lea VDP_Ctrl,a6
  136.     lea -4(a6),a5
  137.     moveq   #0,d0
  138.     move.b  routine(a0),d0
  139.     move.w  @Routines(pc,d0.w),d0
  140.     jsr @Routines(pc,d0.w)
  141.     move    #$2300,sr   ; enabla interrupta
  142.     rts
  143.  
  144. ; ---------------------------------------------------------------
  145. @Routines:
  146.     dc.w    WP_IntroDraw-@Routines      ; 0
  147.     dc.w    WP_IntroDraw2-@Routines     ; 2
  148.  
  149.     dc.w    WP_DrawMessage-@Routines    ; 4 Draws intro message
  150.     dc.w    WP_WaitAnwser-@Routines     ; 6 Waits for button press
  151.     dc.w    WP_LoadFirstQuestion-@Routines  ; 8 Load first question
  152.  
  153.     dc.w    WP_DrawMessage-@Routines    ; $A    Draw the question
  154.     dc.w    WP_WaitAnwser-@Routines     ; $C    Waits for the answer
  155.     dc.w    WP_AnimateChoice-@Routines  ; $E    Selected answer blinks
  156.     dc.w    WP_WaitGenerator-@Routines  ; $10   Wait until generator finishes work
  157.     dc.w    WP_LoadNextQuestion-@Routines   ; $12   Load next question
  158.  
  159.     dc.w    WP_DrawMessage-@Routines    ; $14   Cutscene dialog
  160.     dc.w    WP_LoadCheatsMesssage-@Routines ; $16
  161.     dc.w    WP_DrawMessage-@Routines    ; $18   Display cheats
  162.     dc.w    WP_EnterCheat-@Routines     ; $1A   Enter cheat
  163.     dc.w    WP_DrawMessage-@Routines    ; $1C   Display victory message!
  164.     dc.w    WP_EndBoss-@Routines        ; $1E   And that concludes the boss!
  165.  
  166. ; ---------------------------------------------------------------
  167. ; Draws the first line
  168. ; ---------------------------------------------------------------
  169.  
  170. WP_IntroDraw:
  171.     subq.w  #1,timer(a0)    ; timer time???
  172.     bne.s   @Return     ; fuck no
  173.     move.w  #2,timer(a0)    ; reset timer
  174.  
  175.     move.w  #CharBase+' ',d3
  176.  
  177.     ; Draw left dir
  178.     move.w  var1(a0),d1 ; xpos
  179.     subq.w  #1,var1(a0)
  180.     moveq   #4,d2       ; ypos
  181.     bsr CalcCellAddr
  182.     move.l  d0,(a6)
  183.     move.w  d3,(a5)     ; draw black tila
  184.  
  185.     ; Draw right dir
  186.     move.w  var2(a0),d1 ; x pos
  187.     addq.w  #1,var2(a0)
  188.     moveq   #4,d2       ; y pos
  189.     bsr CalcCellAddr
  190.     move.l  d0,(a6)
  191.     move.w  d3,(a5)     ; draw black tila
  192.  
  193.     ; Check if we should finish
  194.     subq.w  #1,var3(a0)
  195.     beq.s   @GoTo_NextAction
  196.  
  197. @Return:
  198.     rts
  199.  
  200.         ; So yeah, next fucking actia
  201. @GoTo_NextAction:
  202.     addq.b  #2,routine(a0)
  203.     move.w  #WindowYpos+1,var1(a0)
  204.     move.w  #3,timer(a0)
  205.  
  206. ; ---------------------------------------------------------------
  207. ; Draws the rest lines
  208. ; ---------------------------------------------------------------
  209.  
  210. WP_IntroDraw2:
  211.     subq.w  #1,timer(a0)
  212.     bne.s   @Return
  213.     move.w  #2,timer(a0)    ; reset timera
  214.  
  215.     ; Draw the line
  216.     move.w  var1(a0),d3 ; d3 = Current Line
  217.     addq.w  #1,var1(a0) ; increase line
  218.     moveq   #WindowWidth-1,d4
  219.     move.w  #CharBase+' ',d5
  220.  
  221. @0  move.w  d3,d2       ; d2 = ypos
  222.     moveq   #WindowXpos,d1
  223.     add.w   d4,d1       ; d1 = xpos
  224.     bsr CalcCellAddr
  225.     move.l  d0,(a6)
  226.     move.w  d5,(a5)
  227.     dbf d4,@0       ; do for all window width, epta
  228.  
  229.     ; Check if this is the last line to draw
  230.     cmpi.w  #WindowYpos+WindowHeight,d3    
  231.     beq.s   @Goto_NextAction
  232.  
  233. @Return:
  234.     rts
  235.  
  236. @Goto_NextAction:
  237.     addq.b  #2,routine(a0)  ; next routine fuck yeah
  238.  
  239. ; ---------------------------------------------------------------
  240. ; Draws the message
  241. ; ---------------------------------------------------------------
  242.  
  243. char_x  = $30   ; w
  244. char_y  = $32   ; w
  245. charpos = $34   ; w
  246. msg_id  = $36   ; b
  247.  
  248.     moveq   #0,d0
  249.     move.b  d0,msg_id(a0)
  250.     bra WP_LoadMessage
  251.  
  252. WP_DrawMessage:
  253.     subq.w  #1,timer(a0)
  254.     bne.s   @Return
  255.     move.w  #2,timer(a0)
  256.  
  257.     lea MessagesList,a1
  258.     adda.w  charpos(a0),a1
  259.     addq.w  #1,charpos(a0)
  260.     moveq   #0,d3
  261.     move.b  (a1),d3     ; load char
  262.     beq.s   @NextLine   ; -- break flag!
  263.     bmi.s   @CheckFlags ; -- just flag!
  264.     addi.w  #CharBase,d3
  265.     move.w  char_x(a0),d1
  266.     move.w  char_y(a0),d2
  267.     bsr CalcCellAddr
  268.     move.l  d0,(a6)
  269.     move.w  d3,(a5)
  270.     addq.w  #1,char_x(a0)   ; increase x-pos
  271.     moveq   #$FFFFFFBA,d0
  272.     jmp PlaySound_Special
  273.    
  274. @CheckFlags:
  275.     addq.b  #1,d3
  276.     beq.s   @GoTo_NextAction
  277.     andi.w  #$7F,d3
  278.     move.w  d3,timer(a0)    ; setup custom delay!
  279.     rts
  280.  
  281. @NextLine:
  282.     addq.w  #1,char_y(a0)
  283.     move.w  #WindowXpos+1,char_x(a0)
  284.  
  285. @Return:
  286.     rts
  287.  
  288. @GoTo_NextAction:
  289.     sf.b    btn_id(a0)
  290.     addq.b  #2,routine(a0)
  291.     cmpi.b  #$A+2,routine(a0)
  292.     bne.s   WP_WaitAnwser
  293.     move.b  #2,btn_ev(a0)       ; set buttons to lock up Sonic
  294.  
  295. ; ---------------------------------------------------------------
  296. ; Wait Button press
  297. ; ---------------------------------------------------------------
  298.  
  299. WP_WaitAnwser:
  300.     moveq   #0,d0
  301.     move.b  btn_id(a0),d0
  302.     beq.s   @Return
  303.     subq.b  #1,d0
  304.     add.w   d0,d0
  305.     add.w   d0,d0
  306.     add.w   d0,charpos(a0)  
  307.     addq.b  #2,routine(a0)
  308.     move.w  #120,timer(a0)      ; time for answer to blink
  309.  
  310. @Return:
  311.     rts
  312.  
  313. ; ---------------------------------------------------------------
  314. ; Loads the next question
  315. ; ---------------------------------------------------------------
  316.  
  317. WP_LoadFirstQuestion:
  318.  
  319.     ; Load HUD object
  320.     jsr SingleObjLoad
  321.     move.b  #$19,(a1)
  322.     move.l  #obj_SYZ3boss_HUD,obj(a1)
  323.  
  324.     sf.b    btn_id(a0)      ; reset id of the button pressed
  325.     moveq   #4,d0           ; setup question id
  326.     bra.s   WP_LoadNextQuestion2
  327.  
  328. WP_LoadNextQuestion:
  329.     moveq   #0,d0
  330.     move.b  msg_id(a0),d0
  331.     addq.w  #1,d0
  332.     cmpi.w  #$C,d0          ; last question?
  333.     beq.w   WP_LoadEggman       ; if yes, branch
  334.  
  335. WP_LoadNextQuestion2:
  336.     move.b  d0,msg_id(a0)
  337.     move.w  #60,timer(a0)       ; wait 1 sec before draw message
  338.     move.b  #$A,routine(a0)     ; => "Draw Message"
  339.     bsr WP_LoadMessage
  340.     bra WP_ClearWindow
  341.  
  342. ; ---------------------------------------------------------------
  343. ; Loads the next question
  344. ; ---------------------------------------------------------------
  345.  
  346. WP_AnimateChoice:
  347.     lea MessagesList,a2
  348.     adda.w  charpos(a0),a2
  349.  
  350.     move.w  timer(a0),d0
  351.     beq.s   @Goto_NextAction
  352.     subq.w  #1,d0
  353.     move.w  d0,timer(a0)
  354.  
  355.     moveq   #' ',d3
  356.     btst    #3,d0
  357.     bne.s   @0
  358.     moveq   #'A'-1,d3
  359.     add.b   btn_id(a0),d3       ; A/B/C
  360.  
  361. @0  addi.w  #CharBase,d3
  362.  
  363.     moveq   #WindowXpos+1,d1
  364.     moveq   #WindowYpos+1,d2
  365.     add.b   (a2),d2         ; ypos
  366.     bsr CalcCellAddr
  367.     move.l  d0,(a6)
  368.     move.w  d3,(a5)
  369.     rts
  370.  
  371. @Goto_NextAction:
  372.     sf.b    btn_id(a0)      ; reset id of the button pressed
  373.     sf.b    btn_ev(a0)      ; set buttons to normal state
  374.     sf.b    gen_ok(a0)      ; set generator as working
  375.     addq.b  #2,routine(a0)
  376.     jsr SingleObjLoad
  377.     move.b  #$19,(a1)    
  378.     moveq   #0,d0
  379.     move.b  1(a2),d0        ; generator ID
  380.     move.l  @Generators(pc,d0.w),obj(a1)
  381.     move.b  2(a2),d0        ; generator argument
  382.     move.w  d0,var1(a1)
  383.     move.w  a0,parent(a1)
  384.     rts
  385.  
  386. @Generators:
  387.     dc.l    obj_SYZ3boss_RingsGen
  388.     dc.l    obj_SYZ3boss_SpikeGen
  389.  
  390. ; ---------------------------------------------------------------
  391. ; Wait until generator finishes work
  392. ; ---------------------------------------------------------------
  393.  
  394. WP_WaitGenerator:
  395.     tst.b   gen_ok(a0)
  396.     beq.s   @Return
  397.     addq.b  #2,routine(a0)  ; => "WP_LoadNextQuestion"
  398.  
  399. @Return:
  400.     rts
  401.  
  402. ; ---------------------------------------------------------------
  403. ; Show Eggman, wait Eggman to be beaten
  404. ; ---------------------------------------------------------------
  405.  
  406. eggman = $3A
  407.  
  408. WP_LoadEggman:
  409.    
  410.     ; Setup boss object
  411.     move.b  #$14,routine(a0)
  412.     st.b    ($FFFFF7CC).w       ; lock Sonic's controls
  413.     bclr    #0,($FFFFD022).w    ; face Sonic left
  414.     move.w  #0,($FFFFD030).w    ; stop Sonic blinking
  415.     move.w  #(Up)<<8,SonicControl        
  416.     jsr SingleObjLoad
  417.     move.b  #$19,(a1)
  418.     move.l  #obj_SYZ3boss_KillGenerator,obj(a1) ; this object will restore Sonic's contro
  419.     move.w  #240,timer(a1)
  420.     move.w  a0,parent(a1)
  421.  
  422.     ; Load dialog
  423.     moveq   #1,d0
  424.     bsr WP_LoadMessage
  425.     move.w  #60,timer(a0)
  426.     bsr WP_ClearWindow
  427.  
  428.     jsr SingleObjLoad
  429.     move.b  #$02,(a1)
  430.     move.w  a1,eggman(a0)
  431.     move.b  #4,routine2(a1)
  432.     move.w  #camXbase+280,xpos(a1)
  433.     move.w  #camYbase-$40,ypos(a1)
  434.     move.w  xpos(a1),xpos2(a1)
  435.     move.w  ypos(a1),ypos2(a1)
  436.     move.w  #$280,yvel(a1)
  437.     move.b  #8,hits(a1)
  438.     move.l  #Nem_Eggman,d0
  439.     move.w  #$8000,d1
  440.     jmp SendToPLC
  441.  
  442. ; ---------------------------------------------------------------
  443.  
  444. WP_LoadCheatsMesssage:
  445.     addq.b  #2,routine(a0)
  446.     moveq   #2,d0
  447.     bsr WP_LoadMessage
  448.     move.w  #60,timer(a0)
  449.     bra WP_ClearWindow
  450.  
  451. ; ---------------------------------------------------------------
  452.  
  453. cheatstr = $30  ; 8 bytes
  454. cheatpos = $38  ; w
  455.  
  456. WP_EnterCheat:
  457.  
  458.     ; Debug output
  459. ;   moveq   #5,d1
  460. ;   moveq   #5,d2
  461. ;   bsr CalcCellAddr
  462. ;   moveq   #7,d3
  463. ;   move.l  d0,(a6)
  464. ;   lea cheatstr(a0),a1
  465. ;
  466. ;@FF    moveq   #0,d0
  467. ;   move.b  (a1)+,d0
  468. ;   addi.w  #CharBase,d0
  469. ;   move.w  d0,(a5)
  470. ;   dbf d3,@FF
  471.  
  472.     ; Check if Eggy's dead
  473.     movea.w eggman(a0),a1
  474.     cmpi.b  #2,(a1)
  475.     bne @GoTo_NextAction
  476.  
  477.     ; Check if button was pressed
  478.     move.b  #4,btn_ev(a0)
  479.     move.b  btn_id(a0),d0       ; d0 = btn_id
  480.     beq.s   @Return
  481.     sf.b    btn_id(a0)
  482.  
  483.     ; Add letter into cheat memory
  484.     moveq   #%111,d3        ; d3 = warp mask
  485.     move.w  cheatpos(a0),d2     ; d2 = current pos in a cheat
  486.     moveq   #'A'-1,d1
  487.     add.b   d0,d1           ; d1 = char
  488.     move.b  d1,cheatstr(a0,d2.w)    ; save cheat char into BLABLA BLA
  489.    
  490.     ; Check if str present in cheats
  491.     moveq   #2,d0           ; check 3 cheats    
  492.     lea @CheatsData,a1
  493.  
  494. @CheckCheat:
  495.     moveq   #0,d4
  496.     move.b  (a1)+,d4        ; d4 = cheat len
  497.     move.b  d2,d1
  498.     sub.b   d4,d1           ; d1 = start char
  499.  
  500. @0  and.w   d3,d1           ; apply mask to pos
  501.     move.b  cheatstr(a0,d1.w),d5    ; d5 = char
  502.     cmp.b   (a1)+,d5
  503.     bne.s   @NextCheat
  504.     addq.w  #1,d1           ; next char
  505.     dbf d4,@0
  506.    
  507.     ; Cheat found! Create cheat generator!
  508.     add.w   d0,d0
  509.     add.w   d0,d0           ; d0 *= 4    
  510.     neg.w   d0
  511.     move.w  d0,d4
  512.     jsr SingleObjLoad
  513.     move.b  #$19,(a1)
  514.     move.l  @CheatsData-4(pc,d4.w),obj(a1)
  515.     move.w  a0,parent(a1)
  516.     moveq   #$FFFFFFA1,d0
  517.     jsr PlaySound_Special   ; CHEATEY!!!
  518.     bra.s   @SaveLetter
  519.    
  520. @NextCheat:
  521.     adda.w  d4,a1           ; jump to end of cheat str
  522.     dbf d0,@CheckCheat
  523.  
  524. @SaveLetter:
  525.     ; Finally, save the letter for the cheat
  526.     addq.w  #1,d2
  527.     and.w   d3,d2
  528.     move.w  d2,cheatpos(a0)
  529.  
  530. @Return:
  531.     rts
  532.  
  533. ; ---------------------------------------------------------------
  534. @GoTo_NextAction:
  535.     addq.b  #2,routine(a0)
  536.    
  537.     ; Load rings generator
  538.     jsr SingleObjLoad
  539.     move.b  #$19,(a1)
  540.     move.l  #obj_SYZ3boss_RingsGen_Special,obj(a1)
  541.     move.w  #180,timer(a1)
  542.     move.w  #50,var1(a1)
  543.    
  544.     ; Load victory message and fade out music
  545.     moveq   #3,d0
  546.     bsr WP_LoadMessage
  547.     bsr WP_ClearWindow
  548.     move.w  #180,timer(a0)
  549.     moveq   #$FFFFFFE0,d0
  550.     jmp PlaySound   ; fade out music
  551.  
  552. ; ---------------------------------------------------------------
  553.  
  554. ; Cheat Generators
  555.     dc.l    obj_SYZ3boss_CheatSpikes
  556.     dc.l    obj_SYZ3boss_CheatSpring
  557.     dc.l    obj_SYZ3boss_CheatRingRush
  558.  
  559. @CheatsData:
  560.     dc.b    2, 'BBC'
  561.     dc.b    4, 'BABAC'
  562.     dc.b    7, 'BCCABBAC'
  563.     even        
  564.  
  565. ; ===============================================================
  566. ; ---------------------------------------------------------------
  567. ; End the boss
  568. ; ---------------------------------------------------------------
  569.  
  570. WP_EndBoss:
  571.     move.w  #320,timer(a0)
  572.     move.l  #@ResetBoss,obj(a0)
  573.     rts
  574.  
  575. @ResetBoss:
  576.     subq.w  #1,timer(a0)
  577.     bne.s   @0
  578.     st.b    NonNoobMsg      ; force non-noob msg
  579.     jmp LoadNextLevel
  580. @0  rts
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement