Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- WriteDEDTreeToWRAM:
- ld d, h
- ld e, l
- ld hl, GetDEDByte
- ld a, LD_A_FFXX_OP
- ld [hli], a
- ld a, hCurBitStream & $ff
- ld [hli], a
- .loop
- ; control codes are styled as follows
- ; 1110 xxxx xxxx xxxx: internal internal, x is jump offset
- ; 1100 xxxx 0000 yyyy: leaf leaf, x if 1, y if 0
- ; 1000 xxxx: internal leaf, x if 1
- ; 0xxx xxxx: internal internal, x is jump offset
- ; 1111 1111: terminator, signifies end of stream
- ld a, [de]
- cp $ff
- jr z, .end
- add a
- jr nc, .huffhuffjr
- add a
- jr nc, .huffleaf
- add a
- jr nc, .leafleaf
- .huffhuffjp
- call CopyBitreeCode
- push bc
- ld a, JP_C_OP
- ld [hli], a
- ld a, [de]
- and $f
- ld b, a
- inc de
- ld a, [de]
- inc de
- ld c, a
- push hl
- add hl, bc
- inc hl
- inc hl
- ld b, h
- ld c, l
- pop hl
- ld a, c
- ld [hli], a
- ld a, b
- ld [hli], a
- pop bc
- jr .loop
- .leafleaf
- call .leafcommon
- ld a, LD_B_XX_OP
- ld [hli], a
- ld a, [de]
- inc de
- ld [hli], a
- ld a, RET_OP
- ld [hli], a
- jr .loop
- .huffleaf
- call .leafcommon
- jr .loop
- .huffhuffjr
- call CopyBitreeCode
- ld a, JR_C_OP
- ld [hli], a
- ld a, [de]
- inc de
- ld [hli], a
- jr .loop
- .end
- inc de
- ld h, d
- ld l, e
- ret
- .leafcommon
- call CopyBitreeCode
- ld a, LD_B_XX_OP
- ld [hli], a
- ld a, [de]
- inc de
- and $f
- ld [hli], a
- ld a, RET_C_OP
- ld [hli], a
- ret
- CopyBitreeCode:
- ld a, DEC_C_OP
- ld [hli], a
- ld a, JR_NZ_OP
- ld [hli], a
- ld a, 3
- ld [hli], a
- ld a, LD_A_HLI_OP
- ld [hli], a
- ld a, LD_C_XX_OP
- ld [hli], a
- ld a, 8
- ld [hli], a
- ld a, ADD_A_OP
- ld [hli], a
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement