Advertisement
Guest User

Untitled

a guest
Jun 9th, 2019
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. *=$C000
  2.  
  3. ; Generic memcpy optimized for speed. No overlapping
  4. ;
  5. ; Copy operation is divided in two parts.  N is the total length
  6. ; * memcpyLong  for N / 256 blocks
  7. ; * memcpyShort for N % 256 remaining bytes
  8.  
  9. memcpySrc = $E0
  10. memcpyDst = $E2
  11. memcpyLen = $E4
  12.  
  13.  
  14. ; set for characters
  15.      lda #$95
  16.      sta memcpySrc
  17.      lda #$35
  18.      sta memcpySrc+1
  19.  
  20.      lda #$00
  21.      sta memcpyDst
  22.      lda #$04
  23.      sta memcpyDst+1
  24.  
  25.      lda #$E8
  26.      sta memcpyLen
  27.      lda #$03
  28.      sta memcpyLen+1
  29.  
  30.      jsr memcpy
  31.  
  32. ; set for attributes
  33.      lda #$95
  34.      sta memcpySrc
  35.      lda #$39
  36.      sta memcpySrc+1
  37.  
  38.      lda #$00
  39.      sta memcpyDst
  40.      lda #$d8
  41.      sta memcpyDst+1
  42.  
  43.      lda #$E8
  44.      sta memcpyLen
  45.      lda #$03
  46.      sta memcpyLen+1
  47.  
  48.      jsr memcpy
  49.      rts
  50.  
  51.  
  52. memcpy
  53.      ldy #0
  54.      ldx memcpyLen+1
  55.      beq memcpyShort           ; We need only the short version for <1 pages
  56.  
  57. memcpyLoopLong                 ; Copy X pages
  58.      lda (memcpySrc),y         ; Loop unrolling can be done with confidence here
  59.      sta (memcpyDst),y         ; any power of 2 will work
  60.      iny
  61.      bne memcpyLoopLong
  62.      dex
  63.      beq memcpyShort
  64.      inc memcpySrc+1           ; Go to the next page
  65.      inc memcpyDst+1
  66.      jmp memcpyLoopLong
  67.  
  68. memcpyShort                    ; Copy remaining bytes
  69.      ldx memcpyLen
  70.      beq memcpyEnd
  71.  
  72. memcpyLoopShort                ; Copy X bytes
  73.      lda (memcpySrc),y
  74.      sta (memcpyDst),y
  75.      iny
  76.      dex
  77.      bne memcpyLoopShort
  78.  
  79. memcpyEnd
  80.      rts
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement