Gameboy implementation of fast, reasonably accurate 8-bit interpolation. Licensed under zero-clause BSD/ISC/OpenBSD license.

形式
Asm
投稿日時
2021-04-12 11:01
公開期間
無期限
  1. ;; Copyright 2021 AlaskanEmily
  2. ;;
  3. ;; Permission to use, copy, modify, and/or distribute this software for any
  4. ;; purpose with or without fee is hereby granted, provided that the above
  5. ;; copyright notice and this permission notice appear in all copies.
  6. ;;
  7. ;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  8. ;; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  9. ;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  10. ;; ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  11. ;; LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  12. ;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  13. ;; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  14. ;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  15. ;; CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  16. ;; ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  17. ;; POSSIBILITY OF SUCH DAMAGE.
  18. ; ASM implementation of this C routine:
  19. ; unsigned interpolate(uint8_t t, uint8_t a, uint8_t b){
  20. ; uint8_t value, diff, dx;
  21. ; if(a > b){
  22. ; value = a;
  23. ; a = b;
  24. ; b = value;
  25. ; t = 255 - t;
  26. ; }
  27. ; diff = b - a;
  28. ; value = a;
  29. ; do{
  30. ; dx = diff & 1;
  31. ; diff >>= 1;
  32. ; if(t & 0x80)
  33. ; value += diff + dx;
  34. ; }while(t <<= 1);
  35. ; return value;
  36. ; }
  37. ; The extra offset of dx here is a very rough form of rounding.
  38. ; If you do not include this, then the results will be about 1/16th too low.
  39. ; Calculates the interpolation at a (0 to 255) of b to c
  40. ; Returns in a.
  41. interpolate:
  42. push de
  43. ld d, a ; Save the T-value in d
  44. ; Swap the interpolation range and T value if necessary
  45. ld a, c
  46. sub b
  47. jrnc @$interpolate_inner
  48. ; Swap b and c
  49. ld e, b
  50. ld b, c
  51. ld c, e
  52. ; Negate the T-value
  53. ld a, 0xFF
  54. sub d
  55. ld d, a
  56. $interpolate_inner:
  57. ld a, c
  58. sub b
  59. ld e, a
  60. ; e has the difference now.
  61. ld a, b
  62. $interpolate_bit:
  63. ; srl will set the carry bit, and bit doesn't modify it.
  64. ; This lets us use adc rather than add plus an inc and a jump below.
  65. srl e
  66. bit7 d
  67. jrz @.no_add
  68. adc e
  69. .no_add:
  70. sla d
  71. jrnz @$interpolate_bit
  72. pop de
  73. ret
ダウンロード 印刷用表示

このコピペの URL

JavaScript での埋め込み

iframe での埋め込み

元のテキスト