Advertisement
Guest User

fastCopy routine for tilemap

a guest
Jan 29th, 2012
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;##########################
  2. ;#UPDATEROTATION
  3. ;#After changing the x offset
  4. ;# of the map, we need to update
  5. ;# the rotation in the fastcopy
  6. ;# routine.
  7. ;#Explanation:
  8. ;#It's a bit confusing i admit,
  9. ;# if you have any questions about
  10. ;# this part it'd probably be better
  11. ;# for now just to ask me personally
  12. ;# about it.
  13. ;##########################
  14. updateRotation:
  15.     ld a,(xOff)         ;what is the xOffset?
  16.     and 7               ;we're only interested in the lower three bits (essentially xOff % 8)
  17.     ld hl,gbufMask
  18.     ld e,a
  19.     ld d,0
  20.     add hl,de           ;pointer to the rotation mask
  21.     ex af,af'           ;save a (swap with shadow register)
  22.    ld a,(hl)
  23.    ld hl,maskLeft
  24.    ld (hl),a
  25.    ld hl,maskRight
  26.    cpl                 ;xor $FF
  27.    ld (hl),a
  28.    ex af,af'
  29.  
  30.     ld hl,rotateRight
  31.     cp 4
  32.     jr nc,rotarDer
  33.     ld hl,rotateLeft
  34. rotarDer:
  35.     and %00000011
  36.     ld e,a
  37.     ld d,0
  38.     add hl,de
  39.     push hl
  40.     ld de,rotLeft
  41.     ldi
  42.     ldi
  43.     ldi
  44.     ldi
  45.     pop hl
  46.     ld de,rotRight
  47.     ldi
  48.     ldi
  49.     ldi
  50.     ldi
  51.     ret
  52.  
  53. rotateRight:       ;if offset greater than or equal to 4, rotate the gbuf right up to four times
  54.     rrca
  55.     rrca
  56.     rrca
  57.     rrca
  58. rotateLeft:       ;the nops keep it smoother (same delay as rlca)
  59.     nop          ; so whether we shift or not, it will take the same amount of cycles
  60.     nop
  61.     nop
  62.     nop
  63.     rlca
  64.     rlca
  65.     rlca
  66.     rlca
  67. gbufMask:
  68. .db %11111111   ;0 display all of the first byte, none of the second
  69. .db %11111110   ;1 after rotating left once, we only want the 7 leftern most bits of byte 1, and rightmost bit of byte 2
  70. .db %11111100   ;2
  71. .db %11111000   ;3
  72. .db %11110000   ;4
  73. .db %11100000   ;5
  74. .db %11000000   ;6
  75. .db %10000000   ;7
  76.  
  77. drawGbuf:
  78.     ld a,$80
  79.     out ($10),a     ;set row ($80: 0, to $BF:63)
  80.     ld hl,saferam1-14+(14*64)-14    ;
  81.                                     ;
  82. xOff = $+1
  83.     ld a,0          ;if xOff > 8, skip the first byte (it's offscreen)
  84.     cp 8
  85.     jr c,$+3
  86.     inc hl
  87. noSkip:
  88. yOff = $+1
  89.     ld b,0
  90.     inc b
  91.     ld de,14
  92.     add hl,de
  93.     djnz $-4
  94. noSkip2:
  95.     ld a,$20        ;$20: col 0, $2E: col 14
  96.     ld c,a
  97.     ld b,64         ;64 filas
  98. fastCopyAgain:
  99.     inc c           ;avanzar a proxima fila
  100.     push bc
  101.     ld de,-(14*64)
  102.     out ($10),a     ;actualizar columna
  103.     add hl,de
  104.     ld de,13
  105.     inc hl
  106. fastCopyLoop:
  107.     add hl,de
  108.     ld a,(hl)       ;cargar valor en gbuf a a
  109. rotLeft:
  110.  .db 0,0,0,0            ;rotate the values we need
  111. maskLeft = $+1
  112.     and $FF         ;necesitamos los valores de la izquierda
  113.     ld c,a
  114.     inc hl
  115.     ld a,(hl)       ;el proximo byte que llena el resto del primero
  116. rotRight:
  117.  .db 0,0,0,0
  118. maskRight = $+1
  119.     and 0
  120.     or c
  121.     out ($11),a
  122.     djnz fastCopyLoop
  123.     pop bc
  124.     ld a,c
  125.     cp $2B+1
  126.     jr nz,fastCopyAgain
  127.     ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement