Advertisement
warmCabin

Untitled

Apr 20th, 2022
1,099
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. bg_collision_check:
  2. ; Check if a given coordinate collides with the background.
  3. ;
  4. ; Parameters:
  5. ; $08 = x pixel
  6. ; $09 = screen number
  7. ; $0A = y pixel
  8. ; $0B = offscreen flag
  9. ; $55 = sprite collision override table length
  10. ; $56 = sprite collision override table
  11. ;
  12. ; Return values:
  13. ; $00 = type of tile at this position
  14. ;   0 = air
  15. ;   1 = ground
  16. ;   2 = ladder
  17. ;   3 = spikes
  18. ;   4 = water
  19. ;   5 = right conveyor belt
  20. ;   6 = left conveyor belt
  21. ;   7 = ice
  22. ;   8 = door scroll/side-only barrier
  23.  0F:CB9F: A4 55     LDY num_solid_sprites
  24. solid_sprite_lookup_loop:
  25. ; Check the sprite collision override table.
  26. ; These tables co-opt standard sprite variables to store a
  27. ; coordinate bitmask, coordinate compare value, and tile type
  28. ; to register as.
  29. ; The input coordinates are ANDed with the masks and compared
  30. ; directly to the sprite positions.
  31. ;
  32. ; This system was only used for solid tiles and door barriers.
  33. ; It can also work for air, spikes, conveyor belts, and ice,
  34. ; but has trouble with ladders and water for some reason
  35. ; (They act as air).
  36.  0F:CBA1: 88        DEY
  37.  0F:CBA2: 30 1C     BMI +
  38.  0F:CBA4: B6 56     LDX solid_sprites,Y
  39.  0F:CBA6: A5 08     LDA $08
  40.  0F:CBA8: 3D 10 06  AND solid_sprite_x_masks[0],X
  41.  0F:CBAB: DD 50 06  CMP solid_sprite_x_pos[0],X
  42.  0F:CBAE: D0 F1     BNE solid_sprite_lookup_loop
  43.  0F:CBB0: A5 0A     LDA $0A
  44.  0F:CBB2: 3D 30 06  AND solid_sprite_y_masks[0],X
  45.  0F:CBB5: DD 70 06  CMP solid_sprite_y_pos[0],X
  46.  0F:CBB8: D0 E7     BNE solid_sprite_lookup_loop
  47. ; Found a match. Return the solid sprite tile type.
  48.  0F:CBBA: BD F0 04  LDA solid_sprite_types[0],X
  49.  0F:CBBD: 85 00     STA $00
  50.  0F:CBBF: 60        RTS -----------------------------------------
  51. +:
  52. ; Load level data bank.
  53. ; Banks 0 - 7 store level data. Data for each Wily stage follows
  54. ; data for each main Robot Master stage.
  55.  0F:CBC0: A5 2A     LDA stage_num
  56.  0F:CBC2: 29 07     AND #$07
  57.  0F:CBC4: 20 00 C0  JSR bank_switch
  58.  0F:CBC7: A9 00     LDA #$00
  59.  0F:CBC9: 85 00     STA $00
  60. ; If $0B is...
  61. ;   0: sprite is on-screen
  62. ;   negative: sprite is above screen
  63. ;   positive: intangible?
  64.  0F:CBCB: A5 0B     LDA $0B
  65.  0F:CBCD: F0 09     BEQ ++
  66.  0F:CBCF: 30 03     BMI +
  67.  0F:CBD1: 4C 3E CC  JMP exit_bg_collision_check
  68. +:
  69. ; If $0B is negative, set y_pixel to 0.
  70. ; This effectively makes the top tile extend infinitely offscreen
  71. ; for collision purposes.
  72.  0F:CBD4: A9 00     LDA #$00
  73.  0F:CBD6: 85 0A     STA $0A
  74. ++:
  75. ; Set up pointer in $0C and $0D
  76. ; Set up offset in $00
  77.  0F:CBD8: A5 08     LDA $08
  78.  0F:CBDA: 4A        LSR
  79.  0F:CBDB: 4A        LSR
  80.  0F:CBDC: 29 38     AND #$38
  81.  0F:CBDE: 85 00     STA $00
  82.  0F:CBE0: A5 0A     LDA $0A
  83.  0F:CBE2: 0A        ASL
  84.  0F:CBE3: 2A        ROL
  85.  0F:CBE4: 2A        ROL
  86.  0F:CBE5: 2A        ROL
  87.  0F:CBE6: 29 07     AND #$07
  88.  0F:CBE8: 05 00     ORA $00
  89.  0F:CBEA: 85 00     STA $00
  90.  0F:CBEC: A9 00     LDA #$00
  91.  0F:CBEE: 85 0C     STA $0C
  92.  0F:CBF0: A5 09     LDA $09
  93.  0F:CBF2: 4A        LSR
  94.  0F:CBF3: 66 0C     ROR $0C
  95.  0F:CBF5: 4A        LSR
  96.  0F:CBF6: 66 0C     ROR $0C
  97.  0F:CBF8: 18        CLC
  98.  0F:CBF9: 69 85     ADC #$85
  99.  0F:CBFB: 85 0D     STA $0D
  100.  0F:CBFD: A4 00     LDY $00
  101. ; I believe this loads the metatile ID.
  102.  0F:CBFF: B1 0C     LDA ($0C),Y
  103.  0F:CC01: 85 0C     STA $0C
  104.  0F:CC03: A9 20     LDA #$20
  105.  0F:CC05: 06 0C     ASL $0C
  106.  0F:CC07: 2A        ROL
  107.  0F:CC08: 06 0C     ASL $0C
  108.  0F:CC0A: 2A        ROL
  109.  0F:CC0B: 85 0D     STA $0D
  110.  0F:CC0D: A0 00     LDY #$00
  111.  0F:CC0F: A5 08     LDA $08
  112.  0F:CC11: 29 10     AND #$10
  113.  0F:CC13: F0 02     BEQ +
  114.  0F:CC15: C8        INY
  115.  0F:CC16: C8        INY
  116. +:
  117.  0F:CC17: A5 0A     LDA $0A
  118.  0F:CC19: 29 10     AND #$10
  119.  0F:CC1B: F0 01     BEQ +
  120.  0F:CC1D: C8        INY
  121. +:
  122. ; Load the type of tile we collided with.
  123.  0F:CC1E: B1 0C     LDA ($0C),Y
  124.  0F:CC20: 85 00     STA $00
  125.  0F:CC22: 06 00     ASL $00
  126.  0F:CC24: 2A        ROL
  127.  0F:CC25: 06 00     ASL $00
  128.  0F:CC27: 2A        ROL
  129.  0F:CC28: 29 03     AND #$03
  130.  0F:CC2A: 85 00     STA $00
  131. ; $00 now contains the tile type, from 0 to 3.
  132. ; 0 = air
  133. ; 1 = ground
  134. ; 2 and 3 = special, determined by the table at $CC44.
  135.  0F:CC2C: 4A        LSR
  136.  0F:CC2D: F0 0F     BEQ exit_bg_collision_check
  137. ; X = 2 * stage_num + (tile_type - 2)
  138.  0F:CC2F: C6 00     DEC $00
  139.  0F:CC31: C6 00     DEC $00
  140.  0F:CC33: A5 2A     LDA stage_num
  141.  0F:CC35: 0A        ASL
  142.  0F:CC36: 65 00     ADC $00
  143.  0F:CC38: AA        TAX
  144. ; There are two special tile entries for each stage.
  145. ;
  146. ; They indicate whether it's supposed to be a ladder,
  147. ; conveyor belt, etc.
  148.  0F:CC39: BD 44 CC  LDA stage_special_tiles,X
  149.  0F:CC3C: 85 00     STA $00
  150. exit_bg_collision_check:
  151. ; Hardcoded switch back to bank E!
  152.  0F:CC3E: A9 0E     LDA #$0E
  153.  0F:CC40: 20 00 C0  JSR bank_switch
  154.  0F:CC43: 60        RTS -----------------------------------------
  155. stage_special_tiles:
  156. ; Two entries for each stage, indicating what tile types
  157. ; 2 and 3 should be (0 and 1 are air and ground).
  158. .db 2, 3, 2, 3, 2, 0, 4, 3, 0, 3, 2, 7, 5, 6, 2, 3
  159. .db 2, 0, 2, 3, 4, 3, 2, 3, 0, 0, 0, 0, $20, $9f, $cb, $a9 ; these last 4 are actually code. There's no stage that would even load them.
  160.  
  161. ; The erroneously disassembled table, 'cause why not
  162.  0F:CC44: 02        UNDEFINED
  163.  0F:CC45: 03        UNDEFINED
  164.  0F:CC46: 02        UNDEFINED
  165.  0F:CC47: 03        UNDEFINED
  166.  0F:CC48: 02        UNDEFINED
  167.  0F:CC49: 00        BRK
  168.  0F:CC4A: 04        UNDEFINED
  169.  0F:CC4B: 03        UNDEFINED
  170.  0F:CC4C: 00        BRK
  171.  0F:CC4D: 03        UNDEFINED
  172.  0F:CC4E: 02        UNDEFINED
  173.  0F:CC4F: 07        UNDEFINED
  174.  0F:CC50: 05 06     ORA $06
  175.  0F:CC52: 02        UNDEFINED
  176.  0F:CC53: 03        UNDEFINED
  177.  
  178.  0F:CC54: 02        UNDEFINED
  179.  0F:CC55: 00        BRK
  180.  0F:CC56: 02        UNDEFINED
  181.  0F:CC57: 03        UNDEFINED
  182.  0F:CC58: 04        UNDEFINED
  183.  0F:CC59: 03        UNDEFINED
  184.  0F:CC5A: 02        UNDEFINED
  185.  0F:CC5B: 03        UNDEFINED
  186.  0F:CC5C: 00        BRK
  187.  0F:CC5D: 00        BRK
  188.  0F:CC5E: 00        BRK
  189.  0F:CC5F: 00        BRK
  190.  0F:CC60: 20 9F CB  JSR bg_collision_check
  191.  0F:CC63: A9 0B     LDA #$0B
  192.  
Advertisement
RAW Paste Data Copied
Advertisement