; LZSS decompressor ; Feb 29th 2012: More than twice as fast ; Feb 27th 2012: Initial revision cpu 6800 * = $f00 LAST equ (save+2) CBYTE equ $fe BIT equ $ff ; IN: X=source ptr, BA=dest ptr ; For self-extracting stuff only ldx #$6000 ldab #$10 ldaa #$00 ; --- stab dst staa dst+1 ldaa #7 staa BIT ldaa ,x staa CBYTE main bsr getbit bcc cpybyte ; Bit = 0 ; Reference to previous data jsr getbyte tab jsr getbyte tsta ; 0,0 = end bne oke tstb beq return oke staa tmp ; Save what we got anda #15 ; Bytes to copy inca psha ldaa tmp ; Shift out counter bits to get offset lsrb rora lsrb rora lsrb rora lsrb rora adda #1 ; Plus +1 adcb #0 stab tmp staa tmp+1 ldab dst ; Dest-offset ldaa dst+1 suba tmp+1 sbcb tmp stx save stab tmp staa tmp+1 ldx tmp pulb bsr blkcpy ; Copy them bytes ldx save bra main return ldaa #4 staa $ca00 rts ; Copy next byte verbatim to dest cpybyte bsr getbyte stx tmp ldx dst staa ,x inx stx dst ldx tmp staa $ca00 bra main ; Copy a block of B bytes from X to dest blkcpy sei sts tmp lds dst luup ldaa ,x inx psha ins ins decb bne luup sts dst lds tmp cli rts ; Check whether the next bit is 0 or 1, result in carry getbit asl CBYTE dec BIT bpl getout ldab #7 stab BIT inx ldab ,x stab CBYTE getout rts ; Get next byte to A getbyte pshb bsr getbit rola bsr getbit rola bsr getbit rola bsr getbit rola bsr getbit rola bsr getbit rola bsr getbit rola bsr getbit rola pulb rts dst dw 0 tmp dw 0 save dw 0