Advertisement
Guest User

Untitled

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