Advertisement
TheBlad768

Scrolling BG (PDW)

Jul 3rd, 2020
2,872
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; ===========================================================================
  2. ; Scrolling BG from the The Pirates of Dark Water.
  3. ; Ripped by TheBlad768.
  4. ; ===========================================================================
  5.  
  6. ; RAM Address
  7. long_221E:                  = RAM+$00       ; 4 bytes
  8. long_2222:                  = RAM+$04       ; 4 bytes
  9. long_2226:                  = RAM+$08       ; 4 bytes
  10. long_222A:                  = RAM+$0C       ; 4 bytes
  11. long_222E:                  = RAM+$10       ; 4 bytes
  12. long_2232:                  = RAM+$14       ; 4 bytes
  13.  
  14. ; =============== S U B R O U T I N E =======================================
  15.  
  16. Scrolling_BG_Init:
  17.         bsr.w   Random_Number
  18.         andi.l  #$1FF,d0
  19.         btst    #4,d0
  20.         beq.s   +
  21.         neg.l   d0
  22.         subi.l  #$100,d0
  23. +       addi.l  #$80,d0
  24.         move.l  d0,(long_221E).w
  25.         bsr.w   Random_Number
  26.         andi.l  #$1FF,d0
  27.         btst    #4,d0
  28.         beq.s   +
  29.         neg.l   d0
  30.         subi.l  #$100,d0
  31. +       addi.l  #$80,d0
  32.         move.l  d0,(long_222A).w
  33.         bsr.w   Random_Number
  34.         andi.l  #$7FF,d0
  35.         btst    #4,d0
  36.         beq.s   +
  37.         neg.l   d0
  38.         subi.l  #$200,d0
  39. +       addi.l  #$100,d0
  40.         move.l  d0,(long_2222).w
  41.         bsr.w   Random_Number
  42.         andi.l  #$7FF,d0
  43.         btst    #4,d0
  44.         beq.s   +
  45.         neg.l   d0
  46.         subi.l  #$200,d0
  47. +       addi.l  #$100,d0
  48.         move.l  d0,(long_222E).w
  49.         bsr.w   Random_Number
  50.         andi.l  #$3F0000,d0
  51.         subi.l  #$1F0000,d0
  52.         move.l  d0,(long_2226).w
  53.         bsr.w   Random_Number
  54.         andi.l  #$3F0000,d0
  55.         subi.l  #$1F0000,d0
  56.         move.l  d0,(long_2232).w
  57.         rts
  58. ; End of function Scrolling_BG_Init
  59.  
  60. ; =============== S U B R O U T I N E =======================================
  61.  
  62. Scrolling_BG:
  63.         move.l  (long_221E).w,d0
  64.         add.l   d0,(long_2222).w
  65.         tst.l   (long_2226).w
  66.         bpl.s   loc_6CC56
  67.         tst.l   (long_221E).w
  68.         bpl.s   loc_6CCB4
  69.         neg.l   (long_221E).w
  70.         bra.s   loc_6CC64
  71. ; ---------------------------------------------------------------------------
  72.  
  73. loc_6CC56:
  74.         tst.l   (long_221E).w
  75.         bmi.s   loc_6CCB4
  76.         neg.l   (long_221E).w
  77.  
  78. loc_6CC64:
  79.         add.l   d0,(long_2222).w
  80.         bsr.w   Random_Number
  81.         andi.l  #$1FF,d0
  82.         subi.l  #$FF,d0
  83.         sub.l   d0,(long_221E).w
  84.         move.l  (long_221E).w,d0
  85.         bpl.s   loc_6CC9E
  86.         cmpi.l  #-$800,d0
  87.         bge.s   loc_6CCAE
  88.         move.l  #-$800,d0
  89.         bra.s   loc_6CCAE
  90. ; ---------------------------------------------------------------------------
  91.  
  92. loc_6CC9E:
  93.         cmpi.l  #$800,d0
  94.         ble.s       loc_6CCAE
  95.         move.l  #$800,d0
  96.  
  97. loc_6CCAE:
  98.         move.l  d0,(long_221E).w
  99.  
  100. loc_6CCB4:
  101.         move.l  (long_222A).w,d0
  102.         add.l   d0,(long_222E).w
  103.         tst.l   (long_2232).w
  104.         bpl.s   loc_6CCD8
  105.         tst.l   (long_222A).w
  106.         bpl.s   loc_6CD36
  107.         neg.l   (long_222A).w
  108.         bra.s   loc_6CCE6
  109. ; ---------------------------------------------------------------------------
  110.  
  111. loc_6CCD8:
  112.         tst.l   (long_222A).w
  113.         bmi.s   loc_6CD36
  114.         neg.l   (long_222A).w
  115.  
  116. loc_6CCE6:
  117.         add.l   d0,(long_222E).w
  118.         bsr.w   Random_Number
  119.         andi.l  #$1FF,d0
  120.         subi.l  #$FF,d0
  121.         sub.l   d0,(long_222A).w
  122.         move.l  (long_222A).w,d0
  123.         bpl.s   loc_6CD20
  124.         cmpi.l  #-$800,d0
  125.         bge.s   loc_6CD30
  126.         move.l  #-$800,d0
  127.         bra.s   loc_6CD30
  128. ; ---------------------------------------------------------------------------
  129.  
  130. loc_6CD20:
  131.         cmpi.l  #$800,d0
  132.         ble.s       loc_6CD30
  133.         move.l  #$800,d0
  134.  
  135. loc_6CD30:
  136.         move.l  d0,(long_222A).w
  137.  
  138. loc_6CD36:
  139.         move.l  (long_2222).w,d0
  140.         bpl.s   loc_6CD54
  141.         cmpi.l  #-$30000,d0
  142.         bge.s   loc_6CD64
  143.         move.l  #-$30000,d0
  144.         bra.s   loc_6CD64
  145. ; ---------------------------------------------------------------------------
  146.  
  147. loc_6CD54:
  148.         cmpi.l  #$30000,d0
  149.         ble.s       loc_6CD64
  150.         move.l  #$30000,d0
  151.  
  152. loc_6CD64:
  153.         move.l  (long_222E).w,d1
  154.         bpl.s   loc_6CD82
  155.         cmpi.l  #-$30000,d1
  156.         bge.s   loc_6CD92
  157.         move.l  #-$30000,d1
  158.         bra.s   loc_6CD92
  159. ; ---------------------------------------------------------------------------
  160.  
  161. loc_6CD82:
  162.         cmpi.l  #$30000,d1
  163.         ble.s       loc_6CD92
  164.         move.l  #$30000,d1
  165.  
  166. loc_6CD92:
  167.         add.l   d0,(long_2226).w
  168.         add.l   d1,(long_2232).w
  169.         move.w  (long_2226).w,(H_scroll_buffer+2).w
  170.         move.w  (long_2232).w,(V_scroll_value+2).w
  171.         rts
  172. ; End of function Scrolling_BG
  173. ; ---------------------------------------------------------------------------
  174. ; Generates a pseudo-random number in d0
  175. ; ---------------------------------------------------------------------------
  176.  
  177. word_CB6:                   = RAM+$18       ; 2 bytes
  178. byte_CC54:                  = RAM+$1A       ; 1 byte
  179. byte_CC55:                  = RAM+$1B       ; 1 byte
  180.  
  181. ; =============== S U B R O U T I N E =======================================
  182.  
  183. Random_Number:
  184.         tst.w   (word_CB6).w
  185.         beq.s   Random_Number_2
  186.         move.w  (V_int_run_count).w,d0
  187.         rts
  188. ; ---------------------------------------------------------------------------
  189.  
  190. Random_Number_2:
  191.         movem.l d1-d2/a0,-(sp)
  192.         move.w  (V_int_run_count).w,d2
  193.         move.w  d2,d1
  194.         andi.w  #$FF,d2
  195.         lsr.w   #8,d1
  196.         move.b  (byte_CC55).w,d0
  197.         eor.b   d0,d2
  198.         move.b  (byte_CC54).w,d0
  199.         eor.b   d0,d1
  200.         moveq   #0,d0
  201.         move.w  d1,d0
  202.         lsl.w   #8,d0
  203.         or.b    d2,d0
  204.         add.l   d0,d0
  205.         movea.l d0,a0
  206.         moveq   #0,d0
  207.         move.w  (a0),d0
  208.         sub.w   d0,d2
  209.         sub.w   d0,d1
  210.         ror.b   #1,d2
  211.         rol.b   #1,d1
  212.         add.b   d1,(byte_CC55).w
  213.         add.b   d2,(byte_CC54).w
  214.         eor.b   d2,d0
  215.         lsl.w   #8,d1
  216.         eor.b   d1,d0
  217.         movem.l (sp)+,d1-d2/a0
  218.         rts
  219. ; End of function Random_Number
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement