Advertisement
KSSBrawl_

decompress.asm

Jan 26th, 2022
3,716
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ; decompress.asm
  3. ;   Data decompression
  4. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5.  
  6. ;.include "../macros.asm"
  7.  
  8. .macro  dcmp_fetch_byte
  9.         lda         [dcmp_srcadd],y
  10.         iny
  11.         bne         :+
  12.         jsr         dcmp_nextbank
  13. :
  14.         ; next code
  15. .endmac
  16.  
  17. .macro  dcmp_chk_lz_end
  18.         pha
  19.         lda         dcmp_lzcctr
  20.         beq         :+
  21.         jsr         dcmp_declzcctr
  22. :
  23.         pla
  24. .endmac
  25.  
  26. label_80a116:
  27.         php
  28.         phb
  29.         regsize     2, 2
  30.         ldy         dcmp_srcadd
  31.         stz         dcmp_srcadd
  32.         regsize     1, NULL
  33.         stz         dcmp_lzcctr
  34.         lda         dcmp_dstbnk
  35.         pha
  36.         plb
  37.         ldx         dcmp_dstadd
  38.         jmp         dcmp_main
  39.  
  40. dcmp_fetch:
  41.         dcmp_fetch_byte
  42.         dcmp_chk_lz_end
  43.         rts
  44.  
  45. dcmp_declzcctr:
  46.         dec
  47.         sta         dcmp_lzcctr
  48.         bne         :+
  49.         lda         dcmp_bnkstr
  50.         sta         dcmp_srcbnk
  51.         ldy         dcmp_addstr
  52. :
  53.         rts
  54.  
  55. dcmp_nextbank:
  56.         inc         dcmp_srcbnk
  57.         ldy         #$8000
  58.         rts
  59.  
  60. dcmp_nibl30:
  61.         sta         dcmp_work
  62.         asl
  63.         bpl         dcmp_nibl50
  64.         and         #$20
  65.         beq         dcmp_nibl40
  66.         lda         dcmp_work
  67.         asl
  68.         asl
  69.         asl
  70.         asl
  71.         ora         #$0f
  72.         sta         a:$0000,x
  73.         inx
  74.         lda         #$1f
  75.         bra         dcmp_nibl10
  76. dcmp_nibl40:
  77.         lda         dcmp_work
  78.         and         #$0f
  79.         ora         #$f0
  80.         sta         a:$0000,x
  81.         inx
  82.         lda         #$0f
  83.         bra         dcmp_nibl10
  84. dcmp_nibl50:
  85.         and         #$20
  86.         beq         dcmp_nibl60
  87.         lda         dcmp_work
  88.         asl
  89.         asl
  90.         asl
  91.         asl
  92.         sta         a:$0000,x
  93.         inx
  94.         lda         #$10
  95.         bra         dcmp_nibl10
  96. dcmp_nibl60:
  97.         lda         dcmp_work
  98.         and         #$0f
  99.         sta         a:$0000,x
  100.         inx
  101.         lda         #$00
  102.         bra         dcmp_nibl10
  103. dcmp_nibl:
  104.         and         #$0f
  105.         inc
  106.         sta         dcmp_work+2
  107.         jsr         dcmp_fetch
  108.         cmp         #$80
  109.         bcs         dcmp_nibl30
  110. dcmp_nibl10:
  111.         cmp         #$10
  112.         bcc         dcmp_nibl20
  113.         and         #$0f
  114.         sta         dcmp_work
  115. dcmp_nibl15:
  116.         jsr         dcmp_fetch
  117.         sta         dcmp_work+1
  118.         and         #$f0
  119.         ora         dcmp_work
  120.         sta         a:$0000,x
  121.         inx
  122.         dec         dcmp_work+2
  123.         bmi         dcmp_niblr
  124.         lda         dcmp_work+1
  125.         asl
  126.         asl
  127.         asl
  128.         asl
  129.         ora         dcmp_work
  130.         sta         a:$0000,x
  131.         inx
  132.         dec         dcmp_work+2
  133.         bpl         dcmp_nibl15
  134.         jmp         dcmp_main
  135.    
  136. dcmp_nibl20:
  137.         asl
  138.         asl
  139.         asl
  140.         asl
  141.         sta         dcmp_work
  142. dcmp_nibl25:
  143.         jsr         dcmp_fetch
  144.         sta         dcmp_work+1
  145.         lsr
  146.         lsr
  147.         lsr
  148.         lsr
  149.         ora         dcmp_work
  150.         sta         a:$0000,x
  151.         inx
  152.         dec         dcmp_work+2
  153.         bmi         dcmp_niblr
  154.         lda         dcmp_work+1
  155.         and         #$0f
  156.         ora         dcmp_work
  157.         sta         a:$0000,x
  158.         inx
  159.         dec         dcmp_work+2
  160.         bpl         dcmp_nibl25
  161. dcmp_niblr:
  162.         jmp         dcmp_main
  163.  
  164. dcmp_chkcmdmsk10:
  165.         cmp         #%01010000
  166.         bcc         dcmp_nibl
  167.         and         #$0f
  168.         sta         dcmp_work+2
  169. dcmp_rep2:
  170.         dcmp_fetch_byte
  171.         dcmp_chk_lz_end
  172.         sta         a:$0000,x
  173.         inx
  174.         sta         a:$0000,x
  175.         inx
  176.         dec         dcmp_work+2
  177.         bpl         dcmp_rep2
  178.         jmp         dcmp_main
  179.  
  180. dcmp_chkcmdmsk:
  181.         lsr
  182.         cmp         #%01100000
  183.         bcc         dcmp_chkcmdmsk10
  184.         xba
  185.         dcmp_fetch_byte
  186.         dcmp_chk_lz_end
  187.         sta         dcmp_work
  188.         xba
  189.         cmp         #%01110000
  190.         and         #$0f
  191.         inc
  192.         sta         dcmp_work+2
  193.         bcs         dcmp_alt2
  194. dcmp_alt1:
  195.         lda         dcmp_work
  196.         sta         a:$0000,x
  197.         inx
  198.         dcmp_fetch_byte
  199.         dcmp_chk_lz_end
  200.         sta         a:$0000,x
  201.         inx
  202.         dec         dcmp_work+2
  203.         bpl         dcmp_alt1
  204.         bra         dcmp_main
  205.  
  206. dcmp_alt2:
  207.         dcmp_fetch_byte
  208.         dcmp_chk_lz_end
  209.         sta         a:$0000,x
  210.         inx
  211.         lda         dcmp_work
  212.         sta         a:$0000,x
  213.         inx
  214.         dec         dcmp_work+2
  215.         bpl         dcmp_alt2
  216.         bra         dcmp_main
  217.  
  218. dcmp_bitmskcmd:
  219.         bmi         dcmp_chkcmdmsk
  220.         lsr
  221.         sta         dcmp_work+2
  222. dcmp_rawd:
  223.         dcmp_fetch_byte
  224.         dcmp_chk_lz_end
  225.         sta         a:$0000,x
  226.         inx
  227.         dec         dcmp_work+2
  228.         bpl         dcmp_rawd
  229. dcmp_main:
  230.         dcmp_fetch_byte
  231.         dcmp_chk_lz_end
  232.         asl
  233.         bcc         dcmp_bitmskcmd
  234.         bmi         dcmp_prefixcmd
  235.         lsr
  236.         pha
  237.         lsr
  238.         lsr
  239.         inc
  240.         sta         dcmp_work+2
  241.         pla
  242.         and         #$03
  243.         xba
  244. label_80a2c2:
  245.         dcmp_fetch_byte
  246.         phy
  247.         regsize     2, NULL
  248.         sta         dcmp_work
  249.         txa
  250.         sec
  251.         sbc         dcmp_work
  252.         tay
  253.         regsize     1, NULL
  254. label_80a2d6:
  255.         lda         a:$0000,y
  256.         sta         a:$0000,x
  257.         iny
  258.         inx
  259.         dec         dcmp_work+2
  260.         bpl         label_80a2d6
  261.         ply
  262. label_80a2e3:
  263.         lda         dcmp_lzcctr
  264.         beq         dcmp_main
  265.         jsr         dcmp_declzcctr
  266.         bra         dcmp_main
  267.  
  268. dcmp_prefixcmd:
  269.         ror
  270.         cmp         #%11100000
  271.         bcs         dcmp_rle1
  272.         and         #$1f
  273.         xba
  274.         dcmp_fetch_byte
  275.         dcmp_chk_lz_end
  276.         regsize     2, NULL
  277.         asl
  278.         regsize     1, NULL
  279.         lsr
  280.         xba
  281.         inc
  282.         sta         dcmp_work+2
  283.         bra         label_80a2c2
  284.  
  285. dcmp_rle1:
  286.         cmp         #%11110000
  287.         bcs         dcmp_rle2
  288.         and         #%00001111
  289.         sta         dcmp_work+1
  290.         dcmp_fetch_byte
  291.         dcmp_chk_lz_end
  292.         sta         dcmp_work
  293.         dcmp_fetch_byte
  294.         phy
  295.         pha
  296.         pha
  297.         regsize     2, NULL
  298.         lda         dcmp_work
  299.         clc
  300.         adc         #3
  301.         lsr
  302.         tay
  303.         pla
  304. dcmp_rle1_10:
  305.         sta         a:$0000,x
  306.         inx
  307.         inx
  308.         dey
  309.         bne         dcmp_rle1_10
  310.         regsize     1, NULL
  311.         bcc         dcmp_rle1_20
  312.         sta         a:$0000,x
  313.         inx
  314. dcmp_rle1_20:
  315.         ply
  316.         bra         label_80a2e3
  317. dcmp_rle2:
  318.         cmp         #%11111000
  319.         bcs         dcmp_lzcf
  320.         and         #%00000111
  321.         adc         #2
  322.         sta         dcmp_work+2
  323.         dcmp_fetch_byte
  324. label_80a367:
  325.         sta         a:$0000,x
  326.         inx
  327.         dec         dcmp_work+2
  328.         bpl         label_80a367
  329.         jmp         label_80a2e3
  330.  
  331. dcmp_lzcf:
  332.         cmp         #%11111100
  333.         bcs         dcmp_lzcn
  334.         and         #%00000011
  335.         xba
  336.         dcmp_fetch_byte
  337.         regsize     2, NULL
  338.         asl
  339.         asl
  340.         asl
  341.         regsize     1, NULL
  342.         lsr
  343.         lsr
  344.         lsr
  345.         xba
  346.         pha
  347.         dcmp_fetch_byte
  348.         regsize     2, NULL
  349.         clc
  350.         adc         #3
  351. dcmp_lzc_calc:
  352.         sty         dcmp_addstr
  353.         sta         dcmp_work
  354.         regsize     1, NULL
  355.         lda         dcmp_srcbnk
  356.         sta         dcmp_bnkstr
  357.         regsize     2, NULL
  358.         tya
  359.         sec
  360.         sbc         dcmp_work
  361.         bmi         label_80a3b3
  362.         clc
  363.         adc         #$8000
  364.         dec         dcmp_srcbnk
  365. label_80a3b3:
  366.         tay
  367.         regsize     1, NULL
  368.         pla
  369.         clc
  370.         adc         #3
  371.         sta         dcmp_lzcctr
  372.         jmp         dcmp_main
  373.  
  374. dcmp_lzcn:
  375.         cmp         #%11111110
  376.         bcs         dcmpret
  377.         and         #%00000001
  378.         xba
  379.         dcmp_fetch_byte
  380.         regsize     2, NULL
  381.         asl
  382.         asl
  383.         regsize     1, NULL
  384.         xba
  385.         pha
  386.         xba
  387.         lsr
  388.         lsr
  389.         regsize     2, NULL
  390.         and         #%0000000000111111
  391.         inc
  392.         inc
  393.         bra         dcmp_lzc_calc
  394. dcmpret:
  395.         plb
  396.         plp
  397.         rtl
  398.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement