Advertisement
Er0l

B2 Decruncher

Dec 30th, 2020
408
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. // ByteBoozer Decruncher /HCL May.2003
  2. // B2 Decruncher December 2014
  3.  
  4. .importonce
  5. .filenamespace b2
  6.  
  7. // You must set .const B2_ZP_BASE prior the import of this file
  8. .if (B2_ZP_BASE > $ff) {
  9. .error "B2_ZP_BASE must be in zeropage. Was $" + toHexString(B2_ZP_BASE,4)
  10. }
  11.  
  12.  
  13. .label zp_base = B2_ZP_BASE
  14. .label bits = zp_base
  15. .label put = zp_base + 2
  16.  
  17. .macro @B2_DECRUNCH(addr) {
  18. ldy #<addr
  19. ldx #>addr
  20. jsr b2.Decrunch
  21. }
  22.  
  23. .macro GetNextBit() {
  24. asl bits
  25. bne DgEnd
  26. jsr GetNewBits
  27. DgEnd:
  28. }
  29.  
  30. .macro GetLen() {
  31. lda #1
  32. GlLoop:
  33. :GetNextBit()
  34. bcc GlEnd
  35. :GetNextBit()
  36. rol
  37. bpl GlLoop
  38. GlEnd:
  39. }
  40.  
  41. Decrunch:
  42. sty Get1+1
  43. sty Get2+1
  44. sty Get3+1
  45. stx Get1+2
  46. stx Get2+2
  47. stx Get3+2
  48.  
  49. ldx #0
  50. jsr GetNewBits
  51. sty put-1,x
  52. cpx #2
  53. bcc *-7
  54. lda #$80
  55. sta bits
  56. DLoop:
  57. :GetNextBit()
  58. bcs Match
  59. Literal:
  60. // Literal run.. get length.
  61. :GetLen()
  62. sta LLen+1
  63.  
  64. ldy #0
  65. LLoop:
  66. Get3:
  67. lda $feed,x
  68. inx
  69. bne *+5
  70. jsr GnbInc
  71. L1: sta (put),y
  72. iny
  73. LLen:
  74. cpy #0
  75. bne LLoop
  76.  
  77. clc
  78. tya
  79. adc put
  80. sta put
  81. bcc *+4
  82. inc put+1
  83.  
  84. iny
  85. beq DLoop
  86.  
  87. // Has to continue with a match..
  88.  
  89. Match:
  90. // Match.. get length.
  91. :GetLen()
  92. sta MLen+1
  93.  
  94. // Length 255 -> EOF
  95. cmp #$ff
  96. beq End
  97.  
  98. // Get num bits
  99. cmp #2
  100. lda #0
  101. rol
  102. :GetNextBit()
  103. rol
  104. :GetNextBit()
  105. rol
  106. tay
  107. lda Tab,y
  108. beq M8
  109.  
  110. // Get bits < 8
  111. M_1:
  112. :GetNextBit()
  113. rol
  114. bcs M_1
  115. bmi MShort
  116. M8:
  117. // Get byte
  118. eor #$ff
  119. tay
  120. Get2:
  121. lda $feed,x
  122. inx
  123. bne *+5
  124. jsr GnbInc
  125. jmp Mdone
  126. MShort:
  127. ldy #$ff
  128. Mdone:
  129. //clc
  130. adc put
  131. sta MLda+1
  132. tya
  133. adc put+1
  134. sta MLda+2
  135.  
  136. ldy #$ff
  137. MLoop:
  138. iny
  139. MLda:
  140. lda $beef,y
  141. sta (put),y
  142. MLen:
  143. cpy #0
  144. bne MLoop
  145.  
  146. //sec
  147. tya
  148. adc put
  149. sta put
  150. bcc *+4
  151. inc put+1
  152.  
  153. jmp DLoop
  154.  
  155. End:
  156. rts
  157.  
  158. GetNewBits:
  159. Get1:
  160. ldy $feed,x
  161. sty bits
  162. rol bits
  163. inx
  164. bne GnbEnd
  165. GnbInc:
  166. inc Get1+2
  167. inc Get2+2
  168. inc Get3+2
  169. GnbEnd:
  170. rts
  171.  
  172. Tab:
  173. // Short offsets
  174. .byte %11011111 // 3
  175. .byte %11111011 // 6
  176. .byte %00000000 // 8
  177. .byte %10000000 // 10
  178. // Long offsets
  179. .byte %11101111 // 4
  180. .byte %11111101 // 7
  181. .byte %10000000 // 10
  182. .byte %11110000 // 13
  183.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement