Advertisement
vladikcomper

Contra Hard Corps - Decompression Routine

Aug 20th, 2013
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ROM:00006512 KonDec:                                 ; CODE XREF: sub_17F78+Cp
  2. ROM:00006512                 move.w  (a5)+,d0
  3. ROM:00006514                 bra.s   @InitDecomp
  4. ROM:00006516 ; ---------------------------------------------------------------------------
  5. ROM:00006516 ; UNUSED CODE
  6. ROM:00006516                 addq.l  #2,a5           ; skip 2 bytes in compressed stream
  7. ROM:00006518 ; ---------------------------------------------------------------------------
  8. ROM:00006518
  9. ROM:00006518 @InitDecomp:                            ; CODE XREF: KonDec+2j
  10. ROM:00006518                 lea     (@MainLoop).l,a0
  11. ROM:0000651E                 moveq   #0,d7           ; ignore the following DBF
  12. ROM:00006520
  13. ROM:00006520 @MainLoop:                              ; DATA XREF: KonDec:@InitDecompo
  14. ROM:00006520                 dbf     d7,@RunDecoding ; if bits in decription field remain, branch
  15. ROM:00006524                 moveq   #7,d7           ; set repeat count to 8
  16. ROM:00006526                 move.b  (a5)+,d1        ; fetch new decription field
  17. ROM:00006528
  18. ROM:00006528 @RunDecoding:                           ; CODE XREF: KonDec:@MainLoopj
  19. ROM:00006528                 lsr.w   #1,d1           ; get a bit from the description bitfield
  20. ROM:0000652A                 bcs.w   @DecodeFlag     ; if bit=1, treat current byte as decompression flag
  21. ROM:0000652E                 move.b  (a5)+,(a6)+     ; if bit=0, treat current byte as raw data
  22. ROM:00006530                 jmp     (a0)            ; back to @MainLoop
  23. ROM:00006532 ; ---------------------------------------------------------------------------
  24. ROM:00006532
  25. ROM:00006532 @DecodeFlag:                            ; CODE XREF: KonDec+18j
  26. ROM:00006532                 moveq   #0,d0
  27. ROM:00006534                 move.b  (a5)+,d0        ; read flag from a compressed stream
  28. ROM:00006536                 bmi.w   @Mode10or11     ; if bit 7 is set, branch
  29. ROM:0000653A                 cmpi.b  #$1F,d0
  30. ROM:0000653E                 beq.w   @QuitDecomp     ; if flag is $1F, branch
  31. ROM:00006542                 move.l  d0,d2           ; d2 = %00000000 0ddnnnnn
  32. ROM:00006544                 lsl.w   #3,d0           ; d0 = %000000dd nnnnn000
  33. ROM:00006546                 move.b  (a5)+,d0        ; d0 = %000000dd dddddddd
  34. ROM:00006548                 andi.w  #$1F,d2         ; d2 = %00000000 000nnnnn
  35. ROM:0000654C                 addq.w  #2,d2
  36. ROM:0000654E                 jmp     (@UncCopyMode).l
  37. ROM:00006554 ; ---------------------------------------------------------------------------
  38. ROM:00006554
  39. ROM:00006554 @Mode10or11:                            ; CODE XREF: KonDec+24j
  40. ROM:00006554                 btst    #6,d0
  41. ROM:00006558                 bne.w   @CompCopyMode   ; if bits 7 and 6 are set, branch
  42. ROM:0000655C                 move.l  d0,d2           ; d2 = %00000000 10xxxxxx
  43. ROM:0000655E                 lsr.w   #4,d2           ; d2 = %00000000 000010xx
  44. ROM:00006560                 subq.w  #7,d2           ; value = 1..4
  45. ROM:00006562                 andi.w  #$F,d0
  46. ROM:00006566
  47. ROM:00006566 @UncCopyMode:                           ; CODE XREF: KonDec+3Cj
  48. ROM:00006566                 neg.w   d0
  49. ROM:00006568
  50. ROM:00006568 @UncCopyLoop:                           ; CODE XREF: KonDec+5Aj
  51. ROM:00006568                 move.b  (a6,d0.w),(a6)+ ; self-copy block of uncompressed stream
  52. ROM:0000656C                 dbf     d2,@UncCopyLoop ; repeat
  53. ROM:00006570                 jmp     (a0)            ; back to @MainLoop
  54. ROM:00006572 ; ---------------------------------------------------------------------------
  55. ROM:00006572
  56. ROM:00006572 @CompCopyMode:                          ; CODE XREF: KonDec+46j
  57. ROM:00006572                 subi.b  #$B9,d0         ; value = 7..70
  58. ROM:00006576
  59. ROM:00006576 @CompCopyLoop:                          ; CODE XREF: KonDec+66j
  60. ROM:00006576                 move.b  (a5)+,(a6)+     ; copy uncompressed sequence
  61. ROM:00006578                 dbf     d0,@CompCopyLoop ; repeat
  62. ROM:0000657C                 jmp     (a0)            ; back to @MainLoop
  63. ROM:0000657E ; ---------------------------------------------------------------------------
  64. ROM:0000657E
  65. ROM:0000657E @QuitDecomp:                            ; CODE XREF: KonDec+2Cj
  66. ROM:0000657E                 rts
  67. ROM:0000657E ; End of function KonDec
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement