Advertisement
luckytyphlosion

DED dynamic bitree code.

Dec 19th, 2016
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. WriteDEDTreeToWRAM:
  2. ld d, h
  3. ld e, l
  4. ld hl, GetDEDByte
  5. ld a, LD_A_FFXX_OP
  6. ld [hli], a
  7. ld a, hCurBitStream & $ff
  8. ld [hli], a
  9. .loop
  10. ; control codes are styled as follows
  11. ; 1110 xxxx xxxx xxxx: internal internal, x is jump offset
  12. ; 1100 xxxx 0000 yyyy: leaf leaf, x if 1, y if 0
  13. ; 1000 xxxx: internal leaf, x if 1
  14. ; 0xxx xxxx: internal internal, x is jump offset
  15. ; 1111 1111: terminator, signifies end of stream
  16. ld a, [de]
  17. cp $ff
  18. jr z, .end
  19. add a
  20. jr nc, .huffhuffjr
  21. add a
  22. jr nc, .huffleaf
  23. add a
  24. jr nc, .leafleaf
  25. .huffhuffjp
  26. call CopyBitreeCode
  27. push bc
  28. ld a, JP_C_OP
  29. ld [hli], a
  30. ld a, [de]
  31. and $f
  32. ld b, a
  33. inc de
  34. ld a, [de]
  35. inc de
  36. ld c, a
  37. push hl
  38. add hl, bc
  39. inc hl
  40. inc hl
  41. ld b, h
  42. ld c, l
  43. pop hl
  44. ld a, c
  45. ld [hli], a
  46. ld a, b
  47. ld [hli], a
  48. pop bc
  49. jr .loop
  50. .leafleaf
  51. call .leafcommon
  52. ld a, LD_B_XX_OP
  53. ld [hli], a
  54. ld a, [de]
  55. inc de
  56. ld [hli], a
  57. ld a, RET_OP
  58. ld [hli], a
  59. jr .loop
  60. .huffleaf
  61. call .leafcommon
  62. jr .loop
  63. .huffhuffjr
  64. call CopyBitreeCode
  65. ld a, JR_C_OP
  66. ld [hli], a
  67. ld a, [de]
  68. inc de
  69. ld [hli], a
  70. jr .loop
  71. .end
  72. inc de
  73. ld h, d
  74. ld l, e
  75. ret
  76. .leafcommon
  77. call CopyBitreeCode
  78. ld a, LD_B_XX_OP
  79. ld [hli], a
  80. ld a, [de]
  81. inc de
  82. and $f
  83. ld [hli], a
  84. ld a, RET_C_OP
  85. ld [hli], a
  86. ret
  87.  
  88. CopyBitreeCode:
  89. ld a, DEC_C_OP
  90. ld [hli], a
  91. ld a, JR_NZ_OP
  92. ld [hli], a
  93. ld a, 3
  94. ld [hli], a
  95. ld a, LD_A_HLI_OP
  96. ld [hli], a
  97. ld a, LD_C_XX_OP
  98. ld [hli], a
  99. ld a, 8
  100. ld [hli], a
  101. ld a, ADD_A_OP
  102. ld [hli], a
  103. ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement