scale_sprites.asm 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. ; scales both uncompressed sprite chunks by two in every dimension (creating 2x2 output pixels per input pixel)
  2. ; assumes that input sprite chunks are 4x4 tiles, and the rightmost and bottommost 4 pixels will be ignored
  3. ; resulting in a 7*7 tile output sprite chunk
  4. ScaleSpriteByTwo:
  5. ld de, sSpriteBuffer1 + (4*4*8) - 5 ; last byte of input data, last 4 rows already skipped
  6. ld hl, sSpriteBuffer0 + SPRITEBUFFERSIZE - 1 ; end of destination buffer
  7. call ScaleLastSpriteColumnByTwo ; last tile column is special case
  8. call ScaleFirstThreeSpriteColumnsByTwo ; scale first 3 tile columns
  9. ld de, sSpriteBuffer2 + (4*4*8) - 5 ; last byte of input data, last 4 rows already skipped
  10. ld hl, sSpriteBuffer1 + SPRITEBUFFERSIZE - 1 ; end of destination buffer
  11. call ScaleLastSpriteColumnByTwo ; last tile column is special case
  12. ScaleFirstThreeSpriteColumnsByTwo:
  13. ld b, $3 ; 3 tile columns
  14. .columnLoop
  15. ld c, 4*8 - 4 ; $1c, 4 tiles minus 4 unused rows
  16. .columnInnerLoop
  17. push bc
  18. ld a, [de]
  19. ld bc, -(7*8)+1 ; $ffc9, scale lower nybble and seek to previous output column
  20. call ScalePixelsByTwo
  21. ld a, [de]
  22. dec de
  23. swap a
  24. ld bc, 7*8+1-2 ; $37, scale upper nybble and seek back to current output column and to the next 2 rows
  25. call ScalePixelsByTwo
  26. pop bc
  27. dec c
  28. jr nz, .columnInnerLoop
  29. dec de
  30. dec de
  31. dec de
  32. dec de
  33. ld a, b
  34. ld bc, -7*8 ; $ffc8, skip one output column (which has already been written along with the current one)
  35. add hl, bc
  36. ld b, a
  37. dec b
  38. jr nz, .columnLoop
  39. ret
  40. ScaleLastSpriteColumnByTwo:
  41. ld a, 4*8 - 4 ; $1c, 4 tiles minus 4 unused rows
  42. ld [H_SPRITEINTERLACECOUNTER], a
  43. ld bc, -1
  44. .columnInnerLoop
  45. ld a, [de]
  46. dec de
  47. swap a ; only high nybble contains information
  48. call ScalePixelsByTwo
  49. ld a, [H_SPRITEINTERLACECOUNTER]
  50. dec a
  51. ld [H_SPRITEINTERLACECOUNTER], a
  52. jr nz, .columnInnerLoop
  53. dec de ; skip last 4 rows of new column
  54. dec de
  55. dec de
  56. dec de
  57. ret
  58. ; scales the given 4 bits in a (4x1 pixels) to 2 output bytes (8x2 pixels)
  59. ; hl: destination pointer
  60. ; bc: destination pointer offset (added after the two bytes have been written)
  61. ScalePixelsByTwo:
  62. push hl
  63. and $f
  64. ld hl, DuplicateBitsTable
  65. add l
  66. ld l, a
  67. jr nc, .noCarry
  68. inc h
  69. .noCarry
  70. ld a, [hl]
  71. pop hl
  72. ld [hld], a ; write output byte twice to make it 2 pixels high
  73. ld [hl], a
  74. add hl, bc ; add offset
  75. ret
  76. ; repeats each input bit twice
  77. DuplicateBitsTable:
  78. db $00, $03, $0c, $0f
  79. db $30, $33, $3c, $3f
  80. db $c0, $c3, $cc, $cf
  81. db $f0, $f3, $fc, $ff