Skip to content

Commit

Permalink
ASM GB-Decompress version
Browse files Browse the repository at this point in the history
  • Loading branch information
untoxa committed Sep 7, 2020
1 parent 8c9607b commit 7f14544
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 7 deletions.
9 changes: 9 additions & 0 deletions gb-decompress/ASM/rle_decompress.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// GB-Compress decompressor
// Compatible with GBTD

#ifndef __RLE_DECOMPRESS_H_INCLUDE
#define __RLE_DECOMPRESS_H_INCLUDE

void gb_decompress(const unsigned char * sour, unsigned char * dest);

#endif
93 changes: 93 additions & 0 deletions gb-decompress/ASM/rle_decompress.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
; GB-Compress decompressor
; Compatible with GBTD

.area _CODE
_gb_decompress::
lda hl,5(SP)
ld a,(hl-)
ld d,a
ld a,(hl-)
ld e,a
ld a,(hl-)
ld l,(hl)
ld h,a

; hl = source; de = dest
gb_decompress::
push bc
1$:
ld a,(hl+) ; load command
or a
jr z,9$ ; exit, if last byte
bit 7,a
jr nz,5$ ; string functions
bit 6,a
jr nz,3$
; RLE byte
and #63 ; calc counter
inc a
ld b,a
ld a,(hl+)
2$:
ld (de),a
inc de
dec b
jr nz,2$
jr 1$ ; next command
3$: ; RLE word
and #63
inc a
ld b,(hl) ; load word into bc
inc hl
ld c,(hl)
inc hl
4$:
push af
ld a,b ; store word
ld (de),a
inc de
ld a,c
ld (de),a
inc de
pop af
dec a
jr nz,4$
jr 1$ ; next command
5$:
bit 6,a
jr nz,7$
; string repeat
and a,#63
inc a
push hl
ld c,(hl)
inc hl
ld b,(hl)
ld h,d
ld l,e
add hl,bc
ld b,a
6$:
ld a,(hl+)
ld (de),a
inc de
dec b
jr nz,6$
pop hl
inc hl
inc hl
jr 1$ ; next command
7$: ; string copy
and #63
inc a
ld b,a
8$:
ld a,(hl+)
ld (de),a
inc de
dec b
jr nz,8$
jr 1$ ; next command
9$:
pop bc
ret
5 changes: 4 additions & 1 deletion gbdk/rle_decompress.c → gb-decompress/C/rle_decompress.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
void decompress(const unsigned char * sour, unsigned char * dest) __naked {
// GB-Compress decompressor
// Compatible with GBTD

void gb_decompress(const unsigned char * sour, unsigned char * dest) __naked {
sour; dest;
__asm
lda hl,5(SP)
Expand Down
9 changes: 9 additions & 0 deletions gb-decompress/C/rle_decompress.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// GB-Compress decompressor
// Compatible with GBTD

#ifndef __RLE_DECOMPRESS_H_INCLUDE
#define __RLE_DECOMPRESS_H_INCLUDE

void gb_decompress(const unsigned char * sour, unsigned char * dest);

#endif
6 changes: 0 additions & 6 deletions gbdk/rle_decompress.h

This file was deleted.

0 comments on commit 7f14544

Please sign in to comment.