Advertisement
atm959

PlaceBorder

Mar 12th, 2021
2,567
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;PlaceBorder
  2. ;
  3. ;Parameters:
  4. ;  Temp+0 - X Position
  5. ;  Temp+2 - Y Position
  6. ;  Temp+4 - Inside Width
  7. ;  Temp+6 - Inside Height
  8. ;
  9. ;Used Temporary Memory:
  10. ;  Temp+8 - Temporary counter
  11. ;  Temp+10 - Top-left tile offset (for placing the sides)
  12. ;  Temp+12 - Top-right tile offset (for placing the sides)
  13. PlaceBorder:
  14.     rep #$20    ;Set A to 16-bit
  15.  
  16.     ;Calculate the offset for the top border tiles:
  17.     lda Temp+2 ;Load the Y position into A
  18.     asl
  19.     asl
  20.     asl
  21.     asl
  22.     asl ;Multiply it by 32
  23.     clc ;Clear the carry flag
  24.     adc Temp+0 ;Add the X position to it
  25.     asl ;Multiply it by 2
  26.     tax ;Transfer A to X
  27.  
  28.     sta Temp+10 ;Store A for later
  29.     lda Temp+4 ;Load the inside width into A
  30.     clc ;Clear the carry flag
  31.     adc #1 ;Add one to it
  32.     asl ;Multiply it by 2
  33.     clc ;Clear the carry flag
  34.     adc Temp+10 ;Add the stored left offset to it, to get the right offset
  35.     sta Temp+12 ;Store the right offset into memory
  36.  
  37.     ;Calculate the offset for the bottom border tiles:
  38.     lda Temp+2 ;Load the Y position into A
  39.     clc ;Clear the carry flag
  40.     adc Temp+6 ;Add the inside height
  41.     clc ;Clear the carry flag
  42.     adc #1 ;Add 1 more
  43.     asl
  44.     asl
  45.     asl
  46.     asl
  47.     asl ;Multiply it by 32
  48.     clc ;Clear the carry flag
  49.     adc Temp+0 ;Add the X position to it
  50.     asl ;Multiply it by 2
  51.     tay ;Transfer A to Y
  52.  
  53.     sep #$20    ;Set A to 8-bit
  54.  
  55.     lda #14
  56.     sta Screen, x ;Top-left corner
  57.     lda #30
  58.     sta Screen, y ;Bottom-left corner
  59.  
  60.     inx
  61.     inx ;Point to the tile to the right on the top
  62.     iny
  63.     iny ;Point to the tile to the right on the bottom
  64.  
  65.     lda #$00
  66.     sta Temp+8 ;Temporary counter
  67. .placeTopAndBottomBorderLoop:
  68.     lda #13
  69.     sta Screen, x ;Place a border tile on the top
  70.     sta Screen, y ;Place a border tile on the bottom
  71.     inx
  72.     inx ;Point to the tile to the right on the top
  73.     iny
  74.     iny ;Point to the tile on the right on the bottom
  75.  
  76.     lda Temp+8 ;Load the temporary counter into A
  77.     ina ;Increment A
  78.     sta Temp+8 ;Store A into the temporary counter
  79.     cmp Temp+4 ;Compare it with the inside width
  80.     bne .placeTopAndBottomBorderLoop ;If not equal, place another tile on the top and bottom
  81.  
  82.     lda #15
  83.     sta Screen, x ;Place the top-right tile
  84.     lda #31
  85.     sta Screen, y ;Place the bottom-right tile
  86.  
  87.     rep #$20 ;Set A to 16-bit
  88.     lda Temp+10 ;Load the left offset into A
  89.     clc ;Clear the carry flag
  90.     adc #64 ;Point to one tile down
  91.     tax ;Copy A to X
  92.     lda Temp+12 ;Load the right offset into A
  93.     clc ;Clear the carry flag
  94.     adc #64 ;Point to one tile down
  95.     tay ;Copy A to Y
  96.     sep #$20 ;Set A to 8-bit
  97.  
  98.     lda #$00
  99.     sta Temp+8 ;Temporary counter
  100. .placeLeftAndRightBorderLoop:
  101.     lda #29
  102.     sta Screen, x
  103.     sta Screen, y
  104.  
  105.     rep #$20 ;Set A to 16-bit
  106.     txa ;Copy X to A
  107.     clc ;Clear the carry flag
  108.     adc #64 ;Point to one tile down
  109.     tax ;Copy A to X
  110.     tya ;Copy Y to A
  111.     clc ;Clear the carry flag
  112.     adc #64 ;Point to one tile down
  113.     tay ;Copy A to Y
  114.  
  115.     lda Temp+8 ;Load the temporary counter into A
  116.     ina ;Increment A
  117.     sta Temp+8 ;Store A into the temporary counter
  118.     cmp Temp+6 ;Compare it with the inside height
  119.     sep #$20 ;Set A to 8-bit
  120.     bne .placeLeftAndRightBorderLoop ;If not equal, place another tile on the left and right
  121.  
  122.     rtl
Advertisement
RAW Paste Data Copied
Advertisement