Advertisement
NovaYoshi

ChkTouchGeneric

Apr 30th, 2016
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; Does a collision check on two rectangles
  2. ; input: TouchTopA/B, TouchLeftA/B, TouchWidthA/B, TouchHeightA/B
  3. ; output: carry (rectangles are overlapping)
  4. .proc ChkTouchGeneric
  5.   ; http://atariage.com/forums/topic/71120-6502-killer-hacks/page-3?&#entry1054049
  6. ; X positions
  7.   lda TouchWidthB
  8.   add TouchWidthA ; carry is clear afterwards
  9.   adc #<-1        ; so this subtracts 1
  10.   sta TouchTemp2  ; now carry is set
  11.   lda TouchWidthB
  12.   sbc #1
  13.   sta TouchTemp
  14.  
  15.   clc
  16.   lda TouchLeftA
  17.   sbc TouchLeftB ; Note will subtract n-1
  18.   sbc TouchTemp  ;#SIZE2-1
  19.   adc TouchTemp2 ;#SIZE1+SIZE2-1 ; Carry set if overlap
  20.   bcc No
  21.  
  22. ; Y positions
  23.   lda TouchHeightB
  24.   add TouchHeightA ; carry is clear afterwards
  25.   adc #<-1         ; so this subtracts 1
  26.   sta TouchTemp2   ; now carry is set
  27.   lda TouchHeightB
  28.   sbc #1
  29.   sta TouchTemp
  30.  
  31.   clc
  32.   lda TouchTopA
  33.   sbc TouchTopB ; Note will subtract n-1
  34.   sbc TouchTemp  ;#SIZE2-1
  35.   adc TouchTemp2 ;#SIZE1+SIZE2-1 ; Carry set if overlap
  36.   bcc No
  37.  
  38.   sec
  39.   rts
  40. No:
  41.   clc
  42.   rts
  43. .endproc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement