;============================================================
;tilemap data decompression routine  from Sylvan Tale
;
; DATA is stored into RAM, not VRAM. can be modified to do so but have to read from vram.
;
;         Hl = address of compressed data
;         DE = RAM address to load data into

SylvanTaleTilemapDecompression:
--:
    ld     c,(hl)          ;      load control byte
    inc    hl              ;
    ld     b,$08           ;           repeat 8 times
-:
    rr     c               ;       evaluate a bit from control byte
    jr     nc,TD_decomp    ;     if bit 0 load new pointer

    ldi                    ;     (de) = (hl)
    inc    bc              ;    restore bc from the ldi
    jr     +               ;


TD_decomp:                 ;   loads  new source pointer + count byte
    push   bc              ;
    ld     c,(hl)          ;
    inc    hl              ;
    ld     b,(hl)          ;
    inc    hl              ;       bc = (hl)

    ld     a,c             ;
    or     b               ;
    jr     z,TD_exit       ;    finish if bc = 0;


    push   hl              ;
    ld     a,b             ;
    or     $f0             ;
    ld     h,a             ;
    ld     l,c             ;
    add    hl,de           ;       hl = de + (bc OR $f000) = new pointer

    ld     a,b             ;
    and    $f0             ;
    rrca                   ;
    rrca                   ;
    rrca                   ;
    rrca                   ;     a = high nibble of b
    add    a,$03           ;
    ld     c,a             ;
    ld     b,$00           ;    counter = high nibble of b + 3

    ldir                   ;       load out previous data
    pop    hl              ;    restore pointer
    pop    bc              ;

+
    djnz   -               ;
    jr     --              ;

TD_exit:
    pop    bc              ;
    ret                    ;



Return to top
0.091s