Advertisement
Guest User

Untitled

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