zlz_decomp.z80 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. inloc = tempword1
  2. incnt = tempword2
  3. zlz_decomp:
  4. ;Input:
  5. ; HL points to the zlz compressed data
  6. ; DE points to the output stream
  7. ; BC is the size of the data
  8. ;Notes:
  9. ; While the format that this accepts uses arbitrary numbers of bits for
  10. ; sizes and offsets, this Z80 algorithm only works on 13-bit or 14-bit
  11. ; values (context dependent)
  12. ;
  13. ld a,(hl)
  14. inc hl
  15. add a,a
  16. ld (incnt),bc
  17. jr c,cpindex
  18. ;from here, read the size in, then copy the data
  19. add a,a
  20. ld b,0
  21. ld c,a
  22. jr nc,+_
  23. ld a,(hl)
  24. inc hl
  25. add a,a
  26. ret c
  27. rrca
  28. ld b,a
  29. call deccnt
  30. _:
  31. srl b
  32. rr c
  33. srl b
  34. rr c
  35. push hl
  36. ld hl,(incnt)
  37. sbc hl,bc
  38. ld (incnt),hl
  39. pop hl
  40. ldir
  41. dec hl
  42. ld bc,(incnt)
  43. cpi
  44. jp pe,zlz_decomp
  45. ret
  46. cpindex:
  47. add a,a
  48. ld b,0
  49. ld c,a
  50. jr nc,+_
  51. ld a,(hl)
  52. inc hl
  53. add a,a
  54. ret c
  55. rrca
  56. ld b,a
  57. call deccnt
  58. _:
  59. srl b
  60. rr c
  61. srl b
  62. rr c
  63. ;BC is the new size
  64. ;Now we need to grab the index
  65. push bc
  66. ld a,(hl)
  67. add a,a
  68. ld b,0
  69. ld c,a
  70. jr nc,+_
  71. inc hl
  72. ld a,(hl)
  73. add a,a
  74. jp c,pop_exit
  75. rrca
  76. ld b,a
  77. call deccnt
  78. _:
  79. srl b
  80. rr c
  81. ld (inloc),hl
  82. ld h,d
  83. ld l,e
  84. or a
  85. sbc hl,bc
  86. pop bc
  87. ldir
  88. ld hl,(inloc)
  89. ld bc,(incnt)
  90. dec bc
  91. cpi
  92. jp pe,zlz_decomp
  93. ret
  94. deccnt:
  95. push hl
  96. ld hl,(incnt)
  97. dec hl
  98. ld (incnt),hl
  99. pop_exit:
  100. pop hl
  101. ret