Skip to content

Instantly share code, notes, and snippets.

@Sanqui
Created January 10, 2014 18:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sanqui/8359454 to your computer and use it in GitHub Desktop.
Save Sanqui/8359454 to your computer and use it in GitHub Desktop.
vmu decompressor for a nybble-based 1bpp compression
decompress_quit:
jmp goodbye
decompress_ret:
jmp decompress_done
decompress:
xor acc
ldc
be #$ff, decompress_quit
st c ; num of bytes
inc c
xor acc
st nextbit
inc nextbit
st b
mov #$00, offset ; it gets +1 right away
mov #frame, 0
mov #bits, 1
.nextbyte
inc offset
dec c
ld c
be #0, decompress_ret
ld offset
ldc
and #$f0
ror
ror
ror
ror
be #$0, .literal
be #$e, .13same
be #$f, .31same
st b
ld nextbit
br .add
.literal:
ld offset
ldc
and #$0f
xor #$0f
rol
rol
rol
rol
rol
call addbit
rol
call addbit
rol
call addbit
rol
call addbit
and #$01
xor #$01
st nextbit
;inc offset
br .nextbyte
.13same:
ld nextbit
mov #13, b
br .addsame
.31same:
ld nextbit
mov #31, b
br .addsame
.addsame
call addbits
br .nextnybble
.add:
call addbits
ld nextbit
xor #$01
st nextbit
.nextnybble:
ld offset
ldc
and #$0f
be #$0, .literal_
be #$e, .13same_
be #$f, .31same_
st b
ld nextbit
br .add_
.literal_:
inc offset
ld offset
ldc
and #$f0
xor #$f0
rol
call addbit
rol
call addbit
rol
call addbit
rol
call addbit
and #$01
xor #$01
st nextbit
dec c
ld c
be #0, .done
br .nextnybble
.13same_:
ld nextbit
mov #13, b
br .addsame_
.31same_:
ld nextbit
mov #31, b
br .addsame_
.addsame_:
call addbits
brf .nextbyte
.add_:
call addbits
ld nextbit
xor #$01
st nextbit
brf .nextbyte
.done:
nop ; holy shit SERIOUSLY
decompress_done:
;inc offset
ld offset
add trl
st trl
bp PSW, CY, .carry
ret
.carry
inc trh
ret
addbits:
call addbit
dbnz b, addbits
ret
addbit:
push acc
and #$01
st @R1
inc 1
ld 1
be #bitsend, .newbyte
pop acc
ret
.newbyte
xor acc
dec 1
or @R1
dec 1
ror
or @R1
dec 1
ror
or @R1
dec 1
ror
or @R1
dec 1
ror
or @R1
dec 1
ror
or @R1
dec 1
ror
or @R1
dec 1
ror
or @R1
ror
st @R0
inc 0
pop acc
ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment