Advertisement
NovaYoshi

levelprocess.s

Nov 8th, 2015
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .proc PostProcessLevel
  2. Pointer = 0
  3. LeftPointer = 2
  4. RightPointer = 4
  5. RowCount = 6
  6. BoundaryLeft = 7
  7. BoundaryRight = 8
  8. Temp1 = 9
  9. Temp2 = 10
  10.  
  11.   ; initialize pointers
  12.   lda #<$6000
  13.   sta Pointer+0
  14.   lda #>$6000
  15.   sta Pointer+1
  16.  
  17.   lda #<$6010
  18.   sta RightPointer+0
  19.   lda #>$6010
  20.   sta RightPointer+1
  21.  
  22.   lda #<$5ff0 ; open bus, (LeftPointer) will return a 2
  23.   sta LeftPointer+0
  24.   lda #>$5ff0
  25.   sta LeftPointer+1
  26.  
  27. ScreenLoop:
  28.   ldy #0
  29.  
  30.   ; load boundaries
  31.   lda Pointer+1
  32.   and #$0f
  33.   tax
  34.   lda ScreenFlags+0,x
  35.   and #SCREEN_BOUNDARY
  36.   sta BoundaryLeft
  37.   lda ScreenFlags+1,x
  38.   and #SCREEN_BOUNDARY
  39.   sta BoundaryRight
  40.  
  41. RowLoopStart:
  42.   lda #15
  43.   sta RowCount
  44. RowLoop:
  45.   lda (Pointer),y
  46.   tax
  47.   lda MetatileFlags,x
  48.   and #M_POST_PROCESS
  49.   beq NoPostProcess
  50.     tya
  51.     pha
  52.  
  53.     txa ; copy block type back to A
  54.     ldx #0
  55.   : cmp ListOfProcessTiles,x
  56.     beq :+
  57.     inx
  58.     bne :-
  59.   : jsr Launch
  60.  
  61.     pla
  62.     tay
  63. NoPostProcess:
  64.   iny
  65.   dec RowCount
  66.   bne RowLoop
  67.  
  68.   iny ; next column
  69.   bne RowLoopStart ; unless we're at the rightmost column again
  70.  
  71. ; next screen, update pointers
  72.   lda Pointer+1 ; are we at the last screen in the level?
  73.   and #$0f
  74.   cmp LevelSize
  75.   bcs Exit
  76.  
  77.   inc Pointer+1
  78.   inc RightPointer+1
  79.  
  80.   lda Pointer
  81.   sub #16
  82.   sta LeftPointer
  83.   lda Pointer+1
  84.   sbc #0
  85.   sta LeftPointer+1
  86.  
  87.   jmp ScreenLoop
  88. Exit:
  89.   rts
  90.  
  91. Launch:
  92.   lda ListOfProcessAddrHi,x
  93.   pha
  94.   lda ListOfProcessAddrLo,x
  95.   pha
  96.   rts
  97.  
  98. ListOfProcessTiles:
  99.   .byt Metatiles::GROUND_MIDDLE_M
  100.   .byt Metatiles::ROCK_MID_M
  101.   .byt Metatiles::WATER_MAIN
  102.   .byt Metatiles::SOLID_LEDGE_M
  103.   .byt Metatiles::FALLTHROUGH_LEDGE_M
  104.   .byt Metatiles::DOOR_TOP
  105.   .byt Metatiles::EXIT_DOOR_TOP
  106.   .byt Metatiles::CLOUD_M
  107. ListOfProcessAddrLo:
  108.   .byt <(ProcessGround-1)
  109.   .byt <(ProcessRock-1)
  110.   .byt <(ProcessWater-1)
  111.   .byt <(ProcessSolidLedge-1)
  112.   .byt <(ProcessFallthroughLedge-1)
  113.   .byt <(ProcessDoorTop-1)
  114.   .byt <(ProcessDoorTop-1)
  115.   .byt <(ProcessCloud-1)
  116. ListOfProcessAddrHi:
  117.   .byt >(ProcessGround-1)
  118.   .byt >(ProcessRock-1)
  119.   .byt >(ProcessWater-1)
  120.   .byt >(ProcessSolidLedge-1)
  121.   .byt >(ProcessFallthroughLedge-1)
  122.   .byt >(ProcessDoorTop-1)
  123.   .byt >(ProcessDoorTop-1)
  124.   .byt >(ProcessCloud-1)
  125.  
  126. ProcessCloud:
  127.   lda (LeftPointer),y
  128.   cmp #Metatiles::CLOUD_L
  129.   beq :+
  130.   cmp #Metatiles::CLOUD_M
  131.   beq :+
  132.     lda #Metatiles::CLOUD_L
  133.     sta (Pointer),y
  134.   :
  135.   lda (RightPointer),y
  136.   cmp #Metatiles::CLOUD_M
  137.   beq :+
  138.     lda #Metatiles::CLOUD_R
  139.     sta (Pointer),y
  140.   :
  141.   rts
  142.  
  143. ProcessGround:
  144.   lda #0
  145.   sta Temp1
  146.   dey
  147.   lda (Pointer),y
  148.   jsr IsGround
  149.   iny
  150.   lda (LeftPointer),y
  151.   jsr IsGround
  152.   lda (RightPointer),y
  153.   jsr IsGround
  154.   iny
  155.   lda (Pointer),y
  156.   jsr IsGround
  157.   dey
  158.   ldx Temp1
  159.   cpx #15
  160.   beq ExtraGround
  161.   lda GroundLUT,x
  162.   sta (Pointer),y
  163.   rts
  164.  
  165. ExtraGround:
  166.   lda #0
  167.   sta Temp1
  168.   dey
  169.   lda (LeftPointer),y
  170.   jsr IsGround
  171.   lda (RightPointer),y
  172.   jsr IsGround
  173.   iny
  174.   ldx Temp1
  175.   lda ExtraGroundTable,x
  176.   sta (Pointer),y
  177.   rts
  178. ExtraGroundTable:
  179.   .byt Metatiles::GROUND_INNER_BOTH
  180.   .byt Metatiles::GROUND_INNER_LEFT
  181.   .byt Metatiles::GROUND_INNER_RIGHT
  182.   .byt Metatiles::GROUND_MIDDLE_M
  183.  
  184. ProcessRock:
  185.   lda #0
  186.   sta Temp1
  187.   dey
  188.   lda (Pointer),y
  189.   jsr IsRock
  190.   iny
  191.   lda (LeftPointer),y
  192.   jsr IsRock
  193.   lda (RightPointer),y
  194.   jsr IsRock
  195.   iny
  196.   lda (Pointer),y
  197.   jsr IsRock
  198.   dey
  199.   ldx Temp1
  200.   lda RockLUT,x
  201.   sta (Pointer),y
  202.   rts
  203.  
  204. GroundLUT:                            ; ULRD
  205.   .byt Metatiles::GROUND_NARROW_TOP   ; 0000
  206.   .byt Metatiles::GROUND_NARROW_TOP   ; 0001
  207.   .byt Metatiles::GROUND_TOP_L        ; 0010
  208.   .byt Metatiles::GROUND_TOP_L        ; 0011
  209.   .byt Metatiles::GROUND_TOP_R        ; 0100
  210.   .byt Metatiles::GROUND_TOP_R        ; 0101
  211.   .byt Metatiles::GROUND_TOP_M        ; 0110
  212.   .byt Metatiles::GROUND_TOP_M        ; 0111
  213.   .byt Metatiles::GROUND_NARROW_SIDES ; 1000
  214.   .byt Metatiles::GROUND_NARROW_SIDES ; 1001
  215.   .byt Metatiles::GROUND_MIDDLE_L     ; 1010
  216.   .byt Metatiles::GROUND_MIDDLE_L     ; 1011
  217.   .byt Metatiles::GROUND_MIDDLE_R     ; 1100
  218.   .byt Metatiles::GROUND_MIDDLE_R     ; 1101
  219.   .byt Metatiles::GROUND_MIDDLE_M     ; 1110
  220.   .byt Metatiles::GROUND_MIDDLE_M     ; 1111
  221.  
  222. RockLUT:                     ; ULRD
  223.   .byt Metatiles::ROCK_MID_M ; 0000 ?
  224.   .byt Metatiles::ROCK_MID_M ; 0001 ?
  225.   .byt Metatiles::ROCK_MID_M ; 0010 ?
  226.   .byt Metatiles::ROCK_TOP_L ; 0011
  227.   .byt Metatiles::ROCK_MID_M ; 0100 ?
  228.   .byt Metatiles::ROCK_TOP_R ; 0101
  229.   .byt Metatiles::ROCK_MID_M ; 0110 ?
  230.   .byt Metatiles::ROCK_TOP_M ; 0111
  231.   .byt Metatiles::ROCK_MID_M ; 1000 ?
  232.   .byt Metatiles::ROCK_MID_M ; 1001 ?
  233.   .byt Metatiles::ROCK_BOT_L ; 1010
  234.   .byt Metatiles::ROCK_MID_L ; 1011
  235.   .byt Metatiles::ROCK_BOT_R ; 1100
  236.   .byt Metatiles::ROCK_MID_R ; 1101
  237.   .byt Metatiles::ROCK_BOT_M ; 1110
  238.   .byt Metatiles::ROCK_MID_M ; 1111
  239.  
  240. IsFallthroughLedge:
  241.   cmp #Metatiles::FALLTHROUGH_LEDGE_L
  242.   bcc NoItIsnt
  243.   cmp #Metatiles::FALLTHROUGH_LEDGE_S+1
  244.   bcs NoItIsnt
  245.   sec
  246.   rol Temp1
  247.   rts
  248. IsSolidLedge:
  249.   cmp #Metatiles::SOLID_LEDGE_L
  250.   bcc NoItIsnt
  251.   cmp #Metatiles::SOLID_LEDGE_S+1
  252.   bcs NoItIsnt
  253.   sec
  254.   rol Temp1
  255.   rts
  256. IsGround:
  257.   cmp #Metatiles::GROUND_TOP_L
  258.   bcc NoItIsnt
  259.   cmp #Metatiles::GROUND_CLIMB_R+1
  260.   bcs NoItIsnt
  261.   sec
  262.   rol Temp1
  263.   rts
  264. NoItIsnt:
  265.   clc
  266.   rol Temp1
  267.   rts
  268. IsRock:
  269.   cmp #Metatiles::ROCK_TOP_L
  270.   bcc NoItIsnt
  271.   cmp #Metatiles::ROCK_BOT_R+1
  272.   bcs NoItIsnt
  273.   sec
  274.   rol Temp1
  275.   rts
  276.  
  277. ProcessWater:
  278.   dey
  279.   lda (Pointer),y
  280.   cmp #Metatiles::WATER_MAIN
  281.   beq TopIsWater
  282.   cmp #Metatiles::WATER_TOP
  283.   beq TopIsWater
  284.   cmp #Metatiles::WATER_BELOW_SOMETHING
  285.   beq TopIsWater
  286. ; not water, check if it's solid or not
  287.   tax
  288.   lda MetatileFlags,x
  289.   iny
  290.   and #M_SOLID_ALL
  291.   bne :+
  292.     lda #Metatiles::WATER_TOP
  293.     sta (Pointer),y
  294.     rts
  295.   :
  296.   lda #Metatiles::WATER_BELOW_SOMETHING
  297.   sta (Pointer),y
  298. TopIsWater:
  299.   rts
  300.  
  301. ProcessSolidLedge:
  302.   lda #0
  303.   sta Temp1
  304.   lda (LeftPointer),y
  305.   jsr IsSolidLedge
  306.   lda (RightPointer),y
  307.   jsr IsSolidLedge
  308.   ldx Temp1
  309.   lda SolidLedges,x
  310.   sta (Pointer),y
  311.   rts
  312. SolidLedges:
  313.   .byt Metatiles::SOLID_LEDGE_S
  314.   .byt Metatiles::SOLID_LEDGE_L
  315.   .byt Metatiles::SOLID_LEDGE_R
  316.   .byt Metatiles::SOLID_LEDGE_M
  317.  
  318. ProcessFallthroughLedge:
  319.   lda #0
  320.   sta Temp1
  321.   lda (LeftPointer),y
  322.   jsr IsFallthroughLedge
  323.   lda (RightPointer),y
  324.   jsr IsFallthroughLedge
  325.   ldx Temp1
  326.   lda FallLedges,x
  327.   sta (Pointer),y
  328.   rts
  329. FallLedges:
  330.   .byt Metatiles::FALLTHROUGH_LEDGE_S
  331.   .byt Metatiles::FALLTHROUGH_LEDGE_L
  332.   .byt Metatiles::FALLTHROUGH_LEDGE_R
  333.   .byt Metatiles::FALLTHROUGH_LEDGE_M
  334.  
  335. ProcessDoorTop:
  336.   iny
  337.   lda #Metatiles::DOOR_BOTTOM
  338.   sta (Pointer),y
  339.   rts
  340. .endproc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement