Advertisement
Guest User

Untitled

a guest
Jul 11th, 2018
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.    
  2.                 ;global variables & constants
  3.    
  4. speed = 1           ;speed
  5. intX = 255 - 24         ;x is leftSprite
  6. intY = 30+20            ;Y is bottomSprite
  7. x0 = $D000 
  8. y0 = $D001
  9. xMSB = $D010
  10. dRight = 88-23          ;343-255 = 88 - 23 x collision threshold with msb set - sprite width
  11. cRight = dRight-speed       ;final x collision threshold one frame before
  12. cLeft = 24+speed        ; same
  13. cTop = 30           ;y collision
  14. cBottom = 229           ; same
  15. dx .byte speed
  16. dy .byte speed
  17. temp .byte 0   
  18. inter .word ?
  19.  
  20.    
  21.     *       = $1000
  22.    
  23.  start
  24.  
  25.                 ;init sprite & isr vector
  26.    
  27.     lda #1
  28.     sta $d015
  29.     lda #intX
  30.     sta x0
  31.     lda #intY
  32.     sta y0
  33.  
  34.     lda $314
  35.     sta inter
  36.     lda $315
  37.     sta inter+1
  38.    
  39.     sei
  40.     lda #<main_loop
  41.     sta $314
  42.     lda #>main_loop
  43.     sta $315
  44.     cli
  45.     rts
  46.  
  47.  
  48.                             ;update sprites
  49. main_loop
  50.  
  51.     lda x0
  52.     ldx dx
  53.     ldy xMSB
  54.     cpx #128        ;direction check
  55.     bcs goingL
  56. goingR
  57.     cpy #1
  58.     beq msbSetR
  59.     cmp #256 - speed    ;256 is for overflow - speed is for a frame before that speed is  intended always > 0
  60.     bcc endC        ;just update
  61.     lda #1
  62.     sta xMSB
  63. endC    clc
  64.     adc dx
  65.     sta x0
  66.         ;jmp (inter)   
  67. yUpdate
  68.     lda y0
  69.     ldy dy
  70.     cpy #128        ;direction check
  71.     bcs goingU
  72. goingD
  73.    
  74.     cmp #cBottom - speed
  75.     bcc endCY       ;just update
  76.     sec
  77.     sbc #cBottom
  78.     sta temp
  79.     lda #cBottom
  80.     sec
  81.     sbc temp
  82.     sta y0
  83.     ldx #-speed
  84.     stx dy
  85.    
  86. endCY   clc
  87.     adc dy
  88.     sta y0
  89.     jmp (inter)         ;back to isr
  90.  
  91. goingL
  92.     cpy #1
  93.     beq msbSetL
  94.     ; if MSB is not set
  95.     cmp #cLeft
  96.     bcs endC        ;just update
  97.     sta temp
  98.     lda #cLeft
  99.     sec
  100.     sbc temp
  101.     sta temp
  102.     lda #cLeft
  103.     clc
  104.     adc temp
  105.     ldx #speed      ;invert direction
  106.     stx dx
  107.     jmp (inter)
  108.    
  109. msbSetR        
  110.     cmp #cRight + speed
  111.     bcc endC
  112.     sec
  113.     sbc #cRight
  114.     sta temp
  115.     lda #dRight
  116.     sec
  117.     sbc temp
  118.     sta x0
  119.     lda #-speed
  120.     sta dx
  121.     lda x0
  122. jEndC   jmp endC
  123.  
  124. wrapR
  125.     sec
  126.     sbc #cRight
  127.     sta temp
  128.     lda #speed
  129.     sec
  130.     sbc temp
  131.     clc
  132.     adc #cRight
  133.     sta x0
  134.     lda #-speed
  135.     sta dx
  136.     jmp (inter)
  137.  
  138. goingU
  139.     cmp #cTop + 20 + speed + 1 ; +1 for bcs
  140.     bcs endCY       ;just update
  141.     sta temp
  142.     lda #cTop + 20
  143.     sec
  144.     sbc temp
  145.     sta temp
  146.     lda #cTop+20
  147.     clc
  148.     adc temp
  149.     sta y0
  150.     ldx #speed
  151.     stx dy
  152.     jmp endCY
  153.    
  154. msbSetL
  155.     cmp #speed + 1      ;check if we need to clear MSB, + 1 for bcs
  156.     bcs jEndC       ;trampoline to endC, just update
  157.     sta temp
  158.     lda speed
  159.     sec
  160.     sbc temp
  161.     lda #0
  162.     sta xMSB
  163.     jmp endC
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement