Advertisement
Guest User

Untitled

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